@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
@@ -1,11 +1,18 @@
1
- import { t as hasRuntimeType } from "./runtime-type-DGUn8Ple.js";
2
- import { a as createWorkflowError, i as safeWorkflowName, n as isWorkflowBoundaryError, r as runWorkflowProviderOperation } from "./provider-operation-CW2cYfVy.js";
1
+ import { t as workflowErrorDiagnostics } from "./error-diagnostics-8YNJ37rP.js";
2
+ import { n as createWorkflowError } from "./errors-DCqRnZpN.js";
3
+ import { a as workflowStartAtKey } from "./delay--ESDybVT.js";
4
+ import { a as safeWorkflowName, i as runWorkflowProviderOperation, r as isWorkflowBoundaryError, t as toWorkflowRunError } from "./run-error-DBWqiJHH.js";
3
5
  //#region src/runtime/vercel.ts
4
6
  async function loadVercelWorkflowRuntime() {
5
7
  const importVercelWorkflow = new Function("specifier", "return import(specifier)");
6
8
  const [api, runtime] = await Promise.all([importVercelWorkflow("workflow/api"), importVercelWorkflow("workflow/runtime")]);
7
9
  return createVercelWorkflowRuntime(api, runtime);
8
10
  }
11
+ /**
12
+ * The largest step page that Vercel's step listing accepts. A larger page fails with HTTP 400. Workflow DevKit's own
13
+ * CLI uses the same bound (`packages/cli/src/lib/inspect/flag-bounds.ts` in vercel/workflow).
14
+ */
15
+ const vercelStepPageLimit = 100;
9
16
  function createVercelWorkflowRuntime(api, runtime) {
10
17
  const { getRun, resumeHook, start } = api;
11
18
  const { getWorld } = runtime;
@@ -13,19 +20,23 @@ function createVercelWorkflowRuntime(api, runtime) {
13
20
  getRun,
14
21
  async listSteps(id) {
15
22
  const steps = [];
23
+ const cursors = /* @__PURE__ */ new Set();
16
24
  let cursor;
17
25
  do {
18
- const page = await (await getWorld()).steps.list({
26
+ const page = normalizeStepPage(await (await getWorld()).steps.list({
19
27
  pagination: {
20
28
  cursor,
21
- limit: 1e3,
29
+ limit: vercelStepPageLimit,
22
30
  sortOrder: "asc"
23
31
  },
24
32
  resolveData: "none",
25
33
  runId: id
26
- });
34
+ }));
27
35
  steps.push(...page.data);
28
- cursor = page.hasMore && page.cursor ? page.cursor : void 0;
36
+ if (!page.hasMore) break;
37
+ if (typeof page.cursor !== "string" || !page.cursor || cursors.has(page.cursor)) throw invalidVercelResult("step pagination cursor");
38
+ cursors.add(page.cursor);
39
+ cursor = page.cursor;
29
40
  } while (cursor);
30
41
  return steps;
31
42
  },
@@ -57,34 +68,53 @@ const statusMap = {
57
68
  running: "running"
58
69
  };
59
70
  function invalidVercelResult(field) {
60
- return /* @__PURE__ */ new TypeError(`Vercel Workflow provider returned an invalid ${field}.`);
71
+ return workflowErrorDiagnostics.WORKFLOW_R0026({ message: `Vercel Workflow provider returned an invalid ${field}.` });
72
+ }
73
+ function normalizeStepPage(page) {
74
+ if (typeof page !== "object" || page === null || Array.isArray(page)) throw invalidVercelResult("step page");
75
+ const { cursor, data, hasMore } = page;
76
+ if (!Array.isArray(data)) throw invalidVercelResult("step page data");
77
+ if (typeof hasMore !== "boolean") throw invalidVercelResult("step page hasMore flag");
78
+ if (cursor !== void 0 && cursor !== null && typeof cursor !== "string") throw invalidVercelResult("step page cursor");
79
+ return {
80
+ ...cursor === void 0 || cursor === null ? {} : { cursor },
81
+ data,
82
+ hasMore
83
+ };
61
84
  }
62
85
  function normalizeStatus(status) {
63
- if (!hasRuntimeType(status, "string")) throw invalidVercelResult("status");
64
- return statusMap[status.toLowerCase()] || "unknown";
86
+ if (typeof status !== "string") throw invalidVercelResult("status");
87
+ const normalized = status.toLowerCase();
88
+ return Object.hasOwn(statusMap, normalized) ? statusMap[normalized] : "unknown";
65
89
  }
66
90
  function normalizeRunId(id) {
67
- if (!hasRuntimeType(id, "string") || !id) throw invalidVercelResult("run ID");
91
+ if (typeof id !== "string" || !id) throw invalidVercelResult("run ID");
68
92
  return id;
69
93
  }
70
94
  function normalizeDate(value, field) {
71
95
  if (value === void 0) return void 0;
72
- if (!(value instanceof Date) || !Number.isFinite(value.getTime())) throw invalidVercelResult(field);
73
- return value;
96
+ let timestamp;
97
+ try {
98
+ timestamp = Date.prototype.getTime.call(value);
99
+ } catch {
100
+ throw invalidVercelResult(field);
101
+ }
102
+ if (!Number.isFinite(timestamp)) throw invalidVercelResult(field);
103
+ return new Date(timestamp);
74
104
  }
75
105
  function normalizeStepError(error) {
76
106
  if (error === void 0 || error === null) return void 0;
77
107
  if (error instanceof Error) return { message: error.message };
78
- if (hasRuntimeType(error, "string")) try {
108
+ if (typeof error === "string") try {
79
109
  return normalizeStepError(JSON.parse(error)) || { message: error };
80
110
  } catch {
81
111
  return { message: error };
82
112
  }
83
- if (hasRuntimeType(error, "object") && error) {
113
+ if (typeof error === "object" && error) {
84
114
  const value = error;
85
- if (hasRuntimeType(value.message, "string")) {
115
+ if (typeof value.message === "string") {
86
116
  const normalized = { message: value.message };
87
- if (hasRuntimeType(value.code, "string")) normalized.code = value.code;
117
+ if (typeof value.code === "string") normalized.code = value.code;
88
118
  return normalized;
89
119
  }
90
120
  if (value.error !== void 0) return normalizeStepError(value.error);
@@ -94,11 +124,11 @@ function normalizeStepError(error) {
94
124
  function normalizeSteps(steps) {
95
125
  if (!Array.isArray(steps)) throw invalidVercelResult("step list");
96
126
  return steps.map((step) => {
97
- if (!hasRuntimeType(step, "object") || step === null) throw invalidVercelResult("step");
127
+ if (typeof step !== "object" || step === null) throw invalidVercelResult("step");
98
128
  const value = step;
99
- if (!hasRuntimeType(value.attempt, "number") || !Number.isFinite(value.attempt)) throw invalidVercelResult("step attempt");
100
- if (!hasRuntimeType(value.stepId, "string") || !value.stepId) throw invalidVercelResult("step ID");
101
- if (!hasRuntimeType(value.stepName, "string") || !value.stepName) throw invalidVercelResult("step name");
129
+ if (typeof value.attempt !== "number" || !Number.isFinite(value.attempt)) throw invalidVercelResult("step attempt");
130
+ if (typeof value.stepId !== "string" || !value.stepId) throw invalidVercelResult("step ID");
131
+ if (typeof value.stepName !== "string" || !value.stepName) throw invalidVercelResult("step name");
102
132
  return {
103
133
  attempt: value.attempt,
104
134
  completedAt: normalizeDate(value.completedAt, "step completion date"),
@@ -112,15 +142,28 @@ function normalizeSteps(steps) {
112
142
  }
113
143
  async function readRunIdentity(run) {
114
144
  const exists = await run.exists;
115
- if (!hasRuntimeType(exists, "boolean")) throw invalidVercelResult("existence state");
145
+ if (typeof exists !== "boolean") throw invalidVercelResult("existence state");
116
146
  if (!exists) return { exists };
117
147
  const workflowName = await run.workflowName;
118
- if (!hasRuntimeType(workflowName, "string")) throw invalidVercelResult("workflow name");
148
+ if (typeof workflowName !== "string") throw invalidVercelResult("workflow name");
119
149
  return {
120
150
  exists,
121
151
  workflowName
122
152
  };
123
153
  }
154
+ /**
155
+ * The error of a failed native run. Workflow DevKit rejects `returnValue` of a failed run with
156
+ * `WorkflowRunFailedError`, which keeps the thrown value in `cause`.
157
+ */
158
+ async function readVercelRunError(run) {
159
+ try {
160
+ await run.returnValue;
161
+ } catch (error) {
162
+ const cause = typeof error === "object" && error !== null && Reflect.get(error, "name") === "WorkflowRunFailedError" ? Reflect.get(error, "cause") : void 0;
163
+ return toWorkflowRunError(cause ?? error);
164
+ }
165
+ return toWorkflowRunError(void 0);
166
+ }
124
167
  function getNativeWorkflowName(name, definition) {
125
168
  const workflowName = (definition.options?.native)?.workflowId;
126
169
  if (!workflowName) throw createWorkflowError({
@@ -156,9 +199,11 @@ async function inspectVercelWorkflowRun(name, definition, id, payload) {
156
199
  };
157
200
  }), runWorkflowProviderOperation("vercel", "list-steps", async () => normalizeSteps(await runtime.listSteps(id)))]);
158
201
  const result = snapshot.status === "completed" ? await runWorkflowProviderOperation("vercel", "get-run", () => run.returnValue) : void 0;
202
+ const error = snapshot.status === "failed" ? await readVercelRunError(run) : void 0;
159
203
  return {
160
204
  completedAt: snapshot.completedAt,
161
205
  createdAt: snapshot.createdAt,
206
+ ...error ? { error } : {},
162
207
  id,
163
208
  metadata: { workflow: name },
164
209
  payload,
@@ -169,7 +214,7 @@ async function inspectVercelWorkflowRun(name, definition, id, payload) {
169
214
  steps
170
215
  };
171
216
  }
172
- async function startVercelWorkflow(name, definition, payload, observeSettlement) {
217
+ async function startVercelWorkflow(name, definition, payload, observeSettlement, onDispatch, startAt) {
173
218
  const native = definition.options?.native;
174
219
  if (!native) throw createWorkflowError({
175
220
  code: "WORKFLOW_NATIVE_ENTRY_REQUIRED",
@@ -178,12 +223,21 @@ async function startVercelWorkflow(name, definition, payload, observeSettlement)
178
223
  provider: "vercel"
179
224
  }
180
225
  });
226
+ if (startAt !== void 0 && Reflect.get(native, "~vitehubGenerated") !== true) throw createWorkflowError({
227
+ code: "WORKFLOW_OPERATION_UNSUPPORTED",
228
+ details: {
229
+ operation: "delay",
230
+ provider: "vercel"
231
+ }
232
+ });
181
233
  const context = {
182
234
  name,
183
235
  payload,
184
- provider: "vercel"
236
+ provider: "vercel",
237
+ ...startAt === void 0 ? {} : { [workflowStartAtKey]: startAt }
185
238
  };
186
239
  const runtime = await getVercelWorkflowRuntime();
240
+ onDispatch?.();
187
241
  const { id, run } = await runWorkflowProviderOperation("vercel", "start", async () => {
188
242
  const run = await runtime.start(native, [context]);
189
243
  return {