Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors
TypeScript a2aai-agentsai-gatewayanthropicclaudeclaude-codeclinecodexcopilotcursordeepseekfree-aigeminikimillm-gatewaymcpopenaiopenai-proxyqwentoken-saver
refactor(playground): expand endpoint contract to 13 endpoints (D4-rev2)
diegosouzapwc89d27ada6c4
diff --git a/src/app/(dashboard)/dashboard/playground/components/StudioConfigPane.tsx b/src/app/(dashboard)/dashboard/playground/components/StudioConfigPane.tsxindex f2e76bf95b..decb51ed73 100644--- a/src/app/(dashboard)/dashboard/playground/components/StudioConfigPane.tsx+++ b/src/app/(dashboard)/dashboard/playground/components/StudioConfigPane.tsx@@ -24,11 +24,14 @@ interface StudioConfigPaneProps {const ENDPOINT_OPTIONS: Array<{ value: PlaygroundEndpoint; label: string }> = [{ value: "chat.completions", label: "Chat completions" },+ { value: "responses", label: "Responses" },{ value: "completions", label: "Completions" },{ value: "embeddings", label: "Embeddings" },{ value: "images", label: "Images" },{ value: "audio.transcriptions", label: "Audio transcriptions" },{ value: "audio.speech", label: "Audio speech" },+ { value: "video", label: "Video" },+ { value: "music", label: "Music" },{ value: "moderations", label: "Moderations" },{ value: "rerank", label: "Rerank" },{ value: "search", label: "Search" },diff --git a/src/lib/playground/codeExport.ts b/src/lib/playground/codeExport.tsindex 01bc457cc1..b58eca72f5 100644--- a/src/lib/playground/codeExport.ts+++ b/src/lib/playground/codeExport.ts@@ -2,16 +2,24 @@import { z } from "zod";/**- * Endpoint suportado pelo Playground Studio. Reflete os 10 endpoints da aba API- * + os endpoints consumidos pelas tabs Chat/Compare/Build/Search/Scrape.+ * Endpoint suportado pelo Playground Studio. Reflete os 13 endpoints da API OmniRoute+ * consumíveis pelas tabs Chat/Compare/Build/Search/Scrape via Export Code.+ *+ * D4-rev2 (2026-05-28): contrato expandido de 10 → 13 incluindo `responses`, `video`,+ * `music` para refletir a API real (`/v1/responses`, `/v1/videos/generations`,+ * `/v1/music/generations`). A tab API (Monaco editor) mantém seu próprio sistema+ * de endpoint values (D14) e não consome este type.*/export type PlaygroundEndpoint =| "chat.completions"+ | "responses"| "completions"| "embeddings"| "images"| "audio.transcriptions"| "audio.speech"+ | "video"+ | "music"| "moderations"| "rerank"| "search"@@ -76,11 +84,14 @@ export interface PlaygroundState {export const PlaygroundStateSchema = z.object({endpoint: z.enum(["chat.completions",+ "responses","completions","embeddings","images","audio.transcriptions","audio.speech",+ "video",+ "music","moderations","rerank","search",@@ -116,11 +127,14 @@ export const API_KEY_PLACEHOLDER = "$OMNIROUTE_API_KEY";export function endpointToPath(endpoint: PlaygroundEndpoint): string {const map: Record<PlaygroundEndpoint, string> = {"chat.completions": "/v1/chat/completions",+ responses: "/v1/responses",completions: "/v1/completions",embeddings: "/v1/embeddings",images: "/v1/images/generations","audio.transcriptions": "/v1/audio/transcriptions","audio.speech": "/v1/audio/speech",+ video: "/v1/videos/generations",+ music: "/v1/music/generations",moderations: "/v1/moderations",rerank: "/v1/rerank",search: "/v1/search",@@ -159,6 +173,18 @@ function buildBody(state: PlaygroundState): Record<string, unknown> {return body;}+ case "responses": {+ const body: Record<string, unknown> = {+ model: model ?? "gpt-4o-mini",+ input: state.prompt ?? "Hello!",+ stream: stream ?? false,+ };+ if (state.systemPrompt) body.instructions = state.systemPrompt;+ if (params) Object.assign(body, params);+ if (tools && tools.length > 0) body.tools = tools;+ return body;+ }+case "completions": {const body: Record<string, unknown> = {model: model ?? "gpt-3.5-turbo-instruct",@@ -202,6 +228,24 @@ function buildBody(state: PlaygroundState): Record<string, unknown> {};}+ case "video": {+ const body: Record<string, unknown> = {+ model: model ?? "sora-1.0",+ prompt: state.prompt ?? "A cinematic shot of a city at sunset",+ };+ if (params) Object.assign(body, params);+ return body;+ }++ case "music": {+ const body: Record<string, unknown> = {+ model: model ?? "music-1",+ prompt: state.prompt ?? "An upbeat lo-fi instrumental",+ };+ if (params) Object.assign(body, params);+ return body;+ }+case "moderations": {return {model: model ?? "text-moderation-latest",diff --git a/tests/unit/playground-code-export.test.ts b/tests/unit/playground-code-export.test.tsindex 508acc9f1d..9bac631b07 100644--- a/tests/unit/playground-code-export.test.ts+++ b/tests/unit/playground-code-export.test.ts@@ -25,13 +25,16 @@ function assertSecurityInvariants(generated: string, label: string) {// ── endpointToPath ─────────────────────────────────────────────────────────────-test("endpointToPath: maps all 10 endpoints correctly", () => {+test("endpointToPath: maps all 13 endpoints correctly (D4-rev2)", () => {assert.equal(endpointToPath("chat.completions"), "/v1/chat/completions");+ assert.equal(endpointToPath("responses"), "/v1/responses");assert.equal(endpointToPath("completions"), "/v1/completions");assert.equal(endpointToPath("embeddings"), "/v1/embeddings");assert.equal(endpointToPath("images"), "/v1/images/generations");assert.equal(endpointToPath("audio.transcriptions"), "/v1/audio/transcriptions");assert.equal(endpointToPath("audio.speech"), "/v1/audio/speech");+ assert.equal(endpointToPath("video"), "/v1/videos/generations");+ assert.equal(endpointToPath("music"), "/v1/music/generations");assert.equal(endpointToPath("moderations"), "/v1/moderations");assert.equal(endpointToPath("rerank"), "/v1/rerank");assert.equal(endpointToPath("search"), "/v1/search");@@ -403,6 +406,96 @@ test("audio.speech: defaults model and prompt when not provided", () => {}});+// ── responses (D4-rev2) ───────────────────────────────────────────────────────++test("responses × all languages: security + path", () => {+ const state = {+ endpoint: "responses" as const,+ baseUrl: "http://localhost:20128",+ model: "gpt-4o",+ prompt: "Summarize the news",+ systemPrompt: "Be concise.",+ };+ for (const lang of ["curl", "python", "typescript"] as const) {+ const generated = exportCode(state, lang);+ assertSecurityInvariants(generated, `responses/${lang}`);+ assert.ok(generated.includes("/v1/responses"), `${lang}: correct path`);+ assert.ok(generated.includes("Summarize the news"), `${lang}: input present`);+ assert.ok(generated.includes("Be concise."), `${lang}: instructions present`);+ }+});++test("responses: defaults model and input when not provided", () => {+ const state = {+ endpoint: "responses" as const,+ baseUrl: "http://localhost:20128",+ };+ for (const lang of ["curl", "python", "typescript"] as const) {+ const generated = exportCode(state, lang);+ assertSecurityInvariants(generated, `responses/defaults/${lang}`);+ assert.ok(generated.includes("gpt-4o-mini"), `${lang}: default model`);+ assert.ok(generated.includes("Hello!"), `${lang}: default input`);+ }+});++// ── video (D4-rev2) ───────────────────────────────────────────────────────────++test("video × all languages: security + path", () => {+ const state = {+ endpoint: "video" as const,+ baseUrl: "http://localhost:20128",+ model: "sora-1.0",+ prompt: "A cat playing piano",+ };+ for (const lang of ["curl", "python", "typescript"] as const) {+ const generated = exportCode(state, lang);+ assertSecurityInvariants(generated, `video/${lang}`);+ assert.ok(generated.includes("/v1/videos/generations"), `${lang}: correct path`);+ assert.ok(generated.includes("A cat playing piano"), `${lang}: prompt present`);+ }+});++test("video: defaults when no model/prompt provided", () => {+ const state = {+ endpoint: "video" as const,+ baseUrl: "http://localhost:20128",+ };+ for (const lang of ["curl", "python", "typescript"] as const) {+ const generated = exportCode(state, lang);+ assertSecurityInvariants(generated, `video/defaults/${lang}`);+ assert.ok(generated.includes("sora-1.0"), `${lang}: default model`);+ }+});++// ── music (D4-rev2) ───────────────────────────────────────────────────────────++test("music × all languages: security + path", () => {+ const state = {+ endpoint: "music" as const,+ baseUrl: "http://localhost:20128",+ model: "music-1",+ prompt: "An ambient piano piece",+ };+ for (const lang of ["curl", "python", "typescript"] as const) {+ const generated = exportCode(state, lang);+ assertSecurityInvariants(generated, `music/${lang}`);+ assert.ok(generated.includes("/v1/music/generations"), `${lang}: correct path`);+ assert.ok(generated.includes("An ambient piano piece"), `${lang}: prompt present`);+ }+});++test("music: defaults when no model/prompt provided", () => {+ const state = {+ endpoint: "music" as const,+ baseUrl: "http://localhost:20128",+ };+ for (const lang of ["curl", "python", "typescript"] as const) {+ const generated = exportCode(state, lang);+ assertSecurityInvariants(generated, `music/defaults/${lang}`);+ assert.ok(generated.includes("music-1"), `${lang}: default model`);+ }+});+test("moderations: defaults model and prompt when not provided", () => {const state = {endpoint: "moderations" as const,