mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-16 09:22:22 +00:00
feat(ui): add compiled LiteFlow workflow graph and inspector
This commit is contained in:
parent
08f2a98250
commit
b322f18438
19 changed files with 3209 additions and 0 deletions
|
|
@ -0,0 +1,9 @@
|
|||
import { notFound } from "next/navigation";
|
||||
|
||||
export default async function WorkflowGraphPreviewPage() {
|
||||
if (process.env.NODE_ENV === "development") {
|
||||
const { default: WorkflowGraphDemo } = await import("../../../../../tests/fixtures/workflows/WorkflowGraphDemo");
|
||||
return <WorkflowGraphDemo />;
|
||||
}
|
||||
notFound();
|
||||
}
|
||||
75
ui/litellm-dashboard/src/components/workflows/README.md
Normal file
75
ui/litellm-dashboard/src/components/workflows/README.md
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
# Workflow definition components
|
||||
|
||||
`WorkflowDefinitionView` combines a read-only graph and definition inspector. `WorkflowGraph` and `WorkflowDefinitionInspector` are also exported separately from `@/components/workflows`
|
||||
|
||||
Pass the `bundle` field from the LiteFlow PR #3 `Draft` response directly. The component validates the compiler's version 1 shape at its boundary, draws nodes in array order and derives connections from adjacent nodes. It does not fetch, register, edit or execute workflows
|
||||
|
||||
```tsx
|
||||
import { WorkflowDefinitionView } from "@/components/workflows";
|
||||
|
||||
const definitionKey = `${draft.workflow_id}:${draft.etag}`;
|
||||
|
||||
<WorkflowDefinitionView
|
||||
key={definitionKey}
|
||||
bundle={draft.bundle}
|
||||
definitionKey={definitionKey}
|
||||
selectedNodeId={selectedNodeId}
|
||||
onNodeSelect={setSelectedNodeId}
|
||||
loading={isLoading}
|
||||
error={loadError}
|
||||
/>;
|
||||
```
|
||||
|
||||
Keep fetching, error recovery and selection state in the parent. Reset selection when changing definitions, or key the parent that owns selection by the definition identity. `onNodeSelect` receives the compiled node ID, or `null` when the user clears selection. Run details and Test run controls can use the same selection without owning a second graph
|
||||
|
||||
For a run, fetch its pinned compiled definition and use its immutable `snapshot_id` as `definitionKey`. Map the typed PR #5 step states by `step.node_id`, which must equal the compiled `node.id`
|
||||
|
||||
```tsx
|
||||
const execution = {
|
||||
definitionKey: steps.snapshot_id,
|
||||
states: Object.fromEntries(steps.steps.map((step) => [step.node_id, step.state])),
|
||||
};
|
||||
|
||||
<WorkflowDefinitionView
|
||||
bundle={pinnedBundle}
|
||||
definitionKey={snapshotId}
|
||||
selectedNodeId={selectedNodeId}
|
||||
onNodeSelect={setSelectedNodeId}
|
||||
execution={execution}
|
||||
/>;
|
||||
```
|
||||
|
||||
An overlay from a different definition is ignored. Missing states leave nodes uncolored. The graph supports `pending`, `running`, `completed`, `failed` and `cancelled`. Resolve any repeated step records to the current node state in the parent before constructing the map. Workflow drafts should use their workflow ID plus ETag and must not borrow a run's overlay without its pinned bundle
|
||||
|
||||
The inspector displays compiler bindings, Python schemas and source, structured ChatCompletion output and execution settings. It never executes Python or renders definition content as HTML. Parallel and If nodes and unknown bundle versions produce an unsupported state instead of misleading sequential edges
|
||||
|
||||
The UI uses the dashboard's shadcn Button, Card, Badge, Collapsible and Skeleton components, shared theme tokens and the existing theme provider. It follows light and dark mode without a second theme toggle. Drag or scroll the canvas to pan, use Ctrl or Command plus scroll to zoom, or use the toolbar. Keyboard users can tab to nodes and controls, pan the focused canvas with arrow keys, zoom with plus/minus and fit with zero
|
||||
|
||||
## Fixture preview and verification
|
||||
|
||||
Fixtures and their generator live in `tests/fixtures/workflows`. The development route `/workflows/graph-preview` returns not found outside development. Fixtures are never a production fallback
|
||||
|
||||
From `ui/litellm-dashboard`, start the local shell fixture service and the actual dashboard in separate terminals
|
||||
|
||||
```sh
|
||||
../../scripts/with_dashboard_node.sh node tests/fixtures/workflows/serve-shell.mjs
|
||||
```
|
||||
|
||||
```sh
|
||||
NEXT_PUBLIC_USE_REWRITES=true LENS_DEV_PROXY_URL=http://127.0.0.1:3368 \
|
||||
../../scripts/with_dashboard_node.sh npm run dev:webpack -- --hostname 127.0.0.1 --port 3367
|
||||
```
|
||||
|
||||
Open `http://workflow-graph.localhost:3367/__workflow_fixture_login`. The isolated hostname keeps the synthetic session separate from other localhost dashboard sessions. The fixture service binds only to loopback, supplies dashboard shell responses and rejects unconfigured requests. It implements no workflow execution or persistence
|
||||
|
||||
Select the Python node to inspect its literal and previous-step bindings, schemas, source, timeout and retries. Select the last ChatCompletion to inspect structured output. Use the fixture preview controls for execution overlays and loading, empty and unsupported states. Use the dashboard header to switch themes and verify pan, zoom, fit and keyboard selection
|
||||
|
||||
This is fixture-based proof in the real dashboard. It does not establish live gateway registration, execution, run polling, billing or Test run integration
|
||||
|
||||
```sh
|
||||
../../scripts/with_dashboard_node.sh npx vitest run \
|
||||
src/components/workflows/definition.test.ts \
|
||||
src/components/workflows/viewport.test.ts \
|
||||
src/components/workflows/WorkflowDefinitionView.integration.test.tsx
|
||||
../../scripts/with_dashboard_node.sh npm run typecheck
|
||||
```
|
||||
|
|
@ -0,0 +1,220 @@
|
|||
"use client";
|
||||
|
||||
import { useMemo, type ReactNode } from "react";
|
||||
import { Braces, ChevronDown, Code2, MousePointer2, Sparkles, X } from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible";
|
||||
import {
|
||||
executionStates,
|
||||
nodeTitle,
|
||||
readWorkflowDefinition,
|
||||
type CompiledWorkflowBundle,
|
||||
type CompiledWorkflowNode,
|
||||
type WorkflowBinding,
|
||||
} from "./definition";
|
||||
import { WorkflowNodeStatus, type WorkflowGraphProps } from "./WorkflowGraph";
|
||||
|
||||
function InspectorSection({ title, children }: { title: string; children: ReactNode }) {
|
||||
return (
|
||||
<section className="space-y-3 border-t border-border pt-5">
|
||||
<h3 className="text-xs font-medium uppercase tracking-wide text-muted-foreground">{title}</h3>
|
||||
{children}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
function InspectorDisclosure({ title, children }: { title: string; children: ReactNode }) {
|
||||
return (
|
||||
<Collapsible className="min-w-0 rounded-lg border border-border bg-muted/30">
|
||||
<CollapsibleTrigger className="group flex w-full items-center justify-between gap-2 rounded-lg px-3 py-2 text-left text-xs font-medium focus-visible:outline-ring">
|
||||
{title}
|
||||
<ChevronDown aria-hidden className="size-3.5 text-muted-foreground group-data-panel-open:rotate-180" />
|
||||
</CollapsibleTrigger>
|
||||
<CollapsibleContent>
|
||||
<pre className="max-h-64 overflow-auto border-t border-border p-3 text-xs leading-relaxed">{children}</pre>
|
||||
</CollapsibleContent>
|
||||
</Collapsible>
|
||||
);
|
||||
}
|
||||
|
||||
function JsonDetails({ title, value }: { title: string; value: unknown }) {
|
||||
return <InspectorDisclosure title={title}>{JSON.stringify(value, null, 2)}</InspectorDisclosure>;
|
||||
}
|
||||
|
||||
function BindingValue({ binding }: { binding: WorkflowBinding }) {
|
||||
const { t } = useTranslation();
|
||||
if ("from" in binding) {
|
||||
return (
|
||||
<div className="flex flex-wrap items-center gap-1.5 text-xs">
|
||||
<span className="rounded-md border border-border bg-muted px-2 py-1 font-mono">{binding.from}</span>
|
||||
<span className="text-muted-foreground">/</span>
|
||||
<code>{binding.output}</code>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return <JsonDetails title={t("workflowGraph.literal")} value={binding.value} />;
|
||||
}
|
||||
|
||||
function NodeBindings({ node }: { node: CompiledWorkflowNode }) {
|
||||
const bindings = node.type === "python" ? node.inputs : { messages: node.messages };
|
||||
return (
|
||||
<dl className="space-y-3">
|
||||
{Object.entries(bindings).map(([name, value]) => (
|
||||
<div key={name} className="space-y-2">
|
||||
<dt className="break-all font-mono text-xs">{name}</dt>
|
||||
<dd>
|
||||
<BindingValue binding={value} />
|
||||
</dd>
|
||||
</div>
|
||||
))}
|
||||
</dl>
|
||||
);
|
||||
}
|
||||
|
||||
function NodeSchemas({ bundle, node }: { bundle: CompiledWorkflowBundle; node: CompiledWorkflowNode }) {
|
||||
const { t } = useTranslation();
|
||||
if (node.type === "python") {
|
||||
return (
|
||||
<>
|
||||
<JsonDetails title={t("workflowGraph.inputSchema")} value={node.program.input_schema} />
|
||||
<JsonDetails title={t("workflowGraph.outputSchema")} value={node.program.output_schema} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<>
|
||||
<JsonDetails title={t("workflowGraph.inputSchema")} value={bundle.input_schema} />
|
||||
{node.response_format ? (
|
||||
<JsonDetails title={t("workflowGraph.outputSchema")} value={node.response_format.json_schema} />
|
||||
) : (
|
||||
<p className="text-xs text-muted-foreground">{t("workflowGraph.textOutput")}</p>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function NodeConfiguration({ node }: { node: CompiledWorkflowNode }) {
|
||||
const { t } = useTranslation();
|
||||
const parameters =
|
||||
node.type === "chat_completion"
|
||||
? Object.fromEntries(
|
||||
["temperature", "top_p", "max_tokens", "max_completion_tokens", "seed", "stop"]
|
||||
.filter((key) => node[key] !== undefined)
|
||||
.map((key) => [key, node[key]]),
|
||||
)
|
||||
: {};
|
||||
return (
|
||||
<>
|
||||
<dl className="grid grid-cols-2 gap-x-3 gap-y-3 text-xs">
|
||||
<dt className="text-muted-foreground">{t("workflowGraph.timeout")}</dt>
|
||||
<dd className="text-right tabular-nums">{t("workflowGraph.seconds", { count: node.timeout_seconds })}</dd>
|
||||
<dt className="text-muted-foreground">{t("workflowGraph.attempts")}</dt>
|
||||
<dd className="text-right tabular-nums">{node.retry.max_attempts}</dd>
|
||||
<dt className="text-muted-foreground">{t("workflowGraph.backoff")}</dt>
|
||||
<dd className="text-right tabular-nums">{t("workflowGraph.seconds", { count: node.retry.backoff_seconds })}</dd>
|
||||
</dl>
|
||||
{Object.keys(parameters).length > 0 && (
|
||||
<JsonDetails title={t("workflowGraph.modelParameters")} value={parameters} />
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export type WorkflowDefinitionInspectorProps = Pick<
|
||||
WorkflowGraphProps,
|
||||
"bundle" | "definitionKey" | "selectedNodeId" | "onNodeSelect" | "execution" | "loading" | "error"
|
||||
>;
|
||||
|
||||
export function WorkflowDefinitionInspector({
|
||||
bundle: input,
|
||||
definitionKey,
|
||||
selectedNodeId,
|
||||
onNodeSelect,
|
||||
execution,
|
||||
loading,
|
||||
error,
|
||||
}: WorkflowDefinitionInspectorProps) {
|
||||
const { t } = useTranslation();
|
||||
const definition = useMemo(() => readWorkflowDefinition(input), [input]);
|
||||
if (loading || error || definition.kind !== "ready") return null;
|
||||
const { bundle } = definition;
|
||||
const node = bundle.nodes.find((candidate) => candidate.id === selectedNodeId);
|
||||
const states = executionStates(definitionKey, execution);
|
||||
const state = node && states?.[node.id];
|
||||
const Icon = node?.type === "python" ? Code2 : Sparkles;
|
||||
|
||||
return (
|
||||
<Card
|
||||
role="complementary"
|
||||
aria-label={t("workflowGraph.inspector")}
|
||||
className="min-w-0 gap-5 p-5 lg:max-h-[640px] lg:overflow-y-auto"
|
||||
>
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<h2 className="text-sm font-semibold">{t("workflowGraph.definition")}</h2>
|
||||
{node && (
|
||||
<Button
|
||||
size="icon-xs"
|
||||
variant="ghost"
|
||||
aria-label={t("workflowGraph.clearSelection")}
|
||||
onClick={() => onNodeSelect(null)}
|
||||
>
|
||||
<X />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
{!node ? (
|
||||
<>
|
||||
<div className="space-y-2">
|
||||
<Braces className="size-5 text-info" aria-hidden />
|
||||
<h3 className="break-all text-lg font-medium">{bundle.name}</h3>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{t("workflowGraph.workflowTimeout", { seconds: bundle.timeout_seconds })}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex gap-2 rounded-lg bg-muted p-3 text-xs text-muted-foreground">
|
||||
<MousePointer2 className="size-4 shrink-0" aria-hidden />
|
||||
{t("workflowGraph.selectHint")}
|
||||
</div>
|
||||
<InspectorSection title={t("workflowGraph.schemas")}>
|
||||
<JsonDetails title={t("workflowGraph.inputSchema")} value={bundle.input_schema} />
|
||||
</InspectorSection>
|
||||
<InspectorSection title={t("workflowGraph.output")}>
|
||||
<BindingValue binding={bundle.output} />
|
||||
</InspectorSection>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<div className="space-y-3">
|
||||
<Badge variant="secondary" className="gap-2">
|
||||
<Icon className="size-3.5 text-info" aria-hidden />
|
||||
{t(`workflowGraph.types.${node.type}`)}
|
||||
</Badge>
|
||||
<h3 className="break-all text-lg font-medium">{nodeTitle(node)}</h3>
|
||||
<div className="flex flex-wrap items-center justify-between gap-2">
|
||||
<code className="break-all text-xs text-muted-foreground">{node.id}</code>
|
||||
{state && <WorkflowNodeStatus state={state} />}
|
||||
</div>
|
||||
</div>
|
||||
<InspectorSection title={t("workflowGraph.bindings")}>
|
||||
<NodeBindings node={node} />
|
||||
</InspectorSection>
|
||||
<InspectorSection title={t("workflowGraph.schemas")}>
|
||||
<NodeSchemas bundle={bundle} node={node} />
|
||||
</InspectorSection>
|
||||
<InspectorSection title={t("workflowGraph.configuration")}>
|
||||
<NodeConfiguration node={node} />
|
||||
</InspectorSection>
|
||||
{node.type === "python" && (
|
||||
<InspectorSection title={t("workflowGraph.program")}>
|
||||
<InspectorDisclosure title={t("workflowGraph.source")}>{node.program.source}</InspectorDisclosure>
|
||||
<p className="break-all font-mono text-xs text-muted-foreground">SHA-256 {node.program.source_sha256}</p>
|
||||
</InspectorSection>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
import { useState } from "react";
|
||||
import { fireEvent, render, screen, within } from "@testing-library/react";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import drafts from "../../../tests/fixtures/workflows/drafts.json";
|
||||
import { WorkflowDefinitionView } from "./WorkflowDefinitionView";
|
||||
import type { WorkflowGraphProps } from "./WorkflowGraph";
|
||||
|
||||
const bundle = drafts["email-reply"].bundle;
|
||||
|
||||
function DefinitionHarness(props: Partial<WorkflowGraphProps>) {
|
||||
const [selectedNodeId, onNodeSelect] = useState<string | null>(null);
|
||||
return (
|
||||
<WorkflowDefinitionView
|
||||
bundle={bundle}
|
||||
definitionKey="snapshot-1"
|
||||
selectedNodeId={selectedNodeId}
|
||||
onNodeSelect={onNodeSelect}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
describe("workflow definition view", () => {
|
||||
it("selects the SDK Python node and inspects its bindings, schemas and retry settings", () => {
|
||||
render(<DefinitionHarness />);
|
||||
fireEvent.click(screen.getByRole("button", { name: /Step 2: prepare_followup/ }));
|
||||
const inspector = within(screen.getByRole("complementary", { name: "Workflow definition inspector" }));
|
||||
expect(inspector.getByRole("heading", { name: "prepare_followup" })).toBeInTheDocument();
|
||||
expect(inspector.getByText("text", { exact: true })).toBeInTheDocument();
|
||||
expect(inspector.getByText("node_1", { exact: true })).toBeInTheDocument();
|
||||
expect(inspector.getByText("15 s")).toBeInTheDocument();
|
||||
expect(inspector.getByText("2", { exact: true })).toBeInTheDocument();
|
||||
expect(inspector.getByText("0.5 s")).toBeInTheDocument();
|
||||
fireEvent.click(inspector.getByText("Input schema", { exact: true }));
|
||||
expect(inspector.getByText(/"additionalProperties": false/)).toHaveTextContent('"text"');
|
||||
fireEvent.click(inspector.getByText("Literal value"));
|
||||
expect(inspector.getByText(/Review this draft for clarity and accuracy/)).toBeVisible();
|
||||
fireEvent.click(inspector.getByRole("button", { name: "Clear node selection" }));
|
||||
expect(inspector.getByText(/Select a step to inspect/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows structured ChatCompletion output from the compiler", () => {
|
||||
render(<DefinitionHarness />);
|
||||
fireEvent.click(screen.getByRole("button", { name: /Step 3: review-model/ }));
|
||||
const inspector = within(screen.getByRole("complementary"));
|
||||
fireEvent.click(inspector.getByText("Output schema", { exact: true }));
|
||||
expect(inspector.getByText(/"strict": true/)).toHaveTextContent('"approved"');
|
||||
expect(inspector.getByText("node_2", { exact: true })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("inspects literal messages in a single-step SDK workflow", () => {
|
||||
render(<DefinitionHarness bundle={drafts["welcome-message"].bundle} />);
|
||||
fireEvent.click(screen.getByRole("button", { name: /Step 1: support-model/ }));
|
||||
const inspector = within(screen.getByRole("complementary"));
|
||||
fireEvent.click(inspector.getByRole("button", { name: "Literal value" }));
|
||||
expect(inspector.getByText(/Write a short welcome message/)).toBeVisible();
|
||||
expect(inspector.getByText(/No structured output schema/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("updates parent-supplied node states without losing selection and ignores other snapshots", () => {
|
||||
const states = { node_2: "running" as const };
|
||||
const { rerender } = render(<DefinitionHarness execution={{ definitionKey: "snapshot-1", states }} />);
|
||||
const pythonNode = screen.getByRole("button", { name: /Step 2: prepare_followup/ });
|
||||
fireEvent.click(pythonNode);
|
||||
expect(within(pythonNode).getByText("Running")).toBeInTheDocument();
|
||||
rerender(<DefinitionHarness execution={{ definitionKey: "snapshot-1", states: { node_2: "failed" } }} />);
|
||||
expect(within(pythonNode).getByText("Failed")).toBeInTheDocument();
|
||||
expect(pythonNode).toHaveAttribute("aria-pressed", "true");
|
||||
rerender(<DefinitionHarness execution={{ definitionKey: "other-snapshot", states }} />);
|
||||
expect(screen.queryByText("Running")).not.toBeInTheDocument();
|
||||
expect(screen.queryByText("Failed")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("zooms and fits through the graph controls", () => {
|
||||
render(<DefinitionHarness />);
|
||||
const initialZoom = screen.getByLabelText("Zoom level").textContent;
|
||||
fireEvent.click(screen.getByRole("button", { name: "Zoom in" }));
|
||||
expect(screen.getByLabelText("Zoom level")).not.toHaveTextContent(initialZoom!);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Fit to view" }));
|
||||
expect(screen.getByLabelText("Zoom level")).toHaveTextContent(initialZoom!);
|
||||
});
|
||||
|
||||
it.each([
|
||||
{ loading: true, text: "Loading workflow definition" },
|
||||
{ bundle: null, text: "No workflow to visualize" },
|
||||
{ bundle: { ...bundle, nodes: [{ type: "if" }] }, text: "This definition is not supported yet" },
|
||||
{ bundle: {}, text: "Unable to read this definition" },
|
||||
{ error: "Definition request failed", text: "Definition request failed" },
|
||||
])("shows $text without a stale graph or inspector", ({ text, ...props }) => {
|
||||
render(<DefinitionHarness {...props} />);
|
||||
expect(screen.getByText(text)).toBeInTheDocument();
|
||||
expect(screen.queryByRole("region", { name: "Workflow graph" })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("complementary")).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
"use client";
|
||||
|
||||
import { cn } from "@/lib/cva.config";
|
||||
import { WorkflowGraph, type WorkflowGraphProps } from "./WorkflowGraph";
|
||||
import { WorkflowDefinitionInspector } from "./WorkflowDefinitionInspector";
|
||||
|
||||
export function WorkflowDefinitionView({ className, ...props }: WorkflowGraphProps) {
|
||||
return (
|
||||
<div className={cn("grid min-w-0 gap-4 lg:grid-cols-[minmax(0,1fr)_340px]", className)}>
|
||||
<WorkflowGraph {...props} />
|
||||
<WorkflowDefinitionInspector {...props} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,109 @@
|
|||
.canvas {
|
||||
position: relative;
|
||||
height: 640px;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
color: var(--foreground);
|
||||
background-color: var(--background);
|
||||
background-image: radial-gradient(color-mix(in oklch, var(--muted-foreground) 24%, transparent) 1px, transparent 1px);
|
||||
background-size: 20px 20px;
|
||||
border-radius: var(--radius-lg);
|
||||
border: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.surface {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
touch-action: none;
|
||||
cursor: grab;
|
||||
outline-offset: -3px;
|
||||
}
|
||||
|
||||
.surface:active {
|
||||
cursor: grabbing;
|
||||
}
|
||||
|
||||
.stage {
|
||||
position: absolute;
|
||||
transform-origin: 0 0;
|
||||
}
|
||||
|
||||
.node {
|
||||
position: absolute;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
justify-content: flex-start;
|
||||
gap: 8px;
|
||||
padding: 16px;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
color: var(--foreground);
|
||||
background: linear-gradient(135deg, var(--card), color-mix(in oklch, var(--card) 92%, var(--muted)));
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 8px 24px rgb(0 0 0 / 20%);
|
||||
}
|
||||
|
||||
.node:hover {
|
||||
border-color: var(--muted-foreground);
|
||||
}
|
||||
|
||||
.node[aria-pressed="true"],
|
||||
.node:focus-visible {
|
||||
border-color: var(--info);
|
||||
outline: 2px solid color-mix(in oklch, var(--info) 35%, transparent);
|
||||
outline-offset: 3px;
|
||||
}
|
||||
|
||||
.port {
|
||||
position: absolute;
|
||||
left: calc(50% - 4px);
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border: 2px solid var(--info);
|
||||
border-radius: 50%;
|
||||
background: var(--background);
|
||||
}
|
||||
|
||||
.terminal {
|
||||
position: absolute;
|
||||
width: 160px;
|
||||
left: 120px;
|
||||
height: 32px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 20px;
|
||||
background: var(--card);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.state {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
font-size: 10px;
|
||||
font-weight: 500;
|
||||
color: var(--muted-foreground);
|
||||
}
|
||||
|
||||
.state[data-state="completed"] {
|
||||
color: var(--success);
|
||||
}
|
||||
|
||||
.state[data-state="running"] {
|
||||
color: var(--info);
|
||||
}
|
||||
|
||||
.state[data-state="failed"] {
|
||||
color: var(--destructive);
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.canvas {
|
||||
height: 520px;
|
||||
}
|
||||
}
|
||||
279
ui/litellm-dashboard/src/components/workflows/WorkflowGraph.tsx
Normal file
279
ui/litellm-dashboard/src/components/workflows/WorkflowGraph.tsx
Normal file
|
|
@ -0,0 +1,279 @@
|
|||
"use client";
|
||||
|
||||
import { useId, useMemo } from "react";
|
||||
import {
|
||||
ArrowDownToLine,
|
||||
Braces,
|
||||
Check,
|
||||
Circle,
|
||||
Code2,
|
||||
GitBranch,
|
||||
Loader2,
|
||||
Maximize,
|
||||
Minus,
|
||||
Plus,
|
||||
Sparkles,
|
||||
X,
|
||||
} from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { cn } from "@/lib/cva.config";
|
||||
import {
|
||||
executionStates,
|
||||
nodeTitle,
|
||||
readWorkflowDefinition,
|
||||
sequentialConnections,
|
||||
type CompiledWorkflowBundle,
|
||||
type WorkflowExecutionOverlay,
|
||||
type WorkflowNodeState,
|
||||
} from "./definition";
|
||||
import { graphSize, MAX_SCALE, MIN_SCALE, NODE_HEIGHT, NODE_WIDTH, nodePosition } from "./viewport";
|
||||
import { useWorkflowViewport } from "./useWorkflowViewport";
|
||||
import styles from "./WorkflowGraph.module.css";
|
||||
|
||||
export interface WorkflowGraphProps {
|
||||
bundle: unknown;
|
||||
definitionKey: string;
|
||||
selectedNodeId: string | null;
|
||||
onNodeSelect: (nodeId: string | null) => void;
|
||||
execution?: WorkflowExecutionOverlay;
|
||||
loading?: boolean;
|
||||
error?: string | null;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export function WorkflowNodeStatus({ state }: { state: WorkflowNodeState }) {
|
||||
const { t } = useTranslation();
|
||||
const icons = { pending: Circle, running: Loader2, completed: Check, failed: X, cancelled: Minus };
|
||||
const Icon = icons[state];
|
||||
return (
|
||||
<span className={styles.state} data-state={state}>
|
||||
<Icon aria-hidden className={cn("size-3", state === "running" && "motion-safe:animate-spin")} />
|
||||
{t(`workflowGraph.states.${state}`)}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
function connectionPath(start: { x: number; y: number }, end: { x: number; y: number }) {
|
||||
const middle = (start.y + end.y) / 2;
|
||||
return `M ${start.x} ${start.y} C ${start.x} ${middle}, ${end.x} ${middle}, ${end.x} ${end.y}`;
|
||||
}
|
||||
|
||||
function GraphConnections({ bundle }: { bundle: CompiledWorkflowBundle }) {
|
||||
const marker = useId();
|
||||
const size = graphSize(bundle.nodes.length);
|
||||
const positions = new Map(bundle.nodes.map((node, index) => [node.id, nodePosition(index)]));
|
||||
const first = nodePosition(0);
|
||||
const last = nodePosition(bundle.nodes.length - 1);
|
||||
return (
|
||||
<svg
|
||||
width={size.width}
|
||||
height={size.height}
|
||||
className="pointer-events-none absolute inset-0 overflow-visible"
|
||||
aria-hidden
|
||||
>
|
||||
<defs>
|
||||
<marker
|
||||
id={marker}
|
||||
viewBox="0 0 10 10"
|
||||
refX="8"
|
||||
refY="5"
|
||||
markerWidth="5"
|
||||
markerHeight="5"
|
||||
orient="auto-start-reverse"
|
||||
>
|
||||
<path d="M 0 0 L 10 5 L 0 10" fill="var(--info)" />
|
||||
</marker>
|
||||
</defs>
|
||||
<g fill="none" stroke="var(--info)" strokeWidth="1.5" strokeOpacity="0.65" markerEnd={`url(#${marker})`}>
|
||||
<path d={connectionPath({ x: 200, y: 44 }, { x: first.x + NODE_WIDTH / 2, y: first.y - 6 })} />
|
||||
{sequentialConnections(bundle.nodes).map(({ source, target }) => {
|
||||
const from = positions.get(source)!;
|
||||
const to = positions.get(target)!;
|
||||
return (
|
||||
<path
|
||||
key={`${source}:${target}`}
|
||||
d={connectionPath(
|
||||
{ x: from.x + NODE_WIDTH / 2, y: from.y + NODE_HEIGHT },
|
||||
{ x: to.x + NODE_WIDTH / 2, y: to.y - 6 },
|
||||
)}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
<path
|
||||
d={connectionPath({ x: last.x + NODE_WIDTH / 2, y: last.y + NODE_HEIGHT }, { x: 200, y: size.height - 38 })}
|
||||
/>
|
||||
</g>
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
|
||||
function SequentialGraph({
|
||||
bundle,
|
||||
definitionKey,
|
||||
selectedNodeId,
|
||||
onNodeSelect,
|
||||
execution,
|
||||
}: Omit<WorkflowGraphProps, "bundle"> & { bundle: CompiledWorkflowBundle }) {
|
||||
const { t } = useTranslation();
|
||||
const hintId = useId();
|
||||
const size = graphSize(bundle.nodes.length);
|
||||
const { surfaceRef, view, zoom, fit, revealNode, handlers } = useWorkflowViewport(size);
|
||||
const states = executionStates(definitionKey, execution);
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="pointer-events-none absolute left-4 top-4 flex items-center gap-2 rounded-md border border-border bg-background/95 px-3 py-2 text-xs text-muted-foreground">
|
||||
<GitBranch className="size-3.5" aria-hidden />
|
||||
{t("workflowGraph.sequential")} <span aria-hidden>·</span>{" "}
|
||||
{t("workflowGraph.stepCount", { count: bundle.nodes.length })}
|
||||
</div>
|
||||
<div
|
||||
ref={surfaceRef}
|
||||
className={styles.surface}
|
||||
role="region"
|
||||
tabIndex={0}
|
||||
aria-label={t("workflowGraph.canvas")}
|
||||
aria-describedby={hintId}
|
||||
{...handlers}
|
||||
>
|
||||
<div
|
||||
className={styles.stage}
|
||||
style={{
|
||||
width: size.width,
|
||||
height: size.height,
|
||||
transform: `translate(${view.x}px, ${view.y}px) scale(${view.scale})`,
|
||||
}}
|
||||
>
|
||||
<GraphConnections bundle={bundle} />
|
||||
<div className={styles.terminal} style={{ top: 12 }}>
|
||||
<Braces className="size-3.5 text-info" aria-hidden />
|
||||
{t("workflowGraph.input")}
|
||||
</div>
|
||||
{bundle.nodes.map((node, index) => {
|
||||
const position = nodePosition(index);
|
||||
const state = states?.[node.id];
|
||||
const Icon = node.type === "python" ? Code2 : Sparkles;
|
||||
return (
|
||||
<Button
|
||||
key={node.id}
|
||||
type="button"
|
||||
variant="outline"
|
||||
className={styles.node}
|
||||
style={{ left: position.x, top: position.y, width: NODE_WIDTH, height: NODE_HEIGHT }}
|
||||
aria-label={t("workflowGraph.nodeLabel", {
|
||||
index: index + 1,
|
||||
title: nodeTitle(node),
|
||||
type: t(`workflowGraph.types.${node.type}`),
|
||||
})}
|
||||
aria-pressed={selectedNodeId === node.id}
|
||||
onClick={() => onNodeSelect(node.id)}
|
||||
onFocus={() => revealNode(position)}
|
||||
>
|
||||
<span className={styles.port} style={{ top: -5 }} aria-hidden />
|
||||
<span className="flex w-full items-center justify-between gap-2">
|
||||
<span className="flex items-center gap-2 text-xs text-muted-foreground">
|
||||
<Icon className="size-4 text-info" aria-hidden />
|
||||
{t(`workflowGraph.types.${node.type}`)}
|
||||
</span>
|
||||
<span className="text-xs tabular-nums text-muted-foreground">
|
||||
{String(index + 1).padStart(2, "0")}
|
||||
</span>
|
||||
</span>
|
||||
<span className="w-full truncate text-sm font-medium" title={nodeTitle(node)}>
|
||||
{nodeTitle(node)}
|
||||
</span>
|
||||
<span className="flex w-full items-center justify-between gap-2">
|
||||
<span className="truncate font-mono text-xs text-muted-foreground">{node.id}</span>
|
||||
{state && <WorkflowNodeStatus state={state} />}
|
||||
</span>
|
||||
<span className={styles.port} style={{ bottom: -5 }} aria-hidden />
|
||||
</Button>
|
||||
);
|
||||
})}
|
||||
<div className={styles.terminal} style={{ top: size.height - 32 }}>
|
||||
<ArrowDownToLine className="size-3.5 text-info" aria-hidden />
|
||||
{t("workflowGraph.output")}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="pointer-events-none absolute bottom-4 left-4 right-4 flex items-end justify-between gap-2">
|
||||
<p
|
||||
id={hintId}
|
||||
className="sr-only sm:not-sr-only sm:max-w-64 sm:rounded-md sm:bg-background/95 sm:p-2 sm:text-xs sm:text-muted-foreground"
|
||||
>
|
||||
{t("workflowGraph.navigationHint")}
|
||||
</p>
|
||||
<p className="rounded-md bg-background/95 p-2 text-xs text-muted-foreground sm:hidden">
|
||||
{t("workflowGraph.panHint")}
|
||||
</p>
|
||||
<div className="pointer-events-auto flex items-center gap-1 rounded-lg border border-border bg-card p-1 shadow-sm">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
aria-label={t("workflowGraph.zoomOut")}
|
||||
disabled={view.scale <= MIN_SCALE}
|
||||
onClick={() => zoom(1 / 1.2)}
|
||||
>
|
||||
<Minus />
|
||||
</Button>
|
||||
<output className="w-12 text-center text-xs tabular-nums" aria-label={t("workflowGraph.zoomLevel")}>
|
||||
{Math.round(view.scale * 100)}%
|
||||
</output>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
aria-label={t("workflowGraph.zoomIn")}
|
||||
disabled={view.scale >= MAX_SCALE}
|
||||
onClick={() => zoom(1.2)}
|
||||
>
|
||||
<Plus />
|
||||
</Button>
|
||||
<span className="mx-1 h-4 border-l border-border" />
|
||||
<Button variant="ghost" size="icon-sm" aria-label={t("workflowGraph.fit")} onClick={fit}>
|
||||
<Maximize />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export function WorkflowGraph(props: WorkflowGraphProps) {
|
||||
const { t } = useTranslation();
|
||||
const definition = useMemo(() => readWorkflowDefinition(props.bundle), [props.bundle]);
|
||||
const contentClass = "flex h-full flex-col items-center justify-center gap-3 px-8 text-center";
|
||||
if (props.loading) {
|
||||
return (
|
||||
<div className={cn(styles.canvas, props.className)} role="status" aria-label={t("workflowGraph.loading")}>
|
||||
<div className={contentClass}>
|
||||
<Skeleton className="h-24 w-64" />
|
||||
<Skeleton className="h-24 w-64" />
|
||||
<p className="text-sm text-muted-foreground">{t("workflowGraph.loading")}</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
if (props.error || definition.kind !== "ready") {
|
||||
const kind = props.error || definition.kind === "ready" ? "error" : definition.kind;
|
||||
const description = definition.kind === "ready" ? "" : t(`workflowGraph.${definition.kind}Description`);
|
||||
return (
|
||||
<div className={cn(styles.canvas, props.className)}>
|
||||
<div className={contentClass} role={kind === "error" || kind === "invalid" ? "alert" : "status"}>
|
||||
<GitBranch className="size-8 text-muted-foreground" aria-hidden />
|
||||
<p className="font-medium">{t(`workflowGraph.${kind}Title`)}</p>
|
||||
<p className="max-w-sm text-sm text-muted-foreground">{props.error ?? description}</p>
|
||||
{definition.kind === "unsupported" && (
|
||||
<code className="max-w-full break-all text-xs">{definition.detail}</code>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<div className={cn(styles.canvas, props.className)}>
|
||||
<SequentialGraph key={props.definitionKey} {...props} bundle={definition.bundle} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
import drafts from "../../../tests/fixtures/workflows/drafts.json";
|
||||
import { executionStates, readWorkflowDefinition, sequentialConnections } from "./definition";
|
||||
|
||||
const bundle = drafts["email-reply"].bundle;
|
||||
|
||||
describe("compiled workflow definitions", () => {
|
||||
it("preserves the SDK bundle fields needed by the inspector", () => {
|
||||
const definition = readWorkflowDefinition(bundle);
|
||||
expect(definition.kind).toBe("ready");
|
||||
if (definition.kind !== "ready") return;
|
||||
expect(definition.bundle).toEqual(bundle);
|
||||
});
|
||||
|
||||
it("connects adjacent nodes in compiler order, including when IDs are not sorted", () => {
|
||||
const definition = readWorkflowDefinition(bundle);
|
||||
if (definition.kind !== "ready") throw new Error("Expected a usable SDK fixture");
|
||||
const nodes = [...definition.bundle.nodes].reverse();
|
||||
expect(sequentialConnections(nodes)).toEqual(
|
||||
nodes.slice(1).map((node, index) => ({ source: nodes[index].id, target: node.id })),
|
||||
);
|
||||
expect(sequentialConnections(nodes.slice(0, 1))).toEqual([]);
|
||||
});
|
||||
|
||||
it.each([null, { ...bundle, nodes: [] }])("handles an empty definition", (value) => {
|
||||
expect(readWorkflowDefinition(value).kind).toBe("empty");
|
||||
});
|
||||
|
||||
it.each([
|
||||
{ ...bundle, contract_version: "future" },
|
||||
{ ...bundle, nodes: [{ id: "branch", type: "if" }] },
|
||||
{ ...bundle, nodes: [{ id: "parallel", type: "parallel" }] },
|
||||
])("declines unsupported semantics instead of drawing a sequential graph", (value) => {
|
||||
expect(readWorkflowDefinition(value).kind).toBe("unsupported");
|
||||
});
|
||||
|
||||
it.each([
|
||||
{},
|
||||
{ ...bundle, nodes: [bundle.nodes[0], bundle.nodes[0]] },
|
||||
{ ...bundle, nodes: [{ ...bundle.nodes[0], messages: { from: "$input" } }] },
|
||||
])("rejects malformed bundles and ambiguous node IDs", (value) => {
|
||||
expect(readWorkflowDefinition(value).kind).toBe("invalid");
|
||||
});
|
||||
|
||||
it("requires the overlay to match the displayed definition", () => {
|
||||
const overlay = { definitionKey: "snapshot-1", states: { node_2: "failed" as const } };
|
||||
expect(executionStates("snapshot-1", overlay)).toEqual(overlay.states);
|
||||
expect(executionStates("snapshot-2", overlay)).toBeUndefined();
|
||||
expect(executionStates("snapshot-1")).toBeUndefined();
|
||||
});
|
||||
});
|
||||
108
ui/litellm-dashboard/src/components/workflows/definition.ts
Normal file
108
ui/litellm-dashboard/src/components/workflows/definition.ts
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
import { z } from "zod";
|
||||
|
||||
const jsonSchema = z.record(z.string(), z.unknown());
|
||||
const reference = z.object({ from: z.string().min(1), output: z.string().min(1) });
|
||||
const binding = z.union([reference, z.object({ value: z.json() })]);
|
||||
const commonNode = {
|
||||
id: z.string().min(1),
|
||||
timeout_seconds: z.number().positive(),
|
||||
retry: z.object({ max_attempts: z.number().int().positive(), backoff_seconds: z.number().nonnegative() }),
|
||||
};
|
||||
const structuredOutputFields = { name: z.string(), strict: z.boolean(), schema: jsonSchema };
|
||||
const chatNodeFields = {
|
||||
...commonNode,
|
||||
type: z.literal("chat_completion"),
|
||||
model: z.string().min(1),
|
||||
messages: binding,
|
||||
temperature: z.number().optional(),
|
||||
top_p: z.number().optional(),
|
||||
max_tokens: z.number().optional(),
|
||||
max_completion_tokens: z.number().optional(),
|
||||
seed: z.number().optional(),
|
||||
stop: z.union([z.string(), z.array(z.string())]).optional(),
|
||||
response_format: z
|
||||
.object({
|
||||
type: z.literal("json_schema"),
|
||||
json_schema: z.object(structuredOutputFields),
|
||||
})
|
||||
.optional(),
|
||||
};
|
||||
const chatNode = z.looseObject(chatNodeFields);
|
||||
const programFields = {
|
||||
contract_version: z.literal("1"),
|
||||
source: z.string(),
|
||||
function_name: z.string().min(1),
|
||||
parameter_names: z.array(z.string()),
|
||||
input_schema: jsonSchema,
|
||||
output_schema: jsonSchema,
|
||||
source_sha256: z.string(),
|
||||
};
|
||||
const pythonNodeFields = {
|
||||
...commonNode,
|
||||
type: z.literal("python"),
|
||||
inputs: z.record(z.string(), binding),
|
||||
program: z.object(programFields),
|
||||
};
|
||||
const pythonNode = z.looseObject(pythonNodeFields);
|
||||
|
||||
const compiledBundleFields = {
|
||||
contract_version: z.literal("1"),
|
||||
name: z.string().min(1),
|
||||
timeout_seconds: z.number().positive(),
|
||||
input_schema: jsonSchema,
|
||||
output: reference,
|
||||
nodes: z.array(z.discriminatedUnion("type", [chatNode, pythonNode])),
|
||||
};
|
||||
const compiledBundle = z.looseObject(compiledBundleFields);
|
||||
|
||||
export type CompiledWorkflowBundle = z.infer<typeof compiledBundle>;
|
||||
export type CompiledWorkflowNode = CompiledWorkflowBundle["nodes"][number];
|
||||
export type WorkflowBinding = z.infer<typeof binding>;
|
||||
export type WorkflowNodeState = "pending" | "running" | "completed" | "failed" | "cancelled";
|
||||
|
||||
export interface WorkflowExecutionOverlay {
|
||||
definitionKey: string;
|
||||
states: Readonly<Record<string, WorkflowNodeState>>;
|
||||
}
|
||||
|
||||
export type WorkflowDefinition =
|
||||
| { kind: "ready"; bundle: CompiledWorkflowBundle }
|
||||
| { kind: "empty" }
|
||||
| { kind: "unsupported"; detail: string }
|
||||
| { kind: "invalid" };
|
||||
|
||||
const envelope = z.object({
|
||||
contract_version: z.string(),
|
||||
nodes: z.array(z.looseObject({ type: z.string() })),
|
||||
});
|
||||
|
||||
export function readWorkflowDefinition(value: unknown): WorkflowDefinition {
|
||||
if (value == null) return { kind: "empty" };
|
||||
const outer = envelope.safeParse(value);
|
||||
if (!outer.success) return { kind: "invalid" };
|
||||
if (outer.data.contract_version !== "1") {
|
||||
return { kind: "unsupported", detail: `contract_version ${outer.data.contract_version}` };
|
||||
}
|
||||
const unsupported = outer.data.nodes.filter((node) => !["chat_completion", "python"].includes(node.type));
|
||||
if (unsupported.length > 0) {
|
||||
return { kind: "unsupported", detail: [...new Set(unsupported.map((node) => node.type))].join(", ") };
|
||||
}
|
||||
const parsed = compiledBundle.safeParse(value);
|
||||
if (!parsed.success) return { kind: "invalid" };
|
||||
const ids = parsed.data.nodes.map((node) => node.id);
|
||||
if (new Set(ids).size !== ids.length) return { kind: "invalid" };
|
||||
if (ids.length === 0) return { kind: "empty" };
|
||||
return { kind: "ready", bundle: parsed.data };
|
||||
}
|
||||
|
||||
export function nodeTitle(node: CompiledWorkflowNode): string {
|
||||
return node.type === "chat_completion" ? node.model : node.program.function_name;
|
||||
}
|
||||
|
||||
export function sequentialConnections(nodes: readonly CompiledWorkflowNode[]) {
|
||||
return nodes.slice(1).map((node, index) => ({ source: nodes[index].id, target: node.id }));
|
||||
}
|
||||
|
||||
export function executionStates(definitionKey: string, overlay?: WorkflowExecutionOverlay) {
|
||||
return overlay?.definitionKey === definitionKey ? overlay.states : undefined;
|
||||
}
|
||||
9
ui/litellm-dashboard/src/components/workflows/index.ts
Normal file
9
ui/litellm-dashboard/src/components/workflows/index.ts
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
export { WorkflowGraph, type WorkflowGraphProps } from "./WorkflowGraph";
|
||||
export { WorkflowDefinitionInspector, type WorkflowDefinitionInspectorProps } from "./WorkflowDefinitionInspector";
|
||||
export { WorkflowDefinitionView } from "./WorkflowDefinitionView";
|
||||
export type {
|
||||
CompiledWorkflowBundle,
|
||||
CompiledWorkflowNode,
|
||||
WorkflowExecutionOverlay,
|
||||
WorkflowNodeState,
|
||||
} from "./definition";
|
||||
|
|
@ -0,0 +1,123 @@
|
|||
"use client";
|
||||
|
||||
import { useEffect, useMemo, useRef, useState, type KeyboardEvent, type PointerEvent } from "react";
|
||||
import { fitViewport, NODE_HEIGHT, NODE_WIDTH, zoomViewport, type Size, type Viewport } from "./viewport";
|
||||
|
||||
export function useWorkflowViewport(graph: Size) {
|
||||
const surfaceRef = useRef<HTMLDivElement>(null);
|
||||
const drag = useRef<{ x: number; y: number; view: Viewport } | null>(null);
|
||||
const [size, setSize] = useState<Size>({ width: 600, height: 640 });
|
||||
const [manualView, setManualView] = useState<Viewport | null>(null);
|
||||
const { width, height } = graph;
|
||||
const fitted = useMemo(() => fitViewport(size, { width, height }), [size, width, height]);
|
||||
const view = manualView ?? fitted;
|
||||
|
||||
useEffect(() => {
|
||||
const surface = surfaceRef.current;
|
||||
if (!surface) return;
|
||||
const observer = new ResizeObserver(([entry]) => {
|
||||
if (entry.contentRect.width > 0 && entry.contentRect.height > 0) {
|
||||
setSize({ width: entry.contentRect.width, height: entry.contentRect.height });
|
||||
}
|
||||
});
|
||||
observer.observe(surface);
|
||||
return () => observer.disconnect();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const surface = surfaceRef.current;
|
||||
if (!surface) return;
|
||||
const handleWheel = (event: WheelEvent) => {
|
||||
event.preventDefault();
|
||||
const bounds = surface.getBoundingClientRect();
|
||||
const delta = event.deltaMode === 1 ? 16 : 1;
|
||||
setManualView((current) => {
|
||||
const previous = current ?? fitted;
|
||||
if (event.ctrlKey || event.metaKey) {
|
||||
return zoomViewport(previous, Math.exp(-event.deltaY * delta * 0.005), {
|
||||
x: event.clientX - bounds.left,
|
||||
y: event.clientY - bounds.top,
|
||||
});
|
||||
}
|
||||
return { ...previous, x: previous.x - event.deltaX * delta, y: previous.y - event.deltaY * delta };
|
||||
});
|
||||
};
|
||||
surface.addEventListener("wheel", handleWheel, { passive: false });
|
||||
return () => surface.removeEventListener("wheel", handleWheel);
|
||||
}, [fitted]);
|
||||
|
||||
function zoom(factor: number) {
|
||||
setManualView(zoomViewport(view, factor, { x: size.width / 2, y: size.height / 2 }));
|
||||
}
|
||||
|
||||
function onPointerDown(event: PointerEvent<HTMLDivElement>) {
|
||||
if (event.button !== 0 || (event.target instanceof Element && event.target.closest("button"))) return;
|
||||
drag.current = { x: event.clientX, y: event.clientY, view };
|
||||
event.currentTarget.setPointerCapture(event.pointerId);
|
||||
event.currentTarget.focus();
|
||||
}
|
||||
|
||||
function onPointerMove(event: PointerEvent<HTMLDivElement>) {
|
||||
if (!drag.current) return;
|
||||
const start = drag.current;
|
||||
setManualView({
|
||||
...start.view,
|
||||
x: start.view.x + event.clientX - start.x,
|
||||
y: start.view.y + event.clientY - start.y,
|
||||
});
|
||||
}
|
||||
|
||||
function endDrag() {
|
||||
drag.current = null;
|
||||
}
|
||||
|
||||
function onKeyDown(event: KeyboardEvent<HTMLDivElement>) {
|
||||
if (event.target !== event.currentTarget) return;
|
||||
const movements: Record<string, [number, number]> = {
|
||||
ArrowLeft: [48, 0],
|
||||
ArrowRight: [-48, 0],
|
||||
ArrowUp: [0, 48],
|
||||
ArrowDown: [0, -48],
|
||||
};
|
||||
const movement = movements[event.key];
|
||||
if (movement) {
|
||||
event.preventDefault();
|
||||
setManualView({ ...view, x: view.x + movement[0], y: view.y + movement[1] });
|
||||
}
|
||||
if (["+", "=", "-", "0"].includes(event.key)) {
|
||||
event.preventDefault();
|
||||
if (event.key === "0") setManualView(null);
|
||||
else zoom(event.key === "-" ? 1 / 1.2 : 1.2);
|
||||
}
|
||||
}
|
||||
|
||||
function revealNode(position: { x: number; y: number }) {
|
||||
const left = view.x + position.x * view.scale;
|
||||
const top = view.y + position.y * view.scale;
|
||||
const outsideWidth = left < 0 || left + NODE_WIDTH * view.scale > size.width;
|
||||
const outsideHeight = top < 0 || top + NODE_HEIGHT * view.scale > size.height;
|
||||
if (outsideWidth || outsideHeight) {
|
||||
setManualView({
|
||||
...view,
|
||||
x: size.width / 2 - (position.x + NODE_WIDTH / 2) * view.scale,
|
||||
y: size.height / 2 - (position.y + NODE_HEIGHT / 2) * view.scale,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
surfaceRef,
|
||||
view,
|
||||
zoom,
|
||||
fit: () => setManualView(null),
|
||||
revealNode,
|
||||
handlers: {
|
||||
onPointerDown,
|
||||
onPointerMove,
|
||||
onPointerUp: endDrag,
|
||||
onPointerCancel: endDrag,
|
||||
onLostPointerCapture: endDrag,
|
||||
onKeyDown,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
import { fitViewport, graphSize, MAX_SCALE, MIN_SCALE, NODE_HEIGHT, nodePosition, zoomViewport } from "./viewport";
|
||||
|
||||
describe("workflow viewport", () => {
|
||||
it.each([3, 120])("fits %i sequential steps and terminals inside the canvas", (count) => {
|
||||
const container = { width: 720, height: 640 };
|
||||
const graph = graphSize(count);
|
||||
const view = fitViewport(container, graph);
|
||||
expect(view.x).toBeGreaterThanOrEqual(0);
|
||||
expect(view.y).toBeGreaterThanOrEqual(0);
|
||||
expect(view.x + graph.width * view.scale).toBeLessThanOrEqual(container.width);
|
||||
expect(view.y + graph.height * view.scale).toBeLessThanOrEqual(container.height);
|
||||
expect(nodePosition(2).y + NODE_HEIGHT).toBeLessThan(graph.height);
|
||||
});
|
||||
|
||||
it("keeps the zoom anchor fixed while enforcing usable scale limits", () => {
|
||||
const view = { x: 20, y: 40, scale: 0.5 };
|
||||
const anchor = { x: 300, y: 200 };
|
||||
const zoomed = zoomViewport(view, 1.2, anchor);
|
||||
expect((anchor.x - zoomed.x) / zoomed.scale).toBeCloseTo((anchor.x - view.x) / view.scale);
|
||||
expect((anchor.y - zoomed.y) / zoomed.scale).toBeCloseTo((anchor.y - view.y) / view.scale);
|
||||
expect(zoomViewport(view, 100, anchor).scale).toBe(MAX_SCALE);
|
||||
expect(zoomViewport(view, 0, anchor).scale).toBe(MIN_SCALE);
|
||||
});
|
||||
});
|
||||
40
ui/litellm-dashboard/src/components/workflows/viewport.ts
Normal file
40
ui/litellm-dashboard/src/components/workflows/viewport.ts
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
export interface Size {
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
|
||||
export interface Viewport {
|
||||
x: number;
|
||||
y: number;
|
||||
scale: number;
|
||||
}
|
||||
|
||||
export const NODE_WIDTH = 288;
|
||||
export const NODE_HEIGHT = 112;
|
||||
export const NODE_GAP = 64;
|
||||
export const GRAPH_WIDTH = 400;
|
||||
export const MIN_SCALE = 0.1;
|
||||
export const MAX_SCALE = 2;
|
||||
|
||||
export function nodePosition(index: number) {
|
||||
return { x: index % 2 === 0 ? 44 : 68, y: 100 + index * (NODE_HEIGHT + NODE_GAP) };
|
||||
}
|
||||
|
||||
export function graphSize(nodeCount: number): Size {
|
||||
return { width: GRAPH_WIDTH, height: 100 + nodeCount * (NODE_HEIGHT + NODE_GAP) + 24 };
|
||||
}
|
||||
|
||||
export function fitViewport(container: Size, graph: Size): Viewport {
|
||||
const scale = Math.min(
|
||||
1,
|
||||
Math.max(1, container.width - 64) / graph.width,
|
||||
Math.max(1, container.height - 128) / graph.height,
|
||||
);
|
||||
return { x: (container.width - graph.width * scale) / 2, y: (container.height - graph.height * scale) / 2, scale };
|
||||
}
|
||||
|
||||
export function zoomViewport(view: Viewport, factor: number, anchor: { x: number; y: number }): Viewport {
|
||||
const scale = Math.max(MIN_SCALE, Math.min(MAX_SCALE, view.scale * factor));
|
||||
const ratio = scale / view.scale;
|
||||
return { x: anchor.x - (anchor.x - view.x) * ratio, y: anchor.y - (anchor.y - view.y) * ratio, scale };
|
||||
}
|
||||
|
|
@ -4138,6 +4138,57 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"workflowGraph": {
|
||||
"sequential": "Sequential",
|
||||
"stepCount_one": "{{count}} step",
|
||||
"stepCount_other": "{{count}} steps",
|
||||
"canvas": "Workflow graph",
|
||||
"nodeLabel": "Step {{index}}: {{title}} ({{type}})",
|
||||
"input": "Workflow input",
|
||||
"output": "Workflow output",
|
||||
"navigationHint": "Drag or scroll to pan. Ctrl / ⌘ + scroll to zoom. Arrow keys pan; + / − zoom; 0 fits.",
|
||||
"panHint": "Drag to pan",
|
||||
"zoomOut": "Zoom out",
|
||||
"zoomIn": "Zoom in",
|
||||
"zoomLevel": "Zoom level",
|
||||
"fit": "Fit to view",
|
||||
"loading": "Loading workflow definition",
|
||||
"emptyTitle": "No workflow to visualize",
|
||||
"emptyDescription": "Select a registered workflow with at least one compiled node to see its definition.",
|
||||
"unsupportedTitle": "This definition is not supported yet",
|
||||
"unsupportedDescription": "This view supports contract version 1 with sequential ChatCompletion and Python nodes. Parallel and If nodes will follow.",
|
||||
"invalidTitle": "Unable to read this definition",
|
||||
"invalidDescription": "The bundle does not match the LiteFlow compiled contract, or contains duplicate node IDs.",
|
||||
"errorTitle": "Unable to load the workflow",
|
||||
"literal": "Literal value",
|
||||
"inputSchema": "Input schema",
|
||||
"outputSchema": "Output schema",
|
||||
"textOutput": "Text result. No structured output schema is configured.",
|
||||
"timeout": "Timeout",
|
||||
"attempts": "Max attempts",
|
||||
"backoff": "Retry backoff",
|
||||
"seconds_one": "{{count}} s",
|
||||
"seconds_other": "{{count}} s",
|
||||
"modelParameters": "Model parameters",
|
||||
"inspector": "Workflow definition inspector",
|
||||
"definition": "Definition",
|
||||
"clearSelection": "Clear node selection",
|
||||
"workflowTimeout": "Workflow timeout {{seconds}} s",
|
||||
"selectHint": "Select a step to inspect its bindings, schemas and configuration.",
|
||||
"schemas": "Schemas",
|
||||
"bindings": "Input bindings",
|
||||
"configuration": "Execution configuration",
|
||||
"program": "Python program",
|
||||
"source": "View compiled source",
|
||||
"types": { "chat_completion": "ChatCompletion", "python": "Python" },
|
||||
"states": {
|
||||
"pending": "Pending",
|
||||
"running": "Running",
|
||||
"completed": "Completed",
|
||||
"failed": "Failed",
|
||||
"cancelled": "Cancelled"
|
||||
}
|
||||
},
|
||||
"workflows": {
|
||||
"page": {
|
||||
"title": "Workflow Runs",
|
||||
|
|
|
|||
20
ui/litellm-dashboard/tests/fixtures/workflows/README.md
vendored
Normal file
20
ui/litellm-dashboard/tests/fixtures/workflows/README.md
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# SDK fixture provenance
|
||||
|
||||
`drafts.json` was generated by the actual SDK at the head of LiteFlow PR #3, commit `ec8a59083494f1c36b3a2561a60a4a7882404d59`. `generate.py` calls `compile_workflow`, computes the bundle digest with `bundle_digest` and serializes the SDK's `Draft` model. Only the workflow/team IDs and ETag are fixture metadata
|
||||
|
||||
The generation environment used Python 3.13, `openai==2.54.0`, `pydantic==2.14.3` and `httpx==0.28.1`. Pinning these dependencies also pins the generated OpenAI message schemas
|
||||
|
||||
From this directory, create an isolated environment and regenerate
|
||||
|
||||
```sh
|
||||
python3.13 -m venv /tmp/liteflow-graph-fixtures
|
||||
/tmp/liteflow-graph-fixtures/bin/pip install \
|
||||
'liteflow @ git+https://github.com/BerriAI/liteflow.git@ec8a59083494f1c36b3a2561a60a4a7882404d59' \
|
||||
'openai==2.54.0' 'pydantic==2.14.3' 'httpx==0.28.1'
|
||||
PYTHONDONTWRITEBYTECODE=1 /tmp/liteflow-graph-fixtures/bin/python generate.py
|
||||
../../../../../scripts/with_dashboard_node.sh npx prettier --write drafts.json
|
||||
```
|
||||
|
||||
The email reply example covers both node types, previous-step references, a literal Python argument, input/output schemas, structured ChatCompletion output and retry configuration. The welcome example covers a single node with literal messages
|
||||
|
||||
`WorkflowGraphDemo.tsx` supplies these bundles to the production components. Its execution overlays and unsupported-node example are explicitly synthetic. The demo imports fixtures only through a route guarded by `NODE_ENV === "development"`
|
||||
76
ui/litellm-dashboard/tests/fixtures/workflows/WorkflowGraphDemo.tsx
vendored
Normal file
76
ui/litellm-dashboard/tests/fixtures/workflows/WorkflowGraphDemo.tsx
vendored
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { GitBranch } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { WorkflowDefinitionView, type WorkflowExecutionOverlay } from "@/components/workflows";
|
||||
import drafts from "./drafts.json";
|
||||
|
||||
const draft = drafts["email-reply"];
|
||||
const definitionKey = `${draft.workflow_id}:${draft.etag}`;
|
||||
const examples = ["Definition", "Running", "Failed", "Completed", "Loading", "Empty", "Unsupported"] as const;
|
||||
type Example = (typeof examples)[number];
|
||||
|
||||
function overlayFor(example: Example): WorkflowExecutionOverlay | undefined {
|
||||
if (example === "Running")
|
||||
return { definitionKey, states: { node_1: "completed", node_2: "running", node_3: "pending" } };
|
||||
if (example === "Failed")
|
||||
return { definitionKey, states: { node_1: "completed", node_2: "failed", node_3: "cancelled" } };
|
||||
if (example === "Completed")
|
||||
return { definitionKey, states: { node_1: "completed", node_2: "completed", node_3: "completed" } };
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function bundleFor(example: Example) {
|
||||
if (example === "Empty") return null;
|
||||
if (example === "Unsupported") return { ...draft.bundle, nodes: [{ id: "future_node", type: "if" }] };
|
||||
return draft.bundle;
|
||||
}
|
||||
|
||||
export default function WorkflowGraphDemo() {
|
||||
const [selectedNodeId, setSelectedNodeId] = useState<string | null>(null);
|
||||
const [example, setExample] = useState<Example>("Definition");
|
||||
return (
|
||||
<div className="mx-auto max-w-7xl space-y-5 p-6">
|
||||
<div className="flex flex-wrap items-center justify-between gap-3">
|
||||
<div className="space-y-1">
|
||||
<p className="flex items-center gap-2 text-xs text-muted-foreground">
|
||||
<GitBranch className="size-3.5" />
|
||||
Workflows / Definition preview
|
||||
</p>
|
||||
<h1 className="text-2xl font-semibold tracking-tight">{draft.name}</h1>
|
||||
<p className="text-sm text-muted-foreground">Inspect how each step transforms your input</p>
|
||||
</div>
|
||||
<span className="rounded-full border border-border bg-muted px-3 py-1 text-xs font-medium">
|
||||
Read-only definition
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-2 rounded-lg border border-border bg-muted/40 p-3">
|
||||
<span className="mr-2 text-xs font-medium text-muted-foreground">Fixture preview</span>
|
||||
{examples.map((name) => (
|
||||
<Button
|
||||
key={name}
|
||||
size="sm"
|
||||
variant={example === name ? "default" : "ghost"}
|
||||
aria-pressed={example === name}
|
||||
onClick={() => setExample(name)}
|
||||
>
|
||||
{name}
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
<WorkflowDefinitionView
|
||||
bundle={bundleFor(example)}
|
||||
definitionKey={definitionKey}
|
||||
selectedNodeId={selectedNodeId}
|
||||
onNodeSelect={setSelectedNodeId}
|
||||
execution={overlayFor(example)}
|
||||
loading={example === "Loading"}
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Development only. Definitions compiled by the LiteFlow PR #3 SDK. Execution states are simulated fixtures. No
|
||||
gateway calls or workflow execution.
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
1786
ui/litellm-dashboard/tests/fixtures/workflows/drafts.json
vendored
Normal file
1786
ui/litellm-dashboard/tests/fixtures/workflows/drafts.json
vendored
Normal file
File diff suppressed because it is too large
Load diff
60
ui/litellm-dashboard/tests/fixtures/workflows/generate.py
vendored
Normal file
60
ui/litellm-dashboard/tests/fixtures/workflows/generate.py
vendored
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
import json
|
||||
from pathlib import Path
|
||||
from typing import Final
|
||||
|
||||
from liteflow.authoring import ChatCompletion, ChatMessage, Input, Python, Retry, Workflow
|
||||
from liteflow.client import Draft
|
||||
from liteflow.compiler import bundle_digest, compile_workflow
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
|
||||
|
||||
def prepare_followup(text: str, instruction: str) -> list[ChatMessage]:
|
||||
return [{"role": "user", "content": instruction + "\n\n" + text}]
|
||||
|
||||
|
||||
class Review(BaseModel):
|
||||
model_config = ConfigDict(frozen=True)
|
||||
summary: str
|
||||
approved: bool
|
||||
|
||||
|
||||
def draft_fixture(workflow: Workflow) -> Draft:
|
||||
bundle: Final = compile_workflow(workflow)
|
||||
digest: Final = bundle_digest(bundle)
|
||||
return Draft(
|
||||
name=workflow.name,
|
||||
workflow_id=f"fixture-{workflow.name}",
|
||||
team_id="fixture-team",
|
||||
etag=f'"{digest}"',
|
||||
digest=digest,
|
||||
bundle=bundle,
|
||||
)
|
||||
|
||||
|
||||
SEQUENTIAL: Final = Workflow(
|
||||
name="email-reply",
|
||||
nodes=(
|
||||
ChatCompletion(model="support-model", messages=Input.messages, temperature=0.4),
|
||||
Python(
|
||||
fn=prepare_followup,
|
||||
inputs={"text": Input.previous, "instruction": "Review this draft for clarity and accuracy"},
|
||||
timeout_seconds=15,
|
||||
retry=Retry(max_attempts=2, backoff_seconds=0.5),
|
||||
),
|
||||
ChatCompletion(model="review-model", messages=Input.previous, response_model=Review, max_completion_tokens=512),
|
||||
),
|
||||
)
|
||||
|
||||
LITERAL: Final = Workflow(
|
||||
name="welcome-message",
|
||||
nodes=(
|
||||
ChatCompletion(
|
||||
model="support-model",
|
||||
messages=({"role": "user", "content": "Write a short welcome message"},),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
FIXTURES: Final = {workflow.name: draft_fixture(workflow).model_dump(mode="json") for workflow in (SEQUENTIAL, LITERAL)}
|
||||
|
||||
Path(__file__).with_name("drafts.json").write_text(json.dumps(FIXTURES, indent=2) + "\n")
|
||||
59
ui/litellm-dashboard/tests/fixtures/workflows/serve-shell.mjs
vendored
Normal file
59
ui/litellm-dashboard/tests/fixtures/workflows/serve-shell.mjs
vendored
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
import { createServer } from "node:http";
|
||||
|
||||
const hostname = "127.0.0.1";
|
||||
const port = 3368;
|
||||
const dashboard = "http://workflow-graph.localhost:3367";
|
||||
const user = { user_id: "fixture-user", user_email: "preview@example.test", user_role: "proxy_admin" };
|
||||
const claims = {
|
||||
...user,
|
||||
key: "fixture-only-not-a-gateway-key",
|
||||
login_method: "sso",
|
||||
exp: Math.floor(Date.now() / 1000) + 86400,
|
||||
};
|
||||
const token = `${Buffer.from('{"alg":"HS256","typ":"JWT"}').toString("base64url")}.${Buffer.from(JSON.stringify(claims)).toString("base64url")}.fixture`;
|
||||
const responses = {
|
||||
"/litellm/.well-known/litellm-ui-config": { server_root_path: "", proxy_base_url: dashboard },
|
||||
"/ui/litellm-runtime-config.json": {},
|
||||
"/litellm-runtime-config.json": {},
|
||||
"/management/v1/users/me": user,
|
||||
"/get/ui_theme_settings": { values: {} },
|
||||
"/get/ui_settings": { values: { enable_projects_ui: false } },
|
||||
"/api/plugins": [],
|
||||
"/user/info": { user_id: user.user_id, user_info: { ...user, teams: [], models: [] }, teams: [], keys: [] },
|
||||
"/organization/info": [],
|
||||
"/team/list": [],
|
||||
"/sso/get/ui_settings": {},
|
||||
"/health/readiness/details": { status: "healthy" },
|
||||
"/health/deployment_warnings": { warnings: [], ignore_available: false },
|
||||
"/health/license": { has_license: false, allowed_features: [], limits: { max_users: null, max_teams: null } },
|
||||
"/user/available_users": { total_users_used: 1, total_teams_used: 0 },
|
||||
"/get/user_banner": { enabled: false, message: "", severity: "info" },
|
||||
"/get/latest_release_info": null,
|
||||
"/model/deprecations": { deprecated: [], imminent: [], upcoming: [] },
|
||||
"/telemetry/settings": { environment_variables: [], groups: [] },
|
||||
"/telemetry/ui_events/enabled": { enabled: false },
|
||||
"/health/readiness": { status: "healthy" },
|
||||
"/health/liveliness": { status: "healthy" },
|
||||
};
|
||||
|
||||
createServer((request, response) => {
|
||||
const pathname = new URL(request.url, dashboard).pathname;
|
||||
if (pathname === "/__workflow_fixture_login") {
|
||||
response.writeHead(302, {
|
||||
"Set-Cookie": `token=${token}; Path=/; SameSite=Lax; Max-Age=86400`,
|
||||
Location: `${dashboard}/workflows/graph-preview`,
|
||||
});
|
||||
response.end();
|
||||
return;
|
||||
}
|
||||
if (Object.hasOwn(responses, pathname)) {
|
||||
response.writeHead(200, { "Content-Type": "application/json" });
|
||||
response.end(JSON.stringify(responses[pathname]));
|
||||
return;
|
||||
}
|
||||
process.stdout.write(`Unconfigured shell fixture ${request.method} ${pathname}\n`);
|
||||
response.writeHead(404, { "Content-Type": "application/json" });
|
||||
response.end(JSON.stringify({ error: "No fixture for this request" }));
|
||||
}).listen(port, hostname, () => {
|
||||
process.stdout.write(`Fixture dashboard login ${dashboard}/__workflow_fixture_login\n`);
|
||||
});
|
||||
Loading…
Add table
Reference in a new issue