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.

Docs: the billing hook, the moderation hook and hosted runs

Adarshf86117ac1576
diff --git a/docs/SELF-HOSTING.md b/docs/SELF-HOSTING.md
index fbf09351..911271cd 100644
--- a/docs/SELF-HOSTING.md
+++ b/docs/SELF-HOSTING.md
@@ -88,6 +88,10 @@ Public sign-up, guest browsing and connecting your own GPU to a shared install a
| `FUOBE_ENGINE_MODE`, `FUOBE_CLOUD_PROVIDER`, `FUOBE_ENHANCE_PROVIDER`, `FUOBE_LLM_PROVIDER` | The Settings choices above |
| `FUOBE_LLM_CONTEXT` | Tokens of context for the local model (default `16384`): Ollama's `num_ctx`, and the context LM Studio loads a model with. `0` leaves it to the server |
| `OPENAI_API_KEY`, `GEMINI_API_KEY` | Read into Settings; no feature uses them yet |
+| `FUOBE_HOSTED_RUNS=1` | With public sign-up: accounts with no GPU of their own may run on this install's ComfyUI ([Hosted runs](public-signup.md#hosted-runs)). Off by default |
+| `FUOBE_POOL_WAIT_MIN` | How long a hosted run may wait in line, in minutes (default `30`) |
+| `FUOBE_BILLING_URL`, `FUOBE_BILLING_TOKEN` | An optional external billing service for hosted runs ([billing-hook.md](billing-hook.md)). None: hosted runs are free |
+| `FUOBE_MODERATION_URL`, `FUOBE_MODERATION_TOKEN`, `FUOBE_MODERATION_MAX_WAIT_H` | An optional external moderation service ([moderation-hook.md](moderation-hook.md)). None: nothing is checked |
Uploads up to 200 MB work with sign-in on; Split soundtrack's Export mix sends its WAV in 16 MB parts, up to 2 GiB. Inputs given as URLs are fetched only from public addresses unless `FUOBE_ALLOW_PRIVATE_URLS=1`.
diff --git a/docs/billing-hook.md b/docs/billing-hook.md
new file mode 100644
index 00000000..ef682499
--- /dev/null
+++ b/docs/billing-hook.md
@@ -0,0 +1,128 @@
+# Billing hook: an optional external service
+
+An install can connect an external billing service at `FUOBE_BILLING_URL`. Fuobe sends facts about each run that goes
+to this install's GPUs (hosted runs, see [public-signup.md](public-signup.md#hosted-runs)); the service answers with what
+the person sees and whether the run may start. With no service set, every run is free and allowed, and Fuobe makes no
+call at all.
+
+Fuobe has no words of its own for prices or balances. Every word on screen about them (the price on Run, the balance in
+the sidebar, a refusal's text, a link, an offer) comes from the service's answers at runtime.
+
+## Settings
+
+| Variable | Meaning | Default |
+|---|---|---|
+| `FUOBE_BILLING_URL` | The service: `https://billing.example.com/base`, `http://…`, or a Unix socket on this machine, `unix:/path/to/billing.sock` | none: no billing |
+| `FUOBE_BILLING_TOKEN` | Sent as `Authorization: Bearer <token>` with every call | none |
+| `FUOBE_HOSTED_RUNS` | `1` lets accounts run on this install's GPUs (the only runs the service prices) | off |
+| `FUOBE_POOL_WAIT_MIN` | How long a run may wait in line on this install's GPUs when the service doesn't say | 30 |
+
+## When Fuobe calls the service
+
+Only for runs on this install's GPUs (the place `pool`), plus an account's policy, its balance, account events and
+offer clicks. A run on the account's own GPU or with its own key never asks the service. Every call is safe to send
+twice: the service must treat a repeated call (the same `requestId`, or the same hold and run row) as the same call.
+
+| Call | Timeout | When |
+|---|---|---|
+| `GET /v1/policy?account=<id>` | 1 s | before a run on this install's GPUs, and for the status (cached for the answer's `ttlS`) |
+| `POST /v1/quote` | 1 s | the price check before Run (`POST /api/generations?preview=1`), asked again 300 ms after each change |
+| `POST /v1/reserve` | 2 s, one retry with the same `requestId` | just before the run's rows are made |
+| `POST /v1/release` | 5 s, through the outbox | the rows couldn't be made after a reserve |
+| `POST /v1/settle` | 5 s, through the outbox | each row that succeeded |
+| `POST /v1/refund` | 5 s, through the outbox | each row that failed, was stopped, or was removed by an output check |
+| `GET /v1/balance?account=<id>` | 1 s | the sidebar's balance chip (cached 10 s) |
+| `POST /v1/account-event` | 5 s, best effort | an account was made, verified, signed in or deleted |
+| `POST /v1/interest` | 5 s | a person pressed an offer's button |
+
+### Shapes
+
+All JSON. Times are Unix milliseconds. Amounts are whole numbers in the service's own unit.
+
+```ts
+type AccountFacts = { id: string; email: string | null; emailVerified: boolean; signIn: "google" | "password"; createdAt: number; adultAt: number | null };
+type Place = "own-gpu" | "own-key" | "pool" | "install-key";
+type RunFacts = {
+ place: Place; model: string; op: string | null; app: string | null; preset: string | null; studio: string;
+ kind: "image" | "video" | "audio" | "text" | "model3d"; engine: "open" | "cloud"; provider: string;
+ jobs: number; outputsPerJob: number; megapixels: number | null; seconds: number | null; fps: number | null;
+ loras: number; inputs: { image: number; video: number; audio: number }; lane: string | null; providerUsd: number | null;
+};
+type QueueFacts = { lane: string; ahead: number; etaS: number | null; workersOnline: number; nextOpenAt: number | null; mine: { waiting: number; running: number } };
+type Action = { label: string; url: string }; // Fuobe opens url as given (https, or a path on this site)
+type Offer = { key: string; text: string; label: string }; // a click sends POST /v1/interest { account, key }
+type RefuseCode = "top-up" | "limit" | "busy" | "not-offered" | "blocked" | "closed" | "paused";
+
+type Quote = { allowed: boolean; amount: number; priceVersion: string; text: string; sub?: string; code?: RefuseCode; etaS?: number | null; action?: Action; offer?: Offer };
+type Policy = {
+ hosted: boolean; // may this account use this install's GPUs at all
+ pool: { allow?: string[]; deny?: string[]; apps?: { allow?: string[]; deny?: string[] } }; // models and apps there
+ uploads: { image: boolean; video: boolean; audio: boolean }; // which of its own files those runs may use
+ limits: { activeRuns: number; waiting: number; runsPerHour: number; outputsPerRun: number; maxMegapixels: number; maxSeconds: number; keepDays: number; spaceBytes: number };
+ links?: Action[]; notice?: { id: string; text: string; url?: string }; ttlS: number;
+};
+```
+
+| Call | Request | Answer |
+|---|---|---|
+| `POST /v1/quote` | `{ account: AccountFacts \| null, run: RunFacts, queue: QueueFacts \| null }` | `Quote` |
+| `POST /v1/reserve` | `{ requestId, account: AccountFacts, run: RunFacts, queue: QueueFacts \| null, shown: { amount, priceVersion } }` | `{ ok: true, holdId, amount, boostMs, maxWaitMs, pools?, text }` or `{ ok: false, code: RefuseCode \| "price-changed", text, quote?, action?, offer? }` |
+| `POST /v1/release` | `{ holdId, reason: "not-created" }` | `{ ok: true }` |
+| `POST /v1/settle` | `{ holdId, generationId, rows, status: "succeeded", final: { outputs, megapixels, seconds }, providerUsd, gpuMs, device, reachedProvider }` | `{ ok: true, charged }` |
+| `POST /v1/refund` | `{ holdId, generationId, rows, status: "failed" \| "canceled" \| "hidden" \| "unchecked", reason, reachedProvider, gpuMs, device }` | `{ ok: true, text }` |
+| `GET /v1/balance` | | `{ amount, chip, text, sub?, refillAt?, detail: { label, text }[], action?, offer? }` |
+| `POST /v1/account-event` | `{ event: "created" \| "verified" \| "signed-in" \| "deleted", account: AccountFacts }` | `{ ok: true }` |
+| `POST /v1/interest` | `{ account, key }` | `{ ok: true, text }` |
+
+`shown` is the price the person saw before pressing Run. A service must never charge more than it: when the price would
+be higher, it refuses with `price-changed` and the new quote, and the person sees the new price before running again.
+
+A reserve's `text` is shown on the result once it succeeded ("7 units"). `maxWaitMs` is how long the run may wait in
+line; past it the row fails and is refunded.
+
+Example (arbitrary numbers):
+
+```json
+POST https://billing.example.com/v1/reserve
+{ "requestId": "r_9Xk2", "account": { "id": "acct_1", "email": "[email protected]", "emailVerified": true, "signIn": "password",
+ "createdAt": 1767225600000, "adultAt": null },
+ "run": { "place": "pool", "model": "oss-example", "op": "t2i", "app": null, "preset": null, "studio": "image", "kind": "image",
+ "engine": "open", "provider": "comfyui", "jobs": 1, "outputsPerJob": 1, "megapixels": null, "seconds": null, "fps": null,
+ "loras": 0, "inputs": { "image": 0, "video": 0, "audio": 0 }, "lane": "comfyui", "providerUsd": 0 },
+ "queue": { "lane": "comfyui", "ahead": 2, "etaS": 40, "workersOnline": 1, "nextOpenAt": null, "mine": { "waiting": 0, "running": 0 } },
+ "shown": { "amount": 7, "priceVersion": "v7" } }
+→ { "ok": true, "holdId": "h_1", "amount": 7, "boostMs": 7000, "maxWaitMs": 700000, "text": "7 units" }
+```
+
+## What the person sees when a run is refused
+
+The run route answers a refusal with the service's `text` as `error`, a status by code, and the header
+`x-fuobe-billing: <code>`. The page opens one card with the text, the `action` link or the `offer` button, and a way to
+run for free on one's own GPU.
+
+| Code | HTTP |
+|---|---|
+| `price-changed` | 409 (the body has the new `quote`) |
+| `top-up` | 402 |
+| `limit` | 429 |
+| `busy`, `paused` | 503 |
+| `blocked`, `not-offered`, `closed` | 403 |
+
+## Holds and the outbox
+
+Every row a run makes (its jobs, and every step its chains queue) carries the reserve's hold. The server stamps it; a
+client can never set it. Once none of a hold's rows is still queued or running, each row is reported once: `settle` for
+a row that succeeded, `refund` for any other, each with `rows` (how many rows share the hold), so the service knows when
+the hold is closed. Reports are written to an outbox table first and sent from there, retried with backoff (10 s,
+doubling, up to 10 minutes) for 7 days. A restart loses nothing: the outbox finds every finished row with a hold and no
+report from what is stored. A run whose rows couldn't be made after its reserve sends one `release`.
+
+## When the service is down
+
+| Situation | What happens |
+|---|---|
+| No `FUOBE_BILLING_URL` | No call. Every run is free and allowed. |
+| Set, and it answers | As above. |
+| Set, and no answer in time | Runs on this install's GPUs are refused (503, "Runs are paused for a moment. Try again soon."). Run shows "Price unavailable". Runs on the account's own GPU or key go on. Reports wait in the outbox and are sent when it is back. Runs that already have a hold keep running. |
+
+The service's address and its errors are written to the server's log only. A browser never sees them.
diff --git a/docs/moderation-hook.md b/docs/moderation-hook.md
new file mode 100644
index 00000000..b91a21f8
--- /dev/null
+++ b/docs/moderation-hook.md
@@ -0,0 +1,62 @@
+# Moderation hook: optional run and output checks
+
+An install can connect an external moderation service at `FUOBE_MODERATION_URL`. Fuobe asks it about an account's run
+before the run is made, and, when the service asks for it, about each output before the account sees it. With no
+service set, nothing is checked (the studio as it was), and "Report this result" goes to a list the owner reads.
+
+The owner's own runs are never sent to the service.
+
+## Settings
+
+| Variable | Meaning | Default |
+|---|---|---|
+| `FUOBE_MODERATION_URL` | The service: `https://moderation.example.com`, `http://…`, or `unix:/path/to/moderation.sock` | none: no checks |
+| `FUOBE_MODERATION_TOKEN` | Sent as `Authorization: Bearer <token>` | none |
+| `FUOBE_MODERATION_MAX_WAIT_H` | How long an output may wait for its check before the run fails (and, with a billing hold, is refunded) | 24 |
+
+## Calls
+
+| Call | Timeout | Request | Answer |
+|---|---|---|---|
+| `POST /v1/check-run` | 10 s | `{ requestId, account: { id }, run: RunFacts, prompt, negative, inputs: { n, kind, sha256, preview }[], consent: null }` | `{ allowed: true, checkOutputs?: boolean }` or `{ allowed: false, code: "blocked" \| "consent", text }` |
+| `POST /v1/check-output` | 30 s | the file's bytes; headers `X-Fuobe-Generation`, `X-Fuobe-Account`, `X-Fuobe-Asset`, `X-Fuobe-Kind` (`image`, `video`, `audio`), `X-Fuobe-Sha256`, `Content-Type` | `{ decision: "show" }`, `{ decision: "hide", text }` or `{ decision: "wait", retryAfterS }` |
+| `POST /v1/report` | 5 s | `{ target: { generationId?, assetId?, shareId? }, category: "intimate" \| "minor" \| "violence" \| "impersonation" \| "copyright" \| "other", text, reporter: { account, email } }` | `{ ok: true, hidden, text }` |
+
+`RunFacts` is the same shape the billing hook uses ([billing-hook.md](billing-hook.md)). `preview` is `null` for now.
+
+## The run check
+
+The check comes first, before a billing hold. `{ allowed: false }` stops the run: nothing is made, nothing is charged,
+and the person sees the service's `text` (403). No answer in time: the run is refused with "Checks are paused for a
+moment" (503).
+
+## The output check, and when a service may skip it
+
+`checkOutputs` says whether this run's outputs go to `check-output` before they show. **A missing field means `true`**,
+the safe default for any service. A service may skip output checks for a run by answering `checkOutputs: false`: the
+outputs then show as soon as the run succeeds and `check-output` is never called for them.
+
+When outputs are checked:
+
+1. The run's files are saved and **held**: never served to the account, never by a shared link. The row stays running
+ with the stage "Checking", and the tile says so.
+2. Each file goes to `check-output`. "wait", or no answer, asks again later.
+3. Every file "show": the files are served and the run succeeds.
+4. Any file "hide": that file is deleted, the others with it, and the run fails with the service's `text`. A billing
+ hold is refunded as `hidden`.
+5. Past `FUOBE_MODERATION_MAX_WAIT_H`: the run fails with "This result couldn't be checked in time" and its files are
+ deleted. A billing hold is refunded as `unchecked`.
+
+## Reports
+
+"Report this result" (`POST /api/reports`, anyone who can see the result or the shared link) goes to `/v1/report`. If
+the service doesn't answer, or none is set, the report is kept in a list the owner reads (`GET /api/reports`).
+
+## Taking results down
+
+The owner can hide, show again and remove results by asset id or run id:
+
+- `POST /api/admin/outputs/hide` `{ assetIds?, generationIds? }`: served to no account and by no link; kept.
+- `POST /api/admin/outputs/unhide`: the same, undone (a file still waiting for its check stays held).
+- `POST /api/admin/outputs/remove` `{ …, evidence?: true }`: deleted; with `evidence`, moved to `<data>/evidence`
+ (mode 0600) instead.
diff --git a/docs/public-signup.md b/docs/public-signup.md
index d19a4ec2..72f0cc1b 100644
--- a/docs/public-signup.md
+++ b/docs/public-signup.md
@@ -267,6 +267,39 @@ account with that provider. The studio's own keys are never used for an account'
them would use the studio's civitai key). Assist, text steps, 3D and the other tools stay closed.
- An account on a studio set to **Open source only** keeps its keys, but they aren't used.
+## Hosted runs
+
+By default an account runs only on its own GPU or its own key. An owner who wants accounts to run on the studio's own
+ComfyUI instead sets `FUOBE_HOSTED_RUNS=1`. It is off unless set, and with it off nothing below changes.
+
+With it on:
+
+- An account with no GPU of its own can run in the studios (generations, camera motions, effects, apps). The run goes
+ to this install's ComfyUI server (the address in Settings). An install whose ComfyUI runs on the owner's computer
+ doesn't offer hosted runs.
+- An account whose own GPU is online runs there by default. The composer shows where a run goes ("Your GPU" or "This
+ studio's GPUs"), and the person can pick either.
+- Every other tool still needs the account's own GPU ("This tool doesn't run on your own GPU yet" stays as it is).
+ Image to 3D, extra LoRAs added to a request, and clips and sound as inputs stay on the account's own GPU.
+- An account can upload pictures for these runs. Clips and sound still need its own GPU or key.
+- A new account goes back to where it was after sign-up, not to "Connect your GPU". Connecting a GPU stays in
+ Settings → Your GPU and at `/connect`; the sidebar says "Your GPU · Optional".
+- A run waiting for the studio's GPUs shows its place in line ("In line · 3rd · about 40 s"). A run may wait
+ `FUOBE_POOL_WAIT_MIN` minutes (30 by default); past that it fails.
+- The account's usual limits apply: runs at once, runs per hour, outputs per run, and its space.
+
+Two optional services can go with it:
+
+- a **billing service** ([billing-hook.md](billing-hook.md)): prices runs on this install's GPUs, sets the price aside
+ before a run starts, and shows the person a balance. Without one, these runs are free.
+- a **moderation service** ([moderation-hook.md](moderation-hook.md)): checks a run before it starts and, when it asks
+ to, its outputs before they show. Without one, nothing is checked.
+
+The code is `src/server/hosted.ts` (the switch, the place, the line), `src/server/hosted-run.ts` (the run route's side),
+`src/server/run-stamp.ts` (what every row of a run carries) and `src/lib/hosted.ts` (the browser's side). The tests are
+`tests/hosted-runs.test.ts`, `tests/billing-hook.test.ts`, `tests/billing-release.test.ts` and
+`tests/moderation-hook.test.ts`.
+
## Uploads
An account with its own ComfyUI connected, or its own key, can upload files (`POST /api/uploads`,