@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
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
12
|
+
key = keys[i];
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
21
|
+
value: mod,
|
|
22
|
+
enumerable: true
|
|
23
|
+
}) : target, mod));
|
|
24
|
+
var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
|
|
25
|
+
//#endregion
|
|
26
|
+
export { __require as n, __toESM as r, __commonJSMin as t };
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { h as WorkflowDefinitionRegistry, l as ResolvedWorkflowOptions, w as WorkflowProviderStep } from "../types-D82WmfZa.js";
|
|
2
2
|
import { t as CloudflareWorkerEnv } from "../cloudflare-env-CIjdFTv6.js";
|
|
3
|
-
|
|
4
3
|
//#region src/runtime/cloudflare-runner.d.ts
|
|
5
|
-
interface CloudflareWorkflowEvent {
|
|
4
|
+
export interface CloudflareWorkflowEvent {
|
|
6
5
|
id?: string;
|
|
7
6
|
instanceId?: string;
|
|
8
7
|
payload?: unknown;
|
|
9
8
|
}
|
|
10
|
-
interface RunCloudflareWorkflowOptions {
|
|
9
|
+
export interface RunCloudflareWorkflowOptions {
|
|
11
10
|
config: false | ResolvedWorkflowOptions | undefined;
|
|
12
11
|
createNonRetryableError?: (error: Error & {
|
|
13
12
|
isRetryable: false;
|
|
@@ -18,14 +17,5 @@ interface RunCloudflareWorkflowOptions {
|
|
|
18
17
|
registry: WorkflowDefinitionRegistry;
|
|
19
18
|
step?: WorkflowProviderStep;
|
|
20
19
|
}
|
|
21
|
-
declare function runCloudflareWorkflow({
|
|
22
|
-
|
|
23
|
-
createNonRetryableError,
|
|
24
|
-
env,
|
|
25
|
-
event,
|
|
26
|
-
name,
|
|
27
|
-
registry,
|
|
28
|
-
step
|
|
29
|
-
}: RunCloudflareWorkflowOptions): Promise<unknown>;
|
|
30
|
-
//#endregion
|
|
31
|
-
export { CloudflareWorkflowEvent, RunCloudflareWorkflowOptions, runCloudflareWorkflow };
|
|
20
|
+
export declare function runCloudflareWorkflow({ config, createNonRetryableError, env, event, name, registry, step }: RunCloudflareWorkflowOptions): Promise<unknown>;
|
|
21
|
+
//#endregion
|
|
@@ -1,9 +1,44 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { t as workflowErrorDiagnostics } from "../error-diagnostics-pwNFvAHP.js";
|
|
2
|
+
import { t as hasRuntimeType } from "../runtime-type-DBCvIh5x.js";
|
|
3
|
+
import { i as runWithActiveCloudflareEnv } from "../cloudflare-env-BNrYo29x.js";
|
|
4
|
+
import { runSerializedWorkflowHandler } from "./execute.js";
|
|
3
5
|
import { loadWorkflowDefinition, runWithWorkflowRuntimeEvent, setWorkflowRuntimeConfig, setWorkflowRuntimeRegistry } from "./state.js";
|
|
4
6
|
//#region src/runtime/cloudflare-runner.ts
|
|
5
7
|
function isNonRetryableError(error) {
|
|
6
|
-
|
|
8
|
+
if (!hasRuntimeType(error, "object") || error === null) return false;
|
|
9
|
+
try {
|
|
10
|
+
const candidate = error;
|
|
11
|
+
if (Reflect.get(candidate, "isRetryable") !== false) return false;
|
|
12
|
+
const nativeIsError = Reflect.get(Error, "isError");
|
|
13
|
+
if (hasRuntimeType(nativeIsError, "function")) return nativeIsError(candidate) === true;
|
|
14
|
+
const clone = Reflect.get(globalThis, "structuredClone");
|
|
15
|
+
if (!hasRuntimeType(clone, "function")) return false;
|
|
16
|
+
try {
|
|
17
|
+
return clone(candidate) instanceof Error;
|
|
18
|
+
} catch {
|
|
19
|
+
const descriptors = /* @__PURE__ */ new Map();
|
|
20
|
+
try {
|
|
21
|
+
for (const key of Reflect.ownKeys(candidate)) {
|
|
22
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(candidate, key);
|
|
23
|
+
if (!descriptor?.configurable || !("value" in descriptor)) continue;
|
|
24
|
+
descriptors.set(key, descriptor);
|
|
25
|
+
Reflect.defineProperty(candidate, key, {
|
|
26
|
+
...descriptor,
|
|
27
|
+
value: void 0
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
return clone(candidate) instanceof Error;
|
|
32
|
+
} catch {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
} finally {
|
|
36
|
+
for (const [key, descriptor] of descriptors) Reflect.defineProperty(candidate, key, descriptor);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
} catch {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
7
42
|
}
|
|
8
43
|
function translateNonRetryableError(error, createNonRetryableError) {
|
|
9
44
|
return createNonRetryableError && isNonRetryableError(error) ? createNonRetryableError(error) : error;
|
|
@@ -34,9 +69,9 @@ async function runCloudflareWorkflow({ config, createNonRetryableError, env, eve
|
|
|
34
69
|
};
|
|
35
70
|
return await runWithActiveCloudflareEnv(env, async () => {
|
|
36
71
|
const definition = await loadWorkflowDefinition(name);
|
|
37
|
-
if (!definition) throw
|
|
72
|
+
if (!definition) throw workflowErrorDiagnostics.WORKFLOW_R0015({ message: `Missing workflow definition: ${name}` });
|
|
38
73
|
try {
|
|
39
|
-
return await runWithWorkflowRuntimeEvent(runtimeEvent, () =>
|
|
74
|
+
return await runWithWorkflowRuntimeEvent(runtimeEvent, () => runSerializedWorkflowHandler({
|
|
40
75
|
id: event?.instanceId || event?.id,
|
|
41
76
|
name,
|
|
42
77
|
payload: event?.payload,
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { a as setActiveCloudflareEnv, i as runWithActiveCloudflareEnv, n as CloudflareWorkerExecutionContext, r as createCloudflareRuntimeEvent, t as CloudflareWorkerEnv } from "../cloudflare-env-CIjdFTv6.js";
|
|
2
|
+
import "../cloudflare-shared-CaxrMD1A.js";
|
|
2
3
|
export { type CloudflareWorkerEnv, type CloudflareWorkerExecutionContext, createCloudflareRuntimeEvent, runWithActiveCloudflareEnv, setActiveCloudflareEnv };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as setActiveCloudflareEnv, i as runWithActiveCloudflareEnv, t as createCloudflareRuntimeEvent } from "../cloudflare-env-
|
|
1
|
+
import { a as setActiveCloudflareEnv, i as runWithActiveCloudflareEnv, t as createCloudflareRuntimeEvent } from "../cloudflare-env-BNrYo29x.js";
|
|
2
2
|
export { createCloudflareRuntimeEvent, runWithActiveCloudflareEnv, setActiveCloudflareEnv };
|
|
@@ -1,18 +1,16 @@
|
|
|
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 { n as CloudflareWorkerExecutionContext, t as CloudflareWorkerEnv } from "../cloudflare-env-CIjdFTv6.js";
|
|
4
|
-
|
|
5
4
|
//#region src/runtime/cloudflare-vite.d.ts
|
|
6
|
-
type CloudflareWorkerApp =
|
|
7
|
-
interface WorkflowCloudflareWorkerOptions {
|
|
5
|
+
export type CloudflareWorkerApp = VitehubApp;
|
|
6
|
+
export interface WorkflowCloudflareWorkerOptions {
|
|
8
7
|
app?: CloudflareWorkerApp;
|
|
9
8
|
registry?: WorkflowDefinitionRegistry;
|
|
10
9
|
workflow?: false | ResolvedWorkflowOptions;
|
|
11
10
|
}
|
|
12
|
-
interface WorkflowCloudflareWorker {
|
|
11
|
+
export interface WorkflowCloudflareWorker {
|
|
13
12
|
fetch: (request: Request, env: CloudflareWorkerEnv, context: CloudflareWorkerExecutionContext) => Promise<Response>;
|
|
14
13
|
}
|
|
15
|
-
declare function installWorkflowCloudflareRuntime(options?: WorkflowCloudflareWorkerOptions): void;
|
|
16
|
-
declare function createWorkflowCloudflareWorker(options?: WorkflowCloudflareWorkerOptions): WorkflowCloudflareWorker;
|
|
17
|
-
//#endregion
|
|
18
|
-
export { CloudflareWorkerApp, WorkflowCloudflareWorker, WorkflowCloudflareWorkerOptions, createWorkflowCloudflareWorker, installWorkflowCloudflareRuntime };
|
|
14
|
+
export declare function installWorkflowCloudflareRuntime(options?: WorkflowCloudflareWorkerOptions): void;
|
|
15
|
+
export declare function createWorkflowCloudflareWorker(options?: WorkflowCloudflareWorkerOptions): WorkflowCloudflareWorker;
|
|
16
|
+
//#endregion
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as installWorkflowCloudflareRuntime, t as createWorkflowCloudflareWorker } from "../cloudflare-vite-
|
|
1
|
+
import { n as installWorkflowCloudflareRuntime, t as createWorkflowCloudflareWorker } from "../cloudflare-vite-B3IabBsv.js";
|
|
2
2
|
export { createWorkflowCloudflareWorker, installWorkflowCloudflareRuntime };
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { M as WorkflowStepOptions, S as WorkflowProviderContext, j as WorkflowStepFunction, p as WorkflowDefinition, w as WorkflowProviderStep } from "../types-D82WmfZa.js";
|
|
2
|
+
import { SerializedResponse } from "@vite-hub/runtime";
|
|
3
3
|
//#region src/runtime/execute.d.ts
|
|
4
|
-
declare function runProviderStep<TResult>(step: WorkflowProviderStep | undefined, name: string, run: () => TResult | Promise<TResult>, options?: WorkflowStepOptions): Promise<TResult>;
|
|
5
|
-
declare function createWorkflowSteps(context:
|
|
4
|
+
export declare function runProviderStep<TResult>(step: WorkflowProviderStep | undefined, name: string, run: () => TResult | Promise<TResult>, options?: WorkflowStepOptions): Promise<TResult>;
|
|
5
|
+
export declare function createWorkflowSteps(context: WorkflowProviderContext, stepModules: Array<{
|
|
6
6
|
name: string;
|
|
7
7
|
run: WorkflowStepFunction;
|
|
8
8
|
}>): Record<string, WorkflowStepFunction>;
|
|
9
|
-
declare function runWorkflowHandler<TPayload, TResult>(context:
|
|
10
|
-
|
|
11
|
-
export
|
|
9
|
+
export declare function runWorkflowHandler<TPayload, TResult>(context: WorkflowProviderContext<TPayload>, definition: WorkflowDefinition<TPayload, TResult>): Promise<Response>;
|
|
10
|
+
/** Encode inside the root step so both checkpoints and final outputs survive replay. */
|
|
11
|
+
export declare function runSerializedWorkflowHandler<TPayload, TResult>(context: WorkflowProviderContext<TPayload>, definition: WorkflowDefinition<TPayload, TResult>): Promise<SerializedResponse>;
|
|
12
|
+
//#endregion
|
package/dist/runtime/execute.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { t as workflowErrorDiagnostics } from "../error-diagnostics-pwNFvAHP.js";
|
|
2
|
+
import { serializeResponse, toResponse } from "@vite-hub/runtime";
|
|
1
3
|
//#region src/runtime/execute.ts
|
|
2
4
|
const defaultStepOptions = { retries: {
|
|
3
5
|
backoff: "exponential",
|
|
@@ -12,14 +14,35 @@ function toStepPropertyName(file) {
|
|
|
12
14
|
return file.split("/").pop().replace(/\.(?:c|m)?[jt]s$/i, "").replace(/^\d+[.-]?/, "").replace(/[-_.]+([a-z0-9])/gi, (_, char) => char.toUpperCase());
|
|
13
15
|
}
|
|
14
16
|
function createWorkflowSteps(context, stepModules) {
|
|
17
|
+
const names = /* @__PURE__ */ new Map();
|
|
15
18
|
return Object.fromEntries(stepModules.map((module) => {
|
|
16
|
-
|
|
19
|
+
const propertyName = toStepPropertyName(module.name);
|
|
20
|
+
if (!propertyName) throw workflowErrorDiagnostics.WORKFLOW_C0011({ message: `[vitehub] Workflow step file ${JSON.stringify(module.name)} normalizes to an empty step property. Rename the file so the step property is non-empty.` });
|
|
21
|
+
const previousName = names.get(propertyName);
|
|
22
|
+
if (previousName) throw workflowErrorDiagnostics.WORKFLOW_C0010({ message: `[vitehub] Workflow step files ${JSON.stringify(previousName)} and ${JSON.stringify(module.name)} both normalize to the \`${propertyName}\` step property. Rename one file so each step property is unique.` });
|
|
23
|
+
names.set(propertyName, module.name);
|
|
24
|
+
return [propertyName, async (input) => await runProviderStep(context.step, `${context.name}/${module.name}`, () => module.run(input))];
|
|
17
25
|
}));
|
|
18
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Gives every handler a step runner. Generated folder Workflows replace this
|
|
29
|
+
* empty runner with their step files.
|
|
30
|
+
*/
|
|
31
|
+
function toExecutionContext(context) {
|
|
32
|
+
return {
|
|
33
|
+
...context,
|
|
34
|
+
steps: {}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
19
37
|
async function runWorkflowHandler(context, definition) {
|
|
20
|
-
const run = () => definition.handler(context);
|
|
21
|
-
|
|
22
|
-
return
|
|
38
|
+
const run = () => definition.handler(toExecutionContext(context));
|
|
39
|
+
const value = definition.options?.rootStep === false ? await run() : await runProviderStep(context.step, context.name, run);
|
|
40
|
+
return toResponse(value);
|
|
41
|
+
}
|
|
42
|
+
/** Encode inside the root step so both checkpoints and final outputs survive replay. */
|
|
43
|
+
async function runSerializedWorkflowHandler(context, definition) {
|
|
44
|
+
const run = async () => serializeResponse(toResponse(await definition.handler(toExecutionContext(context))));
|
|
45
|
+
return definition.options?.rootStep === false ? await run() : await runProviderStep(context.step, context.name, run);
|
|
23
46
|
}
|
|
24
47
|
//#endregion
|
|
25
|
-
export { createWorkflowSteps, runProviderStep, runWorkflowHandler };
|
|
48
|
+
export { createWorkflowSteps, runProviderStep, runSerializedWorkflowHandler, runWorkflowHandler };
|
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
import { h as WorkflowDefinitionRegistry, l as ResolvedWorkflowOptions } from "../types-
|
|
1
|
+
import { h as WorkflowDefinitionRegistry, l as ResolvedWorkflowOptions } from "../types-D82WmfZa.js";
|
|
2
2
|
import { getOpenWorkflowRuntime } from "./openworkflow.js";
|
|
3
3
|
import { ViteHubError } from "@vite-hub/runtime";
|
|
4
|
-
|
|
5
4
|
//#region src/runtime/openworkflow-worker.d.ts
|
|
6
5
|
type OpenWorkflowWorker = ReturnType<Awaited<ReturnType<typeof getOpenWorkflowRuntime>>["client"]["newWorker"]>;
|
|
7
|
-
interface CreateOpenWorkflowWorkerOptions {
|
|
6
|
+
export interface CreateOpenWorkflowWorkerOptions {
|
|
8
7
|
concurrency?: number;
|
|
9
8
|
config?: false | ResolvedWorkflowOptions;
|
|
10
9
|
registry?: WorkflowDefinitionRegistry;
|
|
11
10
|
}
|
|
12
|
-
interface StartOpenWorkflowWorkerOptions extends CreateOpenWorkflowWorkerOptions {
|
|
11
|
+
export interface StartOpenWorkflowWorkerOptions extends CreateOpenWorkflowWorkerOptions {
|
|
13
12
|
onError?: (error: ViteHubError) => Promise<void> | void;
|
|
14
13
|
signal?: AbortSignal;
|
|
15
14
|
signals?: boolean;
|
|
16
15
|
}
|
|
17
|
-
declare function createOpenWorkflowWorker(options?: CreateOpenWorkflowWorkerOptions): Promise<OpenWorkflowWorker>;
|
|
18
|
-
declare function startOpenWorkflowWorker(options?: StartOpenWorkflowWorkerOptions): Promise<OpenWorkflowWorker>;
|
|
19
|
-
//#endregion
|
|
20
|
-
export { CreateOpenWorkflowWorkerOptions, StartOpenWorkflowWorkerOptions, createOpenWorkflowWorker, startOpenWorkflowWorker };
|
|
16
|
+
export declare function createOpenWorkflowWorker(options?: CreateOpenWorkflowWorkerOptions): Promise<OpenWorkflowWorker>;
|
|
17
|
+
export declare function startOpenWorkflowWorker(options?: StartOpenWorkflowWorkerOptions): Promise<OpenWorkflowWorker>;
|
|
18
|
+
//#endregion
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as workflowErrorDiagnostics } from "../error-diagnostics-pwNFvAHP.js";
|
|
2
|
+
import { n as isRuntimeRecord, t as hasRuntimeType } from "../runtime-type-DBCvIh5x.js";
|
|
2
3
|
import { a as createWorkflowError, r as runWorkflowProviderOperation } from "../provider-operation-CW2cYfVy.js";
|
|
3
4
|
import { getOpenWorkflowRuntime, registerOpenWorkflowDefinition } from "./openworkflow.js";
|
|
4
5
|
import { getInlineWorkflowDefinitions, getWorkflowRuntimeConfig, getWorkflowRuntimeRegistry, setWorkflowRuntimeConfig, setWorkflowRuntimeRegistry, takeInlineWorkflowDefinitionForModule } from "./state.js";
|
|
@@ -8,7 +9,7 @@ function getProcess() {
|
|
|
8
9
|
return globalThis.process;
|
|
9
10
|
}
|
|
10
11
|
function isWorkflowDefinition(value) {
|
|
11
|
-
return isRuntimeRecord(value) && hasRuntimeType(value.handler, "function");
|
|
12
|
+
return isRuntimeRecord(value) && Object.hasOwn(value, "handler") && hasRuntimeType(value.handler, "function");
|
|
12
13
|
}
|
|
13
14
|
async function loadRegistryDefinitions(registry) {
|
|
14
15
|
const definitions = /* @__PURE__ */ new Map();
|
|
@@ -27,13 +28,13 @@ async function loadRegistryDefinitions(registry) {
|
|
|
27
28
|
function mergeInlineDefinitions(definitions) {
|
|
28
29
|
for (const [name, definition] of getInlineWorkflowDefinitions()) {
|
|
29
30
|
const existing = definitions.get(name);
|
|
30
|
-
if (existing && existing !== definition) throw
|
|
31
|
+
if (existing && existing !== definition) throw workflowErrorDiagnostics.WORKFLOW_R0016({ message: `Duplicate workflow name "${name}" from inline and discovered definitions.` });
|
|
31
32
|
definitions.set(name, definition);
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
35
|
async function createOpenWorkflowWorker(options = {}) {
|
|
35
36
|
const config = options.config ?? getWorkflowRuntimeConfig();
|
|
36
|
-
if (!config || config.provider !== "openworkflow") throw
|
|
37
|
+
if (!config || config.provider !== "openworkflow") throw workflowErrorDiagnostics.WORKFLOW_R0017({ message: "OpenWorkflow worker requires workflow.provider \"openworkflow\"." });
|
|
37
38
|
const registry = options.registry ?? getWorkflowRuntimeRegistry() ?? {};
|
|
38
39
|
setWorkflowRuntimeConfig(config);
|
|
39
40
|
setWorkflowRuntimeRegistry(registry);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { f as WorkflowDeferOptions, l as ResolvedWorkflowOptions, p as WorkflowDefinition
|
|
2
|
-
|
|
1
|
+
import { T as WorkflowRun, f as WorkflowDeferOptions, l as ResolvedWorkflowOptions, p as WorkflowDefinition } from "../types-D82WmfZa.js";
|
|
3
2
|
//#region src/runtime/openworkflow.d.ts
|
|
4
3
|
type OpenWorkflowModule = typeof import("openworkflow");
|
|
5
4
|
type OpenWorkflowPostgresModule = typeof import("openworkflow/postgres");
|
|
@@ -13,11 +12,10 @@ interface OpenWorkflowRuntime {
|
|
|
13
12
|
client: OpenWorkflowClient;
|
|
14
13
|
workflows: Map<string, OpenWorkflowRunnable>;
|
|
15
14
|
}
|
|
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 };
|
|
15
|
+
export declare function getOpenWorkflowRuntime(config: ResolvedWorkflowOptions): Promise<OpenWorkflowRuntime>;
|
|
16
|
+
export declare function registerOpenWorkflowDefinition(runtime: OpenWorkflowRuntime, name: string, definition: WorkflowDefinition): Promise<OpenWorkflowRunnable>;
|
|
17
|
+
export declare function runOpenWorkflow<TPayload = unknown, TResult = unknown>(config: ResolvedWorkflowOptions, name: string, payload: TPayload | undefined, definition: WorkflowDefinition<TPayload, TResult>, options: WorkflowDeferOptions, onDispatch?: () => void): Promise<WorkflowRun<TPayload, TResult>>;
|
|
18
|
+
export declare function getOpenWorkflowRun<TPayload = unknown, TResult = unknown>(config: ResolvedWorkflowOptions, name: string, id: string): Promise<WorkflowRun<TPayload, TResult>>;
|
|
19
|
+
export declare function resetOpenWorkflowRuntime(): Promise<void>;
|
|
20
|
+
export declare function setOpenWorkflowImporter(importer: OpenWorkflowImporter): void;
|
|
21
|
+
//#endregion
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { t as workflowErrorDiagnostics } from "../error-diagnostics-pwNFvAHP.js";
|
|
1
2
|
import { a as createWorkflowError, r as runWorkflowProviderOperation, t as getWorkflowProviderStatus } from "../provider-operation-CW2cYfVy.js";
|
|
2
|
-
import {
|
|
3
|
+
import { runSerializedWorkflowHandler } from "./execute.js";
|
|
4
|
+
import { deserializeResponse, isSerializedResponse } from "@vite-hub/runtime";
|
|
3
5
|
//#region src/runtime/openworkflow.ts
|
|
4
6
|
const defaultImporter = new Function("specifier", "return import(specifier)");
|
|
5
7
|
let openWorkflowImporter = defaultImporter;
|
|
@@ -24,8 +26,8 @@ function getRuntimeEnvNames(value) {
|
|
|
24
26
|
return value.source?.names ?? (value.source?.name ? [value.source.name] : []);
|
|
25
27
|
}
|
|
26
28
|
function normalizeSqlitePath(path) {
|
|
27
|
-
if (/^(?:libsql:|https?:\/\/)/i.test(path)) throw
|
|
28
|
-
if (/^[a-z][a-z0-9+.-]*:/i.test(path) && !path.startsWith("file:")) throw
|
|
29
|
+
if (/^(?:libsql:|https?:\/\/)/i.test(path)) throw workflowErrorDiagnostics.WORKFLOW_R0018({ message: `OpenWorkflow SQLite storage requires a local SQLite file path, received ${JSON.stringify(path)}.` });
|
|
30
|
+
if (/^[a-z][a-z0-9+.-]*:/i.test(path) && !path.startsWith("file:")) throw workflowErrorDiagnostics.WORKFLOW_R0019({ message: `OpenWorkflow SQLite storage received unsupported storage URL ${JSON.stringify(path)}.` });
|
|
29
31
|
return path.startsWith("file:") ? path.slice(5) : path;
|
|
30
32
|
}
|
|
31
33
|
async function prepareSqlitePath(path, importer) {
|
|
@@ -36,17 +38,23 @@ async function prepareSqlitePath(path, importer) {
|
|
|
36
38
|
return path;
|
|
37
39
|
}
|
|
38
40
|
function getOpenWorkflowConfig(config) {
|
|
39
|
-
if (config.provider !== "openworkflow") throw
|
|
41
|
+
if (config.provider !== "openworkflow") throw workflowErrorDiagnostics.WORKFLOW_R0020({ message: `OpenWorkflow runtime requires workflow.provider "openworkflow", received "${config.provider}".` });
|
|
42
|
+
if ("database" in config && config.database !== void 0) throw workflowErrorDiagnostics.WORKFLOW_R0027({ message: "`workflow.database` is not supported. Set `workflow.sqlite.path` or `workflow.postgres.url` explicitly." });
|
|
40
43
|
const sqlite = config.sqlite || {};
|
|
41
|
-
const
|
|
44
|
+
const postgres = config.postgres || {};
|
|
45
|
+
if (postgres.url !== void 0 && sqlite.path !== void 0) throw workflowErrorDiagnostics.WORKFLOW_R0030({ message: "`workflow.postgres.url` and `workflow.sqlite.path` cannot both configure OpenWorkflow storage." });
|
|
46
|
+
const explicitSqlitePath = resolveRuntimeConfigValue(sqlite.path);
|
|
47
|
+
const explicitPostgresUrl = resolveRuntimeConfigValue(postgres.url)?.trim();
|
|
48
|
+
if (sqlite.path !== void 0 && !explicitSqlitePath?.trim()) throw workflowErrorDiagnostics.WORKFLOW_R0028({ message: "`workflow.sqlite.path` must resolve to a non-empty local SQLite path. Check its runtime environment declaration." });
|
|
49
|
+
if (postgres.url !== void 0 && !explicitPostgresUrl) throw workflowErrorDiagnostics.WORKFLOW_R0029({ message: "`workflow.postgres.url` must resolve to a non-empty Postgres URL. Check its runtime environment declaration." });
|
|
50
|
+
const sqlitePath = explicitSqlitePath || (!explicitPostgresUrl ? readEnv("OPENWORKFLOW_SQLITE_PATH") : void 0);
|
|
42
51
|
if (sqlitePath) return {
|
|
43
52
|
backend: "sqlite",
|
|
44
53
|
namespaceId: sqlite.namespaceId || readEnv("OPENWORKFLOW_NAMESPACE_ID") || "production",
|
|
45
54
|
path: normalizeSqlitePath(sqlitePath),
|
|
46
55
|
runMigrations: sqlite.runMigrations
|
|
47
56
|
};
|
|
48
|
-
const
|
|
49
|
-
const url = resolveRuntimeConfigValue(postgres.url) || readEnv("OPENWORKFLOW_POSTGRES_URL") || readEnv("DATABASE_URL");
|
|
57
|
+
const url = explicitPostgresUrl || readEnv("OPENWORKFLOW_POSTGRES_URL") || readEnv("DATABASE_URL");
|
|
50
58
|
if (url) return {
|
|
51
59
|
backend: "postgres",
|
|
52
60
|
namespaceId: postgres.namespaceId || readEnv("OPENWORKFLOW_NAMESPACE_ID") || "production",
|
|
@@ -61,11 +69,7 @@ function getOpenWorkflowConfig(config) {
|
|
|
61
69
|
runMigrations: sqlite.runMigrations
|
|
62
70
|
};
|
|
63
71
|
}
|
|
64
|
-
function
|
|
65
|
-
return JSON.stringify(getOpenWorkflowConfig(config));
|
|
66
|
-
}
|
|
67
|
-
async function createOpenWorkflowRuntime(config, importer) {
|
|
68
|
-
const options = getOpenWorkflowConfig(config);
|
|
72
|
+
async function createOpenWorkflowRuntime(options, importer) {
|
|
69
73
|
const [{ OpenWorkflow }, backendModule] = await Promise.all([importOpenWorkflowModule("openworkflow", importer), options.backend === "sqlite" ? importOpenWorkflowModule("openworkflow/sqlite", importer) : importOpenWorkflowModule("openworkflow/postgres", importer)]);
|
|
70
74
|
const { backend, client } = await runWorkflowProviderOperation("openworkflow", "connect", async () => {
|
|
71
75
|
let backend;
|
|
@@ -91,10 +95,11 @@ async function createOpenWorkflowRuntime(config, importer) {
|
|
|
91
95
|
}
|
|
92
96
|
async function getOpenWorkflowRuntime(config) {
|
|
93
97
|
const cache = runtimes;
|
|
94
|
-
const
|
|
98
|
+
const options = getOpenWorkflowConfig(config);
|
|
99
|
+
const key = JSON.stringify(options);
|
|
95
100
|
let runtime = cache.get(key);
|
|
96
101
|
if (!runtime) {
|
|
97
|
-
runtime = createOpenWorkflowRuntime(
|
|
102
|
+
runtime = createOpenWorkflowRuntime(options, openWorkflowImporter);
|
|
98
103
|
cache.set(key, runtime);
|
|
99
104
|
runtime.catch(() => {
|
|
100
105
|
if (cache.get(key) === runtime) cache.delete(key);
|
|
@@ -132,7 +137,7 @@ async function registerOpenWorkflowDefinition(runtime, name, definition) {
|
|
|
132
137
|
if (existing) return existing;
|
|
133
138
|
const openWorkflowDefinition = definition;
|
|
134
139
|
const workflow = runtime.client.defineWorkflow({ name }, async ({ input, run, step }) => {
|
|
135
|
-
return await
|
|
140
|
+
return await runSerializedWorkflowHandler({
|
|
136
141
|
id: run.id,
|
|
137
142
|
name,
|
|
138
143
|
payload: input,
|
|
@@ -161,7 +166,7 @@ function serializeOpenWorkflowRun(run, name) {
|
|
|
161
166
|
provider: "openworkflow",
|
|
162
167
|
status: "unknown"
|
|
163
168
|
};
|
|
164
|
-
const result = run.output;
|
|
169
|
+
const result = isSerializedResponse(run.output) ? deserializeResponse(run.output) : run.output;
|
|
165
170
|
return {
|
|
166
171
|
id: run.id,
|
|
167
172
|
metadata: run.error || {
|
|
@@ -174,8 +179,9 @@ function serializeOpenWorkflowRun(run, name) {
|
|
|
174
179
|
status: normalizeOpenWorkflowStatus(run.status)
|
|
175
180
|
};
|
|
176
181
|
}
|
|
177
|
-
async function runOpenWorkflow(config, name, payload, definition, options) {
|
|
182
|
+
async function runOpenWorkflow(config, name, payload, definition, options, onDispatch) {
|
|
178
183
|
const workflow = await registerOpenWorkflowDefinition(await getOpenWorkflowRuntime(config), name, definition);
|
|
184
|
+
onDispatch?.();
|
|
179
185
|
let firstAcknowledgementUnknown = false;
|
|
180
186
|
const handle = await runWorkflowProviderOperation("openworkflow", "run", async () => {
|
|
181
187
|
const start = () => workflow.run(payload, options.id ? { idempotencyKey: options.id } : void 0);
|
package/dist/runtime/state.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { h as WorkflowDefinitionRegistry, l as ResolvedWorkflowOptions, p as WorkflowDefinition } from "../types-
|
|
2
|
-
|
|
1
|
+
import { h as WorkflowDefinitionRegistry, l as ResolvedWorkflowOptions, p as WorkflowDefinition } from "../types-D82WmfZa.js";
|
|
3
2
|
//#region src/runtime/state.d.ts
|
|
4
|
-
interface WorkflowRunState<TResult = unknown> {
|
|
3
|
+
export interface WorkflowRunState<TResult = unknown> {
|
|
5
4
|
error?: unknown;
|
|
6
5
|
expiresAt?: number;
|
|
6
|
+
payload?: unknown;
|
|
7
7
|
promise: Promise<{
|
|
8
8
|
result?: TResult;
|
|
9
9
|
status: "completed" | "failed";
|
|
@@ -12,24 +12,23 @@ interface WorkflowRunState<TResult = unknown> {
|
|
|
12
12
|
result?: TResult;
|
|
13
13
|
status: "running" | "completed" | "failed";
|
|
14
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<{
|
|
15
|
+
export declare function setWorkflowRuntimeConfig(config: false | ResolvedWorkflowOptions | undefined): void;
|
|
16
|
+
export declare function getWorkflowRuntimeConfig(): false | ResolvedWorkflowOptions | undefined;
|
|
17
|
+
export declare function setWorkflowRuntimeRegistry(registry: WorkflowDefinitionRegistry | undefined): void;
|
|
18
|
+
export declare function getWorkflowRuntimeRegistry(): WorkflowDefinitionRegistry | undefined;
|
|
19
|
+
export declare function getInlineWorkflowDefinitions(): ReadonlyMap<string, WorkflowDefinition>;
|
|
20
|
+
export declare function takeInlineWorkflowDefinition(name: string): WorkflowDefinition | undefined;
|
|
21
|
+
export declare function takeInlineWorkflowDefinitionForModule(name: string, loaded: unknown): WorkflowDefinition | undefined;
|
|
22
|
+
export declare function registerInlineWorkflowDefinition(name: string, definition: WorkflowDefinition): void;
|
|
23
|
+
export declare function enterWorkflowRuntimeEvent(event: unknown): void;
|
|
24
|
+
export declare function getWorkflowRuntimeEvent(): unknown;
|
|
25
|
+
export declare function runWithWorkflowRuntimeEvent<T>(event: unknown, run: () => T | Promise<T>): Promise<T>;
|
|
26
|
+
export declare function loadWorkflowDefinition(name: string): Promise<WorkflowDefinition | undefined>;
|
|
27
|
+
export declare function setWorkflowRun<TResult = unknown>(name: string, id: string, promise: Promise<{
|
|
28
28
|
result?: TResult;
|
|
29
29
|
status: "completed" | "failed";
|
|
30
30
|
error?: unknown;
|
|
31
|
-
}
|
|
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 };
|
|
31
|
+
}>, payload?: unknown, retainInFlight?: boolean): WorkflowRunState<TResult>;
|
|
32
|
+
export declare function getWorkflowRunState(name: string, id: string): WorkflowRunState | undefined;
|
|
33
|
+
export declare function resetWorkflowRuntime(): void;
|
|
34
|
+
//#endregion
|