diff --git a/ui/litellm-dashboard/src/app/(dashboard)/workflows/graph-preview/page.tsx b/ui/litellm-dashboard/src/app/(dashboard)/workflows/graph-preview/page.tsx new file mode 100644 index 00000000000..fac5b391f6c --- /dev/null +++ b/ui/litellm-dashboard/src/app/(dashboard)/workflows/graph-preview/page.tsx @@ -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 ; + } + notFound(); +} diff --git a/ui/litellm-dashboard/src/components/workflows/README.md b/ui/litellm-dashboard/src/components/workflows/README.md new file mode 100644 index 00000000000..a17211603dd --- /dev/null +++ b/ui/litellm-dashboard/src/components/workflows/README.md @@ -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}`; + +; +``` + +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])), +}; + +; +``` + +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 +``` diff --git a/ui/litellm-dashboard/src/components/workflows/WorkflowDefinitionInspector.tsx b/ui/litellm-dashboard/src/components/workflows/WorkflowDefinitionInspector.tsx new file mode 100644 index 00000000000..c19e63509fd --- /dev/null +++ b/ui/litellm-dashboard/src/components/workflows/WorkflowDefinitionInspector.tsx @@ -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 ( +
+

{title}

+ {children} +
+ ); +} + +function InspectorDisclosure({ title, children }: { title: string; children: ReactNode }) { + return ( + + + {title} + + + +
{children}
+
+
+ ); +} + +function JsonDetails({ title, value }: { title: string; value: unknown }) { + return {JSON.stringify(value, null, 2)}; +} + +function BindingValue({ binding }: { binding: WorkflowBinding }) { + const { t } = useTranslation(); + if ("from" in binding) { + return ( +
+ {binding.from} + / + {binding.output} +
+ ); + } + return ; +} + +function NodeBindings({ node }: { node: CompiledWorkflowNode }) { + const bindings = node.type === "python" ? node.inputs : { messages: node.messages }; + return ( +
+ {Object.entries(bindings).map(([name, value]) => ( +
+
{name}
+
+ +
+
+ ))} +
+ ); +} + +function NodeSchemas({ bundle, node }: { bundle: CompiledWorkflowBundle; node: CompiledWorkflowNode }) { + const { t } = useTranslation(); + if (node.type === "python") { + return ( + <> + + + + ); + } + return ( + <> + + {node.response_format ? ( + + ) : ( +

{t("workflowGraph.textOutput")}

+ )} + + ); +} + +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 ( + <> +
+
{t("workflowGraph.timeout")}
+
{t("workflowGraph.seconds", { count: node.timeout_seconds })}
+
{t("workflowGraph.attempts")}
+
{node.retry.max_attempts}
+
{t("workflowGraph.backoff")}
+
{t("workflowGraph.seconds", { count: node.retry.backoff_seconds })}
+
+ {Object.keys(parameters).length > 0 && ( + + )} + + ); +} + +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 ( + +
+

{t("workflowGraph.definition")}

+ {node && ( + + )} +
+ {!node ? ( + <> +
+ +

{bundle.name}

+

+ {t("workflowGraph.workflowTimeout", { seconds: bundle.timeout_seconds })} +

+
+
+ + {t("workflowGraph.selectHint")} +
+ + + + + + + + ) : ( + <> +
+ + + {t(`workflowGraph.types.${node.type}`)} + +

{nodeTitle(node)}

+
+ {node.id} + {state && } +
+
+ + + + + + + + + + {node.type === "python" && ( + + {node.program.source} +

SHA-256 {node.program.source_sha256}

+
+ )} + + )} +
+ ); +} diff --git a/ui/litellm-dashboard/src/components/workflows/WorkflowDefinitionView.integration.test.tsx b/ui/litellm-dashboard/src/components/workflows/WorkflowDefinitionView.integration.test.tsx new file mode 100644 index 00000000000..cf75bf47698 --- /dev/null +++ b/ui/litellm-dashboard/src/components/workflows/WorkflowDefinitionView.integration.test.tsx @@ -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) { + const [selectedNodeId, onNodeSelect] = useState(null); + return ( + + ); +} + +describe("workflow definition view", () => { + it("selects the SDK Python node and inspects its bindings, schemas and retry settings", () => { + render(); + 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(); + 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(); + 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(); + const pythonNode = screen.getByRole("button", { name: /Step 2: prepare_followup/ }); + fireEvent.click(pythonNode); + expect(within(pythonNode).getByText("Running")).toBeInTheDocument(); + rerender(); + expect(within(pythonNode).getByText("Failed")).toBeInTheDocument(); + expect(pythonNode).toHaveAttribute("aria-pressed", "true"); + rerender(); + expect(screen.queryByText("Running")).not.toBeInTheDocument(); + expect(screen.queryByText("Failed")).not.toBeInTheDocument(); + }); + + it("zooms and fits through the graph controls", () => { + render(); + 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(); + expect(screen.getByText(text)).toBeInTheDocument(); + expect(screen.queryByRole("region", { name: "Workflow graph" })).not.toBeInTheDocument(); + expect(screen.queryByRole("complementary")).not.toBeInTheDocument(); + }); +}); diff --git a/ui/litellm-dashboard/src/components/workflows/WorkflowDefinitionView.tsx b/ui/litellm-dashboard/src/components/workflows/WorkflowDefinitionView.tsx new file mode 100644 index 00000000000..1dc8421965f --- /dev/null +++ b/ui/litellm-dashboard/src/components/workflows/WorkflowDefinitionView.tsx @@ -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 ( +
+ + +
+ ); +} diff --git a/ui/litellm-dashboard/src/components/workflows/WorkflowGraph.module.css b/ui/litellm-dashboard/src/components/workflows/WorkflowGraph.module.css new file mode 100644 index 00000000000..7ad87b7a000 --- /dev/null +++ b/ui/litellm-dashboard/src/components/workflows/WorkflowGraph.module.css @@ -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; + } +} diff --git a/ui/litellm-dashboard/src/components/workflows/WorkflowGraph.tsx b/ui/litellm-dashboard/src/components/workflows/WorkflowGraph.tsx new file mode 100644 index 00000000000..31856a2e7bc --- /dev/null +++ b/ui/litellm-dashboard/src/components/workflows/WorkflowGraph.tsx @@ -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 ( + + + {t(`workflowGraph.states.${state}`)} + + ); +} + +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 ( + + + + + + + + + {sequentialConnections(bundle.nodes).map(({ source, target }) => { + const from = positions.get(source)!; + const to = positions.get(target)!; + return ( + + ); + })} + + + + ); +} + +function SequentialGraph({ + bundle, + definitionKey, + selectedNodeId, + onNodeSelect, + execution, +}: Omit & { 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 ( + <> +
+ + {t("workflowGraph.sequential")} ·{" "} + {t("workflowGraph.stepCount", { count: bundle.nodes.length })} +
+
+
+ +
+ + {t("workflowGraph.input")} +
+ {bundle.nodes.map((node, index) => { + const position = nodePosition(index); + const state = states?.[node.id]; + const Icon = node.type === "python" ? Code2 : Sparkles; + return ( + + ); + })} +
+ + {t("workflowGraph.output")} +
+
+
+
+

+ {t("workflowGraph.navigationHint")} +

+

+ {t("workflowGraph.panHint")} +

+
+ + + {Math.round(view.scale * 100)}% + + + + +
+
+ + ); +} + +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 ( +
+
+ + +

{t("workflowGraph.loading")}

+
+
+ ); + } + 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 ( +
+
+ +

{t(`workflowGraph.${kind}Title`)}

+

{props.error ?? description}

+ {definition.kind === "unsupported" && ( + {definition.detail} + )} +
+
+ ); + } + return ( +
+ +
+ ); +} diff --git a/ui/litellm-dashboard/src/components/workflows/definition.test.ts b/ui/litellm-dashboard/src/components/workflows/definition.test.ts new file mode 100644 index 00000000000..0064b637be5 --- /dev/null +++ b/ui/litellm-dashboard/src/components/workflows/definition.test.ts @@ -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(); + }); +}); diff --git a/ui/litellm-dashboard/src/components/workflows/definition.ts b/ui/litellm-dashboard/src/components/workflows/definition.ts new file mode 100644 index 00000000000..38ec48de160 --- /dev/null +++ b/ui/litellm-dashboard/src/components/workflows/definition.ts @@ -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; +export type CompiledWorkflowNode = CompiledWorkflowBundle["nodes"][number]; +export type WorkflowBinding = z.infer; +export type WorkflowNodeState = "pending" | "running" | "completed" | "failed" | "cancelled"; + +export interface WorkflowExecutionOverlay { + definitionKey: string; + states: Readonly>; +} + +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; +} diff --git a/ui/litellm-dashboard/src/components/workflows/index.ts b/ui/litellm-dashboard/src/components/workflows/index.ts new file mode 100644 index 00000000000..67d0b06bda0 --- /dev/null +++ b/ui/litellm-dashboard/src/components/workflows/index.ts @@ -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"; diff --git a/ui/litellm-dashboard/src/components/workflows/useWorkflowViewport.ts b/ui/litellm-dashboard/src/components/workflows/useWorkflowViewport.ts new file mode 100644 index 00000000000..6ef6dbf88ba --- /dev/null +++ b/ui/litellm-dashboard/src/components/workflows/useWorkflowViewport.ts @@ -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(null); + const drag = useRef<{ x: number; y: number; view: Viewport } | null>(null); + const [size, setSize] = useState({ width: 600, height: 640 }); + const [manualView, setManualView] = useState(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) { + 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) { + 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) { + if (event.target !== event.currentTarget) return; + const movements: Record = { + 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, + }, + }; +} diff --git a/ui/litellm-dashboard/src/components/workflows/viewport.test.ts b/ui/litellm-dashboard/src/components/workflows/viewport.test.ts new file mode 100644 index 00000000000..4f01071722a --- /dev/null +++ b/ui/litellm-dashboard/src/components/workflows/viewport.test.ts @@ -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); + }); +}); diff --git a/ui/litellm-dashboard/src/components/workflows/viewport.ts b/ui/litellm-dashboard/src/components/workflows/viewport.ts new file mode 100644 index 00000000000..2a26b590852 --- /dev/null +++ b/ui/litellm-dashboard/src/components/workflows/viewport.ts @@ -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 }; +} diff --git a/ui/litellm-dashboard/src/i18n/locales/en.json b/ui/litellm-dashboard/src/i18n/locales/en.json index 919d6cd25cc..8ea1283bd2a 100644 --- a/ui/litellm-dashboard/src/i18n/locales/en.json +++ b/ui/litellm-dashboard/src/i18n/locales/en.json @@ -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", diff --git a/ui/litellm-dashboard/tests/fixtures/workflows/README.md b/ui/litellm-dashboard/tests/fixtures/workflows/README.md new file mode 100644 index 00000000000..c6cb2c00b83 --- /dev/null +++ b/ui/litellm-dashboard/tests/fixtures/workflows/README.md @@ -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"` diff --git a/ui/litellm-dashboard/tests/fixtures/workflows/WorkflowGraphDemo.tsx b/ui/litellm-dashboard/tests/fixtures/workflows/WorkflowGraphDemo.tsx new file mode 100644 index 00000000000..b55b541c65b --- /dev/null +++ b/ui/litellm-dashboard/tests/fixtures/workflows/WorkflowGraphDemo.tsx @@ -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(null); + const [example, setExample] = useState("Definition"); + return ( +
+
+
+

