@nodetool-ai/protocol 0.8.10 → 0.8.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.nodetool-build-stamp +1 -1
- package/dist/ai-video-production.d.ts +4 -0
- package/dist/ai-video-production.d.ts.map +1 -1
- package/dist/api-schemas/admin.d.ts +533 -0
- package/dist/api-schemas/admin.d.ts.map +1 -0
- package/dist/api-schemas/admin.js +172 -0
- package/dist/api-schemas/admin.js.map +1 -0
- package/dist/api-schemas/app-runs.d.ts +20 -0
- package/dist/api-schemas/app-runs.d.ts.map +1 -1
- package/dist/api-schemas/applications.d.ts +46 -0
- package/dist/api-schemas/applications.d.ts.map +1 -1
- package/dist/api-schemas/applications.js +4 -1
- package/dist/api-schemas/applications.js.map +1 -1
- package/dist/api-schemas/document-sharing.d.ts +21 -0
- package/dist/api-schemas/document-sharing.d.ts.map +1 -1
- package/dist/api-schemas/document-sharing.js +6 -1
- package/dist/api-schemas/document-sharing.js.map +1 -1
- package/dist/api-schemas/index.d.ts +2 -0
- package/dist/api-schemas/index.d.ts.map +1 -1
- package/dist/api-schemas/index.js +2 -0
- package/dist/api-schemas/index.js.map +1 -1
- package/dist/api-schemas/js-scripts.d.ts +1 -1
- package/dist/api-schemas/js-scripts.d.ts.map +1 -1
- package/dist/api-schemas/js-scripts.js +1 -1
- package/dist/api-schemas/js-scripts.js.map +1 -1
- package/dist/api-schemas/people.d.ts +27 -0
- package/dist/api-schemas/people.d.ts.map +1 -0
- package/dist/api-schemas/people.js +21 -0
- package/dist/api-schemas/people.js.map +1 -0
- package/dist/api-schemas/recipes.d.ts +4 -0
- package/dist/api-schemas/recipes.d.ts.map +1 -1
- package/dist/api-schemas/recipes.js +8 -2
- package/dist/api-schemas/recipes.js.map +1 -1
- package/dist/api-schemas/scripts.d.ts +56 -0
- package/dist/api-schemas/scripts.d.ts.map +1 -1
- package/dist/api-schemas/sdk-execution-v1.d.ts +1 -0
- package/dist/api-schemas/sdk-execution-v1.d.ts.map +1 -1
- package/dist/api-schemas/settings.d.ts +9 -0
- package/dist/api-schemas/settings.d.ts.map +1 -1
- package/dist/api-schemas/settings.js +13 -1
- package/dist/api-schemas/settings.js.map +1 -1
- package/dist/api-schemas/storyboards.d.ts +329 -0
- package/dist/api-schemas/storyboards.d.ts.map +1 -1
- package/dist/api-schemas/storyboards.js +20 -1
- package/dist/api-schemas/storyboards.js.map +1 -1
- package/dist/api-schemas/threads.d.ts +18 -0
- package/dist/api-schemas/threads.d.ts.map +1 -1
- package/dist/api-schemas/threads.js +5 -1
- package/dist/api-schemas/threads.js.map +1 -1
- package/dist/api-schemas/timeline-tool-contracts.d.ts +123 -0
- package/dist/api-schemas/timeline-tool-contracts.d.ts.map +1 -1
- package/dist/api-schemas/timeline-tool-params.d.ts +123 -0
- package/dist/api-schemas/timeline-tool-params.d.ts.map +1 -1
- package/dist/api-schemas/timeline-tool-params.js +113 -9
- package/dist/api-schemas/timeline-tool-params.js.map +1 -1
- package/dist/api-schemas/timeline.d.ts +4348 -170
- package/dist/api-schemas/timeline.d.ts.map +1 -1
- package/dist/api-schemas/timeline.js +186 -6
- package/dist/api-schemas/timeline.js.map +1 -1
- package/dist/api-schemas/workflows.d.ts +14 -0
- package/dist/api-schemas/workflows.d.ts.map +1 -1
- package/dist/api-schemas/workflows.js +6 -1
- package/dist/api-schemas/workflows.js.map +1 -1
- package/dist/api-types.d.ts +21 -5
- package/dist/api-types.d.ts.map +1 -1
- package/dist/api-types.js +16 -0
- package/dist/api-types.js.map +1 -1
- package/dist/audio-run.d.ts +14 -0
- package/dist/audio-run.d.ts.map +1 -0
- package/dist/audio-run.js +23 -0
- package/dist/audio-run.js.map +1 -0
- package/dist/builtin-packs.js +1 -1
- package/dist/builtin-packs.js.map +1 -1
- package/dist/caption-word.d.ts +4 -0
- package/dist/caption-word.d.ts.map +1 -1
- package/dist/caption-word.js +3 -1
- package/dist/caption-word.js.map +1 -1
- package/dist/cloud-profile.d.ts.map +1 -1
- package/dist/cloud-profile.js +3 -0
- package/dist/cloud-profile.js.map +1 -1
- package/dist/comfy-graph.d.ts +163 -0
- package/dist/comfy-graph.d.ts.map +1 -0
- package/dist/comfy-graph.js +658 -0
- package/dist/comfy-graph.js.map +1 -0
- package/dist/creative.d.ts +32 -1
- package/dist/creative.d.ts.map +1 -1
- package/dist/creative.js +19 -0
- package/dist/creative.js.map +1 -1
- package/dist/gemini-models.d.ts +39 -0
- package/dist/gemini-models.d.ts.map +1 -0
- package/dist/gemini-models.js +104 -0
- package/dist/gemini-models.js.map +1 -0
- package/dist/graph.d.ts +1 -0
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/local-providers.d.ts.map +1 -1
- package/dist/local-providers.js +17 -0
- package/dist/local-providers.js.map +1 -1
- package/dist/messages.d.ts +122 -0
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +40 -0
- package/dist/messages.js.map +1 -1
- package/dist/missing-runtime-package.d.ts +2 -1
- package/dist/missing-runtime-package.d.ts.map +1 -1
- package/dist/missing-runtime-package.js +16 -7
- package/dist/missing-runtime-package.js.map +1 -1
- package/dist/one-take.d.ts +36 -11
- package/dist/one-take.d.ts.map +1 -1
- package/dist/one-take.js +102 -52
- package/dist/one-take.js.map +1 -1
- package/dist/processing-messages.schema.json +170 -0
- package/dist/production-authoring.d.ts +12 -0
- package/dist/production-authoring.d.ts.map +1 -1
- package/dist/provider-failure.d.ts +42 -0
- package/dist/provider-failure.d.ts.map +1 -0
- package/dist/provider-failure.js +70 -0
- package/dist/provider-failure.js.map +1 -0
- package/dist/python-packs.d.ts.map +1 -1
- package/dist/python-packs.js +0 -6
- package/dist/python-packs.js.map +1 -1
- package/dist/reasoning-effort.d.ts +10 -4
- package/dist/reasoning-effort.d.ts.map +1 -1
- package/dist/reasoning-effort.js +39 -18
- package/dist/reasoning-effort.js.map +1 -1
- package/dist/render-record.d.ts +21 -0
- package/dist/render-record.d.ts.map +1 -1
- package/dist/render-record.js +32 -1
- package/dist/render-record.js.map +1 -1
- package/dist/run-trace.js +1 -1
- package/dist/run-trace.js.map +1 -1
- package/dist/sandbox-host.js +1 -1
- package/dist/sandbox-host.js.map +1 -1
- package/dist/screenplay-authoring.d.ts.map +1 -1
- package/dist/screenplay-authoring.js +13 -0
- package/dist/screenplay-authoring.js.map +1 -1
- package/dist/shot-prompt.d.ts +9 -2
- package/dist/shot-prompt.d.ts.map +1 -1
- package/dist/shot-prompt.js +12 -9
- package/dist/shot-prompt.js.map +1 -1
- package/dist/token-providers.d.ts.map +1 -1
- package/dist/token-providers.js +1 -0
- package/dist/token-providers.js.map +1 -1
- package/dist/video-accessories.d.ts +14 -0
- package/dist/video-accessories.d.ts.map +1 -1
- package/dist/video-accessories.js +51 -0
- package/dist/video-accessories.js.map +1 -1
- package/dist/ws-commands.d.ts +7 -0
- package/dist/ws-commands.d.ts.map +1 -1
- package/dist/ws-commands.js +7 -0
- package/dist/ws-commands.js.map +1 -1
- package/package.json +1 -1
- package/schema/sdk-v1.execution.schema.json +2 -0
- package/schema/sdk-v1.manifest.json +1 -1
|
@@ -0,0 +1,658 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Comfy workflows: NodeTool graphs whose nodes are ComfyUI node classes.
|
|
3
|
+
*
|
|
4
|
+
* A workflow with `run_mode: "comfy"` is edited in the NodeTool graph editor
|
|
5
|
+
* but never runs node by node in the NodeTool kernel. The whole graph is
|
|
6
|
+
* compiled to ComfyUI's API ("prompt") format and submitted as one job to
|
|
7
|
+
* Comfy Cloud through the Comfy API v2. This module holds the pure parts of
|
|
8
|
+
* that path, shared by the server and the web client:
|
|
9
|
+
*
|
|
10
|
+
* - {@link comfyObjectInfoToMetadata} turns ComfyUI's `/api/object_info`
|
|
11
|
+
* catalog into NodeTool node metadata, one `comfy.<ClassName>` type per
|
|
12
|
+
* ComfyUI node class, so the editor can place and wire them.
|
|
13
|
+
* - {@link buildComfyPrompt} compiles a NodeTool graph of `comfy.*` nodes to
|
|
14
|
+
* an API-format prompt. Prompt keys are the NodeTool node ids, so progress
|
|
15
|
+
* Comfy reports for a prompt node maps straight back to the editor node.
|
|
16
|
+
* - {@link comfyPromptToGraph} imports an API-format prompt as a graph.
|
|
17
|
+
* - {@link collapseComfyGraph} replaces a Comfy graph with the single runner
|
|
18
|
+
* node the kernel executes.
|
|
19
|
+
*/
|
|
20
|
+
import { isNumber, isString } from "./predicates.js";
|
|
21
|
+
/** The run mode that marks a workflow as a Comfy workflow. */
|
|
22
|
+
export const COMFY_RUN_MODE = "comfy";
|
|
23
|
+
/** Node type prefix of ComfyUI node classes in a NodeTool graph. */
|
|
24
|
+
export const COMFY_NODE_PREFIX = "comfy.";
|
|
25
|
+
/** Edge type prefix of ComfyUI's typed sockets (MODEL, LATENT, IMAGE, ...). */
|
|
26
|
+
export const COMFY_SOCKET_PREFIX = "comfy.";
|
|
27
|
+
/**
|
|
28
|
+
* The runner node {@link collapseComfyGraph} substitutes for a Comfy graph. It
|
|
29
|
+
* is registered by `@nodetool-ai/integration-nodes` and hidden from the menu.
|
|
30
|
+
*/
|
|
31
|
+
export const COMFY_CLOUD_GRAPH_NODE_TYPE = "lib.comfy.RunComfyGraphOnCloud";
|
|
32
|
+
/** Node id of the substituted runner node. */
|
|
33
|
+
export const COMFY_CLOUD_GRAPH_NODE_ID = "__comfy_cloud_graph__";
|
|
34
|
+
const PRIMITIVES = {
|
|
35
|
+
INT: "int",
|
|
36
|
+
FLOAT: "float",
|
|
37
|
+
STRING: "str",
|
|
38
|
+
BOOLEAN: "bool"
|
|
39
|
+
};
|
|
40
|
+
const EDITOR_ONLY_TYPES = new Set([
|
|
41
|
+
"nodetool.workflows.base_node.Comment",
|
|
42
|
+
"nodetool.workflows.base_node.Group",
|
|
43
|
+
"nodetool.workflows.base_node.Preview",
|
|
44
|
+
"nodetool.control.Reroute"
|
|
45
|
+
]);
|
|
46
|
+
export function isComfyNodeType(type) {
|
|
47
|
+
return isString(type) && type.startsWith(COMFY_NODE_PREFIX);
|
|
48
|
+
}
|
|
49
|
+
/** The ComfyUI class name behind a `comfy.<ClassName>` node type. */
|
|
50
|
+
export function comfyClassType(nodeType) {
|
|
51
|
+
return nodeType.slice(COMFY_NODE_PREFIX.length);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* True for a standard workflow Input or Output node. These nodes give a Comfy
|
|
55
|
+
* workflow the same inputs and outputs as any other workflow.
|
|
56
|
+
*/
|
|
57
|
+
export function isComfyBoundaryNodeType(type) {
|
|
58
|
+
return (isString(type) &&
|
|
59
|
+
(type.startsWith("nodetool.input.") || type.startsWith("nodetool.output.")));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* True when the graph has a ComfyUI node class and every other runnable node
|
|
63
|
+
* is a workflow Input or Output. Editor annotations (comments, groups,
|
|
64
|
+
* previews) do not count either way.
|
|
65
|
+
*/
|
|
66
|
+
export function isComfyGraph(graph) {
|
|
67
|
+
let comfy = 0;
|
|
68
|
+
for (const node of graph.nodes) {
|
|
69
|
+
if (isString(node.type) && EDITOR_ONLY_TYPES.has(node.type))
|
|
70
|
+
continue;
|
|
71
|
+
if (isComfyBoundaryNodeType(node.type))
|
|
72
|
+
continue;
|
|
73
|
+
if (!isComfyNodeType(node.type))
|
|
74
|
+
return false;
|
|
75
|
+
comfy += 1;
|
|
76
|
+
}
|
|
77
|
+
return comfy > 0;
|
|
78
|
+
}
|
|
79
|
+
function socketType(name) {
|
|
80
|
+
if (name === "*" || name.includes(",")) {
|
|
81
|
+
return { type: "any", optional: true, type_args: [] };
|
|
82
|
+
}
|
|
83
|
+
return { type: `${COMFY_SOCKET_PREFIX}${name}`, optional: true, type_args: [] };
|
|
84
|
+
}
|
|
85
|
+
function safeNumber(value) {
|
|
86
|
+
return isNumber(value) && Number.isFinite(value) && Math.abs(value) <= Number.MAX_SAFE_INTEGER
|
|
87
|
+
? value
|
|
88
|
+
: null;
|
|
89
|
+
}
|
|
90
|
+
function isRecord(value) {
|
|
91
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
92
|
+
}
|
|
93
|
+
function enumProperty(name, values, opts, required) {
|
|
94
|
+
const fallback = values[0] ?? "";
|
|
95
|
+
const def = opts.default;
|
|
96
|
+
return {
|
|
97
|
+
name,
|
|
98
|
+
type: { type: "enum", optional: !required, values, type_args: [] },
|
|
99
|
+
default: isString(def) || isNumber(def) ? def : fallback,
|
|
100
|
+
title: name,
|
|
101
|
+
description: isString(opts.tooltip) ? opts.tooltip : null,
|
|
102
|
+
values,
|
|
103
|
+
required
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Properties for one ComfyUI input. A dynamic combo (`COMFY_DYNAMICCOMBO_V3`)
|
|
108
|
+
* is an enum of its option keys plus the inputs of its default option,
|
|
109
|
+
* flattened, which is how the API format carries them (`format`, `format.codec`).
|
|
110
|
+
*/
|
|
111
|
+
function inputProperties(name, spec, required, depth = 0) {
|
|
112
|
+
if (!Array.isArray(spec) || spec.length === 0)
|
|
113
|
+
return [];
|
|
114
|
+
const kind = spec[0];
|
|
115
|
+
const opts = isRecord(spec[1]) ? spec[1] : {};
|
|
116
|
+
const description = isString(opts.tooltip) ? opts.tooltip : null;
|
|
117
|
+
if (Array.isArray(kind)) {
|
|
118
|
+
const values = kind.filter((v) => isString(v) || isNumber(v));
|
|
119
|
+
return [enumProperty(name, values, opts, required)];
|
|
120
|
+
}
|
|
121
|
+
if (!isString(kind))
|
|
122
|
+
return [];
|
|
123
|
+
if (kind === "COMBO" && Array.isArray(opts.options)) {
|
|
124
|
+
const values = opts.options.filter((v) => isString(v) || isNumber(v));
|
|
125
|
+
return [enumProperty(name, values, opts, required)];
|
|
126
|
+
}
|
|
127
|
+
if (kind === "COMFY_DYNAMICCOMBO_V3" && Array.isArray(opts.options)) {
|
|
128
|
+
const options = opts.options.filter(isRecord);
|
|
129
|
+
const keys = options
|
|
130
|
+
.map((o) => o.key)
|
|
131
|
+
.filter((k) => isString(k));
|
|
132
|
+
const out = [enumProperty(name, keys, opts, required)];
|
|
133
|
+
const selected = String(opts.default ?? keys[0] ?? "");
|
|
134
|
+
const chosen = options.find((o) => o.key === selected);
|
|
135
|
+
const nested = isRecord(chosen?.inputs) ? chosen.inputs : {};
|
|
136
|
+
if (depth < 3) {
|
|
137
|
+
for (const section of ["required", "optional"]) {
|
|
138
|
+
const group = nested[section];
|
|
139
|
+
if (!isRecord(group))
|
|
140
|
+
continue;
|
|
141
|
+
for (const [child, childSpec] of Object.entries(group)) {
|
|
142
|
+
out.push(...inputProperties(`${name}.${child}`, childSpec, section === "required" && required, depth + 1));
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return out;
|
|
147
|
+
}
|
|
148
|
+
const primitive = PRIMITIVES[kind];
|
|
149
|
+
if (primitive) {
|
|
150
|
+
let def = opts.default;
|
|
151
|
+
if (def === undefined) {
|
|
152
|
+
def = primitive === "str" ? "" : primitive === "bool" ? false : primitive === "int" || primitive === "float" ? (safeNumber(opts.min) ?? 0) : null;
|
|
153
|
+
}
|
|
154
|
+
if ((primitive === "int" || primitive === "float") && safeNumber(def) === null) {
|
|
155
|
+
def = 0;
|
|
156
|
+
}
|
|
157
|
+
const extra = {};
|
|
158
|
+
if (opts.multiline === true)
|
|
159
|
+
extra.multiline = true;
|
|
160
|
+
if (isNumber(opts.step))
|
|
161
|
+
extra.step = opts.step;
|
|
162
|
+
return [
|
|
163
|
+
{
|
|
164
|
+
name,
|
|
165
|
+
type: { type: primitive, optional: !required, type_args: [] },
|
|
166
|
+
default: def,
|
|
167
|
+
title: name,
|
|
168
|
+
description,
|
|
169
|
+
min: safeNumber(opts.min),
|
|
170
|
+
max: safeNumber(opts.max),
|
|
171
|
+
json_schema_extra: Object.keys(extra).length > 0 ? extra : null,
|
|
172
|
+
required
|
|
173
|
+
}
|
|
174
|
+
];
|
|
175
|
+
}
|
|
176
|
+
return [
|
|
177
|
+
{
|
|
178
|
+
name,
|
|
179
|
+
type: socketType(kind),
|
|
180
|
+
default: null,
|
|
181
|
+
title: name,
|
|
182
|
+
description,
|
|
183
|
+
required
|
|
184
|
+
}
|
|
185
|
+
];
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Output slot names for a ComfyUI class, deduplicated in socket order. The
|
|
189
|
+
* index of a name in this list is the socket index the API format links by.
|
|
190
|
+
*/
|
|
191
|
+
export function comfyOutputNames(entry) {
|
|
192
|
+
const types = Array.isArray(entry.output) ? entry.output : [];
|
|
193
|
+
const names = Array.isArray(entry.output_name) ? entry.output_name : [];
|
|
194
|
+
const seen = new Map();
|
|
195
|
+
return types.map((type, index) => {
|
|
196
|
+
const base = String(names[index] ?? (isString(type) ? type : `output_${index}`));
|
|
197
|
+
const count = seen.get(base) ?? 0;
|
|
198
|
+
seen.set(base, count + 1);
|
|
199
|
+
return count === 0 ? base : `${base}_${count + 1}`;
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
function trimUnderscores(value) {
|
|
203
|
+
let start = 0;
|
|
204
|
+
let end = value.length;
|
|
205
|
+
while (start < end && value[start] === "_")
|
|
206
|
+
start += 1;
|
|
207
|
+
while (end > start && value[end - 1] === "_")
|
|
208
|
+
end -= 1;
|
|
209
|
+
return value.slice(start, end);
|
|
210
|
+
}
|
|
211
|
+
function namespaceFor(category) {
|
|
212
|
+
const parts = (category ?? "")
|
|
213
|
+
.split("/")
|
|
214
|
+
.map((p) => trimUnderscores(p.trim().toLowerCase().replace(/[^a-z0-9]+/g, "_")))
|
|
215
|
+
.filter((p) => p.length > 0);
|
|
216
|
+
return ["comfy", ...(parts.length > 0 ? parts : ["other"])].join(".");
|
|
217
|
+
}
|
|
218
|
+
function orderedInputs(entry, section) {
|
|
219
|
+
const group = entry.input?.[section];
|
|
220
|
+
if (!isRecord(group))
|
|
221
|
+
return [];
|
|
222
|
+
const order = entry.input_order?.[section];
|
|
223
|
+
const names = Array.isArray(order) && order.length > 0 ? order : Object.keys(group);
|
|
224
|
+
return names.filter((n) => n in group).map((n) => [n, group[n]]);
|
|
225
|
+
}
|
|
226
|
+
export function comfyEntryToMetadata(className, entry, options = {}) {
|
|
227
|
+
const properties = [];
|
|
228
|
+
const seen = new Set();
|
|
229
|
+
for (const section of ["required", "optional"]) {
|
|
230
|
+
for (const [name, spec] of orderedInputs(entry, section)) {
|
|
231
|
+
for (const prop of inputProperties(name, spec, section === "required")) {
|
|
232
|
+
if (seen.has(prop.name))
|
|
233
|
+
continue;
|
|
234
|
+
seen.add(prop.name);
|
|
235
|
+
properties.push(prop);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
const types = Array.isArray(entry.output) ? entry.output : [];
|
|
240
|
+
const outputs = comfyOutputNames(entry).map((name, index) => {
|
|
241
|
+
const type = types[index];
|
|
242
|
+
return {
|
|
243
|
+
name,
|
|
244
|
+
type: isString(type) ? socketType(type) : { type: "any", optional: true, type_args: [] },
|
|
245
|
+
stream: false
|
|
246
|
+
};
|
|
247
|
+
});
|
|
248
|
+
// A save/preview node gets a media slot of the kind it saves, appended after
|
|
249
|
+
// its sockets, so the editor has somewhere to show the file the job returns.
|
|
250
|
+
// It is display only: prompts link sockets by `comfyOutputNames`.
|
|
251
|
+
let primaryOutput;
|
|
252
|
+
if (entry.output_node === true) {
|
|
253
|
+
const sockets = new Set(properties.map((p) => p.type.type));
|
|
254
|
+
const kind = sockets.has(`${COMFY_SOCKET_PREFIX}VIDEO`)
|
|
255
|
+
? "video"
|
|
256
|
+
: sockets.has(`${COMFY_SOCKET_PREFIX}AUDIO`)
|
|
257
|
+
? "audio"
|
|
258
|
+
: sockets.has(`${COMFY_SOCKET_PREFIX}IMAGE`)
|
|
259
|
+
? "image"
|
|
260
|
+
: null;
|
|
261
|
+
if (kind) {
|
|
262
|
+
outputs.push({ name: "output", type: { type: kind, optional: true, type_args: [] }, stream: false });
|
|
263
|
+
primaryOutput = "output";
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
const title = entry.display_name || entry.name || className;
|
|
267
|
+
const metadata = {
|
|
268
|
+
title,
|
|
269
|
+
description: [entry.description ?? "", `ComfyUI node ${className}`, "comfy, comfyui"]
|
|
270
|
+
.filter((s) => s.length > 0)
|
|
271
|
+
.join("\n "),
|
|
272
|
+
namespace: namespaceFor(entry.category),
|
|
273
|
+
node_type: `${COMFY_NODE_PREFIX}${className}`,
|
|
274
|
+
layout: "default",
|
|
275
|
+
properties,
|
|
276
|
+
outputs,
|
|
277
|
+
recommended_models: [],
|
|
278
|
+
// Sockets are wired, widgets are edited on the node, as in ComfyUI.
|
|
279
|
+
input_fields: properties
|
|
280
|
+
.filter((p) => p.type.type === "any" || p.type.type.startsWith(COMFY_SOCKET_PREFIX))
|
|
281
|
+
.map((p) => p.name),
|
|
282
|
+
inline_fields: properties
|
|
283
|
+
.filter((p) => !(p.type.type === "any" || p.type.type.startsWith(COMFY_SOCKET_PREFIX)))
|
|
284
|
+
.map((p) => p.name),
|
|
285
|
+
required_settings: options.requiredSettings ?? ["COMFY_API_KEY"],
|
|
286
|
+
supports_dynamic_inputs: false,
|
|
287
|
+
supports_dynamic_outputs: false,
|
|
288
|
+
is_streaming_output: false,
|
|
289
|
+
effect: "external",
|
|
290
|
+
deprecated: entry.deprecated === true,
|
|
291
|
+
platforms: ["node"]
|
|
292
|
+
};
|
|
293
|
+
if (primaryOutput) {
|
|
294
|
+
metadata.primary_output = primaryOutput;
|
|
295
|
+
// The runner saves this node's files under its id, so its history reloads.
|
|
296
|
+
metadata.auto_save_asset = true;
|
|
297
|
+
}
|
|
298
|
+
return metadata;
|
|
299
|
+
}
|
|
300
|
+
/** NodeTool metadata for every class in a ComfyUI `/api/object_info` map. */
|
|
301
|
+
export function comfyObjectInfoToMetadata(info, options = {}) {
|
|
302
|
+
const out = [];
|
|
303
|
+
for (const [className, entry] of Object.entries(info)) {
|
|
304
|
+
if (!isRecord(entry))
|
|
305
|
+
continue;
|
|
306
|
+
out.push(comfyEntryToMetadata(className, entry, options));
|
|
307
|
+
}
|
|
308
|
+
return out;
|
|
309
|
+
}
|
|
310
|
+
function nodeValues(node) {
|
|
311
|
+
const values = isRecord(node.properties) ? node.properties : isRecord(node.data) ? node.data : {};
|
|
312
|
+
return values;
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Compile a graph of `comfy.*` nodes to ComfyUI's API format.
|
|
316
|
+
*
|
|
317
|
+
* `outputNames` returns the deduplicated output slot names of a ComfyUI class
|
|
318
|
+
* (see {@link comfyOutputNames}); an edge from slot `n` links socket
|
|
319
|
+
* `outputNames(class).indexOf(n)`. Literal values that are `null` are left
|
|
320
|
+
* out, because a null in the API format is a broken link to ComfyUI.
|
|
321
|
+
*/
|
|
322
|
+
export function buildComfyPrompt(graph, outputNames) {
|
|
323
|
+
const prompt = {};
|
|
324
|
+
const byId = new Map();
|
|
325
|
+
for (const node of graph.nodes) {
|
|
326
|
+
if (!isComfyNodeType(node.type))
|
|
327
|
+
continue;
|
|
328
|
+
byId.set(node.id, node);
|
|
329
|
+
const inputs = {};
|
|
330
|
+
for (const [key, value] of Object.entries(nodeValues(node))) {
|
|
331
|
+
if (value === null || value === undefined)
|
|
332
|
+
continue;
|
|
333
|
+
if (key.startsWith("_"))
|
|
334
|
+
continue;
|
|
335
|
+
inputs[key] = value;
|
|
336
|
+
}
|
|
337
|
+
const title = isRecord(node.ui_properties) && isString(node.ui_properties.title)
|
|
338
|
+
? node.ui_properties.title
|
|
339
|
+
: undefined;
|
|
340
|
+
const entry = { class_type: comfyClassType(node.type), inputs };
|
|
341
|
+
if (title)
|
|
342
|
+
entry._meta = { title };
|
|
343
|
+
prompt[node.id] = entry;
|
|
344
|
+
}
|
|
345
|
+
for (const edge of graph.edges) {
|
|
346
|
+
const source = byId.get(edge.source);
|
|
347
|
+
const target = prompt[edge.target];
|
|
348
|
+
if (!source || !target)
|
|
349
|
+
continue;
|
|
350
|
+
const names = outputNames(comfyClassType(source.type)) ?? [];
|
|
351
|
+
let index = names.indexOf(edge.sourceHandle);
|
|
352
|
+
if (index < 0) {
|
|
353
|
+
// Without the catalog an imported edge keeps its `output_<n>` handle.
|
|
354
|
+
const prefix = "output_";
|
|
355
|
+
const tail = edge.sourceHandle.startsWith(prefix) ? Number(edge.sourceHandle.slice(prefix.length)) : NaN;
|
|
356
|
+
index = names.length === 0 && Number.isInteger(tail) && tail >= 0 ? tail : 0;
|
|
357
|
+
}
|
|
358
|
+
target.inputs[edge.targetHandle] = [edge.source, index];
|
|
359
|
+
}
|
|
360
|
+
return prompt;
|
|
361
|
+
}
|
|
362
|
+
function isLink(value) {
|
|
363
|
+
return (Array.isArray(value) &&
|
|
364
|
+
value.length === 2 &&
|
|
365
|
+
(isString(value[0]) || isNumber(value[0])) &&
|
|
366
|
+
isNumber(value[1]));
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Import an API-format prompt as a NodeTool graph of `comfy.*` nodes, laid out
|
|
370
|
+
* left to right by dependency depth.
|
|
371
|
+
*/
|
|
372
|
+
export function comfyPromptToGraph(prompt, outputNames) {
|
|
373
|
+
const ids = Object.keys(prompt);
|
|
374
|
+
const depth = new Map();
|
|
375
|
+
const visiting = new Set();
|
|
376
|
+
const depthOf = (id) => {
|
|
377
|
+
const known = depth.get(id);
|
|
378
|
+
if (known !== undefined)
|
|
379
|
+
return known;
|
|
380
|
+
if (visiting.has(id))
|
|
381
|
+
return 0;
|
|
382
|
+
visiting.add(id);
|
|
383
|
+
let d = 0;
|
|
384
|
+
for (const value of Object.values(prompt[id]?.inputs ?? {})) {
|
|
385
|
+
if (isLink(value) && String(value[0]) in prompt) {
|
|
386
|
+
d = Math.max(d, depthOf(String(value[0])) + 1);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
visiting.delete(id);
|
|
390
|
+
depth.set(id, d);
|
|
391
|
+
return d;
|
|
392
|
+
};
|
|
393
|
+
const rows = new Map();
|
|
394
|
+
const nodes = [];
|
|
395
|
+
const edges = [];
|
|
396
|
+
for (const id of ids) {
|
|
397
|
+
const entry = prompt[id];
|
|
398
|
+
if (!entry || !isString(entry.class_type))
|
|
399
|
+
continue;
|
|
400
|
+
const column = depthOf(id);
|
|
401
|
+
const row = rows.get(column) ?? 0;
|
|
402
|
+
rows.set(column, row + 1);
|
|
403
|
+
const data = {};
|
|
404
|
+
for (const [field, value] of Object.entries(entry.inputs ?? {})) {
|
|
405
|
+
if (isLink(value)) {
|
|
406
|
+
const sourceId = String(value[0]);
|
|
407
|
+
const sourceClass = prompt[sourceId]?.class_type;
|
|
408
|
+
const names = sourceClass ? outputNames(sourceClass) : undefined;
|
|
409
|
+
edges.push({
|
|
410
|
+
id: `${sourceId}-${value[1]}-${id}-${field}`,
|
|
411
|
+
source: sourceId,
|
|
412
|
+
sourceHandle: names?.[value[1]] ?? `output_${value[1]}`,
|
|
413
|
+
target: id,
|
|
414
|
+
targetHandle: field,
|
|
415
|
+
ui_properties: null
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
else {
|
|
419
|
+
data[field] = value;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
const ui = {
|
|
423
|
+
position: { x: column * 340, y: row * 330 },
|
|
424
|
+
width: 280
|
|
425
|
+
};
|
|
426
|
+
if (entry._meta?.title)
|
|
427
|
+
ui.title = entry._meta.title;
|
|
428
|
+
nodes.push({
|
|
429
|
+
id,
|
|
430
|
+
type: `${COMFY_NODE_PREFIX}${entry.class_type}`,
|
|
431
|
+
data,
|
|
432
|
+
ui_properties: ui,
|
|
433
|
+
dynamic_properties: {},
|
|
434
|
+
dynamic_outputs: {}
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
return { nodes, edges };
|
|
438
|
+
}
|
|
439
|
+
const SAVE_CLASS = /^(Save|VHS_VideoCombine)/;
|
|
440
|
+
const INPUT_NODE_TYPES = {
|
|
441
|
+
image: "nodetool.input.ImageInput",
|
|
442
|
+
audio: "nodetool.input.AudioInput",
|
|
443
|
+
video: "nodetool.input.VideoInput"
|
|
444
|
+
};
|
|
445
|
+
/** The Load classes a run can feed, with the field that names the file. */
|
|
446
|
+
const LOAD_CLASSES = {
|
|
447
|
+
LoadImage: { kind: "image", field: "image" },
|
|
448
|
+
LoadAudio: { kind: "audio", field: "audio" },
|
|
449
|
+
LoadVideo: { kind: "video", field: "file" }
|
|
450
|
+
};
|
|
451
|
+
const PROMPT_FIELDS = ["text", "prompt", "tags", "caption"];
|
|
452
|
+
function saveKind(classType) {
|
|
453
|
+
if (!SAVE_CLASS.test(classType))
|
|
454
|
+
return null;
|
|
455
|
+
if (/Video/.test(classType))
|
|
456
|
+
return "video";
|
|
457
|
+
if (/Audio/.test(classType))
|
|
458
|
+
return "audio";
|
|
459
|
+
return /Image|WEBP|PNG/.test(classType) ? "image" : null;
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* The node and field that hold the positive prompt: walk upstream from the
|
|
463
|
+
* `positive` socket to the first node with a literal prompt field. A graph with
|
|
464
|
+
* no `positive` socket uses its only text encoder.
|
|
465
|
+
*/
|
|
466
|
+
function positivePrompt(graph) {
|
|
467
|
+
const byId = new Map(graph.nodes.map((node) => [node.id, node]));
|
|
468
|
+
const promptField = (node) => /^comfy\.PrimitiveString/.test(node.type) && isString(nodeValues(node).value)
|
|
469
|
+
? "value"
|
|
470
|
+
: PROMPT_FIELDS.find((field) => isString(nodeValues(node)[field]));
|
|
471
|
+
const pending = graph.edges.filter((e) => e.targetHandle === "positive").map((e) => e.source);
|
|
472
|
+
const seen = new Set();
|
|
473
|
+
while (pending.length > 0) {
|
|
474
|
+
const id = pending.shift();
|
|
475
|
+
if (seen.has(id))
|
|
476
|
+
continue;
|
|
477
|
+
seen.add(id);
|
|
478
|
+
const node = byId.get(id);
|
|
479
|
+
if (!node)
|
|
480
|
+
continue;
|
|
481
|
+
const field = promptField(node);
|
|
482
|
+
if (field)
|
|
483
|
+
return { node, field };
|
|
484
|
+
pending.push(...graph.edges.filter((e) => e.target === id).map((e) => e.source));
|
|
485
|
+
}
|
|
486
|
+
const encoders = graph.nodes.filter((node) => isComfyNodeType(node.type) && /TextEncode/.test(node.type) && promptField(node));
|
|
487
|
+
const [only] = encoders;
|
|
488
|
+
return encoders.length === 1 && only ? { node: only, field: promptField(only) } : null;
|
|
489
|
+
}
|
|
490
|
+
function nodePosition(node) {
|
|
491
|
+
const position = isRecord(node.ui_properties) ? node.ui_properties.position : null;
|
|
492
|
+
return isRecord(position) && isNumber(position.x) && isNumber(position.y)
|
|
493
|
+
? { x: position.x, y: position.y }
|
|
494
|
+
: { x: 0, y: 0 };
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* The graph as contract readers and the kernel see it. A stored Comfy graph
|
|
498
|
+
* holds only ComfyUI nodes, so this derives its contract: one input per Load
|
|
499
|
+
* node and for the positive prompt, one output per Save node. The result is
|
|
500
|
+
* never saved. A graph with its own Input or Output nodes keeps them, and any
|
|
501
|
+
* other graph is returned unchanged.
|
|
502
|
+
*
|
|
503
|
+
* Node ids are derived from the Comfy node and field, so a binding to a derived
|
|
504
|
+
* input stays valid across runs.
|
|
505
|
+
*/
|
|
506
|
+
export function exposeComfyInterface(source) {
|
|
507
|
+
const nodesIn = source.nodes;
|
|
508
|
+
if (!isComfyGraph({ nodes: nodesIn }))
|
|
509
|
+
return source;
|
|
510
|
+
if (nodesIn.some((node) => isComfyBoundaryNodeType(node.type)))
|
|
511
|
+
return source;
|
|
512
|
+
const graph = source;
|
|
513
|
+
const added = [];
|
|
514
|
+
const addedEdges = [];
|
|
515
|
+
const counts = new Map();
|
|
516
|
+
const uniqueName = (base) => {
|
|
517
|
+
const count = (counts.get(base) ?? 0) + 1;
|
|
518
|
+
counts.set(base, count);
|
|
519
|
+
return count === 1 ? base : `${base}_${count}`;
|
|
520
|
+
};
|
|
521
|
+
const addInput = (target, field, type, name, value) => {
|
|
522
|
+
const id = `input_${target.id}_${field}`;
|
|
523
|
+
const { x, y } = nodePosition(target);
|
|
524
|
+
added.push({
|
|
525
|
+
id,
|
|
526
|
+
type,
|
|
527
|
+
data: { name, description: "", value },
|
|
528
|
+
// Editor readers use `data`, and the kernel uses `properties`.
|
|
529
|
+
properties: { name, description: "", value },
|
|
530
|
+
ui_properties: { position: { x: x - 340, y }, width: 280 },
|
|
531
|
+
dynamic_properties: {},
|
|
532
|
+
dynamic_outputs: {}
|
|
533
|
+
});
|
|
534
|
+
addedEdges.push({
|
|
535
|
+
id: `${id}-${target.id}`,
|
|
536
|
+
source: id,
|
|
537
|
+
sourceHandle: "output",
|
|
538
|
+
target: target.id,
|
|
539
|
+
targetHandle: field,
|
|
540
|
+
ui_properties: null
|
|
541
|
+
});
|
|
542
|
+
};
|
|
543
|
+
const prompt = positivePrompt(graph);
|
|
544
|
+
if (prompt) {
|
|
545
|
+
addInput(prompt.node, prompt.field, "nodetool.input.StringInput", uniqueName("prompt"), nodeValues(prompt.node)[prompt.field]);
|
|
546
|
+
}
|
|
547
|
+
const nodes = graph.nodes.map((node) => {
|
|
548
|
+
if (!isComfyNodeType(node.type))
|
|
549
|
+
return node;
|
|
550
|
+
const classType = comfyClassType(node.type);
|
|
551
|
+
const load = LOAD_CLASSES[classType];
|
|
552
|
+
if (load) {
|
|
553
|
+
addInput(node, load.field, INPUT_NODE_TYPES[load.kind], uniqueName(load.kind), { type: load.kind, uri: "" });
|
|
554
|
+
return node;
|
|
555
|
+
}
|
|
556
|
+
const kind = saveKind(classType);
|
|
557
|
+
if (!kind)
|
|
558
|
+
return node;
|
|
559
|
+
const id = `output_${node.id}`;
|
|
560
|
+
const outputName = uniqueName("output");
|
|
561
|
+
const { x, y } = nodePosition(node);
|
|
562
|
+
added.push({
|
|
563
|
+
id,
|
|
564
|
+
type: "nodetool.output.Output",
|
|
565
|
+
data: { name: outputName, description: "" },
|
|
566
|
+
properties: { name: outputName, description: "" },
|
|
567
|
+
ui_properties: { position: { x: x + 340, y }, width: 280 },
|
|
568
|
+
dynamic_properties: {},
|
|
569
|
+
dynamic_outputs: {}
|
|
570
|
+
});
|
|
571
|
+
addedEdges.push({
|
|
572
|
+
id: `${node.id}-${id}`,
|
|
573
|
+
source: node.id,
|
|
574
|
+
sourceHandle: "output",
|
|
575
|
+
target: id,
|
|
576
|
+
targetHandle: "value",
|
|
577
|
+
ui_properties: null
|
|
578
|
+
});
|
|
579
|
+
const dynamicOutputs = { ...node.dynamic_outputs };
|
|
580
|
+
dynamicOutputs.output = { type: kind, optional: true, type_args: [] };
|
|
581
|
+
return { ...node, dynamic_outputs: dynamicOutputs };
|
|
582
|
+
});
|
|
583
|
+
return { ...source, nodes: [...nodes, ...added], edges: [...graph.edges, ...addedEdges] };
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* Replace a Comfy graph with the single runner node the kernel executes. The
|
|
587
|
+
* runner carries the original nodes and edges and compiles them at run time,
|
|
588
|
+
* when it has the Comfy catalog to resolve output socket indexes. Input and
|
|
589
|
+
* Output nodes stay in the graph. An edge from an Input becomes a runner input
|
|
590
|
+
* `<comfyNodeId>:<field>`, and an edge to an Output reads the runner output
|
|
591
|
+
* `<comfyNodeId>:<handle>`.
|
|
592
|
+
*
|
|
593
|
+
* Returns the graph unchanged when it is not a Comfy graph.
|
|
594
|
+
*/
|
|
595
|
+
export function collapseComfyGraph(source) {
|
|
596
|
+
if (!isComfyGraph({ nodes: source.nodes }))
|
|
597
|
+
return source;
|
|
598
|
+
const graph = exposeComfyInterface(source);
|
|
599
|
+
const nodes = graph.nodes;
|
|
600
|
+
const edges = graph.edges;
|
|
601
|
+
const comfyNodes = nodes.filter((n) => isComfyNodeType(n.type));
|
|
602
|
+
const boundaryNodes = nodes.filter((n) => isComfyBoundaryNodeType(n.type));
|
|
603
|
+
const comfyIds = new Set(comfyNodes.map((n) => String(n.id)));
|
|
604
|
+
const keptIds = new Set(boundaryNodes.map((n) => String(n.id)));
|
|
605
|
+
const data = {
|
|
606
|
+
nodes: comfyNodes.map((n) => ({
|
|
607
|
+
id: String(n.id),
|
|
608
|
+
type: String(n.type),
|
|
609
|
+
properties: (isRecord(n.properties) ? n.properties : isRecord(n.data) ? n.data : {}),
|
|
610
|
+
ui_properties: isRecord(n.ui_properties) ? { title: n.ui_properties.title } : null
|
|
611
|
+
})),
|
|
612
|
+
edges: edges
|
|
613
|
+
.filter((e) => e.edge_type !== "control" &&
|
|
614
|
+
comfyIds.has(String(e.source)) &&
|
|
615
|
+
comfyIds.has(String(e.target)))
|
|
616
|
+
.map((e) => ({
|
|
617
|
+
source: String(e.source),
|
|
618
|
+
sourceHandle: String(e.sourceHandle ?? ""),
|
|
619
|
+
target: String(e.target),
|
|
620
|
+
targetHandle: String(e.targetHandle ?? "")
|
|
621
|
+
})),
|
|
622
|
+
output_slots: []
|
|
623
|
+
};
|
|
624
|
+
const dynamicOutputs = {};
|
|
625
|
+
const boundaryEdges = [];
|
|
626
|
+
for (const edge of edges) {
|
|
627
|
+
const fromComfy = comfyIds.has(String(edge.source));
|
|
628
|
+
const toComfy = comfyIds.has(String(edge.target));
|
|
629
|
+
if (fromComfy && toComfy)
|
|
630
|
+
continue;
|
|
631
|
+
if (fromComfy && keptIds.has(String(edge.target))) {
|
|
632
|
+
const slot = `${String(edge.source)}:${String(edge.sourceHandle ?? "")}`;
|
|
633
|
+
data.output_slots.push(slot);
|
|
634
|
+
dynamicOutputs[slot] = { type: "any", optional: true, type_args: [] };
|
|
635
|
+
boundaryEdges.push({ ...edge, source: COMFY_CLOUD_GRAPH_NODE_ID, sourceHandle: slot });
|
|
636
|
+
}
|
|
637
|
+
else if (toComfy && keptIds.has(String(edge.source))) {
|
|
638
|
+
boundaryEdges.push({
|
|
639
|
+
...edge,
|
|
640
|
+
target: COMFY_CLOUD_GRAPH_NODE_ID,
|
|
641
|
+
targetHandle: `${String(edge.target)}:${String(edge.targetHandle ?? "")}`
|
|
642
|
+
});
|
|
643
|
+
}
|
|
644
|
+
else if (keptIds.has(String(edge.source)) && keptIds.has(String(edge.target))) {
|
|
645
|
+
boundaryEdges.push(edge);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
// The saved form reads `data`, the normalized form `properties`.
|
|
649
|
+
const runner = {
|
|
650
|
+
id: COMFY_CLOUD_GRAPH_NODE_ID,
|
|
651
|
+
type: COMFY_CLOUD_GRAPH_NODE_TYPE,
|
|
652
|
+
data,
|
|
653
|
+
properties: data,
|
|
654
|
+
dynamic_outputs: dynamicOutputs
|
|
655
|
+
};
|
|
656
|
+
return { ...graph, nodes: [runner, ...boundaryNodes], edges: boundaryEdges };
|
|
657
|
+
}
|
|
658
|
+
//# sourceMappingURL=comfy-graph.js.map
|