File size: 6,378 Bytes
4450790
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
import type { LGraphGroup as TLGraphGroup, LGraphNode as TLGraphNode, IWidget, SerializedLGraphNode, LGraph as TLGraph, LGraphCanvas as TLGraphCanvas, LiteGraph as TLiteGraph } from "./litegraph.js";
import type {Constructor, SerializedGraph} from './index.js';

declare global {
  const LiteGraph: typeof TLiteGraph;
	const LGraph: typeof TLGraph;
	const LGraphNode: typeof TLGraphNode;
	const LGraphCanvas: typeof TLGraphCanvas;
	const LGraphGroup: typeof TLGraphGroup;
}

// @rgthree: Types on ComfyApp as needed.
export interface ComfyApp {
	extensions: ComfyExtension[];
	async queuePrompt(number?: number, batchCount = 1): Promise<void>;
	graph: TLGraph;
	canvas: TLGraphCanvas;
	clean() : void;
 	registerExtension(extension: ComfyExtension): void;
	getPreviewFormatParam(): string;
	getRandParam(): string;
	loadApiJson(apiData: {}, fileName: string): void;
	async graphToPrompt(graph?: TLGraph, clean?: boolean): Promise<void>;
	// workflow: ComfyWorkflowInstance ???
	async loadGraphData(graphData: {}, clean?: boolean, restore_view?: boolean, workflow?: any|null): Promise<void>
	ui: {
		settings: {
			addSetting(config: {id: string, name: string, type: () => HTMLElement}) : void;
		}
	}
	// Just marking as any for now.
	menu?: any;
}

export interface ComfyWidget extends IWidget {
	// https://github.com/comfyanonymous/ComfyUI/issues/2193 Changes from SerializedLGraphNode to
	// LGraphNode...
	serializeValue(nodeType: TLGraphNode, index: number): Promise<TValue>;
	afterQueued(): void;
	inputEl?: HTMLTextAreaElement;
	width: number;
}

export interface ComfyGraphNode extends TLGraphNode {
	getExtraMenuOptions: (node: TLGraphNode, options: ContextMenuItem[]) => void;
	onExecuted(message: any): void;
}

export interface ComfyNode extends TLGraphNode {
	comfyClass: string;
}

// @rgthree
export interface ComfyNodeConstructor extends Constructor<ComfyNode> {
	static title: string;
	static type?: string;
	static comfyClass: string;
}

export type NodeMode = 0|1|2|3|4|undefined;


export interface ComfyExtension {
	/**
	 * The name of the extension
	 */
	name: string;
	/**
	 * Allows any initialisation, e.g. loading resources. Called after the canvas is created but before nodes are added
	 * @param app The ComfyUI app instance
	 */
	init?(app: ComfyApp): Promise<void>;
	/**
	 * Allows any additonal setup, called after the application is fully set up and running
	 * @param app The ComfyUI app instance
	 */
	setup?(app: ComfyApp): Promise<void>;
	/**
	 * Called before nodes are registered with the graph
	 * @param defs The collection of node definitions, add custom ones or edit existing ones
	 * @param app The ComfyUI app instance
	 */
	addCustomNodeDefs?(defs: Record<string, ComfyObjectInfo>, app: ComfyApp): Promise<void>;
	/**
	 * Allows the extension to add custom widgets
	 * @param app The ComfyUI app instance
	 * @returns An array of {[widget name]: widget data}
	 */
	getCustomWidgets?(
		app: ComfyApp
	): Promise<
		Record<string, (node, inputName, inputData, app) => { widget?: IWidget; minWidth?: number; minHeight?: number }>
	>;
	/**
	 * Allows the extension to add additional handling to the node before it is registered with LGraph
	 * @rgthree changed nodeType from `typeof LGraphNode` to `ComfyNodeConstructor`
	 * @param nodeType The node class (not an instance)
	 * @param nodeData The original node object info config object
	 * @param app The ComfyUI app instance
	 */
	beforeRegisterNodeDef?(nodeType: ComfyNodeConstructor, nodeData: ComfyObjectInfo, app: ComfyApp): Promise<void>;
	/**
	 * Allows the extension to register additional nodes with LGraph after standard nodes are added
	 * @param app The ComfyUI app instance
	 */
	// @rgthree - add void for non async
	registerCustomNodes?(app: ComfyApp): void|Promise<void>;
	/**
	 * Allows the extension to modify a node that has been reloaded onto the graph.
	 * If you break something in the backend and want to patch workflows in the frontend
	 * This is the place to do this
	 * @param node The node that has been loaded
	 * @param app The ComfyUI app instance
	 */
	loadedGraphNode?(node: TLGraphNode, app: ComfyApp);
	/**
	 * Allows the extension to run code after the constructor of the node
	 * @param node The node that has been created
	 * @param app The ComfyUI app instance
	 */
	nodeCreated?(node: TLGraphNode, app: ComfyApp);
}

export type ComfyObjectInfo = {
	name: string;
	display_name?: string;
	description?: string;
	category: string;
	input?: {
		required?: Record<string, ComfyObjectInfoConfig>;
		optional?: Record<string, ComfyObjectInfoConfig>;
		hidden?: Record<string, ComfyObjectInfoConfig>;
	};
	output?: string[];
	output_name: string[];
	// @rgthree
	output_node?: boolean;
};

export type ComfyObjectInfoConfig = [string | any[]] | [string | any[], any];

// @rgthree
type ComfyApiInputLink = [
  /** The id string of the connected node. */
  string,
  /** The output index. */
  number,
]

// @rgthree
export type ComfyApiFormatNode = {
  "inputs": {
    [input_name: string]: string|number|boolean|ComfyApiInputLink,
  },
  "class_type": string,
  "_meta": {
    "title": string,
  }
}

// @rgthree
export type ComfyApiFormat = {
  [node_id: string]: ComfyApiFormatNode
}

// @rgthree
export type ComfyApiPrompt = {
  workflow: SerializedGraph,
  output: ComfyApiFormat,
}

// @rgthree
export type ComfyApiEventDetailStatus = {
  exec_info: {
    queue_remaining: number;
  };
};

// @rgthree
export type ComfyApiEventDetailExecutionStart = {
  prompt_id: string;
};

// @rgthree
export type ComfyApiEventDetailExecuting = null | string;

// @rgthree
export type ComfyApiEventDetailProgress = {
  node: string;
  prompt_id: string;
  max: number;
  value: number;
};

// @rgthree
export type ComfyApiEventDetailExecuted = {
  node: string;
  prompt_id: string;
  output: any;
};

// @rgthree
export type ComfyApiEventDetailCached = {
  nodes: string[];
  prompt_id: string;
};

// @rgthree
export type ComfyApiEventDetailExecuted = {
  prompt_id: string;
  node: string;
  output: any;
};

// @rgthree
export type ComfyApiEventDetailError = {
  prompt_id: string;
  exception_type: string;
  exception_message: string;
  node_id: string;
  node_type: string;
  node_id: string;
  traceback: string;
  executed: any[];
  current_inputs:  {[key: string]: (number[]|string[])};
  current_outputs: {[key: string]: (number[]|string[])};
}