@vite-hub/workflow 0.3.1 → 0.5.0

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 (45) hide show
  1. package/README.md +79 -44
  2. package/dist/{app-CmMq8l4t.js → app-2Y7sBAG6.js} +1 -1
  3. package/dist/{client-CU5rELC0.js → client-CgBcDlGn.js} +155 -80
  4. package/dist/{cloudflare-BfFnNWB0.js → cloudflare-Datj_znU.js} +1 -1
  5. package/dist/{config-DCvRDlxA.js → config-z1651xc2.js} +1 -1
  6. package/dist/definition.d.ts +10 -11
  7. package/dist/definition.js +24 -22
  8. package/dist/{delay--ESDybVT.js → delay-CHN4tv3i.js} +6 -42
  9. package/dist/durability.d.ts +1 -1
  10. package/dist/{error-diagnostics-DSkCJC_L.js → error-diagnostics-C0KyI408.js} +10 -2
  11. package/dist/{error-diagnostics-8YNJ37rP.js → error-diagnostics-DMeaFmQD.js} +68 -19
  12. package/dist/{errors-DCqRnZpN.js → errors-BNxEeeCO.js} +0 -4
  13. package/dist/{errors-DVwFb6Fd.d.ts → errors-D-fNDVg0.d.ts} +12 -6
  14. package/dist/index.d.ts +32 -11
  15. package/dist/index.js +13 -6
  16. package/dist/{openworkflow-TEaNk0LV.d.ts → openworkflow-BoaENgh9.d.ts} +8 -7
  17. package/dist/{operation-definition-8gOe-ubD.d.ts → operation-definition-CI2PJGqu.d.ts} +13 -2
  18. package/dist/{operations-B0L8kV5s.js → operations-CYntpf-T.js} +34 -41
  19. package/dist/operations.d.ts +5 -8
  20. package/dist/operations.js +27 -32
  21. package/dist/{out-fRNaVslw.js → out-DxLKolA0.js} +1 -1
  22. package/dist/{rolldown-runtime-CMFfr-1z.js → rolldown-runtime-B4iAMlE-.js} +10 -1
  23. package/dist/{run-error-DBWqiJHH.js → run-error-Ctn50EYz.js} +1 -2
  24. package/dist/run-failed-gVGo1BaF.js +18 -0
  25. package/dist/runtime/cloudflare-runner.d.ts +12 -2
  26. package/dist/runtime/cloudflare-runner.js +28 -9
  27. package/dist/runtime/cloudflare-vite.d.ts +1 -1
  28. package/dist/runtime/cloudflare-vite.js +2 -2
  29. package/dist/runtime/dev-runs.js +1 -0
  30. package/dist/runtime/execute.d.ts +25 -4
  31. package/dist/runtime/execute.js +168 -43
  32. package/dist/runtime/openworkflow-worker.d.ts +2 -2
  33. package/dist/runtime/openworkflow-worker.js +4 -9
  34. package/dist/runtime/openworkflow.d.ts +2 -2
  35. package/dist/runtime/openworkflow.js +60 -49
  36. package/dist/runtime/state.d.ts +1 -1
  37. package/dist/runtime/state.js +4 -6
  38. package/dist/runtime/vercel-vite.d.ts +1 -1
  39. package/dist/runtime/vercel-vite.js +2 -2
  40. package/dist/signals-C1iolifd.js +80 -0
  41. package/dist/{types-CnKVDnEp.d.ts → types-BWPHeugk.d.ts} +99 -28
  42. package/dist/{vercel-BZU_O6ay.js → vercel-BIkBFrQQ.js} +6 -14
  43. package/dist/vite.d.ts +27 -16
  44. package/dist/vite.js +3404 -961
  45. package/package.json +4 -4
package/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # @vite-hub/workflow
2
2
 
3
3
  <p>
