@vite-hub/workflow 0.3.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +79 -44
- package/dist/{app-CmMq8l4t.js → app-2Y7sBAG6.js} +1 -1
- package/dist/{client-CU5rELC0.js → client-CgBcDlGn.js} +155 -80
- package/dist/{cloudflare-BfFnNWB0.js → cloudflare-Datj_znU.js} +1 -1
- package/dist/{config-DCvRDlxA.js → config-z1651xc2.js} +1 -1
- package/dist/definition.d.ts +10 -11
- package/dist/definition.js +24 -22
- package/dist/{delay--ESDybVT.js → delay-CHN4tv3i.js} +6 -42
- package/dist/durability.d.ts +1 -1
- package/dist/{error-diagnostics-DSkCJC_L.js → error-diagnostics-C0KyI408.js} +10 -2
- package/dist/{error-diagnostics-8YNJ37rP.js → error-diagnostics-DMeaFmQD.js} +68 -19
- package/dist/{errors-DCqRnZpN.js → errors-BNxEeeCO.js} +0 -4
- package/dist/{errors-DVwFb6Fd.d.ts → errors-D-fNDVg0.d.ts} +12 -6
- package/dist/index.d.ts +32 -11
- package/dist/index.js +13 -6
- package/dist/{openworkflow-TEaNk0LV.d.ts → openworkflow-BoaENgh9.d.ts} +8 -7
- package/dist/{operation-definition-8gOe-ubD.d.ts → operation-definition-CI2PJGqu.d.ts} +13 -2
- package/dist/{operations-B0L8kV5s.js → operations-CYntpf-T.js} +34 -41
- package/dist/operations.d.ts +5 -8
- package/dist/operations.js +27 -32
- package/dist/{out-fRNaVslw.js → out-DxLKolA0.js} +1 -1
- package/dist/{rolldown-runtime-CMFfr-1z.js → rolldown-runtime-B4iAMlE-.js} +10 -1
- package/dist/{run-error-DBWqiJHH.js → run-error-Ctn50EYz.js} +1 -2
- package/dist/run-failed-gVGo1BaF.js +18 -0
- package/dist/runtime/cloudflare-runner.d.ts +12 -2
- package/dist/runtime/cloudflare-runner.js +28 -9
- package/dist/runtime/cloudflare-vite.d.ts +1 -1
- package/dist/runtime/cloudflare-vite.js +2 -2
- package/dist/runtime/dev-runs.js +1 -0
- package/dist/runtime/execute.d.ts +25 -4
- package/dist/runtime/execute.js +168 -43
- package/dist/runtime/openworkflow-worker.d.ts +2 -2
- package/dist/runtime/openworkflow-worker.js +4 -9
- package/dist/runtime/openworkflow.d.ts +2 -2
- package/dist/runtime/openworkflow.js +60 -49
- package/dist/runtime/state.d.ts +1 -1
- package/dist/runtime/state.js +4 -6
- package/dist/runtime/vercel-vite.d.ts +1 -1
- package/dist/runtime/vercel-vite.js +2 -2
- package/dist/signals-C1iolifd.js +80 -0
- package/dist/{types-CnKVDnEp.d.ts → types-BWPHeugk.d.ts} +99 -28
- package/dist/{vercel-BZU_O6ay.js → vercel-BIkBFrQQ.js} +6 -14
- package/dist/vite.d.ts +27 -16
- package/dist/vite.js +3404 -961
- package/package.json +4 -4
|
@@ -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: {
|
|
@@ -170,7 +170,7 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
170
170
|
},
|
|
171
171
|
INTERNAL_R0004: {
|
|
172
172
|
...dynamicError,
|
|
173
|
-
fix: "Set a larger `maxResponseBytes` on the HTTP request, such as the `
|
|
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
174
|
},
|
|
175
175
|
INTERNAL_R0005: {
|
|
176
176
|
...dynamicError,
|
|
@@ -216,6 +216,10 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
216
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
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
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
|
+
},
|
|
219
223
|
INTERNAL_FORGE_NOT_INSTALLED: {
|
|
220
224
|
why: ({ feature }) => `${feature} needs @vite-hub/forge, and the app did not install it.`,
|
|
221
225
|
fix: "Install Forge in your app with `pnpm add @vite-hub/forge`, then build again."
|
|
@@ -240,6 +244,10 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
240
244
|
why: ({ owner }) => `[vitehub] ${owner} extends tuple requires [preset, options] with an options object.`,
|
|
241
245
|
fix: "Set `extends` to a preset, or to a two-item tuple `[preset, { ...options }]` whose second item is a plain object."
|
|
242
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
|
+
},
|
|
243
251
|
INTERNAL_SECRET_PURPOSE_MISSING: {
|
|
244
252
|
why: "[vitehub] A derived secret requires a purpose.",
|
|
245
253
|
fix: "Pass a non-empty purpose to `deriveSecret()`, such as `deriveSecret(\"my-module:session\")`."
|
|
@@ -8,6 +8,21 @@ const workflowErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
8
8
|
why: ({ name }) => `[vitehub] The Agent Workflow ${JSON.stringify(name)} is not a discovered Agent, so OpenWorkflow workers cannot run its turns.`,
|
|
9
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
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
|
+
},
|
|
11
26
|
WORKFLOW_DEFINITION_NOT_FOUND: {
|
|
12
27
|
why: ({ available, workflow }) => workflow === void 0 ? "Workflow definition was not found." : `Unknown Workflow: ${workflow}.${available ?? ""}`,
|
|
13
28
|
fix: "Pass the name of a Workflow Definition, the file name in `server/workflows/` without the extension."
|
|
@@ -22,7 +37,11 @@ const workflowErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
22
37
|
},
|
|
23
38
|
WORKFLOW_OPERATION_UNSUPPORTED: {
|
|
24
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}`,
|
|
25
|
-
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."
|
|
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
|
+
})
|
|
26
45
|
},
|
|
27
46
|
WORKFLOW_REGISTRY_MISSING: {
|
|
28
47
|
why: ({ workflow }) => `Unknown Workflow: ${workflow}. The runtime has no Workflow registry.`,
|
|
@@ -30,16 +49,12 @@ const workflowErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
30
49
|
},
|
|
31
50
|
WORKFLOW_RUNS_UNAVAILABLE: {
|
|
32
51
|
why: "This runtime keeps no Workflow run history. Only `vite dev` records runs.",
|
|
33
|
-
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."
|
|
34
53
|
},
|
|
35
54
|
WORKFLOW_RUN_AMBIGUOUS: {
|
|
36
55
|
why: ({ id, workflows }) => `Runs of ${workflows} have the id ${id}.`,
|
|
37
56
|
fix: "Pass the name of the Workflow with `--workflow <name>`."
|
|
38
57
|
},
|
|
39
|
-
WORKFLOW_RUN_NOT_FOUND: {
|
|
40
|
-
why: ({ id }) => `No recorded run has the id ${id}.`,
|
|
41
|
-
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."
|
|
42
|
-
},
|
|
43
58
|
WORKFLOW_RUN_UNKNOWN: {
|
|
44
59
|
why: ({ runId }) => `Run ${runId} was not started by \`workflow.start\` in this runtime.`,
|
|
45
60
|
fix: "Pass the name of the Workflow with `--workflow <name>`."
|
|
@@ -98,28 +113,20 @@ const workflowErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
98
113
|
},
|
|
99
114
|
WORKFLOW_C0014: {
|
|
100
115
|
...dynamicError,
|
|
101
|
-
fix: "
|
|
116
|
+
fix: "Set `handler` to a function in the object that you pass to `defineWorkflow()`, such as `defineWorkflow({ handler: async ({ payload, steps }) => { ... } })`."
|
|
102
117
|
},
|
|
103
118
|
WORKFLOW_C0015: {
|
|
104
119
|
...dynamicError,
|
|
105
|
-
fix: "Pass
|
|
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."
|
|
106
121
|
},
|
|
107
122
|
WORKFLOW_C0016: {
|
|
108
123
|
...dynamicError,
|
|
109
|
-
fix: "Set `native` in the `defineWorkflow()`
|
|
124
|
+
fix: "Set `native` in the object that you pass to `defineWorkflow()` to a function, or remove it."
|
|
110
125
|
},
|
|
111
126
|
WORKFLOW_C0017: {
|
|
112
127
|
...dynamicError,
|
|
113
128
|
fix: "Remove `workflow.database`, and set `workflow.sqlite.path` or `workflow.postgres.url`."
|
|
114
129
|
},
|
|
115
|
-
WORKFLOW_C0018: {
|
|
116
|
-
...dynamicError,
|
|
117
|
-
fix: "Pass the Workflow name as the first argument of `defineWorkflow()`, such as `defineWorkflow(\"onboard-user\", handler)`."
|
|
118
|
-
},
|
|
119
|
-
WORKFLOW_C0019: {
|
|
120
|
-
...dynamicError,
|
|
121
|
-
fix: "Pass the name that the message gives to `defineWorkflow()`, or rename the Workflow file or folder to the name that the definition uses."
|
|
122
|
-
},
|
|
123
130
|
WORKFLOW_C0020: {
|
|
124
131
|
...dynamicError,
|
|
125
132
|
fix: "Set `workflow: { driver: \"openworkflow\", sqlite: { path: \".vitehub/data/workflow.sqlite\" } }` or `workflow.postgres.url`, and start the worker with `startOpenWorkflowWorker()`."
|
|
@@ -144,6 +151,10 @@ const workflowErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
144
151
|
why: ({ seconds }) => `Another server held the OpenWorkflow schema setup lock for ${seconds} seconds. This server did not start the schema setup.`,
|
|
145
152
|
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."
|
|
146
153
|
},
|
|
154
|
+
WORKFLOW_PAYLOAD_JSON_INVALID: {
|
|
155
|
+
why: "[vitehub] The request has the `application/json` content type, but its body is not valid JSON.",
|
|
156
|
+
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."
|
|
157
|
+
},
|
|
147
158
|
WORKFLOW_R0001: {
|
|
148
159
|
...dynamicError,
|
|
149
160
|
fix: "Remove `workflow.binding` and `workflow.name`, which apply only to an app with one Workflow, or keep one Workflow under `server/workflows/`."
|
|
@@ -268,17 +279,55 @@ const workflowErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
268
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.`,
|
|
269
280
|
fix: ({ value }) => `Set \`workflow: { driver: ${value} }\`, or run \`npx @vite-hub/codemods driver-key\` to rename it in every config file.`
|
|
270
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
|
+
},
|
|
271
286
|
WORKFLOW_ROOT_STEP_SLEEP: {
|
|
272
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.`,
|
|
273
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."
|
|
274
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
|
+
},
|
|
275
308
|
WORKFLOW_SLEEP_DURATION_INVALID: {
|
|
276
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\`.`,
|
|
277
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))`."
|
|
278
311
|
},
|
|
279
312
|
WORKFLOW_START_DELAY_INVALID: {
|
|
280
|
-
why: ({ delay }) => `[vitehub] \`startWorkflow()\` does not accept the delay ${JSON.stringify(delay)}. A delay is a
|
|
281
|
-
fix: "Pass `{ delay:
|
|
313
|
+
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.`,
|
|
314
|
+
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`."
|
|
315
|
+
},
|
|
316
|
+
WORKFLOW_STEP_OPTIONS_INVALID: {
|
|
317
|
+
why: ({ option, step, value }) => `[vitehub] The Workflow step ${JSON.stringify(step)} sets \`${option}\` to ${value}. A step takes \`retries: { limit, delay, backoff }\` and \`timeout\`.`,
|
|
318
|
+
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."
|
|
319
|
+
},
|
|
320
|
+
WORKFLOW_STEP_OPTIONS_NOT_STATIC: {
|
|
321
|
+
why: ({ file, option }) => `[vitehub] The Workflow step file ${JSON.stringify(file)} exports \`${option}\`, and the build cannot read its value without running the file.`,
|
|
322
|
+
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."
|
|
323
|
+
},
|
|
324
|
+
WORKFLOW_STEP_RETRY_DELAY_UNSUPPORTED: {
|
|
325
|
+
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.`,
|
|
326
|
+
fix: "Remove `delay` and `backoff` from `retries`, and keep `limit`. To wait longer between attempts, deploy the Workflow on Cloudflare or OpenWorkflow."
|
|
327
|
+
},
|
|
328
|
+
WORKFLOW_STEP_TIMEOUT: {
|
|
329
|
+
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
|
+
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."
|
|
282
331
|
}
|
|
283
332
|
}
|
|
284
333
|
});
|
|
@@ -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;
|
|
@@ -32,10 +32,20 @@ type WorkflowOperationDetails = {
|
|
|
32
32
|
};
|
|
33
33
|
/** `rejected`: the provider answered and refused the call. `unknown`: the call can have reached the provider. */
|
|
34
34
|
type WorkflowProviderAcknowledgement = "rejected" | "unknown";
|
|
35
|
-
|
|
35
|
+
/** What `WORKFLOW_PROVIDER_OPERATION_FAILED` keeps in `error.data` when a Workflow call returns it. */
|
|
36
|
+
type WorkflowProviderFailure = {
|
|
37
|
+
/** `rejected`: the provider answered and refused the call. `unknown`: the call can have reached the provider. */
|
|
36
38
|
acknowledgement?: WorkflowProviderAcknowledgement;
|
|
39
|
+
operation: string;
|
|
40
|
+
provider: string;
|
|
37
41
|
/** The provider error name and the first line of its message, without URLs, file paths, or credentials. */
|
|
38
42
|
reason?: string;
|
|
43
|
+
/** The HTTP status of the provider, when it sent one. */
|
|
44
|
+
status?: number;
|
|
45
|
+
};
|
|
46
|
+
type WorkflowProviderOperationDetails = WorkflowOperationDetails & {
|
|
47
|
+
acknowledgement?: WorkflowProviderAcknowledgement;
|
|
48
|
+
reason?: string;
|
|
39
49
|
status?: number;
|
|
40
50
|
};
|
|
41
51
|
type WorkflowErrorDetails<TCode extends WorkflowErrorCode = WorkflowErrorCode> = TCode extends "OPENWORKFLOW_BACKEND_CLOSE_FAILED" | "OPENWORKFLOW_RUNTIME_RESET" | "OPENWORKFLOW_WORKER_FAILED" | "OPENWORKFLOW_WORKER_STOP_FAILED" ? {
|
|
@@ -43,14 +53,10 @@ type WorkflowErrorDetails<TCode extends WorkflowErrorCode = WorkflowErrorCode> =
|
|
|
43
53
|
} : TCode extends "VERCEL_WORKFLOW_SDK_LOAD_FAILED" ? {
|
|
44
54
|
provider: "vercel";
|
|
45
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;
|
|
46
|
-
/**
|
|
47
|
-
* Throw it from a step or a handler to fail the run at once, with no more attempts, on every provider. Cloudflare reads
|
|
48
|
-
* `isRetryable`, Workflow DevKit reads `fatal`, and ViteHub stops OpenWorkflow retries itself.
|
|
49
|
-
*/
|
|
50
56
|
declare class NonRetryableError extends Error {
|
|
51
57
|
override name: string;
|
|
52
58
|
readonly isRetryable = false;
|
|
53
59
|
readonly fatal = true;
|
|
54
60
|
}
|
|
55
61
|
//#endregion
|
|
56
|
-
export {
|
|
62
|
+
export { WorkflowProviderFailure as a, WorkflowOperationName as i, WorkflowErrorCode as n, WorkflowProviderName as o, WorkflowErrorDetails as r, NonRetryableError as t };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { C as
|
|
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
|
|
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
|
+
import { Result } from "@vite-hub/runtime";
|
|
4
5
|
//#region src/integrations/cloudflare.d.ts
|
|
5
6
|
export declare function getCloudflareWorkflowBindingName(name: string): string;
|
|
6
7
|
//#endregion
|
|
@@ -16,17 +17,36 @@ export declare function createWorkflow<TPayload = unknown>(name: string, options
|
|
|
16
17
|
handler?: never;
|
|
17
18
|
}): WorkflowHandle<TPayload, unknown>;
|
|
18
19
|
export declare function createWorkflow<TPayload = unknown, TResult = unknown>(name: string, handler: WorkflowHandler<TPayload, TResult>, options?: WorkflowCreateOptions<TPayload, TResult>): WorkflowHandle<TPayload, TResult>;
|
|
19
|
-
/**
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Starts one durable run of a Workflow Definition and returns `[error, run]`. `run` has the id and the status.
|
|
22
|
+
* The name and the payload type come from `WorkflowRegistry`, which ViteHub writes to `.vitehub/workflow.d.ts`.
|
|
23
|
+
* A provider failure, an unsupported option, or an invalid `delay` is `error`. Config errors, for example an unknown
|
|
24
|
+
* Workflow name, throw.
|
|
25
|
+
*/
|
|
26
|
+
export declare function startWorkflow<TArgs extends WorkflowStartCall>(...args: TArgs): Promise<Result<WorkflowRun<WorkflowPayload<TArgs[0]>, unknown>, WorkflowResultErrorCode>>;
|
|
27
|
+
type WorkflowStartCall = { [TName in WorkflowName]: [name: TName, ...WorkflowStartArguments<WorkflowPayload<TName>>]; }[WorkflowName];
|
|
28
|
+
/**
|
|
29
|
+
* Reads one run and returns `[error, run]`. A provider failure is `error`. A run that the provider does not know has
|
|
30
|
+
* `status: "unknown"`. Config errors throw.
|
|
31
|
+
*/
|
|
32
|
+
export declare function getWorkflowRun(name: string, id: string): Promise<Result<WorkflowRun<unknown, unknown>, WorkflowResultErrorCode>>;
|
|
33
|
+
/**
|
|
34
|
+
* Cancels one run and returns `[error, run]`. A provider failure, or a provider that cannot cancel the run, is
|
|
35
|
+
* `error`. Config errors, for example an unknown Workflow name, throw.
|
|
36
|
+
*/
|
|
37
|
+
export declare function cancelWorkflow(name: string, id: string): Promise<Result<WorkflowRun<unknown, unknown>, WorkflowResultErrorCode>>;
|
|
38
|
+
/**
|
|
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.
|
|
43
|
+
*/
|
|
44
|
+
export declare function resumeWorkflow<TPayload = unknown>(token: string, payload: TPayload): Promise<Result<WorkflowSignalResult, WorkflowResultErrorCode>>;
|
|
25
45
|
/**
|
|
26
46
|
* Starts a run after the response, through `waitUntil`. It returns nothing: a failure goes to the log.
|
|
27
47
|
* Call `startWorkflow()` when the caller needs the run ID or the start error.
|
|
28
48
|
*/
|
|
29
|
-
export declare function deferWorkflow
|
|
49
|
+
export declare function deferWorkflow(...[name, payload, options]: WorkflowStartCall): void;
|
|
30
50
|
//#endregion
|
|
31
51
|
//#region src/runtime/payload.d.ts
|
|
32
52
|
interface PayloadSchema<T> {
|
|
@@ -40,8 +60,9 @@ interface ParsePayloadSchema<T> {
|
|
|
40
60
|
parse: (payload: unknown) => T;
|
|
41
61
|
}
|
|
42
62
|
type PayloadValidator<T> = PayloadSchema<T> | ParsePayloadSchema<T> | ((payload: unknown) => T | Promise<T>);
|
|
43
|
-
|
|
63
|
+
/** Reads a JSON body as parsed JSON and any other body as text. The value is not checked: pass it to `validatePayload()`. */
|
|
64
|
+
export declare function readRequestPayload(request: Request): Promise<unknown>;
|
|
44
65
|
export declare function validatePayload<T>(payload: unknown, schema: PayloadValidator<T>): Promise<T>;
|
|
45
66
|
export declare function readValidatedPayload<T>(request: Request, schema: PayloadValidator<T>): Promise<T>;
|
|
46
67
|
//#endregion
|
|
47
|
-
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 WorkflowOperationName, type WorkflowOptions, type WorkflowProviderContext, type WorkflowProviderName, type WorkflowProviderStep, type WorkflowRun, type WorkflowRunError, type WorkflowRunStatus, type WorkflowRunStep, type WorkflowSharedOptions, type WorkflowSignalResult, type WorkflowStartDelay, type WorkflowStartOptions, type WorkflowStep, type WorkflowStepFunction, type WorkflowStepOptions, type WorkflowStepRegistry, 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,12 +1,19 @@
|
|
|
1
|
-
import { t as workflowErrorDiagnostics } from "./error-diagnostics-
|
|
1
|
+
import { t as workflowErrorDiagnostics } from "./error-diagnostics-DMeaFmQD.js";
|
|
2
2
|
import { defineWorkflow } from "./definition.js";
|
|
3
|
-
import { t as NonRetryableError } from "./errors-
|
|
4
|
-
import { n as getCloudflareWorkflowBindingName } from "./cloudflare-
|
|
5
|
-
import { a as resumeWorkflow, i as getWorkflowRun, n as createWorkflow, o as startWorkflow, r as deferWorkflow, t as cancelWorkflow } from "./client-
|
|
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
|
+
/** Reads a JSON body as parsed JSON and any other body as text. The value is not checked: pass it to `validatePayload()`. */
|
|
7
8
|
async function readRequestPayload(request) {
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
const contentType = request.headers.get("content-type")?.split(";", 1)[0]?.trim().toLowerCase();
|
|
10
|
+
const text = await request.text();
|
|
11
|
+
if (contentType !== "application/json") return text;
|
|
12
|
+
try {
|
|
13
|
+
return JSON.parse(text);
|
|
14
|
+
} catch (cause) {
|
|
15
|
+
throw workflowErrorDiagnostics.WORKFLOW_PAYLOAD_JSON_INVALID({ cause });
|
|
16
|
+
}
|
|
10
17
|
}
|
|
11
18
|
async function validatePayload(payload, schema) {
|
|
12
19
|
if (typeof schema === "function") return await schema(payload);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A as WorkflowRun, B as WorkflowStartOptions, f as WorkflowDefinition, l as ResolvedWorkflowOptions } from "./types-BWPHeugk.js";
|
|
2
2
|
//#region src/runtime/openworkflow.d.ts
|
|
3
3
|
type OpenWorkflowModule = typeof import("openworkflow");
|
|
4
4
|
type OpenWorkflowPostgresModule = typeof import("openworkflow/postgres");
|
|
@@ -10,7 +10,7 @@ type OpenWorkflowImporter = <T>(specifier: string) => Promise<T>;
|
|
|
10
10
|
interface OpenWorkflowRuntime {
|
|
11
11
|
backend: OpenWorkflowBackend;
|
|
12
12
|
client: OpenWorkflowClient;
|
|
13
|
-
|
|
13
|
+
definitions: Map<string, WorkflowDefinition>;
|
|
14
14
|
findRunId: (name: string, key: string) => Promise<string | undefined>;
|
|
15
15
|
workflows: Map<string, OpenWorkflowRunnable>;
|
|
16
16
|
}
|
|
@@ -31,13 +31,14 @@ declare function describeOpenWorkflowStorage(config: ResolvedWorkflowOptions): {
|
|
|
31
31
|
source: OpenWorkflowStorageSource;
|
|
32
32
|
};
|
|
33
33
|
declare function getOpenWorkflowRuntime(config: ResolvedWorkflowOptions): Promise<OpenWorkflowRuntime>;
|
|
34
|
+
/**
|
|
35
|
+
* Sends `value` to a live run that waits for the signal `token`. OpenWorkflow drops early signals and can match
|
|
36
|
+
* a wait left behind by cancellation, so check the run before sending.
|
|
37
|
+
*/
|
|
38
|
+
declare function resumeOpenWorkflowSignal(config: ResolvedWorkflowOptions, workflow: string, id: string, token: string, value: unknown): Promise<boolean>;
|
|
34
39
|
declare function registerOpenWorkflowDefinition(runtime: OpenWorkflowRuntime, name: string, definition: WorkflowDefinition): Promise<OpenWorkflowRunnable>;
|
|
35
40
|
declare function runOpenWorkflow<TPayload = unknown, TResult = unknown>(config: ResolvedWorkflowOptions, name: string, payload: TPayload | undefined, definition: WorkflowDefinition<TPayload, TResult>, options: WorkflowStartOptions, onDispatch?: () => void, startAt?: number): Promise<WorkflowRun<TPayload, TResult>>;
|
|
36
41
|
declare function getOpenWorkflowRun<TPayload = unknown, TResult = unknown>(config: ResolvedWorkflowOptions, name: string, id: string): Promise<WorkflowRun<TPayload, TResult>>;
|
|
37
|
-
/**
|
|
38
|
-
* Cancels a pending or running OpenWorkflow run of this Workflow and returns its state afterwards. A run of another
|
|
39
|
-
* Workflow, or an unknown run, reports `unknown` without being cancelled. A finished run keeps and reports its status.
|
|
40
|
-
*/
|
|
41
42
|
declare function cancelOpenWorkflowRun<TPayload = unknown, TResult = unknown>(config: ResolvedWorkflowOptions, name: string, id: string): Promise<WorkflowRun<TPayload, TResult>>;
|
|
42
43
|
declare function resetOpenWorkflowRuntime(): Promise<void>;
|
|
43
44
|
/**
|
|
@@ -47,4 +48,4 @@ declare function resetOpenWorkflowRuntime(): Promise<void>;
|
|
|
47
48
|
declare function detachOpenWorkflowRuntimes(): () => Promise<void>;
|
|
48
49
|
declare function setOpenWorkflowImporter(importer: OpenWorkflowImporter): void;
|
|
49
50
|
//#endregion
|
|
50
|
-
export { getOpenWorkflowRun as a, resetOpenWorkflowRuntime as c,
|
|
51
|
+
export { getOpenWorkflowRun as a, resetOpenWorkflowRuntime as c, setOpenWorkflowDatabaseUrl as d, setOpenWorkflowImporter as f, detachOpenWorkflowRuntimes as i, resumeOpenWorkflowSignal as l, cancelOpenWorkflowRun as n, getOpenWorkflowRuntime as o, describeOpenWorkflowStorage as r, registerOpenWorkflowDefinition as s, OpenWorkflowStorageSource as t, runOpenWorkflow as u };
|
|
@@ -104,6 +104,11 @@ interface OperationAccess {
|
|
|
104
104
|
*/
|
|
105
105
|
readonly sections: "all" | readonly string[];
|
|
106
106
|
readonly user?: OperationUser;
|
|
107
|
+
/**
|
|
108
|
+
* Who signed the call: `"console"` when the ViteHub Console signed it for a person, whose `user` is then a Console
|
|
109
|
+
* account and not an app user, or `"cli"` for a key. Not set for other calls.
|
|
110
|
+
*/
|
|
111
|
+
readonly via?: "console" | "cli";
|
|
107
112
|
}
|
|
108
113
|
interface OperationContext {
|
|
109
114
|
/** The checked Console access of the call. */
|
|
@@ -115,6 +120,11 @@ interface OperationContext {
|
|
|
115
120
|
surface: "console" | "cli" | "mcp" | "agent";
|
|
116
121
|
/** Set by the host from generated build identity, never from request input or runtime NODE_ENV. */
|
|
117
122
|
development?: boolean;
|
|
123
|
+
/**
|
|
124
|
+
* The project root of a development server, for operations that read build files, such as `bundle.report`. Hosts set
|
|
125
|
+
* it only with `development`, so a deployed server never reads project files through it.
|
|
126
|
+
*/
|
|
127
|
+
projectRoot?: string;
|
|
118
128
|
env?: Record<string, unknown>;
|
|
119
129
|
waitUntil?: (task: Promise<unknown>) => void;
|
|
120
130
|
request?: Request;
|
|
@@ -161,7 +171,8 @@ interface OperationDefinition<Input, Output> {
|
|
|
161
171
|
/** Standard Schema (valibot in this repo). Its Standard JSON Schema builds CLI flags and the MCP input schema. */
|
|
162
172
|
input: StandardSchemaV1<unknown, Input>;
|
|
163
173
|
output?: StandardSchemaV1<unknown, Output>;
|
|
164
|
-
|
|
174
|
+
/** `false`: no `vitehub` command. The Console and MCP still call the operation. */
|
|
175
|
+
cli?: false | {
|
|
165
176
|
/** Defaults: namespace = section, command = verb. */
|
|
166
177
|
namespace?: string;
|
|
167
178
|
/** A space groups commands: `jobs list` and `jobs show` run as `vitehub <namespace> jobs list` and `jobs show`. */
|
|
@@ -202,7 +213,7 @@ interface OperationDefinition<Input, Output> {
|
|
|
202
213
|
/** An operation of any input and output, as a registry holds it. */
|
|
203
214
|
interface AnyOperation extends Omit<OperationDefinition<unknown, unknown>, "cli" | "input" | "mcp" | "output" | "readOnlyWhen" | "run" | "scope" | "section"> {
|
|
204
215
|
readOnlyWhen?: (input: never) => boolean;
|
|
205
|
-
cli?: {
|
|
216
|
+
cli?: false | {
|
|
206
217
|
namespace?: string;
|
|
207
218
|
command?: string;
|
|
208
219
|
default?: boolean;
|
|
@@ -1,19 +1,13 @@
|
|
|
1
|
-
import { t as workflowErrorDiagnostics } from "./error-diagnostics-8YNJ37rP.js";
|
|
2
|
-
import { a as resumeWorkflow, i as getWorkflowRun, o as startWorkflow, t as cancelWorkflow } from "./client-CU5rELC0.js";
|
|
3
1
|
import { t as isRecord } from "./object-Da1zyPCR.js";
|
|
2
|
+
import { t as workflowErrorDiagnostics } from "./error-diagnostics-DMeaFmQD.js";
|
|
3
|
+
import { a as resumeWorkflow, i as getWorkflowRun, o as startWorkflow, t as cancelWorkflow } from "./client-CgBcDlGn.js";
|
|
4
4
|
import { t as getWorkflowDevRecorder } from "./dev-recorder-CTN5Fkao.js";
|
|
5
|
-
import { n as redactInspectionValue, t as redactInspectionText } from "./inspect-B72iFyj-.js";
|
|
6
|
-
import { t as toWorkflowRunError } from "./run-error-DBWqiJHH.js";
|
|
7
5
|
import { getInlineWorkflowDefinitions, getWorkflowRuntimeConfig, getWorkflowRuntimeRegistry } from "./runtime/state.js";
|
|
8
|
-
import {
|
|
6
|
+
import { n as redactInspectionValue, t as redactInspectionText } from "./inspect-B72iFyj-.js";
|
|
7
|
+
import { t as toWorkflowRunError } from "./run-error-Ctn50EYz.js";
|
|
8
|
+
import { deserializeResponse, isSerializedResponse } from "@vite-hub/runtime/internal/response";
|
|
9
9
|
//#region src/results.ts
|
|
10
10
|
const inlineRunNote = "Runs the Workflow inline in the Nitro runtime, as the app does in development. Inline runs are not durable and have no retries.";
|
|
11
|
-
function unsupported(note) {
|
|
12
|
-
return {
|
|
13
|
-
note,
|
|
14
|
-
supported: false
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
11
|
/**
|
|
18
12
|
* Operations that each provider supports. A supported operation can still fail when the runtime decides, for example
|
|
19
13
|
* cancel on an inline Vercel run.
|
|
@@ -28,7 +22,10 @@ function resolveWorkflowOperationSupport(provider) {
|
|
|
28
22
|
note: "Reads the run from the Cloudflare Workflow binding when the runtime has one.",
|
|
29
23
|
supported: true
|
|
30
24
|
},
|
|
31
|
-
resume:
|
|
25
|
+
resume: {
|
|
26
|
+
note: "Queues a signal through the Cloudflare Workflow binding, or delivers it to an inline run in this process.",
|
|
27
|
+
supported: true
|
|
28
|
+
},
|
|
32
29
|
start: {
|
|
33
30
|
note: `Uses the Cloudflare Workflow binding when the runtime has one. Otherwise: ${inlineRunNote}`,
|
|
34
31
|
supported: true
|
|
@@ -43,7 +40,10 @@ function resolveWorkflowOperationSupport(provider) {
|
|
|
43
40
|
note: "Reads the run from OpenWorkflow storage.",
|
|
44
41
|
supported: true
|
|
45
42
|
},
|
|
46
|
-
resume:
|
|
43
|
+
resume: {
|
|
44
|
+
note: "Delivers a signal to a waiting OpenWorkflow run, or to an inline run in this process.",
|
|
45
|
+
supported: true
|
|
46
|
+
},
|
|
47
47
|
start: {
|
|
48
48
|
note: "Enqueues the run in OpenWorkflow storage. The run stays queued until an OpenWorkflow worker processes the same storage.",
|
|
49
49
|
supported: true
|
|
@@ -71,7 +71,6 @@ function resolveWorkflowOperationSupport(provider) {
|
|
|
71
71
|
//#endregion
|
|
72
72
|
//#region src/runtime/operations.ts
|
|
73
73
|
const maxRememberedRuns = 1024;
|
|
74
|
-
/** The HTTP status that the CLI, the Console, and Agents report for each code of a failed operation. */
|
|
75
74
|
const operationStatus = {
|
|
76
75
|
VERCEL_WORKFLOW_SDK_LOAD_FAILED: 501,
|
|
77
76
|
WORKFLOW_DEFINITION_NOT_FOUND: 404,
|
|
@@ -83,11 +82,11 @@ const operationStatus = {
|
|
|
83
82
|
WORKFLOW_PROVIDER_OPERATION_FAILED: 502,
|
|
84
83
|
WORKFLOW_REGISTRY_MISSING: 409,
|
|
85
84
|
WORKFLOW_RUN_AMBIGUOUS: 400,
|
|
86
|
-
WORKFLOW_RUN_NOT_FOUND: 404,
|
|
87
85
|
WORKFLOW_RUN_UNKNOWN: 400,
|
|
88
|
-
WORKFLOW_RUNS_UNAVAILABLE: 409
|
|
86
|
+
WORKFLOW_RUNS_UNAVAILABLE: 409,
|
|
87
|
+
WORKFLOW_SIGNAL_NOT_WAITING: 409,
|
|
88
|
+
WORKFLOW_SIGNAL_TOKEN_INVALID: 400
|
|
89
89
|
};
|
|
90
|
-
/** Gives an operation error the status of its code and the redacted message that the CLI and the Console report. */
|
|
91
90
|
function failure(error, message = error.message) {
|
|
92
91
|
return Object.defineProperties(error, {
|
|
93
92
|
status: {
|
|
@@ -107,11 +106,6 @@ function failure(error, message = error.message) {
|
|
|
107
106
|
function hasStatus(error) {
|
|
108
107
|
return error instanceof Error && typeof Reflect.get(error, "status") === "number" && typeof Reflect.get(error, "code") === "string";
|
|
109
108
|
}
|
|
110
|
-
/**
|
|
111
|
-
* Checks the Fetch Response fields, not one realm's constructor, so a Response from another Fetch implementation also
|
|
112
|
-
* matches. `status` and `headers` alone also match an HTTP client result, such as an Axios response, so the body fields
|
|
113
|
-
* are checked too. The Agent package has the same check.
|
|
114
|
-
*/
|
|
115
109
|
function isResponse$1(value) {
|
|
116
110
|
if (typeof value !== "object" || value === null) return false;
|
|
117
111
|
const response = value;
|
|
@@ -252,24 +246,37 @@ async function run(operation, input) {
|
|
|
252
246
|
workflow
|
|
253
247
|
}));
|
|
254
248
|
}
|
|
255
|
-
const started = await startWorkflow(workflow, payload);
|
|
249
|
+
const [error, started] = await startWorkflow(workflow, payload);
|
|
250
|
+
if (error) throw error;
|
|
256
251
|
rememberRun(started.id, workflow);
|
|
257
252
|
return { run: await toWorkflowRunView(started, workflow) };
|
|
258
253
|
}
|
|
259
254
|
if (operation === "resume") {
|
|
260
255
|
const { payload, token } = input;
|
|
261
|
-
const signal = await resumeWorkflow(token, payload);
|
|
256
|
+
const [error, signal] = await resumeWorkflow(token, payload);
|
|
257
|
+
if (error) throw error;
|
|
262
258
|
return { signal: {
|
|
263
259
|
id: signal.id,
|
|
264
260
|
provider: signal.provider
|
|
265
261
|
} };
|
|
266
262
|
}
|
|
267
263
|
const { runId, workflow: named } = input;
|
|
264
|
+
const recorded = operation === "get" ? getWorkflowDevRecorder()?.list().filter((record) => record.id === runId && (named === void 0 || record.workflow === named)) ?? [] : [];
|
|
265
|
+
if (recorded.length > 1) throw failure(workflowErrorDiagnostics.WORKFLOW_RUN_AMBIGUOUS({
|
|
266
|
+
id: runId,
|
|
267
|
+
workflows: recorded.map((record) => record.workflow).join(", ")
|
|
268
|
+
}));
|
|
269
|
+
const [record] = recorded;
|
|
270
|
+
if (record) return { run: {
|
|
271
|
+
...await toWorkflowRunView(devRunView(record), record.workflow),
|
|
272
|
+
steps: record.steps.map(stepView)
|
|
273
|
+
} };
|
|
268
274
|
const workflow = named ?? startedRuns.get(runId);
|
|
269
275
|
if (!workflow) throw failure(workflowErrorDiagnostics.WORKFLOW_RUN_UNKNOWN({ runId }));
|
|
270
|
-
|
|
276
|
+
const [error, found] = operation === "get" ? await getWorkflowRun(workflow, runId) : await cancelWorkflow(workflow, runId);
|
|
277
|
+
if (error) throw error;
|
|
278
|
+
return { run: await toWorkflowRunView(found, workflow) };
|
|
271
279
|
}
|
|
272
|
-
/** The run history of `vite dev`. Hosted providers keep their own history, which ViteHub does not list. */
|
|
273
280
|
function devRecorder() {
|
|
274
281
|
if (getWorkflowRuntimeConfig() === false) throw failure(workflowErrorDiagnostics.WORKFLOW_DISABLED());
|
|
275
282
|
const recorder = getWorkflowDevRecorder();
|
|
@@ -307,23 +314,9 @@ async function listWorkflowRuns(input) {
|
|
|
307
314
|
stepCount: record.steps.length
|
|
308
315
|
}))) };
|
|
309
316
|
}
|
|
310
|
-
/** Shows one run that `vite dev` recorded, with its steps, result, and error. */
|
|
311
|
-
async function showWorkflowRun(input) {
|
|
312
|
-
const matches = devRecorder().list().filter((record) => record.id === input.id && (input.workflow === void 0 || record.workflow === input.workflow));
|
|
313
|
-
if (matches.length === 0) throw failure(workflowErrorDiagnostics.WORKFLOW_RUN_NOT_FOUND({ id: input.id }));
|
|
314
|
-
if (matches.length > 1) throw failure(workflowErrorDiagnostics.WORKFLOW_RUN_AMBIGUOUS({
|
|
315
|
-
id: input.id,
|
|
316
|
-
workflows: matches.map((record) => record.workflow).join(", ")
|
|
317
|
-
}));
|
|
318
|
-
const record = matches[0];
|
|
319
|
-
return { run: {
|
|
320
|
-
...await toWorkflowRunView(devRunView(record), record.workflow),
|
|
321
|
-
steps: record.steps.map(stepView)
|
|
322
|
-
} };
|
|
323
|
-
}
|
|
324
317
|
/** Removes the runs that `vite dev` recorded. A run that is still active finishes but is not listed again. */
|
|
325
318
|
function clearWorkflowRuns() {
|
|
326
319
|
return { cleared: devRecorder().clear() };
|
|
327
320
|
}
|
|
328
321
|
//#endregion
|
|
329
|
-
export { clearWorkflowRuns, listWorkflowRuns, runWorkflowOperation,
|
|
322
|
+
export { clearWorkflowRuns, listWorkflowRuns, runWorkflowOperation, toWorkflowRunView };
|
package/dist/operations.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as AnyOperation } from "./operation-definition-
|
|
1
|
+
import { M as WorkflowRunStatus, h as WorkflowDriver } from "./types-BWPHeugk.js";
|
|
2
|
+
import { t as AnyOperation } from "./operation-definition-CI2PJGqu.js";
|
|
3
3
|
//#region src/results.d.ts
|
|
4
4
|
/** One Workflow run as the operations return it. The start payload is not included. */
|
|
5
5
|
interface WorkflowRunView {
|
|
@@ -24,7 +24,8 @@ interface WorkflowSignalView {
|
|
|
24
24
|
provider: WorkflowDriver;
|
|
25
25
|
}
|
|
26
26
|
interface WorkflowRunResult {
|
|
27
|
-
run
|
|
27
|
+
/** `workflow.get` adds the steps of a run that `vite dev` recorded. */
|
|
28
|
+
run: WorkflowRunView | WorkflowRunDetailView;
|
|
28
29
|
}
|
|
29
30
|
/** One step of a run that `vite dev` recorded. */
|
|
30
31
|
interface WorkflowRunStepView {
|
|
@@ -53,10 +54,6 @@ interface WorkflowRunsListResult {
|
|
|
53
54
|
interface WorkflowRunsClearResult {
|
|
54
55
|
cleared: number;
|
|
55
56
|
}
|
|
56
|
-
/** Result of `workflow.runs-show`. */
|
|
57
|
-
interface WorkflowRunsShowResult {
|
|
58
|
-
run: WorkflowRunDetailView;
|
|
59
|
-
}
|
|
60
57
|
interface WorkflowSignalResult {
|
|
61
58
|
signal: WorkflowSignalView;
|
|
62
59
|
}
|
|
@@ -68,4 +65,4 @@ interface WorkflowSignalResult {
|
|
|
68
65
|
*/
|
|
69
66
|
export declare const workflowOperations: readonly AnyOperation[];
|
|
70
67
|
//#endregion
|
|
71
|
-
export type { WorkflowRunDetailView, WorkflowRunResult, WorkflowRunStepView, WorkflowRunView, WorkflowRunsClearResult, WorkflowRunsListResult,
|
|
68
|
+
export type { WorkflowRunDetailView, WorkflowRunResult, WorkflowRunStepView, WorkflowRunView, WorkflowRunsClearResult, WorkflowRunsListResult, WorkflowSignalResult, WorkflowSignalView };
|