comfyui-node 1.6.1 → 1.6.3

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.
Files changed (110) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/call-wrapper.js +856 -856
  3. package/dist/index.d.ts +7 -2
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +4 -1
  6. package/dist/index.js.map +1 -1
  7. package/dist/multipool/client-registry.d.ts +32 -11
  8. package/dist/multipool/client-registry.d.ts.map +1 -1
  9. package/dist/multipool/client-registry.js +135 -8
  10. package/dist/multipool/client-registry.js.map +1 -1
  11. package/dist/multipool/helpers.d.ts +5 -0
  12. package/dist/multipool/helpers.d.ts.map +1 -0
  13. package/dist/multipool/helpers.js +53 -0
  14. package/dist/multipool/helpers.js.map +1 -0
  15. package/dist/multipool/index.d.ts +2 -1
  16. package/dist/multipool/index.d.ts.map +1 -1
  17. package/dist/multipool/index.js +2 -1
  18. package/dist/multipool/index.js.map +1 -1
  19. package/dist/multipool/interfaces.d.ts +25 -0
  20. package/dist/multipool/interfaces.d.ts.map +1 -1
  21. package/dist/multipool/job-profiler.d.ts +128 -0
  22. package/dist/multipool/job-profiler.d.ts.map +1 -0
  23. package/dist/multipool/job-profiler.js +222 -0
  24. package/dist/multipool/job-profiler.js.map +1 -0
  25. package/dist/multipool/job-queue-processor.d.ts +27 -11
  26. package/dist/multipool/job-queue-processor.d.ts.map +1 -1
  27. package/dist/multipool/job-queue-processor.js +196 -9
  28. package/dist/multipool/job-queue-processor.js.map +1 -1
  29. package/dist/multipool/job-state-registry.d.ts +67 -0
  30. package/dist/multipool/job-state-registry.d.ts.map +1 -0
  31. package/dist/multipool/job-state-registry.js +283 -0
  32. package/dist/multipool/job-state-registry.js.map +1 -0
  33. package/dist/multipool/logger.d.ts +30 -0
  34. package/dist/multipool/logger.d.ts.map +1 -0
  35. package/dist/multipool/logger.js +75 -0
  36. package/dist/multipool/logger.js.map +1 -0
  37. package/dist/multipool/multi-workflow-pool.d.ts +86 -7
  38. package/dist/multipool/multi-workflow-pool.d.ts.map +1 -1
  39. package/dist/multipool/multi-workflow-pool.js +365 -13
  40. package/dist/multipool/multi-workflow-pool.js.map +1 -1
  41. package/dist/multipool/pool-event-manager.d.ts +10 -10
  42. package/dist/multipool/tests/client-registry-api-demo.d.ts +7 -0
  43. package/dist/multipool/tests/client-registry-api-demo.d.ts.map +1 -0
  44. package/dist/multipool/tests/client-registry-api-demo.js +136 -0
  45. package/dist/multipool/tests/client-registry-api-demo.js.map +1 -0
  46. package/dist/multipool/tests/client-registry.spec.d.ts +2 -0
  47. package/dist/multipool/tests/client-registry.spec.d.ts.map +1 -0
  48. package/dist/multipool/tests/client-registry.spec.js +191 -0
  49. package/dist/multipool/tests/client-registry.spec.js.map +1 -0
  50. package/dist/multipool/tests/error-classification-tests.d.ts +2 -0
  51. package/dist/multipool/tests/error-classification-tests.d.ts.map +1 -0
  52. package/dist/multipool/tests/error-classification-tests.js +374 -0
  53. package/dist/multipool/tests/error-classification-tests.js.map +1 -0
  54. package/dist/multipool/tests/event-forwarding-demo.d.ts +7 -0
  55. package/dist/multipool/tests/event-forwarding-demo.d.ts.map +1 -0
  56. package/dist/multipool/tests/event-forwarding-demo.js +88 -0
  57. package/dist/multipool/tests/event-forwarding-demo.js.map +1 -0
  58. package/dist/multipool/tests/helpers.spec.d.ts +2 -0
  59. package/dist/multipool/tests/helpers.spec.d.ts.map +1 -0
  60. package/dist/multipool/tests/helpers.spec.js +100 -0
  61. package/dist/multipool/tests/helpers.spec.js.map +1 -0
  62. package/dist/multipool/tests/job-queue-processor.spec.d.ts +2 -0
  63. package/dist/multipool/tests/job-queue-processor.spec.d.ts.map +1 -0
  64. package/dist/multipool/tests/job-queue-processor.spec.js +89 -0
  65. package/dist/multipool/tests/job-queue-processor.spec.js.map +1 -0
  66. package/dist/multipool/tests/job-state-registry.d.ts +16 -16
  67. package/dist/multipool/tests/job-state-registry.js +23 -23
  68. package/dist/multipool/tests/job-state-registry.spec.d.ts +2 -0
  69. package/dist/multipool/tests/job-state-registry.spec.d.ts.map +1 -0
  70. package/dist/multipool/tests/job-state-registry.spec.js +143 -0
  71. package/dist/multipool/tests/job-state-registry.spec.js.map +1 -0
  72. package/dist/multipool/tests/multipool-basic.d.ts +11 -1
  73. package/dist/multipool/tests/multipool-basic.d.ts.map +1 -1
  74. package/dist/multipool/tests/multipool-basic.js +140 -2
  75. package/dist/multipool/tests/multipool-basic.js.map +1 -1
  76. package/dist/multipool/tests/profiling-demo.d.ts +7 -0
  77. package/dist/multipool/tests/profiling-demo.d.ts.map +1 -0
  78. package/dist/multipool/tests/profiling-demo.js +88 -0
  79. package/dist/multipool/tests/profiling-demo.js.map +1 -0
  80. package/dist/multipool/tests/prompt-generator.d.ts +10 -0
  81. package/dist/multipool/tests/prompt-generator.d.ts.map +1 -0
  82. package/dist/multipool/tests/prompt-generator.js +26 -0
  83. package/dist/multipool/tests/prompt-generator.js.map +1 -0
  84. package/dist/multipool/tests/test-helpers.d.ts +4 -0
  85. package/dist/multipool/tests/test-helpers.d.ts.map +1 -0
  86. package/dist/multipool/tests/test-helpers.js +10 -0
  87. package/dist/multipool/tests/test-helpers.js.map +1 -0
  88. package/dist/multipool/tests/two-stage-edit-simulation.d.ts +32 -0
  89. package/dist/multipool/tests/two-stage-edit-simulation.d.ts.map +1 -0
  90. package/dist/multipool/tests/two-stage-edit-simulation.js +299 -0
  91. package/dist/multipool/tests/two-stage-edit-simulation.js.map +1 -0
  92. package/dist/multipool/workflow.d.ts +178 -173
  93. package/dist/multipool/workflow.d.ts.map +1 -1
  94. package/dist/multipool/workflow.js +333 -271
  95. package/dist/multipool/workflow.js.map +1 -1
  96. package/dist/pool/SmartPool.d.ts +143 -143
  97. package/dist/pool/SmartPool.js +676 -676
  98. package/dist/pool/SmartPoolV2.d.ts +119 -119
  99. package/dist/pool/SmartPoolV2.js +586 -586
  100. package/dist/pool/WorkflowPool.d.ts +202 -202
  101. package/dist/pool/WorkflowPool.d.ts.map +1 -1
  102. package/dist/pool/WorkflowPool.js +845 -840
  103. package/dist/pool/WorkflowPool.js.map +1 -1
  104. package/dist/pool/client/ClientManager.d.ts +86 -86
  105. package/dist/pool/client/ClientManager.js +215 -215
  106. package/dist/pool/index.d.ts +9 -11
  107. package/dist/pool/index.d.ts.map +1 -1
  108. package/dist/pool/index.js +3 -5
  109. package/dist/pool/index.js.map +1 -1
  110. package/package.json +1 -1
