@brickkit/cli 0.11.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/dashboard-dist/CollapsiblePanel-CbUysOp5.js +2 -0
  2. package/dashboard-dist/CompositeRoot-D4sRkYq3.js +1 -0
  3. package/dashboard-dist/Geist-Variable.woff2 +0 -0
  4. package/dashboard-dist/GeistMono-Variable.woff2 +0 -0
  5. package/dashboard-dist/PopoverPopup-CiI2avT_.js +1 -0
  6. package/dashboard-dist/api-reference-B-bZRtNV.js +265 -0
  7. package/dashboard-dist/app.css +2 -2
  8. package/dashboard-dist/app.js +11 -11
  9. package/dashboard-dist/ccount-CcG1m-Yh.js +1 -0
  10. package/dashboard-dist/client-BJJtVSVr.js +1 -0
  11. package/dashboard-dist/core-Z7NJFk0K.js +1 -0
  12. package/dashboard-dist/docs-Dpfc0wJb.js +4 -0
  13. package/dashboard-dist/docs.css +1 -1
  14. package/dashboard-dist/kit.js +1 -1
  15. package/dashboard-dist/popover-BzejBolB.js +1 -0
  16. package/dist/app-entry2.js +2 -3
  17. package/dist/bin.d.ts +0 -2
  18. package/dist/bin.js +173 -12
  19. package/dist/bin.js.map +1 -1
  20. package/dist/client-contract-file2.js +1 -2
  21. package/dist/client-contract2.js +6 -4
  22. package/dist/client-contract2.js.map +1 -1
  23. package/dist/compiler.d.ts +1 -2
  24. package/dist/compiler.js +1 -1
  25. package/dist/compiler2.js +3 -4
  26. package/dist/config.js +5 -7
  27. package/dist/config.js.map +1 -1
  28. package/dist/dashboard-extension.d.ts +0 -2
  29. package/dist/dashboard.d.ts +4 -134
  30. package/dist/dev-reporter.d.ts +0 -2
  31. package/dist/dev-reporter.js +1 -2
  32. package/dist/dev-telemetry-store.js +9 -19
  33. package/dist/dev-telemetry-store.js.map +1 -1
  34. package/dist/dev-telemetry.js +3 -4
  35. package/dist/dev-telemetry.js.map +1 -1
  36. package/dist/dev-worker.js +1 -2
  37. package/dist/emit.d.ts +0 -2
  38. package/dist/index.d.ts +7 -17
  39. package/dist/index.js +3 -4
  40. package/dist/lint/oxlint.d.ts +0 -2
  41. package/dist/lint/oxlint.js +1 -2
  42. package/dist/plugin.d.ts +0 -6
  43. package/dist/plugin.js +2 -4
  44. package/dist/plugin.js.map +1 -1
  45. package/dist/presets.js +3 -7
  46. package/dist/presets.js.map +1 -1
  47. package/dist/runner.js +5 -9
  48. package/dist/runner.js.map +1 -1
  49. package/dist/vite.d.ts +0 -2
  50. package/dist/vite.js +5 -7
  51. package/dist/vite.js.map +1 -1
  52. package/dist/workflows.d.ts +0 -2
  53. package/dist/workflows2.js +2 -3
  54. package/inspector-dist/client/assets/api.rpc-BvRk9kiK.js +0 -0
  55. package/inspector-dist/client/assets/api.stream._streamId-BvRk9kiK.js +0 -0
  56. package/inspector-dist/client/assets/app-CCzpuUz_.css +2 -0
  57. package/inspector-dist/client/assets/dist-BK8w6xOr.js +3930 -0
  58. package/inspector-dist/client/assets/dist-CG2aVufI.js +197 -0
  59. package/inspector-dist/client/assets/entry.client-D9jbgmTR.js +9391 -0
  60. package/inspector-dist/client/assets/highlighted-body-B3W2YXNL-DYVdwGy2.js +34 -0
  61. package/inspector-dist/client/assets/home-CyjkvtII.js +2883 -0
  62. package/inspector-dist/client/assets/jsx-runtime-CPEah4WQ.js +7084 -0
  63. package/inspector-dist/client/assets/manifest-ba30b52d.js +1 -0
  64. package/inspector-dist/client/assets/mermaid-3ZIDBTTL-Dy6IVqPy.js +1 -0
  65. package/inspector-dist/client/assets/root-8BMab1lL.css +2 -0
  66. package/inspector-dist/client/assets/root-DX9wtogx.js +332 -0
  67. package/inspector-dist/client/assets/run-detail-C69EJGql.js +1549 -0
  68. package/inspector-dist/client/assets/tabs-B6B88IjT.js +75692 -0
  69. package/inspector-dist/client/assets/tabs-L5XKzOpP.css +1 -0
  70. package/inspector-dist/client/assets/world-config-context-C3BqXPIv.js +30 -0
  71. package/inspector-dist/client/assets/zstd-browser-decoder-ByUgcY9H.js +41 -0
  72. package/inspector-dist/server/assets/app-WoDoT62X.js +100155 -0
  73. package/inspector-dist/server/assets/chunk-RLXIAIE6-CbvDIAEa.js +42977 -0
  74. package/inspector-dist/server/assets/dist-BRxZSWUN.js +1140 -0
  75. package/inspector-dist/server/assets/dist-CQnQcIJg.js +199 -0
  76. package/inspector-dist/server/assets/dist-DqRd9pyS.js +1644 -0
  77. package/inspector-dist/server/assets/dist-qR-969AD.js +10327 -0
  78. package/inspector-dist/server/assets/encryption-_PuklZNX.js +888 -0
  79. package/inspector-dist/server/assets/event-metadata-BVakQJ_y.js +147 -0
  80. package/inspector-dist/server/assets/functions-CImcpqNl.js +1172 -0
  81. package/inspector-dist/server/assets/global-singleton-CPirHxFh.js +82 -0
  82. package/inspector-dist/server/assets/highlighted-body-B3W2YXNL-fPMB_t7F.js +36 -0
  83. package/inspector-dist/server/assets/mermaid-3ZIDBTTL-bADXySE3.js +3 -0
  84. package/inspector-dist/server/assets/parse-D9Vvgzt9.js +471 -0
  85. package/inspector-dist/server/assets/rolldown-runtime-CLg409Sh.js +44 -0
  86. package/inspector-dist/server/assets/serialization-format-DDtsVTU1.js +478 -0
  87. package/inspector-dist/server/assets/token-BW4GdQZh.js +62 -0
  88. package/inspector-dist/server/assets/token-D6FXdkJT.js +57 -0
  89. package/inspector-dist/server/assets/token-util-BoNmi-wE.js +457 -0
  90. package/inspector-dist/server/assets/wrapper-wiqsGXcE.js +3626 -0
  91. package/inspector-dist/server/assets/ws-transport-DV7oG4mL.js +29478 -0
  92. package/inspector-dist/server/assets/zstd-browser-decoder-Cswf0KO6.js +40 -0
  93. package/inspector-dist/server/index.js +2 -57
  94. package/package.json +29 -28
  95. package/vite-client.d.ts +1 -1
  96. package/dashboard-dist/CollapsiblePanel-BX79_W-b.js +0 -2
  97. package/dashboard-dist/CompositeRoot-xzybXjnx.js +0 -1
  98. package/dashboard-dist/PopoverPopup-CvlmC7EL.js +0 -1
  99. package/dashboard-dist/api-reference-BcAYVYwJ.js +0 -260
  100. package/dashboard-dist/core-BGO9JZ1r.js +0 -1
  101. package/dashboard-dist/docs-DHikPD2v.js +0 -4
  102. package/dashboard-dist/popover-DG498XHH.js +0 -1
  103. package/dist/bin.d.ts.map +0 -1
  104. package/dist/dashboard-extension.d.ts.map +0 -1
  105. package/dist/dev-reporter.d.ts.map +0 -1
  106. package/dist/emit.d.ts.map +0 -1
  107. package/dist/index.d.ts.map +0 -1
  108. package/dist/lint/oxlint.d.ts.map +0 -1
  109. package/dist/plugin.d.ts.map +0 -1
  110. package/dist/vite.d.ts.map +0 -1
  111. package/dist/workflows.d.ts.map +0 -1
  112. package/inspector-dist/client/assets/api.rpc-l0sNRNKZ.js +0 -1
  113. package/inspector-dist/client/assets/api.stream._streamId-l0sNRNKZ.js +0 -1
  114. package/inspector-dist/client/assets/app-CvoGgWcV.css +0 -1
  115. package/inspector-dist/client/assets/entry.client-BJ6G3n5t.js +0 -11697
  116. package/inspector-dist/client/assets/highlighted-body-B3W2YXNL-C-3wZnxf.js +0 -19
  117. package/inspector-dist/client/assets/home-CSKAS4P2.js +0 -4979
  118. package/inspector-dist/client/assets/index-DECCyMR0.js +0 -4482
  119. package/inspector-dist/client/assets/index-Dot7CgrA.js +0 -9837
  120. package/inspector-dist/client/assets/index-HqNj_XIX.js +0 -200
  121. package/inspector-dist/client/assets/manifest-139c9319.js +0 -1
  122. package/inspector-dist/client/assets/mermaid-3ZIDBTTL-DC0K8uTy.js +0 -58626
  123. package/inspector-dist/client/assets/mermaid-3ZIDBTTL-F88p7PFX.css +0 -1
  124. package/inspector-dist/client/assets/root-BMHd_XHz.css +0 -1
  125. package/inspector-dist/client/assets/root-cbi6iYwg.js +0 -305
  126. package/inspector-dist/client/assets/run-detail-CWoGxu_0.css +0 -1
  127. package/inspector-dist/client/assets/run-detail-Cc7tSGNq.js +0 -6237
  128. package/inspector-dist/client/assets/world-config-context-BAD1QCrR.js +0 -26
  129. package/inspector-dist/client/assets/zstd-browser-decoder-BQoRpP7L.js +0 -28
  130. package/inspector-dist/server/assets/app-DUP5RybL.js +0 -174880
  131. package/inspector-dist/server/assets/highlighted-body-B3W2YXNL-D2g4hL2-.js +0 -71
  132. package/inspector-dist/server/assets/index-BfLBLRRi.js +0 -204
  133. package/inspector-dist/server/assets/index-BzrGWk7J.js +0 -1164
  134. package/inspector-dist/server/assets/index-D71yP6AL.js +0 -191
  135. package/inspector-dist/server/assets/index-wGSWRns3.js +0 -1296
  136. package/inspector-dist/server/assets/mermaid-3ZIDBTTL-DsvuKoEV.js +0 -58
  137. package/inspector-dist/server/assets/token-ClUZZwXl.js +0 -95
  138. package/inspector-dist/server/assets/token-util-DSxMZ6nI.js +0 -33
  139. package/inspector-dist/server/assets/wrapper-B3vstpCO.js +0 -67
  140. package/inspector-dist/server/assets/zstd-browser-decoder-Dn82m2BU.js +0 -77
