workflow 4.2.0-beta.75 → 4.2.0-beta.77
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/docs/api-reference/workflow-ai/durable-agent.mdx +86 -1
- package/docs/api-reference/workflow-api/get-world.mdx +59 -14
- package/docs/api-reference/workflow-api/start.mdx +5 -0
- package/docs/api-reference/workflow-api/world/index.mdx +5 -14
- package/docs/api-reference/workflow-api/world/meta.json +1 -9
- package/docs/api-reference/workflow-api/world/observability.mdx +14 -139
- package/docs/api-reference/workflow-api/world/queue.mdx +26 -67
- package/docs/api-reference/workflow-api/world/storage.mdx +408 -0
- package/docs/api-reference/workflow-api/world/streams.mdx +89 -27
- package/docs/api-reference/workflow-next/with-workflow.mdx +51 -0
- package/docs/changelog/meta.json +1 -1
- package/docs/changelog/resilient-start.mdx +327 -0
- package/docs/deploying/building-a-world.mdx +16 -6
- package/docs/deploying/index.mdx +2 -2
- package/docs/deploying/world/vercel-world.mdx +30 -1
- package/docs/errors/hook-conflict.mdx +1 -1
- package/docs/errors/node-js-module-in-workflow.mdx +1 -1
- package/docs/errors/start-invalid-workflow-function.mdx +83 -58
- package/docs/foundations/serialization.mdx +3 -3
- package/docs/foundations/starting-workflows.mdx +1 -1
- package/docs/foundations/streaming.mdx +1 -1
- package/docs/getting-started/astro.mdx +18 -1
- package/docs/getting-started/express.mdx +18 -1
- package/docs/getting-started/fastify.mdx +18 -1
- package/docs/getting-started/hono.mdx +18 -1
- package/docs/getting-started/nestjs.mdx +84 -6
- package/docs/getting-started/next.mdx +17 -2
- package/docs/getting-started/nitro.mdx +18 -1
- package/docs/getting-started/nuxt.mdx +18 -1
- package/docs/getting-started/sveltekit.mdx +18 -1
- package/docs/getting-started/vite.mdx +18 -1
- package/docs/how-it-works/encryption.mdx +39 -2
- package/docs/how-it-works/event-sourcing.mdx +19 -2
- package/docs/how-it-works/framework-integrations.mdx +68 -11
- package/docs/how-it-works/understanding-directives.mdx +3 -3
- package/docs/observability/index.mdx +1 -1
- package/docs/testing/index.mdx +1 -1
- package/docs/testing/server-based.mdx +59 -16
- package/package.json +10 -10
- package/docs/api-reference/workflow-api/world/events.mdx +0 -227
- package/docs/api-reference/workflow-api/world/hooks.mdx +0 -181
- package/docs/api-reference/workflow-api/world/runs.mdx +0 -223
- package/docs/api-reference/workflow-api/world/steps.mdx +0 -216
|
@@ -1,107 +1,132 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: start-invalid-workflow-function
|
|
3
|
-
description:
|
|
3
|
+
description: The function passed to start() must be a transformed workflow function.
|
|
4
4
|
type: troubleshooting
|
|
5
|
-
summary:
|
|
5
|
+
summary: Fix invalid workflow function errors by adding "use workflow" and enabling your framework integration.
|
|
6
6
|
prerequisites:
|
|
7
7
|
- /docs/foundations/starting-workflows
|
|
8
8
|
related:
|
|
9
9
|
- /docs/api-reference/workflow-api/start
|
|
10
|
+
- /docs/getting-started/next
|
|
11
|
+
- /docs/api-reference/workflow-next/with-workflow
|
|
10
12
|
---
|
|
11
13
|
|
|
12
|
-
This error occurs when
|
|
14
|
+
This error occurs when `start()` receives a function that does not have Workflow SDK's generated workflow metadata. In practice, that usually means the function is missing `"use workflow"` or the file was never transformed by your framework integration.
|
|
13
15
|
|
|
14
16
|
## Error Message
|
|
15
17
|
|
|
16
18
|
```
|
|
17
|
-
'start' received an invalid workflow function. Ensure the Workflow SDK
|
|
18
|
-
is configured correctly and the function includes a 'use workflow' directive.
|
|
19
|
+
'start' received an invalid workflow function. Ensure the Workflow SDK is configured correctly and the function includes a 'use workflow' directive.
|
|
19
20
|
```
|
|
20
21
|
|
|
21
22
|
## Why This Happens
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
This error typically happens when:
|
|
26
|
-
|
|
27
|
-
* The function is missing the `"use workflow"` directive
|
|
28
|
-
* The workflow isn't being built/transformed correctly
|
|
29
|
-
* The function isn't exported from the workflow file
|
|
30
|
-
* The wrong function is being imported
|
|
24
|
+
`start()` expects an imported workflow function, not just any async function. During compilation, Workflow SDK transforms files that contain `"use workflow"` and attaches generated metadata such as the workflow ID. If that transform never runs, or if you pass a wrapper function instead of the transformed export, `start()` cannot identify what to enqueue and throws this error.
|
|
31
25
|
|
|
32
26
|
## Common Causes
|
|
33
27
|
|
|
34
|
-
### Missing `"use workflow"`
|
|
28
|
+
### Missing `"use workflow"`
|
|
35
29
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
// workflow logic
|
|
40
|
-
return { status: "completed" };
|
|
41
|
-
}
|
|
42
|
-
```
|
|
30
|
+
{/* @skip-typecheck: incomplete code sample */}
|
|
31
|
+
```typescript lineNumbers
|
|
32
|
+
import { start } from "workflow/api";
|
|
43
33
|
|
|
44
|
-
|
|
34
|
+
export async function sendReminder(email: string) {
|
|
35
|
+
await sendEmail(email);
|
|
36
|
+
}
|
|
45
37
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
38
|
+
export async function POST() {
|
|
39
|
+
await start(sendReminder, ["hello@example.com"]);
|
|
40
|
+
return new Response("ok");
|
|
41
|
+
}
|
|
50
42
|
|
|
51
|
-
|
|
52
|
-
|
|
43
|
+
async function sendEmail(email: string) {
|
|
44
|
+
"use step";
|
|
45
|
+
console.log(`Sending email to ${email}`);
|
|
53
46
|
}
|
|
54
47
|
```
|
|
55
48
|
|
|
56
|
-
|
|
49
|
+
**Fix:** Add `"use workflow"` to the workflow function.
|
|
57
50
|
|
|
58
|
-
|
|
51
|
+
{/* @skip-typecheck: incomplete code sample */}
|
|
52
|
+
```typescript lineNumbers
|
|
59
53
|
import { start } from "workflow/api";
|
|
60
|
-
// Error - importing step function instead of workflow
|
|
61
|
-
import { processStep } from "@/workflows/order"; // [!code highlight]
|
|
62
54
|
|
|
63
|
-
export async function
|
|
64
|
-
|
|
65
|
-
|
|
55
|
+
export async function sendReminder(email: string) {
|
|
56
|
+
"use workflow"; // [!code highlight]
|
|
57
|
+
await sendEmail(email);
|
|
66
58
|
}
|
|
67
|
-
```
|
|
68
59
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
// Fixed - import workflow function
|
|
74
|
-
import { processOrder } from "@/workflows/order"; // [!code highlight]
|
|
60
|
+
export async function POST() {
|
|
61
|
+
await start(sendReminder, ["hello@example.com"]); // [!code highlight]
|
|
62
|
+
return new Response("ok");
|
|
63
|
+
}
|
|
75
64
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
65
|
+
async function sendEmail(email: string) {
|
|
66
|
+
"use step";
|
|
67
|
+
console.log(`Sending email to ${email}`);
|
|
79
68
|
}
|
|
80
69
|
```
|
|
81
70
|
|
|
82
|
-
###
|
|
71
|
+
### Missing `withWorkflow()` in `next.config.ts`
|
|
83
72
|
|
|
84
|
-
|
|
85
|
-
|
|
73
|
+
{/* @skip-typecheck: incomplete code sample */}
|
|
74
|
+
```typescript title="next.config.ts" lineNumbers
|
|
86
75
|
import type { NextConfig } from "next";
|
|
87
76
|
|
|
88
|
-
const nextConfig: NextConfig = {
|
|
89
|
-
// your config
|
|
90
|
-
};
|
|
77
|
+
const nextConfig: NextConfig = {};
|
|
91
78
|
|
|
92
79
|
export default nextConfig;
|
|
93
80
|
```
|
|
94
81
|
|
|
95
|
-
**
|
|
82
|
+
**Fix:** Wrap the config with `withWorkflow()` so workflow files are transformed.
|
|
96
83
|
|
|
97
|
-
```typescript
|
|
98
|
-
// Fixed - includes withWorkflow
|
|
99
|
-
import { withWorkflow } from "workflow/next"; // [!code highlight}
|
|
84
|
+
```typescript title="next.config.ts" lineNumbers
|
|
100
85
|
import type { NextConfig } from "next";
|
|
86
|
+
import { withWorkflow } from "workflow/next"; // [!code highlight]
|
|
101
87
|
|
|
102
|
-
const nextConfig: NextConfig = {
|
|
103
|
-
// your config
|
|
104
|
-
};
|
|
88
|
+
const nextConfig: NextConfig = {};
|
|
105
89
|
|
|
106
90
|
export default withWorkflow(nextConfig); // [!code highlight]
|
|
107
91
|
```
|
|
92
|
+
|
|
93
|
+
### Passing a wrapper function instead of the imported workflow
|
|
94
|
+
|
|
95
|
+
{/* @skip-typecheck: incomplete code sample */}
|
|
96
|
+
```typescript lineNumbers
|
|
97
|
+
import { start } from "workflow/api";
|
|
98
|
+
import { sendReminder } from "./workflows/send-reminder";
|
|
99
|
+
|
|
100
|
+
export async function POST() {
|
|
101
|
+
// Does NOT work
|
|
102
|
+
await start(async () => sendReminder("hello@example.com"));
|
|
103
|
+
return new Response("ok");
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
**Fix:** Pass the imported workflow function directly and provide arguments in the second parameter.
|
|
108
|
+
|
|
109
|
+
```typescript lineNumbers
|
|
110
|
+
import { start } from "workflow/api";
|
|
111
|
+
import { sendReminder } from "./workflows/send-reminder";
|
|
112
|
+
|
|
113
|
+
export async function POST() {
|
|
114
|
+
await start(sendReminder, ["hello@example.com"]); // [!code highlight]
|
|
115
|
+
return new Response("ok");
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Checklist
|
|
120
|
+
|
|
121
|
+
Before calling `start()`:
|
|
122
|
+
|
|
123
|
+
1. Confirm the function includes `"use workflow"` as its first statement.
|
|
124
|
+
2. Confirm your framework integration is enabled (for Next.js, wrap `next.config.ts` with [`withWorkflow()`](/docs/api-reference/workflow-next/with-workflow)).
|
|
125
|
+
3. Pass the imported workflow function directly to `start()`, not a wrapper callback.
|
|
126
|
+
4. Keep the function in a file that goes through Workflow DevKit's transform step.
|
|
127
|
+
|
|
128
|
+
## Related
|
|
129
|
+
|
|
130
|
+
- [`start()`](/docs/api-reference/workflow-api/start)
|
|
131
|
+
- [`withWorkflow()`](/docs/api-reference/workflow-next/with-workflow)
|
|
132
|
+
- [Next.js Getting Started](/docs/getting-started/next)
|
|
@@ -190,7 +190,7 @@ async function doublePoint(point: Point) {
|
|
|
190
190
|
### Requirements
|
|
191
191
|
|
|
192
192
|
<Callout type="warn">
|
|
193
|
-
|
|
193
|
+
`WORKFLOW_SERIALIZE` and `WORKFLOW_DESERIALIZE` must be implemented as **static** methods on the class. Defining them as instance methods is not supported.
|
|
194
194
|
</Callout>
|
|
195
195
|
|
|
196
196
|
- The data returned by `WORKFLOW_SERIALIZE` must itself be serializable (see [Supported Serializable Types](#supported-serializable-types))
|
|
@@ -205,9 +205,9 @@ The `WORKFLOW_SERIALIZE` and `WORKFLOW_DESERIALIZE` methods run inside the workf
|
|
|
205
205
|
Keep these methods simple and focused on data transformation only.
|
|
206
206
|
</Callout>
|
|
207
207
|
|
|
208
|
-
###
|
|
208
|
+
### Instance Methods as Steps
|
|
209
209
|
|
|
210
|
-
|
|
210
|
+
In practice, many classes have methods that need Node.js APIs, perform network calls, or interact with databases — operations that are not allowed in the `"use workflow"` execution context. You can make these methods workflow-compatible by adding `"use step"` to them. The SWC compiler will strip the method bodies from the workflow bundle and replace them with proxy functions that invoke the method as a step — with full Node.js runtime access. The `this` context (the class instance) is automatically serialized and deserialized across the workflow/step boundary.
|
|
211
211
|
|
|
212
212
|
This requires the class to implement `WORKFLOW_SERIALIZE` and `WORKFLOW_DESERIALIZE`, so that the instance can be passed to the step execution context.
|
|
213
213
|
|
|
@@ -144,7 +144,7 @@ export async function POST(request: Request) {
|
|
|
144
144
|
}
|
|
145
145
|
```
|
|
146
146
|
|
|
147
|
-
Your workflow can
|
|
147
|
+
Your workflow can obtain a writable stream using [`getWritable()`](/docs/api-reference/workflow/get-writable):
|
|
148
148
|
|
|
149
149
|
```typescript lineNumbers
|
|
150
150
|
import { getWritable } from "workflow";
|
|
@@ -44,7 +44,7 @@ Use the `Run` object's `readable` property to consume the stream from your API r
|
|
|
44
44
|
|
|
45
45
|
```typescript title="app/api/stream/route.ts" lineNumbers
|
|
46
46
|
import { start } from "workflow/api";
|
|
47
|
-
import { simpleStreamingWorkflow } from "./workflows/simple";
|
|
47
|
+
import { simpleStreamingWorkflow } from "./workflows/simple-streaming";
|
|
48
48
|
|
|
49
49
|
export async function POST() {
|
|
50
50
|
const run = await start(simpleStreamingWorkflow);
|
|
@@ -9,7 +9,7 @@ related:
|
|
|
9
9
|
- /docs/foundations/workflows-and-steps
|
|
10
10
|
---
|
|
11
11
|
|
|
12
|
-
This guide will walk through setting up your first workflow in an Astro app. Along the way, you'll learn more about the concepts that are fundamental to using the
|
|
12
|
+
This guide will walk through setting up your first workflow in an Astro app. Along the way, you'll learn more about the concepts that are fundamental to using the Workflow SDK in your own projects.
|
|
13
13
|
|
|
14
14
|
---
|
|
15
15
|
|
|
@@ -235,6 +235,23 @@ npx astro add vercel
|
|
|
235
235
|
|
|
236
236
|
Additionally, check the [Deploying](/docs/deploying) section to learn how your workflows can be deployed elsewhere.
|
|
237
237
|
|
|
238
|
+
## Troubleshooting
|
|
239
|
+
|
|
240
|
+
### `start()` says it received an invalid workflow function
|
|
241
|
+
|
|
242
|
+
If you see this error:
|
|
243
|
+
|
|
244
|
+
```
|
|
245
|
+
'start' received an invalid workflow function. Ensure the Workflow Development Kit is configured correctly and the function includes a 'use workflow' directive.
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
Check both of these first:
|
|
249
|
+
|
|
250
|
+
1. The workflow function includes `"use workflow"`.
|
|
251
|
+
2. Your `astro.config.mjs` includes the `workflow()` integration.
|
|
252
|
+
|
|
253
|
+
See [start-invalid-workflow-function](/docs/errors/start-invalid-workflow-function) for full examples and fixes.
|
|
254
|
+
|
|
238
255
|
## Next Steps
|
|
239
256
|
|
|
240
257
|
* Learn more about the [Foundations](/docs/foundations).
|
|
@@ -9,7 +9,7 @@ related:
|
|
|
9
9
|
- /docs/foundations/workflows-and-steps
|
|
10
10
|
---
|
|
11
11
|
|
|
12
|
-
This guide will walk through setting up your first workflow in
|
|
12
|
+
This guide will walk through setting up your first workflow in an Express app. Along the way, you'll learn more about the concepts that are fundamental to using the Workflow SDK in your own projects.
|
|
13
13
|
|
|
14
14
|
---
|
|
15
15
|
|
|
@@ -262,6 +262,23 @@ Workflow SDK apps currently work best when deployed to [Vercel](https://vercel.c
|
|
|
262
262
|
|
|
263
263
|
Check the [Deploying](/docs/deploying) section to learn how your workflows can be deployed elsewhere.
|
|
264
264
|
|
|
265
|
+
## Troubleshooting
|
|
266
|
+
|
|
267
|
+
### `start()` says it received an invalid workflow function
|
|
268
|
+
|
|
269
|
+
If you see this error:
|
|
270
|
+
|
|
271
|
+
```
|
|
272
|
+
'start' received an invalid workflow function. Ensure the Workflow Development Kit is configured correctly and the function includes a 'use workflow' directive.
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
Check both of these first:
|
|
276
|
+
|
|
277
|
+
1. The workflow function includes `"use workflow"`.
|
|
278
|
+
2. Your Nitro config includes the `workflow/nitro` module.
|
|
279
|
+
|
|
280
|
+
See [start-invalid-workflow-function](/docs/errors/start-invalid-workflow-function) for full examples and fixes.
|
|
281
|
+
|
|
265
282
|
## Next Steps
|
|
266
283
|
|
|
267
284
|
- Learn more about the [Foundations](/docs/foundations).
|
|
@@ -9,7 +9,7 @@ related:
|
|
|
9
9
|
- /docs/foundations/workflows-and-steps
|
|
10
10
|
---
|
|
11
11
|
|
|
12
|
-
This guide will walk through setting up your first workflow in a Fastify app. Along the way, you'll learn more about the concepts that are fundamental to using the
|
|
12
|
+
This guide will walk through setting up your first workflow in a Fastify app. Along the way, you'll learn more about the concepts that are fundamental to using the Workflow SDK in your own projects.
|
|
13
13
|
|
|
14
14
|
---
|
|
15
15
|
|
|
@@ -249,6 +249,23 @@ Workflow SDK apps currently work best when deployed to [Vercel](https://vercel.c
|
|
|
249
249
|
|
|
250
250
|
Check the [Deploying](/docs/deploying) section to learn how your workflows can be deployed elsewhere.
|
|
251
251
|
|
|
252
|
+
## Troubleshooting
|
|
253
|
+
|
|
254
|
+
### `start()` says it received an invalid workflow function
|
|
255
|
+
|
|
256
|
+
If you see this error:
|
|
257
|
+
|
|
258
|
+
```
|
|
259
|
+
'start' received an invalid workflow function. Ensure the Workflow Development Kit is configured correctly and the function includes a 'use workflow' directive.
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
Check both of these first:
|
|
263
|
+
|
|
264
|
+
1. The workflow function includes `"use workflow"`.
|
|
265
|
+
2. Your Nitro config includes the `workflow/nitro` module.
|
|
266
|
+
|
|
267
|
+
See [start-invalid-workflow-function](/docs/errors/start-invalid-workflow-function) for full examples and fixes.
|
|
268
|
+
|
|
252
269
|
## Next Steps
|
|
253
270
|
|
|
254
271
|
- Learn more about the [Foundations](/docs/foundations).
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: Hono
|
|
3
|
-
description: This guide will walk through setting up your first workflow in a Hono app. Along the way, you'll learn more about the concepts that are fundamental to using the
|
|
3
|
+
description: This guide will walk through setting up your first workflow in a Hono app. Along the way, you'll learn more about the concepts that are fundamental to using the Workflow SDK in your own projects.
|
|
4
4
|
type: guide
|
|
5
5
|
summary: Set up Workflow SDK in a Hono app.
|
|
6
6
|
prerequisites:
|
|
@@ -244,6 +244,23 @@ Workflow SDK apps currently work best when deployed to [Vercel](https://vercel.c
|
|
|
244
244
|
|
|
245
245
|
Check the [Deploying](/docs/deploying) section to learn how your workflows can be deployed elsewhere.
|
|
246
246
|
|
|
247
|
+
## Troubleshooting
|
|
248
|
+
|
|
249
|
+
### `start()` says it received an invalid workflow function
|
|
250
|
+
|
|
251
|
+
If you see this error:
|
|
252
|
+
|
|
253
|
+
```
|
|
254
|
+
'start' received an invalid workflow function. Ensure the Workflow Development Kit is configured correctly and the function includes a 'use workflow' directive.
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
Check both of these first:
|
|
258
|
+
|
|
259
|
+
1. The workflow function includes `"use workflow"`.
|
|
260
|
+
2. Your Nitro config includes the `workflow/nitro` module.
|
|
261
|
+
|
|
262
|
+
See [start-invalid-workflow-function](/docs/errors/start-invalid-workflow-function) for full examples and fixes.
|
|
263
|
+
|
|
247
264
|
## Next Steps
|
|
248
265
|
|
|
249
266
|
- Learn more about the [Foundations](/docs/foundations).
|
|
@@ -9,7 +9,7 @@ related:
|
|
|
9
9
|
- /docs/foundations/workflows-and-steps
|
|
10
10
|
---
|
|
11
11
|
|
|
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
|
|
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 Workflow SDK in your own projects.
|
|
13
13
|
|
|
14
14
|
<Callout>
|
|
15
15
|
NestJS integration is experimental and not yet supported for deployment to Vercel.
|
|
@@ -41,15 +41,18 @@ cd my-workflow-app
|
|
|
41
41
|
npm i workflow @workflow/nest
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
###
|
|
44
|
+
### Choose Your Module Format
|
|
45
45
|
|
|
46
|
-
NestJS
|
|
46
|
+
NestJS projects using `@workflow/nest` can compile as either ESM or CommonJS. Choose the setup that matches your SWC output instead of assuming ESM is required.
|
|
47
|
+
|
|
48
|
+
#### ESM (default)
|
|
49
|
+
|
|
50
|
+
Use this when your NestJS project is configured as an ES module app.
|
|
47
51
|
|
|
48
52
|
```json title="package.json" lineNumbers
|
|
49
53
|
{
|
|
50
54
|
"name": "my-workflow-app",
|
|
51
|
-
"type": "module"
|
|
52
|
-
// ... rest of your config
|
|
55
|
+
"type": "module"
|
|
53
56
|
}
|
|
54
57
|
```
|
|
55
58
|
|
|
@@ -57,6 +60,29 @@ NestJS with SWC uses ES modules. Add `"type": "module"` to your `package.json`:
|
|
|
57
60
|
When using ESM with NestJS, local imports must include the `.js` extension (e.g., `import { AppModule } from './app.module.js'`). This applies even though your source files are `.ts`.
|
|
58
61
|
</Callout>
|
|
59
62
|
|
|
63
|
+
#### CommonJS
|
|
64
|
+
|
|
65
|
+
Use this when your NestJS project compiles CommonJS via SWC.
|
|
66
|
+
|
|
67
|
+
```typescript title="src/app.module.ts" lineNumbers
|
|
68
|
+
import { Module } from '@nestjs/common';
|
|
69
|
+
import { WorkflowModule } from '@workflow/nest';
|
|
70
|
+
|
|
71
|
+
@Module({
|
|
72
|
+
imports: [
|
|
73
|
+
WorkflowModule.forRoot({
|
|
74
|
+
moduleType: 'commonjs',
|
|
75
|
+
distDir: 'dist',
|
|
76
|
+
}),
|
|
77
|
+
],
|
|
78
|
+
})
|
|
79
|
+
export class AppModule {}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
<Callout type="info">
|
|
83
|
+
`distDir` should match the directory where NestJS writes compiled `.js` files. In the default SWC setup, that is `dist`.
|
|
84
|
+
</Callout>
|
|
85
|
+
|
|
60
86
|
### Configure NestJS to use SWC
|
|
61
87
|
|
|
62
88
|
NestJS supports SWC as an alternative compiler for faster builds. The Workflow SDK uses an SWC plugin to transform workflow files.
|
|
@@ -141,7 +167,7 @@ To enable helpful hints in your IDE, setup the workflow plugin in `tsconfig.json
|
|
|
141
167
|
|
|
142
168
|
## Import the WorkflowModule
|
|
143
169
|
|
|
144
|
-
In your `app.module.ts`, import the `WorkflowModule
|
|
170
|
+
In your `app.module.ts`, import the `WorkflowModule` and keep the module format you chose above.
|
|
145
171
|
|
|
146
172
|
```typescript title="src/app.module.ts" lineNumbers
|
|
147
173
|
import { Module } from '@nestjs/common';
|
|
@@ -157,6 +183,20 @@ import { AppService } from './app.service.js';
|
|
|
157
183
|
export class AppModule {}
|
|
158
184
|
```
|
|
159
185
|
|
|
186
|
+
<Callout type="info">
|
|
187
|
+
If you chose CommonJS above, keep the CommonJS options here as well:
|
|
188
|
+
|
|
189
|
+
{/* @skip-typecheck - config snippet, full import shown above */}
|
|
190
|
+
```typescript
|
|
191
|
+
WorkflowModule.forRoot({
|
|
192
|
+
moduleType: 'commonjs',
|
|
193
|
+
distDir: 'dist',
|
|
194
|
+
})
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
The `.js` local import specifiers in this example are the ESM form.
|
|
198
|
+
</Callout>
|
|
199
|
+
|
|
160
200
|
The `WorkflowModule` handles workflow bundle building and provides HTTP routing for workflow execution at `.well-known/workflow/v1/`.
|
|
161
201
|
|
|
162
202
|
</Step>
|
|
@@ -171,6 +211,15 @@ Create a new file for our first workflow in the `src/workflows` directory:
|
|
|
171
211
|
Workflow files must be inside the `src/` directory so they get compiled with the SWC plugin that enables the `start()` function to work correctly.
|
|
172
212
|
</Callout>
|
|
173
213
|
|
|
214
|
+
<Callout type="info">
|
|
215
|
+
If `start()` says it received an invalid workflow function, check both of these first:
|
|
216
|
+
|
|
217
|
+
1. The workflow function includes `"use workflow"`.
|
|
218
|
+
2. The workflow file lives inside `src/` so NestJS compiles it with the SWC plugin.
|
|
219
|
+
|
|
220
|
+
See [start-invalid-workflow-function](/docs/errors/start-invalid-workflow-function) for full examples and fixes.
|
|
221
|
+
</Callout>
|
|
222
|
+
|
|
174
223
|
```typescript title="src/workflows/user-signup.ts" lineNumbers
|
|
175
224
|
import { sleep } from "workflow";
|
|
176
225
|
|
|
@@ -269,6 +318,10 @@ export class AppController {
|
|
|
269
318
|
}
|
|
270
319
|
```
|
|
271
320
|
|
|
321
|
+
<Callout type="info">
|
|
322
|
+
If you chose CommonJS above, use the same local import style as the rest of your NestJS app here too. The `.js` extension shown in this example is the ESM form.
|
|
323
|
+
</Callout>
|
|
324
|
+
|
|
272
325
|
This creates a `POST` endpoint at `/signup` that will trigger your workflow.
|
|
273
326
|
|
|
274
327
|
</Step>
|
|
@@ -324,9 +377,34 @@ WorkflowModule.forRoot({
|
|
|
324
377
|
|
|
325
378
|
// Skip building in production when bundles are pre-built
|
|
326
379
|
skipBuild: false,
|
|
380
|
+
|
|
381
|
+
// SWC module type: 'es6' (default) or 'commonjs'
|
|
382
|
+
// Set to 'commonjs' if your NestJS project compiles to CJS via SWC
|
|
383
|
+
moduleType: 'es6',
|
|
384
|
+
|
|
385
|
+
// Directory where NestJS compiles .ts to .js (default: 'dist')
|
|
386
|
+
// Only used when moduleType is 'commonjs'
|
|
387
|
+
// Should match the outDir in your tsconfig.json
|
|
388
|
+
distDir: 'dist',
|
|
327
389
|
});
|
|
328
390
|
```
|
|
329
391
|
|
|
392
|
+
## Troubleshooting
|
|
393
|
+
|
|
394
|
+
### `start()` says it received an invalid workflow function
|
|
395
|
+
|
|
396
|
+
If you see this error:
|
|
397
|
+
|
|
398
|
+
```
|
|
399
|
+
'start' received an invalid workflow function. Ensure the Workflow Development Kit is configured correctly and the function includes a 'use workflow' directive.
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
Check both of these first:
|
|
403
|
+
|
|
404
|
+
1. The workflow function includes `"use workflow"`.
|
|
405
|
+
2. Your NestJS app imports and registers the `WorkflowModule`.
|
|
406
|
+
|
|
407
|
+
See [start-invalid-workflow-function](/docs/errors/start-invalid-workflow-function) for full examples and fixes.
|
|
330
408
|
## Next Steps
|
|
331
409
|
|
|
332
410
|
- Learn more about the [Foundations](/docs/foundations).
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: Next.js
|
|
3
|
-
description: This guide will walk through setting up your first workflow in a Next.js app. Along the way, you'll learn more about the concepts that are fundamental to using the
|
|
3
|
+
description: This guide will walk through setting up your first workflow in a Next.js app. Along the way, you'll learn more about the concepts that are fundamental to using the Workflow SDK in your own projects.
|
|
4
4
|
type: guide
|
|
5
5
|
summary: Set up Workflow SDK in a Next.js app.
|
|
6
6
|
prerequisites:
|
|
@@ -275,12 +275,27 @@ Build error occurred
|
|
|
275
275
|
Error: Cannot find module 'next/dist/lib/server-external-packages.json'
|
|
276
276
|
```
|
|
277
277
|
|
|
278
|
-
Upgrade to `workflow@4.0
|
|
278
|
+
Upgrade to `workflow@4.2.0` or later:
|
|
279
279
|
|
|
280
280
|
```package-install
|
|
281
281
|
workflow@latest
|
|
282
282
|
```
|
|
283
283
|
|
|
284
|
+
### `start()` says it received an invalid workflow function
|
|
285
|
+
|
|
286
|
+
If you see this error:
|
|
287
|
+
|
|
288
|
+
```
|
|
289
|
+
'start' received an invalid workflow function. Ensure the Workflow Development Kit is configured correctly and the function includes a 'use workflow' directive.
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
Check both of these first:
|
|
293
|
+
|
|
294
|
+
1. The workflow function includes `"use workflow"`.
|
|
295
|
+
2. Your `next.config.ts` is wrapped with [`withWorkflow()`](/docs/api-reference/workflow-next/with-workflow).
|
|
296
|
+
|
|
297
|
+
See [start-invalid-workflow-function](/docs/errors/start-invalid-workflow-function) for full examples and fixes.
|
|
298
|
+
|
|
284
299
|
## Next Steps
|
|
285
300
|
|
|
286
301
|
* Learn more about the [Foundations](/docs/foundations).
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: Nitro
|
|
3
|
-
description: This guide will walk through setting up your first workflow in a Nitro v3 project. Along the way, you'll learn more about the concepts that are fundamental to using the
|
|
3
|
+
description: This guide will walk through setting up your first workflow in a Nitro v3 project. Along the way, you'll learn more about the concepts that are fundamental to using the Workflow SDK in your own projects.
|
|
4
4
|
type: guide
|
|
5
5
|
summary: Set up Workflow SDK in a Nitro app.
|
|
6
6
|
prerequisites:
|
|
@@ -228,6 +228,23 @@ Workflow SDK apps currently work best when deployed to [Vercel](https://vercel.c
|
|
|
228
228
|
|
|
229
229
|
Check the [Deploying](/docs/deploying) section to learn how your workflows can be deployed elsewhere.
|
|
230
230
|
|
|
231
|
+
## Troubleshooting
|
|
232
|
+
|
|
233
|
+
### `start()` says it received an invalid workflow function
|
|
234
|
+
|
|
235
|
+
If you see this error:
|
|
236
|
+
|
|
237
|
+
```
|
|
238
|
+
'start' received an invalid workflow function. Ensure the Workflow Development Kit is configured correctly and the function includes a 'use workflow' directive.
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
Check both of these first:
|
|
242
|
+
|
|
243
|
+
1. The workflow function includes `"use workflow"`.
|
|
244
|
+
2. Your Nitro config includes the `workflow/nitro` module.
|
|
245
|
+
|
|
246
|
+
See [start-invalid-workflow-function](/docs/errors/start-invalid-workflow-function) for full examples and fixes.
|
|
247
|
+
|
|
231
248
|
## Next Steps
|
|
232
249
|
|
|
233
250
|
- Learn more about the [Foundations](/docs/foundations).
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: Nuxt
|
|
3
|
-
description: This guide will walk through setting up your first workflow in a Nuxt app. Along the way, you'll learn more about the concepts that are fundamental to using the
|
|
3
|
+
description: This guide will walk through setting up your first workflow in a Nuxt app. Along the way, you'll learn more about the concepts that are fundamental to using the Workflow SDK in your own projects.
|
|
4
4
|
type: guide
|
|
5
5
|
summary: Set up Workflow SDK in a Nuxt app.
|
|
6
6
|
prerequisites:
|
|
@@ -229,6 +229,23 @@ Workflow SDK apps currently work best when deployed to [Vercel](https://vercel.c
|
|
|
229
229
|
|
|
230
230
|
Check the [Deploying](/docs/deploying) section to learn how your workflows can be deployed elsewhere.
|
|
231
231
|
|
|
232
|
+
## Troubleshooting
|
|
233
|
+
|
|
234
|
+
### `start()` says it received an invalid workflow function
|
|
235
|
+
|
|
236
|
+
If you see this error:
|
|
237
|
+
|
|
238
|
+
```
|
|
239
|
+
'start' received an invalid workflow function. Ensure the Workflow Development Kit is configured correctly and the function includes a 'use workflow' directive.
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
Check both of these first:
|
|
243
|
+
|
|
244
|
+
1. The workflow function includes `"use workflow"`.
|
|
245
|
+
2. Your `nuxt.config.ts` includes the `workflow/nuxt` module.
|
|
246
|
+
|
|
247
|
+
See [start-invalid-workflow-function](/docs/errors/start-invalid-workflow-function) for full examples and fixes.
|
|
248
|
+
|
|
232
249
|
## Next Steps
|
|
233
250
|
|
|
234
251
|
- Learn more about the [Foundations](/docs/foundations).
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: SvelteKit
|
|
3
|
-
description: This guide will walk through setting up your first workflow in a SvelteKit app. Along the way, you'll learn more about the concepts that are fundamental to using the
|
|
3
|
+
description: This guide will walk through setting up your first workflow in a SvelteKit app. Along the way, you'll learn more about the concepts that are fundamental to using the Workflow SDK in your own projects.
|
|
4
4
|
type: guide
|
|
5
5
|
summary: Set up Workflow SDK in a SvelteKit app.
|
|
6
6
|
prerequisites:
|
|
@@ -228,6 +228,23 @@ Workflow SDK apps currently work best when deployed to [Vercel](https://vercel.c
|
|
|
228
228
|
|
|
229
229
|
Check the [Deploying](/docs/deploying) section to learn how your workflows can be deployed elsewhere.
|
|
230
230
|
|
|
231
|
+
## Troubleshooting
|
|
232
|
+
|
|
233
|
+
### `start()` says it received an invalid workflow function
|
|
234
|
+
|
|
235
|
+
If you see this error:
|
|
236
|
+
|
|
237
|
+
```
|
|
238
|
+
'start' received an invalid workflow function. Ensure the Workflow Development Kit is configured correctly and the function includes a 'use workflow' directive.
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
Check both of these first:
|
|
242
|
+
|
|
243
|
+
1. The workflow function includes `"use workflow"`.
|
|
244
|
+
2. Your `vite.config.ts` includes the `workflow/sveltekit` plugin.
|
|
245
|
+
|
|
246
|
+
See [start-invalid-workflow-function](/docs/errors/start-invalid-workflow-function) for full examples and fixes.
|
|
247
|
+
|
|
231
248
|
## Next Steps
|
|
232
249
|
|
|
233
250
|
* Learn more about the [Foundations](/docs/foundations).
|