comfyui-node 1.6.6 → 1.6.7

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 (51) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +342 -341
  3. package/dist/.tsbuildinfo +1 -1
  4. package/dist/multipool/client-registry.d.ts +3 -3
  5. package/dist/multipool/client-registry.d.ts.map +1 -1
  6. package/dist/multipool/client-registry.js +9 -9
  7. package/dist/multipool/client-registry.js.map +1 -1
  8. package/dist/multipool/helpers.d.ts +4 -4
  9. package/dist/multipool/index.d.ts +2 -2
  10. package/dist/multipool/interfaces.d.ts +0 -2
  11. package/dist/multipool/interfaces.d.ts.map +1 -1
  12. package/dist/multipool/job-queue-processor.d.ts +3 -3
  13. package/dist/multipool/job-queue-processor.d.ts.map +1 -1
  14. package/dist/multipool/job-queue-processor.js +28 -27
  15. package/dist/multipool/job-queue-processor.js.map +1 -1
  16. package/dist/multipool/logger.d.ts +29 -29
  17. package/dist/multipool/multi-workflow-pool.d.ts +0 -1
  18. package/dist/multipool/multi-workflow-pool.d.ts.map +1 -1
  19. package/dist/multipool/multi-workflow-pool.js +36 -37
  20. package/dist/multipool/multi-workflow-pool.js.map +1 -1
  21. package/dist/multipool/tests/client-registry-api-demo.js +1 -3
  22. package/dist/multipool/tests/client-registry-api-demo.js.map +1 -1
  23. package/dist/multipool/tests/client-registry.spec.js +6 -7
  24. package/dist/multipool/tests/client-registry.spec.js.map +1 -1
  25. package/dist/multipool/tests/error-classification-tests.d.ts +1 -1
  26. package/dist/multipool/tests/event-forwarding-demo.js +1 -3
  27. package/dist/multipool/tests/event-forwarding-demo.js.map +1 -1
  28. package/dist/multipool/tests/job-queue-processor.spec.js +7 -7
  29. package/dist/multipool/tests/job-queue-processor.spec.js.map +1 -1
  30. package/dist/multipool/tests/job-state-registry.d.ts +16 -16
  31. package/dist/multipool/tests/job-state-registry.js +23 -23
  32. package/dist/multipool/tests/job-state-registry.spec.js +5 -4
  33. package/dist/multipool/tests/job-state-registry.spec.js.map +1 -1
  34. package/dist/multipool/tests/multipool-basic.d.ts +11 -11
  35. package/dist/multipool/tests/profiling-demo.d.ts +6 -6
  36. package/dist/multipool/tests/profiling-demo.js +1 -2
  37. package/dist/multipool/tests/profiling-demo.js.map +1 -1
  38. package/dist/multipool/tests/prompt-generator.d.ts +9 -9
  39. package/dist/multipool/tests/test-helpers.d.ts +3 -3
  40. package/dist/multipool/tests/two-stage-edit-simulation.d.ts +31 -31
  41. package/dist/multipool/tests/two-stage-edit-simulation.d.ts.map +1 -1
  42. package/dist/multipool/tests/two-stage-edit-simulation.js +1 -2
  43. package/dist/multipool/tests/two-stage-edit-simulation.js.map +1 -1
  44. package/dist/pool/SmartPool.d.ts +143 -143
  45. package/dist/pool/SmartPool.js +676 -676
  46. package/dist/pool/SmartPoolV2.d.ts +119 -119
  47. package/dist/pool/SmartPoolV2.js +586 -586
  48. package/dist/pool/WorkflowPool.d.ts +202 -202
  49. package/dist/pool/client/ClientManager.d.ts +86 -86
  50. package/dist/pool/index.d.ts +9 -9
  51. package/package.json +2 -2
