@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/react-router.js CHANGED
@@ -792,6 +792,10 @@ var triggerFirstInvocation = async (params) => {
792
792
  workflowConfig: {
793
793
  workflowRunId: workflowContext.workflowRunId,
794
794
  workflowUrl: workflowContext.url,
795
+ // the run doesn't exist yet, so the trigger time is sent when the creation time
796
+ // is not known. serve and client.trigger set it on the context already, so a
797
+ // retry of this request carries the same value and is deduplicated.
798
+ workflowRunCreatedAt: workflowContext.workflowRunCreatedAt || Date.now(),
795
799
  failureUrl,
796
800
  retries,
797
801
  retryDelay,
@@ -899,7 +903,10 @@ var triggerWorkflowDelete = async (workflowContext, result, cancel = false, disp
899
903
  path: ["v2", "workflows", "runs", `${workflowContext.workflowRunId}?cancel=${cancel}`],
900
904
  method: "DELETE",
901
905
  parseResponseAsJson: false,
902
- body: JSON.stringify(result)
906
+ body: JSON.stringify(result),
907
+ // with the creation time, QStash deletes the run only if it is the same run.
908
+ // a late delete of a previous run can't delete a new run with the same id.
909
+ headers: workflowContext.workflowRunCreatedAt ? { [WORKFLOW_CREATED_AT_HEADER]: workflowContext.workflowRunCreatedAt.toString() } : void 0
903
910
  });
904
911
  await dispatchDebug?.("onInfo", {
905
912
  info: `Workflow run ${workflowContext.workflowRunId} deleted from QStash successfully.`
@@ -976,6 +983,7 @@ ${atob(callbackMessage.body ?? "")}`
976
983
  const concurrentString = request.headers.get("Upstash-Workflow-Concurrent");
977
984
  const contentType = request.headers.get("Upstash-Workflow-ContentType");
978
985
  const invokeCount = request.headers.get(WORKFLOW_INVOKE_COUNT_HEADER);
986
+ const workflowRunCreatedAt = request.headers.get(WORKFLOW_CREATED_AT_HEADER);
979
987
  if (!(workflowRunId && stepIdString && stepName && StepTypes.includes(stepType) && concurrentString && contentType)) {
980
988
  throw new Error(
981
989
  `Missing info in callback message source header: ${JSON.stringify({
@@ -993,6 +1001,7 @@ ${atob(callbackMessage.body ?? "")}`
993
1001
  workflowConfig: {
994
1002
  workflowRunId,
995
1003
  workflowUrl,
1004
+ workflowRunCreatedAt: Number(workflowRunCreatedAt ?? "0"),
996
1005
  telemetry: telemetry2
997
1006
  },
998
1007
  invokeCount: Number(invokeCount)
@@ -1167,6 +1176,7 @@ var BaseLazyStep = class _BaseLazyStep {
1167
1176
  workflowConfig: {
1168
1177
  workflowRunId: context.workflowRunId,
1169
1178
  workflowUrl: context.url,
1179
+ workflowRunCreatedAt: context.workflowRunCreatedAt,
1170
1180
  useJSONContent: false,
1171
1181
  telemetry: telemetry2
1172
1182
  },
@@ -1498,6 +1508,8 @@ var LazyWaitEventStep = class extends BaseLazyStep {
1498
1508
  ) : {},
1499
1509
  // note: using WORKFLOW_ID_HEADER doesn't work, because Runid -> RunId:
1500
1510
  "Upstash-Workflow-Runid": [context.workflowRunId],
1511
+ // same for WORKFLOW_CREATED_AT_HEADER, because Createdat -> CreatedAt:
1512
+ ...context.workflowRunCreatedAt ? { "Upstash-Workflow-Createdat": [context.workflowRunCreatedAt.toString()] } : {},
1501
1513
  [WORKFLOW_INIT_HEADER]: ["false"],
1502
1514
  [WORKFLOW_URL_HEADER]: [context.url],
1503
1515
  "Upstash-Workflow-CallType": ["step"]
@@ -1600,6 +1612,7 @@ var LazyInvokeStep = class extends BaseLazyStep {
1600
1612
  workflowConfig: {
1601
1613
  workflowRunId: context.workflowRunId,
1602
1614
  workflowUrl: context.url,
1615
+ workflowRunCreatedAt: context.workflowRunCreatedAt,
1603
1616
  telemetry: telemetry2,
1604
1617
  useJSONContent: false
1605
1618
  },
@@ -1609,6 +1622,9 @@ var LazyInvokeStep = class extends BaseLazyStep {
1609
1622
  invokerHeaders[key] = value;
1610
1623
  });
1611
1624
  invokerHeaders["Upstash-Workflow-Runid"] = context.workflowRunId;
1625
+ if (context.workflowRunCreatedAt) {
1626
+ invokerHeaders["Upstash-Workflow-Createdat"] = context.workflowRunCreatedAt.toString();
1627
+ }
1612
1628
  const request = {
1613
1629
  body: stringifyBody(this.params.body),
1614
1630
  headers: Object.fromEntries(
@@ -1637,6 +1653,9 @@ var LazyInvokeStep = class extends BaseLazyStep {
1637
1653
  workflowConfig: {
1638
1654
  workflowRunId: getWorkflowRunId(workflowRunId),
1639
1655
  workflowUrl: newUrl,
1656
+ // the invoked run doesn't exist yet, so the creation time of the invoker run is sent.
1657
+ // it separates the invocations made by different runs of the invoker.
1658
+ workflowRunCreatedAt: context.workflowRunCreatedAt,
1640
1659
  retries,
1641
1660
  retryDelay,
1642
1661
  telemetry: telemetry2,
@@ -1806,6 +1825,9 @@ var WorkflowHeaders = class {
1806
1825
  [WORKFLOW_PROTOCOL_VERSION_HEADER]: WORKFLOW_PROTOCOL_VERSION,
1807
1826
  ...this.workflowConfig.telemetry ? getTelemetryHeaders(this.workflowConfig.telemetry) : {}
1808
1827
  };
1828
+ if (this.workflowConfig.workflowRunCreatedAt) {
1829
+ this.headers.rawHeaders[WORKFLOW_CREATED_AT_HEADER] = this.workflowConfig.workflowRunCreatedAt.toString();
1830
+ }
1809
1831
  if (this.stepInfo?.lazyStep.stepType !== "Call") {
1810
1832
  this.headers.rawHeaders[`Upstash-Forward-${WORKFLOW_PROTOCOL_VERSION_HEADER}`] = WORKFLOW_PROTOCOL_VERSION;
1811
1833
  }
@@ -2004,6 +2026,7 @@ var submitParallelSteps = async ({
2004
2026
  workflowConfig: {
2005
2027
  workflowRunId: context.workflowRunId,
2006
2028
  workflowUrl: context.url,
2029
+ workflowRunCreatedAt: context.workflowRunCreatedAt,
2007
2030
  telemetry: telemetry2
2008
2031
  },
2009
2032
  invokeCount,
@@ -2094,6 +2117,7 @@ var publishStepConfigRequest = async ({
2094
2117
  initHeaderValue: "false",
2095
2118
  workflowConfig: {
2096
2119
  workflowRunId: context.workflowRunId,
2120
+ workflowRunCreatedAt: context.workflowRunCreatedAt,
2097
2121
  workflowUrl: context.url,
2098
2122
  telemetry: telemetry2
2099
2123
  },
@@ -2106,7 +2130,9 @@ var publishStepConfigRequest = async ({
2106
2130
  const result = await context.qstashClient.publishJSON({
2107
2131
  headers: {
2108
2132
  ...headers,
2109
- "Upstash-Workflow-CallType": WORKFLOW_STEP_CONFIG_CALL_TYPE
2133
+ "Upstash-Workflow-CallType": WORKFLOW_STEP_CONFIG_CALL_TYPE,
2134
+ "Upstash-Forward-Upstash-Workflow-StepId": targetStep.toString(),
2135
+ "Upstash-Forward-Upstash-Workflow-StepName": lazyStep.stepName
2110
2136
  },
2111
2137
  method: "POST",
2112
2138
  body: { targetStep, invokeCount },
@@ -2125,6 +2151,19 @@ var publishStepConfigRequest = async ({
2125
2151
  };
2126
2152
 
2127
2153
  // src/qstash/step-config.ts
2154
+ var normalizeStepSettings = (settings) => {
2155
+ if (settings === void 0) {
2156
+ return void 0;
2157
+ }
2158
+ const { retries, retryDelay } = settings;
2159
+ if (retryDelay !== void 0 && typeof retryDelay !== "string") {
2160
+ throw new WorkflowNonRetryableError("Invalid step retryDelay: must be a string.");
2161
+ }
2162
+ if (retries !== void 0 && (!Number.isInteger(retries) || retries < 0)) {
2163
+ throw new WorkflowNonRetryableError("Invalid step retries: must be a non-negative integer.");
2164
+ }
2165
+ return { ...settings, retryDelay: retryDelay?.trim() || void 0 };
2166
+ };
2128
2167
  var DEFAULT_PARALLELISM = 0;
2129
2168
  var DEFAULT_RATE = 0;
2130
2169
  var DEFAULT_PERIOD_SECONDS = 1;
@@ -2388,10 +2427,18 @@ var AutoExecutor = class _AutoExecutor {
2388
2427
  dispatchLifecycle: this.dispatchLifecycle
2389
2428
  });
2390
2429
  if (lazyStep.supportsDeferredSubmission) {
2391
- this.pendingStep = { status: "held", lazyStep, resultStep };
2430
+ const serializedOut = JSON.stringify(resultStep.out);
2431
+ this.pendingStep = {
2432
+ status: "held",
2433
+ lazyStep,
2434
+ resultStep: {
2435
+ ...resultStep,
2436
+ out: serializedOut === void 0 ? void 0 : JSON.parse(serializedOut)
2437
+ }
2438
+ };
2392
2439
  return lazyStep.parseOut({
2393
2440
  ...resultStep,
2394
- out: resultStep.out === void 0 ? void 0 : JSON.stringify(resultStep.out)
2441
+ out: serializedOut
2395
2442
  });
2396
2443
  }
2397
2444
  await submitStepResult({
@@ -2736,6 +2783,11 @@ var BaseWorkflowApi = class {
2736
2783
 
2737
2784
  // src/context/api/anthropic.ts
2738
2785
  var AnthropicAPI = class extends BaseWorkflowApi {
2786
+ /**
2787
+ * Runs as a `context.call` step, so the `context.call` caveats apply.
2788
+ *
2789
+ * @see node_modules/@upstash/workflow/docs/integrations/anthropic.mdx
2790
+ */
2739
2791
  async call(stepName, settings) {
2740
2792
  const { token, operation, ...parameters } = settings;
2741
2793
  return await this.callApi(stepName, {
@@ -2751,6 +2803,11 @@ var AnthropicAPI = class extends BaseWorkflowApi {
2751
2803
  // src/context/api/openai.ts
2752
2804
  var import_qstash7 = require("@upstash/qstash");
2753
2805
  var OpenAIAPI = class extends BaseWorkflowApi {
2806
+ /**
2807
+ * Runs as a `context.call` step, so the `context.call` caveats apply.
2808
+ *
2809
+ * @see node_modules/@upstash/workflow/docs/integrations/openai.mdx
2810
+ */
2754
2811
  async call(stepName, settings) {
2755
2812
  const { token, organization, operation, baseURL, ...parameters } = settings;
2756
2813
  const useOpenAI = baseURL === void 0;
@@ -2768,6 +2825,11 @@ var OpenAIAPI = class extends BaseWorkflowApi {
2768
2825
  // src/context/api/resend.ts
2769
2826
  var import_qstash8 = require("@upstash/qstash");
2770
2827
  var ResendAPI = class extends BaseWorkflowApi {
2828
+ /**
2829
+ * Runs as a `context.call` step, so the `context.call` caveats apply.
2830
+ *
2831
+ * @see node_modules/@upstash/workflow/docs/integrations/resend.mdx
2832
+ */
2771
2833
  async call(stepName, settings) {
2772
2834
  const { token, batch = false, ...parameters } = settings;
2773
2835
  return await this.callApi(stepName, {
@@ -3009,8 +3071,9 @@ var WorkflowContext = class {
3009
3071
  *
3010
3072
  * ```ts
3011
3073
  * import { Client } from "@upstash/qstash"
3074
+ * import { serve } from "@upstash/workflow/nextjs"
3012
3075
  *
3013
- * export const POST = serve(
3076
+ * export const { POST } = serve(
3014
3077
  * async (context) => {
3015
3078
  * ...
3016
3079
  * },
@@ -3035,7 +3098,7 @@ var WorkflowContext = class {
3035
3098
  * Can be overwritten by passing a `url` parameter in `serve`:
3036
3099
  *
3037
3100
  * ```ts
3038
- * export const POST = serve(
3101
+ * export const { POST } = serve(
3039
3102
  * async (context) => {
3040
3103
  * ...
3041
3104
  * },
@@ -3053,7 +3116,7 @@ var WorkflowContext = class {
3053
3116
  *
3054
3117
  * ```ts
3055
3118
  * // set requestPayload type to MyPayload:
3056
- * export const POST = serve<MyPayload>(
3119
+ * export const { POST } = serve<MyPayload>(
3057
3120
  * async (context) => {
3058
3121
  * ...
3059
3122
  * }
@@ -3065,7 +3128,7 @@ var WorkflowContext = class {
3065
3128
  * the `initialPayloadParser` parameter:
3066
3129
  *
3067
3130
  * ```ts
3068
- * export const POST = serve<MyPayload>(
3131
+ * export const { POST } = serve<MyPayload>(
3069
3132
  * async (context) => {
3070
3133
  * ...
3071
3134
  * },
@@ -3074,6 +3137,13 @@ var WorkflowContext = class {
3074
3137
  * }
3075
3138
  * )
3076
3139
  * ```
3140
+ *
3141
+ * When a `context.call` response comes back, the route runs up to its first step with this
3142
+ * set to the call-result envelope (and `workflowRunId` set to a random id) before the SDK
3143
+ * recognizes the request. Code before the first step must not dereference, validate or
3144
+ * return early on the payload; read it inside `context.run`.
3145
+ *
3146
+ * @see node_modules/@upstash/workflow/docs/basics/serve/advanced.mdx
3077
3147
  */
3078
3148
  requestPayload;
3079
3149
  /**
@@ -3086,7 +3156,7 @@ var WorkflowContext = class {
3086
3156
  * Can be set using the `env` option of serve:
3087
3157
  *
3088
3158
  * ```ts
3089
- * export const POST = serve<MyPayload>(
3159
+ * export const { POST } = serve<MyPayload>(
3090
3160
  * async (context) => {
3091
3161
  * const key = context.env["API_KEY"];
3092
3162
  * },
@@ -3252,18 +3322,24 @@ var WorkflowContext = class {
3252
3322
  * )
3253
3323
  * ```
3254
3324
  *
3325
+ * Do not wrap steps in try/catch or `.catch` without rethrowing `WorkflowAbort`: each step
3326
+ * throws it to end the request. To stop retrying a failed step, throw
3327
+ * `WorkflowNonRetryableError`.
3328
+ *
3255
3329
  * @param stepName name of the step
3256
3330
  * @param stepFunction step function to be executed
3257
3331
  * @param stepSettings step-level settings for this step
3258
3332
  * @returns result of the step function
3333
+ * @see node_modules/@upstash/workflow/docs/steps/run.mdx
3259
3334
  */
3260
3335
  async run(stepName, stepFunction, stepSettings) {
3336
+ const normalizedSettings = normalizeStepSettings(stepSettings);
3261
3337
  if (stepSettings) {
3262
3338
  validateFlowControl(stepSettings.flowControl);
3263
3339
  }
3264
3340
  const wrappedStepFunction = (() => this.executor.wrapStep(stepName, stepFunction));
3265
3341
  return await this.addStep(
3266
- new LazyFunctionStep(this, stepName, wrappedStepFunction, stepSettings)
3342
+ new LazyFunctionStep(this, stepName, wrappedStepFunction, normalizedSettings)
3267
3343
  );
3268
3344
  }
3269
3345
  /**
@@ -3274,8 +3350,9 @@ var WorkflowContext = class {
3274
3350
  * ```
3275
3351
  *
3276
3352
  * @param stepName
3277
- * @param duration sleep duration in seconds
3353
+ * @param duration sleep duration in seconds, or a duration string such as "10m"
3278
3354
  * @returns undefined
3355
+ * @see node_modules/@upstash/workflow/docs/steps/sleep.mdx
3279
3356
  */
3280
3357
  async sleep(stepName, duration) {
3281
3358
  await this.addStep(new LazySleepStep(this, stepName, duration));
@@ -3289,8 +3366,11 @@ var WorkflowContext = class {
3289
3366
  *
3290
3367
  * @param stepName
3291
3368
  * @param datetime time to sleep until. Can be provided as a number (in unix seconds),
3292
- * as a Date object or a string (passed to `new Date(datetimeString)`)
3369
+ * as a Date object or a string (passed to `new Date(datetimeString)`).
3370
+ * A millisecond timestamp such as `Date.now()` is too far in the future, so QStash
3371
+ * rejects the step and the run fails. Pass `new Date(ms)` instead.
3293
3372
  * @returns undefined
3373
+ * @see node_modules/@upstash/workflow/docs/steps/sleepUntil.mdx
3294
3374
  */
3295
3375
  async sleepUntil(stepName, datetime) {
3296
3376
  let time;
@@ -3341,7 +3421,7 @@ var WorkflowContext = class {
3341
3421
  * Pauses workflow execution until a specific event occurs or a timeout is reached.
3342
3422
  *
3343
3423
  *```ts
3344
- * const result = await workflow.waitForEvent("payment-confirmed", "payment.confirmed", {
3424
+ * const result = await context.waitForEvent("payment-confirmed", "payment.confirmed", {
3345
3425
  * timeout: "5m"
3346
3426
  * });
3347
3427
  *```
@@ -3365,11 +3445,14 @@ var WorkflowContext = class {
3365
3445
  * Alternatively, you can use the `context.notify` method.
3366
3446
  *
3367
3447
  * @param stepName
3368
- * @param eventId - Unique identifier for the event to wait for
3448
+ * @param eventId - Unique identifier for the event to wait for. Only letters, digits,
3449
+ * "-", "_" and "." are allowed. QStash rejects other characters, such as ":", which
3450
+ * stops the run with only a "Tried to append to a cancelled workflow" warning.
3369
3451
  * @param options - Configuration options.
3370
3452
  * @returns `{ timeout: boolean, eventData: TEventData }`.
3371
3453
  * The `timeout` property specifies if the workflow has timed out. The `eventData`
3372
3454
  * is the data passed when notifying this workflow of an event.
3455
+ * @see node_modules/@upstash/workflow/docs/steps/waitForEvent.mdx
3373
3456
  */
3374
3457
  async waitForEvent(stepName, eventId, options = {}) {
3375
3458
  const { timeout = "7d" } = options;
@@ -3391,28 +3474,31 @@ var WorkflowContext = class {
3391
3474
  * will receive the given event data and resume execution.
3392
3475
  *
3393
3476
  * The response includes the same eventId and eventData. Additionally, there is
3394
- * a notifyResponse field which contains a list of `Waiter` objects, each corresponding
3395
- * to a notified workflow run.
3396
- *
3397
- * Optionally, you can pass a workflowRunId to enable lookback functionality:
3398
- *
3399
- * ```ts
3400
- * const { eventId, eventData, notifyResponse } = await context.notify(
3401
- * "notify step", "event-id", "event-data", "wfr_123"
3402
- * );
3403
- * ```
3477
+ * a notifyResponse field which contains a list of `NotifyResponse` objects, each corresponding
3478
+ * to a notified workflow run. The notified `Waiter` is under `notifyResponse[i].waiter`.
3404
3479
  *
3405
3480
  * @param stepName
3406
- * @param eventId event id to notify
3481
+ * @param eventId event id to notify. Only letters, digits, "-", "_" and "." are allowed.
3482
+ * QStash rejects other characters, such as ":", which stops the run with only a
3483
+ * "Tried to append to a cancelled workflow" warning.
3407
3484
  * @param eventData event data to notify with
3408
- * @param workflowRunId optional workflow run id for lookback support
3409
- * @returns notify response which has event id, event data and list of waiters which were notified
3485
+ * @param workflowRunId optional workflow run id for lookback: the event is kept for the run
3486
+ * even if it has not reached `waitForEvent` yet
3487
+ * @returns notify response which has event id, event data and list of waiters which were
3488
+ * notified. With `workflowRunId`, QStash returns `notifyResponse` as a single object instead
3489
+ * of an array, despite the type.
3490
+ * @see node_modules/@upstash/workflow/docs/steps/notify.mdx
3410
3491
  */
3411
3492
  async notify(stepName, eventId, eventData, workflowRunId) {
3412
3493
  return await this.addStep(
3413
3494
  new LazyNotifyStep(this, stepName, eventId, eventData, this.qstashClient.http, workflowRunId)
3414
3495
  );
3415
3496
  }
3497
+ /**
3498
+ * Starts another workflow run and waits for its result.
3499
+ *
3500
+ * @see node_modules/@upstash/workflow/docs/steps/invoke.mdx
3501
+ */
3416
3502
  async invoke(stepName, settings) {
3417
3503
  validateLabel(settings.label);
3418
3504
  validateFlowControl(settings.flowControl);
@@ -3420,9 +3506,15 @@ var WorkflowContext = class {
3420
3506
  new LazyInvokeStep(this, stepName, settings)
3421
3507
  );
3422
3508
  }
3509
+ /**
3510
+ * @see node_modules/@upstash/workflow/docs/steps/createWebhook.mdx
3511
+ */
3423
3512
  async createWebhook(stepName) {
3424
3513
  return await this.addStep(new LazyCreateWebhookStep(this, stepName));
3425
3514
  }
3515
+ /**
3516
+ * @see node_modules/@upstash/workflow/docs/steps/waitForWebhook.mdx
3517
+ */
3426
3518
  async waitForWebhook(stepName, webhook, timeout) {
3427
3519
  return await this.addStep(new LazyWaitForWebhookStep(this, stepName, webhook, timeout));
3428
3520
  }
@@ -3431,6 +3523,8 @@ var WorkflowContext = class {
3431
3523
  *
3432
3524
  * Will throw WorkflowCancelAbort to stop workflow execution.
3433
3525
  * Shouldn't be inside try/catch.
3526
+ *
3527
+ * @see node_modules/@upstash/workflow/docs/steps/cancel.mdx
3434
3528
  */
3435
3529
  async cancel() {
3436
3530
  throw new WorkflowCancelAbort();
@@ -3449,6 +3543,11 @@ var WorkflowContext = class {
3449
3543
  throw error;
3450
3544
  }
3451
3545
  }
3546
+ /**
3547
+ * Calls OpenAI, Anthropic or Resend through QStash, like `context.call`.
3548
+ *
3549
+ * @see node_modules/@upstash/workflow/docs/steps/api.mdx
3550
+ */
3452
3551
  get api() {
3453
3552
  return new WorkflowApi({
3454
3553
  context: this
@@ -4231,7 +4330,8 @@ var serveBase = (routeFunction, telemetry2, options, internalOptions) => {
4231
4330
  const invokeCount = Number(request.headers.get(WORKFLOW_INVOKE_COUNT_HEADER) ?? "0");
4232
4331
  const retried = Number(request.headers.get(WORKFLOW_RETRIED_HEADER) ?? "0");
4233
4332
  const label = request.headers.get(WORKFLOW_LABEL_HEADER) ?? void 0;
4234
- const workflowRunCreatedAt = request.headers.get(WORKFLOW_CREATED_AT_HEADER);
4333
+ const workflowRunCreatedAtHeader = request.headers.get(WORKFLOW_CREATED_AT_HEADER);
4334
+ const workflowRunCreatedAt = workflowRunCreatedAtHeader ? Number(workflowRunCreatedAtHeader) : isFirstInvocation ? Date.now() : 0;
4235
4335
  const effectiveConfig = getEffectiveConfig(request.headers);
4236
4336
  const workflowContext = new WorkflowContext({
4237
4337
  qstashClient: regionalClient,
@@ -4246,7 +4346,7 @@ var serveBase = (routeFunction, telemetry2, options, internalOptions) => {
4246
4346
  invokeCount,
4247
4347
  label,
4248
4348
  retried,
4249
- workflowRunCreatedAt: Number(workflowRunCreatedAt),
4349
+ workflowRunCreatedAt,
4250
4350
  middlewareManager
4251
4351
  });
4252
4352
  const authCheck = await DisabledWorkflowContext.tryAuthentication(
package/react-router.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
  // platforms/react-router.ts
8
8
  import { startDevServer } from "@upstash/qstash";
@@ -1,4 +1,4 @@
1
- import { d as WorkflowServeOptions, c as RouteFunction, I as InvokableWorkflow } from './types-ffLPVG5_.mjs';
1
+ import { d as WorkflowServeOptions, c as RouteFunction, I as InvokableWorkflow } from './types-CrgK5P6p.mjs';
2
2
 
3
3
  type OmitOptionsInServeMany<TOptions> = Omit<TOptions, "env" | "url" | "schema" | "initialPayloadParser">;
4
4
  declare const serveManyBase: <THandler extends (...params: any[]) => any, TOptions extends OmitOptionsInServeMany<WorkflowServeOptions> = OmitOptionsInServeMany<WorkflowServeOptions>, TServeParams extends [routeFunction: RouteFunction<any, any>, options: TOptions] = [routeFunction: RouteFunction<any, any>, options: TOptions]>({ workflows, getUrl, serveMethod, options, }: {
@@ -1,4 +1,4 @@
1
- import { d as WorkflowServeOptions, c as RouteFunction, I as InvokableWorkflow } from './types-ffLPVG5_.js';
1
+ import { d as WorkflowServeOptions, c as RouteFunction, I as InvokableWorkflow } from './types-CrgK5P6p.js';
2
2
 
3
3
  type OmitOptionsInServeMany<TOptions> = Omit<TOptions, "env" | "url" | "schema" | "initialPayloadParser">;
4
4
  declare const serveManyBase: <THandler extends (...params: any[]) => any, TOptions extends OmitOptionsInServeMany<WorkflowServeOptions> = OmitOptionsInServeMany<WorkflowServeOptions>, TServeParams extends [routeFunction: RouteFunction<any, any>, options: TOptions] = [routeFunction: RouteFunction<any, any>, options: TOptions]>({ workflows, getUrl, serveMethod, options, }: {
package/solidjs.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { APIEvent } from '@solidjs/start/server';
2
- import { c as RouteFunction, d as WorkflowServeOptions } from './types-ffLPVG5_.mjs';
2
+ import { c as RouteFunction, d as WorkflowServeOptions } from './types-CrgK5P6p.mjs';
3
3
  import '@upstash/qstash';
4
4
  import 'zod';
5
5
  import 'neverthrow';
@@ -9,9 +9,17 @@ import 'neverthrow';
9
9
  *
10
10
  * See for options https://upstash.com/docs/qstash/workflows/basics/serve
11
11
  *
12
+ * Code outside steps runs again on every request of the run. Anything it branches on or
13
+ * returns early on (Date.now(), database rows, random values) must give the same answer on
14
+ * every request, or later requests fail with "Incompatible step name" or "Failed to
15
+ * authenticate Workflow request". Read such values inside `context.run` and branch on its
16
+ * result.
17
+ *
12
18
  * @param routeFunction workflow function
13
19
  * @param options workflow options
14
20
  * @returns
21
+ * @see node_modules/@upstash/workflow/docs/basics/serve.mdx
22
+ * @see node_modules/@upstash/workflow/docs/quickstarts/solidjs.mdx
15
23
  */
16
24
  declare const serve: <TInitialPayload = unknown, TResult = unknown>(routeFunction: RouteFunction<TInitialPayload, TResult>, options?: WorkflowServeOptions<TInitialPayload, TResult>) => {
17
25
  POST: (event: APIEvent) => Promise<Response>;
package/solidjs.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { APIEvent } from '@solidjs/start/server';
2
- import { c as RouteFunction, d as WorkflowServeOptions } from './types-ffLPVG5_.js';
2
+ import { c as RouteFunction, d as WorkflowServeOptions } from './types-CrgK5P6p.js';
3
3
  import '@upstash/qstash';
4
4
  import 'zod';
5
5
  import 'neverthrow';
@@ -9,9 +9,17 @@ import 'neverthrow';
9
9
  *
10
10
  * See for options https://upstash.com/docs/qstash/workflows/basics/serve
11
11
  *
12
+ * Code outside steps runs again on every request of the run. Anything it branches on or
13
+ * returns early on (Date.now(), database rows, random values) must give the same answer on
14
+ * every request, or later requests fail with "Incompatible step name" or "Failed to
15
+ * authenticate Workflow request". Read such values inside `context.run` and branch on its
16
+ * result.
17
+ *
12
18
  * @param routeFunction workflow function
13
19
  * @param options workflow options
14
20
  * @returns
21
+ * @see node_modules/@upstash/workflow/docs/basics/serve.mdx
22
+ * @see node_modules/@upstash/workflow/docs/quickstarts/solidjs.mdx
15
23
  */
16
24
  declare const serve: <TInitialPayload = unknown, TResult = unknown>(routeFunction: RouteFunction<TInitialPayload, TResult>, options?: WorkflowServeOptions<TInitialPayload, TResult>) => {
17
25
  POST: (event: APIEvent) => Promise<Response>;