|
| 1 | +import { LGraphNode, IWidget } from "./litegraph"; |
| 2 | +import { ComfyApp } from "/scripts/app"; |
| 3 | + |
| 4 | +export interface ComfyExtension { |
| 5 | + /** |
| 6 | + * The name of the extension |
| 7 | + */ |
| 8 | + name: string; |
| 9 | + /** |
| 10 | + * Allows any initialisation, e.g. loading resources. Called after the canvas is created but before nodes are added |
| 11 | + * @param app The ComfyUI app instance |
| 12 | + */ |
| 13 | + init(app: ComfyApp): Promise<void>; |
| 14 | + /** |
| 15 | + * Allows any additonal setup, called after the application is fully set up and running |
| 16 | + * @param app The ComfyUI app instance |
| 17 | + */ |
| 18 | + setup(app: ComfyApp): Promise<void>; |
| 19 | + /** |
| 20 | + * Called before nodes are registered with the graph |
| 21 | + * @param defs The collection of node definitions, add custom ones or edit existing ones |
| 22 | + * @param app The ComfyUI app instance |
| 23 | + */ |
| 24 | + addCustomNodeDefs(defs: Record<string, ComfyObjectInfo>, app: ComfyApp): Promise<void>; |
| 25 | + /** |
| 26 | + * Allows the extension to add custom widgets |
| 27 | + * @param app The ComfyUI app instance |
| 28 | + * @returns An array of {[widget name]: widget data} |
| 29 | + */ |
| 30 | + getCustomWidgets( |
| 31 | + app: ComfyApp |
| 32 | + ): Promise< |
| 33 | + Array< |
| 34 | + Record<string, (node, inputName, inputData, app) => { widget?: IWidget; minWidth?: number; minHeight?: number }> |
| 35 | + > |
| 36 | + >; |
| 37 | + /** |
| 38 | + * Allows the extension to add additional handling to the node before it is registered with LGraph |
| 39 | + * @param nodeType The node class (not an instance) |
| 40 | + * @param nodeData The original node object info config object |
| 41 | + * @param app The ComfyUI app instance |
| 42 | + */ |
| 43 | + beforeRegisterNodeDef(nodeType: typeof LGraphNode, nodeData: ComfyObjectInfo, app: ComfyApp): Promise<void>; |
| 44 | + /** |
| 45 | + * Allows the extension to register additional nodes with LGraph after standard nodes are added |
| 46 | + * @param app The ComfyUI app instance |
| 47 | + */ |
| 48 | + registerCustomNodes(app: ComfyApp): Promise<void>; |
| 49 | + /** |
| 50 | + * Allows the extension to modify a node that has been reloaded onto the graph. |
| 51 | + * If you break something in the backend and want to patch workflows in the frontend |
| 52 | + * This is the place to do this |
| 53 | + * @param node The node that has been loaded |
| 54 | + * @param app The ComfyUI app instance |
| 55 | + */ |
| 56 | + loadedGraphNode(node: LGraphNode, app: ComfyApp); |
| 57 | + /** |
| 58 | + * Allows the extension to run code after the constructor of the node |
| 59 | + * @param node The node that has been created |
| 60 | + * @param app The ComfyUI app instance |
| 61 | + */ |
| 62 | + nodeCreated(node: LGraphNode, app: ComfyApp); |
| 63 | +} |
| 64 | + |
| 65 | +export type ComfyObjectInfo = { |
| 66 | + name: string; |
| 67 | + display_name?: string; |
| 68 | + description?: string; |
| 69 | + category: string; |
| 70 | + input?: { |
| 71 | + required?: Record<string, ComfyObjectInfoConfig>; |
| 72 | + optional?: Record<string, ComfyObjectInfoConfig>; |
| 73 | + }; |
| 74 | + output?: string[]; |
| 75 | + output_name: string[]; |
| 76 | +}; |
| 77 | + |
| 78 | +export type ComfyObjectInfoConfig = [string | any[]] | [string | any[], any]; |
0 commit comments