@upstash/workflow 0.2.10 → 0.2.12
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/astro.d.mts +2 -2
- package/astro.d.ts +2 -2
- package/astro.js +217 -112
- package/astro.mjs +1 -1
- package/{chunk-GFNR743S.mjs → chunk-4GTHIL7S.mjs} +217 -112
- package/cloudflare.d.mts +2 -2
- package/cloudflare.d.ts +2 -2
- package/cloudflare.js +217 -112
- package/cloudflare.mjs +1 -1
- package/express.d.mts +2 -2
- package/express.d.ts +2 -2
- package/express.js +217 -112
- package/express.mjs +1 -1
- package/h3.d.mts +2 -2
- package/h3.d.ts +2 -2
- package/h3.js +217 -112
- package/h3.mjs +1 -1
- package/hono.d.mts +2 -2
- package/hono.d.ts +2 -2
- package/hono.js +217 -112
- package/hono.mjs +1 -1
- package/index.d.mts +34 -4
- package/index.d.ts +34 -4
- package/index.js +217 -112
- package/index.mjs +1 -1
- package/nextjs.d.mts +2 -2
- package/nextjs.d.ts +2 -2
- package/nextjs.js +217 -112
- package/nextjs.mjs +1 -1
- package/package.json +1 -1
- package/{serve-many-e4zufyXN.d.ts → serve-many-BdMq5rFX.d.ts} +1 -1
- package/{serve-many-BVDpPsF-.d.mts → serve-many-DLguU9iR.d.mts} +1 -1
- package/solidjs.d.mts +1 -1
- package/solidjs.d.ts +1 -1
- package/solidjs.js +217 -112
- package/solidjs.mjs +1 -1
- package/svelte.d.mts +2 -2
- package/svelte.d.ts +2 -2
- package/svelte.js +217 -112
- package/svelte.mjs +1 -1
- package/{types-CYhDXnf8.d.ts → types-D1W0VOpy.d.mts} +70 -46
- package/{types-CYhDXnf8.d.mts → types-D1W0VOpy.d.ts} +70 -46
package/svelte.js
CHANGED
|
@@ -134,7 +134,7 @@ var formatWorkflowError = (error) => {
|
|
|
134
134
|
message: error.message
|
|
135
135
|
} : {
|
|
136
136
|
error: "Error",
|
|
137
|
-
message:
|
|
137
|
+
message: `An error occured while executing workflow: '${typeof error === "string" ? error : JSON.stringify(error)}'`
|
|
138
138
|
};
|
|
139
139
|
};
|
|
140
140
|
|
|
@@ -151,22 +151,21 @@ function getWorkflowRunId(id) {
|
|
|
151
151
|
return `wfr_${id ?? nanoid()}`;
|
|
152
152
|
}
|
|
153
153
|
function decodeBase64(base64) {
|
|
154
|
+
const binString = atob(base64);
|
|
154
155
|
try {
|
|
155
|
-
const binString = atob(base64);
|
|
156
156
|
const intArray = Uint8Array.from(binString, (m) => m.codePointAt(0));
|
|
157
157
|
return new TextDecoder().decode(intArray);
|
|
158
158
|
} catch (error) {
|
|
159
159
|
console.warn(
|
|
160
160
|
`Upstash Qstash: Failed while decoding base64 "${base64}". Decoding with atob and returning it instead. ${error}`
|
|
161
161
|
);
|
|
162
|
-
return
|
|
162
|
+
return binString;
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
165
|
|
|
166
166
|
// src/context/steps.ts
|
|
167
|
-
var BaseLazyStep = class {
|
|
167
|
+
var BaseLazyStep = class _BaseLazyStep {
|
|
168
168
|
stepName;
|
|
169
|
-
// will be set in the subclasses
|
|
170
169
|
constructor(stepName) {
|
|
171
170
|
if (!stepName) {
|
|
172
171
|
throw new WorkflowError(
|
|
@@ -175,10 +174,58 @@ var BaseLazyStep = class {
|
|
|
175
174
|
}
|
|
176
175
|
this.stepName = stepName;
|
|
177
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* parse the out field of a step result.
|
|
179
|
+
*
|
|
180
|
+
* will be called when returning the steps to the context from auto executor
|
|
181
|
+
*
|
|
182
|
+
* @param out field of the step
|
|
183
|
+
* @returns parsed out field
|
|
184
|
+
*/
|
|
185
|
+
parseOut(out) {
|
|
186
|
+
if (out === void 0) {
|
|
187
|
+
if (this.allowUndefinedOut) {
|
|
188
|
+
return void 0;
|
|
189
|
+
} else {
|
|
190
|
+
throw new WorkflowError(
|
|
191
|
+
`Error while parsing output of ${this.stepType} step. Expected a string, but got: undefined`
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (typeof out === "object") {
|
|
196
|
+
if (this.stepType !== "Wait") {
|
|
197
|
+
console.warn(
|
|
198
|
+
`Error while parsing ${this.stepType} step output. Expected a string, but got object. Please reach out to Upstash Support.`
|
|
199
|
+
);
|
|
200
|
+
return out;
|
|
201
|
+
}
|
|
202
|
+
return {
|
|
203
|
+
...out,
|
|
204
|
+
eventData: _BaseLazyStep.tryParsing(out.eventData)
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
if (typeof out !== "string") {
|
|
208
|
+
throw new WorkflowError(
|
|
209
|
+
`Error while parsing output of ${this.stepType} step. Expected a string or undefined, but got: ${typeof out}`
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
return this.safeParseOut(out);
|
|
213
|
+
}
|
|
214
|
+
safeParseOut(out) {
|
|
215
|
+
return _BaseLazyStep.tryParsing(out);
|
|
216
|
+
}
|
|
217
|
+
static tryParsing(stepOut) {
|
|
218
|
+
try {
|
|
219
|
+
return JSON.parse(stepOut);
|
|
220
|
+
} catch {
|
|
221
|
+
return stepOut;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
178
224
|
};
|
|
179
225
|
var LazyFunctionStep = class extends BaseLazyStep {
|
|
180
226
|
stepFunction;
|
|
181
227
|
stepType = "Run";
|
|
228
|
+
allowUndefinedOut = true;
|
|
182
229
|
constructor(stepName, stepFunction) {
|
|
183
230
|
super(stepName);
|
|
184
231
|
this.stepFunction = stepFunction;
|
|
@@ -209,6 +256,7 @@ var LazyFunctionStep = class extends BaseLazyStep {
|
|
|
209
256
|
var LazySleepStep = class extends BaseLazyStep {
|
|
210
257
|
sleep;
|
|
211
258
|
stepType = "SleepFor";
|
|
259
|
+
allowUndefinedOut = true;
|
|
212
260
|
constructor(stepName, sleep) {
|
|
213
261
|
super(stepName);
|
|
214
262
|
this.sleep = sleep;
|
|
@@ -236,6 +284,7 @@ var LazySleepStep = class extends BaseLazyStep {
|
|
|
236
284
|
var LazySleepUntilStep = class extends BaseLazyStep {
|
|
237
285
|
sleepUntil;
|
|
238
286
|
stepType = "SleepUntil";
|
|
287
|
+
allowUndefinedOut = true;
|
|
239
288
|
constructor(stepName, sleepUntil) {
|
|
240
289
|
super(stepName);
|
|
241
290
|
this.sleepUntil = sleepUntil;
|
|
@@ -259,8 +308,11 @@ var LazySleepUntilStep = class extends BaseLazyStep {
|
|
|
259
308
|
concurrent
|
|
260
309
|
});
|
|
261
310
|
}
|
|
311
|
+
safeParseOut() {
|
|
312
|
+
return void 0;
|
|
313
|
+
}
|
|
262
314
|
};
|
|
263
|
-
var LazyCallStep = class extends BaseLazyStep {
|
|
315
|
+
var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
|
|
264
316
|
url;
|
|
265
317
|
method;
|
|
266
318
|
body;
|
|
@@ -269,6 +321,7 @@ var LazyCallStep = class extends BaseLazyStep {
|
|
|
269
321
|
timeout;
|
|
270
322
|
flowControl;
|
|
271
323
|
stepType = "Call";
|
|
324
|
+
allowUndefinedOut = false;
|
|
272
325
|
constructor(stepName, url, method, body, headers, retries, timeout, flowControl) {
|
|
273
326
|
super(stepName);
|
|
274
327
|
this.url = url;
|
|
@@ -300,11 +353,53 @@ var LazyCallStep = class extends BaseLazyStep {
|
|
|
300
353
|
callHeaders: this.headers
|
|
301
354
|
});
|
|
302
355
|
}
|
|
356
|
+
safeParseOut(out) {
|
|
357
|
+
const { header, status, body } = JSON.parse(out);
|
|
358
|
+
const responseHeaders = new Headers(header);
|
|
359
|
+
if (_LazyCallStep.isText(responseHeaders.get("content-type"))) {
|
|
360
|
+
const bytes = new Uint8Array(out.length);
|
|
361
|
+
for (let i = 0; i < out.length; i++) {
|
|
362
|
+
bytes[i] = out.charCodeAt(i);
|
|
363
|
+
}
|
|
364
|
+
const processedResult = new TextDecoder().decode(bytes);
|
|
365
|
+
const newBody = JSON.parse(processedResult).body;
|
|
366
|
+
return {
|
|
367
|
+
status,
|
|
368
|
+
header,
|
|
369
|
+
body: BaseLazyStep.tryParsing(newBody)
|
|
370
|
+
};
|
|
371
|
+
} else {
|
|
372
|
+
return { header, status, body };
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
static applicationHeaders = /* @__PURE__ */ new Set([
|
|
376
|
+
"application/json",
|
|
377
|
+
"application/xml",
|
|
378
|
+
"application/javascript",
|
|
379
|
+
"application/x-www-form-urlencoded",
|
|
380
|
+
"application/xhtml+xml",
|
|
381
|
+
"application/ld+json",
|
|
382
|
+
"application/rss+xml",
|
|
383
|
+
"application/atom+xml"
|
|
384
|
+
]);
|
|
385
|
+
static isText = (contentTypeHeader) => {
|
|
386
|
+
if (!contentTypeHeader) {
|
|
387
|
+
return false;
|
|
388
|
+
}
|
|
389
|
+
if (_LazyCallStep.applicationHeaders.has(contentTypeHeader)) {
|
|
390
|
+
return true;
|
|
391
|
+
}
|
|
392
|
+
if (contentTypeHeader.startsWith("text/")) {
|
|
393
|
+
return true;
|
|
394
|
+
}
|
|
395
|
+
return false;
|
|
396
|
+
};
|
|
303
397
|
};
|
|
304
398
|
var LazyWaitForEventStep = class extends BaseLazyStep {
|
|
305
399
|
eventId;
|
|
306
400
|
timeout;
|
|
307
401
|
stepType = "Wait";
|
|
402
|
+
allowUndefinedOut = false;
|
|
308
403
|
constructor(stepName, eventId, timeout) {
|
|
309
404
|
super(stepName);
|
|
310
405
|
this.eventId = eventId;
|
|
@@ -331,6 +426,13 @@ var LazyWaitForEventStep = class extends BaseLazyStep {
|
|
|
331
426
|
concurrent
|
|
332
427
|
});
|
|
333
428
|
}
|
|
429
|
+
safeParseOut(out) {
|
|
430
|
+
const result = JSON.parse(out);
|
|
431
|
+
return {
|
|
432
|
+
...result,
|
|
433
|
+
eventData: BaseLazyStep.tryParsing(result.eventData)
|
|
434
|
+
};
|
|
435
|
+
}
|
|
334
436
|
};
|
|
335
437
|
var LazyNotifyStep = class extends LazyFunctionStep {
|
|
336
438
|
stepType = "Notify";
|
|
@@ -344,10 +446,18 @@ var LazyNotifyStep = class extends LazyFunctionStep {
|
|
|
344
446
|
};
|
|
345
447
|
});
|
|
346
448
|
}
|
|
449
|
+
safeParseOut(out) {
|
|
450
|
+
const result = JSON.parse(out);
|
|
451
|
+
return {
|
|
452
|
+
...result,
|
|
453
|
+
eventData: BaseLazyStep.tryParsing(result.eventData)
|
|
454
|
+
};
|
|
455
|
+
}
|
|
347
456
|
};
|
|
348
457
|
var LazyInvokeStep = class extends BaseLazyStep {
|
|
349
458
|
stepType = "Invoke";
|
|
350
459
|
params;
|
|
460
|
+
allowUndefinedOut = false;
|
|
351
461
|
constructor(stepName, {
|
|
352
462
|
workflow,
|
|
353
463
|
body,
|
|
@@ -387,6 +497,13 @@ var LazyInvokeStep = class extends BaseLazyStep {
|
|
|
387
497
|
concurrent
|
|
388
498
|
});
|
|
389
499
|
}
|
|
500
|
+
safeParseOut(out) {
|
|
501
|
+
const result = JSON.parse(out);
|
|
502
|
+
return {
|
|
503
|
+
...result,
|
|
504
|
+
body: BaseLazyStep.tryParsing(result.body)
|
|
505
|
+
};
|
|
506
|
+
}
|
|
390
507
|
};
|
|
391
508
|
|
|
392
509
|
// node_modules/neverthrow/dist/index.es.js
|
|
@@ -1072,7 +1189,8 @@ var getHeaders = ({
|
|
|
1072
1189
|
flowControl,
|
|
1073
1190
|
callFlowControl
|
|
1074
1191
|
}) => {
|
|
1075
|
-
const
|
|
1192
|
+
const callHeaders = new Headers(step?.callHeaders);
|
|
1193
|
+
const contentType = (callHeaders.get("content-type") ? callHeaders.get("content-type") : userHeaders?.get("Content-Type") ? userHeaders.get("Content-Type") : void 0) ?? DEFAULT_CONTENT_TYPE;
|
|
1076
1194
|
const baseHeaders = {
|
|
1077
1195
|
[WORKFLOW_INIT_HEADER]: initHeaderValue,
|
|
1078
1196
|
[WORKFLOW_ID_HEADER]: workflowRunId,
|
|
@@ -1483,7 +1601,7 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1483
1601
|
step,
|
|
1484
1602
|
stepCount: this.stepCount
|
|
1485
1603
|
});
|
|
1486
|
-
return step.out;
|
|
1604
|
+
return lazyStep.parseOut(step.out);
|
|
1487
1605
|
}
|
|
1488
1606
|
const resultStep = await lazyStep.getResultStep(NO_CONCURRENCY, this.stepCount);
|
|
1489
1607
|
await this.debug?.log("INFO", "RUN_SINGLE", {
|
|
@@ -1558,7 +1676,9 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1558
1676
|
case "last": {
|
|
1559
1677
|
const parallelResultSteps = sortedSteps.filter((step) => step.stepId >= initialStepCount).slice(0, parallelSteps.length);
|
|
1560
1678
|
validateParallelSteps(parallelSteps, parallelResultSteps);
|
|
1561
|
-
return parallelResultSteps.map(
|
|
1679
|
+
return parallelResultSteps.map(
|
|
1680
|
+
(step, index) => parallelSteps[index].parseOut(step.out)
|
|
1681
|
+
);
|
|
1562
1682
|
}
|
|
1563
1683
|
}
|
|
1564
1684
|
const fillValue = void 0;
|
|
@@ -1661,7 +1781,7 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1661
1781
|
});
|
|
1662
1782
|
throw new WorkflowAbort(invokeStep.stepName, invokeStep);
|
|
1663
1783
|
}
|
|
1664
|
-
const result = await this.context.qstashClient.
|
|
1784
|
+
const result = await this.context.qstashClient.batch(
|
|
1665
1785
|
steps.map((singleStep, index) => {
|
|
1666
1786
|
const lazyStep = lazySteps[index];
|
|
1667
1787
|
const { headers } = getHeaders({
|
|
@@ -1691,7 +1811,7 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1691
1811
|
{
|
|
1692
1812
|
headers,
|
|
1693
1813
|
method: singleStep.callMethod,
|
|
1694
|
-
body: singleStep.callBody,
|
|
1814
|
+
body: JSON.stringify(singleStep.callBody),
|
|
1695
1815
|
url: singleStep.callUrl
|
|
1696
1816
|
}
|
|
1697
1817
|
) : (
|
|
@@ -1701,7 +1821,7 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1701
1821
|
{
|
|
1702
1822
|
headers,
|
|
1703
1823
|
method: "POST",
|
|
1704
|
-
body: singleStep,
|
|
1824
|
+
body: JSON.stringify(singleStep),
|
|
1705
1825
|
url: this.context.url,
|
|
1706
1826
|
notBefore: willWait ? singleStep.sleepUntil : void 0,
|
|
1707
1827
|
delay: willWait ? singleStep.sleepFor : void 0
|
|
@@ -1709,8 +1829,9 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1709
1829
|
);
|
|
1710
1830
|
})
|
|
1711
1831
|
);
|
|
1832
|
+
const _result = result;
|
|
1712
1833
|
await this.debug?.log("INFO", "SUBMIT_STEP", {
|
|
1713
|
-
messageIds:
|
|
1834
|
+
messageIds: _result.map((message) => {
|
|
1714
1835
|
return {
|
|
1715
1836
|
message: message.messageId
|
|
1716
1837
|
};
|
|
@@ -1913,6 +2034,9 @@ var WorkflowApi = class extends BaseWorkflowApi {
|
|
|
1913
2034
|
}
|
|
1914
2035
|
};
|
|
1915
2036
|
|
|
2037
|
+
// src/agents/index.ts
|
|
2038
|
+
var import_openai3 = require("@ai-sdk/openai");
|
|
2039
|
+
|
|
1916
2040
|
// src/agents/adapters.ts
|
|
1917
2041
|
var import_openai2 = require("@ai-sdk/openai");
|
|
1918
2042
|
var import_ai = require("ai");
|
|
@@ -1932,46 +2056,49 @@ you need from that agent.
|
|
|
1932
2056
|
`;
|
|
1933
2057
|
|
|
1934
2058
|
// src/agents/adapters.ts
|
|
1935
|
-
var
|
|
1936
|
-
const
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
if (error instanceof Error && error.name === "WorkflowAbort") {
|
|
1968
|
-
throw error;
|
|
1969
|
-
} else {
|
|
1970
|
-
console.error("Error in fetch implementation:", error);
|
|
1971
|
-
throw error;
|
|
1972
|
-
}
|
|
1973
|
-
}
|
|
2059
|
+
var fetchWithContextCall = async (context, ...params) => {
|
|
2060
|
+
const [input, init] = params;
|
|
2061
|
+
try {
|
|
2062
|
+
const headers = init?.headers ? Object.fromEntries(new Headers(init.headers).entries()) : {};
|
|
2063
|
+
const body = init?.body ? JSON.parse(init.body) : void 0;
|
|
2064
|
+
const agentName = headers[AGENT_NAME_HEADER];
|
|
2065
|
+
const stepName = agentName ? `Call Agent ${agentName}` : "Call Agent";
|
|
2066
|
+
const responseInfo = await context.call(stepName, {
|
|
2067
|
+
url: input.toString(),
|
|
2068
|
+
method: init?.method,
|
|
2069
|
+
headers,
|
|
2070
|
+
body
|
|
2071
|
+
});
|
|
2072
|
+
const responseHeaders = new Headers(
|
|
2073
|
+
Object.entries(responseInfo.header).reduce(
|
|
2074
|
+
(acc, [key, values]) => {
|
|
2075
|
+
acc[key] = values.join(", ");
|
|
2076
|
+
return acc;
|
|
2077
|
+
},
|
|
2078
|
+
{}
|
|
2079
|
+
)
|
|
2080
|
+
);
|
|
2081
|
+
return new Response(JSON.stringify(responseInfo.body), {
|
|
2082
|
+
status: responseInfo.status,
|
|
2083
|
+
headers: responseHeaders
|
|
2084
|
+
});
|
|
2085
|
+
} catch (error) {
|
|
2086
|
+
if (error instanceof Error && error.name === "WorkflowAbort") {
|
|
2087
|
+
throw error;
|
|
2088
|
+
} else {
|
|
2089
|
+
console.error("Error in fetch implementation:", error);
|
|
2090
|
+
throw error;
|
|
1974
2091
|
}
|
|
2092
|
+
}
|
|
2093
|
+
};
|
|
2094
|
+
var createWorkflowModel = ({
|
|
2095
|
+
context,
|
|
2096
|
+
provider,
|
|
2097
|
+
providerParams
|
|
2098
|
+
}) => {
|
|
2099
|
+
return provider({
|
|
2100
|
+
fetch: (...params) => fetchWithContextCall(context, ...params),
|
|
2101
|
+
...providerParams
|
|
1975
2102
|
});
|
|
1976
2103
|
};
|
|
1977
2104
|
var wrapTools = ({
|
|
@@ -2211,9 +2338,14 @@ var WorkflowAgents = class {
|
|
|
2211
2338
|
openai(...params) {
|
|
2212
2339
|
const [model, settings] = params;
|
|
2213
2340
|
const { baseURL, apiKey, ...otherSettings } = settings ?? {};
|
|
2214
|
-
const
|
|
2215
|
-
|
|
2341
|
+
const openaiModel = this.AISDKModel({
|
|
2342
|
+
context: this.context,
|
|
2343
|
+
provider: import_openai3.createOpenAI,
|
|
2344
|
+
providerParams: { baseURL, apiKey, compatibility: "strict" }
|
|
2345
|
+
});
|
|
2346
|
+
return openaiModel(model, otherSettings);
|
|
2216
2347
|
}
|
|
2348
|
+
AISDKModel = createWorkflowModel;
|
|
2217
2349
|
};
|
|
2218
2350
|
|
|
2219
2351
|
// src/context/context.ts
|
|
@@ -2399,7 +2531,7 @@ var WorkflowContext = class {
|
|
|
2399
2531
|
*/
|
|
2400
2532
|
async run(stepName, stepFunction) {
|
|
2401
2533
|
const wrappedStepFunction = () => this.executor.wrapStep(stepName, stepFunction);
|
|
2402
|
-
return this.addStep(new LazyFunctionStep(stepName, wrappedStepFunction));
|
|
2534
|
+
return await this.addStep(new LazyFunctionStep(stepName, wrappedStepFunction));
|
|
2403
2535
|
}
|
|
2404
2536
|
/**
|
|
2405
2537
|
* Stops the execution for the duration provided.
|
|
@@ -2470,43 +2602,27 @@ var WorkflowContext = class {
|
|
|
2470
2602
|
* }
|
|
2471
2603
|
*/
|
|
2472
2604
|
async call(stepName, settings) {
|
|
2473
|
-
const {
|
|
2474
|
-
|
|
2605
|
+
const {
|
|
2606
|
+
url,
|
|
2607
|
+
method = "GET",
|
|
2608
|
+
body: requestBody,
|
|
2609
|
+
headers = {},
|
|
2610
|
+
retries = 0,
|
|
2611
|
+
timeout,
|
|
2612
|
+
flowControl
|
|
2613
|
+
} = settings;
|
|
2614
|
+
return await this.addStep(
|
|
2475
2615
|
new LazyCallStep(
|
|
2476
2616
|
stepName,
|
|
2477
2617
|
url,
|
|
2478
2618
|
method,
|
|
2479
|
-
|
|
2619
|
+
requestBody,
|
|
2480
2620
|
headers,
|
|
2481
2621
|
retries,
|
|
2482
2622
|
timeout,
|
|
2483
2623
|
flowControl
|
|
2484
2624
|
)
|
|
2485
2625
|
);
|
|
2486
|
-
if (typeof result === "string") {
|
|
2487
|
-
try {
|
|
2488
|
-
const body2 = JSON.parse(result);
|
|
2489
|
-
return {
|
|
2490
|
-
status: 200,
|
|
2491
|
-
header: {},
|
|
2492
|
-
body: body2
|
|
2493
|
-
};
|
|
2494
|
-
} catch {
|
|
2495
|
-
return {
|
|
2496
|
-
status: 200,
|
|
2497
|
-
header: {},
|
|
2498
|
-
body: result
|
|
2499
|
-
};
|
|
2500
|
-
}
|
|
2501
|
-
}
|
|
2502
|
-
try {
|
|
2503
|
-
return {
|
|
2504
|
-
...result,
|
|
2505
|
-
body: JSON.parse(result.body)
|
|
2506
|
-
};
|
|
2507
|
-
} catch {
|
|
2508
|
-
return result;
|
|
2509
|
-
}
|
|
2510
2626
|
}
|
|
2511
2627
|
/**
|
|
2512
2628
|
* Pauses workflow execution until a specific event occurs or a timeout is reached.
|
|
@@ -2545,15 +2661,7 @@ var WorkflowContext = class {
|
|
|
2545
2661
|
async waitForEvent(stepName, eventId, options = {}) {
|
|
2546
2662
|
const { timeout = "7d" } = options;
|
|
2547
2663
|
const timeoutStr = typeof timeout === "string" ? timeout : `${timeout}s`;
|
|
2548
|
-
|
|
2549
|
-
try {
|
|
2550
|
-
return {
|
|
2551
|
-
...result,
|
|
2552
|
-
eventData: JSON.parse(result.eventData)
|
|
2553
|
-
};
|
|
2554
|
-
} catch {
|
|
2555
|
-
return result;
|
|
2556
|
-
}
|
|
2664
|
+
return await this.addStep(new LazyWaitForEventStep(stepName, eventId, timeoutStr));
|
|
2557
2665
|
}
|
|
2558
2666
|
/**
|
|
2559
2667
|
* Notify workflow runs waiting for an event
|
|
@@ -2577,24 +2685,12 @@ var WorkflowContext = class {
|
|
|
2577
2685
|
* @returns notify response which has event id, event data and list of waiters which were notified
|
|
2578
2686
|
*/
|
|
2579
2687
|
async notify(stepName, eventId, eventData) {
|
|
2580
|
-
|
|
2688
|
+
return await this.addStep(
|
|
2581
2689
|
new LazyNotifyStep(stepName, eventId, eventData, this.qstashClient.http)
|
|
2582
2690
|
);
|
|
2583
|
-
try {
|
|
2584
|
-
return {
|
|
2585
|
-
...result,
|
|
2586
|
-
eventData: JSON.parse(result.eventData)
|
|
2587
|
-
};
|
|
2588
|
-
} catch {
|
|
2589
|
-
return result;
|
|
2590
|
-
}
|
|
2591
2691
|
}
|
|
2592
2692
|
async invoke(stepName, settings) {
|
|
2593
|
-
|
|
2594
|
-
return {
|
|
2595
|
-
...result,
|
|
2596
|
-
body: result.body ? JSON.parse(result.body) : void 0
|
|
2597
|
-
};
|
|
2693
|
+
return await this.addStep(new LazyInvokeStep(stepName, settings));
|
|
2598
2694
|
}
|
|
2599
2695
|
/**
|
|
2600
2696
|
* Cancel the current workflow run
|
|
@@ -2753,10 +2849,6 @@ var processRawSteps = (rawSteps) => {
|
|
|
2753
2849
|
const stepsToDecode = encodedSteps.filter((step) => step.callType === "step");
|
|
2754
2850
|
const otherSteps = stepsToDecode.map((rawStep) => {
|
|
2755
2851
|
const step = JSON.parse(decodeBase64(rawStep.body));
|
|
2756
|
-
try {
|
|
2757
|
-
step.out = JSON.parse(step.out);
|
|
2758
|
-
} catch {
|
|
2759
|
-
}
|
|
2760
2852
|
if (step.waitEventId) {
|
|
2761
2853
|
const newOut = {
|
|
2762
2854
|
eventData: step.out ? decodeBase64(step.out) : void 0,
|
|
@@ -2976,6 +3068,7 @@ var processOptions = (options) => {
|
|
|
2976
3068
|
retries: DEFAULT_RETRIES,
|
|
2977
3069
|
useJSONContent: false,
|
|
2978
3070
|
disableTelemetry: false,
|
|
3071
|
+
onError: console.error,
|
|
2979
3072
|
...options
|
|
2980
3073
|
};
|
|
2981
3074
|
};
|
|
@@ -3025,7 +3118,8 @@ var serveBase = (routeFunction, telemetry2, options) => {
|
|
|
3025
3118
|
retries,
|
|
3026
3119
|
useJSONContent,
|
|
3027
3120
|
disableTelemetry,
|
|
3028
|
-
flowControl
|
|
3121
|
+
flowControl,
|
|
3122
|
+
onError
|
|
3029
3123
|
} = processOptions(options);
|
|
3030
3124
|
telemetry2 = disableTelemetry ? void 0 : telemetry2;
|
|
3031
3125
|
const debug = WorkflowLogger.getLogger(verbose);
|
|
@@ -3154,8 +3248,19 @@ var serveBase = (routeFunction, telemetry2, options) => {
|
|
|
3154
3248
|
try {
|
|
3155
3249
|
return await handler(request);
|
|
3156
3250
|
} catch (error) {
|
|
3157
|
-
|
|
3158
|
-
|
|
3251
|
+
const formattedError = formatWorkflowError(error);
|
|
3252
|
+
try {
|
|
3253
|
+
onError?.(error);
|
|
3254
|
+
} catch (onErrorError) {
|
|
3255
|
+
const formattedOnErrorError = formatWorkflowError(onErrorError);
|
|
3256
|
+
const errorMessage = `Error while running onError callback: '${formattedOnErrorError.message}'.
|
|
3257
|
+
Original error: '${formattedError.message}'`;
|
|
3258
|
+
console.error(errorMessage);
|
|
3259
|
+
return new Response(errorMessage, {
|
|
3260
|
+
status: 500
|
|
3261
|
+
});
|
|
3262
|
+
}
|
|
3263
|
+
return new Response(JSON.stringify(formattedError), {
|
|
3159
3264
|
status: 500
|
|
3160
3265
|
});
|
|
3161
3266
|
}
|