@workflow/core 5.0.0-beta.43 → 5.0.0-beta.44

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 (217) hide show
  1. package/dist/capabilities.d.ts +4 -4
  2. package/dist/capabilities.js +5 -5
  3. package/dist/capture-stack.d.ts +1 -1
  4. package/dist/capture-stack.js +2 -2
  5. package/dist/class-serialization.d.ts +8 -8
  6. package/dist/class-serialization.js +9 -9
  7. package/dist/classify-error.js +5 -5
  8. package/dist/context-violation-error.d.ts +5 -5
  9. package/dist/context-violation-error.d.ts.map +1 -1
  10. package/dist/context-violation-error.js +5 -5
  11. package/dist/create-hook.d.ts +2 -2
  12. package/dist/create-hook.js +1 -1
  13. package/dist/define-hook.js +2 -2
  14. package/dist/describe-error.d.ts +7 -7
  15. package/dist/describe-error.js +8 -8
  16. package/dist/encryption.d.ts +5 -5
  17. package/dist/encryption.js +7 -7
  18. package/dist/events-consumer.d.ts +19 -7
  19. package/dist/events-consumer.d.ts.map +1 -1
  20. package/dist/events-consumer.js +33 -12
  21. package/dist/flushable-stream.d.ts +4 -4
  22. package/dist/flushable-stream.js +12 -12
  23. package/dist/global.d.ts +1 -1
  24. package/dist/global.js +1 -1
  25. package/dist/index.d.ts +1 -1
  26. package/dist/index.js +2 -2
  27. package/dist/log-format.d.ts +2 -2
  28. package/dist/log-format.js +5 -5
  29. package/dist/logger.js +4 -4
  30. package/dist/private.d.ts +21 -65
  31. package/dist/private.d.ts.map +1 -1
  32. package/dist/private.js +160 -38
  33. package/dist/replay-payload-cache.d.ts +1 -1
  34. package/dist/replay-payload-cache.js +4 -4
  35. package/dist/runtime/compute-instance.d.ts +4 -3
  36. package/dist/runtime/compute-instance.d.ts.map +1 -1
  37. package/dist/runtime/compute-instance.js +5 -4
  38. package/dist/runtime/constants.d.ts +24 -24
  39. package/dist/runtime/constants.d.ts.map +1 -1
  40. package/dist/runtime/constants.js +49 -43
  41. package/dist/runtime/count-step-started-events.d.ts +7 -7
  42. package/dist/runtime/count-step-started-events.js +4 -4
  43. package/dist/runtime/deployment-guard.d.ts +7 -7
  44. package/dist/runtime/deployment-guard.js +8 -8
  45. package/dist/runtime/get-port-lazy.d.ts +2 -2
  46. package/dist/runtime/get-port-lazy.d.ts.map +1 -1
  47. package/dist/runtime/get-port-lazy.js +37 -30
  48. package/dist/runtime/get-world-lazy.d.ts +2 -2
  49. package/dist/runtime/get-world-lazy.js +3 -3
  50. package/dist/runtime/helpers.d.ts +18 -18
  51. package/dist/runtime/helpers.js +27 -27
  52. package/dist/runtime/quickjs-entrypoint.d.ts +21 -10
  53. package/dist/runtime/quickjs-entrypoint.d.ts.map +1 -1
  54. package/dist/runtime/quickjs-entrypoint.js +199 -81
  55. package/dist/runtime/quickjs-runtime.d.ts +31 -15
  56. package/dist/runtime/quickjs-runtime.d.ts.map +1 -1
  57. package/dist/runtime/quickjs-runtime.js +126 -77
  58. package/dist/runtime/quickjs-serde.d.ts +10 -10
  59. package/dist/runtime/quickjs-serde.js +20 -20
  60. package/dist/runtime/replay-budget.d.ts +4 -4
  61. package/dist/runtime/replay-budget.js +5 -5
  62. package/dist/runtime/replay-recovery-reporter.d.ts +1 -1
  63. package/dist/runtime/replay-recovery-reporter.js +2 -2
  64. package/dist/runtime/resume-hook.d.ts +2 -2
  65. package/dist/runtime/resume-hook.js +27 -27
  66. package/dist/runtime/resume-latency.d.ts +25 -25
  67. package/dist/runtime/resume-latency.d.ts.map +1 -1
  68. package/dist/runtime/resume-latency.js +4 -4
  69. package/dist/runtime/run-id-time.d.ts +2 -2
  70. package/dist/runtime/run-id-time.js +5 -5
  71. package/dist/runtime/run.d.ts +21 -4
  72. package/dist/runtime/run.d.ts.map +1 -1
  73. package/dist/runtime/run.js +104 -10
  74. package/dist/runtime/runs.d.ts +4 -4
  75. package/dist/runtime/runs.js +2 -2
  76. package/dist/runtime/start.d.ts +3 -3
  77. package/dist/runtime/start.d.ts.map +1 -1
  78. package/dist/runtime/start.js +27 -23
  79. package/dist/runtime/step-executor.d.ts +14 -14
  80. package/dist/runtime/step-executor.d.ts.map +1 -1
  81. package/dist/runtime/step-executor.js +54 -39
  82. package/dist/runtime/step-latency.d.ts +14 -14
  83. package/dist/runtime/step-latency.js +11 -11
  84. package/dist/runtime/step-ownership.d.ts +6 -6
  85. package/dist/runtime/step-ownership.js +8 -8
  86. package/dist/runtime/step-single-flight.d.ts +1 -1
  87. package/dist/runtime/step-single-flight.d.ts.map +1 -1
  88. package/dist/runtime/step-single-flight.js +17 -11
  89. package/dist/runtime/suspension-handler.d.ts +29 -17
  90. package/dist/runtime/suspension-handler.d.ts.map +1 -1
  91. package/dist/runtime/suspension-handler.js +206 -71
  92. package/dist/runtime/unserializable-step.d.ts +34 -0
  93. package/dist/runtime/unserializable-step.d.ts.map +1 -0
  94. package/dist/runtime/unserializable-step.js +52 -0
  95. package/dist/runtime/vm-mode.d.ts +1 -1
  96. package/dist/runtime/vm-mode.js +2 -2
  97. package/dist/runtime/wait-continuation.d.ts +31 -9
  98. package/dist/runtime/wait-continuation.d.ts.map +1 -1
  99. package/dist/runtime/wait-continuation.js +44 -13
  100. package/dist/runtime/wait-until.d.ts +1 -1
  101. package/dist/runtime/wait-until.js +2 -2
  102. package/dist/runtime/world-compatibility.d.ts +20 -9
  103. package/dist/runtime/world-compatibility.d.ts.map +1 -1
  104. package/dist/runtime/world-compatibility.js +24 -13
  105. package/dist/runtime/world-init.d.ts +5 -5
  106. package/dist/runtime/world-init.js +6 -6
  107. package/dist/runtime/world.d.ts.map +1 -1
  108. package/dist/runtime/world.js +13 -3
  109. package/dist/runtime.d.ts.map +1 -1
  110. package/dist/runtime.js +300 -206
  111. package/dist/sealed-box.d.ts +7 -7
  112. package/dist/sealed-box.js +15 -15
  113. package/dist/serialization/client.js +2 -2
  114. package/dist/serialization/codec-devalue-vm.d.ts +1 -1
  115. package/dist/serialization/codec-devalue-vm.js +4 -4
  116. package/dist/serialization/codec-devalue.d.ts +1 -1
  117. package/dist/serialization/codec-devalue.js +2 -2
  118. package/dist/serialization/codec.d.ts +4 -4
  119. package/dist/serialization/codec.js +2 -2
  120. package/dist/serialization/compression.d.ts +12 -11
  121. package/dist/serialization/compression.d.ts.map +1 -1
  122. package/dist/serialization/compression.js +16 -15
  123. package/dist/serialization/encryption.d.ts +7 -7
  124. package/dist/serialization/encryption.d.ts.map +1 -1
  125. package/dist/serialization/encryption.js +8 -8
  126. package/dist/serialization/errors.js +2 -2
  127. package/dist/serialization/format.d.ts +6 -6
  128. package/dist/serialization/format.js +7 -7
  129. package/dist/serialization/hardened.d.ts +18 -18
  130. package/dist/serialization/hardened.d.ts.map +1 -1
  131. package/dist/serialization/hardened.js +41 -32
  132. package/dist/serialization/index.d.ts +1 -1
  133. package/dist/serialization/index.js +2 -2
  134. package/dist/serialization/reducers/class-vm.d.ts +1 -1
  135. package/dist/serialization/reducers/class-vm.js +2 -2
  136. package/dist/serialization/reducers/class.js +2 -2
  137. package/dist/serialization/reducers/common-vm.js +12 -12
  138. package/dist/serialization/reducers/common.js +12 -12
  139. package/dist/serialization/reducers/step-function-vm.d.ts +1 -1
  140. package/dist/serialization/reducers/step-function-vm.js +2 -2
  141. package/dist/serialization/reducers/step-function.js +2 -2
  142. package/dist/serialization/step.js +2 -2
  143. package/dist/serialization/types.d.ts +5 -5
  144. package/dist/serialization/types.js +2 -2
  145. package/dist/serialization/workflow-vm.d.ts +1 -1
  146. package/dist/serialization/workflow-vm.d.ts.map +1 -1
  147. package/dist/serialization/workflow-vm.js +13 -10
  148. package/dist/serialization-format.d.ts +11 -11
  149. package/dist/serialization-format.d.ts.map +1 -1
  150. package/dist/serialization-format.js +29 -23
  151. package/dist/serialization.d.ts +10 -10
  152. package/dist/serialization.js +98 -98
  153. package/dist/set-attributes.js +2 -2
  154. package/dist/source-map.d.ts +1 -1
  155. package/dist/source-map.d.ts.map +1 -1
  156. package/dist/source-map.js +18 -12
  157. package/dist/step/context-storage.d.ts +5 -5
  158. package/dist/step/context-storage.js +1 -1
  159. package/dist/step/writable-stream.d.ts +3 -3
  160. package/dist/step/writable-stream.js +7 -7
  161. package/dist/step.js +12 -12
  162. package/dist/symbols.d.ts +2 -2
  163. package/dist/symbols.js +3 -3
  164. package/dist/telemetry/semantic-conventions.d.ts +21 -13
  165. package/dist/telemetry/semantic-conventions.d.ts.map +1 -1
  166. package/dist/telemetry/semantic-conventions.js +21 -15
  167. package/dist/telemetry.d.ts +3 -3
  168. package/dist/telemetry.d.ts.map +1 -1
  169. package/dist/telemetry.js +19 -10
  170. package/dist/test-support/orchestrator-context.d.ts.map +1 -1
  171. package/dist/test-support/orchestrator-context.js +12 -2
  172. package/dist/version.d.ts +1 -1
  173. package/dist/version.js +2 -2
  174. package/dist/vm/index.js +4 -4
  175. package/dist/vm/script-cache.d.ts.map +1 -1
  176. package/dist/vm/script-cache.js +23 -17
  177. package/dist/vm/uint8array-base64.js +1 -1
  178. package/dist/workflow/abort-controller.d.ts +1 -1
  179. package/dist/workflow/abort-controller.js +12 -12
  180. package/dist/workflow/create-hook.js +2 -2
  181. package/dist/workflow/get-workflow-metadata.js +2 -2
  182. package/dist/workflow/hook.js +16 -16
  183. package/dist/workflow/set-attributes.d.ts +1 -1
  184. package/dist/workflow/set-attributes.js +2 -2
  185. package/dist/workflow/sleep.js +2 -2
  186. package/dist/workflow/world-init-stub.d.ts +1 -1
  187. package/dist/workflow/world-init-stub.js +2 -2
  188. package/dist/workflow.d.ts +2 -2
  189. package/dist/workflow.js +21 -7
  190. package/docs/api-reference/create-hook.mdx +15 -15
  191. package/docs/api-reference/create-webhook.mdx +15 -15
  192. package/docs/api-reference/define-hook.mdx +10 -10
  193. package/docs/api-reference/fatal-error.mdx +2 -2
  194. package/docs/api-reference/fetch.mdx +7 -7
  195. package/docs/api-reference/get-step-metadata.mdx +2 -2
  196. package/docs/api-reference/get-workflow-metadata.mdx +3 -3
  197. package/docs/api-reference/get-writable.mdx +7 -7
  198. package/docs/api-reference/index.mdx +1 -1
  199. package/docs/api-reference/retryable-error.mdx +1 -1
  200. package/docs/api-reference/set-attributes.mdx +2 -2
  201. package/docs/api-reference/sleep.mdx +3 -3
  202. package/docs/foundations/cancellation.mdx +31 -31
  203. package/docs/foundations/errors-and-retries.mdx +42 -11
  204. package/docs/foundations/hooks.mdx +35 -35
  205. package/docs/foundations/idempotency.mdx +9 -9
  206. package/docs/foundations/serialization.mdx +21 -22
  207. package/docs/foundations/starting-workflows.mdx +36 -37
  208. package/docs/foundations/streaming.mdx +46 -41
  209. package/docs/foundations/versioning.mdx +3 -3
  210. package/docs/foundations/workflows-and-steps.mdx +9 -9
  211. package/docs/how-it-works/cancellation.mdx +62 -62
  212. package/docs/how-it-works/code-transform.mdx +66 -54
  213. package/docs/how-it-works/encryption.mdx +25 -21
  214. package/docs/how-it-works/event-sourcing.mdx +53 -35
  215. package/docs/how-it-works/framework-integrations.mdx +12 -12
  216. package/docs/how-it-works/understanding-directives.mdx +21 -21
  217. package/package.json +7 -7
