workflow 5.0.0-beta.43 → 5.0.0-beta.44
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 +6 -4
- package/dist/internal/builtins.d.ts +4 -4
- package/dist/internal/builtins.js +6 -6
- package/docs/ai/chat-session-modeling.mdx +23 -24
- package/docs/ai/defining-tools.mdx +5 -6
- package/docs/ai/human-in-the-loop.mdx +11 -11
- package/docs/ai/index.mdx +20 -20
- package/docs/ai/message-queueing.mdx +6 -6
- package/docs/ai/meta.json +1 -0
- package/docs/ai/resumable-streams.mdx +28 -28
- package/docs/ai/sleep-and-delays.mdx +9 -9
- package/docs/ai/streaming-updates-from-tools.mdx +4 -4
- package/docs/api-reference/vitest/index.mdx +8 -8
- package/docs/api-reference/workflow/create-hook.mdx +15 -15
- package/docs/api-reference/workflow/create-webhook.mdx +15 -15
- package/docs/api-reference/workflow/define-hook.mdx +10 -10
- package/docs/api-reference/workflow/fatal-error.mdx +2 -2
- package/docs/api-reference/workflow/fetch.mdx +7 -7
- package/docs/api-reference/workflow/get-step-metadata.mdx +2 -2
- package/docs/api-reference/workflow/get-workflow-metadata.mdx +3 -3
- package/docs/api-reference/workflow/get-writable.mdx +7 -7
- package/docs/api-reference/workflow/index.mdx +1 -1
- package/docs/api-reference/workflow/retryable-error.mdx +1 -1
- package/docs/api-reference/workflow/set-attributes.mdx +2 -2
- package/docs/api-reference/workflow/sleep.mdx +3 -3
- package/docs/api-reference/workflow-ai/durable-agent.mdx +42 -42
- package/docs/api-reference/workflow-ai/index.mdx +3 -3
- package/docs/api-reference/workflow-ai/workflow-chat-transport.mdx +28 -28
- package/docs/api-reference/workflow-api/get-hook-by-token.mdx +11 -11
- package/docs/api-reference/workflow-api/get-run.mdx +10 -10
- package/docs/api-reference/workflow-api/index.mdx +2 -4
- package/docs/api-reference/workflow-api/resume-hook.mdx +14 -14
- package/docs/api-reference/workflow-api/resume-webhook.mdx +3 -3
- package/docs/api-reference/workflow-api/start.mdx +16 -15
- package/docs/api-reference/workflow-astro/workflow.mdx +3 -3
- package/docs/api-reference/workflow-errors/entity-conflict-error.mdx +4 -4
- package/docs/api-reference/workflow-errors/hook-conflict-error.mdx +4 -4
- package/docs/api-reference/workflow-errors/hook-not-found-error.mdx +8 -8
- package/docs/api-reference/workflow-errors/index.mdx +6 -6
- package/docs/api-reference/workflow-errors/precondition-failed-error.mdx +9 -9
- package/docs/api-reference/workflow-errors/run-expired-error.mdx +2 -2
- package/docs/api-reference/workflow-errors/run-not-supported-error.mdx +4 -4
- package/docs/api-reference/workflow-errors/step-not-registered-error.mdx +5 -5
- package/docs/api-reference/workflow-errors/throttle-error.mdx +2 -2
- package/docs/api-reference/workflow-errors/too-early-error.mdx +2 -2
- package/docs/api-reference/workflow-errors/workflow-error.mdx +4 -4
- package/docs/api-reference/workflow-errors/workflow-not-registered-error.mdx +5 -6
- package/docs/api-reference/workflow-errors/workflow-run-cancelled-error.mdx +6 -6
- package/docs/api-reference/workflow-errors/workflow-run-failed-error.mdx +5 -5
- package/docs/api-reference/workflow-errors/workflow-run-not-completed-error.mdx +4 -4
- package/docs/api-reference/workflow-errors/workflow-run-not-found-error.mdx +4 -4
- package/docs/api-reference/workflow-errors/workflow-runtime-error.mdx +2 -2
- package/docs/api-reference/workflow-errors/workflow-world-error.mdx +8 -8
- package/docs/api-reference/workflow-globals.mdx +12 -11
- package/docs/api-reference/workflow-nest/configure-workflow-controller.mdx +2 -2
- package/docs/api-reference/workflow-nest/nest-local-builder.mdx +4 -4
- package/docs/api-reference/workflow-nest/workflow-controller.mdx +1 -1
- package/docs/api-reference/workflow-nest/workflow-module.mdx +4 -4
- package/docs/api-reference/workflow-next/with-workflow.mdx +16 -16
- package/docs/api-reference/workflow-nitro/index.mdx +6 -6
- package/docs/api-reference/workflow-nuxt/index.mdx +4 -4
- package/docs/api-reference/workflow-observability/hydrate-data.mdx +5 -5
- package/docs/api-reference/workflow-observability/hydrate-resource-io.mdx +4 -4
- package/docs/api-reference/workflow-observability/index.mdx +6 -8
- package/docs/api-reference/workflow-observability/observability-revivers.mdx +2 -2
- package/docs/api-reference/workflow-observability/parse-class-name.mdx +3 -3
- package/docs/api-reference/workflow-observability/parse-step-name.mdx +4 -4
- package/docs/api-reference/workflow-observability/parse-workflow-name.mdx +4 -4
- package/docs/api-reference/workflow-runtime/create-world.mdx +8 -8
- package/docs/api-reference/workflow-runtime/get-world-handlers.mdx +6 -6
- package/docs/api-reference/workflow-runtime/get-world.mdx +4 -4
- package/docs/api-reference/workflow-runtime/health-check.mdx +1 -1
- package/docs/api-reference/workflow-runtime/index.mdx +2 -4
- package/docs/api-reference/workflow-runtime/set-world.mdx +15 -13
- package/docs/api-reference/workflow-runtime/workflow-entrypoint.mdx +6 -5
- package/docs/api-reference/workflow-runtime/world/analytics.mdx +9 -9
- package/docs/api-reference/workflow-runtime/world/index.mdx +5 -3
- package/docs/api-reference/workflow-runtime/world/queue.mdx +11 -11
- package/docs/api-reference/workflow-runtime/world/storage.mdx +62 -28
- package/docs/api-reference/workflow-runtime/world/streams.mdx +7 -7
- package/docs/api-reference/workflow-serde/index.mdx +1 -1
- package/docs/api-reference/workflow-serde/workflow-deserialize.mdx +2 -2
- package/docs/api-reference/workflow-serde/workflow-serialize.mdx +7 -7
- package/docs/api-reference/workflow-sveltekit/workflow-plugin.mdx +3 -3
- package/docs/api-reference/workflow-vite/workflow.mdx +5 -5
- package/docs/changelog/attributes-mvp.mdx +39 -39
- package/docs/changelog/batched-event-writes.mdx +12 -12
- package/docs/changelog/eager-processing.mdx +63 -63
- package/docs/changelog/index.mdx +3 -3
- package/docs/changelog/lazy-event-creation.md +27 -27
- package/docs/changelog/resilient-resume.mdx +5 -5
- package/docs/changelog/resilient-start.mdx +14 -14
- package/docs/changelog/step-message-ownership.mdx +47 -47
- package/docs/changelog/turbo-mode.md +20 -20
- package/docs/comparisons/index.mdx +13 -13
- package/docs/comparisons/workflow-sdk-vs-aws-agentcore.mdx +15 -15
- package/docs/comparisons/workflow-sdk-vs-aws-step-functions.mdx +12 -12
- package/docs/comparisons/workflow-sdk-vs-cloudflare-workflows.mdx +11 -11
- package/docs/comparisons/workflow-sdk-vs-inngest.mdx +19 -19
- package/docs/comparisons/workflow-sdk-vs-temporal.mdx +23 -23
- package/docs/comparisons/workflow-sdk-vs-trigger-dev.mdx +18 -17
- package/docs/configuration/build-and-diagnostics.mdx +5 -5
- package/docs/configuration/cli-and-web-ui.mdx +4 -4
- package/docs/configuration/runtime-tuning.mdx +86 -23
- package/docs/configuration/worlds.mdx +28 -14
- package/docs/cookbook/advanced/child-workflows.mdx +25 -25
- package/docs/cookbook/advanced/publishing-libraries.mdx +40 -40
- package/docs/cookbook/advanced/serializable-steps.mdx +21 -21
- package/docs/cookbook/advanced/upgrading-workflows.mdx +31 -31
- package/docs/cookbook/agent-patterns/agent-cancellation.mdx +20 -20
- package/docs/cookbook/agent-patterns/human-in-the-loop.mdx +22 -22
- package/docs/cookbook/common-patterns/batching.mdx +14 -14
- package/docs/cookbook/common-patterns/idempotency.mdx +9 -9
- package/docs/cookbook/common-patterns/rate-limiting.mdx +3 -3
- package/docs/cookbook/common-patterns/saga.mdx +19 -19
- package/docs/cookbook/common-patterns/scheduling.mdx +23 -23
- package/docs/cookbook/common-patterns/sequential-and-parallel.mdx +26 -26
- package/docs/cookbook/common-patterns/timeouts.mdx +23 -23
- package/docs/cookbook/common-patterns/webhooks.mdx +6 -6
- package/docs/cookbook/common-patterns/workflow-composition.mdx +19 -19
- package/docs/cookbook/index.mdx +22 -22
- package/docs/cookbook/integrations/ai-sdk.mdx +43 -41
- package/docs/cookbook/integrations/chat-sdk.mdx +34 -34
- package/docs/cookbook/integrations/sandbox.mdx +46 -46
- package/docs/deploying.mdx +15 -15
- package/docs/errors/abort-signal-timeout-in-workflow.mdx +12 -12
- package/docs/errors/corrupted-event-log.mdx +11 -11
- package/docs/errors/deployment-mismatch.mdx +14 -14
- package/docs/errors/fetch-in-workflow.mdx +8 -8
- package/docs/errors/hook-conflict.mdx +11 -11
- package/docs/errors/index.mdx +1 -1
- package/docs/errors/node-js-module-in-workflow.mdx +5 -5
- package/docs/errors/replay-divergence.mdx +2 -2
- package/docs/errors/runtime-decryption-failed.mdx +12 -12
- package/docs/errors/serialization-failed.mdx +40 -12
- package/docs/errors/start-invalid-workflow-function.mdx +5 -5
- package/docs/errors/step-executed-multiple-times.mdx +2 -2
- package/docs/errors/step-not-registered.mdx +5 -5
- package/docs/errors/timeout-in-workflow.mdx +8 -8
- package/docs/errors/webhook-invalid-respond-with-value.mdx +18 -18
- package/docs/errors/webhook-response-not-sent.mdx +16 -16
- package/docs/errors/workflow-not-registered.mdx +5 -5
- package/docs/foundations/cancellation.mdx +31 -31
- package/docs/foundations/errors-and-retries.mdx +42 -11
- package/docs/foundations/hooks.mdx +35 -35
- package/docs/foundations/idempotency.mdx +9 -9
- package/docs/foundations/serialization.mdx +21 -22
- package/docs/foundations/starting-workflows.mdx +36 -37
- package/docs/foundations/streaming.mdx +46 -41
- package/docs/foundations/versioning.mdx +3 -3
- package/docs/foundations/workflows-and-steps.mdx +9 -9
- package/docs/getting-started/astro.mdx +16 -16
- package/docs/getting-started/express.mdx +8 -8
- package/docs/getting-started/fastify.mdx +8 -8
- package/docs/getting-started/hono.mdx +8 -8
- package/docs/getting-started/nestjs.mdx +18 -17
- package/docs/getting-started/next.mdx +11 -11
- package/docs/getting-started/nitro.mdx +16 -16
- package/docs/getting-started/nuxt.mdx +8 -8
- package/docs/getting-started/python.mdx +4 -4
- package/docs/getting-started/react-router/v7.mdx +1 -1
- package/docs/getting-started/react-router/v8.mdx +1 -1
- package/docs/getting-started/sveltekit.mdx +14 -14
- package/docs/getting-started/tanstack-start.mdx +12 -12
- package/docs/getting-started/vite.mdx +8 -8
- package/docs/how-it-works/cancellation.mdx +62 -62
- package/docs/how-it-works/code-transform.mdx +66 -54
- package/docs/how-it-works/encryption.mdx +25 -21
- package/docs/how-it-works/event-sourcing.mdx +53 -35
- package/docs/how-it-works/framework-integrations.mdx +12 -12
- package/docs/how-it-works/understanding-directives.mdx +21 -21
- package/docs/internal/index.mdx +6 -6
- package/docs/internal/nitro-native-build.mdx +2 -2
- package/docs/internal/nitro-web-ui.mdx +4 -4
- package/docs/internal/serializable-abort-controller.mdx +7 -7
- package/docs/observability/attributes.mdx +3 -3
- package/docs/observability/index.mdx +14 -10
- package/docs/observability/tracing.mdx +10 -10
- package/docs/testing/index.mdx +33 -33
- package/docs/testing/server-based.mdx +10 -10
- package/docs/whats-new.mdx +185 -0
- package/package.json +12 -12
|
@@ -14,18 +14,18 @@ import { File, Folder, Files } from "fumadocs-ui/components/files";
|
|
|
14
14
|
|
|
15
15
|
Workflows (a.k.a. *durable functions*) are a programming model for building long-running, stateful application logic that can maintain its execution state across restarts, failures, or user events. Unlike traditional serverless functions that lose all state when they terminate, workflows persist their progress and can resume exactly where they left off.
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
Workflows let you model complex multi-step processes in code. To do this, we introduce two fundamental entities:
|
|
18
18
|
|
|
19
19
|
1. **Workflow Functions**: Functions that orchestrate/organize steps
|
|
20
20
|
2. **Step Functions**: Functions that carry out the actual work
|
|
21
21
|
|
|
22
|
-
## Workflow
|
|
22
|
+
## Workflow functions
|
|
23
23
|
|
|
24
24
|
*Directive: `"use workflow"`*
|
|
25
25
|
|
|
26
26
|
Workflow functions define the entrypoint of a workflow and organize how step functions are called. This type of function does not have access to the Node.js runtime, and usable `npm` packages are limited.
|
|
27
27
|
|
|
28
|
-
Although this may seem limiting initially, this feature is
|
|
28
|
+
Although this may seem limiting initially, this feature is required to suspend and accurately resume workflow execution.
|
|
29
29
|
|
|
30
30
|
It helps to think of the workflow function less like a full JavaScript runtime and more like "stitching together" various steps using conditionals, loops, try/catch handlers, `Promise.all`, and other language primitives.
|
|
31
31
|
|
|
@@ -51,7 +51,7 @@ Determinism in the workflow is required to resume the workflow from a suspension
|
|
|
51
51
|
|
|
52
52
|
The sandboxed environment that workflows run in already ensures determinism. For instance, `Math.random` and `Date` constructors are fixed in workflow runs, so you are safe to use them, and the framework ensures that the values don't change across replays.
|
|
53
53
|
|
|
54
|
-
## Step
|
|
54
|
+
## Step functions
|
|
55
55
|
|
|
56
56
|
*Directive: `"use step"`*
|
|
57
57
|
|
|
@@ -115,10 +115,10 @@ export async function POST() {
|
|
|
115
115
|
```
|
|
116
116
|
|
|
117
117
|
<Callout type="info">
|
|
118
|
-
|
|
118
|
+
Calling a step function outside a workflow function provides neither retry semantics nor observability. Additionally, certain workflow-specific functions like [`getStepMetadata()`](/docs/api-reference/workflow/get-step-metadata) will throw an error when used inside a step that's called outside a workflow.
|
|
119
119
|
</Callout>
|
|
120
120
|
|
|
121
|
-
### Suspension and
|
|
121
|
+
### Suspension and resumption
|
|
122
122
|
|
|
123
123
|
Workflow functions have the ability to automatically suspend while they wait on asynchronous work. While suspended, the workflow's state is stored via the [event log](/docs/how-it-works/event-sourcing) and no compute resources are used until the workflow resumes execution.
|
|
124
124
|
|
|
@@ -126,7 +126,7 @@ Workflow functions have the ability to automatically suspend while they wait on
|
|
|
126
126
|
|
|
127
127
|
There are multiple ways a workflow can suspend:
|
|
128
128
|
|
|
129
|
-
- Waiting on a step function: the workflow yields while the step runs in the step
|
|
129
|
+
- Waiting on a step function: the workflow yields while the step body runs. The step usually executes inline in the same invocation; when the invocation's inline budget is exhausted or its timeout approaches, the step is handed to the queue and the workflow resumes in a later invocation.
|
|
130
130
|
- Using `sleep()` to pause for some fixed duration.
|
|
131
131
|
- Awaiting on a promise returned by [`createWebhook()`](/docs/api-reference/workflow/create-webhook), which resumes the workflow when an external system passes data into the workflow.
|
|
132
132
|
|
|
@@ -150,9 +150,9 @@ export async function documentReviewProcess(userId: string) {
|
|
|
150
150
|
}
|
|
151
151
|
```
|
|
152
152
|
|
|
153
|
-
## Writing
|
|
153
|
+
## Writing workflows
|
|
154
154
|
|
|
155
|
-
### Basic
|
|
155
|
+
### Basic structure
|
|
156
156
|
|
|
157
157
|
The simplest workflow consists of a workflow function and one or more step functions.
|
|
158
158
|
|
|
@@ -13,16 +13,16 @@ related:
|
|
|
13
13
|
text="In this Astro app, run `npm i workflow`. In `astro.config.mjs`, import `workflow` from `workflow/astro` and add `integrations: [workflow()]`. Add the TypeScript plugin `{ "name": "workflow" }` to `tsconfig.json` if TypeScript is used. Create `src/workflows/user-signup.ts` exporting `handleUserSignup(email)` with `"use workflow"`, `sleep` from `workflow`, and `"use step"` helpers. Add `src/pages/api/signup.ts` exporting `POST: APIRoute` that reads `{ email }`, calls `start(handleUserSignup, [email])` from `workflow/api`, returns `Response.json`, and sets `prerender = false`. Run `npm run dev`, call `curl -X POST --json '{"email":"hello@example.com"}' http://localhost:4321/api/signup`, and inspect with `npx workflow inspect runs`."
|
|
14
14
|
/>
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
Set up your first durable workflow in an Astro app and learn the core Workflow SDK concepts.
|
|
17
17
|
|
|
18
18
|
---
|
|
19
19
|
|
|
20
20
|
<Steps>
|
|
21
21
|
|
|
22
22
|
<Step>
|
|
23
|
-
## Create
|
|
23
|
+
## Create your Astro project
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
Create an Astro project in a new directory named `my-workflow-app`:
|
|
26
26
|
|
|
27
27
|
```bash
|
|
28
28
|
npm create astro@latest my-workflow-app -- --template minimal --install --yes
|
|
@@ -59,16 +59,16 @@ export default defineConfig({
|
|
|
59
59
|
|
|
60
60
|
| Option | Type | Default | Description |
|
|
61
61
|
| --- | --- | --- | --- |
|
|
62
|
-
| `sourcemap` | `boolean \| 'inline' \| 'linked' \| 'external' \| 'both'` | `'inline'` (dev) / `false` (prod) | Controls source maps on generated workflow bundles. Accepts the same values as esbuild's `sourcemap` option. Defaults to `'inline'` in development and `false` in production (smaller function bundles
|
|
62
|
+
| `sourcemap` | `boolean \| 'inline' \| 'linked' \| 'external' \| 'both'` | `'inline'` (dev) / `false` (prod) | Controls source maps on generated workflow bundles. Accepts the same values as esbuild's `sourcemap` option. Defaults to `'inline'` in development and `false` in production (smaller function bundles, which helps stay under the Vercel 250 MB function size limit). Set it explicitly, or use the `WORKFLOW_SOURCEMAP` environment variable, to override in either environment. |
|
|
63
63
|
|
|
64
64
|
<Accordion type="single" collapsible>
|
|
65
65
|
<AccordionItem value="typescript-intellisense" className="[&_h3]:my-0">
|
|
66
66
|
<AccordionTrigger className="text-sm">
|
|
67
|
-
###
|
|
67
|
+
### Set up IntelliSense for TypeScript (optional)
|
|
68
68
|
</AccordionTrigger>
|
|
69
69
|
<AccordionContent className="[&_p]:my-2">
|
|
70
70
|
|
|
71
|
-
To enable helpful hints in your IDE,
|
|
71
|
+
To enable helpful hints in your IDE, set up the workflow plugin in `tsconfig.json`:
|
|
72
72
|
|
|
73
73
|
```json title="tsconfig.json" lineNumbers
|
|
74
74
|
{
|
|
@@ -91,7 +91,7 @@ To enable helpful hints in your IDE, setup the workflow plugin in `tsconfig.json
|
|
|
91
91
|
|
|
92
92
|
<Step>
|
|
93
93
|
|
|
94
|
-
## Create
|
|
94
|
+
## Create your first workflow
|
|
95
95
|
|
|
96
96
|
Create a new file for our first workflow:
|
|
97
97
|
|
|
@@ -112,14 +112,14 @@ export async function handleUserSignup(email: string) {
|
|
|
112
112
|
|
|
113
113
|
```
|
|
114
114
|
|
|
115
|
-
We'll fill in those functions next, but
|
|
115
|
+
We'll fill in those functions next, but first review this code:
|
|
116
116
|
|
|
117
117
|
* We define a **workflow** function with the directive `"use workflow"`. Think of the workflow function as the _orchestrator_ of individual **steps**.
|
|
118
118
|
* The Workflow SDK's `sleep` function allows us to suspend execution of the workflow without using up any resources. A sleep can be a few seconds, hours, days, or even months long.
|
|
119
119
|
|
|
120
|
-
## Create
|
|
120
|
+
## Create your workflow steps
|
|
121
121
|
|
|
122
|
-
|
|
122
|
+
Define the missing functions.
|
|
123
123
|
|
|
124
124
|
```typescript title="src/workflows/user-signup.ts" lineNumbers
|
|
125
125
|
import { FatalError } from "workflow"
|
|
@@ -172,7 +172,7 @@ We'll dive deeper into workflows, steps, and other ways to suspend or handle eve
|
|
|
172
172
|
|
|
173
173
|
<Step>
|
|
174
174
|
|
|
175
|
-
## Create
|
|
175
|
+
## Create your route handler
|
|
176
176
|
|
|
177
177
|
To invoke your new workflow, we'll have to add your workflow to a `POST` API route handler, `src/pages/api/signup.ts` with the following code:
|
|
178
178
|
|
|
@@ -204,7 +204,7 @@ Workflows can be triggered from API routes or any server-side code.
|
|
|
204
204
|
|
|
205
205
|
</Steps>
|
|
206
206
|
|
|
207
|
-
## Run in
|
|
207
|
+
## Run in development
|
|
208
208
|
|
|
209
209
|
To start your development server, run the following command in your terminal in the Vite root directory:
|
|
210
210
|
|
|
@@ -231,9 +231,9 @@ npx workflow inspect runs
|
|
|
231
231
|
|
|
232
232
|
---
|
|
233
233
|
|
|
234
|
-
## Deploying to
|
|
234
|
+
## Deploying to production
|
|
235
235
|
|
|
236
|
-
Workflow SDK apps currently work best when deployed to [Vercel](https://vercel.com/home) and
|
|
236
|
+
Workflow SDK apps currently work best when deployed to [Vercel](https://vercel.com/home) and need no special configuration.
|
|
237
237
|
|
|
238
238
|
<FluidComputeCallout />
|
|
239
239
|
|
|
@@ -251,7 +251,7 @@ Additionally, check the [Deploying](/docs/deploying) section to learn how your w
|
|
|
251
251
|
|
|
252
252
|
If you see this error:
|
|
253
253
|
|
|
254
|
-
```
|
|
254
|
+
```text
|
|
255
255
|
'start' received an invalid workflow function. Ensure the Workflow SDK is configured correctly and the function includes a 'use workflow' directive.
|
|
256
256
|
```
|
|
257
257
|
|
|
@@ -262,7 +262,7 @@ Check both of these first:
|
|
|
262
262
|
|
|
263
263
|
See [start-invalid-workflow-function](/docs/errors/start-invalid-workflow-function) for full examples and fixes.
|
|
264
264
|
|
|
265
|
-
## Next
|
|
265
|
+
## Next steps
|
|
266
266
|
|
|
267
267
|
* Learn more about the [Foundations](/docs/foundations).
|
|
268
268
|
* Check [Errors](/docs/errors) if you encounter issues.
|
|
@@ -20,7 +20,7 @@ This guide will walk through setting up your first workflow in an Express app. A
|
|
|
20
20
|
<Steps>
|
|
21
21
|
|
|
22
22
|
<Step>
|
|
23
|
-
## Create
|
|
23
|
+
## Create your Express project
|
|
24
24
|
|
|
25
25
|
Start by creating a new Express project.
|
|
26
26
|
|
|
@@ -117,7 +117,7 @@ To use the Nitro builder, update your `package.json` to include the following sc
|
|
|
117
117
|
|
|
118
118
|
<Step>
|
|
119
119
|
|
|
120
|
-
## Create
|
|
120
|
+
## Create your first workflow
|
|
121
121
|
|
|
122
122
|
Create a new file for our first workflow:
|
|
123
123
|
|
|
@@ -137,14 +137,14 @@ export async function handleUserSignup(email: string) {
|
|
|
137
137
|
}
|
|
138
138
|
```
|
|
139
139
|
|
|
140
|
-
We'll fill in those functions next
|
|
140
|
+
We'll fill in those functions next. The current code does the following:
|
|
141
141
|
|
|
142
142
|
- We define a **workflow** function with the directive `"use workflow"`. Think of the workflow function as the _orchestrator_ of individual **steps**.
|
|
143
143
|
- The Workflow SDK's `sleep` function allows us to suspend execution of the workflow without using up any resources. A sleep can be a few seconds, hours, days, or even months long.
|
|
144
144
|
|
|
145
|
-
## Create
|
|
145
|
+
## Create your workflow steps
|
|
146
146
|
|
|
147
|
-
|
|
147
|
+
Define the missing functions.
|
|
148
148
|
|
|
149
149
|
```typescript title="workflows/user-signup.ts" lineNumbers
|
|
150
150
|
import { FatalError } from "workflow";
|
|
@@ -198,7 +198,7 @@ Taking a look at this code:
|
|
|
198
198
|
|
|
199
199
|
<Step>
|
|
200
200
|
|
|
201
|
-
## Create
|
|
201
|
+
## Create your route handler
|
|
202
202
|
|
|
203
203
|
To invoke your new workflow, we'll create both the Express app and a new API route handler at `src/index.ts` with the following code:
|
|
204
204
|
|
|
@@ -272,7 +272,7 @@ Check the [Deploying](/docs/deploying) section to learn how your workflows can b
|
|
|
272
272
|
|
|
273
273
|
If you see this error:
|
|
274
274
|
|
|
275
|
-
```
|
|
275
|
+
```text
|
|
276
276
|
'start' received an invalid workflow function. Ensure the Workflow SDK is configured correctly and the function includes a 'use workflow' directive.
|
|
277
277
|
```
|
|
278
278
|
|
|
@@ -283,7 +283,7 @@ Check both of these first:
|
|
|
283
283
|
|
|
284
284
|
See [start-invalid-workflow-function](/docs/errors/start-invalid-workflow-function) for full examples and fixes.
|
|
285
285
|
|
|
286
|
-
## Next
|
|
286
|
+
## Next steps
|
|
287
287
|
|
|
288
288
|
- Learn more about the [Foundations](/docs/foundations).
|
|
289
289
|
- Check [Errors](/docs/errors) if you encounter issues.
|
|
@@ -20,7 +20,7 @@ This guide will walk through setting up your first workflow in a Fastify app. Al
|
|
|
20
20
|
<Steps>
|
|
21
21
|
|
|
22
22
|
<Step>
|
|
23
|
-
## Create
|
|
23
|
+
## Create your Fastify project
|
|
24
24
|
|
|
25
25
|
Start by creating a new Fastify project.
|
|
26
26
|
|
|
@@ -116,7 +116,7 @@ To use the Nitro builder, update your `package.json` to include the following sc
|
|
|
116
116
|
|
|
117
117
|
<Step>
|
|
118
118
|
|
|
119
|
-
## Create
|
|
119
|
+
## Create your first workflow
|
|
120
120
|
|
|
121
121
|
Create a new file for our first workflow:
|
|
122
122
|
|
|
@@ -136,13 +136,13 @@ export async function handleUserSignup(email: string) {
|
|
|
136
136
|
}
|
|
137
137
|
```
|
|
138
138
|
|
|
139
|
-
We'll fill in those functions next
|
|
139
|
+
We'll fill in those functions next. The current code does the following:
|
|
140
140
|
|
|
141
141
|
- We define a **workflow** function with the directive `"use workflow"`. Think of the workflow function as the _orchestrator_ of individual **steps**.
|
|
142
142
|
- The Workflow SDK's `sleep` function allows us to suspend execution of the workflow without using up any resources. A sleep can be a few seconds, hours, days, or even months long.
|
|
143
|
-
## Create
|
|
143
|
+
## Create your workflow steps
|
|
144
144
|
|
|
145
|
-
|
|
145
|
+
Define the missing functions:
|
|
146
146
|
```typescript title="workflows/user-signup.ts" lineNumbers
|
|
147
147
|
import { FatalError } from "workflow";
|
|
148
148
|
|
|
@@ -186,7 +186,7 @@ Taking a look at this code:
|
|
|
186
186
|
|
|
187
187
|
<Step>
|
|
188
188
|
|
|
189
|
-
## Create
|
|
189
|
+
## Create your route handler
|
|
190
190
|
|
|
191
191
|
To invoke your new workflow, we'll create both the Fastify app and a new API route handler at `src/index.ts` with the following code:
|
|
192
192
|
|
|
@@ -259,7 +259,7 @@ Check the [Deploying](/docs/deploying) section to learn how your workflows can b
|
|
|
259
259
|
|
|
260
260
|
If you see this error:
|
|
261
261
|
|
|
262
|
-
```
|
|
262
|
+
```text
|
|
263
263
|
'start' received an invalid workflow function. Ensure the Workflow SDK is configured correctly and the function includes a 'use workflow' directive.
|
|
264
264
|
```
|
|
265
265
|
|
|
@@ -270,7 +270,7 @@ Check both of these first:
|
|
|
270
270
|
|
|
271
271
|
See [start-invalid-workflow-function](/docs/errors/start-invalid-workflow-function) for full examples and fixes.
|
|
272
272
|
|
|
273
|
-
## Next
|
|
273
|
+
## Next steps
|
|
274
274
|
|
|
275
275
|
- Learn more about the [Foundations](/docs/foundations).
|
|
276
276
|
- Check [Errors](/docs/errors) if you encounter issues.
|
|
@@ -16,7 +16,7 @@ related:
|
|
|
16
16
|
<Steps>
|
|
17
17
|
|
|
18
18
|
<Step>
|
|
19
|
-
## Create
|
|
19
|
+
## Create your Hono project
|
|
20
20
|
|
|
21
21
|
Start by creating a new Hono project. This command will create a new directory named `my-workflow-app` and set up a Hono project inside it.
|
|
22
22
|
|
|
@@ -100,7 +100,7 @@ To use the Nitro builder, update your `package.json` to include the following sc
|
|
|
100
100
|
|
|
101
101
|
<Step>
|
|
102
102
|
|
|
103
|
-
## Create
|
|
103
|
+
## Create your first workflow
|
|
104
104
|
|
|
105
105
|
Create a new file for our first workflow:
|
|
106
106
|
|
|
@@ -122,14 +122,14 @@ export async function handleUserSignup(email: string) {
|
|
|
122
122
|
}
|
|
123
123
|
```
|
|
124
124
|
|
|
125
|
-
We'll fill in those functions next
|
|
125
|
+
We'll fill in those functions next. The current code does the following:
|
|
126
126
|
|
|
127
127
|
- We define a **workflow** function with the directive `"use workflow"`. Think of the workflow function as the _orchestrator_ of individual **steps**.
|
|
128
128
|
- The Workflow SDK's `sleep` function allows us to suspend execution of the workflow without using up any resources. A sleep can be a few seconds, hours, days, or even months long.
|
|
129
129
|
|
|
130
|
-
## Create
|
|
130
|
+
## Create your workflow steps
|
|
131
131
|
|
|
132
|
-
|
|
132
|
+
Define the missing functions.
|
|
133
133
|
|
|
134
134
|
```typescript title="workflows/user-signup.ts" lineNumbers
|
|
135
135
|
import { FatalError } from "workflow";
|
|
@@ -183,7 +183,7 @@ Taking a look at this code:
|
|
|
183
183
|
|
|
184
184
|
<Step>
|
|
185
185
|
|
|
186
|
-
## Create
|
|
186
|
+
## Create your route handler
|
|
187
187
|
|
|
188
188
|
To invoke your new workflow, we'll create a new API route handler at `src/index.ts` with the following code:
|
|
189
189
|
|
|
@@ -254,7 +254,7 @@ Check the [Deploying](/docs/deploying) section to learn how your workflows can b
|
|
|
254
254
|
|
|
255
255
|
If you see this error:
|
|
256
256
|
|
|
257
|
-
```
|
|
257
|
+
```text
|
|
258
258
|
'start' received an invalid workflow function. Ensure the Workflow SDK is configured correctly and the function includes a 'use workflow' directive.
|
|
259
259
|
```
|
|
260
260
|
|
|
@@ -265,7 +265,7 @@ Check both of these first:
|
|
|
265
265
|
|
|
266
266
|
See [start-invalid-workflow-function](/docs/errors/start-invalid-workflow-function) for full examples and fixes.
|
|
267
267
|
|
|
268
|
-
## Next
|
|
268
|
+
## Next steps
|
|
269
269
|
|
|
270
270
|
- Learn more about the [Foundations](/docs/foundations).
|
|
271
271
|
- Check [Errors](/docs/errors) if you encounter issues.
|
|
@@ -13,11 +13,11 @@ related:
|
|
|
13
13
|
text="In this NestJS app, run `npm i workflow @workflow/nest` and `npm i -D @swc/cli @swc/core`. Configure `nest-cli.json` with `compilerOptions.builder: "swc"` and `deleteOutDir: true`. Run `npx @workflow/nest init`, add `.swcrc` to `.gitignore`, and set package scripts `prebuild: "npx @workflow/nest init --force"` and `start:dev: "npx @workflow/nest init --force && nest start --watch"`. Import `WorkflowModule.forRoot()` from `@workflow/nest` in `src/app.module.ts` (use `{ moduleType: "commonjs", distDir: "dist" }` if compiling CommonJS). Create `src/workflows/user-signup.ts` with `"use workflow"`, `sleep`, and `"use step"` helpers. Add a `POST /signup` controller method that reads `email`, calls `start(handleUserSignup, [email])` from `workflow/api`, and returns JSON. Run `npm run start:dev`, call `curl -X POST --json '{"email":"hello@example.com"}' http://localhost:3000/signup`, and inspect with `npx workflow web` or `npx workflow inspect runs`."
|
|
14
14
|
/>
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
Set up your first durable workflow in a NestJS app and learn the core Workflow SDK concepts.
|
|
17
17
|
|
|
18
18
|
<Callout>
|
|
19
19
|
NestJS integration is experimental. Deployment to Vercel is supported via the
|
|
20
|
-
`workflow-nest build --vercel` command
|
|
20
|
+
`workflow-nest build --vercel` command. See [Deploy to Vercel](#deploy-to-vercel) below.
|
|
21
21
|
</Callout>
|
|
22
22
|
|
|
23
23
|
---
|
|
@@ -25,7 +25,7 @@ NestJS integration is experimental. Deployment to Vercel is supported via the
|
|
|
25
25
|
<Steps>
|
|
26
26
|
|
|
27
27
|
<Step>
|
|
28
|
-
## Create
|
|
28
|
+
## Create your NestJS project
|
|
29
29
|
|
|
30
30
|
Start by creating a new NestJS project using the NestJS CLI.
|
|
31
31
|
|
|
@@ -46,7 +46,7 @@ cd my-workflow-app
|
|
|
46
46
|
npm i workflow @workflow/nest
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
-
### Choose
|
|
49
|
+
### Choose your module format
|
|
50
50
|
|
|
51
51
|
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.
|
|
52
52
|
|
|
@@ -112,7 +112,7 @@ Ensure your `nest-cli.json` has SWC as the builder:
|
|
|
112
112
|
}
|
|
113
113
|
```
|
|
114
114
|
|
|
115
|
-
### Initialize SWC
|
|
115
|
+
### Initialize SWC configuration
|
|
116
116
|
|
|
117
117
|
Run the init command to generate the SWC configuration:
|
|
118
118
|
|
|
@@ -120,7 +120,7 @@ Run the init command to generate the SWC configuration:
|
|
|
120
120
|
npx @workflow/nest init
|
|
121
121
|
```
|
|
122
122
|
|
|
123
|
-
This creates a `.swcrc` file configured with the Workflow SWC plugin for
|
|
123
|
+
This creates a `.swcrc` file configured with the Workflow SWC plugin for step-mode transformations.
|
|
124
124
|
|
|
125
125
|
<Callout>
|
|
126
126
|
Add `.swcrc` to your `.gitignore` as it contains machine-specific absolute paths that shouldn't be committed.
|
|
@@ -143,10 +143,10 @@ Add scripts to regenerate the SWC configuration before builds:
|
|
|
143
143
|
<Accordion type="single" collapsible>
|
|
144
144
|
<AccordionItem value="typescript-intellisense" className="[&_h3]:my-0">
|
|
145
145
|
<AccordionTrigger className="[&_p]:my-0 text-lg [&_p]:text-foreground">
|
|
146
|
-
|
|
146
|
+
Set up IntelliSense for TypeScript (optional)
|
|
147
147
|
</AccordionTrigger>
|
|
148
148
|
<AccordionContent className="[&_p]:my-2">
|
|
149
|
-
To enable helpful hints in your IDE,
|
|
149
|
+
To enable helpful hints in your IDE, set up the workflow plugin in `tsconfig.json`:
|
|
150
150
|
|
|
151
151
|
```json title="tsconfig.json" lineNumbers
|
|
152
152
|
{
|
|
@@ -208,7 +208,7 @@ The `WorkflowModule` handles workflow bundle building and provides HTTP routing
|
|
|
208
208
|
|
|
209
209
|
<Step>
|
|
210
210
|
|
|
211
|
-
## Create
|
|
211
|
+
## Create your first workflow
|
|
212
212
|
|
|
213
213
|
Create a new file for our first workflow in the `src/workflows` directory:
|
|
214
214
|
|
|
@@ -241,14 +241,14 @@ export async function handleUserSignup(email: string) {
|
|
|
241
241
|
}
|
|
242
242
|
```
|
|
243
243
|
|
|
244
|
-
We'll fill in those functions next, but
|
|
244
|
+
We'll fill in those functions next, but first review this code:
|
|
245
245
|
|
|
246
246
|
- We define a **workflow** function with the directive `"use workflow"`. Think of the workflow function as the _orchestrator_ of individual **steps**.
|
|
247
247
|
- The Workflow SDK's `sleep` function allows us to suspend execution of the workflow without using up any resources. A sleep can be a few seconds, hours, days, or even months long.
|
|
248
248
|
|
|
249
|
-
## Create
|
|
249
|
+
## Create your workflow steps
|
|
250
250
|
|
|
251
|
-
|
|
251
|
+
Define the missing functions.
|
|
252
252
|
|
|
253
253
|
```typescript title="src/workflows/user-signup.ts" lineNumbers
|
|
254
254
|
import { FatalError } from "workflow";
|
|
@@ -302,7 +302,7 @@ Taking a look at this code:
|
|
|
302
302
|
|
|
303
303
|
<Step>
|
|
304
304
|
|
|
305
|
-
## Create
|
|
305
|
+
## Create your controller
|
|
306
306
|
|
|
307
307
|
To invoke your new workflow, update your controller with a new endpoint:
|
|
308
308
|
|
|
@@ -426,7 +426,7 @@ execute instead of staying `pending`.
|
|
|
426
426
|
|
|
427
427
|
---
|
|
428
428
|
|
|
429
|
-
## Configuration
|
|
429
|
+
## Configuration options
|
|
430
430
|
|
|
431
431
|
The `WorkflowModule.forRoot()` method accepts optional configuration:
|
|
432
432
|
|
|
@@ -456,7 +456,7 @@ WorkflowModule.forRoot({
|
|
|
456
456
|
// development, false in production).
|
|
457
457
|
// Accepts the same values as esbuild's sourcemap option: true, false,
|
|
458
458
|
// 'inline', 'linked', 'external', 'both'. Set to false for smaller
|
|
459
|
-
// function bundles (useful for staying under the Vercel
|
|
459
|
+
// function bundles (useful for staying under the Vercel 250 MB function
|
|
460
460
|
// size limit) at the cost of stack traces pointing at generated code.
|
|
461
461
|
// Can also be set via the WORKFLOW_SOURCEMAP environment variable.
|
|
462
462
|
sourcemap: 'inline',
|
|
@@ -469,7 +469,7 @@ WorkflowModule.forRoot({
|
|
|
469
469
|
|
|
470
470
|
If you see this error:
|
|
471
471
|
|
|
472
|
-
```
|
|
472
|
+
```text
|
|
473
473
|
'start' received an invalid workflow function. Ensure the Workflow SDK is configured correctly and the function includes a 'use workflow' directive.
|
|
474
474
|
```
|
|
475
475
|
|
|
@@ -479,7 +479,8 @@ Check both of these first:
|
|
|
479
479
|
2. Your NestJS app imports and registers the `WorkflowModule`.
|
|
480
480
|
|
|
481
481
|
See [start-invalid-workflow-function](/docs/errors/start-invalid-workflow-function) for full examples and fixes.
|
|
482
|
-
|
|
482
|
+
|
|
483
|
+
## Next steps
|
|
483
484
|
|
|
484
485
|
- Learn more about the [Foundations](/docs/foundations).
|
|
485
486
|
- Check [Errors](/docs/errors) if you encounter issues.
|
|
@@ -17,7 +17,7 @@ related:
|
|
|
17
17
|
<Steps>
|
|
18
18
|
|
|
19
19
|
<Step>
|
|
20
|
-
## Create
|
|
20
|
+
## Create your Next.js project
|
|
21
21
|
|
|
22
22
|
Start by creating a new Next.js project. This command will create a new directory named `my-workflow-app` and set up a Next.js project inside it.
|
|
23
23
|
|
|
@@ -89,7 +89,7 @@ If your Next.js app has a [proxy handler](https://nextjs.org/docs/app/api-refere
|
|
|
89
89
|
(formerly known as "middleware"), you'll need to update the matcher pattern to exclude Workflow's
|
|
90
90
|
internal paths to prevent the proxy handler from running on them.
|
|
91
91
|
|
|
92
|
-
If you see `[local world] Queue operation failed` with `Cannot perform ArrayBuffer.prototype.slice on a detached ArrayBuffer`, your proxy matcher is still intercepting Workflow's internal `POST /.well-known/workflow/v1/flow` request. This
|
|
92
|
+
If you see `[local world] Queue operation failed` with `Cannot perform ArrayBuffer.prototype.slice on a detached ArrayBuffer`, your proxy matcher is still intercepting Workflow's internal `POST /.well-known/workflow/v1/flow` request. This issue can be hard to spot in Next.js 16, where `proxy.ts` replaced `middleware.ts`.
|
|
93
93
|
|
|
94
94
|
Add `.well-known/workflow/*` to your matcher exclusion list:
|
|
95
95
|
|
|
@@ -121,7 +121,7 @@ This ensures that internal Workflow paths are not intercepted by your middleware
|
|
|
121
121
|
|
|
122
122
|
<Step>
|
|
123
123
|
|
|
124
|
-
## Create
|
|
124
|
+
## Create your first workflow
|
|
125
125
|
|
|
126
126
|
Create a new file for our first workflow:
|
|
127
127
|
|
|
@@ -144,14 +144,14 @@ export async function handleUserSignup(email: string) {
|
|
|
144
144
|
|
|
145
145
|
```
|
|
146
146
|
|
|
147
|
-
We'll fill in those functions next
|
|
147
|
+
We'll fill in those functions next. The current code does the following:
|
|
148
148
|
|
|
149
149
|
* We define a **workflow** function with the directive `"use workflow"`. Think of the workflow function as the _orchestrator_ of individual **steps**.
|
|
150
150
|
* The Workflow SDK's `sleep` function allows us to suspend execution of the workflow without using up any resources. A sleep can be a few seconds, hours, days, or even months long.
|
|
151
151
|
|
|
152
|
-
## Create
|
|
152
|
+
## Create your workflow steps
|
|
153
153
|
|
|
154
|
-
|
|
154
|
+
Define the missing functions.
|
|
155
155
|
|
|
156
156
|
```typescript title="workflows/user-signup.ts" lineNumbers
|
|
157
157
|
import { FatalError } from "workflow"
|
|
@@ -204,7 +204,7 @@ We'll dive deeper into workflows, steps, and other ways to suspend or handle eve
|
|
|
204
204
|
|
|
205
205
|
<Step>
|
|
206
206
|
|
|
207
|
-
## Create
|
|
207
|
+
## Create your route handler
|
|
208
208
|
|
|
209
209
|
To invoke your new workflow, we'll need to add your workflow to a `POST` API Route Handler, `app/api/signup/route.ts`, with the following code:
|
|
210
210
|
|
|
@@ -276,12 +276,12 @@ Check the [Deploying](/docs/deploying) section to learn how your workflows can b
|
|
|
276
276
|
|
|
277
277
|
If you see this error when upgrading to Next.js 16.1 or later:
|
|
278
278
|
|
|
279
|
-
```
|
|
279
|
+
```text
|
|
280
280
|
Build error occurred
|
|
281
281
|
Error: Cannot find module 'next/dist/lib/server-external-packages.json'
|
|
282
282
|
```
|
|
283
283
|
|
|
284
|
-
Upgrade
|
|
284
|
+
Upgrade `workflow` to the latest release:
|
|
285
285
|
|
|
286
286
|
```package-install
|
|
287
287
|
workflow@latest
|
|
@@ -315,7 +315,7 @@ Without this configuration, you may experience intermittent issues where workflo
|
|
|
315
315
|
|
|
316
316
|
If you see this error:
|
|
317
317
|
|
|
318
|
-
```
|
|
318
|
+
```text
|
|
319
319
|
'start' received an invalid workflow function. Ensure the Workflow SDK is configured correctly and the function includes a 'use workflow' directive.
|
|
320
320
|
```
|
|
321
321
|
|
|
@@ -326,7 +326,7 @@ Check both of these first:
|
|
|
326
326
|
|
|
327
327
|
See [start-invalid-workflow-function](/docs/errors/start-invalid-workflow-function) for full examples and fixes.
|
|
328
328
|
|
|
329
|
-
## Next
|
|
329
|
+
## Next steps
|
|
330
330
|
|
|
331
331
|
* Learn more about the [Foundations](/docs/foundations).
|
|
332
332
|
* Check [Errors](/docs/errors) if you encounter issues.
|