4
- <a href="https://vitehub.dev"><img alt="ViteHub" src="https://comark-ui.onmax.me/badge.svg?label=ViteHub&amp;value=vitehub.dev"></a>
5
- <img alt="TypeScript" src="https://comark-ui.onmax.me/badge.svg?label=TypeScript&amp;value=ready">
6
- <img alt="Vite" src="https://comark-ui.onmax.me/badge.svg?label=Vite&amp;value=discovery">
7
- <img alt="Workflow" src="https://comark-ui.onmax.me/badge.svg?label=Workflow&amp;value=durable+steps">
4
+ <a href="https://vitehub.dev"><img alt="ViteHub" src="https://img.shields.io/static/v1?label=ViteHub&amp;message=vitehub.dev&amp;color=blue"></a>
5
+ <img alt="TypeScript" src="https://img.shields.io/static/v1?label=TypeScript&amp;message=ready&amp;color=blue">
6
+ <img alt="Vite" src="https://img.shields.io/static/v1?label=Vite&amp;message=discovery&amp;color=blue">
7
+ <img alt="Workflow" src="https://img.shields.io/static/v1?label=Workflow&amp;message=durable+steps&amp;color=blue">
8
8
  </p>
9
9
 
10
10
  `@vite-hub/workflow` discovers named long-running work and exposes one provider-neutral API for starting and inspecting runs.
@@ -37,20 +37,22 @@ The former `workflow.database` option was never connected to Named Databases. It
37
37
  // server/workflows/onboard-user.ts
38
38
  import { defineWorkflow } from "@vite-hub/workflow";
39
39
 
