@vite-hub/workflow 0.0.4 → 0.3.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.
Files changed (65) hide show
  1. package/README.md +168 -47
  2. package/dist/{_app-DgwN4ulW.d.ts → app-BojnC_yf.d.ts} +1 -4
  3. package/dist/{app-BZpq2cwC.js → app-CmMq8l4t.js} +2 -1
  4. package/dist/client-CU5rELC0.js +658 -0
  5. package/dist/{cloudflare-D0Di-QYL.js → cloudflare-BfFnNWB0.js} +20 -4
  6. package/dist/cloudflare-env-CGLx7lUd.js +115 -0
  7. package/dist/cloudflare-env-lookup-CfX6wZKb.d.ts +4 -0
  8. package/dist/{cloudflare-env-CIjdFTv6.d.ts → cloudflare-shared-CTqh_a2s.d.ts} +2 -2
  9. package/dist/config-DCvRDlxA.js +145 -0
  10. package/dist/definition.d.ts +19 -0
  11. package/dist/definition.js +31 -0
  12. package/dist/delay--ESDybVT.js +81 -0
  13. package/dist/dev-recorder-CTN5Fkao.js +10 -0
  14. package/dist/durability.d.ts +23 -0
  15. package/dist/durability.js +62 -0
  16. package/dist/error-diagnostics-8YNJ37rP.js +286 -0
  17. package/dist/error-diagnostics-DSkCJC_L.js +266 -0
  18. package/dist/errors-DCqRnZpN.js +35 -0
  19. package/dist/errors-DVwFb6Fd.d.ts +56 -0
  20. package/dist/index.d.ts +23 -71
  21. package/dist/index.js +23 -378
  22. package/dist/inspect-B72iFyj-.js +70 -0
  23. package/dist/object-Da1zyPCR.js +11 -0
  24. package/dist/openworkflow-TEaNk0LV.d.ts +50 -0
  25. package/dist/openworkflow-defaults-DDig2M4s.js +26 -0
  26. package/dist/openworkflow-storage-Dj9zUAsk.js +28 -0
  27. package/dist/openworkflow.d.ts +2 -0
  28. package/dist/openworkflow.js +2 -0
  29. package/dist/operation-definition-8gOe-ubD.d.ts +234 -0
  30. package/dist/operations-B0L8kV5s.js +329 -0
  31. package/dist/operations.d.ts +71 -0
  32. package/dist/operations.js +314 -0
  33. package/dist/out-fRNaVslw.js +20357 -0
  34. package/dist/rolldown-runtime-CMFfr-1z.js +26 -0
  35. package/dist/run-error-DBWqiJHH.js +110 -0
  36. package/dist/runtime/cloudflare-runner.d.ts +7 -19
  37. package/dist/runtime/cloudflare-runner.js +27 -10
  38. package/dist/runtime/cloudflare-shared.d.ts +2 -1
  39. package/dist/runtime/cloudflare-shared.js +1 -1
  40. package/dist/runtime/cloudflare-vite.d.ts +10 -11
  41. package/dist/runtime/cloudflare-vite.js +47 -1
  42. package/dist/runtime/dev-runs.d.ts +4 -0
  43. package/dist/runtime/dev-runs.js +73 -0
  44. package/dist/runtime/execute.d.ts +24 -7
  45. package/dist/runtime/execute.js +135 -6
  46. package/dist/runtime/openworkflow-worker.d.ts +34 -9
  47. package/dist/runtime/openworkflow-worker.js +156 -37
  48. package/dist/runtime/openworkflow.d.ts +2 -23
  49. package/dist/runtime/openworkflow.js +289 -46
  50. package/dist/runtime/state.d.ts +22 -21
  51. package/dist/runtime/state.js +99 -25
  52. package/dist/runtime/vercel-vite.d.ts +10 -12
  53. package/dist/runtime/vercel-vite.js +7 -4
  54. package/dist/types-CnKVDnEp.d.ts +241 -0
  55. package/dist/{vercel-B0MuIVgJ.js → vercel-BZU_O6ay.js} +78 -24
  56. package/dist/vite.d.ts +529 -23
  57. package/dist/vite.js +2789 -1609
  58. package/package.json +62 -34
  59. package/dist/cloudflare-env-DjxQNbrx.js +0 -58
  60. package/dist/cloudflare-shared-BVVgDSdq.d.ts +0 -1
  61. package/dist/cloudflare-vite-BkDgB6Sr.js +0 -46
  62. package/dist/config-BHknO_rT.js +0 -136
  63. package/dist/provider-operation-CW2cYfVy.js +0 -65
  64. package/dist/runtime-type-DGUn8Ple.js +0 -37
  65. package/dist/types-B9RdRkKh.d.ts +0 -169
