workflow 4.2.0-beta.73 → 4.2.0-beta.75

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 (56) hide show
  1. package/README.md +6 -6
  2. package/docs/ai/defining-tools.mdx +2 -2
  3. package/docs/ai/human-in-the-loop.mdx +1 -1
  4. package/docs/ai/index.mdx +8 -8
  5. package/docs/ai/resumable-streams.mdx +1 -1
  6. package/docs/ai/sleep-and-delays.mdx +2 -2
  7. package/docs/ai/streaming-updates-from-tools.mdx +1 -1
  8. package/docs/api-reference/index.mdx +9 -3
  9. package/docs/api-reference/meta.json +10 -1
  10. package/docs/api-reference/workflow/create-webhook.mdx +4 -0
  11. package/docs/api-reference/workflow/index.mdx +2 -2
  12. package/docs/api-reference/workflow-ai/durable-agent.mdx +1 -1
  13. package/docs/api-reference/workflow-api/get-world.mdx +33 -157
  14. package/docs/api-reference/workflow-api/index.mdx +3 -0
  15. package/docs/api-reference/workflow-api/world/events.mdx +227 -0
  16. package/docs/api-reference/workflow-api/world/hooks.mdx +181 -0
  17. package/docs/api-reference/workflow-api/world/index.mdx +67 -0
  18. package/docs/api-reference/workflow-api/world/meta.json +12 -0
  19. package/docs/api-reference/workflow-api/world/observability.mdx +289 -0
  20. package/docs/api-reference/workflow-api/world/queue.mdx +127 -0
  21. package/docs/api-reference/workflow-api/world/runs.mdx +223 -0
  22. package/docs/api-reference/workflow-api/world/steps.mdx +216 -0
  23. package/docs/api-reference/workflow-api/world/streams.mdx +152 -0
  24. package/docs/api-reference/workflow-globals.mdx +102 -0
  25. package/docs/api-reference/workflow-next/index.mdx +1 -1
  26. package/docs/api-reference/workflow-serde/index.mdx +2 -2
  27. package/docs/changelog/index.mdx +2 -2
  28. package/docs/deploying/building-a-world.mdx +1 -1
  29. package/docs/deploying/world/vercel-world.mdx +20 -13
  30. package/docs/errors/index.mdx +1 -1
  31. package/docs/errors/node-js-module-in-workflow.mdx +1 -1
  32. package/docs/errors/serialization-failed.mdx +1 -1
  33. package/docs/errors/start-invalid-workflow-function.mdx +3 -3
  34. package/docs/foundations/errors-and-retries.mdx +1 -1
  35. package/docs/foundations/hooks.mdx +5 -1
  36. package/docs/foundations/serialization.mdx +2 -2
  37. package/docs/foundations/streaming.mdx +3 -2
  38. package/docs/foundations/workflows-and-steps.mdx +2 -2
  39. package/docs/getting-started/astro.mdx +5 -5
  40. package/docs/getting-started/express.mdx +5 -5
  41. package/docs/getting-started/fastify.mdx +5 -5
  42. package/docs/getting-started/hono.mdx +5 -5
  43. package/docs/getting-started/nestjs.mdx +5 -5
  44. package/docs/getting-started/next.mdx +5 -5
  45. package/docs/getting-started/nitro.mdx +5 -5
  46. package/docs/getting-started/nuxt.mdx +5 -5
  47. package/docs/getting-started/sveltekit.mdx +5 -5
  48. package/docs/getting-started/vite.mdx +5 -5
  49. package/docs/how-it-works/code-transform.mdx +6 -6
  50. package/docs/how-it-works/encryption.mdx +3 -3
  51. package/docs/how-it-works/event-sourcing.mdx +5 -5
  52. package/docs/how-it-works/framework-integrations.mdx +9 -9
  53. package/docs/how-it-works/understanding-directives.mdx +11 -11
  54. package/docs/observability/index.mdx +5 -5
  55. package/docs/testing/index.mdx +4 -4
  56. package/package.json +12 -12
