workflow 5.0.0-beta.2 → 5.0.0-beta.21

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 (170) 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 +2 -2
  4. package/dist/api.d.ts +5 -1
  5. package/dist/api.d.ts.map +1 -1
  6. package/dist/api.js +14 -2
  7. package/dist/internal/builtins.d.ts +17 -0
  8. package/dist/internal/builtins.d.ts.map +1 -1
  9. package/dist/internal/builtins.js +65 -1
  10. package/dist/observability.d.ts +1 -1
  11. package/dist/observability.js +2 -2
  12. package/dist/runtime.d.ts +1 -1
  13. package/dist/runtime.d.ts.map +1 -1
  14. package/dist/runtime.js +2 -2
  15. package/docs/ai/index.mdx +27 -23
  16. package/docs/api-reference/index.mdx +24 -0
  17. package/docs/api-reference/meta.json +8 -0
  18. package/docs/api-reference/vitest/index.mdx +28 -7
  19. package/docs/api-reference/workflow/create-hook.mdx +38 -0
  20. package/docs/api-reference/workflow/create-webhook.mdx +1 -0
  21. package/docs/api-reference/workflow/experimental-set-attributes.mdx +65 -0
  22. package/docs/api-reference/workflow/fetch.mdx +5 -0
  23. package/docs/api-reference/workflow/index.mdx +3 -0
  24. package/docs/api-reference/workflow-ai/durable-agent.mdx +7 -45
  25. package/docs/api-reference/workflow-api/get-hook-by-token.mdx +7 -0
  26. package/docs/api-reference/workflow-api/get-run.mdx +6 -0
  27. package/docs/api-reference/workflow-api/index.mdx +6 -8
  28. package/docs/api-reference/workflow-api/resume-hook.mdx +57 -0
  29. package/docs/api-reference/workflow-api/start.mdx +13 -5
  30. package/docs/api-reference/workflow-astro/index.mdx +18 -0
  31. package/docs/api-reference/workflow-astro/meta.json +4 -0
  32. package/docs/api-reference/workflow-astro/workflow.mdx +45 -0
  33. package/docs/api-reference/workflow-errors/hook-conflict-error.mdx +60 -0
  34. package/docs/api-reference/workflow-errors/index.mdx +85 -0
  35. package/docs/api-reference/workflow-errors/meta.json +5 -0
  36. package/docs/api-reference/workflow-errors/run-not-supported-error.mdx +58 -0
  37. package/docs/api-reference/workflow-errors/workflow-error.mdx +52 -0
  38. package/docs/api-reference/workflow-errors/workflow-run-failed-error.mdx +16 -6
  39. package/docs/api-reference/workflow-errors/workflow-run-not-completed-error.mdx +58 -0
  40. package/docs/api-reference/workflow-errors/workflow-runtime-error.mdx +58 -0
  41. package/docs/api-reference/workflow-nest/configure-workflow-controller.mdx +33 -0
  42. package/docs/api-reference/workflow-nest/index.mdx +31 -0
  43. package/docs/api-reference/workflow-nest/meta.json +9 -0
  44. package/docs/api-reference/workflow-nest/nest-local-builder.mdx +64 -0
  45. package/docs/api-reference/workflow-nest/workflow-controller.mdx +40 -0
  46. package/docs/api-reference/workflow-nest/workflow-module.mdx +74 -0
  47. package/docs/api-reference/workflow-next/with-workflow.mdx +56 -2
  48. package/docs/api-reference/workflow-nitro/index.mdx +59 -0
  49. package/docs/api-reference/workflow-nuxt/index.mdx +47 -0
  50. package/docs/api-reference/workflow-observability/hydrate-data.mdx +35 -0
  51. package/docs/api-reference/workflow-observability/hydrate-resource-io.mdx +62 -0
  52. package/docs/api-reference/workflow-observability/index.mdx +64 -0
  53. package/docs/api-reference/workflow-observability/meta.json +11 -0
  54. package/docs/api-reference/workflow-observability/observability-revivers.mdx +50 -0
  55. package/docs/api-reference/workflow-observability/parse-class-name.mdx +41 -0
  56. package/docs/api-reference/workflow-observability/parse-step-name.mdx +40 -0
  57. package/docs/api-reference/workflow-observability/parse-workflow-name.mdx +55 -0
  58. package/docs/api-reference/workflow-runtime/create-world.mdx +39 -0
  59. package/docs/api-reference/workflow-runtime/get-world-handlers.mdx +44 -0
  60. package/docs/api-reference/{workflow-api → workflow-runtime}/get-world.mdx +7 -10
  61. package/docs/api-reference/workflow-runtime/health-check.mdx +50 -0
  62. package/docs/api-reference/workflow-runtime/index.mdx +43 -0
  63. package/docs/api-reference/workflow-runtime/meta.json +12 -0
  64. package/docs/api-reference/workflow-runtime/set-world.mdx +49 -0
  65. package/docs/api-reference/workflow-runtime/workflow-entrypoint.mdx +42 -0
  66. package/docs/api-reference/{workflow-api → workflow-runtime}/world/index.mdx +5 -8
  67. package/docs/api-reference/workflow-runtime/world/meta.json +4 -0
  68. package/docs/api-reference/{workflow-api → workflow-runtime}/world/queue.mdx +2 -2
  69. package/docs/api-reference/{workflow-api → workflow-runtime}/world/storage.mdx +11 -4
  70. package/docs/api-reference/{workflow-api → workflow-runtime}/world/streams.mdx +2 -2
  71. package/docs/api-reference/workflow-serde/index.mdx +0 -1
  72. package/docs/api-reference/workflow-serde/workflow-deserialize.mdx +1 -2
  73. package/docs/api-reference/workflow-serde/workflow-serialize.mdx +1 -2
  74. package/docs/api-reference/workflow-sveltekit/index.mdx +18 -0
  75. package/docs/api-reference/workflow-sveltekit/meta.json +4 -0
  76. package/docs/api-reference/workflow-sveltekit/workflow-plugin.mdx +42 -0
  77. package/docs/api-reference/workflow-vite/index.mdx +18 -0
  78. package/docs/api-reference/workflow-vite/meta.json +4 -0
  79. package/docs/api-reference/workflow-vite/workflow.mdx +48 -0
  80. package/docs/changelog/attributes-mvp.mdx +380 -0
  81. package/docs/changelog/eager-processing.mdx +269 -0
  82. package/docs/changelog/index.mdx +2 -1
  83. package/docs/changelog/lazy-event-creation.md +127 -0
  84. package/docs/changelog/meta.json +7 -1
  85. package/docs/changelog/resilient-start.mdx +31 -283
  86. package/docs/changelog/turbo-mode.md +87 -0
  87. package/docs/cookbook/advanced/child-workflows.mdx +315 -0
  88. package/docs/cookbook/advanced/meta.json +2 -3
  89. package/docs/cookbook/advanced/publishing-libraries.mdx +87 -29
  90. package/docs/cookbook/advanced/serializable-steps.mdx +17 -5
  91. package/docs/cookbook/advanced/upgrading-workflows.mdx +195 -0
  92. package/docs/cookbook/agent-patterns/agent-cancellation.mdx +156 -0
  93. package/docs/cookbook/agent-patterns/durable-agent.mdx +11 -184
  94. package/docs/cookbook/agent-patterns/human-in-the-loop.mdx +150 -173
  95. package/docs/cookbook/agent-patterns/meta.json +1 -7
  96. package/docs/cookbook/common-patterns/batching.mdx +44 -118
  97. package/docs/cookbook/common-patterns/idempotency.mdx +36 -52
  98. package/docs/cookbook/common-patterns/meta.json +4 -4
  99. package/docs/cookbook/common-patterns/rate-limiting.mdx +1 -1
  100. package/docs/cookbook/common-patterns/saga.mdx +128 -33
  101. package/docs/cookbook/common-patterns/scheduling.mdx +77 -193
  102. package/docs/cookbook/common-patterns/sequential-and-parallel.mdx +155 -0
  103. package/docs/cookbook/common-patterns/timeouts.mdx +100 -0
  104. package/docs/cookbook/common-patterns/workflow-composition.mdx +117 -0
  105. package/docs/cookbook/index.mdx +14 -17
  106. package/docs/cookbook/integrations/ai-sdk.mdx +330 -142
  107. package/docs/cookbook/integrations/chat-sdk.mdx +264 -151
  108. package/docs/cookbook/integrations/sandbox.mdx +482 -81
  109. package/docs/cookbook/meta.json +1 -1
  110. package/docs/deploying/building-a-world.mdx +1 -1
  111. package/docs/deploying/world/postgres-world.mdx +5 -3
  112. package/docs/deploying/world/vercel-world.mdx +2 -0
  113. package/docs/errors/abort-signal-timeout-in-workflow.mdx +80 -0
  114. package/docs/errors/corrupted-event-log.mdx +5 -5
  115. package/docs/errors/hook-conflict.mdx +56 -4
  116. package/docs/errors/index.mdx +9 -0
  117. package/docs/errors/replay-divergence.mdx +27 -0
  118. package/docs/errors/runtime-decryption-failed.mdx +77 -0
  119. package/docs/errors/step-executed-multiple-times.mdx +23 -0
  120. package/docs/errors/step-not-registered.mdx +1 -1
  121. package/docs/foundations/cancellation.mdx +459 -0
  122. package/docs/foundations/errors-and-retries.mdx +7 -3
  123. package/docs/foundations/hooks.mdx +29 -0
  124. package/docs/foundations/idempotency.mdx +236 -11
  125. package/docs/foundations/index.mdx +3 -3
  126. package/docs/foundations/meta.json +3 -2
  127. package/docs/foundations/serialization.mdx +78 -42
  128. package/docs/foundations/starting-workflows.mdx +6 -2
  129. package/docs/foundations/streaming.mdx +14 -23
  130. package/docs/foundations/versioning.mdx +263 -0
  131. package/docs/getting-started/astro.mdx +6 -0
  132. package/docs/getting-started/index.mdx +6 -7
  133. package/docs/getting-started/meta.json +1 -0
  134. package/docs/getting-started/nestjs.mdx +9 -0
  135. package/docs/getting-started/next.mdx +5 -3
  136. package/docs/getting-started/nitro.mdx +22 -0
  137. package/docs/getting-started/sveltekit.mdx +6 -0
  138. package/docs/getting-started/tanstack-start.mdx +241 -0
  139. package/docs/how-it-works/cancellation.mdx +287 -0
  140. package/docs/how-it-works/code-transform.mdx +2 -2
  141. package/docs/how-it-works/encryption.mdx +2 -2
  142. package/docs/how-it-works/event-sourcing.mdx +2 -2
  143. package/docs/how-it-works/meta.json +2 -1
  144. package/docs/internal/index.mdx +21 -0
  145. package/docs/internal/meta.json +10 -0
  146. package/docs/internal/nitro-native-build.mdx +38 -0
  147. package/docs/internal/nitro-web-ui.mdx +24 -0
  148. package/docs/internal/serializable-abort-controller.mdx +148 -0
  149. package/docs/migration-guides/migrating-from-aws-step-functions.mdx +63 -16
  150. package/docs/migration-guides/migrating-from-inngest.mdx +44 -22
  151. package/docs/migration-guides/migrating-from-temporal.mdx +43 -14
  152. package/docs/migration-guides/migrating-from-trigger-dev.mdx +59 -27
  153. package/docs/observability/attributes.mdx +87 -0
  154. package/docs/observability/index.mdx +25 -1
  155. package/docs/observability/meta.json +1 -1
  156. package/docs/observability/tracing.mdx +106 -0
  157. package/docs/testing/index.mdx +2 -2
  158. package/package.json +14 -13
  159. package/docs/api-reference/workflow-api/world/meta.json +0 -4
  160. package/docs/api-reference/workflow-api/world/observability.mdx +0 -164
  161. package/docs/cookbook/advanced/custom-serialization.mdx +0 -168
  162. package/docs/cookbook/advanced/durable-objects.mdx +0 -148
  163. package/docs/cookbook/advanced/isomorphic-packages.mdx +0 -145
  164. package/docs/cookbook/agent-patterns/stop-workflow.mdx +0 -216
  165. package/docs/cookbook/agent-patterns/tool-orchestration.mdx +0 -255
  166. package/docs/cookbook/agent-patterns/tool-streaming.mdx +0 -181
  167. package/docs/cookbook/common-patterns/child-workflows.mdx +0 -372
  168. package/docs/cookbook/common-patterns/content-router.mdx +0 -207
  169. package/docs/cookbook/common-patterns/fan-out.mdx +0 -208
  170. package/docs/foundations/common-patterns.mdx +0 -265
