workflow 5.0.0-beta.43 → 5.0.0-beta.46
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 +16 -16
- package/docs/api-reference/workflow-api/resume-webhook.mdx +4 -4
- 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 +4 -3
- package/docs/changelog/lazy-event-creation.md +27 -27
- package/docs/changelog/lazy-hook-resume.mdx +51 -0
- package/docs/changelog/meta.json +1 -0
- package/docs/changelog/resilient-resume.mdx +13 -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 +87 -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
|
@@ -31,8 +31,8 @@ keywords:
|
|
|
31
31
|
|
|
32
32
|
The World storage interface exposes four sub-interfaces for querying workflow data:
|
|
33
33
|
|
|
34
|
-
- **`world.events
|
|
35
|
-
- **`world.runs`**, **`world.steps`**, **`world.hooks
|
|
34
|
+
- **`world.events`**: The append-only event log. This is the source of truth for all workflow state. See [Event Sourcing](/docs/how-it-works/event-sourcing) for background.
|
|
35
|
+
- **`world.runs`**, **`world.steps`**, **`world.hooks`**: Materialized views derived from the event log, provided as convenience accessors for the most common query patterns.
|
|
36
36
|
|
|
37
37
|
```typescript lineNumbers
|
|
38
38
|
import { getWorld } from "workflow/runtime";
|
|
@@ -62,7 +62,7 @@ await world.events.create(runId, { // [!code highlight]
|
|
|
62
62
|
| `data` | `CreateEventRequest` | Event data including `eventType` |
|
|
63
63
|
| `params` | `object` | Optional parameters |
|
|
64
64
|
|
|
65
|
-
**Returns:** `EventResult
|
|
65
|
+
**Returns:** `EventResult`, the created event and the affected entity (run/step/hook)
|
|
66
66
|
|
|
67
67
|
### events.get()
|
|
68
68
|
|
|
@@ -119,7 +119,7 @@ const result = await world.events.listByCorrelationId({ // [!code highlight]
|
|
|
119
119
|
|
|
120
120
|
**Returns:** `{ data: Event[], cursor?: string }`
|
|
121
121
|
|
|
122
|
-
### Event
|
|
122
|
+
### Event types
|
|
123
123
|
|
|
124
124
|
| Category | Types |
|
|
125
125
|
|----------|-------|
|
|
@@ -151,6 +151,40 @@ const run = await world.runs.get(runId); // [!code highlight]
|
|
|
151
151
|
|
|
152
152
|
**Returns:** `WorkflowRun` (or `WorkflowRunWithoutData` when `resolveData: 'none'`)
|
|
153
153
|
|
|
154
|
+
### runs.waitForTerminalStatus()
|
|
155
|
+
|
|
156
|
+
Optional. Long poll for a run to reach a terminal status (`completed`,
|
|
157
|
+
`failed`, or `cancelled`) instead of re-reading it on an interval. This is what
|
|
158
|
+
`await run.returnValue` uses, so a run's result reaches the awaiting side as
|
|
159
|
+
soon as it finishes rather than at the next poll tick.
|
|
160
|
+
|
|
161
|
+
```typescript lineNumbers
|
|
162
|
+
const run = await world.runs.waitForTerminalStatus?.(runId, { // [!code highlight]
|
|
163
|
+
timeoutMs: 25_000, // [!code highlight]
|
|
164
|
+
}); // [!code highlight]
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
| Parameter | Type | Description |
|
|
168
|
+
|-----------|------|-------------|
|
|
169
|
+
| `runId` | `string` | The workflow run ID |
|
|
170
|
+
| `params.timeoutMs` | `number` | Upper bound on the wait. The call returns earlier, the moment the run is terminal |
|
|
171
|
+
| `params.signal` | `AbortSignal` | Abandons the wait |
|
|
172
|
+
| `params.resolveData` | `'all' \| 'none'` | Whether to include input/output data. Default: `'all'` |
|
|
173
|
+
|
|
174
|
+
**Returns:** the same `WorkflowRun` as `runs.get()`: terminal if the run
|
|
175
|
+
finished within the budget, otherwise the latest snapshot. An expired budget is
|
|
176
|
+
a normal return, not an error, and a missing run throws
|
|
177
|
+
`WorkflowRunNotFoundError` exactly as `runs.get()` does.
|
|
178
|
+
|
|
179
|
+
<Callout>
|
|
180
|
+
Not every backend can hold a read open, so this method is optional and may
|
|
181
|
+
also return a non-terminal snapshot before `timeoutMs` is up. Callers pace
|
|
182
|
+
their own retries (`await run.returnValue` keeps consecutive non-terminal
|
|
183
|
+
observations at least one `WORKFLOW_RETURN_VALUE_POLL_INTERVAL_MS` apart), and
|
|
184
|
+
worlds that omit the method are polled on that interval instead. Set
|
|
185
|
+
`WORKFLOW_RETURN_VALUE_LONG_POLL=0` to force interval polling everywhere.
|
|
186
|
+
</Callout>
|
|
187
|
+
|
|
154
188
|
### runs.list()
|
|
155
189
|
|
|
156
190
|
```typescript lineNumbers
|
|
@@ -174,13 +208,13 @@ const result = await world.runs.list({ // [!code highlight]
|
|
|
174
208
|
reads.
|
|
175
209
|
</Callout>
|
|
176
210
|
|
|
177
|
-
### Cancelling
|
|
211
|
+
### Cancelling runs
|
|
178
212
|
|
|
179
|
-
To cancel a run, create a `run_cancelled` event
|
|
213
|
+
To cancel a run, create a `run_cancelled` event through `world.events.create()` (see [world.events](#worldevents) above), or use the Workflow CLI or web interface helpers.
|
|
180
214
|
|
|
181
215
|
To cancel a batch in one call, a world may implement the optional `runs.cancelMany({ runIds })`. It returns a summary plus a per-run outcome (`cancelled`, `already_cancelled`, `not_cancellable`, `not_found`, or `failed`). Backends that omit it fall back to per-run cancellation automatically.
|
|
182
216
|
|
|
183
|
-
### WorkflowRun
|
|
217
|
+
### WorkflowRun type
|
|
184
218
|
|
|
185
219
|
| Field | Type | Description |
|
|
186
220
|
|-------|------|-------------|
|
|
@@ -211,7 +245,7 @@ const step = await world.steps.get(runId, stepId); // [!code highlight]
|
|
|
211
245
|
|
|
212
246
|
| Parameter | Type | Description |
|
|
213
247
|
|-----------|------|-------------|
|
|
214
|
-
| `runId` | `string
|
|
248
|
+
| `runId` | `string` | The workflow run ID that owns the step |
|
|
215
249
|
| `stepId` | `string` | The step ID |
|
|
216
250
|
| `params.resolveData` | `'all' \| 'none'` | Whether to include input/output data. Default: `'all'` |
|
|
217
251
|
|
|
@@ -234,7 +268,7 @@ const result = await world.steps.list({ // [!code highlight]
|
|
|
234
268
|
|
|
235
269
|
**Returns:** `{ data: Step[], cursor?: string }`
|
|
236
270
|
|
|
237
|
-
### Step
|
|
271
|
+
### Step type
|
|
238
272
|
|
|
239
273
|
| Field | Type | Description |
|
|
240
274
|
|-------|------|-------------|
|
|
@@ -251,11 +285,11 @@ const result = await world.steps.list({ // [!code highlight]
|
|
|
251
285
|
| `retryAfter` | `string \| null` | ISO timestamp for next retry attempt |
|
|
252
286
|
|
|
253
287
|
<Callout type="info">
|
|
254
|
-
Step I/O is serialized using the [devalue](https://github.com/Rich-Harris/devalue) format. Use `hydrateResourceIO()` from `workflow/observability` to deserialize it for display. See [`hydrateResourceIO()`](/docs/api-reference/workflow-observability/hydrate-resource-io).
|
|
288
|
+
Step input/output (I/O) is serialized using the [devalue](https://github.com/Rich-Harris/devalue) format. Use `hydrateResourceIO()` from `workflow/observability` to deserialize it for display. See [`hydrateResourceIO()`](/docs/api-reference/workflow-observability/hydrate-resource-io).
|
|
255
289
|
</Callout>
|
|
256
290
|
|
|
257
291
|
<Callout type="warn">
|
|
258
|
-
`stepName` is a machine-readable identifier like `step//./src/workflows/order//processPayment`. Use `parseStepName()` from `workflow/observability` to extract the `shortName` for
|
|
292
|
+
`stepName` is a machine-readable identifier like `step//./src/workflows/order//processPayment`. Use `parseStepName()` from `workflow/observability` to extract the `shortName` for display in a user interface.
|
|
259
293
|
</Callout>
|
|
260
294
|
|
|
261
295
|
---
|
|
@@ -283,7 +317,7 @@ Look up a hook by its token. Useful in webhook resume flows where you receive a
|
|
|
283
317
|
<Callout type="info">
|
|
284
318
|
For runtime application code, prefer [`getHookByToken()`](/docs/api-reference/workflow-api/get-hook-by-token). Use `world.hooks.getByToken()` when you are working directly with the World storage interface for custom tooling, admin views, or low-level integrations.
|
|
285
319
|
|
|
286
|
-
Hook-token lookup is the low-level form of the recommended idempotency flow: if a hook is already registered for your business key, reuse the hook's `runId` or resume that hook instead of starting another run. If no hook exists yet, start a workflow that creates the deterministic hook near the beginning and checks `await hook.getConflict()` to detect whether another run claimed the token first
|
|
320
|
+
Hook-token lookup is the low-level form of the recommended idempotency flow: if a hook is already registered for your business key, reuse the hook's `runId` or resume that hook instead of starting another run. If no hook exists yet, start a workflow that creates the deterministic hook near the beginning and checks `await hook.getConflict()` to detect whether another run claimed the token first. On a conflict it resolves with the run that owns the token. See [Run idempotency](/docs/foundations/idempotency#run-idempotency).
|
|
287
321
|
</Callout>
|
|
288
322
|
|
|
289
323
|
```typescript lineNumbers
|
|
@@ -310,7 +344,7 @@ const result = await world.hooks.list({ // [!code highlight]
|
|
|
310
344
|
|
|
311
345
|
**Returns:** `{ data: Hook[], cursor?: string }`
|
|
312
346
|
|
|
313
|
-
### Hook
|
|
347
|
+
### Hook type
|
|
314
348
|
|
|
315
349
|
| Field | Type | Description |
|
|
316
350
|
|-------|------|-------------|
|
|
@@ -327,7 +361,7 @@ const result = await world.hooks.list({ // [!code highlight]
|
|
|
327
361
|
|
|
328
362
|
## Examples
|
|
329
363
|
|
|
330
|
-
### List
|
|
364
|
+
### List runs with pagination
|
|
331
365
|
|
|
332
366
|
```typescript lineNumbers
|
|
333
367
|
import { getWorld } from "workflow/runtime";
|
|
@@ -342,23 +376,23 @@ const runs = await world.runs.list({ // [!code highlight]
|
|
|
342
376
|
cursor = runs.cursor; // pass to next call for pagination
|
|
343
377
|
```
|
|
344
378
|
|
|
345
|
-
### Get a
|
|
379
|
+
### Get a run: full data vs. metadata only
|
|
346
380
|
|
|
347
381
|
```typescript lineNumbers
|
|
348
382
|
import { getWorld } from "workflow/runtime";
|
|
349
383
|
|
|
350
384
|
const world = await getWorld();
|
|
351
385
|
|
|
352
|
-
// Full data (default)
|
|
386
|
+
// Full data (default): includes serialized input/output
|
|
353
387
|
const run = await world.runs.get(runId); // [!code highlight]
|
|
354
388
|
|
|
355
|
-
// Metadata only
|
|
389
|
+
// Metadata only: lighter, no I/O loaded
|
|
356
390
|
const lightweight = await world.runs.get(runId, { // [!code highlight]
|
|
357
391
|
resolveData: "none", // [!code highlight]
|
|
358
392
|
}); // [!code highlight]
|
|
359
393
|
```
|
|
360
394
|
|
|
361
|
-
### List
|
|
395
|
+
### List steps for a progress dashboard
|
|
362
396
|
|
|
363
397
|
```typescript lineNumbers
|
|
364
398
|
import { getWorld } from "workflow/runtime";
|
|
@@ -380,7 +414,7 @@ const progress = steps.data.map((step) => {
|
|
|
380
414
|
});
|
|
381
415
|
```
|
|
382
416
|
|
|
383
|
-
### Hydrate
|
|
417
|
+
### Hydrate step I/O
|
|
384
418
|
|
|
385
419
|
```typescript lineNumbers
|
|
386
420
|
import { getWorld } from "workflow/runtime";
|
|
@@ -392,7 +426,7 @@ const hydrated = hydrateResourceIO(step, observabilityRevivers); // [!code highl
|
|
|
392
426
|
console.log(hydrated.input, hydrated.output);
|
|
393
427
|
```
|
|
394
428
|
|
|
395
|
-
### Cancel a
|
|
429
|
+
### Cancel a run
|
|
396
430
|
|
|
397
431
|
```typescript lineNumbers
|
|
398
432
|
import { getWorld } from "workflow/runtime";
|
|
@@ -403,7 +437,7 @@ await world.events.create(runId, { // [!code highlight]
|
|
|
403
437
|
}); // [!code highlight]
|
|
404
438
|
```
|
|
405
439
|
|
|
406
|
-
### Look
|
|
440
|
+
### Look up hook by token
|
|
407
441
|
|
|
408
442
|
```typescript lineNumbers
|
|
409
443
|
import { getWorld } from "workflow/runtime";
|
|
@@ -413,7 +447,7 @@ const hook = await world.hooks.getByToken(token); // [!code highlight]
|
|
|
413
447
|
console.log(hook.runId, hook.metadata); // [!code highlight]
|
|
414
448
|
```
|
|
415
449
|
|
|
416
|
-
### List
|
|
450
|
+
### List events for audit trail
|
|
417
451
|
|
|
418
452
|
```typescript lineNumbers
|
|
419
453
|
import { getWorld } from "workflow/runtime";
|
|
@@ -428,9 +462,9 @@ for (const event of events.data) {
|
|
|
428
462
|
|
|
429
463
|
## Related
|
|
430
464
|
|
|
431
|
-
- [Event
|
|
432
|
-
- [getRun()](/docs/api-reference/workflow-api/get-run)
|
|
433
|
-
- [`workflow/observability`](/docs/api-reference/workflow-observability)
|
|
434
|
-
- [resumeHook()](/docs/api-reference/workflow-api/resume-hook)
|
|
435
|
-
- [Hooks](/docs/foundations/hooks)
|
|
436
|
-
- [Workflows and
|
|
465
|
+
- [Event sourcing](/docs/how-it-works/event-sourcing): How the event log powers workflow replay and state
|
|
466
|
+
- [`getRun()`](/docs/api-reference/workflow-api/get-run): Higher-level API for working with individual runs
|
|
467
|
+
- [`workflow/observability`](/docs/api-reference/workflow-observability): Hydrate step I/O and parse display names
|
|
468
|
+
- [`resumeHook()`](/docs/api-reference/workflow-api/resume-hook): Resume a workflow by sending a payload to a hook
|
|
469
|
+
- [Hooks](/docs/foundations/hooks): Core concepts for hooks and pause points
|
|
470
|
+
- [Workflows and steps](/docs/foundations/workflows-and-steps): Core concepts for steps
|
|
@@ -33,7 +33,7 @@ Stream methods live on `world.streams` (the `streams` sub-object of the `World`
|
|
|
33
33
|
import { getWorld } from "workflow/runtime";
|
|
34
34
|
|
|
35
35
|
const world = await getWorld(); // [!code highlight]
|
|
36
|
-
// Stream methods are called on world.streams
|
|
36
|
+
// Stream methods are called on world.streams, e.g. world.streams.write()
|
|
37
37
|
```
|
|
38
38
|
|
|
39
39
|
## Methods
|
|
@@ -56,7 +56,7 @@ await world.streams.write(runId, "default", chunk); // [!code highlight]
|
|
|
56
56
|
|
|
57
57
|
### writeMulti()
|
|
58
58
|
|
|
59
|
-
Write multiple chunks in a single operation. Optional optimization
|
|
59
|
+
Write multiple chunks in a single operation. Optional optimization: not all World implementations support it. Falls back to sequential `write()` calls if unavailable.
|
|
60
60
|
|
|
61
61
|
```typescript lineNumbers
|
|
62
62
|
await world.streams.writeMulti?.(runId, "default", [chunk1, chunk2]); // [!code highlight]
|
|
@@ -173,7 +173,7 @@ const info = await world.streams.getInfo(runId, "default"); // [!code highlight]
|
|
|
173
173
|
|
|
174
174
|
## Examples
|
|
175
175
|
|
|
176
|
-
### Read a
|
|
176
|
+
### Read a stream as a response
|
|
177
177
|
|
|
178
178
|
```typescript lineNumbers
|
|
179
179
|
// app/api/workflow-streams/read/route.ts
|
|
@@ -192,7 +192,7 @@ export async function GET(req: Request) {
|
|
|
192
192
|
}
|
|
193
193
|
```
|
|
194
194
|
|
|
195
|
-
### Paginate
|
|
195
|
+
### Paginate through stream chunks
|
|
196
196
|
|
|
197
197
|
```typescript lineNumbers
|
|
198
198
|
import { getWorld } from "workflow/runtime";
|
|
@@ -211,6 +211,6 @@ do {
|
|
|
211
211
|
|
|
212
212
|
## Related
|
|
213
213
|
|
|
214
|
-
- [Streaming](/docs/foundations/streaming)
|
|
215
|
-
- [getWritable()](/docs/api-reference/workflow/get-writable)
|
|
216
|
-
- [Storage](/docs/api-reference/workflow-runtime/world/storage)
|
|
214
|
+
- [Streaming](/docs/foundations/streaming): Core concepts for streaming data from workflows
|
|
215
|
+
- [`getWritable()`](/docs/api-reference/workflow/get-writable): The standard way to write to streams from within steps
|
|
216
|
+
- [Storage](/docs/api-reference/workflow-runtime/world/storage): Query runs, steps, hooks, and events
|
|
@@ -23,7 +23,7 @@ class Point {
|
|
|
23
23
|
}
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
## API
|
|
26
|
+
## API signature
|
|
27
27
|
|
|
28
28
|
{/* @skip-typecheck: type-only signature snippet, not compilable code */}
|
|
29
29
|
|
|
@@ -65,5 +65,5 @@ This method runs inside the workflow context and is subject to the same constrai
|
|
|
65
65
|
- No non-deterministic operations (like `Math.random()` or `Date.now()`)
|
|
66
66
|
- No external network calls
|
|
67
67
|
|
|
68
|
-
Keep this method
|
|
68
|
+
Keep this method focused on reconstructing the instance from the provided data.
|
|
69
69
|
</Callout>
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
title: WORKFLOW_SERIALIZE
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
`WORKFLOW_SERIALIZE` defines custom serialization for user-defined class instances. The static method accepts an instance and returns serializable data.
|
|
6
6
|
|
|
7
7
|
## Usage
|
|
8
8
|
|
|
@@ -23,7 +23,7 @@ class Point {
|
|
|
23
23
|
}
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
## API
|
|
26
|
+
## API signature
|
|
27
27
|
|
|
28
28
|
{/* @skip-typecheck: type-only signature snippet, not compilable code */}
|
|
29
29
|
|
|
@@ -60,16 +60,16 @@ The method should return serializable data. This can be:
|
|
|
60
60
|
The method must be implemented as a **static** method on the class. Instance methods are not supported.
|
|
61
61
|
</Callout>
|
|
62
62
|
|
|
63
|
-
- Both `WORKFLOW_SERIALIZE` and `WORKFLOW_DESERIALIZE` must be implemented together
|
|
64
|
-
- The returned data must itself be serializable
|
|
65
|
-
- The SWC compiler plugin automatically detects and registers classes that implement these symbols
|
|
63
|
+
- Both `WORKFLOW_SERIALIZE` and `WORKFLOW_DESERIALIZE` must be implemented together.
|
|
64
|
+
- The returned data must itself be serializable.
|
|
65
|
+
- The SWC compiler plugin automatically detects and registers classes that implement these symbols.
|
|
66
66
|
|
|
67
67
|
<Callout type="warn">
|
|
68
68
|
This method runs inside the workflow context and is subject to the same constraints as `"use workflow"` functions:
|
|
69
69
|
- No Node.js-specific APIs (like `fs`, `path`, `crypto`, etc.)
|
|
70
70
|
- No non-deterministic operations (like `Math.random()` or `Date.now()`)
|
|
71
71
|
- No external network calls
|
|
72
|
-
- No side effects on workflow state
|
|
72
|
+
- No side effects on workflow state: the method may run outside deterministic replay, so mutations would not be reconstructed
|
|
73
73
|
|
|
74
|
-
Keep this method
|
|
74
|
+
Keep this method focused on extracting data from the instance.
|
|
75
75
|
</Callout>
|
|
@@ -23,7 +23,7 @@ export default defineConfig({
|
|
|
23
23
|
});
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
## API
|
|
26
|
+
## API signature
|
|
27
27
|
|
|
28
28
|
### Parameters
|
|
29
29
|
|
|
@@ -35,8 +35,8 @@ export default defineConfig({
|
|
|
35
35
|
|
|
36
36
|
| Option | Type | Default | Description |
|
|
37
37
|
| --- | --- | --- | --- |
|
|
38
|
-
| `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
|
|
38
|
+
| `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. |
|
|
39
39
|
|
|
40
40
|
### Returns
|
|
41
41
|
|
|
42
|
-
Returns an array of Vite `Plugin` objects. Spread or pass the array directly to the `plugins` option of your Vite config
|
|
42
|
+
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.
|
|
@@ -26,7 +26,7 @@ export default defineConfig({
|
|
|
26
26
|
});
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
## API
|
|
29
|
+
## API signature
|
|
30
30
|
|
|
31
31
|
### Parameters
|
|
32
32
|
|
|
@@ -39,10 +39,10 @@ export default defineConfig({
|
|
|
39
39
|
| Option | Type | Default | Description |
|
|
40
40
|
| --- | --- | --- | --- |
|
|
41
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 (
|
|
44
|
-
| `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
|
|
42
|
+
| `typescriptPlugin` | `boolean` | `false` | Adds the `workflow` TypeScript plugin to the generated `tsconfig.json` for integrated development environment (IDE) IntelliSense. |
|
|
43
|
+
| `runtime` | `string` | — | Node.js runtime version for Vercel Functions (for example, `'nodejs22.x'` or `'nodejs24.x'`). Only applies when deploying to Vercel. |
|
|
44
|
+
| `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. |
|
|
45
45
|
|
|
46
46
|
### Returns
|
|
47
47
|
|
|
48
|
-
Returns an array of Vite `Plugin` objects. Spread or pass the array directly to the `plugins` option of your Vite config
|
|
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.
|