40
- export default defineWorkflow("onboard-user", async (payload: { email: string }, { id, provider }) => {
41
- const idempotencyKey = `onboard-user:${payload.email}`;
42
- const user = await upsertUser(payload.email, { idempotencyKey });
43
- await sendWelcomeEmail(user.email, { idempotencyKey: `${idempotencyKey}:welcome-email` });
40
+ export default defineWorkflow<{ email: string }>({
41
+ handler: async ({ payload, id, provider }) => {
42
+ const idempotencyKey = `onboard-user:${payload.email}`;
43
+ const user = await upsertUser(payload.email, { idempotencyKey });
44
+ await sendWelcomeEmail(user.email, { idempotencyKey: `${idempotencyKey}:welcome-email` });
44
45
 
45
- return { id, provider };
46
+ return { id, provider };
47
+ },
46
48
  });
47
49
  ```
48
50
 
49
51
  Both external operations receive keys derived from stable input. Preserve that idempotency when adding side effects so retrying a completed operation does not duplicate it.
50
52
 
51
- ViteHub discovers `server/workflows/<name>.ts`, folder workflows such as `server/workflows/onboard-user/index.ts`, and `src/<name>.workflow.ts`. The file or folder name is the Workflow name. Pass the same name to `defineWorkflow(name, handler)` and to the runtime helpers. A definition that passes another name fails with `WORKFLOW_C0019` when the Workflow loads.
53
+ ViteHub discovers `server/workflows/<name>.ts`, folder workflows such as `server/workflows/onboard-user/index.ts`, and `src/<name>.workflow.ts`. The file or folder path is the Workflow name. `defineWorkflow()` takes one object and no name. Pass the name to the runtime helpers.
52
54
 
53
- The handler gets `(payload, context)`. Annotate `payload` to type it. `context` has `id`, `name`, `provider`, and `steps`.
55
+ The handler gets one object with `payload`, `id`, `name`, `provider`, `sleep`, `createSignal`, and `steps`. Pass the payload type as the type argument of `defineWorkflow()`. ViteHub writes the names and payload types to `.vitehub/workflow.d.ts`, so `startWorkflow("onboard-user", payload)` checks both.
54
56
 
55
57
  ## Call typed steps
56
58
 
@@ -60,9 +62,11 @@ A folder Workflow runs its numbered files as steps. `01.create-user.ts` becomes
60
62
  // server/workflows/onboard-user/index.ts
61
63
  import { defineWorkflow } from "@vite-hub/workflow";
62
64
 
63
- export default defineWorkflow("onboard-user", async (payload: { email: string }, { steps }) => {
64
- const user = await steps.createUser(payload);
65
- return await steps.sendWelcome(user);
65
+ export default defineWorkflow<{ email: string }>({
66
+ handler: async ({ payload, steps }) => {
67
+ const user = await steps.createUser(payload);
68
+ return await steps.sendWelcome(user);
69
+ },
66
70
  });
67
71
  ```
68
72
 
@@ -80,7 +84,7 @@ export default async function sendWelcome(user: { id: string, email: string }) {
80
84
  }
81
85
  ```
82
86
 
83
- The Vite Integration writes `.vitehub/workflow.d.ts`. It declares the step files of each folder Workflow, so each step takes the input type of its file and returns its result type. A call to a step that has no file is a type error. Include `.vitehub/workflow.d.ts` in your TypeScript project; `vite-hub` includes it through `.vitehub/types.d.ts`.
87
+ The Vite Integration writes `.vitehub/workflow.d.ts`. A step name shared by multiple folders accepts only inputs that all those steps accept and can return any of their result types. A call to a step that has no file is a type error. At runtime, only the current folder's steps are available. Include `.vitehub/workflow.d.ts` in your TypeScript project; `vite-hub` includes it through `.vitehub/types.d.ts`.
84
88
 
85
89
  ## Configure the driver
86
90
 
@@ -176,48 +180,51 @@ installWorkflowRuntime();
176
180
 
177
181
  export default defineEventHandler(async (event) => {
178
182
  const payload = await readBody<{ email: string }>(event);
179
- const started = await startWorkflow("onboard-user", payload);
183
+ const [startError, started] = await startWorkflow("onboard-user", payload);
184
+ if (startError) throw startError;
180
185
 
181
- return await getWorkflowRun("onboard-user", started.id);
186
+ const [error, run] = await getWorkflowRun("onboard-user", started.id);
187
+ if (error) throw error;
188
+ return run;
182
189
  });
183
190
  ```
184
191
 
185
- `startWorkflow()` returns a normalized acknowledgement with an id, provider, and status. When you pass `{ id }`, that id is the run id on Cloudflare, OpenWorkflow, and inline runs, and a second start with the same id returns the first run. `getWorkflowRun()` returns normalized run and step state, including timestamps, attempts, and results when the provider supplies them. A failed run has `error`: `{ message, name?, code? }`, safe to send as JSON, on every provider. `metadata` keeps provider data and no longer holds the error. Every provider reports the same statuses: a sleeping or waiting run reports `running`, a Cloudflare `terminated` run reports `cancelled`, and a run id that does not exist reports `unknown`.
192
+ `startWorkflow()` returns `[error, run]`: a normalized acknowledgement with an id, provider, and status. `getWorkflowRun()`, `cancelWorkflow()`, `resumeWorkflow()`, and the `start`, `getRun`, and `cancel` methods of a handle also return `[error, data]`. A provider failure, an unsupported option, or an invalid `delay` is `error`; its `code` is a `WorkflowResultErrorCode`. A config error, such as an unknown Workflow name, throws. When you pass `{ id }`, that id is the run id on Cloudflare, OpenWorkflow, and inline runs, and a second start with the same id returns the first run. `getWorkflowRun()` returns normalized run and step state, including timestamps, attempts, and results when the provider supplies them. A failed run has `error`: `{ message, name?, code? }`, safe to send as JSON, on every provider. `metadata` keeps provider data and no longer holds the error. Every provider reports the same statuses: a sleeping or waiting run reports `running`, a Cloudflare `terminated` run reports `cancelled`, and a run id that does not exist reports `unknown`.
186
193
 
187
- To set your own id, pass `{ id }`. On Cloudflare, start with a letter, a digit, or `_`, then use only letters, digits, `-`, and `_`, up to 100 characters. Invalid start ids fail with `WORKFLOW_CLOUDFLARE_RUN_ID_INVALID`. Inspection queries the binding because existing instance ids can follow different rules.
194
+ To set your own id, pass `{ id }`. On Cloudflare, start with a letter, a digit, or `_`, then use only letters, digits, `-`, and `_`, up to 100 characters. `startWorkflow()` returns the error `WORKFLOW_CLOUDFLARE_RUN_ID_INVALID` for another id. Inspection queries the binding because existing instance ids can follow different rules.
188
195
 
189
196
  The other runtime helpers are:
190
197
 
191
198
  - `deferWorkflow()` starts a run after the response, through `waitUntil`. It returns nothing and logs a failure. Call `startWorkflow()` when you need the run id.
192
199
  - `cancelWorkflow()` cancels a Cloudflare run with `instance.terminate()`, a native Vercel run, or a pending or running OpenWorkflow run. A finished run keeps its status, and a missing run reports `unknown`.
193
- - `resumeWorkflow()` resumes a registered Vercel Workflow DevKit hook token.
200
+ - `resumeWorkflow(token, value)` sends `value` to a run that waits on `context.createSignal()`, or resumes a Workflow DevKit hook token on Vercel.
194
201
  - `createWorkflow()` creates a named handle with `start`, `defer`, `getRun`, and `cancel` methods.
195
202
 
196
203
  Unsupported provider operations fail with `WORKFLOW_OPERATION_UNSUPPORTED`; ViteHub does not pretend that an inline run was cancelled or resumed.
197
204
 
198
- `hubWorkflow()` contributes the `workflow.start`, `get`, `cancel`, `resume`, `runs-list`, `runs-show`, and `runs-clear` operations. In `vite dev`, the dev Nitro plugin records every inline run in the memory of the dev server: its status, times, result, error, and each step of a folder Workflow. `vitehub workflow runs list` lists the newest runs first, `vitehub workflow runs show <runId>` shows one with its steps, and `vitehub workflow runs clear --yes` removes them all. The history keeps the newest 200 runs until the dev server restarts. It does not include runs that a Cloudflare binding, OpenWorkflow, or a native Vercel Workflow executes. Only the dev Nitro plugin imports the `runtime/dev-runs` module, by file path. It holds the history. The production runtime has only an empty recorder slot, so a build does not include the history code and never records runs. The three commands fail there with `WORKFLOW_RUNS_UNAVAILABLE`.
205
+ `hubWorkflow()` contributes the `workflow.start`, `get`, `cancel`, `resume`, `runs-list`, and `runs-clear` operations. In `vite dev`, the dev Nitro plugin records every inline run in the memory of the dev server: its status, times, result, error, and each step of a folder Workflow. `vitehub workflow runs list` lists the newest runs first, `vitehub workflow runs get <runId>` shows one with its steps, and `vitehub workflow runs clear --yes` removes them all. The history keeps the newest 200 runs until the dev server restarts. It does not include runs that a Cloudflare binding, OpenWorkflow, or a native Vercel Workflow executes. Only the dev Nitro plugin imports the `runtime/dev-runs` module, by file path. It holds the history. The production runtime has only an empty recorder slot, so a build does not include the history code and never records runs. `runs list` and `runs clear` fail there with `WORKFLOW_RUNS_UNAVAILABLE`, and `runs get` reads the run from the provider, without steps.
199
206
 
200
207
  The `result` of a completed run is the value that the handler returned, stored as JSON. Every provider returns the same plain value, so a `Date` comes back as a string and `undefined` fields are dropped. Return a JSON-safe value, or return a `Response` for binary data or for status and headers. When the handler returns a `Response`, `result` is a `Response`.
201
208
 
202
209
  Inline runs buffer a returned `Response` body before completion. Each inspection and duplicate start returns a fresh `Response`, so reading or cancelling one result does not consume later results. A body read failure marks the run as failed.
203
210
 
204
- Inline run inspection uses weak references while execution is active. A reachable execution remains inspectable; an abandoned execution with no remaining owner can be garbage-collected and then reports `unknown`. Completed inline runs are retained for five minutes, up to 1,024 entries per runtime. Completed history does not evict active executions. If either `WeakRef` or `FinalizationRegistry` is unavailable, active inspection uses strong references capped at 1,024 entries. Starting another run evicts the oldest active inspection entry, even if execution is still reachable; it reports `unknown` and completion does not restore it. Use a durable provider when inspection must survive abandonment or a process restart.
211
+ Inline run inspection uses weak references while execution is active. A reachable execution remains inspectable; an abandoned execution with no remaining owner can be garbage-collected and then reports `unknown`. Completed inline runs are retained for five minutes, up to 1,024 entries per runtime. In `vite dev`, `getWorkflowRun()` also reads the dev run history, which keeps the newest 200 runs until the dev server restarts. Completed history does not evict active executions. If either `WeakRef` or `FinalizationRegistry` is unavailable, active inspection uses strong references capped at 1,024 entries. Starting another run evicts the oldest active inspection entry, even if execution is still reachable; it reports `unknown` and completion does not restore it. Use a durable provider when inspection must survive abandonment or a process restart.
205
212
 
206
213
  ## Start a run later
207
214
 
208
- Pass `delay` to start the run later. It accepts milliseconds, a duration such as `"30 minutes"` or `"3 days"`, or a `Date` that the run must not start before. A `Date` in the past starts the run now. A negative or unknown value fails with `WORKFLOW_START_DELAY_INVALID`. Use a `Date` for a month or a calendar time. `delay` works with `{ id }`.
215
+ Pass `delay` to start the run later. It accepts a duration such as `"30m"` or `"3 days"`, or a `Date` that the run must not start before. A `Date` in the past starts the run now. `startWorkflow()` returns `RUNTIME_DURATION_INVALID` for an invalid duration, including a bare number, and `WORKFLOW_START_DELAY_INVALID` for an invalid or out-of-range start time. Use a `Date` for a month or a calendar time. `delay` works with `{ id }`.
209
216
 
210
217
  ```ts fragment
211
- await startWorkflow("send-reminder", { email }, { delay: "3 days", id: `reminder-${userId}` });
218
+ const [error, run] = await startWorkflow("send-reminder", { email }, { delay: "3 days", id: `reminder-${userId}` });
212
219
  ```
213
220
 
214
221
  | Provider | How the delay works | Status during the delay |
215
222
  | --- | --- | --- |
216
223
  | OpenWorkflow | The run stays pending in storage until its start time (`availableAt`). | `queued` |
217
224
  | Cloudflare | The run sleeps with `step.sleepUntil()` before the handler. A waiting instance does not count toward the concurrency limit. | `running` |
218
- | Vercel `native` entry of a folder Workflow | The generated entry calls Workflow DevKit `sleep()` before the first step. | `running` |
219
- | Vercel `native` entry that you wrote | Not supported. `startWorkflow()` fails with `WORKFLOW_OPERATION_UNSUPPORTED`. | |
220
- | Inline runs (`vite dev`, normal Vercel handlers) | A timer in the process. It is not durable: a restart loses the run. | `queued` |
225
+ | Vercel, generated native entry for numbered steps without an index handler | The generated entry calls Workflow DevKit `sleep()` before the first step. | `running` |
226
+ | Vercel `native` entry that you wrote | Not supported. `startWorkflow()` returns the error `WORKFLOW_OPERATION_UNSUPPORTED`. | |
227
+ | Inline runs (`vite dev`, normal Vercel handlers) | A timer in the process. It is not durable: a restart loses the run. Outside `vite dev`, the first delayed run of each Workflow logs a warning. | `queued` |
221
228
 
222
229
  For a recurring run, call `startWorkflow()` from a [Schedule](https://vitehub.dev/docs/schedule) handler.
223
230
 
@@ -251,12 +258,13 @@ async function durableOnboard({ payload }: WorkflowProviderContext<OnboardPayloa
251
258
  return { userId: user.id };
252
259
  }
253
260
 
254
- async function inlineOnboard(payload: OnboardPayload) {
255
- const user = await upsertUser(payload.email, { idempotencyKey: `onboard-user:${payload.email}` });
256
- return { userId: user.id };
257
- }
258
-
259
- export default defineWorkflow("onboard-user", inlineOnboard, { native: durableOnboard });
261
+ export default defineWorkflow<OnboardPayload>({
262
+ handler: async ({ payload }) => {
263
+ const user = await upsertUser(payload.email, { idempotencyKey: `onboard-user:${payload.email}` });
264
+ return { userId: user.id };
265
+ },
266
+ native: durableOnboard,
267
+ });
260
268
  ```
261
269
 
262
270
  ViteHub transforms `native` when it generates Vercel output. Other providers keep using the normal handler. `vite dev` does not transform `native`, so the dev server runs the normal handler inline, also with the Vercel provider. Test the durable entry on a Vercel preview deployment. Vercel calls `native` with a `WorkflowProviderContext`, which has no `steps` runner. Put external side effects in idempotent `use step` functions because a durable step may be retried.
@@ -282,9 +290,16 @@ async function transcribe(recordingId: string) {
282
290
 
283
291
  `code` and `message` remain available through `error.toJSON()`. Keep `details` JSON-safe and free of secrets; `toJSON()` omits `cause`, which remains available only on the in-memory error. ViteHub's built-in codes are typed as `WorkflowErrorCode` and use code-derived messages and code-specific details. A `ViteHubError` does not change the retry policy.
284
292
 
285
- A step file has no retry option. On Cloudflare and OpenWorkflow, every step file uses `limit: 3`, `delay: "10 seconds"`, and `backoff: "exponential"`. A Vercel `native` entry follows the Workflow DevKit rules, and an inline run does not retry.
293
+ A step gets 3 retries after the first attempt, 10 seconds apart and then twice as long each time. A step file can export its own policy and a time limit for each attempt:
294
+
295
+ ```ts
296
+ export const retries = { limit: 5, delay: "30 seconds", backoff: "exponential" };
297
+ export const timeout = "2 minutes";
298
+ ```
299
+
300
+ Cloudflare gets both in `step.do()`. OpenWorkflow gets `retries` as its `retryPolicy`, and a generated Vercel step gets `limit` as `maxRetries`. Vercel steps cannot set `delay` or `backoff`, so the build fails with `WORKFLOW_STEP_RETRY_DELAY_UNSUPPORTED`. Outside Cloudflare, ViteHub enforces `timeout` itself: it aborts the `signal` that the step function gets as its second argument and fails the attempt. Code that ignores the signal keeps running. An inline run does not retry. See [Retries and sleeps](https://vitehub.dev/docs/workflows/limits-and-errors#retries-and-sleeps).
286
301
 
287
- Throw `NonRetryableError` when another attempt cannot succeed. The run fails at once on every provider. `getWorkflowRun()` reports the error `message` and `name` in `metadata` for inline and OpenWorkflow runs, Cloudflare keeps the error in its status record in `metadata`, and a Vercel `native` run reports the message on the failed step in `steps`.
302
+ Throw `NonRetryableError` when another attempt cannot succeed. The run fails at once on every provider. `getWorkflowRun()` reports the error `message` and `name` in `error` on every provider, and inline runs also keep `code`. OpenWorkflow also reports the original message on the failed step in `steps`. Native Vercel can report a generic step error if it cannot read the provider's step error message. Cloudflare also keeps the error in its status record in `metadata`.
288
303
 
289
304
  ```ts fragment
290
305
  import { NonRetryableError } from "@vite-hub/workflow";
@@ -298,11 +313,13 @@ Only a folder Workflow can sleep. Its `index.ts` calls `context.sleep()` between
298
313
 
299
314
  ```ts fragment
300
315
  // server/workflows/remind-user/index.ts, next to 01.send-welcome.ts and 02.send-reminder.ts
301
- export default defineWorkflow("remind-user", async (payload: { email: string, remindAt: string }, { sleep, steps }) => {
302
- await steps.sendWelcome(payload);
303
- await sleep("1 day");
304
- await sleep(new Date(payload.remindAt));
305
- await steps.sendReminder(payload);
316
+ export default defineWorkflow<{ email: string, remindAt: string }>({
317
+ handler: async ({ payload, sleep, steps }) => {
318
+ await steps.sendWelcome(payload);
319
+ await sleep("1 day");
320
+ await sleep(new Date(payload.remindAt));
321
+ await steps.sendReminder(payload);
322
+ },
306
323
  });
307
324
  ```
308
325
 
@@ -312,6 +329,25 @@ After a sleep, the provider runs `index.ts` again from the start, and completed
312
329
 
313
330
  A single-file Workflow runs as one root step, and a replay after a sleep would run the code before the sleep again. So `context.sleep()` in a single-file Workflow throws `WORKFLOW_ROOT_STEP_SLEEP` on every provider, and the run fails without a retry. A duration that is not in the form above throws `WORKFLOW_SLEEP_DURATION_INVALID`.
314
331
 
332
+ A folder Workflow can wait for a value from outside the run, such as a webhook. `context.createSignal<T>()` returns `{ token, wait() }`. Give `token` to the other service, then call `wait()`. `resumeWorkflow(token, value)` sends a JSON value, and `wait()` returns it.
333
+
334
+ ```ts fragment
335
+ // server/workflows/summary/index.ts
336
+ export default defineWorkflow<{ callId: string }>({
337
+ handler: async ({ createSignal, payload, steps }) => {
338
+ const transcript = createSignal<{ text: string }>();
339
+ await steps.requestTranscript({ callId: payload.callId, token: transcript.token });
340
+ const { text } = await transcript.wait();
341
+ return await steps.summarize({ text });
342
+ },
343
+ });
344
+
345
+ // server/api/webhooks/transcript.post.ts, after the webhook signature check
346
+ const [error] = await resumeWorkflow(body.token, { text: body.text });
347
+ ```
348
+
349
+ ViteHub makes the token from the Workflow name, the run id, and the call order (`signal-1`, `signal-2`), so a replay gets the same token. The token is not a secret: check the caller before you pass a token from a request. Cloudflare waits with `step.waitForEvent()` for at most 365 days, and `resumeWorkflow()` calls `instance.sendEvent()`. OpenWorkflow waits with `step.waitForSignal()` for one year, then fails the run with `WORKFLOW_SIGNAL_TIMEOUT`. It drops a value that comes before the wait, so `resumeWorkflow()` returns `WORKFLOW_SIGNAL_NOT_WAITING` and the caller retries later. Inline runs wait in memory and keep an early value. Vercel does not support signals yet: `createSignal()` throws `WORKFLOW_SIGNAL_VERCEL_UNSUPPORTED`, and a `native` entry uses `defineHook()` from Workflow DevKit instead. A token of another provider returns `WORKFLOW_SIGNAL_TOKEN_INVALID`, and `wait()` in a single-file Workflow throws `WORKFLOW_ROOT_STEP_SIGNAL`.
350
+
315
351
  ## Production checklist
316
352
 
317
353
  - Confirm that the selected provider is durable enough for the work; inline Vercel handlers are not durable.
@@ -334,11 +370,10 @@ A single-file Workflow runs as one root step, and a replay after a sleep would r
334
370
  A typed Workflow handle requires a payload when its handler requires one. Both `start()` and `defer()` use this rule. A handle with an optional payload or `void` input can still start with no argument. To set start options for a no-input Workflow, pass `undefined` first.
335
371
 
336
372
  ```ts fragment
337
- const welcome = createWorkflow("welcome", async (payload: { email: string }) => {
373
+ const welcome = createWorkflow<{ email: string }>("welcome", async ({ payload }) => {
338
374
  await sendWelcomeEmail(payload.email)
339
375
  })
340
- await welcome.start({ email: "ada@example.com" })
341
- // welcome.start() is a type error.
376
+ const [error, run] = await welcome.start({ email: "ada@example.com" })
342
377
  ```
343
378
 
344
- This is a breaking type correction. Supply the required payload at each handle call. Named operational functions do not infer a handler from a string, and persisted run results remain unknown.
379
+ For a Workflow created outside discovery, use its handle. For a discovered Workflow, use its discovered name with `startWorkflow()` or `deferWorkflow()`, even if its file exports a `createWorkflow()` handle with a different name. These functions read the payload type from `.vitehub/workflow.d.ts` when the default export has a typed handler. A handle export does not supply that handler type. Stored run results stay `unknown`.
@@ -1,4 +1,4 @@
1
- import { t as internalErrorDiagnostics } from "./error-diagnostics-DSkCJC_L.js";
1
+ import { t as internalErrorDiagnostics } from "./error-diagnostics-C0KyI408.js";
2
2
  //#region ../internal/src/runtime/app.ts
3
3
  function resolveAppFetch(label, app) {
4
4
  if (!app) return;