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.

Character Sheet and AI Influencer: Run sends the run unless this studio's GPUs refused it

Adarshe7d691c82b2f
diff --git a/src/components/fashion/character-sheet.tsx b/src/components/fashion/character-sheet.tsx
index c22abc3b..1da693e7 100644
--- a/src/components/fashion/character-sheet.tsx
+++ b/src/components/fashion/character-sheet.tsx
@@ -27,6 +27,7 @@ import type { Generation } from "@/lib/catalog/types";
import { cn } from "@/lib/utils";
import { onAttr, TAB_PILL, TabRow } from "@/components/ui/tab-row";
import { toastError } from "@/lib/refusals";
+import { refusedBeforeRun } from "@/lib/run-place";
import { SheetExample } from "@/components/empty-examples";
import { linkTab, TabFromLink } from "@/components/nav/tab-from-link";
@@ -240,8 +241,10 @@ export function CharacterSheetView({ fields, defaults }: { fields: CastFieldData
askRun(() => {
if (mode === "reference" && !photos.length) return toast("Upload at least 1 image");
if (!body) return toast(mode === "describe" ? "Describe your character first" : "Wait for the uploads to finish");
- // Not taken now (the price check said why): nothing is sent.
- if (preview.data?.error) return toast(preview.data.error);
+ // Not taken now by this studio's GPUs (the check of these settings said why): nothing is sent. Any other answer of
+ // the check goes to the server, whose refusal opens the card that helps (connect a GPU, add a key).
+ const refused = refusedBeforeRun(preview.data, preview.isPlaceholderData);
+ if (refused) return toast(refused);
run.mutate(body, {
// The run line already says which model runs and why (its notes), so no toast here.
onSuccess: (r) => setIds((xs) => [...r.items.map((g) => g.id), ...xs]),
diff --git a/src/components/influencer/influencer-builder.tsx b/src/components/influencer/influencer-builder.tsx
index 3b791ed9..abf4d0cf 100644
--- a/src/components/influencer/influencer-builder.tsx
+++ b/src/components/influencer/influencer-builder.tsx
@@ -17,7 +17,7 @@ import { Button } from "@/components/ui/button";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import { Textarea } from "@/components/ui/textarea";
import { useAskBeforeUpload, useEngine, useGenerations, useModelAccess } from "@/lib/api";
-import { toolPoolPrice } from "@/lib/run-place";
+import { refusedBeforeRun, toolPoolPrice } from "@/lib/run-place";
import { keepOffered, offered } from "@/lib/model-access";
import {
categoriesFor,
@@ -202,8 +202,10 @@ export function InfluencerBuilder() {
askRun(() => {
if (blocker) return toast(blocker);
if (!body) return toast("Wait for the uploads to finish");
- // Not taken now (the price check said why): nothing is sent.
- if (preview.data?.error) return toast(preview.data.error);
+ // Not taken now by this studio's GPUs (the check of these settings said why): nothing is sent. Any other answer of
+ // the check goes to the server, whose refusal opens the card that helps (connect a GPU, add a key).
+ const refused = refusedBeforeRun(preview.data, preview.isPlaceholderData);
+ if (refused) return toast(refused);
run.mutate(body, {
onSuccess: (r) => setIds((xs) => [...r.items.map((g) => g.id), ...xs]),
onError: (e) => toastError(e, "Couldn't start the sheet"),
diff --git a/src/components/photodump/hooks.ts b/src/components/photodump/hooks.ts
index 17d616d4..a40897ce 100644
--- a/src/components/photodump/hooks.ts
+++ b/src/components/photodump/hooks.ts
@@ -6,7 +6,7 @@ import { COMPUTER_KICK_EVENT, useElements, useSaveElement, useViewer } from "@/l
import type { StudioElement } from "@/lib/catalog/elements";
import type { Generation } from "@/lib/catalog/types";
import { responseError } from "@/lib/refusals";
-import { toolPoolPrice } from "@/lib/run-place";
+import { withPoolRefusal } from "@/lib/run-place";
/**
* A run started: the tab that runs this person's jobs on the ComfyUI on this computer (an account's "Your GPU") asks for
@@ -32,6 +32,8 @@ export interface RunPreview {
fixedAspect?: boolean;
notes: string[];
error?: string;
+ /** The error is this studio's GPUs not taking the run now (run-place.ts withPoolRefusal): Run sends nothing. */
+ poolRefused?: boolean;
}
export interface UserPack {
@@ -48,9 +50,8 @@ export function useRunPreview(url: string, body: unknown | null) {
queryFn: async () => {
const p = await post<RunPreview>(`${url}?preview=1`, body);
// A run on this studio's GPUs that isn't taken now (or runs on the person's own setup): said as the reason it
- // can't run, so Run is off with the service's words.
- const pool = toolPoolPrice(p);
- return pool?.refused ? { ...p, error: pool.text } : p;
+ // can't run, so Run is off with the service's words (marked poolRefused: no other error stops Run).
+ return withPoolRefusal(p);
},
enabled: body !== null,
placeholderData: keepPreviousData,
diff --git a/src/lib/run-place.ts b/src/lib/run-place.ts
index 3b442d05..d6e501b7 100644
--- a/src/lib/run-place.ts
+++ b/src/lib/run-place.ts
@@ -291,3 +291,21 @@ export function toolPoolPrice(check: unknown): ToolPoolPrice | null {
headers: shown ? { [RUN_SHOWN_HEADER]: shownHeader(shown) } : {},
};
}
+
+/**
+ * A tool page's price check (`?preview=1`) as its Run reads it: when this studio's GPUs wouldn't take the run now, their
+ * words become the check's error, marked `poolRefused`. Every other answer stays as it is: an error there (no GPU or key
+ * connected yet, say) is the server's to answer when Run is pressed, and its refusal opens the card that helps.
+ */
+export function withPoolRefusal<T extends { error?: string; poolRefused?: boolean }>(check: T): T {
+ const pool = toolPoolPrice(check);
+ return pool?.refused ? { ...check, error: pool.text, poolRefused: true } : check;
+}
+
+/**
+ * What Run says instead of sending the run: only a refusal by this studio's GPUs (withPoolRefusal), and only from the
+ * check of the settings shown now (`stale`: a previous check, kept on screen while the new one runs). Null: send it.
+ */
+export function refusedBeforeRun(check: { error?: string; poolRefused?: boolean } | null | undefined, stale = false): string | null {
+ return check?.poolRefused && check.error && !stale ? check.error : null;
+}
diff --git a/tests/run-place.test.ts b/tests/run-place.test.ts
index 03b330ad..511fe54f 100644
--- a/tests/run-place.test.ts
+++ b/tests/run-place.test.ts
@@ -1,6 +1,6 @@
import { describe, expect, it } from "vitest";
import { quoteBody } from "@/lib/hosted";
-import { checkedPool, composerOnPool, composerPlace, IN_BROWSER, mainModel, openCheckPlace, placePrice, runPlace, toolPoolPrice, type RunPlaceInput } from "@/lib/run-place";
+import { checkedPool, composerOnPool, composerPlace, IN_BROWSER, mainModel, openCheckPlace, placePrice, refusedBeforeRun, runPlace, toolPoolPrice, withPoolRefusal, type RunPlaceInput } from "@/lib/run-place";
import { RUN_SHOWN_HEADER, shownHeader } from "@/lib/guest-access";
import { lineWords } from "@/lib/pool-line";
@@ -289,3 +289,39 @@ describe("a tool page's own price check, for a run on this studio's GPUs", () =>
expect(toolPoolPrice(null)).toBeNull();
});
});
+
+describe("Run on a tool page (Character Sheet, AI Influencer) after its price check", () => {
+ const busy = { costUsd: 0, demo: false, notes: [], place: "pool", quote: { allowed: false, amount: 0, priceVersion: "", text: "Busy right now. Try again in a little while." } };
+
+ it("sends nothing only when this studio's GPUs refused the run, in their words", () => {
+ const check = withPoolRefusal(busy as { notes: string[]; error?: string; poolRefused?: boolean });
+ expect(check).toMatchObject({ error: "Busy right now. Try again in a little while.", poolRefused: true });
+ expect(refusedBeforeRun(check)).toBe("Busy right now. Try again in a little while.");
+ });
+
+ it("sends the run for any other error of the check, so the server's refusal opens the connect or add-key card", () => {
+ // The check of an owner on the cloud engine with no key, or an account without its GPU or key: an error, no pool quote.
+ for (const error of ["Connect fal.ai or Replicate in Settings to run this model", "Add your fal.ai key in Settings to run this.", "Connect your GPU in Settings to run this."]) {
+ const check = withPoolRefusal({ costUsd: null, demo: false, notes: [], error } as { notes: string[]; error?: string; poolRefused?: boolean });
+ expect(check.poolRefused).toBeUndefined();
+ expect(refusedBeforeRun(check)).toBeNull();
+ }
+ expect(refusedBeforeRun(withPoolRefusal({ ...busy, quote: { ...busy.quote, allowed: true, text: "Free" } } as { notes: string[]; error?: string }))).toBeNull();
+ expect(refusedBeforeRun(undefined)).toBeNull();
+ });
+
+ it("never stops Run on a refusal from the check of earlier settings, kept on screen while the new one runs", () => {
+ const check = withPoolRefusal(busy as { notes: string[]; error?: string; poolRefused?: boolean });
+ expect(refusedBeforeRun(check, true)).toBeNull();
+ });
+
+ it("is how both pages read their check: no other error stops Run there", async () => {
+ const fs = await import("node:fs");
+ const path = await import("node:path");
+ for (const page of ["src/components/fashion/character-sheet.tsx", "src/components/influencer/influencer-builder.tsx"]) {
+ const src = fs.readFileSync(path.join(__dirname, "..", page), "utf8");
+ expect(src, page).toContain("refusedBeforeRun(preview.data, preview.isPlaceholderData)");
+ expect(src, page).not.toMatch(/if (preview.data?.error) return/);
+ }
+ });
+});