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.
- package/README.md +6 -6
- package/docs/ai/defining-tools.mdx +2 -2
- package/docs/ai/human-in-the-loop.mdx +1 -1
- package/docs/ai/index.mdx +8 -8
- package/docs/ai/resumable-streams.mdx +1 -1
- package/docs/ai/sleep-and-delays.mdx +2 -2
- package/docs/ai/streaming-updates-from-tools.mdx +1 -1
- package/docs/api-reference/index.mdx +9 -3
- package/docs/api-reference/meta.json +10 -1
- package/docs/api-reference/workflow/create-webhook.mdx +4 -0
- package/docs/api-reference/workflow/index.mdx +2 -2
- package/docs/api-reference/workflow-ai/durable-agent.mdx +1 -1
- package/docs/api-reference/workflow-api/get-world.mdx +33 -157
- package/docs/api-reference/workflow-api/index.mdx +3 -0
- package/docs/api-reference/workflow-api/world/events.mdx +227 -0
- package/docs/api-reference/workflow-api/world/hooks.mdx +181 -0
- package/docs/api-reference/workflow-api/world/index.mdx +67 -0
- package/docs/api-reference/workflow-api/world/meta.json +12 -0
- package/docs/api-reference/workflow-api/world/observability.mdx +289 -0
- package/docs/api-reference/workflow-api/world/queue.mdx +127 -0
- package/docs/api-reference/workflow-api/world/runs.mdx +223 -0
- package/docs/api-reference/workflow-api/world/steps.mdx +216 -0
- package/docs/api-reference/workflow-api/world/streams.mdx +152 -0
- package/docs/api-reference/workflow-globals.mdx +102 -0
- package/docs/api-reference/workflow-next/index.mdx +1 -1
- package/docs/api-reference/workflow-serde/index.mdx +2 -2
- package/docs/changelog/index.mdx +2 -2
- package/docs/deploying/building-a-world.mdx +1 -1
- package/docs/deploying/world/vercel-world.mdx +20 -13
- package/docs/errors/index.mdx +1 -1
- package/docs/errors/node-js-module-in-workflow.mdx +1 -1
- package/docs/errors/serialization-failed.mdx +1 -1
- package/docs/errors/start-invalid-workflow-function.mdx +3 -3
- package/docs/foundations/errors-and-retries.mdx +1 -1
- package/docs/foundations/hooks.mdx +5 -1
- package/docs/foundations/serialization.mdx +2 -2
- package/docs/foundations/streaming.mdx +3 -2
- package/docs/foundations/workflows-and-steps.mdx +2 -2
- package/docs/getting-started/astro.mdx +5 -5
- package/docs/getting-started/express.mdx +5 -5
- package/docs/getting-started/fastify.mdx +5 -5
- package/docs/getting-started/hono.mdx +5 -5
- package/docs/getting-started/nestjs.mdx +5 -5
- package/docs/getting-started/next.mdx +5 -5
- package/docs/getting-started/nitro.mdx +5 -5
- package/docs/getting-started/nuxt.mdx +5 -5
- package/docs/getting-started/sveltekit.mdx +5 -5
- package/docs/getting-started/vite.mdx +5 -5
- package/docs/how-it-works/code-transform.mdx +6 -6
- package/docs/how-it-works/encryption.mdx +3 -3
- package/docs/how-it-works/event-sourcing.mdx +5 -5
- package/docs/how-it-works/framework-integrations.mdx +9 -9
- package/docs/how-it-works/understanding-directives.mdx +11 -11
- package/docs/observability/index.mdx +5 -5
- package/docs/testing/index.mdx +4 -4
- package/package.json +12 -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
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: world.runs
|
|
3
|
+
description: List, filter, and inspect workflow runs with cursor pagination and status filtering.
|
|
4
|
+
type: reference
|
|
5
|
+
summary: "Methods: get(), list(). Query workflow runs by status, paginate results, and inspect run metadata."
|
|
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/events
|
|
11
|
+
- /docs/api-reference/workflow-api/get-run
|
|
12
|
+
keywords:
|
|
13
|
+
- world.runs
|
|
14
|
+
- world.runs.get
|
|
15
|
+
- world.runs.list
|
|
16
|
+
- WorkflowRun
|
|
17
|
+
- cursor pagination
|
|
18
|
+
- run status
|
|
19
|
+
- resolveData
|
|
20
|
+
- parseWorkflowName
|
|
21
|
+
- list workflow runs
|
|
22
|
+
- filter runs
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
The `world.runs` interface provides direct access to workflow run data. Use it to list runs with pagination, filter by status, and inspect individual run metadata.
|
|
26
|
+
|
|
27
|
+
## Import
|
|
28
|
+
|
|
29
|
+
```typescript lineNumbers
|
|
30
|
+
import { getWorld } from "workflow/runtime";
|
|
31
|
+
|
|
32
|
+
const world = getWorld();
|
|
33
|
+
const runs = world.runs; // [!code highlight]
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Methods
|
|
37
|
+
|
|
38
|
+
### get()
|
|
39
|
+
|
|
40
|
+
Retrieve a single workflow run by ID.
|
|
41
|
+
|
|
42
|
+
```typescript lineNumbers
|
|
43
|
+
const run = await world.runs.get(runId); // [!code highlight]
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
**Parameters:**
|
|
47
|
+
|
|
48
|
+
| Parameter | Type | Description |
|
|
49
|
+
|-----------|------|-------------|
|
|
50
|
+
| `runId` | `string` | The workflow run ID |
|
|
51
|
+
| `params.resolveData` | `'all' \| 'none'` | Whether to hydrate input/output data. Default: `'all'` |
|
|
52
|
+
|
|
53
|
+
**Returns:** `WorkflowRun`
|
|
54
|
+
|
|
55
|
+
### list()
|
|
56
|
+
|
|
57
|
+
List workflow runs with cursor pagination.
|
|
58
|
+
|
|
59
|
+
```typescript lineNumbers
|
|
60
|
+
const result = await world.runs.list({ // [!code highlight]
|
|
61
|
+
pagination: { cursor },
|
|
62
|
+
}); // [!code highlight]
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**Parameters:**
|
|
66
|
+
|
|
67
|
+
| Parameter | Type | Description |
|
|
68
|
+
|-----------|------|-------------|
|
|
69
|
+
| `params.pagination.cursor` | `string` | Cursor for the next page |
|
|
70
|
+
| `params.resolveData` | `'all' \| 'none'` | Whether to hydrate input/output data |
|
|
71
|
+
|
|
72
|
+
**Returns:** `{ data: WorkflowRun[], cursor?: string }`
|
|
73
|
+
|
|
74
|
+
### cancel()
|
|
75
|
+
|
|
76
|
+
Cancel a running workflow. This is a convenience method that creates a `run_cancelled` event.
|
|
77
|
+
|
|
78
|
+
```typescript lineNumbers
|
|
79
|
+
const run = await world.runs.cancel(runId); // [!code highlight]
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
**Parameters:**
|
|
83
|
+
|
|
84
|
+
| Parameter | Type | Description |
|
|
85
|
+
|-----------|------|-------------|
|
|
86
|
+
| `runId` | `string` | The workflow run ID to cancel |
|
|
87
|
+
|
|
88
|
+
**Returns:** `WorkflowRun`
|
|
89
|
+
|
|
90
|
+
<Callout type="info">
|
|
91
|
+
Cancellation works by creating an event with `eventType: 'run_cancelled'`. See [world.events](/docs/api-reference/workflow-api/world/events) for the full event creation API.
|
|
92
|
+
</Callout>
|
|
93
|
+
|
|
94
|
+
## Types
|
|
95
|
+
|
|
96
|
+
### WorkflowRun
|
|
97
|
+
|
|
98
|
+
| Field | Type | Description |
|
|
99
|
+
|-------|------|-------------|
|
|
100
|
+
| `runId` | `string` | Unique run identifier |
|
|
101
|
+
| `status` | `string` | Run status: `'running'`, `'completed'`, `'failed'`, `'cancelled'` |
|
|
102
|
+
| `workflowName` | `string` | Machine-readable workflow identifier |
|
|
103
|
+
| `input` | `any` | Workflow input data (when `resolveData: 'all'`) |
|
|
104
|
+
| `output` | `any` | Workflow output data (when `resolveData: 'all'`) |
|
|
105
|
+
| `error` | `any` | Error data if the run failed |
|
|
106
|
+
| `startedAt` | `string` | ISO timestamp when the run started |
|
|
107
|
+
| `completedAt` | `string \| null` | ISO timestamp when the run completed |
|
|
108
|
+
| `specVersion` | `number` | Workflow spec version |
|
|
109
|
+
|
|
110
|
+
<Callout type="warn">
|
|
111
|
+
The `workflowName` field contains a machine-readable identifier like `workflow//./src/workflows/order//processOrder`. Use `parseWorkflowName()` from `workflow/observability` to extract a display-friendly name.
|
|
112
|
+
</Callout>
|
|
113
|
+
|
|
114
|
+
## Examples
|
|
115
|
+
|
|
116
|
+
### List Workflow Runs with Cursor Pagination
|
|
117
|
+
|
|
118
|
+
```typescript lineNumbers
|
|
119
|
+
// app/api/workflow-runs/route.ts
|
|
120
|
+
import { getWorld } from "workflow/runtime";
|
|
121
|
+
|
|
122
|
+
export async function GET(req: Request) {
|
|
123
|
+
const url = new URL(req.url);
|
|
124
|
+
const cursor = url.searchParams.get("cursor") ?? undefined;
|
|
125
|
+
|
|
126
|
+
const world = getWorld(); // [!code highlight]
|
|
127
|
+
const runs = await world.runs.list({ // [!code highlight]
|
|
128
|
+
pagination: { cursor }, // [!code highlight]
|
|
129
|
+
}); // [!code highlight]
|
|
130
|
+
|
|
131
|
+
return Response.json(runs);
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Get a Single Run with Full Data
|
|
136
|
+
|
|
137
|
+
Use `resolveData: 'all'` (the default) to fetch the complete run including input and output:
|
|
138
|
+
|
|
139
|
+
```typescript lineNumbers
|
|
140
|
+
// app/api/workflow-runs/[runId]/route.ts
|
|
141
|
+
import { getWorld } from "workflow/runtime";
|
|
142
|
+
|
|
143
|
+
export async function GET(req: Request) {
|
|
144
|
+
const url = new URL(req.url);
|
|
145
|
+
const runId = url.searchParams.get("runId");
|
|
146
|
+
|
|
147
|
+
if (!runId) {
|
|
148
|
+
return Response.json({ error: "runId required" }, { status: 400 });
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const world = getWorld();
|
|
152
|
+
const run = await world.runs.get(runId, { // [!code highlight]
|
|
153
|
+
resolveData: "all", // [!code highlight]
|
|
154
|
+
}); // [!code highlight]
|
|
155
|
+
|
|
156
|
+
return Response.json({
|
|
157
|
+
runId: run.runId,
|
|
158
|
+
status: run.status,
|
|
159
|
+
input: run.input,
|
|
160
|
+
output: run.output,
|
|
161
|
+
startedAt: run.startedAt,
|
|
162
|
+
completedAt: run.completedAt,
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Get Run without Data for Lightweight Status Checks
|
|
168
|
+
|
|
169
|
+
Use `resolveData: 'none'` when you only need status metadata:
|
|
170
|
+
|
|
171
|
+
```typescript lineNumbers
|
|
172
|
+
import { getWorld } from "workflow/runtime";
|
|
173
|
+
|
|
174
|
+
const world = getWorld();
|
|
175
|
+
const run = await world.runs.get(runId, { // [!code highlight]
|
|
176
|
+
resolveData: "none", // Skip input/output for performance // [!code highlight]
|
|
177
|
+
}); // [!code highlight]
|
|
178
|
+
|
|
179
|
+
console.log(run.status); // 'running' | 'completed' | 'failed' | 'cancelled'
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Parse Workflow Display Name from Machine-Readable ID
|
|
183
|
+
|
|
184
|
+
```typescript lineNumbers
|
|
185
|
+
import { getWorld } from "workflow/runtime";
|
|
186
|
+
import { parseWorkflowName } from "workflow/observability"; // [!code highlight]
|
|
187
|
+
|
|
188
|
+
const world = getWorld();
|
|
189
|
+
const runs = await world.runs.list({});
|
|
190
|
+
|
|
191
|
+
for (const run of runs.data) {
|
|
192
|
+
const parsed = parseWorkflowName(run.workflowName); // [!code highlight]
|
|
193
|
+
console.log(parsed?.shortName); // e.g., "processOrder" // [!code highlight]
|
|
194
|
+
console.log(parsed?.moduleSpecifier); // e.g., "./src/workflows/order"
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Cancel a Running Workflow
|
|
199
|
+
|
|
200
|
+
```typescript lineNumbers
|
|
201
|
+
// app/api/workflow-runs/cancel/route.ts
|
|
202
|
+
import { getWorld } from "workflow/runtime";
|
|
203
|
+
|
|
204
|
+
export async function POST(req: Request) {
|
|
205
|
+
const { runId } = await req.json();
|
|
206
|
+
|
|
207
|
+
if (!runId) {
|
|
208
|
+
return Response.json({ error: "runId required" }, { status: 400 });
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const world = getWorld();
|
|
212
|
+
const run = await world.runs.cancel(runId); // [!code highlight]
|
|
213
|
+
|
|
214
|
+
return Response.json({ status: run.status });
|
|
215
|
+
}
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## Related
|
|
219
|
+
|
|
220
|
+
- [world.steps](/docs/api-reference/workflow-api/world/steps) — Inspect individual step execution within a run
|
|
221
|
+
- [world.events](/docs/api-reference/workflow-api/world/events) — Query the event log for a run
|
|
222
|
+
- [getRun()](/docs/api-reference/workflow-api/get-run) — Higher-level API for working with individual runs
|
|
223
|
+
- [Observability Utilities](/docs/api-reference/workflow-api/world/observability) — Parse workflow names and hydrate data
|