@upstash/workflow 1.4.0-rc → 1.5.0

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.
Files changed (223) hide show
  1. package/README.md +9 -0
  2. package/astro.d.mts +18 -2
  3. package/astro.d.ts +18 -2
  4. package/astro.js +129 -29
  5. package/astro.mjs +1 -1
  6. package/{chunk-UH6O5IJY.mjs → chunk-J3PXPHSB.mjs} +129 -29
  7. package/cloudflare.d.mts +16 -2
  8. package/cloudflare.d.ts +16 -2
  9. package/cloudflare.js +129 -29
  10. package/cloudflare.mjs +1 -1
  11. package/docs/agents/examples.mdx +8 -0
  12. package/docs/agents/features.mdx +374 -0
  13. package/docs/agents/getting-started.mdx +139 -0
  14. package/docs/agents/overview.mdx +40 -0
  15. package/docs/agents/patterns/evaluator-optimizer.mdx +72 -0
  16. package/docs/agents/patterns/orchestrator-workers.mdx +95 -0
  17. package/docs/agents/patterns/parallelization.mdx +77 -0
  18. package/docs/agents/patterns/prompt-chaining.mdx +84 -0
  19. package/docs/basics/best-practices/at-least-one-step.mdx +57 -0
  20. package/docs/basics/best-practices/business-logic-in-steps.mdx +52 -0
  21. package/docs/basics/best-practices/deterministic-code.mdx +132 -0
  22. package/docs/basics/best-practices/idempotency.mdx +38 -0
  23. package/docs/basics/best-practices/nested-context-methods.mdx +38 -0
  24. package/docs/basics/best-practices/overview.mdx +35 -0
  25. package/docs/basics/best-practices/promise-any.mdx +9 -0
  26. package/docs/basics/best-practices/return-step-results.mdx +80 -0
  27. package/docs/basics/best-practices/workflow-limits.mdx +62 -0
  28. package/docs/basics/client/cancel.mdx +137 -0
  29. package/docs/basics/client/dlq/callback.mdx +21 -0
  30. package/docs/basics/client/dlq/delete.mdx +120 -0
  31. package/docs/basics/client/dlq/list.mdx +96 -0
  32. package/docs/basics/client/dlq/restart.mdx +164 -0
  33. package/docs/basics/client/dlq/resume.mdx +167 -0
  34. package/docs/basics/client/logs.mdx +139 -0
  35. package/docs/basics/client/notify.mdx +79 -0
  36. package/docs/basics/client/trigger.mdx +139 -0
  37. package/docs/basics/client/waiters.mdx +31 -0
  38. package/docs/basics/client.mdx +40 -0
  39. package/docs/basics/how.mdx +65 -0
  40. package/docs/basics/serve/advanced.mdx +435 -0
  41. package/docs/basics/serve.mdx +142 -0
  42. package/docs/changelog.mdx +174 -0
  43. package/docs/examples/allInOne.mdx +377 -0
  44. package/docs/examples/authWebhook.mdx +567 -0
  45. package/docs/examples/customRetry.mdx +309 -0
  46. package/docs/examples/customerOnboarding.mdx +230 -0
  47. package/docs/examples/dynamicWorkflow.mdx +203 -0
  48. package/docs/examples/eCommerceOrderFulfillment.mdx +281 -0
  49. package/docs/examples/imageProcessing.mdx +339 -0
  50. package/docs/examples/paymentRetry.mdx +438 -0
  51. package/docs/examples/waitForEvent.mdx +201 -0
  52. package/docs/features/dlq/callback.mdx +42 -0
  53. package/docs/features/dlq/delete.mdx +29 -0
  54. package/docs/features/dlq/restart.mdx +33 -0
  55. package/docs/features/dlq/resume.mdx +37 -0
  56. package/docs/features/dlq.mdx +39 -0
  57. package/docs/features/failure-callback.mdx +102 -0
  58. package/docs/features/failureFunction/advanced.mdx +36 -0
  59. package/docs/features/failureFunction/reliability.mdx +33 -0
  60. package/docs/features/flow-control/monitor.mdx +22 -0
  61. package/docs/features/flow-control/parallelism.mdx +45 -0
  62. package/docs/features/flow-control/rate-period.mdx +46 -0
  63. package/docs/features/flow-control.mdx +164 -0
  64. package/docs/features/invoke/serveMany.mdx +109 -0
  65. package/docs/features/invoke.mdx +39 -0
  66. package/docs/features/notify.mdx +127 -0
  67. package/docs/features/parallel-steps.mdx +41 -0
  68. package/docs/features/retries/prevent-retries.mdx +140 -0
  69. package/docs/features/retries.mdx +93 -0
  70. package/docs/features/wait-for-event.mdx +104 -0
  71. package/docs/features/wait.mdx +44 -0
  72. package/docs/features/webhooks.mdx +116 -0
  73. package/docs/getstarted.mdx +200 -0
  74. package/docs/howto/cancel.mdx +50 -0
  75. package/docs/howto/changes.mdx +33 -0
  76. package/docs/howto/configure.mdx +42 -0
  77. package/docs/howto/failures.mdx +185 -0
  78. package/docs/howto/get-token.mdx +18 -0
  79. package/docs/howto/local-development/development-server.mdx +130 -0
  80. package/docs/howto/local-development/local-tunnel.mdx +73 -0
  81. package/docs/howto/middlewares.mdx +263 -0
  82. package/docs/howto/migrations.mdx +335 -0
  83. package/docs/howto/multi-region.mdx +107 -0
  84. package/docs/howto/parallel-runs.mdx +52 -0
  85. package/docs/howto/readonly-token.mdx +19 -0
  86. package/docs/howto/realtime/basic.mdx +315 -0
  87. package/docs/howto/realtime/human-in-the-loop.mdx +454 -0
  88. package/docs/howto/redact-fields.mdx +61 -0
  89. package/docs/howto/retry-now.mdx +41 -0
  90. package/docs/howto/schedule.mdx +104 -0
  91. package/docs/howto/security.mdx +143 -0
  92. package/docs/howto/singleton.mdx +137 -0
  93. package/docs/howto/start.mdx +69 -0
  94. package/docs/howto/use-webhooks.mdx +256 -0
  95. package/docs/integrations/aisdk.mdx +316 -0
  96. package/docs/integrations/anthropic.mdx +51 -0
  97. package/docs/integrations/datadog.mdx +69 -0
  98. package/docs/integrations/openai.mdx +87 -0
  99. package/docs/integrations/prometheus.mdx +65 -0
  100. package/docs/integrations/resend.mdx +82 -0
  101. package/docs/llms-txt.mdx +4 -0
  102. package/docs/openapi.yaml +2944 -0
  103. package/docs/pricing.mdx +22 -0
  104. package/docs/quickstarts/astro.mdx +185 -0
  105. package/docs/quickstarts/cloudflare-workers.mdx +190 -0
  106. package/docs/quickstarts/express.mdx +190 -0
  107. package/docs/quickstarts/fastapi.mdx +282 -0
  108. package/docs/quickstarts/flask.mdx +282 -0
  109. package/docs/quickstarts/hono.mdx +221 -0
  110. package/docs/quickstarts/nextjs-fastapi.mdx +147 -0
  111. package/docs/quickstarts/nextjs-flask.mdx +147 -0
  112. package/docs/quickstarts/nuxt.mdx +169 -0
  113. package/docs/quickstarts/platforms.mdx +78 -0
  114. package/docs/quickstarts/solidjs.mdx +161 -0
  115. package/docs/quickstarts/svelte.mdx +170 -0
  116. package/docs/quickstarts/tanstack-start.mdx +205 -0
  117. package/docs/quickstarts/vercel-nextjs.mdx +233 -0
  118. package/docs/roadmap.mdx +8 -0
  119. package/docs/sdk/workflow-js.mdx +4 -0
  120. package/docs/sdk/workflow-py.mdx +4 -0
  121. package/docs/steps/api.mdx +64 -0
  122. package/docs/steps/call.mdx +183 -0
  123. package/docs/steps/cancel.mdx +25 -0
  124. package/docs/steps/createWebhook.mdx +40 -0
  125. package/docs/steps/invoke.mdx +100 -0
  126. package/docs/steps/notify.mdx +105 -0
  127. package/docs/steps/run.mdx +150 -0
  128. package/docs/steps/sleep.mdx +97 -0
  129. package/docs/steps/sleepUntil.mdx +88 -0
  130. package/docs/steps/waitForEvent.mdx +60 -0
  131. package/docs/steps/waitForWebhook.mdx +78 -0
  132. package/docs/steps.mdx +108 -0
  133. package/docs/troubleshooting/general.mdx +331 -0
  134. package/docs/troubleshooting/vercel.mdx +82 -0
  135. package/express.d.mts +18 -2
  136. package/express.d.ts +18 -2
  137. package/express.js +129 -29
  138. package/express.mjs +1 -1
  139. package/h3.d.mts +18 -2
  140. package/h3.d.ts +18 -2
  141. package/h3.js +129 -29
  142. package/h3.mjs +1 -1
  143. package/hono.d.mts +16 -2
  144. package/hono.d.ts +16 -2
  145. package/hono.js +129 -29
  146. package/hono.mjs +1 -1
  147. package/index.d.mts +49 -21
  148. package/index.d.ts +49 -21
  149. package/index.js +145 -41
  150. package/index.mjs +17 -13
  151. package/nextjs.d.mts +39 -2
  152. package/nextjs.d.ts +39 -2
  153. package/nextjs.js +129 -29
  154. package/nextjs.mjs +1 -1
  155. package/package.json +1 -1
  156. package/react-router.d.mts +15 -2
  157. package/react-router.d.ts +15 -2
  158. package/react-router.js +129 -29
  159. package/react-router.mjs +1 -1
  160. package/{serve-many-CbIV7145.d.mts → serve-many-BKukvLNl.d.mts} +1 -1
  161. package/{serve-many-BCtZg31b.d.ts → serve-many-CrLKQpuZ.d.ts} +1 -1
  162. package/solidjs.d.mts +9 -1
  163. package/solidjs.d.ts +9 -1
  164. package/solidjs.js +129 -29
  165. package/solidjs.mjs +1 -1
  166. package/src/platforms/astro.ts +84 -0
  167. package/src/platforms/cloudflare.ts +127 -0
  168. package/src/platforms/express.ts +147 -0
  169. package/src/platforms/h3.ts +105 -0
  170. package/src/platforms/hono.ts +103 -0
  171. package/src/platforms/nextjs.ts +193 -0
  172. package/src/platforms/react-router.ts +92 -0
  173. package/src/platforms/solidjs.ts +59 -0
  174. package/src/platforms/svelte.ts +99 -0
  175. package/src/platforms/tanstack.ts +96 -0
  176. package/src/src/client/dlq.ts +387 -0
  177. package/src/src/client/filter-types.ts +166 -0
  178. package/src/src/client/index.ts +350 -0
  179. package/src/src/client/types.ts +501 -0
  180. package/src/src/client/utils.ts +307 -0
  181. package/src/src/constants.ts +82 -0
  182. package/src/src/context/api/anthropic.ts +58 -0
  183. package/src/src/context/api/base.ts +52 -0
  184. package/src/src/context/api/index.ts +24 -0
  185. package/src/src/context/api/openai.ts +125 -0
  186. package/src/src/context/api/resend.ts +57 -0
  187. package/src/src/context/auto-executor.ts +707 -0
  188. package/src/src/context/context.ts +681 -0
  189. package/src/src/context/index.ts +1 -0
  190. package/src/src/context/provider.ts +37 -0
  191. package/src/src/context/steps.ts +965 -0
  192. package/src/src/error.ts +203 -0
  193. package/src/src/index.ts +13 -0
  194. package/src/src/middleware/default-callbacks.ts +20 -0
  195. package/src/src/middleware/index.ts +2 -0
  196. package/src/src/middleware/logging.ts +39 -0
  197. package/src/src/middleware/manager.ts +148 -0
  198. package/src/src/middleware/middleware.ts +46 -0
  199. package/src/src/middleware/types.ts +72 -0
  200. package/src/src/qstash/headers.ts +397 -0
  201. package/src/src/qstash/step-config.ts +268 -0
  202. package/src/src/qstash/submit-steps.ts +284 -0
  203. package/src/src/serve/authorization.ts +118 -0
  204. package/src/src/serve/index.ts +475 -0
  205. package/src/src/serve/multi-region/handlers.ts +225 -0
  206. package/src/src/serve/multi-region/utils.ts +88 -0
  207. package/src/src/serve/options.ts +241 -0
  208. package/src/src/serve/serve-many.ts +117 -0
  209. package/src/src/serve/utils.ts +11 -0
  210. package/src/src/types.ts +590 -0
  211. package/src/src/utils.ts +141 -0
  212. package/src/src/workflow-parser.ts +472 -0
  213. package/src/src/workflow-requests.ts +575 -0
  214. package/svelte.d.mts +16 -2
  215. package/svelte.d.ts +16 -2
  216. package/svelte.js +129 -29
  217. package/svelte.mjs +1 -1
  218. package/tanstack.d.mts +14 -2
  219. package/tanstack.d.ts +14 -2
  220. package/tanstack.js +129 -29
  221. package/tanstack.mjs +1 -1
  222. package/{types-ffLPVG5_.d.ts → types-CrgK5P6p.d.mts} +124 -24
  223. package/{types-ffLPVG5_.d.mts → types-CrgK5P6p.d.ts} +124 -24
