@vite-hub/workflow 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.md +32 -8
  2. package/dist/{app-DXUHElAz.js → app-Cpa9qCXr.js} +1 -1
  3. package/dist/{client-CbBg4HlH.js → client-CPxPxsl5.js} +37 -37
  4. package/dist/cloudflare-concurrency-counter-CDHHiMfn.js +136 -0
  5. package/dist/{config-CizNRTMi.js → config-CwCwuZqv.js} +1 -1
  6. package/dist/definition.d.ts +1 -1
  7. package/dist/definition.js +4 -1
  8. package/dist/{delay-CtT3442d.js → delay-JrpW40UF.js} +4 -2
  9. package/dist/durability.d.ts +3 -1
  10. package/dist/durability.js +7 -1
  11. package/dist/{error-diagnostics--2cV_ER1.js → error-diagnostics-35AEmfve.js} +25 -5
  12. package/dist/{error-diagnostics-kKXseq8d.js → error-diagnostics-CsiNo_oI.js} +3 -3
  13. package/dist/{errors-CJZuvOcx.d.ts → errors-DwKy5MQ8.d.ts} +1 -1
  14. package/dist/execute-CLmIXnON.js +355 -0
  15. package/dist/index.d.ts +12 -10
  16. package/dist/index.js +3 -3
  17. package/dist/{openworkflow-defaults-DfQWtSRU.js → invariant-Dj2R1eMr.js} +1 -4
  18. package/dist/openworkflow-BiwPTYEz.js +752 -0
  19. package/dist/{openworkflow-CdKbUGGa.d.ts → openworkflow-C65AWQSJ.d.ts} +23 -4
  20. package/dist/openworkflow-defaults-1n0DbLdb.js +4 -0
  21. package/dist/{operation-definition-CqZkx1Rm.d.ts → operations-Blwi3jQF.d.ts} +1 -0
  22. package/dist/{operations-BBTmDm2H.js → operations-DyaGK9zW.js} +70 -14
  23. package/dist/operations.d.ts +3 -59
  24. package/dist/operations.js +5 -5
  25. package/dist/results-DBp_bmUP.d.ts +60 -0
  26. package/dist/runtime/cloudflare-concurrency.d.ts +21 -0
  27. package/dist/runtime/cloudflare-concurrency.js +21 -0
  28. package/dist/runtime/cloudflare-runner.d.ts +1 -1
  29. package/dist/runtime/cloudflare-runner.js +7 -3
  30. package/dist/runtime/cloudflare-vite.d.ts +1 -1
  31. package/dist/runtime/cloudflare-vite.js +2 -2
  32. package/dist/runtime/execute.d.ts +8 -2
  33. package/dist/runtime/execute.js +1 -278
  34. package/dist/runtime/openworkflow-worker.d.ts +2 -2
  35. package/dist/runtime/openworkflow-worker.js +2 -2
  36. package/dist/runtime/openworkflow.d.ts +2 -2
  37. package/dist/runtime/openworkflow.js +1 -481
  38. package/dist/runtime/state.d.ts +1 -1
  39. package/dist/runtime/state.js +2 -2
  40. package/dist/runtime/vercel-vite.d.ts +1 -1
  41. package/dist/runtime/vercel-vite.js +2 -2
  42. package/dist/{signals-BHQdxoJo.js → signals-CdaxRNjN.js} +1 -1
  43. package/dist/{types-DvYcvbPG.d.ts → types-CvyOEp0V.d.ts} +33 -4
  44. package/dist/{vercel-Cw_Z9-j4.js → vercel-ADMH2MK8.js} +5 -3
  45. package/dist/vite.d.ts +18 -4
  46. package/dist/vite.js +553 -116
  47. package/package.json +3 -3
  48. package/dist/cloudflare-Sgywkm1N.js +0 -57
@@ -1,4 +1,5 @@
1
- import { A as WorkflowRun, B as WorkflowStartOptions, f as WorkflowDefinition, l as ResolvedWorkflowOptions } from "./types-DvYcvbPG.js";
1
+ import { s as WorkflowRunsListStatus } from "./results-DBp_bmUP.js";
2
+ import { G as WorkflowStartOptions, P as WorkflowRun, d as ResolvedWorkflowOptions, h as WorkflowDefinition, p as WorkflowConcurrencySlots } from "./types-CvyOEp0V.js";
2
3
  type OpenWorkflowModule = typeof import("openworkflow");
3
4
  type OpenWorkflowPostgresModule = typeof import("openworkflow/postgres");
4
5
  type OpenWorkflowSqliteModule = typeof import("openworkflow/sqlite");
