workflow 4.4.0 → 4.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/docs/api-reference/index.mdx +24 -0
  2. package/docs/api-reference/meta.json +8 -0
  3. package/docs/api-reference/vitest/index.mdx +0 -6
  4. package/docs/api-reference/workflow/create-hook.mdx +32 -0
  5. package/docs/api-reference/workflow/create-webhook.mdx +1 -0
  6. package/docs/api-reference/workflow-api/index.mdx +6 -8
  7. package/docs/api-reference/workflow-errors/meta.json +5 -0
  8. package/docs/api-reference/workflow-serde/index.mdx +0 -1
  9. package/docs/api-reference/workflow-serde/workflow-deserialize.mdx +1 -2
  10. package/docs/api-reference/workflow-serde/workflow-serialize.mdx +1 -2
  11. package/docs/deploying/world/vercel-world.mdx +2 -0
  12. package/docs/errors/index.mdx +3 -0
  13. package/docs/foundations/hooks.mdx +29 -0
  14. package/docs/foundations/streaming.mdx +7 -1
  15. package/docs/foundations/versioning.mdx +1 -1
  16. package/docs/how-it-works/encryption.mdx +2 -2
  17. package/docs/how-it-works/event-sourcing.mdx +2 -2
  18. package/docs/v4/api-reference/workflow-astro/index.mdx +18 -0
  19. package/docs/v4/api-reference/workflow-astro/meta.json +4 -0
  20. package/docs/v4/api-reference/workflow-astro/workflow.mdx +37 -0
  21. package/docs/v4/api-reference/workflow-errors/hook-conflict-error.mdx +60 -0
  22. package/docs/v4/api-reference/workflow-errors/run-not-supported-error.mdx +58 -0
  23. package/docs/v4/api-reference/workflow-errors/workflow-error.mdx +52 -0
  24. package/docs/v4/api-reference/workflow-errors/workflow-run-not-completed-error.mdx +58 -0
  25. package/docs/v4/api-reference/workflow-errors/workflow-runtime-error.mdx +58 -0
  26. package/docs/v4/api-reference/workflow-nest/configure-workflow-controller.mdx +33 -0
  27. package/docs/v4/api-reference/workflow-nest/index.mdx +31 -0
  28. package/docs/v4/api-reference/workflow-nest/meta.json +9 -0
  29. package/docs/v4/api-reference/workflow-nest/nest-local-builder.mdx +63 -0
  30. package/docs/v4/api-reference/workflow-nest/workflow-controller.mdx +40 -0
  31. package/docs/v4/api-reference/workflow-nest/workflow-module.mdx +73 -0
  32. package/docs/v4/api-reference/workflow-nitro/index.mdx +57 -0
  33. package/docs/v4/api-reference/workflow-nuxt/index.mdx +47 -0
  34. package/docs/v4/api-reference/workflow-observability/hydrate-data.mdx +35 -0
  35. package/docs/v4/api-reference/workflow-observability/hydrate-resource-io.mdx +62 -0
  36. package/docs/v4/api-reference/workflow-observability/index.mdx +64 -0
  37. package/docs/v4/api-reference/workflow-observability/meta.json +11 -0
  38. package/docs/v4/api-reference/workflow-observability/observability-revivers.mdx +50 -0
  39. package/docs/v4/api-reference/workflow-observability/parse-class-name.mdx +41 -0
  40. package/docs/v4/api-reference/workflow-observability/parse-step-name.mdx +40 -0
  41. package/docs/v4/api-reference/workflow-observability/parse-workflow-name.mdx +55 -0
  42. package/docs/v4/api-reference/workflow-runtime/create-world.mdx +43 -0
  43. package/docs/v4/api-reference/workflow-runtime/get-world-handlers.mdx +44 -0
  44. package/docs/v4/api-reference/workflow-runtime/get-world.mdx +124 -0
  45. package/docs/v4/api-reference/workflow-runtime/health-check.mdx +50 -0
  46. package/docs/v4/api-reference/workflow-runtime/index.mdx +46 -0
  47. package/docs/v4/api-reference/workflow-runtime/meta.json +13 -0
  48. package/docs/v4/api-reference/workflow-runtime/set-world.mdx +49 -0
  49. package/docs/v4/api-reference/workflow-runtime/step-entrypoint.mdx +39 -0
  50. package/docs/v4/api-reference/workflow-runtime/workflow-entrypoint.mdx +42 -0
  51. package/docs/{api-reference/workflow-api → v4/api-reference/workflow-runtime}/world/index.mdx +5 -8
  52. package/docs/v4/api-reference/workflow-runtime/world/meta.json +4 -0
  53. package/docs/v4/api-reference/workflow-runtime/world/queue.mdx +86 -0
  54. package/docs/{api-reference/workflow-api → v4/api-reference/workflow-runtime}/world/storage.mdx +4 -4
  55. package/docs/v4/api-reference/workflow-runtime/world/streams.mdx +216 -0
  56. package/docs/v4/api-reference/workflow-sveltekit/index.mdx +18 -0
  57. package/docs/v4/api-reference/workflow-sveltekit/meta.json +4 -0
  58. package/docs/v4/api-reference/workflow-sveltekit/workflow-plugin.mdx +34 -0
  59. package/docs/v4/api-reference/workflow-vite/index.mdx +18 -0
  60. package/docs/v4/api-reference/workflow-vite/meta.json +4 -0
  61. package/docs/v4/api-reference/workflow-vite/workflow.mdx +47 -0
  62. package/docs/v4/errors/step-executed-multiple-times.mdx +23 -0
  63. package/docs/v5/api-reference/workflow-astro/index.mdx +18 -0
  64. package/docs/v5/api-reference/workflow-astro/meta.json +4 -0
  65. package/docs/v5/api-reference/workflow-astro/workflow.mdx +45 -0
  66. package/docs/v5/api-reference/workflow-errors/hook-conflict-error.mdx +60 -0
  67. package/docs/v5/api-reference/workflow-errors/run-not-supported-error.mdx +58 -0
  68. package/docs/v5/api-reference/workflow-errors/workflow-error.mdx +52 -0
  69. package/docs/v5/api-reference/workflow-errors/workflow-run-not-completed-error.mdx +58 -0
  70. package/docs/v5/api-reference/workflow-errors/workflow-runtime-error.mdx +58 -0
  71. package/docs/v5/api-reference/workflow-nest/configure-workflow-controller.mdx +33 -0
  72. package/docs/v5/api-reference/workflow-nest/index.mdx +31 -0
  73. package/docs/v5/api-reference/workflow-nest/meta.json +9 -0
  74. package/docs/v5/api-reference/workflow-nest/nest-local-builder.mdx +64 -0
  75. package/docs/v5/api-reference/workflow-nest/workflow-controller.mdx +40 -0
  76. package/docs/v5/api-reference/workflow-nest/workflow-module.mdx +74 -0
  77. package/docs/v5/api-reference/workflow-nitro/index.mdx +59 -0
  78. package/docs/v5/api-reference/workflow-nuxt/index.mdx +47 -0
  79. package/docs/v5/api-reference/workflow-observability/hydrate-data.mdx +35 -0
  80. package/docs/v5/api-reference/workflow-observability/hydrate-resource-io.mdx +62 -0
  81. package/docs/v5/api-reference/workflow-observability/index.mdx +64 -0
  82. package/docs/v5/api-reference/workflow-observability/meta.json +11 -0
  83. package/docs/v5/api-reference/workflow-observability/observability-revivers.mdx +50 -0
  84. package/docs/v5/api-reference/workflow-observability/parse-class-name.mdx +41 -0
  85. package/docs/v5/api-reference/workflow-observability/parse-step-name.mdx +40 -0
  86. package/docs/v5/api-reference/workflow-observability/parse-workflow-name.mdx +55 -0
  87. package/docs/v5/api-reference/workflow-runtime/create-world.mdx +39 -0
  88. package/docs/v5/api-reference/workflow-runtime/get-world-handlers.mdx +44 -0
  89. package/docs/{api-reference/workflow-api → v5/api-reference/workflow-runtime}/get-world.mdx +7 -10
  90. package/docs/v5/api-reference/workflow-runtime/health-check.mdx +50 -0
  91. package/docs/v5/api-reference/workflow-runtime/index.mdx +43 -0
  92. package/docs/v5/api-reference/workflow-runtime/meta.json +12 -0
  93. package/docs/v5/api-reference/workflow-runtime/set-world.mdx +49 -0
  94. package/docs/v5/api-reference/workflow-runtime/workflow-entrypoint.mdx +42 -0
  95. package/docs/v5/api-reference/workflow-runtime/world/index.mdx +55 -0
  96. package/docs/v5/api-reference/workflow-runtime/world/meta.json +4 -0
  97. package/docs/{api-reference/workflow-api → v5/api-reference/workflow-runtime}/world/queue.mdx +2 -2
  98. package/docs/v5/api-reference/workflow-runtime/world/storage.mdx +409 -0
  99. package/docs/{api-reference/workflow-api → v5/api-reference/workflow-runtime}/world/streams.mdx +2 -2
  100. package/docs/v5/api-reference/workflow-sveltekit/index.mdx +18 -0
  101. package/docs/v5/api-reference/workflow-sveltekit/meta.json +4 -0
  102. package/docs/v5/api-reference/workflow-sveltekit/workflow-plugin.mdx +42 -0
  103. package/docs/v5/api-reference/workflow-vite/index.mdx +18 -0
  104. package/docs/v5/api-reference/workflow-vite/meta.json +4 -0
  105. package/docs/v5/api-reference/workflow-vite/workflow.mdx +48 -0
  106. package/docs/v5/errors/index.mdx +3 -0
  107. package/docs/v5/errors/step-executed-multiple-times.mdx +23 -0
  108. package/package.json +10 -10
  109. package/docs/api-reference/workflow-api/world/meta.json +0 -4
  110. package/docs/api-reference/workflow-api/world/observability.mdx +0 -164
