workflow 4.4.0 → 4.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 (110) hide show
  1. package/docs/api-reference/index.mdx +24 -0
  2. package/docs/api-reference/meta.json +8 -0
  3. package/docs/api-reference/vitest/index.mdx +0 -6
  4. package/docs/api-reference/workflow/create-hook.mdx +32 -0
  5. package/docs/api-reference/workflow/create-webhook.mdx +1 -0
  6. package/docs/api-reference/workflow-api/index.mdx +6 -8
  7. package/docs/api-reference/workflow-errors/meta.json +5 -0
  8. package/docs/api-reference/workflow-serde/index.mdx +0 -1
  9. package/docs/api-reference/workflow-serde/workflow-deserialize.mdx +1 -2
  10. package/docs/api-reference/workflow-serde/workflow-serialize.mdx +1 -2
  11. package/docs/deploying/world/vercel-world.mdx +2 -0
  12. package/docs/errors/index.mdx +3 -0
  13. package/docs/foundations/hooks.mdx +29 -0
  14. package/docs/foundations/streaming.mdx +7 -1
  15. package/docs/foundations/versioning.mdx +1 -1
  16. package/docs/how-it-works/encryption.mdx +2 -2
  17. package/docs/how-it-works/event-sourcing.mdx +2 -2
  18. package/docs/v4/api-reference/workflow-astro/index.mdx +18 -0
  19. package/docs/v4/api-reference/workflow-astro/meta.json +4 -0
  20. package/docs/v4/api-reference/workflow-astro/workflow.mdx +37 -0
  21. package/docs/v4/api-reference/workflow-errors/hook-conflict-error.mdx +60 -0
  22. package/docs/v4/api-reference/workflow-errors/run-not-supported-error.mdx +58 -0
  23. package/docs/v4/api-reference/workflow-errors/workflow-error.mdx +52 -0
  24. package/docs/v4/api-reference/workflow-errors/workflow-run-not-completed-error.mdx +58 -0
  25. package/docs/v4/api-reference/workflow-errors/workflow-runtime-error.mdx +58 -0
  26. package/docs/v4/api-reference/workflow-nest/configure-workflow-controller.mdx +33 -0
  27. package/docs/v4/api-reference/workflow-nest/index.mdx +31 -0
  28. package/docs/v4/api-reference/workflow-nest/meta.json +9 -0
  29. package/docs/v4/api-reference/workflow-nest/nest-local-builder.mdx +63 -0
  30. package/docs/v4/api-reference/workflow-nest/workflow-controller.mdx +40 -0
  31. package/docs/v4/api-reference/workflow-nest/workflow-module.mdx +73 -0
  32. package/docs/v4/api-reference/workflow-nitro/index.mdx +57 -0
  33. package/docs/v4/api-reference/workflow-nuxt/index.mdx +47 -0
  34. package/docs/v4/api-reference/workflow-observability/hydrate-data.mdx +35 -0
  35. package/docs/v4/api-reference/workflow-observability/hydrate-resource-io.mdx +62 -0
  36. package/docs/v4/api-reference/workflow-observability/index.mdx +64 -0
  37. package/docs/v4/api-reference/workflow-observability/meta.json +11 -0
  38. package/docs/v4/api-reference/workflow-observability/observability-revivers.mdx +50 -0
  39. package/docs/v4/api-reference/workflow-observability/parse-class-name.mdx +41 -0
  40. package/docs/v4/api-reference/workflow-observability/parse-step-name.mdx +40 -0
  41. package/docs/v4/api-reference/workflow-observability/parse-workflow-name.mdx +55 -0
  42. package/docs/v4/api-reference/workflow-runtime/create-world.mdx +43 -0
  43. package/docs/v4/api-reference/workflow-runtime/get-world-handlers.mdx +44 -0
  44. package/docs/v4/api-reference/workflow-runtime/get-world.mdx +124 -0
  45. package/docs/v4/api-reference/workflow-runtime/health-check.mdx +50 -0
  46. package/docs/v4/api-reference/workflow-runtime/index.mdx +46 -0
  47. package/docs/v4/api-reference/workflow-runtime/meta.json +13 -0
  48. package/docs/v4/api-reference/workflow-runtime/set-world.mdx +49 -0
  49. package/docs/v4/api-reference/workflow-runtime/step-entrypoint.mdx +39 -0
  50. package/docs/v4/api-reference/workflow-runtime/workflow-entrypoint.mdx +42 -0
  51. package/docs/{api-reference/workflow-api → v4/api-reference/workflow-runtime}/world/index.mdx +5 -8
  52. package/docs/v4/api-reference/workflow-runtime/world/meta.json +4 -0
  53. package/docs/v4/api-reference/workflow-runtime/world/queue.mdx +86 -0
  54. package/docs/{api-reference/workflow-api → v4/api-reference/workflow-runtime}/world/storage.mdx +4 -4
  55. package/docs/v4/api-reference/workflow-runtime/world/streams.mdx +216 -0
  56. package/docs/v4/api-reference/workflow-sveltekit/index.mdx +18 -0
  57. package/docs/v4/api-reference/workflow-sveltekit/meta.json +4 -0
  58. package/docs/v4/api-reference/workflow-sveltekit/workflow-plugin.mdx +34 -0
  59. package/docs/v4/api-reference/workflow-vite/index.mdx +18 -0
  60. package/docs/v4/api-reference/workflow-vite/meta.json +4 -0
  61. package/docs/v4/api-reference/workflow-vite/workflow.mdx +47 -0
  62. package/docs/v4/errors/step-executed-multiple-times.mdx +23 -0
  63. package/docs/v5/api-reference/workflow-astro/index.mdx +18 -0
  64. package/docs/v5/api-reference/workflow-astro/meta.json +4 -0
  65. package/docs/v5/api-reference/workflow-astro/workflow.mdx +45 -0
  66. package/docs/v5/api-reference/workflow-errors/hook-conflict-error.mdx +60 -0
  67. package/docs/v5/api-reference/workflow-errors/run-not-supported-error.mdx +58 -0
  68. package/docs/v5/api-reference/workflow-errors/workflow-error.mdx +52 -0
  69. package/docs/v5/api-reference/workflow-errors/workflow-run-not-completed-error.mdx +58 -0
  70. package/docs/v5/api-reference/workflow-errors/workflow-runtime-error.mdx +58 -0
  71. package/docs/v5/api-reference/workflow-nest/configure-workflow-controller.mdx +33 -0
  72. package/docs/v5/api-reference/workflow-nest/index.mdx +31 -0
  73. package/docs/v5/api-reference/workflow-nest/meta.json +9 -0
  74. package/docs/v5/api-reference/workflow-nest/nest-local-builder.mdx +64 -0
  75. package/docs/v5/api-reference/workflow-nest/workflow-controller.mdx +40 -0
  76. package/docs/v5/api-reference/workflow-nest/workflow-module.mdx +74 -0
  77. package/docs/v5/api-reference/workflow-nitro/index.mdx +59 -0
  78. package/docs/v5/api-reference/workflow-nuxt/index.mdx +47 -0
  79. package/docs/v5/api-reference/workflow-observability/hydrate-data.mdx +35 -0
  80. package/docs/v5/api-reference/workflow-observability/hydrate-resource-io.mdx +62 -0
  81. package/docs/v5/api-reference/workflow-observability/index.mdx +64 -0
  82. package/docs/v5/api-reference/workflow-observability/meta.json +11 -0
  83. package/docs/v5/api-reference/workflow-observability/observability-revivers.mdx +50 -0
  84. package/docs/v5/api-reference/workflow-observability/parse-class-name.mdx +41 -0
  85. package/docs/v5/api-reference/workflow-observability/parse-step-name.mdx +40 -0
  86. package/docs/v5/api-reference/workflow-observability/parse-workflow-name.mdx +55 -0
  87. package/docs/v5/api-reference/workflow-runtime/create-world.mdx +39 -0
  88. package/docs/v5/api-reference/workflow-runtime/get-world-handlers.mdx +44 -0
  89. package/docs/{api-reference/workflow-api → v5/api-reference/workflow-runtime}/get-world.mdx +7 -10
  90. package/docs/v5/api-reference/workflow-runtime/health-check.mdx +50 -0
  91. package/docs/v5/api-reference/workflow-runtime/index.mdx +43 -0
  92. package/docs/v5/api-reference/workflow-runtime/meta.json +12 -0
  93. package/docs/v5/api-reference/workflow-runtime/set-world.mdx +49 -0
  94. package/docs/v5/api-reference/workflow-runtime/workflow-entrypoint.mdx +42 -0
  95. package/docs/v5/api-reference/workflow-runtime/world/index.mdx +55 -0
  96. package/docs/v5/api-reference/workflow-runtime/world/meta.json +4 -0
  97. package/docs/{api-reference/workflow-api → v5/api-reference/workflow-runtime}/world/queue.mdx +2 -2
  98. package/docs/v5/api-reference/workflow-runtime/world/storage.mdx +409 -0
  99. package/docs/{api-reference/workflow-api → v5/api-reference/workflow-runtime}/world/streams.mdx +2 -2
  100. package/docs/v5/api-reference/workflow-sveltekit/index.mdx +18 -0
  101. package/docs/v5/api-reference/workflow-sveltekit/meta.json +4 -0
  102. package/docs/v5/api-reference/workflow-sveltekit/workflow-plugin.mdx +42 -0
  103. package/docs/v5/api-reference/workflow-vite/index.mdx +18 -0
  104. package/docs/v5/api-reference/workflow-vite/meta.json +4 -0
  105. package/docs/v5/api-reference/workflow-vite/workflow.mdx +48 -0
  106. package/docs/v5/errors/index.mdx +3 -0
  107. package/docs/v5/errors/step-executed-multiple-times.mdx +23 -0
  108. package/package.json +10 -10
  109. package/docs/api-reference/workflow-api/world/meta.json +0 -4
  110. package/docs/api-reference/workflow-api/world/observability.mdx +0 -164
