@vite-hub/workflow 0.0.3 → 0.0.4
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/LICENSE +201 -0
- package/README.md +165 -54
- package/dist/{cloudflare-Cds1VIWa.js → cloudflare-D0Di-QYL.js} +4 -3
- package/dist/{cloudflare-env-mFp2Uj6Z.js → cloudflare-env-DjxQNbrx.js} +8 -3
- package/dist/{cloudflare-vite-B0zel2Do.js → cloudflare-vite-BkDgB6Sr.js} +16 -9
- package/dist/{config-BDqB6I4E.js → config-BHknO_rT.js} +8 -2
- package/dist/index.d.ts +10 -5
- package/dist/index.js +69 -34
- package/dist/{provider-operation-CWIV4k42.js → provider-operation-CW2cYfVy.js} +13 -10
- package/dist/runtime/cloudflare-runner.d.ts +5 -1
- package/dist/runtime/cloudflare-runner.js +40 -12
- package/dist/runtime/cloudflare-shared.js +1 -1
- package/dist/runtime/cloudflare-vite.d.ts +3 -2
- package/dist/runtime/cloudflare-vite.js +2 -2
- package/dist/runtime/execute.d.ts +1 -1
- package/dist/runtime/openworkflow-worker.d.ts +1 -1
- package/dist/runtime/openworkflow-worker.js +40 -4
- package/dist/runtime/openworkflow.d.ts +1 -1
- package/dist/runtime/openworkflow.js +28 -16
- package/dist/runtime/state.d.ts +1 -1
- package/dist/runtime/vercel-vite.d.ts +3 -2
- package/dist/runtime/vercel-vite.js +10 -7
- package/dist/runtime-type-DGUn8Ple.js +37 -0
- package/dist/{types-BUlYBZwH.d.ts → types-B9RdRkKh.d.ts} +14 -8
- package/dist/{vercel-D2_J5D_Y.js → vercel-B0MuIVgJ.js} +27 -19
- package/dist/vite.d.ts +50 -5
- package/dist/vite.js +4080 -899
- package/package.json +5 -5
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
//#region src/types.d.ts
|
|
2
2
|
type WorkflowProvider = "cloudflare" | "openworkflow" | "vercel";
|
|
3
3
|
interface CloudflareWorkflowBinding<TPayload = unknown> {
|
|
4
|
-
|
|
5
|
-
id
|
|
4
|
+
createBatch: (batch: Array<{
|
|
5
|
+
id: string;
|
|
6
6
|
params?: TPayload;
|
|
7
|
-
}) => Promise<CloudflareWorkflowInstance>;
|
|
7
|
+
}>) => Promise<CloudflareWorkflowInstance[]>;
|
|
8
8
|
get: (id: string) => Promise<CloudflareWorkflowInstance>;
|
|
9
9
|
}
|
|
10
10
|
interface CloudflareWorkflowInstance {
|
|
@@ -98,6 +98,7 @@ interface WorkflowStepOptions {
|
|
|
98
98
|
type WorkflowStepFunction<TInput = unknown, TResult = unknown> = (input: TInput) => TResult | Promise<TResult>;
|
|
99
99
|
interface WorkflowProviderStep {
|
|
100
100
|
do?: <TResult>(name: string, options: WorkflowStepOptions, run: () => TResult | Promise<TResult>) => Promise<TResult>;
|
|
101
|
+
sleep?: (name: string, duration: string) => Promise<void>;
|
|
101
102
|
}
|
|
102
103
|
type WorkflowStepRunner<TSteps extends Record<string, WorkflowStepFunction> = Record<string, WorkflowStepFunction>> = { [TName in keyof TSteps]: TSteps[TName] };
|
|
103
104
|
interface WorkflowExecutionContext<TPayload = unknown> {
|
|
@@ -119,6 +120,7 @@ interface WorkflowCreateOptions<TPayload = unknown, TResult = unknown> {
|
|
|
119
120
|
payload?: TPayload;
|
|
120
121
|
}) => Promise<WorkflowRunIdValue> | WorkflowRunIdValue;
|
|
121
122
|
name?: string;
|
|
123
|
+
rootStep?: boolean;
|
|
122
124
|
}
|
|
123
125
|
interface WorkflowDefinitionOptions<TPayload = unknown, TResult = unknown> {
|
|
124
126
|
id?: string;
|
|
@@ -126,13 +128,15 @@ interface WorkflowDefinitionOptions<TPayload = unknown, TResult = unknown> {
|
|
|
126
128
|
rootStep?: boolean;
|
|
127
129
|
}
|
|
128
130
|
interface WorkflowDefinition<TPayload = unknown, TResult = unknown> {
|
|
131
|
+
/** @internal Identifies provider-generated Agent invocation recovery definitions. */
|
|
132
|
+
internalAgentInvocationRecovery?: true;
|
|
129
133
|
handler: WorkflowHandler<TPayload, TResult>;
|
|
130
134
|
options?: WorkflowDefinitionOptions<TPayload, TResult>;
|
|
131
135
|
}
|
|
132
136
|
interface WorkflowHandle<TPayload = unknown, TResult = unknown> {
|
|
133
|
-
cancel: (id: string) => Promise<WorkflowRun<
|
|
137
|
+
cancel: (id: string) => Promise<WorkflowRun<unknown, unknown>>;
|
|
134
138
|
defer: (payload?: TPayload, options?: WorkflowStartOptions) => Promise<WorkflowRun<TPayload>>;
|
|
135
|
-
getRun: (id: string) => Promise<WorkflowRun<
|
|
139
|
+
getRun: (id: string) => Promise<WorkflowRun<unknown, unknown>>;
|
|
136
140
|
name: string;
|
|
137
141
|
run: (payload?: TPayload, options?: WorkflowStartOptions) => Promise<WorkflowRun<TPayload, TResult>>;
|
|
138
142
|
}
|
|
@@ -147,16 +151,18 @@ interface WorkflowSignalResult {
|
|
|
147
151
|
provider: WorkflowProvider;
|
|
148
152
|
}
|
|
149
153
|
interface WorkflowDefinitionRegistry {
|
|
150
|
-
[name: string]: () => Promise<{
|
|
154
|
+
[name: string]: (() => Promise<{
|
|
151
155
|
default?: WorkflowDefinition;
|
|
152
156
|
[exportName: string]: unknown;
|
|
153
|
-
} | WorkflowDefinition
|
|
157
|
+
} | WorkflowDefinition>) & {
|
|
158
|
+
/** @internal Identifies provider-generated Agent invocation recovery definitions without evaluating their modules. */internalAgentInvocationRecovery?: true;
|
|
159
|
+
};
|
|
154
160
|
}
|
|
155
161
|
interface DiscoveredWorkflowDefinition {
|
|
156
162
|
agentIdentity?: string;
|
|
157
163
|
handler: string;
|
|
158
164
|
name: string;
|
|
159
|
-
source?: "agent-workflow" | "inline" | "server-workflows" | "vite-suffix";
|
|
165
|
+
source?: "agent-workflow" | "agent-workflow-recovery" | "inline" | "server-workflows" | "vite-suffix";
|
|
160
166
|
steps?: string[];
|
|
161
167
|
}
|
|
162
168
|
//#endregion
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as hasRuntimeType } from "./runtime-type-DGUn8Ple.js";
|
|
2
|
+
import { a as createWorkflowError, i as safeWorkflowName, n as isWorkflowBoundaryError, r as runWorkflowProviderOperation } from "./provider-operation-CW2cYfVy.js";
|
|
2
3
|
//#region src/runtime/vercel.ts
|
|
3
4
|
async function loadVercelWorkflowRuntime() {
|
|
4
5
|
const importVercelWorkflow = new Function("specifier", "return import(specifier)");
|
|
@@ -59,11 +60,11 @@ function invalidVercelResult(field) {
|
|
|
59
60
|
return /* @__PURE__ */ new TypeError(`Vercel Workflow provider returned an invalid ${field}.`);
|
|
60
61
|
}
|
|
61
62
|
function normalizeStatus(status) {
|
|
62
|
-
if (
|
|
63
|
+
if (!hasRuntimeType(status, "string")) throw invalidVercelResult("status");
|
|
63
64
|
return statusMap[status.toLowerCase()] || "unknown";
|
|
64
65
|
}
|
|
65
66
|
function normalizeRunId(id) {
|
|
66
|
-
if (
|
|
67
|
+
if (!hasRuntimeType(id, "string") || !id) throw invalidVercelResult("run ID");
|
|
67
68
|
return id;
|
|
68
69
|
}
|
|
69
70
|
function normalizeDate(value, field) {
|
|
@@ -74,17 +75,18 @@ function normalizeDate(value, field) {
|
|
|
74
75
|
function normalizeStepError(error) {
|
|
75
76
|
if (error === void 0 || error === null) return void 0;
|
|
76
77
|
if (error instanceof Error) return { message: error.message };
|
|
77
|
-
if (
|
|
78
|
+
if (hasRuntimeType(error, "string")) try {
|
|
78
79
|
return normalizeStepError(JSON.parse(error)) || { message: error };
|
|
79
80
|
} catch {
|
|
80
81
|
return { message: error };
|
|
81
82
|
}
|
|
82
|
-
if (
|
|
83
|
+
if (hasRuntimeType(error, "object") && error) {
|
|
83
84
|
const value = error;
|
|
84
|
-
if (
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
if (hasRuntimeType(value.message, "string")) {
|
|
86
|
+
const normalized = { message: value.message };
|
|
87
|
+
if (hasRuntimeType(value.code, "string")) normalized.code = value.code;
|
|
88
|
+
return normalized;
|
|
89
|
+
}
|
|
88
90
|
if (value.error !== void 0) return normalizeStepError(value.error);
|
|
89
91
|
}
|
|
90
92
|
return { message: "Workflow step failed." };
|
|
@@ -92,11 +94,11 @@ function normalizeStepError(error) {
|
|
|
92
94
|
function normalizeSteps(steps) {
|
|
93
95
|
if (!Array.isArray(steps)) throw invalidVercelResult("step list");
|
|
94
96
|
return steps.map((step) => {
|
|
95
|
-
if (
|
|
97
|
+
if (!hasRuntimeType(step, "object") || step === null) throw invalidVercelResult("step");
|
|
96
98
|
const value = step;
|
|
97
|
-
if (
|
|
98
|
-
if (
|
|
99
|
-
if (
|
|
99
|
+
if (!hasRuntimeType(value.attempt, "number") || !Number.isFinite(value.attempt)) throw invalidVercelResult("step attempt");
|
|
100
|
+
if (!hasRuntimeType(value.stepId, "string") || !value.stepId) throw invalidVercelResult("step ID");
|
|
101
|
+
if (!hasRuntimeType(value.stepName, "string") || !value.stepName) throw invalidVercelResult("step name");
|
|
100
102
|
return {
|
|
101
103
|
attempt: value.attempt,
|
|
102
104
|
completedAt: normalizeDate(value.completedAt, "step completion date"),
|
|
@@ -110,10 +112,10 @@ function normalizeSteps(steps) {
|
|
|
110
112
|
}
|
|
111
113
|
async function readRunIdentity(run) {
|
|
112
114
|
const exists = await run.exists;
|
|
113
|
-
if (
|
|
115
|
+
if (!hasRuntimeType(exists, "boolean")) throw invalidVercelResult("existence state");
|
|
114
116
|
if (!exists) return { exists };
|
|
115
117
|
const workflowName = await run.workflowName;
|
|
116
|
-
if (
|
|
118
|
+
if (!hasRuntimeType(workflowName, "string")) throw invalidVercelResult("workflow name");
|
|
117
119
|
return {
|
|
118
120
|
exists,
|
|
119
121
|
workflowName
|
|
@@ -167,7 +169,7 @@ async function inspectVercelWorkflowRun(name, definition, id, payload) {
|
|
|
167
169
|
steps
|
|
168
170
|
};
|
|
169
171
|
}
|
|
170
|
-
async function startVercelWorkflow(name, definition, payload) {
|
|
172
|
+
async function startVercelWorkflow(name, definition, payload, observeSettlement) {
|
|
171
173
|
const native = definition.options?.native;
|
|
172
174
|
if (!native) throw createWorkflowError({
|
|
173
175
|
code: "WORKFLOW_NATIVE_ENTRY_REQUIRED",
|
|
@@ -182,10 +184,16 @@ async function startVercelWorkflow(name, definition, payload) {
|
|
|
182
184
|
provider: "vercel"
|
|
183
185
|
};
|
|
184
186
|
const runtime = await getVercelWorkflowRuntime();
|
|
187
|
+
const { id, run } = await runWorkflowProviderOperation("vercel", "start", async () => {
|
|
188
|
+
const run = await runtime.start(native, [context]);
|
|
189
|
+
return {
|
|
190
|
+
id: normalizeRunId(run.runId),
|
|
191
|
+
run
|
|
192
|
+
};
|
|
193
|
+
});
|
|
194
|
+
observeSettlement?.(Promise.resolve(run.returnValue).then(() => void 0, () => void 0));
|
|
185
195
|
return {
|
|
186
|
-
id
|
|
187
|
-
return normalizeRunId((await runtime.start(native, [context])).runId);
|
|
188
|
-
}),
|
|
196
|
+
id,
|
|
189
197
|
metadata: { workflow: name },
|
|
190
198
|
payload,
|
|
191
199
|
provider: "vercel",
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,13 +1,58 @@
|
|
|
1
|
-
import { y as WorkflowModuleOptions } from "./types-
|
|
2
|
-
import { Plugin } from "
|
|
1
|
+
import { i as DiscoveredWorkflowDefinition, y as WorkflowModuleOptions } from "./types-B9RdRkKh.js";
|
|
2
|
+
import { Plugin } from "esbuild";
|
|
3
|
+
import { Plugin as Plugin$1 } from "vite";
|
|
3
4
|
|
|
5
|
+
//#region src/discovery.d.ts
|
|
6
|
+
declare function discoverWorkflowDefinitions(options: {
|
|
7
|
+
mode?: "vite-suffix";
|
|
8
|
+
rootDir: string;
|
|
9
|
+
scanDirs?: string[];
|
|
10
|
+
serverDirs?: string[];
|
|
11
|
+
} | {
|
|
12
|
+
mode: "server-workflows";
|
|
13
|
+
scanDirs: string[];
|
|
14
|
+
}): DiscoveredWorkflowDefinition[];
|
|
15
|
+
//#endregion
|
|
4
16
|
//#region src/vite.d.ts
|
|
5
|
-
|
|
6
|
-
|
|
17
|
+
interface WorkflowNitroConfigOptions {
|
|
18
|
+
nitro: Record<string, unknown>;
|
|
19
|
+
projectRoot: string;
|
|
20
|
+
serverDirs?: string[];
|
|
21
|
+
transformRegistry?: (code: string, id: string) => string | Promise<string>;
|
|
22
|
+
}
|
|
23
|
+
type WorkflowVitePlugin = Plugin$1 & {
|
|
24
|
+
vitehub?: {
|
|
25
|
+
workflow?: {
|
|
26
|
+
createNitroConfig?: (options: WorkflowNitroConfigOptions) => Promise<Record<string, unknown>>;
|
|
27
|
+
prepareScheduleRuntime?: (artifactDir?: string) => Promise<{
|
|
28
|
+
bundleAlias: Record<string, string>;
|
|
29
|
+
bundlePlugins?: Plugin[];
|
|
30
|
+
importBase: string;
|
|
31
|
+
native: boolean;
|
|
32
|
+
registryFile: string;
|
|
33
|
+
} | undefined>;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
interface InternalWorkflowModuleOptions {
|
|
38
|
+
agentImportBase?: string;
|
|
39
|
+
hosting?: string;
|
|
40
|
+
implicitlyEnabled?: boolean;
|
|
41
|
+
importBase?: string;
|
|
42
|
+
providerImportAliases?: Record<string, string>;
|
|
43
|
+
includeUserAppEntry?: boolean;
|
|
44
|
+
workspaceDependencyRuntimeImports?: {
|
|
45
|
+
sandbox?: string;
|
|
46
|
+
sandboxRuntimeState?: string;
|
|
47
|
+
shellWorkspace?: string;
|
|
48
|
+
};
|
|
49
|
+
workspaceImportBase?: string;
|
|
50
|
+
}
|
|
51
|
+
declare function hubWorkflow(options?: WorkflowModuleOptions, internalOptions?: InternalWorkflowModuleOptions): WorkflowVitePlugin;
|
|
7
52
|
declare module "vite" {
|
|
8
53
|
interface UserConfig {
|
|
9
54
|
workflow?: WorkflowModuleOptions;
|
|
10
55
|
}
|
|
11
56
|
}
|
|
12
57
|
//#endregion
|
|
13
|
-
export { WorkflowVitePlugin, hubWorkflow };
|
|
58
|
+
export { WorkflowVitePlugin, discoverWorkflowDefinitions, hubWorkflow };
|