@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.
Files changed (66) hide show
  1. package/README.md +173 -55
  2. package/dist/{app-CzPoP84f.js → app-He0GTrYZ.js} +1 -1
  3. package/dist/client-DkwOxEiT.js +707 -0
  4. package/dist/{cloudflare-nF4abPd4.js → cloudflare-BHfClPvT.js} +2 -2
  5. package/dist/{cloudflare-env-BNrYo29x.js → cloudflare-env-CGLx7lUd.js} +44 -42
  6. package/dist/cloudflare-env-lookup-CfX6wZKb.d.ts +4 -0
  7. package/dist/{cloudflare-env-CIjdFTv6.d.ts → cloudflare-shared-CTqh_a2s.d.ts} +2 -2
  8. package/dist/{config-IJMb0eeZ.js → config-C3DvtjfJ.js} +41 -40
  9. package/dist/definition.d.ts +18 -0
  10. package/dist/definition.js +33 -0
  11. package/dist/delay-D1-nq_VE.js +46 -0
  12. package/dist/dev-recorder-CTN5Fkao.js +10 -0
  13. package/dist/durability.d.ts +23 -0
  14. package/dist/durability.js +62 -0
  15. package/dist/error-diagnostics-0V2T3JFw.js +317 -0
  16. package/dist/error-diagnostics-CQ4BUqRe.js +270 -0
  17. package/dist/errors-DCqRnZpN.js +35 -0
  18. package/dist/errors-uhP8DZTi.d.ts +67 -0
  19. package/dist/index.d.ts +35 -63
  20. package/dist/index.js +15 -19
  21. package/dist/object-Da1zyPCR.js +11 -0
  22. package/dist/openworkflow-BhzxV_Y3.d.ts +52 -0
  23. package/dist/openworkflow-defaults-DDig2M4s.js +26 -0
  24. package/dist/openworkflow-storage-Dj9zUAsk.js +28 -0
  25. package/dist/openworkflow.d.ts +2 -0
  26. package/dist/openworkflow.js +2 -0
  27. package/dist/{operations-tNUdj3G4.d.ts → operation-definition-nmRu_O3V.d.ts} +42 -15
  28. package/dist/operations-D_WJwjrS.js +333 -0
  29. package/dist/operations.d.ts +40 -6
  30. package/dist/operations.js +163 -736
  31. package/dist/{out-CsaJxg8m.js → out-DxLKolA0.js} +32 -1430
  32. package/dist/{rolldown-runtime-CMFfr-1z.js → rolldown-runtime-B4iAMlE-.js} +10 -1
  33. package/dist/run-error-DBWqiJHH.js +110 -0
  34. package/dist/run-failed-gVGo1BaF.js +18 -0
  35. package/dist/runtime/cloudflare-runner.d.ts +3 -5
  36. package/dist/runtime/cloudflare-runner.js +39 -45
  37. package/dist/runtime/cloudflare-shared.d.ts +2 -2
  38. package/dist/runtime/cloudflare-shared.js +1 -1
  39. package/dist/runtime/cloudflare-vite.d.ts +3 -2
  40. package/dist/runtime/cloudflare-vite.js +47 -1
  41. package/dist/runtime/dev-runs.d.ts +4 -0
  42. package/dist/runtime/dev-runs.js +73 -0
  43. package/dist/runtime/execute.d.ts +42 -5
  44. package/dist/runtime/execute.js +216 -17
  45. package/dist/runtime/openworkflow-worker.d.ts +29 -2
  46. package/dist/runtime/openworkflow-worker.js +156 -38
  47. package/dist/runtime/openworkflow.d.ts +2 -21
  48. package/dist/runtime/openworkflow.js +307 -44
  49. package/dist/runtime/state.d.ts +3 -1
  50. package/dist/runtime/state.js +6 -6
  51. package/dist/runtime/vercel-vite.d.ts +1 -1
  52. package/dist/runtime/vercel-vite.js +7 -4
  53. package/dist/types-Dsmwsdlv.d.ts +282 -0
  54. package/dist/{vercel-D-ZNtB_u.js → vercel-DTvm61iY.js} +53 -24
  55. package/dist/vite.d.ts +228 -30
  56. package/dist/vite.js +2640 -1449
  57. package/package.json +28 -50
  58. package/dist/client-DsGM3M4U.js +0 -389
  59. package/dist/cloudflare-shared-CaxrMD1A.d.ts +0 -1
  60. package/dist/cloudflare-vite-B3IabBsv.js +0 -47
  61. package/dist/error-diagnostics-A_8Kp-48.js +0 -116
  62. package/dist/error-diagnostics-pwNFvAHP.js +0 -67
  63. package/dist/operations-B_rYG71W.js +0 -230
  64. package/dist/provider-operation-CW2cYfVy.js +0 -65
  65. package/dist/runtime-type-DBCvIh5x.js +0 -7
  66. package/dist/types-D82WmfZa.d.ts +0 -180
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vite-hub/workflow",
3
- "version": "0.1.0",
3
+ "version": "0.4.1",
4
4
  "description": "Workflow primitives and Vite integration for ViteHub.",
