workflow 5.0.0-beta.14 → 5.0.0-beta.16
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 +1 -7
- package/docs/api-reference/workflow/create-hook.mdx +38 -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/fetch.mdx +5 -0
- package/docs/api-reference/workflow-api/get-hook-by-token.mdx +7 -0
- package/docs/api-reference/workflow-api/get-run.mdx +6 -0
- package/docs/api-reference/workflow-api/index.mdx +6 -8
- package/docs/api-reference/workflow-api/resume-hook.mdx +57 -0
- package/docs/api-reference/workflow-api/start.mdx +6 -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/index.mdx +85 -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 +11 -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/changelog/index.mdx +1 -1
- package/docs/cookbook/advanced/child-workflows.mdx +3 -1
- package/docs/cookbook/advanced/publishing-libraries.mdx +13 -12
- package/docs/cookbook/advanced/serializable-steps.mdx +3 -3
- package/docs/cookbook/agent-patterns/human-in-the-loop.mdx +2 -2
- package/docs/cookbook/common-patterns/idempotency.mdx +36 -52
- package/docs/cookbook/common-patterns/rate-limiting.mdx +1 -1
- package/docs/cookbook/common-patterns/saga.mdx +2 -2
- package/docs/cookbook/common-patterns/scheduling.mdx +4 -0
- package/docs/cookbook/common-patterns/timeouts.mdx +2 -1
- package/docs/cookbook/common-patterns/workflow-composition.mdx +6 -0
- package/docs/cookbook/index.mdx +1 -1
- package/docs/cookbook/integrations/ai-sdk.mdx +10 -1
- package/docs/cookbook/integrations/chat-sdk.mdx +9 -0
- package/docs/cookbook/integrations/sandbox.mdx +9 -0
- package/docs/errors/step-not-registered.mdx +1 -1
- package/docs/foundations/cancellation.mdx +1 -2
- package/docs/foundations/hooks.mdx +29 -0
- package/docs/foundations/idempotency.mdx +236 -11
- 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/migration-guides/migrating-from-temporal.mdx +1 -1
- package/docs/observability/attributes.mdx +26 -5
- package/docs/testing/index.mdx +2 -2
- 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
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: hydrateResourceIO
|
|
3
|
+
description: Hydrate the serialized data fields of a run, step, hook, or event for display.
|
|
4
|
+
type: reference
|
|
5
|
+
summary: Use hydrateResourceIO with observabilityRevivers to deserialize step input/output for display in observability tools.
|
|
6
|
+
prerequisites:
|
|
7
|
+
- /docs/api-reference/workflow-runtime/get-world
|
|
8
|
+
related:
|
|
9
|
+
- /docs/api-reference/workflow-observability/observability-revivers
|
|
10
|
+
- /docs/api-reference/workflow-runtime/world/storage
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
Hydrates (deserializes) the data fields of a resource returned by the [World SDK](/docs/api-reference/workflow-runtime/world) — a workflow run, step, hook, or event. Workflow data is serialized using the [devalue](https://github.com/Rich-Harris/devalue) format, so this is required before displaying step input/output in a UI.
|
|
14
|
+
|
|
15
|
+
The function dispatches on the resource shape: steps get `input`/`output` hydrated, hooks get `metadata`, events get `eventData`, and runs get `input`/`output`.
|
|
16
|
+
|
|
17
|
+
```typescript lineNumbers
|
|
18
|
+
import { getWorld } from "workflow/runtime";
|
|
19
|
+
import { hydrateResourceIO, observabilityRevivers } from "workflow/observability"; // [!code highlight]
|
|
20
|
+
declare const runId: string; // @setup
|
|
21
|
+
declare const stepId: string; // @setup
|
|
22
|
+
|
|
23
|
+
const world = await getWorld();
|
|
24
|
+
const step = await world.steps.get(runId, stepId);
|
|
25
|
+
const hydrated = hydrateResourceIO(step, observabilityRevivers); // [!code highlight]
|
|
26
|
+
console.log(hydrated.input, hydrated.output);
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## API Signature
|
|
30
|
+
|
|
31
|
+
### Parameters
|
|
32
|
+
|
|
33
|
+
| Parameter | Type | Description |
|
|
34
|
+
|-----------|------|-------------|
|
|
35
|
+
| `resource` | `WorkflowRun \| Step \| Hook \| Event` | The resource with serialized data fields |
|
|
36
|
+
| `revivers` | `Revivers` | Reviver functions for deserialization. Use [`observabilityRevivers`](/docs/api-reference/workflow-observability/observability-revivers) for standard use. |
|
|
37
|
+
|
|
38
|
+
### Returns
|
|
39
|
+
|
|
40
|
+
The same resource with its data fields hydrated into plain JavaScript values.
|
|
41
|
+
|
|
42
|
+
<Callout type="info">
|
|
43
|
+
Encrypted data fields pass through as raw `Uint8Array` values rather than being decrypted — see [Encrypted Data](/docs/api-reference/workflow-observability#encrypted-data).
|
|
44
|
+
</Callout>
|
|
45
|
+
|
|
46
|
+
## Examples
|
|
47
|
+
|
|
48
|
+
### Display a Run's Steps with Hydrated I/O
|
|
49
|
+
|
|
50
|
+
```typescript lineNumbers
|
|
51
|
+
import { getWorld } from "workflow/runtime";
|
|
52
|
+
import { hydrateResourceIO, observabilityRevivers } from "workflow/observability"; // [!code highlight]
|
|
53
|
+
declare const runId: string; // @setup
|
|
54
|
+
|
|
55
|
+
const world = await getWorld();
|
|
56
|
+
const steps = await world.steps.list({ runId, resolveData: "all" });
|
|
57
|
+
|
|
58
|
+
for (const step of steps.data) {
|
|
59
|
+
const hydrated = hydrateResourceIO(step, observabilityRevivers); // [!code highlight]
|
|
60
|
+
console.log(step.stepName, hydrated.input, hydrated.output);
|
|
61
|
+
}
|
|
62
|
+
```
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "workflow/observability"
|
|
3
|
+
description: Utilities to hydrate serialized step I/O and parse machine-readable workflow names for display.
|
|
4
|
+
type: overview
|
|
5
|
+
summary: Explore utilities for hydrating serialized workflow data and parsing display names in observability tools.
|
|
6
|
+
keywords:
|
|
7
|
+
- workflow/observability
|
|
8
|
+
- hydrateResourceIO
|
|
9
|
+
- observabilityRevivers
|
|
10
|
+
- hydrateData
|
|
11
|
+
- parseStepName
|
|
12
|
+
- parseWorkflowName
|
|
13
|
+
- parseClassName
|
|
14
|
+
- data hydration
|
|
15
|
+
- devalue deserialization
|
|
16
|
+
- display name parsing
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
API reference for observability utilities from the `workflow/observability` package.
|
|
20
|
+
|
|
21
|
+
The observability package provides utilities for working with workflow data in observability and debugging tools — hydrating serialized step I/O for display, and parsing machine-readable names into display-friendly formats.
|
|
22
|
+
|
|
23
|
+
```typescript lineNumbers
|
|
24
|
+
import { // [!code highlight]
|
|
25
|
+
hydrateResourceIO, // [!code highlight]
|
|
26
|
+
observabilityRevivers, // [!code highlight]
|
|
27
|
+
hydrateData, // [!code highlight]
|
|
28
|
+
parseStepName, // [!code highlight]
|
|
29
|
+
parseWorkflowName, // [!code highlight]
|
|
30
|
+
parseClassName, // [!code highlight]
|
|
31
|
+
} from "workflow/observability"; // [!code highlight]
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Data Hydration
|
|
35
|
+
|
|
36
|
+
<Cards>
|
|
37
|
+
<Card href="/docs/api-reference/workflow-observability/hydrate-resource-io" title="hydrateResourceIO()">
|
|
38
|
+
Hydrate the serialized data fields of a run, step, hook, or event for display.
|
|
39
|
+
</Card>
|
|
40
|
+
<Card href="/docs/api-reference/workflow-observability/observability-revivers" title="observabilityRevivers">
|
|
41
|
+
Standard revivers for deserializing workflow data types (Date, Map, Set, streams, etc.).
|
|
42
|
+
</Card>
|
|
43
|
+
<Card href="/docs/api-reference/workflow-observability/hydrate-data" title="hydrateData()">
|
|
44
|
+
Hydrate a single serialized value (lower-level than hydrateResourceIO).
|
|
45
|
+
</Card>
|
|
46
|
+
</Cards>
|
|
47
|
+
|
|
48
|
+
## Name Parsing
|
|
49
|
+
|
|
50
|
+
<Cards>
|
|
51
|
+
<Card href="/docs/api-reference/workflow-observability/parse-step-name" title="parseStepName()">
|
|
52
|
+
Parse a machine-readable step name into display-friendly components.
|
|
53
|
+
</Card>
|
|
54
|
+
<Card href="/docs/api-reference/workflow-observability/parse-workflow-name" title="parseWorkflowName()">
|
|
55
|
+
Parse a machine-readable workflow name into display-friendly components.
|
|
56
|
+
</Card>
|
|
57
|
+
<Card href="/docs/api-reference/workflow-observability/parse-class-name" title="parseClassName()">
|
|
58
|
+
Parse a machine-readable class ID into display-friendly components.
|
|
59
|
+
</Card>
|
|
60
|
+
</Cards>
|
|
61
|
+
|
|
62
|
+
## Encrypted Data
|
|
63
|
+
|
|
64
|
+
When a [World](/docs/api-reference/workflow-runtime/world) stores encrypted data, the hydration utilities intentionally leave encrypted values untouched: [`hydrateData()`](/docs/api-reference/workflow-observability/hydrate-data) and [`hydrateResourceIO()`](/docs/api-reference/workflow-observability/hydrate-resource-io) return encrypted fields as raw `Uint8Array` values so observability tools can detect them and decide how to render them (for example, the Workflow CLI shows an "Encrypted" placeholder). Decryption is handled by the runtime and the World implementation — see [Encryption](/docs/how-it-works/encryption) for how keys are managed.
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: observabilityRevivers
|
|
3
|
+
description: Standard reviver functions for deserializing workflow data types in observability tools.
|
|
4
|
+
type: reference
|
|
5
|
+
summary: Pass observabilityRevivers to hydrateResourceIO or hydrateData to deserialize standard workflow data types.
|
|
6
|
+
related:
|
|
7
|
+
- /docs/api-reference/workflow-observability/hydrate-resource-io
|
|
8
|
+
- /docs/api-reference/workflow-observability/hydrate-data
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
A set of reviver functions that handle the workflow serialization format's workflow-specific types — streams, step/workflow function references, class instances, `AbortController`/`AbortSignal`, and `DOMException` — reviving them as display-friendly marker objects or strings. Built-in JavaScript types (`Date`, `Map`, `Set`, `RegExp`, etc.) are handled by the devalue format itself and need no revivers.
|
|
12
|
+
|
|
13
|
+
Pass it as the `revivers` argument to [`hydrateResourceIO()`](/docs/api-reference/workflow-observability/hydrate-resource-io) or [`hydrateData()`](/docs/api-reference/workflow-observability/hydrate-data).
|
|
14
|
+
|
|
15
|
+
```typescript lineNumbers
|
|
16
|
+
import { hydrateResourceIO, observabilityRevivers } from "workflow/observability"; // [!code highlight]
|
|
17
|
+
import type { Step } from "@workflow/world";
|
|
18
|
+
declare const step: Step; // @setup
|
|
19
|
+
|
|
20
|
+
const hydrated = hydrateResourceIO(step, observabilityRevivers); // [!code highlight]
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## API Signature
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import type { Revivers } from "workflow/observability";
|
|
27
|
+
|
|
28
|
+
declare const observabilityRevivers: Revivers;
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Where `Revivers` is:
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
type Revivers = Record<string, (value: any) => any>;
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Each key is a serialized type tag, and each function revives a serialized value of that type. You can spread `observabilityRevivers` into a custom reviver map to override how specific types are displayed:
|
|
38
|
+
|
|
39
|
+
```typescript lineNumbers
|
|
40
|
+
import { hydrateData, observabilityRevivers } from "workflow/observability";
|
|
41
|
+
declare const value: unknown; // @setup
|
|
42
|
+
|
|
43
|
+
const customRevivers = {
|
|
44
|
+
...observabilityRevivers,
|
|
45
|
+
// Render stream references as plain strings instead of marker objects
|
|
46
|
+
ReadableStream: () => "<stream>",
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const hydrated = hydrateData(value, customRevivers);
|
|
50
|
+
```
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: parseClassName
|
|
3
|
+
description: Parse a machine-readable class ID into display-friendly components.
|
|
4
|
+
type: reference
|
|
5
|
+
summary: Use parseClassName to extract a display-friendly class name from a serialized class instance identifier.
|
|
6
|
+
related:
|
|
7
|
+
- /docs/api-reference/workflow-observability/parse-step-name
|
|
8
|
+
- /docs/api-reference/workflow-observability/parse-workflow-name
|
|
9
|
+
- /docs/api-reference/workflow-serde
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
Serialized class instances reference their class with machine-readable IDs like `class//./src/models//User`. This function parses them into components suitable for display in a UI.
|
|
13
|
+
|
|
14
|
+
```typescript lineNumbers
|
|
15
|
+
import { parseClassName } from "workflow/observability"; // [!code highlight]
|
|
16
|
+
|
|
17
|
+
const parsed = parseClassName("class//./src/models//User"); // [!code highlight]
|
|
18
|
+
// parsed?.shortName → "User"
|
|
19
|
+
// parsed?.moduleSpecifier → "./src/models"
|
|
20
|
+
// parsed?.functionName → "User"
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## API Signature
|
|
24
|
+
|
|
25
|
+
### Parameters
|
|
26
|
+
|
|
27
|
+
| Parameter | Type | Description |
|
|
28
|
+
|-----------|------|-------------|
|
|
29
|
+
| `name` | `string` | The machine-readable class ID |
|
|
30
|
+
|
|
31
|
+
### Returns
|
|
32
|
+
|
|
33
|
+
`{ shortName: string; moduleSpecifier: string; functionName: string } | null`
|
|
34
|
+
|
|
35
|
+
| Property | Description |
|
|
36
|
+
|----------|-------------|
|
|
37
|
+
| `shortName` | The display name of the class (e.g. `"User"`). |
|
|
38
|
+
| `moduleSpecifier` | The module the class is defined in — a relative path (`./src/models`) or a package specifier (`point@0.0.1`). |
|
|
39
|
+
| `functionName` | The class name as recorded by the compiler. |
|
|
40
|
+
|
|
41
|
+
Returns `null` when the input is not a valid class ID.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: parseStepName
|
|
3
|
+
description: Parse a machine-readable step name into display-friendly components.
|
|
4
|
+
type: reference
|
|
5
|
+
summary: Use parseStepName to extract a display-friendly short name from a step's machine-readable identifier.
|
|
6
|
+
related:
|
|
7
|
+
- /docs/api-reference/workflow-observability/parse-workflow-name
|
|
8
|
+
- /docs/api-reference/workflow-observability/parse-class-name
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
Step names are stored as machine-readable identifiers like `step//./src/workflows/order//processPayment`. This function parses them into components suitable for display in a UI.
|
|
12
|
+
|
|
13
|
+
```typescript lineNumbers
|
|
14
|
+
import { parseStepName } from "workflow/observability"; // [!code highlight]
|
|
15
|
+
|
|
16
|
+
const parsed = parseStepName("step//./src/workflows/order//processPayment"); // [!code highlight]
|
|
17
|
+
// parsed?.shortName → "processPayment"
|
|
18
|
+
// parsed?.moduleSpecifier → "./src/workflows/order"
|
|
19
|
+
// parsed?.functionName → "processPayment"
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## API Signature
|
|
23
|
+
|
|
24
|
+
### Parameters
|
|
25
|
+
|
|
26
|
+
| Parameter | Type | Description |
|
|
27
|
+
|-----------|------|-------------|
|
|
28
|
+
| `name` | `string` | The machine-readable step name (e.g. from `step.stepName`) |
|
|
29
|
+
|
|
30
|
+
### Returns
|
|
31
|
+
|
|
32
|
+
`{ shortName: string; moduleSpecifier: string; functionName: string } | null`
|
|
33
|
+
|
|
34
|
+
| Property | Description |
|
|
35
|
+
|----------|-------------|
|
|
36
|
+
| `shortName` | The display name — the last segment of the function name. For nested steps like `processOrder/chargeCard`, this is `"chargeCard"`. |
|
|
37
|
+
| `moduleSpecifier` | The module the step is defined in — a relative path (`./src/workflows/order`) or a package specifier (`@myorg/tasks@2.0.0`). |
|
|
38
|
+
| `functionName` | The full function name including nesting (e.g. `processOrder/chargeCard`). |
|
|
39
|
+
|
|
40
|
+
Returns `null` when the input is not a valid step name.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: parseWorkflowName
|
|
3
|
+
description: Parse a machine-readable workflow name into display-friendly components.
|
|
4
|
+
type: reference
|
|
5
|
+
summary: Use parseWorkflowName to extract a display-friendly short name from a run's workflowName identifier.
|
|
6
|
+
related:
|
|
7
|
+
- /docs/api-reference/workflow-observability/parse-step-name
|
|
8
|
+
- /docs/api-reference/workflow-observability/parse-class-name
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
Workflow names are stored as machine-readable identifiers like `workflow//./src/workflows/order//processOrder`. This function parses them into components suitable for display in a UI — for example when listing runs from the [World SDK](/docs/api-reference/workflow-runtime/world/storage), where `run.workflowName` holds the machine-readable form.
|
|
12
|
+
|
|
13
|
+
```typescript lineNumbers
|
|
14
|
+
import { parseWorkflowName } from "workflow/observability"; // [!code highlight]
|
|
15
|
+
|
|
16
|
+
const parsed = parseWorkflowName("workflow//./src/workflows/order//processOrder"); // [!code highlight]
|
|
17
|
+
// parsed?.shortName → "processOrder"
|
|
18
|
+
// parsed?.moduleSpecifier → "./src/workflows/order"
|
|
19
|
+
// parsed?.functionName → "processOrder"
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## API Signature
|
|
23
|
+
|
|
24
|
+
### Parameters
|
|
25
|
+
|
|
26
|
+
| Parameter | Type | Description |
|
|
27
|
+
|-----------|------|-------------|
|
|
28
|
+
| `name` | `string` | The machine-readable workflow name (e.g. from `run.workflowName`) |
|
|
29
|
+
|
|
30
|
+
### Returns
|
|
31
|
+
|
|
32
|
+
`{ shortName: string; moduleSpecifier: string; functionName: string } | null`
|
|
33
|
+
|
|
34
|
+
| Property | Description |
|
|
35
|
+
|----------|-------------|
|
|
36
|
+
| `shortName` | The display name. For default exports, falls back to the module's short name (e.g. `"order"` for `./src/workflows/order`). |
|
|
37
|
+
| `moduleSpecifier` | The module the workflow is defined in — a relative path (`./src/workflows/order`) or a package specifier (`@myorg/flows@1.0.0`). |
|
|
38
|
+
| `functionName` | The full exported function name. |
|
|
39
|
+
|
|
40
|
+
Returns `null` when the input is not a valid workflow name.
|
|
41
|
+
|
|
42
|
+
## Example: List Runs with Display Names
|
|
43
|
+
|
|
44
|
+
```typescript lineNumbers
|
|
45
|
+
import { getWorld } from "workflow/runtime";
|
|
46
|
+
import { parseWorkflowName } from "workflow/observability"; // [!code highlight]
|
|
47
|
+
|
|
48
|
+
const world = await getWorld();
|
|
49
|
+
const runs = await world.runs.list({ resolveData: "none" });
|
|
50
|
+
|
|
51
|
+
for (const run of runs.data) {
|
|
52
|
+
const parsed = parseWorkflowName(run.workflowName); // [!code highlight]
|
|
53
|
+
console.log(`${parsed?.shortName ?? run.workflowName}: ${run.status}`);
|
|
54
|
+
}
|
|
55
|
+
```
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: createWorld
|
|
3
|
+
description: Create a new World instance from environment configuration.
|
|
4
|
+
type: reference
|
|
5
|
+
summary: Use createWorld to instantiate a World from WORKFLOW_TARGET_WORLD environment configuration, bypassing the cached instance.
|
|
6
|
+
prerequisites:
|
|
7
|
+
- /docs/api-reference/workflow-runtime/get-world
|
|
8
|
+
related:
|
|
9
|
+
- /docs/api-reference/workflow-runtime/set-world
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
Creates a new [World](/docs/api-reference/workflow-runtime/world) instance based on environment configuration. The `WORKFLOW_TARGET_WORLD` environment variable determines which World implementation is instantiated (for example the local development World or the Vercel production World).
|
|
13
|
+
|
|
14
|
+
Unlike [`getWorld()`](/docs/api-reference/workflow-runtime/get-world), which caches a singleton instance, `createWorld()` constructs a fresh instance on every call. Application code should almost always use `getWorld()` — `createWorld()` is for infrastructure code that manages World lifecycles itself.
|
|
15
|
+
|
|
16
|
+
```typescript lineNumbers
|
|
17
|
+
import { createWorld } from "workflow/runtime";
|
|
18
|
+
|
|
19
|
+
const world = await createWorld(); // [!code highlight]
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## API Signature
|
|
23
|
+
|
|
24
|
+
### Parameters
|
|
25
|
+
|
|
26
|
+
This function does not accept any parameters. Configuration is read from environment variables.
|
|
27
|
+
|
|
28
|
+
### Returns
|
|
29
|
+
|
|
30
|
+
Returns a `Promise<World>` with a newly constructed World instance.
|
|
31
|
+
|
|
32
|
+
<Callout type="info">
|
|
33
|
+
Tooling that needs to construct a World with explicit (non-environment) configuration should instantiate the specific World implementation directly and register it with [`setWorld()`](/docs/api-reference/workflow-runtime/set-world).
|
|
34
|
+
</Callout>
|
|
35
|
+
|
|
36
|
+
## Related Functions
|
|
37
|
+
|
|
38
|
+
- [`getWorld()`](/docs/api-reference/workflow-runtime/get-world) - Resolve the cached World instance (preferred in application code).
|
|
39
|
+
- [`setWorld()`](/docs/api-reference/workflow-runtime/set-world) - Override the cached World instance.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: getWorldHandlers
|
|
3
|
+
description: Build-time-safe access to the World's queue handlers without binding to runtime environment variables.
|
|
4
|
+
type: reference
|
|
5
|
+
summary: Use getWorldHandlers at build time to access queue handler creation without caching an environment-bound World.
|
|
6
|
+
prerequisites:
|
|
7
|
+
- /docs/api-reference/workflow-runtime/get-world
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
Returns a restricted view of the [World](/docs/api-reference/workflow-runtime/world) exposing only the members that are safe to use at build time: `createQueueHandler` and `specVersion`. Framework adapters use it while generating workflow route handlers, before the deployment's runtime environment variables exist.
|
|
11
|
+
|
|
12
|
+
Unlike [`getWorld()`](/docs/api-reference/workflow-runtime/get-world), this function does not cache a fully configured World instance — caching at build time would lock in incomplete environment configuration.
|
|
13
|
+
|
|
14
|
+
```typescript lineNumbers
|
|
15
|
+
import { getWorldHandlers } from "workflow/runtime";
|
|
16
|
+
|
|
17
|
+
const handlers = await getWorldHandlers(); // [!code highlight]
|
|
18
|
+
console.log(handlers.specVersion);
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## API Signature
|
|
22
|
+
|
|
23
|
+
### Parameters
|
|
24
|
+
|
|
25
|
+
This function does not accept any parameters.
|
|
26
|
+
|
|
27
|
+
### Returns
|
|
28
|
+
|
|
29
|
+
Returns a `Promise<WorldHandlers>`, where:
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import type { World } from "@workflow/world";
|
|
33
|
+
|
|
34
|
+
type WorldHandlers = Pick<World, "createQueueHandler" | "specVersion">;
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
<Callout type="warn">
|
|
38
|
+
This is SDK infrastructure used by framework adapters and the workflow entrypoint. Application code should use [`getWorld()`](/docs/api-reference/workflow-runtime/get-world) instead.
|
|
39
|
+
</Callout>
|
|
40
|
+
|
|
41
|
+
## Related Functions
|
|
42
|
+
|
|
43
|
+
- [`getWorld()`](/docs/api-reference/workflow-runtime/get-world) - Resolve the full World instance at runtime.
|
|
44
|
+
- [`workflowEntrypoint()`](/docs/api-reference/workflow-runtime/workflow-entrypoint) - The route handler factory built on these handlers.
|
|
@@ -36,21 +36,18 @@ showSections={["returns"]}
|
|
|
36
36
|
|
|
37
37
|
## World SDK
|
|
38
38
|
|
|
39
|
-
The World object provides access to several entity interfaces. See the [World SDK](/docs/api-reference/workflow-
|
|
39
|
+
The World object provides access to several entity interfaces. See the [World SDK](/docs/api-reference/workflow-runtime/world) reference for complete documentation:
|
|
40
40
|
|
|
41
41
|
<Cards>
|
|
42
|
-
<Card href="/docs/api-reference/workflow-
|
|
42
|
+
<Card href="/docs/api-reference/workflow-runtime/world/storage" title="Storage">
|
|
43
43
|
Query runs, steps, hooks, and the underlying event log.
|
|
44
44
|
</Card>
|
|
45
|
-
<Card href="/docs/api-reference/workflow-
|
|
45
|
+
<Card href="/docs/api-reference/workflow-runtime/world/streams" title="Streams">
|
|
46
46
|
Read, write, and manage data streams.
|
|
47
47
|
</Card>
|
|
48
|
-
<Card href="/docs/api-reference/workflow-
|
|
48
|
+
<Card href="/docs/api-reference/workflow-runtime/world/queue" title="Queue">
|
|
49
49
|
Low-level queue dispatch (internal SDK infrastructure).
|
|
50
50
|
</Card>
|
|
51
|
-
<Card href="/docs/api-reference/workflow-api/world/observability" title="Observability">
|
|
52
|
-
Hydrate step I/O, parse display names, decrypt data.
|
|
53
|
-
</Card>
|
|
54
51
|
</Cards>
|
|
55
52
|
|
|
56
53
|
## Data Hydration
|
|
@@ -64,7 +61,7 @@ const step = await world.steps.get(runId, stepId);
|
|
|
64
61
|
const hydrated = hydrateResourceIO(step, observabilityRevivers); // [!code highlight]
|
|
65
62
|
```
|
|
66
63
|
|
|
67
|
-
See [
|
|
64
|
+
See [`workflow/observability`](/docs/api-reference/workflow-observability) for the full hydration and parsing API.
|
|
68
65
|
|
|
69
66
|
### List Workflow Runs (Display Names)
|
|
70
67
|
|
|
@@ -72,7 +69,7 @@ List workflow runs and derive human-readable names from the `workflowName` field
|
|
|
72
69
|
|
|
73
70
|
```typescript lineNumbers
|
|
74
71
|
import { getWorld } from "workflow/runtime";
|
|
75
|
-
import { parseWorkflowName } from "
|
|
72
|
+
import { parseWorkflowName } from "workflow/observability"; // [!code highlight]
|
|
76
73
|
|
|
77
74
|
export async function GET(req: Request) {
|
|
78
75
|
const url = new URL(req.url);
|
|
@@ -113,7 +110,7 @@ export async function GET(req: Request) {
|
|
|
113
110
|
|
|
114
111
|
<Callout type="info">
|
|
115
112
|
The `workflowName` field contains a machine-readable identifier like `workflow//./src/workflows/order//processOrder`.
|
|
116
|
-
Use `parseWorkflowName()`
|
|
113
|
+
Use [`parseWorkflowName()`](/docs/api-reference/workflow-observability/parse-workflow-name) to extract the `shortName` (e.g., `"processOrder"`)
|
|
117
114
|
and `moduleSpecifier` for display in your UI.
|
|
118
115
|
</Callout>
|
|
119
116
|
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: healthCheck
|
|
3
|
+
description: Verify a deployment's workflow infrastructure by sending a message through the queue pipeline.
|
|
4
|
+
type: reference
|
|
5
|
+
summary: Use healthCheck to verify the workflow endpoint of a deployment processes queue messages end-to-end.
|
|
6
|
+
prerequisites:
|
|
7
|
+
- /docs/api-reference/workflow-runtime/get-world
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
Performs an end-to-end health check of a deployment's workflow infrastructure by sending a message through the queue pipeline and verifying it is processed by the workflow endpoint. Because it goes through the queue rather than direct HTTP, it works even when the deployment is behind Deployment Protection on Vercel.
|
|
11
|
+
|
|
12
|
+
```typescript lineNumbers
|
|
13
|
+
import { getWorld, healthCheck } from "workflow/runtime";
|
|
14
|
+
|
|
15
|
+
const world = await getWorld();
|
|
16
|
+
const result = await healthCheck(world, "workflow"); // [!code highlight]
|
|
17
|
+
|
|
18
|
+
if (!result.healthy) {
|
|
19
|
+
console.error("Workflow infrastructure unhealthy:", result.error);
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## API Signature
|
|
24
|
+
|
|
25
|
+
### Parameters
|
|
26
|
+
|
|
27
|
+
| Parameter | Type | Description |
|
|
28
|
+
|-----------|------|-------------|
|
|
29
|
+
| `world` | `World` | The World instance to send the health check through |
|
|
30
|
+
| `endpoint` | `"workflow" \| "step"` | Which endpoint to check |
|
|
31
|
+
| `options` | `HealthCheckOptions & { namespace?: string }` | Optional configuration |
|
|
32
|
+
|
|
33
|
+
Where `HealthCheckOptions` is:
|
|
34
|
+
|
|
35
|
+
| Option | Type | Description |
|
|
36
|
+
|--------|------|-------------|
|
|
37
|
+
| `timeout` | `number` | Milliseconds to wait for the health check response. Default: `30000`. |
|
|
38
|
+
| `deploymentId` | `string` | Deployment to target. Falls back to `process.env.VERCEL_DEPLOYMENT_ID`. |
|
|
39
|
+
|
|
40
|
+
### Returns
|
|
41
|
+
|
|
42
|
+
Returns a `Promise<HealthCheckResult>`:
|
|
43
|
+
|
|
44
|
+
| Property | Type | Description |
|
|
45
|
+
|----------|------|-------------|
|
|
46
|
+
| `healthy` | `boolean` | Whether the endpoint processed the health check message |
|
|
47
|
+
| `error` | `string \| undefined` | Error message when the check failed |
|
|
48
|
+
| `latencyMs` | `number \| undefined` | Round-trip latency when the check succeeded |
|
|
49
|
+
| `specVersion` | `number \| undefined` | Workflow spec version of the responding deployment |
|
|
50
|
+
| `workflowCoreVersion` | `string \| undefined` | `@workflow/core` version of the responding deployment |
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "workflow/runtime"
|
|
3
|
+
description: Runtime functions for accessing the World instance and wiring up workflow infrastructure.
|
|
4
|
+
type: overview
|
|
5
|
+
summary: Explore runtime functions for resolving the World instance and configuring workflow infrastructure.
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
API reference for runtime functions from the `workflow/runtime` package.
|
|
9
|
+
|
|
10
|
+
The runtime package provides low-level access to the workflow runtime — resolving the [World](/docs/api-reference/workflow-runtime/world) instance that backs storage, queuing, and streaming, and wiring up workflow infrastructure in custom server environments.
|
|
11
|
+
|
|
12
|
+
## Functions
|
|
13
|
+
|
|
14
|
+
<Cards>
|
|
15
|
+
<Card href="/docs/api-reference/workflow-runtime/get-world" title="getWorld()">
|
|
16
|
+
Async: resolve the World instance for storage, queuing, and streaming backends.
|
|
17
|
+
</Card>
|
|
18
|
+
<Card href="/docs/api-reference/workflow-runtime/world" title="World SDK">
|
|
19
|
+
Low-level API for inspecting runs, steps, events, hooks, streams, and queues.
|
|
20
|
+
</Card>
|
|
21
|
+
</Cards>
|
|
22
|
+
|
|
23
|
+
## Infrastructure Functions
|
|
24
|
+
|
|
25
|
+
These functions are primarily used by framework adapters and custom world setups, and are rarely needed in application code:
|
|
26
|
+
|
|
27
|
+
<Cards>
|
|
28
|
+
<Card href="/docs/api-reference/workflow-runtime/create-world" title="createWorld()">
|
|
29
|
+
Create a World instance from environment configuration.
|
|
30
|
+
</Card>
|
|
31
|
+
<Card href="/docs/api-reference/workflow-runtime/set-world" title="setWorld()">
|
|
32
|
+
Override the cached World instance with a custom World.
|
|
33
|
+
</Card>
|
|
34
|
+
<Card href="/docs/api-reference/workflow-runtime/get-world-handlers" title="getWorldHandlers()">
|
|
35
|
+
Build-time-safe access to the World's queue handlers.
|
|
36
|
+
</Card>
|
|
37
|
+
<Card href="/docs/api-reference/workflow-runtime/workflow-entrypoint" title="workflowEntrypoint()">
|
|
38
|
+
Create the HTTP route handler that executes workflow runs.
|
|
39
|
+
</Card>
|
|
40
|
+
<Card href="/docs/api-reference/workflow-runtime/health-check" title="healthCheck()">
|
|
41
|
+
Check the health of a deployment's workflow infrastructure.
|
|
42
|
+
</Card>
|
|
43
|
+
</Cards>
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: setWorld
|
|
3
|
+
description: Override or reset the cached World instance used by the workflow runtime.
|
|
4
|
+
type: reference
|
|
5
|
+
summary: Use setWorld to inject a custom World instance or reset the cache after environment configuration changes.
|
|
6
|
+
prerequisites:
|
|
7
|
+
- /docs/api-reference/workflow-runtime/get-world
|
|
8
|
+
related:
|
|
9
|
+
- /docs/api-reference/workflow-runtime/create-world
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
Overrides the cached [World](/docs/api-reference/workflow-runtime/world) instance that [`getWorld()`](/docs/api-reference/workflow-runtime/get-world) returns. Use it to inject a World constructed with explicit configuration (rather than environment variables), or pass `undefined` to clear the cache so the next `getWorld()` call reinitializes from the current environment.
|
|
13
|
+
|
|
14
|
+
```typescript lineNumbers
|
|
15
|
+
import { setWorld, getWorld } from "workflow/runtime";
|
|
16
|
+
import type { World } from "@workflow/world";
|
|
17
|
+
declare const customWorld: World; // @setup
|
|
18
|
+
|
|
19
|
+
setWorld(customWorld); // [!code highlight]
|
|
20
|
+
const world = await getWorld(); // resolves customWorld
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## API Signature
|
|
24
|
+
|
|
25
|
+
### Parameters
|
|
26
|
+
|
|
27
|
+
| Parameter | Type | Description |
|
|
28
|
+
|-----------|------|-------------|
|
|
29
|
+
| `world` | `World \| undefined` | The World instance to use, or `undefined` to reset the cache and reinitialize from environment variables on next access |
|
|
30
|
+
|
|
31
|
+
### Returns
|
|
32
|
+
|
|
33
|
+
This function does not return a value.
|
|
34
|
+
|
|
35
|
+
## Example: Reset After Environment Changes
|
|
36
|
+
|
|
37
|
+
```typescript lineNumbers
|
|
38
|
+
import { setWorld, getWorld } from "workflow/runtime";
|
|
39
|
+
|
|
40
|
+
process.env.WORKFLOW_TARGET_WORLD = "@workflow/world-local";
|
|
41
|
+
setWorld(undefined); // clear the cached instance // [!code highlight]
|
|
42
|
+
|
|
43
|
+
const world = await getWorld(); // reinitialized with new configuration
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Related Functions
|
|
47
|
+
|
|
48
|
+
- [`getWorld()`](/docs/api-reference/workflow-runtime/get-world) - Resolve the cached World instance.
|
|
49
|
+
- [`createWorld()`](/docs/api-reference/workflow-runtime/create-world) - Construct a fresh World from environment configuration.
|