@vite-hub/workflow 0.0.4 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -14
- package/dist/{_app-DgwN4ulW.d.ts → app-BojnC_yf.d.ts} +1 -4
- package/dist/{app-BZpq2cwC.js → app-CzPoP84f.js} +2 -1
- package/dist/client-DsGM3M4U.js +389 -0
- package/dist/cloudflare-env-BNrYo29x.js +113 -0
- package/dist/{cloudflare-D0Di-QYL.js → cloudflare-nF4abPd4.js} +20 -4
- package/dist/cloudflare-shared-CaxrMD1A.d.ts +1 -0
- package/dist/{cloudflare-vite-BkDgB6Sr.js → cloudflare-vite-B3IabBsv.js} +5 -4
- package/dist/{config-BHknO_rT.js → config-IJMb0eeZ.js} +38 -30
- package/dist/error-diagnostics-A_8Kp-48.js +116 -0
- package/dist/error-diagnostics-pwNFvAHP.js +67 -0
- package/dist/index.d.ts +20 -21
- package/dist/index.js +25 -369
- package/dist/inspect-B72iFyj-.js +70 -0
- package/dist/operations-B_rYG71W.js +230 -0
- package/dist/operations-tNUdj3G4.d.ts +212 -0
- package/dist/operations.d.ts +37 -0
- package/dist/operations.js +887 -0
- package/dist/out-CsaJxg8m.js +21755 -0
- package/dist/rolldown-runtime-CMFfr-1z.js +26 -0
- package/dist/runtime/cloudflare-runner.d.ts +5 -15
- package/dist/runtime/cloudflare-runner.js +40 -5
- package/dist/runtime/cloudflare-shared.d.ts +1 -0
- package/dist/runtime/cloudflare-shared.js +1 -1
- package/dist/runtime/cloudflare-vite.d.ts +8 -10
- package/dist/runtime/cloudflare-vite.js +1 -1
- package/dist/runtime/execute.d.ts +8 -7
- package/dist/runtime/execute.js +28 -5
- package/dist/runtime/openworkflow-worker.d.ts +6 -8
- package/dist/runtime/openworkflow-worker.js +5 -4
- package/dist/runtime/openworkflow.d.ts +8 -10
- package/dist/runtime/openworkflow.js +23 -17
- package/dist/runtime/state.d.ts +20 -21
- package/dist/runtime/state.js +90 -20
- package/dist/runtime/vercel-vite.d.ts +10 -12
- package/dist/runtime/vercel-vite.js +2 -2
- package/dist/runtime-type-DBCvIh5x.js +7 -0
- package/dist/{types-B9RdRkKh.d.ts → types-D82WmfZa.d.ts} +23 -12
- package/dist/{vercel-B0MuIVgJ.js → vercel-D-ZNtB_u.js} +34 -9
- package/dist/vite.d.ts +325 -11
- package/dist/vite.js +1267 -691
- package/package.json +79 -29
- package/dist/cloudflare-env-DjxQNbrx.js +0 -58
- package/dist/cloudflare-shared-BVVgDSdq.d.ts +0 -1
- package/dist/runtime-type-DGUn8Ple.js +0 -37
package/dist/runtime/state.js
CHANGED
|
@@ -1,23 +1,34 @@
|
|
|
1
|
+
import { t as workflowErrorDiagnostics } from "../error-diagnostics-pwNFvAHP.js";
|
|
1
2
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
3
|
//#region src/runtime/state.ts
|
|
3
4
|
const RUNS_LIMIT = 1024;
|
|
4
|
-
const RUNS_TTL_MS =
|
|
5
|
+
const RUNS_TTL_MS = 3e5;
|
|
5
6
|
let runtimeConfig;
|
|
6
7
|
let runtimeRegistry;
|
|
7
8
|
const inlineRegistry = /* @__PURE__ */ new Map();
|
|
8
9
|
const loadingRegistryEntries = /* @__PURE__ */ new Map();
|
|
9
10
|
const loadedRegistryEntries = /* @__PURE__ */ new Map();
|
|
11
|
+
let runtimeRegistryGeneration = 0;
|
|
10
12
|
let fallbackEvent;
|
|
11
13
|
const eventStorage = new AsyncLocalStorage();
|
|
12
14
|
const loadingRegistryStorage = new AsyncLocalStorage();
|
|
13
15
|
const loadingInlineRegistryStorage = new AsyncLocalStorage();
|
|
16
|
+
const loadingGenerationStorage = new AsyncLocalStorage();
|
|
14
17
|
const runs = /* @__PURE__ */ new Map();
|
|
18
|
+
const inFlightRuns = /* @__PURE__ */ new Map();
|
|
19
|
+
const fallbackRunKeys = /* @__PURE__ */ new Set();
|
|
20
|
+
let collectedRuns;
|
|
21
|
+
const completedRuns = /* @__PURE__ */ new Map();
|
|
22
|
+
function isWeakReference(reference) {
|
|
23
|
+
return reference !== null && "deref" in reference;
|
|
24
|
+
}
|
|
15
25
|
function getRunKey(name, id) {
|
|
16
|
-
return
|
|
26
|
+
return JSON.stringify([name, id]);
|
|
17
27
|
}
|
|
18
28
|
function pruneWorkflowRuns() {
|
|
19
29
|
const now = Date.now();
|
|
20
|
-
for (const [key, run] of
|
|
30
|
+
for (const [key, run] of completedRuns) if (run.expiresAt && run.expiresAt <= now) completedRuns.delete(key);
|
|
31
|
+
while (completedRuns.size > RUNS_LIMIT) completedRuns.delete(completedRuns.keys().next().value);
|
|
21
32
|
}
|
|
22
33
|
function setWorkflowRuntimeConfig(config) {
|
|
23
34
|
runtimeConfig = config;
|
|
@@ -26,6 +37,8 @@ function getWorkflowRuntimeConfig() {
|
|
|
26
37
|
return runtimeConfig;
|
|
27
38
|
}
|
|
28
39
|
function setWorkflowRuntimeRegistry(registry) {
|
|
40
|
+
if (runtimeRegistry !== registry) loadingRegistryEntries.clear();
|
|
41
|
+
runtimeRegistryGeneration++;
|
|
29
42
|
runtimeRegistry = registry;
|
|
30
43
|
loadedRegistryEntries.clear();
|
|
31
44
|
}
|
|
@@ -42,7 +55,12 @@ function takeInlineWorkflowDefinition(name) {
|
|
|
42
55
|
return definition;
|
|
43
56
|
}
|
|
44
57
|
function isWorkflowHandle(value) {
|
|
45
|
-
|
|
58
|
+
if (typeof value !== "object" || value === null) return false;
|
|
59
|
+
const candidate = value;
|
|
60
|
+
if (typeof candidate.name !== "string") return false;
|
|
61
|
+
if (typeof candidate.defer !== "function") return false;
|
|
62
|
+
if (typeof candidate.getRun !== "function") return false;
|
|
63
|
+
return typeof candidate.run === "function";
|
|
46
64
|
}
|
|
47
65
|
function findExportedInlineWorkflowDefinition(name, loaded, definitions) {
|
|
48
66
|
const namedDefinition = definitions.get(name);
|
|
@@ -83,13 +101,14 @@ function consumeInlineWorkflowDefinition(name, expected) {
|
|
|
83
101
|
return definition;
|
|
84
102
|
}
|
|
85
103
|
function registerInlineWorkflowDefinition(name, definition) {
|
|
86
|
-
if (!name || typeof name !== "string") throw
|
|
104
|
+
if (!name || typeof name !== "string") throw workflowErrorDiagnostics.WORKFLOW_R0023({ message: "`createWorkflow()` requires a workflow name." });
|
|
87
105
|
const loadingDefinitions = loadingInlineRegistryStorage.getStore();
|
|
106
|
+
const loadingGeneration = loadingGenerationStorage.getStore();
|
|
88
107
|
const existing = inlineRegistry.get(name);
|
|
89
108
|
if (existing && existing !== definition) {
|
|
90
|
-
if (!loadingDefinitions) throw
|
|
109
|
+
if (!loadingDefinitions) throw workflowErrorDiagnostics.WORKFLOW_R0024({ message: `Duplicate workflow name "${name}" from inline definitions.` });
|
|
91
110
|
}
|
|
92
|
-
inlineRegistry.set(name, definition);
|
|
111
|
+
if (loadingGeneration === void 0 || loadingGeneration === runtimeRegistryGeneration) inlineRegistry.set(name, definition);
|
|
93
112
|
loadingDefinitions?.set(name, definition);
|
|
94
113
|
}
|
|
95
114
|
function enterWorkflowRuntimeEvent(event) {
|
|
@@ -105,11 +124,12 @@ async function runWithWorkflowRuntimeEvent(event, run) {
|
|
|
105
124
|
return await eventStorage.run(event, run);
|
|
106
125
|
}
|
|
107
126
|
async function loadWorkflowDefinition(name) {
|
|
127
|
+
const generation = runtimeRegistryGeneration;
|
|
108
128
|
const inlineDefinition = inlineRegistry.get(name);
|
|
109
|
-
const entry = runtimeRegistry
|
|
129
|
+
const entry = runtimeRegistry && Object.hasOwn(runtimeRegistry, name) ? runtimeRegistry[name] : void 0;
|
|
110
130
|
if (entry && loadedRegistryEntries.has(name)) return loadedRegistryEntries.get(name);
|
|
111
131
|
if (inlineDefinition) {
|
|
112
|
-
if (entry) throw
|
|
132
|
+
if (entry) throw workflowErrorDiagnostics.WORKFLOW_R0025({ message: `Duplicate workflow name "${name}" from inline and discovered definitions.` });
|
|
113
133
|
return inlineDefinition;
|
|
114
134
|
}
|
|
115
135
|
if (!entry) return;
|
|
@@ -120,9 +140,15 @@ async function loadWorkflowDefinition(name) {
|
|
|
120
140
|
nextActiveLoads.add(name);
|
|
121
141
|
const loadingEntry = Promise.resolve().then(() => loadingRegistryStorage.run(nextActiveLoads, async () => {
|
|
122
142
|
const loadingInlineDefinitions = /* @__PURE__ */ new Map();
|
|
123
|
-
|
|
143
|
+
let loaded;
|
|
144
|
+
try {
|
|
145
|
+
loaded = await loadingGenerationStorage.run(generation, () => loadingInlineRegistryStorage.run(loadingInlineDefinitions, entry));
|
|
146
|
+
} catch (error) {
|
|
147
|
+
for (const [definitionName, definition] of loadingInlineDefinitions) if (inlineRegistry.get(definitionName) === definition) inlineRegistry.delete(definitionName);
|
|
148
|
+
throw error;
|
|
149
|
+
}
|
|
124
150
|
if (!loaded || typeof loaded !== "object") return;
|
|
125
|
-
const registeredInlineDefinition = loadingInlineDefinitions.get(name) ?? consumeInlineWorkflowDefinition(name);
|
|
151
|
+
const registeredInlineDefinition = loadingInlineDefinitions.get(name) ?? (generation === runtimeRegistryGeneration ? consumeInlineWorkflowDefinition(name) : void 0);
|
|
126
152
|
if (registeredInlineDefinition) {
|
|
127
153
|
consumeInlineWorkflowDefinition(name, registeredInlineDefinition);
|
|
128
154
|
return registeredInlineDefinition;
|
|
@@ -137,43 +163,87 @@ async function loadWorkflowDefinition(name) {
|
|
|
137
163
|
loadingRegistryEntries.set(name, loadingEntry);
|
|
138
164
|
try {
|
|
139
165
|
const loaded = await loadingEntry;
|
|
140
|
-
loadedRegistryEntries.set(name, loaded);
|
|
166
|
+
if (generation === runtimeRegistryGeneration && loadingRegistryEntries.get(name) === loadingEntry) loadedRegistryEntries.set(name, loaded);
|
|
141
167
|
return loaded;
|
|
142
168
|
} finally {
|
|
143
|
-
loadingRegistryEntries.delete(name);
|
|
169
|
+
if (loadingRegistryEntries.get(name) === loadingEntry) loadingRegistryEntries.delete(name);
|
|
144
170
|
}
|
|
145
171
|
}
|
|
146
|
-
function setWorkflowRun(name, id, promise) {
|
|
172
|
+
function setWorkflowRun(name, id, promise, payload, retainInFlight = false) {
|
|
147
173
|
pruneWorkflowRuns();
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
174
|
+
const key = getRunKey(name, id);
|
|
175
|
+
const canUseWeakReferences = globalThis.WeakRef !== void 0 && globalThis.FinalizationRegistry !== void 0;
|
|
176
|
+
if (canUseWeakReferences) collectedRuns ??= new FinalizationRegistry(({ key, reference }) => {
|
|
177
|
+
if (runs.get(key) === reference) runs.delete(key);
|
|
178
|
+
});
|
|
179
|
+
const previous = runs.get(key);
|
|
180
|
+
if (previous && canUseWeakReferences) collectedRuns?.unregister(previous);
|
|
181
|
+
fallbackRunKeys.delete(key);
|
|
182
|
+
completedRuns.delete(key);
|
|
152
183
|
const state = {
|
|
184
|
+
payload,
|
|
153
185
|
promise: promise.then((resolved) => {
|
|
154
186
|
state.status = resolved.status;
|
|
155
187
|
state.result = resolved.result;
|
|
156
188
|
state.error = resolved.error;
|
|
157
189
|
state.expiresAt = Date.now() + RUNS_TTL_MS;
|
|
190
|
+
if (inFlightRuns.get(key) === state) inFlightRuns.delete(key);
|
|
191
|
+
const active = runs.get(key);
|
|
192
|
+
if ((active && isWeakReference(active) ? active.deref() : active) === state) {
|
|
193
|
+
runs.delete(key);
|
|
194
|
+
fallbackRunKeys.delete(key);
|
|
195
|
+
if (isWeakReference(reference)) collectedRuns?.unregister(reference);
|
|
196
|
+
completedRuns.set(key, state);
|
|
197
|
+
pruneWorkflowRuns();
|
|
198
|
+
}
|
|
158
199
|
return resolved;
|
|
159
200
|
}),
|
|
160
201
|
status: "running"
|
|
161
202
|
};
|
|
162
|
-
|
|
203
|
+
const reference = canUseWeakReferences ? new WeakRef(state) : state;
|
|
204
|
+
runs.set(key, reference);
|
|
205
|
+
if (retainInFlight) inFlightRuns.set(key, state);
|
|
206
|
+
if (isWeakReference(reference)) collectedRuns?.register(state, {
|
|
207
|
+
key,
|
|
208
|
+
reference
|
|
209
|
+
}, reference);
|
|
210
|
+
else {
|
|
211
|
+
fallbackRunKeys.add(key);
|
|
212
|
+
while (fallbackRunKeys.size > RUNS_LIMIT) {
|
|
213
|
+
const oldest = fallbackRunKeys.values().next().value;
|
|
214
|
+
fallbackRunKeys.delete(oldest);
|
|
215
|
+
runs.delete(oldest);
|
|
216
|
+
inFlightRuns.delete(oldest);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
163
219
|
return state;
|
|
164
220
|
}
|
|
165
221
|
function getWorkflowRunState(name, id) {
|
|
166
222
|
pruneWorkflowRuns();
|
|
167
|
-
|
|
223
|
+
const key = getRunKey(name, id);
|
|
224
|
+
const inFlight = inFlightRuns.get(key);
|
|
225
|
+
if (inFlight) return inFlight;
|
|
226
|
+
const reference = runs.get(key);
|
|
227
|
+
const state = reference && isWeakReference(reference) ? reference.deref() : reference;
|
|
228
|
+
if (reference && !state) {
|
|
229
|
+
runs.delete(key);
|
|
230
|
+
if (isWeakReference(reference)) collectedRuns?.unregister(reference);
|
|
231
|
+
}
|
|
232
|
+
return state ?? completedRuns.get(key);
|
|
168
233
|
}
|
|
169
234
|
function resetWorkflowRuntime() {
|
|
235
|
+
runtimeRegistryGeneration++;
|
|
170
236
|
runtimeConfig = void 0;
|
|
171
237
|
runtimeRegistry = void 0;
|
|
172
238
|
inlineRegistry.clear();
|
|
173
239
|
loadingRegistryEntries.clear();
|
|
174
240
|
loadedRegistryEntries.clear();
|
|
175
241
|
fallbackEvent = void 0;
|
|
242
|
+
for (const reference of runs.values()) if (isWeakReference(reference)) collectedRuns?.unregister(reference);
|
|
176
243
|
runs.clear();
|
|
244
|
+
inFlightRuns.clear();
|
|
245
|
+
fallbackRunKeys.clear();
|
|
246
|
+
completedRuns.clear();
|
|
177
247
|
}
|
|
178
248
|
//#endregion
|
|
179
249
|
export { enterWorkflowRuntimeEvent, getInlineWorkflowDefinitions, getWorkflowRunState, getWorkflowRuntimeConfig, getWorkflowRuntimeEvent, getWorkflowRuntimeRegistry, loadWorkflowDefinition, registerInlineWorkflowDefinition, resetWorkflowRuntime, runWithWorkflowRuntimeEvent, setWorkflowRun, setWorkflowRuntimeConfig, setWorkflowRuntimeRegistry, takeInlineWorkflowDefinition, takeInlineWorkflowDefinitionForModule };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { h as WorkflowDefinitionRegistry, l as ResolvedWorkflowOptions } from "../types-
|
|
2
|
-
import { t as
|
|
1
|
+
import { h as WorkflowDefinitionRegistry, l as ResolvedWorkflowOptions } from "../types-D82WmfZa.js";
|
|
2
|
+
import { t as VitehubApp } from "../app-BojnC_yf.js";
|
|
3
3
|
import { IncomingMessage, ServerResponse } from "node:http";
|
|
4
|
-
|
|
5
4
|
//#region src/runtime/vercel.d.ts
|
|
6
5
|
interface VercelRun {
|
|
7
6
|
cancel: () => Promise<void>;
|
|
@@ -40,7 +39,7 @@ interface VercelWorkflowRuntimeModule {
|
|
|
40
39
|
getWorld: () => Promise<{
|
|
41
40
|
steps: {
|
|
42
41
|
list: (options: unknown) => Promise<{
|
|
43
|
-
cursor?: string;
|
|
42
|
+
cursor?: string | null;
|
|
44
43
|
data: unknown[];
|
|
45
44
|
hasMore: boolean;
|
|
46
45
|
}>;
|
|
@@ -48,23 +47,22 @@ interface VercelWorkflowRuntimeModule {
|
|
|
48
47
|
}> | {
|
|
49
48
|
steps: {
|
|
50
49
|
list: (options: unknown) => Promise<{
|
|
51
|
-
cursor?: string;
|
|
50
|
+
cursor?: string | null;
|
|
52
51
|
data: unknown[];
|
|
53
52
|
hasMore: boolean;
|
|
54
53
|
}>;
|
|
55
54
|
};
|
|
56
55
|
};
|
|
57
56
|
}
|
|
58
|
-
declare function setVercelWorkflowRuntimeModules(api: VercelWorkflowApiModule, runtime: VercelWorkflowRuntimeModule): void;
|
|
57
|
+
export declare function setVercelWorkflowRuntimeModules(api: VercelWorkflowApiModule, runtime: VercelWorkflowRuntimeModule): void;
|
|
59
58
|
//#endregion
|
|
60
59
|
//#region src/runtime/vercel-vite.d.ts
|
|
61
|
-
declare function runWithVercelWorkflowRuntimeEvent<T>(req: unknown, res: unknown, run: () => T | Promise<T>): Promise<T>;
|
|
60
|
+
export declare function runWithVercelWorkflowRuntimeEvent<T>(req: unknown, res: unknown, run: () => T | Promise<T>): Promise<T>;
|
|
62
61
|
interface WorkflowVercelServerOptions {
|
|
63
|
-
app?:
|
|
62
|
+
app?: VitehubApp;
|
|
64
63
|
registry?: WorkflowDefinitionRegistry;
|
|
65
64
|
workflow?: false | ResolvedWorkflowOptions;
|
|
66
65
|
}
|
|
67
|
-
type WorkflowVercelServer = (req: IncomingMessage, res: ServerResponse) => unknown;
|
|
68
|
-
declare function createWorkflowVercelServer(options?: WorkflowVercelServerOptions): WorkflowVercelServer;
|
|
69
|
-
//#endregion
|
|
70
|
-
export { WorkflowVercelServer, createWorkflowVercelServer, runWithVercelWorkflowRuntimeEvent, setVercelWorkflowRuntimeModules };
|
|
66
|
+
export type WorkflowVercelServer = (req: IncomingMessage, res: ServerResponse) => unknown;
|
|
67
|
+
export declare function createWorkflowVercelServer(options?: WorkflowVercelServerOptions): WorkflowVercelServer;
|
|
68
|
+
//#endregion
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { runWithWorkflowRuntimeEvent, setWorkflowRuntimeConfig, setWorkflowRuntimeRegistry } from "./state.js";
|
|
2
|
-
import { i as setVercelWorkflowRuntimeModules } from "../vercel-
|
|
3
|
-
import { t as resolveAppFetch } from "../app-
|
|
2
|
+
import { i as setVercelWorkflowRuntimeModules } from "../vercel-D-ZNtB_u.js";
|
|
3
|
+
import { t as resolveAppFetch } from "../app-CzPoP84f.js";
|
|
4
4
|
import { waitUntil } from "@vercel/functions";
|
|
5
5
|
import { H3 } from "h3";
|
|
6
6
|
//#region ../internal/src/runtime/vercel-hosted.ts
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { hasRuntimeType } from "@vite-hub/runtime/internal/runtime-type";
|
|
2
|
+
//#region src/internal/runtime-type.ts
|
|
3
|
+
function isRuntimeRecord(value) {
|
|
4
|
+
return value !== null && hasRuntimeType(value, "object") && !Array.isArray(value);
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
export { isRuntimeRecord as n, hasRuntimeType as t };
|
|
@@ -46,14 +46,12 @@ interface OpenWorkflowWorkerOptions {
|
|
|
46
46
|
concurrency?: number;
|
|
47
47
|
}
|
|
48
48
|
interface OpenWorkflowProviderOptions extends WorkflowSharedOptions {
|
|
49
|
-
database?: string;
|
|
50
49
|
postgres?: OpenWorkflowPostgresOptions;
|
|
51
50
|
provider: "openworkflow";
|
|
52
51
|
sqlite?: OpenWorkflowSqliteOptions;
|
|
53
52
|
worker?: OpenWorkflowWorkerOptions;
|
|
54
53
|
}
|
|
55
54
|
interface InferredWorkflowProviderOptions extends WorkflowSharedOptions {
|
|
56
|
-
database?: string;
|
|
57
55
|
postgres?: OpenWorkflowPostgresOptions;
|
|
58
56
|
provider?: undefined;
|
|
59
57
|
sqlite?: OpenWorkflowSqliteOptions;
|
|
@@ -100,14 +98,18 @@ interface WorkflowProviderStep {
|
|
|
100
98
|
do?: <TResult>(name: string, options: WorkflowStepOptions, run: () => TResult | Promise<TResult>) => Promise<TResult>;
|
|
101
99
|
sleep?: (name: string, duration: string) => Promise<void>;
|
|
102
100
|
}
|
|
103
|
-
type WorkflowStepRunner<TSteps extends Record<string, WorkflowStepFunction> = Record<string, WorkflowStepFunction>> = { [TName in keyof TSteps]: TSteps[TName] };
|
|
104
|
-
|
|
101
|
+
type WorkflowStepRunner<TSteps extends Record<string, WorkflowStepFunction> = Record<string, WorkflowStepFunction>> = { [TName in keyof TSteps]: TSteps[TName]; };
|
|
102
|
+
/** Run data that a provider gives to ViteHub before ViteHub adds the step runner. */
|
|
103
|
+
interface WorkflowProviderContext<TPayload = unknown> {
|
|
105
104
|
id?: string;
|
|
106
105
|
name: string;
|
|
107
106
|
payload: TPayload;
|
|
108
107
|
provider: WorkflowProvider;
|
|
109
108
|
step?: WorkflowProviderStep;
|
|
110
|
-
|
|
109
|
+
}
|
|
110
|
+
interface WorkflowExecutionContext<TPayload = unknown> extends WorkflowProviderContext<TPayload> {
|
|
111
|
+
/** Step functions from the numbered files in the Workflow folder. Empty when the Workflow has no step files. */
|
|
112
|
+
steps: WorkflowStepRunner;
|
|
111
113
|
}
|
|
112
114
|
type WorkflowHandler<TPayload = unknown, TResult = unknown> = (context: WorkflowExecutionContext<TPayload>) => TResult | Promise<TResult>;
|
|
113
115
|
type WorkflowRunIdValue = boolean | null | number | string | undefined | {
|
|
@@ -124,7 +126,8 @@ interface WorkflowCreateOptions<TPayload = unknown, TResult = unknown> {
|
|
|
124
126
|
}
|
|
125
127
|
interface WorkflowDefinitionOptions<TPayload = unknown, TResult = unknown> {
|
|
126
128
|
id?: string;
|
|
127
|
-
native
|
|
129
|
+
/** Vercel native entry. Vercel calls it with the provider context only, so it gets no step runner. */
|
|
130
|
+
native?: (context: WorkflowProviderContext<TPayload>) => TResult | Promise<TResult>;
|
|
128
131
|
rootStep?: boolean;
|
|
129
132
|
}
|
|
130
133
|
interface WorkflowDefinition<TPayload = unknown, TResult = unknown> {
|
|
@@ -133,12 +136,14 @@ interface WorkflowDefinition<TPayload = unknown, TResult = unknown> {
|
|
|
133
136
|
handler: WorkflowHandler<TPayload, TResult>;
|
|
134
137
|
options?: WorkflowDefinitionOptions<TPayload, TResult>;
|
|
135
138
|
}
|
|
139
|
+
/** Omission is valid only when the handler accepts undefined. */
|
|
140
|
+
type WorkflowStartArguments<TPayload> = undefined extends TPayload ? [payload?: TPayload, options?: WorkflowStartOptions] : [payload: TPayload, options?: WorkflowStartOptions];
|
|
136
141
|
interface WorkflowHandle<TPayload = unknown, TResult = unknown> {
|
|
137
142
|
cancel: (id: string) => Promise<WorkflowRun<unknown, unknown>>;
|
|
138
|
-
defer: (
|
|
143
|
+
defer: (...args: WorkflowStartArguments<TPayload>) => Promise<WorkflowRun<TPayload>>;
|
|
139
144
|
getRun: (id: string) => Promise<WorkflowRun<unknown, unknown>>;
|
|
140
145
|
name: string;
|
|
141
|
-
run: (
|
|
146
|
+
run: (...args: WorkflowStartArguments<TPayload>) => Promise<WorkflowRun<TPayload, TResult>>;
|
|
142
147
|
}
|
|
143
148
|
interface WorkflowStartOptions {
|
|
144
149
|
id?: string;
|
|
@@ -150,12 +155,18 @@ interface WorkflowSignalResult {
|
|
|
150
155
|
id: string;
|
|
151
156
|
provider: WorkflowProvider;
|
|
152
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Maps Workflow names to module loaders. The registry does not know each
|
|
160
|
+
* payload type, so it uses `never` as the payload. A definition with any
|
|
161
|
+
* payload type fits without a cast.
|
|
162
|
+
*/
|
|
153
163
|
interface WorkflowDefinitionRegistry {
|
|
154
164
|
[name: string]: (() => Promise<{
|
|
155
|
-
default?: WorkflowDefinition
|
|
165
|
+
default?: WorkflowDefinition<never>;
|
|
156
166
|
[exportName: string]: unknown;
|
|
157
|
-
} | WorkflowDefinition
|
|
158
|
-
/** @internal Identifies provider-generated Agent invocation recovery definitions without evaluating their modules. */
|
|
167
|
+
} | WorkflowDefinition<never>>) & {
|
|
168
|
+
/** @internal Identifies provider-generated Agent invocation recovery definitions without evaluating their modules. */
|
|
169
|
+
internalAgentInvocationRecovery?: true;
|
|
159
170
|
};
|
|
160
171
|
}
|
|
161
172
|
interface DiscoveredWorkflowDefinition {
|
|
@@ -166,4 +177,4 @@ interface DiscoveredWorkflowDefinition {
|
|
|
166
177
|
steps?: string[];
|
|
167
178
|
}
|
|
168
179
|
//#endregion
|
|
169
|
-
export {
|
|
180
|
+
export { WorkflowStartOptions as A, WorkflowProviderOptions as C, WorkflowRunStep as D, WorkflowRunStatus as E, WorkflowStepOptions as M, WorkflowStepRunner as N, WorkflowSharedOptions as O, WorkflowProviderContext as S, WorkflowRun 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, WorkflowStepFunction as j, WorkflowSignalResult 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, WorkflowProviderStep as w, WorkflowProvider as x, WorkflowModuleOptions as y };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { t as
|
|
1
|
+
import { t as workflowErrorDiagnostics } from "./error-diagnostics-pwNFvAHP.js";
|
|
2
|
+
import { t as hasRuntimeType } from "./runtime-type-DBCvIh5x.js";
|
|
2
3
|
import { a as createWorkflowError, i as safeWorkflowName, n as isWorkflowBoundaryError, r as runWorkflowProviderOperation } from "./provider-operation-CW2cYfVy.js";
|
|
3
4
|
//#region src/runtime/vercel.ts
|
|
4
5
|
async function loadVercelWorkflowRuntime() {
|
|
@@ -13,9 +14,10 @@ function createVercelWorkflowRuntime(api, runtime) {
|
|
|
13
14
|
getRun,
|
|
14
15
|
async listSteps(id) {
|
|
15
16
|
const steps = [];
|
|
17
|
+
const cursors = /* @__PURE__ */ new Set();
|
|
16
18
|
let cursor;
|
|
17
19
|
do {
|
|
18
|
-
const page = await (await getWorld()).steps.list({
|
|
20
|
+
const page = normalizeStepPage(await (await getWorld()).steps.list({
|
|
19
21
|
pagination: {
|
|
20
22
|
cursor,
|
|
21
23
|
limit: 1e3,
|
|
@@ -23,9 +25,12 @@ function createVercelWorkflowRuntime(api, runtime) {
|
|
|
23
25
|
},
|
|
24
26
|
resolveData: "none",
|
|
25
27
|
runId: id
|
|
26
|
-
});
|
|
28
|
+
}));
|
|
27
29
|
steps.push(...page.data);
|
|
28
|
-
|
|
30
|
+
if (!page.hasMore) break;
|
|
31
|
+
if (!hasRuntimeType(page.cursor, "string") || !page.cursor || cursors.has(page.cursor)) throw invalidVercelResult("step pagination cursor");
|
|
32
|
+
cursors.add(page.cursor);
|
|
33
|
+
cursor = page.cursor;
|
|
29
34
|
} while (cursor);
|
|
30
35
|
return steps;
|
|
31
36
|
},
|
|
@@ -57,11 +62,24 @@ const statusMap = {
|
|
|
57
62
|
running: "running"
|
|
58
63
|
};
|
|
59
64
|
function invalidVercelResult(field) {
|
|
60
|
-
return
|
|
65
|
+
return workflowErrorDiagnostics.WORKFLOW_R0026({ message: `Vercel Workflow provider returned an invalid ${field}.` });
|
|
66
|
+
}
|
|
67
|
+
function normalizeStepPage(page) {
|
|
68
|
+
if (!hasRuntimeType(page, "object") || page === null || Array.isArray(page)) throw invalidVercelResult("step page");
|
|
69
|
+
const { cursor, data, hasMore } = page;
|
|
70
|
+
if (!Array.isArray(data)) throw invalidVercelResult("step page data");
|
|
71
|
+
if (!hasRuntimeType(hasMore, "boolean")) throw invalidVercelResult("step page hasMore flag");
|
|
72
|
+
if (cursor !== void 0 && cursor !== null && !hasRuntimeType(cursor, "string")) throw invalidVercelResult("step page cursor");
|
|
73
|
+
return {
|
|
74
|
+
...cursor === void 0 || cursor === null ? {} : { cursor },
|
|
75
|
+
data,
|
|
76
|
+
hasMore
|
|
77
|
+
};
|
|
61
78
|
}
|
|
62
79
|
function normalizeStatus(status) {
|
|
63
80
|
if (!hasRuntimeType(status, "string")) throw invalidVercelResult("status");
|
|
64
|
-
|
|
81
|
+
const normalized = status.toLowerCase();
|
|
82
|
+
return Object.hasOwn(statusMap, normalized) ? statusMap[normalized] : "unknown";
|
|
65
83
|
}
|
|
66
84
|
function normalizeRunId(id) {
|
|
67
85
|
if (!hasRuntimeType(id, "string") || !id) throw invalidVercelResult("run ID");
|
|
@@ -69,8 +87,14 @@ function normalizeRunId(id) {
|
|
|
69
87
|
}
|
|
70
88
|
function normalizeDate(value, field) {
|
|
71
89
|
if (value === void 0) return void 0;
|
|
72
|
-
|
|
73
|
-
|
|
90
|
+
let timestamp;
|
|
91
|
+
try {
|
|
92
|
+
timestamp = Date.prototype.getTime.call(value);
|
|
93
|
+
} catch {
|
|
94
|
+
throw invalidVercelResult(field);
|
|
95
|
+
}
|
|
96
|
+
if (!Number.isFinite(timestamp)) throw invalidVercelResult(field);
|
|
97
|
+
return new Date(timestamp);
|
|
74
98
|
}
|
|
75
99
|
function normalizeStepError(error) {
|
|
76
100
|
if (error === void 0 || error === null) return void 0;
|
|
@@ -169,7 +193,7 @@ async function inspectVercelWorkflowRun(name, definition, id, payload) {
|
|
|
169
193
|
steps
|
|
170
194
|
};
|
|
171
195
|
}
|
|
172
|
-
async function startVercelWorkflow(name, definition, payload, observeSettlement) {
|
|
196
|
+
async function startVercelWorkflow(name, definition, payload, observeSettlement, onDispatch) {
|
|
173
197
|
const native = definition.options?.native;
|
|
174
198
|
if (!native) throw createWorkflowError({
|
|
175
199
|
code: "WORKFLOW_NATIVE_ENTRY_REQUIRED",
|
|
@@ -184,6 +208,7 @@ async function startVercelWorkflow(name, definition, payload, observeSettlement)
|
|
|
184
208
|
provider: "vercel"
|
|
185
209
|
};
|
|
186
210
|
const runtime = await getVercelWorkflowRuntime();
|
|
211
|
+
onDispatch?.();
|
|
187
212
|
const { id, run } = await runWorkflowProviderOperation("vercel", "start", async () => {
|
|
188
213
|
const run = await runtime.start(native, [context]);
|
|
189
214
|
return {
|