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
@@ -0,0 +1,42 @@
1
+ ---
2
+ title: workflowEntrypoint
3
+ description: Create the HTTP route handler that executes workflow runs from a workflow bundle.
4
+ type: reference
5
+ summary: Use workflowEntrypoint to wire a compiled workflow bundle into an HTTP route in custom server environments.
6
+ prerequisites:
7
+ - /docs/how-it-works/code-transform
8
+ related:
9
+ - /docs/api-reference/workflow-runtime/health-check
10
+ ---
11
+
12
+ Creates the HTTP route handler that executes workflow runs. The handler receives queue messages, replays the workflow from its event log, executes steps inline where possible, and suspends when the workflow waits on sleeps or hooks.
13
+
14
+ Framework adapters (Next.js, Nitro, SvelteKit, etc.) call this for you and mount the result at `/.well-known/workflow/v1/flow` — you only need it when wiring workflow support into a custom server environment.
15
+
16
+ ```typescript lineNumbers
17
+ import { workflowEntrypoint } from "workflow/runtime";
18
+ declare const workflowBundleCode: string; // @setup
19
+
20
+ const handler = workflowEntrypoint(workflowBundleCode); // [!code highlight]
21
+
22
+ // Mount on your server, e.g. a fetch-style route:
23
+ export const POST = (req: Request) => handler(req);
24
+ ```
25
+
26
+ ## API Signature
27
+
28
+ ### Parameters
29
+
30
+ | Parameter | Type | Description |
31
+ |-----------|------|-------------|
32
+ | `workflowCode` | `string` | The compiled workflow bundle code containing all workflow functions |
33
+ | `options` | `{ namespace?: string }` | Optional. `namespace` scopes the queue topics this handler consumes. |
34
+
35
+ ### Returns
36
+
37
+ Returns a fetch-style request handler: `(req: Request) => Promise<Response>`.
38
+
39
+ ## Related Functions
40
+
41
+ - [`getWorldHandlers()`](/docs/api-reference/workflow-runtime/get-world-handlers) - The build-time World access this handler is built on.
42
+ - [`healthCheck()`](/docs/api-reference/workflow-runtime/health-check) - Verify the entrypoint processes queue messages end-to-end.
@@ -0,0 +1,55 @@
1
+ ---
2
+ title: World SDK
3
+ description: Low-level API for inspecting and managing workflow runs, steps, events, hooks, streams, and queues.
4
+ type: overview
5
+ summary: Access workflow infrastructure via await getWorld() for building observability dashboards, admin tools, and custom integrations.
6
+ prerequisites:
7
+ - /docs/api-reference/workflow-runtime/get-world
8
+ keywords:
9
+ - getWorld
10
+ - World SDK
11
+ - workflow runtime
12
+ - observability dashboard
13
+ - admin panel
14
+ - workflow management
15
+ ---
16
+
17
+ The World SDK provides direct access to workflow infrastructure — runs, steps, events, hooks, streams, and queues. Use it to build observability dashboards, admin panels, debugging tools, and custom workflow management logic.
18
+
19
+ ```typescript lineNumbers
20
+ import { getWorld } from "workflow/runtime";
21
+
22
+ const world = await getWorld(); // [!code highlight]
23
+ ```
24
+
25
+ ## Interfaces
26
+
27
+ <Cards>
28
+ <Card href="/docs/api-reference/workflow-runtime/world/storage" title="Storage">
29
+ Query runs, steps, hooks, and the underlying event log.
30
+ </Card>
31
+ <Card href="/docs/api-reference/workflow-runtime/world/streams" title="Streams">
32
+ Read, write, and manage real-time data streams for workflow runs.
33
+ </Card>
34
+ <Card href="/docs/api-reference/workflow-runtime/world/queue" title="Queue">
35
+ Low-level queue dispatch (internal SDK infrastructure).
36
+ </Card>
37
+ </Cards>
38
+
39
+ <Callout type="info">
40
+ The World SDK is the low-level foundation that higher-level functions like [`getRun()`](/docs/api-reference/workflow-api/get-run) and [`start()`](/docs/api-reference/workflow-api/start) are built on. Use it when you need capabilities beyond what those functions provide.
41
+ </Callout>
42
+
43
+ ## Data Hydration
44
+
45
+ Step input/output data is serialized using the [devalue](https://github.com/Rich-Harris/devalue) format. To display this data in your UI, use the hydration utilities from `workflow/observability`:
46
+
47
+ ```typescript lineNumbers
48
+ import { hydrateResourceIO, observabilityRevivers } from "workflow/observability"; // [!code highlight]
49
+
50
+ const step = await world.steps.get(runId, stepId);
51
+ const hydrated = hydrateResourceIO(step, observabilityRevivers); // [!code highlight]
52
+ console.log(hydrated.input, hydrated.output);
53
+ ```
54
+
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
+ }
@@ -4,7 +4,7 @@ description: Low-level queue interface for dispatching workflow and step invocat
4
4
  type: reference
