flowscale 1.2.0 → 1.3.1
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/CHANGELOG.md +2 -0
- package/CLAUDE.md +2 -7
- package/Makefile +1 -10
- package/README.md +42 -127
- package/dist/index.d.ts +17 -27
- package/dist/index.js +517 -189
- package/dist/types.d.ts +22 -18
- package/examples/backend-proxy-example.js +1 -12
- package/package.json +1 -1
- package/examples/node-websocket-example.js +0 -173
- package/examples/websocket-example.html +0 -157
package/CHANGELOG.md
CHANGED
|
@@ -9,10 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
9
9
|
|
|
10
10
|
### ✨ Added
|
|
11
11
|
- `executeWorkflowAsync` now supports an options object with `onIntermediateResponse` callback to emit intermediate polling updates.
|
|
12
|
+
- Added `subscribeRunEvents(runId, options)` to consume run events via SSE (`/api/v1/runs/{run_id}/events`).
|
|
12
13
|
|
|
13
14
|
### 🔄 Changed
|
|
14
15
|
- `executeWorkflowAsync` still accepts the legacy boolean as the 6th parameter for backward compatibility.
|
|
15
16
|
- `GetOutputResponse` and `RunDetail` types now include optional progress-related fields returned by the API.
|
|
17
|
+
- Removed WebSocket APIs from the JavaScript SDK (`connectWebSocket`, `disconnectWebSocket`, `sendWebSocketMessage`, `isWebSocketConnected`) and removed related examples.
|
|
16
18
|
|
|
17
19
|
## [1.1.0] - 2025-01-29
|
|
18
20
|
|
package/CLAUDE.md
CHANGED
|
@@ -18,13 +18,11 @@ This is a TypeScript SDK for interacting with the Flowscale ComfyUI API. The cod
|
|
|
18
18
|
- **FlowscaleAPI Class** (`src/index.ts`): The main SDK class that provides all API methods
|
|
19
19
|
- Uses Axios for HTTP requests with built-in retry logic and timeout handling
|
|
20
20
|
- Supports both Node.js and browser environments with security warnings for browser usage
|
|
21
|
-
- Includes WebSocket support for real-time communication (browser only)
|
|
22
21
|
- Has configurable logging with different levels (debug, info, warn, error)
|
|
23
22
|
|
|
24
23
|
- **Type Definitions** (`src/types.ts`): Comprehensive TypeScript interfaces for:
|
|
25
24
|
- API responses (HealthCheckResponse, WorkflowResponse, etc.)
|
|
26
25
|
- Configuration options (FlowscaleConfig)
|
|
27
|
-
- WebSocket-related types (WebSocketOptions, WebSocketMessage)
|
|
28
26
|
|
|
29
27
|
### Key Features
|
|
30
28
|
|
|
@@ -33,8 +31,7 @@ This is a TypeScript SDK for interacting with the Flowscale ComfyUI API. The cod
|
|
|
33
31
|
3. **Input Validation**: Comprehensive validation for all required parameters with helpful error messages
|
|
34
32
|
4. **File Upload Support**: Handles FormData for file uploads in workflow execution
|
|
35
33
|
5. **Async Workflow Execution**: `executeWorkflowAsync` method polls for all outputs and waits for completion automatically
|
|
36
|
-
6. **
|
|
37
|
-
7. **Error Handling**: Consistent error handling with retry logic for timeouts and 504 errors
|
|
34
|
+
6. **Error Handling**: Consistent error handling with retry logic for timeouts and 504 errors
|
|
38
35
|
|
|
39
36
|
### API Methods Structure
|
|
40
37
|
|
|
@@ -52,7 +49,6 @@ The SDK requires:
|
|
|
52
49
|
- Optional: timeout, retry settings
|
|
53
50
|
- Optional: `proxyMode` - Enable secure frontend usage without exposing API key
|
|
54
51
|
- Optional: `customHeaders` - For JWT tokens, session cookies, etc.
|
|
55
|
-
- Optional: `WebSocketImpl` - For Node.js environments, pass the 'ws' WebSocket constructor to enable WebSocket functionality
|
|
56
52
|
|
|
57
53
|
### Build Configuration
|
|
58
54
|
|
|
@@ -64,10 +60,9 @@ The SDK requires:
|
|
|
64
60
|
## Important Notes
|
|
65
61
|
|
|
66
62
|
- No test framework is currently configured
|
|
67
|
-
- WebSocket functionality works in both browser and Node.js environments (Node.js requires passing `WebSocketImpl: require('ws')`)
|
|
68
63
|
- **Security**: Supports both direct API key usage and secure proxy mode for frontend applications
|
|
69
64
|
- **Proxy Mode**: Enables secure frontend usage by routing requests through a backend proxy that holds the API key
|
|
70
65
|
- All file uploads are handled through FormData with support for File/Blob objects
|
|
71
66
|
- The SDK has built-in retry logic for network timeouts and gateway errors
|
|
72
67
|
- Comprehensive input validation prevents common configuration errors
|
|
73
|
-
- Dynamic header management supports JWT token refresh and session management
|
|
68
|
+
- Dynamic header management supports JWT token refresh and session management
|
package/Makefile
CHANGED
|
@@ -24,13 +24,6 @@ ifndef VERSION
|
|
|
24
24
|
endif
|
|
25
25
|
npm deprecate flowscale@$(VERSION) "This version is deprecated. Please upgrade to a newer version."
|
|
26
26
|
|
|
27
|
-
# Run the WebSocket examples
|
|
28
|
-
run-browser-example:
|
|
29
|
-
@echo "Open examples/websocket-example.html in your browser"
|
|
30
|
-
|
|
31
|
-
run-node-example:
|
|
32
|
-
node examples/node-websocket-example.js
|
|
33
|
-
|
|
34
27
|
# Complete release process
|
|
35
28
|
release: build version publish
|
|
36
29
|
|
|
@@ -47,6 +40,4 @@ help:
|
|
|
47
40
|
@echo " make release - Complete release process (build, version, publish)"
|
|
48
41
|
@echo " make release-beta - Complete beta release process (build, version, publish-beta)"
|
|
49
42
|
@echo " make deprecate VERSION=x.x.x - Deprecate a specific version"
|
|
50
|
-
@echo " make
|
|
51
|
-
@echo " make run-node-example - Run Node.js WebSocket example"
|
|
52
|
-
@echo " make help - Show this help message"
|
|
43
|
+
@echo " make help - Show this help message"
|
package/README.md
CHANGED
|
@@ -501,156 +501,71 @@ console.log('All Runs:', allRuns);
|
|
|
501
501
|
|
|
502
502
|
---
|
|
503
503
|
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
### Environment Configuration
|
|
507
|
-
- Always store sensitive information such as API keys in environment variables.
|
|
508
|
-
- Use `.env` files and libraries like `dotenv` for easy environment management.
|
|
509
|
-
|
|
510
|
-
### Error Handling
|
|
511
|
-
- Wrap API calls in try-catch blocks to handle errors gracefully.
|
|
512
|
-
- Log errors for debugging and improve resilience.
|
|
513
|
-
|
|
514
|
-
### Testing and Debugging
|
|
515
|
-
- Test workflows in a development environment before deploying to production.
|
|
516
|
-
- Validate inputs to ensure they match the workflow requirements.
|
|
517
|
-
|
|
518
|
-
---
|
|
519
|
-
|
|
520
|
-
## WebSocket API
|
|
521
|
-
|
|
522
|
-
The Flowscale SDK provides WebSocket functionality to enable real-time communication with the Flowscale API. This is particularly useful for receiving updates about workflow execution status and other events in real-time.
|
|
523
|
-
|
|
524
|
-
### 1. `connectWebSocket(options)`
|
|
504
|
+
### 10. `subscribeRunEvents(runId, options?)`
|
|
525
505
|
|
|
526
506
|
**Description:**
|
|
527
|
-
|
|
507
|
+
Subscribe to run-level events over SSE using the new `/api/v1/runs/{run_id}/events` endpoint.
|
|
528
508
|
|
|
529
509
|
**Parameters:**
|
|
530
|
-
- `
|
|
531
|
-
|
|
532
|
-
- `
|
|
533
|
-
- `
|
|
534
|
-
- `
|
|
535
|
-
- `
|
|
536
|
-
- `
|
|
537
|
-
- `
|
|
510
|
+
- `runId` *(string)*: The run ID to stream events for.
|
|
511
|
+
- `options` *(object, optional)*:
|
|
512
|
+
- `fromSeq` *(number, optional)*: Replay from this sequence number.
|
|
513
|
+
- `signal` *(AbortSignal, optional)*: External abort signal.
|
|
514
|
+
- `onOpen` *(function, optional)*: Called when stream response opens.
|
|
515
|
+
- `onEvent` *(function, optional)*: Called for each parsed SSE event payload.
|
|
516
|
+
- `onError` *(function, optional)*: Called on stream errors.
|
|
517
|
+
- `onClose` *(function, optional)*: Called when stream closes.
|
|
518
|
+
|
|
519
|
+
**Returns:**
|
|
520
|
+
- `{ close, done }`
|
|
521
|
+
- `close()` aborts the SSE stream.
|
|
522
|
+
- `done` is a promise that resolves when stream ends.
|
|
538
523
|
|
|
539
524
|
**Usage:**
|
|
540
525
|
```javascript
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
console.log('
|
|
526
|
+
const stream = flowscale.subscribeRunEvents(runId, {
|
|
527
|
+
fromSeq: 0,
|
|
528
|
+
onEvent: (event) => {
|
|
529
|
+
console.log('Run event:', event.id, event.data);
|
|
545
530
|
},
|
|
546
|
-
|
|
547
|
-
console.
|
|
548
|
-
// Handle different message types
|
|
549
|
-
if (message.type === 'run_status_update') {
|
|
550
|
-
console.log('Run status updated:', message.data);
|
|
551
|
-
}
|
|
531
|
+
onError: (error) => {
|
|
532
|
+
console.error('Run event stream error:', error);
|
|
552
533
|
},
|
|
553
|
-
onClose: (
|
|
554
|
-
console.log('
|
|
534
|
+
onClose: () => {
|
|
535
|
+
console.log('Run event stream closed');
|
|
555
536
|
},
|
|
556
|
-
onError: (error) => {
|
|
557
|
-
console.error('WebSocket error:', error);
|
|
558
|
-
}
|
|
559
537
|
});
|
|
560
538
|
|
|
561
|
-
//
|
|
562
|
-
|
|
563
|
-
```
|
|
564
|
-
|
|
565
|
-
### 2. `disconnectWebSocket()`
|
|
566
|
-
|
|
567
|
-
**Description:**
|
|
568
|
-
Closes the WebSocket connection if it is open.
|
|
539
|
+
// Optional: stop manually
|
|
540
|
+
// stream.close();
|
|
569
541
|
|
|
570
|
-
|
|
571
|
-
```javascript
|
|
572
|
-
flowscale.disconnectWebSocket();
|
|
573
|
-
console.log('WebSocket disconnected');
|
|
542
|
+
await stream.done;
|
|
574
543
|
```
|
|
575
544
|
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
**Description:**
|
|
579
|
-
Sends a message through the WebSocket connection.
|
|
580
|
-
|
|
581
|
-
**Parameters:**
|
|
582
|
-
- `message` *(any)*: The message to send. Objects will be automatically stringified.
|
|
583
|
-
|
|
584
|
-
**Returns:**
|
|
585
|
-
- *(boolean)*: `true` if the message was sent successfully, `false` otherwise.
|
|
586
|
-
|
|
587
|
-
**Usage:**
|
|
545
|
+
**Node.js < 18 note:** pass a custom `fetchImpl` in SDK config for SSE support.
|
|
588
546
|
```javascript
|
|
589
|
-
const
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
runId: '808f34d0-ef97-4b78-a00f-1268077ea6db'
|
|
594
|
-
}
|
|
547
|
+
const flowscale = new FlowscaleAPI({
|
|
548
|
+
apiKey,
|
|
549
|
+
baseUrl,
|
|
550
|
+
fetchImpl: fetch // e.g. from undici/node-fetch polyfill
|
|
595
551
|
});
|
|
596
|
-
|
|
597
|
-
if (success) {
|
|
598
|
-
console.log('Message sent successfully');
|
|
599
|
-
} else {
|
|
600
|
-
console.error('Failed to send message');
|
|
601
|
-
}
|
|
602
|
-
```
|
|
603
|
-
|
|
604
|
-
### 4. `isWebSocketConnected()`
|
|
605
|
-
|
|
606
|
-
**Description:**
|
|
607
|
-
Checks if the WebSocket connection is currently open.
|
|
608
|
-
|
|
609
|
-
**Returns:**
|
|
610
|
-
- *(boolean)*: `true` if the WebSocket is connected, `false` otherwise.
|
|
611
|
-
|
|
612
|
-
**Usage:**
|
|
613
|
-
```javascript
|
|
614
|
-
if (flowscale.isWebSocketConnected()) {
|
|
615
|
-
console.log('WebSocket is connected');
|
|
616
|
-
} else {
|
|
617
|
-
console.log('WebSocket is not connected');
|
|
618
|
-
}
|
|
619
552
|
```
|
|
620
553
|
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
The SDK includes example implementations for both browser and Node.js environments:
|
|
624
|
-
|
|
625
|
-
#### Browser Example
|
|
626
|
-
See `examples/websocket-example.html` for a complete browser example with a user interface.
|
|
627
|
-
|
|
628
|
-
#### Node.js Example
|
|
629
|
-
Node.js requires a custom WebSocket implementation since the WebSocket API is not built-in. See `examples/node-websocket-example.js` for an example using the 'ws' library.
|
|
554
|
+
---
|
|
630
555
|
|
|
631
|
-
|
|
632
|
-
```bash
|
|
633
|
-
npm install ws
|
|
634
|
-
```
|
|
556
|
+
## Best Practices
|
|
635
557
|
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
apiKey: 'your-api-key',
|
|
640
|
-
baseUrl: 'https://your-api-url.pod.flowscale.ai',
|
|
641
|
-
WebSocketImpl: WebSocket // Pass the WebSocket implementation for Node.js
|
|
642
|
-
});
|
|
558
|
+
### Environment Configuration
|
|
559
|
+
- Always store sensitive information such as API keys in environment variables.
|
|
560
|
+
- Use `.env` files and libraries like `dotenv` for easy environment management.
|
|
643
561
|
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
onMessage: (message) => console.log('Message:', message),
|
|
648
|
-
onClose: (event) => console.log('Closed:', event),
|
|
649
|
-
onError: (error) => console.error('Error:', error)
|
|
650
|
-
});
|
|
651
|
-
```
|
|
562
|
+
### Error Handling
|
|
563
|
+
- Wrap API calls in try-catch blocks to handle errors gracefully.
|
|
564
|
+
- Log errors for debugging and improve resilience.
|
|
652
565
|
|
|
653
|
-
|
|
566
|
+
### Testing and Debugging
|
|
567
|
+
- Test workflows in a development environment before deploying to production.
|
|
568
|
+
- Validate inputs to ensure they match the workflow requirements.
|
|
654
569
|
|
|
655
570
|
## 🔒 Advanced Security Features
|
|
656
571
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HealthCheckResponse, QueueResponse, ExecuteWorkflowResponse, GetOutputResponse, GetAllOutputsResponse, LegacyGetOutputResponse, RunDetailResponse, RunListResponse, CancelRunResponse, ExecuteWorkflowAsyncOptions, FlowscaleConfig, WorkflowResponse
|
|
1
|
+
import { HealthCheckResponse, QueueResponse, ExecuteWorkflowResponse, GetOutputResponse, GetAllOutputsResponse, LegacyGetOutputResponse, RunDetailResponse, RunListResponse, CancelRunResponse, ExecuteWorkflowAsyncOptions, RunEventsSSEConnection, RunEventsSSEOptions, FlowscaleConfig, WorkflowResponse } from './types';
|
|
2
2
|
export declare class FlowscaleAPI {
|
|
3
3
|
private apiKey;
|
|
4
4
|
private baseUrl;
|
|
@@ -6,13 +6,9 @@ export declare class FlowscaleAPI {
|
|
|
6
6
|
private isNode;
|
|
7
7
|
private maxRetries;
|
|
8
8
|
private retryDelay;
|
|
9
|
-
private ws;
|
|
10
|
-
private wsConnected;
|
|
11
|
-
private reconnectAttempts;
|
|
12
|
-
private reconnectTimeout;
|
|
13
|
-
private WebSocketImpl;
|
|
14
9
|
private proxyMode;
|
|
15
10
|
private customHeaders;
|
|
11
|
+
private fetchImpl;
|
|
16
12
|
constructor(config: FlowscaleConfig);
|
|
17
13
|
/**
|
|
18
14
|
* Checks the health status of all ComfyUI instances within the specified cluster.
|
|
@@ -68,10 +64,25 @@ export declare class FlowscaleAPI {
|
|
|
68
64
|
* @param groupId - The group ID to filter runs.
|
|
69
65
|
*/
|
|
70
66
|
getRuns(groupId?: string): Promise<RunListResponse>;
|
|
67
|
+
/**
|
|
68
|
+
* Subscribes to run events from the SSE endpoint.
|
|
69
|
+
* @param runId - The run ID to stream events for.
|
|
70
|
+
* @param options - SSE subscription options and callbacks.
|
|
71
|
+
* @returns Connection handle with `close()` and `done` promise.
|
|
72
|
+
*/
|
|
73
|
+
subscribeRunEvents(runId: string, options?: RunEventsSSEOptions): RunEventsSSEConnection;
|
|
71
74
|
private resolveExecuteWorkflowAsyncOptions;
|
|
72
75
|
private emitExecuteWorkflowAsyncIntermediateResponse;
|
|
73
76
|
private formatUnknownError;
|
|
74
77
|
private sleep;
|
|
78
|
+
private normalizeGetOutputResponse;
|
|
79
|
+
private resolveGlobalFetch;
|
|
80
|
+
private consumeRunEventsStream;
|
|
81
|
+
private safeReadResponseText;
|
|
82
|
+
private consumeRunEventsSnapshotResponse;
|
|
83
|
+
private consumeSSEReadableStream;
|
|
84
|
+
private parseSSEEventId;
|
|
85
|
+
private invokeRunEventsCallback;
|
|
75
86
|
/**
|
|
76
87
|
* Helper method to append data to FormData.
|
|
77
88
|
*/
|
|
@@ -92,22 +103,6 @@ export declare class FlowscaleAPI {
|
|
|
92
103
|
* Makes API request with retry capability for browser environments
|
|
93
104
|
*/
|
|
94
105
|
private makeRequest;
|
|
95
|
-
/**
|
|
96
|
-
* Connects to the WebSocket API endpoint and sets up event handlers.
|
|
97
|
-
* @param options - Configuration options for the WebSocket connection
|
|
98
|
-
* @returns A function that can be called to disconnect the WebSocket
|
|
99
|
-
*/
|
|
100
|
-
connectWebSocket(options?: WebSocketOptions): () => void;
|
|
101
|
-
/**
|
|
102
|
-
* Disconnects the WebSocket connection if it exists.
|
|
103
|
-
*/
|
|
104
|
-
disconnectWebSocket(): void;
|
|
105
|
-
/**
|
|
106
|
-
* Sends a message through the WebSocket connection.
|
|
107
|
-
* @param message - The message to send
|
|
108
|
-
* @returns Whether the message was sent successfully
|
|
109
|
-
*/
|
|
110
|
-
sendWebSocketMessage(message: any): boolean;
|
|
111
106
|
/**
|
|
112
107
|
* Updates custom headers for authentication (useful for refreshing JWT tokens)
|
|
113
108
|
* @param headers - Object containing header key-value pairs
|
|
@@ -126,10 +121,5 @@ export declare class FlowscaleAPI {
|
|
|
126
121
|
getCustomHeaders(): {
|
|
127
122
|
[key: string]: string;
|
|
128
123
|
};
|
|
129
|
-
/**
|
|
130
|
-
* Checks if the WebSocket connection is currently open.
|
|
131
|
-
* @returns True if the WebSocket is connected, false otherwise
|
|
132
|
-
*/
|
|
133
|
-
isWebSocketConnected(): boolean;
|
|
134
124
|
}
|
|
135
125
|
export * from './types';
|