@@ -0,0 +1,58 @@
1
+ ---
2
+ title: RunNotSupportedError
3
+ description: Thrown when a workflow run requires a newer workflow spec version than the installed SDK supports.
4
+ type: reference
5
+ summary: Catch RunNotSupportedError when stored run data requires a newer workflow package version.
6
+ related:
7
+ - /docs/foundations/versioning
8
+ ---
9
+
10
+ `RunNotSupportedError` is thrown when reading a workflow run whose data was written with a newer workflow spec version than the running SDK supports. This typically means the run was created by a newer version of the `workflow` package — upgrade the package to process it.
11
+
12
+ ```typescript lineNumbers
13
+ import { RunNotSupportedError } from "workflow/errors"
14
+ declare function readRun(runId: string): Promise<unknown>; // @setup
15
+ declare const runId: string; // @setup
16
+
17
+ try {
18
+ await readRun(runId);
19
+ } catch (error) {
20
+ if (RunNotSupportedError.is(error)) { // [!code highlight]
21
+ console.error(
22
+ `Run requires spec v${error.runSpecVersion}, world supports v${error.worldSpecVersion}`
23
+ );
24
+ }
25
+ }
26
+ ```
27
+
28
+ ## API Signature
29
+
30
+ ### Properties
31
+
32
+ <TSDoc
33
+ definition={`
34
+ interface RunNotSupportedError {
35
+ /** The spec version the run's stored data requires. */
36
+ runSpecVersion: number;
37
+ /** The spec version the current World supports. */
38
+ worldSpecVersion: number;
39
+ /** The error message. */
40
+ message: string;
41
+ }
42
+ export default RunNotSupportedError;`}
43
+ />
44
+
45
+ ### Static Methods
46
+
47
+ #### `RunNotSupportedError.is(value)`
48
+
49
+ Type-safe check for `RunNotSupportedError` instances. Preferred over `instanceof` because it works across module boundaries and VM contexts.
50
+
51
+ ```typescript
52
+ import { RunNotSupportedError } from "workflow/errors"
53
+ declare const error: unknown; // @setup
54
+
55
+ if (RunNotSupportedError.is(error)) {
56
+ // error is typed as RunNotSupportedError
57
+ }
58
+ ```
@@ -0,0 +1,52 @@
1
+ ---
2
+ title: WorkflowError
3
+ description: Base class for all workflow error types.
4
+ type: reference
5
+ summary: All errors thrown by the Workflow SDK extend WorkflowError.
6
+ related:
7
+ - /docs/foundations/errors-and-retries
8
+ ---
9
+
10
+ `WorkflowError` is the base class that all Workflow SDK error types extend, such as [`WorkflowRunFailedError`](/docs/api-reference/workflow-errors/workflow-run-failed-error) and [`HookNotFoundError`](/docs/api-reference/workflow-errors/hook-not-found-error). It extends `Error` with an optional `cause` and, for some subclasses, a link to the relevant error documentation appended to the message.
11
+
12
+ ```typescript lineNumbers
13
+ import { WorkflowError } from "workflow/errors"
14
+
15
+ const error = new WorkflowError("something went wrong", {
16
+ cause: new Error("underlying cause"),
17
+ });
18
+ ```
19
+
20
+ ## API Signature
21
+
22
+ ### Properties
23
+
24
+ <TSDoc
25
+ definition={`
26
+ interface WorkflowError {
27
+ /** The error message. */
28
+ message: string;
29
+ /** The underlying cause, when provided. */
30
+ cause?: unknown;
31
+ }
32
+ export default WorkflowError;`}
33
+ />
34
+
35
+ ### Static Methods
36
+
37
+ #### `WorkflowError.is(value)`
38
+
39
+ Type-safe check for `WorkflowError` instances. Preferred over `instanceof` because it works across module boundaries and VM contexts.
40
+
41
+ <Callout type="warn">
42
+ `WorkflowError.is()` matches only direct `WorkflowError` instances — not subclasses, which override the error name it checks. To handle a specific error type, use that subclass's own `.is()` method (e.g. `WorkflowRunFailedError.is(error)`).
43
+ </Callout>
44
+
45
+ ```typescript
46
+ import { WorkflowError } from "workflow/errors"
47
+ declare const error: unknown; // @setup
48
+
49
+ if (WorkflowError.is(error)) {
50
+ // error is typed as WorkflowError
51
+ }
52
+ ```
@@ -11,7 +11,7 @@ related:
11
11
 
