@vite-hub/workflow 0.6.1 → 0.7.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.
- package/README.md +32 -8
- package/dist/{app-DXUHElAz.js → app-Cpa9qCXr.js} +1 -1
- package/dist/{client-CbBg4HlH.js → client-CPxPxsl5.js} +37 -37
- package/dist/cloudflare-concurrency-counter-CDHHiMfn.js +136 -0
- package/dist/{config-CizNRTMi.js → config-CwCwuZqv.js} +1 -1
- package/dist/definition.d.ts +1 -1
- package/dist/definition.js +4 -1
- package/dist/{delay-CtT3442d.js → delay-JrpW40UF.js} +4 -2
- package/dist/durability.d.ts +3 -1
- package/dist/durability.js +7 -1
- package/dist/{error-diagnostics--2cV_ER1.js → error-diagnostics-35AEmfve.js} +25 -5
- package/dist/{error-diagnostics-kKXseq8d.js → error-diagnostics-CsiNo_oI.js} +3 -3
- package/dist/{errors-CJZuvOcx.d.ts → errors-DwKy5MQ8.d.ts} +1 -1
- package/dist/execute-CLmIXnON.js +355 -0
- package/dist/index.d.ts +12 -10
- package/dist/index.js +3 -3
- package/dist/{openworkflow-defaults-DfQWtSRU.js → invariant-Dj2R1eMr.js} +1 -4
- package/dist/openworkflow-BiwPTYEz.js +752 -0
- package/dist/{openworkflow-CdKbUGGa.d.ts → openworkflow-C65AWQSJ.d.ts} +23 -4
- package/dist/openworkflow-defaults-1n0DbLdb.js +4 -0
- package/dist/{operation-definition-CqZkx1Rm.d.ts → operations-Blwi3jQF.d.ts} +1 -0
- package/dist/{operations-BBTmDm2H.js → operations-DyaGK9zW.js} +70 -14
- package/dist/operations.d.ts +3 -59
- package/dist/operations.js +5 -5
- package/dist/results-DBp_bmUP.d.ts +60 -0
- package/dist/runtime/cloudflare-concurrency.d.ts +21 -0
- package/dist/runtime/cloudflare-concurrency.js +21 -0
- package/dist/runtime/cloudflare-runner.d.ts +1 -1
- package/dist/runtime/cloudflare-runner.js +7 -3
- package/dist/runtime/cloudflare-vite.d.ts +1 -1
- package/dist/runtime/cloudflare-vite.js +2 -2
- package/dist/runtime/execute.d.ts +8 -2
- package/dist/runtime/execute.js +1 -278
- package/dist/runtime/openworkflow-worker.d.ts +2 -2
- package/dist/runtime/openworkflow-worker.js +2 -2
- package/dist/runtime/openworkflow.d.ts +2 -2
- package/dist/runtime/openworkflow.js +1 -481
- package/dist/runtime/state.d.ts +1 -1
- package/dist/runtime/state.js +2 -2
- package/dist/runtime/vercel-vite.d.ts +1 -1
- package/dist/runtime/vercel-vite.js +2 -2
- package/dist/{signals-BHQdxoJo.js → signals-CdaxRNjN.js} +1 -1
- package/dist/{types-DvYcvbPG.d.ts → types-CvyOEp0V.d.ts} +33 -4
- package/dist/{vercel-Cw_Z9-j4.js → vercel-ADMH2MK8.js} +5 -3
- package/dist/vite.d.ts +18 -4
- package/dist/vite.js +553 -116
- package/package.json +3 -3
- package/dist/cloudflare-Sgywkm1N.js +0 -57
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ Then install the dependency required by the selected driver:
|
|
|
22
22
|
| Provider | Additional dependency | Durable state |
|
|
23
23
|
| -------------------- | ------------------------------------------------------------------ | ------------------------------------------------------------------------ |
|
|
24
24
|
| Cloudflare Workflows | None in application code | Cloudflare owns run state. Without the binding, only `vite dev` runs inline; a Worker fails with `WORKFLOW_R0036`. |
|
|
25
|
-
| Vercel Workflow | `@vercel/functions
|
|
25
|
+
| Vercel Workflow | `@vercel/functions`, `workflow@5.2.3`, and `@workflow/builders@5.0.6` ([versions](#make-a-vercel-workflow-durable)) | Workflow DevKit runs every discovered Workflow file. Agent turns and `createWorkflow()` run inline. |
|
|
26
26
|
| OpenWorkflow | None. `@vite-hub/workflow` depends on `openworkflow` and `postgres` | Postgres Default Database, else a local SQLite file. |
|
|
27
27
|
|
|
28
28
|
Importing the provider-neutral package root does not load OpenWorkflow types. Worker lifecycle helpers live at `@vite-hub/workflow/openworkflow`.
|
|
@@ -202,7 +202,7 @@ The other runtime helpers are:
|
|
|
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`, 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
|
|
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. With OpenWorkflow, in `vite dev` and in a build, `runs list` also lists the stored runs with their step count, and `runs get <runId>` finds the Workflow of a stored run from its id or idempotency key. `runs clear` removes only the dev history. On other providers outside `vite dev`, `runs list` and `runs clear` fail 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
|
|
|
@@ -222,15 +222,39 @@ 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, generated native entry for numbered steps without an index handler | The generated entry calls Workflow DevKit `sleep()` before the first step. | `running` |
|
|
225
|
+
| Vercel, generated native entry for a single file or 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`,
|
|
227
|
+
| Inline runs (`vite dev`, Agent turns and `createWorkflow()` on Vercel) | 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
|
|
|
231
|
+
## Limit runs at once
|
|
232
|
+
|
|
233
|
+
Set `concurrency` on the Workflow to let at most that number of its runs execute at the same time, on all servers. A Queue `concurrency` only limits starts.
|
|
234
|
+
|
|
235
|
+
```ts
|
|
236
|
+
import { defineWorkflow } from "@vite-hub/workflow";
|
|
237
|
+
|
|
238
|
+
export default defineWorkflow<{ pullRequest: number }>({
|
|
239
|
+
concurrency: 3,
|
|
240
|
+
handler: async ({ payload }) => ({ reviewed: payload.pullRequest }),
|
|
241
|
+
});
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
A run that finds no free place sleeps before its handler and tries again, after 1 second and then after up to 60 seconds. A run that ends without freeing its place loses it at the next try.
|
|
245
|
+
|
|
246
|
+
| Driver | Count kept in |
|
|
247
|
+
| --- | --- |
|
|
248
|
+
| Cloudflare | The `ViteHubWorkflowConcurrency` Durable Object, one per Workflow. The build exports it and binds it as `VITEHUB_WORKFLOW_CONCURRENCY`. A missing binding fails the run with `WORKFLOW_CONCURRENCY_BINDING_MISSING`. |
|
|
249
|
+
| OpenWorkflow | The `vitehub_workflow_slots` table of the OpenWorkflow database. |
|
|
250
|
+
| Inline | The process. |
|
|
251
|
+
| Vercel | Not supported. The build fails with `WORKFLOW_CONCURRENCY_VERCEL_UNSUPPORTED`. |
|
|
252
|
+
|
|
253
|
+
The build reads `concurrency` from the default export of the Workflow file, so set it in the object literal. A value that is not a whole number of 1 or more throws `WORKFLOW_CONCURRENCY_INVALID`.
|
|
254
|
+
|
|
231
255
|
## Make a Vercel workflow durable
|
|
232
256
|
|
|
233
|
-
A
|
|
257
|
+
A Vercel build never runs a discovered Workflow file inline. It generates a Workflow DevKit entry for a single file, which runs the handler as one step, and for a folder of numbered steps without an index file. A folder with an index handler needs a native entry that you write, or the build fails with `WORKFLOW_VERCEL_INDEX_NOT_NATIVE`. Install `@vercel/functions` and the Workflow DevKit packages, keep the same handler, and register the native entry:
|
|
234
258
|
|
|
235
259
|
```sh
|
|
236
260
|
pnpm add --save-exact workflow@5.2.3 @workflow/builders@5.0.6
|
|
@@ -297,7 +321,7 @@ export const retries = { limit: 5, delay: "30 seconds", backoff: "exponential" }
|
|
|
297
321
|
export const timeout = "2 minutes";
|
|
298
322
|
```
|
|
299
323
|
|
|
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).
|
|
324
|
+
Cloudflare gets both in `step.do()`. OpenWorkflow gets `retries` as its `retryPolicy`, with each wait at most 365 days, 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
325
|
|
|
302
326
|
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
327
|
|
|
@@ -323,7 +347,7 @@ export default defineWorkflow<{ email: string, remindAt: string }>({
|
|
|
323
347
|
});
|
|
324
348
|
```
|
|
325
349
|
|
|
326
|
-
The sleep is durable on Cloudflare (`step.sleep` and `step.sleepUntil`, at most 365 days) and OpenWorkflow. Inline runs, in `vite dev` and
|
|
350
|
+
The sleep is durable on Cloudflare (`step.sleep` and `step.sleepUntil`, at most 365 days) and OpenWorkflow. Inline runs, in `vite dev` and for Agent turns and `createWorkflow()` on Vercel, wait with a timer. That wait is not durable: a restart loses the run. A Vercel `native` entry uses Workflow DevKit's `sleep()`.
|
|
327
351
|
|
|
328
352
|
After a sleep, the provider runs `index.ts` again from the start, and completed step files return their stored results. ViteHub names each sleep by call order (`sleep-1`, `sleep-2`), so `index.ts` must call `sleep()` in the same order on each replay. Put each side effect and each value that changes, such as `Date.now()`, in a step file. `getWorkflowRun()` lists a sleep as a step with the name `sleep-1` and the wake time in `sleepUntil` on OpenWorkflow. A sleeping Cloudflare run reports `running` with `metadata.status: "waiting"`.
|
|
329
353
|
|
|
@@ -350,7 +374,7 @@ ViteHub makes the token from the Workflow name, the run id, and the call order (
|
|
|
350
374
|
|
|
351
375
|
## Production checklist
|
|
352
376
|
|
|
353
|
-
- Confirm that the selected provider is durable enough for the work;
|
|
377
|
+
- Confirm that the selected provider is durable enough for the work; Agent turns and `createWorkflow()` on Vercel run inline and are not durable.
|
|
354
378
|
- Make side-effecting steps idempotent so retries do not duplicate work.
|
|
355
379
|
- Keep provider credentials and database URLs in Server Env.
|
|
356
380
|
- Configure durable OpenWorkflow storage and run its migrations before serving traffic.
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { a as getCloudflareEnv, n as resolveWaitUntil } from "./cloudflare-env-DHhzRZOs.js";
|
|
2
|
-
import { t as normalizeWorkflowOptions } from "./config-
|
|
2
|
+
import { t as normalizeWorkflowOptions } from "./config-CwCwuZqv.js";
|
|
3
3
|
import { n as createWorkflowError } from "./errors-CZf7oz4k.js";
|
|
4
|
-
import { t as workflowErrorDiagnostics } from "./error-diagnostics
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { t as workflowErrorDiagnostics } from "./error-diagnostics-35AEmfve.js";
|
|
5
|
+
import { d as encodeNameHex, s as getCloudflareWorkflowBindingName, u as isCloudflareInstanceNotFound } from "./cloudflare-concurrency-counter-CDHHiMfn.js";
|
|
6
|
+
import { a as toCloudflareStartParams, i as resolveWorkflowStartAt } from "./delay-JrpW40UF.js";
|
|
7
7
|
import { t as getWorkflowDevRecorder } from "./dev-recorder-Dltdmlkv.js";
|
|
8
|
-
import { runSerializedWorkflowHandler } from "./
|
|
8
|
+
import { o as runSerializedWorkflowHandler } from "./execute-CLmIXnON.js";
|
|
9
9
|
import { cloudflareSignalEventType } from "./runtime/cloudflare-runner.js";
|
|
10
|
-
import {
|
|
10
|
+
import { a as getOpenWorkflowRun, d as runOpenWorkflow, t as cancelOpenWorkflowRun, u as resumeOpenWorkflowSignal } from "./openworkflow-BiwPTYEz.js";
|
|
11
11
|
import { a as safeWorkflowName, i as runWorkflowProviderOperation, t as toWorkflowRunError } from "./run-error-8p4BtTMv.js";
|
|
12
12
|
import { t as emitWorkflowFailed } from "./run-failed-BcSjSU2t.js";
|
|
13
|
-
import { i as readWorkflowSignalToken, o as resumeInlineWorkflowSignal } from "./signals-
|
|
13
|
+
import { i as readWorkflowSignalToken, o as resumeInlineWorkflowSignal } from "./signals-CdaxRNjN.js";
|
|
14
14
|
import { getInlineWorkflowDefinitions, getWorkflowRunState, getWorkflowRuntimeConfig, getWorkflowRuntimeEvent, getWorkflowRuntimeRegistry, loadWorkflowDefinition, registerInlineWorkflowDefinition, runWithWorkflowRuntimeEvent, setWorkflowRun } from "./runtime/state.js";
|
|
15
|
-
import { a as startVercelWorkflow, n as inspectVercelWorkflowRun, r as resumeVercelWorkflowSignal, t as cancelVercelWorkflow } from "./vercel-
|
|
15
|
+
import { a as startVercelWorkflow, n as inspectVercelWorkflowRun, r as resumeVercelWorkflowSignal, t as cancelVercelWorkflow } from "./vercel-ADMH2MK8.js";
|
|
16
16
|
import { getViteHubErrorShape, isRuntimeDiagnostic, toResultError } from "@vite-hub/runtime";
|
|
17
17
|
import { getViteHubTestMode } from "@vite-hub/runtime/internal/test-mode";
|
|
18
18
|
import { deserializeResponse, isSerializedResponse } from "@vite-hub/runtime/internal/response";
|
|
@@ -134,15 +134,6 @@ function ownStatusError(metadata) {
|
|
|
134
134
|
if (typeof metadata !== "object" || metadata === null || !Object.hasOwn(metadata, "error")) return void 0;
|
|
135
135
|
return Reflect.get(metadata, "error");
|
|
136
136
|
}
|
|
137
|
-
function isCloudflareInstanceNotFound(error) {
|
|
138
|
-
if (typeof error !== "object" || error === null) return false;
|
|
139
|
-
try {
|
|
140
|
-
const message = Reflect.get(error, "message");
|
|
141
|
-
return typeof message === "string" && message.includes("instance.not_found");
|
|
142
|
-
} catch {
|
|
143
|
-
return false;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
137
|
function isCloudflareRejection(error) {
|
|
147
138
|
if (typeof error !== "object" || error === null) return false;
|
|
148
139
|
try {
|
|
@@ -279,20 +270,25 @@ function createCloudflareAdapter(config) {
|
|
|
279
270
|
};
|
|
280
271
|
return adapter;
|
|
281
272
|
}
|
|
282
|
-
const
|
|
283
|
-
function
|
|
273
|
+
const warnedInlineWorkflowNames = /* @__PURE__ */ new Set();
|
|
274
|
+
function warnInlineWorkflow(name, runner) {
|
|
275
|
+
if (warnedInlineWorkflowNames.has(name)) return;
|
|
276
|
+
warnedInlineWorkflowNames.add(name);
|
|
277
|
+
console.warn(`[vitehub:workflow] The Workflow ${JSON.stringify(name)} is not a discovered file, so ${runner} cannot run it. Its runs execute inline in this process and are not durable. Move it to server/workflows/ to make it durable.`);
|
|
278
|
+
}
|
|
279
|
+
function isDiscoveredWorkflow(name) {
|
|
284
280
|
const registry = getWorkflowRuntimeRegistry();
|
|
285
281
|
return Boolean(registry && Object.hasOwn(registry, name));
|
|
286
282
|
}
|
|
287
283
|
function createOpenWorkflowAdapter(config) {
|
|
288
284
|
const inline = inlineAdapter(config);
|
|
289
285
|
return {
|
|
290
|
-
cancel: async ({ event, id, name }) =>
|
|
286
|
+
cancel: async ({ event, id, name }) => isDiscoveredWorkflow(name) ? await cancelOpenWorkflowRun(config, name, id) : await inline.cancel({
|
|
291
287
|
event,
|
|
292
288
|
id,
|
|
293
289
|
name
|
|
294
290
|
}),
|
|
295
|
-
get: async ({ event, id, name }) =>
|
|
291
|
+
get: async ({ event, id, name }) => isDiscoveredWorkflow(name) ? await getOpenWorkflowRun(config, name, id) : await inline.get({
|
|
296
292
|
event,
|
|
297
293
|
id,
|
|
298
294
|
name
|
|
@@ -302,12 +298,9 @@ function createOpenWorkflowAdapter(config) {
|
|
|
302
298
|
}),
|
|
303
299
|
run: async (context) => {
|
|
304
300
|
const { definition, event, name, options, payload, startAt } = context;
|
|
305
|
-
if (
|
|
301
|
+
if (isDiscoveredWorkflow(name)) return await runOpenWorkflow(config, name, payload, definition, options, resolveDispatchObserver(event), startAt);
|
|
306
302
|
if (definition?.internalAgentWorkflow || definition?.internalAgentInvocationRecovery) throw workflowErrorDiagnostics.WORKFLOW_AGENT_NOT_DISCOVERED({ name });
|
|
307
|
-
|
|
308
|
-
warnedInlineOpenWorkflowNames.add(name);
|
|
309
|
-
console.warn(`[vitehub:workflow] The Workflow ${JSON.stringify(name)} is not a discovered file, so OpenWorkflow workers cannot run it. Its runs execute inline in this process and are not durable. Move it to server/workflows/ to make it durable.`);
|
|
310
|
-
}
|
|
303
|
+
warnInlineWorkflow(name, "OpenWorkflow workers");
|
|
311
304
|
return {
|
|
312
305
|
...await inline.run(context),
|
|
313
306
|
metadata: {
|
|
@@ -467,7 +460,16 @@ function createVercelAdapter(config) {
|
|
|
467
460
|
},
|
|
468
461
|
async run(context) {
|
|
469
462
|
const { definition, event, name, payload, startAt } = context;
|
|
470
|
-
|
|
463
|
+
const agentTurn = Boolean(definition?.internalAgentWorkflow || definition?.internalAgentInvocationRecovery);
|
|
464
|
+
const registry = getWorkflowRuntimeRegistry();
|
|
465
|
+
if (!agentTurn && registry && Object.hasOwn(registry, name) && Reflect.get(registry, Symbol.for("vitehub.vercel.nativeWorkflowRegistry")) === true) {
|
|
466
|
+
const native = definition?.native;
|
|
467
|
+
if (typeof native !== "function" || typeof Reflect.get(native, "workflowId") !== "string" || !Reflect.get(native, "workflowId")) throw workflowErrorDiagnostics.WORKFLOW_VERCEL_DISCOVERED_NOT_NATIVE({ name });
|
|
468
|
+
}
|
|
469
|
+
if (!runsNatively(definition)) {
|
|
470
|
+
if (!agentTurn && !isDiscoveredWorkflow(name) && !isDevelopmentServer()) warnInlineWorkflow(name, "Workflow DevKit");
|
|
471
|
+
return await fallback.run(context);
|
|
472
|
+
}
|
|
471
473
|
return await startVercelWorkflow(name, definition, payload, resolveSettlementObserver(event), resolveDispatchObserver(event), startAt);
|
|
472
474
|
}
|
|
473
475
|
};
|
|
@@ -618,10 +620,10 @@ function createWorkflow(nameOrOptions, handlerOrOptions, options) {
|
|
|
618
620
|
...createOptions?.rootStep === void 0 ? {} : { rootStep: createOptions.rootStep }
|
|
619
621
|
});
|
|
620
622
|
return {
|
|
621
|
-
cancel: (id) =>
|
|
623
|
+
cancel: async (id) => await cancelWorkflowRun(name, id),
|
|
622
624
|
name,
|
|
623
625
|
defer: (payload, options = {}) => deferWorkflowStart(name, async () => await startWorkflowRun(name, payload, await resolveWorkflowStartOptions(name, payload, createOptions, options), true)),
|
|
624
|
-
getRun: (id) =>
|
|
626
|
+
getRun: async (id) => await readWorkflowRun(name, id),
|
|
625
627
|
async start(payload, options = {}) {
|
|
626
628
|
const startOptions = await resolveWorkflowStartOptions(name, payload, createOptions, options);
|
|
627
629
|
return await toWorkflowResult(() => startWorkflowRun(name, payload, startOptions));
|
|
@@ -660,11 +662,10 @@ async function startWorkflowRun(name, payload, options, deferred = false) {
|
|
|
660
662
|
startAt
|
|
661
663
|
});
|
|
662
664
|
}
|
|
663
|
-
/**
|
|
664
|
-
* Reads one run and returns `[error, run]`. A provider failure is `error`. A run that the provider does not know has
|
|
665
|
-
* `status: "unknown"`. Config errors throw.
|
|
666
|
-
*/
|
|
667
665
|
async function getWorkflowRun(name, id) {
|
|
666
|
+
return await readWorkflowRun(name, id);
|
|
667
|
+
}
|
|
668
|
+
async function readWorkflowRun(name, id) {
|
|
668
669
|
const config = getActiveWorkflowConfig();
|
|
669
670
|
const test = getViteHubTestMode();
|
|
670
671
|
if (test) return [void 0, getWorkflowTestRun(test, config.driver, name, id)];
|
|
@@ -674,11 +675,10 @@ async function getWorkflowRun(name, id) {
|
|
|
674
675
|
name
|
|
675
676
|
}));
|
|
676
677
|
}
|
|
677
|
-
/**
|
|
678
|
-
* Cancels one run and returns `[error, run]`. A provider failure, or a provider that cannot cancel the run, is
|
|
679
|
-
* `error`. Config errors, for example an unknown Workflow name, throw.
|
|
680
|
-
*/
|
|
681
678
|
async function cancelWorkflow(name, id) {
|
|
679
|
+
return await cancelWorkflowRun(name, id);
|
|
680
|
+
}
|
|
681
|
+
async function cancelWorkflowRun(name, id) {
|
|
682
682
|
const config = getActiveWorkflowConfig();
|
|
683
683
|
const definition = await loadRequiredWorkflowDefinition(name);
|
|
684
684
|
const test = getViteHubTestMode();
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { n as invariantError } from "./invariant-Dj2R1eMr.js";
|
|
2
|
+
import { t as workflowErrorDiagnostics } from "./error-diagnostics-35AEmfve.js";
|
|
3
|
+
// ../internal/src/integrations/hex.ts
|
|
4
|
+
const textEncoder = new TextEncoder();
|
|
5
|
+
new TextDecoder();
|
|
6
|
+
function encodeNameHex(name) {
|
|
7
|
+
return [...textEncoder.encode(name)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
8
|
+
}
|
|
9
|
+
// src/integrations/cloudflare.ts
|
|
10
|
+
const cloudflareWorkflowNameMaxLength = 64;
|
|
11
|
+
function isCloudflareInstanceNotFound(error) {
|
|
12
|
+
if (typeof error !== "object" || error === null) return false;
|
|
13
|
+
try {
|
|
14
|
+
const message = Reflect.get(error, "message");
|
|
15
|
+
return typeof message === "string" && message.includes("instance.not_found");
|
|
16
|
+
} catch {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function shortHash(value) {
|
|
21
|
+
let hash = 14695981039346656037n;
|
|
22
|
+
for (const char of value) {
|
|
23
|
+
hash ^= BigInt(char.codePointAt(0) || 0);
|
|
24
|
+
hash = BigInt.asUintN(64, hash * 1099511628211n);
|
|
25
|
+
}
|
|
26
|
+
return hash.toString(16).padStart(16, "0");
|
|
27
|
+
}
|
|
28
|
+
function legacyShortHash(value) {
|
|
29
|
+
let hash = 2166136261;
|
|
30
|
+
for (const char of value) {
|
|
31
|
+
hash ^= char.codePointAt(0) || 0;
|
|
32
|
+
hash = Math.imul(hash, 16777619);
|
|
33
|
+
}
|
|
34
|
+
return (hash >>> 0).toString(16).padStart(8, "0");
|
|
35
|
+
}
|
|
36
|
+
function workflowClassPrefix(name) {
|
|
37
|
+
return name.split(/[^a-z0-9]+/i).filter(Boolean).map((segment) => `${segment.charAt(0).toUpperCase()}${segment.slice(1)}`).join("") || "Default";
|
|
38
|
+
}
|
|
39
|
+
function getCloudflareWorkflowBindingName(name) {
|
|
40
|
+
return `WORKFLOW_${encodeNameHex(name).toUpperCase()}`;
|
|
41
|
+
}
|
|
42
|
+
function getCloudflareWorkflowName(name) {
|
|
43
|
+
const encoded = encodeNameHex(name);
|
|
44
|
+
const fullName = `workflow--${encoded}`;
|
|
45
|
+
if (fullName.length <= cloudflareWorkflowNameMaxLength) return fullName;
|
|
46
|
+
const hash = shortHash(name);
|
|
47
|
+
const prefixLength = 53 - hash.length;
|
|
48
|
+
return `workflow--${encoded.slice(0, prefixLength)}-${hash}`;
|
|
49
|
+
}
|
|
50
|
+
function getCloudflareWorkflowClassName(name) {
|
|
51
|
+
return `ViteHub${workflowClassPrefix(name)}${shortHash(name)}Workflow`;
|
|
52
|
+
}
|
|
53
|
+
/** The pre-64-bit class export kept for existing Cloudflare Workflow instances. */
|
|
54
|
+
function getLegacyCloudflareWorkflowClassName(name) {
|
|
55
|
+
return `ViteHub${workflowClassPrefix(name)}${legacyShortHash(name)}Workflow`;
|
|
56
|
+
}
|
|
57
|
+
function createCloudflareWorkflowBindings(definitions, options) {
|
|
58
|
+
if (!definitions.length) return;
|
|
59
|
+
const configurable = definitions.filter((definition) => definition.source !== "agent-workflow-recovery");
|
|
60
|
+
if (configurable.length > 1 && options && (options.binding || options.name)) throw workflowErrorDiagnostics.WORKFLOW_R0001({ message: "Cloudflare workflow binding and name overrides are only supported when one workflow is discovered." });
|
|
61
|
+
return definitions.map((definition) => ({
|
|
62
|
+
binding: configurable.length === 1 && configurable[0] === definition && options ? options.binding || getCloudflareWorkflowBindingName(definition.name) : getCloudflareWorkflowBindingName(definition.name),
|
|
63
|
+
class_name: getCloudflareWorkflowClassName(definition.name),
|
|
64
|
+
name: configurable.length === 1 && configurable[0] === definition && options ? options.name || getCloudflareWorkflowName(definition.name) : getCloudflareWorkflowName(definition.name)
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
// src/runtime/cloudflare-concurrency-counter.ts
|
|
68
|
+
/** The Durable Object binding that counts the runs of the Workflows that set `concurrency`. */
|
|
69
|
+
const cloudflareConcurrencyBinding = "VITEHUB_WORKFLOW_CONCURRENCY";
|
|
70
|
+
const cloudflareConcurrencyClassName = "ViteHubWorkflowConcurrency";
|
|
71
|
+
const cloudflareConcurrencyMigrationTag = "vitehub-workflow-concurrency-v1";
|
|
72
|
+
const endedStatuses = /* @__PURE__ */ new Set([
|
|
73
|
+
"complete",
|
|
74
|
+
"errored",
|
|
75
|
+
"terminated"
|
|
76
|
+
]);
|
|
77
|
+
const holdersKey = "holders";
|
|
78
|
+
function isCounterNamespace(value) {
|
|
79
|
+
return typeof value === "object" && value !== null && typeof Reflect.get(value, "get") === "function" && typeof Reflect.get(value, "idFromName") === "function";
|
|
80
|
+
}
|
|
81
|
+
function isWorkflowInstanceBinding(value) {
|
|
82
|
+
return typeof value === "object" && value !== null && typeof Reflect.get(value, "get") === "function";
|
|
83
|
+
}
|
|
84
|
+
async function readHolders(storage) {
|
|
85
|
+
const value = await storage.get(holdersKey);
|
|
86
|
+
return Array.isArray(value) ? value.filter((holder) => typeof holder === "string") : [];
|
|
87
|
+
}
|
|
88
|
+
async function hasEnded(binding, run) {
|
|
89
|
+
try {
|
|
90
|
+
const { status } = await (await binding.get(run)).status();
|
|
91
|
+
return status !== void 0 && endedStatuses.has(status);
|
|
92
|
+
} catch (error) {
|
|
93
|
+
return isCloudflareInstanceNotFound(error);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* The count of one Workflow, kept by one Durable Object. `blockConcurrencyWhile` keeps a second request out while a
|
|
98
|
+
* request reads the instance status of the runs that hold a place, so two runs cannot take the last place. A holder whose
|
|
99
|
+
* instance ended, or that Cloudflare no longer knows (it throws after retention), loses its place.
|
|
100
|
+
*/
|
|
101
|
+
function createCloudflareConcurrencyCounter(state, env) {
|
|
102
|
+
return {
|
|
103
|
+
acquire: async (run, limit, binding) => await state.blockConcurrencyWhile(async () => {
|
|
104
|
+
let holders = await readHolders(state.storage);
|
|
105
|
+
if (holders.includes(run)) return true;
|
|
106
|
+
if (holders.length >= limit) {
|
|
107
|
+
const instances = env[binding];
|
|
108
|
+
if (!isWorkflowInstanceBinding(instances)) throw invariantError(`The Workflow binding ${binding} is missing in the Durable Object that counts its runs.`);
|
|
109
|
+
const ended = await Promise.all(holders.map(async (holder) => await hasEnded(instances, holder)));
|
|
110
|
+
holders = holders.filter((_holder, index) => !ended[index]);
|
|
111
|
+
if (holders.length >= limit) {
|
|
112
|
+
await state.storage.put(holdersKey, holders);
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
await state.storage.put(holdersKey, [...holders, run]);
|
|
117
|
+
return true;
|
|
118
|
+
}),
|
|
119
|
+
release: async (run) => await state.blockConcurrencyWhile(async () => {
|
|
120
|
+
const holders = await readHolders(state.storage);
|
|
121
|
+
if (holders.includes(run)) await state.storage.put(holdersKey, holders.filter((holder) => holder !== run));
|
|
122
|
+
})
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/** The place of the Cloudflare instance `run` in the count of the Workflow `name`. */
|
|
126
|
+
function createCloudflareConcurrencySlots(env, name, run, binding) {
|
|
127
|
+
const namespace = env[cloudflareConcurrencyBinding];
|
|
128
|
+
if (!isCounterNamespace(namespace)) throw workflowErrorDiagnostics.WORKFLOW_CONCURRENCY_BINDING_MISSING({ name });
|
|
129
|
+
if (!run) throw invariantError(`Cloudflare started the Workflow ${JSON.stringify(name)} without an instance id.`);
|
|
130
|
+
const counter = () => namespace.get(namespace.idFromName(name));
|
|
131
|
+
return {
|
|
132
|
+
acquire: async (limit) => await counter().acquire(run, limit, binding),
|
|
133
|
+
release: async () => await counter().release(run)
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
export { createCloudflareConcurrencySlots as a, getCloudflareWorkflowClassName as c, encodeNameHex as d, createCloudflareConcurrencyCounter as i, getLegacyCloudflareWorkflowClassName as l, cloudflareConcurrencyClassName as n, createCloudflareWorkflowBindings as o, cloudflareConcurrencyMigrationTag as r, getCloudflareWorkflowBindingName as s, cloudflareConcurrencyBinding as t, isCloudflareInstanceNotFound as u };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as isRecord } from "./object-CAK6UYR5.js";
|
|
2
|
-
import { t as workflowErrorDiagnostics } from "./error-diagnostics
|
|
2
|
+
import { t as workflowErrorDiagnostics } from "./error-diagnostics-35AEmfve.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) {
|
package/dist/definition.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { h as WorkflowDefinition } from "./types-CvyOEp0V.js";
|
|
2
2
|
/**
|
|
3
3
|
* Defines a Workflow from one object: `defineWorkflow({ handler, ...options })`. The file path is the Workflow name.
|
|
4
4
|
* The handler receives one object, `{ payload, steps, sleep, ...context }`. Pass the payload type as the type argument.
|
package/dist/definition.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { t as isRecord } from "./object-CAK6UYR5.js";
|
|
2
|
-
import { t as workflowErrorDiagnostics } from "./error-diagnostics
|
|
2
|
+
import { t as workflowErrorDiagnostics } from "./error-diagnostics-35AEmfve.js";
|
|
3
3
|
// src/definition.ts
|
|
4
4
|
const workflowDefinitionKeys = /* @__PURE__ */ new Set([
|
|
5
|
+
"concurrency",
|
|
5
6
|
"handler",
|
|
6
7
|
"native",
|
|
7
8
|
"rootStep"
|
|
@@ -27,6 +28,8 @@ function defineWorkflow(definition, ...removed) {
|
|
|
27
28
|
if (unknownKey) throw workflowErrorDiagnostics.WORKFLOW_C0015({ message: `\`defineWorkflow()\` does not support the ${JSON.stringify(unknownKey)} option.` });
|
|
28
29
|
if (typeof definition.handler !== "function") throw workflowErrorDiagnostics.WORKFLOW_C0014({ message: "`defineWorkflow()` requires a workflow handler." });
|
|
29
30
|
if (definition.native !== void 0 && typeof definition.native !== "function") throw workflowErrorDiagnostics.WORKFLOW_C0016({ message: "`defineWorkflow()` native entry must be a workflow handler." });
|
|
31
|
+
const concurrency = definition.concurrency;
|
|
32
|
+
if (concurrency !== void 0 && (typeof concurrency !== "number" || !Number.isSafeInteger(concurrency) || concurrency < 1)) throw workflowErrorDiagnostics.WORKFLOW_CONCURRENCY_INVALID({ value: typeof concurrency === "string" ? JSON.stringify(concurrency) : String(concurrency) });
|
|
30
33
|
return definition;
|
|
31
34
|
}
|
|
32
35
|
export { defineWorkflow };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as workflowErrorDiagnostics } from "./error-diagnostics
|
|
1
|
+
import { t as workflowErrorDiagnostics } from "./error-diagnostics-35AEmfve.js";
|
|
2
2
|
import { parseDuration } from "@vite-hub/runtime";
|
|
3
3
|
// src/runtime/delay.ts
|
|
4
4
|
const maximumTime = 864e13;
|
|
@@ -23,6 +23,8 @@ function resolveWorkflowStartAt(delay, now = Date.now()) {
|
|
|
23
23
|
const workflowStartAtKey = "~vitehubStartAt";
|
|
24
24
|
/** Marks the Vercel native entry that ViteHub generates for a folder Workflow. Only that entry reads the start time. */
|
|
25
25
|
const generatedNativeEntryKey = "~vitehubGenerated";
|
|
26
|
+
const generatedNativeRootStepKey = "~vitehubGeneratedRootStep";
|
|
27
|
+
const vercelNativeRegistryKey = "vitehub.vercel.nativeWorkflowRegistry";
|
|
26
28
|
/** Cloudflare `create()` has no delay, so a delayed run sends its start time next to the payload. */
|
|
27
29
|
function toCloudflareStartParams(payload, startAt) {
|
|
28
30
|
return startAt === void 0 ? payload : {
|
|
@@ -41,4 +43,4 @@ function fromCloudflareStartParams(params) {
|
|
|
41
43
|
startAt
|
|
42
44
|
};
|
|
43
45
|
}
|
|
44
|
-
export {
|
|
46
|
+
export { toCloudflareStartParams as a, resolveWorkflowStartAt as i, generatedNativeEntryKey as n, vercelNativeRegistryKey as o, generatedNativeRootStepKey as r, workflowStartAtKey as s, fromCloudflareStartParams as t };
|
package/dist/durability.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { z as WorkflowRuntimeConfigValue } from "./types-CvyOEp0V.js";
|
|
2
2
|
import { Durability, DurabilityContext } from "@vite-hub/runtime/durability";
|
|
3
3
|
/** What the build passes to `workflowDurability()`. The storage values may name runtime environment variables. */
|
|
4
4
|
export interface WorkflowDurabilityInput {
|
|
@@ -6,6 +6,8 @@ export interface WorkflowDurabilityInput {
|
|
|
6
6
|
defaultDatabase?: boolean;
|
|
7
7
|
postgresUrl?: WorkflowRuntimeConfigValue;
|
|
8
8
|
driver: string;
|
|
9
|
+
/** The build makes a Workflow DevKit entry for each discovered Workflow file. Only a Vercel build does. */
|
|
10
|
+
native?: boolean;
|
|
9
11
|
sqlitePath?: WorkflowRuntimeConfigValue;
|
|
10
12
|
}
|
|
11
13
|
/**
|
package/dist/durability.js
CHANGED
|
@@ -32,12 +32,18 @@ function workflowDurability(input, context) {
|
|
|
32
32
|
scope: "shared",
|
|
33
33
|
reason: "Cloudflare Workflows store each run."
|
|
34
34
|
}];
|
|
35
|
+
if (input.driver === "vercel" && input.native) return [{
|
|
36
|
+
primitive: "workflow",
|
|
37
|
+
store: "vercel",
|
|
38
|
+
scope: "shared",
|
|
39
|
+
reason: "Vercel Workflow DevKit stores each run of a discovered Workflow file."
|
|
40
|
+
}];
|
|
35
41
|
if (input.driver !== "openworkflow") return [{
|
|
36
42
|
primitive: "workflow",
|
|
37
43
|
store: "inline",
|
|
38
44
|
scope: "process",
|
|
39
45
|
reason: "Runs execute in the request process. A restart loses them.",
|
|
40
|
-
fix: "
|
|
46
|
+
fix: "The Vercel driver runs Workflows durably only in a Vercel build. Deploy to Vercel, or set `workflow: { driver: \"openworkflow\" }` with a Postgres URL to run them on this server."
|
|
41
47
|
}];
|
|
42
48
|
const storage = resolveOpenWorkflowStorage({
|
|
43
49
|
postgresUrl: resolveDurabilityValue(input.postgresUrl, env),
|
|
@@ -48,16 +48,16 @@ const workflowErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
48
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
49
|
},
|
|
50
50
|
WORKFLOW_RUNS_UNAVAILABLE: {
|
|
51
|
-
why: "This runtime keeps no Workflow run history.
|
|
52
|
-
fix: "Run the app with `vite dev
|
|
51
|
+
why: "This runtime keeps no Workflow run history that ViteHub can read. OpenWorkflow stores its runs, and `vite dev` records inline runs.",
|
|
52
|
+
fix: "Run the app with its dev server (`nuxt dev` or `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
58
|
WORKFLOW_RUN_UNKNOWN: {
|
|
59
|
-
why: ({ runId }) => `
|
|
60
|
-
fix: "
|
|
59
|
+
why: ({ operation, runId, stored }) => stored ? `No run has the id ${runId}. OpenWorkflow storage, the inline runs that \`vite dev\` recorded, and the runs that this runtime started with \`workflow.start\` do not have it.` : `ViteHub needs the Workflow name to ${operation === "get" ? "read" : "cancel"} run ${runId}. Without the name, it finds only ${operation === "get" ? "the inline runs that `vite dev` recorded and " : ""}the runs that this runtime started with \`workflow.start\`.`,
|
|
60
|
+
fix: "Check the run id. On OpenWorkflow, check that the app uses the database that stores the run. On other providers, pass the name of the Workflow with `--workflow <name>`."
|
|
61
61
|
},
|
|
62
62
|
WORKFLOW_C0001: {
|
|
63
63
|
...dynamicError,
|
|
@@ -117,7 +117,7 @@ const workflowErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
117
117
|
},
|
|
118
118
|
WORKFLOW_C0015: {
|
|
119
119
|
...dynamicError,
|
|
120
|
-
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."
|
|
120
|
+
fix: "Pass one object to `defineWorkflow()`, such as `defineWorkflow({ handler, native })`, with only `concurrency`, `handler`, `native`, and `rootStep`. The file path is the Workflow name, so do not pass a name."
|
|
121
121
|
},
|
|
122
122
|
WORKFLOW_C0016: {
|
|
123
123
|
...dynamicError,
|
|
@@ -135,6 +135,18 @@ const workflowErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
135
135
|
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.`,
|
|
136
136
|
fix: "Build the id from allowed characters only, for example `checkout-${orderId}` instead of `checkout:${orderId}`. Hash a long or free-form value first."
|
|
137
137
|
},
|
|
138
|
+
WORKFLOW_CONCURRENCY_BINDING_MISSING: {
|
|
139
|
+
why: ({ name }) => `[vitehub] The Workflow ${JSON.stringify(name)} sets \`concurrency\`, but the Worker has no \`VITEHUB_WORKFLOW_CONCURRENCY\` Durable Object binding to count its runs. The build adds the binding when it reads \`concurrency\` as a number in the \`defineWorkflow()\` call.`,
|
|
140
|
+
fix: "Write `concurrency` as a number literal in the object that the Workflow file passes to `defineWorkflow()`, such as `defineWorkflow({ concurrency: 3, handler })`, and build again."
|
|
141
|
+
},
|
|
142
|
+
WORKFLOW_CONCURRENCY_INVALID: {
|
|
143
|
+
why: ({ value }) => `[vitehub] \`defineWorkflow()\` received \`concurrency: ${value}\`. It must be a whole number of 1 or more.`,
|
|
144
|
+
fix: "Set `concurrency` to the most runs that can run at the same time, such as `concurrency: 3`, or remove it."
|
|
145
|
+
},
|
|
146
|
+
WORKFLOW_CONCURRENCY_VERCEL_UNSUPPORTED: {
|
|
147
|
+
why: ({ name }) => `[vitehub] The Workflow ${JSON.stringify(name)} sets \`concurrency\`. Vercel Workflow has no store that counts the runs of a Workflow on all instances, so ViteHub cannot keep the limit on Vercel.`,
|
|
148
|
+
fix: "Run the Workflow on Cloudflare or OpenWorkflow to keep the limit. On Vercel, remove `concurrency` and limit the work inside the steps, for example with a Queue consumer that starts fewer runs."
|
|
149
|
+
},
|
|
138
150
|
WORKFLOW_OPENWORKFLOW_DATABASE_URL_IGNORED: {
|
|
139
151
|
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.",
|
|
140
152
|
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."
|
|
@@ -328,6 +340,14 @@ const workflowErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
328
340
|
WORKFLOW_STEP_TIMEOUT: {
|
|
329
341
|
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.`,
|
|
330
342
|
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."
|
|
343
|
+
},
|
|
344
|
+
WORKFLOW_VERCEL_DISCOVERED_NOT_NATIVE: {
|
|
345
|
+
why: ({ name }) => `[vitehub] The discovered Workflow ${JSON.stringify(name)} has no runnable Workflow DevKit entry. ViteHub does not run discovered Workflows inline on Vercel.`,
|
|
346
|
+
fix: "Default-export `defineWorkflow({ handler })` from a single file, use numbered step files without an index handler, or provide a `native` entry with a Workflow DevKit `use workflow` directive."
|
|
347
|
+
},
|
|
348
|
+
WORKFLOW_VERCEL_INDEX_NOT_NATIVE: {
|
|
349
|
+
why: ({ file, name }) => `[vitehub] The Workflow ${JSON.stringify(name)} has the index handler ${JSON.stringify(file)} and no \`native\` entry. On Vercel, ViteHub cannot make a durable run from an index handler, and an inline run is lost when the function stops.`,
|
|
350
|
+
fix: "Remove the index file and keep the numbered step files, such as `01.create-user.ts`. ViteHub then generates a Workflow DevKit entry that runs the steps in order. If the Workflow needs code between the steps, keep the index file and add a `native` entry that you write with Workflow DevKit."
|
|
331
351
|
}
|
|
332
352
|
}
|
|
333
353
|
});
|
|
@@ -29,7 +29,7 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
29
29
|
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
30
30
|
},
|
|
31
31
|
INTERNAL_R0024: {
|
|
32
|
-
fix: "Start the dev server
|
|
32
|
+
fix: "Start the dev server (`nuxt dev` or `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
33
|
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
34
34
|
},
|
|
35
35
|
INTERNAL_R0023: {
|
|
@@ -145,7 +145,7 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
145
145
|
fix: "Give a switch column `format: \"switch\"` and `switch: { operation, input }` with a registered operation name, or remove both."
|
|
146
146
|
},
|
|
147
147
|
INTERNAL_R0025: {
|
|
148
|
-
fix: "Start `vite dev` in the project that you run the command from, or pass `--url` of that server.",
|
|
148
|
+
fix: "Start the dev server (`nuxt dev` or `vite dev`) in the project that you run the command from, or pass `--url` of that server.",
|
|
149
149
|
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
150
150
|
},
|
|
151
151
|
INTERNAL_R0026: {
|
|
@@ -166,7 +166,7 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
166
166
|
},
|
|
167
167
|
INTERNAL_R0002: {
|
|
168
168
|
...dynamicError,
|
|
169
|
-
fix:
|
|
169
|
+
fix: ({ fix }) => fix ?? "Build for a host that provides this capability, or set the option named in the message to `false`."
|
|
170
170
|
},
|
|
171
171
|
INTERNAL_R0004: {
|
|
172
172
|
...dynamicError,
|
|
@@ -14,7 +14,7 @@ declare const workflowErrorMessages: {
|
|
|
14
14
|
readonly WORKFLOW_RUN_ID_UNSUPPORTED: "Native Vercel workflows assign their own run IDs.";
|
|
15
15
|
};
|
|
16
16
|
declare const workflowProviderNames: readonly ["cloudflare", "openworkflow", "vercel"];
|
|
17
|
-
declare const workflowOperationNames: readonly ["cancel", "cancellation", "connect", "create", "delay", "get", "get-run", "import", "list-steps", "resume-signal", "run", "signals", "start", "status"];
|
|
17
|
+
declare const workflowOperationNames: readonly ["cancel", "cancellation", "connect", "create", "delay", "get", "get-run", "import", "list-runs", "list-steps", "resume-signal", "run", "signals", "start", "status"];
|
|
18
18
|
type WorkflowErrorCode = keyof typeof workflowErrorMessages;
|
|
19
19
|
type WorkflowOperationName = typeof workflowOperationNames[number];
|
|
20
20
|
type WorkflowProviderName = typeof workflowProviderNames[number];
|