workflow 5.0.0-beta.4 → 5.0.0-beta.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (227) hide show
  1. package/README.md +63 -20
  2. package/dist/api-workflow.d.ts +1 -1
  3. package/dist/api-workflow.d.ts.map +1 -1
  4. package/dist/api-workflow.js +1 -1
  5. package/dist/api.d.ts +5 -1
  6. package/dist/api.d.ts.map +1 -1
  7. package/dist/api.js +12 -2
  8. package/dist/index.d.ts +1 -0
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +6 -1
  11. package/dist/internal/builtins.d.ts +17 -0
  12. package/dist/internal/builtins.d.ts.map +1 -1
  13. package/dist/internal/builtins.js +65 -1
  14. package/dist/internal/errors.d.ts +1 -1
  15. package/dist/internal/errors.d.ts.map +1 -1
  16. package/dist/internal/errors.js +2 -2
  17. package/dist/nest-builder.d.ts +2 -0
  18. package/dist/nest-builder.d.ts.map +1 -0
  19. package/dist/nest-builder.js +2 -0
  20. package/dist/nest-vercel-builder.d.ts +2 -0
  21. package/dist/nest-vercel-builder.d.ts.map +1 -0
  22. package/dist/nest-vercel-builder.js +2 -0
  23. package/dist/observability.d.ts +1 -1
  24. package/dist/observability.js +2 -2
  25. package/dist/runtime.d.ts +2 -1
  26. package/dist/runtime.d.ts.map +1 -1
  27. package/dist/runtime.js +5 -2
  28. package/docs/ai/chat-session-modeling.mdx +7 -3
  29. package/docs/ai/defining-tools.mdx +2 -2
  30. package/docs/ai/index.mdx +30 -25
  31. package/docs/ai/message-queueing.mdx +10 -10
  32. package/docs/ai/resumable-streams.mdx +9 -1
  33. package/docs/api-reference/index.mdx +24 -0
  34. package/docs/api-reference/meta.json +8 -0
  35. package/docs/api-reference/vitest/index.mdx +28 -7
  36. package/docs/api-reference/workflow/create-hook.mdx +79 -0
  37. package/docs/api-reference/workflow/create-webhook.mdx +1 -0
  38. package/docs/api-reference/workflow/define-hook.mdx +26 -24
  39. package/docs/api-reference/workflow/fatal-error.mdx +29 -7
  40. package/docs/api-reference/workflow/fetch.mdx +8 -4
  41. package/docs/api-reference/workflow/index.mdx +3 -0
  42. package/docs/api-reference/workflow/set-attributes.mdx +61 -0
  43. package/docs/api-reference/workflow/sleep.mdx +1 -1
  44. package/docs/api-reference/workflow-ai/durable-agent.mdx +7 -45
  45. package/docs/api-reference/workflow-ai/index.mdx +2 -2
  46. package/docs/api-reference/workflow-ai/workflow-chat-transport.mdx +44 -1
  47. package/docs/api-reference/workflow-api/get-hook-by-token.mdx +9 -0
  48. package/docs/api-reference/workflow-api/get-run.mdx +25 -0
  49. package/docs/api-reference/workflow-api/index.mdx +6 -8
  50. package/docs/api-reference/workflow-api/resume-hook.mdx +60 -1
  51. package/docs/api-reference/workflow-api/resume-webhook.mdx +6 -4
  52. package/docs/api-reference/workflow-api/start.mdx +39 -6
  53. package/docs/api-reference/workflow-astro/index.mdx +18 -0
  54. package/docs/api-reference/workflow-astro/meta.json +4 -0
  55. package/docs/api-reference/workflow-astro/workflow.mdx +45 -0
  56. package/docs/api-reference/workflow-errors/hook-conflict-error.mdx +60 -0
  57. package/docs/api-reference/workflow-errors/index.mdx +88 -0
  58. package/docs/api-reference/workflow-errors/meta.json +6 -0
  59. package/docs/api-reference/workflow-errors/precondition-failed-error.mdx +68 -0
  60. package/docs/api-reference/workflow-errors/run-not-supported-error.mdx +58 -0
  61. package/docs/api-reference/workflow-errors/workflow-error.mdx +52 -0
  62. package/docs/api-reference/workflow-errors/workflow-run-failed-error.mdx +16 -6
  63. package/docs/api-reference/workflow-errors/workflow-run-not-completed-error.mdx +58 -0
  64. package/docs/api-reference/workflow-errors/workflow-runtime-error.mdx +58 -0
  65. package/docs/api-reference/workflow-globals.mdx +4 -1
  66. package/docs/api-reference/workflow-nest/configure-workflow-controller.mdx +33 -0
  67. package/docs/api-reference/workflow-nest/index.mdx +31 -0
  68. package/docs/api-reference/workflow-nest/meta.json +9 -0
  69. package/docs/api-reference/workflow-nest/nest-local-builder.mdx +64 -0
  70. package/docs/api-reference/workflow-nest/workflow-controller.mdx +40 -0
  71. package/docs/api-reference/workflow-nest/workflow-module.mdx +74 -0
  72. package/docs/api-reference/workflow-next/with-workflow.mdx +56 -2
  73. package/docs/api-reference/workflow-nitro/index.mdx +60 -0
  74. package/docs/api-reference/workflow-nuxt/index.mdx +48 -0
  75. package/docs/api-reference/workflow-observability/hydrate-data.mdx +35 -0
  76. package/docs/api-reference/workflow-observability/hydrate-resource-io.mdx +62 -0
  77. package/docs/api-reference/workflow-observability/index.mdx +64 -0
  78. package/docs/api-reference/workflow-observability/meta.json +11 -0
  79. package/docs/api-reference/workflow-observability/observability-revivers.mdx +50 -0
  80. package/docs/api-reference/workflow-observability/parse-class-name.mdx +41 -0
  81. package/docs/api-reference/workflow-observability/parse-step-name.mdx +40 -0
  82. package/docs/api-reference/workflow-observability/parse-workflow-name.mdx +55 -0
  83. package/docs/api-reference/workflow-runtime/create-world.mdx +39 -0
  84. package/docs/api-reference/workflow-runtime/get-world-handlers.mdx +44 -0
  85. package/docs/api-reference/{workflow-api → workflow-runtime}/get-world.mdx +7 -10
  86. package/docs/api-reference/workflow-runtime/health-check.mdx +50 -0
  87. package/docs/api-reference/workflow-runtime/index.mdx +43 -0
  88. package/docs/api-reference/workflow-runtime/meta.json +12 -0
  89. package/docs/api-reference/workflow-runtime/set-world.mdx +49 -0
  90. package/docs/api-reference/workflow-runtime/workflow-entrypoint.mdx +42 -0
  91. package/docs/api-reference/workflow-runtime/world/analytics.mdx +138 -0
  92. package/docs/api-reference/{workflow-api → workflow-runtime}/world/index.mdx +10 -10
  93. package/docs/api-reference/workflow-runtime/world/meta.json +4 -0
  94. package/docs/api-reference/{workflow-api → workflow-runtime}/world/queue.mdx +8 -6
  95. package/docs/api-reference/{workflow-api → workflow-runtime}/world/storage.mdx +24 -7
  96. package/docs/api-reference/{workflow-api → workflow-runtime}/world/streams.mdx +2 -2
  97. package/docs/api-reference/workflow-serde/index.mdx +0 -1
  98. package/docs/api-reference/workflow-serde/workflow-deserialize.mdx +1 -2
  99. package/docs/api-reference/workflow-serde/workflow-serialize.mdx +2 -2
  100. package/docs/api-reference/workflow-sveltekit/index.mdx +18 -0
  101. package/docs/api-reference/workflow-sveltekit/meta.json +4 -0
  102. package/docs/api-reference/workflow-sveltekit/workflow-plugin.mdx +42 -0
  103. package/docs/api-reference/workflow-vite/index.mdx +18 -0
  104. package/docs/api-reference/workflow-vite/meta.json +4 -0
  105. package/docs/api-reference/workflow-vite/workflow.mdx +48 -0
  106. package/docs/changelog/attributes-mvp.mdx +380 -0
  107. package/docs/changelog/eager-processing.mdx +269 -0
  108. package/docs/changelog/index.mdx +3 -1
  109. package/docs/changelog/lazy-event-creation.md +127 -0
  110. package/docs/changelog/meta.json +9 -1
  111. package/docs/changelog/resilient-resume.mdx +22 -0
  112. package/docs/changelog/resilient-start.mdx +31 -283
  113. package/docs/changelog/step-message-ownership.mdx +360 -0
  114. package/docs/changelog/turbo-mode.md +87 -0
  115. package/docs/comparisons/index.mdx +66 -0
  116. package/docs/comparisons/meta.json +11 -0
  117. package/docs/comparisons/workflow-sdk-vs-aws-agentcore.mdx +55 -0
  118. package/docs/comparisons/workflow-sdk-vs-aws-step-functions.mdx +111 -0
  119. package/docs/comparisons/workflow-sdk-vs-cloudflare-workflows.mdx +71 -0
  120. package/docs/comparisons/workflow-sdk-vs-inngest.mdx +102 -0
  121. package/docs/comparisons/workflow-sdk-vs-temporal.mdx +123 -0
  122. package/docs/comparisons/workflow-sdk-vs-trigger-dev.mdx +103 -0
  123. package/docs/configuration/build-and-diagnostics.mdx +70 -0
  124. package/docs/configuration/cli-and-web-ui.mdx +182 -0
  125. package/docs/configuration/framework-options.mdx +165 -0
  126. package/docs/configuration/index.mdx +32 -0
  127. package/docs/configuration/meta.json +12 -0
  128. package/docs/configuration/runtime-tuning.mdx +281 -0
  129. package/docs/configuration/worlds.mdx +283 -0
  130. package/docs/cookbook/advanced/child-workflows.mdx +203 -256
  131. package/docs/cookbook/advanced/meta.json +1 -1
  132. package/docs/cookbook/advanced/publishing-libraries.mdx +33 -24
  133. package/docs/cookbook/advanced/serializable-steps.mdx +12 -4
  134. package/docs/cookbook/advanced/upgrading-workflows.mdx +199 -0
  135. package/docs/cookbook/agent-patterns/agent-cancellation.mdx +34 -75
  136. package/docs/cookbook/agent-patterns/durable-agent.mdx +14 -142
  137. package/docs/cookbook/agent-patterns/human-in-the-loop.mdx +11 -3
  138. package/docs/cookbook/common-patterns/batching.mdx +4 -0
  139. package/docs/cookbook/common-patterns/idempotency.mdx +40 -52
  140. package/docs/cookbook/common-patterns/rate-limiting.mdx +5 -1
  141. package/docs/cookbook/common-patterns/saga.mdx +6 -2
  142. package/docs/cookbook/common-patterns/scheduling.mdx +12 -0
  143. package/docs/cookbook/common-patterns/sequential-and-parallel.mdx +4 -0
  144. package/docs/cookbook/common-patterns/timeouts.mdx +6 -1
  145. package/docs/cookbook/common-patterns/webhooks.mdx +4 -0
  146. package/docs/cookbook/common-patterns/workflow-composition.mdx +19 -16
  147. package/docs/cookbook/index.mdx +3 -3
  148. package/docs/cookbook/integrations/ai-sdk.mdx +64 -28
  149. package/docs/cookbook/integrations/chat-sdk.mdx +17 -0
  150. package/docs/cookbook/integrations/sandbox.mdx +17 -0
  151. package/docs/{deploying/index.mdx → deploying.mdx} +7 -7
  152. package/docs/errors/abort-signal-timeout-in-workflow.mdx +84 -0
  153. package/docs/errors/corrupted-event-log.mdx +11 -8
  154. package/docs/errors/deployment-mismatch.mdx +71 -0
  155. package/docs/errors/fetch-in-workflow.mdx +4 -0
  156. package/docs/errors/hook-conflict.mdx +60 -4
  157. package/docs/errors/index.mdx +1 -35
  158. package/docs/errors/node-js-module-in-workflow.mdx +4 -0
  159. package/docs/errors/replay-divergence.mdx +27 -0
  160. package/docs/errors/runtime-decryption-failed.mdx +77 -0
  161. package/docs/errors/serialization-failed.mdx +4 -0
  162. package/docs/errors/start-invalid-workflow-function.mdx +4 -0
  163. package/docs/errors/step-executed-multiple-times.mdx +23 -0
  164. package/docs/errors/step-not-registered.mdx +1 -1
  165. package/docs/errors/timeout-in-workflow.mdx +4 -0
  166. package/docs/errors/webhook-response-not-sent.mdx +4 -0
  167. package/docs/foundations/cancellation.mdx +459 -0
  168. package/docs/foundations/errors-and-retries.mdx +7 -3
  169. package/docs/foundations/hooks.mdx +29 -0
  170. package/docs/foundations/idempotency.mdx +243 -11
  171. package/docs/foundations/index.mdx +1 -23
  172. package/docs/foundations/meta.json +3 -1
  173. package/docs/foundations/serialization.mdx +77 -41
  174. package/docs/foundations/starting-workflows.mdx +79 -2
  175. package/docs/foundations/streaming.mdx +14 -23
  176. package/docs/foundations/versioning.mdx +263 -0
  177. package/docs/getting-started/astro.mdx +12 -2
  178. package/docs/getting-started/express.mdx +6 -2
  179. package/docs/getting-started/fastify.mdx +6 -2
  180. package/docs/getting-started/hono.mdx +6 -2
  181. package/docs/getting-started/index.mdx +16 -10
  182. package/docs/getting-started/meta.json +4 -1
  183. package/docs/getting-started/nestjs.mdx +77 -3
  184. package/docs/getting-started/next.mdx +12 -6
  185. package/docs/getting-started/nitro.mdx +28 -2
  186. package/docs/getting-started/nuxt.mdx +6 -2
  187. package/docs/getting-started/python.mdx +24 -18
  188. package/docs/getting-started/react-router/index.mdx +33 -0
  189. package/docs/getting-started/react-router/meta.json +5 -0
  190. package/docs/getting-started/react-router/v7.mdx +237 -0
  191. package/docs/getting-started/react-router/v8.mdx +232 -0
  192. package/docs/getting-started/sveltekit.mdx +12 -2
  193. package/docs/getting-started/tanstack-start.mdx +245 -0
  194. package/docs/getting-started/vite.mdx +6 -2
  195. package/docs/how-it-works/cancellation.mdx +287 -0
  196. package/docs/how-it-works/code-transform.mdx +21 -17
  197. package/docs/how-it-works/encryption.mdx +5 -5
  198. package/docs/how-it-works/event-sourcing.mdx +17 -9
  199. package/docs/how-it-works/framework-integrations.mdx +96 -337
  200. package/docs/how-it-works/meta.json +2 -1
  201. package/docs/internal/index.mdx +21 -0
  202. package/docs/internal/meta.json +10 -0
  203. package/docs/internal/nitro-native-build.mdx +38 -0
  204. package/docs/internal/nitro-web-ui.mdx +24 -0
  205. package/docs/internal/serializable-abort-controller.mdx +148 -0
  206. package/docs/meta.json +2 -2
  207. package/docs/observability/attributes.mdx +112 -0
  208. package/docs/observability/index.mdx +20 -1
  209. package/docs/observability/meta.json +1 -1
  210. package/docs/observability/tracing.mdx +124 -0
  211. package/docs/testing/index.mdx +2 -2
  212. package/package.json +17 -13
  213. package/docs/api-reference/workflow-api/world/meta.json +0 -4
  214. package/docs/api-reference/workflow-api/world/observability.mdx +0 -164
  215. package/docs/cookbook/advanced/distributed-abort-controller.mdx +0 -318
  216. package/docs/deploying/building-a-world.mdx +0 -251
  217. package/docs/deploying/meta.json +0 -4
  218. package/docs/deploying/world/local-world.mdx +0 -84
  219. package/docs/deploying/world/meta.json +0 -4
  220. package/docs/deploying/world/postgres-world.mdx +0 -222
  221. package/docs/deploying/world/vercel-world.mdx +0 -179
  222. package/docs/migration-guides/index.mdx +0 -34
  223. package/docs/migration-guides/meta.json +0 -9
  224. package/docs/migration-guides/migrating-from-aws-step-functions.mdx +0 -363
  225. package/docs/migration-guides/migrating-from-inngest.mdx +0 -314
  226. package/docs/migration-guides/migrating-from-temporal.mdx +0 -318
  227. package/docs/migration-guides/migrating-from-trigger-dev.mdx +0 -337