12
12
  `WorkflowRunFailedError` is thrown when awaiting `run.returnValue` on a workflow run whose status is `'failed'`. This indicates that the workflow encountered a fatal error during execution and cannot produce a return value.
13
13
 
14
- The `cause` property contains the underlying error with its message, stack trace, and optional error code.
14
+ The `cause` property holds the original thrown value, hydrated through the workflow serialization pipeline so its type identity (e.g. `FatalError`, `RetryableError`, custom `Error` subclasses), `cause` chain, and custom properties are preserved. Because any JavaScript value can be thrown, `cause` is typed as `unknown` — narrow it with `instanceof Error` (or a more specific check) before accessing fields like `message`. The high-level error classification is exposed as the top-level `errorCode` property.
15
15
 
16
16
  ```typescript lineNumbers
17
17
  import { WorkflowRunFailedError } from "workflow/errors"
@@ -21,9 +21,11 @@ try {
21
21
  const result = await run.returnValue;
22
22
  } catch (error) {
23
23
  if (WorkflowRunFailedError.is(error)) { // [!code highlight]
24
- console.error(`Run ${error.runId} failed:`, error.cause.message);
25
- if (error.cause.code) {
26
- console.error("Error code:", error.cause.code);
24
+ if (error.cause instanceof Error) {
25
+ console.error(`Run ${error.runId} failed:`, error.cause.message);
26
+ }
27
+ if (error.errorCode) {
28
+ console.error("Error code:", error.errorCode);
27
29
  }
28
30
  }
29
31
  }
@@ -38,8 +40,16 @@ definition={`
38
40
  interface WorkflowRunFailedError {
39
41
  /** The ID of the failed run. */
40
42
  runId: string;
41
- /** The underlying error that caused the failure. */
42
- cause: Error & { code?: string };
43
+ /**
44
+ * The original thrown value from the failed workflow run, hydrated through
45
+ * the workflow serialization pipeline. Preserves the original type identity
46
+ * (Error subclasses, FatalError, custom classes with WORKFLOW_SERIALIZE,
47
+ * etc.) and custom properties. Typed as \`unknown\` because any value can
48
+ * be thrown — narrow with \`instanceof Error\` before accessing fields.
49
+ */
50
+ cause: unknown;
51
+ /** The high-level error category (e.g. \`USER_ERROR\`, \`RUNTIME_ERROR\`). */
52
+ errorCode?: string;
43
53
  /** The error message. */
44
54
  message: string;
45
55
  }
