@vite-hub/workflow 0.1.0 → 0.4.1

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 (66) hide show
  1. package/README.md +173 -55
  2. package/dist/{app-CzPoP84f.js → app-He0GTrYZ.js} +1 -1
  3. package/dist/client-DkwOxEiT.js +707 -0
  4. package/dist/{cloudflare-nF4abPd4.js → cloudflare-BHfClPvT.js} +2 -2
  5. package/dist/{cloudflare-env-BNrYo29x.js → cloudflare-env-CGLx7lUd.js} +44 -42
  6. package/dist/cloudflare-env-lookup-CfX6wZKb.d.ts +4 -0
  7. package/dist/{cloudflare-env-CIjdFTv6.d.ts → cloudflare-shared-CTqh_a2s.d.ts} +2 -2
  8. package/dist/{config-IJMb0eeZ.js → config-C3DvtjfJ.js} +41 -40
  9. package/dist/definition.d.ts +18 -0
  10. package/dist/definition.js +33 -0
  11. package/dist/delay-D1-nq_VE.js +46 -0
  12. package/dist/dev-recorder-CTN5Fkao.js +10 -0
  13. package/dist/durability.d.ts +23 -0
  14. package/dist/durability.js +62 -0
  15. package/dist/error-diagnostics-0V2T3JFw.js +317 -0
  16. package/dist/error-diagnostics-CQ4BUqRe.js +270 -0
  17. package/dist/errors-DCqRnZpN.js +35 -0
  18. package/dist/errors-uhP8DZTi.d.ts +67 -0
  19. package/dist/index.d.ts +35 -63
  20. package/dist/index.js +15 -19
  21. package/dist/object-Da1zyPCR.js +11 -0
  22. package/dist/openworkflow-BhzxV_Y3.d.ts +52 -0
  23. package/dist/openworkflow-defaults-DDig2M4s.js +26 -0
  24. package/dist/openworkflow-storage-Dj9zUAsk.js +28 -0
  25. package/dist/openworkflow.d.ts +2 -0
  26. package/dist/openworkflow.js +2 -0
  27. package/dist/{operations-tNUdj3G4.d.ts → operation-definition-nmRu_O3V.d.ts} +42 -15
  28. package/dist/operations-D_WJwjrS.js +333 -0
  29. package/dist/operations.d.ts +40 -6
  30. package/dist/operations.js +163 -736
  31. package/dist/{out-CsaJxg8m.js → out-DxLKolA0.js} +32 -1430
  32. package/dist/{rolldown-runtime-CMFfr-1z.js → rolldown-runtime-B4iAMlE-.js} +10 -1
  33. package/dist/run-error-DBWqiJHH.js +110 -0
  34. package/dist/run-failed-gVGo1BaF.js +18 -0
  35. package/dist/runtime/cloudflare-runner.d.ts +3 -5
  36. package/dist/runtime/cloudflare-runner.js +39 -45
  37. package/dist/runtime/cloudflare-shared.d.ts +2 -2
  38. package/dist/runtime/cloudflare-shared.js +1 -1
  39. package/dist/runtime/cloudflare-vite.d.ts +3 -2
  40. package/dist/runtime/cloudflare-vite.js +47 -1
  41. package/dist/runtime/dev-runs.d.ts +4 -0
  42. package/dist/runtime/dev-runs.js +73 -0
  43. package/dist/runtime/execute.d.ts +42 -5
  44. package/dist/runtime/execute.js +216 -17
  45. package/dist/runtime/openworkflow-worker.d.ts +29 -2
  46. package/dist/runtime/openworkflow-worker.js +156 -38
  47. package/dist/runtime/openworkflow.d.ts +2 -21
  48. package/dist/runtime/openworkflow.js +307 -44
  49. package/dist/runtime/state.d.ts +3 -1
  50. package/dist/runtime/state.js +6 -6
  51. package/dist/runtime/vercel-vite.d.ts +1 -1
  52. package/dist/runtime/vercel-vite.js +7 -4
  53. package/dist/types-Dsmwsdlv.d.ts +282 -0
  54. package/dist/{vercel-D-ZNtB_u.js → vercel-DTvm61iY.js} +53 -24
  55. package/dist/vite.d.ts +228 -30
  56. package/dist/vite.js +2640 -1449
  57. package/package.json +28 -50
  58. package/dist/client-DsGM3M4U.js +0 -389
  59. package/dist/cloudflare-shared-CaxrMD1A.d.ts +0 -1
  60. package/dist/cloudflare-vite-B3IabBsv.js +0 -47
  61. package/dist/error-diagnostics-A_8Kp-48.js +0 -116
  62. package/dist/error-diagnostics-pwNFvAHP.js +0 -67
  63. package/dist/operations-B_rYG71W.js +0 -230
  64. package/dist/provider-operation-CW2cYfVy.js +0 -65
  65. package/dist/runtime-type-DBCvIh5x.js +0 -7
  66. package/dist/types-D82WmfZa.d.ts +0 -180
