@workflow/core 5.0.0-beta.5 → 5.0.0-beta.50
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/attribute-changes.d.ts +5 -0
- package/dist/attribute-changes.d.ts.map +1 -0
- package/dist/attribute-changes.js +25 -0
- package/dist/capabilities.d.ts +35 -2
- package/dist/capabilities.d.ts.map +1 -1
- package/dist/capabilities.js +74 -5
- package/dist/capture-stack.d.ts +1 -1
- package/dist/capture-stack.js +2 -2
- package/dist/class-serialization.d.ts +32 -0
- package/dist/class-serialization.d.ts.map +1 -1
- package/dist/class-serialization.js +37 -1
- package/dist/classify-error.d.ts +19 -3
- package/dist/classify-error.d.ts.map +1 -1
- package/dist/classify-error.js +98 -6
- package/dist/context-violation-error.d.ts +5 -5
- package/dist/context-violation-error.d.ts.map +1 -1
- package/dist/context-violation-error.js +8 -6
- package/dist/create-hook.d.ts +72 -7
- package/dist/create-hook.d.ts.map +1 -1
- package/dist/create-hook.js +1 -1
- package/dist/define-hook.js +2 -2
- package/dist/describe-error.d.ts +7 -7
- package/dist/describe-error.d.ts.map +1 -1
- package/dist/describe-error.js +97 -12
- package/dist/encryption.d.ts +38 -4
- package/dist/encryption.d.ts.map +1 -1
- package/dist/encryption.js +96 -14
- package/dist/events-consumer.d.ts +271 -0
- package/dist/events-consumer.d.ts.map +1 -1
- package/dist/events-consumer.js +646 -42
- package/dist/flushable-stream.d.ts +56 -1
- package/dist/flushable-stream.d.ts.map +1 -1
- package/dist/flushable-stream.js +123 -11
- package/dist/global.d.ts +36 -2
- package/dist/global.d.ts.map +1 -1
- package/dist/global.js +21 -6
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/log-format.d.ts +2 -2
- package/dist/log-format.js +7 -7
- package/dist/logger.d.ts +1 -0
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +10 -6
- package/dist/private.d.ts +226 -9
- package/dist/private.d.ts.map +1 -1
- package/dist/private.js +626 -7
- package/dist/replay-payload-cache.d.ts +64 -0
- package/dist/replay-payload-cache.d.ts.map +1 -0
- package/dist/replay-payload-cache.js +158 -0
- package/dist/runtime/compute-instance.d.ts +13 -0
- package/dist/runtime/compute-instance.d.ts.map +1 -0
- package/dist/runtime/compute-instance.js +14 -0
- package/dist/runtime/constants.d.ts +315 -0
- package/dist/runtime/constants.d.ts.map +1 -1
- package/dist/runtime/constants.js +502 -16
- package/dist/runtime/count-step-started-events.d.ts +52 -0
- package/dist/runtime/count-step-started-events.d.ts.map +1 -0
- package/dist/runtime/count-step-started-events.js +72 -0
- package/dist/runtime/deployment-guard.d.ts +99 -0
- package/dist/runtime/deployment-guard.d.ts.map +1 -0
- package/dist/runtime/deployment-guard.js +154 -0
- package/dist/runtime/get-port-lazy.d.ts +15 -0
- package/dist/runtime/get-port-lazy.d.ts.map +1 -1
- package/dist/runtime/get-port-lazy.js +75 -6
- package/dist/runtime/get-world-lazy.d.ts +5 -14
- package/dist/runtime/get-world-lazy.d.ts.map +1 -1
- package/dist/runtime/get-world-lazy.js +19 -29
- package/dist/runtime/helpers.d.ts +341 -29
- package/dist/runtime/helpers.d.ts.map +1 -1
- package/dist/runtime/helpers.js +559 -57
- package/dist/runtime/quickjs-assets.generated.d.ts +14 -0
- package/dist/runtime/quickjs-assets.generated.d.ts.map +1 -0
- package/dist/runtime/quickjs-assets.generated.js +30 -0
- package/dist/runtime/quickjs-entrypoint.d.ts +136 -0
- package/dist/runtime/quickjs-entrypoint.d.ts.map +1 -0
- package/dist/runtime/quickjs-entrypoint.js +1686 -0
- package/dist/runtime/quickjs-runtime.d.ts +244 -0
- package/dist/runtime/quickjs-runtime.d.ts.map +1 -0
- package/dist/runtime/quickjs-runtime.js +2427 -0
- package/dist/runtime/quickjs-serde.d.ts +107 -0
- package/dist/runtime/quickjs-serde.d.ts.map +1 -0
- package/dist/runtime/quickjs-serde.js +2159 -0
- package/dist/runtime/replay-budget.d.ts +97 -0
- package/dist/runtime/replay-budget.d.ts.map +1 -0
- package/dist/runtime/replay-budget.js +139 -0
- package/dist/runtime/replay-recovery-reporter.d.ts +36 -0
- package/dist/runtime/replay-recovery-reporter.d.ts.map +1 -0
- package/dist/runtime/replay-recovery-reporter.js +64 -0
- package/dist/runtime/resume-hook.d.ts +91 -8
- package/dist/runtime/resume-hook.d.ts.map +1 -1
- package/dist/runtime/resume-hook.js +512 -89
- package/dist/runtime/resume-latency.d.ts +150 -0
- package/dist/runtime/resume-latency.d.ts.map +1 -0
- package/dist/runtime/resume-latency.js +155 -0
- package/dist/runtime/run-id-time.d.ts +19 -0
- package/dist/runtime/run-id-time.d.ts.map +1 -0
- package/dist/runtime/run-id-time.js +42 -0
- package/dist/runtime/run.d.ts +72 -7
- package/dist/runtime/run.d.ts.map +1 -1
- package/dist/runtime/run.js +280 -53
- package/dist/runtime/runs.d.ts +54 -3
- package/dist/runtime/runs.d.ts.map +1 -1
- package/dist/runtime/runs.js +126 -16
- package/dist/runtime/start.d.ts +101 -2
- package/dist/runtime/start.d.ts.map +1 -1
- package/dist/runtime/start.js +352 -61
- package/dist/runtime/step-executor.d.ts +205 -5
- package/dist/runtime/step-executor.d.ts.map +1 -1
- package/dist/runtime/step-executor.js +760 -127
- package/dist/runtime/step-latency.d.ts +220 -0
- package/dist/runtime/step-latency.d.ts.map +1 -0
- package/dist/runtime/step-latency.js +215 -0
- package/dist/runtime/step-ownership.d.ts +72 -0
- package/dist/runtime/step-ownership.d.ts.map +1 -0
- package/dist/runtime/step-ownership.js +114 -0
- package/dist/runtime/step-single-flight.d.ts +12 -0
- package/dist/runtime/step-single-flight.d.ts.map +1 -0
- package/dist/runtime/step-single-flight.js +75 -0
- package/dist/runtime/suspension-handler.d.ts +269 -7
- package/dist/runtime/suspension-handler.d.ts.map +1 -1
- package/dist/runtime/suspension-handler.js +1253 -125
- package/dist/runtime/unserializable-step.d.ts +34 -0
- package/dist/runtime/unserializable-step.d.ts.map +1 -0
- package/dist/runtime/unserializable-step.js +52 -0
- package/dist/runtime/vm-mode.d.ts +44 -0
- package/dist/runtime/vm-mode.d.ts.map +1 -0
- package/dist/runtime/vm-mode.js +62 -0
- package/dist/runtime/vm-serde-bundle.generated.d.ts +14 -0
- package/dist/runtime/vm-serde-bundle.generated.d.ts.map +1 -0
- package/dist/runtime/vm-serde-bundle.generated.js +16 -0
- package/dist/runtime/wait-continuation.d.ts +106 -0
- package/dist/runtime/wait-continuation.d.ts.map +1 -0
- package/dist/runtime/wait-continuation.js +136 -0
- package/dist/runtime/wait-until.d.ts +18 -0
- package/dist/runtime/wait-until.d.ts.map +1 -0
- package/dist/runtime/wait-until.js +42 -0
- package/dist/runtime/world-compatibility.d.ts +32 -0
- package/dist/runtime/world-compatibility.d.ts.map +1 -0
- package/dist/runtime/world-compatibility.js +44 -0
- package/dist/runtime/world-init.d.ts +17 -42
- package/dist/runtime/world-init.d.ts.map +1 -1
- package/dist/runtime/world-init.js +18 -43
- package/dist/runtime/world.d.ts +14 -2
- package/dist/runtime/world.d.ts.map +1 -1
- package/dist/runtime/world.js +75 -19
- package/dist/runtime.d.ts +10 -6
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +3741 -490
- package/dist/sealed-box.d.ts +167 -0
- package/dist/sealed-box.d.ts.map +1 -0
- package/dist/sealed-box.js +571 -0
- package/dist/serialization/client.d.ts +3 -3
- package/dist/serialization/client.d.ts.map +1 -1
- package/dist/serialization/client.js +8 -4
- package/dist/serialization/codec-devalue-vm.d.ts +16 -0
- package/dist/serialization/codec-devalue-vm.d.ts.map +1 -0
- package/dist/serialization/codec-devalue-vm.js +148 -0
- package/dist/serialization/codec-devalue.d.ts +1 -1
- package/dist/serialization/codec-devalue.d.ts.map +1 -1
- package/dist/serialization/codec-devalue.js +24 -6
- package/dist/serialization/codec.d.ts +37 -2
- package/dist/serialization/codec.d.ts.map +1 -1
- package/dist/serialization/codec.js +2 -2
- package/dist/serialization/compression.d.ts +105 -0
- package/dist/serialization/compression.d.ts.map +1 -0
- package/dist/serialization/compression.js +261 -0
- package/dist/serialization/encryption.d.ts +119 -17
- package/dist/serialization/encryption.d.ts.map +1 -1
- package/dist/serialization/encryption.js +152 -17
- package/dist/serialization/errors.d.ts +13 -0
- package/dist/serialization/errors.d.ts.map +1 -1
- package/dist/serialization/errors.js +20 -2
- package/dist/serialization/format.d.ts +6 -6
- package/dist/serialization/format.js +7 -7
- package/dist/serialization/hardened.d.ts +156 -0
- package/dist/serialization/hardened.d.ts.map +1 -0
- package/dist/serialization/hardened.js +538 -0
- package/dist/serialization/index.d.ts +10 -8
- package/dist/serialization/index.d.ts.map +1 -1
- package/dist/serialization/index.js +10 -8
- package/dist/serialization/reducers/class-vm.d.ts +20 -0
- package/dist/serialization/reducers/class-vm.d.ts.map +1 -0
- package/dist/serialization/reducers/class-vm.js +77 -0
- package/dist/serialization/reducers/class.d.ts.map +1 -1
- package/dist/serialization/reducers/class.js +11 -6
- package/dist/serialization/reducers/common-vm.d.ts +15 -0
- package/dist/serialization/reducers/common-vm.d.ts.map +1 -0
- package/dist/serialization/reducers/common-vm.js +616 -0
- package/dist/serialization/reducers/common.d.ts +1 -1
- package/dist/serialization/reducers/common.d.ts.map +1 -1
- package/dist/serialization/reducers/common.js +202 -62
- package/dist/serialization/reducers/step-function-vm.d.ts +44 -0
- package/dist/serialization/reducers/step-function-vm.d.ts.map +1 -0
- package/dist/serialization/reducers/step-function-vm.js +97 -0
- package/dist/serialization/reducers/step-function.d.ts.map +1 -1
- package/dist/serialization/reducers/step-function.js +25 -9
- package/dist/serialization/step.d.ts +4 -4
- package/dist/serialization/step.d.ts.map +1 -1
- package/dist/serialization/step.js +9 -5
- package/dist/serialization/types.d.ts +80 -1
- package/dist/serialization/types.d.ts.map +1 -1
- package/dist/serialization/types.js +15 -1
- package/dist/serialization/workflow-vm.d.ts +29 -0
- package/dist/serialization/workflow-vm.d.ts.map +1 -0
- package/dist/serialization/workflow-vm.js +74 -0
- package/dist/serialization-format.d.ts +64 -8
- package/dist/serialization-format.d.ts.map +1 -1
- package/dist/serialization-format.js +225 -73
- package/dist/serialization.d.ts +262 -34
- package/dist/serialization.d.ts.map +1 -1
- package/dist/serialization.js +1879 -274
- package/dist/set-attributes.d.ts +13 -0
- package/dist/set-attributes.d.ts.map +1 -0
- package/dist/set-attributes.js +60 -0
- package/dist/source-map.d.ts +25 -0
- package/dist/source-map.d.ts.map +1 -1
- package/dist/source-map.js +154 -10
- package/dist/step/context-storage.d.ts +61 -2
- package/dist/step/context-storage.d.ts.map +1 -1
- package/dist/step/context-storage.js +7 -5
- package/dist/step/writable-stream.d.ts +3 -3
- package/dist/step/writable-stream.d.ts.map +1 -1
- package/dist/step/writable-stream.js +72 -9
- package/dist/step.d.ts.map +1 -1
- package/dist/step.js +148 -27
- package/dist/symbols.d.ts +50 -0
- package/dist/symbols.d.ts.map +1 -1
- package/dist/symbols.js +51 -1
- package/dist/telemetry/semantic-conventions.d.ts +397 -2
- package/dist/telemetry/semantic-conventions.d.ts.map +1 -1
- package/dist/telemetry/semantic-conventions.js +297 -3
- package/dist/telemetry.d.ts +91 -0
- package/dist/telemetry.d.ts.map +1 -1
- package/dist/telemetry.js +244 -17
- package/dist/test-support/orchestrator-context.d.ts +25 -0
- package/dist/test-support/orchestrator-context.d.ts.map +1 -0
- package/dist/test-support/orchestrator-context.js +101 -0
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +23 -1
- package/dist/util.d.ts +0 -5
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +1 -15
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +2 -2
- package/dist/vm/index.d.ts.map +1 -1
- package/dist/vm/index.js +84 -14
- package/dist/vm/script-cache.d.ts +26 -0
- package/dist/vm/script-cache.d.ts.map +1 -0
- package/dist/vm/script-cache.js +131 -0
- package/dist/vm/uint8array-base64.js +1 -1
- package/dist/workflow/abort-controller.d.ts +2 -2
- package/dist/workflow/abort-controller.d.ts.map +1 -1
- package/dist/workflow/abort-controller.js +88 -21
- package/dist/workflow/attribute-dispatcher.d.ts +6 -0
- package/dist/workflow/attribute-dispatcher.d.ts.map +1 -0
- package/dist/workflow/attribute-dispatcher.js +45 -0
- package/dist/workflow/create-hook.d.ts.map +1 -1
- package/dist/workflow/create-hook.js +24 -3
- package/dist/workflow/get-workflow-metadata.js +2 -2
- package/dist/workflow/hook.d.ts.map +1 -1
- package/dist/workflow/hook.js +304 -47
- package/dist/workflow/index.d.ts +1 -0
- package/dist/workflow/index.d.ts.map +1 -1
- package/dist/workflow/index.js +2 -1
- package/dist/workflow/set-attributes.d.ts +68 -0
- package/dist/workflow/set-attributes.d.ts.map +1 -0
- package/dist/workflow/set-attributes.js +60 -0
- package/dist/workflow/sleep.d.ts.map +1 -1
- package/dist/workflow/sleep.js +58 -12
- package/dist/workflow/world-init-stub.d.ts +3 -3
- package/dist/workflow/world-init-stub.js +4 -4
- package/dist/workflow.d.ts +95 -3
- package/dist/workflow.d.ts.map +1 -1
- package/dist/workflow.js +895 -561
- package/docs/api-reference/create-hook.mdx +89 -10
- package/docs/api-reference/create-webhook.mdx +16 -15
- package/docs/api-reference/define-hook.mdx +35 -33
- package/docs/api-reference/fatal-error.mdx +30 -8
- package/docs/api-reference/fetch.mdx +14 -10
- package/docs/api-reference/get-step-metadata.mdx +2 -2
- package/docs/api-reference/get-workflow-metadata.mdx +3 -3
- package/docs/api-reference/get-writable.mdx +7 -7
- package/docs/api-reference/index.mdx +4 -1
- package/docs/api-reference/retryable-error.mdx +1 -1
- package/docs/api-reference/set-attributes.mdx +61 -0
- package/docs/api-reference/sleep.mdx +4 -4
- package/docs/foundations/cancellation.mdx +31 -32
- package/docs/foundations/errors-and-retries.mdx +42 -11
- package/docs/foundations/hooks.mdx +64 -35
- package/docs/foundations/idempotency.mdx +244 -12
- package/docs/foundations/index.mdx +1 -23
- package/docs/foundations/meta.json +2 -1
- package/docs/foundations/serialization.mdx +21 -22
- package/docs/foundations/starting-workflows.mdx +106 -30
- package/docs/foundations/streaming.mdx +107 -59
- package/docs/foundations/versioning.mdx +263 -0
- package/docs/foundations/workflows-and-steps.mdx +9 -9
- package/docs/how-it-works/cancellation.mdx +63 -63
- package/docs/how-it-works/code-transform.mdx +83 -67
- package/docs/how-it-works/encryption.mdx +30 -26
- package/docs/how-it-works/event-sourcing.mdx +98 -34
- package/docs/how-it-works/framework-integrations.mdx +96 -337
- package/docs/how-it-works/understanding-directives.mdx +22 -22
- package/package.json +24 -15
- package/dist/runtime/step-handler.d.ts +0 -2
- package/dist/runtime/step-handler.d.ts.map +0 -1
- package/dist/runtime/step-handler.js +0 -776
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: Starting
|
|
2
|
+
title: Starting workflows
|
|
3
3
|
description: Trigger workflow execution with the start() function and track progress with Run objects.
|
|
4
4
|
type: guide
|
|
5
5
|
summary: Trigger workflows and track their execution using the start() function.
|
|
@@ -9,11 +9,11 @@ related:
|
|
|
9
9
|
- /docs/api-reference/workflow-api/start
|
|
10
10
|
---
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
After you define a workflow function, use the `start()` function from `workflow/api` to trigger it. The function enqueues a new workflow run and returns a `Run` object for tracking its progress.
|
|
13
13
|
|
|
14
|
-
## The `start()`
|
|
14
|
+
## The `start()` function
|
|
15
15
|
|
|
16
|
-
The [`start()`](/docs/api-reference/workflow-api/start) function
|
|
16
|
+
The [`start()`](/docs/api-reference/workflow-api/start) function programmatically triggers workflow executions from runtime contexts such as API routes, Server Actions, or other server-side code. In v5, you can also call `start()` inside a workflow function to spawn a child run or continue work in a new run.
|
|
17
17
|
|
|
18
18
|
```typescript lineNumbers
|
|
19
19
|
import { start } from "workflow/api";
|
|
@@ -32,16 +32,21 @@ export async function POST(request: Request) {
|
|
|
32
32
|
}
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
**Key
|
|
35
|
+
**Key points:**
|
|
36
36
|
|
|
37
|
-
- `start()` returns immediately after enqueuing the workflow
|
|
37
|
+
- `start()` returns immediately after enqueuing the workflow. It doesn't wait for completion
|
|
38
38
|
- The first argument is your workflow function
|
|
39
39
|
- The second argument is an array of arguments to pass to the workflow (optional if the workflow takes no arguments)
|
|
40
40
|
- All arguments must be [serializable](/docs/foundations/serialization)
|
|
41
|
+
- On Worlds with a regional dimension, the optional `region` option pins the new run's storage, queuing, and streams to a specific region. See [Multi-region on the Vercel World](/worlds/vercel#multi-region)
|
|
41
42
|
|
|
42
|
-
**Learn more**: [`start()` API
|
|
43
|
+
**Learn more**: [`start()` API reference](/docs/api-reference/workflow-api/start)
|
|
43
44
|
|
|
44
|
-
|
|
45
|
+
<Callout type="info">
|
|
46
|
+
For parent-child workflow patterns, see [Workflow Composition](/cookbook/common-patterns/workflow-composition). For long-lived workflows that intentionally hand off to newer deployments with `deploymentId: "latest"`, see [Versioning](/docs/foundations/versioning).
|
|
47
|
+
</Callout>
|
|
48
|
+
|
|
49
|
+
## The `Run` object
|
|
45
50
|
|
|
46
51
|
When you call `start()`, it returns a [`Run`](/docs/api-reference/workflow-api/start#returns) object that provides access to the workflow's status and results.
|
|
47
52
|
|
|
@@ -61,24 +66,53 @@ const status = await run.status; // "running" | "completed" | "failed"
|
|
|
61
66
|
const result = await run.returnValue;
|
|
62
67
|
```
|
|
63
68
|
|
|
64
|
-
**Key
|
|
69
|
+
**Key properties:**
|
|
65
70
|
|
|
66
|
-
- `runId
|
|
67
|
-
- `status
|
|
68
|
-
- `returnValue
|
|
69
|
-
- `readable`
|
|
71
|
+
- `runId`: Unique identifier for this workflow run
|
|
72
|
+
- `status`: Current status of the workflow (async)
|
|
73
|
+
- `returnValue`: The value returned by the workflow function (async, blocks until completion)
|
|
74
|
+
- `readable`: `ReadableStream` for streaming updates from the workflow
|
|
70
75
|
|
|
71
76
|
<Callout type="info">
|
|
72
|
-
Most `Run` properties are async getters that return promises.
|
|
77
|
+
Most `Run` properties are async getters that return promises. `await` them to get their values. For a complete list of properties and methods, see the API reference below.
|
|
73
78
|
</Callout>
|
|
74
79
|
|
|
75
|
-
**Learn more**: [`Run` API
|
|
80
|
+
**Learn more**: [`Run` API reference](/docs/api-reference/workflow-api/start#returns)
|
|
81
|
+
|
|
82
|
+
## Common patterns
|
|
83
|
+
|
|
84
|
+
### Starting workflows from workflow functions
|
|
85
|
+
|
|
86
|
+
You can also call `start()` directly inside workflow functions to spawn child workflows. For choosing between this and awaiting a workflow function directly, see [Workflow Composition](/cookbook/common-patterns/workflow-composition).
|
|
87
|
+
|
|
88
|
+
```typescript lineNumbers
|
|
89
|
+
import { start } from "workflow/api";
|
|
90
|
+
import { childWorkflow } from "./workflows/child";
|
|
91
|
+
|
|
92
|
+
export async function parentWorkflow(inputValue: number) {
|
|
93
|
+
"use workflow";
|
|
94
|
+
|
|
95
|
+
const childRun = await start(childWorkflow, [inputValue]); // [!code highlight]
|
|
76
96
|
|
|
77
|
-
|
|
97
|
+
// childRun is a full Run object. Use it like normal.
|
|
98
|
+
const childResult = await childRun.returnValue;
|
|
99
|
+
return { childRunId: childRun.runId, childResult };
|
|
100
|
+
}
|
|
101
|
+
```
|
|
78
102
|
|
|
79
|
-
|
|
103
|
+
When you call `start()` inside a workflow function, it automatically executes through an internal step to maintain deterministic replay. The returned `Run` object works as it does outside workflows. Properties such as `.runId`, `.status`, and `.returnValue`, and methods such as `.cancel()`, are all available. Each property access or method call executes as a separate step.
|
|
80
104
|
|
|
81
|
-
|
|
105
|
+
<Callout type="info">
|
|
106
|
+
Inside workflow functions, each `Run` property access (e.g., `run.status`, `run.returnValue`) triggers a workflow step. This means each access is recorded in the event log and replayed deterministically.
|
|
107
|
+
</Callout>
|
|
108
|
+
|
|
109
|
+
<Callout type="warn">
|
|
110
|
+
Awaiting `returnValue` polls the child run every second, and the polling step holds its worker slot open until the child finishes. Size worker-based Worlds to cover the peak number of these polls in flight. If the child workflow is long-running, spawn it without awaiting `returnValue` and have it resume a [hook](/docs/foundations/hooks) when it completes. See the [`startAndWait()` pattern](/cookbook/advanced/child-workflows).
|
|
111
|
+
</Callout>
|
|
112
|
+
|
|
113
|
+
### Fire and forget
|
|
114
|
+
|
|
115
|
+
Start a workflow and immediately return to let it execute in the background:
|
|
82
116
|
|
|
83
117
|
```typescript lineNumbers
|
|
84
118
|
import { start } from "workflow/api";
|
|
@@ -96,7 +130,7 @@ export async function POST(request: Request) {
|
|
|
96
130
|
}
|
|
97
131
|
```
|
|
98
132
|
|
|
99
|
-
### Wait for
|
|
133
|
+
### Wait for completion
|
|
100
134
|
|
|
101
135
|
If you need to wait for the workflow to complete before responding:
|
|
102
136
|
|
|
@@ -115,12 +149,12 @@ export async function POST(request: Request) {
|
|
|
115
149
|
```
|
|
116
150
|
|
|
117
151
|
<Callout type="warn">
|
|
118
|
-
|
|
152
|
+
Waiting for `returnValue` can cause your API route to time out if the workflow takes a long time.
|
|
119
153
|
</Callout>
|
|
120
154
|
|
|
121
|
-
### Stream
|
|
155
|
+
### Stream updates to client
|
|
122
156
|
|
|
123
|
-
Stream
|
|
157
|
+
Stream updates from your workflow as it executes without waiting for completion:
|
|
124
158
|
|
|
125
159
|
```typescript lineNumbers
|
|
126
160
|
import { start } from "workflow/api";
|
|
@@ -144,7 +178,7 @@ export async function POST(request: Request) {
|
|
|
144
178
|
}
|
|
145
179
|
```
|
|
146
180
|
|
|
147
|
-
Your workflow can
|
|
181
|
+
Your workflow can write to the stream using [`getWritable()`](/docs/api-reference/workflow/get-writable):
|
|
148
182
|
|
|
149
183
|
```typescript lineNumbers
|
|
150
184
|
import { getWritable } from "workflow";
|
|
@@ -178,12 +212,12 @@ async function streamContentToClient(
|
|
|
178
212
|
```
|
|
179
213
|
|
|
180
214
|
<Callout type="info">
|
|
181
|
-
|
|
215
|
+
Use streams to show users real-time progress from AI workflows or intermediate results from long-running processes.
|
|
182
216
|
</Callout>
|
|
183
217
|
|
|
184
|
-
**Learn more**: [Streaming in
|
|
218
|
+
**Learn more**: [Streaming in workflows](/docs/foundations/serialization#streaming)
|
|
185
219
|
|
|
186
|
-
### Check
|
|
220
|
+
### Check status later
|
|
187
221
|
|
|
188
222
|
You can retrieve a workflow run later using its `runId` with [`getRun()`](/docs/api-reference/workflow-api/get-run):
|
|
189
223
|
|
|
@@ -209,10 +243,52 @@ export async function GET(request: Request) {
|
|
|
209
243
|
}
|
|
210
244
|
```
|
|
211
245
|
|
|
212
|
-
|
|
246
|
+
### Recursive and repeating workflows
|
|
247
|
+
|
|
248
|
+
A workflow can start a new instance of itself. This pattern prevents a single long-running workflow from accumulating too many events. Large event logs are slower to replay, more expensive to store, and harder to inspect in the UI. Breaking work into smaller runs that chain together keeps each run lean.
|
|
249
|
+
|
|
250
|
+
```typescript lineNumbers
|
|
251
|
+
import { start } from "workflow/api";
|
|
252
|
+
declare function fetchBatch(cursor?: string): Promise<{ items: string[]; nextCursor?: string }>; // @setup
|
|
253
|
+
declare function processBatch(items: string[]): Promise<void>; // @setup
|
|
254
|
+
|
|
255
|
+
export async function processQueue(cursor?: string) {
|
|
256
|
+
"use workflow";
|
|
257
|
+
|
|
258
|
+
const { items, nextCursor } = await fetchBatch(cursor);
|
|
259
|
+
await processBatch(items);
|
|
260
|
+
|
|
261
|
+
if (nextCursor) {
|
|
262
|
+
// Continue processing in a new workflow run
|
|
263
|
+
await start(processQueue, [nextCursor]); // [!code highlight]
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
This pattern also enables **repeating cron-like workflows**. A workflow can complete its work, sleep, and then schedule a new instance of itself. This creates an indefinite chain without allowing any single run to grow too large:
|
|
269
|
+
|
|
270
|
+
```typescript lineNumbers
|
|
271
|
+
import { sleep } from "workflow";
|
|
272
|
+
import { start } from "workflow/api";
|
|
273
|
+
declare function refreshMetrics(): Promise<void>; // @setup
|
|
274
|
+
|
|
275
|
+
export async function syncDashboard() {
|
|
276
|
+
"use workflow";
|
|
277
|
+
|
|
278
|
+
await refreshMetrics();
|
|
279
|
+
await sleep("1h");
|
|
280
|
+
|
|
281
|
+
// Schedule the next run
|
|
282
|
+
await start(syncDashboard); // [!code highlight]
|
|
283
|
+
}
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
#### Starting against the latest deployment
|
|
287
|
+
|
|
288
|
+
By default a chained run starts on the same deployment as its parent. For workflows that chain over long periods, pass [`deploymentId: "latest"`](/docs/api-reference/workflow-api/start#using-deploymentid-latest) so the next run picks up new code. [Versioning](/docs/foundations/versioning#self-upgrading-workflows) covers this pattern in full, including how the serialized state acts as the migration boundary between versions.
|
|
213
289
|
|
|
214
|
-
|
|
290
|
+
## Next steps
|
|
215
291
|
|
|
216
292
|
- Browse the [Cookbook](/cookbook) for copy-paste recipes covering composition, scheduling, timeouts, and more
|
|
217
|
-
- Explore [Errors
|
|
218
|
-
- Check the [`start()` API
|
|
293
|
+
- Explore [Errors and retrying](/docs/foundations/errors-and-retries) to handle failures
|
|
294
|
+
- Check the [`start()` API reference](/docs/api-reference/workflow-api/start) for complete details
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: Streaming
|
|
3
|
-
description: Stream data in real
|
|
3
|
+
description: Stream data in real time to clients for progress updates and incremental content delivery.
|
|
4
4
|
type: conceptual
|
|
5
|
-
summary: Stream
|
|
5
|
+
summary: Stream data to clients in real time without waiting for workflow completion.
|
|
6
6
|
prerequisites:
|
|
7
7
|
- /docs/foundations/workflows-and-steps
|
|
8
8
|
related:
|
|
@@ -10,9 +10,9 @@ related:
|
|
|
10
10
|
- /docs/ai/resumable-streams
|
|
11
11
|
---
|
|
12
12
|
|
|
13
|
-
Workflows can stream data in real
|
|
13
|
+
Workflows can stream data to clients in real time without waiting for the entire workflow to complete. Clients can receive progress updates, AI-generated content, log messages, and other incremental data as workflows execute.
|
|
14
14
|
|
|
15
|
-
## Getting
|
|
15
|
+
## Getting started with `getWritable()`
|
|
16
16
|
|
|
17
17
|
Every workflow run has a default writable stream that steps can write to using [`getWritable()`](/docs/api-reference/workflow/get-writable). Data written to this stream becomes immediately available to clients consuming the workflow's output.
|
|
18
18
|
|
|
@@ -38,7 +38,7 @@ export async function simpleStreamingWorkflow() {
|
|
|
38
38
|
}
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
### Consuming the
|
|
41
|
+
### Consuming the stream
|
|
42
42
|
|
|
43
43
|
Use the `Run` object's `readable` property to consume the stream from your API route:
|
|
44
44
|
|
|
@@ -58,7 +58,31 @@ export async function POST() {
|
|
|
58
58
|
|
|
59
59
|
When a client makes a request to this endpoint, they'll receive each message as it's written, without waiting for the workflow to complete.
|
|
60
60
|
|
|
61
|
-
###
|
|
61
|
+
### Avoiding function timeouts after client disconnects
|
|
62
|
+
|
|
63
|
+
On Vercel, `run.readable` and `run.getReadable()` reconnect to Workflow's stream storage while the workflow is still running. By default, a client disconnect does not terminate the Vercel Function serving the stream. If a user closes the page or stops the request, the function can therefore keep reconnecting until it reaches its maximum duration and fails with `FUNCTION_INVOCATION_TIMEOUT`.
|
|
64
|
+
|
|
65
|
+
For streaming routes using the Node.js runtime, opt in to [request cancellation](https://vercel.com/docs/functions/functions-api-reference#enable-cancellation) in `vercel.json`:
|
|
66
|
+
|
|
67
|
+
```json filename="vercel.json"
|
|
68
|
+
{
|
|
69
|
+
"functions": {
|
|
70
|
+
"app/api/stream/route.ts": {
|
|
71
|
+
"supportsCancellation": true
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Replace the function path with the path or glob for your streaming route. When the downstream client disconnects, Vercel terminates the matching function invocation instead of leaving its stream reader running. The workflow run and its durable stream continue independently, so the client can reconnect through another route invocation later.
|
|
78
|
+
|
|
79
|
+
<Callout type="warn">
|
|
80
|
+
Cancellation applies to every function matching the configured path or glob, even if the route does not listen to `request.signal`. Any other work in that invocation which is not wrapped in [`waitUntil`](https://vercel.com/docs/functions/functions-api-reference/vercel-functions-package#waituntil) or [`after`](https://nextjs.org/docs/app/api-reference/functions/after) can be lost. Only enable it for routes that are safe to terminate when their client disconnects.
|
|
81
|
+
</Callout>
|
|
82
|
+
|
|
83
|
+
This setting prevents abandoned stream readers from consuming the rest of a function invocation. It does not extend the function's maximum duration. An actively connected streaming response can still reach the configured limit, at which point the client should reconnect to the durable stream.
|
|
84
|
+
|
|
85
|
+
### Resuming streams from a specific point
|
|
62
86
|
|
|
63
87
|
Use `run.getReadable({ startIndex })` to resume a stream from a specific position. This is useful for reconnecting after timeouts or network interruptions:
|
|
64
88
|
|
|
@@ -85,7 +109,7 @@ export async function GET(
|
|
|
85
109
|
}
|
|
86
110
|
```
|
|
87
111
|
|
|
88
|
-
|
|
112
|
+
Clients can reconnect and continue receiving data from where they left off instead of restarting from the beginning.
|
|
89
113
|
|
|
90
114
|
`startIndex` also supports **negative values** to read relative to the end of the stream. For example, `startIndex: -5` starts 5 chunks before the current end. This is useful when you want to show the most recent output without reading the entire stream history.
|
|
91
115
|
|
|
@@ -103,31 +127,32 @@ If the absolute value exceeds the total number of chunks, reading starts from th
|
|
|
103
127
|
Because streams are live and continue receiving chunks, negative `startIndex` values resolve to different absolute positions on each call. Accurate pagination over a live stream requires cursor-based access, which is not yet supported. Keep this in mind when building clients that paginate over stream data.
|
|
104
128
|
</Callout>
|
|
105
129
|
|
|
106
|
-
## Streams as
|
|
130
|
+
## Streams as data types
|
|
107
131
|
|
|
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.
|
|
132
|
+
[`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. Workflow SDK lets you pass these standard types between functions while maintaining their streaming capabilities.
|
|
109
133
|
|
|
110
134
|
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
135
|
|
|
112
136
|
**Key properties:**
|
|
137
|
+
|
|
113
138
|
- Stream references can be passed between workflow and step functions
|
|
114
139
|
- Stream data flows directly without being stored in the event log
|
|
115
140
|
- Streams preserve their state across workflow suspension points
|
|
116
141
|
|
|
117
142
|
<Callout type="info">
|
|
118
|
-
**How
|
|
143
|
+
**How streams persist across workflow suspensions**
|
|
119
144
|
|
|
120
|
-
|
|
145
|
+
Persistent, resumable storage from the World implementation lets Workflow SDK streams maintain their state when workflows suspend and resume:
|
|
121
146
|
|
|
122
147
|
- **Vercel deployments**: Streams are backed by a performant Redis-based stream
|
|
123
148
|
- **Local development**: Stream chunks are stored in the filesystem
|
|
124
149
|
</Callout>
|
|
125
150
|
|
|
126
|
-
### Passing
|
|
151
|
+
### Passing streams as arguments
|
|
127
152
|
|
|
128
|
-
|
|
153
|
+
Because streams are serializable data types, you don't need to use [`getWritable()`](/docs/api-reference/workflow/get-writable). You can pass your own streams as arguments from outside a workflow into steps.
|
|
129
154
|
|
|
130
|
-
|
|
155
|
+
The following example passes a request body stream through a workflow to a step that processes it:
|
|
131
156
|
|
|
132
157
|
```typescript title="app/api/upload/route.ts" lineNumbers
|
|
133
158
|
import { start } from "workflow/api";
|
|
@@ -167,15 +192,15 @@ async function processInputStream(input: ReadableStream<Uint8Array>) {
|
|
|
167
192
|
}
|
|
168
193
|
```
|
|
169
194
|
|
|
170
|
-
## Important
|
|
195
|
+
## Important limitation
|
|
171
196
|
|
|
172
197
|
<Callout type="info">
|
|
173
|
-
**Streams
|
|
198
|
+
**Streams cannot be used directly in workflow context**
|
|
174
199
|
|
|
175
200
|
You cannot read from or write to streams directly within a workflow function. All stream operations must happen in step functions.
|
|
176
201
|
</Callout>
|
|
177
202
|
|
|
178
|
-
Workflow functions must be deterministic to support replay.
|
|
203
|
+
Workflow functions must be deterministic to support replay. Streams bypass the [event log](/docs/how-it-works/event-sourcing) for performance, so reading stream data in a workflow would break determinism because each replay could see different data. Requiring all stream operations to happen in steps ensures consistent behavior.
|
|
179
204
|
|
|
180
205
|
For more on determinism and replay, see [Workflows and Steps](/docs/foundations/workflows-and-steps).
|
|
181
206
|
|
|
@@ -214,7 +239,7 @@ async function writeToStream(data: string) {
|
|
|
214
239
|
}
|
|
215
240
|
```
|
|
216
241
|
|
|
217
|
-
## Namespaced
|
|
242
|
+
## Namespaced streams
|
|
218
243
|
|
|
219
244
|
Use `getWritable({ namespace: 'name' })` to create multiple independent streams for different types of data. This is useful when you want to separate logs, metrics, data outputs, or other distinct channels.
|
|
220
245
|
|
|
@@ -264,7 +289,7 @@ export async function multiStreamWorkflow() {
|
|
|
264
289
|
}
|
|
265
290
|
```
|
|
266
291
|
|
|
267
|
-
### Consuming
|
|
292
|
+
### Consuming namespaced streams
|
|
268
293
|
|
|
269
294
|
Use `run.getReadable({ namespace: 'name' })` to access specific streams:
|
|
270
295
|
|
|
@@ -289,9 +314,37 @@ export async function POST(request: Request) {
|
|
|
289
314
|
}
|
|
290
315
|
```
|
|
291
316
|
|
|
292
|
-
##
|
|
317
|
+
## Writing to another run's stream
|
|
318
|
+
|
|
319
|
+
`getRun(runId).getWritable()` appends to a stream owned by another run. This lets short-lived runs contribute to a long-lived holder run's stream using only its ID.
|
|
293
320
|
|
|
294
|
-
|
|
321
|
+
```typescript title="workflows/turn.ts" lineNumbers
|
|
322
|
+
import { getRun } from "workflow/api";
|
|
323
|
+
|
|
324
|
+
type SessionEvent = { turn: number; text: string };
|
|
325
|
+
|
|
326
|
+
async function runTurn(holderRunId: string, turn: number) {
|
|
327
|
+
"use step";
|
|
328
|
+
|
|
329
|
+
const writable = getRun(holderRunId).getWritable<SessionEvent>(); // [!code highlight]
|
|
330
|
+
const writer = writable.getWriter();
|
|
331
|
+
|
|
332
|
+
await writer.write({ turn, text: "done" });
|
|
333
|
+
writer.releaseLock(); // [!code highlight]
|
|
334
|
+
}
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
Pass `{ namespace: "name" }` to target a [namespaced stream](#namespaced-streams). The writable can also be forwarded through `start()` and into steps.
|
|
338
|
+
|
|
339
|
+
<Callout type="warn">
|
|
340
|
+
Contributors should call `releaseLock()`, which flushes pending writes. Calling `close()` closes the shared stream for every writer.
|
|
341
|
+
</Callout>
|
|
342
|
+
|
|
343
|
+
The API grants append access, not read access or additional authorization. The owning run controls the stream's lifecycle, and writes to an unknown run fail.
|
|
344
|
+
|
|
345
|
+
## Common patterns
|
|
346
|
+
|
|
347
|
+
### Progress updates for long-running tasks
|
|
295
348
|
|
|
296
349
|
Send incremental progress updates to keep users informed during lengthy workflows:
|
|
297
350
|
|
|
@@ -345,29 +398,19 @@ export async function batchProcessingWorkflow(items: string[]) {
|
|
|
345
398
|
}
|
|
346
399
|
```
|
|
347
400
|
|
|
348
|
-
### Streaming AI
|
|
401
|
+
### Streaming AI responses with `WorkflowAgent`
|
|
349
402
|
|
|
350
|
-
Stream AI-generated content using [`
|
|
403
|
+
Stream AI-generated content using AI SDK's [`WorkflowAgent`](https://ai-sdk.dev/v7/docs/agents/workflow-agent#workflowagent) from `@ai-sdk/workflow`. The agent writes `ModelCallStreamPart` chunks to the workflow stream, and route handlers convert them to UI message chunks with `createModelCallToUIChunkTransform()` before returning the response:
|
|
351
404
|
|
|
352
405
|
```typescript title="workflows/ai-assistant.ts" lineNumbers
|
|
353
|
-
import {
|
|
406
|
+
import { WorkflowAgent, type ModelCallStreamPart } from "@ai-sdk/workflow";
|
|
407
|
+
import { tool } from "ai";
|
|
354
408
|
import { getWritable } from "workflow";
|
|
355
409
|
import { z } from "zod";
|
|
356
|
-
import type { UIMessageChunk } from "ai";
|
|
357
410
|
|
|
358
411
|
async function searchFlights({ query }: { query: string }) {
|
|
359
412
|
"use step";
|
|
360
413
|
|
|
361
|
-
// Tools can emit progress updates to the stream
|
|
362
|
-
const writable = getWritable<UIMessageChunk>(); // [!code highlight]
|
|
363
|
-
const writer = writable.getWriter(); // [!code highlight]
|
|
364
|
-
await writer.write({ // [!code highlight]
|
|
365
|
-
type: "data-progress", // [!code highlight]
|
|
366
|
-
data: { message: `Searching flights for ${query}...` }, // [!code highlight]
|
|
367
|
-
transient: true, // [!code highlight]
|
|
368
|
-
}); // [!code highlight]
|
|
369
|
-
writer.releaseLock(); // [!code highlight]
|
|
370
|
-
|
|
371
414
|
// ... search logic ...
|
|
372
415
|
return { flights: [/* results */] };
|
|
373
416
|
}
|
|
@@ -375,27 +418,28 @@ async function searchFlights({ query }: { query: string }) {
|
|
|
375
418
|
export async function aiAssistantWorkflow(userMessage: string) {
|
|
376
419
|
"use workflow";
|
|
377
420
|
|
|
378
|
-
const agent = new
|
|
421
|
+
const agent = new WorkflowAgent({
|
|
379
422
|
model: "anthropic/claude-haiku-4.5",
|
|
380
|
-
|
|
423
|
+
instructions: "You are a helpful flight assistant.",
|
|
381
424
|
tools: {
|
|
382
|
-
searchFlights: {
|
|
425
|
+
searchFlights: tool({
|
|
383
426
|
description: "Search for flights",
|
|
384
427
|
inputSchema: z.object({ query: z.string() }),
|
|
385
428
|
execute: searchFlights,
|
|
386
|
-
},
|
|
429
|
+
}),
|
|
387
430
|
},
|
|
388
431
|
});
|
|
389
432
|
|
|
390
433
|
// LLM response will be streamed to the run's writable
|
|
391
434
|
await agent.stream({
|
|
392
435
|
messages: [{ role: "user", content: userMessage }],
|
|
393
|
-
writable: getWritable<
|
|
436
|
+
writable: getWritable<ModelCallStreamPart>(), // [!code highlight]
|
|
394
437
|
});
|
|
395
438
|
}
|
|
396
439
|
```
|
|
397
440
|
|
|
398
441
|
```typescript title="app/api/ai-assistant/route.ts" lineNumbers
|
|
442
|
+
import { createModelCallToUIChunkTransform } from "@ai-sdk/workflow";
|
|
399
443
|
import { createUIMessageStreamResponse } from "ai";
|
|
400
444
|
import { start } from "workflow/api";
|
|
401
445
|
import { aiAssistantWorkflow } from "./workflows/ai";
|
|
@@ -406,16 +450,16 @@ export async function POST(request: Request) {
|
|
|
406
450
|
const run = await start(aiAssistantWorkflow, [message]);
|
|
407
451
|
|
|
408
452
|
return createUIMessageStreamResponse({
|
|
409
|
-
stream: run.readable,
|
|
453
|
+
stream: run.readable.pipeThrough(createModelCallToUIChunkTransform()), // [!code highlight]
|
|
410
454
|
});
|
|
411
455
|
}
|
|
412
456
|
```
|
|
413
457
|
|
|
414
458
|
<Callout type="info">
|
|
415
|
-
For
|
|
459
|
+
For the full agent API and migration notes, see the [`WorkflowAgent` documentation](https://ai-sdk.dev/v7/docs/agents/workflow-agent#workflowagent).
|
|
416
460
|
</Callout>
|
|
417
461
|
|
|
418
|
-
### Streaming
|
|
462
|
+
### Streaming between steps
|
|
419
463
|
|
|
420
464
|
One step produces a stream and another step consumes it:
|
|
421
465
|
|
|
@@ -456,7 +500,7 @@ async function consumeData(readable: ReadableStream<number>) {
|
|
|
456
500
|
}
|
|
457
501
|
```
|
|
458
502
|
|
|
459
|
-
### Processing
|
|
503
|
+
### Processing large files without memory overhead
|
|
460
504
|
|
|
461
505
|
Process large files by streaming chunks through transformation steps:
|
|
462
506
|
|
|
@@ -497,7 +541,11 @@ async function uploadResult(stream: ReadableStream<Uint8Array>) {
|
|
|
497
541
|
}
|
|
498
542
|
```
|
|
499
543
|
|
|
500
|
-
## Best
|
|
544
|
+
## Best practices
|
|
545
|
+
|
|
546
|
+
**Batching and first-chunk latency:**
|
|
547
|
+
|
|
548
|
+
Writes are flushed immediately by default. The leading chunk of an idle stream dispatches as soon as it is written, and chunks arriving while a flush is in flight coalesce into the next batch. If you write bursts of many tiny chunks and prefer fewer round trips over first-chunk latency, set a group-commit window with the World's `streamFlushIntervalMs` option or the `WORKFLOW_STREAM_FLUSH_INTERVAL_MS` environment variable. See [Worlds configuration](/docs/configuration/worlds#streamflushintervalms).
|
|
501
549
|
|
|
502
550
|
**Release locks properly:**
|
|
503
551
|
|
|
@@ -515,7 +563,7 @@ Stream locks acquired in a step only apply within that step, not across other st
|
|
|
515
563
|
</Callout>
|
|
516
564
|
|
|
517
565
|
<Callout type="warn">
|
|
518
|
-
If a lock is not released, the
|
|
566
|
+
If a lock is not released, the invocation that ran the step cannot terminate. Even though the step returns and the workflow continues, the underlying request remains active until it times out and wastes compute resources.
|
|
519
567
|
</Callout>
|
|
520
568
|
|
|
521
569
|
**Close streams when done:**
|
|
@@ -541,7 +589,7 @@ const writer = writable.getWriter();
|
|
|
541
589
|
await writer.write({ /* typed data */ });
|
|
542
590
|
```
|
|
543
591
|
|
|
544
|
-
## Stream
|
|
592
|
+
## Stream failures
|
|
545
593
|
|
|
546
594
|
When a step returns a stream, the step is considered successful once it returns, even if the stream later encounters an error. The workflow won't automatically retry the step. The consumer of the stream must handle errors gracefully. For more on retry behavior, see [Errors and Retries](/docs/foundations/errors-and-retries).
|
|
547
595
|
|
|
@@ -584,17 +632,17 @@ export async function streamErrorWorkflow() {
|
|
|
584
632
|
```
|
|
585
633
|
|
|
586
634
|
<Callout type="info">
|
|
587
|
-
Stream errors don't trigger automatic retries for the producer step. Design your stream consumers to handle errors
|
|
635
|
+
Stream errors don't trigger automatic retries for the producer step. Design your stream consumers to handle errors. Because the stream is already in an errored state, retrying the consumer won't help. Use `FatalError` to fail the workflow immediately.
|
|
588
636
|
</Callout>
|
|
589
637
|
|
|
590
|
-
## Related
|
|
591
|
-
|
|
592
|
-
- [`getWritable()` API
|
|
593
|
-
- [`sleep()` API
|
|
594
|
-
- [`start()` API
|
|
595
|
-
- [`getRun()` API
|
|
596
|
-
- [world.streams](/docs/api-reference/workflow-
|
|
597
|
-
- [
|
|
598
|
-
- [Errors and
|
|
599
|
-
- [Serialization](/docs/foundations/serialization)
|
|
600
|
-
- [Workflows and
|
|
638
|
+
## Related documentation
|
|
639
|
+
|
|
640
|
+
- [`getWritable()` API reference](/docs/api-reference/workflow/get-writable): Get the workflow's writable stream
|
|
641
|
+
- [`sleep()` API reference](/docs/api-reference/workflow/sleep): Pause workflow execution for a duration
|
|
642
|
+
- [`start()` API reference](/docs/api-reference/workflow-api/start): Start workflows and access the `Run` object
|
|
643
|
+
- [`getRun()` API reference](/docs/api-reference/workflow-api/get-run): Retrieve runs and their streams later
|
|
644
|
+
- [`world.streams`](/docs/api-reference/workflow-runtime/world/streams): Use low-level stream read, write, and close operations through the World SDK
|
|
645
|
+
- [`WorkflowAgent`](https://ai-sdk.dev/v7/docs/agents/workflow-agent#workflowagent): Build AI agents with durable, resumable streaming support
|
|
646
|
+
- [Errors and retries](/docs/foundations/errors-and-retries): Understand error handling and retry behavior
|
|
647
|
+
- [Serialization](/docs/foundations/serialization): Understand which data types you can pass in workflows
|
|
648
|
+
- [Workflows and steps](/docs/foundations/workflows-and-steps): Learn the core concepts of workflow execution
|