@@ -26,7 +26,7 @@ export async function hookWorkflow() {
26
26
  }
27
27
  ```
28
28
 
29
- ## API Signature
29
+ ## API signature
30
30
 
31
31
  ### Parameters
32
32
 
@@ -66,11 +66,11 @@ export default Hook;`}
66
66
 
67
67
  The returned `Hook` object also implements `AsyncIterable<T>`, which allows you to iterate over incoming payloads using `for await...of` syntax.
68
68
 
69
- Use `hook.getConflict()` to check whether the hook token is already claimed by another hook, including one kept reserved after its run ends, without waiting for hook payload data. Calling `createHook()` on its own does not register the hook registration is only committed when the workflow suspends. Awaiting `hook.getConflict()` suspends the workflow to commit the registration, then resolves with `null` once `hook_created` is recorded, or with the conflicting [`Run`](/docs/api-reference/workflow-api/get-run).
69
+ Use `hook.getConflict()` to check whether the hook token is already claimed by another hook, including one kept reserved after its run ends, without waiting for hook payload data. Calling `createHook()` on its own does not register the hook: registration is only committed when the workflow suspends. Awaiting `hook.getConflict()` suspends the workflow to commit the registration, then resolves with `null` once `hook_created` is recorded, or with the conflicting [`Run`](/docs/api-reference/workflow-api/get-run).
70
70
 
