@upstash/workflow 0.2.16 → 0.2.18

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/solidjs.js CHANGED
@@ -84,12 +84,13 @@ var WORKFLOW_URL_HEADER = "Upstash-Workflow-Url";
84
84
  var WORKFLOW_FAILURE_HEADER = "Upstash-Workflow-Is-Failure";
85
85
  var WORKFLOW_FEATURE_HEADER = "Upstash-Feature-Set";
86
86
  var WORKFLOW_INVOKE_COUNT_HEADER = "Upstash-Workflow-Invoke-Count";
87
+ var WORKFLOW_LABEL_HEADER = "Upstash-Label";
87
88
  var WORKFLOW_PROTOCOL_VERSION = "1";
88
89
  var WORKFLOW_PROTOCOL_VERSION_HEADER = "Upstash-Workflow-Sdk-Version";
89
90
  var DEFAULT_CONTENT_TYPE = "application/json";
90
91
  var NO_CONCURRENCY = 1;
91
92
  var DEFAULT_RETRIES = 3;
92
- var VERSION = "v0.2.15";
93
+ var VERSION = "v0.2.18";
93
94
  var SDK_TELEMETRY = `@upstash/workflow@${VERSION}`;
94
95
  var TELEMETRY_HEADER_SDK = "Upstash-Telemetry-Sdk";
95
96
  var TELEMETRY_HEADER_FRAMEWORK = "Upstash-Telemetry-Framework";
