workflow 5.0.0-beta.3 → 5.0.0-beta.30

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.
Files changed (176) hide show
  1. package/dist/api-workflow.d.ts +1 -1
  2. package/dist/api-workflow.d.ts.map +1 -1
  3. package/dist/api-workflow.js +1 -1
  4. package/dist/api.d.ts +5 -1
  5. package/dist/api.d.ts.map +1 -1
  6. package/dist/api.js +12 -2
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +6 -1
  10. package/dist/internal/builtins.d.ts +17 -0
  11. package/dist/internal/builtins.d.ts.map +1 -1
  12. package/dist/internal/builtins.js +65 -1
  13. package/dist/observability.d.ts +1 -1
  14. package/dist/observability.js +2 -2
  15. package/dist/runtime.d.ts +2 -1
  16. package/dist/runtime.d.ts.map +1 -1
  17. package/dist/runtime.js +5 -2
  18. package/docs/ai/chat-session-modeling.mdx +7 -3
  19. package/docs/ai/defining-tools.mdx +2 -2
  20. package/docs/ai/index.mdx +28 -23
  21. package/docs/ai/message-queueing.mdx +10 -10
  22. package/docs/ai/resumable-streams.mdx +9 -1
  23. package/docs/api-reference/index.mdx +24 -0
  24. package/docs/api-reference/meta.json +8 -0
  25. package/docs/api-reference/vitest/index.mdx +28 -7
  26. package/docs/api-reference/workflow/create-hook.mdx +38 -0
  27. package/docs/api-reference/workflow/create-webhook.mdx +1 -0
  28. package/docs/api-reference/workflow/experimental-set-attributes.mdx +65 -0
  29. package/docs/api-reference/workflow/fetch.mdx +5 -0
  30. package/docs/api-reference/workflow/index.mdx +3 -0
  31. package/docs/api-reference/workflow-ai/durable-agent.mdx +7 -45
  32. package/docs/api-reference/workflow-ai/index.mdx +2 -2
  33. package/docs/api-reference/workflow-ai/workflow-chat-transport.mdx +44 -1
  34. package/docs/api-reference/workflow-api/get-hook-by-token.mdx +7 -0
  35. package/docs/api-reference/workflow-api/get-run.mdx +25 -0
  36. package/docs/api-reference/workflow-api/index.mdx +6 -8
  37. package/docs/api-reference/workflow-api/resume-hook.mdx +57 -0
  38. package/docs/api-reference/workflow-api/start.mdx +13 -5
  39. package/docs/api-reference/workflow-astro/index.mdx +18 -0
  40. package/docs/api-reference/workflow-astro/meta.json +4 -0
  41. package/docs/api-reference/workflow-astro/workflow.mdx +45 -0
  42. package/docs/api-reference/workflow-errors/hook-conflict-error.mdx +60 -0
  43. package/docs/api-reference/workflow-errors/index.mdx +85 -0
  44. package/docs/api-reference/workflow-errors/meta.json +5 -0
  45. package/docs/api-reference/workflow-errors/run-not-supported-error.mdx +58 -0
  46. package/docs/api-reference/workflow-errors/workflow-error.mdx +52 -0
  47. package/docs/api-reference/workflow-errors/workflow-run-failed-error.mdx +16 -6
  48. package/docs/api-reference/workflow-errors/workflow-run-not-completed-error.mdx +58 -0
  49. package/docs/api-reference/workflow-errors/workflow-runtime-error.mdx +58 -0
  50. package/docs/api-reference/workflow-nest/configure-workflow-controller.mdx +33 -0
  51. package/docs/api-reference/workflow-nest/index.mdx +31 -0
  52. package/docs/api-reference/workflow-nest/meta.json +9 -0
  53. package/docs/api-reference/workflow-nest/nest-local-builder.mdx +64 -0
  54. package/docs/api-reference/workflow-nest/workflow-controller.mdx +40 -0
  55. package/docs/api-reference/workflow-nest/workflow-module.mdx +74 -0
  56. package/docs/api-reference/workflow-next/with-workflow.mdx +56 -2
  57. package/docs/api-reference/workflow-nitro/index.mdx +60 -0
  58. package/docs/api-reference/workflow-nuxt/index.mdx +48 -0
  59. package/docs/api-reference/workflow-observability/hydrate-data.mdx +35 -0
  60. package/docs/api-reference/workflow-observability/hydrate-resource-io.mdx +62 -0
  61. package/docs/api-reference/workflow-observability/index.mdx +64 -0
  62. package/docs/api-reference/workflow-observability/meta.json +11 -0
  63. package/docs/api-reference/workflow-observability/observability-revivers.mdx +50 -0
  64. package/docs/api-reference/workflow-observability/parse-class-name.mdx +41 -0
  65. package/docs/api-reference/workflow-observability/parse-step-name.mdx +40 -0
  66. package/docs/api-reference/workflow-observability/parse-workflow-name.mdx +55 -0
  67. package/docs/api-reference/workflow-runtime/create-world.mdx +39 -0
  68. package/docs/api-reference/workflow-runtime/get-world-handlers.mdx +44 -0
  69. package/docs/api-reference/{workflow-api → workflow-runtime}/get-world.mdx +7 -10
  70. package/docs/api-reference/workflow-runtime/health-check.mdx +50 -0
  71. package/docs/api-reference/workflow-runtime/index.mdx +43 -0
  72. package/docs/api-reference/workflow-runtime/meta.json +12 -0
  73. package/docs/api-reference/workflow-runtime/set-world.mdx +49 -0
  74. package/docs/api-reference/workflow-runtime/workflow-entrypoint.mdx +42 -0
  75. package/docs/api-reference/{workflow-api → workflow-runtime}/world/index.mdx +5 -8
  76. package/docs/api-reference/workflow-runtime/world/meta.json +4 -0
  77. package/docs/api-reference/{workflow-api → workflow-runtime}/world/queue.mdx +4 -2
  78. package/docs/api-reference/{workflow-api → workflow-runtime}/world/storage.mdx +11 -4
  79. package/docs/api-reference/{workflow-api → workflow-runtime}/world/streams.mdx +2 -2
  80. package/docs/api-reference/workflow-serde/index.mdx +0 -1
  81. package/docs/api-reference/workflow-serde/workflow-deserialize.mdx +1 -2
  82. package/docs/api-reference/workflow-serde/workflow-serialize.mdx +1 -2
  83. package/docs/api-reference/workflow-sveltekit/index.mdx +18 -0
  84. package/docs/api-reference/workflow-sveltekit/meta.json +4 -0
  85. package/docs/api-reference/workflow-sveltekit/workflow-plugin.mdx +42 -0
  86. package/docs/api-reference/workflow-vite/index.mdx +18 -0
  87. package/docs/api-reference/workflow-vite/meta.json +4 -0
  88. package/docs/api-reference/workflow-vite/workflow.mdx +48 -0
  89. package/docs/changelog/attributes-mvp.mdx +380 -0
  90. package/docs/changelog/eager-processing.mdx +269 -0
  91. package/docs/changelog/index.mdx +2 -1
  92. package/docs/changelog/lazy-event-creation.md +127 -0
  93. package/docs/changelog/meta.json +8 -1
  94. package/docs/changelog/resilient-start.mdx +31 -283
  95. package/docs/changelog/step-message-ownership.mdx +360 -0
  96. package/docs/changelog/turbo-mode.md +87 -0
  97. package/docs/configuration/build-and-diagnostics.mdx +51 -0
  98. package/docs/configuration/cli-and-web-ui.mdx +154 -0
  99. package/docs/configuration/framework-options.mdx +165 -0
  100. package/docs/configuration/index.mdx +32 -0
  101. package/docs/configuration/meta.json +12 -0
  102. package/docs/configuration/runtime-tuning.mdx +156 -0
  103. package/docs/configuration/worlds.mdx +228 -0
  104. package/docs/cookbook/advanced/child-workflows.mdx +199 -256
  105. package/docs/cookbook/advanced/meta.json +1 -1
  106. package/docs/cookbook/advanced/publishing-libraries.mdx +13 -12
  107. package/docs/cookbook/advanced/serializable-steps.mdx +8 -4
  108. package/docs/cookbook/advanced/upgrading-workflows.mdx +195 -0
  109. package/docs/cookbook/agent-patterns/agent-cancellation.mdx +31 -76
  110. package/docs/cookbook/agent-patterns/durable-agent.mdx +11 -143
  111. package/docs/cookbook/agent-patterns/human-in-the-loop.mdx +7 -3
  112. package/docs/cookbook/common-patterns/idempotency.mdx +36 -52
  113. package/docs/cookbook/common-patterns/rate-limiting.mdx +1 -1
  114. package/docs/cookbook/common-patterns/saga.mdx +2 -2
  115. package/docs/cookbook/common-patterns/scheduling.mdx +8 -0
  116. package/docs/cookbook/common-patterns/timeouts.mdx +2 -1
  117. package/docs/cookbook/common-patterns/workflow-composition.mdx +15 -16
  118. package/docs/cookbook/index.mdx +3 -3
  119. package/docs/cookbook/integrations/ai-sdk.mdx +60 -28
  120. package/docs/cookbook/integrations/chat-sdk.mdx +13 -0
  121. package/docs/cookbook/integrations/sandbox.mdx +13 -0
  122. package/docs/deploying/building-a-world.mdx +1 -1
  123. package/docs/deploying/index.mdx +1 -0
  124. package/docs/deploying/world/local-world.mdx +23 -6
  125. package/docs/deploying/world/postgres-world.mdx +79 -13
  126. package/docs/deploying/world/vercel-world.mdx +47 -12
  127. package/docs/errors/abort-signal-timeout-in-workflow.mdx +80 -0
  128. package/docs/errors/corrupted-event-log.mdx +5 -5
  129. package/docs/errors/hook-conflict.mdx +56 -4
  130. package/docs/errors/index.mdx +1 -35
  131. package/docs/errors/replay-divergence.mdx +27 -0
  132. package/docs/errors/runtime-decryption-failed.mdx +77 -0
  133. package/docs/errors/step-executed-multiple-times.mdx +23 -0
  134. package/docs/errors/step-not-registered.mdx +1 -1
  135. package/docs/foundations/cancellation.mdx +459 -0
  136. package/docs/foundations/errors-and-retries.mdx +7 -3
  137. package/docs/foundations/hooks.mdx +29 -0
  138. package/docs/foundations/idempotency.mdx +236 -11
  139. package/docs/foundations/index.mdx +1 -23
  140. package/docs/foundations/meta.json +3 -1
  141. package/docs/foundations/serialization.mdx +77 -41
  142. package/docs/foundations/starting-workflows.mdx +5 -1
  143. package/docs/foundations/streaming.mdx +14 -23
  144. package/docs/foundations/versioning.mdx +263 -0
  145. package/docs/getting-started/astro.mdx +6 -0
  146. package/docs/getting-started/index.mdx +6 -7
  147. package/docs/getting-started/meta.json +1 -0
  148. package/docs/getting-started/nestjs.mdx +9 -0
  149. package/docs/getting-started/next.mdx +5 -3
  150. package/docs/getting-started/nitro.mdx +22 -0
  151. package/docs/getting-started/sveltekit.mdx +6 -0
  152. package/docs/getting-started/tanstack-start.mdx +241 -0
  153. package/docs/how-it-works/cancellation.mdx +287 -0
  154. package/docs/how-it-works/code-transform.mdx +2 -2
  155. package/docs/how-it-works/encryption.mdx +2 -2
  156. package/docs/how-it-works/event-sourcing.mdx +2 -2
  157. package/docs/how-it-works/meta.json +2 -1
  158. package/docs/internal/index.mdx +21 -0
  159. package/docs/internal/meta.json +10 -0
  160. package/docs/internal/nitro-native-build.mdx +38 -0
  161. package/docs/internal/nitro-web-ui.mdx +24 -0
  162. package/docs/internal/serializable-abort-controller.mdx +148 -0
  163. package/docs/meta.json +1 -1
  164. package/docs/migration-guides/migrating-from-aws-step-functions.mdx +7 -12
  165. package/docs/migration-guides/migrating-from-inngest.mdx +7 -17
  166. package/docs/migration-guides/migrating-from-temporal.mdx +6 -11
  167. package/docs/migration-guides/migrating-from-trigger-dev.mdx +8 -17
  168. package/docs/observability/attributes.mdx +87 -0
  169. package/docs/observability/index.mdx +18 -1
  170. package/docs/observability/meta.json +1 -1
  171. package/docs/observability/tracing.mdx +119 -0
  172. package/docs/testing/index.mdx +2 -2
  173. package/package.json +14 -13
  174. package/docs/api-reference/workflow-api/world/meta.json +0 -4
  175. package/docs/api-reference/workflow-api/world/observability.mdx +0 -164
  176. package/docs/cookbook/advanced/distributed-abort-controller.mdx +0 -318
