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.

Runs: describe prefer as any caller's route choice, and shorten comments

Adarsh79eaceddcc7d
diff --git a/src/components/studio/composer.tsx b/src/components/studio/composer.tsx
index c6d9c91a..9db6a8cc 100644
--- a/src/components/studio/composer.tsx
+++ b/src/components/studio/composer.tsx
@@ -224,7 +224,7 @@ function lookCleared(from: ModelDef | undefined, to: ModelDef): Partial<Draft> {
/** Docked and collapsed, the composer hides its tiles: this event asks it to open first. */
const EXPAND_EVENT = "composer:expand";
-/** "Run anyway" pressed this session (route-notice.ts anywayKeys), kept in this tab's session storage. */
+/** "Run anyway" keys (route-notice.ts anywayKeys) for this tab's session. */
const ANYWAY_KEY = "fuobe:route-anyway";
function readAnyway(): string[] {
@@ -240,7 +240,6 @@ function keepAnyway(keys: string[]) {
try {
sessionStorage.setItem(ANYWAY_KEY, JSON.stringify(keys.slice(-50)));
} catch {
- // Storage off (a private window): asked again next time.
}
}
@@ -751,7 +750,6 @@ export function Composer({ docked }: { docked: boolean }) {
const engineError =
(lockedModel && preset && !appIds.length ? `${preset.name} has no ${engine === "open" ? "open-source" : "cloud"} version yet` : null) ?? accessError ?? comfyBlock;
let op: Operation | undefined;
- // The model the plan runs (a preset's may be another): the one whose routes the run picks from.
let planModel: ModelDef | undefined;
let cost: number | null = null;
// The run goes to a LoRA endpoint whose price isn't published (fal's MOSS-Image /lora).
@@ -945,11 +943,7 @@ export function Composer({ docked }: { docked: boolean }) {
// GPU): run it once on the key, at its price, or connect a GPU. Nothing runs until one is pressed.
const [keyChoice, setKeyChoice] = useState(false);
- // A paid route that can't honour a setting another route of the model takes (Replicate's Wan 2.2 makes 16:9 or 9:16 only
- // and reads no negative prompt): said before the run (src/lib/catalog/route-notice.ts), with "Run anyway" (there, the
- // shape fitted and the setting left out; the run says what changed) and, when it runs for this person, the route that
- // makes everything as asked ("Use fal.ai"). Nothing runs until one is pressed. "Run anyway" isn't asked again this
- // session for the same settings on the same route, and those runs stay on that route.
+ // Route notice (route-notice.ts): shown on Run; nothing runs until "Run anyway" or "Use <provider>" is pressed.
const usableRoute = (p: string) =>
!!status?.providers[p]?.configured && (viewerInfo?.kind !== "account" || (isCloudProvider(p) && (viewerInfo.usableKeys ?? viewerInfo.keys ?? []).includes(p)));
const routeAsk = { params: signed.request.params, negativePrompt: signed.request.negativePrompt, prefer: signed.request.prefer };
@@ -958,7 +952,6 @@ export function Composer({ docked }: { docked: boolean }) {
? routeNotice(planModel, op, likelyProvider(planModel, op, routeAsk, { ready: usableRoute, preferred: status?.cloudProvider }), routeAsk, usableRoute)
: null;
const [routeChoice, setRouteChoice] = useState(false);
- // (A draft changed so its route makes everything as asked: the choice goes.)
if (routeChoice && !routeCheck) setRouteChoice(false);
const [anyway, setAnyway] = useState<string[]>(readAnyway);
const anywayHere = !!routeCheck && !!planModel && !!op && anywaySaid(anyway, planModel.id, op, routeCheck);
@@ -973,8 +966,8 @@ export function Composer({ docked }: { docked: boolean }) {
// `skip` is true only from the guided fix's "Run anyway" (a click handler passes its event here). `withKey`: this run
// only, on the cloud version that action names and the account's key (hosted runs on; see onRunWithKey). `once`: a
// place for this run only (hosted runs: "Run on Our GPUs", or the account's GPU for what only it runs). `signedUp`: the
- // run a guest pressed, started by itself back from sign-up (its note says so once the run is made). `picked`: the route
- // chosen before the run ("Run anyway" on the route it goes to, or "Use fal.ai"), named in the request.
+ // run a guest pressed, started by itself back from sign-up (its note says so once the run is made). `picked`: route chosen
+ // in the route notice, sent as `prefer`.
const submit = (skip?: unknown, withKey?: TroubleAction, once?: "own" | "pool", signedUp?: boolean, picked?: { prefer?: CloudProvider }): void => {
const skipGpu = skip === true;
setKeyChoice(false);
@@ -1018,9 +1011,8 @@ export function Composer({ docked }: { docked: boolean }) {
}
return;
}
- // A route that can't honour a setting: the choice first, unless "Run anyway" was pressed for it this session.
if (routeCheck && !picked && !withKey && !once && !anywayHere) return void setRouteChoice(true);
- const route = picked ?? (routeCheck && anywayHere && isCloudProvider(routeCheck.provider) ? { prefer: routeCheck.provider } : undefined);
+ const route = withKey ? undefined : picked ?? (routeCheck && anywayHere && isCloudProvider(routeCheck.provider) ? { prefer: routeCheck.provider } : undefined);
const withRoute = <R extends object>(r: R): R => (route?.prefer ? { ...r, prefer: route.prefer } : r);
toast.dismiss("composer-blocker");
setPriceNote(null);
@@ -1057,8 +1049,8 @@ export function Composer({ docked }: { docked: boolean }) {
model?.kind,
);
const withVoiceFirst = cleanFirst ? { ...sent.request, params: { ...sent.request.params, extra: { ...sent.request.params?.extra, [VOICE_FIRST_PARAM]: true } } } : sent.request;
- const onKey = withKey ? onCloudKey(withVoiceFirst, withKey) : withRoute(withVoiceFirst);
- const body = { ...onKey, ...hosted, ...(skipGpu && { gpuCheck: "skip" }) } as typeof sent.request;
+ const onKey = withKey ? onCloudKey(withVoiceFirst, withKey) : withVoiceFirst;
+ const body = { ...withRoute(onKey), ...hosted, ...(skipGpu && { gpuCheck: "skip" }) } as typeof sent.request;
create.mutate(body, {
// Accepted: nothing to try again (a card opened later never starts this run a second time). Back from sign-up, the
// line says the run is on its way (hosted runs: its tile shows "In line" too).
@@ -2153,7 +2145,6 @@ export function Composer({ docked }: { docked: boolean }) {
</div>
</div>
)}
- {/* A route that can't honour a setting another route takes: run it there anyway, or where everything is made as asked. */}
{routeChoice && routeCheck && (
<div role="note" aria-live="polite" data-route-notice className="mx-1 mt-2 space-y-1.5 rounded-xl border border-dashed px-3 py-2 text-[12px] leading-snug text-muted-foreground">
<p className="font-medium text-foreground">{routeCheck.words}</p>
diff --git a/src/lib/catalog/route-notice.ts b/src/lib/catalog/route-notice.ts
index 62df2359..60424936 100644
--- a/src/lib/catalog/route-notice.ts
+++ b/src/lib/catalog/route-notice.ts
@@ -6,16 +6,10 @@ import { routesFor } from "./plan";
import { routeTakes } from "./route-takes";
import type { GenParams, ModelDef, ModelRoute, Operation, ProviderId } from "./types";
-/*
- * The notice before a run whose route can't honour a setting another route of the model takes (Replicate's Wan 2.2 makes
- * 16:9 or 9:16 only and has no negative prompt; fal's makes 1:1 and reads one). It reads the same rules as the run's own
- * fit (fitted.ts, route-takes.ts), so the words before the run, the run itself and the note it carries agree. A setting no
- * route of the model takes isn't one: the pickers already say so. Pure, for the composer, the server and their tests.
- */
+// Pre-run notice for a route that can't take a setting another route of the model takes (built on fittedSettings).
type Model = Pick<ModelDef, "id" | "name" | "kind" | "engine" | "routes" | "defaults">;
-/** The settings a route may make differently from what was asked. */
const SETTINGS = new Set<SettingChange["setting"]>(["aspectRatio", "resolution", "duration", "seed", "negativePrompt", "generateAudio"]);
const PROVIDER_LABEL: Partial<Record<ProviderId, string>> = { fal: "fal.ai", replicate: "Replicate" };
@@ -28,7 +22,7 @@ const shortName = (m: Pick<ModelDef, "name">) => m.name.replace(/\s*\([^)]*\)\s*
const listOr = (items: string[]) => (items.length <= 1 ? (items[0] ?? "") : `${items.slice(0, -1).join(", ")} or ${items[items.length - 1]}`);
-/** One setting a route makes differently: what it can do (before the run) and what it did (the run's note). */
+/** `can`: words before the run; `did`: words for the run's notice. */
export interface Shortfall {
setting: SettingChange["setting"];
asked: string;
@@ -47,13 +41,9 @@ export interface RunRequest {
const changesOn = (model: Model, op: Operation, provider: ProviderId, req: RunRequest) =>
fittedSettings(model, op, req.params, { provider, negativePrompt: req.negativePrompt }).changes.filter((c) => SETTINGS.has(c.setting));
-/** The providers that serve the operation (each once, in the model's order). */
const providersFor = (model: Model, op: Operation, params?: GenParams) => [...new Set(routesFor(model as ModelDef, op, params).map((r) => r.provider))];
-/**
- * The settings `provider`'s route makes differently that another route of the operation makes as asked. Nothing on a
- * model with one route, on the open engine, or on routes that take every setting.
- */
+/** Changes on `provider`'s route that some other route of the op doesn't make. */
export function routeShortfalls(model: Model, op: Operation, provider: ProviderId, req: RunRequest): Shortfall[] {
if (model.engine === "open") return [];
const others = providersFor(model, op, req.params).filter((p) => p !== provider);
@@ -73,7 +63,6 @@ function shortfall(model: Model, route: ModelRoute | undefined, c: SettingChange
switch (c.setting) {
case "aspectRatio": {
const list = Array.isArray(takes?.aspectRatios) ? takes.aspectRatios.filter((a) => a.toLowerCase() !== "auto") : [];
- // Not sent: the shape is the model's own ("Its own shape") or its input's ("The start frame's shape").
const own = c.made.toLowerCase();
const can = list.length ? `makes ${listOr(list)} ${noun} only` : own.startsWith("its own") ? "sets its own shape" : `keeps ${own}`;
return { ...base, can, did: same(list) ? `at ${c.made} in place of ${c.asked}` : `in ${own}` };
@@ -84,7 +73,6 @@ function shortfall(model: Model, route: ModelRoute | undefined, c: SettingChange
}
case "duration": {
if (takes?.durations === false) return { ...base, can: "keeps the clip's length", did: "at the clip's length" };
- // A frame-count route's length to the half second ("5s", not "5.06s").
const n = Number.parseFloat(c.made);
const made = Number.isFinite(n) ? `${Math.round(n * 2) / 2}s` : c.made;
return { ...base, made, can: `makes this ${made} long, not ${c.asked}`, did: `${made} long in place of ${c.asked}` };
@@ -102,35 +90,26 @@ function shortfall(model: Model, route: ModelRoute | undefined, c: SettingChange
export const shortfallWords = (model: Pick<ModelDef, "name">, provider: ProviderId, s: readonly Shortfall[]) =>
`${routeLabel(provider)}'s ${shortName(model)} ${listWords(s.map((x) => x.can))}.`;
-/** The run's note: "Replicate's Wan 2.2 A14B made this at 16:9 in place of 1:1 and without the negative prompt." */
+/** "Replicate's Wan 2.2 A14B made this at 16:9 in place of 1:1 and without the negative prompt." */
export const shortfallNote = (model: Pick<ModelDef, "name">, provider: ProviderId, s: readonly Shortfall[]) =>
`${routeLabel(provider)}'s ${shortName(model)} made this ${listWords(s.map((x) => x.did))}.`;
-/**
- * The route a run goes to, the way the server picks it (chooseRoute): the provider asked for (`prefer`) when one of its
- * routes is ready, else the install's preferred aggregator first; of the ready routes, one that makes the length asked
- * (Replicate's Wan 2.2 fast makes 81–121 frames) and carries every LoRA (`fits`), else the first ready one.
- */
+/** Route pick shared by chooseRoute and the composer: `prefer` if ready, then LoRA fit + length, then first ready. */
export function pickRoute<R extends Pick<ModelRoute, "provider" | "map" | "preview">>(
candidates: readonly R[],
o: { ok: (r: R) => boolean; fits?: (r: R) => boolean; seconds?: number; preferred?: string; prefer?: CloudProvider },
): R | undefined {
let routes = !o.preferred || o.preferred === "auto" ? [...candidates] : [...candidates].sort((a, b) => Number(b.provider === o.preferred) - Number(a.provider === o.preferred));
- // A route asked for by name (the person's pick before the run, "Use fal.ai") runs there whenever it can.
if (o.prefer && routes.some((r) => r.provider === o.prefer && o.ok(r))) routes = routes.filter((r) => r.provider === o.prefer);
const fits = o.fits ?? (() => true);
const long = (r: R) => framedLength(r.map?.numFrames ?? r.preview?.numFrames, o.seconds) === undefined;
return routes.find((r) => o.ok(r) && fits(r) && long(r)) ?? routes.find((r) => o.ok(r) && fits(r)) ?? routes.find((r) => o.ok(r) && long(r)) ?? routes.find(o.ok);
}
-/** Operations whose clip length is the one asked (made, not an input video's): the length a route is picked for. */
+/** Same as generations.ts MADE_LENGTH_OPS. */
const MADE_LENGTH = new Set<Operation>(["t2v", "i2v", "flf2v", "ref2v", "extend", "keyframes"]);
-/**
- * The provider a request's run goes to, from the browser's catalog (pickRoute, as the server picks): `ready` says which
- * providers run for this person now; `preferred` is the install's preferred aggregator (Settings). LoRAs and image counts
- * aren't known here, so a run they move elsewhere is said by the server's notes.
- */
+/** Client-side guess of the route chooseRoute picks (no LoRA or image-count checks). */
export function likelyProvider(
model: Model | undefined,
op: Operation | undefined,
@@ -143,19 +122,14 @@ export function likelyProvider(
return pickRoute(routes, { ok: (r) => o.ready(r.provider), seconds, preferred: o.preferred, prefer: req.prefer })?.provider;
}
-/** What the composer says before Run: the words, the route the run goes to, and the one that makes everything as asked. */
export interface RouteNotice {
words: string;
provider: ProviderId;
shortfalls: Shortfall[];
- /** A route the person can use now that makes every setting as asked ("Use fal.ai"). */
+ /** A usable route with no shortfalls. */
instead?: CloudProvider;
}
-/**
- * The notice before a run on `provider`'s route, or null when it makes everything as asked (or nothing else would).
- * `usable`: whether a provider runs for this person now (a key of theirs, a connected provider).
- */
export function routeNotice(model: Model | undefined, op: Operation | undefined, provider: ProviderId | undefined, req: RunRequest, usable: (p: CloudProvider) => boolean): RouteNotice | null {
if (!model || !op || !provider) return null;
const shortfalls = routeShortfalls(model, op, provider, req);
@@ -164,9 +138,8 @@ export function routeNotice(model: Model | undefined, op: Operation | undefined,
return { words: shortfallWords(model, provider, shortfalls), provider, shortfalls, ...(instead && { instead }) };
}
-/** What "Run anyway" remembers for the session: this model's mode, on this route, for each of these settings. */
+/** Session keys for "Run anyway". */
export const anywayKeys = (modelId: string, op: Operation, n: Pick<RouteNotice, "provider" | "shortfalls">) => n.shortfalls.map((s) => `${modelId}|${op}|${n.provider}|${s.setting}`);
-/** Whether "Run anyway" was pressed already this session for every setting this notice names. */
export const anywaySaid = (said: readonly string[], modelId: string, op: Operation, n: Pick<RouteNotice, "provider" | "shortfalls">) =>
anywayKeys(modelId, op, n).every((k) => said.includes(k));
diff --git a/src/lib/catalog/types.ts b/src/lib/catalog/types.ts
index 4552905a..fe3f0da6 100644
--- a/src/lib/catalog/types.ts
+++ b/src/lib/catalog/types.ts
@@ -1290,10 +1290,7 @@ export interface GenerationRequest {
* Unset: the install's engine mode, else the first one connected (your GPU before the cloud).
*/
engine?: Engine;
- /**
- * An account's cloud run on this provider's key when the model is on several ("Run with your Replicate key"): its
- * routes there go first. Without a key for it the run asks for one.
- */
+ /** The provider a cloud run goes on when the model is on several; its route runs while ready (an account without its key is asked for one). */
prefer?: "fal" | "replicate";
/** Chained jobs: where the previous job's image goes among `inputs.images` (one dependency). */
chainFrom?: "first" | "last";
diff --git a/src/server/generations.ts b/src/server/generations.ts
index 28f2827e..2aee9ea1 100644
--- a/src/server/generations.ts
+++ b/src/server/generations.ts
@@ -999,10 +999,8 @@ export function chooseRoute(candidates: ModelRoute[], images = 0, loras: LoraRef
// anything a studio starts inside runAsDemo (a skill's dry run of a studio step, src/server/demo-scope.ts).
if (demo === "on" || forceDemo || inDemoScope()) return { route: routes[0], demo: true };
const takes = (r: ModelRoute) => !r.map?.maxImages || images <= r.map.maxImages;
- // A route asked for by name (the person's pick before the run: "Run anyway" or "Use fal.ai") runs there while it is
- // ready. Otherwise a route that carries every LoRA wins (Replicate's Wan 2.2 takes one per expert, fal's takes a Mix),
- // then one that makes the length asked; otherwise the first ready one runs and the plan's notes say what it changes.
- // (The composer reads the same pick: src/lib/catalog/route-notice.ts.)
+ // A route that carries every LoRA wins (Replicate's Wan 2.2 takes one per expert, fal's takes a Mix), then one
+ // that makes the length asked; otherwise the first ready one runs and the plan's notes say what it changes.
const ok = (r: ModelRoute) => routeReady(r) && takes(r);
const real = pickRoute(routes, { ok, fits: (r) => lorasFit(r, loras), seconds, prefer });
if (real) return { route: real, demo: false };
@@ -1226,7 +1224,6 @@ function prepare(original: GenerationRequest) {
if (access.dropped.length) plan = { ...plan, loras: access.loras, prompt: withoutTriggers(plan.prompt, plan.loras.filter((l) => !access.loras.some((k) => k.file === l.file)), access.loras) };
else if (access.loras.some((l, i) => l !== plan.loras[i])) plan = { ...plan, loras: access.loras };
// A preset can route to another model than the one asked for: its routes that are on (or the switch that's off).
- // The provider the request names (an account's "Run with your fal.ai key", the person's pick before the run).
const prefer = isCloudProvider(worded.prefer) ? worded.prefer : undefined;
const { route, demo } = chooseRoute(triedRoutes(plan.model, offeredRoutes(plan.model, routesFor(plan.model, plan.op, plan.params))), req.inputs?.images?.length ?? 0, plan.loras, seconds, !!worded.demo, prefer);
// Qwen-Image 2.1's Options → Speed loads its speed's LoRA in the graph: that LoRA switched off holds the speed.
@@ -1316,10 +1313,7 @@ function prepare(original: GenerationRequest) {
// split into one job per result just above, so it isn't one.)
const drops = demo ? [] : routeDrops(route, plan.model.id, { negativePrompt: req.negativePrompt, params: plan.params });
if (drops.length) notes.push(`${plan.model.name} on ${provider(route.provider).label} doesn't take ${listWords(drops)}: this run goes without`);
- // What this route makes differently that another route of the model makes as asked (Replicate's Wan 2.2 makes 16:9 or
- // 9:16 and reads no negative prompt; fal's makes 1:1 and reads one): the composer says so before the run, the payload
- // fits the shape to the closest one the route makes, and the run carries a note of it (its notice). A shape or size it
- // fits is said in the notes too (a dropped setting is, just above).
+ // Settings another route of the model would honour: fitted shape/size noted here, all kept as the run's notice.
const shortfalls = demo ? [] : routeShortfalls(plan.model, plan.op, route.provider, { params: req.params, negativePrompt: req.negativePrompt });
for (const s of shortfalls)
if ((s.setting === "aspectRatio" || s.setting === "resolution") && s.did.includes(" in place of "))
@@ -1597,7 +1591,6 @@ export function createGenerations(sent: GenerationRequest, opts: CreateOptions =
const { req, plan, route, demo, providerId, cost } = p;
// Auto keeps its pick with the run: planned again, the run goes to the same model, and its tile names it.
const picked = p.auto ? { ...original, auto: p.auto } : original;
- // What the route made differently (routeShortfalls) stays with the run, said under it once it is made.
const kept = p.notice && !picked.notice?.includes(p.notice) ? { ...picked, notice: [picked.notice, p.notice].filter(Boolean).join(" · ") } : picked;
// A preset whose recipe edited the start frame into an end frame first: two steps (the edit, then the clip).
if (!opts.dependsOn && plan.end) return createEndFrameClip(original, plan.end);
diff --git a/src/server/request-schema.ts b/src/server/request-schema.ts
index f2c475fd..80e63eb6 100644
--- a/src/server/request-schema.ts
+++ b/src/server/request-schema.ts
@@ -129,7 +129,7 @@ export const GenerationRequestSchema = z.object({
engine: z.enum(["open", "cloud"]).optional(),
// "Run without LoRAs": an @element with a trained LoRA goes in as its photos instead.
lorasOff: z.literal(true).optional(),
- // The provider whose key a cloud run goes on when the model is on several ("Run with your Replicate key").
+ // The provider a cloud run goes on when the model is on several; its route runs while ready.
prefer: z.enum(["fal", "replicate"]).optional(),
// A recipe's LoRAs (the evaluation harness, scripts/eval): added after the preset's own. On ComfyUI `file` must
// already be in models/loras (ComfyUI checks the name against its list); a cloud LoRA endpoint takes `url`.
diff --git a/tests/route-drops-note.test.ts b/tests/route-drops-note.test.ts
index e7781a35..5998fef0 100644
--- a/tests/route-drops-note.test.ts
+++ b/tests/route-drops-note.test.ts
@@ -66,12 +66,7 @@ describe("a setting the chosen route has no field for", () => {
});
});
-/**
- * A shape or a setting the route a run goes to can't take, when another route of the model makes it (Wan 2.2 text to
- * video: Replicate's makes 16:9 or 9:16 and reads no negative prompt, fal's makes 1:1 and reads one). The API takes the run
- * either way: on Replicate it is made at the closest shape with the negative prompt left out, and the run says so; a run
- * that names fal.ai (`prefer`, the composer's "Use fal.ai") goes there with everything as asked.
- */
+/** Wan 2.2 t2v: Replicate takes 16:9/9:16 and no negative prompt; fal takes 1:1 and one. */
describe("a run whose route can't honour a setting", () => {
const wan = { feature: "video" as const, modelId: "wan-2-2-a14b-cloud", engine: "cloud" as const, prompt: "a slow dolly past a quiet harbour", negativePrompt: "blur", params: { aspectRatio: "1:1" } };
const sent = (log: { method: string; path: string; body: string }[]) => log.filter((r) => r.method === "POST" && /predictions|wan/.test(r.path)).map((r) => JSON.parse(r.body || "{}"));
diff --git a/tests/route-notice.test.ts b/tests/route-notice.test.ts
index f933543e..721dd275 100644
--- a/tests/route-notice.test.ts
+++ b/tests/route-notice.test.ts
@@ -4,11 +4,7 @@ import { anywayKeys, anywaySaid, likelyProvider, pickRoute, routeNotice, routeSh
import type { ModelDef, ProviderId } from "@/lib/catalog/types";
import { slimModel } from "@/lib/studio-catalog";
-/**
- * The notice before a run whose route can't honour a setting another route of the model takes: Wan 2.2 text to video on
- * Replicate makes 16:9 or 9:16 only and reads no negative prompt, on fal.ai it makes 1:1 and reads one. Said from the
- * browser's catalog (no field maps) the same way the server fits the run, with "Use fal.ai" only where fal.ai runs.
- */
+/** Route notice from the server catalog and the browser's slim catalog. */
const model = (id: string): ModelDef => {
const m = getModel(id);
if (!m) throw new Error(`no ${id}`);