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
Studios say before a run when a picked value is made differently
Adarshbe8ae79f0bb9
diff --git a/src/components/marketing/marketing-studio.tsx b/src/components/marketing/marketing-studio.tsxindex c6710020..b9190f40 100644--- a/src/components/marketing/marketing-studio.tsx+++ b/src/components/marketing/marketing-studio.tsx@@ -28,6 +28,7 @@ import type { MarketingRun } from "@/lib/catalog/marketing";import { toastError } from "@/lib/refusals";import { templateCover } from "@/lib/template-covers";import type { ModelInfo } from "./model-info";+import { FitNotes, type FitNote } from "@/components/studio/fit-notes";import { AvatarSlot, HookPicker, ProductSlot, productChoice, SettingPicker, VoiceControl, type ProductChoice } from "./pickers";import { ProductParam } from "./product-param";import { RunsList } from "./runs";@@ -405,6 +406,11 @@ export function MarketingStudio({ models, starters = [] }: { models: Record<stri// Where the run happens and its price, as the studios say it (the chip by the send button); a guest or an account is// told the tool isn't available here, with no price.const priced = est.data && !est.data.blocker ? est.data : undefined;+ const fits = est.data?.fits;+ // A note the fit already says (with its fix) isn't said again in the line under the composer.+ const notes = (est.data?.notes ?? []).filter((n) => !fits?.some((c) => c.note === n));+ const fitFix = (c: FitNote) =>+ c.switchTo ? () => set({ modelId: c.switchTo!.id }) : c.use === undefined ? undefined : c.setting === "aspectRatio" ? () => set({ aspectRatio: String(c.use) }) : c.setting === "duration" ? () => set({ duration: Number(c.use) }) : undefined;// Until the run is priced (no product yet), the chip names the model Settings has picked, as the studios' model chip does.const access = useModelAccess();const picked = useMemo(() => {@@ -611,13 +617,15 @@ export function MarketingStudio({ models, starters = [] }: { models: Record<stri<TooltipContent>{blocker ?? (template ? `Recreate template${sendTip}` : `Generate${sendTip}`)}</TooltipContent></Tooltip></div>- {est.data?.notes.length && !blocker ? <p className="hidden truncate px-2 pt-1 text-[11px] text-muted-foreground sm:block">{est.data.notes[0]}</p> : null}+ {notes.length && !blocker ? <p className="hidden truncate px-2 pt-1 text-[11px] text-muted-foreground sm:block">{notes[0]}</p> : null}{/* Phones have no hover: what blocks Generate sits under the composer (the chip says where it runs and its price). */}- {(!!blocker || !!est.data?.notes.length) && (+ {(!!blocker || !!notes.length) && (<p className="min-w-0 truncate px-2 pt-1 text-[11px] text-muted-foreground sm:hidden" aria-live="polite">- {blocker ?? est.data?.notes[0] ?? ""}+ {blocker ?? notes[0] ?? ""}</p>)}+ {/* A shape or length picked here that the run makes differently: said before it runs, with the way to what is made. */}+ {!blocker && <FitNotes fits={fits} apply={fitFix} className="px-1" />}</div></div></div>diff --git a/src/components/mixed-media/mixed-studio.tsx b/src/components/mixed-media/mixed-studio.tsxindex bb6053a7..8c84b924 100644--- a/src/components/mixed-media/mixed-studio.tsx+++ b/src/components/mixed-media/mixed-studio.tsx@@ -386,20 +386,27 @@ function Editor({const capped = r === "4K" && cloud && (modelId === "seedream-5-flash" || original);// Your GPU's per-frame graph draws up to 1536 px on the long side: 2K and 4K would come out the same as 1K.const gpuCap = !cloud && r !== "1K";+ // A size it would draw smaller says why, with the size it does draw one tap away.+ const use: MixedResolution | undefined = gpuCap ? "1K" : capped ? "2K" : undefined;return {value: r,label: r,hint: undefined,- disabled: capped || gpuCap,- title: gpuCap ? "Your GPU draws each frame up to 1536 px: 2K and 4K are per frame in the cloud" : capped ? `${model?.name} draws frames up to 2K` : `Each frame at ${r}`,+ unavailable: use+ ? { why: gpuCap ? "Your GPU draws each frame up to 1536 px: 2K and 4K are per frame in the cloud" : `${model?.name} draws frames up to 2K`, fix: { label: `Use ${use}`, run: () => setResolution(use) } }+ : undefined,+ title: `Each frame at ${r}`,};}const at = fast ? nearestResolution(model?.resolutions, r) : undefined;const prev = i > 0 && fast ? nearestResolution(model?.resolutions, MIXED.resolutions[i - 1]) : undefined;- return { value: r, label: r, hint: at, disabled: fast && !!at && at === prev, title: fast && at === prev ? `${model?.name} renders up to ${at}` : at };+ // Fast renders at the model's own size nearest to the one picked: a choice that lands on the same size as a smaller one+ // says so, with the smaller one (the same render) one tap away.+ const same = fast && !!at && at === prev ? MIXED.resolutions.find((x) => nearestResolution(model?.resolutions, x) === at) : undefined;+ return { value: r, label: r, hint: at, unavailable: same ? { why: `${model?.name} renders up to ${at}`, fix: { label: `Use ${same}`, run: () => setResolution(same) } } : undefined, title: at };});- const showResolution = !smooth && (!fast || resOptions.some((o) => o.hint && !o.disabled && o.value !== "1K"));- const resShown: MixedResolution = resOptions.find((o) => o.value === resolution)?.disabled ? ([...resOptions].reverse().find((o) => !o.disabled)?.value ?? "1K") : resolution;+ const showResolution = !smooth && (!fast || resOptions.some((o) => o.hint && !o.unavailable && o.value !== "1K"));+ const resShown: MixedResolution = resOptions.find((o) => o.value === resolution)?.unavailable ? ([...resOptions].reverse().find((o) => !o.unavailable)?.value ?? "1K") : resolution;const modelRes = fast ? nearestResolution(model?.resolutions, resShown) : undefined;const previewImage = preview?.status === "succeeded" ? preview.outputs.find((o) => o.kind === "image") : undefined;// The partner editors start every run of frames from the approved preview; Fast only when the model takes a still. Thediff --git a/src/components/studio/fit-notes.tsx b/src/components/studio/fit-notes.tsxnew file mode 100644index 00000000..298622a8--- /dev/null+++ b/src/components/studio/fit-notes.tsx@@ -0,0 +1,25 @@+"use client";++import { UnavailableNote } from "@/components/ui/unavailable";+import type { SettingChange } from "@/lib/catalog/made";++/** A picked setting a run makes differently, and the model in the list that makes the one picked (when there is one). */+export type FitNote = SettingChange & { switchTo?: { id: string; name: string } };++/**+ * Before a run, under a studio's settings: each picked value the run makes differently (src/lib/catalog/fitted.ts), in the+ * shared unavailable note, with the one-tap way to what is made ("Use 4:3") or to a model that makes the one picked+ * ("Use Kling 3.0"). `apply` sets it; a note without a way to get it says why alone.+ */+export function FitNotes({ fits, apply, className }: { fits: FitNote[] | undefined; apply: (c: FitNote) => (() => void) | undefined; className?: string }) {+ if (!fits?.length) return null;+ return (+ <div className={className}>+ {fits.map((c) => {+ const run = apply(c);+ const label = c.switchTo ? `Use ${c.switchTo.name}` : `Use ${c.made}`;+ return <UnavailableNote key={c.setting + c.note} reason={{ why: c.note, ...(run && { fix: { label, run } }) }} onClose={() => undefined} />;+ })}+ </div>+ );+}diff --git a/src/lib/catalog/fitted.ts b/src/lib/catalog/fitted.tsindex 4d8a1b52..12c1981b 100644--- a/src/lib/catalog/fitted.ts+++ b/src/lib/catalog/fitted.ts@@ -41,7 +41,7 @@ export function fittedSettings(model: Pick<ModelDef, "id" | "name" | "engine" | "routes" | "defaults">,op: Operation,params: GenParams | undefined,- opts: { provider?: ProviderId; negativePrompt?: string } = {},+ opts: { provider?: ProviderId; negativePrompt?: string; deliberate?: boolean } = {},): MadeSettings {const p = params ?? {};const made: MadeSettings = {@@ -68,7 +68,8 @@ export function fittedSettings(const place = !QUIET_PLACE.has(op) && OPERATION_PLACE[op] ? ` ${OPERATION_PLACE[op]}` : "";// A default every studio fills in (a shape for a start frame) that the route doesn't send isn't a choice: it is left out// of the made settings without a word.- const filled = (k: "aspectRatio" | "resolution" | "duration", v: unknown) => v === "auto" || (model.defaults as Record<string, unknown> | undefined)?.[k] === v;+ // `deliberate`: the value was picked on purpose (a studio's own picker), so even the default is said.+ const filled = (k: "aspectRatio" | "resolution" | "duration", v: unknown) => v === "auto" || (!opts.deliberate && (model.defaults as Record<string, unknown> | undefined)?.[k] === v);// Quality.const res = p.resolution;@@ -208,3 +209,71 @@ export function settingChange(): SettingChange | undefined {return fittedSettings(model, op, { [setting]: value }).changes.find((c) => c.setting === setting);}++const ASKED_LABEL = { aspectRatio: "Aspect ratio", resolution: "Quality", duration: "Duration" } as const;+const askedWords = (k: keyof typeof ASKED_LABEL, v: string | number) => (k === "duration" ? secs(Number(v)) : k === "resolution" ? tierWords(String(v)) : String(v));++/**+ * What a studio's own picker asked for against what its request is made at. The studio may have moved the value already+ * (5:4 sent as 4:3, the closest the model lists), and the route may fit it again: one change per setting asked, with the+ * value to pick instead (none when the model keeps the input's own shape or length).+ */+export function askedChanges(+ model: Pick<ModelDef, "id" | "name" | "engine" | "routes" | "defaults">,+ op: Operation,+ sent: GenParams,+ asked: Partial<Record<keyof typeof ASKED_LABEL, string | number>>,+): SettingChange[] {+ const made = fittedSettings(model, op, sent, { deliberate: true });+ const out: SettingChange[] = [];+ for (const k of Object.keys(ASKED_LABEL) as (keyof typeof ASKED_LABEL)[]) {+ const a = asked[k];+ if (a === undefined || sent[k] === undefined) continue;+ const route = made.changes.find((c) => c.setting === k);+ const m = made[k];+ if (m === undefined) {+ if (route) out.push({ ...route, asked: askedWords(k, a), use: undefined });+ continue;+ }+ if (String(m).toLowerCase() === String(a).toLowerCase()) continue;+ const shown = askedWords(k, m);+ out.push({+ setting: k,+ label: ASKED_LABEL[k],+ asked: askedWords(k, a),+ made: shown,+ reason: route?.reason ?? "the closest this model makes",+ note: route?.note ?? `${model.name} makes ${shown}, the closest to ${askedWords(k, a)}`,+ use: m,+ });+ }+ return out;+}++/**+ * What a run's steps make differently from what they ask (each step's route), each said once: for a studio that builds+ * its own steps and says before the run what changes.+ */+export function stepChanges(+ requests: { modelId: string; op?: Operation; params?: GenParams; negativePrompt?: string }[],+ lookup: (id: string) => (Pick<ModelDef, "id" | "name" | "engine" | "routes" | "defaults"> & Partial<ModelDef>) | undefined,+): SettingChange[] {+ const out: SettingChange[] = [];+ for (const r of requests) {+ const m = lookup(r.modelId);+ if (!m || m.engine === "open" || !r.op) continue;+ for (const c of fittedSettings(m, r.op, { ...m.defaults, ...r.params }, { negativePrompt: r.negativePrompt }).changes) if (!out.some((x) => x.note === c.note)) out.push(c);+ }+ return out;+}++/** stepChanges as the notes a studio's estimate adds, leaving out what its own notes say already. */+export function routeNotes(+ requests: { modelId: string; op?: Operation; params?: GenParams; negativePrompt?: string }[],+ lookup: Parameters<typeof stepChanges>[1],+ said: readonly string[] = [],+): string[] {+ return stepChanges(requests, lookup)+ .map((c) => c.note)+ .filter((n) => !said.includes(n));+}diff --git a/src/lib/catalog/marketing.ts b/src/lib/catalog/marketing.tsindex 72a49dab..7a0ef78f 100644--- a/src/lib/catalog/marketing.ts+++ b/src/lib/catalog/marketing.ts@@ -1,3 +1,4 @@+import type { SettingChange } from "./made";import type { ChainSlot, Engine, Generation, GenerationRequest } from "./types";/**@@ -1283,8 +1284,16 @@ export interface RunEstimate {/** Why it can't run yet (shown on the Generate button). */blocker?: string;runs: number;+ /**+ * A shape, length or quality picked here that the run makes differently (src/lib/catalog/fitted.ts), said before the run+ * with its fix: the value it is made at (`use`), or a model in the list that makes the one picked (`switchTo`).+ */+ fits?: PickerFit[];}+/** One picked setting the run makes differently, and the one-tap way to what is made (or to the model that makes it). */+export type PickerFit = SettingChange & { switchTo?: { id: string; name: string } };+/** The state of a whole run: its results', else the first step that failed on its own, else running. */export function runStatus(r: Pick<MarketingRun, "generations" | "finalIds">): { state: "done" | "failed" | "running" | "canceled"; step?: string; error?: string } {const finals = r.generations.filter((g) => r.finalIds.includes(g.id));diff --git a/src/server/genjutsu.ts b/src/server/genjutsu.tsindex f8fd5e72..e333bb20 100644--- a/src/server/genjutsu.ts+++ b/src/server/genjutsu.ts@@ -2,6 +2,7 @@ import "server-only";import { ORIGINAL_SOUND_IDS, originalSoundOn, type OriginalSound } from "@/lib/av/original-sound";import { z } from "zod";import { getModel } from "@/lib/catalog";+import { routeNotes } from "@/lib/catalog/fitted";import { onEngine } from "@/lib/catalog/engines";import {ANCHOR_MODELS,@@ -694,7 +695,8 @@ export async function estimateGenjutsu(body: GenjutsuBody, viewer: GenjutsuViewepieces: plan.pieces,seconds: Math.round((input.range.end - input.range.start) * 100) / 100,steps: plan.steps.length,- notes: cost.demo ? notes : [...notes, ...tokenBilled],+ // What a step's route makes differently (src/lib/catalog/fitted.ts) is said with the rest.+ notes: [...(cost.demo ? notes : [...notes, ...tokenBilled]), ...routeNotes(plan.steps.map((s) => s.request), getModel, notes)],...(plan.anchors !== undefined ? { anchors: plan.anchors } : {}),...(character ? { limits: [...CHARACTER_LIMITS] } : {}),...(character && maker.h3 && maker.engine === "open" ? { gpu: { ...CHARACTER_GPU } } : {}),diff --git a/src/server/marketing.ts b/src/server/marketing.tsindex b9a90850..c17a0575 100644--- a/src/server/marketing.ts+++ b/src/server/marketing.ts@@ -43,13 +43,14 @@ import {type MarketingTemplate,type PlannedStep,type Product,+ type PickerFit,type RunEstimate,type RunFeature,type RunOverlay,} from "@/lib/catalog/marketing";import { dualEngine } from "@/lib/catalog/engines";import { routesFor } from "@/lib/catalog/plan";-import { opTakes } from "@/lib/catalog/route-takes";+import { askedChanges, fittedSettings, stepChanges, type SettingChange } from "@/lib/catalog/fitted";import { themeFrom, type AdLayout } from "@/components/ads/layout";import { adDraft } from "@/lib/layout-surfaces";import { LAYOUT_PARAM } from "@/lib/layout-prompt";@@ -417,7 +418,7 @@ export function planMarketing(input: MarketingInput, ctx: PlanContext): RunPlanif (productShot) notes.push("Your product is cut out and relit into the scene, so it stays as it is");else if (open && op === "edit") notes.push("Qwen-Image 2.1 keeps your first photo's shape on your GPU");// Settings the picked model doesn't take are said before the run, never dropped without a word.- else if (!open && !opTakes(model, op).aspect && !model.options.aspectRatios?.length) notes.push(`${model.name} keeps your photo's shape: Aspect ratio doesn't change it`);+ else if (!open && keepsShape(model, op, aspect)) notes.push(`${model.name} keeps your photo's shape: Aspect ratio doesn't change it`);else if (aspect && input.aspectRatio && aspect !== input.aspectRatio) notes.push(`${model.name} makes ${aspect}, the closest to ${input.aspectRatio}`);if (model.options.promptless && prompt) notes.push(`${model.name} works from your photos alone: the words aren't used`);return {@@ -469,7 +470,7 @@ export function planMarketing(input: MarketingInput, ctx: PlanContext): RunPlanconst steps: Step[] = [];const { after: frameAfter, ...frame } = op === "i2v" ? startFrame(steps, refs[0], aspect, model, `${feature}-step`) : { after: undefined };if (frameAfter) notes.push(`${model.name} keeps its first frame's shape: the photo is grown to ${aspect} on Qwen-Image 2.1 first`);- else if (!open && op === "i2v" && !opTakes(model, "i2v").aspect) notes.push(`${model.name} keeps your photo's shape: Aspect ratio doesn't change it`);+ else if (!open && keepsShape(model, op, aspect)) notes.push(`${model.name} keeps your photo's shape: Aspect ratio doesn't change it`);else if (aspect && input.aspectRatio && aspect !== input.aspectRatio) notes.push(`${model.name} makes ${aspect}, the closest to ${input.aspectRatio}`);steps.push(...shots.map(@@ -1158,6 +1159,45 @@ export function onPlanEngine(plan: RunPlan): RunPlan {return plan.steps.some((s) => pin(s) !== s) ? { ...plan, steps: plan.steps.map(pin) } : plan;}+/** Whether a hosted model's route leaves the shape out on this mode (it keeps the photo's or its own), from its route. */+function keepsShape(model: ModelDef, op: Operation, aspect: string | undefined): boolean {+ return !!aspect && fittedSettings(model, op, { aspectRatio: aspect }, { deliberate: true }).aspectRatio === undefined;+}++/** Whether the plan's own notes already say a step's change (its shape, length or size), so it isn't said twice. */+function alreadySaid(notes: string[], modelName: string, c: SettingChange): boolean {+ const own = notes.filter((n) => n.startsWith(modelName));+ if (c.setting === "aspectRatio") return own.some((n) => /shape|closest to/.test(n));+ if (c.setting === "duration") return own.some((n) => /clips?/.test(n));+ return own.some((n) => n.includes(c.made));+}++/** The steps that make what was asked for (not a helper: a photo grown first, a join, a voice), in order. */+const MADE_OPS = new Set<Operation>(["t2i", "edit", "t2v", "i2v", "ref2v", "avatar"]);++/**+ * The shape, length and quality picked here against what the run's first making step is made at, each with its fix: the+ * value it is made at, or (when the model keeps the photo's own shape) the first model in the list that makes the one+ * picked.+ */+export function pickerFits(plan: RunPlan, asked: { aspectRatio?: string; duration?: number; resolution?: string }, choices: { id: string }[] = []): PickerFit[] {+ const step = plan.steps.find((s) => s.request.op && MADE_OPS.has(s.request.op) && s.request.modelId !== FIT_PHOTO_MODEL);+ const model = step && getModel(step.request.modelId);+ if (!step || !model || !step.request.op) return [];+ const op = step.request.op;+ // A run of several shots is as long as its shots together: its length is the plan's, said in its notes.+ const shots = plan.steps.filter((s) => s.request.modelId === model.id && s.request.op === op).length;+ const fits: PickerFit[] = askedChanges(model, op, { ...model.defaults, ...step.request.params }, { ...asked, ...(shots > 1 && { duration: undefined }) });+ // The plan's own words for a shape it leaves out ("keeps your photo's shape") are the ones said.+ const ownShapeNote = plan.notes.find((n) => n.startsWith(model.name) && /shape/.test(n));+ return fits.map((c) => {+ if (c.use !== undefined || c.setting !== "aspectRatio" || !asked.aspectRatio) return c;+ if (ownShapeNote) c = { ...c, note: ownShapeNote };+ const other = choices.map((x) => getModel(x.id)).find((m) => m && m.id !== model.id && m.engine === model.engine && m.routes.some((r) => r.op === op) && !keepsShape(m, op, nearestAspect(asked.aspectRatio, m.options.aspectRatios)));+ return other ? { ...c, switchTo: { id: other.id, name: other.name } } : c;+ });+}+/** Price and validate every step with placeholders for what earlier steps make (nothing is created). */export function estimatePlan(input: RunPlan, runs = 1): RunEstimate {const plan = onPlanEngine(input);@@ -1170,7 +1210,14 @@ export function estimatePlan(input: RunPlan, runs = 1): RunEstimate {steps.push({ key: s.key, label: s.label, modelId: p.model.id, modelName: p.model.name, costUsd: p.costUsd });total = total === null || p.costUsd === null ? null : total + p.costUsd;}- return { costUsd: total === null ? null : Math.round(total * runs * 1000) / 1000, demo, steps, notes: plan.notes, runs };+ // What a step's route makes differently that the plan's own notes don't say yet (src/lib/catalog/fitted.ts).+ const routeNotes: string[] = [];+ for (const s of plan.steps) {+ const m = getModel(s.request.modelId);+ if (!m || !s.request.op) continue;+ for (const c of stepChanges([{ ...s.request, op: s.request.op }], getModel)) if (!alreadySaid(plan.notes, m.name, c) && !plan.notes.includes(c.note) && !routeNotes.includes(c.note)) routeNotes.push(c.note);+ }+ return { costUsd: total === null ? null : Math.round(total * runs * 1000) / 1000, demo, steps, notes: [...plan.notes, ...routeNotes], runs };}interface RunRow {@@ -1267,7 +1314,10 @@ export function estimateMarketing(input: MarketingInput): RunEstimate {const f = FORMATS[input.format];const script = f.pipeline === "ugc" ? input.script?.trim() || Array(wordBudget(presenterSeconds(input, ctx))).fill("word").join(" ") : undefined;const plan = planMarketing(input, { ...ctx, script });- return estimatePlan(plan, runsFor(input, plan));+ const est = estimatePlan(plan, runsFor(input, plan));+ const choices = formatModels(f, input.engine, { product: !!(input.productImages?.length || ctx.product?.images.length), avatar: !!input.avatar }, !!input.drawnWords && !!f.text && f.pipeline === "image");+ const fits = pickerFits(plan, { aspectRatio: input.aspectRatio, duration: f.durations ? input.duration : undefined }, choices.filter((c) => !c.unavailable));+ return fits.length ? { ...est, fits } : est;}export async function runMarketing(input: MarketingInput): Promise<{ runs: MarketingRun[]; script?: string }> {diff --git a/src/server/mixed-media.ts b/src/server/mixed-media.tsindex 95266d2d..9c0e1df6 100644--- a/src/server/mixed-media.ts+++ b/src/server/mixed-media.ts@@ -1,6 +1,7 @@import "server-only";import { originalSoundOn, type OriginalSound } from "@/lib/av/original-sound";import { getModel } from "@/lib/catalog";+import { routeNotes } from "@/lib/catalog/fitted";import {clampFps,cleanValues,@@ -261,7 +262,8 @@ export async function estimateMixed(body: MixedBody): Promise<MixedEstimate> {modelId: input.modelId,frames,fps,- notes,+ // What a step's route makes differently (src/lib/catalog/fitted.ts) is said with the rest.+ notes: [...notes, ...routeNotes(plan.steps.map((s) => s.request), getModel, notes)],...(input.mode && { mode: input.mode }),...(perFrameUsd !== undefined && { perFrameUsd }),};diff --git a/src/server/photodump.ts b/src/server/photodump.tsindex 7b1dc9b0..9510dc36 100644--- a/src/server/photodump.ts+++ b/src/server/photodump.ts@@ -1,6 +1,7 @@import "server-only";import { nanoid } from "nanoid";import { getModel, getPreset } from "@/lib/catalog";+import { stepChanges } from "@/lib/catalog/fitted";import { CAST_LOOK, CAST_SHEET_MODEL, castPrompt, SOUL_BUILDER_MODEL, type CastValues } from "@/lib/catalog/cinema";import { soulRecipe } from "@/lib/catalog/soul";import {@@ -229,6 +230,13 @@ export function previewRun(requests: GenerationRequest[], notes: string[] = [])const sized = first.route.provider !== "comfyui" || !!loadManifest().workflows.find((w) => w.id === first.route.endpoint)?.bindings.width;const fixedAspect = !first.model.options.aspectRatios?.length || !sized;const asked = requests.some((r) => r.params?.aspectRatio && r.params.aspectRatio !== "auto");+ // What a request's route makes differently (src/lib/catalog/fitted.ts), said before the run; a shape the model leaves+ // out is the line below.+ const said = fixedAspect && asked ? [...notes, `${first.model.name} keeps the shape of your photo — the aspect ratio doesn't apply`] : notes;+ const routeNotes = stepChanges(+ requests.map((r, i) => ({ ...fitted(r), op: previews[i].op })),+ getModel,+ ).filter((c) => !(fixedAspect && c.setting === "aspectRatio") && !said.includes(c.note));return {modelId: first.model.id,modelName: first.model.name,@@ -236,7 +244,7 @@ export function previewRun(requests: GenerationRequest[], notes: string[] = [])costUsd: costs.some((c) => c === null) ? null : Math.round(costs.reduce((a, b) => a! + b!, 0)! * 1000) / 1000,demo: previews.some((p) => p.demo),fixedAspect,- notes: fixedAspect && asked ? [...notes, `${first.model.name} keeps the shape of your photo — the aspect ratio doesn't apply`] : notes,+ notes: [...said, ...routeNotes.map((c) => c.note)],};} catch (e) {return { error: (e as Error).message, notes };diff --git a/src/server/shorts.ts b/src/server/shorts.tsindex 11f025bf..66abf532 100644--- a/src/server/shorts.ts+++ b/src/server/shorts.ts@@ -2,6 +2,7 @@ import "server-only";import { originalSoundOn, type OriginalSound } from "@/lib/av/original-sound";import { nanoid } from "nanoid";import { getModel } from "@/lib/catalog";+import { routeNotes } from "@/lib/catalog/fitted";import { maxRefsFor, reframes, resolutionFor, sourceSeconds } from "@/lib/catalog/shorts-models";import {clipLengthProblem,@@ -522,13 +523,16 @@ export function estimateWith(body: ShortsBody, info: SourceInfo): ShortsEstimatesegments: plan.segments.length,seconds: Math.round((input.range.end - input.range.start) * 10) / 10,refsSent: input.engine === "open" ? Math.min(SHORTS.openReferences, input.look.references?.length ?? 0) : Math.min(input.maxRefs, input.look.references?.length ?? 0),- notes: notesFor(input, plan.segments.length),+ notes: withRouteNotes(notesFor(input, plan.segments.length), plan.steps),};}// ---------------------------------------------------------------------------// Sessions+/** A plan's notes and what its steps' routes make differently (src/lib/catalog/fitted.ts). */+const withRouteNotes = (notes: string[], steps: PlanStep[]) => [...notes, ...routeNotes(steps.map((s) => s.request), getModel, notes)];+/** A plan's steps as the requests they make, with how many earlier steps each waits for (account-tool-run.ts ToolStep). */export const shortsSteps = (steps: PlanStep[]): { request: GenerationRequest; deps: number }[] => steps.map((s) => ({ request: withChain(s), deps: s.after?.length ?? 0 }));diff --git a/tests/marketing-fits.test.ts b/tests/marketing-fits.test.tsnew file mode 100644index 00000000..c2a64e93--- /dev/null+++ b/tests/marketing-fits.test.ts@@ -0,0 +1,38 @@+import { describe, expect, it } from "vitest";+import { tempDir } from "./helpers/temp-dir";++process.env.FUOBE_DATA_DIR = tempDir("fuobe-marketing-fits-");++const mk = await import("@/server/marketing");+const { FORMATS, formatModels } = await import("@/lib/catalog/marketing");++/**+ * Marketing Studio says before a run when the shape or length picked is made differently (src/lib/catalog/fitted.ts),+ * with the one-tap way to what is made, or to a model in the list that makes the one picked.+ */+const photo = "/api/files/product.png";+const choices = (format: keyof typeof FORMATS) => formatModels(FORMATS[format], "cloud", { product: true, avatar: false }).filter((c) => !c.unavailable);++describe("Marketing Studio's picked shape and length", () => {+ it("a model that keeps the photo's shape says so, and offers one that makes the shape picked", () => {+ const plan = mk.planMarketing({ engine: "cloud", format: "motion-2d", modelId: "kling-o3", aspectRatio: "9:16", productImages: [photo] }, {});+ const fits = mk.pickerFits(plan, { aspectRatio: "9:16" }, choices("motion-2d"));+ expect(fits).toEqual([expect.objectContaining({ setting: "aspectRatio", asked: "9:16", switchTo: expect.objectContaining({ id: expect.any(String) }) })]);+ expect(fits[0].use).toBeUndefined();+ expect(fits[0].switchTo!.id).not.toBe("kling-o3");+ // The plan says it in its own words, once.+ expect(plan.notes.filter((n) => /Kling O3 Omni keeps your photo's shape/.test(n))).toHaveLength(1);+ });++ it("a shape the model makes as picked says nothing", () => {+ const plan = mk.planMarketing({ engine: "cloud", format: "motion-2d", modelId: "gemini-omni-flash", aspectRatio: "9:16", productImages: [photo] }, {});+ expect(mk.pickerFits(plan, { aspectRatio: "9:16" }, choices("motion-2d"))).toEqual([]);+ });++ it("a product shot model that keeps its own shape says so before the run", () => {+ const plan = mk.planMarketing({ engine: "cloud", format: "product-standalone", modelId: "bria-product-shot", aspectRatio: "9:16", productImages: [photo] }, {});+ const fits = mk.pickerFits(plan, { aspectRatio: "9:16" }, choices("product-standalone"));+ expect(fits[0]).toMatchObject({ setting: "aspectRatio", asked: "9:16" });+ expect(plan.notes.some((n) => /Bria Product Shot keeps your photo's shape/.test(n))).toBe(true);+ });+});diff --git a/tests/studio-made-values.test.ts b/tests/studio-made-values.test.tsnew file mode 100644index 00000000..a3eb2f5d--- /dev/null+++ b/tests/studio-made-values.test.ts@@ -0,0 +1,124 @@+import { describe, expect, it } from "vitest";+import { getModel, PRESETS } from "@/lib/catalog";+import { askedChanges, fittedSettings, routeNotes } from "@/lib/catalog/fitted";+import { ENGINE_MODELS } from "@/lib/catalog/faceless";+import { MAKERS } from "@/lib/catalog/genjutsu";+import { MIXED_MODELS, nearestResolution } from "@/lib/catalog/mixed-media";+import { presetRoutes } from "@/lib/catalog/preset-recipe-routes";+import { RESTORE_UPSCALE } from "@/lib/catalog/restore";+import { SHORTS_RATIOS } from "@/lib/catalog/shorts";+import { reframes, resolutionFor } from "@/lib/catalog/shorts-models";+import { STORYBOARD_ASPECTS, STORYBOARD_MODELS, STORYBOARD_PARTNERS } from "@/lib/catalog/storyboard";+import { TURN_ROUTES } from "@/lib/catalog/turnaround";+import type { GenParams, ModelDef, Operation } from "@/lib/catalog/types";+import { INFLUENCER_CLOUD_MODELS, INFLUENCER_START, planInfluencer } from "@/lib/influencer";++/**+ * Every value a studio offers or fills in by itself for a hosted model is one that model's route makes as offered+ * (src/lib/catalog/fitted.ts), so a run never comes out at another size, shape or length without a word. A studio whose+ * list drifts from its routes fails here; the run would still say so in its notes.+ */+const model = (id: string): ModelDef => {+ const m = getModel(id);+ if (!m) throw new Error(`no ${id}`);+ return m;+};+const KEPT = ["resolution", "aspectRatio", "duration"] as const;++/** The changes to a size, shape or length a request makes on its model's route (the values picked on purpose). */+function changes(id: string, op: Operation, params: GenParams): string[] {+ const m = model(id);+ if (!m.routes.some((r) => r.op === op)) return [];+ return fittedSettings(m, op, params, { deliberate: true })+ .changes.filter((c) => (KEPT as readonly string[]).includes(c.setting) && !(c.setting === "aspectRatio" && params.aspectRatio === "auto"))+ .map((c) => `${id} ${op}: ${c.note}`);+}+const opsOf = (id: string) => [...new Set(model(id).routes.map((r) => r.op))];++describe("each studio's own values are made as offered", () => {+ it("Genjutsu: every maker's qualities", () => {+ const off = MAKERS.filter((mk) => getModel(mk.id)).flatMap((mk) => (mk.qualities ?? []).flatMap((q) => opsOf(mk.id).flatMap((op) => changes(mk.id, op, { resolution: q }))));+ expect(off).toEqual([]);+ });++ it("Mixed media: Fast's sizes for 1K, 2K and 4K", () => {+ const off = MIXED_MODELS.cloud.flatMap((id) =>+ (["1K", "2K", "4K"] as const).flatMap((want) => {+ const r = nearestResolution(model(id).options.resolutions, want);+ return r ? changes(id, "v2v", { resolution: r }) : [];+ }),+ );+ expect(off).toEqual([]);+ });++ it("Shorts: 9:16 and 16:9 at 720p on every restyle model", () => {+ const ids = [...new Set([...MIXED_MODELS.cloud])];+ const off = ids.flatMap((id) => SHORTS_RATIOS.flatMap((r) => changes(id, "v2v", { ...(reframes(id) && { aspectRatio: r.value }), ...(resolutionFor(id) && { resolution: resolutionFor(id) }) })));+ expect(off).toEqual([]);+ });++ it("Storyboards: every shape on the cloud's frame models and the partner", () => {+ const sets = [STORYBOARD_MODELS.cloud, ...Object.values(STORYBOARD_PARTNERS)];+ const off = sets.flatMap((s) => [...new Set([s.first, s.firstWithRefs, s.next])].flatMap((id) => STORYBOARD_ASPECTS.flatMap((a) => opsOf(id).flatMap((op) => changes(id, op, { aspectRatio: a })))));+ // 21:9 on the cloud's own frame models is said by boardShapeProblem (made 16:9, cropped by a look).+ expect(off.filter((l) => !/21:9/.test(l))).toEqual([]);+ });++ it("Turnaround: each cloud route's lengths and size", () => {+ const off = Object.values(TURN_ROUTES)+ .filter((r) => r.engine === "cloud")+ .flatMap((r) => r.durations.flatMap((d) => opsOf(r.modelId).flatMap((op) => changes(r.modelId, op, { duration: d, resolution: r.resolution }))));+ expect(off).toEqual([]);+ });++ it("AI Influencer: the sheet and the dressing step on each cloud model", () => {+ const off = INFLUENCER_CLOUD_MODELS.flatMap((modelId) =>+ [undefined, "face.png"].flatMap((photo) =>+ planInfluencer({ engine: "cloud", state: INFLUENCER_START, start: photo ? "face" : "scratch", photo, modelId }, {}).steps.flatMap((s) => changes(s.request.modelId, s.request.op!, s.request.params ?? {})),+ ),+ );+ expect(off).toEqual([]);+ });++ it("apps and motions: every cloud recipe's own settings", () => {+ const off = PRESETS.flatMap((p) =>+ presetRoutes(p, "cloud", (id) => !!getModel(id))+ .filter((r) => r.params && getModel(r.modelId)?.engine === "cloud")+ .flatMap((r) => changes(r.modelId, r.op, r.params!)),+ );+ expect(off).toEqual([]);+ });++ it("Faceless: the channel avatar (1:1) on the cloud's picture model", () => {+ const id = ENGINE_MODELS.cloud.still;+ expect(opsOf(id).flatMap((op) => changes(id, op, { aspectRatio: "1:1" }))).toEqual([]);+ });++ it("Restore's finish: Topaz Video to 2160p", () => {+ expect(changes(RESTORE_UPSCALE.cloud.modelId, "upscale-video", RESTORE_UPSCALE.cloud.params)).toEqual([]);+ });+});++describe("a studio's estimate says what a route makes differently", () => {+ it("names the change once, and not what the studio says already", () => {+ const req = { modelId: "minimax-h3-max-turbo", op: "t2v" as const, params: { resolution: "2K" } };+ const notes = routeNotes([req, req], getModel);+ expect(notes).toEqual(["MiniMax H3 Max Turbo makes up to 1080p, so this is made at 1080p"]);+ expect(routeNotes([req], getModel, notes)).toEqual([]);+ });++ it("compares a picker's own value with what is made, with the value to use", () => {+ const turbo = model("minimax-h3-max-turbo");+ // The studio sent the closest its options list (4:3 for 5:4); the route makes it as sent.+ expect(askedChanges(turbo, "t2v", { aspectRatio: "4:3" }, { aspectRatio: "5:4" })).toEqual([+ expect.objectContaining({ setting: "aspectRatio", asked: "5:4", made: "4:3", use: "4:3", note: "MiniMax H3 Max Turbo makes 4:3, the closest to 5:4" }),+ ]);+ // The route fits it again: its own words.+ expect(askedChanges(turbo, "t2v", { resolution: "2K" }, { resolution: "2K" })[0]).toMatchObject({ made: "1080p", use: "1080P" });+ // A start frame's shape: picked on purpose, so even the default is said, with nothing to use instead.+ const kept = askedChanges(turbo, "i2v", { aspectRatio: turbo.defaults?.aspectRatio ?? "16:9" }, { aspectRatio: turbo.defaults?.aspectRatio ?? "16:9" });+ expect(kept[0]).toMatchObject({ setting: "aspectRatio", made: "The start frame's shape" });+ expect(kept[0].use).toBeUndefined();+ expect(askedChanges(turbo, "t2v", { aspectRatio: "16:9" }, { aspectRatio: "16:9" })).toEqual([]);+ });+});