@@ -11,6 +12,8 @@ interface OpenWorkflowRuntime {
11
12
  client: OpenWorkflowClient;
12
13
  definitions: Map<string, WorkflowDefinition>;
13
14
  findRunId: (name: string, key: string) => Promise<string | undefined>;
15
+ findRuns: (id: string, name?: string) => Promise<StoredRunIdentity[]>;
16
+ slots: (workflow: string, run: string) => WorkflowConcurrencySlots;
14
17
  workflows: Map<string, OpenWorkflowRunnable>;
15
18
  }
16
19
  /**
@@ -23,6 +26,10 @@ type OpenWorkflowStorageSource = "configured" | "database" | "default";
23
26
  * generated startup plugin installs it when the build has a Postgres Default Database.
24
27
  */
25
28
  declare function setOpenWorkflowDatabaseUrl(resolve: (() => string | undefined) | undefined): void;
29
+ interface StoredRunIdentity {
30
+ id: string;
31
+ workflow: string;
32
+ }
26
33
  /** The storage that OpenWorkflow uses for `config` now, without credentials. */
27
34
  declare function describeOpenWorkflowStorage(config: ResolvedWorkflowOptions): {
28
35
  backend: "postgres" | "sqlite";
@@ -37,8 +44,20 @@ declare function getOpenWorkflowRuntime(config: ResolvedWorkflowOptions): Promis
37
44
  declare function resumeOpenWorkflowSignal(config: ResolvedWorkflowOptions, workflow: string, id: string, token: string, value: unknown): Promise<boolean>;
38
45
  declare function registerOpenWorkflowDefinition(runtime: OpenWorkflowRuntime, name: string, definition: WorkflowDefinition): Promise<OpenWorkflowRunnable>;
39
46
  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>>;
40
- declare function getOpenWorkflowRun<TPayload = unknown, TResult = unknown>(config: ResolvedWorkflowOptions, name: string, id: string): Promise<WorkflowRun<TPayload, TResult>>;
41
- declare function cancelOpenWorkflowRun<TPayload = unknown, TResult = unknown>(config: ResolvedWorkflowOptions, name: string, id: string): Promise<WorkflowRun<TPayload, TResult>>;
47
+ declare function getOpenWorkflowRun<TPayload = unknown, TResult = unknown>(config: ResolvedWorkflowOptions, name: string, id: string, lookup?: "key-or-id" | "provider-id"): Promise<WorkflowRun<TPayload, TResult>>;
48
+ declare function findOpenWorkflowRuns(config: ResolvedWorkflowOptions, id: string, name?: string): Promise<StoredRunIdentity[]>;
49
+ interface OpenWorkflowRunListing {
50
+ run: WorkflowRun<unknown, unknown>;
51
+ stepCount: number;
52
+ workflow: string;
53
+ }
54
+ /** Lists the stored OpenWorkflow runs, newest first, with the number of steps of each run. */
55
+ declare function listOpenWorkflowRuns(config: ResolvedWorkflowOptions, input: {
56
+ limit: number;
57
+ status?: WorkflowRunsListStatus;
58
+ workflow?: string;
59
+ }): Promise<OpenWorkflowRunListing[]>;
60
+ declare function cancelOpenWorkflowRun<TPayload = unknown, TResult = unknown>(config: ResolvedWorkflowOptions, name: string, id: string, lookup?: "key-or-id" | "provider-id"): Promise<WorkflowRun<TPayload, TResult>>;
42
61
  declare function resetOpenWorkflowRuntime(): Promise<void>;
43
62
  /**
44
63
  * Starts a new runtime cache, so the next acquisition opens a fresh backend. Returns a function that closes the
@@ -46,4 +65,4 @@ declare function resetOpenWorkflowRuntime(): Promise<void>;
46
65
  */
47
66
  declare function detachOpenWorkflowRuntimes(): () => Promise<void>;
48
67
  declare function setOpenWorkflowImporter(importer: OpenWorkflowImporter): void;
49
- 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 };
68
+ export { detachOpenWorkflowRuntimes as a, getOpenWorkflowRuntime as c, resetOpenWorkflowRuntime as d, resumeOpenWorkflowSignal as f, setOpenWorkflowImporter as h, describeOpenWorkflowStorage as i, listOpenWorkflowRuns as l, setOpenWorkflowDatabaseUrl as m, OpenWorkflowStorageSource as n, findOpenWorkflowRuns as o, runOpenWorkflow as p, cancelOpenWorkflowRun as r, getOpenWorkflowRun as s, OpenWorkflowRunListing as t, registerOpenWorkflowDefinition as u };
@@ -0,0 +1,4 @@
1
+ // src/internal/openworkflow-defaults.ts
2
+ /** The SQLite file that OpenWorkflow uses without configured storage, relative to the working directory of the server. */
3
+ const defaultOpenWorkflowSqlitePath = ".vitehub/data/openworkflow.sqlite.db";
4
+ export { defaultOpenWorkflowSqlitePath as t };
@@ -1,3 +1,4 @@
1
+ import "nostics";
1
2
  /** The Standard Typed interface. This is a base type extended by other specs. */
