The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.
TypeScript ai-videocomfyuicreative-toolsgenerative-aiideogramimage-generationimage-to-3dimage-to-videoltx-videominimax-h3nextjsopen-sourceopen-weightsqwen-imagetext-to-imagevideo-generationwan
Tests for round-3 cloud models, payload mapping and structured outputs
Claude25daa9881e86
diff --git a/scripts/gen-cloud-models.py b/scripts/gen-cloud-models.pyindex 1e95e7b8..f3458667 100644--- a/scripts/gen-cloud-models.py+++ b/scripts/gen-cloud-models.py@@ -421,10 +421,6 @@ model("sonilo-sfx", "Sonilo SFX 1.1", "Sonilo", "sonilo", "audio", "Fast, cheap[("sfx", "sonilo/v1.1/text-to-sound-effects")], badges=["fast"], defaults={"duration": 5}, options={"durations": [2, 5, 8, 15, 30]})model("stable-audio-3-sfx", "Stable Audio 3 SFX", "Stability AI", "stable-audio", "audio", "Stability's small SFX model — crisp one-shots and ambiences",[("sfx", "fal-ai/stable-audio-3/small/sfx/text-to-audio")], defaults={"duration": 10}, options={"durations": [5, 10, 30, 60]})-model("stable-audio-2-5", "Stable Audio 2.5", "Stability AI", "stable-audio", "audio", "Sound design and music beds up to 3 minutes",- [("sfx", "fal-ai/stable-audio-25/text-to-audio"), ("music", "fal-ai/stable-audio-25/text-to-audio"),- ("sfx", "stability-ai/stable-audio-2.5", "replicate"), ("music", "stability-ai/stable-audio-2.5", "replicate")],- defaults={"duration": 30}, options={"durations": [10, 30, 60, 120, 190]})model("cassette-sfx", "CassetteAI Sound Effects", "CassetteAI", "cassette", "audio", "One-cent sound effects up to 30 s",[("sfx", "cassetteai/sound-effects-generator")], badges=["fast"], defaults={"duration": 5}, options={"durations": [2, 5, 10, 30]})model("seed-audio", "Seed Audio 1.0", "ByteDance", "seed-audio", "audio", "Higgsfield's Seed Audio: speech, ambience, music and Foley from one prompt",@@ -442,6 +438,10 @@ model("stable-audio-3-music", "Stable Audio 3 Music", "Stability AI", "stable-aumodel("mureka-song", "Mureka 9.5", "Mureka", "mureka", "audio", "Full songs with vocals in many genres",[("music", "mureka/api/generate/song")], pricing=("request", 0.75, "prompt-to-song on mureka-9.5; with lyrics $0.225"),controls=[("model", "Version"), ("gender", "Voice")])+model("stable-audio-2-5", "Stable Audio 2.5", "Stability AI", "stable-audio", "audio", "Sound design and music beds up to 3 minutes",+ [("sfx", "fal-ai/stable-audio-25/text-to-audio"), ("music", "fal-ai/stable-audio-25/text-to-audio"),+ ("sfx", "stability-ai/stable-audio-2.5", "replicate"), ("music", "stability-ai/stable-audio-2.5", "replicate")],+ defaults={"duration": 30}, options={"durations": [10, 30, 60, 120, 190]})model("elevenlabs-sfx", "ElevenLabs Sound Effects", "ElevenLabs", "elevenlabs", "audio", "Describe a sound, get a sound",[("sfx", "fal-ai/elevenlabs/sound-effects/v2")], pricing=("second", 0.002), defaults={"duration": 5}, options={"durations": [2, 5, 10, 22]})model("elevenlabs-music", "ElevenLabs Music", "ElevenLabs", "elevenlabs", "audio", "Studio-quality songs from a prompt",diff --git a/src/lib/catalog/cloud-models.generated.ts b/src/lib/catalog/cloud-models.generated.tsindex eda4a8e0..d53f8ea5 100644--- a/src/lib/catalog/cloud-models.generated.ts+++ b/src/lib/catalog/cloud-models.generated.ts@@ -9038,80 +9038,6 @@ export const CLOUD_MODELS: ModelDef[] = ["usd": 0.0206}},- {- "id": "stable-audio-2-5",- "name": "Stable Audio 2.5",- "vendor": "Stability AI",- "family": "stable-audio",- "engine": "cloud",- "kind": "audio",- "tagline": "Sound design and music beds up to 3 minutes",- "routes": [- {- "op": "sfx",- "provider": "fal",- "endpoint": "fal-ai/stable-audio-25/text-to-audio",- "map": {- "seed": "seed",- "duration": {- "key": "seconds_total",- "type": "number"- }- }- },- {- "op": "music",- "provider": "fal",- "endpoint": "fal-ai/stable-audio-25/text-to-audio",- "map": {- "seed": "seed",- "duration": {- "key": "seconds_total",- "type": "number"- }- }- },- {- "op": "sfx",- "provider": "replicate",- "endpoint": "stability-ai/stable-audio-2.5",- "map": {- "duration": {- "key": "duration",- "type": "number"- }- }- },- {- "op": "music",- "provider": "replicate",- "endpoint": "stability-ai/stable-audio-2.5",- "map": {- "duration": {- "key": "duration",- "type": "number"- }- }- }- ],- "options": {- "seed": true,- "durations": [- 10,- 30,- 60,- 120,- 190- ]- },- "defaults": {- "duration": 30- },- "pricing": {- "unit": "request",- "usd": 0.2- }- },{"id": "cassette-sfx","name": "CassetteAI Sound Effects",@@ -9445,6 +9371,80 @@ export const CLOUD_MODELS: ModelDef[] = ["note": "prompt-to-song on mureka-9.5; with lyrics $0.225"}},+ {+ "id": "stable-audio-2-5",+ "name": "Stable Audio 2.5",+ "vendor": "Stability AI",+ "family": "stable-audio",+ "engine": "cloud",+ "kind": "audio",+ "tagline": "Sound design and music beds up to 3 minutes",+ "routes": [+ {+ "op": "sfx",+ "provider": "fal",+ "endpoint": "fal-ai/stable-audio-25/text-to-audio",+ "map": {+ "seed": "seed",+ "duration": {+ "key": "seconds_total",+ "type": "number"+ }+ }+ },+ {+ "op": "music",+ "provider": "fal",+ "endpoint": "fal-ai/stable-audio-25/text-to-audio",+ "map": {+ "seed": "seed",+ "duration": {+ "key": "seconds_total",+ "type": "number"+ }+ }+ },+ {+ "op": "sfx",+ "provider": "replicate",+ "endpoint": "stability-ai/stable-audio-2.5",+ "map": {+ "duration": {+ "key": "duration",+ "type": "number"+ }+ }+ },+ {+ "op": "music",+ "provider": "replicate",+ "endpoint": "stability-ai/stable-audio-2.5",+ "map": {+ "duration": {+ "key": "duration",+ "type": "number"+ }+ }+ }+ ],+ "options": {+ "seed": true,+ "durations": [+ 10,+ 30,+ 60,+ 120,+ 190+ ]+ },+ "defaults": {+ "duration": 30+ },+ "pricing": {+ "unit": "request",+ "usd": 0.2+ }+ },{"id": "elevenlabs-sfx","name": "ElevenLabs Sound Effects",diff --git a/src/lib/catalog/payload.ts b/src/lib/catalog/payload.tsindex a074a41b..b3e7a3ed 100644--- a/src/lib/catalog/payload.ts+++ b/src/lib/catalog/payload.ts@@ -494,5 +494,14 @@ export function extractOutputs(response: unknown, op?: Operation): ExtractedOutpconst text = textOf(response)?.trim();if (text) out = transcriptOutputs(response);}+ const r = body(response);+ if (isObj(r)) {+ // Recraft makes a style from reference images on the fly and returns its id: keep it to reuse the style.+ const styleId = str(r.style_id);+ if (styleId) out = out.map((o) => ({ ...o, meta: { ...o.meta, styleId } }));+ // Cut-out endpoints (Bria extract-object) return the matte next to the image.+ const mask = fileOf(r.mask)?.url;+ if (mask) out = out.map((o) => (o.url === mask ? { ...o, meta: { ...o.meta, role: "mask" } } : o));+ }return out;}diff --git a/tests/cloud-catalog.test.ts b/tests/cloud-catalog.test.tsnew file mode 100644index 00000000..3d2a3705--- /dev/null+++ b/tests/cloud-catalog.test.ts@@ -0,0 +1,261 @@+import fs from "node:fs";+import { describe, expect, it } from "vitest";+import { getModel, getPreset, MODELS, modelsFor } from "@/lib/catalog";+import { buildPayload } from "@/lib/catalog/payload";+import { planGeneration } from "@/lib/catalog/plan";+import { OPERATION_OUTPUT, type FieldMap, type ModelRoute, type Operation } from "@/lib/catalog/types";++type Endpoint = { provider: string; endpoint: string; inputs?: Record<string, unknown>; verified?: boolean };+const research = ["paid-model-apis.json", "paid-model-apis-2.json", "paid-model-apis-3.json"].flatMap(+ (f) => (JSON.parse(fs.readFileSync(`docs/research/${f}`, "utf8")) as { endpoints: Endpoint[] }).endpoints,+);+const byId = new Map<string, Endpoint>();+for (const e of research) byId.set(`${e.provider}:${e.endpoint}`, { ...byId.get(`${e.provider}:${e.endpoint}`), ...e });++/** Every provider field a FieldMap names (top-level part of dotted paths). */+function fieldsOf(map: FieldMap): string[] {+ const out: string[] = [];+ for (const [k, v] of Object.entries(map)) {+ if (k === "fixed" || k === "seedRange" || k === "maskFormat") continue;+ if (typeof v === "string") out.push(v);+ else if (v && typeof v === "object") {+ const o = v as Record<string, unknown>;+ for (const f of ["key", "background", "shotType", "flag"]) if (typeof o[f] === "string") out.push(o[f] as string);+ }+ }+ return [...out, ...Object.keys(map.fixed ?? {})].map((f) => f.split(".")[0].replace("[]", ""));+}++/** The models this round added (research part 3), with the operation each is for. */+const ROUND3: Record<string, Operation> = {+ "seedream-5-layers": "layers",+ "seedream-5-flash-layers": "layers",+ "qwen-image-layered-cloud": "layers",+ "ideogram-3-text-layers": "text-layers",+ "ideogram-remove-bg": "bg-remove",+ "bria-extract-object": "edit",+ "recraft-vectorize": "vectorize",+ image2svg: "vectorize",+ "recraft-4-1-pro": "t2i",+ "recraft-4-style": "t2i",+ "recraft-4-style-pro": "t2i",+ "ideogram-3": "t2i",+ "krea-2-style": "edit",+ "flux-redux-ultra": "edit",+ "flux-redux-pro": "edit",+ "instant-character": "edit",+ "qwen-multiple-angles": "edit",+ "fashn-tryon": "edit",+ "google-try-on": "edit",+ "leffa-tryon": "edit",+ "bria-product-shot": "edit",+ "product-photography": "edit",+ "bria-background-replace": "edit",+ "happy-horse-video-edit": "v2v",+ "lucy-edit-pro": "v2v",+ "runway-aleph-2": "v2v",+ "kling-o3-4k-edit": "v2v",+ "grok-imagine-video-edit": "v2v",+ "ltx-2-3-restyle": "v2v",+ "trim-video": "trim",+ "merge-audio-video": "mux",+ "auto-subtitle": "captions",+ "veed-subtitles": "captions",+ "scribe-v2": "transcribe",+ wizper: "transcribe",+ whisper: "transcribe",+ demucs: "separate-audio",+ "mirelo-sfx-2": "sfx",+ "sonilo-sfx": "sfx",+ "stable-audio-3-sfx": "sfx",+ "stable-audio-2-5": "sfx",+ "cassette-sfx": "sfx",+ "seed-audio": "sfx",+ "mirelo-sfx-2-video": "v2a",+ "sonilo-music": "music",+ "lyria-3": "music",+ "lyria-3-pro": "music",+ "minimax-music-2-5": "music",+ "stable-audio-3-music": "music",+ "mureka-song": "music",+ "hunyuan-3d-3-1-pro": "image-to-3d",+ "hunyuan-3d-3-1-rapid": "image-to-3d",+ "trellis-2": "image-to-3d",+ "tripo-h3-1": "image-to-3d",+ "meshy-7-1": "image-to-3d",+ "inworld-tts": "tts",+ "minimax-speech-2-8": "tts",+};++const route = (id: string, op?: Operation, provider = "fal"): ModelRoute => {+ const m = getModel(id);+ if (!m) throw new Error(`no model ${id}`);+ const r = m.routes.find((x) => (!op || x.op === op) && x.provider === provider);+ if (!r) throw new Error(`${id} has no ${provider} ${op} route`);+ return r;+};++describe("round-3 cloud models", () => {+ it("every new model resolves, is cloud, and runs its operation", () => {+ for (const [id, op] of Object.entries(ROUND3)) {+ const m = getModel(id);+ expect(m, id).toBeDefined();+ expect(m!.engine, id).toBe("cloud");+ expect(m!.routes.some((r) => r.op === op), `${id} ${op}`).toBe(true);+ // The model's kind is what its main operation outputs (pickers filter on it).+ expect(m!.kind, id).toBe(OPERATION_OUTPUT[op] === "text" ? "text" : op === "v2a" ? "video" : OPERATION_OUTPUT[op]);+ }+ });++ it("routes every fal / Replicate model only to researched, verified endpoints with fields the schema has", () => {+ const routes = MODELS.flatMap((m) => m.routes.filter((r) => r.provider === "fal" || r.provider === "replicate").map((r) => ({ m, r })));+ const bad: string[] = [];+ for (const { m, r } of routes) {+ if (r.endpoint.startsWith("chain:")) continue;+ const e = byId.get(`${r.provider}:${r.endpoint}`);+ if (!e) {+ bad.push(`${m.id}: ${r.provider}:${r.endpoint} not in research`);+ continue;+ }+ if (ROUND3[m.id] && !e.verified) bad.push(`${m.id}: ${r.endpoint} unverified`);+ const inputs = Object.keys(e.inputs ?? {});+ for (const f of fieldsOf(r.map ?? {})) if (!inputs.includes(f)) bad.push(`${m.id}: ${r.endpoint} has no field ${f}`);+ }+ expect(bad).toEqual([]);+ });++ it("hides utility-only steps and keeps sliders and controls inside the API's limits", () => {+ expect(getModel("trim-video")!.hidden).toBe(true);+ expect(getModel("merge-audio-video")!.hidden).toBe(true);+ for (const id of Object.keys(ROUND3).filter((x) => !["trim-video", "merge-audio-video"].includes(x))) expect(getModel(id)!.hidden, id).toBeFalsy();+ for (const m of MODELS) {+ for (const s of m.options.sliders ?? []) {+ expect(s.min, `${m.id} ${s.param}`).toBeLessThan(s.max);+ expect(s.default >= s.min && s.default <= s.max, `${m.id} ${s.param} default`).toBe(true);+ }+ for (const c of m.options.controls ?? []) expect(c.values.length, `${m.id} ${c.param}`).toBeGreaterThan(0);+ }+ });++ it("puts the new models in the right pickers, defaults first", () => {+ const ids = (kind: Parameters<typeof modelsFor>[0]["kind"], ops: Operation[]) => modelsFor({ kind, ops, engine: "cloud" }).map((m) => m.id);+ expect(ids("audio", ["sfx"]).slice(0, 2)).toEqual(["mirelo-sfx-2", "sonilo-sfx"]);+ expect(ids("audio", ["sfx"])).toContain("elevenlabs-sfx");+ expect(ids("audio", ["music"])[0]).toBe("sonilo-music");+ expect(ids("audio", ["music"])).toEqual(expect.arrayContaining(["elevenlabs-music", "lyria-3", "lyria-3-pro", "minimax-music-2-5", "stable-audio-3-music", "mureka-song", "stable-audio-2-5"]));+ expect(ids("audio", ["tts"])).toEqual(expect.arrayContaining(["inworld-tts", "minimax-speech-2-8", "seed-audio"]));+ expect(ids("video", ["v2a"])).toContain("mirelo-sfx-2-video");+ expect(ids("video", ["v2v"])).toEqual(expect.arrayContaining(["happy-horse-video-edit", "lucy-edit-pro", "runway-aleph-2", "kling-o3-4k-edit", "grok-imagine-video-edit", "ltx-2-3-restyle", "kling-o3", "wan-2-7"]));+ expect(ids("image", ["t2i", "edit"])).toEqual(expect.arrayContaining(["recraft-4-1-pro", "ideogram-3", "krea-2-style", "fashn-tryon", "qwen-multiple-angles"]));+ expect(ids("image", ["layers"])[0]).toBe("seedream-5-layers");+ expect(ids("image", ["vectorize"])[0]).toBe("recraft-vectorize");+ expect(ids("model3d", ["image-to-3d"])[0]).toBe("hunyuan-3d-3-1-pro");+ expect(ids("text", ["transcribe"])[0]).toBe("scribe-v2");+ expect(ids("video", ["captions"])[0]).toBe("auto-subtitle");+ expect(ids("audio", ["separate-audio"])).toEqual(["demucs"]);+ // Utility steps never show up in a picker.+ expect(modelsFor({ ops: ["trim", "mux"] }).filter((m) => m.engine === "cloud")).toEqual([]);+ });++ it("chips: defaults are marked top, Pro/4K/fast where the research says so", () => {+ for (const id of ["seedream-5-layers", "mirelo-sfx-2", "sonilo-music", "hunyuan-3d-3-1-pro", "fashn-tryon", "scribe-v2", "auto-subtitle", "recraft-vectorize"]) {+ expect(getModel(id)!.badges, id).toContain("top");+ }+ expect(getModel("kling-o3-4k-edit")!.badges).toContain("4k");+ expect(getModel("recraft-4-1-pro")!.badges).toContain("pro");+ expect(getModel("hunyuan-3d-3-1-rapid")!.badges).toContain("fast");+ });++ it("plans requests for the new operations", () => {+ const plan = (req: Parameters<typeof planGeneration>[0]) => planGeneration(req, getModel, getPreset);+ expect(plan({ feature: "x", modelId: "fashn-tryon", prompt: "try it on", inputs: { images: ["/p.png", "/g.png"] } }).op).toBe("edit");+ expect(plan({ feature: "x", modelId: "seedream-5-layers", op: "layers", prompt: "split", inputs: { images: ["/a.png"] } }).op).toBe("layers");+ expect(plan({ feature: "x", modelId: "ideogram-3", prompt: "poster", params: { palette: ["#ff0000"] } }).params.palette).toEqual(["#ff0000"]);+ expect(plan({ feature: "x", modelId: "trellis-2", op: "image-to-3d", prompt: "x", inputs: { images: ["/a.png"] } }).params.resolution).toBe("1024");+ });+});++describe("round-3 payloads", () => {+ it("sends a palette in each API's own shape", () => {+ const palette = ["#FF0000", "00ff80", "#123456"];+ expect(buildPayload(route("recraft-4-1").map!, { prompt: "p", palette, extra: { background_color: "#ffffff" } })).toMatchObject({+ colors: [{ r: 255, g: 0, b: 0 }, { r: 0, g: 255, b: 128 }, { r: 18, g: 52, b: 86 }],+ background_color: { r: 255, g: 255, b: 255 },+ });+ expect(buildPayload(route("recraft-4-1", "t2i", "higgsfield").map!, { prompt: "p", palette, extra: { background_color: "#000000" } })).toMatchObject({+ colors: [{ rgb: [255, 0, 0] }, { rgb: [0, 255, 128] }, { rgb: [18, 52, 86] }],+ background_color: { rgb: [0, 0, 0] },+ });+ expect(buildPayload(route("ideogram-3", "t2i").map!, { prompt: "p", palette }).color_palette).toEqual({+ members: [+ { rgb: { r: 255, g: 0, b: 0 }, color_weight: 1 },+ { rgb: { r: 0, g: 255, b: 128 }, color_weight: 0.65 },+ { rgb: { r: 18, g: 52, b: 86 }, color_weight: 0.3 },+ ],+ });+ expect(buildPayload({ palette: { key: "colors", format: "hex" } }, { palette: ["ff0000", "#00FF80", "nope"] }).colors).toEqual(["#FF0000", "#00FF80"]);+ // No palette, no field; an object background the caller already shaped is left alone.+ expect(buildPayload(route("recraft-4-1").map!, { prompt: "p", extra: { background_color: { r: 1, g: 2, b: 3 } } })).toEqual({+ prompt: "p",+ background_color: { r: 1, g: 2, b: 3 },+ });+ });++ it("maps trims, offsets and frame rates in seconds or milliseconds", () => {+ expect(buildPayload(route("trim-video").map!, { video: "v.mp4", startTime: 2.5, endTime: 9, duration: 5 })).toEqual({ video_url: "v.mp4", start_time: 2.5, end_time: 9 });+ expect(buildPayload(route("merge-audio-video").map!, { video: "v.mp4", audio: "a.mp3", startTime: 1 })).toEqual({ video_url: "v.mp4", audio_url: "a.mp3", start_offset: 1 });+ expect(buildPayload({ startTime: { key: "start_ms", type: "number", multiplier: 1000 }, endTime: { key: "end", type: "string", suffix: "s" }, fps: "fps" }, { startTime: 1.5, endTime: 4, fps: 24 })).toEqual({+ start_ms: 1500,+ end: "4s",+ fps: 24,+ });+ });++ it("sends the second image, style ids, layer counts and source languages", () => {+ expect(buildPayload(route("fashn-tryon").map!, { prompt: "ignored", images: ["person.png", "shirt.png"], extra: { category: "tops" } })).toEqual({+ model_image: "person.png",+ garment_image: "shirt.png",+ category: "tops",+ });+ expect(buildPayload(route("leffa-tryon").map!, { images: ["p.png"] })).toEqual({ human_image_url: "p.png", garment_type: "upper_body" });+ expect(buildPayload(route("bria-product-shot").map!, { prompt: "on a marble counter", images: ["bottle.png", "scene.png"] })).toEqual({+ scene_description: "on a marble counter",+ image_url: "bottle.png",+ ref_image_url: "scene.png",+ });+ expect(buildPayload(route("recraft-4-style", "t2i").map!, { prompt: "a fox", styleId: "st-123", aspectRatio: "16:9" })).toEqual({+ prompt: "a fox",+ style_id: "st-123",+ image_size: "landscape_16_9",+ });+ expect(buildPayload(route("qwen-image-layered-cloud").map!, { prompt: "a poster", images: ["a.png"], numLayers: 6 })).toEqual({ prompt: "a poster", image_url: "a.png", num_layers: 6 });+ expect(buildPayload(route("qwen-image-layered-cloud", "layers", "replicate").map!, { prompt: "a poster", images: ["a.png"], numLayers: 6 })).toEqual({+ description: "a poster",+ image: "a.png",+ num_layers: 6,+ });+ expect(buildPayload(route("scribe-v2").map!, { prompt: "x", video: "clip.mp4", sourceLanguage: "fr" })).toEqual({ audio_url: "clip.mp4", language_code: "fr" });+ expect(buildPayload(route("auto-subtitle").map!, { video: "v.mp4", sourceLanguage: "es", extra: { words_per_subtitle: 2 } })).toEqual({ video_url: "v.mp4", language: "es", words_per_subtitle: 2 });+ });++ it("uses each model's own field names for voices, angles, resolutions and fixed switches", () => {+ expect(buildPayload(route("minimax-speech-2-8").map!, { prompt: "Hi", voice: "Calm_Woman", extra: { "voice_setting.speed": 1.2 } })).toEqual({+ prompt: "Hi",+ voice_setting: { voice_id: "Calm_Woman", speed: 1.2 },+ output_format: "url",+ });+ expect(buildPayload(route("inworld-tts").map!, { prompt: "Hi", voice: "Loretta (en)" })).toEqual({ text: "Hi", voice: "Loretta (en)" });+ expect(buildPayload(route("qwen-multiple-angles").map!, { prompt: "", images: ["a.png"], extra: { horizontal_angle: 90, zoom: 2 } })).toEqual({+ additional_prompt: "",+ image_urls: ["a.png"],+ horizontal_angle: 90,+ zoom: 2,+ });+ expect(buildPayload(route("trellis-2").map!, { images: ["a.png"], resolution: "1536" })).toEqual({ image_url: "a.png", resolution: 1536 });+ expect(buildPayload(route("lucy-edit-pro").map!, { prompt: "make it snow", video: "v.mp4" })).toEqual({ prompt: "make it snow", video_url: "v.mp4", sync_mode: false });+ expect(buildPayload(route("demucs").map!, { audio: "song.mp3" })).toEqual({ audio_url: "song.mp3", model: "htdemucs" });+ // Ideogram's remix doesn't send the picture being remixed as its own style reference.+ expect(buildPayload(route("ideogram-3", "edit").map!, { prompt: "p", images: ["a.png"] })).toEqual({ prompt: "p", image_url: "a.png" });+ expect(route("ideogram-3", "inpaint").map).toMatchObject({ mask: "mask_url", maskFormat: "black" });+ });+});diff --git a/tests/outputs.test.ts b/tests/outputs.test.tsnew file mode 100644index 00000000..e9fe0871--- /dev/null+++ b/tests/outputs.test.ts@@ -0,0 +1,218 @@+import { describe, expect, it } from "vitest";+import { extractOutputs, textDataUri, wordsToCues } from "@/lib/catalog/payload";++// Response fixtures follow docs/research/paid-model-apis-3.json → outputFields / outputShape of each endpoint.+const file = (url: string, content_type?: string) => ({ url, file_name: url.split("/").pop(), file_size: 1234, ...(content_type ? { content_type } : {}) });+const decode = (uri: string) => Buffer.from(uri.slice(uri.indexOf(",") + 1), "base64").toString("utf8");++describe("layers", () => {+ it("Seedream layerize: base + named layers with z order and [x, y, w, h] boxes", () => {+ const base = { ...file("https://v3.fal.media/files/base.png", "image/png"), width: 1024, height: 768 };+ const mug = { ...file("https://v3.fal.media/files/mug.png", "image/png"), width: 300, height: 400 };+ const res = {+ layers: [+ { image: base, z_index: 0 },+ {+ image: mug,+ z_index: 1,+ name: "Red mug",+ description: "A red ceramic mug with steam",+ bounding_box: { absolute: [100, 200, 400, 600], normalized: [98, 260, 391, 781] },+ },+ ],+ images: [base, mug],+ };+ expect(extractOutputs(res, "layers")).toEqual([+ { url: base.url, kind: "image", contentType: "image/png", meta: { name: "Background", z: 0 } },+ {+ url: mug.url,+ kind: "image",+ contentType: "image/png",+ meta: { name: "Red mug", z: 1, bbox: [100, 200, 300, 400], bboxNormalized: [98, 260, 293, 521], description: "A red ceramic mug with steam" },+ },+ ]);+ });++ it("Qwen layered (fal images[] and Replicate output[]): stacking order is array order", () => {+ const fal = {+ images: [file("https://v3.fal.media/files/l0.png", "image/png"), file("https://v3.fal.media/files/l1.png", "image/png"), file("https://v3.fal.media/files/l2.png", "image/png")],+ seed: 42,+ prompt: "a poster",+ has_nsfw_concepts: [false, false, false],+ timings: { inference: 3.2 },+ };+ expect(extractOutputs(fal, "layers").map((o) => o.meta)).toEqual([+ { name: "Background", z: 0 },+ { name: "Layer 1", z: 1 },+ { name: "Layer 2", z: 2 },+ ]);+ const rep = { output: ["https://replicate.delivery/x/out-0.webp", "https://replicate.delivery/x/out-1.webp"] };+ expect(extractOutputs(rep, "layers")).toEqual([+ { url: rep.output[0], kind: "image", meta: { name: "Background", z: 0 } },+ { url: rep.output[1], kind: "image", meta: { name: "Layer 1", z: 1 } },+ ]);+ });++ it("Ideogram layerize-text: the clean background carries the text blocks and overlay HTML", () => {+ const containers = [{ id: "c1", items: [{ spans: [{ text: "BIG" }, { text: "SUMMER" }] }, { spans: [{ text: "SALE" }] }], left: 40, top: 60 }];+ const res = {+ image: file("https://v3.fal.media/files/clean.png", "image/png"),+ text_containers: containers,+ text_html: "<div class='c1'>BIG SUMMER SALE</div>",+ image_layers: [{ url: "https://v3.fal.media/files/logo.png", name: "Logo" }],+ seed: 7,+ prompt: "poster",+ };+ const out = extractOutputs(res, "text-layers");+ expect(out[0]).toEqual({+ url: "https://v3.fal.media/files/clean.png",+ kind: "image",+ contentType: "image/png",+ meta: { name: "Background", z: 0, textBlocks: [{ ...containers[0], text: "BIG SUMMER SALE" }], textHtml: res.text_html },+ });+ expect(out[1]).toEqual({ url: "https://v3.fal.media/files/logo.png", kind: "image", meta: { name: "Logo", z: 1 } });+ });+});++describe("transcripts", () => {+ it("Scribe v2: text output with a data URI the runner can store, and caption cues per speaker/sentence", () => {+ const res = {+ text: "Hello there. How are you?",+ language_code: "en",+ language_probability: 0.98,+ words: [+ { text: "Hello", start: 0, end: 0.4, type: "word", speaker_id: "speaker_0" },+ { text: " ", start: 0.4, end: 0.45, type: "spacing", speaker_id: "speaker_0" },+ { text: "there.", start: 0.45, end: 0.9, type: "word", speaker_id: "speaker_0" },+ { text: " ", start: 0.9, end: 1.5, type: "spacing", speaker_id: "speaker_1" },+ { text: "How", start: 1.5, end: 1.7, type: "word", speaker_id: "speaker_1" },+ { text: " ", start: 1.7, end: 1.75, type: "spacing", speaker_id: "speaker_1" },+ { text: "are", start: 1.75, end: 1.9, type: "word", speaker_id: "speaker_1" },+ { text: " ", start: 1.9, end: 1.95, type: "spacing", speaker_id: "speaker_1" },+ { text: "you?", start: 1.95, end: 2.3, type: "word", speaker_id: "speaker_1" },+ ],+ };+ const [o, ...rest] = extractOutputs(res, "transcribe");+ expect(rest).toEqual([]);+ expect(o).toMatchObject({ kind: "text", contentType: "text/plain", text: "Hello there. How are you?" });+ expect(o.url).toMatch(/^data:text\/plain;base64,/);+ expect(decode(o.url)).toBe(res.text);+ expect(o.meta).toEqual({+ language: "en",+ cues: [+ { start: 0, end: 0.9, text: "Hello there.", speaker: "speaker_0" },+ { start: 1.5, end: 2.3, text: "How are you?", speaker: "speaker_1" },+ ],+ });+ });++ it("Whisper / Wizper segment chunks are cues as they are; Replicate Scribe answers with an object", () => {+ const wizper = { text: " Hello there. How are you?", languages: ["en"], chunks: [{ timestamp: [0, 2.5], text: " Hello there." }, { timestamp: [2.5, 4.1], text: " How are you?" }] };+ expect(extractOutputs(wizper, "transcribe")[0].meta).toEqual({+ language: "en",+ cues: [+ { start: 0, end: 2.5, text: "Hello there." },+ { start: 2.5, end: 4.1, text: "How are you?" },+ ],+ });+ const rep = { output: { text: "Bonjour.", language_code: "fr", language_probability: 0.9, words: [{ text: "Bonjour.", start: 0.1, end: 0.6, type: "word" }] } };+ expect(extractOutputs(rep, "transcribe")).toEqual([+ { url: textDataUri("Bonjour."), kind: "text", contentType: "text/plain", text: "Bonjour.", meta: { language: "fr", cues: [{ start: 0.1, end: 0.6, text: "Bonjour." }] } },+ ]);+ });++ it("keeps UTF-8 intact in the data URI and wraps long lines into caption-sized cues", () => {+ expect(decode(textDataUri("Café — ✓ 日本語"))).toBe("Café — ✓ 日本語");+ const words = "one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen".split(" ").map((t, i) => ({ text: t, start: i * 0.3, end: i * 0.3 + 0.25 }));+ const cues = wordsToCues(words);+ expect(cues.length).toBeGreaterThan(1);+ expect(cues.every((c) => c.text.length <= 64)).toBe(true);+ expect(cues.map((c) => c.text).join(" ")).toBe(words.map((w) => w.text).join(" "));+ });++ it("Auto Subtitle: the captioned video keeps what was transcribed", () => {+ const res = {+ video: file("https://v3.fal.media/files/captioned.mp4", "video/mp4"),+ transcription: "Hello there",+ words: [+ { word: "Hello", start: 0, end: 0.5 },+ { word: "there", start: 0.5, end: 1 },+ ],+ subtitle_count: 1,+ transcription_metadata: { language: "en" },+ };+ expect(extractOutputs(res, "captions")).toEqual([+ {+ url: "https://v3.fal.media/files/captioned.mp4",+ kind: "video",+ contentType: "video/mp4",+ meta: { transcript: "Hello there", cues: [{ start: 0, end: 1, text: "Hello there" }] },+ },+ ]);+ });++ it("text-only answers become one text output instead of nothing", () => {+ expect(extractOutputs({ text: "A red mug on a table." })).toMatchObject([{ kind: "text", text: "A red mug on a table." }]);+ expect(extractOutputs({ output: ["A ", "red ", "mug"] })).toMatchObject([{ kind: "text", text: "A red mug" }]);+ expect(extractOutputs({ seed: 1, timings: {} })).toEqual([]);+ });+});++describe("3D models, stems and other extras", () => {+ it("Hunyuan3D: the GLB as a model3d output, with the other formats and the preview in meta", () => {+ const res = {+ model_glb: file("https://v3.fal.media/files/model.glb", "application/octet-stream"),+ thumbnail: file("https://v3.fal.media/files/thumb.png", "image/png"),+ model_urls: { glb: file("https://v3.fal.media/files/model.glb"), obj: file("https://v3.fal.media/files/model.obj"), fbx: null, usdz: null },+ seed: 3,+ };+ expect(extractOutputs(res, "image-to-3d")).toEqual([+ {+ url: "https://v3.fal.media/files/model.glb",+ kind: "model3d",+ contentType: "model/gltf-binary",+ meta: { preview: "https://v3.fal.media/files/thumb.png", formats: { glb: "https://v3.fal.media/files/model.glb", obj: "https://v3.fal.media/files/model.obj" } },+ },+ ]);+ const tripo = { model_mesh: file("https://v3.fal.media/files/mesh.glb", "model/gltf-binary"), rendered_image: file("https://v3.fal.media/files/render.webp"), task_id: "t1" };+ expect(extractOutputs(tripo, "image-to-3d")).toEqual([+ { url: "https://v3.fal.media/files/mesh.glb", kind: "model3d", contentType: "model/gltf-binary", meta: { preview: "https://v3.fal.media/files/render.webp" } },+ ]);+ expect(extractOutputs({ output: "https://replicate.delivery/x/model.glb" }, "image-to-3d")).toEqual([+ { url: "https://replicate.delivery/x/model.glb", kind: "model3d", contentType: "model/gltf-binary" },+ ]);+ });++ it("Demucs: one audio output per stem, voice first", () => {+ const res = {+ drums: file("https://v3.fal.media/files/drums.mp3", "audio/mpeg"),+ vocals: file("https://v3.fal.media/files/vocals.mp3", "audio/mpeg"),+ other: file("https://v3.fal.media/files/other.mp3", "audio/mpeg"),+ bass: file("https://v3.fal.media/files/bass.mp3", "audio/mpeg"),+ guitar: null,+ piano: null,+ };+ expect(extractOutputs(res, "separate-audio").map((o) => [o.kind, o.meta?.stem])).toEqual([+ ["audio", "vocals"],+ ["audio", "drums"],+ ["audio", "bass"],+ ["audio", "other"],+ ]);+ });++ it("keeps Recraft's new style id and labels Bria's matte", () => {+ expect(extractOutputs({ images: [file("https://v3.fal.media/files/a.png", "image/png")], style_id: "style-9" }, "t2i")[0].meta).toEqual({ styleId: "style-9" });+ const cut = extractOutputs({ image: file("https://v3.fal.media/files/cut.png", "image/png"), mask: file("https://v3.fal.media/files/mask.png", "image/png") }, "edit");+ expect(cut.map((o) => o.meta)).toEqual([undefined, { role: "mask" }]);+ });++ it("plain media responses come back unchanged", () => {+ expect(extractOutputs({ audio: [file("https://v3.fal.media/files/a.wav", "audio/wav"), file("https://v3.fal.media/files/b.wav", "audio/wav")], seeds: [1, 2] }, "sfx")).toEqual([+ { url: "https://v3.fal.media/files/a.wav", kind: "audio", contentType: "audio/wav" },+ { url: "https://v3.fal.media/files/b.wav", kind: "audio", contentType: "audio/wav" },+ ]);+ expect(extractOutputs({ image: file("https://v3.fal.media/files/logo.svg", "image/svg+xml") }, "vectorize")).toEqual([+ { url: "https://v3.fal.media/files/logo.svg", kind: "image", contentType: "image/svg+xml" },+ ]);+ });+});diff --git a/tests/providers.test.ts b/tests/providers.test.tsindex c32ca477..f32ca1b7 100644--- a/tests/providers.test.ts+++ b/tests/providers.test.ts@@ -75,6 +75,13 @@ describe("Higgsfield poll (S1)", () => {});});+ it("keeps a layer's structure through the Higgsfield route too", async () => {+ const statusUrl = "https://api.higgsfield.ai/requests/req-4/status";+ const body = { status: "completed", request_id: "req-4", status_url: statusUrl, cancel_url: "x", images: [{ url: "https://cdn.higgsfield.ai/a.png" }, { url: "https://cdn.higgsfield.ai/b.png" }] };+ const { result } = await withFetch({ [statusUrl]: body }, () => higgsfieldProvider.poll(ctx({ provider: "higgsfield", op: "layers" }, { statusUrl })));+ expect(result).toMatchObject({ state: "succeeded", outputs: [{ meta: { name: "Background", z: 0 } }, { meta: { name: "Layer 1", z: 1 } }] });+ });+it("fails cleanly when a completed status has no media", async () => {const statusUrl = "https://api.higgsfield.ai/requests/req-3/status";const body = { status: "completed", request_id: "req-3", status_url: statusUrl, cancel_url: "https://api.higgsfield.ai/requests/req-3/cancel" };@@ -82,3 +89,50 @@ describe("Higgsfield poll (S1)", () => {expect(result.state).toBe("failed");});});++describe("fal poll: structured results", () => {+ const meta = { statusUrl: "https://queue.fal.run/fal-ai/x/requests/r1/status", responseUrl: "https://queue.fal.run/fal-ai/x/requests/r1" };++ it("returns a transcript as a text output instead of failing with 'No media in response'", async () => {+ const result = { text: "Hello world.", language_code: "en", words: [{ text: "Hello", start: 0, end: 0.4, type: "word" }, { text: "world.", start: 0.5, end: 0.9, type: "word" }] };+ const { result: r } = await withFetch({ [meta.statusUrl]: { status: "COMPLETED" }, [meta.responseUrl]: result }, () =>+ falProvider.poll(ctx({ op: "transcribe", endpoint: "fal-ai/elevenlabs/speech-to-text/scribe-v2" }, meta)),+ );+ expect(r).toMatchObject({+ state: "succeeded",+ outputs: [{ kind: "text", contentType: "text/plain", text: "Hello world.", meta: { language: "en", cues: [{ start: 0, end: 0.9, text: "Hello world." }] } }],+ });+ if (r.state === "succeeded") expect(r.outputs[0].url).toMatch(/^data:text\/plain;base64,/);+ });++ it("keeps Seedream layer names, z order and boxes", async () => {+ const result = {+ layers: [+ { image: { url: "https://v3.fal.media/files/base.png", content_type: "image/png" }, z_index: 0 },+ { image: { url: "https://v3.fal.media/files/cat.png", content_type: "image/png" }, z_index: 1, name: "Cat", bounding_box: { absolute: [10, 20, 110, 220] } },+ ],+ images: [{ url: "https://v3.fal.media/files/base.png" }, { url: "https://v3.fal.media/files/cat.png" }],+ };+ const { result: r } = await withFetch({ [meta.statusUrl]: { status: "COMPLETED" }, [meta.responseUrl]: result }, () =>+ falProvider.poll(ctx({ op: "layers", endpoint: "bytedance/seedream/v5/pro/layerize" }, meta)),+ );+ expect(r).toMatchObject({ state: "succeeded", outputs: [{ meta: { name: "Background", z: 0 } }, { meta: { name: "Cat", z: 1, bbox: [10, 20, 100, 200] } }] });+ });++ it("still fails when the response holds neither media nor text", async () => {+ const { result: r } = await withFetch({ [meta.statusUrl]: { status: "COMPLETED" }, [meta.responseUrl]: { seed: 1 } }, () => falProvider.poll(ctx({ op: "t2i" }, meta)));+ expect(r).toMatchObject({ state: "failed", error: expect.stringMatching(/No media in response/) });+ });+});++describe("Replicate poll: structured results", () => {+ it("reads an object output (Scribe) as the result and URL lists in order (Qwen layers)", async () => {+ const url = "https://api.replicate.com/v1/predictions/req-1";+ const scribe = { status: "succeeded", output: { text: "Hi.", language_code: "en", language_probability: 1, words: [{ text: "Hi.", start: 0, end: 0.3, type: "word" }] } };+ const { result: a } = await withFetch({ [url]: scribe }, () => replicateProvider.poll(ctx({ op: "transcribe", provider: "replicate", endpoint: "elevenlabs/scribe-v2" })));+ expect(a).toMatchObject({ state: "succeeded", outputs: [{ kind: "text", text: "Hi." }] });+ const layered = { status: "succeeded", output: ["https://replicate.delivery/a/0.webp", "https://replicate.delivery/a/1.webp"] };+ const { result: b } = await withFetch({ [url]: layered }, () => replicateProvider.poll(ctx({ op: "layers", provider: "replicate", endpoint: "qwen/qwen-image-layered" })));+ expect(b).toMatchObject({ state: "succeeded", outputs: [{ meta: { z: 0 } }, { meta: { z: 1 } }] });+ });+});