@upstash/workflow 0.2.13 → 0.2.15
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 +92 -57
- package/astro.mjs +1 -1
- package/{chunk-XVNSBBDC.mjs → chunk-AC5CQCN3.mjs} +94 -57
- package/cloudflare.d.mts +2 -2
- package/cloudflare.d.ts +2 -2
- package/cloudflare.js +92 -57
- package/cloudflare.mjs +1 -1
- package/express.d.mts +2 -2
- package/express.d.ts +2 -2
- package/express.js +92 -57
- package/express.mjs +1 -1
- package/h3.d.mts +2 -2
- package/h3.d.ts +2 -2
- package/h3.js +92 -57
- package/h3.mjs +1 -1
- package/hono.d.mts +2 -2
- package/hono.d.ts +2 -2
- package/hono.js +92 -57
- package/hono.mjs +1 -1
- package/index.d.mts +270 -42
- package/index.d.ts +270 -42
- package/index.js +206 -119
- package/index.mjs +117 -63
- package/nextjs.d.mts +2 -2
- package/nextjs.d.ts +2 -2
- package/nextjs.js +92 -57
- package/nextjs.mjs +1 -1
- package/package.json +1 -1
- package/{serve-many-BF71QZHQ.d.mts → serve-many-AFwJPR3S.d.mts} +1 -1
- package/{serve-many-BMlN2PAB.d.ts → serve-many-AaKSQyi7.d.ts} +1 -1
- package/solidjs.d.mts +1 -1
- package/solidjs.d.ts +1 -1
- package/solidjs.js +92 -57
- package/solidjs.mjs +1 -1
- package/svelte.d.mts +2 -2
- package/svelte.d.ts +2 -2
- package/svelte.js +92 -57
- package/svelte.mjs +1 -1
- package/{types-C1WIgVLA.d.ts → types-Dd-3bPoU.d.mts} +39 -4
- package/{types-C1WIgVLA.d.mts → types-Dd-3bPoU.d.ts} +39 -4
package/astro.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { APIContext, APIRoute } from 'astro';
|
|
2
|
-
import {
|
|
3
|
-
import { s as serveManyBase } from './serve-many-
|
|
2
|
+
import { g as WorkflowContext, n as PublicServeOptions, w as InvokableWorkflow } from './types-Dd-3bPoU.mjs';
|
|
3
|
+
import { s as serveManyBase } from './serve-many-AFwJPR3S.mjs';
|
|
4
4
|
import '@upstash/qstash';
|
|
5
5
|
import 'zod';
|
|
6
6
|
import 'ai';
|
package/astro.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { APIContext, APIRoute } from 'astro';
|
|
2
|
-
import {
|
|
3
|
-
import { s as serveManyBase } from './serve-many-
|
|
2
|
+
import { g as WorkflowContext, n as PublicServeOptions, w as InvokableWorkflow } from './types-Dd-3bPoU.js';
|
|
3
|
+
import { s as serveManyBase } from './serve-many-AaKSQyi7.js';
|
|
4
4
|
import '@upstash/qstash';
|
|
5
5
|
import 'zod';
|
|
6
6
|
import 'ai';
|
package/astro.js
CHANGED
|
@@ -91,7 +91,7 @@ var WORKFLOW_PROTOCOL_VERSION_HEADER = "Upstash-Workflow-Sdk-Version";
|
|
|
91
91
|
var DEFAULT_CONTENT_TYPE = "application/json";
|
|
92
92
|
var NO_CONCURRENCY = 1;
|
|
93
93
|
var DEFAULT_RETRIES = 3;
|
|
94
|
-
var VERSION = "v0.2.
|
|
94
|
+
var VERSION = "v0.2.15";
|
|
95
95
|
var SDK_TELEMETRY = `@upstash/workflow@${VERSION}`;
|
|
96
96
|
var TELEMETRY_HEADER_SDK = "Upstash-Telemetry-Sdk";
|
|
97
97
|
var TELEMETRY_HEADER_FRAMEWORK = "Upstash-Telemetry-Framework";
|
|
@@ -129,6 +129,16 @@ var WorkflowAbort = class extends Error {
|
|
|
129
129
|
this.cancelWorkflow = cancelWorkflow;
|
|
130
130
|
}
|
|
131
131
|
};
|
|
132
|
+
var WorkflowNonRetryableError = class extends WorkflowAbort {
|
|
133
|
+
/**
|
|
134
|
+
* @param message error message to be displayed
|
|
135
|
+
*/
|
|
136
|
+
constructor(message) {
|
|
137
|
+
super("fail", void 0, false);
|
|
138
|
+
this.name = "WorkflowNonRetryableError";
|
|
139
|
+
if (message) this.message = message;
|
|
140
|
+
}
|
|
141
|
+
};
|
|
132
142
|
var formatWorkflowError = (error) => {
|
|
133
143
|
return error instanceof Error ? {
|
|
134
144
|
error: error.name,
|
|
@@ -599,59 +609,72 @@ var StepTypes = [
|
|
|
599
609
|
|
|
600
610
|
// src/workflow-requests.ts
|
|
601
611
|
var import_qstash3 = require("@upstash/qstash");
|
|
602
|
-
var triggerFirstInvocation = async ({
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
}
|
|
630
|
-
try {
|
|
631
|
-
const body = typeof workflowContext.requestPayload === "string" ? workflowContext.requestPayload : JSON.stringify(workflowContext.requestPayload);
|
|
632
|
-
const result = await workflowContext.qstashClient.publish({
|
|
633
|
-
headers,
|
|
634
|
-
method: "POST",
|
|
635
|
-
body,
|
|
636
|
-
url: workflowContext.url,
|
|
637
|
-
delay
|
|
638
|
-
});
|
|
639
|
-
if (result.deduplicated) {
|
|
640
|
-
await debug?.log("WARN", "SUBMIT_FIRST_INVOCATION", {
|
|
641
|
-
message: `Workflow run ${workflowContext.workflowRunId} already exists. A new one isn't created.`,
|
|
612
|
+
var triggerFirstInvocation = async (params) => {
|
|
613
|
+
const firstInvocationParams = Array.isArray(params) ? params : [params];
|
|
614
|
+
const workflowContextClient = firstInvocationParams[0].workflowContext.qstashClient;
|
|
615
|
+
const invocationBatch = firstInvocationParams.map(
|
|
616
|
+
({ workflowContext, useJSONContent, telemetry: telemetry2, invokeCount, delay }) => {
|
|
617
|
+
const { headers } = getHeaders({
|
|
618
|
+
initHeaderValue: "true",
|
|
619
|
+
workflowConfig: {
|
|
620
|
+
workflowRunId: workflowContext.workflowRunId,
|
|
621
|
+
workflowUrl: workflowContext.url,
|
|
622
|
+
failureUrl: workflowContext.failureUrl,
|
|
623
|
+
retries: workflowContext.retries,
|
|
624
|
+
telemetry: telemetry2,
|
|
625
|
+
flowControl: workflowContext.flowControl,
|
|
626
|
+
useJSONContent: useJSONContent ?? false
|
|
627
|
+
},
|
|
628
|
+
invokeCount: invokeCount ?? 0,
|
|
629
|
+
userHeaders: workflowContext.headers
|
|
630
|
+
});
|
|
631
|
+
if (workflowContext.headers.get("content-type")) {
|
|
632
|
+
headers["content-type"] = workflowContext.headers.get("content-type");
|
|
633
|
+
}
|
|
634
|
+
if (useJSONContent) {
|
|
635
|
+
headers["content-type"] = "application/json";
|
|
636
|
+
}
|
|
637
|
+
const body = typeof workflowContext.requestPayload === "string" ? workflowContext.requestPayload : JSON.stringify(workflowContext.requestPayload);
|
|
638
|
+
return {
|
|
642
639
|
headers,
|
|
643
|
-
|
|
640
|
+
method: "POST",
|
|
641
|
+
body,
|
|
644
642
|
url: workflowContext.url,
|
|
645
|
-
|
|
646
|
-
}
|
|
643
|
+
delay
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
);
|
|
647
|
+
try {
|
|
648
|
+
const results = await workflowContextClient.batch(invocationBatch);
|
|
649
|
+
const invocationStatuses = [];
|
|
650
|
+
for (let i = 0; i < results.length; i++) {
|
|
651
|
+
const result = results[i];
|
|
652
|
+
const invocationParams = firstInvocationParams[i];
|
|
653
|
+
if (result.deduplicated) {
|
|
654
|
+
await invocationParams.debug?.log("WARN", "SUBMIT_FIRST_INVOCATION", {
|
|
655
|
+
message: `Workflow run ${invocationParams.workflowContext.workflowRunId} already exists. A new one isn't created.`,
|
|
656
|
+
headers: invocationBatch[i].headers,
|
|
657
|
+
requestPayload: invocationParams.workflowContext.requestPayload,
|
|
658
|
+
url: invocationParams.workflowContext.url,
|
|
659
|
+
messageId: result.messageId
|
|
660
|
+
});
|
|
661
|
+
invocationStatuses.push("workflow-run-already-exists");
|
|
662
|
+
} else {
|
|
663
|
+
await invocationParams.debug?.log("SUBMIT", "SUBMIT_FIRST_INVOCATION", {
|
|
664
|
+
headers: invocationBatch[i].headers,
|
|
665
|
+
requestPayload: invocationParams.workflowContext.requestPayload,
|
|
666
|
+
url: invocationParams.workflowContext.url,
|
|
667
|
+
messageId: result.messageId
|
|
668
|
+
});
|
|
669
|
+
invocationStatuses.push("success");
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
const hasAnyDeduplicated = invocationStatuses.some(
|
|
673
|
+
(status) => status === "workflow-run-already-exists"
|
|
674
|
+
);
|
|
675
|
+
if (hasAnyDeduplicated) {
|
|
647
676
|
return ok("workflow-run-already-exists");
|
|
648
677
|
} else {
|
|
649
|
-
await debug?.log("SUBMIT", "SUBMIT_FIRST_INVOCATION", {
|
|
650
|
-
headers,
|
|
651
|
-
requestPayload: workflowContext.requestPayload,
|
|
652
|
-
url: workflowContext.url,
|
|
653
|
-
messageId: result.messageId
|
|
654
|
-
});
|
|
655
678
|
return ok("success");
|
|
656
679
|
}
|
|
657
680
|
} catch (error) {
|
|
@@ -680,6 +703,8 @@ var triggerRouteFunction = async ({
|
|
|
680
703
|
return ok("workflow-was-finished");
|
|
681
704
|
} else if (!(error_ instanceof WorkflowAbort)) {
|
|
682
705
|
return err(error_);
|
|
706
|
+
} else if (error_ instanceof WorkflowNonRetryableError) {
|
|
707
|
+
return ok(error_);
|
|
683
708
|
} else if (error_.cancelWorkflow) {
|
|
684
709
|
await onCancel();
|
|
685
710
|
return ok("workflow-finished");
|
|
@@ -841,7 +866,7 @@ ${atob(callbackMessage.body ?? "")}`
|
|
|
841
866
|
var getTelemetryHeaders = (telemetry2) => {
|
|
842
867
|
return {
|
|
843
868
|
[TELEMETRY_HEADER_SDK]: telemetry2.sdk,
|
|
844
|
-
[TELEMETRY_HEADER_FRAMEWORK]: telemetry2.framework,
|
|
869
|
+
[TELEMETRY_HEADER_FRAMEWORK]: telemetry2.framework ?? "unknown",
|
|
845
870
|
[TELEMETRY_HEADER_RUNTIME]: telemetry2.runtime ?? "unknown"
|
|
846
871
|
};
|
|
847
872
|
};
|
|
@@ -1141,7 +1166,7 @@ var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
|
|
|
1141
1166
|
return { header, status, body };
|
|
1142
1167
|
}
|
|
1143
1168
|
}
|
|
1144
|
-
static
|
|
1169
|
+
static applicationContentTypes = [
|
|
1145
1170
|
"application/json",
|
|
1146
1171
|
"application/xml",
|
|
1147
1172
|
"application/javascript",
|
|
@@ -1150,12 +1175,12 @@ var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
|
|
|
1150
1175
|
"application/ld+json",
|
|
1151
1176
|
"application/rss+xml",
|
|
1152
1177
|
"application/atom+xml"
|
|
1153
|
-
]
|
|
1178
|
+
];
|
|
1154
1179
|
static isText = (contentTypeHeader) => {
|
|
1155
1180
|
if (!contentTypeHeader) {
|
|
1156
1181
|
return false;
|
|
1157
1182
|
}
|
|
1158
|
-
if (_LazyCallStep.
|
|
1183
|
+
if (_LazyCallStep.applicationContentTypes.some((type) => contentTypeHeader.includes(type))) {
|
|
1159
1184
|
return true;
|
|
1160
1185
|
}
|
|
1161
1186
|
if (contentTypeHeader.startsWith("text/")) {
|
|
@@ -2953,10 +2978,10 @@ var DisabledWorkflowContext = class _DisabledWorkflowContext extends WorkflowCon
|
|
|
2953
2978
|
throw new WorkflowAbort(_DisabledWorkflowContext.disabledMessage);
|
|
2954
2979
|
}
|
|
2955
2980
|
/**
|
|
2956
|
-
* overwrite cancel method to
|
|
2981
|
+
* overwrite cancel method to throw WorkflowAbort with the disabledMessage
|
|
2957
2982
|
*/
|
|
2958
2983
|
async cancel() {
|
|
2959
|
-
|
|
2984
|
+
throw new WorkflowAbort(_DisabledWorkflowContext.disabledMessage);
|
|
2960
2985
|
}
|
|
2961
2986
|
/**
|
|
2962
2987
|
* copies the passed context to create a DisabledWorkflowContext. Then, runs the
|
|
@@ -2988,7 +3013,7 @@ var DisabledWorkflowContext = class _DisabledWorkflowContext extends WorkflowCon
|
|
|
2988
3013
|
try {
|
|
2989
3014
|
await routeFunction(disabledContext);
|
|
2990
3015
|
} catch (error) {
|
|
2991
|
-
if (error instanceof WorkflowAbort && error.stepName === this.disabledMessage) {
|
|
3016
|
+
if (error instanceof WorkflowAbort && error.stepName === this.disabledMessage || error instanceof WorkflowNonRetryableError) {
|
|
2992
3017
|
return ok("step-found");
|
|
2993
3018
|
}
|
|
2994
3019
|
return err(error);
|
|
@@ -3209,6 +3234,13 @@ var processOptions = (options) => {
|
|
|
3209
3234
|
status: 400
|
|
3210
3235
|
}
|
|
3211
3236
|
);
|
|
3237
|
+
} else if (finishCondition instanceof WorkflowNonRetryableError) {
|
|
3238
|
+
return new Response(JSON.stringify(formatWorkflowError(finishCondition)), {
|
|
3239
|
+
headers: {
|
|
3240
|
+
"Upstash-NonRetryable-Error": "true"
|
|
3241
|
+
},
|
|
3242
|
+
status: 489
|
|
3243
|
+
});
|
|
3212
3244
|
}
|
|
3213
3245
|
return new Response(JSON.stringify({ workflowRunId }), {
|
|
3214
3246
|
status: 200
|
|
@@ -3401,6 +3433,9 @@ var serveBase = (routeFunction, telemetry2, options) => {
|
|
|
3401
3433
|
},
|
|
3402
3434
|
debug
|
|
3403
3435
|
});
|
|
3436
|
+
if (result.isOk() && result.value instanceof WorkflowNonRetryableError) {
|
|
3437
|
+
return onStepFinish(workflowRunId, result.value);
|
|
3438
|
+
}
|
|
3404
3439
|
if (result.isErr()) {
|
|
3405
3440
|
await debug?.log("ERROR", "ERROR", { error: result.error.message });
|
|
3406
3441
|
throw result.error;
|
package/astro.mjs
CHANGED
|
@@ -42,7 +42,7 @@ var WORKFLOW_PROTOCOL_VERSION_HEADER = "Upstash-Workflow-Sdk-Version";
|
|
|
42
42
|
var DEFAULT_CONTENT_TYPE = "application/json";
|
|
43
43
|
var NO_CONCURRENCY = 1;
|
|
44
44
|
var DEFAULT_RETRIES = 3;
|
|
45
|
-
var VERSION = "v0.2.
|
|
45
|
+
var VERSION = "v0.2.15";
|
|
46
46
|
var SDK_TELEMETRY = `@upstash/workflow@${VERSION}`;
|
|
47
47
|
var TELEMETRY_HEADER_SDK = "Upstash-Telemetry-Sdk";
|
|
48
48
|
var TELEMETRY_HEADER_FRAMEWORK = "Upstash-Telemetry-Framework";
|
|
@@ -80,6 +80,16 @@ var WorkflowAbort = class extends Error {
|
|
|
80
80
|
this.cancelWorkflow = cancelWorkflow;
|
|
81
81
|
}
|
|
82
82
|
};
|
|
83
|
+
var WorkflowNonRetryableError = class extends WorkflowAbort {
|
|
84
|
+
/**
|
|
85
|
+
* @param message error message to be displayed
|
|
86
|
+
*/
|
|
87
|
+
constructor(message) {
|
|
88
|
+
super("fail", void 0, false);
|
|
89
|
+
this.name = "WorkflowNonRetryableError";
|
|
90
|
+
if (message) this.message = message;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
83
93
|
var formatWorkflowError = (error) => {
|
|
84
94
|
return error instanceof Error ? {
|
|
85
95
|
error: error.name,
|
|
@@ -809,59 +819,72 @@ var fromThrowable = Result.fromThrowable;
|
|
|
809
819
|
|
|
810
820
|
// src/workflow-requests.ts
|
|
811
821
|
import { QstashError as QstashError3 } from "@upstash/qstash";
|
|
812
|
-
var triggerFirstInvocation = async ({
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
}
|
|
840
|
-
try {
|
|
841
|
-
const body = typeof workflowContext.requestPayload === "string" ? workflowContext.requestPayload : JSON.stringify(workflowContext.requestPayload);
|
|
842
|
-
const result = await workflowContext.qstashClient.publish({
|
|
843
|
-
headers,
|
|
844
|
-
method: "POST",
|
|
845
|
-
body,
|
|
846
|
-
url: workflowContext.url,
|
|
847
|
-
delay
|
|
848
|
-
});
|
|
849
|
-
if (result.deduplicated) {
|
|
850
|
-
await debug?.log("WARN", "SUBMIT_FIRST_INVOCATION", {
|
|
851
|
-
message: `Workflow run ${workflowContext.workflowRunId} already exists. A new one isn't created.`,
|
|
822
|
+
var triggerFirstInvocation = async (params) => {
|
|
823
|
+
const firstInvocationParams = Array.isArray(params) ? params : [params];
|
|
824
|
+
const workflowContextClient = firstInvocationParams[0].workflowContext.qstashClient;
|
|
825
|
+
const invocationBatch = firstInvocationParams.map(
|
|
826
|
+
({ workflowContext, useJSONContent, telemetry, invokeCount, delay }) => {
|
|
827
|
+
const { headers } = getHeaders({
|
|
828
|
+
initHeaderValue: "true",
|
|
829
|
+
workflowConfig: {
|
|
830
|
+
workflowRunId: workflowContext.workflowRunId,
|
|
831
|
+
workflowUrl: workflowContext.url,
|
|
832
|
+
failureUrl: workflowContext.failureUrl,
|
|
833
|
+
retries: workflowContext.retries,
|
|
834
|
+
telemetry,
|
|
835
|
+
flowControl: workflowContext.flowControl,
|
|
836
|
+
useJSONContent: useJSONContent ?? false
|
|
837
|
+
},
|
|
838
|
+
invokeCount: invokeCount ?? 0,
|
|
839
|
+
userHeaders: workflowContext.headers
|
|
840
|
+
});
|
|
841
|
+
if (workflowContext.headers.get("content-type")) {
|
|
842
|
+
headers["content-type"] = workflowContext.headers.get("content-type");
|
|
843
|
+
}
|
|
844
|
+
if (useJSONContent) {
|
|
845
|
+
headers["content-type"] = "application/json";
|
|
846
|
+
}
|
|
847
|
+
const body = typeof workflowContext.requestPayload === "string" ? workflowContext.requestPayload : JSON.stringify(workflowContext.requestPayload);
|
|
848
|
+
return {
|
|
852
849
|
headers,
|
|
853
|
-
|
|
850
|
+
method: "POST",
|
|
851
|
+
body,
|
|
854
852
|
url: workflowContext.url,
|
|
855
|
-
|
|
856
|
-
}
|
|
853
|
+
delay
|
|
854
|
+
};
|
|
855
|
+
}
|
|
856
|
+
);
|
|
857
|
+
try {
|
|
858
|
+
const results = await workflowContextClient.batch(invocationBatch);
|
|
859
|
+
const invocationStatuses = [];
|
|
860
|
+
for (let i = 0; i < results.length; i++) {
|
|
861
|
+
const result = results[i];
|
|
862
|
+
const invocationParams = firstInvocationParams[i];
|
|
863
|
+
if (result.deduplicated) {
|
|
864
|
+
await invocationParams.debug?.log("WARN", "SUBMIT_FIRST_INVOCATION", {
|
|
865
|
+
message: `Workflow run ${invocationParams.workflowContext.workflowRunId} already exists. A new one isn't created.`,
|
|
866
|
+
headers: invocationBatch[i].headers,
|
|
867
|
+
requestPayload: invocationParams.workflowContext.requestPayload,
|
|
868
|
+
url: invocationParams.workflowContext.url,
|
|
869
|
+
messageId: result.messageId
|
|
870
|
+
});
|
|
871
|
+
invocationStatuses.push("workflow-run-already-exists");
|
|
872
|
+
} else {
|
|
873
|
+
await invocationParams.debug?.log("SUBMIT", "SUBMIT_FIRST_INVOCATION", {
|
|
874
|
+
headers: invocationBatch[i].headers,
|
|
875
|
+
requestPayload: invocationParams.workflowContext.requestPayload,
|
|
876
|
+
url: invocationParams.workflowContext.url,
|
|
877
|
+
messageId: result.messageId
|
|
878
|
+
});
|
|
879
|
+
invocationStatuses.push("success");
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
const hasAnyDeduplicated = invocationStatuses.some(
|
|
883
|
+
(status) => status === "workflow-run-already-exists"
|
|
884
|
+
);
|
|
885
|
+
if (hasAnyDeduplicated) {
|
|
857
886
|
return ok("workflow-run-already-exists");
|
|
858
887
|
} else {
|
|
859
|
-
await debug?.log("SUBMIT", "SUBMIT_FIRST_INVOCATION", {
|
|
860
|
-
headers,
|
|
861
|
-
requestPayload: workflowContext.requestPayload,
|
|
862
|
-
url: workflowContext.url,
|
|
863
|
-
messageId: result.messageId
|
|
864
|
-
});
|
|
865
888
|
return ok("success");
|
|
866
889
|
}
|
|
867
890
|
} catch (error) {
|
|
@@ -890,6 +913,8 @@ var triggerRouteFunction = async ({
|
|
|
890
913
|
return ok("workflow-was-finished");
|
|
891
914
|
} else if (!(error_ instanceof WorkflowAbort)) {
|
|
892
915
|
return err(error_);
|
|
916
|
+
} else if (error_ instanceof WorkflowNonRetryableError) {
|
|
917
|
+
return ok(error_);
|
|
893
918
|
} else if (error_.cancelWorkflow) {
|
|
894
919
|
await onCancel();
|
|
895
920
|
return ok("workflow-finished");
|
|
@@ -1051,7 +1076,7 @@ ${atob(callbackMessage.body ?? "")}`
|
|
|
1051
1076
|
var getTelemetryHeaders = (telemetry) => {
|
|
1052
1077
|
return {
|
|
1053
1078
|
[TELEMETRY_HEADER_SDK]: telemetry.sdk,
|
|
1054
|
-
[TELEMETRY_HEADER_FRAMEWORK]: telemetry.framework,
|
|
1079
|
+
[TELEMETRY_HEADER_FRAMEWORK]: telemetry.framework ?? "unknown",
|
|
1055
1080
|
[TELEMETRY_HEADER_RUNTIME]: telemetry.runtime ?? "unknown"
|
|
1056
1081
|
};
|
|
1057
1082
|
};
|
|
@@ -1351,7 +1376,7 @@ var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
|
|
|
1351
1376
|
return { header, status, body };
|
|
1352
1377
|
}
|
|
1353
1378
|
}
|
|
1354
|
-
static
|
|
1379
|
+
static applicationContentTypes = [
|
|
1355
1380
|
"application/json",
|
|
1356
1381
|
"application/xml",
|
|
1357
1382
|
"application/javascript",
|
|
@@ -1360,12 +1385,12 @@ var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
|
|
|
1360
1385
|
"application/ld+json",
|
|
1361
1386
|
"application/rss+xml",
|
|
1362
1387
|
"application/atom+xml"
|
|
1363
|
-
]
|
|
1388
|
+
];
|
|
1364
1389
|
static isText = (contentTypeHeader) => {
|
|
1365
1390
|
if (!contentTypeHeader) {
|
|
1366
1391
|
return false;
|
|
1367
1392
|
}
|
|
1368
|
-
if (_LazyCallStep.
|
|
1393
|
+
if (_LazyCallStep.applicationContentTypes.some((type) => contentTypeHeader.includes(type))) {
|
|
1369
1394
|
return true;
|
|
1370
1395
|
}
|
|
1371
1396
|
if (contentTypeHeader.startsWith("text/")) {
|
|
@@ -2997,10 +3022,10 @@ var DisabledWorkflowContext = class _DisabledWorkflowContext extends WorkflowCon
|
|
|
2997
3022
|
throw new WorkflowAbort(_DisabledWorkflowContext.disabledMessage);
|
|
2998
3023
|
}
|
|
2999
3024
|
/**
|
|
3000
|
-
* overwrite cancel method to
|
|
3025
|
+
* overwrite cancel method to throw WorkflowAbort with the disabledMessage
|
|
3001
3026
|
*/
|
|
3002
3027
|
async cancel() {
|
|
3003
|
-
|
|
3028
|
+
throw new WorkflowAbort(_DisabledWorkflowContext.disabledMessage);
|
|
3004
3029
|
}
|
|
3005
3030
|
/**
|
|
3006
3031
|
* copies the passed context to create a DisabledWorkflowContext. Then, runs the
|
|
@@ -3032,7 +3057,7 @@ var DisabledWorkflowContext = class _DisabledWorkflowContext extends WorkflowCon
|
|
|
3032
3057
|
try {
|
|
3033
3058
|
await routeFunction(disabledContext);
|
|
3034
3059
|
} catch (error) {
|
|
3035
|
-
if (error instanceof WorkflowAbort && error.stepName === this.disabledMessage) {
|
|
3060
|
+
if (error instanceof WorkflowAbort && error.stepName === this.disabledMessage || error instanceof WorkflowNonRetryableError) {
|
|
3036
3061
|
return ok("step-found");
|
|
3037
3062
|
}
|
|
3038
3063
|
return err(error);
|
|
@@ -3253,6 +3278,13 @@ var processOptions = (options) => {
|
|
|
3253
3278
|
status: 400
|
|
3254
3279
|
}
|
|
3255
3280
|
);
|
|
3281
|
+
} else if (finishCondition instanceof WorkflowNonRetryableError) {
|
|
3282
|
+
return new Response(JSON.stringify(formatWorkflowError(finishCondition)), {
|
|
3283
|
+
headers: {
|
|
3284
|
+
"Upstash-NonRetryable-Error": "true"
|
|
3285
|
+
},
|
|
3286
|
+
status: 489
|
|
3287
|
+
});
|
|
3256
3288
|
}
|
|
3257
3289
|
return new Response(JSON.stringify({ workflowRunId }), {
|
|
3258
3290
|
status: 200
|
|
@@ -3445,6 +3477,9 @@ var serveBase = (routeFunction, telemetry, options) => {
|
|
|
3445
3477
|
},
|
|
3446
3478
|
debug
|
|
3447
3479
|
});
|
|
3480
|
+
if (result.isOk() && result.value instanceof WorkflowNonRetryableError) {
|
|
3481
|
+
return onStepFinish(workflowRunId, result.value);
|
|
3482
|
+
}
|
|
3448
3483
|
if (result.isErr()) {
|
|
3449
3484
|
await debug?.log("ERROR", "ERROR", { error: result.error.message });
|
|
3450
3485
|
throw result.error;
|
|
@@ -3500,9 +3535,11 @@ export {
|
|
|
3500
3535
|
SDK_TELEMETRY,
|
|
3501
3536
|
WorkflowError,
|
|
3502
3537
|
WorkflowAbort,
|
|
3538
|
+
WorkflowNonRetryableError,
|
|
3503
3539
|
getWorkflowRunId,
|
|
3504
3540
|
StepTypes,
|
|
3505
3541
|
triggerFirstInvocation,
|
|
3542
|
+
prepareFlowControl,
|
|
3506
3543
|
WorkflowTool,
|
|
3507
3544
|
serveManyBase,
|
|
3508
3545
|
WorkflowContext,
|
package/cloudflare.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { R as RouteFunction,
|
|
2
|
-
import { s as serveManyBase } from './serve-many-
|
|
1
|
+
import { R as RouteFunction, n as PublicServeOptions, w as InvokableWorkflow } from './types-Dd-3bPoU.mjs';
|
|
2
|
+
import { s as serveManyBase } from './serve-many-AFwJPR3S.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,
|
|
2
|
-
import { s as serveManyBase } from './serve-many-
|
|
1
|
+
import { R as RouteFunction, n as PublicServeOptions, w as InvokableWorkflow } from './types-Dd-3bPoU.js';
|
|
2
|
+
import { s as serveManyBase } from './serve-many-AaKSQyi7.js';
|
|
3
3
|
import '@upstash/qstash';
|
|
4
4
|
import 'zod';
|
|
5
5
|
import 'ai';
|