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 run's tile says In line with its place, then Working, then the result

Adarsh2f6bff847adb
diff --git a/src/components/studio/ai-tag.tsx b/src/components/studio/ai-tag.tsx
new file mode 100644
index 00000000..50a82fc8
--- /dev/null
+++ b/src/components/studio/ai-tag.tsx
@@ -0,0 +1,24 @@
+"use client";
+
+import { useHydrated, useStatus } from "@/lib/api";
+import { cn } from "@/lib/utils";
+
+/**
+ * Results carry an "AI-generated" tag where this studio runs visitors' work on its own GPUs (hosted runs on). With
+ * hosted runs off, nothing new shows.
+ */
+export function useAiTag(): boolean {
+ const hydrated = useHydrated();
+ const hosted = !!useStatus().data?.viewer?.hosted;
+ // Once hydrated: the page's first paint is the server's, which knows no status.
+ return hydrated && hosted;
+}
+
+/** The tag itself: a small label over a picture or a clip. */
+export function AiTag({ className }: { className?: string }) {
+ return (
+ <span data-ai-tag className={cn("pointer-events-none rounded-full bg-black/55 px-2 py-0.5 text-[10.5px] font-medium text-white backdrop-blur", className)}>
+ AI-generated
+ </span>
+ );
+}
diff --git a/src/components/studio/feed.tsx b/src/components/studio/feed.tsx
index 0fca3d15..6c6c746c 100644
--- a/src/components/studio/feed.tsx
+++ b/src/components/studio/feed.tsx
@@ -1,10 +1,10 @@
"use client";
import { Cloud, Copy, Cpu, Download, FolderDown, Heart, MoreHorizontal, RotateCcw, Sparkles, Trash2, Wrench, X } from "lucide-react";
-import { lineWords } from "@/lib/hosted";
+import { lineWords } from "@/lib/pool-line";
import { openGpuSetup } from "@/hooks/use-gpu";
import { useLocalJob } from "@/components/gpu/computer-runner";
-import { jobFraction, jobWords } from "@/lib/relay";
+import { jobFraction, jobWords, POOL_WORDS } from "@/lib/relay";
import { createContext, memo, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
import { toast } from "sonner";
import {
@@ -32,6 +32,7 @@ import { PlaceholderChip } from "@/components/demo-mode";
import { Viewer } from "./viewer";
import { NextSteps } from "@/components/nav/next-steps";
import { reservedRowHeight, useArrival, useEnter, useFollowRow, useLiveRun } from "./feed-motion";
+import { AiTag, useAiTag } from "./ai-tag";
export { MediaThumb } from "./result-media";
export { downloadName } from "@/lib/library";
@@ -52,10 +53,20 @@ export function PendingTile({ g, ratio }: { g: Generation; ratio: number }) {
// Its % and time left come from its own steps then, so they agree with "step 9 of 12".
const local = useLocalJob(g.id, now);
useLiveRun(g.id);
- const label = (local && jobWords(local.job, g.kind, g.message ?? undefined, local.comfy)) ?? (g.status === "queued" ? (g.message ?? "Queued") : (g.message ?? "Generating…"));
+ // On this studio's GPUs (hosted runs) a run shows only where it is: "In line" with its place and wait (again after any
+ // recovery, its place kept, with no progress from an earlier attempt), then "Working" with its progress.
+ const pool = g.place === "pool";
+ const inLine = pool && g.status === "queued";
+ const label = pool
+ ? inLine
+ ? g.queue
+ ? lineWords(g.queue)
+ : POOL_WORDS.inLine
+ : (g.message ?? POOL_WORDS.working)
+ : ((local && jobWords(local.job, g.kind, g.message ?? undefined, local.comfy)) ?? (g.status === "queued" ? (g.message ?? "Queued") : (g.message ?? "Generating…")));
const steps = local ? jobFraction(local.job) : null;
const saving = local && (local.job.phase === "saving" || local.job.phase === "done");
- const fraction = local ? (saving ? null : steps) : g.progress;
+ const fraction = local ? (saving ? null : steps) : inLine ? null : g.progress;
const pct = fraction != null ? Math.round(fraction * 100) : null;
// When progress moved (not every poll: each one rewrites updatedAt) gives the pace, so the time left.
// Keyed by id: a chain's tile moves on to its next step's generation.
@@ -71,7 +82,7 @@ export function PendingTile({ g, ratio }: { g: Generation; ratio: number }) {
return (
// max-w-full: in a grid row stretched by a taller neighbour (a card with a footer), h-full + aspect-ratio would
// otherwise make the tile wider than its column and spill over the next card.
- <div className="relative h-full max-w-full overflow-hidden rounded-xl bg-muted" style={{ aspectRatio: ratio }}>
+ <div className="relative h-full max-w-full overflow-hidden rounded-xl bg-muted" style={{ aspectRatio: ratio }} data-run-state={pool ? (inLine ? "in-line" : "working") : undefined}>
<div className="skeleton-sweep absolute inset-0 animate-skeleton" />
{local?.preview && (
// eslint-disable-next-line @next/next/no-img-element -- a live frame from the person's own ComfyUI (a blob: address)
@@ -126,11 +137,19 @@ export function PendingTile({ g, ratio }: { g: Generation; ratio: number }) {
}
export function FailedTile({ g, ratio, onRetry }: { g: Generation; ratio: number; onRetry: () => void }) {
+ // A run on this studio's GPUs that couldn't finish: one plain sentence (the server's), nothing technical.
+ const poolFailed = g.place === "pool" && g.status === "failed";
return (
<div className="flex h-full max-w-full flex-col justify-between rounded-xl border border-dashed bg-background p-3" style={{ aspectRatio: Math.max(ratio, 0.8) }}>
<div className="min-h-0 space-y-1 overflow-hidden">
- <p className="text-[13px] font-medium">{g.status === "canceled" ? "Canceled" : "Couldn't generate this one"}</p>
- {g.error && <p className="line-clamp-5 text-[12px] leading-snug break-words whitespace-pre-line text-muted-foreground">{g.error}</p>}
+ {poolFailed ? (
+ <p className="line-clamp-5 text-[13px] leading-snug font-medium break-words">{g.error || POOL_WORDS.failed}</p>
+ ) : (
+ <>
+ <p className="text-[13px] font-medium">{g.status === "canceled" ? "Canceled" : "Couldn't generate this one"}</p>
+ {g.error && <p className="line-clamp-5 text-[12px] leading-snug break-words whitespace-pre-line text-muted-foreground">{g.error}</p>}
+ </>
+ )}
</div>
<div className="mt-2 flex flex-wrap gap-1.5">
{g.status === "failed" && g.fix && (
@@ -177,6 +196,8 @@ interface FeedApi {
retry: (g: Generation) => void;
runner: RunnerOptions;
reuse?: (g: Generation) => void;
+ /** Pictures and clips carry an "AI-generated" tag (hosted runs on). */
+ aiTag?: boolean;
}
const FeedCtx = createContext<FeedApi | null>(null);
@@ -243,6 +264,7 @@ const OutputTile = memo(function OutputTile({ g, index, ratio, layered, count }:
className={cn("absolute", o.kind === "text" ? "bottom-2" : o.draftId ? "top-11" : "top-2", audio && canHover && "group-focus-within/tile:opacity-0 group-hover/tile:opacity-0 focus-within:opacity-100! has-data-[state=open]:opacity-100!")}
/>
{g.favorite && <Heart className={cn("absolute top-2 right-2 size-4 fill-highlight text-highlight drop-shadow", audio && canHover && "group-focus-within/tile:opacity-0 group-hover/tile:opacity-0")} />}
+ {feed.aiTag && (o.kind === "image" || o.kind === "video") && <AiTag className={cn("absolute bottom-2 left-2", canHover && "transition-opacity group-focus-within/tile:opacity-0 group-hover/tile:opacity-0")} />}
{canHover && hot === "bar" && (
<TileActions
g={g}
@@ -321,7 +343,6 @@ export const GenerationGroup = memo(function GenerationGroup({ g, newest, first
<span className="before:mr-1.5 before:content-['·']">{timeAgo(g.createdAt)}</span>
{/* A run its provider never took (a refused key, an empty balance) cost nothing: said, not priced. */}
{/* On this studio's GPUs (hosted runs): the billing service's words for its charge, or that it cost nothing. */}
- {g.queue ? <span className="before:mr-1.5 before:content-['·']">{lineWords(g.queue)}</span> : null}
{g.stage === "checking" ? <span className="before:mr-1.5 before:content-['·']">Checking</span> : null}
{g.place === "pool" ? (
g.notCharged ? (
@@ -444,6 +465,7 @@ export function Feed({
reuseRef.current = onReuse;
});
const hasReuse = !!onReuse;
+ const aiTag = useAiTag();
const openAt = useCallback((g: Generation, index: number) => setOpen({ id: g.id, index }), []);
const api = useMemo<FeedApi>(
() => ({
@@ -451,8 +473,9 @@ export function Feed({
retry: (g) => createRef.current.mutate(g.request, { onError: (e) => toastError(e) }),
reuse: hasReuse ? (g) => reuseRef.current?.(g) : undefined,
runner: { onOpen: openAt, onReuse: hasReuse ? (g) => reuseRef.current?.(g) : undefined },
+ ...(aiTag && { aiTag }),
}),
- [openAt, hasReuse],
+ [openAt, hasReuse, aiTag],
);
if (!items.length) return <>{empty}</>;
// The feed is newest first: the next steps go under the first finished result.
diff --git a/src/components/studio/viewer.tsx b/src/components/studio/viewer.tsx
index a5ecdaed..614db192 100644
--- a/src/components/studio/viewer.tsx
+++ b/src/components/studio/viewer.tsx
@@ -23,6 +23,7 @@ import { LayersStack, ModelViewer, TextReader, VideoFileCard } from "./result-me
import { ReviewSelect } from "@/components/library/review";
import { PlaceholderChip } from "@/components/demo-mode";
import { NextSteps } from "@/components/nav/next-steps";
+import { AiTag, useAiTag } from "./ai-tag";
/** One line of the details; `center` lines the label up with a control (the Review picker) instead of a text value's first line. */
@@ -59,6 +60,7 @@ function metaText(o: OutputFile | undefined, key: string): string | undefined {
function Details({ g, index }: { g: Generation; index: number }) {
const p = g.request.params ?? {};
const title = userTitle(g);
+ const aiTag = useAiTag();
if (g.feature === "upload") {
return (
<div className="space-y-4">
@@ -75,6 +77,7 @@ function Details({ g, index }: { g: Generation; index: number }) {
<div className="space-y-4">
<div>
<p className="font-heading text-[20px] leading-snug">{title}</p>
+ {aiTag && <AiTag className="mt-1.5 inline-block bg-muted text-muted-foreground backdrop-blur-none" />}
{g.prompt && g.prompt !== title && <p className="mt-1 line-clamp-6 text-[12px] leading-relaxed break-words text-muted-foreground">{g.modelId === "local-motion" ? "Words" : "Sent to the model"}: {g.prompt}</p>}
{g.prompt && (
<button
@@ -87,7 +90,7 @@ function Details({ g, index }: { g: Generation; index: number }) {
</div>
<div className="divide-y rounded-lg border px-3">
<Row label="Model" value={g.modelName ?? g.modelId} />
- <Row label="Made on" value={g.provider === "mock" ? "Placeholder" : g.provider === "local" ? "In your browser" : g.engine === "open" ? "Your GPU" : "Cloud"} />
+ <Row label="Made on" value={g.provider === "mock" ? "Placeholder" : g.provider === "local" ? "In your browser" : g.place === "pool" ? "This studio" : g.engine === "open" ? "Your GPU" : "Cloud"} />
<Row label="Mode" value={OPERATION_LABELS[g.op]} />
<Row label={g.modelId.startsWith("fuobe-soul") ? "Look" : "Preset"} value={g.presetName} />
<Row label="Finish" value={finishText(g.outputs[index])} />
diff --git a/tests/hosted-price-check.test.ts b/tests/hosted-price-check.test.ts
index 9010cc01..a98a4524 100644
--- a/tests/hosted-price-check.test.ts
+++ b/tests/hosted-price-check.test.ts
@@ -1,12 +1,14 @@
import http from "node:http";
-import { afterAll, beforeAll, beforeEach, describe, expect, it } from "vitest";
+import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import { FAKE_POLICY, listenInRange, startFakeBilling, type FakeBilling } from "./helpers/fake-billing";
import { startFakeComfy, type FakeComfy } from "./helpers/fake-comfy-runner";
import { tempDir } from "./helpers/temp-dir";
// The price check before Run (`?preview=1`) on hosted runs: where a new run would stand in line and the wait, and a
// refusal (busy, a limit, a model or files this install's GPUs don't take) said before Run is pressed, in the words the
-// run itself would get. With hosted runs off the answer is as before.
+// run itself would get. A run's state reads the same from the list and from its own route (a refresh, a second
+// device). With hosted runs off every answer is as before.
+vi.mock("next/server", async (importOriginal) => ({ ...(await importOriginal<typeof import("next/server")>()), connection: async () => {} }));
const dir = tempDir("fuobe-hosted-price-check-");
process.env.FUOBE_DATA_DIR = dir;
process.env.FUOBE_PUBLIC_SIGNUP = "1";
@@ -25,6 +27,8 @@ process.env.COMFYUI_URL = comfy.url;
const auth = await import("@/server/auth");
const generationsRoute = await import("@/app/api/generations/route");
+const oneRoute = await import("@/app/api/generations/[id]/route");
+const { POOL_WORDS } = await import("@/lib/relay");
const { db } = await import("@/server/db");
const { resetRates } = await import("@/server/rate");
const billing = await import("@/server/billing");
@@ -184,3 +188,31 @@ describe("the price check with hosted runs on", () => {
});
});
+describe("a run's state after a refresh or on a second device", () => {
+ beforeEach(() => {
+ process.env.FUOBE_HOSTED_RUNS = "1";
+ process.env.FUOBE_HOSTED_FREE = "1";
+ });
+ const list = async () => {
+ const r = await generationsRoute.GET(new Request("http://localhost:3000/api/generations", { headers: { host: "localhost:3000", cookie } }));
+ return ((await r.json()) as { items: Record<string, unknown>[] }).items;
+ };
+ const one = async (id: string) => (await (await oneRoute.GET(new Request(`http://localhost:3000/api/generations/${id}`), { params: Promise.resolve({ id }) } as never)).json()) as Record<string, unknown>;
+ const state = (g: Record<string, unknown> | undefined) => g && { status: g.status, message: g.message, progress: g.progress, queue: g.queue ?? null, place: g.place };
+
+ it("the list and the run's own route say the same: In line with its place, then Working with its progress", async () => {
+ waitingRun(other);
+ const id = waitingRun(a);
+ const listed = state((await list()).find((g) => g.id === id));
+ expect(listed).toEqual({ status: "queued", message: POOL_WORDS.inLine, progress: null, queue: { place: 2, etaSeconds: null }, place: "pool" });
+ expect(state(await one(id))).toEqual(listed);
+ // A worker has it: Working, with its progress, and no place in line.
+ const now = Date.now();
+ db().prepare("INSERT INTO generation_runs (id, submitted_at, started_at) VALUES (?, ?, ?)").run(id, now, now);
+ db().prepare("UPDATE generations SET status = 'running', progress = 0.5 WHERE id = ?").run(id);
+ const working = state((await list()).find((g) => g.id === id));
+ expect(working).toEqual({ status: "running", message: POOL_WORDS.working, progress: 0.5, queue: null, place: "pool" });
+ expect(state(await one(id))).toEqual(working);
+ });
+});
+
diff --git a/tests/hosted-run-tiles.test.ts b/tests/hosted-run-tiles.test.ts
new file mode 100644
index 00000000..0823da73
--- /dev/null
+++ b/tests/hosted-run-tiles.test.ts
@@ -0,0 +1,91 @@
+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
+import { createElement, type ReactNode } from "react";
+import { renderToStaticMarkup } from "react-dom/server";
+import { describe, expect, it, vi } from "vitest";
+import type { Generation } from "@/lib/catalog/types";
+
+/*
+ * A run's tile on this studio's GPUs (hosted runs): "In line" with its place and wait (again after any recovery, its
+ * place kept), "Working" with its progress, then the result with an "AI-generated" tag, or one plain sentence when it
+ * can't finish. Every other run's tiles render as before.
+ */
+
+vi.mock("next/navigation", () => ({
+ useRouter: () => ({ prefetch: () => {}, push: () => {}, replace: () => {}, back: () => {}, refresh: () => {} }),
+ usePathname: () => "/image",
+ useSearchParams: () => new URLSearchParams(),
+}));
+
+const { POOL_WORDS } = await import("@/lib/relay");
+const { PendingTile, FailedTile } = await import("@/components/studio/feed");
+const { AiTag } = await import("@/components/studio/ai-tag");
+const { TooltipProvider } = await import("@/components/ui/tooltip");
+
+const render = (node: ReactNode) => renderToStaticMarkup(createElement(QueryClientProvider, { client: new QueryClient() }, createElement(TooltipProvider, null, node)));
+
+const gen = (o: Partial<Generation> = {}): Generation =>
+ ({
+ id: "g1",
+ batchId: null,
+ feature: "image",
+ presetId: null,
+ modelId: "oss-z-image-turbo",
+ engine: "open",
+ provider: "comfyui",
+ op: "t2i",
+ kind: "image",
+ status: "queued",
+ progress: null,
+ message: null,
+ prompt: "a fox",
+ request: { feature: "image", modelId: "oss-z-image-turbo", prompt: "a fox" },
+ outputs: [],
+ error: null,
+ costUsd: null,
+ favorite: false,
+ createdAt: Date.now(),
+ updatedAt: Date.now(),
+ completedAt: null,
+ ...o,
+ }) as Generation;
+
+describe("a run's tile on this studio's GPUs", () => {
+ it("in line: its place and wait, no progress (after a recovery too, whatever an earlier attempt reached)", () => {
+ const html = render(createElement(PendingTile, { g: gen({ place: "pool", status: "queued", message: POOL_WORDS.inLine, progress: 0.6, queue: { place: 3, etaSeconds: 130 } }), ratio: 1 }));
+ expect(html).toContain('data-run-state="in-line"');
+ expect(html).toContain("In line · 3rd · about 2 min");
+ expect(html).not.toContain("60%");
+ expect(html).not.toContain("scaleX");
+ });
+ it("in line with no place known yet: In line", () => {
+ const html = render(createElement(PendingTile, { g: gen({ place: "pool", status: "queued", message: POOL_WORDS.inLine }), ratio: 1 }));
+ expect(html).toContain(">In line<");
+ });
+ it("working: Working, with its progress", () => {
+ const html = render(createElement(PendingTile, { g: gen({ place: "pool", status: "running", message: POOL_WORDS.working, progress: 0.4 }), ratio: 1 }));
+ expect(html).toContain('data-run-state="working"');
+ expect(html).toContain(">Working<");
+ expect(html).toContain("40%");
+ });
+ it("a run that can't finish: one plain sentence, and Retry", () => {
+ const html = render(createElement(FailedTile, { g: gen({ place: "pool", status: "failed", error: POOL_WORDS.failed, notCharged: true }), ratio: 1, onRetry: () => {} }));
+ expect(html).toContain(POOL_WORDS.failed.replace("'", "&#x27;"));
+ expect(html).not.toContain("Couldn&#x27;t generate this one");
+ expect(html).toContain("Retry");
+ });
+ it("every other run's tiles are as before", () => {
+ const own = render(createElement(PendingTile, { g: gen({ status: "running", message: "Generating", progress: 0.4 }), ratio: 1 }));
+ expect(own).not.toContain("data-run-state");
+ expect(own).toContain("Generating");
+ expect(own).toContain("40%");
+ const queued = render(createElement(PendingTile, { g: gen({ status: "queued", progress: 0.4 }), ratio: 1 }));
+ expect(queued).toContain(">Queued<");
+ const failed = render(createElement(FailedTile, { g: gen({ status: "failed", error: "Your ComfyUI answered HTTP 500." }), ratio: 1, onRetry: () => {} }));
+ expect(failed).toContain("Couldn&#x27;t generate this one");
+ expect(failed).toContain("Your ComfyUI answered HTTP 500.");
+ });
+ it("the AI-generated tag", () => {
+ expect(render(createElement(AiTag))).toContain("AI-generated");
+ });
+});
+