comfyui-node 1.3.1 → 1.4.0

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 (60) hide show
  1. package/README.md +39 -33
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/call-wrapper.d.ts +1 -0
  4. package/dist/call-wrapper.d.ts.map +1 -1
  5. package/dist/call-wrapper.js +136 -41
  6. package/dist/call-wrapper.js.map +1 -1
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +1 -0
  10. package/dist/index.js.map +1 -1
  11. package/dist/pool/WorkflowPool.d.ts +37 -0
  12. package/dist/pool/WorkflowPool.d.ts.map +1 -0
  13. package/dist/pool/WorkflowPool.js +435 -0
  14. package/dist/pool/WorkflowPool.js.map +1 -0
  15. package/dist/pool/client/ClientManager.d.ts +36 -0
  16. package/dist/pool/client/ClientManager.d.ts.map +1 -0
  17. package/dist/pool/client/ClientManager.js +104 -0
  18. package/dist/pool/client/ClientManager.js.map +1 -0
  19. package/dist/pool/failover/SmartFailoverStrategy.d.ts +18 -0
  20. package/dist/pool/failover/SmartFailoverStrategy.d.ts.map +1 -0
  21. package/dist/pool/failover/SmartFailoverStrategy.js +65 -0
  22. package/dist/pool/failover/SmartFailoverStrategy.js.map +1 -0
  23. package/dist/pool/failover/Strategy.d.ts +10 -0
  24. package/dist/pool/failover/Strategy.d.ts.map +1 -0
  25. package/dist/pool/failover/Strategy.js +2 -0
  26. package/dist/pool/failover/Strategy.js.map +1 -0
  27. package/dist/pool/index.d.ts +8 -0
  28. package/dist/pool/index.d.ts.map +1 -0
  29. package/dist/pool/index.js +4 -0
  30. package/dist/pool/index.js.map +1 -0
  31. package/dist/pool/queue/QueueAdapter.d.ts +31 -0
  32. package/dist/pool/queue/QueueAdapter.d.ts.map +1 -0
  33. package/dist/pool/queue/QueueAdapter.js +2 -0
  34. package/dist/pool/queue/QueueAdapter.js.map +1 -0
  35. package/dist/pool/queue/adapters/memory.d.ts +21 -0
  36. package/dist/pool/queue/adapters/memory.d.ts.map +1 -0
  37. package/dist/pool/queue/adapters/memory.js +96 -0
  38. package/dist/pool/queue/adapters/memory.js.map +1 -0
  39. package/dist/pool/types/events.d.ts +75 -0
  40. package/dist/pool/types/events.d.ts.map +1 -0
  41. package/dist/pool/types/events.js +2 -0
  42. package/dist/pool/types/events.js.map +1 -0
  43. package/dist/pool/types/job.d.ts +56 -0
  44. package/dist/pool/types/job.d.ts.map +1 -0
  45. package/dist/pool/types/job.js +2 -0
  46. package/dist/pool/types/job.js.map +1 -0
  47. package/dist/pool/utils/clone.d.ts +2 -0
  48. package/dist/pool/utils/clone.d.ts.map +1 -0
  49. package/dist/pool/utils/clone.js +7 -0
  50. package/dist/pool/utils/clone.js.map +1 -0
  51. package/dist/pool/utils/hash.d.ts +5 -0
  52. package/dist/pool/utils/hash.d.ts.map +1 -0
  53. package/dist/pool/utils/hash.js +19 -0
  54. package/dist/pool/utils/hash.js.map +1 -0
  55. package/dist/types/event.d.ts +3 -2
  56. package/dist/types/event.d.ts.map +1 -1
  57. package/dist/workflow.d.ts.map +1 -1
  58. package/dist/workflow.js +2 -1
  59. package/dist/workflow.js.map +1 -1
  60. package/package.json +4 -4
package/README.md CHANGED
@@ -452,50 +452,56 @@ Changing outputs later? Re‑generate the type after adding the new `.output()`
452
452
 
453
453
  ## Multi-Instance Pool
454
454
 
455
- `ComfyPool` provides weighted job scheduling & automatic client selection across multiple ComfyUI instances. It is transport‑agnostic and only relies on the standard `ComfyApi` event surface.
455
+ The SDK ships two pooling layers:
456
456
 
457
- ### Modes
457
+ - **`WorkflowPool` (new, recommended)** – Manages its own queue (pluggable adapters), emits per-job events with consistent job ids, and handles smart failover / retry without depending on the ComfyUI server queue depth. Ideal for multi-tenant services or when integrating with Redis/BullMQ/RabbitMQ backends.
458
+ - **`ComfyPool` (legacy)** – Weighted, in-memory scheduler that delegates most coordination to the ComfyUI queue. Useful for lightweight scripts or when you need backwards compatibility with earlier SDK versions.
458
459
 
