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
Keyframes: leftover images stay a start frame on Wan, the open film starts at 0 s and keeps each frame within ±2 frames, and a waiting film is refused before Run
Claude346d75c4112b
diff --git a/src/lib/catalog/canvas.ts b/src/lib/catalog/canvas.tsindex cef10aa5..139da736 100644--- a/src/lib/catalog/canvas.ts+++ b/src/lib/catalog/canvas.ts@@ -8,6 +8,7 @@* the server (POST /api/canvases/:id/run) plan a graph exactly the same way.*/import { getModel, getPreset, MODELS, supportsOp } from "./index";+import { chainedWaitMessage, keyframeChain } from "./keyframes";import { estimateCost, inferOperation, planGeneration, type Plan } from "./plan";import {OPERATION_LABELS,@@ -425,7 +426,10 @@ export function inputPorts(n: Pick<CanvasNode, "type" | "data">): PortDef[] {const model = n.data.modelId ? getModel(n.data.modelId) : undefined;const all = nodeOps(n, model);const fallback: Operation[] = n.type === "model" ? (n.data.mediaKind === "video" ? ["t2v", "i2v"] : n.data.mediaKind === "audio" ? ["tts"] : n.data.mediaKind === "text" ? ["write"] : ["t2i", "edit"]) : [];- const ops = n.data.op && all.includes(n.data.op) ? [n.data.op] : all.length ? all : fallback;+ // On Auto, a keyframe film made clip by clip (the open chain) only runs when it's picked: Auto never infers it+ // without frame times, which the canvas doesn't set, so Wan's image port stays the start frame.+ const auto = all.filter((op) => !(op === "keyframes" && model && keyframeChain(model)));+ const ops = n.data.op && all.includes(n.data.op) ? [n.data.op] : auto.length ? auto : fallback;const ids = new Set(ops.flatMap((op) => OP_PORTS[op] ?? []));// Start & end frames: shown on image-to-video models that can take an end frame.if (ops.includes("i2v") && (model?.options.endFrame || (model && supportsOp(model, "flf2v")))) ids.add("endImage");@@ -863,6 +867,8 @@ export function describeNode(graph: CanvasGraph, n: CanvasNode, ctx: DescribeConif ("error" in built) return { model, costUsd: null, error: built.error };try {const plan = planGeneration(withPlaceholders(built.request), getModel, getPreset);+ // A film built clip by clip is planned from its inputs when it starts: it can't wait for another node (said before Run).+ if (built.deps.length && plan.op === "keyframes" && keyframeChain(plan.model)) return { ...built, model, costUsd: null, error: chainedWaitMessage(plan.model.name) };return { ...built, model, plan, costUsd: estimateCost(plan.model, plan.params, plan.jobs) };} catch (e) {return { ...built, model, costUsd: null, error: (e as Error).message };diff --git a/src/lib/catalog/keyframes.ts b/src/lib/catalog/keyframes.tsindex bd86ef68..052f3412 100644--- a/src/lib/catalog/keyframes.ts+++ b/src/lib/catalog/keyframes.ts@@ -50,12 +50,20 @@ export function frameSupport(model: Pick<ModelDef, "routes" | "options">): Framereturn ops.has("i2v") ? "start" : "none";}-/** The model to suggest for every frame on each engine (it must be in the Video studio's list). */+/**+ * The model to suggest for every frame on each engine (it must be in the Video studio's list). On the open+ * engine that's Wan 2.2 14B: its start/end-frame workflow is the one every pair runs on (Lightning has no+ * 4-step version of it), so the whole film comes out at one quality, with up to 7 s between frames.+ */export const FRAMES_MODELS: Record<Engine, { id: string; name: string }> = {cloud: { id: "flux-3-max", name: "FLUX 3 Max" },- open: { id: "oss-wan22-14b-fast", name: "Wan 2.2 14B Lightning" },+ open: { id: "oss-wan22-14b", name: "Wan 2.2 14B" },};+/** Why a chained route can't be a step that waits (a Canvas node fed by another node, a pipeline step): its clips are planned from its inputs when it's created. */+export const chainedWaitMessage = (name: string) =>+ `${name} builds this film from several clips of the images you add when it starts — give it uploaded images and a typed prompt, not another step's output`;+/** What stops Generate in Frames mode before the planner speaks: no start frame, or a model that can't follow frames. */export function framesBlocker(model: Pick<ModelDef, "name" | "engine" | "routes" | "options">, count: number): { message: string; slot?: "frames" } | null {const support = frameSupport(model);@@ -66,12 +74,26 @@ export function framesBlocker(model: Pick<ModelDef, "name" | "engine" | "routes"return null;}+type NoteModel = Pick<ModelDef, "id" | "name" | "engine" | "routes" | "options">;+/*** The line under the strip: what the model will do with the frames (said before anything runs).- * Null when every frame is used as placed.+ * Null when every frame is used as placed. `suggested` is the engine's FRAMES_MODELS model, when the+ * catalog has it: an open chain whose pairs run on that model's own workflow says it gains nothing there+ * (Wan 2.2 14B Lightning: the same full-quality start/end-frame clips, shorter gaps, and only the stretch+ * after the last frame, `tail`, a fast one).*/-export function framesNote(model: Pick<ModelDef, "name" | "engine" | "routes" | "options">, count: number, lastAt = 1): string | null {+export function framesNote(model: NoteModel, count: number, lastAt = 1, ctx: { suggested?: NoteModel; tail?: boolean } = {}): string | null {const support = frameSupport(model);+ const chain = keyframeChain(model);+ const { suggested } = ctx;+ const theirs = suggested && keyframeChain(suggested);+ if (support === "all" && count >= 2 && chain && theirs && suggested.id !== model.id && theirs.endpoint === chain.endpoint) {+ const longer = chainTiming(suggested).maxSeconds > chainTiming(model).maxSeconds + EPS;+ const more = longer ? ` and allows up to ${secondsLabel(chainTiming(suggested).maxSeconds)} between frames` : "";+ const tail = ctx.tail ? " (only the stretch after the last frame is a fast clip)" : "";+ return `${model.name} has no fast start/end-frame clips: the clips between frames render at ${suggested.name}'s full quality${tail} — ${suggested.name} takes as long${more}.`;+ }if (support !== "ends" || count < 2) return null;const alt = FRAMES_MODELS[model.engine].name;if (count > 2) {@@ -180,6 +202,9 @@ export function framesInputs(refs: string[], times: number[], support: FrameSupp// ---------------------------------------------------------------------------// Checks and the open engine's plan+/** The open chain starts its film on the first frame: nothing comes before it. */+export const FIRST_AT_ZERO = "The first frame is the start frame — give it the time 0";+export interface ChainTiming {/** The model's name, for messages. */name: string;@@ -201,6 +226,11 @@ export function chainTiming(model: Pick<ModelDef, "name" | "options">): ChainTim*/export function chainGapProblem(times: number[], duration: number, t: ChainTiming): string | null {const min = t.minSeconds ?? OPEN_MIN_GAP;+ // One frame is one clip from it alone (a plain image-to-video), as long as the model makes.+ if (times.length === 1) {+ const one = round1(duration - times[0]);+ return one > t.maxSeconds + EPS ? `One frame makes a clip of up to ${secondsLabel(t.maxSeconds)} on ${t.name} — add more frames or make the clip shorter` : null;+ }for (let i = 1; i < times.length; i++) {const gap = round1(times[i] - times[i - 1]);if (gap > t.maxSeconds + EPS) return `Frames ${i} and ${i + 1} are ${secondsLabel(gap)} apart — ${t.name} makes up to ${secondsLabel(t.maxSeconds)} between two frames. Move them closer or add a frame between them`;@@ -225,11 +255,13 @@ export interface KeyframeClip {* One start/end-frame clip per pair of neighbouring frames, then the stretch after the last frame* when it isn't at the end (shorter than the minimum: the film ends on the last frame). Each clip's* last frame is the next one's first, so frame k lands on the film's frame Σ(earlier clips) − 1;- * the counts are chosen against the film's running total, so the frames stay on their times within- * half a frame step (Wan 2.2: ±2 frames at 16 fps) however many clips there are.+ * the counts are chosen against the film's running total and the frame's exact time (t·fps, not+ * rounded first), so the frames stay on their times within half a frame step (Wan 2.2: ±2 frames+ * at 16 fps) however many clips there are. The film starts on the first frame, so its time is 0.*/export function planKeyframeClips(times: number[], duration: number, t: ChainTiming & { fps: number; step: number; maxFrames?: number }): KeyframeClip[] {if (times.length < 2) throw new Error("A keyframe film needs at least two frames");+ if (Math.abs(times[0]) > EPS) throw new Error(FIRST_AT_ZERO);const problem = chainGapProblem(times, duration, t);if (problem) throw new Error(problem);const min = t.minSeconds ?? OPEN_MIN_GAP;@@ -245,7 +277,7 @@ export function planKeyframeClips(times: number[], duration: number, t: ChainTimlet total = 0;for (let i = 1; i < stops.length; i++) {// The film's frame count once this clip is in: its last frame (the next frame) sits at stops[i].- const target = Math.round(stops[i] * t.fps) + 1;+ const target = stops[i] * t.fps + 1;const frames = fit(target - total);total += frames;clips.push({ from: i - 1, to: i < times.length ? i : null, frames, seconds: Math.round(((frames - 1) / t.fps) * 1e4) / 1e4 });diff --git a/src/lib/catalog/plan.ts b/src/lib/catalog/plan.tsindex 1637d9ea..abdc78d1 100644--- a/src/lib/catalog/plan.ts+++ b/src/lib/catalog/plan.ts@@ -10,7 +10,7 @@ import type {PresetRoute,Pricing,} from "./types";-import { chainGapProblem, chainTiming, frameTimes, keyframeChain, MAX_KEYFRAMES, spread } from "./keyframes";+import { chainGapProblem, chainTiming, FIRST_AT_ZERO, frameTimes, keyframeChain, MAX_KEYFRAMES, spread } from "./keyframes";/** Infer the operation from what the user attached. */export function inferOperation(model: ModelDef, req: Pick<GenerationRequest, "op" | "inputs" | "params">): Operation {@@ -30,8 +30,9 @@ export function inferOperation(model: ModelDef, req: Pick<GenerationRequest, "opif (req.inputs?.video && imgs && has("video-swap")) return "video-swap";if (req.inputs?.video && has("remove-object")) return "remove-object";if (imgs && req.inputs?.endImage && has("flf2v")) return "flf2v";- // Several stills are keyframes when they have times, or when the model takes no references.- if (imgs > 1 && has("keyframes") && (req.params?.keyframeTimes?.length || !has("ref2v"))) return "keyframes";+ // Several stills are keyframes when they have times, or when the model takes no references. The open+ // chain (a film of several clips) only with times: stills left over from references stay a start frame.+ if (imgs > 1 && has("keyframes") && (req.params?.keyframeTimes?.length || (!has("ref2v") && !keyframeChain(model)))) return "keyframes";if ((imgs > 1 || clipRefs > 0) && has("ref2v")) return "ref2v";if (imgs && has("i2v")) return "i2v";if (has("t2v")) return "t2v";@@ -300,6 +301,8 @@ function checkKeyframes(model: ModelDef, n: number, params: GenParams) {if (times?.length) {if (times.length !== n) throw new Error(`Give each of the ${n} keyframes a time`);if (times.some((t, i) => !Number.isFinite(t) || t < 0 || (i > 0 && t <= times[i - 1]))) throw new Error("Keyframe times start at 0 or later and go up");+ // The open chain's film starts on the first frame (FLUX 3 Max can start it later).+ if (chain && times[0] !== 0) throw new Error(FIRST_AT_ZERO);const last = times[times.length - 1];if (duration !== undefined && last > duration) throw new Error(`The last keyframe is at ${last}s — make the clip at least that long`);}diff --git a/src/server/generations.ts b/src/server/generations.tsindex bc7edd97..c16cbbe6 100644--- a/src/server/generations.ts+++ b/src/server/generations.ts@@ -8,7 +8,7 @@ import { withSignatureWords } from "@/lib/catalog/palettes";import { applySketch, stripMotionPaths } from "@/lib/catalog/sketch";import { cueText, type Cue } from "@/lib/cues";import { HELPER_FEATURES, HELPER_SUFFIX, isReviewStatus, type AssetUse, type ReviewFilter } from "@/lib/library";-import { keyframeChain } from "@/lib/catalog/keyframes";+import { chainedWaitMessage, keyframeChain } from "@/lib/catalog/keyframes";import { estimateCost, inferOperation, planGeneration, routesFor } from "@/lib/catalog/plan";import { keepMatte } from "@/lib/catalog/payload";import {@@ -441,6 +441,8 @@ export function previewChained(req: GenerationRequest, deps: number) {if (!deps) return previewGeneration(req);// A waiting step always runs as one job (createGenerations doesn't batch dependents).const p = previewGeneration(withChainInputs(req, slotsFor(req, deps).map(placeholderFor)));+ // Refused before anything starts, as createGenerations refuses it.+ if (routesFor(p.model, p.op).some((r) => r.chained)) throw new Error(chainedWaitMessage(p.model.name));const jobs = Math.max(1, p.jobs);return { ...p, jobs: 1, outputs: p.outputs / jobs, costUsd: p.costUsd === null ? null : p.costUsd / jobs };}@@ -475,7 +477,7 @@ export function createGenerations(original: GenerationRequest, opts: CreateOptioconst p = waits ? prepare(withChainInputs(original, slotsFor(original, deps.length).map(placeholderFor))) : prepare(original);const { req, plan, route, demo, providerId, cost } = p;// A chained route is built from its inputs when it's created; it can't wait for another step's output.- if (waits && route.chained) throw new Error(`${plan.model.name} builds this from several clips of the images you add — give it uploaded images, not another step's output`);+ if (waits && route.chained) throw new Error(chainedWaitMessage(plan.model.name));const jobs = waits ? 1 : plan.jobs;const batchId = opts.batchId ?? (jobs > 1 ? nanoid(10) : null);const now = Date.now();diff --git a/tests/canvas.test.ts b/tests/canvas.test.tsindex 1092e2ff..0fbcf547 100644--- a/tests/canvas.test.ts+++ b/tests/canvas.test.ts@@ -444,6 +444,34 @@ describe("round-4 models on the canvas", () => {expect(keyframes.find((p) => p.id === "images")!.multiple).toBe(true);});+ it("keeps Wan 2.2 14B's image port a start frame on Auto; its keyframe film is picked, and fed uploaded images", () => {+ for (const id of ["oss-wan22-14b-fast", "oss-wan22-14b"]) {+ const auto = inputPorts(modelNode(id)).find((p) => p.id === "images")!;+ expect(auto).toMatchObject({ label: "Start frame", multiple: false });+ expect(inputPorts(modelNode(id, "keyframes")).find((p) => p.id === "images")).toMatchObject({ label: "Images", multiple: true });+ }+ // Uploaded stills: a film is planned.+ const files: CanvasGraph = {+ nodes: [+ node("a", "image-input", 0, 0, { url: "/api/files/a.png" }),+ node("b", "image-input", 0, 200, { url: "/api/files/b.png" }),+ node("m", "model", 300, 0, { modelId: "oss-wan22-14b", mediaKind: "video", op: "keyframes", prompt: "dawn over the bay", params: { duration: 5 } }),+ ],+ edges: [edge("a", "m", "images"), edge("b", "m", "images")],+ };+ const film = describeNode(files, files.nodes[2]);+ expect(film.error).toBeUndefined();+ expect(film.plan?.op).toBe("keyframes");+ // Generated stills: said on the node before Run (the film's clips are planned from its inputs when it starts).+ const generated: CanvasGraph = {+ nodes: [node("img", "model", 0, 0, { modelId: "nano-banana-pro", prompt: "a bay at dawn" }), { ...files.nodes[2] }, files.nodes[0]],+ edges: [edge("a", "m", "images"), edge("img", "m", "images")],+ };+ const d = describeNode(generated, generated.nodes[1]);+ expect(d.error).toBe("Wan 2.2 14B builds this film from several clips of the images you add when it starts — give it uploaded images and a typed prompt, not another step's output");+ expect(planCanvas(generated).errors.map((e) => e.nodeId)).toEqual(["m"]);+ });+it("runs an eraser fed from the board", () => {const g: CanvasGraph = {nodes: [node("clip", "video-input", 0, 0, { url: "/api/files/clip.mp4" }), node("m", "model", 300, 0, { modelId: "bria-video-erase", prompt: "the coffee cup" })],diff --git a/tests/chains.test.ts b/tests/chains.test.tsindex 8634e79e..01226b68 100644--- a/tests/chains.test.ts+++ b/tests/chains.test.ts@@ -198,9 +198,19 @@ describe("keyframe film (Frames mode on the open engine)", () => {expect(gens.listGenerations({ limit: 500 }).length).toBe(before);});- it("refuses to wait for another step's images", () => {- expect(() =>- gens.createGenerations({ feature: "canvas", modelId: "oss-wan22-14b-fast", op: "keyframes", prompt: "x", chain: [{ slot: "images" }, { slot: "images" }] }, { dependsOn: ["a", "b"] }),- ).toThrow(/uploaded images, not another step's output/);+ it("refuses to wait for another step's images, in the preview as when it's created", () => {+ const req = { feature: "canvas", modelId: "oss-wan22-14b-fast", op: "keyframes" as const, prompt: "x", chain: [{ slot: "images" as const }, { slot: "images" as const }] };+ expect(() => gens.createGenerations(req, { dependsOn: ["a", "b"] })).toThrow(/give it uploaded images and a typed prompt, not another step's output/);+ expect(() => gens.previewChained(req, 2)).toThrow(/give it uploaded images and a typed prompt, not another step's output/);+ // Another model's image-to-video waits as before.+ expect(gens.previewChained({ feature: "canvas", modelId: "oss-wan22-14b-fast", prompt: "x", chainFrom: "first" }, 1).op).toBe("i2v");+ });++ it("keeps a start frame and a leftover reference an image-to-video clip, not a film", async () => {+ // A Seedance reference tile carried over to Wan when the engine switches: no times, no film.+ const images = await frames(2);+ const items = gens.createGenerations({ feature: "video", modelId: "oss-wan22-14b-fast", prompt: "a fox in snow", inputs: { images }, params: { duration: 5 } });+ expect(items).toHaveLength(1);+ expect(items[0].op).toBe("i2v");});});diff --git a/tests/composer-frames.test.ts b/tests/composer-frames.test.tsindex 7c267d8d..24e00e42 100644--- a/tests/composer-frames.test.ts+++ b/tests/composer-frames.test.ts@@ -17,7 +17,7 @@ describe("Frames mode in the Video studio composer", () => {it("is offered in the Video studio, whose list has the models that take every frame", () => {expect(VIDEO_STUDIO.frames).toBe(true);const ids = studioCatalog(VIDEO_STUDIO).models.map((m) => m.id);- expect(ids).toEqual(expect.arrayContaining(["flux-3-max", "oss-wan22-14b-fast", "kling-o3"]));+ expect(ids).toEqual(expect.arrayContaining(["flux-3-max", "oss-wan22-14b-fast", "oss-wan22-14b", "kling-o3"]));// The client copy keeps the chained route's marker (the field maps stay on the server).const wan = studioCatalog(VIDEO_STUDIO).models.find((m) => m.id === "oss-wan22-14b-fast")!;expect(wan.routes.find((r) => r.op === "keyframes")).toMatchObject({ chained: true });@@ -81,7 +81,7 @@ describe("Frames mode in the Video studio composer", () => {it("asks for the start frame first and says which models can't follow frames", () => {const base = { model: true, uploading: false, promptMissing: true };expect(blockerFor({ ...base, frames: framesBlocker(getModel("flux-3-max")!, 0) })).toEqual({ message: "Add the start frame", slot: "frames" });- expect(blockerFor({ ...base, frames: framesBlocker(getModel("oss-ltx25")!, 2) })?.message).toBe("LTX-2.5 takes a start frame only — pick Wan 2.2 14B Lightning to follow your frames, or turn Frames off");+ expect(blockerFor({ ...base, frames: framesBlocker(getModel("oss-ltx25")!, 2) })?.message).toBe("LTX-2.5 takes a start frame only — pick Wan 2.2 14B to follow your frames, or turn Frames off");// A model that takes every frame (or the ends) falls through to the usual checks.expect(blockerFor({ ...base, frames: framesBlocker(getModel("kling-o3")!, 3) })?.message).toBe("Write a prompt first");expect(blockerFor({ ...base, loading: "Loading models…", frames: framesBlocker(getModel("flux-3-max")!, 0) })?.message).toBe("Loading models…");diff --git a/tests/keyframes.test.ts b/tests/keyframes.test.tsindex 9152bec6..567034a2 100644--- a/tests/keyframes.test.ts+++ b/tests/keyframes.test.ts@@ -100,7 +100,7 @@ describe("what each model does with frames", () => {});it("blocks models that can't follow frames, and asks for the start frame", () => {- expect(framesBlocker(m("oss-wan22-5b"), 3)?.message).toBe("Wan 2.2 5B takes a start frame only — pick Wan 2.2 14B Lightning to follow your frames, or turn Frames off");+ expect(framesBlocker(m("oss-wan22-5b"), 3)?.message).toBe("Wan 2.2 5B takes a start frame only — pick Wan 2.2 14B to follow your frames, or turn Frames off");const t2vOnly = { name: "Text Only", engine: "cloud" as const, routes: [{ op: "t2v" as const, provider: "fal" as const, endpoint: "x" }], options: {} };expect(framesBlocker(t2vOnly, 2)?.message).toBe("Text Only can't start from frames — pick FLUX 3 Max, or turn Frames off");expect(framesBlocker(m("flux-3-max"), 0)).toEqual({ message: "Add the start frame", slot: "frames" });@@ -117,6 +117,22 @@ describe("what each model does with frames", () => {expect(framesNote(m("oss-wan22-14b-fast"), 6)).toBeNull();});+ it("suggests Wan 2.2 14B for Frames on the open engine, and says Lightning gains nothing there", () => {+ // Lightning's pairs run the same full-quality start/end-frame workflow as Wan 2.2 14B (it has no 4-step one).+ expect(keyframeChain(m("oss-wan22-14b-fast"))?.endpoint).toBe(keyframeChain(m("oss-wan22-14b"))?.endpoint);+ expect(m("oss-wan22-14b-fast").routes.find((r) => r.op === "flf2v")?.endpoint).toBe("wan22-flf2v-14b");+ const suggested = m("oss-wan22-14b");+ expect(framesNote(m("oss-wan22-14b-fast"), 3, 1, { suggested })).toBe(+ "Wan 2.2 14B Lightning has no fast start/end-frame clips: the clips between frames render at Wan 2.2 14B's full quality — Wan 2.2 14B takes as long and allows up to 7 s between frames.",+ );+ expect(framesNote(m("oss-wan22-14b-fast"), 3, 0.8, { suggested, tail: true })).toMatch(/full quality \(only the stretch after the last frame is a fast clip\) — /);+ // Nothing to say with one frame, or on Wan 2.2 14B itself.+ expect(framesNote(m("oss-wan22-14b-fast"), 1, 0, { suggested })).toBeNull();+ expect(framesNote(suggested, 4, 1, { suggested })).toBeNull();+ // A start + end frame model on the open engine points at it.+ expect(framesNote(m("oss-wan22-14b-fast"), 3, 1, { suggested: m("flux-3-max") })).toBeNull();+ });+it("sends every frame with its time, or the first and last as start and end", () => {const refs = ["/a.png", "/b.png", "/c.png"];expect(framesInputs(refs, [0, 2, 5], "all")).toEqual({ images: refs, keyframeTimes: [0, 2, 5] });@@ -174,6 +190,27 @@ describe("keyframes through the planner", () => {expect(fails({ modelId: "oss-wan22-14b-fast", op: "keyframes", inputs: { images: imgs(3) }, params: { duration: 8 } })).toBeNull();expect(fails({ modelId: "oss-wan22-14b-fast", op: "keyframes", inputs: { images: imgs(3) }, params: { duration: 30 } })).toMatch(/15 s apart/);});++ it("never turns leftover images into a keyframe film on the open chain unless they have times", () => {+ // A start frame plus a reference carried over from a cloud model: still image-to-video from the start frame.+ for (const id of ["oss-wan22-14b-fast", "oss-wan22-14b"]) {+ expect(inferOperation(m(id), { inputs: { images: imgs(2) } })).toBe("i2v");+ expect(inferOperation(m(id), { inputs: { images: imgs(4) }, params: { duration: 5 } })).toBe("i2v");+ expect(plan({ modelId: id, inputs: { images: imgs(2) } }).op).toBe("i2v");+ // Times, or the operation asked for, make it a film.+ expect(inferOperation(m(id), { inputs: { images: imgs(2) }, params: { keyframeTimes: [0, 5] } })).toBe("keyframes");+ expect(inferOperation(m(id), { op: "keyframes", inputs: { images: imgs(2) } })).toBe("keyframes");+ }+ // FLUX 3 Max isn't a chain: its keyframes still read several stills without times.+ expect(inferOperation(m("flux-3-max"), { inputs: { images: imgs(3) } })).toBe("keyframes");+ });++ it("starts the open chain's film on the first frame", () => {+ expect(fails({ modelId: "oss-wan22-14b-fast", inputs: { images: imgs(2) }, params: { duration: 5, keyframeTimes: [1, 3] } })).toBe("The first frame is the start frame — give it the time 0");+ expect(fails({ modelId: "oss-wan22-14b", inputs: { images: imgs(2) }, params: { duration: 7, keyframeTimes: [2, 6.9] } })).toBe("The first frame is the start frame — give it the time 0");+ // FLUX 3 Max places its first keyframe where it's asked.+ expect(fails({ modelId: "flux-3-max", inputs: { images: imgs(2) }, params: { duration: 5, keyframeTimes: [1, 3] } })).toBeNull();+ });});describe("the open per-pair plan", () => {@@ -204,6 +241,34 @@ describe("the open per-pair plan", () => {});});+ it("holds the half-step bound (±2 frames at 16 fps) on any film the planner accepts", () => {+ // A seeded walk over many films: 2–10 frames anywhere on the 0.1 s grid, with and without a tail.+ let seed = 7;+ const rand = () => ((seed = (seed * 1103515245 + 12345) % 2 ** 31) / 2 ** 31);+ const full = { ...wan, name: "Wan 2.2 14B", maxSeconds: 7 };+ let checked = 0;+ let worst = 0;+ for (let k = 0; k < 4000; k++) {+ const t = k % 2 ? wan : full;+ const duration = [3, 5, 8, 10, 15, 20, 30][k % 7];+ const n = 2 + Math.floor(rand() * 9);+ const ats = [0, ...Array.from({ length: n - 1 }, () => rand())].sort((a, b) => a - b);+ if (rand() < 0.5) ats[n - 1] = 1;+ const times = frameTimes(ats, duration);+ if (chainGapProblem(times, duration, t)) continue;+ const clips = planKeyframeClips(times, duration, t);+ let total = 0;+ for (const c of clips) {+ total += c.frames;+ const at = c.to === null ? duration : times[c.to];+ worst = Math.max(worst, Math.abs(total - 1 - at * 16));+ }+ checked++;+ }+ expect(checked).toBeGreaterThan(500);+ expect(worst).toBeLessThanOrEqual(2 + 1e-9);+ });+it("adds the stretch after the last frame from that frame alone, unless it's too short", () => {const clips = planKeyframeClips([0, 2, 4], 6, wan);expect(clips.map((c) => [c.from, c.to])).toEqual([@@ -218,6 +283,14 @@ describe("the open per-pair plan", () => {it("refuses gaps the model can't make", () => {expect(() => planKeyframeClips([0, 5.5], 6, wan)).toThrow(/5.5 s apart/);expect(() => planKeyframeClips([0], 5, wan)).toThrow(/at least two frames/);+ expect(() => planKeyframeClips([1, 3], 5, wan)).toThrow("The first frame is the start frame — give it the time 0");expect(chainGapProblem([0, 2, 5], 5, wan)).toBeNull();});++ it("holds one frame to one clip the model makes", () => {+ // One frame is a plain image-to-video: no longer than the model's own clip.+ expect(chainGapProblem([0], 30, wan)).toBe("One frame makes a clip of up to 5 s on Wan 2.2 14B Lightning — add more frames or make the clip shorter");+ expect(chainGapProblem([0], 5, wan)).toBeNull();+ expect(chainGapProblem([], 30, wan)).toBeNull();+ });});