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.

Merge every surface through the one gate, and own-setup labels

Adarsh65a9b6096bb4
diff --cc docs/billing-hook.md
index 607b2897,672e6052..09093c0d
--- a/docs/billing-hook.md
+++ b/docs/billing-hook.md
@@@ -79,17 -79,69 +79,69 @@@ defaults where the request names none)
input's size, an upscale's times its factor, within the workflow's limits. It is null for sound, text and 3D.
`steps` lists every step of the run that uses this install's GPUs, the run's own step first: a chain (a film of
- several shots, a picture and then a step on it, MiniMax H3 at 2K with its finish for each take) is priced once, with one
- quote and one hold, for one press of Run.
+ several shots, a picture and then a step on it) is priced once, with one quote and one hold, for one press of Run.
Steps of CPU work are left out: they cost nothing. The requirements index marks these `cpu`: no model file, no
graphics memory and no card their nodes need, such as filters, trims, joins, adding sound and Ken Burns moves. A step
- whose nodes run on the card (RTX Video) is GPU work. Every step must be one the policy allows (`pool`, `kinds`) and one
- this install's GPUs can run (a ComfyUI step: not a text step, a step made in the browser or a cloud model), or the run
- isn't offered here. It is refused before Run, never part way through.
+ whose nodes run on the card (RTX Video) is GPU work. A text step inside the run (a script, lyrics, a translation)
+ is written by the install's AI helper: it is left out too, and never counted. Every other step must be one the policy
+ allows (`pool`, `kinds`) and one this install's GPUs can run (a ComfyUI step: not a step made in the browser or a
+ cloud model), or the run isn't offered here. It is refused before Run, never part way through.
+
+ A tool's run (Shorts, Cinema Studio, Storyboard, the apps, the palette lock and every other tool an account runs) goes
+ through the same gate as a studio run: every step is checked, the run is priced once from every step, held once, and
+ counted once. Its price check answers `{ place: "pool", quote, line }` beside the tool's own answer when the run would
+ go to this install's GPUs, and the tool's own answer is then priced as a run there (so an account with no GPU of its
+ own is priced, not asked to connect one). A tool whose body has no field for the place or the price shown reads them
+ from the request's headers: `x-fuobe-place` (`own` or `pool`) and `x-fuobe-shown` (`{ amount, priceVersion }` as
+ URI-encoded JSON). A field in the body wins.
+
+ A tool makes its own requests, so each of its steps is priced as it asks. A step that asks for more outputs at once
+ than `outputsPerRun` allows (or Fuobe's own cap of 4) is refused before Run with words that say how many a run there
+ makes. It is never priced as a smaller run. The studios' own runs are cut to the cap instead, and say so. Before
+ anything of a tool's run is sent, Fuobe checks the rows its start made against what was priced and held: no more jobs
+ of any model, no more outputs at once than the cap, and only CPU work for a run held as CPU work. A run whose rows
+ don't match is stopped (403, `code: "not-offered"`): its rows are canceled, and their reports close its hold. A hold
+ gets a `release` only when none of its rows were made, never as well as its rows' reports. A tool run whose start makes
+ no rows at all (it kept its own error, say) sends nothing: its hold gets a `release`, and the run doesn't count toward
+ the hour. The palette lock spreads the pictures a person picks over separate jobs of one picture each: on this install's
+ GPUs it makes no more of them than `outputsPerRun` allows, as a studio run there is cut.
+
+ One press of Run is one hold and one run, however often it is sent. A tool page sends its own id for each press
+ (`requestId` in the body, or the `x-request-id` header for a tool whose body has no field for it). With hosted runs on,
+ the press is kept in the database for a day: a resend that reaches another server process, or comes after a restart,
+ gets the first answer and makes nothing. The reserve's `requestId` is made from the account and the press (a hash, so
+ one account can never name another's hold). A press refused after its hold was made gives that hold back; a resend of
+ it asks for a new hold under a new `requestId`.
+
+ The limits on runs at once and in line count a tool run from the moment it is let in. A tool whose start waits for
+ something (a channel, a plan) before it makes its rows still counts as one run going, and one in line, until its rows
+ exist, so requests sent together can't all pass the limits.
+
+ Some models, modes and options run on a visitor's own setup only (`src/lib/own-setup.ts`), and so does a workflow that
+ none of this install's GPUs can run right now (none holds its files, serves its kind of work, or has the memory it
+ needs). A run that asks for one, on any step, is refused before Run. The price check answers `allowed: false` with the
+ label's words as `text` and the setup itself as `ownSetup` (`{ need: "gpu", vramGb? }` or `{ need: "key", provider }`),
+ and Run opens that setup (Connect your GPU, or Add your key) instead of staying off. The run itself is refused with
+ 403, `code: "connect-gpu"` or `"add-key"`. A mode whose own check refuses it while it is planned here (MiniMax H3 at
+ 2K, Kandinsky 6.0 Pro) gets the same answer, but with no plan in it: only `modelId`, `place`, `quote` and `line`.
+ When the account has its own GPU, these runs go to that GPU, as before. `GET /api/status` lists the open models these
+ GPUs can't run right now (`viewer.pool.own`), so the pickers can label them. An item whose graphs the workflow manifest
+ marks validated runs here like any other, as its label leaves the pages, with no code change. Restore & colourise names
+ a GPU of the visitor's own only: its gated LoRA is never sent with a visitor's key.
+
+ A tool page whose price check answers `{ place: "pool", quote, line }` shows the service's words and the place in line
+ in its price slot, not its own words for a run on the visitor's own GPU. When the quote is refused, Run sends nothing
+ and says why, or opens the visitor's own setup when `ownSetup` names one.
+
+ For a visitor with no GPU of its own, the pickers never leave out what these GPUs keep off. The model picker, the preset
+ galleries and the camera motion, effect and Mix pickers show each such item with its label ("Runs on your own GPU ·
+ 48 GB", "Use your own fal.ai key"). A preset card says the `cardText` ("Try free") only when these GPUs run it. An app's
+ own tool says the label in its place chip, and its Run opens the setup too. "Connect your GPU" says the label under
+ its title.
A run made only of CPU work is free and never counted. Fuobe asks the service for no quote and no hold, and the run
-counts against none of the policy's limits. For now it still waits in the same line on this install's GPUs as GPU work.
-It does not run on the install's own CPU yet.
+counts against none of the policy's limits. A worker with a CPU slot runs it beside its GPU's job, in a line of its
+own ([gpu-workers.md](gpu-workers.md), "The CPU slot"). A worker with none runs it in its GPU's line, as before.
3D runs (Image to 3D and the other 3D tools) aren't offered on this install's GPUs yet, whatever `kinds.model3d` says.
They run on the account's own GPU, as before. An account with no GPU of its own is told the tool isn't available here
diff --cc src/server/generations.ts
index ec0c461b,2e2b6e21..07157f9f
--- a/src/server/generations.ts
+++ b/src/server/generations.ts
@@@ -559,9 -568,8 +572,10 @@@ export const ASSET_FREE: Record<string
"relay_workers.hours_json": "a worker's hours: a time zone and windows",
"relay_workers.allow_json": "the lanes the owner lets a worker run, with their delays",
"relay_workers.seen_json": "the countries and network hashes a worker's token was used from",
+ "relay_workers.ceiling_json": "the most a worker's PC may run: lanes, workflow ids and sizes",
+ "relay_workers.cpu_slot_json": "the kinds of finishing job a worker's CPU slot runs",
"relay_pairings.facts_json": "what a paired ComfyUI said about itself: its name, GPU and version",
+ "account_canvases.summary_json": "an account board's list line: node and page counts, and its outline (node types, places and short labels)",
};
/** The query that finds the rows of one ASSET_REFS table naming a file (@id), except the purged generation's own (@g). */
diff --cc src/server/hosted-run.ts
index 8405522e,ead8b861..51ee3930
--- a/src/server/hosted-run.ts
+++ b/src/server/hosted-run.ts
@@@ -25,11 -24,12 +24,12 @@@ import
type RunFacts,
} from "./billing";
import { getModel } from "@/lib/catalog";
- import { PLACE_ASK_HEADER } from "@/lib/guest-access";
- import { createGenerations, outputKind, plannedSteps, previewGeneration, type PlannedStep } from "./generations";
+ import { PLACE_ASK_HEADER, RUN_PLACE_HEADER, RUN_SHOWN_HEADER } from "@/lib/guest-access";
+ import { db } from "./db";
+ import { AccountRunError, createGenerations, outputKind, plannedSteps, previewChained, previewGeneration, stepsOf, type PlannedStep } from "./generations";
import { loadIndex } from "./gpu/index-file";
import { poolLane } from "./computer/pool";
- import { HOSTED_GUEST_WORDS, HOSTED_WORDS, inputCounts, poolAllows, poolAllowsRun, poolOnWorkers, poolReady, poolRunsProvider, poolTakes, poolTakesFiles, poolTicketsReady, POOL_LANE, queueFacts, runFacts, runOnPool, workflowPicks } from "./hosted";
-import { HOSTED_GUEST_WORDS, HOSTED_WORDS, inputCounts, outputsWords, poolAllows, poolAllowsRun, poolOnWorkers, poolReady, poolRunsProvider, poolTakes, poolUploads, POOL_LANE, queueFacts, runFacts, runOnPool, workflowPicks } from "./hosted";
++import { HOSTED_GUEST_WORDS, HOSTED_WORDS, inputCounts, outputsWords, poolAllows, poolAllowsRun, poolOnWorkers, poolReady, poolRunsProvider, poolTakes, poolTicketsReady, poolUploads, POOL_LANE, queueFacts, runFacts, runOnPool, workflowPicks } from "./hosted";
import { withRunStamp } from "./run-stamp";
import { hostedRunsOn } from "./hosted-switch";
import { checkRun, moderationConfigured } from "./moderation";
@@@ -92,7 -122,30 +122,32 @@@ const OWN = { kind: "own" } as const
export const OWN_GPU_QUIET = "Your GPU isn't answering right now. Run this on this studio's GPUs instead, or try again when your GPU is back.";
/** A run this install's GPUs won't take, refused in the words the price check before Run gives too. */
- const notOffered = (error: string): PlaceDecision => ({ kind: "refuse", refusal: { status: 403, body: { error, code: "not-offered" }, headers: { [BILLING_HEADER]: "not-offered" } } });
+ 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 = gateText(gate, false);
++ // Not right now (the GPUs that could run it are being updated): refused as a busy moment, with Run off until then.
++ if (gate.reason === "busy") return { kind: "refuse", refusal: billingRefusal("busy", error) };
+ 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" } });
@@@ -183,12 -278,22 +280,22 @@@ export function pricedSteps(steps: Plan
/**
* 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, a kind of file, or (`busy`) not right now: the GPUs that could run it are being updated.
+ * LoRAs, a kind of file, more outputs at once than a run there makes (`outputs`: a tool's run, which can't be cut down
- * the way the studios' own runs are), or one that runs on the visitor's own setup only (`ownSetup`: a static item of
++ * the way the studios' own runs are), 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).
++ * has the memory), or (`busy`) not right now: the GPUs that could run it are being updated.
*/
- export type GateReason = "model3d" | "notOffered" | "rtxCard" | "loras" | "inputs" | "busy";
-export type GateReason = "model3d" | "notOffered" | "rtxCard" | "loras" | "inputs" | "outputs" | "ownSetup";
++export type GateReason = "model3d" | "notOffered" | "rtxCard" | "loras" | "inputs" | "outputs" | "ownSetup" | "busy";
+
+ /**
+ * 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). `cap`: with "outputs", the most a run there
+ * makes at once.
+ */
+ export type GateRefusal = { ok: false; reason: GateReason; setup?: OwnSetup; cap?: number };
/** 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" | "outputs">, guest: boolean): string {
if (reason === "model3d") return OWN_GPU_TOOL_MESSAGE;
return (guest ? HOSTED_GUEST_WORDS : HOSTED_WORDS)[reason];
}
@@@ -221,12 -337,12 +339,16 @@@ export function poolGate
}
// 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" ? ownSetupHere(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 };
+ // A run its GPUs could take, but none of them can right now (every one that could is built from the catalog before
+ // this studio's update): Run is off until one is updated, never a run that waits in line for nothing.
+ const endpoints = [planned.route.endpoint, ...(steps ?? []).filter((s) => s.provider === "comfyui").map(stepEndpoint)];
+ if (!endpoints.every((e) => poolTicketsReady(e))) return { ok: false, reason: "busy" };
return { ok: true, steps };
}
@@@ -451,7 -560,14 +566,18 @@@ 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 gate's refusal as the price check's quote (gateText: the label's words for an own setup). Busy (the GPUs that could
++ * run it are being updated) is quoted as code "busy", shown like the other busy moments with Run off.
++ */
++const gateQuote = (gate: GateRefusal, guest: boolean): Quote & { ownSetup?: OwnSetup } =>
++ gate.reason === "busy" ? { ...notOfferedQuote(gateText(gate, guest)), code: "busy" } : 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,
diff --cc src/server/hosted.ts
index 937c41bd,238556c0..1db968e0
--- a/src/server/hosted.ts
+++ b/src/server/hosted.ts
@@@ -84,24 -84,13 +84,25 @@@ export function poolTakes(endpoint: str
return picks.length > 0 && picks.every((id) => workersCanRun(id));
}
+/**
+ * Can this install's GPUs take this workflow's job tickets now (an account's run there goes as one): on the workers, one
+ * built for this studio's catalog that may run it (a workflow that picks its graph at run time: every graph it may
+ * pick). After an update of the studio, a worker built from the catalog before takes them once it is updated too:
+ * meanwhile poolTakes still says the run could go there, and this says not yet. Not on the workers: yes.
+ */
+export function poolTicketsReady(endpoint: string | undefined): boolean {
+ if (!endpoint || !poolOnWorkers()) return true;
+ const picks = endpoint.includes("{") ? workflowPicks(endpoint) : [endpoint];
+ return picks.length > 0 && picks.every((id) => workersCanRun(id, { tickets: true }));
+}
+
/**
- * The steps a run on this install's GPUs can carry out there: ComfyUI's. The price check, the run's admission and its
- * submit read this one table, so a run is refused before Run when a step of it couldn't run there (a text step, a step
- * made in the browser, a cloud model), never part way through.
+ * The steps a run on this install's GPUs can carry out there: ComfyUI's, and a chain's text steps (a script, lyrics, a
+ * translation), which the install's AI helper writes for free. The price check, the run's admission and its submit read
+ * this one table, so a run is refused before Run when a step of it couldn't run there (a step made in the browser, a
+ * cloud model), never part way through.
*/
- const POOL_PROVIDERS: ReadonlySet<string> = new Set(["comfyui"]);
+ const POOL_PROVIDERS: ReadonlySet<string> = new Set(["comfyui", "llm"]);
export const poolRunsProvider = (provider: string): boolean => POOL_PROVIDERS.has(provider);
/** May a run on this install's GPUs send them this kind of file (the workers take only the kinds the install allows)? */