459
- | Mode | Enum | Behavior | When to use |
460
- | ---- | ---- | -------- | ----------- |
461
- | Pick zero queue | `EQueueMode.PICK_ZERO` (default) | Choose any online client whose reported `queue_remaining` is 0 (prefers idle machines). Locks a client until it emits an execution event. | Co‑existence with the ComfyUI web UI where queue spikes are common. |
462
- | Lowest queue | `EQueueMode.PICK_LOWEST` | Choose the online client with the smallest `queue_remaining` (may still be busy). | High throughput batch ingestion; keeps all nodes saturated. |
463
- | Round‑robin | `EQueueMode.PICK_ROUTINE` | Simple rotation through available online clients irrespective of queue depth. | Latency balancing; predictable distribution. |
464
-
465
- ### Basic Example
460
+ ### WorkflowPool Snapshot
466
461
 
467
462
  ```ts
468
- import { ComfyApi, ComfyPool, EQueueMode, CallWrapper, PromptBuilder, seed } from "comfyui-node";
469
- import ExampleTxt2ImgWorkflow from "./example-txt2img-workflow.json";
470
- // ... pool basic example content (see earlier dedicated Workflow section for high-level abstraction)
471
- ```
463
+ import { ComfyApi, WorkflowPool, MemoryQueueAdapter } from "comfyui-node";
464
+ import WorkflowJson from "./example-txt2img-workflow.json";
472
465
 
473
- Pool variant (experimental):
466
+ const clients = [
467
+ new ComfyApi("http://localhost:8188"),
468
+ new ComfyApi("http://localhost:8189")
469
+ ];
474
470
 
475
- ```ts
476
- import { ComfyApi, ComfyPool, Workflow } from 'comfyui-node';
477
- import BaseWorkflow from './example-txt2img-workflow.json';
471
+ const pool = new WorkflowPool(clients, {
472
+ queueAdapter: new MemoryQueueAdapter()
473
+ });
478
474
 
479
- const pool = new ComfyPool([
480
- new ComfyApi('http://localhost:8188'),
481
- new ComfyApi('http://localhost:8189')
482
- ]);
475
+ pool.on("job:progress", (ev) => {
476
+ console.log(`job ${ev.detail.jobId} -> ${ev.detail.progress.value}/${ev.detail.progress.max}`);
477
+ });
483
478
 
484
- const wf = Workflow.from(BaseWorkflow)
485
- .set('6.inputs.text', 'A macro photo of a dewdrop on a leaf')
486
- .output('9');
479
+ pool.on("client:blocked_workflow", (ev) => {
480
+ console.warn(`client ${ev.detail.clientId} cooling off for workflow ${ev.detail.workflowHash.slice(0, 8)}`);
481
+ });
487
482
 
488
- // Run using one specific API (pool provided for scheduling context)
489
- const api = pool.clients[0];
490
- const job = await api.run(wf, { pool });
491
- await job.done();
483
+ const jobId = await pool.enqueue(WorkflowJson, {
484
+ metadata: { tenant: "alpha" },
485
+ includeOutputs: ["9"],
486
+ priority: 10
487
+ });
488
+
489
+ console.log("queued", jobId);
492
490
  ```
493
491
 
494
- Notes:
492
+ See `docs/workflow-pool.md` for full API and event reference.
495
493
 
496
- - Experimental surface: event names / helpers may refine before a stable minor release.
497
- - Falls back to `SaveImage` detection if you omit `output(...)`.
498
- - For advanced validation, serialization, or complex key mapping prefer `PromptBuilder`.
494
+ ### Legacy Pool (`ComfyPool`)
495
+
496
+ The legacy `ComfyPool` is a simpler, in-memory scheduler that relies on the server's queue depth for load balancing.
497
+
498
+ #### ComfyPool Modes
499
+
500
+ | Mode | Enum | Behavior | When to use |
501
+ | ---- | ---- | -------- | ----------- |
502
+ | Pick zero queue | `EQueueMode.PICK_ZERO` (default) | Choose any online client whose reported `queue_remaining` is 0 (prefers idle machines). Locks a client until it emits an execution event. | Co-existence with the ComfyUI web UI where queue spikes are common. |
503
+ | Lowest queue | `EQueueMode.PICK_LOWEST` | Choose the online client with the smallest `queue_remaining` (may still be busy). | High throughput batch ingestion; keeps all nodes saturated. |
504
+ | Round-robin | `EQueueMode.PICK_ROUTINE` | Simple rotation through available online clients irrespective of queue depth. | Latency balancing; predictable distribution. |
499
505
 
500
506
  ---
501
507
 
@@ -1102,7 +1108,7 @@ If you only need generation progress & previews you do NOT need the Crystools ex
1102
1108
 
1103
1109
  ## Examples
1104
1110
 
1105
- See the `examples` directory for texttoimage, imagetoimage, upscaling and pool orchestration patterns.
1111
+ See the `examples` directory for text-to-image, image-to-image, upscaling and pool orchestration patterns. For an end-to-end WorkflowPool + WebSocket demo, open `demos/recursive-edit/` and run the recursive image editing server + web client.
1106
1112
 
1107
1113
  ## Errors & Diagnostics
1108
1114