UNPKG

@wiro-ai/n8n-nodes-wiroai

Version:

n8n community node for Wiro AI's Generative AI APIs.

59 lines 2.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.pollTaskUntilComplete = pollTaskUntilComplete; async function pollTaskUntilComplete(socketaccesstoken, headers, options) { var _a, _b, _c, _d, _e, _f; const pollingIntervalMs = (_a = options === null || options === void 0 ? void 0 : options.pollingIntervalMs) !== null && _a !== void 0 ? _a : 20000; const maxAttempts = (_b = options === null || options === void 0 ? void 0 : options.maxAttempts) !== null && _b !== void 0 ? _b : 30; for (let attempt = 1; attempt <= maxAttempts; attempt++) { if (options === null || options === void 0 ? void 0 : options.debug) { } const taskRequest = { tasktoken: socketaccesstoken, }; try { const response = await this.helpers.request({ method: 'POST', url: 'https://api.wiro.ai/v1/Task/Detail', headers: { ...headers, 'Content-Type': 'application/json', }, body: taskRequest, json: true, }); const task = (_c = response.tasklist) === null || _c === void 0 ? void 0 : _c[0]; const status = task === null || task === void 0 ? void 0 : task.status; if (status === 'task_cancel') { return '-4'; } if (status === 'task_postprocess_end') { const outputs = task.outputs; if (Array.isArray(outputs) && outputs.length > 0) { if (outputs.length === 1) { if ((_d = outputs[0]) === null || _d === void 0 ? void 0 : _d.url) { return outputs[0].url; } } else { const urls = outputs.map((o) => o.url).filter(Boolean); if (urls.length > 0) { return urls.join(' | '); } } const firstMessage = (_f = (_e = outputs[0]) === null || _e === void 0 ? void 0 : _e.content) === null || _f === void 0 ? void 0 : _f.message; if (firstMessage) { return firstMessage; } } return '-3'; } } catch (err) { return '-2'; } await new Promise((res) => setTimeout(res, pollingIntervalMs)); } return '-1'; } //# sourceMappingURL=polling.js.map