@@ -0,0 +1,58 @@
1
+ ---
2
+ title: WorkflowRunNotCompletedError
3
+ description: Thrown when requesting the result of a workflow run that has not completed yet.
4
+ type: reference
5
+ summary: Catch WorkflowRunNotCompletedError when reading the return value of a run that is still pending or running.
6
+ related:
7
+ - /docs/api-reference/workflow-api/get-run
8
+ ---
9
+
10
+ `WorkflowRunNotCompletedError` is thrown when requesting the result of a workflow run that has not completed yet. The run's current status (for example `pending` or `running`) is available on the error.
11
+
12
+ [`run.returnValue()`](/docs/api-reference/workflow-api/get-run) handles this error internally — it polls until the run completes — so you will mainly encounter it when building custom polling logic on lower-level APIs.
13
+
14
+ ```typescript lineNumbers
15
+ import { WorkflowRunNotCompletedError } from "workflow/errors"
16
+ declare function readRunResult(runId: string): Promise<unknown>; // @setup
17
+ declare const runId: string; // @setup
18
+
19
+ try {
20
+ const result = await readRunResult(runId);
21
+ } catch (error) {
22
+ if (WorkflowRunNotCompletedError.is(error)) { // [!code highlight]
23
+ console.log(`Run ${error.runId} is still ${error.status}`);
24
+ }
25
+ }
26
+ ```
27
+
28
+ ## API Signature
29
+
30
+ ### Properties
31
+
32
+ <TSDoc
33
+ definition={`
34
+ interface WorkflowRunNotCompletedError {
35
+ /** The workflow run ID. */
36
+ runId: string;
37
+ /** The run's status at the time of the error (e.g. "pending", "running"). */
38
+ status: string;
39
+ /** The error message. */
40
+ message: string;
41
+ }
42
+ export default WorkflowRunNotCompletedError;`}
43
+ />
44
+
45
+ ### Static Methods
46
+
47
+ #### `WorkflowRunNotCompletedError.is(value)`
48
+
49
+ Type-safe check for `WorkflowRunNotCompletedError` instances. Preferred over `instanceof` because it works across module boundaries and VM contexts.
50
+
51
+ ```typescript
52
+ import { WorkflowRunNotCompletedError } from "workflow/errors"
53
+ declare const error: unknown; // @setup
54
+
55
+ if (WorkflowRunNotCompletedError.is(error)) {
56
+ // error is typed as WorkflowRunNotCompletedError
57
+ }
58
+ ```
@@ -0,0 +1,58 @@
1
+ ---
2
+ title: WorkflowRuntimeError
3
+ description: Thrown when the workflow runtime encounters an execution error, such as serialization failures or timeouts.
4
+ type: reference
5
+ summary: Catch WorkflowRuntimeError for runtime-level failures like unserializable values or workflow timeouts.
6
+ related:
7
+ - /docs/foundations/serialization
8
+ - /docs/foundations/errors-and-retries
9
+ ---
10
+
11
+ `WorkflowRuntimeError` is thrown when the workflow runtime encounters an error executing a workflow. Common causes include:
12
+
13
+ - Values crossing the workflow/step boundary that cannot be serialized
14
+ - Workflow execution timeouts
15
+ - Invalid runtime state, such as misconfigured streams
16
+
17
+ ```typescript lineNumbers
18
+ import { WorkflowRuntimeError } from "workflow/errors"
19
+ declare function runWorkflowOperation(): Promise<void>; // @setup
20
+
21
+ try {
22
+ await runWorkflowOperation();
23
+ } catch (error) {
24
+ if (WorkflowRuntimeError.is(error)) { // [!code highlight]
25
+ console.error("Workflow runtime error:", error.message);
26
+ }
27
+ }
28
+ ```
29
+
30
+ ## API Signature
31
+
32
+ ### Properties
33
+
34
+ <TSDoc
35
+ definition={`
36
+ interface WorkflowRuntimeError {
37
+ /** The error message. */
38
+ message: string;
39
+ /** The underlying cause, when provided. */
40
+ cause?: unknown;
41
+ }
42
+ export default WorkflowRuntimeError;`}
43
+ />
44
+
45
+ ### Static Methods
46
+
47
+ #### `WorkflowRuntimeError.is(value)`
48
+
49
+ Type-safe check for `WorkflowRuntimeError` instances. Preferred over `instanceof` because it works across module boundaries and VM contexts.
50
+
51
+ ```typescript
52
+ import { WorkflowRuntimeError } from "workflow/errors"
53
+ declare const error: unknown; // @setup
54
+
55
+ if (WorkflowRuntimeError.is(error)) {
56
+ // error is typed as WorkflowRuntimeError
57
+ }
58
+ ```
@@ -0,0 +1,33 @@
1
+ ---
2
+ title: configureWorkflowController
3
+ description: Point WorkflowController at the generated workflow bundles.
4
+ type: reference
5
+ summary: Configure the directory WorkflowController loads workflow bundles from.
6
+ prerequisites:
7
+ - /docs/getting-started/nestjs
8
+ ---
9
+
10
+ Configures the output directory that [`WorkflowController`](/docs/api-reference/workflow-nest/workflow-controller) loads the generated workflow bundles (`steps.mjs`, `workflows.mjs`, `webhook.mjs`, `manifest.json`) from.
11
+
12
+ [`WorkflowModule.forRoot()`](/docs/api-reference/workflow-nest/workflow-module) calls this for you with its resolved `outDir` — call it yourself only when registering `WorkflowController` manually. The controller's route handlers throw if no directory has been configured.
13
+
14
+ ## Usage
15
+
16
+ ```typescript title="src/app.module.ts" lineNumbers
17
+ import { join } from "node:path";
18
+ import { configureWorkflowController } from "workflow/nest"; // [!code highlight]
19
+
20
+ configureWorkflowController(join(process.cwd(), ".nestjs/workflow")); // [!code highlight]
21
+ ```
22
+
23
+ ## API Signature
24
+
25
+ ### Parameters
26
+
27
+ | Parameter | Type | Description |
28
+ | --- | --- | --- |
29
+ | `outDir` | `string` | Directory containing the generated workflow bundles. Should match the `outDir` used by the builder (default: `.nestjs/workflow` in the working directory). |
30
+
31
+ ### Returns
32
+
33
+ Returns `void`.
@@ -0,0 +1,31 @@
1
+ ---
2
+ title: "workflow/nest"
3
+ description: NestJS integration for workflow bundling and HTTP routing.
4
+ type: overview
5
+ summary: Explore the NestJS integration for workflow bundle building and runtime routing.
6
+ related:
7
+ - /docs/getting-started/nestjs
8
+ ---
9
+
10
+ NestJS integration for Workflow SDK. The `WorkflowModule` builds the workflow bundles on application startup and registers the controller that serves the workflow runtime routes.
11
+
12
+ <Callout>
13
+ NestJS integration is experimental and not yet supported for deployment to Vercel. The same exports are also available from the `@workflow/nest` package.
14
+ </Callout>
15
+
16
+ ## Exports
17
+
18
+ <Cards>
19
+ <Card title="WorkflowModule" href="/docs/api-reference/workflow-nest/workflow-module">
20
+ NestJS module that builds workflow bundles on startup and registers the workflow controller
21
+ </Card>
22
+ <Card title="NestLocalBuilder" href="/docs/api-reference/workflow-nest/nest-local-builder">
23
+ Builder that compiles workflow files into step, workflow, and webhook bundles
24
+ </Card>
25
+ <Card title="WorkflowController" href="/docs/api-reference/workflow-nest/workflow-controller">
26
+ Controller that serves the workflow runtime routes under `.well-known/workflow/v1`
27
+ </Card>
28
+ <Card title="configureWorkflowController()" href="/docs/api-reference/workflow-nest/configure-workflow-controller">
29
+ Points `WorkflowController` at the directory containing the generated workflow bundles
30
+ </Card>
31
+ </Cards>
@@ -0,0 +1,9 @@
1
+ {
2
+ "title": "workflow/nest",
3
+ "pages": [
4
+ "workflow-module",
5
+ "nest-local-builder",
6
+ "workflow-controller",
7
+ "configure-workflow-controller"
8
+ ]
9
+ }
@@ -0,0 +1,64 @@
1
+ ---
2
+ title: NestLocalBuilder
3
+ description: Builder that compiles workflow files into bundles for NestJS apps.
4
+ type: reference
5
+ summary: Use NestLocalBuilder to build workflow bundles programmatically in a NestJS project.
6
+ prerequisites:
7
+ - /docs/getting-started/nestjs
8
+ ---
9
+
10
+ Builder that scans a NestJS project for workflow files and compiles them into the step, workflow, and webhook bundles plus a manifest. [`WorkflowModule.forRoot()`](/docs/api-reference/workflow-nest/workflow-module) creates and runs one automatically on startup — instantiate it yourself only when you need to build bundles outside the module lifecycle (e.g. a custom build script for production with `skipBuild`).
11
+
12
+ ## Usage
13
+
14
+ ```typescript title="scripts/build-workflows.ts" lineNumbers
15
+ import { NestLocalBuilder } from "workflow/nest"; // [!code highlight]
16
+
17
+ const builder = new NestLocalBuilder({
18
+ dirs: ["src"],
19
+ });
20
+
21
+ await builder.build(); // [!code highlight]
22
+
23
+ console.log(`Workflow bundles written to ${builder.outDir}`);
24
+ ```
25
+
26
+ ## API Signature
27
+
28
+ ### Constructor
29
+
30
+ `new NestLocalBuilder(options?)` creates a builder for the given options.
31
+
32
+ ### Parameters
33
+
34
+ | Parameter | Type | Description |
35
+ | --- | --- | --- |
36
+ | `options` | `NestBuilderOptions` | Optional. Configures the workflow build. |
37
+
38
+ #### NestBuilderOptions
39
+
40
+ | Option | Type | Default | Description |
41
+ | --- | --- | --- | --- |
42
+ | `workingDir` | `string` | `process.cwd()` | Working directory for the NestJS application. |
43
+ | `dirs` | `string[]` | `['src']` | Directories to scan for workflow files. |
44
+ | `outDir` | `string` | `'.nestjs/workflow'` (relative to `workingDir`) | Output directory for generated workflow bundles. |
45
+ | `watch` | `boolean` | `false` | Enable watch mode for development. |
46
+ | `moduleType` | `'es6' \| 'commonjs'` | `'es6'` | SWC module compilation type. When `'commonjs'`, the builder rewrites externalized imports in the steps bundle to use `require()` via `createRequire`, avoiding ESM/CJS named-export interop issues with SWC's output. |
47
+ | `distDir` | `string` | `'dist'` | Directory where NestJS compiles `.ts` source files to `.js` (relative to `workingDir`). Used when `moduleType` is `'commonjs'` to resolve compiled file paths. Should match the `outDir` in your `tsconfig.json`. |
48
+ | `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. Can also be set via the `WORKFLOW_SOURCEMAP` environment variable. |
49
+
50
+ ### Methods
51
+
52
+ #### `build()`
53
+
54
+ Builds the workflow bundles. Writes `steps.mjs`, `workflows.mjs`, `webhook.mjs`, and `manifest.json` to the output directory (plus a `.gitignore` covering the generated files when not deploying to Vercel). Returns `Promise<void>`.
55
+
56
+ ### Properties
57
+
58
+ #### `outDir`
59
+
60
+ Read-only getter that returns the output directory for generated workflow bundles — the `outDir` option as passed, or the default `.nestjs/workflow` resolved against `workingDir`.
61
+
62
+ ### Returns
63
+
64
+ The constructor returns a `NestLocalBuilder` instance.
@@ -0,0 +1,40 @@
1
+ ---
2
+ title: WorkflowController
3
+ description: NestJS controller that serves the workflow runtime routes.
4
+ type: reference
5
+ summary: WorkflowController handles the well-known workflow endpoints in a NestJS app.
6
+ prerequisites:
7
+ - /docs/getting-started/nestjs
8
+ ---
9
+
10
+ NestJS controller that handles the well-known workflow endpoints under `.well-known/workflow/v1`. It dynamically imports the generated workflow bundles and converts between Express/Fastify requests and the Web API `Request`/`Response` objects the workflow runtime expects. Both the Express and Fastify HTTP adapters are supported.
11
+
12
+ [`WorkflowModule.forRoot()`](/docs/api-reference/workflow-nest/workflow-module) registers this controller automatically — you only register it yourself if you are not using `WorkflowModule`.
13
+
14
+ ## Usage
15
+
16
+ When registering the controller manually, call [`configureWorkflowController`](/docs/api-reference/workflow-nest/configure-workflow-controller) first so it can locate the generated bundles; its route handlers throw otherwise.
17
+
18
+ ```typescript title="src/app.module.ts" lineNumbers
19
+ import { join } from "node:path";
20
+ import { Module } from "@nestjs/common";
21
+ import {
22
+ configureWorkflowController, // [!code highlight]
23
+ WorkflowController, // [!code highlight]
24
+ } from "workflow/nest";
25
+
26
+ configureWorkflowController(join(process.cwd(), ".nestjs/workflow")); // [!code highlight]
27
+
28
+ @Module({
29
+ controllers: [WorkflowController], // [!code highlight]
30
+ })
31
+ export class AppModule {}
32
+ ```
33
+
34
+ ## Routes
35
+
36
+ | Route | Method | Description |
37
+ | --- | --- | --- |
38
+ | `/.well-known/workflow/v1/flow` | `POST` | Executes workflow and step work items via the combined handler in `workflows.mjs` (step registrations are imported from `steps.mjs` first). |
39
+ | `/.well-known/workflow/v1/webhook/:token` | Any | Forwards webhook requests to the handler in `webhook.mjs`. |
40
+ | `/.well-known/workflow/v1/manifest.json` | `GET` | Serves the workflow manifest. Responds with `404` unless the `WORKFLOW_PUBLIC_MANIFEST=1` environment variable is set. |
@@ -0,0 +1,74 @@
1
+ ---
2
+ title: WorkflowModule
3
+ description: NestJS module that builds workflow bundles and registers the workflow controller.
4
+ type: reference
5
+ summary: Import WorkflowModule.forRoot() in your AppModule to enable workflows in a NestJS app.
6
+ prerequisites:
7
+ - /docs/getting-started/nestjs
8
+ ---
9
+
10
+ NestJS module that provides workflow functionality. It builds the workflow bundles on module initialization (`onModuleInit`) and registers the [`WorkflowController`](/docs/api-reference/workflow-nest/workflow-controller) that serves the workflow runtime routes.
11
+
12
+ ## Usage
13
+
14
+ Add `WorkflowModule.forRoot()` to the `imports` array of your root module.
15
+
16
+ ```typescript title="src/app.module.ts" lineNumbers
17
+ import { Module } from "@nestjs/common";
18
+ import { WorkflowModule } from "workflow/nest"; // [!code highlight]
19
+
20
+ @Module({
21
+ imports: [WorkflowModule.forRoot()], // [!code highlight]
22
+ })
23
+ export class AppModule {}
24
+ ```
25
+
26
+ If your NestJS project compiles to CommonJS via SWC, pass `moduleType` and `distDir` so the builder can rewrite imports in the generated bundles:
27
+
28
+ ```typescript title="src/app.module.ts" lineNumbers
29
+ import { Module } from "@nestjs/common";
30
+ import { WorkflowModule } from "workflow/nest";
31
+
32
+ @Module({
33
+ imports: [
34
+ WorkflowModule.forRoot({
35
+ moduleType: "commonjs", // [!code highlight]
36
+ distDir: "dist", // [!code highlight]
37
+ }),
38
+ ],
39
+ })
40
+ export class AppModule {}
41
+ ```
42
+
43
+ ## API Signature
44
+
45
+ ### Static Methods
46
+
47
+ #### `forRoot(options?)`
48
+
49
+ Configures the module and returns a NestJS `DynamicModule` registered as `global`. It calls [`configureWorkflowController`](/docs/api-reference/workflow-nest/configure-workflow-controller) with the resolved output directory, and (unless `skipBuild` is set) creates a [`NestLocalBuilder`](/docs/api-reference/workflow-nest/nest-local-builder) that builds the workflow bundles when the module initializes.
50
+
51
+ ### Parameters
52
+
53
+ | Parameter | Type | Description |
54
+ | --- | --- | --- |
55
+ | `options` | `WorkflowModuleOptions` | Optional. Configures the workflow build. |
56
+
57
+ #### WorkflowModuleOptions
58
+
59
+ Extends [`NestBuilderOptions`](/docs/api-reference/workflow-nest/nest-local-builder#nestbuilderoptions) — all builder options are accepted, plus `skipBuild`:
60
+
61
+ | Option | Type | Default | Description |
62
+ | --- | --- | --- | --- |
63
+ | `skipBuild` | `boolean` | `false` | Skip building workflow bundles on startup. Useful in production when the bundles are pre-built. |
64
+ | `workingDir` | `string` | `process.cwd()` | Working directory for the NestJS application. |
65
+ | `dirs` | `string[]` | `['src']` | Directories to scan for workflow files. |
66
+ | `outDir` | `string` | `'.nestjs/workflow'` (relative to `workingDir`) | Output directory for generated workflow bundles. |
67
+ | `watch` | `boolean` | `false` | Enable watch mode for development. |
68
+ | `moduleType` | `'es6' \| 'commonjs'` | `'es6'` | SWC module compilation type. Set to `'commonjs'` if your NestJS project compiles to CJS via SWC. |
69
+ | `distDir` | `string` | `'dist'` | Directory where NestJS compiles `.ts` source files to `.js` (relative to `workingDir`). Used when `moduleType` is `'commonjs'`. Should match the `outDir` in your `tsconfig.json`. |
70
+ | `sourcemap` | `boolean \| 'inline' \| 'linked' \| 'external' \| 'both'` | `'inline'` (dev) / `false` (prod) | Controls source maps on generated workflow bundles. Defaults to `'inline'` in development and `false` in production. Can also be set via the `WORKFLOW_SOURCEMAP` environment variable. |
71
+
72
+ ### Returns
73
+
74
+ `forRoot()` returns a `DynamicModule` to include in the `imports` array of your root module.
@@ -27,6 +27,39 @@ const workflowConfig = {}
27
27
  export default withWorkflow(nextConfig, workflowConfig); // [!code highlight]
28
28
  ```
