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: a 2K take's finish is checked and priced beside its draft again

Claude69277d6da2b1
diff --git a/docs/billing-hook.md b/docs/billing-hook.md
index cbcb1269..e22dd3e7 100644
--- a/docs/billing-hook.md
+++ b/docs/billing-hook.md
@@ -47,6 +47,7 @@ type RunFacts = {
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;
+ steps?: { model: string; op: string }[]; // the run's other steps beside `model` (a 2K take's finish on this install's GPUs)
};
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)
diff --git a/src/server/billing.ts b/src/server/billing.ts
index 7eb6d2b7..19d91d08 100644
--- a/src/server/billing.ts
+++ b/src/server/billing.ts
@@ -46,6 +46,8 @@ export interface RunFacts {
inputs: { image: number; video: number; audio: number };
lane: string | null;
providerUsd: number | null;
+ /** The other steps the run makes beside `model` (a 2K take's Open-H3 Regenerate finish), when it makes any. */
+ steps?: { model: string; op: string }[];
}
export interface QueueFacts {
diff --git a/src/server/hosted-run.ts b/src/server/hosted-run.ts
index 85f5df63..137fec35 100644
--- a/src/server/hosted-run.ts
+++ b/src/server/hosted-run.ts
@@ -23,7 +23,7 @@ import {
type RunFacts,
} from "./billing";
import { outputKind, previewGeneration } from "./generations";
-import { HOSTED_WORDS, inputCounts, poolAllows, poolReady, queueFacts, runFacts, runOnPool } from "./hosted";
+import { HOSTED_WORDS, inputCounts, poolAllowsRun, poolReady, queueFacts, runFacts, runOnPool } from "./hosted";
import { hostedRunsOn } from "./hosted-switch";
import { checkRun, moderationConfigured } from "./moderation";
import type { RunStamp } from "./run-stamp";
@@ -115,7 +115,7 @@ export async function decidePlace(account: Account, req: GenerationRequest, wish
// From here on the run would be this install's: what it can't take there goes to the account's own GPU when it has one.
const notHere = (error: string): PlaceDecision => (hasGpu && wish !== "pool" ? { kind: "own" } : { kind: "refuse", refusal: { status: 403, body: { error, code: "not-offered" }, headers: { [BILLING_HEADER]: "not-offered" } } });
if (outputKind(planned.op, planned.model) === "model3d") return hasGpu && wish !== "pool" ? { kind: "own" } : { kind: "refuse", refusal: { status: 403, body: { error: OWN_GPU_TOOL_MESSAGE, code: "own-gpu-tool" }, headers: {} } };
- if (!poolAllows(p, planned.model.id, req.presetId)) return notHere(HOSTED_WORDS.notOffered);
+ if (!poolAllowsRun(p, planned, req.presetId)) return notHere(HOSTED_WORDS.notOffered);
if (poolCardRefuses(planned.model.id)) return notHere(HOSTED_WORDS.rtxCard);
if (req.loras?.length) return notHere(HOSTED_WORDS.loras);
const inputs = inputCounts(req);
@@ -224,7 +224,7 @@ export async function poolQuote(account: Account | null, asked: GenerationReques
}
if (planned.route.provider !== "comfyui") return null;
if (account && wish !== "pool" && accountGpu(account.id) && (await ownGpuOnline(account.id))) return null;
- if (p && (!p.hosted || !poolAllows(p, planned.model.id, req.presetId))) return null;
+ if (p && (!p.hosted || !poolAllowsRun(p, planned, req.presetId))) return null;
if (poolCardRefuses(planned.model.id)) return null;
const kind = outputKind(planned.op, planned.model);
const q = await billingQuote(account ? accountFacts(account) : null, runFacts(req, planned, kind), queueFacts(account?.id ?? null));
diff --git a/src/server/hosted.ts b/src/server/hosted.ts
index bc651119..37ddb04c 100644
--- a/src/server/hosted.ts
+++ b/src/server/hosted.ts
@@ -64,6 +64,14 @@ export function poolAllows(p: Pick<Policy, "pool">, modelId: string, presetId?:
return true;
}
+/**
+ * May this whole run go on this install's GPUs: its model and every other step it makes (a 2K take's Open-H3 Regenerate
+ * finish), so a policy that keeps a model off the pool keeps it off as a step too.
+ */
+export function poolAllowsRun(p: Pick<Policy, "pool">, planned: { model: { id: string }; steps?: { model: string }[] }, presetId?: string | null): boolean {
+ return [planned.model.id, ...(planned.steps ?? []).map((s) => s.model)].every((id) => poolAllows(p, id, presetId));
+}
+
/** The file kinds a request uses (for the policy's uploads rule and the billing facts). */
export function inputCounts(req: GenerationRequest): { image: number; video: number; audio: number } {
const i = req.inputs ?? {};
@@ -139,7 +147,7 @@ export function placeInLine(generationId: string): { place: number; etaSeconds:
/** The facts the billing service prices a run by (from a planned request: previewGeneration's answer). */
export function runFacts(
req: GenerationRequest,
- p: { model: { id: string; kind: string; engine: "open" | "cloud" }; op: string; jobs: number; outputs: number; providerId: string; costUsd: number | null; loras: { applied: unknown[] } },
+ p: { model: { id: string; kind: string; engine: "open" | "cloud" }; op: string; jobs: number; outputs: number; providerId: string; costUsd: number | null; loras: { applied: unknown[] }; steps?: { model: string; op: string }[] },
kind: RunFacts["kind"],
): RunFacts {
const model = getModel(p.model.id);
@@ -162,5 +170,7 @@ export function runFacts(
inputs: inputCounts(req),
lane: POOL_LANE,
providerUsd: p.costUsd,
+ // The run's other steps (a 2K take's finish), each a model and op the service prices beside the main one.
+ ...(p.steps?.length && { steps: p.steps.map((s) => ({ model: s.model, op: s.op })) }),
};
}