@vite-hub/workflow 0.0.1 → 0.0.3

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 (37) hide show
  1. package/README.md +56 -6
  2. package/dist/{cloudflare-env-BVUMOgFK.d.ts → cloudflare-env-CIjdFTv6.d.ts} +2 -1
  3. package/dist/{cloudflare-env-g0Rf3ClH.js → cloudflare-env-mFp2Uj6Z.js} +7 -3
  4. package/dist/{cloudflare-vite-DcM5YVTP.js → cloudflare-vite-B0zel2Do.js} +4 -5
  5. package/dist/{config-DkgsQuXz.js → config-BDqB6I4E.js} +43 -5
  6. package/dist/index.d.ts +43 -18
  7. package/dist/index.js +99 -111
  8. package/dist/provider-operation-CWIV4k42.js +62 -0
  9. package/dist/runtime/cloudflare-runner.d.ts +2 -2
  10. package/dist/runtime/cloudflare-runner.js +15 -14
  11. package/dist/runtime/cloudflare-shared.d.ts +2 -2
  12. package/dist/runtime/cloudflare-shared.js +2 -2
  13. package/dist/runtime/cloudflare-vite.d.ts +3 -3
  14. package/dist/runtime/cloudflare-vite.js +1 -1
  15. package/dist/runtime/execute.d.ts +1 -1
  16. package/dist/runtime/openworkflow-worker.d.ts +4 -2
  17. package/dist/runtime/openworkflow-worker.js +63 -6
  18. package/dist/runtime/openworkflow.d.ts +22 -1
  19. package/dist/runtime/openworkflow.js +110 -37
  20. package/dist/runtime/state.d.ts +1 -1
  21. package/dist/runtime/vercel-vite.d.ts +58 -3
  22. package/dist/runtime/vercel-vite.js +3 -2
  23. package/dist/{types-ThDitg7Z.d.ts → types-BUlYBZwH.d.ts} +48 -6
  24. package/dist/vercel-D2_J5D_Y.js +217 -0
  25. package/dist/vite.d.ts +2 -5
  26. package/dist/vite.js +1753 -143
  27. package/package.json +45 -48
  28. package/dist/module-UYEnVfxy.js +0 -1546
  29. package/dist/nitro.d.ts +0 -19
  30. package/dist/nitro.js +0 -2
  31. package/dist/openworkflow-amN7IkGO.d.ts +0 -24
  32. package/dist/runtime/nitro-plugin.d.ts +0 -6
  33. package/dist/runtime/nitro-plugin.js +0 -14
  34. /package/dist/{_app-BVWpnNHo.d.ts → _app-DgwN4ulW.d.ts} +0 -0
  35. /package/dist/{app-BE3EYOWn.js → app-BZpq2cwC.js} +0 -0
  36. /package/dist/{cloudflare-CeHVSHoN.js → cloudflare-Cds1VIWa.js} +0 -0
  37. /package/dist/{cloudflare-shared-BIeY2kak.d.ts → cloudflare-shared-BVVgDSdq.d.ts} +0 -0
@@ -1,49 +1,111 @@
1
+ import { i as createWorkflowError, n as runWorkflowProviderOperation } from "../provider-operation-CWIV4k42.js";
1
2
  import { runWorkflowHandler } from "./execute.js";
2
3
  //#region src/runtime/openworkflow.ts
3
4
  const defaultImporter = new Function("specifier", "return import(specifier)");
4
5
  let openWorkflowImporter = defaultImporter;
5
- const runtimes = /* @__PURE__ */ new Map();
6
+ const defaultOpenWorkflowSqlitePath = ".vitehub/data/openworkflow.sqlite.db";
7
+ let runtimes = /* @__PURE__ */ new Map();
8
+ async function importOpenWorkflowModule(specifier, importer) {
9
+ return await runWorkflowProviderOperation("openworkflow", "import", () => importer(specifier));
10
+ }
6
11
  function readEnv(name) {
7
12
  const value = (globalThis.process?.env)?.[name];
8
13
  return typeof value === "string" && value.trim() ? value.trim() : void 0;
9
14
  }
