comfyui-node 1.6.3 → 1.6.5

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 (53) hide show
  1. package/README.md +121 -9
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/call-wrapper.d.ts.map +1 -1
  4. package/dist/call-wrapper.js +859 -856
  5. package/dist/call-wrapper.js.map +1 -1
  6. package/dist/client.d.ts +27 -0
  7. package/dist/client.d.ts.map +1 -1
  8. package/dist/client.js +87 -6
  9. package/dist/client.js.map +1 -1
  10. package/dist/index.d.ts +6 -3
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +2 -0
  13. package/dist/index.js.map +1 -1
  14. package/dist/multipool/client-registry.d.ts +23 -32
  15. package/dist/multipool/client-registry.d.ts.map +1 -1
  16. package/dist/multipool/client-registry.js +1 -1
  17. package/dist/multipool/client-registry.js.map +1 -1
  18. package/dist/multipool/interfaces.d.ts +106 -0
  19. package/dist/multipool/interfaces.d.ts.map +1 -1
  20. package/dist/multipool/job-profiler.d.ts +64 -127
  21. package/dist/multipool/job-profiler.d.ts.map +1 -1
  22. package/dist/multipool/job-profiler.js +221 -221
  23. package/dist/multipool/job-profiler.js.map +1 -1
  24. package/dist/multipool/job-queue-processor.d.ts +23 -27
  25. package/dist/multipool/job-queue-processor.d.ts.map +1 -1
  26. package/dist/multipool/job-queue-processor.js +196 -196
  27. package/dist/multipool/job-queue-processor.js.map +1 -1
  28. package/dist/multipool/job-state-registry.d.ts +42 -66
  29. package/dist/multipool/job-state-registry.d.ts.map +1 -1
  30. package/dist/multipool/job-state-registry.js.map +1 -1
  31. package/dist/multipool/multi-workflow-pool.d.ts +2 -3
  32. package/dist/multipool/multi-workflow-pool.d.ts.map +1 -1
  33. package/dist/multipool/multi-workflow-pool.js +61 -30
  34. package/dist/multipool/multi-workflow-pool.js.map +1 -1
  35. package/dist/multipool/pool-event-manager.d.ts +10 -10
  36. package/dist/multipool/pool-event-manager.d.ts.map +1 -1
  37. package/dist/multipool/workflow.d.ts +178 -178
  38. package/dist/multipool/workflow.d.ts.map +1 -1
  39. package/dist/multipool/workflow.js +333 -333
  40. package/dist/pool/WorkflowPool.d.ts.map +1 -1
  41. package/dist/pool/WorkflowPool.js +855 -845
  42. package/dist/pool/WorkflowPool.js.map +1 -1
  43. package/dist/pool/client/ClientManager.js +215 -215
  44. package/dist/pool/index.js +3 -3
  45. package/dist/pool/types/job.d.ts +15 -0
  46. package/dist/pool/types/job.d.ts.map +1 -1
  47. package/dist/types/event.d.ts +17 -1
  48. package/dist/types/event.d.ts.map +1 -1
  49. package/dist/utils/model-loading.d.ts +158 -0
  50. package/dist/utils/model-loading.d.ts.map +1 -0
  51. package/dist/utils/model-loading.js +273 -0
  52. package/dist/utils/model-loading.js.map +1 -0
  53. package/package.json +9 -5
