@vite-hub/workflow 0.1.0 → 0.3.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.
Files changed (64) hide show
  1. package/README.md +144 -43
  2. package/dist/{app-CzPoP84f.js → app-CmMq8l4t.js} +1 -1
  3. package/dist/client-CU5rELC0.js +658 -0
  4. package/dist/{cloudflare-nF4abPd4.js → cloudflare-BfFnNWB0.js} +2 -2
  5. package/dist/{cloudflare-env-BNrYo29x.js → cloudflare-env-CGLx7lUd.js} +44 -42
  6. package/dist/cloudflare-env-lookup-CfX6wZKb.d.ts +4 -0
  7. package/dist/{cloudflare-env-CIjdFTv6.d.ts → cloudflare-shared-CTqh_a2s.d.ts} +2 -2
  8. package/dist/{config-IJMb0eeZ.js → config-DCvRDlxA.js} +41 -40
  9. package/dist/definition.d.ts +19 -0
  10. package/dist/definition.js +31 -0
  11. package/dist/delay--ESDybVT.js +81 -0
  12. package/dist/dev-recorder-CTN5Fkao.js +10 -0
  13. package/dist/durability.d.ts +23 -0
  14. package/dist/durability.js +62 -0
  15. package/dist/error-diagnostics-8YNJ37rP.js +286 -0
  16. package/dist/error-diagnostics-DSkCJC_L.js +266 -0
  17. package/dist/errors-DCqRnZpN.js +35 -0
  18. package/dist/errors-DVwFb6Fd.d.ts +56 -0
  19. package/dist/index.d.ts +13 -60
  20. package/dist/index.js +6 -17
  21. package/dist/object-Da1zyPCR.js +11 -0
  22. package/dist/openworkflow-TEaNk0LV.d.ts +50 -0
  23. package/dist/openworkflow-defaults-DDig2M4s.js +26 -0
  24. package/dist/openworkflow-storage-Dj9zUAsk.js +28 -0
  25. package/dist/openworkflow.d.ts +2 -0
  26. package/dist/openworkflow.js +2 -0
  27. package/dist/{operations-tNUdj3G4.d.ts → operation-definition-8gOe-ubD.d.ts} +37 -15
  28. package/dist/operations-B0L8kV5s.js +329 -0
  29. package/dist/operations.d.ts +40 -6
  30. package/dist/operations.js +163 -736
  31. package/dist/{out-CsaJxg8m.js → out-fRNaVslw.js} +31 -1429
  32. package/dist/run-error-DBWqiJHH.js +110 -0
  33. package/dist/runtime/cloudflare-runner.d.ts +3 -5
  34. package/dist/runtime/cloudflare-runner.js +24 -42
  35. package/dist/runtime/cloudflare-shared.d.ts +2 -2
  36. package/dist/runtime/cloudflare-shared.js +1 -1
  37. package/dist/runtime/cloudflare-vite.d.ts +3 -2
  38. package/dist/runtime/cloudflare-vite.js +47 -1
  39. package/dist/runtime/dev-runs.d.ts +4 -0
  40. package/dist/runtime/dev-runs.js +73 -0
  41. package/dist/runtime/execute.d.ts +20 -4
  42. package/dist/runtime/execute.js +118 -12
  43. package/dist/runtime/openworkflow-worker.d.ts +29 -2
  44. package/dist/runtime/openworkflow-worker.js +156 -38
  45. package/dist/runtime/openworkflow.d.ts +2 -21
  46. package/dist/runtime/openworkflow.js +273 -36
  47. package/dist/runtime/state.d.ts +3 -1
  48. package/dist/runtime/state.js +11 -7
  49. package/dist/runtime/vercel-vite.d.ts +1 -1
  50. package/dist/runtime/vercel-vite.js +7 -4
  51. package/dist/types-CnKVDnEp.d.ts +241 -0
  52. package/dist/{vercel-D-ZNtB_u.js → vercel-BZU_O6ay.js} +51 -22
  53. package/dist/vite.d.ts +219 -27
  54. package/dist/vite.js +1787 -1183
  55. package/package.json +28 -50
  56. package/dist/client-DsGM3M4U.js +0 -389
  57. package/dist/cloudflare-shared-CaxrMD1A.d.ts +0 -1
  58. package/dist/cloudflare-vite-B3IabBsv.js +0 -47
  59. package/dist/error-diagnostics-A_8Kp-48.js +0 -116
  60. package/dist/error-diagnostics-pwNFvAHP.js +0 -67
  61. package/dist/operations-B_rYG71W.js +0 -230
  62. package/dist/provider-operation-CW2cYfVy.js +0 -65
  63. package/dist/runtime-type-DBCvIh5x.js +0 -7
  64. package/dist/types-D82WmfZa.d.ts +0 -180
