@vite-hub/workflow 0.4.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 (42) hide show
  1. package/README.md +28 -10
  2. package/dist/{app-He0GTrYZ.js → app-2Y7sBAG6.js} +1 -1
  3. package/dist/{client-DkwOxEiT.js → client-CgBcDlGn.js} +80 -54
  4. package/dist/{cloudflare-BHfClPvT.js → cloudflare-Datj_znU.js} +1 -1
  5. package/dist/{config-C3DvtjfJ.js → config-z1651xc2.js} +1 -1
  6. package/dist/definition.d.ts +1 -1
  7. package/dist/definition.js +1 -1
  8. package/dist/{delay-D1-nq_VE.js → delay-CHN4tv3i.js} +1 -2
  9. package/dist/durability.d.ts +1 -1
  10. package/dist/{error-diagnostics-CQ4BUqRe.js → error-diagnostics-C0KyI408.js} +5 -1
  11. package/dist/{error-diagnostics-0V2T3JFw.js → error-diagnostics-DMeaFmQD.js} +23 -5
  12. package/dist/{errors-DCqRnZpN.js → errors-BNxEeeCO.js} +0 -4
  13. package/dist/{errors-uhP8DZTi.d.ts → errors-D-fNDVg0.d.ts} +0 -5
  14. package/dist/index.d.ts +7 -5
  15. package/dist/index.js +4 -4
  16. package/dist/{openworkflow-BhzxV_Y3.d.ts → openworkflow-BoaENgh9.d.ts} +7 -8
  17. package/dist/{operation-definition-nmRu_O3V.d.ts → operation-definition-CI2PJGqu.d.ts} +8 -2
  18. package/dist/{operations-D_WJwjrS.js → operations-CYntpf-T.js} +27 -38
  19. package/dist/operations.d.ts +5 -8
  20. package/dist/operations.js +27 -32
  21. package/dist/{run-error-DBWqiJHH.js → run-error-Ctn50EYz.js} +1 -2
  22. package/dist/runtime/cloudflare-runner.d.ts +12 -2
  23. package/dist/runtime/cloudflare-runner.js +13 -6
  24. package/dist/runtime/cloudflare-vite.d.ts +1 -1
  25. package/dist/runtime/cloudflare-vite.js +2 -2
  26. package/dist/runtime/dev-runs.js +1 -0
  27. package/dist/runtime/execute.d.ts +2 -2
  28. package/dist/runtime/execute.js +64 -32
  29. package/dist/runtime/openworkflow-worker.d.ts +2 -2
  30. package/dist/runtime/openworkflow-worker.js +4 -9
  31. package/dist/runtime/openworkflow.d.ts +2 -2
  32. package/dist/runtime/openworkflow.js +33 -48
  33. package/dist/runtime/state.d.ts +1 -1
  34. package/dist/runtime/state.js +3 -1
  35. package/dist/runtime/vercel-vite.d.ts +1 -1
  36. package/dist/runtime/vercel-vite.js +2 -2
  37. package/dist/signals-C1iolifd.js +80 -0
  38. package/dist/{types-Dsmwsdlv.d.ts → types-BWPHeugk.d.ts} +34 -4
  39. package/dist/{vercel-DTvm61iY.js → vercel-BIkBFrQQ.js} +4 -12
  40. package/dist/vite.d.ts +12 -7
  41. package/dist/vite.js +3516 -1660
  42. package/package.json +3 -3
package/README.md CHANGED
@@ -52,7 +52,7 @@ Both external operations receive keys derived from stable input. Preserve that i
52
52
 
53
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.
54
54
 
55
- The handler gets one object with `payload`, `id`, `name`, `provider`, `sleep`, 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.
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.
56
56
 
57
57
  ## Call typed steps
58
58
 
@@ -197,18 +197,18 @@ The other runtime helpers are:
197
197
 
198
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.
199
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`.
200
- - `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.
201
201
  - `createWorkflow()` creates a named handle with `start`, `defer`, `getRun`, and `cancel` methods.
202
202
 
203
203
  Unsupported provider operations fail with `WORKFLOW_OPERATION_UNSUPPORTED`; ViteHub does not pretend that an inline run was cancelled or resumed.
204
204
 
205
- `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.
206
206
 
207
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`.
208
208
 
209
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.
210
210
 
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. 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.
212
212
 
213
213
  ## Start a run later
214
214
 