@@ -0,0 +1,1140 @@
1
+ import { createRequire as __wkfCreateRequire } from "node:module";
2
+ if (typeof require === "undefined") globalThis.require = __wkfCreateRequire(import.meta.url);
3
+ import { o as __toESM, t as __commonJSMin } from "./rolldown-runtime-CLg409Sh.js";
4
+ // ../../node_modules/.bun/ms@2.1.3/node_modules/ms/index.js
5
+ var require_ms = /* @__PURE__ */ __commonJSMin(((exports, module) => {
6
+ /**
7
+ * Helpers.
8
+ */
9
+ var s = 1e3;
10
+ var m = s * 60;
11
+ var h = m * 60;
12
+ var d = h * 24;
13
+ var w = d * 7;
14
+ var y = d * 365.25;
15
+ /**
16
+ * Parse or format the given `val`.
17
+ *
18
+ * Options:
19
+ *
20
+ * - `long` verbose formatting [false]
21
+ *
22
+ * @param {String|Number} val
23
+ * @param {Object} [options]
24
+ * @throws {Error} throw an error if val is not a non-empty string or a number
25
+ * @return {String|Number}
26
+ * @api public
27
+ */
28
+ module.exports = function(val, options) {
29
+ options = options || {};
30
+ var type = typeof val;
31
+ if (type === "string" && val.length > 0) return parse(val);
32
+ else if (type === "number" && isFinite(val)) return options.long ? fmtLong(val) : fmtShort(val);
33
+ throw new Error("val is not a non-empty string or a valid number. val=" + JSON.stringify(val));
34
+ };
35
+ /**
36
+ * Parse the given `str` and return milliseconds.
37
+ *
38
+ * @param {String} str
39
+ * @return {Number}
40
+ * @api private
41
+ */
42
+ function parse(str) {
43
+ str = String(str);
44
+ if (str.length > 100) return;
45
+ var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(str);
46
+ if (!match) return;
47
+ var n = parseFloat(match[1]);
48
+ switch ((match[2] || "ms").toLowerCase()) {
49
+ case "years":
50
+ case "year":
51
+ case "yrs":
52
+ case "yr":
53
+ case "y": return n * y;
54
+ case "weeks":
55
+ case "week":
56
+ case "w": return n * w;
57
+ case "days":
58
+ case "day":
59
+ case "d": return n * d;
60
+ case "hours":
61
+ case "hour":
62
+ case "hrs":
63
+ case "hr":
64
+ case "h": return n * h;
65
+ case "minutes":
66
+ case "minute":
67
+ case "mins":
68
+ case "min":
69
+ case "m": return n * m;
70
+ case "seconds":
71
+ case "second":
72
+ case "secs":
73
+ case "sec":
74
+ case "s": return n * s;
75
+ case "milliseconds":
76
+ case "millisecond":
77
+ case "msecs":
78
+ case "msec":
79
+ case "ms": return n;
80
+ default: return;
81
+ }
82
+ }
83
+ /**
84
+ * Short format for `ms`.
85
+ *
86
+ * @param {Number} ms
87
+ * @return {String}
88
+ * @api private
89
+ */
90
+ function fmtShort(ms) {
91
+ var msAbs = Math.abs(ms);
92
+ if (msAbs >= d) return Math.round(ms / d) + "d";
93
+ if (msAbs >= h) return Math.round(ms / h) + "h";
94
+ if (msAbs >= m) return Math.round(ms / m) + "m";
95
+ if (msAbs >= s) return Math.round(ms / s) + "s";
96
+ return ms + "ms";
97
+ }
98
+ /**
99
+ * Long format for `ms`.
100
+ *
101
+ * @param {Number} ms
102
+ * @return {String}
103
+ * @api private
104
+ */
105
+ function fmtLong(ms) {
106
+ var msAbs = Math.abs(ms);
107
+ if (msAbs >= d) return plural(ms, msAbs, d, "day");
108
+ if (msAbs >= h) return plural(ms, msAbs, h, "hour");
109
+ if (msAbs >= m) return plural(ms, msAbs, m, "minute");
110
+ if (msAbs >= s) return plural(ms, msAbs, s, "second");
111
+ return ms + " ms";
112
+ }
113
+ /**
114
+ * Pluralization helper.
115
+ */
116
+ function plural(ms, msAbs, n, name) {
117
+ var isPlural = msAbs >= n * 1.5;
118
+ return Math.round(ms / n) + " " + name + (isPlural ? "s" : "");
119
+ }
120
+ }));
121
+ // ../../node_modules/.bun/@workflow+utils@5.0.2/node_modules/@workflow/utils/dist/time.js
122
+ var import_ms = /* @__PURE__ */ __toESM(require_ms(), 1);
123
+ /**
124
+ * Parses a duration parameter (string, number, or Date) and returns a Date object
125
+ * representing when the duration should elapse.
126
+ *
127
+ * - For strings: Parses duration strings like "1s", "5m", "1h", etc. using the `ms` library
128
+ * - For numbers: Treats as milliseconds from now
129
+ * - For Date objects: Returns the date directly (handles both Date instances and date-like objects from deserialization)
130
+ *
131
+ * @param param - The duration parameter (StringValue, Date, or number of milliseconds)
132
+ * @returns A Date object representing when the duration should elapse
133
+ * @throws {Error} If the parameter is invalid or cannot be parsed, or the
134
+ * resulting time is not a valid date (an Invalid Date, or a duration that
135
+ * lands past the largest time a Date can hold)
136
+ */
137
+ function parseDurationToDate(param) {
138
+ const date = durationToDate(param);
139
+ if (Number.isNaN(date.getTime())) throw new Error(typeof param === "object" ? "Invalid date: the Date object does not hold a valid time." : `Invalid duration: ${JSON.stringify(param)} ends past the latest time a Date can represent.`);
140
+ return date;
141
+ }
142
+ function durationToDate(param) {
143
+ if (typeof param === "string") {
144
+ const durationMs = (0, import_ms.default)(param);
145
+ if (typeof durationMs !== "number" || durationMs < 0) throw new Error(`Invalid duration: "${param}". Expected a valid duration string like "1s", "1m", "1h", etc.`);
146
+ return new Date(Date.now() + durationMs);
147
+ } else if (typeof param === "number") {
148
+ if (param < 0 || !Number.isFinite(param)) throw new Error(`Invalid duration: ${param}. Expected a non-negative finite number of milliseconds.`);
149
+ return new Date(Date.now() + param);
150
+ } else if (param instanceof Date || param && typeof param === "object" && typeof param.getTime === "function") return param instanceof Date ? param : new Date(param.getTime());
151
+ else throw new Error(`Invalid duration parameter. Expected a duration string, number (milliseconds), or Date object.`);
152
+ }
153
+ // ../../node_modules/.bun/@workflow+errors@5.1.0/node_modules/@workflow/errors/dist/error-codes.js
154
+ /**
155
+ * Error codes for classifying run failures.
156
+ * These are populated in the `errorCode` field of `run_failed` events
157
+ * and flow through to `StructuredError.code` on the run entity.
158
+ */
159
+ var RUN_ERROR_CODES = {
160
+ /** Error thrown in user workflow or step code */
161
+ USER_ERROR: "USER_ERROR",
162
+ /** Internal runtime error (missing timestamps, runtime invariant failures) */
163
+ RUNTIME_ERROR: "RUNTIME_ERROR",
164
+ /** Event log contains orphaned or mismatched events and cannot be replayed */
165
+ CORRUPTED_EVENT_LOG: "CORRUPTED_EVENT_LOG",
166
+ /** One replay could not consume the event log deterministically; retryable */
167
+ REPLAY_DIVERGENCE: "REPLAY_DIVERGENCE",
168
+ /** Run exceeded the maximum number of queue deliveries */
169
+ MAX_DELIVERIES_EXCEEDED: "MAX_DELIVERIES_EXCEEDED",
170
+ /** Run exceeded the maximum number of events per run */
171
+ MAX_EVENTS_EXCEEDED: "MAX_EVENTS_EXCEEDED",
172
+ /** Workflow replay exceeded the maximum allowed duration */
173
+ REPLAY_TIMEOUT: "REPLAY_TIMEOUT",
174
+ /** Workflow stream infrastructure failed while reading or writing data */
175
+ STREAM_ERROR: "STREAM_ERROR",
176
+ /** World response violated the SDK contract and cannot be retried safely */
177
+ WORLD_CONTRACT_ERROR: "WORLD_CONTRACT_ERROR",
178
+ /** Run was delivered to a deployment other than the one it is pinned to */
179
+ DEPLOYMENT_MISMATCH: "DEPLOYMENT_MISMATCH"
180
+ };
181
+ // ../../node_modules/.bun/@workflow+errors@5.1.0/node_modules/@workflow/errors/dist/index.js
182
+ var BASE_URL = "https://workflow-sdk.dev/err";
183
+ /**
184
+ * @internal
185
+ * Check if a value is an Error without relying on Node.js utilities.
186
+ * This is needed for error classes that can be used in VM contexts where
187
+ * Node.js imports are not available.
188
+ */
189
+ function isError(value) {
190
+ return typeof value === "object" && value !== null && "name" in value && "message" in value;
191
+ }
192
+ /**
193
+ * @internal
194
+ * Compose a framed-detail body for an error message, using the same `╰▶` /
195
+ * `├▶` box-drawing structure used by `ContextViolationError` (in
196
+ * `@workflow/core`), so every error class with a hint or docs slug
197
+ * renders consistently:
198
+ *
199
+ * <title>
200
+ * ├▶ hint: <hint>
201
+ * ╰▶ docs: https://workflow-sdk.dev/err/<slug>
202
+ *
203
+ * Plain text only, no ANSI here, since `@workflow/errors`'s main entry
204
+ * stays chalk-free. The runtime logger renders the same chars with
205
+ * dim styling at log time.
206
+ *
207
+ * Returns only `title` when there are no details to frame. Multi-line
208
+ * detail values are indented under their branch so the tree stays
209
+ * readable.
210
+ */
211
+ function appendFramedDetails(title, details) {
212
+ if (details.length === 0) return title;
213
+ const lines = [title];
214
+ details.forEach((detail, index) => {
215
+ const isLast = index === details.length - 1;
216
+ const head = isLast ? "╰▶ " : "├▶ ";
217
+ const cont = isLast ? " " : "│ ";
218
+ `${detail.label}: ${detail.value}`.split("\n").forEach((line, i) => {
219
+ lines.push(`${i === 0 ? head : cont}${line}`);
220
+ });
221
+ });
222
+ return lines.join("\n");
223
+ }
224
+ function buildFramedDetails(hint, slug) {
225
+ const out = [];
226
+ if (hint) out.push({
227
+ label: "hint",
228
+ value: hint
229
+ });
230
+ if (slug) out.push({
231
+ label: "docs",
232
+ value: `${BASE_URL}/${slug}`
233
+ });
234
+ return out;
235
+ }
236
+ /**
237
+ * @internal
238
+ * All the slugs of the errors used for documentation links.
239
+ */
240
+ var ERROR_SLUGS = {
241
+ NODE_JS_MODULE_IN_WORKFLOW: "node-js-module-in-workflow",
242
+ START_INVALID_WORKFLOW_FUNCTION: "start-invalid-workflow-function",
243
+ SERIALIZATION_FAILED: "serialization-failed",
244
+ WEBHOOK_INVALID_RESPOND_WITH_VALUE: "webhook-invalid-respond-with-value",
245
+ WEBHOOK_RESPONSE_NOT_SENT: "webhook-response-not-sent",
246
+ FETCH_IN_WORKFLOW_FUNCTION: "fetch-in-workflow",
247
+ TIMEOUT_FUNCTIONS_IN_WORKFLOW: "timeout-in-workflow",
248
+ HOOK_CONFLICT: "hook-conflict",
249
+ HOOK_FORCE_CLAIMED: "hook-force-claimed",
250
+ CORRUPTED_EVENT_LOG: "corrupted-event-log",
251
+ REPLAY_DIVERGENCE: "replay-divergence",
252
+ STEP_NOT_REGISTERED: "step-not-registered",
253
+ WORKFLOW_NOT_REGISTERED: "workflow-not-registered",
254
+ RUNTIME_DECRYPTION_FAILED: "runtime-decryption-failed",
255
+ DEPLOYMENT_MISMATCH: "deployment-mismatch",
256
+ MAX_EVENTS_EXCEEDED: "max-events-exceeded",
257
+ REPLAY_TIMEOUT: "replay-timeout"
258
+ };
259
+ /**
260
+ * The base class for all Workflow-related errors.
261
+ *
262
+ * This error is thrown by the Workflow SDK when internal operations fail.
263
+ * You can use this class with `instanceof` to catch any Workflow SDK error.
264
+ *
265
+ * @example
266
+ * ```ts
267
+ * try {
268
+ * await getRun(runId);
269
+ * } catch (error) {
270
+ * if (error instanceof WorkflowError) {
271
+ * console.error('Workflow SDK error:', error.message);
272
+ * }
273
+ * }
274
+ * ```
275
+ */
276
+ var WorkflowError = class extends Error {
277
+ cause;
278
+ constructor(message, options) {
279
+ const msgDocs = appendFramedDetails(message, buildFramedDetails(void 0, options?.slug));
280
+ super(msgDocs, { cause: options?.cause });
281
+ if (options?.cause !== void 0) this.cause = options.cause;
282
+ if (options?.cause instanceof Error) this.stack = `${this.stack}\nCaused by: ${options.cause.stack}`;
283
+ }
284
+ static is(value) {
285
+ return isError(value) && value.name === "WorkflowError";
286
+ }
287
+ };
288
+ /**
289
+ * Thrown when a world (storage backend) operation fails unexpectedly.
290
+ *
291
+ * This is the catch-all error for world implementations. Specific,
292
+ * well-known failure modes have dedicated error types (e.g.
293
+ * EntityConflictError, RunExpiredError, ThrottleError). This error
294
+ * covers everything else: validation failures, missing entities
295
+ * without a dedicated type, or unexpected HTTP errors from world-vercel.
296
+ */
297
+ var WorkflowWorldError = class extends WorkflowError {
298
+ status;
299
+ code;
300
+ url;
301
+ /** Retry-After value in seconds, present on 429 and 425 responses */
302
+ retryAfter;
303
+ /**
304
+ * The offending argument, present on client-side validation failures
305
+ * (`code: 'INVALID_ARGUMENT'`). Lets a caller correct the specific
306
+ * parameter without parsing the message.
307
+ */
308
+ field;
309
+ /**
310
+ * Why the World gave `code`, when it says. For
311
+ * `START_HOOK_ADMISSION_REJECTED`: `invalid`, `expired`, `token_mismatch`,
312
+ * `ordinary_run` or `disabled`; for `START_HOOK_ADMISSION_DISABLED`:
313
+ * `disabled`.
314
+ */
315
+ reason;
316
+ constructor(message, options) {
317
+ super(message, { cause: options?.cause });
318
+ this.name = "WorkflowWorldError";
319
+ this.status = options?.status;
320
+ this.code = options?.code;
321
+ this.url = options?.url;
322
+ this.retryAfter = options?.retryAfter;
323
+ this.field = options?.field;
324
+ this.reason = options?.reason;
325
+ }
326
+ static is(value) {
327
+ return isError(value) && value.name === "WorkflowWorldError";
328
+ }
329
+ };
330
+ /**
331
+ * `WorkflowWorldError.code` for a `start({ hook })` request the World will
332
+ * never admit: an invalid start Hook, a retention beyond the World's limit, a
333
+ * candidate too old to be created, or a candidate refused while admission was
334
+ * switched off and recorded as refused. Permanent, so the queued copy of the
335
+ * candidate stops retrying on it.
336
+ */
337
+ var START_HOOK_ADMISSION_REJECTED = "START_HOOK_ADMISSION_REJECTED";
338
+ /**
339
+ * `WorkflowWorldError.code` for a `start({ hook })` request answered while
340
+ * admission is switched off on the backend, with no decision recorded for the
341
+ * candidate. Not final: once admission is back on, another copy of the same
342
+ * candidate can still be admitted. `start()` reports it as
343
+ * `WorkflowStartError`, and the candidate's queued copy is redelivered rather
344
+ * than acknowledged.
345
+ */
346
+ var START_HOOK_ADMISSION_DISABLED = "START_HOOK_ADMISSION_DISABLED";
347
+ /**
348
+ * `WorkflowWorldError.code` for a `run_cancelled` that reached a
349
+ * `start({ hook })` candidate the World admitted but never created a run for.
350
+ * The World fenced it, so no copy can create it any more, and released its
351
+ * token as for an ended run. `cancel()` treats it as cancelled.
352
+ */
353
+ var START_HOOK_CANDIDATE_CANCELLED = "START_HOOK_CANDIDATE_CANCELLED";
354
+ /**
355
+ * Thrown when `start()` with a `hook` cannot confirm whether its candidate run
356
+ * was queued (`stage: 'queue'`) or admitted (`stage: 'admission'`). The outcome
357
+ * is unknown, not failed: the candidate may still become the run that owns the
358
+ * token. `runId` identifies the candidate for inspection.
359
+ *
360
+ * Safe to retry while the token is held: if the first candidate was admitted
361
+ * and still holds the token, the retry throws `HookConflictError` naming it;
362
+ * if it was not admitted, the retry's candidate becomes the owner. The token
363
+ * is held until the owner ends, then for any `experimental_minRetention`,
364
+ * unless the owner disposes its start Hook first, which releases it at once
365
+ * (see "Take care with the start Hook's lifecycle" in the `start()` docs). A
366
+ * retry after the token is released is admitted as a new run, so set a
367
+ * retention that covers the retry window, and keep the start Hook open, when
368
+ * a repeat must never run. Inside a workflow, the
369
+ * `start()` step retries it like any other transient failure.
370
+ *
371
+ * Use the static `WorkflowStartError.is()` method for type-safe checking in
372
+ * catch blocks.
373
+ */
374
+ var WorkflowStartError = class extends WorkflowError {
375
+ /** The candidate run's ID. */
376
+ runId;
377
+ /** The step whose outcome could not be confirmed. */
378
+ stage;
379
+ constructor(runId, stage, cause) {
380
+ const causeMessage = isError(cause) ? cause.message : cause === void 0 ? "unknown error" : String(cause);
381
+ super(`Could not confirm whether workflow run "${runId}" was ${stage === "queue" ? "queued" : "admitted"}: ${causeMessage}. Retrying with the same hook token is safe while the token is held: it never admits a second run while the first one holds it.`, { cause });
382
+ this.name = "WorkflowStartError";
383
+ this.runId = runId;
384
+ this.stage = stage;
385
+ }
386
+ static is(value) {
387
+ return isError(value) && value.name === "WorkflowStartError";
388
+ }
389
+ };
390
+ /**
391
+ * Thrown when a workflow run fails during execution.
392
+ *
393
+ * This error indicates that the workflow encountered a fatal error and cannot
394
+ * continue. It is thrown when awaiting `run.returnValue` on a run whose status
395
+ * is `'failed'`. The `cause` property contains the underlying error with its
396
+ * message, stack trace, and optional error code.
397
+ *
398
+ * Use the static `WorkflowRunFailedError.is()` method for type-safe checking
399
+ * in catch blocks.
400
+ *
401
+ * @example
402
+ * ```ts
403
+ * import { WorkflowRunFailedError } from "workflow/internal/errors";
404
+ *
405
+ * try {
406
+ * const result = await run.returnValue;
407
+ * } catch (error) {
408
+ * if (WorkflowRunFailedError.is(error)) {
409
+ * console.error(`Run ${error.runId} failed:`, error.cause.message);
410
+ * }
411
+ * }
412
+ * ```
413
+ */
414
+ var WorkflowRunFailedError = class extends WorkflowError {
415
+ /**
416
+ * `failed` is terminal, and a run's terminal state is immutable. This error
417
+ * is only ever thrown after a *successful* read of such a run, so re-running
418
+ * the read returns the same record and throws the same error. Marking it
419
+ * non-retryable is what stops the step executor from spending a retry budget
420
+ * on that when the read happens inside a step — a parent awaiting a child's
421
+ * `returnValue` — and then replacing this error with its retry-exhaustion
422
+ * wrapper. A read that *fails* throws something else and stays retryable.
423
+ * See `FatalError.is()`.
424
+ */
425
+ fatal = true;
426
+ runId;
427
+ /**
428
+ * The high-level error category (e.g. USER_ERROR, RUNTIME_ERROR) for the
429
+ * failed run, from the run_failed event's `errorCode` field.
430
+ */
431
+ errorCode;
432
+ constructor(runId, error, options = {}) {
433
+ const message = error instanceof Error ? error.message : typeof error === "string" ? error : error && typeof error === "object" && "message" in error ? String(error.message) : "Unknown error";
434
+ super(`Workflow run "${runId}" failed: ${message}`, { cause: error });
435
+ this.name = "WorkflowRunFailedError";
436
+ this.runId = runId;
437
+ if (options.errorCode !== void 0) this.errorCode = options.errorCode;
438
+ }
439
+ static is(value) {
440
+ return isError(value) && value.name === "WorkflowRunFailedError";
441
+ }
442
+ };
443
+ /**
444
+ * Thrown when attempting to get results from an incomplete workflow run.
445
+ *
446
+ * This error occurs when you try to access the result of a workflow
447
+ * that is still running or hasn't completed yet.
448
+ */
449
+ var WorkflowRunNotCompletedError = class extends WorkflowError {
450
+ runId;
451
+ status;
452
+ constructor(runId, status) {
453
+ super(`Workflow run "${runId}" has not completed`, {});
454
+ this.name = "WorkflowRunNotCompletedError";
455
+ this.runId = runId;
456
+ this.status = status;
457
+ }
458
+ static is(value) {
459
+ return isError(value) && value.name === "WorkflowRunNotCompletedError";
460
+ }
461
+ };
462
+ /**
463
+ * Thrown when the Workflow runtime encounters an internal error.
464
+ *
465
+ * This error indicates an issue with workflow execution, such as
466
+ * serialization failures, starting an invalid workflow function, or
467
+ * other runtime problems.
468
+ */
469
+ var WorkflowRuntimeError = class extends WorkflowError {
470
+ constructor(message, options) {
471
+ super(message, { ...options });
472
+ this.name = "WorkflowRuntimeError";
473
+ }
474
+ static is(value) {
475
+ return isError(value) && value.name === "WorkflowRuntimeError";
476
+ }
477
+ };
478
+ /**
479
+ * Thrown when the persisted workflow event log cannot be replayed because it
480
+ * contains orphaned, duplicate, or mismatched events.
481
+ *
482
+ * This is a runtime/infrastructure failure rather than user code throwing.
483
+ * When this reaches run failure handling, it is recorded with the distinct
484
+ * `CORRUPTED_EVENT_LOG` code so worlds and backends can track it separately
485
+ * from generic runtime failures.
486
+ */
487
+ var CorruptedEventLogError = class extends WorkflowRuntimeError {
488
+ constructor(message, options) {
489
+ super(message, {
490
+ ...options,
491
+ slug: ERROR_SLUGS.CORRUPTED_EVENT_LOG
492
+ });
493
+ this.name = "CorruptedEventLogError";
494
+ }
495
+ static is(value) {
496
+ return isError(value) && value.name === "CorruptedEventLogError";
497
+ }
498
+ };
499
+ /**
500
+ * Thrown when the SDK's built-in AES-GCM encryption layer fails to encrypt
501
+ * or decrypt a workflow payload.
502
+ *
503
+ * This is an internal SDK failure: user code never invokes the SDK's
504
+ * encryption primitives directly. Common causes:
505
+ *
506
+ * - A ciphertext / auth tag mismatch, typically surfaced as the native Web
507
+ * Crypto `OperationError: The operation failed for an operation-specific
508
+ * reason`. Usually caused by ciphertext mutation or truncation in transit
509
+ * between storage and read (truncated HTTP response, edge-cache miss
510
+ * returning a partial 200, proxy drop during streaming, etc.).
511
+ * - A key resolution mismatch (wrong deployment, missing key material).
512
+ * - A malformed encrypted envelope (too short to contain the GCM nonce
513
+ * and tag).
514
+ *
515
+ * Extends {@link WorkflowRuntimeError} so the run-failure classifier
516
+ * routes it to `RUNTIME_ERROR`.
517
+ */
518
+ var RuntimeDecryptionError = class extends WorkflowRuntimeError {
519
+ constructor(message, options) {
520
+ super(message, {
521
+ cause: options?.cause,
522
+ slug: ERROR_SLUGS.RUNTIME_DECRYPTION_FAILED
523
+ });
524
+ this.name = "RuntimeDecryptionError";
525
+ if (options?.context !== void 0) this.context = options.context;
526
+ }
527
+ static is(value) {
528
+ return isError(value) && value.name === "RuntimeDecryptionError";
529
+ }
530
+ };
531
+ /**
532
+ * Thrown when a stream's encryption key cannot be resolved and retrying will
533
+ * not help: the key lookup failed with something other than a transient world
534
+ * error (e.g. a `404`, or the run that owns the stream does not exist). The
535
+ * original failure is the `cause`.
536
+ *
537
+ * Transient lookup failures (transport, timeout, or an HTTP `429` / `5xx`
538
+ * status, whether or not the world threw a `WorkflowWorldError`) are not
539
+ * wrapped in this error; they surface as themselves so the step retries.
540
+ *
541
+ * Fatal, so the step skips the retry loop.
542
+ */
543
+ var EncryptionKeyLookupError = class extends WorkflowRuntimeError {
544
+ fatal = true;
545
+ constructor(message, options) {
546
+ super(message, { cause: options?.cause });
547
+ this.name = "EncryptionKeyLookupError";
548
+ }
549
+ static is(value) {
550
+ return isError(value) && value.name === "EncryptionKeyLookupError";
551
+ }
552
+ };
553
+ /**
554
+ * Thrown when a value cannot be serialized into or deserialized out of the
555
+ * workflow event log.
556
+ *
557
+ * This usually indicates a user-facing mistake: passing a non-serializable
558
+ * value (class without `WORKFLOW_SERIALIZE`, locked stream, direct workflow
559
+ * function reference) into a step boundary, or an unregistered class
560
+ * returning from a step.
561
+ *
562
+ * Internal invariants (corrupted buffers, unknown format bytes) should use
563
+ * `WorkflowRuntimeError` instead; this class is scoped to things the user
564
+ * can fix in their own code.
565
+ */
566
+ var SerializationError = class extends WorkflowError {
567
+ hint;
568
+ /**
569
+ * Serialization errors are deterministic: if a step returns a non-POJO,
570
+ * replaying the step will always produce the same non-serializable value.
571
+ * Retrying is guaranteed to fail, so these errors are surfaced as fatal
572
+ * and skip the step-retry loop. `FatalError.is()` recognizes any error
573
+ * with `fatal: true` (see `packages/errors/src/index.ts`), so no other
574
+ * wiring is required for user-thrown SerializationErrors.
575
+ */
576
+ fatal = true;
577
+ constructor(message, options) {
578
+ const body = appendFramedDetails(message, buildFramedDetails(options?.hint, void 0));
579
+ super(body, { cause: options?.cause });
580
+ this.name = "SerializationError";
581
+ this.hint = options?.hint;
582
+ }
583
+ static is(value) {
584
+ return isError(value) && value.name === "SerializationError";
585
+ }
586
+ };
587
+ /**
588
+ * Thrown when a step function is not registered in the current deployment.
589
+ *
590
+ * This is an infrastructure error, not a user code error. It typically means
591
+ * something went wrong with the bundling/build tooling that caused the step
592
+ * to not get built correctly.
593
+ *
594
+ * When this happens, the step fails (like a FatalError) and control is passed back
595
+ * to the workflow function, which can optionally handle the failure gracefully.
596
+ */
597
+ var StepNotRegisteredError = class extends WorkflowRuntimeError {
598
+ stepName;
599
+ constructor(stepName) {
600
+ super(`Step "${stepName}" is not registered in the current deployment. This usually indicates a build or bundling issue that caused the step to not be included in the deployment.`, { slug: ERROR_SLUGS.STEP_NOT_REGISTERED });
601
+ this.name = "StepNotRegisteredError";
602
+ this.stepName = stepName;
603
+ }
604
+ static is(value) {
605
+ return isError(value) && value.name === "StepNotRegisteredError";
606
+ }
607
+ };
608
+ /**
609
+ * Thrown when a workflow function is not registered in the current deployment.
610
+ *
611
+ * This is an infrastructure error, not a user code error. It typically means:
612
+ * - A run was started against a deployment that does not have the workflow
613
+ * (e.g., the workflow was renamed or moved and a new run targeted the latest deployment)
614
+ * - Something went wrong with the bundling/build tooling that caused the workflow
615
+ * to not get built correctly
616
+ *
617
+ * When this happens, the run fails with a `RUNTIME_ERROR` error code.
618
+ */
619
+ var WorkflowNotRegisteredError = class extends WorkflowRuntimeError {
620
+ workflowName;
621
+ constructor(workflowName) {
622
+ super(`Workflow "${workflowName}" is not registered in the current deployment. This usually means a run was started against a deployment that does not have this workflow, or there was a build/bundling issue.`, { slug: ERROR_SLUGS.WORKFLOW_NOT_REGISTERED });
623
+ this.name = "WorkflowNotRegisteredError";
624
+ this.workflowName = workflowName;
625
+ }
626
+ static is(value) {
627
+ return isError(value) && value.name === "WorkflowNotRegisteredError";
628
+ }
629
+ };
630
+ /**
631
+ * Thrown when performing operations on a workflow run that does not exist.
632
+ *
633
+ * This error occurs when you call methods on a run object (e.g. `run.status`,
634
+ * `run.cancel()`, `run.returnValue`) but the underlying run ID does not match
635
+ * any known workflow run. Note that `getRun(id)` itself is synchronous and will
636
+ * not throw; this error is raised when subsequent operations discover the run
637
+ * is missing.
638
+ *
639
+ * Use the static `WorkflowRunNotFoundError.is()` method for type-safe checking
640
+ * in catch blocks.
641
+ *
642
+ * @example
643
+ * ```ts
644
+ * import { WorkflowRunNotFoundError } from "workflow/internal/errors";
645
+ *
646
+ * try {
647
+ * const status = await run.status;
648
+ * } catch (error) {
649
+ * if (WorkflowRunNotFoundError.is(error)) {
650
+ * console.error(`Run ${error.runId} does not exist`);
651
+ * }
652
+ * }
653
+ * ```
654
+ */
655
+ var WorkflowRunNotFoundError = class extends WorkflowError {
656
+ runId;
657
+ constructor(runId) {
658
+ super(`Workflow run "${runId}" not found`, {});
659
+ this.name = "WorkflowRunNotFoundError";
660
+ this.runId = runId;
661
+ }
662
+ static is(value) {
663
+ return isError(value) && value.name === "WorkflowRunNotFoundError";
664
+ }
665
+ };
666
+ /**
667
+ * Thrown when a hook token is already in use by another active workflow run.
668
+ *
669
+ * This is a user error: it means the same custom token was passed to
670
+ * `createHook` in two or more concurrent runs. Use a unique token per run
671
+ * (or omit the token to let the runtime generate one automatically).
672
+ *
673
+ * `start(workflow, args, { hook })` throws it with `kind: 'start'` for a
674
+ * duplicate start: no run was created, and `conflictingRunId` owns the token.
675
+ */
676
+ var HookConflictError = class extends WorkflowError {
677
+ token;
678
+ conflictingRunId;
679
+ /** `'start'` when a `start({ hook })` was refused; no run was created. */
680
+ kind;
681
+ constructor(token, conflictingRunId, options) {
682
+ super(options?.kind === "start" ? `No run was created: workflow run "${conflictingRunId}" already owns this hook token` : `Hook token "${token}" is already in use by another workflow${conflictingRunId ? ` (run "${conflictingRunId}")` : ""}`, { slug: ERROR_SLUGS.HOOK_CONFLICT });
683
+ this.name = "HookConflictError";
684
+ this.token = token;
685
+ if (conflictingRunId !== void 0) this.conflictingRunId = conflictingRunId;
686
+ if (options?.kind !== void 0) this.kind = options.kind;
687
+ }
688
+ static is(value) {
689
+ return isError(value) && value.name === "HookConflictError";
690
+ }
691
+ };
692
+ /**
693
+ * Thrown from `await hook` (or the hook's async iterator) when another run
694
+ * took this hook's token with `createHook({ token, experimental_force: true })`.
695
+ *
696
+ * The hook is disposed: payloads it received before the takeover were still
697
+ * delivered, everything after goes to the new owner, and this run's log holds
698
+ * a `hook_disposed` naming the run that took it. Whether that ends the run is
699
+ * the workflow's call — catch it to hand over gracefully, or let it fail.
700
+ *
701
+ * Use the static `HookForceClaimedError.is()` method for type-safe checking
702
+ * in catch blocks; the class identity differs between the workflow VM and the
703
+ * host, so `instanceof` is not reliable across that boundary.
704
+ */
705
+ var HookForceClaimedError = class extends WorkflowError {
706
+ token;
707
+ /** The run that took the token. */
708
+ claimedByRunId;
709
+ /** The hook (in `claimedByRunId`) the token now belongs to. */
710
+ claimedByHookId;
711
+ constructor(token, claimedByRunId, claimedByHookId) {
712
+ super(`Hook token "${token}" was force-claimed by another workflow (run "${claimedByRunId}")`, { slug: ERROR_SLUGS.HOOK_FORCE_CLAIMED });
713
+ this.name = "HookForceClaimedError";
714
+ this.token = token;
715
+ this.claimedByRunId = claimedByRunId;
716
+ if (claimedByHookId !== void 0) this.claimedByHookId = claimedByHookId;
717
+ }
718
+ static is(value) {
719
+ return isError(value) && value.name === "HookForceClaimedError";
720
+ }
721
+ };
722
+ /**
723
+ * Thrown when calling `resumeHook()` or `resumeWebhook()` with a token that
724
+ * does not match any active hook.
725
+ *
726
+ * Common causes:
727
+ * - The hook has expired (past its TTL)
728
+ * - The hook was already disposed after being consumed
729
+ * - The workflow has not started yet, so the hook does not exist
730
+ *
731
+ * A common pattern is to catch this error and start a new workflow run when
732
+ * the hook does not exist yet (the "resume or start" pattern).
733
+ *
734
+ * Use the static `HookNotFoundError.is()` method for type-safe checking in
735
+ * catch blocks.
736
+ *
737
+ * @example
738
+ * ```ts
739
+ * import { HookNotFoundError } from "workflow/internal/errors";
740
+ *
741
+ * try {
742
+ * await resumeHook(token, payload);
743
+ * } catch (error) {
744
+ * if (HookNotFoundError.is(error)) {
745
+ * // Hook doesn't exist, so start a new workflow run instead
746
+ * await startWorkflow("myWorkflow", payload);
747
+ * }
748
+ * }
749
+ * ```
750
+ */
751
+ var HookNotFoundError = class extends WorkflowError {
752
+ token;
753
+ constructor(token) {
754
+ super("Hook not found", {});
755
+ this.name = "HookNotFoundError";
756
+ this.token = token;
757
+ }
758
+ static is(value) {
759
+ return isError(value) && value.name === "HookNotFoundError";
760
+ }
761
+ };
762
+ /**
763
+ * Thrown when an operation conflicts with the current state of an entity.
764
+ * This includes attempts to modify an entity already in a terminal state,
765
+ * create an entity that already exists, or any other 409-style conflict.
766
+ *
767
+ * The workflow runtime handles this error automatically. Users interacting
768
+ * with world storage backends directly may encounter it.
769
+ */
770
+ var EntityConflictError = class extends WorkflowWorldError {
771
+ constructor(message) {
772
+ super(message);
773
+ this.name = "EntityConflictError";
774
+ }
775
+ static is(value) {
776
+ return isError(value) && value.name === "EntityConflictError";
777
+ }
778
+ };
779
+ /**
780
+ * Thrown when a run is no longer available, either because it has been
781
+ * cleaned up, expired, or already reached a terminal state (completed/failed).
782
+ *
783
+ * Also thrown by `await run.returnValue` when the run's data passed its
784
+ * retention boundary — because it was started with
785
+ * `experimental_retention: 0`, or simply because it aged out of the World's
786
+ * default window. The run's metadata usually outlives its payloads, so
787
+ * `runStatus` and `expiredAt` are populated when the World still has them: the
788
+ * caller can tell "it succeeded, but the result is gone" from "it failed".
789
+ * When even the metadata is gone the World reports the run as missing and you
790
+ * get {@link WorkflowRunNotFoundError} instead.
791
+ *
792
+ * This is terminal. Retrying cannot bring the data back.
793
+ */
794
+ var RunExpiredError = class extends WorkflowWorldError {
795
+ runId;
796
+ runStatus;
797
+ expiredAt;
798
+ constructor(message, runId, runStatus, expiredAt) {
799
+ super(message, {
800
+ status: 410,
801
+ code: "run-expired"
802
+ });
803
+ this.runId = runId;
804
+ this.runStatus = runStatus;
805
+ this.expiredAt = expiredAt;
806
+ this.name = "RunExpiredError";
807
+ }
808
+ static is(value) {
809
+ return isError(value) && value.name === "RunExpiredError";
810
+ }
811
+ };
812
+ /**
813
+ * Thrown when Workflow's stream infrastructure fails to read or write data.
814
+ * The failure is attributable to the Workflow service rather than user code.
815
+ */
816
+ var StreamError = class extends WorkflowWorldError {
817
+ constructor(message, options) {
818
+ super(message, {
819
+ code: RUN_ERROR_CODES.STREAM_ERROR,
820
+ cause: options?.cause,
821
+ url: options?.url,
822
+ status: options?.status
823
+ });
824
+ this.name = "StreamError";
825
+ }
826
+ static is(value) {
827
+ return isError(value) && value.name === "StreamError";
828
+ }
829
+ };
830
+ /**
831
+ * Thrown when a stream is no longer readable because its owning run passed its
832
+ * storage-retention boundary. This is terminal: retrying cannot restore data.
833
+ *
834
+ * Unlike {@link RunExpiredError}, this identifies the failed stream read and
835
+ * exposes the server's authoritative expiry timestamp for user-facing errors.
836
+ */
837
+ var StreamExpiredError = class extends WorkflowWorldError {
838
+ runId;
839
+ streamId;
840
+ expiredAt;
841
+ constructor(message, runId, streamId, expiredAt) {
842
+ super(message, {
843
+ status: 410,
844
+ code: "stream-expired"
845
+ });
846
+ this.runId = runId;
847
+ this.streamId = streamId;
848
+ this.expiredAt = expiredAt;
849
+ this.name = "StreamExpiredError";
850
+ }
851
+ static is(value) {
852
+ return isError(value) && value.name === "StreamExpiredError";
853
+ }
854
+ };
855
+ /**
856
+ * Thrown when an operation cannot proceed because a required timestamp
857
+ * (e.g. retryAfter) has not been reached yet.
858
+ *
859
+ * The workflow runtime handles this error automatically. Users interacting
860
+ * with world storage backends directly may encounter it.
861
+ *
862
+ * @property retryAfter - Delay in seconds before the operation can be retried.
863
+ */
864
+ var TooEarlyError = class extends WorkflowWorldError {
865
+ constructor(message, options) {
866
+ super(message, { retryAfter: options?.retryAfter });
867
+ this.name = "TooEarlyError";
868
+ }
869
+ static is(value) {
870
+ return isError(value) && value.name === "TooEarlyError";
871
+ }
872
+ };
873
+ /**
874
+ * Thrown when a request is rate limited by the workflow backend.
875
+ *
876
+ * The workflow runtime handles this error automatically with retry logic.
877
+ * Users interacting with world storage backends directly may encounter it
878
+ * if retries are exhausted.
879
+ *
880
+ * @property retryAfter - Delay in seconds before the request can be retried.
881
+ */
882
+ var ThrottleError = class extends WorkflowWorldError {
883
+ retryAfter;
884
+ constructor(message, options) {
885
+ super(message);
886
+ this.name = "ThrottleError";
887
+ this.retryAfter = options?.retryAfter;
888
+ }
889
+ static is(value) {
890
+ return isError(value) && value.name === "ThrottleError";
891
+ }
892
+ };
893
+ /**
894
+ * Thrown when the backend rejects an event creation because the client's
895
+ * event-log snapshot is stale: the log the client replayed from is missing
896
+ * an event the backend has already recorded (HTTP 412).
897
+ *
898
+ * The workflow runtime handles this automatically: it restarts the replay from
899
+ * a corrected event log, ultimately re-enqueueing the run if it cannot catch
900
+ * up. Users interacting with world storage backends directly may encounter it.
901
+ *
902
+ * @property retryAfter - Delay in seconds before retrying. Accepted for
903
+ * forward-compatibility; the runtime restarts its replay immediately and
904
+ * does not read this field.
905
+ * @property details - Optional rejection detail supplied by the World. A World
906
+ * MAY attach the events the client's snapshot was missing so the client can
907
+ * correct its log without a follow-up fetch. The attached set must account
908
+ * for the whole discrepancy the rejection reported or be omitted entirely; a
909
+ * client that receives nothing does the authoritative full reload, which is
910
+ * always correct. Typed `unknown` because this package cannot depend
911
+ * on the event type; consumers narrow it themselves and must treat a
912
+ * missing or malformed value as "no detail" (a full reload is always
913
+ * correct).
914
+ */
915
+ var PreconditionFailedError = class extends WorkflowWorldError {
916
+ details;
917
+ constructor(message, options) {
918
+ super(message, {
919
+ status: 412,
920
+ retryAfter: options?.retryAfter
921
+ });
922
+ this.name = "PreconditionFailedError";
923
+ this.details = options?.details;
924
+ }
925
+ static is(value) {
926
+ return isError(value) && value.name === "PreconditionFailedError";
927
+ }
928
+ };
929
+ /** Error code a World uses for an {@link InBandSupersededError} refusal. */
930
+ var IN_BAND_SUPERSEDED_CODE = "in-band-superseded";
931
+ /**
932
+ * Thrown when a World refuses an in-band write (a write made by the run's
933
+ * orchestrator) because another orchestrator invocation of the same run has
934
+ * written in-band since this one loaded the log (HTTP 412,
935
+ * `in-band-superseded`).
936
+ *
937
+ * The in-band fence is what keeps a run to one orchestrator writer. An
938
+ * invocation that receives this error has been superseded: it stops writing
939
+ * and stops running step bodies, sends the queue messages its own committed
940
+ * writes still owe (background step messages, wait timers), and asks for a
941
+ * redelivery of its queue message instead of acknowledging it: the
942
+ * redelivery re-sends what a second delivery of the same message may have
943
+ * committed and never sent, and continues the run if no other invocation
944
+ * does. The runtime handles all of this;
945
+ * users calling a World's storage API directly may encounter it.
946
+ *
947
+ * @property seq - The run's allocated position count at the time of the
948
+ * refusal, when the World reports it. Diagnostic only.
949
+ * @property seqInBand - The run's in-band position count at the time of the
950
+ * refusal, when the World reports it. Diagnostic only: a client must never
951
+ * adopt it as its own count, since that would make it a writer without
952
+ * having seen the events the count stands for.
953
+ */
954
+ var InBandSupersededError = class extends WorkflowWorldError {
955
+ seq;
956
+ seqInBand;
957
+ constructor(message, options) {
958
+ super(message, {
959
+ status: 412,
960
+ code: IN_BAND_SUPERSEDED_CODE
961
+ });
962
+ this.name = "InBandSupersededError";
963
+ this.seq = options?.seq;
964
+ this.seqInBand = options?.seqInBand;
965
+ }
966
+ static is(value) {
967
+ return isError(value) && value.name === "InBandSupersededError";
968
+ }
969
+ };
970
+ /**
971
+ * Thrown when awaiting `run.returnValue` on a workflow run that was cancelled.
972
+ *
973
+ * This error indicates that the workflow was explicitly cancelled (via
974
+ * `run.cancel()`) and will not produce a return value. You can check for
975
+ * cancellation before awaiting the return value by inspecting `run.status`.
976
+ *
977
+ * Use the static `WorkflowRunCancelledError.is()` method for type-safe
978
+ * checking in catch blocks.
979
+ *
980
+ * @example
981
+ * ```ts
982
+ * import { WorkflowRunCancelledError } from "workflow/internal/errors";
983
+ *
984
+ * try {
985
+ * const result = await run.returnValue;
986
+ * } catch (error) {
987
+ * if (WorkflowRunCancelledError.is(error)) {
988
+ * console.log(`Run ${error.runId} was cancelled`);
989
+ * }
990
+ * }
991
+ * ```
992
+ */
993
+ var WorkflowRunCancelledError = class extends WorkflowError {
994
+ /** Terminal and immutable, for the same reason as {@link WorkflowRunFailedError.fatal}. */
995
+ fatal = true;
996
+ runId;
997
+ constructor(runId) {
998
+ super(`Workflow run "${runId}" cancelled`, {});
999
+ this.name = "WorkflowRunCancelledError";
1000
+ this.runId = runId;
1001
+ }
1002
+ static is(value) {
1003
+ return isError(value) && value.name === "WorkflowRunCancelledError";
1004
+ }
1005
+ };
1006
+ /**
1007
+ * Thrown when attempting to operate on a workflow run that requires a newer World version.
1008
+ *
1009
+ * This error occurs when a run was created with a newer spec version than the
1010
+ * current World implementation supports. To resolve this, upgrade your
1011
+ * `workflow` packages to a version that supports the required spec version.
1012
+ *
1013
+ * Use the static `RunNotSupportedError.is()` method for type-safe checking in
1014
+ * catch blocks.
1015
+ *
1016
+ * @example
1017
+ * ```ts
1018
+ * import { RunNotSupportedError } from "workflow/internal/errors";
1019
+ *
1020
+ * try {
1021
+ * const status = await run.status;
1022
+ * } catch (error) {
1023
+ * if (RunNotSupportedError.is(error)) {
1024
+ * console.error(
1025
+ * `Run requires spec v${error.runSpecVersion}, ` +
1026
+ * `but world supports v${error.worldSpecVersion}`
1027
+ * );
1028
+ * }
1029
+ * }
1030
+ * ```
1031
+ */
1032
+ var RunNotSupportedError = class extends WorkflowError {
1033
+ runSpecVersion;
1034
+ worldSpecVersion;
1035
+ constructor(runSpecVersion, worldSpecVersion) {
1036
+ super(`Run requires spec version ${runSpecVersion}, but world supports version ${worldSpecVersion}. Please upgrade 'workflow' package.`);
1037
+ this.name = "RunNotSupportedError";
1038
+ this.runSpecVersion = runSpecVersion;
1039
+ this.worldSpecVersion = worldSpecVersion;
1040
+ }
1041
+ static is(value) {
1042
+ return isError(value) && value.name === "RunNotSupportedError";
1043
+ }
1044
+ };
1045
+ /**
1046
+ * A fatal error is an error that cannot be retried.
1047
+ * It will cause the step to fail and the error will
1048
+ * be bubbled up to the workflow logic.
1049
+ *
1050
+ * Any error can opt into the non-retry behavior by setting a `fatal: true`
1051
+ * own property. This is how structured error classes that aren't direct
1052
+ * `FatalError` subclasses (e.g. context-violation errors) signal to the
1053
+ * step executor that retrying will never help (the user's code is calling
1054
+ * a workflow-only API from the wrong context, or similar) and burning
1055
+ * retry attempts produces a wall of duplicated log output.
1056
+ */
1057
+ var FatalError = class extends Error {
1058
+ fatal = true;
1059
+ constructor(message) {
1060
+ super(message);
1061
+ this.name = "FatalError";
1062
+ }
1063
+ static is(value) {
1064
+ if (!isError(value)) return false;
1065
+ if (value.name === "FatalError") return true;
1066
+ return value.fatal === true;
1067
+ }
1068
+ };
1069
+ /**
1070
+ * An error that can happen during a step execution, allowing
1071
+ * for configuration of the retry behavior.
1072
+ */
1073
+ var RetryableError = class extends Error {
1074
+ /**
1075
+ * The Date when the step should be retried.
1076
+ */
1077
+ retryAfter;
1078
+ constructor(message, options = {}) {
1079
+ super(message);
1080
+ this.name = "RetryableError";
1081
+ if (options.retryAfter !== void 0) this.retryAfter = parseDurationToDate(options.retryAfter);
1082
+ else this.retryAfter = new Date(Date.now() + 1e3);
1083
+ }
1084
+ static is(value) {
1085
+ return isError(value) && value.name === "RetryableError";
1086
+ }
1087
+ };
1088
+ var VERCEL_403_ERROR_MESSAGE = "Your current vercel account does not have access to this resource. Use `vercel login` or `vercel switch` to ensure you are linked to the right account.";
1089
+ var FATAL_ERROR_KEY = Symbol.for("@workflow/errors//FatalError");
1090
+ var RETRYABLE_ERROR_KEY = Symbol.for("@workflow/errors//RetryableError");
1091
+ var HOOK_CONFLICT_ERROR_KEY = Symbol.for("@workflow/errors//HookConflictError");
1092
+ var HOOK_FORCE_CLAIMED_ERROR_KEY = Symbol.for("@workflow/errors//HookForceClaimedError");
1093
+ var RUNTIME_DECRYPTION_ERROR_KEY = Symbol.for("@workflow/errors//RuntimeDecryptionError");
1094
+ var STREAM_ERROR_KEY = Symbol.for("@workflow/errors//StreamError");
1095
+ var WORKFLOW_START_ERROR_KEY = Symbol.for("@workflow/errors//WorkflowStartError");
1096
+ if (typeof globalThis !== "undefined") {
1097
+ if (!Object.hasOwn(globalThis, FATAL_ERROR_KEY)) Object.defineProperty(globalThis, FATAL_ERROR_KEY, {
1098
+ value: FatalError,
1099
+ writable: false,
1100
+ enumerable: false,
1101
+ configurable: false
1102
+ });
1103
+ if (!Object.hasOwn(globalThis, RETRYABLE_ERROR_KEY)) Object.defineProperty(globalThis, RETRYABLE_ERROR_KEY, {
1104
+ value: RetryableError,
1105
+ writable: false,
1106
+ enumerable: false,
1107
+ configurable: false
1108
+ });
1109
+ if (!Object.hasOwn(globalThis, HOOK_CONFLICT_ERROR_KEY)) Object.defineProperty(globalThis, HOOK_CONFLICT_ERROR_KEY, {
1110
+ value: HookConflictError,
1111
+ writable: false,
1112
+ enumerable: false,
1113
+ configurable: false
1114
+ });
1115
+ if (!Object.hasOwn(globalThis, HOOK_FORCE_CLAIMED_ERROR_KEY)) Object.defineProperty(globalThis, HOOK_FORCE_CLAIMED_ERROR_KEY, {
1116
+ value: HookForceClaimedError,
1117
+ writable: false,
1118
+ enumerable: false,
1119
+ configurable: false
1120
+ });
1121
+ if (!Object.hasOwn(globalThis, RUNTIME_DECRYPTION_ERROR_KEY)) Object.defineProperty(globalThis, RUNTIME_DECRYPTION_ERROR_KEY, {
1122
+ value: RuntimeDecryptionError,
1123
+ writable: false,
1124
+ enumerable: false,
1125
+ configurable: false
1126
+ });
1127
+ if (!Object.hasOwn(globalThis, STREAM_ERROR_KEY)) Object.defineProperty(globalThis, STREAM_ERROR_KEY, {
1128
+ value: StreamError,
1129
+ writable: false,
1130
+ enumerable: false,
1131
+ configurable: false
1132
+ });
1133
+ if (!Object.hasOwn(globalThis, WORKFLOW_START_ERROR_KEY)) Object.defineProperty(globalThis, WORKFLOW_START_ERROR_KEY, {
1134
+ value: WorkflowStartError,
1135
+ writable: false,
1136
+ enumerable: false,
1137
+ configurable: false
1138
+ });
1139
+ }
1140
+ export { WorkflowRuntimeError as A, TooEarlyError as C, WorkflowRunFailedError as D, WorkflowRunCancelledError as E, require_ms as F, WorkflowWorldError as M, RUN_ERROR_CODES as N, WorkflowRunNotCompletedError as O, parseDurationToDate as P, ThrottleError as S, WorkflowNotRegisteredError as T, START_HOOK_CANDIDATE_CANCELLED as _, HookConflictError as a, StreamError as b, IN_BAND_SUPERSEDED_CODE as c, RetryableError as d, RunExpiredError as f, START_HOOK_ADMISSION_REJECTED as g, START_HOOK_ADMISSION_DISABLED as h, FatalError as i, WorkflowStartError as j, WorkflowRunNotFoundError as k, InBandSupersededError as l, RuntimeDecryptionError as m, EncryptionKeyLookupError as n, HookForceClaimedError as o, RunNotSupportedError as p, EntityConflictError as r, HookNotFoundError as s, CorruptedEventLogError as t, PreconditionFailedError as u, SerializationError as v, VERCEL_403_ERROR_MESSAGE as w, StreamExpiredError as x, StepNotRegisteredError as y };