workflow 4.3.1 → 4.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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-api/index.mdx +6 -8
- package/docs/api-reference/workflow-errors/meta.json +5 -0
- 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/deploying/building-a-world.mdx +1 -1
- package/docs/deploying/world/vercel-world.mdx +2 -0
- package/docs/errors/hook-conflict.mdx +56 -4
- package/docs/errors/index.mdx +6 -0
- package/docs/foundations/hooks.mdx +29 -0
- package/docs/foundations/streaming.mdx +7 -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/v4/api-reference/workflow-astro/index.mdx +18 -0
- package/docs/v4/api-reference/workflow-astro/meta.json +4 -0
- package/docs/v4/api-reference/workflow-astro/workflow.mdx +37 -0
- package/docs/v4/api-reference/workflow-errors/hook-conflict-error.mdx +60 -0
- package/docs/v4/api-reference/workflow-errors/run-not-supported-error.mdx +58 -0
- package/docs/v4/api-reference/workflow-errors/workflow-error.mdx +52 -0
- package/docs/v4/api-reference/workflow-errors/workflow-run-not-completed-error.mdx +58 -0
- package/docs/v4/api-reference/workflow-errors/workflow-runtime-error.mdx +58 -0
- package/docs/v4/api-reference/workflow-nest/configure-workflow-controller.mdx +33 -0
- package/docs/v4/api-reference/workflow-nest/index.mdx +31 -0
- package/docs/v4/api-reference/workflow-nest/meta.json +9 -0
- package/docs/v4/api-reference/workflow-nest/nest-local-builder.mdx +63 -0
- package/docs/v4/api-reference/workflow-nest/workflow-controller.mdx +40 -0
- package/docs/v4/api-reference/workflow-nest/workflow-module.mdx +73 -0
- package/docs/v4/api-reference/workflow-nitro/index.mdx +57 -0
- package/docs/v4/api-reference/workflow-nuxt/index.mdx +47 -0
- package/docs/v4/api-reference/workflow-observability/hydrate-data.mdx +35 -0
- package/docs/v4/api-reference/workflow-observability/hydrate-resource-io.mdx +62 -0
- package/docs/v4/api-reference/workflow-observability/index.mdx +64 -0
- package/docs/v4/api-reference/workflow-observability/meta.json +11 -0
- package/docs/v4/api-reference/workflow-observability/observability-revivers.mdx +50 -0
- package/docs/v4/api-reference/workflow-observability/parse-class-name.mdx +41 -0
- package/docs/v4/api-reference/workflow-observability/parse-step-name.mdx +40 -0
- package/docs/v4/api-reference/workflow-observability/parse-workflow-name.mdx +55 -0
- package/docs/v4/api-reference/workflow-runtime/create-world.mdx +43 -0
- package/docs/v4/api-reference/workflow-runtime/get-world-handlers.mdx +44 -0
- package/docs/v4/api-reference/workflow-runtime/get-world.mdx +124 -0
- package/docs/v4/api-reference/workflow-runtime/health-check.mdx +50 -0
- package/docs/v4/api-reference/workflow-runtime/index.mdx +46 -0
- package/docs/v4/api-reference/workflow-runtime/meta.json +13 -0
- package/docs/v4/api-reference/workflow-runtime/set-world.mdx +49 -0
- package/docs/v4/api-reference/workflow-runtime/step-entrypoint.mdx +39 -0
- package/docs/v4/api-reference/workflow-runtime/workflow-entrypoint.mdx +42 -0
- package/docs/{api-reference/workflow-api → v4/api-reference/workflow-runtime}/world/index.mdx +5 -8
- package/docs/v4/api-reference/workflow-runtime/world/meta.json +4 -0
- package/docs/v4/api-reference/workflow-runtime/world/queue.mdx +86 -0
- package/docs/{api-reference/workflow-api → v4/api-reference/workflow-runtime}/world/storage.mdx +4 -4
- package/docs/v4/api-reference/workflow-runtime/world/streams.mdx +216 -0
- package/docs/v4/api-reference/workflow-sveltekit/index.mdx +18 -0
- package/docs/v4/api-reference/workflow-sveltekit/meta.json +4 -0
- package/docs/v4/api-reference/workflow-sveltekit/workflow-plugin.mdx +34 -0
- package/docs/v4/api-reference/workflow-vite/index.mdx +18 -0
- package/docs/v4/api-reference/workflow-vite/meta.json +4 -0
- package/docs/v4/api-reference/workflow-vite/workflow.mdx +47 -0
- package/docs/v4/errors/runtime-decryption-failed.mdx +77 -0
- package/docs/v4/errors/step-executed-multiple-times.mdx +23 -0
- package/docs/v5/api-reference/workflow-astro/index.mdx +18 -0
- package/docs/v5/api-reference/workflow-astro/meta.json +4 -0
- package/docs/v5/api-reference/workflow-astro/workflow.mdx +45 -0
- package/docs/v5/api-reference/workflow-errors/hook-conflict-error.mdx +60 -0
- package/docs/v5/api-reference/workflow-errors/run-not-supported-error.mdx +58 -0
- package/docs/v5/api-reference/workflow-errors/workflow-error.mdx +52 -0
- package/docs/v5/api-reference/workflow-errors/workflow-run-not-completed-error.mdx +58 -0
- package/docs/v5/api-reference/workflow-errors/workflow-runtime-error.mdx +58 -0
- package/docs/v5/api-reference/workflow-nest/configure-workflow-controller.mdx +33 -0
- package/docs/v5/api-reference/workflow-nest/index.mdx +31 -0
- package/docs/v5/api-reference/workflow-nest/meta.json +9 -0
- package/docs/v5/api-reference/workflow-nest/nest-local-builder.mdx +64 -0
- package/docs/v5/api-reference/workflow-nest/workflow-controller.mdx +40 -0
- package/docs/v5/api-reference/workflow-nest/workflow-module.mdx +74 -0
- package/docs/v5/api-reference/workflow-nitro/index.mdx +59 -0
- package/docs/v5/api-reference/workflow-nuxt/index.mdx +47 -0
- package/docs/v5/api-reference/workflow-observability/hydrate-data.mdx +35 -0
- package/docs/v5/api-reference/workflow-observability/hydrate-resource-io.mdx +62 -0
- package/docs/v5/api-reference/workflow-observability/index.mdx +64 -0
- package/docs/v5/api-reference/workflow-observability/meta.json +11 -0
- package/docs/v5/api-reference/workflow-observability/observability-revivers.mdx +50 -0
- package/docs/v5/api-reference/workflow-observability/parse-class-name.mdx +41 -0
- package/docs/v5/api-reference/workflow-observability/parse-step-name.mdx +40 -0
- package/docs/v5/api-reference/workflow-observability/parse-workflow-name.mdx +55 -0
- package/docs/v5/api-reference/workflow-runtime/create-world.mdx +39 -0
- package/docs/v5/api-reference/workflow-runtime/get-world-handlers.mdx +44 -0
- package/docs/{api-reference/workflow-api → v5/api-reference/workflow-runtime}/get-world.mdx +7 -10
- package/docs/v5/api-reference/workflow-runtime/health-check.mdx +50 -0
- package/docs/v5/api-reference/workflow-runtime/index.mdx +43 -0
- package/docs/v5/api-reference/workflow-runtime/meta.json +12 -0
- package/docs/v5/api-reference/workflow-runtime/set-world.mdx +49 -0
- package/docs/v5/api-reference/workflow-runtime/workflow-entrypoint.mdx +42 -0
- package/docs/v5/api-reference/workflow-runtime/world/index.mdx +55 -0
- package/docs/v5/api-reference/workflow-runtime/world/meta.json +4 -0
- package/docs/{api-reference/workflow-api → v5/api-reference/workflow-runtime}/world/queue.mdx +2 -2
- package/docs/v5/api-reference/workflow-runtime/world/storage.mdx +409 -0
- package/docs/{api-reference/workflow-api → v5/api-reference/workflow-runtime}/world/streams.mdx +2 -2
- package/docs/v5/api-reference/workflow-sveltekit/index.mdx +18 -0
- package/docs/v5/api-reference/workflow-sveltekit/meta.json +4 -0
- package/docs/v5/api-reference/workflow-sveltekit/workflow-plugin.mdx +42 -0
- package/docs/v5/api-reference/workflow-vite/index.mdx +18 -0
- package/docs/v5/api-reference/workflow-vite/meta.json +4 -0
- package/docs/v5/api-reference/workflow-vite/workflow.mdx +48 -0
- package/docs/v5/errors/index.mdx +59 -0
- package/docs/v5/errors/runtime-decryption-failed.mdx +77 -0
- package/docs/v5/errors/step-executed-multiple-times.mdx +23 -0
- package/package.json +13 -13
- 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,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.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: stepEntrypoint
|
|
3
|
+
description: The HTTP route handler that executes step functions.
|
|
4
|
+
type: reference
|
|
5
|
+
summary: Mount stepEntrypoint as the route that executes step functions in custom server environments.
|
|
6
|
+
prerequisites:
|
|
7
|
+
- /docs/how-it-works/code-transform
|
|
8
|
+
related:
|
|
9
|
+
- /docs/api-reference/workflow-runtime/workflow-entrypoint
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
The HTTP route handler that executes step functions. It receives step execution requests from the queue, routes them to the appropriate step function, and reports results back to the workflow run.
|
|
13
|
+
|
|
14
|
+
Unlike [`workflowEntrypoint()`](/docs/api-reference/workflow-runtime/workflow-entrypoint), this is the handler itself rather than a factory — step bundles register their step functions globally, and the handler routes by step name.
|
|
15
|
+
|
|
16
|
+
Framework adapters mount this for you at `/.well-known/workflow/v1/step` — you only need it when wiring workflow support into a custom server environment.
|
|
17
|
+
|
|
18
|
+
{/* @skip-typecheck: stepEntrypoint exists in workflow@4 only; docs samples are type-checked against the v5 packages on main */}
|
|
19
|
+
|
|
20
|
+
```typescript lineNumbers
|
|
21
|
+
import { stepEntrypoint } from "workflow/runtime";
|
|
22
|
+
|
|
23
|
+
// Mount on your server, e.g. a fetch-style route:
|
|
24
|
+
export const POST = stepEntrypoint; // [!code highlight]
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## API Signature
|
|
28
|
+
|
|
29
|
+
{/* @skip-typecheck: type-only signature snippet, not compilable code */}
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
const stepEntrypoint: (req: Request) => Promise<Response>;
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
A fetch-style request handler.
|
|
36
|
+
|
|
37
|
+
<Callout type="info">
|
|
38
|
+
`stepEntrypoint` exists in workflow 4.x only. In 5.x the combined handler created by [`workflowEntrypoint()`](/docs/api-reference/workflow-runtime/workflow-entrypoint) executes steps inline, and the separate step endpoint was removed.
|
|
39
|
+
</Callout>
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: workflowEntrypoint
|
|
3
|
+
description: Create the HTTP route handler that executes workflow runs from a workflow bundle.
|
|
4
|
+
type: reference
|
|
5
|
+
summary: Use workflowEntrypoint to wire a compiled workflow bundle into an HTTP route in custom server environments.
|
|
6
|
+
prerequisites:
|
|
7
|
+
- /docs/how-it-works/code-transform
|
|
8
|
+
related:
|
|
9
|
+
- /docs/api-reference/workflow-runtime/health-check
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
Creates the HTTP route handler that executes workflow runs. The handler receives queue messages, replays the workflow from its event log, executes steps inline where possible, and suspends when the workflow waits on sleeps or hooks.
|
|
13
|
+
|
|
14
|
+
Framework adapters (Next.js, Nitro, SvelteKit, etc.) call this for you and mount the result at `/.well-known/workflow/v1/flow` — you only need it when wiring workflow support into a custom server environment.
|
|
15
|
+
|
|
16
|
+
```typescript lineNumbers
|
|
17
|
+
import { workflowEntrypoint } from "workflow/runtime";
|
|
18
|
+
declare const workflowBundleCode: string; // @setup
|
|
19
|
+
|
|
20
|
+
const handler = workflowEntrypoint(workflowBundleCode); // [!code highlight]
|
|
21
|
+
|
|
22
|
+
// Mount on your server, e.g. a fetch-style route:
|
|
23
|
+
export const POST = (req: Request) => handler(req);
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## API Signature
|
|
27
|
+
|
|
28
|
+
### Parameters
|
|
29
|
+
|
|
30
|
+
| Parameter | Type | Description |
|
|
31
|
+
|-----------|------|-------------|
|
|
32
|
+
| `workflowCode` | `string` | The compiled workflow bundle code containing all workflow functions |
|
|
33
|
+
| `options` | `{ namespace?: string }` | Optional. `namespace` scopes the queue topics this handler consumes. |
|
|
34
|
+
|
|
35
|
+
### Returns
|
|
36
|
+
|
|
37
|
+
Returns a fetch-style request handler: `(req: Request) => Promise<Response>`.
|
|
38
|
+
|
|
39
|
+
## Related Functions
|
|
40
|
+
|
|
41
|
+
- [`getWorldHandlers()`](/docs/api-reference/workflow-runtime/get-world-handlers) - The build-time World access this handler is built on.
|
|
42
|
+
- [`healthCheck()`](/docs/api-reference/workflow-runtime/health-check) - Verify the entrypoint processes queue messages end-to-end.
|
package/docs/{api-reference/workflow-api → v4/api-reference/workflow-runtime}/world/index.mdx
RENAMED
|
@@ -4,7 +4,7 @@ description: Low-level API for inspecting and managing workflow runs, steps, eve
|
|
|
4
4
|
type: overview
|
|
5
5
|
summary: Access workflow infrastructure directly via getWorld() for building observability dashboards, admin tools, and custom integrations.
|
|
6
6
|
prerequisites:
|
|
7
|
-
- /docs/api-reference/workflow-
|
|
7
|
+
- /docs/api-reference/workflow-runtime/get-world
|
|
8
8
|
keywords:
|
|
9
9
|
- getWorld
|
|
10
10
|
- World SDK
|
|
@@ -25,18 +25,15 @@ const world = getWorld(); // [!code highlight]
|
|
|
25
25
|
## Interfaces
|
|
26
26
|
|
|
27
27
|
<Cards>
|
|
28
|
-
<Card href="/docs/api-reference/workflow-
|
|
28
|
+
<Card href="/docs/api-reference/workflow-runtime/world/storage" title="Storage">
|
|
29
29
|
Query runs, steps, hooks, and the underlying event log.
|
|
30
30
|
</Card>
|
|
31
|
-
<Card href="/docs/api-reference/workflow-
|
|
31
|
+
<Card href="/docs/api-reference/workflow-runtime/world/streams" title="Streams">
|
|
32
32
|
Read, write, and manage real-time data streams for workflow runs.
|
|
33
33
|
</Card>
|
|
34
|
-
<Card href="/docs/api-reference/workflow-
|
|
34
|
+
<Card href="/docs/api-reference/workflow-runtime/world/queue" title="Queue">
|
|
35
35
|
Low-level queue dispatch (internal SDK infrastructure).
|
|
36
36
|
</Card>
|
|
37
|
-
<Card href="/docs/api-reference/workflow-api/world/observability" title="Observability Utilities">
|
|
38
|
-
Hydrate step I/O, parse display names, and decrypt workflow data.
|
|
39
|
-
</Card>
|
|
40
37
|
</Cards>
|
|
41
38
|
|
|
42
39
|
<Callout type="info">
|
|
@@ -55,4 +52,4 @@ const hydrated = hydrateResourceIO(step, observabilityRevivers); // [!code highl
|
|
|
55
52
|
console.log(hydrated.input, hydrated.output);
|
|
56
53
|
```
|
|
57
54
|
|
|
58
|
-
See [
|
|
55
|
+
See [`workflow/observability`](/docs/api-reference/workflow-observability) for the full API.
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Queue
|
|
3
|
+
description: Low-level queue interface for dispatching workflow and step invocations.
|
|
4
|
+
type: reference
|
|
5
|
+
summary: "Methods: getDeploymentId(), queue(), createQueueHandler(). Internal queue dispatch — normally handled by the SDK."
|
|
6
|
+
prerequisites:
|
|
7
|
+
- /docs/api-reference/workflow-runtime/get-world
|
|
8
|
+
related:
|
|
9
|
+
- /docs/api-reference/workflow-api/start
|
|
10
|
+
- /docs/foundations/starting-workflows
|
|
11
|
+
keywords:
|
|
12
|
+
- world.queue
|
|
13
|
+
- getDeploymentId
|
|
14
|
+
- queue
|
|
15
|
+
- createQueueHandler
|
|
16
|
+
- ValidQueueName
|
|
17
|
+
- queue dispatch
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
Queue methods live directly on the `world` object (not nested). They dispatch internal workflow and step invocations to the queue backend.
|
|
21
|
+
|
|
22
|
+
<Callout type="warn">
|
|
23
|
+
These methods are used internally by the Workflow SDK to dispatch execution. You do not need to call them in normal operations — use [`start()`](/docs/api-reference/workflow-api/start) to trigger workflows instead. Direct queue access is only needed if you programmatically create a run via `world.events.create()` with a `run_created` event and need to kick off its initial execution, or for debugging resumption of a flow or step route.
|
|
24
|
+
</Callout>
|
|
25
|
+
|
|
26
|
+
## Import
|
|
27
|
+
|
|
28
|
+
```typescript lineNumbers
|
|
29
|
+
import { getWorld } from "workflow/runtime";
|
|
30
|
+
|
|
31
|
+
const world = await getWorld(); // [!code highlight]
|
|
32
|
+
// Queue methods are called directly on world — e.g. world.queue()
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Methods
|
|
36
|
+
|
|
37
|
+
### getDeploymentId()
|
|
38
|
+
|
|
39
|
+
Get the current deployment ID. Used internally for routing queue messages to the correct deployment.
|
|
40
|
+
|
|
41
|
+
```typescript lineNumbers
|
|
42
|
+
const deploymentId = await world.getDeploymentId(); // [!code highlight]
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**Returns:** `string` — The current deployment ID
|
|
46
|
+
|
|
47
|
+
### queue()
|
|
48
|
+
|
|
49
|
+
Dispatch a message to a named queue. The message payload is an internal SDK type (`WorkflowInvokePayload`, `StepInvokePayload`, or `HealthCheckPayload`).
|
|
50
|
+
|
|
51
|
+
```typescript lineNumbers
|
|
52
|
+
const { messageId } = await world.queue(queueName, payload, opts); // [!code highlight]
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
**Parameters:**
|
|
56
|
+
|
|
57
|
+
| Parameter | Type | Description |
|
|
58
|
+
|-----------|------|-------------|
|
|
59
|
+
| `queueName` | `ValidQueueName` | The queue name (branded string) |
|
|
60
|
+
| `message` | `QueuePayload` | Internal SDK payload |
|
|
61
|
+
| `opts` | `QueueOptions` | Optional — `deploymentId`, `idempotencyKey`, `delaySeconds`, `headers` |
|
|
62
|
+
|
|
63
|
+
**Returns:** `{ messageId: MessageId | null }`
|
|
64
|
+
|
|
65
|
+
### createQueueHandler()
|
|
66
|
+
|
|
67
|
+
Create an HTTP handler that processes messages from a queue. Used to set up the queue consumer endpoint.
|
|
68
|
+
|
|
69
|
+
```typescript lineNumbers
|
|
70
|
+
const handler = world.createQueueHandler(prefix, callback); // [!code highlight]
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
**Parameters:**
|
|
74
|
+
|
|
75
|
+
| Parameter | Type | Description |
|
|
76
|
+
|-----------|------|-------------|
|
|
77
|
+
| `prefix` | `QueuePrefix` | Queue name prefix to match |
|
|
78
|
+
| `callback` | `(message, meta) => Promise<void \| { timeoutSeconds: number }>` | Handler called for each message. `meta` contains `attempt`, `queueName`, `messageId`, `requestId`. |
|
|
79
|
+
|
|
80
|
+
**Returns:** `(req: Request) => Promise<Response>`
|
|
81
|
+
|
|
82
|
+
## Related
|
|
83
|
+
|
|
84
|
+
- [start()](/docs/api-reference/workflow-api/start) — The standard way to start workflow runs
|
|
85
|
+
- [Starting Workflows](/docs/foundations/starting-workflows) — Core concepts for workflow invocation
|
|
86
|
+
- [Storage](/docs/api-reference/workflow-runtime/world/storage) — Create events that trigger queue dispatch
|
package/docs/{api-reference/workflow-api → v4/api-reference/workflow-runtime}/world/storage.mdx
RENAMED
|
@@ -4,11 +4,11 @@ description: Query workflow runs, steps, hooks, and the underlying event log via
|
|
|
4
4
|
type: reference
|
|
5
5
|
summary: "Interfaces: world.events, world.runs, world.steps, world.hooks. Events are the source of truth; runs, steps, and hooks are materialized views."
|
|
6
6
|
prerequisites:
|
|
7
|
-
- /docs/api-reference/workflow-
|
|
7
|
+
- /docs/api-reference/workflow-runtime/get-world
|
|
8
8
|
related:
|
|
9
9
|
- /docs/api-reference/workflow-api/get-run
|
|
10
10
|
- /docs/how-it-works/event-sourcing
|
|
11
|
-
- /docs/api-reference/workflow-
|
|
11
|
+
- /docs/api-reference/workflow-observability
|
|
12
12
|
keywords:
|
|
13
13
|
- world.events
|
|
14
14
|
- world.runs
|
|
@@ -229,7 +229,7 @@ const result = await world.steps.list({ // [!code highlight]
|
|
|
229
229
|
| `retryAfter` | `string \| null` | ISO timestamp for next retry attempt |
|
|
230
230
|
|
|
231
231
|
<Callout type="info">
|
|
232
|
-
Step I/O is serialized using the [devalue](https://github.com/Rich-Harris/devalue) format. Use `hydrateResourceIO()` from `workflow/observability` to deserialize it for display. See [
|
|
232
|
+
Step I/O is serialized using the [devalue](https://github.com/Rich-Harris/devalue) format. Use `hydrateResourceIO()` from `workflow/observability` to deserialize it for display. See [`hydrateResourceIO()`](/docs/api-reference/workflow-observability/hydrate-resource-io).
|
|
233
233
|
</Callout>
|
|
234
234
|
|
|
235
235
|
<Callout type="warn">
|
|
@@ -402,7 +402,7 @@ for (const event of events.data) {
|
|
|
402
402
|
|
|
403
403
|
- [Event Sourcing](/docs/how-it-works/event-sourcing) — How the event log powers workflow replay and state
|
|
404
404
|
- [getRun()](/docs/api-reference/workflow-api/get-run) — Higher-level API for working with individual runs
|
|
405
|
-
- [
|
|
405
|
+
- [`workflow/observability`](/docs/api-reference/workflow-observability) — Hydrate step I/O and parse display names
|
|
406
406
|
- [resumeHook()](/docs/api-reference/workflow-api/resume-hook) — Resume a workflow by sending a payload to a hook
|
|
407
407
|
- [Hooks](/docs/foundations/hooks) — Core concepts for hooks and pause points
|
|
408
408
|
- [Workflows and Steps](/docs/foundations/workflows-and-steps) — Core concepts for steps
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Streams
|
|
3
|
+
description: Read, write, and manage real-time data streams for workflow runs.
|
|
4
|
+
type: reference
|
|
5
|
+
summary: "Methods: streams.write(), streams.writeMulti(), streams.get(), streams.close(), streams.list(), streams.getChunks(), streams.getInfo(). Stream methods live on world.streams."
|
|
6
|
+
prerequisites:
|
|
7
|
+
- /docs/api-reference/workflow-runtime/get-world
|
|
8
|
+
related:
|
|
9
|
+
- /docs/foundations/streaming
|
|
10
|
+
- /docs/api-reference/workflow/get-writable
|
|
11
|
+
keywords:
|
|
12
|
+
- streams.write
|
|
13
|
+
- streams.writeMulti
|
|
14
|
+
- streams.get
|
|
15
|
+
- streams.close
|
|
16
|
+
- streams.list
|
|
17
|
+
- streams.getChunks
|
|
18
|
+
- streams.getInfo
|
|
19
|
+
- Streamer interface
|
|
20
|
+
- real-time streaming
|
|
21
|
+
- stream lifecycle
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
Stream methods live on `world.streams` (the `streams` sub-object of the `World` instance returned by `await getWorld()`). Use them to write chunks, read streams, and manage stream lifecycle outside of the standard `getWritable()` pattern.
|
|
25
|
+
|
|
26
|
+
<Callout type="info">
|
|
27
|
+
For most streaming use cases, use [`getWritable()`](/docs/api-reference/workflow/get-writable) inside steps. Direct stream methods are for advanced scenarios like building custom stream consumers or managing streams from outside a workflow.
|
|
28
|
+
</Callout>
|
|
29
|
+
|
|
30
|
+
## Import
|
|
31
|
+
|
|
32
|
+
```typescript lineNumbers
|
|
33
|
+
import { getWorld } from "workflow/runtime";
|
|
34
|
+
|
|
35
|
+
const world = await getWorld(); // [!code highlight]
|
|
36
|
+
// Stream methods are called on world.streams — e.g. world.streams.write()
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Methods
|
|
40
|
+
|
|
41
|
+
### write()
|
|
42
|
+
|
|
43
|
+
Write a data chunk to a named stream.
|
|
44
|
+
|
|
45
|
+
```typescript lineNumbers
|
|
46
|
+
await world.streams.write(runId, "default", chunk); // [!code highlight]
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
**Parameters:**
|
|
50
|
+
|
|
51
|
+
| Parameter | Type | Description |
|
|
52
|
+
|-----------|------|-------------|
|
|
53
|
+
| `runId` | `string` | The workflow run ID |
|
|
54
|
+
| `name` | `string` | The stream name |
|
|
55
|
+
| `chunk` | `string \| Uint8Array` | Data to write |
|
|
56
|
+
|
|
57
|
+
### writeMulti()
|
|
58
|
+
|
|
59
|
+
Write multiple chunks in a single operation. Optional optimization — not all World implementations support it. Falls back to sequential `write()` calls if unavailable.
|
|
60
|
+
|
|
61
|
+
```typescript lineNumbers
|
|
62
|
+
await world.streams.writeMulti?.(runId, "default", [chunk1, chunk2]); // [!code highlight]
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**Parameters:**
|
|
66
|
+
|
|
67
|
+
| Parameter | Type | Description |
|
|
68
|
+
|-----------|------|-------------|
|
|
69
|
+
| `runId` | `string` | The workflow run ID |
|
|
70
|
+
| `name` | `string` | The stream name |
|
|
71
|
+
| `chunks` | `(string \| Uint8Array)[]` | Chunks to write, in order |
|
|
72
|
+
|
|
73
|
+
### get()
|
|
74
|
+
|
|
75
|
+
Read data from a named stream as a live `ReadableStream` that waits for new chunks in real time.
|
|
76
|
+
|
|
77
|
+
```typescript lineNumbers
|
|
78
|
+
const readable = await world.streams.get(runId, "default"); // [!code highlight]
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
**Parameters:**
|
|
82
|
+
|
|
83
|
+
| Parameter | Type | Description |
|
|
84
|
+
|-----------|------|-------------|
|
|
85
|
+
| `runId` | `string` | The workflow run ID |
|
|
86
|
+
| `name` | `string` | The stream name |
|
|
87
|
+
| `startIndex` | `number` | Optional. Positive values skip chunks from the start (0-based). Negative values read from the tail (e.g. `-3` starts 3 chunks from the end). Clamped to 0. |
|
|
88
|
+
|
|
89
|
+
**Returns:** `ReadableStream<Uint8Array>`
|
|
90
|
+
|
|
91
|
+
### close()
|
|
92
|
+
|
|
93
|
+
Close a stream when done writing.
|
|
94
|
+
|
|
95
|
+
```typescript lineNumbers
|
|
96
|
+
await world.streams.close(runId, "default"); // [!code highlight]
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
**Parameters:**
|
|
100
|
+
|
|
101
|
+
| Parameter | Type | Description |
|
|
102
|
+
|-----------|------|-------------|
|
|
103
|
+
| `runId` | `string` | The workflow run ID |
|
|
104
|
+
| `name` | `string` | The stream name |
|
|
105
|
+
|
|
106
|
+
### list()
|
|
107
|
+
|
|
108
|
+
List all stream names associated with a workflow run.
|
|
109
|
+
|
|
110
|
+
```typescript lineNumbers
|
|
111
|
+
const streamNames = await world.streams.list(runId); // [!code highlight]
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
**Parameters:**
|
|
115
|
+
|
|
116
|
+
| Parameter | Type | Description |
|
|
117
|
+
|-----------|------|-------------|
|
|
118
|
+
| `runId` | `string` | The workflow run ID |
|
|
119
|
+
|
|
120
|
+
**Returns:** `string[]`
|
|
121
|
+
|
|
122
|
+
### getChunks()
|
|
123
|
+
|
|
124
|
+
Fetch stream chunks with cursor-based pagination. Unlike `get()` (which returns a live `ReadableStream`), this returns a snapshot of currently available chunks.
|
|
125
|
+
|
|
126
|
+
```typescript lineNumbers
|
|
127
|
+
const result = await world.streams.getChunks(runId, "default", { // [!code highlight]
|
|
128
|
+
limit: 50,
|
|
129
|
+
}); // [!code highlight]
|
|
130
|
+
// result.data: StreamChunk[], result.cursor, result.hasMore, result.done
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
**Parameters:**
|
|
134
|
+
|
|
135
|
+
| Parameter | Type | Description |
|
|
136
|
+
|-----------|------|-------------|
|
|
137
|
+
| `runId` | `string` | The workflow run ID |
|
|
138
|
+
| `name` | `string` | The stream name |
|
|
139
|
+
| `options.limit` | `number` | Max chunks per page (default: 100, max: 1000) |
|
|
140
|
+
| `options.cursor` | `string` | Cursor from a previous response |
|
|
141
|
+
|
|
142
|
+
**Returns:** `StreamChunksResponse`
|
|
143
|
+
|
|
144
|
+
| Field | Type | Description |
|
|
145
|
+
|-------|------|-------------|
|
|
146
|
+
| `data` | `StreamChunk[]` | Chunks in index order. Each has `index` (0-based) and `data` (`Uint8Array`). |
|
|
147
|
+
| `cursor` | `string \| null` | Cursor for the next page |
|
|
148
|
+
| `hasMore` | `boolean` | Whether more pages of already-written chunks exist |
|
|
149
|
+
| `done` | `boolean` | Whether the stream is fully closed. When `false`, new chunks may appear in future requests even after `hasMore` is `false`. |
|
|
150
|
+
|
|
151
|
+
### getInfo()
|
|
152
|
+
|
|
153
|
+
Retrieve lightweight metadata about a stream without fetching chunks.
|
|
154
|
+
|
|
155
|
+
```typescript lineNumbers
|
|
156
|
+
const info = await world.streams.getInfo(runId, "default"); // [!code highlight]
|
|
157
|
+
// info.tailIndex: last chunk index (-1 if empty), info.done: whether stream is closed
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
**Parameters:**
|
|
161
|
+
|
|
162
|
+
| Parameter | Type | Description |
|
|
163
|
+
|-----------|------|-------------|
|
|
164
|
+
| `runId` | `string` | The workflow run ID |
|
|
165
|
+
| `name` | `string` | The stream name |
|
|
166
|
+
|
|
167
|
+
**Returns:** `StreamInfoResponse`
|
|
168
|
+
|
|
169
|
+
| Field | Type | Description |
|
|
170
|
+
|-------|------|-------------|
|
|
171
|
+
| `tailIndex` | `number` | Index of the last known chunk (0-based). `-1` when no chunks have been written. |
|
|
172
|
+
| `done` | `boolean` | Whether the stream is fully complete (closed). |
|
|
173
|
+
|
|
174
|
+
## Examples
|
|
175
|
+
|
|
176
|
+
### Read a Stream as a Response
|
|
177
|
+
|
|
178
|
+
```typescript lineNumbers
|
|
179
|
+
// app/api/workflow-streams/read/route.ts
|
|
180
|
+
import { getWorld } from "workflow/runtime";
|
|
181
|
+
|
|
182
|
+
export async function GET(req: Request) {
|
|
183
|
+
const url = new URL(req.url);
|
|
184
|
+
const streamName = url.searchParams.get("name") ?? "default";
|
|
185
|
+
const runId = url.searchParams.get("runId")!;
|
|
186
|
+
const world = await getWorld();
|
|
187
|
+
const readable = await world.streams.get(runId, streamName); // [!code highlight]
|
|
188
|
+
|
|
189
|
+
return new Response(readable, {
|
|
190
|
+
headers: { "Content-Type": "application/octet-stream" },
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Paginate Through Stream Chunks
|
|
196
|
+
|
|
197
|
+
```typescript lineNumbers
|
|
198
|
+
import { getWorld } from "workflow/runtime";
|
|
199
|
+
|
|
200
|
+
const world = await getWorld();
|
|
201
|
+
let cursor: string | undefined;
|
|
202
|
+
|
|
203
|
+
do {
|
|
204
|
+
const result = await world.streams.getChunks(runId, "default", { cursor }); // [!code highlight]
|
|
205
|
+
for (const chunk of result.data) {
|
|
206
|
+
console.log(`Chunk ${chunk.index}:`, chunk.data);
|
|
207
|
+
}
|
|
208
|
+
cursor = result.cursor ?? undefined;
|
|
209
|
+
} while (cursor);
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## Related
|
|
213
|
+
|
|
214
|
+
- [Streaming](/docs/foundations/streaming) — Core concepts for streaming data from workflows
|
|
215
|
+
- [getWritable()](/docs/api-reference/workflow/get-writable) — The standard way to write to streams from within steps
|
|
216
|
+
- [Storage](/docs/api-reference/workflow-runtime/world/storage) — Query runs, steps, hooks, and events
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "workflow/sveltekit"
|
|
3
|
+
description: SvelteKit integration for automatic workflow bundling via Vite.
|
|
4
|
+
type: overview
|
|
5
|
+
summary: Explore the SvelteKit integration for automatic workflow bundling and runtime support.
|
|
6
|
+
related:
|
|
7
|
+
- /docs/getting-started/sveltekit
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
SvelteKit integration for Workflow SDK that configures Vite to transform workflow code and build the workflow bundles.
|
|
11
|
+
|
|
12
|
+
## Functions
|
|
13
|
+
|
|
14
|
+
<Cards>
|
|
15
|
+
<Card title="workflowPlugin()" href="/docs/api-reference/workflow-sveltekit/workflow-plugin">
|
|
16
|
+
Vite plugin that transforms workflow code (`"use step"`/`"use workflow"` directives) in SvelteKit apps
|
|
17
|
+
</Card>
|
|
18
|
+
</Cards>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: workflowPlugin
|
|
3
|
+
description: Configure Vite to transform workflow directives in SvelteKit.
|
|
4
|
+
type: reference
|
|
5
|
+
summary: Add workflowPlugin to your Vite config to enable workflow directive transformation in SvelteKit apps.
|
|
6
|
+
prerequisites:
|
|
7
|
+
- /docs/getting-started/sveltekit
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
Returns the Vite plugins that transform workflow code (`"use step"`/`"use workflow"` directives) and build the workflow bundles in a SvelteKit app.
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
To enable `"use step"` and `"use workflow"` directives while developing locally or deploying to production, add `workflowPlugin()` to the `plugins` array of your Vite config.
|
|
15
|
+
|
|
16
|
+
```typescript title="vite.config.ts" lineNumbers
|
|
17
|
+
import { sveltekit } from "@sveltejs/kit/vite";
|
|
18
|
+
import { defineConfig } from "vite";
|
|
19
|
+
import { workflowPlugin } from "workflow/sveltekit"; // [!code highlight]
|
|
20
|
+
|
|
21
|
+
export default defineConfig({
|
|
22
|
+
plugins: [sveltekit(), workflowPlugin()], // [!code highlight]
|
|
23
|
+
});
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## API Signature
|
|
27
|
+
|
|
28
|
+
### Parameters
|
|
29
|
+
|
|
30
|
+
This function does not accept any parameters in workflow 4.x. (5.x adds an options object with a `sourcemap` setting.)
|
|
31
|
+
|
|
32
|
+
### Returns
|
|
33
|
+
|
|
34
|
+
Returns an array of Vite `Plugin` objects. Spread or pass the array directly to the `plugins` option of your Vite config — Vite flattens nested plugin arrays automatically.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "workflow/vite"
|
|
3
|
+
description: Vite plugin for automatic workflow bundling in Vite + Nitro apps.
|
|
4
|
+
type: overview
|
|
5
|
+
summary: Explore the Vite plugin for automatic workflow bundling and runtime support.
|
|
6
|
+
related:
|
|
7
|
+
- /docs/getting-started/vite
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
Vite integration for Workflow SDK. It wraps the [`workflow/nitro`](/docs/api-reference/workflow-nitro) module as a Vite plugin, for apps using Nitro's Vite plugin (`nitro/vite`).
|
|
11
|
+
|
|
12
|
+
## Functions
|
|
13
|
+
|
|
14
|
+
<Cards>
|
|
15
|
+
<Card title="workflow()" href="/docs/api-reference/workflow-vite/workflow">
|
|
16
|
+
Vite plugin that transforms workflow code (`"use step"`/`"use workflow"` directives) and configures the Nitro server
|
|
17
|
+
</Card>
|
|
18
|
+
</Cards>
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: workflow
|
|
3
|
+
description: Configure Vite and Nitro to transform workflow directives.
|
|
4
|
+
type: reference
|
|
5
|
+
summary: Add the workflow plugin to your Vite config to enable workflow directive transformation in Vite + Nitro apps.
|
|
6
|
+
prerequisites:
|
|
7
|
+
- /docs/getting-started/vite
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
Returns the Vite plugins that transform workflow code (`"use step"`/`"use workflow"` directives) and configure the [`workflow/nitro`](/docs/api-reference/workflow-nitro) module on the Nitro server. It is designed to be used alongside `nitro()` from `nitro/vite`, which provides the server framework for API routes and deployment.
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
To enable `"use step"` and `"use workflow"` directives while developing locally or deploying to production, add `workflow()` to the `plugins` array of your Vite config, together with `nitro()`.
|
|
15
|
+
|
|
16
|
+
```typescript title="vite.config.ts" lineNumbers
|
|
17
|
+
import { nitro } from "nitro/vite";
|
|
18
|
+
import { defineConfig } from "vite";
|
|
19
|
+
import { workflow } from "workflow/vite"; // [!code highlight]
|
|
20
|
+
|
|
21
|
+
export default defineConfig({
|
|
22
|
+
plugins: [nitro(), workflow()], // [!code highlight]
|
|
23
|
+
nitro: {
|
|
24
|
+
serverDir: "./",
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## API Signature
|
|
30
|
+
|
|
31
|
+
### Parameters
|
|
32
|
+
|
|
33
|
+
| Parameter | Type | Description |
|
|
34
|
+
| --- | --- | --- |
|
|
35
|
+
| `options` | `ModuleOptions` | Optional. Forwarded to the `workflow/nitro` module as its module options. |
|
|
36
|
+
|
|
37
|
+
#### ModuleOptions
|
|
38
|
+
|
|
39
|
+
| Option | Type | Default | Description |
|
|
40
|
+
| --- | --- | --- | --- |
|
|
41
|
+
| `dirs` | `string[]` | — | Directories to scan for workflows and steps. By default, the `workflows/` directory is scanned from the project root and all layer source directories. |
|
|
42
|
+
| `typescriptPlugin` | `boolean` | `false` | Adds the `workflow` TypeScript plugin to the generated `tsconfig.json` for IDE IntelliSense. |
|
|
43
|
+
| `runtime` | `string` | — | Node.js runtime version for Vercel Functions (e.g. `'nodejs22.x'`, `'nodejs24.x'`). Only applies when deploying to Vercel. |
|
|
44
|
+
|
|
45
|
+
### Returns
|
|
46
|
+
|
|
47
|
+
Returns an array of Vite `Plugin` objects. Spread or pass the array directly to the `plugins` option of your Vite config — Vite flattens nested plugin arrays automatically.
|