flowscale 1.0.13 → 1.0.14
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 +45 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +49 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -165,6 +165,51 @@ console.log('Workflow Result:', result);
|
|
|
165
165
|
|
|
166
166
|
---
|
|
167
167
|
|
|
168
|
+
### 3.1 `executeWorkflowAsync(workflowId, data, groupId?, pollIntervalMs?, timeoutMs?)`
|
|
169
|
+
|
|
170
|
+
**Description:**
|
|
171
|
+
Execute a workflow and automatically wait for the result by polling the output. This is a convenience method that combines `executeWorkflow` and `getOutput` with automatic polling.
|
|
172
|
+
|
|
173
|
+
**Parameters:**
|
|
174
|
+
- `workflowId` *(string)*: The unique ID of the workflow.
|
|
175
|
+
- `data` *(object)*: Input parameters for the workflow.
|
|
176
|
+
- `groupId` *(string, optional)*: A custom identifier for grouping runs.
|
|
177
|
+
- `pollIntervalMs` *(number, optional)*: Polling interval in milliseconds (default: 1000).
|
|
178
|
+
- `timeoutMs` *(number, optional)*: Maximum time to wait for results in milliseconds (default: 300000 - 5 minutes).
|
|
179
|
+
|
|
180
|
+
**Usage:**
|
|
181
|
+
```javascript
|
|
182
|
+
const workflowId = "bncu0a1kipv";
|
|
183
|
+
const inputs = {
|
|
184
|
+
"text_51536": "Prompt test",
|
|
185
|
+
"image_1234": { /* File or Blob of image */ }
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
try {
|
|
189
|
+
const result = await flowscale.executeWorkflowAsync(workflowId, inputs);
|
|
190
|
+
console.log('Workflow Result:', result);
|
|
191
|
+
} catch (error) {
|
|
192
|
+
if (error.message.includes('timed out')) {
|
|
193
|
+
console.error('Workflow took too long to complete');
|
|
194
|
+
} else {
|
|
195
|
+
console.error('Workflow error:', error);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
**Response Example:**
|
|
201
|
+
```json
|
|
202
|
+
{
|
|
203
|
+
"status": "success",
|
|
204
|
+
"data": {
|
|
205
|
+
"download_url": "https://runs.s3.amazonaws.com/generations/...",
|
|
206
|
+
"generation_status": "success"
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
168
213
|
### 4. `getOutput(filename)`
|
|
169
214
|
|
|
170
215
|
**Description:**
|
package/dist/index.d.ts
CHANGED
|
@@ -21,6 +21,17 @@ export declare class FlowscaleAPI {
|
|
|
21
21
|
executeWorkflow(workflowId: string, data: {
|
|
22
22
|
[key: string]: any;
|
|
23
23
|
}, groupId?: string): Promise<ExecuteWorkflowResponse>;
|
|
24
|
+
/**
|
|
25
|
+
* Executes a workflow and waits for the output by polling.
|
|
26
|
+
* @param workflowId - The ID of the workflow to execute.
|
|
27
|
+
* @param data - Form data including text fields and file uploads.
|
|
28
|
+
* @param groupId - Optional group ID.
|
|
29
|
+
* @param pollIntervalMs - Optional polling interval in milliseconds (default: 1000)
|
|
30
|
+
* @param timeoutMs - Optional timeout in milliseconds (default: 300000 - 5 minutes)
|
|
31
|
+
*/
|
|
32
|
+
executeWorkflowAsync(workflowId: string, data: {
|
|
33
|
+
[key: string]: any;
|
|
34
|
+
}, groupId?: string, pollIntervalMs?: number, timeoutMs?: number): Promise<GetOutputResponse>;
|
|
24
35
|
/**
|
|
25
36
|
* Retrieves the output of a specific run by providing the filename.
|
|
26
37
|
* @param filename - The filename of the output to retrieve.
|
package/dist/index.js
CHANGED
|
@@ -167,6 +167,55 @@ var FlowscaleAPI = /** @class */ (function () {
|
|
|
167
167
|
});
|
|
168
168
|
});
|
|
169
169
|
};
|
|
170
|
+
/**
|
|
171
|
+
* Executes a workflow and waits for the output by polling.
|
|
172
|
+
* @param workflowId - The ID of the workflow to execute.
|
|
173
|
+
* @param data - Form data including text fields and file uploads.
|
|
174
|
+
* @param groupId - Optional group ID.
|
|
175
|
+
* @param pollIntervalMs - Optional polling interval in milliseconds (default: 1000)
|
|
176
|
+
* @param timeoutMs - Optional timeout in milliseconds (default: 300000 - 5 minutes)
|
|
177
|
+
*/
|
|
178
|
+
FlowscaleAPI.prototype.executeWorkflowAsync = function (workflowId_1, data_1, groupId_1) {
|
|
179
|
+
return __awaiter(this, arguments, void 0, function (workflowId, data, groupId, pollIntervalMs, timeoutMs) {
|
|
180
|
+
var startTime, executeResponse, outputName, output;
|
|
181
|
+
var _a, _b;
|
|
182
|
+
if (pollIntervalMs === void 0) { pollIntervalMs = 1000; }
|
|
183
|
+
if (timeoutMs === void 0) { timeoutMs = 300000; }
|
|
184
|
+
return __generator(this, function (_c) {
|
|
185
|
+
switch (_c.label) {
|
|
186
|
+
case 0:
|
|
187
|
+
startTime = Date.now();
|
|
188
|
+
return [4 /*yield*/, this.executeWorkflow(workflowId, data, groupId)];
|
|
189
|
+
case 1:
|
|
190
|
+
executeResponse = _c.sent();
|
|
191
|
+
// If there are no output names, throw an error
|
|
192
|
+
if (!((_b = (_a = executeResponse === null || executeResponse === void 0 ? void 0 : executeResponse.data) === null || _a === void 0 ? void 0 : _a.output_names) === null || _b === void 0 ? void 0 : _b.length)) {
|
|
193
|
+
throw new Error('No output names returned from workflow execution');
|
|
194
|
+
}
|
|
195
|
+
outputName = executeResponse.data.output_names[0];
|
|
196
|
+
_c.label = 2;
|
|
197
|
+
case 2:
|
|
198
|
+
if (!true) return [3 /*break*/, 5];
|
|
199
|
+
if (Date.now() - startTime > timeoutMs) {
|
|
200
|
+
throw new Error("Workflow execution timed out after ".concat(timeoutMs, "ms"));
|
|
201
|
+
}
|
|
202
|
+
return [4 /*yield*/, this.getOutput(outputName)];
|
|
203
|
+
case 3:
|
|
204
|
+
output = _c.sent();
|
|
205
|
+
if (output !== null) {
|
|
206
|
+
return [2 /*return*/, output];
|
|
207
|
+
}
|
|
208
|
+
// Wait for the polling interval
|
|
209
|
+
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, pollIntervalMs); })];
|
|
210
|
+
case 4:
|
|
211
|
+
// Wait for the polling interval
|
|
212
|
+
_c.sent();
|
|
213
|
+
return [3 /*break*/, 2];
|
|
214
|
+
case 5: return [2 /*return*/];
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
};
|
|
170
219
|
/**
|
|
171
220
|
* Retrieves the output of a specific run by providing the filename.
|
|
172
221
|
* @param filename - The filename of the output to retrieve.
|