Skip to content

armgit / fuobe

Public Imported from GitHub
0

The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.

Hosted runs: what this install's GPUs can't run is refused with the own setup that runs it

Adarsh975b24838063
diff --git a/src/lib/hosted.ts b/src/lib/hosted.ts
index bdf52b29..a8cc1e6a 100644
--- a/src/lib/hosted.ts
+++ b/src/lib/hosted.ts
@@ -5,6 +5,7 @@ import { useMutation, useQuery, type QueryClient } from "@tanstack/react-query";
import { toast } from "sonner";
import type { GenerationRequest } from "./catalog/types";
import { lineWords } from "./pool-line";
+import type { OwnSetup } from "./own-setup";
/**
* The browser's side of hosted runs and the optional billing service (src/server/hosted.ts, src/server/billing.ts).
@@ -33,6 +34,11 @@ export interface HostedQuote {
etaS?: number | null;
action?: BillingAction;
offer?: BillingOffer;
+ /**
+ * Refused because it runs on the visitor's own setup (src/lib/own-setup.ts): what that setup is. Run opens it (Connect
+ * your GPU, Add your key, or a guest's sign-up) instead of staying off.
+ */
+ ownSetup?: OwnSetup;
}
/** The billing service's words for an account's balance (the top bar's chip and the account menu). */
@@ -150,14 +156,17 @@ export function refreshPriceChecks(qc: QueryClient): void {
* What Run says and does for a run on this studio's GPUs, from its price check:
* - `refused`: the run wouldn't be taken now (busy, a limit, not offered here, closed, paused, a top-up): Run is off,
* and the price slot says the service's words (`text`), with its line under them (`sub`) and its link or offer;
+ * `setup`: it runs on the visitor's own setup, whose label is `text`, and Run opens that setup instead of staying off;
* - otherwise the price (`text`: the service's words, empty when there is none) and, under it, where the run would stand
* in line and the wait (`wait`).
* Null while there is no answer yet.
*/
-export function poolRunState(check: HostedCheck | null | undefined): { refused: boolean; text: string; sub?: string; wait?: string; action?: BillingAction; offer?: BillingOffer } | null {
+export function poolRunState(
+ check: HostedCheck | null | undefined,
+): { refused: boolean; text: string; sub?: string; wait?: string; action?: BillingAction; offer?: BillingOffer; setup?: OwnSetup } | null {
const q = check?.quote;
if (!q) return null;
- if (!q.allowed) return { refused: true, text: q.text, ...(q.sub && { sub: q.sub }), ...(q.action && { action: q.action }), ...(q.offer && { offer: q.offer }) };
+ if (!q.allowed) return { refused: true, text: q.text, ...(q.sub && { sub: q.sub }), ...(q.action && { action: q.action }), ...(q.offer && { offer: q.offer }), ...(q.ownSetup && { setup: q.ownSetup }) };
return { refused: false, text: q.text, ...(q.sub && { sub: q.sub }), ...(check?.line && { wait: lineWords(check.line) }) };
}
diff --git a/src/lib/pool-rules.ts b/src/lib/pool-rules.ts
index 7f09ed5a..c7e17bb7 100644
--- a/src/lib/pool-rules.ts
+++ b/src/lib/pool-rules.ts
@@ -1,20 +1,26 @@
import type { MediaKind } from "./catalog/types";
+import { ownSetupOnly, type OwnSetup } from "./own-setup";
/**
* What this studio's GPUs run for a visitor with no GPU of its own (hosted runs): the policy's model and app lists and
- * its kinds, as GET /api/status sends them (`viewer.pool`). Pickers leave out what these rules keep off, so a run never
- * fails at Run for it. The server checks the same rules on every run (src/server/hosted.ts poolAllows).
+ * its kinds, and the open models they can't run right now, as GET /api/status sends them (`viewer.pool`). Pickers show
+ * what these rules keep off with its "own setup" label (src/lib/own-setup.ts), and pressing Run on it opens that setup,
+ * so a run never fails at Run for it. The server checks the same rules on every run (src/server/hosted.ts poolAllows,
+ * src/server/hosted-run.ts poolGate).
*
* - `allow`: only these models (absent: every model); `deny`: never these.
* - `apps`: the same for apps, camera motions and effects (by preset id). A preset whose open model (or the kind it
* makes) the rules keep off is kept off here too, so its card never says "Try free" for a run that would be refused.
* - `kinds`: a kind set to false runs on the visitor's own GPU only (absent: every kind).
+ * - `own`: open models this studio's GPUs can't run right now (none of them holds the model, serves its kind of work,
+ * or has the card it needs), each with what the visitor needs to run it on its own setup.
*/
export interface PoolRules {
allow?: string[];
deny?: string[];
apps?: { allow?: string[]; deny?: string[] };
kinds?: Partial<Record<MediaKind, boolean>>;
+ own?: Record<string, OwnSetup>;
}
/** A preset as the rules see it: its id, and the open model it runs on with the kind it makes (none: no open route). */
@@ -26,11 +32,13 @@ export interface PresetModel {
/**
* The rules a policy's pool lists and kinds make, or undefined when they keep nothing off. `presets`: the catalog's
* presets with their open models, so a preset is kept off with its model (by id, in the app lists: the shorter of the
- * two lists when the policy has no app allow list of its own).
+ * two lists when the policy has no app allow list of its own), and with a model that runs on a visitor's own setup only.
+ * `own`: the open models this studio's GPUs can't run right now (src/server/pool-own-setup.ts poolOwnSetups).
*/
export function poolRulesOf(
p: { pool?: { allow?: string[]; deny?: string[]; apps?: { allow?: string[]; deny?: string[] } }; kinds?: Partial<Record<MediaKind, boolean>> },
presets: readonly PresetModel[] = [],
+ own: Record<string, OwnSetup> = {},
): PoolRules | undefined {
const list = (xs: unknown) => (Array.isArray(xs) ? xs.filter((x): x is string => typeof x === "string") : undefined);
const lists = p.pool ?? {};
@@ -41,9 +49,10 @@ export function poolRulesOf(
if (deny?.length) out.deny = deny;
const off = Object.entries(p.kinds ?? {}).filter(([, v]) => v === false);
if (off.length) out.kinds = Object.fromEntries(off) as PoolRules["kinds"];
+ if (Object.keys(own).length) out.own = own;
let appsAllow = list(lists.apps?.allow);
let appsDeny = list(lists.apps?.deny);
- const modelOff = new Set(presets.filter((x) => x.model && !poolRunsModel(out, { ...x.model, engine: "open" })).map((x) => x.id));
+ const modelOff = new Set(presets.filter((x) => x.model && (!poolRunsModel(out, { ...x.model, engine: "open" }) || ownSetupOnly(x.model.id, "open"))).map((x) => x.id));
if (modelOff.size) {
if (appsAllow) appsAllow = appsAllow.filter((id) => !modelOff.has(id));
// Most presets kept off: the presets still on make the shorter list.
@@ -59,9 +68,30 @@ export function poolRunsModel(rules: PoolRules | undefined, m: { id: string; kin
if (!rules || m.engine !== "open") return true;
if (rules.deny?.includes(m.id)) return false;
if (rules.allow && !rules.allow.includes(m.id)) return false;
+ if (rules.own?.[m.id]) return false;
return rules.kinds?.[m.kind] !== false;
}
+/** What any GPU of the visitor's own runs (no memory or files named). */
+const ANY_GPU: OwnSetup = { need: "gpu" };
+
+/**
+ * The label a picker shows on an open model these rules keep off (null: they run it, or have no say): what a visitor
+ * needs to run it on its own setup. Shown, never left out: pressing Run on it opens that setup.
+ */
+export function poolOwnSetup(rules: PoolRules | undefined, m: { id: string; kind: MediaKind; engine: string }): OwnSetup | null {
+ if (!rules || m.engine !== "open") return null;
+ return rules.own?.[m.id] ?? (poolRunsModel(rules, m) ? null : ANY_GPU);
+}
+
+/**
+ * A model's label in a picker for a visitor: the static items (ownSetupOnly), then what the rules keep off. Null for the
+ * models that run as any other.
+ */
+export function modelOwnSetup(rules: PoolRules | undefined, m: { id: string; kind: MediaKind; engine: string }): OwnSetup | null {
+ return ownSetupOnly(m.id, m.engine === "cloud" ? "cloud" : "open") ?? poolOwnSetup(rules, m);
+}
+
/** Does this studio's GPUs run this app, camera motion or effect under the rules (no rules: yes)? */
export function poolRunsPreset(rules: PoolRules | undefined, presetId: string): boolean {
const apps = rules?.apps;
@@ -81,6 +111,16 @@ export function presetOffered(rules: PoolRules | undefined, p: { id: string; ope
return poolRunsPreset(rules, p.id);
}
+/**
+ * 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 {
+ if (presetOffered(rules, p, engine)) return null;
+ const model = p.open?.modelId;
+ return (model && (rules?.own?.[model] ?? ownSetupOnly(model, "open"))) || ANY_GPU;
+}
+
/**
* The words on preset cards ("Try free"): with hosted runs on, a card whose preset runs on this studio's GPUs for this
* viewer (a guest, an account with no GPU of its own, or one whose runs go to this studio's GPUs first) says the words
diff --git a/src/server/account-gpu.ts b/src/server/account-gpu.ts
index d450daf2..990201a8 100644
--- a/src/server/account-gpu.ts
+++ b/src/server/account-gpu.ts
@@ -7,14 +7,14 @@ import { accountGpu, type Account, type AccountGpu } from "./auth";
import type { OwnerGpuView } from "@/lib/connections";
import { runnerFacts, type Principal } from "./computer/tasks";
import { offeredSummary } from "./model-access";
-import { getModel, MODELS, PRESETS } from "@/lib/catalog";
+import { getModel, PRESETS } from "@/lib/catalog";
import { operationOutput } from "@/lib/catalog/types";
-import { hostedUntestedSummary } from "@/lib/catalog/hosted-untested";
import { PROVIDERS } from "./providers";
import { blockedForAccounts, fetchPublic, isLoopbackGpu } from "./remote-fetch";
import { isInstallHost, REFUSED_ADDRESS } from "./gpu/hosts";
import { balance as billingBalance, policy as billingPolicy, type Action, type Balance } from "./billing";
import { poolReady } from "./hosted";
+import { poolOwnModels } from "./pool-own-setup";
import { poolRulesOf, type PoolRules, type PresetModel } from "@/lib/pool-rules";
/**
@@ -243,7 +243,9 @@ export async function visitorStatus(account: Account | null) {
if (p?.hosted && p.prefer === "pool") viewer.prefer = "pool";
const card = p?.hosted && typeof p.cardText === "string" ? p.cardText.trim().slice(0, 40) : "";
if (card) viewer.cardText = card;
- const rules = p?.hosted && !gpu ? poolRulesOf(p, presetModels()) : undefined;
+ // What this studio's GPUs keep off, the open models they can't run right now among it: shown in the pickers with
+ // what the visitor needs to run them on its own setup.
+ const rules = p?.hosted && !gpu ? poolRulesOf(p, presetModels(), poolOwnModels()) : undefined;
if (rules) viewer.pool = rules;
if (account && p?.links?.length) viewer.links = p.links;
if (account && p?.notice) viewer.notice = p.notice;
@@ -251,8 +253,9 @@ export async function visitorStatus(account: Account | null) {
if (b) viewer.balance = b;
}
const configured = (id: string) => (id === "comfyui" ? (gpu ? !!live?.online : true) : isCloudProvider(id) && keys.includes(id));
- // With keys: the hosted routes no live call has passed yet are left out too (they run for the owner only).
- const access = keys.length ? hostedUntestedSummary(MODELS, offeredSummary()) : undefined;
+ // With keys: the paid models the owner switched off (a cloud route no live call has passed yet runs on the visitor's
+ // own key, labelled so: src/lib/own-setup.ts).
+ const access = keys.length ? offeredSummary() : undefined;
return {
providers: Object.fromEntries(Object.values(PROVIDERS).map((p) => [p.id, { label: p.id === "comfyui" ? "Your GPU" : p.label, configured: configured(p.id) }])),
demoMode: "off",
diff --git a/src/server/hosted-run.ts b/src/server/hosted-run.ts
index 34ea1f05..30045244 100644
--- a/src/server/hosted-run.ts
+++ b/src/server/hosted-run.ts
@@ -2,9 +2,8 @@ import "server-only";
import crypto from "node:crypto";
import { nanoid } from "nanoid";
import type { GenerationRequest } from "@/lib/catalog/types";
-import { OWN_GPU_TOOL_MESSAGE } from "@/lib/guest-access";
-import { RTX_CLASSES, rtxCardOf } from "@/lib/catalog/rtx-video";
-import { gpuFits } from "@/lib/gpu/readiness";
+import { CONNECT_GPU_HEADER, OWN_GPU_TOOL_MESSAGE } from "@/lib/guest-access";
+import { ownSetupLabel, ownSetupOnly, type OwnSetup } from "@/lib/own-setup";
import { gpuState } from "./account-gpu";
import { accountGpu, type Account } from "./auth";
import {
@@ -35,10 +34,13 @@ import { hostedRunsOn } from "./hosted-switch";
import { checkRun, moderationConfigured } from "./moderation";
import type { RunStamp } from "./run-stamp";
import { readRef } from "./storage";
-import { readSnapshot } from "./gpu/snapshots";
import { ACCOUNT_LIMITS } from "./account-files";
import { poolLimitRefusal } from "./pool-limits";
import { runAsTenant } from "./tenant";
+import { needsGpu, poolCardRefuses, requestOwnSetup } from "./pool-own-setup";
+import { ADD_KEY_HEADER } from "@/lib/your-keys";
+
+export { poolCardRefuses };
/**
* The generations route's side of hosted runs (hosted.ts), the billing hook (billing.ts) and the moderation hook
@@ -108,6 +110,29 @@ export const OWN_GPU_QUIET = "Your GPU isn't answering right now. Run this on th
/** A run this install's GPUs won't take, refused in the words the price check before Run gives too. */
const notOffered = (error: string): { kind: "refuse"; refusal: Refusal } => ({ kind: "refuse", refusal: { status: 403, body: { error, code: "not-offered" }, headers: { [BILLING_HEADER]: "not-offered" } } });
+/**
+ * A run that runs on the visitor's own setup only (own-setup.ts): refused in its label's words, with the setup itself so
+ * the client opens it (Connect your GPU, or Add your key) instead of saying no.
+ */
+const ownSetupRefusal = (setup: OwnSetup): { kind: "refuse"; refusal: Refusal } => ({
+ kind: "refuse",
+ refusal: {
+ status: 403,
+ body: { error: ownSetupLabel(setup), code: setup.need === "key" ? "add-key" : "connect-gpu", ownSetup: setup, ...(setup.need === "key" && { provider: setup.provider }) },
+ headers: setup.need === "key" ? { [ADD_KEY_HEADER]: setup.provider } : { [CONNECT_GPU_HEADER]: "1" },
+ },
+});
+
+/** A gate's refusal as the run's answer: its words, with the own setup that would run it. */
+function gateRefusal(gate: GateRefusal): { kind: "refuse"; refusal: Refusal } {
+ if (gate.reason === "ownSetup") return ownSetupRefusal(gate.setup ?? needsGpu());
+ const error = gateWords(gate.reason, false);
+ if (gate.reason === "model3d") return { kind: "refuse", refusal: { status: 403, body: { error, code: "own-gpu-tool" }, headers: {} } };
+ const r = notOffered(error);
+ if (gate.setup) r.refusal.body.ownSetup = gate.setup;
+ return r;
+}
+
const askPlace = (): Refusal => ({ status: 409, body: { error: OWN_GPU_QUIET, code: "own-gpu-offline" }, headers: { [PLACE_ASK_HEADER]: "1" } });
/** Does the policy put runs on this install's GPUs first, before the account's own GPU? */
@@ -165,6 +190,8 @@ export function poolSteps(accountId: string, req: GenerationRequest): PlannedSte
*/
export function stepsProblem(p: Policy, steps: PlannedStep[]): string | null {
for (const s of steps) {
+ const own = s.provider === "comfyui" ? ownSetupOnly(s.modelId, "open") : null;
+ if (own) return ownSetupLabel(own);
if (!poolRunsProvider(s.provider)) return HOSTED_WORDS.notOffered;
if (s.provider === "comfyui" && poolCardRefuses(s.modelId)) return HOSTED_WORDS.rtxCard;
if (freeStep(s)) {
@@ -204,16 +231,26 @@ export function pricedSteps(steps: PlannedStep[]): NonNullable<RunFacts["steps"]
/**
* Why this install's GPUs won't take a run: a 3D model, a model or kind not offered there, a model their card can't run,
- * LoRAs, or a kind of file.
+ * LoRAs, a kind of file, or one that runs on the visitor's own setup only (`ownSetup`: a static item of own-setup.ts, or
+ * a workflow none of this install's GPUs can run right now: none holds its files, serves its lane, or has the memory).
+ */
+export type GateReason = "model3d" | "notOffered" | "rtxCard" | "loras" | "inputs" | "ownSetup";
+
+/**
+ * A gate's refusal: its reason, and the visitor's own setup that would run it (`setup`: always with "ownSetup"; with the
+ * others, a GPU of its own, which runs what this install's GPUs don't take).
*/
-export type GateReason = "model3d" | "notOffered" | "rtxCard" | "loras" | "inputs";
+export type GateRefusal = { ok: false; reason: GateReason; setup?: OwnSetup };
/** The words for a gate's reason: an account may connect its own GPU in Settings, a guest has nowhere to do that yet. */
-export function gateWords(reason: GateReason, guest: boolean): string {
+export function gateWords(reason: Exclude<GateReason, "ownSetup">, guest: boolean): string {
if (reason === "model3d") return OWN_GPU_TOOL_MESSAGE;
return (guest ? HOSTED_GUEST_WORDS : HOSTED_WORDS)[reason];
}
+/** A gate's refusal in words: the own setup's label (the same for a guest and an account), or the reason's words. */
+export const gateText = (gate: GateRefusal, guest: boolean): string => (gate.reason === "ownSetup" ? ownSetupLabel(gate.setup ?? needsGpu()) : gateWords(gate.reason, guest));
+
/**
* The one check of whether this install's GPUs take a run, shared by the run itself (decidePlace) and the price check
* before Run (poolQuote), so the two always agree: its output kind (no 3D there), the policy's model, app and kind
@@ -221,29 +258,40 @@ export function gateWords(reason: GateReason, guest: boolean): string {
* allowed its lane, a card that can run it, LoRAs, the kinds of file it sends, and every later step of a chain (planned
* only once the cheaper checks pass). `p` null: the billing service didn't answer, so only what needs no policy is
* checked. Passed, it gives the planned steps for the run's one price.
+ *
+ * First of all, every step's own setup (own-setup.ts): a model, mode or option that runs on a visitor's own GPU or key
+ * only is refused as "ownSetup" with that setup, on the run's own step and on every later step of a chain alike.
*/
export function poolGate(
p: Policy | null,
planned: Planned,
req: GenerationRequest,
planSteps: () => PlannedStep[] | null,
-): { ok: true; steps: PlannedStep[] | null } | { ok: false; reason: GateReason } {
+): { ok: true; steps: PlannedStep[] | null } | GateRefusal {
+ const own = requestOwnSetup({ ...req, modelId: planned.model.id, engine: "open" });
+ if (own) return { ok: false, reason: "ownSetup", setup: own };
+ const gpu = needsGpu(planned.route.endpoint);
const kind = outputKind(planned.op, planned.model);
if (kind === "model3d") return { ok: false, reason: "model3d" };
- if (p && (!poolAllowsRun(p, planned, req.presetId) || !kindAllowed(p, kind))) return { ok: false, reason: "notOffered" };
- // Nothing of this install's would ever run it (no worker is allowed its lane): never a run that waits for nothing.
- if (!poolTakes(planned.route.endpoint)) return { ok: false, reason: "notOffered" };
- if (poolCardRefuses(planned.model.id)) return { ok: false, reason: "rtxCard" };
- if (req.loras?.length) return { ok: false, reason: "loras" };
+ if (p && (!poolAllowsRun(p, planned, req.presetId) || !kindAllowed(p, kind))) return { ok: false, reason: "notOffered", setup: gpu };
+ // Nothing of this install's runs it right now (no worker holds its files, is allowed its lane, or has the memory it
+ // needs): a run that would wait for nothing, so it runs on the visitor's own GPU instead.
+ if (!poolTakes(planned.route.endpoint)) return { ok: false, reason: "ownSetup", setup: gpu };
+ if (poolCardRefuses(planned.model.id)) return { ok: false, reason: "rtxCard", setup: gpu };
+ if (req.loras?.length) return { ok: false, reason: "loras", setup: gpu };
if (p) {
const inputs = inputCounts(req);
const takes = poolUploads(p);
- if ((inputs.image && !takes.image) || (inputs.video && !takes.video) || (inputs.audio && !takes.audio)) return { ok: false, reason: "inputs" };
+ if ((inputs.image && !takes.image) || (inputs.video && !takes.video) || (inputs.audio && !takes.audio)) return { ok: false, reason: "inputs", setup: gpu };
}
// Every step of a chain, not only its first: each one the policy must allow, and the run is priced for all of them.
const steps = planSteps();
+ for (const s of steps ?? []) {
+ const later = s.provider === "comfyui" ? ownSetupOnly(s.modelId, "open") : null;
+ if (later) return { ok: false, reason: "ownSetup", setup: later };
+ }
const problem = steps && p ? stepsProblem(p, steps) : null;
- if (problem) return { ok: false, reason: problem === HOSTED_WORDS.rtxCard ? "rtxCard" : "notOffered" };
+ if (problem) return { ok: false, reason: problem === HOSTED_WORDS.rtxCard ? "rtxCard" : "notOffered", setup: gpu };
return { ok: true, steps };
}
@@ -278,22 +326,6 @@ export function poolRequest(req: GenerationRequest, p: Pick<Policy, "limits"> |
return { req: { ...req, params: { ...req.params, numOutputs: cap } }, capped: true };
}
-/**
- * A model that needs an NVIDIA RTX card (src/lib/catalog/rtx-video.ts) on this install's GPUs: refused when the install's
- * last GPU check says its card can't run it (a CPU, an Apple, AMD or Intel device, an older NVIDIA card) or its ComfyUI
- * lacks the RTX Video nodes. A card the name doesn't tell, or no check yet, never refuses (the run says what it finds).
- * On the workers that check is of another machine, so it isn't made: a worker takes a job only when it has the job's
- * node packs and files.
- */
-export function poolCardRefuses(modelId: string): boolean {
- if (poolOnWorkers()) return false;
- const need = rtxCardOf(modelId);
- if (!need) return false;
- const inv = readSnapshot({ kind: "install", key: "install", via: "server" })?.inventory;
- if (!inv?.reachable) return false;
- return gpuFits(need, inv) === false || RTX_CLASSES.some((c) => inv.nodes.missing.includes(c));
-}
-
/**
* Where an account's run goes (hosted.ts has the order). Only with hosted runs on; otherwise always "own" (today).
*
@@ -345,8 +377,7 @@ export async function decidePlace(account: Account, asked: GenerationRequest, wi
const gate = poolGate(p, planned, req, () => stepsFor(account, req));
if (!gate.ok) {
if (ownFallback) return OWN;
- const error = gateWords(gate.reason, false);
- return gate.reason === "model3d" ? { kind: "refuse", refusal: { status: 403, body: { error, code: "own-gpu-tool" }, headers: {} } } : notOffered(error);
+ return gateRefusal(gate);
}
// Its own GPU didn't answer the check: asked, never moved to this install's GPUs (and charged) without a word.
if (ownOffline) return { kind: "refuse", refusal: askPlace() };
@@ -467,7 +498,14 @@ export interface PoolLine {
}
/** A price check's answer for a run this install's GPUs won't take, in the words the run itself would get. */
-const notOfferedQuote = (text: string): Quote => ({ allowed: false, amount: 0, priceVersion: "", text, code: "not-offered" });
+/**
+ * A price check refused for what this install's GPUs don't take: its words, and (`ownSetup`) the visitor's own setup
+ * that runs it, so Run opens that setup (Connect your GPU, Add your key, or a guest's sign-up) instead of staying off.
+ */
+const notOfferedQuote = (text: string, setup?: OwnSetup): Quote & { ownSetup?: OwnSetup } => ({ allowed: false, amount: 0, priceVersion: "", text, code: "not-offered", ...(setup && { ownSetup: setup }) });
+
+/** A gate's refusal as the price check's quote (gateText: the label's words for an own setup). */
+const gateQuote = (gate: GateRefusal, guest: boolean) => notOfferedQuote(gateText(gate, guest), gate.reason === "model3d" ? undefined : gate.setup);
/**
* A price check on this install's GPUs (hosted runs on): the plan there, the billing service's quote (no service: free,
@@ -508,7 +546,7 @@ export async function poolQuote(
const gate = poolGate(p, planned, req, () => stepsFor(account, req));
if (!gate.ok) {
if (hasGpu && wish !== "pool") return null;
- return { planned, quote: notOfferedQuote(gateWords(gate.reason, !account)), line: line(queueFacts(account?.id ?? null, planned.route.endpoint)) };
+ return { planned, quote: gateQuote(gate, !account), line: line(queueFacts(account?.id ?? null, planned.route.endpoint)) };
}
// Light work only (joins, trims): free, and never counted against the policy's limits, so the service isn't asked.
if (lightRun(gate.steps)) {
@@ -574,7 +612,7 @@ export function toolGate(
p: Policy | null,
viewer: string | null,
steps: ToolRunStep[],
-): "unplanned" | { ok: false; reason: GateReason } | { ok: true; main: ToolPoolRun["main"]; rows: PlannedStep[] } {
+): "unplanned" | GateRefusal | { ok: true; main: ToolPoolRun["main"]; rows: PlannedStep[] } {
let main: ToolPoolRun["main"] | null = null;
const rows: PlannedStep[] = [];
for (const step of steps) {
@@ -593,7 +631,7 @@ export function toolGate(
if (planned.route.provider !== "comfyui") return "unplanned";
const gate = poolGate(p, planned, req, () => (deps ? [asPlannedStep(req, planned, true)] : poolSteps(viewer ?? GUEST_PLAN, req)));
// A tool adds its LoRAs itself (a person adds none to it): said as a step that runs on an own GPU, not as extra LoRAs.
- if (!gate.ok) return gate.reason === "loras" ? { ok: false, reason: "notOffered" } : gate;
+ if (!gate.ok) return gate.reason === "loras" ? { ok: false, reason: "notOffered", setup: gate.setup } : gate;
rows.push(...(gate.steps ?? [asPlannedStep(req, planned, deps > 0)]));
main ??= { req, planned };
}
@@ -625,8 +663,7 @@ export async function decideToolPlace(account: Account, steps: ToolRunStep[], wi
if (gate === "unplanned") return OWN;
if (!gate.ok) {
if (ownFallback) return OWN;
- const error = gateWords(gate.reason, false);
- return gate.reason === "model3d" ? { kind: "refuse", refusal: { status: 403, body: { error, code: "own-gpu-tool" }, headers: {} } } : notOffered(error);
+ return gateRefusal(gate);
}
if (ownOffline) return { kind: "refuse", refusal: askPlace() };
return { kind: "pool", policy: p, main: gate.main, steps: pricedSteps(gate.rows), light: lightRun(gate.rows) };
@@ -656,7 +693,7 @@ export async function toolPoolQuote(
};
if (!gate.ok) {
if (hasGpu && wish !== "pool") return null;
- return { quote: notOfferedQuote(gateWords(gate.reason, !account)), line: lineOf(undefined) };
+ return { quote: gateQuote(gate, !account), line: lineOf(undefined) };
}
const endpoint = gate.main.planned.route.endpoint;
if (lightRun(gate.rows)) return { quote: FREE_QUOTE, line: lineOf(endpoint) };
diff --git a/src/server/pool-own-setup.ts b/src/server/pool-own-setup.ts
new file mode 100644
index 00000000..bf63f8b1
--- /dev/null
+++ b/src/server/pool-own-setup.ts
@@ -0,0 +1,107 @@
+import "server-only";
+import type { GenerationRequest, ModelDef } from "@/lib/catalog/types";
+import { MODELS } from "@/lib/catalog/models";
+import { directRunFeatures } from "@/lib/catalog/genjutsu";
+import { ENHANCE_FEATURES, REGEN_MODEL, wantsH3TwoK } from "@/lib/catalog/regenerate";
+import { wantsVoiceFirst } from "@/lib/av/voice-first";
+import { ownSetupOnly, type OwnSetup } from "@/lib/own-setup";
+import { RTX_CLASSES, rtxCardOf } from "@/lib/catalog/rtx-video";
+import { gpuFits } from "@/lib/gpu/readiness";
+import { loadIndex } from "./gpu/index-file";
+import { readSnapshot } from "./gpu/snapshots";
+import { poolOnWorkers, poolTakes } from "./hosted";
+
+/**
+ * What a run on this install's GPUs needs instead, in the "own setup" shape (src/lib/own-setup.ts): the visitor's own GPU
+ * or key. Two sources, one shape:
+ * - the static items (ownSetupOnly): a model, or a mode or option of it with an id of its own (MiniMax H3 at 2K,
+ * Kandinsky 6.0 Pro, Regenerate, Genjutsu's makers, "Clean the voice first");
+ * - what this install's GPUs can't run right now (a model none of them holds, a lane none serves, a card too small or
+ * of the wrong kind): `needsGpu`, with the memory its workflow needs when the index says.
+ * The pool gate (hosted-run.ts poolGate) refuses with it, the price check says its label, and GET /api/status sends the
+ * dynamic ones to the pickers (pool-rules.ts `own`), which show them labelled instead of leaving them out.
+ */
+
+/** The ids a request's own setup is asked by: its model, then the modes and options of it that have their own. */
+export function requestSetupIds(req: Pick<GenerationRequest, "modelId" | "op" | "feature" | "params">): string[] {
+ const ids = [req.modelId];
+ const extra = req.params?.extra ?? {};
+ if (wantsH3TwoK(req.modelId, req.params?.resolution)) ids.push("regenerate:h3-2k");
+ if (req.modelId === REGEN_MODEL && req.feature && ENHANCE_FEATURES.has(req.feature)) ids.push("regenerate:enhance");
+ if (req.modelId === "oss-kandinsky6" && extra.quality === "pro") ids.push("oss-kandinsky6:pro");
+ if (wantsVoiceFirst(req)) ids.push("sound:clean-voice-first");
+ const genjutsu = extra.openjutsu;
+ const features = directRunFeatures(req.modelId, genjutsu && typeof genjutsu === "object" ? (genjutsu as Record<string, unknown>) : {});
+ for (const f of features ?? []) ids.push(`genjutsu:${f}`);
+ return ids;
+}
+
+/** The first static item a request asks for that runs on a visitor's own setup only, or null. */
+export function requestOwnSetup(req: Pick<GenerationRequest, "modelId" | "op" | "feature" | "params" | "engine">): OwnSetup | null {
+ for (const id of requestSetupIds(req)) {
+ const o = ownSetupOnly(id, req.engine);
+ if (o) return o;
+ }
+ return null;
+}
+
+/** The memory (GB, whole) a workflow's index entry says it needs, or none. */
+function workflowGb(endpoint: string | undefined): number | undefined {
+ const gb = endpoint ? loadIndex().workflows[endpoint]?.vramGb : undefined;
+ return typeof gb === "number" && gb > 0 ? Math.ceil(gb) : undefined;
+}
+
+/** A GPU of the visitor's own, with the memory the workflow needs when the index says. */
+export function needsGpu(endpoint?: string): OwnSetup {
+ const vramGb = workflowGb(endpoint);
+ return { need: "gpu", ...(vramGb && { vramGb }) };
+}
+
+/** A model's workflows on this install's GPUs (its ComfyUI routes). */
+const comfyEndpoints = (m: ModelDef): string[] => [...new Set(m.routes.filter((r) => r.provider === "comfyui").map((r) => r.endpoint))];
+
+/**
+ * The open models this install's GPUs can't run right now, with what a visitor needs to run each on its own setup: every
+ * ComfyUI workflow of the model refused by `takes` (no worker allowed its lane, holding its files, with the memory it
+ * needs), or by `cardRefuses` (a card that can't run it). The smallest memory among its workflows is the one named.
+ */
+export function poolOwnSetups(takes: (endpoint: string) => boolean, cardRefuses: (modelId: string) => boolean): Record<string, OwnSetup> {
+ const out: Record<string, OwnSetup> = {};
+ const known = new Map<string, boolean>();
+ const taken = (e: string) => {
+ let v = known.get(e);
+ if (v === undefined) known.set(e, (v = takes(e)));
+ return v;
+ };
+ for (const m of MODELS) {
+ const endpoints = comfyEndpoints(m);
+ if (!endpoints.length) continue;
+ if (cardRefuses(m.id)) {
+ out[m.id] = { need: "gpu" };
+ continue;
+ }
+ if (endpoints.some(taken)) continue;
+ const gbs = endpoints.map(workflowGb).filter((n): n is number => n !== undefined);
+ out[m.id] = { need: "gpu", ...(gbs.length && { vramGb: Math.min(...gbs) }) };
+ }
+ return out;
+}
+
+/**
+ * A model that needs an NVIDIA RTX card (src/lib/catalog/rtx-video.ts) on this install's GPUs: refused when the install's
+ * last GPU check says its card can't run it (a CPU, an Apple, AMD or Intel device, an older NVIDIA card) or its ComfyUI
+ * lacks the RTX Video nodes. A card the name doesn't tell, or no check yet, never refuses (the run says what it finds).
+ * On the workers that check is of another machine, so it isn't made: a worker takes a job only when it has the job's
+ * node packs and files.
+ */
+export function poolCardRefuses(modelId: string): boolean {
+ if (poolOnWorkers()) return false;
+ const need = rtxCardOf(modelId);
+ if (!need) return false;
+ const inv = readSnapshot({ kind: "install", key: "install", via: "server" })?.inventory;
+ if (!inv?.reachable) return false;
+ return gpuFits(need, inv) === false || RTX_CLASSES.some((c) => inv.nodes.missing.includes(c));
+}
+
+/** The open models this install's GPUs can't run right now (poolOwnSetups), for GET /api/status's pool rules. */
+export const poolOwnModels = (): Record<string, OwnSetup> => poolOwnSetups(poolTakes, poolCardRefuses);
diff --git a/tests/hosted-price-check.test.ts b/tests/hosted-price-check.test.ts
index c6e0e10f..fc1e40f5 100644
--- a/tests/hosted-price-check.test.ts
+++ b/tests/hosted-price-check.test.ts
@@ -242,7 +242,13 @@ describe("what this install's GPUs keep off, in the status", () => {
auth.setAccountGpu(a, null);
billing.resetBillingCache();
fake.policy = { ...FAKE_POLICY };
- expect((await visitorStatus(auth.accountById(a)!)).viewer.pool).toBeUndefined();
+ // A policy that keeps nothing off: only the open models these GPUs can't run right now are named, with the GPU of
+ // its own that runs each.
+ const left = (await visitorStatus(auth.accountById(a)!)).viewer.pool;
+ expect(left?.allow).toBeUndefined();
+ expect(left?.deny).toBeUndefined();
+ expect(left?.kinds).toBeUndefined();
+ for (const o of Object.values(left?.own ?? {})) expect(o.need).toBe("gpu");
});
it("the preset cards' words are the billing service's, or Try free when runs here are free with no service", async () => {
diff --git a/tests/pool-account-runs.test.ts b/tests/pool-account-runs.test.ts
index c687b5dd..4ede4058 100644
--- a/tests/pool-account-runs.test.ts
+++ b/tests/pool-account-runs.test.ts
@@ -328,7 +328,9 @@ describe("an account's run on the workers", () => {
const before = (db().prepare("SELECT COUNT(*) AS n FROM relay_tasks").get() as { n: number }).n;
const r = await run({ feature: "image", modelId: "oss-z-image-turbo", prompt: "a lighthouse" });
expect(r.status, JSON.stringify(r.body)).toBe(403);
- expect(r.body.code).toBe("not-offered");
+ // It runs on the account's own GPU instead: Run opens Connect your GPU.
+ expect(r.body.code).toBe("connect-gpu");
+ expect((r.body as { ownSetup?: unknown }).ownSetup).toMatchObject({ need: "gpu" });
expect((db().prepare("SELECT COUNT(*) AS n FROM relay_tasks").get() as { n: number }).n).toBe(before);
// Its files are there again: the run goes in line.
db().prepare("UPDATE relay_workers SET lanes_json = ? WHERE id = ?").run(JSON.stringify({ ...lanesNow, workflows }), w.id);
diff --git a/tests/pool-own-setup.test.ts b/tests/pool-own-setup.test.ts
new file mode 100644
index 00000000..8f5a1aa0
--- /dev/null
+++ b/tests/pool-own-setup.test.ts
@@ -0,0 +1,91 @@
+import { describe, expect, it } from "vitest";
+import { getModel, PRESETS } from "@/lib/catalog";
+import { ownSetupOnly } from "@/lib/own-setup";
+import { modelOwnSetup, poolOwnSetup, poolRulesOf, poolRunsModel, presetOwnSetup } from "@/lib/pool-rules";
+import { poolRunState, type HostedCheck } from "@/lib/hosted";
+import { needsGpu, poolOwnSetups, requestOwnSetup, requestSetupIds } from "@/server/pool-own-setup";
+import { loadIndex } from "@/server/gpu/index-file";
+
+/**
+ * What runs on a visitor's own setup only, as the hosted runs see it: the static items a request asks for (a model, or a
+ * mode or option of it), the open models this install's GPUs can't run right now (in the "own setup" shape), and how the
+ * pickers and Run read both.
+ */
+const H3 = "oss-minimax-h3";
+const comfyEndpoint = (id: string) => getModel(id)!.routes.find((r) => r.provider === "comfyui")!.endpoint;
+
+describe("a request's own setup", () => {
+ it("is asked by its model, then by the modes and options of it that have an id of their own", () => {
+ expect(requestSetupIds({ feature: "image", modelId: "oss-z-image-turbo", op: "t2i", params: {} })).toEqual(["oss-z-image-turbo"]);
+ expect(requestSetupIds({ feature: "video", modelId: H3, op: "t2v", params: { resolution: "2K" } })).toContain("regenerate:h3-2k");
+ expect(requestSetupIds({ feature: "video", modelId: H3, op: "t2v", params: { resolution: "768p" } })).not.toContain("regenerate:h3-2k");
+ expect(requestSetupIds({ feature: "video", modelId: "oss-kandinsky6", op: "t2v", params: { extra: { quality: "pro" } } })).toContain("oss-kandinsky6:pro");
+ });
+
+ it("is the first static item it asks for, or none", () => {
+ expect(requestOwnSetup({ feature: "image", modelId: "oss-z-image-turbo", op: "t2i", params: {}, engine: "open" })).toBeNull();
+ expect(requestOwnSetup({ feature: "video", modelId: H3, op: "t2v", params: { resolution: "2K" }, engine: "open" })).toEqual(ownSetupOnly("regenerate:h3-2k"));
+ expect(requestOwnSetup({ feature: "video", modelId: "oss-h3-regenerate", op: "upscale-video", params: {}, engine: "open" })).toEqual(ownSetupOnly("oss-h3-regenerate"));
+ });
+});
+
+describe("the open models this install's GPUs can't run right now", () => {
+ it("names each with a GPU of the visitor's own, and the memory its workflow needs when the index says", () => {
+ const off = comfyEndpoint("oss-z-image-turbo");
+ const out = poolOwnSetups(
+ (e) => e !== off,
+ (id) => id === H3,
+ );
+ expect(out["oss-z-image-turbo"]).toMatchObject({ need: "gpu" });
+ const gb = loadIndex().workflows[off]?.vramGb;
+ if (typeof gb === "number" && gb > 0) expect(out["oss-z-image-turbo"]).toEqual({ need: "gpu", vramGb: Math.ceil(gb) });
+ // A card that can't run it: a GPU of its own, whatever the memory.
+ expect(out[H3]).toEqual({ need: "gpu" });
+ // Everything else runs there.
+ expect(out["oss-wan22-14b"]).toBeUndefined();
+ expect(poolOwnSetups(() => true, () => false)).toEqual({});
+ });
+
+ it("needsGpu names the memory only when the index has it", () => {
+ expect(needsGpu()).toEqual({ need: "gpu" });
+ expect(needsGpu("no-such-workflow")).toEqual({ need: "gpu" });
+ });
+});
+
+describe("the pickers' labels", () => {
+ const own = { "oss-z-image-turbo": { need: "gpu" as const, vramGb: 12 } };
+
+ it("a model these GPUs can't run is kept off with what runs it; a denied model needs any GPU of its own", () => {
+ const rules = poolRulesOf({ pool: { deny: ["oss-wan22-14b"] } }, [], own)!;
+ expect(rules.own).toEqual(own);
+ expect(poolRunsModel(rules, { id: "oss-z-image-turbo", kind: "image", engine: "open" })).toBe(false);
+ expect(poolOwnSetup(rules, { id: "oss-z-image-turbo", kind: "image", engine: "open" })).toEqual(own["oss-z-image-turbo"]);
+ expect(poolOwnSetup(rules, { id: "oss-wan22-14b", kind: "video", engine: "open" })).toEqual({ need: "gpu" });
+ expect(poolOwnSetup(rules, { id: "oss-flux3-klein", kind: "image", engine: "open" })).toBeNull();
+ // A cloud model is the visitor's own key's: these rules have no say.
+ expect(poolOwnSetup(rules, { id: "oss-z-image-turbo", kind: "image", engine: "cloud" })).toBeNull();
+ // No rules (hosted runs off, or an account with its own GPU): no label.
+ expect(poolOwnSetup(undefined, { id: "oss-z-image-turbo", kind: "image", engine: "open" })).toBeNull();
+ });
+
+ it("the static items come first", () => {
+ expect(modelOwnSetup(undefined, { id: "oss-h3-regenerate", kind: "video", engine: "open" })).toEqual(ownSetupOnly("oss-h3-regenerate"));
+ expect(modelOwnSetup(poolRulesOf({}, [], own), { id: "oss-z-image-turbo", kind: "image", engine: "open" })).toEqual(own["oss-z-image-turbo"]);
+ });
+
+ it("a preset kept off says what its open model needs; one that runs there has no label", () => {
+ const preset = PRESETS.find((p) => p.open?.modelId === "oss-z-image-turbo");
+ if (!preset) return;
+ const rules = poolRulesOf({}, [{ id: preset.id, model: { id: "oss-z-image-turbo", kind: "image" } }], own);
+ expect(presetOwnSetup(rules, preset)).toEqual(own["oss-z-image-turbo"]);
+ expect(presetOwnSetup(undefined, preset)).toBeNull();
+ });
+
+ it("Run opens the own setup a price check names instead of staying off", () => {
+ const setup = { need: "gpu" as const, vramGb: 48 };
+ const check = { quote: { allowed: false, amount: 0, priceVersion: "", text: "Runs on your own GPU · 48 GB", code: "not-offered", ownSetup: setup } } as unknown as HostedCheck;
+ expect(poolRunState(check)).toMatchObject({ refused: true, setup });
+ const plain = { quote: { allowed: false, amount: 0, priceVersion: "", text: "Busy", code: "busy" } } as unknown as HostedCheck;
+ expect(poolRunState(plain)?.setup).toBeUndefined();
+ });
+});
diff --git a/tests/regenerate-more-hosted.test.ts b/tests/regenerate-more-hosted.test.ts
index bddedff2..1395cb87 100644
--- a/tests/regenerate-more-hosted.test.ts
+++ b/tests/regenerate-more-hosted.test.ts
@@ -6,8 +6,8 @@ import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from "vites
import { listenOnFreePort, startFakeBilling, type FakeBilling } from "./helpers/fake-billing";
import { startFakeComfy, type FakeComfy } from "./helpers/fake-comfy-runner";
-// MiniMax H3 at 2K with hosted runs on (review 6 of package n7-10): an account's 2K run on this install's GPUs is planned
-// and priced with each take's Open-H3 Regenerate finish beside its 768p draft, and a policy that keeps the finish's model
+// MiniMax H3 at 2K with hosted runs on: its Open-H3 Regenerate finish runs on the visitor's own GPU only, so a 2K run is
+// refused on this install's GPUs before Run (its 768p draft still runs there), and a policy that keeps the finish's model
// off those GPUs keeps the whole run off, priced or run.
// Regenerate is switched off for now (REGEN_OFFERED); these tests check it as it runs once switched on.
// tests/regenerate-offered.test.ts checks that nothing offers it while it is off.
@@ -32,6 +32,7 @@ const billing = await import("@/server/billing");
const { resetRates } = await import("@/server/rate");
const { decidePlace, poolQuote } = await import("@/server/hosted-run");
const R = await import("@/lib/catalog/regenerate");
+const { ownSetupLabel, ownSetupOnly } = await import("@/lib/own-setup");
let fake: FakeBilling;
let a = "";
@@ -59,32 +60,18 @@ beforeEach(() => {
});
const twoK = (resolution = "2K") => ({ feature: "video", modelId: R.H3_OPEN_MODEL, op: "t2v" as const, prompt: "A lighthouse in a storm", params: { resolution, duration: 5, numOutputs: 2 } });
-const finishes = (n: number) => Array.from({ length: n }, () => ({ model: R.REGEN_MODEL, op: "upscale-video" }));
describe("MiniMax H3 at 2K on this install's GPUs", () => {
- it("plans and prices each take's finish beside its draft", async () => {
- const place = await decidePlace(auth.accountById(a)!, twoK(), undefined);
- expect(place.kind).toBe("pool");
- if (place.kind !== "pool") return;
- expect(place.planned.model.id).toBe(R.H3_OPEN_MODEL);
- expect(place.planned.steps).toEqual(finishes(2));
- const before = fake.calls_of("/v1/quote").length;
- const quoted = await poolQuote(auth.accountById(a)!, twoK(), undefined);
- expect(quoted?.planned.steps).toEqual(finishes(2));
- // Priced as one run: the drafts first, then every take's finish (each model and operation once, with its count).
- const priced = [
- { model: R.H3_OPEN_MODEL, op: "t2v", kind: "video", jobs: 2 },
- { model: R.REGEN_MODEL, op: "upscale-video", kind: "video", jobs: 2 },
- ];
- expect(place.steps).toMatchObject(priced);
- const sent = fake.calls_of("/v1/quote").slice(before).at(-1)?.body as { run: { model: string; jobs: number; steps?: unknown } };
- expect(sent.run).toMatchObject({ model: R.H3_OPEN_MODEL, jobs: 2, steps: priced });
- expect(sent.run.steps).toHaveLength(2);
- // The plan alone (no row planned yet, as the moderation service's facts are) gives the same steps.
- const { runFacts } = await import("@/server/hosted");
- expect(runFacts(twoK(), place.planned, "video").steps).toMatchObject(priced);
- // 768p is the model alone.
- expect((await poolQuote(auth.accountById(a)!, twoK("768p"), undefined))?.planned.steps).toBeUndefined();
+ it("2K runs on the visitor's own GPU only: refused before Run in its label's words, never priced; 768p runs here", async () => {
+ const setup = ownSetupOnly("regenerate:h3-2k")!;
+ expect(setup).toMatchObject({ need: "gpu" });
+ const refused = await decidePlace(auth.accountById(a)!, twoK(), undefined);
+ expect(refused.kind).toBe("refuse");
+ if (refused.kind === "refuse") expect(refused.refusal.body).toMatchObject({ code: "connect-gpu", error: ownSetupLabel(setup), ownSetup: setup });
+ const quotes = fake.calls_of("/v1/quote").length;
+ expect((await poolQuote(auth.accountById(a)!, twoK(), undefined))?.quote).toMatchObject({ allowed: false, text: ownSetupLabel(setup), ownSetup: setup });
+ expect(fake.calls_of("/v1/quote").length).toBe(quotes);
+ expect((await decidePlace(auth.accountById(a)!, twoK("768p"), undefined)).kind).toBe("pool");
});
it("a policy that keeps Open-H3 Regenerate off these GPUs keeps the 2K run off; 768p still runs here", async () => {