workflow 5.0.0-beta.5 → 5.0.0-beta.50

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 (256) hide show
  1. package/README.md +68 -23
  2. package/dist/api-workflow.d.ts +1 -1
  3. package/dist/api-workflow.d.ts.map +1 -1
  4. package/dist/api-workflow.js +1 -1
  5. package/dist/api.d.ts +3 -3
  6. package/dist/api.d.ts.map +1 -1
  7. package/dist/api.js +5 -7
  8. package/dist/index.d.ts +1 -0
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +6 -1
  11. package/dist/internal/builtins.d.ts +20 -3
  12. package/dist/internal/builtins.d.ts.map +1 -1
  13. package/dist/internal/builtins.js +68 -4
  14. package/dist/internal/errors.d.ts +1 -1
  15. package/dist/internal/errors.d.ts.map +1 -1
  16. package/dist/internal/errors.js +2 -2
  17. package/dist/nest-builder.d.ts +2 -0
  18. package/dist/nest-builder.d.ts.map +1 -0
  19. package/dist/nest-builder.js +2 -0
  20. package/dist/nest-vercel-builder.d.ts +2 -0
  21. package/dist/nest-vercel-builder.d.ts.map +1 -0
  22. package/dist/nest-vercel-builder.js +2 -0
  23. package/dist/observability.d.ts +1 -1
  24. package/dist/observability.js +2 -2
  25. package/dist/runtime.d.ts +2 -1
  26. package/dist/runtime.d.ts.map +1 -1
  27. package/dist/runtime.js +4 -1
  28. package/docs/ai/chat-session-modeling.mdx +29 -26
  29. package/docs/ai/defining-tools.mdx +6 -7
  30. package/docs/ai/human-in-the-loop.mdx +11 -11
  31. package/docs/ai/index.mdx +50 -45
  32. package/docs/ai/message-queueing.mdx +16 -16
  33. package/docs/ai/meta.json +1 -0
  34. package/docs/ai/resumable-streams.mdx +40 -28
  35. package/docs/ai/sleep-and-delays.mdx +10 -10
  36. package/docs/ai/streaming-updates-from-tools.mdx +6 -6
  37. package/docs/api-reference/index.mdx +24 -0
  38. package/docs/api-reference/meta.json +8 -0
  39. package/docs/api-reference/vitest/index.mdx +9 -15
  40. package/docs/api-reference/workflow/create-hook.mdx +89 -10
  41. package/docs/api-reference/workflow/create-webhook.mdx +16 -15
  42. package/docs/api-reference/workflow/define-hook.mdx +35 -33
  43. package/docs/api-reference/workflow/fatal-error.mdx +30 -8
  44. package/docs/api-reference/workflow/fetch.mdx +14 -10
  45. package/docs/api-reference/workflow/get-step-metadata.mdx +2 -2
  46. package/docs/api-reference/workflow/get-workflow-metadata.mdx +3 -3
  47. package/docs/api-reference/workflow/get-writable.mdx +7 -7
  48. package/docs/api-reference/workflow/index.mdx +4 -1
  49. package/docs/api-reference/workflow/retryable-error.mdx +1 -1
  50. package/docs/api-reference/workflow/set-attributes.mdx +61 -0
  51. package/docs/api-reference/workflow/sleep.mdx +4 -4
  52. package/docs/api-reference/workflow-ai/durable-agent.mdx +48 -86
  53. package/docs/api-reference/workflow-ai/index.mdx +3 -3
  54. package/docs/api-reference/workflow-ai/workflow-chat-transport.mdx +67 -24
  55. package/docs/api-reference/workflow-api/get-hook-by-token.mdx +26 -12
  56. package/docs/api-reference/workflow-api/get-run.mdx +43 -8
  57. package/docs/api-reference/workflow-api/index.mdx +6 -10
  58. package/docs/api-reference/workflow-api/resume-hook.mdx +73 -12
  59. package/docs/api-reference/workflow-api/resume-webhook.mdx +11 -9
  60. package/docs/api-reference/workflow-api/start.mdx +60 -13
  61. package/docs/api-reference/workflow-astro/index.mdx +18 -0
  62. package/docs/api-reference/workflow-astro/meta.json +4 -0
  63. package/docs/api-reference/workflow-astro/workflow.mdx +45 -0
  64. package/docs/api-reference/workflow-errors/entity-conflict-error.mdx +4 -4
  65. package/docs/api-reference/workflow-errors/hook-conflict-error.mdx +60 -0
  66. package/docs/api-reference/workflow-errors/hook-not-found-error.mdx +8 -8
  67. package/docs/api-reference/workflow-errors/index.mdx +88 -0
  68. package/docs/api-reference/workflow-errors/meta.json +6 -0
  69. package/docs/api-reference/workflow-errors/precondition-failed-error.mdx +68 -0
  70. package/docs/api-reference/workflow-errors/run-expired-error.mdx +2 -2
  71. package/docs/api-reference/workflow-errors/run-not-supported-error.mdx +58 -0
  72. package/docs/api-reference/workflow-errors/step-not-registered-error.mdx +5 -5
  73. package/docs/api-reference/workflow-errors/throttle-error.mdx +2 -2
  74. package/docs/api-reference/workflow-errors/too-early-error.mdx +2 -2
  75. package/docs/api-reference/workflow-errors/workflow-error.mdx +52 -0
  76. package/docs/api-reference/workflow-errors/workflow-not-registered-error.mdx +5 -6
  77. package/docs/api-reference/workflow-errors/workflow-run-cancelled-error.mdx +6 -6
  78. package/docs/api-reference/workflow-errors/workflow-run-failed-error.mdx +5 -5
  79. package/docs/api-reference/workflow-errors/workflow-run-not-completed-error.mdx +58 -0
  80. package/docs/api-reference/workflow-errors/workflow-run-not-found-error.mdx +4 -4
  81. package/docs/api-reference/workflow-errors/workflow-runtime-error.mdx +58 -0
  82. package/docs/api-reference/workflow-errors/workflow-world-error.mdx +8 -8
  83. package/docs/api-reference/workflow-globals.mdx +14 -10
  84. package/docs/api-reference/workflow-nest/configure-workflow-controller.mdx +33 -0
  85. package/docs/api-reference/workflow-nest/index.mdx +31 -0
  86. package/docs/api-reference/workflow-nest/meta.json +9 -0
  87. package/docs/api-reference/workflow-nest/nest-local-builder.mdx +64 -0
  88. package/docs/api-reference/workflow-nest/workflow-controller.mdx +40 -0
  89. package/docs/api-reference/workflow-nest/workflow-module.mdx +74 -0
  90. package/docs/api-reference/workflow-next/with-workflow.mdx +39 -17
  91. package/docs/api-reference/workflow-nitro/index.mdx +60 -0
  92. package/docs/api-reference/workflow-nuxt/index.mdx +48 -0
  93. package/docs/api-reference/workflow-observability/hydrate-data.mdx +35 -0
  94. package/docs/api-reference/workflow-observability/hydrate-resource-io.mdx +62 -0
  95. package/docs/api-reference/workflow-observability/index.mdx +62 -0
  96. package/docs/api-reference/workflow-observability/meta.json +11 -0
  97. package/docs/api-reference/workflow-observability/observability-revivers.mdx +50 -0
  98. package/docs/api-reference/workflow-observability/parse-class-name.mdx +41 -0
  99. package/docs/api-reference/workflow-observability/parse-step-name.mdx +40 -0
  100. package/docs/api-reference/workflow-observability/parse-workflow-name.mdx +55 -0
  101. package/docs/api-reference/workflow-runtime/create-world.mdx +39 -0
  102. package/docs/api-reference/workflow-runtime/get-world-handlers.mdx +44 -0
  103. package/docs/api-reference/{workflow-api → workflow-runtime}/get-world.mdx +11 -14
  104. package/docs/api-reference/workflow-runtime/health-check.mdx +50 -0
  105. package/docs/api-reference/workflow-runtime/index.mdx +41 -0
  106. package/docs/api-reference/workflow-runtime/meta.json +12 -0
  107. package/docs/api-reference/workflow-runtime/set-world.mdx +51 -0
  108. package/docs/api-reference/workflow-runtime/workflow-entrypoint.mdx +43 -0
  109. package/docs/api-reference/workflow-runtime/world/analytics.mdx +315 -0
  110. package/docs/api-reference/workflow-runtime/world/index.mdx +60 -0
  111. package/docs/api-reference/workflow-runtime/world/meta.json +4 -0
  112. package/docs/api-reference/workflow-runtime/world/queue.mdx +88 -0
  113. package/docs/api-reference/{workflow-api → workflow-runtime}/world/storage.mdx +98 -34
  114. package/docs/api-reference/{workflow-api → workflow-runtime}/world/streams.mdx +8 -8
  115. package/docs/api-reference/workflow-serde/index.mdx +1 -2
  116. package/docs/api-reference/workflow-serde/workflow-deserialize.mdx +3 -4
  117. package/docs/api-reference/workflow-serde/workflow-serialize.mdx +8 -8
  118. package/docs/api-reference/workflow-sveltekit/index.mdx +18 -0
  119. package/docs/api-reference/workflow-sveltekit/meta.json +4 -0
  120. package/docs/api-reference/workflow-sveltekit/workflow-plugin.mdx +42 -0
  121. package/docs/api-reference/workflow-vite/index.mdx +18 -0
  122. package/docs/api-reference/workflow-vite/meta.json +4 -0
  123. package/docs/api-reference/workflow-vite/workflow.mdx +48 -0
  124. package/docs/changelog/attributes-mvp.mdx +380 -0
  125. package/docs/changelog/batched-event-writes.mdx +79 -0
  126. package/docs/changelog/eager-processing.mdx +110 -436
  127. package/docs/changelog/index.mdx +4 -2
  128. package/docs/changelog/lazy-event-creation.md +127 -0
  129. package/docs/changelog/lazy-hook-resume.mdx +78 -0
  130. package/docs/changelog/meta.json +11 -1
  131. package/docs/changelog/resilient-resume.mdx +32 -0
  132. package/docs/changelog/resilient-start.mdx +33 -285
  133. package/docs/changelog/step-message-ownership.mdx +360 -0
  134. package/docs/changelog/turbo-mode.md +87 -0
  135. package/docs/comparisons/index.mdx +66 -0
  136. package/docs/comparisons/meta.json +11 -0
  137. package/docs/comparisons/workflow-sdk-vs-aws-agentcore.mdx +55 -0
  138. package/docs/comparisons/workflow-sdk-vs-aws-step-functions.mdx +111 -0
  139. package/docs/comparisons/workflow-sdk-vs-cloudflare-workflows.mdx +71 -0
  140. package/docs/comparisons/workflow-sdk-vs-inngest.mdx +102 -0
  141. package/docs/comparisons/workflow-sdk-vs-temporal.mdx +123 -0
  142. package/docs/comparisons/workflow-sdk-vs-trigger-dev.mdx +104 -0
  143. package/docs/configuration/build-and-diagnostics.mdx +70 -0
  144. package/docs/configuration/cli-and-web-ui.mdx +241 -0
  145. package/docs/configuration/framework-options.mdx +165 -0
  146. package/docs/configuration/index.mdx +32 -0
  147. package/docs/configuration/meta.json +12 -0
  148. package/docs/configuration/runtime-tuning.mdx +376 -0
  149. package/docs/configuration/worlds.mdx +313 -0
  150. package/docs/cookbook/advanced/child-workflows.mdx +211 -264
  151. package/docs/cookbook/advanced/meta.json +6 -1
  152. package/docs/cookbook/advanced/publishing-libraries.mdx +65 -56
  153. package/docs/cookbook/advanced/serializable-steps.mdx +28 -20
  154. package/docs/cookbook/advanced/upgrading-workflows.mdx +199 -0
  155. package/docs/cookbook/agent-patterns/agent-cancellation.mdx +27 -19
  156. package/docs/cookbook/agent-patterns/durable-agent.mdx +14 -142
  157. package/docs/cookbook/agent-patterns/human-in-the-loop.mdx +30 -22
  158. package/docs/cookbook/common-patterns/batching.mdx +18 -14
  159. package/docs/cookbook/common-patterns/idempotency.mdx +41 -53
  160. package/docs/cookbook/common-patterns/rate-limiting.mdx +8 -4
  161. package/docs/cookbook/common-patterns/saga.mdx +23 -19
  162. package/docs/cookbook/common-patterns/scheduling.mdx +34 -22
  163. package/docs/cookbook/common-patterns/sequential-and-parallel.mdx +29 -25
  164. package/docs/cookbook/common-patterns/timeouts.mdx +26 -21
  165. package/docs/cookbook/common-patterns/webhooks.mdx +10 -6
  166. package/docs/cookbook/common-patterns/workflow-composition.mdx +30 -27
  167. package/docs/cookbook/index.mdx +22 -21
  168. package/docs/cookbook/integrations/ai-sdk.mdx +85 -47
  169. package/docs/cookbook/integrations/chat-sdk.mdx +50 -33
  170. package/docs/cookbook/integrations/sandbox.mdx +62 -45
  171. package/docs/deploying.mdx +95 -0
  172. package/docs/errors/abort-signal-timeout-in-workflow.mdx +16 -12
  173. package/docs/errors/corrupted-event-log.mdx +29 -18
  174. package/docs/errors/deployment-mismatch.mdx +71 -0
  175. package/docs/errors/fetch-in-workflow.mdx +11 -7
  176. package/docs/errors/hook-conflict.mdx +69 -13
  177. package/docs/errors/index.mdx +2 -36
  178. package/docs/errors/node-js-module-in-workflow.mdx +9 -5
  179. package/docs/errors/replay-divergence.mdx +27 -0
  180. package/docs/errors/run-expired.mdx +85 -0
  181. package/docs/errors/runtime-decryption-failed.mdx +77 -0
  182. package/docs/errors/serialization-failed.mdx +44 -12
  183. package/docs/errors/start-invalid-workflow-function.mdx +9 -5
  184. package/docs/errors/step-executed-multiple-times.mdx +23 -0
  185. package/docs/errors/step-not-registered.mdx +6 -6
  186. package/docs/errors/timeout-in-workflow.mdx +12 -8
  187. package/docs/errors/webhook-invalid-respond-with-value.mdx +18 -18
  188. package/docs/errors/webhook-response-not-sent.mdx +20 -16
  189. package/docs/errors/workflow-not-registered.mdx +5 -5
  190. package/docs/foundations/cancellation.mdx +31 -32
  191. package/docs/foundations/errors-and-retries.mdx +42 -11
  192. package/docs/foundations/hooks.mdx +64 -35
  193. package/docs/foundations/idempotency.mdx +244 -12
  194. package/docs/foundations/index.mdx +1 -23
  195. package/docs/foundations/meta.json +2 -1
  196. package/docs/foundations/serialization.mdx +21 -22
  197. package/docs/foundations/starting-workflows.mdx +106 -30
  198. package/docs/foundations/streaming.mdx +107 -59
  199. package/docs/foundations/versioning.mdx +263 -0
  200. package/docs/foundations/workflows-and-steps.mdx +9 -9
  201. package/docs/getting-started/astro.mdx +22 -18
  202. package/docs/getting-started/express.mdx +15 -11
  203. package/docs/getting-started/fastify.mdx +15 -11
  204. package/docs/getting-started/hono.mdx +15 -11
  205. package/docs/getting-started/index.mdx +10 -3
  206. package/docs/getting-started/meta.json +3 -1
  207. package/docs/getting-started/nestjs.mdx +87 -20
  208. package/docs/getting-started/next.mdx +22 -16
  209. package/docs/getting-started/nitro.mdx +22 -18
  210. package/docs/getting-started/nuxt.mdx +15 -11
  211. package/docs/getting-started/python.mdx +135 -40
  212. package/docs/getting-started/react-router/index.mdx +33 -0
  213. package/docs/getting-started/react-router/meta.json +5 -0
  214. package/docs/getting-started/react-router/v7.mdx +237 -0
  215. package/docs/getting-started/react-router/v8.mdx +232 -0
  216. package/docs/getting-started/sveltekit.mdx +20 -16
  217. package/docs/getting-started/tanstack-start.mdx +17 -13
  218. package/docs/getting-started/vite.mdx +15 -11
  219. package/docs/how-it-works/cancellation.mdx +63 -63
  220. package/docs/how-it-works/code-transform.mdx +83 -67
  221. package/docs/how-it-works/encryption.mdx +30 -26
  222. package/docs/how-it-works/event-sourcing.mdx +98 -34
  223. package/docs/how-it-works/framework-integrations.mdx +96 -337
  224. package/docs/how-it-works/understanding-directives.mdx +22 -22
  225. package/docs/internal/index.mdx +6 -4
  226. package/docs/internal/meta.json +6 -1
  227. package/docs/internal/nitro-native-build.mdx +38 -0
  228. package/docs/internal/nitro-web-ui.mdx +24 -0
  229. package/docs/internal/serializable-abort-controller.mdx +7 -7
  230. package/docs/meta.json +3 -2
  231. package/docs/observability/attributes.mdx +134 -0
  232. package/docs/observability/index.mdx +32 -10
  233. package/docs/observability/meta.json +1 -1
  234. package/docs/observability/retention.mdx +93 -0
  235. package/docs/observability/tracing.mdx +124 -0
  236. package/docs/testing/index.mdx +36 -36
  237. package/docs/testing/server-based.mdx +10 -10
  238. package/docs/whats-new.mdx +186 -0
  239. package/package.json +17 -14
  240. package/docs/api-reference/workflow-api/world/index.mdx +0 -58
  241. package/docs/api-reference/workflow-api/world/meta.json +0 -4
  242. package/docs/api-reference/workflow-api/world/observability.mdx +0 -164
  243. package/docs/api-reference/workflow-api/world/queue.mdx +0 -86
  244. package/docs/deploying/building-a-world.mdx +0 -251
  245. package/docs/deploying/index.mdx +0 -95
  246. package/docs/deploying/meta.json +0 -4
  247. package/docs/deploying/world/local-world.mdx +0 -84
  248. package/docs/deploying/world/meta.json +0 -4
  249. package/docs/deploying/world/postgres-world.mdx +0 -224
  250. package/docs/deploying/world/vercel-world.mdx +0 -179
  251. package/docs/migration-guides/index.mdx +0 -34
  252. package/docs/migration-guides/meta.json +0 -9
  253. package/docs/migration-guides/migrating-from-aws-step-functions.mdx +0 -363
  254. package/docs/migration-guides/migrating-from-inngest.mdx +0 -314
  255. package/docs/migration-guides/migrating-from-temporal.mdx +0 -318
  256. package/docs/migration-guides/migrating-from-trigger-dev.mdx +0 -337