@@ -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-api/world) reference for complete documentation:
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-api/world/storage" title="Storage">
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-api/world/streams" title="Streams">
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-api/world/queue" title="Queue">
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 [Observability Utilities](/docs/api-reference/workflow-api/world/observability) for the full hydration, parsing, and encryption API.
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 "@workflow/utils/parse-name"; // [!code highlight]
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()` from `@workflow/utils/parse-name` to extract the `shortName` (e.g., `"processOrder"`)
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,12 @@
1
+ {
2
+ "title": "workflow/runtime",
3
+ "pages": [
4
+ "get-world",
5
+ "world",
6
+ "create-world",
7
+ "set-world",
8
+ "get-world-handlers",
9
+ "workflow-entrypoint",
10
+ "health-check"
11
+ ]
12
+ }
@@ -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,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.
@@ -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 via await getWorld() for building observability dashboards, admin tools, and custom integrations.
6
6
  prerequisites:
7
- - /docs/api-reference/workflow-api/get-world
7
+ - /docs/api-reference/workflow-runtime/get-world
8
8
  keywords:
9
9
  - getWorld
10
10
  - World SDK
@@ -25,18 +25,15 @@ const world = await getWorld(); // [!code highlight]
25
25
  ## Interfaces
26
26
 
27
27
  <Cards>
28
- <Card href="/docs/api-reference/workflow-api/world/storage" title="Storage">
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-api/world/streams" title="Streams">
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-api/world/queue" title="Queue">
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 [Observability Utilities](/docs/api-reference/workflow-api/world/observability) for the full API.
55
+ See [`workflow/observability`](/docs/api-reference/workflow-observability) for the full API.
@@ -0,0 +1,4 @@
1
+ {
2
+ "title": "World SDK",
3
+ "pages": ["storage", "streams", "queue"]
4
+ }
@@ -4,7 +4,7 @@ description: Low-level queue interface for dispatching workflow and step invocat
4
4
  type: reference
5
5
  summary: "Methods: getDeploymentId(), queue(), createQueueHandler(). Internal queue dispatch — normally handled by the SDK."
6
6
  prerequisites:
7
- - /docs/api-reference/workflow-api/get-world
7
+ - /docs/api-reference/workflow-runtime/get-world
8
8
  related:
9
9
  - /docs/api-reference/workflow-api/start
10
10
  - /docs/foundations/starting-workflows
@@ -79,8 +79,10 @@ const handler = world.createQueueHandler(prefix, callback); // [!code highlight]
79
79
 
80
80
  **Returns:** `(req: Request) => Promise<Response>`
81
81
 
82
+ `meta.messageId` should be stable across redeliveries of the same message (one ID per enqueued message, reused on every delivery attempt). The runtime records it on inline `step_started` events as a liveness lease so that only a redelivery of the owning message re-executes a crashed inline step before the lease expires (see [Inline step message ownership](/v5/docs/changelog/step-message-ownership)). A World whose queue mints a fresh ID per delivery degrades gracefully — crashed inline steps recover via the delayed backstop instead of immediately on redelivery — but never wedges or duplicates.
83
+
82
84
  ## Related
83
85
 
84
86
  - [start()](/docs/api-reference/workflow-api/start) — The standard way to start workflow runs
85
87
  - [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
88
+ - [Storage](/docs/api-reference/workflow-runtime/world/storage) — Create events that trigger queue dispatch
@@ -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-api/get-world
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-api/world/observability
11
+ - /docs/api-reference/workflow-observability
12
12
  keywords:
13
13
  - world.events
14
14
  - world.runs
@@ -116,6 +116,7 @@ const result = await world.events.listByCorrelationId({ // [!code highlight]
116
116
  | Category | Types |
117
117
  |----------|-------|
118
118
  | Run | `run_created`, `run_started`, `run_completed`, `run_failed`, `run_cancelled` |
119
+ | Attribute | `attr_set` |
119
120
  | Step | `step_created`, `step_started`, `step_completed`, `step_failed`, `step_retrying` |
120
121
  | Hook | `hook_created`, `hook_received`, `hook_disposed`, `hook_conflict` |
121
122
  | Wait | `wait_created`, `wait_completed` |
@@ -229,7 +230,7 @@ const result = await world.steps.list({ // [!code highlight]
229
230
  | `retryAfter` | `string \| null` | ISO timestamp for next retry attempt |
230
231
 
231
232
  <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 [Observability Utilities](/docs/api-reference/workflow-api/world/observability).
233
+ 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
234
  </Callout>
234
235
 
235
236
  <Callout type="warn">
@@ -258,6 +259,12 @@ const hook = await world.hooks.get(hookId); // [!code highlight]
258
259
 
259
260
  Look up a hook by its token. Useful in webhook resume flows where you receive a token in the callback URL.
260
261
 
262
+ <Callout type="info">
263
+ For runtime application code, prefer [`getHookByToken()`](/docs/api-reference/workflow-api/get-hook-by-token). Use `world.hooks.getByToken()` when you are working directly with the World storage interface for custom tooling, admin views, or low-level integrations.
264
+
265
+ Hook-token lookup is the low-level form of the recommended idempotency flow: if a hook is already registered for your business key, reuse the hook's `runId` or resume that hook instead of starting another run. If no hook exists yet, start a workflow that creates the deterministic hook near the beginning and checks `await hook.getConflict()` to detect whether another run claimed the token first — on a conflict it resolves with the run that owns the token. See [Run idempotency](/docs/foundations/idempotency#run-idempotency).
266
+ </Callout>
267
+
261
268
  ```typescript lineNumbers