@@ -0,0 +1,227 @@
1
+ ---
2
+ title: world.events
3
+ description: Query the append-only event log for workflow state changes, audit trails, and run cancellation.
4
+ type: reference
5
+ summary: "Methods: create(), get(), list(), listByCorrelationId(). The event log is the source of truth for all workflow state."
6
+ prerequisites:
7
+ - /docs/api-reference/workflow-api/get-world
8
+ related:
9
+ - /docs/api-reference/workflow-api/world/runs
10
+ - /docs/api-reference/workflow-api/world/steps
11
+ keywords:
12
+ - world.events
13
+ - world.events.create
14
+ - world.events.get
15
+ - world.events.list
16
+ - world.events.listByCorrelationId
17
+ - event log
18
+ - audit trail
19
+ - run_cancelled
20
+ - event types
21
+ - correlation ID
22
+ - cancel workflow run
23
+ ---
24
+
25
+ The `world.events` interface provides access to the append-only event log that drives all workflow state. Runs, steps, and hooks are materialized views derived from events. Use this interface for audit trails, debugging, and programmatic run cancellation.
26
+
27
+ ## Import
28
+
29
+ ```typescript lineNumbers
30
+ import { getWorld } from "workflow/runtime";
31
+
32
+ const world = getWorld();
33
+ const events = world.events; // [!code highlight]
34
+ ```
35
+
36
+ ## Methods
37
+
38
+ ### create()
39
+
40
+ Create a new event for a workflow run. Most commonly used to cancel a run.
41
+
42
+ ```typescript lineNumbers
43
+ await world.events.create(runId, { // [!code highlight]
44
+ eventType: "run_cancelled", // [!code highlight]
45
+ }); // [!code highlight]
46
+ ```
47
+
48
+ **Parameters:**
49
+
50
+ | Parameter | Type | Description |
51
+ |-----------|------|-------------|
52
+ | `runId` | `string` | The workflow run ID |
53
+ | `data` | `object` | Event data including `eventType` |
54
+ | `params` | `object` | Optional parameters |
55
+
56
+ **Returns:** `Event`
57
+
58
+ ### get()
59
+
60
+ Retrieve a single event by run ID and event ID.
61
+
62
+ ```typescript lineNumbers
63
+ const event = await world.events.get(runId, eventId); // [!code highlight]
64
+ ```
65
+
66
+ **Parameters:**
67
+
68
+ | Parameter | Type | Description |
69
+ |-----------|------|-------------|
70
+ | `runId` | `string` | The workflow run ID |
71
+ | `eventId` | `string` | The event ID |
72
+ | `params` | `object` | Optional parameters |
73
+
74
+ **Returns:** `Event`
75
+
76
+ ### list()
77
+
78
+ List events with cursor pagination.
79
+
80
+ ```typescript lineNumbers
81
+ const result = await world.events.list({ // [!code highlight]
82
+ runId,
83
+ pagination: { cursor },
84
+ }); // [!code highlight]
85
+ ```
86
+
87
+ **Parameters:**
88
+
89
+ | Parameter | Type | Description |
90
+ |-----------|------|-------------|
91
+ | `params.runId` | `string` | Filter events by run ID |
92
+ | `params.pagination.cursor` | `string` | Cursor for the next page |
93
+
94
+ **Returns:** `{ data: Event[], cursor?: string }`
95
+
96
+ ### listByCorrelationId()
97
+
98
+ List events that share a correlation ID, useful for tracing related events across runs.
99
+
100
+ ```typescript lineNumbers
101
+ const result = await world.events.listByCorrelationId({ // [!code highlight]
102
+ correlationId: "order-123",
103
+ }); // [!code highlight]
104
+ ```
105
+
106
+ **Parameters:**
107
+
108
+ | Parameter | Type | Description |
109
+ |-----------|------|-------------|
110
+ | `params.correlationId` | `string` | The correlation ID to filter by |
111
+ | `params.pagination.cursor` | `string` | Cursor for the next page |
112
+
113
+ **Returns:** `{ data: Event[], cursor?: string }`
114
+
115
+ ## Event Types
116
+
117
+ Events are grouped by the entity they affect:
118
+
119
+ ### Run Events
120
+
121
+ | Event Type | Description |
122
+ |-----------|-------------|
123
+ | `run_created` | Workflow run was created |
124
+ | `run_started` | Workflow run execution began |
125
+ | `run_completed` | Workflow run completed successfully |
126
+ | `run_failed` | Workflow run failed with an error |
127
+ | `run_cancelled` | Workflow run was cancelled |
128
+
129
+ ### Step Events
130
+
131
+ | Event Type | Description |
132
+ |-----------|-------------|
133
+ | `step_created` | Step was created |
134
+ | `step_started` | Step execution began |
135
+ | `step_completed` | Step completed successfully |
136
+ | `step_failed` | Step failed with an error |
137
+ | `step_retrying` | Step scheduled for retry |
138
+
139
+ ### Hook Events
140
+
141
+ | Event Type | Description |
142
+ |-----------|-------------|
143
+ | `hook_created` | Hook was created (workflow paused) |
144
+ | `hook_received` | Hook received a payload |
145
+ | `hook_disposed` | Hook was disposed (workflow reached terminal state) |
146
+ | `hook_conflict` | Hook token conflict detected |
147
+
148
+ ### Wait Events
149
+
150
+ | Event Type | Description |
151
+ |-----------|-------------|
152
+ | `wait_created` | Workflow entered a wait state (e.g., `sleep()`) |
153
+ | `wait_completed` | Wait state completed |
154
+
155
+ <Callout type="info">
156
+ Events are the append-only source of truth for all workflow state. `WorkflowRun`, `Step`, and `Hook` objects are materialized views derived from these events.
157
+ </Callout>
158
+
159
+ ## Examples
160
+
161
+ ### List Events for a Run as Audit Trail
162
+
163
+ ```typescript lineNumbers
164
+ // app/api/workflow-events/route.ts
165
+ import { getWorld } from "workflow/runtime";
166
+
167
+ export async function GET(req: Request) {
168
+ const url = new URL(req.url);
169
+ const runId = url.searchParams.get("runId");
170
+
171
+ if (!runId) {
172
+ return Response.json({ error: "runId required" }, { status: 400 });
173
+ }
174
+
175
+ const world = getWorld();
176
+ const events = await world.events.list({ runId }); // [!code highlight]
177
+
178
+ return Response.json(events);
179
+ }
180
+ ```
181
+
182
+ ### Cancel a Run via Event Creation
183
+
184
+ Cancelling a run is done by creating a `run_cancelled` event:
185
+
186
+ ```typescript lineNumbers
187
+ // app/api/workflow-runs/cancel/route.ts
188
+ import { getWorld } from "workflow/runtime";
189
+
190
+ export async function POST(req: Request) {
191
+ const { runId } = await req.json();
192
+
193
+ const world = getWorld();
194
+ await world.events.create(runId, { // [!code highlight]
195
+ eventType: "run_cancelled", // [!code highlight]
196
+ }); // [!code highlight]
197
+
198
+ return Response.json({ cancelled: true });
199
+ }
200
+ ```
201
+
202
+ <Callout type="info">
203
+ `world.runs.cancel(runId)` is a convenience wrapper around this event creation pattern. Use `world.events.create()` directly when you need to attach custom data to the cancellation event.
204
+ </Callout>
205
+
206
+ ### List Events by Correlation ID
207
+
208
+ Trace related events across workflow runs using a shared correlation ID:
209
+
210
+ ```typescript lineNumbers
211
+ import { getWorld } from "workflow/runtime";
212
+
213
+ const world = getWorld();
214
+ const events = await world.events.listByCorrelationId({ // [!code highlight]
215
+ correlationId: "order-123", // [!code highlight]
216
+ }); // [!code highlight]
217
+
218
+ for (const event of events.data) {
219
+ console.log(event.eventType, event.runId, event.createdAt);
220
+ }
221
+ ```
222
+
223
+ ## Related
224
+
225
+ - [world.runs](/docs/api-reference/workflow-api/world/runs) — Inspect runs (materialized from events)
226
+ - [world.steps](/docs/api-reference/workflow-api/world/steps) — Inspect steps (materialized from events)
227
+ - [world.hooks](/docs/api-reference/workflow-api/world/hooks) — Inspect hooks (materialized from events)
@@ -0,0 +1,181 @@
1
+ ---
2
+ title: world.hooks
3
+ description: Look up workflow hooks by ID or token for webhook resume flows and metadata inspection.
4
+ type: reference
5
+ summary: "Methods: get(), getByToken(), list(). Query hook details for resume flows."
6
+ prerequisites:
7
+ - /docs/api-reference/workflow-api/get-world
8
+ related:
9
+ - /docs/api-reference/workflow-api/world/events
10
+ - /docs/api-reference/workflow-api/resume-hook
11
+ - /docs/api-reference/workflow-api/resume-webhook
12
+ keywords:
13
+ - world.hooks
14
+ - world.hooks.get
15
+ - world.hooks.getByToken
16
+ - world.hooks.list
17
+ - Hook
18
+ - webhook token
19
+ - hook metadata
20
+ - resume flow
21
+ - pending approvals
22
+ ---
23
+
24
+ The `world.hooks` interface provides access to workflow hook data. 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 admin UIs for pending approvals.
25
+
26
+ ## Import
27
+
28
+ ```typescript lineNumbers
29
+ import { getWorld } from "workflow/runtime";
30
+
31
+ const world = getWorld();
32
+ const hooks = world.hooks; // [!code highlight]
33
+ ```
34
+
35
+ ## Methods
36
+
37
+ ### get()
38
+
39
+ Retrieve a hook by its ID.
40
+
41
+ ```typescript lineNumbers
42
+ const hook = await world.hooks.get(hookId); // [!code highlight]
43
+ ```
44
+
45
+ **Parameters:**
46
+
47
+ | Parameter | Type | Description |
48
+ |-----------|------|-------------|
49
+ | `hookId` | `string` | The hook ID |
50
+ | `params` | `object` | Optional parameters |
51
+
52
+ **Returns:** `Hook`
53
+
54
+ ### getByToken()
55
+
56
+ Look up a hook by its token. Useful in webhook resume flows where you receive a token in the callback URL.
57
+
58
+ ```typescript lineNumbers
59
+ const hook = await world.hooks.getByToken(token); // [!code highlight]
60
+ ```
61
+
62
+ **Parameters:**
63
+
64
+ | Parameter | Type | Description |
65
+ |-----------|------|-------------|
66
+ | `token` | `string` | The hook token |
67
+ | `params` | `object` | Optional parameters |
68
+
69
+ **Returns:** `Hook`
70
+
71
+ ### list()
72
+
73
+ List hooks with cursor pagination.
74
+
75
+ ```typescript lineNumbers
76
+ const result = await world.hooks.list({ // [!code highlight]
77
+ pagination: { cursor },
78
+ }); // [!code highlight]
79
+ ```
80
+
81
+ **Parameters:**
82
+
83
+ | Parameter | Type | Description |
84
+ |-----------|------|-------------|
85
+ | `params.pagination.cursor` | `string` | Cursor for the next page |
86
+
87
+ **Returns:** `{ data: Hook[], cursor?: string }`
88
+
89
+ ## Types
90
+
91
+ ### Hook
92
+
93
+ | Field | Type | Description |
94
+ |-------|------|-------------|
95
+ | `runId` | `string` | Parent workflow run ID |
96
+ | `hookId` | `string` | Unique hook identifier |
97
+ | `token` | `string` | Hook token for resuming |
98
+ | `ownerId` | `string` | Owner (team/user) ID |
99
+ | `projectId` | `string` | Project ID |
100
+ | `environment` | `string` | Deployment environment |
101
+ | `metadata` | `object` | Custom metadata attached to the hook |
102
+ | `isWebhook` | `boolean` | Whether this is a webhook-style hook |
103
+
104
+ ## Examples
105
+
106
+ ### Look Up Hook by ID
107
+
108
+ ```typescript lineNumbers
109
+ // app/api/workflow-hooks/route.ts
110
+ import { getWorld } from "workflow/runtime";
111
+
112
+ export async function GET(req: Request) {
113
+ const url = new URL(req.url);
114
+ const hookId = url.searchParams.get("hookId");
115
+
116
+ if (!hookId) {
117
+ return Response.json({ error: "hookId required" }, { status: 400 });
118
+ }
119
+
120
+ const world = getWorld();
121
+ const hook = await world.hooks.get(hookId); // [!code highlight]
122
+
123
+ return Response.json({
124
+ hookId: hook.hookId,
125
+ runId: hook.runId,
126
+ token: hook.token,
127
+ metadata: hook.metadata,
128
+ });
129
+ }
130
+ ```
131
+
132
+ ### Look Up Hook by Token for Webhook Resume
133
+
134
+ When you receive a webhook callback with a token, look up the hook to inspect metadata before resuming:
135
+
136
+ ```typescript lineNumbers
137
+ // app/api/workflow-hooks/resume/route.ts
138
+ import { getWorld } from "workflow/runtime";
139
+
140
+ export async function POST(req: Request) {
141
+ const { token } = await req.json();
142
+
143
+ const world = getWorld();
144
+ const hook = await world.hooks.getByToken(token); // [!code highlight]
145
+
146
+ // Inspect hook metadata before deciding to resume
147
+ console.log(hook.runId, hook.metadata); // [!code highlight]
148
+
149
+ return Response.json({
150
+ runId: hook.runId,
151
+ hookId: hook.hookId,
152
+ metadata: hook.metadata,
153
+ });
154
+ }
155
+ ```
156
+
157
+ ### List All Hooks for Pending Approvals Dashboard
158
+
159
+ ```typescript lineNumbers
160
+ // app/api/workflow-hooks/pending/route.ts
161
+ import { getWorld } from "workflow/runtime";
162
+
163
+ export async function GET(req: Request) {
164
+ const url = new URL(req.url);
165
+ const cursor = url.searchParams.get("cursor") ?? undefined;
166
+
167
+ const world = getWorld();
168
+ const hooks = await world.hooks.list({ // [!code highlight]
169
+ pagination: { cursor },
170
+ }); // [!code highlight]
171
+
172
+ return Response.json(hooks);
173
+ }
174
+ ```
175
+
176
+ ## Related
177
+
178
+ - [resumeHook()](/docs/api-reference/workflow-api/resume-hook) — Resume a workflow by sending a payload to a hook
179
+ - [resumeWebhook()](/docs/api-reference/workflow-api/resume-webhook) — Resume a workflow via webhook
180
+ - [getHookByToken()](/docs/api-reference/workflow-api/get-hook-by-token) — Higher-level API for hook lookup
181
+ - [Hooks](/docs/foundations/hooks) — Core concepts for hooks and pause points
@@ -0,0 +1,67 @@
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 directly via getWorld() for building observability dashboards, admin tools, and custom integrations.
6
+ prerequisites:
7
+ - /docs/api-reference/workflow-api/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 = getWorld(); // [!code highlight]
23
+ ```
24
+
25
+ ## Entities
26
+
27
+ <Cards>
28
+ <Card href="/docs/api-reference/workflow-api/world/runs" title="world.runs">
29
+ List, filter, and inspect workflow runs with pagination and status filtering.
30
+ </Card>
31
+ <Card href="/docs/api-reference/workflow-api/world/steps" title="world.steps">
32
+ List and inspect step execution data including input/output hydration.
33
+ </Card>
34
+ <Card href="/docs/api-reference/workflow-api/world/hooks" title="world.hooks">
35
+ Look up hooks by ID or token for webhook resume flows.
36
+ </Card>
37
+ <Card href="/docs/api-reference/workflow-api/world/events" title="world.events">
38
+ Query the append-only event log — the source of truth for all workflow state changes.
39
+ </Card>
40
+ <Card href="/docs/api-reference/workflow-api/world/streams" title="Streams">
41
+ Read, write, and manage real-time data streams for workflow runs.
42
+ </Card>
43
+ <Card href="/docs/api-reference/workflow-api/world/queue" title="world.queue">
44
+ Enqueue workflow runs and create queue handlers for processing.
45
+ </Card>
46
+ <Card href="/docs/api-reference/workflow-api/world/observability" title="Observability Utilities">
47
+ Hydrate step I/O, parse display names, and decrypt workflow data.
48
+ </Card>
49
+ </Cards>
50
+
51
+ <Callout type="info">
52
+ 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.
53
+ </Callout>
54
+
55
+ ## Data Hydration
56
+
57
+ 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`:
58
+
59
+ ```typescript lineNumbers
60
+ import { hydrateResourceIO, observabilityRevivers } from "workflow/observability"; // [!code highlight]
61
+
62
+ const step = await world.steps.get(runId, stepId);
63
+ const hydrated = hydrateResourceIO(step, observabilityRevivers); // [!code highlight]
64
+ console.log(hydrated.input, hydrated.output);
65
+ ```
66
+
67
+ See [Observability Utilities](/docs/api-reference/workflow-api/world/observability) for the full API.
@@ -0,0 +1,12 @@
1
+ {
2
+ "title": "World SDK",
3
+ "pages": [
4
+ "runs",
5
+ "steps",
6
+ "hooks",
7
+ "events",
8
+ "streams",
9
+ "queue",
10
+ "observability"
11
+ ]
12
+ }