@node-ai/comfyui
Version:
node-ai for comfyui
214 lines (213 loc) • 8.49 kB
TypeScript
import { ComfyClientConfig, DirectoryType, EnqueuePromptOptions, Filename, FolderName, HistoryResult, ImageChanel, ImagePreview, ImageReference, ObjectInfoResponse, PromptQueueResponse, QueuePromptResponse, QueueResponse, SystemStatsResponse, UpdateHistoryRequest, UpdateQueueRequest, UploadImageResult, UsersResponse, ViewMetadataResponse, WorkflowExecutedOutput, WorkflowPrompt } from '../types';
import { ComfyUIWsClient } from './comfyui.ws.client';
export declare class ComfyUIApiClient extends ComfyUIWsClient {
#private;
constructor(config?: ComfyClientConfig);
extractBody<T extends object | string | void>(response: Response, type?: keyof Pick<Response, 'json' | 'text' | 'arrayBuffer' | 'formData'>): Promise<T>;
/**
* Gets a list of extension urls
* @returns An array of script urls to import
*/
getExtensions(): Promise<string[]>;
/**
* Gets a list of embedding names
* @returns An array of embeddings
*/
getEmbeddings(): Promise<string[]>;
/**
* Gets a list of model types
* @returns An array of mode types
*/
getModelTypes(): Promise<string[]>;
/**
* Gets a list of model names
* @returns An array of modes
*/
getModels(folder: string): Promise<string[]>;
/**
* Get node object info
* @param nodeClass the specific node class name
*/
getObjectInfo(nodeClass?: string): Promise<ObjectInfoResponse>;
/**
* Clears the node object definitions cache
*/
resetCache(): void;
/**
* Gets all setting values for the current user
*/
getSettings(): Promise<Record<string, unknown>>;
/**
* Gets a setting for the current user
* @param id The id of the setting to fetch
*/
getSetting(id: string): Promise<unknown>;
/**
* put settings for the current user
*/
putSettings(settings: Record<string, unknown>): Promise<void>;
/**
* put a setting for the current user
*/
putSetting(id: string, value: unknown): Promise<void>;
/**
* get users
*/
getUsers(): Promise<UsersResponse>;
/**
* get users
*/
createUser(username: string): Promise<UsersResponse>;
/**
* List user data files in a specified directory.
* @param dir The directory to list files from.
* @param recurse If "true", recursively list files in subdirectories.
* @param fullInfo If "true", return detailed file information (path, size, modified time).
* @param split If "true", split file paths into components (only applies when full_info is false).
* @throws 400: If 'dir' parameter is missing.
* @throws 403: If the requested path is not allowed.
* @throws 404: If the requested directory does not exist.
* @throws 404: If the requested directory does not exist.
*/
getUserDataList(dir: string, recurse?: boolean, fullInfo?: false): Promise<string[]>;
getUserDataList(dir: string, recurse: boolean, fullInfo: true): Promise<Array<{
path: string;
size: number;
modified: number;
}>>;
/**
* Get a user data file for the current user
*/
getUserData(file: string): Promise<unknown>;
/**
* Put a user data file for the current user
*/
putUserData(file: string, data: any): Promise<void>;
/**
* Gets system & device stats
*/
getSystemStats(): Promise<SystemStatsResponse>;
/**
* Gets the queue info
*/
getPrompt(): Promise<PromptQueueResponse>;
/**
* Gets the prompt execution history
* @param promptId specific promptId
* @param maxItems max number of items
*/
getHistory(promptId?: string, maxItems?: number): Promise<HistoryResult>;
/**
* Update the history list
* @param params
*/
updateHistory(params: UpdateHistoryRequest): Promise<void>;
/**
* Gets the current state of the queue
* @returns The currently running and queued items
*/
getQueue(): Promise<QueueResponse>;
/**
* Update the queue
* @param params
*/
updateQueue(params: UpdateQueueRequest): Promise<string | void | object>;
/**
* Upload image
* @param image the image buffer to upload
* @param filename the image filename to upload
* @param overwrite whether overwrite when the filename is exists
* @param type the dir type
* @param subfolder the subfolder
*/
uploadImage(image: Buffer, filename: string, overwrite?: boolean, type?: DirectoryType, subfolder?: string): Promise<UploadImageResult>;
/**
* Upload mask,the output is the originalRef image apply the mask alpha
* @param image the mask image buffer to upload
* @param filename the image filename to upload
* @param originalRef the origin image ref
* @param overwrite whether overwrite when the filename is exists
* @param type the dir type
* @param subfolder the subfolder
*/
uploadMask(image: Buffer, filename: Filename, originalRef: ImageReference, overwrite?: boolean, type?: DirectoryType, subfolder?: string): Promise<UploadImageResult>;
/**
* view the image
* @param filename the image filename to view
* @param type the dir type
* @param subfolder the subfolder
* @param preview the preview type
* @param channel the channel
* @param arrayBuffer whether to return arrayBuffer
*/
viewImage(filename: Filename, type?: DirectoryType, subfolder?: string, preview?: ImagePreview, channel?: ImageChanel, arrayBuffer?: boolean): Promise<ArrayBuffer | Blob>;
/**
* view the model metadata
* @param folderName the model folder name
* @param filename the model filename
*/
viewMetadata(folderName: FolderName, filename: `${string}.safetensors`): Promise<ViewMetadataResponse>;
/**
* enqueue a prompt
* @param prompt The prompt to queue
* @param options
*/
queuePrompt(prompt: WorkflowPrompt, options?: EnqueuePromptOptions): Promise<QueuePromptResponse>;
/**
* Interrupts the execution of the running prompt
*/
interrupt(): Promise<void>;
/**
* Free up memory by unloading models and freeing memory
*/
free(unload_models?: boolean, free_memory?: boolean): Promise<void>;
/**
* Asynchronously waits for the prompt with the provided ID to be done using WebSocket.
*
* @param prompt_id - The ID of the prompt to wait for.
* @param options - The options for wait for the prompt
* @return A promise that resolves to a WorkflowOutput object containing the images and prompt_id.
*/
waitForPromptWebSocket(prompt_id: string, options?: EnqueuePromptOptions): Promise<WorkflowExecutedOutput>;
/**
* Randomizes the seed value of nodes with class type "KSampler" in the prompt.
*
* @param prompt - The prompt object to randomize.
*/
private randomizePrompt;
/**
* Asynchronously enqueues a prompt with optional workflow and random seed.
*
* @param prompt - The prompt to enqueue.
* @param [options] - The options for enqueueing the prompt.
* @return A promise that resolves with the enqueued prompt response.
* @throws If there is an error in the response.
*/
protected _enqueue_prompt(prompt: WorkflowPrompt, options?: EnqueuePromptOptions): Promise<QueuePromptResponse>;
/**
* Enqueues a prompt and waits for the corresponding prompt websocket.
*
* @param prompt - The prompt to enqueue.
* @param [options] - The options for enqueueing the prompt.
* @return A promise that resolves with the prompt result.
*/
enqueue(prompt: WorkflowPrompt, options?: EnqueuePromptOptions): Promise<WorkflowExecutedOutput>;
execPromptAndWaitOutputs(prompt: WorkflowPrompt, currentNodeId: number): Promise<Record<string, any>>;
internalGetFiles(directory: 'models' | 'user' | 'output'): Promise<{
name: string;
path: string;
type: "file" | "directory";
size: number;
}[]>;
internalGetLogs(): Promise<string>;
internalGetFolderPaths(): Promise<Record<string, string>[]>;
/**
* download model
* @param url
* @param modelDirectory
* @param folderPath
* @param modelFilename
* @param progressInterval
*/
internalDownloadModel(url: string, modelDirectory: string, folderPath: string, modelFilename: string, progressInterval?: number): Promise<string>;
}