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.

Settings follow what the run's routes send

Adarsh23601a2ef875
diff --git a/src/components/canvas/nodes.tsx b/src/components/canvas/nodes.tsx
index 5735df78..32d61e44 100644
--- a/src/components/canvas/nodes.tsx
+++ b/src/components/canvas/nodes.tsx
@@ -114,7 +114,9 @@ import {
type PortDef,
type PortType,
} from "@/lib/catalog/canvas";
-import { OPERATION_LABELS, type Engine, type MediaKind, type ModelDef, type OutputFile } from "@/lib/catalog/types";
+import { OPERATION_LABELS, type Engine, type MediaKind, type ModelDef, type Operation, type OutputFile } from "@/lib/catalog/types";
+import { OPERATION_PLACE, opTakes, settingUnavailable } from "@/lib/catalog/route-takes";
+import { settingsShape } from "@/lib/composer";
import { formatCost } from "@/lib/format";
import { dubResult, languageStage, type DubSessionView, type DubStage } from "@/lib/av/dub";
import { DUB_LANGUAGES, supportsTarget } from "@/lib/av/languages";
@@ -594,7 +596,22 @@ function Results({ id, r, compact }: { id: string; r: NodeResults; compact?: boo
* A compact select. Its options mount only while it's open (a closed Radix Select still renders
* every item, which adds up to thousands on a big board); the trigger shows the value itself.
*/
-function OptionSelect<T extends string | number>({ value, options, onChange, label, format }: { value: T | undefined; options: T[]; onChange: (v: T) => void; label: string; format?: (v: T) => string }) {
+function OptionSelect<T extends string | number>({
+ value,
+ options,
+ onChange,
+ label,
+ format,
+ unavailable,
+}: {
+ value: T | undefined;
+ options: T[];
+ onChange: (v: T) => void;
+ label: string;
+ format?: (v: T) => string;
+ /** Why a value can't be made by this node's run (route-takes.ts): listed, muted, with the reason, and never picked. */
+ unavailable?: (v: T) => string | undefined;
+}) {
const [open, setOpen] = useState(false);
const text = (v: T) => (format ? format(v) : String(v));
return (
@@ -604,22 +621,35 @@ function OptionSelect<T extends string | number>({ value, options, onChange, lab
</SelectTrigger>
{open && (
<SelectContent className="max-h-72">
- {options.map((o) => (
- <SelectItem key={String(o)} value={String(o)} className="text-[13px]">
- {text(o)}
- </SelectItem>
- ))}
+ {options.map((o) => {
+ const why = unavailable?.(o);
+ return (
+ <SelectItem key={String(o)} value={String(o)} disabled={!!why} className="text-[13px]">
+ {text(o)}
+ {why && <span className="text-[11px] text-muted-foreground"> · {why}</span>}
+ </SelectItem>
+ );
+ })}
</SelectContent>
)}
</Select>
);
}
-function ModelOptions({ id, model, data }: { id: string; model: ModelDef; data: CanvasNodeData }) {
+function ModelOptions({ id, model, data, runOp }: { id: string; model: ModelDef; data: CanvasNodeData; runOp?: Operation }) {
const actions = useEditorActions();
const p = data.params ?? {};
const o = model.options;
const d = model.defaults ?? {};
+ // The operation the node runs (its own, or the one Auto resolves to from what is connected): a setting it has no field for
+ // (a start frame's shape, an edit that follows image 1) isn't offered, and a value its routes don't make says so.
+ const op = data.op ?? runOp;
+ const shape = settingsShape(model, op, model.kind, true, p);
+ const takes = opTakes(model, op);
+ const off = (setting: "aspect" | "resolution" | "duration") => (v: string | number) => {
+ const u = settingUnavailable(model, op, setting, v, takes);
+ return u ? `not ${(op && OPERATION_PLACE[op]) || "here"}` : undefined;
+ };
const set = (patch: Partial<NonNullable<CanvasNodeData["params"]>>) => actions.update(id, { params: { ...p, ...patch } });
const extra = (p.extra ?? {}) as Record<string, unknown>;
const setExtra = (param: string, v?: string | number) => {
@@ -630,9 +660,9 @@ function ModelOptions({ id, model, data }: { id: string; model: ModelDef; data:
};
const text = model.kind === "text";
const items: React.ReactNode[] = [];
- if (o.aspectRatios?.length) items.push(<OptionSelect key="ar" label="Aspect ratio" value={p.aspectRatio ?? d.aspectRatio} options={o.aspectRatios} onChange={(v) => set({ aspectRatio: v })} />);
- if (o.durations?.length && o.durations.length > 1) items.push(<OptionSelect key="dur" label="Duration" value={p.duration ?? d.duration} options={o.durations} onChange={(v) => set({ duration: v })} format={(v) => `${v}s`} />);
- if (o.resolutions?.length && o.resolutions.length > 1) items.push(<OptionSelect key="res" label="Quality" value={p.resolution ?? d.resolution} options={o.resolutions} onChange={(v) => set({ resolution: v })} />);
+ if (shape.aspect) items.push(<OptionSelect key="ar" label="Aspect ratio" value={p.aspectRatio ?? d.aspectRatio} options={shape.aspect} onChange={(v) => set({ aspectRatio: v })} unavailable={off("aspect")} />);
+ if (shape.duration) items.push(<OptionSelect key="dur" label="Duration" value={p.duration ?? d.duration} options={shape.duration} onChange={(v) => set({ duration: v })} format={(v) => `${v}s`} unavailable={off("duration")} />);
+ if (shape.resolution) items.push(<OptionSelect key="res" label="Quality" value={p.resolution ?? d.resolution} options={shape.resolution} onChange={(v) => set({ resolution: v })} unavailable={off("resolution")} />);
if ((o.maxOutputs ?? 1) > 1) items.push(<OptionSelect key="n" label="Count" value={p.numOutputs ?? 1} options={Array.from({ length: Math.min(4, o.maxOutputs!) }, (_, i) => i + 1)} onChange={(v) => set({ numOutputs: v })} format={(v) => `×${v}`} />);
if (o.voices?.length) items.push(<OptionSelect key="voice" label="Voice" value={p.voice ?? d.voice ?? o.voices[0].id} options={o.voices.map((v) => v.id)} onChange={(v) => set({ voice: v })} format={(v) => o.voices!.find((x) => x.id === v)?.name ?? v} />);
// A text model writes; picking a language makes it translate (Auto), and "Don't translate" goes back to writing.
@@ -669,7 +699,7 @@ function ModelOptions({ id, model, data }: { id: string; model: ModelDef; data:
</button>,
);
if (o.sliders?.length) items.push(<div key="sliders" className={NO_DRAG}><SlidersChip model={model} values={extra} onChange={setExtra} /></div>);
- if (o.controls?.length) items.push(<div key="controls" className={NO_DRAG}><ControlsChip controls={o.controls} values={extra} onChange={setExtra} op={data.op} /></div>);
+ if (o.controls?.length) items.push(<div key="controls" className={NO_DRAG}><ControlsChip controls={o.controls} values={extra} onChange={setExtra} op={op} /></div>);
if (!items.length) return null;
return <div className={cn("flex flex-wrap gap-1 [&_button]:h-7 [&_button]:text-[12px]", NO_DRAG)}>{items}</div>;
}
@@ -919,7 +949,7 @@ const GeneratorNode = memo(function GeneratorNode({ id, type: flowType, data, se
className={cn("field-sizing-content max-h-36 min-h-14 w-full resize-none rounded-lg bg-muted px-2.5 py-2 text-[13px] leading-snug outline-none placeholder:text-subtle-foreground focus:ring-2 focus:ring-brand-faint", NO_DRAG)}
/>
)}
- {model && !g.readOnly && type !== "concat" && <ModelOptions id={id} model={model} data={data} />}
+ {model && !g.readOnly && type !== "concat" && <ModelOptions id={id} model={model} data={data} runOp={v.op} />}
{v.rows && (
<p className="flex items-center gap-1.5 text-[12px] text-muted-foreground">
<Table className="size-3.5 shrink-0" /> Runs once per table row: {v.rows === 1 ? "1 run" : `${v.rows} runs`}
diff --git a/src/components/studio/settings-panel.tsx b/src/components/studio/settings-panel.tsx
index ace1f2f9..3b23bcc2 100644
--- a/src/components/studio/settings-panel.tsx
+++ b/src/components/studio/settings-panel.tsx
@@ -15,6 +15,9 @@ import { colormapLabel, durationLabel, formatOf, hiddenChanges, MATTE_OUTPUT_LAB
import { ratioValue } from "@/lib/format";
import { matchSpokenLanguage, spokenLanguageName, spokenLanguageOptions } from "@/lib/speech-languages";
import { cn } from "@/lib/utils";
+import { UNAVAILABLE_OPTION, UnavailableNote, useUnavailableNote } from "@/components/ui/unavailable";
+import { opTakes, settingUnavailable, type OpTakes } from "@/lib/catalog/route-takes";
+import type { Unavailable } from "@/lib/unavailable";
import { SliderControls } from "./audio-controls";
import { Chip } from "./chip";
import { radioKeys, radioTab } from "./radio-keys";
@@ -39,27 +42,94 @@ function Section({ label, children, id }: { label: string; children: React.React
);
}
-function Segmented<T extends string | number>({ label, options, value, onChange, format = (v) => String(v) }: { label: string; options: T[]; value: T; onChange: (v: T) => void; format?: (v: T) => string }) {
+function Segmented<T extends string | number>({
+ label,
+ options,
+ value,
+ onChange,
+ format = (v) => String(v),
+ unavailable,
+}: {
+ label: string;
+ options: T[];
+ value: T;
+ onChange: (v: T) => void;
+ format?: (v: T) => string;
+ /** Why a value can't be had with this model and operation (src/lib/unavailable.ts): it stays in view, muted, and says why. */
+ unavailable?: (v: T) => Unavailable | undefined;
+}) {
+ const opts = options.map((o) => ({ value: o, unavailable: unavailable?.(o) }));
+ const note = useUnavailableNote(opts);
// Nothing selected (an unexpected value): the first option takes the Tab stop.
const current = options.includes(value) ? value : options[0];
+ // The value on show is one this run can't make (a model's default, a choice kept from another model): said at once.
+ const held = unavailable?.(value);
return (
- <div role="radiogroup" aria-label={label} onKeyDown={radioKeys} className="flex flex-wrap gap-0.5 rounded-full bg-muted p-0.5">
- {options.map((o) => (
- <button
- key={String(o)}
- type="button"
- role="radio"
- aria-checked={value === o}
- tabIndex={radioTab(current === o)}
- onClick={() => onChange(o)}
- className={cn(
- "h-7 min-w-11 flex-1 rounded-full px-2.5 text-[13px] font-medium whitespace-nowrap text-muted-foreground tabular-nums transition outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/50",
- value === o && "bg-background text-foreground shadow-soft",
- )}
- >
- {format(o)}
- </button>
- ))}
+ <div>
+ <div role="radiogroup" aria-label={label} onKeyDown={radioKeys} className="flex flex-wrap gap-0.5 rounded-full bg-muted p-0.5">
+ {opts.map((o) => {
+ const off = note.isUnavailable(o);
+ return (
+ <button
+ key={String(o.value)}
+ type="button"
+ role="radio"
+ aria-checked={value === o.value && !off}
+ tabIndex={radioTab(current === o.value)}
+ onClick={() => note.press(o, onChange)}
+ {...note.optionProps(o)}
+ className={cn(
+ "h-7 min-w-11 flex-1 rounded-full px-2.5 text-[13px] font-medium whitespace-nowrap text-muted-foreground tabular-nums transition outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/50",
+ value === o.value && !off && "bg-background text-foreground shadow-soft",
+ off && UNAVAILABLE_OPTION,
+ )}
+ >
+ {format(o.value)}
+ </button>
+ );
+ })}
+ </div>
+ <UnavailableNote {...note.noteProps} reason={note.reason ?? held} />
+ </div>
+ );
+}
+
+/** The aspect ratio grid: a shape this run can't make stays in view, muted, and pressing it says why with the closest one. */
+function AspectChoices({ options, value, onChange, unavailable }: { options: string[]; value: string; onChange: (v: string) => void; unavailable: (v: string) => Unavailable | undefined }) {
+ const opts = options.map((o) => ({ value: o, unavailable: unavailable(o) }));
+ const note = useUnavailableNote(opts);
+ const held = unavailable(value);
+ return (
+ <div>
+ <div role="radiogroup" aria-label="Aspect ratio" onKeyDown={radioKeys} className="grid grid-cols-4 gap-1 sm:grid-cols-5">
+ {opts.map((o) => {
+ const off = note.isUnavailable(o);
+ const sel = value === o.value && !off;
+ return (
+ <button
+ key={o.value}
+ type="button"
+ role="radio"
+ aria-checked={sel}
+ tabIndex={radioTab(value === o.value)}
+ onClick={() => note.press(o, onChange)}
+ {...note.optionProps(o)}
+ className={cn(
+ "flex h-14 flex-col items-center justify-center gap-1.5 rounded-lg text-[11px] font-medium text-muted-foreground transition-colors outline-none hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring/50",
+ sel && "bg-brand-faint text-brand-text hover:bg-brand-faint-hover",
+ off && UNAVAILABLE_OPTION,
+ off && "hover:bg-transparent",
+ )}
+ >
+ <span className="grid h-5 place-items-center">
+ <RatioGlyph ratio={o.value} />
+ </span>
+ {o.value === "auto" ? "Auto" : o.value}
+ </button>
+ );
+ })}
+ </div>
+ <UnavailableNote {...note.noteProps} reason={note.reason ?? held} />
</div>
);
}
@@ -119,18 +189,33 @@ function SpokenLanguage({ codes, value, onChange }: { codes: string[]; value?: s
);
}
-function Toggle({ label, hint, checked, onChange, children }: { label: string; hint: string; checked: boolean; onChange: (v: boolean) => void; children?: React.ReactNode }) {
+function Toggle({
+ label,
+ hint,
+ checked,
+ onChange,
+ children,
+ unavailable,
+}: {
+ label: string;
+ hint: string;
+ checked: boolean;
+ onChange: (v: boolean) => void;
+ children?: React.ReactNode;
+ /** Why the switch can't change anything with this model here: it is off-limits and says so in place of its hint. */
+ unavailable?: string;
+}) {
const id = useId();
return (
<div className="flex items-center gap-3 py-2">
<div className="min-w-0 flex-1">
- <label htmlFor={id} className="block cursor-pointer">
- <span className="block text-[13px] font-medium">{label}</span>
- <span className="block text-[12px] leading-snug text-muted-foreground">{hint}</span>
+ <label htmlFor={id} className={cn("block", unavailable ? "cursor-not-allowed" : "cursor-pointer")}>
+ <span className={cn("block text-[13px] font-medium", unavailable && "text-muted-foreground")}>{label}</span>
+ <span className="block text-[12px] leading-snug text-muted-foreground">{unavailable ?? hint}</span>
</label>
{children}
</div>
- <Switch id={id} checked={checked} onCheckedChange={onChange} />
+ <Switch id={id} checked={checked} disabled={!!unavailable} onCheckedChange={onChange} />
</div>
);
}
@@ -241,35 +326,27 @@ function SettingsBody({ model, op, shape, params: p, setP, setExtra, negativePro
const [advanced, setAdvanced] = useState(p.seed !== undefined || !!negativePrompt);
// "Rewrite my prompt now" uses the install's AI helper, which guests and accounts can't call.
const visitor = useLikelyVisitor();
+ // What this operation's routes send (route-takes.ts): a ratio, size or length they don't make stays in view, muted, and
+ // says why with the closest one they do; a seed, negative prompt or sound switch they don't read says so.
+ const takes: OpTakes = useMemo(() => opTakes(model, op), [model, op]);
+ const why = (setting: "aspect" | "resolution" | "duration", v: string | number, apply: (x: string | number) => void, label = (x: string | number) => String(x)): Unavailable | undefined => {
+ if (!model) return undefined;
+ const u = settingUnavailable(model, op, setting, v, takes);
+ if (!u) return undefined;
+ const instead = u.instead;
+ return { why: u.why, ...(instead !== undefined && { fix: { label: `Use ${label(instead)}`, run: () => apply(instead) } }) };
+ };
return (
<div className="space-y-4">
{extras && <div className="flex flex-wrap gap-1.5 sm:hidden">{extras}</div>}
{shape.aspect && (
<Section label="Aspect ratio">
- <div role="radiogroup" aria-label="Aspect ratio" onKeyDown={radioKeys} className="grid grid-cols-4 gap-1 sm:grid-cols-5">
- {shape.aspect.map((o) => {
- const sel = (p.aspectRatio ?? d.aspectRatio ?? shape.aspect![0]) === o;
- return (
- <button
- key={o}
- type="button"
- role="radio"
- aria-checked={sel}
- tabIndex={radioTab(sel)}
- onClick={() => setP({ aspectRatio: o })}
- className={cn(
- "flex h-14 flex-col items-center justify-center gap-1.5 rounded-lg text-[11px] font-medium text-muted-foreground transition-colors outline-none hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring/50",
- sel && "bg-brand-faint text-brand-text hover:bg-brand-faint-hover",
- )}
- >
- <span className="grid h-5 place-items-center">
- <RatioGlyph ratio={o} />
- </span>
- {o === "auto" ? "Auto" : o}
- </button>
- );
- })}
- </div>
+ <AspectChoices
+ options={shape.aspect}
+ value={p.aspectRatio ?? d.aspectRatio ?? shape.aspect[0]}
+ onChange={(o) => setP({ aspectRatio: o })}
+ unavailable={(o) => why("aspect", o, (x) => setP({ aspectRatio: String(x) }), (x) => (x === "auto" ? "Auto" : String(x)))}
+ />
</Section>
)}
{shape.formats && (
@@ -284,6 +361,7 @@ function SettingsBody({ model, op, shape, params: p, setP, setExtra, negativePro
options={shape.resolution}
value={p.resolution ?? d.resolution ?? shape.resolution[0]}
onChange={(v) => setP({ resolution: v })}
+ unavailable={(v) => why("resolution", v, (x) => setP({ resolution: String(x) }))}
/>
{/* MiniMax H3 (open) at 2K finishes with Open-H3 Regenerate: a visitor runs it on its own GPU (own-setup.ts). */}
{visitor && model && shape.resolution.find((r) => wantsH3TwoK(model.id, r)) && (
@@ -313,7 +391,14 @@ function SettingsBody({ model, op, shape, params: p, setP, setExtra, negativePro
)}
{shape.duration && (
<Section label="Duration">
- <Segmented label="Duration" options={shape.duration} value={p.duration ?? d.duration ?? shape.duration[0]} onChange={(v) => setP({ duration: v })} format={durationLabel} />
+ <Segmented
+ label="Duration"
+ options={shape.duration}
+ value={p.duration ?? d.duration ?? shape.duration[0]}
+ onChange={(v) => setP({ duration: v })}
+ format={durationLabel}
+ unavailable={(v) => why("duration", v, (x) => setP({ duration: Number(x) }), (x) => durationLabel(Number(x)))}
+ />
</Section>
)}
{shape.count && (
@@ -350,7 +435,13 @@ function SettingsBody({ model, op, shape, params: p, setP, setExtra, negativePro
<Toggle label="Draft" hint={p.draft ? "Cheap 480p take — finish the one you like in 1080p" : "Preview at 480p first, then render the keeper in 1080p"} checked={!!p.draft} onChange={(v) => setP({ draft: v })} />
)}
{shape.audio && (
- <Toggle label="Audio" hint={p.generateAudio === false ? "Silent video (cheaper)" : "Native sound, music and dialogue"} checked={p.generateAudio !== false} onChange={(v) => setP({ generateAudio: v })} />
+ <Toggle
+ label="Audio"
+ hint={p.generateAudio === false ? "Silent video (cheaper)" : "Native sound, music and dialogue"}
+ checked={p.generateAudio !== false}
+ onChange={(v) => setP({ generateAudio: v })}
+ unavailable={!takes.audio && model ? `${model.name} sets its own sound here: this switch can't change it` : undefined}
+ />
)}
{shape.enhance && (
<Toggle label="Enhance prompt" hint="Rewrites your prompt with more detail before it runs" checked={!!p.enhancePrompt} onChange={(v) => setP({ enhancePrompt: v })}>
@@ -382,12 +473,14 @@ function SettingsBody({ model, op, shape, params: p, setP, setExtra, negativePro
<div className="space-y-1.5">
<div className="flex items-center justify-between text-[12px] text-muted-foreground">
<span>Seed</span>
- <label className="flex items-center gap-2">
+ <label className={cn("flex items-center gap-2", !takes.seed && "cursor-not-allowed opacity-60")}>
Random
- <Switch checked={p.seed === undefined} onCheckedChange={(r) => setP({ seed: r ? undefined : Math.floor(Math.random() * 1e9) })} aria-label="Random seed" />
+ <Switch checked={!takes.seed || p.seed === undefined} disabled={!takes.seed} onCheckedChange={(r) => setP({ seed: r ? undefined : Math.floor(Math.random() * 1e9) })} aria-label="Random seed" />
</label>
</div>
- {p.seed !== undefined && (
+ {/* A model that takes no seed here (Nano Banana Pro, Seedance 2.5): every run is new, and it says so. */}
+ {!takes.seed && model && <p className="text-[12px] leading-snug text-muted-foreground">{model.name} picks its own seed here, so each run comes out new.</p>}
+ {takes.seed && p.seed !== undefined && (
<div className="flex gap-1.5">
<SeedInput value={p.seed} onChange={(seed) => setP({ seed })} />
<Button variant="secondary" size="icon" className="size-8" onClick={() => setP({ seed: Math.floor(Math.random() * 1e9) })} aria-label="New random seed">
@@ -403,10 +496,15 @@ function SettingsBody({ model, op, shape, params: p, setP, setExtra, negativePro
value={negativePrompt}
onChange={(e) => setNegativePrompt(e.target.value)}
rows={3}
+ disabled={!takes.negativePrompt}
aria-label="Negative prompt"
placeholder="blurry, low quality, extra fingers…"
- className="w-full resize-none rounded-md border bg-background px-2 py-1.5 text-sm outline-none focus:border-primary"
+ className="w-full resize-none rounded-md border bg-background px-2 py-1.5 text-sm outline-none focus:border-primary disabled:cursor-not-allowed disabled:opacity-60"
/>
+ {/* The route sends no negative prompt (Qwen Image Edit on fal, Kandinsky 6.0): said, never dropped without a word. */}
+ {!takes.negativePrompt && model && (
+ <p className="text-[12px] leading-snug text-muted-foreground">{model.name} doesn&apos;t read a negative prompt here: describe only what you want in the prompt.</p>
+ )}
</div>
)}
{model && (
diff --git a/src/lib/catalog/plan.ts b/src/lib/catalog/plan.ts
index 5c391c16..14348dfe 100644
--- a/src/lib/catalog/plan.ts
+++ b/src/lib/catalog/plan.ts
@@ -21,6 +21,7 @@ import { cloudPath, fitLoras, gated, localOnly, loraCapacity, needsToken, routeL
import { anglesPrompt, anglesWords, ANGLES_ORIGINAL } from "./open-tools";
import { qmaRunPrompt } from "@/lib/qma";
import { askedSize, clipWords, numFramesValue, sizeValue } from "./payload";
+import { oneEachCall } from "./route-takes";
import { characterScale, CINEMA_CROP, soulKind, soulMegapixels, soulRecipe, soulSize, type SoulOverlay } from "./soul";
import { computeDimensions, fitCanvas } from "@/lib/comfy";
import { carriesLayout, flux3Boxes, flux3Caption, layoutCompilerFor, LAYOUT_MAX_SIDE, LAYOUT_MULTIPLE, LAYOUT_PARAM, readLayout, validateLayout, type LayoutDraft, type LayoutFormat } from "@/lib/layout-prompt";
@@ -681,7 +682,9 @@ export function planGeneration(
params = controlSets(model, params);
const requested = Math.max(1, Math.min(8, params.numOutputs ?? 1));
- const maxPerJob = Math.max(1, model.options.maxOutputs ?? 1);
+ // A route with no count field makes one result a call (Nano Banana Pro, Qwen Image Edit): each result is its own job, never
+ // a count the API never sees.
+ const maxPerJob = oneEachCall(model, op) ? 1 : Math.max(1, model.options.maxOutputs ?? 1);
const perJobOutputs = Math.min(requested, maxPerJob);
const jobs = Math.ceil(requested / perJobOutputs);
return {
diff --git a/src/lib/catalog/route-takes.ts b/src/lib/catalog/route-takes.ts
new file mode 100644
index 00000000..ad9e0536
--- /dev/null
+++ b/src/lib/catalog/route-takes.ts
@@ -0,0 +1,166 @@
+import type { FieldMap, ModelDef, ModelRoute, Operation, RouteTakes } from "./types";
+
+/*
+ * What a run's settings reach: a hosted route sends only the fields its map names, and fits an aspect ratio, a size or a
+ * length to the list it takes (EnumField.accepts, DurationField.accepts). The composer's pickers read this so a choice the
+ * route would drop or change looks unavailable, and says so, before the run (src/lib/unavailable.ts).
+ *
+ * The browser's catalog has no field maps (slimModel): it keeps this summary as route.takes. ComfyUI graphs and the
+ * routes Fuobe builds itself (Soul, Cinema, Mixed Media, Animation: their sizes are written by the plan) take everything.
+ */
+
+/** Operations whose result keeps the clip it is given: its shape, size and length are the clip's. */
+const FOLLOWS_CLIP = new Set<Operation>(["extend", "v2v", "video-swap", "video-insert", "remove-object", "finalize"]);
+
+const listOf = (f: FieldMap["aspectRatio"]): string[] | undefined => (f && typeof f !== "string" && f.accepts?.length ? [...f.accepts] : undefined);
+
+/** A route's summary from its field map; undefined when it takes every setting (no map, or a size the plan writes). */
+export function takesFromMap(route: Pick<ModelRoute, "op" | "provider" | "map">, modelId: string): RouteTakes | undefined {
+ const m = route.map;
+ if (!m || route.provider === "comfyui" || modelId.startsWith("fuobe-")) return undefined;
+ const lengths = (m.duration as { accepts?: number[] } | undefined)?.accepts;
+ const follows = FOLLOWS_CLIP.has(route.op);
+ const out: RouteTakes = {};
+ if (!m.aspectRatio && !m.size) out.aspectRatios = false;
+ else if (!m.size && listOf(m.aspectRatio)) out.aspectRatios = listOf(m.aspectRatio);
+ if (!m.resolution && !m.size && !m.upscaleFactor) out.resolutions = false;
+ else if (!m.size && !m.upscaleFactor && listOf(m.resolution)) out.resolutions = listOf(m.resolution);
+ if (!m.duration && !m.numFrames && !m.multiShot && follows) out.durations = false;
+ else if (lengths?.length) out.durations = [...lengths];
+ if (!m.seed) out.seed = false;
+ if (!m.negativePrompt) out.negativePrompt = false;
+ if (!m.generateAudio) out.audio = false;
+ if (!m.numOutputs) out.outputs = false;
+ return Object.keys(out).length ? out : undefined;
+}
+
+/** A route's summary on the server (its map) or in the browser (route.takes). */
+export function routeTakes(route: ModelRoute, modelId: string): RouteTakes | undefined {
+ return route.map ? takesFromMap(route, modelId) : route.takes;
+}
+
+/** Whether every route of the operation makes one result a call (no count field): several results are several jobs. */
+export function oneEachCall(model: Pick<ModelDef, "id" | "routes">, op: Operation): boolean {
+ const routes = model.routes.filter((r) => r.op === op);
+ return routes.length > 0 && routes.every((r) => routeTakes(r, model.id)?.outputs === false);
+}
+
+/** What an operation's routes take together (a run goes to one of them): a value any of them takes counts. */
+export interface OpTakes {
+ /** The ratios / sizes / lengths they take; undefined = any. */
+ aspectRatios?: string[];
+ resolutions?: string[];
+ durations?: number[];
+ /** False when none of them sends the setting at all. */
+ aspect: boolean;
+ resolution: boolean;
+ duration: boolean;
+ seed: boolean;
+ negativePrompt: boolean;
+ audio: boolean;
+}
+
+const ALL: OpTakes = { aspect: true, resolution: true, duration: true, seed: true, negativePrompt: true, audio: true };
+
+export function opTakes(model: Pick<ModelDef, "id" | "routes"> | undefined, op: Operation | undefined): OpTakes {
+ if (!model || !op) return ALL;
+ const routes = model.routes.filter((r) => r.op === op);
+ if (!routes.length) return ALL;
+ const each = routes.map((r) => routeTakes(r, model.id));
+ // One route that takes everything (a GPU graph, a route with no limits) takes everything for the operation.
+ if (each.some((t) => !t)) return ALL;
+ const ts = each as RouteTakes[];
+ const any = <K extends "aspectRatios" | "resolutions" | "durations">(k: K) => ts.some((t) => t[k] !== false);
+ const list = <T extends string | number>(k: "aspectRatios" | "resolutions" | "durations"): T[] | undefined => {
+ const sent = ts.filter((t) => t[k] !== false);
+ if (!sent.length || sent.some((t) => t[k] === undefined)) return undefined;
+ return [...new Set(sent.flatMap((t) => t[k] as T[]))];
+ };
+ return {
+ aspect: any("aspectRatios"),
+ resolution: any("resolutions"),
+ duration: any("durations"),
+ aspectRatios: list<string>("aspectRatios"),
+ resolutions: list<string>("resolutions"),
+ durations: list<number>("durations"),
+ seed: ts.some((t) => t.seed !== false),
+ negativePrompt: ts.some((t) => t.negativePrompt !== false),
+ audio: ts.some((t) => t.audio !== false),
+ };
+}
+
+/** Whether a route list takes a value (in any case: "1K" and "1k"). */
+export function takesValue(list: readonly (string | number)[] | undefined, v: string | number): boolean {
+ return !list || list.some((x) => String(x).toLowerCase() === String(v).toLowerCase());
+}
+
+/** Where an operation's own limits apply, after the model's name ("from words alone", "when it extends a clip"). */
+export const OPERATION_PLACE: Partial<Record<Operation, string>> = {
+ t2i: "from words alone",
+ t2v: "from words alone",
+ edit: "in an edit",
+ i2v: "from a start frame",
+ flf2v: "from start and end frames",
+ ref2v: "from references",
+ extend: "when it extends a clip",
+ finalize: "when it finishes a draft",
+};
+
+const secs = (n: number) => `${n}s`;
+
+/**
+ * Why a ratio, size or length isn't made on this operation, and the closest one it is (picked by the note's Use button):
+ * undefined when the routes take it (or take any).
+ */
+export function settingUnavailable(
+ model: Pick<ModelDef, "name">,
+ op: Operation | undefined,
+ setting: "aspect" | "resolution" | "duration",
+ value: string | number,
+ takes: OpTakes,
+): { why: string; instead?: string | number } | undefined {
+ const list = setting === "aspect" ? takes.aspectRatios : setting === "resolution" ? takes.resolutions : takes.durations;
+ if (!list?.length || takesValue(list, value)) return undefined;
+ const place = (op && OPERATION_PLACE[op]) ?? "here";
+ if (setting === "duration") {
+ const lengths = (list as number[]).slice().sort((a, b) => a - b);
+ const below = lengths.filter((l) => l <= Number(value));
+ const instead = below.length ? below[below.length - 1] : lengths[0];
+ return { why: `${model.name} makes ${listOr(lengths.map(secs))} clips ${place}`, instead };
+ }
+ if (setting === "aspect" && String(value).toLowerCase() === "auto") {
+ return { why: `Auto keeps a start frame's shape: ${model.name} needs a shape ${place}`, instead: list[0] };
+ }
+ const named = (list as string[]).filter((v) => v.toLowerCase() !== "auto");
+ const instead = nearest(named, String(value), setting);
+ return { why: `${model.name} doesn't make ${value} ${place}`, instead };
+}
+
+function listOr(items: string[]): string {
+ return items.length <= 1 ? (items[0] ?? "") : `${items.slice(0, -1).join(", ")} or ${items[items.length - 1]}`;
+}
+
+const ratio = (v: string) => {
+ const [w, h] = v.split(":").map(Number);
+ return w > 0 && h > 0 ? w / h : undefined;
+};
+const tier = (v: string) => {
+ const m = /^(\d+(?:\.\d+)?)\s*([kp])$/i.exec(v.trim());
+ if (!m) return undefined;
+ return m[2].toLowerCase() === "k" ? Number(m[1]) * 1000 : Number(m[1]) * 1.6;
+};
+
+/** The listed ratio closest in shape, or the largest size not above the one asked (else the smallest). */
+function nearest(list: string[], value: string, setting: "aspect" | "resolution"): string | undefined {
+ if (!list.length) return undefined;
+ const size = setting === "aspect" ? ratio : tier;
+ const want = size(value);
+ const sized = list.flatMap((a) => {
+ const n = size(a);
+ return n === undefined ? [] : [{ a, n }];
+ });
+ if (want === undefined || !sized.length) return list[0];
+ if (setting === "aspect") return sized.reduce((b, c) => (Math.abs(Math.log(c.n / want)) < Math.abs(Math.log(b.n / want)) ? c : b)).a;
+ const below = sized.filter((c) => c.n <= want);
+ return (below.length ? below.reduce((b, c) => (c.n > b.n ? c : b)) : sized.reduce((b, c) => (c.n < b.n ? c : b))).a;
+}
diff --git a/src/lib/catalog/types.ts b/src/lib/catalog/types.ts
index 71298292..39131831 100644
--- a/src/lib/catalog/types.ts
+++ b/src/lib/catalog/types.ts
@@ -628,6 +628,21 @@ export interface FieldMap {
upscaleFactor?: { key: string; min?: number; max?: number };
}
+/**
+ * The settings a hosted route sends (route-takes.ts): false = it has no field for it (the choice would be dropped), a list =
+ * the only values it takes (any other is fitted to one of them). A key left out: it takes any value.
+ */
+export interface RouteTakes {
+ aspectRatios?: string[] | false;
+ resolutions?: string[] | false;
+ durations?: number[] | false;
+ seed?: false;
+ negativePrompt?: false;
+ audio?: false;
+ /** No count field: one result a call. */
+ outputs?: false;
+}
+
export interface ModelRoute {
op: Operation;
provider: ProviderId;
@@ -639,6 +654,11 @@ export interface ModelRoute {
* layout is compiled at), kept by slimModel when it drops the field maps for the browser. The server reads `map`.
*/
preview?: Pick<FieldMap, "upscaleFactor" | "numFrames" | "size">;
+ /**
+ * What `map` sends, kept by slimModel for the browser's pickers (src/lib/catalog/route-takes.ts): a setting the route has no
+ * field for, or the only values it takes. Unset: it takes every setting.
+ */
+ takes?: RouteTakes;
/** Optional note shown in the UI (e.g. "uses Lightx2v 4-step LoRA"). */
note?: string;
/**
diff --git a/src/lib/composer.ts b/src/lib/composer.ts
index 32749266..a539afed 100644
--- a/src/lib/composer.ts
+++ b/src/lib/composer.ts
@@ -15,6 +15,7 @@ import { FACE_MOSAIC_MODELS } from "./catalog/open-tools";
import { pricingOn, type PriceClock } from "./catalog/promo";
import { soulPostStep } from "./catalog/soul";
import { studioResolutions } from "./catalog/regenerate";
+import { opTakes } from "./catalog/route-takes";
import { appModels, ownRoute, presetRoutes, type HasModel, type RecipePreset } from "./catalog/preset-recipe-routes";
import { COLORMAPS, type Engine, type GenParams, type InputSlot, type MatteOutput, type MediaKind, type ModelDef, type Operation, type Preset, type PresetRoute, type VideoFormat } from "./catalog/types";
import { formatCost } from "./format";
@@ -69,7 +70,7 @@ export interface SettingsShape {
* transforms (Lipsync), there's still no batch count.
*/
export function settingsShape(
- model: (Pick<ModelDef, "options" | "defaults"> & Partial<Pick<ModelDef, "routes">>) | undefined,
+ model: (Pick<ModelDef, "options" | "defaults"> & Partial<Pick<ModelDef, "routes" | "id">>) | undefined,
op: Operation | undefined,
kind: MediaKind,
showPrompt: boolean,
@@ -90,11 +91,14 @@ export function settingsShape(
const sized = !routes.length || routes.some((r) => !r.unsized);
// A cloud edit that follows image 1's shape at the chosen tier (ModelRoute.followsImage: fal's FLUX 3 Klein) keeps Resolution only.
const shaped = routes.length > 0 && routes.every((r) => r.unsized || r.followsImage);
+ // A setting none of the operation's hosted routes sends (Kling O3's video edit keeps the clip's shape and length; Hailuo 02
+ // makes text to video at one size) has nothing to pick: it would be dropped.
+ const takes = model?.id && model.routes ? opTakes({ id: model.id, routes: model.routes }, op) : opTakes(undefined, op);
return {
- aspect: !sized || shaped || op === "i2v" || op === "flf2v" ? null : many(o.aspectRatios),
+ aspect: !sized || shaped || op === "i2v" || op === "flf2v" || !takes.aspect ? null : many(o.aspectRatios),
// With the tiers a finishing pass reaches (MiniMax H3's 2K on your GPU: a 768p draft redrawn by Open-H3 Regenerate).
- resolution: sized ? many(studioResolutions(o)) : null,
- duration: params.shots ? null : many(o.durations),
+ resolution: sized && takes.resolution ? many(studioResolutions(o)) : null,
+ duration: params.shots || !takes.duration ? null : many(o.durations),
count: (kind === "image" || kind === "video") && !single,
draft: !!o.draft,
audio: o.audio === true,
diff --git a/src/lib/studio-catalog.ts b/src/lib/studio-catalog.ts
index 7ef233b7..243ec478 100644
--- a/src/lib/studio-catalog.ts
+++ b/src/lib/studio-catalog.ts
@@ -5,6 +5,7 @@
* provider field maps stay on the server, which plans and builds the real request itself.
*/
import { getModel, modelsFor } from "./catalog";
+import { takesFromMap } from "./catalog/route-takes";
import type { ModelDef } from "./catalog/types";
import type { StudioConfig } from "@/components/studio/studio-context";
@@ -28,6 +29,9 @@ export function slimModel(m: ModelDef): ModelDef {
delete copy.map;
const { upscaleFactor, numFrames, size } = r.map ?? {};
if (upscaleFactor || numFrames || size) copy.preview = { ...(upscaleFactor && { upscaleFactor }), ...(numFrames && { numFrames }), ...(size && { size }) };
+ // What the map sends, for the pickers: a setting it would drop or fit looks unavailable before the run.
+ const takes = takesFromMap(r, m.id);
+ if (takes) copy.takes = takes;
return copy;
}),
};
diff --git a/tests/route-takes.test.ts b/tests/route-takes.test.ts
new file mode 100644
index 00000000..fb404656
--- /dev/null
+++ b/tests/route-takes.test.ts
@@ -0,0 +1,84 @@
+import { describe, expect, it } from "vitest";
+import { getModel, getPreset } from "@/lib/catalog";
+import { planGeneration } from "@/lib/catalog/plan";
+import { oneEachCall, opTakes, settingUnavailable, takesFromMap } from "@/lib/catalog/route-takes";
+import type { ModelDef } from "@/lib/catalog/types";
+import { settingsShape } from "@/lib/composer";
+import { slimModel } from "@/lib/studio-catalog";
+
+/**
+ * The composer's settings follow what the run's routes send: a setting no route sends isn't offered, and a value no
+ * route takes stays in view, muted, with why and the closest one it does. The browser reads the same summary
+ * (route.takes, kept by slimModel) as the server reads from the field maps.
+ */
+const model = (id: string) => {
+ const m = getModel(id);
+ if (!m) throw new Error(`no ${id}`);
+ return m;
+};
+
+describe("what a route sends", () => {
+ it("reads the same in the browser as on the server", () => {
+ for (const id of ["kling-4", "vidu-q4", "nano-banana-pro", "kling-o3", "wan-2-2-a14b-cloud"]) {
+ const full = model(id);
+ const slim = slimModel(full);
+ for (const op of new Set(full.routes.map((r) => r.op))) expect(opTakes(slim, op)).toEqual(opTakes(full, op));
+ }
+ });
+
+ it("takes everything on a GPU graph or a route Fuobe sizes itself", () => {
+ expect(takesFromMap({ op: "t2i", provider: "comfyui", map: {} }, "oss-x")).toBeUndefined();
+ expect(takesFromMap({ op: "t2i", provider: "fal", map: { seed: "seed" } }, "fuobe-soul")).toBeUndefined();
+ });
+
+ it("has nothing to pick for a setting no route of the operation sends", () => {
+ const o3 = model("kling-o3");
+ const v2v = settingsShape(slimModel(o3), "v2v", "video", true);
+ // Kling O3's video edit keeps the clip's shape and length.
+ expect(v2v.aspect).toBeNull();
+ expect(v2v.duration).toBeNull();
+ });
+
+ it("says a ratio a route doesn't take is unavailable, with the closest it does", () => {
+ const k4 = model("kling-4");
+ const takes = opTakes(k4, "t2v");
+ expect(takes.aspectRatios).not.toContain("auto");
+ const auto = settingUnavailable(k4, "t2v", "aspect", "auto", takes);
+ expect(auto?.why).toMatch(/Auto keeps a start frame's shape/);
+ expect(auto?.instead).toBeDefined();
+ expect(settingUnavailable(k4, "t2v", "aspect", "16:9", takes)).toBeUndefined();
+ });
+
+ it("fits a size to the closest one taken", () => {
+ const takes = { aspect: true, resolution: true, duration: true, seed: true, negativePrompt: true, audio: true, resolutions: ["480p", "720p"], durations: [5, 10] };
+ const m = { name: "Wan" } as Pick<ModelDef, "name">;
+ expect(settingUnavailable(m, "t2v", "resolution", "580p", takes)).toEqual({ why: "Wan doesn't make 580p from words alone", instead: "480p" });
+ expect(settingUnavailable(m, "i2v", "duration", 15, takes)).toEqual({ why: "Wan makes 5s or 10s clips from a start frame", instead: 10 });
+ expect(settingUnavailable(m, "i2v", "duration", 10, takes)).toBeUndefined();
+ });
+
+ it("knows a sound switch and a seed the route doesn't send", () => {
+ const vidu = model("vidu-q4");
+ expect(opTakes(vidu, "i2v").audio).toBe(false);
+ expect(opTakes(vidu, "ref2v").audio).toBe(true);
+ expect(opTakes(model("seedance-2-5"), "t2v").seed).toBe(false);
+ });
+});
+
+describe("several results from a route with no count field", () => {
+ it("runs one job a result", () => {
+ // Ideogram's vectorizer lists 4 results, and its route makes one a call.
+ const z = model("ideogram-vector");
+ expect(oneEachCall(z, "vectorize")).toBe(true);
+ const plan = planGeneration({ feature: "image", modelId: z.id, op: "vectorize", prompt: "", inputs: { images: ["https://example.com/a.png"] }, params: { numOutputs: 3 } }, getModel, getPreset);
+ expect(plan.jobs).toBe(3);
+ expect(plan.perJobOutputs).toBe(1);
+ });
+
+ it("keeps one call for a route that takes a count", () => {
+ const nb = model("nano-banana-pro");
+ expect(oneEachCall(nb, "t2i")).toBe(false);
+ const plan = planGeneration({ feature: "image", modelId: nb.id, prompt: "a red chair in a white room", params: { numOutputs: 3 } }, getModel, getPreset);
+ expect(plan.jobs).toBe(1);
+ });
+});