package/h3.js CHANGED
@@ -1101,6 +1101,10 @@ var triggerFirstInvocation = async (params) => {
1101
1101
  workflowConfig: {
1102
1102
  workflowRunId: workflowContext.workflowRunId,
1103
1103
  workflowUrl: workflowContext.url,
1104
+ // the run doesn't exist yet, so the trigger time is sent when the creation time
1105
+ // is not known. serve and client.trigger set it on the context already, so a
1106
+ // retry of this request carries the same value and is deduplicated.
1107
+ workflowRunCreatedAt: workflowContext.workflowRunCreatedAt || Date.now(),
1104
1108
  failureUrl,
1105
1109
  retries,
1106
1110
  retryDelay,
@@ -1208,7 +1212,10 @@ var triggerWorkflowDelete = async (workflowContext, result, cancel = false, disp
1208
1212
  path: ["v2", "workflows", "runs", `${workflowContext.workflowRunId}?cancel=${cancel}`],
1209
1213
  method: "DELETE",
1210
1214
  parseResponseAsJson: false,
1211
- body: JSON.stringify(result)
1215
+ body: JSON.stringify(result),
1216
+ // with the creation time, QStash deletes the run only if it is the same run.
1217
+ // a late delete of a previous run can't delete a new run with the same id.
1218
+ headers: workflowContext.workflowRunCreatedAt ? { [WORKFLOW_CREATED_AT_HEADER]: workflowContext.workflowRunCreatedAt.toString() } : void 0
1212
1219
  });
1213
1220
  await dispatchDebug?.("onInfo", {
1214
1221
  info: `Workflow run ${workflowContext.workflowRunId} deleted from QStash successfully.`
@@ -1285,6 +1292,7 @@ ${atob(callbackMessage.body ?? "")}`
1285
1292
  const concurrentString = request.headers.get("Upstash-Workflow-Concurrent");
1286
1293
  const contentType = request.headers.get("Upstash-Workflow-ContentType");
1287
1294
  const invokeCount = request.headers.get(WORKFLOW_INVOKE_COUNT_HEADER);
1295
+ const workflowRunCreatedAt = request.headers.get(WORKFLOW_CREATED_AT_HEADER);
1288
1296
  if (!(workflowRunId && stepIdString && stepName && StepTypes.includes(stepType) && concurrentString && contentType)) {
1289
1297
  throw new Error(
1290
1298
  `Missing info in callback message source header: ${JSON.stringify({
@@ -1302,6 +1310,7 @@ ${atob(callbackMessage.body ?? "")}`
1302
1310
  workflowConfig: {
1303
1311
  workflowRunId,
1304
1312
  workflowUrl,
1313
+ workflowRunCreatedAt: Number(workflowRunCreatedAt ?? "0"),
1305
1314
  telemetry: telemetry2
1306
1315
  },
1307
1316
  invokeCount: Number(invokeCount)
@@ -1476,6 +1485,7 @@ var BaseLazyStep = class _BaseLazyStep {
1476
1485
  workflowConfig: {
1477
1486
  workflowRunId: context.workflowRunId,
1478
1487
  workflowUrl: context.url,
1488
+ workflowRunCreatedAt: context.workflowRunCreatedAt,
1479
1489
  useJSONContent: false,
1480
1490
  telemetry: telemetry2
1481
1491
  },
@@ -1807,6 +1817,8 @@ var LazyWaitEventStep = class extends BaseLazyStep {
1807
1817
  ) : {},
1808
1818
  // note: using WORKFLOW_ID_HEADER doesn't work, because Runid -> RunId:
1809
1819
  "Upstash-Workflow-Runid": [context.workflowRunId],
1820
+ // same for WORKFLOW_CREATED_AT_HEADER, because Createdat -> CreatedAt:
1821
+ ...context.workflowRunCreatedAt ? { "Upstash-Workflow-Createdat": [context.workflowRunCreatedAt.toString()] } : {},
1810
1822
  [WORKFLOW_INIT_HEADER]: ["false"],
1811
1823
  [WORKFLOW_URL_HEADER]: [context.url],
1812
1824
  "Upstash-Workflow-CallType": ["step"]
@@ -1909,6 +1921,7 @@ var LazyInvokeStep = class extends BaseLazyStep {
1909
1921
  workflowConfig: {
1910
1922
  workflowRunId: context.workflowRunId,
1911
1923
  workflowUrl: context.url,
1924
+ workflowRunCreatedAt: context.workflowRunCreatedAt,
1912
1925
  telemetry: telemetry2,
1913
1926
  useJSONContent: false
1914
1927
  },
@@ -1918,6 +1931,9 @@ var LazyInvokeStep = class extends BaseLazyStep {
1918
1931
  invokerHeaders[key] = value;
1919
1932
  });
1920
1933
  invokerHeaders["Upstash-Workflow-Runid"] = context.workflowRunId;
1934
+ if (context.workflowRunCreatedAt) {
1935
+ invokerHeaders["Upstash-Workflow-Createdat"] = context.workflowRunCreatedAt.toString();
1936
+ }
1921
1937
  const request = {
1922
1938
  body: stringifyBody(this.params.body),
1923
1939
  headers: Object.fromEntries(
@@ -1946,6 +1962,9 @@ var LazyInvokeStep = class extends BaseLazyStep {
1946
1962
  workflowConfig: {
1947
1963
  workflowRunId: getWorkflowRunId(workflowRunId),
1948
1964
  workflowUrl: newUrl,
1965
+ // the invoked run doesn't exist yet, so the creation time of the invoker run is sent.
1966
+ // it separates the invocations made by different runs of the invoker.
1967
+ workflowRunCreatedAt: context.workflowRunCreatedAt,
1949
1968
  retries,
1950
1969
  retryDelay,
1951
1970
  telemetry: telemetry2,
@@ -2115,6 +2134,9 @@ var WorkflowHeaders = class {
2115
2134
  [WORKFLOW_PROTOCOL_VERSION_HEADER]: WORKFLOW_PROTOCOL_VERSION,
2116
2135
  ...this.workflowConfig.telemetry ? getTelemetryHeaders(this.workflowConfig.telemetry) : {}
2117
2136
  };
2137
+ if (this.workflowConfig.workflowRunCreatedAt) {
2138
+ this.headers.rawHeaders[WORKFLOW_CREATED_AT_HEADER] = this.workflowConfig.workflowRunCreatedAt.toString();
2139
+ }
2118
2140
  if (this.stepInfo?.lazyStep.stepType !== "Call") {
2119
2141
  this.headers.rawHeaders[`Upstash-Forward-${WORKFLOW_PROTOCOL_VERSION_HEADER}`] = WORKFLOW_PROTOCOL_VERSION;
2120
2142
  }
@@ -2313,6 +2335,7 @@ var submitParallelSteps = async ({
2313
2335
  workflowConfig: {
2314
2336
  workflowRunId: context.workflowRunId,
2315
2337
  workflowUrl: context.url,
2338
+ workflowRunCreatedAt: context.workflowRunCreatedAt,
2316
2339
  telemetry: telemetry2
2317
2340
  },
2318
2341
  invokeCount,
@@ -2403,6 +2426,7 @@ var publishStepConfigRequest = async ({
2403
2426
  initHeaderValue: "false",
2404
2427
  workflowConfig: {
2405
2428
  workflowRunId: context.workflowRunId,
2429
+ workflowRunCreatedAt: context.workflowRunCreatedAt,
2406
2430
  workflowUrl: context.url,
2407
2431
  telemetry: telemetry2
2408
2432
  },
@@ -2415,7 +2439,9 @@ var publishStepConfigRequest = async ({
2415
2439
  const result = await context.qstashClient.publishJSON({
2416
2440
  headers: {
2417
2441
  ...headers,
2418
- "Upstash-Workflow-CallType": WORKFLOW_STEP_CONFIG_CALL_TYPE
2442
+ "Upstash-Workflow-CallType": WORKFLOW_STEP_CONFIG_CALL_TYPE,
2443
+ "Upstash-Forward-Upstash-Workflow-StepId": targetStep.toString(),
2444
+ "Upstash-Forward-Upstash-Workflow-StepName": lazyStep.stepName
2419
2445
  },
2420
2446
  method: "POST",
2421
2447
  body: { targetStep, invokeCount },
@@ -2434,6 +2460,19 @@ var publishStepConfigRequest = async ({
2434
2460
  };
2435
2461
 
2436
2462
  // src/qstash/step-config.ts
2463
+ var normalizeStepSettings = (settings) => {
2464
+ if (settings === void 0) {
2465
+ return void 0;
2466
+ }
2467
+ const { retries, retryDelay } = settings;
2468
+ if (retryDelay !== void 0 && typeof retryDelay !== "string") {
2469
+ throw new WorkflowNonRetryableError("Invalid step retryDelay: must be a string.");
2470
+ }
2471
+ if (retries !== void 0 && (!Number.isInteger(retries) || retries < 0)) {
2472
+ throw new WorkflowNonRetryableError("Invalid step retries: must be a non-negative integer.");
2473
+ }
2474
+ return { ...settings, retryDelay: retryDelay?.trim() || void 0 };
2475
+ };
2437
2476
  var DEFAULT_PARALLELISM = 0;
2438
2477
  var DEFAULT_RATE = 0;
2439
2478
  var DEFAULT_PERIOD_SECONDS = 1;
@@ -2697,10 +2736,18 @@ var AutoExecutor = class _AutoExecutor {
2697
2736
  dispatchLifecycle: this.dispatchLifecycle
2698
2737
  });
2699
2738
  if (lazyStep.supportsDeferredSubmission) {
2700
- this.pendingStep = { status: "held", lazyStep, resultStep };
2739
+ const serializedOut = JSON.stringify(resultStep.out);
2740
+ this.pendingStep = {
2741
+ status: "held",
2742
+ lazyStep,
2743
+ resultStep: {
2744
+ ...resultStep,
2745
+ out: serializedOut === void 0 ? void 0 : JSON.parse(serializedOut)
2746
+ }
2747
+ };
2701
2748
  return lazyStep.parseOut({
2702
2749
  ...resultStep,
2703
- out: resultStep.out === void 0 ? void 0 : JSON.stringify(resultStep.out)
2750
+ out: serializedOut
2704
2751
  });
2705
2752
  }
2706
2753
  await submitStepResult({
@@ -3045,6 +3092,11 @@ var BaseWorkflowApi = class {
3045
3092
 
3046
3093
  // src/context/api/anthropic.ts
3047
3094
  var AnthropicAPI = class extends BaseWorkflowApi {
3095
+ /**
3096
+ * Runs as a `context.call` step, so the `context.call` caveats apply.
3097
+ *
3098
+ * @see node_modules/@upstash/workflow/docs/integrations/anthropic.mdx
3099
+ */
3048
3100
  async call(stepName, settings) {
3049
3101
  const { token, operation, ...parameters } = settings;
3050
3102
  return await this.callApi(stepName, {
@@ -3060,6 +3112,11 @@ var AnthropicAPI = class extends BaseWorkflowApi {
3060
3112
  // src/context/api/openai.ts
3061
3113
  var import_qstash7 = require("@upstash/qstash");
3062
3114
  var OpenAIAPI = class extends BaseWorkflowApi {
3115
+ /**
3116
+ * Runs as a `context.call` step, so the `context.call` caveats apply.
3117
+ *
3118
+ * @see node_modules/@upstash/workflow/docs/integrations/openai.mdx
3119
+ */
3063
3120
  async call(stepName, settings) {
3064
3121
  const { token, organization, operation, baseURL, ...parameters } = settings;
3065
3122
  const useOpenAI = baseURL === void 0;
@@ -3077,6 +3134,11 @@ var OpenAIAPI = class extends BaseWorkflowApi {
3077
3134
  // src/context/api/resend.ts
3078
3135
  var import_qstash8 = require("@upstash/qstash");
3079
3136
  var ResendAPI = class extends BaseWorkflowApi {
3137
+ /**
3138
+ * Runs as a `context.call` step, so the `context.call` caveats apply.
3139
+ *
3140
+ * @see node_modules/@upstash/workflow/docs/integrations/resend.mdx
3141
+ */
3080
3142
  async call(stepName, settings) {
3081
3143
  const { token, batch = false, ...parameters } = settings;
3082
3144
  return await this.callApi(stepName, {
@@ -3318,8 +3380,9 @@ var WorkflowContext = class {
3318
3380
  *
3319
3381
  * ```ts
3320
3382
  * import { Client } from "@upstash/qstash"
3383
+ * import { serve } from "@upstash/workflow/nextjs"
3321
3384
  *
3322
- * export const POST = serve(
3385
+ * export const { POST } = serve(
3323
3386
  * async (context) => {
3324
3387
  * ...
3325
3388
  * },
@@ -3344,7 +3407,7 @@ var WorkflowContext = class {
3344
3407
  * Can be overwritten by passing a `url` parameter in `serve`:
3345
3408
  *
3346
3409
  * ```ts
3347
- * export const POST = serve(
3410
+ * export const { POST } = serve(
3348
3411
  * async (context) => {
3349
3412
  * ...
3350
3413
  * },
@@ -3362,7 +3425,7 @@ var WorkflowContext = class {
3362
3425
  *
3363
3426
  * ```ts
3364
3427
  * // set requestPayload type to MyPayload:
3365
- * export const POST = serve<MyPayload>(
3428
+ * export const { POST } = serve<MyPayload>(
3366
3429
  * async (context) => {
3367
3430
  * ...
3368
3431
  * }
@@ -3374,7 +3437,7 @@ var WorkflowContext = class {
3374
3437
  * the `initialPayloadParser` parameter:
3375
3438
  *
3376
3439
  * ```ts
3377
- * export const POST = serve<MyPayload>(
3440
+ * export const { POST } = serve<MyPayload>(
3378
3441
  * async (context) => {
3379
3442
  * ...
3380
3443
  * },
@@ -3383,6 +3446,13 @@ var WorkflowContext = class {
3383
3446
  * }
3384
3447
  * )
3385
3448
  * ```
3449
+ *
3450
+ * When a `context.call` response comes back, the route runs up to its first step with this
3451
+ * set to the call-result envelope (and `workflowRunId` set to a random id) before the SDK
3452
+ * recognizes the request. Code before the first step must not dereference, validate or
3453
+ * return early on the payload; read it inside `context.run`.
3454
+ *
3455
+ * @see node_modules/@upstash/workflow/docs/basics/serve/advanced.mdx
3386
3456
  */
3387
3457
  requestPayload;
3388
3458
  /**
@@ -3395,7 +3465,7 @@ var WorkflowContext = class {
3395
3465
  * Can be set using the `env` option of serve:
3396
3466
  *
3397
3467
  * ```ts
3398
- * export const POST = serve<MyPayload>(
3468
+ * export const { POST } = serve<MyPayload>(
3399
3469
  * async (context) => {
3400
3470
  * const key = context.env["API_KEY"];
3401
3471
  * },
@@ -3561,18 +3631,24 @@ var WorkflowContext = class {
3561
3631
  * )
3562
3632
  * ```
3563
3633
  *
3634
+ * Do not wrap steps in try/catch or `.catch` without rethrowing `WorkflowAbort`: each step
3635
+ * throws it to end the request. To stop retrying a failed step, throw
3636
+ * `WorkflowNonRetryableError`.
3637
+ *
3564
3638
  * @param stepName name of the step
3565
3639
  * @param stepFunction step function to be executed
3566
3640
  * @param stepSettings step-level settings for this step
3567
3641
  * @returns result of the step function
3642
+ * @see node_modules/@upstash/workflow/docs/steps/run.mdx
3568
3643
  */
3569
3644
  async run(stepName, stepFunction, stepSettings) {
3645
+ const normalizedSettings = normalizeStepSettings(stepSettings);
3570
3646
  if (stepSettings) {
3571
3647
  validateFlowControl(stepSettings.flowControl);
3572
3648
  }
3573
3649
  const wrappedStepFunction = (() => this.executor.wrapStep(stepName, stepFunction));
3574
3650
  return await this.addStep(
3575
- new LazyFunctionStep(this, stepName, wrappedStepFunction, stepSettings)
3651
+ new LazyFunctionStep(this, stepName, wrappedStepFunction, normalizedSettings)
3576
3652
  );
3577
3653
  }
3578
3654
  /**
@@ -3583,8 +3659,9 @@ var WorkflowContext = class {
3583
3659
  * ```
3584
3660
  *
3585
3661
  * @param stepName
3586
- * @param duration sleep duration in seconds
3662
+ * @param duration sleep duration in seconds, or a duration string such as "10m"
3587
3663
  * @returns undefined
3664
+ * @see node_modules/@upstash/workflow/docs/steps/sleep.mdx
3588
3665
  */
3589
3666
  async sleep(stepName, duration) {
3590
3667
  await this.addStep(new LazySleepStep(this, stepName, duration));
@@ -3598,8 +3675,11 @@ var WorkflowContext = class {
3598
3675
  *
3599
3676
  * @param stepName
3600
3677
  * @param datetime time to sleep until. Can be provided as a number (in unix seconds),
3601
- * as a Date object or a string (passed to `new Date(datetimeString)`)
3678
+ * as a Date object or a string (passed to `new Date(datetimeString)`).
3679
+ * A millisecond timestamp such as `Date.now()` is too far in the future, so QStash
3680
+ * rejects the step and the run fails. Pass `new Date(ms)` instead.
3602
3681
  * @returns undefined
3682
+ * @see node_modules/@upstash/workflow/docs/steps/sleepUntil.mdx
3603
3683
  */
3604
3684
  async sleepUntil(stepName, datetime) {
3605
3685
  let time;
@@ -3650,7 +3730,7 @@ var WorkflowContext = class {
3650
3730
  * Pauses workflow execution until a specific event occurs or a timeout is reached.
3651
3731
  *
3652
3732
  *```ts
3653
- * const result = await workflow.waitForEvent("payment-confirmed", "payment.confirmed", {
3733
+ * const result = await context.waitForEvent("payment-confirmed", "payment.confirmed", {
3654
3734
  * timeout: "5m"
3655
3735
  * });
3656
3736
  *```
@@ -3674,11 +3754,14 @@ var WorkflowContext = class {
3674
3754
  * Alternatively, you can use the `context.notify` method.
3675
3755
  *
3676
3756
  * @param stepName
3677
- * @param eventId - Unique identifier for the event to wait for
3757
+ * @param eventId - Unique identifier for the event to wait for. Only letters, digits,
3758
+ * "-", "_" and "." are allowed. QStash rejects other characters, such as ":", which
3759
+ * stops the run with only a "Tried to append to a cancelled workflow" warning.
3678
3760
  * @param options - Configuration options.
3679
3761
  * @returns `{ timeout: boolean, eventData: TEventData }`.
3680
3762
  * The `timeout` property specifies if the workflow has timed out. The `eventData`
3681
3763
  * is the data passed when notifying this workflow of an event.
3764
+ * @see node_modules/@upstash/workflow/docs/steps/waitForEvent.mdx
3682
3765
  */
3683
3766
  async waitForEvent(stepName, eventId, options = {}) {
3684
3767
  const { timeout = "7d" } = options;
@@ -3700,28 +3783,31 @@ var WorkflowContext = class {
3700
3783
  * will receive the given event data and resume execution.
3701
3784
  *
3702
3785
  * The response includes the same eventId and eventData. Additionally, there is
3703
- * a notifyResponse field which contains a list of `Waiter` objects, each corresponding
3704
- * to a notified workflow run.
3705
- *
3706
- * Optionally, you can pass a workflowRunId to enable lookback functionality:
3707
- *
3708
- * ```ts
3709
- * const { eventId, eventData, notifyResponse } = await context.notify(
3710
- * "notify step", "event-id", "event-data", "wfr_123"
3711
- * );
3712
- * ```
3786
+ * a notifyResponse field which contains a list of `NotifyResponse` objects, each corresponding
3787
+ * to a notified workflow run. The notified `Waiter` is under `notifyResponse[i].waiter`.
3713
3788
  *
3714
3789
  * @param stepName
3715
- * @param eventId event id to notify
3790
+ * @param eventId event id to notify. Only letters, digits, "-", "_" and "." are allowed.
3791
+ * QStash rejects other characters, such as ":", which stops the run with only a
3792
+ * "Tried to append to a cancelled workflow" warning.
3716
3793
  * @param eventData event data to notify with
3717
- * @param workflowRunId optional workflow run id for lookback support
3718
- * @returns notify response which has event id, event data and list of waiters which were notified
3794
+ * @param workflowRunId optional workflow run id for lookback: the event is kept for the run
3795
+ * even if it has not reached `waitForEvent` yet
3796
+ * @returns notify response which has event id, event data and list of waiters which were
3797
+ * notified. With `workflowRunId`, QStash returns `notifyResponse` as a single object instead
3798
+ * of an array, despite the type.
3799
+ * @see node_modules/@upstash/workflow/docs/steps/notify.mdx
3719
3800
  */
3720
3801
  async notify(stepName, eventId, eventData, workflowRunId) {
3721
3802
  return await this.addStep(
3722
3803
  new LazyNotifyStep(this, stepName, eventId, eventData, this.qstashClient.http, workflowRunId)
3723
3804
  );
3724
3805
  }
3806
+ /**
3807
+ * Starts another workflow run and waits for its result.
3808
+ *
3809
+ * @see node_modules/@upstash/workflow/docs/steps/invoke.mdx
3810
+ */
3725
3811
  async invoke(stepName, settings) {
3726
3812
  validateLabel(settings.label);
3727
3813
  validateFlowControl(settings.flowControl);
@@ -3729,9 +3815,15 @@ var WorkflowContext = class {
3729
3815
  new LazyInvokeStep(this, stepName, settings)
3730
3816
  );
3731
3817
  }
3818
+ /**
3819
+ * @see node_modules/@upstash/workflow/docs/steps/createWebhook.mdx
3820
+ */
3732
3821
  async createWebhook(stepName) {
3733
3822
  return await this.addStep(new LazyCreateWebhookStep(this, stepName));
3734
3823
  }
3824
+ /**
3825
+ * @see node_modules/@upstash/workflow/docs/steps/waitForWebhook.mdx
3826
+ */
3735
3827
  async waitForWebhook(stepName, webhook, timeout) {
3736
3828
  return await this.addStep(new LazyWaitForWebhookStep(this, stepName, webhook, timeout));
3737
3829
  }
@@ -3740,6 +3832,8 @@ var WorkflowContext = class {
3740
3832
  *
3741
3833
  * Will throw WorkflowCancelAbort to stop workflow execution.
3742
3834
  * Shouldn't be inside try/catch.
3835
+ *
3836
+ * @see node_modules/@upstash/workflow/docs/steps/cancel.mdx
3743
3837
  */
3744
3838
  async cancel() {
3745
3839
  throw new WorkflowCancelAbort();
@@ -3758,6 +3852,11 @@ var WorkflowContext = class {
3758
3852
  throw error;
3759
3853
  }
3760
3854
  }
3855
+ /**
3856
+ * Calls OpenAI, Anthropic or Resend through QStash, like `context.call`.
3857
+ *
3858
+ * @see node_modules/@upstash/workflow/docs/steps/api.mdx
3859
+ */
3761
3860
  get api() {
3762
3861
  return new WorkflowApi({
3763
3862
  context: this
@@ -4540,7 +4639,8 @@ var serveBase = (routeFunction, telemetry2, options, internalOptions) => {
4540
4639
  const invokeCount = Number(request.headers.get(WORKFLOW_INVOKE_COUNT_HEADER) ?? "0");
4541
4640
  const retried = Number(request.headers.get(WORKFLOW_RETRIED_HEADER) ?? "0");
4542
4641
  const label = request.headers.get(WORKFLOW_LABEL_HEADER) ?? void 0;
4543
- const workflowRunCreatedAt = request.headers.get(WORKFLOW_CREATED_AT_HEADER);
4642
+ const workflowRunCreatedAtHeader = request.headers.get(WORKFLOW_CREATED_AT_HEADER);
4643
+ const workflowRunCreatedAt = workflowRunCreatedAtHeader ? Number(workflowRunCreatedAtHeader) : isFirstInvocation ? Date.now() : 0;
4544
4644
  const effectiveConfig = getEffectiveConfig(request.headers);
4545
4645
  const workflowContext = new WorkflowContext({
4546
4646
  qstashClient: regionalClient,
@@ -4555,7 +4655,7 @@ var serveBase = (routeFunction, telemetry2, options, internalOptions) => {
4555
4655
  invokeCount,
4556
4656
  label,
4557
4657
  retried,
4558
- workflowRunCreatedAt: Number(workflowRunCreatedAt),
4658
+ workflowRunCreatedAt,
4559
4659
  middlewareManager
4560
4660
  });
4561
4661
  const authCheck = await DisabledWorkflowContext.tryAuthentication(
package/h3.mjs CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  SDK_TELEMETRY,
3
3
  serveBase,
4
4
  serveManyBase
5
- } from "./chunk-UH6O5IJY.mjs";
5
+ } from "./chunk-J3PXPHSB.mjs";
6
6
 
7
7
  // node_modules/defu/dist/defu.mjs
8
8
  function isPlainObject(value) {
package/hono.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Context } from 'hono';
2
- import { c as RouteFunction, d as WorkflowServeOptions, I as InvokableWorkflow } from './types-ffLPVG5_.mjs';
2
+ import { c as RouteFunction, d as WorkflowServeOptions, I as InvokableWorkflow } from './types-CrgK5P6p.mjs';
3
3
  import { Variables } from 'hono/types';
4
- import { s as serveManyBase } from './serve-many-CbIV7145.mjs';
4
+ import { s as serveManyBase } from './serve-many-BKukvLNl.mjs';
5
5
  import '@upstash/qstash';
6
6
  import 'zod';
7
7
  import 'neverthrow';
@@ -18,15 +18,29 @@ type WorkflowBindings = {
18
18
  *
19
19
  * See for options https://upstash.com/docs/qstash/workflows/basics/serve
20
20
  *
21
+ * Code outside steps runs again on every request of the run. Anything it branches on or
22
+ * returns early on (Date.now(), database rows, random values) must give the same answer on
23
+ * every request, or later requests fail with "Incompatible step name" or "Failed to
24
+ * authenticate Workflow request". Read such values inside `context.run` and branch on its
25
+ * result.
26
+ *
21
27
  * @param routeFunction workflow function
22
28
  * @param options workflow options
23
29
  * @returns
30
+ * @see node_modules/@upstash/workflow/docs/basics/serve.mdx
31
+ * @see node_modules/@upstash/workflow/docs/quickstarts/hono.mdx
24
32
  */
25
33
  declare const serve: <TInitialPayload = unknown, TBindings extends WorkflowBindings = WorkflowBindings, TVariables extends Variables = Variables, TResult = unknown>(routeFunction: RouteFunction<TInitialPayload, TResult>, options?: WorkflowServeOptions<TInitialPayload, TResult>) => ((context: Context<{
26
34
  Bindings: TBindings;
27
35
  Variables: TVariables;
28
36
  }>) => Promise<Response>);
37
+ /**
38
+ * @see node_modules/@upstash/workflow/docs/features/invoke.mdx
39
+ */
29
40
  declare const createWorkflow: <TInitialPayload = unknown, TResult = unknown, TBindings extends WorkflowBindings = WorkflowBindings, TVariables extends Variables = Variables>(...params: Parameters<typeof serve<TInitialPayload, TBindings, TVariables, TResult>>) => InvokableWorkflow<TInitialPayload, TResult>;
41
+ /**
42
+ * @see node_modules/@upstash/workflow/docs/features/invoke/serveMany.mdx
43
+ */
30
44
  declare const serveMany: (workflows: Parameters<typeof serveManyBase>[0]["workflows"], options?: Parameters<typeof serveManyBase>[0]["options"]) => (context: Context<{
31
45
  Bindings: WorkflowBindings;
32
46
  Variables: object;
package/hono.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Context } from 'hono';
2
- import { c as RouteFunction, d as WorkflowServeOptions, I as InvokableWorkflow } from './types-ffLPVG5_.js';
2
+ import { c as RouteFunction, d as WorkflowServeOptions, I as InvokableWorkflow } from './types-CrgK5P6p.js';
3
3
  import { Variables } from 'hono/types';
4
- import { s as serveManyBase } from './serve-many-BCtZg31b.js';
4
+ import { s as serveManyBase } from './serve-many-CrLKQpuZ.js';
5
5
  import '@upstash/qstash';
6
6
  import 'zod';
7
7
  import 'neverthrow';
@@ -18,15 +18,29 @@ type WorkflowBindings = {
18
18
  *
19
19
  * See for options https://upstash.com/docs/qstash/workflows/basics/serve
20
20
  *
21
+ * Code outside steps runs again on every request of the run. Anything it branches on or
22
+ * returns early on (Date.now(), database rows, random values) must give the same answer on
23
+ * every request, or later requests fail with "Incompatible step name" or "Failed to
24
+ * authenticate Workflow request". Read such values inside `context.run` and branch on its
25
+ * result.
26
+ *
21
27
  * @param routeFunction workflow function
22
28
  * @param options workflow options
23
29
  * @returns
30
+ * @see node_modules/@upstash/workflow/docs/basics/serve.mdx
31
+ * @see node_modules/@upstash/workflow/docs/quickstarts/hono.mdx
24
32
  */
25
33
  declare const serve: <TInitialPayload = unknown, TBindings extends WorkflowBindings = WorkflowBindings, TVariables extends Variables = Variables, TResult = unknown>(routeFunction: RouteFunction<TInitialPayload, TResult>, options?: WorkflowServeOptions<TInitialPayload, TResult>) => ((context: Context<{
26
34
  Bindings: TBindings;
27
35
  Variables: TVariables;
28
36
  }>) => Promise<Response>);
37
+ /**
38
+ * @see node_modules/@upstash/workflow/docs/features/invoke.mdx
39
+ */
29
40
  declare const createWorkflow: <TInitialPayload = unknown, TResult = unknown, TBindings extends WorkflowBindings = WorkflowBindings, TVariables extends Variables = Variables>(...params: Parameters<typeof serve<TInitialPayload, TBindings, TVariables, TResult>>) => InvokableWorkflow<TInitialPayload, TResult>;
41
+ /**
42
+ * @see node_modules/@upstash/workflow/docs/features/invoke/serveMany.mdx
43
+ */
30
44
  declare const serveMany: (workflows: Parameters<typeof serveManyBase>[0]["workflows"], options?: Parameters<typeof serveManyBase>[0]["options"]) => (context: Context<{
31
45
  Bindings: WorkflowBindings;
32
46
  Variables: object;