Skip to content

Commit

Permalink
✨ add workflow.node support invalid class_name node
Browse files Browse the repository at this point in the history
  • Loading branch information
zhzLuke96 committed Aug 18, 2024
1 parent 83bc520 commit debd27a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stable-canvas/comfyui-client",
"version": "1.3.11",
"version": "1.3.12",
"description": "api Client for ComfyUI that supports both NodeJS and Browser environments. It provides full support for all RESTful / WebSocket APIs.",
"source": "src/main.ts",
"main": "dist/main.umd.js",
Expand Down
6 changes: 6 additions & 0 deletions scripts/build-node-types.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ function addInterface(nodeName, nodeSchema, namespace) {
},
],
});
} else {
nodeInterface.addProperty({
name: "inputs",
type: "{ [k: string]: unknown }",
hasQuestionToken: true,
});
}

let output_types = "";
Expand Down
45 changes: 34 additions & 11 deletions src/ComfyUIWorkflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,30 +131,53 @@ export class ComfyUIWorkflow {
};
protected _last_node_id = 0;

public classes = this._createClassesProxy();
public classes = this._createClassesProxy() as BuiltinNodeClasses &
Record<string, ComfyUINodeClass>;

protected _createClassesProxy() {
const source = {} as BuiltinNodeClasses & Record<string, ComfyUINodeClass>;
const source = {};
return new Proxy(source, {
get: (target, p, receiver) => {
if (p in target) {
return (target as any)[p];
}
return (inputs: Record<string, any>) => {
const node: WorkflowPromptNode = {
class_type: p.toString(),
inputs,
};
const id = (++this._last_node_id).toString();
this._workflow.prompt[id] = node;
return Array.from({ length: 10 }, (_, i) => {
return [id, i];
});
return this.node(p as any, inputs);
};
},
});
}

public node<
T extends keyof ComfyUINodeTypes.NodeTypes | (string & {}),
C extends T extends keyof ComfyUINodeTypes.NodeTypes
? Required<Required<ComfyUINodeTypes.NodeTypes>[T]>
: unknown,
>(
node_name: T,
inputs: C extends { inputs: infer INP } ? INP : Record<string, unknown>
): Iterable<NodeOutput>;
public node(
node_name: string,
inputs: Record<string, unknown>
): Iterable<NodeOutput> {
const node: WorkflowPromptNode = {
class_type: node_name,
inputs,
} as any;
const id = (++this._last_node_id).toString();
this._workflow.prompt[id] = node;

function* outputs() {
let i = 0;
while (true) {
yield [id, i++] as NodeOutput;
}
}

return outputs();
}

/**
* Resets the workflow by clearing the prompt and setting the workflow to undefined.
*/
Expand Down

0 comments on commit debd27a

Please sign in to comment.