@@ -1,272 +1,334 @@
1
- import { hashWorkflow } from '../pool/utils/hash.js';
2
- class TinyEmitter {
3
- listeners = new Map();
4
- on(evt, fn) {
5
- if (!this.listeners.has(evt))
6
- this.listeners.set(evt, new Set());
7
- this.listeners.get(evt).add(fn);
8
- return () => this.off(evt, fn);
9
- }
10
- off(evt, fn) { this.listeners.get(evt)?.delete(fn); }
11
- emit(evt, ...args) { this.listeners.get(evt)?.forEach(fn => { try {
12
- fn(...args);
13
- }
14
- catch { } }); }
15
- removeAll() { this.listeners.clear(); }
16
- }
17
- export class WorkflowJob {
18
- emitter = new TinyEmitter();
19
- donePromise;
20
- doneResolve;
21
- doneReject;
22
- lastProgressPct = -1;
23
- constructor() {
24
- this.donePromise = new Promise((res, rej) => { this.doneResolve = res; this.doneReject = rej; });
25
- // Prevent unhandled rejection warnings by attaching a catch handler
26
- // The actual error handling happens when user calls done()
27
- this.donePromise.catch(() => { });
28
- }
29
- on(evt, fn) { this.emitter.on(evt, fn); return this; }
30
- off(evt, fn) { this.emitter.off(evt, fn); return this; }
31
- /** Await final mapped outputs */
32
- done() { return this.donePromise; }
33
- _emit(evt, ...args) { this.emitter.emit(evt, ...args); }
34
- _finish(data) { this.doneResolve(data); this.emitter.emit('finished', data, data._promptId); }
35
- _fail(err, promptId) { this.doneReject(err); this.emitter.emit('failed', err, promptId); }
36
- }
37
- export class Workflow {
38
- json;
39
- outputNodeIds = [];
40
- outputAliases = {}; // nodeId -> alias
41
- bypassedNodes = []; // nodes to bypass during execution
42
- // Pending assets to upload before execution
43
- _pendingImageInputs = [];
44
- _pendingFolderFiles = [];
45
- /** Structural hash of the workflow JSON for compatibility tracking in failover scenarios */
46
- structureHash;
47
- static from(data, opts) {
48
- if (typeof data === 'string') {
49
- try {
50
- const parsed = JSON.parse(data);
51
- return new Workflow(parsed, opts);
52
- }
53
- catch (e) {
54
- throw new Error('Failed to parse workflow JSON string', { cause: e });
55
- }
56
- }
57
- return new Workflow(structuredClone(data), opts);
58
- }
59
- constructor(json, opts) {
60
- this.json = structuredClone(json);
61
- // Compute structural hash by default unless explicitly disabled
62
- if (opts?.autoHash !== false) {
63
- this.structureHash = hashWorkflow(this.json);
64
- }
65
- }
66
- /**
67
- * Like from(), but augments known node types (e.g., KSampler) with soft union hints
68
- * for inputs such as sampler_name & scheduler while still allowing arbitrary strings.
69
- */
70
- static fromAugmented(data, opts) {
71
- return Workflow.from(data, opts);
72
- }
73
- /** Set a nested input path on a node e.g. set('9.inputs.text','hello') */
74
- set(path, value) {
75
- const keys = path.split('.');
76
- let cur = this.json;
77
- for (let i = 0; i < keys.length - 1; i++) {
78
- if (cur[keys[i]] === undefined)
79
- cur[keys[i]] = {};
80
- cur = cur[keys[i]];
81
- }
82
- cur[keys[keys.length - 1]] = value;
83
- return this;
84
- }
85
- /** Attach a single image buffer to a node input (e.g., LoadImage.image). Will upload on run() then set the input to the filename. */
86
- attachImage(nodeId, inputName, data, fileName, opts) {
87
- const blob = toBlob(data, fileName);
88
- this._pendingImageInputs.push({ nodeId: String(nodeId), inputName, blob, fileName, subfolder: opts?.subfolder, override: opts?.override });
89
- return this;
90
- }
91
- /** Attach multiple files into a server subfolder (useful for LoadImageSetFromFolderNode). */
92
- attachFolderFiles(subfolder, files, opts) {
93
- for (const f of files) {
94
- const blob = toBlob(f.data, f.fileName);
95
- this._pendingFolderFiles.push({ subfolder, blob, fileName: f.fileName, override: opts?.override });
96
- }
97
- return this;
98
- }
99
- /**
100
- * Sugar for setting a node's input: wf.input('SAMPLER','steps',30)
101
- * Equivalent to set('SAMPLER.inputs.steps', 30).
102
- * Performs a light existence check to aid DX (doesn't throw if missing by design unless strict parameter is passed).
103
- */
104
- input(nodeId, inputName, value, opts) {
105
- const nodeKey = String(nodeId);
106
- const node = this.json[nodeKey];
107
- if (!node) {
108
- if (opts?.strict)
109
- throw new Error(`Workflow.input: node '${String(nodeId)}' not found`);
110
- // create minimal node shell if non-strict (lets users build up dynamically)
111
- this.json[nodeKey] = { inputs: { [inputName]: value } };
112
- return this;
113
- }
114
- if (!node.inputs) {
115
- if (opts?.strict)
116
- throw new Error(`Workflow.input: node '${String(nodeId)}' missing inputs object`);
117
- node.inputs = {};
118
- }
119
- node.inputs[inputName] = value;
120
- return this;
121
- }
122
- batchInputs(a, b, c) {
123
- // Form 1: (nodeId, values, opts)
124
- if (typeof a === 'string') {
125
- const nodeId = a;
126
- const values = b || {};
127
- const opts = c || {};
128
- for (const [k, v] of Object.entries(values)) {
129
- this.input(nodeId, k, v, opts);
130
- }
131
- return this;
132
- }
133
- // Form 2: (batchObject, opts)
134
- const batch = a || {};
135
- const opts = b || {};
136
- for (const [nodeId, values] of Object.entries(batch)) {
137
- if (!values)
138
- continue;
139
- for (const [k, v] of Object.entries(values)) {
140
- this.input(nodeId, k, v, opts);
141
- }
142
- }
143
- return this;
144
- }
145
- /**
146
- * Mark a node id whose outputs we want collected.
147
- * Supports aliasing in two forms:
148
- * - output('alias','9')
149
- * - output('alias:9')
150
- * - output('9') (no alias, raw node id key)
151
- */
152
- output(a, b) {
153
- let alias;
154
- let nodeId;
155
- if (b) {
156
- // Heuristic: if first arg looks like a node id and second arg looks like an alias, swap
157
- // Node ids are often numeric strings (e.g., '2'); aliases are non-numeric labels.
158
- const looksLikeNodeId = (s) => /^\d+$/.test(s) || this.json[s];
159
- if (looksLikeNodeId(String(a)) && !looksLikeNodeId(String(b))) {
160
- nodeId = String(a);
161
- alias = String(b);
162
- try {
163
- console.warn(`Workflow.output called as output(nodeId, alias). Interpreting as output(alias,nodeId): '${alias}:${nodeId}'`);
164
- }
165
- catch { }
166
- }
167
- else {
168
- alias = String(a);
169
- nodeId = String(b);
170
- }
171
- }
172
- else {
173
- // single param variant: maybe "alias:node" or just node
174
- if (a.includes(':')) {
175
- const [al, id] = a.split(':');
176
- if (al && id) {
177
- alias = al;
178
- nodeId = id;
179
- }
180
- else {
181
- nodeId = a;
182
- }
183
- }
184
- else {
185
- nodeId = a;
186
- }
187
- }
188
- if (!this.outputNodeIds.includes(nodeId))
189
- this.outputNodeIds.push(nodeId);
190
- if (alias) {
191
- this.outputAliases[nodeId] = alias;
192
- }
193
- return this; // typed refinement handled via declaration merging below
194
- }
195
- bypass(nodes) {
196
- if (!Array.isArray(nodes)) {
197
- nodes = [nodes];
198
- }
199
- for (const node of nodes) {
200
- if (!this.bypassedNodes.includes(node)) {
201
- this.bypassedNodes.push(node);
202
- }
203
- }
204
- return this;
205
- }
206
- reinstate(nodes) {
207
- if (!Array.isArray(nodes)) {
208
- nodes = [nodes];
209
- }
210
- for (const node of nodes) {
211
- const idx = this.bypassedNodes.indexOf(node);
212
- if (idx !== -1) {
213
- this.bypassedNodes.splice(idx, 1);
214
- }
215
- }
216
- return this;
217
- }
218
- /**
219
- * Update the structural hash after making non-dynamic changes to the workflow.
220
- * Call this if you modify the workflow structure after initialization and the autoHash was disabled,
221
- * or if you want to recalculate the hash after making structural changes.
222
- *
223
- * Example:
224
- * ```
225
- * const wf = Workflow.from(data, { autoHash: false });
226
- * wf.input('SAMPLER', 'ckpt_name', 'model_v1.safetensors');
227
- * wf.updateHash(); // Recompute hash after structural change
228
- * ```
229
- */
230
- updateHash() {
231
- this.structureHash = hashWorkflow(this.json);
232
- return this;
233
- }
234
- /** IDE helper returning empty object typed as final result (aliases + metadata). */
235
- typedResult() { return {}; }
236
- }
237
- // Helper: normalize to Blob for upload
238
- function toBlob(src, fileName) {
239
- if (src instanceof Blob)
240
- return src;
241
- // Normalize everything to a plain ArrayBuffer for reliable BlobPart typing
242
- let ab;
243
- if (typeof Buffer !== 'undefined' && src instanceof Buffer) {
244
- const u8 = new Uint8Array(src);
245
- ab = u8.slice(0).buffer;
246
- }
247
- else if (src instanceof Uint8Array) {
248
- const u8 = new Uint8Array(src.byteLength);
249
- u8.set(src);
250
- ab = u8.buffer;
251
- }
252
- else if (src instanceof ArrayBuffer) {
253
- ab = src;
254
- }
255
- else {
256
- ab = new ArrayBuffer(0);
257
- }
258
- return new Blob([ab], { type: mimeFromName(fileName) });
259
- }
260
- function mimeFromName(name) {
261
- if (!name)
262
- return undefined;
263
- const n = name.toLowerCase();
264
- if (n.endsWith('.png'))
265
- return 'image/png';
266
- if (n.endsWith('.jpg') || n.endsWith('.jpeg'))
267
- return 'image/jpeg';
268
- if (n.endsWith('.webp'))
269
- return 'image/webp';
270
- return undefined;
271
- }
1
+ import { hashWorkflow } from "../pool/utils/hash.js";
2
+ class TinyEmitter {
3
+ listeners = new Map();
4
+ on(evt, fn) {
5
+ if (!this.listeners.has(evt))
6
+ this.listeners.set(evt, new Set());
7
+ this.listeners.get(evt).add(fn);
8
+ return () => this.off(evt, fn);
9
+ }
10
+ off(evt, fn) {
11
+ this.listeners.get(evt)?.delete(fn);
12
+ }
13
+ emit(evt, ...args) {
14
+ this.listeners.get(evt)?.forEach(fn => {
15
+ try {
16
+ fn(...args);
17
+ }
18
+ catch {
19
+ }
20
+ });
21
+ }
22
+ removeAll() {
23
+ this.listeners.clear();
24
+ }
25
+ }
26
+ export class WorkflowJob {
27
+ emitter = new TinyEmitter();
28
+ donePromise;
29
+ doneResolve;
30
+ doneReject;
31
+ lastProgressPct = -1;
32
+ constructor() {
33
+ this.donePromise = new Promise((res, rej) => {
34
+ this.doneResolve = res;
35
+ this.doneReject = rej;
36
+ });
37
+ // Prevent unhandled rejection warnings by attaching a catch handler
38
+ // The actual error handling happens when user calls done()
39
+ this.donePromise.catch(() => {
40
+ });
41
+ }
42
+ on(evt, fn) {
43
+ this.emitter.on(evt, fn);
44
+ return this;
45
+ }
46
+ off(evt, fn) {
47
+ this.emitter.off(evt, fn);
48
+ return this;
49
+ }
50
+ /** Await final mapped outputs */
51
+ done() {
52
+ return this.donePromise;
53
+ }
54
+ _emit(evt, ...args) {
55
+ this.emitter.emit(evt, ...args);
56
+ }
57
+ _finish(data) {
58
+ this.doneResolve(data);
59
+ this.emitter.emit("finished", data, data._promptId);
60
+ }
61
+ _fail(err, promptId) {
62
+ this.doneReject(err);
63
+ this.emitter.emit("failed", err, promptId);
64
+ }
65
+ }
66
+ export class Workflow {
67
+ json;
68
+ outputNodeIds = [];
69
+ outputAliases = {}; // nodeId -> alias
70
+ bypassedNodes = []; // nodes to bypass during execution
71
+ // Pending assets to upload before execution
72
+ _pendingImageInputs = [];
73
+ _pendingFolderFiles = [];
74
+ /** Structural hash of the workflow JSON for compatibility tracking in failover scenarios */
75
+ structureHash;
76
+ static from(data, opts) {
77
+ if (typeof data === "string") {
78
+ try {
79
+ const parsed = JSON.parse(data);
80
+ return new Workflow(parsed, opts);
81
+ }
82
+ catch (e) {
83
+ throw new Error("Failed to parse workflow JSON string", { cause: e });
84
+ }
85
+ }
86
+ return new Workflow(structuredClone(data), opts);
87
+ }
88
+ constructor(json, opts) {
89
+ this.json = structuredClone(json);
90
+ // Compute structural hash by default unless explicitly disabled
91
+ if (opts?.autoHash !== false) {
92
+ this.structureHash = hashWorkflow(this.json);
93
+ }
94
+ }
95
+ /**
96
+ * Like from(), but augments known node types (e.g., KSampler) with soft union hints
97
+ * for inputs such as sampler_name & scheduler while still allowing arbitrary strings.
98
+ */
99
+ static fromAugmented(data, opts) {
100
+ return Workflow.from(data, opts);
101
+ }
102
+ /** Set a nested input path on a node e.g. set('9.inputs.text','hello') */
103
+ set(path, value) {
104
+ const keys = path.split(".");
105
+ let cur = this.json;
106
+ for (let i = 0; i < keys.length - 1; i++) {
107
+ if (cur[keys[i]] === undefined)
108
+ cur[keys[i]] = {};
109
+ cur = cur[keys[i]];
110
+ }
111
+ cur[keys[keys.length - 1]] = value;
112
+ return this;
113
+ }
114
+ /** Attach a single image buffer to a node input (e.g., LoadImage.image). Will upload on run() then set the input to the filename. */
115
+ attachImage(nodeId, inputName, data, fileName, opts) {
116
+ const blob = toBlob(data, fileName);
117
+ this._pendingImageInputs.push({
118
+ nodeId: String(nodeId),
119
+ inputName,
120
+ blob,
121
+ fileName,
122
+ subfolder: opts?.subfolder,
123
+ override: opts?.override
124
+ });
125
+ return this;
126
+ }
127
+ /** Attach multiple files into a server subfolder (useful for LoadImageSetFromFolderNode). */
128
+ attachFolderFiles(subfolder, files, opts) {
129
+ for (const f of files) {
130
+ const blob = toBlob(f.data, f.fileName);
131
+ this._pendingFolderFiles.push({ subfolder, blob, fileName: f.fileName, override: opts?.override });
132
+ }
133
+ return this;
134
+ }
135
+ /**
136
+ * Sugar for setting a node's input: wf.input('SAMPLER','steps',30)
137
+ * Equivalent to set('SAMPLER.inputs.steps', 30).
138
+ * Performs a light existence check to aid DX (doesn't throw if missing by design unless strict parameter is passed).
139
+ */
140
+ input(nodeId, inputName, value, opts) {
141
+ const nodeKey = String(nodeId);
142
+ const node = this.json[nodeKey];
143
+ if (!node) {
144
+ if (opts?.strict)
145
+ throw new Error(`Workflow.input: node '${String(nodeId)}' not found`);
146
+ // create minimal node shell if non-strict (lets users build up dynamically)
147
+ this.json[nodeKey] = { inputs: { [inputName]: value } };
148
+ return this;
149
+ }
150
+ if (!node.inputs) {
151
+ if (opts?.strict)
152
+ throw new Error(`Workflow.input: node '${String(nodeId)}' missing inputs object`);
153
+ node.inputs = {};
154
+ }
155
+ node.inputs[inputName] = value;
156
+ return this;
157
+ }
158
+ batchInputs(a, b, c) {
159
+ // Form 1: (nodeId, values, opts)
160
+ if (typeof a === "string") {
161
+ const nodeId = a;
162
+ const values = b || {};
163
+ const opts = c || {};
164
+ for (const [k, v] of Object.entries(values)) {
165
+ this.input(nodeId, k, v, opts);
166
+ }
167
+ return this;
168
+ }
169
+ // Form 2: (batchObject, opts)
170
+ const batch = a || {};
171
+ const opts = b || {};
172
+ for (const [nodeId, values] of Object.entries(batch)) {
173
+ if (!values)
174
+ continue;
175
+ for (const [k, v] of Object.entries(values)) {
176
+ this.input(nodeId, k, v, opts);
177
+ }
178
+ }
179
+ return this;
180
+ }
181
+ /**
182
+ * Mark a node id whose outputs we want collected.
183
+ * Supports aliasing in two forms:
184
+ * - output('alias','9')
185
+ * - output('alias:9')
186
+ * - output('9') (no alias, raw node id key)
187
+ */
188
+ output(a, b) {
189
+ let alias;
190
+ let nodeId;
191
+ if (b) {
192
+ // Heuristic: if first arg looks like a node id and second arg looks like an alias, swap
193
+ // Node ids are often numeric strings (e.g., '2'); aliases are non-numeric labels.
194
+ const looksLikeNodeId = (s) => /^\d+$/.test(s) || this.json[s];
195
+ if (looksLikeNodeId(String(a)) && !looksLikeNodeId(String(b))) {
196
+ nodeId = String(a);
197
+ alias = String(b);
198
+ try {
199
+ console.warn(`Workflow.output called as output(nodeId, alias). Interpreting as output(alias,nodeId): '${alias}:${nodeId}'`);
200
+ }
201
+ catch {
202
+ }
203
+ }
204
+ else {
205
+ alias = String(a);
206
+ nodeId = String(b);
207
+ }
208
+ }
209
+ else {
210
+ // single param variant: maybe "alias:node" or just node
211
+ if (a.includes(":")) {
212
+ const [al, id] = a.split(":");
213
+ if (al && id) {
214
+ alias = al;
215
+ nodeId = id;
216
+ }
217
+ else {
218
+ nodeId = a;
219
+ }
220
+ }
221
+ else {
222
+ nodeId = a;
223
+ }
224
+ }
225
+ if (!this.outputNodeIds.includes(nodeId))
226
+ this.outputNodeIds.push(nodeId);
227
+ if (alias) {
228
+ this.outputAliases[nodeId] = alias;
229
+ }
230
+ return this; // typed refinement handled via declaration merging below
231
+ }
232
+ bypass(nodes) {
233
+ if (!Array.isArray(nodes)) {
234
+ nodes = [nodes];
235
+ }
236
+ for (const node of nodes) {
237
+ if (!this.bypassedNodes.includes(node)) {
238
+ this.bypassedNodes.push(node);
239
+ }
240
+ }
241
+ return this;
242
+ }
243
+ reinstate(nodes) {
244
+ if (!Array.isArray(nodes)) {
245
+ nodes = [nodes];
246
+ }
247
+ for (const node of nodes) {
248
+ const idx = this.bypassedNodes.indexOf(node);
249
+ if (idx !== -1) {
250
+ this.bypassedNodes.splice(idx, 1);
251
+ }
252
+ }
253
+ return this;
254
+ }
255
+ /**
256
+ * Update the structural hash after making non-dynamic changes to the workflow.
257
+ * Call this if you modify the workflow structure after initialization and the autoHash was disabled,
258
+ * or if you want to recalculate the hash after making structural changes.
259
+ *
260
+ * Example:
261
+ * ```
262
+ * const wf = Workflow.from(data, { autoHash: false });
263
+ * wf.input('SAMPLER', 'ckpt_name', 'model_v1.safetensors');
264
+ * wf.updateHash(); // Recompute hash after structural change
265
+ * ```
266
+ */
267
+ updateHash() {
268
+ this.structureHash = hashWorkflow(this.json);
269
+ return this;
270
+ }
271
+ /** IDE helper returning empty object typed as final result (aliases + metadata). */
272
+ typedResult() {
273
+ return {};
274
+ }
275
+ /** Get the raw workflow JSON structure. */
276
+ toJSON() {
277
+ return structuredClone(this.json);
278
+ }
279
+ /** Upload pending images to client */
280
+ async uploadAssets(api) {
281
+ // Upload any pending assets first, then patch JSON inputs
282
+ if (this._pendingFolderFiles.length || this._pendingImageInputs.length) {
283
+ // Upload folder files
284
+ for (const f of this._pendingFolderFiles) {
285
+ await api.ext.file.uploadImage(f.blob, f.fileName, { subfolder: f.subfolder, override: f.override });
286
+ }
287
+ // Upload and set single-image inputs
288
+ for (const it of this._pendingImageInputs) {
289
+ await api.ext.file.uploadImage(it.blob, it.fileName, { subfolder: it.subfolder, override: it.override });
290
+ // Prefer just the filename; many LoadImage nodes look up by filename (subfolder managed server-side)
291
+ this.input(it.nodeId, it.inputName, it.fileName);
292
+ }
293
+ // Clear pending once applied
294
+ this._pendingFolderFiles = [];
295
+ this._pendingImageInputs = [];
296
+ }
297
+ }
298
+ }
299
+ // Helper: normalize to Blob for upload
300
+ function toBlob(src, fileName) {
301
+ if (src instanceof Blob)
302
+ return src;
303
+ // Normalize everything to a plain ArrayBuffer for reliable BlobPart typing
304
+ let ab;
305
+ if (typeof Buffer !== "undefined" && src instanceof Buffer) {
306
+ const u8 = new Uint8Array(src);
307
+ ab = u8.slice(0).buffer;
308
+ }
309
+ else if (src instanceof Uint8Array) {
310
+ const u8 = new Uint8Array(src.byteLength);
311
+ u8.set(src);
312
+ ab = u8.buffer;
313
+ }
314
+ else if (src instanceof ArrayBuffer) {
315
+ ab = src;
316
+ }
317
+ else {
318
+ ab = new ArrayBuffer(0);
319
+ }
320
+ return new Blob([ab], { type: mimeFromName(fileName) });
321
+ }
322
+ function mimeFromName(name) {
323
+ if (!name)
324
+ return undefined;
325
+ const n = name.toLowerCase();
326
+ if (n.endsWith(".png"))
327
+ return "image/png";
328
+ if (n.endsWith(".jpg") || n.endsWith(".jpeg"))
329
+ return "image/jpeg";
330
+ if (n.endsWith(".webp"))
331
+ return "image/webp";
332
+ return undefined;
333
+ }
272
334
  //# sourceMappingURL=workflow.js.map