package/dist/index.d.ts CHANGED
@@ -1,61 +1,8 @@
1
- import { A as WorkflowStartOptions, C as WorkflowProviderOptions, D as WorkflowRunStep, E as WorkflowRunStatus, M as WorkflowStepOptions, N as WorkflowStepRunner, O as WorkflowSharedOptions, S as WorkflowProviderContext, T as WorkflowRun, _ as WorkflowHandle, a as InferredWorkflowProviderOptions, b as WorkflowModuleProviderOptions, c as OpenWorkflowWorkerOptions, d as WorkflowCreateOptions, f as WorkflowDeferOptions, g as WorkflowExecutionContext, h as WorkflowDefinitionRegistry, i as DiscoveredWorkflowDefinition, j as WorkflowStepFunction, k as WorkflowSignalResult, l as ResolvedWorkflowOptions, m as WorkflowDefinitionOptions, n as CloudflareWorkflowInstance, o as OpenWorkflowPostgresOptions, p as WorkflowDefinition, r as CloudflareWorkflowProviderOptions, s as OpenWorkflowProviderOptions, t as CloudflareWorkflowBinding, u as VercelWorkflowProviderOptions, v as WorkflowHandler, w as WorkflowProviderStep, x as WorkflowProvider, y as WorkflowModuleOptions } from "./types-D82WmfZa.js";
2
- import { createWorkflowCloudflareWorker } from "./runtime/cloudflare-vite.js";
3
- import { ViteHubError } from "@vite-hub/runtime";
4
- //#region src/config.d.ts
5
- interface WorkflowResolutionInput {
6
- hosting?: string;
7
- }
8
- export declare function normalizeWorkflowOptions(options: WorkflowModuleOptions | undefined, input?: WorkflowResolutionInput): ResolvedWorkflowOptions | undefined;
9
- //#endregion
10
- //#region src/definition.d.ts
11
- export declare function defineWorkflow<TPayload = unknown, TResult = unknown>(handler: WorkflowHandler<TPayload, TResult>, options?: WorkflowDefinitionOptions<TPayload, TResult>): WorkflowDefinition<TPayload, TResult>;
12
- //#endregion
13
- //#region src/errors.d.ts
14
- declare const workflowErrorMessages: {
15
- readonly OPENWORKFLOW_BACKEND_CLOSE_FAILED: "OpenWorkflow backend cleanup failed.";
16
- readonly OPENWORKFLOW_RUNTIME_RESET: "OpenWorkflow runtime was reset while it was being acquired.";
17
- readonly OPENWORKFLOW_WORKER_STOP_FAILED: "OpenWorkflow worker stop failed.";
18
- readonly VERCEL_WORKFLOW_SDK_LOAD_FAILED: "Vercel Workflow DevKit load failed. Install the optional workflow peer dependency.";
19
- readonly WORKFLOW_DEFINITION_NOT_FOUND: "Workflow definition was not found.";
20
- readonly WORKFLOW_DISABLED: "Workflow is disabled.";
21
- readonly WORKFLOW_NATIVE_ENTRY_INVALID: "Workflow has no transformed native Vercel entry.";
22
- readonly WORKFLOW_NATIVE_ENTRY_REQUIRED: "Workflow has no native durable entry for Vercel.";
23
- readonly WORKFLOW_OPERATION_UNSUPPORTED: "Workflow provider operation is unsupported.";
24
- readonly WORKFLOW_PROVIDER_OPERATION_FAILED: "Workflow provider operation failed.";
25
- readonly WORKFLOW_RUN_ID_UNSUPPORTED: "Native Vercel workflows assign their own run IDs.";
26
- };
27
- declare const workflowProviderNames: readonly ["cloudflare", "openworkflow", "vercel"];
28
- declare const workflowOperationNames: readonly ["cancel", "cancellation", "connect", "create", "get", "get-run", "import", "list-steps", "resume-signal", "run", "signals", "start", "status"];
29
- type WorkflowErrorCode = keyof typeof workflowErrorMessages;
30
- type WorkflowOperationName = typeof workflowOperationNames[number];
31
- type WorkflowProviderName = typeof workflowProviderNames[number];
32
- type WorkflowNameDetails = {
33
- name?: string;
34
- };
35
- type VercelWorkflowDetails = {
36
- name?: string;
37
- provider: "vercel";
38
- };
39
- type WorkflowOperationDetails = {
40
- operation: WorkflowOperationName;
41
- provider: WorkflowProviderName;
42
- };
43
- type WorkflowProviderOperationDetails = WorkflowOperationDetails & {
44
- status?: number;
45
- };
46
- type WorkflowErrorDetails<TCode extends WorkflowErrorCode = WorkflowErrorCode> = TCode extends "OPENWORKFLOW_BACKEND_CLOSE_FAILED" | "OPENWORKFLOW_RUNTIME_RESET" | "OPENWORKFLOW_WORKER_STOP_FAILED" ? {
47
- provider: "openworkflow";
48
- } : TCode extends "VERCEL_WORKFLOW_SDK_LOAD_FAILED" ? {
49
- provider: "vercel";
50
- } : TCode extends "WORKFLOW_DEFINITION_NOT_FOUND" ? WorkflowNameDetails : TCode extends "WORKFLOW_DISABLED" ? Record<string, never> : TCode extends "WORKFLOW_NATIVE_ENTRY_INVALID" | "WORKFLOW_NATIVE_ENTRY_REQUIRED" | "WORKFLOW_RUN_ID_UNSUPPORTED" ? VercelWorkflowDetails : TCode extends "WORKFLOW_OPERATION_UNSUPPORTED" ? WorkflowOperationDetails : TCode extends "WORKFLOW_PROVIDER_OPERATION_FAILED" ? WorkflowProviderOperationDetails : never;
51
- //#endregion
1
+ import { C as WorkflowOptions, D as WorkflowRunError, E as WorkflowRun, F as WorkflowStep, I as WorkflowStepFunction, L as WorkflowStepOptions, M as WorkflowSignalResult, N as WorkflowStartDelay, O as WorkflowRunStatus, P as WorkflowStartOptions, R as WorkflowStepRegistry, S as WorkflowModuleDriverOptions, T as WorkflowProviderStep, _ as WorkflowDuration, a as InferredWorkflowDriverOptions, b as WorkflowHandle, c as OpenWorkflowWorkerOptions, d as WorkflowCreateOptions, f as WorkflowDefinition, g as WorkflowDriverOptions, h as WorkflowDriver, i as DiscoveredWorkflowDefinition, j as WorkflowSharedOptions, k as WorkflowRunStep, l as ResolvedWorkflowOptions, m as WorkflowDefinitionRegistry, n as CloudflareWorkflowDriverOptions, o as OpenWorkflowDriverOptions, p as WorkflowDefinitionOptions, r as CloudflareWorkflowInstance, s as OpenWorkflowPostgresOptions, t as CloudflareWorkflowBinding, u as VercelWorkflowDriverOptions, v as WorkflowDurationUnit, w as WorkflowProviderContext, x as WorkflowHandler, y as WorkflowExecutionContext, z as WorkflowSteps } from "./types-CnKVDnEp.js";
2
+ import { defineWorkflow } from "./definition.js";
3
+ import { a as WorkflowProviderName, i as WorkflowOperationName, n as WorkflowErrorCode, r as WorkflowErrorDetails, t as NonRetryableError } from "./errors-DVwFb6Fd.js";
52
4
  //#region src/integrations/cloudflare.d.ts