@@ -222,9 +222,9 @@ const [error, run] = await startWorkflow("send-reminder", { email }, { delay: "3
222
222
  | --- | --- | --- |
223
223
  | OpenWorkflow | The run stays pending in storage until its start time (`availableAt`). | `queued` |
224
224
  | Cloudflare | The run sleeps with `step.sleepUntil()` before the handler. A waiting instance does not count toward the concurrency limit. | `running` |
225
- | Vercel `native` entry of a folder Workflow | The generated entry calls Workflow DevKit `sleep()` before the first step. | `running` |
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
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. | `queued` |
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` |
228
228
 
229
229
  For a recurring run, call `startWorkflow()` from a [Schedule](https://vitehub.dev/docs/schedule) handler.
230
230
 
@@ -299,7 +299,7 @@ export const timeout = "2 minutes";
299
299
 
300
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).
301
301
 
302
- 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`.
303
303
 
304
304
  ```ts fragment
305
305
  import { NonRetryableError } from "@vite-hub/workflow";
@@ -329,6 +329,25 @@ After a sleep, the provider runs `index.ts` again from the start, and completed
329
329
 
330
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`.
331
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
+
332
351
  ## Production checklist
333
352
 
334
353
  - Confirm that the selected provider is durable enough for the work; inline Vercel handlers are not durable.
@@ -354,8 +373,7 @@ A typed Workflow handle requires a payload when its handler requires one. Both `
354
373
  const welcome = createWorkflow<{ email: string }>("welcome", async ({ payload }) => {
355
374
  await sendWelcomeEmail(payload.email)
356
375
  })
357
- await welcome.start({ email: "ada@example.com" })
358
- // welcome.start() is a type error.
376
+ const [error, run] = await welcome.start({ email: "ada@example.com" })
359
377
  ```
360
378
 
361
- 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-CQ4BUqRe.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;
@@ -1,18 +1,21 @@
1
- import { t as workflowErrorDiagnostics } from "./error-diagnostics-0V2T3JFw.js";
2
- import { n as createWorkflowError } from "./errors-DCqRnZpN.js";
3
- import { a as encodeNameHex, n as getCloudflareWorkflowBindingName } from "./cloudflare-BHfClPvT.js";
1
+ import { t as workflowErrorDiagnostics } from "./error-diagnostics-DMeaFmQD.js";
2
+ import { n as createWorkflowError } from "./errors-BNxEeeCO.js";
3
+ import { a as encodeNameHex, n as getCloudflareWorkflowBindingName } from "./cloudflare-Datj_znU.js";
4
4
  import { a as getCloudflareEnv, n as resolveWaitUntil } from "./cloudflare-env-CGLx7lUd.js";
5
- import { t as normalizeWorkflowOptions } from "./config-C3DvtjfJ.js";
6
- import { i as toCloudflareStartParams, r as resolveWorkflowStartAt } from "./delay-D1-nq_VE.js";
5
+ import { t as normalizeWorkflowOptions } from "./config-z1651xc2.js";
6
+ import { i as toCloudflareStartParams, r as resolveWorkflowStartAt } from "./delay-CHN4tv3i.js";
7
7
  import { t as getWorkflowDevRecorder } from "./dev-recorder-CTN5Fkao.js";
8
+ import { i as readWorkflowSignalToken, o as resumeInlineWorkflowSignal } from "./signals-C1iolifd.js";
8
9
  import { runSerializedWorkflowHandler } from "./runtime/execute.js";
9
- import { a as safeWorkflowName, i as runWorkflowProviderOperation, t as toWorkflowRunError } from "./run-error-DBWqiJHH.js";
10
10
  import { t as emitWorkflowFailed } from "./run-failed-gVGo1BaF.js";
11
- import { cancelOpenWorkflowRun, getOpenWorkflowRun, runOpenWorkflow } from "./runtime/openworkflow.js";
12
11
  import { getInlineWorkflowDefinitions, getWorkflowRunState, getWorkflowRuntimeConfig, getWorkflowRuntimeEvent, getWorkflowRuntimeRegistry, loadWorkflowDefinition, registerInlineWorkflowDefinition, runWithWorkflowRuntimeEvent, setWorkflowRun } from "./runtime/state.js";
13
- import { a as startVercelWorkflow, n as inspectVercelWorkflowRun, r as resumeVercelWorkflowSignal, t as cancelVercelWorkflow } from "./vercel-DTvm61iY.js";
14
- import { deserializeResponse, getViteHubErrorShape, isRuntimeDiagnostic, isSerializedResponse, toResultError } from "@vite-hub/runtime";
12
+ import { cloudflareSignalEventType } from "./runtime/cloudflare-runner.js";
13
+ import { a as safeWorkflowName, i as runWorkflowProviderOperation, t as toWorkflowRunError } from "./run-error-Ctn50EYz.js";
14
+ import { cancelOpenWorkflowRun, getOpenWorkflowRun, resumeOpenWorkflowSignal, runOpenWorkflow } from "./runtime/openworkflow.js";
15
+ import { a as startVercelWorkflow, n as inspectVercelWorkflowRun, r as resumeVercelWorkflowSignal, t as cancelVercelWorkflow } from "./vercel-BIkBFrQQ.js";
16
+ import { getViteHubErrorShape, isRuntimeDiagnostic, toResultError } from "@vite-hub/runtime";
15
17
  import { getViteHubTestMode } from "@vite-hub/runtime/internal/test-mode";
18
+ import { deserializeResponse, isSerializedResponse } from "@vite-hub/runtime/internal/response";
16
19
  //#region ../internal/src/runtime/random.ts
17
20
  function randomId(prefix) {
18
21
  const body = `${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;
@@ -25,6 +28,17 @@ function getVercelWorkflowName(name) {
25
28
  }
26
29
  //#endregion
27
30
  //#region src/runtime/adapters.ts
31
+ async function resumeViteHubSignal(config, token, payload, durable) {
32
+ const address = readWorkflowSignalToken(token);
33
+ if (!address) throw workflowErrorDiagnostics.WORKFLOW_SIGNAL_TOKEN_INVALID({ provider: config.driver });
34
+ if (address.host === "inline") resumeInlineWorkflowSignal(token, address, payload);
35
+ else if (address.host === config.driver && durable) await durable(address);
36
+ else throw workflowErrorDiagnostics.WORKFLOW_SIGNAL_TOKEN_INVALID({ provider: config.driver });
37
+ return {
38
+ id: address.run,
39
+ provider: config.driver
40
+ };
41
+ }
28
42
  function resolveDispatchObserver(event) {
29
43
  if (!event || typeof event !== "object") return void 0;
30
44
  const candidate = Object.hasOwn(event, "onDispatch") ? Reflect.get(event, "onDispatch") : void 0;
@@ -49,19 +63,11 @@ function unsupportedOperation(provider, operation) {
49
63
  }
50
64
  });
51
65
  }
52
- /**
53
- * True on a development server: `vite dev` installs the run history. Code that ViteHub did not start, such as a test
54
- * runner, has no history, so `NODE_ENV` decides there.
55
- */
56
66
  function isDevelopmentServer() {
57
67
  if (getWorkflowDevRecorder()) return true;
58
68
  const mode = globalThis.process?.env?.NODE_ENV;
59
69
  return mode === "development" || mode === "test";
60
70
  }
61
- /**
62
- * The Cloudflare Workflow binding of `name`. Only a development server runs the Workflow inline without it. Elsewhere,
63
- * a missing binding fails, because an inline run is not durable.
64
- */
65
71
  function resolveCloudflareBinding(event, binding, name, definition) {
66
72
  const env = getCloudflareEnv(event);
67
73
  const bindingName = definition?.internalAgentInvocationRecovery ? getCloudflareWorkflowBindingName(name) : binding || getCloudflareWorkflowBindingName(name);
@@ -75,7 +81,6 @@ function resolveCloudflareBinding(event, binding, name, definition) {
75
81
  function resolveCloudflareInspectionBinding(event, binding, name) {
76
82
  return resolveCloudflareBinding(event, binding, name, getWorkflowRuntimeRegistry()?.[name]);
77
83
  }
78
- /** The start can have reached Cloudflare, so the acknowledgement is unknown. */
79
84
  function invalidCloudflareWorkflowStart(cause) {
80
85
  return createWorkflowError({
81
86
  ...cause === void 0 ? {} : { cause },
@@ -100,7 +105,6 @@ function normalizeCloudflareWorkflowStart(value, expectedId) {
100
105
  return { id };
101
106
  }
102
107
  const cloudflareInstanceIdPattern = /^[a-zA-Z0-9_][a-zA-Z0-9_-]{0,99}$/;
103
- /** The array-form `createBatch` accepts reserved ids, unlike the object form. */
104
108
  function isCloudflareInstanceId(id) {
105
109
  return cloudflareInstanceIdPattern.test(id);
106
110
  }
@@ -123,18 +127,15 @@ function normalizeCloudflareStatus(status) {
123
127
  const normalized = String(value || "").toLowerCase();
124
128
  return Object.hasOwn(cloudflareStatusMap, normalized) ? cloudflareStatusMap[normalized] : "unknown";
125
129
  }
126
- /** The run result from Cloudflare status: the stored value, or a `Response` when the handler returned one. */
127
130
  function cloudflareRunResult(metadata) {
128
131
  if (typeof metadata !== "object" || metadata === null || !Object.hasOwn(metadata, "output")) return void 0;
129
132
  const output = metadata.output;
130
133
  return isSerializedResponse(output) ? deserializeResponse(output) : output;
131
134
  }
132
- /** The `error` member of a Cloudflare `status()` record. */
133
135
  function ownStatusError(metadata) {
134
136
  if (typeof metadata !== "object" || metadata === null || !Object.hasOwn(metadata, "error")) return void 0;
135
137
  return Reflect.get(metadata, "error");
136
138
  }
137
- /** Cloudflare `get(id)` rejects with `instance.not_found` when no instance has the id. */
138
139
  function isCloudflareInstanceNotFound(error) {
139
140
  if (typeof error !== "object" || error === null) return false;
140
141
  try {
@@ -144,10 +145,6 @@ function isCloudflareInstanceNotFound(error) {
144
145
  return false;
145
146
  }
146
147
  }
147
- /**
148
- * The Cloudflare Workflows service refused the call: its error carries a service code such as `(instance.already_exists)`,
149
- * or local Miniflare rejected the instance id. A lost connection has neither.
150
- */
151
148
  function isCloudflareRejection(error) {
152
149
  if (typeof error !== "object" || error === null) return false;
153
150
  try {
@@ -162,7 +159,6 @@ function hasUnknownWorkflowAcknowledgement(error) {
162
159
  const details = error.details;
163
160
  return Boolean(details && typeof details === "object" && details.acknowledgement === "unknown");
164
161
  }
165
- /** Reads a Cloudflare Workflow instance and its run. A missing instance has no `instance` and reports `unknown`. */
166
162
  async function readCloudflareRun(binding, id) {
167
163
  const instance = await runWorkflowProviderOperation("cloudflare", "get", async () => {
168
164
  try {
@@ -196,10 +192,6 @@ const finishedRunStatuses = /* @__PURE__ */ new Set([
196
192
  "completed",
197
193
  "failed"
198
194
  ]);
199
- /**
200
- * Terminates a Cloudflare Workflow instance that has not finished and returns its run afterwards. A finished run keeps
201
- * and reports its status, and a missing run reports `unknown`, as on OpenWorkflow.
202
- */
203
195
  async function cancelCloudflareRun(binding, id) {
204
196
  const { instance, run } = await readCloudflareRun(binding, id);
205
197
  if (!instance || run.status === "unknown" || finishedRunStatuses.has(run.status)) return run;
@@ -268,18 +260,28 @@ function createCloudflareAdapter(config) {
268
260
  }
269
261
  return await inlineAdapter(config).run(context);
270
262
  },
271
- resume: () => unsupportedOperation("cloudflare", "signals")
263
+ resume: async (token, payload) => await resumeViteHubSignal(config, token, payload, async ({ run, signal, workflow }) => {
264
+ const binding = resolveCloudflareInspectionBinding(getWorkflowRuntimeEvent(), config.binding, workflow);
265
+ if (!binding) throw workflowErrorDiagnostics.WORKFLOW_SIGNAL_NOT_WAITING({ run });
266
+ const { instance, run: current } = await readCloudflareRun(binding, run);
267
+ if (!instance || finishedRunStatuses.has(current.status)) throw workflowErrorDiagnostics.WORKFLOW_SIGNAL_NOT_WAITING({ run });
268
+ await runWorkflowProviderOperation("cloudflare", "resume-signal", async () => {
269
+ if (!instance.sendEvent) unsupportedOperation("cloudflare", "signals");
270
+ try {
271
+ await instance.sendEvent({
272
+ payload,
273
+ type: cloudflareSignalEventType(signal)
274
+ });
275
+ } catch (error) {
276
+ if (isCloudflareInstanceNotFound(error)) throw workflowErrorDiagnostics.WORKFLOW_SIGNAL_NOT_WAITING({ run });
277
+ throw error;
278
+ }
279
+ });
280
+ })
272
281
  };
273
282
  return adapter;
274
283
  }
275
284
  const warnedInlineOpenWorkflowNames = /* @__PURE__ */ new Set();
276
- /**
277
- * Every OpenWorkflow worker registers the Workflow Definitions of the build registry when it starts: discovered
278
- * Workflows and discovered Agent Workflows. Any worker can claim a run, so a run of an inline
279
- * `createWorkflow(name, handler)` could wait in storage on a worker that never registers it. Those runs execute inline
280
- * in this process. A turn of an Agent that is not discovered fails with `WORKFLOW_AGENT_NOT_DISCOVERED`, so Agent turns are
281
- * never inline.
282
- */
283
285
  function isDurableOpenWorkflowDefinition(name) {
284
286
  const registry = getWorkflowRuntimeRegistry();
285
287
  return Boolean(registry && Object.hasOwn(registry, name));
@@ -297,7 +299,9 @@ function createOpenWorkflowAdapter(config) {
297
299
  id,
298
300
  name
299
301
  }),
300
- resume: () => unsupportedOperation("openworkflow", "signals"),
302
+ resume: async (token, payload) => await resumeViteHubSignal(config, token, payload, async ({ run, workflow }) => {
303
+ if (!await resumeOpenWorkflowSignal(config, workflow, run, token, payload)) throw workflowErrorDiagnostics.WORKFLOW_SIGNAL_NOT_WAITING({ run });
304
+ }),
301
305
  run: async (context) => {
302
306
  const { definition, event, name, options, payload, startAt } = context;
303
307
  if (isDurableOpenWorkflowDefinition(name)) return await runOpenWorkflow(config, name, payload, definition, options, resolveDispatchObserver(event), startAt);
@@ -316,11 +320,27 @@ function createOpenWorkflowAdapter(config) {
316
320
  }
317
321
  };
318
322
  }
319
- /** `setTimeout` fires at once for a delay above 2^31 - 1 ms (about 24.8 days), so a long wait uses several timers. */
320
323
  const maximumTimerDelay = 2147483647;
324
+ const warnedDelayedInlineWorkflowNames = /* @__PURE__ */ new Set();
325
+ function warnDelayedInlineRun(name, startAt) {
326
+ if (startAt === void 0 || startAt <= Date.now() || isDevelopmentServer() || warnedDelayedInlineWorkflowNames.has(name)) return;
327
+ warnedDelayedInlineWorkflowNames.add(name);
328
+ console.warn(`[vitehub:workflow] The Workflow ${JSON.stringify(name)} starts later in an inline run. A timer in this process holds the run, so a restart loses it. Use OpenWorkflow, Cloudflare, or a Vercel \`native\` entry for a durable delay.`);
329
+ }
321
330
  async function waitUntilTime(startAt) {
322
331
  while (startAt !== void 0 && startAt > Date.now()) await new Promise((resolve) => setTimeout(resolve, Math.min(startAt - Date.now(), maximumTimerDelay)));
323
332
  }
333
+ function recordedDevRun(config, name, id) {
334
+ const record = getWorkflowDevRecorder()?.get(name, id);
335
+ if (record?.status !== "completed" && record?.status !== "failed") return;
336
+ return {
337
+ ...record.status === "failed" ? { error: toWorkflowRunError(record.error) } : {},
338
+ id,
339
+ provider: config.driver,
340
+ result: isSerializedResponse(record.result) ? deserializeResponse(record.result) : record.result,
341
+ status: record.status
342
+ };
343
+ }
324
344
  function inlineAdapter(config) {
325
345
  return {
326
346
  cancel: () => unsupportedOperation(config.driver, "cancellation"),
@@ -340,6 +360,8 @@ function inlineAdapter(config) {
340
360
  status: run.status
341
361
  };
342
362
  }
363
+ const recorded = recordedDevRun(config, name, id);
364
+ if (recorded) return recorded;
343
365
  return {
344
366
  id,
345
367
  provider: config.driver,
@@ -348,6 +370,14 @@ function inlineAdapter(config) {
348
370
  },
349
371
  async run({ definition, event, id, name, payload, startAt }) {
350
372
  const existing = getWorkflowRunState(name, id);
373
+ const recorded = existing ? void 0 : recordedDevRun(config, name, id);
374
+ if (recorded) return {
375
+ ...recorded,
376
+ metadata: config.driver === "vercel" ? {
377
+ mode: "inline",
378
+ workflow: getVercelWorkflowName(name)
379
+ } : void 0
380
+ };
351
381
  if (existing) return {
352
382
  ...existing.status === "failed" ? { error: toWorkflowRunError(existing.error) } : {},
353
383
  id,
@@ -368,6 +398,7 @@ function inlineAdapter(config) {
368
398
  payload,
369
399
  provider: config.driver
370
400
  }, definition);
401
+ warnDelayedInlineRun(name, startAt);
371
402
  const run = waitUntilTime(startAt).then(() => {
372
403
  runState.startAt = void 0;
373
404
  return recordRun ? recordRun(execute) : execute();
@@ -395,17 +426,12 @@ function inlineAdapter(config) {
395
426
  status: "queued"
396
427
  };
397
428
  },
398
- resume: () => unsupportedOperation(config.driver, "signals")
429
+ resume: async (token, payload) => await resumeViteHubSignal(config, token, payload)
399
430
  };
400
431
  }
401
- /**
402
- * True when Workflow DevKit runs the `native` entry. `vite dev` does not run the Workflow DevKit transform, so the
403
- * dev server runs the normal handler inline, as for every other Workflow there.
404
- */
405
432
  function runsNatively(definition) {
406
433
  return Boolean(definition?.native) && !getWorkflowDevRecorder();
407
434
  }
408
- /** Whether a registered Workflow has a native Vercel entry, so a run of it can wait for a signal. */
409
435
  async function hasNativeWorkflowDefinition() {
410
436
  const names = /* @__PURE__ */ new Set([...Object.keys(getWorkflowRuntimeRegistry() ?? {}), ...getInlineWorkflowDefinitions().keys()]);
411
437
  for (const name of names) if ((await loadWorkflowDefinition(name))?.native) return true;
@@ -432,6 +458,7 @@ function createVercelAdapter(config) {
432
458
  });
433
459
  },
434
460
  async resume(token, payload) {
461
+ if (readWorkflowSignalToken(token)) throw workflowErrorDiagnostics.WORKFLOW_SIGNAL_TOKEN_INVALID({ provider: config.driver });
435
462
  if (getWorkflowDevRecorder()) unsupportedOperation(config.driver, "signals");
436
463
  try {
437
464
  return await resumeVercelWorkflowSignal(token, payload);
@@ -501,15 +528,13 @@ const resultErrorCodes = /* @__PURE__ */ new Set([
501
528
  "WORKFLOW_PROVIDER_OPERATION_FAILED",
502
529
  "WORKFLOW_R0014",
503
530
  "WORKFLOW_RUN_ID_UNSUPPORTED",
531
+ "WORKFLOW_SIGNAL_NOT_WAITING",
532
+ "WORKFLOW_SIGNAL_TOKEN_INVALID",
504
533
  "WORKFLOW_START_DELAY_INVALID"
505
534
  ]);
506
535
  function resultError(diagnostic) {
507
536
  return toResultError(diagnostic);
508
537
  }
509
- /**
510
- * Returns a runtime failure of a Workflow call as a catalog error. The providers throw `ViteHubError` inside the
511
- * package. The catalog error keeps its `details` in `data` and the provider error in `cause`. Config errors throw.
512
- */
513
538
  function toWorkflowResultError(error) {
514
539
  if (isRuntimeDiagnostic(error) && resultErrorCodes.has(error.code)) return resultError(error);
515
540
  const shape = getViteHubErrorShape(error);
@@ -527,7 +552,6 @@ function toWorkflowResultError(error) {
527
552
  provider: details.provider
528
553
  }));
529
554
  }
530
- /** Runs one Workflow call and returns its runtime failure as `[error, undefined]`. */
531
555
  async function toWorkflowResult(run) {
532
556
  try {
533
557
  return [void 0, await run()];
@@ -676,8 +700,10 @@ async function cancelWorkflow(name, id) {
676
700
  }));
677
701
  }
678
702
  /**
679
- * Resumes a run that waits for a signal and returns `[error, signal]`. `token` is the opaque token that the provider
680
- * gave the waiting step. An empty token or a provider failure is `error`. Config errors throw.
703
+ * Resumes a run that waits for a signal and returns `[error, signal]`. `token` is `signal.token` from
704
+ * `context.createSignal()`, or the hook token of a native Vercel entry. `payload` is the value that `signal.wait()`
705
+ * returns: send a JSON value. An invalid token, a run that does not wait for the token, or a provider failure is
706
+ * `error`. Config errors throw.
681
707
  */
682
708
  async function resumeWorkflow(token, payload) {
683
709
  if (!token || typeof token !== "string") return [resultError(workflowErrorDiagnostics.WORKFLOW_R0014({ message: "`resumeWorkflow()` requires an opaque signal token." })), void 0];
@@ -1,4 +1,4 @@
1
- import { t as workflowErrorDiagnostics } from "./error-diagnostics-0V2T3JFw.js";
1
+ import { t as workflowErrorDiagnostics } from "./error-diagnostics-DMeaFmQD.js";
2
2
  //#region ../internal/src/integrations/hex.ts
3
3
  const textEncoder = new TextEncoder();
4
4
  new TextDecoder();
@@ -1,5 +1,5 @@
1
1
  import { t as isRecord } from "./object-Da1zyPCR.js";
2
- import { t as workflowErrorDiagnostics } from "./error-diagnostics-0V2T3JFw.js";
2
+ import { t as workflowErrorDiagnostics } from "./error-diagnostics-DMeaFmQD.js";
3
3
  import { defu } from "defu";
4
4
  /** Maps a host name or a Nitro preset name, such as `cloudflare-module` or `node-server`, to its ViteHub host. */
5
5
  function hostFromNitroPreset(value) {
@@ -1,4 +1,4 @@
1
- import { f as WorkflowDefinition } from "./types-Dsmwsdlv.js";
1
+ import { f as WorkflowDefinition } from "./types-BWPHeugk.js";
2
2
  //#region src/definition.d.ts
3
3
  /**
4
4
  * Defines a Workflow from one object: `defineWorkflow({ handler, ...options })`. The file path is the Workflow name.
@@ -1,5 +1,5 @@
1
1
  import { t as isRecord } from "./object-Da1zyPCR.js";
2
- import { t as workflowErrorDiagnostics } from "./error-diagnostics-0V2T3JFw.js";
2
+ import { t as workflowErrorDiagnostics } from "./error-diagnostics-DMeaFmQD.js";
3
3
  //#region src/definition.ts
4
4
  const workflowDefinitionKeys = /* @__PURE__ */ new Set([
5
5
  "handler",
@@ -1,7 +1,6 @@
1
- import { t as workflowErrorDiagnostics } from "./error-diagnostics-0V2T3JFw.js";
1
+ import { t as workflowErrorDiagnostics } from "./error-diagnostics-DMeaFmQD.js";
2
2
  import { parseDuration } from "@vite-hub/runtime";
3
3
  //#region src/runtime/delay.ts
4
- /** The largest time that a JavaScript Date can hold. */
5
4
  const maximumTime = 864e13;
6
5
  function isDate(value) {
7
6
  return Object.prototype.toString.call(value) === "[object Date]";
@@ -1,4 +1,4 @@
1
- import { P as WorkflowRuntimeConfigValue } from "./types-Dsmwsdlv.js";
1
+ import { P as WorkflowRuntimeConfigValue } from "./types-BWPHeugk.js";
2
2
  import { Durability, DurabilityContext } from "@vite-hub/runtime/durability";
3
3
  //#region src/durability.d.ts
4
4
  /** What the build passes to `workflowDurability()`. The storage values may name runtime environment variables. */
@@ -25,7 +25,7 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
25
25
  why: ({ message }) => message === void 0 ? "" : String(message)
26
26
  },
27
27
  INTERNAL_R0022: {
28
- fix: "Send input that matches the schema of the operation. `vitehub <namespace> <command> --help` shows the fields.",
28
+ fix: "Send input that matches the schema of the operation. `vitehub <namespace> <command> --help` shows the fields, and the list_operations tool of the ViteHub MCP gives the input schema of each operation.",
29
29
  why: ({ message }) => message === void 0 ? "" : String(message)
30
30
  },
31
31
  INTERNAL_R0024: {
@@ -244,6 +244,10 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
244
244
  why: ({ owner }) => `[vitehub] ${owner} extends tuple requires [preset, options] with an options object.`,
245
245
  fix: "Set `extends` to a preset, or to a two-item tuple `[preset, { ...options }]` whose second item is a plain object."
246
246
  },
247
+ INTERNAL_RUNTIME_PACKAGE_VERSION_CONFLICT: {
248
+ why: ({ first, name, second }) => `[vitehub] One server function needs ${name} from two installations: ${first} and ${second}.`,
249
+ fix: "Install one version of the package that the message names, for example with `pnpm dedupe` or an `overrides` entry in `package.json`, then build again."
250
+ },
247
251
  INTERNAL_SECRET_PURPOSE_MISSING: {
248
252
  why: "[vitehub] A derived secret requires a purpose.",
249
253
  fix: "Pass a non-empty purpose to `deriveSecret()`, such as `deriveSecret(\"my-module:session\")`."
@@ -49,16 +49,12 @@ const workflowErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
49
49
  },
50
50
  WORKFLOW_RUNS_UNAVAILABLE: {
51
51
  why: "This runtime keeps no Workflow run history. Only `vite dev` records runs.",
52
- fix: "Run the app with `vite dev`. On a deployment, read one run with `vitehub workflow get <runId> --workflow <name>`, or use the provider dashboard."
52
+ fix: "Run the app with `vite dev`. On a deployment, read one run with `vitehub workflow runs get <runId> --workflow <name>`, or use the provider dashboard."
53
53
  },
54
54
  WORKFLOW_RUN_AMBIGUOUS: {
55
55
  why: ({ id, workflows }) => `Runs of ${workflows} have the id ${id}.`,
56
56
  fix: "Pass the name of the Workflow with `--workflow <name>`."
57
57
  },
58
- WORKFLOW_RUN_NOT_FOUND: {
59
- why: ({ id }) => `No recorded run has the id ${id}.`,
60
- fix: "Run `vitehub workflow runs list` for the ids. The dev server keeps the newest 200 runs until it restarts or `vitehub workflow runs clear` empties the history."
61
- },
62
58
  WORKFLOW_RUN_UNKNOWN: {
63
59
  why: ({ runId }) => `Run ${runId} was not started by \`workflow.start\` in this runtime.`,
64
60
  fix: "Pass the name of the Workflow with `--workflow <name>`."
@@ -283,10 +279,32 @@ const workflowErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
283
279
  why: ({ value }) => `\`workflow.provider\` is ${value}. ViteHub renamed this key to \`driver\`, and it does not read \`provider\`, so Workflow would not use the driver you chose.`,
284
280
  fix: ({ value }) => `Set \`workflow: { driver: ${value} }\`, or run \`npx @vite-hub/codemods driver-key\` to rename it in every config file.`
285
281
  },
282
+ WORKFLOW_ROOT_STEP_SIGNAL: {
283
+ why: ({ name }) => `[vitehub] The Workflow ${JSON.stringify(name)} called \`signal.wait()\` in its root step. Only a folder Workflow can wait for a signal: move it to \`server/workflows/${name}/index.ts\` and put the work in numbered step files.`,
284
+ fix: "A single-file Workflow runs as one step, so a replay after the wait would run the code before the wait again. Move the handler to `server/workflows/<name>/index.ts`, put each side effect in a numbered step file such as `01.request-transcript.ts`, and call `signal.wait()` between the steps."
285
+ },
286
286
  WORKFLOW_ROOT_STEP_SLEEP: {
287
287
  why: ({ name }) => `[vitehub] The Workflow ${JSON.stringify(name)} called \`context.sleep()\` in its root step. Only a folder Workflow can sleep: move it to \`server/workflows/${name}/index.ts\` and put the work in numbered step files.`,
288
288
  fix: "A single-file Workflow runs as one step, so a replay after a sleep would run the code before the sleep again. Move the handler to `server/workflows/<name>/index.ts`, put each side effect in a numbered step file such as `01.charge.ts`, and call `context.sleep()` between the steps."
289
289
  },
290
+ WORKFLOW_SIGNAL_NOT_WAITING: {
291
+ why: ({ run }) => `[vitehub] No run waits for this signal token. The run ${JSON.stringify(run)} has not reached \`signal.wait()\` yet, it got the signal already, or it ended.`,
292
+ fix: "Retry later when the run can still be before its `signal.wait()`, for example by answering a webhook with a 5xx status so the sender retries. Check the run with `getWorkflowRun()`. An inline run in `vite dev` waits in memory, so a restart of the dev server loses it.",
293
+ data: ({ run }) => ({ run })
294
+ },
295
+ WORKFLOW_SIGNAL_TIMEOUT: {
296
+ why: ({ name }) => `[vitehub] The Workflow ${JSON.stringify(name)} waited one year for a signal, and no \`resumeWorkflow()\` call sent it.`,
297
+ fix: "Call `resumeWorkflow(signal.token, value)` within one year. To stop waiting sooner, cancel the run with `cancelWorkflow()`."
298
+ },
299
+ WORKFLOW_SIGNAL_TOKEN_INVALID: {
300
+ why: ({ provider }) => `[vitehub] \`resumeWorkflow()\` got a token that \`context.createSignal()\` did not make for the ${provider} Workflow provider of this app.`,
301
+ fix: "Pass the `token` of `context.createSignal()` from a run of this app, as it is. A token from another provider, such as an inline run in `vite dev`, does not resume a deployed run.",
302
+ data: ({ provider }) => ({ provider })
303
+ },
304
+ WORKFLOW_SIGNAL_VERCEL_UNSUPPORTED: {
305
+ why: ({ name }) => `[vitehub] The Workflow ${JSON.stringify(name)} called \`context.createSignal()\`. Signals do not work on Vercel yet.`,
306
+ fix: "Run the Workflow on Cloudflare or OpenWorkflow to wait for a signal. On Vercel, a `native` entry can wait with `defineHook()` from the Workflow DevKit, and `resumeWorkflow()` resumes its hook token."
307
+ },
290
308
  WORKFLOW_SLEEP_DURATION_INVALID: {
291
309
  why: ({ name, value }) => `[vitehub] The Workflow ${JSON.stringify(name)} called \`context.sleep(${value})\`. A sleep takes a duration such as \`'30 seconds'\` or \`'1 day'\`, a number of milliseconds that is 0 or more, or a valid \`Date\`.`,
292
310
  fix: "Write the duration as a number, one space, and a unit: second, minute, hour, day, week, month, or year, with or without a final `s`. For example `context.sleep('2 hours')`, `context.sleep(5_000)`, or `context.sleep(new Date(payload.remindAt))`."
@@ -17,10 +17,6 @@ const workflowErrorMessages = {
17
17
  function createWorkflowError(options) {
18
18
  return new ViteHubError(options.code, workflowErrorMessages[options.code], options);
19
19
  }
20
- /**
21
- * Throw it from a step or a handler to fail the run at once, with no more attempts, on every provider. Cloudflare reads
22
- * `isRetryable`, Workflow DevKit reads `fatal`, and ViteHub stops OpenWorkflow retries itself.
23
- */
24
20
  var NonRetryableError = class extends Error {
25
21
  name = "NonRetryableError";
26
22
  isRetryable = false;
@@ -45,7 +45,6 @@ type WorkflowProviderFailure = {
45
45
  };
46
46
  type WorkflowProviderOperationDetails = WorkflowOperationDetails & {
47
47
  acknowledgement?: WorkflowProviderAcknowledgement;
48
- /** The provider error name and the first line of its message, without URLs, file paths, or credentials. */
49
48
  reason?: string;
50
49
  status?: number;
51
50
  };
@@ -54,10 +53,6 @@ type WorkflowErrorDetails<TCode extends WorkflowErrorCode = WorkflowErrorCode> =
54
53
  } : TCode extends "VERCEL_WORKFLOW_SDK_LOAD_FAILED" ? {
55
54
  provider: "vercel";
56
55
  } : TCode extends "WORKFLOW_DEFINITION_NOT_FOUND" ? WorkflowNameDetails : TCode extends "WORKFLOW_DISABLED" ? Record<string, never> : TCode extends "WORKFLOW_NATIVE_ENTRY_INVALID" | "WORKFLOW_NATIVE_ENTRY_REQUIRED" | "WORKFLOW_RUN_ID_UNSUPPORTED" ? VercelWorkflowDetails : TCode extends "WORKFLOW_OPERATION_UNSUPPORTED" ? WorkflowOperationDetails : TCode extends "WORKFLOW_PROVIDER_OPERATION_FAILED" ? WorkflowProviderOperationDetails : never;
57
- /**
58
- * Throw it from a step or a handler to fail the run at once, with no more attempts, on every provider. Cloudflare reads
59
- * `isRetryable`, Workflow DevKit reads `fatal`, and ViteHub stops OpenWorkflow retries itself.
60
- */
61
56
  declare class NonRetryableError extends Error {
62
57
  override name: string;
63
58
  readonly isRetryable = false;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { A as WorkflowRun, B as WorkflowStep, C as WorkflowName, D as WorkflowProviderStep, E as WorkflowProviderContext, F as WorkflowSharedOptions, G as WorkflowStepRegistry, H as WorkflowStepContext, I as WorkflowSignalResult, K as WorkflowStepRetries, L as WorkflowStartArguments, M as WorkflowRunStatus, N as WorkflowRunStep, O as WorkflowRegistry, R as WorkflowStartDelay, S as WorkflowModuleDriverOptions, T as WorkflowPayload, U as WorkflowStepFunction, V as WorkflowStepBackoff, W as WorkflowStepOptions, _ as WorkflowDuration, a as InferredWorkflowDriverOptions, b as WorkflowHandle, c as OpenWorkflowWorkerOptions, d as WorkflowCreateOptions, f as WorkflowDefinition, g as WorkflowDriverOptions, h as WorkflowDriver, i as DiscoveredWorkflowDefinition, j as WorkflowRunError, k as WorkflowResultErrorCode, l as ResolvedWorkflowOptions, m as WorkflowDefinitionRegistry, n as CloudflareWorkflowDriverOptions, o as OpenWorkflowDriverOptions, p as WorkflowDefinitionOptions, q as WorkflowSteps, r as CloudflareWorkflowInstance, s as OpenWorkflowPostgresOptions, t as CloudflareWorkflowBinding, u as VercelWorkflowDriverOptions, v as WorkflowDurationUnit, w as WorkflowOptions, x as WorkflowHandler, y as WorkflowExecutionContext, z as WorkflowStartOptions } from "./types-Dsmwsdlv.js";
1
+ import { A as WorkflowRun, B as WorkflowStartOptions, C as WorkflowName, D as WorkflowProviderStep, E as WorkflowProviderContext, F as WorkflowSharedOptions, G as WorkflowStepOptions, H as WorkflowStepBackoff, I as WorkflowSignal, J as WorkflowSteps, K as WorkflowStepRegistry, L as WorkflowSignalResult, M as WorkflowRunStatus, N as WorkflowRunStep, O as WorkflowRegistry, R as WorkflowStartArguments, S as WorkflowModuleDriverOptions, T as WorkflowPayload, U as WorkflowStepContext, V as WorkflowStep, W as WorkflowStepFunction, _ as WorkflowDuration, a as InferredWorkflowDriverOptions, b as WorkflowHandle, c as OpenWorkflowWorkerOptions, d as WorkflowCreateOptions, f as WorkflowDefinition, g as WorkflowDriverOptions, h as WorkflowDriver, i as DiscoveredWorkflowDefinition, j as WorkflowRunError, k as WorkflowResultErrorCode, l as ResolvedWorkflowOptions, m as WorkflowDefinitionRegistry, n as CloudflareWorkflowDriverOptions, o as OpenWorkflowDriverOptions, p as WorkflowDefinitionOptions, q as WorkflowStepRetries, r as CloudflareWorkflowInstance, s as OpenWorkflowPostgresOptions, t as CloudflareWorkflowBinding, u as VercelWorkflowDriverOptions, v as WorkflowDurationUnit, w as WorkflowOptions, x as WorkflowHandler, y as WorkflowExecutionContext, z as WorkflowStartDelay } from "./types-BWPHeugk.js";
2
2
  import { defineWorkflow } from "./definition.js";
3
- import { a as WorkflowProviderFailure, i as WorkflowOperationName, n as WorkflowErrorCode, o as WorkflowProviderName, r as WorkflowErrorDetails, t as NonRetryableError } from "./errors-uhP8DZTi.js";
3
+ import { a as WorkflowProviderFailure, i as WorkflowOperationName, n as WorkflowErrorCode, o as WorkflowProviderName, r as WorkflowErrorDetails, t as NonRetryableError } from "./errors-D-fNDVg0.js";
4
4
  import { Result } from "@vite-hub/runtime";
5
5
  //#region src/integrations/cloudflare.d.ts
6
6
  export declare function getCloudflareWorkflowBindingName(name: string): string;
@@ -36,8 +36,10 @@ export declare function getWorkflowRun(name: string, id: string): Promise<Result
36
36
  */
37
37
  export declare function cancelWorkflow(name: string, id: string): Promise<Result<WorkflowRun<unknown, unknown>, WorkflowResultErrorCode>>;
38
38
  /**
39
- * Resumes a run that waits for a signal and returns `[error, signal]`. `token` is the opaque token that the provider
40
- * gave the waiting step. An empty token or a provider failure is `error`. Config errors throw.
39
+ * Resumes a run that waits for a signal and returns `[error, signal]`. `token` is `signal.token` from
40
+ * `context.createSignal()`, or the hook token of a native Vercel entry. `payload` is the value that `signal.wait()`
41
+ * returns: send a JSON value. An invalid token, a run that does not wait for the token, or a provider failure is
42
+ * `error`. Config errors throw.
41
43
  */
42
44
  export declare function resumeWorkflow<TPayload = unknown>(token: string, payload: TPayload): Promise<Result<WorkflowSignalResult, WorkflowResultErrorCode>>;
43
45
  /**
@@ -63,4 +65,4 @@ export declare function readRequestPayload(request: Request): Promise<unknown>;
63
65
  export declare function validatePayload<T>(payload: unknown, schema: PayloadValidator<T>): Promise<T>;
64
66
  export declare function readValidatedPayload<T>(request: Request, schema: PayloadValidator<T>): Promise<T>;
65
67
  //#endregion
66
- export { type CloudflareWorkflowBinding, type CloudflareWorkflowDriverOptions, type CloudflareWorkflowInstance, type DiscoveredWorkflowDefinition, type InferredWorkflowDriverOptions, NonRetryableError, type OpenWorkflowDriverOptions, type OpenWorkflowPostgresOptions, type OpenWorkflowWorkerOptions, type ResolvedWorkflowOptions, type VercelWorkflowDriverOptions, type WorkflowCreateOptions, type WorkflowDefinition, type WorkflowDefinitionOptions, type WorkflowDefinitionRegistry, type WorkflowDriver, type WorkflowDriverOptions, type WorkflowDuration, type WorkflowDurationUnit, type WorkflowErrorCode, type WorkflowErrorDetails, type WorkflowExecutionContext, type WorkflowHandle, type WorkflowHandler, type WorkflowModuleDriverOptions, type WorkflowName, type WorkflowOperationName, type WorkflowOptions, type WorkflowPayload, type WorkflowProviderContext, type WorkflowProviderFailure, type WorkflowProviderName, type WorkflowProviderStep, type WorkflowRegistry, type WorkflowResultErrorCode, type WorkflowRun, type WorkflowRunError, type WorkflowRunStatus, type WorkflowRunStep, type WorkflowSharedOptions, type WorkflowSignalResult, type WorkflowStartDelay, type WorkflowStartOptions, type WorkflowStep, type WorkflowStepBackoff, type WorkflowStepContext, type WorkflowStepFunction, type WorkflowStepOptions, type WorkflowStepRegistry, type WorkflowStepRetries, type WorkflowSteps, defineWorkflow };
68
+ export { type CloudflareWorkflowBinding, type CloudflareWorkflowDriverOptions, type CloudflareWorkflowInstance, type DiscoveredWorkflowDefinition, type InferredWorkflowDriverOptions, NonRetryableError, type OpenWorkflowDriverOptions, type OpenWorkflowPostgresOptions, type OpenWorkflowWorkerOptions, type ResolvedWorkflowOptions, type VercelWorkflowDriverOptions, type WorkflowCreateOptions, type WorkflowDefinition, type WorkflowDefinitionOptions, type WorkflowDefinitionRegistry, type WorkflowDriver, type WorkflowDriverOptions, type WorkflowDuration, type WorkflowDurationUnit, type WorkflowErrorCode, type WorkflowErrorDetails, type WorkflowExecutionContext, type WorkflowHandle, type WorkflowHandler, type WorkflowModuleDriverOptions, type WorkflowName, type WorkflowOperationName, type WorkflowOptions, type WorkflowPayload, type WorkflowProviderContext, type WorkflowProviderFailure, type WorkflowProviderName, type WorkflowProviderStep, type WorkflowRegistry, type WorkflowResultErrorCode, type WorkflowRun, type WorkflowRunError, type WorkflowRunStatus, type WorkflowRunStep, type WorkflowSharedOptions, type WorkflowSignal, type WorkflowSignalResult, type WorkflowStartDelay, type WorkflowStartOptions, type WorkflowStep, type WorkflowStepBackoff, type WorkflowStepContext, type WorkflowStepFunction, type WorkflowStepOptions, type WorkflowStepRegistry, type WorkflowStepRetries, type WorkflowSteps, defineWorkflow };
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
- import { t as workflowErrorDiagnostics } from "./error-diagnostics-0V2T3JFw.js";
1
+ import { t as workflowErrorDiagnostics } from "./error-diagnostics-DMeaFmQD.js";
2
2
  import { defineWorkflow } from "./definition.js";
3
- import { t as NonRetryableError } from "./errors-DCqRnZpN.js";
4
- import { n as getCloudflareWorkflowBindingName } from "./cloudflare-BHfClPvT.js";
5
- import { a as resumeWorkflow, i as getWorkflowRun, n as createWorkflow, o as startWorkflow, r as deferWorkflow, t as cancelWorkflow } from "./client-DkwOxEiT.js";
3
+ import { t as NonRetryableError } from "./errors-BNxEeeCO.js";
4
+ import { n as getCloudflareWorkflowBindingName } from "./cloudflare-Datj_znU.js";
5
+ import { a as resumeWorkflow, i as getWorkflowRun, n as createWorkflow, o as startWorkflow, r as deferWorkflow, t as cancelWorkflow } from "./client-CgBcDlGn.js";
6
6
  //#region src/runtime/payload.ts
7
7
  /** Reads a JSON body as parsed JSON and any other body as text. The value is not checked: pass it to `validatePayload()`. */
8
8
  async function readRequestPayload(request) {