workflow 5.0.0-beta.5 → 5.0.0-beta.51
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/README.md +68 -23
- package/dist/api-workflow.d.ts +1 -1
- package/dist/api-workflow.d.ts.map +1 -1
- package/dist/api-workflow.js +1 -1
- package/dist/api.d.ts +3 -3
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +5 -7
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/internal/builtins.d.ts +20 -3
- package/dist/internal/builtins.d.ts.map +1 -1
- package/dist/internal/builtins.js +68 -4
- package/dist/internal/errors.d.ts +1 -1
- package/dist/internal/errors.d.ts.map +1 -1
- package/dist/internal/errors.js +2 -2
- package/dist/nest-builder.d.ts +2 -0
- package/dist/nest-builder.d.ts.map +1 -0
- package/dist/nest-builder.js +2 -0
- package/dist/nest-vercel-builder.d.ts +2 -0
- package/dist/nest-vercel-builder.d.ts.map +1 -0
- package/dist/nest-vercel-builder.js +2 -0
- package/dist/observability.d.ts +1 -1
- package/dist/observability.js +2 -2
- package/dist/runtime.d.ts +2 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +4 -1
- package/docs/ai/chat-session-modeling.mdx +176 -422
- package/docs/ai/defining-tools.mdx +6 -7
- package/docs/ai/human-in-the-loop.mdx +11 -11
- package/docs/ai/index.mdx +71 -75
- package/docs/ai/message-queueing.mdx +71 -110
- package/docs/ai/meta.json +1 -0
- package/docs/ai/resumable-streams.mdx +40 -28
- package/docs/ai/sleep-and-delays.mdx +10 -10
- package/docs/ai/streaming-updates-from-tools.mdx +6 -6
- package/docs/api-reference/index.mdx +25 -1
- package/docs/api-reference/meta.json +8 -0
- package/docs/api-reference/vitest/index.mdx +9 -15
- package/docs/api-reference/workflow/create-hook.mdx +89 -10
- package/docs/api-reference/workflow/create-webhook.mdx +16 -15
- package/docs/api-reference/workflow/define-hook.mdx +35 -33
- package/docs/api-reference/workflow/fatal-error.mdx +30 -8
- package/docs/api-reference/workflow/fetch.mdx +14 -10
- package/docs/api-reference/workflow/get-step-metadata.mdx +2 -2
- package/docs/api-reference/workflow/get-workflow-metadata.mdx +3 -3
- package/docs/api-reference/workflow/get-writable.mdx +7 -7
- package/docs/api-reference/workflow/index.mdx +4 -1
- package/docs/api-reference/workflow/retryable-error.mdx +1 -1
- package/docs/api-reference/workflow/set-attributes.mdx +61 -0
- package/docs/api-reference/workflow/sleep.mdx +4 -4
- package/docs/api-reference/workflow-ai/durable-agent.mdx +63 -101
- package/docs/api-reference/workflow-ai/index.mdx +5 -5
- package/docs/api-reference/workflow-ai/workflow-chat-transport.mdx +67 -24
- package/docs/api-reference/workflow-api/get-hook-by-token.mdx +26 -12
- package/docs/api-reference/workflow-api/get-run.mdx +43 -8
- package/docs/api-reference/workflow-api/index.mdx +6 -10
- package/docs/api-reference/workflow-api/resume-hook.mdx +73 -12
- package/docs/api-reference/workflow-api/resume-webhook.mdx +11 -9
- package/docs/api-reference/workflow-api/start.mdx +60 -13
- 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/entity-conflict-error.mdx +4 -4
- package/docs/api-reference/workflow-errors/hook-conflict-error.mdx +60 -0
- package/docs/api-reference/workflow-errors/hook-not-found-error.mdx +8 -8
- package/docs/api-reference/workflow-errors/index.mdx +88 -0
- package/docs/api-reference/workflow-errors/meta.json +6 -0
- package/docs/api-reference/workflow-errors/precondition-failed-error.mdx +68 -0
- package/docs/api-reference/workflow-errors/run-expired-error.mdx +2 -2
- package/docs/api-reference/workflow-errors/run-not-supported-error.mdx +58 -0
- package/docs/api-reference/workflow-errors/step-not-registered-error.mdx +5 -5
- package/docs/api-reference/workflow-errors/throttle-error.mdx +2 -2
- package/docs/api-reference/workflow-errors/too-early-error.mdx +2 -2
- package/docs/api-reference/workflow-errors/workflow-error.mdx +52 -0
- package/docs/api-reference/workflow-errors/workflow-not-registered-error.mdx +5 -6
- package/docs/api-reference/workflow-errors/workflow-run-cancelled-error.mdx +6 -6
- package/docs/api-reference/workflow-errors/workflow-run-failed-error.mdx +5 -5
- package/docs/api-reference/workflow-errors/workflow-run-not-completed-error.mdx +58 -0
- package/docs/api-reference/workflow-errors/workflow-run-not-found-error.mdx +4 -4
- package/docs/api-reference/workflow-errors/workflow-runtime-error.mdx +58 -0
- package/docs/api-reference/workflow-errors/workflow-world-error.mdx +8 -8
- package/docs/api-reference/workflow-globals.mdx +14 -10
- 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-next/with-workflow.mdx +39 -17
- package/docs/api-reference/workflow-nitro/index.mdx +60 -0
- package/docs/api-reference/workflow-nuxt/index.mdx +48 -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 +62 -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 +11 -14
- package/docs/api-reference/workflow-runtime/health-check.mdx +50 -0
- package/docs/api-reference/workflow-runtime/index.mdx +41 -0
- package/docs/api-reference/workflow-runtime/meta.json +12 -0
- package/docs/api-reference/workflow-runtime/set-world.mdx +51 -0
- package/docs/api-reference/workflow-runtime/workflow-entrypoint.mdx +43 -0
- package/docs/api-reference/workflow-runtime/world/analytics.mdx +315 -0
- package/docs/api-reference/workflow-runtime/world/index.mdx +60 -0
- package/docs/api-reference/workflow-runtime/world/meta.json +4 -0
- package/docs/api-reference/workflow-runtime/world/queue.mdx +88 -0
- package/docs/api-reference/{workflow-api → workflow-runtime}/world/storage.mdx +98 -34
- package/docs/api-reference/{workflow-api → workflow-runtime}/world/streams.mdx +8 -8
- package/docs/api-reference/workflow-serde/index.mdx +1 -2
- package/docs/api-reference/workflow-serde/workflow-deserialize.mdx +3 -4
- package/docs/api-reference/workflow-serde/workflow-serialize.mdx +8 -8
- 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 +380 -0
- package/docs/changelog/batched-event-writes.mdx +79 -0
- package/docs/changelog/eager-processing.mdx +110 -436
- package/docs/changelog/index.mdx +4 -2
- package/docs/changelog/lazy-event-creation.md +127 -0
- package/docs/changelog/lazy-hook-resume.mdx +78 -0
- package/docs/changelog/meta.json +11 -1
- package/docs/changelog/resilient-resume.mdx +32 -0
- package/docs/changelog/resilient-start.mdx +33 -285
- package/docs/changelog/step-message-ownership.mdx +360 -0
- package/docs/changelog/turbo-mode.md +87 -0
- package/docs/comparisons/index.mdx +66 -0
- package/docs/comparisons/meta.json +11 -0
- package/docs/comparisons/workflow-sdk-vs-aws-agentcore.mdx +55 -0
- package/docs/comparisons/workflow-sdk-vs-aws-step-functions.mdx +111 -0
- package/docs/comparisons/workflow-sdk-vs-cloudflare-workflows.mdx +71 -0
- package/docs/comparisons/workflow-sdk-vs-inngest.mdx +102 -0
- package/docs/comparisons/workflow-sdk-vs-temporal.mdx +123 -0
- package/docs/comparisons/workflow-sdk-vs-trigger-dev.mdx +104 -0
- package/docs/configuration/build-and-diagnostics.mdx +70 -0
- package/docs/configuration/cli-and-web-ui.mdx +241 -0
- package/docs/configuration/framework-options.mdx +165 -0
- package/docs/configuration/index.mdx +32 -0
- package/docs/configuration/meta.json +12 -0
- package/docs/configuration/runtime-tuning.mdx +381 -0
- package/docs/configuration/worlds.mdx +313 -0
- package/docs/cookbook/advanced/child-workflows.mdx +211 -264
- package/docs/cookbook/advanced/meta.json +6 -1
- package/docs/cookbook/advanced/publishing-libraries.mdx +65 -56
- package/docs/cookbook/advanced/serializable-steps.mdx +48 -68
- package/docs/cookbook/advanced/upgrading-workflows.mdx +199 -0
- package/docs/cookbook/agent-patterns/agent-cancellation.mdx +78 -60
- package/docs/cookbook/agent-patterns/durable-agent.mdx +23 -131
- package/docs/cookbook/agent-patterns/human-in-the-loop.mdx +180 -195
- package/docs/cookbook/common-patterns/batching.mdx +18 -14
- package/docs/cookbook/common-patterns/idempotency.mdx +41 -53
- package/docs/cookbook/common-patterns/rate-limiting.mdx +8 -4
- package/docs/cookbook/common-patterns/saga.mdx +23 -19
- package/docs/cookbook/common-patterns/scheduling.mdx +34 -22
- package/docs/cookbook/common-patterns/sequential-and-parallel.mdx +29 -25
- package/docs/cookbook/common-patterns/timeouts.mdx +26 -21
- package/docs/cookbook/common-patterns/webhooks.mdx +10 -6
- package/docs/cookbook/common-patterns/workflow-composition.mdx +30 -27
- package/docs/cookbook/index.mdx +22 -21
- package/docs/cookbook/integrations/ai-sdk.mdx +86 -48
- package/docs/cookbook/integrations/chat-sdk.mdx +50 -33
- package/docs/cookbook/integrations/sandbox.mdx +62 -45
- package/docs/deploying.mdx +95 -0
- package/docs/errors/abort-signal-timeout-in-workflow.mdx +16 -12
- package/docs/errors/corrupted-event-log.mdx +39 -18
- package/docs/errors/deployment-mismatch.mdx +71 -0
- package/docs/errors/fetch-in-workflow.mdx +15 -14
- package/docs/errors/hook-conflict.mdx +69 -13
- package/docs/errors/index.mdx +2 -36
- package/docs/errors/node-js-module-in-workflow.mdx +9 -5
- package/docs/errors/replay-divergence.mdx +27 -0
- package/docs/errors/run-expired.mdx +85 -0
- package/docs/errors/runtime-decryption-failed.mdx +77 -0
- package/docs/errors/serialization-failed.mdx +44 -12
- package/docs/errors/start-invalid-workflow-function.mdx +9 -5
- package/docs/errors/step-executed-multiple-times.mdx +23 -0
- package/docs/errors/step-not-registered.mdx +6 -6
- package/docs/errors/timeout-in-workflow.mdx +12 -8
- package/docs/errors/webhook-invalid-respond-with-value.mdx +18 -18
- package/docs/errors/webhook-response-not-sent.mdx +20 -16
- package/docs/errors/workflow-not-registered.mdx +5 -5
- package/docs/foundations/cancellation.mdx +31 -32
- package/docs/foundations/errors-and-retries.mdx +42 -11
- package/docs/foundations/hooks.mdx +64 -35
- package/docs/foundations/idempotency.mdx +244 -12
- package/docs/foundations/index.mdx +1 -23
- package/docs/foundations/meta.json +2 -1
- package/docs/foundations/serialization.mdx +21 -22
- package/docs/foundations/starting-workflows.mdx +106 -30
- package/docs/foundations/streaming.mdx +108 -60
- package/docs/foundations/versioning.mdx +263 -0
- package/docs/foundations/workflows-and-steps.mdx +9 -9
- package/docs/getting-started/astro.mdx +22 -18
- package/docs/getting-started/express.mdx +15 -11
- package/docs/getting-started/fastify.mdx +15 -11
- package/docs/getting-started/hono.mdx +15 -11
- package/docs/getting-started/index.mdx +10 -3
- package/docs/getting-started/meta.json +3 -1
- package/docs/getting-started/nestjs.mdx +87 -20
- package/docs/getting-started/next.mdx +22 -16
- package/docs/getting-started/nitro.mdx +22 -18
- package/docs/getting-started/nuxt.mdx +15 -11
- package/docs/getting-started/python.mdx +190 -41
- package/docs/getting-started/react-router/index.mdx +33 -0
- package/docs/getting-started/react-router/meta.json +5 -0
- package/docs/getting-started/react-router/v7.mdx +237 -0
- package/docs/getting-started/react-router/v8.mdx +232 -0
- package/docs/getting-started/sveltekit.mdx +20 -16
- package/docs/getting-started/tanstack-start.mdx +17 -13
- package/docs/getting-started/vite.mdx +15 -11
- package/docs/how-it-works/cancellation.mdx +63 -63
- package/docs/how-it-works/code-transform.mdx +83 -67
- package/docs/how-it-works/encryption.mdx +30 -26
- package/docs/how-it-works/event-sourcing.mdx +125 -34
- package/docs/how-it-works/framework-integrations.mdx +96 -337
- package/docs/how-it-works/understanding-directives.mdx +22 -22
- package/docs/internal/index.mdx +6 -4
- package/docs/internal/meta.json +6 -1
- package/docs/internal/nitro-native-build.mdx +38 -0
- package/docs/internal/nitro-web-ui.mdx +24 -0
- package/docs/internal/serializable-abort-controller.mdx +7 -7
- package/docs/meta.json +3 -2
- package/docs/observability/attributes.mdx +134 -0
- package/docs/observability/index.mdx +32 -10
- package/docs/observability/meta.json +1 -1
- package/docs/observability/retention.mdx +95 -0
- package/docs/observability/tracing.mdx +124 -0
- package/docs/testing/index.mdx +36 -36
- package/docs/testing/server-based.mdx +10 -10
- package/docs/whats-new.mdx +186 -0
- package/package.json +17 -14
- package/docs/api-reference/workflow-api/world/index.mdx +0 -58
- package/docs/api-reference/workflow-api/world/meta.json +0 -4
- package/docs/api-reference/workflow-api/world/observability.mdx +0 -164
- package/docs/api-reference/workflow-api/world/queue.mdx +0 -86
- package/docs/deploying/building-a-world.mdx +0 -251
- package/docs/deploying/index.mdx +0 -95
- package/docs/deploying/meta.json +0 -4
- package/docs/deploying/world/local-world.mdx +0 -84
- package/docs/deploying/world/meta.json +0 -4
- package/docs/deploying/world/postgres-world.mdx +0 -224
- package/docs/deploying/world/vercel-world.mdx +0 -179
- package/docs/migration-guides/index.mdx +0 -34
- package/docs/migration-guides/meta.json +0 -9
- package/docs/migration-guides/migrating-from-aws-step-functions.mdx +0 -363
- package/docs/migration-guides/migrating-from-inngest.mdx +0 -314
- package/docs/migration-guides/migrating-from-temporal.mdx +0 -318
- package/docs/migration-guides/migrating-from-trigger-dev.mdx +0 -337
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "workflow",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.51",
|
|
4
4
|
"description": "Workflow SDK - Build durable, resilient, and observable workflows",
|
|
5
5
|
"main": "dist/typescript-plugin.cjs",
|
|
6
6
|
"type": "module",
|
|
@@ -49,6 +49,8 @@
|
|
|
49
49
|
"./astro": "./dist/astro.js",
|
|
50
50
|
"./vite": "./dist/vite.js",
|
|
51
51
|
"./nest": "./dist/nest.js",
|
|
52
|
+
"./nest/builder": "./dist/nest-builder.js",
|
|
53
|
+
"./nest/vercel-builder": "./dist/nest-vercel-builder.js",
|
|
52
54
|
"./runtime": "./dist/runtime.js",
|
|
53
55
|
"./observability": {
|
|
54
56
|
"types": "./dist/observability.d.ts",
|
|
@@ -56,24 +58,25 @@
|
|
|
56
58
|
}
|
|
57
59
|
},
|
|
58
60
|
"dependencies": {
|
|
61
|
+
"@workflow/astro": "5.0.0-beta.51",
|
|
62
|
+
"@workflow/cli": "5.0.0-beta.51",
|
|
63
|
+
"@workflow/core": "5.0.0-beta.51",
|
|
64
|
+
"@workflow/errors": "5.0.0-beta.21",
|
|
65
|
+
"@workflow/typescript-plugin": "5.0.0-beta.5",
|
|
66
|
+
"@workflow/utils": "5.0.0-beta.10",
|
|
59
67
|
"ms": "2.1.3",
|
|
60
|
-
"@workflow/
|
|
61
|
-
"@workflow/
|
|
62
|
-
"@workflow/
|
|
63
|
-
"@workflow/
|
|
64
|
-
"@workflow/
|
|
65
|
-
"@workflow/
|
|
66
|
-
"@workflow/next": "5.0.0-beta.5",
|
|
67
|
-
"@workflow/nest": "5.0.0-beta.5",
|
|
68
|
-
"@workflow/nitro": "5.0.0-beta.5",
|
|
69
|
-
"@workflow/nuxt": "5.0.0-beta.5",
|
|
70
|
-
"@workflow/sveltekit": "5.0.0-beta.5",
|
|
71
|
-
"@workflow/rollup": "5.0.0-beta.5"
|
|
68
|
+
"@workflow/next": "5.0.0-beta.51",
|
|
69
|
+
"@workflow/nest": "5.0.0-beta.51",
|
|
70
|
+
"@workflow/nitro": "5.0.0-beta.51",
|
|
71
|
+
"@workflow/nuxt": "5.0.0-beta.51",
|
|
72
|
+
"@workflow/sveltekit": "5.0.0-beta.51",
|
|
73
|
+
"@workflow/rollup": "5.0.0-beta.51"
|
|
72
74
|
},
|
|
73
75
|
"devDependencies": {
|
|
74
76
|
"@types/ms": "2.1.0",
|
|
75
77
|
"@types/node": "22.19.0",
|
|
76
|
-
"@workflow/tsconfig": "5.0.0-beta.0"
|
|
78
|
+
"@workflow/tsconfig": "5.0.0-beta.0",
|
|
79
|
+
"typescript": "^6.0.3"
|
|
77
80
|
},
|
|
78
81
|
"peerDependencies": {
|
|
79
82
|
"@opentelemetry/api": "1"
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: World SDK
|
|
3
|
-
description: Low-level API for inspecting and managing workflow runs, steps, events, hooks, streams, and queues.
|
|
4
|
-
type: overview
|
|
5
|
-
summary: Access workflow infrastructure via await getWorld() for building observability dashboards, admin tools, and custom integrations.
|
|
6
|
-
prerequisites:
|
|
7
|
-
- /docs/api-reference/workflow-api/get-world
|
|
8
|
-
keywords:
|
|
9
|
-
- getWorld
|
|
10
|
-
- World SDK
|
|
11
|
-
- workflow runtime
|
|
12
|
-
- observability dashboard
|
|
13
|
-
- admin panel
|
|
14
|
-
- workflow management
|
|
15
|
-
---
|
|
16
|
-
|
|
17
|
-
The World SDK provides direct access to workflow infrastructure — runs, steps, events, hooks, streams, and queues. Use it to build observability dashboards, admin panels, debugging tools, and custom workflow management logic.
|
|
18
|
-
|
|
19
|
-
```typescript lineNumbers
|
|
20
|
-
import { getWorld } from "workflow/runtime";
|
|
21
|
-
|
|
22
|
-
const world = await getWorld(); // [!code highlight]
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## Interfaces
|
|
26
|
-
|
|
27
|
-
<Cards>
|
|
28
|
-
<Card href="/docs/api-reference/workflow-api/world/storage" title="Storage">
|
|
29
|
-
Query runs, steps, hooks, and the underlying event log.
|
|
30
|
-
</Card>
|
|
31
|
-
<Card href="/docs/api-reference/workflow-api/world/streams" title="Streams">
|
|
32
|
-
Read, write, and manage real-time data streams for workflow runs.
|
|
33
|
-
</Card>
|
|
34
|
-
<Card href="/docs/api-reference/workflow-api/world/queue" title="Queue">
|
|
35
|
-
Low-level queue dispatch (internal SDK infrastructure).
|
|
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
|
-
</Cards>
|
|
41
|
-
|
|
42
|
-
<Callout type="info">
|
|
43
|
-
The World SDK is the low-level foundation that higher-level functions like [`getRun()`](/docs/api-reference/workflow-api/get-run) and [`start()`](/docs/api-reference/workflow-api/start) are built on. Use it when you need capabilities beyond what those functions provide.
|
|
44
|
-
</Callout>
|
|
45
|
-
|
|
46
|
-
## Data Hydration
|
|
47
|
-
|
|
48
|
-
Step input/output data is serialized using the [devalue](https://github.com/Rich-Harris/devalue) format. To display this data in your UI, use the hydration utilities from `workflow/observability`:
|
|
49
|
-
|
|
50
|
-
```typescript lineNumbers
|
|
51
|
-
import { hydrateResourceIO, observabilityRevivers } from "workflow/observability"; // [!code highlight]
|
|
52
|
-
|
|
53
|
-
const step = await world.steps.get(runId, stepId);
|
|
54
|
-
const hydrated = hydrateResourceIO(step, observabilityRevivers); // [!code highlight]
|
|
55
|
-
console.log(hydrated.input, hydrated.output);
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
See [Observability Utilities](/docs/api-reference/workflow-api/world/observability) for the full API.
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Observability Utilities
|
|
3
|
-
description: Hydrate step I/O, parse display names, and decrypt workflow data using workflow/observability.
|
|
4
|
-
type: reference
|
|
5
|
-
summary: "Functions: hydrateResourceIO(), parseStepName(), parseWorkflowName(), parseClassName(), getEncryptionKeyForRun(), hydrateResourceIOWithKey()."
|
|
6
|
-
prerequisites:
|
|
7
|
-
- /docs/api-reference/workflow-api/get-world
|
|
8
|
-
related:
|
|
9
|
-
- /docs/api-reference/workflow-api/world/storage
|
|
10
|
-
keywords:
|
|
11
|
-
- workflow/observability
|
|
12
|
-
- hydrateResourceIO
|
|
13
|
-
- observabilityRevivers
|
|
14
|
-
- parseStepName
|
|
15
|
-
- parseWorkflowName
|
|
16
|
-
- parseClassName
|
|
17
|
-
- getEncryptionKeyForRun
|
|
18
|
-
- hydrateResourceIOWithKey
|
|
19
|
-
- data hydration
|
|
20
|
-
- devalue deserialization
|
|
21
|
-
- encryption decryption
|
|
22
|
-
- display name parsing
|
|
23
|
-
---
|
|
24
|
-
|
|
25
|
-
The `workflow/observability` module provides utilities for working with workflow data in observability and debugging tools. It includes functions to hydrate serialized step I/O, parse machine-readable names into display-friendly formats, and decrypt encrypted workflow data.
|
|
26
|
-
|
|
27
|
-
## Import
|
|
28
|
-
|
|
29
|
-
```typescript lineNumbers
|
|
30
|
-
import { // [!code highlight]
|
|
31
|
-
hydrateResourceIO, // [!code highlight]
|
|
32
|
-
observabilityRevivers, // [!code highlight]
|
|
33
|
-
parseStepName, // [!code highlight]
|
|
34
|
-
parseWorkflowName, // [!code highlight]
|
|
35
|
-
parseClassName, // [!code highlight]
|
|
36
|
-
} from "workflow/observability"; // [!code highlight]
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
## Data Hydration
|
|
40
|
-
|
|
41
|
-
### hydrateResourceIO()
|
|
42
|
-
|
|
43
|
-
Deserialize step or run data that was serialized using the [devalue](https://github.com/Rich-Harris/devalue) format. Required to display step input/output in your UI.
|
|
44
|
-
|
|
45
|
-
```typescript lineNumbers
|
|
46
|
-
import { hydrateResourceIO, observabilityRevivers } from "workflow/observability"; // [!code highlight]
|
|
47
|
-
|
|
48
|
-
const step = await world.steps.get(runId, stepId);
|
|
49
|
-
const hydrated = hydrateResourceIO(step, observabilityRevivers); // [!code highlight]
|
|
50
|
-
console.log(hydrated.input, hydrated.output);
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
**Parameters:**
|
|
54
|
-
|
|
55
|
-
| Parameter | Type | Description |
|
|
56
|
-
|-----------|------|-------------|
|
|
57
|
-
| `resource` | `Step \| WorkflowRun` | The step or run with serialized data |
|
|
58
|
-
| `revivers` | `Revivers` | Reviver functions for deserialization. Use `observabilityRevivers` for standard use. |
|
|
59
|
-
|
|
60
|
-
**Returns:** The resource with hydrated `input` and `output` fields.
|
|
61
|
-
|
|
62
|
-
### observabilityRevivers
|
|
63
|
-
|
|
64
|
-
A set of reviver functions that handle standard workflow serialization types (Date, Map, Set, Error, etc.).
|
|
65
|
-
|
|
66
|
-
## Name Parsing
|
|
67
|
-
|
|
68
|
-
Workflow and step names are stored as machine-readable identifiers. These utilities extract display-friendly names. All return `{ shortName: string, moduleSpecifier: string } | null`.
|
|
69
|
-
|
|
70
|
-
### parseStepName()
|
|
71
|
-
|
|
72
|
-
```typescript lineNumbers
|
|
73
|
-
import { parseStepName } from "workflow/observability"; // [!code highlight]
|
|
74
|
-
|
|
75
|
-
const parsed = parseStepName("step//./src/workflows/order//processPayment"); // [!code highlight]
|
|
76
|
-
// parsed?.shortName → "processPayment"
|
|
77
|
-
// parsed?.moduleSpecifier → "./src/workflows/order"
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
### parseWorkflowName()
|
|
81
|
-
|
|
82
|
-
```typescript lineNumbers
|
|
83
|
-
import { parseWorkflowName } from "workflow/observability"; // [!code highlight]
|
|
84
|
-
|
|
85
|
-
const parsed = parseWorkflowName("workflow//./src/workflows/order//processOrder"); // [!code highlight]
|
|
86
|
-
// parsed?.shortName → "processOrder"
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
### parseClassName()
|
|
90
|
-
|
|
91
|
-
```typescript lineNumbers
|
|
92
|
-
import { parseClassName } from "workflow/observability"; // [!code highlight]
|
|
93
|
-
|
|
94
|
-
const parsed = parseClassName("class//./src/models//User"); // [!code highlight]
|
|
95
|
-
// parsed?.shortName → "User"
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
## Encryption
|
|
99
|
-
|
|
100
|
-
For workflows with encrypted step data, decrypt before hydrating.
|
|
101
|
-
|
|
102
|
-
### getEncryptionKeyForRun()
|
|
103
|
-
|
|
104
|
-
Retrieve the encryption key used for a specific workflow run.
|
|
105
|
-
|
|
106
|
-
{/* @expect-error:2305 */}
|
|
107
|
-
```typescript lineNumbers
|
|
108
|
-
import { getEncryptionKeyForRun } from "workflow/observability"; // [!code highlight]
|
|
109
|
-
|
|
110
|
-
const key = await getEncryptionKeyForRun(runId); // [!code highlight]
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
**Parameters:**
|
|
114
|
-
|
|
115
|
-
| Parameter | Type | Description |
|
|
116
|
-
|-----------|------|-------------|
|
|
117
|
-
| `runId` | `string` | The workflow run ID |
|
|
118
|
-
|
|
119
|
-
**Returns:** Encryption key for the run
|
|
120
|
-
|
|
121
|
-
### hydrateResourceIOWithKey()
|
|
122
|
-
|
|
123
|
-
Hydrate step or run data using a decryption key. Use this instead of `hydrateResourceIO()` when data is encrypted.
|
|
124
|
-
|
|
125
|
-
{/* @expect-error:2305,2724 */}
|
|
126
|
-
```typescript lineNumbers
|
|
127
|
-
import { getEncryptionKeyForRun, hydrateResourceIOWithKey } from "workflow/observability"; // [!code highlight]
|
|
128
|
-
|
|
129
|
-
const key = await getEncryptionKeyForRun(runId); // [!code highlight]
|
|
130
|
-
const hydrated = hydrateResourceIOWithKey(step, key); // [!code highlight]
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
**Parameters:**
|
|
134
|
-
|
|
135
|
-
| Parameter | Type | Description |
|
|
136
|
-
|-----------|------|-------------|
|
|
137
|
-
| `resource` | `Step \| WorkflowRun` | The step or run with encrypted serialized data |
|
|
138
|
-
| `key` | `EncryptionKey` | The encryption key from `getEncryptionKeyForRun()` |
|
|
139
|
-
|
|
140
|
-
**Returns:** The resource with decrypted and hydrated `input` and `output` fields.
|
|
141
|
-
|
|
142
|
-
## Examples
|
|
143
|
-
|
|
144
|
-
### Parse Display Names for a Run's Steps
|
|
145
|
-
|
|
146
|
-
```typescript lineNumbers
|
|
147
|
-
import { getWorld } from "workflow/runtime";
|
|
148
|
-
import { parseStepName, parseWorkflowName } from "workflow/observability"; // [!code highlight]
|
|
149
|
-
|
|
150
|
-
const world = await getWorld();
|
|
151
|
-
const run = await world.runs.get(runId, { resolveData: "none" });
|
|
152
|
-
console.log("Workflow:", parseWorkflowName(run.workflowName)?.shortName); // [!code highlight]
|
|
153
|
-
|
|
154
|
-
const steps = await world.steps.list({ runId, resolveData: "none" });
|
|
155
|
-
for (const step of steps.data) {
|
|
156
|
-
const parsed = parseStepName(step.stepName); // [!code highlight]
|
|
157
|
-
console.log(` ${parsed?.shortName}: ${step.status}`); // [!code highlight]
|
|
158
|
-
}
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
## Related
|
|
162
|
-
|
|
163
|
-
- [Storage](/docs/api-reference/workflow-api/world/storage) — Query runs, steps, hooks, and events
|
|
164
|
-
- [Serialization](/docs/foundations/serialization) — How workflow data is serialized
|
|
@@ -1,86 +0,0 @@
|
|
|
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-api/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-api/world/storage) — Create events that trigger queue dispatch
|
|
@@ -1,251 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Building a World
|
|
3
|
-
description: Implement the World interface to run workflows on any custom infrastructure.
|
|
4
|
-
type: guide
|
|
5
|
-
summary: Build a custom World adapter to run workflows on your own infrastructure.
|
|
6
|
-
prerequisites:
|
|
7
|
-
- /docs/deploying
|
|
8
|
-
- /docs/foundations/workflows-and-steps
|
|
9
|
-
related:
|
|
10
|
-
- /docs/deploying/world/local-world
|
|
11
|
-
- /docs/deploying/world/postgres-world
|
|
12
|
-
- /docs/deploying/world/vercel-world
|
|
13
|
-
---
|
|
14
|
-
|
|
15
|
-
A **World** is the abstraction that allows workflows to run on any infrastructure. It handles workflow storage, step execution queuing, and data streaming. This guide explains the World interface and how to implement your own.
|
|
16
|
-
|
|
17
|
-
<Callout>
|
|
18
|
-
Before building a custom World, check the [Worlds Ecosystem](/worlds) page — there may already be a community implementation for your infrastructure.
|
|
19
|
-
</Callout>
|
|
20
|
-
|
|
21
|
-
<Callout type="info">
|
|
22
|
-
**Reference Implementation:** The [Postgres World source code](https://github.com/vercel/workflow/tree/main/packages/world-postgres) is a production-ready example of how to implement the World interface with a database backend and graphile-worker for queuing.
|
|
23
|
-
</Callout>
|
|
24
|
-
|
|
25
|
-
## What is a World?
|
|
26
|
-
|
|
27
|
-
A World connects workflows to the infrastructure that powers them. The World interface abstracts three core responsibilities:
|
|
28
|
-
|
|
29
|
-
1. **Storage** — Persisting workflow runs, steps, hooks, and the event log
|
|
30
|
-
2. **Queue** — Enqueuing and processing workflow and step invocations
|
|
31
|
-
3. **Streamer** — Managing real-time data streams between workflows and clients
|
|
32
|
-
|
|
33
|
-
{/* @skip-typecheck - interface definition, not runnable code */}
|
|
34
|
-
```typescript
|
|
35
|
-
interface World extends Storage, Queue, Streamer {
|
|
36
|
-
start?(): Promise<void>;
|
|
37
|
-
close?(): Promise<void>;
|
|
38
|
-
getEncryptionKeyForRun?(run: WorkflowRun): Promise<Uint8Array | undefined>;
|
|
39
|
-
getEncryptionKeyForRun?(runId: string, context?: Record<string, unknown>): Promise<Uint8Array | undefined>;
|
|
40
|
-
}
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
The optional `start()` method initializes background tasks (for example, queue polling). The optional `close()` method releases resources like connection pools and listeners. The optional `getEncryptionKeyForRun()` method returns the AES-256 key used to encrypt data for a run; if it is not implemented, encryption is disabled.
|
|
44
|
-
|
|
45
|
-
## The Event Log Model
|
|
46
|
-
|
|
47
|
-
Workflow storage is built on an **append-only event log**. All state changes happen through events — you never modify runs, steps, or hooks directly. Instead, you create events that update the materialized state.
|
|
48
|
-
|
|
49
|
-
Events fall into three categories: run lifecycle events, step lifecycle events, and hook lifecycle events. See the [Event Sourcing](/docs/how-it-works/event-sourcing) documentation for a complete list of event types and their semantics.
|
|
50
|
-
|
|
51
|
-
## Storage Interface
|
|
52
|
-
|
|
53
|
-
The Storage interface provides read access to materialized entities and write access through events:
|
|
54
|
-
|
|
55
|
-
{/* @skip-typecheck - interface definition, not runnable code */}
|
|
56
|
-
```typescript
|
|
57
|
-
interface Storage {
|
|
58
|
-
runs: {
|
|
59
|
-
get(id: string, params?: GetWorkflowRunParams): Promise<WorkflowRun>;
|
|
60
|
-
list(params?: ListWorkflowRunsParams): Promise<PaginatedResponse<WorkflowRun>>;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
steps: {
|
|
64
|
-
get(runId: string | undefined, stepId: string, params?: GetStepParams): Promise<Step>;
|
|
65
|
-
list(params: ListWorkflowRunStepsParams): Promise<PaginatedResponse<Step>>;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
events: {
|
|
69
|
-
// Create a new workflow run (runId may be client-provided or null for server generation)
|
|
70
|
-
create(runId: string | null, data: RunCreatedEventRequest, params?: CreateEventParams): Promise<EventResult>;
|
|
71
|
-
|
|
72
|
-
// Create an event for an existing run
|
|
73
|
-
create(runId: string, data: CreateEventRequest, params?: CreateEventParams): Promise<EventResult>;
|
|
74
|
-
|
|
75
|
-
list(params: ListEventsParams): Promise<PaginatedResponse<Event>>;
|
|
76
|
-
listByCorrelationId(params: ListEventsByCorrelationIdParams): Promise<PaginatedResponse<Event>>;
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
hooks: {
|
|
80
|
-
get(hookId: string, params?: GetHookParams): Promise<Hook>;
|
|
81
|
-
getByToken(token: string, params?: GetHookParams): Promise<Hook>;
|
|
82
|
-
list(params: ListHooksParams): Promise<PaginatedResponse<Hook>>;
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
### Key Implementation Details
|
|
88
|
-
|
|
89
|
-
**Event Creation:** When `events.create()` is called, your implementation must:
|
|
90
|
-
1. Persist the event to the event log
|
|
91
|
-
2. Atomically update the affected entity (run, step, or hook)
|
|
92
|
-
3. Return both the created event and the updated entity
|
|
93
|
-
|
|
94
|
-
**Run Creation:** For `run_created` events, the `runId` parameter may be a client-provided string or `null`. When `null`, your World generates and returns a new `runId`.
|
|
95
|
-
|
|
96
|
-
**Hook Tokens:** Hook tokens must be unique. If a `hook_created` event conflicts with an existing token, return a `hook_conflict` event instead.
|
|
97
|
-
|
|
98
|
-
**Automatic Hook Disposal:** When a workflow reaches a terminal state (`completed`, `failed`, or `cancelled`), automatically dispose of all associated hooks to release tokens for reuse.
|
|
99
|
-
|
|
100
|
-
## Queue Interface
|
|
101
|
-
|
|
102
|
-
The Queue interface handles asynchronous execution of workflows and steps:
|
|
103
|
-
|
|
104
|
-
{/* @skip-typecheck - interface definition, not runnable code */}
|
|
105
|
-
```typescript
|
|
106
|
-
interface Queue {
|
|
107
|
-
getDeploymentId(): Promise<string>;
|
|
108
|
-
|
|
109
|
-
queue(
|
|
110
|
-
queueName: ValidQueueName,
|
|
111
|
-
message: QueuePayload,
|
|
112
|
-
opts?: QueueOptions
|
|
113
|
-
): Promise<{ messageId: MessageId }>;
|
|
114
|
-
|
|
115
|
-
createQueueHandler(
|
|
116
|
-
queueNamePrefix: QueuePrefix,
|
|
117
|
-
handler: (message: unknown, meta: { attempt: number; queueName: ValidQueueName; messageId: MessageId }) => Promise<void | { timeoutSeconds: number }>
|
|
118
|
-
): (req: Request) => Promise<Response>;
|
|
119
|
-
}
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
### Queue Names
|
|
123
|
-
|
|
124
|
-
Queue names follow a specific pattern:
|
|
125
|
-
- `__wkf_workflow_<name>` — For workflow invocations
|
|
126
|
-
- `__wkf_step_<name>` — For step invocations
|
|
127
|
-
|
|
128
|
-
### Message Payloads
|
|
129
|
-
|
|
130
|
-
Two types of messages flow through queues:
|
|
131
|
-
|
|
132
|
-
**Workflow Invocations:**
|
|
133
|
-
{/* @skip-typecheck - interface definition, not runnable code */}
|
|
134
|
-
```typescript
|
|
135
|
-
interface WorkflowInvokePayload {
|
|
136
|
-
runId: string;
|
|
137
|
-
traceCarrier?: Record<string, string>; // OpenTelemetry context
|
|
138
|
-
requestedAt?: Date;
|
|
139
|
-
}
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
**Step Invocations:**
|
|
143
|
-
{/* @skip-typecheck - interface definition, not runnable code */}
|
|
144
|
-
```typescript
|
|
145
|
-
interface StepInvokePayload {
|
|
146
|
-
workflowName: string;
|
|
147
|
-
workflowRunId: string;
|
|
148
|
-
workflowStartedAt: number;
|
|
149
|
-
stepId: string;
|
|
150
|
-
traceCarrier?: Record<string, string>;
|
|
151
|
-
requestedAt?: Date;
|
|
152
|
-
}
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
### Implementation Considerations
|
|
156
|
-
|
|
157
|
-
- Messages must be delivered at-least-once
|
|
158
|
-
- Support configurable retry policies
|
|
159
|
-
- Track attempt counts for observability
|
|
160
|
-
- Implement idempotency using the `idempotencyKey` option when provided
|
|
161
|
-
|
|
162
|
-
## Streamer Interface
|
|
163
|
-
|
|
164
|
-
The Streamer interface enables real-time data streaming:
|
|
165
|
-
|
|
166
|
-
{/* @skip-typecheck - interface definition, not runnable code */}
|
|
167
|
-
```typescript
|
|
168
|
-
interface Streamer {
|
|
169
|
-
streamFlushIntervalMs?: number;
|
|
170
|
-
|
|
171
|
-
streams: {
|
|
172
|
-
write(
|
|
173
|
-
runId: string,
|
|
174
|
-
name: string,
|
|
175
|
-
chunk: string | Uint8Array
|
|
176
|
-
): Promise<void>;
|
|
177
|
-
|
|
178
|
-
writeMulti?(
|
|
179
|
-
runId: string,
|
|
180
|
-
name: string,
|
|
181
|
-
chunks: (string | Uint8Array)[]
|
|
182
|
-
): Promise<void>;
|
|
183
|
-
|
|
184
|
-
close(runId: string, name: string): Promise<void>;
|
|
185
|
-
|
|
186
|
-
get(
|
|
187
|
-
runId: string,
|
|
188
|
-
name: string,
|
|
189
|
-
startIndex?: number
|
|
190
|
-
): Promise<ReadableStream<Uint8Array>>;
|
|
191
|
-
|
|
192
|
-
list(runId: string): Promise<string[]>;
|
|
193
|
-
|
|
194
|
-
/** Paginated snapshot of stream chunks. */
|
|
195
|
-
getChunks(
|
|
196
|
-
runId: string,
|
|
197
|
-
name: string,
|
|
198
|
-
options?: { limit?: number; cursor?: string }
|
|
199
|
-
): Promise<{
|
|
200
|
-
data: { index: number; data: Uint8Array }[];
|
|
201
|
-
cursor: string | null;
|
|
202
|
-
hasMore: boolean;
|
|
203
|
-
done: boolean;
|
|
204
|
-
}>;
|
|
205
|
-
|
|
206
|
-
/** Lightweight metadata: tail index and completion flag. */
|
|
207
|
-
getInfo(
|
|
208
|
-
runId: string,
|
|
209
|
-
name: string
|
|
210
|
-
): Promise<{ tailIndex: number; done: boolean }>;
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
Streams are identified by a combination of `runId` and `name`. Each workflow run can have multiple named streams.
|
|
216
|
-
`writeMulti()` is an optional optimization for batching multiple writes.
|
|
217
|
-
|
|
218
|
-
`getChunks` returns a paginated snapshot of currently available chunks (unlike `get` which returns a live `ReadableStream` that waits for new chunks). `getInfo` returns the tail index (last chunk index, 0-based, or `-1` when empty) and whether the stream is complete — useful for resolving negative `startIndex` values into absolute positions.
|
|
219
|
-
|
|
220
|
-
## Reference Implementations
|
|
221
|
-
|
|
222
|
-
Study these implementations for guidance:
|
|
223
|
-
|
|
224
|
-
- **[Local World](https://github.com/vercel/workflow/tree/main/packages/world-local)** — Filesystem-based, great for understanding the basics
|
|
225
|
-
- **[Postgres World](https://github.com/vercel/workflow/tree/main/packages/world-postgres)** — Database-backed with graphile-worker for queuing
|
|
226
|
-
|
|
227
|
-
## Testing Your World
|
|
228
|
-
|
|
229
|
-
Workflow SDK includes an E2E test suite that validates World implementations. Once your World is published to npm:
|
|
230
|
-
|
|
231
|
-
1. Add your world to [`worlds-manifest.json`](https://github.com/vercel/workflow/blob/main/worlds-manifest.json)
|
|
232
|
-
2. Open a PR to the Workflow repository
|
|
233
|
-
3. CI will automatically run the E2E test suite against your implementation
|
|
234
|
-
|
|
235
|
-
Your world will then appear on the [Worlds Ecosystem](/worlds) page with its compatibility status and performance benchmarks.
|
|
236
|
-
|
|
237
|
-
## Publishing Your World
|
|
238
|
-
|
|
239
|
-
1. **Package your World** — Export a default World instance from your package
|
|
240
|
-
2. **Publish to npm** — Publish your package to npm
|
|
241
|
-
3. **Add to the manifest** — Submit a PR adding your world to [`worlds-manifest.json`](https://github.com/vercel/workflow/blob/main/worlds-manifest.json)
|
|
242
|
-
4. **Document configuration** — Clearly document any required environment variables
|
|
243
|
-
|
|
244
|
-
```json
|
|
245
|
-
// worlds-manifest.json entry
|
|
246
|
-
{
|
|
247
|
-
"package": "your-world-package",
|
|
248
|
-
"repository": "https://github.com/you/your-world",
|
|
249
|
-
"docs": "https://github.com/you/your-world#readme"
|
|
250
|
-
}
|
|
251
|
-
```
|