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
Presets: a preset opens on the model its preview was made with
Adarsh8d780681ff5c
diff --git a/src/app/(studio)/apps/[id]/page.tsx b/src/app/(studio)/apps/[id]/page.tsxindex 8e3ce76f..5fd06add 100644--- a/src/app/(studio)/apps/[id]/page.tsx+++ b/src/app/(studio)/apps/[id]/page.tsx@@ -2,7 +2,8 @@ import type { Metadata } from "next";import { notFound } from "next/navigation";import { Suspense } from "react";import { Studio } from "@/components/studio/studio";-import { APPS, getPreset } from "@/lib/catalog";+import { APPS, getModel, getPreset } from "@/lib/catalog";+import { withRecipe } from "@/lib/catalog/preset-recipes";import { appStudio } from "@/lib/studios";export function generateStaticParams() {@@ -19,7 +20,8 @@ async function AppStudio({ params }: { params: PageProps<"/apps/[id]">["params"]const { id } = await params;const preset = getPreset(id);if (!preset || preset.type !== "app") notFound();- return <Studio config={appStudio(preset)} />;+ // The app opens on the model its preview was made with, its own route one pick away.+ return <Studio config={withRecipe(appStudio(preset), (m) => !!getModel(m))} />;}export default function Page({ params }: PageProps<"/apps/[id]">) {diff --git a/src/app/api/gpu/plan/route.ts b/src/app/api/gpu/plan/route.tsindex 610c2d84..7458de57 100644--- a/src/app/api/gpu/plan/route.ts+++ b/src/app/api/gpu/plan/route.ts@@ -4,11 +4,12 @@ import { planFor } from "@/server/gpu/readiness-service";import { gpuTargetFor } from "@/server/gpu/target";/**- * GPU pre-flight: one tool's fix plan (`?ref=model:<id>#<op>`, `preset:<id>`, `studio:<href>` or- * `workflow:<id>`), built on the server from the requirement index and the viewer's last check. The client- * names a tool only, never a file, URL or repository (R2). P1 plans are by hand: the commands to run.+ * GPU pre-flight: one tool's fix plan (`?ref=model:<id>#<op>`, `preset:<id>` or `preset:<id>@<model id>` for its+ * route on that model, `studio:<href>` or `workflow:<id>`), built on the server from the requirement index and the+ * viewer's last check. The client names a tool only, never a file, URL or repository (R2). P1 plans are by hand: the+ * commands to run.*/-const REF = /^(model:[\w.-]{1,120}#[\w-]{1,40}|preset:[\w.-]{1,120}|studio:\/[\w/-]{0,60}|workflow:[\w.-]{1,120})$/;+const REF = /^(model:[\w.-]{1,120}#[\w-]{1,40}|preset:[\w.-]{1,120}(?:@[\w.-]{1,120})?|studio:\/[\w/-]{0,60}|workflow:[\w.-]{1,120})$/;export async function GET(request: Request) {await connection();diff --git a/src/components/preset-header.tsx b/src/components/preset-header.tsxindex 38bd8c89..fb223d47 100644--- a/src/components/preset-header.tsx+++ b/src/components/preset-header.tsx@@ -1,13 +1,14 @@"use client";-import { Cloud, Cpu, Info, X } from "lucide-react";+import { Cloud, Cpu, Info, Sparkles, X } from "lucide-react";import { HeaderPill } from "@/components/gpu/readiness-chip";import { PresetPreview, usePreviewPlayback } from "@/components/preset-preview";import { openGpuSetup, useGpuBadges } from "@/hooks/use-gpu";import { useEngine } from "@/lib/api";import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";+import { presetRecipe } from "@/lib/catalog/preset-recipes";import type { Preset } from "@/lib/catalog/types";-import { onPeak, presetCard, presetHowTo, presetRouteLines, previewFlip } from "@/lib/preset-cards";+import { onPeak, parityNote, presetCard, presetHowTo, presetRouteLines, previewFlip } from "@/lib/preset-cards";// The slim covers map comes with coverPreview: this component is loaded on its own (next/dynamic in studio-page.tsx).import { coverPreview } from "@/lib/preset-covers";import { cn } from "@/lib/utils";@@ -25,12 +26,18 @@ import { cn } from "@/lib/utils";export function PresetHeader({preset,modelName,+ gpuKey,onClear,className,}: {preset: Preset;/** Display name for a model id (the studio's model lookup). */modelName?: (id: string) => string | undefined;+ /**+ * The preset's GPU badge for the composer's model and Quality (presetGpuKey): "<id>", "<id>@<model id>", or undefined+ * when the run is the model's own (no preset pill).+ */+ gpuKey?: string;/** Clear the preset (motions/effects picked in a general studio); omit on a preset's own page. */onClear?: () => void;className?: string;@@ -39,11 +46,16 @@ export function PresetHeader({// card the visitor came from (onPeak).const card = onPeak(presetCard(preset, coverPreview(preset)));const { ref, playing, asked, handlers, onTap } = usePreviewPlayback<HTMLDivElement>(card.id, card.preview, { always: true });- const routes = presetRouteLines(preset, modelName);+ // The model its preview was made with comes first (when this studio has it), marked when the live preview came from it.+ const has = (id: string) => !!modelName?.(id);+ const routes = presetRouteLines(preset, modelName, (e) => presetRecipe(preset, e, has));+ const note = parityNote(preset.parity, routes);// Its state on the viewer's GPU (open engine only): a pill that opens the guided fix.const badges = useGpuBadges().data;const [engine] = useEngine();- const gpu = preset.open && engine === "open" ? (badges?.presets[preset.id] ?? null) : null;+ const gpu = gpuKey && engine === "open" ? (badges?.presets[gpuKey] ?? null) : null;+ // The model its live preview was made with, said in words on the card (the composer marks it with a sparkle).+ const made = routes.find((r) => r.made && !r.alt && r.engine === engine) ?? routes.find((r) => r.made);return (<div className={cn("mx-auto flex w-full max-w-[760px] items-center gap-3 rounded-2xl border bg-background p-2 pr-3 text-left shadow-soft", className)}><div@@ -58,8 +70,14 @@ export function PresetHeader({<div className="min-w-0 flex-1"><p className="truncate font-heading text-[19px] leading-snug">{preset.name}</p><p className="line-clamp-2 text-[13px] text-muted-foreground max-sm:line-clamp-3">{presetHowTo(preset)}</p>+ {made?.model && (+ <p className="mt-0.5 flex min-w-0 items-center gap-1 text-[11px] font-medium text-brand-text">+ <Sparkles className="size-3 shrink-0" aria-hidden />+ <span className="truncate">Preview made with {made.model}</span>+ </p>+ )}</div>- {gpu && <HeaderPill badge={gpu} gpu={badges?.gpu} compact onOpen={() => openGpuSetup({ ref: `preset:${preset.id}`, name: preset.name })} />}+ {gpu && <HeaderPill badge={gpu} gpu={badges?.gpu} compact onOpen={() => openGpuSetup({ ref: `preset:${gpuKey}`, name: preset.name })} />}<Popover><PopoverTrigger asChild><button@@ -75,14 +93,28 @@ export function PresetHeader({<p className="text-muted-foreground">{preset.description}</p><ul className="space-y-1">{routes.map((r) => (- <li key={r.engine} className="flex items-center gap-2">- {r.engine === "cloud" ? <Cloud className="size-3.5 shrink-0" /> : <Cpu className="size-3.5 shrink-0" />}- <span className="text-muted-foreground">{r.label}</span>- <span className={cn("ml-auto truncate font-medium", !r.model && "font-normal text-muted-foreground")}>{r.model ?? "Not available yet"}</span>+ <li key={`${r.engine}-${r.alt ? "alt" : "first"}`} className="flex items-start gap-2">+ {r.alt ? (+ <span className="size-3.5 shrink-0" aria-hidden />+ ) : r.engine === "cloud" ? (+ <Cloud className="mt-0.5 size-3.5 shrink-0" />+ ) : (+ <Cpu className="mt-0.5 size-3.5 shrink-0" />+ )}+ <span className="text-muted-foreground">{r.alt ? "or" : r.label}</span>+ <span className="ml-auto flex min-w-0 flex-col items-end text-right">+ <span className={cn("max-w-full truncate font-medium", !r.model && "font-normal text-muted-foreground", r.alt && "font-normal")}>{r.model ?? "Not available yet"}</span>+ {r.made && (+ <span className="flex items-center gap-1 text-[11px] font-medium text-brand-text">+ <Sparkles className="size-3 shrink-0" aria-hidden />+ Used for this preview+ </span>+ )}+ </span></li>))}</ul>- {preset.parity && <p className="border-t pt-2 text-[12px] text-muted-foreground">{preset.parity}</p>}+ {note && <p className="border-t pt-2 text-[12px] text-muted-foreground">{note}</p>}</PopoverContent></Popover>{onClear && (diff --git a/src/components/studio/composer.tsx b/src/components/studio/composer.tsxindex 15bfdb81..d7ea0248 100644--- a/src/components/studio/composer.tsx+++ b/src/components/studio/composer.tsx@@ -1,9 +1,9 @@"use client";-import { ArrowUp, AtSign, GalleryHorizontalEnd, Loader2, Sparkles, X } from "lucide-react";+import { ArrowUp, AtSign, Cloud, Cpu, GalleryHorizontalEnd, Loader2, Sparkles, X } from "lucide-react";import dynamic from "next/dynamic";import Link from "next/link";-import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";+import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";import { flushSync } from "react-dom";import { toast } from "sonner";import { openAddKey } from "@/components/keys/your-keys";@@ -12,7 +12,7 @@ import { Kbd } from "@/components/ui/kbd";import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";import { useToday } from "@/hooks/use-today";import { estimateCost, imageLimit, planGeneration, routesFor } from "@/lib/catalog/plan";-import type { Engine, GenerationRequest, MediaKind, ModelDef, Operation, Preset, VideoFormat } from "@/lib/catalog/types";+import type { Engine, GenerationRequest, MediaKind, ModelDef, Operation, Preset, PresetRoute, VideoFormat } from "@/lib/catalog/types";import { dualEngine } from "@/lib/catalog/engines";import { locksByDefault } from "@/lib/catalog/palettes";import { DEFAULT_LOOK, lookCard } from "@/lib/catalog/soul-cards";@@ -36,7 +36,9 @@ import {OPEN_MIN_GAP,type FrameSupport,} from "@/lib/catalog/keyframes";+import { appModels, presetGpuKey, presetRoutes, recipeRoute } from "@/lib/catalog/preset-recipe-routes";import {+ appRoute,blockerFor,blockerLine,clipBlocker,@@ -58,10 +60,13 @@ import {PLACEHOLDER,presetModel,presetOriginal,+ presetFallback as presetFallbackRoute,presetParams,postStepCost,prestepCost,pushRecent,+ routeParams,+ untouchedParams,settingsShape,showsPrompt,startStep,@@ -181,6 +186,24 @@ function buildRequest(};}+/**+ * Whether the preset's preview was made with its recipe on this engine ("Used for this preview" on that model). The covers+ * manifest that says so is its own chunk (src/lib/catalog/preset-recipes.ts), loaded once a preset with a recipe is open.+ */+function useRecipeMade(preset: Preset | undefined, engine: Engine, recipeModel: string | undefined): boolean {+ const key = preset && recipeModel ? `${preset.id}:${engine}` : "";+ const [made, setMade] = useState<Record<string, boolean>>({});+ useEffect(() => {+ if (!key || !preset || key in made) return;+ let live = true;+ void import("@/lib/catalog/preset-recipes").then((m) => live && setMade((x) => ({ ...x, [key]: m.recipeMade(preset, engine) })));+ return () => {+ live = false;+ };+ }, [key, preset, engine, made]);+ return !!key && !!made[key];+}+/** Leaving a model that takes looks (Fuobe Soul) for one that doesn't: the look (its presetId) doesn't come along. */function lookCleared(from: ModelDef | undefined, to: ModelDef): Partial<Draft> {return from?.options.looks && !to.options.looks ? { presetId: undefined, presetStrength: undefined } : {};@@ -293,6 +316,23 @@ export function Composer({ docked }: { docked: boolean }) {const preset: Preset | undefined = draft.presetId && !takesLook ? catalog.getPreset(draft.presetId) : config.preset;const lockedModel = preset?.type === "app";const presetLoading = !!draft.presetId && !takesLook && !preset && !catalog.complete;+ // The models the viewer's catalog has (the studio's slice, or the full catalog once it's loaded), and the ones this+ // viewer can run now: offered in Settings → Models & licences, and a key for its provider when it's an account's paid run.+ const has = useCallback((id: string) => !!catalog.getModel(id), [catalog]);+ const runs = useCallback(+ (id: string) => {+ const m = catalog.getModel(id);+ return !!m && catalog.offered(id, engine) && !needsKey(m, status);+ },+ [catalog, engine, status],+ );+ // An app runs on its own models on this engine: the one its preview was made with, then its own route's.+ const appIds = useMemo(() => (lockedModel && preset ? appModels(preset, engine, has) : []), [lockedModel, preset, engine, has]);+ // The model the preset's preview was made with on this engine (MiniMax H3, Qwen-Image 2.1 Turbo), and whether its live+ // preview really came from it ("Used for this preview" on that model).+ const recipe = preset && !takesLook ? recipeRoute(preset, engine) : undefined;+ const recipeModel = recipe && has(recipe.modelId) ? recipe.modelId : undefined;+ const madeWith = useRecipeMade(preset, engine, recipeModel) ? recipeModel : undefined;/** What the request names for its model: the engine (only a model that runs on both, a Fuobe Original), and whether it takes looks. */const targetFor = (id: string) => {const m = catalog.getModel(id);@@ -339,7 +379,7 @@ export function Composer({ docked }: { docked: boolean }) {seen.current = { engine, model };if (!model) return;if (heldForKey && (model.id !== config.defaultModels.cloud || new URLSearchParams(window.location.search).get("model") === model.id)) return;- const next = engineSwitchModel({ model, preset, engine, from: before.engine, defaults });+ const next = engineSwitchModel({ model, preset, engine, from: before.engine, defaults, has });const m = next ? catalog.getModel(next) : undefined;if (!m) {if (before.engine === engine || before.model?.id !== model.id || before.model === model) return;@@ -353,9 +393,10 @@ export function Composer({ docked }: { docked: boolean }) {}// Only the model this effect saw: a hand-off applied in the same commit (?model=, a layout effect) already// replaced it, and swapping it for the engine's default would undo the link (it landed on Z-Image Turbo).- const route = m.id === presetModel(preset, engine) ? presetParams(preset, engine) : {};+ // An app takes the settings of its route on that model; a camera motion or effect its move's.+ const route = lockedModel ? routeParams(appRoute(preset, engine, m.id, has), "app") : m.id === presetModel(preset, engine, has) ? presetParams(preset, engine, has) : {};setDraft((d) => (d.modelId !== model.id ? {} : { modelId: m.id, params: { ...m.defaults, ...route, numOutputs: d.params.numOutputs, enhancePrompt: d.params.enhancePrompt }, ...lookCleared(model, m) }));- }, [engine, model, preset, defaults, setDraft, catalog, heldForKey, config.defaultModels.cloud]);+ }, [engine, model, preset, defaults, setDraft, catalog, heldForKey, config.defaultModels.cloud, has, lockedModel]);// Where the server can't write Ideogram 4's caption (writesCaptions), the studio's untouched default moves to its stand-in// once the status is known. Ideogram 4 picked after that stays.@@ -364,31 +405,46 @@ export function Composer({ docked }: { docked: boolean }) {if (captionChecked.current || writes === undefined || !model) return;captionChecked.current = true;const to = defaults[engine];- const m = to !== model.id && model.id === config.defaultModels[engine] && !lockedModel ? catalog.getModel(to) : undefined;+ // An app moves only to one of its own models.+ const m = to !== model.id && model.id === config.defaultModels[engine] && (!lockedModel || appIds.includes(to)) ? catalog.getModel(to) : undefined;if (m) setDraft((d) => (d.modelId !== model.id ? {} : { modelId: m.id, params: { ...m.defaults, numOutputs: d.params.numOutputs, enhancePrompt: d.params.enhancePrompt }, ...lookCleared(model, m) }));- }, [writes, model, defaults, engine, config.defaultModels, lockedModel, catalog, setDraft]);+ }, [writes, model, defaults, engine, config.defaultModels, lockedModel, appIds, catalog, setDraft]);++ // The preset's recipe (the model its preview was made with) that this viewer can't run: a Replicate-only account and+ // hosted MiniMax H3 (fal only), or a model switched off in Settings → Models & licences. The composer moves to the+ // preset's own route on this engine when the viewer can run that (Kling 2.5 Turbo, Fuobe DoP, the app's own model).+ const presetFallback = useMemo(() => (takesLook ? undefined : presetFallbackRoute(preset, engine, model?.id, has, runs)), [preset, takesLook, model, engine, has, runs]);+ useEffect(() => {+ const m = presetFallback && model ? catalog.getModel(presetFallback.modelId) : undefined;+ if (!m || !model) return;+ const route = routeParams(presetFallback, preset!.type);+ setDraft((d) => (d.modelId !== model.id ? {} : { modelId: m.id, params: { ...m.defaults, ...route, numOutputs: d.params.numOutputs, enhancePrompt: d.params.enhancePrompt, seed: d.params.seed } }));+ // Said only for the setting: an account's key is its own business (the keys' note says what each model needs).+ if (!catalog.offered(model.id, engine)) toast(`${model.name} is turned off in Settings → Models & licences, so this uses ${m.name}`, { id: "model-access" });+ }, [presetFallback, model, preset, engine, catalog, setDraft]);// Settings → Models & licences switched the model off (a default, a remembered pick, a Reuse, a link): the composer// moves to the studio's default on this engine, else the first model of its list that is on, and says so. With- // none on, Generate says what to turn on (accessError).+ // none on, Generate says what to turn on (accessError). A preset's recipe moves to the preset's own route instead.const offModel = model && !catalog.offered(model.id, engine) ? model : undefined;const fallback = offModel ? [defaults[engine], ...models.filter((m) => m.engine === engine).map((m) => m.id)].find((id) => !!id && catalog.offered(id, engine) && !!catalog.getModel(id)) : undefined;useEffect(() => {- if (!offModel || !fallback || lockedModel) return;+ if (!offModel || !fallback || lockedModel || presetFallback) return;const m = catalog.getModel(fallback)!;setDraft((d) => (d.modelId !== offModel.id ? {} : { modelId: m.id, params: { ...m.defaults, numOutputs: d.params.numOutputs, enhancePrompt: d.params.enhancePrompt }, ...lookCleared(offModel, m) }));toast(`${offModel.name} is turned off in Settings → Models & licences, so this uses ${m.name}`, { id: "model-access" });- }, [offModel, fallback, lockedModel, catalog, setDraft]);+ }, [offModel, fallback, lockedModel, presetFallback, catalog, setDraft]);// An account (Your keys) starts on a paid model it can run: the studio's untouched default when it has that key, else- // the first of the list it can run. Quietly: nothing it picked changed (a model it picked is never swapped).+ // the first of the list it can run. Quietly: nothing it picked changed (a model it picked is never swapped). A preset's+ // recipe moves to the preset's own route instead (presetFallback).const keyStart =model && model.id === config.defaultModels[engine] && needsKey(model, status) ? startingModel(model.id, models.filter((m) => m.engine === engine && catalog.offered(m.id, engine)), status) : undefined;useEffect(() => {- const m = keyStart && model && keyStart !== model.id && !lockedModel ? catalog.getModel(keyStart) : undefined;+ const m = keyStart && model && keyStart !== model.id && !lockedModel && !presetFallback ? catalog.getModel(keyStart) : undefined;if (!m || !model) return;setDraft((d) => (d.modelId !== model.id ? {} : { modelId: m.id, params: { ...m.defaults, numOutputs: d.params.numOutputs, enhancePrompt: d.params.enhancePrompt }, ...lookCleared(model, m) }));- }, [keyStart, model, lockedModel, catalog, setDraft]);+ }, [keyStart, model, lockedModel, presetFallback, catalog, setDraft]);// A camera motion or effect runs on its Original on this engine (Fuobe DoP): picking one moves the composer there,// with the move's own settings (Focus Change: 6 s, silent). Another video model can be picked after it; it takes@@ -397,10 +453,12 @@ export function Composer({ docked }: { docked: boolean }) {presetUrl(id);if (!id) return setDraft({ presetId: undefined, mix: undefined, presetStrength: undefined });const picked = catalog.getPreset(id);- const want = presetOriginal(picked, engine);- const m = want && want !== model?.id ? catalog.getModel(want) : undefined;+ const want = presetOriginal(picked, engine, runs);+ const m = want ? catalog.getModel(want) : undefined;if (!m) return setDraft({ presetId: id });- const route = presetParams(picked, engine);+ // Also when the composer is already on that model (MiniMax H3 for most moves): the move picked brings its own length+ // and Quality, not the last one's.+ const route = presetParams(picked, engine, runs);setDraft((d) => ({ presetId: id, modelId: m.id, params: { ...m.defaults, ...route, numOutputs: d.params.numOutputs, enhancePrompt: d.params.enhancePrompt, seed: d.params.seed }, ...lookCleared(model, m) }));};// The empty studio's example tiles pick a camera motion or effect here, as the chip does, so what is attached stays.@@ -415,14 +473,23 @@ export function Composer({ docked }: { docked: boolean }) {// studio's untouched default model to its Original, once per preset.const adoptedPreset = useRef<string | undefined>(undefined);useEffect(() => {- const want = presetOriginal(preset, engine);+ const want = presetOriginal(preset, engine, runs);if (!preset || !want || !model || adoptedPreset.current === preset.id) return;adoptedPreset.current = preset.id;- if (model.id === want || model.id !== defaults[engine]) return;+ const route = presetParams(preset, engine, runs);+ // Already on that model (MiniMax H3 is the Video studio's default): the move's length and Quality replace the ones+ // still at the model's defaults.+ if (model.id === want) {+ setDraft((d) => {+ const params = d.modelId === model.id ? untouchedParams(d.params, model.defaults ?? {}, route) : undefined;+ return params ? { params } : {};+ });+ return;+ }+ if (model.id !== defaults[engine]) return;const m = catalog.getModel(want);- const route = presetParams(preset, engine);if (m) setDraft((d) => (d.modelId !== model.id ? {} : { modelId: m.id, params: { ...m.defaults, ...route, numOutputs: d.params.numOutputs, enhancePrompt: d.params.enhancePrompt, seed: d.params.seed }, ...lookCleared(model, m) }));- }, [preset, engine, model, defaults, catalog, setDraft]);+ }, [preset, engine, model, defaults, catalog, setDraft, runs]);// A link to a camera motion or effect Fuobe doesn't have (?preset=nope): once every preset is known, the composer// drops it and says so, so the chip doesn't wait on it and a plain prompt runs.const unknownPreset = catalog.complete && !!draft.presetId && !takesLook && !preset;@@ -496,9 +563,9 @@ export function Composer({ docked }: { docked: boolean }) {// A cloud-only install refuses open models, and with demo mode off nothing else runs it, so Generate says why.const comfyMissing = !!config.comfyOnly && !!status && (engineMode === "cloud" || !status.providers.comfyui?.configured);const comfyBlock = comfyMissing && model?.engine === "open" && (engineMode === "cloud" || status?.demoMode === "off") ? "Needs ComfyUI: see the note below" : null;- const accessError = offModel && (!fallback || lockedModel) ? `${offModel.name} is turned off in Settings → Models & licences` : null;+ const accessError = offModel && !presetFallback && (!fallback || lockedModel) ? `${offModel.name} is turned off in Settings → Models & licences` : null;const engineError =- (lockedModel && preset && !(engine === "open" ? preset.open : preset.cloud) ? `${preset.name} has no ${engine === "open" ? "open-source" : "cloud"} version yet` : null) ?? accessError ?? comfyBlock;+ (lockedModel && preset && !appIds.length ? `${preset.name} has no ${engine === "open" ? "open-source" : "cloud"} version yet` : null) ?? accessError ?? comfyBlock;let op: Operation | undefined;let cost: number | null = null;// The run goes to a LoRA endpoint whose price isn't published (fal's MOSS-Image /lora).@@ -558,19 +625,25 @@ export function Composer({ docked }: { docked: boolean }) {// GPU): Generate opens the guided fix instead of sending a run that would fail late, and the prompt stays here.const gpuBadges = useGpuBadges().data;const gpuOp = op ?? studioOp;- const gpuBadge =- model?.engine === "open" && gpuBadges?.connected- ? ((preset?.open ? gpuBadges.presets[preset.id] : undefined) ?? badgeFor(gpuBadges, { modelId: model.id, op: gpuOp }))- : null;+ // A preset's badge describes its route on the model picked (src/server/gpu/tools.ts): the first open route (its recipe's+ // when the catalog has its model) as "<id>", another one as "<id>@<model id>" (Fuobe DoP with the move's LoRAs). On a+ // model the preset has no route on, or at another Quality than the route's (H3's 8-step graph for a preset made at+ // Best), the model's own badge applies.+ const presetKey =+ preset && !takesLook && model+ ? presetGpuKey(preset, has, model.id, draft.params.extra?.quality, model.options.controls?.find((c) => c.param === "quality")?.default)+ : undefined;+ const presetGpu = presetKey && gpuBadges?.connected ? gpuBadges.presets[presetKey] : undefined;+ const gpuBadge = model?.engine === "open" && gpuBadges?.connected ? (presetGpu ?? badgeFor(gpuBadges, { modelId: model.id, op: gpuOp })) : null;const gpuSetup = gpuBadge && gpuBadge[0] !== "r" ? gpuBadge : null;- const gpuRef = preset?.open && gpuBadges?.presets[preset.id] ? `preset:${preset.id}` : model ? `model:${model.id}#${gpuOp ?? Object.keys(gpuBadges?.models ?? {}).find((k) => k.startsWith(`${model.id}#`))?.split("#")[1] ?? ""}` : "";+ const gpuRef = presetGpu && presetKey ? `preset:${presetKey}` : model ? `model:${model.id}#${gpuOp ?? Object.keys(gpuBadges?.models ?? {}).find((k) => k.startsWith(`${model.id}#`))?.split("#")[1] ?? ""}` : "";const openGpuFix = () => {setGpuRetry(() => submitRef.current(),() => submitRef.current(true),model?.kind,);- openGpuSetup({ ref: gpuRef, name: preset?.open ? preset.name : model?.name });+ openGpuSetup({ ref: gpuRef, name: presetGpu ? preset?.name : model?.name });};// An account's paid model it has no key for yet: Generate asks for the key (the note below says so too).@@ -745,6 +818,25 @@ export function Composer({ docked }: { docked: boolean }) {setDraft((d) => ({ modelId: m.id, params: { ...m.defaults, numOutputs: d.params.numOutputs, enhancePrompt: d.params.enhancePrompt, seed: d.params.seed }, ...lookCleared(model, m) }));if (m.engine !== engine) setEngine(m.engine);};+ // An app's two models on this engine (the one its preview was made with, then its own route's): a picker of those in+ // place of the model chip, listing the other engine's too for the picker's engine switch. A model switched off in+ // Settings → Models & licences leaves it.+ const appPickerModels = useMemo(+ () =>+ lockedModel && preset+ ? (["cloud", "open"] as const)+ .flatMap((e) => appModels(preset, e, has).filter((id) => catalog.offered(id, e)))+ .map((id) => catalog.getModel(id))+ .filter((m): m is ModelDef => !!m)+ : [],+ [lockedModel, preset, has, catalog],+ );+ const appChoice = appPickerModels.filter((m) => m.engine === engine).length > 1;+ const pickAppModel = (m: ModelDef) => {+ const route = routeParams(appRoute(preset, m.engine, m.id, has), "app");+ setDraft((d) => ({ modelId: m.id, params: { ...m.defaults, ...route, numOutputs: d.params.numOutputs, enhancePrompt: d.params.enhancePrompt, seed: d.params.seed } }));+ if (m.engine !== engine) setEngine(m.engine);+ };// Frames on: the start and end frames already attached become the first frames. Off: the first and last frames// go back to start and end (the ones in between can come back with Undo).@@ -825,6 +917,15 @@ export function Composer({ docked }: { docked: boolean }) {)}</>);+ // A move's strength scales its LoRAs (Fuobe DoP's, Fuobe DoP · LTX's camera LoRA): the slider shows on a model whose+ // route of the move has them, else the note names the model that does (MiniMax H3 runs a move in words).+ const moveStrength = useMemo(() => {+ if (!preset || !model || (preset.type !== "motion" && preset.type !== "effect")) return { here: true };+ const scaled = (r: PresetRoute | null | undefined) => !!r?.loras?.length || !!r?.params?.extra?.camera_lora;+ if (presetRoutes(preset, engine, has).some((r) => r.modelId === model.id && scaled(r))) return { here: true };+ const own = engine === "open" ? preset.open : preset.cloud;+ return { here: false, on: scaled(own) && own!.modelId !== model.id ? catalog.getModel(own!.modelId)?.name : undefined };+ }, [preset, model, engine, has, catalog]);const styleChips = (<>{(config.presetPicker || (preset && (preset.type === "motion" || preset.type === "effect"))) && (@@ -833,6 +934,8 @@ export function Composer({ docked }: { docked: boolean }) {preset={preset}presetId={draft.presetId}strength={draft.presetStrength ?? 1}+ takesStrength={moveStrength.here}+ strengthOn={moveStrength.on}mix={draft.mix}onPreset={pickPreset}onMix={(patch) => setDraft(patch)}@@ -1067,16 +1170,19 @@ export function Composer({ docked }: { docked: boolean }) {)}{/* The model chip may shrink (its name truncates) on phones, so the row fits without scrolling. */}<span className="flex min-w-0 shrink-0 max-sm:order-2 max-sm:min-w-[4.5rem] max-sm:shrink max-sm:[&>button]:min-w-0 max-sm:[&>button]:shrink max-sm:[&>button>svg:first-child]:hidden">- {!lockedModel ? (+ {!lockedModel || appChoice ? (catalog.ready ? (<ModelPicker- models={models}+ models={appChoice ? appPickerModels : models}value={model}engine={engine}onEngineChange={setEngine}defaultModels={defaults}ops={pickerOps}- onChange={pickModel}+ onChange={appChoice ? pickAppModel : pickModel}+ recipe={recipeModel}+ flat={appChoice}+ madeWith={madeWith}/>) : (<Chip icon={Loader2} disabled className="[&>svg]:animate-spin">@@ -1086,11 +1192,15 @@ export function Composer({ docked }: { docked: boolean }) {) : (<Tooltip><TooltipTrigger asChild>- <Chip icon={Sparkles}>+ <Chip icon={model?.engine === "cloud" ? Cloud : Cpu} aria-label={`${preset?.name} runs on ${model?.name ?? "its own model"}${model && model.id === madeWith ? ", used for this preview" : ""}`}><span className="min-w-0 truncate">{model?.name ?? "…"}</span>+ {model && model.id === madeWith && <Sparkles className="size-3.5 shrink-0 text-brand-text" aria-hidden />}</Chip></TooltipTrigger>- <TooltipContent>{preset?.name} runs on {model?.name ?? "its own model"}</TooltipContent>+ <TooltipContent>+ {preset?.name} runs on {model?.name ?? "its own model"}+ {model && model.id === madeWith ? " · Used for this preview" : ""}+ </TooltipContent></Tooltip>)}</span>diff --git a/src/components/studio/model-picker.tsx b/src/components/studio/model-picker.tsxindex 5c104a41..b345dd02 100644--- a/src/components/studio/model-picker.tsx+++ b/src/components/studio/model-picker.tsx@@ -1,6 +1,6 @@"use client";-import { ChevronDown, Cloud, Cpu, SearchX, Server, Star } from "lucide-react";+import { ChevronDown, Cloud, Cpu, SearchX, Server, Sparkles, Star } from "lucide-react";import Link from "next/link";import { useEffect, useMemo, useRef, useState } from "react";import { KEY_ADDED_EVENT, openAddKey } from "@/components/keys/your-keys";@@ -83,6 +83,7 @@ function ModelRow({gpu,gpuName,needs,+ made,}: {m: ModelDef;selected: boolean;@@ -96,6 +97,8 @@ function ModelRow({gpuName?: string;/** An account's paid model it has no key for yet: dimmed, "Add your fal.ai key" in place of the price. */needs?: CloudProvider[] | null;+ /** The active preset's live preview was made with this model. */+ made?: boolean;}) {return (<>@@ -125,6 +128,12 @@ function ModelRow({<span className="block truncate text-[12px] leading-snug text-muted-foreground">{m.vendor} · {m.tagline}</span>+ {made && (+ <span className="mt-0.5 flex items-center gap-1 text-[11px] leading-snug font-medium text-brand-text">+ <Sparkles className="size-3! shrink-0" aria-hidden />+ Used for this preview+ </span>+ )}{m.worker === "isolated" && (<span className="mt-0.5 flex items-center gap-1 text-[11px] leading-snug text-muted-foreground"><Server className="size-3! shrink-0" aria-hidden />@@ -172,6 +181,12 @@ interface PickerProps {defaultModels?: { cloud: string; open: string };/** The operations the studio offers, its main one first: "Best for this studio" ranks the models that do it. */ops?: Operation[];+ /** The model the active preset's preview was made with (its recipe): first in "Best for this studio". */+ recipe?: string;+ /** A short list in its own order (an app's models): one group, no Recent, Starred or Best. */+ flat?: boolean;+ /** The model the active preset's live preview really came from: "Used for this preview" on its row. */+ madeWith?: string;}/**@@ -180,9 +195,18 @@ interface PickerProps {* desktop, a bottom sheet on phones. The list is built only while the panel is open (a canvas* board shows dozens of closed pickers).*/+/**+ * A model's name on a phone's narrow button: Qwen-Image's family name shortened ("Qwen 2.1 Turbo"), so the word that+ * tells two models apart (Turbo) stays in view. The full name is the button's label.+ */+export function phoneName(name: string): string {+ return name.replace(/^Qwen-Image(-Edit)? /, (_, edit?: string) => (edit ? "Qwen Edit " : "Qwen "));+}+export function ModelPicker(props: PickerProps) {const [open, setOpen] = useState(false);const { value, models, onChange } = props;+ const made = !!value && value.id === props.madeWith;// The model a dimmed row was chosen for (by this picker only): picked once its key is saved and the studio knows it// (the status has the key, so the engine switch is on Cloud and nothing swaps the model back to an open one).const waiting = useRef<string | null>(null);@@ -213,9 +237,17 @@ export function ModelPicker(props: PickerProps) {className="w-[min(92vw,440px)] p-0 shadow-strong"sheetClassName="h-[80svh]"trigger={- <Button variant="secondary" size="sm" className="h-8 shrink-0 gap-1.5 rounded-full px-3 text-[13px] font-medium" aria-label={`Model: ${value?.name ?? "none"}. Change model`}>+ <Button+ variant="secondary"+ size="sm"+ className="h-8 shrink-0 gap-1.5 rounded-full px-3 text-[13px] font-medium"+ aria-label={`Model: ${value?.name ?? "none"}${made ? ", used for this preview" : ""}. Change model`}+ title={made ? "Used for this preview" : undefined}+ >{value?.engine === "open" ? <Cpu className="size-3.5" /> : <Cloud className="size-3.5" />}- <span className="max-w-32 truncate sm:max-w-44">{value?.name ?? "Choose model"}</span>+ <span className="max-w-40 truncate max-sm:hidden sm:max-w-44">{value?.name ?? "Choose model"}</span>+ <span className="max-w-40 truncate sm:hidden">{value ? phoneName(value.name) : "Choose model"}</span>+ {made && <Sparkles className="size-3.5 text-brand-text" aria-hidden />}<ChevronDown className="size-3.5 opacity-60" /></Button>}@@ -242,6 +274,9 @@ function PickerList({onEngineChange,defaultModels,ops,+ recipe,+ flat,+ madeWith,onPicked,onNeedsKey,}: PickerProps & { onPicked: () => void; onNeedsKey?: (m: ModelDef, p: CloudProvider) => void }) {@@ -255,8 +290,12 @@ function PickerList({const today = useToday();const engines = useMemo<Engine[]>(() => (mode === "both" ? ["cloud", "open"] : [mode]), [mode]);// "Best" ranks models that do what the studio is for, not single-purpose tools.- const best = useMemo(() => studioBest(models, engine, defaultModels?.[engine], ops), [models, engine, defaultModels, ops]);- const { groups, count } = useMemo(() => groupModels({ models, engine, engines, query: q, recent, starred, best }), [models, engine, engines, q, recent, starred, best]);+ // A preset's recipe leads, when it runs on this engine.+ const best = useMemo(() => {+ const ranked = studioBest(models, engine, defaultModels?.[engine], ops);+ return recipe && models.some((m) => m.id === recipe && m.engine === engine) ? [recipe, ...ranked.filter((id) => id !== recipe)] : ranked;+ }, [models, engine, defaultModels, ops, recipe]);+ const { groups, count } = useMemo(() => groupModels({ models, engine, engines, query: q, recent, starred, best, flat }), [models, engine, engines, q, recent, starred, best, flat]);const ready = (m: ModelDef) => m.routes.some((r) => status?.providers[r.provider]?.configured);const shown = groups.flatMap((g) => g.models);const demo = status && status.demoMode !== "off" && shown.some((m) => !ready(m));@@ -358,6 +397,7 @@ function PickerList({gpu={m.engine === "open" ? badgeFor(badges, { modelId: m.id }) : null}gpuName={badges?.gpu}needs={needsKey(m, status)}+ made={m.id === madeWith}/></CommandItem>))}diff --git a/src/components/studio/preset-chips.tsx b/src/components/studio/preset-chips.tsxindex e3a34a0e..7a3df6b3 100644--- a/src/components/studio/preset-chips.tsx+++ b/src/components/studio/preset-chips.tsx@@ -165,15 +165,22 @@ export function PresetChip({ type, value, onChange }: { type: "motion" | "effectconst pct = (n: number) => `${Math.round(n * 100)}%`;-/** Higgsfield's Mix: a second motion or effect on top of the first, each with a strength. */+/**+ * Higgsfield's Mix: a second motion or effect on top of the first, each with a strength. The first one's strength scales+ * its LoRAs, so its slider shows only on a model that runs them (`strengthOn` names the model that does, otherwise).+ */export function MixChip({primary,strength,+ takesStrength = true,+ strengthOn,mix,onChange,}: {primary: Preset;strength: number;+ takesStrength?: boolean;+ strengthOn?: string;mix?: { presetId: string; strength: number };onChange: (patch: { presetStrength?: number; mix?: { presetId: string; strength: number } | undefined }) => void;}) {@@ -207,13 +214,19 @@ export function MixChip({</PopoverTrigger><PopoverContent className={cn(POPOVER_HEIGHT, "w-[min(92vw,460px)] space-y-3 p-3")} align="start" side={side} collisionPadding={12} aria-label="Mix"><div className="space-y-2.5">- <div className="space-y-1.5">- <div className="flex items-center justify-between text-[12px]">- <span className="font-medium">{primary.name}</span>- <span className="text-muted-foreground tabular-nums">{pct(strength)}</span>+ {takesStrength ? (+ <div className="space-y-1.5">+ <div className="flex items-center justify-between text-[12px]">+ <span className="font-medium">{primary.name}</span>+ <span className="text-muted-foreground tabular-nums">{pct(strength)}</span>+ </div>+ <Slider min={0.1} max={1} step={0.05} value={[strength]} onValueChange={([v]) => onChange({ presetStrength: v })} aria-label={`${primary.name} strength`} /></div>- <Slider min={0.1} max={1} step={0.05} value={[strength]} onValueChange={([v]) => onChange({ presetStrength: v })} aria-label={`${primary.name} strength`} />- </div>+ ) : (+ <p className="text-[12px] text-muted-foreground">+ <span className="font-medium text-foreground">{primary.name}</span> runs at full strength{strengthOn ? `; its strength can be set on ${strengthOn}` : ""}.+ </p>+ )}{second && mix && (<div className="space-y-1.5"><div className="flex items-center justify-between text-[12px]">@@ -243,6 +256,8 @@ export default function PresetChips({preset,presetId,strength,+ takesStrength,+ strengthOn,mix,onPreset,onMix,@@ -251,6 +266,9 @@ export default function PresetChips({preset?: Preset;presetId?: string;strength: number;+ /** The run's model scales the move's LoRAs (its strength slider shows); `strengthOn`: the model that does, otherwise. */+ takesStrength?: boolean;+ strengthOn?: string;mix?: { presetId: string; strength: number };onPreset: (id?: string) => void;onMix: (patch: { presetStrength?: number; mix?: { presetId: string; strength: number } | undefined }) => void;@@ -258,7 +276,7 @@ export default function PresetChips({return (<>{picker && <PresetChip type={picker} value={presetId} onChange={onPreset} />}- {preset && (preset.type === "motion" || preset.type === "effect") && <MixChip primary={preset} strength={strength} mix={mix} onChange={onMix} />}+ {preset && (preset.type === "motion" || preset.type === "effect") && <MixChip primary={preset} strength={strength} takesStrength={takesStrength} strengthOn={strengthOn} mix={mix} onChange={onMix} />}</>);}diff --git a/src/components/studio/studio-context.tsx b/src/components/studio/studio-context.tsxindex 3cb6f2bd..3bd52b5c 100644--- a/src/components/studio/studio-context.tsx+++ b/src/components/studio/studio-context.tsx@@ -1,7 +1,7 @@"use client";import { createContext, useCallback, useContext, useMemo, useState } from "react";-import type { GenParams, InputSlot, MediaKind, Operation, Preset } from "@/lib/catalog/types";+import type { Engine, GenParams, InputSlot, MediaKind, Operation, Preset } from "@/lib/catalog/types";import type { FeedFilter } from "@/lib/api";import type { Signature } from "@/lib/catalog/palettes";import type { FrameAttachment } from "@/lib/composer";@@ -32,6 +32,11 @@ export interface StudioConfig {presetPicker?: "motion" | "effect";preset?: Preset;defaultModels: { cloud: string; open: string };+ /**+ * An app's models on each engine (withRecipe, src/lib/catalog/preset-recipes.ts): the one its preview was made with+ * first, then its own route's. With two on the engine the composer offers both in place of the model chip.+ */+ appModels?: Record<Engine, string[]>;/*** The default to open on instead where the server can't write the default's caption for this viewer (Ideogram 4 for an* account, a guest, or an install with no local model answering: writesCaptions in src/lib/composer.ts).diff --git a/src/components/studio/studio-page.tsx b/src/components/studio/studio-page.tsxindex 293a65e5..d5aa0dab 100644--- a/src/components/studio/studio-page.tsx+++ b/src/components/studio/studio-page.tsx@@ -12,7 +12,8 @@ import { HeaderPill } from "@/components/gpu/readiness-chip";import { badgeFor, openGpuSetup, useGpuBadges } from "@/hooks/use-gpu";import type { Generation, MediaKind, ModelDef, Preset } from "@/lib/catalog/types";import { GUEST_PROMPT_EVENT, useEngine, useGenerations, useIsGuest } from "@/lib/api";-import { claimStartToken, followEngineDefault, handoffKey, mergeHandoff, presetModel, promptShown, START_PARAM, withoutStart, withPreset } from "@/lib/composer";+import { claimStartToken, followEngineDefault, handoffKey, mergeHandoff, presetModel, presetParams, promptShown, routeParams, START_PARAM, withoutStart, withPreset } from "@/lib/composer";+import { presetGpuKey, presetRoutes } from "@/lib/catalog/preset-recipe-routes";import { positionsFrom } from "@/lib/catalog/keyframes";import { reuseSignature, withSignatureWords } from "@/lib/catalog/palettes";import { movedAppRequest } from "@/lib/catalog/plan";@@ -48,21 +49,26 @@ function initialDraft(const preset = sp.get("preset") ? lookup.getPreset(sp.get("preset")!) : config.preset;// A link or Assist hand-off that names a model Fuobe retired opens on the one that replaced it (replaced.ts).const requested = sp.get("model") && currentModelId(sp.get("model")!);- // An app opened on one of its own models (?model=, from ⌘K) takes that model's route and params.- const presetRoute = preset- ? ([preset.cloud, preset.open].find((r) => !!requested && r?.modelId === requested) ?? (engine === "open" ? preset.open : preset.cloud) ?? preset.cloud ?? preset.open)- : null;- // A camera motion or effect starts on its Original (Fuobe DoP) when the studio has it.- const presetOwn = presetModel(preset, engine);+ const has = (id: string) => !!lookup.getModel(id);+ // An app starts on the model its preview was made with on this engine, else its own route (else the other engine's,+ // for an app with no version here); opened on one of its models (?model=, from ⌘K), on that model's route.+ const other = engine === "open" ? "cloud" : "open";+ const appRoutes = preset?.type === "app" ? [...presetRoutes(preset, engine, has), ...presetRoutes(preset, other, has)] : [];+ const appRoute = appRoutes.find((r) => !!requested && r.modelId === requested) ?? appRoutes[0];+ // A camera motion or effect starts on the model its preview was made with (MiniMax H3), else its Original (Fuobe DoP),+ // when the studio has it.+ const presetOwn = presetModel(preset, engine, has);const modelId =(requested && lookup.getModel(requested)?.id) ||- (preset?.type === "app" ? presetRoute?.modelId : undefined) ||+ appRoute?.modelId ||(presetOwn && lookup.getModel(presetOwn)?.id) ||config.defaultModels[engine] ||config.defaultModels.cloud ||// Open-only tools (Match colors) keep their open model under the Cloud switch, like cloud-only ones do under Open.config.defaultModels.open;const model = lookup.getModel(modelId);+ // The route's own settings (Wan 2.2 at 480p; a recipe on H3 at the Quality its cover was made at) on its own model.+ const routeSettings = appRoute && modelId === appRoute.modelId ? routeParams(appRoute, "app") : presetOwn && modelId === presetOwn ? presetParams(preset, engine, has) : {};const slots: Draft["slots"] = {};const imageSlot = config.slots.find((s) => s.accept === "image")?.key ?? preset?.inputs.find((s) => s.accept === "image")?.key;const refs: SlotValue[] = [];@@ -79,7 +85,7 @@ function initialDraft(prompt: sp.get("prompt") ?? "",negativePrompt: "",modelId,- params: { ...model?.defaults, ...(preset?.type === "app" ? presetRoute?.params : {}), ...(format && { format }) },+ params: { ...model?.defaults, ...routeSettings, ...(format && { format }) },slots,refs,presetId: sp.get("preset") ?? config.preset?.id,@@ -209,6 +215,13 @@ function ActivePresetHeader() {preset={preset}className="mb-3"modelName={(id) => catalog.getModel(id)?.name}+ gpuKey={presetGpuKey(+ preset,+ (id) => !!catalog.getModel(id),+ draft.modelId,+ draft.params.extra?.quality,+ catalog.getModel(draft.modelId)?.options.controls?.find((c) => c.param === "quality")?.default,+ )}onClear={config.preset? undefined@@ -314,16 +327,21 @@ function StudioExamples({ row }: { row: StudioExampleRow }) {*/function StudioGpuPill() {const { config, draft } = useStudio();+ const catalog = useCatalog();const [engine] = useEngine();const badges = useGpuBadges().data;if (engine !== "open" || !badges?.connected) return null;const modelId = draft.modelId || config.defaultModels.open;const presetId = draft.presetId ?? config.preset?.id;- const preset = presetId ? badges.presets[presetId] : undefined;+ // A preset's badge describes its route on the model picked, at the route's Quality (presetGpuKey, as the composer).+ const p = presetId ? catalog.getPreset(presetId) : undefined;+ const m = catalog.getModel(modelId);+ const key = p ? presetGpuKey(p, (id) => !!catalog.getModel(id), modelId, draft.params.extra?.quality, m?.options.controls?.find((c) => c.param === "quality")?.default) : undefined;+ const preset = key ? badges.presets[key] : undefined;const op = config.ops.find((o) => badges.models[`${modelId}#${o}`]);const badge = preset ?? (op ? badges.models[`${modelId}#${op}`] : badgeFor(badges, { modelId }));if (!badge) return null;- const ref = preset && presetId ? `preset:${presetId}` : `model:${modelId}#${op ?? Object.keys(badges.models).find((k) => k.startsWith(`${modelId}#`))?.split("#")[1] ?? ""}`;+ const ref = preset && key ? `preset:${key}` : `model:${modelId}#${op ?? Object.keys(badges.models).find((k) => k.startsWith(`${modelId}#`))?.split("#")[1] ?? ""}`;return <HeaderPill badge={badge} gpu={badges.gpu} compact onOpen={() => openGpuSetup({ ref })} />;}diff --git a/src/lib/catalog/plan.ts b/src/lib/catalog/plan.tsindex b71363ce..4881794c 100644--- a/src/lib/catalog/plan.ts+++ b/src/lib/catalog/plan.ts@@ -17,6 +17,7 @@ import { anglesPrompt, anglesWords, ANGLES_ORIGINAL } from "./open-tools";import { askedSize, numFramesValue, sizeValue } from "./payload";import { characterScale, CINEMA_CROP, soulKind, soulMegapixels, soulRecipe, soulSize, type SoulOverlay } from "./soul";import { pricingOn, type PriceClock } from "./promo";+import { presetRoutes } from "./preset-recipe-routes";export { pricingAt } from "./promo";@@ -110,10 +111,13 @@ export function composeShots(overall: string, shots: { prompt: string; duration:return [overall.trim() && `${overall.trim().replace(/[.\s]+$/, "")}.`, ...parts].filter(Boolean).join(" ");}+/** The preset's own route on an engine (its recipe, the route its preview was made with, is in presetRoutes). */export function presetRoute(preset: Preset, engine: Engine): PresetRoute | null {return engine === "open" ? preset.open : preset.cloud;}+export { presetRoutes };+/*** The model apps ran on before they moved to a newer one (2026-10-31, the owner's newest image models): the edit apps* left Qwen-Image-Edit 2511, Expand and Zoom Out left FLUX Fill, both for Qwen-Image 2.1.@@ -236,17 +240,29 @@ export function planGeneration(let op: Operation | undefined = req.op;if (preset) {- const route = presetRoute(preset, model.engine);- if (!route) throw new Error(`${preset.name} has no ${model.engine === "open" ? "open-source" : "cloud"} version yet`);- if (route.modelId !== model.id && !preset.type.match(/motion|effect/)) {- // Apps pin their model; motions/effects let the user pick any compatible video model.- throw new Error(`${preset.name} runs on ${route.modelId}, not ${model.id}`);+ // The preset's routes on this engine: the one its preview was made with (when this catalog has its model), then its own.+ const routes = presetRoutes(preset, model.engine, (id) => !!getModel(id));+ if (!routes.length) throw new Error(`${preset.name} has no ${model.engine === "open" ? "open-source" : "cloud"} version yet`);+ const matched = routes.find((r) => r.modelId === model.id);+ if (!matched && !preset.type.match(/motion|effect/)) {+ // Apps run on their own models; motions/effects let the user pick any compatible video model.+ throw new Error(`${preset.name} runs on ${[...new Set(routes.map((r) => r.modelId))].join(" or ")}, not ${model.id}`);}- // Preset params/LoRAs are tuned for the preset's own model; other compatible models only get the prompt (without+ const route = matched ?? routes[0];+ // Preset params/LoRAs are tuned for the route's own model; other compatible models only get the prompt (without// a LoRA's trigger word, which means nothing to them).- const sameModel = route.modelId === model.id;- prompt = composePrompt((sameModel || preset.type === "app" ? route.promptTemplate : undefined) ?? preset.promptTemplate, req.prompt, preset, req.presetOptions);- params = { ...model.defaults, ...(sameModel ? route.params : {}), ...req.params };+ const sameModel = !!matched;+ prompt = composePrompt((sameModel ? route.promptTemplate : undefined) ?? preset.promptTemplate, req.prompt, preset, req.presetOptions);+ // The route's extra settings (H3's orbit, a camera pose) stay under what the request sets itself. A setting the composer+ // shows as a control (H3's Quality) is the request's own: the composer starts it at the route's value, and its Auto+ // sends none, which is the model's default.+ const shown = new Set((model.options.controls ?? []).map((c) => c.param));+ const routeExtra = Object.fromEntries(Object.entries(route.params?.extra ?? {}).filter(([k]) => !shown.has(k)));+ const routePlain = { ...route.params };+ delete routePlain.extra;+ const hasExtra = Object.keys(routeExtra).length > 0 || !!req.params?.extra;+ const extra = sameModel && hasExtra ? { extra: { ...routeExtra, ...req.params?.extra } } : {};+ params = { ...model.defaults, ...(sameModel ? routePlain : {}), ...req.params, ...extra };// Option choices that set model settings (Angles: rotate / tilt / zoom); a value the user set wins.const chosen = Object.assign({}, ...(preset.options ?? []).map((o) => o.choices.find((c) => c.value === (req.presetOptions?.[o.key] ?? o.default ?? o.choices[0]?.value))?.extra ?? {}));if (sameModel && Object.keys(chosen).length) params = { ...params, extra: { ...chosen, ...params.extra } };diff --git a/src/lib/catalog/preset-recipe-routes.ts b/src/lib/catalog/preset-recipe-routes.tsnew file mode 100644index 00000000..f9a9dc54--- /dev/null+++ b/src/lib/catalog/preset-recipe-routes.ts@@ -0,0 +1,231 @@+/**+ * A preset's recipe: the model and settings its preview was made with, per engine. A preset opens on it, and its own+ * route (preset.open / preset.cloud) stays as the second choice: Fuobe DoP's LoRAs, Mix, start-frame steps and grades+ * read those routes, and a viewer whose catalog lacks the recipe's model runs them as before.+ *+ * Pure and light: no catalog or covers import, so the composer and the planner read it in the browser. Which presets'+ * previews really came from their recipe (the "Used for this preview" label) is in ./preset-recipes.ts, which reads the+ * covers manifest.+ *+ * The rules, in order:+ * 1. No recipe: effects with a start-frame step (their step feeds Fuobe DoP), colour-grade effects (Fuobe DoP's clip is+ * graded afterwards), and the apps in OWN_ROUTE_APPS.+ * 2. MiniMax H3: every other camera motion and effect, and every app whose route is image-to-video or start-and-end+ * frame: the preset's own operation from the person's picture, 5 s, at the Quality its cover was made at (Best is+ * set; Fast is H3's default). The orbit presets run H3's Orbit LoRA. Many covers ran H3 from their start frame to an+ * end frame edited beforehand; a recipe starts from the picture alone.+ * 3. Qwen-Image 2.1 Turbo: the edit apps on Qwen-Image 2.1, with the same words (images named by position become+ * <image1>, <image2>, as the encoder reads them), the specialist apps, in the words their covers were made with, and+ * Angles, in the app's own words (its Multiple-Angles LoRA route stays second).+ * 4. Expand Image, Zoom Out and Zooms: their own Qwen-Image 2.1 route is their recipe.+ * Only H3 recipes have a cloud side: there is no hosted Qwen-Image 2.1.+ */+import type { Engine, Operation, Preset, PresetRoute } from "./types";++/** What the rules read of a preset. */+export type RecipePreset = Pick<Preset, "id" | "type" | "open" | "cloud" | "prestep" | "promptTemplate" | "grade">;++/** Whether the viewer's catalog has a model (the server's full catalog, or a studio's slice in the browser). */+export type HasModel = (id: string) => boolean;++export const H3_OPEN = "oss-minimax-h3";+export const H3_CLOUD = "minimax-h3";+export const QWEN_21 = "oss-qwen-image-21";+export const QWEN_21_TURBO = "oss-qwen-image-21-turbo";++/** The kind of recipe a preset has, for the label's rules and the tests. */+export type RecipeKind = "h3" | "orbit" | "turbo" | "specialist" | "words" | "own";++/**+ * Apps that keep their own route.+ * - Fuobe Angles: its camera fields drive the Multiple-angles LoRA.+ * - AI Influencer: it draws in the Soul Cast look, with its LoRAs.+ * - Shots, What's Next: camera turns, which the 25-step Qwen-Image 2.1 holds better than its Turbo.+ * - ASMR Host, ASMR Promo, Talking Photo: they speak with the person's own voice track.+ * - Recast, Video Face Swap: they carry a performance over from a clip.+ * - 3D Rotation: its Rotate LoRA turns the subject into a solid object that spins in place.+ * - Remove Background, Upscale, Vectorize, Video Background Remover, Image to 3D: tools, whose covers show the idea.+ */+export const OWN_ROUTE_APPS: ReadonlySet<string> = new Set([+ "app-fuobe-angles",+ "app-ai-influencer",+ "app-shots",+ "app-what-s-next",+ "app-asmr-host",+ "app-asmr-promo",+ "app-talking-photo",+ "app-recast",+ "app-video-face-swap",+ "app-3d-rotation",+ "app-remove-background",+ "app-upscale",+ "app-vectorize",+ "app-video-background-remover",+ "app-image-to-3d",+]);++/** Presets whose clip was made on H3's 20-step graph (Quality: Best); the others on its 8-step Turbo graph (Fast). */+export const BEST_QUALITY_PRESETS: ReadonlySet<string> = new Set([+ "app-macro-scene",+ "app-macroshot-product",+ "motion-crash-zoom-in",+ "motion-whip-pan",+ "motion-snorricam",+ "motion-catwalk",+ "motion-downhill-pov",+ "motion-fisheye",+ "motion-fpv-drone",+ "motion-drone-reveal",+ "motion-aerial-pullback",+ "motion-road-rush",+ "motion-robo-arm",+ "motion-robot-arm",+ "motion-timelapse",+ "motion-roll-transition",+ "motion-flying-cam-transition",+ "motion-skate-cruise",+ "effect-bloom-mouth",+ "effect-black-tears",+ "effect-exploded-view",+ "effect-lacewalker",+ "effect-lidar-transition",+ "effect-pigeons",+ "effect-particles",+]);++/**+ * Presets made with H3's Orbit LoRA: one frozen instant, the camera circling it (73 frames, about 3 s). The orbit keeps+ * the picture as it is, so an app whose words add to the scene (Bullet Time Splash's water, Bullet Time White's+ * cyclorama) runs H3's image-to-video in its own words instead.+ */+export const ORBIT_PRESETS: ReadonlySet<string> = new Set([+ "app-product-360",+ "app-bullet-time-scene",+ "motion-360-orbit",+ "motion-3d-rotation",+ "motion-bullet-time",+ "effect-frozen-in-motion",+]);++/**+ * The orbit's words: the Orbit LoRA's training caption as the cover graph sends it, word for word, keeping the sentences+ * that describe the shot; then the person's own words.+ */+export const ORBIT_WORDS =+ "One frozen instant. Only the camera moves. In a continuous 360 orbit. Preserve every person and object in exactly the same world position, orientation, shape and pose throughout the shot. Airborne objects remain suspended at the captured height and angle. Keep faces, hands, clothing, liquids and the background motionless while retaining their natural appearance. Camera parallax is the only source of apparent movement. {prompt}";++/**+ * Apps on Qwen-Image 2.1 Turbo in the app's own words (its options become words): Angles, whose cover's new view came+ * from the Turbo. Its Multiple-Angles LoRA route on Qwen-Image-Edit 2511 stays second.+ */+export const WORDS_APPS: ReadonlySet<string> = new Set(["app-angles"]);++/** Apps whose recipe is their own Qwen-Image 2.1 route (their covers came from it). */+export const OWN_QWEN_APPS: ReadonlySet<string> = new Set(["app-expand-image", "app-zoom-out", "app-zooms"]);++/**+ * The specialist apps on Qwen-Image 2.1 Turbo, in the words their covers were made with: the picture is <image1>, the+ * reference <image2>. Each keeps its options ({option:…}).+ */+export const SPECIALIST_TEMPLATES: Readonly<Record<string, string>> = {+ "app-face-swap":+ "Replace the face of the person in <image1> with the face of the person in <image2>: their eyes, brows, nose, mouth, skin tone and features, lit by the same light as <image1> and turned to the same head angle. Show one person only. Keep the hair, clothing, pose, setting and framing exactly as in <image1>.",+ "app-relight":+ "Relight <image1> with {option:light} {option:dir}: the light, shadows, reflections and colour temperature follow the new light. Keep the subject, their pose, face and hair, the setting, every detail and the framing exactly as in <image1>.",+ "app-match-lighting":+ "Relight <image1> to match the lighting in <image2>: the same light direction, softness, colour temperature, contrast and mood, with the shadows and reflections that light casts. Keep the subject, their pose, face and hair, the setting, every detail and the framing exactly as in <image1>.",+ "app-match-colors":+ "Recolour <image1> with the colour palette and grade of <image2>: the same hues, saturation, contrast and tones in the shadows and highlights throughout. Keep every person and object, every shape and detail, the light direction and the framing exactly as in <image1>.",+ "app-product-shot":+ "Replace the background of <image1>: the product {option:scene}. {prompt}. Keep the product, its shape, colours, label, position and size, and the framing exactly as in <image1>. Reproduce only what is visible in <image1>; where a surface is plain it stays plain.",+ "app-virtual-try-on":+ "Dress the person from <image1> in the garment from <image2>, keeping the person exactly as in <image1> and the garment exactly as in <image2>: its fabric, colour, pattern, logo and fit, with natural folds and shadows. Keep the pose, face, camera angle, background and framing exactly as in <image1>. Show one person only.",+};++const ORDINAL: Record<string, number> = { first: 1, second: 2, third: 3, fourth: 4 };++/**+ * An app's words with the images it names by position as Qwen-Image 2.1's encoder names them: "the first image" →+ * <image1>, "image 2" → <image2>. Unchanged when it names none.+ */+export function imageTags(words: string): string {+ return words+ .replace(/\b(?:the )?(first|second|third|fourth) image\b/gi, (_, n: string) => `<image${ORDINAL[n.toLowerCase()]}>`)+ .replace(/\bimage ([1-4])\b/gi, (_, n: string) => `<image${n}>`);+}++const VIDEO_OPS = new Set<Operation>(["i2v", "flf2v"]);++/** Which recipe a preset has (the same on both engines). */+export function recipeKind(p: RecipePreset): RecipeKind | undefined {+ if (p.prestep || p.grade || OWN_ROUTE_APPS.has(p.id)) return undefined;+ const own = p.open ?? p.cloud;+ if (p.type !== "app" || (own && VIDEO_OPS.has(own.op))) {+ if (!own || !VIDEO_OPS.has(own.op)) return undefined;+ return ORBIT_PRESETS.has(p.id) ? "orbit" : "h3";+ }+ if (SPECIALIST_TEMPLATES[p.id]) return "specialist";+ if (WORDS_APPS.has(p.id)) return "words";+ if (OWN_QWEN_APPS.has(p.id)) return p.open?.modelId === QWEN_21 ? "own" : undefined;+ if (p.open?.modelId === QWEN_21 && p.open.op === "edit") return "turbo";+ return undefined;+}++/** The recipe's route on an engine, whether or not the viewer's catalog has its model. */+export function recipeRoute(p: RecipePreset, engine: Engine): PresetRoute | undefined {+ const kind = recipeKind(p);+ if (!kind) return undefined;+ const own = (p.open ?? p.cloud)!;+ if (kind === "orbit") {+ return engine === "open"+ ? { modelId: H3_OPEN, op: "i2v", params: { duration: 3, extra: { orbit: true } }, promptTemplate: ORBIT_WORDS }+ : // Hosted H3 makes 5 s at the least, and has no Orbit LoRA: the orbit's words alone.+ { modelId: H3_CLOUD, op: "i2v", params: { duration: 5 }, promptTemplate: ORBIT_WORDS };+ }+ if (kind === "h3") {+ if (engine === "cloud") return { modelId: H3_CLOUD, op: own.op, params: { duration: 5 } };+ // Fast is H3's default Quality: only Best is set.+ return { modelId: H3_OPEN, op: own.op, params: { duration: 5, ...(BEST_QUALITY_PRESETS.has(p.id) && { extra: { quality: "best" } }) } };+ }+ // The rest are Qwen-Image 2.1 recipes: none is hosted.+ if (engine === "cloud") return undefined;+ if (kind === "own") return p.open!;+ if (kind === "specialist") return { modelId: QWEN_21_TURBO, op: "edit", promptTemplate: SPECIALIST_TEMPLATES[p.id] };+ if (kind === "words") return { modelId: QWEN_21_TURBO, op: "edit", promptTemplate: imageTags(p.promptTemplate) };+ const words = p.open!.promptTemplate ?? p.promptTemplate;+ const tagged = imageTags(words);+ return { ...p.open!, modelId: QWEN_21_TURBO, ...(tagged !== words && { promptTemplate: tagged }) };+}++/** The preset's own route on an engine. */+export const ownRoute = (p: Pick<Preset, "open" | "cloud">, engine: Engine): PresetRoute | null => (engine === "open" ? p.open : p.cloud);++/**+ * The routes a preset runs on, on an engine, in order: its recipe (when the viewer's catalog has its model), then its own+ * route. Empty when it has no version there.+ */+export function presetRoutes(p: RecipePreset, engine: Engine, has: HasModel): PresetRoute[] {+ const recipe = recipeRoute(p, engine);+ const own = ownRoute(p, engine);+ return [...(recipe && has(recipe.modelId) ? [recipe] : []), ...(own ? [own] : [])];+}++/**+ * The key of a preset's GPU badge for a run on a model (src/server/gpu/tools.ts presetTool): "<id>" on its first open+ * route, "<id>@<model id>" on another. Undefined on a model the preset has no open route on, and when the run's Quality+ * isn't the one the route's graph was picked for (`quality`, `defaultQuality`: the draft's and the model's): the model's+ * own badge applies then.+ */+export function presetGpuKey(p: RecipePreset, has: HasModel, modelId: string | undefined, quality?: unknown, defaultQuality?: unknown): string | undefined {+ if (!p.open || !modelId) return undefined;+ const routes = presetRoutes(p, "open", has);+ const route = routes.find((r) => r.modelId === modelId);+ if (!route) return undefined;+ if ((route.params?.extra?.quality ?? defaultQuality) !== (quality ?? defaultQuality)) return undefined;+ return routes[0].modelId === modelId ? p.id : `${p.id}@${modelId}`;+}++/** The models an app runs on, on an engine: its recipe's first, then its own route's (once each). */+export function appModels(p: RecipePreset, engine: Engine, has: HasModel): string[] {+ return [...new Set(presetRoutes(p, engine, has).map((r) => r.modelId))];+}diff --git a/src/lib/catalog/preset-recipes.ts b/src/lib/catalog/preset-recipes.tsnew file mode 100644index 00000000..ea0d1d97--- /dev/null+++ b/src/lib/catalog/preset-recipes.ts@@ -0,0 +1,61 @@+/**+ * A preset's recipe (./preset-recipe-routes.ts) and whether its live preview really came from it: the "Used for this+ * preview" label next to the model, in the model picker, the preset card's details and the app's model chip.+ *+ * It reads the covers manifest (preset-previews.generated.ts, the model each cover was made with), so the browser loads+ * it in its own chunk: the composer's helpers and the planner read the light module instead. A cover that is still a+ * still gets its recipe without the label; the label turns on when its clip is published (pnpm eval:covers).+ */+import type { StudioConfig } from "@/components/studio/studio-context";+import { PRESET_PREVIEWS } from "../preset-previews.generated";+import { appModels, ORBIT_PRESETS, presetRoutes, recipeKind, recipeRoute, type HasModel, type RecipePreset } from "./preset-recipe-routes";+import type { Engine, PresetRoute } from "./types";++export * from "./preset-recipe-routes";++export interface PresetRecipe {+ route: PresetRoute;+ /** Its live preview came from this route's model (the label shows). */+ made: boolean;+}++/** The cover models (PresetPreviewMedia.model): an H3 clip, and an Ideogram 4 still with its Qwen-Image 2.1 edit. */+const H3_COVER = "minimax-h3";+const QWEN_COVER = "ideogram4+qwen-image-2.1-edit";+/** Image apps whose cover is an H3 clip morphing into their Qwen-Image 2.1 picture. */+const QWEN_MORPHS: ReadonlySet<string> = new Set(["app-age-shift", "app-angles", "app-zooms"]);++/** Whether the preset's live preview was made by its recipe on this engine. */+export function recipeMade(p: RecipePreset, engine: Engine): boolean {+ const kind = recipeKind(p);+ const cover = PRESET_PREVIEWS[p.id]?.model;+ if (!kind || !cover) return false;+ // Hosted H3 is the same model; the Orbit LoRA runs on the open engine only.+ if (kind === "h3" || kind === "orbit") return cover === H3_COVER && (engine === "open" || !ORBIT_PRESETS.has(p.id));+ return engine === "open" && (cover === QWEN_COVER || (cover === H3_COVER && QWEN_MORPHS.has(p.id)));+}++/** The route that made the preset's preview, on an engine, when the viewer's catalog has its model; else undefined. */+export function presetRecipe(preset: RecipePreset, engine: Engine, has: HasModel): PresetRecipe | undefined {+ const route = recipeRoute(preset, engine);+ if (!route || !has(route.modelId)) return undefined;+ return { route, made: recipeMade(preset, engine) };+}++/**+ * An app's studio with its recipe first: its default model on each engine is the recipe's (else its own route's), its+ * operations include the recipe's (Face Swap and Match Colors gain the edit), and `appModels` lists both models per+ * engine for the composer's picker. A preset without a recipe keeps the config it has.+ */+export function withRecipe(config: StudioConfig, has: HasModel): StudioConfig {+ const preset = config.preset;+ if (preset?.type !== "app") return config;+ const models = { cloud: appModels(preset, "cloud", has), open: appModels(preset, "open", has) };+ const routes = [...presetRoutes(preset, "cloud", has), ...presetRoutes(preset, "open", has)];+ return {+ ...config,+ ops: [...new Set([...config.ops, ...routes.map((r) => r.op)])],+ defaultModels: { cloud: models.cloud[0] ?? config.defaultModels.cloud, open: models.open[0] ?? config.defaultModels.open },+ appModels: models,+ };+}diff --git a/src/lib/composer.ts b/src/lib/composer.tsindex 0562c409..c7f1c24b 100644--- a/src/lib/composer.ts+++ b/src/lib/composer.ts@@ -12,7 +12,8 @@ import { addFrameAt, frameTimes, framesInputs, removeFrameAt, spread, type Frameimport { FACE_MOSAIC_MODELS } from "./catalog/open-tools";import { pricingOn, type PriceClock } from "./catalog/promo";import { soulPostStep } from "./catalog/soul";-import { COLORMAPS, type Engine, type GenParams, type InputSlot, type MatteOutput, type MediaKind, type ModelDef, type Operation, type Preset, type VideoFormat } from "./catalog/types";+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 { spokenLanguageName } from "./speech-languages";// ---------------------------------------------------------------------------@@ -683,37 +684,99 @@ export interface DraftShape {const same = (a: unknown, b: unknown) => a === b || JSON.stringify(a ?? null) === JSON.stringify(b ?? null);const sameAttachment = (a: Attachment | null | undefined, b: Attachment | null | undefined) => (a ?? null) === (b ?? null) || (!!a && !!b && a.id === b.id && a.ref === b.ref);-type PresetRoutes = Pick<Preset, "type" | "open" | "cloud">;+type PresetRoutes = RecipePreset;++const isMove = (preset: PresetRoutes | undefined): preset is PresetRoutes => preset?.type === "motion" || preset?.type === "effect";/**- * The model a camera motion or effect runs on by default on an engine (Fuobe DoP, or the route its move names: a- * camera LoRA in the cloud runs on Fuobe DoP · LTX; a move with nothing of the Original's own in the cloud keeps its- * partner model there). Undefined for apps (their model is pinned) and without a preset.+ * The route a camera motion or effect runs on by default on an engine: the one its preview was made with (MiniMax H3)+ * when the viewer's catalog has its model (`has`), else its own (Fuobe DoP, or the route its move names: a camera LoRA+ * in the cloud runs on Fuobe DoP · LTX; a move with nothing of the Original's own in the cloud keeps its partner model+ * there). Undefined for apps and without a preset.*/-export function presetModel(preset: PresetRoutes | undefined, engine: Engine): string | undefined {- if (!preset || (preset.type !== "motion" && preset.type !== "effect")) return undefined;- return (engine === "open" ? preset.open : preset.cloud)?.modelId;+function moveRoute(preset: PresetRoutes | undefined, engine: Engine, has: HasModel): PresetRoute | undefined {+ return isMove(preset) ? presetRoutes(preset, engine, has)[0] : undefined;+}++/** The model a camera motion or effect runs on by default on an engine (moveRoute). Undefined for apps and without a preset. */+export function presetModel(preset: PresetRoutes | undefined, engine: Engine, has: HasModel): string | undefined {+ return moveRoute(preset, engine, has)?.modelId;}/**- * The Original a camera motion or effect moves the composer to when it is picked or linked (Fuobe DoP on this engine).- * Never a partner route (a move Fuobe DoP has nothing of its own for in the cloud): the person's model stays.+ * The model a camera motion or effect moves the composer to when it is picked or linked: its recipe's (MiniMax H3),+ * else its Original (Fuobe DoP on this engine). Never a partner route (a move Fuobe DoP has nothing of its own for in+ * the cloud): the person's model stays.*/-export function presetOriginal(preset: PresetRoutes | undefined, engine: Engine): string | undefined {- const route = preset && presetModel(preset, engine) ? (engine === "open" ? preset.open : preset.cloud) : undefined;+export function presetOriginal(preset: PresetRoutes | undefined, engine: Engine, has: HasModel): string | undefined {+ const route = moveRoute(preset, engine, has);return route && !route.partner ? route.modelId : undefined;}/**- * The settings a preset's route starts the composer with on its model (Focus Change: 6 s, 720p, silent), over the- * model's defaults. Only plain values the composer shows: the route's extra (a camera LoRA, a pose) stays the- * preset's, so the next preset picked on the same model doesn't inherit it.+ * The settings a preset's route starts the composer with on its model (Focus Change: 6 s, 720p, silent; a recipe on H3:+ * 5 s at the Quality its cover was made at), over the model's defaults. Only values the composer shows: the route's other+ * extras (a camera LoRA, a pose, the orbit) stay the preset's, so the next preset picked on the same model doesn't inherit+ * them. The planner adds them to the run.+ */+export function presetParams(preset: PresetRoutes | undefined, engine: Engine, has: HasModel): GenParams {+ return routeParams(moveRoute(preset, engine, has), "motion");+}++/**+ * The settings a preset's route starts the composer with: an app's route's as they are (they are its own); a camera+ * motion's or effect's plain ones and its Quality (presetParams).*/-export function presetParams(preset: PresetRoutes | undefined, engine: Engine): GenParams {- const route = preset && presetModel(preset, engine) ? (engine === "open" ? preset.open : preset.cloud) : undefined;+export function routeParams(route: Pick<PresetRoute, "params"> | undefined, type: Preset["type"]): GenParams {+ if (type === "app") return { ...route?.params };const plain: GenParams = { ...route?.params };+ const quality = route?.params?.extra?.quality;delete plain.extra;- return plain;+ return quality === undefined ? plain : { ...plain, extra: { quality } };+}++/**+ * A route's settings over a draft that is already on the route's model: each setting still at the model's default takes+ * the route's value (a linked preset that loads after the first draft: Whip Pan at Best, 360 Orbit at 3 s). A setting+ * the person changed stays. Undefined when nothing changes.+ */+export function untouchedParams(params: GenParams, defaults: GenParams, route: GenParams): GenParams | undefined {+ const next: Record<string, unknown> = { ...params };+ let changed = false;+ for (const [k, v] of Object.entries(route)) {+ if (k === "extra") continue;+ const now = (params as Record<string, unknown>)[k];+ if (same(now, (defaults as Record<string, unknown>)[k]) && !same(now, v)) {+ next[k] = v;+ changed = true;+ }+ }+ for (const [k, v] of Object.entries(route.extra ?? {})) {+ const now = params.extra?.[k];+ if (same(now, defaults.extra?.[k]) && !same(now, v)) {+ next.extra = { ...(next.extra as GenParams["extra"]), [k]: v };+ changed = true;+ }+ }+ return changed ? (next as GenParams) : undefined;+}++/** An app's route for a model on an engine (its recipe's or its own), if the app runs on that model there. */+export function appRoute(preset: PresetRoutes | undefined, engine: Engine, modelId: string, has: HasModel): PresetRoute | undefined {+ return preset?.type === "app" ? presetRoutes(preset, engine, has).find((r) => r.modelId === modelId) : undefined;+}++/**+ * Where the composer goes when the viewer can't run the route a preset opens on (its recipe: a Replicate-only account and+ * hosted MiniMax H3, which is on fal alone; a model switched off in Settings → Models & licences): the first of the+ * preset's other routes on this engine the viewer can run (`runs`). Undefined when the composer isn't on the first+ * route's model, the viewer can run it, or no other route runs for them (Generate then says what is missing).+ */+export function presetFallback(preset: PresetRoutes | undefined, engine: Engine, modelId: string | undefined, has: HasModel, runs: HasModel): PresetRoute | undefined {+ if (!preset || !modelId) return undefined;+ const routes = presetRoutes(preset, engine, has);+ if (routes.length < 2 || routes[0].modelId !== modelId || runs(modelId)) return undefined;+ return routes.slice(1).find((r) => r.modelId !== modelId && runs(r.modelId));}/**@@ -737,10 +800,12 @@ export function viewerDefaults<D extends { cloud: string; open: string }>(defaul/*** What the engine switch (or a model change) does to the composer's model: the model id to move to, or undefined to- * keep it. A model that doesn't run on the engine gives way to the preset's model there (an app's pinned route), else- * the studio's default. A camera motion or effect on its model for the other engine follows its move to this one's- * (Jib Up: Fuobe DoP on the GPU, Fuobe DoP · LTX in the cloud), but only when the engine has just changed: the sibling- * model picked on purpose on the same engine stays.+ * keep it. An app runs only on its own models for the engine (its recipe's, then its route's): any other model, even+ * one that also runs on this engine (Fuobe Soul, AI Influencer's cloud model), gives way to the first. A model that+ * doesn't run on the engine gives way to the preset's model there, else the studio's default. A camera motion or effect+ * on a model of the other engine follows its move to this one's (MiniMax H3 hosted → on the GPU; Jib Up: Fuobe DoP on+ * the GPU, Fuobe DoP · LTX in the cloud), but only when the engine has just changed: the sibling model picked on purpose+ * on the same engine stays.*/export function engineSwitchModel(o: {model: Pick<ModelDef, "id" | "engine">;@@ -749,13 +814,26 @@ export function engineSwitchModel(o: {/** The engine the composer was on before (the same one when only the model changed). */from: Engine;defaults: Partial<Record<Engine, string>>;+ has: HasModel;}): string | undefined {- const { model, preset, engine } = o;- const want = presetModel(preset, engine);- const other = presetModel(preset, engine === "open" ? "cloud" : "open");- const follows = o.from !== engine && !!want && want !== model.id && model.id === other;- if (model.engine === engine && !follows) return undefined;- if (preset?.type === "app") return engine === "open" ? preset.open?.modelId : preset.cloud?.modelId;+ const { model, preset, engine, has } = o;+ if (preset?.type === "app") {+ const ids = appModels(preset, engine, has);+ return ids.includes(model.id) || !ids.length ? undefined : ids[0];+ }+ const otherEngine: Engine = engine === "open" ? "cloud" : "open";+ const want = presetModel(preset, engine, has);+ // The same choice on the other engine (the recipe's model, or the move's own route's) moves to its sibling here.+ let follows: string | undefined;+ if (isMove(preset) && o.from !== engine) {+ const mine = presetRoutes(preset, engine, has);+ const theirs = presetRoutes(preset, otherEngine, has);+ const i = theirs.findIndex((r) => r.modelId === model.id);+ const sibling = i >= 0 ? (mine[i]?.modelId ?? want) : undefined;+ if (sibling && sibling !== model.id) follows = sibling;+ }+ if (follows) return follows;+ if (model.engine === engine) return undefined;return want ?? o.defaults[engine];}@@ -793,7 +871,8 @@ export function postStepCost(* preset's own model: a partner model runs the effect's words alone.*/export function prestepCost(preset: Pick<Preset, "type" | "open" | "cloud" | "prestep"> | undefined, modelId: string | undefined, engine: Engine): number {- if (!preset?.prestep || !modelId || presetModel(preset, engine) !== modelId) return 0;+ // A preset with a step has no recipe: its own route is the one that runs the step.+ if (!preset?.prestep || !modelId || ownRoute(preset, engine)?.modelId !== modelId) return 0;return preset.prestep[engine].usd ?? 0;}@@ -996,6 +1075,8 @@ export function groupModels(input: {recent: string[];starred: string[];best: string[];+ /** A short list in its own order (an app's models): one group. */+ flat?: boolean;}): { groups: ModelGroup[]; count: number } {const { models, engine, engines, query, recent, starred, best } = input;const q = query.trim();@@ -1009,6 +1090,7 @@ export function groupModels(input: {return { groups: hits.length ? [{ id: "results", label: "Results", models: hits }] : [], count: hits.length };}const pool = models.filter((m) => m.engine === engine);+ if (input.flat) return { groups: pool.length ? [{ id: "all", label: "Models", models: pool }] : [], count: pool.length };const byId = new Map(pool.map((m) => [m.id, m]));const used = new Set<string>();const take = (ids: string[], max: number) => {diff --git a/src/lib/preset-cards.ts b/src/lib/preset-cards.tsindex 2fa46148..fe9e1607 100644--- a/src/lib/preset-cards.ts+++ b/src/lib/preset-cards.ts@@ -501,21 +501,56 @@ function joinList(items: string[]): string {return `${items.slice(0, -1).join(", ")} and ${items[items.length - 1]}`;}+/** A line of the preset header's details popover: a model an engine runs a preset on. */+export interface PresetRouteLine {+ engine: "cloud" | "open";+ label: string;+ model: string | null;+ /** The preset's live preview was made with this model ("Used for this preview"). */+ made?: true;+ /** A second choice on the same engine (its own route, after the model its preview was made with). */+ alt?: true;+}++/**+ * The preset's note on how it runs (preset.parity) under its route lines. When it opens on the model its preview was+ * made with, the note is about its second choice, and says so: "Fuobe DoP: Wan 2.2 with …" reads "Or Fuobe DoP: …", and+ * "The open version …" names that model.+ */+export function parityNote(parity: string | undefined, lines: Pick<PresetRouteLine, "engine" | "model" | "alt">[]): string | undefined {+ if (!parity) return undefined;+ const alt = lines.filter((l) => l.alt);+ if (!alt.length) return parity;+ if (/^Fuobe DoP\b/.test(parity)) return `Or ${parity}`;+ const openAlt = alt.find((l) => l.engine === "open")?.model;+ if (openAlt && parity.startsWith("The open version ")) return `${openAlt}, the second choice on your GPU, ${parity.slice("The open version ".length)}`;+ return parity;+}+/*** Which model each engine runs a preset on, for the preset header's details popover (the studio- * hero no longer needs to spell out "Cloud: … · Open source: …").+ * hero no longer needs to spell out "Cloud: … · Open source: …"): the model its preview was made+ * with first (`recipeOf`, src/lib/catalog/preset-recipes.ts presetRecipe), then its own route.*/export function presetRouteLines(p: Pick<Preset, "cloud" | "open" | "parity">,nameOf: (modelId: string) => string | undefined = () => undefined,-): { engine: "cloud" | "open"; label: string; model: string | null }[] {- return (["cloud", "open"] as const).map((engine) => {+ recipeOf: (engine: "cloud" | "open") => { route: { modelId: string }; made: boolean } | undefined = () => undefined,+): PresetRouteLine[] {+ return (["cloud", "open"] as const).flatMap((engine) => {const route = p[engine];+ const label = engine === "cloud" ? "Cloud" : "Open source";const name = route ? (nameOf(route.modelId) ?? route.modelId) : null;// A LoRA licensed for the user's GPU only (civitai "RentCivit"): the cloud route keeps the preset's words until Fuobe// DoP with the LoRA is evaluated there; the licence is said, not enforced.const gpuOnly = engine === "cloud" && !route?.loras?.length && !!p.open?.loras?.length && p.open.loras.every((l) => l.licence?.hostedOk === false);- return { engine, label: engine === "cloud" ? "Cloud" : "Open source", model: name && gpuOnly ? `${name} · words only (its LoRA is licensed for your GPU only)` : name };+ const own: PresetRouteLine = { engine, label, model: name && gpuOnly ? `${name} · words only (its LoRA is licensed for your GPU only)` : name };+ const recipe = recipeOf(engine);+ if (!recipe) return [own];+ const first: PresetRouteLine = { engine, label, model: nameOf(recipe.route.modelId) ?? recipe.route.modelId, ...(recipe.made && { made: true as const }) };+ // The recipe on the preset's own model (Zooms on Qwen-Image 2.1) is one line.+ if (recipe.route.modelId === route?.modelId || !own.model) return [first];+ return [first, { ...own, alt: true as const }];});}diff --git a/src/lib/studio-catalog.ts b/src/lib/studio-catalog.tsindex a3bbe09e..f2e62256 100644--- a/src/lib/studio-catalog.ts+++ b/src/lib/studio-catalog.ts@@ -33,10 +33,12 @@ export function slimModel(m: ModelDef): ModelDef {};}-export function studioCatalog(config: Pick<StudioConfig, "kind" | "ops" | "pickerOps" | "defaultModels" | "preset" | "extraModels">): StudioCatalog {+export function studioCatalog(config: Pick<StudioConfig, "kind" | "ops" | "pickerOps" | "defaultModels" | "preset" | "extraModels" | "appModels">): StudioCatalog {const list = modelsFor({ kind: config.kind, ops: config.pickerOps ?? config.ops });const ids = new Set(list.map((m) => m.id));- const extra = [config.defaultModels.cloud, config.defaultModels.open, config.preset?.cloud?.modelId, config.preset?.open?.modelId]+ // An app's models on both engines: the one its preview was made with and its own route's (withRecipe).+ const own = [...(config.appModels?.cloud ?? []), ...(config.appModels?.open ?? [])];+ const extra = [config.defaultModels.cloud, config.defaultModels.open, config.preset?.cloud?.modelId, config.preset?.open?.modelId, ...own].filter((id): id is string => !!id && !ids.has(id)).map((id) => getModel(id)).filter((m): m is ModelDef => !!m);diff --git a/src/server/gpu/gate.ts b/src/server/gpu/gate.tsindex 09b33f59..eaafbda4 100644--- a/src/server/gpu/gate.ts+++ b/src/server/gpu/gate.ts@@ -52,7 +52,8 @@ export async function gateGeneration(t: GpuTarget, g: GateInput): Promise<GateRehas,});if (!has(id)) return { ok: true };- const preset = req.presetId ? presetTool(req.presetId) : null;+ // The preset's route on the run's model (the one its preview was made with, or its own): its LoRAs are checked too.+ const preset = req.presetId ? presetTool(req.presetId, { modelId: g.modelId }) : null;const model = modelTool(g.modelId, g.op);const ref: ToolRef = preset?.ref ?? model?.ref ?? `workflow:${id}`;const name = preset?.name ?? model?.name ?? id;diff --git a/src/server/gpu/readiness-service.ts b/src/server/gpu/readiness-service.tsindex a241b400..c1271825 100644--- a/src/server/gpu/readiness-service.ts+++ b/src/server/gpu/readiness-service.ts@@ -8,7 +8,7 @@ import { vramGb } from "@/lib/gpu/requirements";import { getSetting } from "../settings";import { loadIndex } from "./index-file";import { probe, readSnapshot, saveViews, checkWait, type Snapshot } from "./snapshots";-import { STUDIO_ROWS, openModelTools, presetTools, studioOthers, studioTool, toolFor, type Tool } from "./tools";+import { STUDIO_ROWS, openModelTools, presetRouteTools, presetTools, studioOthers, studioTool, toolFor, type Tool } from "./tools";import { urlHash, type ReadTarget } from "./target";/**@@ -54,7 +54,8 @@ export function buildViews(inv: GpuInventory, idx: RequirementIndex, ctx: Readinconst b = badgeOf(readinessOf(tool, inv, idx, ctx));if (b) badges.models[tool.ref.slice("model:".length)] = b;}- for (const tool of presetTools()) {+ // The route a preset opens on ("<id>"), and its other routes ("<id>@<model id>": Fuobe DoP with the move's LoRAs).+ for (const tool of [...presetTools(), ...presetRouteTools()]) {const b = badgeOf(readinessOf(tool, inv, idx, ctx));if (b) badges.presets[tool.ref.slice("preset:".length)] = b;}diff --git a/src/server/gpu/tools.ts b/src/server/gpu/tools.tsindex 631c3983..ff0dc643 100644--- a/src/server/gpu/tools.ts+++ b/src/server/gpu/tools.ts@@ -7,6 +7,8 @@ import { dualEngine, onEngine, runsOn } from "@/lib/catalog/engines";import { FRAMES_MODELS } from "@/lib/catalog/keyframes";import { libraryEntry, needsToken } from "@/lib/catalog/loras";import { ANGLES_2511_LORA } from "@/lib/catalog/open-tools";+import { presetRoutes, recipeRoute } from "@/lib/catalog/preset-recipes";+import { resolveWorkflowId } from "@/lib/comfy-variants";import { STUDIO_WORKFLOWS } from "@/lib/catalog/swap-studio-plan";import { FILL_MODELS } from "@/lib/catalog/turnaround";import type { LoraRef, ModelDef, Operation } from "@/lib/catalog/types";@@ -92,23 +94,40 @@ export function modelTool(modelId: string, op: string): Tool | null {};}-/** A preset: its open route, its prestep's, and their LoRAs. */-export function presetTool(presetId: string): Tool | null {+/**+ * A preset: an open route of it, its prestep's, and their LoRAs. By default the route the composer opens it on (the one+ * its preview was made with, when the catalog has its model); `own`: its own route; `modelId`: its route on that model+ * (null when it has none there: the run is the model's alone).+ */+export function presetTool(presetId: string, pick: { own?: boolean; modelId?: string } = {}): Tool | null {const p = getPreset(presetId);if (!p?.open) return null;- const main = modelTool(p.open.modelId, p.open.op);+ const routes = presetRoutes(p, "open", (id) => !!getModel(id));+ const route = pick.own ? p.open : pick.modelId ? routes.find((r) => r.modelId === pick.modelId) : (routes[0] ?? p.open);+ if (!route) return null;+ const main = modelTool(route.modelId, route.op);if (!main) return null;+ // The graph the route's own settings pick (H3's Orbit graph, its Best one; a camera pose), as the gate resolves a run.+ const extra = route.params?.extra;+ const has = (id: string) => !!loadIndex().workflows[id];+ const graphs = extra ? main.workflows.map((w) => resolveWorkflowId(w, { op: route.op, clips: 0, images: 0, audio2: false, extra, has })) : main.workflows;const pre = p.prestep?.open ? modelTool(p.prestep.open.modelId, p.prestep.open.op) : null;const loras = new Map<string, LoraNeed>();- for (const l of [...(p.open.loras ?? []), ...(p.prestep?.open.loras ?? [])]) loras.set(basename(l.file), loraNeed(l));+ for (const l of [...(route.loras ?? []), ...(p.prestep?.open.loras ?? [])]) loras.set(basename(l.file), loraNeed(l));for (const l of [...main.loras, ...(pre?.loras ?? [])]) loras.set(l.file, l);+ // A route after the first is named by its model too ("preset:motion-jib-up@fuobe-dop"), so its guided fix plans it.+ const first = (routes[0] ?? p.open).modelId === route.modelId;+ // Its cloud alternative: on the route its preview was made with, that recipe hosted (MiniMax H3 on fal) when the+ // catalog has it; else the preset's own cloud route, for an Original that runs on both engines.+ const hosted = !pick.own && recipeRoute(p, "open")?.modelId === route.modelId ? recipeRoute(p, "cloud") : undefined;+ const cloud = hosted && getModel(hosted.modelId) ? hosted.modelId : p.cloud && main.cloud ? p.cloud.modelId : undefined;return {- ref: `preset:${p.id}`,+ ref: first ? `preset:${p.id}` : `preset:${p.id}@${route.modelId}`,name: p.name,kind: main.kind,- workflows: [...new Set([...main.workflows, ...(pre?.workflows ?? [])])],+ workflows: [...new Set([...graphs, ...(pre?.workflows ?? [])])],loras: [...loras.values()],- ...(p.cloud && main.cloud && { cloud: { modelId: p.cloud.modelId } }),+ ...(cloud && { cloud: { modelId: cloud } }),...(main.local && !pre && { local: true }),};}@@ -243,19 +262,37 @@ export function openModelTools(): Tool[] {return out;}-/** Every preset with an open route (the gallery's chips). */-export function presetTools(): Tool[] {+/** Every preset with an open route (the gallery's chips), on the route it opens on (`own`: its own route). */+export function presetTools(pick: { own?: boolean } = {}): Tool[] {return PRESETS.flatMap((p) => {- const t = presetTool(p.id);+ const t = presetTool(p.id, pick);return t ? [t] : [];});}+/**+ * Every preset's other open routes (Fuobe DoP with the move's LoRAs, an app's own model), each as+ * "preset:<id>@<model id>": the composer's badge and guided fix when one of them is picked.+ */+export function presetRouteTools(): Tool[] {+ return PRESETS.flatMap((p) => {+ const routes = presetRoutes(p, "open", (id) => !!getModel(id));+ const others = [...new Set(routes.slice(1).map((r) => r.modelId))].filter((id) => id !== routes[0]?.modelId);+ return others.flatMap((modelId) => {+ const t = presetTool(p.id, { modelId });+ return t ? [t] : [];+ });+ });+}+let loraNamesCache: string[] | null = null;-/** Every LoRA a preset or a recipe names (what a full check looks for in models/loras). */+/**+ * Every LoRA a preset or a recipe names (what a full check looks for in models/loras): the presets' own routes too (Fuobe+ * DoP's), which stay one pick away when a preset opens on the model its preview was made with.+ */export function allLoraNames(): string[] {- loraNamesCache ??= [...new Set([...presetTools(), ...openModelTools()].flatMap((t) => t.loras.map((l) => l.file)))].sort();+ loraNamesCache ??= [...new Set([...presetTools(), ...presetTools({ own: true }), ...openModelTools()].flatMap((t) => t.loras.map((l) => l.file)))].sort();return loraNamesCache;}@@ -263,8 +300,8 @@ export function allLoraNames(): string[] {export function toolFor(ref: string): Tool | null {const m = /^model:([^#]+)#(.+)$/.exec(ref);if (m) return modelTool(m[1], m[2]);- const p = /^preset:(.+)$/.exec(ref);- if (p) return presetTool(p[1]);+ const p = /^preset:([^@]+)(?:@(.+))?$/.exec(ref);+ if (p) return presetTool(p[1], p[2] ? { modelId: p[2] } : {});const s = /^studio:(.+)$/.exec(ref);if (s) {const row = STUDIO_ROWS.find((r) => r.href === s[1]);diff --git a/tests/composer.test.ts b/tests/composer.test.tsindex b7832e9e..a7a3d978 100644--- a/tests/composer.test.ts+++ b/tests/composer.test.ts@@ -23,6 +23,9 @@ import {toggleIn,type Attachment,} from "@/lib/composer";+import { appRoute, engineSwitchModel, presetFallback, presetOriginal, presetParams, routeParams } from "@/lib/composer";+import { withRecipe } from "@/lib/catalog/preset-recipes";+import { needsKey } from "@/lib/your-keys";import { appStudio, EDIT_STUDIO, IMAGE_STUDIO, JOIN_CLIPS_STUDIO, LIPSYNC_STUDIO, TRANSCRIBE_STUDIO, VIDEO_STUDIO } from "@/lib/studios";import { studioCatalog } from "@/lib/studio-catalog";import { buildPayload } from "@/lib/catalog/payload";@@ -336,6 +339,77 @@ describe("studio catalog slice", () => {});});+describe("a preset opens on the model its preview was made with", () => {+ const inCatalog = (id: string) => !!getModel(id);+ // An account with a Replicate token only: hosted MiniMax H3 is on fal alone.+ const replicateOnly = { viewer: { kind: "account" as const, keys: ["replicate" as const] } };+ const runs = (id: string) => inCatalog(id) && !needsKey(getModel(id), replicateOnly);++ it("ships an app's two models in its slice and offers both", () => {+ const face = withRecipe(appStudio(getPreset("app-face-swap")!), inCatalog);+ const ids = studioCatalog(face).models.map((m) => m.id);+ expect(ids).toEqual(expect.arrayContaining(["oss-qwen-image-21-turbo", "oss-reactor", "nano-banana-pro"]));+ const dance = withRecipe(appStudio(getPreset("app-dance")!), inCatalog);+ expect(studioCatalog(dance).models.map((m) => m.id)).toEqual(expect.arrayContaining(["oss-minimax-h3", "minimax-h3", "oss-wan22-14b", "kling-2-5-turbo"]));+ });++ it("starts a motion on H3 at the Quality its cover was made at, and an app on its route's settings", () => {+ expect(presetOriginal(getPreset("motion-crash-zoom-in")!, "open", inCatalog)).toBe("oss-minimax-h3");+ expect(presetParams(getPreset("motion-crash-zoom-in")!, "open", inCatalog)).toEqual({ duration: 5, extra: { quality: "best" } });+ // Fast is H3's default: nothing to set (Director stays on Auto). The orbit stays the preset's (the planner adds it).+ expect(presetParams(getPreset("motion-truck-left")!, "open", inCatalog)).toEqual({ duration: 5 });+ expect(presetParams(getPreset("motion-360-orbit")!, "open", inCatalog)).toEqual({ duration: 3 });+ // A colour-grade effect starts on Fuobe DoP.+ expect(presetOriginal(getPreset("effect-candy-pink")!, "open", inCatalog)).toBe("fuobe-dop");+ const dance = getPreset("app-dance")!;+ expect(routeParams(appRoute(dance, "open", "oss-wan22-14b", inCatalog), "app")).toEqual(dance.open!.params);+ expect(routeParams(appRoute(dance, "open", "oss-minimax-h3", inCatalog), "app")).toEqual({ duration: 5 });+ });++ it("falls back to the preset's own route where the viewer can't run its recipe (a Replicate-only account)", () => {+ const dance = getPreset("app-dance")!;+ expect(presetFallback(dance, "cloud", "minimax-h3", inCatalog, runs)?.modelId).toBe("kling-2-5-turbo");+ // A viewer who can run the recipe stays on it; so does one on another model already.+ expect(presetFallback(dance, "cloud", "minimax-h3", inCatalog, inCatalog)).toBeUndefined();+ expect(presetFallback(dance, "cloud", "kling-2-5-turbo", inCatalog, runs)).toBeUndefined();+ // A motion: its own cloud route (Fuobe DoP · LTX for Truck Left), when the move is picked and when it is open.+ const truck = getPreset("motion-truck-left")!;+ expect(presetOriginal(truck, "cloud", runs)).toBe(truck.cloud!.modelId);+ expect(presetFallback(truck, "cloud", "minimax-h3", inCatalog, runs)?.modelId).toBe(truck.cloud!.modelId);+ // A model switched off in Settings: the GPU's H3 gives way to Fuobe DoP.+ const offH3 = (id: string) => id !== "oss-minimax-h3" && inCatalog(id);+ expect(presetFallback(truck, "open", "oss-minimax-h3", inCatalog, offH3)?.modelId).toBe("fuobe-dop");+ // Nothing runnable: the recipe stays (Generate asks for the key).+ expect(presetFallback(dance, "cloud", "minimax-h3", inCatalog, () => false)).toBeUndefined();+ // A preset with one route has nowhere to go.+ expect(presetFallback(getPreset("effect-candy-pink")!, "open", "fuobe-dop", inCatalog, () => false)).toBeUndefined();+ });++ it("lists an app's two models once each, in their order", () => {+ const models = ["oss-qwen-image-21-turbo", "oss-reactor"].map((id) => getModel(id)!);+ const flat = groupModels({ models, engine: "open", engines: ["cloud", "open"], query: "", recent: ["oss-reactor"], starred: [], best: ["oss-qwen-image-21-turbo"], flat: true });+ expect(flat.groups.map((g) => g.models.map((m) => m.id))).toEqual([["oss-qwen-image-21-turbo", "oss-reactor"]]);+ expect(flat.count).toBe(2);+ const grouped = groupModels({ models, engine: "open", engines: ["cloud", "open"], query: "", recent: [], starred: [], best: ["oss-qwen-image-21-turbo"] });+ expect(grouped.groups.map((g) => g.id)).toEqual(["best", "all"]);+ });++ it("keeps an app on its own models when the engine changes (AI Influencer's cloud Original on the GPU)", () => {+ const influencer = getPreset("app-ai-influencer")!;+ const defaults = { cloud: "fuobe-soul", open: "oss-zimage-soul-cast" };+ const soulOnGpu = { id: "fuobe-soul", engine: "open" as const };+ expect(engineSwitchModel({ model: soulOnGpu, preset: influencer, engine: "open", from: "cloud", defaults, has: inCatalog })).toBe("oss-zimage-soul-cast");+ expect(engineSwitchModel({ model: soulOnGpu, preset: influencer, engine: "open", from: "open", defaults, has: inCatalog })).toBe("oss-zimage-soul-cast");+ expect(engineSwitchModel({ model: { id: "fuobe-soul", engine: "cloud" }, preset: influencer, engine: "cloud", from: "open", defaults, has: inCatalog })).toBeUndefined();+ // An app on its own route stays; on the other engine's model it moves to this engine's recipe.+ const face = getPreset("app-face-swap")!;+ expect(engineSwitchModel({ model: { id: "oss-reactor", engine: "open" }, preset: face, engine: "open", from: "open", defaults, has: inCatalog })).toBeUndefined();+ expect(engineSwitchModel({ model: { id: "nano-banana-pro", engine: "cloud" }, preset: face, engine: "open", from: "cloud", defaults, has: inCatalog })).toBe("oss-qwen-image-21-turbo");+ // An app with no version on the engine keeps its model (Generate says so).+ expect(engineSwitchModel({ model: { id: "oss-wan22-animate", engine: "open" }, preset: getPreset("app-recast")!, engine: "cloud", from: "open", defaults, has: inCatalog })).toBeUndefined();+ });+});+describe("an app page's hero", () => {it("says what you get: the notes stay in Details, a missing engine is said", () => {for (const id of ["app-similarity-score", "app-angles", "app-rap-god", "app-video-background-remover", "app-gtai", "app-shots", "app-clipcut"]) {diff --git a/tests/dop-originals.test.ts b/tests/dop-originals.test.tsindex 3930d992..de3d5b2e 100644--- a/tests/dop-originals.test.ts+++ b/tests/dop-originals.test.ts@@ -27,7 +27,10 @@ beforeAll(() => setSetting("demoMode", "auto"));afterAll(() => fs.rmSync(dir, { recursive: true, force: true }));const view = (id: string, engine: "open" | "cloud") => onEngine(getModel(id)!, engine);-const plan = (engine: "open" | "cloud", req: Partial<GenerationRequest> & { presetId?: string }, modelId = presetModel(getPreset(req.presetId ?? "")!, engine) ?? "fuobe-dop") => {+// A move's own route: as when the model its preview was made with (MiniMax H3) isn't in the catalog, or Fuobe DoP is picked.+const noRecipe = () => false;+const inCatalog = (id: string) => !!getModel(id);+const plan = (engine: "open" | "cloud", req: Partial<GenerationRequest> & { presetId?: string }, modelId = presetModel(getPreset(req.presetId ?? "")!, engine, noRecipe) ?? "fuobe-dop") => {const m = view(modelId, engine);return planGeneration({ feature: "motion", modelId: m.id, prompt: "a woman in a red coat on a bridge", inputs: { images: ["/a.png"] }, ...req }, (id) => (id === m.id ? m : getModel(id)), getPreset);};@@ -207,7 +210,7 @@ describe("effects as steps", () => {const pink = getPreset("effect-candy-pink")!;expect(pink.grade).toBe("candy-pink");// The grade is Fuobe DoP's step: the effect runs on it on both engines, without a LoRA.- for (const engine of ["open", "cloud"] as const) expect(presetModel(pink, engine)).toBe("fuobe-dop");+ for (const engine of ["open", "cloud"] as const) expect(presetModel(pink, engine, noRecipe)).toBe("fuobe-dop");expect(plan("cloud", { presetId: "effect-candy-pink" }).loras).toEqual([]);const g = {id: "gen123",@@ -302,11 +305,11 @@ describe("review fixes", () => {it("runs Focus Change on LTX-2.5's fast endpoint: 720p, the start frame's shape, silent, about $0.54", async () => {const focus = getPreset("motion-focus-change")!;- expect(presetModel(focus, "cloud")).toBe("ltx-2-5-fast");+ expect(presetModel(focus, "cloud", noRecipe)).toBe("ltx-2-5-fast");const m = getModel("ltx-2-5-fast")!;expect(m.hidden).toBe(true);// As the composer sends it: the model's defaults, then the move's own settings over them.- const p = plan("cloud", { presetId: "motion-focus-change", params: { ...m.defaults, ...presetParams(focus, "cloud") } });+ const p = plan("cloud", { presetId: "motion-focus-change", params: { ...m.defaults, ...presetParams(focus, "cloud", noRecipe) } });expect(p.params).toMatchObject({ duration: 6, resolution: "720p", aspectRatio: "auto", generateAudio: false, extra: { camera_motion: "focus_shift" } });expect(estimateCost(m, p.params, 1, "i2v")).toBeCloseTo(0.54);const { url, body } = await submit(m, m.routes[0], { ...p.params, prompt: p.prompt, images: ["https://fal.media/a.png"] });@@ -370,30 +373,50 @@ describe("the composer follows the engine, not a person's pick", () => {const jib = getPreset("motion-jib-up")!;const defaults = { open: "oss-wan22-14b", cloud: "kling-2-5-turbo" };it("moves a move to its model on the new engine when the engine changes", () => {- expect(presetModel(jib, "open")).toBe("fuobe-dop");- expect(presetModel(jib, "cloud")).toBe("fuobe-dop-ltx");+ expect(presetModel(jib, "open", noRecipe)).toBe("fuobe-dop");+ expect(presetModel(jib, "cloud", noRecipe)).toBe("fuobe-dop-ltx");// GPU → cloud on Fuobe DoP: Jib Up follows to Fuobe DoP · LTX.- expect(engineSwitchModel({ model: view("fuobe-dop", "cloud"), preset: jib, engine: "cloud", from: "open", defaults })).toBe("fuobe-dop-ltx");+ expect(engineSwitchModel({ model: view("fuobe-dop", "cloud"), preset: jib, engine: "cloud", from: "open", defaults, has: noRecipe })).toBe("fuobe-dop-ltx");// A partner model left behind on the other engine gives way to the move's model here.- expect(engineSwitchModel({ model: getModel("kling-2-5-turbo")!, preset: jib, engine: "open", from: "cloud", defaults })).toBe("fuobe-dop");+ expect(engineSwitchModel({ model: getModel("kling-2-5-turbo")!, preset: jib, engine: "open", from: "cloud", defaults, has: noRecipe })).toBe("fuobe-dop");+ });++ it("opens a Fuobe DoP move on the model its preview was made with, DoP one pick away and following the engine", () => {+ // MiniMax H3 on both engines when the catalog has it.+ expect(presetModel(jib, "open", inCatalog)).toBe("oss-minimax-h3");+ expect(presetModel(jib, "cloud", inCatalog)).toBe("minimax-h3");+ expect(presetOriginal(getPreset("motion-whip-pan")!, "cloud", inCatalog)).toBe("minimax-h3");+ // Hosted H3 follows to H3 on the GPU; Fuobe DoP picked on the GPU still follows to Jib Up's DoP · LTX in the cloud.+ expect(engineSwitchModel({ model: getModel("minimax-h3")!, preset: jib, engine: "open", from: "cloud", defaults, has: inCatalog })).toBe("oss-minimax-h3");+ expect(engineSwitchModel({ model: view("fuobe-dop", "cloud"), preset: jib, engine: "cloud", from: "open", defaults, has: inCatalog })).toBe("fuobe-dop-ltx");+ expect(engineSwitchModel({ model: view("fuobe-dop", "open"), preset: jib, engine: "open", from: "open", defaults, has: inCatalog })).toBeUndefined();+ // The effects with a start-frame step (relight, Mixed Media) stay on Fuobe DoP, which runs the step.+ const steps = EFFECTS.filter((p) => p.prestep);+ expect(steps).toHaveLength(38);+ for (const p of steps) for (const engine of ["open", "cloud"] as const) expect(presetModel(p, engine, inCatalog), p.id).toBe(p[engine]!.modelId);+ // A colour-grade effect stays on Fuobe DoP on both engines, whose clip carries the grade (as its cover was made).+ for (const engine of ["open", "cloud"] as const) expect(presetModel(getPreset("effect-candy-pink")!, engine, inCatalog)).toBe("fuobe-dop");+ // Fuobe DoP picked: its own route runs as before (LoRAs, the trigger, its settings).+ const dop = plan("open", { presetId: "motion-jib-up" }, "fuobe-dop");+ expect(dop.loras.map((l) => l.file)).toEqual(jib.open!.loras?.map((l) => l.file) ?? []);});it("keeps the sibling Original picked on purpose on the same engine", () => {// In the cloud, Fuobe DoP (Wan) picked for Jib Up stays: the engine didn't change.- expect(engineSwitchModel({ model: view("fuobe-dop", "cloud"), preset: jib, engine: "cloud", from: "cloud", defaults })).toBeUndefined();+ expect(engineSwitchModel({ model: view("fuobe-dop", "cloud"), preset: jib, engine: "cloud", from: "cloud", defaults, has: noRecipe })).toBeUndefined();// On the GPU, Fuobe DoP · LTX picked for Jib Up stays too.- expect(engineSwitchModel({ model: view("fuobe-dop-ltx", "open"), preset: jib, engine: "open", from: "open", defaults })).toBeUndefined();+ expect(engineSwitchModel({ model: view("fuobe-dop-ltx", "open"), preset: jib, engine: "open", from: "open", defaults, has: noRecipe })).toBeUndefined();// Focus Change: Fuobe DoP picked in the cloud doesn't snap back to LTX 2.5 Fast.- expect(engineSwitchModel({ model: view("fuobe-dop", "cloud"), preset: getPreset("motion-focus-change")!, engine: "cloud", from: "cloud", defaults })).toBeUndefined();+ expect(engineSwitchModel({ model: view("fuobe-dop", "cloud"), preset: getPreset("motion-focus-change")!, engine: "cloud", from: "cloud", defaults, has: noRecipe })).toBeUndefined();});it("moves to a picked or linked move's Original, never to a partner route", () => {- expect(presetOriginal(jib, "cloud")).toBe("fuobe-dop-ltx");- expect(presetOriginal(getPreset("motion-whip-pan")!, "cloud")).toBeUndefined();- expect(presetOriginal(getPreset("motion-whip-pan")!, "open")).toBe("fuobe-dop");- expect(presetOriginal(getPreset("app-face-swap") ?? undefined, "cloud")).toBeUndefined();+ expect(presetOriginal(jib, "cloud", noRecipe)).toBe("fuobe-dop-ltx");+ expect(presetOriginal(getPreset("motion-whip-pan")!, "cloud", noRecipe)).toBeUndefined();+ expect(presetOriginal(getPreset("motion-whip-pan")!, "open", noRecipe)).toBe("fuobe-dop");+ expect(presetOriginal(getPreset("app-face-swap") ?? undefined, "cloud", inCatalog)).toBeUndefined();// The move's own settings start the composer, its extra (a camera LoRA) stays the preset's.- expect(presetParams(jib, "cloud")).toEqual({ duration: 5 });+ expect(presetParams(jib, "cloud", noRecipe)).toEqual({ duration: 5 });});it("takes the other engine's defaults for the settings left alone when the same Original changes engine", () => {diff --git a/tests/plan.test.ts b/tests/plan.test.tsindex a68742a6..7d92bce2 100644--- a/tests/plan.test.ts+++ b/tests/plan.test.ts@@ -57,6 +57,65 @@ describe("planGeneration", () => {});});+describe("a preset on the model its preview was made with, or on its own", () => {+ const open = (id: string) => (getModel(id) ? onEngine(getModel(id)!, "open") : undefined);+ const run = (presetId: string, modelId: string, extra: Partial<Parameters<typeof planGeneration>[0]> = {}) =>+ planGeneration({ feature: "app", presetId, modelId, prompt: "", inputs: { images: ["a.png", "b.png"] }, ...extra }, open, getPreset);++ it("runs an app on its recipe and on its own route, and refuses any other model naming both", () => {+ expect(run("app-headshot-generator", "oss-qwen-image-21-turbo").model.id).toBe("oss-qwen-image-21-turbo");+ expect(run("app-headshot-generator", "oss-qwen-image-21").model.id).toBe("oss-qwen-image-21");+ expect(() => run("app-headshot-generator", "oss-krea2-edit")).toThrow("Headshot Generator runs on oss-qwen-image-21-turbo or oss-qwen-image-21, not oss-krea2-edit");+ });++ it("uses the matched route's operation and words", () => {+ const qwen = run("app-face-swap", "oss-qwen-image-21-turbo");+ expect(qwen.op).toBe("edit");+ expect(qwen.prompt).toMatch(/^Replace the face of the person in <image1> with the face of the person in <image2>/);+ const reactor = run("app-face-swap", "oss-reactor");+ expect(reactor.op).toBe("face-swap");+ // A two-image app's words name its pictures as the encoder does, on the Turbo only.+ expect(run("app-character-swap", "oss-qwen-image-21-turbo").prompt).toMatch(/<image1>.*<image2>|<image2>.*<image1>/);+ expect(run("app-character-swap", "oss-qwen-image-21").prompt).toMatch(/the first image/);+ // Specialist options fill in.+ expect(run("app-relight", "oss-qwen-image-21-turbo", { presetOptions: { light: "neon-night", dir: "left" } }).prompt).toMatch(/^Relight <image1> with pink and blue neon lights at night coming from the left:/);+ });++ it("gives an H3 run its Quality, orbit and length", () => {+ const one = { inputs: { images: ["a.png"] } };+ const truck = run("motion-truck-left", "oss-minimax-h3", one);+ expect(truck.op).toBe("i2v");+ expect(truck.params).toMatchObject({ duration: 5 });+ expect(truck.params.extra?.quality).toBeUndefined();+ expect(truck.loras).toEqual([]);+ // Quality is a control the composer shows: it starts at the route's Best and sends it; Auto sends none, which is+ // H3's default (Fast), even on a preset made at Best.+ expect(run("motion-crash-zoom-in", "oss-minimax-h3", { ...one, params: { extra: { quality: "best" } } }).params.extra).toMatchObject({ quality: "best" });+ expect(run("motion-crash-zoom-in", "oss-minimax-h3", { ...one, params: { extra: { quality: "fast" } } }).params.extra).toMatchObject({ quality: "fast" });+ expect(run("motion-crash-zoom-in", "oss-minimax-h3", one).params.extra?.quality).toBeUndefined();+ // The composer sends the Quality it shows; the route's orbit stays under it.+ const orbit = run("motion-360-orbit", "oss-minimax-h3", { ...one, prompt: "a dancer mid-leap", params: { duration: 3, extra: { quality: "fast" } } });+ expect(orbit.params).toMatchObject({ duration: 3, extra: { orbit: true, quality: "fast" } });+ expect(orbit.prompt).toMatch(/^One frozen instant\. Only the camera moves\. In a continuous 360 orbit\..* a dancer mid-leap$/);+ // Hosted H3: 5 s, the orbit's words, no LoRA.+ const hosted = planGeneration({ feature: "motion", presetId: "motion-360-orbit", modelId: "minimax-h3", prompt: "", ...one }, getModel, getPreset);+ expect(hosted.params.duration).toBe(5);+ expect(hosted.prompt).toMatch(/^One frozen instant/);+ // Fuobe DoP picked: its LoRAs and trigger, as before.+ const jib = getPreset("motion-jib-up")!;+ const dop = run("motion-jib-up", "fuobe-dop", one);+ expect(dop.loras.map((l) => l.file)).toEqual((jib.open!.loras ?? []).map((l) => l.file));+ });++ it("runs AI Influencer on its GPU model on the open engine, and refuses the cloud's Original there", () => {+ const plan = planGeneration({ feature: "app", presetId: "app-ai-influencer", modelId: "oss-zimage-soul-cast", prompt: "a surfer from Lisbon" }, open, getPreset);+ expect(plan.model.id).toBe("oss-zimage-soul-cast");+ expect(() => planGeneration({ feature: "app", presetId: "app-ai-influencer", modelId: "fuobe-soul", prompt: "a surfer from Lisbon" }, open, getPreset)).toThrow(+ /runs on oss-zimage-soul-cast, not fuobe-soul/,+ );+ });+});+describe("estimateCost", () => {it("prices per image, per second and free for open models", () => {expect(estimateCost(getModel("nano-banana-pro")!, { numOutputs: 2 })).toBeCloseTo(0.3);diff --git a/tests/preset-cards.test.ts b/tests/preset-cards.test.tsindex 2f6d9c8d..ce563c24 100644--- a/tests/preset-cards.test.ts+++ b/tests/preset-cards.test.ts@@ -20,6 +20,7 @@ import {motionMove,moveVars,PREVIEW_LAYERS,+ parityNote,presetHowTo,presetRouteLines,previewFlip,@@ -288,6 +289,42 @@ describe("preset route lines (details popover)", () => {expect(open.model).toBe("Fuobe DoP");expect(presetRouteLines(getPreset("motion-overhead")!, () => "Fuobe DoP")[0].model).toBe("Fuobe DoP");});++ it("names the model a preset's preview was made with first, with the label when it made the live preview", () => {+ const truck = getPreset("motion-truck-left")!;+ const names: Record<string, string> = { "oss-minimax-h3": "MiniMax H3", "minimax-h3": "MiniMax H3", "fuobe-dop": "Fuobe DoP", "fuobe-dop-ltx": "Fuobe DoP · LTX" };+ const h3 = (made: boolean) => (e: "cloud" | "open") => ({ route: { modelId: e === "open" ? "oss-minimax-h3" : "minimax-h3" }, made });+ expect(presetRouteLines(truck, (id) => names[id], h3(true))).toEqual([+ { engine: "cloud", label: "Cloud", model: "MiniMax H3", made: true },+ { engine: "cloud", label: "Cloud", model: names[truck.cloud!.modelId], alt: true },+ { engine: "open", label: "Open source", model: "MiniMax H3", made: true },+ { engine: "open", label: "Open source", model: names[truck.open!.modelId], alt: true },+ ]);+ // The preset's note then speaks of its second choice.+ const truckLines = presetRouteLines(truck, (id) => names[id], h3(true));+ expect(parityNote("Fuobe DoP: Wan 2.2 with the motionpushin LoRA, on your GPU and in the cloud", truckLines)).toBe(+ "Or Fuobe DoP: Wan 2.2 with the motionpushin LoRA, on your GPU and in the cloud",+ );+ expect(parityNote("Fuobe DoP: Wan 2.2", presetRouteLines(truck, (id) => names[id]))).toBe("Fuobe DoP: Wan 2.2");+ const colors = [+ { engine: "open" as const, model: "Qwen-Image 2.1 Turbo" },+ { engine: "open" as const, model: "Palette match", alt: true as const },+ ];+ expect(parityNote("The open version transfers the palette directly (no AI model, runs on CPU)", colors)).toBe(+ "Palette match, the second choice on your GPU, transfers the palette directly (no AI model, runs on CPU)",+ );+ expect(parityNote("Approximation: one combined image", colors)).toBe("Approximation: one combined image");+ expect(parityNote(undefined, colors)).toBeUndefined();+ // A still cover: the recipe leads, without the label.+ expect(presetRouteLines(truck, (id) => names[id], h3(false))[0]).toEqual({ engine: "cloud", label: "Cloud", model: "MiniMax H3" });+ // A recipe on the preset's own model (Zooms on Qwen-Image 2.1) is one line; an engine without a recipe keeps its route.+ const zooms = getPreset("app-zooms")!;+ const lines = presetRouteLines(zooms, (id) => ({ "oss-qwen-image-21": "Qwen-Image 2.1", "nano-banana-pro": "Nano Banana Pro" })[id], (e) => (e === "open" ? { route: zooms.open!, made: true } : undefined));+ expect(lines).toEqual([+ { engine: "cloud", label: "Cloud", model: "Nano Banana Pro" },+ { engine: "open", label: "Open source", model: "Qwen-Image 2.1", made: true },+ ]);+ });});describe("a card's description on a phone", () => {diff --git a/tests/preset-covers.test.ts b/tests/preset-covers.test.tsindex 8acc1ed5..5fdefd7e 100644--- a/tests/preset-covers.test.ts+++ b/tests/preset-covers.test.ts@@ -144,7 +144,10 @@ describe("the preset covers manifest", () => {.filter((s) => spec.test(s.text)).map((s) => s.file).sort();- expect(importers(/from "[^"]*preset-previews\.generated"/)).toEqual(["lib/preset-card-data.ts"]);+ expect(importers(/from "[^"]*preset-previews\.generated"/)).toEqual(["lib/catalog/preset-recipes.ts", "lib/preset-card-data.ts"]);+ // "Used for this preview" reads it too: on server pages and modules, in the preset header's chunk, and in a chunk the+ // composer loads on its own (import()); the composer and the planner read the light preset-recipe-routes.ts.+ expect(importers(/from "[^"]*catalog\/preset-recipes"/)).toEqual(["app/(studio)/apps/[id]/page.tsx", "components/preset-header.tsx", "server/gpu/tools.ts"]);expect(importers(/from "[^"]*preset-card-data"/)).toEqual(["app/(studio)/apps/page.tsx","app/(studio)/effects/page.tsx",diff --git a/tests/preset-recipes.test.ts b/tests/preset-recipes.test.tsnew file mode 100644index 00000000..7778b4b5--- /dev/null+++ b/tests/preset-recipes.test.ts@@ -0,0 +1,342 @@+import { describe, expect, it } from "vitest";+import { APPS, EFFECTS, getModel, getPreset, MOTIONS, PRESETS } from "@/lib/catalog";+import {+ appModels,+ BEST_QUALITY_PRESETS,+ imageTags,+ ORBIT_PRESETS,+ ORBIT_WORDS,+ OWN_ROUTE_APPS,+ presetGpuKey,+ presetRecipe,+ presetRoutes,+ recipeKind,+ recipeMade,+ recipeRoute,+ SPECIALIST_TEMPLATES,+ withRecipe,+ WORDS_APPS,+} from "@/lib/catalog/preset-recipes";+import { planGeneration } from "@/lib/catalog/plan";+import { untouchedParams } from "@/lib/composer";+import type { Preset } from "@/lib/catalog/types";+import { PRESET_PREVIEWS } from "@/lib/preset-previews.generated";+import { appStudio } from "@/lib/studios";++// A preset opens on the model its preview was made with (its recipe), its own route second (src/lib/catalog/preset-recipes.ts).+const inCatalog = (id: string) => !!getModel(id);+const p = (id: string) => getPreset(id)!;+const VIDEO_OPS = ["i2v", "flf2v"];+/** Words a default prompt never uses: it names only what is wanted. */+const NEGATION = /\b(no|not|never|without|don't|avoid|nothing|none|neither|nor)\b/i;++describe("which presets get a recipe", () => {+ const kinds = new Map(PRESETS.map((x) => [x.id, recipeKind(x)]));+ const of = (k: string | undefined) => PRESETS.filter((x) => kinds.get(x.id) === k);++ it("puts every camera motion and effect without a start-frame step or a grade, and every image-to-video app, on MiniMax H3", () => {+ const moves = [...MOTIONS, ...EFFECTS].filter((x) => !x.prestep && !x.grade);+ const videoApps = APPS.filter((a) => VIDEO_OPS.includes((a.open ?? a.cloud)!.op) && !OWN_ROUTE_APPS.has(a.id));+ const h3 = [...of("h3"), ...of("orbit")];+ expect(h3.length).toBe(moves.length + videoApps.length);+ expect(new Set(h3.map((x) => x.id))).toEqual(new Set([...moves, ...videoApps].map((x) => x.id)));+ // At the time of writing: 310 moves and 61 video apps.+ expect(h3.length).toBe(371);+ expect(of("orbit").map((x) => x.id).sort()).toEqual([...ORBIT_PRESETS].sort());+ // The label: their live cover is an H3 clip (255 when this was written; it grows as clips are published). Hosted H3+ // is the same model, but has no Orbit LoRA.+ const isClip = (x: Preset) => PRESET_PREVIEWS[x.id]?.model === "minimax-h3";+ expect(h3.filter((x) => recipeMade(x, "open")).map((x) => x.id)).toEqual(h3.filter(isClip).map((x) => x.id));+ expect(h3.filter((x) => recipeMade(x, "cloud")).map((x) => x.id)).toEqual(h3.filter((x) => isClip(x) && !ORBIT_PRESETS.has(x.id)).map((x) => x.id));+ expect(h3.filter(isClip).length).toBeGreaterThanOrEqual(255);+ });++ it("puts the edit apps on Qwen-Image 2.1 on its Turbo, and the specialists on it in their covers' words", () => {+ const edits = APPS.filter((a) => a.open?.modelId === "oss-qwen-image-21" && a.open.op === "edit" && !["app-shots", "app-what-s-next", "app-zooms"].includes(a.id));+ expect(of("turbo").map((x) => x.id).sort()).toEqual(edits.map((x) => x.id).sort());+ expect(of("turbo")).toHaveLength(39);+ // Labelled where the cover's edit came from the Turbo (35 when this was written), never in the cloud.+ const qwenMade = (x: Preset) => PRESET_PREVIEWS[x.id]?.model === "ideogram4+qwen-image-2.1-edit" || (x.id === "app-age-shift" && PRESET_PREVIEWS[x.id]?.model === "minimax-h3");+ expect(of("turbo").filter((x) => recipeMade(x, "open")).map((x) => x.id)).toEqual(of("turbo").filter(qwenMade).map((x) => x.id));+ expect(of("turbo").filter(qwenMade).length).toBeGreaterThanOrEqual(35);+ expect(PRESETS.filter((x) => recipeKind(x) !== "h3" && recipeKind(x) !== "orbit" && recipeMade(x, "cloud"))).toEqual([]);+ expect(of("specialist").map((x) => x.id).sort()).toEqual(Object.keys(SPECIALIST_TEMPLATES).sort());+ expect(of("own").map((x) => x.id).sort()).toEqual(["app-expand-image", "app-zoom-out", "app-zooms"]);+ });++ it("leaves the effects with a start-frame step or a grade, and the apps that need their own route, as they are", () => {+ const none = of(undefined);+ const steps = EFFECTS.filter((x) => x.prestep);+ expect(steps).toHaveLength(38);+ // Fuobe DoP's clip of a colour-grade effect is graded afterwards, as its cover was.+ const grades = [...MOTIONS, ...EFFECTS].filter((x) => x.grade && !x.prestep);+ expect(grades).toHaveLength(15);+ expect(new Set(none.map((x) => x.id))).toEqual(new Set([...steps.map((x) => x.id), ...grades.map((x) => x.id), ...OWN_ROUTE_APPS]));+ expect(none).toHaveLength(68);+ for (const x of none) for (const engine of ["open", "cloud"] as const) expect(presetRecipe(x, engine, inCatalog), x.id).toBeUndefined();+ });++ it("names only models the catalog has", () => {+ for (const x of PRESETS) {+ for (const engine of ["open", "cloud"] as const) {+ const r = recipeRoute(x, engine);+ if (r) expect(getModel(r.modelId), `${x.id} ${engine}`).toBeDefined();+ if (r) expect(getModel(r.modelId)!.routes.some((m) => m.op === r.op), `${x.id} ${engine} ${r.op}`).toBe(true);+ }+ }+ });++ it("writes its own words positively", () => {+ expect(ORBIT_WORDS).not.toMatch(NEGATION);+ for (const [id, words] of Object.entries(SPECIALIST_TEMPLATES)) expect(words, id).not.toMatch(NEGATION);+ expect(ORBIT_WORDS.endsWith("{prompt}")).toBe(true);+ });+});++describe("spot checks", () => {+ it("Truck Left: H3 image-to-video at Fast, made on both engines", () => {+ const x = p("motion-truck-left");+ // Fast is H3's default Quality: nothing to set.+ expect(presetRecipe(x, "open", inCatalog)).toEqual({ route: { modelId: "oss-minimax-h3", op: "i2v", params: { duration: 5 } }, made: true });+ expect(presetRecipe(x, "cloud", inCatalog)).toEqual({ route: { modelId: "minimax-h3", op: "i2v", params: { duration: 5 } }, made: true });+ // Fuobe DoP stays second on each engine.+ expect(presetRoutes(x, "open", inCatalog).map((r) => r.modelId)).toEqual(["oss-minimax-h3", x.open!.modelId]);+ expect(presetRoutes(x, "cloud", inCatalog).map((r) => r.modelId)).toEqual(["minimax-h3", x.cloud!.modelId]);+ });++ it("Set on Fire and Disintegration: H3, with the label only where the clip is out", () => {+ expect(presetRecipe(p("effect-set-on-fire"), "open", inCatalog)?.made).toBe(true);+ const dis = presetRecipe(p("effect-disintegration"), "open", inCatalog)!;+ expect(dis.route.modelId).toBe("oss-minimax-h3");+ expect(dis.made).toBe(false);+ });++ it("the presets made at Best open at Best", () => {+ expect(BEST_QUALITY_PRESETS.size).toBe(25);+ // Particles keeps its start-frame step (Mixed Media), so it keeps Fuobe DoP.+ const stepped = [...BEST_QUALITY_PRESETS].filter((id) => p(id).prestep);+ expect(stepped).toEqual(["effect-particles"]);+ for (const id of BEST_QUALITY_PRESETS) if (!p(id).prestep) expect(recipeRoute(p(id), "open")?.params?.extra?.quality, id).toBe("best");+ expect(PRESETS.filter((x) => recipeRoute(x, "open")?.params?.extra?.quality === "best")).toHaveLength(24);+ expect(recipeRoute(p("motion-crash-zoom-in"), "cloud")?.params).toEqual({ duration: 5 });+ });++ it("360 Orbit: the Orbit LoRA's 3 s on the GPU, 5 s hosted, the label on the GPU only", () => {+ const x = p("motion-360-orbit");+ const open = presetRecipe(x, "open", inCatalog)!;+ expect(open.route).toEqual({ modelId: "oss-minimax-h3", op: "i2v", params: { duration: 3, extra: { orbit: true } }, promptTemplate: ORBIT_WORDS });+ expect(open.made).toBe(true);+ const cloud = presetRecipe(x, "cloud", inCatalog)!;+ expect(cloud.route).toEqual({ modelId: "minimax-h3", op: "i2v", params: { duration: 5 }, promptTemplate: ORBIT_WORDS });+ expect(cloud.made).toBe(false);+ });++ it("a colour-grade effect stays on Fuobe DoP, whose clip is graded", () => {+ const pink = p("effect-candy-pink");+ expect(pink.grade).toBe("candy-pink");+ for (const engine of ["open", "cloud"] as const) {+ expect(recipeRoute(pink, engine)).toBeUndefined();+ expect(presetRoutes(pink, engine, inCatalog)).toEqual([pink[engine]]);+ }+ });++ it("orbits only a picture as it is: an app whose words add to the scene keeps them", () => {+ // Bullet Time Scene and Product 360 circle the picture with the Orbit LoRA.+ for (const id of ["app-bullet-time-scene", "app-product-360"]) expect(recipeKind(p(id)), id).toBe("orbit");+ // Bullet Time Splash and White run H3's image-to-video in their own words (the water, the white cyclorama).+ for (const id of ["app-bullet-time-splash", "app-bullet-time-white"]) {+ expect(recipeKind(p(id)), id).toBe("h3");+ expect(recipeRoute(p(id), "open"), id).toEqual({ modelId: "oss-minimax-h3", op: "i2v", params: { duration: 5 } });+ expect(recipeRoute(p(id), "cloud")?.promptTemplate, id).toBeUndefined();+ }+ // 3D Rotation keeps its own route and its Rotate LoRA.+ expect(recipeKind(p("app-3d-rotation"))).toBeUndefined();+ expect(appModels(p("app-3d-rotation"), "open", inCatalog)).toEqual([p("app-3d-rotation").open!.modelId]);+ });++ it("Headshot Generator: Qwen-Image 2.1 Turbo with its own words, made on the GPU, no cloud recipe", () => {+ const x = p("app-headshot-generator");+ const open = presetRecipe(x, "open", inCatalog)!;+ expect(open.route).toMatchObject({ modelId: "oss-qwen-image-21-turbo", op: "edit" });+ expect(open.route.promptTemplate).toBeUndefined();+ expect(open.made).toBe(true);+ expect(presetRecipe(x, "cloud", inCatalog)).toBeUndefined();+ expect(appModels(x, "open", inCatalog)).toEqual(["oss-qwen-image-21-turbo", "oss-qwen-image-21"]);+ expect(appModels(x, "cloud", inCatalog)).toEqual([x.cloud!.modelId]);+ });++ it("Face Swap: Qwen-Image 2.1 Turbo in the cover's words, ReActor second", () => {+ const x = p("app-face-swap");+ const r = presetRecipe(x, "open", inCatalog)!;+ expect(r.route.modelId).toBe("oss-qwen-image-21-turbo");+ expect(r.route.op).toBe("edit");+ expect(r.route.promptTemplate).toMatch(/^Replace the face of the person in <image1> with the face of the person in <image2>/);+ expect(r.made).toBe(true);+ expect(appModels(x, "open", inCatalog)).toEqual(["oss-qwen-image-21-turbo", "oss-reactor"]);+ });++ it("the specialists keep their options, and Product Shot keeps the product as it is", () => {+ expect(SPECIALIST_TEMPLATES["app-relight"]).toContain("{option:light} {option:dir}");+ expect(SPECIALIST_TEMPLATES["app-product-shot"]).toContain("{option:scene}");+ expect(SPECIALIST_TEMPLATES["app-product-shot"]).toMatch(/Keep the product, its shape, colours, label, position and size/);+ for (const id of Object.keys(SPECIALIST_TEMPLATES)) {+ const options = p(id).options?.map((o) => o.key) ?? [];+ for (const key of options) expect(SPECIALIST_TEMPLATES[id], `${id} ${key}`).toContain(`{option:${key}}`);+ }+ });++ it("names a two-image app's pictures as Qwen-Image 2.1's encoder does", () => {+ expect(imageTags("Place the product from the second image into the first image. Keep the first image's light.")).toBe(+ "Place the product from <image2> into <image1>. Keep <image1>'s light.",+ );+ expect(imageTags("Relight image 1 so it matches image 2.")).toBe("Relight <image1> so it matches <image2>.");+ const swap = recipeRoute(p("app-character-swap"), "open")!;+ expect(swap.promptTemplate).toMatch(/<image1>/);+ expect(swap.promptTemplate).not.toMatch(/(first|second) image/);+ // An app that names no picture by position keeps its words (the preset's own).+ expect(recipeRoute(p("app-headshot-generator"), "open")!.promptTemplate).toBeUndefined();+ });++ it("Zooms keeps its own Qwen-Image 2.1 route, with the label its H3 morph earns", () => {+ const x = p("app-zooms");+ expect(presetRecipe(x, "open", inCatalog)).toEqual({ route: x.open, made: true });+ expect(appModels(x, "open", inCatalog)).toEqual(["oss-qwen-image-21"]);+ expect(presetRecipe(p("app-expand-image"), "open", inCatalog)?.made).toBe(false);+ });++ it("Angles: Qwen-Image 2.1 Turbo in the app's words, its Multiple-Angles LoRA route second", () => {+ const x = p("app-angles");+ expect([...WORDS_APPS]).toEqual(["app-angles"]);+ expect(recipeKind(x)).toBe("words");+ const r = presetRecipe(x, "open", inCatalog)!;+ expect(r.route).toEqual({ modelId: "oss-qwen-image-21-turbo", op: "edit", promptTemplate: x.promptTemplate });+ expect(r.route.loras).toBeUndefined();+ // Its cover's new view came from the Turbo, then an H3 morph.+ expect(r.made).toBe(PRESET_PREVIEWS[x.id]?.model === "minimax-h3");+ expect(appModels(x, "open", inCatalog)).toEqual(["oss-qwen-image-21-turbo", "oss-qwen-edit"]);+ expect(presetRecipe(x, "cloud", inCatalog)).toBeUndefined();+ // The options become words on the Turbo; the 2511 route keeps the LoRA's own words.+ const choice = { angle: "back-left", height: "high-angle", distance: "close-up" };+ const run = (modelId: string) =>+ planGeneration({ feature: "app:app-angles", presetId: x.id, modelId, op: "edit", inputs: { images: ["/api/files/a.png"] }, presetOptions: choice }, getModel, getPreset);+ const turbo = run("oss-qwen-image-21-turbo");+ expect(turbo.prompt).toMatch(/^Show the exact same scene and subject as a back-left quarter view, high-angle shot, close-up/);+ expect(turbo.loras).toEqual([]);+ const own = run("oss-qwen-edit");+ expect(own.prompt).toMatch(/^<sks> back-left quarter view high-angle shot close-up/);+ expect(own.loras[0]?.file).toMatch(/multiple-angles/);+ });++ it("never labels a tool", () => {+ for (const id of ["app-remove-background", "app-upscale", "app-vectorize", "app-video-background-remover", "app-image-to-3d"]) {+ for (const engine of ["open", "cloud"] as const) expect(recipeMade(p(id), engine), id).toBe(false);+ }+ });+});++describe("a linked preset that loads after the first draft", () => {+ it("brings its length and Quality to the settings still at the model's defaults", () => {+ const h3 = getModel("oss-minimax-h3")!;+ const draft = { ...h3.defaults };+ expect(untouchedParams(draft, h3.defaults ?? {}, { duration: 5, extra: { quality: "best" } })).toEqual({ ...draft, extra: { quality: "best" } });+ expect(untouchedParams(draft, h3.defaults ?? {}, { duration: 3 })).toEqual({ ...draft, duration: 3 });+ // A setting the person changed stays; nothing to change is undefined.+ expect(untouchedParams({ ...draft, duration: 10 }, h3.defaults ?? {}, { duration: 3 })).toBeUndefined();+ expect(untouchedParams({ ...draft, extra: { quality: "fast", seedLock: 1 } }, { ...h3.defaults, extra: { quality: "fast" } }, { extra: { quality: "best" } })).toEqual({+ ...draft,+ extra: { quality: "best", seedLock: 1 },+ });+ expect(untouchedParams(draft, h3.defaults ?? {}, { duration: 5 })).toBeUndefined();+ });+});++describe("without the recipe's model", () => {+ it("falls back to the preset's own route", () => {+ const noH3 = (id: string) => id !== "oss-minimax-h3" && inCatalog(id);+ const x = p("motion-truck-left");+ expect(presetRecipe(x, "open", noH3)).toBeUndefined();+ expect(presetRoutes(x, "open", noH3)).toEqual([x.open]);+ expect(presetRoutes(x, "cloud", noH3).map((r) => r.modelId)).toEqual(["minimax-h3", x.cloud!.modelId]);+ const dance = p("app-dance");+ expect(appModels(dance, "open", noH3)).toEqual([dance.open!.modelId]);+ });+});++describe("the GPU pre-flight", () => {+ it("keys a preset's badge by the route on the model picked, at the route's Quality", () => {+ const crash = p("motion-crash-zoom-in");+ // Made at Best: its badge is the 20-step graph's, so at Fast the model's own badge applies.+ expect(presetGpuKey(crash, inCatalog, "oss-minimax-h3", "best", "fast")).toBe(crash.id);+ expect(presetGpuKey(crash, inCatalog, "oss-minimax-h3", "fast", "fast")).toBeUndefined();+ expect(presetGpuKey(crash, inCatalog, "oss-minimax-h3", undefined, "fast")).toBeUndefined();+ const jib = p("motion-jib-up");+ expect(presetGpuKey(jib, inCatalog, "oss-minimax-h3", undefined, "fast")).toBe(jib.id);+ expect(presetGpuKey(jib, inCatalog, "oss-minimax-h3", "best", "fast")).toBeUndefined();+ expect(presetGpuKey(jib, inCatalog, "fuobe-dop")).toBe("motion-jib-up@fuobe-dop");+ expect(presetGpuKey(jib, inCatalog, "oss-ltx25")).toBeUndefined();+ expect(presetGpuKey(jib, inCatalog, undefined)).toBeUndefined();+ });++ it("offers hosted MiniMax H3 as the cloud alternative of a preset that opens on it", async () => {+ const { presetTool } = await import("@/server/gpu/tools");+ expect(presetTool("motion-jib-up")!.cloud).toEqual({ modelId: "minimax-h3" });+ expect(presetTool("app-dance")!.cloud).toEqual({ modelId: "minimax-h3" });+ // Its own route keeps the rule it had: Fuobe DoP runs on both engines.+ expect(presetTool("motion-jib-up", { modelId: "fuobe-dop" })!.cloud).toEqual({ modelId: p("motion-jib-up").cloud!.modelId });+ // No hosted Qwen-Image 2.1.+ expect(presetTool("app-face-swap")!.cloud).toBeUndefined();+ });++ it("describes the route a preset opens on, its own route by its model, and still looks for its own LoRAs", async () => {+ const { allLoraNames, modelTool, presetRouteTools, presetTool, toolFor } = await import("@/server/gpu/tools");+ const jib = p("motion-jib-up");+ const first = presetTool(jib.id)!;+ expect(first.ref).toBe("preset:motion-jib-up");+ expect(first.workflows).toEqual(modelTool("oss-minimax-h3", "i2v")!.workflows);+ expect(first.loras).toEqual([]);+ // The graph its settings pick: the Orbit graph for an orbit, the 20-step one at Best.+ expect(presetTool("motion-360-orbit")!.workflows).toEqual(["minimax-h3-orbit"]);+ expect(presetTool("motion-crash-zoom-in")!.workflows).toEqual(["minimax-h3-i2v-hq"]);+ // Each other open route has a badge of its own, named by its model; a recipe on the preset's own model has none.+ const others = presetRouteTools().map((t) => t.ref);+ expect(others).toContain("preset:motion-jib-up@fuobe-dop");+ expect(others).toContain("preset:app-face-swap@oss-reactor");+ expect(others.filter((r) => r.startsWith("preset:app-zooms"))).toEqual([]);+ expect(new Set(others).size).toBe(others.length);+ // The run's model picks the route the gate checks: Fuobe DoP's with its LoRAs; another model's run is its own.+ const own = presetTool(jib.id, { modelId: "fuobe-dop" })!;+ expect(own.ref).toBe("preset:motion-jib-up@fuobe-dop");+ expect(toolFor(own.ref)).toEqual(own);+ expect(own.loras.map((l) => l.file).sort()).toEqual(presetTool(jib.id, { own: true })!.loras.map((l) => l.file).sort());+ expect(presetTool(jib.id, { modelId: "oss-ltx25" })).toBeNull();+ const dopLoras = MOTIONS.flatMap((m) => m.open?.loras ?? []).map((l) => l.file.split("/").at(-1)!);+ expect(dopLoras.length).toBeGreaterThan(0);+ expect(allLoraNames()).toEqual(expect.arrayContaining(dopLoras));+ // Face Swap opens on Qwen-Image 2.1 Turbo; ReActor's graph is its own route's.+ expect(presetTool("app-face-swap")!.workflows).toEqual(modelTool("oss-qwen-image-21-turbo", "edit")!.workflows);+ expect(presetTool("app-face-swap", { own: true })!.workflows).toEqual(modelTool("oss-reactor", "face-swap")!.workflows);+ });+});++describe("an app's studio with its recipe", () => {+ it("opens on the recipe on each engine and lists both models", () => {+ const face = withRecipe(appStudio(p("app-face-swap")), inCatalog);+ expect(face.defaultModels).toEqual({ cloud: "nano-banana-pro", open: "oss-qwen-image-21-turbo" });+ expect(face.ops).toEqual(expect.arrayContaining(["edit", "face-swap"]));+ expect(face.appModels).toEqual({ cloud: ["nano-banana-pro"], open: ["oss-qwen-image-21-turbo", "oss-reactor"] });+ const colors = withRecipe(appStudio(p("app-match-colors")), inCatalog);+ expect(colors.ops).toEqual(expect.arrayContaining(["edit", "color-match"]));+ const dance = withRecipe(appStudio(p("app-dance")), inCatalog);+ expect(dance.defaultModels).toEqual({ cloud: "minimax-h3", open: "oss-minimax-h3" });+ expect(dance.appModels?.cloud).toEqual(["minimax-h3", p("app-dance").cloud!.modelId]);+ // An app with no recipe keeps its config, with its one model per engine listed.+ const influencer = withRecipe(appStudio(p("app-ai-influencer")), inCatalog);+ expect(influencer.defaultModels).toEqual(appStudio(p("app-ai-influencer")).defaultModels);+ expect(influencer.appModels).toEqual({ cloud: ["fuobe-soul"], open: ["oss-zimage-soul-cast"] });+ });++ it("keeps a motion's or a studio's config as it is", () => {+ const config = { ...appStudio(p("app-dance")), preset: p("motion-truck-left") as Preset };+ expect(withRecipe(config, inCatalog)).toBe(config);+ });+});diff --git a/tests/vectorize.test.ts b/tests/vectorize.test.tsindex 3279660e..7c44e6a8 100644--- a/tests/vectorize.test.ts+++ b/tests/vectorize.test.ts@@ -24,6 +24,7 @@ const { planGeneration } = await import("@/lib/catalog/plan");const { buildPayload, extractOutputs } = await import("@/lib/catalog/payload");const { outputActions } = await import("@/lib/output-actions");const { appStudio } = await import("@/lib/studios");+const { withRecipe } = await import("@/lib/catalog/preset-recipes");const { studioCatalog } = await import("@/lib/studio-catalog");const files = await import("@/app/api/files/[...path]/route");@@ -54,9 +55,11 @@ describe("Vectorize app", () => {expect(plan.jobs).toBe(1);}expect(() => planGeneration({ feature: "app:app-vectorize", presetId: app.id, modelId: "oss-vtracer" }, getModel, getPreset)).toThrow(/Add the image to turn into an SVG/);- // The app page knows both models (the studio slice carries them), and VTracer is an open model of its own.- const config = appStudio(app);+ // The app page knows both models (the studio slice carries them), and VTracer is an open model of its own. A tool keeps+ // its own models: no other model is listed first.+ const config = withRecipe(appStudio(app), (id) => !!getModel(id));expect(config.defaultModels).toEqual({ cloud: "recraft-vectorize", open: "oss-vtracer" });+ expect(config.appModels).toEqual({ cloud: ["recraft-vectorize"], open: ["oss-vtracer"] });expect(studioCatalog(config).models.map((m) => m.id)).toEqual(expect.arrayContaining(["recraft-vectorize", "oss-vtracer"]));expect(getModel("oss-vtracer")).toMatchObject({ engine: "open", kind: "image" });expect(getModel("oss-vtracer")!.hidden).toBeFalsy();