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
3D apps: an account's Image to 3D, Photo to 3D and Make it 3D run on its own GPU or key
Adarsh9daef19dd33f
diff --git a/docs/public-signup.md b/docs/public-signup.mdindex 5d752c7d..8a13a83f 100644--- a/docs/public-signup.md+++ b/docs/public-signup.md@@ -267,13 +267,15 @@ cloudflared tunnel --url http://localhost:8188 # or: ngrok http 8188with the open-source engine: the Image, Video and Audio studios (their input modes too: edit,inpaint, extend, lipsync, reframe, upscale, image to video…), every camera motion and effect,and the apps that take a picture, a clip or a sound. Their chained steps (multi-shot films,- Frames mode, Extend, relit effects) run there too, as the account's own. Polls,+ Frames mode, Extend, relit effects) run there too, as the account's own. So does a 3D model (the+ Image to 3D and Photo to 3D apps, and an image result's "Make it 3D", which opens Photo to 3D), on+ the account's own GPU or key; it is finished as Image to 3D's models are (below), and on this+ install's GPUs (hosted runs) 3D isn't offered yet. Polls,uploads, outputs and cancels go there, and nothing falls back to the studio's own providers. Ifthe account's ComfyUI can't be reached, the run fails and says so. A cloud model, an AI helper orthe studio's local LLM is refused; "Enhance prompt" uses Fuobe's offline wording. Other tools(Canvas, Assist, Marketing…) answer 403 with `code: "own-gpu-tool"`, because they- plan with the studio's own AI helpers or keep projects of their own. A 3D model sent here answers the- same: Image to 3D has its own route (below). So do the Audio hub's Split+ plan with the studio's own AI helpers or keep projects of their own. So do the Audio hub's Splitsoundtrack and Edit speech and Video tools → Remove dialogue (all `POST /api/audio-tools`) and theturnaround video (`POST /api/turnaround`), though their price checks work, priced for the account'sown GPU. Split soundtrack's, Edit speech's and Remove dialogue's pages say so up front ("Splitdiff --git a/src/app/api/generations/route.ts b/src/app/api/generations/route.tsindex 2054c6ff..7c0e3c56 100644--- a/src/app/api/generations/route.ts+++ b/src/app/api/generations/route.ts@@ -219,13 +219,9 @@ export async function POST(request: Request) {if (account) unhit(`run:${account.id}`);return refuse(422, ISOLATED_ON_COMPUTER, { code: "isolated-on-computer" });}- // A 3D model from someone else's ComfyUI is finished on this server (decimate, web GLB, turntable): accounts- // don't get Image to 3D until that finish runs under an account's own limits.- // (Any Angle's 3D view is a splat and its turntable: nothing to finish, so an account builds it on its own GPU.)- if (account && outputKind(planned.op, planned.model) === "model3d" && planned.model.id !== ANY_ANGLE.buildModel) {- unhit(`run:${account.id}`);- return Response.json({ error: OWN_GPU_TOOL_MESSAGE, code: "own-gpu-tool" }, { status: 403 });- }+ // An account's 3D model (Image to 3D, Photo to 3D, Make it 3D) runs on its own GPU or key, and is finished on+ // this server under the account's limits (model3d-finish.ts). This install's GPUs don't take 3D: decidePlace+ // refuses it there, and createGenerations refuses a run stamped for them.const skip = (body as { gpuCheck?: unknown } | null)?.gpuCheck === "skip";const gate = await gateGeneration(gpuTargetFor(request, "read"), { request: req, route: planned.route, op: planned.op, modelId: planned.model.id, gpu: planned.gpu, h3: planned.h3, skip, actor: account?.id ?? "owner" });if (!gate.ok) {diff --git a/tests/account-3d-apps.test.ts b/tests/account-3d-apps.test.tsnew file mode 100644index 00000000..115bad4b--- /dev/null+++ b/tests/account-3d-apps.test.ts@@ -0,0 +1,196 @@+import { afterAll, beforeAll, beforeEach, describe, expect, it } from "vitest";+import { NextRequest } from "next/server";+import { startFakeComfy, TINY_PNG, type FakeComfy } from "./helpers/fake-comfy-runner";+import { tempDir } from "./helpers/temp-dir";++/**+ * 3D from the apps (public sign-up): the Image to 3D app and Photo to 3D (where an image result's Make it 3D goes) run+ * through POST /api/generations. A signed-in account's run goes to its own ComfyUI (a stand-in here) and is made there,+ * with no "isn't available here" answer; an account with neither a GPU nor a key is asked to connect one; a guest gets+ * the sign-up card; a run stamped for this install's GPUs is still refused, and a place sent in the body changes+ * nothing. The owner's run is as before.+ */+const dir = tempDir("fuobe-account-3d-apps-");+process.env.FUOBE_DATA_DIR = dir;+process.env.COMFYUI_URL = "http://owner-comfy.test:8188";+process.env.FUOBE_PUBLIC_SIGNUP = "1";+delete process.env.FUOBE_PASSWORD;+delete process.env.FUOBE_ALLOW_PRIVATE_URLS;+delete process.env.FUOBE_HOSTED_RUNS;+globalThis.__fuobeTestDiskFree = 1e13;++// Plain fetch is the install's own ComfyUI ("owner-comfy.test"): recorded, so a test sees that nothing reached it.+const realFetch = globalThis.fetch;+const fetched: string[] = [];+globalThis.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => {+ const url = new URL(String(input instanceof Request ? input.url : input));+ if (url.hostname === "127.0.0.1") return realFetch(input, init);+ fetched.push(url.toString());+ if (url.host !== "owner-comfy.test:8188") return new Response("not stubbed", { status: 599 });+ if (url.pathname === "/system_stats") return Response.json({ system: { comfyui_version: "owner", ram_total: 1 }, devices: [] });+ return Response.json({});+}) as typeof fetch;++const auth = await import("@/server/auth");+const route = await import("@/app/api/generations/route");+const uploadsRoute = await import("@/app/api/uploads/route");+const gpuRoute = await import("@/app/api/account/gpu/route");+const { proxy } = await import("@/proxy");+const access = await import("@/lib/guest-access");+const { createGenerations, getGeneration, asAccount } = await import("@/server/generations");+const { db } = await import("@/server/db");+const { resetRates } = await import("@/server/rate");+const { withRunStamp } = await import("@/server/run-stamp");+const { outputActions } = await import("@/lib/output-actions");++let fake: FakeComfy;+let a = "";+const cookies: Record<string, string> = {};+beforeAll(async () => {+ fake = await startFakeComfy({ loras: [], delayMs: 0, output: "model3d" });+ globalThis.__fuobeTestGpuPort = fake.port;+ auth.setPassword("install password");+ for (const [k, email] of [+ ["a", "[email protected]"],+ ["c", "[email protected]"],+ ] as const) {+ const id = auth.createAccount(email, "long enough").id;+ cookies[k] = `${auth.SESSION_COOKIE}=${auth.createSession(id).value}`;+ if (k === "a") a = id;+ }+ cookies.owner = `${auth.SESSION_COOKIE}=${auth.createSession().value}`;+ // A links its own ComfyUI; C has neither a GPU nor a key.+ expect((await gpuRoute.PUT(json("/api/account/gpu", "PUT", { url: fake.url }, "a"))).status).toBe(200);+});+afterAll(async () => {+ globalThis.fetch = realFetch;+ globalThis.__fuobeTestGpuPort = undefined;+ globalThis.__fuobeTestDiskFree = undefined;+ await fake.close();+});+beforeEach(() => {+ resetRates();+ db().prepare("UPDATE generations SET status = 'canceled' WHERE status IN ('queued', 'running') AND json_extract(request_json, '$.account') IS NOT NULL").run();+});++function json(url: string, method: string, body: unknown, who?: string): Request {+ const text = JSON.stringify(body);+ return new Request(`http://localhost:3000${url}`, {+ method,+ headers: { host: "localhost:3000", "content-type": "application/json", "content-length": String(Buffer.byteLength(text)), ...(who && { cookie: cookies[who] }) },+ body: text,+ });+}++const viaProxy = (url: string, method: string, who?: string) =>+ proxy(new NextRequest(`http://localhost:3000${url}`, { method, headers: { host: "localhost:3000", "content-type": "application/json", ...(who && { cookie: cookies[who] }) }, body: "{}" }));+const passed = (r: Response) => r.headers.get("x-middleware-next") === "1";++async function upload(who: string, name: string): Promise<string> {+ const r = await uploadsRoute.POST(new Request("http://localhost:3000/api/uploads", { method: "POST", headers: { host: "localhost:3000", cookie: cookies[who], "content-type": "image/png", "x-file-name": name, "content-length": String(TINY_PNG.length) }, body: new Uint8Array(TINY_PNG) }));+ expect(r.status, await r.clone().text()).toBe(201);+ return ((await r.json()) as { url: string }).url;+}++/** Tick the runner until the row is done (or the time is up). */+async function settle(id: string, ms = 60_000) {+ const end = Date.now() + ms;+ for (;;) {+ await globalThis.__fuobeRunner?.tick();+ const g = getGeneration(id, { includeDeleted: true });+ if (!g || (g.status !== "queued" && g.status !== "running") || Date.now() > end) return g;+ await new Promise((r) => setTimeout(r, 100));+ }+}++/** What the Image to 3D app's composer sends on the open engine. */+const imageTo3dApp = (photo: string) => ({ feature: "app:app-image-to-3d", presetId: "app-image-to-3d", modelId: "oss-pixal3d", op: "image-to-3d", engine: "open", prompt: "", inputs: { images: [photo] } });+/** What Photo to 3D's composer sends (Make it 3D opens it with the picture in). */+const photoTo3dApp = (photo: string) => ({ feature: "app:app-photo-to-3d", presetId: "app-photo-to-3d", modelId: "oss-idol-3d", op: "image-to-3d", engine: "open", prompt: "", inputs: { images: [photo] } });+const made = async (r: Response) => {+ expect(r.status, await r.clone().text()).toBe(201);+ return ((await r.json()) as { items: { id: string }[] }).items;+};++describe("a guest and an account with nothing connected", () => {+ it("a guest gets the sign-up card at the proxy and at the route", async () => {+ const p = viaProxy("/api/generations", "POST");+ expect(p.status).toBe(401);+ expect(p.headers.get(access.GUEST_HEADER)).toBe("1");+ const r = await route.POST(json("/api/generations", "POST", imageTo3dApp("/api/files/x.png")));+ expect(r.status).toBe(401);+ expect((await r.json()).error).toBe(access.GUEST_RUN_MESSAGE);+ });++ it("an account with neither a GPU nor a key is asked to connect one, never told the tool isn't available", async () => {+ const r = viaProxy("/api/generations", "POST", "c");+ expect(r.status).toBe(403);+ expect(r.headers.get(access.CONNECT_GPU_HEADER)).toBe("1");+ const body = (await r.json()) as { code: string; error: string };+ expect(body.code).toBe("connect-gpu");+ expect(body.error).not.toBe(access.OWN_GPU_TOOL_MESSAGE);+ expect(passed(viaProxy("/api/generations", "POST", "a"))).toBe(true);+ });+});++describe("an account's 3D app runs on its own ComfyUI", () => {+ let photo = "";+ beforeAll(async () => {+ photo = await upload("a", "lamp.png");+ });++ it("the Image to 3D app: made on its ComfyUI end to end, a GLB of its own", async () => {+ fake.log.length = 0;+ fetched.length = 0;+ const [item] = await made(await route.POST(json("/api/generations", "POST", imageTo3dApp(photo), "a")));+ const g = getGeneration(item.id)!;+ expect(g.request.account).toBe(a);+ expect(g.provider).toBe("comfyui");+ expect(g.kind).toBe("model3d");+ const done = await settle(item.id);+ expect(done?.status, done?.error ?? "").toBe("succeeded");+ expect(fake.log.filter((e) => e.path === "/prompt")).toHaveLength(1);+ // Nothing reached the install's own ComfyUI.+ expect(fetched.filter((u) => !u.endsWith("/system_stats"))).toEqual([]);+ const model = done!.outputs.find((o) => o.kind === "model3d")!;+ expect(model.contentType).toBe("model/gltf-binary");+ }, 120_000);++ it("Photo to 3D (an image result's Make it 3D) is taken for its own ComfyUI", async () => {+ const actions = outputActions({ id: "g1", feature: "image", modelId: "x", status: "succeeded", request: { account: a }, outputs: [{ url: photo, kind: "image" }] } as never, 0, { visitor: true, account: true });+ expect(actions.find((x) => x.id === "make-3d")?.href).toBe(`/apps/app-photo-to-3d?image=${encodeURIComponent(photo)}`);+ const [item] = await made(await route.POST(json("/api/generations", "POST", photoTo3dApp(photo), "a")));+ const g = getGeneration(item.id)!;+ expect(g.request.account).toBe(a);+ expect(g.provider).toBe("comfyui");+ expect(g.kind).toBe("model3d");+ });++ it("a place sent in the body changes nothing: the run is the account's own, never stamped for this install's GPUs", async () => {+ for (const place of ["own", "pool"]) {+ const [item] = await made(await route.POST(json("/api/generations", "POST", { ...imageTo3dApp(photo), place }, "a")));+ const g = getGeneration(item.id)!;+ expect(g.request.account, place).toBe(a);+ expect(g.request.place, place).toBeUndefined();+ expect(g.provider, place).toBe("comfyui");+ db().prepare("UPDATE generations SET status = 'canceled' WHERE id = ?").run(item.id);+ }+ });++ it("the same run stamped for this install's GPUs is refused when it is made", () => {+ const req = imageTo3dApp(photo) as Parameters<typeof createGenerations>[0];+ expect(() => asAccount(a, () => withRunStamp({ place: "pool" }, () => createGenerations(req)))).toThrow(access.OWN_GPU_TOOL_MESSAGE);+ // A place in the request itself is dropped: only the stamp in scope sets it.+ const own = asAccount(a, () => createGenerations({ ...req, place: "pool" } as never));+ expect(own[0].request.place).toBeUndefined();+ expect(own[0].kind).toBe("model3d");+ });+});++describe("the owner's 3D app runs are as before", () => {+ it("the owner's Image to 3D app run is made", async () => {+ const [item] = await made(await route.POST(json("/api/generations", "POST", imageTo3dApp("/api/files/placeholder.png"), "owner")));+ expect(getGeneration(item.id)!.request.account).toBeUndefined();+ db().prepare("UPDATE generations SET status = 'canceled' WHERE id = ?").run(item.id);+ });+});diff --git a/tests/account-idol.test.ts b/tests/account-idol.test.tsindex 911763da..4483dbc3 100644--- a/tests/account-idol.test.ts+++ b/tests/account-idol.test.ts@@ -3,10 +3,9 @@ import { startFakeComfy, TINY_PNG, type FakeComfy } from "./helpers/fake-comfy-rimport { tempDir } from "./helpers/temp-dir";/**- * Idol 3D under public sign-up: 3D models are closed to accounts, so an account's Idol run answers 403- * own-gpu-tool on both engines — on its own linked ComfyUI (oss-idol, and the quick mesh oss-idol-mesh) and with its- * own fal.ai key (idol-3d) — and nothing reaches its GPU or fal. So does its "Make the other sides" run (Idol 3D's- * four views).+ * Idol 3D under public sign-up: an account's Idol run is taken for its own GPU or key on both engines — its own+ * linked ComfyUI (oss-idol, and the quick mesh oss-idol-mesh) and its own fal.ai key (idol-3d) — and so is its "Make+ * the other sides" run (Idol 3D's four views). A run on this install's GPUs stays refused (account-3d-apps.test.ts).*/const dir = tempDir("fuobe-account-idol-");@@ -28,6 +27,8 @@ const auth = await import("@/server/auth");const keys = await import("@/server/account-keys");const generationsRoute = await import("@/app/api/generations/route");const { saveFile } = await import("@/server/storage");+const { getGeneration } = await import("@/server/generations");+const { db } = await import("@/server/db");const { getModel } = await import("@/lib/catalog");const { model3dRequest } = await import("@/lib/av/model3d");const { idolViewsRequest } = await import("@/lib/av/idol-views");@@ -62,32 +63,40 @@ const post = (body: unknown) => {);};-describe("Idol 3D stays closed to accounts", () => {+/** Put a queued run aside, so the next run is under the account's limit of runs at once. */+const cancel = (id: string) => db().prepare("UPDATE generations SET status = 'canceled' WHERE id = ? OR batch_id = ?").run(id, id);++describe("Idol 3D runs on the account's own GPU or key", () => {it.each([- ["open", "oss-idol", "splat"],- ["cloud", "idol-3d", "splat"],+ ["open", "oss-idol", "splat", "comfyui"],+ ["cloud", "idol-3d", "splat", "fal"],// idol-7: Idol 3D quick mesh, in From an image.- ["open", "oss-idol-mesh", "image"],- ] as const)("on the %s engine (%s): 403 own-gpu-tool, nothing sent", async (engine, modelId, mode) => {+ ["open", "oss-idol-mesh", "image", "comfyui"],+ ] as const)("on the %s engine (%s): taken for the account's own %s", async (engine, modelId, mode, provider) => {expect(getModel(modelId)?.engine).toBe(engine);const photo = saveFile({ data: TINY_PNG, contentType: "image/png", source: "upload", accountId: account }).url;const req = model3dRequest({ engine, mode, modelId, photo, quality: "quick", photoCrop: true });expect(req.modelId).toBe(modelId);- fake.log.length = 0;- fetched.length = 0;const r = await post(req);- expect(r.status, await r.clone().text()).toBe(403);- expect((await r.json()).code).toBe("own-gpu-tool");- expect(fake.log.filter((e) => e.path === "/prompt" || e.path === "/upload/image")).toHaveLength(0);- expect(fetched.filter((u) => /fal\.(run|ai|media)/.test(u))).toHaveLength(0);+ expect(r.status, await r.clone().text()).toBe(201);+ const [item] = ((await r.json()) as { items: { id: string }[] }).items;+ const g = getGeneration(item.id)!;+ expect(g.request.account).toBe(account);+ expect(g.request.place).toBeUndefined();+ expect(g.provider).toBe(provider);+ cancel(item.id);});- it("the other sides from one picture (Idol 3D's views): 403 own-gpu-tool, nothing sent", async () => {+ it("the other sides from one picture (Idol 3D's views): taken for the account's own ComfyUI", async () => {const photo = saveFile({ data: TINY_PNG, contentType: "image/png", source: "upload", accountId: account }).url;- fake.log.length = 0;const r = await post(idolViewsRequest(photo));- expect(r.status, await r.clone().text()).toBe(403);- expect((await r.json()).code).toBe("own-gpu-tool");- expect(fake.log.filter((e) => e.path === "/prompt" || e.path === "/upload/image")).toHaveLength(0);+ expect(r.status, await r.clone().text()).toBe(201);+ const items = ((await r.json()) as { items: { id: string }[] }).items;+ expect(items.length).toBeGreaterThan(0);+ for (const { id } of items) {+ expect(getGeneration(id)!.request.account).toBe(account);+ expect(getGeneration(id)!.provider).toBe("comfyui");+ cancel(id);+ }});});