@@ -0,0 +1,48 @@
1
+ ---
2
+ title: workflow
3
+ description: Configure Vite and Nitro to transform workflow directives.
4
+ type: reference
5
+ summary: Add the workflow plugin to your Vite config to enable workflow directive transformation in Vite + Nitro apps.
6
+ prerequisites:
7
+ - /docs/getting-started/vite
8
+ ---
9
+
10
+ Returns the Vite plugins that transform workflow code (`"use step"`/`"use workflow"` directives) and configure the [`workflow/nitro`](/docs/api-reference/workflow-nitro) module on the Nitro server. It is designed to be used alongside `nitro()` from `nitro/vite`, which provides the server framework for API routes and deployment.
11
+
12
+ ## Usage
13
+
14
+ To enable `"use step"` and `"use workflow"` directives while developing locally or deploying to production, add `workflow()` to the `plugins` array of your Vite config, together with `nitro()`.
15
+
16
+ ```typescript title="vite.config.ts" lineNumbers
17
+ import { nitro } from "nitro/vite";
18
+ import { defineConfig } from "vite";
19
+ import { workflow } from "workflow/vite"; // [!code highlight]
20
+
21
+ export default defineConfig({
22
+ plugins: [nitro(), workflow()], // [!code highlight]
23
+ nitro: {
24
+ serverDir: "./",
25
+ },
26
+ });
27
+ ```
28
+
29
+ ## API Signature
30
+
31
+ ### Parameters
32
+
33
+ | Parameter | Type | Description |
34
+ | --- | --- | --- |
35
+ | `options` | `ModuleOptions` | Optional. Forwarded to the `workflow/nitro` module as its module options. |
36
+
37
+ #### ModuleOptions
38
+
39
+ | Option | Type | Default | Description |
40
+ | --- | --- | --- | --- |
41
+ | `dirs` | `string[]` | — | Directories to scan for workflows and steps. By default, the `workflows/` directory is scanned from the project root and all layer source directories. |
42
+ | `typescriptPlugin` | `boolean` | `false` | Adds the `workflow` TypeScript plugin to the generated `tsconfig.json` for IDE IntelliSense. |
43
+ | `runtime` | `string` | — | Node.js runtime version for Vercel Functions (e.g. `'nodejs22.x'`, `'nodejs24.x'`). Only applies when deploying to Vercel. |
44
+ | `sourcemap` | `boolean \| 'inline' \| 'linked' \| 'external' \| 'both'` | `'inline'` | Controls source maps on generated workflow bundles. Accepts the same values as esbuild's `sourcemap` option. Set to `false` for smaller function bundles (useful for staying under the Vercel 250MB function size limit) at the cost of stack traces pointing at generated code. Can also be set via the `WORKFLOW_SOURCEMAP` environment variable. |
45
+
46
+ ### Returns
47
+
48
+ 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.
@@ -40,6 +40,9 @@ Fix common mistakes when creating and executing workflows in the **Workflow SDK*
40
40
  <Card href="/docs/errors/step-not-registered" title="step-not-registered">
