@upstash/workflow 0.2.16 → 0.2.17

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
@@ -89,7 +89,7 @@ var WORKFLOW_PROTOCOL_VERSION_HEADER = "Upstash-Workflow-Sdk-Version";
89
89
  var DEFAULT_CONTENT_TYPE = "application/json";
90
90
  var NO_CONCURRENCY = 1;
91
91
  var DEFAULT_RETRIES = 3;
92
- var VERSION = "v0.2.15";
92
+ var VERSION = "v0.2.17";
93
93
  var SDK_TELEMETRY = `@upstash/workflow@${VERSION}`;
94
94
  var TELEMETRY_HEADER_SDK = "Upstash-Telemetry-Sdk";
95
95
  var TELEMETRY_HEADER_FRAMEWORK = "Upstash-Telemetry-Framework";
@@ -619,6 +619,7 @@ var triggerFirstInvocation = async (params) => {
619
619
  workflowUrl: workflowContext.url,
620
620
  failureUrl: workflowContext.failureUrl,
621
621
  retries: workflowContext.retries,
622
+ retryDelay: workflowContext.retryDelay,
622
623
  telemetry,
623
624
  flowControl: workflowContext.flowControl,
624
625
  useJSONContent: useJSONContent ?? false
@@ -748,6 +749,7 @@ var handleThirdPartyCallResult = async ({
748
749
  workflowUrl,
749
750
  failureUrl,
750
751
  retries,
752
+ retryDelay,
751
753
  telemetry,
752
754
  flowControl,
753
755
  debug
@@ -818,6 +820,7 @@ ${atob(callbackMessage.body ?? "")}`
818
820
  workflowUrl,
819
821
  failureUrl,
820
822
  retries,
823
+ retryDelay,
821
824
  telemetry,
822
825
  flowControl
823
826
  },
@@ -968,7 +971,8 @@ var BaseLazyStep = class _BaseLazyStep {
968
971
  workflowRunId: context.workflowRunId,
969
972
  workflowUrl: context.url,
970
973
  failureUrl: context.failureUrl,
971
- retries: context.retries,
974
+ retries: DEFAULT_RETRIES === context.retries ? void 0 : context.retries,
975
+ retryDelay: context.retryDelay,
972
976
  useJSONContent: false,
973
977
  telemetry,
974
978
  flowControl: context.flowControl
@@ -987,6 +991,9 @@ var BaseLazyStep = class _BaseLazyStep {
987
991
  body,
988
992
  headers,
989
993
  method: "POST",
994
+ retries: DEFAULT_RETRIES === context.retries ? void 0 : context.retries,
995
+ retryDelay: context.retryDelay,
996
+ flowControl: context.flowControl,
990
997
  url: context.url
991
998
  }
992
999
  ]);
@@ -1057,6 +1064,9 @@ var LazySleepStep = class extends BaseLazyStep {
1057
1064
  headers,
1058
1065
  method: "POST",
1059
1066
  url: context.url,
1067
+ retries: DEFAULT_RETRIES === context.retries ? void 0 : context.retries,
1068
+ retryDelay: context.retryDelay,
1069
+ flowControl: context.flowControl,
1060
1070
  delay: isParallel ? void 0 : this.sleep
1061
1071
  }
1062
1072
  ]);
@@ -1099,6 +1109,9 @@ var LazySleepUntilStep = class extends BaseLazyStep {
1099
1109
  headers,
1100
1110
  method: "POST",
1101
1111
  url: context.url,
1112
+ retries: DEFAULT_RETRIES === context.retries ? void 0 : context.retries,
1113
+ retryDelay: context.retryDelay,
1114
+ flowControl: context.flowControl,
1102
1115
  notBefore: isParallel ? void 0 : this.sleepUntil
1103
1116
  }
1104
1117
  ]);
@@ -1110,17 +1123,19 @@ var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
1110
1123
  body;
1111
1124
  headers;
1112
1125
  retries;
1126
+ retryDelay;
1113
1127
  timeout;
1114
1128
  flowControl;
1115
1129
  stepType = "Call";
1116
1130
  allowUndefinedOut = false;
1117
- constructor(stepName, url, method, body, headers, retries, timeout, flowControl) {
1131
+ constructor(stepName, url, method, body, headers, retries, retryDelay, timeout, flowControl) {
1118
1132
  super(stepName);
1119
1133
  this.url = url;
1120
1134
  this.method = method;
1121
1135
  this.body = body;
1122
1136
  this.headers = headers;
1123
1137
  this.retries = retries;
1138
+ this.retryDelay = retryDelay;
1124
1139
  this.timeout = timeout;
1125
1140
  this.flowControl = flowControl;
1126
1141
  }
@@ -1195,6 +1210,9 @@ var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
1195
1210
  getHeaders({ context, telemetry, invokeCount, step }) {
1196
1211
  const { headers, contentType } = super.getHeaders({ context, telemetry, invokeCount, step });
1197
1212
  headers["Upstash-Retries"] = this.retries.toString();
1213
+ if (this.retryDelay) {
1214
+ headers["Upstash-Retry-Delay"] = this.retryDelay;
1215
+ }
1198
1216
  headers[WORKFLOW_FEATURE_HEADER] = "WF_NoDelete,InitialBody";
1199
1217
  if (this.flowControl) {
1200
1218
  const { flowControlKey, flowControlValue } = prepareFlowControl(this.flowControl);
@@ -1216,7 +1234,7 @@ var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
1216
1234
  "Upstash-Callback-Workflow-CallType": "fromCallback",
1217
1235
  "Upstash-Callback-Workflow-Init": "false",
1218
1236
  "Upstash-Callback-Workflow-Url": context.url,
1219
- "Upstash-Callback-Feature-Set": "LazyFetch,InitialBody",
1237
+ "Upstash-Callback-Feature-Set": "LazyFetch,InitialBody,WF_DetectTrigger",
1220
1238
  "Upstash-Callback-Forward-Upstash-Workflow-Callback": "true",
1221
1239
  "Upstash-Callback-Forward-Upstash-Workflow-StepId": step.stepId.toString(),
1222
1240
  "Upstash-Callback-Forward-Upstash-Workflow-StepName": this.stepName,
@@ -1234,7 +1252,10 @@ var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
1234
1252
  headers,
1235
1253
  body: JSON.stringify(this.body),
1236
1254
  method: this.method,
1237
- url: this.url
1255
+ url: this.url,
1256
+ retries: DEFAULT_RETRIES === this.retries ? void 0 : this.retries,
1257
+ retryDelay: this.retryDelay,
1258
+ flowControl: this.flowControl
1238
1259
  }
1239
1260
  ]);
1240
1261
  }
@@ -1363,6 +1384,7 @@ var LazyInvokeStep = class extends BaseLazyStep {
1363
1384
  headers = {},
1364
1385
  workflowRunId,
1365
1386
  retries,
1387
+ retryDelay,
1366
1388
  flowControl
1367
1389
  }) {
1368
1390
  super(stepName);
@@ -1372,6 +1394,7 @@ var LazyInvokeStep = class extends BaseLazyStep {
1372
1394
  headers,
1373
1395
  workflowRunId: getWorkflowRunId(workflowRunId),
1374
1396
  retries,
1397
+ retryDelay,
1375
1398
  flowControl
1376
1399
  };
1377
1400
  const { workflowId } = workflow;
@@ -1416,6 +1439,7 @@ var LazyInvokeStep = class extends BaseLazyStep {
1416
1439
  workflowUrl: context.url,
1417
1440
  failureUrl: context.failureUrl,
1418
1441
  retries: context.retries,
1442
+ retryDelay: context.retryDelay,
1419
1443
  telemetry,
1420
1444
  flowControl: context.flowControl,
1421
1445
  useJSONContent: false
@@ -1441,11 +1465,13 @@ var LazyInvokeStep = class extends BaseLazyStep {
1441
1465
  headers = {},
1442
1466
  workflowRunId = getWorkflowRunId(),
1443
1467
  retries,
1468
+ retryDelay,
1444
1469
  flowControl
1445
1470
  } = this.params;
1446
1471
  const newUrl = context.url.replace(/[^/]+$/, this.workflowId);
1447
1472
  const {
1448
1473
  retries: workflowRetries,
1474
+ retryDelay: workflowRetryDelay,
1449
1475
  failureFunction,
1450
1476
  failureUrl,
1451
1477
  useJSONContent,
@@ -1457,6 +1483,7 @@ var LazyInvokeStep = class extends BaseLazyStep {
1457
1483
  workflowRunId,
1458
1484
  workflowUrl: newUrl,
1459
1485
  retries: retries ?? workflowRetries,
1486
+ retryDelay: retryDelay ?? workflowRetryDelay,
1460
1487
  telemetry,
1461
1488
  failureUrl: failureFunction ? newUrl : failureUrl,
1462
1489
  flowControl: flowControl ?? workflowFlowControl,
@@ -1523,6 +1550,7 @@ var WorkflowHeaders = class {
1523
1550
  getHeaders() {
1524
1551
  this.addBaseHeaders();
1525
1552
  this.addRetries();
1553
+ this.addRetryDelay();
1526
1554
  this.addFlowControl();
1527
1555
  this.addUserHeaders();
1528
1556
  this.addInvokeCount();
@@ -1536,7 +1564,7 @@ var WorkflowHeaders = class {
1536
1564
  [WORKFLOW_INIT_HEADER]: this.initHeaderValue,
1537
1565
  [WORKFLOW_ID_HEADER]: this.workflowConfig.workflowRunId,
1538
1566
  [WORKFLOW_URL_HEADER]: this.workflowConfig.workflowUrl,
1539
- [WORKFLOW_FEATURE_HEADER]: "LazyFetch,InitialBody",
1567
+ [WORKFLOW_FEATURE_HEADER]: "LazyFetch,InitialBody,WF_DetectTrigger",
1540
1568
  [WORKFLOW_PROTOCOL_VERSION_HEADER]: WORKFLOW_PROTOCOL_VERSION,
1541
1569
  ...this.workflowConfig.telemetry ? getTelemetryHeaders(this.workflowConfig.telemetry) : {},
1542
1570
  ...this.workflowConfig.telemetry && this.stepInfo?.lazyStep instanceof LazyCallStep && this.stepInfo.lazyStep.headers[AGENT_NAME_HEADER] ? { [TELEMETRY_HEADER_AGENT]: "true" } : {}
@@ -1568,6 +1596,16 @@ var WorkflowHeaders = class {
1568
1596
  this.headers.failureHeaders["Retries"] = retries;
1569
1597
  }
1570
1598
  }
1599
+ addRetryDelay() {
1600
+ if (this.workflowConfig.retryDelay === void 0 || this.workflowConfig.retryDelay === "") {
1601
+ return;
1602
+ }
1603
+ const retryDelay = this.workflowConfig.retryDelay.toString();
1604
+ this.headers.workflowHeaders["Retry-Delay"] = retryDelay;
1605
+ if (this.workflowConfig.failureUrl) {
1606
+ this.headers.failureHeaders["Retry-Delay"] = retryDelay;
1607
+ }
1608
+ }
1571
1609
  addFlowControl() {
1572
1610
  if (!this.workflowConfig.flowControl) {
1573
1611
  return;
@@ -1602,10 +1640,13 @@ var WorkflowHeaders = class {
1602
1640
  this.headers.failureHeaders["Workflow-Init"] = "false";
1603
1641
  this.headers.failureHeaders["Workflow-Url"] = this.workflowConfig.workflowUrl;
1604
1642
  this.headers.failureHeaders["Workflow-Calltype"] = "failureCall";
1605
- this.headers.failureHeaders["Feature-Set"] = "LazyFetch,InitialBody";
1643
+ this.headers.failureHeaders["Feature-Set"] = "LazyFetch,InitialBody,WF_DetectTrigger";
1606
1644
  if (this.workflowConfig.retries !== void 0 && this.workflowConfig.retries !== DEFAULT_RETRIES) {
1607
1645
  this.headers.failureHeaders["Retries"] = this.workflowConfig.retries.toString();
1608
1646
  }
1647
+ if (this.workflowConfig.retryDelay !== void 0 && this.workflowConfig.retryDelay !== "") {
1648
+ this.headers.failureHeaders["Retry-Delay"] = this.workflowConfig.retryDelay.toString();
1649
+ }
1609
1650
  }
1610
1651
  addContentType() {
1611
1652
  if (this.workflowConfig.useJSONContent) {
@@ -1687,6 +1728,7 @@ var submitParallelSteps = async ({
1687
1728
  workflowUrl: context.url,
1688
1729
  failureUrl: context.failureUrl,
1689
1730
  retries: context.retries,
1731
+ retryDelay: context.retryDelay,
1690
1732
  flowControl: context.flowControl,
1691
1733
  telemetry
1692
1734
  },
@@ -2107,7 +2149,7 @@ var BaseWorkflowApi = class {
2107
2149
  */
2108
2150
  async callApi(stepName, settings) {
2109
2151
  const { url, appendHeaders, method } = getProviderInfo(settings.api);
2110
- const { method: userMethod, body, headers = {}, retries = 0, timeout } = settings;
2152
+ const { method: userMethod, body, headers = {}, retries = 0, retryDelay, timeout } = settings;
2111
2153
  return await this.context.call(stepName, {
2112
2154
  url,
2113
2155
  method: userMethod ?? method,
@@ -2117,6 +2159,7 @@ var BaseWorkflowApi = class {
2117
2159
  ...headers
2118
2160
  },
2119
2161
  retries,
2162
+ retryDelay,
2120
2163
  timeout
2121
2164
  });
2122
2165
  }
@@ -2206,6 +2249,7 @@ var fetchWithContextCall = async (context, agentCallParams, ...params) => {
2206
2249
  body,
2207
2250
  timeout: agentCallParams?.timeout,
2208
2251
  retries: agentCallParams?.retries,
2252
+ retryDelay: agentCallParams?.retryDelay,
2209
2253
  flowControl: agentCallParams?.flowControl
2210
2254
  });
2211
2255
  const responseHeaders = new Headers(
@@ -2619,6 +2663,37 @@ var WorkflowContext = class {
2619
2663
  * Number of retries
2620
2664
  */
2621
2665
  retries;
2666
+ /**
2667
+ * Delay between retries.
2668
+ *
2669
+ * By default, the `retryDelay` is exponential backoff.
2670
+ * More details can be found in: https://upstash.com/docs/qstash/features/retry.
2671
+ *
2672
+ * The `retryDelay` option allows you to customize the delay (in milliseconds) between retry attempts when message delivery fails.
2673
+ *
2674
+ * You can use mathematical expressions and the following built-in functions to calculate the delay dynamically.
2675
+ * The special variable `retried` represents the current retry attempt count (starting from 0).
2676
+ *
2677
+ * Supported functions:
2678
+ * - `pow`
2679
+ * - `sqrt`
2680
+ * - `abs`
2681
+ * - `exp`
2682
+ * - `floor`
2683
+ * - `ceil`
2684
+ * - `round`
2685
+ * - `min`
2686
+ * - `max`
2687
+ *
2688
+ * Examples of valid `retryDelay` values:
2689
+ * ```ts
2690
+ * 1000 // 1 second
2691
+ * 1000 * (1 + retried) // 1 second multiplied by the current retry attempt
2692
+ * pow(2, retried) // 2 to the power of the current retry attempt
2693
+ * max(10, pow(2, retried)) // The greater of 10 or 2^retried
2694
+ * ```
2695
+ */
2696
+ retryDelay;
2622
2697
  /**
2623
2698
  * Settings for controlling the number of active requests
2624
2699
  * and number of requests per second with the same key.
@@ -2635,6 +2710,7 @@ var WorkflowContext = class {
2635
2710
  initialPayload,
2636
2711
  env,
2637
2712
  retries,
2713
+ retryDelay,
2638
2714
  telemetry,
2639
2715
  invokeCount,
2640
2716
  flowControl
@@ -2648,6 +2724,7 @@ var WorkflowContext = class {
2648
2724
  this.requestPayload = initialPayload;
2649
2725
  this.env = env ?? {};
2650
2726
  this.retries = retries ?? DEFAULT_RETRIES;
2727
+ this.retryDelay = retryDelay;
2651
2728
  this.flowControl = flowControl;
2652
2729
  this.executor = new AutoExecutor(this, this.steps, telemetry, invokeCount, debug);
2653
2730
  }
@@ -2729,6 +2806,7 @@ var WorkflowContext = class {
2729
2806
  settings.body,
2730
2807
  settings.headers || {},
2731
2808
  settings.retries || 0,
2809
+ settings.retryDelay,
2732
2810
  settings.timeout,
2733
2811
  settings.flowControl ?? settings.workflow.options.flowControl
2734
2812
  );
@@ -2739,6 +2817,7 @@ var WorkflowContext = class {
2739
2817
  body,
2740
2818
  headers = {},
2741
2819
  retries = 0,
2820
+ retryDelay,
2742
2821
  timeout,
2743
2822
  flowControl
2744
2823
  } = settings;
@@ -2749,6 +2828,7 @@ var WorkflowContext = class {
2749
2828
  body,
2750
2829
  headers,
2751
2830
  retries,
2831
+ retryDelay,
2752
2832
  timeout,
2753
2833
  flowControl
2754
2834
  );
@@ -2759,7 +2839,7 @@ var WorkflowContext = class {
2759
2839
  * Pauses workflow execution until a specific event occurs or a timeout is reached.
2760
2840
  *
2761
2841
  *```ts
2762
- * const result = await workflow.waitForEvent("payment-confirmed", {
2842
+ * const result = await workflow.waitForEvent("payment-confirmed", "payment.confirmed", {
2763
2843
  * timeout: "5m"
2764
2844
  * });
2765
2845
  *```
@@ -2785,7 +2865,7 @@ var WorkflowContext = class {
2785
2865
  * @param stepName
2786
2866
  * @param eventId - Unique identifier for the event to wait for
2787
2867
  * @param options - Configuration options.
2788
- * @returns `{ timeout: boolean, eventData: unknown }`.
2868
+ * @returns `{ timeout: boolean, eventData: TEventData }`.
2789
2869
  * The `timeout` property specifies if the workflow has timed out. The `eventData`
2790
2870
  * is the data passed when notifying this workflow of an event.
2791
2871
  */
@@ -2945,6 +3025,7 @@ var DisabledWorkflowContext = class _DisabledWorkflowContext extends WorkflowCon
2945
3025
  initialPayload: context.requestPayload,
2946
3026
  env: context.env,
2947
3027
  retries: context.retries,
3028
+ retryDelay: context.retryDelay,
2948
3029
  flowControl: context.flowControl
2949
3030
  });
2950
3031
  try {
@@ -2953,6 +3034,9 @@ var DisabledWorkflowContext = class _DisabledWorkflowContext extends WorkflowCon
2953
3034
  if (error instanceof WorkflowAbort && error.stepName === this.disabledMessage || error instanceof WorkflowNonRetryableError) {
2954
3035
  return ok("step-found");
2955
3036
  }
3037
+ console.warn(
3038
+ "Upstash Workflow: Received an error while authorizing request. Please avoid throwing errors before the first step of your workflow."
3039
+ );
2956
3040
  return err(error);
2957
3041
  }
2958
3042
  return ok("run-ended");
@@ -3094,9 +3178,9 @@ var parseRequest = async (requestPayload, isFirstInvocation, workflowRunId, requ
3094
3178
  };
3095
3179
  }
3096
3180
  };
3097
- var handleFailure = async (request, requestPayload, qstashClient, initialPayloadParser, routeFunction, failureFunction, env, retries, flowControl, debug) => {
3181
+ var handleFailure = async (request, requestPayload, qstashClient, initialPayloadParser, routeFunction, failureFunction, env, retries, retryDelay, flowControl, debug) => {
3098
3182
  if (request.headers.get(WORKFLOW_FAILURE_HEADER) !== "true") {
3099
- return ok("not-failure-callback");
3183
+ return ok({ result: "not-failure-callback" });
3100
3184
  }
3101
3185
  if (!failureFunction) {
3102
3186
  return err(
@@ -3130,6 +3214,7 @@ var handleFailure = async (request, requestPayload, qstashClient, initialPayload
3130
3214
  debug,
3131
3215
  env,
3132
3216
  retries,
3217
+ retryDelay,
3133
3218
  flowControl,
3134
3219
  telemetry: void 0
3135
3220
  // not going to make requests in authentication check
@@ -3144,16 +3229,16 @@ var handleFailure = async (request, requestPayload, qstashClient, initialPayload
3144
3229
  } else if (authCheck.value === "run-ended") {
3145
3230
  return err(new WorkflowError("Not authorized to run the failure function."));
3146
3231
  }
3147
- await failureFunction({
3232
+ const failureResponse = await failureFunction({
3148
3233
  context: workflowContext,
3149
3234
  failStatus: status,
3150
3235
  failResponse: errorMessage,
3151
3236
  failHeaders: header
3152
3237
  });
3238
+ return ok({ result: "is-failure-callback", response: failureResponse });
3153
3239
  } catch (error) {
3154
3240
  return err(error);
3155
3241
  }
3156
- return ok("is-failure-callback");
3157
3242
  };
3158
3243
 
3159
3244
  // src/serve/options.ts
@@ -3169,8 +3254,8 @@ var processOptions = (options) => {
3169
3254
  baseUrl: environment.QSTASH_URL,
3170
3255
  token: environment.QSTASH_TOKEN
3171
3256
  }),
3172
- onStepFinish: (workflowRunId, finishCondition) => {
3173
- if (finishCondition === "auth-fail") {
3257
+ onStepFinish: (workflowRunId, _finishCondition, detailedFinishCondition) => {
3258
+ if (detailedFinishCondition?.condition === "auth-fail") {
3174
3259
  console.error(AUTH_FAIL_MESSAGE);
3175
3260
  return new Response(
3176
3261
  JSON.stringify({
@@ -3178,19 +3263,33 @@ var processOptions = (options) => {
3178
3263
  workflowRunId
3179
3264
  }),
3180
3265
  {
3181
- status: 400
3266
+ status: 400,
3267
+ headers: {
3268
+ [WORKFLOW_PROTOCOL_VERSION_HEADER]: WORKFLOW_PROTOCOL_VERSION
3269
+ }
3182
3270
  }
3183
3271
  );
3184
- } else if (finishCondition instanceof WorkflowNonRetryableError) {
3185
- return new Response(JSON.stringify(formatWorkflowError(finishCondition)), {
3272
+ } else if (detailedFinishCondition?.condition === "non-retryable-error") {
3273
+ return new Response(JSON.stringify(formatWorkflowError(detailedFinishCondition.result)), {
3186
3274
  headers: {
3187
- "Upstash-NonRetryable-Error": "true"
3275
+ "Upstash-NonRetryable-Error": "true",
3276
+ [WORKFLOW_PROTOCOL_VERSION_HEADER]: WORKFLOW_PROTOCOL_VERSION
3188
3277
  },
3189
3278
  status: 489
3190
3279
  });
3280
+ } else if (detailedFinishCondition?.condition === "failure-callback") {
3281
+ return new Response(detailedFinishCondition.result ?? void 0, {
3282
+ status: 200,
3283
+ headers: {
3284
+ [WORKFLOW_PROTOCOL_VERSION_HEADER]: WORKFLOW_PROTOCOL_VERSION
3285
+ }
3286
+ });
3191
3287
  }
3192
3288
  return new Response(JSON.stringify({ workflowRunId }), {
3193
- status: 200
3289
+ status: 200,
3290
+ headers: {
3291
+ [WORKFLOW_PROTOCOL_VERSION_HEADER]: WORKFLOW_PROTOCOL_VERSION
3292
+ }
3194
3293
  });
3195
3294
  },
3196
3295
  initialPayloadParser: (initialRequest) => {
@@ -3264,6 +3363,7 @@ var serveBase = (routeFunction, telemetry, options) => {
3264
3363
  baseUrl,
3265
3364
  env,
3266
3365
  retries,
3366
+ retryDelay,
3267
3367
  useJSONContent,
3268
3368
  disableTelemetry,
3269
3369
  flowControl,
@@ -3294,10 +3394,14 @@ var serveBase = (routeFunction, telemetry, options) => {
3294
3394
  debug
3295
3395
  );
3296
3396
  if (workflowRunEnded) {
3297
- return onStepFinish(workflowRunId, "workflow-already-ended");
3397
+ return onStepFinish(workflowRunId, "workflow-already-ended", {
3398
+ condition: "workflow-already-ended"
3399
+ });
3298
3400
  }
3299
3401
  if (isLastDuplicate) {
3300
- return onStepFinish(workflowRunId, "duplicate-step");
3402
+ return onStepFinish(workflowRunId, "duplicate-step", {
3403
+ condition: "duplicate-step"
3404
+ });
3301
3405
  }
3302
3406
  const failureCheck = await handleFailure(
3303
3407
  request,
@@ -3308,14 +3412,18 @@ var serveBase = (routeFunction, telemetry, options) => {
3308
3412
  failureFunction,
3309
3413
  env,
3310
3414
  retries,
3415
+ retryDelay,
3311
3416
  flowControl,
3312
3417
  debug
3313
3418
  );
3314
3419
  if (failureCheck.isErr()) {
3315
3420
  throw failureCheck.error;
3316
- } else if (failureCheck.value === "is-failure-callback") {
3421
+ } else if (failureCheck.value.result === "is-failure-callback") {
3317
3422
  await debug?.log("WARN", "RESPONSE_DEFAULT", "failureFunction executed");
3318
- return onStepFinish(workflowRunId, "failure-callback");
3423
+ return onStepFinish(workflowRunId, "failure-callback", {
3424
+ condition: "failure-callback",
3425
+ result: failureCheck.value.response
3426
+ });
3319
3427
  }
3320
3428
  const invokeCount = Number(request.headers.get(WORKFLOW_INVOKE_COUNT_HEADER) ?? "0");
3321
3429
  const workflowContext = new WorkflowContext({
@@ -3329,6 +3437,7 @@ var serveBase = (routeFunction, telemetry, options) => {
3329
3437
  debug,
3330
3438
  env,
3331
3439
  retries,
3440
+ retryDelay,
3332
3441
  telemetry,
3333
3442
  invokeCount,
3334
3443
  flowControl
@@ -3344,7 +3453,8 @@ var serveBase = (routeFunction, telemetry, options) => {
3344
3453
  await debug?.log("ERROR", "ERROR", { error: AUTH_FAIL_MESSAGE });
3345
3454
  return onStepFinish(
3346
3455
  isFirstInvocation ? "no-workflow-id" : workflowContext.workflowRunId,
3347
- "auth-fail"
3456
+ "auth-fail",
3457
+ { condition: "auth-fail" }
3348
3458
  );
3349
3459
  }
3350
3460
  const callReturnCheck = await handleThirdPartyCallResult({
@@ -3354,6 +3464,7 @@ var serveBase = (routeFunction, telemetry, options) => {
3354
3464
  workflowUrl,
3355
3465
  failureUrl: workflowFailureUrl,
3356
3466
  retries,
3467
+ retryDelay,
3357
3468
  flowControl,
3358
3469
  telemetry,
3359
3470
  debug
@@ -3381,19 +3492,28 @@ var serveBase = (routeFunction, telemetry, options) => {
3381
3492
  debug
3382
3493
  });
3383
3494
  if (result.isOk() && result.value instanceof WorkflowNonRetryableError) {
3384
- return onStepFinish(workflowRunId, result.value);
3495
+ return onStepFinish(workflowRunId, result.value, {
3496
+ condition: "non-retryable-error",
3497
+ result: result.value
3498
+ });
3385
3499
  }
3386
3500
  if (result.isErr()) {
3387
3501
  await debug?.log("ERROR", "ERROR", { error: result.error.message });
3388
3502
  throw result.error;
3389
3503
  }
3390
3504
  await debug?.log("INFO", "RESPONSE_WORKFLOW");
3391
- return onStepFinish(workflowContext.workflowRunId, "success");
3505
+ return onStepFinish(workflowContext.workflowRunId, "success", {
3506
+ condition: "success"
3507
+ });
3392
3508
  } else if (callReturnCheck.value === "workflow-ended") {
3393
- return onStepFinish(workflowContext.workflowRunId, "workflow-already-ended");
3509
+ return onStepFinish(workflowContext.workflowRunId, "workflow-already-ended", {
3510
+ condition: "workflow-already-ended"
3511
+ });
3394
3512
  }
3395
3513
  await debug?.log("INFO", "RESPONSE_DEFAULT");
3396
- return onStepFinish("no-workflow-id", "fromCallback");
3514
+ return onStepFinish("no-workflow-id", "fromCallback", {
3515
+ condition: "fromCallback"
3516
+ });
3397
3517
  };
3398
3518
  const safeHandler = async (request) => {
3399
3519
  try {
@@ -3408,11 +3528,17 @@ var serveBase = (routeFunction, telemetry, options) => {
3408
3528
  Original error: '${formattedError.message}'`;
3409
3529
  console.error(errorMessage);
3410
3530
  return new Response(errorMessage, {
3411
- status: 500
3531
+ status: 500,
3532
+ headers: {
3533
+ [WORKFLOW_PROTOCOL_VERSION_HEADER]: WORKFLOW_PROTOCOL_VERSION
3534
+ }
3412
3535
  });
3413
3536
  }
3414
3537
  return new Response(JSON.stringify(formattedError), {
3415
- status: 500
3538
+ status: 500,
3539
+ headers: {
3540
+ [WORKFLOW_PROTOCOL_VERSION_HEADER]: WORKFLOW_PROTOCOL_VERSION
3541
+ }
3416
3542
  });
3417
3543
  }
3418
3544
  };
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-RP7G4UD5.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--R_3XZXz.mjs';
4
+ import { s as serveManyBase } from './serve-many-DgDSOvQs.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--R_3XZXz.js';
4
+ import { s as serveManyBase } from './serve-many-B3DfoTFt.js';
5
5
  import '@upstash/qstash';
6
6
  import 'zod';
7
7
  import 'ai';