5
5
  "keywords": [
6
6
  "background-jobs",
@@ -36,51 +36,26 @@
36
36
  "import": "./dist/index.js",
37
37
  "default": "./dist/index.js"
38
38
  },
39
- "./operations": {
40
- "types": "./dist/operations.d.ts",
41
- "import": "./dist/operations.js",
42
- "default": "./dist/operations.js"
43
- },
44
- "./runtime/cloudflare-runner": {
45
- "types": "./dist/runtime/cloudflare-runner.d.ts",
46
- "import": "./dist/runtime/cloudflare-runner.js",
47
- "default": "./dist/runtime/cloudflare-runner.js"
48
- },
49
- "./runtime/cloudflare-shared": {
50
- "types": "./dist/runtime/cloudflare-shared.d.ts",
51
- "import": "./dist/runtime/cloudflare-shared.js",
52
- "default": "./dist/runtime/cloudflare-shared.js"
53
- },
54
- "./runtime/cloudflare-vite": {
55
- "types": "./dist/runtime/cloudflare-vite.d.ts",
56
- "import": "./dist/runtime/cloudflare-vite.js",
57
- "default": "./dist/runtime/cloudflare-vite.js"
58
- },
59
- "./runtime/execute": {
60
- "types": "./dist/runtime/execute.d.ts",
61
- "import": "./dist/runtime/execute.js",
62
- "default": "./dist/runtime/execute.js"
39
+ "./durability": {
40
+ "types": "./dist/durability.d.ts",
41
+ "import": "./dist/durability.js",
42
+ "default": "./dist/durability.js"
63
43
  },
64
44
  "./runtime/openworkflow": {
65
45
  "types": "./dist/runtime/openworkflow.d.ts",
66
46
  "import": "./dist/runtime/openworkflow.js",
67
47
  "default": "./dist/runtime/openworkflow.js"
68
48
  },
69
- "./runtime/openworkflow-worker": {
70
- "types": "./dist/runtime/openworkflow-worker.d.ts",
71
- "import": "./dist/runtime/openworkflow-worker.js",
72
- "default": "./dist/runtime/openworkflow-worker.js"
49
+ "./openworkflow": {
50
+ "types": "./dist/openworkflow.d.ts",
51
+ "import": "./dist/openworkflow.js",
52
+ "default": "./dist/openworkflow.js"
73
53
  },
74
54
  "./runtime/state": {
75
55
  "types": "./dist/runtime/state.d.ts",
76
56
  "import": "./dist/runtime/state.js",
77
57
  "default": "./dist/runtime/state.js"
78
58
  },
79
- "./runtime/vercel-vite": {
80
- "types": "./dist/runtime/vercel-vite.d.ts",
81
- "import": "./dist/runtime/vercel-vite.js",
82
- "default": "./dist/runtime/vercel-vite.js"
83
- },
84
59
  "./vite": {
85
60
  "types": "./dist/vite.d.ts",
86
61
  "import": "./dist/vite.js",
@@ -89,40 +64,43 @@
89
64
  "./package.json": "./package.json"
90
65
  },
91
66
  "dependencies": {
92
- "@vercel/functions": "^3.9.11",
93
- "@vite-hub/runtime": "0.1.0",
67
+ "@valibot/to-json-schema": "^1.8.0",
68
+ "@vite-hub/runtime": "0.4.1",
94
69
  "defu": "^6.1.7",
95
70
  "esbuild": "^0.28.2",
96
- "h3": "2.0.1-rc.33",
97
- "nostics": "1.3.0",
71
+ "h3": "^2.0.8",
72
+ "nostics": "1.4.0",
73
+ "openworkflow": "^0.9.2",
98
74
  "pathe": "^2.0.3",
75
+ "postgres": "^3.4.9",
76
+ "semver": "^7.8.5",
99
77
  "valibot": "^1.5.0"
100
78
  },
101
79
  "devDependencies": {
102
80
  "@types/node": "^24.19.1",
103
- "openworkflow": "^0.9.2",
81
+ "@vercel/functions": "^3.9.11",
82
+ "@vite-hub/internal": "0.0.1",
104
83
  "publint": "^0.3.25",
105
84
  "typescript": "^6.0.3",
106
85
  "vite": "^8.2.2",
107
86
  "vite-plus": "^0.3.3",
108
- "vitest": "^4.1.11",
109
- "@vite-hub/internal": "0.0.1"
87
+ "vitest": "^4.1.11"
110
88
  },
111
89
  "peerDependencies": {
112
- "@vite-hub/database": "0.1.0",
113
- "@workflow/builders": "5.0.1",
114
- "openworkflow": "^0.9.2",
90
+ "@vercel/functions": "^3.9.11",
91
+ "@vite-hub/database": "0.4.1",
92
+ "@workflow/builders": "^5.0.6",
115
93
  "vite": ">=8.0.0",
116
- "workflow": "5.0.1"
94
+ "workflow": "^5.2.3"
117
95
  },
118
96
  "peerDependenciesMeta": {
119
- "@vite-hub/database": {
97
+ "@vercel/functions": {
120
98
  "optional": true
121
99
  },
122
- "@workflow/builders": {
100
+ "@vite-hub/database": {
123
101
  "optional": true
124
102
  },
125
- "openworkflow": {
103
+ "@workflow/builders": {
126
104
  "optional": true
127
105
  },
128
106
  "vite": {
@@ -133,12 +111,12 @@
133
111
  }
134
112
  },
135
113
  "engines": {
136
- "node": ">=24.0.0"
114
+ "node": ">=24.15.0"
137
115
  },
138
116
  "scripts": {
139
117
  "build": "vp pack",
140
118
  "dev": "vp pack --watch",
141
119
  "typecheck": "vp run --cache -t @vite-hub/workflow#build && node ../../test/package-typecheck.mjs --noEmit -p ./tsconfig.json",
142
- "test": "vp run -t @vite-hub/workflow#build && vp run -t @vite-hub/agent#build && vp test"
120
+ "test": "vp run --cache -t @vite-hub/workflow#build && vp run --cache -t @vite-hub/agent#build && vp test"
143
121
  }
144
122
  }
@@ -1,389 +0,0 @@
1
- import { t as normalizeWorkflowOptions } from "./config-IJMb0eeZ.js";
2
- import { t as workflowErrorDiagnostics } from "./error-diagnostics-pwNFvAHP.js";
3
- import { n as getCloudflareWorkflowBindingName, o as encodeNameHex } from "./cloudflare-nF4abPd4.js";
4
- import { t as hasRuntimeType } from "./runtime-type-DBCvIh5x.js";
5
- import { a as createWorkflowError, i as safeWorkflowName, r as runWorkflowProviderOperation } from "./provider-operation-CW2cYfVy.js";
6
- import { n as getCloudflareEnv, r as resolveWaitUntil } from "./cloudflare-env-BNrYo29x.js";
7
- import { runSerializedWorkflowHandler } from "./runtime/execute.js";
8
- import { getOpenWorkflowRun, runOpenWorkflow } from "./runtime/openworkflow.js";
9
- import { getWorkflowRunState, getWorkflowRuntimeConfig, getWorkflowRuntimeEvent, getWorkflowRuntimeRegistry, loadWorkflowDefinition, registerInlineWorkflowDefinition, runWithWorkflowRuntimeEvent, setWorkflowRun } from "./runtime/state.js";
10
- import { a as startVercelWorkflow, n as inspectVercelWorkflowRun, r as resumeVercelWorkflowSignal, t as cancelVercelWorkflow } from "./vercel-D-ZNtB_u.js";
11
- import { deserializeResponse, isSerializedResponse } from "@vite-hub/runtime";
12
- //#region src/integrations/vercel.ts
13
- function getVercelWorkflowName(name) {
14
- return `workflow--${encodeNameHex(name)}`;
15
- }
16
- //#endregion
17
- //#region ../internal/src/runtime/random.ts
18
- function randomId(prefix) {
19
- const body = `${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;
20
- return prefix ? `${prefix}_${body}` : body;
21
- }
22
- //#endregion
23
- //#region src/runtime/adapters.ts
24
- function resolveDispatchObserver(event) {
25
- if (!event || !hasRuntimeType(event, "object")) return void 0;
26
- const candidate = Object.hasOwn(event, "onDispatch") ? Reflect.get(event, "onDispatch") : void 0;
27
- return hasRuntimeType(candidate, "function") ? candidate : void 0;
28
- }
29
- function resolveSettlementObserver(event) {
30
- if (!event || !hasRuntimeType(event, "object")) return void 0;
31
- const candidate = Object.hasOwn(event, "settled") ? Reflect.get(event, "settled") : void 0;
32
- if (hasRuntimeType(candidate, "function")) return candidate;
33
- const context = Object.hasOwn(event, "context") ? Reflect.get(event, "context") : void 0;
34
- if (!context || !hasRuntimeType(context, "object")) return void 0;
35
- const contextObject = Object(context);
36
- const nested = Object.hasOwn(contextObject, "settled") ? Reflect.get(contextObject, "settled") : void 0;
37
- return hasRuntimeType(nested, "function") ? nested : void 0;
38
- }
39
- function unsupportedOperation(provider, operation) {
40
- throw createWorkflowError({
41
- code: "WORKFLOW_OPERATION_UNSUPPORTED",
42
- details: {
43
- operation,
44
- provider
45
- }
46
- });
47
- }
48
- function resolveCloudflareBinding(event, binding, name, definition) {
49
- const env = getCloudflareEnv(event);
50
- const bindingName = definition?.internalAgentInvocationRecovery ? getCloudflareWorkflowBindingName(name) : binding || getCloudflareWorkflowBindingName(name);
51
- return env && Object.hasOwn(env, bindingName) ? env[bindingName] : void 0;
52
- }
53
- function resolveCloudflareInspectionBinding(event, binding, name) {
54
- return resolveCloudflareBinding(event, binding, name, getWorkflowRuntimeRegistry()?.[name]);
55
- }
56
- function normalizeCloudflareWorkflowStart(value, expectedId) {
57
- if (!hasRuntimeType(value, "object") || value === null) throw new Error("Cloudflare Workflow provider returned an invalid workflow instance.");
58
- let id;
59
- try {
60
- id = Reflect.get(value, "id");
61
- } catch (cause) {
62
- throw new Error("Cloudflare Workflow provider returned an invalid workflow instance.", { cause });
63
- }
64
- if (!hasRuntimeType(id, "string") || !id || id !== expectedId) throw new Error("Cloudflare Workflow provider returned an invalid workflow instance.");
65
- return { id };
66
- }
67
- const cloudflareStatusMap = {
68
- cancelled: "cancelled",
69
- complete: "completed",
70
- completed: "completed",
71
- errored: "failed",
72
- failed: "failed",
73
- queued: "queued",
74
- running: "running",
75
- success: "completed",
76
- terminated: "failed"
77
- };
78
- function normalizeCloudflareStatus(status) {
79
- const value = hasRuntimeType(status, "object") && status && Object.hasOwn(status, "status") ? status.status : status;
80
- const normalized = String(value || "").toLowerCase();
81
- return Object.hasOwn(cloudflareStatusMap, normalized) ? cloudflareStatusMap[normalized] : "unknown";
82
- }
83
- function ownSerializedOutput(metadata) {
84
- if (!hasRuntimeType(metadata, "object") || metadata === null || !Object.hasOwn(metadata, "output")) return void 0;
85
- const output = metadata.output;
86
- return isSerializedResponse(output) ? output : void 0;
87
- }
88
- function hasUnknownWorkflowAcknowledgement(error) {
89
- if (!error || !hasRuntimeType(error, "object")) return false;
90
- const details = error.details;
91
- return Boolean(details && hasRuntimeType(details, "object") && details.acknowledgement === "unknown");
92
- }
93
- function createCloudflareAdapter(config) {
94
- return {
95
- cancel: () => unsupportedOperation("cloudflare", "cancellation"),
96
- async get({ event, id, name }) {
97
- const binding = resolveCloudflareInspectionBinding(event, config.binding, name);
98
- if (binding) {
99
- const instance = await runWorkflowProviderOperation("cloudflare", "get", () => binding.get(id));
100
- const metadata = await runWorkflowProviderOperation("cloudflare", "status", () => instance.status());
101
- const output = ownSerializedOutput(metadata);
102
- return {
103
- id,
104
- metadata,
105
- provider: "cloudflare",
106
- result: output ? deserializeResponse(output) : void 0,
107
- status: normalizeCloudflareStatus(metadata)
108
- };
109
- }
110
- return await inlineAdapter(config).get({
111
- event,
112
- id,
113
- name
114
- });
115
- },
116
- async run({ definition, event, id, name, options, payload }) {
117
- const binding = resolveCloudflareBinding(event, config.binding, name, definition);
118
- if (binding) {
119
- resolveDispatchObserver(event)?.();
120
- const start = () => runWorkflowProviderOperation("cloudflare", "create", async () => normalizeCloudflareWorkflowStart((await binding.createBatch([{
121
- id,
122
- params: payload
123
- }]))[0] || await binding.get(id), id), { acknowledgementUnknown: (_error, status) => status === void 0 });
124
- const creation = start().catch(async (firstError) => {
125
- try {
126
- return await start();
127
- } catch (retryError) {
128
- if (hasUnknownWorkflowAcknowledgement(firstError)) throw firstError;
129
- throw retryError;
130
- }
131
- });
132
- const waitUntil = options.deferred ? resolveWaitUntil(event) : void 0;
133
- if (waitUntil) waitUntil(creation);
134
- return {
135
- id: (await creation).id,
136
- payload,
137
- provider: "cloudflare",
138
- status: "queued"
139
- };
140
- }
141
- return await inlineAdapter(config).run({
142
- definition,
143
- event,
144
- id,
145
- name,
146
- options,
147
- payload
148
- });
149
- },
150
- resume: () => unsupportedOperation("cloudflare", "signals")
151
- };
152
- }
153
- function createOpenWorkflowAdapter(config) {
154
- return {
155
- cancel: () => unsupportedOperation("openworkflow", "cancellation"),
156
- get: async ({ id, name }) => await getOpenWorkflowRun(config, name, id),
157
- resume: () => unsupportedOperation("openworkflow", "signals"),
158
- run: async ({ definition, event, name, options, payload }) => await runOpenWorkflow(config, name, payload, definition, options, resolveDispatchObserver(event))
159
- };
160
- }
161
- function inlineAdapter(config) {
162
- return {
163
- cancel: () => unsupportedOperation(config.provider, "cancellation"),
164
- async get({ id, name }) {
165
- const run = getWorkflowRunState(name, id);
166
- if (run) {
167
- if (run.status === "running") return {
168
- id,
169
- provider: config.provider,
170
- status: "running"
171
- };
172
- return {
173
- id,
174
- metadata: run.error,
175
- provider: config.provider,
176
- result: isSerializedResponse(run.result) ? deserializeResponse(run.result) : run.result,
177
- status: run.status
178
- };
179
- }
180
- return {
181
- id,
182
- provider: config.provider,
183
- status: "unknown"
184
- };
185
- },
186
- async run({ definition, event, id, name, payload }) {
187
- const existing = getWorkflowRunState(name, id);
188
- if (existing) return {
189
- id,
190
- metadata: existing.error ?? (config.provider === "vercel" ? {
191
- mode: "inline",
192
- workflow: getVercelWorkflowName(name)
193
- } : void 0),
194
- payload: existing.payload,
195
- provider: config.provider,
196
- result: isSerializedResponse(existing.result) ? deserializeResponse(existing.result) : existing.result,
197
- status: existing.status === "running" ? "queued" : existing.status
198
- };
199
- resolveDispatchObserver(event)?.();
200
- const run = Promise.resolve().then(() => runSerializedWorkflowHandler({
201
- id,
202
- name,
203
- payload,
204
- provider: config.provider
205
- }, definition)).then((result) => ({
206
- result,
207
- status: "completed"
208
- })).catch((error) => ({
209
- error,
210
- status: "failed"
211
- }));
212
- const runState = setWorkflowRun(name, id, run, payload, true);
213
- const waitUntil = resolveWaitUntil(event);
214
- if (waitUntil) waitUntil(runState.promise);
215
- return {
216
- id,
217
- metadata: config.provider === "vercel" ? {
218
- mode: "inline",
219
- workflow: getVercelWorkflowName(name)
220
- } : void 0,
221
- payload,
222
- provider: config.provider,
223
- status: "queued"
224
- };
225
- },
226
- resume: () => unsupportedOperation(config.provider, "signals")
227
- };
228
- }
229
- function createVercelAdapter(config) {
230
- const fallback = inlineAdapter(config);
231
- return {
232
- async cancel({ id, name }) {
233
- const definition = await loadWorkflowDefinition(name);
234
- if (!definition?.options?.native) return await fallback.cancel({
235
- event: void 0,
236
- id,
237
- name
238
- });
239
- return await cancelVercelWorkflow(name, definition, id);
240
- },
241
- async get({ id, name }) {
242
- const definition = await loadWorkflowDefinition(name);
243
- return definition?.options?.native ? await inspectVercelWorkflowRun(name, definition, id) : await fallback.get({
244
- event: void 0,
245
- id,
246
- name
247
- });
248
- },
249
- resume: async (token, payload) => await resumeVercelWorkflowSignal(token, payload),
250
- async run({ definition, event, id, name, options, payload }) {
251
- if (!definition.options?.native) return await fallback.run({
252
- definition,
253
- event,
254
- id,
255
- name,
256
- options,
257
- payload
258
- });
259
- if (options.id) throw createWorkflowError({
260
- code: "WORKFLOW_RUN_ID_UNSUPPORTED",
261
- details: {
262
- ...safeWorkflowName(name) ? { name } : {},
263
- provider: "vercel"
264
- }
265
- });
266
- return await startVercelWorkflow(name, definition, payload, resolveSettlementObserver(event), resolveDispatchObserver(event));
267
- }
268
- };
269
- }
270
- function getWorkflowRuntimeAdapter(config) {
271
- if (config.provider === "cloudflare") return createCloudflareAdapter(config);
272
- if (config.provider === "openworkflow") return createOpenWorkflowAdapter(config);
273
- return createVercelAdapter(config);
274
- }
275
- //#endregion
276
- //#region src/runtime/client.ts
277
- function getActiveWorkflowConfig() {
278
- const config = getWorkflowRuntimeConfig();
279
- if (config === false) throw createWorkflowError({ code: "WORKFLOW_DISABLED" });
280
- return config || normalizeWorkflowOptions(void 0, { hosting: "vercel" });
281
- }
282
- async function loadRequiredWorkflowDefinition(name) {
283
- const definition = await loadWorkflowDefinition(name);
284
- if (!definition) throw createWorkflowError({
285
- code: "WORKFLOW_DEFINITION_NOT_FOUND",
286
- details: safeWorkflowName(name) ? { name } : void 0
287
- });
288
- return definition;
289
- }
290
- function normalizeWorkflowRunIdValue(value) {
291
- if (value === void 0) return null;
292
- if (value === null || !hasRuntimeType(value, "object")) return value;
293
- if (Array.isArray(value)) return value.map((item) => normalizeWorkflowRunIdValue(item));
294
- const record = value;
295
- return Object.fromEntries(Object.keys(record).filter((key) => record[key] !== void 0).sort().map((key) => [key, normalizeWorkflowRunIdValue(record[key])]));
296
- }
297
- async function sha256Hex(value) {
298
- const data = new TextEncoder().encode(value);
299
- const digest = await crypto.subtle.digest("SHA-256", data);
300
- return Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join("");
301
- }
302
- async function createStableWorkflowRunId(name, value) {
303
- const hash = await sha256Hex(`${name}:${JSON.stringify(normalizeWorkflowRunIdValue(value))}`);
304
- return `${name.replace(/[^a-zA-Z0-9_-]+/g, "-").replace(/^-+|-+$/g, "") || "workflow"}-${hash.slice(0, 32)}`;
305
- }
306
- async function resolveWorkflowStartOptions(name, payload, createOptions, startOptions) {
307
- if (startOptions.id || !createOptions?.id) return startOptions;
308
- return {
309
- ...startOptions,
310
- id: await createStableWorkflowRunId(name, await createOptions.id({
311
- name,
312
- payload
313
- }))
314
- };
315
- }
316
- function createWorkflow(nameOrOptions, handlerOrOptions, options) {
317
- let name;
318
- let handler;
319
- let createOptions;
320
- if (hasRuntimeType(nameOrOptions, "object") && nameOrOptions !== null) {
321
- createOptions = nameOrOptions;
322
- if (!createOptions.name || !hasRuntimeType(createOptions.name, "string")) throw workflowErrorDiagnostics.WORKFLOW_R0009({ message: "`createWorkflow()` requires a workflow name." });
323
- if (!hasRuntimeType(createOptions.handler, "function")) throw workflowErrorDiagnostics.WORKFLOW_R0010({ message: "`createWorkflow()` requires a workflow handler." });
324
- name = createOptions.name;
325
- handler = createOptions.handler;
326
- } else {
327
- name = nameOrOptions;
328
- if (!name || !hasRuntimeType(name, "string")) throw workflowErrorDiagnostics.WORKFLOW_R0011({ message: "`createWorkflow()` requires a workflow name." });
329
- handler = hasRuntimeType(handlerOrOptions, "function") ? handlerOrOptions : hasRuntimeType(handlerOrOptions, "object") && handlerOrOptions !== null ? handlerOrOptions.handler : void 0;
330
- createOptions = hasRuntimeType(handlerOrOptions, "function") ? options : handlerOrOptions;
331
- if (handler !== void 0 && !hasRuntimeType(handler, "function")) throw workflowErrorDiagnostics.WORKFLOW_R0012({ message: "`createWorkflow()` requires a workflow handler." });
332
- if (handler === void 0 && handlerOrOptions !== void 0 && (!hasRuntimeType(handlerOrOptions, "object") || handlerOrOptions === null)) throw workflowErrorDiagnostics.WORKFLOW_R0013({ message: "`createWorkflow()` options must be an object." });
333
- }
334
- if (handler !== void 0) registerInlineWorkflowDefinition(name, {
335
- handler,
336
- ...createOptions?.rootStep === void 0 ? {} : { options: { rootStep: createOptions.rootStep } }
337
- });
338
- return {
339
- cancel: (id) => cancelWorkflow(name, id),
340
- name,
341
- defer: async (payload, options = {}) => deferWorkflow(name, payload, await resolveWorkflowStartOptions(name, payload, createOptions, options)),
342
- getRun: (id) => getWorkflowRun(name, id),
343
- async run(payload, options = {}) {
344
- return await runWorkflow(name, payload, await resolveWorkflowStartOptions(name, payload, createOptions, options));
345
- }
346
- };
347
- }
348
- async function runWorkflow(name, payload, options = {}) {
349
- const config = getActiveWorkflowConfig();
350
- const id = options.id || randomId("wrun");
351
- const definition = await loadRequiredWorkflowDefinition(name);
352
- return await getWorkflowRuntimeAdapter(config).run({
353
- definition,
354
- event: getWorkflowRuntimeEvent(),
355
- id,
356
- name,
357
- options,
358
- payload
359
- });
360
- }
361
- async function getWorkflowRun(name, id) {
362
- return await getWorkflowRuntimeAdapter(getActiveWorkflowConfig()).get({
363
- event: getWorkflowRuntimeEvent(),
364
- id,
365
- name
366
- });
367
- }
368
- async function cancelWorkflow(name, id) {
369
- const config = getActiveWorkflowConfig();
370
- await loadRequiredWorkflowDefinition(name);
371
- return await getWorkflowRuntimeAdapter(config).cancel({
372
- event: getWorkflowRuntimeEvent(),
373
- id,
374
- name
375
- });
376
- }
377
- async function resumeWorkflowSignal(token, payload) {
378
- if (!token || !hasRuntimeType(token, "string")) throw workflowErrorDiagnostics.WORKFLOW_R0014({ message: "`resumeWorkflowSignal()` requires an opaque signal token." });
379
- return await getWorkflowRuntimeAdapter(getActiveWorkflowConfig()).resume(token, payload);
380
- }
381
- function deferWorkflow(name, payload, options = {}) {
382
- const request = getWorkflowRuntimeEvent();
383
- return runWithWorkflowRuntimeEvent(request, () => runWorkflow(name, payload, {
384
- ...options,
385
- deferred: true
386
- }));
387
- }
388
- //#endregion
389
- export { resumeWorkflowSignal as a, getWorkflowRun as i, createWorkflow as n, runWorkflow as o, deferWorkflow as r, getVercelWorkflowName as s, cancelWorkflow as t };
@@ -1 +0,0 @@
1
- export {}
@@ -1,47 +0,0 @@
1
- import { t as normalizeWorkflowOptions } from "./config-IJMb0eeZ.js";
2
- import { i as runWithActiveCloudflareEnv, t as createCloudflareRuntimeEvent } from "./cloudflare-env-BNrYo29x.js";
3
- import { runWithWorkflowRuntimeEvent, setWorkflowRuntimeConfig, setWorkflowRuntimeRegistry } from "./runtime/state.js";
4
- import { t as resolveAppFetch } from "./app-CzPoP84f.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
- const workflowConfig = options.workflow === false ? false : normalizeWorkflowOptions(options.workflow, { hosting: "cloudflare" });
32
- setWorkflowRuntimeConfig(workflowConfig);
33
- setWorkflowRuntimeRegistry(options.registry);
34
- }
35
- function createWorkflowCloudflareWorker(options = {}) {
36
- return createCloudflareHostedWorker({
37
- app: options.app,
38
- label: "workflow",
39
- async onRequest({ env, executionContext, handle }) {
40
- installWorkflowCloudflareRuntime(options);
41
- const runtimeEvent = createCloudflareRuntimeEvent(env, executionContext);
42
- return await runWithActiveCloudflareEnv(env, () => runWithWorkflowRuntimeEvent(runtimeEvent, () => handle(runtimeEvent.context)));
43
- }
44
- });
45
- }
46
- //#endregion
47
- export { installWorkflowCloudflareRuntime as n, createWorkflowCloudflareWorker as t };