From 6718198a2738c8988637dfc9dc6a82ff66bedded Mon Sep 17 00:00:00 2001 From: Dariusz L Date: Mon, 30 Jun 2025 00:35:37 +0200 Subject: [PATCH] Add documentation summaries for ComfyApi and ComfyApp Introduced two new documentation files: ComfyApi and ComfyApp. These files provide concise summaries of the main functions, properties, and event types for the ComfyApi and ComfyApp classes, aiding developers in understanding their usage and structure. --- Doc/ComfyApi | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++ Doc/ComfyApp | 72 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 168 insertions(+) create mode 100644 Doc/ComfyApi create mode 100644 Doc/ComfyApp diff --git a/Doc/ComfyApi b/Doc/ComfyApi new file mode 100644 index 0000000..d02ebe1 --- /dev/null +++ b/Doc/ComfyApi @@ -0,0 +1,96 @@ +# ComfyApi - Function Documentation Summary import { api } from "../../scripts/api.js"; + +## Basic Information + +ComfyApi is a class for communication with ComfyUI backend via WebSocket and REST API. + +## Main Functions: + +### Connection and Initialization + +- constructor() - Initializes API, sets host and base path +- init() - Starts WebSocket connection for real-time updates +- #createSocket() - Creates and manages WebSocket connection + +### URL Management + +- internalURL(route) - Generates URL for internal endpoints +- apiURL(route) - Generates URL for public API endpoints +- fileURL(route) - Generates URL for static files +- fetchApi(route, options) - Performs HTTP requests with automatic user headers + +### Event Handling + +- addEventListener(type, callback) - Listens for API events (status, executing, progress, etc.) +- removeEventListener(type, callback) - Removes event listeners +- dispatchCustomEvent(type, detail) - Emits custom events + +### Queue and Prompt Management + +- queuePrompt(number, data) - Adds prompt to execution queue +- getQueue() - Gets current queue state (Running/Pending) +- interrupt() - Interrupts currently executing prompt +- clearItems(type) - Clears queue or history +- deleteItem(type, id) - Removes item from queue or history + +### History and Statistics + +- getHistory(max_items) - Gets history of executed prompts +- getSystemStats() - Gets system statistics (Python, OS, GPU, etc.) +- getLogs() - Gets system logs +- getRawLogs() - Gets raw logs +- subscribeLogs(enabled) - Enables/disables log subscription + +### Model and Resource Management + +- getNodeDefs(options) - Gets definitions of available nodes +- getExtensions() - List of installed extensions +- getEmbeddings() - List of available embeddings +- getModelFolders() - List of model folders +- getModels(folder) - List of models in given folder +- viewMetadata(folder, model) - Metadata of specific model + +### Workflow Templates + +- getWorkflowTemplates() - Gets workflow templates from custom nodes +- getCoreWorkflowTemplates() - Gets core workflow templates + +### User Management + +- getUserConfig() - Gets user configuration +- createUser(username) - Creates new user +- getSettings() - Gets all user settings +- getSetting(id) - Gets specific setting +- storeSettings(settings) - Saves settings dictionary +- storeSetting(id, value) - Saves single setting + +### User Data + +- getUserData(file) - Gets user data file +- storeUserData(file, data, options) - Saves user data +- deleteUserData(file) - Deletes user data file +- moveUserData(source, dest) - Moves data file +- listUserDataFullInfo(dir) - Lists files with full information + +### Other + +- getFolderPaths() - Gets system folder paths +- getCustomNodesI18n() - Gets internationalization data for custom nodes + +## Important Properties + +- clientId - Client ID from WebSocket +- authToken - Authorization token for ComfyOrg account +- apiKey - API key for ComfyOrg account +- socket - Active WebSocket connection + +## WebSocket Event Types + +- status - System status +- executing - Currently executing node +- progress - Execution progress +- executed - Node executed +- execution_start/success/error/interrupted/cached - Execution events +- logs - System logs +- b_preview - Image preview (binary) +- reconnecting/reconnected - Connection events diff --git a/Doc/ComfyApp b/Doc/ComfyApp new file mode 100644 index 0000000..934b68a --- /dev/null +++ b/Doc/ComfyApp @@ -0,0 +1,72 @@ +## __Main ComfyApp Functions__ import { app, ComfyApp } from "../../scripts/app.js"; + +### __Application Management__ + +- `setup(canvasEl)` - Initializes the application on the page, loads extensions, registers nodes +- `resizeCanvas()` - Adjusts canvas size to window +- `clean()` - Clears application state (node outputs, image previews, errors) + +### __Workflow Management__ + +- `loadGraphData(graphData, clean, restore_view, workflow, options)` - Loads workflow data from JSON +- `loadApiJson(apiData, fileName)` - Loads workflow from API format +- `graphToPrompt(graph, options)` - Converts graph to prompt for execution +- `handleFile(file)` - Handles file loading (PNG, WebP, JSON, MP3, MP4, SVG, etc.) + +### __Execution__ + +- `queuePrompt(number, batchCount, queueNodeIds)` - Queues prompt for execution +- `registerNodes()` - Registers node definitions from backend +- `registerNodeDef(nodeId, nodeDef)` - Registers single node definition +- `refreshComboInNodes()` - Refreshes combo lists in nodes + +### __Node Management__ + +- `registerExtension(extension)` - Registers ComfyUI extension +- `updateVueAppNodeDefs(defs)` - Updates node definitions in Vue app +- `revokePreviews(nodeId)` - Frees memory for node previews + +### __Clipboard__ + +- `copyToClipspace(node)` - Copies node to clipboard +- `pasteFromClipspace(node)` - Pastes data from clipboard to node + +### __Position Conversion__ + +- `clientPosToCanvasPos(pos)` - Converts client position to canvas position +- `canvasPosToClientPos(pos)` - Converts canvas position to client position + +### __Error Handling__ + +- `showErrorOnFileLoad(file)` - Displays file loading error +- `#showMissingNodesError(missingNodeTypes)` - Shows missing nodes error +- `#showMissingModelsError(missingModels, paths)` - Shows missing models error + +### __Internal Handlers__ + +- `#addDropHandler()` - Handles drag and drop of files +- `#addProcessKeyHandler()` - Handles keyboard input +- `#addDrawNodeHandler()` - Modifies node drawing behavior +- `#addApiUpdateHandlers()` - Handles API updates +- `#addConfigureHandler()` - Graph configuration flag +- `#addAfterConfigureHandler()` - Post-configuration handling + +### __Deprecated Properties__ + +Many properties are marked as deprecated and redirect to appropriate stores: + +- `lastNodeErrors` → `useExecutionStore().lastNodeErrors` +- `lastExecutionError` → `useExecutionStore().lastExecutionError` +- `runningNodeId` → `useExecutionStore().executingNodeId` +- `shiftDown` → `useWorkspaceStore().shiftDown` +- `widgets` → `useWidgetStore().widgets` +- `extensions` → `useExtensionStore().extensions` + +### __Utility Functions__ + +- `sanitizeNodeName(string)` - Cleans node name from dangerous characters +- `getPreviewFormatParam()` - Returns preview format parameter +- `getRandParam()` - Returns random parameter for refresh +- `isApiJson(data)` - Checks if data is in API JSON format + +This application uses Vue and TypeScript composition pattern, where many functionalities are separated into different services and stores (e.g., `useExecutionStore`, `useWorkflowService`, `useExtensionService`, etc.).