package/README.md CHANGED
@@ -136,12 +136,64 @@ Hash-based routing intelligently handles failures at the workflow level (not cli
136
136
 
137
137
  See [Hash-Based Routing Guide](./docs/hash-routing-guide.md) for details and demos.
138
138
 
139
- ## What's New in v1.5.0
139
+ ### Advanced: `MultiWorkflowPool` for Heterogeneous Clusters
140
140
 
141
- - **WorkflowPool Profiling** Enable automatic per-node performance tracking with `enableProfiling: true`.
142
- - **Timeout Protection** – Prevent jobs from hanging with `executionStartTimeoutMs` and `nodeExecutionTimeoutMs`.
143
- - **Idle connection stability** Automatic health checks keep WebSocket connections alive.
144
- - **Better DX** – Comprehensive JSDoc comments and exported types for all pool options.
141
+ For complex use cases involving a heterogeneous cluster of workers (e.g., some with SDXL models, others for video generation), `MultiWorkflowPool` provides fine-grained control over job routing based on workflow requirements.
142
+
143
+ It uses an event-driven architecture to manage clients with specific **workflow affinities**, ensuring that jobs are only sent to nodes capable of processing them.
144
+
145
+ - **Workflow Affinity:** Assign clients to specific workflows. Jobs are automatically routed to the correct client.
146
+ - **Dynamic Job Queues:** A separate job queue is created for each workflow type, preventing head-of-line blocking.
147
+ - **Event-Driven Architecture:** Zero polling for maximum efficiency and responsiveness.
148
+ - **Built-in Monitoring:** Optional real-time monitoring of client and queue states.
149
+
150
+ **Example:**
151
+ ```ts
152
+ import { MultiWorkflowPool, Workflow } from "comfyui-node";
153
+ import SdxlWorkflow from './sdxl-workflow.json';
154
+ import VideoWorkflow from './video-workflow.json';
155
+
156
+ // 1. Define workflows and generate their hash for affinity mapping
157
+ const sdxlWF = Workflow.from(SdxlWorkflow).updateHash();
158
+ const videoWF = Workflow.from(VideoWorkflow).updateHash();
159
+
160
+ // 2. Create a new pool
161
+ const pool = new MultiWorkflowPool({
162
+ logLevel: "info",
163
+ enableMonitoring: true,
164
+ });
165
+
166
+ // 3. Add clients with workflow affinity
167
+ // This client is specialized for SDXL workflows
168
+ pool.addClient("http://localhost:8188", { workflowAffinity: [sdxlWF] });
169
+
170
+ // This client is specialized for Video workflows
171
+ pool.addClient("http://localhost:8189", { workflowAffinity: [videoWF] });
172
+
173
+ // This client is a general-purpose worker
174
+ pool.addClient("http://localhost:8190");
175
+
176
+ // 4. Initialize the pool (connects to all clients)
177
+ await pool.init();
178
+
179
+ // 5. Submit jobs
180
+ // The pool automatically routes them to the correct client
181
+ const sdxlJobId = await pool.submitJob(sdxlWF);
182
+ const videoJobId = await pool.submitJob(videoWF);
183
+
184
+ // 6. Wait for a job to complete
185
+ const results = await pool.waitForJobCompletion(sdxlJobId);
186
+ console.log("SDXL Job completed!", results.images);
187
+ ```
188
+
189
+ ## What's New in v1.6.5
190
+
191
+ - **Integration Test Infrastructure** – Comprehensive reconnection testing with real mock server processes
192
+ - Mock servers spawn in separate OS processes that can be killed/restarted
193
+ - 13 integration tests covering manual/auto-reconnection, state transitions, and multiple restart cycles
194
+ - Test helpers and utilities for easy test development
195
+ - 900+ lines of documentation with quick-start guide and examples
196
+ - Run with: `bun test test/integration/` or `bun run test:integration`
145
197
 
146
198
  See [CHANGELOG.md](./CHANGELOG.md) for complete release notes.
147
199
 
@@ -200,11 +252,71 @@ job.on('failed', err => console.error(err));
200
252
 
201
253
  ## Testing
202
254
 
255
+ ### Unit and Integration Tests
256
+
203
257
  ```bash
204
- bun test # Unit + integration tests
205
- bun run test:real # Real server tests (COMFY_REAL=1)
206
- bun run test:full # Comprehensive tests (COMFY_FULL=1)
207
- bun run coverage # Coverage report
258
+ bun test # Unit + integration tests
259
+ bun run test:integration # Run all integration tests
260
+ bun run test:integration:simple # Run simple reconnection examples
261
+ bun run test:real # Real server tests (COMFY_REAL=1)
262
+ bun run test:full # Comprehensive tests (COMFY_FULL=1)
263
+ bun run coverage # Coverage report
264
+ ```
265
+
266
+ ### Integration Tests (v1.6.5+)
267
+
268
+ The library includes a comprehensive integration test infrastructure that spawns real mock server processes to test reconnection behavior:
269
+
270
+ ```bash
271
+ # Run all integration tests
272
+ bun test test/integration/
273
+
274
+ # Run simple examples (recommended first)
275
+ bun run test:integration:simple
276
+
277
+ # Validate the mock server infrastructure
278
+ bun test/integration/validate-mock-server.ts
279
+
280
+ # Debug: Run mock server standalone
281
+ bun test/integration/mock-server.ts 8191
282
+ ```
283
+
284
+ **What's Tested:**
285
+ - Manual and automatic reconnection after server crashes
286
+ - Connection state transitions (connecting → connected → disconnected → reconnecting)
287
+ - Event emission (`reconnected`, `reconnection_failed`)
288
+ - Multiple server restart cycles
289
+ - WebSocket message handling across reconnections
290
+
291
+ **Documentation:**
292
+ - `test/integration/README.md` – Comprehensive guide
293
+ - `test/integration/QUICKSTART.md` – Developer quick-start with patterns
294
+ - `test/integration/SUMMARY.md` – Architecture overview
295
+
296
+ **Example:**
297
+ ```ts
298
+ // Integration test pattern
299
+ const manager = new ServerManager({ port: 8191 });
300
+ await manager.startServer(8191);
301
+
302
+ const api = new ComfyApi("http://localhost:8191");
303
+ await initializeClient(api);
304
+
305
+ // Kill server to simulate crash
306
+ await manager.killServer(8191);
307
+ await sleep(500);
308
+
309
+ // Restart server
310
+ await manager.startServer(8191);
311
+
312
+ // Verify reconnection
313
+ await api.reconnectWs(true);
314
+ await waitForConnection(api);
315
+ expect(api.isConnected()).toBe(true);
316
+
317
+ // Cleanup
318
+ api.destroy();
319
+ await manager.killAll();
208
320
  ```
209
321
 
210
322
  See [Troubleshooting docs](./docs/troubleshooting.md#testing--coverage) for details.