@@ -0,0 +1,317 @@
1
+ import { defineDiagnostics } from "nostics";
2
+ //#region src/error-diagnostics.ts
3
+ const dynamicError = { why: ({ message }) => message === void 0 ? "" : String(message) };
4
+ const workflowErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
5
+ docsBase: "https://vitehub.dev/docs/workflows/diagnostics",
6
+ codes: {
7
+ WORKFLOW_AGENT_NOT_DISCOVERED: {
8
+ why: ({ name }) => `[vitehub] The Agent Workflow ${JSON.stringify(name)} is not a discovered Agent, so OpenWorkflow workers cannot run its turns.`,
9
+ fix: "Move the Agent to server/agents/, so that the build adds its Workflow to the registry that every OpenWorkflow worker loads. To run it without a Workflow, call runAgent()."
10
+ },
11
+ WORKFLOW_PROVIDER_OPERATION_FAILED: {
12
+ why: ({ operation, provider, reason }) => `The ${provider} Workflow provider failed during ${operation}.${reason ? ` ${reason}` : ""}`,
13
+ fix: ({ acknowledgement }) => acknowledgement === "unknown" ? "The call may have reached the provider. If the original start supplied a run `id`, check that ID with `getWorkflowRun()` and reuse the same ID if you retry. If you do not know the original ID, verify whether the run started before trying again. Read `error.cause` for the provider error." : "Read `error.cause` for the provider error. Retry when the provider is available again.",
14
+ data: ({ acknowledgement, operation, provider, reason, status }) => ({
15
+ acknowledgement,
16
+ operation,
17
+ provider,
18
+ reason,
19
+ status
20
+ })
21
+ },
22
+ WORKFLOW_RUN_ID_UNSUPPORTED: {
23
+ why: "A native Vercel Workflow assigns its own run ID, so `startWorkflow()` cannot use the `id` option.",
24
+ fix: "Remove `id` from the options of `startWorkflow()`. Store the `id` of the run that it returns."
25
+ },
26
+ WORKFLOW_DEFINITION_NOT_FOUND: {
27
+ why: ({ available, workflow }) => workflow === void 0 ? "Workflow definition was not found." : `Unknown Workflow: ${workflow}.${available ?? ""}`,
28
+ fix: "Pass the name of a Workflow Definition, the file name in `server/workflows/` without the extension."
29
+ },
30
+ WORKFLOW_DISABLED: {
31
+ why: "Workflow is disabled in this runtime.",
32
+ fix: "Enable Workflow with `vitehub({ workflow: true })` or `hubWorkflow()`."
33
+ },
34
+ WORKFLOW_OPERATION_FAILED: {
35
+ why: "The Workflow operation failed.",
36
+ fix: "Read `error.cause` for the error of the Workflow runtime. Check the Workflow handler and the provider, then retry."
37
+ },
38
+ WORKFLOW_OPERATION_UNSUPPORTED: {
39
+ why: ({ note, operation, provider }) => note === void 0 ? `workflow ${operation} is not supported by the ${provider} provider for this run.` : `workflow ${operation} is not supported by the ${provider} provider. ${note}`,
40
+ fix: "Use an operation that the provider supports, or run the app with a Workflow provider that supports it. The message says what the provider cannot do.",
41
+ data: ({ operation, provider }) => ({
42
+ operation,
43
+ provider
44
+ })
45
+ },
46
+ WORKFLOW_REGISTRY_MISSING: {
47
+ why: ({ workflow }) => `Unknown Workflow: ${workflow}. The runtime has no Workflow registry.`,
48
+ fix: "Restart the dev server. In development the Workflow Vite plugin installs the registry with the Nitro plugin .vitehub/nitro/workflow/dev-plugin.mjs."
49
+ },
50
+ WORKFLOW_RUNS_UNAVAILABLE: {
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."
53
+ },
54
+ WORKFLOW_RUN_AMBIGUOUS: {
55
+ why: ({ id, workflows }) => `Runs of ${workflows} have the id ${id}.`,
56
+ fix: "Pass the name of the Workflow with `--workflow <name>`."
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
+ WORKFLOW_RUN_UNKNOWN: {
63
+ why: ({ runId }) => `Run ${runId} was not started by \`workflow.start\` in this runtime.`,
64
+ fix: "Pass the name of the Workflow with `--workflow <name>`."
65
+ },
66
+ WORKFLOW_C0001: {
67
+ ...dynamicError,
68
+ fix: "Set the `workflow` option that the message names to a non-empty string, or remove it."
69
+ },
70
+ WORKFLOW_C0002: {
71
+ ...dynamicError,
72
+ fix: "Set the `workflow` option that the message names to a string, or to an env declaration such as `{ kind: \"env-variable\", source: { kind: \"env\", name: \"OPENWORKFLOW_POSTGRES_URL\" } }`."
73
+ },
74
+ WORKFLOW_C0003: {
75
+ ...dynamicError,
76
+ fix: "Set the `runMigrations` option that the message names to `true` or `false`, or remove it."
77
+ },
78
+ WORKFLOW_C0004: {
79
+ ...dynamicError,
80
+ fix: "Set `workflow.worker.concurrency` to an integer of 1 or more, or remove it."
81
+ },
82
+ WORKFLOW_C0005: {
83
+ ...dynamicError,
84
+ fix: "Set `workflow.postgres` to an object, such as `{ url: \"postgres://...\" }`, or remove it."
85
+ },
86
+ WORKFLOW_C0006: {
87
+ ...dynamicError,
88
+ fix: "Set `workflow.sqlite` to an object, such as `{ path: \".vitehub/data/workflow.sqlite\" }`, or remove it."
89
+ },
90
+ WORKFLOW_C0007: {
91
+ ...dynamicError,
92
+ fix: "Set `workflow.worker` to an object, such as `{ concurrency: 4 }`, or remove it."
93
+ },
94
+ WORKFLOW_C0008: {
95
+ ...dynamicError,
96
+ fix: "On Netlify, set `workflow: { driver: \"openworkflow\" }` with `workflow.sqlite.path` or `workflow.postgres.url`, or set `workflow: false`."
97
+ },
98
+ WORKFLOW_C0009: {
99
+ ...dynamicError,
100
+ fix: "Set `workflow.driver` to `\"cloudflare\"`, `\"openworkflow\"`, or `\"vercel\"`, or remove it to let ViteHub select the driver of the host."
101
+ },
102
+ WORKFLOW_C0010: {
103
+ ...dynamicError,
104
+ fix: "Rename one of the two step files that the message names, so that each step file of the Workflow folder gives a different step name."
105
+ },
106
+ WORKFLOW_C0011: {
107
+ ...dynamicError,
108
+ fix: "Rename the step file that the message names so that it has letters after its number prefix, such as `01.create-user.ts`."
109
+ },
110
+ WORKFLOW_C0012: {
111
+ ...dynamicError,
112
+ fix: "Set only one of `workflow.postgres.url` and `workflow.sqlite.path`, and remove the other."
113
+ },
114
+ WORKFLOW_C0013: {
115
+ ...dynamicError,
116
+ fix: "Set `workflow` to an object, such as `{ driver: \"openworkflow\" }`, or remove it."
117
+ },
118
+ WORKFLOW_C0014: {
119
+ ...dynamicError,
120
+ fix: "Set `handler` to a function in the object that you pass to `defineWorkflow()`, such as `defineWorkflow({ handler: async ({ payload, steps }) => { ... } })`."
121
+ },
122
+ WORKFLOW_C0015: {
123
+ ...dynamicError,
124
+ fix: "Pass one object to `defineWorkflow()`, such as `defineWorkflow({ handler, native })`, with only `handler`, `native`, and `rootStep`. The file path is the Workflow name, so do not pass a name."
125
+ },
126
+ WORKFLOW_C0016: {
127
+ ...dynamicError,
128
+ fix: "Set `native` in the object that you pass to `defineWorkflow()` to a function, or remove it."
129
+ },
130
+ WORKFLOW_C0017: {
131
+ ...dynamicError,
132
+ fix: "Remove `workflow.database`, and set `workflow.sqlite.path` or `workflow.postgres.url`."
133
+ },
134
+ WORKFLOW_C0020: {
135
+ ...dynamicError,
136
+ fix: "Set `workflow: { driver: \"openworkflow\", sqlite: { path: \".vitehub/data/workflow.sqlite\" } }` or `workflow.postgres.url`, and start the worker with `startOpenWorkflowWorker()`."
137
+ },
138
+ WORKFLOW_CLOUDFLARE_RUN_ID_INVALID: {
139
+ why: ({ id }) => `[vitehub] Cloudflare does not accept the run id ${JSON.stringify(id)}. A Cloudflare instance id starts with a letter, a digit, or \`_\`, then uses only letters, digits, \`-\`, and \`_\`, up to 100 characters.`,
140
+ fix: "Build the id from allowed characters only, for example `checkout-${orderId}` instead of `checkout:${orderId}`. Hash a long or free-form value first."
141
+ },
142
+ WORKFLOW_OPENWORKFLOW_DATABASE_URL_IGNORED: {
143
+ why: "DATABASE_URL contains a Postgres URL, but OpenWorkflow no longer selects storage from DATABASE_URL alone. Falling back to a local SQLite file would leave existing Postgres runs behind and stop sharing runs between servers.",
144
+ fix: "Set OPENWORKFLOW_POSTGRES_URL or `workflow.postgres.url` to the same Postgres URL, or add a Postgres Default Database. To choose local storage intentionally, set `workflow.sqlite.path` or OPENWORKFLOW_SQLITE_PATH."
145
+ },
146
+ WORKFLOW_OPENWORKFLOW_DATABASE_URL_MISSING: {
147
+ why: "OpenWorkflow uses the Postgres Default Database of the app, but that Database has no connection URL outside a request. It connects through PG* environment variables, which OpenWorkflow cannot read.",
148
+ fix: "Set `connection.url` on the Database Definition, or set OPENWORKFLOW_POSTGRES_URL or `workflow.postgres.url`."
149
+ },
150
+ WORKFLOW_OPENWORKFLOW_SETUP_CONNECTION_UNAVAILABLE: {
151
+ why: "OpenWorkflow sets up its Postgres schema on a second connection while this server holds the setup lock on the first. The database gave no second connection in 10 seconds, so the setup did not start. A pool with one connection, or a pool that other traffic fills, does this. The server tries again later.",
152
+ fix: "Raise the pool size to 2 or more. Or set up the schema once through a direct connection, then set `workflow.postgres.runMigrations: false`."
153
+ },
154
+ WORKFLOW_OPENWORKFLOW_SETUP_LOCK_TIMEOUT: {
155
+ why: ({ seconds }) => `Another server held the OpenWorkflow schema setup lock for ${seconds} seconds. This server did not start the schema setup.`,
156
+ fix: "Check the server that holds the setup lock and let its migration finish. The worker retries automatically. If you start a worker yourself, retry after the lock is released."
157
+ },
158
+ WORKFLOW_PAYLOAD_JSON_INVALID: {
159
+ why: "[vitehub] The request has the `application/json` content type, but its body is not valid JSON.",
160
+ fix: "Send a JSON body with `content-type: application/json`, or send another content type to read the body as text. Read `error.cause` for the parse error."
161
+ },
162
+ WORKFLOW_R0001: {
163
+ ...dynamicError,
164
+ fix: "Remove `workflow.binding` and `workflow.name`, which apply only to an app with one Workflow, or keep one Workflow under `server/workflows/`."
165
+ },
166
+ WORKFLOW_R0003: {
167
+ ...dynamicError,
168
+ fix: "Delete the `.vercel/output` folder and `.vitehub/workflow/vercel-output.json`, then build again, so that ViteHub writes these JSON files again."
169
+ },
170
+ WORKFLOW_R0004: {
171
+ ...dynamicError,
172
+ fix: "Move the file with `\"use workflow\"` that the message names into the folder of its Workflow under `server/workflows/`."
173
+ },
174
+ WORKFLOW_R0005: {
175
+ ...dynamicError,
176
+ fix: "Build all native Vercel Workflow source folders in one build, or delete the Workflow DevKit functions that the message lists from `.vercel/output`."
177
+ },
178
+ WORKFLOW_R0006: {
179
+ ...dynamicError,
180
+ fix: "Install the `workflow` and `@workflow/builders` packages, such as with `pnpm add workflow @workflow/builders`, then build again."
181
+ },
182
+ WORKFLOW_R0008: {
183
+ ...dynamicError,
184
+ fix: "Rename the Workflow that the message names. Names that start with `vitehub-agent-invocation-recovery-` are for the Workflows that ViteHub generates for Agents."
185
+ },
186
+ WORKFLOW_R0009: {
187
+ ...dynamicError,
188
+ fix: "Pass `createWorkflow()` a non-empty Workflow name, as `createWorkflow(\"welcome\", handler)` or `createWorkflow({ name, handler })`."
189
+ },
190
+ WORKFLOW_R0010: {
191
+ ...dynamicError,
192
+ fix: "Pass `createWorkflow()` a handler function, as `createWorkflow(\"welcome\", handler)` or `createWorkflow({ name, handler })`."
193
+ },
194
+ WORKFLOW_R0011: {
195
+ ...dynamicError,
196
+ fix: "Pass `createWorkflow()` a non-empty Workflow name, as `createWorkflow(\"welcome\", handler)` or `createWorkflow({ name, handler })`."
197
+ },
198
+ WORKFLOW_R0012: {
199
+ ...dynamicError,
200
+ fix: "Pass `createWorkflow()` a handler function, as `createWorkflow(\"welcome\", handler)` or `createWorkflow({ name, handler })`."
201
+ },
202
+ WORKFLOW_R0013: {
203
+ ...dynamicError,
204
+ fix: "Pass the options of `createWorkflow(name, options)` as an object, such as `{ handler }`."
205
+ },
206
+ WORKFLOW_R0014: {
207
+ ...dynamicError,
208
+ fix: "Pass `resumeWorkflow()` the signal token that the waiting step of the run received, as a non-empty string."
209
+ },
210
+ WORKFLOW_R0015: {
211
+ ...dynamicError,
212
+ fix: "Deploy the Worker with the output of the current build, and keep the file under `server/workflows/` of every Workflow that still has runs on Cloudflare."
213
+ },
214
+ WORKFLOW_R0017: {
215
+ ...dynamicError,
216
+ fix: "Set `workflow: { driver: \"openworkflow\" }` in `vitehub()`, or pass a `config` with that driver to `createOpenWorkflowWorker()`."
217
+ },
218
+ WORKFLOW_R0018: {
219
+ ...dynamicError,
220
+ fix: "Set `workflow.sqlite.path` to a local SQLite file, such as `.vitehub/data/workflow.sqlite`. OpenWorkflow cannot use a remote libSQL or HTTP database."
221
+ },
222
+ WORKFLOW_R0019: {
223
+ ...dynamicError,
224
+ fix: "Set `workflow.sqlite.path` to a local file path or a `file:` URL."
225
+ },
226
+ WORKFLOW_R0020: {
227
+ ...dynamicError,
228
+ fix: "Set `workflow: { driver: \"openworkflow\" }` in `vitehub()` before you use the OpenWorkflow runtime."
229
+ },
230
+ WORKFLOW_R0021: {
231
+ ...dynamicError,
232
+ fix: "Send a payload that the schema accepts. Use a schema whose failed `safeParse()` returns an `error`, so that the error names the field."
233
+ },
234
+ WORKFLOW_R0022: {
235
+ ...dynamicError,
236
+ fix: "Pass `validatePayload()` or `readValidatedPayload()` a function, or a schema with a `safeParse()` or `parse()` method, such as a Zod schema."
237
+ },
238
+ WORKFLOW_R0023: {
239
+ ...dynamicError,
240
+ fix: "Pass `createWorkflow()` a non-empty Workflow name, as `createWorkflow(\"welcome\", handler)` or `createWorkflow({ name, handler })`."
241
+ },
242
+ WORKFLOW_R0024: {
243
+ ...dynamicError,
244
+ fix: "Give each inline `createWorkflow()` Workflow a different name."
245
+ },
246
+ WORKFLOW_R0025: {
247
+ ...dynamicError,
248
+ fix: "Give the inline `createWorkflow()` Workflow and the file under `server/workflows/` different names, or remove one of them."
249
+ },
250
+ WORKFLOW_R0026: {
251
+ ...dynamicError,
252
+ fix: "Install the `workflow` package version that `@vite-hub/workflow` lists as a peer dependency, then build again. A retry does not help."
253
+ },
254
+ WORKFLOW_R0027: {
255
+ ...dynamicError,
256
+ fix: "Remove `workflow.database`, and set `workflow.sqlite.path` or `workflow.postgres.url`."
257
+ },
258
+ WORKFLOW_R0028: {
259
+ ...dynamicError,
260
+ fix: "Set the env variable that `workflow.sqlite.path` reads to a local SQLite file path, or set `workflow.sqlite.path` to a string."
261
+ },
262
+ WORKFLOW_R0029: {
263
+ ...dynamicError,
264
+ fix: "Set the env variable that `workflow.postgres.url` reads to a Postgres URL, or set `workflow.postgres.url` to a string."
265
+ },
266
+ WORKFLOW_R0030: {
267
+ ...dynamicError,
268
+ fix: "Keep only one of `workflow.postgres.url` and `workflow.sqlite.path`."
269
+ },
270
+ WORKFLOW_R0036: {
271
+ why: ({ binding, name }) => `[vitehub] The Cloudflare Workflow ${JSON.stringify(name)} needs the binding ${JSON.stringify(binding)}, and the Worker has no binding of that name. ViteHub does not run the Workflow inline outside a development server, because an inline run is not durable.`,
272
+ fix: "Deploy with the Wrangler config that the build writes, or add the Workflow binding to your own Wrangler config. Set `workflow.binding` when the binding has another name."
273
+ },
274
+ WORKFLOW_B0002: {
275
+ why: ({ root }) => `[vitehub] Cannot identify the owning Workflow build for ${JSON.stringify(root)} because its environment does not uniquely match a resolved configuration.`,
276
+ fix: "Use a separate Workflow plugin instance per build or preserve the resolved build options in each environment config."
277
+ },
278
+ WORKFLOW_B0003: {
279
+ why: "[vitehub] Agent Workflows need the Agent package, and the project does not resolve `@vite-hub/agent`.",
280
+ fix: "Install `@vite-hub/agent`, or turn the Agent on with `vitehub({ agent: true })`."
281
+ },
282
+ WORKFLOW_RENAMED_PROVIDER_KEY: {
283
+ 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
+ fix: ({ value }) => `Set \`workflow: { driver: ${value} }\`, or run \`npx @vite-hub/codemods driver-key\` to rename it in every config file.`
285
+ },
286
+ WORKFLOW_ROOT_STEP_SLEEP: {
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
+ 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
+ },
290
+ WORKFLOW_SLEEP_DURATION_INVALID: {
291
+ 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
+ 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))`."
293
+ },
294
+ WORKFLOW_START_DELAY_INVALID: {
295
+ why: ({ delay }) => `[vitehub] \`startWorkflow()\` does not accept the delay ${JSON.stringify(delay)}. A delay is a duration such as \`"30m"\` or \`"3 days"\`, or a valid \`Date\`, that ends before the year 275760.`,
296
+ fix: "Pass `{ delay: \"1h\" }`, `{ delay: \"3 days\" }`, or `{ delay: new Date(\"2026-12-01T09:00:00Z\") }`. For a month or a calendar time, pass a `Date`."
297
+ },
298
+ WORKFLOW_STEP_OPTIONS_INVALID: {
299
+ why: ({ option, step, value }) => `[vitehub] The Workflow step ${JSON.stringify(step)} sets \`${option}\` to ${value}. A step takes \`retries: { limit, delay, backoff }\` and \`timeout\`.`,
300
+ fix: "Set `retries.limit` to a whole number of 0 or more, `retries.delay` to a duration such as `'30 seconds'` or a number of milliseconds, `retries.backoff` to `'constant'` or `'exponential'`, and `timeout` to a duration that is more than 0. Remove other keys."
301
+ },
302
+ WORKFLOW_STEP_OPTIONS_NOT_STATIC: {
303
+ why: ({ file, option }) => `[vitehub] The Workflow step file ${JSON.stringify(file)} exports \`${option}\`, and the build cannot read its value without running the file.`,
304
+ fix: "Write the value in the export itself, with literals only, such as `export const retries = { limit: 5, delay: '30 seconds' }` or `export const timeout = '2 minutes'`. The build reads it from the source to check it and to configure the provider."
305
+ },
306
+ WORKFLOW_STEP_RETRY_DELAY_UNSUPPORTED: {
307
+ why: ({ file }) => `[vitehub] The Workflow step file ${JSON.stringify(file)} sets \`retries.delay\` or \`retries.backoff\`. On Vercel, Workflow DevKit runs this step and retries it after about one second. It has no wait or backoff option for a step.`,
308
+ fix: "Remove `delay` and `backoff` from `retries`, and keep `limit`. To wait longer between attempts, deploy the Workflow on Cloudflare or OpenWorkflow."
309
+ },
310
+ WORKFLOW_STEP_TIMEOUT: {
311
+ why: ({ step, timeout }) => `[vitehub] The Workflow step ${JSON.stringify(step)} ran longer than its timeout of ${timeout}. ViteHub aborted the step's signal and failed this attempt.`,
312
+ fix: "Make the step finish sooner, or set a longer `timeout` in the step file. Pass the `signal` of the step to `fetch()` and other calls, so they stop when the attempt times out. The provider retries the step as its `retries` say."
313
+ }
314
+ }
315
+ });
316
+ //#endregion
317
+ export { workflowErrorDiagnostics as t };
@@ -0,0 +1,270 @@
1
+ import { defineDiagnostics } from "nostics";
2
+ //#region ../internal/src/error-diagnostics.ts
3
+ const dynamicError = { why: ({ message }) => message === void 0 ? "" : String(message) };
4
+ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
5
+ docsBase: "https://vitehub.dev/docs/development/diagnostics",
6
+ codes: {
7
+ INTERNAL_R0012: {
8
+ ...dynamicError,
9
+ fix: "Check the URL, the headers, and the credentials of the HTTP request. `error.status` holds the status that the server sent."
10
+ },
11
+ INTERNAL_R0013: {
12
+ ...dynamicError,
13
+ fix: "Check that the provider token can manage the resource in the path that the message names. `error.kind` and `error.codes` hold the provider failure."
14
+ },
15
+ INTERNAL_R0014: {
16
+ why: ({ path }) => `Cannot read Provision State from "${path}".`,
17
+ fix: "Check file access and restore valid JSON while preserving existing resource IDs."
18
+ },
19
+ INTERNAL_R0020: {
20
+ fix: "Give the operation a name like `content.publish`, a description, a section, a kind, an input schema, and a run function.",
21
+ why: ({ message }) => message === void 0 ? "" : String(message)
22
+ },
23
+ INTERNAL_R0021: {
24
+ fix: "Run `vitehub inspect definitions --kind operation` to list the operations of this app.",
25
+ why: ({ message }) => message === void 0 ? "" : String(message)
26
+ },
27
+ INTERNAL_R0022: {
28
+ fix: "Send input that matches the schema of the operation. `vitehub <namespace> <command> --help` shows the fields.",
29
+ why: ({ message }) => message === void 0 ? "" : String(message)
30
+ },
31
+ INTERNAL_R0024: {
32
+ fix: "Start the dev server with `vite dev`, or pass `--url <origin>` of a deployed app and set VITEHUB_CONSOLE_PRIVATE_KEY_<NAME> to a private key whose public key the app has in VITEHUB_CONSOLE_KEY_<NAME>.",
33
+ why: ({ message }) => message === void 0 ? "" : String(message)
34
+ },
35
+ INTERNAL_R0023: {
36
+ fix: "Ask for access to the section of this operation.",
37
+ why: ({ message }) => message === void 0 ? "" : String(message)
38
+ },
39
+ INTERNAL_B0001: {
40
+ ...dynamicError,
41
+ fix: "Give the resource that the message names another name or binding in the `vitehub()` options of its feature, so that two different Cloudflare resources do not share one name."
42
+ },
43
+ INTERNAL_B0015: {
44
+ ...dynamicError,
45
+ fix: "Install one version of the package that the message names, for example with `pnpm dedupe` or an `overrides` entry in `package.json`."
46
+ },
47
+ INTERNAL_B0016: {
48
+ ...dynamicError,
49
+ fix: "Correct the field that the message names in the `package.json` of a runtime dependency of the app, such as a workspace package, or run `pnpm install` again to restore an installed package."
50
+ },
51
+ INTERNAL_B0017: {
52
+ ...dynamicError,
53
+ fix: "Correct the field that the message names in the `package.json` of a runtime dependency of the app, such as a workspace package, or run `pnpm install` again to restore an installed package."
54
+ },
55
+ INTERNAL_B0018: {
56
+ ...dynamicError,
57
+ fix: "Correct the field that the message names in the `package.json` of a runtime dependency of the app, such as a workspace package, or run `pnpm install` again to restore an installed package."
58
+ },
59
+ INTERNAL_B0019: {
60
+ ...dynamicError,
61
+ fix: "Correct the field that the message names in the `package.json` of a runtime dependency of the app, such as a workspace package, or run `pnpm install` again to restore an installed package."
62
+ },
63
+ INTERNAL_B0020: {
64
+ ...dynamicError,
65
+ fix: "Correct the field that the message names in the `package.json` of a runtime dependency of the app, such as a workspace package, or run `pnpm install` again to restore an installed package."
66
+ },
67
+ INTERNAL_B0021: {
68
+ ...dynamicError,
69
+ fix: "Install the package that the message names in the app, for example with `pnpm add <name>`, then build again."
70
+ },
71
+ INTERNAL_B0022: {
72
+ ...dynamicError,
73
+ fix: "Install one version of the package that the message names, for example with `pnpm dedupe` or an `overrides` entry in `package.json`."
74
+ },
75
+ INTERNAL_B0025: {
76
+ ...dynamicError,
77
+ fix: "Replace the `new URL(\"./...\", import.meta.url)` in the project-root `main.ts`, or in a Schedule file of `server/schedules/` and the files it imports, with a static `import` of that file."
78
+ },
79
+ INTERNAL_B0026: {
80
+ ...dynamicError,
81
+ fix: "Replace the computed `import()` in the project-root `main.ts`, or in a Schedule file of `server/schedules/` and the files it imports, with a static `import` or with `import(\"<literal path>\")`."
82
+ },
83
+ INTERNAL_B0027: {
84
+ ...dynamicError,
85
+ fix: "Replace the computed `require()` in the project-root `main.ts`, or in a Schedule file of `server/schedules/` and the files it imports, with a static `import`."
86
+ },
87
+ INTERNAL_B0028: {
88
+ ...dynamicError,
89
+ fix: "Wait for the other build of this app to finish, or stop the process that the message names, then build again."
90
+ },
91
+ INTERNAL_B0029: {
92
+ ...dynamicError,
93
+ fix: "Stop the other builds that write the same Deno output folder, delete the `.vitehub-lock` folder next to that output folder, such as `.output.vitehub-lock`, then build again."
94
+ },
95
+ INTERNAL_B0031: {
96
+ ...dynamicError,
97
+ fix: "Import `./schedule/deno-cron.mjs` at the top level of the project-root `main.ts`, for example with `await import(new URL(\"./schedule/deno-cron.mjs\", import.meta.url).href)` outside any condition."
98
+ },
99
+ INTERNAL_B0032: {
100
+ ...dynamicError,
101
+ fix: "Import `./server/index.mjs` at the top level of the project-root `main.ts`, for example with `await import(new URL(\"./server/index.mjs\", import.meta.url).href)` outside any condition."
102
+ },
103
+ INTERNAL_B0035: {
104
+ ...dynamicError,
105
+ fix: "Delete the provider output folder that holds the file that the message names, such as `dist/<app>` for Cloudflare, and build again."
106
+ },
107
+ INTERNAL_B0039: {
108
+ ...dynamicError,
109
+ fix: "Fix the build error that ViteHub showed before this one. ViteHub stops writing the provider output when another part of the build fails."
110
+ },
111
+ INTERNAL_B0040: {
112
+ ...dynamicError,
113
+ fix: "Remove the custom Nitro `output.serverDir`, so that the Nitro preset of the host writes the server entry that the message names."
114
+ },
115
+ INTERNAL_B0043: {
116
+ ...dynamicError,
117
+ fix: "Delete the build output folder, such as `.output` or `.vercel/output`, and build again."
118
+ },
119
+ INTERNAL_B0046: {
120
+ ...dynamicError,
121
+ fix: "Install the package that the message names in the app, for example with `pnpm add <name>`, then build again."
122
+ },
123
+ INTERNAL_B0047: {
124
+ ...dynamicError,
125
+ fix: "Correct the `package.json` file that the message names so that it holds one JSON object, or run `pnpm install` again to restore an installed package."
126
+ },
127
+ INTERNAL_B0048: {
128
+ fix: "Rename one of the two operations. A name is `<section>.<verb>` and is unique in the app.",
129
+ why: ({ message }) => message === void 0 ? "" : String(message)
130
+ },
131
+ INTERNAL_B0049: {
132
+ fix: "Set `cli: { namespace, command }` on one of the two operations.",
133
+ why: ({ message }) => message === void 0 ? "" : String(message)
134
+ },
135
+ INTERNAL_B0050: {
136
+ fix: "Rename one of the two operations, or set `mcp: false` on it. MCP tool names replace every character outside letters, digits, `_`, and `-` with `_`.",
137
+ why: ({ message }) => message === void 0 ? "" : String(message)
138
+ },
139
+ INTERNAL_B0051: {
140
+ why: ({ field, generated, name, path, project, scope }) => `The Cloudflare ${path} entry "${name}"${scope} is written by ViteHub and by the project's Wrangler config with a different ${field}: ${generated} and ${project}.`,
141
+ fix: "Remove the entry from the project's Wrangler config, since ViteHub writes it, or give one of them another name."
142
+ },
143
+ INTERNAL_B0052: {
144
+ why: ({ column, section }) => `The column "${column}" of the Console section "${section}" needs both \`format: "switch"\` and a \`switch\` operation name such as "skills.set".`,
145
+ fix: "Give a switch column `format: \"switch\"` and `switch: { operation, input }` with a registered operation name, or remove both."
146
+ },
147
+ INTERNAL_R0025: {
148
+ fix: "Start `vite dev` in the project that you run the command from, or pass `--url` of that server.",
149
+ why: ({ message }) => message === void 0 ? "" : String(message)
150
+ },
151
+ INTERNAL_R0026: {
152
+ why: "The server parsed a destructive operation that the CLI did not confirm.",
153
+ fix: "Review the operation, then run it again with --yes to confirm the change."
154
+ },
155
+ INTERNAL_C0001: {
156
+ ...dynamicError,
157
+ fix: "Rename or remove one of the two files that the message lists. ViteHub takes the Definition name from the file path."
158
+ },
159
+ INTERNAL_C0002: {
160
+ ...dynamicError,
161
+ fix: "Rename or remove one of the two files that the message lists. ViteHub takes the Definition name from the file path."
162
+ },
163
+ INTERNAL_R0001: {
164
+ ...dynamicError,
165
+ fix: "Set `host` in `vitehub()`, or in the `vitehub` options of `nuxt.config.ts`, to `cloudflare`, `deno`, `netlify`, `node`, or `vercel`. Or remove `host` so that ViteHub finds the host from the environment."
166
+ },
167
+ INTERNAL_R0002: {
168
+ ...dynamicError,
169
+ fix: "Stop using the feature that the message names, or set `host` in `vitehub()` to a host that provides it. For Blob, you can also set `blob: { driver: \"s3\" }` with a remote store."
170
+ },
171
+ INTERNAL_R0004: {
172
+ ...dynamicError,
173
+ fix: "Set a larger `maxResponseBytes` on the HTTP request, such as the `url()` Source options, or ask the server for a smaller response."
174
+ },
175
+ INTERNAL_R0005: {
176
+ ...dynamicError,
177
+ fix: "Set `method` of the HTTP request to `GET`, `HEAD`, or `POST`."
178
+ },
179
+ INTERNAL_R0006: {
180
+ ...dynamicError,
181
+ fix: "Set `timeout` of the HTTP request to a number of milliseconds from 1 to 2147483647, or remove it to use the default."
182
+ },
183
+ INTERNAL_R0007: {
184
+ ...dynamicError,
185
+ fix: "Set `maxResponseBytes` of the HTTP request to a positive integer no greater than the limit that the message names, or remove it to use the default."
186
+ },
187
+ INTERNAL_R0008: {
188
+ ...dynamicError,
189
+ fix: "Make the value that the message names match its schema: the input, query, or body that you send, or the response schema that you declare for the request."
190
+ },
191
+ INTERNAL_R0009: {
192
+ ...dynamicError,
193
+ fix: "Use a Standard Schema whose `validate()` returns `{ value }` or `{ issues }` for the value that the message names."
194
+ },
195
+ INTERNAL_R0010: {
196
+ ...dynamicError,
197
+ fix: "Run the command again. If the error stays, check the Cloudflare API status, because Cloudflare sent a response that ViteHub cannot read."
198
+ },
199
+ INTERNAL_R0011: {
200
+ ...dynamicError,
201
+ fix: "Pass an h3 app, an object with a `fetch(request)` method, or a fetch function as `app`."
202
+ },
203
+ INTERNAL_CONSOLE_KEY_NAME_INVALID: {
204
+ why: ({ name }) => `[vitehub] The Console key name ${JSON.stringify(name)} must be 1 to 64 of A-Z, 0-9, and _.`,
205
+ fix: "Name the Console key with 1 to 64 characters from A-Z, 0-9, and _, such as `CI`. The app reads its public key from `VITEHUB_CONSOLE_KEY_<NAME>`."
206
+ },
207
+ INTERNAL_CONSOLE_PRIVATE_KEY_INVALID: {
208
+ why: "[vitehub] A Console private key is the 32-byte Ed25519 seed as base64url (43 characters). `vitehub secret console-key` makes one.",
209
+ fix: "Run `vitehub secret console-key` and use the 43-character private key that it prints, without spaces or quotes."
210
+ },
211
+ INTERNAL_CONSOLE_PRIVATE_KEY_VARIABLES_MULTIPLE: {
212
+ why: ({ prefix, variables }) => `[vitehub] Set one ${prefix}<NAME> variable. This environment has ${variables}.`,
213
+ fix: "Keep one `VITEHUB_CONSOLE_PRIVATE_KEY_<NAME>` variable in the environment of the command, and unset the others that the message names."
214
+ },
215
+ INTERNAL_CONSOLE_PRIVATE_KEY_VARIABLE_INVALID: {
216
+ why: ({ variable }) => `[vitehub] ${variable} must be the 43-character private key that \`vitehub secret console-key\` prints, and its name 1 to 64 of A-Z, 0-9, and _.`,
217
+ fix: "Set the variable that the message names to the private key that `vitehub secret console-key` prints, and name it `VITEHUB_CONSOLE_PRIVATE_KEY_<NAME>` with A-Z, 0-9, and _ in `<NAME>`."
218
+ },
219
+ INTERNAL_DEV_SERVER_NOT_FOUND: {
220
+ why: ({ command }) => `[vitehub] No dev server of this project is running, and --url is not set, so \`vitehub ${command}\` has no app to call.`,
221
+ fix: "Start the dev server of this project, such as with `pnpm dev`, or pass --url with the app URL, such as --url http://localhost:3000."
222
+ },
223
+ INTERNAL_FORGE_NOT_INSTALLED: {
224
+ why: ({ feature }) => `${feature} needs @vite-hub/forge, and the app did not install it.`,
225
+ fix: "Install Forge in your app with `pnpm add @vite-hub/forge`, then build again."
226
+ },
227
+ INTERNAL_MCP_ARGUMENTS_INVALID: {
228
+ why: ({ detail }) => detail,
229
+ fix: "Pass the prompt or resource the arguments that `prompts/list` or `resources/templates/list` describes for it."
230
+ },
231
+ INTERNAL_MCP_METHOD_FAILED: {
232
+ why: ({ name }) => `${name} failed on the server.`,
233
+ fix: "Read the server log for the error of the MCP prompt or resource that the message names, and fix its handler."
234
+ },
235
+ INTERNAL_MCP_RESOURCE_NOT_FOUND: {
236
+ why: ({ uri }) => `Resource not found: ${uri}. Call resources/list or resources/templates/list for the resources of this server.`,
237
+ fix: "Call `resources/list` or `resources/templates/list`, and read a URI that one of them returns."
238
+ },
239
+ INTERNAL_PRESET_OPTION_UNKNOWN: {
240
+ why: ({ key, label }) => `[vitehub] Unknown ${label} option "${key}".`,
241
+ fix: "Remove the option that the message names from the preset options, or correct its spelling to an option that the preset declares."
242
+ },
243
+ INTERNAL_PRESET_TUPLE_INVALID: {
244
+ why: ({ owner }) => `[vitehub] ${owner} extends tuple requires [preset, options] with an options object.`,
245
+ fix: "Set `extends` to a preset, or to a two-item tuple `[preset, { ...options }]` whose second item is a plain object."
246
+ },
247
+ INTERNAL_SECRET_PURPOSE_MISSING: {
248
+ why: "[vitehub] A derived secret requires a purpose.",
249
+ fix: "Pass a non-empty purpose to `deriveSecret()`, such as `deriveSecret(\"my-module:session\")`."
250
+ },
251
+ INTERNAL_SECRET_TOO_SHORT: {
252
+ why: ({ minimum }) => `[vitehub] VITEHUB_SECRET must be at least ${minimum} characters. Generate one with \`openssl rand -base64 32\`.`,
253
+ fix: "Set `VITEHUB_SECRET` to the output of `openssl rand -base64 32`, which has 44 characters."
254
+ },
255
+ INTERNAL_SQLITE_ARGUMENT_INVALID: {
256
+ why: ({ value }) => value === "undefined" ? "undefined cannot be passed as argument to the database" : "Only finite numbers (not Infinity or NaN) can be passed as arguments",
257
+ fix: "Pass query arguments as finite numbers, strings, booleans, bigints, dates, byte arrays, or null. Replace undefined with null, and check numbers with `Number.isFinite()` before the query."
258
+ },
259
+ INTERNAL_SQLITE_INTEGER_UNSAFE: {
260
+ why: "Received integer which cannot be safely represented as a JavaScript number",
261
+ fix: "Create the client with `intMode: \"bigint\"` or `intMode: \"string\"`, or read the column with `CAST(column AS TEXT)` in the query."
262
+ },
263
+ INTERNAL_VALIBOT_JSON_SCHEMA_TARGET_UNSUPPORTED: {
264
+ why: ({ target }) => `[vitehub] Valibot cannot convert a schema to the ${target} JSON Schema target.`,
265
+ fix: "Ask for the `draft-07`, `draft-2020-12`, or `openapi-3.0` JSON Schema target, or pass one of them as `withValibotJsonSchema(schema, { target })`."
266
+ }
267
+ }
268
+ });
269
+ //#endregion
270
+ export { internalErrorDiagnostics as t };
@@ -0,0 +1,35 @@
1
+ import { ViteHubError } from "@vite-hub/runtime";
2
+ //#region src/errors.ts
3
+ const workflowErrorMessages = {
4
+ OPENWORKFLOW_BACKEND_CLOSE_FAILED: "OpenWorkflow backend cleanup failed.",
5
+ OPENWORKFLOW_RUNTIME_RESET: "OpenWorkflow runtime was reset while it was being acquired.",
6
+ OPENWORKFLOW_WORKER_FAILED: "OpenWorkflow worker failed to start or run.",
7
+ OPENWORKFLOW_WORKER_STOP_FAILED: "OpenWorkflow worker stop failed.",
8
+ VERCEL_WORKFLOW_SDK_LOAD_FAILED: "Vercel Workflow DevKit load failed. Install the optional workflow peer dependency.",
9
+ WORKFLOW_DEFINITION_NOT_FOUND: "Workflow definition was not found.",
10
+ WORKFLOW_DISABLED: "Workflow is disabled.",
11
+ WORKFLOW_NATIVE_ENTRY_INVALID: "Workflow has no transformed native Vercel entry.",
12
+ WORKFLOW_NATIVE_ENTRY_REQUIRED: "Workflow has no native durable entry for Vercel.",
13
+ WORKFLOW_OPERATION_UNSUPPORTED: "Workflow provider operation is unsupported.",
14
+ WORKFLOW_PROVIDER_OPERATION_FAILED: "Workflow provider operation failed.",
15
+ WORKFLOW_RUN_ID_UNSUPPORTED: "Native Vercel workflows assign their own run IDs."
16
+ };
17
+ function createWorkflowError(options) {
18
+ return new ViteHubError(options.code, workflowErrorMessages[options.code], options);
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
+ var NonRetryableError = class extends Error {
25
+ name = "NonRetryableError";
26
+ isRetryable = false;
27
+ fatal = true;
28
+ };
29
+ /** Reads the fields, not the class, so an error from another bundle or realm also matches. */
30
+ function isNonRetryableError(error) {
31
+ if (typeof error !== "object" || error === null) return false;
32
+ return typeof Reflect.get(error, "message") === "string" && (Reflect.get(error, "isRetryable") === false || Reflect.get(error, "name") === "NonRetryableError");
33
+ }
34
+ //#endregion
35
+ export { createWorkflowError as n, isNonRetryableError as r, NonRetryableError as t };