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
Runs: say before the run when its route can't take a setting
Adarsh551f45303dff
diff --git a/src/components/studio/composer.tsx b/src/components/studio/composer.tsxindex 4a10f185..c6d9c91a 100644--- a/src/components/studio/composer.tsx+++ b/src/components/studio/composer.tsx@@ -103,7 +103,8 @@ import { qwen21Note } from "@/lib/qwen21-speed";import { H3_TIER_PARAM, h3TierNote } from "@/lib/gpu/h3-tier";import { formatCost } from "@/lib/format";import { toastError } from "@/lib/refusals";-import { addKeyLabel, billedTo, CLOUD_KEY, cloudVersion, needsKey, paidThrough, startingModel } from "@/lib/your-keys";+import { addKeyLabel, billedTo, CLOUD_KEY, cloudVersion, isCloudProvider, needsKey, paidThrough, startingModel, type CloudProvider } from "@/lib/your-keys";+import { anywayKeys, anywaySaid, likelyProvider, routeNotice } from "@/lib/catalog/route-notice";import { beforeRunTail, gpuBeforeRun, onCloudKey, runOnceOnKey } from "@/lib/before-run";import { BILLING_URL, ISOLATED_ON_GPU_WHY, withKeyAction, type TroubleAction } from "@/lib/diagnose";import { openModelPicker } from "@/lib/open-model-picker";@@ -223,6 +224,26 @@ 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. */+const ANYWAY_KEY = "fuobe:route-anyway";++function readAnyway(): string[] {+ try {+ const v = JSON.parse(sessionStorage.getItem(ANYWAY_KEY) ?? "[]") as unknown;+ return Array.isArray(v) ? v.filter((x): x is string => typeof x === "string") : [];+ } catch {+ return [];+ }+}++function keepAnyway(keys: string[]) {+ try {+ sessionStorage.setItem(ANYWAY_KEY, JSON.stringify(keys.slice(-50)));+ } catch {+ // Storage off (a private window): asked again next time.+ }+}+/** Point at an attachment tile: scroll it into view and pulse its outline. */function pulseSlot(root: HTMLElement | null, key: string, retried = false) {const el = root?.querySelector<HTMLElement>(`[data-slot-key="${key}"]`);@@ -730,6 +751,8 @@ 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).let loraPriceUnknown = false;@@ -755,6 +778,7 @@ export function Composer({ docked }: { docked: boolean }) {});const plan = planGeneration({ ...planned, prompt: planned.prompt || (config.promptOptional ? " " : "") }, catalog.getModel, catalog.getPreset);op = plan.op;+ planModel = plan.model;laid = plan.layout;// A run with LoRAs (a Soul look) goes to the route's LoRA endpoint, which has its own price.const withLoras = plan.loras.length > 0 && routesFor(plan.model, plan.op).some((r) => !!r.loraEndpoint);@@ -921,13 +945,40 @@ 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.+ 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 };+ const routeCheck =+ planModel && op && !placeholdersOn(status?.demoMode)+ ? 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);+ const runAnyway = () => {+ if (!routeCheck || !planModel || !op) return;+ const next = [...new Set([...anyway, ...anywayKeys(planModel.id, op, routeCheck)])];+ setAnyway(next);+ keepAnyway(next);+ submitRef.current(undefined, undefined, undefined, undefined, { prefer: isCloudProvider(routeCheck.provider) ? routeCheck.provider : undefined });+ };+// `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).- const submit = (skip?: unknown, withKey?: TroubleAction, once?: "own" | "pool", signedUp?: boolean): void => {+ // 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.+ const submit = (skip?: unknown, withKey?: TroubleAction, once?: "own" | "pool", signedUp?: boolean, picked?: { prefer?: CloudProvider }): void => {const skipGpu = skip === true;setKeyChoice(false);+ setRouteChoice(false);if (exact) {// An exact orbit: the still filmed along the orbit's numbers (Fly around), priced in its panel.const stop = !exactImage ? "Add a start frame to film an exact orbit" : fly.preview.data?.blocker;@@ -967,6 +1018,10 @@ 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 withRoute = <R extends object>(r: R): R => (route?.prefer ? { ...r, prefer: route.prefer } : r);toast.dismiss("composer-blocker");setPriceNote(null);// A guest (hosted runs on): the draft, its kept files and this run wait for the sign-up, with the price shown; back@@ -991,7 +1046,7 @@ export function Composer({ docked }: { docked: boolean }) {// Open palette lock: the images are recoloured to the palette by a chained step (POST /api/palettes/lock).// (An account's lock runs on this studio's GPUs only: sent there by name.)if (sent.lock) {- const request = withKey ? onCloudKey(sent.request, withKey) : sent.request;+ const request = withKey ? onCloudKey(sent.request, withKey) : withRoute(sent.request);return signature.lock.mutate({ request, colors: sent.lock.colors, ...hosted, ...(poolPrice && !withKey && once !== "own" && { place: "pool" as const }) }, { onError: (e) => toastError(e) });}// If the server's pre-flight stops it (409 gpu-setup), the guided fix that opens can try again, or run it anyway.@@ -1002,7 +1057,7 @@ 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) : withVoiceFirst;+ const onKey = withKey ? onCloudKey(withVoiceFirst, withKey) : withRoute(withVoiceFirst);const body = { ...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@@ -2098,6 +2153,34 @@ 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>+ <div className="flex flex-wrap gap-1.5">+ <button+ type="button"+ onMouseDown={(e) => e.preventDefault()}+ onClick={runAnyway}+ disabled={create.isPending}+ className="inline-flex h-7 w-fit items-center rounded-full bg-highlight px-2.5 text-[12px] font-medium text-highlight-foreground hover:opacity-90 disabled:opacity-70"+ >+ Run anyway+ </button>+ {routeCheck.instead && (+ <button+ type="button"+ onMouseDown={(e) => e.preventDefault()}+ onClick={() => submitRef.current(undefined, undefined, undefined, undefined, { prefer: routeCheck.instead })}+ disabled={create.isPending}+ className="inline-flex h-7 w-fit items-center rounded-full bg-secondary px-2.5 text-[12px] font-medium hover:bg-accent disabled:opacity-70"+ >+ Use {CLOUD_KEY[routeCheck.instead].label}+ </button>+ )}+ </div>+ </div>+ )}{isolatedHere && !gpuDown && (<div role="note" 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>diff --git a/src/lib/catalog/route-notice.ts b/src/lib/catalog/route-notice.tsnew file mode 100644index 00000000..62df2359--- /dev/null+++ b/src/lib/catalog/route-notice.ts@@ -0,0 +1,172 @@+import { listWords } from "@/lib/unavailable";+import { isCloudProvider, type CloudProvider } from "@/lib/your-keys";+import { fittedSettings, tierWords, type SettingChange } from "./fitted";+import { framedLength } from "./payload";+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.+ */++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" };++/** "fal.ai", "Replicate". */+export const routeLabel = (p: ProviderId) => PROVIDER_LABEL[p] ?? p;++/** The model's name without a trailing "(hosted)". */+const shortName = (m: Pick<ModelDef, "name">) => m.name.replace(/\s*\([^)]*\)\s*$/, "") || m.name;++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). */+export interface Shortfall {+ setting: SettingChange["setting"];+ asked: string;+ made: string;+ /** "makes 16:9 or 9:16 clips only", "ignores a negative prompt". */+ can: string;+ /** "at 16:9 in place of 1:1", "without the negative prompt". */+ did: string;+}++export interface RunRequest {+ params?: GenParams;+ negativePrompt?: string;+}++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.+ */+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);+ if (!others.length) return [];+ const mine = changesOn(model, op, provider, req);+ if (!mine.length) return [];+ const theirs = others.map((p) => changesOn(model, op, p, req));+ const route = routesFor(model as ModelDef, op, req.params).find((r) => r.provider === provider);+ return mine.filter((c) => theirs.some((t) => !t.some((x) => x.setting === c.setting))).map((c) => shortfall(model, route, c));+}++function shortfall(model: Model, route: ModelRoute | undefined, c: SettingChange): Shortfall {+ const takes = route && routeTakes(route, model.id);+ const noun = model.kind === "video" ? "clips" : model.kind === "image" ? "pictures" : "results";+ const base = { setting: c.setting, asked: c.asked, made: c.made };+ const same = (list: readonly string[]) => list.some((a) => a.toLowerCase() === c.made.toLowerCase());+ 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}` };+ }+ case "resolution": {+ const list = Array.isArray(takes?.resolutions) ? takes.resolutions.map(tierWords) : [];+ return { ...base, can: list.length ? `makes ${listOr(list)} ${noun} only` : "sets its own quality", did: same(list) ? `at ${c.made} in place of ${c.asked}` : "at its own quality" };+ }+ 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}` };+ }+ case "seed":+ return { ...base, can: "takes no seed", did: "without the seed" };+ case "negativePrompt":+ return { ...base, can: "ignores a negative prompt", did: "without the negative prompt" };+ default:+ return { ...base, can: "makes its own sound", did: "with its own sound" };+ }+}++/** "Replicate's Wan 2.2 A14B makes 16:9 or 9:16 clips only and ignores a negative prompt." */+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." */+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.+ */+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. */+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.+ */+export function likelyProvider(+ model: Model | undefined,+ op: Operation | undefined,+ req: RunRequest & { prefer?: CloudProvider },+ o: { ready: (p: ProviderId) => boolean; preferred?: string },+): ProviderId | undefined {+ if (!model || !op || model.engine === "open") return undefined;+ const routes = routesFor(model as ModelDef, op, req.params);+ const seconds = MADE_LENGTH.has(op) ? req.params?.duration : undefined;+ 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"). */+ 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);+ if (!shortfalls.length) return null;+ const instead = providersFor(model, op, req.params).find((p): p is CloudProvider => p !== provider && isCloudProvider(p) && usable(p) && routeShortfalls(model, op, p, req).length === 0);+ 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. */+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/server/generations.ts b/src/server/generations.tsindex aa0d4608..28f2827e 100644--- a/src/server/generations.ts+++ b/src/server/generations.ts@@ -10,6 +10,7 @@ import { NO_SUBJECT_MESSAGE, withFrontView } from "./any-angle";import { applyMentions } from "@/lib/catalog/elements";import { madeOfRun } from "@/lib/catalog/fitted";import { routeDrops } from "@/lib/catalog/route-takes";+import { pickRoute, routeShortfalls, shortfallNote } from "@/lib/catalog/route-notice";import { listWords } from "@/lib/unavailable";import { migrateRequest, replacedBy } from "@/lib/catalog/replaced";import { directorFieldWords } from "@/lib/catalog/cinema";@@ -981,6 +982,7 @@ export function deleteGeneration(id: string): void {* Imagine Image takes 5 on fal) gives way to one that takes them all, or says so.* `loras` and `seconds` (the clip length asked for) prefer a route that carries every LoRA and makes that* length (Replicate's Wan 2.2 fast renders only 81–121 frames, fal's 17–161).+ * `prefer` (GenerationRequest.prefer) is the provider the request names: its route runs while it is ready.*/export function chooseRoute(candidates: ModelRoute[], images = 0, loras: LoraRef[] = [], seconds?: number, forceDemo = false, prefer?: CloudProvider): { route: ModelRoute; demo: boolean } {// Honour the preferred cloud aggregator (Settings → API configuration) when a model is on several.@@ -997,12 +999,12 @@ 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 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.+ // 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.)const ok = (r: ModelRoute) => routeReady(r) && takes(r);- const long = (r: ModelRoute) => framedLength(r.map?.numFrames, seconds) === undefined;- const real =- routes.find((r) => ok(r) && lorasFit(r, loras) && long(r)) ?? routes.find((r) => ok(r) && lorasFit(r, loras)) ?? routes.find((r) => ok(r) && long(r)) ?? routes.find(ok);+ const real = pickRoute(routes, { ok, fits: (r) => lorasFit(r, loras), seconds, prefer });if (real) return { route: real, demo: false };const short = routes.find(routeReady);if (short) {@@ -1224,7 +1226,8 @@ 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).- const prefer = tenantAccount() && isCloudProvider(worded.prefer) ? worded.prefer : undefined;+ // 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.const tier = route.provider === "comfyui" ? speedLora(route.endpoint, plan.params.extra) : undefined;@@ -1313,6 +1316,15 @@ 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).+ 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 "))+ notes.push(`${plan.model.name} on ${provider(route.provider).label} doesn't make ${s.asked}: this run is made at ${s.made}`);+ const notice = shortfalls.length ? shortfallNote(plan.model, route.provider, shortfalls) : undefined;const providerId: ProviderId = demo ? "mock" : route.provider;// A text step that runs on a local model is free; only Claude costs money.const free = demo || (route.provider === "llm" && !llmUsesClaude(route));@@ -1333,6 +1345,7 @@ function prepare(original: GenerationRequest) {gpu: gpu?.gpu,h3: h3 && { gpuTier: h3.gpuTier, ...(h3.unet && { unet: h3.unet }) },cost: free ? 0 : estimateCost(plan.model, priced, 1, plan.op, withLoras),+ notice,// Auto's pick, which the stored request keeps....(routed.auto && { auto: routed.auto }),};@@ -1583,7 +1596,9 @@ export function createGenerations(sent: GenerationRequest, opts: CreateOptions =const p = waits ? prepare(withChainInputs(original, slotsFor(original, deps.length).map(placeholderFor))) : prepare(original);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 kept = p.auto ? { ...original, auto: p.auto } : original;+ 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);const notes = moved.note ? [moved.note, ...p.notes] : p.notes;diff --git a/tests/route-drops-note.test.ts b/tests/route-drops-note.test.tsindex 66e39a6d..e7781a35 100644--- a/tests/route-drops-note.test.ts+++ b/tests/route-drops-note.test.ts@@ -1,5 +1,5 @@import { afterAll, beforeAll, describe, expect, it } from "vitest";-import { startFakeReplicate, type FakeCloud } from "./helpers/fake-cloud";+import { startFakeFal, startFakeReplicate, type FakeCloud } from "./helpers/fake-cloud";import { tempDir } from "./helpers/temp-dir";/**@@ -18,17 +18,23 @@ const gens = await import("@/server/generations");const { setSetting } = await import("@/server/settings");let rep: FakeCloud;+let fal: FakeCloud;beforeAll(async () => {rep = await startFakeReplicate();+ fal = await startFakeFal();globalThis.__fuobeTestReplicateUrl = rep.url;+ globalThis.__fuobeTestFalUrl = fal.url;rep.keys["owner-rep"] = "good";+ fal.keys["owner-fal"] = "good";setSetting("replicateToken", "owner-rep");setSetting("falKey", "");});afterAll(async () => {globalThis.__fuobeTestReplicateUrl = undefined;+ globalThis.__fuobeTestFalUrl = undefined;globalThis.__fuobeTestDiskFree = undefined;await rep.close();+ await fal.close();});async function settle(id: string, ms = 15_000) {@@ -59,3 +65,61 @@ describe("a setting the chosen route has no field for", () => {expect((g.notes ?? []).join(" ")).not.toMatch(/doesn't take/);});});++/**+ * 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.+ */+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 || "{}"));++ it("runs anyway on the only route ready: the closest shape, no negative prompt, and a note it keeps", async () => {+ setSetting("falKey", "");+ rep.log.length = 0;+ const [g] = gens.createGenerations(wan);+ expect(g.provider).toBe("replicate");+ expect(g.notes).toEqual(+ expect.arrayContaining(["Wan 2.2 A14B (hosted) on Replicate doesn't take a negative prompt: this run goes without", "Wan 2.2 A14B (hosted) on Replicate doesn't make 1:1: this run is made at 16:9"]),+ );+ const done = await settle(g.id);+ expect(done.status).toBe("succeeded");+ expect(done.request.notice).toBe("Replicate's Wan 2.2 A14B made this at 16:9 in place of 1:1 and without the negative prompt.");+ const input = sent(rep.log).at(-1)?.input ?? {};+ expect(input.aspect_ratio).toBe("16:9");+ expect(input).not.toHaveProperty("negative_prompt");+ });++ it("goes to the route the request names, with everything as asked and nothing to say", async () => {+ setSetting("falKey", "owner-fal");+ setSetting("cloudProvider", "replicate");+ try {+ fal.log.length = 0;+ const [g] = gens.createGenerations({ ...wan, prefer: "fal" });+ expect(g.provider).toBe("fal");+ expect((g.notes ?? []).join(" ")).not.toMatch(/doesn't (take|make)/);+ const done = await settle(g.id);+ expect(done.status).toBe("succeeded");+ expect(done.request.notice).toBeUndefined();+ const body = sent(fal.log).at(-1) ?? {};+ expect(body.aspect_ratio).toBe("1:1");+ expect(body.negative_prompt).toBe("blur");+ // Named Replicate ("Run anyway" on it), it stays there although fal.ai is ready and makes 1:1.+ const [r] = gens.createGenerations({ ...wan, prefer: "replicate" });+ expect(r.provider).toBe("replicate");+ expect((await settle(r.id)).request.notice).toMatch(/^Replicate's Wan 2.2 A14B made this at 16:9/);+ } finally {+ setSetting("cloudProvider", "auto");+ setSetting("falKey", "");+ }+ });++ it("says nothing on a shape and settings the route takes", async () => {+ const [g] = gens.createGenerations({ ...wan, negativePrompt: undefined, params: { aspectRatio: "9:16" } });+ expect(g.provider).toBe("replicate");+ expect((g.notes ?? []).join(" ")).not.toMatch(/doesn't (take|make)/);+ expect((await settle(g.id)).request.notice).toBeUndefined();+ });+});diff --git a/tests/route-notice.test.ts b/tests/route-notice.test.tsnew file mode 100644index 00000000..f933543e--- /dev/null+++ b/tests/route-notice.test.ts@@ -0,0 +1,89 @@+import { describe, expect, it } from "vitest";+import { getModel } from "@/lib/catalog";+import { anywayKeys, anywaySaid, likelyProvider, pickRoute, routeNotice, routeShortfalls, shortfallNote } from "@/lib/catalog/route-notice";+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.+ */+const model = (id: string): ModelDef => {+ const m = getModel(id);+ if (!m) throw new Error(`no ${id}`);+ return m;+};+const wan = model("wan-2-2-a14b-cloud");+const slim = slimModel(wan);+const asked = { params: { aspectRatio: "1:1" }, negativePrompt: "blur" };+const only = (...ps: ProviderId[]) => (p: ProviderId) => ps.includes(p);++describe("before a run on a route that can't honour a setting", () => {+ it("names what Replicate's Wan 2.2 can't do, in plain words, and offers fal.ai only when fal.ai runs", () => {+ for (const m of [wan, slim]) {+ const n = routeNotice(m, "t2v", "replicate", asked, only("replicate"));+ expect(n?.words).toBe("Replicate's Wan 2.2 A14B makes 16:9 or 9:16 clips only and ignores a negative prompt.");+ expect(n?.instead).toBeUndefined();+ expect(routeNotice(m, "t2v", "replicate", asked, only("replicate", "fal"))?.instead).toBe("fal");+ }+ });++ it("says one thing when only one is asked", () => {+ expect(routeNotice(slim, "t2v", "replicate", { params: { aspectRatio: "1:1" } }, () => true)?.words).toBe("Replicate's Wan 2.2 A14B makes 16:9 or 9:16 clips only.");+ expect(routeNotice(slim, "t2v", "replicate", { params: { aspectRatio: "9:16" }, negativePrompt: "blur" }, () => true)?.words).toBe(+ "Replicate's Wan 2.2 A14B ignores a negative prompt.",+ );+ });++ it("says nothing when the route makes everything as asked, or no route of the model would", () => {+ expect(routeNotice(slim, "t2v", "replicate", { params: { aspectRatio: "16:9" } }, () => true)).toBeNull();+ expect(routeNotice(slim, "t2v", "fal", asked, () => true)).toBeNull();+ // 1080p: no route of Wan 2.2 makes it (the picker says so), so it isn't Replicate's to say.+ expect(routeShortfalls(slim, "t2v", "replicate", { params: { resolution: "1080p" } })).toEqual([]);+ // A blank negative prompt asks for nothing.+ expect(routeNotice(slim, "t2v", "replicate", { params: {}, negativePrompt: " " }, () => true)).toBeNull();+ });++ it("a longer clip than Replicate's frames make, which fal.ai makes as asked", () => {+ const s = routeShortfalls(slim, "t2v", "replicate", { params: { duration: 3 } });+ expect(s.map((x) => [x.setting, x.can])).toEqual([["duration", "makes this 5s long, not 3s"]]);+ });++ it("the run's note says what was made, in the past tense", () => {+ const s = routeShortfalls(wan, "t2v", "replicate", asked);+ expect(shortfallNote(wan, "replicate", s)).toBe("Replicate's Wan 2.2 A14B made this at 16:9 in place of 1:1 and without the negative prompt.");+ });++ it("works for any model whose routes take different settings (Nano Banana Pro's seed on Replicate)", () => {+ const nano = slimModel(model("nano-banana-pro"));+ expect(routeNotice(nano, "t2i", "replicate", { params: { seed: 7 } }, () => true)).toMatchObject({ words: "Replicate's Nano Banana Pro takes no seed.", instead: "fal" });+ });++ it("Run anyway is remembered per model, mode, route and setting", () => {+ const n = routeNotice(slim, "t2v", "replicate", asked, () => true)!;+ const said = anywayKeys(wan.id, "t2v", n);+ expect(anywaySaid(said, wan.id, "t2v", n)).toBe(true);+ // The same shape asked again: still said. A new setting the route can't take: asked again.+ expect(anywaySaid(said, wan.id, "t2v", routeNotice(slim, "t2v", "replicate", { params: { aspectRatio: "1:1" } }, () => true)!)).toBe(true);+ expect(anywaySaid(said, wan.id, "t2v", routeNotice(slim, "t2v", "replicate", { params: { duration: 3 } }, () => true)!)).toBe(false);+ });+});++describe("where the run goes, as the server picks", () => {+ it("the first ready route, the preferred aggregator first, and the one the request names", () => {+ expect(likelyProvider(slim, "t2v", asked, { ready: only("replicate") })).toBe("replicate");+ expect(likelyProvider(slim, "t2v", asked, { ready: only("replicate", "fal") })).toBe("fal");+ expect(likelyProvider(slim, "t2v", asked, { ready: only("replicate", "fal"), preferred: "replicate" })).toBe("replicate");+ expect(likelyProvider(slim, "t2v", { ...asked, prefer: "fal" }, { ready: only("replicate", "fal"), preferred: "replicate" })).toBe("fal");+ // Named but not ready: the next ready one.+ expect(likelyProvider(slim, "t2v", { ...asked, prefer: "fal" }, { ready: only("replicate") })).toBe("replicate");+ expect(likelyProvider(slim, "t2v", asked, { ready: () => false })).toBeUndefined();+ });++ it("a route that makes the length asked wins over the preferred one", () => {+ // 3 s: Replicate's Wan 2.2 makes 81–121 frames (about 5 s), fal's makes 3 s.+ expect(likelyProvider(slim, "t2v", { params: { duration: 3 } }, { ready: () => true, preferred: "replicate" })).toBe("fal");+ expect(pickRoute(wan.routes.filter((r) => r.op === "t2v"), { ok: () => true, seconds: 3, preferred: "replicate", prefer: "replicate" })?.provider).toBe("replicate");+ });+});