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
Assist faceless_episode runs on the open engine: voice_sample to clone, demo voice, atomic plans
Claude203d7a5c2f7b
diff --git a/src/components/assist/transcript.tsx b/src/components/assist/transcript.tsxindex 5ec721cf..d4b24bb7 100644--- a/src/components/assist/transcript.tsx+++ b/src/components/assist/transcript.tsx@@ -7,7 +7,7 @@ import { toast } from "sonner";import { Button } from "@/components/ui/button";import { FailedTile, MediaThumb, PendingTile, tileRatio } from "@/components/studio/feed";import { useCreateGeneration } from "@/lib/api";-import type { AssistItem, AssistThread, PlannedJob, SkillSummary } from "@/lib/assist";+import { planRunnable, type AssistItem, type AssistThread, type PlannedJob, type SkillSummary } from "@/lib/assist";import { OPERATION_LABELS, type Generation, type MediaKind, type Operation } from "@/lib/catalog/types";import { formatCost } from "@/lib/format";import { cn } from "@/lib/utils";@@ -58,12 +58,14 @@ function jobLine(j: PlannedJob): string {export function ApprovalCard({ item, live, onAnswer }: { item: Extract<AssistItem, { role: "approval" }>; live: boolean; onAnswer: (ok: boolean) => Promise<void> }) {const [busy, setBusy] = useState<boolean | null>(null);- const runnable = item.jobs.some((j) => !j.error);+ const runnable = planRunnable(item.jobs);const memoryOnly = item.jobs.length > 0 && item.jobs.every((j) => j.op === "memory");const allDemo = item.jobs.every((j) => j.demo || j.error || j.op === "memory");const total = memoryOnly? "Saved to memory for future chats"- : allDemo+ : !runnable && item.status === "pending"+ ? "Can't run yet — fix what's marked above, or tell Assist what to change"+ : allDemo? "Demo run — no provider connected": item.totalUsd === null? "Some prices vary"diff --git a/src/lib/assist.ts b/src/lib/assist.tsindex f5e10109..ab93dc19 100644--- a/src/lib/assist.ts+++ b/src/lib/assist.ts@@ -27,8 +27,13 @@ export interface PlannedJob {error?: string;/** A short extra line on the card (a studio's step, what a step waits for). */note?: string;+ /** One step of a pipeline: it only starts when every step can, so one error blocks the run. */+ atomic?: boolean;}+/** Whether an approval card's plan can run: something to run, and no pipeline with a broken step. */+export const planRunnable = (jobs: PlannedJob[]): boolean => jobs.some((j) => !j.error) && !jobs.some((j) => j.atomic && j.error);+export type AssistItem =| { id: string; role: "user"; text: string; attachments?: string[]; skills?: string[] }| { id: string; role: "assistant"; text: string }diff --git a/src/server/assist/studio-tools.ts b/src/server/assist/studio-tools.tsindex 7fe6a3db..86179b75 100644--- a/src/server/assist/studio-tools.ts+++ b/src/server/assist/studio-tools.ts@@ -3,10 +3,13 @@ import { nanoid } from "nanoid";import { z } from "zod";import type { PlannedJob } from "@/lib/assist";import { getModel } from "@/lib/catalog";-import type { ChainSlot, Engine, GenerationRequest } from "@/lib/catalog/types";+import { routesFor } from "@/lib/catalog/plan";+import type { ChainSlot, Engine, GenerationRequest, Operation } from "@/lib/catalog/types";import { createPipeline, type PipelineStep } from "../chains";-import { createGenerations, outputKind, previewChained } from "../generations";+import { db } from "../db";+import { chooseRoute, createGenerations, outputKind, previewChained } from "../generations";import { engineMode } from "../settings";+import { fileUrl, saveFile } from "../storage";import { defineTool, type ToolContext, type ToolOutcome } from "./define";/**@@ -68,7 +71,10 @@ const FacelessInput = z.object({.describe("2–8 scenes in order."),style: z.string().describe("The visual style for every scene, e.g. 'flat 2D illustration, muted palette'."),aspect_ratio: z.string().optional().describe("9:16 (default), 16:9 or 1:1."),- voice: z.string().optional().describe("A voice id for the narrator (search_models kind audio lists them)."),+ voice: z.string().optional().describe("A premade narrator voice id for the cloud engine (search_models kind audio lists them)."),+ voice_sample: ref+ .optional()+ .describe("A short recording of the narrator (10–60 s of clear speech): an attachment, a saved voice or an earlier audio output. The narration clones it. Required on the open-source engine; on the cloud engine it replaces the premade voice."),});const AdsInput = z.object({brief: z.string().describe("What the ads sell and to whom, with the offer or angle."),@@ -111,20 +117,29 @@ const pick = (ctx: ToolContext, cloud: string, open: string, override?: string)const asList = <T,>(a: T | T[] | undefined): T[] => (a === undefined ? [] : Array.isArray(a) ? a : [a]);const req = (r: Omit<GenerationRequest, "feature">): GenerationRequest => ({ feature: "assist", ...r });-/** Price each step of a pipeline the way createPipeline validates it, without creating anything. */-export function planSteps(tool: string, steps: PipelineStep[]): PlannedJob[] {+/**+ * Price each step of a pipeline the way createPipeline validates it, without creating anything.+ * Every job is marked `atomic`: a pipeline only starts when all of its steps can. `problems` names+ * a step (by key) that can't run as planned, in clearer words than the model's own check. With+ * `independent` the steps start on their own (a batch, not a pipeline): one bad step doesn't stop the rest.+ */+export function planSteps(tool: string, steps: PipelineStep[], problems: Record<string, string | undefined> = {}, independent = false): PlannedJob[] {+ const atomic = independent ? undefined : true;const jobs = steps.map((s, i): PlannedJob => {const chain = s.chain ?? s.request.chain;const r: GenerationRequest = { ...s.request, ...(chain && { chain }) };const label = s.request.step?.label ?? `Step ${i + 1} of ${steps.length}`;try {+ const problem = problems[s.key];+ if (problem) throw new Error(problem);const p = previewChained(r, asList(s.after).length);- return { tool, modelId: p.model.id, modelName: p.model.name, kind: outputKind(p.op, p.model), op: p.op, prompt: s.request.prompt?.trim() || label, count: p.outputs, costUsd: p.costUsd, demo: p.demo, note: label };+ return { tool, modelId: p.model.id, modelName: p.model.name, kind: outputKind(p.op, p.model), op: p.op, prompt: s.request.prompt?.trim() || label, count: p.outputs, costUsd: p.costUsd, demo: p.demo, note: label, atomic };} catch (e) {const m = getModel(s.request.modelId);- return { tool, modelId: s.request.modelId, modelName: m?.name ?? s.request.modelId, kind: m?.kind ?? "video", op: s.request.op ?? "t2i", prompt: s.request.prompt?.trim() || label, count: 0, costUsd: 0, demo: false, note: label, error: (e as Error).message };+ return { tool, modelId: s.request.modelId, modelName: m?.name ?? s.request.modelId, kind: m?.kind ?? "video", op: s.request.op ?? "t2i", prompt: s.request.prompt?.trim() || label, count: 0, costUsd: 0, demo: false, note: label, atomic, error: (e as Error).message };}});+ if (independent) return jobs;// createPipeline refuses a mix of demo and real steps: say so on the card already.if (jobs.some((j) => j.demo && !j.error) && jobs.some((j) => !j.demo && !j.error)) {const d = jobs.find((j) => j.demo && !j.error)!;@@ -194,7 +209,66 @@ function dubSteps(i: DubToolInput, ctx: ToolContext): PipelineStep[] {return labelled(steps);}-function facelessSteps(i: FacelessToolInput, ctx: ToolContext): PipelineStep[] {+// The narrator's voice. Open-source narration (Chatterbox) clones a voice from a sample, so the+// open engine needs one; the cloud engine has premade voices, and clones a sample when given one.++const NEEDS_SAMPLE =+ "Add a voice sample for the narrator: open-source narration clones a voice. Attach or record 10–60 s of clear speech (or use a saved voice), then pass it as voice_sample.";++/** Whether a model's operation would run as a demo right now (no provider connected). */+function runsAsDemo(modelId: string, op: Operation): boolean {+ const m = getModel(modelId);+ if (!m) return false;+ try {+ return chooseRoute(routesFor(m, op)).demo;+ } catch {+ return false;+ }+}++/** Stands in for the demo voice while planning, so a plan never writes a file. */+const DEMO_VOICE_PLAN = "/api/files/uploads/fuobe-demo-voice.wav";++/**+ * A voice to clone when the open narrator has no sample and the narration only runs as a demo+ * anyway (no ComfyUI): a short tone saved once, so demo mode stays clickable end to end. It has the+ * same asset name as Faceless Studio's, so the two share one file.+ */+function demoVoice(): string {+ const found = db().prepare("SELECT rel_path FROM assets WHERE name = 'fuobe-demo-voice.wav' LIMIT 1").get() as { rel_path: string } | undefined;+ if (found) return fileUrl(found.rel_path);+ const rate = 16000;+ const n = rate * 2;+ const buf = Buffer.alloc(44 + n * 2);+ buf.write("RIFF", 0);+ buf.writeUInt32LE(36 + n * 2, 4);+ buf.write("WAVEfmt ", 8);+ buf.writeUInt32LE(16, 16);+ buf.writeUInt16LE(1, 20);+ buf.writeUInt16LE(1, 22);+ buf.writeUInt32LE(rate, 24);+ buf.writeUInt32LE(rate * 2, 28);+ buf.writeUInt16LE(2, 32);+ buf.writeUInt16LE(16, 34);+ buf.write("data", 36);+ buf.writeUInt32LE(n * 2, 40);+ for (let k = 0; k < n; k++) buf.writeInt16LE(Math.round(Math.sin((2 * Math.PI * 220 * k) / rate) * 0.2 * 32767 * Math.min(1, k / 800, (n - k) / 800)), 44 + k * 2);+ return saveFile({ data: buf, contentType: "audio/wav", name: "fuobe-demo-voice.wav", source: "upload" }).url;+}++/** Planning uses a placeholder for the demo voice; starting the job saves the real file. */+type VoiceFor = "plan" | "run";++/** The narration model and the sample it clones (none: a premade voice); `missing` when the open engine has nothing to clone. */+export function narratorVoice(i: Pick<FacelessToolInput, "voice_sample">, ctx: ToolContext, voiceFor: VoiceFor = "plan"): { modelId: string; voiceAudio?: string; missing?: string } {+ const sample = i.voice_sample?.trim();+ if (engineOf(ctx) === "cloud") return sample ? { modelId: "chatterbox-cloud", voiceAudio: sample } : { modelId: "elevenlabs-v4" };+ if (sample) return { modelId: "oss-chatterbox", voiceAudio: sample };+ if (runsAsDemo("oss-chatterbox", "tts")) return { modelId: "oss-chatterbox", voiceAudio: voiceFor === "run" ? demoVoice() : DEMO_VOICE_PLAN };+ return { modelId: "oss-chatterbox", missing: NEEDS_SAMPLE };+}++function facelessSteps(i: FacelessToolInput, ctx: ToolContext, voiceFor: VoiceFor = "plan"): PipelineStep[] {const scenes = i.scenes.filter((s) => s.visual.trim() || s.narration.trim()).slice(0, 8);if (scenes.length < 2) throw new Error("Give at least 2 scenes");const open = engineOf(ctx) === "open";@@ -232,8 +306,14 @@ function facelessSteps(i: FacelessToolInput, ctx: ToolContext): PipelineStep[] {steps.push({ key: "film", label: "Joined scenes", request: req({ modelId: join, op: "concat", prompt: i.title?.trim() || "Episode" }), after: groups, chain: groups.map(() => ({ slot: "videos" as const })) });film = "film";}+ const narrator = narratorVoice(i, ctx, voiceFor);+ const narration = scenes.map((s) => s.narration.trim()).filter(Boolean).join("\n\n");steps.push(- { key: "voice", label: "Narration", request: req({ modelId: open ? "oss-chatterbox" : "elevenlabs-v4", op: "tts", prompt: scenes.map((s) => s.narration.trim()).filter(Boolean).join("\n\n"), params: { voice: i.voice } }) },+ {+ key: "voice",+ label: "Narration",+ request: req({ modelId: narrator.modelId, op: "tts", prompt: narration, ...(narrator.voiceAudio ? { inputs: { voiceAudio: narrator.voiceAudio } } : { params: { voice: i.voice } }) }),+ },{ key: "episode", label: "Episode", request: req({ modelId: open ? "oss-mux" : "merge-audio-video", op: "mux", prompt: i.title?.trim() || "Episode" }), after: [film, "voice"], chain: [{ slot: "video" }, { slot: "audio" }] },);return labelled(steps);@@ -359,7 +439,7 @@ const dubVideo = defineTool({try {return planSteps("dub_video", dubSteps(i, ctx));} catch (e) {- return [{ tool: "dub_video", modelId: "dub", modelName: "Translate & dub", kind: "video", op: "dub", prompt: i.languages.join(", "), count: 0, costUsd: 0, demo: false, error: (e as Error).message }];+ return [{ tool: "dub_video", modelId: "dub", modelName: "Translate & dub", kind: "video", op: "dub", prompt: i.languages.join(", "), count: 0, costUsd: 0, demo: false, atomic: true, error: (e as Error).message }];}},async run(i, ctx) {@@ -370,20 +450,24 @@ const dubVideo = defineTool({const facelessEpisode = defineTool({name: "faceless_episode",description:- "Make a narrated faceless video from scenes you wrote: a still and an animated clip per scene in one style, the narration, joined into one episode — Fuobe's Faceless studio. Write the narration and visuals first (load the faceless-video skill), then call this once. Gated by the same approval card as generate.",+ "Make a narrated faceless video from scenes you wrote: a still and an animated clip per scene in one style, the narration, joined into one episode — Fuobe's Faceless studio. Write the narration and visuals first (load the faceless-video skill), then call this once. On the open-source engine the narration clones voice_sample, so ask the user for a recording (or a saved voice) when there is none. Gated by the same approval card as generate.",schema: FacelessInput,gated: true,title: (i) => i.title?.trim() || "Faceless episode",plan: (i, ctx) => {if (STUDIO_ROUTES.faceless_episode?.plan) return STUDIO_ROUTES.faceless_episode.plan(i, ctx);try {- return planSteps("faceless_episode", facelessSteps(i, ctx));+ return planSteps("faceless_episode", facelessSteps(i, ctx), { voice: narratorVoice(i, ctx).missing });} catch (e) {- return [{ tool: "faceless_episode", modelId: "faceless", modelName: "Faceless episode", kind: "video", op: "concat", prompt: i.title ?? "Episode", count: 0, costUsd: 0, demo: false, error: (e as Error).message }];+ return [{ tool: "faceless_episode", modelId: "faceless", modelName: "Faceless episode", kind: "video", op: "concat", prompt: i.title ?? "Episode", count: 0, costUsd: 0, demo: false, atomic: true, error: (e as Error).message }];}},async run(i, ctx) {- return (await viaStudio(STUDIO_ROUTES.faceless_episode, i, ctx, "Started a faceless episode")) ?? startPipeline("Faceless episode", facelessSteps(i, ctx), i.title?.trim() || "Faceless episode");+ const studio = await viaStudio(STUDIO_ROUTES.faceless_episode, i, ctx, "Started a faceless episode");+ if (studio) return studio;+ const missing = narratorVoice(i, ctx).missing;+ if (missing) return { content: JSON.stringify({ error: missing }), isError: true };+ return startPipeline("Faceless episode", facelessSteps(i, ctx, "run"), i.title?.trim() || "Faceless episode");},});@@ -399,6 +483,8 @@ const createAds = defineTool({return planSteps("create_ads",adRequests(i, ctx).map((r, k) => ({ key: `ad${k}`, request: { ...r, step: { label: `Ad ${k + 1} · ${r.params?.aspectRatio}`, index: k, of: 0 } } })),+ {},+ true,);},async run(i, ctx) {diff --git a/src/server/assist/tools.ts b/src/server/assist/tools.tsindex ba9f4674..7a3064bc 100644--- a/src/server/assist/tools.ts+++ b/src/server/assist/tools.ts@@ -377,7 +377,12 @@ const generate = defineTool({// Not strict: the API allows 24 optional parameters across all strict tools in a request, and a// job has more. Calls are validated with zod (validateInput / planFor / executeTool) instead, and// a malformed one goes back to the model as an error it can fix.- plan: ({ jobs }) => chainJobs(jobs.slice(0, 6)).map(plannedJob),+ // Chained jobs are one pipeline (all or nothing); separate jobs start one by one.+ plan: ({ jobs }) => {+ const list = jobs.slice(0, 6);+ const atomic = list.some((j) => j.after !== undefined) || undefined;+ return chainJobs(list).map((c) => ({ ...plannedJob(c), atomic }));+ },async run({ summary, jobs }) {const list = jobs.slice(0, 6);// The plan's jobs share a batch, so the Library stacks them under the plan's summary.diff --git a/tests/assist-context.test.ts b/tests/assist-context.test.tsindex e43319a1..1c194eda 100644--- a/tests/assist-context.test.ts+++ b/tests/assist-context.test.ts@@ -18,6 +18,7 @@ const memory = await import("@/server/assist/memory");const projects = await import("@/server/assist/projects");const { handleMcp } = await import("@/server/mcp");const { db } = await import("@/server/db");+const { planRunnable } = await import("@/lib/assist");type Msg = Anthropic.Beta.BetaMessage;type Block = Anthropic.Beta.BetaContentBlock;@@ -274,6 +275,86 @@ describe("studio tools", () => {expect(ads[0]).toMatchObject({ modelId: "nano-banana-pro", op: "edit", inputs: { images: ["/api/files/uploads/p.png"] } });});+ const image = "/api/files/uploads/2026-10-19/still.png";+ const scenes = [+ { narration: "Tea began as medicine.", visual: "A misty mountain tea garden" },+ { narration: "Then it became a ritual.", visual: "Hands pouring tea in a quiet room" },+ { narration: "Today it's everywhere.", visual: "A busy café counter" },+ ];+ const SAMPLES: Record<string, unknown[]> = {+ split_layers: [{ image }, { image, layers: 8, focus: "the person and the text" }],+ restyle_footage: [{ video, style: "claymation" }, { video, style: "anime", references: [image] }],+ dub_video: [{ video, languages: ["Spanish"] }, { video, languages: ["Spanish", "German"], lipsync: false }],+ faceless_episode: [+ { scenes, style: "flat 2D" },+ { title: "Tea", scenes: [...scenes, ...scenes], style: "watercolour", aspect_ratio: "1:1" },+ { scenes, style: "flat 2D", voice_sample: "/api/files/uploads/2026-10-19/me.wav" },+ ],+ create_ads: [{ brief: "oat milk for runners" }, { brief: "oat milk", product_image: image, count: 2, aspect_ratios: ["1:1", "9:16"] }],+ add_captions: [{ video }, { video, translate_to: "Spanish" }],+ };++ it("every studio tool plans without errors on both engines in demo mode", () => {+ expect(Object.keys(SAMPLES).sort()).toEqual(studio.STUDIO_TOOLS.map((t) => t.name).sort());+ for (const mode of ["both", "open", "cloud"] as const) {+ setSetting("engineMode", mode);+ try {+ for (const [name, inputs] of Object.entries(SAMPLES))+ for (const input of inputs)+ for (const engine of ["cloud", "open"] as const) {+ const p = plan(name, input, engine);+ expect(p.error, `${name} ${engine}/${mode}`).toBeUndefined();+ expect(p.jobs.length, `${name} ${engine}/${mode}`).toBeGreaterThan(0);+ for (const j of p.jobs) expect(j.error, `${name} ${engine}/${mode}: ${j.modelId}`).toBeUndefined();+ expect(planRunnable(p.jobs)).toBe(true);+ }+ } finally {+ setSetting("engineMode", "both");+ }+ }+ });++ it("an open-source narrator needs a voice sample to clone once it runs for real", () => {+ // No sample on a real open engine: the narration step says what to add, and the card can't run.+ setSetting("demoMode", "off");+ try {+ const p = plan("faceless_episode", { scenes, style: "flat 2D" }, "open");+ const voice = p.jobs.find((j) => j.note === "Narration")!;+ expect(voice).toMatchObject({ modelId: "oss-chatterbox", atomic: true });+ expect(voice.error).toMatch(/Add a voice sample for the narrator/);+ expect(planRunnable(p.jobs)).toBe(false);+ } finally {+ setSetting("demoMode", "auto");+ }+ // A sample is cloned on either engine; the cloud engine otherwise uses a premade voice.+ const sample = "/api/files/uploads/2026-10-19/me.wav";+ const open = studio.fallbackSteps.faceless({ scenes, style: "x", voice_sample: sample }, { engine: "open" }).find((s) => s.key === "voice")!;+ expect(open.request).toMatchObject({ modelId: "oss-chatterbox", inputs: { voiceAudio: sample } });+ const cloud = studio.fallbackSteps.faceless({ scenes, style: "x", voice_sample: sample }, { engine: "cloud" }).find((s) => s.key === "voice")!;+ expect(cloud.request).toMatchObject({ modelId: "chatterbox-cloud", inputs: { voiceAudio: sample } });+ const premade = studio.fallbackSteps.faceless({ scenes, style: "x", voice: "rachel" }, { engine: "cloud" }).find((s) => s.key === "voice")!;+ expect(premade.request).toMatchObject({ modelId: "elevenlabs-v4", params: { voice: "rachel" } });+ });++ it("a demo faceless episode on the open engine clones a saved demo voice", async () => {+ const out = await tools.executeTool("faceless_episode", { scenes, style: "flat 2D" }, { engine: "open" });+ expect(out.isError).toBeFalsy();+ const body = JSON.parse(out.content as string) as { steps: { step: string; id: string }[]; demo: boolean };+ expect(body.demo).toBe(true);+ const voiceId = body.steps.find((s) => s.step === "Narration")!.id;+ const row = db().prepare("SELECT request_json FROM generations WHERE id = ?").get(voiceId) as { request_json: string };+ expect(JSON.parse(row.request_json).inputs.voiceAudio).toMatch(/^\/api\/files\/uploads\/.+\.wav$/);+ });++ it("one broken step blocks a pipeline's card; a separate job only blocks itself", () => {+ const chained = plan("generate", { summary: "s", jobs: [{ model_id: "nope", prompt: "a" }, { model_id: "oss-wan22-14b-fast", prompt: "b", after: 0 }] }, "open");+ expect(chained.jobs.every((j) => j.atomic)).toBe(true);+ expect(planRunnable(chained.jobs)).toBe(false);+ const separate = plan("generate", { summary: "s", jobs: [{ model_id: "nope", prompt: "a" }, { model_id: "oss-z-image-turbo", prompt: "b" }] }, "open");+ expect(separate.jobs.some((j) => j.atomic)).toBe(false);+ expect(planRunnable(separate.jobs)).toBe(true);+ });+it("runs as one demo pipeline, final result in the chat", async () => {const out = await tools.executeTool("dub_video", { video, languages: ["Spanish"], lipsync: false }, { engine: "open" });expect(out.isError).toBeFalsy();