@@ -1,203 +1,203 @@
1
- import { TypedEventTarget } from "../typed-event-target.js";
2
- import type { ComfyApi } from "../client.js";
3
- import type { QueueAdapter, QueueStats } from "./queue/QueueAdapter.js";
4
- import type { FailoverStrategy } from "./failover/Strategy.js";
5
- import type { JobRecord, WorkflowInput, WorkflowJobOptions, JobId } from "./types/job.js";
6
- import type { WorkflowPoolEventMap } from "./types/events.js";
7
- import type { WorkflowAffinity } from "./types/affinity.js";
8
- /**
9
- * Configuration options for WorkflowPool.
10
- */
11
- export interface WorkflowPoolOpts {
12
- /**
13
- * An array of workflow affinity rules to establish a default mapping
14
- * between workflows and specific clients.
15
- *
16
- * @example
17
- * ```ts
18
- * const pool = new WorkflowPool(clients, {
19
- * workflowAffinities: [
20
- * { workflowHash: "hash1", preferredClientIds: ["client-a"] },
21
- * { workflowHash: "hash2", excludeClientIds: ["client-b"] },
22
- * ]
23
- * });
24
- * ```
25
- */
26
- workflowAffinities?: WorkflowAffinity[];
27
- /**
28
- * Queue adapter for managing job queue operations.
29
- *
30
- * @default MemoryQueueAdapter (in-memory queue)
31
- * @example
32
- * ```ts
33
- * import { WorkflowPool, MemoryQueueAdapter } from 'comfyui-node';
34
- * const pool = new WorkflowPool(clients, {
35
- * queueAdapter: new MemoryQueueAdapter()
36
- * });
37
- * ```
38
- */
39
- queueAdapter?: QueueAdapter;
40
- /**
41
- * Failover strategy for handling client failures and workflow routing.
42
- *
43
- * @default SmartFailoverStrategy (exponential backoff with workflow-specific cooldowns)
44
- * @example
45
- * ```ts
46
- * import { WorkflowPool, SmartFailoverStrategy } from 'comfyui-node';
47
- * const pool = new WorkflowPool(clients, {
48
- * failoverStrategy: new SmartFailoverStrategy()
49
- * });
50
- * ```
51
- */
52
- failoverStrategy?: FailoverStrategy;
53
- /**
54
- * Base retry backoff delay in milliseconds for failed jobs.
55
- * Actual delay may be adjusted by the failover strategy.
56
- *
57
- * @default 1000 (1 second)
58
- */
59
- retryBackoffMs?: number;
60
- /**
61
- * Timeout in milliseconds for execution to start after job is queued.
62
- *
63
- * If a server gets stuck before emitting the `execution_start` event, the job
64
- * will be failed and retried on another server after this timeout.
65
- *
66
- * This prevents jobs from being lost when a server accepts a prompt but fails
67
- * to begin execution (e.g., GPU hang, process crash, deadlock).
68
- *
69
- * Set to `0` to disable timeout (not recommended for production).
70
- *
71
- * @default 5000 (5 seconds)
72
- * @example
73
- * ```ts
74
- * const pool = new WorkflowPool(clients, {
75
- * executionStartTimeoutMs: 10000 // 10 seconds
76
- * });
77
- * ```
78
- * @since 1.5.0
79
- */
80
- executionStartTimeoutMs?: number;
81
- /**
82
- * Timeout in milliseconds for individual node execution.
83
- *
84
- * If a node takes longer than this timeout to execute (time between `executing` events),
85
- * the job will be failed and retried on another server.
86
- *
87
- * This is critical for:
88
- * - Model loading on slow disks (can take 60+ seconds on first load)
89
- * - Heavy diffusion steps on slower GPUs
90
- * - VAE decode operations on large images
91
- * - Custom nodes with long processing times
92
- *
93
- * The timeout is per-node, not total execution time. Each node gets the full timeout duration.
94
- *
95
- * Set to `0` to disable timeout (not recommended for production).
96
- *
97
- * @default 300000 (5 minutes)
98
- * @example
99
- * ```ts
100
- * const pool = new WorkflowPool(clients, {
101
- * nodeExecutionTimeoutMs: 600000 // 10 minutes for slow model loading
102
- * });
103
- * ```
104
- * @remarks
105
- * - Timeout resets when a new node starts executing
106
- * - Progress events (e.g., KSampler steps) reset the timeout
107
- * - First generation with model loading often needs longer timeout
108
- * - Cached nodes complete instantly and don't trigger timeout
109
- * @since 1.5.0
110
- */
111
- nodeExecutionTimeoutMs?: number;
112
- /**
113
- * Interval in milliseconds for health check pings to keep WebSocket connections alive.
114
- *
115
- * Health checks prevent idle connection timeouts by periodically pinging inactive clients
116
- * with lightweight `getQueue()` calls. This maintains stable connections when the pool
117
- * has no active jobs, avoiding false disconnection alerts.
118
- *
119
- * Set to `0` to disable health checks (not recommended for production).
120
- *
121
- * @default 30000 (30 seconds)
122
- * @example
123
- * ```ts
124
- * const pool = new WorkflowPool(clients, {
125
- * healthCheckIntervalMs: 30000 // ping every 30 seconds
126
- * });
127
- * ```
128
- * @remarks
129
- * - Only pings idle (non-busy) clients to avoid interference with active jobs
130
- * - Recommended for long-running services or when using persistent connections
131
- * - Lower values increase network traffic but detect issues faster
132
- * - Higher values reduce overhead but may miss connection issues sooner
133
- * @since 1.4.1
134
- */
135
- healthCheckIntervalMs?: number;
136
- /**
137
- * Enable automatic profiling of workflow execution.
138
- *
139
- * When enabled, captures detailed per-node execution metrics including:
140
- * - Node execution timing (start, end, duration)
141
- * - Progress events for long-running nodes
142
- * - Cached vs executed nodes
143
- * - Execution order and dependencies
144
- *
145
- * Profile stats are attached to `JobRecord.profileStats` and included
146
- * in `job:completed` event details.
147
- *
148
- * @default false
149
- * @example
150
- * ```ts
151
- * const pool = new WorkflowPool(clients, {
152
- * enableProfiling: true
153
- * });
154
- *
155
- * pool.on('job:completed', (event) => {
156
- * const stats = event.detail.job.profileStats;
157
- * console.log(`Total: ${stats.totalDuration}ms`);
158
- * console.log(`Slowest nodes:`, stats.summary.slowestNodes);
159
- * });
160
- * ```
161
- * @since 1.5.0
162
- */
163
- enableProfiling?: boolean;
164
- }
165
- export declare class WorkflowPool extends TypedEventTarget<WorkflowPoolEventMap> {
166
- private queue;
167
- private strategy;
168
- private clientManager;
169
- private opts;
170
- private jobStore;
171
- private jobFailureAnalysis;
172
- private affinities;
173
- private initPromise;
174
- private processing;
175
- private processQueued;
176
- private activeJobs;
177
- private readonly queueDebug;
178
- private debugLog;
179
- constructor(clients: ComfyApi[], opts?: WorkflowPoolOpts);
180
- ready(): Promise<void>;
181
- setAffinity(affinity: WorkflowAffinity): void;
182
- removeAffinity(workflowHash: string): boolean;
183
- getAffinities(): WorkflowAffinity[];
184
- enqueue(workflowInput: WorkflowInput, options?: WorkflowJobOptions): Promise<JobId>;
185
- getJob(jobId: string): JobRecord | undefined;
186
- cancel(jobId: string): Promise<boolean>;
187
- shutdown(): Promise<void>;
188
- getQueueStats(): Promise<QueueStats>;
189
- private normalizeWorkflow;
190
- private generateJobId;
191
- private static fallbackId;
192
- private scheduleProcess;
193
- private applyAutoSeed;
194
- private rememberJobFailure;
195
- private clearJobFailures;
196
- private collectFailureReasons;
197
- private addPermanentExclusion;
198
- private hasRetryPath;
199
- private createWorkflowNotSupportedError;
200
- private processQueue;
201
- private runJob;
202
- }
1
+ import { TypedEventTarget } from "../typed-event-target.js";
2
+ import type { ComfyApi } from "../client.js";
3
+ import type { QueueAdapter, QueueStats } from "./queue/QueueAdapter.js";
4
+ import type { FailoverStrategy } from "./failover/Strategy.js";
5
+ import type { JobRecord, WorkflowInput, WorkflowJobOptions, JobId } from "./types/job.js";
6
+ import type { WorkflowPoolEventMap } from "./types/events.js";
7
+ import type { WorkflowAffinity } from "./types/affinity.js";
8
+ /**
9
+ * Configuration options for WorkflowPool.
10
+ */
11
+ export interface WorkflowPoolOpts {
12
+ /**
13
+ * An array of workflow affinity rules to establish a default mapping
14
+ * between workflows and specific clients.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * const pool = new WorkflowPool(clients, {
19
+ * workflowAffinities: [
20
+ * { workflowHash: "hash1", preferredClientIds: ["client-a"] },
21
+ * { workflowHash: "hash2", excludeClientIds: ["client-b"] },
22
+ * ]
23
+ * });
24
+ * ```
25
+ */
26
+ workflowAffinities?: WorkflowAffinity[];
27
+ /**
28
+ * Queue adapter for managing job queue operations.
29
+ *
30
+ * @default MemoryQueueAdapter (in-memory queue)
31
+ * @example
32
+ * ```ts
33
+ * import { WorkflowPool, MemoryQueueAdapter } from 'comfyui-node';
34
+ * const pool = new WorkflowPool(clients, {
35
+ * queueAdapter: new MemoryQueueAdapter()
36
+ * });
37
+ * ```
38
+ */
39
+ queueAdapter?: QueueAdapter;
40
+ /**
41
+ * Failover strategy for handling client failures and workflow routing.
42
+ *
43
+ * @default SmartFailoverStrategy (exponential backoff with workflow-specific cooldowns)
44
+ * @example
45
+ * ```ts
46
+ * import { WorkflowPool, SmartFailoverStrategy } from 'comfyui-node';
47
+ * const pool = new WorkflowPool(clients, {
48
+ * failoverStrategy: new SmartFailoverStrategy()
49
+ * });
50
+ * ```
51
+ */
52
+ failoverStrategy?: FailoverStrategy;
53
+ /**
54
+ * Base retry backoff delay in milliseconds for failed jobs.
55
+ * Actual delay may be adjusted by the failover strategy.
56
+ *
57
+ * @default 1000 (1 second)
58
+ */
59
+ retryBackoffMs?: number;
60
+ /**
61
+ * Timeout in milliseconds for execution to start after job is queued.
62
+ *
63
+ * If a server gets stuck before emitting the `execution_start` event, the job
64
+ * will be failed and retried on another server after this timeout.
65
+ *
66
+ * This prevents jobs from being lost when a server accepts a prompt but fails
67
+ * to begin execution (e.g., GPU hang, process crash, deadlock).
68
+ *
69
+ * Set to `0` to disable timeout (not recommended for production).
70
+ *
71
+ * @default 5000 (5 seconds)
72
+ * @example
73
+ * ```ts
74
+ * const pool = new WorkflowPool(clients, {
75
+ * executionStartTimeoutMs: 10000 // 10 seconds
76
+ * });
77
+ * ```
78
+ * @since 1.5.0
79
+ */
80
+ executionStartTimeoutMs?: number;
81
+ /**
82
+ * Timeout in milliseconds for individual node execution.
83
+ *
84
+ * If a node takes longer than this timeout to execute (time between `executing` events),
85
+ * the job will be failed and retried on another server.
86
+ *
87
+ * This is critical for:
88
+ * - Model loading on slow disks (can take 60+ seconds on first load)
89
+ * - Heavy diffusion steps on slower GPUs
90
+ * - VAE decode operations on large images
91
+ * - Custom nodes with long processing times
92
+ *
93
+ * The timeout is per-node, not total execution time. Each node gets the full timeout duration.
94
+ *
95
+ * Set to `0` to disable timeout (not recommended for production).
96
+ *
97
+ * @default 300000 (5 minutes)
98
+ * @example
99
+ * ```ts
100
+ * const pool = new WorkflowPool(clients, {
101
+ * nodeExecutionTimeoutMs: 600000 // 10 minutes for slow model loading
102
+ * });
103
+ * ```
104
+ * @remarks
105
+ * - Timeout resets when a new node starts executing
106
+ * - Progress events (e.g., KSampler steps) reset the timeout
107
+ * - First generation with model loading often needs longer timeout
108
+ * - Cached nodes complete instantly and don't trigger timeout
109
+ * @since 1.5.0
110
+ */
111
+ nodeExecutionTimeoutMs?: number;
112
+ /**
113
+ * Interval in milliseconds for health check pings to keep WebSocket connections alive.
114
+ *
115
+ * Health checks prevent idle connection timeouts by periodically pinging inactive clients
116
+ * with lightweight `getQueue()` calls. This maintains stable connections when the pool
117
+ * has no active jobs, avoiding false disconnection alerts.
118
+ *
119
+ * Set to `0` to disable health checks (not recommended for production).
120
+ *
121
+ * @default 30000 (30 seconds)
122
+ * @example
123
+ * ```ts
124
+ * const pool = new WorkflowPool(clients, {
125
+ * healthCheckIntervalMs: 30000 // ping every 30 seconds
126
+ * });
127
+ * ```
128
+ * @remarks
129
+ * - Only pings idle (non-busy) clients to avoid interference with active jobs
130
+ * - Recommended for long-running services or when using persistent connections
131
+ * - Lower values increase network traffic but detect issues faster
132
+ * - Higher values reduce overhead but may miss connection issues sooner
133
+ * @since 1.4.1
134
+ */
135
+ healthCheckIntervalMs?: number;
136
+ /**
137
+ * Enable automatic profiling of workflow execution.
138
+ *
139
+ * When enabled, captures detailed per-node execution metrics including:
140
+ * - Node execution timing (start, end, duration)
141
+ * - Progress events for long-running nodes
142
+ * - Cached vs executed nodes
143
+ * - Execution order and dependencies
144
+ *
145
+ * Profile stats are attached to `JobRecord.profileStats` and included
146
+ * in `job:completed` event details.
147
+ *
148
+ * @default false
149
+ * @example
150
+ * ```ts
151
+ * const pool = new WorkflowPool(clients, {
152
+ * enableProfiling: true
153
+ * });
154
+ *
155
+ * pool.on('job:completed', (event) => {
156
+ * const stats = event.detail.job.profileStats;
157
+ * console.log(`Total: ${stats.totalDuration}ms`);
158
+ * console.log(`Slowest nodes:`, stats.summary.slowestNodes);
159
+ * });
160
+ * ```
161
+ * @since 1.5.0
162
+ */
163
+ enableProfiling?: boolean;
164
+ }
165
+ export declare class WorkflowPool extends TypedEventTarget<WorkflowPoolEventMap> {
166
+ private queue;
167
+ private strategy;
168
+ private clientManager;
169
+ private opts;
170
+ private jobStore;
171
+ private jobFailureAnalysis;
172
+ private affinities;
173
+ private initPromise;
174
+ private processing;
175
+ private processQueued;
176
+ private activeJobs;
177
+ private readonly queueDebug;
178
+ private debugLog;
179
+ constructor(clients: ComfyApi[], opts?: WorkflowPoolOpts);
180
+ ready(): Promise<void>;
181
+ setAffinity(affinity: WorkflowAffinity): void;
182
+ removeAffinity(workflowHash: string): boolean;
183
+ getAffinities(): WorkflowAffinity[];
184
+ enqueue(workflowInput: WorkflowInput, options?: WorkflowJobOptions): Promise<JobId>;
185
+ getJob(jobId: string): JobRecord | undefined;
186
+ cancel(jobId: string): Promise<boolean>;
187
+ shutdown(): Promise<void>;
188
+ getQueueStats(): Promise<QueueStats>;
189
+ private normalizeWorkflow;
190
+ private generateJobId;
191
+ private static fallbackId;
192
+ private scheduleProcess;
193
+ private applyAutoSeed;
194
+ private rememberJobFailure;
195
+ private clearJobFailures;
196
+ private collectFailureReasons;
197
+ private addPermanentExclusion;
198
+ private hasRetryPath;
199
+ private createWorkflowNotSupportedError;
200
+ private processQueue;
201
+ private runJob;
202
+ }
203
203
  //# sourceMappingURL=WorkflowPool.d.ts.map
