Skip to content

armgit / fuobe

Public Imported from GitHub
0

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.

Assist and MCP: generate takes keyframes with a timing per gap, the playback rate and a still mouth

Claude4674ac4cbb05
diff --git a/src/server/assist/tools.ts b/src/server/assist/tools.ts
index 89e2153d..b161f893 100644
--- a/src/server/assist/tools.ts
+++ b/src/server/assist/tools.ts
@@ -2,6 +2,7 @@ import "server-only";
import type Anthropic from "@anthropic-ai/sdk";
import { nanoid } from "nanoid";
import { z } from "zod";
+import { keyTimes, type InbetweenTiming, type PlaybackFps, type Speed } from "@/lib/inbetween";
import { getModel, modelsFor } from "@/lib/catalog";
import { offeredModels } from "../model-access";
import { dualEngine, runsOn } from "@/lib/catalog/engines";
@@ -278,6 +279,15 @@ const Job = z.object({
end_time: z.number().optional().describe("Trim: where the kept part ends, in seconds."),
num_layers: z.number().int().optional().describe("Layers: how many layers to split the image into."),
system: z.string().optional().describe("Write: extra instructions for the writer (tone, format, length)."),
+ keyframe_times: z.array(z.number()).optional().describe("Keyframes (2–10 images in order): each image's time in seconds, the first at 0."),
+ gaps: z
+ .array(z.object({ frames: z.number().int(), speed: z.number().int().optional(), words: z.string().optional() }))
+ .optional()
+ .describe(
+ "Keyframe animation (fuobe-animation): one entry per gap between neighbouring images: frames drawn (4n + 1, 17–81), speed (keep every Nth frame, 1–4; the cloud keeps every frame), and what happens in that gap.",
+ ),
+ playback_fps: z.number().int().optional().describe("Keyframe animation: 24 (snappier, the default on the GPU) or 16 (true time; the cloud plays at 16)."),
+ still_mouth: z.boolean().optional().describe("Keyframe animation: keep the character's mouth still between poses."),
after: z
.number()
.int()
@@ -332,6 +342,7 @@ function asRequest(j: JobInput): GenerationRequest {
...(j.voice_audio && { voiceAudio: j.voice_audio }),
};
const shots = j.shots && j.shots > 1 ? shotList(getModel(currentModelId(j.model_id)), j.shots) : undefined;
+ const animation = animationOf(j);
return {
feature: "assist",
modelId: j.model_id,
@@ -353,11 +364,26 @@ function asRequest(j: JobInput): GenerationRequest {
endTime: j.end_time,
numLayers: j.num_layers,
...(shots && { shots }),
- ...(j.system && { extra: { system: j.system } }),
+ ...(j.keyframe_times?.length && { keyframeTimes: j.keyframe_times }),
+ ...((j.system || animation) && { extra: { ...(j.system && { system: j.system }), ...animation } }),
+ ...(animation?.inbetween && !j.keyframe_times?.length && { keyframeTimes: keyTimes({ ...animation.inbetween, fps: animation.inbetween.fps ?? (j.engine === "cloud" ? 16 : 24) }) }),
},
};
}
+/** A keyframe animation's timing from a job (gaps, playback rate, still mouth), as the request carries it. */
+function animationOf(j: JobInput): { inbetween?: InbetweenTiming; stillMouth?: true } | undefined {
+ if (!j.gaps?.length && !j.playback_fps && !j.still_mouth) return undefined;
+ // Without a rate the engine's own plays it (24 fps on the GPU, 16 in the cloud: src/lib/inbetween.ts requestTiming).
+ const inbetween = j.gaps?.length
+ ? ({
+ gaps: j.gaps.map((g) => ({ frames: g.frames, speed: (g.speed ?? 1) as Speed, ...(g.words?.trim() && { prompt: g.words.trim() }) })),
+ ...(j.playback_fps && { fps: j.playback_fps as PlaybackFps }),
+ } as InbetweenTiming)
+ : undefined;
+ return { ...(inbetween && { inbetween }), ...(j.still_mouth && { stillMouth: true as const }) };
+}
+
/** Where an earlier job's result goes in a later one, by what it is and what the later job does. */
function slotFor(kind: MediaKind, op: Operation | undefined): ChainSlot {
if (kind === "text") return { slot: "prompt" };
diff --git a/tests/inbetween-runs.test.ts b/tests/inbetween-runs.test.ts
index 406d171f..75ff06c2 100644
--- a/tests/inbetween-runs.test.ts
+++ b/tests/inbetween-runs.test.ts
@@ -12,6 +12,7 @@ process.env.COMFYUI_URL = "http://127.0.0.1:9";
const { setSetting } = await import("@/server/settings");
const gens = await import("@/server/generations");
const { saveFile } = await import("@/server/storage");
+const tools = await import("@/server/assist/tools");
beforeAll(() => setSetting("demoMode", "auto"));
afterAll(() => fs.rmSync(dir, { recursive: true, force: true }));
@@ -77,4 +78,23 @@ describe("Fuobe Animation runs", () => {
).toThrow(/your GPU/);
expect(gens.listGenerations({ limit: 500 }).length).toBe(before);
});
+
+ it("takes keyframes with a timing per gap from Assist and MCP's generate tool", async () => {
+ const images = frames(3);
+ const job = { model_id: "fuobe-animation", prompt: "a cat stretches", images, gaps: [{ frames: 21, speed: 2, words: "it yawns" }, { frames: 17 }], still_mouth: true };
+ const plan = tools.planFor("generate", { summary: "Animate", jobs: [job] }, { engine: "open" });
+ expect(plan.error).toBeUndefined();
+ expect(plan.jobs[0]).toMatchObject({ modelId: "fuobe-animation", op: "keyframes", costUsd: 0 });
+ // The cloud keeps every frame: ×2 is refused there, with the reason.
+ const cloud = tools.planFor("generate", { summary: "Animate", jobs: [{ ...job, engine: "cloud" }] }, { engine: "cloud" });
+ expect(cloud.jobs[0].error).toMatch(/your GPU/);
+ const out = await tools.executeTool("generate", { summary: "Animate", jobs: [job] }, { engine: "open" });
+ expect(out.isError).toBeFalsy();
+ const result = JSON.parse(out.content as string)[0];
+ expect(result.error).toBeUndefined();
+ const id = (result.started as string[])[0];
+ const g = gens.getGeneration(id)!;
+ expect(g.request.params?.extra).toMatchObject({ inbetween: { gaps: [{ frames: 21, speed: 2, prompt: "it yawns" }, { frames: 17, speed: 1 }] }, stillMouth: true });
+ expect(g.request.params?.keyframeTimes).toEqual([0, 10 / 24, 26 / 24].map((t) => Math.round(t * 1000) / 1000));
+ });
});