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
Preset cards: their words for a run on the studio's GPUs come from the billing service
Adarshfef301e58195
diff --git a/docs/billing-hook.md b/docs/billing-hook.mdindex 2f22d598..45ac19ee 100644--- a/docs/billing-hook.md+++ b/docs/billing-hook.md@@ -64,10 +64,15 @@ type Policy = {limits: { activeRuns: number; waiting: number; runsPerHour: number; outputsPerRun: number; maxMegapixels: number; maxSeconds: number; keepDays: number; spaceBytes: number; addressRunsPerHour?: number };prefer?: "pool" | "own"; // the default place (absent: "own")kinds?: { image?: boolean; video?: boolean; audio?: boolean; text?: boolean; model3d?: boolean }; // absent: all+ cardText?: string; // preset cards' words for a run there (absent: none)links?: Action[]; notice?: { id: string; text: string; url?: string }; ttlS: number;};```+`cardText` is what a preset card says when its run would go to this install's GPUs for the viewer, such as "Try free"+(at most 40 characters). With a service set, the cards say only these words, and nothing when the policy has none.+With no service, runs there are free (`FUOBE_HOSTED_FREE=1`), and the cards say "Try free".+`megapixels` is the size of each picture or frame the run makes, about, as its workflow makes it: the canvas theworkflow binds (a canvas the request names counts only there; else the aspect ratio and resolution, the model'sdefaults where the request names none), or for a workflow sized by its input (an edit, an upscale, a face swap) thediff --git a/docs/public-signup.md b/docs/public-signup.mdindex 79bbc9d1..eeb023b3 100644--- a/docs/public-signup.md+++ b/docs/public-signup.md@@ -423,7 +423,9 @@ With it on:policy's model and app lists, and its kinds). The app lists also hold every preset whose open model, or the kind itmakes, is kept off. The model, camera motion and effect pickers and the preset galleries leave those out. A presetwith a cloud route stays in the galleries, and in the pickers while the composer is on the cloud engine (an account's- own key runs it there). Preset cards that run on the studio's GPUs for the viewer say "Try free".+ own key runs it there). Preset cards that run on the studio's GPUs for the viewer show the billing service's words+ for them (`viewer.cardText`, from the policy's `cardText`, such as "Try free"), and none when it sends none. With no+ billing service those runs are free, and the cards say "Try free".- A guest can attach files (pictures, clips and sound) in a studio before signing up: they stay in the browser andare not uploaded. A voice recording, and a drawing or painted area on a kept picture, are uploaded as they are made,so those ask the guest to sign up first. The whole draft (words, model, settings, preset and files) is kept for thediff --git a/src/components/preset-gallery.tsx b/src/components/preset-gallery.tsxindex 5afc2e33..28a896f5 100644--- a/src/components/preset-gallery.tsx+++ b/src/components/preset-gallery.tsx@@ -66,7 +66,8 @@ export const PresetCard = memo(function PresetCard({}) {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 tryFree = useTryFree()?.(preset) && !badge;+ const card = useTryFree();+ const tryFree = card && card.runs(preset) && !badge ? 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);@@ -103,7 +104,7 @@ export const PresetCard = memo(function PresetCard({)}{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">- Try free+ {tryFree}</span>)}<CardPending />diff --git a/src/hooks/use-pool-rules.ts b/src/hooks/use-pool-rules.tsindex 8a8bf4ab..84abb54d 100644--- a/src/hooks/use-pool-rules.ts+++ b/src/hooks/use-pool-rules.ts@@ -12,8 +12,8 @@ export function usePoolRules(): PoolRules | undefined {return v?.hosted && !v.gpu.connected ? v.pool : undefined;}-/** "Try free" on preset cards (tryFreeFor), once the page has hydrated: null until then, and with hosted runs off. */-export function useTryFree(): ((p: { id: string; open: boolean }) => boolean) | null {+/** The words on preset cards ("Try free", tryFreeFor), once the page has hydrated: null until then, and with none. */+export function useTryFree(): ReturnType<typeof tryFreeFor> {const hydrated = useHydrated();const v = useStatus().data?.viewer;const mode = useEngineMode();diff --git a/src/lib/api.ts b/src/lib/api.tsindex 9a0eaa6e..74682e1d 100644--- a/src/lib/api.ts+++ b/src/lib/api.ts@@ -893,6 +893,8 @@ export interface StatusInfo {hosted?: boolean;/** "pool": runs go to this studio's GPUs first, even with its own GPU online (either can still be picked). */prefer?: "pool";+ /** The words a preset card shows when its run would go to this studio's GPUs ("Try free"), from the server. None: no words. */+ cardText?: string;/** What this studio's GPUs keep off, for a viewer with no GPU of its own: its pickers leave it out (src/lib/pool-rules.ts). */pool?: PoolRules;/** The billing service's words for the account's balance (src/server/billing.ts). */diff --git a/src/lib/pool-rules.ts b/src/lib/pool-rules.tsindex bcc43206..7f09ed5a 100644--- a/src/lib/pool-rules.ts+++ b/src/lib/pool-rules.ts@@ -82,17 +82,18 @@ export function presetOffered(rules: PoolRules | undefined, p: { id: string; ope}/**- * "Try free" on preset cards: 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 it can be tried there.- * The rules hold presets whose model or kind is kept off too (poolRulesOf). Null (no card says it) with hosted runs off,- * for a viewer whose runs go to its own GPU, and with cloud models only.+ * 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+ * the server gives (`viewer.cardText`: the billing service's, or "Try free" when those runs are free with no service).+ * The rules hold presets whose model or kind is kept off too (poolRulesOf). Null (no card says anything) with hosted+ * runs off, with no words from the server, for a viewer whose runs go to its own GPU, and with cloud models only.*/export function tryFreeFor(- viewer: { hosted?: boolean; prefer?: "pool"; gpu: { connected: boolean }; pool?: PoolRules } | undefined,+ viewer: { hosted?: boolean; prefer?: "pool"; cardText?: string; gpu: { connected: boolean }; pool?: PoolRules } | undefined,engineMode: "cloud" | "open" | "both",-): ((p: { id: string; open: boolean }) => boolean) | null {- if (!viewer?.hosted || engineMode === "cloud") return null;+): { text: string; runs: (p: { id: string; open: boolean }) => boolean } | null {+ if (!viewer?.hosted || !viewer.cardText || engineMode === "cloud") return null;if (viewer.gpu.connected && viewer.prefer !== "pool") return null;const rules = viewer.gpu.connected ? undefined : viewer.pool;- return (p) => p.open && poolRunsPreset(rules, p.id);+ return { text: viewer.cardText, runs: (p) => p.open && poolRunsPreset(rules, p.id) };}diff --git a/src/server/account-gpu.ts b/src/server/account-gpu.tsindex ec2f4bf6..d450daf2 100644--- a/src/server/account-gpu.ts+++ b/src/server/account-gpu.ts@@ -188,6 +188,11 @@ export interface VisitorView {* policy says so). Absent: its own GPU first, as before. Either can always be picked.*/prefer?: "pool";+ /**+ * The words a preset card shows when its run would go to this install's GPUs (the billing service's policy, such as+ * "Try free"; with no service, "Try free": those runs are free). Absent: the cards show none.+ */+ cardText?: string;/*** What this install's GPUs keep off (the policy's model and app lists, and its kinds), for a visitor with no GPU of its* own: its pickers leave those out instead of failing at Run. Absent: nothing is kept off, or it has a GPU of its own.@@ -236,6 +241,8 @@ export async function visitorStatus(account: Account | null) {const p = await billingPolicy(account?.id ?? null);if (p?.hosted) viewer.hosted = true;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;if (rules) viewer.pool = rules;if (account && p?.links?.length) viewer.links = p.links;diff --git a/src/server/billing.ts b/src/server/billing.tsindex 87460104..957014fb 100644--- a/src/server/billing.ts+++ b/src/server/billing.ts@@ -111,6 +111,11 @@ export interface Policy {prefer?: "pool" | "own";/** Which kinds of run may use this install's GPUs (absent: all; a kind set to false: not that kind). */kinds?: { image?: boolean; video?: boolean; audio?: boolean; text?: boolean; model3d?: boolean };+ /**+ * The words a preset card shows when its run would go to this install's GPUs, such as "Try free" (absent: the cards+ * show none). Fuobe has no price words of its own: with a service, only the service says a run there is free.+ */+ cardText?: string;links?: Action[];notice?: { id: string; text: string; url?: string };ttlS: number;@@ -215,12 +220,16 @@ export function accountFacts(a: Pick<Account, "id" | "email" | "createdAt"> & {return { id: a.id, email: a.email || null, emailVerified: !!a.emailVerifiedAt, signIn: a.signIn ?? "password", createdAt: a.createdAt, adultAt: a.adultAt ?? null };}-/** With no billing service: an account may use this install's GPUs (when hosted runs are on) within today's limits. */+/**+ * With no billing service: an account may use this install's GPUs (when hosted runs are on) within today's limits. Those+ * runs are free (hosted runs with no service need FUOBE_HOSTED_FREE=1), so preset cards say so.+ */export const OPEN_POLICY: Policy = {hosted: true,pool: {},uploads: { image: true, video: false, audio: false },limits: { activeRuns: 4, waiting: 4, runsPerHour: 60, outputsPerRun: 4, maxMegapixels: 0, maxSeconds: 0, keepDays: 0, spaceBytes: 0 },+ cardText: "Try free",ttlS: 60,};diff --git a/tests/hosted-pickers.test.ts b/tests/hosted-pickers.test.tsindex 4df69732..18383114 100644--- a/tests/hosted-pickers.test.ts+++ b/tests/hosted-pickers.test.ts@@ -73,7 +73,7 @@ describe("presets kept off with their model or the kind they make", () => {{ id: "effect-melt", model: { id: "oss-clip", kind: "video" as const } },{ id: "app-cloud-only" },];- const tryFree = (pool: Parameters<typeof poolRulesOf>[0]) => tryFreeFor({ hosted: true, gpu: { connected: false }, pool: poolRulesOf(pool, presets) }, "both")!;+ 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", () => {const denied = tryFree({ pool: { deny: ["oss-face"] } });@@ -104,7 +104,7 @@ describe("presets kept off with their model or the kind they make", () => {const { kindAllowed } = await import("@/server/hosted-run");const policies = [{ pool: {} }, { pool: { deny: ["oss-face"] } }, { pool: { allow: ["oss-clip"] } }, { pool: {}, kinds: { video: false } }, { pool: { apps: { deny: ["app-portrait"] } } }];for (const p of policies) {- const free = tryFreeFor({ hosted: true, gpu: { connected: false }, pool: poolRulesOf(p, presets) }, "both")!;+ const free = tryFreeFor({ hosted: true, cardText: "Try free", gpu: { connected: false }, pool: poolRulesOf(p, presets) }, "both")!.runs;for (const preset of presets.filter((x) => x.model)) {const server = poolAllows(p, preset.model!.id, preset.id) && kindAllowed(p, preset.model!.kind);expect(free({ id: preset.id, open: true }), JSON.stringify({ p, preset: preset.id })).toBe(server);@@ -115,15 +115,23 @@ describe("presets kept off with their model or the kind they make", () => {describe("Try free on preset cards", () => {const card = { id: "app-x", open: true };+ const words = "Try free";it("only with hosted runs on, for a viewer whose runs go to this studio's GPUs, on presets they run", () => {expect(tryFreeFor(undefined, "both")).toBeNull();- expect(tryFreeFor({ gpu: { connected: false } }, "both")).toBeNull();- expect(tryFreeFor({ hosted: true, gpu: { connected: false } }, "cloud")).toBeNull();- expect(tryFreeFor({ hosted: true, gpu: { connected: true } }, "both")).toBeNull();- expect(tryFreeFor({ hosted: true, gpu: { connected: true }, prefer: "pool" }, "both")?.(card)).toBe(true);- const guest = tryFreeFor({ hosted: true, gpu: { connected: false }, pool: { apps: { deny: ["app-x"] } } }, "both")!;- expect(guest(card)).toBe(false);- expect(guest({ id: "app-y", open: true })).toBe(true);- expect(guest({ id: "app-y", open: false })).toBe(false);+ expect(tryFreeFor({ gpu: { connected: false }, cardText: words }, "both")).toBeNull();+ expect(tryFreeFor({ hosted: true, cardText: words, gpu: { connected: false } }, "cloud")).toBeNull();+ expect(tryFreeFor({ hosted: true, cardText: words, gpu: { connected: true } }, "both")).toBeNull();+ expect(tryFreeFor({ hosted: true, cardText: words, gpu: { connected: true }, prefer: "pool" }, "both")?.runs(card)).toBe(true);+ const guest = tryFreeFor({ hosted: true, cardText: words, gpu: { connected: false }, pool: { apps: { deny: ["app-x"] } } }, "both")!;+ expect(guest.text).toBe(words);+ expect(guest.runs(card)).toBe(false);+ expect(guest.runs({ id: "app-y", open: true })).toBe(true);+ expect(guest.runs({ id: "app-y", open: false })).toBe(false);+ });++ it("says only the server's words: none from it, no words on any card", () => {+ expect(tryFreeFor({ hosted: true, gpu: { connected: false } }, "both")).toBeNull();+ expect(tryFreeFor({ hosted: true, cardText: "", gpu: { connected: false } }, "both")).toBeNull();+ expect(tryFreeFor({ hosted: true, cardText: "Included", gpu: { connected: false } }, "both")?.text).toBe("Included");});});diff --git a/tests/hosted-price-check.test.ts b/tests/hosted-price-check.test.tsindex 943a5513..c6e0e10f 100644--- a/tests/hosted-price-check.test.ts+++ b/tests/hosted-price-check.test.ts@@ -244,4 +244,23 @@ describe("what this install's GPUs keep off, in the status", () => {fake.policy = { ...FAKE_POLICY };expect((await visitorStatus(auth.accountById(a)!)).viewer.pool).toBeUndefined();});++ it("the preset cards' words are the billing service's, or Try free when runs here are free with no service", async () => {+ // Hosted runs off: no words.+ process.env.FUOBE_HOSTED_FREE = "1";+ expect((await visitorStatus(auth.accountById(a)!)).viewer.cardText).toBeUndefined();+ // Free with no service: Try free.+ process.env.FUOBE_HOSTED_RUNS = "1";+ expect((await visitorStatus(auth.accountById(a)!)).viewer.cardText).toBe("Try free");+ expect((await visitorStatus(null)).viewer.cardText).toBe("Try free");+ // A billing service that says nothing about the cards: no words of Fuobe's own.+ process.env.FUOBE_BILLING_URL = fake.url;+ process.env.FUOBE_BILLING_TOKEN = "test-billing-token";+ billing.resetBillingCache();+ expect((await visitorStatus(auth.accountById(a)!)).viewer.cardText).toBeUndefined();+ // Its words, as they are.+ fake.policy = { ...FAKE_POLICY, cardText: "Free this week" };+ billing.resetBillingCache();+ expect((await visitorStatus(auth.accountById(a)!)).viewer.cardText).toBe("Free this week");+ });});