2
3
  interface StandardTypedV1<Input = unknown, Output = Input> {
3
4
  /** The Standard properties. */
@@ -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--2cV_ER1.js";
4
- import { a as resumeWorkflow, i as getWorkflowRun, o as startWorkflow, t as cancelWorkflow } from "./client-CbBg4HlH.js";
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-CPxPxsl5.js";
5
5
  import { t as getWorkflowDevRecorder } from "./dev-recorder-Dltdmlkv.js";
6
+ import { a as getOpenWorkflowRun, i as findOpenWorkflowRuns, s as listOpenWorkflowRuns, t as cancelOpenWorkflowRun } from "./openworkflow-BiwPTYEz.js";
6
7
  import { t as toWorkflowRunError } from "./run-error-8p4BtTMv.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 recorded = operation === "get" ? getWorkflowDevRecorder()?.list().filter((record) => record.id === runId && (named === void 0 || record.workflow === named)) ?? [] : [];
264
- if (recorded.length > 1) throw failure(workflowErrorDiagnostics.WORKFLOW_RUN_AMBIGUOUS({
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: recorded.map((record) => record.workflow).join(", ")
281
+ workflows: matches.map((match) => match.workflow).join(", ")
267
282
  }));
268
- const [record] = recorded;
269
- if (record) return { run: {
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
- const workflow = named ?? startedRuns.get(runId);
274
- if (!workflow) throw failure(workflowErrorDiagnostics.WORKFLOW_RUN_UNKNOWN({ runId }));
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
- /** Lists the runs that `vite dev` recorded, newest first. */
309
- async function listWorkflowRuns(input) {
310
- 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);
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() {
@@ -1,64 +1,8 @@
1
- import { t as AnyOperation } from "./operation-definition-CqZkx1Rm.js";
2
- import { M as WorkflowRunStatus, h as WorkflowDriver } from "./types-DvYcvbPG.js";
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-DBp_bmUP.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 };
@@ -1,5 +1,5 @@
1
1
  import { n as isRecordOrFunction } from "./object-CAK6UYR5.js";
2
- import { t as internalErrorDiagnostics } from "./error-diagnostics-kKXseq8d.js";
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-BBTmDm2H.js");
142
+ const runtime = () => import("./operations-DyaGK9zW.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. Pass `workflow` for a run that this runtime did not start.",
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 Workflow runs that `vite dev` recorded, newest first. Other runtimes keep no history and fail with WORKFLOW_RUNS_UNAVAILABLE.",
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. Other runtimes keep no history and fail with WORKFLOW_RUNS_UNAVAILABLE.",
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-CvyOEp0V.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 };
@@ -0,0 +1,21 @@
1
+ import "../types-CvyOEp0V.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 { D as WorkflowProviderStep, l as ResolvedWorkflowOptions, m as WorkflowDefinitionRegistry } from "../types-DvYcvbPG.js";
2
+ import { A as WorkflowProviderStep, _ as WorkflowDefinitionRegistry, d as ResolvedWorkflowOptions } from "../types-CvyOEp0V.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 { t as fromCloudflareStartParams } from "../delay-CtT3442d.js";
4
- import { resolveWorkflowStepOptions, runSerializedWorkflowHandler } from "./execute.js";
3
+ import { a as createCloudflareConcurrencySlots, s as getCloudflareWorkflowBindingName } from "../cloudflare-concurrency-counter-CDHHiMfn.js";
4
+ import { t as fromCloudflareStartParams } from "../delay-JrpW40UF.js";
5
+ import { i as resolveWorkflowStepOptions, o as runSerializedWorkflowHandler } from "../execute-CLmIXnON.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--2cV_ER1.js";
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 { l as ResolvedWorkflowOptions, m as WorkflowDefinitionRegistry } from "../types-DvYcvbPG.js";
4
+ import { _ as WorkflowDefinitionRegistry, d as ResolvedWorkflowOptions } from "../types-CvyOEp0V.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-DXUHElAz.js";
2
- import { t as normalizeWorkflowOptions } from "../config-CizNRTMi.js";
1
+ import { t as resolveAppFetch } from "../app-Cpa9qCXr.js";
2
+ import { t as normalizeWorkflowOptions } from "../config-CwCwuZqv.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 { E as WorkflowProviderContext, G as WorkflowStepOptions, U as WorkflowStepContext, W as WorkflowStepFunction, _ as WorkflowDuration, f as WorkflowDefinition, q as WorkflowStepRetries } from "../types-DvYcvbPG.js";
2
- import { t as NonRetryableError } from "../errors-CJZuvOcx.js";
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-CvyOEp0V.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>;