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.

Models & licences: chains and Originals refuse a switched-off step before anything is queued

Claude1775861aadcb
diff --git a/src/server/chains.ts b/src/server/chains.ts
index 2e7a854a..a4b73289 100644
--- a/src/server/chains.ts
+++ b/src/server/chains.ts
@@ -3,12 +3,14 @@ import { nanoid } from "nanoid";
import { getModel, supportsOp } from "@/lib/catalog";
import { MODEL3D_STEP_FEATURE, stillPromptFor3d } from "@/lib/av/model3d";
import { chainTiming, frameTimes, planKeyframeClips, spread } from "@/lib/catalog/keyframes";
+import { onEngine } from "@/lib/catalog/engines";
import { routesFor } from "@/lib/catalog/plan";
import type { ChainSlot, Engine, Generation, GenerationRequest, LoraRef, ModelDef, ModelRoute, Operation } from "@/lib/catalog/types";
import { db } from "./db";
import { cancelGeneration, chooseRoute, createGenerations, getGeneration, previewChained, previewGeneration } from "./generations";
import { provider } from "./providers";
import { loadManifest } from "./providers/comfyui";
+import { offeredRoutes, requireOffered } from "./model-access";
/**
* Multi-step jobs built from chained generations: each step waits for the ones it needs and
@@ -24,6 +26,8 @@ interface ModeStep {
label: string;
modelId: string;
op: Operation;
+ /** The engine a Fuobe Original's step runs on (its routes there are the ones checked). */
+ engine?: Engine;
}
/** Who can run a model's operation, as Settings names them ("fal.ai", "Claude or Ollama"). */
@@ -31,13 +35,16 @@ export const providerNames = (m: ModelDef, op: Operation) => [...new Set(routesF
/**
* A chain must not mix paid and demo steps: a demo join of paid clips (or a paid step fed a demo
- * placeholder) wastes the money and returns the wrong result. Throws before any row is created.
+ * placeholder) wastes the money and returns the wrong result. Nor can it reach a step that is switched off in
+ * Settings → Models & licences (the refusal names the switch). Throws before any row is created.
*/
export function assertOneMode(steps: ModeStep[]): void {
const modes = steps.map((s) => {
- const m = getModel(s.modelId);
- if (!m) throw new Error(`Unknown model ${s.modelId}`);
- return { ...s, model: m, demo: chooseRoute(routesFor(m, s.op)).demo };
+ const found = getModel(s.modelId);
+ if (!found) throw new Error(`Unknown model ${s.modelId}`);
+ const m = requireOffered(found, s.engine);
+ const routes = offeredRoutes(found, routesFor(s.engine ? onEngine(found, s.engine) : found, s.op));
+ return { ...s, model: m, demo: chooseRoute(routes).demo };
});
const demo = modes.find((s) => s.demo);
if (demo && modes.some((s) => !s.demo)) {
@@ -109,8 +116,14 @@ export function joinClips(ids: string[], o: JoinOptions): Generation {
// Fold the first `max` clips into one until the rest fit in a final join (8 clips → 3 joins).
let level = ids;
const room = max - (o.before?.length ?? 0);
- while (level.length > room) level = [join(level.slice(0, max), false).id, ...level.slice(max)];
- return join(level, true);
+ try {
+ while (level.length > room) level = [join(level.slice(0, max), false).id, ...level.slice(max)];
+ return join(level, true);
+ } catch (e) {
+ // A join that can't be made (switched off in Settings → Models & licences, say): clips still waiting aren't paid for.
+ cancelWaiting(ids);
+ throw e;
+ }
}
/**
@@ -127,7 +140,7 @@ export function createShotFilm(original: GenerationRequest, model: ModelDef): Ge
const canT2v = supportsOp(model, "t2v");
const firstOp: Operation = original.inputs?.images?.length || !canT2v ? "i2v" : "t2v";
assertOneMode([
- { label: `${model.name} shots`, modelId: model.id, op: firstOp },
+ { label: `${model.name} shots`, modelId: model.id, op: firstOp, engine: model.engine },
{ label: "Joining the shots", modelId: joinModelId(model.engine), op: "concat" },
]);
const batchId = nanoid(10);
@@ -136,34 +149,43 @@ export function createShotFilm(original: GenerationRequest, model: ModelDef): Ge
delete params.shots;
delete params.multiShot;
const n = shots.length;
- const clips = shots.map((s, i) => {
- const { images, endImage, ...rest } = original.inputs ?? {};
- const inputs = { ...rest, ...((i === 0 || !canT2v) && images?.length && { images }), ...(i === n - 1 && endImage && { endImage }) };
- return createGenerations(
+ const clips: Generation[] = [];
+ try {
+ for (const [i, s] of shots.entries()) {
+ const { images, endImage, ...rest } = original.inputs ?? {};
+ const inputs = { ...rest, ...((i === 0 || !canT2v) && images?.length && { images }), ...(i === n - 1 && endImage && { endImage }) };
+ clips.push(
+ createGenerations(
+ {
+ ...original,
+ op: undefined,
+ prompt: overall ? `${overall}. ${s.prompt.trim()}` : s.prompt.trim(),
+ inputs: Object.keys(inputs).length ? inputs : undefined,
+ params: { ...params, duration: s.duration, numOutputs: 1 },
+ step: { label: `Shot ${i + 1} of ${n}`, index: i, of: n },
+ },
+ { batchId },
+ )[0],
+ );
+ }
+ const film = joinClips(
+ clips.map((c) => c.id),
{
- ...original,
- op: undefined,
- prompt: overall ? `${overall}. ${s.prompt.trim()}` : s.prompt.trim(),
- inputs: Object.keys(inputs).length ? inputs : undefined,
- params: { ...params, duration: s.duration, numOutputs: 1 },
- step: { label: `Shot ${i + 1} of ${n}`, index: i, of: n },
+ engine: model.engine,
+ feature: original.feature,
+ batchId,
+ title: overall || shots.map((s) => tidy(s.prompt)).join(" / "),
+ aspectRatio: params.aspectRatio,
+ resolution: params.resolution,
+ step: { label: `Film · ${n} shots`, index: n, of: n + 1 },
},
- { batchId },
- )[0];
- });
- const film = joinClips(
- clips.map((c) => c.id),
- {
- engine: model.engine,
- feature: original.feature,
- batchId,
- title: overall || shots.map((s) => tidy(s.prompt)).join(" / "),
- aspectRatio: params.aspectRatio,
- resolution: params.resolution,
- step: { label: `Film · ${n} shots`, index: n, of: n + 1 },
- },
- );
- return [film, ...clips];
+ );
+ return [film, ...clips];
+ } catch (e) {
+ // Don't leave shots rendering for a film that can't be made.
+ for (const g of clips) void cancelGeneration(g.id);
+ throw e;
+ }
}
/**
@@ -187,8 +209,8 @@ export function createKeyframeFilm(original: GenerationRequest, model: ModelDef,
});
const tail = clips.some((c) => c.to === null);
assertOneMode([
- { label: `${model.name} clips`, modelId: model.id, op: "flf2v" },
- ...(tail ? [{ label: `${model.name} after the last frame`, modelId: model.id, op: "i2v" as const }] : []),
+ { label: `${model.name} clips`, modelId: model.id, op: "flf2v", engine: model.engine },
+ ...(tail ? [{ label: `${model.name} after the last frame`, modelId: model.id, op: "i2v" as const, engine: model.engine }] : []),
...(clips.length > 1 ? [{ label: "Joining the clips", modelId: joinModelId(model.engine), op: "concat" as const }] : []),
]);
const batchId = nanoid(10);
@@ -243,7 +265,7 @@ export function createExtendChain(original: GenerationRequest, model: ModelDef):
const frameModel = model.engine === "open" ? "oss-extract-frame" : "extract-frame";
assertOneMode([
{ label: "Taking the last frame", modelId: frameModel, op: "frame" },
- { label: model.name, modelId: model.id, op: "i2v" },
+ { label: model.name, modelId: model.id, op: "i2v", engine: model.engine },
{ label: "Joining the clips", modelId: joinModelId(model.engine), op: "concat" },
]);
const batchId = nanoid(10);
@@ -251,29 +273,36 @@ export function createExtendChain(original: GenerationRequest, model: ModelDef):
{ feature: original.feature, modelId: frameModel, op: "frame", inputs: { video }, step: { label: "Last frame", index: 0, of: 3 } },
{ batchId },
)[0];
- const rest = { ...original.inputs };
- delete rest.video;
- delete rest.videos;
- const clip = createGenerations(
- {
- ...original,
- op: "i2v",
- prompt: original.prompt?.trim() || "Continue the shot naturally, same subject, same camera move",
- inputs: Object.keys(rest).length ? rest : undefined,
- chain: [{ slot: "images", position: "first" }],
- step: { label: "Continuation", index: 1, of: 3 },
- },
- { batchId, dependsOn: frame.id },
- )[0];
- const film = joinClips([clip.id], {
- engine: model.engine,
- feature: original.feature,
- batchId,
- title: tidy(original.prompt) || "Extended video",
- before: [video],
- step: { label: "Extended video", index: 2, of: 3 },
- });
- return [film, clip, frame];
+ const made = [frame];
+ try {
+ const rest = { ...original.inputs };
+ delete rest.video;
+ delete rest.videos;
+ const clip = createGenerations(
+ {
+ ...original,
+ op: "i2v",
+ prompt: original.prompt?.trim() || "Continue the shot naturally, same subject, same camera move",
+ inputs: Object.keys(rest).length ? rest : undefined,
+ chain: [{ slot: "images", position: "first" }],
+ step: { label: "Continuation", index: 1, of: 3 },
+ },
+ { batchId, dependsOn: frame.id },
+ )[0];
+ made.push(clip);
+ const film = joinClips([clip.id], {
+ engine: model.engine,
+ feature: original.feature,
+ batchId,
+ title: tidy(original.prompt) || "Extended video",
+ before: [video],
+ step: { label: "Extended video", index: 2, of: 3 },
+ });
+ return [film, clip, frame];
+ } catch (e) {
+ for (const g of made) void cancelGeneration(g.id);
+ throw e;
+ }
}
/** The still the open text-to-3D route draws first. */
@@ -337,9 +366,12 @@ export function createRelitClip(original: GenerationRequest, relight: { engine:
const [image, ...rest] = original.inputs?.images ?? [];
if (!image) throw new Error("Add a start frame to relight");
const { engine, step } = relight;
+ // The clip runs on the engine asked for, never quietly on the other one (createGenerations refuses an engine that is off).
+ const where = (e: Engine) => (e === "open" ? "on your GPU" : "in the cloud");
+ if (original.engine && original.engine !== engine) throw new Error(`This relight effect was planned ${where(engine)}, but ${where(original.engine)} was asked for`);
assertOneMode([
- { label: "Relighting the start frame", modelId: step.modelId, op: step.op },
- { label: getModel(original.modelId)?.name ?? original.modelId, modelId: original.modelId, op: original.op ?? "i2v" },
+ { label: "Relighting the start frame", modelId: step.modelId, op: step.op, engine },
+ { label: getModel(original.modelId)?.name ?? original.modelId, modelId: original.modelId, op: original.op ?? "i2v", engine },
]);
const batchId = nanoid(10);
const relit = createGenerations(
@@ -354,17 +386,22 @@ export function createRelitClip(original: GenerationRequest, relight: { engine:
},
{ batchId },
)[0];
- const clip = createGenerations(
- {
- ...original,
- engine,
- inputs: { ...original.inputs, images: rest.length ? rest : undefined },
- chain: [{ slot: "images", position: "first" }],
- step: { label: "Relit clip", index: 1, of: 2 },
- },
- { batchId, dependsOn: relit.id },
- )[0];
- return [clip, relit];
+ try {
+ const clip = createGenerations(
+ {
+ ...original,
+ engine,
+ inputs: { ...original.inputs, images: rest.length ? rest : undefined },
+ chain: [{ slot: "images", position: "first" }],
+ step: { label: "Relit clip", index: 1, of: 2 },
+ },
+ { batchId, dependsOn: relit.id },
+ )[0];
+ return [clip, relit];
+ } catch (e) {
+ void cancelGeneration(relit.id);
+ throw e;
+ }
}
/** The model a storyboard film is animated with. */
diff --git a/src/server/generations.ts b/src/server/generations.ts
index 0959cca7..cdc166e4 100644
--- a/src/server/generations.ts
+++ b/src/server/generations.ts
@@ -44,7 +44,7 @@ import { setResolver, watchGenerations, type LiveEvent } from "./live";
import { provider } from "./providers";
import { comfyLoraFiles, probeComfy } from "./providers/comfyui";
import { ensureLorasOnComfy, prepareCloudLoras, withoutUnreachableCivitai } from "./loras";
-import { offeredLoras, offeredModel, offeredRoutes, requireOffered } from "./model-access";
+import { offeredLoras, offeredRoutes, requireOffered } from "./model-access";
import { llmBackends, llmMissing, llmUsesClaude, probeOllama } from "./providers/llm";
import type { PollContext, PollResult, RemoteOutput } from "./providers/types";
import { mediaFacts } from "./media-facts";
@@ -451,6 +451,18 @@ export function relightStep(req: GenerationRequest, model: ModelDef): { engine:
return { engine, step: preset.prestep[engine] };
}
+/**
+ * The model a request may run, as Settings → Models & licences offers it (only its routes that are on). Engine mode
+ * refuses an Original's engine it rules out first; then a model that is off is refused naming the switch, and so is
+ * an Original's engine that is off when it is the one asked for, or the one the install's engine mode runs it on.
+ * Every run and every chain (createGenerations, before any step is queued) goes through it.
+ */
+export function offeredFor(m: ModelDef, asked: Engine | undefined): ModelDef {
+ const mode = engineMode();
+ if (dualEngine(m)) pickEngine(m, asked, mode, () => true);
+ return requireOffered(m, asked ?? (mode === "both" ? undefined : mode));
+}
+
/** Resolve mentions and drawings, plan, enforce the engine mode and pick a provider route. */
function prepare(original: GenerationRequest) {
// @element mentions become reference images / LoRAs; the stored request keeps the mentions for "Reuse".
@@ -460,7 +472,7 @@ function prepare(original: GenerationRequest) {
// Settings → Models & licences: a model (or the engine of an Original asked for) that is switched off is refused,
// naming the switch; an Original otherwise runs on an engine that is still on, with the routes that are on.
const found = getModel(worded.modelId);
- const allowed = found && requireOffered(found, worded.engine);
+ const allowed = found && offeredFor(found, worded.engine);
const model = allowed && dualEngine(allowed) ? onEngine(allowed, engineFor(allowed, worded.engine)) : allowed;
const lookup = (id: string) => (model && id === model.id ? model : getModel(id));
const req = model ? stripMotionPaths(applySketch(applyMentions(worded, model, listElements()).request, model).request, model) : worded;
@@ -576,9 +588,10 @@ const depIds = (v: string | null): string[] => (!v ? [] : v.startsWith("[") ? (J
export function createGenerations(original: GenerationRequest, opts: CreateOptions = {}): Generation[] {
// Open models make multi-shot films shot by shot, then join the clips. A Fuobe Original is taken on the engine it runs
// on (Fuobe DoP's Frames mode is a GPU chain).
- // An Original runs on an engine still on in Settings → Models & licences (prepare refuses a model that is off).
+ // A model (or an Original's engine asked for) switched off in Settings → Models & licences is refused here, before a
+ // chain queues any step; an Original otherwise runs on an engine still on.
const catalogModel = getModel(original.modelId);
- const found = catalogModel && (offeredModel(catalogModel) ?? catalogModel);
+ const found = catalogModel && offeredFor(catalogModel, original.engine);
const shotModel = found && dualEngine(found) ? onEngine(found, engineFor(found, original.engine)) : found;
if (!opts.dependsOn && shotModel?.options.multiShot?.mode === "concat" && (original.params?.shots?.filter((x) => x.prompt.trim()).length ?? 0) > 1) {
return createShotFilm(original, shotModel);
diff --git a/tests/model-access.test.ts b/tests/model-access.test.ts
index fe515f73..6b64c371 100644
--- a/tests/model-access.test.ts
+++ b/tests/model-access.test.ts
@@ -13,9 +13,10 @@ import { accessSummary, ALL_ON, applyChange, firstOffered, gateModel, offered, o
// The switches live in the settings table: a throwaway database.
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "fuobe-model-access-"));
process.env.FUOBE_DATA_DIR = dir;
-const { changeAccess, factsOf, isOffered, offeredLoras, offeredModels, offeredSummary, pickOffered, readAccess, routeLicence } = await import("@/server/model-access");
-const { previewGeneration } = await import("@/server/generations");
+const { changeAccess, factsOf, isOffered, offeredDefault, offeredLoras, offeredModels, offeredSummary, readAccess, routeLicence } = await import("@/server/model-access");
+const { createGenerations, previewGeneration } = await import("@/server/generations");
const { setSetting } = await import("@/server/settings");
+const { db } = await import("@/server/db");
afterAll(() => fs.rmSync(dir, { recursive: true, force: true }));
const MANIFEST = JSON.parse(fs.readFileSync(path.join(process.cwd(), "workflows/comfyui/manifest.json"), "utf8")) as Manifest;
@@ -215,10 +216,17 @@ describe("the switches on the server", () => {
expect(() => previewGeneration({ feature: "image", modelId: "nano-banana-pro", prompt: "a cat" })).toThrow(/open source only/);
});
- it("picks the next model that is on, or says what to turn on", () => {
+ it("picks the next model that is on, or keeps the default so its run says what to turn on", () => {
changeAccess([{ kind: "model", id: "nano-banana-pro", on: false }]);
- expect(pickOffered(["nano-banana-pro", "seedream-5-pro"])).toBe("seedream-5-pro");
- expect(() => pickOffered(["nano-banana-pro"])).toThrow(/^Nano Banana Pro is turned off in Settings → Models & licences/);
+ const next = offeredDefault("nano-banana-pro", "cloud")!;
+ expect(next).not.toBe("nano-banana-pro");
+ expect(isOffered(next, "cloud")).toBe(true);
+ expect(model(next).kind).toBe("image");
+ expect(offeredDefault("seedream-5-pro", "cloud")).toBe("seedream-5-pro");
+ changeAccess([{ kind: "class", id: "paid-api", on: false }]);
+ // No cloud image model is on: the default stays, and its run refuses naming the switch.
+ expect(offeredDefault("nano-banana-pro", "cloud")).toBe("nano-banana-pro");
+ expect(() => previewGeneration({ feature: "image", modelId: "nano-banana-pro", prompt: "a cat" })).toThrow(/^Nano Banana Pro is turned off in Settings → Models & licences/);
});
it("leaves out LoRAs switched off by file or licence class, and marks GPU-only ones when the admin keeps them home", () => {
@@ -237,3 +245,66 @@ describe("the switches on the server", () => {
expect(offeredLoras([aw]).loras[0]).toMatchObject({ file: aw.file, keepOnGpu: true });
});
});
+
+describe("chains and Originals refuse a switched-off step before anything is queued", () => {
+ const rows = () => (db().prepare("SELECT COUNT(*) AS n FROM generations").get() as { n: number }).n;
+ const relight = { feature: "motion", modelId: "fuobe-dop", presetId: "effect-window", prompt: "a woman reading", inputs: { images: ["/api/files/uploads/a.png"] } };
+ beforeEach(() => {
+ reset();
+ setSetting("demoMode", "on");
+ setSetting("engineMode", "both");
+ });
+
+ it("refuses the model itself before a chain queues its first step", () => {
+ changeAccess([{ kind: "model", id: "fuobe-dop", on: false }]);
+ const before = rows();
+ expect(() => createGenerations({ ...relight, engine: "cloud" })).toThrow(/^Fuobe DoP is turned off in Settings → Models & licences \(the model is switched off\)/);
+ expect(rows()).toBe(before);
+ });
+
+ it("refuses a chain whose helper step is off, before any step is queued", () => {
+ changeAccess([{ kind: "model", id: "join-clips", on: false }]);
+ let before = rows();
+ expect(() => createGenerations({ feature: "extend", modelId: "kling-3", op: "extend", prompt: "she keeps running", inputs: { video: "/api/files/placeholder.mp4" } })).toThrow(
+ /^Join clips is turned off in Settings → Models & licences/,
+ );
+ expect(rows()).toBe(before);
+ reset();
+ changeAccess([{ kind: "model", id: "oss-join-clips", on: false }]);
+ before = rows();
+ const shots = [
+ { prompt: "wide shot", duration: 3 },
+ { prompt: "close-up", duration: 5 },
+ ];
+ expect(() => createGenerations({ feature: "video", modelId: "oss-wan22-14b-fast", prompt: "A fox", params: { aspectRatio: "16:9", shots } })).toThrow(/turned off in Settings → Models & licences/);
+ expect(rows()).toBe(before);
+ reset();
+ changeAccess([{ kind: "model", id: "qwen-image-edit-2509-cloud", on: false }]);
+ before = rows();
+ expect(() => createGenerations({ ...relight, engine: "cloud" })).toThrow(/turned off in Settings → Models & licences/);
+ expect(rows()).toBe(before);
+ });
+
+ it("refuses a relight effect on the engine asked for when that engine is off, in the preview as when it's created", () => {
+ changeAccess([{ kind: "class", id: "paid-api", on: false }]);
+ const before = rows();
+ const refusal = /^Fuobe DoP in the cloud is turned off in Settings → Models & licences \(Proprietary paid API is switched off\)/;
+ expect(() => previewGeneration({ ...relight, engine: "cloud" })).toThrow(refusal);
+ expect(() => createGenerations({ ...relight, engine: "cloud" })).toThrow(refusal);
+ expect(rows()).toBe(before);
+ // Without an engine asked for, it runs on the one still on, the relight step with it.
+ const [clip, relit] = createGenerations(relight);
+ expect(clip).toMatchObject({ modelId: "fuobe-dop", engine: "open" });
+ expect(relit.modelId).toBe("oss-qwen-relight");
+ });
+
+ it("names the switch, not Engine mode, when cloud only meets an Original whose cloud half is off", () => {
+ setSetting("engineMode", "cloud");
+ changeAccess([{ kind: "class", id: "paid-api", on: false }]);
+ expect(() => previewGeneration({ feature: "image", modelId: "fuobe-soul", prompt: "a cat" })).toThrow(
+ /^Fuobe Soul in the cloud is turned off in Settings → Models & licences \(Proprietary paid API is switched off\)/,
+ );
+ // Engine mode still refuses the engine it rules out first.
+ expect(() => previewGeneration({ feature: "image", modelId: "fuobe-soul", prompt: "a cat", engine: "open" })).toThrow(/paid cloud APIs only/);
+ });
+});