@happyvertical/comfyui 0.74.8
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/AGENT.md +33 -0
- package/LICENSE +7 -0
- package/README.md +283 -0
- package/dist/index.d.ts +506 -0
- package/dist/index.js +478 -0
- package/dist/index.js.map +1 -0
- package/metadata.json +29 -0
- package/package.json +54 -0
package/AGENT.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# @happyvertical/comfyui
|
|
2
|
+
|
|
3
|
+
<!-- BEGIN AGENT:GENERATED -->
|
|
4
|
+
## Purpose
|
|
5
|
+
ComfyUI API client for workflow orchestration and video generation
|
|
6
|
+
|
|
7
|
+
## Package Map
|
|
8
|
+
- Package: `@happyvertical/comfyui`
|
|
9
|
+
- Hierarchy path: `@happyvertical/sdk > packages > comfyui`
|
|
10
|
+
- Workspace position: `6 of 30` local packages
|
|
11
|
+
- Internal dependencies: `@happyvertical/logger`, `@happyvertical/utils`
|
|
12
|
+
- Internal dependents: none
|
|
13
|
+
- Knowledge graph files: `AGENT.md`, `metadata.json`, `ecosystem-manifest.json`
|
|
14
|
+
|
|
15
|
+
## Build & Test
|
|
16
|
+
```bash
|
|
17
|
+
pnpm --filter @happyvertical/comfyui build
|
|
18
|
+
pnpm --filter @happyvertical/comfyui test
|
|
19
|
+
pnpm --filter @happyvertical/comfyui clean
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Agent Correction Loops
|
|
23
|
+
- If module resolution or export errors mention a workspace dependency, build the dependency first (`pnpm --filter @happyvertical/logger build`, `pnpm --filter @happyvertical/utils build`) and then rerun `pnpm --filter @happyvertical/comfyui build`.
|
|
24
|
+
- If tests or exports fail after API, type, or bundle changes, run `pnpm --filter @happyvertical/comfyui clean` followed by `pnpm --filter @happyvertical/comfyui build` and `pnpm --filter @happyvertical/comfyui test`.
|
|
25
|
+
- If failures span multiple packages or Turborepo ordering looks wrong, run `pnpm build` and `pnpm typecheck` from the repo root before retrying package-scoped commands.
|
|
26
|
+
|
|
27
|
+
## Ecosystem Relationships
|
|
28
|
+
- Provides: ComfyUI API client for workflow orchestration and video generation
|
|
29
|
+
- Implements: none
|
|
30
|
+
- Requires: @happyvertical/logger, @happyvertical/utils
|
|
31
|
+
- Stability: stable (Primary package surface is described as implemented and production-oriented.)
|
|
32
|
+
<!-- END AGENT:GENERATED -->
|
|
33
|
+
|
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright <2025> <Happy Vertical Corporation>
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: comfyui
|
|
3
|
+
title: "@happyvertical/comfyui: ComfyUI API Client"
|
|
4
|
+
sidebar_label: "@happyvertical/comfyui"
|
|
5
|
+
sidebar_position: 10
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# @happyvertical/comfyui
|
|
9
|
+
|
|
10
|
+
[](https://opensource.org/licenses/MIT)
|
|
11
|
+
|
|
12
|
+
A WebSocket-based client for ComfyUI workflow orchestration and video generation in the HAVE SDK.
|
|
13
|
+
|
|
14
|
+
## Overview
|
|
15
|
+
|
|
16
|
+
The `@happyvertical/comfyui` package provides a TypeScript client for interacting with ComfyUI servers via WebSocket. It supports workflow execution, progress monitoring, and output downloading for AI-powered image and video generation pipelines.
|
|
17
|
+
|
|
18
|
+
## Features
|
|
19
|
+
|
|
20
|
+
- **WebSocket Connection**: Real-time communication with ComfyUI servers
|
|
21
|
+
- **Workflow Execution**: Queue and execute ComfyUI workflows
|
|
22
|
+
- **Progress Monitoring**: Track execution progress with detailed events
|
|
23
|
+
- **Parameter Injection**: Dynamically inject values into workflow nodes
|
|
24
|
+
- **Output Download**: Retrieve generated images and videos
|
|
25
|
+
- **Queue Management**: Monitor and manage the execution queue
|
|
26
|
+
- **System Stats**: Query server status and capabilities
|
|
27
|
+
- **File Upload**: Upload images and other files for workflow inputs
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
# Install with bun (recommended)
|
|
33
|
+
bun add @happyvertical/comfyui
|
|
34
|
+
|
|
35
|
+
# Or with npm
|
|
36
|
+
npm install @happyvertical/comfyui
|
|
37
|
+
|
|
38
|
+
# Or with pnpm
|
|
39
|
+
pnpm add @happyvertical/comfyui
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Quick Start
|
|
43
|
+
|
|
44
|
+
### Basic Usage
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import { ComfyUIClient, injectWorkflowParams } from '@happyvertical/comfyui';
|
|
48
|
+
|
|
49
|
+
// Create client
|
|
50
|
+
const client = new ComfyUIClient({
|
|
51
|
+
url: 'http://localhost:8188',
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Connect to server
|
|
55
|
+
await client.connect();
|
|
56
|
+
|
|
57
|
+
// Load and modify workflow
|
|
58
|
+
const workflow = JSON.parse(fs.readFileSync('workflow.json', 'utf-8'));
|
|
59
|
+
const modifiedWorkflow = injectWorkflowParams(
|
|
60
|
+
workflow,
|
|
61
|
+
{
|
|
62
|
+
seedImage: '3',
|
|
63
|
+
prompt: '6',
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
seedImage: 'input/anchor.png',
|
|
67
|
+
prompt: 'professional news anchor speaking',
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
// Queue prompt and wait for completion
|
|
72
|
+
const result = await client.queuePrompt(modifiedWorkflow);
|
|
73
|
+
const history = await client.waitForCompletion(result.promptId);
|
|
74
|
+
|
|
75
|
+
// Download output
|
|
76
|
+
const output = history.outputs['SaveVideo'];
|
|
77
|
+
if (output?.videos?.[0]) {
|
|
78
|
+
const video = await client.downloadOutput(output.videos[0].filename);
|
|
79
|
+
fs.writeFileSync('output.mp4', video);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
await client.disconnect();
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Progress Tracking
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
const history = await client.waitForCompletion(promptId, {
|
|
89
|
+
onProgress: (event) => {
|
|
90
|
+
switch (event.type) {
|
|
91
|
+
case 'progress':
|
|
92
|
+
console.log(`Progress: ${event.value}/${event.max}`);
|
|
93
|
+
break;
|
|
94
|
+
case 'executing':
|
|
95
|
+
console.log(`Executing node: ${event.node}`);
|
|
96
|
+
break;
|
|
97
|
+
case 'execution_cached':
|
|
98
|
+
console.log(`Cached nodes: ${event.nodes.join(', ')}`);
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### File Upload
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
// Upload image for workflow input
|
|
109
|
+
const imageBuffer = fs.readFileSync('input.png');
|
|
110
|
+
const uploadResult = await client.uploadImage(imageBuffer, 'input.png');
|
|
111
|
+
|
|
112
|
+
console.log(`Uploaded: ${uploadResult.name}`);
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### System Status
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
// Get system stats
|
|
119
|
+
const stats = await client.getSystemStats();
|
|
120
|
+
console.log(`Queue: ${stats.queue.running}/${stats.queue.pending}`);
|
|
121
|
+
|
|
122
|
+
// Get queue status
|
|
123
|
+
const queue = await client.getQueueStatus();
|
|
124
|
+
console.log(`Running: ${queue.running.length}, Pending: ${queue.pending.length}`);
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## API Reference
|
|
128
|
+
|
|
129
|
+
### ComfyUIClient
|
|
130
|
+
|
|
131
|
+
The main client class for interacting with ComfyUI servers.
|
|
132
|
+
|
|
133
|
+
#### Constructor
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
new ComfyUIClient(options: ComfyUIClientOptions)
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
| Option | Type | Default | Description |
|
|
140
|
+
|--------|------|---------|-------------|
|
|
141
|
+
| `url` | `string` | - | ComfyUI server URL (e.g., `http://localhost:8188`) |
|
|
142
|
+
| `clientId` | `string` | auto-generated | Unique client identifier |
|
|
143
|
+
| `timeout` | `number` | `600000` | Request timeout in milliseconds |
|
|
144
|
+
|
|
145
|
+
#### Methods
|
|
146
|
+
|
|
147
|
+
| Method | Description |
|
|
148
|
+
|--------|-------------|
|
|
149
|
+
| `connect()` | Establish WebSocket connection |
|
|
150
|
+
| `disconnect()` | Close WebSocket connection |
|
|
151
|
+
| `queuePrompt(workflow)` | Queue a workflow for execution |
|
|
152
|
+
| `waitForCompletion(promptId, options?)` | Wait for prompt completion with progress tracking |
|
|
153
|
+
| `getHistory(promptId)` | Get execution history for a prompt |
|
|
154
|
+
| `getQueueStatus()` | Get current queue status |
|
|
155
|
+
| `getSystemStats()` | Get server system statistics |
|
|
156
|
+
| `uploadImage(buffer, filename, options?)` | Upload an image file |
|
|
157
|
+
| `downloadOutput(filename, subfolder?, type?)` | Download a generated output file |
|
|
158
|
+
| `interruptExecution()` | Interrupt the current execution |
|
|
159
|
+
| `clearQueue()` | Clear all pending queue items |
|
|
160
|
+
|
|
161
|
+
### injectWorkflowParams
|
|
162
|
+
|
|
163
|
+
Utility function to inject dynamic values into workflow nodes.
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
function injectWorkflowParams(
|
|
167
|
+
workflow: ComfyWorkflow,
|
|
168
|
+
nodeMapping: NodeMapping,
|
|
169
|
+
values: Record<string, unknown>
|
|
170
|
+
): ComfyWorkflow
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
#### Parameters
|
|
174
|
+
|
|
175
|
+
- `workflow` - The ComfyUI workflow JSON
|
|
176
|
+
- `nodeMapping` - Maps parameter names to node IDs (e.g., `{ seedImage: '3' }`)
|
|
177
|
+
- `values` - Values to inject (e.g., `{ seedImage: 'path/to/image.png' }`)
|
|
178
|
+
|
|
179
|
+
## Types
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
interface ComfyUIClientOptions {
|
|
183
|
+
url: string;
|
|
184
|
+
clientId?: string;
|
|
185
|
+
timeout?: number;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
interface PromptResult {
|
|
189
|
+
promptId: string;
|
|
190
|
+
number: number;
|
|
191
|
+
nodeErrors?: Record<string, unknown>;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
interface HistoryEntry {
|
|
195
|
+
promptId: string;
|
|
196
|
+
outputs: Record<string, NodeOutput>;
|
|
197
|
+
status: { completed: boolean; messages?: unknown[] };
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
interface ProgressEvent {
|
|
201
|
+
type: 'progress' | 'executing' | 'executed' | 'execution_cached' | 'execution_error';
|
|
202
|
+
promptId?: string;
|
|
203
|
+
node?: string;
|
|
204
|
+
value?: number;
|
|
205
|
+
max?: number;
|
|
206
|
+
nodes?: string[];
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
## Use Cases
|
|
211
|
+
|
|
212
|
+
### AI Video Generation Pipeline
|
|
213
|
+
|
|
214
|
+
```typescript
|
|
215
|
+
import { ComfyUIClient, injectWorkflowParams } from '@happyvertical/comfyui';
|
|
216
|
+
|
|
217
|
+
async function generateVideo(seedImage: string, audioFile: string) {
|
|
218
|
+
const client = new ComfyUIClient({ url: 'http://localhost:8188' });
|
|
219
|
+
await client.connect();
|
|
220
|
+
|
|
221
|
+
try {
|
|
222
|
+
// Upload inputs
|
|
223
|
+
await client.uploadImage(fs.readFileSync(seedImage), 'seed.png');
|
|
224
|
+
await client.uploadImage(fs.readFileSync(audioFile), 'audio.wav');
|
|
225
|
+
|
|
226
|
+
// Load lip-sync workflow
|
|
227
|
+
const workflow = JSON.parse(fs.readFileSync('lipsync-workflow.json', 'utf-8'));
|
|
228
|
+
const modified = injectWorkflowParams(workflow, {
|
|
229
|
+
seedImage: '3',
|
|
230
|
+
audioFile: '5',
|
|
231
|
+
}, {
|
|
232
|
+
seedImage: 'input/seed.png',
|
|
233
|
+
audioFile: 'input/audio.wav',
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
// Execute with progress
|
|
237
|
+
const result = await client.queuePrompt(modified);
|
|
238
|
+
const history = await client.waitForCompletion(result.promptId, {
|
|
239
|
+
onProgress: (e) => {
|
|
240
|
+
if (e.type === 'progress') {
|
|
241
|
+
console.log(`Rendering: ${Math.round((e.value! / e.max!) * 100)}%`);
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
// Download output
|
|
247
|
+
const output = history.outputs['SaveVideo'];
|
|
248
|
+
return await client.downloadOutput(output.videos[0].filename);
|
|
249
|
+
} finally {
|
|
250
|
+
await client.disconnect();
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### Batch Image Generation
|
|
256
|
+
|
|
257
|
+
```typescript
|
|
258
|
+
async function generateBatch(prompts: string[]) {
|
|
259
|
+
const client = new ComfyUIClient({ url: 'http://localhost:8188' });
|
|
260
|
+
await client.connect();
|
|
261
|
+
|
|
262
|
+
const results = [];
|
|
263
|
+
for (const prompt of prompts) {
|
|
264
|
+
const workflow = injectWorkflowParams(baseWorkflow, { prompt: '6' }, { prompt });
|
|
265
|
+
const result = await client.queuePrompt(workflow);
|
|
266
|
+
const history = await client.waitForCompletion(result.promptId);
|
|
267
|
+
results.push(history);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
await client.disconnect();
|
|
271
|
+
return results;
|
|
272
|
+
}
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
## Requirements
|
|
276
|
+
|
|
277
|
+
- ComfyUI server running and accessible
|
|
278
|
+
- Node.js 20+ or Bun
|
|
279
|
+
- WebSocket support in runtime
|
|
280
|
+
|
|
281
|
+
## License
|
|
282
|
+
|
|
283
|
+
This package is part of the HAVE SDK and is licensed under the MIT License - see the [LICENSE](../../LICENSE) file for details.
|