@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/solidjs.js
CHANGED
|
@@ -132,7 +132,7 @@ var formatWorkflowError = (error) => {
|
|
|
132
132
|
message: error.message
|
|
133
133
|
} : {
|
|
134
134
|
error: "Error",
|
|
135
|
-
message:
|
|
135
|
+
message: `An error occured while executing workflow: '${typeof error === "string" ? error : JSON.stringify(error)}'`
|
|
136
136
|
};
|
|
137
137
|
};
|
|
138
138
|
|
|
@@ -149,22 +149,21 @@ function getWorkflowRunId(id) {
|
|
|
149
149
|
return `wfr_${id ?? nanoid()}`;
|
|
150
150
|
}
|
|
151
151
|
function decodeBase64(base64) {
|
|
152
|
+
const binString = atob(base64);
|
|
152
153
|
try {
|
|
153
|
-
const binString = atob(base64);
|
|
154
154
|
const intArray = Uint8Array.from(binString, (m) => m.codePointAt(0));
|
|
155
155
|
return new TextDecoder().decode(intArray);
|
|
156
156
|
} catch (error) {
|
|
157
157
|
console.warn(
|
|
158
158
|
`Upstash Qstash: Failed while decoding base64 "${base64}". Decoding with atob and returning it instead. ${error}`
|
|
159
159
|
);
|
|
160
|
-
return
|
|
160
|
+
return binString;
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
// src/context/steps.ts
|
|
165
|
-
var BaseLazyStep = class {
|
|
165
|
+
var BaseLazyStep = class _BaseLazyStep {
|
|
166
166
|
stepName;
|
|
167
|
-
// will be set in the subclasses
|
|
168
167
|
constructor(stepName) {
|
|
169
168
|
if (!stepName) {
|
|
170
169
|
throw new WorkflowError(
|
|
@@ -173,10 +172,58 @@ var BaseLazyStep = class {
|
|
|
173
172
|
}
|
|
174
173
|
this.stepName = stepName;
|
|
175
174
|
}
|
|
175
|
+
/**
|
|
176
|
+
* parse the out field of a step result.
|
|
177
|
+
*
|
|
178
|
+
* will be called when returning the steps to the context from auto executor
|
|
179
|
+
*
|
|
180
|
+
* @param out field of the step
|
|
181
|
+
* @returns parsed out field
|
|
182
|
+
*/
|
|
183
|
+
parseOut(out) {
|
|
184
|
+
if (out === void 0) {
|
|
185
|
+
if (this.allowUndefinedOut) {
|
|
186
|
+
return void 0;
|
|
187
|
+
} else {
|
|
188
|
+
throw new WorkflowError(
|
|
189
|
+
`Error while parsing output of ${this.stepType} step. Expected a string, but got: undefined`
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (typeof out === "object") {
|
|
194
|
+
if (this.stepType !== "Wait") {
|
|
195
|
+
console.warn(
|
|
196
|
+
`Error while parsing ${this.stepType} step output. Expected a string, but got object. Please reach out to Upstash Support.`
|
|
197
|
+
);
|
|
198
|
+
return out;
|
|
199
|
+
}
|
|
200
|
+
return {
|
|
201
|
+
...out,
|
|
202
|
+
eventData: _BaseLazyStep.tryParsing(out.eventData)
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
if (typeof out !== "string") {
|
|
206
|
+
throw new WorkflowError(
|
|
207
|
+
`Error while parsing output of ${this.stepType} step. Expected a string or undefined, but got: ${typeof out}`
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
return this.safeParseOut(out);
|
|
211
|
+
}
|
|
212
|
+
safeParseOut(out) {
|
|
213
|
+
return _BaseLazyStep.tryParsing(out);
|
|
214
|
+
}
|
|
215
|
+
static tryParsing(stepOut) {
|
|
216
|
+
try {
|
|
217
|
+
return JSON.parse(stepOut);
|
|
218
|
+
} catch {
|
|
219
|
+
return stepOut;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
176
222
|
};
|
|
177
223
|
var LazyFunctionStep = class extends BaseLazyStep {
|
|
178
224
|
stepFunction;
|
|
179
225
|
stepType = "Run";
|
|
226
|
+
allowUndefinedOut = true;
|
|
180
227
|
constructor(stepName, stepFunction) {
|
|
181
228
|
super(stepName);
|
|
182
229
|
this.stepFunction = stepFunction;
|
|
@@ -207,6 +254,7 @@ var LazyFunctionStep = class extends BaseLazyStep {
|
|
|
207
254
|
var LazySleepStep = class extends BaseLazyStep {
|
|
208
255
|
sleep;
|
|
209
256
|
stepType = "SleepFor";
|
|
257
|
+
allowUndefinedOut = true;
|
|
210
258
|
constructor(stepName, sleep) {
|
|
211
259
|
super(stepName);
|
|
212
260
|
this.sleep = sleep;
|
|
@@ -234,6 +282,7 @@ var LazySleepStep = class extends BaseLazyStep {
|
|
|
234
282
|
var LazySleepUntilStep = class extends BaseLazyStep {
|
|
235
283
|
sleepUntil;
|
|
236
284
|
stepType = "SleepUntil";
|
|
285
|
+
allowUndefinedOut = true;
|
|
237
286
|
constructor(stepName, sleepUntil) {
|
|
238
287
|
super(stepName);
|
|
239
288
|
this.sleepUntil = sleepUntil;
|
|
@@ -257,8 +306,11 @@ var LazySleepUntilStep = class extends BaseLazyStep {
|
|
|
257
306
|
concurrent
|
|
258
307
|
});
|
|
259
308
|
}
|
|
309
|
+
safeParseOut() {
|
|
310
|
+
return void 0;
|
|
311
|
+
}
|
|
260
312
|
};
|
|
261
|
-
var LazyCallStep = class extends BaseLazyStep {
|
|
313
|
+
var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
|
|
262
314
|
url;
|
|
263
315
|
method;
|
|
264
316
|
body;
|
|
@@ -267,6 +319,7 @@ var LazyCallStep = class extends BaseLazyStep {
|
|
|
267
319
|
timeout;
|
|
268
320
|
flowControl;
|
|
269
321
|
stepType = "Call";
|
|
322
|
+
allowUndefinedOut = false;
|
|
270
323
|
constructor(stepName, url, method, body, headers, retries, timeout, flowControl) {
|
|
271
324
|
super(stepName);
|
|
272
325
|
this.url = url;
|
|
@@ -298,11 +351,53 @@ var LazyCallStep = class extends BaseLazyStep {
|
|
|
298
351
|
callHeaders: this.headers
|
|
299
352
|
});
|
|
300
353
|
}
|
|
354
|
+
safeParseOut(out) {
|
|
355
|
+
const { header, status, body } = JSON.parse(out);
|
|
356
|
+
const responseHeaders = new Headers(header);
|
|
357
|
+
if (_LazyCallStep.isText(responseHeaders.get("content-type"))) {
|
|
358
|
+
const bytes = new Uint8Array(out.length);
|
|
359
|
+
for (let i = 0; i < out.length; i++) {
|
|
360
|
+
bytes[i] = out.charCodeAt(i);
|
|
361
|
+
}
|
|
362
|
+
const processedResult = new TextDecoder().decode(bytes);
|
|
363
|
+
const newBody = JSON.parse(processedResult).body;
|
|
364
|
+
return {
|
|
365
|
+
status,
|
|
366
|
+
header,
|
|
367
|
+
body: BaseLazyStep.tryParsing(newBody)
|
|
368
|
+
};
|
|
369
|
+
} else {
|
|
370
|
+
return { header, status, body };
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
static applicationHeaders = /* @__PURE__ */ new Set([
|
|
374
|
+
"application/json",
|
|
375
|
+
"application/xml",
|
|
376
|
+
"application/javascript",
|
|
377
|
+
"application/x-www-form-urlencoded",
|
|
378
|
+
"application/xhtml+xml",
|
|
379
|
+
"application/ld+json",
|
|
380
|
+
"application/rss+xml",
|
|
381
|
+
"application/atom+xml"
|
|
382
|
+
]);
|
|
383
|
+
static isText = (contentTypeHeader) => {
|
|
384
|
+
if (!contentTypeHeader) {
|
|
385
|
+
return false;
|
|
386
|
+
}
|
|
387
|
+
if (_LazyCallStep.applicationHeaders.has(contentTypeHeader)) {
|
|
388
|
+
return true;
|
|
389
|
+
}
|
|
390
|
+
if (contentTypeHeader.startsWith("text/")) {
|
|
391
|
+
return true;
|
|
392
|
+
}
|
|
393
|
+
return false;
|
|
394
|
+
};
|
|
301
395
|
};
|
|
302
396
|
var LazyWaitForEventStep = class extends BaseLazyStep {
|
|
303
397
|
eventId;
|
|
304
398
|
timeout;
|
|
305
399
|
stepType = "Wait";
|
|
400
|
+
allowUndefinedOut = false;
|
|
306
401
|
constructor(stepName, eventId, timeout) {
|
|
307
402
|
super(stepName);
|
|
308
403
|
this.eventId = eventId;
|
|
@@ -329,6 +424,13 @@ var LazyWaitForEventStep = class extends BaseLazyStep {
|
|
|
329
424
|
concurrent
|
|
330
425
|
});
|
|
331
426
|
}
|
|
427
|
+
safeParseOut(out) {
|
|
428
|
+
const result = JSON.parse(out);
|
|
429
|
+
return {
|
|
430
|
+
...result,
|
|
431
|
+
eventData: BaseLazyStep.tryParsing(result.eventData)
|
|
432
|
+
};
|
|
433
|
+
}
|
|
332
434
|
};
|
|
333
435
|
var LazyNotifyStep = class extends LazyFunctionStep {
|
|
334
436
|
stepType = "Notify";
|
|
@@ -342,10 +444,18 @@ var LazyNotifyStep = class extends LazyFunctionStep {
|
|
|
342
444
|
};
|
|
343
445
|
});
|
|
344
446
|
}
|
|
447
|
+
safeParseOut(out) {
|
|
448
|
+
const result = JSON.parse(out);
|
|
449
|
+
return {
|
|
450
|
+
...result,
|
|
451
|
+
eventData: BaseLazyStep.tryParsing(result.eventData)
|
|
452
|
+
};
|
|
453
|
+
}
|
|
345
454
|
};
|
|
346
455
|
var LazyInvokeStep = class extends BaseLazyStep {
|
|
347
456
|
stepType = "Invoke";
|
|
348
457
|
params;
|
|
458
|
+
allowUndefinedOut = false;
|
|
349
459
|
constructor(stepName, {
|
|
350
460
|
workflow,
|
|
351
461
|
body,
|
|
@@ -385,6 +495,13 @@ var LazyInvokeStep = class extends BaseLazyStep {
|
|
|
385
495
|
concurrent
|
|
386
496
|
});
|
|
387
497
|
}
|
|
498
|
+
safeParseOut(out) {
|
|
499
|
+
const result = JSON.parse(out);
|
|
500
|
+
return {
|
|
501
|
+
...result,
|
|
502
|
+
body: BaseLazyStep.tryParsing(result.body)
|
|
503
|
+
};
|
|
504
|
+
}
|
|
388
505
|
};
|
|
389
506
|
|
|
390
507
|
// node_modules/neverthrow/dist/index.es.js
|
|
@@ -1070,7 +1187,8 @@ var getHeaders = ({
|
|
|
1070
1187
|
flowControl,
|
|
1071
1188
|
callFlowControl
|
|
1072
1189
|
}) => {
|
|
1073
|
-
const
|
|
1190
|
+
const callHeaders = new Headers(step?.callHeaders);
|
|
1191
|
+
const contentType = (callHeaders.get("content-type") ? callHeaders.get("content-type") : userHeaders?.get("Content-Type") ? userHeaders.get("Content-Type") : void 0) ?? DEFAULT_CONTENT_TYPE;
|
|
1074
1192
|
const baseHeaders = {
|
|
1075
1193
|
[WORKFLOW_INIT_HEADER]: initHeaderValue,
|
|
1076
1194
|
[WORKFLOW_ID_HEADER]: workflowRunId,
|
|
@@ -1420,7 +1538,7 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1420
1538
|
step,
|
|
1421
1539
|
stepCount: this.stepCount
|
|
1422
1540
|
});
|
|
1423
|
-
return step.out;
|
|
1541
|
+
return lazyStep.parseOut(step.out);
|
|
1424
1542
|
}
|
|
1425
1543
|
const resultStep = await lazyStep.getResultStep(NO_CONCURRENCY, this.stepCount);
|
|
1426
1544
|
await this.debug?.log("INFO", "RUN_SINGLE", {
|
|
@@ -1495,7 +1613,9 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1495
1613
|
case "last": {
|
|
1496
1614
|
const parallelResultSteps = sortedSteps.filter((step) => step.stepId >= initialStepCount).slice(0, parallelSteps.length);
|
|
1497
1615
|
validateParallelSteps(parallelSteps, parallelResultSteps);
|
|
1498
|
-
return parallelResultSteps.map(
|
|
1616
|
+
return parallelResultSteps.map(
|
|
1617
|
+
(step, index) => parallelSteps[index].parseOut(step.out)
|
|
1618
|
+
);
|
|
1499
1619
|
}
|
|
1500
1620
|
}
|
|
1501
1621
|
const fillValue = void 0;
|
|
@@ -1598,7 +1718,7 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1598
1718
|
});
|
|
1599
1719
|
throw new WorkflowAbort(invokeStep.stepName, invokeStep);
|
|
1600
1720
|
}
|
|
1601
|
-
const result = await this.context.qstashClient.
|
|
1721
|
+
const result = await this.context.qstashClient.batch(
|
|
1602
1722
|
steps.map((singleStep, index) => {
|
|
1603
1723
|
const lazyStep = lazySteps[index];
|
|
1604
1724
|
const { headers } = getHeaders({
|
|
@@ -1628,7 +1748,7 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1628
1748
|
{
|
|
1629
1749
|
headers,
|
|
1630
1750
|
method: singleStep.callMethod,
|
|
1631
|
-
body: singleStep.callBody,
|
|
1751
|
+
body: JSON.stringify(singleStep.callBody),
|
|
1632
1752
|
url: singleStep.callUrl
|
|
1633
1753
|
}
|
|
1634
1754
|
) : (
|
|
@@ -1638,7 +1758,7 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1638
1758
|
{
|
|
1639
1759
|
headers,
|
|
1640
1760
|
method: "POST",
|
|
1641
|
-
body: singleStep,
|
|
1761
|
+
body: JSON.stringify(singleStep),
|
|
1642
1762
|
url: this.context.url,
|
|
1643
1763
|
notBefore: willWait ? singleStep.sleepUntil : void 0,
|
|
1644
1764
|
delay: willWait ? singleStep.sleepFor : void 0
|
|
@@ -1646,8 +1766,9 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1646
1766
|
);
|
|
1647
1767
|
})
|
|
1648
1768
|
);
|
|
1769
|
+
const _result = result;
|
|
1649
1770
|
await this.debug?.log("INFO", "SUBMIT_STEP", {
|
|
1650
|
-
messageIds:
|
|
1771
|
+
messageIds: _result.map((message) => {
|
|
1651
1772
|
return {
|
|
1652
1773
|
message: message.messageId
|
|
1653
1774
|
};
|
|
@@ -1850,6 +1971,9 @@ var WorkflowApi = class extends BaseWorkflowApi {
|
|
|
1850
1971
|
}
|
|
1851
1972
|
};
|
|
1852
1973
|
|
|
1974
|
+
// src/agents/index.ts
|
|
1975
|
+
var import_openai3 = require("@ai-sdk/openai");
|
|
1976
|
+
|
|
1853
1977
|
// src/agents/adapters.ts
|
|
1854
1978
|
var import_openai2 = require("@ai-sdk/openai");
|
|
1855
1979
|
var import_ai = require("ai");
|
|
@@ -1869,46 +1993,49 @@ you need from that agent.
|
|
|
1869
1993
|
`;
|
|
1870
1994
|
|
|
1871
1995
|
// src/agents/adapters.ts
|
|
1872
|
-
var
|
|
1873
|
-
const
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
if (error instanceof Error && error.name === "WorkflowAbort") {
|
|
1905
|
-
throw error;
|
|
1906
|
-
} else {
|
|
1907
|
-
console.error("Error in fetch implementation:", error);
|
|
1908
|
-
throw error;
|
|
1909
|
-
}
|
|
1910
|
-
}
|
|
1996
|
+
var fetchWithContextCall = async (context, ...params) => {
|
|
1997
|
+
const [input, init] = params;
|
|
1998
|
+
try {
|
|
1999
|
+
const headers = init?.headers ? Object.fromEntries(new Headers(init.headers).entries()) : {};
|
|
2000
|
+
const body = init?.body ? JSON.parse(init.body) : void 0;
|
|
2001
|
+
const agentName = headers[AGENT_NAME_HEADER];
|
|
2002
|
+
const stepName = agentName ? `Call Agent ${agentName}` : "Call Agent";
|
|
2003
|
+
const responseInfo = await context.call(stepName, {
|
|
2004
|
+
url: input.toString(),
|
|
2005
|
+
method: init?.method,
|
|
2006
|
+
headers,
|
|
2007
|
+
body
|
|
2008
|
+
});
|
|
2009
|
+
const responseHeaders = new Headers(
|
|
2010
|
+
Object.entries(responseInfo.header).reduce(
|
|
2011
|
+
(acc, [key, values]) => {
|
|
2012
|
+
acc[key] = values.join(", ");
|
|
2013
|
+
return acc;
|
|
2014
|
+
},
|
|
2015
|
+
{}
|
|
2016
|
+
)
|
|
2017
|
+
);
|
|
2018
|
+
return new Response(JSON.stringify(responseInfo.body), {
|
|
2019
|
+
status: responseInfo.status,
|
|
2020
|
+
headers: responseHeaders
|
|
2021
|
+
});
|
|
2022
|
+
} catch (error) {
|
|
2023
|
+
if (error instanceof Error && error.name === "WorkflowAbort") {
|
|
2024
|
+
throw error;
|
|
2025
|
+
} else {
|
|
2026
|
+
console.error("Error in fetch implementation:", error);
|
|
2027
|
+
throw error;
|
|
1911
2028
|
}
|
|
2029
|
+
}
|
|
2030
|
+
};
|
|
2031
|
+
var createWorkflowModel = ({
|
|
2032
|
+
context,
|
|
2033
|
+
provider,
|
|
2034
|
+
providerParams
|
|
2035
|
+
}) => {
|
|
2036
|
+
return provider({
|
|
2037
|
+
fetch: (...params) => fetchWithContextCall(context, ...params),
|
|
2038
|
+
...providerParams
|
|
1912
2039
|
});
|
|
1913
2040
|
};
|
|
1914
2041
|
var wrapTools = ({
|
|
@@ -2148,9 +2275,14 @@ var WorkflowAgents = class {
|
|
|
2148
2275
|
openai(...params) {
|
|
2149
2276
|
const [model, settings] = params;
|
|
2150
2277
|
const { baseURL, apiKey, ...otherSettings } = settings ?? {};
|
|
2151
|
-
const
|
|
2152
|
-
|
|
2278
|
+
const openaiModel = this.AISDKModel({
|
|
2279
|
+
context: this.context,
|
|
2280
|
+
provider: import_openai3.createOpenAI,
|
|
2281
|
+
providerParams: { baseURL, apiKey, compatibility: "strict" }
|
|
2282
|
+
});
|
|
2283
|
+
return openaiModel(model, otherSettings);
|
|
2153
2284
|
}
|
|
2285
|
+
AISDKModel = createWorkflowModel;
|
|
2154
2286
|
};
|
|
2155
2287
|
|
|
2156
2288
|
// src/context/context.ts
|
|
@@ -2336,7 +2468,7 @@ var WorkflowContext = class {
|
|
|
2336
2468
|
*/
|
|
2337
2469
|
async run(stepName, stepFunction) {
|
|
2338
2470
|
const wrappedStepFunction = () => this.executor.wrapStep(stepName, stepFunction);
|
|
2339
|
-
return this.addStep(new LazyFunctionStep(stepName, wrappedStepFunction));
|
|
2471
|
+
return await this.addStep(new LazyFunctionStep(stepName, wrappedStepFunction));
|
|
2340
2472
|
}
|
|
2341
2473
|
/**
|
|
2342
2474
|
* Stops the execution for the duration provided.
|
|
@@ -2407,43 +2539,27 @@ var WorkflowContext = class {
|
|
|
2407
2539
|
* }
|
|
2408
2540
|
*/
|
|
2409
2541
|
async call(stepName, settings) {
|
|
2410
|
-
const {
|
|
2411
|
-
|
|
2542
|
+
const {
|
|
2543
|
+
url,
|
|
2544
|
+
method = "GET",
|
|
2545
|
+
body: requestBody,
|
|
2546
|
+
headers = {},
|
|
2547
|
+
retries = 0,
|
|
2548
|
+
timeout,
|
|
2549
|
+
flowControl
|
|
2550
|
+
} = settings;
|
|
2551
|
+
return await this.addStep(
|
|
2412
2552
|
new LazyCallStep(
|
|
2413
2553
|
stepName,
|
|
2414
2554
|
url,
|
|
2415
2555
|
method,
|
|
2416
|
-
|
|
2556
|
+
requestBody,
|
|
2417
2557
|
headers,
|
|
2418
2558
|
retries,
|
|
2419
2559
|
timeout,
|
|
2420
2560
|
flowControl
|
|
2421
2561
|
)
|
|
2422
2562
|
);
|
|
2423
|
-
if (typeof result === "string") {
|
|
2424
|
-
try {
|
|
2425
|
-
const body2 = JSON.parse(result);
|
|
2426
|
-
return {
|
|
2427
|
-
status: 200,
|
|
2428
|
-
header: {},
|
|
2429
|
-
body: body2
|
|
2430
|
-
};
|
|
2431
|
-
} catch {
|
|
2432
|
-
return {
|
|
2433
|
-
status: 200,
|
|
2434
|
-
header: {},
|
|
2435
|
-
body: result
|
|
2436
|
-
};
|
|
2437
|
-
}
|
|
2438
|
-
}
|
|
2439
|
-
try {
|
|
2440
|
-
return {
|
|
2441
|
-
...result,
|
|
2442
|
-
body: JSON.parse(result.body)
|
|
2443
|
-
};
|
|
2444
|
-
} catch {
|
|
2445
|
-
return result;
|
|
2446
|
-
}
|
|
2447
2563
|
}
|
|
2448
2564
|
/**
|
|
2449
2565
|
* Pauses workflow execution until a specific event occurs or a timeout is reached.
|
|
@@ -2482,15 +2598,7 @@ var WorkflowContext = class {
|
|
|
2482
2598
|
async waitForEvent(stepName, eventId, options = {}) {
|
|
2483
2599
|
const { timeout = "7d" } = options;
|
|
2484
2600
|
const timeoutStr = typeof timeout === "string" ? timeout : `${timeout}s`;
|
|
2485
|
-
|
|
2486
|
-
try {
|
|
2487
|
-
return {
|
|
2488
|
-
...result,
|
|
2489
|
-
eventData: JSON.parse(result.eventData)
|
|
2490
|
-
};
|
|
2491
|
-
} catch {
|
|
2492
|
-
return result;
|
|
2493
|
-
}
|
|
2601
|
+
return await this.addStep(new LazyWaitForEventStep(stepName, eventId, timeoutStr));
|
|
2494
2602
|
}
|
|
2495
2603
|
/**
|
|
2496
2604
|
* Notify workflow runs waiting for an event
|
|
@@ -2514,24 +2622,12 @@ var WorkflowContext = class {
|
|
|
2514
2622
|
* @returns notify response which has event id, event data and list of waiters which were notified
|
|
2515
2623
|
*/
|
|
2516
2624
|
async notify(stepName, eventId, eventData) {
|
|
2517
|
-
|
|
2625
|
+
return await this.addStep(
|
|
2518
2626
|
new LazyNotifyStep(stepName, eventId, eventData, this.qstashClient.http)
|
|
2519
2627
|
);
|
|
2520
|
-
try {
|
|
2521
|
-
return {
|
|
2522
|
-
...result,
|
|
2523
|
-
eventData: JSON.parse(result.eventData)
|
|
2524
|
-
};
|
|
2525
|
-
} catch {
|
|
2526
|
-
return result;
|
|
2527
|
-
}
|
|
2528
2628
|
}
|
|
2529
2629
|
async invoke(stepName, settings) {
|
|
2530
|
-
|
|
2531
|
-
return {
|
|
2532
|
-
...result,
|
|
2533
|
-
body: result.body ? JSON.parse(result.body) : void 0
|
|
2534
|
-
};
|
|
2630
|
+
return await this.addStep(new LazyInvokeStep(stepName, settings));
|
|
2535
2631
|
}
|
|
2536
2632
|
/**
|
|
2537
2633
|
* Cancel the current workflow run
|
|
@@ -2690,10 +2786,6 @@ var processRawSteps = (rawSteps) => {
|
|
|
2690
2786
|
const stepsToDecode = encodedSteps.filter((step) => step.callType === "step");
|
|
2691
2787
|
const otherSteps = stepsToDecode.map((rawStep) => {
|
|
2692
2788
|
const step = JSON.parse(decodeBase64(rawStep.body));
|
|
2693
|
-
try {
|
|
2694
|
-
step.out = JSON.parse(step.out);
|
|
2695
|
-
} catch {
|
|
2696
|
-
}
|
|
2697
2789
|
if (step.waitEventId) {
|
|
2698
2790
|
const newOut = {
|
|
2699
2791
|
eventData: step.out ? decodeBase64(step.out) : void 0,
|
|
@@ -2913,6 +3005,7 @@ var processOptions = (options) => {
|
|
|
2913
3005
|
retries: DEFAULT_RETRIES,
|
|
2914
3006
|
useJSONContent: false,
|
|
2915
3007
|
disableTelemetry: false,
|
|
3008
|
+
onError: console.error,
|
|
2916
3009
|
...options
|
|
2917
3010
|
};
|
|
2918
3011
|
};
|
|
@@ -2962,7 +3055,8 @@ var serveBase = (routeFunction, telemetry, options) => {
|
|
|
2962
3055
|
retries,
|
|
2963
3056
|
useJSONContent,
|
|
2964
3057
|
disableTelemetry,
|
|
2965
|
-
flowControl
|
|
3058
|
+
flowControl,
|
|
3059
|
+
onError
|
|
2966
3060
|
} = processOptions(options);
|
|
2967
3061
|
telemetry = disableTelemetry ? void 0 : telemetry;
|
|
2968
3062
|
const debug = WorkflowLogger.getLogger(verbose);
|
|
@@ -3091,8 +3185,19 @@ var serveBase = (routeFunction, telemetry, options) => {
|
|
|
3091
3185
|
try {
|
|
3092
3186
|
return await handler(request);
|
|
3093
3187
|
} catch (error) {
|
|
3094
|
-
|
|
3095
|
-
|
|
3188
|
+
const formattedError = formatWorkflowError(error);
|
|
3189
|
+
try {
|
|
3190
|
+
onError?.(error);
|
|
3191
|
+
} catch (onErrorError) {
|
|
3192
|
+
const formattedOnErrorError = formatWorkflowError(onErrorError);
|
|
3193
|
+
const errorMessage = `Error while running onError callback: '${formattedOnErrorError.message}'.
|
|
3194
|
+
Original error: '${formattedError.message}'`;
|
|
3195
|
+
console.error(errorMessage);
|
|
3196
|
+
return new Response(errorMessage, {
|
|
3197
|
+
status: 500
|
|
3198
|
+
});
|
|
3199
|
+
}
|
|
3200
|
+
return new Response(JSON.stringify(formattedError), {
|
|
3096
3201
|
status: 500
|
|
3097
3202
|
});
|
|
3098
3203
|
}
|
package/solidjs.mjs
CHANGED
package/svelte.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _sveltejs_kit from '@sveltejs/kit';
|
|
2
2
|
import { RequestHandler } from '@sveltejs/kit';
|
|
3
|
-
import { R as RouteFunction, k as PublicServeOptions, t as InvokableWorkflow } from './types-
|
|
4
|
-
import { s as serveManyBase } from './serve-many-
|
|
3
|
+
import { R as RouteFunction, k as PublicServeOptions, t as InvokableWorkflow } from './types-D1W0VOpy.mjs';
|
|
4
|
+
import { s as serveManyBase } from './serve-many-DLguU9iR.mjs';
|
|
5
5
|
import '@upstash/qstash';
|
|
6
6
|
import 'zod';
|
|
7
7
|
import 'ai';
|
package/svelte.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _sveltejs_kit from '@sveltejs/kit';
|
|
2
2
|
import { RequestHandler } from '@sveltejs/kit';
|
|
3
|
-
import { R as RouteFunction, k as PublicServeOptions, t as InvokableWorkflow } from './types-
|
|
4
|
-
import { s as serveManyBase } from './serve-many-
|
|
3
|
+
import { R as RouteFunction, k as PublicServeOptions, t as InvokableWorkflow } from './types-D1W0VOpy.js';
|
|
4
|
+
import { s as serveManyBase } from './serve-many-BdMq5rFX.js';
|
|
5
5
|
import '@upstash/qstash';
|
|
6
6
|
import 'zod';
|
|
7
7
|
import 'ai';
|