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
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<a href="https://useworkflow.dev">
|
|
3
3
|
<picture>
|
|
4
4
|
<source media="(prefers-color-scheme: dark)" srcset="https://useworkflow.dev/workflow-circle-symbol-dark.svg">
|
|
5
|
-
<img alt="Workflow
|
|
5
|
+
<img alt="Workflow SDK logo" src="https://useworkflow.dev/workflow-circle-symbol-light.svg" height="128">
|
|
6
6
|
</picture>
|
|
7
7
|
</a>
|
|
8
8
|
<h1>Workflow Development Kit</h1>
|
|
@@ -22,15 +22,15 @@ Visit [https://useworkflow.dev](https://useworkflow.dev) to view the full docume
|
|
|
22
22
|
|
|
23
23
|
## Community
|
|
24
24
|
|
|
25
|
-
The Workflow
|
|
25
|
+
The Workflow SDK community can be found on [GitHub Discussions](https://github.com/vercel/workflow/discussions), where you can ask questions, voice ideas, and share your projects with other people.
|
|
26
26
|
|
|
27
27
|
## Contributing
|
|
28
28
|
|
|
29
|
-
Contributions to Workflow
|
|
29
|
+
Contributions to Workflow SDK are welcome and highly appreciated. Please use GitHub [issues](https://github.com/vercel/workflow/issues) and [discussions](https://github.com/vercel/workflow/discussions) to collaborate with the team and wider community.
|
|
30
30
|
|
|
31
31
|
## Author list
|
|
32
32
|
|
|
33
|
-
Workflow
|
|
33
|
+
Workflow SDK was built by engineers at [Vercel](https://vercel.com) and the [Open Source Community](https://github.com/vercel/workflow/graphs/contributors).
|
|
34
34
|
|
|
35
35
|
The initial core contributing engineers are:
|
|
36
36
|
|
|
@@ -42,12 +42,12 @@ The initial core contributing engineers are:
|
|
|
42
42
|
- Peter Wielander ([@VaguelySerious](https://github.com/VaguelySerious))
|
|
43
43
|
- Pranay Prakash ([@pranaygp](https://github.com/pranaygp))
|
|
44
44
|
|
|
45
|
-
The Workflow
|
|
45
|
+
The Workflow SDK logo was designed by Cecilio Ruiz [@ceciliorz](https://x.com/ceciliorz)
|
|
46
46
|
|
|
47
47
|
---
|
|
48
48
|
|
|
49
49
|
## Security
|
|
50
50
|
|
|
51
|
-
If you believe you have found a security vulnerability in Workflow
|
|
51
|
+
If you believe you have found a security vulnerability in Workflow SDK, we encourage you to **_responsibly disclose this and not open a public issue_**.
|
|
52
52
|
|
|
53
53
|
To participate in our Open Source Software Bug Bounty program, please email [responsible.disclosure@vercel.com](mailto:responsible.disclosure@vercel.com). We will add you to the program and provide further instructions for submitting your report.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: Patterns for Defining Tools
|
|
3
|
-
description: Common patterns for defining tools in durable AI agents using Workflow
|
|
3
|
+
description: Common patterns for defining tools in durable AI agents using Workflow SDK.
|
|
4
4
|
type: guide
|
|
5
5
|
summary: Define step-level and workflow-level tools for durable AI agents with stream writing and context access.
|
|
6
6
|
prerequisites:
|
|
@@ -12,7 +12,7 @@ related:
|
|
|
12
12
|
- /docs/api-reference/workflow/get-writable
|
|
13
13
|
---
|
|
14
14
|
|
|
15
|
-
This page covers the details for some common patterns when defining tools for AI agents using Workflow
|
|
15
|
+
This page covers the details for some common patterns when defining tools for AI agents using Workflow SDK.
|
|
16
16
|
|
|
17
17
|
Using DurableAgent, we model most tools as steps. These can be anything from a simple function call to a entire multi-day long workflow.
|
|
18
18
|
|
|
@@ -15,7 +15,7 @@ related:
|
|
|
15
15
|
|
|
16
16
|
A common pre-requisite for running AI agents in production is the ability to wait for human input or external events before proceeding.
|
|
17
17
|
|
|
18
|
-
Workflow
|
|
18
|
+
Workflow SDK's [webhook](/docs/api-reference/workflow/create-webhook) and [hook](/docs/api-reference/workflow/define-hook) primitives enable "human-in-the-loop" patterns where workflows pause until a human takes action, allowing smooth resumption of workflows even after days of inactivity, and provides stability across code deployments.
|
|
19
19
|
|
|
20
20
|
If you need to react to external events programmatically, see the [hooks](/docs/foundations/hooks) documentation for more information. This part of the guide will focus on the human-in-the-loop pattern, which is a subset of the more general hook pattern.
|
|
21
21
|
|
package/docs/ai/index.mdx
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
title: Building Durable AI Agents
|
|
3
3
|
description: Build AI agents that survive crashes, scale across requests, and maintain state with durable LLM tool-call loops.
|
|
4
4
|
type: overview
|
|
5
|
-
summary: Convert a basic AI chat app into a durable, resumable agent using Workflow
|
|
5
|
+
summary: Convert a basic AI chat app into a durable, resumable agent using Workflow SDK.
|
|
6
6
|
related:
|
|
7
7
|
- /docs/foundations/workflows-and-steps
|
|
8
8
|
- /docs/foundations/streaming
|
|
@@ -15,11 +15,11 @@ related:
|
|
|
15
15
|
|
|
16
16
|
AI agents are built on the primitive of LLM and tool-call loops, often with additional processes for data fetching, resource provisioning, or reacting to external events.
|
|
17
17
|
|
|
18
|
-
Workflow
|
|
18
|
+
Workflow SDK makes your agents production-ready, by turning them into durable, resumable workflows. It transforms your LLM calls, tool executions, and other async operations into retryable, scalable, and observable steps.
|
|
19
19
|
|
|
20
20
|
<AgentTraces />
|
|
21
21
|
|
|
22
|
-
This guide walks you through converting a basic AI chat app into a durable AI agent using Workflow
|
|
22
|
+
This guide walks you through converting a basic AI chat app into a durable AI agent using Workflow SDK.
|
|
23
23
|
|
|
24
24
|
## Why Durable Agents?
|
|
25
25
|
|
|
@@ -30,20 +30,20 @@ Aside from the usual challenges of getting your long-running tasks to be product
|
|
|
30
30
|
- **Resumability**: Resuming streams requires not just storing your messages, but also storing streams, and piping them across services.
|
|
31
31
|
- **Human-in-the-loop**: Your client, API, and async job orchestration need to work together to create, track, route to, and display human approval requests, or similar webhook operations.
|
|
32
32
|
|
|
33
|
-
Workflow
|
|
33
|
+
Workflow SDK provides all of these capabilities out of the box. Your agent becomes a workflow, your tools become steps, and the framework handles interplay with your existing infrastructure.
|
|
34
34
|
|
|
35
35
|
## Getting Started
|
|
36
36
|
|
|
37
37
|
To make an Agent durable, we first need an Agent, which we'll be setting up here. If you already have an app you'd like to follow along with, you can skip this section.
|
|
38
38
|
|
|
39
|
-
For our example, we'll need an app with a simple chat interface and an API route calling an LLM, so that we can add Workflow
|
|
39
|
+
For our example, we'll need an app with a simple chat interface and an API route calling an LLM, so that we can add Workflow SDK to it. We'll use the [Flight Booking Agent](https://github.com/vercel/workflow-examples/tree/main/flight-booking-app) example as a starting point, which comes with a chat interface built using Next.js, AI SDK, and Shadcn UI.
|
|
40
40
|
|
|
41
41
|
<Steps>
|
|
42
42
|
|
|
43
43
|
<Step>
|
|
44
44
|
### Clone example app
|
|
45
45
|
|
|
46
|
-
We'll need an app with a simple chat interface and an API route calling an LLM, so that we can add Workflow
|
|
46
|
+
We'll need an app with a simple chat interface and an API route calling an LLM, so that we can add Workflow SDK to it. For the follow-along steps, we'll use the [Flight Booking Agent](https://github.com/vercel/workflow-examples/tree/main/flight-booking-app) example as a starting point, which comes with a chat interface built using Next.js, AI SDK, and Shadcn UI.
|
|
47
47
|
|
|
48
48
|
If you have your own project, you can skip this step, and simply apply the changes of the following steps to your own project.
|
|
49
49
|
|
|
@@ -219,7 +219,7 @@ export default function ChatPage() {
|
|
|
219
219
|
|
|
220
220
|
</Steps>
|
|
221
221
|
|
|
222
|
-
## Integrating Workflow
|
|
222
|
+
## Integrating Workflow SDK
|
|
223
223
|
|
|
224
224
|
Now that we have a basic agent using AI SDK, we can modify it to make it durable.
|
|
225
225
|
|
|
@@ -228,7 +228,7 @@ Now that we have a basic agent using AI SDK, we can modify it to make it durable
|
|
|
228
228
|
|
|
229
229
|
### Install Dependencies
|
|
230
230
|
|
|
231
|
-
Add the Workflow
|
|
231
|
+
Add the Workflow SDK packages to your project:
|
|
232
232
|
|
|
233
233
|
```package-install
|
|
234
234
|
npm i workflow @workflow/ai
|
|
@@ -16,7 +16,7 @@ When building chat interfaces, it's common to run into network interruptions, pa
|
|
|
16
16
|
|
|
17
17
|
Where a standard chat implementation would require the user to resend their message and wait for the entire response again, workflow runs are durable, and so are the streams attached to them. This means a stream can be resumed at any point, optionally only syncing the data that was missed since the last connection.
|
|
18
18
|
|
|
19
|
-
Resumable streams come out of the box with Workflow
|
|
19
|
+
Resumable streams come out of the box with Workflow SDK, however, the client needs to recognize that a stream exists, and needs to know which stream to reconnect to, and needs to know where to start from. For this, Workflow SDK provides the [`WorkflowChatTransport`](/docs/api-reference/workflow-ai/workflow-chat-transport) helper, a drop-in transport for the AI SDK that handles client-side resumption logic for you.
|
|
20
20
|
|
|
21
21
|
## Implementing stream resumption
|
|
22
22
|
|
|
@@ -14,7 +14,7 @@ related:
|
|
|
14
14
|
|
|
15
15
|
AI agents sometimes need to pause execution in order to schedule recurring or future actions, wait before retrying an operation (e.g. for rate limiting), or wait for external state to be available.
|
|
16
16
|
|
|
17
|
-
Workflow
|
|
17
|
+
Workflow SDK's `sleep` function enables Agents to pause execution without consuming resources, and resume at a specified time, after a specified duration, or in response to an external event. Workflow operation that suspend will survive restarts, new deploys, and infrastructure changes, independent of whether the suspense takes seconds or months.
|
|
18
18
|
|
|
19
19
|
<Callout type="info">
|
|
20
20
|
See the [`sleep()` API Reference](/docs/api-reference/workflow/sleep) for the full list of supported duration formats and detailed API documentation, and see the [hooks](/docs/foundations/hooks) documentation for more information on how to resume in response to external events.
|
|
@@ -22,7 +22,7 @@ See the [`sleep()` API Reference](/docs/api-reference/workflow/sleep) for the fu
|
|
|
22
22
|
|
|
23
23
|
## Adding a Sleep Tool
|
|
24
24
|
|
|
25
|
-
Sleep is a built-in function in Workflow
|
|
25
|
+
Sleep is a built-in function in Workflow SDK, so exposing it as a tool is as simple as wrapping it in a tool definition. Learn more about how to define tools in [Patterns for Defining Tools](/docs/ai/defining-tools).
|
|
26
26
|
|
|
27
27
|
<Steps>
|
|
28
28
|
|
|
@@ -14,7 +14,7 @@ related:
|
|
|
14
14
|
|
|
15
15
|
After [building a durable AI agent](/docs/ai), we already get UI message chunks for displaying tool invocations and return values. However, for long-running steps, we may want to show progress updates, or stream step output to the user while it's being generated.
|
|
16
16
|
|
|
17
|
-
Workflow
|
|
17
|
+
Workflow SDK enables this by letting step functions write custom chunks to the same stream the agent uses. These chunks appear as data parts in your messages, which you can render however you like.
|
|
18
18
|
|
|
19
19
|
As an example, we'll extend out Flight Booking Agent to use emit more granular progress updates while searching for flights.
|
|
20
20
|
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: API Reference
|
|
3
|
-
description: Complete reference for all Workflow
|
|
3
|
+
description: Complete reference for all Workflow SDK functions and primitives by package.
|
|
4
4
|
type: overview
|
|
5
5
|
summary: Browse all available functions and primitives organized by package.
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
All the functions and primitives that come with Workflow
|
|
8
|
+
All the functions and primitives that come with Workflow SDK by package.
|
|
9
9
|
|
|
10
10
|
<Cards>
|
|
11
|
+
<Card title="Workflow Globals" href="/docs/api-reference/workflow-globals">
|
|
12
|
+
Global APIs available inside workflow functions, including deterministic APIs, Web Platform APIs, and environment variables.
|
|
13
|
+
</Card>
|
|
11
14
|
<Card title="workflow" href="/docs/api-reference/workflow">
|
|
12
15
|
Core workflow primitives including steps, context management, streaming, webhooks, and error handling.
|
|
13
16
|
</Card>
|
|
@@ -15,7 +18,10 @@ All the functions and primitives that come with Workflow DevKit by package.
|
|
|
15
18
|
API reference for runtime functions from the `workflow/api` package.
|
|
16
19
|
</Card>
|
|
17
20
|
<Card title="workflow/next" href="/docs/api-reference/workflow-next">
|
|
18
|
-
Next.js integration for Workflow
|
|
21
|
+
Next.js integration for Workflow SDK that automatically configures bundling and runtime support.
|
|
22
|
+
</Card>
|
|
23
|
+
<Card title="workflow/errors" href="/docs/api-reference/workflow-errors">
|
|
24
|
+
Semantic error types for handling workflow storage backend failures.
|
|
19
25
|
</Card>
|
|
20
26
|
<Card title="@workflow/serde" href="/docs/api-reference/workflow-serde">
|
|
21
27
|
Serialization symbols for custom class serialization in workflows.
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"title": "API Reference",
|
|
3
|
-
"pages": [
|
|
3
|
+
"pages": [
|
|
4
|
+
"workflow-globals",
|
|
5
|
+
"workflow",
|
|
6
|
+
"workflow-api",
|
|
7
|
+
"workflow-next",
|
|
8
|
+
"workflow-errors",
|
|
9
|
+
"workflow-serde",
|
|
10
|
+
"workflow-ai",
|
|
11
|
+
"vitest"
|
|
12
|
+
]
|
|
4
13
|
}
|
|
@@ -13,6 +13,10 @@ Creates a webhook that can be used to suspend and resume a workflow run upon rec
|
|
|
13
13
|
|
|
14
14
|
Webhooks provide a way for external systems to send HTTP requests directly to your workflow. Unlike hooks which accept arbitrary payloads, webhooks work with standard HTTP `Request` objects and can return HTTP `Response` objects.
|
|
15
15
|
|
|
16
|
+
<Callout type="warn">
|
|
17
|
+
`createWebhook()` creates a public endpoint at `/.well-known/workflow/v1/webhook/:token`, and the token in that URL is the only authorization performed for incoming requests resuming that webhook. This is convenient for prototypes and simple resume links because it avoids creating another route, but if you need stronger security, prefer [`createHook()`](/docs/api-reference/workflow/create-hook) behind your own route and authorize the request before calling [`resumeHook()`](/docs/api-reference/workflow-api/resume-hook) to avoid unauthenticated workflow resumptions.
|
|
18
|
+
</Callout>
|
|
19
|
+
|
|
16
20
|
```ts lineNumbers
|
|
17
21
|
import { createWebhook } from "workflow"
|
|
18
22
|
|
|
@@ -20,7 +20,7 @@ npm i workflow
|
|
|
20
20
|
|
|
21
21
|
## Functions
|
|
22
22
|
|
|
23
|
-
Workflow
|
|
23
|
+
Workflow SDK contains the following functions you can use inside your workflow functions:
|
|
24
24
|
|
|
25
25
|
<Cards>
|
|
26
26
|
<Card href="/docs/api-reference/workflow/get-workflow-metadata" title="getWorkflowMetadata()">
|
|
@@ -51,7 +51,7 @@ Workflow DevKit contains the following functions you can use inside your workflo
|
|
|
51
51
|
|
|
52
52
|
## Error Classes
|
|
53
53
|
|
|
54
|
-
Workflow
|
|
54
|
+
Workflow SDK includes error classes that can be thrown in a workflow or step to change the error exit strategy of a workflow.
|
|
55
55
|
|
|
56
56
|
<Cards>
|
|
57
57
|
<Card href="/docs/api-reference/workflow/fatal-error" title="FatalError()">
|
|
@@ -204,7 +204,7 @@ export default OutputSpecification;`}
|
|
|
204
204
|
- **Durable Execution**: Agents can be interrupted and resumed without losing state
|
|
205
205
|
- **Flexible Tool Implementation**: Tools can be implemented as workflow steps for automatic retries, or as regular workflow-level logic
|
|
206
206
|
- **Stream Processing**: Handles streaming responses and tool calls in a structured way
|
|
207
|
-
- **Workflow Native**: Fully integrated with Workflow
|
|
207
|
+
- **Workflow Native**: Fully integrated with Workflow SDK for production-grade reliability
|
|
208
208
|
- **AI SDK Parity**: Supports the same options as AI SDK's `streamText` including generation settings, callbacks, and structured output
|
|
209
209
|
|
|
210
210
|
## Good to Know
|
|
@@ -14,7 +14,7 @@ Use this function when you need direct access to the underlying workflow infrast
|
|
|
14
14
|
```typescript lineNumbers
|
|
15
15
|
import { getWorld } from "workflow/runtime";
|
|
16
16
|
|
|
17
|
-
const world = getWorld();
|
|
17
|
+
const world = getWorld(); // [!code highlight]
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
## API Signature
|
|
@@ -34,167 +34,43 @@ export default World;`}
|
|
|
34
34
|
showSections={["returns"]}
|
|
35
35
|
/>
|
|
36
36
|
|
|
37
|
-
##
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
### Cancel a Workflow Run
|
|
67
|
-
|
|
68
|
-
Cancel a running workflow:
|
|
69
|
-
|
|
70
|
-
```typescript lineNumbers
|
|
71
|
-
import { getWorld } from "workflow/runtime";
|
|
72
|
-
|
|
73
|
-
export async function POST(req: Request) {
|
|
74
|
-
const { runId } = await req.json();
|
|
75
|
-
|
|
76
|
-
if (!runId) {
|
|
77
|
-
return Response.json({ error: "No runId provided" }, { status: 400 });
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
try {
|
|
81
|
-
const world = getWorld(); // [!code highlight]
|
|
82
|
-
const run = await world.runs.cancel(runId); // [!code highlight]
|
|
83
|
-
|
|
84
|
-
return Response.json({ status: run.status });
|
|
85
|
-
} catch (error) {
|
|
86
|
-
return Response.json(
|
|
87
|
-
{ error: "Failed to cancel workflow run" },
|
|
88
|
-
{ status: 500 }
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
### List Steps for a Run (Without Data)
|
|
95
|
-
|
|
96
|
-
List steps for a workflow run with `resolveData: 'none'` to efficiently get step metadata without fetching serialized input/output. Use `parseStepName` to extract user-friendly display names:
|
|
37
|
+
## World SDK
|
|
38
|
+
|
|
39
|
+
The World object provides access to several entity interfaces. See the [World SDK](/docs/api-reference/workflow-api/world) reference for complete documentation:
|
|
40
|
+
|
|
41
|
+
<Cards>
|
|
42
|
+
<Card href="/docs/api-reference/workflow-api/world/runs" title="world.runs">
|
|
43
|
+
List, filter, and inspect workflow runs.
|
|
44
|
+
</Card>
|
|
45
|
+
<Card href="/docs/api-reference/workflow-api/world/steps" title="world.steps">
|
|
46
|
+
List and inspect step execution data.
|
|
47
|
+
</Card>
|
|
48
|
+
<Card href="/docs/api-reference/workflow-api/world/hooks" title="world.hooks">
|
|
49
|
+
Look up hooks by ID or token.
|
|
50
|
+
</Card>
|
|
51
|
+
<Card href="/docs/api-reference/workflow-api/world/events" title="world.events">
|
|
52
|
+
Query the append-only event log.
|
|
53
|
+
</Card>
|
|
54
|
+
<Card href="/docs/api-reference/workflow-api/world/streams" title="world.streams">
|
|
55
|
+
Read, write, and manage data streams.
|
|
56
|
+
</Card>
|
|
57
|
+
<Card href="/docs/api-reference/workflow-api/world/queue" title="world.queue">
|
|
58
|
+
Enqueue runs and create queue handlers.
|
|
59
|
+
</Card>
|
|
60
|
+
</Cards>
|
|
61
|
+
|
|
62
|
+
## Data Hydration
|
|
63
|
+
|
|
64
|
+
Step and run data is serialized using the [devalue](https://github.com/Rich-Harris/devalue) format. Use `workflow/observability` to hydrate it for display:
|
|
97
65
|
|
|
98
66
|
```typescript lineNumbers
|
|
99
|
-
import {
|
|
100
|
-
import { parseStepName } from "@workflow/utils/parse-name"; // [!code highlight]
|
|
101
|
-
|
|
102
|
-
export async function GET(req: Request) {
|
|
103
|
-
const url = new URL(req.url);
|
|
104
|
-
const runId = url.searchParams.get("runId");
|
|
105
|
-
|
|
106
|
-
if (!runId) {
|
|
107
|
-
return Response.json({ error: "No runId provided" }, { status: 400 });
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
try {
|
|
111
|
-
const world = getWorld(); // [!code highlight]
|
|
112
|
-
const steps = await world.steps.list({ // [!code highlight]
|
|
113
|
-
runId, // [!code highlight]
|
|
114
|
-
resolveData: "none", // Skip fetching input/output for performance // [!code highlight]
|
|
115
|
-
}); // [!code highlight]
|
|
116
|
-
|
|
117
|
-
// Map steps to a progress view using parseStepName for display
|
|
118
|
-
const progress = steps.data.map((step) => {
|
|
119
|
-
const parsed = parseStepName(step.stepName); // [!code highlight]
|
|
120
|
-
return {
|
|
121
|
-
stepId: step.stepId,
|
|
122
|
-
// Use shortName for UI display (e.g., "fetchUserData") // [!code highlight]
|
|
123
|
-
displayName: parsed?.shortName ?? step.stepName, // [!code highlight]
|
|
124
|
-
// Module info available for debugging // [!code highlight]
|
|
125
|
-
module: parsed?.moduleSpecifier, // [!code highlight]
|
|
126
|
-
status: step.status,
|
|
127
|
-
startedAt: step.startedAt,
|
|
128
|
-
completedAt: step.completedAt,
|
|
129
|
-
};
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
return Response.json({ progress, cursor: steps.cursor });
|
|
133
|
-
} catch (error) {
|
|
134
|
-
return Response.json(
|
|
135
|
-
{ error: "Failed to list steps" },
|
|
136
|
-
{ status: 500 }
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
### Get Step with Hydrated Input/Output
|
|
143
|
-
|
|
144
|
-
Retrieve a step with its serialized data and hydrate it for display. This example shows how to decrypt and deserialize step input/output:
|
|
67
|
+
import { hydrateResourceIO, observabilityRevivers } from "workflow/observability"; // [!code highlight]
|
|
145
68
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
import { parseStepName } from "@workflow/utils/parse-name"; // [!code highlight]
|
|
149
|
-
import { // [!code highlight]
|
|
150
|
-
hydrateResourceIO, // [!code highlight]
|
|
151
|
-
observabilityRevivers, // [!code highlight]
|
|
152
|
-
} from "@workflow/core/serialization-format"; // [!code highlight]
|
|
153
|
-
|
|
154
|
-
export async function GET(req: Request) {
|
|
155
|
-
const url = new URL(req.url);
|
|
156
|
-
const runId = url.searchParams.get("runId");
|
|
157
|
-
const stepId = url.searchParams.get("stepId");
|
|
158
|
-
|
|
159
|
-
if (!runId || !stepId) {
|
|
160
|
-
return Response.json({ error: "runId and stepId required" }, { status: 400 });
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
try {
|
|
164
|
-
const world = getWorld(); // [!code highlight]
|
|
165
|
-
// Fetch step with data (default resolveData behavior) // [!code highlight]
|
|
166
|
-
const step = await world.steps.get(runId, stepId); // [!code highlight]
|
|
167
|
-
|
|
168
|
-
// Hydrate serialized input/output for display // [!code highlight]
|
|
169
|
-
const hydrated = hydrateResourceIO(step, observabilityRevivers); // [!code highlight]
|
|
170
|
-
|
|
171
|
-
// Parse the stepName for user-friendly display
|
|
172
|
-
const parsed = parseStepName(step.stepName);
|
|
173
|
-
|
|
174
|
-
return Response.json({
|
|
175
|
-
stepId: hydrated.stepId,
|
|
176
|
-
displayName: parsed?.shortName ?? step.stepName, // [!code highlight]
|
|
177
|
-
module: parsed?.moduleSpecifier, // [!code highlight]
|
|
178
|
-
status: hydrated.status,
|
|
179
|
-
attempt: hydrated.attempt,
|
|
180
|
-
// Hydrated input/output ready for rendering // [!code highlight]
|
|
181
|
-
input: hydrated.input, // [!code highlight]
|
|
182
|
-
output: hydrated.output, // [!code highlight]
|
|
183
|
-
});
|
|
184
|
-
} catch (error) {
|
|
185
|
-
return Response.json(
|
|
186
|
-
{ error: "Step not found" },
|
|
187
|
-
{ status: 404 }
|
|
188
|
-
);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
69
|
+
const step = await world.steps.get(runId, stepId);
|
|
70
|
+
const hydrated = hydrateResourceIO(step, observabilityRevivers); // [!code highlight]
|
|
191
71
|
```
|
|
192
72
|
|
|
193
|
-
|
|
194
|
-
The `stepName` field contains a machine-readable identifier like `step//./src/workflows/order//processPayment`.
|
|
195
|
-
Use `parseStepName()` from `@workflow/utils/parse-name` to extract the `shortName` (e.g., `"processPayment"`)
|
|
196
|
-
and `moduleSpecifier` for display in your UI.
|
|
197
|
-
</Callout>
|
|
73
|
+
See [Observability Utilities](/docs/api-reference/workflow-api/world/observability) for the full hydration, parsing, and encryption API.
|
|
198
74
|
|
|
199
75
|
## Related Functions
|
|
200
76
|
|
|
@@ -30,4 +30,7 @@ The API package is for access and introspection of workflow data to inspect runs
|
|
|
30
30
|
<Card href="/docs/api-reference/workflow-api/get-world" title="getWorld()">
|
|
31
31
|
Get direct access to workflow storage, queuing, and streaming backends.
|
|
32
32
|
</Card>
|
|
33
|
+
<Card href="/docs/api-reference/workflow-api/world" title="World SDK">
|
|
34
|
+
Low-level API for inspecting runs, steps, events, hooks, streams, and queues.
|
|
35
|
+
</Card>
|
|
33
36
|
</Cards>
|