@@ -1,87 +1,87 @@
1
- import type { ComfyApi } from "../../client.js";
2
- import { TypedEventTarget } from "../../typed-event-target.js";
3
- import type { JobRecord } from "../types/job.js";
4
- import type { FailoverStrategy } from "../failover/Strategy.js";
5
- import type { WorkflowPoolEventMap } from "../types/events.js";
6
- export interface ManagedClient {
7
- client: ComfyApi;
8
- id: string;
9
- online: boolean;
10
- busy: boolean;
11
- lastError?: unknown;
12
- lastSeenAt: number;
13
- supportedWorkflows: Set<string>;
14
- lastDisconnectedAt?: number;
15
- reconnectionStableAt?: number;
16
- }
17
- interface ClientLease {
18
- client: ComfyApi;
19
- clientId: string;
20
- release: (opts?: {
21
- success?: boolean;
22
- }) => void;
23
- }
24
- export declare class ClientManager extends TypedEventTarget<WorkflowPoolEventMap> {
25
- private clients;
26
- private strategy;
27
- private healthCheckInterval;
28
- private readonly healthCheckIntervalMs;
29
- private readonly debugLogs;
30
- /**
31
- * Grace period after reconnection before client is considered stable (default: 10 seconds).
32
- * ComfyUI sometimes quickly disconnects/reconnects after job execution.
33
- * During this grace period, the client won't be used for new jobs.
34
- */
35
- private readonly reconnectionGracePeriodMs;
36
- /**
37
- * Create a new ClientManager for managing ComfyUI client connections.
38
- *
39
- * @param strategy - Failover strategy for handling client failures
40
- * @param opts - Configuration options
41
- * @param opts.healthCheckIntervalMs - Interval (ms) for health check pings to keep connections alive.
42
- * Set to 0 to disable. Default: 30000 (30 seconds).
43
- */
44
- constructor(strategy: FailoverStrategy, opts?: {
45
- /**
46
- * Interval in milliseconds for health check pings.
47
- * Health checks keep idle connections alive by periodically polling client status.
48
- * @default 30000 (30 seconds)
49
- */
50
- healthCheckIntervalMs?: number;
51
- });
52
- private emitBlocked;
53
- private emitUnblocked;
54
- initialize(clients: ComfyApi[]): Promise<void>;
55
- addClient(client: ComfyApi): Promise<void>;
56
- list(): ManagedClient[];
57
- getClient(clientId: string): ManagedClient | undefined;
58
- /**
59
- * Checks if a client is truly available for work.
60
- * A client must be online, not busy, AND past the reconnection grace period.
61
- */
62
- isClientStable(client: ManagedClient): boolean;
63
- canClientRunJob(client: ManagedClient, job: JobRecord): boolean;
64
- claim(job: JobRecord, specificClientId?: string): ClientLease | null;
65
- recordFailure(clientId: string, job: JobRecord, error: unknown): void;
66
- /**
67
- * Start periodic health check to keep connections alive and detect issues early.
68
- * Pings idle clients by polling their queue status.
69
- */
70
- private startHealthCheck;
71
- /**
72
- * Perform health check on all clients.
73
- * Polls queue status to keep WebSocket alive and detect connection issues.
74
- * IMPORTANT: Pings ALL online clients (including busy ones) to prevent WebSocket timeout during heavy load.
75
- */
76
- private performHealthCheck;
77
- /**
78
- * Stop health check interval (called during shutdown).
79
- */
80
- stopHealthCheck(): void;
81
- /**
82
- * Cleanup resources when destroying the manager.
83
- */
84
- destroy(): void;
85
- }
86
- export {};
1
+ import type { ComfyApi } from "../../client.js";
2
+ import { TypedEventTarget } from "../../typed-event-target.js";
3
+ import type { JobRecord } from "../types/job.js";
4
+ import type { FailoverStrategy } from "../failover/Strategy.js";
5
+ import type { WorkflowPoolEventMap } from "../types/events.js";
6
+ export interface ManagedClient {
7
+ client: ComfyApi;
8
+ id: string;
9
+ online: boolean;
10
+ busy: boolean;
11
+ lastError?: unknown;
12
+ lastSeenAt: number;
13
+ supportedWorkflows: Set<string>;
14
+ lastDisconnectedAt?: number;
15
+ reconnectionStableAt?: number;
16
+ }
17
+ interface ClientLease {
18
+ client: ComfyApi;
19
+ clientId: string;
20
+ release: (opts?: {
21
+ success?: boolean;
22
+ }) => void;
23
+ }
24
+ export declare class ClientManager extends TypedEventTarget<WorkflowPoolEventMap> {
25
+ private clients;
26
+ private strategy;
27
+ private healthCheckInterval;
28
+ private readonly healthCheckIntervalMs;
29
+ private readonly debugLogs;
30
+ /**
31
+ * Grace period after reconnection before client is considered stable (default: 10 seconds).
32
+ * ComfyUI sometimes quickly disconnects/reconnects after job execution.
33
+ * During this grace period, the client won't be used for new jobs.
34
+ */
35
+ private readonly reconnectionGracePeriodMs;
36
+ /**
37
+ * Create a new ClientManager for managing ComfyUI client connections.
38
+ *
39
+ * @param strategy - Failover strategy for handling client failures
40
+ * @param opts - Configuration options
41
+ * @param opts.healthCheckIntervalMs - Interval (ms) for health check pings to keep connections alive.
42
+ * Set to 0 to disable. Default: 30000 (30 seconds).
43
+ */
44
+ constructor(strategy: FailoverStrategy, opts?: {
45
+ /**
46
+ * Interval in milliseconds for health check pings.
47
+ * Health checks keep idle connections alive by periodically polling client status.
48
+ * @default 30000 (30 seconds)
49
+ */
50
+ healthCheckIntervalMs?: number;
51
+ });
52
+ private emitBlocked;
53
+ private emitUnblocked;
54
+ initialize(clients: ComfyApi[]): Promise<void>;
55
+ addClient(client: ComfyApi): Promise<void>;
56
+ list(): ManagedClient[];
57
+ getClient(clientId: string): ManagedClient | undefined;
58
+ /**
59
+ * Checks if a client is truly available for work.
60
+ * A client must be online, not busy, AND past the reconnection grace period.
61
+ */
62
+ isClientStable(client: ManagedClient): boolean;
63
+ canClientRunJob(client: ManagedClient, job: JobRecord): boolean;
64
+ claim(job: JobRecord, specificClientId?: string): ClientLease | null;
65
+ recordFailure(clientId: string, job: JobRecord, error: unknown): void;
66
+ /**
67
+ * Start periodic health check to keep connections alive and detect issues early.
68
+ * Pings idle clients by polling their queue status.
69
+ */
70
+ private startHealthCheck;
71
+ /**
72
+ * Perform health check on all clients.
73
+ * Polls queue status to keep WebSocket alive and detect connection issues.
74
+ * IMPORTANT: Pings ALL online clients (including busy ones) to prevent WebSocket timeout during heavy load.
75
+ */
76
+ private performHealthCheck;
77
+ /**
78
+ * Stop health check interval (called during shutdown).
79
+ */
80
+ stopHealthCheck(): void;
81
+ /**
82
+ * Cleanup resources when destroying the manager.
83
+ */
84
+ destroy(): void;
85
+ }
86
+ export {};
87
87
  //# sourceMappingURL=ClientManager.d.ts.map
