@vite-hub/workflow 0.1.0 → 0.4.1
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 +173 -55
- package/dist/{app-CzPoP84f.js → app-He0GTrYZ.js} +1 -1
- package/dist/client-DkwOxEiT.js +707 -0
- package/dist/{cloudflare-nF4abPd4.js → cloudflare-BHfClPvT.js} +2 -2
- package/dist/{cloudflare-env-BNrYo29x.js → cloudflare-env-CGLx7lUd.js} +44 -42
- package/dist/cloudflare-env-lookup-CfX6wZKb.d.ts +4 -0
- package/dist/{cloudflare-env-CIjdFTv6.d.ts → cloudflare-shared-CTqh_a2s.d.ts} +2 -2
- package/dist/{config-IJMb0eeZ.js → config-C3DvtjfJ.js} +41 -40
- package/dist/definition.d.ts +18 -0
- package/dist/definition.js +33 -0
- package/dist/delay-D1-nq_VE.js +46 -0
- package/dist/dev-recorder-CTN5Fkao.js +10 -0
- package/dist/durability.d.ts +23 -0
- package/dist/durability.js +62 -0
- package/dist/error-diagnostics-0V2T3JFw.js +317 -0
- package/dist/error-diagnostics-CQ4BUqRe.js +270 -0
- package/dist/errors-DCqRnZpN.js +35 -0
- package/dist/errors-uhP8DZTi.d.ts +67 -0
- package/dist/index.d.ts +35 -63
- package/dist/index.js +15 -19
- package/dist/object-Da1zyPCR.js +11 -0
- package/dist/openworkflow-BhzxV_Y3.d.ts +52 -0
- package/dist/openworkflow-defaults-DDig2M4s.js +26 -0
- package/dist/openworkflow-storage-Dj9zUAsk.js +28 -0
- package/dist/openworkflow.d.ts +2 -0
- package/dist/openworkflow.js +2 -0
- package/dist/{operations-tNUdj3G4.d.ts → operation-definition-nmRu_O3V.d.ts} +42 -15
- package/dist/operations-D_WJwjrS.js +333 -0
- package/dist/operations.d.ts +40 -6
- package/dist/operations.js +163 -736
- package/dist/{out-CsaJxg8m.js → out-DxLKolA0.js} +32 -1430
- package/dist/{rolldown-runtime-CMFfr-1z.js → rolldown-runtime-B4iAMlE-.js} +10 -1
- package/dist/run-error-DBWqiJHH.js +110 -0
- package/dist/run-failed-gVGo1BaF.js +18 -0
- package/dist/runtime/cloudflare-runner.d.ts +3 -5
- package/dist/runtime/cloudflare-runner.js +39 -45
- package/dist/runtime/cloudflare-shared.d.ts +2 -2
- package/dist/runtime/cloudflare-shared.js +1 -1
- package/dist/runtime/cloudflare-vite.d.ts +3 -2
- package/dist/runtime/cloudflare-vite.js +47 -1
- package/dist/runtime/dev-runs.d.ts +4 -0
- package/dist/runtime/dev-runs.js +73 -0
- package/dist/runtime/execute.d.ts +42 -5
- package/dist/runtime/execute.js +216 -17
- package/dist/runtime/openworkflow-worker.d.ts +29 -2
- package/dist/runtime/openworkflow-worker.js +156 -38
- package/dist/runtime/openworkflow.d.ts +2 -21
- package/dist/runtime/openworkflow.js +307 -44
- package/dist/runtime/state.d.ts +3 -1
- package/dist/runtime/state.js +6 -6
- package/dist/runtime/vercel-vite.d.ts +1 -1
- package/dist/runtime/vercel-vite.js +7 -4
- package/dist/types-Dsmwsdlv.d.ts +282 -0
- package/dist/{vercel-D-ZNtB_u.js → vercel-DTvm61iY.js} +53 -24
- package/dist/vite.d.ts +228 -30
- package/dist/vite.js +2640 -1449
- package/package.json +28 -50
- package/dist/client-DsGM3M4U.js +0 -389
- package/dist/cloudflare-shared-CaxrMD1A.d.ts +0 -1
- package/dist/cloudflare-vite-B3IabBsv.js +0 -47
- package/dist/error-diagnostics-A_8Kp-48.js +0 -116
- package/dist/error-diagnostics-pwNFvAHP.js +0 -67
- package/dist/operations-B_rYG71W.js +0 -230
- package/dist/provider-operation-CW2cYfVy.js +0 -65
- package/dist/runtime-type-DBCvIh5x.js +0 -7
- package/dist/types-D82WmfZa.d.ts +0 -180
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { ViteHubError } from "@vite-hub/runtime";
|
|
2
|
+
//#region src/errors.d.ts
|
|
3
|
+
declare const workflowErrorMessages: {
|
|
4
|
+
readonly OPENWORKFLOW_BACKEND_CLOSE_FAILED: "OpenWorkflow backend cleanup failed.";
|
|
5
|
+
readonly OPENWORKFLOW_RUNTIME_RESET: "OpenWorkflow runtime was reset while it was being acquired.";
|
|
6
|
+
readonly OPENWORKFLOW_WORKER_FAILED: "OpenWorkflow worker failed to start or run.";
|
|
7
|
+
readonly OPENWORKFLOW_WORKER_STOP_FAILED: "OpenWorkflow worker stop failed.";
|
|
8
|
+
readonly VERCEL_WORKFLOW_SDK_LOAD_FAILED: "Vercel Workflow DevKit load failed. Install the optional workflow peer dependency.";
|
|
9
|
+
readonly WORKFLOW_DEFINITION_NOT_FOUND: "Workflow definition was not found.";
|
|
10
|
+
readonly WORKFLOW_DISABLED: "Workflow is disabled.";
|
|
11
|
+
readonly WORKFLOW_NATIVE_ENTRY_INVALID: "Workflow has no transformed native Vercel entry.";
|
|
12
|
+
readonly WORKFLOW_NATIVE_ENTRY_REQUIRED: "Workflow has no native durable entry for Vercel.";
|
|
13
|
+
readonly WORKFLOW_OPERATION_UNSUPPORTED: "Workflow provider operation is unsupported.";
|
|
14
|
+
readonly WORKFLOW_PROVIDER_OPERATION_FAILED: "Workflow provider operation failed.";
|
|
15
|
+
readonly WORKFLOW_RUN_ID_UNSUPPORTED: "Native Vercel workflows assign their own run IDs.";
|
|
16
|
+
};
|
|
17
|
+
declare const workflowProviderNames: readonly ["cloudflare", "openworkflow", "vercel"];
|
|
18
|
+
declare const workflowOperationNames: readonly ["cancel", "cancellation", "connect", "create", "delay", "get", "get-run", "import", "list-steps", "resume-signal", "run", "signals", "start", "status"];
|
|
19
|
+
type WorkflowErrorCode = keyof typeof workflowErrorMessages;
|
|
20
|
+
type WorkflowOperationName = typeof workflowOperationNames[number];
|
|
21
|
+
type WorkflowProviderName = typeof workflowProviderNames[number];
|
|
22
|
+
type WorkflowNameDetails = {
|
|
23
|
+
name?: string;
|
|
24
|
+
};
|
|
25
|
+
type VercelWorkflowDetails = {
|
|
26
|
+
name?: string;
|
|
27
|
+
provider: "vercel";
|
|
28
|
+
};
|
|
29
|
+
type WorkflowOperationDetails = {
|
|
30
|
+
operation: WorkflowOperationName;
|
|
31
|
+
provider: WorkflowProviderName;
|
|
32
|
+
};
|
|
33
|
+
/** `rejected`: the provider answered and refused the call. `unknown`: the call can have reached the provider. */
|
|
34
|
+
type WorkflowProviderAcknowledgement = "rejected" | "unknown";
|
|
35
|
+
/** What `WORKFLOW_PROVIDER_OPERATION_FAILED` keeps in `error.data` when a Workflow call returns it. */
|
|
36
|
+
type WorkflowProviderFailure = {
|
|
37
|
+
/** `rejected`: the provider answered and refused the call. `unknown`: the call can have reached the provider. */
|
|
38
|
+
acknowledgement?: WorkflowProviderAcknowledgement;
|
|
39
|
+
operation: string;
|
|
40
|
+
provider: string;
|
|
41
|
+
/** The provider error name and the first line of its message, without URLs, file paths, or credentials. */
|
|
42
|
+
reason?: string;
|
|
43
|
+
/** The HTTP status of the provider, when it sent one. */
|
|
44
|
+
status?: number;
|
|
45
|
+
};
|
|
46
|
+
type WorkflowProviderOperationDetails = WorkflowOperationDetails & {
|
|
47
|
+
acknowledgement?: WorkflowProviderAcknowledgement;
|
|
48
|
+
/** The provider error name and the first line of its message, without URLs, file paths, or credentials. */
|
|
49
|
+
reason?: string;
|
|
50
|
+
status?: number;
|
|
51
|
+
};
|
|
52
|
+
type WorkflowErrorDetails<TCode extends WorkflowErrorCode = WorkflowErrorCode> = TCode extends "OPENWORKFLOW_BACKEND_CLOSE_FAILED" | "OPENWORKFLOW_RUNTIME_RESET" | "OPENWORKFLOW_WORKER_FAILED" | "OPENWORKFLOW_WORKER_STOP_FAILED" ? {
|
|
53
|
+
provider: "openworkflow";
|
|
54
|
+
} : TCode extends "VERCEL_WORKFLOW_SDK_LOAD_FAILED" ? {
|
|
55
|
+
provider: "vercel";
|
|
56
|
+
} : TCode extends "WORKFLOW_DEFINITION_NOT_FOUND" ? WorkflowNameDetails : TCode extends "WORKFLOW_DISABLED" ? Record<string, never> : TCode extends "WORKFLOW_NATIVE_ENTRY_INVALID" | "WORKFLOW_NATIVE_ENTRY_REQUIRED" | "WORKFLOW_RUN_ID_UNSUPPORTED" ? VercelWorkflowDetails : TCode extends "WORKFLOW_OPERATION_UNSUPPORTED" ? WorkflowOperationDetails : TCode extends "WORKFLOW_PROVIDER_OPERATION_FAILED" ? WorkflowProviderOperationDetails : never;
|
|
57
|
+
/**
|
|
58
|
+
* Throw it from a step or a handler to fail the run at once, with no more attempts, on every provider. Cloudflare reads
|
|
59
|
+
* `isRetryable`, Workflow DevKit reads `fatal`, and ViteHub stops OpenWorkflow retries itself.
|
|
60
|
+
*/
|
|
61
|
+
declare class NonRetryableError extends Error {
|
|
62
|
+
override name: string;
|
|
63
|
+
readonly isRetryable = false;
|
|
64
|
+
readonly fatal = true;
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
export { WorkflowProviderFailure as a, WorkflowOperationName as i, WorkflowErrorCode as n, WorkflowProviderName as o, WorkflowErrorDetails as r, NonRetryableError as t };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,61 +1,9 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
interface WorkflowResolutionInput {
|
|
6
|
-
hosting?: string;
|
|
7
|
-
}
|
|
8
|
-
export declare function normalizeWorkflowOptions(options: WorkflowModuleOptions | undefined, input?: WorkflowResolutionInput): ResolvedWorkflowOptions | undefined;
|
|
9
|
-
//#endregion
|
|
10
|
-
//#region src/definition.d.ts
|
|
11
|
-
export declare function defineWorkflow<TPayload = unknown, TResult = unknown>(handler: WorkflowHandler<TPayload, TResult>, options?: WorkflowDefinitionOptions<TPayload, TResult>): WorkflowDefinition<TPayload, TResult>;
|
|
12
|
-
//#endregion
|
|
13
|
-
//#region src/errors.d.ts
|
|
14
|
-
declare const workflowErrorMessages: {
|
|
15
|
-
readonly OPENWORKFLOW_BACKEND_CLOSE_FAILED: "OpenWorkflow backend cleanup failed.";
|
|
16
|
-
readonly OPENWORKFLOW_RUNTIME_RESET: "OpenWorkflow runtime was reset while it was being acquired.";
|
|
17
|
-
readonly OPENWORKFLOW_WORKER_STOP_FAILED: "OpenWorkflow worker stop failed.";
|
|
18
|
-
readonly VERCEL_WORKFLOW_SDK_LOAD_FAILED: "Vercel Workflow DevKit load failed. Install the optional workflow peer dependency.";
|
|
19
|
-
readonly WORKFLOW_DEFINITION_NOT_FOUND: "Workflow definition was not found.";
|
|
20
|
-
readonly WORKFLOW_DISABLED: "Workflow is disabled.";
|
|
21
|
-
readonly WORKFLOW_NATIVE_ENTRY_INVALID: "Workflow has no transformed native Vercel entry.";
|
|
22
|
-
readonly WORKFLOW_NATIVE_ENTRY_REQUIRED: "Workflow has no native durable entry for Vercel.";
|
|
23
|
-
readonly WORKFLOW_OPERATION_UNSUPPORTED: "Workflow provider operation is unsupported.";
|
|
24
|
-
readonly WORKFLOW_PROVIDER_OPERATION_FAILED: "Workflow provider operation failed.";
|
|
25
|
-
readonly WORKFLOW_RUN_ID_UNSUPPORTED: "Native Vercel workflows assign their own run IDs.";
|
|
26
|
-
};
|
|
27
|
-
declare const workflowProviderNames: readonly ["cloudflare", "openworkflow", "vercel"];
|
|
28
|
-
declare const workflowOperationNames: readonly ["cancel", "cancellation", "connect", "create", "get", "get-run", "import", "list-steps", "resume-signal", "run", "signals", "start", "status"];
|
|
29
|
-
type WorkflowErrorCode = keyof typeof workflowErrorMessages;
|
|
30
|
-
type WorkflowOperationName = typeof workflowOperationNames[number];
|
|
31
|
-
type WorkflowProviderName = typeof workflowProviderNames[number];
|
|
32
|
-
type WorkflowNameDetails = {
|
|
33
|
-
name?: string;
|
|
34
|
-
};
|
|
35
|
-
type VercelWorkflowDetails = {
|
|
36
|
-
name?: string;
|
|
37
|
-
provider: "vercel";
|
|
38
|
-
};
|
|
39
|
-
type WorkflowOperationDetails = {
|
|
40
|
-
operation: WorkflowOperationName;
|
|
41
|
-
provider: WorkflowProviderName;
|
|
42
|
-
};
|
|
43
|
-
type WorkflowProviderOperationDetails = WorkflowOperationDetails & {
|
|
44
|
-
status?: number;
|
|
45
|
-
};
|
|
46
|
-
type WorkflowErrorDetails<TCode extends WorkflowErrorCode = WorkflowErrorCode> = TCode extends "OPENWORKFLOW_BACKEND_CLOSE_FAILED" | "OPENWORKFLOW_RUNTIME_RESET" | "OPENWORKFLOW_WORKER_STOP_FAILED" ? {
|
|
47
|
-
provider: "openworkflow";
|
|
48
|
-
} : TCode extends "VERCEL_WORKFLOW_SDK_LOAD_FAILED" ? {
|
|
49
|
-
provider: "vercel";
|
|
50
|
-
} : TCode extends "WORKFLOW_DEFINITION_NOT_FOUND" ? WorkflowNameDetails : TCode extends "WORKFLOW_DISABLED" ? Record<string, never> : TCode extends "WORKFLOW_NATIVE_ENTRY_INVALID" | "WORKFLOW_NATIVE_ENTRY_REQUIRED" | "WORKFLOW_RUN_ID_UNSUPPORTED" ? VercelWorkflowDetails : TCode extends "WORKFLOW_OPERATION_UNSUPPORTED" ? WorkflowOperationDetails : TCode extends "WORKFLOW_PROVIDER_OPERATION_FAILED" ? WorkflowProviderOperationDetails : never;
|
|
51
|
-
//#endregion
|
|
1
|
+
import { A as WorkflowRun, B as WorkflowStep, C as WorkflowName, D as WorkflowProviderStep, E as WorkflowProviderContext, F as WorkflowSharedOptions, G as WorkflowStepRegistry, H as WorkflowStepContext, I as WorkflowSignalResult, K as WorkflowStepRetries, L as WorkflowStartArguments, M as WorkflowRunStatus, N as WorkflowRunStep, O as WorkflowRegistry, R as WorkflowStartDelay, S as WorkflowModuleDriverOptions, T as WorkflowPayload, U as WorkflowStepFunction, V as WorkflowStepBackoff, W as WorkflowStepOptions, _ as WorkflowDuration, a as InferredWorkflowDriverOptions, b as WorkflowHandle, c as OpenWorkflowWorkerOptions, d as WorkflowCreateOptions, f as WorkflowDefinition, g as WorkflowDriverOptions, h as WorkflowDriver, i as DiscoveredWorkflowDefinition, j as WorkflowRunError, k as WorkflowResultErrorCode, l as ResolvedWorkflowOptions, m as WorkflowDefinitionRegistry, n as CloudflareWorkflowDriverOptions, o as OpenWorkflowDriverOptions, p as WorkflowDefinitionOptions, q as WorkflowSteps, r as CloudflareWorkflowInstance, s as OpenWorkflowPostgresOptions, t as CloudflareWorkflowBinding, u as VercelWorkflowDriverOptions, v as WorkflowDurationUnit, w as WorkflowOptions, x as WorkflowHandler, y as WorkflowExecutionContext, z as WorkflowStartOptions } from "./types-Dsmwsdlv.js";
|
|
2
|
+
import { defineWorkflow } from "./definition.js";
|
|
3
|
+
import { a as WorkflowProviderFailure, i as WorkflowOperationName, n as WorkflowErrorCode, o as WorkflowProviderName, r as WorkflowErrorDetails, t as NonRetryableError } from "./errors-uhP8DZTi.js";
|
|
4
|
+
import { Result } from "@vite-hub/runtime";
|
|
52
5
|
//#region src/integrations/cloudflare.d.ts
|
|
53
6
|
export declare function getCloudflareWorkflowBindingName(name: string): string;
|
|
54
|
-
export declare function getCloudflareWorkflowName(name: string): string;
|
|
55
|
-
export declare function getCloudflareWorkflowClassName(name: string): string;
|
|
56
|
-
//#endregion
|
|
57
|
-
//#region src/integrations/vercel.d.ts
|
|
58
|
-
export declare function getVercelWorkflowName(name: string): string;
|
|
59
7
|
//#endregion
|
|
60
8
|
//#region src/runtime/client.d.ts
|
|
61
9
|
export declare function createWorkflow<TPayload = unknown, TResult = unknown>(options: WorkflowCreateOptions<TPayload, TResult> & {
|
|
@@ -69,11 +17,34 @@ export declare function createWorkflow<TPayload = unknown>(name: string, options
|
|
|
69
17
|
handler?: never;
|
|
70
18
|
}): WorkflowHandle<TPayload, unknown>;
|
|
71
19
|
export declare function createWorkflow<TPayload = unknown, TResult = unknown>(name: string, handler: WorkflowHandler<TPayload, TResult>, options?: WorkflowCreateOptions<TPayload, TResult>): WorkflowHandle<TPayload, TResult>;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Starts one durable run of a Workflow Definition and returns `[error, run]`. `run` has the id and the status.
|
|
22
|
+
* The name and the payload type come from `WorkflowRegistry`, which ViteHub writes to `.vitehub/workflow.d.ts`.
|
|
23
|
+
* A provider failure, an unsupported option, or an invalid `delay` is `error`. Config errors, for example an unknown
|
|
24
|
+
* Workflow name, throw.
|
|
25
|
+
*/
|
|
26
|
+
export declare function startWorkflow<TArgs extends WorkflowStartCall>(...args: TArgs): Promise<Result<WorkflowRun<WorkflowPayload<TArgs[0]>, unknown>, WorkflowResultErrorCode>>;
|
|
27
|
+
type WorkflowStartCall = { [TName in WorkflowName]: [name: TName, ...WorkflowStartArguments<WorkflowPayload<TName>>]; }[WorkflowName];
|
|
28
|
+
/**
|
|
29
|
+
* Reads one run and returns `[error, run]`. A provider failure is `error`. A run that the provider does not know has
|
|
30
|
+
* `status: "unknown"`. Config errors throw.
|
|
31
|
+
*/
|
|
32
|
+
export declare function getWorkflowRun(name: string, id: string): Promise<Result<WorkflowRun<unknown, unknown>, WorkflowResultErrorCode>>;
|
|
33
|
+
/**
|
|
34
|
+
* Cancels one run and returns `[error, run]`. A provider failure, or a provider that cannot cancel the run, is
|
|
35
|
+
* `error`. Config errors, for example an unknown Workflow name, throw.
|
|
36
|
+
*/
|
|
37
|
+
export declare function cancelWorkflow(name: string, id: string): Promise<Result<WorkflowRun<unknown, unknown>, WorkflowResultErrorCode>>;
|
|
38
|
+
/**
|
|
39
|
+
* Resumes a run that waits for a signal and returns `[error, signal]`. `token` is the opaque token that the provider
|
|
40
|
+
* gave the waiting step. An empty token or a provider failure is `error`. Config errors throw.
|
|
41
|
+
*/
|
|
42
|
+
export declare function resumeWorkflow<TPayload = unknown>(token: string, payload: TPayload): Promise<Result<WorkflowSignalResult, WorkflowResultErrorCode>>;
|
|
43
|
+
/**
|
|
44
|
+
* Starts a run after the response, through `waitUntil`. It returns nothing: a failure goes to the log.
|
|
45
|
+
* Call `startWorkflow()` when the caller needs the run ID or the start error.
|
|
46
|
+
*/
|
|
47
|
+
export declare function deferWorkflow(...[name, payload, options]: WorkflowStartCall): void;
|
|
77
48
|
//#endregion
|
|
78
49
|
//#region src/runtime/payload.d.ts
|
|
79
50
|
interface PayloadSchema<T> {
|
|
@@ -87,8 +58,9 @@ interface ParsePayloadSchema<T> {
|
|
|
87
58
|
parse: (payload: unknown) => T;
|
|
88
59
|
}
|
|
89
60
|
type PayloadValidator<T> = PayloadSchema<T> | ParsePayloadSchema<T> | ((payload: unknown) => T | Promise<T>);
|
|
90
|
-
|
|
61
|
+
/** Reads a JSON body as parsed JSON and any other body as text. The value is not checked: pass it to `validatePayload()`. */
|
|
62
|
+
export declare function readRequestPayload(request: Request): Promise<unknown>;
|
|
91
63
|
export declare function validatePayload<T>(payload: unknown, schema: PayloadValidator<T>): Promise<T>;
|
|
92
64
|
export declare function readValidatedPayload<T>(request: Request, schema: PayloadValidator<T>): Promise<T>;
|
|
93
65
|
//#endregion
|
|
94
|
-
export { type CloudflareWorkflowBinding, type
|
|
66
|
+
export { type CloudflareWorkflowBinding, type CloudflareWorkflowDriverOptions, type CloudflareWorkflowInstance, type DiscoveredWorkflowDefinition, type InferredWorkflowDriverOptions, NonRetryableError, type OpenWorkflowDriverOptions, type OpenWorkflowPostgresOptions, type OpenWorkflowWorkerOptions, type ResolvedWorkflowOptions, type VercelWorkflowDriverOptions, type WorkflowCreateOptions, type WorkflowDefinition, type WorkflowDefinitionOptions, type WorkflowDefinitionRegistry, type WorkflowDriver, type WorkflowDriverOptions, type WorkflowDuration, type WorkflowDurationUnit, type WorkflowErrorCode, type WorkflowErrorDetails, type WorkflowExecutionContext, type WorkflowHandle, type WorkflowHandler, type WorkflowModuleDriverOptions, type WorkflowName, type WorkflowOperationName, type WorkflowOptions, type WorkflowPayload, type WorkflowProviderContext, type WorkflowProviderFailure, type WorkflowProviderName, type WorkflowProviderStep, type WorkflowRegistry, type WorkflowResultErrorCode, type WorkflowRun, type WorkflowRunError, type WorkflowRunStatus, type WorkflowRunStep, type WorkflowSharedOptions, type WorkflowSignalResult, type WorkflowStartDelay, type WorkflowStartOptions, type WorkflowStep, type WorkflowStepBackoff, type WorkflowStepContext, type WorkflowStepFunction, type WorkflowStepOptions, type WorkflowStepRegistry, type WorkflowStepRetries, type WorkflowSteps, defineWorkflow };
|
package/dist/index.js
CHANGED
|
@@ -1,23 +1,19 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { t as
|
|
6
|
-
//#region src/definition.ts
|
|
7
|
-
function defineWorkflow(handler, options) {
|
|
8
|
-
if (typeof handler !== "function") throw workflowErrorDiagnostics.WORKFLOW_C0014({ message: "`defineWorkflow()` requires a workflow handler." });
|
|
9
|
-
if (typeof options !== "undefined" && (!options || typeof options !== "object" || Array.isArray(options))) throw workflowErrorDiagnostics.WORKFLOW_C0015({ message: "`defineWorkflow()` options must be a plain object." });
|
|
10
|
-
if (options?.native !== void 0 && typeof options.native !== "function") throw workflowErrorDiagnostics.WORKFLOW_C0016({ message: "`defineWorkflow()` native entry must be a workflow handler." });
|
|
11
|
-
return {
|
|
12
|
-
handler,
|
|
13
|
-
options
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
//#endregion
|
|
1
|
+
import { t as workflowErrorDiagnostics } from "./error-diagnostics-0V2T3JFw.js";
|
|
2
|
+
import { defineWorkflow } from "./definition.js";
|
|
3
|
+
import { t as NonRetryableError } from "./errors-DCqRnZpN.js";
|
|
4
|
+
import { n as getCloudflareWorkflowBindingName } from "./cloudflare-BHfClPvT.js";
|
|
5
|
+
import { a as resumeWorkflow, i as getWorkflowRun, n as createWorkflow, o as startWorkflow, r as deferWorkflow, t as cancelWorkflow } from "./client-DkwOxEiT.js";
|
|
17
6
|
//#region src/runtime/payload.ts
|
|
7
|
+
/** Reads a JSON body as parsed JSON and any other body as text. The value is not checked: pass it to `validatePayload()`. */
|
|
18
8
|
async function readRequestPayload(request) {
|
|
19
|
-
|
|
20
|
-
|
|
9
|
+
const contentType = request.headers.get("content-type")?.split(";", 1)[0]?.trim().toLowerCase();
|
|
10
|
+
const text = await request.text();
|
|
11
|
+
if (contentType !== "application/json") return text;
|
|
12
|
+
try {
|
|
13
|
+
return JSON.parse(text);
|
|
14
|
+
} catch (cause) {
|
|
15
|
+
throw workflowErrorDiagnostics.WORKFLOW_PAYLOAD_JSON_INVALID({ cause });
|
|
16
|
+
}
|
|
21
17
|
}
|
|
22
18
|
async function validatePayload(payload, schema) {
|
|
23
19
|
if (typeof schema === "function") return await schema(payload);
|
|
@@ -45,4 +41,4 @@ async function readValidatedPayload(request, schema) {
|
|
|
45
41
|
return await validatePayload(await readRequestPayload(request), schema);
|
|
46
42
|
}
|
|
47
43
|
//#endregion
|
|
48
|
-
export { cancelWorkflow, createWorkflow,
|
|
44
|
+
export { NonRetryableError, cancelWorkflow, createWorkflow, deferWorkflow, defineWorkflow, getCloudflareWorkflowBindingName, getWorkflowRun, readRequestPayload, readValidatedPayload, resumeWorkflow, startWorkflow, validatePayload };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region ../internal/src/object.ts
|
|
2
|
+
/** A non-null object that is not an array. Functions do not pass. */
|
|
3
|
+
function isRecord(value) {
|
|
4
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5
|
+
}
|
|
6
|
+
/** A non-null object or a function that is not an array. */
|
|
7
|
+
function isRecordOrFunction(value) {
|
|
8
|
+
return Object(value) === value && !Array.isArray(value);
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { isRecordOrFunction as n, isRecord as t };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { A as WorkflowRun, f as WorkflowDefinition, l as ResolvedWorkflowOptions, z as WorkflowStartOptions } from "./types-Dsmwsdlv.js";
|
|
2
|
+
//#region src/runtime/openworkflow.d.ts
|
|
3
|
+
type OpenWorkflowModule = typeof import("openworkflow");
|
|
4
|
+
type OpenWorkflowPostgresModule = typeof import("openworkflow/postgres");
|
|
5
|
+
type OpenWorkflowSqliteModule = typeof import("openworkflow/sqlite");
|
|
6
|
+
type OpenWorkflowClient = InstanceType<OpenWorkflowModule["OpenWorkflow"]>;
|
|
7
|
+
type OpenWorkflowBackend = Awaited<ReturnType<OpenWorkflowPostgresModule["BackendPostgres"]["connect"]>> | ReturnType<OpenWorkflowSqliteModule["BackendSqlite"]["connect"]>;
|
|
8
|
+
type OpenWorkflowRunnable = ReturnType<OpenWorkflowClient["defineWorkflow"]>;
|
|
9
|
+
type OpenWorkflowImporter = <T>(specifier: string) => Promise<T>;
|
|
10
|
+
interface OpenWorkflowRuntime {
|
|
11
|
+
backend: OpenWorkflowBackend;
|
|
12
|
+
client: OpenWorkflowClient;
|
|
13
|
+
/** The registered ViteHub definitions, by name. */
|
|
14
|
+
definitions: Map<string, WorkflowDefinition>;
|
|
15
|
+
/** Returns the OpenWorkflow id of the first run of `name` that started with the id `key`. */
|
|
16
|
+
findRunId: (name: string, key: string) => Promise<string | undefined>;
|
|
17
|
+
workflows: Map<string, OpenWorkflowRunnable>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Where the storage came from: `configured` options or environment variables, the Postgres Default `database` of the
|
|
21
|
+
* app, or the `default` SQLite file.
|
|
22
|
+
*/
|
|
23
|
+
type OpenWorkflowStorageSource = "configured" | "database" | "default";
|
|
24
|
+
/**
|
|
25
|
+
* Makes OpenWorkflow use the Postgres Default Database of the app when no OpenWorkflow storage is configured. The
|
|
26
|
+
* generated startup plugin installs it when the build has a Postgres Default Database.
|
|
27
|
+
*/
|
|
28
|
+
declare function setOpenWorkflowDatabaseUrl(resolve: (() => string | undefined) | undefined): void;
|
|
29
|
+
/** The storage that OpenWorkflow uses for `config` now, without credentials. */
|
|
30
|
+
declare function describeOpenWorkflowStorage(config: ResolvedWorkflowOptions): {
|
|
31
|
+
backend: "postgres" | "sqlite";
|
|
32
|
+
location: string;
|
|
33
|
+
source: OpenWorkflowStorageSource;
|
|
34
|
+
};
|
|
35
|
+
declare function getOpenWorkflowRuntime(config: ResolvedWorkflowOptions): Promise<OpenWorkflowRuntime>;
|
|
36
|
+
declare function registerOpenWorkflowDefinition(runtime: OpenWorkflowRuntime, name: string, definition: WorkflowDefinition): Promise<OpenWorkflowRunnable>;
|
|
37
|
+
declare function runOpenWorkflow<TPayload = unknown, TResult = unknown>(config: ResolvedWorkflowOptions, name: string, payload: TPayload | undefined, definition: WorkflowDefinition<TPayload, TResult>, options: WorkflowStartOptions, onDispatch?: () => void, startAt?: number): Promise<WorkflowRun<TPayload, TResult>>;
|
|
38
|
+
declare function getOpenWorkflowRun<TPayload = unknown, TResult = unknown>(config: ResolvedWorkflowOptions, name: string, id: string): Promise<WorkflowRun<TPayload, TResult>>;
|
|
39
|
+
/**
|
|
40
|
+
* Cancels a pending or running OpenWorkflow run of this Workflow and returns its state afterwards. A run of another
|
|
41
|
+
* Workflow, or an unknown run, reports `unknown` without being cancelled. A finished run keeps and reports its status.
|
|
42
|
+
*/
|
|
43
|
+
declare function cancelOpenWorkflowRun<TPayload = unknown, TResult = unknown>(config: ResolvedWorkflowOptions, name: string, id: string): Promise<WorkflowRun<TPayload, TResult>>;
|
|
44
|
+
declare function resetOpenWorkflowRuntime(): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Starts a new runtime cache, so the next acquisition opens a fresh backend. Returns a function that closes the
|
|
47
|
+
* backends of the old cache. Call it after the work that still uses them, such as a stopping worker, finishes.
|
|
48
|
+
*/
|
|
49
|
+
declare function detachOpenWorkflowRuntimes(): () => Promise<void>;
|
|
50
|
+
declare function setOpenWorkflowImporter(importer: OpenWorkflowImporter): void;
|
|
51
|
+
//#endregion
|
|
52
|
+
export { getOpenWorkflowRun as a, resetOpenWorkflowRuntime as c, setOpenWorkflowImporter as d, detachOpenWorkflowRuntimes as i, runOpenWorkflow as l, cancelOpenWorkflowRun as n, getOpenWorkflowRuntime as o, describeOpenWorkflowStorage as r, registerOpenWorkflowDefinition as s, OpenWorkflowStorageSource as t, setOpenWorkflowDatabaseUrl as u };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { defineDiagnostics } from "nostics";
|
|
2
|
+
//#region ../internal/src/invariant.ts
|
|
3
|
+
const invariantDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
4
|
+
docsBase: "https://vitehub.dev/docs/development/diagnostics",
|
|
5
|
+
codes: { INTERNAL_INVARIANT_FAILED: {
|
|
6
|
+
why: ({ what }) => `ViteHub reached a state that it does not expect: ${what}`,
|
|
7
|
+
fix: "This is a ViteHub bug. Open an issue at https://github.com/vite-hub/vitehub/issues with this error message and its stack trace."
|
|
8
|
+
} }
|
|
9
|
+
});
|
|
10
|
+
/**
|
|
11
|
+
* The error for a state that only a ViteHub bug can reach, such as an impossible branch. `what` says which rule broke.
|
|
12
|
+
* Use a code from the package catalog when a developer can cause the error or fix it.
|
|
13
|
+
*/
|
|
14
|
+
function invariantError(what) {
|
|
15
|
+
return invariantDiagnostics.INTERNAL_INVARIANT_FAILED({ what });
|
|
16
|
+
}
|
|
17
|
+
/** Throws `INTERNAL_INVARIANT_FAILED` when `condition` is falsy. */
|
|
18
|
+
function invariant(condition, what) {
|
|
19
|
+
if (!condition) throw invariantError(what);
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/internal/openworkflow-defaults.ts
|
|
23
|
+
/** The SQLite file that OpenWorkflow uses without configured storage, relative to the working directory of the server. */
|
|
24
|
+
const defaultOpenWorkflowSqlitePath = ".vitehub/data/openworkflow.sqlite.db";
|
|
25
|
+
//#endregion
|
|
26
|
+
export { invariant as n, invariantError as r, defaultOpenWorkflowSqlitePath as t };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//#region src/internal/openworkflow-storage.ts
|
|
2
|
+
/** Select storage once for both the OpenWorkflow runtime and its durability report. Values are already resolved. */
|
|
3
|
+
function resolveOpenWorkflowStorage(input, readEnv) {
|
|
4
|
+
const sqlitePath = input.sqlitePath || (!input.postgresUrl ? readEnv("OPENWORKFLOW_SQLITE_PATH") : void 0);
|
|
5
|
+
if (sqlitePath) return {
|
|
6
|
+
backend: "sqlite",
|
|
7
|
+
path: sqlitePath,
|
|
8
|
+
source: "configured"
|
|
9
|
+
};
|
|
10
|
+
if (input.postgresUrl) return {
|
|
11
|
+
backend: "postgres",
|
|
12
|
+
url: input.postgresUrl,
|
|
13
|
+
source: "`workflow.postgres.url`"
|
|
14
|
+
};
|
|
15
|
+
const url = readEnv("OPENWORKFLOW_POSTGRES_URL");
|
|
16
|
+
if (url) return {
|
|
17
|
+
backend: "postgres",
|
|
18
|
+
url,
|
|
19
|
+
source: "OPENWORKFLOW_POSTGRES_URL"
|
|
20
|
+
};
|
|
21
|
+
return {
|
|
22
|
+
backend: "sqlite",
|
|
23
|
+
path: ".vitehub/data/openworkflow.sqlite.db",
|
|
24
|
+
source: "default"
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { resolveOpenWorkflowStorage as t };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { CreateOpenWorkflowWorkerOptions, InstallOpenWorkflowOptions, OpenWorkflowWorkerApp, StartOpenWorkflowWorkerOptions, createOpenWorkflowWorker, installOpenWorkflow, startOpenWorkflowWorker } from "./runtime/openworkflow-worker.js";
|
|
2
|
+
export { CreateOpenWorkflowWorkerOptions, InstallOpenWorkflowOptions, OpenWorkflowWorkerApp, StartOpenWorkflowWorkerOptions, createOpenWorkflowWorker, installOpenWorkflow, startOpenWorkflowWorker };
|
|
@@ -75,7 +75,7 @@ declare namespace StandardSchemaV1 {
|
|
|
75
75
|
type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
|
|
76
76
|
}
|
|
77
77
|
//#endregion
|
|
78
|
-
//#region ../internal/src/
|
|
78
|
+
//#region ../internal/src/operation-definition.d.ts
|
|
79
79
|
/** `read` never changes state. `write` changes state. `destructive` deletes or publishes. */
|
|
80
80
|
type OperationKind = "read" | "write" | "destructive";
|
|
81
81
|
/** The signed-in user of a call. */
|
|
@@ -98,7 +98,9 @@ interface OperationAccess {
|
|
|
98
98
|
readonly mode: string;
|
|
99
99
|
/**
|
|
100
100
|
* The sections that the call may use. `"all"` when no section filter applies. An entry is a section id (`"kv"`, every
|
|
101
|
-
* operation of the section)
|
|
101
|
+
* operation of the section), `"<section>:read"` (only the operations that read), or `"<section>:<scope>"` (only the
|
|
102
|
+
* calls of a scoped operation for that scope, such as `"blob:media"` for one Blob store). `"<section>:<scope>:read"`
|
|
103
|
+
* allows only the reads of that scope.
|
|
102
104
|
*/
|
|
103
105
|
readonly sections: "all" | readonly string[];
|
|
104
106
|
readonly user?: OperationUser;
|
|
@@ -113,9 +115,20 @@ interface OperationContext {
|
|
|
113
115
|
surface: "console" | "cli" | "mcp" | "agent";
|
|
114
116
|
/** Set by the host from generated build identity, never from request input or runtime NODE_ENV. */
|
|
115
117
|
development?: boolean;
|
|
118
|
+
/**
|
|
119
|
+
* The project root of a development server, for operations that read build files, such as `bundle.report`. Hosts set
|
|
120
|
+
* it only with `development`, so a deployed server never reads project files through it.
|
|
121
|
+
*/
|
|
122
|
+
projectRoot?: string;
|
|
116
123
|
env?: Record<string, unknown>;
|
|
117
124
|
waitUntil?: (task: Promise<unknown>) => void;
|
|
118
125
|
request?: Request;
|
|
126
|
+
/**
|
|
127
|
+
* The request event of the HTTP request that carries the call, when there is one: the Request of the Console route,
|
|
128
|
+
* with its Standard Context. Operations hand it to app hooks that read the request's own session, such as `identify`
|
|
129
|
+
* of Comments.
|
|
130
|
+
*/
|
|
131
|
+
event?: unknown;
|
|
119
132
|
/** Operations set a success status here, such as 202 for an accepted call. */
|
|
120
133
|
response?: {
|
|
121
134
|
status?: number;
|
|
@@ -138,9 +151,16 @@ interface OperationDefinition<Input, Output> {
|
|
|
138
151
|
description: string;
|
|
139
152
|
/**
|
|
140
153
|
* Console section that grants access, such as `content`. `false`: any Console user. A function reads the section
|
|
141
|
-
* from the input, for operations that serve several sections.
|
|
154
|
+
* from the input, for operations that serve several sections. Section ids cannot contain `:`; it is reserved for
|
|
155
|
+
* scope and read-only grants. A function that returns an invalid id denies the call.
|
|
142
156
|
*/
|
|
143
157
|
section: string | false | ((input: Input) => string | undefined);
|
|
158
|
+
/**
|
|
159
|
+
* The part of a string `section` that one call uses, such as the Blob store that the input names. The call then needs
|
|
160
|
+
* the section (every scope) or `"<section>:<scope>"` (only this scope). A scope that is empty, is `read`, or has a
|
|
161
|
+
* `:` needs the whole section.
|
|
162
|
+
*/
|
|
163
|
+
scope?: (input: Input) => string | undefined;
|
|
144
164
|
/** `read` never changes state. `write` changes state. `destructive` deletes or publishes; the CLI asks for `--yes`, MCP marks `destructiveHint`, agents require approval by default. */
|
|
145
165
|
kind: OperationKind;
|
|
146
166
|
/** Standard Schema (valibot in this repo). Its Standard JSON Schema builds CLI flags and the MCP input schema. */
|
|
@@ -149,19 +169,14 @@ interface OperationDefinition<Input, Output> {
|
|
|
149
169
|
cli?: {
|
|
150
170
|
/** Defaults: namespace = section, command = verb. */
|
|
151
171
|
namespace?: string;
|
|
172
|
+
/** A space groups commands: `jobs list` and `jobs show` run as `vitehub <namespace> jobs list` and `jobs show`. */
|
|
152
173
|
command?: string;
|
|
153
174
|
/** Input keys read from positional arguments, in order. */
|
|
154
175
|
positional?: string[];
|
|
155
176
|
/** Human output, written verbatim. Without it the CLI prints JSON. `--json` always prints JSON. */
|
|
156
177
|
format?: (output: Output) => string;
|
|
157
|
-
/** `vitehub <namespace>` runs this command when no command is named
|
|
178
|
+
/** `vitehub <namespace>` runs this command when no command is named. */
|
|
158
179
|
default?: boolean;
|
|
159
|
-
/**
|
|
160
|
-
* Route of the app that takes a signed dispatch of this operation, such as `/_vitehub/schedules/run`. With `--url`
|
|
161
|
-
* and a dispatch key in the environment (`VITEHUB_DISPATCH_KEY`), the command signs the input and posts it there, so
|
|
162
|
-
* a CI job needs no Console credentials. Without a key it calls the RPC.
|
|
163
|
-
*/
|
|
164
|
-
dispatch?: string;
|
|
165
180
|
};
|
|
166
181
|
/** Largest request body in bytes. It can raise the 64 KiB default but not lower it. */
|
|
167
182
|
maxRequestBytes?: number;
|
|
@@ -170,8 +185,16 @@ interface OperationDefinition<Input, Output> {
|
|
|
170
185
|
* confirmation, and agents run it without approval. Without it, every call of a `destructive` operation asks.
|
|
171
186
|
*/
|
|
172
187
|
readOnlyWhen?: (input: Input) => boolean;
|
|
173
|
-
/**
|
|
174
|
-
|
|
188
|
+
/**
|
|
189
|
+
* How MCP offers the operation as a tool. `false`: MCP does not offer it, such as an editor transport that only the
|
|
190
|
+
* Console uses. `title`: the short title that clients show, instead of the name in words. `format`: the text of a
|
|
191
|
+
* result for the Agent, such as a list of lines. The result stays the structured content. Without `format`, the text
|
|
192
|
+
* is the result as JSON.
|
|
193
|
+
*/
|
|
194
|
+
mcp?: false | {
|
|
195
|
+
title?: string;
|
|
196
|
+
format?: (output: NoInfer<Output>) => string;
|
|
197
|
+
};
|
|
175
198
|
/** `false`: the operation never reads `context.user`, so the Console skips the session lookup for it. */
|
|
176
199
|
user?: false;
|
|
177
200
|
/**
|
|
@@ -182,24 +205,28 @@ interface OperationDefinition<Input, Output> {
|
|
|
182
205
|
run: (input: Input, context: OperationContext) => Output | Promise<Output>;
|
|
183
206
|
}
|
|
184
207
|
/** An operation of any input and output, as a registry holds it. */
|
|
185
|
-
interface AnyOperation extends Omit<OperationDefinition<unknown, unknown>, "cli" | "input" | "output" | "readOnlyWhen" | "run" | "section"> {
|
|
208
|
+
interface AnyOperation extends Omit<OperationDefinition<unknown, unknown>, "cli" | "input" | "mcp" | "output" | "readOnlyWhen" | "run" | "scope" | "section"> {
|
|
186
209
|
readOnlyWhen?: (input: never) => boolean;
|
|
187
210
|
cli?: {
|
|
188
211
|
namespace?: string;
|
|
189
212
|
command?: string;
|
|
190
213
|
default?: boolean;
|
|
191
|
-
dispatch?: string;
|
|
192
214
|
positional?: string[];
|
|
193
215
|
format?: (output: never) => string;
|
|
194
216
|
};
|
|
217
|
+
mcp?: false | {
|
|
218
|
+
title?: string;
|
|
219
|
+
format?: (output: never) => string;
|
|
220
|
+
};
|
|
195
221
|
input: StandardSchemaV1;
|
|
196
222
|
output?: StandardSchemaV1;
|
|
197
223
|
run: (input: never, context: OperationContext) => unknown;
|
|
224
|
+
scope?: (input: never) => string | undefined;
|
|
198
225
|
section: string | false | ((input: never) => string | undefined);
|
|
199
226
|
}
|
|
200
227
|
/** The contribution of one plugin: operations, or a module that exports them. */
|
|
201
228
|
interface OperationContributionEntry {
|
|
202
|
-
/**
|
|
229
|
+
/** The absolute path of the module that generated code imports, such as `ownModule(import.meta.url, "operations")`. */
|
|
203
230
|
module: string;
|
|
204
231
|
/** Named export that holds an operation or an array of operations. Defaults to `default`. */
|
|
205
232
|
export?: string;
|