Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

feat(ui): restyle Decisions playground after OpenRouter's model playground (#45903)

devin-ai-integration[bot]246c0e126b6e
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/CurlPreview.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/CurlPreview.test.tsx
new file mode 100644
index 00000000000..14a4e5dcbcf
--- /dev/null
+++ b/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/CurlPreview.test.tsx
@@ -0,0 +1,26 @@
+import { render, screen } from "@testing-library/react";
+import { describe, expect, it } from "vitest";
+import CurlPreview from "./CurlPreview";
+
+const input = {
+ baseUrl: "http://localhost:4000",
+ endpoint: "/v1/systemone" as const,
+ payload: JSON.stringify({ model: "jev-latest", state: "ok" }),
+ authHeaderName: "Authorization",
+};
+
+describe("CurlPreview", () => {
+ it("shows the command and a copy button for a valid payload", () => {
+ render(<CurlPreview {...input} />);
+ expect(screen.getByLabelText("cURL request")).toHaveTextContent("http://localhost:4000/v1/systemone");
+ expect(screen.getByRole("button", { name: /copy curl/i })).toBeInTheDocument();
+ expect(screen.queryByRole("alert")).not.toBeInTheDocument();
+ });
+
+ it("hides the copy button and points back to the form while the payload has errors", () => {
+ render(<CurlPreview {...input} errorCount={2} />);
+ expect(screen.getByRole("alert")).toHaveTextContent("Fix 2 issues on the Form tab");
+ expect(screen.getByLabelText("cURL request")).toHaveTextContent("jev-latest");
+ expect(screen.queryByRole("button", { name: /copy curl/i })).not.toBeInTheDocument();
+ });
+});
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/CurlPreview.tsx b/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/CurlPreview.tsx
new file mode 100644
index 00000000000..ecefd87933b
--- /dev/null
+++ b/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/CurlPreview.tsx
@@ -0,0 +1,35 @@
+import CopyButton from "@/components/shared/CopyButton";
+import { buildCurlCommand, type CurlCommandInput } from "./lib/curlCommand";
+
+interface CurlPreviewProps extends CurlCommandInput {
+ errorCount?: number;
+}
+
+export default function CurlPreview({ errorCount = 0, ...input }: CurlPreviewProps) {
+ const command = buildCurlCommand(input);
+ return (
+ <div className="flex min-h-0 flex-1 flex-col rounded-md border">
+ <div className="flex items-center justify-between gap-2 border-b px-3 py-2 text-sm">
+ <span className="font-medium">cURL request</span>
+ <div className="flex items-center gap-2 text-xs text-muted-foreground">
+ {errorCount > 0 ? (
+ <span role="alert" className="text-destructive">
+ Fix {errorCount} {errorCount === 1 ? "issue" : "issues"} on the Form tab before copying
+ </span>
+ ) : (
+ <>
+ <span>Replace $LITELLM_API_KEY with a virtual key</span>
+ <CopyButton value={command} label="Copy cURL" variant="action" />
+ </>
+ )}
+ </div>
+ </div>
+ <pre
+ aria-label="cURL request"
+ className="m-0 min-h-0 flex-1 overflow-auto whitespace-pre-wrap wrap-anywhere px-3 py-3 font-mono text-xs leading-5"
+ >
+ {command}
+ </pre>
+ </div>
+ );
+}
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/DecisionFormControls.tsx b/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/DecisionFormControls.tsx
index af821e77916..afa88bf7051 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/DecisionFormControls.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/DecisionFormControls.tsx
@@ -2,7 +2,7 @@ import { Button } from "@/components/ui/button";
import { cn } from "@/lib/cva.config";
import { Plus, Trash2 } from "lucide-react";
import { useId, type ReactNode } from "react";
-import { IssueList, ValidationStatus } from "./JsonEditor";
+import { IssueList, ValidationStatus } from "./ValidationFeedback";
import type { PayloadValidation } from "./lib/validatePayload";
export function RemoveButton({ label, onClick }: { label: string; onClick: () => void }) {
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/JsonEditor.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/JsonEditor.test.tsx
deleted file mode 100644
index c861c1d466d..00000000000
--- a/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/JsonEditor.test.tsx
+++ /dev/null
@@ -1,70 +0,0 @@
-import { fireEvent, render, screen } from "@testing-library/react";
-import { describe, expect, it, vi } from "vitest";
-import JsonEditor from "./JsonEditor";
-import { validateSystemOnePayload } from "./lib/validatePayload";
-
-const validPayload = JSON.stringify(
- { state: "Hi", questions: { escalate: { type: "noul", instructions: "Escalate?" } } },
- null,
- 2,
-);
-
-describe("JsonEditor", () => {
- it("marks a valid payload as ready to send and counts its lines", () => {
- render(<JsonEditor value={validPayload} onChange={vi.fn()} validation={validateSystemOnePayload(validPayload)} />);
-
- expect(screen.getByText("Valid payload")).toBeInTheDocument();
- expect(screen.getByRole("status")).toHaveTextContent("Ready to send");
- expect(screen.getByText(`${validPayload.split("\n").length} lines`)).toBeInTheDocument();
- expect(screen.getByRole("textbox", { name: "System One JSON payload" })).toHaveAttribute("aria-invalid", "false");
- });
-
- it("lists each issue with its path and counts only errors in the status badge", () => {
- const payload = JSON.stringify({
- state: "Hi",
- questions: {
- category: { type: "choice", instructions: 1, criteria: { support: "Help" } },
- urgency: { type: "score", instructions: "Rate", criteria: ["Low"] },
- },
- });
- render(<JsonEditor value={payload} onChange={vi.fn()} validation={validateSystemOnePayload(payload)} />);
-
- expect(screen.getByText("2 issues")).toBeInTheDocument();
- const issues = screen.getByRole("list", { name: "Payload validation issues" });
- expect(issues).toHaveTextContent("questions.category.instructionsInstructions must be a string.");
- expect(issues).toHaveTextContent("questions.urgency.criteriaScore criteria must contain at least 2 levels.");
- expect(screen.getByRole("textbox", { name: "System One JSON payload" })).toHaveAttribute("aria-invalid", "true");
- });
-
- it("shows warnings without counting them as issues", () => {
- const payload = JSON.stringify({
- state: "Hi",
- questions: { urgency: { type: "score", instructions: "Rate", criteria: Array.from({ length: 11 }, () => "L") } },
- });
- render(<JsonEditor value={payload} onChange={vi.fn()} validation={validateSystemOnePayload(payload)} />);
-
- expect(screen.getByText("Valid payload")).toBeInTheDocument();
- expect(screen.getByRole("list", { name: "Payload validation issues" })).toHaveTextContent(
- "More than 10 score levels may reduce result quality.",
- );
- });
-
- it("numbers every line, including a trailing empty one, so wrapped lines keep their number", () => {
- const value = `${validPayload}\n`;
- render(<JsonEditor value={value} onChange={vi.fn()} validation={validateSystemOnePayload(value)} />);
-
- const lineCount = value.split("\n").length;
- expect(screen.getByText(`${lineCount} lines`)).toBeInTheDocument();
- expect(screen.getByText(String(lineCount))).toBeInTheDocument();
- expect(screen.queryByText(String(lineCount + 1))).not.toBeInTheDocument();
- });
-
- it("reports edits to the caller", () => {
- const onChange = vi.fn();
- render(<JsonEditor value={validPayload} onChange={onChange} validation={validateSystemOnePayload(validPayload)} />);
-
- fireEvent.change(screen.getByRole("textbox", { name: "System One JSON payload" }), { target: { value: "{}" } });
-
- expect(onChange).toHaveBeenCalledWith("{}");
- });
-});
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/JsonEditor.tsx b/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/JsonEditor.tsx
deleted file mode 100644
index 7311c3a055a..00000000000
--- a/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/JsonEditor.tsx
+++ /dev/null
@@ -1,191 +0,0 @@
-import { Badge } from "@/components/ui/badge";
-import { cn } from "@/lib/cva.config";
-import { CircleAlert, CircleCheck, TriangleAlert } from "lucide-react";
-import { useTheme } from "next-themes";
-import { useId, useRef } from "react";
-import { createElement, PrismLight as SyntaxHighlighter } from "react-syntax-highlighter";
-import type { SyntaxHighlighterProps } from "react-syntax-highlighter";
-import json from "react-syntax-highlighter/dist/esm/languages/prism/json";
-import { vs, vscDarkPlus } from "react-syntax-highlighter/dist/esm/styles/prism";
-import type { PayloadValidation } from "./lib/validatePayload";
-
-SyntaxHighlighter.registerLanguage("json", json);
-
-const EDITOR_TEXT = "m-0 whitespace-pre-wrap wrap-anywhere py-3 font-mono text-xs leading-5 [scrollbar-gutter:stable]";
-const GUTTER_WIDTH = "w-11";
-type LineRendererProps = Parameters<NonNullable<SyntaxHighlighterProps["renderer"]>>[0];
-const CONTENT_INSET = "pl-14 pr-3";
-type SyntaxTheme = NonNullable<SyntaxHighlighterProps["style"]>;
-const THEME_BLOCKS = ['pre[class*="language-"]', 'code[class*="language-"]'] as const;
-
-function withoutBlockBackground(theme: SyntaxTheme): SyntaxTheme {
- const stripped = THEME_BLOCKS.map((block) => {
- const { background: _background, backgroundColor: _backgroundColor, ...rest } = theme[block] ?? {};
- return [block, rest] as const;
- });
- return { ...theme, ...Object.fromEntries(stripped) };
-}
-
-const VS_CODE_DARK_PLUS = withoutBlockBackground(vscDarkPlus);
-const VS_CODE_LIGHT_PLUS = {
- ...withoutBlockBackground(vs),
- property: { color: "#0451a5" },
- string: { color: "#a31515" },
- number: { color: "#098658" },
- boolean: { color: "#0000ff" },
- punctuation: { color: "#000000" },
- operator: { color: "#000000" },
-} as const;
-const INHERIT_TEXT = {
- fontFamily: "inherit",
- fontSize: "inherit",
- lineHeight: "inherit",
- whiteSpace: "pre-wrap",
- overflowWrap: "anywhere",
- textShadow: "none",
-} as const;
-const CODE_TAG_PROPS = { className: "language-json", style: INHERIT_TEXT } as const;
-const TRANSPARENT_PRE = {
- ...INHERIT_TEXT,
- background: "transparent",
- border: 0,
- margin: 0,
- padding: 0,
- overflow: "visible",
-} as const;
-
-interface JsonEditorProps {
- value: string;
- onChange: (value: string) => void;
- validation: PayloadValidation<unknown>;
- label?: string;
- placeholder?: string;
-}
-
-export function ValidationStatus({ validation }: { validation: PayloadValidation<unknown> }) {
- const errorCount = validation.issues.filter((issue) => issue.severity === "error").length;
- if (errorCount > 0) {
- return (
- <Badge variant="destructive">
- {errorCount} {errorCount === 1 ? "issue" : "issues"}
- </Badge>
- );
- }
- return <Badge variant="secondary">Valid payload</Badge>;
-}
-
-export function IssueList({ id, validation }: { id: string; validation: PayloadValidation<unknown> }) {
- if (validation.issues.length === 0) {
- return (
- <p id={id} role="status" className="flex items-center gap-1.5 border-t px-3 py-2 text-xs text-muted-foreground">
- <CircleCheck className="size-3.5 text-emerald-600 dark:text-emerald-400" />
- Ready to send
- </p>
- );
- }
- return (
- <ul id={id} aria-label="Payload validation issues" className="grid max-h-36 gap-1 overflow-auto border-t px-3 py-2">
- {validation.issues.map((issue, index) => (
- <li key={`${issue.path}-${index}`} className="flex items-start gap-1.5 text-xs">
- {issue.severity === "error" ? (
- <CircleAlert className="mt-0.5 size-3.5 shrink-0 text-destructive" />
- ) : (
- <TriangleAlert className="mt-0.5 size-3.5 shrink-0 text-amber-600 dark:text-amber-400" />
- )}
- <code className="shrink-0 rounded bg-muted px-1 font-mono">{issue.path}</code>
- <span>{issue.message}</span>
- </li>
- ))}
- </ul>
- );
-}
-
-function LineRows({ rows, stylesheet, useInlineStyles }: LineRendererProps) {
- return rows.map((row, line) => {
- const lineElement = { node: row, stylesheet, useInlineStyles, key: line };
- return (
- <div key={line} className="flex">
- <span className={cn(GUTTER_WIDTH, "shrink-0 select-none pr-3 text-right text-zinc-400 dark:text-zinc-500")}>
- {line + 1}
- </span>
- <span className="min-h-5 min-w-0 flex-1 px-3">{createElement(lineElement)}</span>
- </div>
- );
- });
-}
-
-export default function JsonEditor({
- value,
- onChange,
- validation,
- label = "System One JSON payload",
- placeholder = "Paste or write a System One request",
-}: JsonEditorProps) {
- const issuesId = useId();
- const highlightRef = useRef<HTMLDivElement>(null);
- const syntaxTheme = useTheme().resolvedTheme === "dark" ? VS_CODE_DARK_PLUS : VS_CODE_LIGHT_PLUS;
- const lineCount = value.split("\n").length;
- const hasErrors = !validation.isValid;
-
- return (
- <div
- className={cn(
- "flex min-h-96 flex-1 flex-col overflow-hidden rounded-md border bg-background",
- hasErrors && "border-destructive/60",
- )}
- >
- <div className="flex items-center justify-between gap-2 border-b px-3 py-2">
- <div className="flex items-center gap-2">
- <span className="text-sm font-medium">Request JSON</span>
- <ValidationStatus validation={validation} />
- </div>
- <span className="text-xs text-muted-foreground tabular-nums">
- {lineCount} {lineCount === 1 ? "line" : "lines"}
- </span>
- </div>
- <div className="relative min-h-80 flex-1 bg-background dark:bg-[#1e1e1e]">
- <div
- aria-hidden="true"
- className={cn(
- GUTTER_WIDTH,
- "absolute inset-y-0 left-0 border-r bg-muted/50 dark:border-zinc-700 dark:bg-zinc-800/60",
- )}
- />
- <div ref={highlightRef} aria-hidden="true" className={cn("absolute inset-0 overflow-hidden", EDITOR_TEXT)}>
- <SyntaxHighlighter
- language="json"
- style={syntaxTheme}
- customStyle={TRANSPARENT_PRE}
- PreTag="div"
- codeTagProps={CODE_TAG_PROPS}
- renderer={LineRows}
- >
- {value}
- </SyntaxHighlighter>
- </div>
- <textarea
- aria-label={label}
- aria-invalid={hasErrors}
- aria-describedby={issuesId}
- value={value}
- onChange={(event) => onChange(event.target.value)}
- onScroll={(event) => {
- if (highlightRef.current) {
- highlightRef.current.scrollTop = event.currentTarget.scrollTop;
- }
- }}
- spellCheck={false}
- autoCapitalize="off"
- autoComplete="off"
- placeholder={placeholder}
- className={cn(
- EDITOR_TEXT,
- CONTENT_INSET,
- "absolute inset-0 size-full resize-none overflow-y-auto bg-transparent text-transparent caret-foreground outline-none selection:bg-primary/20 placeholder:text-muted-foreground",
- )}
- />
- </div>
- <IssueList id={issuesId} validation={validation} />
- </div>
- );
-}
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/OpenAIDecisionsForm.tsx b/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/OpenAIDecisionsForm.tsx
index a88278e18e2..e7a1e14ca02 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/OpenAIDecisionsForm.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/OpenAIDecisionsForm.tsx
@@ -177,10 +177,10 @@ interface OpenAIDecisionsFormProps {
value: string;
onChange: (value: string) => void;
validation: PayloadValidation<OpenAIDecisionsRequest>;
- onOpenJson: () => void;
+ onReset: () => void;
}
-export default function OpenAIDecisionsForm({ value, onChange, validation, onOpenJson }: OpenAIDecisionsFormProps) {
+export default function OpenAIDecisionsForm({ value, onChange, validation, onReset }: OpenAIDecisionsFormProps) {
const inputId = useId();
const safetyId = useId();
const form = useMemo(() => readDecisionsForm(value), [value]);
@@ -188,11 +188,9 @@ export default function OpenAIDecisionsForm({ value, onChange, validation, onOpe
if (form === undefined) {
return (
<FormFrame validation={validation}>
- <p className="text-sm text-muted-foreground">
- This request has JSON the form can&apos;t show. Edit it in JSON to fix its shape.
- </p>
- <Button variant="outline" className="w-fit" onClick={onOpenJson}>
- Edit in JSON
+ <p className="text-sm text-muted-foreground">This request has a shape the form can&apos;t show.</p>
+ <Button variant="outline" className="w-fit" onClick={onReset}>
+ Reset to example
</Button>
</FormFrame>
);
@@ -207,12 +205,7 @@ export default function OpenAIDecisionsForm({ value, onChange, validation, onOpe
<div className="grid gap-1.5">
{Array.isArray(form.input) ? (
<>
- <p className="text-sm text-muted-foreground">
- Input contains messages. Edit messages and image parts in JSON; form edits keep them unchanged.
- </p>
- <Button variant="outline" className="w-fit" onClick={onOpenJson}>
- Edit input in JSON
- </Button>
+ <p className="text-sm text-muted-foreground">Input contains messages. Form edits keep them unchanged.</p>
</>
) : (
<>
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/QuestionBreakdown.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/QuestionBreakdown.test.tsx
deleted file mode 100644
index 289ce8a53f5..00000000000
--- a/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/QuestionBreakdown.test.tsx
+++ /dev/null
@@ -1,33 +0,0 @@
-import { render, screen } from "@testing-library/react";
-import { describe, expect, it } from "vitest";
-import QuestionBreakdown from "./QuestionBreakdown";
-import { validateSystemOnePayload } from "./lib/validatePayload";
-
-const previewOf = (questions: object) => validateSystemOnePayload(JSON.stringify({ state: "Hi", questions })).payload;
-
-describe("QuestionBreakdown", () => {
- it("previews every noul criterion that will be sent, not only true and false", () => {
- render(
- <QuestionBreakdown
- payload={previewOf({
- escalate: {
- type: "noul",
- instructions: "Escalate?",
- criteria: { true: "Asks for a person", unsure: "Maybe" },
- },
- })}
- />,
- );
-
- expect(screen.getByText("Asks for a person")).toBeInTheDocument();
- expect(screen.getByText("unsure")).toBeInTheDocument();
- expect(screen.getByText("Maybe")).toBeInTheDocument();
- expect(screen.queryByText("No criteria defined")).not.toBeInTheDocument();
- });
-
- it("says when a noul question has no criteria", () => {
- render(<QuestionBreakdown payload={previewOf({ escalate: { type: "noul", instructions: "Escalate?" } })} />);
-
- expect(screen.getByText("No criteria defined")).toBeInTheDocument();
- });
-});
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/QuestionBreakdown.tsx b/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/QuestionBreakdown.tsx
deleted file mode 100644
index 8fc06101783..00000000000
--- a/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/QuestionBreakdown.tsx
+++ /dev/null
@@ -1,103 +0,0 @@
-import { Badge } from "@/components/ui/badge";
-import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
-import type { PlaygroundQuestion, PlaygroundRequest } from "./lib/schemas";
-
-function formatState(state: unknown): string {
- if (typeof state === "string") {
- return state;
- }
- return JSON.stringify(state, null, 2) ?? String(state);
-}
-
-function QuestionCriteria({ question }: { question: PlaygroundQuestion }) {
- if (question.type === "choice") {
- return (
- <dl className="grid gap-2">
- {Object.entries(question.criteria).map(([label, description]) => (
- <div key={label} className="grid gap-0.5 sm:grid-cols-[minmax(7rem,auto)_1fr] sm:gap-3">
- <dt className="font-mono text-xs font-medium">{label}</dt>
- <dd className="text-xs text-muted-foreground">{formatState(description)}</dd>
- </div>
- ))}
- </dl>
- );
- }
-
- if (question.type === "noul") {
- const criteria = Object.entries(question.criteria ?? {}).filter(([, description]) => description !== undefined);
- return criteria.length > 0 ? (
- <dl className="grid gap-2">
- {criteria.map(([label, description]) => (
- <div key={label} className="grid gap-0.5 sm:grid-cols-[minmax(7rem,auto)_1fr] sm:gap-3">
- <dt className="text-xs font-medium">{label}</dt>
- <dd className="text-xs text-muted-foreground">
- {typeof description === "string" ? description : JSON.stringify(description)}
- </dd>
- </div>
- ))}
- </dl>
- ) : (
- <p className="text-xs text-muted-foreground">No criteria defined</p>
- );
- }
-
- return (
- <ol className="grid gap-2">
- {question.criteria.map((description, index) => (
- <li key={`${index}-${description}`} className="grid gap-0.5 sm:grid-cols-[minmax(7rem,auto)_1fr] sm:gap-3">
- <span className="font-mono text-xs font-medium">{index}</span>
- <span className="text-xs text-muted-foreground">{formatState(description)}</span>
- </li>
- ))}
- </ol>
- );
-}
-
-export default function QuestionBreakdown({ payload }: { payload?: PlaygroundRequest }) {
- if (!payload) {
- return (
- <Card>
- <CardHeader>
- <CardTitle>Question breakdown</CardTitle>
- <CardDescription>Enter a valid request to preview its state and questions.</CardDescription>
- </CardHeader>
- </Card>
- );
- }
-
- return (
- <Card>
- <CardHeader>
- <CardTitle>Question breakdown</CardTitle>
- <CardDescription>Review the state and criteria that will be sent.</CardDescription>
- </CardHeader>
- <CardContent className="grid gap-4 wrap-anywhere">
- <section aria-labelledby="system-one-state-heading" className="grid gap-2">
- <h3 id="system-one-state-heading" className="text-sm font-medium">
- State
- </h3>
- <pre className="max-h-48 overflow-y-auto whitespace-pre-wrap rounded-md bg-muted p-3 font-mono text-xs">
- {formatState(payload.state)}
- </pre>
- </section>
- <div className="grid gap-3">
- {Object.entries(payload.questions).map(([id, question]) => (
- <section key={id} className="grid gap-3 rounded-md border p-3" aria-labelledby={`question-${id}`}>
- <div className="flex flex-wrap items-center justify-between gap-2">
- <h3 id={`question-${id}`} className="font-mono text-sm font-medium">
- {id}
- </h3>
- <Badge variant="secondary">{question.type}</Badge>
- </div>
- {question.instructions != null && <p className="text-sm">{formatState(question.instructions)}</p>}
- <div className="grid gap-2">
- <h4 className="text-xs font-medium text-muted-foreground">Criteria</h4>
- <QuestionCriteria question={question} />
- </div>
- </section>
- ))}
- </div>
- </CardContent>
- </Card>
- );
-}
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/ResponseView.integration.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/ResponseView.integration.test.tsx
index 7cd303bbcd2..141fdc43374 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/ResponseView.integration.test.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/ResponseView.integration.test.tsx
@@ -27,7 +27,7 @@ const sampleResponse: SystemOneResponse = {
};
describe("ResponseView integration", () => {
- it("shows OpenAI Decisions answer cards in Form view and the complete response in JSON view", async () => {
+ it("shows OpenAI Decisions answer cards in Form view and the complete response in cURL view", async () => {
const response: OpenAIDecisionsResponse = {
model: "jev-latest",
answers: [
@@ -71,7 +71,7 @@ describe("ResponseView integration", () => {
expect(screen.queryByRole("region", { name: "Decisions response JSON" })).not.toBeInTheDocument();
await userEvent.click(screen.getByRole("button", { name: "Raw response" }));
expect(screen.getByRole("region", { name: "Decisions response JSON" })).toHaveTextContent("keep-extra-fields");
- rerender(<ResponseView response={response} isLoading={false} view="json" />);
+ rerender(<ResponseView response={response} isLoading={false} view="curl" />);
expect(screen.queryByRole("meter")).not.toBeInTheDocument();
expect(JSON.parse(screen.getByRole("region", { name: "Decisions response JSON" }).textContent ?? "")).toEqual(
response,
@@ -80,8 +80,8 @@ describe("ResponseView integration", () => {
expect(screen.getByRole("meter", { name: "false probability" })).toHaveAttribute("aria-valuenow", "80");
});
- it("shows System One raw response instead of cards in JSON view", () => {
- render(<ResponseView response={sampleResponse} isLoading={false} view="json" />);
+ it("shows System One raw response instead of cards in cURL view", () => {
+ render(<ResponseView response={sampleResponse} isLoading={false} view="curl" />);
expect(screen.queryByRole("meter")).not.toBeInTheDocument();
expect(JSON.parse(screen.getByRole("region", { name: "Decisions response JSON" }).textContent ?? "")).toEqual(
sampleResponse,
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/ResponseView.tsx b/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/ResponseView.tsx
index 0754946f5f4..538d2f659a6 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/ResponseView.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/ResponseView.tsx
@@ -12,7 +12,7 @@ const SCORE_FORMAT = new Intl.NumberFormat("en-US", { maximumFractionDigits: 2 }
interface ResponseViewProps {
response?: SystemOneResponse | OpenAIDecisionsResponse;
- view?: "form" | "json";
+ view?: "form" | "curl";
fallbackModel?: string;
latencyMs?: number;
error?: string;
@@ -236,7 +236,7 @@ export default function ResponseView({
<CardHeader>
<div className="flex flex-wrap items-start justify-between gap-3">
<div className="grid gap-1">
- <CardTitle>{view === "json" ? "Response JSON" : "Calibrated probabilities"}</CardTitle>
+ <CardTitle>{view === "curl" ? "Response JSON" : "Calibrated probabilities"}</CardTitle>
{model && <CardDescription>{model}</CardDescription>}
</div>
<div className="flex flex-wrap items-center gap-2 text-xs">
@@ -250,7 +250,7 @@ export default function ResponseView({
</div>
</CardHeader>
<CardContent className="grid gap-3">
- {view === "json" ? <RawResponse response={response} /> : <AnswerCards answers={response.answers} />}
+ {view === "curl" ? <RawResponse response={response} /> : <AnswerCards answers={response.answers} />}
{view === "form" && (
<Collapsible open={showRaw} onOpenChange={setShowRaw}>
<CollapsibleTrigger
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/SystemOneForm.tsx b/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/SystemOneForm.tsx
index cfffb30bb5d..96cf5208048 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/SystemOneForm.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/SystemOneForm.tsx
@@ -40,7 +40,7 @@ interface SystemOneFormProps {
value: string;
onChange: (value: string) => void;
validation: SystemOnePayloadValidation;
- onOpenJson: () => void;
+ onReset: () => void;
}
interface QuestionEditorProps<Q extends FormQuestion> {
@@ -247,18 +247,16 @@ function QuestionCard({ name, question, taken, onChange, onRename, onRemove }: Q
);
}
-export default function SystemOneForm({ value, onChange, validation, onOpenJson }: SystemOneFormProps) {
+export default function SystemOneForm({ value, onChange, validation, onReset }: SystemOneFormProps) {
const stateId = useId();
const form = useMemo(() => readForm(value), [value]);
if (form === undefined) {
return (
<FormFrame validation={validation}>
- <p className="text-sm text-muted-foreground">
- This request has JSON the form can&apos;t show, such as a syntax error or a value that isn&apos;t text.
- </p>
- <Button variant="outline" className="w-fit" onClick={onOpenJson}>
- Edit in JSON
+ <p className="text-sm text-muted-foreground">This request has a shape the form can&apos;t show.</p>
+ <Button variant="outline" className="w-fit" onClick={onReset}>
+ Reset to example
</Button>
</FormFrame>
);
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/SystemOneUI.integration.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/SystemOneUI.integration.test.tsx
index eb75c836b2b..703c50805f1 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/SystemOneUI.integration.test.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/SystemOneUI.integration.test.tsx
@@ -11,9 +11,10 @@ import {
import type { ReactElement } from "react";
import userEvent from "@testing-library/user-event";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
-import SystemOneUI, { NOUL_HELP } from "./SystemOneUI";
+import SystemOneUI from "./SystemOneUI";
import type { SystemOneResponse } from "./lib/schemas";
import type { OpenAIDecisionsResponse } from "./lib/openAIDecisions";
+import { curlPayload } from "./lib/curlCommand";
interface ModelGroupInfo {
model_group: string;
@@ -60,9 +61,11 @@ const isModelLookup = (input: RequestInfo | URL) => String(input).endsWith("/mod
const lookupAuthHeaders = (calls: Parameters<typeof fetch>[]) =>
calls.map(([, init]) => Object.values((init?.headers ?? {}) as Record<string, string>));
-const openJsonEditor = async () => {
- await userEvent.click(screen.getByRole("tab", { name: "JSON" }));
- return screen.getByRole("textbox", { name: "System One JSON payload" });
+const readCurlPayload = async () => {
+ await userEvent.click(screen.getByRole("tab", { name: "cURL" }));
+ const payload = curlPayload(screen.getByLabelText("cURL request").textContent ?? "");
+ await userEvent.click(screen.getByRole("tab", { name: "Form" }));
+ return JSON.parse(payload ?? "") as Record<string, unknown>;
};
const selectEndpoint = async (endpoint: "/v1/decisions" | "/v1/systemone") => {
@@ -107,20 +110,20 @@ describe("SystemOneUI integration", () => {
it("switches between example presets and reads Custom once the request is edited", async () => {
render(<SystemOneUI accessToken="session-key" />);
- const editor = await openJsonEditor();
- const example = (editor as HTMLTextAreaElement).value;
+ const input = screen.getByRole("textbox", { name: "Input" }) as HTMLTextAreaElement;
+ const example = input.value;
const picker = screen.getByRole("combobox", { name: "Example" });
expect(picker).toHaveTextContent("Triage a bug report");
- fireEvent.change(editor, { target: { value: "{}" } });
+ fireEvent.change(input, { target: { value: "Something else" } });
expect(picker).toHaveTextContent("Custom");
await selectPreset("Triage a bug report");
- expect(editor).toHaveValue(example);
+ expect(screen.getByRole("textbox", { name: "Input" })).toHaveValue(example);
expect(picker).toHaveTextContent("Triage a bug report");
await selectPreset("Score a sales lead");
expect(picker).toHaveTextContent("Score a sales lead");
- expect(JSON.parse((editor as HTMLTextAreaElement).value)).toMatchObject({ questions: { fit: { type: "score" } } });
+ expect(await readCurlPayload()).toMatchObject({ questions: { fit: { type: "score" } } });
});
it("clears the whole request and lets a preset be picked from nothing", async () => {
@@ -142,26 +145,24 @@ describe("SystemOneUI integration", () => {
expect(screen.getByRole("button", { name: "Send" })).toBeEnabled();
});
- it("keeps the preset label after picking a model and leaves an omitted model out when clearing", async () => {
+ it("keeps the preset label after picking a model and keeps that model when clearing", async () => {
+ const user = userEvent.setup();
mockModelLookup.mockResolvedValue(modelGroupInfoResponse(DECISION_AND_CHAT_MODELS));
render(<SystemOneUI accessToken="session-key" />);
- await waitFor(() => expect(screen.getByRole("combobox", { name: "Decision model" })).toHaveValue("jev-latest"));
+ const modelPicker = screen.getByRole("combobox", { name: "Decision model" });
+ await waitFor(() => expect(modelPicker).toHaveValue("jev-latest"));
const picker = screen.getByRole("combobox", { name: "Example" });
- const editor = await openJsonEditor();
- const example = JSON.parse((editor as HTMLTextAreaElement).value) as Record<string, unknown>;
- const { model: _model, ...withoutModel } = example;
- fireEvent.change(editor, {
- target: { value: JSON.stringify({ ...withoutModel, model: "pplx-decider" }, null, 2) },
- });
+ await user.clear(modelPicker);
+ await user.type(modelPicker, "p");
+ await user.click(await screen.findByRole("option", { name: "pplx-decider" }));
expect(picker).toHaveTextContent("Triage a bug report");
+ expect(await readCurlPayload()).toMatchObject({ model: "pplx-decider" });
- fireEvent.change(editor, { target: { value: JSON.stringify(withoutModel, null, 2) } });
- expect(picker).toHaveTextContent("Triage a bug report");
- await userEvent.click(screen.getByRole("button", { name: "Clear" }));
- expect(JSON.parse((editor as HTMLTextAreaElement).value)).toEqual({ state: "", questions: {} });
+ await user.click(screen.getByRole("button", { name: "Clear" }));
+ expect(await readCurlPayload()).toEqual({ model: "pplx-decider", state: "", questions: {} });
await selectPreset("Score a sales lead");
- expect(JSON.parse((editor as HTMLTextAreaElement).value)).not.toHaveProperty("model");
+ expect(await readCurlPayload()).toMatchObject({ model: "pplx-decider", questions: { fit: { type: "score" } } });
});
it("offers the same presets on /v1/decisions in the OpenAI shape and clears to an empty input", async () => {
@@ -169,16 +170,14 @@ describe("SystemOneUI integration", () => {
render(<SystemOneUI accessToken="session-key" />);
await selectEndpoint("/v1/decisions");
await selectPreset("Moderate a forum comment");
- await user.click(screen.getByRole("tab", { name: "JSON" }));
- const editor = screen.getByRole("textbox", { name: "Decisions JSON payload" }) as HTMLTextAreaElement;
- const payload = JSON.parse(editor.value);
+ const payload = await readCurlPayload();
expect(payload.input).toMatch(/stream=false/);
expect(payload.questions).toEqual([
{ type: "predicate", name: "breaks_rules", instructions: "Does this comment break the community guidelines?" },
]);
await user.click(screen.getByRole("button", { name: "Clear" }));
- expect(JSON.parse(editor.value)).toEqual({ input: "", questions: [] });
+ expect(await readCurlPayload()).toEqual({ input: "", questions: [] });
expect(screen.getByRole("button", { name: "Send" })).toBeDisabled();
});
@@ -194,17 +193,11 @@ describe("SystemOneUI integration", () => {
expect(screen.queryByText(/TypeSafe/)).not.toBeInTheDocument();
await userEvent.keyboard("{Escape}");
- expect(screen.getByRole("note", { name: "Decision endpoint notice" })).toHaveTextContent(
- "omit model to use the proxy's configured default.",
- );
expect(screen.getByRole("link", { name: "How to call /v1/decisions and /v1/systemone" })).toHaveAttribute(
"href",
"https://docs.litellm.ai/docs/decisions",
);
- expect(screen.getByRole("link", { name: "Give us feedback on what you want for decision models" })).toHaveAttribute(
- "href",
- "https://github.com/BerriAI/litellm/discussions/44231",
- );
+ expect(screen.queryByRole("note")).not.toBeInTheDocument();
expect(screen.queryByRole("alert")).not.toBeInTheDocument();
});
@@ -231,91 +224,79 @@ describe("SystemOneUI integration", () => {
mockModelLookup.mockResolvedValue(modelGroupInfoResponse(DECISION_AND_CHAT_MODELS));
render(<SystemOneUI accessToken="session-key" />);
await waitFor(() => expect(screen.getByRole("combobox", { name: "Decision model" })).toHaveValue("jev-latest"));
- const systemOneEditor = await openJsonEditor();
- const systemOneDraft = JSON.stringify({
- model: "jev-latest",
- state: "An outage",
- questions: { urgent: { type: "noul", instructions: "Is it urgent?" } },
- });
- fireEvent.change(systemOneEditor, { target: { value: systemOneDraft } });
+ fireEvent.change(screen.getByRole("textbox", { name: "Input" }), { target: { value: "An outage" } });
await selectEndpoint("/v1/decisions");
- const editor = screen.getByRole("textbox", { name: "Decisions JSON payload" });
- const nativeExample = (editor as HTMLTextAreaElement).value;
- expect(JSON.parse(nativeExample)).toMatchObject({
+ expect(screen.getByRole("textbox", { name: "Input" })).not.toHaveValue("An outage");
+ expect(await readCurlPayload()).toMatchObject({
input: expect.any(String),
questions: expect.arrayContaining([expect.objectContaining({ type: "predicate" })]),
});
- expect(screen.getByRole("tab", { name: "Form" })).toBeInTheDocument();
- const payload = {
- model: "jev-latest",
- input: "An outage",
- questions: [{ name: "urgent", type: "predicate", instructions: "Is it urgent?" }],
- safety_identifier: "qa-session",
- };
- fireEvent.change(editor, { target: { value: JSON.stringify(payload) } });
+ fireEvent.change(screen.getByRole("textbox", { name: "Input" }), { target: { value: "An outage" } });
const response: OpenAIDecisionsResponse = {
model: "jev-latest",
- answers: [{ name: "urgent", type: "predicate", probability: 0.95 }],
+ answers: [{ name: "has_repro_steps", type: "predicate", probability: 0.95 }],
usage: { input_tokens: 10, output_tokens: 1, total_tokens: 11 },
};
mockFetch.mockResolvedValueOnce(createResponse(response));
await user.click(screen.getByRole("button", { name: "Send" }));
- const result = await screen.findByRole("region", { name: "Decisions response JSON" });
- expect(result).toHaveTextContent('"probability": 0.95');
- expect(result).toHaveTextContent('"answers": [');
+ expect(await screen.findByRole("meter", { name: "Yes probability" })).toHaveAttribute("aria-valuenow", "95");
+ expect(screen.queryByRole("region", { name: "Decisions response JSON" })).not.toBeInTheDocument();
expect(mockFetch.mock.calls[0]?.[0]).toMatch(/\/v1\/decisions$/);
- expect(JSON.parse(mockFetch.mock.calls[0]?.[1]?.body as string)).toEqual(payload);
+ expect(JSON.parse(mockFetch.mock.calls[0]?.[1]?.body as string)).toMatchObject({
+ model: "jev-latest",
+ input: "An outage",
+ questions: expect.arrayContaining([expect.objectContaining({ type: "predicate" })]),
+ });
+ await user.click(screen.getByRole("tab", { name: "cURL" }));
+ const result = screen.getByRole("region", { name: "Decisions response JSON" });
+ expect(result).toHaveTextContent('"probability": 0.95');
+ expect(result).toHaveTextContent('"answers": [');
expect(screen.queryByRole("meter")).not.toBeInTheDocument();
await user.click(screen.getByRole("tab", { name: "Form" }));
- expect(screen.getByRole("meter", { name: "Yes probability" })).toHaveAttribute("aria-valuenow", "95");
- expect(screen.queryByRole("region", { name: "Decisions response JSON" })).not.toBeInTheDocument();
- await user.click(screen.getByRole("tab", { name: "JSON" }));
- expect(screen.getByRole("region", { name: "Decisions response JSON" })).toHaveTextContent('"probability": 0.95');
+ expect(screen.getByRole("meter", { name: "Yes probability" })).toBeInTheDocument();
expect(mockFetch).toHaveBeenCalledTimes(1);
await selectEndpoint("/v1/systemone");
- expect(screen.getByRole("textbox", { name: "System One JSON payload" })).toHaveValue(systemOneDraft);
- expect(screen.queryByRole("region", { name: "Decisions response JSON" })).not.toBeInTheDocument();
+ expect(screen.getByRole("textbox", { name: "Input" })).toHaveValue("An outage");
+ expect(screen.queryByRole("region", { name: "Decisions results" })).not.toBeInTheDocument();
await user.click(screen.getByRole("button", { name: "Send" }));
- expect(await screen.findByRole("region", { name: "Decisions response JSON" })).toHaveTextContent(
- '"choice": "technical"',
- );
- expect(screen.queryByRole("meter")).not.toBeInTheDocument();
- await user.click(screen.getByRole("tab", { name: "Form" }));
- expect(screen.getByText("Selected choice")).toBeInTheDocument();
+ expect(await screen.findByText("Selected choice")).toBeInTheDocument();
expect(screen.getByRole("meter", { name: "technical probability" })).toHaveAttribute("aria-valuenow", "90");
- await user.click(screen.getByRole("tab", { name: "JSON" }));
+ await user.click(screen.getByRole("tab", { name: "cURL" }));
+ expect(screen.getByRole("region", { name: "Decisions response JSON" })).toHaveTextContent('"choice": "technical"');
+ expect(screen.queryByRole("meter")).not.toBeInTheDocument();
expect(mockFetch).toHaveBeenCalledTimes(2);
expect(mockFetch.mock.calls[1]?.[0]).toMatch(/\/v1\/systemone$/);
- expect(JSON.parse(mockFetch.mock.calls[1]?.[1]?.body as string)).toEqual(JSON.parse(systemOneDraft));
+ expect(JSON.parse(mockFetch.mock.calls[1]?.[1]?.body as string)).toMatchObject({
+ model: "jev-latest",
+ state: "An outage",
+ });
await selectEndpoint("/v1/decisions");
- expect(screen.getByRole("textbox", { name: "Decisions JSON payload" })).toHaveValue(JSON.stringify(payload));
+ expect(await readCurlPayload()).toMatchObject({ input: "An outage" });
await selectPreset("Triage a bug report");
- expect(screen.getByRole("textbox", { name: "Decisions JSON payload" })).toHaveValue(nativeExample);
+ expect(screen.getByRole("textbox", { name: "Input" })).not.toHaveValue("An outage");
await selectEndpoint("/v1/systemone");
- expect(screen.getByRole("textbox", { name: "System One JSON payload" })).toHaveValue(systemOneDraft);
+ expect(screen.getByRole("textbox", { name: "Input" })).toHaveValue("An outage");
});
it("validates /v1/decisions independently and preserves an invalid draft across switches", async () => {
render(<SystemOneUI accessToken="session-key" />);
await selectEndpoint("/v1/decisions");
- await userEvent.click(screen.getByRole("tab", { name: "JSON" }));
- const editor = screen.getByRole("textbox", { name: "Decisions JSON payload" });
- fireEvent.change(editor, { target: { value: "{" } });
+ await userEvent.click(screen.getByRole("button", { name: "Clear" }));
expect(screen.getByRole("button", { name: "Send" })).toBeDisabled();
await selectEndpoint("/v1/systemone");
expect(screen.getByRole("button", { name: "Send" })).toBeEnabled();
await selectEndpoint("/v1/decisions");
- expect(screen.getByRole("textbox", { name: "Decisions JSON payload" })).toHaveValue("{");
+ expect(screen.getByRole("textbox", { name: "Input" })).toHaveValue("");
expect(screen.getByRole("button", { name: "Send" })).toBeDisabled();
expect(mockFetch).not.toHaveBeenCalled();
});
- it("offers a Decisions form that sends input and typed questions and stays in sync with JSON", async () => {
+ it("offers a Decisions form that sends input and typed questions and mirrors them in cURL", async () => {
const user = userEvent.setup();
mockFetch.mockResolvedValueOnce(
createResponse({
@@ -327,7 +308,6 @@ describe("SystemOneUI integration", () => {
render(<SystemOneUI accessToken="session-key" />);
await selectEndpoint("/v1/decisions");
expect(screen.getByRole("tab", { name: "Form" })).toHaveAttribute("aria-selected", "true");
- expect(screen.queryByRole("button", { name: "Format JSON" })).not.toBeInTheDocument();
fireEvent.change(screen.getByRole("textbox", { name: "Input" }), { target: { value: "Login is broken" } });
const firstQuestion = within(screen.getByRole("group", { name: "Question 1" }));
fireEvent.change(firstQuestion.getByRole("textbox", { name: "Question name" }), { target: { value: "team" } });
@@ -340,9 +320,7 @@ describe("SystemOneUI integration", () => {
fireEvent.change(screen.getByRole("textbox", { name: "Safety identifier" }), {
target: { value: "qa-session" },
});
- await user.click(screen.getByRole("tab", { name: "JSON" }));
- const editor = screen.getByRole("textbox", { name: "Decisions JSON payload" });
- const payload = JSON.parse((editor as HTMLTextAreaElement).value);
+ const payload = (await readCurlPayload()) as { questions: unknown[] };
expect(payload).toMatchObject({ input: "Login is broken", safety_identifier: "qa-session" });
const expectedQuestion = {
name: "team",
@@ -352,15 +330,12 @@ describe("SystemOneUI integration", () => {
};
expect(payload.questions[0]).toMatchObject(expectedQuestion);
expect(payload).not.toHaveProperty("state");
- fireEvent.change(editor, { target: { value: JSON.stringify({ ...payload, input: "Fixed in JSON" }) } });
- await user.click(screen.getByRole("tab", { name: "Form" }));
- expect(screen.getByRole("textbox", { name: "Input" })).toHaveValue("Fixed in JSON");
await user.click(screen.getByRole("button", { name: "Send" }));
await waitFor(() => expect(mockFetch).toHaveBeenCalledTimes(1));
expect(mockFetch.mock.calls[0]?.[0]).toMatch(/\/v1\/decisions$/);
- expect(JSON.parse(mockFetch.mock.calls[0]?.[1]?.body as string)).toEqual({ ...payload, input: "Fixed in JSON" });
+ expect(JSON.parse(mockFetch.mock.calls[0]?.[1]?.body as string)).toEqual(payload);
expect(await screen.findByRole("button", { name: "Raw response" })).toBeInTheDocument();
- await user.click(screen.getByRole("tab", { name: "JSON" }));
+ await user.click(screen.getByRole("tab", { name: "cURL" }));
expect(screen.getByRole("region", { name: "Decisions response JSON" })).toBeInTheDocument();
});
@@ -388,10 +363,7 @@ describe("SystemOneUI integration", () => {
target: { value: "Not urgent" },
});
expect(screen.getByRole("button", { name: "Send" })).toBeEnabled();
- await user.click(screen.getByRole("tab", { name: "JSON" }));
- const choicePayload = JSON.parse(
- (screen.getByRole("textbox", { name: "Decisions JSON payload" }) as HTMLTextAreaElement).value,
- );
+ const choicePayload = (await readCurlPayload()) as { questions: Record<string, unknown>[] };
const expectedChoice = {
type: "choice",
name: "question_1",
@@ -410,10 +382,7 @@ describe("SystemOneUI integration", () => {
expect(question(4).getByRole("textbox", { name: "Level 2 label" })).toHaveValue("2");
await user.click(question(2).getByRole("button", { name: "Remove question 2" }));
expect(question(3).getByRole("textbox", { name: "Instructions" })).toHaveValue("Should we escalate?");
- await user.click(screen.getByRole("tab", { name: "JSON" }));
- const scorePayload = JSON.parse(
- (screen.getByRole("textbox", { name: "Decisions JSON payload" }) as HTMLTextAreaElement).value,
- );
+ const scorePayload = (await readCurlPayload()) as { questions: Record<string, unknown>[] };
expect(scorePayload.questions).toHaveLength(3);
const expectedScore = {
type: "score",
@@ -424,10 +393,7 @@ describe("SystemOneUI integration", () => {
expect(scorePayload.questions[2]).toEqual(expectedScore);
await user.click(screen.getByRole("tab", { name: "Form" }));
await pick(question(3).getByRole("combobox", { name: "Answer type" }), "Predicate");
- await user.click(screen.getByRole("tab", { name: "JSON" }));
- const predicatePayload = JSON.parse(
- (screen.getByRole("textbox", { name: "Decisions JSON payload" }) as HTMLTextAreaElement).value,
- );
+ const predicatePayload = (await readCurlPayload()) as { questions: Record<string, unknown>[] };
expect(predicatePayload.questions[2]).toEqual({
type: "predicate",
name: "question_1",
@@ -435,60 +401,6 @@ describe("SystemOneUI integration", () => {
});
});
- it("preserves message input and extra fields in the Decisions form, including across routes and reset", async () => {
- const user = userEvent.setup();
- render(<SystemOneUI accessToken="session-key" />);
- await selectEndpoint("/v1/decisions");
- await user.click(screen.getByRole("tab", { name: "JSON" }));
- const payload = {
- model: "jev-latest",
- metadata: { source: "playground" },
- input: [
- {
- role: "user",
- content: [
- { type: "input_text", text: "Is this urgent?" },
- { type: "input_image", image_url: "https://example.com/image.png" },
- ],
- },
- ],
- questions: [{ type: "predicate", name: null, instructions: "Old instructions" }],
- };
- fireEvent.change(screen.getByRole("textbox", { name: "Decisions JSON payload" }), {
- target: { value: JSON.stringify(payload) },
- });
- await user.click(screen.getByRole("tab", { name: "Form" }));
- expect(screen.getByRole("button", { name: "Edit input in JSON" })).toBeInTheDocument();
- fireEvent.change(screen.getByRole("textbox", { name: "Instructions" }), { target: { value: "Is it urgent?" } });
- await selectEndpoint("/v1/systemone");
- const nativeInput = (screen.getByRole("textbox", { name: "Input" }) as HTMLTextAreaElement).value;
- await selectEndpoint("/v1/decisions");
- expect(screen.getByRole("textbox", { name: "Instructions" })).toHaveValue("Is it urgent?");
- await user.click(screen.getByRole("button", { name: "Edit input in JSON" }));
- const next = JSON.parse(
- (screen.getByRole("textbox", { name: "Decisions JSON payload" }) as HTMLTextAreaElement).value,
- );
- expect(next).toEqual({ ...payload, questions: [{ ...payload.questions[0], instructions: "Is it urgent?" }] });
- await user.click(screen.getByRole("tab", { name: "Form" }));
- await selectPreset("Triage a bug report");
- expect(screen.getByRole("textbox", { name: "Input" })).toBeInTheDocument();
- expect(screen.getAllByRole("group", { name: /Question \d/ })).toHaveLength(3);
- await selectEndpoint("/v1/systemone");
- expect(screen.getByRole("textbox", { name: "Input" })).toHaveValue(nativeInput);
- });
-
- it("keeps malformed Decisions JSON intact when switching to its form", async () => {
- const user = userEvent.setup();
- render(<SystemOneUI accessToken="session-key" />);
- await selectEndpoint("/v1/decisions");
- await user.click(screen.getByRole("tab", { name: "JSON" }));
- fireEvent.change(screen.getByRole("textbox", { name: "Decisions JSON payload" }), { target: { value: "{" } });
- await user.click(screen.getByRole("tab", { name: "Form" }));
- expect(screen.getByRole("button", { name: "Send" })).toBeDisabled();
- await user.click(screen.getByRole("button", { name: "Edit in JSON" }));
- expect(screen.getByRole("textbox", { name: "Decisions JSON payload" })).toHaveValue("{");
- });
-
it.each(["success", "error"])("cancels the previous endpoint request and ignores a late %s", async (outcome) => {
const pending = Promise.withResolvers<Response>();
mockFetch.mockReturnValueOnce(pending.promise);
@@ -529,8 +441,7 @@ describe("SystemOneUI integration", () => {
expect(screen.queryByRole("option", { name: "gpt-5.5" })).not.toBeInTheDocument();
await user.click(screen.getByRole("option", { name: "pplx-decider" }));
- const editor = await openJsonEditor();
- expect(JSON.parse((editor as HTMLTextAreaElement).value)).toMatchObject({
+ expect(await readCurlPayload()).toMatchObject({
model: "pplx-decider",
questions: { has_repro_steps: { type: "noul" } },
});
@@ -601,16 +512,14 @@ describe("SystemOneUI integration", () => {
const models = Promise.withResolvers<Response>();
mockModelLookup.mockReturnValue(models.promise);
render(<SystemOneUI accessToken="session-key" />);
- const editor = await openJsonEditor();
- const draft = JSON.stringify({ state: "edited", questions: { q: { type: "noul", instructions: "Yes?" } } });
- fireEvent.change(editor, { target: { value: draft } });
+ fireEvent.change(screen.getByRole("textbox", { name: "Input" }), { target: { value: "edited" } });
await act(async () => {
models.resolve(modelGroupInfoResponse(DECISION_AND_CHAT_MODELS));
await new Promise((resolve) => setTimeout(resolve, 0));
});
- expect(editor).toHaveValue(draft);
+ expect(screen.getByRole("textbox", { name: "Input" })).toHaveValue("edited");
expect(screen.getByRole("combobox", { name: "Decision model" })).toHaveValue("");
});
@@ -642,15 +551,46 @@ describe("SystemOneUI integration", () => {
},
);
- it("shows invalid JSON and disables Send", async () => {
+ it("shows a read-only cURL command for the proxy with a key placeholder instead of the real key", async () => {
+ const user = userEvent.setup();
+ sessionStorage.setItem("customProxyBaseUrl", "https://proxy.example/");
render(<SystemOneUI accessToken="session-key" />);
+ await user.click(screen.getByRole("tab", { name: "cURL" }));
- fireEvent.change(await openJsonEditor(), {
- target: { value: "{" },
+ const command = screen.getByLabelText("cURL request");
+ expect(command).toHaveTextContent("curl -X POST 'https://proxy.example/v1/systemone'");
+ expect(command).toHaveTextContent("Authorization: Bearer $LITELLM_API_KEY");
+ expect(command).not.toHaveTextContent("session-key");
+ expect(JSON.parse(curlPayload(command.textContent ?? "") ?? "")).toMatchObject({
+ questions: { has_repro_steps: { type: "noul" } },
});
+ expect(screen.queryByRole("textbox")).not.toBeInTheDocument();
+ expect(screen.getByRole("button", { name: "Copy cURL" })).toBeInTheDocument();
- expect(await screen.findByText(/Invalid JSON syntax/)).toBeInTheDocument();
- expect(screen.getByRole("button", { name: "Send" })).toBeDisabled();
+ await selectEndpoint("/v1/decisions");
+ expect(screen.getByLabelText("cURL request")).toHaveTextContent("https://proxy.example/v1/decisions");
+ expect(screen.getByRole("button", { name: "Send" })).toBeEnabled();
+ });
+
+ it("keeps Send below the form and shows results only after a request", async () => {
+ const user = userEvent.setup();
+ render(<SystemOneUI accessToken="session-key" />);
+
+ const send = screen.getByRole("button", { name: "Send" });
+ const editor = screen.getByRole("region", { name: "Decisions request editor" });
+ const form = within(editor).getByRole("textbox", { name: "Input" });
+ expect(form.compareDocumentPosition(send) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
+ expect(screen.queryByRole("region", { name: "Decisions results" })).not.toBeInTheDocument();
+ expect(screen.queryByRole("note")).not.toBeInTheDocument();
+
+ await user.click(send);
+
+ const results = await screen.findByRole("region", { name: "Decisions results" });
+ expect(within(results).getByText("Calibrated probabilities")).toBeInTheDocument();
+ expect(editor.compareDocumentPosition(results) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
+
+ fireEvent.change(within(editor).getByRole("textbox", { name: "Input" }), { target: { value: "Edited state" } });
+ expect(screen.queryByRole("region", { name: "Decisions results" })).not.toBeInTheDocument();
});
it("sends to /v1/systemone even without discovered models and renders calibrated answers", async () => {
@@ -692,64 +632,16 @@ describe("SystemOneUI integration", () => {
expect(screen.getByText("Selected choice")).toBeInTheDocument();
});
- it("validates native question values before sending", async () => {
- render(<SystemOneUI accessToken="session-key" />);
-
- fireEvent.change(await openJsonEditor(), {
- target: {
- value: JSON.stringify({
- state: "A new support request",
- questions: {
- category: {
- type: "choice",
- instructions: 1,
- criteria: { support: true },
- },
- },
- }),
- },
- });
-
- expect(screen.getByRole("button", { name: "Send" })).toBeDisabled();
- await userEvent.click(screen.getByRole("tab", { name: "Form" }));
- expect(screen.getByText("Enter a valid request to preview its state and questions.")).toBeInTheDocument();
- });
-
- it("sends structured native questions without changing their payload", async () => {
- const user = userEvent.setup();
- render(<SystemOneUI accessToken="session-key" />);
- const editor = await openJsonEditor();
- const draft = JSON.stringify({
- model: "my-decider",
- state: {},
- questions: {
- route: { type: "choice", criteria: { support: { text: "Help" }, other: null } },
- },
- });
- fireEvent.change(editor, { target: { value: draft } });
- expect(screen.getByRole("button", { name: "Send" })).toBeEnabled();
- await user.click(screen.getByRole("tab", { name: "Form" }));
- expect(screen.getByText(/"text": "Help"/)).toBeInTheDocument();
-
- await user.click(screen.getByRole("button", { name: "Send" }));
- expect(await screen.findByText("Selected choice")).toBeInTheDocument();
- expect(mockFetch.mock.calls[0]?.[0]).toMatch(/\/v1\/systemone$/);
- expect(JSON.parse(mockFetch.mock.calls[0]?.[1]?.body as string)).toEqual(JSON.parse(draft));
- });
-
it("sends a native request without model so the proxy can select its default", async () => {
const user = userEvent.setup();
render(<SystemOneUI accessToken="session-key" />);
- const payload = { state: "An outage", questions: { urgent: { type: "noul", instructions: "Is this urgent?" } } };
- fireEvent.change(await openJsonEditor(), {
- target: { value: JSON.stringify(payload) },
- });
+ fireEvent.change(screen.getByRole("textbox", { name: "Input" }), { target: { value: "An outage" } });
expect(screen.getByRole("button", { name: "Send" })).toBeEnabled();
await user.click(screen.getByRole("button", { name: "Send" }));
expect(await screen.findByText("jev-1.13.0")).toBeInTheDocument();
expect(mockFetch.mock.calls[0]?.[0]).toMatch(/\/v1\/systemone$/);
const body = JSON.parse(mockFetch.mock.calls[0]?.[1]?.body as string);
- expect(body).toEqual(payload);
+ expect(body).toMatchObject({ state: "An outage" });
expect(body).not.toHaveProperty("model");
});
@@ -844,19 +736,8 @@ describe("SystemOneUI integration", () => {
await user.click(screen.getByRole("button", { name: "Send" }));
expect(await screen.findByText("Selected choice")).toBeInTheDocument();
- fireEvent.change(await openJsonEditor(), {
- target: {
- value: JSON.stringify({
- state: "A different support request",
- questions: {
- department: {
- type: "choice",
- instructions: "Where should this go?",
- criteria: { billing: "Billing questions" },
- },
- },
- }),
- },
+ fireEvent.change(screen.getByRole("textbox", { name: "Input" }), {
+ target: { value: "A different support request" },
});
expect(screen.queryByText("Selected choice")).not.toBeInTheDocument();
@@ -920,13 +801,10 @@ describe("SystemOneUI integration", () => {
fireEvent.blur(field);
}
- it("explains noul on hover in the banner and on the answer type option", async () => {
+ it("explains noul on the answer type option", async () => {
const user = userEvent.setup();
render(<SystemOneUI accessToken="session-key" />);
- await user.hover(screen.getByText("noul", { selector: "span.cursor-help" }));
- expect(await screen.findByText(NOUL_HELP)).toBeInTheDocument();
-
question("has_repro_steps").getByRole("combobox", { name: "Answer type" }).focus();
await user.keyboard("{ArrowDown}");
expect(await screen.findByRole("option", { name: "noul" })).toHaveAttribute(
@@ -965,7 +843,6 @@ describe("SystemOneUI integration", () => {
await user.click(screen.getByRole("button", { name: "Send" }));
expect(await screen.findByText("Selected choice")).toBeInTheDocument();
- expect(screen.queryByRole("textbox", { name: "System One JSON payload" })).not.toBeInTheDocument();
expect(mockFetch.mock.calls[0]?.[0]).toMatch(/\/v1\/systemone$/);
expect(sentBody()).toEqual({
state: "The login page is blank after the upgrade",
@@ -1038,39 +915,8 @@ describe("SystemOneUI integration", () => {
expect(question("impact").getByRole("textbox", { name: "Question name" })).toHaveValue("impact");
await user.click(screen.getByRole("button", { name: "Add question" }));
await user.click(screen.getByRole("button", { name: "Add question" }));
- const json = JSON.parse(((await openJsonEditor()) as HTMLTextAreaElement).value);
+ const json = (await readCurlPayload()) as { questions: Record<string, unknown> };
expect(Object.keys(json.questions)).toEqual(["area", "has_repro_steps", "impact", "question_1", "question_2"]);
});
-
- it("round-trips unknown fields between JSON and the form and points to JSON when it cannot show one", async () => {
- const user = userEvent.setup();
- render(<SystemOneUI accessToken="session-key" />);
- expect(screen.queryByRole("button", { name: "Format JSON" })).not.toBeInTheDocument();
-
- fireEvent.change(await openJsonEditor(), {
- target: { value: JSON.stringify({ state: { ticket: 1 }, questions: {} }) },
- });
- expect(screen.getByRole("button", { name: "Format JSON" })).toBeInTheDocument();
- await user.click(screen.getByRole("tab", { name: "Form" }));
- expect(screen.getByText(/This request has JSON the form can.t show/)).toBeInTheDocument();
- await user.click(screen.getByRole("button", { name: "Edit in JSON" }));
-
- const payload = {
- model: "m",
- state: "s",
- metadata: { k: 1 },
- questions: { q: { type: "noul", instructions: "i", note: "x" } },
- };
- fireEvent.change(screen.getByRole("textbox", { name: "System One JSON payload" }), {
- target: { value: JSON.stringify(payload) },
- });
- await user.click(screen.getByRole("tab", { name: "Form" }));
- expect(screen.getByRole("textbox", { name: "Input" })).toHaveValue("s");
- fill(question("q").getByRole("textbox", { name: "Yes means" }), "y");
-
- const json = JSON.parse(((await openJsonEditor()) as HTMLTextAreaElement).value);
- expect(json).toEqual({ ...payload, questions: { q: { ...payload.questions.q, criteria: { true: "y" } } } });
- expect(Object.keys(json)).toEqual(["model", "state", "metadata", "questions"]);
- });
});
});
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/SystemOneUI.tsx b/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/SystemOneUI.tsx
index 3d2d4c0f1a0..ae5def7dc48 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/SystemOneUI.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/SystemOneUI.tsx
@@ -1,26 +1,26 @@
"use client";
-import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
-import { Button } from "@/components/ui/button";
+import { Button, buttonVariants } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { SimpleTooltip } from "@/components/ui/tooltip";
import { SearchSelect } from "@/components/shared/SearchSelect";
+import { cn } from "@/lib/cva.config";
import { DECISIONS_DOCS_URL } from "@/lib/decisionModels";
+import { getGlobalLitellmHeaderName, getProxyBaseUrl } from "@/components/networking";
import { uiHref } from "@/utils/uiHref";
import { useMutation } from "@tanstack/react-query";
-import { Code, Eraser, Info, LoaderCircle, Send } from "lucide-react";
+import { BookOpen, Eraser, LoaderCircle, Send } from "lucide-react";
import { useEffect, useMemo, useRef, useState } from "react";
import { makePlaygroundDecisionRequest, type PlaygroundDecisionRequest } from "../../llm_calls/system_one";
import { DECISION_PRESETS, emptyPayload, matchPreset, presetPayload, type DecisionPreset } from "./lib/example";
import { payloadModel, withPayloadModel } from "./lib/payloadModel";
-import JsonEditor from "./JsonEditor";
-import QuestionBreakdown from "./QuestionBreakdown";
+import CurlPreview from "./CurlPreview";
import ResponseView from "./ResponseView";
import SystemOneForm from "./SystemOneForm";
import OpenAIDecisionsForm from "./OpenAIDecisionsForm";
-import { validateSystemOnePayload, validateOpenAIDecisionsPayload } from "./lib/validatePayload";
+import { validateSystemOnePayload, validateOpenAIDecisionsPayload, errorCount } from "./lib/validatePayload";
import { useDecisionModels, type ApiKeySource } from "./useDecisionModels";
interface SystemOneUIProps {
@@ -28,7 +28,7 @@ interface SystemOneUIProps {
disabledPersonalKeyCreation?: boolean;
}
-type EditorView = "form" | "json";
+type EditorView = "form" | "curl";
interface SystemOneSendVariables {
request: PlaygroundDecisionRequest;
@@ -38,7 +38,6 @@ interface SystemOneSendVariables {
export const NOUL_HELP = "noul is a yes / no question. The model returns the probability that the answer is yes.";
const CUSTOM_PRESET = "custom";
-const DECISION_MODELS_DISCUSSION_URL = "https://github.com/BerriAI/litellm/discussions/44231";
interface PresetPickerProps {
activePreset: DecisionPreset | undefined;
@@ -96,13 +95,13 @@ export default function SystemOneUI({ accessToken, disabledPersonalKeyCreation =
[rawPayload, endpoint],
);
const validation = validated.validation;
- const hasSyntaxError = validation.issues.some((issue) => issue.path === "syntax");
const systemOne = useMutation({
mutationFn: ({ request, apiKey, signal }: SystemOneSendVariables) =>
makePlaygroundDecisionRequest(request, apiKey, getCustomProxyBaseUrl(), { signal }),
});
const isLoading = systemOne.isPending;
+ const hasResult = isLoading || systemOne.data !== undefined || systemOne.error !== null;
const { reset: resetSystemOne } = systemOne;
useEffect(() => () => activeController.current?.abort(), []);
@@ -119,6 +118,10 @@ export default function SystemOneUI({ accessToken, disabledPersonalKeyCreation =
systemOne.reset();
}
+ function handleReset() {
+ handlePayloadChange(presetPayload(DECISION_PRESETS[0], endpoint, draftModel ?? decisionModels[0]));
+ }
+
function handlePayloadChange(value: string) {
if (value !== rawPayload) {
clearRequestState();
@@ -140,12 +143,6 @@ export default function SystemOneUI({ accessToken, disabledPersonalKeyCreation =
}
}
- function handleFormatJson() {
- if (rawPayload.trim() && !hasSyntaxError) {
- handlePayloadChange(JSON.stringify(JSON.parse(rawPayload), null, 2));
- }
- }
-
function handleSend() {
const request: PlaygroundDecisionRequest | undefined =
validated.endpoint === "/v1/decisions"
@@ -163,49 +160,48 @@ export default function SystemOneUI({ accessToken, disabledPersonalKeyCreation =
}
return (
- <div className="flex h-full min-h-0 flex-col gap-4 overflow-auto p-4 xl:overflow-hidden">
- <section className="grid gap-3">
- <div className="flex flex-wrap items-center gap-2">
- <span className="text-sm font-medium text-muted-foreground">Endpoint</span>
- <Select
- value={endpoint}
- onValueChange={(value) => {
- if (value === "/v1/decisions" || value === "/v1/systemone") {
- clearRequestState();
- setEndpoint(value);
- }
- }}
- >
- <SelectTrigger className="w-80" aria-label="Decision endpoint">
- <SelectValue>{endpoint}</SelectValue>
- </SelectTrigger>
- <SelectContent>
- <SelectItem value="/v1/decisions">/v1/decisions</SelectItem>
- <SelectItem value="/v1/systemone">/v1/systemone</SelectItem>
- </SelectContent>
- </Select>
- <span className="ml-2 text-sm font-medium text-muted-foreground">Model</span>
- <div className="w-80">
- <SearchSelect
- aria-label="Decision model"
- options={decisionModels.map((model) => ({ label: model, value: model }))}
- value={payloadModel(rawPayload) ?? null}
- onValueChange={handleModelPick}
- placeholder={decisionModels.length > 0 ? "Pick a decision model" : "No decision models yet"}
- emptyText="No decision models found"
- disabled={hasSyntaxError}
- allowClear={false}
- />
- </div>
- {decisionModelsLoaded && decisionModels.length === 0 && (
- <a href={uiHref("models-and-endpoints")} className="text-sm text-primary underline">
- Add a decision model
- </a>
- )}
- </div>
- <div className="flex flex-wrap items-center gap-3">
+ <div className="flex h-full min-h-0 flex-col overflow-auto p-4 xl:overflow-hidden">
+ <div
+ className={cn(
+ "mx-auto grid w-full gap-4 xl:min-h-0 xl:flex-1",
+ hasResult ? "max-w-7xl xl:grid-cols-2" : "max-w-3xl",
+ )}
+ >
+ <section className="flex min-h-96 flex-col gap-3 xl:min-h-0" aria-label="Decisions request editor">
<div className="flex flex-wrap items-center gap-2">
- <span className="text-sm font-medium text-muted-foreground">Virtual Key Source</span>
+ <Select
+ value={endpoint}
+ onValueChange={(value) => {
+ if (value === "/v1/decisions" || value === "/v1/systemone") {
+ clearRequestState();
+ setEndpoint(value);
+ }
+ }}
+ >
+ <SelectTrigger className="w-44" aria-label="Decision endpoint">
+ <SelectValue>{endpoint}</SelectValue>
+ </SelectTrigger>
+ <SelectContent>
+ <SelectItem value="/v1/decisions">/v1/decisions</SelectItem>
+ <SelectItem value="/v1/systemone">/v1/systemone</SelectItem>
+ </SelectContent>
+ </Select>
+ <div className="w-56">
+ <SearchSelect
+ aria-label="Decision model"
+ options={decisionModels.map((model) => ({ label: model, value: model }))}
+ value={payloadModel(rawPayload) ?? null}
+ onValueChange={handleModelPick}
+ placeholder={decisionModels.length > 0 ? "Pick a decision model" : "No decision models yet"}
+ emptyText="No decision models found"
+ allowClear={false}
+ />
+ </div>
+ {decisionModelsLoaded && decisionModels.length === 0 && (
+ <a href={uiHref("models-and-endpoints")} className="text-sm text-primary underline">
+ Add a decision model
+ </a>
+ )}
<Select
value={apiKeySource}
onValueChange={(value) => {
@@ -215,7 +211,7 @@ export default function SystemOneUI({ accessToken, disabledPersonalKeyCreation =
}}
disabled={disabledPersonalKeyCreation}
>
- <SelectTrigger className="w-48" aria-label="Virtual Key Source">
+ <SelectTrigger className="w-44" aria-label="Virtual Key Source">
<SelectValue>{apiKeySource === "custom" ? "Virtual Key" : "Current UI Session"}</SelectValue>
</SelectTrigger>
<SelectContent>
@@ -236,112 +232,100 @@ export default function SystemOneUI({ accessToken, disabledPersonalKeyCreation =
/>
)}
</div>
- <div className="ml-auto flex items-center gap-2">
- <PresetPicker activePreset={activePreset} onPick={handlePresetPick} />
- <Button
- variant="outline"
- onClick={() => handlePayloadChange(clearedPayload)}
- disabled={rawPayload === clearedPayload}
- >
- <Eraser />
- Clear
- </Button>
- {view === "json" && (
- <Button variant="outline" onClick={handleFormatJson} disabled={!rawPayload.trim() || hasSyntaxError}>
- <Code />
- Format JSON
- </Button>
- )}
- {isLoading && (
- <Button variant="outline" onClick={clearRequestState}>
- Cancel request
- </Button>
- )}
- <Button onClick={handleSend} disabled={!validation.isValid || isLoading || !effectiveApiKey}>
- {isLoading ? <LoaderCircle className="animate-spin" /> : <Send />}
- Send
- </Button>
- </div>
- </div>
- <Alert role="note" aria-label="Decision endpoint notice">
- <Info />
- <AlertTitle>{endpoint}</AlertTitle>
- <AlertDescription>
- {endpoint === "/v1/decisions" ? (
- "Uses input and a questions array with predicate, choice, and score questions. Edit the form or JSON and inspect the response JSON in the OpenAI Decisions format."
- ) : (
- <>
- Uses state and a questions object with{" "}
- <SimpleTooltip content={NOUL_HELP} className="underline decoration-dotted underline-offset-2">
- noul
- </SimpleTooltip>
- , choice, and score questions in the System One format.
- </>
- )}{" "}
- Pick a decision model under Model, or omit model to use the proxy&apos;s configured default.{" "}
- <a href={DECISIONS_DOCS_URL} target="_blank" rel="noopener noreferrer" className="underline">
- How to call /v1/decisions and /v1/systemone
- </a>
- {" · "}
- <a href={DECISION_MODELS_DISCUSSION_URL} target="_blank" rel="noopener noreferrer" className="underline">
- Give us feedback on what you want for decision models
- </a>
- </AlertDescription>
- </Alert>
- </section>
- <div className="grid gap-4 xl:min-h-0 xl:flex-1 xl:grid-cols-2">
- <section className="flex min-h-96 flex-col xl:min-h-0" aria-label="Decisions request editor">
<Tabs
value={view}
- onValueChange={(value) => (value === "form" || value === "json") && setView(value)}
+ onValueChange={(value) => (value === "form" || value === "curl") && setView(value)}
className="min-h-0 flex-1"
>
- <TabsList aria-label="Request editor view">
- <TabsTrigger value="form">Form</TabsTrigger>
- <TabsTrigger value="json">JSON</TabsTrigger>
- </TabsList>
+ <div className="flex flex-wrap items-center justify-between gap-2">
+ <TabsList aria-label="Request editor view">
+ <TabsTrigger value="form">Form</TabsTrigger>
+ <TabsTrigger value="curl">cURL</TabsTrigger>
+ </TabsList>
+ <div className="flex items-center gap-1">
+ <PresetPicker activePreset={activePreset} onPick={handlePresetPick} />
+ <SimpleTooltip content="How to call /v1/decisions and /v1/systemone">
+ <a
+ href={DECISIONS_DOCS_URL}
+ target="_blank"
+ rel="noopener noreferrer"
+ aria-label="How to call /v1/decisions and /v1/systemone"
+ className={cn(buttonVariants({ variant: "ghost", size: "icon" }), "shrink-0")}
+ >
+ <BookOpen />
+ </a>
+ </SimpleTooltip>
+ </div>
+ </div>
<TabsContent value="form" className="flex min-h-0 flex-col">
{validated.endpoint === "/v1/decisions" ? (
<OpenAIDecisionsForm
value={rawPayload}
onChange={handlePayloadChange}
validation={validated.validation}
- onOpenJson={() => setView("json")}
+ onReset={handleReset}
/>
) : (
<SystemOneForm
value={rawPayload}
onChange={handlePayloadChange}
validation={validated.validation}
- onOpenJson={() => setView("json")}
+ onReset={handleReset}
/>
)}
</TabsContent>
- <TabsContent value="json" className="flex min-h-0 flex-col">
- <JsonEditor
- value={rawPayload}
- onChange={handlePayloadChange}
- validation={validation}
- label={endpoint === "/v1/decisions" ? "Decisions JSON payload" : "System One JSON payload"}
- placeholder={`Paste or write a ${endpoint} request`}
+ <TabsContent value="curl" className="flex min-h-0 flex-col">
+ <CurlPreview
+ baseUrl={getCustomProxyBaseUrl() ?? getProxyBaseUrl()}
+ endpoint={endpoint}
+ payload={validation.payload === undefined ? rawPayload : JSON.stringify(validation.payload)}
+ authHeaderName={getGlobalLitellmHeaderName()}
+ errorCount={errorCount(validation)}
/>
</TabsContent>
</Tabs>
+
+ <div className="flex flex-wrap items-center gap-2">
+ <Button
+ variant="ghost"
+ onClick={() => handlePayloadChange(clearedPayload)}
+ disabled={rawPayload === clearedPayload}
+ >
+ <Eraser />
+ Clear
+ </Button>
+ <div className="ml-auto flex items-center gap-2">
+ {isLoading && (
+ <Button variant="outline" onClick={clearRequestState}>
+ Cancel request
+ </Button>
+ )}
+ <Button
+ size="lg"
+ className="min-w-32"
+ onClick={handleSend}
+ disabled={!validation.isValid || isLoading || !effectiveApiKey}
+ >
+ {isLoading ? <LoaderCircle className="animate-spin" /> : <Send />}
+ Send
+ </Button>
+ </div>
+ </div>
</section>
- <section className="grid content-start gap-4 xl:min-h-0 xl:overflow-auto" aria-label="Decisions results">
- <ResponseView
- response={systemOne.data?.response}
- view={view}
- fallbackModel={validation.payload?.model}
- latencyMs={systemOne.data?.latencyMs}
- error={systemOne.error?.message}
- isLoading={isLoading}
- />
- {view === "form" && validated.endpoint === "/v1/systemone" && (
- <QuestionBreakdown payload={validated.validation.payload} />
- )}
- </section>
+
+ {hasResult && (
+ <section className="grid content-start gap-4 xl:min-h-0 xl:overflow-auto" aria-label="Decisions results">
+ <ResponseView
+ response={systemOne.data?.response}
+ view={view}
+ fallbackModel={validation.payload?.model}
+ latencyMs={systemOne.data?.latencyMs}
+ error={systemOne.error?.message}
+ isLoading={isLoading}
+ />
+ </section>
+ )}
</div>
</div>
);
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/ValidationFeedback.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/ValidationFeedback.test.tsx
new file mode 100644
index 00000000000..24f93c58af9
--- /dev/null
+++ b/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/ValidationFeedback.test.tsx
@@ -0,0 +1,40 @@
+import { render, screen } from "@testing-library/react";
+import { describe, expect, it } from "vitest";
+import { IssueList, ValidationStatus } from "./ValidationFeedback";
+import type { PayloadValidation } from "./lib/validatePayload";
+
+const validation = (issues: PayloadValidation<unknown>["issues"]): PayloadValidation<unknown> => ({
+ isValid: issues.every((issue) => issue.severity !== "error"),
+ issues,
+});
+
+describe("ValidationStatus", () => {
+ it("counts only errors as issues", () => {
+ render(
+ <ValidationStatus
+ validation={validation([
+ { path: "state", message: "Required", severity: "error" },
+ { path: "model", message: "Required", severity: "error" },
+ { path: "questions.a", message: "Long question", severity: "warning" },
+ ])}
+ />,
+ );
+ expect(screen.getByText("2 issues")).toBeInTheDocument();
+ });
+
+ it("reports a valid payload when only warnings remain", () => {
+ render(<ValidationStatus validation={validation([{ path: "q", message: "Long", severity: "warning" }])} />);
+ expect(screen.getByText("Valid payload")).toBeInTheDocument();
+ });
+});
+
+describe("IssueList", () => {
+ it("lists every issue with its path and says ready when there are none", () => {
+ const { rerender } = render(
+ <IssueList id="issues" validation={validation([{ path: "state", message: "Required", severity: "error" }])} />,
+ );
+ expect(screen.getByRole("list", { name: "Payload validation issues" })).toHaveTextContent("stateRequired");
+ rerender(<IssueList id="issues" validation={validation([])} />);
+ expect(screen.getByRole("status")).toHaveTextContent("Ready to send");
+ });
+});
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/ValidationFeedback.tsx b/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/ValidationFeedback.tsx
new file mode 100644
index 00000000000..369c4243857
--- /dev/null
+++ b/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/ValidationFeedback.tsx
@@ -0,0 +1,41 @@
+import { Badge } from "@/components/ui/badge";
+import { CircleAlert, CircleCheck, TriangleAlert } from "lucide-react";
+import { errorCount as countErrors, type PayloadValidation } from "./lib/validatePayload";
+
+export function ValidationStatus({ validation }: { validation: PayloadValidation<unknown> }) {
+ const errorCount = countErrors(validation);
+ if (errorCount > 0) {
+ return (
+ <Badge variant="destructive">
+ {errorCount} {errorCount === 1 ? "issue" : "issues"}
+ </Badge>
+ );
+ }
+ return <Badge variant="secondary">Valid payload</Badge>;
+}
+
+export function IssueList({ id, validation }: { id: string; validation: PayloadValidation<unknown> }) {
+ if (validation.issues.length === 0) {
+ return (
+ <p id={id} role="status" className="flex items-center gap-1.5 border-t px-3 py-2 text-xs text-muted-foreground">
+ <CircleCheck className="size-3.5 text-emerald-600 dark:text-emerald-400" />
+ Ready to send
+ </p>
+ );
+ }
+ return (
+ <ul id={id} aria-label="Payload validation issues" className="grid max-h-36 gap-1 overflow-auto border-t px-3 py-2">
+ {validation.issues.map((issue, index) => (
+ <li key={`${issue.path}-${index}`} className="flex items-start gap-1.5 text-xs">
+ {issue.severity === "error" ? (
+ <CircleAlert className="mt-0.5 size-3.5 shrink-0 text-destructive" />
+ ) : (
+ <TriangleAlert className="mt-0.5 size-3.5 shrink-0 text-amber-600 dark:text-amber-400" />
+ )}
+ <code className="shrink-0 rounded bg-muted px-1 font-mono">{issue.path}</code>
+ <span>{issue.message}</span>
+ </li>
+ ))}
+ </ul>
+ );
+}
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/lib/curlCommand.test.ts b/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/lib/curlCommand.test.ts
new file mode 100644
index 00000000000..4cd749ba913
--- /dev/null
+++ b/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/lib/curlCommand.test.ts
@@ -0,0 +1,72 @@
+import { execFileSync } from "node:child_process";
+import { describe, expect, it } from "vitest";
+import { buildCurlCommand, curlPayload } from "./curlCommand";
+
+describe("buildCurlCommand", () => {
+ it("targets the proxy endpoint with a key placeholder and the pretty payload", () => {
+ const input = {
+ baseUrl: "http://localhost:4000/",
+ endpoint: "/v1/systemone",
+ payload: JSON.stringify({ model: "jev-latest", state: "it's broken" }),
+ authHeaderName: "Authorization",
+ };
+ const command = buildCurlCommand(input);
+
+ expect(command).toContain("curl -X POST 'http://localhost:4000/v1/systemone'");
+ expect(command).toContain('-H "Authorization: Bearer $LITELLM_API_KEY"');
+ expect(command).not.toContain("sk-");
+ expect(command).toContain(' "state": "it\'\\\'\'s broken"');
+ expect(JSON.parse(curlPayload(command) ?? "")).toEqual({ model: "jev-latest", state: "it's broken" });
+ });
+
+ it("quotes a proxy URL that carries shell metacharacters", () => {
+ const input = {
+ baseUrl: "http://proxy.example/$(touch pwned)'; echo x",
+ endpoint: "/v1/decisions",
+ payload: "{}",
+ authHeaderName: "Authorization",
+ };
+ const command = buildCurlCommand(input);
+ expect(command).toContain(`curl -X POST 'http://proxy.example/$(touch pwned)'\\''; echo x/v1/decisions'`);
+ });
+
+ it("sends the key under the proxy's configured auth header name", () => {
+ const input = {
+ baseUrl: "https://proxy.example",
+ endpoint: "/v1/systemone",
+ payload: "{}",
+ authHeaderName: "X-Litellm-Key",
+ };
+ const command = buildCurlCommand(input);
+ expect(command).toContain('-H "X-Litellm-Key: Bearer $LITELLM_API_KEY"');
+ expect(command).not.toContain("Authorization");
+ });
+
+ it("lets the shell expand the key while a hostile header name stays literal", () => {
+ const input = {
+ baseUrl: "https://proxy.example",
+ endpoint: "/v1/systemone" as const,
+ payload: "{}",
+ authHeaderName: 'X-"$(touch pwned)`id`\\Key',
+ };
+ const command = buildCurlCommand(input);
+ const args = execFileSync("bash", ["-c", command.replace(/^curl /, "printf '%s\\n' ")], {
+ encoding: "utf8",
+ env: { ...process.env, LITELLM_API_KEY: "sk-test-key" },
+ });
+ expect(args).toContain('X-"$(touch pwned)`id`\\Key: Bearer sk-test-key\n');
+ expect(args).not.toContain("$LITELLM_API_KEY");
+ });
+
+ it("passes a payload that is not JSON through untouched", () => {
+ const input = {
+ baseUrl: "https://proxy.example",
+ endpoint: "/v1/decisions",
+ payload: "{",
+ authHeaderName: "Authorization",
+ };
+ const command = buildCurlCommand(input);
+ expect(command).toContain("'https://proxy.example/v1/decisions'");
+ expect(curlPayload(command)).toBe("{");
+ });
+});
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/lib/curlCommand.ts b/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/lib/curlCommand.ts
new file mode 100644
index 00000000000..22ede5ab6f3
--- /dev/null
+++ b/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/lib/curlCommand.ts
@@ -0,0 +1,33 @@
+export interface CurlCommandInput {
+ baseUrl: string;
+ endpoint: "/v1/decisions" | "/v1/systemone";
+ payload: string;
+ authHeaderName: string;
+}
+
+export const CURL_KEY_PLACEHOLDER = "$LITELLM_API_KEY";
+
+const shellSingleQuote = (value: string): string => `'${value.replace(/'/g, `'\\''`)}'`;
+
+const shellDoubleQuoteLiteral = (value: string): string => value.replace(/["\\$`]/g, (char) => `\\${char}`);
+
+const prettyPayload = (payload: string): string => {
+ try {
+ return JSON.stringify(JSON.parse(payload), null, 2);
+ } catch {
+ return payload;
+ }
+};
+
+export const buildCurlCommand = ({ baseUrl, endpoint, payload, authHeaderName }: CurlCommandInput): string =>
+ [
+ `curl -X POST ${shellSingleQuote(`${baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl}${endpoint}`)}`,
+ ` -H "${shellDoubleQuoteLiteral(authHeaderName)}: Bearer ${CURL_KEY_PLACEHOLDER}"`,
+ ` -H "Content-Type: application/json"`,
+ ` -d ${shellSingleQuote(prettyPayload(payload))}`,
+ ].join(" \\\n");
+
+export const curlPayload = (command: string): string | undefined => {
+ const match = /-d '([\s\S]*)'$/.exec(command);
+ return match === null ? undefined : match[1].replace(/'\\''/g, "'");
+};
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/lib/validatePayload.ts b/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/lib/validatePayload.ts
index 316c98e6c92..d74923bb3e6 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/lib/validatePayload.ts
+++ b/ui/litellm-dashboard/src/app/(dashboard)/playground/components/systemOneUI/lib/validatePayload.ts
@@ -23,6 +23,9 @@ export interface PayloadValidation<T> {
export type SystemOnePayloadValidation = PayloadValidation<PlaygroundRequest>;
+export const errorCount = (validation: PayloadValidation<unknown>): number =>
+ validation.issues.filter((issue) => issue.severity === "error").length;
+
const invalid = (path: string, message: string) => ({
isValid: false,
issues: [{ path, message, severity: "error" as const }],