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
Top bar: the balance pill says where runs go and opens its choice
Adarshdf7fbf5a88db
diff --git a/src/components/nav/status-chips.tsx b/src/components/nav/status-chips.tsxindex 80427062..7fdbde46 100644--- a/src/components/nav/status-chips.tsx+++ b/src/components/nav/status-chips.tsx@@ -2,23 +2,26 @@import dynamic from "next/dynamic";import { cloneElement } from "react";-import { Cpu } from "lucide-react";+import { ChevronDown, Cpu, KeyRound, Server } from "lucide-react";import { PlaceholdersOnChip } from "@/components/demo-mode";import { IntentLink } from "@/components/intent-link";import { awayFix, openConnect, useComputerSupport } from "@/components/gpu/open-connect";import { usePagePlace } from "@/components/gpu/use-page-place";import { useHadItems } from "@/components/use-had-items";-import { DropdownMenu, DropdownMenuContent, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";+import { DropdownMenu, DropdownMenuContent, DropdownMenuLabel, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";import { Skeleton } from "@/components/ui/skeleton";+import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";import { ownGpuOf, signInHref, useEngineMode, useHydrated, useStatus, useViewer, type EngineMode, type StatusInfo } from "@/lib/api";import { placeholdersOn } from "@/lib/demo-mode";import { deviceLabel } from "@/lib/gpu/readiness";import { shortState } from "@/lib/diagnose";import { safeLink, useInterest } from "@/lib/hosted";import type { ViewerKind } from "@/lib/nav-model";+import { barRuns, type BarRuns, type RunOnPick } from "@/lib/run-place";+import { useSetRunOn } from "@/lib/run-on";import { cn } from "@/lib/utils";-import { MENU_ROW_1, NavMenuItem } from "./nav-row";+import { MENU_HEADING, MENU_ROW_1, MENU_ROW_2, NavMenuItem, ROW_LINE, ROW_NAME } from "./nav-row";/** What the sidebar's footer said about GPUs, keys and balance, moved here unchanged in what it says and to whom: the@@ -144,12 +147,13 @@ export function refillWords(at: number, now = Date.now()): string {* The balance's menu items (a studio with a billing service, src/server/billing.ts): the service's own words for what* the account has left, its detail lines, its links, its offer, and the way to run for free on one's own GPU or keys.*/-function BalanceItems({ viewer }: { viewer: Viewer }) {+function BalanceItems({ viewer, runs }: { viewer: Viewer; runs?: BarRuns }) {const b = viewer.balance!;const interest = useInterest();const action = safeLink(b.action?.url);return (<>+ {runs && <RunsChoice viewer={viewer} runs={runs} />}<DropdownMenuLabel className="px-2.5 text-[12px] font-normal text-muted-foreground">{b.text}</DropdownMenuLabel>{b.detail.map((d, i) => (<div key={i} className="flex justify-between gap-3 px-2.5 py-1 text-[12px]">@@ -191,40 +195,110 @@ function BalanceItems({ viewer }: { viewer: Viewer }) {*/export const balanceGoes = (b: Pick<NonNullable<Viewer["balance"]>, "amount" | "refillAt" | "offer" | "action">): boolean => b.amount > 0 || (!b.refillAt && !b.offer && !b.action);-function balanceLabel(viewer: Viewer): { chip: string; refill: string | null } {+function balanceLabel(viewer: Viewer): { refill: string | null; runs: BarRuns } {const b = viewer.balance!;- return { chip: b.chip, refill: b.refillAt ? refillWords(b.refillAt) : null };+ const refill = b.refillAt ? refillWords(b.refillAt) : null;+ return { refill, runs: barRuns(viewer, b.chip, refill) };+}++const RUNS_ICON: Record<RunOnPick, typeof Cpu> = { site: Server, gpu: Cpu, key: KeyRound };++/** Green while runs go where they are sent: the balance has some (or runs are free), its GPU answers, or its key. */+const runsGo = (viewer: Viewer, on: RunOnPick): boolean => (on === "site" ? balanceGoes(viewer.balance!) : on === "gpu" ? !!viewer.gpu.online : true);++/** The menu's first section: where the runs go, and a pick of the place when the account has its own GPU or key. */+function RunsChoice({ viewer, runs }: { viewer: Viewer; runs: BarRuns }) {+ const setRunOn = useSetRunOn();+ const row = (Icon: typeof Cpu, name: string, sub: string, online?: boolean) => (+ <>+ <Icon aria-hidden className="size-4 text-muted-foreground" />+ <span className="flex min-w-0 flex-col">+ <span className={ROW_NAME}>{name}</span>+ <span className={cn(ROW_LINE, "flex items-center gap-1.5")}>+ {online && <StatusDot ok />}+ <span className="truncate">{sub}</span>+ </span>+ </span>+ </>+ );+ return (+ <>+ <DropdownMenuLabel className={MENU_HEADING}>Where your runs go</DropdownMenuLabel>+ {runs.rows ? (+ <DropdownMenuRadioGroup value={runs.on} onValueChange={(id) => setRunOn.mutate({ runOn: id as RunOnPick, ...(id === "key" && runs.key && { key: runs.key }) })}>+ {runs.rows.map((r) => (+ <DropdownMenuRadioItem key={r.id} value={r.id} disabled={setRunOn.isPending} className={cn("nav-row gap-3 rounded-[10px] pl-2.5 text-[13.5px]", MENU_ROW_2)}>+ {row(RUNS_ICON[r.id], r.label, r.sub, r.online)}+ </DropdownMenuRadioItem>+ ))}+ </DropdownMenuRadioGroup>+ ) : (+ <div className={cn("flex items-center gap-3 px-2.5", MENU_ROW_2)}>{row(RUNS_ICON[runs.on], runs.short, viewer.balance!.chip)}</div>+ )}+ <DropdownMenuSeparator className="mx-2.5 my-1.5" />+ </>+ );}/**- * The balance chip with its own menu. `pill`: the bar's compact form (one line, 36 px); otherwise the footer-style block- * (the You sheet, and inside the account menu it is a submenu-free block with the same items).+ * The balance chip with its own menu: where the runs go and at what price ("Free · Our GPUs"), a caret, and a tooltip.+ * `pill`: the bar's compact form (one line, 36 px; the place alone below xl); otherwise the footer-style block (the You+ * sheet, and inside the account menu it is a submenu-free block with the same items).*/export function BalanceChip({ viewer, pill, className }: { viewer: Viewer; pill?: boolean; className?: string }) {const b = viewer.balance!;- const { chip, refill } = balanceLabel(viewer);+ const { refill, runs } = balanceLabel(viewer);+ const Icon = RUNS_ICON[runs.on];+ const icon = <Icon aria-hidden className={cn("size-4 shrink-0", runsGo(viewer, runs.on) ? "text-success" : "text-muted-foreground")} />;+ const caret = <ChevronDown aria-hidden className="size-3.5 shrink-0 opacity-70 motion-safe:transition-transform group-aria-expanded/runs:rotate-180" />;return (<DropdownMenu>- <DropdownMenuTrigger asChild>- <button- type="button"- aria-label={`${chip}${refill ? `, ${refill}` : ""}`}- className={cn(- pill- ? "inline-flex h-9 max-w-56 items-center gap-2 rounded-full [@media(pointer:coarse)]:h-11 border border-sidebar-border px-3 text-[12.5px] text-muted-foreground nav-row"- : cn(CHIP, "-mx-2 rounded-xl px-2"),- className,- )}- >- <span className={cn("flex min-w-0 items-center", pill ? "gap-2" : "gap-3")}>- {pill ? <StatusDot ok={balanceGoes(b)} /> : <DotSlot ok={balanceGoes(b)} />} <span className="truncate font-medium text-foreground">{chip}</span>- {refill && <span className={cn("ml-auto shrink-0", pill && "hidden xl:inline")}>{refill}</span>}- </span>- {!pill && b.sub && <span className="truncate pl-7 text-[11px]">{b.sub}</span>}- </button>- </DropdownMenuTrigger>- <DropdownMenuContent side={pill ? "bottom" : "top"} align={pill ? "end" : "start"} className="w-64">- <BalanceItems viewer={viewer} />+ <Tooltip>+ <TooltipTrigger asChild>+ <DropdownMenuTrigger asChild>+ <button+ type="button"+ aria-label={`${runs.tip}. Change`}+ data-runs={runs.on}+ className={cn(+ "group/runs",+ pill+ ? "inline-flex h-9 items-center gap-1.5 rounded-full border border-sidebar-border pr-2.5 pl-3 text-[12.5px] font-medium text-foreground/85 nav-row nav-hover:border-border-strong nav-hover:text-foreground aria-expanded:border-border-strong aria-expanded:text-foreground [@media(pointer:coarse)]:h-11"+ : cn(CHIP, "-mx-2 rounded-xl px-2"),+ className,+ )}+ >+ {pill ? (+ <>+ {icon}+ <span className="min-w-0 flex-1 truncate text-left">+ <span className="xl:hidden">{runs.short}</span>+ <span className="hidden xl:inline">{runs.text}</span>+ </span>+ {caret}+ </>+ ) : (+ <>+ <span className="flex w-full min-w-0 items-center gap-3">+ <span aria-hidden className="grid w-[var(--nav-icon,16px)] shrink-0 place-items-center">+ {icon}+ </span>+ <span className="truncate font-medium text-foreground">{runs.text}</span>+ <span className="ml-auto flex shrink-0 items-center gap-1.5">+ {refill}+ {caret}+ </span>+ </span>+ {b.sub && <span className="truncate pl-7 text-[11px]">{b.sub}</span>}+ </>+ )}+ </button>+ </DropdownMenuTrigger>+ </TooltipTrigger>+ <TooltipContent side="bottom">{runs.tip}</TooltipContent>+ </Tooltip>+ <DropdownMenuContent side={pill ? "bottom" : "top"} align={pill ? "end" : "start"} className="w-72">+ <BalanceItems viewer={viewer} runs={viewer.hosted ? runs : undefined} /></DropdownMenuContent></DropdownMenu>);@@ -233,12 +307,12 @@ export function BalanceChip({ viewer, pill, className }: { viewer: Viewer; pill?/** The balance inside the account menu: the chip's words as a label, then its items, at the same level as the menu's. */export function BalanceSection({ viewer }: { viewer: Viewer }) {const b = viewer.balance!;- const { chip, refill } = balanceLabel(viewer);+ const { refill, runs } = balanceLabel(viewer);return (<><DropdownMenuLabel className="flex flex-col gap-0.5 px-2.5 font-normal"><span className="flex items-center gap-3 text-[12.5px]">- <DotSlot ok={balanceGoes(b)} /> <span className="font-medium text-foreground">{chip}</span>+ <DotSlot ok={runsGo(viewer, runs.on)} /> <span className="font-medium text-foreground">{runs.text}</span>{refill && <span className="ml-auto text-[12px] text-muted-foreground">{refill}</span>}</span>{b.sub && <span className="pl-7 text-[11px] text-muted-foreground">{b.sub}</span>}@@ -449,4 +523,4 @@ export function BarPills({ kind }: { kind: ViewerKind | undefined }) {}/** Each pill's fixed width: the kept room before the status is known is exactly what the pill takes after. */-export const PILL_W = { balance: "w-40", computer: "w-9 xl:w-[140px]", placeholders: "w-[136px]" } as const;+export const PILL_W = { balance: "w-40 xl:w-[184px]", computer: "w-9 xl:w-[140px]", placeholders: "w-[136px]" } as const;diff --git a/src/lib/run-place.ts b/src/lib/run-place.tsindex 5fe8726b..c6b3cb1c 100644--- a/src/lib/run-place.ts+++ b/src/lib/run-place.ts@@ -390,6 +390,50 @@ export function placeRows(return { rows, on, ...(note && { note }) };}+/** The top bar's balance pill: where an account's runs go now, in the pill's words. */+export interface BarRuns {+ on: RunOnPick;+ /** From xl: the price, then the place ("Free · Our GPUs"). */+ text: string;+ /** Below xl: the place alone. */+ short: string;+ /** The button's name and its tooltip ("Where your runs go: Free on our GPUs"). */+ tip: string;+ /** The Run on list, when the account has its own GPU or key to pick. */+ rows: RunOnRow[] | null;+ /** The key a pick of "key" runs on. */+ key?: CloudProvider;+}++/**+ * The balance pill's words (an account while the studio bills): the billing service's `chip` for runs on this studio's+ * GPUs, with the place, or the account's own GPU (free) or key (its provider bills) when its runs go there, as Settings →+ * Your GPU shows them. Hosted runs off for it: the chip alone.+ */+export function barRuns(+ viewer: RunOnViewer & { keys?: readonly CloudProvider[]; runKey?: CloudProvider; paidAllowed?: boolean },+ chip: string,+ refill?: string | null,+): BarRuns {+ if (!viewer.hosted) return { on: "site", text: chip, short: chip, tip: refill ? `${chip}, ${refill}` : chip, rows: null };+ const keys = viewer.paidAllowed === false ? [] : (viewer.keys ?? []);+ const key = viewer.runKey && keys.includes(viewer.runKey) ? viewer.runKey : keys.includes("fal") ? "fal" : keys[0];+ const list = placeRows(viewer, { key: key ? { provider: key } : null, cloud: true }, { text: chip });+ const on = list?.on ?? "site";+ const place = placeOf(viewer.placeName);+ const [price, name, inText] =+ on === "gpu" ? ["Free", "Your GPU", "your GPU"] : on === "key" && key ? [null, `Your ${CLOUD_KEY[key].label} key`, `your ${CLOUD_KEY[key].label} key`] : [chip, place.label, place.text];+ const where = price ? `${price} on ${inText}` : inText;+ return {+ on,+ text: price ? `${price} · ${name}` : name,+ short: name,+ tip: `Where your runs go: ${where}${on === "site" && refill ? `, ${refill}` : ""}`,+ rows: list?.rows ?? null,+ ...(key && { key }),+ };+}+/** Drawn in this browser (a Kinetic template, Click to Ad's end card): the same place and price whoever looks. */export const IN_BROWSER: RunPlace = runPlace({ audience: "guest", engine: "browser", format: String });diff --git a/tests/nav-bar.test.ts b/tests/nav-bar.test.tsindex 41bb3689..568f6447 100644--- a/tests/nav-bar.test.ts+++ b/tests/nav-bar.test.ts@@ -39,13 +39,14 @@ const { AccountSections } = await import("@/components/nav/account-menu");const { avatarDot, refillWords } = await import("@/components/nav/status-chips");const { COVER_SIZES, CoverThumb } = await import("@/components/nav/cover-thumb");const { NavUiProvider } = await import("@/components/nav/nav-ui");+const { TooltipProvider } = await import("@/components/ui/tooltip");const { navCovers } = await import("@/lib/nav-covers");const { entriesFor, entry, launcherColumns, NAV_ENTRIES, studioCount } = await import("@/lib/nav-model");const { studiosMenu } = await import("@/lib/mega-menus");const covers = navCovers();const Nav = NavUiProvider as (p: { covers: typeof covers; children?: ReactNode }) => ReactNode;-const render = (node: ReactNode) => renderToStaticMarkup(createElement(QueryClientProvider, { client: new QueryClient() }, createElement(Nav, { covers }, node)));+const render = (node: ReactNode) => renderToStaticMarkup(createElement(QueryClientProvider, { client: new QueryClient() }, createElement(TooltipProvider, null, createElement(Nav, { covers }, node))));/** Every link in the markup: its tag (attributes) and its href (React escapes & as &). */const anchors = (html: string) => [...html.matchAll(/<a\s[^>]*>/g)].map((m) => ({ tag: m[0], href: (/href="([^"]*)"/.exec(m[0])?.[1] ?? "").replaceAll("&", "&") }));const hrefs = (html: string) => anchors(html).map((a) => a.href);@@ -376,6 +377,19 @@ describe("the account menu's sections (as the phone's You sheet shows them)", ()expect(words(html)).toContain("3 runs left");});+ it("says where the runs go beside the balance, in the bar and the sheet, as a button that opens its menu", () => {+ state.hydrated = true;+ state.viewer = ACCOUNT;+ const balance = { amount: 1, chip: "Free", text: "Free runs", detail: [] };+ state.status = install({ viewer: { kind: "account", gpu: { connected: false }, hosted: true, placeName: "Fuobe Cloud", balance } });+ const bar = render(createElement(TopBar));+ const pill = /<button[^>]*data-runs="site"[^>]*>/.exec(bar)?.[0] ?? "";+ expect(pill).toContain('aria-label="Where your runs go: Free on Fuobe Cloud. Change"');+ expect(pill).toContain('aria-haspopup="menu"');+ expect(words(bar)).toContain("Free · Fuobe Cloud");+ expect(words(sheet())).toContain("Free · Fuobe Cloud");+ });+it("shows the owner the install's status as the sidebar's footer did", () => {state.hydrated = true;state.viewer = OWNER;diff --git a/tests/run-place.test.ts b/tests/run-place.test.tsindex e1a38ddc..29891e70 100644--- a/tests/run-place.test.ts+++ b/tests/run-place.test.ts@@ -1,7 +1,7 @@import { describe, expect, it } from "vitest";import { placeOf } from "@/lib/place-name";import { quoteBody } from "@/lib/hosted";-import { checkedPool, composerOnPool, composerPlace, IN_BROWSER, keyOnlyChip, mainModel, openCheckPlace, placePrice, placeRows, refusedBeforeRun, retryRequest, runPlace, toolPoolPrice, withPoolRefusal, type RunPlaceInput } from "@/lib/run-place";+import { barRuns, checkedPool, composerOnPool, composerPlace, IN_BROWSER, keyOnlyChip, mainModel, openCheckPlace, placePrice, placeRows, refusedBeforeRun, retryRequest, runPlace, toolPoolPrice, withPoolRefusal, type RunPlaceInput } from "@/lib/run-place";import { RUN_SHOWN_HEADER, shownHeader } from "@/lib/guest-access";/** Where a run happens and what it costs, for each audience and engine (the composers' place chip and send button). */@@ -306,6 +306,34 @@ describe("the Run on list", () => {});});+describe("the top bar's balance pill", () => {+ const account = { kind: "account" as const, hosted: true, placeName: "Fuobe Cloud", gpu: { connected: false } };+ const gpu = { connected: true, online: true, device: "NVIDIA GeForce RTX 4090" };+ it("never a bare price: the price and where the runs go, the place alone below xl, and a name that says what it does", () => {+ const r = barRuns(account, "Free");+ expect(r).toMatchObject({ on: "site", text: "Free · Fuobe Cloud", short: "Fuobe Cloud", tip: "Where your runs go: Free on Fuobe Cloud", rows: null });+ expect(barRuns(account, "3 runs left", "refills in 5 h").tip).toBe("Where your runs go: 3 runs left on Fuobe Cloud, refills in 5 h");+ // The default name reads lower case inside a sentence.+ expect(barRuns({ ...account, placeName: undefined }, "Free")).toMatchObject({ text: "Free · Our GPUs", tip: "Where your runs go: Free on our GPUs" });+ });+ it("an account's own GPU or key when its runs go there, with the Run on rows to change it", () => {+ const own = barRuns({ ...account, gpu, runOn: "gpu" }, "Free", "refills in 5 h");+ expect(own).toMatchObject({ on: "gpu", text: "Free · Your GPU", short: "Your GPU", tip: "Where your runs go: Free on your GPU" });+ expect(own.rows?.map((r) => [r.id, r.selected])).toEqual([+ ["site", false],+ ["gpu", true],+ ]);+ const keyed = barRuns({ ...account, keys: ["replicate", "fal"], runOn: "key" }, "Free");+ expect(keyed).toMatchObject({ on: "key", key: "fal", text: "Your fal.ai key", tip: "Where your runs go: your fal.ai key" });+ expect(barRuns({ ...account, keys: ["replicate", "fal"], runKey: "replicate", runOn: "key" }, "Free").text).toBe("Your Replicate key");+ // A studio with paid models off takes no keys: its runs stay here.+ expect(barRuns({ ...account, keys: ["fal"], runOn: "key", paidAllowed: false }, "Free")).toMatchObject({ on: "site", rows: null });+ });+ it("hosted runs off for the account: the chip as the service says it", () => {+ expect(barRuns({ ...account, hosted: false }, "Free")).toMatchObject({ text: "Free", short: "Free", rows: null });+ });+});+describe("the price check asks with the place the run names", () => {const req = { feature: "image", modelId: "oss-z-image-turbo", prompt: "a fox" };it("named: with it; named none (the server decides): with none, so the answer is where the run would really go", () => {