@node-ai/comfyui
Version:
node-ai for comfyui
194 lines (193 loc) • 8.13 kB
TypeScript
import { ComfyClientConfig, ComfyConnectOptions, DirectoryType, DownloadProgressMessage, ExecutedMessage, ExecutingMessage, ExecutionCachedMessage, ExecutionErrorMessage, ExecutionInterruptedMessage, ExecutionStartMessage, Filename, ImageChanel, ImagePreview, ProgressMessage, StatusMessage } from '../types';
type ComfyUIClientEvents = {
status: [StatusMessage['data']['status'] | null];
/**
* execute events
*/
/**
* enqueue
* 任务入队成功,此时可能有部分分支验证错误
*/
enqueue: [ExecutionStartMessage['data']];
/**
* execution start
* 任务执行开始。prompt执行前通知
*/
execution_start: [ExecutionStartMessage['data']];
/**
* execution cached
* 任务执行已缓存。如果此节点在前面已经执行过,则会缓存此节点,在execution_start后会将已缓存所有节点通知
*/
execution_cached: [ExecutionCachedMessage['data']];
/**
* executing
* 节点开始执行
*/
executing: [ExecutingMessage['data']];
/**
* progress
* 节点进度
*/
progress: [ProgressMessage['data']];
/**
* executed
* 节点执行完成
*/
executed: [ExecutedMessage['data']];
/**
* execution interrupted
* 节点被打断
*/
execution_interrupted: [ExecutionInterruptedMessage['data']];
/**
* execution error
* 节点执行错误
*/
execution_error: [ExecutionErrorMessage['data']];
/**
* execution finish
* 任务执行完成
*/
execution_finish: [Omit<ExecutingMessage['data'], 'node'>];
/**
* model download progress
* 模型下载进度
*/
download_progress: [DownloadProgressMessage['data']];
/**
* unhandled
* 未处理消息
* type: 消息类型
* data: 消息数据
*/
unhandled: [type: string, data: any];
/**
* websocket events
*/
open: any;
error: [Error];
close: any;
message: [any];
reconnected: any;
reconnecting: any;
/**
* event for load image data from websocket
*/
image_data: [
{
image: ArrayBuffer;
mime: 'image/jpeg' | 'image/png' | 'image/webp' | string;
}
];
};
type EventValidTypes = string | symbol | object;
type EventNames<T extends EventValidTypes> = T extends string | symbol ? T : keyof T;
type EventArgumentMap<T extends object> = {
[K in keyof T]: T[K] extends (...args: any[]) => void ? Parameters<T[K]> : T[K] extends any[] ? T[K] : any[];
};
type EventListener<T extends EventValidTypes, K extends EventNames<T>> = T extends string | symbol ? (...args: any[]) => void : (...args: EventArgumentMap<Exclude<T, string | symbol>>[Extract<K, keyof T>]) => void;
export declare class ComfyUIWsClient {
#private;
private readonly config?;
private logError;
constructor(config?: ComfyClientConfig | undefined);
/**
* Generates the URL for the API endpoint based on the provided route.
*
* @param route - The route for the API endpoint.
* @return The generated URL for the API endpoint.
*/
apiURL(route: string): string;
/**
* Generates a URL for viewing a specific file with the given filename, subfolder, and type.
*
* @param filename - The name of the file to view.
* @param subfolder - The subfolder where the file is located.
* @param type - The type of the file.
* @param preview
* @param channel
* @return The URL for viewing the file.
*/
viewURL(filename: Filename, subfolder?: string, type?: DirectoryType, preview?: ImagePreview, channel?: ImageChanel): string;
/**
* Fetches API data based on the provided route and options.
*
* NOTE: CORS policy: Request header field comfy-user is not allowed by Access-Control-Allow-Headers in preflight response. Please use empty string in browser.
*
* @param route - The route for the API request.
* @param options - (Optional) Additional options for the request.
* @return A promise that resolves to the API response.
*/
fetchApi(route: string, options?: RequestInit): Promise<Response>;
/**
* Adds an event listener for the specified event type.
*
* @param type - The type of event to listen for.
* @param callback - The callback function to be executed when the event is triggered.
* @param options - (Optional) Additional options for the event listener.
* @return A function that removes the event listener when called.
*/
addEventListener<T extends EventNames<ComfyUIClientEvents>>(type: T, callback: EventListener<ComfyUIClientEvents, T>, options?: any): () => void;
/**
* Adds a once event listener for the specified event type.
*
* @param type - The type of event to listen for.
* @param callback - The callback function to be executed when the event is triggered.
* @param options - (Optional) Additional options for the event listener.
* @return A function that removes the event listener when called.
*/
addOnceEventListener<T extends EventNames<ComfyUIClientEvents>>(type: T, callback: EventListener<ComfyUIClientEvents, T>, options?: any): () => void;
/**
* Remove a event listener for the specified event type with callback.
* @param type
* @param callback
*/
removeEventListener<T extends EventNames<ComfyUIClientEvents>>(type: T, callback: EventListener<ComfyUIClientEvents, T>): void;
/**
* Adds an event listener for the specified event type. a shortcut of addEventListener
*
* @param type - The type of event to listen for.
* @param callback - The callback function to be executed when the event is triggered.
* @param options - (Optional) Additional options for the event listener.
* @return A function that removes the event listener when called.
*/
on<T extends EventNames<ComfyUIClientEvents>>(type: T, callback: EventListener<ComfyUIClientEvents, T>, options?: any): () => void;
/**
* Adds a once event listener for the specified event type. a shortcut of addOnceEventListener
*
* @param type - The type of event to listen for.
* @param callback - The callback function to be executed when the event is triggered.
* @param options - (Optional) Additional options for the event listener.
* @return A function that removes the event listener when called.
*/
once<T extends EventNames<ComfyUIClientEvents>>(type: T, callback: EventListener<ComfyUIClientEvents, T>, options?: any): () => void;
/**
* Remove a event listener for the specified event type with callback. a shortcut of removeEventListener
* @param type
* @param callback
*/
off<T extends EventNames<ComfyUIClientEvents>>(type: T, callback: EventListener<ComfyUIClientEvents, T>): void;
protected addSocketCallback<K extends keyof WebSocketEventMap>(socket: WebSocket, type: K, listener: (this: WebSocket, ev: WebSocketEventMap[K]) => any, options?: boolean | AddEventListenerOptions): () => void;
/**
* Removes all event listeners from the given WebSocket and clears the socket_callbacks object.
*/
protected removeSocketCallbacks(): void;
private loadImageData;
close(): void;
/**
* Connects to the WebSocket server by creating a new socket connection.
*
* @param options - The options for connecting to the server.
* @return - The instance of the class.
*/
connect({ polling, websocket, }?: ComfyConnectOptions): this;
waitForConnect(options?: ComfyConnectOptions): Promise<void>;
/**
* Disconnects the WebSocket connection and cleans up event listeners.
*/
disconnect(): void;
log: (level: "debug" | "info" | "log" | "trace" | "warn" | "error", message?: any, error?: Error) => void;
getFetchHeaders(options?: RequestInit): import("undici-types").HeadersInit | undefined;
protected doFetch(input: string | URL | globalThis.Request, init?: RequestInit): Promise<Response>;
}
export {};