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
Pickers and galleries: what this install's GPUs don't run shows with its setup label
Adarsh7119f3cc0f12
diff --git a/src/components/preset-gallery.tsx b/src/components/preset-gallery.tsxindex 28a896f5..17737747 100644--- a/src/components/preset-gallery.tsx+++ b/src/components/preset-gallery.tsx@@ -12,7 +12,9 @@ import { useProgressive } from "@/components/use-progressive";import { CardChip, badgeKey, parseBadgeKey } from "@/components/gpu/readiness-chip";import { useGpuBadges } from "@/hooks/use-gpu";import { usePoolRules, useTryFree } from "@/hooks/use-pool-rules";-import { presetOffered } from "@/lib/pool-rules";+import { presetOwnSetup } from "@/lib/pool-rules";+import { OwnSetupChip } from "@/components/own-setup";+import type { OwnSetup } from "@/lib/own-setup";import { useEngineMode, useViewer } from "@/lib/api";import { categoryFrom, skippedInAll } from "@/lib/gallery-category";import { matchesSearch, previewFlip, readMoreTap, searchText, TAP_TO_READ, type PresetCardData } from "@/lib/preset-cards";@@ -46,6 +48,7 @@ export const PresetCard = memo(function PresetCard({engine,gpu,gpuName,+ setup,}: {preset: PresetCardData;href: string;@@ -63,11 +66,13 @@ export const PresetCard = memo(function PresetCard({/** Its state on the viewer's GPU (a badge as one string, badgeKey), or none. */gpu?: string;gpuName?: string;+ /** It runs on the visitor's own GPU only (the hosted-run rules keep it off this studio's GPUs): its label. */+ setup?: OwnSetup | null;}) {const badge = engine !== "cloud" ? parseBadgeKey(gpu) : null;// Hosted runs on, and this preset runs on this studio's GPUs for the viewer: the card says it can be tried there.const card = useTryFree();- const tryFree = card && card.runs(preset) && !badge ? card.text : null;+ const tryFree = card && card.runs(preset) && !badge && !setup ? card.text : null;const Icon = PRESET_ICONS[preset.icon] ?? Sparkles;const { ref, playing, asked, handlers } = usePreviewPlayback<HTMLAnchorElement>(preset.id, preset.preview);const [more, setMore] = useState(false);@@ -102,6 +107,11 @@ export const PresetCard = memo(function PresetCard({<CardChip badge={badge} gpu={gpuName} /></span>)}+ {setup && !badge && (+ <span className="pointer-events-none absolute top-1.5 right-1.5 max-w-[calc(100%-0.75rem)]">+ <OwnSetupChip setup={setup} className="bg-background/90" />+ </span>+ )}{tryFree && (<span data-try-free className="pointer-events-none absolute top-1.5 right-1.5 rounded-full bg-primary px-1.5 py-0.5 text-[10.5px] font-semibold text-primary-foreground">{tryFree}@@ -263,16 +273,15 @@ export function PresetGallery({const [q, setQ] = useState("");const [runsOnChoice, setRunsOn] = useState<RunsOn>("all");// For a viewer with no GPU of its own (hosted runs), a preset only this studio's GPUs could run, and which they keep- // off, is left out (src/lib/pool-rules.ts): nothing here fails at Run for it.+ // off, stays with what runs it (its own-setup label, src/lib/pool-rules.ts): Run then opens that setup.const rules = usePoolRules();- const offered = useMemo(() => (rules ? presets.filter((p) => presetOffered(rules, p)) : presets), [presets, rules]);// "both" until hydrated, so the server HTML and the first client render agree.const mode = useEngineMode();const locked = mode === "both" ? undefined : mode;const runsOn: RunsOn = locked ?? runsOnChoice;const query = useDeferredValue(q.trim().toLowerCase());- const index = useMemo(() => offered.map((p) => [p, searchText(p)] as const), [offered]);+ const index = useMemo(() => presets.map((p) => [p, searchText(p)] as const), [presets]);const cats = useMemo(() => ["All", ...categories], [categories]);const list = useMemo(() =>@@ -308,7 +317,7 @@ export function PresetGallery({type="search"value={q}onChange={(e) => setQ(e.target.value)}- placeholder={`Search ${offered.length} ${noun}`}+ placeholder={`Search ${presets.length} ${noun}`}aria-label={`Search ${noun}`}className="h-9 w-full rounded-full border bg-background pr-9 pl-9 text-[14px] outline-none placeholder:text-subtle-foreground focus:border-primary focus:ring-4 focus:ring-brand-faint [&::-webkit-search-cancel-button]:hidden"/>@@ -325,7 +334,7 @@ export function PresetGallery({</div><div className="flex items-center justify-between gap-2 sm:ml-auto sm:justify-end"><span className="order-last text-[12px] whitespace-nowrap text-muted-foreground tabular-nums sm:order-first sm:mr-2" aria-live="polite">- {list.length === offered.length || (cat === "All" && !query && runsOn === "all") ? `${offered.length} ${noun}` : `${list.length} of ${offered.length}`}+ {list.length === presets.length || (cat === "All" && !query && runsOn === "all") ? `${presets.length} ${noun}` : `${list.length} of ${presets.length}`}</span><RunsOnControl value={runsOn} onChange={setRunsOn} locked={locked} owner={!!viewer?.owner} /></div>@@ -370,7 +379,7 @@ export function PresetGallery({<LeadingCard key={c.href} card={c} />))}{list.slice(0, shown).map((p) => (- <PresetCard key={p.id} preset={p} href={href.replace("{id}", p.id)} engine={locked} gpu={p.open ? badgeKey(badges?.presets[p.id]) : undefined} gpuName={badges?.gpu} />+ <PresetCard key={p.id} preset={p} href={href.replace("{id}", p.id)} engine={locked} gpu={p.open ? badgeKey(badges?.presets[p.id]) : undefined} gpuName={badges?.gpu} setup={presetOwnSetup(rules, p)} />))}</div>{hasMore && (diff --git a/src/components/studio/composer.tsx b/src/components/studio/composer.tsxindex 91fcf1d8..aa7ec362 100644--- a/src/components/studio/composer.tsx+++ b/src/components/studio/composer.tsx@@ -22,7 +22,8 @@ import { formatsOf } from "@/lib/av/formats";import { poolRunState, quoteBody, useHostedQuote, useSettled, type RunOn } from "@/lib/hosted";import { composerOnPool, composerPlace } from "@/lib/run-place";import { PoolNote } from "./pool-note";-import { poolRunsModel } from "@/lib/pool-rules";+import { modelOwnSetup, poolRunsModel } from "@/lib/pool-rules";+import { OwnSetupChip, useOwnSetupPress, useOwnSetupViewer } from "@/components/own-setup";import { HoldFilesCtx } from "@/lib/held-files";import { pendingStep } from "@/lib/guest-draft";import { useGuestDraft } from "./guest-draft";@@ -330,12 +331,14 @@ export function Composer({ docked }: { docked: boolean }) {}, []);const pickerOps = config.pickerOps ?? config.ops;- // For a viewer with no GPU of its own (hosted runs), the open models this studio's GPUs keep off are left out.+ // For a viewer with no GPU of its own (hosted runs), the open models this studio's GPUs keep off stay in the list with+ // what runs them (their own-setup label, src/lib/pool-rules.ts), as the models that run on a visitor's own setup only+ // do: Run then opens that setup.const poolRules = status?.viewer?.hosted && !status.viewer.gpu.connected ? status.viewer.pool : undefined;- const models = useMemo(- () => filterModels(catalog.models, { kind: config.kind, ops: pickerOps }).filter((m) => poolRunsModel(poolRules, m)),- [catalog.models, config.kind, pickerOps, poolRules],- );+ const models = useMemo(() => filterModels(catalog.models, { kind: config.kind, ops: pickerOps }), [catalog.models, config.kind, pickerOps]);+ const setupViewer = useOwnSetupViewer();+ const pressSetup = useOwnSetupPress();+ const modelSetup = useCallback((m: ModelDef) => (setupViewer ? modelOwnSetup(poolRules, m) : null), [setupViewer, poolRules]);const model: ModelDef | undefined = catalog.getModel(draft.modelId);// MiniMax H3 on your GPU has a References mode (Pika H3 Flex): reference clips and voice or music clips beside the images.const refMode = config.ops.includes("ref2v") ? openReferenceMode(model) : null;@@ -348,9 +351,10 @@ export function Composer({ docked }: { docked: boolean }) {const preset: Preset | undefined = draft.presetId && !takesLook ? catalog.getPreset(draft.presetId) : config.preset;const lockedModel = preset?.type === "app";// Fuobe DoP's orbit moves: the Exact switch films the orbit by its numbers through /api/fly-around.- // It starts with a 3D depth step and runs on the studio's own GPU: the owner's for now.+ // It starts with a 3D depth step and films on a 48 GB GPU or a fal.ai key: a visitor sees it with that label, and Run+ // opens the setup it lacks (own-setup.ts "fly-around:exact-orbit").const owner = useIsOwner();- const exactId = owner && preset?.type === "motion" && takesExact(preset.id) ? preset.id : undefined;+ const exactId = preset?.type === "motion" && takesExact(preset.id) ? preset.id : undefined;const [exactBy, setExactBy] = useState<{ id: string; orbit: ExactOrbit } | null>(null);const exact = exactId && exactBy?.id === exactId ? exactBy.orbit : null;const exactImage = draft.slots.image?.ref;@@ -475,13 +479,21 @@ export function Composer({ docked }: { docked: boolean }) {toast(`${offModel.name} is turned off in Settings → Models & licences, so this uses ${m.name}`, { id: "model-access" });}, [offModel, fallback, lockedModel, presetFallback, catalog, setDraft]);- // A model this studio's GPUs keep off, for a viewer with no GPU of its own (the studio's default, a link, a Reuse): the- // composer moves to the studio's default, else the first model of its list they run, before Run could fail on it.- const poolOff = model && !lockedModel && !presetFallback && !offModel && !poolRunsModel(poolRules, model) ? model : undefined;- const poolTo = poolOff ? [defaults[engine], ...models.filter((m) => m.engine === engine).map((m) => m.id)].find((id) => !!id && id !== poolOff.id && models.some((m) => m.id === id)) : undefined;+ // The studio's untouched default that this studio's GPUs keep off, for a viewer with no GPU of its own: the composer+ // moves to the first model of its list they run. A model the person picked (or a link, a Reuse) stays, with its label,+ // and Run opens the setup that runs it.+ const untouched = !!model && (model.id === config.defaultModels[engine] || model.id === defaults[engine]);+ const poolOff = model && untouched && !lockedModel && !presetFallback && !offModel && !poolRunsModel(poolRules, model) ? model : undefined;+ const poolTo = poolOff+ ? [defaults[engine], ...models.filter((m) => m.engine === engine).map((m) => m.id)].find((id) => {+ const m = id && id !== poolOff.id ? models.find((x) => x.id === id) : undefined;+ return !!m && poolRunsModel(poolRules, m) && !modelSetup(m);+ })+ : undefined;useEffect(() => {const m = poolOff && poolTo ? catalog.getModel(poolTo) : undefined;- if (!m || !poolOff) return;+ // A link that names the model keeps it.+ if (!m || !poolOff || new URLSearchParams(window.location.search).get("model") === poolOff.id) return;setDraft((d) => (d.modelId !== poolOff.id ? {} : { modelId: m.id, params: { ...m.defaults, numOutputs: d.params.numOutputs, enhancePrompt: d.params.enhancePrompt }, ...lookCleared(poolOff, m) }));}, [poolOff, poolTo, catalog, setDraft]);@@ -667,6 +679,8 @@ export function Composer({ docked }: { docked: boolean }) {// the price, and where the run would stand in line with the wait.const poolState = poolPrice ? poolRunState(hostedCheck) : null;const poolRefused = !!poolState?.refused;+ // Refused because it runs on the visitor's own GPU or key: Run opens that setup instead of staying off.+ const poolSetup = poolRefused ? poolState?.setup : undefined;const resolvesOnServer = mentions.mentioned.length > 0 || !!draft.slots.mask?.ref || !!draft.slots.sketch?.ref;// Plan with stand-ins for attachments that are missing or still uploading, so the cost and the@@ -813,12 +827,17 @@ export function Composer({ docked }: { docked: boolean }) {if (stop) return void toast(stop, { id: "composer-blocker" });if (fly.run.isPending) return;toast.dismiss("composer-blocker");- fly.run.mutate({ engine, image: exactImage, orbit: exact, prompt: draft.prompt.trim() || undefined, feature: config.feature });+ pressSetup(owner ? null : "fly-around:exact-orbit", () => fly.run.mutate({ engine, image: exactImage, orbit: exact, prompt: draft.prompt.trim() || undefined, feature: config.feature }));return;}if (keyToAdd && model && !create.isPending) return openAddKey(keyToAdd, model.id);if (!blocker && gpuSetup && !skipGpu && !create.isPending) return openGpuFix();// Refused by the price check (Run is off; Enter in the prompt lands here too): its words, and nothing is sent.+ if (!blocker && poolSetup) {+ // An account that has the setup (its own GPU, or the key that runs it) runs it there.+ if (pressSetup(poolSetup)) setRunOn("own");+ return;+ }if (!blocker && poolRefused && poolState) return void toast(poolState.text, { id: "composer-blocker" });if (blocker || create.isPending || signature.lock.isPending) {if (blocker) {@@ -1480,7 +1499,9 @@ export function Composer({ docked }: { docked: boolean }) {value={exact}defaults={exactDefaults(exactId)}onChange={(orbit) => setExactBy(orbit ? { id: exactId, orbit } : null)}- footer={exact && exactImage && fly.preview.data?.blocker ? <span>{fly.preview.data.blocker}</span> : undefined}+ footer={+ exact && exactImage && fly.preview.data?.blocker ? <span>{fly.preview.data.blocker}</span> : !owner ? <OwnSetupChip setup="fly-around:exact-orbit" className="mt-1" /> : undefined+ }/>)}@@ -1624,6 +1645,7 @@ export function Composer({ docked }: { docked: boolean }) {flat={appChoice}madeWith={madeWith}boxes={layoutOn}+ ownSetup={modelSetup}/>) : (<Chip icon={Loader2} disabled className="[&>svg]:animate-spin">@@ -1744,7 +1766,7 @@ export function Composer({ docked }: { docked: boolean }) {<Buttonsize="icon"onClick={submit}- disabled={create.isPending || signature.lock.isPending || poolRefused}+ disabled={create.isPending || signature.lock.isPending || (poolRefused && !poolSetup)}aria-label={blocker ? `Generate — ${blocker.message}` : poolRefused && poolState ? `Generate — ${poolState.text}` : "Generate"}aria-busy={create.isPending || signature.lock.isPending || undefined}// Blocked, it stays the brand colour (paler, the arrow still 3:1 or more): pressing it still says what's missing and points at it.diff --git a/src/components/studio/model-picker.tsx b/src/components/studio/model-picker.tsxindex cc9f99d7..41053c68 100644--- a/src/components/studio/model-picker.tsx+++ b/src/components/studio/model-picker.tsx@@ -5,6 +5,8 @@ import Link from "next/link";import { useEffect, useMemo, useRef, useState } from "react";import { KEY_ADDED_EVENT, openAddKey } from "@/components/keys/your-keys";import { Badge } from "@/components/ui/badge";+import { OwnSetupChip } from "@/components/own-setup";+import type { OwnSetup } from "@/lib/own-setup";import { Button } from "@/components/ui/button";import { Command, CommandGroup, CommandInput, CommandItem, CommandList } from "@/components/ui/command";import { RowDot } from "@/components/gpu/readiness-chip";@@ -77,7 +79,7 @@ function starKey(e: React.KeyboardEvent<HTMLElement>, toggle: (id: string) => votoggle(id);}-function ModelRow({+export function ModelRow({m,selected,starred,@@ -90,6 +92,7 @@ function ModelRow({needs,made,edits,+ setup,}: {m: ModelDef;selected: boolean;@@ -109,6 +112,8 @@ function ModelRow({made?: boolean;/** The studio edits clips (Edit video): the price is an edit's, on the seconds in and out (Kling 4.0). */edits?: boolean;+ /** It runs on the visitor's own GPU or key (own-setup.ts): its label in place of the price; Run then opens that setup. */+ setup?: OwnSetup | null;}) {return (<>@@ -149,7 +154,9 @@ function ModelRow({</span>)}</span>- {needs ? (+ {setup && !needs ? (+ <OwnSetupChip setup={setup} className="h-auto min-h-4 max-w-[45%]" />+ ) : needs ? (// On a phone the short words, so the model's name keeps its room.<span className="shrink-0 text-right text-[11px] font-medium text-brand-text"><span className="sm:hidden">Add key</span>@@ -197,6 +204,11 @@ interface PickerProps {flat?: boolean;/** The model the active preset's live preview really came from: "Used for this preview" on its row. */madeWith?: string;+ /**+ * What a model needs on the visitor's own setup (own-setup.ts, the hosted-run rules), or null: such a model is listed+ * with that label in place of its price, never left out.+ */+ ownSetup?: (m: ModelDef) => OwnSetup | null;}/**@@ -288,6 +300,7 @@ function PickerList({recipe,flat,madeWith,+ ownSetup,onPicked,onNeedsKey,}: PickerProps & { onPicked: () => void; onNeedsKey?: (m: ModelDef, p: CloudProvider) => void }) {@@ -414,6 +427,7 @@ function PickerList({needs={needsKey(m, status)}made={m.id === madeWith}edits={editsClips}+ setup={ownSetup?.(m)}/></CommandItem>))}diff --git a/src/components/studio/preset-chips.tsx b/src/components/studio/preset-chips.tsxindex 34400fc7..b75902a3 100644--- a/src/components/studio/preset-chips.tsx+++ b/src/components/studio/preset-chips.tsx@@ -12,7 +12,9 @@ import { onAttr, TAB_PILL, TabRow } from "@/components/ui/tab-row";import { CoverScrollBox, CoverTile, usePickerPlayback } from "@/components/cover-tile";import { PRESET_ICONS } from "@/components/preset-icons";import { usePoolRules } from "@/hooks/use-pool-rules";-import { presetOffered } from "@/lib/pool-rules";+import { presetOwnSetup, type PoolRules } from "@/lib/pool-rules";+import { OwnSetupChip } from "@/components/own-setup";+import type { OwnSetup } from "@/lib/own-setup";import { loadFullCatalog, useCatalog } from "./catalog";import { Chip, ClearableChip } from "./chip";@@ -26,7 +28,7 @@ import { Chip, ClearableChip } from "./chip";const tileClass = "group flex flex-col items-start gap-1 overflow-hidden rounded-lg p-1 text-left ring-primary transition hover:bg-accent";-function PresetTile({ preset: p, picked, onPick }: { preset: Preset; picked: boolean; onPick: () => void }) {+function PresetTile({ preset: p, picked, onPick, setup }: { preset: Preset; picked: boolean; onPick: () => void; setup?: OwnSetup | null }) {const { playing, handlers } = usePickerPlayback(p.id, { picked });const PI = PRESET_ICONS[p.look.icon] ?? Film;return (@@ -43,11 +45,30 @@ function PresetTile({ preset: p, picked, onPick }: { preset: Preset; picked: boo}/><span className="w-full truncate px-0.5 text-[12px] font-medium">{p.name}</span>+ {setup && <OwnSetupChip setup={setup} className="mx-0.5" />}</button>);}-export function PresetGrid({ list, value, onPick, noneLabel }: { list: Preset[] | null; value?: string; onPick: (id: string | undefined) => void; noneLabel: string }) {+/**+ * The picker's grid. `rules` (hosted runs, a viewer with no GPU of its own): a preset only this studio's GPUs could run+ * and which they keep off stays, with what runs it (its own-setup label); Run then opens that setup.+ */+export function PresetGrid({+ list,+ value,+ onPick,+ noneLabel,+ rules,+ engine,+}: {+ list: Preset[] | null;+ value?: string;+ onPick: (id: string | undefined) => void;+ noneLabel: string;+ rules?: PoolRules;+ engine?: "open" | "cloud";+}) {const [cat, setCat] = useState<string>("All");const box = useRef<HTMLDivElement>(null);const ordered = useMemo(() => (list ? featuredAll(list) : null), [list]);@@ -89,7 +110,7 @@ export function PresetGrid({ list, value, onPick, noneLabel }: { list: Preset[]{ordered.filter((p) => cat === "All" || p.category === cat).map((p) => (- <PresetTile key={p.id} preset={p} picked={value === p.id} onPick={() => onPick(p.id)} />+ <PresetTile key={p.id} preset={p} picked={value === p.id} onPick={() => onPick(p.id)} setup={presetOwnSetup(rules, p, engine)} />))}</div></div>@@ -122,11 +143,10 @@ export function PresetChip({ type, value, onChange, engine }: { type: "motion" |const [open, setOpen] = useState(false);const { chip, side, measure } = usePickerSide();const catalog = useCatalog();- // For a viewer with no GPU of its own, what this studio's GPUs keep off is left out (src/lib/pool-rules.ts), unless- // the preset has a cloud route and the composer isn't on the open engine (the gallery keeps those too).+ // For a viewer with no GPU of its own, what this studio's GPUs keep off shows with its own-setup label+ // (src/lib/pool-rules.ts), unless the preset has a cloud route and the composer isn't on the open engine.const rules = usePoolRules();- const all = catalog.presets?.[type] ?? null;- const list = useMemo(() => (all && rules ? all.filter((p) => presetOffered(rules, p, engine)) : all), [all, rules, engine]);+ const list = catalog.presets?.[type] ?? null;const selected = value ? catalog.getPreset(value) : undefined;// The picked preset's poster in place of its icon, as the Look chip shows its look.const cover = selected && presetCover(selected.id);@@ -153,6 +173,8 @@ export function PresetChip({ type, value, onChange, engine }: { type: "motion" |<PresetGridlist={list}value={value}+ rules={rules}+ engine={engine}noneLabel="None"onPick={(id) => {onChange(id);@@ -198,8 +220,8 @@ export function MixChip({const presets = catalog.presets;const rules = usePoolRules();const mixable = useMemo(- () => (presets ? [...presets.motion, ...presets.effect].filter((p) => p.id !== primary.id && !p.inputs.some((i) => i.key === "endImage") && presetOffered(rules, p, engine)) : null),- [presets, primary.id, rules, engine],+ () => (presets ? [...presets.motion, ...presets.effect].filter((p) => p.id !== primary.id && !p.inputs.some((i) => i.key === "endImage")) : null),+ [presets, primary.id],);return (<ClearableChip active={!!mix} onClear={() => onChange({ mix: undefined })} clearLabel="Remove the mix">@@ -247,6 +269,8 @@ export function MixChip({<PresetGridlist={mixable}value={mix?.presetId}+ rules={rules}+ engine={engine}noneLabel="No mix"onPick={(id) => onChange({ mix: id ? { presetId: id, strength: mix?.strength ?? 0.6 } : undefined })}/>diff --git a/src/components/studio/run-place-chip.tsx b/src/components/studio/run-place-chip.tsxindex b0f33d93..8422d9eb 100644--- a/src/components/studio/run-place-chip.tsx+++ b/src/components/studio/run-place-chip.tsx@@ -5,6 +5,7 @@ import Link from "next/link";import { usePathname } from "next/navigation";import { useState } from "react";import { openAddKey } from "@/components/keys/your-keys";+import { useOwnSetupPress } from "@/components/own-setup";import { Button } from "@/components/ui/button";import { useIsMobile } from "@/hooks/use-mobile";import type { Engine, GenerationRequest } from "@/lib/catalog/types";@@ -95,6 +96,7 @@ export function RunPlaceChip({}) {const [open, setOpen] = useState(false);const pathname = usePathname();+ const press = useOwnSetupPress();// A phone's sheet says the title and the tip in its own header; the desktop popover says them here.const mobile = useIsMobile();if (!place) return null;@@ -163,12 +165,17 @@ export function RunPlaceChip({<Link href={signInHref("signup", pathname)}>Sign up free</Link></Button>)}- {place.needs === "gpu" && (+ {place.setup && place.needs && place.needs !== "signup" && (+ <Button size="sm" className="w-full" onClick={() => (setOpen(false), press(place.setup))}>+ {place.needs === "key" ? "Add your key" : "Connect your GPU"}+ </Button>+ )}+ {!place.setup && place.needs === "gpu" && (<Button size="sm" className="w-full" onClick={() => (setOpen(false), window.dispatchEvent(new Event(CONNECT_GPU_EVENT)))}>Connect your GPU</Button>)}- {place.needs === "key" && (+ {!place.setup && place.needs === "key" && (<Button size="sm" className="w-full" onClick={() => (setOpen(false), openAddKey("fal"))}>Add your key</Button>diff --git a/src/hooks/use-pool-rules.ts b/src/hooks/use-pool-rules.tsindex 84abb54d..9162f626 100644--- a/src/hooks/use-pool-rules.ts+++ b/src/hooks/use-pool-rules.ts@@ -4,8 +4,8 @@ import { useEngineMode, useHydrated, useStatus } from "@/lib/api";import { tryFreeFor, type PoolRules } from "@/lib/pool-rules";/**- * What this studio's GPUs keep off for this viewer (hosted runs on, no GPU of its own): pickers leave it out- * (src/lib/pool-rules.ts). Undefined when nothing is kept off, with hosted runs off, or for a viewer with its own GPU.+ * What this studio's GPUs keep off for this viewer (hosted runs on, no GPU of its own): pickers show it with its+ * own-setup label (src/lib/pool-rules.ts), and Run opens that setup. Undefined when nothing is kept off, with hosted runs off, or for a viewer with its own GPU.*/export function usePoolRules(): PoolRules | undefined {const v = useStatus().data?.viewer;diff --git a/src/lib/pool-rules.ts b/src/lib/pool-rules.tsindex c7e17bb7..482fbffe 100644--- a/src/lib/pool-rules.ts+++ b/src/lib/pool-rules.ts@@ -115,9 +115,11 @@ export function presetOffered(rules: PoolRules | undefined, p: { id: string; ope* The label a picker or gallery shows on a preset the rules keep off (presetOffered false), instead of leaving it out:* what its open model needs on the visitor's own setup (the rules' `own`, the static items), else any GPU of its own.*/-export function presetOwnSetup(rules: PoolRules | undefined, p: { id: string; open: { modelId?: string } | null; cloud: unknown }, engine?: "open" | "cloud"): OwnSetup | null {+export function presetOwnSetup(rules: PoolRules | undefined, p: { id: string; open: unknown; cloud: unknown }, engine?: "open" | "cloud"): OwnSetup | null {if (presetOffered(rules, p, engine)) return null;- const model = p.open?.modelId;+ // A catalog preset names its open model; a gallery card only says it has an open route.+ const open = p.open && typeof p.open === "object" ? (p.open as { modelId?: unknown }) : null;+ const model = typeof open?.modelId === "string" ? open.modelId : undefined;return (model && (rules?.own?.[model] ?? ownSetupOnly(model, "open"))) || ANY_GPU;}diff --git a/src/lib/run-place.ts b/src/lib/run-place.tsindex e8e2d4b8..ad9675b4 100644--- a/src/lib/run-place.ts+++ b/src/lib/run-place.ts@@ -1,3 +1,4 @@+import { ownSetupDetail, ownSetupLabel, type OwnSetup } from "./own-setup";import { lineWords } from "./pool-line";import { billedTo, CLOUD_KEY, type CloudProvider } from "./your-keys";@@ -36,9 +37,10 @@ export interface RunPlaceInput {/*** The price of a run on this studio's GPUs (the billing service's words; empty text: free), undefined while pricing.* `refused`: the price check refused the run (its words are `text`), so it can't start now. `wait`: where it would- * stand in line, and the wait.+ * stand in line, and the wait. `setup`: refused because it runs on the visitor's own setup (own-setup.ts), which the+ * send button opens instead of staying off.*/- pool?: { text: string; sub?: string; refused?: boolean; wait?: string } | null;+ pool?: { text: string; sub?: string; refused?: boolean; wait?: string; setup?: OwnSetup } | null;/** The provider an account's paid run is billed to (its own key), or null when it has no key for this model. */payer?: CloudProvider | null;/** How a price reads: "$0.04". */@@ -64,6 +66,8 @@ export interface RunPlace {refused?: string;/** The cloud model the chip names, when known (the label is "Cloud" without one). */model?: string;+ /** It runs on the visitor's own setup (own-setup.ts): the send button opens that setup (`needs` says which). */+ setup?: OwnSetup;}const list = (names: readonly string[]) => (names.length < 2 ? (names[0] ?? "") : `${names.slice(0, -1).join(", ")} and ${names[names.length - 1]}`);@@ -111,6 +115,21 @@ export function runPlace(input: RunPlaceInput): RunPlace {// at the billing service's price (the studio composer's "This studio's GPUs" chip).if (open && input.hosted && audience !== "owner" && (!input.gpu || input.preferPool)) {const signup = audience === "guest";+ // Runs on the visitor's own GPU or key only: said in the setup's own words, and the send button opens that setup.+ const setup = !input.demo && input.pool?.refused ? input.pool.setup : undefined;+ if (setup) {+ const needs = signup ? "signup" : setup.need === "key" ? "key" : input.gpu ? undefined : "gpu";+ return {+ where: setup.need === "key" ? "cloud" : "gpu",+ label: setup.need === "key" ? "Your key" : "Your GPU",+ price: "",+ title: ownSetupLabel(setup),+ tip: `${ownSetupDetail(setup)}${signup ? " Create a free account to run it." : ""}`,+ send: ownSetupLabel(setup),+ ...(needs && { needs: needs as RunPlace["needs"] }),+ setup,+ };+ }const refused = !input.demo && input.pool?.refused ? input.pool.text : undefined;const poolPrice = input.demo ? price : input.pool ? input.pool.text || "Free" : "";const tip = input.demo@@ -228,12 +247,13 @@ export const IN_BROWSER: RunPlace = runPlace({ audience: "guest", engine: "brows* `count`: runs one press starts (the quote is for one, said "each").*/export function checkedPool(- check: { place?: "pool"; quote?: { text: string; sub?: string; allowed?: boolean }; line?: { place: number; etaSeconds: number | null } } | null | undefined,+ check: { place?: "pool"; quote?: { text: string; sub?: string; allowed?: boolean; ownSetup?: OwnSetup }; line?: { place: number; etaSeconds: number | null } } | null | undefined,count = 1,-): { text: string; sub?: string; refused?: boolean; wait?: string } | undefined {+): { text: string; sub?: string; refused?: boolean; wait?: string; setup?: OwnSetup } | undefined {if (check?.place !== "pool" || !check.quote) return undefined;- const { text, sub } = check.quote;- // Refused before Run (busy, a limit, not offered here): its words, never priced "each".- if (check.quote.allowed === false) return { text, ...(sub && { sub }), refused: true };+ const { text, sub, ownSetup } = check.quote;+ // Refused before Run (busy, a limit, not offered here): its words, never priced "each"; with the visitor's own setup+ // that runs it, when that is the answer.+ if (check.quote.allowed === false) return { text, ...(sub && { sub }), refused: true, ...(ownSetup && { setup: ownSetup }) };return { text: count > 1 && text ? `${text} each` : text, ...(sub && { sub }), ...(check.line && { wait: lineWords(check.line) }) };}diff --git a/tests/hosted-pickers.test.ts b/tests/hosted-pickers.test.tsindex 18383114..b097920c 100644--- a/tests/hosted-pickers.test.ts+++ b/tests/hosted-pickers.test.ts@@ -2,11 +2,12 @@ import { describe, expect, it } from "vitest";import { poolRulesOf, poolRunsModel, poolRunsPreset, presetOffered, tryFreeFor } from "@/lib/pool-rules";/*- * For a visitor with no GPU of its own (hosted runs), pickers leave out what this studio's GPUs keep off (the policy's- * model and app lists and its kinds), the same rules the server checks on every run; and "Try free" on preset cards.+ * For a visitor with no GPU of its own (hosted runs), pickers label what this studio's GPUs keep off (the policy's+ * model and app lists and its kinds) with the visitor's own setup, the same rules the server checks on every run; and+ * "Try free" on preset cards. (The labels themselves: tests/own-setup-labels.test.ts.)*/-describe("what pickers leave out for a visitor with no GPU of its own", () => {+describe("what pickers label for a visitor with no GPU of its own", () => {const open = (id: string, kind: "image" | "video" | "model3d" = "image") => ({ id, kind, engine: "open" });it("the policy's lists and kinds, made into rules only when they keep something off", () => {expect(poolRulesOf({ pool: {} })).toBeUndefined();@@ -75,7 +76,7 @@ describe("presets kept off with their model or the kind they make", () => {];const tryFree = (pool: Parameters<typeof poolRulesOf>[0]) => tryFreeFor({ hosted: true, cardText: "Try free", gpu: { connected: false }, pool: poolRulesOf(pool, presets) }, "both")!.runs;- it("a preset on a model the policy denies, or of a kind it keeps off, says no Try free and leaves the pickers", () => {+ it("a preset on a model the policy denies, or of a kind it keeps off, says no Try free and is labelled in the pickers", () => {const denied = tryFree({ pool: { deny: ["oss-face"] } });expect(denied({ id: "app-face", open: true })).toBe(false);expect(denied({ id: "app-portrait", open: true })).toBe(true);diff --git a/tests/own-setup-labels.test.ts b/tests/own-setup-labels.test.tsnew file mode 100644index 00000000..163987df--- /dev/null+++ b/tests/own-setup-labels.test.ts@@ -0,0 +1,185 @@+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";+import { createElement, type ReactNode } from "react";+import { renderToStaticMarkup } from "react-dom/server";+import { afterEach, describe, expect, it, vi } from "vitest";++/*+ * What this install's GPUs don't run for a visitor with no GPU of its own shows in the pickers and galleries with its+ * own-setup label, never left out: a model over the memory of those GPUs, one none of them holds, a preset on such a+ * model. Run on it opens that setup (Connect your GPU, Add your key, or a guest's sign-up) instead of staying off, and+ * "Try free" stays on the items these GPUs run. The words say what to use, never why.+ */++vi.mock("server-only", () => ({}));+vi.mock("next/navigation", () => ({+ useRouter: () => ({ prefetch: () => {}, push: () => {}, replace: () => {}, back: () => {}, refresh: () => {} }),+ usePathname: () => "/video",+ useSearchParams: () => new URLSearchParams(),+}));++const { getModel, PRESETS } = await import("@/lib/catalog");+const { OWN_SETUP_IDS, ownSetupDetail, ownSetupLabel, ownSetupOnly, ownSetupShort, ownSetupStep } = await import("@/lib/own-setup");+const { modelOwnSetup, poolRulesOf, presetOwnSetup, tryFreeFor } = await import("@/lib/pool-rules");+const { poolRunState } = await import("@/lib/hosted");+const { checkedPool, runPlace } = await import("@/lib/run-place");+const { poolOwnSetups, needsGpu } = await import("@/server/pool-own-setup");+const { gateText } = await import("@/server/hosted-run");+const { loadIndex } = await import("@/server/gpu/index-file");+const { openOwnSetupStep } = await import("@/components/own-setup");+const { ModelRow } = await import("@/components/studio/model-picker");+const { PresetCard } = await import("@/components/preset-gallery");+const { PresetGrid } = await import("@/components/studio/preset-chips");+const { TooltipProvider } = await import("@/components/ui/tooltip");++const render = (node: ReactNode) => renderToStaticMarkup(createElement(QueryClientProvider, { client: new QueryClient() }, createElement(TooltipProvider, null, node)));+const text = (html: string) => html.replace(/<[^>]+>/g, " ").replace(/\s+/g, " ");++/** Words a visitor never reads on a run that uses this install's GPUs: why it can't run there, or how they work. */+const REASON = /worker|comfy|lane|provider|pool|vram|queue|validat|tested|verified|held|owner|beta|experimental|soon|isn['’]t|can['’]t|cannot|not available|unavailable|not offered|refused|too small|missing|busy|paused/i;++const ACCOUNT = { kind: "account" as const, gpu: { connected: false }, keys: [] as string[] };+const H3 = getModel("oss-minimax-h3")!;+const REGEN = getModel("oss-h3-regenerate")!;+// An open model with presets of its own (camera motions and effects run on it).+const Z = getModel("oss-wan22-14b")!;+const zEndpoints = Z.routes.filter((r) => r.provider === "comfyui").map((r) => r.endpoint);+const rowHtml = (m: NonNullable<typeof Z>, setup: ReturnType<typeof modelOwnSetup>) =>+ render(createElement(ModelRow, { m, selected: false, starred: false, showEngine: false, today: null, onStar: () => {}, setup }));+const refusedCheck = (setup: NonNullable<ReturnType<typeof ownSetupOnly>>) => ({+ place: "pool" as const,+ quote: { allowed: false, amount: 0, priceVersion: "", text: ownSetupLabel(setup), code: "not-offered", ownSetup: setup },+});++const win = globalThis as { window?: unknown; CustomEvent?: unknown };+afterEach(() => {+ delete win.window;+});++describe("a model over the memory of this install's GPUs", () => {+ it("shows its label in the model picker, in place of its price", () => {+ // A static item: a card bigger than these GPUs'.+ const setup = modelOwnSetup(undefined, REGEN)!;+ expect(setup).toMatchObject({ need: "gpu", vramGb: 48 });+ const html = rowHtml(REGEN, setup);+ expect(html).toContain('data-slot="own-setup"');+ expect(html).toContain(ownSetupLabel(setup));+ expect(ownSetupLabel(setup)).toBe("Runs on your own GPU · 48 GB");+ // A model that runs here has no label.+ expect(rowHtml(H3, modelOwnSetup(undefined, H3))).not.toContain('data-slot="own-setup"');+ });++ it("a workflow too big for every card these GPUs have names the memory it needs", () => {+ const off = new Set(H3.routes.filter((r) => r.provider === "comfyui").map((r) => r.endpoint));+ const own = poolOwnSetups((e) => !off.has(e), () => false);+ const gbs = [...off].map((e) => loadIndex().workflows[e]?.vramGb).filter((n): n is number => typeof n === "number" && n > 0);+ expect(own[H3.id]).toEqual({ need: "gpu", ...(gbs.length && { vramGb: Math.ceil(Math.min(...gbs)) }) });+ const rules = poolRulesOf({}, [], own);+ const setup = modelOwnSetup(rules, H3)!;+ expect(text(rowHtml(H3, setup))).toContain(ownSetupLabel(setup));+ });++ it("Run opens the setup instead of staying off: Connect your GPU, a guest's sign-up, or the run itself", () => {+ const setup = ownSetupOnly(REGEN.id)!;+ const state = poolRunState(refusedCheck(setup))!;+ expect(state).toMatchObject({ refused: true, text: ownSetupLabel(setup), setup });+ expect(ownSetupStep(state.setup!, ACCOUNT)).toEqual({ kind: "connect-gpu", gpuOnly: true });+ expect(ownSetupStep(state.setup!, { kind: "guest" })).toEqual({ kind: "sign-up" });+ expect(ownSetupStep(state.setup!, { ...ACCOUNT, gpu: { connected: true } })).toEqual({ kind: "run" });+ // The step opens the card.+ const target = new EventTarget();+ const seen: { type: string; detail: unknown }[] = [];+ target.addEventListener("fuobe:connect-gpu", (e) => seen.push({ type: e.type, detail: (e as CustomEvent).detail }));+ win.window = target;+ expect(openOwnSetupStep(ownSetupStep(setup, ACCOUNT))).toBe(true);+ expect(seen).toEqual([{ type: "fuobe:connect-gpu", detail: { action: "run", gpuOnly: true, needs: "gpu" } }]);+ });++ it("an app's own tool says the label and sends Run to the setup, never a refusal", () => {+ const setup = ownSetupOnly(REGEN.id)!;+ const pool = checkedPool(refusedCheck(setup));+ expect(pool).toMatchObject({ refused: true, setup });+ const account = runPlace({ audience: "account", engine: "open", hosted: true, pool, format: String });+ expect(account).toMatchObject({ where: "gpu", title: ownSetupLabel(setup), send: ownSetupLabel(setup), needs: "gpu", setup });+ expect(account.refused).toBeUndefined();+ expect(runPlace({ audience: "guest", engine: "open", hosted: true, pool, format: String }).needs).toBe("signup");+ const key = { need: "key" as const, provider: "fal" };+ expect(runPlace({ audience: "account", engine: "open", hosted: true, pool: checkedPool(refusedCheck(key)), format: String })).toMatchObject({ needs: "key", send: "Use your own fal.ai key" });+ // Any other refusal still turns the button off with its words.+ const busy = checkedPool({ place: "pool", quote: { allowed: false, text: "Busy right now." } });+ expect(runPlace({ audience: "account", engine: "open", hosted: true, pool: busy, format: String }).refused).toBe("Busy right now.");+ });+});++describe("a model none of this install's GPUs holds", () => {+ const own = poolOwnSetups((e) => !zEndpoints.includes(e), () => false);+ const preset = PRESETS.find((p) => p.open?.modelId === Z.id);+ // A preset on a model these GPUs still run.+ const other = PRESETS.find((p) => p.open && getModel(p.open.modelId)?.kind === Z.kind && !own[p.open.modelId] && p.open.modelId !== Z.id);+ const rules = poolRulesOf({}, PRESETS.map((p) => ({ id: p.id, ...(p.open && getModel(p.open.modelId) && { model: { id: p.open.modelId, kind: getModel(p.open.modelId)!.kind } }) })), own);++ it("shows a label from the pool rules in the model picker", () => {+ expect(own[Z.id]).toEqual(needsGpu(zEndpoints[0]));+ const setup = modelOwnSetup(rules, Z)!;+ expect(setup).toEqual(own[Z.id]);+ expect(text(rowHtml(Z, setup))).toContain(ownSetupLabel(setup));+ });++ it("its presets show in the galleries and pickers with that label; Try free stays on the ones these GPUs run", () => {+ expect(preset && other).toBeTruthy();+ if (!preset || !other) return;+ // On the open engine (a preset with a cloud route keeps it on the cloud engine, as before).+ const setup = presetOwnSetup(rules, preset, "open")!;+ expect(setup).toEqual(own[Z.id]);+ expect(presetOwnSetup(rules, other, "open")).toBeNull();+ // A gallery card only knows the preset has an open route: a GPU of the visitor's own.+ const card = { id: preset.id, name: preset.name, description: preset.description, category: preset.category, icon: "Sparkles", hue: 200, cloud: false, open: true, preview: { kind: "none" } } as never;+ expect(presetOwnSetup(rules, card)).toEqual({ need: "gpu" });+ const html = render(createElement(PresetCard, { preset: card, href: "/x", setup: presetOwnSetup(rules, card) }));+ expect(text(html)).toContain(ownSetupLabel({ need: "gpu" }));+ expect(html).not.toContain("data-try-free");+ // The camera-motion and effect pickers list it, labelled, beside the ones that run here.+ const grid = render(createElement(PresetGrid, { list: [preset, other], noneLabel: "None", onPick: () => {}, rules, engine: "open" }));+ expect(text(grid)).toContain(preset.name);+ expect(text(grid)).toContain(other.name);+ expect(grid.match(/data-slot="own-setup"/g)).toHaveLength(1);+ // Try free: only on what these GPUs run.+ const tryFree = tryFreeFor({ hosted: true, cardText: "Try free", gpu: { connected: false }, pool: rules }, "both")!;+ expect(tryFree.runs({ id: preset.id, open: true })).toBe(false);+ expect(tryFree.runs({ id: other.id, open: true })).toBe(true);+ });++ it("with hosted runs off, or for a viewer with its own GPU, nothing is labelled by the rules", () => {+ expect(modelOwnSetup(undefined, Z)).toBeNull();+ expect(presetOwnSetup(undefined, preset!)).toBeNull();+ });+});++describe("the reason never appears in a visitor's words", () => {+ const setups = [+ ...OWN_SETUP_IDS.map((id) => ownSetupOnly(id) ?? null),+ { need: "gpu" as const },+ { need: "gpu" as const, vramGb: 12 },+ needsGpu(zEndpoints[0]),+ { need: "key" as const, provider: "fal" },+ { need: "key" as const, provider: "replicate" },+ ].filter((o): o is NonNullable<typeof o> => !!o);++ it("in the labels, the price check's words and the tools' place", () => {+ for (const o of setups) {+ const words = [ownSetupLabel(o), ownSetupShort(o), ownSetupDetail(o), gateText({ ok: false, reason: "ownSetup", setup: o }, true), gateText({ ok: false, reason: "ownSetup", setup: o }, false)];+ for (const audience of ["account", "guest"] as const) {+ const place = runPlace({ audience, engine: "open", hosted: true, pool: checkedPool(refusedCheck(o)), format: String });+ words.push(place.label, place.title, place.tip, place.send);+ }+ for (const w of words) expect(w, JSON.stringify(o)).not.toMatch(REASON);+ }+ });++ it("in the picker rows and cards that show them", () => {+ for (const o of setups) {+ expect(text(rowHtml(Z, o))).not.toMatch(REASON);+ const card = { id: "p", name: "Orbit", description: "A slow orbit", category: "Orbit", icon: "Sparkles", hue: 200, cloud: false, open: true, preview: { kind: "none" } } as never;+ expect(text(render(createElement(PresetCard, { preset: card, href: "/x", setup: o })))).not.toMatch(REASON);+ }+ });+});diff --git a/tests/pool-account-runs.test.ts b/tests/pool-account-runs.test.tsindex 4ede4058..67af47dd 100644--- a/tests/pool-account-runs.test.ts+++ b/tests/pool-account-runs.test.ts@@ -337,6 +337,26 @@ describe("an account's run on the workers", () => {expect((await run({ feature: "image", modelId: "oss-z-image-turbo", prompt: "a lighthouse" })).status).toBe(201);});+ it("a model whose files no worker has: the price check says its label, and the status labels it in the pickers", async () => {+ const { ownSetupLabel } = await import("@/lib/own-setup");+ const { modelOwnSetup } = await import("@/lib/pool-rules");+ const { visitorStatus } = await import("@/server/account-gpu");+ const w = standInWorker();+ const model = getModel("oss-z-image-turbo")!;+ const endpoints = new Set(model.routes.filter((x) => x.provider === "comfyui").map((x) => x.endpoint));+ const workflows = loadManifest().workflows.map((x) => x.id);+ db().prepare("UPDATE relay_workers SET lanes_json = ? WHERE id = ?").run(JSON.stringify({ lanes: [], workflows: workflows.filter((x) => !endpoints.has(x)) }), w.id);+ const r = await generationsRoute.POST(request("/api/generations?preview=1", { body: { feature: "image", modelId: model.id, prompt: "a lighthouse" } }));+ const quote = ((await r.json()) as { quote?: { allowed: boolean; text: string; ownSetup?: { need: "gpu"; vramGb?: number } } }).quote;+ expect(quote).toMatchObject({ allowed: false, ownSetup: { need: "gpu" } });+ expect(quote?.text).toBe(ownSetupLabel(quote!.ownSetup!));+ const pool = (await visitorStatus(auth.accountById(accountId)!)).viewer.pool;+ expect(pool?.own?.[model.id]).toEqual(quote?.ownSetup);+ expect(modelOwnSetup(pool, model)).toEqual(quote?.ownSetup);+ // A model the workers hold has no label.+ expect(pool?.own?.["oss-wan22-14b"]).toBeUndefined();+ });+it("a file input in params.extra is one the run sent, never a name in the workers' folders", async () => {standInWorker();const uploadsRoute = await import("@/app/api/uploads/route");