@vite-hub/workflow 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -10
- package/dist/{app-He0GTrYZ.js → app-2Y7sBAG6.js} +1 -1
- package/dist/{client-DkwOxEiT.js → client-CgBcDlGn.js} +80 -54
- package/dist/{cloudflare-BHfClPvT.js → cloudflare-Datj_znU.js} +1 -1
- package/dist/{config-C3DvtjfJ.js → config-z1651xc2.js} +1 -1
- package/dist/definition.d.ts +1 -1
- package/dist/definition.js +1 -1
- package/dist/{delay-D1-nq_VE.js → delay-CHN4tv3i.js} +1 -2
- package/dist/durability.d.ts +1 -1
- package/dist/{error-diagnostics-CQ4BUqRe.js → error-diagnostics-C0KyI408.js} +5 -1
- package/dist/{error-diagnostics-0V2T3JFw.js → error-diagnostics-DMeaFmQD.js} +23 -5
- package/dist/{errors-DCqRnZpN.js → errors-BNxEeeCO.js} +0 -4
- package/dist/{errors-uhP8DZTi.d.ts → errors-D-fNDVg0.d.ts} +0 -5
- package/dist/index.d.ts +7 -5
- package/dist/index.js +4 -4
- package/dist/{openworkflow-BhzxV_Y3.d.ts → openworkflow-BoaENgh9.d.ts} +7 -8
- package/dist/{operation-definition-nmRu_O3V.d.ts → operation-definition-CI2PJGqu.d.ts} +8 -2
- package/dist/{operations-D_WJwjrS.js → operations-CYntpf-T.js} +27 -38
- package/dist/operations.d.ts +5 -8
- package/dist/operations.js +27 -32
- package/dist/{run-error-DBWqiJHH.js → run-error-Ctn50EYz.js} +1 -2
- package/dist/runtime/cloudflare-runner.d.ts +12 -2
- package/dist/runtime/cloudflare-runner.js +13 -6
- 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 +2 -2
- package/dist/runtime/execute.js +64 -32
- 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 +33 -48
- package/dist/runtime/state.d.ts +1 -1
- package/dist/runtime/state.js +3 -1
- 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-Dsmwsdlv.d.ts → types-BWPHeugk.d.ts} +34 -4
- package/dist/{vercel-DTvm61iY.js → vercel-BIkBFrQQ.js} +4 -12
- package/dist/vite.d.ts +12 -7
- package/dist/vite.js +3516 -1660
- package/package.json +3 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as WorkflowRun,
|
|
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,9 +10,7 @@ type OpenWorkflowImporter = <T>(specifier: string) => Promise<T>;
|
|
|
10
10
|
interface OpenWorkflowRuntime {
|
|
11
11
|
backend: OpenWorkflowBackend;
|
|
12
12
|
client: OpenWorkflowClient;
|
|
13
|
-
/** The registered ViteHub definitions, by name. */
|
|
14
13
|
definitions: Map<string, WorkflowDefinition>;
|
|
15
|
-
/** Returns the OpenWorkflow id of the first run of `name` that started with the id `key`. */
|
|
16
14
|
findRunId: (name: string, key: string) => Promise<string | undefined>;
|
|
17
15
|
workflows: Map<string, OpenWorkflowRunnable>;
|
|
18
16
|
}
|
|
@@ -33,13 +31,14 @@ declare function describeOpenWorkflowStorage(config: ResolvedWorkflowOptions): {
|
|
|
33
31
|
source: OpenWorkflowStorageSource;
|
|
34
32
|
};
|
|
35
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>;
|
|
36
39
|
declare function registerOpenWorkflowDefinition(runtime: OpenWorkflowRuntime, name: string, definition: WorkflowDefinition): Promise<OpenWorkflowRunnable>;
|
|
37
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>>;
|
|
38
41
|
declare function getOpenWorkflowRun<TPayload = unknown, TResult = unknown>(config: ResolvedWorkflowOptions, name: string, id: string): Promise<WorkflowRun<TPayload, TResult>>;
|
|
39
|
-
/**
|
|
40
|
-
* Cancels a pending or running OpenWorkflow run of this Workflow and returns its state afterwards. A run of another
|
|
41
|
-
* Workflow, or an unknown run, reports `unknown` without being cancelled. A finished run keeps and reports its status.
|
|
42
|
-
*/
|
|
43
42
|
declare function cancelOpenWorkflowRun<TPayload = unknown, TResult = unknown>(config: ResolvedWorkflowOptions, name: string, id: string): Promise<WorkflowRun<TPayload, TResult>>;
|
|
44
43
|
declare function resetOpenWorkflowRuntime(): Promise<void>;
|
|
45
44
|
/**
|
|
@@ -49,4 +48,4 @@ declare function resetOpenWorkflowRuntime(): Promise<void>;
|
|
|
49
48
|
declare function detachOpenWorkflowRuntimes(): () => Promise<void>;
|
|
50
49
|
declare function setOpenWorkflowImporter(importer: OpenWorkflowImporter): void;
|
|
51
50
|
//#endregion
|
|
52
|
-
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. */
|
|
@@ -166,7 +171,8 @@ interface OperationDefinition<Input, Output> {
|
|
|
166
171
|
/** Standard Schema (valibot in this repo). Its Standard JSON Schema builds CLI flags and the MCP input schema. */
|
|
167
172
|
input: StandardSchemaV1<unknown, Input>;
|
|
168
173
|
output?: StandardSchemaV1<unknown, Output>;
|
|
169
|
-
|
|
174
|
+
/** `false`: no `vitehub` command. The Console and MCP still call the operation. */
|
|
175
|
+
cli?: false | {
|
|
170
176
|
/** Defaults: namespace = section, command = verb. */
|
|
171
177
|
namespace?: string;
|
|
172
178
|
/** A space groups commands: `jobs list` and `jobs show` run as `vitehub <namespace> jobs list` and `jobs show`. */
|
|
@@ -207,7 +213,7 @@ interface OperationDefinition<Input, Output> {
|
|
|
207
213
|
/** An operation of any input and output, as a registry holds it. */
|
|
208
214
|
interface AnyOperation extends Omit<OperationDefinition<unknown, unknown>, "cli" | "input" | "mcp" | "output" | "readOnlyWhen" | "run" | "scope" | "section"> {
|
|
209
215
|
readOnlyWhen?: (input: never) => boolean;
|
|
210
|
-
cli?: {
|
|
216
|
+
cli?: false | {
|
|
211
217
|
namespace?: string;
|
|
212
218
|
command?: string;
|
|
213
219
|
default?: boolean;
|
|
@@ -1,19 +1,13 @@
|
|
|
1
1
|
import { t as isRecord } from "./object-Da1zyPCR.js";
|
|
2
|
-
import { t as workflowErrorDiagnostics } from "./error-diagnostics-
|
|
3
|
-
import { a as resumeWorkflow, i as getWorkflowRun, o as startWorkflow, t as cancelWorkflow } from "./client-
|
|
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;
|
|
@@ -267,13 +261,22 @@ async function run(operation, input) {
|
|
|
267
261
|
} };
|
|
268
262
|
}
|
|
269
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
|
+
} };
|
|
270
274
|
const workflow = named ?? startedRuns.get(runId);
|
|
271
275
|
if (!workflow) throw failure(workflowErrorDiagnostics.WORKFLOW_RUN_UNKNOWN({ runId }));
|
|
272
276
|
const [error, found] = operation === "get" ? await getWorkflowRun(workflow, runId) : await cancelWorkflow(workflow, runId);
|
|
273
277
|
if (error) throw error;
|
|
274
278
|
return { run: await toWorkflowRunView(found, workflow) };
|
|
275
279
|
}
|
|
276
|
-
/** The run history of `vite dev`. Hosted providers keep their own history, which ViteHub does not list. */
|
|
277
280
|
function devRecorder() {
|
|
278
281
|
if (getWorkflowRuntimeConfig() === false) throw failure(workflowErrorDiagnostics.WORKFLOW_DISABLED());
|
|
279
282
|
const recorder = getWorkflowDevRecorder();
|
|
@@ -311,23 +314,9 @@ async function listWorkflowRuns(input) {
|
|
|
311
314
|
stepCount: record.steps.length
|
|
312
315
|
}))) };
|
|
313
316
|
}
|
|
314
|
-
/** Shows one run that `vite dev` recorded, with its steps, result, and error. */
|
|
315
|
-
async function showWorkflowRun(input) {
|
|
316
|
-
const matches = devRecorder().list().filter((record) => record.id === input.id && (input.workflow === void 0 || record.workflow === input.workflow));
|
|
317
|
-
if (matches.length === 0) throw failure(workflowErrorDiagnostics.WORKFLOW_RUN_NOT_FOUND({ id: input.id }));
|
|
318
|
-
if (matches.length > 1) throw failure(workflowErrorDiagnostics.WORKFLOW_RUN_AMBIGUOUS({
|
|
319
|
-
id: input.id,
|
|
320
|
-
workflows: matches.map((record) => record.workflow).join(", ")
|
|
321
|
-
}));
|
|
322
|
-
const record = matches[0];
|
|
323
|
-
return { run: {
|
|
324
|
-
...await toWorkflowRunView(devRunView(record), record.workflow),
|
|
325
|
-
steps: record.steps.map(stepView)
|
|
326
|
-
} };
|
|
327
|
-
}
|
|
328
317
|
/** Removes the runs that `vite dev` recorded. A run that is still active finishes but is not listed again. */
|
|
329
318
|
function clearWorkflowRuns() {
|
|
330
319
|
return { cleared: devRecorder().clear() };
|
|
331
320
|
}
|
|
332
321
|
//#endregion
|
|
333
|
-
export { clearWorkflowRuns, listWorkflowRuns, runWorkflowOperation,
|
|
322
|
+
export { clearWorkflowRuns, listWorkflowRuns, runWorkflowOperation, toWorkflowRunView };
|
package/dist/operations.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { M as WorkflowRunStatus, h as WorkflowDriver } from "./types-
|
|
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 };
|
package/dist/operations.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as isRecordOrFunction } from "./object-Da1zyPCR.js";
|
|
2
|
-
import { t as internalErrorDiagnostics } from "./error-diagnostics-
|
|
2
|
+
import { t as internalErrorDiagnostics } from "./error-diagnostics-C0KyI408.js";
|
|
3
3
|
import { toJsonSchema } from "@valibot/to-json-schema";
|
|
4
4
|
import * as v from "valibot";
|
|
5
5
|
//#region ../internal/src/standard-schema.ts
|
|
@@ -143,7 +143,7 @@ function table(rows) {
|
|
|
143
143
|
}
|
|
144
144
|
//#endregion
|
|
145
145
|
//#region src/operations.ts
|
|
146
|
-
const runtime = () => import("./operations-
|
|
146
|
+
const runtime = () => import("./operations-CYntpf-T.js");
|
|
147
147
|
const name = v.pipe(v.string(), v.check((value) => value.trim() !== "", "Name a Workflow."));
|
|
148
148
|
const runId = v.pipe(v.string(), v.check((value) => value.trim() !== "", "Pass the id of a run."));
|
|
149
149
|
const maxRequestBytes = 1048576;
|
|
@@ -172,8 +172,12 @@ const start = defineWorkflowOperation({
|
|
|
172
172
|
run: async (input) => (await runtime()).runWorkflowOperation("start", input)
|
|
173
173
|
});
|
|
174
174
|
const get = defineWorkflowOperation({
|
|
175
|
-
cli: {
|
|
176
|
-
|
|
175
|
+
cli: {
|
|
176
|
+
command: "runs get",
|
|
177
|
+
format: formatRun,
|
|
178
|
+
positional: ["runId"]
|
|
179
|
+
},
|
|
180
|
+
description: "Show the status and result of a Workflow run, with its steps when `vite dev` recorded it. Pass `workflow` for a run that this runtime did not start.",
|
|
177
181
|
input: v.object({
|
|
178
182
|
runId,
|
|
179
183
|
workflow: v.optional(name)
|
|
@@ -227,6 +231,24 @@ function formatRuns({ runs }) {
|
|
|
227
231
|
function json(value) {
|
|
228
232
|
return JSON.stringify(value ?? null, null, 2);
|
|
229
233
|
}
|
|
234
|
+
/** The steps of a run that `vite dev` recorded. A run of another runtime has no steps. */
|
|
235
|
+
function stepLines(steps) {
|
|
236
|
+
if (!steps) return [];
|
|
237
|
+
if (!steps.length) return ["Steps: none"];
|
|
238
|
+
return ["Steps:", table([[
|
|
239
|
+
"STEP",
|
|
240
|
+
"STATUS",
|
|
241
|
+
"STARTED AT",
|
|
242
|
+
"COMPLETED AT",
|
|
243
|
+
"ERROR"
|
|
244
|
+
], ...steps.map((step) => [
|
|
245
|
+
step.name,
|
|
246
|
+
step.status,
|
|
247
|
+
step.startedAt,
|
|
248
|
+
step.completedAt ?? "-",
|
|
249
|
+
step.error?.message ?? "-"
|
|
250
|
+
])])];
|
|
251
|
+
}
|
|
230
252
|
function formatRun({ run }) {
|
|
231
253
|
return [
|
|
232
254
|
`Run: ${run.id}`,
|
|
@@ -237,19 +259,7 @@ function formatRun({ run }) {
|
|
|
237
259
|
...run.startedAt ? [`Started at: ${run.startedAt}`] : [],
|
|
238
260
|
...run.completedAt ? [`Completed at: ${run.completedAt}`] : [],
|
|
239
261
|
...run.error ? [`Error: ${run.error.code ? `${run.error.code} ` : ""}${run.error.message}`] : [],
|
|
240
|
-
...run.steps
|
|
241
|
-
"STEP",
|
|
242
|
-
"STATUS",
|
|
243
|
-
"STARTED AT",
|
|
244
|
-
"COMPLETED AT",
|
|
245
|
-
"ERROR"
|
|
246
|
-
], ...run.steps.map((step) => [
|
|
247
|
-
step.name,
|
|
248
|
-
step.status,
|
|
249
|
-
step.startedAt,
|
|
250
|
-
step.completedAt ?? "-",
|
|
251
|
-
step.error?.message ?? "-"
|
|
252
|
-
])])] : ["Steps: none"],
|
|
262
|
+
...stepLines(run.steps),
|
|
253
263
|
...run.status === "completed" ? ["Result:", json(run.result)] : [],
|
|
254
264
|
""
|
|
255
265
|
].join("\n");
|
|
@@ -283,21 +293,6 @@ const workflowOperations = [
|
|
|
283
293
|
name: "workflow.runs-list",
|
|
284
294
|
run: async (input) => (await runtime()).listWorkflowRuns(input)
|
|
285
295
|
}),
|
|
286
|
-
defineWorkflowOperation({
|
|
287
|
-
cli: {
|
|
288
|
-
command: "runs show",
|
|
289
|
-
format: formatRun,
|
|
290
|
-
positional: ["id"]
|
|
291
|
-
},
|
|
292
|
-
description: "Show one Workflow run that `vite dev` recorded, with its steps, status, result, and error.",
|
|
293
|
-
input: v.strictObject({
|
|
294
|
-
id: runId,
|
|
295
|
-
workflow: v.optional(name)
|
|
296
|
-
}),
|
|
297
|
-
kind: "read",
|
|
298
|
-
name: "workflow.runs-show",
|
|
299
|
-
run: async (input) => (await runtime()).showWorkflowRun(input)
|
|
300
|
-
}),
|
|
301
296
|
defineWorkflowOperation({
|
|
302
297
|
cli: {
|
|
303
298
|
command: "runs clear",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as createWorkflowError } from "./errors-
|
|
1
|
+
import { n as createWorkflowError } from "./errors-BNxEeeCO.js";
|
|
2
2
|
import { t as getWorkflowDevRecorder } from "./dev-recorder-CTN5Fkao.js";
|
|
3
3
|
import { t as redactInspectionText } from "./inspect-B72iFyj-.js";
|
|
4
4
|
import { getViteHubErrorShape } from "@vite-hub/runtime";
|
|
@@ -45,7 +45,6 @@ function getWorkflowProviderReason(error) {
|
|
|
45
45
|
const reason = safeName ? `${safeName}: ${text}` : text;
|
|
46
46
|
return reason.length > maxReasonLength ? `${reason.slice(0, 199)}…` : reason;
|
|
47
47
|
}
|
|
48
|
-
/** `vite dev` installs the run history. Elsewhere, `NODE_ENV` says whether the app runs a development server. */
|
|
49
48
|
function isDevelopment() {
|
|
50
49
|
return Boolean(getWorkflowDevRecorder()) || globalThis.process?.env?.NODE_ENV === "development";
|
|
51
50
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { D as WorkflowProviderStep, l as ResolvedWorkflowOptions, m as WorkflowDefinitionRegistry } from "../types-
|
|
1
|
+
import { D as WorkflowProviderStep, l as ResolvedWorkflowOptions, m as WorkflowDefinitionRegistry } from "../types-BWPHeugk.js";
|
|
2
2
|
import { t as CloudflareWorkerEnv } from "../cloudflare-env-lookup-CfX6wZKb.js";
|
|
3
3
|
//#region src/runtime/cloudflare-runner.d.ts
|
|
4
4
|
export interface CloudflareWorkflowEvent {
|
|
@@ -6,6 +6,15 @@ export interface CloudflareWorkflowEvent {
|
|
|
6
6
|
instanceId?: string;
|
|
7
7
|
payload?: unknown;
|
|
8
8
|
}
|
|
9
|
+
/** The `step` of a Cloudflare Workflow: the ViteHub step runner names, and `waitForEvent()`. */
|
|
10
|
+
export interface CloudflareWorkflowStep extends Omit<WorkflowProviderStep, "waitForSignal"> {
|
|
11
|
+
waitForEvent?: (name: string, options: {
|
|
12
|
+
timeout?: string;
|
|
13
|
+
type: string;
|
|
14
|
+
}) => Promise<{
|
|
15
|
+
payload?: unknown;
|
|
16
|
+
}>;
|
|
17
|
+
}
|
|
9
18
|
export interface RunCloudflareWorkflowOptions {
|
|
10
19
|
config: false | ResolvedWorkflowOptions | undefined;
|
|
11
20
|
createNonRetryableError?: (error: Error) => Error;
|
|
@@ -13,7 +22,8 @@ export interface RunCloudflareWorkflowOptions {
|
|
|
13
22
|
event: CloudflareWorkflowEvent;
|
|
14
23
|
name: string;
|
|
15
24
|
registry: WorkflowDefinitionRegistry;
|
|
16
|
-
step?:
|
|
25
|
+
step?: CloudflareWorkflowStep;
|
|
17
26
|
}
|
|
27
|
+
export declare function cloudflareSignalEventType(signal: string): string;
|
|
18
28
|
export declare function runCloudflareWorkflow({ config, createNonRetryableError, env, event, name, registry, step }: RunCloudflareWorkflowOptions): Promise<unknown>;
|
|
19
29
|
//#endregion
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import { t as workflowErrorDiagnostics } from "../error-diagnostics-
|
|
2
|
-
import { n as createWorkflowError, r as isNonRetryableError } from "../errors-
|
|
1
|
+
import { t as workflowErrorDiagnostics } from "../error-diagnostics-DMeaFmQD.js";
|
|
2
|
+
import { n as createWorkflowError, r as isNonRetryableError } from "../errors-BNxEeeCO.js";
|
|
3
3
|
import { r as runWithActiveCloudflareEnv } from "../cloudflare-env-CGLx7lUd.js";
|
|
4
|
-
import { t as fromCloudflareStartParams } from "../delay-
|
|
4
|
+
import { t as fromCloudflareStartParams } from "../delay-CHN4tv3i.js";
|
|
5
5
|
import { resolveWorkflowStepOptions, runSerializedWorkflowHandler } from "./execute.js";
|
|
6
6
|
import { t as emitWorkflowFailed } from "../run-failed-gVGo1BaF.js";
|
|
7
7
|
import { loadWorkflowDefinition, runWithWorkflowRuntimeEvent, setWorkflowRuntimeConfig, setWorkflowRuntimeRegistry } from "./state.js";
|
|
8
8
|
import { hasRunFailedListeners } from "@vite-hub/runtime/internal/run-failed";
|
|
9
9
|
//#region src/runtime/cloudflare-runner.ts
|
|
10
|
-
|
|
10
|
+
function cloudflareSignalEventType(signal) {
|
|
11
|
+
return `vitehub-${signal}`;
|
|
12
|
+
}
|
|
13
|
+
const cloudflareSignalTimeout = "365 days";
|
|
11
14
|
const cloudflareNonRetryableErrors = /* @__PURE__ */ new WeakSet();
|
|
12
15
|
function translateNonRetryableError(error, createNonRetryableError) {
|
|
13
16
|
if (!createNonRetryableError || !isNonRetryableError(error) || cloudflareNonRetryableErrors.has(error)) return error;
|
|
@@ -28,7 +31,11 @@ function wrapCloudflareWorkflowStep(step, createNonRetryableError, env, runtimeE
|
|
|
28
31
|
})));
|
|
29
32
|
},
|
|
30
33
|
...step.sleep ? { sleep: async (name, milliseconds) => await step.sleep(name, milliseconds) } : {},
|
|
31
|
-
...step.sleepUntil ? { sleepUntil: async (name, date) => await step.sleepUntil(name, date) } : {}
|
|
34
|
+
...step.sleepUntil ? { sleepUntil: async (name, date) => await step.sleepUntil(name, date) } : {},
|
|
35
|
+
...step.waitForEvent ? { waitForSignal: async (name) => (await step.waitForEvent(name, {
|
|
36
|
+
timeout: cloudflareSignalTimeout,
|
|
37
|
+
type: cloudflareSignalEventType(name)
|
|
38
|
+
})).payload } : {}
|
|
32
39
|
};
|
|
33
40
|
}
|
|
34
41
|
async function runCloudflareWorkflow({ config, createNonRetryableError, env, event, name, registry, step }) {
|
|
@@ -78,4 +85,4 @@ async function runCloudflareWorkflow({ config, createNonRetryableError, env, eve
|
|
|
78
85
|
});
|
|
79
86
|
}
|
|
80
87
|
//#endregion
|
|
81
|
-
export { runCloudflareWorkflow };
|
|
88
|
+
export { cloudflareSignalEventType, runCloudflareWorkflow };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { l as ResolvedWorkflowOptions, m as WorkflowDefinitionRegistry } from "../types-
|
|
1
|
+
import { l as ResolvedWorkflowOptions, m as WorkflowDefinitionRegistry } from "../types-BWPHeugk.js";
|
|
2
2
|
import { t as CloudflareWorkerEnv } from "../cloudflare-env-lookup-CfX6wZKb.js";
|
|
3
3
|
import { t as CloudflareWorkerExecutionContext } from "../cloudflare-shared-CTqh_a2s.js";
|
|
4
4
|
import { t as VitehubApp } from "../app-BojnC_yf.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { r as runWithActiveCloudflareEnv, t as createCloudflareRuntimeEvent } from "../cloudflare-env-CGLx7lUd.js";
|
|
2
|
-
import { t as normalizeWorkflowOptions } from "../config-
|
|
2
|
+
import { t as normalizeWorkflowOptions } from "../config-z1651xc2.js";
|
|
3
3
|
import { runWithWorkflowRuntimeEvent, setWorkflowRuntimeConfig, setWorkflowRuntimeRegistry } from "./state.js";
|
|
4
|
-
import { t as resolveAppFetch } from "../app-
|
|
4
|
+
import { t as resolveAppFetch } from "../app-2Y7sBAG6.js";
|
|
5
5
|
import "./cloudflare-shared.js";
|
|
6
6
|
//#region ../internal/src/runtime/cloudflare-hosted.ts
|
|
7
7
|
function createWebRequestHandler(appHandler) {
|
package/dist/runtime/dev-runs.js
CHANGED
|
@@ -10,6 +10,7 @@ function createWorkflowDevRecorder() {
|
|
|
10
10
|
runs.clear();
|
|
11
11
|
return count;
|
|
12
12
|
},
|
|
13
|
+
get: (workflow, id) => runs.get(JSON.stringify([workflow, id])),
|
|
13
14
|
list: () => [...runs.values()].reverse(),
|
|
14
15
|
start(workflow, id, provider) {
|
|
15
16
|
const key = JSON.stringify([workflow, id]);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { E as WorkflowProviderContext,
|
|
2
|
-
import { t as NonRetryableError } from "../errors-
|
|
1
|
+
import { E as WorkflowProviderContext, G as WorkflowStepOptions, U as WorkflowStepContext, W as WorkflowStepFunction, _ as WorkflowDuration, f as WorkflowDefinition, q as WorkflowStepRetries } from "../types-BWPHeugk.js";
|
|
2
|
+
import { t as NonRetryableError } from "../errors-D-fNDVg0.js";
|
|
3
3
|
//#region src/runtime/execute.d.ts
|
|
4
4
|
/** The options of a step with the default retries filled in. */
|
|
5
5
|
export interface ResolvedWorkflowStepOptions {
|
package/dist/runtime/execute.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { t as workflowErrorDiagnostics } from "../error-diagnostics-
|
|
2
|
-
import { r as isNonRetryableError, t as NonRetryableError } from "../errors-
|
|
1
|
+
import { t as workflowErrorDiagnostics } from "../error-diagnostics-DMeaFmQD.js";
|
|
2
|
+
import { n as createWorkflowError, r as isNonRetryableError, t as NonRetryableError } from "../errors-BNxEeeCO.js";
|
|
3
3
|
import { t as getWorkflowDevRecorder } from "../dev-recorder-CTN5Fkao.js";
|
|
4
|
-
import {
|
|
4
|
+
import { n as createWorkflowSignalToken, r as openInlineWorkflowSignal, s as waitForInlineWorkflowSignal, t as closeInlineWorkflowSignals } from "../signals-C1iolifd.js";
|
|
5
|
+
import { isResponse, serializeResponse, toResponse } from "@vite-hub/runtime/internal/response";
|
|
5
6
|
//#region src/runtime/execute.ts
|
|
6
7
|
const defaultRetries = {
|
|
7
8
|
backoff: "exponential",
|
|
@@ -48,7 +49,6 @@ function resolveWorkflowStepOptions(step, options) {
|
|
|
48
49
|
...timeout === void 0 ? {} : { timeout }
|
|
49
50
|
};
|
|
50
51
|
}
|
|
51
|
-
/** Calls `callback` after `milliseconds`, also when that is longer than one Node timer can wait. Returns a cancel function. */
|
|
52
52
|
function onTimeout(milliseconds, callback) {
|
|
53
53
|
const deadline = Date.now() + milliseconds;
|
|
54
54
|
let timer;
|
|
@@ -116,7 +116,6 @@ function createWorkflowSteps(context, stepModules) {
|
|
|
116
116
|
return [propertyName, async (input) => await runProviderStep(context.step, `${context.name}/${module.name}`, (stepContext) => module.run(input, stepContext), module.options)];
|
|
117
117
|
}));
|
|
118
118
|
}
|
|
119
|
-
/** The units of a sleep duration, in milliseconds. Cloudflare reads a month as 30 days and a year as 365.25 days. */
|
|
120
119
|
const durationUnits = {
|
|
121
120
|
second: 1e3,
|
|
122
121
|
minute: 6e4,
|
|
@@ -134,7 +133,6 @@ function toDurationMilliseconds(value) {
|
|
|
134
133
|
const match = durationPattern.exec(value);
|
|
135
134
|
return match ? Number(match[1]) * durationUnits[match[2]] : void 0;
|
|
136
135
|
}
|
|
137
|
-
/** A sleep target: a number of milliseconds, or a date. */
|
|
138
136
|
function toSleepTarget(name, until) {
|
|
139
137
|
if (Object.prototype.toString.call(until) === "[object Date]") {
|
|
140
138
|
const date = new Date(until.getTime());
|
|
@@ -149,15 +147,10 @@ function toSleepTarget(name, until) {
|
|
|
149
147
|
value
|
|
150
148
|
});
|
|
151
149
|
}
|
|
152
|
-
/** Node fires a timer longer than this at once, so a longer wait uses more than one timer. */
|
|
153
150
|
const maxTimerDelay = 2147483647;
|
|
154
151
|
async function waitUntil(time) {
|
|
155
152
|
for (let left = time - Date.now(); left > 0; left = time - Date.now()) await new Promise((resolve) => setTimeout(resolve, Math.min(left, maxTimerDelay)));
|
|
156
153
|
}
|
|
157
|
-
/**
|
|
158
|
-
* `context.sleep()` of a folder Workflow. It names each sleep by call order (`sleep-1`, `sleep-2`), so the orchestrator
|
|
159
|
-
* must call it in the same order on each replay. Without a provider sleep, the run is inline and waits with a timer.
|
|
160
|
-
*/
|
|
161
154
|
function createSleep(context) {
|
|
162
155
|
let count = 0;
|
|
163
156
|
return async (until) => {
|
|
@@ -173,19 +166,52 @@ function createSleep(context) {
|
|
|
173
166
|
await runProviderStep(void 0, name, async () => await waitUntil(time));
|
|
174
167
|
};
|
|
175
168
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
169
|
+
function createSignals(context, wait) {
|
|
170
|
+
let count = 0;
|
|
171
|
+
const inlineTokens = [];
|
|
172
|
+
const createSignal = () => {
|
|
173
|
+
if (context.provider === "vercel") throw workflowErrorDiagnostics.WORKFLOW_SIGNAL_VERCEL_UNSUPPORTED({ name: context.name });
|
|
174
|
+
const step = context.step;
|
|
175
|
+
if (step?.do && !step.waitForSignal) throw createWorkflowError({
|
|
176
|
+
code: "WORKFLOW_OPERATION_UNSUPPORTED",
|
|
177
|
+
details: {
|
|
178
|
+
operation: "signals",
|
|
179
|
+
provider: context.provider
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
const name = `signal-${++count}`;
|
|
183
|
+
const inline = !step?.waitForSignal;
|
|
184
|
+
const token = createWorkflowSignalToken({
|
|
185
|
+
host: inline ? "inline" : context.provider,
|
|
186
|
+
run: context.id ?? "",
|
|
187
|
+
signal: name,
|
|
188
|
+
workflow: context.name
|
|
189
|
+
});
|
|
190
|
+
if (inline) {
|
|
191
|
+
openInlineWorkflowSignal(token);
|
|
192
|
+
inlineTokens.push(token);
|
|
193
|
+
}
|
|
194
|
+
let waiting;
|
|
195
|
+
return {
|
|
196
|
+
token,
|
|
197
|
+
wait: () => waiting ??= wait ? wait() : inline ? runProviderStep(void 0, name, async () => await waitForInlineWorkflowSignal(token)) : step.waitForSignal(name, token)
|
|
198
|
+
};
|
|
199
|
+
};
|
|
200
|
+
return {
|
|
201
|
+
close: () => closeInlineWorkflowSignals(inlineTokens),
|
|
202
|
+
createSignal
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
function toExecutionContext(context, sleep, createSignal) {
|
|
181
206
|
return {
|
|
182
207
|
...context,
|
|
208
|
+
createSignal,
|
|
183
209
|
sleep,
|
|
184
210
|
steps: {}
|
|
185
211
|
};
|
|
186
212
|
}
|
|
187
|
-
/** The root step result that says the handler called `context.sleep()`. A replay reads it and fails the same way. */
|
|
188
213
|
const rootStepSleepResult = { "~vitehubRootStepSleep": true };
|
|
214
|
+
const rootStepSignalResult = { "~vitehubRootStepSignal": true };
|
|
189
215
|
function toNonRetryableStepResult(error) {
|
|
190
216
|
if (!isNonRetryableError(error)) return void 0;
|
|
191
217
|
const code = Reflect.get(error, "code");
|
|
@@ -202,38 +228,44 @@ function readNonRetryableStepResult(value) {
|
|
|
202
228
|
error.name = name;
|
|
203
229
|
return code === void 0 ? error : Object.assign(error, { code });
|
|
204
230
|
}
|
|
205
|
-
/**
|
|
206
|
-
* Runs the handler in its root step, or alone for a folder Workflow (`rootStep: false`). A sleep inside the root step
|
|
207
|
-
* fails the run with `WORKFLOW_ROOT_STEP_SLEEP` on every provider. The root step returns a marker instead of throwing,
|
|
208
|
-
* so the provider does not retry it and run the code before the sleep again.
|
|
209
|
-
*/
|
|
210
231
|
async function runInRootStep(context, definition, encode) {
|
|
211
|
-
if (definition.rootStep === false)
|
|
212
|
-
|
|
232
|
+
if (definition.rootStep === false) {
|
|
233
|
+
const signals = createSignals(context);
|
|
234
|
+
try {
|
|
235
|
+
return await encode(await definition.handler(toExecutionContext(context, createSleep(context), signals.createSignal)));
|
|
236
|
+
} finally {
|
|
237
|
+
signals.close();
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
let suspended;
|
|
213
241
|
const sleepError = () => workflowErrorDiagnostics.WORKFLOW_ROOT_STEP_SLEEP({ name: context.name });
|
|
242
|
+
const signalError = () => workflowErrorDiagnostics.WORKFLOW_ROOT_STEP_SIGNAL({ name: context.name });
|
|
214
243
|
const sleep = async () => {
|
|
215
|
-
|
|
244
|
+
suspended = rootStepSleepResult;
|
|
216
245
|
throw sleepError();
|
|
217
246
|
};
|
|
247
|
+
const signals = createSignals(context, async () => {
|
|
248
|
+
suspended = rootStepSignalResult;
|
|
249
|
+
throw signalError();
|
|
250
|
+
});
|
|
218
251
|
const output = await runProviderStep(context.step, context.name, async () => {
|
|
219
252
|
try {
|
|
220
|
-
const value = await encode(await definition.handler(toExecutionContext(context, sleep)));
|
|
221
|
-
return
|
|
253
|
+
const value = await encode(await definition.handler(toExecutionContext(context, sleep, signals.createSignal)));
|
|
254
|
+
return suspended ?? value;
|
|
222
255
|
} catch (error) {
|
|
223
|
-
if (
|
|
256
|
+
if (suspended) return suspended;
|
|
224
257
|
throw error;
|
|
258
|
+
} finally {
|
|
259
|
+
signals.close();
|
|
225
260
|
}
|
|
226
261
|
});
|
|
227
262
|
if (typeof output === "object" && output !== null && "~vitehubRootStepSleep" in output) throw sleepError();
|
|
263
|
+
if (typeof output === "object" && output !== null && "~vitehubRootStepSignal" in output) throw signalError();
|
|
228
264
|
return output;
|
|
229
265
|
}
|
|
230
266
|
async function runWorkflowHandler(context, definition) {
|
|
231
267
|
return toResponse(await runInRootStep(context, definition, (value) => value));
|
|
232
268
|
}
|
|
233
|
-
/**
|
|
234
|
-
* The stored result of a run. A `Response` from the handler is stored as a serialized Response. Any other value is
|
|
235
|
-
* stored as JSON, so every provider returns the same plain value.
|
|
236
|
-
*/
|
|
237
269
|
async function toStoredWorkflowResult(value) {
|
|
238
270
|
if (isResponse(value)) return await serializeResponse(value);
|
|
239
271
|
const json = JSON.stringify(value);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { l as ResolvedWorkflowOptions, m as WorkflowDefinitionRegistry } from "../types-
|
|
2
|
-
import { o as getOpenWorkflowRuntime } from "../openworkflow-
|
|
1
|
+
import { l as ResolvedWorkflowOptions, m as WorkflowDefinitionRegistry } from "../types-BWPHeugk.js";
|
|
2
|
+
import { o as getOpenWorkflowRuntime } from "../openworkflow-BoaENgh9.js";
|
|
3
3
|
import { ViteHubError } from "@vite-hub/runtime";
|
|
4
4
|
import { ShutdownApp } from "@vite-hub/runtime/internal/shutdown";
|
|
5
5
|
//#region src/runtime/openworkflow-worker.d.ts
|