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.

Home: Start runs the prompt in the studio it opens, and says what it costs first

Claude268a0f222e8a
diff --git a/src/app/(studio)/page.tsx b/src/app/(studio)/page.tsx
index 0ab46809..2904cc9b 100644
--- a/src/app/(studio)/page.tsx
+++ b/src/app/(studio)/page.tsx
@@ -1,11 +1,11 @@
import { HomeView } from "@/components/home-view";
import { APPS, EFFECTS, MOTIONS } from "@/lib/catalog";
import { homeEffects, toPresetCard } from "@/lib/preset-cards";
-import { starterPriceLine } from "@/lib/starter-prices";
+import { startQuotes, starterPriceLine } from "@/lib/starter-prices";
const HOME_MOTIONS = ["motion-crash-zoom-in", "motion-360-orbit", "motion-bullet-time", "motion-fpv-drone", "motion-dolly-zoom-in", "motion-snorricam"];
-/** The catalog stays on the server: the home view gets 18 slim cards, three counts and the first-run guide's prices. */
+/** The catalog stays on the server: the home view gets 18 slim cards, three counts, and what Start and the first-run guide cost. */
export default function Page() {
return (
<HomeView
@@ -17,6 +17,7 @@ export default function Page() {
.map(toPresetCard)}
effects={homeEffects(EFFECTS, 6).map(toPresetCard)}
prices={starterPriceLine()}
+ quotes={startQuotes()}
/>
);
}
diff --git a/src/components/home-view.tsx b/src/components/home-view.tsx
index 03f90d4a..ec7e883a 100644
--- a/src/components/home-view.tsx
+++ b/src/components/home-view.tsx
@@ -27,7 +27,8 @@ import { MediaThumb } from "@/components/studio/result-media";
import { useEngine, useGenerations, useHydrated, useStatus } from "@/lib/api";
import { EngineSwitch } from "@/components/studio/engine-switch";
import type { Generation } from "@/lib/catalog/types";
-import { nothingConnected as noConnection, showFirstRun } from "@/lib/connections";
+import { connectedEngines, nothingConnected as noConnection, showFirstRun } from "@/lib/connections";
+import type { StartQuote } from "@/lib/starter-prices";
import { userTitle } from "@/lib/library";
import type { PresetCardData } from "@/lib/preset-cards";
import { cn } from "@/lib/utils";
@@ -144,6 +145,7 @@ export function HomeView({
apps,
effects,
prices,
+ quotes,
}: {
counts: Counts;
motions: PresetCardData[];
@@ -151,6 +153,8 @@ export function HomeView({
effects: PresetCardData[];
/** What a first paid image and clip cost, for the first-run guide. */
prices?: string;
+ /** What Start runs in each mode, and its price on the paid engine. */
+ quotes?: Record<string, StartQuote>;
}) {
const router = useRouter();
const [mode, setMode] = useState(MODES[0]);
@@ -169,7 +173,17 @@ export function HomeView({
const locked = engineMode === "both" ? undefined : engineMode;
- const go = () => router.push(`${mode.href}${prompt.trim() ? `?prompt=${encodeURIComponent(prompt.trim())}` : ""}`);
+ // With a prompt, the studio starts the run itself (go=1), or points at the photo it still needs.
+ const go = () => router.push(`${mode.href}${prompt.trim() ? `?prompt=${encodeURIComponent(prompt.trim())}&go=1` : ""}`);
+ // What Start will run, and what it costs, before it's pressed.
+ const quote = quotes?.[mode.id];
+ const runsFor = (() => {
+ if (!status || nothingConnected || !quote) return null;
+ const engines = connectedEngines(status);
+ const then = mode.id === "image" ? "" : mode.id === "edit" ? " after you add the photo" : "";
+ if (engine === "open") return engines.open && quote.open ? `Start runs ${quote.open.name} on your GPU${then} · Free` : "ComfyUI isn't connected, so Start runs a free demo";
+ return engines.cloud && quote.cloud ? `Start runs ${quote.cloud.name}${then} · ${quote.cloud.price}` : "No paid API is connected, so Start runs a free demo";
+ })();
const focusComposer = () => requestAnimationFrame(() => box.current?.focus());
return (
@@ -228,6 +242,7 @@ export function HomeView({
</div>
</div>
</div>
+ {runsFor && <p className="mt-2 text-[12px] text-muted-foreground">{runsFor}</p>}
{firstRun && status ? (
<GetStarted
className="mt-6 max-w-[960px]"
diff --git a/src/components/studio/composer.tsx b/src/components/studio/composer.tsx
index 0f564423..5dcb88ac 100644
--- a/src/components/studio/composer.tsx
+++ b/src/components/studio/composer.tsx
@@ -12,7 +12,7 @@ import type { GenerationRequest, MediaKind, ModelDef, Operation, Preset } from "
import { enhance, useCreateGeneration, useElements, useEngine, useHydrated, useStatus } from "@/lib/api";
import { applyMentions, type StudioElement } from "@/lib/catalog/elements";
import { applySketch, stripMotionPaths } from "@/lib/catalog/sketch";
-import { blockerFor, costLabel, filterModels, firstMissingSlot, namedImageSlots, needsMask, PLACEHOLDER, promptShown, pushRecent, settingsShape } from "@/lib/composer";
+import { blockerFor, costLabel, filterModels, firstMissingSlot, namedImageSlots, needsMask, PLACEHOLDER, promptShown, pushRecent, settingsShape, startStep } from "@/lib/composer";
import { formatCost } from "@/lib/format";
import { cn } from "@/lib/utils";
import { AttachMenu } from "./attach-menu";
@@ -29,7 +29,7 @@ import { SettingsChip } from "./settings-panel";
import { ShotsEditor } from "./shots-editor";
import { SketchTools } from "./sketch-tools";
import { RECENT_MODELS, useStoredList } from "./stored-list";
-import { useStudio, type Draft } from "./studio-context";
+import { useStartRequest, useStudio, type Draft } from "./studio-context";
import { useEdgeFade } from "./use-edge-fade";
import { useSignature } from "../palettes/use-signature";
@@ -328,6 +328,23 @@ export function Composer({ docked }: { docked: boolean }) {
toast.dismiss("composer-blocker");
}, [blocking]);
+ // Home's Start (go=1): run the handed-over prompt once the models and uploads have settled. A
+ // blocker (Edit's photo) gets the usual toast, and its slot is pointed at, instead.
+ const startRequest = useStartRequest();
+ const startedFor = useRef(0);
+ const submitRef = useRef(submit);
+ useLayoutEffect(() => {
+ submitRef.current = submit;
+ });
+ const settling = !catalog.ready || presetLoading || uploading || (needsFull && !catalog.complete);
+ const step = startRequest ? startStep({ settling, blocker }) : "wait";
+ useEffect(() => {
+ if (step === "wait" || startRequest <= startedFor.current) return;
+ startedFor.current = startRequest;
+ // After the blocker toast above was cleared for this render.
+ submitRef.current();
+ }, [step, startRequest]);
+
// Voice, language, motion, style and Director chips: inline from sm up; on phones they live in the settings sheet, so the toolbar fits.
const voiceChips = (
<>
diff --git a/src/components/studio/studio-context.tsx b/src/components/studio/studio-context.tsx
index b087f4a6..0dc3231f 100644
--- a/src/components/studio/studio-context.tsx
+++ b/src/components/studio/studio-context.tsx
@@ -131,6 +131,16 @@ export function StudioProvider({
);
}
+/**
+ * Home's Start (`?go=1`): a count the composer runs its draft for, once per increase, after the
+ * handed-over prompt is in place (HandoffSync raises it). 0: nothing to start.
+ */
+export const StartRequestCtx = createContext(0);
+
+export function useStartRequest(): number {
+ return useContext(StartRequestCtx);
+}
+
/** Replace a slot value by key, updating only when it's the same upload (async upload callbacks). */
export function slotUpdater(setSlot: Actions["setSlot"], key: SlotKey) {
return (v: SlotValue | null) => setSlot(key, v);
diff --git a/src/components/studio/studio-page.tsx b/src/components/studio/studio-page.tsx
index a4d78273..7efa2c76 100644
--- a/src/components/studio/studio-page.tsx
+++ b/src/components/studio/studio-page.tsx
@@ -9,7 +9,7 @@ import { toast } from "sonner";
import { SidebarTrigger } from "@/components/ui/sidebar";
import type { Generation, MediaKind, ModelDef, Preset } from "@/lib/catalog/types";
import { useEngine, useGenerations } from "@/lib/api";
-import { handoffKey, mergeHandoff, promptShown } from "@/lib/composer";
+import { handoffKey, mergeHandoff, promptShown, START_PARAM, withoutStart } from "@/lib/composer";
import { reuseSignature, withSignatureWords } from "@/lib/catalog/palettes";
import { matchSpokenLanguage } from "@/lib/speech-languages";
import { SoulPresetCards } from "@/components/moodboards/soul-preset-cards";
@@ -21,7 +21,7 @@ import { Composer } from "./composer";
import { EngineSwitch } from "./engine-switch";
import { Feed } from "./feed";
import type { SlotValue } from "./media-slot";
-import { StudioProvider, useStudio, useStudioActions, type Draft, type StudioConfig } from "./studio-context";
+import { StartRequestCtx, StudioProvider, useStudio, useStudioActions, type Draft, type StudioConfig } from "./studio-context";
function kindOfUrl(url: string): MediaKind {
if (/\.(mp4|webm|mov)(\?|$)/i.test(url)) return "video";
@@ -347,11 +347,13 @@ interface StudioPageProps {
type DraftProps = Omit<StudioPageProps, "catalog">;
-/** Reports the URL's hand-off params. It reads the URL, so it sits under its own Suspense: the static shell renders without it. */
-function UrlParams({ onChange }: { onChange: (key: string) => void }) {
- const key = handoffKey(useSearchParams());
+/** Reports the URL's hand-off params, and whether it asks to start (`go=1`). It reads the URL, so it sits under its own Suspense: the static shell renders without it. */
+function UrlParams({ onChange }: { onChange: (key: string, start: boolean) => void }) {
+ const sp = useSearchParams();
+ const key = handoffKey(sp);
+ const start = sp.get(START_PARAM) === "1";
// Layout effect: on a client navigation the prefilled draft is in place before the first paint.
- useLayoutEffect(() => onChange(key), [key, onChange]);
+ useLayoutEffect(() => onChange(key, start), [key, start, onChange]);
return null;
}
@@ -361,29 +363,67 @@ function UrlParams({ onChange }: { onChange: (key: string) => void }) {
* of a client navigation. Fields the person already changed — a prompt typed before the page
* hydrated — are kept. A later change of the params (Animate → Video while on Video) starts a
* fresh draft instead.
+ *
+ * With `go=1` (Home's Start) it then asks the composer to run the draft once (onStart), after the
+ * draft was built from the loaded models, and takes `go` out of the address so a reload or Back
+ * doesn't run it again.
*/
-function HandoffSync({ startKey, start, build, ready, onNavigate }: { startKey: string; start: Draft; build: React.RefObject<(key: string) => Draft>; ready: boolean; onNavigate: (key: string) => void }) {
+function HandoffSync({
+ startKey,
+ start,
+ build,
+ ready,
+ onNavigate,
+ onStart,
+}: {
+ startKey: string;
+ start: Draft;
+ build: React.RefObject<(key: string) => Draft>;
+ ready: boolean;
+ onNavigate: (key: string) => void;
+ onStart: () => void;
+}) {
const { setDraft } = useStudioActions();
- const [url, setUrl] = useState<string | null>(null);
+ const [url, setUrl] = useState<{ key: string; start: boolean } | null>(null);
const applied = useRef({ key: startKey, ready, base: start, seen: false });
+ const started = useRef(false);
+ const onParams = useCallback((key: string, start: boolean) => setUrl((u) => (u?.key === key && u.start === start ? u : { key, start })), []);
useLayoutEffect(() => {
if (url === null) return;
const a = applied.current;
- if (a.seen && url !== a.key) return onNavigate(url);
+ if (a.seen && url.key !== a.key) return onNavigate(url.key);
a.seen = true;
- if (url === a.key && ready === a.ready) return;
- const next = build.current(url);
- const base = a.base;
- setDraft((d) => mergeHandoff(base, d, next));
- applied.current = { key: url, ready, base: next, seen: true };
- }, [url, ready, build, setDraft, onNavigate]);
+ if (url.key !== a.key || ready !== a.ready) {
+ const next = build.current(url.key);
+ const base = a.base;
+ setDraft((d) => mergeHandoff(base, d, next));
+ applied.current = { key: url.key, ready, base: next, seen: true };
+ }
+ if (url.start && ready && !started.current) {
+ started.current = true;
+ onStart();
+ window.history.replaceState(null, "", withoutStart(window.location.href));
+ }
+ }, [url, ready, build, setDraft, onNavigate, onStart]);
return (
<Suspense fallback={null}>
- <UrlParams onChange={setUrl} />
+ <UrlParams onChange={onParams} />
</Suspense>
);
}
+/** One draft's page: the studio and its hand-off. The start request resets with the draft (a new epoch). */
+function StudioSession({ header, tabs, sync }: { header?: React.ReactNode; tabs?: React.ReactNode; sync: Omit<React.ComponentProps<typeof HandoffSync>, "onStart"> }) {
+ const [startRequest, setStartRequest] = useState(0);
+ const onStart = useCallback(() => setStartRequest((n) => n + 1), []);
+ return (
+ <StartRequestCtx.Provider value={startRequest}>
+ <StudioBody header={header} tabs={tabs} />
+ <HandoffSync {...sync} onStart={onStart} />
+ </StartRequestCtx.Provider>
+ );
+}
+
/**
* The studio. It renders the same tree in the static shell and after hydration (the URL is read
* by HandoffSync alone), so the composer the shell painted is the one you type into: nothing
@@ -411,8 +451,7 @@ function StudioDraft({ config, header, tabs, initialRefs, initialPrompt }: Draft
return (
<ComposerBridgeCtx.Provider value={bridge}>
<StudioProvider key={start.epoch} config={config} initial={initial}>
- <StudioBody header={header} tabs={tabs} />
- <HandoffSync startKey={start.key} start={initial} build={buildRef} ready={catalog.ready} onNavigate={onNavigate} />
+ <StudioSession header={header} tabs={tabs} sync={{ startKey: start.key, start: initial, build: buildRef, ready: catalog.ready, onNavigate }} />
</StudioProvider>
</ComposerBridgeCtx.Provider>
);
diff --git a/src/lib/composer.ts b/src/lib/composer.ts
index a6433c2f..211844c0 100644
--- a/src/lib/composer.ts
+++ b/src/lib/composer.ts
@@ -408,6 +408,30 @@ export function mergeHandoff<D extends DraftShape>(base: D, current: D, next: D)
return patch;
}
+// ---------------------------------------------------------------------------
+// Home's Start: "/image?prompt=…&go=1" runs the handed-over prompt once
+
+/** The query flag that asks a studio to run its handed-over draft once (Home's Start). */
+export const START_PARAM = "go";
+
+/** The same address without the start flag, so a reload or Back doesn't run it again. */
+export function withoutStart(href: string): string {
+ const u = new URL(href, "http://x");
+ u.searchParams.delete(START_PARAM);
+ const rest = `${u.pathname}${u.search}${u.hash}`;
+ return /^https?:\/\//.test(href) ? `${u.origin}${rest}` : rest;
+}
+
+/**
+ * What a studio does with a start request now: wait while models, presets or uploads are still
+ * loading (their blockers are temporary), run when nothing blocks, else explain — the blocker's
+ * toast names what's missing and points at its slot (Edit and Video's photo).
+ */
+export function startStep(s: { settling: boolean; blocker: Blocker | null }): "wait" | "run" | "explain" {
+ if (s.settling) return "wait";
+ return s.blocker ? "explain" : "run";
+}
+
// ---------------------------------------------------------------------------
// Models for a studio and the picker's groups
diff --git a/src/lib/starter-prices.ts b/src/lib/starter-prices.ts
index eb645a0a..2c3692e1 100644
--- a/src/lib/starter-prices.ts
+++ b/src/lib/starter-prices.ts
@@ -1,7 +1,7 @@
import { getModel } from "@/lib/catalog";
import { estimateCost } from "@/lib/catalog/plan";
import { formatCost } from "@/lib/format";
-import { IMAGE_STUDIO, VIDEO_STUDIO } from "@/lib/studios";
+import { EDIT_STUDIO, IMAGE_STUDIO, VIDEO_STUDIO } from "@/lib/studios";
/**
* What a first image and a first clip cost on the default paid models, for the first-run guide
@@ -16,3 +16,27 @@ export function starterPriceLine(): string {
};
return [quote(IMAGE_STUDIO.defaultModels.cloud, () => "an image"), quote(VIDEO_STUDIO.defaultModels.cloud, (d) => (d ? `a ${d} s clip` : "a clip"))].filter(Boolean).join(" · ");
}
+
+/** What Home's Start runs in a mode: the studio's default model on each engine, and what one run costs on the paid one. */
+export interface StartQuote {
+ cloud: { name: string; price: string } | null;
+ open: { name: string } | null;
+}
+
+/** Home's Start quotes, by mode (image, video, edit), so the price is known before a paid run starts. */
+export function startQuotes(): Record<"image" | "video" | "edit", StartQuote> {
+ const quote = (d: { cloud: string; open: string }, what: (duration?: number) => string): StartQuote => {
+ const cloud = getModel(d.cloud);
+ const open = getModel(d.open);
+ const usd = cloud ? estimateCost(cloud, { ...cloud.defaults }) : null;
+ return {
+ cloud: cloud ? { name: cloud.name, price: usd ? `about ${formatCost(usd)} ${what(cloud.defaults?.duration)}` : "priced by the provider" } : null,
+ open: open ? { name: open.name } : null,
+ };
+ };
+ return {
+ image: quote(IMAGE_STUDIO.defaultModels, () => "an image"),
+ video: quote(VIDEO_STUDIO.defaultModels, (d) => (d ? `a ${d} s clip` : "a clip")),
+ edit: quote(EDIT_STUDIO.defaultModels, () => "an edit"),
+ };
+}
diff --git a/tests/home-start.test.ts b/tests/home-start.test.ts
new file mode 100644
index 00000000..0ce179d8
--- /dev/null
+++ b/tests/home-start.test.ts
@@ -0,0 +1,35 @@
+import { describe, expect, it } from "vitest";
+import { blockerFor, firstMissingSlot, handoffKey, startStep, withoutStart } from "@/lib/composer";
+import { startQuotes } from "@/lib/starter-prices";
+import { EDIT_STUDIO, IMAGE_STUDIO } from "@/lib/studios";
+
+/** Home's Start runs the prompt in the studio it opens (R4-16). */
+
+describe("the start flag", () => {
+ it("is taken out of the address once used, keeping the hand-off", () => {
+ expect(withoutStart("/image?prompt=a%20fox&go=1")).toBe("/image?prompt=a+fox");
+ expect(withoutStart("http://localhost:3000/edit?go=1&prompt=sky#x")).toBe("http://localhost:3000/edit?prompt=sky#x");
+ expect(withoutStart("/video?go=1")).toBe("/video");
+ // It isn't part of the hand-off, so dropping it never rebuilds the draft.
+ expect(handoffKey("prompt=a+fox&go=1")).toBe(handoffKey("prompt=a+fox"));
+ });
+
+ it("waits while things load, runs when nothing blocks, else explains what's missing", () => {
+ expect(startStep({ settling: true, blocker: { message: "Loading models…" } })).toBe("wait");
+ expect(startStep({ settling: false, blocker: null })).toBe("run");
+ // Edit with a prompt and no photo: the blocker names the slot, which the toast points at.
+ const missing = firstMissingSlot(EDIT_STUDIO.slots, {});
+ const blocker = blockerFor({ model: true, missing, uploading: false, promptMissing: false });
+ expect(blocker).toEqual({ message: "Add an image", slot: "image" });
+ expect(startStep({ settling: false, blocker })).toBe("explain");
+ // Image needs nothing but the prompt.
+ expect(firstMissingSlot(IMAGE_STUDIO.slots, {})).toBeUndefined();
+ });
+
+ it("says what Start runs and costs in each mode", () => {
+ const q = startQuotes();
+ expect(q.image).toEqual({ cloud: { name: "Nano Banana Pro", price: expect.stringMatching(/^about \$[\d.]+ an image$/) }, open: { name: expect.any(String) } });
+ expect(q.video.cloud?.price).toMatch(/^about \$[\d.]+ a 5 s clip$/);
+ expect(q.edit.cloud?.price).toMatch(/an edit$/);
+ });
+});