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
Studio and Library: a run on its way always shows a ring, its words and its place
Adarsh684deb7738e6
diff --git a/src/components/library/asset-card.tsx b/src/components/library/asset-card.tsxindex 67da452d..bf960f16 100644--- a/src/components/library/asset-card.tsx+++ b/src/components/library/asset-card.tsx@@ -1,6 +1,6 @@"use client";-import { Check, ChevronDown, Heart, Layers, MoreHorizontal, Pin, RotateCcw } from "lucide-react";+import { Check, ChevronDown, Heart, Layers, Loader2, MoreHorizontal, Pin, RotateCcw } from "lucide-react";import { memo, useMemo, useState } from "react";import { tileRatio } from "@/components/studio/feed";import { TileActions, useCanHover, type RunnerOptions } from "@/components/studio/result-actions";@@ -9,7 +9,7 @@ import { OPERATION_LABELS, type Generation } from "@/lib/catalog/types";import { elapsed, timeAgo } from "@/lib/format";import { cardStateWords, coverOf, trashDaysLeft, userTitle, type LibraryEntry } from "@/lib/library";import { isLayered, shownOutputs } from "@/lib/output-actions";-import { lineWords } from "@/lib/pool-line";+import { pendingWords } from "@/lib/pending-words";import { POOL_WORDS } from "@/lib/relay";import { cn } from "@/lib/utils";import { PlaceholderChip } from "@/components/demo-mode";@@ -63,14 +63,18 @@ export function StatusCover({ g, small, actionable }: { g: Generation; small?: bconst pool = g.place === "pool";if (g.status === "queued" || g.status === "running") {const pct = g.progress != null ? Math.round(g.progress * 100) : null;- const label = pool ? (g.status === "queued" ? (g.queue ? lineWords(g.queue) : POOL_WORDS.inLine) : (g.message ?? POOL_WORDS.working)) : (g.message ?? (g.status === "queued" ? "Queued" : "Generating…"));+ const { label, place } = pendingWords(g);const waiting = g.status === "queued" ? g.waiting : undefined;return (<div className="relative size-full bg-muted"><div className="skeleton-sweep absolute inset-0 animate-skeleton" />{!small && (<div className="absolute inset-x-0 bottom-0 space-y-1 p-3">- <p className="shimmer-text animate-shimmer-text truncate text-[13px] font-medium">{label}</p>+ <p className="flex items-center gap-1.5 text-[13px] font-medium">+ <Loader2 aria-hidden data-run-spinner className="size-3.5 shrink-0 animate-spin text-muted-foreground motion-reduce:animate-none" />+ <span className="shimmer-text animate-shimmer-text truncate">{label}</span>+ </p>+ {place && <p className="truncate text-[11px] text-muted-foreground">{place}</p>}<p className="font-mono text-[11px] text-muted-foreground">{pct != null ? `${pct}% · ` : ""}{elapsed(g.createdAt)}diff --git a/src/components/studio/feed.tsx b/src/components/studio/feed.tsxindex 75fa92bc..48497523 100644--- a/src/components/studio/feed.tsx+++ b/src/components/studio/feed.tsx@@ -1,8 +1,8 @@"use client";-import { Cloud, Copy, Cpu, Download, FolderDown, Heart, MoreHorizontal, RotateCcw, Sparkles, Trash2, Wrench, X } from "lucide-react";+import { Cloud, Copy, Cpu, Download, FolderDown, Heart, Loader2, MoreHorizontal, RotateCcw, Sparkles, Trash2, Wrench, X } from "lucide-react";import { useQueryClient } from "@tanstack/react-query";-import { lineWords } from "@/lib/pool-line";+import { pendingWords } from "@/lib/pending-words";import { refreshPriceChecks } from "@/lib/hosted";import { openGpuSetup } from "@/hooks/use-gpu";import { useLocalJob } from "@/components/gpu/computer-runner";@@ -91,13 +91,7 @@ export function PendingTile({ g, ratio }: { g: Generation; ratio: number }) {// so a refusal for runs going (or the line's wait) doesn't outlast it.const qc = useQueryClient();useEffect(() => (pool ? () => refreshPriceChecks(qc) : undefined), [pool, qc]);- 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 { label, place } = pendingWords(g, local && jobWords(local.job, g.kind, g.message ?? undefined, local.comfy));const steps = local ? jobFraction(local.job) : null;const saving = local && (local.job.phase === "saving" || local.job.phase === "done");const fraction = local ? (saving ? null : steps) : inLine ? null : g.progress;@@ -136,9 +130,16 @@ export function PendingTile({ g, ratio }: { g: Generation; ratio: number }) {)}<div className={cn("absolute inset-x-0 bottom-0 flex items-end justify-between gap-2 p-3", frame && "bg-gradient-to-t from-background/85 to-transparent pt-8")}><div className="min-w-0">- <p title={label} className="shimmer-text animate-shimmer-text line-clamp-2 text-[13px] font-medium">- {label}+ {/* Always a sign it is on its way (a turning ring), with the run's own words beside it. */}+ <p title={label} className="flex items-start gap-1.5 text-[13px] font-medium">+ <Loader2 aria-hidden data-run-spinner className="mt-0.5 size-3.5 shrink-0 animate-spin text-muted-foreground motion-reduce:animate-none" />+ <span className="shimmer-text animate-shimmer-text line-clamp-2">{label}</span></p>+ {place && (+ <p title={place} className="line-clamp-2 text-[11px] text-muted-foreground">+ {place}+ </p>+ )}{where && (<p title={where} className="line-clamp-2 text-[11px] text-muted-foreground">{where}diff --git a/src/lib/pending-words.ts b/src/lib/pending-words.tsnew file mode 100644index 00000000..5ea1f0ec--- /dev/null+++ b/src/lib/pending-words.ts@@ -0,0 +1,24 @@+import type { Generation } from "./catalog/types";+import { lineWords } from "./pool-line";+import { POOL_WORDS } from "./relay";++/** Words that already say a run's place ("Waiting for a GPU · 1 ahead", "Next for a GPU", "In ComfyUI's queue"). */+const SAYS_PLACE = /\bahead\b|\bnext\b|\bin line\b|queue/i;++/**+ * What a run on its way says on its tile or cover: its words (never empty: a blank or missing message reads "Queued" or+ * "Generating…"), and, for a run waiting for the workers whose words don't say it already, its place in their line+ * ("Next in line", "In line · 3rd · ready in about 2 min"). `local`: the words of its job on the ComfyUI on this+ * computer, when it runs there. On this studio's GPUs (hosted runs) only "In line" with its place, then "Working".+ */+export function pendingWords(g: Pick<Generation, "status" | "message" | "place" | "queue">, local?: string | null): { label: string; place: string | null } {+ const message = g.message?.trim() || null;+ if (g.place === "pool") {+ if (g.status === "queued") return { label: g.queue ? lineWords(g.queue) : POOL_WORDS.inLine, place: null };+ return { label: message ?? POOL_WORDS.working, place: null };+ }+ if (local) return { label: local, place: null };+ const label = message ?? (g.status === "queued" ? "Queued" : "Generating…");+ const place = g.status === "queued" && g.queue && !SAYS_PLACE.test(label) ? lineWords(g.queue) : null;+ return { label, place };+}diff --git a/tests/golden/self-host/feed-tiles.html b/tests/golden/self-host/feed-tiles.htmlindex 119fd5d4..66ca6780 100644--- a/tests/golden/self-host/feed-tiles.html+++ b/tests/golden/self-host/feed-tiles.html@@ -3,7 +3,13 @@</div><div class="absolute inset-x-0 bottom-0 flex items-end justify-between gap-2 p-3"><div class="min-w-0">-<p title="Queued" class="shimmer-text animate-shimmer-text line-clamp-2 text-[13px] font-medium">Queued</p>+<p title="Queued" class="flex items-start gap-1.5 text-[13px] font-medium">+<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-loader-circle lucide-loader-2 mt-0.5 size-3.5 shrink-0 animate-spin text-muted-foreground motion-reduce:animate-none" aria-hidden="true" data-run-spinner="true">+<path d="M21 12a9 9 0 1 1-6.219-8.56">+</path>+</svg>+<span class="shimmer-text animate-shimmer-text line-clamp-2">Queued</span>+</p><p class="flex flex-wrap gap-x-1.5 font-mono text-[11px] text-muted-foreground tabular-nums"><span class="">1m 30s</span></p>@@ -24,7 +30,13 @@</div><div class="absolute inset-x-0 bottom-0 flex items-end justify-between gap-2 p-3"><div class="min-w-0">-<p title="Generating" class="shimmer-text animate-shimmer-text line-clamp-2 text-[13px] font-medium">Generating</p>+<p title="Generating" class="flex items-start gap-1.5 text-[13px] font-medium">+<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-loader-circle lucide-loader-2 mt-0.5 size-3.5 shrink-0 animate-spin text-muted-foreground motion-reduce:animate-none" aria-hidden="true" data-run-spinner="true">+<path d="M21 12a9 9 0 1 1-6.219-8.56">+</path>+</svg>+<span class="shimmer-text animate-shimmer-text line-clamp-2">Generating</span>+</p><p class="flex flex-wrap gap-x-1.5 font-mono text-[11px] text-muted-foreground tabular-nums"><span>42%</span><span class="before:mr-1.5 before:content-['·']">1m 30s</span>diff --git a/tests/golden/self-host/library-cover.html b/tests/golden/self-host/library-cover.htmlindex 26dcc51d..a77f7e4a 100644--- a/tests/golden/self-host/library-cover.html+++ b/tests/golden/self-host/library-cover.html@@ -2,7 +2,13 @@<div class="skeleton-sweep absolute inset-0 animate-skeleton"></div><div class="absolute inset-x-0 bottom-0 space-y-1 p-3">-<p class="shimmer-text animate-shimmer-text truncate text-[13px] font-medium">Queued</p>+<p class="flex items-center gap-1.5 text-[13px] font-medium">+<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-loader-circle lucide-loader-2 size-3.5 shrink-0 animate-spin text-muted-foreground motion-reduce:animate-none" aria-hidden="true" data-run-spinner="true">+<path d="M21 12a9 9 0 1 1-6.219-8.56">+</path>+</svg>+<span class="shimmer-text animate-shimmer-text truncate">Queued</span>+</p><p class="font-mono text-[11px] text-muted-foreground">1m 30s</p></div></div>@@ -11,7 +17,13 @@<div class="skeleton-sweep absolute inset-0 animate-skeleton"></div><div class="absolute inset-x-0 bottom-0 space-y-1 p-3">-<p class="shimmer-text animate-shimmer-text truncate text-[13px] font-medium">Generating</p>+<p class="flex items-center gap-1.5 text-[13px] font-medium">+<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-loader-circle lucide-loader-2 size-3.5 shrink-0 animate-spin text-muted-foreground motion-reduce:animate-none" aria-hidden="true" data-run-spinner="true">+<path d="M21 12a9 9 0 1 1-6.219-8.56">+</path>+</svg>+<span class="shimmer-text animate-shimmer-text truncate">Generating</span>+</p><p class="font-mono text-[11px] text-muted-foreground">42% · 1m 30s</p></div></div>diff --git a/tests/pending-run-tiles.test.ts b/tests/pending-run-tiles.test.tsnew file mode 100644index 00000000..fd172bce--- /dev/null+++ b/tests/pending-run-tiles.test.ts@@ -0,0 +1,119 @@+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 on its way never shows a blank tile: in the studio feed and on a Library card it has a turning ring, its own+ * words (a blank message reads "Queued" or "Generating…"), and, while it waits for the workers, its place in their line+ * when its words don't say it already. The owner's jobs on the workers, a step waiting for the steps before it, and+ * runs on this studio's GPUs (hosted runs) alike.+ */++vi.mock("next/navigation", () => ({+ useRouter: () => ({ prefetch: () => {}, push: () => {}, replace: () => {}, back: () => {}, refresh: () => {} }),+ usePathname: () => "/image",+ useSearchParams: () => new URLSearchParams(),+}));++const { POOL_WORDS } = await import("@/lib/relay");+const { pendingWords } = await import("@/lib/pending-words");+const { PendingTile, Feed } = await import("@/components/studio/feed");+const { StatusCover } = await import("@/components/library/asset-card");+const { TooltipProvider } = await import("@/components/ui/tooltip");++const render = (node: ReactNode) => renderToStaticMarkup(createElement(QueryClientProvider, { client: new QueryClient() }, createElement(TooltipProvider, null, node)));+const text = (html: string) => html.replace(/<[^>]+>/g, " ").replace(/'/g, "'").replace(/\s+/g, " ");++const gen = (o: Partial<Generation> = {}): Generation =>+ ({+ id: "g1",+ batchId: null,+ feature: "image",+ presetId: null,+ modelId: "oss-qwen-image-21",+ engine: "open",+ provider: "comfyui",+ op: "edit",+ kind: "image",+ status: "queued",+ progress: null,+ message: null,+ prompt: "a model in a red coat",+ request: { feature: "image", modelId: "oss-qwen-image-21", prompt: "a model in a red coat" },+ outputs: [],+ error: null,+ costUsd: null,+ favorite: false,+ createdAt: Date.now(),+ updatedAt: Date.now(),+ completedAt: null,+ ...o,+ }) as Generation;++/** The tile of one run as the studio feed draws it (its group: the prompt, then the tile). */+const feedTile = (g: Generation) => render(createElement(Feed, { items: [g] }));++describe("a run on its way in the studio feed", () => {+ it("the owner's job waiting for the workers: a ring, its words with its place, and the time it has waited", () => {+ const html = feedTile(gen({ status: "queued", message: "Waiting for a GPU · 1 ahead", queue: { place: 2, etaSeconds: 90 } }));+ expect(html).toContain("data-run-spinner");+ expect(text(html)).toContain("Waiting for a GPU · 1 ahead");+ // Its words say its place already: not said twice.+ expect(text(html)).not.toContain("In line · 2nd");+ expect(text(html)).toMatch(/\d+s/);+ });++ it("the owner's job waiting with words that don't say its place: its place in the workers' line under them", () => {+ const html = feedTile(gen({ status: "queued", message: "Waiting for a GPU to come on", queue: { place: 3, etaSeconds: 130 } }));+ expect(text(html)).toContain("Waiting for a GPU to come on");+ expect(text(html)).toContain("In line · 3rd · ready in about 2 min");+ const next = feedTile(gen({ status: "queued", message: "Submitting", queue: { place: 1, etaSeconds: null, unknown: true } }));+ expect(text(next)).toContain("Next in line · starts when a GPU is free");+ });++ it("the owner's job running on a worker: a ring, its step words and its progress", () => {+ const html = feedTile(gen({ status: "running", message: "Making your picture · step 3 of 8", progress: 0.375 }));+ expect(html).toContain("data-run-spinner");+ expect(text(html)).toContain("Making your picture · step 3 of 8");+ expect(text(html)).toContain("38%");+ expect(html).toContain("scaleX(0.38)");+ });++ it("a step waiting for the steps before it: a ring and its words", () => {+ const html = feedTile(gen({ kind: "video", op: "i2v", status: "queued", message: "Waits for the earlier steps", request: { feature: "video", modelId: "oss-minimax-h3", prompt: "she turns" } }));+ expect(html).toContain("data-run-spinner");+ expect(text(html)).toContain("Waits for the earlier steps");+ });++ it("a blank or missing message still says something", () => {+ for (const message of [null, "", " "]) {+ expect(text(render(createElement(PendingTile, { g: gen({ status: "queued", message }), ratio: 1 })))).toContain("Queued");+ expect(text(render(createElement(PendingTile, { g: gen({ status: "running", message }), ratio: 1 })))).toContain("Generating…");+ }+ });++ it("runs on this studio's GPUs keep their words, now with the ring too", () => {+ const html = render(createElement(PendingTile, { g: gen({ place: "pool", status: "queued", message: POOL_WORDS.inLine, queue: { place: 3, etaSeconds: 130 } }), ratio: 1 }));+ expect(html).toContain("data-run-spinner");+ expect(text(html)).toContain("In line · 3rd · ready in about 2 min");+ expect(pendingWords({ place: "pool", status: "running", message: "", queue: undefined })).toEqual({ label: POOL_WORDS.working, place: null });+ });++ it("a job on this computer's ComfyUI says its own words", () => {+ expect(pendingWords(gen({ status: "queued", message: "Submitting", queue: { place: 2, etaSeconds: 10 } }), "In ComfyUI's queue · 1 ahead")).toEqual({ label: "In ComfyUI's queue · 1 ahead", place: null });+ });+});++describe("a run on its way on a Library card", () => {+ it("the same ring, words and place", () => {+ const waiting = render(createElement(StatusCover, { g: gen({ status: "queued", message: "Waiting for a GPU to come on", queue: { place: 1, etaSeconds: null, unknown: true } }) }));+ expect(waiting).toContain("data-run-spinner");+ expect(text(waiting)).toContain("Waiting for a GPU to come on");+ expect(text(waiting)).toContain("Next in line · starts when a GPU is free");+ const running = render(createElement(StatusCover, { g: gen({ status: "running", message: "Making your picture · step 3 of 8", progress: 0.375 }) }));+ expect(text(running)).toContain("Making your picture · step 3 of 8");+ expect(text(render(createElement(StatusCover, { g: gen({ status: "queued", message: "" }) })))).toContain("Queued");+ });+});