262
269
  const hook = await world.hooks.getByToken(token); // [!code highlight]
263
270
  ```
@@ -402,7 +409,7 @@ for (const event of events.data) {
402
409
 
403
410
  - [Event Sourcing](/docs/how-it-works/event-sourcing) — How the event log powers workflow replay and state
404
411
  - [getRun()](/docs/api-reference/workflow-api/get-run) — Higher-level API for working with individual runs
405
- - [Observability Utilities](/docs/api-reference/workflow-api/world/observability) — Hydrate step I/O, parse display names, decrypt data
412
+ - [`workflow/observability`](/docs/api-reference/workflow-observability) — Hydrate step I/O and parse display names
406
413
  - [resumeHook()](/docs/api-reference/workflow-api/resume-hook) — Resume a workflow by sending a payload to a hook
407
414
  - [Hooks](/docs/foundations/hooks) — Core concepts for hooks and pause points
408
415
  - [Workflows and Steps](/docs/foundations/workflows-and-steps) — Core concepts for steps
@@ -4,7 +4,7 @@ description: Read, write, and manage real-time data streams for workflow runs.
4
4
  type: reference
5
5
  summary: "Methods: streams.write(), streams.writeMulti(), streams.get(), streams.close(), streams.list(), streams.getChunks(), streams.getInfo(). Stream methods live on world.streams."
6
6
  prerequisites:
7
- - /docs/api-reference/workflow-api/get-world
7
+ - /docs/api-reference/workflow-runtime/get-world
8
8
  related:
9
9
  - /docs/foundations/streaming
10
10
  - /docs/api-reference/workflow/get-writable
@@ -213,4 +213,4 @@ do {
213
213
 
214
214
  - [Streaming](/docs/foundations/streaming) — Core concepts for streaming data from workflows
215
215
  - [getWritable()](/docs/api-reference/workflow/get-writable) — The standard way to write to streams from within steps
216
- - [Storage](/docs/api-reference/workflow-api/world/storage) — Query runs, steps, hooks, and events
216
+ - [Storage](/docs/api-reference/workflow-runtime/world/storage) — Query runs, steps, hooks, and events
@@ -29,7 +29,6 @@ The `@workflow/serde` package provides two symbols that allow you to define cust
29
29
 
30
30
  ## Quick Example
31
31
 
32
- {/* @expect-error:2351 */}
33
32
 
34
33
  ```typescript lineNumbers