29
29
 
30
+ <Callout type="warn">
31
+ If a package in `serverExternalPackages` contains workflow code (`"use step"`,
32
+ `"use workflow"`, or serialization classes), `withWorkflow()` automatically
33
+ removes it from `serverExternalPackages` for the current build and prints a
34
+ warning. Workflow still compiles the package so its directives are transformed.
35
+ Remove that package from `serverExternalPackages` in your
36
+ `next.config` to silence the warning.
37
+ </Callout>
38
+
39
+ ### Workflow Discovery in Next.js
40
+
41
+ `withWorkflow()` discovers workflows by scanning your Next.js entrypoints — App
42
+ Router `route`, `page`, and `layout` files (under `app/` or `src/app/`) and any
43
+ file under `pages/` or `src/pages/` — for `start()` calls imported from
44
+ `workflow/api`. The workflow and step files themselves can live anywhere (for
45
+ example `src/workflows/`); they are discovered transitively through imports, as
46
+ long as a `start()` call in an entrypoint statically reaches them.
47
+
48
+ <Callout type="info">
49
+ Call `start()` from server-side entrypoints, including Route Handlers and Server
50
+ Actions. Don't call workflow functions directly — that bypasses the workflow
51
+ runtime.
52
+ </Callout>
53
+
54
+ ### Next.js Server Actions and `"use server"`
55
+
56
+ Don't put a top-level `"use server"` directive in modules imported by workflow
57
+ or step functions. Workflow transformation wraps imported modules in synchronous
58
+ initializers, and Next.js rejects a `"use server"` directive inside that wrapper
59
+ with errors like `Server Actions must be async functions`. Keep `"use server"`
60
+ on the files that define your Server Actions, and move shared logic into
61
+ separate modules that don't carry the directive.
62
+
30
63
  ### Monorepos and Workspace Imports
