import type { ImageDimensions, ImageEditRequest, ImageGenerateRequest, ImageOperation, ImageProvider, ImageProviderCallContext, ImageProviderInfo, ImageResult } from '../types/images.js'; import type { AssetTransformer } from './transform.js'; /** One node of a ComfyUI API-format workflow. */ export interface ComfyNode { /** The node type, such as `KSampler`. */ class_type: string; /** Its inputs: literal values, or `[nodeId, outputIndex]` links to other nodes. */ inputs: Record; } /** A ComfyUI workflow in API format: nodes keyed by id. */ export type ComfyWorkflow = Record; /** An image uploaded to ComfyUI's input folder. */ export interface ComfyUploadedImage { /** File name ComfyUI assigned. */ name: string; /** Subfolder it was stored in. */ subfolder?: string; /** Folder type, usually `input`. */ type?: string; } /** What a workflow builder receives besides the request. */ export interface ComfyWorkflowContext { /** Whether it generates or edits. */ operation: ImageOperation; /** Uploaded input image, present for edits. */ input?: ComfyUploadedImage; /** Uploaded mask, already converted to white-is-editable, present for masked edits. */ mask?: ComfyUploadedImage; /** A seed to use when the request did not supply one, so every run is reproducible after the fact. */ seed: number; } /** * Builds the workflow graph for one request. * * ComfyUI has no fixed request shape — a workflow is an arbitrary graph — so the adapter owns the * queue-upload-poll-download protocol and the application owns the graph. The bundled * `comfyTextToImageWorkflow` and `comfyInpaintWorkflow` cover the stock Stable Diffusion shapes. */ export type ComfyWorkflowBuilder = (request: ImageGenerateRequest | ImageEditRequest, context: ComfyWorkflowContext) => ComfyWorkflow; /** Options for the ComfyUI image provider. */ export interface ComfyUIImageProviderConfig { /** ComfyUI server URL. Defaults to `http://127.0.0.1:8188`. */ baseUrl?: string; /** * Builds the workflow for each request. Defaults to the bundled text-to-image and inpaint * workflows. */ workflow?: ComfyWorkflowBuilder; /** Checkpoint used by the bundled workflows. */ checkpoint?: string; /** Replaces the global `fetch`. */ fetch?: typeof globalThis.fetch; /** Starting poll interval. Defaults to 500 ms; it backs off to `maxPollIntervalMs`. */ pollIntervalMs?: number; /** Longest poll interval, in milliseconds. Defaults to 5 seconds. */ maxPollIntervalMs?: number; /** Gives up waiting for the queue after this long. Defaults to 10 minutes. */ timeoutMs?: number; /** Sizes the server supports, reported as capabilities. */ dimensions?: readonly ImageDimensions[]; /** * Converts neutral masks to ComfyUI's white-is-editable form. Defaults to the bundled PNG * transformer, loaded on the first masked request. */ maskTransformer?: AssetTransformer; /** Headers added to every request, such as authorization for a proxied server. */ headers?: Record; /** Client id sent with queued prompts. Defaults to a random id. */ clientId?: string; } /** * A self-hosted ComfyUI server. * * Validates the neutral contract against a backend unlike either hosted API: work is queued and * polled rather than answered in the response, inputs are uploaded as files the graph refers to by * name, outputs are fetched by filename afterwards, and a cancelled request has to be removed from * the queue explicitly or it keeps consuming the GPU. */ export declare class ComfyUIImageProvider implements ImageProvider { private readonly config; /** Provider name, capabilities, and models. */ readonly info: ImageProviderInfo; private readonly baseUrl; private readonly fetchImplementation; private readonly workflow; private readonly clientId; constructor(config?: ComfyUIImageProviderConfig); /** Generates images by queueing the workflow and polling for its outputs. */ generate(request: ImageGenerateRequest, context: ImageProviderCallContext): Promise; /** Edits an image by uploading it, and any mask, then queueing the workflow. */ edit(request: ImageEditRequest, context: ImageProviderCallContext): Promise; private run; private waitForCompletion; private cancel; private upload; private download; private json; private send; private headers; } /** The stock Stable Diffusion text-to-image graph. */ export declare function comfyTextToImageWorkflow(request: ImageGenerateRequest | ImageEditRequest, context: ComfyWorkflowContext, checkpoint: string): ComfyWorkflow; /** * The stock inpainting graph. * * The mask arrives white-is-editable and is read from its red channel, which is what * `VAEEncodeForInpaint` treats as the region to repaint. Without a mask it degrades to a whole-image * img2img pass. */ export declare function comfyInpaintWorkflow(request: ImageGenerateRequest | ImageEditRequest, context: ComfyWorkflowContext, checkpoint: string): ComfyWorkflow;