35
34
  import { WORKFLOW_SERIALIZE, WORKFLOW_DESERIALIZE } from "@workflow/serde";
@@ -6,7 +6,6 @@ A symbol used to define custom deserialization for user-defined class instances.
6
6
 
7
7
  ## Usage
8
8
 
9
- {/* @expect-error:2351 */}
10
9
 
11
10
  ```typescript lineNumbers
12
11
  import { WORKFLOW_SERIALIZE, WORKFLOW_DESERIALIZE } from "@workflow/serde";
@@ -26,7 +25,7 @@ class Point {
26
25
 
27
26
  ## API Signature
28
27
 
29
- {/* @skip-typecheck */}
28
+ {/* @skip-typecheck: type-only signature snippet, not compilable code */}
30
29
 
31
30
  ```typescript
32
31
  static [WORKFLOW_DESERIALIZE](data: SerializableData): T
@@ -6,7 +6,6 @@ A symbol used to define custom serialization for user-defined class instances. T
6
6
 
7
7
  ## Usage
8
8
 
9
- {/* @expect-error:2351 */}
10
9
 
11
10
  ```typescript lineNumbers
12
11
  import { WORKFLOW_SERIALIZE, WORKFLOW_DESERIALIZE } from "@workflow/serde";
@@ -26,7 +25,7 @@ class Point {
26
25
 
27
26
  ## API Signature
28
27
 
29
- {/* @skip-typecheck */}
28
+ {/* @skip-typecheck: type-only signature snippet, not compilable code */}
30
29
 
31
30
  ```typescript
32
31
  static [WORKFLOW_SERIALIZE](instance: T): SerializableData
@@ -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,4 @@
1
+ {
2
+ "title": "workflow/sveltekit",
3
+ "pages": ["workflow-plugin"]
4
+ }
@@ -0,0 +1,42 @@
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
+ | Parameter | Type | Description |
31
+ | --- | --- | --- |
32
+ | `options` | `WorkflowPluginOptions` | Optional. Configures the workflow build. |
33
+
34
+ #### WorkflowPluginOptions
35
+
36
+ | Option | Type | Default | Description |
37
+ | --- | --- | --- | --- |
38
+ | `sourcemap` | `boolean \| 'inline' \| 'linked' \| 'external' \| 'both'` | `'inline'` (dev) / `false` (prod) | Controls source maps on generated workflow bundles. Accepts the same values as esbuild's `sourcemap` option. Defaults to `'inline'` in development and `false` in production (smaller function bundles — helps stay under the Vercel 250MB function size limit). Set it explicitly, or use the `WORKFLOW_SOURCEMAP` environment variable, to override in either environment. |
39
+
40
+ ### Returns
41
+
42
+ 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.