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
Genjutsu: words as they come out — the resolution a model renders, the 30 fps way out, setup links that don't throw
Claude442a236b5c49
diff --git a/src/lib/catalog/genjutsu.ts b/src/lib/catalog/genjutsu.tsindex 48d617e5..45157ac0 100644--- a/src/lib/catalog/genjutsu.ts+++ b/src/lib/catalog/genjutsu.ts@@ -112,8 +112,10 @@ export interface Maker {maxFps?: number;/** The result carries the piece's own sound (otherwise the clip's sound is put back). */keepsSound: boolean;- /** The resolutions it renders; the quality asked for goes to the nearest (none: it keeps the clip's size). */+ /** The resolutions it renders; the quality asked for goes to the nearest (none: see `renders`). */qualities?: string[];+ /** Without a resolution setting: what it renders, in words ("keeps your clip's size", "renders 4K"). */+ renders?: string;/** Words aren't needed (Genjutsu and P-Video find what to swap from the references). */promptOptional?: boolean;/** Swaps the person on camera only. */@@ -175,6 +177,7 @@ export const MAKERS: Maker[] = [maxSeconds: 10,minSeconds: 3,keepsSound: false,+ renders: "picks its own size",},// Object swap (cloud).{@@ -224,6 +227,7 @@ export const MAKERS: Maker[] = [minSeconds: 3,keepsSound: true,sides: { min: 720, max: 3840 },+ renders: "keeps your clip's size",},{id: "p-video-replace",@@ -285,6 +289,7 @@ export const MAKERS: Maker[] = [note: "Reads up to 4 of the look's images · 4K · pieces of up to 10 s",refs: { min: 0, max: 0 },keepsSound: false,+ renders: "renders 4K",looks: "fuobe",readsLookImages: 4,},@@ -343,6 +348,7 @@ export const MAKERS: Maker[] = [note: "The Shorts chain: the first frame restyled (Qwen-Image-Edit, 2 of the look's images), then every frame with depth · 5 s segments at 16 fps, 480p",refs: { min: 0, max: 0 },keepsSound: false,+ renders: "renders 480p at 16 fps",looks: "fuobe",readsLookImages: 2,},@@ -367,6 +373,9 @@ export const OPEN_TARGET_PROBLEM: Partial<Record<GenjutsuMode, string>> = {insert: "On your ComfyUI, paint where it goes — saying it in words is on the cloud engine",};+/** Restyle on the open engine with one of Higgsfield's looks (they run on Higgsfield's Genjutsu Restyle only). */+export const OPEN_LOOK_PROBLEM = "Higgsfield's looks run on the cloud engine — pick one of the 44 looks or Your own";+/*** The model a request runs on, or why there is none. Without a modelId: Genjutsu (Lite unless Quality is High) with a* Higgsfield key, else the keyless route for the mode; on the open engine, the one graph that does the mode.@@ -384,7 +393,10 @@ export function chooseMaker(o: {const target = MODE_TARGETS[o.mode].length ? (o.target ?? MODE_TARGETS[o.mode][0]) : undefined;if (target && !MODE_TARGETS[o.mode].includes(target)) return { problem: `${getMode(o.mode).label} doesn't take ${target === "click" ? "clicks" : "that"} — pick another way` };const options = makersFor(o.engine, o.mode, target, o.look);- if (!options.length) return { problem: (o.engine === "open" && OPEN_TARGET_PROBLEM[o.mode]) || "Nothing on this engine does that yet" };+ if (!options.length) {+ if (o.engine === "open" && o.mode === "restyle" && o.look?.kind === "higgsfield") return { problem: OPEN_LOOK_PROBLEM };+ return { problem: (o.engine === "open" && OPEN_TARGET_PROBLEM[o.mode]) || "Nothing on this engine does that yet" };+ }const withTier = (m: Maker) => (m.pair && o.tier && m.tier !== o.tier ? (getMaker(m.pair) ?? m) : m);const picked = getMaker(o.modelId);if (picked) {@@ -461,13 +473,25 @@ export function makerStepUsd(modelId: string, params: { duration?: number; resolreturn usd * (modelId.startsWith("genjutsu") ? Math.ceil(secs - 1e-6) : secs);}+const px = (q: string) => parseInt(q, 10) || 0;+/** The resolution a model is asked for: the quality picked, or the nearest it renders (the largest not above, else its smallest). */export function qualityFor(m: Maker, quality: string): string | undefined {if (!m.qualities?.length) return undefined;if (m.qualities.includes(quality)) return quality;- const p = (q: string) => parseInt(q, 10) || 0;- const below = m.qualities.filter((q) => p(q) <= p(quality)).sort((a, b) => p(b) - p(a));- return below[0] ?? [...m.qualities].sort((a, b) => p(a) - p(b))[0];+ const below = m.qualities.filter((q) => px(q) <= px(quality)).sort((a, b) => px(b) - px(a));+ return below[0] ?? [...m.qualities].sort((a, b) => px(a) - px(b))[0];+}++/**+ * What comes out when it isn't the quality picked, in words (undefined: it is): "renders 720p (its lowest)" when the+ * model starts above it, "renders up to 720p" when it stops below it, or the model's own words without a setting.+ */+export function resolutionWords(m: Maker, quality: string): string | undefined {+ const res = qualityFor(m, quality);+ if (!res) return m.renders ?? "keeps your clip's size";+ if (res === quality) return undefined;+ return px(res) > px(quality) ? `renders ${res} (its lowest)` : `renders up to ${res}`;}// ---------------------------------------------------------------------------@@ -579,6 +603,7 @@ export function genjutsuProblem(c: GenjutsuCheck): string | null {const m = c.maker;const len = c.range.end - c.range.start;const { width: w, height: h } = c.source;+ const target = MODE_TARGETS[c.mode].length ? (c.target ?? MODE_TARGETS[c.mode][0]) : undefined;if (m.minSeconds && len < m.minSeconds - 0.01) return `${m.label} needs at least ${m.minSeconds} s`;if (m.sides && w && h) {if (Math.min(w, h) < m.sides.min) return `${m.label} needs a clip at least ${m.sides.min} px on each side (this one is ${w}×${h}) — pick another model`;@@ -586,7 +611,13 @@ export function genjutsuProblem(c: GenjutsuCheck): string | null {}if (m.minPixels && w && h && w * h < m.minPixels) return `${m.label} needs a sharper clip (at least ${Math.round(m.minPixels / 1000)} thousand pixels a frame; this one is ${w}×${h}) — Genjutsu Lite takes it`;if (m.window && !c.source.fps) return "Couldn't read this clip's frame rate — save it as an MP4 (H.264) and try again";- if (m.maxFps && c.source.fps && c.source.fps > m.maxFps + 0.01) return `${m.label} takes up to ${m.maxFps} fps (this clip is ${Math.round(c.source.fps)} fps) — pick another model`;+ if (m.maxFps && c.source.fps && c.source.fps > m.maxFps + 0.01) {+ // The hosted VACE is the only model for clicks and paint: the way out is words (or a slower copy of the clip).+ const others = makersFor(m.engine, c.mode, target).filter((x) => x.id !== m.id);+ const words = TARGET_LABELS[c.mode].type?.label;+ const way = others.length ? "pick another model" : words && target !== "type" ? `switch to “${words}”, or save the clip at ${m.maxFps} fps and add it again` : `save the clip at ${m.maxFps} fps and add it again`;+ return `${m.label} takes up to ${m.maxFps} fps (this clip is ${Math.round(c.source.fps)} fps) — ${way}`;+ }if (c.mode !== "restyle" && c.references < Math.max(1, m.refs.min)) return REFS_MISSING[c.mode];if (c.mode === "restyle") {if (!c.look) return "Pick a look";@@ -595,7 +626,6 @@ export function genjutsuProblem(c: GenjutsuCheck): string | null {if (m.looks === "fuobe" && c.look.kind === "higgsfield") return "Higgsfield's looks run on Genjutsu Restyle";if (c.look.kind === "custom" && !m.readsLookImages && !c.look.words?.trim()) return `${m.label} restyles from words only — describe your look, or pick Kling O3 4K Edit`;}- const target = MODE_TARGETS[c.mode].length ? (c.target ?? MODE_TARGETS[c.mode][0]) : undefined;if (target === "type") {if (c.mode === "swap" && !m.promptOptional && !c.subject?.trim()) return "Say what to swap, e.g. “the red car”";if (c.mode === "insert" && !c.prompt?.trim()) return "Say where it goes, e.g. “on the table, next to the cup”";@@ -881,12 +911,13 @@ export function encodeSetup(s: GenjutsuSetup): string {/** A setup read back from a code (or a link with ?setup=…), checked field by field; null when it isn't one. */export function decodeSetup(input: string): GenjutsuSetup | null {- let code = input.trim();- const fromLink = /[?&]setup=([^&#\s]+)/.exec(code);- if (fromLink) code = decodeURIComponent(fromLink[1]);- if (!code.startsWith("gj1.")) return null;let o: Record<string, unknown>;try {+ let code = input.trim();+ // A link: its ?setup= (a malformed %-escape is not a code either).+ const fromLink = /[?&]setup=([^&#\s]+)/.exec(code);+ if (fromLink) code = decodeURIComponent(fromLink[1]);+ if (!code.startsWith("gj1.")) return null;o = JSON.parse(fromBase64Url(code.slice(4).replace(/\s+/g, ""))) as Record<string, unknown>;} catch {return null;diff --git a/src/lib/studios.ts b/src/lib/studios.tsindex 85720653..9b323d05 100644--- a/src/lib/studios.ts+++ b/src/lib/studios.ts@@ -266,7 +266,7 @@ export const MOTION_CONTROL_STUDIO: StudioConfig = {],defaultModels: { cloud: "kling-motion-control", open: "oss-wan22-animate" },promptOptional: true,- related: { href: "/genjutsu?mode=motion", label: "Up to 30 s and 10 references with Genjutsu" },+ related: { href: "/genjutsu?mode=motion", label: "Up to 30 s and 8 character images with Genjutsu" },};export const VIDEO_EDIT_STUDIO: StudioConfig = {diff --git a/src/server/providers/comfyui.ts b/src/server/providers/comfyui.tsindex ff1bd0ec..2fa9fb2b 100644--- a/src/server/providers/comfyui.ts+++ b/src/server/providers/comfyui.ts@@ -593,7 +593,7 @@ export async function prepareWorkflow(endpointTemplate: string, input: GenInput,// as Genjutsu sends it), the reference comes in, the prompt describes the result. Insert: the painted spot and the// reference, the prompt says what appears there. Neither graph takes clicked points.if (ctx.op === "video-swap" || ctx.op === "video-insert") {- if (input.points?.length && !input.mask && typeof extra.maskPrompt !== "string") throw new ProviderError(OPEN_TARGET_PROBLEM.swap!);+ if (input.points?.length && !input.mask && typeof extra.maskPrompt !== "string") throw new ProviderError(OPEN_TARGET_PROBLEM[ctx.op === "video-insert" ? "insert" : "swap"]!);const words = input.prompt?.trim() ?? "";const vace = getMaker(ctx.op === "video-swap" ? "oss-vace-swap" : "oss-vace-insert")!;if (ctx.op === "video-swap" && b.maskPrompt) {diff --git a/tests/genjutsu-comfy.test.ts b/tests/genjutsu-comfy.test.tsindex 4f5e3a51..f3eb1435 100644--- a/tests/genjutsu-comfy.test.ts+++ b/tests/genjutsu-comfy.test.ts@@ -54,6 +54,8 @@ describe("Genjutsu's open graphs through the provider", () => {expect(at(wf, "40", "image")).toBe("lamp.png");expect(at(wf, "16", "text")).toMatch(/^The object from the reference image in the marked area/);await expect(prepare("video-insert-wan-vace", { images: ["lamp.png"], prompt: "a lamp" }, "video-insert")).rejects.toThrow("Paint where it goes on the first frame");+ // Clicks (a Canvas node) are refused with the insert's own words: paint, not "name what to swap".+ await expect(prepare("video-insert-wan-vace", { images: ["lamp.png"], points: [{ x: 3, y: 4 }] }, "video-insert")).rejects.toThrow(OPEN_TARGET_PROBLEM.insert!);});it("a planned swap window is what the graph is given", async () => {diff --git a/tests/genjutsu.test.ts b/tests/genjutsu.test.tsindex 94f31238..f9e8b3cb 100644--- a/tests/genjutsu.test.ts+++ b/tests/genjutsu.test.ts@@ -8,9 +8,11 @@ import {makerPrompt,makersFor,makerStepUsd,+ OPEN_LOOK_PROBLEM,planGenjutsu,planMakerPieces,qualityFor,+ resolutionWords,swapParts,swapTarget,type GenjutsuPlanInput,@@ -55,6 +57,8 @@ describe("Genjutsu: which model runs", () => {expect(chooseMaker({ engine: "open", mode: "restyle", look: { kind: "preset", id: "shorts-watercolor" }, higgsfield: false })).toMatchObject({ maker: { id: "oss-wan22-vace-restyle" } });expect(chooseMaker({ engine: "open", mode: "swap", target: "paint", higgsfield: false })).toEqual({ problem: expect.stringMatching(/name what to swap/) });expect(chooseMaker({ engine: "open", mode: "insert", target: "type", higgsfield: false })).toEqual({ problem: expect.stringMatching(/paint where it goes/) });+ // Higgsfield's looks are cloud-only: said as such, not "nothing does that".+ expect(chooseMaker({ engine: "open", mode: "restyle", look: { kind: "higgsfield", id: "abc" }, higgsfield: true })).toEqual({ problem: OPEN_LOOK_PROBLEM });});it("every maker is a catalog model that does its mode's operation", () => {@@ -96,7 +100,11 @@ describe("Genjutsu: checks", () => {const small = { ...clip, width: 640, height: 360 };expect(genjutsuProblem({ ...base, mode: "swap", maker: maker("genjutsu-object-swap"), source: small, target: "type" })).toMatch(/Genjutsu Lite takes it/);expect(genjutsuProblem({ ...base, mode: "swap", maker: maker("kling-o3"), source: small, target: "type", subject: "the cup" })).toMatch(/at least 720 px/);- expect(genjutsuProblem({ ...base, mode: "swap", maker: maker("wan-22-vace-inpaint"), source: { ...clip, fps: 60 }, target: "paint", mask: true })).toMatch(/up to 30 fps/);+ // The hosted VACE is the only model for clicks and paint: the way out is words, not "another model".+ expect(genjutsuProblem({ ...base, mode: "swap", maker: maker("wan-22-vace-inpaint"), source: { ...clip, fps: 60 }, target: "paint", mask: true })).toBe(+ "Wan 2.2 VACE (hosted) takes up to 30 fps (this clip is 60 fps) — switch to “Type it”, or save the clip at 30 fps and add it again",+ );+ expect(genjutsuProblem({ ...base, mode: "insert", maker: maker("wan-22-vace-inpaint"), source: { ...clip, fps: 60 }, target: "paint", mask: true })).toMatch(/switch to “Say where”/);expect(genjutsuProblem({ ...base, mode: "swap", maker: maker("oss-vace-swap"), source: { ...clip, fps: undefined }, target: "type", subject: "the cup" })).toMatch(/frame rate/);});});@@ -260,6 +268,19 @@ describe("Genjutsu: words and qualities", () => {expect(qualityFor(maker("oss-vace-swap"), "1080p")).toBe("720p");expect(qualityFor(maker("kling-o3"), "1080p")).toBeUndefined();});++ it("says what comes out when it isn't the quality picked", () => {+ // Above the pick is the model's lowest, below it the most it renders.+ expect(resolutionWords(maker("p-video-replace"), "480p")).toBe("renders 720p (its lowest)");+ expect(resolutionWords(maker("gemini-omni-flash"), "480p")).toBe("renders 720p (its lowest)");+ expect(resolutionWords(maker("wan-22-vace-inpaint"), "1080p")).toBe("renders up to 720p");+ expect(resolutionWords(maker("genjutsu-lite-motion-transfer"), "1080p")).toBeUndefined();+ // No setting: each model's own words.+ expect(resolutionWords(maker("kling-o3"), "720p")).toBe("keeps your clip's size");+ expect(resolutionWords(maker("kling-o3-4k-edit"), "720p")).toBe("renders 4K");+ expect(resolutionWords(maker("oss-wan22-vace-restyle"), "1080p")).toBe("renders 480p at 16 fps");+ expect(resolutionWords(maker("kling-motion-control"), "720p")).toBe("picks its own size");+ });});describe("Genjutsu: setup codes", () => {@@ -288,6 +309,8 @@ describe("Genjutsu: setup codes", () => {expect(decodeSetup(encodeSetup({ mode: "restyle", look: { kind: "preset", id: "nope" } }))?.look).toBeUndefined();expect(decodeSetup(encodeSetup({ mode: "motion", target: "paint", model: "not-a-model" }))).toEqual({ mode: "motion" });expect(decodeSetup("gj1.!!!")).toBeNull();+ // A link with a broken %-escape is no code (it doesn't throw).+ expect(decodeSetup("https://x/genjutsu?setup=%E0%A4%A")).toBeNull();expect(decodeSetup("hello")).toBeNull();expect(decodeSetup(`gj1.${btoa(JSON.stringify({ m: "fly" }))}`)).toBeNull();});