workflow 4.2.0-beta.72 → 4.2.0-beta.74
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/index.mdx +2 -2
- package/docs/api-reference/workflow-ai/durable-agent.mdx +1 -1
- 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/postgres-world.mdx +7 -0
- 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 +1 -1
- package/docs/foundations/serialization.mdx +2 -2
- package/docs/foundations/streaming.mdx +2 -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 +5 -5
- package/package.json +11 -11
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
|
}
|
|
@@ -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
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Workflow Globals
|
|
3
|
+
description: Global APIs available inside workflow functions.
|
|
4
|
+
type: reference
|
|
5
|
+
summary: Reference of all global APIs available inside workflow functions.
|
|
6
|
+
prerequisites:
|
|
7
|
+
- /docs/foundations/workflows-and-steps
|
|
8
|
+
related:
|
|
9
|
+
- /docs/errors/node-js-module-in-workflow
|
|
10
|
+
- /docs/errors/fetch-in-workflow
|
|
11
|
+
- /docs/errors/timeout-in-workflow
|
|
12
|
+
- /docs/how-it-works/code-transform
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
Workflow functions run in a restricted environment that prevents access to non-deterministic or side-effecting APIs. This page lists all global APIs available inside `"use workflow"` functions.
|
|
16
|
+
|
|
17
|
+
For full Node.js runtime access, use [step functions](/docs/foundations/workflows-and-steps#step-functions).
|
|
18
|
+
|
|
19
|
+
## Deterministic APIs
|
|
20
|
+
|
|
21
|
+
These APIs are available but are **seeded or fixed** to ensure deterministic behavior across replays.
|
|
22
|
+
|
|
23
|
+
| API | Behavior |
|
|
24
|
+
|-----|----------|
|
|
25
|
+
| [`Math.random()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random) | Seeded random number generator — same seed produces the same sequence every replay |
|
|
26
|
+
| [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) / `Date.now()` / `new Date()` | Returns a fixed timestamp that advances with the workflow's logical clock |
|
|
27
|
+
| [`crypto.getRandomValues()`](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues) | Seeded — produces deterministic output for a given workflow run |
|
|
28
|
+
| [`crypto.randomUUID()`](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/randomUUID) | Seeded — produces deterministic UUIDs for a given workflow run |
|
|
29
|
+
| [`crypto.subtle.digest()`](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest) | Passes through to the real implementation (SHA-256, etc. are deterministic by nature) |
|
|
30
|
+
|
|
31
|
+
<Callout type="info">
|
|
32
|
+
You can safely use `Math.random()`, `Date.now()`, and `crypto.randomUUID()` in workflow functions. The framework ensures these return the same values across replays.
|
|
33
|
+
</Callout>
|
|
34
|
+
|
|
35
|
+
## Web Platform APIs
|
|
36
|
+
|
|
37
|
+
These standard Web APIs are available in workflow functions:
|
|
38
|
+
|
|
39
|
+
- [`Headers`](https://developer.mozilla.org/en-US/docs/Web/API/Headers)
|
|
40
|
+
- [`TextEncoder`](https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder) / [`TextDecoder`](https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder)
|
|
41
|
+
- [`URL`](https://developer.mozilla.org/en-US/docs/Web/API/URL) / [`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams)
|
|
42
|
+
- [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request) / [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) — custom implementations with [special behavior in the workflow context](/docs/foundations/serialization#request--response). Body methods like `.json()` and `.text()` are automatically treated as step invocations.
|
|
43
|
+
- [`console`](https://developer.mozilla.org/en-US/docs/Web/API/console)
|
|
44
|
+
- [`structuredClone`](https://developer.mozilla.org/en-US/docs/Web/API/Window/structuredClone)
|
|
45
|
+
- [`atob`](https://developer.mozilla.org/en-US/docs/Web/API/Window/atob) / [`btoa`](https://developer.mozilla.org/en-US/docs/Web/API/Window/btoa)
|
|
46
|
+
|
|
47
|
+
## Environment Variables
|
|
48
|
+
|
|
49
|
+
`process.env` is available as a **read-only, frozen** snapshot of the environment variables at the time the workflow was started. You cannot modify it.
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
export async function myWorkflow() {
|
|
53
|
+
"use workflow";
|
|
54
|
+
|
|
55
|
+
const apiKey = process.env.API_KEY; // works
|
|
56
|
+
process.env.FOO = "bar"; // throws — process.env is frozen
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Binary Data
|
|
61
|
+
|
|
62
|
+
Standard JavaScript typed arrays (`Uint8Array`, `Int32Array`, `Float64Array`, etc.) are available in workflow functions.
|
|
63
|
+
|
|
64
|
+
### Base64 and hex encoding
|
|
65
|
+
|
|
66
|
+
The workflow environment provides [`Uint8Array` base64 and hex methods](https://tc39.es/proposal-arraybuffer-base64/) for encoding and decoding binary data:
|
|
67
|
+
|
|
68
|
+
{/* @skip-typecheck: polyfilled methods not available in host TypeScript */}
|
|
69
|
+
```typescript
|
|
70
|
+
// Encode to base64
|
|
71
|
+
const bytes = new Uint8Array([72, 101, 108, 108, 111]);
|
|
72
|
+
bytes.toBase64(); // "SGVsbG8="
|
|
73
|
+
bytes.toBase64({ alphabet: "base64url" }); // URL-safe variant
|
|
74
|
+
bytes.toBase64({ omitPadding: true }); // "SGVsbG8"
|
|
75
|
+
|
|
76
|
+
// Decode from base64
|
|
77
|
+
Uint8Array.fromBase64("SGVsbG8="); // Uint8Array([72, 101, 108, 108, 111])
|
|
78
|
+
|
|
79
|
+
// Encode to hex
|
|
80
|
+
bytes.toHex(); // "48656c6c6f"
|
|
81
|
+
|
|
82
|
+
// Decode from hex
|
|
83
|
+
Uint8Array.fromHex("48656c6c6f"); // Uint8Array([72, 101, 108, 108, 111])
|
|
84
|
+
|
|
85
|
+
// Write into an existing array
|
|
86
|
+
const target = new Uint8Array(5);
|
|
87
|
+
target.setFromBase64("SGVsbG8="); // { read: 8, written: 5 }
|
|
88
|
+
target.setFromHex("48656c6c6f"); // { read: 10, written: 5 }
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
<Callout type="info">
|
|
92
|
+
These methods are polyfilled in the workflow environment. When the JavaScript runtime ships native support, the polyfill is automatically bypassed.
|
|
93
|
+
</Callout>
|
|
94
|
+
|
|
95
|
+
## Not Available
|
|
96
|
+
|
|
97
|
+
The following are **not available** in workflow functions. Move this logic to [step functions](/docs/foundations/workflows-and-steps#step-functions) instead.
|
|
98
|
+
|
|
99
|
+
- **Node.js core modules**: `fs`, `path`, `http`, `https`, `net`, `dns`, `child_process`, `cluster`, `os`, `stream`, `crypto` (Node.js version), etc. See [node-js-module-in-workflow](/docs/errors/node-js-module-in-workflow).
|
|
100
|
+
- **Global `fetch`**: Use [`import { fetch } from "workflow"`](/docs/api-reference/workflow/fetch) instead. See [fetch-in-workflow](/docs/errors/fetch-in-workflow).
|
|
101
|
+
- **Timers**: `setTimeout`, `setInterval`, `setImmediate`, and their `clear*` counterparts. Use [`sleep()`](/docs/api-reference/workflow/sleep) instead. See [timeout-in-workflow](/docs/errors/timeout-in-workflow).
|
|
102
|
+
- **`Buffer`**: Node.js-specific API. Use `Uint8Array` with `toBase64()` / `fromBase64()` / `toHex()` / `fromHex()` for binary data encoding, or `atob()` / `btoa()` for string-based base64.
|
|
@@ -7,7 +7,7 @@ related:
|
|
|
7
7
|
- /docs/getting-started/next
|
|
8
8
|
---
|
|
9
9
|
|
|
10
|
-
Next.js integration for Workflow
|
|
10
|
+
Next.js integration for Workflow SDK that automatically configures bundling and runtime support.
|
|
11
11
|
|
|
12
12
|
## Functions
|
|
13
13
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
title: "@workflow/serde"
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
-
Serialization symbols for custom class serialization in Workflow
|
|
5
|
+
Serialization symbols for custom class serialization in Workflow SDK.
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
@@ -12,7 +12,7 @@ npm i @workflow/serde
|
|
|
12
12
|
|
|
13
13
|
## Overview
|
|
14
14
|
|
|
15
|
-
By default, Workflow
|
|
15
|
+
By default, Workflow SDK can serialize standard JavaScript types like primitives, objects, arrays, `Date`, `Map`, `Set`, and more. However, custom class instances are not serializable by default because the serialization system doesn't know how to reconstruct them.
|
|
16
16
|
|
|
17
17
|
The `@workflow/serde` package provides two symbols that allow you to define custom serialization and deserialization logic for your classes, enabling them to be passed between workflow and step functions.
|
|
18
18
|
|
package/docs/changelog/index.mdx
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: Changelog
|
|
3
|
-
description: Latest updates and new features in Workflow
|
|
3
|
+
description: Latest updates and new features in Workflow SDK.
|
|
4
4
|
type: overview
|
|
5
5
|
---
|
|
6
6
|
|
|
7
7
|
# Changelog
|
|
8
8
|
|
|
9
|
-
Stay up to date with the latest changes to Workflow
|
|
9
|
+
Stay up to date with the latest changes to Workflow SDK.
|
|
10
10
|
|
|
11
11
|
---
|
|
12
12
|
|
|
@@ -214,7 +214,7 @@ Study these implementations for guidance:
|
|
|
214
214
|
|
|
215
215
|
## Testing Your World
|
|
216
216
|
|
|
217
|
-
Workflow
|
|
217
|
+
Workflow SDK includes an E2E test suite that validates World implementations. Once your World is published to npm:
|
|
218
218
|
|
|
219
219
|
1. Add your world to [`worlds-manifest.json`](https://github.com/vercel/workflow/blob/main/worlds-manifest.json)
|
|
220
220
|
2. Open a PR to the Workflow repository
|
|
@@ -160,6 +160,12 @@ Prefix for graphile-worker queue job names. Useful when sharing a database betwe
|
|
|
160
160
|
|
|
161
161
|
Number of concurrent workers polling for jobs. Default: `10`
|
|
162
162
|
|
|
163
|
+
### `WORKFLOW_POSTGRES_MAX_POOL_SIZE`
|
|
164
|
+
|
|
165
|
+
Maximum size of the internal `pg.Pool` used when `createWorld()` constructs the pool. Default: `10`
|
|
166
|
+
|
|
167
|
+
For higher worker concurrency, Graphile Worker recommends setting `maxPoolSize` to `10` or `queueConcurrency + 2`, whichever is larger.
|
|
168
|
+
|
|
163
169
|
### Programmatic configuration
|
|
164
170
|
|
|
165
171
|
{/* @skip-typecheck: incomplete code sample */}
|
|
@@ -170,6 +176,7 @@ const world = createWorld({
|
|
|
170
176
|
connectionString: "postgres://user:password@host:5432/database",
|
|
171
177
|
jobPrefix: "myapp_",
|
|
172
178
|
queueConcurrency: 20,
|
|
179
|
+
maxPoolSize: 20, // overrides WORKFLOW_POSTGRES_MAX_POOL_SIZE
|
|
173
180
|
});
|
|
174
181
|
```
|
|
175
182
|
|
|
@@ -23,8 +23,6 @@ Deploy your application to Vercel:
|
|
|
23
23
|
vercel deploy
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
<FluidComputeCallout />
|
|
27
|
-
|
|
28
26
|
That's it. Vercel automatically:
|
|
29
27
|
|
|
30
28
|
- Selects the Vercel World backend
|
|
@@ -32,6 +30,24 @@ That's it. Vercel automatically:
|
|
|
32
30
|
- Provisions storage and queuing infrastructure
|
|
33
31
|
- Isolates data per environment (production, preview, development)
|
|
34
32
|
|
|
33
|
+
<FluidComputeCallout />
|
|
34
|
+
|
|
35
|
+
## Vercel platform documentation
|
|
36
|
+
|
|
37
|
+
For complete details on pricing, usage limits, and included allotments on Vercel, see the official Vercel documentation:
|
|
38
|
+
|
|
39
|
+
- **[Vercel Workflow](https://vercel.com/docs/workflow)** — Pricing details, concepts, and observability for Workflow on Vercel
|
|
40
|
+
- **[Vercel limits](https://vercel.com/docs/limits)** — Platform-wide limits including Workflow-specific constraints
|
|
41
|
+
- **[Vercel Hobby plan](https://vercel.com/docs/plans/hobby)** — Free tier included usage for Workflow and other resources
|
|
42
|
+
|
|
43
|
+
For self-hosted deployments, use the [Postgres World](/worlds/postgres). For local development, use the [Local World](/worlds/local).
|
|
44
|
+
|
|
45
|
+
## Limitations
|
|
46
|
+
|
|
47
|
+
- **Single-region deployment** - The backend infrastructure is currently deployed only in `iad1`. Applications in other regions will route workflow requests to `iad1`, which may result in higher latency. For best performance, deploy your Vercel apps using Workflow to `iad1`. Global deployment is planned to colocate the backend closer to your applications.
|
|
48
|
+
|
|
49
|
+
- **Data residency** - The Vercel World is currently deployed in the `iad1` region. This means independently of the deployment location of your application, the data for your workflows will be stored in the `iad1` region.
|
|
50
|
+
|
|
35
51
|
## Observability
|
|
36
52
|
|
|
37
53
|
Workflow observability is built into the Vercel dashboard on your project page. It respects your existing authentication and project permission settings.
|
|
@@ -97,7 +113,8 @@ Custom base URL for the Vercel workflow API. Automatically detected.
|
|
|
97
113
|
|
|
98
114
|
### Programmatic configuration
|
|
99
115
|
|
|
100
|
-
{
|
|
116
|
+
{/*@skip-typecheck: incomplete code sample*/}
|
|
117
|
+
|
|
101
118
|
```typescript title="workflow.config.ts" lineNumbers
|
|
102
119
|
import { createVercelWorld } from "@workflow/world-vercel";
|
|
103
120
|
|
|
@@ -131,13 +148,3 @@ The Vercel World uses Vercel's infrastructure for workflow execution:
|
|
|
131
148
|
- **Authentication** - OIDC tokens provide secure, automatic authentication
|
|
132
149
|
|
|
133
150
|
For more details, see the [Vercel Workflow documentation](https://vercel.com/docs/workflow).
|
|
134
|
-
|
|
135
|
-
## Pricing and More
|
|
136
|
-
|
|
137
|
-
See the [Vercel Workflow documentation](https://vercel.com/docs/workflow) for current pricing and to learn more.
|
|
138
|
-
|
|
139
|
-
For self-hosted deployments, use the [Postgres World](/worlds/postgres). For local development, use the [Local World](/worlds/local).
|
|
140
|
-
|
|
141
|
-
## Limitations
|
|
142
|
-
|
|
143
|
-
- **Single-region deployment** - The backend infrastructure is currently deployed only in `iad1`. Applications in other regions will route workflow requests to `iad1`, which may result in higher latency. For best performance, deploy your Vercel apps using Workflow to `iad1`. Global deployment is planned to colocate the backend closer to your applications.
|
package/docs/errors/index.mdx
CHANGED
|
@@ -7,7 +7,7 @@ related:
|
|
|
7
7
|
- /docs/foundations/errors-and-retries
|
|
8
8
|
---
|
|
9
9
|
|
|
10
|
-
Fix common mistakes when creating and executing workflows in the **Workflow
|
|
10
|
+
Fix common mistakes when creating and executing workflows in the **Workflow SDK**.
|
|
11
11
|
|
|
12
12
|
<Cards>
|
|
13
13
|
<Card href="/docs/errors/fetch-in-workflow" title="fetch-in-workflow">
|
|
@@ -76,5 +76,5 @@ These common Node.js core modules cannot be used in workflow functions:
|
|
|
76
76
|
- Streams: `stream` (use Web Streams API instead)
|
|
77
77
|
|
|
78
78
|
<Callout type="info">
|
|
79
|
-
You can use Web Platform APIs in workflow functions (like `Headers`, `crypto.randomUUID()`, `Response`, etc.), since these are available in the sandboxed environment.
|
|
79
|
+
You can use Web Platform APIs in workflow functions (like `Headers`, `crypto.randomUUID()`, `Response`, etc.), since these are available in the sandboxed environment. See [Workflow Globals](/docs/api-reference/workflow-globals) for the full list.
|
|
80
80
|
</Callout>
|
|
@@ -109,7 +109,7 @@ async function greetStep(userData: { name: string }) {
|
|
|
109
109
|
|
|
110
110
|
## Supported Serializable Types
|
|
111
111
|
|
|
112
|
-
Workflow
|
|
112
|
+
Workflow SDK supports these types across execution boundaries:
|
|
113
113
|
|
|
114
114
|
### Standard JSON Types
|
|
115
115
|
|
|
@@ -9,18 +9,18 @@ related:
|
|
|
9
9
|
- /docs/api-reference/workflow-api/start
|
|
10
10
|
---
|
|
11
11
|
|
|
12
|
-
This error occurs when you try to call `start()` with a function that is not a valid workflow function or when the Workflow
|
|
12
|
+
This error occurs when you try to call `start()` with a function that is not a valid workflow function or when the Workflow SDK is not configured correctly.
|
|
13
13
|
|
|
14
14
|
## Error Message
|
|
15
15
|
|
|
16
16
|
```
|
|
17
|
-
'start' received an invalid workflow function. Ensure the Workflow
|
|
17
|
+
'start' received an invalid workflow function. Ensure the Workflow SDK
|
|
18
18
|
is configured correctly and the function includes a 'use workflow' directive.
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
## Why This Happens
|
|
22
22
|
|
|
23
|
-
The `start()` function expects a workflow function that has been properly processed by Workflow
|
|
23
|
+
The `start()` function expects a workflow function that has been properly processed by Workflow SDK's build system. During the build process, workflow functions are transformed and marked with special metadata that `start()` uses to identify and execute them.
|
|
24
24
|
|
|
25
25
|
This error typically happens when:
|
|
26
26
|
|
|
@@ -10,7 +10,7 @@ related:
|
|
|
10
10
|
- /docs/api-reference/workflow/retryable-error
|
|
11
11
|
---
|
|
12
12
|
|
|
13
|
-
By default, errors thrown inside steps are retried. Additionally, Workflow
|
|
13
|
+
By default, errors thrown inside steps are retried. Additionally, Workflow SDK provides two new types of errors you can use to customize retries.
|
|
14
14
|
|
|
15
15
|
## Default Retrying
|
|
16
16
|
|
|
@@ -219,7 +219,7 @@ While hooks are powerful, they require you to manually handle HTTP requests and
|
|
|
219
219
|
2. Provides an automatically addressable `url` property pointing to the generated webhook endpoint
|
|
220
220
|
3. Handles sending HTTP [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) objects back to the caller
|
|
221
221
|
|
|
222
|
-
When using Workflow
|
|
222
|
+
When using Workflow SDK, webhooks are automatically wired up at `/.well-known/workflow/v1/webhook/:token` without any additional setup.
|
|
223
223
|
|
|
224
224
|
<Callout type="info">
|
|
225
225
|
See the full API reference for [`createWebhook()`](/docs/api-reference/workflow/create-webhook) for all available options.
|
|
@@ -9,7 +9,7 @@ related:
|
|
|
9
9
|
- /docs/errors/serialization-failed
|
|
10
10
|
---
|
|
11
11
|
|
|
12
|
-
All function arguments and return values passed between workflow and step functions must be serializable. Workflow
|
|
12
|
+
All function arguments and return values passed between workflow and step functions must be serializable. Workflow SDK uses a custom serialization system built on top of [devalue](https://github.com/sveltejs/devalue). This system supports standard JSON types, as well as a few additional popular Web API types.
|
|
13
13
|
|
|
14
14
|
<Callout type="info">
|
|
15
15
|
The serialization system ensures that all data persists correctly across workflow suspensions and resumptions, enabling durable execution.
|
|
@@ -98,7 +98,7 @@ export async function handleWebhookWorkflow() {
|
|
|
98
98
|
|
|
99
99
|
### Using `fetch` in Workflows
|
|
100
100
|
|
|
101
|
-
Because `Request` and `Response` are serializable, Workflow
|
|
101
|
+
Because `Request` and `Response` are serializable, Workflow SDK provides a `fetch` function that can be used directly in workflow functions:
|
|
102
102
|
|
|
103
103
|
```typescript title="workflows/api-call.ts" lineNumbers
|
|
104
104
|
import { fetch } from "workflow"; // [!code highlight]
|
|
@@ -105,7 +105,7 @@ Because streams are live and continue receiving chunks, negative `startIndex` va
|
|
|
105
105
|
|
|
106
106
|
## Streams as Data Types
|
|
107
107
|
|
|
108
|
-
[`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) and [`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream) are standard Web Streams API types that Workflow
|
|
108
|
+
[`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) and [`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream) are standard Web Streams API types that Workflow SDK makes serializable. These are not custom types - they follow the web standard - but Workflow SDK adds the ability to pass them between functions while maintaining their streaming capabilities.
|
|
109
109
|
|
|
110
110
|
Unlike regular values that are fully serialized to the [event log](/docs/how-it-works/event-sourcing), streams maintain their streaming capabilities when passed between functions.
|
|
111
111
|
|
|
@@ -117,7 +117,7 @@ Unlike regular values that are fully serialized to the [event log](/docs/how-it-
|
|
|
117
117
|
<Callout type="info">
|
|
118
118
|
**How Streams Persist Across Workflow Suspensions**
|
|
119
119
|
|
|
120
|
-
Streams in Workflow
|
|
120
|
+
Streams in Workflow SDK are backed by persistent, resumable storage provided by the "world" implementation. This is what enables streams to maintain their state even when workflows suspend and resume:
|
|
121
121
|
|
|
122
122
|
- **Vercel deployments**: Streams are backed by a performant Redis-based stream
|
|
123
123
|
- **Local development**: Stream chunks are stored in the filesystem
|
|
@@ -43,7 +43,7 @@ export async function processOrderWorkflow(orderId: string) {
|
|
|
43
43
|
|
|
44
44
|
**Key Characteristics:**
|
|
45
45
|
|
|
46
|
-
- Runs in a sandboxed environment without full Node.js access
|
|
46
|
+
- Runs in a sandboxed environment without full Node.js access (see [Workflow Globals](/docs/api-reference/workflow-globals) for what's available)
|
|
47
47
|
- All step results are persisted to the [event log](/docs/how-it-works/event-sourcing)
|
|
48
48
|
- Must be **deterministic** to allow resuming after failures
|
|
49
49
|
|
|
@@ -203,5 +203,5 @@ While you can organize workflow and step functions however you like, we find tha
|
|
|
203
203
|
You can choose to organize your steps into a single `steps.ts` file or separate files within a `steps` folder. The `shared` folder is a good place to put common steps that are used by multiple workflows.
|
|
204
204
|
|
|
205
205
|
<Callout type="info">
|
|
206
|
-
Splitting up steps and workflows will also help avoid most bundler related bugs with the Workflow
|
|
206
|
+
Splitting up steps and workflows will also help avoid most bundler related bugs with the Workflow SDK.
|
|
207
207
|
</Callout>
|