41
41
  Resolve step not registered errors caused by deployment mismatches.
42
42
  </Card>
43
+ <Card href="/docs/errors/step-executed-multiple-times" title="Step executed multiple times">
44
+ Diagnose duplicate step_started events from function crashes, timeouts, or OOMs.
45
+ </Card>
43
46
  <Card href="/docs/errors/workflow-not-registered" title="workflow-not-registered">
44
47
  Resolve workflow not registered errors caused by deployment mismatches.
45
48
  </Card>
@@ -0,0 +1,23 @@
1
+ ---
2
+ title: Step executed multiple times
3
+ description: A step ran more than once because its function invocation crashed before it could report a result.
4
+ type: troubleshooting
5
+ summary: Diagnose duplicate step_started events caused by function timeouts, OOMs, or network issues.
6
+ prerequisites:
7
+ - /docs/foundations/workflows-and-steps
8
+ related:
9
+ - /docs/observability
10
+ - /docs/foundations/errors-and-retries
11
+ ---
12
+
13
+ There may be cases where you see multiple `step_started` events for the same step in a workflow run. This happens if the function invocation executing the step crashes unexpectedly, and the step can not report the error. The step will be re-tried according to your retry policy in this case, but no error will be visible in the [Observability UI](/docs/observability).
14
+
15
+ ## Common Causes
16
+
17
+ - **Function timeouts**: if your step code runs longer than the configured maximum function duration, it will be killed. Compare the gap between the `step_started` events to your configured function duration to be sure.
18
+ - **Out of memory (OOM)**: if your step code loads enough data into memory, especially if the step is invoked concurrently, the function invocation might run out of memory. You can see your function's peak memory use by going to the [Observability Query page](https://vercel.com/docs/observability) and showing the **Function Invocation Peak Memory** metric, then filtering down the **Route** to `/.well-known/workflow` endpoints.
19
+ - **Network issues**: persistent firewall, network stability, and related issues might prevent your function from reporting results or errors. This should be temporary.
20
+
21
+ ## Getting Help
22
+
23
+ If you consistently see multiple `step_started` events and have ruled out function timeouts, OOMs, and firewall issues, please [contact support](https://vercel.com/help).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "workflow",
3
- "version": "4.4.0",
3
+ "version": "4.5.0",
4
4
  "description": "Workflow SDK - Build durable, resilient, and observable workflows",
5
5
  "main": "dist/typescript-plugin.cjs",
6
6
  "type": "module",
@@ -57,18 +57,18 @@
57
57
  },