71
71
  ## Examples
72
72
 
73
- ### Basic Usage
73
+ ### Basic usage
74
74
 
75
75
  When creating a hook, you can specify a payload type for automatic type safety:
76
76
 
@@ -91,7 +91,7 @@ export async function approvalWorkflow() {
91
91
  }
92
92
  ```
93
93
 
94
- ### Customizing Tokens
94
+ ### Customizing tokens
95
95
 
96
96
  Tokens are used to identify a specific hook. You can customize the token to be more specific to a use case.
97
97
 
@@ -115,7 +115,7 @@ export async function slackBotWorkflow(channelId: string) {
115
115
  }
116
116
  ```
117
117
 
118
- ### Detecting Token Conflicts
118
+ ### Detecting token conflicts
119
119
 
120
120
  Use `hook.getConflict()` when the workflow needs to claim a hook token before doing other work, but does not need a payload yet:
121
121
 
@@ -141,7 +141,7 @@ async function processOrder(orderId: string) {
141
141
  }
142
142
  ```
143
143
 
144
- Because `createHook()` alone does not suspend the workflow, awaiting `hook.getConflict()` is what actually suspends the run and commits the hook registration. It only waits for registration to receive payload data from a future `resumeHook()` call, await the hook itself or iterate it with `for await...of`.
144
+ Because `createHook()` alone does not suspend the workflow, awaiting `hook.getConflict()` is what actually suspends the run and commits the hook registration. It only waits for registration. To receive payload data from a future `resumeHook()` call, await the hook itself or iterate it with `for await...of`.
145
145
 
146
146
  On a conflict, the resolved value is a `Run` handle for the run that owns the token, with durable step-backed accessors. The duplicate run can decide in code how to handle it: return or log `conflict.runId`, inspect `await conflict.status`, wait on `await conflict.returnValue`, or cancel the owner with `await conflict.cancel()` and continue in the current run. See [Run idempotency](/docs/foundations/idempotency#run-idempotency) for these strategies in context.
147
147
 
@@ -149,7 +149,7 @@ On a conflict, the resolved value is a `Run` handle for the run that owns the to
149
149
  Custom hook tokens are the recommended way to coordinate active workflow runs. Use a deterministic token from your domain, such as an order ID or conversation ID, create the hook near the beginning of the workflow, and check `await hook.getConflict()` before work that depends on owning the token. See [Run idempotency](/docs/foundations/idempotency#run-idempotency).
150
150
  </Callout>
151
151
 
152
- ### Keep a Token Unavailable After the Run Ends
152
+ ### Keep a token unavailable after the run ends
153
153
 
154
154
  By default, another Hook can use the token after its workflow ends. Set `experimental_minRetention` to keep the token unavailable for at least a specific time after `createHook()` runs:
155
155
 
@@ -190,7 +190,7 @@ After the workflow ends, [`getHookByToken()`](/docs/api-reference/workflow-api/g
190
190
  This option is experimental. Worlds can limit how long tokens are retained; see [World configuration](/docs/configuration/worlds) for each World's limit. If the configured World does not support minimum retention, the workflow fails when registering the Hook. `createWebhook()` does not accept this option.
191
191
  </Callout>
192
192
 
193
- ### Waiting for Multiple Payloads
193
+ ### Waiting for multiple payloads
194
194
 
195
195
  You can also wait for multiple payloads by using the `for await...of` syntax.
196
196
 
@@ -213,7 +213,7 @@ export async function collectHookWorkflow() {
213
213
  }
214
214
  ```