5
5
  summary: "Methods: getDeploymentId(), queue(), createQueueHandler(). Internal queue dispatch — normally handled by the SDK."
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/start
10
10
  - /docs/foundations/starting-workflows
@@ -83,4 +83,4 @@ const handler = world.createQueueHandler(prefix, callback); // [!code highlight]
83
83
 
84
84
  - [start()](/docs/api-reference/workflow-api/start) — The standard way to start workflow runs
85
85
  - [Starting Workflows](/docs/foundations/starting-workflows) — Core concepts for workflow invocation
86
- - [Storage](/docs/api-reference/workflow-api/world/storage) — Create events that trigger queue dispatch
86
+ - [Storage](/docs/api-reference/workflow-runtime/world/storage) — Create events that trigger queue dispatch
@@ -0,0 +1,409 @@
1
+ ---
2
+ title: Storage
3
+ description: Query workflow runs, steps, hooks, and the underlying event log via the World storage interface.
4
+ type: reference
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
+ prerequisites:
7
+ - /docs/api-reference/workflow-runtime/get-world
8
+ related:
9
+ - /docs/api-reference/workflow-api/get-run
10
+ - /docs/how-it-works/event-sourcing
11
+ - /docs/api-reference/workflow-observability
12
+ keywords:
13
+ - world.events
14
+ - world.runs
15
+ - world.steps
16
+ - world.hooks
17
+ - event log
18
+ - event sourcing
19
+ - materialized views
20
+ - WorkflowRun
21
+ - Step
22
+ - Hook
23
+ - Event
24
+ - cursor pagination
25
+ - resolveData
26
+ - run_cancelled
27
+ - correlation ID
28
+ - parseStepName
29
+ - parseWorkflowName
30
+ ---
31
+
32
+ The World storage interface exposes four sub-interfaces for querying workflow data:
33
+
34
+ - **`world.events`** — The append-only event log. This is the source of truth for all workflow state. See [Event Sourcing](/docs/how-it-works/event-sourcing) for background.
35
+ - **`world.runs`**, **`world.steps`**, **`world.hooks`** — Materialized views derived from the event log, provided as convenience accessors for the most common query patterns.
36
+
37
+ ```typescript lineNumbers
38
+ import { getWorld } from "workflow/runtime";
39
+
40
+ const world = await getWorld(); // [!code highlight]
41
+ ```
42
+
43
+ ---
44
+
45
+ ## world.events
46
+
47
+ The event log drives all workflow state. Use it for audit trails, debugging, and programmatic run cancellation.
48
+
49
+ ### events.create()
50
+
51
+ Create a new event for a workflow run. Most commonly used to cancel a run.
52
+
53
+ ```typescript lineNumbers
54
+ await world.events.create(runId, { // [!code highlight]
55
+ eventType: "run_cancelled", // [!code highlight]
56
+ }); // [!code highlight]
57
+ ```
58
+
59
+ | Parameter | Type | Description |
60
+ |-----------|------|-------------|
61
+ | `runId` | `string \| null` | The workflow run ID (`null` only for `run_created` events, where the server generates an ID) |
62
+ | `data` | `CreateEventRequest` | Event data including `eventType` |
63
+ | `params` | `object` | Optional parameters |
64
+
65
+ **Returns:** `EventResult` — The created event and the affected entity (run/step/hook)
66
+
67
+ ### events.get()
68
+
69
+ Retrieve a single event by run ID and event ID.
70
+
71
+ ```typescript lineNumbers
72
+ const event = await world.events.get(runId, eventId); // [!code highlight]
73
+ ```
74
+
75
+ | Parameter | Type | Description |
76
+ |-----------|------|-------------|
77
+ | `runId` | `string` | The workflow run ID |
78
+ | `eventId` | `string` | The event ID |
79
+
80
+ **Returns:** `Event`
81
+
82
+ ### events.list()
83
+
84
+ List events for a run with cursor pagination.
85
+
86
+ ```typescript lineNumbers
87
+ const result = await world.events.list({ runId, pagination: { cursor } }); // [!code highlight]
88
+ ```
89
+
90
+ | Parameter | Type | Description |
91
+ |-----------|------|-------------|
92
+ | `params.runId` | `string` | Filter events by run ID |
93
+ | `params.pagination.cursor` | `string` | Cursor for the next page |
94
+
95
+ **Returns:** `{ data: Event[], cursor?: string }`
96
+
97
+ ### events.listByCorrelationId()
98
+
99
+ List events that share a correlation ID, useful for tracing related events across runs.
100
+
101
+ ```typescript lineNumbers
102
+ const result = await world.events.listByCorrelationId({ // [!code highlight]
103
+ correlationId: "order-123",
104
+ }); // [!code highlight]
105
+ ```
106
+
107
+ | Parameter | Type | Description |
108
+ |-----------|------|-------------|
109
+ | `params.correlationId` | `string` | The correlation ID to filter by |
110
+ | `params.pagination.cursor` | `string` | Cursor for the next page |
111
+
112
+ **Returns:** `{ data: Event[], cursor?: string }`
113
+
114
+ ### Event Types
115
+
116
+ | Category | Types |
117
+ |----------|-------|
118
+ | Run | `run_created`, `run_started`, `run_completed`, `run_failed`, `run_cancelled` |
119
+ | Attribute | `attr_set` |
120
+ | Step | `step_created`, `step_started`, `step_completed`, `step_failed`, `step_retrying` |
121
+ | Hook | `hook_created`, `hook_received`, `hook_disposed`, `hook_conflict` |
122
+ | Wait | `wait_created`, `wait_completed` |
123
+
124
+ ---
125
+
126
+ ## world.runs
127
+
128
+ Materialized from run events. Use it to list and inspect workflow runs.
129
+
130
+ ### runs.get()
131
+
132
+ ```typescript lineNumbers
133
+ const run = await world.runs.get(runId); // [!code highlight]
134
+ ```
135
+
136
+ | Parameter | Type | Description |
137
+ |-----------|------|-------------|
138
+ | `runId` | `string` | The workflow run ID |
139
+ | `params.resolveData` | `'all' \| 'none'` | Whether to include input/output data. Default: `'all'` |
140
+
141
+ **Returns:** `WorkflowRun` (or `WorkflowRunWithoutData` when `resolveData: 'none'`)
142
+
143
+ ### runs.list()
144
+
145
+ ```typescript lineNumbers
146
+ const result = await world.runs.list({ // [!code highlight]
147
+ pagination: { cursor },
148
+ }); // [!code highlight]
149
+ ```
150
+
151
+ | Parameter | Type | Description |
152
+ |-----------|------|-------------|
153
+ | `params.pagination.cursor` | `string` | Cursor for the next page |
154
+ | `params.resolveData` | `'all' \| 'none'` | Whether to include input/output data |
155
+
156
+ **Returns:** `{ data: WorkflowRun[], cursor?: string }`
157
+
158
+ ### Cancelling Runs
159
+
160
+ To cancel a run, create a `run_cancelled` event via `world.events.create()` (see [world.events](#worldevents) above), or use the CLI or Web UI helpers.
161
+
162
+ ### WorkflowRun Type
163
+
164
+ | Field | Type | Description |
165
+ |-------|------|-------------|
166
+ | `runId` | `string` | Unique run identifier |
167
+ | `status` | `string` | `'running'`, `'completed'`, `'failed'`, `'cancelled'` |
168
+ | `workflowName` | `string` | Machine-readable workflow identifier |
169
+ | `input` | `any` | Workflow input data (when `resolveData: 'all'`) |
170
+ | `output` | `any` | Workflow output data (when `resolveData: 'all'`) |
171
+ | `error` | `any` | Error data if the run failed |
172
+ | `startedAt` | `string` | ISO timestamp when the run started |
173
+ | `completedAt` | `string \| null` | ISO timestamp when the run completed |
174
+
175
+ <Callout type="warn">
176
+ `workflowName` is a machine-readable identifier like `workflow//./src/workflows/order//processOrder`. Use `parseWorkflowName()` from `workflow/observability` to extract a display-friendly name.
177
+ </Callout>
178
+
179
+ ---
180
+
181
+ ## world.steps
182
+
183
+ Materialized from step events. Use it to list steps, inspect their input/output, and build progress dashboards.
184
+
185
+ ### steps.get()
186
+
187
+ ```typescript lineNumbers
188
+ const step = await world.steps.get(runId, stepId); // [!code highlight]
189
+ ```
190
+
191
+ | Parameter | Type | Description |
192
+ |-----------|------|-------------|
193
+ | `runId` | `string \| undefined` | The workflow run ID |
194
+ | `stepId` | `string` | The step ID |
195
+ | `params.resolveData` | `'all' \| 'none'` | Whether to include input/output data. Default: `'all'` |
196
+
197
+ **Returns:** `Step` (or `StepWithoutData` when `resolveData: 'none'`)
198
+
199
+ ### steps.list()
200
+
201
+ ```typescript lineNumbers
202
+ const result = await world.steps.list({ // [!code highlight]
203
+ runId,
204
+ pagination: { cursor },
205
+ }); // [!code highlight]
206
+ ```
207
+
208
+ | Parameter | Type | Description |
209
+ |-----------|------|-------------|
210
+ | `params.runId` | `string` | Filter steps by run ID |
211
+ | `params.pagination.cursor` | `string` | Cursor for the next page |
212
+ | `params.resolveData` | `'all' \| 'none'` | Whether to include input/output data |
213
+
214
+ **Returns:** `{ data: Step[], cursor?: string }`
215
+
216
+ ### Step Type
217
+
218
+ | Field | Type | Description |
219
+ |-------|------|-------------|
220
+ | `runId` | `string` | Parent workflow run ID |
221
+ | `stepId` | `string` | Unique step identifier |
222
+ | `stepName` | `string` | Machine-readable step identifier |
223
+ | `status` | `string` | `'running'`, `'completed'`, `'failed'` |
224
+ | `input` | `any` | Step input data (when `resolveData: 'all'`) |
225
+ | `output` | `any` | Step output data (when `resolveData: 'all'`) |
226
+ | `error` | `any` | Error data if the step failed |
227
+ | `attempt` | `number` | Current retry attempt number |
228
+ | `startedAt` | `string` | ISO timestamp when the step started |
229
+ | `completedAt` | `string \| null` | ISO timestamp when the step completed |
230
+ | `retryAfter` | `string \| null` | ISO timestamp for next retry attempt |
231
+
232
+ <Callout type="info">
233
+ 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).
234
+ </Callout>
235
+
236
+ <Callout type="warn">
237
+ `stepName` is a machine-readable identifier like `step//./src/workflows/order//processPayment`. Use `parseStepName()` from `workflow/observability` to extract the `shortName` for UI display.
238
+ </Callout>
239
+
240
+ ---
241
+
242
+ ## world.hooks
243
+
244
+ Materialized from hook events. Hooks are pause points in workflows that wait for external input. Use this interface to look up hooks by ID or token, inspect metadata, and build UIs for pending approvals.
245
+
246
+ ### hooks.get()
247
+
248
+ ```typescript lineNumbers
249
+ const hook = await world.hooks.get(hookId); // [!code highlight]
250
+ ```
251
+
252
+ | Parameter | Type | Description |
253
+ |-----------|------|-------------|
254
+ | `hookId` | `string` | The hook ID |
255
+
256
+ **Returns:** `Hook`
257
+
258
+ ### hooks.getByToken()
259
+
260
+ Look up a hook by its token. Useful in webhook resume flows where you receive a token in the callback URL.
261
+
262
+ ```typescript lineNumbers
263
+ const hook = await world.hooks.getByToken(token); // [!code highlight]
264
+ ```
265
+
266
+ | Parameter | Type | Description |
267
+ |-----------|------|-------------|
268
+ | `token` | `string` | The hook token |
269
+
270
+ **Returns:** `Hook`
271
+
272
+ ### hooks.list()
273
+
274
+ ```typescript lineNumbers
275
+ const result = await world.hooks.list({ // [!code highlight]
276
+ pagination: { cursor },
277
+ }); // [!code highlight]
278
+ ```
279
+
280
+ | Parameter | Type | Description |
281
+ |-----------|------|-------------|
282
+ | `params.pagination.cursor` | `string` | Cursor for the next page |
283
+
284
+ **Returns:** `{ data: Hook[], cursor?: string }`
285
+
286
+ ### Hook Type
287
+
288
+ | Field | Type | Description |
289
+ |-------|------|-------------|
290
+ | `runId` | `string` | Parent workflow run ID |
291
+ | `hookId` | `string` | Unique hook identifier |
292
+ | `token` | `string` | Hook token for resuming |
293
+ | `ownerId` | `string` | Owner (team/user) ID |
294
+ | `projectId` | `string` | Project ID |
295
+ | `environment` | `string` | Deployment environment |
296
+ | `metadata` | `object` | Custom metadata attached to the hook |
297
+ | `isWebhook` | `boolean` | Whether this is a webhook-style hook |
298
+
299
+ ---
300
+
301
+ ## Examples
302
+
303
+ ### List Runs with Pagination
304
+
305
+ ```typescript lineNumbers
306
+ import { getWorld } from "workflow/runtime";
307
+
308
+ const world = await getWorld();
309
+ let cursor: string | undefined;
310
+
311
+ const runs = await world.runs.list({ // [!code highlight]
312
+ pagination: { cursor },
313
+ }); // [!code highlight]
314
+
315
+ cursor = runs.cursor; // pass to next call for pagination
316
+ ```
317
+
318
+ ### Get a Run — Full Data vs. Metadata Only
319
+
320
+ ```typescript lineNumbers
321
+ import { getWorld } from "workflow/runtime";
322
+
323
+ const world = await getWorld();
324
+
325
+ // Full data (default) — includes serialized input/output
326
+ const run = await world.runs.get(runId); // [!code highlight]
327
+
328
+ // Metadata only — lighter, no I/O loaded
329
+ const lightweight = await world.runs.get(runId, { // [!code highlight]
330
+ resolveData: "none", // [!code highlight]
331
+ }); // [!code highlight]
332
+ ```
333
+
334
+ ### List Steps for a Progress Dashboard
335
+
336
+ ```typescript lineNumbers
337
+ import { getWorld } from "workflow/runtime";
338
+ import { parseStepName } from "workflow/observability"; // [!code highlight]
339
+
340
+ const world = await getWorld();
341
+ const steps = await world.steps.list({ // [!code highlight]
342
+ runId,
343
+ resolveData: "none",
344
+ }); // [!code highlight]
345
+
346
+ const progress = steps.data.map((step) => {
347
+ const parsed = parseStepName(step.stepName); // [!code highlight]
348
+ return {
349
+ stepId: step.stepId,
350
+ displayName: parsed?.shortName ?? step.stepName, // [!code highlight]
351
+ status: step.status,
352
+ };
353
+ });
354
+ ```
355
+
356
+ ### Hydrate Step I/O
357
+
358
+ ```typescript lineNumbers
359
+ import { getWorld } from "workflow/runtime";
360
+ import { hydrateResourceIO, observabilityRevivers } from "workflow/observability"; // [!code highlight]
361
+
362
+ const world = await getWorld();
363
+ const step = await world.steps.get(runId, stepId); // [!code highlight]
364
+ const hydrated = hydrateResourceIO(step, observabilityRevivers); // [!code highlight]
365
+ console.log(hydrated.input, hydrated.output);
366
+ ```
367
+
368
+ ### Cancel a Run
369
+
370
+ ```typescript lineNumbers
371
+ import { getWorld } from "workflow/runtime";
372
+
373
+ const world = await getWorld();
374
+ await world.events.create(runId, { // [!code highlight]
375
+ eventType: "run_cancelled", // [!code highlight]
376
+ }); // [!code highlight]
377
+ ```
378
+
379
+ ### Look Up Hook by Token
380
+
381
+ ```typescript lineNumbers
382
+ import { getWorld } from "workflow/runtime";
383
+
384
+ const world = await getWorld();
385
+ const hook = await world.hooks.getByToken(token); // [!code highlight]
386
+ console.log(hook.runId, hook.metadata); // [!code highlight]
387
+ ```
388
+
389
+ ### List Events for Audit Trail
390
+
391
+ ```typescript lineNumbers
392
+ import { getWorld } from "workflow/runtime";
393
+
394
+ const world = await getWorld();
395
+ const events = await world.events.list({ runId }); // [!code highlight]
396
+
397
+ for (const event of events.data) {
398
+ console.log(event.eventType, event.createdAt);
399
+ }
400
+ ```
401
+
402
+ ## Related
403
+
404
+ - [Event Sourcing](/docs/how-it-works/event-sourcing) — How the event log powers workflow replay and state
405
+ - [getRun()](/docs/api-reference/workflow-api/get-run) — Higher-level API for working with individual runs
406
+ - [`workflow/observability`](/docs/api-reference/workflow-observability) — Hydrate step I/O and parse display names
407
+ - [resumeHook()](/docs/api-reference/workflow-api/resume-hook) — Resume a workflow by sending a payload to a hook
408
+ - [Hooks](/docs/foundations/hooks) — Core concepts for hooks and pause points
409
+ - [Workflows and Steps](/docs/foundations/workflows-and-steps) — Core concepts for steps
@@ -4,7 +4,7 @@ description: Read, write, and manage real-time data streams for workflow runs.
4
4
  type: reference
5
5
  summary: "Methods: writeToStream(), writeToStreamMulti(), readFromStream(), closeStream(), listStreamsByRunId(), getStreamChunks(), getStreamInfo(). Stream methods live directly on the world object."
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/foundations/streaming
10
10
  - /docs/api-reference/workflow/get-writable
@@ -211,4 +211,4 @@ do {
211
211
 
212
212
  - [Streaming](/docs/foundations/streaming) — Core concepts for streaming data from workflows
213
213
  - [getWritable()](/docs/api-reference/workflow/get-writable) — The standard way to write to streams from within steps
214
- - [Storage](/docs/api-reference/workflow-api/world/storage) — Query runs, steps, hooks, and events
214
+ - [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,42 @@
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
+ | Parameter | Type | Description |
31
+ | --- | --- | --- |
32
+ | `options` | `WorkflowPluginOptions` | Optional. Configures the workflow build. |
33
+
34
+ #### WorkflowPluginOptions
35
+
36
+ | Option | Type | Default | Description |
37
+ | --- | --- | --- | --- |
38
+ | `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. |
39
+
40
+ ### Returns
41
+
42
+ 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
+ }