workflow 5.4.0 → 5.5.0
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/dist/observability.d.ts +1 -1
- package/dist/observability.d.ts.map +1 -1
- package/dist/observability.js +2 -2
- package/docs/ai/chat-session-modeling.mdx +1 -1
- package/docs/ai/resumable-streams.mdx +1 -1
- package/docs/api-reference/workflow/create-hook.mdx +2 -2
- package/docs/api-reference/workflow/get-step-metadata.mdx +19 -0
- package/docs/api-reference/workflow-ai/durable-agent.mdx +2 -1
- package/docs/api-reference/workflow-ai/workflow-chat-transport.mdx +4 -4
- package/docs/api-reference/workflow-errors/workflow-run-cancelled-error.mdx +1 -1
- package/docs/api-reference/workflow-errors/workflow-run-failed-error.mdx +1 -1
- package/docs/api-reference/workflow-next/with-workflow.mdx +57 -0
- package/docs/api-reference/workflow-observability/create-state-resolver.mdx +56 -0
- package/docs/api-reference/workflow-observability/index.mdx +5 -0
- package/docs/api-reference/workflow-observability/meta.json +1 -0
- package/docs/api-reference/workflow-runtime/world/storage.mdx +1 -2
- package/docs/changelog/attributes-mvp.mdx +1 -1
- package/docs/changelog/batched-event-writes.mdx +0 -2
- package/docs/changelog/eager-processing.mdx +1 -1
- package/docs/changelog/lazy-event-creation.md +1 -1
- package/docs/changelog/spec-9.mdx +268 -120
- package/docs/changelog/step-message-ownership.mdx +2 -7
- package/docs/configuration/build-and-diagnostics.mdx +2 -0
- package/docs/configuration/cli-and-web-ui.mdx +9 -0
- package/docs/configuration/framework-options.mdx +7 -0
- package/docs/configuration/runtime-tuning.mdx +22 -77
- package/docs/configuration/worlds.mdx +54 -22
- package/docs/cookbook/advanced/child-workflows.mdx +3 -3
- package/docs/cookbook/agent-patterns/human-in-the-loop.mdx +1 -1
- package/docs/cookbook/integrations/ai-sdk.mdx +2 -2
- package/docs/errors/corrupted-event-log.mdx +1 -1
- package/docs/errors/hook-force-claimed.mdx +1 -1
- package/docs/errors/runtime-decryption-failed.mdx +1 -1
- package/docs/foundations/errors-and-retries.mdx +3 -1
- package/docs/foundations/serialization.mdx +80 -0
- package/docs/getting-started/next.mdx +2 -0
- package/docs/how-it-works/event-sourcing.mdx +2 -2
- package/docs/observability/index.mdx +2 -0
- package/docs/whats-new.mdx +3 -3
- package/docs/worlds/building-a-world.mdx +18 -3
- package/docs/worlds/local.mdx +11 -7
- package/docs/worlds/postgres.mdx +10 -13
- package/docs/worlds/upgrading-to-v5.mdx +2 -2
- package/docs/worlds/vercel.mdx +10 -5
- package/package.json +14 -14
package/dist/observability.d.ts
CHANGED
|
@@ -15,6 +15,6 @@
|
|
|
15
15
|
* // hydrated.input and hydrated.output are now plain JS objects
|
|
16
16
|
* ```
|
|
17
17
|
*/
|
|
18
|
-
export { hydrateData, hydrateResourceIO, observabilityRevivers, type Revivers, } from '@workflow/core/serialization-format';
|
|
18
|
+
export { createStateResolver, hydrateData, hydrateResourceIO, observabilityRevivers, type Revivers, type StateResolver, stateSourceId, } from '@workflow/core/serialization-format';
|
|
19
19
|
export { parseClassName, parseStepName, parseWorkflowName, } from '@workflow/utils';
|
|
20
20
|
//# sourceMappingURL=observability.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observability.d.ts","sourceRoot":"","sources":["../src/observability.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,qBAAqB,EACrB,KAAK,QAAQ,GACd,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EACL,cAAc,EACd,aAAa,EACb,iBAAiB,GAClB,MAAM,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"observability.d.ts","sourceRoot":"","sources":["../src/observability.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EACL,mBAAmB,EACnB,WAAW,EACX,iBAAiB,EACjB,qBAAqB,EACrB,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,aAAa,GACd,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EACL,cAAc,EACd,aAAa,EACb,iBAAiB,GAClB,MAAM,iBAAiB,CAAC"}
|
package/dist/observability.js
CHANGED
|
@@ -15,6 +15,6 @@
|
|
|
15
15
|
* // hydrated.input and hydrated.output are now plain JS objects
|
|
16
16
|
* ```
|
|
17
17
|
*/
|
|
18
|
-
export { hydrateData, hydrateResourceIO, observabilityRevivers, } from '@workflow/core/serialization-format';
|
|
18
|
+
export { createStateResolver, hydrateData, hydrateResourceIO, observabilityRevivers, stateSourceId, } from '@workflow/core/serialization-format';
|
|
19
19
|
export { parseClassName, parseStepName, parseWorkflowName, } from '@workflow/utils';
|
|
20
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
20
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib2JzZXJ2YWJpbGl0eS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9vYnNlcnZhYmlsaXR5LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7Ozs7Ozs7Ozs7O0dBZ0JHO0FBQ0gsT0FBTyxFQUNMLG1CQUFtQixFQUNuQixXQUFXLEVBQ1gsaUJBQWlCLEVBQ2pCLHFCQUFxQixFQUdyQixhQUFhLEdBQ2QsTUFBTSxxQ0FBcUMsQ0FBQztBQUU3QyxPQUFPLEVBQ0wsY0FBYyxFQUNkLGFBQWEsRUFDYixpQkFBaUIsR0FDbEIsTUFBTSxpQkFBaUIsQ0FBQyIsInNvdXJjZXNDb250ZW50IjpbIi8qKlxuICogT2JzZXJ2YWJpbGl0eSB1dGlsaXRpZXMgZm9yIGh5ZHJhdGluZyBzZXJpYWxpemVkIHdvcmtmbG93IGRhdGEuXG4gKlxuICogVXNlIHRoZXNlIHdoZW4gaW5zcGVjdGluZyB3b3JrZmxvdyBzdGVwIEkvTywgcnVuIGlucHV0cy9vdXRwdXRzLFxuICogb3IgZXZlbnQgZGF0YSBmcm9tIHRoZSBXb3JrZmxvdyBTREsncyB3b3JsZCBBUElzLlxuICpcbiAqIEBleGFtcGxlXG4gKiBgYGB0c1xuICogaW1wb3J0IHsgZ2V0V29ybGQgfSBmcm9tICd3b3JrZmxvdy9ydW50aW1lJztcbiAqIGltcG9ydCB7IGh5ZHJhdGVSZXNvdXJjZUlPLCBvYnNlcnZhYmlsaXR5UmV2aXZlcnMgfSBmcm9tICd3b3JrZmxvdy9vYnNlcnZhYmlsaXR5JztcbiAqXG4gKiBjb25zdCB3b3JsZCA9IGF3YWl0IGdldFdvcmxkKCk7XG4gKiBjb25zdCBzdGVwID0gYXdhaXQgd29ybGQuc3RlcHMuZ2V0KHJ1bklkLCBzdGVwSWQsIHsgcmVzb2x2ZURhdGE6ICdhbGwnIH0pO1xuICogY29uc3QgaHlkcmF0ZWQgPSBoeWRyYXRlUmVzb3VyY2VJTyhzdGVwLCBvYnNlcnZhYmlsaXR5UmV2aXZlcnMpO1xuICogLy8gaHlkcmF0ZWQuaW5wdXQgYW5kIGh5ZHJhdGVkLm91dHB1dCBhcmUgbm93IHBsYWluIEpTIG9iamVjdHNcbiAqIGBgYFxuICovXG5leHBvcnQge1xuICBjcmVhdGVTdGF0ZVJlc29sdmVyLFxuICBoeWRyYXRlRGF0YSxcbiAgaHlkcmF0ZVJlc291cmNlSU8sXG4gIG9ic2VydmFiaWxpdHlSZXZpdmVycyxcbiAgdHlwZSBSZXZpdmVycyxcbiAgdHlwZSBTdGF0ZVJlc29sdmVyLFxuICBzdGF0ZVNvdXJjZUlkLFxufSBmcm9tICdAd29ya2Zsb3cvY29yZS9zZXJpYWxpemF0aW9uLWZvcm1hdCc7XG5cbmV4cG9ydCB7XG4gIHBhcnNlQ2xhc3NOYW1lLFxuICBwYXJzZVN0ZXBOYW1lLFxuICBwYXJzZVdvcmtmbG93TmFtZSxcbn0gZnJvbSAnQHdvcmtmbG93L3V0aWxzJztcbiJdfQ==
|
|
@@ -76,7 +76,7 @@ export async function POST(request: Request) {
|
|
|
76
76
|
"use client";
|
|
77
77
|
|
|
78
78
|
import { useChat } from "@ai-sdk/react";
|
|
79
|
-
import { WorkflowChatTransport } from "@ai-sdk/workflow";
|
|
79
|
+
import { WorkflowChatTransport } from "@ai-sdk/workflow/client";
|
|
80
80
|
import { useMemo } from "react";
|
|
81
81
|
|
|
82
82
|
export function Chat({ initialMessages }) {
|
|
@@ -117,7 +117,7 @@ Replace the default transport in AI SDK's `useChat` with [`WorkflowChatTransport
|
|
|
117
117
|
"use client";
|
|
118
118
|
|
|
119
119
|
import { useChat } from "@ai-sdk/react";
|
|
120
|
-
import { WorkflowChatTransport } from "@ai-sdk/workflow"; // [!code highlight]
|
|
120
|
+
import { WorkflowChatTransport } from "@ai-sdk/workflow/client"; // [!code highlight]
|
|
121
121
|
import { useMemo, useState } from "react";
|
|
122
122
|
|
|
123
123
|
export default function ChatPage() {
|
|
@@ -180,7 +180,7 @@ On a conflict, the resolved value is a `Run` handle for the run that owns the to
|
|
|
180
180
|
|
|
181
181
|
Work started *beside* the awaiter, rather than after it, is not slowed down by it. In `await Promise.all([hook.getConflict(), prepare()])` the registration and the step are scheduled together: the runtime commits the registration, resolves the awaiter in the same invocation, and then runs `prepare()` there too, so the step does not pay an extra round trip through the queue for having been started next to a `getConflict()`.
|
|
182
182
|
|
|
183
|
-
This is a scheduling improvement, not an ordering guarantee. Only the steps the invocation runs inline start after the registration is recorded: the first [`WORKFLOW_MAX_INLINE_STEPS`](/docs/configuration/runtime-tuning#workflow_max_inline_steps) of them, less any inline steps the invocation is still running from an earlier part of the workflow
|
|
183
|
+
This is a scheduling improvement, not an ordering guarantee. Only the steps the invocation runs inline start after the registration is recorded: the first [`WORKFLOW_MAX_INLINE_STEPS`](/docs/configuration/runtime-tuning#workflow_max_inline_steps) of them, less any inline steps the invocation is still running from an earlier part of the workflow. A wider fan-out beside the awaiter has its remaining steps created and queued alongside the hook, exactly as described above, so they can start before the registration commits and can start even if it conflicts. When the ordering is what you need, await `hook.getConflict()` *before* calling the step.
|
|
184
184
|
|
|
185
185
|
<Callout type="info">
|
|
186
186
|
Custom hook tokens are the recommended way to coordinate active workflow runs. Use a deterministic token from your domain, such as an order ID or conversation ID, create the hook near the beginning of the workflow, and check `await hook.getConflict()` before work that depends on owning the token. See [Run idempotency](/docs/foundations/idempotency#run-idempotency).
|
|
@@ -266,7 +266,7 @@ With `experimental_force`, this run always ends up owning the token:
|
|
|
266
266
|
The takeover is durable. If either run's compute fails partway through, the next request for the token completes it, so the token never ends up held by nobody or by both runs. The previous owner's wake is durable too: if the new owner's compute fails between registering the Hook and waking the previous owner, the new owner's next invocation republishes the wake, whatever else the new owner has recorded since (a step it started alongside the Hook, for example). Every invocation of the new owner within 24 hours of the takeover republishes it under the same idempotency key, which collapses the repeats into one wake; a repeat that does get through only replays the previous owner, which finds nothing new.
|
|
267
267
|
|
|
268
268
|
<Callout type="info">
|
|
269
|
-
A token can only be taken from a run whose runtime understands being taken from. Runs started at a Workflow spec version below 8, which includes every run started by an older SDK release, a Python SDK run, or a deployment with `
|
|
269
|
+
A token can only be taken from a run whose runtime understands being taken from. Runs started at a Workflow spec version below 8, which includes every run started by an older SDK release, a Python SDK run, or a deployment with `WORKFLOW_SPEC_VERSION` set below 8, would never learn that their Hook was disposed. The World declines to take their token and the forced Hook rejects with the ordinary [`HookConflictError`](/docs/api-reference/workflow-errors/hook-conflict-error) instead, exactly as if `experimental_force` had not been set. Finished runs holding a retained token are taken over at any version.
|
|
270
270
|
</Callout>
|
|
271
271
|
|
|
272
272
|
`hook.getConflict()` on a forced Hook resolves with `null` once the takeover succeeds: the token is this run's by construction. If the World declines the takeover because the current owner predates spec version 8, `getConflict()` behaves as it does for an ordinary conflict and resolves with that owner's `Run`. Read `hook.claimedFrom` on the value returned by [`getHookByToken()`](/docs/api-reference/workflow-api/get-hook-by-token) to find out which run, if any, the token was taken from.
|
|
@@ -61,6 +61,25 @@ async function chargeUser(userId: string, amount: number) {
|
|
|
61
61
|
<a href="/docs/foundations/idempotency">Idempotency</a> guide.
|
|
62
62
|
</Callout>
|
|
63
63
|
|
|
64
|
+
### Example: handle the last attempt differently
|
|
65
|
+
|
|
66
|
+
```typescript lineNumbers
|
|
67
|
+
import { getStepMetadata } from "workflow";
|
|
68
|
+
|
|
69
|
+
async function welcomeUser(userId: string) {
|
|
70
|
+
"use step";
|
|
71
|
+
const { attempt, maxAttempts } = getStepMetadata();
|
|
72
|
+
|
|
73
|
+
try {
|
|
74
|
+
return await sendWelcomeEmail(userId);
|
|
75
|
+
} catch (error) {
|
|
76
|
+
if (attempt < maxAttempts) throw error; // [!code highlight]
|
|
77
|
+
console.error(`Giving up on the welcome email for ${userId}`, error);
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
64
83
|
## API signature
|
|
65
84
|
|
|
66
85
|
### Parameters
|
|
@@ -13,7 +13,7 @@ related:
|
|
|
13
13
|
`DurableAgent` is deprecated. Use AI SDK's [`WorkflowAgent`](https://ai-sdk.dev/v7/docs/agents/workflow-agent#workflowagent) for new durable agents. See the [migration guide](https://ai-sdk.dev/v7/docs/agents/workflow-agent#migrating-from-durableagent).
|
|
14
14
|
</Callout>
|
|
15
15
|
|
|
16
|
-
This reference is kept for existing applications that still import `DurableAgent` from `@workflow/ai/agent`. Do not use `DurableAgent` for new code.
|
|
16
|
+
This reference is kept for existing applications that still import `DurableAgent` from `@workflow/ai/agent`. Do not use `DurableAgent` for new code. `@workflow/ai` supports AI SDK 6 only (`ai@^6`); AI SDK 7 apps use `WorkflowAgent` from `@ai-sdk/workflow`.
|
|
17
17
|
|
|
18
18
|
For current examples and implementation guidance, see AI SDK's [`WorkflowAgent`](https://ai-sdk.dev/v7/docs/agents/workflow-agent#workflowagent) docs. For legacy code, the API surface below documents the existing `DurableAgent` exports.
|
|
19
19
|
|
|
@@ -718,6 +718,7 @@ async function agentWithToolChoice() {
|
|
|
718
718
|
|
|
719
719
|
Use `experimental_context` to pass shared context to tool executions:
|
|
720
720
|
|
|
721
|
+
{/* @skip-typecheck: DurableAgent tools use the AI SDK 6 tool options; docs samples are checked against AI SDK 7 */}
|
|
721
722
|
```typescript
|
|
722
723
|
import { DurableAgent } from "@workflow/ai/agent";
|
|
723
724
|
import { getWritable } from "workflow";
|
|
@@ -31,7 +31,7 @@ export default function Chat() {
|
|
|
31
31
|
return (
|
|
32
32
|
<div>
|
|
33
33
|
{messages.map((m) => (
|
|
34
|
-
<div key={m.id}>{m.
|
|
34
|
+
<div key={m.id}>{m.parts.map((part) => (part.type === "text" ? part.text : "")).join("")}</div>
|
|
35
35
|
))}
|
|
36
36
|
</div>
|
|
37
37
|
);
|
|
@@ -96,7 +96,7 @@ export default function BasicChat() {
|
|
|
96
96
|
<div className="space-y-4">
|
|
97
97
|
{messages.map((m) => (
|
|
98
98
|
<div key={m.id}>
|
|
99
|
-
<strong>{m.role}:</strong> {m.
|
|
99
|
+
<strong>{m.role}:</strong> {m.parts.map((part) => (part.type === "text" ? part.text : "")).join("")}
|
|
100
100
|
</div>
|
|
101
101
|
))}
|
|
102
102
|
</div>
|
|
@@ -164,7 +164,7 @@ export default function ChatWithResumption() {
|
|
|
164
164
|
<div className="space-y-4">
|
|
165
165
|
{messages.map((m) => (
|
|
166
166
|
<div key={m.id}>
|
|
167
|
-
<strong>{m.role}:</strong> {m.
|
|
167
|
+
<strong>{m.role}:</strong> {m.parts.map((part) => (part.type === "text" ? part.text : "")).join("")}
|
|
168
168
|
</div>
|
|
169
169
|
))}
|
|
170
170
|
</div>
|
|
@@ -231,7 +231,7 @@ export default function ChatWithCustomConfig() {
|
|
|
231
231
|
<div className="space-y-4">
|
|
232
232
|
{messages.map((m) => (
|
|
233
233
|
<div key={m.id}>
|
|
234
|
-
<strong>{m.role}:</strong> {m.
|
|
234
|
+
<strong>{m.role}:</strong> {m.parts.map((part) => (part.type === "text" ? part.text : "")).join("")}
|
|
235
235
|
</div>
|
|
236
236
|
))}
|
|
237
237
|
</div>
|
|
@@ -12,7 +12,7 @@ related:
|
|
|
12
12
|
|
|
13
13
|
You can check for cancellation before awaiting by inspecting `run.status`.
|
|
14
14
|
|
|
15
|
-
A canceled run is terminal, so this error is non-retryable (`fatal: true`). Inside a workflow, `await run.returnValue`
|
|
15
|
+
A canceled run is terminal, so this error is non-retryable (`fatal: true`). Inside a workflow, `await run.returnValue` reads the result in a step, and that step fails on its first attempt instead of spending its retry budget re-reading a run that cannot change. Errors from *failing to read* the run, such as a transport blip, stay retryable.
|
|
16
16
|
|
|
17
17
|
```typescript lineNumbers
|
|
18
18
|
import { WorkflowRunCancelledError } from "workflow/errors"
|
|
@@ -13,7 +13,7 @@ related:
|
|
|
13
13
|
|
|
14
14
|
The `cause` property holds the original thrown value, hydrated through the workflow serialization pipeline so its type identity (e.g. `FatalError`, `RetryableError`, custom `Error` subclasses), `cause` chain, and custom properties are preserved. Because any JavaScript value can be thrown, `cause` is typed as `unknown`, so narrow it with `instanceof Error` (or a more specific check) before accessing fields like `message`. The high-level error classification is exposed as the top-level `errorCode` property.
|
|
15
15
|
|
|
16
|
-
A failed run is terminal, so this error is non-retryable (`fatal: true`). Inside a workflow, `await run.returnValue`
|
|
16
|
+
A failed run is terminal, so this error is non-retryable (`fatal: true`). Inside a workflow, `await run.returnValue` reads the result in a step, and that step fails on its first attempt instead of spending its retry budget re-reading a run that cannot change: the remote failure reaches the caller immediately, and the caller catches a `WorkflowRunFailedError` rather than a retry-exhaustion wrapper. Errors from *failing to read* the run, such as a transport blip, stay retryable.
|
|
17
17
|
|
|
18
18
|
```typescript lineNumbers
|
|
19
19
|
import { WorkflowRunFailedError } from "workflow/errors"
|
|
@@ -104,6 +104,7 @@ export default withWorkflow(nextConfig, {
|
|
|
104
104
|
| --- | --- | --- | --- |
|
|
105
105
|
| `workflows.local.port` | `number` | — | Overrides the `PORT` environment variable for local development. Has no effect when deployed to Vercel. |
|
|
106
106
|
| `workflows.sourcemap` | `boolean \| 'inline' \| 'linked' \| 'external' \| 'both'` | `'inline'` (dev) / `false` (prod) | Controls source maps on generated workflow bundles. See [Source maps](#source-maps) below. |
|
|
107
|
+
| `workflows.experimentalRoutePrefix` | `string` | — | Serves the generated workflow routes below a route segment this app owns, such as `/dashboard`. See [Workflow route prefix](#workflow-route-prefix) below. |
|
|
107
108
|
|
|
108
109
|
### Source maps
|
|
109
110
|
|
|
@@ -129,6 +130,62 @@ The option can also be set via the `WORKFLOW_SOURCEMAP` environment variable, wh
|
|
|
129
130
|
The `workflows.local` options only affect local development. When deployed to Vercel, the runtime ignores `local` settings and uses the Vercel world automatically.
|
|
130
131
|
</Callout>
|
|
131
132
|
|
|
133
|
+
### Workflow route prefix
|
|
134
|
+
|
|
135
|
+
By default the integration generates its routes at the root of your app, so the flow route answers at `/.well-known/workflow/v1/flow`. Some deployments cannot own those paths. In a [Microfrontends](https://vercel.com/docs/microfrontends) setup, for example, a child app is routed a path such as `/dashboard/*` while requests for `/.well-known/*` go to the default app, so queue deliveries and webhooks aimed at the root never reach the child.
|
|
136
|
+
|
|
137
|
+
`workflows.experimentalRoutePrefix` moves the generated workflow routes below a segment the app does own:
|
|
138
|
+
|
|
139
|
+
```typescript title="next.config.ts" lineNumbers
|
|
140
|
+
import type { NextConfig } from "next";
|
|
141
|
+
import { withWorkflow } from "workflow/next";
|
|
142
|
+
|
|
143
|
+
const nextConfig: NextConfig = {};
|
|
144
|
+
|
|
145
|
+
export default withWorkflow(nextConfig, {
|
|
146
|
+
workflows: {
|
|
147
|
+
experimentalRoutePrefix: "/dashboard", // [!code highlight]
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
With that prefix, the build emits:
|
|
153
|
+
|
|
154
|
+
| Artifact | Path |
|
|
155
|
+
| --- | --- |
|
|
156
|
+
| Flow route | `app/dashboard/.well-known/workflow/v1/flow/route.js` |
|
|
157
|
+
| Webhook route | `app/dashboard/.well-known/workflow/v1/webhook/[token]/route.js` |
|
|
158
|
+
| Vercel function config | `app/dashboard/.well-known/workflow/v1/config.json` |
|
|
159
|
+
| Manifest | `app/dashboard/.well-known/workflow/v1/manifest.json` |
|
|
160
|
+
|
|
161
|
+
The queue trigger that makes the flow route a queue consumer is written next to the prefixed route, so deliveries reach it without any additional routing configuration. Webhook URLs, health checks, and the local and Postgres queue targets are all built from the prefix, so `createWebhook()` returns a URL under `/dashboard/.well-known/workflow/v1/webhook/:token`. `getWorkflowMetadata().url` includes the prefix too (for example `https://example.com/dashboard`), so don't build URLs to the rest of your app from it.
|
|
162
|
+
|
|
163
|
+
The prefix is a plain path of one or more segments. Leading and trailing slashes are optional. Anything Next.js would not serve at a fixed path is rejected when the config is created: dynamic segments such as `/[team]`, route groups such as `/(group)`, and `_`-prefixed segments, which Next.js excludes from routing entirely. Segments starting with `.` are rejected too, because the build could not clean up routes generated below them after the prefix changes.
|
|
164
|
+
|
|
165
|
+
<Callout type="warn">
|
|
166
|
+
If you cache your build with Turborepo, update the `outputs` globs to the prefixed paths. `app/.well-known/workflow/**` no longer matches `app/dashboard/.well-known/workflow/**`, and a cache hit would restore a build with no workflow routes in it.
|
|
167
|
+
</Callout>
|
|
168
|
+
|
|
169
|
+
<Callout type="warn">
|
|
170
|
+
If the app has `proxy.ts` or middleware, its matcher must exclude the prefixed path. A pattern such as `/((?!.well-known/workflow/).*)` only matches from the start of the path, so it no longer skips `/dashboard/.well-known/workflow/v1/flow`; exclude `dashboard/.well-known/workflow/` instead.
|
|
171
|
+
</Callout>
|
|
172
|
+
|
|
173
|
+
<Callout type="warn">
|
|
174
|
+
Your routing layer must send the prefixed paths to this app. With Microfrontends, that means choosing a prefix the child app is already routed in the group's [routing configuration](https://vercel.com/docs/microfrontends/routing).
|
|
175
|
+
</Callout>
|
|
176
|
+
|
|
177
|
+
This option is experimental and its name may change.
|
|
178
|
+
|
|
179
|
+
#### Compared with `basePath`
|
|
180
|
+
|
|
181
|
+
The integration already honors Next.js' [`basePath`](https://nextjs.org/docs/app/api-reference/config/next-config-js/basePath): Next.js serves every route, including the generated workflow routes, below it, and `withWorkflow` passes it to the runtime so webhook and queue URLs include it. That only helps when the whole app can move under one path. A Microfrontends child app usually can't: its pages already live at `app/dashboard/...`, so `basePath: "/dashboard"` would serve them at `/dashboard/dashboard/...`.
|
|
182
|
+
|
|
183
|
+
`experimentalRoutePrefix` moves only the generated workflow routes and their function config into the app tree; the rest of your routes keep their paths. The two compose: with `basePath: "/v2"` and `experimentalRoutePrefix: "/dashboard"`, the flow route answers at `/v2/dashboard/.well-known/workflow/v1/flow`.
|
|
184
|
+
|
|
185
|
+
<Callout type="info">
|
|
186
|
+
The local CLI and web UI find a prefixed manifest such as `app/dashboard/.well-known/workflow/v1/manifest.json` on their own; set [`WORKFLOW_MANIFEST_PATH`](/docs/configuration/cli-and-web-ui#workflow_manifest_path) to pick another. Pass the base path to [`workflow health`](/docs/configuration/cli-and-web-ui#--base-path), for example `workflow health --base-path /dashboard`.
|
|
187
|
+
</Callout>
|
|
188
|
+
|
|
132
189
|
## Exporting a function
|
|
133
190
|
|
|
134
191
|
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: createStateResolver
|
|
3
|
+
description: Rebuild frozen state that a run stored by reference, so inspection tools show actual values.
|
|
4
|
+
type: reference
|
|
5
|
+
summary: Use createStateResolver to show the actual values of step inputs and outputs that hold frozen state stored by reference.
|
|
6
|
+
related:
|
|
7
|
+
- /docs/api-reference/workflow-observability/hydrate-data
|
|
8
|
+
- /docs/api-reference/workflow-observability/observability-revivers
|
|
9
|
+
- /docs/foundations/serialization
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
Deeply frozen values passed between steps are stored by reference: a step input that holds one is written as a reference to an earlier step's output, and a step output as its change from the value it was made from. See [Serialization](/docs/foundations/serialization). Workflow rebuilds them during replay, so your code always receives whole values. An inspection tool reading the stored payloads directly has to rebuild them too, from the run's earlier records.
|
|
13
|
+
|
|
14
|
+
Create one resolver per run, feed it the run's persisted payloads once, in event-log order, and merge its revivers over the ones you hydrate with:
|
|
15
|
+
|
|
16
|
+
```typescript lineNumbers
|
|
17
|
+
import { createStateResolver, hydrateData, observabilityRevivers, stateSourceId } from "workflow/observability"; // [!code highlight]
|
|
18
|
+
declare const runInput: unknown; // @setup
|
|
19
|
+
declare const events: { eventId: string; eventType: string; eventData?: { payload?: unknown; result?: unknown } }[]; // @setup
|
|
20
|
+
declare const stepInput: unknown; // @setup
|
|
21
|
+
|
|
22
|
+
const resolver = createStateResolver(observabilityRevivers); // [!code highlight]
|
|
23
|
+
resolver.add(runInput, stateSourceId("run-input"));
|
|
24
|
+
for (const event of events) {
|
|
25
|
+
if (event.eventType === "hook_received") resolver.add(event.eventData?.payload, stateSourceId(event));
|
|
26
|
+
if (event.eventType === "step_completed") resolver.add(event.eventData?.result);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const input = hydrateData(stepInput, { ...observabilityRevivers, ...resolver.revivers }); // [!code highlight]
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Pass decrypted payloads. Keep the resolver for the run and reuse it across inspections, so the history is read once.
|
|
33
|
+
|
|
34
|
+
A web inspector built on `@workflow/web-shared` can use `createRunStateHydrator()` instead. It reads the run's history through loaders you give it, only as far as the inspected value needs, and handles encrypted and compressed payloads. The Workflow web UI uses it for its span details, and `workflow inspect` rebuilds values the same way.
|
|
35
|
+
|
|
36
|
+
## API signature
|
|
37
|
+
|
|
38
|
+
### Parameters
|
|
39
|
+
|
|
40
|
+
| Parameter | Type | Description |
|
|
41
|
+
|-----------|------|-------------|
|
|
42
|
+
| `revivers` | `Revivers` | Optional. Revivers for the other types inside the stored payloads. Use [`observabilityRevivers`](/docs/api-reference/workflow-observability/observability-revivers) for standard use. |
|
|
43
|
+
|
|
44
|
+
### Returns
|
|
45
|
+
|
|
46
|
+
A `StateResolver`:
|
|
47
|
+
|
|
48
|
+
| Property | Type | Description |
|
|
49
|
+
|----------|------|-------------|
|
|
50
|
+
| `add(data, source?)` | `(data: unknown, source?: string) => void` | Reads one persisted payload. Pass `stateSourceId(event)` for a `hook_received` payload and `stateSourceId("run-input")` for the run input, so state can refer to their strings. A step output with no state records is skipped. |
|
|
51
|
+
| `revivers` | `Revivers` | Revivers that rebuild state records from what has been added. Merge them over your own. |
|
|
52
|
+
| `unresolved` | `number` | How many records referred to history that hasn't been added yet. Those show as `<state …>` placeholders; add more of the history and hydrate again. |
|
|
53
|
+
|
|
54
|
+
## stateSourceId
|
|
55
|
+
|
|
56
|
+
`stateSourceId(event)` returns the id a `hook_received` event's payload is registered under, and `stateSourceId("run-input")` the id for the run input. Use the same ids the runtime uses, or state that refers to those payloads' strings stays unresolved.
|
|
@@ -8,6 +8,7 @@ keywords:
|
|
|
8
8
|
- hydrateResourceIO
|
|
9
9
|
- observabilityRevivers
|
|
10
10
|
- hydrateData
|
|
11
|
+
- createStateResolver
|
|
11
12
|
- parseStepName
|
|
12
13
|
- parseWorkflowName
|
|
13
14
|
- parseClassName
|
|
@@ -23,6 +24,7 @@ import { // [!code highlight]
|
|
|
23
24
|
hydrateResourceIO, // [!code highlight]
|
|
24
25
|
observabilityRevivers, // [!code highlight]
|
|
25
26
|
hydrateData, // [!code highlight]
|
|
27
|
+
createStateResolver, // [!code highlight]
|
|
26
28
|
parseStepName, // [!code highlight]
|
|
27
29
|
parseWorkflowName, // [!code highlight]
|
|
28
30
|
parseClassName, // [!code highlight]
|
|
@@ -41,6 +43,9 @@ import { // [!code highlight]
|
|
|
41
43
|
<Card href="/docs/api-reference/workflow-observability/hydrate-data" title="hydrateData()">
|
|
42
44
|
Hydrate a single serialized value (lower-level than hydrateResourceIO).
|
|
43
45
|
</Card>
|
|
46
|
+
<Card href="/docs/api-reference/workflow-observability/create-state-resolver" title="createStateResolver()">
|
|
47
|
+
Rebuild frozen state a run stored by reference, so inspected values show in full.
|
|
48
|
+
</Card>
|
|
44
49
|
</Cards>
|
|
45
50
|
|
|
46
51
|
## Name parsing
|
|
@@ -182,8 +182,7 @@ a normal return, not an error, and a missing run throws
|
|
|
182
182
|
also return a non-terminal snapshot before `timeoutMs` is up. Callers pace
|
|
183
183
|
their own retries (`await run.returnValue` keeps consecutive non-terminal
|
|
184
184
|
observations at least one `WORKFLOW_RETURN_VALUE_POLL_INTERVAL_MS` apart), and
|
|
185
|
-
worlds that omit the method are polled on that interval instead.
|
|
186
|
-
`WORKFLOW_RETURN_VALUE_LONG_POLL=0` to force interval polling everywhere.
|
|
185
|
+
worlds that omit the method are polled on that interval instead.
|
|
187
186
|
</Callout>
|
|
188
187
|
|
|
189
188
|
### runs.list()
|
|
@@ -301,7 +301,7 @@ Integration tests in `world-postgres`:
|
|
|
301
301
|
- Upsert, merge across calls, unset via `null` (the SQL `jsonb_set` / `-` chain is exercised through these)
|
|
302
302
|
- Atomic cap enforcement inside the `UPDATE`'s `WHERE` clause; concurrent writers cannot collectively push past the per-run cap
|
|
303
303
|
|
|
304
|
-
End-to-end in `workbench/nextjs-turbopack` (exercises the full SWC plugin + workflow VM + step worker + `world-vercel` wire path against the production
|
|
304
|
+
End-to-end in `workbench/nextjs-turbopack` (exercises the full SWC plugin + workflow VM + step worker + `world-vercel` wire path against the production `world-vercel` backend `/v2/runs/:runId/attributes` endpoint):
|
|
305
305
|
|
|
306
306
|
- Awaited workflow-body calls dispatch through the `__builtin_set_attributes` step bridge and merge correctly (the test inspects the run's event log to confirm a `step_created` / `step_completed` pair was emitted)
|
|
307
307
|
- Fire-and-forget (`void experimental_setAttributes`) attributes land before the run terminates
|
|
@@ -72,8 +72,6 @@ Per-event `409`s are tolerated the same way the single path tolerates `EntityCon
|
|
|
72
72
|
|
|
73
73
|
`createBatch` is optional, so today only the Vercel World folds at all: every other World keeps the single-event path and never sends a pair.
|
|
74
74
|
|
|
75
|
-
**Escape hatch**: Set `WORKFLOW_BATCH_TRANSITIONS=0` (or `false`) to disable batching and restore the exact prior one-write-per-event path. See [`WORKFLOW_BATCH_TRANSITIONS`](/docs/configuration/worlds#workflow_batch_transitions).
|
|
76
|
-
|
|
77
75
|
## Follow-up
|
|
78
76
|
|
|
79
77
|
The deferred sequential transition (holding `step_completed(N)` across the replay turn and committing `[step_completed(N), step_created(N+1), step_started(N+1)]` as one batch at the next lazy start) builds on this contract and ships separately.
|
|
@@ -78,7 +78,7 @@ Each background step message is handled by a separate function invocation of the
|
|
|
78
78
|
- **Steps still pending**: The handler returns without queuing a continuation. The last handler to complete its step will see all steps done and replay inline.
|
|
79
79
|
- **Pending ops (stream writes)**: The handler queues a continuation and returns, so `waitUntil` can flush the pending stream data.
|
|
80
80
|
|
|
81
|
-
The inline steps of one invocation do not wait for each other. When one of them completes while its siblings are still running, the handler replays the workflow right away, so the branch it belongs to can start its next step inline. The siblings stay owned by this handler. If the workflow returns or throws first, the run ends right away; the handler still lets the siblings' bodies finish before it returns, so their step events can follow `run_completed` or `run_failed` in the log, and a sibling whose attempt fails retryably is not retried.
|
|
81
|
+
The inline steps of one invocation do not wait for each other. When one of them completes while its siblings are still running, the handler replays the workflow right away, so the branch it belongs to can start its next step inline. The siblings stay owned by this handler. If the workflow returns or throws first, the run ends right away; the handler still lets the siblings' bodies finish before it returns, so their step events can follow `run_completed` or `run_failed` in the log, and a sibling whose attempt fails retryably is not retried.
|
|
82
82
|
|
|
83
83
|
### Convergence after parallel steps
|
|
84
84
|
|
|
@@ -89,7 +89,7 @@ A follow-up builds two more latency wins on top of lazy inline start. Both are c
|
|
|
89
89
|
|
|
90
90
|
Previously the owned-inline path ran **exactly one** step inline per suspension and queued the rest. For a `Promise.all([stepA(), stepB(), stepC()])` fan-out that meant one branch ran inline while the others paid a queue round-trip each before making any progress.
|
|
91
91
|
|
|
92
|
-
The suspension handler now defers `step_created` for up to **`WORKFLOW_MAX_INLINE_STEPS` (default 3)** steps and returns them as `lazyInlineSteps`. The runtime runs that batch inline **in parallel**, each via its own lazy `step_started`, and queues only the steps beyond the cap.
|
|
92
|
+
The suspension handler now defers `step_created` for up to **`WORKFLOW_MAX_INLINE_STEPS` (default 3)** steps and returns them as `lazyInlineSteps`. The runtime runs that batch inline **in parallel**, each via its own lazy `step_started`, and queues only the steps beyond the cap. The runtime replays as soon as one step of the batch settles, so steps still running hold their slots and a later suspension gets fewer.
|
|
93
93
|
|
|
94
94
|
- **Selection:** the first N uncreated steps, matching the previous single-step inline candidate. Steps beyond N keep their eager `step_created` and are queued exactly as before.
|
|
95
95
|
- **Result aggregation:** `retry` steps (whose `step_started` succeeded, so the step exists) are re-queued per-step as background steps with their own delay. `throttled` steps are different: a throttle rejects the lazy `step_started` on the create-claim, so the step was *never created* and has no recoverable input. Re-queuing it as an input-less background step would make the world reject the bare `step_started` with "Step not found" and redeliver until it fails. Any throttle instead **defers redelivery of the orchestrator** (by the longest throttle backoff in the batch), which re-runs the throttled step inline *with its input* on replay. The runtime only loops back to replay in-process once every inline step has reached a terminal state.
|