@@ -1,251 +0,0 @@
1
- ---
2
- title: Building a World
3
- description: Implement the World interface to run workflows on any custom infrastructure.
4
- type: guide
5
- summary: Build a custom World adapter to run workflows on your own infrastructure.
6
- prerequisites:
7
- - /docs/deploying
8
- - /docs/foundations/workflows-and-steps
9
- related:
10
- - /docs/deploying/world/local-world
11
- - /docs/deploying/world/postgres-world
12
- - /docs/deploying/world/vercel-world
13
- ---
14
-
15
- A **World** is the abstraction that allows workflows to run on any infrastructure. It handles workflow storage, step execution queuing, and data streaming. This guide explains the World interface and how to implement your own.
16
-
17
- <Callout>
18
- Before building a custom World, check the [Worlds Ecosystem](/worlds) page — there may already be a community implementation for your infrastructure.
19
- </Callout>
20
-
21
- <Callout type="info">
22
- **Reference Implementation:** The [Postgres World source code](https://github.com/vercel/workflow/tree/main/packages/world-postgres) is a production-ready example of how to implement the World interface with a database backend and graphile-worker for queuing.
23
- </Callout>
24
-
25
- ## What is a World?
26
-
27
- A World connects workflows to the infrastructure that powers them. The World interface abstracts three core responsibilities:
28
-
29
- 1. **Storage** — Persisting workflow runs, steps, hooks, and the event log
30
- 2. **Queue** — Enqueuing and processing workflow and step invocations
31
- 3. **Streamer** — Managing real-time data streams between workflows and clients
32
-
33
- {/* @skip-typecheck - interface definition, not runnable code */}
34
- ```typescript
35
- interface World extends Storage, Queue, Streamer {
36
- start?(): Promise<void>;
37
- close?(): Promise<void>;
38
- getEncryptionKeyForRun?(run: WorkflowRun): Promise<Uint8Array | undefined>;
39
- getEncryptionKeyForRun?(runId: string, context?: Record<string, unknown>): Promise<Uint8Array | undefined>;
40
- }
41
- ```
42
-
43
- The optional `start()` method initializes background tasks (for example, queue polling). The optional `close()` method releases resources like connection pools and listeners. The optional `getEncryptionKeyForRun()` method returns the AES-256 key used to encrypt data for a run; if it is not implemented, encryption is disabled.
44
-
45
- ## The Event Log Model
46
-
47
- Workflow storage is built on an **append-only event log**. All state changes happen through events — you never modify runs, steps, or hooks directly. Instead, you create events that update the materialized state.
48
-
49
- Events fall into three categories: run lifecycle events, step lifecycle events, and hook lifecycle events. See the [Event Sourcing](/docs/how-it-works/event-sourcing) documentation for a complete list of event types and their semantics.
50
-
51
- ## Storage Interface
52
-
53
- The Storage interface provides read access to materialized entities and write access through events:
54
-
55
- {/* @skip-typecheck - interface definition, not runnable code */}
56
- ```typescript
57
- interface Storage {
58
- runs: {
59
- get(id: string, params?: GetWorkflowRunParams): Promise<WorkflowRun>;
60
- list(params?: ListWorkflowRunsParams): Promise<PaginatedResponse<WorkflowRun>>;
61
- };
62
-
63
- steps: {
64
- get(runId: string | undefined, stepId: string, params?: GetStepParams): Promise<Step>;
65
- list(params: ListWorkflowRunStepsParams): Promise<PaginatedResponse<Step>>;
66
- };
67
-
68
- events: {
69
- // Create a new workflow run (runId may be client-provided or null for server generation)
70
- create(runId: string | null, data: RunCreatedEventRequest, params?: CreateEventParams): Promise<EventResult>;
71
-
72
- // Create an event for an existing run
73
- create(runId: string, data: CreateEventRequest, params?: CreateEventParams): Promise<EventResult>;
74
-
75
- list(params: ListEventsParams): Promise<PaginatedResponse<Event>>;
76
- listByCorrelationId(params: ListEventsByCorrelationIdParams): Promise<PaginatedResponse<Event>>;
77
- };
78
-
79
- hooks: {
80
- get(hookId: string, params?: GetHookParams): Promise<Hook>;
81
- getByToken(token: string, params?: GetHookParams): Promise<Hook>;
82
- list(params: ListHooksParams): Promise<PaginatedResponse<Hook>>;
83
- };
84
- }
85
- ```
86
-
87
- ### Key Implementation Details
88
-
89
- **Event Creation:** When `events.create()` is called, your implementation must:
90
- 1. Persist the event to the event log
91
- 2. Atomically update the affected entity (run, step, or hook)
92
- 3. Return both the created event and the updated entity
93
-
94
- **Run Creation:** For `run_created` events, the `runId` parameter may be a client-provided string or `null`. When `null`, your World generates and returns a new `runId`.
95
-
96
- **Hook Tokens:** Hook tokens must be unique. If a `hook_created` event conflicts with an existing token, return a `hook_conflict` event instead.
97
-
98
- **Automatic Hook Disposal:** When a workflow reaches a terminal state (`completed`, `failed`, or `cancelled`), automatically dispose of all associated hooks to release tokens for reuse.
99
-
100
- ## Queue Interface
101
-
102
- The Queue interface handles asynchronous execution of workflows and steps:
103
-
104
- {/* @skip-typecheck - interface definition, not runnable code */}
105
- ```typescript
106
- interface Queue {
107
- getDeploymentId(): Promise<string>;
108
-
109
- queue(
110
- queueName: ValidQueueName,
111
- message: QueuePayload,
112
- opts?: QueueOptions
113
- ): Promise<{ messageId: MessageId }>;
114
-
115
- createQueueHandler(
116
- queueNamePrefix: QueuePrefix,
117
- handler: (message: unknown, meta: { attempt: number; queueName: ValidQueueName; messageId: MessageId }) => Promise<void | { timeoutSeconds: number }>
118
- ): (req: Request) => Promise<Response>;
119
- }
120
- ```
121
-
122
- ### Queue Names
123
-
124
- Queue names follow a specific pattern:
125
- - `__wkf_workflow_<name>` — For workflow invocations
126
- - `__wkf_step_<name>` — For step invocations
127
-
128
- ### Message Payloads
129
-
130
- Two types of messages flow through queues:
131
-
132
- **Workflow Invocations:**
133
- {/* @skip-typecheck - interface definition, not runnable code */}
134
- ```typescript
135
- interface WorkflowInvokePayload {
136
- runId: string;
137
- traceCarrier?: Record<string, string>; // OpenTelemetry context
138
- requestedAt?: Date;
139
- }
140
- ```
141
-
142
- **Step Invocations:**
143
- {/* @skip-typecheck - interface definition, not runnable code */}
144
- ```typescript
145
- interface StepInvokePayload {
146
- workflowName: string;
147
- workflowRunId: string;
148
- workflowStartedAt: number;
149
- stepId: string;
150
- traceCarrier?: Record<string, string>;
151
- requestedAt?: Date;
152
- }
153
- ```
154
-
155
- ### Implementation Considerations
156
-
157
- - Messages must be delivered at-least-once
158
- - Support configurable retry policies
159
- - Track attempt counts for observability
160
- - Implement idempotency using the `idempotencyKey` option when provided
161
-
162
- ## Streamer Interface
163
-
164
- The Streamer interface enables real-time data streaming:
165
-
166
- {/* @skip-typecheck - interface definition, not runnable code */}
167
- ```typescript
168
- interface Streamer {
169
- streamFlushIntervalMs?: number;
170
-
171
- streams: {
172
- write(
173
- runId: string,
174
- name: string,
175
- chunk: string | Uint8Array
176
- ): Promise<void>;
177
-
178
- writeMulti?(
179
- runId: string,
180
- name: string,
181
- chunks: (string | Uint8Array)[]
182
- ): Promise<void>;
183
-
184
- close(runId: string, name: string): Promise<void>;
185
-
186
- get(
187
- runId: string,
188
- name: string,
189
- startIndex?: number
190
- ): Promise<ReadableStream<Uint8Array>>;
191
-
192
- list(runId: string): Promise<string[]>;
193
-
194
- /** Paginated snapshot of stream chunks. */
195
- getChunks(
196
- runId: string,
197
- name: string,
198
- options?: { limit?: number; cursor?: string }
199
- ): Promise<{
200
- data: { index: number; data: Uint8Array }[];
201
- cursor: string | null;
202
- hasMore: boolean;
203
- done: boolean;
204
- }>;
205
-
206
- /** Lightweight metadata: tail index and completion flag. */
207
- getInfo(
208
- runId: string,
209
- name: string
210
- ): Promise<{ tailIndex: number; done: boolean }>;
211
- };
212
- }
213
- ```
214
-
215
- Streams are identified by a combination of `runId` and `name`. Each workflow run can have multiple named streams.
216
- `writeMulti()` is an optional optimization for batching multiple writes.
217
-
218
- `getChunks` returns a paginated snapshot of currently available chunks (unlike `get` which returns a live `ReadableStream` that waits for new chunks). `getInfo` returns the tail index (last chunk index, 0-based, or `-1` when empty) and whether the stream is complete — useful for resolving negative `startIndex` values into absolute positions.
219
-
220
- ## Reference Implementations
221
-
222
- Study these implementations for guidance:
223
-
224
- - **[Local World](https://github.com/vercel/workflow/tree/main/packages/world-local)** — Filesystem-based, great for understanding the basics
225
- - **[Postgres World](https://github.com/vercel/workflow/tree/main/packages/world-postgres)** — Database-backed with graphile-worker for queuing
226
-
227
- ## Testing Your World
228
-
229
- Workflow SDK includes an E2E test suite that validates World implementations. Once your World is published to npm:
230
-
231
- 1. Add your world to [`worlds-manifest.json`](https://github.com/vercel/workflow/blob/main/worlds-manifest.json)
232
- 2. Open a PR to the Workflow repository
233
- 3. CI will automatically run the E2E test suite against your implementation
234
-
235
- Your world will then appear on the [Worlds Ecosystem](/worlds) page with its compatibility status and performance benchmarks.
236
-
237
- ## Publishing Your World
238
-
239
- 1. **Package your World** — Export a default World instance from your package
240
- 2. **Publish to npm** — Publish your package to npm
241
- 3. **Add to the manifest** — Submit a PR adding your world to [`worlds-manifest.json`](https://github.com/vercel/workflow/blob/main/worlds-manifest.json)
242
- 4. **Document configuration** — Clearly document any required environment variables
243
-
244
- ```json
245
- // worlds-manifest.json entry
246
- {
247
- "package": "your-world-package",
248
- "repository": "https://github.com/you/your-world",
249
- "docs": "https://github.com/you/your-world#readme"
250
- }
251
- ```
@@ -1,4 +0,0 @@
1
- {
2
- "title": "Deploying",
3
- "pages": ["...deploying", "building-a-world"]
4
- }
@@ -1,84 +0,0 @@
1
- ---
2
- title: Local World
3
- description: Zero-config world bundled with Workflow for local development. No external services required.
4
- type: integration
5
- summary: Set up the Local World for zero-config workflow development on your machine.
6
- prerequisites:
7
- - /docs/deploying
8
- related:
9
- - /docs/deploying/world/postgres-world
10
- - /docs/deploying/world/vercel-world
11
- ---
12
-
13
- The Local World is bundled with `workflow` and used automatically during local development. No installation or configuration required.
14
-
15
- To explicitly use the local world in any environment, set the environment variable:
16
-
17
- ```bash
18
- WORKFLOW_TARGET_WORLD=local
19
- ```
20
-
21
- ## Observability
22
-
23
- The `workflow` CLI uses the local world by default. Running these commands inside your workflow project will show your local development workflows:
24
-
25
- ```bash
26
- # List recent workflow runs
27
- npx workflow inspect runs
28
-
29
- # Launch the web UI
30
- npx workflow web
31
- ```
32
-
33
- Learn more in the [Observability](/docs/observability) documentation.
34
-
35
- ## Testing & Compatibility
36
-
37
- <WorldTestingPerformance />
38
-
39
- ## Configuration
40
-
41
- The local world works with zero configuration, but you can customize behavior through environment variables or programmatically via `createLocalWorld()`.
42
-
43
- ### `WORKFLOW_LOCAL_DATA_DIR`
44
-
45
- Directory for storing workflow data as JSON files. Default: `.workflow-data/`
46
-
47
- ### `PORT`
48
-
49
- The application dev server port. Used to enqueue steps and workflows. Default: auto-detected
50
-
51
- ### `WORKFLOW_LOCAL_BASE_URL`
52
-
53
- Full base URL override for HTTPS or custom hostnames. Default: `http://localhost:{port}`
54
-
55
- Port resolution priority: `baseUrl` > `port` > `PORT` > auto-detected
56
-
57
- ### `WORKFLOW_LOCAL_QUEUE_CONCURRENCY`
58
-
59
- Maximum number of concurrent queue workers. Default: `100`
60
-
61
- ### Programmatic configuration
62
-
63
- {/* @skip-typecheck: incomplete code sample */}
64
- ```typescript title="workflow.config.ts" lineNumbers
65
- import { createLocalWorld } from "@workflow/world-local";
66
-
67
- const world = createLocalWorld({
68
- dataDir: "./custom-workflow-data",
69
- port: 5173,
70
- // baseUrl overrides port if set
71
- baseUrl: "https://local.example.com:3000",
72
- });
73
- ```
74
-
75
- ## Limitations
76
-
77
- The local world is designed for development, not production:
78
-
79
- - **In-memory queue** - Steps are queued in memory and do not persist across server restarts
80
- - **Filesystem storage** - Data is stored in local JSON files
81
- - **Single instance** - Cannot handle distributed deployments
82
- - **No authentication** - Suitable only for local development
83
-
84
- For production deployments, use the [Vercel World](/worlds/vercel) or [Postgres World](/worlds/postgres).
@@ -1,4 +0,0 @@
1
- {
2
- "title": "World",
3
- "pages": ["local-world", "vercel-world", "postgres-world"]
4
- }
@@ -1,222 +0,0 @@
1
- ---
2
- title: Postgres World
3
- description: Production-ready, self-hosted world using PostgreSQL for storage and graphile-worker for job processing.
4
- type: integration
5
- summary: Deploy workflows to your own infrastructure using PostgreSQL and graphile-worker.
6
- prerequisites:
7
- - /docs/deploying
8
- related:
9
- - /docs/deploying/world/local-world
10
- - /docs/deploying/world/vercel-world
11
- ---
12
-
13
- The Postgres World is a production-ready backend for self-hosted deployments. It uses PostgreSQL for durable storage and [graphile-worker](https://github.com/graphile/worker) for reliable job processing.
14
-
15
- Use the Postgres World when you need to deploy workflows on your own infrastructure outside of Vercel - such as a Docker container, Kubernetes cluster, or any cloud that supports long-running servers.
16
-
17
- ## Installation
18
-
19
- Install the Postgres World package in your workflow project:
20
-
21
- ```package-install
22
- @workflow/world-postgres
23
- ```
24
-
25
- Configure the required environment variables to use the world and point it to your PostgreSQL database:
26
-
27
- ```bash title=".env"
28
- WORKFLOW_TARGET_WORLD="@workflow/world-postgres"
29
- WORKFLOW_POSTGRES_URL="postgres://user:password@host:5432/database"
30
- ```
31
-
32
- Run the migration script to create the necessary tables in your database. Ensure `WORKFLOW_POSTGRES_URL` is set when running this command:
33
-
34
- ```bash
35
- npx workflow-postgres-setup
36
- ```
37
-
38
- <Callout type="info">
39
- The migration is idempotent and can safely be run as a post-deployment lifecycle script.
40
- </Callout>
41
-
42
- ## Starting the World
43
-
44
- To subscribe to the graphile-worker queue, your workflow app needs to start the world on server start. Here are examples for a few frameworks:
45
-
46
- <Tabs items={["Next.js", "SvelteKit", "Nitro"]}>
47
-
48
- <Tab value="Next.js">
49
-
50
- Create an `instrumentation.ts` file in your project root:
51
-
52
- ```ts title="instrumentation.ts" lineNumbers
53
- export async function register() {
54
- if (process.env.NEXT_RUNTIME !== "edge") {
55
- const { getWorld } = await import("workflow/runtime");
56
- const world = await getWorld();
57
- await world.start?.();
58
- }
59
- }
60
- ```
61
-
62
- <Callout type="info">
63
- Learn more about [Next.js Instrumentation](https://nextjs.org/docs/app/guides/instrumentation).
64
- </Callout>
65
-
66
- </Tab>
67
-
68
- <Tab value="SvelteKit">
69
-
70
- Create a `src/hooks.server.ts` file:
71
-
72
- ```ts title="src/hooks.server.ts" lineNumbers
73
- import type { ServerInit } from "@sveltejs/kit";
74
-
75
- export const init: ServerInit = async () => {
76
- const { getWorld } = await import("workflow/runtime");
77
- const world = await getWorld();
78
- await world.start?.();
79
- };
80
- ```
81
-
82
- <Callout type="info">
83
- Learn more about [SvelteKit Hooks](https://svelte.dev/docs/kit/hooks).
84
- </Callout>
85
-
86
- </Tab>
87
-
88
- <Tab value="Nitro">
89
-
90
- Create a plugin to start the world on server initialization:
91
-
92
- ```ts title="plugins/start-pg-world.ts" lineNumbers
93
- import { defineNitroPlugin } from "nitro/~internal/runtime/plugin";
94
-
95
- export default defineNitroPlugin(async () => {
96
- const { getWorld } = await import("workflow/runtime");
97
- const world = await getWorld();
98
- await world.start?.();
99
- });
100
- ```
101
-
102
- Register the plugin in your config:
103
-
104
- ```ts title="nitro.config.ts"
105
- import { defineNitroConfig } from "nitropack";
106
-
107
- export default defineNitroConfig({
108
- modules: ["workflow/nitro"],
109
- plugins: ["plugins/start-pg-world.ts"],
110
- });
111
- ```
112
-
113
- <Callout type="info">
114
- Learn more about [Nitro Plugins](https://v3.nitro.build/docs/plugins).
115
- </Callout>
116
-
117
- </Tab>
118
-
119
- </Tabs>
120
-
121
- <Callout type="info">
122
- The Postgres World requires a long-lived worker process that polls the database for jobs. This does not work on serverless environments. For Vercel deployments, use the [Vercel World](/worlds/vercel) instead.
123
- </Callout>
124
-
125
- ## Observability
126
-
127
- Use the `workflow` CLI to inspect workflows stored in PostgreSQL:
128
-
129
- ```bash
130
- # Set your database URL
131
- export WORKFLOW_POSTGRES_URL="postgres://user:password@host:5432/database"
132
-
133
- # List workflow runs
134
- npx workflow inspect runs --backend @workflow/world-postgres
135
-
136
- # Launch the web UI
137
- npx workflow web --backend @workflow/world-postgres
138
- ```
139
-
140
- If `WORKFLOW_POSTGRES_URL` is not set, the CLI defaults to `postgres://world:world@localhost:5432/world`.
141
-
142
- Learn more in the [Observability](/docs/observability) documentation.
143
-
144
- ## Testing & Compatibility
145
-
146
- <WorldTestingPerformance />
147
-
148
- ## Configuration
149
-
150
- All configuration options can be set via environment variables or programmatically via `createWorld()`.
151
-
152
- ### `WORKFLOW_POSTGRES_URL` (required)
153
-
154
- PostgreSQL connection string. Falls back to `DATABASE_URL` if not set.
155
-
156
- Default: `postgres://world:world@localhost:5432/world`
157
-
158
- ### `WORKFLOW_POSTGRES_JOB_PREFIX`
159
-
160
- Prefix for graphile-worker queue job names. Useful when sharing a database between multiple applications.
161
-
162
- ### `WORKFLOW_POSTGRES_WORKER_CONCURRENCY`
163
-
164
- Number of concurrent workers polling for jobs. Default: `10`
165
-
166
- ### `WORKFLOW_POSTGRES_MAX_POOL_SIZE`
167
-
168
- Maximum size of the internal `pg.Pool` used when `createWorld()` constructs the pool. Default: `10`
169
-
170
- For higher worker concurrency, Graphile Worker recommends setting `maxPoolSize` to `10` or `queueConcurrency + 2`, whichever is larger.
171
-
172
- ### Programmatic configuration
173
-
174
- {/*@skip-typecheck: incomplete code sample*/}
175
-
176
- ```typescript title="workflow.config.ts" lineNumbers
177
- import { createWorld } from "@workflow/world-postgres";
178
-
179
- const world = createWorld({
180
- connectionString: "postgres://user:password@host:5432/database",
181
- jobPrefix: "myapp_",
182
- queueConcurrency: 20,
183
- maxPoolSize: 20, // overrides WORKFLOW_POSTGRES_MAX_POOL_SIZE
184
- });
185
- ```
186
-
187
- ## How It Works
188
-
189
- The Postgres World uses PostgreSQL as a durable backend:
190
-
191
- - **Storage** - Workflow runs, events, steps, and hooks are stored in PostgreSQL tables
192
- - **Job Queue** - [graphile-worker](https://github.com/graphile/worker) handles reliable job processing with retries
193
- - **Streaming** - PostgreSQL NOTIFY/LISTEN enables real-time event distribution
194
-
195
- This architecture ensures workflows survive application restarts with all state reliably persisted. For implementation details, see the [source code](https://github.com/vercel/workflow/tree/main/packages/world-postgres).
196
-
197
- ## Deployment
198
-
199
- Deploy your application to any cloud that supports long-running servers:
200
-
201
- - Docker containers
202
- - Kubernetes clusters
203
- - Virtual machines
204
- - Platform-as-a-Service providers (Railway, Render, Fly.io, etc.)
205
-
206
- Ensure your deployment has:
207
-
208
- 1. Network access to your PostgreSQL database
209
- 2. Environment variables configured correctly
210
- 3. The `start()` function called on server initialization
211
-
212
- <Callout type="info">
213
- The Postgres World is not compatible with Vercel deployments. On Vercel, workflows automatically use the [Vercel World](/worlds/vercel) with zero configuration.
214
- </Callout>
215
-
216
- ## Limitations
217
-
218
- - **Requires long-running process** - Must call `start()` on server initialization; not compatible with serverless platforms
219
- - **PostgreSQL infrastructure** - Requires a PostgreSQL database (self-hosted or managed)
220
- - **Not compatible with Vercel** - Use the [Vercel World](/worlds/vercel) for Vercel deployments
221
-
222
- For local development, use the [Local World](/worlds/local) which requires no external services.