@@ -1,363 +0,0 @@
1
- ---
2
- title: Migrating from AWS Step Functions
3
- description: Move an AWS Step Functions state machine to the Workflow SDK by replacing JSON state definitions, Task states, Choice/Wait/Parallel states, Retry/Catch blocks, and .waitForTaskToken callbacks with Workflows, Steps, Hooks, and idiomatic TypeScript control flow.
4
- type: guide
5
- summary: Translate an AWS Step Functions state machine into the Workflow SDK with side-by-side code examples.
6
- prerequisites:
7
- - /docs/getting-started/next
8
- - /docs/foundations/workflows-and-steps
9
- related:
10
- - /docs/foundations/starting-workflows
11
- - /docs/foundations/errors-and-retries
12
- - /docs/foundations/hooks
13
- - /docs/foundations/streaming
14
- - /docs/deploying/world/vercel-world
15
- ---
16
-
17
- Move an AWS Step Functions state machine to the Workflow SDK by replacing JSON state definitions with TypeScript functions. This guide shows the direct mapping between ASL states and Workflow SDK primitives.
18
-
19
- <Callout type="info">
20
- Install the Workflow SDK migration skill:
21
-
22
- ```bash
23
- npx skills add https://github.com/vercel/workflow --skill migrating-to-workflow-sdk
24
- ```
25
- </Callout>
26
-
27
- ## Why migrate to the Workflow SDK
28
-
29
- - Orchestration code is TypeScript, not JSON ASL. Transitions are `await`, branches are `if`/`switch`, and parallelism is `Promise.all`.
30
- - Streaming is built in. Write durable progress from steps with `getWritable()` and named streams. No DynamoDB or SNS glue to surface status to clients.
31
- - Infrastructure lives in one deployment. No separate state machine, per-task Lambda, IAM role wiring, or callback SQS queues.
32
- - Error handling is TypeScript-native: step-level retries, `RetryableError`, and `FatalError` replace per-state Retry/Catch blocks.
33
- - The `npx workflow` CLI and `npx workflow web` observability UI ship out of the box.
34
- - AI/agent helpers — `@workflow/ai` for AI-SDK integration and the Claude migration skill — are available as separate installs.
35
-
36
- ## Before you migrate
37
-
38
- This guide assumes **Standard** workflows. Express workflows have different semantics (at-least-once, 5-minute max duration, no execution history) and may need a different target — consider keeping them on Step Functions, moving them to a queue consumer, or ensuring your steps are idempotent before replaying the pattern here.
39
-
40
- ## What changes when you leave Step Functions?
41
-
42
- AWS Step Functions defines workflows as JSON state machines using Amazon States Language (ASL). Each state (Task, Choice, Wait, Parallel, Map) is a node in a declarative graph. Lambda functions handle tasks, Retry/Catch blocks configure per-state error handling, and `.waitForTaskToken` manages callbacks.
43
-
44
- The Workflow SDK replaces that JSON DSL with TypeScript. `"use workflow"` functions orchestrate `"use step"` functions in the same file. Branching is `if`/`else`. Waiting is `sleep()`. Parallelism is `Promise.all()`. Retries move down to the step level.
45
-
46
- The migration replaces declarative configuration with idiomatic TypeScript and collapses the orchestrator and compute split. Business logic stays the same.
47
-
48
- ## Concept mapping
49
-
50
- | AWS Step Functions | Workflow SDK | Migration note |
51
- | --- | --- | --- |
52
- | State machine (ASL JSON) | `"use workflow"` function | The workflow function is the state machine. |
53
- | Task state / Lambda | `"use step"` function | Side effects go in steps. No separate Lambda. |
54
- | Choice state | `if` / `else` / `switch` | Native TypeScript control flow. |
55
- | Wait state | `sleep()` | Import `sleep` from `workflow`. |
56
- | Parallel state | `Promise.all()` | Standard concurrency primitives. |
57
- | Map state | Inline sequential → `for` loop; bounded parallel (`MaxConcurrency: N`) → batched `Promise.all` or a concurrency limiter like `p-limit`; Distributed Map / large fan-out → step-wrapped `start()` per item, then step-wrapped `getRun()` to collect. | Match the concurrency mode of the original Map. |
58
- | Retry / Catch | Step retries, `RetryableError`, `FatalError` | Retry logic moves to step boundaries. |
59
- | `Catch` to a compensation state | `try`/`catch` in the workflow function, calling compensation steps in reverse order (push/pop a rollback stack) | See [`/docs/foundations/errors-and-retries`](/docs/foundations/errors-and-retries) for the SAGA pattern. |
60
- | `.waitForTaskToken` | `createHook()` or `createWebhook()` | Hooks for typed signals; webhooks for HTTP. |
61
- | Child state machine (`StartExecution`) | `"use step"` around `start()` / `getRun()` | Return the `Run` object, await its result from another step. |
62
- | Execution event history | Workflow event log | Same durable replay model. |
63
- | Progress via DynamoDB / SNS for client polling | `getWritable()` + named streams | Stream durable updates; clients read from the stream. |
64
-
65
- <Callout type="info">
66
- `.waitForTaskToken` becomes `createHook()` or `createWebhook()`. Choice states become `if`/`else`. Map states become `Promise.all()`. Retry policies move from per-state configuration to step-level defaults.
67
- </Callout>
68
-
69
- ## Translate your first workflow
70
-
71
- Start with a single Task state. In ASL, even "call one Lambda" requires a state machine shell:
72
-
73
- ```json title="stateMachine.asl.json (Step Functions)"
74
- "LoadOrder": {
75
- "Type": "Task",
76
- "Resource": "arn:aws:states:::lambda:invoke",
77
- "Parameters": { "FunctionName": "loadOrder", "Payload.$": "$" },
78
- "End": true
79
- }
80
- ```
81
-
82
- <Callout type="info">
83
- Examples use JSONPath mode. If your state machine sets `QueryLanguage: 'JSONata'`, the shape of `Arguments`/`Output` fields differs but the TypeScript translation is identical.
84
- </Callout>
85
-
86
- ```typescript title="workflow/workflows/order.ts (Workflow SDK)"
87
- export async function processOrder(orderId: string) {
88
- 'use workflow'; // [!code highlight]
89
- return await loadOrder(orderId);
90
- }
91
-
92
- async function loadOrder(orderId: string) {
93
- 'use step'; // [!code highlight]
94
- const res = await fetch(`https://example.com/api/orders/${orderId}`);
95
- return res.json() as Promise<{ id: string }>;
96
- }
97
- ```
98
-
99
- What changed: the ASL state machine and its Lambda collapse into two directive-tagged functions in one file.
100
-
101
- ### Adding a second step
102
-
103
- In ASL, a second Task means a new state and a `"Next"` transition. In the Workflow SDK, it's another `await`:
104
-
105
- ```typescript
106
- export async function processOrder(orderId: string) {
107
- 'use workflow';
108
- const order = await loadOrder(orderId);
109
- await reserveInventory(order.id); // [!code highlight]
110
- return { orderId: order.id, status: 'reserved' };
111
- }
112
- ```
113
-
114
- `await` replaces `"Next"`. Each new step is a new function with `"use step"`; no additional deployment. The second version also reshapes the return value; the workflow return type can be anything serializable.
115
-
116
- ### Starting from an API route
117
-
118
- Step Functions starts a run via `StartExecution` (AWS SDK or API Gateway integration). The Workflow SDK starts a run with `start()` from a route handler:
119
-
120
- ```typescript title="app/api/orders/route.ts"
121
- import { start } from 'workflow/api';
122
- import { processOrder } from '@/workflows/order';
123
-
124
- export async function POST(request: Request) {
125
- const { orderId } = (await request.json()) as { orderId: string };
126
- const run = await start(processOrder, [orderId]); // [!code highlight]
127
- return Response.json({ runId: run.runId });
128
- }
129
- ```
130
-
131
- ### Waiting for a fixed duration
132
-
133
- A `Wait` state becomes `sleep()`:
134
-
135
- ```json title="stateMachine.asl.json (Step Functions)"
136
- { "Type": "Wait", "Seconds": 60, "Next": "Next" }
137
- ```
138
-
139
- {/* @skip-typecheck: one-line snippet fragment */}
140
-
141
- ```typescript title="workflow/workflows/order.ts (Workflow SDK)"
142
- await sleep('1m');
143
- ```
144
-
145
- ## Wait for an external signal
146
-
147
- The minimal ASL for a callback is a Task with `.waitForTaskToken`:
148
-
149
- ```json title="approval.asl.json (Step Functions)"
150
- "WaitForApproval": {
151
- "Type": "Task",
152
- "Resource": "arn:aws:states:::sqs:sendMessage.waitForTaskToken",
153
- "Parameters": {
154
- "QueueUrl": "https://sqs.us-east-1.amazonaws.com/123456789012/approvals",
155
- "MessageBody": {
156
- "refundId.$": "$.refundId",
157
- "TaskToken.$": "$$.Task.Token"
158
- }
159
- },
160
- "End": true
161
- }
162
- ```
163
-
164
- ```typescript title="workflow/workflows/refund.ts (Workflow SDK)"
165
- import { createHook } from 'workflow';
166
-
167
- export async function refundWorkflow(refundId: string) {
168
- 'use workflow';
169
- using approval = createHook<{ approved: boolean }>({ // [!code highlight]
170
- token: `refund:${refundId}:approval`,
171
- });
172
- return await approval;
173
- }
174
- ```
175
-
176
- What changed: no SQS queue, no task token, no callback Lambda. The hook suspends the workflow durably until it is resumed.
177
-
178
- ### Resuming the hook
179
-
180
- Step Functions resumes by calling `SendTaskSuccess` with the task token. The Workflow SDK resumes by calling `resumeHook` with the hook's token:
181
-
182
- ```typescript title="app/api/refunds/[refundId]/approve/route.ts"
183
- import { resumeHook } from 'workflow/api';
184
-
185
- export async function POST(req: Request, { params }: { params: Promise<{ refundId: string }> }) {
186
- const { refundId } = await params;
187
- const { approved } = (await req.json()) as { approved: boolean };
188
- await resumeHook(`refund:${refundId}:approval`, { approved }); // [!code highlight]
189
- return Response.json({ ok: true });
190
- }
191
- ```
192
-
193
- ### Branching on the result
194
-
195
- In ASL, branching after the wait requires a Choice state. In TypeScript, it's just `if`/`else`:
196
-
197
- ```json title="approval.asl.json (Step Functions)"
198
- "CheckApproval": {
199
- "Type": "Choice",
200
- "Choices": [
201
- { "Variable": "$.approved", "BooleanEquals": true, "Next": "Approved" }
202
- ],
203
- "Default": "Rejected"
204
- }
205
- ```
206
-
207
- {/* @skip-typecheck: continuation snippet */}
208
- ```typescript title="workflow/workflows/refund.ts (Workflow SDK)"
209
- const { approved } = await approval;
210
- if (approved) return { refundId, status: 'approved' }; // [!code highlight]
211
- return { refundId, status: 'rejected' };
212
- ```
213
-
214
- ## Spawn a child workflow
215
-
216
- In ASL, a parent machine calls `StartExecution` (usually via `.sync` or `.waitForTaskToken`) to launch a child. In the Workflow SDK, `start()` and `getRun()` are runtime APIs, so wrap them in `"use step"` functions. Returning the `Run` object from the spawn step lets workflow observability deep-link to the child run.
217
-
218
- ### Parent starts a child
219
-
220
- ```typescript title="workflow/workflows/parent.ts"
221
- import { start } from 'workflow/api';
222
-
223
- async function spawnChild(item: string) {
224
- 'use step'; // [!code highlight]
225
- return await start(childWorkflow, [item]);
226
- }
227
-
228
- export async function parentWorkflow(item: string) {
229
- 'use workflow';
230
- const run = await spawnChild(item);
231
- return { childRunId: run.runId };
232
- }
233
- ```
234
-
235
- ### Awaiting the child's result
236
-
237
- Add a second step that wraps `getRun()` and awaits `returnValue`:
238
-
239
- ```typescript
240
- import { getRun } from 'workflow/api';
241
-
242
- async function collectResult(runId: string) {
243
- 'use step'; // [!code highlight]
244
- const run = getRun(runId);
245
- return (await run.returnValue) as { item: string; result: string };
246
- }
247
- ```
248
-
249
- Then in the workflow: `const result = await collectResult(run.runId);`. The child workflow itself (`childWorkflow`) is defined elsewhere with `"use workflow"`.
250
-
251
- ## What you stop operating
252
-
253
- Moving off Step Functions removes these surfaces from the application:
254
-
255
- - ASL state machine JSON and its reference syntax.
256
- - Per-task Lambda functions, their IAM roles, and CloudFormation/CDK wiring.
257
- - Task-token delivery infrastructure (SQS queues, callback Lambdas).
258
- - Separate progress channels (DynamoDB, SNS) for client-visible updates.
259
- - Remove CloudWatch and X-Ray wiring that was specific to orchestrator state transitions. Keep (or re-wire) any application-level CloudWatch alarms, log retention policies, or X-Ray propagation that the rest of your AWS footprint still depends on. Workflow SDK exports OTEL traces, so existing OTEL-compatible backends can continue to ingest them.
260
-
261
- Workflow and step functions live in the same deployment as the application. State transitions are ordinary control flow (`await`, `if`, `Promise.all`, `for`). Progress streaming, retries, and observability are built in.
262
-
263
- ### What you take on
264
-
265
- Steps that previously invoked AWS services via optimized integrations (EventBridge, DynamoDB, Bedrock, ECS.RunTask.sync, etc.) become ordinary SDK calls inside `'use step'` functions. Credentials and retries move into the step, and `.sync`-style waits for long-running jobs become explicit polling loops or hook-based callbacks.
266
-
267
- ## Step-by-step first migration
268
-
269
- Pick one state machine and migrate it end-to-end before touching the rest. The steps below describe the smallest viable path.
270
-
271
- ### Step 1: Install the Workflow SDK
272
-
273
- Add the `workflow` runtime package.
274
-
275
- ```bash
276
- pnpm add workflow
277
- ```
278
-
279
- ### Step 2: Rewrite the state machine as a `"use workflow"` function
280
-
281
- Transitions become `await` calls. Control flow (`Choice`, `Wait`, `Parallel`, `Map`) becomes `if`/`switch`, `sleep`, `Promise.all`, and loops.
282
-
283
- ```ts title="workflows/order.ts"
284
- export async function processOrder(orderId: string) {
285
- "use workflow"; // [!code highlight]
286
- const order = await loadOrder(orderId);
287
- if (order.total > 1000) await reviewManually(order);
288
- await chargePayment(order);
289
- }
290
- ```
291
-
292
- ### Step 3: Move each Lambda into a step function
293
-
294
- Inline the Lambda body into a function with `"use step"` on the first line. Step functions keep full Node.js access, so existing SDK calls work unchanged.
295
-
296
- ```ts
297
- async function loadOrder(id: string) {
298
- "use step"; // [!code highlight]
299
- return fetch(`/api/orders/${id}`).then((r) => r.json());
300
- }
301
- ```
302
-
303
- ### Step 4: Replace `.waitForTaskToken` with a hook
304
-
305
- Swap the task-token callback Lambda for `createHook()`. Callers `resumeHook(token, payload)` instead of `SendTaskSuccess`.
306
-
307
- Move Retry/Catch off per-state configuration and onto step boundaries. Set `maxRetries` as a function property; throw `RetryableError` or `FatalError` to control retry behavior:
308
-
309
- ```typescript
310
- async function chargePayment(orderId: string) {
311
- "use step";
312
- // ...
313
- }
314
- chargePayment.maxRetries = 5;
315
- ```
316
-
317
- See [`/docs/foundations/errors-and-retries`](/docs/foundations/errors-and-retries) for the full retry and SAGA compensation patterns.
318
-
319
- ### Step 5: Start runs from an API route
320
-
321
- Delete the `StartExecution` call and IAM wiring. Launch runs directly from a route handler:
322
-
323
- ```ts title="app/api/orders/route.ts"
324
- import { start } from "workflow/api";
325
- import { processOrder } from "@/workflows/order";
326
-
327
- export async function POST(req: Request) {
328
- const { orderId } = await req.json();
329
- const run = await start(processOrder, [orderId]);
330
- return Response.json({ runId: run.runId });
331
- }
332
- ```
333
-
334
- ### Step 6: Retire the Step Functions infrastructure
335
-
336
- Delete the ASL JSON, per-task Lambda deployments, IAM roles, and callback queues. Remove CloudWatch and X-Ray wiring that was specific to orchestrator state transitions — keep alarms, log retention, and traces for resources you still depend on. Verify the run in `npx workflow web` before shipping.
337
-
338
- ## Features without a 1:1 equivalent
339
-
340
- - **Express workflows.** At-least-once semantics and 5-minute duration make them a poor fit for the SDK's durable replay model. Consider keeping them on Step Functions or migrating to a queue consumer.
341
- - **Distributed Map state.** Up to 10,000 concurrent child executions with S3 item sources has no 1:1 analog; fan out with step-wrapped `start()` per item, then `Promise.all` with `p-limit` to bound concurrency.
342
- - **Optimized AWS service integrations (`arn:aws:states:::dynamodb:*`, `eventbridge:*`, `bedrock:*`, `ecs:runTask.sync`, etc.).** These become regular SDK calls inside `'use step'` functions — credentials, retries, and polling move into the step.
343
- - **Per-state IAM roles.** ASL lets each state run under its own IAM role. In the SDK, all steps share the deployment's credentials; scope secrets and roles at deployment time.
344
- - **CloudWatch alarms / X-Ray cross-service traces / CloudWatch Logs retention.** The SDK event log + observability UI replaces orchestrator state transitions, not AWS-wide observability. Keep alarms and traces for other resources.
345
- - **`JSONata` `QueryLanguage` mode.** Valid at the source; the TS translation is identical regardless of mode.
346
-
347
- ## Quick-start checklist
348
-
349
- - Replace the ASL state machine with a single `"use workflow"` function. Transitions become `await` calls.
350
- - Convert each Task / Lambda into a `"use step"` function in the same file.
351
- - Replace Choice states with `if`/`else`/`switch`.
352
- - Replace Wait states with `sleep()` from `workflow`.
353
- - Replace Parallel states with `Promise.all()`.
354
- - Replace Map states based on their concurrency mode: inline sequential → `for` loop; bounded parallel (`MaxConcurrency: N`) → batched `Promise.all` or a concurrency limiter like `p-limit`; Distributed Map / large fan-out → step-wrapped `start()` per item, then step-wrapped `getRun()` to collect.
355
- - Replace `StartExecution` child machines with `"use step"` wrappers around `start()` and `getRun()`.
356
- - Replace `.waitForTaskToken` with `createHook()` (internal callers) or `createWebhook()` (HTTP callers).
357
- - Move Retry/Catch to step boundaries using `maxRetries`, `RetryableError`, and `FatalError`.
358
- - Use `getStepMetadata().stepId` as the idempotency key for external side effects.
359
- - Stream progress from steps with `getWritable()` instead of polling DynamoDB or SNS.
360
- - Deploy and verify runs end-to-end with built-in observability.
361
-
362
- ---
363
- *Verified against `workflow@5.0.0-beta.1` and the AWS Step Functions Amazon States Language spec on 2026-04-16.*
@@ -1,314 +0,0 @@
1
- ---
2
- title: Migrating from Inngest
3
- description: Move an Inngest TypeScript SDK v3 or v4 app to the Workflow SDK by replacing createFunction, step.run(), step.sleep(), step.waitForEvent(), and step.invoke() with Workflows, Steps, Hooks, and start()/getRun().
4
- type: guide
5
- summary: Translate an Inngest app into the Workflow SDK with side-by-side code examples.
6
- prerequisites:
7
- - /docs/getting-started/next
8
- - /docs/foundations/workflows-and-steps
9
- related:
10
- - /docs/foundations/starting-workflows
11
- - /docs/foundations/errors-and-retries
12
- - /docs/foundations/hooks
13
- - /docs/foundations/streaming
14
- - /docs/deploying/world/vercel-world
15
- ---
16
-
17
- <Callout type="info">
18
- Install the Workflow SDK migration skill:
19
-
20
- ```bash
21
- npx skills add https://github.com/vercel/workflow --skill migrating-to-workflow-sdk
22
- ```
23
- </Callout>
24
-
25
- ## Why migrate to the Workflow SDK
26
-
27
- - Streaming is built in. Durable progress writes go to named streams via `getWritable()`. There is no separate realtime publish channel or WebSocket layer to operate.
28
- - Infrastructure and orchestration live in a single deployment. Workflows run where the app runs. There is no separate Inngest Dev Server or event bus to operate.
29
- - TypeScript-first DX. Steps are named async functions marked with `"use step"`. No inline closures tied to a framework-specific lifecycle.
30
- - Agent-first tooling: the `npx workflow` CLI, `@workflow/ai` integration for durable AI agents, and a Claude skill for generating workflows.
31
-
32
- Inngest code samples in this guide use the v4 two-argument `createFunction({ id, triggers }, handler)` shape. If the app is still on Inngest v3, treat the three-argument form `createFunction({ id }, { event: '...' }, handler)` as equivalent — the `triggers` option in v4 replaces the second argument in v3.
33
-
34
- ## What changes when you leave Inngest
35
-
36
- Inngest defines functions with `inngest.createFunction()`, registers them through a `serve()` handler, and breaks work into steps with `step.run()`, `step.sleep()`, and `step.waitForEvent()`. The platform routes events, schedules steps, and applies retries.
37
-
38
- The Workflow SDK replaces that with `"use workflow"` functions that orchestrate `"use step"` functions in plain TypeScript. There is no function registry, event dispatch layer, or SDK client. Durable replay, automatic retries, and step-level persistence are built into the runtime.
39
-
40
- Migration collapses the SDK abstraction into plain async functions. Business logic stays the same.
41
-
42
- <Callout type="info">
43
- Inngest's event-bus model is loosely coupled — publishers don't know consumers. `start()` requires the caller to import the workflow function directly, giving stronger type safety but tighter coupling. For event-bus-like fan-out, wrap `start()` in a shared publisher module.
44
- </Callout>
45
-
46
- ## Concept mapping
47
-
48
- | Inngest | Workflow SDK | Migration note |
49
- | --- | --- | --- |
50
- | `inngest.createFunction()` | `"use workflow"` function started with `start()` | No wrapper needed. |
51
- | `step.run()` | `"use step"` function | Standalone async function with Node.js access. |
52
- | `step.sleep()` / `step.sleepUntil()` | `sleep()` | `sleep('5m')` for a duration; `sleep(date)` for sleep-until. |
53
- | `step.waitForEvent()` | `createHook()` or `createWebhook()` | Hooks for typed signals, webhooks for HTTP. |
54
- | `step.invoke()` | `"use step"` wrappers around `start()` / `getRun()` | Spawn a child run, pass `runId` forward. |
55
- | `inngest.send()` / event triggers | `start()` from your app boundary | Start workflows directly. |
56
- | Retry configuration (`retries`) | `RetryableError`, `FatalError`, `maxRetries` | Retry logic lives at the step level. |
57
- | `step.sendEvent()` | `"use step"` wrapper around `start()` | Fan out via `start()`, not an event bus. |
58
- | Realtime / `step.realtime.publish()` | `getWritable()` / `getWritable({ namespace })` | Named streams are the canonical way for clients to read workflow status. No database or `getRun()` polling required. |
59
-
60
- ## Translate your first workflow
61
-
62
- Start with the shell of a function. Inngest wraps it in `createFunction`; Workflow SDK marks it with a directive.
63
-
64
- {/* @skip-typecheck: Inngest SDK types not available */}
65
- ```typescript title="inngest/functions/order.ts"
66
- export const processOrder = inngest.createFunction(
67
- {
68
- id: 'process-order',
69
- triggers: { event: 'order/created' },
70
- },
71
- async ({ event, step }) => {
72
- return { orderId: event.data.orderId, status: 'completed' };
73
- }
74
- );
75
- ```
76
-
77
- ```typescript title="workflow/workflows/order.ts"
78
- export async function processOrder(orderId: string) {
79
- 'use workflow'; // [!code highlight]
80
- return { orderId, status: 'completed' };
81
- }
82
- ```
83
-
84
- **What changed:** the factory + event binding collapses into a plain exported function with a `"use workflow"` directive.
85
-
86
- ### Add a step
87
-
88
- `step.run()` closures become named `"use step"` functions.
89
-
90
- ```typescript title="workflow/workflows/order.ts"
91
- async function loadOrder(orderId: string) {
92
- 'use step'; // [!code highlight]
93
- const res = await fetch(`https://example.com/api/orders/${orderId}`);
94
- return res.json() as Promise<{ id: string }>;
95
- }
96
- ```
97
-
98
- Call it from the workflow like any async function: `const order = await loadOrder(orderId)`. Additional side effects (`reserveInventory`, `chargePayment`) follow the same shape.
99
-
100
- ### Start the run
101
-
102
- Inngest dispatches via `inngest.send({ name: 'order/created', data: { orderId } })`. Workflow SDK launches directly:
103
-
104
- ```typescript title="app/api/orders/route.ts"
105
- import { start } from 'workflow/api';
106
- import { processOrder } from '@/workflows/order';
107
-
108
- const run = await start(processOrder, [orderId]); // [!code highlight]
109
- ```
110
-
111
- No event bus, no registry. `start()` returns a handle immediately.
112
-
113
- ## Wait for an external signal
114
-
115
- `step.waitForEvent()` becomes `createHook()` plus `await`.
116
-
117
- ```typescript title="workflow/workflows/refund.ts (Inngest)"
118
- const approval = await step.waitForEvent('wait-for-approval', {
119
- event: 'refund/approved',
120
- match: 'data.refundId',
121
- timeout: '7d',
122
- });
123
- ```
124
-
125
- {/* @skip-typecheck: snippet without imports */}
126
- ```typescript title="workflow/workflows/refund.ts (Workflow SDK)"
127
- using approval = createHook<{ approved: boolean }>({ // [!code highlight]
128
- token: `refund:${refundId}:approval`,
129
- });
130
- const payload = await approval;
131
- ```
132
-
133
- **What changed:** event name + match expression collapse into a single `token` string. The caller supplies that token directly, with no event schema.
134
-
135
- ### Resume from an API route
136
-
137
- Inngest resumes with `inngest.send({ name: 'refund/approved', data: { refundId, approved } })`. The SDK equivalent is `resumeHook`:
138
-
139
- ```typescript title="app/api/refunds/[refundId]/approve/route.ts"
140
- import { resumeHook } from 'workflow/api';
141
-
142
- export async function POST(request: Request, { params }: { params: Promise<{ refundId: string }> }) {
143
- const { refundId } = await params;
144
- const { approved } = (await request.json()) as { approved: boolean };
145
- await resumeHook(`refund:${refundId}:approval`, { approved }); // [!code highlight]
146
- return Response.json({ ok: true });
147
- }
148
- ```
149
-
150
- ### Add a timeout and branch on the payload
151
-
152
- Inngest's `timeout: '7d'` option maps to a `Promise.race()` with `sleep()`:
153
-
154
- {/* @skip-typecheck: continuation snippet */}
155
- ```typescript title="workflow/workflows/refund.ts"
156
- const result = await Promise.race([
157
- approval.then((p) => ({ type: 'decision' as const, approved: p.approved })),
158
- sleep('7d').then(() => ({ type: 'timeout' as const })), // [!code highlight]
159
- ]);
160
-
161
- if (result.type === 'timeout') return { refundId, status: 'timed-out' };
162
- if (!result.approved) return { refundId, status: 'rejected' };
163
- return { refundId, status: 'approved' };
164
- ```
165
-
166
- <Callout type="info">
167
- Event matching disappears. A hook's token encodes the routing (for example, `refund:${refundId}:approval`), and the caller supplies that token to `resumeHook()`.
168
- </Callout>
169
-
170
- ## Spawn a child workflow
171
-
172
- `step.invoke()` splits into two steps: spawn and collect. `start()` and `getRun()` are runtime APIs, so wrap them in `"use step"` functions. Return the `Run` object from the spawn step so observability can deep-link into the child run.
173
-
174
- You can return either the full `Run` object (enables deep-linking) or just `run.runId` (simpler).
175
-
176
- {/* @skip-typecheck: snippet without imports */}
177
- ```typescript title="workflow/workflows/parent.ts"
178
- async function spawnChild(item: string) {
179
- 'use step';
180
- return start(childWorkflow, [item]); // [!code highlight]
181
- }
182
- ```
183
-
184
- Await the result in a second step, then orchestrate both from the parent:
185
-
186
- {/* @skip-typecheck: snippet without imports */}
187
- ```typescript title="workflow/workflows/parent.ts"
188
- async function collectResult(runId: string) {
189
- 'use step';
190
- const run = getRun(runId);
191
- return await run.returnValue; // [!code highlight]
192
- }
193
-
194
- export async function parentWorkflow(item: string) {
195
- 'use workflow';
196
- const child = await spawnChild(item);
197
- return await collectResult(child.runId);
198
- }
199
- ```
200
-
201
- ## What you stop operating
202
-
203
- Dropping the Inngest SDK removes several moving parts:
204
-
205
- - **No SDK client or serve handler.** Workflow files carry directive annotations. No registry, no serve endpoint.
206
- - **No event bus.** `start()` launches workflows directly from API routes, server actions, or other entry points. No event schemas or dispatch layer.
207
- - **No inline step closures.** Steps are named async functions. They type-check and test like any other TypeScript function.
208
- - **No separate streaming transport.** `getWritable()` delivers progress to clients without WebSockets or SSE glue.
209
- - **No idle workers.** Workflows suspended on `sleep()` or a hook consume no compute until resumed.
210
-
211
- ## Step-by-step first migration
212
-
213
- Pick one Inngest function and migrate it end-to-end before touching the rest. The steps below describe the smallest viable path.
214
-
215
- ### Step 1: Install the Workflow SDK
216
-
217
- Install the SDK. Framework integrations (`workflow/next`, `workflow/nitro`, `workflow/nuxt`, etc.) are subpath exports of the same `workflow` package — no additional install needed.
218
-
219
- ```bash
220
- pnpm add workflow
221
- ```
222
-
223
- ### Step 2: Convert `createFunction` to a `"use workflow"` export
224
-
225
- Replace the factory call with a plain async export. Move the handler body up. The event-binding argument goes away.
226
-
227
- ```ts title="workflows/order.ts"
228
- // Before (Inngest)
229
- // export const processOrder = inngest.createFunction(
230
- // { id: "process-order", triggers: { event: "order/created" } },
231
- // async ({ event, step }) => { ... }
232
- // );
233
-
234
- // After (Workflow SDK)
235
- export async function processOrder(orderId: string) {
236
- "use workflow"; // [!code highlight]
237
- // ...
238
- }
239
- ```
240
-
241
- ### Step 3: Convert `step.run` callbacks into named step functions
242
-
243
- Each inline callback becomes a named function with `"use step"` on the first line. The workflow calls them with a plain `await`.
244
-
245
- ```ts
246
- async function loadOrder(id: string) {
247
- "use step"; // [!code highlight]
248
- return fetch(`https://example.com/api/orders/${id}`).then((r) => r.json());
249
- }
250
- ```
251
-
252
- Configure per-step retry counts by assigning `maxRetries` as a function property:
253
-
254
- ```ts
255
- async function callApi(endpoint: string) {
256
- "use step";
257
- const response = await fetch(endpoint);
258
- return response.json();
259
- }
260
- callApi.maxRetries = 5;
261
- ```
262
-
263
- See [Errors and retries](/docs/foundations/errors-and-retries) for full retry docs.
264
-
265
- ### Step 4: Replace `waitForEvent`, `sleep`, and `invoke`
266
-
267
- - `step.waitForEvent(...)` → `createHook({ token })` + `await hook`. Resume it from an API route with `resumeHook(token, payload)`.
268
- - `step.sleep(...)` → `sleep("5m")` from `workflow`.
269
- - `step.invoke(child, { data })` → wrap `start(child, [data])` in a `"use step"` function that returns the `Run`, and optionally read its return value with `getRun(run.runId).returnValue`.
270
-
271
- ### Step 5: Start runs from the app
272
-
273
- Delete the `serve()` handler and event dispatch. Launch runs directly from an API route:
274
-
275
- ```ts title="app/api/orders/route.ts"
276
- import { start } from "workflow/api";
277
- import { processOrder } from "@/workflows/order";
278
-
279
- export async function POST(req: Request) {
280
- const { orderId } = await req.json();
281
- const run = await start(processOrder, [orderId]);
282
- return Response.json({ runId: run.runId });
283
- }
284
- ```
285
-
286
- ### Step 6: Retire the Inngest infrastructure
287
-
288
- Remove the `inngest` client, the `serve()` route, event schemas, and the Inngest Dev Server from the app. Verify the run in `npx workflow web` before shipping.
289
-
290
- ## Features without a 1:1 equivalent
291
-
292
- - **Cron / scheduled functions (`triggers: { cron: '...' }`).** The SDK has no built-in scheduler. Trigger runs from Vercel Cron or a system cron calling `start()` from an API route.
293
- - **Concurrency, throttling, rate limiting, debounce, singleton, priority, and `batchEvents`.** These function-level settings have no direct analog. Enforce limits inside steps (semaphores, external rate-limiter service) or debounce at the publisher before calling `start()`.
294
- - **`EventSchemas` / typed events.** The event-bus indirection goes away; publishers import the workflow function directly, giving the same type safety through a different mechanism.
295
- - **Event-bus fan-out by name match.** `inngest.send()` that triggered multiple functions by event name must be replaced by explicit `start()` calls for each target workflow.
296
-
297
- ## Quick-start checklist
298
-
299
- - Replace `inngest.createFunction()` with a `"use workflow"` function; launch it with `start()`.
300
- - Convert each `step.run()` callback into a named `"use step"` function.
301
- - Swap `step.sleep()` / `step.sleepUntil()` for `sleep()` from `workflow`.
302
- - Swap `step.waitForEvent()` for `createHook()` (internal) or `createWebhook()` (HTTP).
303
- - Model `waitForEvent` timeouts as `Promise.race()` between the hook and `sleep()`.
304
- - Replace `step.invoke()` with `"use step"` wrappers around `start()` and `getRun()`.
305
- - Replace `step.sendEvent()` fan-out with `start()` called from a `"use step"` function.
306
- - Remove the Inngest client, `serve()` handler, and event definitions.
307
- - Push retry configuration down to step boundaries via `maxRetries`, `RetryableError`, and `FatalError`.
308
- - Use `getStepMetadata().stepId` as the idempotency key for external side effects.
309
- - Replace `step.realtime.publish()` with `getWritable()`.
310
- - Deploy and verify end-to-end with the built-in observability UI.
311
-
312
- ---
313
-
314
- *Verified against `workflow@5.0.0-beta.1` and Inngest TypeScript SDK v4 on 2026-04-16.*