@@ -4,7 +4,7 @@ description: Low-level API for inspecting and managing workflow runs, steps, eve
4
4
  type: overview
5
5
  summary: Access workflow infrastructure directly via getWorld() for building observability dashboards, admin tools, and custom integrations.
6
6
  prerequisites:
7
- - /docs/api-reference/workflow-api/get-world
7
+ - /docs/api-reference/workflow-runtime/get-world
8
8
  keywords:
9
9
  - getWorld
10
10
  - World SDK
@@ -25,18 +25,15 @@ const world = getWorld(); // [!code highlight]
25
25
  ## Interfaces
26
26
 
27
27
  <Cards>
28
- <Card href="/docs/api-reference/workflow-api/world/storage" title="Storage">
28
+ <Card href="/docs/api-reference/workflow-runtime/world/storage" title="Storage">
29
29
  Query runs, steps, hooks, and the underlying event log.
30
30
  </Card>
31
- <Card href="/docs/api-reference/workflow-api/world/streams" title="Streams">
31
+ <Card href="/docs/api-reference/workflow-runtime/world/streams" title="Streams">
32
32
  Read, write, and manage real-time data streams for workflow runs.
33
33
  </Card>
34
- <Card href="/docs/api-reference/workflow-api/world/queue" title="Queue">
34
+ <Card href="/docs/api-reference/workflow-runtime/world/queue" title="Queue">
35
35
  Low-level queue dispatch (internal SDK infrastructure).