31
64
 
32
65
  By default, Next.js detects the correct workspace root automatically. If your Next.js app lives in a subdirectory such as `apps/web` and workspace resolution is not working correctly, you can set `outputFileTracingRoot` as a workaround:
@@ -59,18 +92,38 @@ const nextConfig: NextConfig = {};
59
92
 
60
93
  export default withWorkflow(nextConfig, {
61
94
  workflows: {
62
- lazyDiscovery: true,
63
95
  local: {
64
96
  port: 4000,
65
97
  },
98
+ sourcemap: false,
66
99
  },
67
100
  });
68
101
  ```
69
102
 
70
103
  | Option | Type | Default | Description |
71
104
  | --- | --- | --- | --- |
72
- | `workflows.lazyDiscovery` | `boolean` | `false` | When `true`, defers workflow discovery until files are requested instead of scanning eagerly at startup. Useful for large projects where startup time matters. |
73
105
  | `workflows.local.port` | `number` | — | Overrides the `PORT` environment variable for local development. Has no effect when deployed to Vercel. |
106
+ | `workflows.sourcemap` | `boolean \| 'inline' \| 'linked' \| 'external' \| 'both'` | `'inline'` (dev) / `false` (prod) | Controls source maps on generated workflow bundles. See [Source maps](#source-maps) below. |
107
+
108
+ ### Source maps
109
+
110
+ The step bundle and intermediate workflow bundle default to `'inline'` source maps **in development** — so stack traces from step errors and workflow VM errors point at your source files — and to **`false` in production**, so function bundles stay small. The `sourcemap` option lets you change that:
111
+
112
+ | Value | Behavior |
113
+ | --- | --- |
114
+ | `true` / `'inline'` | Base64-encode the source map and append it to the bundle (default in development). |
115
+ | `'linked'` | Write a separate `.map` file and add a `sourceMappingURL` comment. |
116
+ | `'external'` | Write a separate `.map` file without the comment. |
117
+ | `'both'` | Emit both inline and external source maps. |
118
+ | `false` | Omit source maps entirely. |
119
+
120
+ In production, source maps are already off by default. Setting `sourcemap: false` explicitly also turns them off in development, and it drops the inline source map from every bundle while skipping the source-map-support runtime shim on the Vercel step function (the same behavior production gets by default) — the main lever for staying under the Vercel 250MB function size limit. The tradeoff is that workflow VM stack traces will reference generated code (e.g. `evalmachine.<anonymous>`) rather than your source files.
121
+
122
+ <Callout type="info">
123
+ Setting `sourcemap` explicitly affects **all** generated bundles (steps, workflows, webhook). The legacy `WORKFLOW_EMIT_SOURCEMAPS_FOR_DEBUGGING=1` environment variable is narrower — it only toggles source maps on the final workflow wrapper and webhook bundle (which default to off). It continues to work, but new code should use the `sourcemap` option or the `WORKFLOW_SOURCEMAP` environment variable instead.
124
+ </Callout>
125
+
126
+ The option can also be set via the `WORKFLOW_SOURCEMAP` environment variable, which accepts the same values plus `'0'` / `'1'` as aliases for `false` / `true`. Precedence is: explicit config > `WORKFLOW_SOURCEMAP` > the environment-aware default (`'inline'` in development, `false` in production). Development is detected from `next dev` / `NODE_ENV=development`, so the config option and the env var both let you force either behavior in either environment.
74
127
 
75
128
  <Callout type="info">
76
129
  The `workflows.local` options only affect local development. When deployed to Vercel, the runtime ignores `local` settings and uses the Vercel world automatically.
@@ -78,6 +131,7 @@ The `workflows.local` options only affect local development. When deployed to Ve
78
131
 
79
132
  ## Exporting a Function
80
133
 
134
+
81
135
  If you are exporting a function in your `next.config` you will need to ensure you call the function returned from `withWorkflow`.
82
136
 
83
137
  ```typescript title="next.config.ts" lineNumbers