package/package.json CHANGED
@@ -1,17 +1,20 @@
1
1
  {
2
2
  "name": "@vite-hub/workflow",
3
- "version": "0.0.4",
3
+ "version": "0.3.1",
4
4
  "description": "Workflow primitives and Vite integration for ViteHub.",
5
5
  "keywords": [
6
+ "background-jobs",
6
7
  "cloudflare",
7
8
  "docker",
9
+ "durable-execution",
8
10
  "openworkflow",
11
+ "typescript",
9
12
  "vercel",
10
13
  "vite",
11
14
  "vitehub",
12
15
  "workflow"
13
16
  ],
14
- "homepage": "https://github.com/vite-hub/vitehub#readme",
17
+ "homepage": "https://vitehub.dev",
15
18
  "bugs": "https://github.com/vite-hub/vitehub/issues",
16
19
  "license": "Apache-2.0",
17
20
  "author": "onmax <maximogarciamtnez@gmail.com>",
@@ -28,51 +31,76 @@
28
31
  "sideEffects": false,
29
32
  "types": "./dist/index.d.ts",
30
33
  "exports": {
31
- ".": "./dist/index.js",
32
- "./runtime/cloudflare-runner": "./dist/runtime/cloudflare-runner.js",
33
- "./runtime/cloudflare-shared": "./dist/runtime/cloudflare-shared.js",
34
- "./runtime/cloudflare-vite": "./dist/runtime/cloudflare-vite.js",
35
- "./runtime/execute": "./dist/runtime/execute.js",
36
- "./runtime/openworkflow": "./dist/runtime/openworkflow.js",
37
- "./runtime/openworkflow-worker": "./dist/runtime/openworkflow-worker.js",
38
- "./runtime/state": "./dist/runtime/state.js",
39
- "./runtime/vercel-vite": "./dist/runtime/vercel-vite.js",
40
- "./vite": "./dist/vite.js",
34
+ ".": {
35
+ "types": "./dist/index.d.ts",
36
+ "import": "./dist/index.js",
37
+ "default": "./dist/index.js"
38
+ },
39
+ "./durability": {
40
+ "types": "./dist/durability.d.ts",
41
+ "import": "./dist/durability.js",
42
+ "default": "./dist/durability.js"
43
+ },
44
+ "./runtime/openworkflow": {
45
+ "types": "./dist/runtime/openworkflow.d.ts",
46
+ "import": "./dist/runtime/openworkflow.js",
47
+ "default": "./dist/runtime/openworkflow.js"
48
+ },
49
+ "./openworkflow": {
50
+ "types": "./dist/openworkflow.d.ts",
51
+ "import": "./dist/openworkflow.js",
52
+ "default": "./dist/openworkflow.js"
53
+ },
54
+ "./runtime/state": {
55
+ "types": "./dist/runtime/state.d.ts",
56
+ "import": "./dist/runtime/state.js",
57
+ "default": "./dist/runtime/state.js"
58
+ },
59
+ "./vite": {
60
+ "types": "./dist/vite.d.ts",
61
+ "import": "./dist/vite.js",
62
+ "default": "./dist/vite.js"
63
+ },
41
64
  "./package.json": "./package.json"
42
65
  },
43
66
  "dependencies": {
44
- "@vercel/functions": "^3.7.5",
45
- "@vite-hub/runtime": "0.0.4",
67
+ "@valibot/to-json-schema": "^1.8.0",
68
+ "@vite-hub/runtime": "0.3.1",
46
69
  "defu": "^6.1.7",
47
- "esbuild": "^0.28.1",
48
- "h3": "2.0.1-rc.25",
49
- "pathe": "^2.0.3"
70
+ "esbuild": "^0.28.2",
71
+ "h3": "^2.0.8",
72
+ "nostics": "1.4.0",
73
+ "openworkflow": "^0.9.2",
74
+ "pathe": "^2.0.3",
75
+ "postgres": "^3.4.9",
76
+ "semver": "^7.8.5",
77
+ "valibot": "^1.5.0"
50
78
  },
51
79
  "devDependencies": {
52
- "@types/node": "^24.13.3",
53
- "openworkflow": "^0.9.0",
54
- "publint": "^0.3.21",
80
+ "@types/node": "^24.19.1",
81
+ "@vercel/functions": "^3.9.11",
82
+ "@vite-hub/internal": "0.0.1",
83
+ "publint": "^0.3.25",
55
84
  "typescript": "^6.0.3",
56
- "vite": "^8.0.8",
57
- "vite-plus": "^0.1.24",
58
- "vitest": "^4.1.4",
59
- "@vite-hub/internal": "0.0.1"
85
+ "vite": "^8.2.2",
86
+ "vite-plus": "^0.3.3",
87
+ "vitest": "^4.1.11"
60
88
  },
61
89
  "peerDependencies": {
62
- "@vite-hub/database": "0.0.4",
63
- "@workflow/builders": "5.0.0-beta.35",
64
- "openworkflow": "^0.9.0",
90
+ "@vercel/functions": "^3.9.11",
91
+ "@vite-hub/database": "0.3.1",
92
+ "@workflow/builders": "^5.0.6",
65
93
  "vite": ">=8.0.0",
66
- "workflow": "5.0.0-beta.35"
94
+ "workflow": "^5.2.3"
67
95
  },
68
96
  "peerDependenciesMeta": {
69
- "@vite-hub/database": {
97
+ "@vercel/functions": {
70
98
  "optional": true
71
99
  },
72
- "@workflow/builders": {
100
+ "@vite-hub/database": {
73
101
  "optional": true
74
102
  },
75
- "openworkflow": {
103
+ "@workflow/builders": {
76
104
  "optional": true
77
105
  },
78
106
  "vite": {
@@ -83,12 +111,12 @@
83
111
  }
84
112
  },
85
113
  "engines": {
86
- "node": ">=24.0.0"
114
+ "node": ">=22.18.0"
87
115
  },
88
116
  "scripts": {
89
117
  "build": "vp pack",
90
118
  "dev": "vp pack --watch",
91
- "typecheck": "tsc --noEmit -p ./tsconfig.json",
92
- "test": "vp run -t @vite-hub/workflow#build && vp test"
119
+ "typecheck": "vp run --cache -t @vite-hub/workflow#build && node ../../test/package-typecheck.mjs --noEmit -p ./tsconfig.json",
120
+ "test": "vp run --cache -t @vite-hub/workflow#build && vp run --cache -t @vite-hub/agent#build && vp test"
93
121
  }
94
122
  }
@@ -1,58 +0,0 @@
1
- import { AsyncLocalStorage } from "node:async_hooks";
2
- //#region ../internal/src/runtime/cloudflare-env.ts
3
- let activeEnv;
4
- const activeEnvStorageKey = Symbol.for("vitehub.cloudflare.env-storage");
5
- const runtimeGlobal = globalThis;
6
- const activeEnvStorage = runtimeGlobal[activeEnvStorageKey] ||= new AsyncLocalStorage();
7
- function setActiveCloudflareEnv(env) {
8
- activeEnv = env;
9
- globalThis.__env__ = env;
10
- try {
11
- activeEnvStorage.enterWith({ env });
12
- } catch {}
13
- }
14
- function runWithActiveCloudflareEnv(env, callback) {
15
- return activeEnvStorage.run({ env }, callback);
16
- }
17
- function getActiveCloudflareEnv() {
18
- const scoped = activeEnvStorage.getStore();
19
- return scoped ? scoped.env : activeEnv ?? globalThis.__env__;
20
- }
21
- function getCloudflareEnv(event) {
22
- const target = event;
23
- return target?.env || target?.context?.cloudflare?.env || target?.context?._platform?.cloudflare?.env || target?.req?.runtime?.cloudflare?.env || target?.node?.req?.runtime?.cloudflare?.env || getActiveCloudflareEnv();
24
- }
25
- function resolveWaitUntil(event) {
26
- const target = event;
27
- const owners = [
28
- target,
29
- target?.context,
30
- target?.context?.cloudflare,
31
- target?.context?.cloudflare?.context,
32
- target?.context?._platform?.cloudflare,
33
- target?.context?._platform?.cloudflare?.context,
34
- target?.req,
35
- target?.req?.runtime?.cloudflare,
36
- target?.req?.runtime?.cloudflare?.context,
37
- target?.node?.req,
38
- target?.node?.req?.runtime?.cloudflare,
39
- target?.node?.req?.runtime?.cloudflare?.context
40
- ];
41
- for (const owner of owners) if (typeof owner?.waitUntil === "function") return owner.waitUntil.bind(owner);
42
- }
43
- function createCloudflareRuntimeEvent(env, context) {
44
- const waitUntil = typeof context?.waitUntil === "function" ? context.waitUntil.bind(context) : void 0;
45
- return {
46
- context: {
47
- cloudflare: {
48
- env,
49
- context
50
- },
51
- waitUntil
52
- },
53
- env,
54
- waitUntil
55
- };
56
- }
57
- //#endregion
58
- export { setActiveCloudflareEnv as a, runWithActiveCloudflareEnv as i, getCloudflareEnv as n, resolveWaitUntil as r, createCloudflareRuntimeEvent as t };
@@ -1 +0,0 @@
1
- export { };
@@ -1,46 +0,0 @@
1
- import { t as normalizeWorkflowOptions } from "./config-BHknO_rT.js";
2
- import { i as runWithActiveCloudflareEnv, t as createCloudflareRuntimeEvent } from "./cloudflare-env-DjxQNbrx.js";
3
- import { runWithWorkflowRuntimeEvent, setWorkflowRuntimeConfig, setWorkflowRuntimeRegistry } from "./runtime/state.js";
4
- import { t as resolveAppFetch } from "./app-BZpq2cwC.js";
5
- //#region ../internal/src/runtime/cloudflare-hosted.ts
6
- function createWebRequestHandler(appHandler) {
7
- return async (request, context) => await Promise.resolve(appHandler ? appHandler(request, context) : new Response(JSON.stringify({
8
- status: 404,
9
- message: `Cannot find any route matching [${request.method}] ${request.url}`
10
- }), {
11
- headers: { "content-type": "application/json;charset=UTF-8" },
12
- status: 404,
13
- statusText: "Not Found"
14
- }));
15
- }
16
- function createCloudflareHostedWorker(adapter) {
17
- const requestHandler = createWebRequestHandler(resolveAppFetch(adapter.label, adapter.app));
18
- return { async fetch(request, env, context) {
19
- const handle = async (handlerContext) => await Promise.resolve(requestHandler(request, handlerContext));
20
- if (adapter.onRequest) return await adapter.onRequest({
21
- env,
22
- executionContext: context,
23
- handle
24
- });
25
- return await handle();
26
- } };
27
- }
28
- //#endregion
29
- //#region src/runtime/cloudflare-vite.ts
30
- function installWorkflowCloudflareRuntime(options = {}) {
31
- setWorkflowRuntimeConfig(options.workflow === false ? false : normalizeWorkflowOptions(options.workflow, { hosting: "cloudflare" }));
32
- setWorkflowRuntimeRegistry(options.registry);
33
- }
34
- function createWorkflowCloudflareWorker(options = {}) {
35
- return createCloudflareHostedWorker({
36
- app: options.app,
37
- label: "workflow",
38
- async onRequest({ env, executionContext, handle }) {
39
- installWorkflowCloudflareRuntime(options);
40
- const runtimeEvent = createCloudflareRuntimeEvent(env, executionContext);
41
- return await runWithActiveCloudflareEnv(env, () => runWithWorkflowRuntimeEvent(runtimeEvent, () => handle(runtimeEvent.context)));
42
- }
43
- });
44
- }
45
- //#endregion
46
- export { installWorkflowCloudflareRuntime as n, createWorkflowCloudflareWorker as t };
@@ -1,136 +0,0 @@
1
- import { defu } from "defu";
2
- //#region ../internal/src/hosting.ts
3
- function normalizeHosting(hosting) {
4
- const normalized = hosting?.trim().toLowerCase().replaceAll("_", "-") || "";
5
- if (normalized === "cloudflare") return "cloudflare-module";
6
- return normalized;
7
- }
8
- //#endregion
9
- //#region ../internal/src/object.ts
10
- function isPlainObject(value) {
11
- if (value === null || Object(value) !== value || Array.isArray(value)) return false;
12
- try {
13
- Function.prototype.toString.call(value);
14
- return false;
15
- } catch {
16
- return true;
17
- }
18
- }
19
- //#endregion
20
- //#region src/config.ts
21
- const knownProviders = new Set([
22
- "cloudflare",
23
- "openworkflow",
24
- "vercel"
25
- ]);
26
- function readString(value, label) {
27
- if (typeof value === "undefined") return;
28
- if (typeof value !== "string" || !value.trim()) throw new TypeError(`\`${label}\` must be a non-empty string when provided.`);
29
- return value.trim();
30
- }
31
- function readRuntimeConfigValue(value, label) {
32
- if (typeof value === "undefined") return;
33
- if (typeof value === "string") return readString(value, label);
34
- if (!isRuntimeEnvDeclaration(value)) throw new TypeError(`\`${label}\` must be a string or runtime env declaration.`);
35
- return value;
36
- }
37
- function readBoolean(value, label) {
38
- if (typeof value === "undefined") return;
39
- if (typeof value !== "boolean") throw new TypeError(`\`${label}\` must be a boolean when provided.`);
40
- return value;
41
- }
42
- function isRuntimeEnvDeclaration(value) {
43
- return isPlainObject(value) && value.kind === "env-variable" && (!("source" in value) || isRuntimeEnvSource(value.source));
44
- }
45
- function isRuntimeEnvSource(value) {
46
- return isPlainObject(value) && value.kind === "env" && typeof value.name === "string" && (!("names" in value) || Array.isArray(value.names) && value.names.every((name) => typeof name === "string"));
47
- }
48
- function readDatabaseName(value) {
49
- return readString(value, "workflow.database");
50
- }
51
- function readPositiveInteger(value, label) {
52
- if (typeof value === "undefined") return;
53
- if (!Number.isInteger(value) || value <= 0) throw new TypeError(`\`${label}\` must be a positive integer when provided.`);
54
- return value;
55
- }
56
- function normalizeOpenWorkflowPostgresOptions(value) {
57
- if (typeof value === "undefined") return;
58
- if (!isPlainObject(value)) throw new TypeError("`workflow.postgres` must be a plain object.");
59
- const namespaceId = readString(value.namespaceId, "workflow.postgres.namespaceId");
60
- const runMigrations = readBoolean(value.runMigrations, "workflow.postgres.runMigrations");
61
- const schema = readString(value.schema, "workflow.postgres.schema");
62
- const url = readRuntimeConfigValue(value.url, "workflow.postgres.url");
63
- return {
64
- ...namespaceId ? { namespaceId } : {},
65
- ...typeof runMigrations === "boolean" ? { runMigrations } : {},
66
- ...schema ? { schema } : {},
67
- ...url ? { url } : {}
68
- };
69
- }
70
- function normalizeOpenWorkflowSqliteOptions(value) {
71
- if (typeof value === "undefined") return;
72
- if (!isPlainObject(value)) throw new TypeError("`workflow.sqlite` must be a plain object.");
73
- const namespaceId = readString(value.namespaceId, "workflow.sqlite.namespaceId");
74
- const path = readRuntimeConfigValue(value.path, "workflow.sqlite.path");
75
- const runMigrations = readBoolean(value.runMigrations, "workflow.sqlite.runMigrations");
76
- return {
77
- ...namespaceId ? { namespaceId } : {},
78
- ...path ? { path } : {},
79
- ...typeof runMigrations === "boolean" ? { runMigrations } : {}
80
- };
81
- }
82
- function normalizeOpenWorkflowWorkerOptions(value) {
83
- if (typeof value === "undefined") return;
84
- if (!isPlainObject(value)) throw new TypeError("`workflow.worker` must be a plain object.");
85
- const concurrency = readPositiveInteger(value.concurrency, "workflow.worker.concurrency");
86
- return typeof concurrency === "number" ? { concurrency } : {};
87
- }
88
- function hasOpenWorkflowStorageConfig(options) {
89
- return typeof options.database === "string" && !!options.database.trim() || isPlainObject(options.postgres) && isDefinedRuntimeConfigValue(options.postgres.url) || isPlainObject(options.sqlite) && isDefinedRuntimeConfigValue(options.sqlite.path);
90
- }
91
- function isDefinedRuntimeConfigValue(value) {
92
- return typeof value === "string" && !!value.trim() || isRuntimeEnvDeclaration(value);
93
- }
94
- function inferProvider(provider, hosting) {
95
- if (provider === "cloudflare" || provider === "openworkflow" || provider === "vercel") return provider;
96
- if (hosting.includes("netlify")) throw new TypeError("`workflow.provider` cannot be inferred for Netlify hosting. Set `workflow.provider` explicitly or disable `workflow`.");
97
- if (hosting.includes("cloudflare")) return "cloudflare";
98
- return "vercel";
99
- }
100
- function inferProviderFromOptions(options, hosting) {
101
- if (typeof options.provider === "undefined" && (hosting.includes("node") || hosting.includes("docker")) && hasOpenWorkflowStorageConfig(options)) return "openworkflow";
102
- return inferProvider(options.provider, hosting);
103
- }
104
- function resolveProvider(options, hosting) {
105
- const shared = {
106
- ...typeof options.binding === "string" ? { binding: options.binding } : {},
107
- ...typeof options.name === "string" ? { name: options.name } : {}
108
- };
109
- const provider = options.provider;
110
- if (typeof provider === "string" && !knownProviders.has(provider)) throw new TypeError(`Unknown \`workflow.provider\`: ${JSON.stringify(provider)}. Expected "cloudflare", "openworkflow", or "vercel".`);
111
- const resolved = inferProviderFromOptions(options, hosting);
112
- if (resolved === "cloudflare") return defu(shared, { provider: "cloudflare" });
113
- if (resolved === "openworkflow") {
114
- const database = readDatabaseName(options.database);
115
- const postgres = normalizeOpenWorkflowPostgresOptions(options.postgres);
116
- const sqlite = normalizeOpenWorkflowSqliteOptions(options.sqlite);
117
- const worker = normalizeOpenWorkflowWorkerOptions(options.worker);
118
- if (database && postgres?.url) throw new TypeError("`workflow.database` and `workflow.postgres.url` cannot both configure OpenWorkflow storage.");
119
- if (database && sqlite?.path) throw new TypeError("`workflow.database` and `workflow.sqlite.path` cannot both configure OpenWorkflow storage.");
120
- if (postgres?.url && sqlite?.path) throw new TypeError("`workflow.postgres.url` and `workflow.sqlite.path` cannot both configure OpenWorkflow storage.");
121
- return defu({
122
- ...database ? { database } : {},
123
- ...postgres ? { postgres } : {},
124
- ...sqlite ? { sqlite } : {},
125
- ...worker ? { worker } : {}
126
- }, shared, { provider: "openworkflow" });
127
- }
128
- return defu(shared, { provider: "vercel" });
129
- }
130
- function normalizeWorkflowOptions(options, input = {}) {
131
- if (options === false) return void 0;
132
- if (typeof options !== "undefined" && !isPlainObject(options)) throw new TypeError("`workflow` must be a plain object.");
133
- return resolveProvider(options || {}, normalizeHosting(input.hosting));
134
- }
135
- //#endregion
136
- export { isPlainObject as n, normalizeHosting as r, normalizeWorkflowOptions as t };
@@ -1,65 +0,0 @@
1
- import { ViteHubError, getViteHubErrorShape } from "@vite-hub/runtime";
2
- //#region src/errors.ts
3
- const workflowErrorMessages = {
4
- OPENWORKFLOW_BACKEND_CLOSE_FAILED: "OpenWorkflow backend cleanup failed.",
5
- OPENWORKFLOW_RUNTIME_RESET: "OpenWorkflow runtime was reset while it was being acquired.",
6
- OPENWORKFLOW_WORKER_STOP_FAILED: "OpenWorkflow worker stop failed.",
7
- VERCEL_WORKFLOW_SDK_LOAD_FAILED: "Vercel Workflow DevKit load failed. Install the optional workflow peer dependency.",
8
- WORKFLOW_DEFINITION_NOT_FOUND: "Workflow definition was not found.",
9
- WORKFLOW_DISABLED: "Workflow is disabled.",
10
- WORKFLOW_NATIVE_ENTRY_INVALID: "Workflow has no transformed native Vercel entry.",
11
- WORKFLOW_NATIVE_ENTRY_REQUIRED: "Workflow has no native durable entry for Vercel.",
12
- WORKFLOW_OPERATION_UNSUPPORTED: "Workflow provider operation is unsupported.",
13
- WORKFLOW_PROVIDER_OPERATION_FAILED: "Workflow provider operation failed.",
14
- WORKFLOW_RUN_ID_UNSUPPORTED: "Native Vercel workflows assign their own run IDs."
15
- };
16
- function createWorkflowError(options) {
17
- return new ViteHubError(options.code, workflowErrorMessages[options.code], options);
18
- }
19
- //#endregion
20
- //#region src/runtime/provider-operation.ts
21
- function isWorkflowBoundaryError(error) {
22
- if (getViteHubErrorShape(error)) return true;
23
- if (typeof error !== "object" || error === null) return false;
24
- try {
25
- return "name" in error && error.name === "AbortError";
26
- } catch {
27
- return false;
28
- }
29
- }
30
- function getWorkflowProviderStatus(error) {
31
- if (typeof error !== "object" || error === null) return void 0;
32
- try {
33
- const value = error;
34
- const response = typeof value.response === "object" && value.response !== null ? value.response : void 0;
35
- const status = value.status ?? value.statusCode ?? response?.status;
36
- return typeof status === "number" && Number.isInteger(status) && status >= 400 && status <= 599 ? status : void 0;
37
- } catch {
38
- return;
39
- }
40
- }
41
- async function runWorkflowProviderOperation(provider, operation, run, options = {}) {
42
- try {
43
- return await run();
44
- } catch (error) {
45
- if (options.boundaryError?.(error) || isWorkflowBoundaryError(error)) throw error;
46
- const status = getWorkflowProviderStatus(error);
47
- const acknowledgement = options.acknowledgementUnknown?.(error, status) === true ? "unknown" : void 0;
48
- const details = {
49
- operation,
50
- provider
51
- };
52
- if (acknowledgement) details.acknowledgement = acknowledgement;
53
- if (status !== void 0) details.status = status;
54
- throw createWorkflowError({
55
- cause: error,
56
- code: "WORKFLOW_PROVIDER_OPERATION_FAILED",
57
- details
58
- });
59
- }
60
- }
61
- function safeWorkflowName(name) {
62
- return /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(name) ? name : void 0;
63
- }
64
- //#endregion
65
- export { createWorkflowError as a, safeWorkflowName as i, isWorkflowBoundaryError as n, runWorkflowProviderOperation as r, getWorkflowProviderStatus as t };
@@ -1,37 +0,0 @@
1
- //#region src/internal/runtime-type.ts
2
- function isCallableRepresentation(value) {
3
- if (value === null || value === void 0 || Object(value) !== value) return false;
4
- try {
5
- Function.prototype.toString.call(value);
6
- return true;
7
- } catch {
8
- return false;
9
- }
10
- }
11
- /** Parses JavaScript runtime representation categories at Workflow boundaries. */
12
- function hasRuntimeType(value, expected) {
13
- if (expected === "undefined") return value === void 0;
14
- if (expected === "object" && value === null) return true;
15
- if (value === null || value === void 0) return false;
16
- const isPrimitive = Object(value) !== value;
17
- if (!isPrimitive) {
18
- if (expected === "function") return isCallableRepresentation(value);
19
- return expected === "object" && !isCallableRepresentation(value);
20
- }
21
- const tag = Object.prototype.toString.call(value);
22
- switch (expected) {
23
- case "bigint": return isPrimitive && tag === "[object BigInt]";
24
- case "boolean": return isPrimitive && tag === "[object Boolean]";
25
- case "function": return false;
26
- case "number": return isPrimitive && tag === "[object Number]";
27
- case "object": return false;
28
- case "string": return isPrimitive && tag === "[object String]";
29
- case "symbol": return isPrimitive && tag === "[object Symbol]";
30
- }
31
- throw new TypeError(`Unsupported runtime type: ${expected}`);
32
- }
33
- function isRuntimeRecord(value) {
34
- return value !== null && hasRuntimeType(value, "object") && !Array.isArray(value);
35
- }
36
- //#endregion
37
- export { isRuntimeRecord as n, hasRuntimeType as t };
@@ -1,169 +0,0 @@
1
- //#region src/types.d.ts
2
- type WorkflowProvider = "cloudflare" | "openworkflow" | "vercel";
3
- interface CloudflareWorkflowBinding<TPayload = unknown> {
4
- createBatch: (batch: Array<{
5
- id: string;
6
- params?: TPayload;
7
- }>) => Promise<CloudflareWorkflowInstance[]>;
8
- get: (id: string) => Promise<CloudflareWorkflowInstance>;
9
- }
10
- interface CloudflareWorkflowInstance {
11
- id: string;
12
- status: () => Promise<unknown>;
13
- }
14
- interface WorkflowSharedOptions {
15
- binding?: string;
16
- name?: string;
17
- }
18
- interface CloudflareWorkflowProviderOptions extends WorkflowSharedOptions {
19
- provider: "cloudflare";
20
- }
21
- interface VercelWorkflowProviderOptions extends WorkflowSharedOptions {
22
- provider: "vercel";
23
- }
24
- interface OpenWorkflowPostgresOptions {
25
- namespaceId?: string;
26
- runMigrations?: boolean;
27
- schema?: string;
28
- url?: WorkflowRuntimeConfigValue;
29
- }
30
- interface WorkflowRuntimeEnvDeclarationLike {
31
- default?: unknown;
32
- kind: "env-variable";
33
- source?: {
34
- kind: "env";
35
- name: string;
36
- names?: string[];
37
- };
38
- }
39
- type WorkflowRuntimeConfigValue = string | WorkflowRuntimeEnvDeclarationLike;
40
- interface OpenWorkflowSqliteOptions {
41
- namespaceId?: string;
42
- path?: WorkflowRuntimeConfigValue;
43
- runMigrations?: boolean;
44
- }
45
- interface OpenWorkflowWorkerOptions {
46
- concurrency?: number;
47
- }
48
- interface OpenWorkflowProviderOptions extends WorkflowSharedOptions {
49
- database?: string;
50
- postgres?: OpenWorkflowPostgresOptions;
51
- provider: "openworkflow";
52
- sqlite?: OpenWorkflowSqliteOptions;
53
- worker?: OpenWorkflowWorkerOptions;
54
- }
55
- interface InferredWorkflowProviderOptions extends WorkflowSharedOptions {
56
- database?: string;
57
- postgres?: OpenWorkflowPostgresOptions;
58
- provider?: undefined;
59
- sqlite?: OpenWorkflowSqliteOptions;
60
- worker?: OpenWorkflowWorkerOptions;
61
- }
62
- type WorkflowProviderOptions = CloudflareWorkflowProviderOptions | OpenWorkflowProviderOptions | VercelWorkflowProviderOptions;
63
- type WorkflowModuleProviderOptions = InferredWorkflowProviderOptions | WorkflowProviderOptions;
64
- type WorkflowModuleOptions = false | WorkflowModuleProviderOptions;
65
- type ResolvedWorkflowOptions = WorkflowProviderOptions;
66
- interface WorkflowRun<TPayload = unknown, TResult = unknown> {
67
- completedAt?: Date;
68
- createdAt?: Date;
69
- id: string;
70
- provider: WorkflowProvider;
71
- result?: TResult;
72
- startedAt?: Date;
73
- status: WorkflowRunStatus;
74
- steps?: WorkflowRunStep[];
75
- metadata?: unknown;
76
- payload?: TPayload;
77
- }
78
- type WorkflowRunStatus = "queued" | "running" | "completed" | "failed" | "cancelled" | "unknown";
79
- interface WorkflowRunStep {
80
- attempt: number;
81
- completedAt?: Date;
82
- error?: {
83
- code?: string;
84
- message: string;
85
- };
86
- id: string;
87
- name: string;
88
- startedAt?: Date;
89
- status: WorkflowRunStatus;
90
- }
91
- interface WorkflowStepOptions {
92
- retries?: {
93
- backoff?: string;
94
- delay?: string;
95
- limit?: number;
96
- };
97
- }
98
- type WorkflowStepFunction<TInput = unknown, TResult = unknown> = (input: TInput) => TResult | Promise<TResult>;
99
- interface WorkflowProviderStep {
100
- do?: <TResult>(name: string, options: WorkflowStepOptions, run: () => TResult | Promise<TResult>) => Promise<TResult>;
101
- sleep?: (name: string, duration: string) => Promise<void>;
102
- }
103
- type WorkflowStepRunner<TSteps extends Record<string, WorkflowStepFunction> = Record<string, WorkflowStepFunction>> = { [TName in keyof TSteps]: TSteps[TName] };
104
- interface WorkflowExecutionContext<TPayload = unknown> {
105
- id?: string;
106
- name: string;
107
- payload: TPayload;
108
- provider: WorkflowProvider;
109
- step?: WorkflowProviderStep;
110
- steps?: WorkflowStepRunner;
111
- }
112
- type WorkflowHandler<TPayload = unknown, TResult = unknown> = (context: WorkflowExecutionContext<TPayload>) => TResult | Promise<TResult>;
113
- type WorkflowRunIdValue = boolean | null | number | string | undefined | {
114
- readonly [key: string]: WorkflowRunIdValue;
115
- } | readonly WorkflowRunIdValue[];
116
- interface WorkflowCreateOptions<TPayload = unknown, TResult = unknown> {
117
- handler?: WorkflowHandler<TPayload, TResult>;
118
- id?: (context: {
119
- name: string;
120
- payload?: TPayload;
121
- }) => Promise<WorkflowRunIdValue> | WorkflowRunIdValue;
122
- name?: string;
123
- rootStep?: boolean;
124
- }
125
- interface WorkflowDefinitionOptions<TPayload = unknown, TResult = unknown> {
126
- id?: string;
127
- native?: WorkflowHandler<TPayload, TResult>;
128
- rootStep?: boolean;
129
- }
130
- interface WorkflowDefinition<TPayload = unknown, TResult = unknown> {
131
- /** @internal Identifies provider-generated Agent invocation recovery definitions. */
132
- internalAgentInvocationRecovery?: true;
133
- handler: WorkflowHandler<TPayload, TResult>;
134
- options?: WorkflowDefinitionOptions<TPayload, TResult>;
135
- }
136
- interface WorkflowHandle<TPayload = unknown, TResult = unknown> {
137
- cancel: (id: string) => Promise<WorkflowRun<unknown, unknown>>;
138
- defer: (payload?: TPayload, options?: WorkflowStartOptions) => Promise<WorkflowRun<TPayload>>;
139
- getRun: (id: string) => Promise<WorkflowRun<unknown, unknown>>;
140
- name: string;
141
- run: (payload?: TPayload, options?: WorkflowStartOptions) => Promise<WorkflowRun<TPayload, TResult>>;
142
- }
143
- interface WorkflowStartOptions {
144
- id?: string;
145
- }
146
- interface WorkflowDeferOptions extends WorkflowStartOptions {
147
- deferred?: boolean;
148
- }
149
- interface WorkflowSignalResult {
150
- id: string;
151
- provider: WorkflowProvider;
152
- }
153
- interface WorkflowDefinitionRegistry {
154
- [name: string]: (() => Promise<{
155
- default?: WorkflowDefinition;
156
- [exportName: string]: unknown;
157
- } | WorkflowDefinition>) & {
158
- /** @internal Identifies provider-generated Agent invocation recovery definitions without evaluating their modules. */internalAgentInvocationRecovery?: true;
159
- };
160
- }
161
- interface DiscoveredWorkflowDefinition {
162
- agentIdentity?: string;
163
- handler: string;
164
- name: string;
165
- source?: "agent-workflow" | "agent-workflow-recovery" | "inline" | "server-workflows" | "vite-suffix";
166
- steps?: string[];
167
- }
168
- //#endregion
169
- export { WorkflowStepFunction as A, WorkflowProviderStep as C, WorkflowSharedOptions as D, WorkflowRunStep as E, WorkflowStepRunner as M, WorkflowSignalResult as O, WorkflowProviderOptions as S, WorkflowRunStatus 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, WorkflowStepOptions as j, WorkflowStartOptions 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, WorkflowRun as w, WorkflowProvider as x, WorkflowModuleOptions as y };