workflow 5.0.0-beta.13 → 5.0.0-beta.15
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/docs/api-reference/index.mdx +24 -0
- package/docs/api-reference/meta.json +8 -0
- package/docs/api-reference/vitest/index.mdx +0 -6
- package/docs/api-reference/workflow/create-hook.mdx +32 -0
- package/docs/api-reference/workflow/create-webhook.mdx +1 -0
- package/docs/api-reference/workflow/experimental-set-attributes.mdx +3 -1
- package/docs/api-reference/workflow-api/index.mdx +6 -8
- package/docs/api-reference/workflow-api/start.mdx +3 -1
- package/docs/api-reference/workflow-astro/index.mdx +18 -0
- package/docs/api-reference/workflow-astro/meta.json +4 -0
- package/docs/api-reference/workflow-astro/workflow.mdx +45 -0
- package/docs/api-reference/workflow-errors/hook-conflict-error.mdx +60 -0
- package/docs/api-reference/workflow-errors/meta.json +5 -0
- package/docs/api-reference/workflow-errors/run-not-supported-error.mdx +58 -0
- package/docs/api-reference/workflow-errors/workflow-error.mdx +52 -0
- package/docs/api-reference/workflow-errors/workflow-run-not-completed-error.mdx +58 -0
- package/docs/api-reference/workflow-errors/workflow-runtime-error.mdx +58 -0
- package/docs/api-reference/workflow-nest/configure-workflow-controller.mdx +33 -0
- package/docs/api-reference/workflow-nest/index.mdx +31 -0
- package/docs/api-reference/workflow-nest/meta.json +9 -0
- package/docs/api-reference/workflow-nest/nest-local-builder.mdx +64 -0
- package/docs/api-reference/workflow-nest/workflow-controller.mdx +40 -0
- package/docs/api-reference/workflow-nest/workflow-module.mdx +74 -0
- package/docs/api-reference/workflow-nitro/index.mdx +59 -0
- package/docs/api-reference/workflow-nuxt/index.mdx +47 -0
- package/docs/api-reference/workflow-observability/hydrate-data.mdx +35 -0
- package/docs/api-reference/workflow-observability/hydrate-resource-io.mdx +62 -0
- package/docs/api-reference/workflow-observability/index.mdx +64 -0
- package/docs/api-reference/workflow-observability/meta.json +11 -0
- package/docs/api-reference/workflow-observability/observability-revivers.mdx +50 -0
- package/docs/api-reference/workflow-observability/parse-class-name.mdx +41 -0
- package/docs/api-reference/workflow-observability/parse-step-name.mdx +40 -0
- package/docs/api-reference/workflow-observability/parse-workflow-name.mdx +55 -0
- package/docs/api-reference/workflow-runtime/create-world.mdx +39 -0
- package/docs/api-reference/workflow-runtime/get-world-handlers.mdx +44 -0
- package/docs/api-reference/{workflow-api → workflow-runtime}/get-world.mdx +7 -10
- package/docs/api-reference/workflow-runtime/health-check.mdx +50 -0
- package/docs/api-reference/workflow-runtime/index.mdx +43 -0
- package/docs/api-reference/workflow-runtime/meta.json +12 -0
- package/docs/api-reference/workflow-runtime/set-world.mdx +49 -0
- package/docs/api-reference/workflow-runtime/workflow-entrypoint.mdx +42 -0
- package/docs/api-reference/{workflow-api → workflow-runtime}/world/index.mdx +5 -8
- package/docs/api-reference/workflow-runtime/world/meta.json +4 -0
- package/docs/api-reference/{workflow-api → workflow-runtime}/world/queue.mdx +2 -2
- package/docs/api-reference/{workflow-api → workflow-runtime}/world/storage.mdx +5 -4
- package/docs/api-reference/{workflow-api → workflow-runtime}/world/streams.mdx +2 -2
- package/docs/api-reference/workflow-serde/index.mdx +0 -1
- package/docs/api-reference/workflow-serde/workflow-deserialize.mdx +1 -2
- package/docs/api-reference/workflow-serde/workflow-serialize.mdx +1 -2
- package/docs/api-reference/workflow-sveltekit/index.mdx +18 -0
- package/docs/api-reference/workflow-sveltekit/meta.json +4 -0
- package/docs/api-reference/workflow-sveltekit/workflow-plugin.mdx +42 -0
- package/docs/api-reference/workflow-vite/index.mdx +18 -0
- package/docs/api-reference/workflow-vite/meta.json +4 -0
- package/docs/api-reference/workflow-vite/workflow.mdx +48 -0
- package/docs/changelog/attributes-mvp.mdx +15 -3
- package/docs/changelog/eager-processing.mdx +26 -6
- package/docs/errors/index.mdx +3 -0
- package/docs/errors/step-executed-multiple-times.mdx +23 -0
- package/docs/foundations/hooks.mdx +29 -0
- package/docs/foundations/streaming.mdx +1 -1
- package/docs/foundations/versioning.mdx +1 -1
- package/docs/how-it-works/encryption.mdx +2 -2
- package/docs/how-it-works/event-sourcing.mdx +2 -2
- package/docs/observability/attributes.mdx +12 -5
- package/package.json +10 -10
- package/docs/api-reference/workflow-api/world/meta.json +0 -4
- package/docs/api-reference/workflow-api/world/observability.mdx +0 -164
|
@@ -17,9 +17,33 @@ All the functions and primitives that come with Workflow SDK by package.
|
|
|
17
17
|
<Card title="workflow/api" href="/docs/api-reference/workflow-api">
|
|
18
18
|
API reference for runtime functions from the `workflow/api` package.
|
|
19
19
|
</Card>
|
|
20
|
+
<Card title="workflow/runtime" href="/docs/api-reference/workflow-runtime">
|
|
21
|
+
Runtime functions for resolving the World instance and the low-level World SDK.
|
|
22
|
+
</Card>
|
|
23
|
+
<Card title="workflow/observability" href="/docs/api-reference/workflow-observability">
|
|
24
|
+
Utilities to hydrate step I/O, parse display names, and decrypt workflow data.
|
|
25
|
+
</Card>
|
|
20
26
|
<Card title="workflow/next" href="/docs/api-reference/workflow-next">
|
|
21
27
|
Next.js integration for Workflow SDK that automatically configures bundling and runtime support.
|
|
22
28
|
</Card>
|
|
29
|
+
<Card title="workflow/nitro" href="/docs/api-reference/workflow-nitro">
|
|
30
|
+
Nitro module for workflow bundling and runtime support.
|
|
31
|
+
</Card>
|
|
32
|
+
<Card title="workflow/nuxt" href="/docs/api-reference/workflow-nuxt">
|
|
33
|
+
Nuxt module for workflow bundling and runtime support.
|
|
34
|
+
</Card>
|
|
35
|
+
<Card title="workflow/sveltekit" href="/docs/api-reference/workflow-sveltekit">
|
|
36
|
+
SvelteKit Vite plugin for workflow bundling and runtime support.
|
|
37
|
+
</Card>
|
|
38
|
+
<Card title="workflow/astro" href="/docs/api-reference/workflow-astro">
|
|
39
|
+
Astro integration for workflow bundling and runtime support.
|
|
40
|
+
</Card>
|
|
41
|
+
<Card title="workflow/vite" href="/docs/api-reference/workflow-vite">
|
|
42
|
+
Standalone Vite plugin for workflow bundling and runtime support.
|
|
43
|
+
</Card>
|
|
44
|
+
<Card title="workflow/nest" href="/docs/api-reference/workflow-nest">
|
|
45
|
+
NestJS module for workflow bundling and runtime support.
|
|
46
|
+
</Card>
|
|
23
47
|
<Card title="workflow/errors" href="/docs/api-reference/workflow-errors">
|
|
24
48
|
Semantic error types for handling workflow storage backend failures.
|
|
25
49
|
</Card>
|
|
@@ -4,7 +4,15 @@
|
|
|
4
4
|
"workflow-globals",
|
|
5
5
|
"workflow",
|
|
6
6
|
"workflow-api",
|
|
7
|
+
"workflow-runtime",
|
|
8
|
+
"workflow-observability",
|
|
7
9
|
"workflow-next",
|
|
10
|
+
"workflow-nitro",
|
|
11
|
+
"workflow-nuxt",
|
|
12
|
+
"workflow-sveltekit",
|
|
13
|
+
"workflow-astro",
|
|
14
|
+
"workflow-vite",
|
|
15
|
+
"workflow-nest",
|
|
8
16
|
"workflow-errors",
|
|
9
17
|
"workflow-serde",
|
|
10
18
|
"workflow-ai",
|
|
@@ -11,7 +11,6 @@ The `@workflow/vitest` package provides a Vitest plugin and test helpers for run
|
|
|
11
11
|
|
|
12
12
|
Returns a Vite plugin array that handles SWC transforms, bundle building, and in-process handler registration automatically.
|
|
13
13
|
|
|
14
|
-
{/* @skip-typecheck - @workflow/vitest not available in docs-typecheck */}
|
|
15
14
|
|
|
16
15
|
```typescript
|
|
17
16
|
import { defineConfig } from "vitest/config";
|
|
@@ -24,7 +23,6 @@ export default defineConfig({
|
|
|
24
23
|
|
|
25
24
|
Pass a [`WorkflowTestOptions`](#workflowtestoptions) object when your project uses a non-standard layout — for example, a monorepo where `workflows/` does not live at the Vitest config's directory, or when the default `.workflow-data` / `.workflow-vitest` output locations need to move. The plugin forwards these paths to `buildWorkflowTests()` and `setupWorkflowTests()` through Vitest's per-project provided context, so each Vitest workspace project stays isolated.
|
|
26
25
|
|
|
27
|
-
{/* @skip-typecheck - @workflow/vitest not available in docs-typecheck */}
|
|
28
26
|
|
|
29
27
|
```typescript
|
|
30
28
|
import { defineConfig } from "vitest/config";
|
|
@@ -54,7 +52,6 @@ export default defineConfig({
|
|
|
54
52
|
|
|
55
53
|
Builds workflow and step bundles to disk. Called automatically by the `workflow()` plugin in `globalSetup`. Use directly only for [manual setup](/docs/testing#manual-setup).
|
|
56
54
|
|
|
57
|
-
{/* @skip-typecheck - @workflow/vitest not available in docs-typecheck */}
|
|
58
55
|
|
|
59
56
|
```typescript
|
|
60
57
|
import { buildWorkflowTests } from "@workflow/vitest";
|
|
@@ -76,7 +73,6 @@ Sets up an in-process workflow runtime in each test worker. Imports pre-built bu
|
|
|
76
73
|
|
|
77
74
|
Called automatically by the `workflow()` plugin in `setupFiles`. Use directly only for [manual setup](/docs/testing#manual-setup).
|
|
78
75
|
|
|
79
|
-
{/* @skip-typecheck - @workflow/vitest not available in docs-typecheck */}
|
|
80
76
|
|
|
81
77
|
```typescript
|
|
82
78
|
import { beforeAll, afterAll } from "vitest";
|
|
@@ -118,7 +114,6 @@ Tears down the workflow test world. Clears the global world and closes the Local
|
|
|
118
114
|
|
|
119
115
|
Polls the event log until the workflow has a pending `sleep()` call — one with a `wait_created` event but no corresponding `wait_completed` event. Returns the correlation ID of the pending sleep, which can be passed to [`wakeUp()`](/docs/api-reference/workflow-api/get-run) to target a specific sleep.
|
|
120
116
|
|
|
121
|
-
{/* @skip-typecheck - @workflow/vitest not available in docs-typecheck */}
|
|
122
117
|
|
|
123
118
|
```typescript
|
|
124
119
|
import { waitForSleep } from "@workflow/vitest"; // [!code highlight]
|
|
@@ -147,7 +142,6 @@ await getRun(run.runId).wakeUp({ correlationIds: [sleepId] }); // [!code highlig
|
|
|
147
142
|
|
|
148
143
|
Polls the hook list and event log until a hook matching the optional `token` filter exists that hasn't been received yet. Returns the matching hook object.
|
|
149
144
|
|
|
150
|
-
{/* @skip-typecheck - @workflow/vitest not available in docs-typecheck */}
|
|
151
145
|
|
|
152
146
|
```typescript
|
|
153
147
|
import { waitForHook } from "@workflow/vitest"; // [!code highlight]
|
|
@@ -65,6 +65,8 @@ export default Hook;`}
|
|
|
65
65
|
|
|
66
66
|
The returned `Hook` object also implements `AsyncIterable<T>`, which allows you to iterate over incoming payloads using `for await...of` syntax.
|
|
67
67
|
|
|
68
|
+
Use `hook.getConflict()` to check whether the hook token is already claimed by another active hook, without waiting for hook payload data. Calling `createHook()` on its own does not register the hook — registration is only committed when the workflow suspends. Awaiting `hook.getConflict()` suspends the workflow to commit the registration, then resolves with `null` once `hook_created` is recorded, or with the conflicting [`Run`](/docs/api-reference/workflow-api/get-run) if another active hook already owns the same token.
|
|
69
|
+
|
|
68
70
|
## Examples
|
|
69
71
|
|
|
70
72
|
### Basic Usage
|
|
@@ -112,6 +114,36 @@ export async function slackBotWorkflow(channelId: string) {
|
|
|
112
114
|
}
|
|
113
115
|
```
|
|
114
116
|
|
|
117
|
+
### Detecting Token Conflicts
|
|
118
|
+
|
|
119
|
+
Use `hook.getConflict()` when the workflow needs to claim a hook token before doing other work, but does not need a payload yet:
|
|
120
|
+
|
|
121
|
+
```typescript lineNumbers
|
|
122
|
+
import { createHook } from "workflow";
|
|
123
|
+
|
|
124
|
+
declare function chargeOrder(orderId: string): Promise<void>; // @setup
|
|
125
|
+
|
|
126
|
+
async function processOrder(orderId: string) {
|
|
127
|
+
"use workflow";
|
|
128
|
+
|
|
129
|
+
using hook = createHook({ // [!code highlight]
|
|
130
|
+
token: `order:${orderId}` // [!code highlight]
|
|
131
|
+
}); // [!code highlight]
|
|
132
|
+
|
|
133
|
+
const conflict = await hook.getConflict(); // [!code highlight]
|
|
134
|
+
if (conflict) { // [!code highlight]
|
|
135
|
+
// Another active workflow run already owns this token.
|
|
136
|
+
return { dedupedTo: conflict.runId };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
await chargeOrder(orderId);
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Because `createHook()` alone does not suspend the workflow, awaiting `hook.getConflict()` is what actually suspends the run and commits the hook registration. It only waits for registration — to receive payload data from a future `resumeHook()` call, await the hook itself or iterate it with `for await...of`.
|
|
144
|
+
|
|
145
|
+
On a conflict, the resolved value is a `Run` handle for the run that currently owns the token, with durable step-backed accessors. The duplicate run can decide in code how to handle it: return or log `conflict.runId`, inspect `await conflict.status`, wait on `await conflict.returnValue`, or cancel the owner with `await conflict.cancel()` and continue in the current run. See [Idempotency](/docs/foundations/idempotency) for these strategies in context.
|
|
146
|
+
|
|
115
147
|
### Waiting for Multiple Payloads
|
|
116
148
|
|
|
117
149
|
You can also wait for multiple payloads by using the `for await...of` syntax.
|
|
@@ -55,6 +55,7 @@ The returned `Webhook` object has:
|
|
|
55
55
|
|
|
56
56
|
- `url`: The HTTP endpoint URL that external systems can call
|
|
57
57
|
- `token`: The unique token identifying this webhook
|
|
58
|
+
- `getConflict()`: A promise that resolves with the conflicting run if another active hook already owns this token, or `null` once the webhook endpoint has been registered
|
|
58
59
|
- Implements `AsyncIterable<T>` for handling multiple requests, where `T` is `Request` (default) or `RequestWithResponse` (manual mode)
|
|
59
60
|
|
|
60
61
|
When using `createWebhook({ respondWith: 'manual' })`, the resolved request type is `RequestWithResponse`, which extends the standard `Request` interface with a `respondWith(response: Response): Promise<void>` method for sending custom responses back to the caller.
|
|
@@ -60,4 +60,6 @@ Attribute keys must be 1-256 characters, values must be strings up to 256 bytes,
|
|
|
60
60
|
|
|
61
61
|
Validation errors throw [`FatalError`](/docs/api-reference/workflow/fatal-error) and fail the run before an attribute write is attempted.
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
Calls from both workflow and step bodies append a native `attr_set` event, which the World materializes onto `run.attributes`. Workflow-originated events record a workflow writer; step-originated events record the originating step ID and attempt.
|
|
64
|
+
|
|
65
|
+
Native attributes require spec version 4 or later. Step-body storage errors throw from `experimental_setAttributes`; catch them inside the step if the write should be best-effort. Workflow-body writes are committed when the workflow suspends: transient storage errors are retried with the suspension, while a write the World rejects as invalid — such as exceeding the per-run attribute cap across multiple calls — fails the run with the validation error.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: "workflow/api"
|
|
3
|
-
description: Runtime functions to inspect runs, start workflows, and
|
|
3
|
+
description: Runtime functions to inspect runs, start workflows, and manage hooks.
|
|
4
4
|
type: overview
|
|
5
5
|
summary: Explore runtime functions for starting workflows, inspecting runs, and managing hooks.
|
|
6
6
|
---
|
|
@@ -9,7 +9,7 @@ API reference for runtime functions from the `workflow/api` package.
|
|
|
9
9
|
|
|
10
10
|
## Functions
|
|
11
11
|
|
|
12
|
-
The API package is for access and introspection of workflow data to inspect runs, start new runs,
|
|
12
|
+
The API package is for access and introspection of workflow data to inspect runs, start new runs, and manage hooks.
|
|
13
13
|
|
|
14
14
|
<Cards>
|
|
15
15
|
<Card href="/docs/api-reference/workflow-api/start" title="start()">
|
|
@@ -27,10 +27,8 @@ The API package is for access and introspection of workflow data to inspect runs
|
|
|
27
27
|
<Card href="/docs/api-reference/workflow-api/get-run" title="getRun()">
|
|
28
28
|
Get workflow run status and metadata without waiting for completion.
|
|
29
29
|
</Card>
|
|
30
|
-
<Card href="/docs/api-reference/workflow-api/get-world" title="getWorld()">
|
|
31
|
-
Async: resolve the World instance for storage, queuing, and streaming backends.
|
|
32
|
-
</Card>
|
|
33
|
-
<Card href="/docs/api-reference/workflow-api/world" title="World SDK">
|
|
34
|
-
Low-level API for inspecting runs, steps, events, hooks, streams, and queues.
|
|
35
|
-
</Card>
|
|
36
30
|
</Cards>
|
|
31
|
+
|
|
32
|
+
<Callout type="info">
|
|
33
|
+
Looking for `getWorld()` and the World SDK? They are exported from `workflow/runtime` — see the [`workflow/runtime` reference](/docs/api-reference/workflow-runtime).
|
|
34
|
+
</Callout>
|
|
@@ -56,6 +56,7 @@ Learn more about [`WorkflowReadableStreamOptions`](/docs/api-reference/workflow-
|
|
|
56
56
|
* The function returns immediately after enqueuing the workflow - it doesn't wait for the workflow to complete.
|
|
57
57
|
* All arguments must be [serializable](/docs/foundations/serialization).
|
|
58
58
|
* When `deploymentId` is provided, the argument types and return type become `unknown` since there is no guarantee the workflow function's types will be consistent across different deployments.
|
|
59
|
+
* `attributes` seeds plaintext run metadata as part of creation and requires a World implementing spec version 4 or later.
|
|
59
60
|
|
|
60
61
|
<Callout type="info">
|
|
61
62
|
If `start()` throws `'start' received an invalid workflow function. Ensure the Workflow Development Kit is configured correctly and the function includes a 'use workflow' directive.`, the passed function was not transformed as a workflow. The two most common causes are a missing `"use workflow"` directive or missing framework integration. See [start-invalid-workflow-function](/docs/errors/start-invalid-workflow-function).
|
|
@@ -79,7 +80,8 @@ import { start } from "workflow/api";
|
|
|
79
80
|
import { myWorkflow } from "./workflows/my-workflow";
|
|
80
81
|
|
|
81
82
|
const run = await start(myWorkflow, ["arg1", "arg2"], { // [!code highlight]
|
|
82
|
-
deploymentId: "custom-deployment-id" // [!code highlight]
|
|
83
|
+
deploymentId: "custom-deployment-id", // [!code highlight]
|
|
84
|
+
attributes: { source: "checkout" } // [!code highlight]
|
|
83
85
|
}); // [!code highlight]
|
|
84
86
|
```
|
|
85
87
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "workflow/astro"
|
|
3
|
+
description: Astro integration for automatic workflow bundling and route registration.
|
|
4
|
+
type: overview
|
|
5
|
+
summary: Explore the Astro integration for automatic workflow bundling and runtime support.
|
|
6
|
+
related:
|
|
7
|
+
- /docs/getting-started/astro
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
Astro integration for Workflow SDK that transforms workflow code and builds the workflow bundles.
|
|
11
|
+
|
|
12
|
+
## Functions
|
|
13
|
+
|
|
14
|
+
<Cards>
|
|
15
|
+
<Card title="workflow()" href="/docs/api-reference/workflow-astro/workflow">
|
|
16
|
+
Astro integration that transforms workflow code (`"use step"`/`"use workflow"` directives)
|
|
17
|
+
</Card>
|
|
18
|
+
</Cards>
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: workflow
|
|
3
|
+
description: Configure Astro to transform workflow directives.
|
|
4
|
+
type: reference
|
|
5
|
+
summary: Add the workflow integration to your Astro config to enable workflow directive transformation.
|
|
6
|
+
prerequisites:
|
|
7
|
+
- /docs/getting-started/astro
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
Returns an Astro integration that transforms workflow code (`"use step"`/`"use workflow"` directives) and builds the workflow bundles.
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
To enable `"use step"` and `"use workflow"` directives while developing locally or deploying to production, add `workflow()` to the `integrations` array of your Astro config.
|
|
15
|
+
|
|
16
|
+
```typescript title="astro.config.mjs" lineNumbers
|
|
17
|
+
// @ts-check
|
|
18
|
+
import { defineConfig } from "astro/config";
|
|
19
|
+
import { workflow } from "workflow/astro"; // [!code highlight]
|
|
20
|
+
|
|
21
|
+
// https://astro.build/config
|
|
22
|
+
export default defineConfig({
|
|
23
|
+
integrations: [workflow()], // [!code highlight]
|
|
24
|
+
});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
The integration registers the workflow Vite transform plugins during `astro:config:setup` and builds the workflow bundles — locally during config setup, or via the Vercel builder after `astro:build:done` when deploying to Vercel.
|
|
28
|
+
|
|
29
|
+
## API Signature
|
|
30
|
+
|
|
31
|
+
### Parameters
|
|
32
|
+
|
|
33
|
+
| Parameter | Type | Description |
|
|
34
|
+
| --- | --- | --- |
|
|
35
|
+
| `options` | `WorkflowPluginOptions` | Optional. Configures the workflow build. |
|
|
36
|
+
|
|
37
|
+
#### WorkflowPluginOptions
|
|
38
|
+
|
|
39
|
+
| Option | Type | Default | Description |
|
|
40
|
+
| --- | --- | --- | --- |
|
|
41
|
+
| `sourcemap` | `boolean \| 'inline' \| 'linked' \| 'external' \| 'both'` | `'inline'` | Controls source maps on generated workflow bundles. Accepts the same values as esbuild's `sourcemap` option. Set to `false` for smaller function bundles (useful for staying under the Vercel 250MB function size limit) at the cost of stack traces pointing at generated code. Can also be set via the `WORKFLOW_SOURCEMAP` environment variable. |
|
|
42
|
+
|
|
43
|
+
### Returns
|
|
44
|
+
|
|
45
|
+
Returns an `AstroIntegration` object to include in the `integrations` array of your Astro config.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: HookConflictError
|
|
3
|
+
description: Thrown when creating a hook with a token that is already in use by another workflow run.
|
|
4
|
+
type: reference
|
|
5
|
+
summary: Catch HookConflictError when a hook token is already claimed by another active workflow run.
|
|
6
|
+
related:
|
|
7
|
+
- /docs/api-reference/workflow/create-hook
|
|
8
|
+
- /docs/foundations/hooks
|
|
9
|
+
- /docs/errors/hook-conflict
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
`HookConflictError` is thrown when creating a hook with a token that is already in use by another active workflow run. Hook tokens must be unique across all running workflows — see the [hook-conflict](/docs/errors/hook-conflict) error guide for resolution strategies.
|
|
13
|
+
|
|
14
|
+
```typescript lineNumbers
|
|
15
|
+
import { HookConflictError } from "workflow/errors"
|
|
16
|
+
declare function startApprovalWorkflow(token: string): Promise<void>; // @setup
|
|
17
|
+
declare const token: string; // @setup
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
await startApprovalWorkflow(token);
|
|
21
|
+
} catch (error) {
|
|
22
|
+
if (HookConflictError.is(error)) { // [!code highlight]
|
|
23
|
+
console.error(
|
|
24
|
+
`Token "${error.token}" already in use by run ${error.conflictingRunId}`
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## API Signature
|
|
31
|
+
|
|
32
|
+
### Properties
|
|
33
|
+
|
|
34
|
+
<TSDoc
|
|
35
|
+
definition={`
|
|
36
|
+
interface HookConflictError {
|
|
37
|
+
/** The hook token that conflicted. */
|
|
38
|
+
token: string;
|
|
39
|
+
/** The run ID of the workflow currently holding the token, when known. */
|
|
40
|
+
conflictingRunId?: string;
|
|
41
|
+
/** The error message. */
|
|
42
|
+
message: string;
|
|
43
|
+
}
|
|
44
|
+
export default HookConflictError;`}
|
|
45
|
+
/>
|
|
46
|
+
|
|
47
|
+
### Static Methods
|
|
48
|
+
|
|
49
|
+
#### `HookConflictError.is(value)`
|
|
50
|
+
|
|
51
|
+
Type-safe check for `HookConflictError` instances. Preferred over `instanceof` because it works across module boundaries and VM contexts.
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { HookConflictError } from "workflow/errors"
|
|
55
|
+
declare const error: unknown; // @setup
|
|
56
|
+
|
|
57
|
+
if (HookConflictError.is(error)) {
|
|
58
|
+
// error is typed as HookConflictError
|
|
59
|
+
}
|
|
60
|
+
```
|
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"title": "workflow/errors",
|
|
3
3
|
"pages": [
|
|
4
|
+
"workflow-error",
|
|
4
5
|
"hook-not-found-error",
|
|
6
|
+
"hook-conflict-error",
|
|
5
7
|
"step-not-registered-error",
|
|
6
8
|
"workflow-not-registered-error",
|
|
7
9
|
"workflow-run-not-found-error",
|
|
8
10
|
"workflow-run-failed-error",
|
|
9
11
|
"workflow-run-cancelled-error",
|
|
12
|
+
"workflow-run-not-completed-error",
|
|
13
|
+
"workflow-runtime-error",
|
|
10
14
|
"workflow-world-error",
|
|
11
15
|
"throttle-error",
|
|
12
16
|
"entity-conflict-error",
|
|
13
17
|
"run-expired-error",
|
|
18
|
+
"run-not-supported-error",
|
|
14
19
|
"too-early-error"
|
|
15
20
|
]
|
|
16
21
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: RunNotSupportedError
|
|
3
|
+
description: Thrown when a workflow run requires a newer workflow spec version than the installed SDK supports.
|
|
4
|
+
type: reference
|
|
5
|
+
summary: Catch RunNotSupportedError when stored run data requires a newer workflow package version.
|
|
6
|
+
related:
|
|
7
|
+
- /docs/foundations/versioning
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
`RunNotSupportedError` is thrown when reading a workflow run whose data was written with a newer workflow spec version than the running SDK supports. This typically means the run was created by a newer version of the `workflow` package — upgrade the package to process it.
|
|
11
|
+
|
|
12
|
+
```typescript lineNumbers
|
|
13
|
+
import { RunNotSupportedError } from "workflow/errors"
|
|
14
|
+
declare function readRun(runId: string): Promise<unknown>; // @setup
|
|
15
|
+
declare const runId: string; // @setup
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
await readRun(runId);
|
|
19
|
+
} catch (error) {
|
|
20
|
+
if (RunNotSupportedError.is(error)) { // [!code highlight]
|
|
21
|
+
console.error(
|
|
22
|
+
`Run requires spec v${error.runSpecVersion}, world supports v${error.worldSpecVersion}`
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## API Signature
|
|
29
|
+
|
|
30
|
+
### Properties
|
|
31
|
+
|
|
32
|
+
<TSDoc
|
|
33
|
+
definition={`
|
|
34
|
+
interface RunNotSupportedError {
|
|
35
|
+
/** The spec version the run's stored data requires. */
|
|
36
|
+
runSpecVersion: number;
|
|
37
|
+
/** The spec version the current World supports. */
|
|
38
|
+
worldSpecVersion: number;
|
|
39
|
+
/** The error message. */
|
|
40
|
+
message: string;
|
|
41
|
+
}
|
|
42
|
+
export default RunNotSupportedError;`}
|
|
43
|
+
/>
|
|
44
|
+
|
|
45
|
+
### Static Methods
|
|
46
|
+
|
|
47
|
+
#### `RunNotSupportedError.is(value)`
|
|
48
|
+
|
|
49
|
+
Type-safe check for `RunNotSupportedError` instances. Preferred over `instanceof` because it works across module boundaries and VM contexts.
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import { RunNotSupportedError } from "workflow/errors"
|
|
53
|
+
declare const error: unknown; // @setup
|
|
54
|
+
|
|
55
|
+
if (RunNotSupportedError.is(error)) {
|
|
56
|
+
// error is typed as RunNotSupportedError
|
|
57
|
+
}
|
|
58
|
+
```
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: WorkflowError
|
|
3
|
+
description: Base class for all workflow error types.
|
|
4
|
+
type: reference
|
|
5
|
+
summary: All errors thrown by the Workflow SDK extend WorkflowError.
|
|
6
|
+
related:
|
|
7
|
+
- /docs/foundations/errors-and-retries
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
`WorkflowError` is the base class that all Workflow SDK error types extend, such as [`WorkflowRunFailedError`](/docs/api-reference/workflow-errors/workflow-run-failed-error) and [`HookNotFoundError`](/docs/api-reference/workflow-errors/hook-not-found-error). It extends `Error` with an optional `cause` and, for some subclasses, a link to the relevant error documentation appended to the message.
|
|
11
|
+
|
|
12
|
+
```typescript lineNumbers
|
|
13
|
+
import { WorkflowError } from "workflow/errors"
|
|
14
|
+
|
|
15
|
+
const error = new WorkflowError("something went wrong", {
|
|
16
|
+
cause: new Error("underlying cause"),
|
|
17
|
+
});
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## API Signature
|
|
21
|
+
|
|
22
|
+
### Properties
|
|
23
|
+
|
|
24
|
+
<TSDoc
|
|
25
|
+
definition={`
|
|
26
|
+
interface WorkflowError {
|
|
27
|
+
/** The error message. */
|
|
28
|
+
message: string;
|
|
29
|
+
/** The underlying cause, when provided. */
|
|
30
|
+
cause?: unknown;
|
|
31
|
+
}
|
|
32
|
+
export default WorkflowError;`}
|
|
33
|
+
/>
|
|
34
|
+
|
|
35
|
+
### Static Methods
|
|
36
|
+
|
|
37
|
+
#### `WorkflowError.is(value)`
|
|
38
|
+
|
|
39
|
+
Type-safe check for `WorkflowError` instances. Preferred over `instanceof` because it works across module boundaries and VM contexts.
|
|
40
|
+
|
|
41
|
+
<Callout type="warn">
|
|
42
|
+
`WorkflowError.is()` matches only direct `WorkflowError` instances — not subclasses, which override the error name it checks. To handle a specific error type, use that subclass's own `.is()` method (e.g. `WorkflowRunFailedError.is(error)`).
|
|
43
|
+
</Callout>
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
import { WorkflowError } from "workflow/errors"
|
|
47
|
+
declare const error: unknown; // @setup
|
|
48
|
+
|
|
49
|
+
if (WorkflowError.is(error)) {
|
|
50
|
+
// error is typed as WorkflowError
|
|
51
|
+
}
|
|
52
|
+
```
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: WorkflowRunNotCompletedError
|
|
3
|
+
description: Thrown when requesting the result of a workflow run that has not completed yet.
|
|
4
|
+
type: reference
|
|
5
|
+
summary: Catch WorkflowRunNotCompletedError when reading the return value of a run that is still pending or running.
|
|
6
|
+
related:
|
|
7
|
+
- /docs/api-reference/workflow-api/get-run
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
`WorkflowRunNotCompletedError` is thrown when requesting the result of a workflow run that has not completed yet. The run's current status (for example `pending` or `running`) is available on the error.
|
|
11
|
+
|
|
12
|
+
[`run.returnValue()`](/docs/api-reference/workflow-api/get-run) handles this error internally — it polls until the run completes — so you will mainly encounter it when building custom polling logic on lower-level APIs.
|
|
13
|
+
|
|
14
|
+
```typescript lineNumbers
|
|
15
|
+
import { WorkflowRunNotCompletedError } from "workflow/errors"
|
|
16
|
+
declare function readRunResult(runId: string): Promise<unknown>; // @setup
|
|
17
|
+
declare const runId: string; // @setup
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
const result = await readRunResult(runId);
|
|
21
|
+
} catch (error) {
|
|
22
|
+
if (WorkflowRunNotCompletedError.is(error)) { // [!code highlight]
|
|
23
|
+
console.log(`Run ${error.runId} is still ${error.status}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## API Signature
|
|
29
|
+
|
|
30
|
+
### Properties
|
|
31
|
+
|
|
32
|
+
<TSDoc
|
|
33
|
+
definition={`
|
|
34
|
+
interface WorkflowRunNotCompletedError {
|
|
35
|
+
/** The workflow run ID. */
|
|
36
|
+
runId: string;
|
|
37
|
+
/** The run's status at the time of the error (e.g. "pending", "running"). */
|
|
38
|
+
status: string;
|
|
39
|
+
/** The error message. */
|
|
40
|
+
message: string;
|
|
41
|
+
}
|
|
42
|
+
export default WorkflowRunNotCompletedError;`}
|
|
43
|
+
/>
|
|
44
|
+
|
|
45
|
+
### Static Methods
|
|
46
|
+
|
|
47
|
+
#### `WorkflowRunNotCompletedError.is(value)`
|
|
48
|
+
|
|
49
|
+
Type-safe check for `WorkflowRunNotCompletedError` instances. Preferred over `instanceof` because it works across module boundaries and VM contexts.
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import { WorkflowRunNotCompletedError } from "workflow/errors"
|
|
53
|
+
declare const error: unknown; // @setup
|
|
54
|
+
|
|
55
|
+
if (WorkflowRunNotCompletedError.is(error)) {
|
|
56
|
+
// error is typed as WorkflowRunNotCompletedError
|
|
57
|
+
}
|
|
58
|
+
```
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: WorkflowRuntimeError
|
|
3
|
+
description: Thrown when the workflow runtime encounters an execution error, such as serialization failures or timeouts.
|
|
4
|
+
type: reference
|
|
5
|
+
summary: Catch WorkflowRuntimeError for runtime-level failures like unserializable values or workflow timeouts.
|
|
6
|
+
related:
|
|
7
|
+
- /docs/foundations/serialization
|
|
8
|
+
- /docs/foundations/errors-and-retries
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
`WorkflowRuntimeError` is thrown when the workflow runtime encounters an error executing a workflow. Common causes include:
|
|
12
|
+
|
|
13
|
+
- Values crossing the workflow/step boundary that cannot be serialized
|
|
14
|
+
- Workflow execution timeouts
|
|
15
|
+
- Invalid runtime state, such as misconfigured streams
|
|
16
|
+
|
|
17
|
+
```typescript lineNumbers
|
|
18
|
+
import { WorkflowRuntimeError } from "workflow/errors"
|
|
19
|
+
declare function runWorkflowOperation(): Promise<void>; // @setup
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
await runWorkflowOperation();
|
|
23
|
+
} catch (error) {
|
|
24
|
+
if (WorkflowRuntimeError.is(error)) { // [!code highlight]
|
|
25
|
+
console.error("Workflow runtime error:", error.message);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## API Signature
|
|
31
|
+
|
|
32
|
+
### Properties
|
|
33
|
+
|
|
34
|
+
<TSDoc
|
|
35
|
+
definition={`
|
|
36
|
+
interface WorkflowRuntimeError {
|
|
37
|
+
/** The error message. */
|
|
38
|
+
message: string;
|
|
39
|
+
/** The underlying cause, when provided. */
|
|
40
|
+
cause?: unknown;
|
|
41
|
+
}
|
|
42
|
+
export default WorkflowRuntimeError;`}
|
|
43
|
+
/>
|
|
44
|
+
|
|
45
|
+
### Static Methods
|
|
46
|
+
|
|
47
|
+
#### `WorkflowRuntimeError.is(value)`
|
|
48
|
+
|
|
49
|
+
Type-safe check for `WorkflowRuntimeError` instances. Preferred over `instanceof` because it works across module boundaries and VM contexts.
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import { WorkflowRuntimeError } from "workflow/errors"
|
|
53
|
+
declare const error: unknown; // @setup
|
|
54
|
+
|
|
55
|
+
if (WorkflowRuntimeError.is(error)) {
|
|
56
|
+
// error is typed as WorkflowRuntimeError
|
|
57
|
+
}
|
|
58
|
+
```
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: configureWorkflowController
|
|
3
|
+
description: Point WorkflowController at the generated workflow bundles.
|
|
4
|
+
type: reference
|
|
5
|
+
summary: Configure the directory WorkflowController loads workflow bundles from.
|
|
6
|
+
prerequisites:
|
|
7
|
+
- /docs/getting-started/nestjs
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
Configures the output directory that [`WorkflowController`](/docs/api-reference/workflow-nest/workflow-controller) loads the generated workflow bundles (`steps.mjs`, `workflows.mjs`, `webhook.mjs`, `manifest.json`) from.
|
|
11
|
+
|
|
12
|
+
[`WorkflowModule.forRoot()`](/docs/api-reference/workflow-nest/workflow-module) calls this for you with its resolved `outDir` — call it yourself only when registering `WorkflowController` manually. The controller's route handlers throw if no directory has been configured.
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```typescript title="src/app.module.ts" lineNumbers
|
|
17
|
+
import { join } from "node:path";
|
|
18
|
+
import { configureWorkflowController } from "workflow/nest"; // [!code highlight]
|
|
19
|
+
|
|
20
|
+
configureWorkflowController(join(process.cwd(), ".nestjs/workflow")); // [!code highlight]
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## API Signature
|
|
24
|
+
|
|
25
|
+
### Parameters
|
|
26
|
+
|
|
27
|
+
| Parameter | Type | Description |
|
|
28
|
+
| --- | --- | --- |
|
|
29
|
+
| `outDir` | `string` | Directory containing the generated workflow bundles. Should match the `outDir` used by the builder (default: `.nestjs/workflow` in the working directory). |
|
|
30
|
+
|
|
31
|
+
### Returns
|
|
32
|
+
|
|
33
|
+
Returns `void`.
|