+ + Workflows / Definition preview +

+

{draft.name}

+

Inspect how each step transforms your input

+
+ + Read-only definition + +
+
+ Fixture preview + {examples.map((name) => ( + + ))} +
+ +

+ Development only. Definitions compiled by the LiteFlow PR #3 SDK. Execution states are simulated fixtures. No + gateway calls or workflow execution. +

+
+ ); +} diff --git a/ui/litellm-dashboard/tests/fixtures/workflows/drafts.json b/ui/litellm-dashboard/tests/fixtures/workflows/drafts.json new file mode 100644 index 00000000000..7528cffabf4 --- /dev/null +++ b/ui/litellm-dashboard/tests/fixtures/workflows/drafts.json @@ -0,0 +1,1786 @@ +{ + "email-reply": { + "name": "email-reply", + "workflow_id": "fixture-email-reply", + "team_id": "fixture-team", + "etag": "\"098b942710af75cd3421f9465ffc114ec6a7e2be034076c7a593fcc1b44df402\"", + "digest": "098b942710af75cd3421f9465ffc114ec6a7e2be034076c7a593fcc1b44df402", + "bundle": { + "contract_version": "1", + "name": "email-reply", + "timeout_seconds": 300.0, + "input_schema": { + "$defs": { + "Audio": { + "description": "Data about a previous audio response from the model.\n[Learn more](https://platform.openai.com/docs/guides/audio).", + "properties": { + "id": { + "title": "Id", + "type": "string" + } + }, + "required": ["id"], + "title": "Audio", + "type": "object" + }, + "ChatCompletionAssistantMessageParam": { + "description": "Messages sent by the model in response to user messages.", + "properties": { + "role": { + "const": "assistant", + "title": "Role", + "type": "string" + }, + "audio": { + "anyOf": [ + { + "$ref": "#/$defs/Audio" + }, + { + "type": "null" + } + ] + }, + "content": { + "anyOf": [ + { + "type": "string" + }, + { + "items": { + "anyOf": [ + { + "$ref": "#/$defs/ChatCompletionContentPartTextParam" + }, + { + "$ref": "#/$defs/ChatCompletionContentPartRefusalParam" + } + ] + }, + "type": "array" + }, + { + "type": "null" + } + ], + "title": "Content" + }, + "function_call": { + "anyOf": [ + { + "$ref": "#/$defs/FunctionCall" + }, + { + "type": "null" + } + ] + }, + "name": { + "title": "Name", + "type": "string" + }, + "refusal": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Refusal" + }, + "tool_calls": { + "items": { + "anyOf": [ + { + "$ref": "#/$defs/ChatCompletionMessageFunctionToolCallParam" + }, + { + "$ref": "#/$defs/ChatCompletionMessageCustomToolCallParam" + } + ] + }, + "title": "Tool Calls", + "type": "array" + } + }, + "required": ["role"], + "title": "ChatCompletionAssistantMessageParam", + "type": "object" + }, + "ChatCompletionContentPartImageParam": { + "description": "Learn about [image inputs](https://platform.openai.com/docs/guides/vision).", + "properties": { + "image_url": { + "$ref": "#/$defs/ImageURL" + }, + "type": { + "const": "image_url", + "title": "Type", + "type": "string" + }, + "prompt_cache_breakpoint": { + "$ref": "#/$defs/PromptCacheBreakpoint" + } + }, + "required": ["image_url", "type"], + "title": "ChatCompletionContentPartImageParam", + "type": "object" + }, + "ChatCompletionContentPartInputAudioParam": { + "description": "Learn about [audio inputs](https://platform.openai.com/docs/guides/audio).", + "properties": { + "input_audio": { + "$ref": "#/$defs/InputAudio" + }, + "type": { + "const": "input_audio", + "title": "Type", + "type": "string" + }, + "prompt_cache_breakpoint": { + "$ref": "#/$defs/PromptCacheBreakpoint" + } + }, + "required": ["input_audio", "type"], + "title": "ChatCompletionContentPartInputAudioParam", + "type": "object" + }, + "ChatCompletionContentPartRefusalParam": { + "properties": { + "refusal": { + "title": "Refusal", + "type": "string" + }, + "type": { + "const": "refusal", + "title": "Type", + "type": "string" + } + }, + "required": ["refusal", "type"], + "title": "ChatCompletionContentPartRefusalParam", + "type": "object" + }, + "ChatCompletionContentPartTextParam": { + "description": "Learn about [text inputs](https://platform.openai.com/docs/guides/text-generation).", + "properties": { + "text": { + "title": "Text", + "type": "string" + }, + "type": { + "const": "text", + "title": "Type", + "type": "string" + }, + "prompt_cache_breakpoint": { + "$ref": "#/$defs/PromptCacheBreakpoint" + } + }, + "required": ["text", "type"], + "title": "ChatCompletionContentPartTextParam", + "type": "object" + }, + "ChatCompletionDeveloperMessageParam": { + "description": "Developer-provided instructions that the model should follow, regardless of\nmessages sent by the user. With o1 models and newer, `developer` messages\nreplace the previous `system` messages.", + "properties": { + "content": { + "anyOf": [ + { + "type": "string" + }, + { + "items": { + "$ref": "#/$defs/ChatCompletionContentPartTextParam" + }, + "type": "array" + } + ], + "title": "Content" + }, + "role": { + "const": "developer", + "title": "Role", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + } + }, + "required": ["content", "role"], + "title": "ChatCompletionDeveloperMessageParam", + "type": "object" + }, + "ChatCompletionFunctionMessageParam": { + "properties": { + "content": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Content" + }, + "name": { + "title": "Name", + "type": "string" + }, + "role": { + "const": "function", + "title": "Role", + "type": "string" + } + }, + "required": ["content", "name", "role"], + "title": "ChatCompletionFunctionMessageParam", + "type": "object" + }, + "ChatCompletionMessageCustomToolCallParam": { + "description": "A call to a custom tool created by the model.", + "properties": { + "id": { + "title": "Id", + "type": "string" + }, + "custom": { + "$ref": "#/$defs/Custom" + }, + "type": { + "const": "custom", + "title": "Type", + "type": "string" + } + }, + "required": ["id", "custom", "type"], + "title": "ChatCompletionMessageCustomToolCallParam", + "type": "object" + }, + "ChatCompletionMessageFunctionToolCallParam": { + "description": "A call to a function tool created by the model.", + "properties": { + "id": { + "title": "Id", + "type": "string" + }, + "function": { + "$ref": "#/$defs/Function" + }, + "type": { + "const": "function", + "title": "Type", + "type": "string" + } + }, + "required": ["id", "function", "type"], + "title": "ChatCompletionMessageFunctionToolCallParam", + "type": "object" + }, + "ChatCompletionSystemMessageParam": { + "description": "Developer-provided instructions that the model should follow, regardless of\nmessages sent by the user. With o1 models and newer, use `developer` messages\nfor this purpose instead.", + "properties": { + "content": { + "anyOf": [ + { + "type": "string" + }, + { + "items": { + "$ref": "#/$defs/ChatCompletionContentPartTextParam" + }, + "type": "array" + } + ], + "title": "Content" + }, + "role": { + "const": "system", + "title": "Role", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + } + }, + "required": ["content", "role"], + "title": "ChatCompletionSystemMessageParam", + "type": "object" + }, + "ChatCompletionToolMessageParam": { + "properties": { + "content": { + "anyOf": [ + { + "type": "string" + }, + { + "items": { + "$ref": "#/$defs/ChatCompletionContentPartTextParam" + }, + "type": "array" + } + ], + "title": "Content" + }, + "role": { + "const": "tool", + "title": "Role", + "type": "string" + }, + "tool_call_id": { + "title": "Tool Call Id", + "type": "string" + } + }, + "required": ["content", "role", "tool_call_id"], + "title": "ChatCompletionToolMessageParam", + "type": "object" + }, + "ChatCompletionUserMessageParam": { + "description": "Messages sent by an end user, containing prompts or additional context\ninformation.", + "properties": { + "content": { + "anyOf": [ + { + "type": "string" + }, + { + "items": { + "anyOf": [ + { + "$ref": "#/$defs/ChatCompletionContentPartTextParam" + }, + { + "$ref": "#/$defs/ChatCompletionContentPartImageParam" + }, + { + "$ref": "#/$defs/ChatCompletionContentPartInputAudioParam" + }, + { + "$ref": "#/$defs/File" + } + ] + }, + "type": "array" + } + ], + "title": "Content" + }, + "role": { + "const": "user", + "title": "Role", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + } + }, + "required": ["content", "role"], + "title": "ChatCompletionUserMessageParam", + "type": "object" + }, + "Custom": { + "description": "The custom tool that the model called.", + "properties": { + "input": { + "title": "Input", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + } + }, + "required": ["input", "name"], + "title": "Custom", + "type": "object" + }, + "File": { + "description": "Learn about [file inputs](https://platform.openai.com/docs/guides/text) for text generation.", + "properties": { + "file": { + "$ref": "#/$defs/FileFile" + }, + "type": { + "const": "file", + "title": "Type", + "type": "string" + }, + "prompt_cache_breakpoint": { + "$ref": "#/$defs/FilePromptCacheBreakpoint" + } + }, + "required": ["file", "type"], + "title": "File", + "type": "object" + }, + "FileFile": { + "properties": { + "file_data": { + "title": "File Data", + "type": "string" + }, + "file_id": { + "title": "File Id", + "type": "string" + }, + "filename": { + "title": "Filename", + "type": "string" + } + }, + "title": "FileFile", + "type": "object" + }, + "FilePromptCacheBreakpoint": { + "description": "Marks the exact end of a reusable prompt prefix.\n\nThe breakpoint inherits its TTL from the request's `prompt_cache_options.ttl`; the boundary is not rounded to a token block.", + "properties": { + "mode": { + "const": "explicit", + "title": "Mode", + "type": "string" + } + }, + "required": ["mode"], + "title": "FilePromptCacheBreakpoint", + "type": "object" + }, + "Function": { + "description": "The function that the model called.", + "properties": { + "arguments": { + "title": "Arguments", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + } + }, + "required": ["arguments", "name"], + "title": "Function", + "type": "object" + }, + "FunctionCall": { + "description": "Deprecated and replaced by `tool_calls`.\n\nThe name and arguments of a function that should be called, as generated by the model.", + "properties": { + "arguments": { + "title": "Arguments", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + } + }, + "required": ["arguments", "name"], + "title": "FunctionCall", + "type": "object" + }, + "ImageURL": { + "properties": { + "url": { + "title": "Url", + "type": "string" + }, + "detail": { + "enum": ["auto", "low", "high"], + "title": "Detail", + "type": "string" + } + }, + "required": ["url"], + "title": "ImageURL", + "type": "object" + }, + "InputAudio": { + "properties": { + "data": { + "title": "Data", + "type": "string" + }, + "format": { + "enum": ["wav", "mp3"], + "title": "Format", + "type": "string" + } + }, + "required": ["data", "format"], + "title": "InputAudio", + "type": "object" + }, + "PromptCacheBreakpoint": { + "description": "Marks the exact end of a reusable prompt prefix.\n\nThe breakpoint inherits its TTL from the request's `prompt_cache_options.ttl`; the boundary is not rounded to a token block.", + "properties": { + "mode": { + "const": "explicit", + "title": "Mode", + "type": "string" + } + }, + "required": ["mode"], + "title": "PromptCacheBreakpoint", + "type": "object" + } + }, + "items": { + "anyOf": [ + { + "$ref": "#/$defs/ChatCompletionDeveloperMessageParam" + }, + { + "$ref": "#/$defs/ChatCompletionSystemMessageParam" + }, + { + "$ref": "#/$defs/ChatCompletionUserMessageParam" + }, + { + "$ref": "#/$defs/ChatCompletionAssistantMessageParam" + }, + { + "$ref": "#/$defs/ChatCompletionToolMessageParam" + }, + { + "$ref": "#/$defs/ChatCompletionFunctionMessageParam" + } + ] + }, + "type": "array" + }, + "output": { + "from": "node_3", + "output": "result" + }, + "nodes": [ + { + "id": "node_1", + "timeout_seconds": 60.0, + "retry": { + "max_attempts": 1, + "backoff_seconds": 0.0 + }, + "type": "chat_completion", + "model": "support-model", + "messages": { + "from": "$input", + "output": "messages" + }, + "temperature": 0.4 + }, + { + "id": "node_2", + "timeout_seconds": 15, + "retry": { + "max_attempts": 2, + "backoff_seconds": 0.5 + }, + "type": "python", + "program": { + "contract_version": "1", + "source": "def prepare_followup(text: str, instruction: str) -> list[ChatMessage]:\n return [{'role': 'user', 'content': instruction + '\\n\\n' + text}]\n", + "function_name": "prepare_followup", + "parameter_names": ["text", "instruction"], + "input_schema": { + "additionalProperties": false, + "properties": { + "text": { + "title": "Text", + "type": "string" + }, + "instruction": { + "title": "Instruction", + "type": "string" + } + }, + "required": ["text", "instruction"], + "title": "Arguments", + "type": "object" + }, + "output_schema": { + "$defs": { + "Audio": { + "description": "Data about a previous audio response from the model.\n[Learn more](https://platform.openai.com/docs/guides/audio).", + "properties": { + "id": { + "title": "Id", + "type": "string" + } + }, + "required": ["id"], + "title": "Audio", + "type": "object" + }, + "ChatCompletionAssistantMessageParam": { + "description": "Messages sent by the model in response to user messages.", + "properties": { + "role": { + "const": "assistant", + "title": "Role", + "type": "string" + }, + "audio": { + "anyOf": [ + { + "$ref": "#/$defs/Audio" + }, + { + "type": "null" + } + ] + }, + "content": { + "anyOf": [ + { + "type": "string" + }, + { + "items": { + "anyOf": [ + { + "$ref": "#/$defs/ChatCompletionContentPartTextParam" + }, + { + "$ref": "#/$defs/ChatCompletionContentPartRefusalParam" + } + ] + }, + "type": "array" + }, + { + "type": "null" + } + ], + "title": "Content" + }, + "function_call": { + "anyOf": [ + { + "$ref": "#/$defs/FunctionCall" + }, + { + "type": "null" + } + ] + }, + "name": { + "title": "Name", + "type": "string" + }, + "refusal": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Refusal" + }, + "tool_calls": { + "items": { + "anyOf": [ + { + "$ref": "#/$defs/ChatCompletionMessageFunctionToolCallParam" + }, + { + "$ref": "#/$defs/ChatCompletionMessageCustomToolCallParam" + } + ] + }, + "title": "Tool Calls", + "type": "array" + } + }, + "required": ["role"], + "title": "ChatCompletionAssistantMessageParam", + "type": "object" + }, + "ChatCompletionContentPartImageParam": { + "description": "Learn about [image inputs](https://platform.openai.com/docs/guides/vision).", + "properties": { + "image_url": { + "$ref": "#/$defs/ImageURL" + }, + "type": { + "const": "image_url", + "title": "Type", + "type": "string" + }, + "prompt_cache_breakpoint": { + "$ref": "#/$defs/PromptCacheBreakpoint" + } + }, + "required": ["image_url", "type"], + "title": "ChatCompletionContentPartImageParam", + "type": "object" + }, + "ChatCompletionContentPartInputAudioParam": { + "description": "Learn about [audio inputs](https://platform.openai.com/docs/guides/audio).", + "properties": { + "input_audio": { + "$ref": "#/$defs/InputAudio" + }, + "type": { + "const": "input_audio", + "title": "Type", + "type": "string" + }, + "prompt_cache_breakpoint": { + "$ref": "#/$defs/PromptCacheBreakpoint" + } + }, + "required": ["input_audio", "type"], + "title": "ChatCompletionContentPartInputAudioParam", + "type": "object" + }, + "ChatCompletionContentPartRefusalParam": { + "properties": { + "refusal": { + "title": "Refusal", + "type": "string" + }, + "type": { + "const": "refusal", + "title": "Type", + "type": "string" + } + }, + "required": ["refusal", "type"], + "title": "ChatCompletionContentPartRefusalParam", + "type": "object" + }, + "ChatCompletionContentPartTextParam": { + "description": "Learn about [text inputs](https://platform.openai.com/docs/guides/text-generation).", + "properties": { + "text": { + "title": "Text", + "type": "string" + }, + "type": { + "const": "text", + "title": "Type", + "type": "string" + }, + "prompt_cache_breakpoint": { + "$ref": "#/$defs/PromptCacheBreakpoint" + } + }, + "required": ["text", "type"], + "title": "ChatCompletionContentPartTextParam", + "type": "object" + }, + "ChatCompletionDeveloperMessageParam": { + "description": "Developer-provided instructions that the model should follow, regardless of\nmessages sent by the user. With o1 models and newer, `developer` messages\nreplace the previous `system` messages.", + "properties": { + "content": { + "anyOf": [ + { + "type": "string" + }, + { + "items": { + "$ref": "#/$defs/ChatCompletionContentPartTextParam" + }, + "type": "array" + } + ], + "title": "Content" + }, + "role": { + "const": "developer", + "title": "Role", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + } + }, + "required": ["content", "role"], + "title": "ChatCompletionDeveloperMessageParam", + "type": "object" + }, + "ChatCompletionFunctionMessageParam": { + "properties": { + "content": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Content" + }, + "name": { + "title": "Name", + "type": "string" + }, + "role": { + "const": "function", + "title": "Role", + "type": "string" + } + }, + "required": ["content", "name", "role"], + "title": "ChatCompletionFunctionMessageParam", + "type": "object" + }, + "ChatCompletionMessageCustomToolCallParam": { + "description": "A call to a custom tool created by the model.", + "properties": { + "id": { + "title": "Id", + "type": "string" + }, + "custom": { + "$ref": "#/$defs/Custom" + }, + "type": { + "const": "custom", + "title": "Type", + "type": "string" + } + }, + "required": ["id", "custom", "type"], + "title": "ChatCompletionMessageCustomToolCallParam", + "type": "object" + }, + "ChatCompletionMessageFunctionToolCallParam": { + "description": "A call to a function tool created by the model.", + "properties": { + "id": { + "title": "Id", + "type": "string" + }, + "function": { + "$ref": "#/$defs/Function" + }, + "type": { + "const": "function", + "title": "Type", + "type": "string" + } + }, + "required": ["id", "function", "type"], + "title": "ChatCompletionMessageFunctionToolCallParam", + "type": "object" + }, + "ChatCompletionSystemMessageParam": { + "description": "Developer-provided instructions that the model should follow, regardless of\nmessages sent by the user. With o1 models and newer, use `developer` messages\nfor this purpose instead.", + "properties": { + "content": { + "anyOf": [ + { + "type": "string" + }, + { + "items": { + "$ref": "#/$defs/ChatCompletionContentPartTextParam" + }, + "type": "array" + } + ], + "title": "Content" + }, + "role": { + "const": "system", + "title": "Role", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + } + }, + "required": ["content", "role"], + "title": "ChatCompletionSystemMessageParam", + "type": "object" + }, + "ChatCompletionToolMessageParam": { + "properties": { + "content": { + "anyOf": [ + { + "type": "string" + }, + { + "items": { + "$ref": "#/$defs/ChatCompletionContentPartTextParam" + }, + "type": "array" + } + ], + "title": "Content" + }, + "role": { + "const": "tool", + "title": "Role", + "type": "string" + }, + "tool_call_id": { + "title": "Tool Call Id", + "type": "string" + } + }, + "required": ["content", "role", "tool_call_id"], + "title": "ChatCompletionToolMessageParam", + "type": "object" + }, + "ChatCompletionUserMessageParam": { + "description": "Messages sent by an end user, containing prompts or additional context\ninformation.", + "properties": { + "content": { + "anyOf": [ + { + "type": "string" + }, + { + "items": { + "anyOf": [ + { + "$ref": "#/$defs/ChatCompletionContentPartTextParam" + }, + { + "$ref": "#/$defs/ChatCompletionContentPartImageParam" + }, + { + "$ref": "#/$defs/ChatCompletionContentPartInputAudioParam" + }, + { + "$ref": "#/$defs/File" + } + ] + }, + "type": "array" + } + ], + "title": "Content" + }, + "role": { + "const": "user", + "title": "Role", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + } + }, + "required": ["content", "role"], + "title": "ChatCompletionUserMessageParam", + "type": "object" + }, + "Custom": { + "description": "The custom tool that the model called.", + "properties": { + "input": { + "title": "Input", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + } + }, + "required": ["input", "name"], + "title": "Custom", + "type": "object" + }, + "File": { + "description": "Learn about [file inputs](https://platform.openai.com/docs/guides/text) for text generation.", + "properties": { + "file": { + "$ref": "#/$defs/FileFile" + }, + "type": { + "const": "file", + "title": "Type", + "type": "string" + }, + "prompt_cache_breakpoint": { + "$ref": "#/$defs/FilePromptCacheBreakpoint" + } + }, + "required": ["file", "type"], + "title": "File", + "type": "object" + }, + "FileFile": { + "properties": { + "file_data": { + "title": "File Data", + "type": "string" + }, + "file_id": { + "title": "File Id", + "type": "string" + }, + "filename": { + "title": "Filename", + "type": "string" + } + }, + "title": "FileFile", + "type": "object" + }, + "FilePromptCacheBreakpoint": { + "description": "Marks the exact end of a reusable prompt prefix.\n\nThe breakpoint inherits its TTL from the request's `prompt_cache_options.ttl`; the boundary is not rounded to a token block.", + "properties": { + "mode": { + "const": "explicit", + "title": "Mode", + "type": "string" + } + }, + "required": ["mode"], + "title": "FilePromptCacheBreakpoint", + "type": "object" + }, + "Function": { + "description": "The function that the model called.", + "properties": { + "arguments": { + "title": "Arguments", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + } + }, + "required": ["arguments", "name"], + "title": "Function", + "type": "object" + }, + "FunctionCall": { + "description": "Deprecated and replaced by `tool_calls`.\n\nThe name and arguments of a function that should be called, as generated by the model.", + "properties": { + "arguments": { + "title": "Arguments", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + } + }, + "required": ["arguments", "name"], + "title": "FunctionCall", + "type": "object" + }, + "ImageURL": { + "properties": { + "url": { + "title": "Url", + "type": "string" + }, + "detail": { + "enum": ["auto", "low", "high"], + "title": "Detail", + "type": "string" + } + }, + "required": ["url"], + "title": "ImageURL", + "type": "object" + }, + "InputAudio": { + "properties": { + "data": { + "title": "Data", + "type": "string" + }, + "format": { + "enum": ["wav", "mp3"], + "title": "Format", + "type": "string" + } + }, + "required": ["data", "format"], + "title": "InputAudio", + "type": "object" + }, + "PromptCacheBreakpoint": { + "description": "Marks the exact end of a reusable prompt prefix.\n\nThe breakpoint inherits its TTL from the request's `prompt_cache_options.ttl`; the boundary is not rounded to a token block.", + "properties": { + "mode": { + "const": "explicit", + "title": "Mode", + "type": "string" + } + }, + "required": ["mode"], + "title": "PromptCacheBreakpoint", + "type": "object" + } + }, + "items": { + "anyOf": [ + { + "$ref": "#/$defs/ChatCompletionDeveloperMessageParam" + }, + { + "$ref": "#/$defs/ChatCompletionSystemMessageParam" + }, + { + "$ref": "#/$defs/ChatCompletionUserMessageParam" + }, + { + "$ref": "#/$defs/ChatCompletionAssistantMessageParam" + }, + { + "$ref": "#/$defs/ChatCompletionToolMessageParam" + }, + { + "$ref": "#/$defs/ChatCompletionFunctionMessageParam" + } + ] + }, + "type": "array" + }, + "source_sha256": "81685c2f4773b08d0b26d6809b996b8c5ccd159a80f5091e2d5744169ee5cb51" + }, + "inputs": { + "text": { + "from": "node_1", + "output": "result" + }, + "instruction": { + "value": "Review this draft for clarity and accuracy" + } + } + }, + { + "id": "node_3", + "timeout_seconds": 60.0, + "retry": { + "max_attempts": 1, + "backoff_seconds": 0.0 + }, + "type": "chat_completion", + "model": "review-model", + "messages": { + "from": "node_2", + "output": "result" + }, + "max_completion_tokens": 512, + "response_format": { + "type": "json_schema", + "json_schema": { + "name": "Review", + "strict": true, + "schema": { + "properties": { + "summary": { + "title": "Summary", + "type": "string" + }, + "approved": { + "title": "Approved", + "type": "boolean" + } + }, + "required": ["summary", "approved"], + "title": "Review", + "type": "object" + } + } + } + } + ] + }, + "published_snapshot_id": null + }, + "welcome-message": { + "name": "welcome-message", + "workflow_id": "fixture-welcome-message", + "team_id": "fixture-team", + "etag": "\"ce819013c8670fca99016cfd55155fc9869e5e33fadbc03867f23a54977cb834\"", + "digest": "ce819013c8670fca99016cfd55155fc9869e5e33fadbc03867f23a54977cb834", + "bundle": { + "contract_version": "1", + "name": "welcome-message", + "timeout_seconds": 300.0, + "input_schema": { + "$defs": { + "Audio": { + "description": "Data about a previous audio response from the model.\n[Learn more](https://platform.openai.com/docs/guides/audio).", + "properties": { + "id": { + "title": "Id", + "type": "string" + } + }, + "required": ["id"], + "title": "Audio", + "type": "object" + }, + "ChatCompletionAssistantMessageParam": { + "description": "Messages sent by the model in response to user messages.", + "properties": { + "role": { + "const": "assistant", + "title": "Role", + "type": "string" + }, + "audio": { + "anyOf": [ + { + "$ref": "#/$defs/Audio" + }, + { + "type": "null" + } + ] + }, + "content": { + "anyOf": [ + { + "type": "string" + }, + { + "items": { + "anyOf": [ + { + "$ref": "#/$defs/ChatCompletionContentPartTextParam" + }, + { + "$ref": "#/$defs/ChatCompletionContentPartRefusalParam" + } + ] + }, + "type": "array" + }, + { + "type": "null" + } + ], + "title": "Content" + }, + "function_call": { + "anyOf": [ + { + "$ref": "#/$defs/FunctionCall" + }, + { + "type": "null" + } + ] + }, + "name": { + "title": "Name", + "type": "string" + }, + "refusal": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Refusal" + }, + "tool_calls": { + "items": { + "anyOf": [ + { + "$ref": "#/$defs/ChatCompletionMessageFunctionToolCallParam" + }, + { + "$ref": "#/$defs/ChatCompletionMessageCustomToolCallParam" + } + ] + }, + "title": "Tool Calls", + "type": "array" + } + }, + "required": ["role"], + "title": "ChatCompletionAssistantMessageParam", + "type": "object" + }, + "ChatCompletionContentPartImageParam": { + "description": "Learn about [image inputs](https://platform.openai.com/docs/guides/vision).", + "properties": { + "image_url": { + "$ref": "#/$defs/ImageURL" + }, + "type": { + "const": "image_url", + "title": "Type", + "type": "string" + }, + "prompt_cache_breakpoint": { + "$ref": "#/$defs/PromptCacheBreakpoint" + } + }, + "required": ["image_url", "type"], + "title": "ChatCompletionContentPartImageParam", + "type": "object" + }, + "ChatCompletionContentPartInputAudioParam": { + "description": "Learn about [audio inputs](https://platform.openai.com/docs/guides/audio).", + "properties": { + "input_audio": { + "$ref": "#/$defs/InputAudio" + }, + "type": { + "const": "input_audio", + "title": "Type", + "type": "string" + }, + "prompt_cache_breakpoint": { + "$ref": "#/$defs/PromptCacheBreakpoint" + } + }, + "required": ["input_audio", "type"], + "title": "ChatCompletionContentPartInputAudioParam", + "type": "object" + }, + "ChatCompletionContentPartRefusalParam": { + "properties": { + "refusal": { + "title": "Refusal", + "type": "string" + }, + "type": { + "const": "refusal", + "title": "Type", + "type": "string" + } + }, + "required": ["refusal", "type"], + "title": "ChatCompletionContentPartRefusalParam", + "type": "object" + }, + "ChatCompletionContentPartTextParam": { + "description": "Learn about [text inputs](https://platform.openai.com/docs/guides/text-generation).", + "properties": { + "text": { + "title": "Text", + "type": "string" + }, + "type": { + "const": "text", + "title": "Type", + "type": "string" + }, + "prompt_cache_breakpoint": { + "$ref": "#/$defs/PromptCacheBreakpoint" + } + }, + "required": ["text", "type"], + "title": "ChatCompletionContentPartTextParam", + "type": "object" + }, + "ChatCompletionDeveloperMessageParam": { + "description": "Developer-provided instructions that the model should follow, regardless of\nmessages sent by the user. With o1 models and newer, `developer` messages\nreplace the previous `system` messages.", + "properties": { + "content": { + "anyOf": [ + { + "type": "string" + }, + { + "items": { + "$ref": "#/$defs/ChatCompletionContentPartTextParam" + }, + "type": "array" + } + ], + "title": "Content" + }, + "role": { + "const": "developer", + "title": "Role", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + } + }, + "required": ["content", "role"], + "title": "ChatCompletionDeveloperMessageParam", + "type": "object" + }, + "ChatCompletionFunctionMessageParam": { + "properties": { + "content": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Content" + }, + "name": { + "title": "Name", + "type": "string" + }, + "role": { + "const": "function", + "title": "Role", + "type": "string" + } + }, + "required": ["content", "name", "role"], + "title": "ChatCompletionFunctionMessageParam", + "type": "object" + }, + "ChatCompletionMessageCustomToolCallParam": { + "description": "A call to a custom tool created by the model.", + "properties": { + "id": { + "title": "Id", + "type": "string" + }, + "custom": { + "$ref": "#/$defs/Custom" + }, + "type": { + "const": "custom", + "title": "Type", + "type": "string" + } + }, + "required": ["id", "custom", "type"], + "title": "ChatCompletionMessageCustomToolCallParam", + "type": "object" + }, + "ChatCompletionMessageFunctionToolCallParam": { + "description": "A call to a function tool created by the model.", + "properties": { + "id": { + "title": "Id", + "type": "string" + }, + "function": { + "$ref": "#/$defs/Function" + }, + "type": { + "const": "function", + "title": "Type", + "type": "string" + } + }, + "required": ["id", "function", "type"], + "title": "ChatCompletionMessageFunctionToolCallParam", + "type": "object" + }, + "ChatCompletionSystemMessageParam": { + "description": "Developer-provided instructions that the model should follow, regardless of\nmessages sent by the user. With o1 models and newer, use `developer` messages\nfor this purpose instead.", + "properties": { + "content": { + "anyOf": [ + { + "type": "string" + }, + { + "items": { + "$ref": "#/$defs/ChatCompletionContentPartTextParam" + }, + "type": "array" + } + ], + "title": "Content" + }, + "role": { + "const": "system", + "title": "Role", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + } + }, + "required": ["content", "role"], + "title": "ChatCompletionSystemMessageParam", + "type": "object" + }, + "ChatCompletionToolMessageParam": { + "properties": { + "content": { + "anyOf": [ + { + "type": "string" + }, + { + "items": { + "$ref": "#/$defs/ChatCompletionContentPartTextParam" + }, + "type": "array" + } + ], + "title": "Content" + }, + "role": { + "const": "tool", + "title": "Role", + "type": "string" + }, + "tool_call_id": { + "title": "Tool Call Id", + "type": "string" + } + }, + "required": ["content", "role", "tool_call_id"], + "title": "ChatCompletionToolMessageParam", + "type": "object" + }, + "ChatCompletionUserMessageParam": { + "description": "Messages sent by an end user, containing prompts or additional context\ninformation.", + "properties": { + "content": { + "anyOf": [ + { + "type": "string" + }, + { + "items": { + "anyOf": [ + { + "$ref": "#/$defs/ChatCompletionContentPartTextParam" + }, + { + "$ref": "#/$defs/ChatCompletionContentPartImageParam" + }, + { + "$ref": "#/$defs/ChatCompletionContentPartInputAudioParam" + }, + { + "$ref": "#/$defs/File" + } + ] + }, + "type": "array" + } + ], + "title": "Content" + }, + "role": { + "const": "user", + "title": "Role", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + } + }, + "required": ["content", "role"], + "title": "ChatCompletionUserMessageParam", + "type": "object" + }, + "Custom": { + "description": "The custom tool that the model called.", + "properties": { + "input": { + "title": "Input", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + } + }, + "required": ["input", "name"], + "title": "Custom", + "type": "object" + }, + "File": { + "description": "Learn about [file inputs](https://platform.openai.com/docs/guides/text) for text generation.", + "properties": { + "file": { + "$ref": "#/$defs/FileFile" + }, + "type": { + "const": "file", + "title": "Type", + "type": "string" + }, + "prompt_cache_breakpoint": { + "$ref": "#/$defs/FilePromptCacheBreakpoint" + } + }, + "required": ["file", "type"], + "title": "File", + "type": "object" + }, + "FileFile": { + "properties": { + "file_data": { + "title": "File Data", + "type": "string" + }, + "file_id": { + "title": "File Id", + "type": "string" + }, + "filename": { + "title": "Filename", + "type": "string" + } + }, + "title": "FileFile", + "type": "object" + }, + "FilePromptCacheBreakpoint": { + "description": "Marks the exact end of a reusable prompt prefix.\n\nThe breakpoint inherits its TTL from the request's `prompt_cache_options.ttl`; the boundary is not rounded to a token block.", + "properties": { + "mode": { + "const": "explicit", + "title": "Mode", + "type": "string" + } + }, + "required": ["mode"], + "title": "FilePromptCacheBreakpoint", + "type": "object" + }, + "Function": { + "description": "The function that the model called.", + "properties": { + "arguments": { + "title": "Arguments", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + } + }, + "required": ["arguments", "name"], + "title": "Function", + "type": "object" + }, + "FunctionCall": { + "description": "Deprecated and replaced by `tool_calls`.\n\nThe name and arguments of a function that should be called, as generated by the model.", + "properties": { + "arguments": { + "title": "Arguments", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + } + }, + "required": ["arguments", "name"], + "title": "FunctionCall", + "type": "object" + }, + "ImageURL": { + "properties": { + "url": { + "title": "Url", + "type": "string" + }, + "detail": { + "enum": ["auto", "low", "high"], + "title": "Detail", + "type": "string" + } + }, + "required": ["url"], + "title": "ImageURL", + "type": "object" + }, + "InputAudio": { + "properties": { + "data": { + "title": "Data", + "type": "string" + }, + "format": { + "enum": ["wav", "mp3"], + "title": "Format", + "type": "string" + } + }, + "required": ["data", "format"], + "title": "InputAudio", + "type": "object" + }, + "PromptCacheBreakpoint": { + "description": "Marks the exact end of a reusable prompt prefix.\n\nThe breakpoint inherits its TTL from the request's `prompt_cache_options.ttl`; the boundary is not rounded to a token block.", + "properties": { + "mode": { + "const": "explicit", + "title": "Mode", + "type": "string" + } + }, + "required": ["mode"], + "title": "PromptCacheBreakpoint", + "type": "object" + } + }, + "items": { + "anyOf": [ + { + "$ref": "#/$defs/ChatCompletionDeveloperMessageParam" + }, + { + "$ref": "#/$defs/ChatCompletionSystemMessageParam" + }, + { + "$ref": "#/$defs/ChatCompletionUserMessageParam" + }, + { + "$ref": "#/$defs/ChatCompletionAssistantMessageParam" + }, + { + "$ref": "#/$defs/ChatCompletionToolMessageParam" + }, + { + "$ref": "#/$defs/ChatCompletionFunctionMessageParam" + } + ] + }, + "type": "array" + }, + "output": { + "from": "node_1", + "output": "result" + }, + "nodes": [ + { + "id": "node_1", + "timeout_seconds": 60.0, + "retry": { + "max_attempts": 1, + "backoff_seconds": 0.0 + }, + "type": "chat_completion", + "model": "support-model", + "messages": { + "value": [ + { + "role": "user", + "content": "Write a short welcome message" + } + ] + } + } + ] + }, + "published_snapshot_id": null + } +} diff --git a/ui/litellm-dashboard/tests/fixtures/workflows/generate.py b/ui/litellm-dashboard/tests/fixtures/workflows/generate.py new file mode 100644 index 00000000000..31e2ea96005 --- /dev/null +++ b/ui/litellm-dashboard/tests/fixtures/workflows/generate.py @@ -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") diff --git a/ui/litellm-dashboard/tests/fixtures/workflows/serve-shell.mjs b/ui/litellm-dashboard/tests/fixtures/workflows/serve-shell.mjs new file mode 100644 index 00000000000..59e38b2de48 --- /dev/null +++ b/ui/litellm-dashboard/tests/fixtures/workflows/serve-shell.mjs @@ -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`); +});