flowscale 1.0.17-beta.6 → 1.0.17-beta.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/README.md +41 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +103 -9
- package/dist/types.d.ts +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -421,6 +421,47 @@ console.log('All Runs:', allRuns);
|
|
|
421
421
|
- Always store sensitive information such as API keys in environment variables.
|
|
422
422
|
- Use `.env` files and libraries like `dotenv` for easy environment management.
|
|
423
423
|
|
|
424
|
+
### Logging Configuration
|
|
425
|
+
The SDK includes configurable logging to help with debugging and monitoring. By default, logging is enabled with the 'info' level.
|
|
426
|
+
|
|
427
|
+
#### Configuration Options
|
|
428
|
+
```javascript
|
|
429
|
+
const flowscale = new FlowscaleAPI({
|
|
430
|
+
apiKey: 'your-api-key',
|
|
431
|
+
baseUrl: 'https://your-api-url.pod.flowscale.ai',
|
|
432
|
+
enableLogging: true, // Enable/disable logging (default: true)
|
|
433
|
+
logLevel: 'info' // Set log level: 'debug', 'info', 'warn', 'error' (default: 'info')
|
|
434
|
+
});
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
#### Dynamic Logging Control
|
|
438
|
+
You can also change logging settings after initialization:
|
|
439
|
+
|
|
440
|
+
```javascript
|
|
441
|
+
// Enable debug logging
|
|
442
|
+
flowscale.setLoggingConfig(true, 'debug');
|
|
443
|
+
|
|
444
|
+
// Disable logging completely
|
|
445
|
+
flowscale.setLoggingConfig(false);
|
|
446
|
+
|
|
447
|
+
// Check current logging configuration
|
|
448
|
+
const loggingConfig = flowscale.getLoggingConfig();
|
|
449
|
+
console.log(loggingConfig); // { enabled: true, level: 'debug' }
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
#### Log Levels
|
|
453
|
+
- **debug**: Most verbose, includes detailed operation information
|
|
454
|
+
- **info**: General information about operations (default)
|
|
455
|
+
- **warn**: Warning messages for potential issues
|
|
456
|
+
- **error**: Only error messages
|
|
457
|
+
|
|
458
|
+
#### Log Format
|
|
459
|
+
All logs are prefixed with timestamp and level:
|
|
460
|
+
```
|
|
461
|
+
[Flowscale INFO] 2025-06-03T10:30:45.123Z: WebSocket connection established
|
|
462
|
+
[Flowscale DEBUG] 2025-06-03T10:30:46.456Z: Polling workflow output: {...}
|
|
463
|
+
```
|
|
464
|
+
|
|
424
465
|
### Error Handling
|
|
425
466
|
- Wrap API calls in try-catch blocks to handle errors gracefully.
|
|
426
467
|
- Log errors for debugging and improve resilience.
|
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export declare class FlowscaleAPI {
|
|
|
9
9
|
private ws;
|
|
10
10
|
private wsConnected;
|
|
11
11
|
private reconnectAttempts;
|
|
12
|
+
private enableLogging;
|
|
13
|
+
private logLevel;
|
|
12
14
|
constructor(config: FlowscaleConfig);
|
|
13
15
|
/**
|
|
14
16
|
* Checks the health status of all ComfyUI instances within the specified cluster.
|
|
@@ -71,6 +73,14 @@ export declare class FlowscaleAPI {
|
|
|
71
73
|
* Error handling helper.
|
|
72
74
|
*/
|
|
73
75
|
private handleError;
|
|
76
|
+
/**
|
|
77
|
+
* Internal logging methods
|
|
78
|
+
*/
|
|
79
|
+
private log;
|
|
80
|
+
private logDebug;
|
|
81
|
+
private logInfo;
|
|
82
|
+
private logWarn;
|
|
83
|
+
private logError;
|
|
74
84
|
/**
|
|
75
85
|
* Makes API request with retry capability for browser environments
|
|
76
86
|
*/
|
|
@@ -96,4 +106,18 @@ export declare class FlowscaleAPI {
|
|
|
96
106
|
* @returns True if the WebSocket is connected, false otherwise
|
|
97
107
|
*/
|
|
98
108
|
isWebSocketConnected(): boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Configure logging settings dynamically
|
|
111
|
+
* @param enabled Whether to enable logging
|
|
112
|
+
* @param level Log level to use ('debug', 'info', 'warn', 'error')
|
|
113
|
+
*/
|
|
114
|
+
setLoggingConfig(enabled: boolean, level?: 'debug' | 'info' | 'warn' | 'error'): void;
|
|
115
|
+
/**
|
|
116
|
+
* Get current logging configuration
|
|
117
|
+
* @returns Object with current logging settings
|
|
118
|
+
*/
|
|
119
|
+
getLoggingConfig(): {
|
|
120
|
+
enabled: boolean;
|
|
121
|
+
level: "debug" | "info" | "warn" | "error";
|
|
122
|
+
};
|
|
99
123
|
}
|
package/dist/index.js
CHANGED
|
@@ -35,6 +35,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
39
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
40
|
+
if (ar || !(i in from)) {
|
|
41
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
42
|
+
ar[i] = from[i];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
46
|
+
};
|
|
38
47
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
48
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
49
|
};
|
|
@@ -62,6 +71,8 @@ var FlowscaleAPI = /** @class */ (function () {
|
|
|
62
71
|
this.baseUrl = config.baseUrl;
|
|
63
72
|
this.maxRetries = config.maxRetries || 3;
|
|
64
73
|
this.retryDelay = config.retryDelay || 1000;
|
|
74
|
+
this.enableLogging = config.enableLogging !== false; // Default to true for backward compatibility
|
|
75
|
+
this.logLevel = config.logLevel || 'info';
|
|
65
76
|
this.client = axios_1.default.create({
|
|
66
77
|
baseURL: this.baseUrl,
|
|
67
78
|
timeout: config.timeout || 6000000, // Default 6000s timeout instead of Axios default 0 (no timeout)
|
|
@@ -184,11 +195,13 @@ var FlowscaleAPI = /** @class */ (function () {
|
|
|
184
195
|
return [4 /*yield*/, this.getOutput(outputName)];
|
|
185
196
|
case 4:
|
|
186
197
|
output = _c.sent();
|
|
187
|
-
|
|
188
|
-
if (output) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
198
|
+
this.logDebug("Polling workflow output:", output);
|
|
199
|
+
if (output === null) {
|
|
200
|
+
this.logWarn("No output found for ".concat(outputName, ", retrying..."));
|
|
201
|
+
return [3 /*break*/, 2]; // No output yet, continue polling
|
|
202
|
+
}
|
|
203
|
+
if (output.status === 'success') {
|
|
204
|
+
return [2 /*return*/, output]; // Return the output if successful
|
|
192
205
|
}
|
|
193
206
|
return [3 /*break*/, 6];
|
|
194
207
|
case 5:
|
|
@@ -322,6 +335,66 @@ var FlowscaleAPI = /** @class */ (function () {
|
|
|
322
335
|
// Something else happened
|
|
323
336
|
throw new Error("Error: ".concat(error.message));
|
|
324
337
|
};
|
|
338
|
+
/**
|
|
339
|
+
* Internal logging methods
|
|
340
|
+
*/
|
|
341
|
+
FlowscaleAPI.prototype.log = function (level, message) {
|
|
342
|
+
var args = [];
|
|
343
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
|
344
|
+
args[_i - 2] = arguments[_i];
|
|
345
|
+
}
|
|
346
|
+
if (!this.enableLogging)
|
|
347
|
+
return;
|
|
348
|
+
var levels = ['debug', 'info', 'warn', 'error'];
|
|
349
|
+
var currentLevelIndex = levels.indexOf(this.logLevel);
|
|
350
|
+
var messageLevelIndex = levels.indexOf(level);
|
|
351
|
+
if (messageLevelIndex >= currentLevelIndex) {
|
|
352
|
+
var timestamp = new Date().toISOString();
|
|
353
|
+
var prefix = "[Flowscale ".concat(level.toUpperCase(), "] ").concat(timestamp, ":");
|
|
354
|
+
switch (level) {
|
|
355
|
+
case 'debug':
|
|
356
|
+
console.log.apply(console, __spreadArray([prefix, message], args, false));
|
|
357
|
+
break;
|
|
358
|
+
case 'info':
|
|
359
|
+
console.info.apply(console, __spreadArray([prefix, message], args, false));
|
|
360
|
+
break;
|
|
361
|
+
case 'warn':
|
|
362
|
+
console.warn.apply(console, __spreadArray([prefix, message], args, false));
|
|
363
|
+
break;
|
|
364
|
+
case 'error':
|
|
365
|
+
console.error.apply(console, __spreadArray([prefix, message], args, false));
|
|
366
|
+
break;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
FlowscaleAPI.prototype.logDebug = function (message) {
|
|
371
|
+
var args = [];
|
|
372
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
373
|
+
args[_i - 1] = arguments[_i];
|
|
374
|
+
}
|
|
375
|
+
this.log.apply(this, __spreadArray(['debug', message], args, false));
|
|
376
|
+
};
|
|
377
|
+
FlowscaleAPI.prototype.logInfo = function (message) {
|
|
378
|
+
var args = [];
|
|
379
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
380
|
+
args[_i - 1] = arguments[_i];
|
|
381
|
+
}
|
|
382
|
+
this.log.apply(this, __spreadArray(['info', message], args, false));
|
|
383
|
+
};
|
|
384
|
+
FlowscaleAPI.prototype.logWarn = function (message) {
|
|
385
|
+
var args = [];
|
|
386
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
387
|
+
args[_i - 1] = arguments[_i];
|
|
388
|
+
}
|
|
389
|
+
this.log.apply(this, __spreadArray(['warn', message], args, false));
|
|
390
|
+
};
|
|
391
|
+
FlowscaleAPI.prototype.logError = function (message) {
|
|
392
|
+
var args = [];
|
|
393
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
394
|
+
args[_i - 1] = arguments[_i];
|
|
395
|
+
}
|
|
396
|
+
this.log.apply(this, __spreadArray(['error', message], args, false));
|
|
397
|
+
};
|
|
325
398
|
/**
|
|
326
399
|
* Makes API request with retry capability for browser environments
|
|
327
400
|
*/
|
|
@@ -429,7 +502,7 @@ var FlowscaleAPI = /** @class */ (function () {
|
|
|
429
502
|
this.reconnectAttempts = 0;
|
|
430
503
|
// Set up event handlers
|
|
431
504
|
this.ws.onopen = function () {
|
|
432
|
-
|
|
505
|
+
_this.logInfo('WebSocket connection established');
|
|
433
506
|
_this.wsConnected = true;
|
|
434
507
|
_this.reconnectAttempts = 0;
|
|
435
508
|
if (options.onOpen)
|
|
@@ -442,18 +515,18 @@ var FlowscaleAPI = /** @class */ (function () {
|
|
|
442
515
|
options.onMessage(message);
|
|
443
516
|
}
|
|
444
517
|
catch (error) {
|
|
445
|
-
|
|
518
|
+
_this.logError('Failed to parse WebSocket message:', error);
|
|
446
519
|
if (options.onError)
|
|
447
520
|
options.onError(new ErrorEvent('error', { error: error }));
|
|
448
521
|
}
|
|
449
522
|
};
|
|
450
523
|
this.ws.onclose = function (event) {
|
|
451
|
-
|
|
524
|
+
_this.logInfo("WebSocket connection closed: ".concat(event.code, " ").concat(event.reason));
|
|
452
525
|
_this.wsConnected = false;
|
|
453
526
|
// Attempt to reconnect if enabled
|
|
454
527
|
if (reconnect && _this.reconnectAttempts < maxReconnectAttempts) {
|
|
455
528
|
_this.reconnectAttempts++;
|
|
456
|
-
|
|
529
|
+
_this.logInfo("Attempting to reconnect (".concat(_this.reconnectAttempts, "/").concat(maxReconnectAttempts, ")..."));
|
|
457
530
|
setTimeout(function () {
|
|
458
531
|
_this.connectWebSocket(options);
|
|
459
532
|
}, reconnectInterval);
|
|
@@ -506,6 +579,27 @@ var FlowscaleAPI = /** @class */ (function () {
|
|
|
506
579
|
FlowscaleAPI.prototype.isWebSocketConnected = function () {
|
|
507
580
|
return this.wsConnected && this.ws !== null && this.ws.readyState === WebSocket.OPEN;
|
|
508
581
|
};
|
|
582
|
+
/**
|
|
583
|
+
* Configure logging settings dynamically
|
|
584
|
+
* @param enabled Whether to enable logging
|
|
585
|
+
* @param level Log level to use ('debug', 'info', 'warn', 'error')
|
|
586
|
+
*/
|
|
587
|
+
FlowscaleAPI.prototype.setLoggingConfig = function (enabled, level) {
|
|
588
|
+
this.enableLogging = enabled;
|
|
589
|
+
if (level) {
|
|
590
|
+
this.logLevel = level;
|
|
591
|
+
}
|
|
592
|
+
};
|
|
593
|
+
/**
|
|
594
|
+
* Get current logging configuration
|
|
595
|
+
* @returns Object with current logging settings
|
|
596
|
+
*/
|
|
597
|
+
FlowscaleAPI.prototype.getLoggingConfig = function () {
|
|
598
|
+
return {
|
|
599
|
+
enabled: this.enableLogging,
|
|
600
|
+
level: this.logLevel
|
|
601
|
+
};
|
|
602
|
+
};
|
|
509
603
|
return FlowscaleAPI;
|
|
510
604
|
}());
|
|
511
605
|
exports.FlowscaleAPI = FlowscaleAPI;
|
package/dist/types.d.ts
CHANGED
|
@@ -93,6 +93,8 @@ export interface FlowscaleConfig {
|
|
|
93
93
|
timeout?: number;
|
|
94
94
|
maxRetries?: number;
|
|
95
95
|
retryDelay?: number;
|
|
96
|
+
enableLogging?: boolean;
|
|
97
|
+
logLevel?: 'debug' | 'info' | 'warn' | 'error';
|
|
96
98
|
}
|
|
97
99
|
export type WebSocketEventCallback = (data: any) => void;
|
|
98
100
|
export interface WebSocketMessage {
|