36
36
  </Card>
37
- <Card href="/docs/api-reference/workflow-api/world/observability" title="Observability Utilities">
38
- Hydrate step I/O, parse display names, and decrypt workflow data.
39
- </Card>
40
37
  </Cards>
41
38
 
42
39
  <Callout type="info">
@@ -55,4 +52,4 @@ const hydrated = hydrateResourceIO(step, observabilityRevivers); // [!code highl
55
52
  console.log(hydrated.input, hydrated.output);
56
53
  ```
57
54
 
58
- See [Observability Utilities](/docs/api-reference/workflow-api/world/observability) for the full API.
55
+ See [`workflow/observability`](/docs/api-reference/workflow-observability) for the full API.
@@ -0,0 +1,4 @@
1
+ {
2
+ "title": "World SDK",
3
+ "pages": ["storage", "streams", "queue"]
4
+ }
@@ -0,0 +1,86 @@
1
+ ---
2
+ title: Queue
3
+ description: Low-level queue interface for dispatching workflow and step invocations.
4
+ type: reference
5
+ summary: "Methods: getDeploymentId(), queue(), createQueueHandler(). Internal queue dispatch — normally handled by the SDK."
6
+ prerequisites:
7
+ - /docs/api-reference/workflow-runtime/get-world
8
+ related:
9
+ - /docs/api-reference/workflow-api/start
10
+ - /docs/foundations/starting-workflows
11
+ keywords:
12
+ - world.queue
13
+ - getDeploymentId
14
+ - queue
15
+ - createQueueHandler
16
+ - ValidQueueName
17
+ - queue dispatch
18
+ ---
19
+
20
+ Queue methods live directly on the `world` object (not nested). They dispatch internal workflow and step invocations to the queue backend.
21
+
22
+ <Callout type="warn">
23
+ These methods are used internally by the Workflow SDK to dispatch execution. You do not need to call them in normal operations — use [`start()`](/docs/api-reference/workflow-api/start) to trigger workflows instead. Direct queue access is only needed if you programmatically create a run via `world.events.create()` with a `run_created` event and need to kick off its initial execution, or for debugging resumption of a flow or step route.
24
+ </Callout>
25
+
26
+ ## Import
27
+
28
+ ```typescript lineNumbers
29
+ import { getWorld } from "workflow/runtime";
30
+
31
+ const world = await getWorld(); // [!code highlight]
32
+ // Queue methods are called directly on world — e.g. world.queue()
33
+ ```
34
+
35
+ ## Methods
36
+
37
+ ### getDeploymentId()
38
+
39
+ Get the current deployment ID. Used internally for routing queue messages to the correct deployment.
40
+
41
+ ```typescript lineNumbers
42
+ const deploymentId = await world.getDeploymentId(); // [!code highlight]
43
+ ```
44
+
45
+ **Returns:** `string` — The current deployment ID
46
+
47
+ ### queue()
48
+
49
+ Dispatch a message to a named queue. The message payload is an internal SDK type (`WorkflowInvokePayload`, `StepInvokePayload`, or `HealthCheckPayload`).
50
+
51
+ ```typescript lineNumbers
52
+ const { messageId } = await world.queue(queueName, payload, opts); // [!code highlight]
53
+ ```
54
+
55
+ **Parameters:**
56
+
57
+ | Parameter | Type | Description |
58
+ |-----------|------|-------------|
59
+ | `queueName` | `ValidQueueName` | The queue name (branded string) |
60
+ | `message` | `QueuePayload` | Internal SDK payload |
61
+ | `opts` | `QueueOptions` | Optional — `deploymentId`, `idempotencyKey`, `delaySeconds`, `headers` |
62
+
63
+ **Returns:** `{ messageId: MessageId | null }`
64
+
65
+ ### createQueueHandler()
66
+
67
+ Create an HTTP handler that processes messages from a queue. Used to set up the queue consumer endpoint.
68
+
69
+ ```typescript lineNumbers
70
+ const handler = world.createQueueHandler(prefix, callback); // [!code highlight]
71
+ ```
72
+
73
+ **Parameters:**
74
+
75
+ | Parameter | Type | Description |
76
+ |-----------|------|-------------|
77
+ | `prefix` | `QueuePrefix` | Queue name prefix to match |
78
+ | `callback` | `(message, meta) => Promise<void \| { timeoutSeconds: number }>` | Handler called for each message. `meta` contains `attempt`, `queueName`, `messageId`, `requestId`. |
79
+
80
+ **Returns:** `(req: Request) => Promise<Response>`
81
+
82
+ ## Related
83
+
84
+ - [start()](/docs/api-reference/workflow-api/start) — The standard way to start workflow runs
85
+ - [Starting Workflows](/docs/foundations/starting-workflows) — Core concepts for workflow invocation
86
+ - [Storage](/docs/api-reference/workflow-runtime/world/storage) — Create events that trigger queue dispatch
@@ -4,11 +4,11 @@ description: Query workflow runs, steps, hooks, and the underlying event log via
4
4
  type: reference
5
5
  summary: "Interfaces: world.events, world.runs, world.steps, world.hooks. Events are the source of truth; runs, steps, and hooks are materialized views."
6
6
  prerequisites:
7
- - /docs/api-reference/workflow-api/get-world
7
+ - /docs/api-reference/workflow-runtime/get-world
8
8
  related:
9
9
  - /docs/api-reference/workflow-api/get-run
10
10
  - /docs/how-it-works/event-sourcing
11
- - /docs/api-reference/workflow-api/world/observability
11
+ - /docs/api-reference/workflow-observability
12
12
  keywords:
13
13
  - world.events
14
14
  - world.runs
@@ -229,7 +229,7 @@ const result = await world.steps.list({ // [!code highlight]
229
229
  | `retryAfter` | `string \| null` | ISO timestamp for next retry attempt |
230
230
 
231
231
  <Callout type="info">
232
- Step I/O is serialized using the [devalue](https://github.com/Rich-Harris/devalue) format. Use `hydrateResourceIO()` from `workflow/observability` to deserialize it for display. See [Observability Utilities](/docs/api-reference/workflow-api/world/observability).
232
+ Step I/O is serialized using the [devalue](https://github.com/Rich-Harris/devalue) format. Use `hydrateResourceIO()` from `workflow/observability` to deserialize it for display. See [`hydrateResourceIO()`](/docs/api-reference/workflow-observability/hydrate-resource-io).
233
233
  </Callout>
234
234
 
235
235
  <Callout type="warn">
@@ -402,7 +402,7 @@ for (const event of events.data) {
402
402
 
403
403
  - [Event Sourcing](/docs/how-it-works/event-sourcing) — How the event log powers workflow replay and state
404
404
  - [getRun()](/docs/api-reference/workflow-api/get-run) — Higher-level API for working with individual runs
405
- - [Observability Utilities](/docs/api-reference/workflow-api/world/observability) — Hydrate step I/O, parse display names, decrypt data
405
+ - [`workflow/observability`](/docs/api-reference/workflow-observability) — Hydrate step I/O and parse display names
406
406
  - [resumeHook()](/docs/api-reference/workflow-api/resume-hook) — Resume a workflow by sending a payload to a hook
407
407
  - [Hooks](/docs/foundations/hooks) — Core concepts for hooks and pause points
408
408
  - [Workflows and Steps](/docs/foundations/workflows-and-steps) — Core concepts for steps
@@ -0,0 +1,216 @@
1
+ ---
2
+ title: Streams
3
+ description: Read, write, and manage real-time data streams for workflow runs.
4
+ type: reference
5
+ summary: "Methods: streams.write(), streams.writeMulti(), streams.get(), streams.close(), streams.list(), streams.getChunks(), streams.getInfo(). Stream methods live on world.streams."
6
+ prerequisites:
7
+ - /docs/api-reference/workflow-runtime/get-world
8
+ related:
9
+ - /docs/foundations/streaming
10
+ - /docs/api-reference/workflow/get-writable
11
+ keywords:
12
+ - streams.write
13
+ - streams.writeMulti
14
+ - streams.get
15
+ - streams.close
16
+ - streams.list
17
+ - streams.getChunks
18
+ - streams.getInfo
19
+ - Streamer interface
20
+ - real-time streaming
21
+ - stream lifecycle
22
+ ---
23
+
24
+ Stream methods live on `world.streams` (the `streams` sub-object of the `World` instance returned by `await getWorld()`). Use them to write chunks, read streams, and manage stream lifecycle outside of the standard `getWritable()` pattern.
25
+
26
+ <Callout type="info">
27
+ For most streaming use cases, use [`getWritable()`](/docs/api-reference/workflow/get-writable) inside steps. Direct stream methods are for advanced scenarios like building custom stream consumers or managing streams from outside a workflow.
28
+ </Callout>
29
+
30
+ ## Import
31
+
32
+ ```typescript lineNumbers
33
+ import { getWorld } from "workflow/runtime";
34
+
35
+ const world = await getWorld(); // [!code highlight]
36
+ // Stream methods are called on world.streams — e.g. world.streams.write()
37
+ ```
38
+
39
+ ## Methods
40
+
41
+ ### write()
42
+
43
+ Write a data chunk to a named stream.
44
+
45
+ ```typescript lineNumbers
46
+ await world.streams.write(runId, "default", chunk); // [!code highlight]
47
+ ```
48
+
49
+ **Parameters:**
50
+
51
+ | Parameter | Type | Description |
52
+ |-----------|------|-------------|
53
+ | `runId` | `string` | The workflow run ID |
54
+ | `name` | `string` | The stream name |
55
+ | `chunk` | `string \| Uint8Array` | Data to write |
56
+
57
+ ### writeMulti()
58
+
59
+ Write multiple chunks in a single operation. Optional optimization — not all World implementations support it. Falls back to sequential `write()` calls if unavailable.
60
+
61
+ ```typescript lineNumbers
62
+ await world.streams.writeMulti?.(runId, "default", [chunk1, chunk2]); // [!code highlight]
63
+ ```
64
+
65
+ **Parameters:**
66
+
67
+ | Parameter | Type | Description |
68
+ |-----------|------|-------------|
69
+ | `runId` | `string` | The workflow run ID |
70
+ | `name` | `string` | The stream name |
71
+ | `chunks` | `(string \| Uint8Array)[]` | Chunks to write, in order |
72
+
73
+ ### get()
74
+
75
+ Read data from a named stream as a live `ReadableStream` that waits for new chunks in real time.
76
+
77
+ ```typescript lineNumbers
78
+ const readable = await world.streams.get(runId, "default"); // [!code highlight]
79
+ ```
80
+
81
+ **Parameters:**
82
+
83
+ | Parameter | Type | Description |
84
+ |-----------|------|-------------|
85
+ | `runId` | `string` | The workflow run ID |
86
+ | `name` | `string` | The stream name |
87
+ | `startIndex` | `number` | Optional. Positive values skip chunks from the start (0-based). Negative values read from the tail (e.g. `-3` starts 3 chunks from the end). Clamped to 0. |
88
+
89
+ **Returns:** `ReadableStream<Uint8Array>`
90
+
91
+ ### close()
92
+
93
+ Close a stream when done writing.
94
+
95
+ ```typescript lineNumbers
96
+ await world.streams.close(runId, "default"); // [!code highlight]
97
+ ```
98
+
99
+ **Parameters:**
100
+
101
+ | Parameter | Type | Description |
102
+ |-----------|------|-------------|
103
+ | `runId` | `string` | The workflow run ID |
104
+ | `name` | `string` | The stream name |
105
+
106
+ ### list()
107
+
108
+ List all stream names associated with a workflow run.
109
+
110
+ ```typescript lineNumbers
111
+ const streamNames = await world.streams.list(runId); // [!code highlight]
112
+ ```
113
+
114
+ **Parameters:**
115
+
116
+ | Parameter | Type | Description |
117
+ |-----------|------|-------------|
118
+ | `runId` | `string` | The workflow run ID |
119
+
120
+ **Returns:** `string[]`
121
+
122
+ ### getChunks()
123
+
124
+ Fetch stream chunks with cursor-based pagination. Unlike `get()` (which returns a live `ReadableStream`), this returns a snapshot of currently available chunks.
125
+
126
+ ```typescript lineNumbers
127
+ const result = await world.streams.getChunks(runId, "default", { // [!code highlight]
128
+ limit: 50,
129
+ }); // [!code highlight]
130
+ // result.data: StreamChunk[], result.cursor, result.hasMore, result.done
131
+ ```
132
+
133
+ **Parameters:**
134
+
135
+ | Parameter | Type | Description |
136
+ |-----------|------|-------------|
137
+ | `runId` | `string` | The workflow run ID |
138
+ | `name` | `string` | The stream name |
139
+ | `options.limit` | `number` | Max chunks per page (default: 100, max: 1000) |
140
+ | `options.cursor` | `string` | Cursor from a previous response |
141
+
142
+ **Returns:** `StreamChunksResponse`
143
+
144
+ | Field | Type | Description |
145
+ |-------|------|-------------|
146
+ | `data` | `StreamChunk[]` | Chunks in index order. Each has `index` (0-based) and `data` (`Uint8Array`). |
147
+ | `cursor` | `string \| null` | Cursor for the next page |
148
+ | `hasMore` | `boolean` | Whether more pages of already-written chunks exist |
149
+ | `done` | `boolean` | Whether the stream is fully closed. When `false`, new chunks may appear in future requests even after `hasMore` is `false`. |
150
+
151
+ ### getInfo()
152
+
153
+ Retrieve lightweight metadata about a stream without fetching chunks.
154
+
155
+ ```typescript lineNumbers
156
+ const info = await world.streams.getInfo(runId, "default"); // [!code highlight]
157
+ // info.tailIndex: last chunk index (-1 if empty), info.done: whether stream is closed
158
+ ```
159
+
160
+ **Parameters:**
161
+
162
+ | Parameter | Type | Description |
163
+ |-----------|------|-------------|
164
+ | `runId` | `string` | The workflow run ID |
165
+ | `name` | `string` | The stream name |
166
+
167
+ **Returns:** `StreamInfoResponse`
168
+
169
+ | Field | Type | Description |
170
+ |-------|------|-------------|
171
+ | `tailIndex` | `number` | Index of the last known chunk (0-based). `-1` when no chunks have been written. |
172
+ | `done` | `boolean` | Whether the stream is fully complete (closed). |
173
+
174
+ ## Examples
175
+
176
+ ### Read a Stream as a Response
177
+
178
+ ```typescript lineNumbers
179
+ // app/api/workflow-streams/read/route.ts
180
+ import { getWorld } from "workflow/runtime";
181
+
182
+ export async function GET(req: Request) {
183
+ const url = new URL(req.url);
184
+ const streamName = url.searchParams.get("name") ?? "default";
185
+ const runId = url.searchParams.get("runId")!;
186
+ const world = await getWorld();
187
+ const readable = await world.streams.get(runId, streamName); // [!code highlight]
188
+
189
+ return new Response(readable, {
190
+ headers: { "Content-Type": "application/octet-stream" },
191
+ });
192
+ }
193
+ ```
194
+
195
+ ### Paginate Through Stream Chunks
196
+
197
+ ```typescript lineNumbers
198
+ import { getWorld } from "workflow/runtime";
199
+
200
+ const world = await getWorld();
201
+ let cursor: string | undefined;
202
+
203
+ do {
204
+ const result = await world.streams.getChunks(runId, "default", { cursor }); // [!code highlight]
205
+ for (const chunk of result.data) {
206
+ console.log(`Chunk ${chunk.index}:`, chunk.data);
207
+ }
208
+ cursor = result.cursor ?? undefined;
209
+ } while (cursor);
210
+ ```
211
+
212
+ ## Related
213
+
214
+ - [Streaming](/docs/foundations/streaming) — Core concepts for streaming data from workflows
215
+ - [getWritable()](/docs/api-reference/workflow/get-writable) — The standard way to write to streams from within steps
216
+ - [Storage](/docs/api-reference/workflow-runtime/world/storage) — Query runs, steps, hooks, and events
@@ -0,0 +1,18 @@
1
+ ---
2
+ title: "workflow/sveltekit"
3
+ description: SvelteKit integration for automatic workflow bundling via Vite.
4
+ type: overview
5
+ summary: Explore the SvelteKit integration for automatic workflow bundling and runtime support.
6
+ related:
7
+ - /docs/getting-started/sveltekit
8
+ ---
9
+
10
+ SvelteKit integration for Workflow SDK that configures Vite to transform workflow code and build the workflow bundles.
11
+
12
+ ## Functions
13
+
14
+ <Cards>
15
+ <Card title="workflowPlugin()" href="/docs/api-reference/workflow-sveltekit/workflow-plugin">
16
+ Vite plugin that transforms workflow code (`"use step"`/`"use workflow"` directives) in SvelteKit apps
17
+ </Card>
18
+ </Cards>
@@ -0,0 +1,4 @@
1
+ {
2
+ "title": "workflow/sveltekit",
3
+ "pages": ["workflow-plugin"]
4
+ }
@@ -0,0 +1,34 @@
1
+ ---
2
+ title: workflowPlugin
3
+ description: Configure Vite to transform workflow directives in SvelteKit.
4
+ type: reference
5
+ summary: Add workflowPlugin to your Vite config to enable workflow directive transformation in SvelteKit apps.
6
+ prerequisites:
7
+ - /docs/getting-started/sveltekit
8
+ ---
9
+
10
+ Returns the Vite plugins that transform workflow code (`"use step"`/`"use workflow"` directives) and build the workflow bundles in a SvelteKit app.
11
+
12
+ ## Usage
13
+
14
+ To enable `"use step"` and `"use workflow"` directives while developing locally or deploying to production, add `workflowPlugin()` to the `plugins` array of your Vite config.
15
+
16
+ ```typescript title="vite.config.ts" lineNumbers
17
+ import { sveltekit } from "@sveltejs/kit/vite";
18
+ import { defineConfig } from "vite";
19
+ import { workflowPlugin } from "workflow/sveltekit"; // [!code highlight]
20
+
21
+ export default defineConfig({
22
+ plugins: [sveltekit(), workflowPlugin()], // [!code highlight]
23
+ });
24
+ ```
25
+
26
+ ## API Signature
27
+
28
+ ### Parameters
29
+
30
+ This function does not accept any parameters in workflow 4.x. (5.x adds an options object with a `sourcemap` setting.)
31
+
32
+ ### Returns
33
+
34
+ Returns an array of Vite `Plugin` objects. Spread or pass the array directly to the `plugins` option of your Vite config — Vite flattens nested plugin arrays automatically.
@@ -0,0 +1,18 @@
1
+ ---
2
+ title: "workflow/vite"
3
+ description: Vite plugin for automatic workflow bundling in Vite + Nitro apps.
4
+ type: overview
5
+ summary: Explore the Vite plugin for automatic workflow bundling and runtime support.
6
+ related:
7
+ - /docs/getting-started/vite
8
+ ---
9
+
10
+ Vite integration for Workflow SDK. It wraps the [`workflow/nitro`](/docs/api-reference/workflow-nitro) module as a Vite plugin, for apps using Nitro's Vite plugin (`nitro/vite`).
11
+
12
+ ## Functions
13
+
14
+ <Cards>
15
+ <Card title="workflow()" href="/docs/api-reference/workflow-vite/workflow">
16
+ Vite plugin that transforms workflow code (`"use step"`/`"use workflow"` directives) and configures the Nitro server
17
+ </Card>
18
+ </Cards>
@@ -0,0 +1,4 @@
1
+ {
2
+ "title": "workflow/vite",
3
+ "pages": ["workflow"]
4
+ }
@@ -0,0 +1,47 @@
1
+ ---
2
+ title: workflow
3
+ description: Configure Vite and Nitro to transform workflow directives.
4
+ type: reference
5
+ summary: Add the workflow plugin to your Vite config to enable workflow directive transformation in Vite + Nitro apps.
6
+ prerequisites:
7
+ - /docs/getting-started/vite
8
+ ---
9
+
10
+ Returns the Vite plugins that transform workflow code (`"use step"`/`"use workflow"` directives) and configure the [`workflow/nitro`](/docs/api-reference/workflow-nitro) module on the Nitro server. It is designed to be used alongside `nitro()` from `nitro/vite`, which provides the server framework for API routes and deployment.
11
+
12
+ ## Usage
13
+
14
+ To enable `"use step"` and `"use workflow"` directives while developing locally or deploying to production, add `workflow()` to the `plugins` array of your Vite config, together with `nitro()`.
15
+
16
+ ```typescript title="vite.config.ts" lineNumbers
17
+ import { nitro } from "nitro/vite";
18
+ import { defineConfig } from "vite";
19
+ import { workflow } from "workflow/vite"; // [!code highlight]
20
+
21
+ export default defineConfig({
22
+ plugins: [nitro(), workflow()], // [!code highlight]
23
+ nitro: {
24
+ serverDir: "./",
25
+ },
26
+ });
27
+ ```
28
+
29
+ ## API Signature
30
+
31
+ ### Parameters
32
+
33
+ | Parameter | Type | Description |
34
+ | --- | --- | --- |
35
+ | `options` | `ModuleOptions` | Optional. Forwarded to the `workflow/nitro` module as its module options. |
36
+
37
+ #### ModuleOptions
38
+
39
+ | Option | Type | Default | Description |
40
+ | --- | --- | --- | --- |
41
+ | `dirs` | `string[]` | — | Directories to scan for workflows and steps. By default, the `workflows/` directory is scanned from the project root and all layer source directories. |
42
+ | `typescriptPlugin` | `boolean` | `false` | Adds the `workflow` TypeScript plugin to the generated `tsconfig.json` for IDE IntelliSense. |
43
+ | `runtime` | `string` | — | Node.js runtime version for Vercel Functions (e.g. `'nodejs22.x'`, `'nodejs24.x'`). Only applies when deploying to Vercel. |
44
+
45
+ ### Returns
46
+
47
+ Returns an array of Vite `Plugin` objects. Spread or pass the array directly to the `plugins` option of your Vite config — Vite flattens nested plugin arrays automatically.
@@ -0,0 +1,23 @@
1
+ ---
2
+ title: Step executed multiple times
3
+ description: A step ran more than once because its function invocation crashed before it could report a result.
4
+ type: troubleshooting
5
+ summary: Diagnose duplicate step_started events caused by function timeouts, OOMs, or network issues.
6
+ prerequisites:
7
+ - /docs/foundations/workflows-and-steps
8
+ related:
9
+ - /docs/observability
10
+ - /docs/foundations/errors-and-retries
11
+ ---
12
+
13
+ There may be cases where you see multiple `step_started` events for the same step in a workflow run. This happens if the function invocation executing the step crashes unexpectedly, and the step can not report the error. The step will be re-tried according to your retry policy in this case, but no error will be visible in the [Observability UI](/docs/observability).
14
+
15
+ ## Common Causes
16
+
17
+ - **Function timeouts**: if your step code runs longer than the configured maximum function duration, it will be killed. Compare the gap between the `step_started` events to your configured function duration to be sure.
18
+ - **Out of memory (OOM)**: if your step code loads enough data into memory, especially if the step is invoked concurrently, the function invocation might run out of memory. You can see your function's peak memory use by going to the [Observability Query page](https://vercel.com/docs/observability) and showing the **Function Invocation Peak Memory** metric, then filtering down the **Route** to `/.well-known/workflow` endpoints.
19
+ - **Network issues**: persistent firewall, network stability, and related issues might prevent your function from reporting results or errors. This should be temporary.
20
+
21
+ ## Getting Help
22
+
23
+ If you consistently see multiple `step_started` events and have ruled out function timeouts, OOMs, and firewall issues, please [contact support](https://vercel.com/help).
@@ -0,0 +1,18 @@
1
+ ---
2
+ title: "workflow/astro"
3
+ description: Astro integration for automatic workflow bundling and route registration.
4
+ type: overview
5
+ summary: Explore the Astro integration for automatic workflow bundling and runtime support.
6
+ related:
7
+ - /docs/getting-started/astro
8
+ ---
9
+
10
+ Astro integration for Workflow SDK that transforms workflow code and builds the workflow bundles.
11
+
12
+ ## Functions
13
+
14
+ <Cards>
15
+ <Card title="workflow()" href="/docs/api-reference/workflow-astro/workflow">
16
+ Astro integration that transforms workflow code (`"use step"`/`"use workflow"` directives)
17
+ </Card>
18
+ </Cards>
@@ -0,0 +1,4 @@
1
+ {
2
+ "title": "workflow/astro",
3
+ "pages": ["workflow"]
4
+ }
@@ -0,0 +1,45 @@
1
+ ---
2
+ title: workflow
3
+ description: Configure Astro to transform workflow directives.
4
+ type: reference
5
+ summary: Add the workflow integration to your Astro config to enable workflow directive transformation.
6
+ prerequisites:
7
+ - /docs/getting-started/astro
8
+ ---
9
+
10
+ Returns an Astro integration that transforms workflow code (`"use step"`/`"use workflow"` directives) and builds the workflow bundles.
11
+
12
+ ## Usage
13
+
14
+ To enable `"use step"` and `"use workflow"` directives while developing locally or deploying to production, add `workflow()` to the `integrations` array of your Astro config.
15
+
16
+ ```typescript title="astro.config.mjs" lineNumbers
17
+ // @ts-check
18
+ import { defineConfig } from "astro/config";
19
+ import { workflow } from "workflow/astro"; // [!code highlight]
20
+
21
+ // https://astro.build/config
22
+ export default defineConfig({
23
+ integrations: [workflow()], // [!code highlight]
24
+ });
25
+ ```
26
+
27
+ The integration registers the workflow Vite transform plugins during `astro:config:setup` and builds the workflow bundles — locally during config setup, or via the Vercel builder after `astro:build:done` when deploying to Vercel.
28
+
29
+ ## API Signature
30
+
31
+ ### Parameters
32
+
33
+ | Parameter | Type | Description |
34
+ | --- | --- | --- |
35
+ | `options` | `WorkflowPluginOptions` | Optional. Configures the workflow build. |
36
+
37
+ #### WorkflowPluginOptions
38
+
39
+ | Option | Type | Default | Description |
40
+ | --- | --- | --- | --- |
41
+ | `sourcemap` | `boolean \| 'inline' \| 'linked' \| 'external' \| 'both'` | `'inline'` | Controls source maps on generated workflow bundles. Accepts the same values as esbuild's `sourcemap` option. Set to `false` for smaller function bundles (useful for staying under the Vercel 250MB function size limit) at the cost of stack traces pointing at generated code. Can also be set via the `WORKFLOW_SOURCEMAP` environment variable. |
42
+
43
+ ### Returns
44
+
45
+ Returns an `AstroIntegration` object to include in the `integrations` array of your Astro config.
@@ -0,0 +1,60 @@
1
+ ---
2
+ title: HookConflictError
3
+ description: Thrown when creating a hook with a token that is already in use by another workflow run.
4
+ type: reference
5
+ summary: Catch HookConflictError when a hook token is already claimed by another active workflow run.
6
+ related:
7
+ - /docs/api-reference/workflow/create-hook
8
+ - /docs/foundations/hooks
9
+ - /docs/errors/hook-conflict
10
+ ---
11
+
12
+ `HookConflictError` is thrown when creating a hook with a token that is already in use by another active workflow run. Hook tokens must be unique across all running workflows — see the [hook-conflict](/docs/errors/hook-conflict) error guide for resolution strategies.
13
+
14
+ ```typescript lineNumbers
15
+ import { HookConflictError } from "workflow/errors"
16
+ declare function startApprovalWorkflow(token: string): Promise<void>; // @setup
17
+ declare const token: string; // @setup
18
+
19
+ try {
20
+ await startApprovalWorkflow(token);
21
+ } catch (error) {
22
+ if (HookConflictError.is(error)) { // [!code highlight]
23
+ console.error(
24
+ `Token "${error.token}" already in use by run ${error.conflictingRunId}`
25
+ );
26
+ }
27
+ }
28
+ ```
29
+
30
+ ## API Signature
31
+
32
+ ### Properties
33
+
34
+ <TSDoc
35
+ definition={`
36
+ interface HookConflictError {
37
+ /** The hook token that conflicted. */
38
+ token: string;
39
+ /** The run ID of the workflow currently holding the token, when known. */
40
+ conflictingRunId?: string;
41
+ /** The error message. */
42
+ message: string;
43
+ }
44
+ export default HookConflictError;`}
45
+ />
46
+
47
+ ### Static Methods
48
+
49
+ #### `HookConflictError.is(value)`
50
+
51
+ Type-safe check for `HookConflictError` instances. Preferred over `instanceof` because it works across module boundaries and VM contexts.
52
+
53
+ ```typescript
54
+ import { HookConflictError } from "workflow/errors"
55
+ declare const error: unknown; // @setup
56
+
57
+ if (HookConflictError.is(error)) {
58
+ // error is typed as HookConflictError
59
+ }
60
+ ```