@@ -619,6 +620,7 @@ var triggerFirstInvocation = async (params) => {
619
620
  workflowUrl: workflowContext.url,
620
621
  failureUrl: workflowContext.failureUrl,
621
622
  retries: workflowContext.retries,
623
+ retryDelay: workflowContext.retryDelay,
622
624
  telemetry,
623
625
  flowControl: workflowContext.flowControl,
624
626
  useJSONContent: useJSONContent ?? false
@@ -632,6 +634,9 @@ var triggerFirstInvocation = async (params) => {
632
634
  if (useJSONContent) {
633
635
  headers["content-type"] = "application/json";
634
636
  }
637
+ if (workflowContext.label) {
638
+ headers[WORKFLOW_LABEL_HEADER] = workflowContext.label;
639
+ }
635
640
  const body = typeof workflowContext.requestPayload === "string" ? workflowContext.requestPayload : JSON.stringify(workflowContext.requestPayload);
636
641
  return {
637
642
  headers,
@@ -732,10 +737,11 @@ var recreateUserHeaders = (headers) => {
732
737
  const pairs = headers.entries();
733
738
  for (const [header, value] of pairs) {
734
739
  const headerLowerCase = header.toLowerCase();
735
- if (!headerLowerCase.startsWith("upstash-workflow-") && // https://vercel.com/docs/edge-network/headers/request-headers#x-vercel-id
740
+ const isUserHeader = !headerLowerCase.startsWith("upstash-workflow-") && // https://vercel.com/docs/edge-network/headers/request-headers#x-vercel-id
736
741
  !headerLowerCase.startsWith("x-vercel-") && !headerLowerCase.startsWith("x-forwarded-") && // https://blog.cloudflare.com/preventing-request-loops-using-cdn-loop/
737
742
  headerLowerCase !== "cf-connecting-ip" && headerLowerCase !== "cdn-loop" && headerLowerCase !== "cf-ew-via" && headerLowerCase !== "cf-ray" && // For Render https://render.com
738
- headerLowerCase !== "render-proxy-ttl") {
743
+ headerLowerCase !== "render-proxy-ttl" || headerLowerCase === WORKFLOW_LABEL_HEADER.toLocaleLowerCase();
744
+ if (isUserHeader) {
739
745
  filteredHeaders.append(header, value);
740
746
  }
741
747
  }
@@ -748,6 +754,7 @@ var handleThirdPartyCallResult = async ({
748
754
  workflowUrl,
749
755
  failureUrl,
750
756
  retries,
757
+ retryDelay,
751
758
  telemetry,
752
759
  flowControl,
753
760
  debug
@@ -818,6 +825,7 @@ ${atob(callbackMessage.body ?? "")}`
818
825
  workflowUrl,
819
826
  failureUrl,
820
827
  retries,
828
+ retryDelay,
821
829
  telemetry,
822
830
  flowControl
823
831
  },
@@ -968,7 +976,8 @@ var BaseLazyStep = class _BaseLazyStep {
968
976
  workflowRunId: context.workflowRunId,
969
977
  workflowUrl: context.url,
970
978
  failureUrl: context.failureUrl,
971
- retries: context.retries,
979
+ retries: DEFAULT_RETRIES === context.retries ? void 0 : context.retries,
980
+ retryDelay: context.retryDelay,
972
981
  useJSONContent: false,
973
982
  telemetry,
974
983
  flowControl: context.flowControl
@@ -987,6 +996,9 @@ var BaseLazyStep = class _BaseLazyStep {
987
996
  body,
988
997
  headers,
989
998
  method: "POST",
999
+ retries: DEFAULT_RETRIES === context.retries ? void 0 : context.retries,
1000
+ retryDelay: context.retryDelay,
1001
+ flowControl: context.flowControl,
990
1002
  url: context.url
991
1003
  }
992
1004
  ]);
@@ -1057,6 +1069,9 @@ var LazySleepStep = class extends BaseLazyStep {
1057
1069
  headers,
1058
1070
  method: "POST",
1059
1071
  url: context.url,
1072
+ retries: DEFAULT_RETRIES === context.retries ? void 0 : context.retries,
1073
+ retryDelay: context.retryDelay,
1074
+ flowControl: context.flowControl,
1060
1075
  delay: isParallel ? void 0 : this.sleep
1061
1076
  }
1062
1077
  ]);
@@ -1099,6 +1114,9 @@ var LazySleepUntilStep = class extends BaseLazyStep {
1099
1114
  headers,
1100
1115
  method: "POST",
1101
1116
  url: context.url,
1117
+ retries: DEFAULT_RETRIES === context.retries ? void 0 : context.retries,
1118
+ retryDelay: context.retryDelay,
1119
+ flowControl: context.flowControl,
1102
1120
  notBefore: isParallel ? void 0 : this.sleepUntil
1103
1121
  }
1104
1122
  ]);
@@ -1110,17 +1128,19 @@ var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
1110
1128
  body;
1111
1129
  headers;
1112
1130
  retries;
1131
+ retryDelay;
1113
1132
  timeout;
1114
1133
  flowControl;
1115
1134
  stepType = "Call";
1116
1135
  allowUndefinedOut = false;
1117
- constructor(stepName, url, method, body, headers, retries, timeout, flowControl) {
1136
+ constructor(stepName, url, method, body, headers, retries, retryDelay, timeout, flowControl) {
1118
1137
  super(stepName);
1119
1138
  this.url = url;
1120
1139
  this.method = method;
1121
1140
  this.body = body;
1122
1141
  this.headers = headers;
1123
1142
  this.retries = retries;
1143
+ this.retryDelay = retryDelay;
1124
1144
  this.timeout = timeout;
1125
1145
  this.flowControl = flowControl;
1126
1146
  }
@@ -1195,6 +1215,9 @@ var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
1195
1215
  getHeaders({ context, telemetry, invokeCount, step }) {
1196
1216
  const { headers, contentType } = super.getHeaders({ context, telemetry, invokeCount, step });
1197
1217
  headers["Upstash-Retries"] = this.retries.toString();
1218
+ if (this.retryDelay) {
1219
+ headers["Upstash-Retry-Delay"] = this.retryDelay;
1220
+ }
1198
1221
  headers[WORKFLOW_FEATURE_HEADER] = "WF_NoDelete,InitialBody";
1199
1222
  if (this.flowControl) {
1200
1223
  const { flowControlKey, flowControlValue } = prepareFlowControl(this.flowControl);
@@ -1216,7 +1239,7 @@ var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
1216
1239
  "Upstash-Callback-Workflow-CallType": "fromCallback",
1217
1240
  "Upstash-Callback-Workflow-Init": "false",
1218
1241
  "Upstash-Callback-Workflow-Url": context.url,
1219
- "Upstash-Callback-Feature-Set": "LazyFetch,InitialBody",
1242
+ "Upstash-Callback-Feature-Set": "LazyFetch,InitialBody,WF_DetectTrigger",
1220
1243
  "Upstash-Callback-Forward-Upstash-Workflow-Callback": "true",
1221
1244
  "Upstash-Callback-Forward-Upstash-Workflow-StepId": step.stepId.toString(),
1222
1245
  "Upstash-Callback-Forward-Upstash-Workflow-StepName": this.stepName,
@@ -1234,7 +1257,10 @@ var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
1234
1257
  headers,
1235
1258
  body: JSON.stringify(this.body),
1236
1259
  method: this.method,
1237
- url: this.url
1260
+ url: this.url,
1261
+ retries: DEFAULT_RETRIES === this.retries ? void 0 : this.retries,
1262
+ retryDelay: this.retryDelay,
1263
+ flowControl: this.flowControl
1238
1264
  }
1239
1265
  ]);
1240
1266
  }
@@ -1363,6 +1389,7 @@ var LazyInvokeStep = class extends BaseLazyStep {
1363
1389
  headers = {},
1364
1390
  workflowRunId,
1365
1391
  retries,
1392
+ retryDelay,
1366
1393
  flowControl
1367
1394
  }) {
1368
1395
  super(stepName);
@@ -1372,6 +1399,7 @@ var LazyInvokeStep = class extends BaseLazyStep {
1372
1399
  headers,
1373
1400
  workflowRunId: getWorkflowRunId(workflowRunId),
1374
1401
  retries,
1402
+ retryDelay,
1375
1403
  flowControl
1376
1404
  };
1377
1405
  const { workflowId } = workflow;
@@ -1416,6 +1444,7 @@ var LazyInvokeStep = class extends BaseLazyStep {
1416
1444
  workflowUrl: context.url,
1417
1445
  failureUrl: context.failureUrl,
1418
1446
  retries: context.retries,
1447
+ retryDelay: context.retryDelay,
1419
1448
  telemetry,
1420
1449
  flowControl: context.flowControl,
1421
1450
  useJSONContent: false
@@ -1441,11 +1470,13 @@ var LazyInvokeStep = class extends BaseLazyStep {
1441
1470
  headers = {},
1442
1471
  workflowRunId = getWorkflowRunId(),
1443
1472
  retries,
1473
+ retryDelay,
1444
1474
  flowControl
1445
1475
  } = this.params;
1446
1476
  const newUrl = context.url.replace(/[^/]+$/, this.workflowId);
1447
1477
  const {
1448
1478
  retries: workflowRetries,
1479
+ retryDelay: workflowRetryDelay,
1449
1480
  failureFunction,
1450
1481
  failureUrl,
1451
1482
  useJSONContent,
@@ -1457,6 +1488,7 @@ var LazyInvokeStep = class extends BaseLazyStep {
1457
1488
  workflowRunId,
1458
1489
  workflowUrl: newUrl,
1459
1490
  retries: retries ?? workflowRetries,
1491
+ retryDelay: retryDelay ?? workflowRetryDelay,
1460
1492
  telemetry,
1461
1493
  failureUrl: failureFunction ? newUrl : failureUrl,
1462
1494
  flowControl: flowControl ?? workflowFlowControl,
@@ -1523,6 +1555,7 @@ var WorkflowHeaders = class {
1523
1555
  getHeaders() {
1524
1556
  this.addBaseHeaders();
1525
1557
  this.addRetries();
1558
+ this.addRetryDelay();
1526
1559
  this.addFlowControl();
1527
1560
  this.addUserHeaders();
1528
1561
  this.addInvokeCount();
@@ -1536,7 +1569,7 @@ var WorkflowHeaders = class {
1536
1569
  [WORKFLOW_INIT_HEADER]: this.initHeaderValue,
1537
1570
  [WORKFLOW_ID_HEADER]: this.workflowConfig.workflowRunId,
1538
1571
  [WORKFLOW_URL_HEADER]: this.workflowConfig.workflowUrl,
1539
- [WORKFLOW_FEATURE_HEADER]: "LazyFetch,InitialBody",
1572
+ [WORKFLOW_FEATURE_HEADER]: "LazyFetch,InitialBody,WF_DetectTrigger",
1540
1573
  [WORKFLOW_PROTOCOL_VERSION_HEADER]: WORKFLOW_PROTOCOL_VERSION,
1541
1574
  ...this.workflowConfig.telemetry ? getTelemetryHeaders(this.workflowConfig.telemetry) : {},
1542
1575
  ...this.workflowConfig.telemetry && this.stepInfo?.lazyStep instanceof LazyCallStep && this.stepInfo.lazyStep.headers[AGENT_NAME_HEADER] ? { [TELEMETRY_HEADER_AGENT]: "true" } : {}
@@ -1568,6 +1601,16 @@ var WorkflowHeaders = class {
1568
1601
  this.headers.failureHeaders["Retries"] = retries;
1569
1602
  }
1570
1603
  }
1604
+ addRetryDelay() {
1605
+ if (this.workflowConfig.retryDelay === void 0 || this.workflowConfig.retryDelay === "") {
1606
+ return;
1607
+ }
1608
+ const retryDelay = this.workflowConfig.retryDelay.toString();
1609
+ this.headers.workflowHeaders["Retry-Delay"] = retryDelay;
1610
+ if (this.workflowConfig.failureUrl) {
1611
+ this.headers.failureHeaders["Retry-Delay"] = retryDelay;
1612
+ }
1613
+ }
1571
1614
  addFlowControl() {
1572
1615
  if (!this.workflowConfig.flowControl) {
1573
1616
  return;
@@ -1602,10 +1645,13 @@ var WorkflowHeaders = class {
1602
1645
  this.headers.failureHeaders["Workflow-Init"] = "false";
1603
1646
  this.headers.failureHeaders["Workflow-Url"] = this.workflowConfig.workflowUrl;
1604
1647
  this.headers.failureHeaders["Workflow-Calltype"] = "failureCall";
1605
- this.headers.failureHeaders["Feature-Set"] = "LazyFetch,InitialBody";
1648
+ this.headers.failureHeaders["Feature-Set"] = "LazyFetch,InitialBody,WF_DetectTrigger";
1606
1649
  if (this.workflowConfig.retries !== void 0 && this.workflowConfig.retries !== DEFAULT_RETRIES) {
1607
1650
  this.headers.failureHeaders["Retries"] = this.workflowConfig.retries.toString();
1608
1651
  }
1652
+ if (this.workflowConfig.retryDelay !== void 0 && this.workflowConfig.retryDelay !== "") {
1653
+ this.headers.failureHeaders["Retry-Delay"] = this.workflowConfig.retryDelay.toString();
1654
+ }
1609
1655
  }
1610
1656
  addContentType() {
1611
1657
  if (this.workflowConfig.useJSONContent) {
@@ -1687,6 +1733,7 @@ var submitParallelSteps = async ({
1687
1733
  workflowUrl: context.url,
1688
1734
  failureUrl: context.failureUrl,
1689
1735
  retries: context.retries,
1736
+ retryDelay: context.retryDelay,
1690
1737
  flowControl: context.flowControl,
1691
1738
  telemetry
1692
1739
  },
@@ -2107,7 +2154,7 @@ var BaseWorkflowApi = class {
2107
2154
  */
2108
2155
  async callApi(stepName, settings) {
2109
2156
  const { url, appendHeaders, method } = getProviderInfo(settings.api);
2110
- const { method: userMethod, body, headers = {}, retries = 0, timeout } = settings;
2157
+ const { method: userMethod, body, headers = {}, retries = 0, retryDelay, timeout } = settings;
2111
2158
  return await this.context.call(stepName, {
2112
2159
  url,
2113
2160
  method: userMethod ?? method,
@@ -2117,6 +2164,7 @@ var BaseWorkflowApi = class {
2117
2164
  ...headers
2118
2165
  },
2119
2166
  retries,
2167
+ retryDelay,
2120
2168
  timeout
2121
2169
  });
2122
2170
  }
@@ -2206,6 +2254,7 @@ var fetchWithContextCall = async (context, agentCallParams, ...params) => {
2206
2254
  body,
2207
2255
  timeout: agentCallParams?.timeout,
2208
2256
  retries: agentCallParams?.retries,
2257
+ retryDelay: agentCallParams?.retryDelay,
2209
2258
  flowControl: agentCallParams?.flowControl
2210
2259
  });
2211
2260
  const responseHeaders = new Headers(
@@ -2619,11 +2668,58 @@ var WorkflowContext = class {
2619
2668
  * Number of retries
2620
2669
  */
2621
2670
  retries;
2671
+ /**
2672
+ * Delay between retries.
2673
+ *
2674
+ * By default, the `retryDelay` is exponential backoff.
2675
+ * More details can be found in: https://upstash.com/docs/qstash/features/retry.
2676
+ *
2677
+ * The `retryDelay` option allows you to customize the delay (in milliseconds) between retry attempts when message delivery fails.
2678
+ *
2679
+ * You can use mathematical expressions and the following built-in functions to calculate the delay dynamically.
2680
+ * The special variable `retried` represents the current retry attempt count (starting from 0).
2681
+ *
2682
+ * Supported functions:
2683
+ * - `pow`
2684
+ * - `sqrt`
2685
+ * - `abs`
2686
+ * - `exp`
2687
+ * - `floor`
2688
+ * - `ceil`
2689
+ * - `round`
2690
+ * - `min`
2691
+ * - `max`
2692
+ *
2693
+ * Examples of valid `retryDelay` values:
2694
+ * ```ts
2695
+ * 1000 // 1 second
2696
+ * 1000 * (1 + retried) // 1 second multiplied by the current retry attempt
2697
+ * pow(2, retried) // 2 to the power of the current retry attempt
2698
+ * max(10, pow(2, retried)) // The greater of 10 or 2^retried
2699
+ * ```
2700
+ */
2701
+ retryDelay;
2622
2702
  /**
2623
2703
  * Settings for controlling the number of active requests
2624
2704
  * and number of requests per second with the same key.
2625
2705
  */
2626
2706
  flowControl;
2707
+ /**
2708
+ * Label to apply to the workflow run.
2709
+ *
2710
+ * Can be used to filter the workflow run logs.
2711
+ *
2712
+ * Can be set by passing a `label` parameter when triggering the workflow
2713
+ * with `client.trigger`:
2714
+ *
2715
+ * ```ts
2716
+ * await client.trigger({
2717
+ * url: "https://workflow-endpoint.com",
2718
+ * label: "my-label"
2719
+ * });
2720
+ * ```
2721
+ */
2722
+ label;
2627
2723
  constructor({
2628
2724
  qstashClient,
2629
2725
  workflowRunId,
@@ -2635,9 +2731,11 @@ var WorkflowContext = class {
2635
2731
  initialPayload,
2636
2732
  env,
2637
2733
  retries,
2734
+ retryDelay,
2638
2735
  telemetry,
2639
2736
  invokeCount,
2640
- flowControl
2737
+ flowControl,
2738
+ label
2641
2739
  }) {
2642
2740
  this.qstashClient = qstashClient;
2643
2741
  this.workflowRunId = workflowRunId;
@@ -2648,7 +2746,9 @@ var WorkflowContext = class {
2648
2746
  this.requestPayload = initialPayload;
2649
2747
  this.env = env ?? {};
2650
2748
  this.retries = retries ?? DEFAULT_RETRIES;
2749
+ this.retryDelay = retryDelay;
2651
2750
  this.flowControl = flowControl;
2751
+ this.label = label;
2652
2752
  this.executor = new AutoExecutor(this, this.steps, telemetry, invokeCount, debug);
2653
2753
  }
2654
2754
  /**
@@ -2729,6 +2829,7 @@ var WorkflowContext = class {
2729
2829
  settings.body,
2730
2830
  settings.headers || {},
2731
2831
  settings.retries || 0,
2832
+ settings.retryDelay,
2732
2833
  settings.timeout,
2733
2834
  settings.flowControl ?? settings.workflow.options.flowControl
2734
2835
  );
@@ -2739,6 +2840,7 @@ var WorkflowContext = class {
2739
2840
  body,
2740
2841
  headers = {},
2741
2842
  retries = 0,
2843
+ retryDelay,
2742
2844
  timeout,
2743
2845
  flowControl
2744
2846
  } = settings;
@@ -2749,6 +2851,7 @@ var WorkflowContext = class {
2749
2851
  body,
2750
2852
  headers,
2751
2853
  retries,
2854
+ retryDelay,
2752
2855
  timeout,
2753
2856
  flowControl
2754
2857
  );
@@ -2759,7 +2862,7 @@ var WorkflowContext = class {
2759
2862
  * Pauses workflow execution until a specific event occurs or a timeout is reached.
2760
2863
  *
2761
2864
  *```ts
2762
- * const result = await workflow.waitForEvent("payment-confirmed", {
2865
+ * const result = await workflow.waitForEvent("payment-confirmed", "payment.confirmed", {
2763
2866
  * timeout: "5m"
2764
2867
  * });
2765
2868
  *```
@@ -2785,7 +2888,7 @@ var WorkflowContext = class {
2785
2888
  * @param stepName
2786
2889
  * @param eventId - Unique identifier for the event to wait for
2787
2890
  * @param options - Configuration options.
2788
- * @returns `{ timeout: boolean, eventData: unknown }`.
2891
+ * @returns `{ timeout: boolean, eventData: TEventData }`.
2789
2892
  * The `timeout` property specifies if the workflow has timed out. The `eventData`
2790
2893
  * is the data passed when notifying this workflow of an event.
2791
2894
  */
@@ -2945,7 +3048,9 @@ var DisabledWorkflowContext = class _DisabledWorkflowContext extends WorkflowCon
2945
3048
  initialPayload: context.requestPayload,
2946
3049
  env: context.env,
2947
3050
  retries: context.retries,
2948
- flowControl: context.flowControl
3051
+ retryDelay: context.retryDelay,
3052
+ flowControl: context.flowControl,
3053
+ label: context.label
2949
3054
  });
2950
3055
  try {
2951
3056
  await routeFunction(disabledContext);
@@ -2953,6 +3058,9 @@ var DisabledWorkflowContext = class _DisabledWorkflowContext extends WorkflowCon
2953
3058
  if (error instanceof WorkflowAbort && error.stepName === this.disabledMessage || error instanceof WorkflowNonRetryableError) {
2954
3059
  return ok("step-found");
2955
3060
  }
3061
+ console.warn(
3062
+ "Upstash Workflow: Received an error while authorizing request. Please avoid throwing errors before the first step of your workflow."
3063
+ );
2956
3064
  return err(error);
2957
3065
  }
2958
3066
  return ok("run-ended");
@@ -3094,9 +3202,9 @@ var parseRequest = async (requestPayload, isFirstInvocation, workflowRunId, requ
3094
3202
  };
3095
3203
  }
3096
3204
  };
3097
- var handleFailure = async (request, requestPayload, qstashClient, initialPayloadParser, routeFunction, failureFunction, env, retries, flowControl, debug) => {
3205
+ var handleFailure = async (request, requestPayload, qstashClient, initialPayloadParser, routeFunction, failureFunction, env, retries, retryDelay, flowControl, debug) => {
3098
3206
  if (request.headers.get(WORKFLOW_FAILURE_HEADER) !== "true") {
3099
- return ok("not-failure-callback");
3207
+ return ok({ result: "not-failure-callback" });
3100
3208
  }
3101
3209
  if (!failureFunction) {
3102
3210
  return err(
@@ -3119,20 +3227,23 @@ var handleFailure = async (request, requestPayload, qstashClient, initialPayload
3119
3227
  if (!errorMessage) {
3120
3228
  errorMessage = `Couldn't parse 'failResponse' in 'failureFunction', received: '${decodedBody}'`;
3121
3229
  }
3230
+ const userHeaders = recreateUserHeaders(request.headers);
3122
3231
  const workflowContext = new WorkflowContext({
3123
3232
  qstashClient,
3124
3233
  workflowRunId,
3125
3234
  initialPayload: sourceBody ? initialPayloadParser(decodeBase64(sourceBody)) : void 0,
3126
- headers: recreateUserHeaders(request.headers),
3235
+ headers: userHeaders,
3127
3236
  steps: [],
3128
3237
  url,
3129
3238
  failureUrl: url,
3130
3239
  debug,
3131
3240
  env,
3132
3241
  retries,
3242
+ retryDelay,
3133
3243
  flowControl,
3134
- telemetry: void 0
3244
+ telemetry: void 0,
3135
3245
  // not going to make requests in authentication check
3246
+ label: userHeaders.get(WORKFLOW_LABEL_HEADER) ?? void 0
3136
3247
  });
3137
3248
  const authCheck = await DisabledWorkflowContext.tryAuthentication(
3138
3249
  routeFunction,
@@ -3144,16 +3255,16 @@ var handleFailure = async (request, requestPayload, qstashClient, initialPayload
3144
3255
  } else if (authCheck.value === "run-ended") {
3145
3256
  return err(new WorkflowError("Not authorized to run the failure function."));
3146
3257
  }
3147
- await failureFunction({
3258
+ const failureResponse = await failureFunction({
3148
3259
  context: workflowContext,
3149
3260
  failStatus: status,
3150
3261
  failResponse: errorMessage,
3151
3262
  failHeaders: header
3152
3263
  });
3264
+ return ok({ result: "is-failure-callback", response: failureResponse });
3153
3265
  } catch (error) {
3154
3266
  return err(error);
3155
3267
  }
3156
- return ok("is-failure-callback");
3157
3268
  };
3158
3269
 
3159
3270
  // src/serve/options.ts
@@ -3169,8 +3280,8 @@ var processOptions = (options) => {
3169
3280
  baseUrl: environment.QSTASH_URL,
3170
3281
  token: environment.QSTASH_TOKEN
3171
3282
  }),
3172
- onStepFinish: (workflowRunId, finishCondition) => {
3173
- if (finishCondition === "auth-fail") {
3283
+ onStepFinish: (workflowRunId, _finishCondition, detailedFinishCondition) => {
3284
+ if (detailedFinishCondition?.condition === "auth-fail") {
3174
3285
  console.error(AUTH_FAIL_MESSAGE);
3175
3286
  return new Response(
3176
3287
  JSON.stringify({
@@ -3178,19 +3289,33 @@ var processOptions = (options) => {
3178
3289
  workflowRunId
3179
3290
  }),
3180
3291
  {
3181
- status: 400
3292
+ status: 400,
3293
+ headers: {
3294
+ [WORKFLOW_PROTOCOL_VERSION_HEADER]: WORKFLOW_PROTOCOL_VERSION
3295
+ }
3182
3296
  }
3183
3297
  );
3184
- } else if (finishCondition instanceof WorkflowNonRetryableError) {
3185
- return new Response(JSON.stringify(formatWorkflowError(finishCondition)), {
3298
+ } else if (detailedFinishCondition?.condition === "non-retryable-error") {
3299
+ return new Response(JSON.stringify(formatWorkflowError(detailedFinishCondition.result)), {
3186
3300
  headers: {
3187
- "Upstash-NonRetryable-Error": "true"
3301
+ "Upstash-NonRetryable-Error": "true",
3302
+ [WORKFLOW_PROTOCOL_VERSION_HEADER]: WORKFLOW_PROTOCOL_VERSION
3188
3303
  },
3189
3304
  status: 489
3190
3305
  });
3306
+ } else if (detailedFinishCondition?.condition === "failure-callback") {
3307
+ return new Response(detailedFinishCondition.result ?? void 0, {
3308
+ status: 200,
3309
+ headers: {
3310
+ [WORKFLOW_PROTOCOL_VERSION_HEADER]: WORKFLOW_PROTOCOL_VERSION
3311
+ }
3312
+ });
3191
3313
  }
3192
3314
  return new Response(JSON.stringify({ workflowRunId }), {
3193
- status: 200
3315
+ status: 200,
3316
+ headers: {
3317
+ [WORKFLOW_PROTOCOL_VERSION_HEADER]: WORKFLOW_PROTOCOL_VERSION
3318
+ }
3194
3319
  });
3195
3320
  },
3196
3321
  initialPayloadParser: (initialRequest) => {
@@ -3264,6 +3389,7 @@ var serveBase = (routeFunction, telemetry, options) => {
3264
3389
  baseUrl,
3265
3390
  env,
3266
3391
  retries,
3392
+ retryDelay,
3267
3393
  useJSONContent,
3268
3394
  disableTelemetry,
3269
3395
  flowControl,
@@ -3294,10 +3420,14 @@ var serveBase = (routeFunction, telemetry, options) => {
3294
3420
  debug
3295
3421
  );
3296
3422
  if (workflowRunEnded) {
3297
- return onStepFinish(workflowRunId, "workflow-already-ended");
3423
+ return onStepFinish(workflowRunId, "workflow-already-ended", {
3424
+ condition: "workflow-already-ended"
3425
+ });
3298
3426
  }
3299
3427
  if (isLastDuplicate) {
3300
- return onStepFinish(workflowRunId, "duplicate-step");
3428
+ return onStepFinish(workflowRunId, "duplicate-step", {
3429
+ condition: "duplicate-step"
3430
+ });
3301
3431
  }
3302
3432
  const failureCheck = await handleFailure(
3303
3433
  request,
@@ -3308,16 +3438,21 @@ var serveBase = (routeFunction, telemetry, options) => {
3308
3438
  failureFunction,
3309
3439
  env,
3310
3440
  retries,
3441
+ retryDelay,
3311
3442
  flowControl,
3312
3443
  debug
3313
3444
  );
3314
3445
  if (failureCheck.isErr()) {
3315
3446
  throw failureCheck.error;
3316
- } else if (failureCheck.value === "is-failure-callback") {
3447
+ } else if (failureCheck.value.result === "is-failure-callback") {
3317
3448
  await debug?.log("WARN", "RESPONSE_DEFAULT", "failureFunction executed");
3318
- return onStepFinish(workflowRunId, "failure-callback");
3449
+ return onStepFinish(workflowRunId, "failure-callback", {
3450
+ condition: "failure-callback",
3451
+ result: failureCheck.value.response
3452
+ });
3319
3453
  }
3320
3454
  const invokeCount = Number(request.headers.get(WORKFLOW_INVOKE_COUNT_HEADER) ?? "0");
3455
+ const label = request.headers.get(WORKFLOW_LABEL_HEADER) ?? void 0;
3321
3456
  const workflowContext = new WorkflowContext({
3322
3457
  qstashClient,
3323
3458
  workflowRunId,
@@ -3329,9 +3464,11 @@ var serveBase = (routeFunction, telemetry, options) => {
3329
3464
  debug,
3330
3465
  env,
3331
3466
  retries,
3467
+ retryDelay,
3332
3468
  telemetry,
3333
3469
  invokeCount,
3334
- flowControl
3470
+ flowControl,
3471
+ label
3335
3472
  });
3336
3473
  const authCheck = await DisabledWorkflowContext.tryAuthentication(
3337
3474
  routeFunction,
@@ -3344,7 +3481,8 @@ var serveBase = (routeFunction, telemetry, options) => {
3344
3481
  await debug?.log("ERROR", "ERROR", { error: AUTH_FAIL_MESSAGE });
3345
3482
  return onStepFinish(
3346
3483
  isFirstInvocation ? "no-workflow-id" : workflowContext.workflowRunId,
3347
- "auth-fail"
3484
+ "auth-fail",
3485
+ { condition: "auth-fail" }
3348
3486
  );
3349
3487
  }
3350
3488
  const callReturnCheck = await handleThirdPartyCallResult({
@@ -3354,6 +3492,7 @@ var serveBase = (routeFunction, telemetry, options) => {
3354
3492
  workflowUrl,
3355
3493
  failureUrl: workflowFailureUrl,
3356
3494
  retries,
3495
+ retryDelay,
3357
3496
  flowControl,
3358
3497
  telemetry,
3359
3498
  debug
@@ -3381,19 +3520,28 @@ var serveBase = (routeFunction, telemetry, options) => {
3381
3520
  debug
3382
3521
  });
3383
3522
  if (result.isOk() && result.value instanceof WorkflowNonRetryableError) {
3384
- return onStepFinish(workflowRunId, result.value);
3523
+ return onStepFinish(workflowRunId, result.value, {
3524
+ condition: "non-retryable-error",
3525
+ result: result.value
3526
+ });
3385
3527
  }
3386
3528
  if (result.isErr()) {
3387
3529
  await debug?.log("ERROR", "ERROR", { error: result.error.message });
3388
3530
  throw result.error;
3389
3531
  }
3390
3532
  await debug?.log("INFO", "RESPONSE_WORKFLOW");
3391
- return onStepFinish(workflowContext.workflowRunId, "success");
3533
+ return onStepFinish(workflowContext.workflowRunId, "success", {
3534
+ condition: "success"
3535
+ });
3392
3536
  } else if (callReturnCheck.value === "workflow-ended") {
3393
- return onStepFinish(workflowContext.workflowRunId, "workflow-already-ended");
3537
+ return onStepFinish(workflowContext.workflowRunId, "workflow-already-ended", {
3538
+ condition: "workflow-already-ended"
3539
+ });
3394
3540
  }
3395
3541
  await debug?.log("INFO", "RESPONSE_DEFAULT");
3396
- return onStepFinish("no-workflow-id", "fromCallback");
3542
+ return onStepFinish("no-workflow-id", "fromCallback", {
3543
+ condition: "fromCallback"
3544
+ });
3397
3545
  };
3398
3546
  const safeHandler = async (request) => {
3399
3547
  try {
@@ -3408,11 +3556,17 @@ var serveBase = (routeFunction, telemetry, options) => {
3408
3556
  Original error: '${formattedError.message}'`;
3409
3557
  console.error(errorMessage);
3410
3558
  return new Response(errorMessage, {
3411
- status: 500
3559
+ status: 500,
3560
+ headers: {
3561
+ [WORKFLOW_PROTOCOL_VERSION_HEADER]: WORKFLOW_PROTOCOL_VERSION
3562
+ }
3412
3563
  });
3413
3564
  }
3414
3565
  return new Response(JSON.stringify(formattedError), {
3415
- status: 500
3566
+ status: 500,
3567
+ headers: {
3568
+ [WORKFLOW_PROTOCOL_VERSION_HEADER]: WORKFLOW_PROTOCOL_VERSION
3569
+ }
3416
3570
  });
3417
3571
  }
3418
3572
  };
package/solidjs.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  SDK_TELEMETRY,
3
3
  serveBase
4
- } from "./chunk-TGEGSOSN.mjs";
4
+ } from "./chunk-EHL7SSJF.mjs";
5
5
 
6
6
  // platforms/solidjs.ts
7
7
  var serve = (routeFunction, options) => {
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, n as PublicServeOptions, w as InvokableWorkflow } from './types-Dd-3bPoU.mjs';
4
- import { s as serveManyBase } from './serve-many-AFwJPR3S.mjs';
3
+ import { R as RouteFunction, n as PublicServeOptions, x as InvokableWorkflow } from './types-B7_5AkKQ.mjs';
4
+ import { s as serveManyBase } from './serve-many-CEUYWQvV.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, n as PublicServeOptions, w as InvokableWorkflow } from './types-Dd-3bPoU.js';
4
- import { s as serveManyBase } from './serve-many-AaKSQyi7.js';
3
+ import { R as RouteFunction, n as PublicServeOptions, x as InvokableWorkflow } from './types-B7_5AkKQ.js';
4
+ import { s as serveManyBase } from './serve-many-BObe3pdI.js';
5
5
  import '@upstash/qstash';
6
6
  import 'zod';
7
7
  import 'ai';