workflow 4.2.0-beta.74 → 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.
@@ -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
+ }
@@ -0,0 +1,289 @@
1
+ ---
2
+ title: Observability Utilities
3
+ description: Hydrate step I/O, parse display names, and decrypt workflow data using workflow/observability.
4
+ type: reference
5
+ summary: "Functions: hydrateResourceIO(), parseStepName(), parseWorkflowName(), parseClassName(), getEncryptionKeyForRun(), hydrateResourceIOWithKey()."
6
+ prerequisites:
7
+ - /docs/api-reference/workflow-api/get-world
8
+ related:
9
+ - /docs/api-reference/workflow-api/world/steps
10
+ - /docs/api-reference/workflow-api/world/runs
11
+ keywords:
12
+ - workflow/observability
13
+ - hydrateResourceIO
14
+ - observabilityRevivers
15
+ - parseStepName
16
+ - parseWorkflowName
17
+ - parseClassName
18
+ - getEncryptionKeyForRun
19
+ - hydrateResourceIOWithKey
20
+ - data hydration
21
+ - devalue deserialization
22
+ - encryption decryption
23
+ - display name parsing
24
+ ---
25
+
26
+ The `workflow/observability` module provides utilities for working with workflow data in observability and debugging tools. It includes functions to hydrate serialized step I/O, parse machine-readable names into display-friendly formats, and decrypt encrypted workflow data.
27
+
28
+ ## Import
29
+
30
+ ```typescript lineNumbers
31
+ import { // [!code highlight]
32
+ hydrateResourceIO, // [!code highlight]
33
+ observabilityRevivers, // [!code highlight]
34
+ parseStepName, // [!code highlight]
35
+ parseWorkflowName, // [!code highlight]
36
+ parseClassName, // [!code highlight]
37
+ } from "workflow/observability"; // [!code highlight]
38
+ ```
39
+
40
+ ## Data Hydration
41
+
42
+ ### hydrateResourceIO()
43
+
44
+ Deserialize step or run data that was serialized using the [devalue](https://github.com/Rich-Harris/devalue) format. This is required to display step input/output in your UI.
45
+
46
+ ```typescript lineNumbers
47
+ import { hydrateResourceIO, observabilityRevivers } from "workflow/observability"; // [!code highlight]
48
+ import { getWorld } from "workflow/runtime";
49
+
50
+ const world = getWorld();
51
+ const step = await world.steps.get(runId, stepId);
52
+
53
+ const hydrated = hydrateResourceIO(step, observabilityRevivers); // [!code highlight]
54
+ console.log(hydrated.input); // Deserialized input data
55
+ console.log(hydrated.output); // Deserialized output data
56
+ ```
57
+
58
+ **Parameters:**
59
+
60
+ | Parameter | Type | Description |
61
+ |-----------|------|-------------|
62
+ | `resource` | `Step \| WorkflowRun` | The step or run with serialized data |
63
+ | `revivers` | `Revivers` | Reviver functions for deserialization. Use `observabilityRevivers` for standard use. |
64
+
65
+ **Returns:** The resource with hydrated `input` and `output` fields.
66
+
67
+ ### observabilityRevivers
68
+
69
+ A set of reviver functions that handle standard workflow serialization types (Date, Map, Set, Error, etc.).
70
+
71
+ ```typescript lineNumbers
72
+ import { observabilityRevivers } from "workflow/observability";
73
+ ```
74
+
75
+ ## Name Parsing
76
+
77
+ Workflow and step names are stored as machine-readable identifiers. These utilities extract display-friendly names.
78
+
79
+ ### parseStepName()
80
+
81
+ Parse a machine-readable step name into its components.
82
+
83
+ ```typescript lineNumbers
84
+ import { parseStepName } from "workflow/observability"; // [!code highlight]
85
+
86
+ const parsed = parseStepName("step//./src/workflows/order//processPayment"); // [!code highlight]
87
+ // parsed.shortName → "processPayment"
88
+ // parsed.moduleSpecifier → "./src/workflows/order"
89
+ ```
90
+
91
+ **Parameters:**
92
+
93
+ | Parameter | Type | Description |
94
+ |-----------|------|-------------|
95
+ | `stepName` | `string` | The machine-readable step name |
96
+
97
+ **Returns:** `{ shortName: string, moduleSpecifier: string } | null`
98
+
99
+ ### parseWorkflowName()
100
+
101
+ Parse a machine-readable workflow name into its components.
102
+
103
+ ```typescript lineNumbers
104
+ import { parseWorkflowName } from "workflow/observability"; // [!code highlight]
105
+
106
+ const parsed = parseWorkflowName("workflow//./src/workflows/order//processOrder"); // [!code highlight]
107
+ // parsed.shortName → "processOrder"
108
+ // parsed.moduleSpecifier → "./src/workflows/order"
109
+ ```
110
+
111
+ **Parameters:**
112
+
113
+ | Parameter | Type | Description |
114
+ |-----------|------|-------------|
115
+ | `workflowName` | `string` | The machine-readable workflow name |
116
+
117
+ **Returns:** `{ shortName: string, moduleSpecifier: string } | null`
118
+
119
+ ### parseClassName()
120
+
121
+ Parse a machine-readable class name into its components.
122
+
123
+ ```typescript lineNumbers
124
+ import { parseClassName } from "workflow/observability"; // [!code highlight]
125
+
126
+ const parsed = parseClassName("class//./src/models//User"); // [!code highlight]
127
+ // parsed.shortName → "User"
128
+ // parsed.moduleSpecifier → "./src/models"
129
+ ```
130
+
131
+ **Parameters:**
132
+
133
+ | Parameter | Type | Description |
134
+ |-----------|------|-------------|
135
+ | `className` | `string` | The machine-readable class name |
136
+
137
+ **Returns:** `{ shortName: string, moduleSpecifier: string } | null`
138
+
139
+ ## Encryption
140
+
141
+ For workflows with encrypted step data, use these utilities to decrypt before hydrating.
142
+
143
+ ### getEncryptionKeyForRun()
144
+
145
+ Retrieve the encryption key used for a specific workflow run.
146
+
147
+ {/* @expect-error:2305 */}
148
+ ```typescript lineNumbers
149
+ import { getEncryptionKeyForRun } from "workflow/observability"; // [!code highlight]
150
+
151
+ const key = await getEncryptionKeyForRun(runId); // [!code highlight]
152
+ ```
153
+
154
+ **Parameters:**
155
+
156
+ | Parameter | Type | Description |
157
+ |-----------|------|-------------|
158
+ | `runId` | `string` | The workflow run ID |
159
+
160
+ **Returns:** Encryption key for the run
161
+
162
+ ### hydrateResourceIOWithKey()
163
+
164
+ Hydrate step or run data using a decryption key. Use this instead of `hydrateResourceIO()` when data is encrypted.
165
+
166
+ {/* @expect-error:2305,2724 */}
167
+ ```typescript lineNumbers
168
+ import { // [!code highlight]
169
+ getEncryptionKeyForRun, // [!code highlight]
170
+ hydrateResourceIOWithKey, // [!code highlight]
171
+ } from "workflow/observability"; // [!code highlight]
172
+
173
+ const key = await getEncryptionKeyForRun(runId); // [!code highlight]
174
+ const hydrated = hydrateResourceIOWithKey(step, key); // [!code highlight]
175
+ ```
176
+
177
+ **Parameters:**
178
+
179
+ | Parameter | Type | Description |
180
+ |-----------|------|-------------|
181
+ | `resource` | `Step \| WorkflowRun` | The step or run with encrypted serialized data |
182
+ | `key` | `EncryptionKey` | The encryption key from `getEncryptionKeyForRun()` |
183
+
184
+ **Returns:** The resource with decrypted and hydrated `input` and `output` fields.
185
+
186
+ ## Examples
187
+
188
+ ### Hydrate Step Input and Output Data
189
+
190
+ ```typescript lineNumbers
191
+ // app/api/workflow-steps/hydrate/route.ts
192
+ import { getWorld } from "workflow/runtime";
193
+ import { // [!code highlight]
194
+ hydrateResourceIO, // [!code highlight]
195
+ observabilityRevivers, // [!code highlight]
196
+ parseStepName, // [!code highlight]
197
+ } from "workflow/observability"; // [!code highlight]
198
+
199
+ export async function GET(req: Request) {
200
+ const url = new URL(req.url);
201
+ const runId = url.searchParams.get("runId");
202
+ const stepId = url.searchParams.get("stepId");
203
+
204
+ if (!runId || !stepId) {
205
+ return Response.json({ error: "runId and stepId required" }, { status: 400 });
206
+ }
207
+
208
+ const world = getWorld();
209
+ const step = await world.steps.get(runId, stepId);
210
+
211
+ const hydrated = hydrateResourceIO(step, observabilityRevivers); // [!code highlight]
212
+ const parsed = parseStepName(step.stepName);
213
+
214
+ return Response.json({
215
+ displayName: parsed?.shortName ?? step.stepName,
216
+ input: hydrated.input, // [!code highlight]
217
+ output: hydrated.output, // [!code highlight]
218
+ });
219
+ }
220
+ ```
221
+
222
+ ### Decrypt and Hydrate Encrypted Step Data
223
+
224
+ For teams with encryption enabled, step data must be decrypted before hydration:
225
+
226
+ {/* @expect-error:2305,2724 */}
227
+ ```typescript lineNumbers
228
+ // app/api/workflow-steps/decrypt/route.ts
229
+ import { getWorld } from "workflow/runtime";
230
+ import { // [!code highlight]
231
+ getEncryptionKeyForRun, // [!code highlight]
232
+ hydrateResourceIOWithKey, // [!code highlight]
233
+ parseStepName, // [!code highlight]
234
+ } from "workflow/observability"; // [!code highlight]
235
+
236
+ export async function GET(req: Request) {
237
+ const url = new URL(req.url);
238
+ const runId = url.searchParams.get("runId");
239
+ const stepId = url.searchParams.get("stepId");
240
+
241
+ if (!runId || !stepId) {
242
+ return Response.json({ error: "runId and stepId required" }, { status: 400 });
243
+ }
244
+
245
+ const world = getWorld();
246
+ const step = await world.steps.get(runId, stepId);
247
+
248
+ // Decrypt then hydrate // [!code highlight]
249
+ const key = await getEncryptionKeyForRun(runId); // [!code highlight]
250
+ const hydrated = hydrateResourceIOWithKey(step, key); // [!code highlight]
251
+
252
+ const parsed = parseStepName(step.stepName);
253
+
254
+ return Response.json({
255
+ displayName: parsed?.shortName ?? step.stepName,
256
+ input: hydrated.input,
257
+ output: hydrated.output,
258
+ });
259
+ }
260
+ ```
261
+
262
+ ### Parse Display Names for a Run's Steps
263
+
264
+ Build a progress dashboard with human-readable step names:
265
+
266
+ ```typescript lineNumbers
267
+ import { getWorld } from "workflow/runtime";
268
+ import { parseStepName, parseWorkflowName } from "workflow/observability"; // [!code highlight]
269
+
270
+ const world = getWorld();
271
+
272
+ // Parse workflow name
273
+ const run = await world.runs.get(runId, { resolveData: "none" });
274
+ const workflowDisplay = parseWorkflowName(run.workflowName); // [!code highlight]
275
+ console.log("Workflow:", workflowDisplay?.shortName); // [!code highlight]
276
+
277
+ // Parse step names
278
+ const steps = await world.steps.list({ runId, resolveData: "none" });
279
+ for (const step of steps.data) {
280
+ const stepDisplay = parseStepName(step.stepName); // [!code highlight]
281
+ console.log(` ${stepDisplay?.shortName}: ${step.status}`); // [!code highlight]
282
+ }
283
+ ```
284
+
285
+ ## Related
286
+
287
+ - [world.steps](/docs/api-reference/workflow-api/world/steps) — Query step data to hydrate
288
+ - [world.runs](/docs/api-reference/workflow-api/world/runs) — Query run data to hydrate
289
+ - [Serialization](/docs/foundations/serialization) — How workflow data is serialized
@@ -0,0 +1,127 @@
1
+ ---
2
+ title: world.queue
3
+ description: Enqueue workflow runs and create queue handlers for background processing.
4
+ type: reference
5
+ summary: "Methods: getDeploymentId(), queue(), createQueueHandler(). Manage workflow run queuing and processing."
6
+ prerequisites:
7
+ - /docs/api-reference/workflow-api/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
+ - background processing
17
+ - enqueue workflow
18
+ - ValidQueueName
19
+ ---
20
+
21
+ The `world.queue` interface provides access to workflow run queuing and processing. Use it to enqueue runs for background execution and create handlers to process queued items.
22
+
23
+ ## Import
24
+
25
+ ```typescript lineNumbers
26
+ import { getWorld } from "workflow/runtime";
27
+
28
+ const world = getWorld();
29
+ const queue = world.queue; // [!code highlight]
30
+ ```
31
+
32
+ ## Methods
33
+
34
+ ### getDeploymentId()
35
+
36
+ Get the current deployment ID. Useful for routing queue messages to the correct deployment.
37
+
38
+ ```typescript lineNumbers
39
+ const deploymentId = await world.queue.getDeploymentId(); // [!code highlight]
40
+ ```
41
+
42
+ **Returns:** `string` — The current deployment ID
43
+
44
+ ### queue()
45
+
46
+ Enqueue a workflow run for background processing.
47
+
48
+ ```typescript lineNumbers
49
+ const messageId = await world.queue.queue(name, message, opts); // [!code highlight]
50
+ ```
51
+
52
+ **Parameters:**
53
+
54
+ | Parameter | Type | Description |
55
+ |-----------|------|-------------|
56
+ | `name` | `ValidQueueName` | The queue name |
57
+ | `message` | `object` | The message payload to enqueue |
58
+ | `opts` | `object` | Optional configuration |
59
+
60
+ **Returns:** `MessageId`
61
+
62
+ ### createQueueHandler()
63
+
64
+ Create a handler function for processing queued messages.
65
+
66
+ ```typescript lineNumbers
67
+ const handler = world.queue.createQueueHandler(prefix, callback); // [!code highlight]
68
+ ```
69
+
70
+ **Parameters:**
71
+
72
+ | Parameter | Type | Description |
73
+ |-----------|------|-------------|
74
+ | `prefix` | `string` | Queue name prefix to match |
75
+ | `callback` | `function` | Handler function called for each queued message |
76
+
77
+ **Returns:** Queue handler function
78
+
79
+ ## Examples
80
+
81
+ ### Enqueue a Workflow Run for Background Processing
82
+
83
+ ```typescript lineNumbers
84
+ // app/api/workflow-queue/route.ts
85
+ import { getWorld } from "workflow/runtime";
86
+
87
+ export async function POST(req: Request) {
88
+ const { workflowName, input } = await req.json();
89
+
90
+ const world = getWorld();
91
+ const messageId = await world.queue.queue(workflowName, { // [!code highlight]
92
+ input,
93
+ priority: "normal",
94
+ }); // [!code highlight]
95
+
96
+ return Response.json({ messageId });
97
+ }
98
+ ```
99
+
100
+ ### Create a Queue Handler for Processing
101
+
102
+ ```typescript lineNumbers
103
+ import { getWorld } from "workflow/runtime";
104
+
105
+ const world = getWorld();
106
+
107
+ const handler = world.queue.createQueueHandler("my-workflows", async (message) => { // [!code highlight]
108
+ console.log("Processing:", message);
109
+ // Handle the queued workflow message
110
+ }); // [!code highlight]
111
+ ```
112
+
113
+ ### Get Current Deployment ID
114
+
115
+ ```typescript lineNumbers
116
+ import { getWorld } from "workflow/runtime";
117
+
118
+ const world = getWorld();
119
+ const deploymentId = await world.queue.getDeploymentId(); // [!code highlight]
120
+ console.log("Running on deployment:", deploymentId);
121
+ ```
122
+
123
+ ## Related
124
+
125
+ - [start()](/docs/api-reference/workflow-api/start) — Higher-level API for starting workflow runs
126
+ - [Starting Workflows](/docs/foundations/starting-workflows) — Core concepts for workflow invocation
127
+ - [world.runs](/docs/api-reference/workflow-api/world/runs) — Inspect queued and running workflows