@vite-hub/workflow 0.1.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +173 -55
- package/dist/{app-CzPoP84f.js → app-He0GTrYZ.js} +1 -1
- package/dist/client-DkwOxEiT.js +707 -0
- package/dist/{cloudflare-nF4abPd4.js → cloudflare-BHfClPvT.js} +2 -2
- package/dist/{cloudflare-env-BNrYo29x.js → cloudflare-env-CGLx7lUd.js} +44 -42
- package/dist/cloudflare-env-lookup-CfX6wZKb.d.ts +4 -0
- package/dist/{cloudflare-env-CIjdFTv6.d.ts → cloudflare-shared-CTqh_a2s.d.ts} +2 -2
- package/dist/{config-IJMb0eeZ.js → config-C3DvtjfJ.js} +41 -40
- package/dist/definition.d.ts +18 -0
- package/dist/definition.js +33 -0
- package/dist/delay-D1-nq_VE.js +46 -0
- package/dist/dev-recorder-CTN5Fkao.js +10 -0
- package/dist/durability.d.ts +23 -0
- package/dist/durability.js +62 -0
- package/dist/error-diagnostics-0V2T3JFw.js +317 -0
- package/dist/error-diagnostics-CQ4BUqRe.js +270 -0
- package/dist/errors-DCqRnZpN.js +35 -0
- package/dist/errors-uhP8DZTi.d.ts +67 -0
- package/dist/index.d.ts +35 -63
- package/dist/index.js +15 -19
- package/dist/object-Da1zyPCR.js +11 -0
- package/dist/openworkflow-BhzxV_Y3.d.ts +52 -0
- package/dist/openworkflow-defaults-DDig2M4s.js +26 -0
- package/dist/openworkflow-storage-Dj9zUAsk.js +28 -0
- package/dist/openworkflow.d.ts +2 -0
- package/dist/openworkflow.js +2 -0
- package/dist/{operations-tNUdj3G4.d.ts → operation-definition-nmRu_O3V.d.ts} +42 -15
- package/dist/operations-D_WJwjrS.js +333 -0
- package/dist/operations.d.ts +40 -6
- package/dist/operations.js +163 -736
- package/dist/{out-CsaJxg8m.js → out-DxLKolA0.js} +32 -1430
- package/dist/{rolldown-runtime-CMFfr-1z.js → rolldown-runtime-B4iAMlE-.js} +10 -1
- package/dist/run-error-DBWqiJHH.js +110 -0
- package/dist/run-failed-gVGo1BaF.js +18 -0
- package/dist/runtime/cloudflare-runner.d.ts +3 -5
- package/dist/runtime/cloudflare-runner.js +39 -45
- package/dist/runtime/cloudflare-shared.d.ts +2 -2
- package/dist/runtime/cloudflare-shared.js +1 -1
- package/dist/runtime/cloudflare-vite.d.ts +3 -2
- package/dist/runtime/cloudflare-vite.js +47 -1
- package/dist/runtime/dev-runs.d.ts +4 -0
- package/dist/runtime/dev-runs.js +73 -0
- package/dist/runtime/execute.d.ts +42 -5
- package/dist/runtime/execute.js +216 -17
- package/dist/runtime/openworkflow-worker.d.ts +29 -2
- package/dist/runtime/openworkflow-worker.js +156 -38
- package/dist/runtime/openworkflow.d.ts +2 -21
- package/dist/runtime/openworkflow.js +307 -44
- package/dist/runtime/state.d.ts +3 -1
- package/dist/runtime/state.js +6 -6
- package/dist/runtime/vercel-vite.d.ts +1 -1
- package/dist/runtime/vercel-vite.js +7 -4
- package/dist/types-Dsmwsdlv.d.ts +282 -0
- package/dist/{vercel-D-ZNtB_u.js → vercel-DTvm61iY.js} +53 -24
- package/dist/vite.d.ts +228 -30
- package/dist/vite.js +2640 -1449
- package/package.json +28 -50
- package/dist/client-DsGM3M4U.js +0 -389
- package/dist/cloudflare-shared-CaxrMD1A.d.ts +0 -1
- package/dist/cloudflare-vite-B3IabBsv.js +0 -47
- package/dist/error-diagnostics-A_8Kp-48.js +0 -116
- package/dist/error-diagnostics-pwNFvAHP.js +0 -67
- package/dist/operations-B_rYG71W.js +0 -230
- package/dist/provider-operation-CW2cYfVy.js +0 -65
- package/dist/runtime-type-DBCvIh5x.js +0 -7
- package/dist/types-D82WmfZa.d.ts +0 -180
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
import { t as isRecord } from "./object-Da1zyPCR.js";
|
|
2
|
+
import { t as workflowErrorDiagnostics } from "./error-diagnostics-0V2T3JFw.js";
|
|
3
|
+
import { a as resumeWorkflow, i as getWorkflowRun, o as startWorkflow, t as cancelWorkflow } from "./client-DkwOxEiT.js";
|
|
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
|
+
import { getInlineWorkflowDefinitions, getWorkflowRuntimeConfig, getWorkflowRuntimeRegistry } from "./runtime/state.js";
|
|
8
|
+
import { deserializeResponse, isSerializedResponse } from "@vite-hub/runtime";
|
|
9
|
+
//#region src/results.ts
|
|
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
|
+
/**
|
|
18
|
+
* Operations that each provider supports. A supported operation can still fail when the runtime decides, for example
|
|
19
|
+
* cancel on an inline Vercel run.
|
|
20
|
+
*/
|
|
21
|
+
function resolveWorkflowOperationSupport(provider) {
|
|
22
|
+
if (provider === "cloudflare") return {
|
|
23
|
+
cancel: {
|
|
24
|
+
note: "Terminates a queued, running, waiting, or paused run through the Cloudflare Workflow binding. A finished run keeps its status. Inline runs return an unsupported error.",
|
|
25
|
+
supported: true
|
|
26
|
+
},
|
|
27
|
+
get: {
|
|
28
|
+
note: "Reads the run from the Cloudflare Workflow binding when the runtime has one.",
|
|
29
|
+
supported: true
|
|
30
|
+
},
|
|
31
|
+
resume: unsupported("Cloudflare Workflows do not support ViteHub signals."),
|
|
32
|
+
start: {
|
|
33
|
+
note: `Uses the Cloudflare Workflow binding when the runtime has one. Otherwise: ${inlineRunNote}`,
|
|
34
|
+
supported: true
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
if (provider === "openworkflow") return {
|
|
38
|
+
cancel: {
|
|
39
|
+
note: "Cancels a pending or running run in OpenWorkflow storage. A step that is already running finishes, but its worker records no further steps or result.",
|
|
40
|
+
supported: true
|
|
41
|
+
},
|
|
42
|
+
get: {
|
|
43
|
+
note: "Reads the run from OpenWorkflow storage.",
|
|
44
|
+
supported: true
|
|
45
|
+
},
|
|
46
|
+
resume: unsupported("OpenWorkflow does not support ViteHub signals."),
|
|
47
|
+
start: {
|
|
48
|
+
note: "Enqueues the run in OpenWorkflow storage. The run stays queued until an OpenWorkflow worker processes the same storage.",
|
|
49
|
+
supported: true
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
return {
|
|
53
|
+
cancel: {
|
|
54
|
+
note: "Only native Vercel Workflow runs can be cancelled. Inline runs return an unsupported error.",
|
|
55
|
+
supported: true
|
|
56
|
+
},
|
|
57
|
+
get: {
|
|
58
|
+
note: "Reads inline runs, which expire 5 minutes after they finish. Native Vercel Workflow runs need the Workflow DevKit runtime.",
|
|
59
|
+
supported: true
|
|
60
|
+
},
|
|
61
|
+
resume: {
|
|
62
|
+
note: "Signals need a native Vercel Workflow run and the Workflow DevKit runtime.",
|
|
63
|
+
supported: true
|
|
64
|
+
},
|
|
65
|
+
start: {
|
|
66
|
+
note: `${inlineRunNote} Native Vercel Workflow Definitions need the Workflow DevKit runtime.`,
|
|
67
|
+
supported: true
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/runtime/operations.ts
|
|
73
|
+
const maxRememberedRuns = 1024;
|
|
74
|
+
/** The HTTP status that the CLI, the Console, and Agents report for each code of a failed operation. */
|
|
75
|
+
const operationStatus = {
|
|
76
|
+
VERCEL_WORKFLOW_SDK_LOAD_FAILED: 501,
|
|
77
|
+
WORKFLOW_DEFINITION_NOT_FOUND: 404,
|
|
78
|
+
WORKFLOW_DISABLED: 409,
|
|
79
|
+
WORKFLOW_NATIVE_ENTRY_INVALID: 501,
|
|
80
|
+
WORKFLOW_NATIVE_ENTRY_REQUIRED: 501,
|
|
81
|
+
WORKFLOW_OPERATION_FAILED: 500,
|
|
82
|
+
WORKFLOW_OPERATION_UNSUPPORTED: 501,
|
|
83
|
+
WORKFLOW_PROVIDER_OPERATION_FAILED: 502,
|
|
84
|
+
WORKFLOW_REGISTRY_MISSING: 409,
|
|
85
|
+
WORKFLOW_RUN_AMBIGUOUS: 400,
|
|
86
|
+
WORKFLOW_RUN_NOT_FOUND: 404,
|
|
87
|
+
WORKFLOW_RUN_UNKNOWN: 400,
|
|
88
|
+
WORKFLOW_RUNS_UNAVAILABLE: 409
|
|
89
|
+
};
|
|
90
|
+
/** Gives an operation error the status of its code and the redacted message that the CLI and the Console report. */
|
|
91
|
+
function failure(error, message = error.message) {
|
|
92
|
+
return Object.defineProperties(error, {
|
|
93
|
+
status: {
|
|
94
|
+
configurable: true,
|
|
95
|
+
enumerable: false,
|
|
96
|
+
value: operationStatus[errorCode(error) ?? ""] ?? 500,
|
|
97
|
+
writable: true
|
|
98
|
+
},
|
|
99
|
+
statusMessage: {
|
|
100
|
+
configurable: true,
|
|
101
|
+
enumerable: false,
|
|
102
|
+
value: redactInspectionText(message),
|
|
103
|
+
writable: true
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
function hasStatus(error) {
|
|
108
|
+
return error instanceof Error && typeof Reflect.get(error, "status") === "number" && typeof Reflect.get(error, "code") === "string";
|
|
109
|
+
}
|
|
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
|
+
function isResponse$1(value) {
|
|
116
|
+
if (typeof value !== "object" || value === null) return false;
|
|
117
|
+
const response = value;
|
|
118
|
+
return typeof response.status === "number" && typeof response.headers?.get === "function" && typeof response.bodyUsed === "boolean" && typeof response.clone === "function" && typeof response.text === "function";
|
|
119
|
+
}
|
|
120
|
+
function jsonReplacer(_key, value) {
|
|
121
|
+
if (typeof value === "bigint") return value.toString();
|
|
122
|
+
if (value instanceof Error) return serializeError(value);
|
|
123
|
+
if (isResponse$1(value)) return { response: {
|
|
124
|
+
status: value.status,
|
|
125
|
+
statusText: value.statusText
|
|
126
|
+
} };
|
|
127
|
+
return value;
|
|
128
|
+
}
|
|
129
|
+
function toJsonValue(value) {
|
|
130
|
+
if (value === void 0) return void 0;
|
|
131
|
+
try {
|
|
132
|
+
const text = JSON.stringify(value, jsonReplacer);
|
|
133
|
+
return text === void 0 ? void 0 : redactInspectionValue(JSON.parse(text));
|
|
134
|
+
} catch {
|
|
135
|
+
return "[unserializable]";
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function errorCode(error) {
|
|
139
|
+
if (!error || typeof error !== "object") return;
|
|
140
|
+
const code = Reflect.get(error, "code");
|
|
141
|
+
return typeof code === "string" ? code : void 0;
|
|
142
|
+
}
|
|
143
|
+
function serializeError(error) {
|
|
144
|
+
const code = errorCode(error);
|
|
145
|
+
return {
|
|
146
|
+
...code ? { code } : {},
|
|
147
|
+
message: redactInspectionText(error.message),
|
|
148
|
+
...error.name && error.name !== "Error" ? { name: error.name } : {}
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
function toIsoDate(value) {
|
|
152
|
+
if (value instanceof Date) return Number.isNaN(value.getTime()) ? void 0 : value.toISOString();
|
|
153
|
+
return typeof value === "string" ? value : void 0;
|
|
154
|
+
}
|
|
155
|
+
function isErrorLike(value) {
|
|
156
|
+
return value instanceof Error || isRecord(value) && typeof value.message === "string";
|
|
157
|
+
}
|
|
158
|
+
async function readResult(result) {
|
|
159
|
+
if (!isResponse$1(result)) return result;
|
|
160
|
+
const text = await result.clone().text();
|
|
161
|
+
if (!text) return void 0;
|
|
162
|
+
try {
|
|
163
|
+
return JSON.parse(text);
|
|
164
|
+
} catch {
|
|
165
|
+
return text;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Converts a runtime Workflow run to JSON data. The view omits the start
|
|
170
|
+
* payload and redacts credentials in the metadata, result, and error message.
|
|
171
|
+
*/
|
|
172
|
+
async function toWorkflowRunView(run, workflow) {
|
|
173
|
+
const createdAt = toIsoDate(run.createdAt);
|
|
174
|
+
const startedAt = toIsoDate(run.startedAt);
|
|
175
|
+
const completedAt = toIsoDate(run.completedAt);
|
|
176
|
+
const error = run.error ? {
|
|
177
|
+
...run.error,
|
|
178
|
+
message: redactInspectionText(run.error.message)
|
|
179
|
+
} : void 0;
|
|
180
|
+
const metadata = toJsonValue(run.metadata);
|
|
181
|
+
const result = toJsonValue(await readResult(run.result));
|
|
182
|
+
return {
|
|
183
|
+
...completedAt ? { completedAt } : {},
|
|
184
|
+
...createdAt ? { createdAt } : {},
|
|
185
|
+
...error ? { error } : {},
|
|
186
|
+
id: run.id,
|
|
187
|
+
...metadata === void 0 ? {} : { metadata },
|
|
188
|
+
provider: run.provider,
|
|
189
|
+
...result === void 0 ? {} : { result },
|
|
190
|
+
...startedAt ? { startedAt } : {},
|
|
191
|
+
status: run.status,
|
|
192
|
+
workflow
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
function runtimeFailure(operation, provider, error) {
|
|
196
|
+
if (hasStatus(error)) return error;
|
|
197
|
+
const code = errorCode(error);
|
|
198
|
+
if (code === "WORKFLOW_OPERATION_UNSUPPORTED") return failure(workflowErrorDiagnostics.WORKFLOW_OPERATION_UNSUPPORTED({
|
|
199
|
+
cause: error,
|
|
200
|
+
operation,
|
|
201
|
+
provider
|
|
202
|
+
}));
|
|
203
|
+
if (code === "WORKFLOW_DISABLED") return failure(workflowErrorDiagnostics.WORKFLOW_DISABLED({ cause: error }));
|
|
204
|
+
if (code === "WORKFLOW_DEFINITION_NOT_FOUND") return failure(workflowErrorDiagnostics.WORKFLOW_DEFINITION_NOT_FOUND({ cause: error }));
|
|
205
|
+
if (error instanceof Error && (code === "VERCEL_WORKFLOW_SDK_LOAD_FAILED" || code === "WORKFLOW_NATIVE_ENTRY_INVALID" || code === "WORKFLOW_NATIVE_ENTRY_REQUIRED")) return failure(error, `workflow ${operation} needs the Vercel Workflow DevKit runtime, which the runtime could not load.`);
|
|
206
|
+
if (error instanceof Error && code === "WORKFLOW_PROVIDER_OPERATION_FAILED") return failure(error, `workflow ${operation} failed in the ${provider} provider.${error.cause instanceof Error && error.cause.message ? ` ${error.cause.message}` : ""}`);
|
|
207
|
+
if (error instanceof Error && code) return failure(error);
|
|
208
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
209
|
+
return failure(workflowErrorDiagnostics.WORKFLOW_OPERATION_FAILED({ cause: error }), message || "The Workflow operation failed.");
|
|
210
|
+
}
|
|
211
|
+
function startableWorkflows() {
|
|
212
|
+
return [.../* @__PURE__ */ new Set([...Object.keys(getWorkflowRuntimeRegistry() ?? {}), ...getInlineWorkflowDefinitions().keys()])].sort();
|
|
213
|
+
}
|
|
214
|
+
const startedRuns = /* @__PURE__ */ new Map();
|
|
215
|
+
function rememberRun(id, workflow) {
|
|
216
|
+
startedRuns.delete(id);
|
|
217
|
+
startedRuns.set(id, workflow);
|
|
218
|
+
if (startedRuns.size > maxRememberedRuns) {
|
|
219
|
+
const oldest = startedRuns.keys().next().value;
|
|
220
|
+
if (oldest !== void 0) startedRuns.delete(oldest);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Runs one Workflow operation in the runtime of the app, so it uses the same Workflow state and registry as the app.
|
|
225
|
+
* It redacts credentials in run data and error messages. Failures are catalog errors with an HTTP `status`.
|
|
226
|
+
*/
|
|
227
|
+
async function runWorkflowOperation(operation, input) {
|
|
228
|
+
const runtimeConfig = getWorkflowRuntimeConfig();
|
|
229
|
+
if (runtimeConfig === false) throw failure(workflowErrorDiagnostics.WORKFLOW_DISABLED());
|
|
230
|
+
const provider = runtimeConfig?.driver ?? "vercel";
|
|
231
|
+
const support = resolveWorkflowOperationSupport(provider)[operation];
|
|
232
|
+
if (!support.supported) throw failure(workflowErrorDiagnostics.WORKFLOW_OPERATION_UNSUPPORTED({
|
|
233
|
+
note: support.note,
|
|
234
|
+
operation,
|
|
235
|
+
provider
|
|
236
|
+
}));
|
|
237
|
+
try {
|
|
238
|
+
return await run(operation, input);
|
|
239
|
+
} catch (error) {
|
|
240
|
+
throw runtimeFailure(operation, provider, error);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
async function run(operation, input) {
|
|
244
|
+
if (operation === "start") {
|
|
245
|
+
const { payload, workflow } = input;
|
|
246
|
+
const workflows = startableWorkflows();
|
|
247
|
+
if (!workflows.includes(workflow)) {
|
|
248
|
+
if (!getWorkflowRuntimeRegistry()) throw failure(workflowErrorDiagnostics.WORKFLOW_REGISTRY_MISSING({ workflow }));
|
|
249
|
+
const available = workflows.length ? ` Available Workflows: ${workflows.join(", ")}.` : " The Workflow registry of the runtime is empty.";
|
|
250
|
+
throw failure(workflowErrorDiagnostics.WORKFLOW_DEFINITION_NOT_FOUND({
|
|
251
|
+
available,
|
|
252
|
+
workflow
|
|
253
|
+
}));
|
|
254
|
+
}
|
|
255
|
+
const [error, started] = await startWorkflow(workflow, payload);
|
|
256
|
+
if (error) throw error;
|
|
257
|
+
rememberRun(started.id, workflow);
|
|
258
|
+
return { run: await toWorkflowRunView(started, workflow) };
|
|
259
|
+
}
|
|
260
|
+
if (operation === "resume") {
|
|
261
|
+
const { payload, token } = input;
|
|
262
|
+
const [error, signal] = await resumeWorkflow(token, payload);
|
|
263
|
+
if (error) throw error;
|
|
264
|
+
return { signal: {
|
|
265
|
+
id: signal.id,
|
|
266
|
+
provider: signal.provider
|
|
267
|
+
} };
|
|
268
|
+
}
|
|
269
|
+
const { runId, workflow: named } = input;
|
|
270
|
+
const workflow = named ?? startedRuns.get(runId);
|
|
271
|
+
if (!workflow) throw failure(workflowErrorDiagnostics.WORKFLOW_RUN_UNKNOWN({ runId }));
|
|
272
|
+
const [error, found] = operation === "get" ? await getWorkflowRun(workflow, runId) : await cancelWorkflow(workflow, runId);
|
|
273
|
+
if (error) throw error;
|
|
274
|
+
return { run: await toWorkflowRunView(found, workflow) };
|
|
275
|
+
}
|
|
276
|
+
/** The run history of `vite dev`. Hosted providers keep their own history, which ViteHub does not list. */
|
|
277
|
+
function devRecorder() {
|
|
278
|
+
if (getWorkflowRuntimeConfig() === false) throw failure(workflowErrorDiagnostics.WORKFLOW_DISABLED());
|
|
279
|
+
const recorder = getWorkflowDevRecorder();
|
|
280
|
+
if (!recorder) throw failure(workflowErrorDiagnostics.WORKFLOW_RUNS_UNAVAILABLE());
|
|
281
|
+
return recorder;
|
|
282
|
+
}
|
|
283
|
+
function devRunView(record) {
|
|
284
|
+
return {
|
|
285
|
+
...record.completedAt ? { completedAt: record.completedAt } : {},
|
|
286
|
+
createdAt: record.createdAt,
|
|
287
|
+
id: record.id,
|
|
288
|
+
...record.status === "failed" ? { error: toWorkflowRunError(record.error) } : {},
|
|
289
|
+
provider: record.provider,
|
|
290
|
+
...record.status === "completed" ? { result: isSerializedResponse(record.result) ? deserializeResponse(record.result) : record.result } : {},
|
|
291
|
+
...record.startedAt ? { startedAt: record.startedAt } : {},
|
|
292
|
+
status: record.status
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
function stepView(step) {
|
|
296
|
+
const output = step.status === "completed" ? toJsonValue(step.output) : void 0;
|
|
297
|
+
return {
|
|
298
|
+
...step.completedAt ? { completedAt: step.completedAt.toISOString() } : {},
|
|
299
|
+
...step.status === "failed" ? { error: isErrorLike(step.error) ? serializeError(step.error) : { message: redactInspectionText(String(step.error)) } } : {},
|
|
300
|
+
name: step.name,
|
|
301
|
+
...output === void 0 ? {} : { output },
|
|
302
|
+
startedAt: step.startedAt.toISOString(),
|
|
303
|
+
status: step.status
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
/** Lists the runs that `vite dev` recorded, newest first. */
|
|
307
|
+
async function listWorkflowRuns(input) {
|
|
308
|
+
const records = devRecorder().list().filter((record) => (input.workflow === void 0 || record.workflow === input.workflow) && (input.status === void 0 || record.status === input.status)).slice(0, input.limit ?? 200);
|
|
309
|
+
return { runs: await Promise.all(records.map(async (record) => ({
|
|
310
|
+
...await toWorkflowRunView(devRunView(record), record.workflow),
|
|
311
|
+
stepCount: record.steps.length
|
|
312
|
+
}))) };
|
|
313
|
+
}
|
|
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
|
+
/** Removes the runs that `vite dev` recorded. A run that is still active finishes but is not listed again. */
|
|
329
|
+
function clearWorkflowRuns() {
|
|
330
|
+
return { cleared: devRecorder().clear() };
|
|
331
|
+
}
|
|
332
|
+
//#endregion
|
|
333
|
+
export { clearWorkflowRuns, listWorkflowRuns, runWorkflowOperation, showWorkflowRun, toWorkflowRunView };
|
package/dist/operations.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as AnyOperation } from "./
|
|
1
|
+
import { M as WorkflowRunStatus, h as WorkflowDriver } from "./types-Dsmwsdlv.js";
|
|
2
|
+
import { t as AnyOperation } from "./operation-definition-nmRu_O3V.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 {
|
|
@@ -12,7 +12,7 @@ interface WorkflowRunView {
|
|
|
12
12
|
};
|
|
13
13
|
id: string;
|
|
14
14
|
metadata?: unknown;
|
|
15
|
-
provider:
|
|
15
|
+
provider: WorkflowDriver;
|
|
16
16
|
result?: unknown;
|
|
17
17
|
startedAt?: string;
|
|
18
18
|
status: WorkflowRunStatus;
|
|
@@ -21,17 +21,51 @@ interface WorkflowRunView {
|
|
|
21
21
|
/** The signal that `workflow.resume` delivered. */
|
|
22
22
|
interface WorkflowSignalView {
|
|
23
23
|
id: string;
|
|
24
|
-
provider:
|
|
24
|
+
provider: WorkflowDriver;
|
|
25
25
|
}
|
|
26
26
|
interface WorkflowRunResult {
|
|
27
27
|
run: WorkflowRunView;
|
|
28
28
|
}
|
|
29
|
+
/** One step of a run that `vite dev` recorded. */
|
|
30
|
+
interface WorkflowRunStepView {
|
|
31
|
+
completedAt?: string;
|
|
32
|
+
error?: {
|
|
33
|
+
code?: string;
|
|
34
|
+
message: string;
|
|
35
|
+
name?: string;
|
|
36
|
+
};
|
|
37
|
+
name: string;
|
|
38
|
+
output?: unknown;
|
|
39
|
+
startedAt: string;
|
|
40
|
+
status: "completed" | "failed" | "running";
|
|
41
|
+
}
|
|
42
|
+
/** A run that `vite dev` recorded, with its steps. */
|
|
43
|
+
interface WorkflowRunDetailView extends WorkflowRunView {
|
|
44
|
+
steps: WorkflowRunStepView[];
|
|
45
|
+
}
|
|
46
|
+
/** Result of `workflow.runs-list`. The runs are newest first and have no steps. */
|
|
47
|
+
interface WorkflowRunsListResult {
|
|
48
|
+
runs: Array<WorkflowRunView & {
|
|
49
|
+
stepCount: number;
|
|
50
|
+
}>;
|
|
51
|
+
}
|
|
52
|
+
/** Result of `workflow.runs-clear`: the number of recorded runs that it removed. */
|
|
53
|
+
interface WorkflowRunsClearResult {
|
|
54
|
+
cleared: number;
|
|
55
|
+
}
|
|
56
|
+
/** Result of `workflow.runs-show`. */
|
|
57
|
+
interface WorkflowRunsShowResult {
|
|
58
|
+
run: WorkflowRunDetailView;
|
|
59
|
+
}
|
|
29
60
|
interface WorkflowSignalResult {
|
|
30
61
|
signal: WorkflowSignalView;
|
|
31
62
|
}
|
|
32
63
|
//#endregion
|
|
33
64
|
//#region src/operations.d.ts
|
|
34
|
-
/**
|
|
65
|
+
/**
|
|
66
|
+
* The `workflow.*` operations: start, get, cancel, resume, and the run history of `vite dev`. The Console,
|
|
67
|
+
* `vitehub workflow`, and agents run them.
|
|
68
|
+
*/
|
|
35
69
|
export declare const workflowOperations: readonly AnyOperation[];
|
|
36
70
|
//#endregion
|
|
37
|
-
export type { WorkflowRunResult, WorkflowRunView, WorkflowSignalResult, WorkflowSignalView };
|
|
71
|
+
export type { WorkflowRunDetailView, WorkflowRunResult, WorkflowRunStepView, WorkflowRunView, WorkflowRunsClearResult, WorkflowRunsListResult, WorkflowRunsShowResult, WorkflowSignalResult, WorkflowSignalView };
|