workflow 4.2.0-beta.71 → 4.2.0-beta.72

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 (48) hide show
  1. package/dist/api.d.ts +1 -1
  2. package/dist/api.d.ts.map +1 -1
  3. package/dist/api.js +1 -1
  4. package/dist/internal/errors.d.ts +1 -1
  5. package/dist/internal/errors.d.ts.map +1 -1
  6. package/dist/internal/errors.js +2 -2
  7. package/dist/observability.d.ts +20 -0
  8. package/dist/observability.d.ts.map +1 -0
  9. package/dist/observability.js +20 -0
  10. package/docs/ai/defining-tools.mdx +6 -0
  11. package/docs/ai/index.mdx +3 -0
  12. package/docs/ai/message-queueing.mdx +2 -0
  13. package/docs/ai/resumable-streams.mdx +37 -4
  14. package/docs/ai/sleep-and-delays.mdx +2 -0
  15. package/docs/api-reference/meta.json +1 -1
  16. package/docs/api-reference/workflow/define-hook.mdx +2 -0
  17. package/docs/api-reference/workflow/get-writable.mdx +1 -0
  18. package/docs/api-reference/workflow-ai/durable-agent.mdx +2 -0
  19. package/docs/api-reference/workflow-ai/workflow-chat-transport.mdx +2 -0
  20. package/docs/api-reference/workflow-api/get-run.mdx +14 -0
  21. package/docs/api-reference/workflow-api/get-world.mdx +105 -0
  22. package/docs/api-reference/workflow-errors/entity-conflict-error.mdx +60 -0
  23. package/docs/api-reference/workflow-errors/hook-not-found-error.mdx +90 -0
  24. package/docs/api-reference/workflow-errors/meta.json +16 -0
  25. package/docs/api-reference/workflow-errors/run-expired-error.mdx +58 -0
  26. package/docs/api-reference/workflow-errors/step-not-registered-error.mdx +56 -0
  27. package/docs/api-reference/workflow-errors/throttle-error.mdx +62 -0
  28. package/docs/api-reference/workflow-errors/too-early-error.mdx +62 -0
  29. package/docs/api-reference/workflow-errors/workflow-not-registered-error.mdx +57 -0
  30. package/docs/api-reference/workflow-errors/workflow-run-cancelled-error.mdx +56 -0
  31. package/docs/api-reference/workflow-errors/workflow-run-failed-error.mdx +62 -0
  32. package/docs/api-reference/workflow-errors/workflow-run-not-found-error.mdx +56 -0
  33. package/docs/api-reference/workflow-errors/workflow-world-error.mdx +79 -0
  34. package/docs/changelog/index.mdx +15 -0
  35. package/docs/changelog/meta.json +5 -0
  36. package/docs/deploying/building-a-world.mdx +20 -0
  37. package/docs/errors/hook-conflict.mdx +9 -3
  38. package/docs/errors/index.mdx +6 -0
  39. package/docs/errors/step-not-registered.mdx +66 -0
  40. package/docs/errors/webhook-invalid-respond-with-value.mdx +10 -0
  41. package/docs/errors/webhook-response-not-sent.mdx +8 -0
  42. package/docs/errors/workflow-not-registered.mdx +64 -0
  43. package/docs/foundations/errors-and-retries.mdx +29 -0
  44. package/docs/foundations/streaming.mdx +22 -0
  45. package/docs/getting-started/index.mdx +3 -3
  46. package/docs/getting-started/meta.json +15 -0
  47. package/docs/getting-started/nestjs.mdx +4 -8
  48. package/package.json +18 -12