15
+ function resolveRuntimeConfigValue(value) {
16
+ if (typeof value === "string" || typeof value === "undefined") return value;
17
+ for (const name of getRuntimeEnvNames(value)) {
18
+ const resolved = readEnv(name);
19
+ if (resolved) return resolved;
20
+ }
21
+ return typeof value.default === "string" && value.default.trim() ? value.default.trim() : void 0;
22
+ }
23
+ function getRuntimeEnvNames(value) {
24
+ return value.source?.names ?? (value.source?.name ? [value.source.name] : []);
25
+ }
26
+ function normalizeSqlitePath(path) {
27
+ if (/^(?:libsql:|https?:\/\/)/i.test(path)) throw new Error(`OpenWorkflow SQLite storage requires a local SQLite file path, received ${JSON.stringify(path)}.`);
28
+ if (/^[a-z][a-z0-9+.-]*:/i.test(path) && !path.startsWith("file:")) throw new Error(`OpenWorkflow SQLite storage received unsupported storage URL ${JSON.stringify(path)}.`);
29
+ return path.startsWith("file:") ? path.slice(5) : path;
30
+ }
31
+ async function prepareSqlitePath(path, importer) {
32
+ if (path !== ":memory:") {
33
+ const [{ mkdirSync }, { dirname }] = await Promise.all([importOpenWorkflowModule("node:fs", importer), importOpenWorkflowModule("node:path", importer)]);
34
+ mkdirSync(dirname(path), { recursive: true });
35
+ }
36
+ return path;
37
+ }
10
38
  function getOpenWorkflowConfig(config) {
11
39
  if (config.provider !== "openworkflow") throw new Error(`OpenWorkflow runtime requires workflow.provider "openworkflow", received "${config.provider}".`);
40
+ const sqlite = config.sqlite || {};
41
+ const sqlitePath = resolveRuntimeConfigValue(sqlite.path) || readEnv("OPENWORKFLOW_SQLITE_PATH");
42
+ if (sqlitePath) return {
43
+ backend: "sqlite",
44
+ namespaceId: sqlite.namespaceId || readEnv("OPENWORKFLOW_NAMESPACE_ID") || "production",
45
+ path: normalizeSqlitePath(sqlitePath),
46
+ runMigrations: sqlite.runMigrations
47
+ };
12
48
  const postgres = config.postgres || {};
13
- const url = postgres.url || readEnv("OPENWORKFLOW_POSTGRES_URL") || readEnv("DATABASE_URL");
14
- if (!url) throw new Error("Missing OpenWorkflow Postgres URL. Set workflow.postgres.url, OPENWORKFLOW_POSTGRES_URL, or DATABASE_URL.");
15
- return {
49
+ const url = resolveRuntimeConfigValue(postgres.url) || readEnv("OPENWORKFLOW_POSTGRES_URL") || readEnv("DATABASE_URL");
50
+ if (url) return {
51
+ backend: "postgres",
16
52
  namespaceId: postgres.namespaceId || readEnv("OPENWORKFLOW_NAMESPACE_ID") || "production",
17
53
  runMigrations: postgres.runMigrations,
18
54
  schema: postgres.schema || readEnv("OPENWORKFLOW_SCHEMA") || "openworkflow",
19
55
  url
20
56
  };
57
+ return {
58
+ backend: "sqlite",
59
+ namespaceId: sqlite.namespaceId || readEnv("OPENWORKFLOW_NAMESPACE_ID") || "production",
60
+ path: defaultOpenWorkflowSqlitePath,
61
+ runMigrations: sqlite.runMigrations
62
+ };
21
63
  }
22
64
  function getRuntimeKey(config) {
23
65
  return JSON.stringify(getOpenWorkflowConfig(config));
24
66
  }
25
- async function createOpenWorkflowRuntime(config) {
67
+ async function createOpenWorkflowRuntime(config, importer) {
26
68
  const options = getOpenWorkflowConfig(config);
27
- const [{ OpenWorkflow }, { BackendPostgres }] = await Promise.all([openWorkflowImporter("openworkflow"), openWorkflowImporter("openworkflow/postgres")]);
28
- const backend = await BackendPostgres.connect(options.url, {
29
- namespaceId: options.namespaceId,
30
- ...typeof options.runMigrations === "boolean" ? { runMigrations: options.runMigrations } : {},
31
- schema: options.schema
69
+ const [{ OpenWorkflow }, backendModule] = await Promise.all([importOpenWorkflowModule("openworkflow", importer), options.backend === "sqlite" ? importOpenWorkflowModule("openworkflow/sqlite", importer) : importOpenWorkflowModule("openworkflow/postgres", importer)]);
70
+ const { backend, client } = await runWorkflowProviderOperation("openworkflow", "connect", async () => {
71
+ let backend;
72
+ if (options.backend === "sqlite") backend = await backendModule.BackendSqlite.connect(await prepareSqlitePath(options.path, importer), {
73
+ namespaceId: options.namespaceId,
74
+ ...typeof options.runMigrations === "boolean" ? { runMigrations: options.runMigrations } : {}
75
+ });
76
+ else backend = await backendModule.BackendPostgres.connect(options.url, {
77
+ namespaceId: options.namespaceId,
78
+ ...typeof options.runMigrations === "boolean" ? { runMigrations: options.runMigrations } : {},
79
+ schema: options.schema
80
+ });
81
+ return {
82
+ backend,
83
+ client: new OpenWorkflow({ backend })
84
+ };
32
85
  });
33
86
  return {
34
87
  backend,
35
- client: new OpenWorkflow({ backend }),
88
+ client,
36
89
  workflows: /* @__PURE__ */ new Map()
37
90
  };
38
91
  }
39
92
  async function getOpenWorkflowRuntime(config) {
93
+ const cache = runtimes;
40
94
  const key = getRuntimeKey(config);
41
- let runtime = runtimes.get(key);
95
+ let runtime = cache.get(key);
42
96
  if (!runtime) {
43
- runtime = createOpenWorkflowRuntime(config);
44
- runtimes.set(key, runtime);
97
+ runtime = createOpenWorkflowRuntime(config, openWorkflowImporter);
98
+ cache.set(key, runtime);
99
+ runtime.catch(() => {
100
+ if (cache.get(key) === runtime) cache.delete(key);
101
+ });
45
102
  }
46
- return await runtime;
103
+ const resolved = await runtime;
104
+ if (cache !== runtimes) throw createWorkflowError({
105
+ code: "OPENWORKFLOW_RUNTIME_RESET",
106
+ details: { provider: "openworkflow" }
107
+ });
108
+ return resolved;
47
109
  }
48
110
  function toOpenWorkflowRetryPolicy(options) {
49
111
  const retries = options.retries;
@@ -108,33 +170,44 @@ function serializeOpenWorkflowRun(run, name) {
108
170
  };
109
171
  }
110
172
  async function runOpenWorkflow(config, name, payload, definition, options) {
111
- const handle = await (await registerOpenWorkflowDefinition(await getOpenWorkflowRuntime(config), name, definition)).run(payload, options.id ? { idempotencyKey: options.id } : void 0);
112
- return {
113
- id: handle.workflowRun.id,
114
- metadata: {
115
- ...options.id ? { idempotencyKey: options.id } : {},
116
- workflow: name
117
- },
118
- payload,
119
- provider: "openworkflow",
120
- status: normalizeOpenWorkflowStatus(handle.workflowRun.status)
121
- };
173
+ const workflow = await registerOpenWorkflowDefinition(await getOpenWorkflowRuntime(config), name, definition);
174
+ return await runWorkflowProviderOperation("openworkflow", "run", async () => {
175
+ const handle = await workflow.run(payload, options.id ? { idempotencyKey: options.id } : void 0);
176
+ return {
177
+ id: handle.workflowRun.id,
178
+ metadata: {
179
+ ...options.id ? { idempotencyKey: options.id } : {},
180
+ workflow: name
181
+ },
182
+ payload,
183
+ provider: "openworkflow",
184
+ status: normalizeOpenWorkflowStatus(handle.workflowRun.status)
185
+ };
186
+ });
122
187
  }
123
188
  async function getOpenWorkflowRun(config, name, id) {
124
- const serialized = serializeOpenWorkflowRun(await (await getOpenWorkflowRuntime(config)).backend.getWorkflowRun({ workflowRunId: id }), name);
125
- return serialized.id ? serialized : {
126
- id,
127
- provider: "openworkflow",
128
- status: "unknown"
129
- };
189
+ const runtime = await getOpenWorkflowRuntime(config);
190
+ return await runWorkflowProviderOperation("openworkflow", "get", async () => {
191
+ const serialized = serializeOpenWorkflowRun(await runtime.backend.getWorkflowRun({ workflowRunId: id }), name);
192
+ return serialized.id ? serialized : {
193
+ id,
194
+ provider: "openworkflow",
195
+ status: "unknown"
196
+ };
197
+ });
130
198
  }
131
199
  async function resetOpenWorkflowRuntime() {
132
- const settled = await Promise.allSettled(runtimes.values());
133
- runtimes.clear();
200
+ const closing = runtimes;
201
+ runtimes = /* @__PURE__ */ new Map();
134
202
  openWorkflowImporter = defaultImporter;
135
- await Promise.all(settled.map(async (entry) => {
136
- if (entry.status === "fulfilled") await entry.value.backend.stop();
137
- }));
203
+ const fulfilled = (await Promise.allSettled(closing.values())).flatMap((entry) => entry.status === "fulfilled" ? [entry.value] : []);
204
+ const failures = (await Promise.allSettled(fulfilled.map((runtime) => Promise.resolve().then(() => runtime.backend.stop())))).flatMap((entry) => entry.status === "rejected" ? [createWorkflowError({
205
+ cause: entry.reason,
206
+ code: "OPENWORKFLOW_BACKEND_CLOSE_FAILED",
207
+ details: { provider: "openworkflow" }
208
+ })] : []);
209
+ if (failures.length === 1) throw failures[0];
210
+ if (failures.length > 1) throw new AggregateError(failures, "OpenWorkflow backend cleanup failed for multiple runtimes.");
138
211
  }
139
212
  function setOpenWorkflowImporter(importer) {
140
213
  openWorkflowImporter = importer;
@@ -1,4 +1,4 @@
1
- import { h as WorkflowDefinitionRegistry, l as ResolvedWorkflowOptions, p as WorkflowDefinition } from "../types-ThDitg7Z.js";
1
+ import { h as WorkflowDefinitionRegistry, l as ResolvedWorkflowOptions, p as WorkflowDefinition } from "../types-BUlYBZwH.js";
2
2
 
3
3
  //#region src/runtime/state.d.ts
4
4
  interface WorkflowRunState<TResult = unknown> {
@@ -1,7 +1,62 @@
1
- import { h as WorkflowDefinitionRegistry, l as ResolvedWorkflowOptions } from "../types-ThDitg7Z.js";
2
- import { t as WorkflowApp } from "../_app-BVWpnNHo.js";
1
+ import { h as WorkflowDefinitionRegistry, l as ResolvedWorkflowOptions } from "../types-BUlYBZwH.js";
2
+ import { t as WorkflowApp } from "../_app-DgwN4ulW.js";
3
3
  import { IncomingMessage, ServerResponse } from "node:http";
4
4
 
5
+ //#region src/runtime/vercel.d.ts
6
+ interface VercelRun {
7
+ cancel: () => Promise<void>;
8
+ completedAt: Promise<Date | undefined>;
9
+ createdAt: Promise<Date>;
10
+ exists: Promise<boolean>;
11
+ returnValue: Promise<unknown>;
12
+ runId: string;
13
+ startedAt: Promise<Date | undefined>;
14
+ status: Promise<string>;
15
+ workflowName: Promise<string>;
16
+ }
17
+ interface VercelStep {
18
+ attempt: number;
19
+ completedAt?: Date;
20
+ error?: unknown;
21
+ startedAt?: Date;
22
+ status: string;
23
+ stepId: string;
24
+ stepName: string;
25
+ }
26
+ interface VercelWorkflowRuntime {
27
+ getRun: (id: string) => VercelRun;
28
+ listSteps: (id: string) => Promise<VercelStep[]>;
29
+ resumeHook: (token: string, payload: unknown) => Promise<{
30
+ runId: string;
31
+ }>;
32
+ start: (handler: (...args: never[]) => unknown, args: unknown[]) => Promise<VercelRun>;
33
+ }
34
+ interface VercelWorkflowApiModule {
35
+ getRun: (id: string) => VercelRun;
36
+ resumeHook: VercelWorkflowRuntime["resumeHook"];
37
+ start: VercelWorkflowRuntime["start"];
38
+ }
39
+ interface VercelWorkflowRuntimeModule {
40
+ getWorld: () => Promise<{
41
+ steps: {
42
+ list: (options: unknown) => Promise<{
43
+ cursor?: string;
44
+ data: unknown[];
45
+ hasMore: boolean;
46
+ }>;
47
+ };
48
+ }> | {
49
+ steps: {
50
+ list: (options: unknown) => Promise<{
51
+ cursor?: string;
52
+ data: unknown[];
53
+ hasMore: boolean;
54
+ }>;
55
+ };
56
+ };
57
+ }
58
+ declare function setVercelWorkflowRuntimeModules(api: VercelWorkflowApiModule, runtime: VercelWorkflowRuntimeModule): void;
59
+ //#endregion
5
60
  //#region src/runtime/vercel-vite.d.ts
6
61
  interface WorkflowVercelServerOptions {
7
62
  app?: WorkflowApp;
@@ -11,4 +66,4 @@ interface WorkflowVercelServerOptions {
11
66
  type WorkflowVercelServer = (req: IncomingMessage, res: ServerResponse) => unknown;
12
67
  declare function createWorkflowVercelServer(options?: WorkflowVercelServerOptions): WorkflowVercelServer;
13
68
  //#endregion
14
- export { WorkflowVercelServer, createWorkflowVercelServer };
69
+ export { WorkflowVercelServer, createWorkflowVercelServer, setVercelWorkflowRuntimeModules };
@@ -1,5 +1,6 @@
1
1
  import { runWithWorkflowRuntimeEvent, setWorkflowRuntimeConfig, setWorkflowRuntimeRegistry } from "./state.js";
2
- import { t as resolveAppFetch } from "../app-BE3EYOWn.js";
2
+ import { i as setVercelWorkflowRuntimeModules } from "../vercel-D2_J5D_Y.js";
3
+ import { t as resolveAppFetch } from "../app-BZpq2cwC.js";
3
4
  import { waitUntil } from "@vercel/functions";
4
5
  import { H3 } from "h3";
5
6
  //#region ../internal/src/runtime/vercel-hosted.ts
@@ -45,4 +46,4 @@ function createWorkflowVercelServer(options = {}) {
45
46
  });
46
47
  }
47
48
  //#endregion
48
- export { createWorkflowVercelServer };
49
+ export { createWorkflowVercelServer, setVercelWorkflowRuntimeModules };
@@ -25,19 +25,38 @@ interface OpenWorkflowPostgresOptions {
25
25
  namespaceId?: string;
26
26
  runMigrations?: boolean;
27
27
  schema?: string;
28
- url?: string;
28
+ url?: WorkflowRuntimeConfigValue;
29
+ }
30
+ interface WorkflowRuntimeEnvDeclarationLike {
31
+ default?: unknown;
32
+ kind: "env-variable";
33
+ source?: {
34
+ kind: "env";
35
+ name: string;
36
+ names?: string[];
37
+ };
38
+ }
39
+ type WorkflowRuntimeConfigValue = string | WorkflowRuntimeEnvDeclarationLike;
40
+ interface OpenWorkflowSqliteOptions {
41
+ namespaceId?: string;
42
+ path?: WorkflowRuntimeConfigValue;
43
+ runMigrations?: boolean;
29
44
  }
30
45
  interface OpenWorkflowWorkerOptions {
31
46
  concurrency?: number;
32
47
  }
33
48
  interface OpenWorkflowProviderOptions extends WorkflowSharedOptions {
49
+ database?: string;
34
50
  postgres?: OpenWorkflowPostgresOptions;
35
51
  provider: "openworkflow";
52
+ sqlite?: OpenWorkflowSqliteOptions;
36
53
  worker?: OpenWorkflowWorkerOptions;
37
54
  }
38
55
  interface InferredWorkflowProviderOptions extends WorkflowSharedOptions {
56
+ database?: string;
39
57
  postgres?: OpenWorkflowPostgresOptions;
40
58
  provider?: undefined;
59
+ sqlite?: OpenWorkflowSqliteOptions;
41
60
  worker?: OpenWorkflowWorkerOptions;
42
61
  }
43
62
  type WorkflowProviderOptions = CloudflareWorkflowProviderOptions | OpenWorkflowProviderOptions | VercelWorkflowProviderOptions;
@@ -45,14 +64,30 @@ type WorkflowModuleProviderOptions = InferredWorkflowProviderOptions | WorkflowP
45
64
  type WorkflowModuleOptions = false | WorkflowModuleProviderOptions;
46
65
  type ResolvedWorkflowOptions = WorkflowProviderOptions;
47
66
  interface WorkflowRun<TPayload = unknown, TResult = unknown> {
67
+ completedAt?: Date;
68
+ createdAt?: Date;
48
69
  id: string;
49
70
  provider: WorkflowProvider;
50
71
  result?: TResult;
72
+ startedAt?: Date;
51
73
  status: WorkflowRunStatus;
74
+ steps?: WorkflowRunStep[];
52
75
  metadata?: unknown;
53
76
  payload?: TPayload;
54
77
  }
55
- type WorkflowRunStatus = "queued" | "running" | "completed" | "failed" | "unknown";
78
+ type WorkflowRunStatus = "queued" | "running" | "completed" | "failed" | "cancelled" | "unknown";
79
+ interface WorkflowRunStep {
80
+ attempt: number;
81
+ completedAt?: Date;
82
+ error?: {
83
+ code?: string;
84
+ message: string;
85
+ };
86
+ id: string;
87
+ name: string;
88
+ startedAt?: Date;
89
+ status: WorkflowRunStatus;
90
+ }
56
91
  interface WorkflowStepOptions {
57
92
  retries?: {
58
93
  backoff?: string;
@@ -85,15 +120,17 @@ interface WorkflowCreateOptions<TPayload = unknown, TResult = unknown> {
85
120
  }) => Promise<WorkflowRunIdValue> | WorkflowRunIdValue;
86
121
  name?: string;
87
122
  }
88
- interface WorkflowDefinitionOptions {
123
+ interface WorkflowDefinitionOptions<TPayload = unknown, TResult = unknown> {
89
124
  id?: string;
125
+ native?: WorkflowHandler<TPayload, TResult>;
90
126
  rootStep?: boolean;
91
127
  }
92
128
  interface WorkflowDefinition<TPayload = unknown, TResult = unknown> {
93
129
  handler: WorkflowHandler<TPayload, TResult>;
94
- options?: WorkflowDefinitionOptions;
130
+ options?: WorkflowDefinitionOptions<TPayload, TResult>;
95
131
  }
96
132
  interface WorkflowHandle<TPayload = unknown, TResult = unknown> {
133
+ cancel: (id: string) => Promise<WorkflowRun<TPayload, TResult>>;
97
134
  defer: (payload?: TPayload, options?: WorkflowStartOptions) => Promise<WorkflowRun<TPayload>>;
98
135
  getRun: (id: string) => Promise<WorkflowRun<TPayload, TResult>>;
99
136
  name: string;
@@ -105,6 +142,10 @@ interface WorkflowStartOptions {
105
142
  interface WorkflowDeferOptions extends WorkflowStartOptions {
106
143
  deferred?: boolean;
107
144
  }
145
+ interface WorkflowSignalResult {
146
+ id: string;
147
+ provider: WorkflowProvider;
148
+ }
108
149
  interface WorkflowDefinitionRegistry {
109
150
  [name: string]: () => Promise<{
110
151
  default?: WorkflowDefinition;
@@ -112,10 +153,11 @@ interface WorkflowDefinitionRegistry {
112
153
  } | WorkflowDefinition>;
113
154
  }
114
155
  interface DiscoveredWorkflowDefinition {
156
+ agentIdentity?: string;
115
157
  handler: string;
116
158
  name: string;
117
- source?: "inline" | "nitro-server-workflows" | "vite-suffix";
159
+ source?: "agent-workflow" | "inline" | "server-workflows" | "vite-suffix";
118
160
  steps?: string[];
119
161
  }
120
162
  //#endregion
121
- export { WorkflowStepRunner as A, WorkflowProviderStep as C, WorkflowStartOptions as D, WorkflowSharedOptions as E, WorkflowStepFunction as O, WorkflowProviderOptions as S, WorkflowRunStatus as T, WorkflowHandle as _, InferredWorkflowProviderOptions as a, WorkflowModuleProviderOptions as b, OpenWorkflowWorkerOptions as c, WorkflowCreateOptions as d, WorkflowDeferOptions as f, WorkflowExecutionContext as g, WorkflowDefinitionRegistry as h, DiscoveredWorkflowDefinition as i, WorkflowStepOptions as k, ResolvedWorkflowOptions as l, WorkflowDefinitionOptions as m, CloudflareWorkflowInstance as n, OpenWorkflowPostgresOptions as o, WorkflowDefinition as p, CloudflareWorkflowProviderOptions as r, OpenWorkflowProviderOptions as s, CloudflareWorkflowBinding as t, VercelWorkflowProviderOptions as u, WorkflowHandler as v, WorkflowRun as w, WorkflowProvider as x, WorkflowModuleOptions as y };
163
+ export { WorkflowStepFunction as A, WorkflowProviderStep as C, WorkflowSharedOptions as D, WorkflowRunStep as E, WorkflowStepRunner as M, WorkflowSignalResult as O, WorkflowProviderOptions as S, WorkflowRunStatus as T, WorkflowHandle as _, InferredWorkflowProviderOptions as a, WorkflowModuleProviderOptions as b, OpenWorkflowWorkerOptions as c, WorkflowCreateOptions as d, WorkflowDeferOptions as f, WorkflowExecutionContext as g, WorkflowDefinitionRegistry as h, DiscoveredWorkflowDefinition as i, WorkflowStepOptions as j, WorkflowStartOptions as k, ResolvedWorkflowOptions as l, WorkflowDefinitionOptions as m, CloudflareWorkflowInstance as n, OpenWorkflowPostgresOptions as o, WorkflowDefinition as p, CloudflareWorkflowProviderOptions as r, OpenWorkflowProviderOptions as s, CloudflareWorkflowBinding as t, VercelWorkflowProviderOptions as u, WorkflowHandler as v, WorkflowRun as w, WorkflowProvider as x, WorkflowModuleOptions as y };
@@ -0,0 +1,217 @@
1
+ import { i as createWorkflowError, n as runWorkflowProviderOperation, r as safeWorkflowName, t as isWorkflowBoundaryError } from "./provider-operation-CWIV4k42.js";
2
+ //#region src/runtime/vercel.ts
3
+ async function loadVercelWorkflowRuntime() {
4
+ const importVercelWorkflow = new Function("specifier", "return import(specifier)");
5
+ const [api, runtime] = await Promise.all([importVercelWorkflow("workflow/api"), importVercelWorkflow("workflow/runtime")]);
6
+ return createVercelWorkflowRuntime(api, runtime);
7
+ }
8
+ function createVercelWorkflowRuntime(api, runtime) {
9
+ const { getRun, resumeHook, start } = api;
10
+ const { getWorld } = runtime;
11
+ return {
12
+ getRun,
13
+ async listSteps(id) {
14
+ const steps = [];
15
+ let cursor;
16
+ do {
17
+ const page = await (await getWorld()).steps.list({
18
+ pagination: {
19
+ cursor,
20
+ limit: 1e3,
21
+ sortOrder: "asc"
22
+ },
23
+ resolveData: "none",
24
+ runId: id
25
+ });
26
+ steps.push(...page.data);
27
+ cursor = page.hasMore && page.cursor ? page.cursor : void 0;
28
+ } while (cursor);
29
+ return steps;
30
+ },
31
+ resumeHook,
32
+ start
33
+ };
34
+ }
35
+ let runtimeLoader = loadVercelWorkflowRuntime;
36
+ function setVercelWorkflowRuntimeModules(api, runtime) {
37
+ runtimeLoader = async () => createVercelWorkflowRuntime(api, runtime);
38
+ }
39
+ async function getVercelWorkflowRuntime() {
40
+ try {
41
+ return await runtimeLoader();
42
+ } catch (error) {
43
+ if (isWorkflowBoundaryError(error)) throw error;
44
+ throw createWorkflowError({
45
+ cause: error,
46
+ code: "VERCEL_WORKFLOW_SDK_LOAD_FAILED",
47
+ details: { provider: "vercel" }
48
+ });
49
+ }
50
+ }
51
+ const statusMap = {
52
+ cancelled: "cancelled",
53
+ completed: "completed",
54
+ failed: "failed",
55
+ pending: "queued",
56
+ running: "running"
57
+ };
58
+ function invalidVercelResult(field) {
59
+ return /* @__PURE__ */ new TypeError(`Vercel Workflow provider returned an invalid ${field}.`);
60
+ }
61
+ function normalizeStatus(status) {
62
+ if (typeof status !== "string") throw invalidVercelResult("status");
63
+ return statusMap[status.toLowerCase()] || "unknown";
64
+ }
65
+ function normalizeRunId(id) {
66
+ if (typeof id !== "string" || !id) throw invalidVercelResult("run ID");
67
+ return id;
68
+ }
69
+ function normalizeDate(value, field) {
70
+ if (value === void 0) return void 0;
71
+ if (!(value instanceof Date) || !Number.isFinite(value.getTime())) throw invalidVercelResult(field);
72
+ return value;
73
+ }
74
+ function normalizeStepError(error) {
75
+ if (error === void 0 || error === null) return void 0;
76
+ if (error instanceof Error) return { message: error.message };
77
+ if (typeof error === "string") try {
78
+ return normalizeStepError(JSON.parse(error)) || { message: error };
79
+ } catch {
80
+ return { message: error };
81
+ }
82
+ if (typeof error === "object") {
83
+ const value = error;
84
+ if (typeof value.message === "string") return {
85
+ ...typeof value.code === "string" ? { code: value.code } : {},
86
+ message: value.message
87
+ };
88
+ if (value.error !== void 0) return normalizeStepError(value.error);
89
+ }
90
+ return { message: "Workflow step failed." };
91
+ }
92
+ function normalizeSteps(steps) {
93
+ if (!Array.isArray(steps)) throw invalidVercelResult("step list");
94
+ return steps.map((step) => {
95
+ if (typeof step !== "object" || step === null) throw invalidVercelResult("step");
96
+ const value = step;
97
+ if (typeof value.attempt !== "number" || !Number.isFinite(value.attempt)) throw invalidVercelResult("step attempt");
98
+ if (typeof value.stepId !== "string" || !value.stepId) throw invalidVercelResult("step ID");
99
+ if (typeof value.stepName !== "string" || !value.stepName) throw invalidVercelResult("step name");
100
+ return {
101
+ attempt: value.attempt,
102
+ completedAt: normalizeDate(value.completedAt, "step completion date"),
103
+ error: normalizeStepError(value.error),
104
+ id: value.stepId,
105
+ name: value.stepName,
106
+ startedAt: normalizeDate(value.startedAt, "step start date"),
107
+ status: normalizeStatus(value.status)
108
+ };
109
+ });
110
+ }
111
+ async function readRunIdentity(run) {
112
+ const exists = await run.exists;
113
+ if (typeof exists !== "boolean") throw invalidVercelResult("existence state");
114
+ if (!exists) return { exists };
115
+ const workflowName = await run.workflowName;
116
+ if (typeof workflowName !== "string") throw invalidVercelResult("workflow name");
117
+ return {
118
+ exists,
119
+ workflowName
120
+ };
121
+ }
122
+ function getNativeWorkflowName(name, definition) {
123
+ const workflowName = (definition.options?.native)?.workflowId;
124
+ if (!workflowName) throw createWorkflowError({
125
+ code: "WORKFLOW_NATIVE_ENTRY_INVALID",
126
+ details: {
127
+ ...safeWorkflowName(name) ? { name } : {},
128
+ provider: "vercel"
129
+ }
130
+ });
131
+ return workflowName;
132
+ }
133
+ async function inspectVercelWorkflowRun(name, definition, id, payload) {
134
+ const runtime = await getVercelWorkflowRuntime();
135
+ const run = await runWorkflowProviderOperation("vercel", "get-run", () => runtime.getRun(id));
136
+ const identity = await runWorkflowProviderOperation("vercel", "get-run", () => readRunIdentity(run));
137
+ if (!identity.exists || identity.workflowName !== getNativeWorkflowName(name, definition)) return {
138
+ id,
139
+ provider: "vercel",
140
+ status: "unknown"
141
+ };
142
+ const [snapshot, steps] = await Promise.all([runWorkflowProviderOperation("vercel", "get-run", async () => {
143
+ const [status, createdAt, startedAt, completedAt] = await Promise.all([
144
+ run.status,
145
+ run.createdAt,
146
+ run.startedAt,
147
+ run.completedAt
148
+ ]);
149
+ return {
150
+ completedAt: normalizeDate(completedAt, "completion date"),
151
+ createdAt: normalizeDate(createdAt, "creation date"),
152
+ startedAt: normalizeDate(startedAt, "start date"),
153
+ status: normalizeStatus(status)
154
+ };
155
+ }), runWorkflowProviderOperation("vercel", "list-steps", async () => normalizeSteps(await runtime.listSteps(id)))]);
156
+ const result = snapshot.status === "completed" ? await runWorkflowProviderOperation("vercel", "get-run", () => run.returnValue) : void 0;
157
+ return {
158
+ completedAt: snapshot.completedAt,
159
+ createdAt: snapshot.createdAt,
160
+ id,
161
+ metadata: { workflow: name },
162
+ payload,
163
+ provider: "vercel",
164
+ result,
165
+ startedAt: snapshot.startedAt,
166
+ status: snapshot.status,
167
+ steps
168
+ };
169
+ }
170
+ async function startVercelWorkflow(name, definition, payload) {
171
+ const native = definition.options?.native;
172
+ if (!native) throw createWorkflowError({
173
+ code: "WORKFLOW_NATIVE_ENTRY_REQUIRED",
174
+ details: {
175
+ ...safeWorkflowName(name) ? { name } : {},
176
+ provider: "vercel"
177
+ }
178
+ });
179
+ const context = {
180
+ name,
181
+ payload,
182
+ provider: "vercel"
183
+ };
184
+ const runtime = await getVercelWorkflowRuntime();
185
+ return {
186
+ id: await runWorkflowProviderOperation("vercel", "start", async () => {
187
+ return normalizeRunId((await runtime.start(native, [context])).runId);
188
+ }),
189
+ metadata: { workflow: name },
190
+ payload,
191
+ provider: "vercel",
192
+ status: "queued"
193
+ };
194
+ }
195
+ async function cancelVercelWorkflow(name, definition, id) {
196
+ const runtime = await getVercelWorkflowRuntime();
197
+ const run = await runWorkflowProviderOperation("vercel", "get-run", () => runtime.getRun(id));
198
+ const identity = await runWorkflowProviderOperation("vercel", "get-run", () => readRunIdentity(run));
199
+ if (!identity.exists || identity.workflowName !== getNativeWorkflowName(name, definition)) return {
200
+ id,
201
+ provider: "vercel",
202
+ status: "unknown"
203
+ };
204
+ await runWorkflowProviderOperation("vercel", "cancel", () => run.cancel());
205
+ return await inspectVercelWorkflowRun(name, definition, id);
206
+ }
207
+ async function resumeVercelWorkflowSignal(token, payload) {
208
+ const runtime = await getVercelWorkflowRuntime();
209
+ return {
210
+ id: await runWorkflowProviderOperation("vercel", "resume-signal", async () => {
211
+ return normalizeRunId((await runtime.resumeHook(token, payload)).runId);
212
+ }),
213
+ provider: "vercel"
214
+ };
215
+ }
216
+ //#endregion
217
+ export { startVercelWorkflow as a, setVercelWorkflowRuntimeModules as i, inspectVercelWorkflowRun as n, resumeVercelWorkflowSignal as r, cancelVercelWorkflow as t };
package/dist/vite.d.ts CHANGED
@@ -1,11 +1,8 @@
1
- import { y as WorkflowModuleOptions } from "./types-ThDitg7Z.js";
2
- import { NitroModule } from "nitro/types";
1
+ import { y as WorkflowModuleOptions } from "./types-BUlYBZwH.js";
3
2
  import { Plugin } from "vite";
4
3
 
5
4
  //#region src/vite.d.ts
6
- type WorkflowVitePlugin = Plugin & {
7
- nitro: NitroModule;
8
- };
5
+ type WorkflowVitePlugin = Plugin;
9
6
  declare function hubWorkflow(options?: WorkflowModuleOptions): WorkflowVitePlugin;
10
7
  declare module "vite" {
11
8
  interface UserConfig {