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 type { GenerationFix, GenInput, MediaKind, ModelDef, ModelRoute, ProviderId } from "@/lib/catalog/types";
import type { Diagnosis } from "@/lib/diagnose";
export interface SubmitContext {
generationId: string;
model: ModelDef;
route: ModelRoute;
input: GenInput;
}
export interface SubmitResult {
externalId: string;
/** Provider-specific state needed for polling (status URLs, client ids...). */
meta?: Record<string, unknown>;
/** The exact payload sent, stored for debugging/reproducibility. */
payload?: unknown;
}
export interface RemoteOutput {
url: string;
draftId?: string;
kind?: MediaKind;
contentType?: string;
/** Text results (transcripts): the content; `url` is then a data:text/plain URI holding the same text. */
text?: string;
/** Structured extras for OutputFile.meta (layer name/z/bbox, cues, textBlocks, stem, 3D preview…). */
meta?: Record<string, unknown>;
/** Extra headers needed to download (e.g. auth for a private ComfyUI). */
headers?: Record<string, string>;
}
/**
* What a poll found. A job on someone's own computer (comfyui.ts) also says when it reached their ComfyUI (`sentAt`: the
* queue clock starts there, not while it waited for their tab), what to say if it waits too long (`timeoutError`), and
* what was missing when it failed (`fix`: the tile's "Fix it"). A job for the workers keeps its task's own clocks
* (`ownClocks`): the runner then sets no wait limit of its own, and ends it only past the deadline of the attempt a
* worker holds now (`deadline`: when, and how long that attempt may last).
*/
export type PollResult =
| {
state: "queued";
progress?: number;
message?: string;
sentAt?: number;
timeoutError?: string;
ownClocks?: true;
deadline?: { at: number; ms: number };
/** Jobs ahead of it in the queue (0: next). */
position?: number;
/** The job its GPU runs now (another one): a new one there is a queue that moves, and one job may take its own time. */
busyWith?: string;
}
| { state: "running"; progress?: number; message?: string; sentAt?: number; ownClocks?: true; deadline?: { at: number; ms: number } }
| { state: "succeeded"; outputs: RemoteOutput[]; message?: string }
/**
* `trouble`: an account's own GPU, why in plain words with what helps (src/lib/diagnose.ts). `lost`: its ComfyUI
* restarted and forgot the job, so the runner may send it once more.
*/
| { state: "failed"; error: string; fix?: GenerationFix; trouble?: Diagnosis; lost?: true; detail?: string };
export interface PollContext {
externalId: string;
meta: Record<string, unknown>;
route: ModelRoute;
model: ModelDef;
createdAt: number;
}
export interface ProviderAdapter {
id: ProviderId;
label: string;
isConfigured(): boolean;
/**
* Turn a local file into something the provider accepts (URL, data URI, uploaded filename). `route` is
* the route the file is for (ComfyUI uploads an isolated-worker workflow's inputs to that worker).
*/
prepareFile(data: Buffer, contentType: string, name: string, route?: ModelRoute): Promise<string>;
submit(ctx: SubmitContext): Promise<SubmitResult>;
poll(ctx: PollContext): Promise<PollResult>;
/** Stop the job there. fal.ai says what it did (CancelOutcome); the other providers say nothing. */
cancel?(ctx: PollContext): Promise<CancelOutcome | void>;
/**
* Lightweight connectivity check for the settings page. `focus` is the setting the person is
* checking (the Anthropic key, the isolated worker's address…), for a provider whose settings
* reach more than one server; the others ignore it.
*/
test?(opts?: { focus?: string }): Promise<{ ok: boolean; detail: string }>;
}
/**
* What a provider did with a cancel, when it says (fal.ai): took the job off its queue (it never runs), asked a running job
* to stop (it may still finish, and be charged), found it finished already (its result is there), had no such job for this
* key, or answered something else.
*/
export type CancelOutcome = "removed" | "requested" | "finished" | "gone" | "unknown";
export class ProviderError extends Error {
constructor(
message: string,
public readonly status?: number,
) {
super(message);
this.name = "ProviderError";
}
}