@vite-hub/workflow 0.0.0 → 0.0.2

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.
@@ -0,0 +1,23 @@
1
+ import { f as WorkflowDeferOptions, l as ResolvedWorkflowOptions, p as WorkflowDefinition, w as WorkflowRun } from "../types-BUlYBZwH.js";
2
+
3
+ //#region src/runtime/openworkflow.d.ts
4
+ type OpenWorkflowModule = typeof import("openworkflow");
5
+ type OpenWorkflowPostgresModule = typeof import("openworkflow/postgres");
6
+ type OpenWorkflowSqliteModule = typeof import("openworkflow/sqlite");
7
+ type OpenWorkflowClient = InstanceType<OpenWorkflowModule["OpenWorkflow"]>;
8
+ type OpenWorkflowBackend = Awaited<ReturnType<OpenWorkflowPostgresModule["BackendPostgres"]["connect"]>> | ReturnType<OpenWorkflowSqliteModule["BackendSqlite"]["connect"]>;
9
+ type OpenWorkflowRunnable = ReturnType<OpenWorkflowClient["defineWorkflow"]>;
10
+ type OpenWorkflowImporter = <T>(specifier: string) => Promise<T>;
11
+ interface OpenWorkflowRuntime {
12
+ backend: OpenWorkflowBackend;
13
+ client: OpenWorkflowClient;
14
+ workflows: Map<string, OpenWorkflowRunnable>;
15
+ }
16
+ declare function getOpenWorkflowRuntime(config: ResolvedWorkflowOptions): Promise<OpenWorkflowRuntime>;
17
+ declare function registerOpenWorkflowDefinition(runtime: OpenWorkflowRuntime, name: string, definition: WorkflowDefinition): Promise<OpenWorkflowRunnable>;
18
+ declare function runOpenWorkflow<TPayload = unknown, TResult = unknown>(config: ResolvedWorkflowOptions, name: string, payload: TPayload | undefined, definition: WorkflowDefinition<TPayload, TResult>, options: WorkflowDeferOptions): Promise<WorkflowRun<TPayload, TResult>>;
19
+ declare function getOpenWorkflowRun<TPayload = unknown, TResult = unknown>(config: ResolvedWorkflowOptions, name: string, id: string): Promise<WorkflowRun<TPayload, TResult>>;
20
+ declare function resetOpenWorkflowRuntime(): Promise<void>;
21
+ declare function setOpenWorkflowImporter(importer: OpenWorkflowImporter): void;
22
+ //#endregion
23
+ export { getOpenWorkflowRun, getOpenWorkflowRuntime, registerOpenWorkflowDefinition, resetOpenWorkflowRuntime, runOpenWorkflow, setOpenWorkflowImporter };
@@ -0,0 +1,216 @@
1
+ import { i as createWorkflowError, n as runWorkflowProviderOperation } from "../provider-operation-CWIV4k42.js";
2
+ import { runWorkflowHandler } from "./execute.js";
3
+ //#region src/runtime/openworkflow.ts
4
+ const defaultImporter = new Function("specifier", "return import(specifier)");
5
+ let openWorkflowImporter = defaultImporter;
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
+ }
11
+ function readEnv(name) {
12
+ const value = (globalThis.process?.env)?.[name];
13
+ return typeof value === "string" && value.trim() ? value.trim() : void 0;
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
+ }
38
+ function getOpenWorkflowConfig(config) {
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
+ };
48
+ const postgres = config.postgres || {};
49
+ const url = resolveRuntimeConfigValue(postgres.url) || readEnv("OPENWORKFLOW_POSTGRES_URL") || readEnv("DATABASE_URL");
50
+ if (url) return {
51
+ backend: "postgres",
52
+ namespaceId: postgres.namespaceId || readEnv("OPENWORKFLOW_NAMESPACE_ID") || "production",
53
+ runMigrations: postgres.runMigrations,
54
+ schema: postgres.schema || readEnv("OPENWORKFLOW_SCHEMA") || "openworkflow",
55
+ url
56
+ };
57
+ return {
58
+ backend: "sqlite",
59
+ namespaceId: sqlite.namespaceId || readEnv("OPENWORKFLOW_NAMESPACE_ID") || "production",
60
+ path: defaultOpenWorkflowSqlitePath,
61
+ runMigrations: sqlite.runMigrations
62
+ };
63
+ }
64
+ function getRuntimeKey(config) {
65
+ return JSON.stringify(getOpenWorkflowConfig(config));
66
+ }
67
+ async function createOpenWorkflowRuntime(config, importer) {
68
+ const options = getOpenWorkflowConfig(config);
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
+ };
85
+ });
86
+ return {
87
+ backend,
88
+ client,
89
+ workflows: /* @__PURE__ */ new Map()
90
+ };
91
+ }
92
+ async function getOpenWorkflowRuntime(config) {
93
+ const cache = runtimes;
94
+ const key = getRuntimeKey(config);
95
+ let runtime = cache.get(key);
96
+ if (!runtime) {
97
+ runtime = createOpenWorkflowRuntime(config, openWorkflowImporter);
98
+ cache.set(key, runtime);
99
+ runtime.catch(() => {
100
+ if (cache.get(key) === runtime) cache.delete(key);
101
+ });
102
+ }
103
+ const resolved = await runtime;
104
+ if (cache !== runtimes) throw createWorkflowError({
105
+ code: "OPENWORKFLOW_RUNTIME_RESET",
106
+ details: { provider: "openworkflow" }
107
+ });
108
+ return resolved;
109
+ }
110
+ function toOpenWorkflowRetryPolicy(options) {
111
+ const retries = options.retries;
112
+ if (!retries) return;
113
+ return {
114
+ ...retries.backoff ? { backoffCoefficient: retries.backoff === "exponential" ? 2 : 1 } : {},
115
+ ...retries.delay ? { initialInterval: retries.delay } : {},
116
+ ...typeof retries.limit === "number" ? { maximumAttempts: retries.limit } : {}
117
+ };
118
+ }
119
+ function createOpenWorkflowProviderStep(step) {
120
+ return { async do(name, options, run) {
121
+ return await step.run({
122
+ name,
123
+ ...toOpenWorkflowRetryPolicy(options) ? { retryPolicy: toOpenWorkflowRetryPolicy(options) } : {}
124
+ }, run);
125
+ } };
126
+ }
127
+ async function registerOpenWorkflowDefinition(runtime, name, definition) {
128
+ const existing = runtime.workflows.get(name);
129
+ if (existing) return existing;
130
+ const workflow = runtime.client.defineWorkflow({ name }, async ({ input, run, step }) => {
131
+ return await runWorkflowHandler({
132
+ id: run.id,
133
+ name,
134
+ payload: input,
135
+ provider: "openworkflow",
136
+ step: createOpenWorkflowProviderStep(step)
137
+ }, definition);
138
+ });
139
+ runtime.workflows.set(name, workflow);
140
+ return workflow;
141
+ }
142
+ function normalizeOpenWorkflowStatus(status) {
143
+ switch (String(status || "").toLowerCase()) {
144
+ case "completed":
145
+ case "succeeded": return "completed";
146
+ case "canceled":
147
+ case "failed": return "failed";
148
+ case "pending": return "queued";
149
+ case "running":
150
+ case "sleeping": return "running";
151
+ default: return "unknown";
152
+ }
153
+ }
154
+ function serializeOpenWorkflowRun(run, name) {
155
+ if (!run || run.workflowName !== name) return {
156
+ id: run?.id || "",
157
+ provider: "openworkflow",
158
+ status: "unknown"
159
+ };
160
+ return {
161
+ id: run.id,
162
+ metadata: run.error || {
163
+ namespaceId: run.namespaceId,
164
+ version: run.version,
165
+ workflowName: run.workflowName
166
+ },
167
+ provider: "openworkflow",
168
+ result: run.output ?? void 0,
169
+ status: normalizeOpenWorkflowStatus(run.status)
170
+ };
171
+ }
172
+ async function runOpenWorkflow(config, name, payload, definition, options) {
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
+ });
187
+ }
188
+ async function getOpenWorkflowRun(config, name, id) {
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
+ });
198
+ }
199
+ async function resetOpenWorkflowRuntime() {
200
+ const closing = runtimes;
201
+ runtimes = /* @__PURE__ */ new Map();
202
+ openWorkflowImporter = defaultImporter;
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.");
211
+ }
212
+ function setOpenWorkflowImporter(importer) {
213
+ openWorkflowImporter = importer;
214
+ }
215
+ //#endregion
216
+ export { getOpenWorkflowRun, getOpenWorkflowRuntime, registerOpenWorkflowDefinition, resetOpenWorkflowRuntime, runOpenWorkflow, setOpenWorkflowImporter };
@@ -0,0 +1,35 @@
1
+ import { h as WorkflowDefinitionRegistry, l as ResolvedWorkflowOptions, p as WorkflowDefinition } from "../types-BUlYBZwH.js";
2
+
3
+ //#region src/runtime/state.d.ts
4
+ interface WorkflowRunState<TResult = unknown> {
5
+ error?: unknown;
6
+ expiresAt?: number;
7
+ promise: Promise<{
8
+ result?: TResult;
9
+ status: "completed" | "failed";
10
+ error?: unknown;
11
+ }>;
12
+ result?: TResult;
13
+ status: "running" | "completed" | "failed";
14
+ }
15
+ declare function setWorkflowRuntimeConfig(config: false | ResolvedWorkflowOptions | undefined): void;
16
+ declare function getWorkflowRuntimeConfig(): false | ResolvedWorkflowOptions | undefined;
17
+ declare function setWorkflowRuntimeRegistry(registry: WorkflowDefinitionRegistry | undefined): void;
18
+ declare function getWorkflowRuntimeRegistry(): WorkflowDefinitionRegistry | undefined;
19
+ declare function getInlineWorkflowDefinitions(): ReadonlyMap<string, WorkflowDefinition>;
20
+ declare function takeInlineWorkflowDefinition(name: string): WorkflowDefinition | undefined;
21
+ declare function takeInlineWorkflowDefinitionForModule(name: string, loaded: unknown): WorkflowDefinition | undefined;
22
+ declare function registerInlineWorkflowDefinition(name: string, definition: WorkflowDefinition): void;
23
+ declare function enterWorkflowRuntimeEvent(event: unknown): void;
24
+ declare function getWorkflowRuntimeEvent(): unknown;
25
+ declare function runWithWorkflowRuntimeEvent<T>(event: unknown, run: () => T | Promise<T>): Promise<T>;
26
+ declare function loadWorkflowDefinition(name: string): Promise<WorkflowDefinition | undefined>;
27
+ declare function setWorkflowRun<TResult = unknown>(name: string, id: string, promise: Promise<{
28
+ result?: TResult;
29
+ status: "completed" | "failed";
30
+ error?: unknown;
31
+ }>): WorkflowRunState<TResult>;
32
+ declare function getWorkflowRunState(name: string, id: string): WorkflowRunState | undefined;
33
+ declare function resetWorkflowRuntime(): void;
34
+ //#endregion
35
+ export { WorkflowRunState, enterWorkflowRuntimeEvent, getInlineWorkflowDefinitions, getWorkflowRunState, getWorkflowRuntimeConfig, getWorkflowRuntimeEvent, getWorkflowRuntimeRegistry, loadWorkflowDefinition, registerInlineWorkflowDefinition, resetWorkflowRuntime, runWithWorkflowRuntimeEvent, setWorkflowRun, setWorkflowRuntimeConfig, setWorkflowRuntimeRegistry, takeInlineWorkflowDefinition, takeInlineWorkflowDefinitionForModule };
@@ -0,0 +1,179 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ //#region src/runtime/state.ts
3
+ const RUNS_LIMIT = 1024;
4
+ const RUNS_TTL_MS = 300 * 1e3;
5
+ let runtimeConfig;
6
+ let runtimeRegistry;
7
+ const inlineRegistry = /* @__PURE__ */ new Map();
8
+ const loadingRegistryEntries = /* @__PURE__ */ new Map();
9
+ const loadedRegistryEntries = /* @__PURE__ */ new Map();
10
+ let fallbackEvent;
11
+ const eventStorage = new AsyncLocalStorage();
12
+ const loadingRegistryStorage = new AsyncLocalStorage();
13
+ const loadingInlineRegistryStorage = new AsyncLocalStorage();
14
+ const runs = /* @__PURE__ */ new Map();
15
+ function getRunKey(name, id) {
16
+ return `${name}\0${id}`;
17
+ }
18
+ function pruneWorkflowRuns() {
19
+ const now = Date.now();
20
+ for (const [key, run] of runs) if (run.expiresAt && run.expiresAt <= now) runs.delete(key);
21
+ }
22
+ function setWorkflowRuntimeConfig(config) {
23
+ runtimeConfig = config;
24
+ }
25
+ function getWorkflowRuntimeConfig() {
26
+ return runtimeConfig;
27
+ }
28
+ function setWorkflowRuntimeRegistry(registry) {
29
+ runtimeRegistry = registry;
30
+ loadedRegistryEntries.clear();
31
+ }
32
+ function getWorkflowRuntimeRegistry() {
33
+ return runtimeRegistry;
34
+ }
35
+ function getInlineWorkflowDefinitions() {
36
+ return inlineRegistry;
37
+ }
38
+ function takeInlineWorkflowDefinition(name) {
39
+ const definition = inlineRegistry.get(name);
40
+ inlineRegistry.delete(name);
41
+ loadingInlineRegistryStorage.getStore()?.delete(name);
42
+ return definition;
43
+ }
44
+ function isWorkflowHandle(value) {
45
+ return typeof value === "object" && value !== null && typeof value.name === "string" && typeof value.defer === "function" && typeof value.getRun === "function" && typeof value.run === "function";
46
+ }
47
+ function findExportedInlineWorkflowDefinition(name, loaded, definitions) {
48
+ const namedDefinition = definitions.get(name);
49
+ if (namedDefinition) return {
50
+ definition: namedDefinition,
51
+ name
52
+ };
53
+ if (!loaded || typeof loaded !== "object") return void 0;
54
+ if ("default" in loaded && isWorkflowHandle(loaded.default)) {
55
+ const definition = definitions.get(loaded.default.name);
56
+ if (definition) return {
57
+ definition,
58
+ name: loaded.default.name
59
+ };
60
+ }
61
+ const matches = /* @__PURE__ */ new Map();
62
+ for (const value of Object.values(loaded)) {
63
+ if (!isWorkflowHandle(value)) continue;
64
+ const definition = definitions.get(value.name);
65
+ if (definition) matches.set(value.name, definition);
66
+ }
67
+ if (matches.size !== 1) return void 0;
68
+ const [matchedName, definition] = matches.entries().next().value;
69
+ return {
70
+ definition,
71
+ name: matchedName
72
+ };
73
+ }
74
+ function takeInlineWorkflowDefinitionForModule(name, loaded) {
75
+ const match = findExportedInlineWorkflowDefinition(name, loaded, inlineRegistry);
76
+ if (!match) return void 0;
77
+ inlineRegistry.delete(match.name);
78
+ return match.definition;
79
+ }
80
+ function consumeInlineWorkflowDefinition(name, expected) {
81
+ const definition = inlineRegistry.get(name);
82
+ if (!expected || definition === expected) inlineRegistry.delete(name);
83
+ return definition;
84
+ }
85
+ function registerInlineWorkflowDefinition(name, definition) {
86
+ if (!name || typeof name !== "string") throw new TypeError("`createWorkflow()` requires a workflow name.");
87
+ const loadingDefinitions = loadingInlineRegistryStorage.getStore();
88
+ const existing = inlineRegistry.get(name);
89
+ if (existing && existing !== definition) {
90
+ if (!loadingDefinitions) throw new Error(`Duplicate workflow name "${name}" from inline definitions.`);
91
+ }
92
+ inlineRegistry.set(name, definition);
93
+ loadingDefinitions?.set(name, definition);
94
+ }
95
+ function enterWorkflowRuntimeEvent(event) {
96
+ fallbackEvent = event;
97
+ try {
98
+ eventStorage.enterWith(event);
99
+ } catch {}
100
+ }
101
+ function getWorkflowRuntimeEvent() {
102
+ return eventStorage.getStore() ?? fallbackEvent;
103
+ }
104
+ async function runWithWorkflowRuntimeEvent(event, run) {
105
+ return await eventStorage.run(event, run);
106
+ }
107
+ async function loadWorkflowDefinition(name) {
108
+ const inlineDefinition = inlineRegistry.get(name);
109
+ const entry = runtimeRegistry?.[name];
110
+ if (entry && loadedRegistryEntries.has(name)) return loadedRegistryEntries.get(name);
111
+ if (inlineDefinition) {
112
+ if (entry) throw new Error(`Duplicate workflow name "${name}" from inline and discovered definitions.`);
113
+ return inlineDefinition;
114
+ }
115
+ if (!entry) return;
116
+ const activeLoads = loadingRegistryStorage.getStore();
117
+ const inFlightEntry = loadingRegistryEntries.get(name);
118
+ if (inFlightEntry) return activeLoads?.has(name) ? void 0 : await inFlightEntry;
119
+ const nextActiveLoads = new Set(activeLoads);
120
+ nextActiveLoads.add(name);
121
+ const loadingEntry = Promise.resolve().then(() => loadingRegistryStorage.run(nextActiveLoads, async () => {
122
+ const loadingInlineDefinitions = /* @__PURE__ */ new Map();
123
+ const loaded = await loadingInlineRegistryStorage.run(loadingInlineDefinitions, entry);
124
+ if (!loaded || typeof loaded !== "object") return;
125
+ const registeredInlineDefinition = loadingInlineDefinitions.get(name) ?? consumeInlineWorkflowDefinition(name);
126
+ if (registeredInlineDefinition) {
127
+ consumeInlineWorkflowDefinition(name, registeredInlineDefinition);
128
+ return registeredInlineDefinition;
129
+ }
130
+ const definition = "default" in loaded ? loaded.default : loaded;
131
+ if (definition && typeof definition.handler === "function") return definition;
132
+ const exportedInlineDefinition = findExportedInlineWorkflowDefinition(name, loaded, loadingInlineDefinitions);
133
+ if (!exportedInlineDefinition) return void 0;
134
+ consumeInlineWorkflowDefinition(exportedInlineDefinition.name, exportedInlineDefinition.definition);
135
+ return exportedInlineDefinition.definition;
136
+ }));
137
+ loadingRegistryEntries.set(name, loadingEntry);
138
+ try {
139
+ const loaded = await loadingEntry;
140
+ loadedRegistryEntries.set(name, loaded);
141
+ return loaded;
142
+ } finally {
143
+ loadingRegistryEntries.delete(name);
144
+ }
145
+ }
146
+ function setWorkflowRun(name, id, promise) {
147
+ pruneWorkflowRuns();
148
+ if (runs.size >= RUNS_LIMIT) {
149
+ const oldest = runs.keys().next().value;
150
+ if (oldest !== void 0) runs.delete(oldest);
151
+ }
152
+ const state = {
153
+ promise: promise.then((resolved) => {
154
+ state.status = resolved.status;
155
+ state.result = resolved.result;
156
+ state.error = resolved.error;
157
+ state.expiresAt = Date.now() + RUNS_TTL_MS;
158
+ return resolved;
159
+ }),
160
+ status: "running"
161
+ };
162
+ runs.set(getRunKey(name, id), state);
163
+ return state;
164
+ }
165
+ function getWorkflowRunState(name, id) {
166
+ pruneWorkflowRuns();
167
+ return runs.get(getRunKey(name, id));
168
+ }
169
+ function resetWorkflowRuntime() {
170
+ runtimeConfig = void 0;
171
+ runtimeRegistry = void 0;
172
+ inlineRegistry.clear();
173
+ loadingRegistryEntries.clear();
174
+ loadedRegistryEntries.clear();
175
+ fallbackEvent = void 0;
176
+ runs.clear();
177
+ }
178
+ //#endregion
179
+ export { enterWorkflowRuntimeEvent, getInlineWorkflowDefinitions, getWorkflowRunState, getWorkflowRuntimeConfig, getWorkflowRuntimeEvent, getWorkflowRuntimeRegistry, loadWorkflowDefinition, registerInlineWorkflowDefinition, resetWorkflowRuntime, runWithWorkflowRuntimeEvent, setWorkflowRun, setWorkflowRuntimeConfig, setWorkflowRuntimeRegistry, takeInlineWorkflowDefinition, takeInlineWorkflowDefinitionForModule };
@@ -0,0 +1,69 @@
1
+ import { h as WorkflowDefinitionRegistry, l as ResolvedWorkflowOptions } from "../types-BUlYBZwH.js";
2
+ import { t as WorkflowApp } from "../_app-DgwN4ulW.js";
3
+ import { IncomingMessage, ServerResponse } from "node:http";
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
60
+ //#region src/runtime/vercel-vite.d.ts
61
+ interface WorkflowVercelServerOptions {
62
+ app?: WorkflowApp;
63
+ registry?: WorkflowDefinitionRegistry;
64
+ workflow?: false | ResolvedWorkflowOptions;
65
+ }
66
+ type WorkflowVercelServer = (req: IncomingMessage, res: ServerResponse) => unknown;
67
+ declare function createWorkflowVercelServer(options?: WorkflowVercelServerOptions): WorkflowVercelServer;
68
+ //#endregion
69
+ export { WorkflowVercelServer, createWorkflowVercelServer, setVercelWorkflowRuntimeModules };
@@ -0,0 +1,49 @@
1
+ import { runWithWorkflowRuntimeEvent, setWorkflowRuntimeConfig, setWorkflowRuntimeRegistry } from "./state.js";
2
+ import { i as setVercelWorkflowRuntimeModules } from "../vercel-D2_J5D_Y.js";
3
+ import { t as resolveAppFetch } from "../app-BZpq2cwC.js";
4
+ import { waitUntil } from "@vercel/functions";
5
+ import { H3 } from "h3";
6
+ //#region ../internal/src/runtime/vercel-hosted.ts
7
+ function createVercelHostedServer(adapter) {
8
+ const app = new H3();
9
+ const appHandler = resolveAppFetch(adapter.label, adapter.app);
10
+ let nodeHandlerPromise;
11
+ return function hostedVercelServer(req, res) {
12
+ const handle = async () => {
13
+ nodeHandlerPromise ||= (async () => {
14
+ if (appHandler) {
15
+ const { fromWebHandler } = await import("h3");
16
+ app.use(fromWebHandler(async (request, context) => await appHandler(request, context)));
17
+ }
18
+ const { toNodeHandler } = await import("h3/node");
19
+ return toNodeHandler(app);
20
+ })();
21
+ return (await nodeHandlerPromise)(req, res);
22
+ };
23
+ if (adapter.onRequest) return adapter.onRequest({
24
+ handle,
25
+ req,
26
+ res
27
+ });
28
+ return handle();
29
+ };
30
+ }
31
+ //#endregion
32
+ //#region src/runtime/vercel-vite.ts
33
+ function createWorkflowVercelServer(options = {}) {
34
+ return createVercelHostedServer({
35
+ app: options.app,
36
+ label: "workflow",
37
+ onRequest({ handle, req, res }) {
38
+ setWorkflowRuntimeConfig(options.workflow);
39
+ setWorkflowRuntimeRegistry(options.registry);
40
+ return runWithWorkflowRuntimeEvent({
41
+ req,
42
+ res,
43
+ waitUntil
44
+ }, handle);
45
+ }
46
+ });
47
+ }
48
+ //#endregion
49
+ export { createWorkflowVercelServer, setVercelWorkflowRuntimeModules };