@@ -43,6 +43,8 @@ export async function webhookWorkflow() {
43
43
  **Solution:** Use `"manual"` or provide a `Response` object.
44
44
 
45
45
  ```typescript lineNumbers
46
+ import { createWebhook } from "workflow";
47
+
46
48
  // Fixed - use "manual"
47
49
  export async function webhookWorkflow() {
48
50
  "use workflow";
@@ -74,6 +76,8 @@ export async function webhookWorkflow() {
74
76
  **Solution:** Create a proper `Response` object.
75
77
 
76
78
  ```typescript lineNumbers
79
+ import { createWebhook } from "workflow";
80
+
77
81
  // Fixed - use Response constructor
78
82
  export async function webhookWorkflow() {
79
83
  "use workflow";
@@ -89,6 +93,8 @@ export async function webhookWorkflow() {
89
93
  ### Default Behavior (202 Response)
90
94
 
91
95
  ```typescript lineNumbers
96
+ import { createWebhook } from "workflow";
97
+
92
98
  // Returns 202 Accepted automatically
93
99
  const webhook = await createWebhook();
94
100
  const request = await webhook;
@@ -98,6 +104,8 @@ const request = await webhook;
98
104
  ### Manual Response
99
105
 
100
106
  ```typescript lineNumbers
107
+ import { createWebhook } from "workflow";
108
+
101
109
  // Manual response control
102
110
  const webhook = await createWebhook({
103
111
  respondWith: "manual",
@@ -120,6 +128,8 @@ await request.respondWith(
120
128
  ### Pre-defined Response
121
129
 
122
130
  ```typescript lineNumbers
131
+ import { createWebhook } from "workflow";
132
+
123
133
  // Immediate response
124
134
  const webhook = await createWebhook({
125
135
  respondWith: new Response("Request received", { status: 200 }),
@@ -49,6 +49,8 @@ export async function webhookWorkflow() {
49
49
  **Solution:** Always call `request.respondWith()` when using manual response mode.
50
50
 
51
51
  ```typescript lineNumbers
52
+ import { createWebhook } from "workflow";
53
+
52
54
  // Fixed - response sent
53
55
  export async function webhookWorkflow() {
54
56
  "use workflow";
@@ -92,6 +94,8 @@ export async function webhookWorkflow() {
92
94
  **Solution:** Ensure all code paths send a response.
93
95
 
94
96
  ```typescript lineNumbers
97
+ import { createWebhook } from "workflow";
98
+
95
99
  // Fixed - response sent in all branches
96
100
  export async function webhookWorkflow() {
97
101
  "use workflow";
@@ -135,6 +139,8 @@ export async function webhookWorkflow() {
135
139
  **Solution:** Use try-catch to handle errors and send appropriate responses.
136
140
 
137
141
  ```typescript lineNumbers
142
+ import { createWebhook } from "workflow";
143
+
138
144
  // Fixed - error handling with response
139
145
  export async function webhookWorkflow() {
140
146
  "use workflow";
@@ -163,6 +169,8 @@ export async function webhookWorkflow() {
163
169
  If you don't need custom response control, consider using the default response mode which automatically returns a `202 Accepted` response:
164
170
 
165
171
  ```typescript lineNumbers
172
+ import { createWebhook } from "workflow";
173
+
166
174
  // Automatic 202 response - no manual response needed
167
175
  export async function webhookWorkflow() {
168
176
  "use workflow";
@@ -0,0 +1,64 @@
1
+ ---
2
+ title: workflow-not-registered
3
+ description: A workflow function is not registered in the current deployment.
4
+ type: troubleshooting
5
+ summary: Resolve workflow not registered errors caused by deployment targeting or build issues.
6
+ prerequisites:
7
+ - /docs/foundations/starting-workflows
8
+ related:
9
+ - /docs/errors/step-not-registered
10
+ - /docs/api-reference/workflow-errors/workflow-not-registered-error
11
+ ---
12
+
13
+ This error occurs when the Workflow runtime tries to execute a workflow function that is not registered in the current deployment. When this happens, the run fails with a `RUNTIME_ERROR` error code.
14
+
15
+ ## Error Message
16
+
17
+ ```
18
+ Workflow "<workflowName>" is not registered in the current deployment.
19
+ This usually means a run was started against a deployment that does not
20
+ have this workflow, or there was a build/bundling issue.
21
+ ```
22
+
23
+ ## Why This Happens
24
+
25
+ This error means the deployment that received the workflow execution request does not have the specified workflow function in its bundle. This is an **infrastructure error**, not a user code error.
26
+
27
+ ## Common Causes
28
+
29
+ ### Run started against a deployment without the workflow
30
+
31
+ A run was started (or restarted from the dashboard UI) targeting a deployment where the workflow was renamed, moved to a different file, or removed entirely.
32
+
33
+ {/* @skip-typecheck: incomplete code sample */}
34
+ ```typescript lineNumbers title="workflows/order.ts (original)"
35
+ export async function processOrder(orderId: string) {
36
+ "use workflow";
37
+ // workflow logic
38
+ }
39
+ ```
40
+
41
+ {/* @skip-typecheck: incomplete code sample */}
42
+ ```typescript lineNumbers title="workflows/order.ts (current deployment)"
43
+ // Renamed from processOrder to handleOrder
44
+ export async function handleOrder(orderId: string) { // [!code highlight]
45
+ "use workflow";
46
+ // workflow logic
47
+ }
48
+ ```
49
+
50
+ If a new run is started targeting the current deployment using the old name `processOrder`, the runtime will not find it.
51
+
52
+ ### Build tooling issue
53
+
54
+ Something went wrong during the build process that caused the workflow function to not be included in the workflow bundle. Check your build logs for errors related to workflow bundling. Common issues include:
55
+
56
+ - The workflow file is missing a valid `"use workflow"` directive
57
+ - The workflow function is not exported from the workflow file
58
+ - An esbuild or SWC plugin error silently excluded the workflow
59
+
60
+ ## How to Resolve
61
+
62
+ 1. **If the workflow was renamed or moved:** Deploy with the workflow restored to its original name and location, then retry the run. Alternatively, start a new run using the updated workflow name against the current deployment.
63
+
64
+ 2. **If it's a build issue:** Check your build logs for errors related to workflow bundling. Ensure the workflow file contains a valid `"use workflow"` directive and is properly exported.
@@ -139,6 +139,35 @@ callApi.maxRetries = 5; // Retry up to 5 times on failure (6 total attempts)
139
139
  step can run up to 4 times total (1 initial attempt + 3 retries).
140
140
  </Callout>
141
141
 
142
+ ## Error Codes
143
+
144
+ When a workflow run fails, the error may include a `code` that classifies the failure. You can access it programmatically via the `Run` class:
145
+
146
+ ```typescript lineNumbers
147
+ import { WorkflowRunFailedError } from "@workflow/errors";
148
+ import { start } from "workflow/api";
149
+
150
+ const run = await start(myWorkflow, [input]);
151
+
152
+ try {
153
+ const result = await run.returnValue;
154
+ } catch (err) {
155
+ if (WorkflowRunFailedError.is(err)) {
156
+ console.log(err.cause.code); // "USER_ERROR", "RUNTIME_ERROR", or undefined
157
+ console.log(err.cause.message); // The error message
158
+ }
159
+ }
160
+ ```
161
+
162
+ | Code | Meaning |
163
+ | --- | --- |
164
+ | `USER_ERROR` | An error thrown in your workflow or step code (including propagated step failures like `FatalError`) |
165
+ | `RUNTIME_ERROR` | An internal runtime error such as a corrupted event log or missing data. If you see this, please [file an issue](https://github.com/vercel/workflow/issues) |
166
+
167
+ <Callout type="info">
168
+ The error code is also available on the run entity via the CLI (`npx workflow inspect runs <runId>`) in the `error.code` field, and as an OTEL span attribute (`workflow.error.code`) for observability.
169
+ </Callout>
170
+
142
171
  ## Rolling Back Failed Steps
143
172
 
144
173
  When a workflow fails partway through, it can leave the system in an inconsistent state.
@@ -87,6 +87,22 @@ export async function GET(
87
87
 
88
88
  This allows clients to reconnect and continue receiving data from where they left off, rather than restarting from the beginning.
89
89
 
90
+ `startIndex` also supports **negative values** to read relative to the end of the stream. For example, `startIndex: -5` starts 5 chunks before the current end. This is useful when you want to show the most recent output without reading the entire stream history.
91
+
92
+ On an active (not-yet-closed) stream, the negative index resolves relative to the chunk count at connection time; any chunks written afterward are still delivered normally.
93
+
94
+ {/* @skip-typecheck: incomplete code sample */}
95
+ ```typescript
96
+ // Read only the last 10 chunks
97
+ const stream = run.getReadable({ startIndex: -10 });
98
+ ```
99
+
100
+ If the absolute value exceeds the total number of chunks, reading starts from the beginning (the value is clamped to 0).
101
+
102
+ <Callout type="warn">
103
+ Because streams are live and continue receiving chunks, negative `startIndex` values resolve to different absolute positions on each call. Accurate pagination over a live stream requires cursor-based access, which is not yet supported. Keep this in mind when building clients that paginate over stream data.
104
+ </Callout>
105
+
90
106
  ## Streams as Data Types
91
107
 
92
108
  [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) and [`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream) are standard Web Streams API types that Workflow DevKit makes serializable. These are not custom types - they follow the web standard - but Workflow DevKit adds the ability to pass them between functions while maintaining their streaming capabilities.
@@ -164,6 +180,8 @@ Workflow functions must be deterministic to support replay. Since streams bypass
164
180
  For more on determinism and replay, see [Workflows and Steps](/docs/foundations/workflows-and-steps).
165
181
 
166
182
  ```typescript title="workflows/bad-example.ts" lineNumbers
183
+ import { getWritable } from "workflow";
184
+
167
185
  export async function badWorkflow() {
168
186
  "use workflow";
169
187
 
@@ -176,6 +194,8 @@ export async function badWorkflow() {
176
194
  ```
177
195
 
178
196
  ```typescript title="workflows/good-example.ts" lineNumbers
197
+ import { getWritable } from "workflow";
198
+
179
199
  export async function goodWorkflow() {
180
200
  "use workflow";
181
201
 
@@ -501,6 +521,8 @@ If a lock is not released, the step function's HTTP request cannot terminate. Ev
501
521
  **Close streams when done:**
502
522
 
503
523
  ```typescript lineNumbers
524
+ import { getWritable } from "workflow";
525
+
504
526
  async function finalizeStream() {
505
527
  "use step";
506
528
 
@@ -63,11 +63,11 @@ import { Next, Nitro, SvelteKit, Nuxt, Hono, Bun, AstroDark, AstroLight, TanStac
63
63
  <span className="font-medium">SvelteKit</span>
64
64
  </div>
65
65
  </Card>
66
- <Card href="/docs/getting-started/nestjs">
66
+ <Card className="opacity-50">
67
67
  <div className="flex flex-col items-center justify-center gap-2">
68
- <Nest className="size-16" />
68
+ <Nest className="size-16 dark:invert grayscale" />
69
69
  <span className="font-medium">NestJS</span>
70
- <Badge variant="secondary">Experimental</Badge>
70
+ <Badge variant="secondary">Coming soon</Badge>
71
71
  </div>
72
72
  </Card>
73
73
  <Card className="opacity-50">
@@ -0,0 +1,15 @@
1
+ {
2
+ "title": "Getting Started",
3
+ "pages": [
4
+ "next",
5
+ "astro",
6
+ "express",
7
+ "fastify",
8
+ "hono",
9
+ "nitro",
10
+ "nuxt",
11
+ "sveltekit",
12
+ "vite"
13
+ ],
14
+ "defaultOpen": true
15
+ }
@@ -11,6 +11,10 @@ related:
11
11
 
12
12
  This guide will walk through setting up your first workflow in a NestJS app. Along the way, you'll learn more about the concepts that are fundamental to using the development kit in your own projects.
13
13
 
14
+ <Callout>
15
+ NestJS integration is experimental and not yet supported for deployment to Vercel.
16
+ </Callout>
17
+
14
18
  ---
15
19
 
16
20
  <Steps>
@@ -323,14 +327,6 @@ WorkflowModule.forRoot({
323
327
  });
324
328
  ```
325
329
 
326
- ## Deploying to production
327
-
328
- Workflow DevKit apps currently work best when deployed to [Vercel](https://vercel.com/home) and needs no special configuration.
329
-
330
- <FluidComputeCallout />
331
-
332
- Check the [Deploying](/docs/deploying) section to learn how your workflows can be deployed elsewhere.
333
-
334
330
  ## Next Steps
335
331
 
336
332
  - Learn more about the [Foundations](/docs/foundations).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "workflow",
3
- "version": "4.2.0-beta.71",
3
+ "version": "4.2.0-beta.72",
4
4
  "description": "Workflow DevKit - Build durable, resilient, and observable workflows",
5
5
  "main": "dist/typescript-plugin.cjs",
6
6
  "type": "module",
@@ -37,6 +37,7 @@
37
37
  "workflow": "./dist/api-workflow.js",
38
38
  "default": "./dist/api.js"
39
39
  },
40
+ "./errors": "./dist/internal/errors.js",
40
41
  "./internal/errors": "./dist/internal/errors.js",
41
42
  "./internal/builtins": "./dist/internal/builtins.js",
42
43
  "./internal/private": "./dist/internal/private.js",
@@ -48,21 +49,26 @@
48
49
  "./astro": "./dist/astro.js",
49
50
  "./vite": "./dist/vite.js",
50
51
  "./nest": "./dist/nest.js",
51
- "./runtime": "./dist/runtime.js"
52
+ "./runtime": "./dist/runtime.js",
53
+ "./observability": {
54
+ "types": "./dist/observability.d.ts",
55
+ "default": "./dist/observability.js"
56
+ }
52
57
  },
53
58
  "dependencies": {
54
59
  "ms": "2.1.3",
55
- "@workflow/astro": "4.0.0-beta.45",
56
- "@workflow/cli": "4.2.0-beta.71",
57
- "@workflow/core": "4.2.0-beta.71",
58
- "@workflow/errors": "4.1.0-beta.18",
60
+ "@workflow/astro": "4.0.0-beta.46",
61
+ "@workflow/cli": "4.2.0-beta.72",
62
+ "@workflow/core": "4.2.0-beta.72",
63
+ "@workflow/errors": "4.1.0-beta.19",
59
64
  "@workflow/typescript-plugin": "4.0.1-beta.5",
60
- "@workflow/next": "4.0.1-beta.67",
61
- "@workflow/nest": "0.0.0-beta.20",
62
- "@workflow/nitro": "4.0.1-beta.66",
63
- "@workflow/nuxt": "4.0.1-beta.55",
64
- "@workflow/sveltekit": "4.0.0-beta.60",
65
- "@workflow/rollup": "4.0.0-beta.28"
65
+ "@workflow/utils": "4.1.0-beta.13",
66
+ "@workflow/next": "4.0.1-beta.68",
67
+ "@workflow/nest": "0.0.0-beta.21",
68
+ "@workflow/nitro": "4.0.1-beta.67",
69
+ "@workflow/nuxt": "4.0.1-beta.56",
70
+ "@workflow/sveltekit": "4.0.0-beta.61",
71
+ "@workflow/rollup": "4.0.0-beta.29"
66
72
  },
67
73
  "devDependencies": {
68
74
  "@types/ms": "2.1.0",