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.

Originals O13: Popcorn boards take a Fuobe Soul look, frame 1 on Fuobe Soul, the look's finish on every frame, priced before they run

Claudedd4c2913d9b6
diff --git a/src/app/api/storyboards/estimate/route.ts b/src/app/api/storyboards/estimate/route.ts
new file mode 100644
index 00000000..d5ebde86
--- /dev/null
+++ b/src/app/api/storyboards/estimate/route.ts
@@ -0,0 +1,12 @@
+import { estimateStoryboard, StoryboardBodySchema } from "@/server/storyboard";
+
+/** What a board costs before it runs ("Free" on your GPU): every frame, the look's model for frame 1. */
+export async function POST(request: Request) {
+ const parsed = StoryboardBodySchema.safeParse(await request.json().catch(() => null));
+ if (!parsed.success) return Response.json({ error: parsed.error.issues.map((i) => i.message).join("; ") }, { status: 400 });
+ try {
+ return Response.json(estimateStoryboard(parsed.data));
+ } catch (e) {
+ return Response.json({ error: (e as Error).message }, { status: 422 });
+ }
+}
diff --git a/src/app/api/storyboards/route.ts b/src/app/api/storyboards/route.ts
index ccfd9bd1..016e7185 100644
--- a/src/app/api/storyboards/route.ts
+++ b/src/app/api/storyboards/route.ts
@@ -1,20 +1,8 @@
-import { z } from "zod";
-import { createStoryboard } from "@/server/storyboard";
-
-const Body = z.object({
- engine: z.enum(["cloud", "open"]),
- scenes: z.array(z.string().max(1000)).max(8).optional(),
- story: z.string().max(4000).optional(),
- frames: z.number().int().min(1).max(8).optional(),
- references: z.array(z.string().startsWith("/api/files/")).max(4).optional(),
- style: z.string().max(500).optional(),
- aspectRatio: z.string().max(10).optional(),
- resolution: z.string().max(10).optional(),
-});
+import { createStoryboard, StoryboardBodySchema } from "@/server/storyboard";
/** Popcorn-style storyboard: consecutive frames, each made from the previous one. */
export async function POST(request: Request) {
- const parsed = Body.safeParse(await request.json().catch(() => null));
+ const parsed = StoryboardBodySchema.safeParse(await request.json().catch(() => null));
if (!parsed.success) return Response.json({ error: parsed.error.issues.map((i) => i.message).join("; ") }, { status: 400 });
try {
return Response.json(await createStoryboard(parsed.data), { status: 201 });
diff --git a/src/lib/catalog/storyboard.ts b/src/lib/catalog/storyboard.ts
index fd6b808b..3b39c407 100644
--- a/src/lib/catalog/storyboard.ts
+++ b/src/lib/catalog/storyboard.ts
@@ -2,8 +2,14 @@
* Storyboards (Higgsfield Popcorn): up to 8 consistent frames. Frame 1 is made from the
* references (or text alone); every later frame is an edit of the previous frame, so faces,
* wardrobe, location and grade carry through.
+ *
+ * Since build plan O13 a board can take one of Fuobe Soul's looks (research §8 popcorn): frame 1
+ * is made on Fuobe Soul with the look on either engine (with references it stays on the reference
+ * model, with the look's words), the next frames carry the look's words, and every frame gets the
+ * look's grade and overlay after it is made (each next frame is made from the previous one as it
+ * came out, so the grade is applied once).
*/
-import type { Engine } from "./types";
+import type { ChainSlot, Engine, GenerationRequest } from "./types";
export const MAX_FRAMES = 8;
@@ -14,6 +20,13 @@ export const STORYBOARD_MODELS: Record<Engine, { first: string; firstWithRefs: s
open: { first: "oss-z-image-turbo", firstWithRefs: "oss-qwen-edit", next: "oss-qwen-next-scene", chainFrom: "first" },
};
+/** The model a board with a Soul look makes its first frame on (no references): the look's LoRAs, words and grade. */
+export const STORYBOARD_LOOK_MODEL = "fuobe-soul";
+
+/** Shapes a board offers; Fuobe Soul has no 21:9, so a look board makes 16:9 frames and crops them to 21:9 after. */
+export const STORYBOARD_ASPECTS = ["16:9", "9:16", "1:1", "4:3", "3:4", "21:9"] as const;
+export const LOOK_CROPPED = "21:9";
+
const SHOTS = [
"establishing wide shot",
"medium shot",
@@ -63,3 +76,61 @@ export function framePrompt(scene: string, index: number, opts: { refs: number;
const prev = opts.refs + 1;
return `Next frame of the same storyboard: ${s}. Image ${prev} is the previous frame — continue from it with the same characters, faces, wardrobe, props, location style, lighting and color grade, like consecutive shots of one film.${style}`;
}
+
+// ---------------------------------------------------------------------------
+// The board's frames (the server creates them, one waiting on the one before)
+
+export interface StoryboardLook {
+ id: string;
+ /** The look in words (soulLook(id).look), carried into every next frame's prompt. */
+ words: string;
+ /** The look's strength (scales its LoRAs on frame 1). */
+ strength?: number;
+}
+
+export interface StoryboardPlanInput {
+ engine: Engine;
+ scenes: string[];
+ references?: string[];
+ style?: string;
+ look?: StoryboardLook;
+ aspectRatio?: string;
+ resolution?: string;
+ batchTitle?: string;
+}
+
+export type FrameRequest = GenerationRequest & { batchTitle?: string };
+
+/**
+ * Each frame's request, in order (frame 1 first). A frame after the first waits on the one before and takes its
+ * picture as it came out (`raw`: before a look's grade, which every frame gets on its own).
+ */
+export function planStoryboard(input: StoryboardPlanInput): FrameRequest[] {
+ const m = STORYBOARD_MODELS[input.engine];
+ const refs = (input.references ?? []).slice(0, 4);
+ const look = input.look;
+ const cropped = !!look && input.aspectRatio === LOOK_CROPPED;
+ const params = { aspectRatio: cropped ? "16:9" : input.aspectRatio, resolution: input.resolution, numOutputs: 1 };
+ const lookWords = look?.words.trim().replace(/[.\s]+$/, "");
+ // The next frames keep the look in words; frame 1 on Fuobe Soul gets them from its recipe.
+ const style = [input.style?.trim().replace(/[.\s]+$/, ""), lookWords].filter(Boolean).join(". ") || undefined;
+ return input.scenes.map((scene, i) => {
+ const first = i === 0;
+ // The open next-scene workflow takes the previous panel plus one character reference.
+ const frameRefs = first ? refs : m.chainFrom === "first" ? refs.slice(0, 1) : refs;
+ const onSoul = first && !!look && !refs.length;
+ // A look board's next frame takes the previous picture as it came out (raw); otherwise the single-image chainFrom.
+ const chain: ChainSlot[] | undefined = first || !look ? undefined : [{ slot: "images", position: m.chainFrom, raw: true }];
+ return {
+ feature: "storyboard",
+ modelId: onSoul ? STORYBOARD_LOOK_MODEL : first ? (refs.length ? m.firstWithRefs : m.first) : m.next,
+ ...(onSoul && { engine: input.engine, presetId: look.id, ...(look.strength !== undefined && { presetStrength: look.strength }) }),
+ prompt: framePrompt(scene, i, { refs: frameRefs.length, chainFrom: m.chainFrom, style: onSoul ? input.style : style }),
+ inputs: frameRefs.length ? { images: frameRefs } : undefined,
+ params,
+ ...(chain ? { chain } : !first && { chainFrom: m.chainFrom }),
+ frame: { scene, index: i, of: input.scenes.length, ...(look && { look: look.id }), ...(cropped && { crop: LOOK_CROPPED }) },
+ ...(input.batchTitle && { batchTitle: input.batchTitle }),
+ };
+ });
+}
diff --git a/src/lib/catalog/types.ts b/src/lib/catalog/types.ts
index 86116b68..763b7d67 100644
--- a/src/lib/catalog/types.ts
+++ b/src/lib/catalog/types.ts
@@ -861,7 +861,11 @@ export interface GenerationRequest {
*/
dropWhenUnused?: boolean;
/** Storyboard frame this request makes (shown under the frame). */
- frame?: { scene: string; index: number; of: number };
+ /**
+ * A storyboard frame. `look`: the board's Fuobe Soul look, whose grade and overlay every frame gets after it is made
+ * (as meta, like a Soul picture); `crop`: a look board asked for 21:9 is made at 16:9 and cropped after.
+ */
+ frame?: { scene: string; index: number; of: number; look?: string; crop?: "21:9" };
/** Part of a multi-step job (a shot of a multi-shot film, a step of an extend): shown on its tile. */
step?: { label: string; index: number; of: number };
/** Server-set: what the user calls this result, shown instead of the prompt (Library, feeds). */
@@ -916,6 +920,11 @@ export interface ChainSlot {
* missing input go), and `notice` is said on the result and on the steps after it.
*/
optional?: { prompt?: string; notice: string };
+ /**
+ * Take the picture as the model made it, before Fuobe Soul's finish in the browser (`meta.original`): a storyboard
+ * with a look makes each next frame from the previous one, and every frame gets the look's grade on its own.
+ */
+ raw?: boolean;
}
/** How many outputs a planned list (ChainSlot.of) may be short of before the steps reading it fail. */
diff --git a/src/server/generations.ts b/src/server/generations.ts
index c3287181..7d261b84 100644
--- a/src/server/generations.ts
+++ b/src/server/generations.ts
@@ -16,7 +16,7 @@ import { estimateCost, inferOperation, planGeneration, presetRoute, routeLoras,
import { framedLength, keepMatte } from "@/lib/catalog/payload";
import { fitLoras, loraName, lorasFit } from "@/lib/catalog/loras";
import { dualEngine, onEngine, pickEngine } from "@/lib/catalog/engines";
-import { promptWithLoras, soulKind, soulLook, soulPostSteps } from "@/lib/catalog/soul";
+import { promptWithLoras, SOUL_MODELS, soulKind, soulLook, soulPostSteps } from "@/lib/catalog/soul";
import { isDop } from "@/lib/catalog/dop";
import { finishSteps } from "@/lib/soul-post";
import {
@@ -793,8 +793,10 @@ function placeholderFor(s: ChainSlot): string {
* A translation of timed text gets the cue list (so the timing survives); text saved only as a
* file, or cut short inline (meta.truncated), is read back from it.
*/
-async function chainValue(o: OutputFile | undefined, s: ChainSlot, op?: Generation["op"]): Promise<string | undefined> {
+export async function chainValue(o: OutputFile | undefined, s: ChainSlot, op?: Generation["op"]): Promise<string | undefined> {
if (!o) return undefined;
+ // The picture as it was made, before a Soul finish replaced it (a look board's next frame: its own grade comes after).
+ if (s.raw && typeof o.meta?.original === "string" && o.meta.original) return o.meta.original;
if (s.slot !== "prompt") return o.url;
const cues = Array.isArray(o.meta?.cues) && o.meta.cues.length ? (o.meta.cues as Cue[]) : null;
if (op === "translate" && cues) return JSON.stringify(cues);
@@ -1381,7 +1383,10 @@ async function pollOne(r: Row): Promise<void> {
}
// Fuobe Soul: what follows in the browser (the look's grade, an overlay, Soul Cinema's 21:9 crop), on each image;
// API clients read it as meta.
- const post = soulPostSteps(r.model_id, r.preset_id, soulKind(r.model_id) ? requestAspect(r.request_json) : undefined);
+ // A storyboard frame with a look gets the look's finish whatever model made it (a 21:9 board is cropped after).
+ const board = (JSON.parse(r.request_json) as GenerationRequest).frame;
+ const boardPost = board?.look ? soulPostSteps(SOUL_MODELS.soul, board.look) : undefined;
+ const post = boardPost ? { ...boardPost, ...(board?.crop && { crop: board.crop }) } : soulPostSteps(r.model_id, r.preset_id, soulKind(r.model_id) ? requestAspect(r.request_json) : undefined);
if (post) for (const [i, o] of outputs.entries()) if (o.kind === "image") outputs[i] = { ...o, meta: { ...o.meta, ...post } };
// Fuobe DoP's colour-grade effects: the grade the browser applies to the clip (the result's "Apply the grade" step).
const grade = isDop(r.model_id) && r.preset_id ? getPreset(r.preset_id)?.grade : undefined;
diff --git a/src/server/storyboard.ts b/src/server/storyboard.ts
index 93016ba0..dee82e57 100644
--- a/src/server/storyboard.ts
+++ b/src/server/storyboard.ts
@@ -1,12 +1,29 @@
import "server-only";
import { nanoid } from "nanoid";
-import { framePrompt, heuristicScenes, MAX_FRAMES, parseScenes, SPLIT_SYSTEM, STORYBOARD_MODELS } from "@/lib/catalog/storyboard";
+import { z } from "zod";
+import { heuristicScenes, MAX_FRAMES, parseScenes, planStoryboard, SPLIT_SYSTEM, type StoryboardLook } from "@/lib/catalog/storyboard";
+import { soulLook } from "@/lib/catalog/soul";
import type { Engine, Generation, GenerationRequest } from "@/lib/catalog/types";
import { storyboardName } from "@/lib/storyboard-board";
import { supportsOp } from "@/lib/catalog";
import { filmModel, joinClips } from "./chains";
import { llmText } from "./enhance";
-import { createGenerations, listGenerations } from "./generations";
+import { createGenerations, listGenerations, previewChained } from "./generations";
+
+/** The body of POST /api/storyboards and /api/storyboards/estimate. */
+export const StoryboardBodySchema = z.object({
+ engine: z.enum(["cloud", "open"]),
+ scenes: z.array(z.string().max(1000)).max(8).optional(),
+ story: z.string().max(4000).optional(),
+ frames: z.number().int().min(1).max(8).optional(),
+ references: z.array(z.string().startsWith("/api/files/")).max(4).optional(),
+ style: z.string().max(500).optional(),
+ /** A Fuobe Soul look id ("v1-general"): frame 1 on Fuobe Soul, the look's grade on every frame. */
+ look: z.string().max(80).optional(),
+ lookStrength: z.number().min(0).max(1).optional(),
+ aspectRatio: z.string().max(10).optional(),
+ resolution: z.string().max(10).optional(),
+});
export interface StoryboardRequest {
engine: Engine;
@@ -17,6 +34,9 @@ export interface StoryboardRequest {
frames?: number;
references?: string[];
style?: string;
+ /** A Fuobe Soul look for the board (build plan O13): frame 1 on Fuobe Soul, the look's grade on every frame. */
+ look?: string;
+ lookStrength?: number;
aspectRatio?: string;
resolution?: string;
}
@@ -27,36 +47,47 @@ export async function splitStory(story: string, n: number): Promise<string[]> {
return (text && parseScenes(text, n)) || heuristicScenes(story, n);
}
+/** The look as the planner takes it (its words), or an error for an unknown one. */
+function boardLook(r: Pick<StoryboardRequest, "look" | "lookStrength">): StoryboardLook | undefined {
+ if (!r.look) return undefined;
+ const look = soulLook(r.look);
+ if (!look) throw new Error("That look doesn't exist — pick another one");
+ return { id: look.id, words: look.look, ...(r.lookStrength !== undefined && { strength: r.lookStrength }) };
+}
+
+/** What a board costs before it runs: each frame's price (frame 1 alone, the rest as chained steps), and whether it would be a demo. */
+export function estimateStoryboard(r: StoryboardRequest): { costUsd: number | null; demo: boolean; frames: number; models: string[] } {
+ const n = Math.max(1, Math.min(MAX_FRAMES, r.scenes?.filter((s) => s.trim()).length || r.frames || 4));
+ const scenes = Array.from({ length: n }, (_, i) => r.scenes?.[i]?.trim() || `scene ${i + 1}`);
+ const frames = planStoryboard({ engine: r.engine, scenes, references: r.references, style: r.style, look: boardLook(r), aspectRatio: r.aspectRatio, resolution: r.resolution });
+ let cost: number | null = 0;
+ let demo = false;
+ const models: string[] = [];
+ frames.forEach((f, i) => {
+ const p = previewChained(f, i ? 1 : 0);
+ demo ||= p.demo;
+ cost = cost === null || p.costUsd === null ? null : cost + p.costUsd;
+ if (!models.includes(p.model.name)) models.push(p.model.name);
+ });
+ return { costUsd: cost === null ? null : Math.round((cost as number) * 10000) / 10000, demo, frames: n, models };
+}
+
export async function createStoryboard(r: StoryboardRequest): Promise<{ batchId: string; scenes: string[]; items: Generation[] }> {
const n = Math.max(1, Math.min(MAX_FRAMES, r.scenes?.length || r.frames || 4));
+ const look = boardLook(r);
const scenes = r.scenes?.length ? r.scenes.slice(0, MAX_FRAMES).map((s) => s.trim()).filter(Boolean) : await splitStory(r.story ?? "", n);
if (!scenes.length) throw new Error("Describe the story or write at least one scene");
- const refs = (r.references ?? []).slice(0, 4);
- const m = STORYBOARD_MODELS[r.engine];
const batchId = nanoid(10);
// The board is named after the user's idea on every device (the Library's stack title too).
const batchTitle = storyboardName(r.scenes?.length ? undefined : r.story, scenes);
- const params = { aspectRatio: r.aspectRatio, resolution: r.resolution, numOutputs: 1 };
+ const frames = planStoryboard({ engine: r.engine, scenes, references: r.references, style: r.style, look, aspectRatio: r.aspectRatio, resolution: r.resolution, batchTitle });
const items: Generation[] = [];
let previous: string | undefined;
- scenes.forEach((scene, i) => {
- const first = i === 0;
- // The open next-scene workflow takes the previous panel plus one character reference.
- const frameRefs = first ? refs : m.chainFrom === "first" ? refs.slice(0, 1) : refs;
- const request: GenerationRequest & { batchTitle?: string } = {
- feature: "storyboard",
- modelId: first ? (refs.length ? m.firstWithRefs : m.first) : m.next,
- prompt: framePrompt(scene, i, { refs: frameRefs.length, chainFrom: m.chainFrom, style: r.style }),
- inputs: frameRefs.length ? { images: frameRefs } : undefined,
- params,
- chainFrom: first ? undefined : m.chainFrom,
- frame: { scene, index: i, of: scenes.length },
- batchTitle,
- };
+ for (const request of frames) {
const [g] = createGenerations(request, { batchId, dependsOn: previous });
items.push(g);
previous = g.id;
- });
+ }
return { batchId, scenes, items };
}
diff --git a/tests/popcorn-looks.test.ts b/tests/popcorn-looks.test.ts
new file mode 100644
index 00000000..22cbfd66
--- /dev/null
+++ b/tests/popcorn-looks.test.ts
@@ -0,0 +1,116 @@
+import fs from "node:fs";
+import os from "node:os";
+import path from "node:path";
+import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
+import { planStoryboard, STORYBOARD_LOOK_MODEL } from "@/lib/catalog/storyboard";
+import { soulLook } from "@/lib/catalog/soul";
+import type { OutputFile } from "@/lib/catalog/types";
+
+vi.setConfig({ testTimeout: 90_000 });
+
+// Popcorn with Fuobe Soul's looks (build plan O13): the planner, then boards end to end in demo mode.
+const dir = fs.mkdtempSync(path.join(os.tmpdir(), "fuobe-popcorn-"));
+process.env.FUOBE_DATA_DIR = dir;
+process.env.COMFYUI_URL = "http://127.0.0.1:9";
+process.env.OLLAMA_URL = "http://127.0.0.1:9";
+
+const { setSetting } = await import("@/server/settings");
+const gens = await import("@/server/generations");
+const { createStoryboard, estimateStoryboard } = await import("@/server/storyboard");
+const estimateRoute = await import("@/app/api/storyboards/estimate/route");
+const { db } = await import("@/server/db");
+
+beforeAll(() => setSetting("demoMode", "auto"));
+afterAll(() => fs.rmSync(dir, { recursive: true, force: true }));
+
+const look = soulLook("v1-digitalcam")!;
+const scenes = ["a girl at a bus stop at night", "the bus arrives", "she looks back"];
+
+describe("Popcorn looks: the planner", () => {
+ it("frame 1 on Fuobe Soul with the look on the board's engine; the next frames carry its words and take the raw frame before", () => {
+ for (const engine of ["cloud", "open"] as const) {
+ const frames = planStoryboard({ engine, scenes, look: { id: look.id, words: look.look, strength: 0.8 }, aspectRatio: "16:9" });
+ expect(frames[0]).toMatchObject({ modelId: STORYBOARD_LOOK_MODEL, engine, presetId: look.id, presetStrength: 0.8, frame: { index: 0, look: look.id } });
+ // The look's words come from Soul's recipe on frame 1, not twice.
+ expect(frames[0].prompt).not.toContain(look.look.replace(/[.\s]+$/, ""));
+ const next = frames[1];
+ expect(next.modelId).toBe(engine === "cloud" ? "nano-banana-pro" : "oss-qwen-next-scene");
+ expect(next.prompt).toContain(`Style: ${look.look.replace(/[.\s]+$/, "")}`);
+ expect(next.chain).toEqual([{ slot: "images", position: engine === "cloud" ? "last" : "first", raw: true }]);
+ expect(next.chainFrom).toBeUndefined();
+ expect(next.frame).toMatchObject({ index: 1, of: 3, look: look.id });
+ }
+ });
+
+ it("with references, frame 1 stays on the reference model with the look's words, and still gets the look's finish", () => {
+ const [first] = planStoryboard({ engine: "cloud", scenes, references: ["/api/files/hero.png"], style: "35mm", look: { id: look.id, words: look.look } });
+ expect(first).toMatchObject({ modelId: "nano-banana-pro", inputs: { images: ["/api/files/hero.png"] }, frame: { look: look.id } });
+ expect(first.presetId).toBeUndefined();
+ expect(first.prompt).toContain(`Style: 35mm. ${look.look.replace(/[.\s]+$/, "")}`);
+ });
+
+ it("21:9 with a look: made at 16:9 (Fuobe Soul has no 21:9) and cropped after; without a look nothing changes", () => {
+ const wide = planStoryboard({ engine: "open", scenes, look: { id: look.id, words: look.look }, aspectRatio: "21:9" });
+ expect(wide.every((f) => f.params?.aspectRatio === "16:9" && f.frame?.crop === "21:9")).toBe(true);
+ const plain = planStoryboard({ engine: "open", scenes, aspectRatio: "21:9" });
+ expect(plain[0]).toMatchObject({ modelId: "oss-z-image-turbo", params: { aspectRatio: "21:9" } });
+ expect(plain[1]).toMatchObject({ chainFrom: "first" });
+ expect(plain[1].chain).toBeUndefined();
+ expect(plain.every((f) => !f.frame?.look && !f.frame?.crop)).toBe(true);
+ });
+});
+
+describe("Popcorn looks: boards (demo)", () => {
+ const settle = async (id: string) => {
+ for (let i = 0; i < 200; i++) {
+ const g = gens.getGeneration(id)!;
+ if (["succeeded", "failed", "canceled"].includes(g.status)) return g;
+ await new Promise((r) => setTimeout(r, 300));
+ }
+ throw new Error("timed out");
+ };
+
+ it("every frame carries the look's finish as meta; a next frame is made from the frame before as it came out", async () => {
+ const board = await createStoryboard({ engine: "cloud", scenes, look: look.id, aspectRatio: "21:9" });
+ expect(board.items.map((g) => g.modelId)).toEqual(["fuobe-soul", "nano-banana-pro", "nano-banana-pro"]);
+ const first = await settle(board.items[0].id);
+ expect(first.status).toBe("succeeded");
+ expect(first.outputs[0].meta).toMatchObject({ look: look.id, overlay: "date-stamp", crop: "21:9", ...(look.grade && { grade: look.grade }) });
+ // A browser finished frame 1 before frame 2 started: frame 2 still gets the raw picture.
+ const finished: OutputFile[] = first.outputs.map((o) => ({ ...o, url: "/api/files/finished.png", meta: { ...o.meta, finished: true, original: o.url } }));
+ db().prepare("UPDATE generations SET outputs_json = ? WHERE id = ?").run(JSON.stringify(finished), first.id);
+ const second = await settle(board.items[1].id);
+ expect(second.status).toBe("succeeded");
+ expect(second.request.inputs?.images?.at(-1)).toBe(first.outputs[0].url);
+ expect(second.outputs[0].meta).toMatchObject({ look: look.id, overlay: "date-stamp", crop: "21:9" });
+ await settle(board.items[2].id);
+ });
+
+ it("a raw slot takes the picture before its finish; any other slot the finished one", async () => {
+ const o: OutputFile = { url: "/api/files/finished.png", kind: "image", meta: { finished: true, original: "/api/files/raw.png" } };
+ expect(await gens.chainValue(o, { slot: "images", position: "last", raw: true })).toBe("/api/files/raw.png");
+ expect(await gens.chainValue(o, { slot: "images", position: "last" })).toBe("/api/files/finished.png");
+ expect(await gens.chainValue({ url: "/api/files/plain.png", kind: "image" }, { slot: "images", raw: true })).toBe("/api/files/plain.png");
+ });
+
+ it("prices a board before it runs: the look's model for frame 1, Free on the GPU", async () => {
+ setSetting("falKey", "fal-test-key");
+ try {
+ const e = estimateStoryboard({ engine: "cloud", frames: 4, look: look.id });
+ expect(e).toMatchObject({ frames: 4, demo: false, models: ["Fuobe Soul", "Nano Banana Pro"] });
+ // Three Nano Banana Pro edits at $0.15, and Fuobe Soul's picture at about a cent.
+ expect(e.costUsd).toBeGreaterThan(0.45);
+ expect(e.costUsd).toBeLessThan(0.5);
+ const plain = estimateStoryboard({ engine: "cloud", frames: 4 });
+ expect(plain.models).toEqual(["Nano Banana Pro"]);
+ expect(plain.costUsd).toBeCloseTo(0.6, 3);
+ } finally {
+ setSetting("falKey", "");
+ }
+ const res = await estimateRoute.POST(new Request("http://x/api", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ engine: "open", scenes, look: look.id }) }));
+ expect(await res.json()).toMatchObject({ costUsd: 0, frames: 3 });
+ const bad = await estimateRoute.POST(new Request("http://x/api", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ engine: "open", scenes, look: "v9-nope" }) }));
+ expect(bad.status).toBe(422);
+ expect((await bad.json()).error).toBe("That look doesn't exist — pick another one");
+ });
+});