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
import { connection } from "next/server";
import { setupCode } from "@/lib/ai-setup/code";
import { ownSetup, waitSetup } from "@/server/ai-setup";
import { inMinutes, SETUP_HEADERS, tooMany } from "@/server/ai-setup-http";
import { requestAccount } from "@/server/auth";
import { hit } from "@/server/rate";
/**
* The account's open tab waits here (up to 25 s) for its AI to read the status: `poke: true` asks for a fresh look at
* its ComfyUI and a report. `slow`: the server holds too many waits, so the tab reports every 10 s instead. `?tab=`:
* the tab's id, so a tab that doesn't lead the setup never takes the leading tab's wait.
*/
export async function GET(request: Request, ctx: RouteContext<"/api/setup/session/[code]/wait">) {
await connection();
const account = requestAccount(request);
if (!account) return Response.json({ error: "Sign up to set it up with your AI." }, { status: 401, headers: SETUP_HEADERS });
const code = setupCode((await ctx.params).code);
const setup = code ? ownSetup(code, account.id) : null;
if (!setup) return Response.json({ error: "This setup code is not active." }, { status: 404, headers: SETUP_HEADERS });
const r = hit(`setup:wait:${account.id}`, 30, 60_000);
if (!r.ok) return tooMany(`Too many waits. Try again in ${inMinutes(r.retryAfterS)}.`, r.retryAfterS);
const tab = new URL(request.url).searchParams.get("tab");
const tabId = tab && /^[A-Za-z0-9_-]{8,40}$/.test(tab) ? tab : undefined;
return Response.json(await waitSetup(setup, request.signal, undefined, tabId), { headers: SETUP_HEADERS });
}