Skip to content

Commit 8cb54fa

Browse files
Merge branch 'jsdoc-types' of https://github.com/pythongosssss/ComfyUI
2 parents 73c3e11 + 2dd28d4 commit 8cb54fa

File tree

3 files changed

+1615
-5
lines changed

3 files changed

+1615
-5
lines changed

web/scripts/app.js

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,49 @@ import { api } from "./api.js";
44
import { defaultGraph } from "./defaultGraph.js";
55
import { getPngMetadata, importA1111 } from "./pnginfo.js";
66

7-
class ComfyApp {
8-
/**
9-
* List of {number, batchCount} entries to queue
7+
/**
8+
* @typedef {import("types/comfy").ComfyExtension} ComfyExtension
9+
*/
10+
11+
export class ComfyApp {
12+
/**
13+
* List of entries to queue
14+
* @type {{number: number, batchCount: number}[]}
1015
*/
1116
#queueItems = [];
1217
/**
1318
* If the queue is currently being processed
19+
* @type {boolean}
1420
*/
1521
#processingQueue = false;
1622

1723
constructor() {
1824
this.ui = new ComfyUI(this);
25+
26+
/**
27+
* List of extensions that are registered with the app
28+
* @type {ComfyExtension[]}
29+
*/
1930
this.extensions = [];
31+
32+
/**
33+
* Stores the execution output data for each node
34+
* @type {Record<string, any>}
35+
*/
2036
this.nodeOutputs = {};
37+
38+
39+
/**
40+
* If the shift key on the keyboard is pressed
41+
* @type {boolean}
42+
*/
2143
this.shiftDown = false;
2244
}
2345

2446
/**
2547
* Invoke an extension callback
26-
* @param {string} method The extension callback to execute
27-
* @param {...any} args Any arguments to pass to the callback
48+
* @param {keyof ComfyExtension} method The extension callback to execute
49+
* @param {any[]} args Any arguments to pass to the callback
2850
* @returns
2951
*/
3052
#invokeExtensions(method, ...args) {
@@ -1120,6 +1142,10 @@ class ComfyApp {
11201142
}
11211143
}
11221144

1145+
/**
1146+
* Registers a Comfy web extension with the app
1147+
* @param {ComfyExtension} extension
1148+
*/
11231149
registerExtension(extension) {
11241150
if (!extension.name) {
11251151
throw new Error("Extensions must have a 'name' property.");

web/types/comfy.d.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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

Comments
 (0)