@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/express.js
CHANGED
|
@@ -23806,7 +23806,7 @@ var formatWorkflowError = (error) => {
|
|
|
23806
23806
|
message: error.message
|
|
23807
23807
|
} : {
|
|
23808
23808
|
error: "Error",
|
|
23809
|
-
message:
|
|
23809
|
+
message: `An error occured while executing workflow: '${typeof error === "string" ? error : JSON.stringify(error)}'`
|
|
23810
23810
|
};
|
|
23811
23811
|
};
|
|
23812
23812
|
|
|
@@ -23823,22 +23823,21 @@ function getWorkflowRunId(id) {
|
|
|
23823
23823
|
return `wfr_${id ?? nanoid()}`;
|
|
23824
23824
|
}
|
|
23825
23825
|
function decodeBase64(base64) {
|
|
23826
|
+
const binString = atob(base64);
|
|
23826
23827
|
try {
|
|
23827
|
-
const binString = atob(base64);
|
|
23828
23828
|
const intArray = Uint8Array.from(binString, (m) => m.codePointAt(0));
|
|
23829
23829
|
return new TextDecoder().decode(intArray);
|
|
23830
23830
|
} catch (error) {
|
|
23831
23831
|
console.warn(
|
|
23832
23832
|
`Upstash Qstash: Failed while decoding base64 "${base64}". Decoding with atob and returning it instead. ${error}`
|
|
23833
23833
|
);
|
|
23834
|
-
return
|
|
23834
|
+
return binString;
|
|
23835
23835
|
}
|
|
23836
23836
|
}
|
|
23837
23837
|
|
|
23838
23838
|
// src/context/steps.ts
|
|
23839
|
-
var BaseLazyStep = class {
|
|
23839
|
+
var BaseLazyStep = class _BaseLazyStep {
|
|
23840
23840
|
stepName;
|
|
23841
|
-
// will be set in the subclasses
|
|
23842
23841
|
constructor(stepName) {
|
|
23843
23842
|
if (!stepName) {
|
|
23844
23843
|
throw new WorkflowError(
|
|
@@ -23847,10 +23846,58 @@ var BaseLazyStep = class {
|
|
|
23847
23846
|
}
|
|
23848
23847
|
this.stepName = stepName;
|
|
23849
23848
|
}
|
|
23849
|
+
/**
|
|
23850
|
+
* parse the out field of a step result.
|
|
23851
|
+
*
|
|
23852
|
+
* will be called when returning the steps to the context from auto executor
|
|
23853
|
+
*
|
|
23854
|
+
* @param out field of the step
|
|
23855
|
+
* @returns parsed out field
|
|
23856
|
+
*/
|
|
23857
|
+
parseOut(out) {
|
|
23858
|
+
if (out === void 0) {
|
|
23859
|
+
if (this.allowUndefinedOut) {
|
|
23860
|
+
return void 0;
|
|
23861
|
+
} else {
|
|
23862
|
+
throw new WorkflowError(
|
|
23863
|
+
`Error while parsing output of ${this.stepType} step. Expected a string, but got: undefined`
|
|
23864
|
+
);
|
|
23865
|
+
}
|
|
23866
|
+
}
|
|
23867
|
+
if (typeof out === "object") {
|
|
23868
|
+
if (this.stepType !== "Wait") {
|
|
23869
|
+
console.warn(
|
|
23870
|
+
`Error while parsing ${this.stepType} step output. Expected a string, but got object. Please reach out to Upstash Support.`
|
|
23871
|
+
);
|
|
23872
|
+
return out;
|
|
23873
|
+
}
|
|
23874
|
+
return {
|
|
23875
|
+
...out,
|
|
23876
|
+
eventData: _BaseLazyStep.tryParsing(out.eventData)
|
|
23877
|
+
};
|
|
23878
|
+
}
|
|
23879
|
+
if (typeof out !== "string") {
|
|
23880
|
+
throw new WorkflowError(
|
|
23881
|
+
`Error while parsing output of ${this.stepType} step. Expected a string or undefined, but got: ${typeof out}`
|
|
23882
|
+
);
|
|
23883
|
+
}
|
|
23884
|
+
return this.safeParseOut(out);
|
|
23885
|
+
}
|
|
23886
|
+
safeParseOut(out) {
|
|
23887
|
+
return _BaseLazyStep.tryParsing(out);
|
|
23888
|
+
}
|
|
23889
|
+
static tryParsing(stepOut) {
|
|
23890
|
+
try {
|
|
23891
|
+
return JSON.parse(stepOut);
|
|
23892
|
+
} catch {
|
|
23893
|
+
return stepOut;
|
|
23894
|
+
}
|
|
23895
|
+
}
|
|
23850
23896
|
};
|
|
23851
23897
|
var LazyFunctionStep = class extends BaseLazyStep {
|
|
23852
23898
|
stepFunction;
|
|
23853
23899
|
stepType = "Run";
|
|
23900
|
+
allowUndefinedOut = true;
|
|
23854
23901
|
constructor(stepName, stepFunction) {
|
|
23855
23902
|
super(stepName);
|
|
23856
23903
|
this.stepFunction = stepFunction;
|
|
@@ -23881,6 +23928,7 @@ var LazyFunctionStep = class extends BaseLazyStep {
|
|
|
23881
23928
|
var LazySleepStep = class extends BaseLazyStep {
|
|
23882
23929
|
sleep;
|
|
23883
23930
|
stepType = "SleepFor";
|
|
23931
|
+
allowUndefinedOut = true;
|
|
23884
23932
|
constructor(stepName, sleep) {
|
|
23885
23933
|
super(stepName);
|
|
23886
23934
|
this.sleep = sleep;
|
|
@@ -23908,6 +23956,7 @@ var LazySleepStep = class extends BaseLazyStep {
|
|
|
23908
23956
|
var LazySleepUntilStep = class extends BaseLazyStep {
|
|
23909
23957
|
sleepUntil;
|
|
23910
23958
|
stepType = "SleepUntil";
|
|
23959
|
+
allowUndefinedOut = true;
|
|
23911
23960
|
constructor(stepName, sleepUntil) {
|
|
23912
23961
|
super(stepName);
|
|
23913
23962
|
this.sleepUntil = sleepUntil;
|
|
@@ -23931,8 +23980,11 @@ var LazySleepUntilStep = class extends BaseLazyStep {
|
|
|
23931
23980
|
concurrent
|
|
23932
23981
|
});
|
|
23933
23982
|
}
|
|
23983
|
+
safeParseOut() {
|
|
23984
|
+
return void 0;
|
|
23985
|
+
}
|
|
23934
23986
|
};
|
|
23935
|
-
var LazyCallStep = class extends BaseLazyStep {
|
|
23987
|
+
var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
|
|
23936
23988
|
url;
|
|
23937
23989
|
method;
|
|
23938
23990
|
body;
|
|
@@ -23941,6 +23993,7 @@ var LazyCallStep = class extends BaseLazyStep {
|
|
|
23941
23993
|
timeout;
|
|
23942
23994
|
flowControl;
|
|
23943
23995
|
stepType = "Call";
|
|
23996
|
+
allowUndefinedOut = false;
|
|
23944
23997
|
constructor(stepName, url, method, body, headers, retries, timeout, flowControl) {
|
|
23945
23998
|
super(stepName);
|
|
23946
23999
|
this.url = url;
|
|
@@ -23972,11 +24025,53 @@ var LazyCallStep = class extends BaseLazyStep {
|
|
|
23972
24025
|
callHeaders: this.headers
|
|
23973
24026
|
});
|
|
23974
24027
|
}
|
|
24028
|
+
safeParseOut(out) {
|
|
24029
|
+
const { header, status, body } = JSON.parse(out);
|
|
24030
|
+
const responseHeaders = new Headers(header);
|
|
24031
|
+
if (_LazyCallStep.isText(responseHeaders.get("content-type"))) {
|
|
24032
|
+
const bytes = new Uint8Array(out.length);
|
|
24033
|
+
for (let i = 0; i < out.length; i++) {
|
|
24034
|
+
bytes[i] = out.charCodeAt(i);
|
|
24035
|
+
}
|
|
24036
|
+
const processedResult = new TextDecoder().decode(bytes);
|
|
24037
|
+
const newBody = JSON.parse(processedResult).body;
|
|
24038
|
+
return {
|
|
24039
|
+
status,
|
|
24040
|
+
header,
|
|
24041
|
+
body: BaseLazyStep.tryParsing(newBody)
|
|
24042
|
+
};
|
|
24043
|
+
} else {
|
|
24044
|
+
return { header, status, body };
|
|
24045
|
+
}
|
|
24046
|
+
}
|
|
24047
|
+
static applicationHeaders = /* @__PURE__ */ new Set([
|
|
24048
|
+
"application/json",
|
|
24049
|
+
"application/xml",
|
|
24050
|
+
"application/javascript",
|
|
24051
|
+
"application/x-www-form-urlencoded",
|
|
24052
|
+
"application/xhtml+xml",
|
|
24053
|
+
"application/ld+json",
|
|
24054
|
+
"application/rss+xml",
|
|
24055
|
+
"application/atom+xml"
|
|
24056
|
+
]);
|
|
24057
|
+
static isText = (contentTypeHeader) => {
|
|
24058
|
+
if (!contentTypeHeader) {
|
|
24059
|
+
return false;
|
|
24060
|
+
}
|
|
24061
|
+
if (_LazyCallStep.applicationHeaders.has(contentTypeHeader)) {
|
|
24062
|
+
return true;
|
|
24063
|
+
}
|
|
24064
|
+
if (contentTypeHeader.startsWith("text/")) {
|
|
24065
|
+
return true;
|
|
24066
|
+
}
|
|
24067
|
+
return false;
|
|
24068
|
+
};
|
|
23975
24069
|
};
|
|
23976
24070
|
var LazyWaitForEventStep = class extends BaseLazyStep {
|
|
23977
24071
|
eventId;
|
|
23978
24072
|
timeout;
|
|
23979
24073
|
stepType = "Wait";
|
|
24074
|
+
allowUndefinedOut = false;
|
|
23980
24075
|
constructor(stepName, eventId, timeout) {
|
|
23981
24076
|
super(stepName);
|
|
23982
24077
|
this.eventId = eventId;
|
|
@@ -24003,6 +24098,13 @@ var LazyWaitForEventStep = class extends BaseLazyStep {
|
|
|
24003
24098
|
concurrent
|
|
24004
24099
|
});
|
|
24005
24100
|
}
|
|
24101
|
+
safeParseOut(out) {
|
|
24102
|
+
const result = JSON.parse(out);
|
|
24103
|
+
return {
|
|
24104
|
+
...result,
|
|
24105
|
+
eventData: BaseLazyStep.tryParsing(result.eventData)
|
|
24106
|
+
};
|
|
24107
|
+
}
|
|
24006
24108
|
};
|
|
24007
24109
|
var LazyNotifyStep = class extends LazyFunctionStep {
|
|
24008
24110
|
stepType = "Notify";
|
|
@@ -24016,10 +24118,18 @@ var LazyNotifyStep = class extends LazyFunctionStep {
|
|
|
24016
24118
|
};
|
|
24017
24119
|
});
|
|
24018
24120
|
}
|
|
24121
|
+
safeParseOut(out) {
|
|
24122
|
+
const result = JSON.parse(out);
|
|
24123
|
+
return {
|
|
24124
|
+
...result,
|
|
24125
|
+
eventData: BaseLazyStep.tryParsing(result.eventData)
|
|
24126
|
+
};
|
|
24127
|
+
}
|
|
24019
24128
|
};
|
|
24020
24129
|
var LazyInvokeStep = class extends BaseLazyStep {
|
|
24021
24130
|
stepType = "Invoke";
|
|
24022
24131
|
params;
|
|
24132
|
+
allowUndefinedOut = false;
|
|
24023
24133
|
constructor(stepName, {
|
|
24024
24134
|
workflow,
|
|
24025
24135
|
body,
|
|
@@ -24059,6 +24169,13 @@ var LazyInvokeStep = class extends BaseLazyStep {
|
|
|
24059
24169
|
concurrent
|
|
24060
24170
|
});
|
|
24061
24171
|
}
|
|
24172
|
+
safeParseOut(out) {
|
|
24173
|
+
const result = JSON.parse(out);
|
|
24174
|
+
return {
|
|
24175
|
+
...result,
|
|
24176
|
+
body: BaseLazyStep.tryParsing(result.body)
|
|
24177
|
+
};
|
|
24178
|
+
}
|
|
24062
24179
|
};
|
|
24063
24180
|
|
|
24064
24181
|
// node_modules/neverthrow/dist/index.es.js
|
|
@@ -24744,7 +24861,8 @@ var getHeaders = ({
|
|
|
24744
24861
|
flowControl,
|
|
24745
24862
|
callFlowControl
|
|
24746
24863
|
}) => {
|
|
24747
|
-
const
|
|
24864
|
+
const callHeaders = new Headers(step?.callHeaders);
|
|
24865
|
+
const contentType = (callHeaders.get("content-type") ? callHeaders.get("content-type") : userHeaders?.get("Content-Type") ? userHeaders.get("Content-Type") : void 0) ?? DEFAULT_CONTENT_TYPE;
|
|
24748
24866
|
const baseHeaders = {
|
|
24749
24867
|
[WORKFLOW_INIT_HEADER]: initHeaderValue,
|
|
24750
24868
|
[WORKFLOW_ID_HEADER]: workflowRunId,
|
|
@@ -25155,7 +25273,7 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
25155
25273
|
step,
|
|
25156
25274
|
stepCount: this.stepCount
|
|
25157
25275
|
});
|
|
25158
|
-
return step.out;
|
|
25276
|
+
return lazyStep.parseOut(step.out);
|
|
25159
25277
|
}
|
|
25160
25278
|
const resultStep = await lazyStep.getResultStep(NO_CONCURRENCY, this.stepCount);
|
|
25161
25279
|
await this.debug?.log("INFO", "RUN_SINGLE", {
|
|
@@ -25230,7 +25348,9 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
25230
25348
|
case "last": {
|
|
25231
25349
|
const parallelResultSteps = sortedSteps.filter((step) => step.stepId >= initialStepCount).slice(0, parallelSteps.length);
|
|
25232
25350
|
validateParallelSteps(parallelSteps, parallelResultSteps);
|
|
25233
|
-
return parallelResultSteps.map(
|
|
25351
|
+
return parallelResultSteps.map(
|
|
25352
|
+
(step, index) => parallelSteps[index].parseOut(step.out)
|
|
25353
|
+
);
|
|
25234
25354
|
}
|
|
25235
25355
|
}
|
|
25236
25356
|
const fillValue = void 0;
|
|
@@ -25333,7 +25453,7 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
25333
25453
|
});
|
|
25334
25454
|
throw new WorkflowAbort(invokeStep.stepName, invokeStep);
|
|
25335
25455
|
}
|
|
25336
|
-
const result = await this.context.qstashClient.
|
|
25456
|
+
const result = await this.context.qstashClient.batch(
|
|
25337
25457
|
steps.map((singleStep, index) => {
|
|
25338
25458
|
const lazyStep = lazySteps[index];
|
|
25339
25459
|
const { headers } = getHeaders({
|
|
@@ -25363,7 +25483,7 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
25363
25483
|
{
|
|
25364
25484
|
headers,
|
|
25365
25485
|
method: singleStep.callMethod,
|
|
25366
|
-
body: singleStep.callBody,
|
|
25486
|
+
body: JSON.stringify(singleStep.callBody),
|
|
25367
25487
|
url: singleStep.callUrl
|
|
25368
25488
|
}
|
|
25369
25489
|
) : (
|
|
@@ -25373,7 +25493,7 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
25373
25493
|
{
|
|
25374
25494
|
headers,
|
|
25375
25495
|
method: "POST",
|
|
25376
|
-
body: singleStep,
|
|
25496
|
+
body: JSON.stringify(singleStep),
|
|
25377
25497
|
url: this.context.url,
|
|
25378
25498
|
notBefore: willWait ? singleStep.sleepUntil : void 0,
|
|
25379
25499
|
delay: willWait ? singleStep.sleepFor : void 0
|
|
@@ -25381,8 +25501,9 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
25381
25501
|
);
|
|
25382
25502
|
})
|
|
25383
25503
|
);
|
|
25504
|
+
const _result = result;
|
|
25384
25505
|
await this.debug?.log("INFO", "SUBMIT_STEP", {
|
|
25385
|
-
messageIds:
|
|
25506
|
+
messageIds: _result.map((message) => {
|
|
25386
25507
|
return {
|
|
25387
25508
|
message: message.messageId
|
|
25388
25509
|
};
|
|
@@ -25585,6 +25706,9 @@ var WorkflowApi = class extends BaseWorkflowApi {
|
|
|
25585
25706
|
}
|
|
25586
25707
|
};
|
|
25587
25708
|
|
|
25709
|
+
// src/agents/index.ts
|
|
25710
|
+
var import_openai3 = require("@ai-sdk/openai");
|
|
25711
|
+
|
|
25588
25712
|
// src/agents/adapters.ts
|
|
25589
25713
|
var import_openai2 = require("@ai-sdk/openai");
|
|
25590
25714
|
var import_ai = require("ai");
|
|
@@ -25604,46 +25728,49 @@ you need from that agent.
|
|
|
25604
25728
|
`;
|
|
25605
25729
|
|
|
25606
25730
|
// src/agents/adapters.ts
|
|
25607
|
-
var
|
|
25608
|
-
const
|
|
25609
|
-
|
|
25610
|
-
|
|
25611
|
-
|
|
25612
|
-
|
|
25613
|
-
|
|
25614
|
-
|
|
25615
|
-
|
|
25616
|
-
|
|
25617
|
-
|
|
25618
|
-
|
|
25619
|
-
|
|
25620
|
-
|
|
25621
|
-
|
|
25622
|
-
|
|
25623
|
-
|
|
25624
|
-
|
|
25625
|
-
|
|
25626
|
-
|
|
25627
|
-
|
|
25628
|
-
|
|
25629
|
-
|
|
25630
|
-
|
|
25631
|
-
|
|
25632
|
-
|
|
25633
|
-
|
|
25634
|
-
|
|
25635
|
-
|
|
25636
|
-
|
|
25637
|
-
|
|
25638
|
-
|
|
25639
|
-
if (error instanceof Error && error.name === "WorkflowAbort") {
|
|
25640
|
-
throw error;
|
|
25641
|
-
} else {
|
|
25642
|
-
console.error("Error in fetch implementation:", error);
|
|
25643
|
-
throw error;
|
|
25644
|
-
}
|
|
25645
|
-
}
|
|
25731
|
+
var fetchWithContextCall = async (context, ...params) => {
|
|
25732
|
+
const [input, init] = params;
|
|
25733
|
+
try {
|
|
25734
|
+
const headers = init?.headers ? Object.fromEntries(new Headers(init.headers).entries()) : {};
|
|
25735
|
+
const body = init?.body ? JSON.parse(init.body) : void 0;
|
|
25736
|
+
const agentName = headers[AGENT_NAME_HEADER];
|
|
25737
|
+
const stepName = agentName ? `Call Agent ${agentName}` : "Call Agent";
|
|
25738
|
+
const responseInfo = await context.call(stepName, {
|
|
25739
|
+
url: input.toString(),
|
|
25740
|
+
method: init?.method,
|
|
25741
|
+
headers,
|
|
25742
|
+
body
|
|
25743
|
+
});
|
|
25744
|
+
const responseHeaders = new Headers(
|
|
25745
|
+
Object.entries(responseInfo.header).reduce(
|
|
25746
|
+
(acc, [key, values]) => {
|
|
25747
|
+
acc[key] = values.join(", ");
|
|
25748
|
+
return acc;
|
|
25749
|
+
},
|
|
25750
|
+
{}
|
|
25751
|
+
)
|
|
25752
|
+
);
|
|
25753
|
+
return new Response(JSON.stringify(responseInfo.body), {
|
|
25754
|
+
status: responseInfo.status,
|
|
25755
|
+
headers: responseHeaders
|
|
25756
|
+
});
|
|
25757
|
+
} catch (error) {
|
|
25758
|
+
if (error instanceof Error && error.name === "WorkflowAbort") {
|
|
25759
|
+
throw error;
|
|
25760
|
+
} else {
|
|
25761
|
+
console.error("Error in fetch implementation:", error);
|
|
25762
|
+
throw error;
|
|
25646
25763
|
}
|
|
25764
|
+
}
|
|
25765
|
+
};
|
|
25766
|
+
var createWorkflowModel = ({
|
|
25767
|
+
context,
|
|
25768
|
+
provider,
|
|
25769
|
+
providerParams
|
|
25770
|
+
}) => {
|
|
25771
|
+
return provider({
|
|
25772
|
+
fetch: (...params) => fetchWithContextCall(context, ...params),
|
|
25773
|
+
...providerParams
|
|
25647
25774
|
});
|
|
25648
25775
|
};
|
|
25649
25776
|
var wrapTools = ({
|
|
@@ -25883,9 +26010,14 @@ var WorkflowAgents = class {
|
|
|
25883
26010
|
openai(...params) {
|
|
25884
26011
|
const [model, settings] = params;
|
|
25885
26012
|
const { baseURL, apiKey, ...otherSettings } = settings ?? {};
|
|
25886
|
-
const
|
|
25887
|
-
|
|
26013
|
+
const openaiModel = this.AISDKModel({
|
|
26014
|
+
context: this.context,
|
|
26015
|
+
provider: import_openai3.createOpenAI,
|
|
26016
|
+
providerParams: { baseURL, apiKey, compatibility: "strict" }
|
|
26017
|
+
});
|
|
26018
|
+
return openaiModel(model, otherSettings);
|
|
25888
26019
|
}
|
|
26020
|
+
AISDKModel = createWorkflowModel;
|
|
25889
26021
|
};
|
|
25890
26022
|
|
|
25891
26023
|
// src/context/context.ts
|
|
@@ -26071,7 +26203,7 @@ var WorkflowContext = class {
|
|
|
26071
26203
|
*/
|
|
26072
26204
|
async run(stepName, stepFunction) {
|
|
26073
26205
|
const wrappedStepFunction = () => this.executor.wrapStep(stepName, stepFunction);
|
|
26074
|
-
return this.addStep(new LazyFunctionStep(stepName, wrappedStepFunction));
|
|
26206
|
+
return await this.addStep(new LazyFunctionStep(stepName, wrappedStepFunction));
|
|
26075
26207
|
}
|
|
26076
26208
|
/**
|
|
26077
26209
|
* Stops the execution for the duration provided.
|
|
@@ -26142,43 +26274,27 @@ var WorkflowContext = class {
|
|
|
26142
26274
|
* }
|
|
26143
26275
|
*/
|
|
26144
26276
|
async call(stepName, settings) {
|
|
26145
|
-
const {
|
|
26146
|
-
|
|
26277
|
+
const {
|
|
26278
|
+
url,
|
|
26279
|
+
method = "GET",
|
|
26280
|
+
body: requestBody,
|
|
26281
|
+
headers = {},
|
|
26282
|
+
retries = 0,
|
|
26283
|
+
timeout,
|
|
26284
|
+
flowControl
|
|
26285
|
+
} = settings;
|
|
26286
|
+
return await this.addStep(
|
|
26147
26287
|
new LazyCallStep(
|
|
26148
26288
|
stepName,
|
|
26149
26289
|
url,
|
|
26150
26290
|
method,
|
|
26151
|
-
|
|
26291
|
+
requestBody,
|
|
26152
26292
|
headers,
|
|
26153
26293
|
retries,
|
|
26154
26294
|
timeout,
|
|
26155
26295
|
flowControl
|
|
26156
26296
|
)
|
|
26157
26297
|
);
|
|
26158
|
-
if (typeof result === "string") {
|
|
26159
|
-
try {
|
|
26160
|
-
const body2 = JSON.parse(result);
|
|
26161
|
-
return {
|
|
26162
|
-
status: 200,
|
|
26163
|
-
header: {},
|
|
26164
|
-
body: body2
|
|
26165
|
-
};
|
|
26166
|
-
} catch {
|
|
26167
|
-
return {
|
|
26168
|
-
status: 200,
|
|
26169
|
-
header: {},
|
|
26170
|
-
body: result
|
|
26171
|
-
};
|
|
26172
|
-
}
|
|
26173
|
-
}
|
|
26174
|
-
try {
|
|
26175
|
-
return {
|
|
26176
|
-
...result,
|
|
26177
|
-
body: JSON.parse(result.body)
|
|
26178
|
-
};
|
|
26179
|
-
} catch {
|
|
26180
|
-
return result;
|
|
26181
|
-
}
|
|
26182
26298
|
}
|
|
26183
26299
|
/**
|
|
26184
26300
|
* Pauses workflow execution until a specific event occurs or a timeout is reached.
|
|
@@ -26217,15 +26333,7 @@ var WorkflowContext = class {
|
|
|
26217
26333
|
async waitForEvent(stepName, eventId, options = {}) {
|
|
26218
26334
|
const { timeout = "7d" } = options;
|
|
26219
26335
|
const timeoutStr = typeof timeout === "string" ? timeout : `${timeout}s`;
|
|
26220
|
-
|
|
26221
|
-
try {
|
|
26222
|
-
return {
|
|
26223
|
-
...result,
|
|
26224
|
-
eventData: JSON.parse(result.eventData)
|
|
26225
|
-
};
|
|
26226
|
-
} catch {
|
|
26227
|
-
return result;
|
|
26228
|
-
}
|
|
26336
|
+
return await this.addStep(new LazyWaitForEventStep(stepName, eventId, timeoutStr));
|
|
26229
26337
|
}
|
|
26230
26338
|
/**
|
|
26231
26339
|
* Notify workflow runs waiting for an event
|
|
@@ -26249,24 +26357,12 @@ var WorkflowContext = class {
|
|
|
26249
26357
|
* @returns notify response which has event id, event data and list of waiters which were notified
|
|
26250
26358
|
*/
|
|
26251
26359
|
async notify(stepName, eventId, eventData) {
|
|
26252
|
-
|
|
26360
|
+
return await this.addStep(
|
|
26253
26361
|
new LazyNotifyStep(stepName, eventId, eventData, this.qstashClient.http)
|
|
26254
26362
|
);
|
|
26255
|
-
try {
|
|
26256
|
-
return {
|
|
26257
|
-
...result,
|
|
26258
|
-
eventData: JSON.parse(result.eventData)
|
|
26259
|
-
};
|
|
26260
|
-
} catch {
|
|
26261
|
-
return result;
|
|
26262
|
-
}
|
|
26263
26363
|
}
|
|
26264
26364
|
async invoke(stepName, settings) {
|
|
26265
|
-
|
|
26266
|
-
return {
|
|
26267
|
-
...result,
|
|
26268
|
-
body: result.body ? JSON.parse(result.body) : void 0
|
|
26269
|
-
};
|
|
26365
|
+
return await this.addStep(new LazyInvokeStep(stepName, settings));
|
|
26270
26366
|
}
|
|
26271
26367
|
/**
|
|
26272
26368
|
* Cancel the current workflow run
|
|
@@ -26425,10 +26521,6 @@ var processRawSteps = (rawSteps) => {
|
|
|
26425
26521
|
const stepsToDecode = encodedSteps.filter((step) => step.callType === "step");
|
|
26426
26522
|
const otherSteps = stepsToDecode.map((rawStep) => {
|
|
26427
26523
|
const step = JSON.parse(decodeBase64(rawStep.body));
|
|
26428
|
-
try {
|
|
26429
|
-
step.out = JSON.parse(step.out);
|
|
26430
|
-
} catch {
|
|
26431
|
-
}
|
|
26432
26524
|
if (step.waitEventId) {
|
|
26433
26525
|
const newOut = {
|
|
26434
26526
|
eventData: step.out ? decodeBase64(step.out) : void 0,
|
|
@@ -26648,6 +26740,7 @@ var processOptions = (options) => {
|
|
|
26648
26740
|
retries: DEFAULT_RETRIES,
|
|
26649
26741
|
useJSONContent: false,
|
|
26650
26742
|
disableTelemetry: false,
|
|
26743
|
+
onError: console.error,
|
|
26651
26744
|
...options
|
|
26652
26745
|
};
|
|
26653
26746
|
};
|
|
@@ -26697,7 +26790,8 @@ var serveBase = (routeFunction, telemetry2, options) => {
|
|
|
26697
26790
|
retries,
|
|
26698
26791
|
useJSONContent,
|
|
26699
26792
|
disableTelemetry,
|
|
26700
|
-
flowControl
|
|
26793
|
+
flowControl,
|
|
26794
|
+
onError
|
|
26701
26795
|
} = processOptions(options);
|
|
26702
26796
|
telemetry2 = disableTelemetry ? void 0 : telemetry2;
|
|
26703
26797
|
const debug = WorkflowLogger.getLogger(verbose);
|
|
@@ -26826,8 +26920,19 @@ var serveBase = (routeFunction, telemetry2, options) => {
|
|
|
26826
26920
|
try {
|
|
26827
26921
|
return await handler(request);
|
|
26828
26922
|
} catch (error) {
|
|
26829
|
-
|
|
26830
|
-
|
|
26923
|
+
const formattedError = formatWorkflowError(error);
|
|
26924
|
+
try {
|
|
26925
|
+
onError?.(error);
|
|
26926
|
+
} catch (onErrorError) {
|
|
26927
|
+
const formattedOnErrorError = formatWorkflowError(onErrorError);
|
|
26928
|
+
const errorMessage = `Error while running onError callback: '${formattedOnErrorError.message}'.
|
|
26929
|
+
Original error: '${formattedError.message}'`;
|
|
26930
|
+
console.error(errorMessage);
|
|
26931
|
+
return new Response(errorMessage, {
|
|
26932
|
+
status: 500
|
|
26933
|
+
});
|
|
26934
|
+
}
|
|
26935
|
+
return new Response(JSON.stringify(formattedError), {
|
|
26831
26936
|
status: 500
|
|
26832
26937
|
});
|
|
26833
26938
|
}
|
package/express.mjs
CHANGED
package/h3.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as h3 from 'h3';
|
|
2
|
-
import { R as RouteFunction, k as PublicServeOptions, t as InvokableWorkflow } from './types-
|
|
3
|
-
import { s as serveManyBase } from './serve-many-
|
|
2
|
+
import { R as RouteFunction, k as PublicServeOptions, t as InvokableWorkflow } from './types-D1W0VOpy.mjs';
|
|
3
|
+
import { s as serveManyBase } from './serve-many-DLguU9iR.mjs';
|
|
4
4
|
import '@upstash/qstash';
|
|
5
5
|
import 'zod';
|
|
6
6
|
import 'ai';
|
package/h3.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as h3 from 'h3';
|
|
2
|
-
import { R as RouteFunction, k as PublicServeOptions, t as InvokableWorkflow } from './types-
|
|
3
|
-
import { s as serveManyBase } from './serve-many-
|
|
2
|
+
import { R as RouteFunction, k as PublicServeOptions, t as InvokableWorkflow } from './types-D1W0VOpy.js';
|
|
3
|
+
import { s as serveManyBase } from './serve-many-BdMq5rFX.js';
|
|
4
4
|
import '@upstash/qstash';
|
|
5
5
|
import 'zod';
|
|
6
6
|
import 'ai';
|