53
5
  export declare function getCloudflareWorkflowBindingName(name: string): string;
54
- export declare function getCloudflareWorkflowName(name: string): string;
55
- export declare function getCloudflareWorkflowClassName(name: string): string;
56
- //#endregion
57
- //#region src/integrations/vercel.d.ts
58
- export declare function getVercelWorkflowName(name: string): string;
59
6
  //#endregion
60
7
  //#region src/runtime/client.d.ts
61
8
  export declare function createWorkflow<TPayload = unknown, TResult = unknown>(options: WorkflowCreateOptions<TPayload, TResult> & {
@@ -69,11 +16,17 @@ export declare function createWorkflow<TPayload = unknown>(name: string, options
69
16
  handler?: never;
70
17
  }): WorkflowHandle<TPayload, unknown>;
71
18
  export declare function createWorkflow<TPayload = unknown, TResult = unknown>(name: string, handler: WorkflowHandler<TPayload, TResult>, options?: WorkflowCreateOptions<TPayload, TResult>): WorkflowHandle<TPayload, TResult>;
72
- export declare function runWorkflow<TPayload = unknown>(name: string, payload?: TPayload, options?: WorkflowDeferOptions): Promise<WorkflowRun<TPayload, unknown>>;
19
+ /** Starts one durable run of a Workflow Definition and returns its id and status. */
20
+ export declare function startWorkflow<TPayload = unknown>(name: string, payload?: TPayload, options?: WorkflowStartOptions): Promise<WorkflowRun<TPayload, unknown>>;
73
21
  export declare function getWorkflowRun(name: string, id: string): Promise<WorkflowRun<unknown, unknown>>;
74
22
  export declare function cancelWorkflow(name: string, id: string): Promise<WorkflowRun<unknown, unknown>>;
75
- export declare function resumeWorkflowSignal<TPayload = unknown>(token: string, payload: TPayload): Promise<WorkflowSignalResult>;
76
- export declare function deferWorkflow<TPayload = unknown>(name: string, payload?: TPayload, options?: WorkflowStartOptions): Promise<WorkflowRun<TPayload>>;
23
+ /** Resumes a run that waits for a signal. `token` is the opaque token that the provider gave the waiting step. */
24
+ export declare function resumeWorkflow<TPayload = unknown>(token: string, payload: TPayload): Promise<WorkflowSignalResult>;
25
+ /**
26
+ * Starts a run after the response, through `waitUntil`. It returns nothing: a failure goes to the log.
27
+ * Call `startWorkflow()` when the caller needs the run ID or the start error.
28
+ */
29
+ export declare function deferWorkflow<TPayload = unknown>(name: string, payload?: TPayload, options?: WorkflowStartOptions): void;
77
30
  //#endregion
78
31
  //#region src/runtime/payload.d.ts
79
32
  interface PayloadSchema<T> {
@@ -91,4 +44,4 @@ export declare function readRequestPayload<T = unknown>(request: Request): Promi
91
44
  export declare function validatePayload<T>(payload: unknown, schema: PayloadValidator<T>): Promise<T>;
92
45
  export declare function readValidatedPayload<T>(request: Request, schema: PayloadValidator<T>): Promise<T>;
93
46
  //#endregion
94
- export { type CloudflareWorkflowBinding, type CloudflareWorkflowInstance, type CloudflareWorkflowProviderOptions, type DiscoveredWorkflowDefinition, type InferredWorkflowProviderOptions, type OpenWorkflowPostgresOptions, type OpenWorkflowProviderOptions, type OpenWorkflowWorkerOptions, type ResolvedWorkflowOptions, type VercelWorkflowProviderOptions, type WorkflowCreateOptions, type WorkflowDeferOptions, type WorkflowDefinition, type WorkflowDefinitionOptions, type WorkflowDefinitionRegistry, type WorkflowErrorCode, type WorkflowErrorDetails, type WorkflowExecutionContext, type WorkflowHandle, type WorkflowHandler, type WorkflowModuleOptions, type WorkflowModuleProviderOptions, type WorkflowOperationName, type WorkflowProvider, type WorkflowProviderContext, type WorkflowProviderName, type WorkflowProviderOptions, type WorkflowProviderStep, type WorkflowRun, type WorkflowRunStatus, type WorkflowRunStep, type WorkflowSharedOptions, type WorkflowSignalResult, type WorkflowStartOptions, type WorkflowStepFunction, type WorkflowStepOptions, type WorkflowStepRunner, createWorkflowCloudflareWorker };
47
+ export { type CloudflareWorkflowBinding, type CloudflareWorkflowDriverOptions, type CloudflareWorkflowInstance, type DiscoveredWorkflowDefinition, type InferredWorkflowDriverOptions, NonRetryableError, type OpenWorkflowDriverOptions, type OpenWorkflowPostgresOptions, type OpenWorkflowWorkerOptions, type ResolvedWorkflowOptions, type VercelWorkflowDriverOptions, type WorkflowCreateOptions, type WorkflowDefinition, type WorkflowDefinitionOptions, type WorkflowDefinitionRegistry, type WorkflowDriver, type WorkflowDriverOptions, type WorkflowDuration, type WorkflowDurationUnit, type WorkflowErrorCode, type WorkflowErrorDetails, type WorkflowExecutionContext, type WorkflowHandle, type WorkflowHandler, type WorkflowModuleDriverOptions, type WorkflowOperationName, type WorkflowOptions, type WorkflowProviderContext, type WorkflowProviderName, type WorkflowProviderStep, type WorkflowRun, type WorkflowRunError, type WorkflowRunStatus, type WorkflowRunStep, type WorkflowSharedOptions, type WorkflowSignalResult, type WorkflowStartDelay, type WorkflowStartOptions, type WorkflowStep, type WorkflowStepFunction, type WorkflowStepOptions, type WorkflowStepRegistry, type WorkflowSteps, defineWorkflow };
package/dist/index.js CHANGED
@@ -1,19 +1,8 @@
1
- import { t as normalizeWorkflowOptions } from "./config-IJMb0eeZ.js";
2
- import { t as workflowErrorDiagnostics } from "./error-diagnostics-pwNFvAHP.js";
3
- import { i as getCloudflareWorkflowName, n as getCloudflareWorkflowBindingName, r as getCloudflareWorkflowClassName } from "./cloudflare-nF4abPd4.js";
4
- import { a as resumeWorkflowSignal, i as getWorkflowRun, n as createWorkflow, o as runWorkflow, r as deferWorkflow, s as getVercelWorkflowName, t as cancelWorkflow } from "./client-DsGM3M4U.js";
5
- import { t as createWorkflowCloudflareWorker } from "./cloudflare-vite-B3IabBsv.js";
6
- //#region src/definition.ts
7
- function defineWorkflow(handler, options) {
8
- if (typeof handler !== "function") throw workflowErrorDiagnostics.WORKFLOW_C0014({ message: "`defineWorkflow()` requires a workflow handler." });
9
- if (typeof options !== "undefined" && (!options || typeof options !== "object" || Array.isArray(options))) throw workflowErrorDiagnostics.WORKFLOW_C0015({ message: "`defineWorkflow()` options must be a plain object." });
10
- if (options?.native !== void 0 && typeof options.native !== "function") throw workflowErrorDiagnostics.WORKFLOW_C0016({ message: "`defineWorkflow()` native entry must be a workflow handler." });
11
- return {
12
- handler,
13
- options
14
- };
15
- }
16
- //#endregion
1
+ import { t as workflowErrorDiagnostics } from "./error-diagnostics-8YNJ37rP.js";
2
+ import { defineWorkflow } from "./definition.js";
3
+ import { t as NonRetryableError } from "./errors-DCqRnZpN.js";
4
+ import { n as getCloudflareWorkflowBindingName } from "./cloudflare-BfFnNWB0.js";
5
+ import { a as resumeWorkflow, i as getWorkflowRun, n as createWorkflow, o as startWorkflow, r as deferWorkflow, t as cancelWorkflow } from "./client-CU5rELC0.js";
17
6
  //#region src/runtime/payload.ts
18
7
  async function readRequestPayload(request) {
19
8
  if (request.headers.get("content-type")?.split(";", 1)[0]?.trim().toLowerCase() === "application/json") return await request.json();
@@ -45,4 +34,4 @@ async function readValidatedPayload(request, schema) {
45
34
  return await validatePayload(await readRequestPayload(request), schema);
46
35
  }
47
36
  //#endregion
48
- export { cancelWorkflow, createWorkflow, createWorkflowCloudflareWorker, deferWorkflow, defineWorkflow, getCloudflareWorkflowBindingName, getCloudflareWorkflowClassName, getCloudflareWorkflowName, getVercelWorkflowName, getWorkflowRun, normalizeWorkflowOptions, readRequestPayload, readValidatedPayload, resumeWorkflowSignal, runWorkflow, validatePayload };
37
+ export { NonRetryableError, cancelWorkflow, createWorkflow, deferWorkflow, defineWorkflow, getCloudflareWorkflowBindingName, getWorkflowRun, readRequestPayload, readValidatedPayload, resumeWorkflow, startWorkflow, validatePayload };
@@ -0,0 +1,11 @@
1
+ //#region ../internal/src/object.ts
2
+ /** A non-null object that is not an array. Functions do not pass. */
3
+ function isRecord(value) {
4
+ return typeof value === "object" && value !== null && !Array.isArray(value);
5
+ }
6
+ /** A non-null object or a function that is not an array. */
7
+ function isRecordOrFunction(value) {
8
+ return Object(value) === value && !Array.isArray(value);
9
+ }
10
+ //#endregion
11
+ export { isRecordOrFunction as n, isRecord as t };
@@ -0,0 +1,50 @@
1
+ import { E as WorkflowRun, P as WorkflowStartOptions, f as WorkflowDefinition, l as ResolvedWorkflowOptions } from "./types-CnKVDnEp.js";
2
+ //#region src/runtime/openworkflow.d.ts
3
+ type OpenWorkflowModule = typeof import("openworkflow");
4
+ type OpenWorkflowPostgresModule = typeof import("openworkflow/postgres");
5
+ type OpenWorkflowSqliteModule = typeof import("openworkflow/sqlite");
6
+ type OpenWorkflowClient = InstanceType<OpenWorkflowModule["OpenWorkflow"]>;
7
+ type OpenWorkflowBackend = Awaited<ReturnType<OpenWorkflowPostgresModule["BackendPostgres"]["connect"]>> | ReturnType<OpenWorkflowSqliteModule["BackendSqlite"]["connect"]>;
8
+ type OpenWorkflowRunnable = ReturnType<OpenWorkflowClient["defineWorkflow"]>;
9
+ type OpenWorkflowImporter = <T>(specifier: string) => Promise<T>;
10
+ interface OpenWorkflowRuntime {
11
+ backend: OpenWorkflowBackend;
12
+ client: OpenWorkflowClient;
13
+ /** Returns the OpenWorkflow id of the first run of `name` that started with the id `key`. */
14
+ findRunId: (name: string, key: string) => Promise<string | undefined>;
15
+ workflows: Map<string, OpenWorkflowRunnable>;
16
+ }
17
+ /**
18
+ * Where the storage came from: `configured` options or environment variables, the Postgres Default `database` of the
19
+ * app, or the `default` SQLite file.
20
+ */
21
+ type OpenWorkflowStorageSource = "configured" | "database" | "default";
22
+ /**
23
+ * Makes OpenWorkflow use the Postgres Default Database of the app when no OpenWorkflow storage is configured. The
24
+ * generated startup plugin installs it when the build has a Postgres Default Database.
25
+ */
26
+ declare function setOpenWorkflowDatabaseUrl(resolve: (() => string | undefined) | undefined): void;
27
+ /** The storage that OpenWorkflow uses for `config` now, without credentials. */
28
+ declare function describeOpenWorkflowStorage(config: ResolvedWorkflowOptions): {
29
+ backend: "postgres" | "sqlite";
30
+ location: string;
31
+ source: OpenWorkflowStorageSource;
32
+ };
33
+ declare function getOpenWorkflowRuntime(config: ResolvedWorkflowOptions): Promise<OpenWorkflowRuntime>;
34
+ declare function registerOpenWorkflowDefinition(runtime: OpenWorkflowRuntime, name: string, definition: WorkflowDefinition): Promise<OpenWorkflowRunnable>;
35
+ declare function runOpenWorkflow<TPayload = unknown, TResult = unknown>(config: ResolvedWorkflowOptions, name: string, payload: TPayload | undefined, definition: WorkflowDefinition<TPayload, TResult>, options: WorkflowStartOptions, onDispatch?: () => void, startAt?: number): Promise<WorkflowRun<TPayload, TResult>>;
36
+ declare function getOpenWorkflowRun<TPayload = unknown, TResult = unknown>(config: ResolvedWorkflowOptions, name: string, id: string): Promise<WorkflowRun<TPayload, TResult>>;
37
+ /**
38
+ * Cancels a pending or running OpenWorkflow run of this Workflow and returns its state afterwards. A run of another
39
+ * Workflow, or an unknown run, reports `unknown` without being cancelled. A finished run keeps and reports its status.
40
+ */
41
+ declare function cancelOpenWorkflowRun<TPayload = unknown, TResult = unknown>(config: ResolvedWorkflowOptions, name: string, id: string): Promise<WorkflowRun<TPayload, TResult>>;
42
+ declare function resetOpenWorkflowRuntime(): Promise<void>;
43
+ /**
44
+ * Starts a new runtime cache, so the next acquisition opens a fresh backend. Returns a function that closes the
45
+ * backends of the old cache. Call it after the work that still uses them, such as a stopping worker, finishes.
46
+ */
47
+ declare function detachOpenWorkflowRuntimes(): () => Promise<void>;
48
+ declare function setOpenWorkflowImporter(importer: OpenWorkflowImporter): void;
49
+ //#endregion
50
+ export { getOpenWorkflowRun as a, resetOpenWorkflowRuntime as c, setOpenWorkflowImporter as d, detachOpenWorkflowRuntimes as i, runOpenWorkflow as l, cancelOpenWorkflowRun as n, getOpenWorkflowRuntime as o, describeOpenWorkflowStorage as r, registerOpenWorkflowDefinition as s, OpenWorkflowStorageSource as t, setOpenWorkflowDatabaseUrl as u };
@@ -0,0 +1,26 @@
1
+ import { defineDiagnostics } from "nostics";
2
+ //#region ../internal/src/invariant.ts
3
+ const invariantDiagnostics = /*#__PURE__*/ defineDiagnostics({
4
+ docsBase: "https://vitehub.dev/docs/development/diagnostics",
5
+ codes: { INTERNAL_INVARIANT_FAILED: {
6
+ why: ({ what }) => `ViteHub reached a state that it does not expect: ${what}`,
7
+ fix: "This is a ViteHub bug. Open an issue at https://github.com/vite-hub/vitehub/issues with this error message and its stack trace."
8
+ } }
9
+ });
10
+ /**
11
+ * The error for a state that only a ViteHub bug can reach, such as an impossible branch. `what` says which rule broke.
12
+ * Use a code from the package catalog when a developer can cause the error or fix it.
13
+ */
14
+ function invariantError(what) {
15
+ return invariantDiagnostics.INTERNAL_INVARIANT_FAILED({ what });
16
+ }
17
+ /** Throws `INTERNAL_INVARIANT_FAILED` when `condition` is falsy. */
18
+ function invariant(condition, what) {
19
+ if (!condition) throw invariantError(what);
20
+ }
21
+ //#endregion
22
+ //#region src/internal/openworkflow-defaults.ts
23
+ /** The SQLite file that OpenWorkflow uses without configured storage, relative to the working directory of the server. */
24
+ const defaultOpenWorkflowSqlitePath = ".vitehub/data/openworkflow.sqlite.db";
25
+ //#endregion
26
+ export { invariant as n, invariantError as r, defaultOpenWorkflowSqlitePath as t };
@@ -0,0 +1,28 @@
1
+ //#region src/internal/openworkflow-storage.ts
2
+ /** Select storage once for both the OpenWorkflow runtime and its durability report. Values are already resolved. */
3
+ function resolveOpenWorkflowStorage(input, readEnv) {
4
+ const sqlitePath = input.sqlitePath || (!input.postgresUrl ? readEnv("OPENWORKFLOW_SQLITE_PATH") : void 0);
5
+ if (sqlitePath) return {
6
+ backend: "sqlite",
7
+ path: sqlitePath,
8
+ source: "configured"
9
+ };
10
+ if (input.postgresUrl) return {
11
+ backend: "postgres",
12
+ url: input.postgresUrl,
13
+ source: "`workflow.postgres.url`"
14
+ };
15
+ const url = readEnv("OPENWORKFLOW_POSTGRES_URL");
16
+ if (url) return {
17
+ backend: "postgres",
18
+ url,
19
+ source: "OPENWORKFLOW_POSTGRES_URL"
20
+ };
21
+ return {
22
+ backend: "sqlite",
23
+ path: ".vitehub/data/openworkflow.sqlite.db",
24
+ source: "default"
25
+ };
26
+ }
27
+ //#endregion
28
+ export { resolveOpenWorkflowStorage as t };
@@ -0,0 +1,2 @@
1
+ import { CreateOpenWorkflowWorkerOptions, InstallOpenWorkflowOptions, OpenWorkflowWorkerApp, StartOpenWorkflowWorkerOptions, createOpenWorkflowWorker, installOpenWorkflow, startOpenWorkflowWorker } from "./runtime/openworkflow-worker.js";
2
+ export { CreateOpenWorkflowWorkerOptions, InstallOpenWorkflowOptions, OpenWorkflowWorkerApp, StartOpenWorkflowWorkerOptions, createOpenWorkflowWorker, installOpenWorkflow, startOpenWorkflowWorker };
@@ -0,0 +1,2 @@
1
+ import { createOpenWorkflowWorker, installOpenWorkflow, startOpenWorkflowWorker } from "./runtime/openworkflow-worker.js";
2
+ export { createOpenWorkflowWorker, installOpenWorkflow, startOpenWorkflowWorker };
@@ -75,7 +75,7 @@ declare namespace StandardSchemaV1 {
75
75
  type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
76
76
  }
77
77
  //#endregion
78
- //#region ../internal/src/operations.d.ts
78
+ //#region ../internal/src/operation-definition.d.ts
79
79
  /** `read` never changes state. `write` changes state. `destructive` deletes or publishes. */
80
80
  type OperationKind = "read" | "write" | "destructive";
81
81
  /** The signed-in user of a call. */
@@ -98,7 +98,9 @@ interface OperationAccess {
98
98
  readonly mode: string;
99
99
  /**
100
100
  * The sections that the call may use. `"all"` when no section filter applies. An entry is a section id (`"kv"`, every
101
- * operation of the section) or `"<section>:read"` (only the operations that read).
101
+ * operation of the section), `"<section>:read"` (only the operations that read), or `"<section>:<scope>"` (only the
102
+ * calls of a scoped operation for that scope, such as `"blob:media"` for one Blob store). `"<section>:<scope>:read"`
103
+ * allows only the reads of that scope.
102
104
  */
103
105
  readonly sections: "all" | readonly string[];
104
106
  readonly user?: OperationUser;
@@ -116,6 +118,12 @@ interface OperationContext {
116
118
  env?: Record<string, unknown>;
117
119
  waitUntil?: (task: Promise<unknown>) => void;
118
120
  request?: Request;
121
+ /**
122
+ * The request event of the HTTP request that carries the call, when there is one: the Request of the Console route,
123
+ * with its Standard Context. Operations hand it to app hooks that read the request's own session, such as `identify`
124
+ * of Comments.
125
+ */
126
+ event?: unknown;
119
127
  /** Operations set a success status here, such as 202 for an accepted call. */
120
128
  response?: {
121
129
  status?: number;
@@ -138,9 +146,16 @@ interface OperationDefinition<Input, Output> {
138
146
  description: string;
139
147
  /**
140
148
  * Console section that grants access, such as `content`. `false`: any Console user. A function reads the section
141
- * from the input, for operations that serve several sections.
149
+ * from the input, for operations that serve several sections. Section ids cannot contain `:`; it is reserved for
150
+ * scope and read-only grants. A function that returns an invalid id denies the call.
142
151
  */
143
152
  section: string | false | ((input: Input) => string | undefined);
153
+ /**
154
+ * The part of a string `section` that one call uses, such as the Blob store that the input names. The call then needs
155
+ * the section (every scope) or `"<section>:<scope>"` (only this scope). A scope that is empty, is `read`, or has a
156
+ * `:` needs the whole section.
157
+ */
158
+ scope?: (input: Input) => string | undefined;
144
159
  /** `read` never changes state. `write` changes state. `destructive` deletes or publishes; the CLI asks for `--yes`, MCP marks `destructiveHint`, agents require approval by default. */
145
160
  kind: OperationKind;
146
161
  /** Standard Schema (valibot in this repo). Its Standard JSON Schema builds CLI flags and the MCP input schema. */
@@ -149,19 +164,14 @@ interface OperationDefinition<Input, Output> {
149
164
  cli?: {
150
165
  /** Defaults: namespace = section, command = verb. */
151
166
  namespace?: string;
167
+ /** A space groups commands: `jobs list` and `jobs show` run as `vitehub <namespace> jobs list` and `jobs show`. */
152
168
  command?: string;
153
169
  /** Input keys read from positional arguments, in order. */
154
170
  positional?: string[];
155
171
  /** Human output, written verbatim. Without it the CLI prints JSON. `--json` always prints JSON. */
156
172
  format?: (output: Output) => string;
157
- /** `vitehub <namespace>` runs this command when no command is named, such as `vitehub usage`. */
173
+ /** `vitehub <namespace>` runs this command when no command is named. */
158
174
  default?: boolean;
159
- /**
160
- * Route of the app that takes a signed dispatch of this operation, such as `/_vitehub/schedules/run`. With `--url`
161
- * and a dispatch key in the environment (`VITEHUB_DISPATCH_KEY`), the command signs the input and posts it there, so
162
- * a CI job needs no Console credentials. Without a key it calls the RPC.
163
- */
164
- dispatch?: string;
165
175
  };
166
176
  /** Largest request body in bytes. It can raise the 64 KiB default but not lower it. */
167
177
  maxRequestBytes?: number;
@@ -170,8 +180,16 @@ interface OperationDefinition<Input, Output> {
170
180
  * confirmation, and agents run it without approval. Without it, every call of a `destructive` operation asks.
171
181
  */
172
182
  readOnlyWhen?: (input: Input) => boolean;
173
- /** `false`: MCP does not offer the operation as a tool, such as an editor transport that only the Console uses. */
174
- mcp?: false;
183
+ /**
184
+ * How MCP offers the operation as a tool. `false`: MCP does not offer it, such as an editor transport that only the
185
+ * Console uses. `title`: the short title that clients show, instead of the name in words. `format`: the text of a
186
+ * result for the Agent, such as a list of lines. The result stays the structured content. Without `format`, the text
187
+ * is the result as JSON.
188
+ */
189
+ mcp?: false | {
190
+ title?: string;
191
+ format?: (output: NoInfer<Output>) => string;
192
+ };
175
193
  /** `false`: the operation never reads `context.user`, so the Console skips the session lookup for it. */
176
194
  user?: false;
177
195
  /**
@@ -182,24 +200,28 @@ interface OperationDefinition<Input, Output> {
182
200
  run: (input: Input, context: OperationContext) => Output | Promise<Output>;
183
201
  }
184
202
  /** An operation of any input and output, as a registry holds it. */
185
- interface AnyOperation extends Omit<OperationDefinition<unknown, unknown>, "cli" | "input" | "output" | "readOnlyWhen" | "run" | "section"> {
203
+ interface AnyOperation extends Omit<OperationDefinition<unknown, unknown>, "cli" | "input" | "mcp" | "output" | "readOnlyWhen" | "run" | "scope" | "section"> {
186
204
  readOnlyWhen?: (input: never) => boolean;
187
205
  cli?: {
188
206
  namespace?: string;
189
207
  command?: string;
190
208
  default?: boolean;
191
- dispatch?: string;
192
209
  positional?: string[];
193
210
  format?: (output: never) => string;
194
211
  };
212
+ mcp?: false | {
213
+ title?: string;
214
+ format?: (output: never) => string;
215
+ };
195
216
  input: StandardSchemaV1;
196
217
  output?: StandardSchemaV1;
197
218
  run: (input: never, context: OperationContext) => unknown;
219
+ scope?: (input: never) => string | undefined;
198
220
  section: string | false | ((input: never) => string | undefined);
199
221
  }
200
222
  /** The contribution of one plugin: operations, or a module that exports them. */
201
223
  interface OperationContributionEntry {
202
- /** Module the app imports, such as `@vite-hub/content/operations`. */
224
+ /** The absolute path of the module that generated code imports, such as `ownModule(import.meta.url, "operations")`. */
203
225
  module: string;
204
226
  /** Named export that holds an operation or an array of operations. Defaults to `default`. */
205
227
  export?: string;