215
215
 
216
- ### Disposing Hooks Early
216
+ ### Disposing hooks early
217
217
 
218
218
  You can dispose a hook early to release its token for reuse by another workflow. This is useful for handoff patterns where one workflow needs to transfer a hook token to another workflow while still running.
219
219
 
@@ -242,7 +242,7 @@ export async function handoffWorkflow(channelId: string) {
242
242
 
243
243
  After calling `dispose()`, the hook will no longer receive events and its token becomes available for other workflows to use.
244
244
 
245
- ### Automatic Disposal with `using`
245
+ ### Automatic disposal with `using`
246
246
 
247
247
  Hooks implement the [TC39 Explicit Resource Management](https://github.com/tc39/proposal-explicit-resource-management) proposal, allowing automatic disposal with the `using` keyword:
248
248
 
@@ -268,9 +268,9 @@ export async function scopedHookWorkflow(channelId: string) {
268
268
 
269
269
  This is equivalent to manually calling `dispose()` but ensures the hook is always cleaned up, even if an error occurs.
270
270
 
271
- ## Related Functions
271
+ ## Related functions
272
272
 
273
- - [`defineHook()`](/docs/api-reference/workflow/define-hook) - Type-safe hook helper
274
- - [`resumeHook()`](/docs/api-reference/workflow-api/resume-hook) - Resume a hook with a payload
275
- - [`createWebhook()`](/docs/api-reference/workflow/create-webhook) - Higher-level HTTP webhook abstraction
276
- - [Idempotency](/docs/foundations/idempotency) - Deduplicate step side effects and workflow starts
273
+ - [`defineHook()`](/docs/api-reference/workflow/define-hook): Type-safe hook helper
274
+ - [`resumeHook()`](/docs/api-reference/workflow-api/resume-hook): Resume a hook with a payload
275
+ - [`createWebhook()`](/docs/api-reference/workflow/create-webhook): Higher-level HTTP webhook abstraction
276
+ - [Idempotency](/docs/foundations/idempotency): Deduplicate step side effects and workflow starts
@@ -14,7 +14,7 @@ Creates a webhook that can be used to suspend and resume a workflow run upon rec
14
14
  Webhooks provide a way for external systems to send HTTP requests directly to your workflow. Unlike hooks which accept arbitrary payloads, webhooks work with standard HTTP `Request` objects and can return HTTP `Response` objects.
15
15
 
16
16
  <Callout type="warn">
17
- `createWebhook()` creates a public endpoint at `/.well-known/workflow/v1/webhook/:token`, and the token in that URL is the only authorization performed for incoming requests resuming that webhook. This is convenient for prototypes and simple resume links because it avoids creating another route, but if you need stronger security, prefer [`createHook()`](/docs/api-reference/workflow/create-hook) behind your own route and authorize the request before calling [`resumeHook()`](/docs/api-reference/workflow-api/resume-hook) to avoid unauthenticated workflow resumptions.
17
+ `createWebhook()` creates a public endpoint at `/.well-known/workflow/v1/webhook/:token`, and the token in that URL is the only authorization performed for incoming requests resuming that webhook. This is convenient for prototypes and basic resume links because it avoids creating another route, but if you need stronger security, prefer [`createHook()`](/docs/api-reference/workflow/create-hook) behind your own route and authorize the request before calling [`resumeHook()`](/docs/api-reference/workflow-api/resume-hook) to avoid unauthenticated workflow resumptions.
18
18
  </Callout>
19
19
 
20
20
  ```ts lineNumbers
@@ -31,7 +31,7 @@ export async function webhookWorkflow() {
31
31
  }
32
32
  ```
33
33
 
34
- ## API Signature
34
+ ## API signature
35
35
 
36
36
  ### Parameters
37
37
 
@@ -63,22 +63,22 @@ When using `createWebhook({ respondWith: 'manual' })`, the resolved request type
63
63
  <Callout type="info">
64
64
  Use the simplest option that satisfies the prompt:
65
65
 
66
- - `createWebhook()` generated callback URL, and the default `202 Accepted` response is fine
67
- - `createWebhook({ respondWith: 'manual' })` generated callback URL, but you must send a custom body, status, or headers
68
- - `createHook()` + `resumeHook()` the app resumes from server-side code with a deterministic business token instead of a generated callback URL
66
+ - `createWebhook()`: generated callback URL, and the default `202 Accepted` response is fine
67
+ - `createWebhook({ respondWith: 'manual' })`: generated callback URL, but you must send a custom body, status, or headers
68
+ - `createHook()` + `resumeHook()`: the app resumes from server-side code with a deterministic business token instead of a generated callback URL
69
69
  </Callout>
70
70
 
71
71
  <details>
72
72
  <summary>Common wrong turns</summary>
73
73
 
74
- - Do not use `respondWith: 'manual'` just because the flow has a callback URL.
74
+ - A callback URL alone does not require `respondWith: 'manual'`.
75
75
  - Do not use `RequestWithResponse` unless you chose manual mode.
76
76
  - Do not invent a custom callback route when `webhook.url` is the intended callback surface.
77
77
  </details>
78
78
 
79
79
  ## Examples
80
80
 
81
- ### Basic Usage
81
+ ### Basic usage
82
82
 
83
83
  Create a webhook that receives HTTP requests and logs the request details:
84
84
 
@@ -101,11 +101,11 @@ export async function basicWebhookWorkflow() {
101
101
  }
102
102
  ```
103
103
 
104
- ### Responding to Webhook Requests (Manual Mode)
104
+ ### Responding to webhook requests (manual mode)
105
105
 
106
106
  Use this section only when the caller requires a non-default HTTP response. If `202 Accepted` is acceptable, use `createWebhook()` without `respondWith: "manual"`.
107
107
 
108
- Pass `{ respondWith: "manual" }` to get a `RequestWithResponse` object with a `respondWith()` method. Note that `respondWith()` must be called from within a step function:
108
+ Pass `{ respondWith: "manual" }` to get a `RequestWithResponse` object with a `respondWith()` method. Call `respondWith()` from within a step function:
109
109
 
110
110
  ```typescript lineNumbers
111
111
  import { createWebhook, type RequestWithResponse } from "workflow"
@@ -143,7 +143,7 @@ async function processData(data: any): Promise<void> {
143
143
  }
144
144
  ```
145
145
 
146
- ### Waiting for Multiple Requests
146
+ ### Waiting for multiple requests
147
147
 
148
148
  You can also wait for multiple requests by using the `for await...of` syntax.
149
149
 
@@ -182,9 +182,9 @@ export async function eventCollectorWorkflow() {
182
182
  }
183
183
  ```
184
184
 
185
- ## Related Functions
185
+ ## Related functions
186
186
 
187
- - [`createHook()`](/docs/api-reference/workflow/create-hook) Use when the app resumes from server-side code with a deterministic business token.
188
- - [`resumeHook()`](/docs/api-reference/workflow-api/resume-hook) Pairs with `createHook()` for deterministic server-side resume.
189
- - [`defineHook()`](/docs/api-reference/workflow/define-hook) Type-safe hook helper.
190
- - [`resumeWebhook()`](/docs/api-reference/workflow-api/resume-webhook) Low-level runtime API. Most integrations should call `webhook.url` directly instead of adding a custom callback route.
187
+ - [`createHook()`](/docs/api-reference/workflow/create-hook): Use when the app resumes from server-side code with a deterministic business token.
188
+ - [`resumeHook()`](/docs/api-reference/workflow-api/resume-hook): Pairs with `createHook()` for deterministic server-side resume.
189
+ - [`defineHook()`](/docs/api-reference/workflow/define-hook): Type-safe hook helper.
190
+ - [`resumeWebhook()`](/docs/api-reference/workflow-api/resume-webhook): Low-level runtime API. Most integrations should call `webhook.url` directly instead of adding a custom callback route.
@@ -33,7 +33,7 @@ export async function nameWorkflow() {
33
33
  }
34
34
  ```
35
35
 
36
- ## API Signature
36
+ ## API signature
37
37
 
38
38
  ### Parameters
39
39
 
@@ -59,11 +59,11 @@ interface TypedHook<TInput, TOutput> {
59
59
  export default TypedHook;`}
60
60
  />
61
61
 
62
- `create()` is called inside a `"use workflow"` function to create the hook; `resume()` is called from runtime code (an API route or server action). When a `schema` is provided, `resume()` accepts the raw input type (`TInput`) and the workflow receives the validated and possibly transformed output type (`TOutput`); without a schema, `TOutput` defaults to `TInput`. `resume()` throws [`HookNotFoundError`](/docs/api-reference/workflow-errors/hook-not-found-error) if the token does not match an active hook it does not return `null`.
62
+ `create()` is called inside a `"use workflow"` function to create the hook; `resume()` is called from runtime code (an API route or server action). When a `schema` is provided, `resume()` accepts the raw input type (`TInput`) and the workflow receives the validated and possibly transformed output type (`TOutput`); without a schema, `TOutput` defaults to `TInput`. `resume()` throws [`HookNotFoundError`](/docs/api-reference/workflow-errors/hook-not-found-error) if the token does not match an active hook. It does not return `null`.
63
63
 
64
64
  ## Examples
65
65
 
66
- ### Basic Type-Safe Hook Definition
66
+ ### Basic type-safe hook definition
67
67
 
68
68
  By defining the hook once with a specific payload type, you can reuse it in multiple workflows and API routes with automatic type safety.
69
69
 
@@ -88,7 +88,7 @@ export async function workflowWithApproval() {
88
88
  }
89
89
  ```
90
90
 
91
- ### Resuming with Type Safety
91
+ ### Resuming with type safety
92
92
 
93
93
  Hooks can be resumed using the same defined hook and a token. By using the same hook, you can ensure that the payload matches the defined type when resuming a hook. `resume()` resolves to the resumed hook and throws [`HookNotFoundError`](/docs/api-reference/workflow-errors/hook-not-found-error) if the token does not match an active hook.
94
94
 
@@ -116,7 +116,7 @@ export async function POST(request: Request) {
116
116
  }
117
117
  ```
118
118
 
119
- ### Validate and Transform with Schema
119
+ ### Validate and transform with schema
120
120
 
121
121
  You can provide runtime validation and transformation of hook payloads using the `schema` option. This option accepts any validator that conforms to the [Standard Schema v1](https://standardschema.dev) specification.
122
122
 
@@ -174,7 +174,7 @@ export async function POST(request: Request) {
174
174
  }
175
175
  ```
176
176
 
177
- #### Using Other Standard Schema Libraries
177
+ #### Using other Standard Schema libraries
178
178
 
179
179
  The same pattern works with any Standard Schema v1 compliant library. Here's an example with [Valibot](https://valibot.dev):
180
180
 
@@ -190,7 +190,7 @@ export const approvalHook = defineHook({
190
190
  });
191
191
  ```
192
192
 
193
- ### Customizing Tokens
193
+ ### Customizing tokens
194
194
 
195
195
  Tokens are used to identify a specific hook and for resuming a hook. You can customize the token to be more specific to a use case.
196
196
 
@@ -211,7 +211,7 @@ export async function slackBotWorkflow(channelId: string) {
211
211
  }
212
212
  ```
213
213
 
214
- ## Related Functions
214
+ ## Related functions
215
215
 
216
- * [`createHook()`](/docs/api-reference/workflow/create-hook) - Create a hook in a workflow.
217
- * [`resumeHook()`](/docs/api-reference/workflow-api/resume-hook) - Resume a hook with a payload.
216
+ - [`createHook()`](/docs/api-reference/workflow/create-hook): Create a hook in a workflow.
217
+ - [`resumeHook()`](/docs/api-reference/workflow-api/resume-hook): Resume a hook with a payload.
@@ -27,7 +27,7 @@ async function fallibleStep() {
27
27
  }
28
28
  ```
29
29
 
30
- ## API Signature
30
+ ## API signature
31
31
 
32
32
  ### Constructor
33
33
 
@@ -50,7 +50,7 @@ interface FatalError {
50
50
  export default FatalError;`}
51
51
  />
52
52
 
53
- ### Static Methods
53
+ ### Static methods
54
54
 
55
55
  #### `FatalError.is(value)`
56
56
 
@@ -34,7 +34,7 @@ async function apiWorkflow() {
34
34
  }
35
35
  ```
36
36
 
37
- ## API Signature
37
+ ## API signature
38
38
 
39
39
  ### Parameters
40
40
 
@@ -60,9 +60,9 @@ showSections={['returns']}
60
60
 
61
61
  ## Examples
62
62
 
63
- ### Basic Usage
63
+ ### Basic usage
64
64
 
65
- Here's a simple example of how you can use `fetch` inside your workflow.
65
+ Here's an example of how you can use `fetch` inside your workflow.
66
66
 
67
67
  ```typescript lineNumbers
68
68
  import { fetch } from "workflow"
@@ -87,13 +87,13 @@ async function apiWorkflow() {
87
87
  }
88
88
  ```
89
89
 
90
- We call `fetch()` with a URL and optional request options, just like the standard fetch API. The workflow runtime automatically handles the response serialization.
90
+ We call `fetch()` with a URL and optional request options, like the standard fetch API. The workflow runtime automatically handles the response serialization.
91
91
 
92
- This API is provided as a convenience to easily use `fetch` in workflow, but often, you might want to extend and implement your own fetch for more powerful error handing and retry logic.
92
+ This API lets you use `fetch` in a workflow. You can also implement a custom fetch for different error handling and retry logic.
93
93
 
94
- ### Customizing Fetch Behavior
94
+ ### Customizing fetch behavior
95
95
 
96
- Here's an example of a custom fetch wrapper that provides more sophisticated error handling with custom retry logic. Call `globalThis.fetch` inside your own `"use step"` function calling the workflow `fetch` imported from `workflow` would nest a step inside a step:
96
+ The following custom fetch wrapper provides more advanced error handling with custom retry logic. Call `globalThis.fetch` inside your own `"use step"` function because calling the workflow `fetch` imported from `workflow` would nest a step inside a step:
97
97
 
98
98
  ```typescript lineNumbers
99
99
  import { FatalError, RetryableError } from "workflow"
@@ -34,7 +34,7 @@ async function logStepId() {
34
34
  }
35
35
  ```
36
36
 
37
- ### Example: Use `stepId` as an idempotency key
37
+ ### Example: use `stepId` as an idempotency key
38
38
 
39
39
  ```typescript lineNumbers
40
40
  import { getStepMetadata } from "workflow";
@@ -61,7 +61,7 @@ async function chargeUser(userId: string, amount: number) {
61
61
  <a href="/docs/foundations/idempotency">Idempotency</a> guide.
62
62
  </Callout>
63
63
 
64
- ## API Signature
64
+ ## API signature
65
65
 
66
66
  ### Parameters
67
67
 
@@ -30,7 +30,7 @@ async function testWorkflow() {
30
30
  }
31
31
  ```
32
32
 
33
- ### Detecting Workflow Runtime
33
+ ### Detecting workflow runtime
34
34
 
35
35
  You can use `getWorkflowMetadata` to detect whether your code is running inside a workflow context. This is useful when building shared utilities that need to behave differently inside and outside of workflows.
36
36
 
@@ -64,7 +64,7 @@ function log(message: string) {
64
64
  }
65
65
  ```
66
66
 
67
- ### Detecting Encryption
67
+ ### Detecting encryption
68
68
 
69
69
  The `features` object indicates which capabilities are active for the current run. Library authors can use `features.encryption` to control whether sensitive data is included in step return values, which are serialized to the event log:
70
70
 
@@ -90,7 +90,7 @@ async function fetchUserProfile(userId: string) {
90
90
  }
91
91
  ```
92
92
 
93
- ## API Signature
93
+ ## API signature
94
94
 
95
95
  ### Parameters
96
96
 
@@ -47,7 +47,7 @@ async function writeToStream(writable: WritableStream) {
47
47
  }
48
48
  ```
49
49
 
50
- ## API Signature
50
+ ## API signature
51
51
 
52
52
  ### Parameters
53
53
 
@@ -69,7 +69,7 @@ export default getWritable;`}
69
69
 
70
70
  Returns a `WritableStream<W>` where `W` is the type of data you plan to write to the stream.
71
71
 
72
- ## Good to Know
72
+ ## Good to know
73
73
 
74
74
  - **Workflow functions can only obtain the stream** - Call `getWritable()` in a workflow to get the stream reference, but you cannot call methods like `getWriter()`, `write()`, or `close()` directly in the workflow context.
75
75
  - **Step functions can interact with streams** - Steps can receive the stream as an argument or call `getWritable()` directly, and they can freely interact with it (write, close, etc.).
@@ -81,9 +81,9 @@ Returns a `WritableStream<W>` where `W` is the type of data you plan to write to
81
81
 
82
82
  ## Examples
83
83
 
84
- ### Basic Text Streaming
84
+ ### Basic text streaming
85
85
 
86
- Here's a simple example streaming text data:
86
+ This example streams text data:
87
87
 
88
88
  ```typescript lineNumbers
89
89
  import { sleep, getWritable } from "workflow";
@@ -118,7 +118,7 @@ async function stepCloseOutputStream(writable: WritableStream) {
118
118
  }
119
119
  ```
120
120
 
121
- ### Calling `getWritable()` Inside Steps
121
+ ### Calling `getWritable()` inside steps
122
122
 
123
123
  You can also call `getWritable()` directly inside step functions without passing it as a parameter:
124
124
 
@@ -157,7 +157,7 @@ async function stepCloseOutputStreamInside() {
157
157
  }
158
158
  ```
159
159
 
160
- ### Using Namespaced Streams in Steps
160
+ ### Using namespaced streams in steps
161
161
 
162
162
  You can also use namespaced streams when calling `getWritable()` from steps:
163
163
 
@@ -201,7 +201,7 @@ async function closeStreams() {
201
201
  }
202
202
  ```
203
203
 
204
- ### Advanced Chat Streaming
204
+ ### Advanced chat streaming
205
205
 
206
206
  Here's a more complex example showing how you might stream AI chat responses:
207
207
 
@@ -52,7 +52,7 @@ Workflow SDK contains the following functions you can use inside your workflow f
52
52
  </Card>
53
53
  </Cards>
54
54
 
55
- ## Error Classes
55
+ ## Error classes
56
56
 
57
57
  Workflow SDK includes error classes that can be thrown in a workflow or step to change the error exit strategy of a workflow.
58
58
 
@@ -31,7 +31,7 @@ async function retryStep() {
31
31
  The difference between `Error` and `RetryableError` may not be entirely obvious, since when both are thrown, they both retry. The difference is that `RetryableError` has an additional configurable `retryAfter` parameter.
32
32
  </Callout>
33
33
 
34
- ## API Signature
34
+ ## API signature
35
35
 
36
36
  ### Parameters
37
37
 
@@ -25,7 +25,7 @@ export async function orderWorkflow(orderId: string) {
25
25
  }
26
26
  ```
27
27
 
28
- ## API Signature
28
+ ## API signature
29
29
 
30
30
  ### Parameters
31
31
 
@@ -58,4 +58,4 @@ Validation errors throw [`FatalError`](/docs/api-reference/workflow/fatal-error)
58
58
 
59
59
  Calls from both workflow and step bodies append a native `attr_set` event, which the World materializes onto `run.attributes`. Workflow-originated events record a workflow writer; step-originated events record the originating step ID and attempt.
60
60
 
61
- Native attributes require spec version 4 or later. Step-body storage errors throw from `setAttributes`; catch them inside the step if the write should be best-effort. Workflow-body writes are committed when the workflow suspends: transient storage errors are retried with the suspension, while a write the World rejects as invalid such as exceeding the per-run attribute cap across multiple calls fails the run with the validation error.
61
+ Native attributes require spec version 4 or later. Step-body storage errors throw from `setAttributes`; catch them inside the step if the write should be best-effort. Workflow-body writes are committed when the workflow suspends: transient storage errors are retried with the suspension, while a write the World rejects as invalid (such as exceeding the per-run attribute cap across multiple calls) fails the run with the validation error.
@@ -26,7 +26,7 @@ async function testWorkflow() {
26
26
  }
27
27
  ```
28
28
 
29
- ## API Signature
29
+ ## API signature
30
30
 
31
31
  ### Parameters
32
32
 
@@ -39,7 +39,7 @@ showSections={['parameters']}
39
39
 
40
40
  ## Examples
41
41
 
42
- ### Sleeping With a Duration
42
+ ### Sleeping with a duration
43
43
 
44
44
  You can specify a duration for `sleep` to suspend the workflow for a fixed amount of time.
45
45
 
@@ -52,7 +52,7 @@ async function testWorkflow() {
52
52
  }
53
53
  ```
54
54
 
55
- ### Sleeping Until an End Date
55
+ ### Sleeping until an end date
56
56
 
57
57
  You can specify a future `Date` object for `sleep` to suspend the workflow until a specific date.
58
58