@vite-hub/workflow 0.6.1 → 0.8.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 +33 -9
- package/dist/{app-DXUHElAz.js → app-Cpa9qCXr.js} +1 -1
- package/dist/{client-CbBg4HlH.js → client-T41cNf3k.js} +41 -52
- package/dist/cloudflare-concurrency-counter-CDHHiMfn.js +136 -0
- package/dist/{config-CizNRTMi.js → config-G0z9jHLM.js} +6 -6
- package/dist/definition.d.ts +1 -1
- package/dist/definition.js +4 -1
- package/dist/{delay-CtT3442d.js → delay-B4azP18B.js} +7 -5
- package/dist/durability.d.ts +3 -1
- package/dist/durability.js +7 -1
- package/dist/{error-diagnostics--2cV_ER1.js → error-diagnostics-35AEmfve.js} +25 -5
- package/dist/{error-diagnostics-kKXseq8d.js → error-diagnostics-CsiNo_oI.js} +3 -3
- package/dist/{errors-CJZuvOcx.d.ts → errors-DwKy5MQ8.d.ts} +1 -1
- package/dist/execute-zu08sWGG.js +353 -0
- package/dist/index.d.ts +12 -10
- package/dist/index.js +3 -3
- package/dist/{openworkflow-defaults-DfQWtSRU.js → invariant-Dj2R1eMr.js} +1 -4
- package/dist/{openworkflow-CdKbUGGa.d.ts → openworkflow-DHuxMJQB.d.ts} +23 -4
- package/dist/openworkflow-defaults-1n0DbLdb.js +4 -0
- package/dist/openworkflow-zD8luED5.js +749 -0
- package/dist/{operation-definition-CqZkx1Rm.d.ts → operations-Blwi3jQF.d.ts} +1 -0
- package/dist/{operations-BBTmDm2H.js → operations-C2XbDDDV.js} +71 -15
- package/dist/operations.d.ts +3 -59
- package/dist/operations.js +5 -5
- package/dist/results-DqbEUMCH.d.ts +60 -0
- package/dist/{run-error-8p4BtTMv.js → run-error-zZh1_IBo.js} +5 -21
- package/dist/runtime/cloudflare-concurrency.d.ts +21 -0
- package/dist/runtime/cloudflare-concurrency.js +21 -0
- package/dist/runtime/cloudflare-runner.d.ts +1 -1
- package/dist/runtime/cloudflare-runner.js +7 -3
- package/dist/runtime/cloudflare-vite.d.ts +1 -1
- package/dist/runtime/cloudflare-vite.js +2 -2
- package/dist/runtime/execute.d.ts +8 -2
- package/dist/runtime/execute.js +1 -278
- package/dist/runtime/openworkflow-worker.d.ts +2 -2
- package/dist/runtime/openworkflow-worker.js +5 -6
- package/dist/runtime/openworkflow.d.ts +2 -2
- package/dist/runtime/openworkflow.js +1 -481
- package/dist/runtime/state.d.ts +1 -1
- package/dist/runtime/state.js +2 -2
- package/dist/runtime/vercel-vite.d.ts +1 -1
- package/dist/runtime/vercel-vite.js +2 -2
- package/dist/{signals-BHQdxoJo.js → signals-CdaxRNjN.js} +1 -1
- package/dist/{types-DvYcvbPG.d.ts → types-DrhUXMsE.d.ts} +34 -4
- package/dist/{vercel-Cw_Z9-j4.js → vercel-DRezYOUp.js} +8 -6
- package/dist/vite.d.ts +19 -4
- package/dist/vite.js +970 -212
- package/package.json +3 -3
- package/dist/cloudflare-Sgywkm1N.js +0 -57
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { n as redactInspectionValue, t as redactInspectionText } from "./inspect-NBCAwsxi.js";
|
|
2
2
|
import { t as isRecord } from "./object-CAK6UYR5.js";
|
|
3
|
-
import { t as workflowErrorDiagnostics } from "./error-diagnostics
|
|
4
|
-
import { a as resumeWorkflow, i as getWorkflowRun, o as startWorkflow, t as cancelWorkflow } from "./client-
|
|
3
|
+
import { t as workflowErrorDiagnostics } from "./error-diagnostics-35AEmfve.js";
|
|
4
|
+
import { a as resumeWorkflow, i as getWorkflowRun, o as startWorkflow, t as cancelWorkflow } from "./client-T41cNf3k.js";
|
|
5
5
|
import { t as getWorkflowDevRecorder } from "./dev-recorder-Dltdmlkv.js";
|
|
6
|
-
import { t as
|
|
6
|
+
import { a as getOpenWorkflowRun, i as findOpenWorkflowRuns, s as listOpenWorkflowRuns, t as cancelOpenWorkflowRun } from "./openworkflow-zD8luED5.js";
|
|
7
|
+
import { t as toWorkflowRunError } from "./run-error-zZh1_IBo.js";
|
|
7
8
|
import { getInlineWorkflowDefinitions, getWorkflowRuntimeConfig, getWorkflowRuntimeRegistry } from "./runtime/state.js";
|
|
9
|
+
import { getViteHubTestMode } from "@vite-hub/runtime/internal/test-mode";
|
|
8
10
|
import { deserializeResponse, isSerializedResponse } from "@vite-hub/runtime/internal/response";
|
|
9
11
|
// src/results.ts
|
|
10
12
|
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.";
|
|
@@ -260,18 +262,54 @@ async function run(operation, input) {
|
|
|
260
262
|
} };
|
|
261
263
|
}
|
|
262
264
|
const { runId, workflow: named } = input;
|
|
263
|
-
const
|
|
264
|
-
if (
|
|
265
|
+
const config = getWorkflowRuntimeConfig();
|
|
266
|
+
if (config && config.driver === "openworkflow" && !getViteHubTestMode()) return await inspectOpenWorkflowRun(config, operation, runId, named);
|
|
267
|
+
if (operation === "get") {
|
|
268
|
+
const recorded = inlineRunMatches(runId, named);
|
|
269
|
+
requireUnambiguousRun(runId, recorded);
|
|
270
|
+
const [record] = recorded;
|
|
271
|
+
if (record) return await inspectRecordedRun(record);
|
|
272
|
+
}
|
|
273
|
+
return await inspectRuntimeRun(operation, runId, named, false);
|
|
274
|
+
}
|
|
275
|
+
function inlineRunMatches(runId, name) {
|
|
276
|
+
return getWorkflowDevRecorder()?.list().filter((record) => record.id === runId && (name === void 0 || record.workflow === name)) ?? [];
|
|
277
|
+
}
|
|
278
|
+
function requireUnambiguousRun(runId, matches) {
|
|
279
|
+
if (matches.length > 1) throw failure(workflowErrorDiagnostics.WORKFLOW_RUN_AMBIGUOUS({
|
|
265
280
|
id: runId,
|
|
266
|
-
workflows:
|
|
281
|
+
workflows: matches.map((match) => match.workflow).join(", ")
|
|
267
282
|
}));
|
|
268
|
-
|
|
269
|
-
|
|
283
|
+
}
|
|
284
|
+
async function inspectRecordedRun(record) {
|
|
285
|
+
return { run: {
|
|
270
286
|
...await toWorkflowRunView(devRunView(record), record.workflow),
|
|
271
287
|
steps: record.steps.map(stepView)
|
|
272
288
|
} };
|
|
273
|
-
|
|
274
|
-
|
|
289
|
+
}
|
|
290
|
+
async function inspectOpenWorkflowRun(config, operation, runId, name) {
|
|
291
|
+
const stored = await findOpenWorkflowRuns(config, runId, name);
|
|
292
|
+
const recorded = inlineRunMatches(runId, name);
|
|
293
|
+
requireUnambiguousRun(runId, [...stored, ...recorded]);
|
|
294
|
+
const [run] = stored;
|
|
295
|
+
if (run) return { run: await toWorkflowRunView(await (operation === "get" ? getOpenWorkflowRun : cancelOpenWorkflowRun)(config, run.workflow, run.id, "provider-id"), run.workflow) };
|
|
296
|
+
const [record] = recorded;
|
|
297
|
+
if (record) {
|
|
298
|
+
if (operation === "get") return await inspectRecordedRun(record);
|
|
299
|
+
throw failure(workflowErrorDiagnostics.WORKFLOW_OPERATION_UNSUPPORTED({
|
|
300
|
+
operation: "cancellation",
|
|
301
|
+
provider: "openworkflow"
|
|
302
|
+
}));
|
|
303
|
+
}
|
|
304
|
+
return await inspectRuntimeRun(operation, runId, name, true);
|
|
305
|
+
}
|
|
306
|
+
async function inspectRuntimeRun(operation, runId, name, stored) {
|
|
307
|
+
const workflow = name ?? startedRuns.get(runId);
|
|
308
|
+
if (!workflow) throw failure(workflowErrorDiagnostics.WORKFLOW_RUN_UNKNOWN({
|
|
309
|
+
operation,
|
|
310
|
+
runId,
|
|
311
|
+
stored
|
|
312
|
+
}));
|
|
275
313
|
const [error, found] = operation === "get" ? await getWorkflowRun(workflow, runId) : await cancelWorkflow(workflow, runId);
|
|
276
314
|
if (error) throw error;
|
|
277
315
|
return { run: await toWorkflowRunView(found, workflow) };
|
|
@@ -305,13 +343,31 @@ function stepView(step) {
|
|
|
305
343
|
status: step.status
|
|
306
344
|
};
|
|
307
345
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
return { runs: await Promise.all(records.map(async (record) => ({
|
|
346
|
+
async function recordedRunViews(recorder, input, limit) {
|
|
347
|
+
const records = recorder.list().filter((record) => (input.workflow === void 0 || record.workflow === input.workflow) && (input.status === void 0 || record.status === input.status)).slice(0, limit);
|
|
348
|
+
return await Promise.all(records.map(async (record) => ({
|
|
312
349
|
...await toWorkflowRunView(devRunView(record), record.workflow),
|
|
313
350
|
stepCount: record.steps.length
|
|
314
|
-
})))
|
|
351
|
+
})));
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Lists Workflow runs, newest first: the runs that OpenWorkflow stores, and the inline runs that `vite dev` recorded.
|
|
355
|
+
* Other providers keep no history that ViteHub can read, so only `vite dev` lists their inline runs.
|
|
356
|
+
*/
|
|
357
|
+
async function listWorkflowRuns(input) {
|
|
358
|
+
const config = getWorkflowRuntimeConfig();
|
|
359
|
+
const limit = input.limit ?? 200;
|
|
360
|
+
if (!config || config.driver !== "openworkflow") return { runs: await recordedRunViews(devRecorder(), input, limit) };
|
|
361
|
+
const recorder = getWorkflowDevRecorder();
|
|
362
|
+
const [stored, recorded] = await Promise.all([listOpenWorkflowRuns(config, {
|
|
363
|
+
limit,
|
|
364
|
+
...input.status ? { status: input.status } : {},
|
|
365
|
+
...input.workflow ? { workflow: input.workflow } : {}
|
|
366
|
+
}), recorder ? recordedRunViews(recorder, input, limit) : []]);
|
|
367
|
+
return { runs: [...await Promise.all(stored.map(async ({ run, stepCount, workflow }) => ({
|
|
368
|
+
...await toWorkflowRunView(run, workflow),
|
|
369
|
+
stepCount
|
|
370
|
+
}))), ...recorded].sort((left, right) => (right.createdAt ?? "").localeCompare(left.createdAt ?? "")).slice(0, limit) };
|
|
315
371
|
}
|
|
316
372
|
/** Removes the runs that `vite dev` recorded. A run that is still active finishes but is not listed again. */
|
|
317
373
|
function clearWorkflowRuns() {
|
package/dist/operations.d.ts
CHANGED
|
@@ -1,64 +1,8 @@
|
|
|
1
|
-
import { t as AnyOperation } from "./
|
|
2
|
-
import {
|
|
3
|
-
/** One Workflow run as the operations return it. The start payload is not included. */
|
|
4
|
-
interface WorkflowRunView {
|
|
5
|
-
completedAt?: string;
|
|
6
|
-
createdAt?: string;
|
|
7
|
-
error?: {
|
|
8
|
-
code?: string;
|
|
9
|
-
message: string;
|
|
10
|
-
name?: string;
|
|
11
|
-
};
|
|
12
|
-
id: string;
|
|
13
|
-
metadata?: unknown;
|
|
14
|
-
provider: WorkflowDriver;
|
|
15
|
-
result?: unknown;
|
|
16
|
-
startedAt?: string;
|
|
17
|
-
status: WorkflowRunStatus;
|
|
18
|
-
workflow: string;
|
|
19
|
-
}
|
|
20
|
-
/** The signal that `workflow.resume` delivered. */
|
|
21
|
-
interface WorkflowSignalView {
|
|
22
|
-
id: string;
|
|
23
|
-
provider: WorkflowDriver;
|
|
24
|
-
}
|
|
25
|
-
interface WorkflowRunResult {
|
|
26
|
-
/** `workflow.get` adds the steps of a run that `vite dev` recorded. */
|
|
27
|
-
run: WorkflowRunView | WorkflowRunDetailView;
|
|
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
|
-
interface WorkflowSignalResult {
|
|
57
|
-
signal: WorkflowSignalView;
|
|
58
|
-
}
|
|
1
|
+
import { t as AnyOperation } from "./operations-Blwi3jQF.js";
|
|
2
|
+
import { a as WorkflowRunsClearResult, c as WorkflowSignalResult, i as WorkflowRunView, l as WorkflowSignalView, n as WorkflowRunResult, o as WorkflowRunsListResult, r as WorkflowRunStepView, s as WorkflowRunsListStatus, t as WorkflowRunDetailView } from "./results-DqbEUMCH.js";
|
|
59
3
|
/**
|
|
60
4
|
* The `workflow.*` operations: start, get, cancel, resume, and the run history of `vite dev`. The Console,
|
|
61
5
|
* `vitehub workflow`, and agents run them.
|
|
62
6
|
*/
|
|
63
7
|
export declare const workflowOperations: readonly AnyOperation[];
|
|
64
|
-
export type { WorkflowRunDetailView, WorkflowRunResult, WorkflowRunStepView, WorkflowRunView, WorkflowRunsClearResult, WorkflowRunsListResult, WorkflowSignalResult, WorkflowSignalView };
|
|
8
|
+
export type { WorkflowRunDetailView, WorkflowRunResult, WorkflowRunStepView, WorkflowRunView, WorkflowRunsClearResult, WorkflowRunsListResult, WorkflowRunsListStatus, WorkflowSignalResult, WorkflowSignalView };
|
package/dist/operations.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as isRecordOrFunction } from "./object-CAK6UYR5.js";
|
|
2
|
-
import { t as internalErrorDiagnostics } from "./error-diagnostics-
|
|
2
|
+
import { t as internalErrorDiagnostics } from "./error-diagnostics-CsiNo_oI.js";
|
|
3
3
|
import { toJsonSchema } from "@valibot/to-json-schema";
|
|
4
4
|
import * as v from "valibot";
|
|
5
5
|
// ../internal/src/standard-schema.ts
|
|
@@ -139,7 +139,7 @@ function table(rows) {
|
|
|
139
139
|
return rows.map((row) => row.map((cell, column) => column === row.length - 1 ? cell : cell.padEnd(widths[column])).join(" ")).join("\n");
|
|
140
140
|
}
|
|
141
141
|
// src/operations.ts
|
|
142
|
-
const runtime = () => import("./operations-
|
|
142
|
+
const runtime = () => import("./operations-C2XbDDDV.js");
|
|
143
143
|
const name = v.pipe(v.string(), v.check((value) => value.trim() !== "", "Name a Workflow."));
|
|
144
144
|
const runId = v.pipe(v.string(), v.check((value) => value.trim() !== "", "Pass the id of a run."));
|
|
145
145
|
const maxRequestBytes = 1048576;
|
|
@@ -173,7 +173,7 @@ const get = defineWorkflowOperation({
|
|
|
173
173
|
format: formatRun,
|
|
174
174
|
positional: ["runId"]
|
|
175
175
|
},
|
|
176
|
-
description: "Show the status and result of a Workflow run, with its steps when `vite dev` recorded it.
|
|
176
|
+
description: "Show the status and result of a Workflow run, with its steps when `vite dev` recorded it. OpenWorkflow finds the Workflow of a stored run from its id. On other providers, pass `workflow` for a run that this runtime did not start.",
|
|
177
177
|
input: v.object({
|
|
178
178
|
runId,
|
|
179
179
|
workflow: v.optional(name)
|
|
@@ -274,7 +274,7 @@ const workflowOperations = [
|
|
|
274
274
|
command: "runs list",
|
|
275
275
|
format: formatRuns
|
|
276
276
|
},
|
|
277
|
-
description: "List the
|
|
277
|
+
description: "List Workflow runs, newest first: the runs that OpenWorkflow stores, and the inline runs that `vite dev` recorded. Other providers outside `vite dev` fail with WORKFLOW_RUNS_UNAVAILABLE.",
|
|
278
278
|
input: v.strictObject({
|
|
279
279
|
limit: v.optional(v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(200))),
|
|
280
280
|
status: v.optional(v.picklist([
|
|
@@ -294,7 +294,7 @@ const workflowOperations = [
|
|
|
294
294
|
command: "runs clear",
|
|
295
295
|
format: ({ cleared }) => `Cleared ${cleared} ${cleared === 1 ? "run" : "runs"}.\n`
|
|
296
296
|
},
|
|
297
|
-
description: "Remove the Workflow runs that `vite dev` recorded.
|
|
297
|
+
description: "Remove the inline Workflow runs that `vite dev` recorded. Stored OpenWorkflow runs stay. Outside `vite dev` it fails with WORKFLOW_RUNS_UNAVAILABLE.",
|
|
298
298
|
input: v.strictObject({}),
|
|
299
299
|
kind: "destructive",
|
|
300
300
|
name: "workflow.runs-clear",
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { L as WorkflowRunStatus, v as WorkflowDriver } from "./types-DrhUXMsE.js";
|
|
2
|
+
/** One Workflow run as the operations return it. The start payload is not included. */
|
|
3
|
+
interface WorkflowRunView {
|
|
4
|
+
completedAt?: string;
|
|
5
|
+
createdAt?: string;
|
|
6
|
+
error?: {
|
|
7
|
+
code?: string;
|
|
8
|
+
message: string;
|
|
9
|
+
name?: string;
|
|
10
|
+
};
|
|
11
|
+
id: string;
|
|
12
|
+
metadata?: unknown;
|
|
13
|
+
provider: WorkflowDriver;
|
|
14
|
+
result?: unknown;
|
|
15
|
+
startedAt?: string;
|
|
16
|
+
status: WorkflowRunStatus;
|
|
17
|
+
workflow: string;
|
|
18
|
+
}
|
|
19
|
+
/** The signal that `workflow.resume` delivered. */
|
|
20
|
+
interface WorkflowSignalView {
|
|
21
|
+
id: string;
|
|
22
|
+
provider: WorkflowDriver;
|
|
23
|
+
}
|
|
24
|
+
interface WorkflowRunResult {
|
|
25
|
+
/** `workflow.get` adds the steps of a run that `vite dev` recorded. */
|
|
26
|
+
run: WorkflowRunView | WorkflowRunDetailView;
|
|
27
|
+
}
|
|
28
|
+
/** One step of a run that `vite dev` recorded. */
|
|
29
|
+
interface WorkflowRunStepView {
|
|
30
|
+
completedAt?: string;
|
|
31
|
+
error?: {
|
|
32
|
+
code?: string;
|
|
33
|
+
message: string;
|
|
34
|
+
name?: string;
|
|
35
|
+
};
|
|
36
|
+
name: string;
|
|
37
|
+
output?: unknown;
|
|
38
|
+
startedAt: string;
|
|
39
|
+
status: "completed" | "failed" | "running";
|
|
40
|
+
}
|
|
41
|
+
/** A run that `vite dev` recorded, with its steps. */
|
|
42
|
+
interface WorkflowRunDetailView extends WorkflowRunView {
|
|
43
|
+
steps: WorkflowRunStepView[];
|
|
44
|
+
}
|
|
45
|
+
/** The statuses that `workflow.runs-list` filters by. */
|
|
46
|
+
type WorkflowRunsListStatus = Extract<WorkflowRunStatus, "completed" | "failed" | "queued" | "running">;
|
|
47
|
+
/** Result of `workflow.runs-list`. The runs are newest first and have no steps. */
|
|
48
|
+
interface WorkflowRunsListResult {
|
|
49
|
+
runs: Array<WorkflowRunView & {
|
|
50
|
+
stepCount: number;
|
|
51
|
+
}>;
|
|
52
|
+
}
|
|
53
|
+
/** Result of `workflow.runs-clear`: the number of recorded runs that it removed. */
|
|
54
|
+
interface WorkflowRunsClearResult {
|
|
55
|
+
cleared: number;
|
|
56
|
+
}
|
|
57
|
+
interface WorkflowSignalResult {
|
|
58
|
+
signal: WorkflowSignalView;
|
|
59
|
+
}
|
|
60
|
+
export { WorkflowRunsClearResult as a, WorkflowSignalResult as c, WorkflowRunView as i, WorkflowSignalView as l, WorkflowRunResult as n, WorkflowRunsListResult as o, WorkflowRunStepView as r, WorkflowRunsListStatus as s, WorkflowRunDetailView as t };
|
|
@@ -6,22 +6,12 @@ import { getViteHubErrorShape } from "@vite-hub/runtime";
|
|
|
6
6
|
function isWorkflowBoundaryError(error) {
|
|
7
7
|
if (getViteHubErrorShape(error)) return true;
|
|
8
8
|
if (typeof error !== "object" || error === null) return false;
|
|
9
|
-
|
|
10
|
-
return "name" in error && error.name === "AbortError";
|
|
11
|
-
} catch {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
9
|
+
return "name" in error && error.name === "AbortError";
|
|
14
10
|
}
|
|
15
11
|
function getWorkflowProviderStatus(error) {
|
|
16
12
|
if (typeof error !== "object" || error === null) return void 0;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const response = typeof value.response === "object" && value.response !== null ? value.response : void 0;
|
|
20
|
-
const status = value.status ?? value.statusCode ?? response?.status;
|
|
21
|
-
return typeof status === "number" && Number.isInteger(status) && status >= 400 && status <= 599 ? status : void 0;
|
|
22
|
-
} catch {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
13
|
+
const status = ("status" in error ? error.status : void 0) ?? ("statusCode" in error ? error.statusCode : void 0) ?? ("response" in error && typeof error.response === "object" && error.response !== null && "status" in error.response ? error.response.status : void 0);
|
|
14
|
+
return typeof status === "number" && Number.isInteger(status) && status >= 400 && status <= 599 ? status : void 0;
|
|
25
15
|
}
|
|
26
16
|
const maxReasonLength = 200;
|
|
27
17
|
/**
|
|
@@ -30,14 +20,8 @@ const maxReasonLength = 200;
|
|
|
30
20
|
*/
|
|
31
21
|
function getWorkflowProviderReason(error) {
|
|
32
22
|
if (typeof error !== "object" || error === null) return void 0;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
try {
|
|
36
|
-
name = Reflect.get(error, "name");
|
|
37
|
-
message = Reflect.get(error, "message");
|
|
38
|
-
} catch {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
23
|
+
const name = "name" in error ? error.name : void 0;
|
|
24
|
+
const message = "message" in error ? error.message : void 0;
|
|
41
25
|
const firstLine = typeof message === "string" ? message.split(/\r?\n/, 1)[0].trim() : "";
|
|
42
26
|
const safeName = typeof name === "string" && /^[A-Za-z][\w$]{0,63}$/.test(name) ? name : void 0;
|
|
43
27
|
if (!firstLine) return safeName;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import "../types-DrhUXMsE.js";
|
|
2
|
+
import { DurableObject } from "cloudflare:workers";
|
|
3
|
+
interface CounterStorage {
|
|
4
|
+
get: (key: string) => Promise<unknown>;
|
|
5
|
+
put: (key: string, value: unknown) => Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
interface CounterState {
|
|
8
|
+
blockConcurrencyWhile: <T>(callback: () => Promise<T>) => Promise<T>;
|
|
9
|
+
storage: CounterStorage;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Counts the runs of one Workflow that sets `concurrency`. The Workflow build exports it from the Worker and binds it as
|
|
13
|
+
* `VITEHUB_WORKFLOW_CONCURRENCY`, with one instance for each Workflow name.
|
|
14
|
+
*/
|
|
15
|
+
export declare class ViteHubWorkflowConcurrency extends DurableObject<Record<string, unknown>> {
|
|
16
|
+
private readonly counter;
|
|
17
|
+
constructor(ctx: CounterState, env: Record<string, unknown>);
|
|
18
|
+
acquire(run: string, limit: number, binding: string): Promise<boolean>;
|
|
19
|
+
release(run: string): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { i as createCloudflareConcurrencyCounter } from "../cloudflare-concurrency-counter-CDHHiMfn.js";
|
|
2
|
+
import { DurableObject } from "cloudflare:workers";
|
|
3
|
+
// src/runtime/cloudflare-concurrency.ts
|
|
4
|
+
/**
|
|
5
|
+
* Counts the runs of one Workflow that sets `concurrency`. The Workflow build exports it from the Worker and binds it as
|
|
6
|
+
* `VITEHUB_WORKFLOW_CONCURRENCY`, with one instance for each Workflow name.
|
|
7
|
+
*/
|
|
8
|
+
var ViteHubWorkflowConcurrency = class extends DurableObject {
|
|
9
|
+
counter;
|
|
10
|
+
constructor(ctx, env) {
|
|
11
|
+
super(ctx, env);
|
|
12
|
+
this.counter = createCloudflareConcurrencyCounter(ctx, env);
|
|
13
|
+
}
|
|
14
|
+
async acquire(run, limit, binding) {
|
|
15
|
+
return await this.counter.acquire(run, limit, binding);
|
|
16
|
+
}
|
|
17
|
+
async release(run) {
|
|
18
|
+
await this.counter.release(run);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
export { ViteHubWorkflowConcurrency };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as CloudflareWorkerEnv } from "../cloudflare-env-lookup-BqomAHN5.js";
|
|
2
|
-
import {
|
|
2
|
+
import { A as WorkflowProviderStep, _ as WorkflowDefinitionRegistry, d as ResolvedWorkflowOptions } from "../types-DrhUXMsE.js";
|
|
3
3
|
export interface CloudflareWorkflowEvent {
|
|
4
4
|
id?: string;
|
|
5
5
|
instanceId?: string;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { r as runWithActiveCloudflareEnv } from "../cloudflare-env-DHhzRZOs.js";
|
|
2
2
|
import { n as createWorkflowError, r as isNonRetryableError } from "../errors-CZf7oz4k.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { a as createCloudflareConcurrencySlots, s as getCloudflareWorkflowBindingName } from "../cloudflare-concurrency-counter-CDHHiMfn.js";
|
|
4
|
+
import { t as fromCloudflareStartParams } from "../delay-B4azP18B.js";
|
|
5
|
+
import { i as resolveWorkflowStepOptions, o as runSerializedWorkflowHandler } from "../execute-zu08sWGG.js";
|
|
5
6
|
import { t as emitWorkflowFailed } from "../run-failed-BcSjSU2t.js";
|
|
6
7
|
import { loadWorkflowDefinition, runWithWorkflowRuntimeEvent, setWorkflowRuntimeConfig, setWorkflowRuntimeRegistry } from "./state.js";
|
|
7
|
-
import { t as workflowErrorDiagnostics } from "../error-diagnostics
|
|
8
|
+
import { t as workflowErrorDiagnostics } from "../error-diagnostics-35AEmfve.js";
|
|
8
9
|
import { hasRunFailedListeners } from "@vite-hub/runtime/internal/run-failed";
|
|
9
10
|
// src/runtime/cloudflare-runner.ts
|
|
10
11
|
function cloudflareSignalEventType(signal) {
|
|
@@ -62,12 +63,15 @@ async function runCloudflareWorkflow({ config, createNonRetryableError, env, eve
|
|
|
62
63
|
await step.sleepUntil("vitehub-delay", new Date(startAt));
|
|
63
64
|
}
|
|
64
65
|
const id = event?.instanceId || event?.id;
|
|
66
|
+
const binding = config && config.driver === "cloudflare" && config.binding || getCloudflareWorkflowBindingName(name);
|
|
67
|
+
const slots = definition.concurrency === void 0 || !providerStep?.do ? void 0 : createCloudflareConcurrencySlots(env, name, id, binding);
|
|
65
68
|
try {
|
|
66
69
|
return await runWithWorkflowRuntimeEvent(runtimeEvent, () => runSerializedWorkflowHandler({
|
|
67
70
|
id,
|
|
68
71
|
name,
|
|
69
72
|
payload,
|
|
70
73
|
provider: "cloudflare",
|
|
74
|
+
...slots ? { slots } : {},
|
|
71
75
|
step: providerStep
|
|
72
76
|
}, definition));
|
|
73
77
|
} catch (error) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as VitehubApp } from "../app-wkVFd7m-.js";
|
|
2
2
|
import { t as CloudflareWorkerEnv } from "../cloudflare-env-lookup-BqomAHN5.js";
|
|
3
3
|
import { t as CloudflareWorkerExecutionContext } from "../cloudflare-shared-B9cY3-jD.js";
|
|
4
|
-
import {
|
|
4
|
+
import { _ as WorkflowDefinitionRegistry, d as ResolvedWorkflowOptions } from "../types-DrhUXMsE.js";
|
|
5
5
|
export type CloudflareWorkerApp = VitehubApp;
|
|
6
6
|
export interface WorkflowCloudflareWorkerOptions {
|
|
7
7
|
app?: CloudflareWorkerApp;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as resolveAppFetch } from "../app-
|
|
2
|
-
import { t as normalizeWorkflowOptions } from "../config-
|
|
1
|
+
import { t as resolveAppFetch } from "../app-Cpa9qCXr.js";
|
|
2
|
+
import { t as normalizeWorkflowOptions } from "../config-G0z9jHLM.js";
|
|
3
3
|
import { r as runWithActiveCloudflareEnv, t as createCloudflareRuntimeEvent } from "../cloudflare-env-DHhzRZOs.js";
|
|
4
4
|
import { runWithWorkflowRuntimeEvent, setWorkflowRuntimeConfig, setWorkflowRuntimeRegistry } from "./state.js";
|
|
5
5
|
import "./cloudflare-shared.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as NonRetryableError } from "../errors-
|
|
1
|
+
import { J as WorkflowStepContext, Q as WorkflowStepRetries, X as WorkflowStepOptions, Y as WorkflowStepFunction, b as WorkflowDuration, h as WorkflowDefinition, k as WorkflowProviderContext } from "../types-DrhUXMsE.js";
|
|
2
|
+
import { t as NonRetryableError } from "../errors-DwKy5MQ8.js";
|
|
3
3
|
/** The options of a step with the default retries filled in. */
|
|
4
4
|
export interface ResolvedWorkflowStepOptions {
|
|
5
5
|
retries: Required<WorkflowStepRetries>;
|
|
@@ -43,5 +43,11 @@ export interface NonRetryableStepResult {
|
|
|
43
43
|
export declare function toNonRetryableStepResult(error: unknown): NonRetryableStepResult | undefined;
|
|
44
44
|
export declare function readNonRetryableStepResult(value: unknown): NonRetryableError | undefined;
|
|
45
45
|
export declare function runWorkflowHandler<TPayload, TResult>(context: WorkflowProviderContext<TPayload>, definition: WorkflowDefinition<TPayload, TResult>): Promise<Response>;
|
|
46
|
+
/**
|
|
47
|
+
* Runs the handler of a single-file Workflow as its root step. The generated Vercel native entry calls it inside its one
|
|
48
|
+
* `"use step"`, so Workflow DevKit stores the result as the Cloudflare root step does.
|
|
49
|
+
*/
|
|
50
|
+
export declare function runWorkflowRootStep<TPayload, TResult>(context: WorkflowProviderContext<TPayload>, definition: WorkflowDefinition<TPayload, TResult>): Promise<unknown>;
|
|
51
|
+
export declare function rejectDirectGeneratedWorkflowCall(): never;
|
|
46
52
|
/** Encode inside the root step so both checkpoints and final outputs survive replay. */
|
|
47
53
|
export declare function runSerializedWorkflowHandler<TPayload, TResult>(context: WorkflowProviderContext<TPayload>, definition: WorkflowDefinition<TPayload, TResult>): Promise<unknown>;
|