@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
|
@@ -85,7 +85,7 @@ var formatWorkflowError = (error) => {
|
|
|
85
85
|
message: error.message
|
|
86
86
|
} : {
|
|
87
87
|
error: "Error",
|
|
88
|
-
message:
|
|
88
|
+
message: `An error occured while executing workflow: '${typeof error === "string" ? error : JSON.stringify(error)}'`
|
|
89
89
|
};
|
|
90
90
|
};
|
|
91
91
|
|
|
@@ -114,15 +114,15 @@ function getWorkflowRunId(id) {
|
|
|
114
114
|
return `wfr_${id ?? nanoid()}`;
|
|
115
115
|
}
|
|
116
116
|
function decodeBase64(base64) {
|
|
117
|
+
const binString = atob(base64);
|
|
117
118
|
try {
|
|
118
|
-
const binString = atob(base64);
|
|
119
119
|
const intArray = Uint8Array.from(binString, (m) => m.codePointAt(0));
|
|
120
120
|
return new TextDecoder().decode(intArray);
|
|
121
121
|
} catch (error) {
|
|
122
122
|
console.warn(
|
|
123
123
|
`Upstash Qstash: Failed while decoding base64 "${base64}". Decoding with atob and returning it instead. ${error}`
|
|
124
124
|
);
|
|
125
|
-
return
|
|
125
|
+
return binString;
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
|
|
@@ -859,7 +859,8 @@ var getHeaders = ({
|
|
|
859
859
|
flowControl,
|
|
860
860
|
callFlowControl
|
|
861
861
|
}) => {
|
|
862
|
-
const
|
|
862
|
+
const callHeaders = new Headers(step?.callHeaders);
|
|
863
|
+
const contentType = (callHeaders.get("content-type") ? callHeaders.get("content-type") : userHeaders?.get("Content-Type") ? userHeaders.get("Content-Type") : void 0) ?? DEFAULT_CONTENT_TYPE;
|
|
863
864
|
const baseHeaders = {
|
|
864
865
|
[WORKFLOW_INIT_HEADER]: initHeaderValue,
|
|
865
866
|
[WORKFLOW_ID_HEADER]: workflowRunId,
|
|
@@ -1184,46 +1185,49 @@ you need from that agent.
|
|
|
1184
1185
|
`;
|
|
1185
1186
|
|
|
1186
1187
|
// src/agents/adapters.ts
|
|
1187
|
-
var
|
|
1188
|
-
const
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
if (error instanceof Error && error.name === "WorkflowAbort") {
|
|
1220
|
-
throw error;
|
|
1221
|
-
} else {
|
|
1222
|
-
console.error("Error in fetch implementation:", error);
|
|
1223
|
-
throw error;
|
|
1224
|
-
}
|
|
1225
|
-
}
|
|
1188
|
+
var fetchWithContextCall = async (context, ...params) => {
|
|
1189
|
+
const [input, init] = params;
|
|
1190
|
+
try {
|
|
1191
|
+
const headers = init?.headers ? Object.fromEntries(new Headers(init.headers).entries()) : {};
|
|
1192
|
+
const body = init?.body ? JSON.parse(init.body) : void 0;
|
|
1193
|
+
const agentName = headers[AGENT_NAME_HEADER];
|
|
1194
|
+
const stepName = agentName ? `Call Agent ${agentName}` : "Call Agent";
|
|
1195
|
+
const responseInfo = await context.call(stepName, {
|
|
1196
|
+
url: input.toString(),
|
|
1197
|
+
method: init?.method,
|
|
1198
|
+
headers,
|
|
1199
|
+
body
|
|
1200
|
+
});
|
|
1201
|
+
const responseHeaders = new Headers(
|
|
1202
|
+
Object.entries(responseInfo.header).reduce(
|
|
1203
|
+
(acc, [key, values]) => {
|
|
1204
|
+
acc[key] = values.join(", ");
|
|
1205
|
+
return acc;
|
|
1206
|
+
},
|
|
1207
|
+
{}
|
|
1208
|
+
)
|
|
1209
|
+
);
|
|
1210
|
+
return new Response(JSON.stringify(responseInfo.body), {
|
|
1211
|
+
status: responseInfo.status,
|
|
1212
|
+
headers: responseHeaders
|
|
1213
|
+
});
|
|
1214
|
+
} catch (error) {
|
|
1215
|
+
if (error instanceof Error && error.name === "WorkflowAbort") {
|
|
1216
|
+
throw error;
|
|
1217
|
+
} else {
|
|
1218
|
+
console.error("Error in fetch implementation:", error);
|
|
1219
|
+
throw error;
|
|
1226
1220
|
}
|
|
1221
|
+
}
|
|
1222
|
+
};
|
|
1223
|
+
var createWorkflowModel = ({
|
|
1224
|
+
context,
|
|
1225
|
+
provider,
|
|
1226
|
+
providerParams
|
|
1227
|
+
}) => {
|
|
1228
|
+
return provider({
|
|
1229
|
+
fetch: (...params) => fetchWithContextCall(context, ...params),
|
|
1230
|
+
...providerParams
|
|
1227
1231
|
});
|
|
1228
1232
|
};
|
|
1229
1233
|
var wrapTools = ({
|
|
@@ -1290,9 +1294,8 @@ var WorkflowTool = class {
|
|
|
1290
1294
|
};
|
|
1291
1295
|
|
|
1292
1296
|
// src/context/steps.ts
|
|
1293
|
-
var BaseLazyStep = class {
|
|
1297
|
+
var BaseLazyStep = class _BaseLazyStep {
|
|
1294
1298
|
stepName;
|
|
1295
|
-
// will be set in the subclasses
|
|
1296
1299
|
constructor(stepName) {
|
|
1297
1300
|
if (!stepName) {
|
|
1298
1301
|
throw new WorkflowError(
|
|
@@ -1301,10 +1304,58 @@ var BaseLazyStep = class {
|
|
|
1301
1304
|
}
|
|
1302
1305
|
this.stepName = stepName;
|
|
1303
1306
|
}
|
|
1307
|
+
/**
|
|
1308
|
+
* parse the out field of a step result.
|
|
1309
|
+
*
|
|
1310
|
+
* will be called when returning the steps to the context from auto executor
|
|
1311
|
+
*
|
|
1312
|
+
* @param out field of the step
|
|
1313
|
+
* @returns parsed out field
|
|
1314
|
+
*/
|
|
1315
|
+
parseOut(out) {
|
|
1316
|
+
if (out === void 0) {
|
|
1317
|
+
if (this.allowUndefinedOut) {
|
|
1318
|
+
return void 0;
|
|
1319
|
+
} else {
|
|
1320
|
+
throw new WorkflowError(
|
|
1321
|
+
`Error while parsing output of ${this.stepType} step. Expected a string, but got: undefined`
|
|
1322
|
+
);
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
if (typeof out === "object") {
|
|
1326
|
+
if (this.stepType !== "Wait") {
|
|
1327
|
+
console.warn(
|
|
1328
|
+
`Error while parsing ${this.stepType} step output. Expected a string, but got object. Please reach out to Upstash Support.`
|
|
1329
|
+
);
|
|
1330
|
+
return out;
|
|
1331
|
+
}
|
|
1332
|
+
return {
|
|
1333
|
+
...out,
|
|
1334
|
+
eventData: _BaseLazyStep.tryParsing(out.eventData)
|
|
1335
|
+
};
|
|
1336
|
+
}
|
|
1337
|
+
if (typeof out !== "string") {
|
|
1338
|
+
throw new WorkflowError(
|
|
1339
|
+
`Error while parsing output of ${this.stepType} step. Expected a string or undefined, but got: ${typeof out}`
|
|
1340
|
+
);
|
|
1341
|
+
}
|
|
1342
|
+
return this.safeParseOut(out);
|
|
1343
|
+
}
|
|
1344
|
+
safeParseOut(out) {
|
|
1345
|
+
return _BaseLazyStep.tryParsing(out);
|
|
1346
|
+
}
|
|
1347
|
+
static tryParsing(stepOut) {
|
|
1348
|
+
try {
|
|
1349
|
+
return JSON.parse(stepOut);
|
|
1350
|
+
} catch {
|
|
1351
|
+
return stepOut;
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1304
1354
|
};
|
|
1305
1355
|
var LazyFunctionStep = class extends BaseLazyStep {
|
|
1306
1356
|
stepFunction;
|
|
1307
1357
|
stepType = "Run";
|
|
1358
|
+
allowUndefinedOut = true;
|
|
1308
1359
|
constructor(stepName, stepFunction) {
|
|
1309
1360
|
super(stepName);
|
|
1310
1361
|
this.stepFunction = stepFunction;
|
|
@@ -1335,6 +1386,7 @@ var LazyFunctionStep = class extends BaseLazyStep {
|
|
|
1335
1386
|
var LazySleepStep = class extends BaseLazyStep {
|
|
1336
1387
|
sleep;
|
|
1337
1388
|
stepType = "SleepFor";
|
|
1389
|
+
allowUndefinedOut = true;
|
|
1338
1390
|
constructor(stepName, sleep) {
|
|
1339
1391
|
super(stepName);
|
|
1340
1392
|
this.sleep = sleep;
|
|
@@ -1362,6 +1414,7 @@ var LazySleepStep = class extends BaseLazyStep {
|
|
|
1362
1414
|
var LazySleepUntilStep = class extends BaseLazyStep {
|
|
1363
1415
|
sleepUntil;
|
|
1364
1416
|
stepType = "SleepUntil";
|
|
1417
|
+
allowUndefinedOut = true;
|
|
1365
1418
|
constructor(stepName, sleepUntil) {
|
|
1366
1419
|
super(stepName);
|
|
1367
1420
|
this.sleepUntil = sleepUntil;
|
|
@@ -1385,8 +1438,11 @@ var LazySleepUntilStep = class extends BaseLazyStep {
|
|
|
1385
1438
|
concurrent
|
|
1386
1439
|
});
|
|
1387
1440
|
}
|
|
1441
|
+
safeParseOut() {
|
|
1442
|
+
return void 0;
|
|
1443
|
+
}
|
|
1388
1444
|
};
|
|
1389
|
-
var LazyCallStep = class extends BaseLazyStep {
|
|
1445
|
+
var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
|
|
1390
1446
|
url;
|
|
1391
1447
|
method;
|
|
1392
1448
|
body;
|
|
@@ -1395,6 +1451,7 @@ var LazyCallStep = class extends BaseLazyStep {
|
|
|
1395
1451
|
timeout;
|
|
1396
1452
|
flowControl;
|
|
1397
1453
|
stepType = "Call";
|
|
1454
|
+
allowUndefinedOut = false;
|
|
1398
1455
|
constructor(stepName, url, method, body, headers, retries, timeout, flowControl) {
|
|
1399
1456
|
super(stepName);
|
|
1400
1457
|
this.url = url;
|
|
@@ -1426,11 +1483,53 @@ var LazyCallStep = class extends BaseLazyStep {
|
|
|
1426
1483
|
callHeaders: this.headers
|
|
1427
1484
|
});
|
|
1428
1485
|
}
|
|
1486
|
+
safeParseOut(out) {
|
|
1487
|
+
const { header, status, body } = JSON.parse(out);
|
|
1488
|
+
const responseHeaders = new Headers(header);
|
|
1489
|
+
if (_LazyCallStep.isText(responseHeaders.get("content-type"))) {
|
|
1490
|
+
const bytes = new Uint8Array(out.length);
|
|
1491
|
+
for (let i = 0; i < out.length; i++) {
|
|
1492
|
+
bytes[i] = out.charCodeAt(i);
|
|
1493
|
+
}
|
|
1494
|
+
const processedResult = new TextDecoder().decode(bytes);
|
|
1495
|
+
const newBody = JSON.parse(processedResult).body;
|
|
1496
|
+
return {
|
|
1497
|
+
status,
|
|
1498
|
+
header,
|
|
1499
|
+
body: BaseLazyStep.tryParsing(newBody)
|
|
1500
|
+
};
|
|
1501
|
+
} else {
|
|
1502
|
+
return { header, status, body };
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
static applicationHeaders = /* @__PURE__ */ new Set([
|
|
1506
|
+
"application/json",
|
|
1507
|
+
"application/xml",
|
|
1508
|
+
"application/javascript",
|
|
1509
|
+
"application/x-www-form-urlencoded",
|
|
1510
|
+
"application/xhtml+xml",
|
|
1511
|
+
"application/ld+json",
|
|
1512
|
+
"application/rss+xml",
|
|
1513
|
+
"application/atom+xml"
|
|
1514
|
+
]);
|
|
1515
|
+
static isText = (contentTypeHeader) => {
|
|
1516
|
+
if (!contentTypeHeader) {
|
|
1517
|
+
return false;
|
|
1518
|
+
}
|
|
1519
|
+
if (_LazyCallStep.applicationHeaders.has(contentTypeHeader)) {
|
|
1520
|
+
return true;
|
|
1521
|
+
}
|
|
1522
|
+
if (contentTypeHeader.startsWith("text/")) {
|
|
1523
|
+
return true;
|
|
1524
|
+
}
|
|
1525
|
+
return false;
|
|
1526
|
+
};
|
|
1429
1527
|
};
|
|
1430
1528
|
var LazyWaitForEventStep = class extends BaseLazyStep {
|
|
1431
1529
|
eventId;
|
|
1432
1530
|
timeout;
|
|
1433
1531
|
stepType = "Wait";
|
|
1532
|
+
allowUndefinedOut = false;
|
|
1434
1533
|
constructor(stepName, eventId, timeout) {
|
|
1435
1534
|
super(stepName);
|
|
1436
1535
|
this.eventId = eventId;
|
|
@@ -1457,6 +1556,13 @@ var LazyWaitForEventStep = class extends BaseLazyStep {
|
|
|
1457
1556
|
concurrent
|
|
1458
1557
|
});
|
|
1459
1558
|
}
|
|
1559
|
+
safeParseOut(out) {
|
|
1560
|
+
const result = JSON.parse(out);
|
|
1561
|
+
return {
|
|
1562
|
+
...result,
|
|
1563
|
+
eventData: BaseLazyStep.tryParsing(result.eventData)
|
|
1564
|
+
};
|
|
1565
|
+
}
|
|
1460
1566
|
};
|
|
1461
1567
|
var LazyNotifyStep = class extends LazyFunctionStep {
|
|
1462
1568
|
stepType = "Notify";
|
|
@@ -1470,10 +1576,18 @@ var LazyNotifyStep = class extends LazyFunctionStep {
|
|
|
1470
1576
|
};
|
|
1471
1577
|
});
|
|
1472
1578
|
}
|
|
1579
|
+
safeParseOut(out) {
|
|
1580
|
+
const result = JSON.parse(out);
|
|
1581
|
+
return {
|
|
1582
|
+
...result,
|
|
1583
|
+
eventData: BaseLazyStep.tryParsing(result.eventData)
|
|
1584
|
+
};
|
|
1585
|
+
}
|
|
1473
1586
|
};
|
|
1474
1587
|
var LazyInvokeStep = class extends BaseLazyStep {
|
|
1475
1588
|
stepType = "Invoke";
|
|
1476
1589
|
params;
|
|
1590
|
+
allowUndefinedOut = false;
|
|
1477
1591
|
constructor(stepName, {
|
|
1478
1592
|
workflow,
|
|
1479
1593
|
body,
|
|
@@ -1513,6 +1627,13 @@ var LazyInvokeStep = class extends BaseLazyStep {
|
|
|
1513
1627
|
concurrent
|
|
1514
1628
|
});
|
|
1515
1629
|
}
|
|
1630
|
+
safeParseOut(out) {
|
|
1631
|
+
const result = JSON.parse(out);
|
|
1632
|
+
return {
|
|
1633
|
+
...result,
|
|
1634
|
+
body: BaseLazyStep.tryParsing(result.body)
|
|
1635
|
+
};
|
|
1636
|
+
}
|
|
1516
1637
|
};
|
|
1517
1638
|
|
|
1518
1639
|
// src/context/auto-executor.ts
|
|
@@ -1618,7 +1739,7 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1618
1739
|
step,
|
|
1619
1740
|
stepCount: this.stepCount
|
|
1620
1741
|
});
|
|
1621
|
-
return step.out;
|
|
1742
|
+
return lazyStep.parseOut(step.out);
|
|
1622
1743
|
}
|
|
1623
1744
|
const resultStep = await lazyStep.getResultStep(NO_CONCURRENCY, this.stepCount);
|
|
1624
1745
|
await this.debug?.log("INFO", "RUN_SINGLE", {
|
|
@@ -1693,7 +1814,9 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1693
1814
|
case "last": {
|
|
1694
1815
|
const parallelResultSteps = sortedSteps.filter((step) => step.stepId >= initialStepCount).slice(0, parallelSteps.length);
|
|
1695
1816
|
validateParallelSteps(parallelSteps, parallelResultSteps);
|
|
1696
|
-
return parallelResultSteps.map(
|
|
1817
|
+
return parallelResultSteps.map(
|
|
1818
|
+
(step, index) => parallelSteps[index].parseOut(step.out)
|
|
1819
|
+
);
|
|
1697
1820
|
}
|
|
1698
1821
|
}
|
|
1699
1822
|
const fillValue = void 0;
|
|
@@ -1796,7 +1919,7 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1796
1919
|
});
|
|
1797
1920
|
throw new WorkflowAbort(invokeStep.stepName, invokeStep);
|
|
1798
1921
|
}
|
|
1799
|
-
const result = await this.context.qstashClient.
|
|
1922
|
+
const result = await this.context.qstashClient.batch(
|
|
1800
1923
|
steps.map((singleStep, index) => {
|
|
1801
1924
|
const lazyStep = lazySteps[index];
|
|
1802
1925
|
const { headers } = getHeaders({
|
|
@@ -1826,7 +1949,7 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1826
1949
|
{
|
|
1827
1950
|
headers,
|
|
1828
1951
|
method: singleStep.callMethod,
|
|
1829
|
-
body: singleStep.callBody,
|
|
1952
|
+
body: JSON.stringify(singleStep.callBody),
|
|
1830
1953
|
url: singleStep.callUrl
|
|
1831
1954
|
}
|
|
1832
1955
|
) : (
|
|
@@ -1836,7 +1959,7 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1836
1959
|
{
|
|
1837
1960
|
headers,
|
|
1838
1961
|
method: "POST",
|
|
1839
|
-
body: singleStep,
|
|
1962
|
+
body: JSON.stringify(singleStep),
|
|
1840
1963
|
url: this.context.url,
|
|
1841
1964
|
notBefore: willWait ? singleStep.sleepUntil : void 0,
|
|
1842
1965
|
delay: willWait ? singleStep.sleepFor : void 0
|
|
@@ -1844,8 +1967,9 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1844
1967
|
);
|
|
1845
1968
|
})
|
|
1846
1969
|
);
|
|
1970
|
+
const _result = result;
|
|
1847
1971
|
await this.debug?.log("INFO", "SUBMIT_STEP", {
|
|
1848
|
-
messageIds:
|
|
1972
|
+
messageIds: _result.map((message) => {
|
|
1849
1973
|
return {
|
|
1850
1974
|
message: message.messageId
|
|
1851
1975
|
};
|
|
@@ -2048,6 +2172,9 @@ var WorkflowApi = class extends BaseWorkflowApi {
|
|
|
2048
2172
|
}
|
|
2049
2173
|
};
|
|
2050
2174
|
|
|
2175
|
+
// src/agents/index.ts
|
|
2176
|
+
import { createOpenAI as createOpenAI2 } from "@ai-sdk/openai";
|
|
2177
|
+
|
|
2051
2178
|
// src/agents/agent.ts
|
|
2052
2179
|
import { z } from "zod";
|
|
2053
2180
|
import { generateText, tool as tool2, ToolExecutionError } from "ai";
|
|
@@ -2253,9 +2380,14 @@ var WorkflowAgents = class {
|
|
|
2253
2380
|
openai(...params) {
|
|
2254
2381
|
const [model, settings] = params;
|
|
2255
2382
|
const { baseURL, apiKey, ...otherSettings } = settings ?? {};
|
|
2256
|
-
const
|
|
2257
|
-
|
|
2383
|
+
const openaiModel = this.AISDKModel({
|
|
2384
|
+
context: this.context,
|
|
2385
|
+
provider: createOpenAI2,
|
|
2386
|
+
providerParams: { baseURL, apiKey, compatibility: "strict" }
|
|
2387
|
+
});
|
|
2388
|
+
return openaiModel(model, otherSettings);
|
|
2258
2389
|
}
|
|
2390
|
+
AISDKModel = createWorkflowModel;
|
|
2259
2391
|
};
|
|
2260
2392
|
|
|
2261
2393
|
// src/context/context.ts
|
|
@@ -2441,7 +2573,7 @@ var WorkflowContext = class {
|
|
|
2441
2573
|
*/
|
|
2442
2574
|
async run(stepName, stepFunction) {
|
|
2443
2575
|
const wrappedStepFunction = () => this.executor.wrapStep(stepName, stepFunction);
|
|
2444
|
-
return this.addStep(new LazyFunctionStep(stepName, wrappedStepFunction));
|
|
2576
|
+
return await this.addStep(new LazyFunctionStep(stepName, wrappedStepFunction));
|
|
2445
2577
|
}
|
|
2446
2578
|
/**
|
|
2447
2579
|
* Stops the execution for the duration provided.
|
|
@@ -2512,43 +2644,27 @@ var WorkflowContext = class {
|
|
|
2512
2644
|
* }
|
|
2513
2645
|
*/
|
|
2514
2646
|
async call(stepName, settings) {
|
|
2515
|
-
const {
|
|
2516
|
-
|
|
2647
|
+
const {
|
|
2648
|
+
url,
|
|
2649
|
+
method = "GET",
|
|
2650
|
+
body: requestBody,
|
|
2651
|
+
headers = {},
|
|
2652
|
+
retries = 0,
|
|
2653
|
+
timeout,
|
|
2654
|
+
flowControl
|
|
2655
|
+
} = settings;
|
|
2656
|
+
return await this.addStep(
|
|
2517
2657
|
new LazyCallStep(
|
|
2518
2658
|
stepName,
|
|
2519
2659
|
url,
|
|
2520
2660
|
method,
|
|
2521
|
-
|
|
2661
|
+
requestBody,
|
|
2522
2662
|
headers,
|
|
2523
2663
|
retries,
|
|
2524
2664
|
timeout,
|
|
2525
2665
|
flowControl
|
|
2526
2666
|
)
|
|
2527
2667
|
);
|
|
2528
|
-
if (typeof result === "string") {
|
|
2529
|
-
try {
|
|
2530
|
-
const body2 = JSON.parse(result);
|
|
2531
|
-
return {
|
|
2532
|
-
status: 200,
|
|
2533
|
-
header: {},
|
|
2534
|
-
body: body2
|
|
2535
|
-
};
|
|
2536
|
-
} catch {
|
|
2537
|
-
return {
|
|
2538
|
-
status: 200,
|
|
2539
|
-
header: {},
|
|
2540
|
-
body: result
|
|
2541
|
-
};
|
|
2542
|
-
}
|
|
2543
|
-
}
|
|
2544
|
-
try {
|
|
2545
|
-
return {
|
|
2546
|
-
...result,
|
|
2547
|
-
body: JSON.parse(result.body)
|
|
2548
|
-
};
|
|
2549
|
-
} catch {
|
|
2550
|
-
return result;
|
|
2551
|
-
}
|
|
2552
2668
|
}
|
|
2553
2669
|
/**
|
|
2554
2670
|
* Pauses workflow execution until a specific event occurs or a timeout is reached.
|
|
@@ -2587,15 +2703,7 @@ var WorkflowContext = class {
|
|
|
2587
2703
|
async waitForEvent(stepName, eventId, options = {}) {
|
|
2588
2704
|
const { timeout = "7d" } = options;
|
|
2589
2705
|
const timeoutStr = typeof timeout === "string" ? timeout : `${timeout}s`;
|
|
2590
|
-
|
|
2591
|
-
try {
|
|
2592
|
-
return {
|
|
2593
|
-
...result,
|
|
2594
|
-
eventData: JSON.parse(result.eventData)
|
|
2595
|
-
};
|
|
2596
|
-
} catch {
|
|
2597
|
-
return result;
|
|
2598
|
-
}
|
|
2706
|
+
return await this.addStep(new LazyWaitForEventStep(stepName, eventId, timeoutStr));
|
|
2599
2707
|
}
|
|
2600
2708
|
/**
|
|
2601
2709
|
* Notify workflow runs waiting for an event
|
|
@@ -2619,24 +2727,12 @@ var WorkflowContext = class {
|
|
|
2619
2727
|
* @returns notify response which has event id, event data and list of waiters which were notified
|
|
2620
2728
|
*/
|
|
2621
2729
|
async notify(stepName, eventId, eventData) {
|
|
2622
|
-
|
|
2730
|
+
return await this.addStep(
|
|
2623
2731
|
new LazyNotifyStep(stepName, eventId, eventData, this.qstashClient.http)
|
|
2624
2732
|
);
|
|
2625
|
-
try {
|
|
2626
|
-
return {
|
|
2627
|
-
...result,
|
|
2628
|
-
eventData: JSON.parse(result.eventData)
|
|
2629
|
-
};
|
|
2630
|
-
} catch {
|
|
2631
|
-
return result;
|
|
2632
|
-
}
|
|
2633
2733
|
}
|
|
2634
2734
|
async invoke(stepName, settings) {
|
|
2635
|
-
|
|
2636
|
-
return {
|
|
2637
|
-
...result,
|
|
2638
|
-
body: result.body ? JSON.parse(result.body) : void 0
|
|
2639
|
-
};
|
|
2735
|
+
return await this.addStep(new LazyInvokeStep(stepName, settings));
|
|
2640
2736
|
}
|
|
2641
2737
|
/**
|
|
2642
2738
|
* Cancel the current workflow run
|
|
@@ -2795,10 +2891,6 @@ var processRawSteps = (rawSteps) => {
|
|
|
2795
2891
|
const stepsToDecode = encodedSteps.filter((step) => step.callType === "step");
|
|
2796
2892
|
const otherSteps = stepsToDecode.map((rawStep) => {
|
|
2797
2893
|
const step = JSON.parse(decodeBase64(rawStep.body));
|
|
2798
|
-
try {
|
|
2799
|
-
step.out = JSON.parse(step.out);
|
|
2800
|
-
} catch {
|
|
2801
|
-
}
|
|
2802
2894
|
if (step.waitEventId) {
|
|
2803
2895
|
const newOut = {
|
|
2804
2896
|
eventData: step.out ? decodeBase64(step.out) : void 0,
|
|
@@ -3018,6 +3110,7 @@ var processOptions = (options) => {
|
|
|
3018
3110
|
retries: DEFAULT_RETRIES,
|
|
3019
3111
|
useJSONContent: false,
|
|
3020
3112
|
disableTelemetry: false,
|
|
3113
|
+
onError: console.error,
|
|
3021
3114
|
...options
|
|
3022
3115
|
};
|
|
3023
3116
|
};
|
|
@@ -3067,7 +3160,8 @@ var serveBase = (routeFunction, telemetry, options) => {
|
|
|
3067
3160
|
retries,
|
|
3068
3161
|
useJSONContent,
|
|
3069
3162
|
disableTelemetry,
|
|
3070
|
-
flowControl
|
|
3163
|
+
flowControl,
|
|
3164
|
+
onError
|
|
3071
3165
|
} = processOptions(options);
|
|
3072
3166
|
telemetry = disableTelemetry ? void 0 : telemetry;
|
|
3073
3167
|
const debug = WorkflowLogger.getLogger(verbose);
|
|
@@ -3196,8 +3290,19 @@ var serveBase = (routeFunction, telemetry, options) => {
|
|
|
3196
3290
|
try {
|
|
3197
3291
|
return await handler(request);
|
|
3198
3292
|
} catch (error) {
|
|
3199
|
-
|
|
3200
|
-
|
|
3293
|
+
const formattedError = formatWorkflowError(error);
|
|
3294
|
+
try {
|
|
3295
|
+
onError?.(error);
|
|
3296
|
+
} catch (onErrorError) {
|
|
3297
|
+
const formattedOnErrorError = formatWorkflowError(onErrorError);
|
|
3298
|
+
const errorMessage = `Error while running onError callback: '${formattedOnErrorError.message}'.
|
|
3299
|
+
Original error: '${formattedError.message}'`;
|
|
3300
|
+
console.error(errorMessage);
|
|
3301
|
+
return new Response(errorMessage, {
|
|
3302
|
+
status: 500
|
|
3303
|
+
});
|
|
3304
|
+
}
|
|
3305
|
+
return new Response(JSON.stringify(formattedError), {
|
|
3201
3306
|
status: 500
|
|
3202
3307
|
});
|
|
3203
3308
|
}
|
package/cloudflare.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { R as RouteFunction, k as PublicServeOptions, t as InvokableWorkflow } from './types-
|
|
2
|
-
import { s as serveManyBase } from './serve-many-
|
|
1
|
+
import { R as RouteFunction, k as PublicServeOptions, t as InvokableWorkflow } from './types-D1W0VOpy.mjs';
|
|
2
|
+
import { s as serveManyBase } from './serve-many-DLguU9iR.mjs';
|
|
3
3
|
import '@upstash/qstash';
|
|
4
4
|
import 'zod';
|
|
5
5
|
import 'ai';
|
package/cloudflare.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { R as RouteFunction, k as PublicServeOptions, t as InvokableWorkflow } from './types-
|
|
2
|
-
import { s as serveManyBase } from './serve-many-
|
|
1
|
+
import { R as RouteFunction, k as PublicServeOptions, t as InvokableWorkflow } from './types-D1W0VOpy.js';
|
|
2
|
+
import { s as serveManyBase } from './serve-many-BdMq5rFX.js';
|
|
3
3
|
import '@upstash/qstash';
|
|
4
4
|
import 'zod';
|
|
5
5
|
import 'ai';
|