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.

Merge main's newer work (Video tools, Turnaround, Fly around, Katana, Audio tools and Translate & dub for accounts)

Adarsh270db68146ee
diff --cc docs/public-signup.md
index 4e34e922,dd2c068f..d1fc2e3b
--- a/docs/public-signup.md
+++ b/docs/public-signup.md
@@@ -373,6 -363,38 +363,40 @@@ cloudflared tunnel --url http://localho
sheets), and a retried photo replaces the failed one for good (it has no Trash). The price is its run's: free on its
GPU, its own key's price on the cloud engine. A guest gets the sign-up card on Generate, on Create pack, on New
character and before choosing a photo.
+ - **Video tools, Turnaround video, Fly around and Katana.** An account runs Remove object and Remove a person
+ (`POST /api/remove-object`, its mask preview `.../preview` and "Redo from here" `.../reroll`), Evolution
+ (`POST /api/evolution`), Mixed Media (`POST /api/mixed-media`, a preview frame `.../preview` and "Try again"
+ `.../retry`), Turnaround video (`POST /api/turnaround`), Fly around (`POST /api/fly-around`: Image to 3D's "Film it
+ photoreal" and the exact orbits) and Katana (`POST /api/katana`, `.../<id>/retry`) the same way as Genjutsu's: every
+ step on the account's ComfyUI or its own fal.ai or Replicate key, with only its own files, after the same checks, and
+ a run counts once against its limits. Their price checks are priced for the account's own GPU or key. Their results
+ are its own runs (each tool's history, "Your …" feeds and its runs list), to open and download. "Redo from here" and
+ "Try again" take only its own removal or render, and a Mixed Media render's frame count (`GET
+ /api/mixed-media/progress`) answers for its own renders only (anyone else's reads as 404). Evolution's direction
+ (`POST /api/evolution/direction`, and a run sent without one) is written by Fuobe's offline writer, never the studio's
+ AI helper. Turnaround and Fly around never use the studio's WorldCast worker for an account; a character from the
+ owner's library answers 404. Katana's runs are its own projects (`GET /api/katana`, `GET`/`DELETE
+ /api/katana/<id>`): up to 50, another account's or the owner's read as 404, deleted with the account. A guest gets
+ the sign-up card.
+ - **Audio tools.** An account runs Split soundtrack and Clean up dialogue, Video tools → Remove dialogue, Edit speech,
+ Loop / extend, Join and Clean up voice (`POST /api/audio-tools`) the same way as Genjutsu's: every step on its own
+ ComfyUI, or on its own fal.ai or Replicate key where a step is a cloud model, with only its own files, after the same
+ checks, and a run counts once against its limits. Its price check is its own run's. Its stems, clean dialogue,
+ edited speech and mixes are its own runs, to reopen in the mixer, open and download, and Export mix keeps the WAV as
+ one of its runs (above). Edit speech runs on the account's own GPU only (AuK's files and a 24 GB card): its tab and
+ page carry the "own setup" label (`audio:edit-speech`), and its upload and run ask an account without a GPU to
+ connect one. Result menus offer Remove dialogue, Clean up dialogue and Edit speech, and Captions offers "Fix this line".
+ A guest gets the sign-up card.
++- **Palette lock.** An account runs the Image studio's palette lock (`POST /api/palettes/lock`) the same way: its
++ images, then each one recoloured to the palette, on its own ComfyUI or key, after the same checks.
+ - **Translate & dub.** An account keeps dubs of its own (`GET`/`POST /api/dub`, `GET`/`PATCH`/`DELETE /api/dub/<id>`,
+ `POST /api/dub/<id>/voice`): up to 50, in the account project store, deleted with the account. Another account's dub,
+ or the owner's, reads as not found (404), and the owner's list never shows an account's. A dub (one shot on its own
+ key, or step by step) and the voice of each language run the same way as Genjutsu's: every step on its own ComfyUI
+ or key, with only its own video. Its translations run on its own GPU (Qwen3.5 4B, `oss-qwen35-translate`), never on
+ the studio's AI helper, on either engine: a cloud step-by-step dub with a key and no GPU is asked to connect one. Its
+ reviewed lines are saved with its dub, and its dubbed videos are its own runs, to open and download. A guest gets the
+ sign-up card.
- **Files a run takes.** A run on your GPU takes only files you uploaded here, or your own results.
A link or a `data:` URI answers 400 with `code: "input-not-allowed"`, someone else's file 403
(`input-not-yours`), and a file that has expired 404 (`input-gone`, "That file has expired.
diff --cc src/app/api/fly-around/route.ts
index 0623ec8c,add880bf..8cc3e88e
--- a/src/app/api/fly-around/route.ts
+++ b/src/app/api/fly-around/route.ts
@@@ -1,8 -1,6 +1,7 @@@
- import { bodyTooBig, guestRun, toolViewer, toolWishes } from "@/server/account-tool-run";
+ import { bodyTooBig, guestRun, onceForAccount, priceAsRun, runAccountTool, toolViewer } from "@/server/account-tool-run";
import { body, handle, once } from "@/server/shorts-schemas";
- import { createFlyAround, FlyAroundSchema, previewFlyAround } from "@/server/fly-around";
- import { bodyFiles, runToolForAccount, withPoolPrice } from "@/server/tool-runs";
- import { priceAs } from "@/server/visitor";
+ import { createFlyAround, flyAroundSteps, FlyAroundSchema, planFlyAroundRun, previewFlyAround, startFlyAround, type FlyAroundRun } from "@/server/fly-around";
++import { withPlanPrice } from "@/server/tool-runs";
import { worldcastContextNow } from "@/server/worldcast-on";
/**
@@@ -14,26 -11,31 +12,32 @@@
*/
async function post(request: Request) {
return handle(async () => {
- const viewer = toolViewer(request);
- const wishes = viewer.kind === "owner" ? {} : await toolWishes(request);
const { requestId, ...input } = await body(request, FlyAroundSchema, "Pick the engine, the still and the path");
- // The WorldCast worker's answer, fresh, before the plan reads it (N7-9).
- await worldcastContextNow();
- const start = () => createFlyAround(input);
- if (new URL(request.url).searchParams.get("preview")) return Response.json(await withPoolPrice(request, previewFlyAround(input), start, wishes.place));
- if (viewer.kind === "account") {
- return runToolForAccount(request, viewer.account, {
- tool: "fly-around",
- files: bodyFiles(input),
- requestId,
- wishes,
- start,
- ok: (value, gpuWarning) => Response.json({ ...value, ...(gpuWarning && { gpuWarning }) }, { status: 201 }),
- });
+ // The WorldCast worker's answer, fresh, before the plan reads it (N7-9). An account's run never uses it.
+ // An account's run never uses the studio's WorldCast worker, nor asks it anything.
+ if (toolViewer(request).kind !== "account") await worldcastContextNow();
- if (new URL(request.url).searchParams.get("preview")) return Response.json(previewFlyAround(input));
++ // With hosted runs on, a run that would go to this install's GPUs adds its place, price and line.
++ if (new URL(request.url).searchParams.get("preview")) return Response.json(await withPlanPrice(request, previewFlyAround(input), () => flyAroundSteps(planFlyAroundRun(input))));
+ const viewer = toolViewer(request);
+ if (viewer.kind !== "account") {
+ // A plan that can't run (FlyAroundError) is a 422 with its reason, as any planner's error is.
+ const result = await once("fly-around", requestId, () => createFlyAround(input));
+ return Response.json(result, { status: 201 });
}
- // A plan that can't run (FlyAroundError) is a 422 with its reason, as any planner's error is.
- const result = await once("fly-around", requestId, start);
- return Response.json(result, { status: 201 });
+ let run: FlyAroundRun | null = null;
+ return onceForAccount(
+ viewer.account,
+ "fly-around",
+ requestId,
+ () =>
+ runAccountTool(request, viewer.account, {
+ tool: "fly-around",
+ files: [input.image, input.render, ...(input.views ?? []), ...Object.values(input.sides ?? {})],
+ plan: () => flyAroundSteps((run = planFlyAroundRun(input))),
+ start: () => startFlyAround(run!),
+ }),
+ ({ value, gpuWarning }) => Response.json({ ...value, ...(gpuWarning && { gpuWarning }) }, { status: 201 }),
+ );
}, request);
}
diff --cc src/app/api/turnaround/route.ts
index 5f5726da,93e1eeb7..33950f2c
--- a/src/app/api/turnaround/route.ts
+++ b/src/app/api/turnaround/route.ts
@@@ -1,10 -1,8 +1,9 @@@
- import { bodyTooBig, guestRun, toolViewer, toolWishes } from "@/server/account-tool-run";
import { requestViewer } from "@/server/auth";
+ import { bodyTooBig, guestRun, onceForAccount, priceAsRun, runAccountTool, toolViewer } from "@/server/account-tool-run";
import { recordExists } from "@/server/records";
import { body, handle, once } from "@/server/shorts-schemas";
- import { bodyFiles, runToolForAccount, withPoolPrice } from "@/server/tool-runs";
- import { createTurnaround, previewTurnaround, TurnaroundBodySchema, turnaroundRun } from "@/server/turnaround";
- import { priceAs } from "@/server/visitor";
+ import { createTurnaround, planTurnaroundRun, previewTurnaround, startTurnaround, TurnaroundBodySchema, turnaroundRun, turnaroundSteps, type TurnaroundRun } from "@/server/turnaround";
++import { withPlanPrice } from "@/server/tool-runs";
import { worldcastContextNow } from "@/server/worldcast-on";
/**
@@@ -22,23 -18,29 +19,30 @@@ async function post(request: Request)
if (input.elementId && (requestViewer(request).kind !== "owner" || !recordExists({ kind: "element", ids: [input.elementId] }))) {
return Response.json({ error: "Character not found" }, { status: 404 });
}
- await worldcastContextNow();
+ // An account's run never uses the studio's WorldCast worker, nor asks it anything.
+ if (toolViewer(request).kind !== "account") await worldcastContextNow();
const run = turnaroundRun(input);
- const start = () => createTurnaround(run);
- if (new URL(request.url).searchParams.get("preview")) return Response.json(await withPoolPrice(request, previewTurnaround(run), start, wishes.place));
- if (new URL(request.url).searchParams.get("preview")) return Response.json(previewTurnaround(run));
++ // With hosted runs on, a run that would go to this install's GPUs adds its place, price and line.
++ if (new URL(request.url).searchParams.get("preview")) return Response.json(await withPlanPrice(request, previewTurnaround(run), () => turnaroundSteps(planTurnaroundRun(run))));
const viewer = toolViewer(request);
- if (viewer.kind === "account") {
- return runToolForAccount(request, viewer.account, {
- tool: "turnaround",
- files: bodyFiles(input),
- requestId,
- wishes,
- start,
- ok: (value, gpuWarning) => Response.json({ ...value, ...(gpuWarning && { gpuWarning }) }, { status: 201 }),
- });
+ if (viewer.kind !== "account") {
+ const result = await once("turnaround", requestId, () => createTurnaround(run));
+ return Response.json(result, { status: 201 });
}
- const result = await once("turnaround", requestId, start);
- return Response.json(result, { status: 201 });
+ let planned: TurnaroundRun | null = null;
+ return onceForAccount(
+ viewer.account,
+ "turnaround",
+ requestId,
+ () =>
+ runAccountTool(request, viewer.account, {
+ tool: "turnaround",
+ files: [...Object.values(input.views ?? {}), input.sheet],
+ plan: () => turnaroundSteps((planned = planTurnaroundRun(run))),
+ start: () => startTurnaround(planned!),
+ }),
+ ({ value, gpuWarning }) => Response.json({ ...value, ...(gpuWarning && { gpuWarning }) }, { status: 201 }),
+ );
});
}
diff --cc src/lib/guest-access.ts
index efb96b96,df3168be..a0c35cbb
--- a/src/lib/guest-access.ts
+++ b/src/lib/guest-access.ts
@@@ -295,14 -296,22 +296,26 @@@ export const ACCOUNT_TOOL_RUNS: readonl
/^\/api\/genjutsu\/describe$/,
// Character Swap Studio's jobs on an account's own project (src/server/swap-studio-account.ts).
/^\/api\/swap-studio\/projects\/[^/]+\/(anchors|assemble|clips|masks|prepare|queue|sharpen|transcribe)$/,
+ // Apps made in one go from the account's own pictures (src/server/tool-runs.ts): Turnaround and Fly around.
+ /^\/api\/(turnaround|fly-around)$/,
// Cinema Studio: a take in the account's own project, a retry and a 2K finish of one of its takes.
/^\/api\/cinema\/projects\/[^/]+\/(generate|items\/[^/]+\/(retry|finish))$/,
+ // The Image studio's palette lock: its images, then each recoloured to the palette (src/server/palettes.ts).
+ /^\/api\/palettes\/lock$/,
// The photo apps: Photodump, Fashion Factory, Character Sheet, AI Influencer, and a retry of its own photo.
/^\/api\/(photodump(\/(fashion|character|retry))?|influencer)$/,
+ // Video tools: Remove object (a mask preview, and "Redo from here" on its own removal), Evolution (its direction is
+ // Fuobe's offline writer's), Mixed Media (a preview frame, and "Try again" on its own render), Turnaround video and
+ // Fly around (Image to 3D's "Film it photoreal"), and Katana (a retry or Run again of its own run).
+ /^\/api\/remove-object(\/(preview|reroll))?$/,
+ /^\/api\/evolution(\/direction)?$/,
+ /^\/api\/mixed-media(\/(preview|retry))?$/,
+ /^\/api\/(turnaround|fly-around)$/,
+ /^\/api\/katana(\/[^/]+\/retry)?$/,
+ // Audio's tools (Split soundtrack, Clean up dialogue, Remove dialogue, Edit speech, Loop, Join, Clean up voice), and
+ // Translate & dub: a dub, and voicing one language of the account's own dub (src/server/dub.ts).
+ /^\/api\/audio-tools$/,
+ /^\/api\/dub(\/[^/]+\/voice)?$/,
];
/**
diff --cc src/server/tool-runs.ts
index e865b90f,00000000..0dd6a887
mode 100644,000000..100644
--- a/src/server/tool-runs.ts
+++ b/src/server/tool-runs.ts
@@@ -1,104 -1,0 +1,114 @@@
+import "server-only";
+import { onceForAccount, runAccountTool, toolPriceCheck, toolViewer, toolWishes, type ToolStep } from "./account-tool-run";
+import type { Account } from "./auth";
+import { db } from "./db";
+import { captureRun } from "./generations";
+import type { GenerationRequest } from "@/lib/catalog/types";
+import type { PlaceWish } from "./hosted-run";
+import { withoutStamp } from "./run-stamp";
+
+/**
+ * The apps and tools whose run is made in one go by a create function (createInfluencer, createPhotodump,
+ * createTurnaround, createFlyAround…: generations and pipelines, nothing else) open to accounts through the same checks
+ * as every tool run (account-tool-run.ts runAccountTool): their steps are what that create function would make, made in
+ * a transaction that is rolled back (nothing kept, nothing sent), then made for real once every check passed. With
+ * hosted runs on, the run may go to this install's GPUs as one run (placeOf).
+ */
+
+const ROLLED_BACK = Symbol("rolled back");
+
+const depCount = (v: string | null): number => (!v ? 0 : v.startsWith("[") ? (JSON.parse(v) as unknown[]).length : 1);
+
+/**
+ * A run's steps as `start` would make them: every row it makes (a chain's later steps too), with the earlier steps each
+ * waits for, made and thrown away inside one transaction. Call it in the run's own scope (asAccount, runOnPool). A start
+ * that awaits before it makes its rows can't be planned this way.
+ */
+export function dryRunSteps(start: () => unknown): ToolStep[] {
+ const d = db();
+ let steps: ToolStep[] = [];
+ try {
+ d.transaction(() => {
+ const made = captureRun(start);
+ if (made.value && typeof (made.value as { then?: unknown }).then === "function") throw new Error("A run that waits before it starts can't be planned here.");
+ const q = d.prepare("SELECT request_json, depends_on FROM generations WHERE id = ?");
+ steps = made.ids.flatMap((id) => {
+ const r = q.get(id) as { request_json: string; depends_on: string | null } | undefined;
+ return r ? [{ request: withoutStamp(JSON.parse(r.request_json) as GenerationRequest), deps: depCount(r.depends_on) }] : [];
+ });
+ throw ROLLED_BACK;
+ })();
+ } catch (e) {
+ if (e !== ROLLED_BACK) throw e;
+ }
+ return steps;
+}
+
+export interface ToolRoute<T> {
+ /** The tool, for the run limit's key and the logs. */
+ tool: string;
+ /** Every file the body names: only the account's own, or Fuobe's example files. */
+ files: (string | null | undefined)[];
+ /** A client nonce: a repeat of it gets the first run. */
+ requestId?: string;
+ /** Makes the run (createInfluencer…), inside the account's scope. */
+ start: () => T;
+ /** The route's answer for the started run. */
+ ok: (value: T, gpuWarning?: string) => Response;
+ skipGpuCheck?: boolean;
+ /** The place and price the body carries (account-tool-run.ts toolWishes, read before the route reads the body). */
+ wishes?: Awaited<ReturnType<typeof toolWishes>>;
+}
+
+/** An account's run of such a tool: its steps planned from `start`, checked, placed and started (runAccountTool). */
+export async function runToolForAccount<T>(request: Request, account: Account, o: ToolRoute<T>): Promise<Response> {
+ return onceForAccount(
+ account,
+ o.tool,
+ o.requestId,
+ () =>
+ runAccountTool(request, account, {
+ tool: o.tool,
+ files: o.files,
+ plan: () => dryRunSteps(o.start),
+ start: o.start,
+ skipGpuCheck: o.skipGpuCheck,
+ ...o.wishes,
+ }),
+ ({ value, gpuWarning }) => o.ok(value, gpuWarning),
+ );
+}
+
+/**
+ * A tool's price check (`?preview=1`) with its place on this install's GPUs added when the run would go there:
+ * `{ place: "pool", quote, line }` beside the tool's own answer (an account's or a guest's; the owner's as always).
+ */
+export async function withPoolPrice(request: Request, answer: object, start: () => unknown, wish?: PlaceWish): Promise<object> {
+ if (toolViewer(request).kind === "owner" || "error" in answer) return answer;
+ const pool = await toolPriceCheck(request, () => dryRunSteps(start), wish);
+ return pool ? { ...answer, ...pool } : answer;
+}
+
++/**
++ * The same, for a tool that plans its steps itself (turnaroundSteps, flyAroundSteps…): `plan` gives the run's steps as
++ * the viewer's run plans them. The place and price come from the request's headers when the body has no field for them.
++ */
++export async function withPlanPrice(request: Request, answer: unknown, plan: () => ToolStep[] | Promise<ToolStep[]>): Promise<unknown> {
++ if (toolViewer(request).kind === "owner" || !answer || typeof answer !== "object" || "error" in answer) return answer;
++ const pool = await toolPriceCheck(request, plan);
++ return pool ? { ...answer, ...pool } : answer;
++}
++
+/** Every stored file a body names (`/api/files/…`), wherever it sits: the files an account's run must own. */
+export function bodyFiles(value: unknown): string[] {
+ const out = new Set<string>();
+ const walk = (v: unknown, depth: number) => {
+ if (depth > 8) return;
+ if (typeof v === "string") {
+ if (v.startsWith("/api/files/")) out.add(v);
+ } else if (Array.isArray(v)) for (const x of v) walk(x, depth + 1);
+ else if (v && typeof v === "object") for (const x of Object.values(v)) walk(x, depth + 1);
+ };
+ walk(value, 0);
+ return [...out];
+}