Fix ComfyExtension types (#778)

This commit is contained in:
Chenlei Hu
2024-09-11 10:43:01 +09:00
committed by GitHub
parent 06a05cb283
commit 8ce7b515a3
6 changed files with 29 additions and 23 deletions

40
src/types/comfy.d.ts vendored
View File

@@ -2,6 +2,16 @@ import { LGraphNode, IWidget } from './litegraph'
import { ComfyApp } from '../scripts/app'
import type { ComfyNodeDef } from '@/types/apiTypes'
export type Widgets = Record<
string,
(
node,
inputName,
inputData,
app?: ComfyApp
) => { widget?: IWidget; minWidth?: number; minHeight?: number }
>
export interface ComfyExtension {
/**
* The name of the extension
@@ -11,12 +21,12 @@ export interface ComfyExtension {
* 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>
init?(app: ComfyApp): Promise<void> | void
/**
* Allows any additional setup, called after the application is fully set up and running
* @param app The ComfyUI app instance
*/
setup?(app: ComfyApp): Promise<void>
setup?(app: ComfyApp): Promise<void> | void
/**
* Called before nodes are registered with the graph
* @param defs The collection of node definitions, add custom ones or edit existing ones
@@ -25,25 +35,13 @@ export interface ComfyExtension {
addCustomNodeDefs?(
defs: Record<string, ComfyObjectInfo>,
app: ComfyApp
): Promise<void>
): Promise<void> | 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 }
>
>
getCustomWidgets?(app: ComfyApp): Promise<Widgets> | Widgets
/**
* Allows the extension to add additional handling to the node before it is registered with **LGraph**
* @param nodeType The node class (not an instance)
@@ -54,7 +52,7 @@ export interface ComfyExtension {
nodeType: typeof LGraphNode,
nodeData: ComfyObjectInfo,
app: ComfyApp
): Promise<void>
): Promise<void> | void
/**
* Allows the extension to modify the node definitions before they are used in the Vue app
@@ -71,7 +69,7 @@ export interface ComfyExtension {
*
* @param app The ComfyUI app instance
*/
registerCustomNodes?(app: ComfyApp): Promise<void>
registerCustomNodes?(app: ComfyApp): Promise<void> | 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
@@ -79,13 +77,15 @@ export interface ComfyExtension {
* @param node The node that has been loaded
* @param app The ComfyUI app instance
*/
loadedGraphNode?(node: LGraphNode, app: ComfyApp)
loadedGraphNode?(node: LGraphNode, app: ComfyApp): void
/**
* 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: LGraphNode, app: ComfyApp)
nodeCreated?(node: LGraphNode, app: ComfyApp): void
[key: string]: any
}
export type ComfyObjectInfo = {