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
/**
* The one next step of a setup, in plain words for the person's AI: what Fuobe sees, what to do, and where the guide
* shows it. The status (GET /api/setup/<code>) and the panel's "Stuck?" say the same. Every word comes from the tables
* here; only fixed words, whole numbers and the studio's own address go into them. ASCII only. Pure.
*/
import { FUOBE_CONNECT, trustedByDefault } from "@/lib/fuobe-connect";
import { COMFY_PORTS } from "@/lib/local-comfy";
import { FIRST_MODEL_NAME } from "./first-picture";
import type { AddressCause, InstallKind, SetupView } from "./facts";
import { RESTART_WAIT_MIN } from "./restart";
import { isConnected, isDone, isPairing } from "./steps";
import { aiSetupHref, type BrowserName, type Os, type Way } from "./ways";
export interface NextStep {
id: string;
/** What Fuobe sees and what to do, in one or two sentences. */
say: string;
/** How, line by line (may be empty). */
how: string[];
/** The guide's part that shows it. */
guide: string;
}
/** The guide's step that gets a first picture model, and the one that stops the tunnel, by way. */
export const MODEL_STEP: Record<Way, number> = { direct: 6, address: 5, connect: 4 };
export const STOP_STEP = 6;
/** How long the tab may be quiet before the status says it isn't open (it reports at least every 25 s). */
export const TAB_QUIET_MS = 40_000;
const BLOCKED_HOW: Record<BrowserName, string> = {
chrome: "Chrome: click the icon to the left of the address, turn on Apps on device, then reload the Fuobe tab.",
edge: "Edge: click the icon to the left of the address, turn on Apps on device, then reload the Fuobe tab.",
opera: "Opera: click the icon to the left of the address, allow apps on this device, then reload the Fuobe tab.",
firefox: "Firefox: click the icon to the left of the address, allow apps and services on this device, then reload the Fuobe tab.",
brave: "Brave: click the Brave icon next to the address, allow localhost access, then reload the Fuobe tab.",
safari: "Safari can't reach ComfyUI from a website. Ask the person to choose A web address in Fuobe.",
other: "Click the icon to the left of the address, allow apps on this device, then reload the Fuobe tab.",
};
const SETTING_HOW: Record<InstallKind, string> = {
desktop: "ComfyUI Desktop: Settings (the gear, bottom left), then Server-Config. Put {site} in Enable CORS header, and nothing else. Restart when it asks.",
portable:
"Portable or Easy-Install: the easiest way is Fuobe's start file (guide Step 3). It adds the guard and the setting, keeps the other settings, and asks before it restarts ComfyUI. The person can also press Download start file in Fuobe.",
"stability-matrix": "Stability Matrix: Packages, then ComfyUI's three-dot menu, then Launch Options. Add --enable-cors-header {site} to Extra Launch Arguments. Stop ComfyUI and launch it again.",
terminal: "Started from a terminal: stop ComfyUI with Ctrl+C in its window, then start it with the same command plus --enable-cors-header {site}.",
};
const GUARD_HOW: Record<InstallKind, string | null> = {
desktop: "Put fuobe_guard.py in the custom_nodes folder of the ComfyUI folder (Documents -> ComfyUI, unless the person chose another one).",
portable: null,
"stability-matrix": "Put fuobe_guard.py in ComfyUI's custom_nodes folder (ComfyUI's three-dot menu, then Open in Explorer or Open in Finder).",
terminal: "Put fuobe_guard.py in ComfyUI's custom_nodes folder.",
};
const ADDRESS_SAY: Record<AddressCause, string> = {
local: "That address only works on the person's own network. Use the address that ends in trycloudflare.com.",
"not-found": "Fuobe couldn't find that address. Make sure that the person pasted the whole address that cloudflared made, and that cloudflared is still running.",
"no-answer":
"Nothing answered at that address. Make sure that ComfyUI and cloudflared are both running, and that the port in the cloudflared command is ComfyUI's port. A new address can take up to a minute to work.",
"not-comfy": "That address isn't a ComfyUI. Make sure that the port in the cloudflared command is ComfyUI's port.",
password:
"Something in front of ComfyUI asks for a password or a token. Keep that protection. Ask the person to type the token in Access token, under the address in Fuobe, then press Connect again. Fuobe sends it as a Bearer token. If it is a sign-in page, Fuobe can't pass it: ask the person what they want to do. Don't ask for the token in this chat.",
format: "Fuobe couldn't use that address. Ask the person what Fuobe says under the box.",
unknown: "Fuobe couldn't use that address. Ask the person what Fuobe says under the box.",
};
/** ComfyUI runs on the processor: how to let it use the graphics card, by computer. */
const CPU_HOW: Record<Os, string[]> = {
windows: [
"If nvidia-smi (guide Step 0) shows an NVIDIA card, ComfyUI's PyTorch can't use it. Portable or Easy-Install: start ComfyUI with run_nvidia_gpu.bat, not run_cpu.bat. Other installs: install the CUDA build of PyTorch, as ComfyUI's own page shows (https://github.com/comfyanonymous/ComfyUI, the part named Manual Install).",
],
linux: [
"If nvidia-smi (guide Step 0) shows an NVIDIA card, ComfyUI's PyTorch can't use it. Install the CUDA build of PyTorch in ComfyUI's Python, as ComfyUI's own page shows (https://github.com/comfyanonymous/ComfyUI, the part named Manual Install).",
],
mac: [
"On Apple silicon, ComfyUI uses the GPU through PyTorch's mps. Install a PyTorch with mps, as ComfyUI's own page shows (https://github.com/comfyanonymous/ComfyUI, the part named Apple Mac silicon). On an Intel Mac, ComfyUI can only use the processor.",
],
other: ["If the computer has a graphics card, ComfyUI's PyTorch can't use it. Install the PyTorch build for that card, as ComfyUI's own page shows (https://github.com/comfyanonymous/ComfyUI)."],
};
/** ComfyUI was started with --cpu: start it again without it (guide Step 1 says where the flag is). */
const CPU_FLAG_HOW = (os: Os, way: Way): string[] => [
"ComfyUI was started with --cpu. Start it again without --cpu. Guide Step 1 says where the flag is.",
...(os === "windows"
? [
"Portable: close ComfyUI's window, then start ComfyUI with run_nvidia_gpu.bat, not run_cpu.bat. Another start file: start ComfyUI with the same line without --cpu, from a new start file (don't change the person's own).",
...(way === "direct" ? ["Then run Fuobe's start file again (guide Step 3), so that Start ComfyUI for Fuobe.bat starts it without --cpu."] : []),
]
: ["Started from a terminal: the same command without --cpu. Stability Matrix: remove it in Launch Options."]),
];
const OWN_KEY ="With no usable graphics card, Fuobe also runs with the person's own fal.ai or Replicate key: {site}/settings, then Your keys.";
/** The page that ends a web address's setup on the computer: the box for the address, under the same code. */
const ADDRESS_PAGE = `{site}${aiSetupHref("address")}`;
/** On a phone, the address goes into Fuobe on the computer: how the person gets there. */
const ON_COMPUTER_HOW = [
`Ask the person to open ${ADDRESS_PAGE} in a browser on the computer that runs ComfyUI, and to sign in with the same account as on the phone.`,
"Fuobe shows the box Your ComfyUI's web address there, with the same setup code as on the phone. If the code is different, the person signed in with another account.",
"The person pastes the address there (it is on that computer's clipboard) and presses Connect.",
];
const curlOf = (os: Os) => (os === "windows" ? "curl.exe" : "curl");
/** A studio Fuobe Connect doesn't trust by itself (a self-hosted one): the person adds its address in ComfyUI. */
const ADD_STUDIO = "Fuobe Connect trusts https://fuobe.com by itself, not this studio. In ComfyUI, the person opens Settings, then Fuobe Connect, and enters {site} (guide Step 2).";
/** Fuobe Connect isn't in ComfyUI yet: where it comes from. */
const installHow = (site: string): string[] => [
`Clone ${FUOBE_CONNECT.gitUrl} into custom_nodes, or use the download in guide Step 2. ComfyUI-Manager's search may offer no version of Fuobe Connect to install.`,
...(trustedByDefault(site) ? [] : [ADD_STUDIO]),
];
/** Pairing: the code that ComfyUI shows, approved in Fuobe by the person. */
function pairHow(v: SetupView): string[] {
const own = !trustedByDefault(v.site);
return [
"In ComfyUI on the computer, the person opens Extensions (in ComfyUI's top menu), then Connect to Fuobe, and presses the Connect button. ComfyUI shows a code like ABCD-EFGH.",
`The person types that code into Fuobe${v.phone ? " on the phone" : ""}, in the box The code ComfyUI shows, and presses Approve. Or at {site}/connect?pair=1, signed in to the same account.`,
`On a computer with no screen, start ComfyUI with the environment variable FUOBE_CONNECT_PAIR=1${own ? " (and FUOBE_CONNECT_SITE={site})" : ""}. The code is then in ComfyUI's window or its log.`,
...(own ? [ADD_STUDIO] : []),
];
}
const gb = (tenths: number) => `${(tenths / 10).toFixed(tenths >= 100 ? 0 : 1)} GB`;
/** The status words' site: the studio's own address (never a visitor's word). */
const fill = (s: string, site: string) => s.replaceAll("{site}", site);
type Say = (id: string, words: string, how?: string[], step?: number) => NextStep;
/**
* No web address yet: start the tunnel, then paste its address into Fuobe on the computer. From a phone, or with the
* Fuobe page closed, the person opens the page that shows the box for it, signed in to the same account.
*/
function startTunnel(v: SetupView, say: Say, open: boolean): NextStep {
if (v.phone)
return say(
"start-tunnel",
"Fuobe doesn't have ComfyUI's web address yet. Start cloudflared (guide Steps 2 and 3). The address then goes into Fuobe on the computer, because it is on the computer's clipboard, not the phone's. Don't paste the address into this chat.",
ON_COMPUTER_HOW,
2,
);
return say(
"start-tunnel",
"Fuobe doesn't have ComfyUI's web address yet. Start cloudflared (guide Steps 2 and 3), then ask the person to paste the address into Your ComfyUI's web address in Fuobe and press Connect. Don't paste the address into this chat.",
open ? [] : [`The Fuobe page isn't open now. The person opens ${ADDRESS_PAGE} on this computer first, signed in to the same account.`],
2,
);
}
export function nextOf(v: SetupView, now: number): NextStep {
const { site, way, os } = v;
const t = v.tab;
const guide = (step?: number) => `${site}/api/setup/guide/${way}/${os}${step !== undefined ? `#step-${step}` : ""}`;
const say = (id: string, words: string, how: string[] = [], step?: number): NextStep => ({ id, say: fill(words, site), how: how.map((h) => fill(h, site)), guide: guide(step) });
// The Fuobe tab: its checks need it open. A web address that Fuobe doesn't have yet needs no tab until it is pasted
// (a phone's tab sleeps while the person reads their AI): the next step is the tunnel, and the page to paste it in.
// Pairing needs no tab either until the code is approved: the server sees the paired ComfyUI itself.
const quiet = !t || now - v.tabAt > TAB_QUIET_MS;
const pairs = isPairing(v);
if (quiet && !(way === "address" && v.server.gpu !== "link") && !pairs) {
if (t && !t.visible)
return say("wake-fuobe", "The Fuobe tab is asleep in the background, so Fuobe can't check. Ask the person to click on the Fuobe tab once, then come back to you.");
return way === "address"
? say("open-fuobe", `The Fuobe page isn't open. Ask the person to open ${ADDRESS_PAGE} in a browser on the computer that runs ComfyUI, signed in to the same account. The setup code stays the same.`)
: say(
"open-fuobe",
`The Fuobe page isn't open. Ask the person to open {site}${aiSetupHref(way)} in ${way === "connect" ? "a browser" : "Chrome, Edge or Firefox"} on the computer that runs ComfyUI, signed in to the same account. The setup code stays the same.`,
);
}
if (pairs) {
if (isDone(v))
return say("done", "Done. Fuobe uses this GPU now. Nothing else to do.", [
"Runs go to the paired ComfyUI while it runs, with no Fuobe tab open.",
`If ComfyUI has no picture model yet, guide Step ${MODEL_STEP.connect} lists one for each size of GPU. Ask the person first: the files are big.`,
]);
const blocked = t?.browser === "blocked" ? [`Or, to connect from this browser instead: ${BLOCKED_HOW[t.browserName ?? "other"]}`] : [];
return say(
"pair",
"Fuobe Connect pairs ComfyUI with the person's Fuobe account. If it isn't in ComfyUI yet, install it (guide Step 2) and restart ComfyUI. Then pair it (guide Step 3).",
[...pairHow(v), ...blocked],
2,
);
}
if (!t || quiet) return startTunnel(v, say, false);
if (isDone(v)) {
const keep =
way === "address"
? [
"Keep cloudflared running while runs go. Each time cloudflared starts again, it makes a new address: paste the new one in Fuobe.",
`Tell the person that closing the cloudflared window stops the address, and that anyone with the address can use ComfyUI while it runs. When they are done for the day, stop cloudflared (guide Step ${STOP_STEP}).`,
]
: way === "connect"
? ["Keep a Fuobe tab open on this computer while runs go.", "For runs with no Fuobe tab open, the person can also pair this ComfyUI with a code (guide Step 3)."]
: ["Keep a Fuobe tab open on this computer while runs go."];
return say("done", "Done. Fuobe uses this GPU now. Nothing else to do.", keep);
}
const connected = isConnected(v);
if (!connected) {
if (way === "address") {
const linked = v.server.gpu === "link";
if (t.address === "testing") return say("address-testing", "Fuobe is testing the address. Wait a few seconds, then check again.");
if (t.address === "failed") return say(`address-${t.addressCause ?? "unknown"}`, ADDRESS_SAY[t.addressCause ?? "unknown"], [], 3);
if (linked && v.server.online === false)
return say("link-offline", "Fuobe can't reach ComfyUI at the saved address. If cloudflared started again, it made a new address: the person pastes the new one in Fuobe.", [], 3);
if (linked) return say("checking-link", "Fuobe is checking the saved address. Wait a few seconds, then check again.");
return startTunnel(v, say, true);
}
if (t.browser === "unsupported") return say("use-address", "This browser can't reach ComfyUI from a website. Ask the person to choose A web address in Fuobe.");
if (t.browser === "ask")
return say(
"allow-browser",
"Fuobe hasn't looked for ComfyUI on this computer yet. If ComfyUI runs now, ask the person to press Let Fuobe look in Fuobe, and Allow if the browser asks. If ComfyUI isn't installed yet, start with guide Step 0, and ask for the press once it runs.",
[],
way === "connect" ? 3 : 5,
);
if (t.browser === "blocked")
return say("unblock-browser", "The browser blocks Fuobe from reaching apps on this computer.", [BLOCKED_HOW[t.browserName ?? "other"], "Or the person switches to A web address in Fuobe."], 5);
if (t.comfy === "none" && (t.quietMin ?? 0) >= RESTART_WAIT_MIN)
return say(
"not-back",
`ComfyUI stopped answering on port ${t.port ?? 8188} ${t.quietMin} min ago, and it hasn't come back. Ask the person to look at ComfyUI's window.`,
[
"If the window shows an error, read its last lines with the person, and fix that first.",
"If the window closed, start ComfyUI again: with Fuobe's start file if the person used it, else the way they always start it.",
"Fuobe finds ComfyUI again by itself as soon as it answers.",
],
1,
);
if (!t.comfy || t.comfy === "none")
return say(
"start-comfyui",
"Fuobe doesn't see ComfyUI on this computer. If ComfyUI is installed, start it. If it isn't, install it first (guide Step 0).",
[`Fuobe looks on ports ${COMFY_PORTS.slice(0, -1).join(", ")} and ${COMFY_PORTS[COMFY_PORTS.length - 1]}.`, "If ComfyUI uses another port, ask the person to type it under ComfyUI on another port? in Fuobe."],
0,
);
if (t.comfy === "other") return say("wrong-app", `Another app answers on port ${t.port ?? 8188}, not ComfyUI. Find ComfyUI's port in its window or its settings.`, [], 1);
if (t.comfy === "waiting")
return say(
"restarting",
`ComfyUI stopped answering on port ${t.port ?? 8188} ${t.quietMin ? `${t.quietMin} min ago` : "less than a minute ago"}. It is most likely starting again: a portable or Easy-Install ComfyUI can take up to ${RESTART_WAIT_MIN} minutes, while it loads its custom nodes. Wait 30 seconds, then check again. Don't start a second ComfyUI meanwhile.`,
["If the person closed ComfyUI, ask them to start it again.", `Fuobe says so if ComfyUI isn't back after ${RESTART_WAIT_MIN} minutes.`],
);
if (way === "connect") {
if (t.guard !== "connect" && t.comfy === "unreadable" && t.restarted)
return say(
"connect-not-loaded",
"ComfyUI restarted, but Fuobe still can't use it. ComfyUI didn't load Fuobe Connect.",
[
`The folder ${FUOBE_CONNECT.folder} in custom_nodes must hold __init__.py itself, not in a second folder inside it.`,
`${curlOf(v.os)} -s http://127.0.0.1:${t.port ?? 8188}/fuobe/connect answers {"connect": 1, ...} once ComfyUI loaded it. If it answers 404, read the last lines in ComfyUI's window with the person: they name each add-on that didn't load, and why.`,
...(trustedByDefault(site) ? [] : [ADD_STUDIO]),
],
2,
);
if (t.guard !== "connect") return say("install-connect", "Fuobe Connect isn't in ComfyUI yet. Install it (guide Step 2), then restart ComfyUI.", installHow(site), 2);
if (t.listen) return say("remove-listen", "ComfyUI listens on the network (--listen). Fuobe doesn't need that, and it lets other computers use ComfyUI. Restart ComfyUI without --listen.");
return say("connecting", "Fuobe sees ComfyUI and is connecting. Wait a few seconds, then check again.");
}
if (t.comfy === "unreadable") {
if (t.restarted)
return say(
"setting-not-taken",
"ComfyUI restarted, but it still doesn't let Fuobe in. The setting didn't take.",
[
"The value must be exactly {site}: https, no www, no slash at the end and nothing after it.",
"In ComfyUI Desktop, the Enable CORS header box holds only {site}.",
"Make sure that ComfyUI was started with the new start file or command. An auto-restart window can start it again the old way.",
],
3,
);
const install = t.install;
const how = install ? [SETTING_HOW[install], ...(GUARD_HOW[install] ? [GUARD_HOW[install]!] : [])] : Object.values(SETTING_HOW);
return say(
"add-setting",
`ComfyUI is running on port ${t.port ?? 8188}, but it doesn't let Fuobe in yet. Add Fuobe's guard to custom_nodes, then restart ComfyUI with --enable-cors-header {site}.`,
how,
2,
);
}
// Found: Fuobe can read it.
if (t.listen) return say("remove-listen", "ComfyUI listens on the network (--listen). Fuobe doesn't need that, and it lets other computers use ComfyUI. Restart ComfyUI without --listen.", [], 3);
if (t.cors === "any") return say("fix-any", "ComfyUI lets every website in. Restart it with --enable-cors-header {site} in place of * or the empty setting.", [], 3);
if (t.cors === "other") return say("fix-setting", "ComfyUI's --enable-cors-header names another site. Restart it with --enable-cors-header {site}.", [], 3);
if (t.guard === "none" && !t.guardSkipped)
return say(
"add-guard",
"Fuobe is allowed in, but Fuobe's guard is not in custom_nodes yet. Without it, other websites can use ComfyUI too. Add the guard, then restart ComfyUI once more.",
[],
2,
);
return say("connecting", "Fuobe sees ComfyUI and is connecting. Wait a few seconds, then check again.");
}
// Connected: a picture model, then the first picture.
const cpu = t.cpu ? " ComfyUI runs on the processor, not a graphics card, so a picture takes minutes." : "";
if (t.picture === "running") return say("picture-running", `Fuobe is making the first picture on this GPU. Wait, then check again.${cpu}`);
if (t.picture === "failed")
return t.pictureCause === "out-of-memory"
? say("picture-failed", "The first picture ran out of GPU memory. Close other apps that use the GPU, then ask the person to press Make your first picture again.")
: say("picture-failed", "The first picture didn't finish. Ask the person what Fuobe says, then to press Make your first picture again.");
if (t.model === "download")
return say(
"get-model",
`ComfyUI is connected, but it has no picture model Fuobe can use yet. The one that fits is ${t.modelId ? FIRST_MODEL_NAME[t.modelId] : "Z-Image Turbo"}, a download of ${gb(t.modelGbTenths ?? 0)}. Ask the person first, then download it (guide Step ${MODEL_STEP[way]}).`,
["The person can also press Copy download commands in Fuobe and run them."],
MODEL_STEP[way],
);
if (t.model === "none") {
if (t.cpu)
return say(
"cpu-only",
"ComfyUI runs on the computer's processor, not on a graphics card. Fuobe's picture models need a graphics card (the smallest, SDXL, needs 8 GB), so none fits, and on the processor one picture would take many minutes. Tell the person plainly. If the computer has a graphics card, make ComfyUI use it, restart ComfyUI (ask the person first), then check again.",
[
...(t.cpuFlag ? CPU_FLAG_HOW(os, way) : CPU_HOW[os]),
...(way === "address" ? ["The web address stays the same while cloudflared runs: the person doesn't paste it again after ComfyUI restarts."] : []),
OWN_KEY,
],
t.cpuFlag ? 1 : 0,
);
if (t.modelWhy === "setup")
return say(
"model-setup",
"None of the small picture models Fuobe starts with is ready, and each needs more than one download on this ComfyUI, most often a newer ComfyUI. Update ComfyUI (ask the person first: it restarts), then check again.",
);
return say("no-model-fits", "This GPU has too little memory for the small picture models Fuobe starts with (the smallest, SDXL, needs 8 GB). Tell the person plainly.", [OWN_KEY], 0);
}
if (t.model !== "ready") return say("checking-models", "ComfyUI is connected. Fuobe is checking which models it has. Wait a few seconds, then check again.");
return say("make-picture", `ComfyUI is connected and has a picture model. Ask the person to press Make your first picture in Fuobe.${cpu}`);
}