@@ -1,10 +1,10 @@
1
- export { WorkflowPool } from "./WorkflowPool.js";
2
- export type { WorkflowPoolOpts } from "./WorkflowPool.js";
3
- export type { WorkflowPoolEventMap } from "./types/events.js";
4
- export type { JobRecord, JobStatus, WorkflowJobOptions } from "./types/job.js";
5
- export type { QueueAdapter, QueueReservation, QueueStats } from "./queue/QueueAdapter.js";
6
- export { MemoryQueueAdapter } from "./queue/adapters/memory.js";
7
- export type { FailoverStrategy } from "./failover/Strategy.js";
8
- export { SmartFailoverStrategy } from "./failover/SmartFailoverStrategy.js";
9
- export type { JobProfileStats, NodeExecutionProfile } from "./profiling/JobProfiler.js";
1
+ export { WorkflowPool } from "./WorkflowPool.js";
2
+ export type { WorkflowPoolOpts } from "./WorkflowPool.js";
3
+ export type { WorkflowPoolEventMap } from "./types/events.js";
4
+ export type { JobRecord, JobStatus, WorkflowJobOptions } from "./types/job.js";
5
+ export type { QueueAdapter, QueueReservation, QueueStats } from "./queue/QueueAdapter.js";
6
+ export { MemoryQueueAdapter } from "./queue/adapters/memory.js";
7
+ export type { FailoverStrategy } from "./failover/Strategy.js";
8
+ export { SmartFailoverStrategy } from "./failover/SmartFailoverStrategy.js";
9
+ export type { JobProfileStats, NodeExecutionProfile } from "./profiling/JobProfiler.js";
10
10
  //# sourceMappingURL=index.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "comfyui-node",
3
- "version": "1.6.6",
3
+ "version": "1.6.7",
4
4
  "description": "ComfyUI Node.js Client",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -74,4 +74,4 @@
74
74
  "typescript": "5.9.3",
75
75
  "type-coverage": "^2.29.7"
76
76
  }
77
- }
77
+ }