58
58
  "dependencies": {
59
59
  "ms": "2.1.3",
60
- "@workflow/astro": "4.0.9",
61
- "@workflow/cli": "4.2.9",
62
- "@workflow/core": "4.4.0",
60
+ "@workflow/astro": "4.0.10",
61
+ "@workflow/cli": "4.2.10",
62
+ "@workflow/core": "4.5.0",
63
63
  "@workflow/errors": "4.1.4",
64
64
  "@workflow/typescript-plugin": "4.0.3",
65
65
  "@workflow/utils": "4.1.3",
66
- "@workflow/next": "4.0.10",
67
- "@workflow/nest": "0.0.9",
68
- "@workflow/nitro": "4.1.0",
69
- "@workflow/nuxt": "4.0.10",
70
- "@workflow/sveltekit": "4.0.9",
71
- "@workflow/rollup": "4.0.9"
66
+ "@workflow/next": "4.0.11",
67
+ "@workflow/nest": "0.0.10",
68
+ "@workflow/nitro": "4.1.1",
69
+ "@workflow/nuxt": "4.0.11",
70
+ "@workflow/sveltekit": "4.0.10",
71
+ "@workflow/rollup": "4.0.10"
72
72
  },
73
73
  "devDependencies": {
74
74
  "@types/ms": "2.1.0",
@@ -1,4 +0,0 @@
1
- {
2
- "title": "World SDK",
3
- "pages": ["storage", "streams", "queue", "observability"]
4
- }
@@ -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 = 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