@ls-stack/agent-eval 0.16.1 → 0.18.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.
@@ -4,7 +4,9 @@ import { mkdir, readFile, readdir, rename, rm, stat, writeFile } from "node:fs/p
4
4
  import { extname, isAbsolute, join, relative, resolve } from "node:path";
5
5
  import { z, z as z$1 } from "zod/v4";
6
6
  import { AsyncLocalStorage } from "node:async_hooks";
7
+ import { formatWithOptions } from "node:util";
7
8
  import { Buffer as Buffer$1 } from "node:buffer";
9
+ import { gunzipSync, gzipSync } from "node:zlib";
8
10
  import { getCompositeKey } from "@ls-stack/utils/getCompositeKey";
9
11
  import { existsSync } from "node:fs";
10
12
  import { resultify } from "t-result";
@@ -49,6 +51,27 @@ const scopeStorage = new AsyncLocalStorage();
49
51
  const runtimeScopeStorage = new AsyncLocalStorage();
50
52
  let activeEvalScopeCount = 0;
51
53
  let activeEvalRuntimeScopeCount = 0;
54
+ let consoleCaptureEnabled = true;
55
+ const maxLogMessageLength = 2e4;
56
+ const maxLogStringLength = 1e4;
57
+ const maxLogArrayLength = 100;
58
+ const maxLogObjectEntries = 100;
59
+ const maxLogValueDepth = 5;
60
+ const consoleCaptureMethods = [
61
+ "log",
62
+ "info",
63
+ "warn",
64
+ "error"
65
+ ];
66
+ const runtimeConsole = globalThis.console;
67
+ const stackFrameLocationPattern = /(?:\((?<parenFile>.+):(?<parenLine>\d+):(?<parenColumn>\d+)\)|at (?<bareFile>.+):(?<bareLine>\d+):(?<bareColumn>\d+))$/;
68
+ const fileUrlPrefixPattern = /^file:\/\//;
69
+ const originalConsoleMethods = {
70
+ log: runtimeConsole.log.bind(runtimeConsole),
71
+ info: runtimeConsole.info.bind(runtimeConsole),
72
+ warn: runtimeConsole.warn.bind(runtimeConsole),
73
+ error: runtimeConsole.error.bind(runtimeConsole)
74
+ };
52
75
  /** Error thrown when an eval assertion fails during case execution. */
53
76
  var EvalAssertionError = class extends Error {
54
77
  constructor(message) {
@@ -73,6 +96,186 @@ function isInEvalScope() {
73
96
  if (activeEvalRuntimeScopeCount === 0) return null;
74
97
  return runtimeScopeStorage.getStore() ?? null;
75
98
  }
99
+ function normalizeLogLevel(level) {
100
+ return level === "warning" ? "warn" : level;
101
+ }
102
+ function getCurrentLogPhase() {
103
+ const runtimeScope = runtimeScopeStorage.getStore();
104
+ if (runtimeScope === "eval" || runtimeScope === "derive" || runtimeScope === "outputsSchema" || runtimeScope === "scorer") return runtimeScope;
105
+ return null;
106
+ }
107
+ function formatLogArgs(args) {
108
+ const formatted = formatWithOptions({
109
+ depth: 2,
110
+ maxArrayLength: 100,
111
+ maxStringLength: 1e4,
112
+ breakLength: 80,
113
+ compact: 3
114
+ }, ...args);
115
+ if (formatted.length <= maxLogMessageLength) return {
116
+ message: formatted,
117
+ truncated: false
118
+ };
119
+ return {
120
+ message: `${formatted.slice(0, maxLogMessageLength)}...`,
121
+ truncated: true
122
+ };
123
+ }
124
+ function truncateLogString(value, ctx) {
125
+ if (value.length <= maxLogStringLength) return value;
126
+ ctx.truncated = true;
127
+ return `${value.slice(0, maxLogStringLength)}...`;
128
+ }
129
+ function primitiveToLogValue(value, ctx) {
130
+ if (typeof value === "string") return {
131
+ handled: true,
132
+ value: truncateLogString(value, ctx)
133
+ };
134
+ if (value === null || typeof value === "number" || typeof value === "boolean") return {
135
+ handled: true,
136
+ value
137
+ };
138
+ if (value === void 0) return {
139
+ handled: true,
140
+ value: "[undefined]"
141
+ };
142
+ if (typeof value === "bigint") return {
143
+ handled: true,
144
+ value: `${value.toString()}n`
145
+ };
146
+ if (typeof value === "symbol") return {
147
+ handled: true,
148
+ value: String(value)
149
+ };
150
+ if (typeof value === "function") return {
151
+ handled: true,
152
+ value: `[Function${value.name.length > 0 ? `: ${value.name}` : ""}]`
153
+ };
154
+ return {
155
+ handled: false,
156
+ value: null
157
+ };
158
+ }
159
+ function objectToLogValue(value, ctx, depth) {
160
+ if (value instanceof Date) return value.toISOString();
161
+ if (value instanceof Error) return {
162
+ name: value.name,
163
+ message: value.message,
164
+ stack: value.stack
165
+ };
166
+ if (ctx.seen.has(value)) return "[Circular]";
167
+ if (depth >= maxLogValueDepth) {
168
+ ctx.truncated = true;
169
+ return Array.isArray(value) ? "[Array]" : "[Object]";
170
+ }
171
+ ctx.seen.add(value);
172
+ try {
173
+ if (Array.isArray(value)) {
174
+ const limited = value.slice(0, maxLogArrayLength).map((item) => toLogJsonValue(item, ctx, depth + 1));
175
+ if (value.length > maxLogArrayLength) {
176
+ ctx.truncated = true;
177
+ limited.push(`[... ${String(value.length - maxLogArrayLength)} more]`);
178
+ }
179
+ return limited;
180
+ }
181
+ const entries = Object.entries(value);
182
+ const result = {};
183
+ for (const [key, entryValue] of entries.slice(0, maxLogObjectEntries)) result[key] = toLogJsonValue(entryValue, ctx, depth + 1);
184
+ if (entries.length > maxLogObjectEntries) {
185
+ ctx.truncated = true;
186
+ result.__truncated = `${String(entries.length - maxLogObjectEntries)} more properties`;
187
+ }
188
+ return result;
189
+ } finally {
190
+ ctx.seen.delete(value);
191
+ }
192
+ }
193
+ function toLogJsonValue(value, ctx, depth) {
194
+ const primitive = primitiveToLogValue(value, ctx);
195
+ if (primitive.handled) return primitive.value;
196
+ if (typeof value === "object" && value !== null) return objectToLogValue(value, ctx, depth);
197
+ return String(value);
198
+ }
199
+ function toLogJsonArgs(args) {
200
+ const ctx = {
201
+ seen: /* @__PURE__ */ new WeakSet(),
202
+ truncated: false
203
+ };
204
+ return {
205
+ args: args.map((value) => toLogJsonValue(value, ctx, 0)),
206
+ truncated: ctx.truncated
207
+ };
208
+ }
209
+ function normalizeStackFile(value) {
210
+ if (!value.startsWith("file://")) return value;
211
+ return decodeURIComponent(value.replace(fileUrlPrefixPattern, ""));
212
+ }
213
+ function isInternalLogFrame(file) {
214
+ return file.includes("/packages/sdk/src/runtime.ts") || file.includes("/node:internal/") || file.startsWith("node:internal/");
215
+ }
216
+ function parseStackFrameLocation(line) {
217
+ const match = stackFrameLocationPattern.exec(line.trim());
218
+ if (!match?.groups) return null;
219
+ const file = match.groups.parenFile ?? match.groups.bareFile;
220
+ const lineNumber = Number(match.groups.parenLine ?? match.groups.bareLine);
221
+ const column = Number(match.groups.parenColumn ?? match.groups.bareColumn);
222
+ if (file === void 0 || !Number.isFinite(lineNumber) || !Number.isFinite(column)) return null;
223
+ return {
224
+ file: normalizeStackFile(file),
225
+ line: lineNumber,
226
+ column
227
+ };
228
+ }
229
+ function getLogLocation() {
230
+ const stack = (/* @__PURE__ */ new Error()).stack;
231
+ if (stack === void 0) return void 0;
232
+ for (const line of stack.split("\n").slice(1)) {
233
+ const location = parseStackFrameLocation(line);
234
+ if (location === null || isInternalLogFrame(location.file)) continue;
235
+ return location;
236
+ }
237
+ }
238
+ function recordEvalLog(level, args) {
239
+ const scope = getCurrentScope();
240
+ const phase = getCurrentLogPhase();
241
+ if (!scope || !phase) return;
242
+ const preview = formatLogArgs(args);
243
+ const jsonArgs = toLogJsonArgs(args);
244
+ const location = getLogLocation();
245
+ scope.logs.push({
246
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
247
+ level: normalizeLogLevel(level),
248
+ phase,
249
+ message: preview.message,
250
+ args: jsonArgs.args,
251
+ truncated: preview.truncated || jsonArgs.truncated,
252
+ location
253
+ });
254
+ }
255
+ for (const method of consoleCaptureMethods) runtimeConsole[method] = (...args) => {
256
+ if (consoleCaptureEnabled) recordEvalLog(method, args);
257
+ originalConsoleMethods[method](...args);
258
+ };
259
+ /**
260
+ * Configure whether console methods are captured as eval case logs.
261
+ *
262
+ * Runner-internal helper. When disabled, console output still prints normally;
263
+ * only automatic persistence to `caseDetail.logs` is skipped. Manual
264
+ * `evalLog(...)` calls are unaffected.
265
+ */
266
+ function configureEvalRunLogs(options) {
267
+ consoleCaptureEnabled = options.captureConsole;
268
+ }
269
+ /**
270
+ * Record a manual log entry on the active eval case.
271
+ *
272
+ * Values are formatted with Node-style console formatting and capped before
273
+ * persistence so a single log cannot make run artifacts unbounded. Calls made
274
+ * outside active case-owned eval phases are ignored.
275
+ */
276
+ function evalLog(level, ...args) {
277
+ recordEvalLog(level, args);
278
+ }
76
279
  function registerBackgroundJobInScope(scope, promise) {
77
280
  const trackedPromise = promise.then(() => {
78
281
  scope.pendingBackgroundJobs.delete(trackedPromise);
@@ -164,6 +367,7 @@ async function runInEvalScope(caseId, fn, options = {}) {
164
367
  input: options.input,
165
368
  outputs: {},
166
369
  assertionFailures: [],
370
+ logs: [],
167
371
  spans: [],
168
372
  checkpoints: /* @__PURE__ */ new Map(),
169
373
  spanStack: [],
@@ -332,1811 +536,327 @@ function evalAssert(condition, message) {
332
536
  throw error;
333
537
  }
334
538
  //#endregion
335
- //#region ../sdk/src/cacheKey.ts
336
- var SerializedCacheKeyValue = class {
337
- value;
338
- constructor(value) {
339
- this.value = value;
340
- }
341
- };
539
+ //#region ../sdk/src/cacheSerialization.ts
540
+ const serializedCacheValueMarker = "__agentEvalsCacheSerialization";
541
+ const jsonSafeCacheValueVersion = "json-safe-v1";
542
+ const packedNumberArrayMinLength = 128;
543
+ const compressedStringMinBytes = 16 * 1024;
544
+ const compressedJsonMinBytes = 64 * 1024;
545
+ const maxCompressedSizeRatio = .8;
546
+ function isRecordLike$3(value) {
547
+ return typeof value === "object" && value !== null && !Array.isArray(value);
548
+ }
549
+ function isJsonSafeSerializedCacheValue(value) {
550
+ return isRecordLike$3(value) && value[serializedCacheValueMarker] === jsonSafeCacheValueVersion && typeof value.type === "string";
551
+ }
552
+ function jsonSafeValue(type, value) {
553
+ return value === void 0 ? {
554
+ [serializedCacheValueMarker]: jsonSafeCacheValueVersion,
555
+ type
556
+ } : {
557
+ [serializedCacheValueMarker]: jsonSafeCacheValueVersion,
558
+ type,
559
+ value
560
+ };
561
+ }
562
+ function hasSerializationMarkerKey(value) {
563
+ return Object.hasOwn(value, serializedCacheValueMarker);
564
+ }
342
565
  /**
343
- * Hash the components of a cache key into a deterministic hex digest.
566
+ * Serialize one cached value while keeping plain JSON as plain JSON.
344
567
  *
345
- * Native `Blob` and `File` values use stable metadata by default. Pass
346
- * `serializeFileBytes: true` to read them asynchronously and include their byte
347
- * hash in the key.
568
+ * Rich runtime values use small tagged wrappers.
348
569
  */
349
- async function hashCacheKey(input, options = {}) {
350
- return hashCacheKeySyncMaterialized(options.serializeFileBytes === true ? await materializeAsyncCacheKeyValue(input) : input);
570
+ async function serializeCacheValue(value) {
571
+ return serializeJsonSafeValue(value, /* @__PURE__ */ new WeakSet(), 0);
351
572
  }
352
- /**
353
- * Synchronously hash cache key components. This supports JSON-like data and
354
- * in-memory binary values such as `Buffer`, `ArrayBuffer`, and typed arrays,
355
- * plus stable metadata for native `Blob` and `File` values.
356
- */
357
- function hashCacheKeySync(input) {
358
- return hashCacheKeySyncMaterialized(input);
573
+ /** Revive one cached value, while preserving legacy JSON-round-tripped data. */
574
+ function deserializeCacheValue(value) {
575
+ return deserializeJsonSafeValue(value);
359
576
  }
360
- function hashCacheKeySyncMaterialized(input) {
361
- return createHash("sha256").update(getCompositeKey(input, { stringify: stringifyCacheKeyValue })).digest("hex");
577
+ /** Clone one value through the same serialization path used for cache data. */
578
+ async function cloneCacheValue(value) {
579
+ return deserializeCacheValue(await serializeCacheValue(value));
362
580
  }
363
- function stringifyCacheKeyValue(value) {
364
- if (value instanceof SerializedCacheKeyValue) return value.value;
365
- if (Buffer$1.isBuffer(value)) return `$buffer:${hashBytes(value)}`;
366
- if (isArrayBuffer(value)) return `$arrayBuffer:${hashBytes(new Uint8Array(value))}`;
367
- if (isSharedArrayBuffer(value)) return `$sharedArrayBuffer:${hashBytes(new Uint8Array(value))}`;
368
- if (isArrayBufferView(value)) {
369
- const bytes = new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
370
- return `$${value.constructor.name}:${hashBytes(bytes)}`;
371
- }
372
- if (isFile$1(value)) return `$file:${getCompositeKey({
581
+ async function serializeJsonSafeValue(value, refs, depth) {
582
+ if (value === void 0) return jsonSafeValue("Undefined");
583
+ if (typeof value === "bigint") return jsonSafeValue("BigInt", value.toString());
584
+ if (typeof value === "number") return serializeNumber(value);
585
+ if (typeof value === "string") return serializeString(value, depth);
586
+ if (value instanceof Date) return jsonSafeValue("Date", value.toISOString());
587
+ if (value instanceof Map) return serializeMap(value, refs, depth);
588
+ if (value instanceof Set) return serializeSet(value, refs, depth);
589
+ if (value instanceof RegExp) return jsonSafeValue("RegExp", {
590
+ flags: value.flags,
591
+ source: value.source
592
+ });
593
+ if (value instanceof URL) return jsonSafeValue("URL", value.toString());
594
+ if (value instanceof URLSearchParams) return jsonSafeValue("URLSearchParams", value.toString());
595
+ if (value instanceof Headers) return jsonSafeValue("Headers", [...value.entries()]);
596
+ if (value instanceof File) return jsonSafeValue("File", {
597
+ bytes: await blobToBase64(value),
373
598
  lastModified: value.lastModified,
374
599
  name: value.name,
375
- size: value.size,
376
600
  type: value.type
377
- })}`;
378
- if (isBlob$1(value)) return `$blob:${getCompositeKey({
379
- size: value.size,
601
+ });
602
+ if (value instanceof Blob) return jsonSafeValue("Blob", {
603
+ bytes: await blobToBase64(value),
380
604
  type: value.type
381
- })}`;
382
- }
383
- async function materializeAsyncCacheKeyValue(value, refs = /* @__PURE__ */ new WeakSet()) {
384
- const serialized = await stringifyAsyncCacheKeyValue(value);
385
- if (serialized !== void 0) return new SerializedCacheKeyValue(serialized);
386
- if (stringifyCacheKeyValue(value) !== void 0) return value;
605
+ });
606
+ if (value instanceof ArrayBuffer) return jsonSafeValue("ArrayBuffer", bytesToBase64(new Uint8Array(value)));
607
+ if (value instanceof Error) return serializeError(value, refs, depth);
387
608
  if (!value || typeof value !== "object") return value;
388
- if (Array.isArray(value)) {
389
- const items = [];
390
- for (const item of value) items.push(await materializeAsyncCacheKeyValue(item, refs));
391
- return items;
392
- }
393
- if (refs.has(value)) throw new Error("Circular reference detected");
609
+ if (refs.has(value)) throw new Error("Circular cache values are not supported");
394
610
  refs.add(value);
395
- const entries = [];
396
- for (const [key, entryValue] of Object.entries(value)) entries.push([key, await materializeAsyncCacheKeyValue(entryValue, refs)]);
397
- refs.delete(value);
398
- return Object.fromEntries(entries);
399
- }
400
- async function stringifyAsyncCacheKeyValue(value) {
401
- if (isFile$1(value)) return `$file:${getCompositeKey({
402
- bytes: await hashBlobBytes(value),
403
- lastModified: value.lastModified,
404
- name: value.name,
405
- size: value.size,
406
- type: value.type
407
- })}`;
408
- if (isBlob$1(value)) return `$blob:${getCompositeKey({
409
- bytes: await hashBlobBytes(value),
410
- size: value.size,
411
- type: value.type
412
- })}`;
413
- }
414
- async function hashBlobBytes(value) {
415
- return hashBytes(new Uint8Array(await value.arrayBuffer()));
416
- }
417
- function hashBytes(value) {
418
- return createHash("sha256").update(value).digest("hex");
419
- }
420
- function isArrayBuffer(value) {
421
- return value instanceof ArrayBuffer;
422
- }
423
- function isSharedArrayBuffer(value) {
424
- return value instanceof SharedArrayBuffer;
425
- }
426
- function isArrayBufferView(value) {
427
- return ArrayBuffer.isView(value);
428
- }
429
- function isBlob$1(value) {
430
- return value instanceof Blob;
431
- }
432
- function isFile$1(value) {
433
- return value instanceof File;
434
- }
435
- //#endregion
436
- //#region ../../node_modules/.pnpm/seroval@1.5.2/node_modules/seroval/dist/esm/production/index.mjs
437
- var L$1 = ((i) => (i[i.AggregateError = 1] = "AggregateError", i[i.ArrowFunction = 2] = "ArrowFunction", i[i.ErrorPrototypeStack = 4] = "ErrorPrototypeStack", i[i.ObjectAssign = 8] = "ObjectAssign", i[i.BigIntTypedArray = 16] = "BigIntTypedArray", i[i.RegExp = 32] = "RegExp", i))(L$1 || {});
438
- var v$1 = Symbol.asyncIterator, mr = Symbol.hasInstance, R = Symbol.isConcatSpreadable, C = Symbol.iterator, pr = Symbol.match, dr = Symbol.matchAll, gr = Symbol.replace, yr = Symbol.search, Nr = Symbol.species, br = Symbol.split, vr = Symbol.toPrimitive, P$1 = Symbol.toStringTag, Cr = Symbol.unscopables, ve = {
439
- [v$1]: 0,
440
- [mr]: 1,
441
- [R]: 2,
442
- [C]: 3,
443
- [pr]: 4,
444
- [dr]: 5,
445
- [gr]: 6,
446
- [yr]: 7,
447
- [Nr]: 8,
448
- [br]: 9,
449
- [vr]: 10,
450
- [P$1]: 11,
451
- [Cr]: 12
452
- }, tt = {
453
- 0: v$1,
454
- 1: mr,
455
- 2: R,
456
- 3: C,
457
- 4: pr,
458
- 5: dr,
459
- 6: gr,
460
- 7: yr,
461
- 8: Nr,
462
- 9: br,
463
- 10: vr,
464
- 11: P$1,
465
- 12: Cr
466
- }, o$1 = void 0, ot = {
467
- 2: !0,
468
- 3: !1,
469
- 1: o$1,
470
- 0: null,
471
- 4: -0,
472
- 5: Number.POSITIVE_INFINITY,
473
- 6: Number.NEGATIVE_INFINITY,
474
- 7: NaN
475
- };
476
- var Ce = {
477
- 0: "Error",
478
- 1: "EvalError",
479
- 2: "RangeError",
480
- 3: "ReferenceError",
481
- 4: "SyntaxError",
482
- 5: "TypeError",
483
- 6: "URIError"
484
- }, at = {
485
- 0: Error,
486
- 1: EvalError,
487
- 2: RangeError,
488
- 3: ReferenceError,
489
- 4: SyntaxError,
490
- 5: TypeError,
491
- 6: URIError
492
- };
493
- function c$1(e, r, t, n, a, s, i, u, l, g, S, d) {
494
- return {
495
- t: e,
496
- i: r,
497
- s: t,
498
- c: n,
499
- m: a,
500
- p: s,
501
- e: i,
502
- a: u,
503
- f: l,
504
- b: g,
505
- o: S,
506
- l: d
507
- };
508
- }
509
- function B$1(e) {
510
- return c$1(2, o$1, e, o$1, o$1, o$1, o$1, o$1, o$1, o$1, o$1, o$1);
511
- }
512
- var J = B$1(2), Z = B$1(3), Ae = B$1(1), Ee = B$1(0), st = B$1(4), it = B$1(5), ut = B$1(6), lt = B$1(7);
513
- function fn(e) {
514
- switch (e) {
515
- case "\"": return "\\\"";
516
- case "\\": return "\\\\";
517
- case `
518
- `: return "\\n";
519
- case "\r": return "\\r";
520
- case "\b": return "\\b";
521
- case " ": return "\\t";
522
- case "\f": return "\\f";
523
- case "<": return "\\x3C";
524
- case "\u2028": return "\\u2028";
525
- case "\u2029": return "\\u2029";
526
- default: return o$1;
527
- }
528
- }
529
- function y$1(e) {
530
- let r = "", t = 0, n;
531
- for (let a = 0, s = e.length; a < s; a++) n = fn(e[a]), n && (r += e.slice(t, a) + n, t = a + 1);
532
- return t === 0 ? r = e : r += e.slice(t), r;
533
- }
534
- function Sn(e) {
535
- switch (e) {
536
- case "\\\\": return "\\";
537
- case "\\\"": return "\"";
538
- case "\\n": return `
539
- `;
540
- case "\\r": return "\r";
541
- case "\\b": return "\b";
542
- case "\\t": return " ";
543
- case "\\f": return "\f";
544
- case "\\x3C": return "<";
545
- case "\\u2028": return "\u2028";
546
- case "\\u2029": return "\u2029";
547
- default: return e;
548
- }
549
- }
550
- function D$1(e) {
551
- return e.replace(/(\\\\|\\"|\\n|\\r|\\b|\\t|\\f|\\u2028|\\u2029|\\x3C)/g, Sn);
552
- }
553
- var U = "__SEROVAL_REFS__";
554
- var Ar = /* @__PURE__ */ new Map(), j = /* @__PURE__ */ new Map();
555
- function Er(e) {
556
- return Ar.has(e);
557
- }
558
- function dn(e) {
559
- return j.has(e);
560
- }
561
- function ct(e) {
562
- if (Er(e)) return Ar.get(e);
563
- throw new Re(e);
564
- }
565
- function ft(e) {
566
- if (dn(e)) return j.get(e);
567
- throw new Pe(e);
568
- }
569
- typeof globalThis != "undefined" ? Object.defineProperty(globalThis, U, {
570
- value: j,
571
- configurable: !0,
572
- writable: !1,
573
- enumerable: !1
574
- }) : typeof window != "undefined" ? Object.defineProperty(window, U, {
575
- value: j,
576
- configurable: !0,
577
- writable: !1,
578
- enumerable: !1
579
- }) : typeof self != "undefined" ? Object.defineProperty(self, U, {
580
- value: j,
581
- configurable: !0,
582
- writable: !1,
583
- enumerable: !1
584
- }) : typeof global != "undefined" && Object.defineProperty(global, U, {
585
- value: j,
586
- configurable: !0,
587
- writable: !1,
588
- enumerable: !1
589
- });
590
- function xe(e) {
591
- return e instanceof EvalError ? 1 : e instanceof RangeError ? 2 : e instanceof ReferenceError ? 3 : e instanceof SyntaxError ? 4 : e instanceof TypeError ? 5 : e instanceof URIError ? 6 : 0;
592
- }
593
- function gn(e) {
594
- let r = Ce[xe(e)];
595
- return e.name !== r ? { name: e.name } : e.constructor.name !== r ? { name: e.constructor.name } : {};
596
- }
597
- function $$1(e, r) {
598
- let t = gn(e), n = Object.getOwnPropertyNames(e);
599
- for (let a = 0, s = n.length, i; a < s; a++) i = n[a], i !== "name" && i !== "message" && (i === "stack" ? r & 4 && (t = t || {}, t[i] = e[i]) : (t = t || {}, t[i] = e[i]));
600
- return t;
601
- }
602
- function Oe(e) {
603
- return Object.isFrozen(e) ? 3 : Object.isSealed(e) ? 2 : Object.isExtensible(e) ? 0 : 1;
604
- }
605
- function Te(e) {
606
- switch (e) {
607
- case Number.POSITIVE_INFINITY: return it;
608
- case Number.NEGATIVE_INFINITY: return ut;
609
- }
610
- return e !== e ? lt : Object.is(e, -0) ? st : c$1(0, o$1, e, o$1, o$1, o$1, o$1, o$1, o$1, o$1, o$1, o$1);
611
- }
612
- function X(e) {
613
- return c$1(1, o$1, y$1(e), o$1, o$1, o$1, o$1, o$1, o$1, o$1, o$1, o$1);
614
- }
615
- function we(e) {
616
- return c$1(3, o$1, "" + e, o$1, o$1, o$1, o$1, o$1, o$1, o$1, o$1, o$1);
617
- }
618
- function mt(e) {
619
- return c$1(4, e, o$1, o$1, o$1, o$1, o$1, o$1, o$1, o$1, o$1, o$1);
620
- }
621
- function he(e, r) {
622
- let t = r.valueOf();
623
- return c$1(5, e, t !== t ? "" : r.toISOString(), o$1, o$1, o$1, o$1, o$1, o$1, o$1, o$1, o$1);
624
- }
625
- function ze(e, r) {
626
- return c$1(6, e, o$1, y$1(r.source), r.flags, o$1, o$1, o$1, o$1, o$1, o$1, o$1);
627
- }
628
- function pt(e, r) {
629
- return c$1(17, e, ve[r], o$1, o$1, o$1, o$1, o$1, o$1, o$1, o$1, o$1);
630
- }
631
- function dt(e, r) {
632
- return c$1(18, e, y$1(ct(r)), o$1, o$1, o$1, o$1, o$1, o$1, o$1, o$1, o$1);
633
- }
634
- function fe$1(e, r, t) {
635
- return c$1(25, e, t, y$1(r), o$1, o$1, o$1, o$1, o$1, o$1, o$1, o$1);
636
- }
637
- function _e(e, r, t) {
638
- return c$1(9, e, o$1, o$1, o$1, o$1, o$1, t, o$1, o$1, Oe(r), o$1);
639
- }
640
- function ke(e, r) {
641
- return c$1(21, e, o$1, o$1, o$1, o$1, o$1, o$1, r, o$1, o$1, o$1);
642
- }
643
- function De(e, r, t) {
644
- return c$1(15, e, o$1, r.constructor.name, o$1, o$1, o$1, o$1, t, r.byteOffset, o$1, r.length);
645
- }
646
- function Fe(e, r, t) {
647
- return c$1(16, e, o$1, r.constructor.name, o$1, o$1, o$1, o$1, t, r.byteOffset, o$1, r.byteLength);
648
- }
649
- function Be(e, r, t) {
650
- return c$1(20, e, o$1, o$1, o$1, o$1, o$1, o$1, t, r.byteOffset, o$1, r.byteLength);
651
- }
652
- function Ve(e, r, t) {
653
- return c$1(13, e, xe(r), o$1, y$1(r.message), t, o$1, o$1, o$1, o$1, o$1, o$1);
654
- }
655
- function Me(e, r, t) {
656
- return c$1(14, e, xe(r), o$1, y$1(r.message), t, o$1, o$1, o$1, o$1, o$1, o$1);
657
- }
658
- function Le(e, r) {
659
- return c$1(7, e, o$1, o$1, o$1, o$1, o$1, r, o$1, o$1, o$1, o$1);
660
- }
661
- function Ue(e, r) {
662
- return c$1(28, o$1, o$1, o$1, o$1, o$1, o$1, [e, r], o$1, o$1, o$1, o$1);
663
- }
664
- function je(e, r) {
665
- return c$1(30, o$1, o$1, o$1, o$1, o$1, o$1, [e, r], o$1, o$1, o$1, o$1);
666
- }
667
- function Ye(e, r, t) {
668
- return c$1(31, e, o$1, o$1, o$1, o$1, o$1, t, r, o$1, o$1, o$1);
669
- }
670
- function qe(e, r) {
671
- return c$1(32, e, o$1, o$1, o$1, o$1, o$1, o$1, r, o$1, o$1, o$1);
672
- }
673
- function We(e, r) {
674
- return c$1(33, e, o$1, o$1, o$1, o$1, o$1, o$1, r, o$1, o$1, o$1);
675
- }
676
- function Ge(e, r) {
677
- return c$1(34, e, o$1, o$1, o$1, o$1, o$1, o$1, r, o$1, o$1, o$1);
678
- }
679
- function Ke(e, r, t, n) {
680
- return c$1(35, e, t, o$1, o$1, o$1, o$1, r, o$1, o$1, o$1, n);
681
- }
682
- var { toString: ys } = Object.prototype;
683
- var yn = {
684
- parsing: 1,
685
- serialization: 2,
686
- deserialization: 3
687
- };
688
- function Nn(e) {
689
- return `Seroval Error (step: ${yn[e]})`;
690
- }
691
- var bn = (e, r) => Nn(e), Se = class extends Error {
692
- constructor(t, n) {
693
- super(bn(t, n));
694
- this.cause = n;
695
- }
696
- }, z$2 = class extends Se {
697
- constructor(r) {
698
- super("parsing", r);
699
- }
700
- }, He = class extends Se {
701
- constructor(r) {
702
- super("deserialization", r);
703
- }
704
- };
705
- function _(e) {
706
- return `Seroval Error (specific: ${e})`;
707
- }
708
- var x$1 = class extends Error {
709
- constructor(t) {
710
- super(_(1));
711
- this.value = t;
712
- }
713
- }, w$1 = class extends Error {
714
- constructor(r) {
715
- super(_(2));
716
- }
717
- }, Q = class extends Error {
718
- constructor(r) {
719
- super(_(3));
720
- }
721
- }, V = class extends Error {
722
- constructor(r) {
723
- super(_(4));
724
- }
725
- }, Re = class extends Error {
726
- constructor(t) {
727
- super(_(5));
728
- this.value = t;
729
- }
730
- }, Pe = class extends Error {
731
- constructor(r) {
732
- super(_(6));
733
- }
734
- }, Je = class extends Error {
735
- constructor(r) {
736
- super(_(7));
737
- }
738
- }, h$1 = class extends Error {
739
- constructor(r) {
740
- super(_(8));
741
- }
742
- }, ee = class extends Error {
743
- constructor(r) {
744
- super(_(9));
745
- }
746
- }, Y$1 = class {
747
- constructor(r, t) {
748
- this.value = r;
749
- this.replacement = t;
750
- }
751
- }, re = () => {
752
- let e = {
753
- p: 0,
754
- s: 0,
755
- f: 0
756
- };
757
- return e.p = new Promise((r, t) => {
758
- e.s = r, e.f = t;
759
- }), e;
760
- }, vn = (e, r) => {
761
- e.s(r), e.p.s = 1, e.p.v = r;
762
- }, Cn = (e, r) => {
763
- e.f(r), e.p.s = 2, e.p.v = r;
764
- };
765
- re.toString();
766
- vn.toString();
767
- Cn.toString();
768
- var Rr = () => {
769
- let e = [], r = [], t = !0, n = !1, a = 0, s = (l, g, S) => {
770
- for (S = 0; S < a; S++) r[S] && r[S][g](l);
771
- }, i = (l, g, S, d) => {
772
- for (g = 0, S = e.length; g < S; g++) d = e[g], !t && g === S - 1 ? l[n ? "return" : "throw"](d) : l.next(d);
773
- }, u = (l, g) => (t && (g = a++, r[g] = l), i(l), () => {
774
- t && (r[g] = r[a], r[a--] = void 0);
775
- });
776
- return {
777
- __SEROVAL_STREAM__: !0,
778
- on: (l) => u(l),
779
- next: (l) => {
780
- t && (e.push(l), s(l, "next"));
781
- },
782
- throw: (l) => {
783
- t && (e.push(l), s(l, "throw"), t = !1, n = !1, r.length = 0);
784
- },
785
- return: (l) => {
786
- t && (e.push(l), s(l, "return"), t = !1, n = !0, r.length = 0);
787
- }
788
- };
789
- };
790
- Rr.toString();
791
- var Pr = (e) => (r) => () => {
792
- let t = 0, n = {
793
- [e]: () => n,
794
- next: () => {
795
- if (t > r.d) return {
796
- done: !0,
797
- value: void 0
798
- };
799
- let a = t++, s = r.v[a];
800
- if (a === r.t) throw s;
801
- return {
802
- done: a === r.d,
803
- value: s
804
- };
805
- }
806
- };
807
- return n;
808
- };
809
- Pr.toString();
810
- var xr = (e, r) => (t) => () => {
811
- let n = 0, a = -1, s = !1, i = [], u = [], l = (S = 0, d = u.length) => {
812
- for (; S < d; S++) u[S].s({
813
- done: !0,
814
- value: void 0
815
- });
816
- };
817
- t.on({
818
- next: (S) => {
819
- let d = u.shift();
820
- d && d.s({
821
- done: !1,
822
- value: S
823
- }), i.push(S);
824
- },
825
- throw: (S) => {
826
- let d = u.shift();
827
- d && d.f(S), l(), a = i.length, s = !0, i.push(S);
828
- },
829
- return: (S) => {
830
- let d = u.shift();
831
- d && d.s({
832
- done: !0,
833
- value: S
834
- }), l(), a = i.length, i.push(S);
835
- }
836
- });
837
- let g = {
838
- [e]: () => g,
839
- next: () => {
840
- if (a === -1) {
841
- let K = n++;
842
- if (K >= i.length) {
843
- let et = r();
844
- return u.push(et), et.p;
845
- }
846
- return {
847
- done: !1,
848
- value: i[K]
849
- };
611
+ if (Array.isArray(value)) {
612
+ if (depth > 0 && value.length >= packedNumberArrayMinLength && isDenseNumberArray(value)) {
613
+ const packed = packNumberArray(value);
614
+ if (packed !== void 0) {
615
+ refs.delete(value);
616
+ return packed;
850
617
  }
851
- if (n > a) return {
852
- done: !0,
853
- value: void 0
854
- };
855
- let S = n++, d = i[S];
856
- if (S !== a) return {
857
- done: !1,
858
- value: d
859
- };
860
- if (s) throw d;
861
- return {
862
- done: !0,
863
- value: d
864
- };
865
- }
866
- };
867
- return g;
868
- };
869
- xr.toString();
870
- var Or = (e) => {
871
- let r = atob(e), t = r.length, n = new Uint8Array(t);
872
- for (let a = 0; a < t; a++) n[a] = r.charCodeAt(a);
873
- return n.buffer;
874
- };
875
- Or.toString();
876
- function Ze(e) {
877
- return "__SEROVAL_SEQUENCE__" in e;
878
- }
879
- function Tr(e, r, t) {
880
- return {
881
- __SEROVAL_SEQUENCE__: !0,
882
- v: e,
883
- t: r,
884
- d: t
885
- };
886
- }
887
- function $e(e) {
888
- let r = [], t = -1, n = -1, a = e[C]();
889
- for (;;) try {
890
- let s = a.next();
891
- if (r.push(s.value), s.done) {
892
- n = r.length - 1;
893
- break;
894
- }
895
- } catch (s) {
896
- t = r.length, r.push(s);
897
- }
898
- return Tr(r, t, n);
899
- }
900
- var An = Pr(C);
901
- function It(e) {
902
- return An(e);
903
- }
904
- var Rt = {}, Pt = {}, xt = {
905
- 0: {},
906
- 1: {},
907
- 2: {},
908
- 3: {},
909
- 4: {},
910
- 5: {}
911
- };
912
- function M(e) {
913
- return "__SEROVAL_STREAM__" in e;
914
- }
915
- function te$1() {
916
- return Rr();
917
- }
918
- function Xe(e) {
919
- let r = te$1(), t = e[v$1]();
920
- async function n() {
921
- try {
922
- let a = await t.next();
923
- a.done ? r.return(a.value) : (r.next(a.value), await n());
924
- } catch (a) {
925
- r.throw(a);
926
- }
927
- }
928
- return n().catch(() => {}), r;
929
- }
930
- var En = xr(v$1, re);
931
- function Tt(e) {
932
- return En(e);
933
- }
934
- async function wr(e) {
935
- try {
936
- return [1, await e];
937
- } catch (r) {
938
- return [0, r];
939
- }
940
- }
941
- function pe$1(e, r) {
942
- return {
943
- plugins: r.plugins,
944
- mode: e,
945
- marked: /* @__PURE__ */ new Set(),
946
- features: 63 ^ (r.disabledFeatures || 0),
947
- refs: r.refs || /* @__PURE__ */ new Map(),
948
- depthLimit: r.depthLimit || 1e3
949
- };
950
- }
951
- function de(e, r) {
952
- e.marked.add(r);
953
- }
954
- function hr(e, r) {
955
- let t = e.refs.size;
956
- return e.refs.set(r, t), t;
957
- }
958
- function Qe(e, r) {
959
- let t = e.refs.get(r);
960
- return t != null ? (de(e, t), {
961
- type: 1,
962
- value: mt(t)
963
- }) : {
964
- type: 0,
965
- value: hr(e, r)
966
- };
967
- }
968
- function q$1(e, r) {
969
- let t = Qe(e, r);
970
- return t.type === 1 ? t : Er(r) ? {
971
- type: 2,
972
- value: dt(t.value, r)
973
- } : t;
974
- }
975
- function I(e, r) {
976
- let t = q$1(e, r);
977
- if (t.type !== 0) return t.value;
978
- if (r in ve) return pt(t.value, r);
979
- throw new x$1(r);
980
- }
981
- function k(e, r) {
982
- let t = Qe(e, xt[r]);
983
- return t.type === 1 ? t.value : c$1(26, t.value, r, o$1, o$1, o$1, o$1, o$1, o$1, o$1, o$1, o$1);
984
- }
985
- function er(e) {
986
- let r = Qe(e, Rt);
987
- return r.type === 1 ? r.value : c$1(27, r.value, o$1, o$1, o$1, o$1, o$1, o$1, I(e, C), o$1, o$1, o$1);
988
- }
989
- function rr(e) {
990
- let r = Qe(e, Pt);
991
- return r.type === 1 ? r.value : c$1(29, r.value, o$1, o$1, o$1, o$1, o$1, [k(e, 1), I(e, v$1)], o$1, o$1, o$1, o$1);
992
- }
993
- function tr(e, r, t, n) {
994
- return c$1(t ? 11 : 10, e, o$1, o$1, o$1, n, o$1, o$1, o$1, o$1, Oe(r), o$1);
995
- }
996
- function nr(e, r, t, n) {
997
- return c$1(8, r, o$1, o$1, o$1, o$1, {
998
- k: t,
999
- v: n
1000
- }, o$1, k(e, 0), o$1, o$1, o$1);
1001
- }
1002
- function or(e, r, t) {
1003
- let n = new Uint8Array(t), a = "";
1004
- for (let s = 0, i = n.length; s < i; s++) a += String.fromCharCode(n[s]);
1005
- return c$1(19, r, y$1(btoa(a)), o$1, o$1, o$1, o$1, o$1, k(e, 5), o$1, o$1, o$1);
1006
- }
1007
- function ne$1(e, r) {
1008
- return {
1009
- base: pe$1(e, r),
1010
- child: void 0
1011
- };
1012
- }
1013
- var _r = class {
1014
- constructor(r, t) {
1015
- this._p = r;
1016
- this.depth = t;
1017
- }
1018
- parse(r) {
1019
- return N$1(this._p, this.depth, r);
1020
- }
1021
- };
1022
- async function Rn(e, r, t) {
1023
- let n = [];
1024
- for (let a = 0, s = t.length; a < s; a++) a in t ? n[a] = await N$1(e, r, t[a]) : n[a] = 0;
1025
- return n;
1026
- }
1027
- async function Pn(e, r, t, n) {
1028
- return _e(t, n, await Rn(e, r, n));
1029
- }
1030
- async function kr(e, r, t) {
1031
- let n = Object.entries(t), a = [], s = [];
1032
- for (let i = 0, u = n.length; i < u; i++) a.push(y$1(n[i][0])), s.push(await N$1(e, r, n[i][1]));
1033
- return C in t && (a.push(I(e.base, C)), s.push(Ue(er(e.base), await N$1(e, r, $e(t))))), v$1 in t && (a.push(I(e.base, v$1)), s.push(je(rr(e.base), await N$1(e, r, Xe(t))))), P$1 in t && (a.push(I(e.base, P$1)), s.push(X(t[P$1]))), R in t && (a.push(I(e.base, R)), s.push(t[R] ? J : Z)), {
1034
- k: a,
1035
- v: s
1036
- };
1037
- }
1038
- async function zr(e, r, t, n, a) {
1039
- return tr(t, n, a, await kr(e, r, n));
1040
- }
1041
- async function xn(e, r, t, n) {
1042
- return ke(t, await N$1(e, r, n.valueOf()));
1043
- }
1044
- async function On(e, r, t, n) {
1045
- return De(t, n, await N$1(e, r, n.buffer));
1046
- }
1047
- async function Tn(e, r, t, n) {
1048
- return Fe(t, n, await N$1(e, r, n.buffer));
1049
- }
1050
- async function wn(e, r, t, n) {
1051
- return Be(t, n, await N$1(e, r, n.buffer));
1052
- }
1053
- async function zt(e, r, t, n) {
1054
- let a = $$1(n, e.base.features);
1055
- return Ve(t, n, a ? await kr(e, r, a) : o$1);
1056
- }
1057
- async function hn(e, r, t, n) {
1058
- let a = $$1(n, e.base.features);
1059
- return Me(t, n, a ? await kr(e, r, a) : o$1);
1060
- }
1061
- async function zn(e, r, t, n) {
1062
- let a = [], s = [];
1063
- for (let [i, u] of n.entries()) a.push(await N$1(e, r, i)), s.push(await N$1(e, r, u));
1064
- return nr(e.base, t, a, s);
1065
- }
1066
- async function _n(e, r, t, n) {
1067
- let a = [];
1068
- for (let s of n.keys()) a.push(await N$1(e, r, s));
1069
- return Le(t, a);
1070
- }
1071
- async function _t(e, r, t, n) {
1072
- let a = e.base.plugins;
1073
- if (a) for (let s = 0, i = a.length; s < i; s++) {
1074
- let u = a[s];
1075
- if (u.parse.async && u.test(n)) return fe$1(t, u.tag, await u.parse.async(n, new _r(e, r), { id: t }));
1076
- }
1077
- return o$1;
1078
- }
1079
- async function kn(e, r, t, n) {
1080
- let [a, s] = await wr(n);
1081
- return c$1(12, t, a, o$1, o$1, o$1, o$1, o$1, await N$1(e, r, s), o$1, o$1, o$1);
1082
- }
1083
- function Dn(e, r, t, n, a) {
1084
- let s = [], i = t.on({
1085
- next: (u) => {
1086
- de(this.base, r), N$1(this, e, u).then((l) => {
1087
- s.push(qe(r, l));
1088
- }, (l) => {
1089
- a(l), i();
1090
- });
1091
- },
1092
- throw: (u) => {
1093
- de(this.base, r), N$1(this, e, u).then((l) => {
1094
- s.push(We(r, l)), n(s), i();
1095
- }, (l) => {
1096
- a(l), i();
1097
- });
1098
- },
1099
- return: (u) => {
1100
- de(this.base, r), N$1(this, e, u).then((l) => {
1101
- s.push(Ge(r, l)), n(s), i();
1102
- }, (l) => {
1103
- a(l), i();
1104
- });
1105
- }
1106
- });
1107
- }
1108
- async function Fn(e, r, t, n) {
1109
- return Ye(t, k(e.base, 4), await new Promise(Dn.bind(e, r, t, n)));
1110
- }
1111
- async function Bn(e, r, t, n) {
1112
- let a = [];
1113
- for (let s = 0, i = n.v.length; s < i; s++) a[s] = await N$1(e, r, n.v[s]);
1114
- return Ke(t, a, n.t, n.d);
1115
- }
1116
- async function Vn(e, r, t, n) {
1117
- if (Array.isArray(n)) return Pn(e, r, t, n);
1118
- if (M(n)) return Fn(e, r, t, n);
1119
- if (Ze(n)) return Bn(e, r, t, n);
1120
- let a = n.constructor;
1121
- if (a === Y$1) return N$1(e, r, n.replacement);
1122
- let s = await _t(e, r, t, n);
1123
- if (s) return s;
1124
- switch (a) {
1125
- case Object: return zr(e, r, t, n, !1);
1126
- case o$1: return zr(e, r, t, n, !0);
1127
- case Date: return he(t, n);
1128
- case Error:
1129
- case EvalError:
1130
- case RangeError:
1131
- case ReferenceError:
1132
- case SyntaxError:
1133
- case TypeError:
1134
- case URIError: return zt(e, r, t, n);
1135
- case Number:
1136
- case Boolean:
1137
- case String:
1138
- case BigInt: return xn(e, r, t, n);
1139
- case ArrayBuffer: return or(e.base, t, n);
1140
- case Int8Array:
1141
- case Int16Array:
1142
- case Int32Array:
1143
- case Uint8Array:
1144
- case Uint16Array:
1145
- case Uint32Array:
1146
- case Uint8ClampedArray:
1147
- case Float32Array:
1148
- case Float64Array: return On(e, r, t, n);
1149
- case DataView: return wn(e, r, t, n);
1150
- case Map: return zn(e, r, t, n);
1151
- case Set: return _n(e, r, t, n);
1152
- default: break;
1153
- }
1154
- if (a === Promise || n instanceof Promise) return kn(e, r, t, n);
1155
- let i = e.base.features;
1156
- if (i & 32 && a === RegExp) return ze(t, n);
1157
- if (i & 16) switch (a) {
1158
- case BigInt64Array:
1159
- case BigUint64Array: return Tn(e, r, t, n);
1160
- default: break;
1161
- }
1162
- if (i & 1 && typeof AggregateError != "undefined" && (a === AggregateError || n instanceof AggregateError)) return hn(e, r, t, n);
1163
- if (n instanceof Error) return zt(e, r, t, n);
1164
- if (C in n || v$1 in n) return zr(e, r, t, n, !!a);
1165
- throw new x$1(n);
1166
- }
1167
- async function Mn(e, r, t) {
1168
- let n = q$1(e.base, t);
1169
- if (n.type !== 0) return n.value;
1170
- let a = await _t(e, r, n.value, t);
1171
- if (a) return a;
1172
- throw new x$1(t);
1173
- }
1174
- async function N$1(e, r, t) {
1175
- switch (typeof t) {
1176
- case "boolean": return t ? J : Z;
1177
- case "undefined": return Ae;
1178
- case "string": return X(t);
1179
- case "number": return Te(t);
1180
- case "bigint": return we(t);
1181
- case "object":
1182
- if (t) {
1183
- let n = q$1(e.base, t);
1184
- return n.type === 0 ? await Vn(e, r + 1, n.value, t) : n.value;
1185
- }
1186
- return Ee;
1187
- case "symbol": return I(e.base, t);
1188
- case "function": return Mn(e, r, t);
1189
- default: throw new x$1(t);
1190
- }
1191
- }
1192
- async function oe(e, r) {
1193
- try {
1194
- return await N$1(e, 0, r);
1195
- } catch (t) {
1196
- throw t instanceof z$2 ? t : new z$2(t);
1197
- }
1198
- }
1199
- var ae = ((t) => (t[t.Vanilla = 1] = "Vanilla", t[t.Cross = 2] = "Cross", t))(ae || {});
1200
- function ni(e) {
1201
- return e;
1202
- }
1203
- function kt(e, r) {
1204
- for (let t = 0, n = r.length; t < n; t++) {
1205
- let a = r[t];
1206
- e.has(a) || (e.add(a), a.extends && kt(e, a.extends));
1207
- }
1208
- }
1209
- function A(e) {
1210
- if (e) {
1211
- let r = /* @__PURE__ */ new Set();
1212
- return kt(r, e), [...r];
1213
- }
1214
- }
1215
- function Dt(e) {
1216
- switch (e) {
1217
- case "Int8Array": return Int8Array;
1218
- case "Int16Array": return Int16Array;
1219
- case "Int32Array": return Int32Array;
1220
- case "Uint8Array": return Uint8Array;
1221
- case "Uint16Array": return Uint16Array;
1222
- case "Uint32Array": return Uint32Array;
1223
- case "Uint8ClampedArray": return Uint8ClampedArray;
1224
- case "Float32Array": return Float32Array;
1225
- case "Float64Array": return Float64Array;
1226
- case "BigInt64Array": return BigInt64Array;
1227
- case "BigUint64Array": return BigUint64Array;
1228
- default: throw new Je(e);
1229
- }
1230
- }
1231
- var Ln = 1e6, Un = 1e4, jn = 2e4;
1232
- function Bt(e, r) {
1233
- switch (r) {
1234
- case 3: return Object.freeze(e);
1235
- case 1: return Object.preventExtensions(e);
1236
- case 2: return Object.seal(e);
1237
- default: return e;
1238
- }
1239
- }
1240
- var Yn = 1e3;
1241
- function Vt(e, r) {
1242
- var t;
1243
- return {
1244
- mode: e,
1245
- plugins: r.plugins,
1246
- refs: r.refs || /* @__PURE__ */ new Map(),
1247
- features: (t = r.features) != null ? t : 63 ^ (r.disabledFeatures || 0),
1248
- depthLimit: r.depthLimit || Yn
1249
- };
1250
- }
1251
- function Mt(e) {
1252
- return {
1253
- mode: 1,
1254
- base: Vt(1, e),
1255
- child: o$1,
1256
- state: { marked: new Set(e.markedRefs) }
1257
- };
1258
- }
1259
- var Dr = class {
1260
- constructor(r, t) {
1261
- this._p = r;
1262
- this.depth = t;
1263
- }
1264
- deserialize(r) {
1265
- return p$1(this._p, this.depth, r);
1266
- }
1267
- };
1268
- function Ut(e, r) {
1269
- if (r < 0 || !Number.isFinite(r) || !Number.isInteger(r)) throw new h$1({
1270
- t: 4,
1271
- i: r
1272
- });
1273
- if (e.refs.has(r)) throw new Error("Conflicted ref id: " + r);
1274
- }
1275
- function qn(e, r, t) {
1276
- return Ut(e.base, r), e.state.marked.has(r) && e.base.refs.set(r, t), t;
1277
- }
1278
- function Wn(e, r, t) {
1279
- return Ut(e.base, r), e.base.refs.set(r, t), t;
1280
- }
1281
- function b(e, r, t) {
1282
- return e.mode === 1 ? qn(e, r, t) : Wn(e, r, t);
1283
- }
1284
- function Fr(e, r, t) {
1285
- if (Object.hasOwn(r, t)) return r[t];
1286
- throw new h$1(e);
1287
- }
1288
- function Gn(e, r) {
1289
- return b(e, r.i, ft(D$1(r.s)));
1290
- }
1291
- function Kn(e, r, t) {
1292
- let n = t.a, a = n.length, s = b(e, t.i, new Array(a));
1293
- for (let i = 0, u; i < a; i++) u = n[i], u && (s[i] = p$1(e, r, u));
1294
- return Bt(s, t.o), s;
1295
- }
1296
- function Hn(e) {
1297
- switch (e) {
1298
- case "constructor":
1299
- case "__proto__":
1300
- case "prototype":
1301
- case "__defineGetter__":
1302
- case "__defineSetter__":
1303
- case "__lookupGetter__":
1304
- case "__lookupSetter__": return !1;
1305
- default: return !0;
1306
- }
1307
- }
1308
- function Jn(e) {
1309
- switch (e) {
1310
- case v$1:
1311
- case R:
1312
- case P$1:
1313
- case C: return !0;
1314
- default: return !1;
1315
- }
1316
- }
1317
- function Ft(e, r, t) {
1318
- Hn(r) ? e[r] = t : Object.defineProperty(e, r, {
1319
- value: t,
1320
- configurable: !0,
1321
- enumerable: !0,
1322
- writable: !0
1323
- });
1324
- }
1325
- function Zn(e, r, t, n, a) {
1326
- if (typeof n == "string") Ft(t, D$1(n), p$1(e, r, a));
1327
- else {
1328
- let s = p$1(e, r, n);
1329
- switch (typeof s) {
1330
- case "string":
1331
- Ft(t, s, p$1(e, r, a));
1332
- break;
1333
- case "symbol":
1334
- Jn(s) && (t[s] = p$1(e, r, a));
1335
- break;
1336
- default: throw new h$1(n);
1337
- }
1338
- }
1339
- }
1340
- function jt(e, r, t, n) {
1341
- let a = t.k;
1342
- if (a.length > 0) for (let i = 0, u = t.v, l = a.length; i < l; i++) Zn(e, r, n, a[i], u[i]);
1343
- return n;
1344
- }
1345
- function $n(e, r, t) {
1346
- let n = b(e, t.i, t.t === 10 ? {} : Object.create(null));
1347
- return jt(e, r, t.p, n), Bt(n, t.o), n;
1348
- }
1349
- function Xn(e, r) {
1350
- return b(e, r.i, new Date(r.s));
1351
- }
1352
- function Qn(e, r) {
1353
- if (e.base.features & 32) {
1354
- let t = D$1(r.c);
1355
- if (t.length > jn) throw new h$1(r);
1356
- return b(e, r.i, new RegExp(t, r.m));
1357
- }
1358
- throw new w$1(r);
1359
- }
1360
- function eo(e, r, t) {
1361
- let n = b(e, t.i, /* @__PURE__ */ new Set());
1362
- for (let a = 0, s = t.a, i = s.length; a < i; a++) n.add(p$1(e, r, s[a]));
1363
- return n;
1364
- }
1365
- function ro(e, r, t) {
1366
- let n = b(e, t.i, /* @__PURE__ */ new Map());
1367
- for (let a = 0, s = t.e.k, i = t.e.v, u = s.length; a < u; a++) n.set(p$1(e, r, s[a]), p$1(e, r, i[a]));
1368
- return n;
1369
- }
1370
- function to(e, r) {
1371
- if (r.s.length > Ln) throw new h$1(r);
1372
- return b(e, r.i, Or(D$1(r.s)));
1373
- }
1374
- function no(e, r, t) {
1375
- var u;
1376
- let n = Dt(t.c), a = p$1(e, r, t.f), s = (u = t.b) != null ? u : 0;
1377
- if (s < 0 || s > a.byteLength) throw new h$1(t);
1378
- return b(e, t.i, new n(a, s, t.l));
1379
- }
1380
- function oo(e, r, t) {
1381
- var i;
1382
- let n = p$1(e, r, t.f), a = (i = t.b) != null ? i : 0;
1383
- if (a < 0 || a > n.byteLength) throw new h$1(t);
1384
- return b(e, t.i, new DataView(n, a, t.l));
1385
- }
1386
- function Yt(e, r, t, n) {
1387
- if (t.p) {
1388
- let a = jt(e, r, t.p, {});
1389
- Object.defineProperties(n, Object.getOwnPropertyDescriptors(a));
1390
- }
1391
- return n;
1392
- }
1393
- function ao(e, r, t) {
1394
- return Yt(e, r, t, b(e, t.i, new AggregateError([], D$1(t.m))));
1395
- }
1396
- function so(e, r, t) {
1397
- let n = Fr(t, at, t.s);
1398
- return Yt(e, r, t, b(e, t.i, new n(D$1(t.m))));
1399
- }
1400
- function io(e, r, t) {
1401
- let n = re(), a = b(e, t.i, n.p), s = p$1(e, r, t.f);
1402
- return t.s ? n.s(s) : n.f(s), a;
1403
- }
1404
- function uo(e, r, t) {
1405
- return b(e, t.i, Object(p$1(e, r, t.f)));
1406
- }
1407
- function lo(e, r, t) {
1408
- let n = e.base.plugins;
1409
- if (n) {
1410
- let a = D$1(t.c);
1411
- for (let s = 0, i = n.length; s < i; s++) {
1412
- let u = n[s];
1413
- if (u.tag === a) return b(e, t.i, u.deserialize(t.s, new Dr(e, r), { id: t.i }));
1414
- }
1415
- }
1416
- throw new Q(t.c);
1417
- }
1418
- function co(e, r) {
1419
- return b(e, r.i, b(e, r.s, re()).p);
1420
- }
1421
- function fo(e, r, t) {
1422
- let n = e.base.refs.get(t.i);
1423
- if (n) return n.s(p$1(e, r, t.a[1])), o$1;
1424
- throw new V("Promise");
1425
- }
1426
- function So(e, r, t) {
1427
- let n = e.base.refs.get(t.i);
1428
- if (n) return n.f(p$1(e, r, t.a[1])), o$1;
1429
- throw new V("Promise");
1430
- }
1431
- function mo(e, r, t) {
1432
- p$1(e, r, t.a[0]);
1433
- return It(p$1(e, r, t.a[1]));
1434
- }
1435
- function po(e, r, t) {
1436
- p$1(e, r, t.a[0]);
1437
- return Tt(p$1(e, r, t.a[1]));
1438
- }
1439
- function go(e, r, t) {
1440
- let n = b(e, t.i, te$1()), a = t.a, s = a.length;
1441
- if (s) for (let i = 0; i < s; i++) p$1(e, r, a[i]);
1442
- return n;
1443
- }
1444
- function yo(e, r, t) {
1445
- let n = e.base.refs.get(t.i);
1446
- if (n && M(n)) return n.next(p$1(e, r, t.f)), o$1;
1447
- throw new V("Stream");
1448
- }
1449
- function No(e, r, t) {
1450
- let n = e.base.refs.get(t.i);
1451
- if (n && M(n)) return n.throw(p$1(e, r, t.f)), o$1;
1452
- throw new V("Stream");
1453
- }
1454
- function bo(e, r, t) {
1455
- let n = e.base.refs.get(t.i);
1456
- if (n && M(n)) return n.return(p$1(e, r, t.f)), o$1;
1457
- throw new V("Stream");
1458
- }
1459
- function vo(e, r, t) {
1460
- return p$1(e, r, t.f), o$1;
1461
- }
1462
- function Co(e, r, t) {
1463
- return p$1(e, r, t.a[1]), o$1;
1464
- }
1465
- function Ao(e, r, t) {
1466
- let n = b(e, t.i, Tr([], t.s, t.l));
1467
- for (let a = 0, s = t.a.length; a < s; a++) n.v[a] = p$1(e, r, t.a[a]);
1468
- return n;
1469
- }
1470
- function p$1(e, r, t) {
1471
- if (r > e.base.depthLimit) throw new ee(e.base.depthLimit);
1472
- switch (r += 1, t.t) {
1473
- case 2: return Fr(t, ot, t.s);
1474
- case 0: return Number(t.s);
1475
- case 1: return D$1(String(t.s));
1476
- case 3:
1477
- if (String(t.s).length > Un) throw new h$1(t);
1478
- return BigInt(t.s);
1479
- case 4: return e.base.refs.get(t.i);
1480
- case 18: return Gn(e, t);
1481
- case 9: return Kn(e, r, t);
1482
- case 10:
1483
- case 11: return $n(e, r, t);
1484
- case 5: return Xn(e, t);
1485
- case 6: return Qn(e, t);
1486
- case 7: return eo(e, r, t);
1487
- case 8: return ro(e, r, t);
1488
- case 19: return to(e, t);
1489
- case 16:
1490
- case 15: return no(e, r, t);
1491
- case 20: return oo(e, r, t);
1492
- case 14: return ao(e, r, t);
1493
- case 13: return so(e, r, t);
1494
- case 12: return io(e, r, t);
1495
- case 17: return Fr(t, tt, t.s);
1496
- case 21: return uo(e, r, t);
1497
- case 25: return lo(e, r, t);
1498
- case 22: return co(e, t);
1499
- case 23: return fo(e, r, t);
1500
- case 24: return So(e, r, t);
1501
- case 28: return mo(e, r, t);
1502
- case 30: return po(e, r, t);
1503
- case 31: return go(e, r, t);
1504
- case 32: return yo(e, r, t);
1505
- case 33: return No(e, r, t);
1506
- case 34: return bo(e, r, t);
1507
- case 27: return vo(e, r, t);
1508
- case 29: return Co(e, r, t);
1509
- case 35: return Ao(e, r, t);
1510
- default: throw new w$1(t);
1511
- }
1512
- }
1513
- function ar(e, r) {
1514
- try {
1515
- return p$1(e, 0, r);
1516
- } catch (t) {
1517
- throw new He(t);
1518
- }
1519
- }
1520
- var Eo = () => T, Io = Eo.toString();
1521
- /=>/.test(Io);
1522
- async function Au(e, r = {}) {
1523
- let n = ne$1(1, {
1524
- plugins: A(r.plugins),
1525
- disabledFeatures: r.disabledFeatures
1526
- });
1527
- return {
1528
- t: await oe(n, e),
1529
- f: n.base.features,
1530
- m: Array.from(n.base.marked)
1531
- };
1532
- }
1533
- function Iu(e, r = {}) {
1534
- var i;
1535
- let t = A(r.plugins), n = r.disabledFeatures || 0, a = (i = e.f) != null ? i : 63;
1536
- return ar(Mt({
1537
- plugins: t,
1538
- markedRefs: e.m,
1539
- features: a & ~n,
1540
- disabledFeatures: n
1541
- }), e.t);
1542
- }
1543
- //#endregion
1544
- //#region ../../node_modules/.pnpm/seroval-plugins@1.5.2_seroval@1.5.2/node_modules/seroval-plugins/dist/esm/production/web.mjs
1545
- var u = (e) => {
1546
- let r = new AbortController(), a = r.abort.bind(r);
1547
- return e.then(a, a), r;
1548
- };
1549
- function E(e) {
1550
- e(this.reason);
1551
- }
1552
- function D(e) {
1553
- this.addEventListener("abort", E.bind(this, e), { once: !0 });
1554
- }
1555
- function c(e) {
1556
- return new Promise(D.bind(e));
1557
- }
1558
- var i = {}, O = ni({
1559
- tag: "seroval-plugins/web/AbortSignal",
1560
- extends: [ni({
1561
- tag: "seroval-plugins/web/AbortControllerFactoryPlugin",
1562
- test(e) {
1563
- return e === i;
1564
- },
1565
- parse: {
1566
- sync() {
1567
- return i;
1568
- },
1569
- async async() {
1570
- return await Promise.resolve(i);
1571
- },
1572
- stream() {
1573
- return i;
1574
- }
1575
- },
1576
- serialize() {
1577
- return u.toString();
1578
- },
1579
- deserialize() {
1580
- return u;
1581
- }
1582
- })],
1583
- test(e) {
1584
- return typeof AbortSignal == "undefined" ? !1 : e instanceof AbortSignal;
1585
- },
1586
- parse: {
1587
- sync(e, r) {
1588
- return e.aborted ? { reason: r.parse(e.reason) } : {};
1589
- },
1590
- async async(e, r) {
1591
- if (e.aborted) return { reason: await r.parse(e.reason) };
1592
- let a = await c(e);
1593
- return { reason: await r.parse(a) };
1594
- },
1595
- stream(e, r) {
1596
- if (e.aborted) return { reason: r.parse(e.reason) };
1597
- let a = c(e);
1598
- return {
1599
- factory: r.parse(i),
1600
- controller: r.parse(a)
1601
- };
1602
- }
1603
- },
1604
- serialize(e, r) {
1605
- return e.reason ? "AbortSignal.abort(" + r.serialize(e.reason) + ")" : e.controller && e.factory ? "(" + r.serialize(e.factory) + ")(" + r.serialize(e.controller) + ").signal" : "(new AbortController).signal";
1606
- },
1607
- deserialize(e, r) {
1608
- return e.reason ? AbortSignal.abort(r.deserialize(e.reason)) : e.controller ? u(r.deserialize(e.controller)).signal : new AbortController().signal;
1609
- }
1610
- });
1611
- var B = ni({
1612
- tag: "seroval-plugins/web/Blob",
1613
- test(e) {
1614
- return typeof Blob == "undefined" ? !1 : e instanceof Blob;
1615
- },
1616
- parse: { async async(e, r) {
1617
- return {
1618
- type: await r.parse(e.type),
1619
- buffer: await r.parse(await e.arrayBuffer())
1620
- };
1621
- } },
1622
- serialize(e, r) {
1623
- return "new Blob([" + r.serialize(e.buffer) + "],{type:" + r.serialize(e.type) + "})";
1624
- },
1625
- deserialize(e, r) {
1626
- return new Blob([r.deserialize(e.buffer)], { type: r.deserialize(e.type) });
1627
- }
1628
- });
1629
- function d(e) {
1630
- return {
1631
- detail: e.detail,
1632
- bubbles: e.bubbles,
1633
- cancelable: e.cancelable,
1634
- composed: e.composed
1635
- };
1636
- }
1637
- var L = ni({
1638
- tag: "seroval-plugins/web/CustomEvent",
1639
- test(e) {
1640
- return typeof CustomEvent == "undefined" ? !1 : e instanceof CustomEvent;
1641
- },
1642
- parse: {
1643
- sync(e, r) {
1644
- return {
1645
- type: r.parse(e.type),
1646
- options: r.parse(d(e))
1647
- };
1648
- },
1649
- async async(e, r) {
1650
- return {
1651
- type: await r.parse(e.type),
1652
- options: await r.parse(d(e))
1653
- };
1654
- },
1655
- stream(e, r) {
1656
- return {
1657
- type: r.parse(e.type),
1658
- options: r.parse(d(e))
1659
- };
1660
- }
1661
- },
1662
- serialize(e, r) {
1663
- return "new CustomEvent(" + r.serialize(e.type) + "," + r.serialize(e.options) + ")";
1664
- },
1665
- deserialize(e, r) {
1666
- return new CustomEvent(r.deserialize(e.type), r.deserialize(e.options));
1667
- }
1668
- });
1669
- var q = ni({
1670
- tag: "seroval-plugins/web/DOMException",
1671
- test(e) {
1672
- return typeof DOMException == "undefined" ? !1 : e instanceof DOMException;
1673
- },
1674
- parse: {
1675
- sync(e, r) {
1676
- return {
1677
- name: r.parse(e.name),
1678
- message: r.parse(e.message)
1679
- };
1680
- },
1681
- async async(e, r) {
1682
- return {
1683
- name: await r.parse(e.name),
1684
- message: await r.parse(e.message)
1685
- };
1686
- },
1687
- stream(e, r) {
1688
- return {
1689
- name: r.parse(e.name),
1690
- message: r.parse(e.message)
1691
- };
1692
- }
1693
- },
1694
- serialize(e, r) {
1695
- return "new DOMException(" + r.serialize(e.message) + "," + r.serialize(e.name) + ")";
1696
- },
1697
- deserialize(e, r) {
1698
- return new DOMException(r.deserialize(e.message), r.deserialize(e.name));
1699
- }
1700
- });
1701
- function f(e) {
1702
- return {
1703
- bubbles: e.bubbles,
1704
- cancelable: e.cancelable,
1705
- composed: e.composed
1706
- };
1707
- }
1708
- var Y = ni({
1709
- tag: "seroval-plugins/web/Event",
1710
- test(e) {
1711
- return typeof Event == "undefined" ? !1 : e instanceof Event;
1712
- },
1713
- parse: {
1714
- sync(e, r) {
1715
- return {
1716
- type: r.parse(e.type),
1717
- options: r.parse(f(e))
1718
- };
1719
- },
1720
- async async(e, r) {
1721
- return {
1722
- type: await r.parse(e.type),
1723
- options: await r.parse(f(e))
1724
- };
1725
- },
1726
- stream(e, r) {
1727
- return {
1728
- type: r.parse(e.type),
1729
- options: r.parse(f(e))
1730
- };
1731
- }
1732
- },
1733
- serialize(e, r) {
1734
- return "new Event(" + r.serialize(e.type) + "," + r.serialize(e.options) + ")";
1735
- },
1736
- deserialize(e, r) {
1737
- return new Event(r.deserialize(e.type), r.deserialize(e.options));
1738
- }
1739
- });
1740
- var m = ni({
1741
- tag: "seroval-plugins/web/File",
1742
- test(e) {
1743
- return typeof File == "undefined" ? !1 : e instanceof File;
1744
- },
1745
- parse: { async async(e, r) {
1746
- return {
1747
- name: await r.parse(e.name),
1748
- options: await r.parse({
1749
- type: e.type,
1750
- lastModified: e.lastModified
1751
- }),
1752
- buffer: await r.parse(await e.arrayBuffer())
1753
- };
1754
- } },
1755
- serialize(e, r) {
1756
- return "new File([" + r.serialize(e.buffer) + "]," + r.serialize(e.name) + "," + r.serialize(e.options) + ")";
1757
- },
1758
- deserialize(e, r) {
1759
- return new File([r.deserialize(e.buffer)], r.deserialize(e.name), r.deserialize(e.options));
1760
- }
1761
- });
1762
- function y(e) {
1763
- let r = [];
1764
- return e.forEach((a, t) => {
1765
- r.push([t, a]);
1766
- }), r;
1767
- }
1768
- var o = {}, v = (e, r = new FormData(), a = 0, t = e.length, s) => {
1769
- for (; a < t; a++) s = e[a], r.append(s[0], s[1]);
1770
- return r;
1771
- }, K = ni({
1772
- tag: "seroval-plugins/web/FormData",
1773
- extends: [m, ni({
1774
- tag: "seroval-plugins/web/FormDataFactory",
1775
- test(e) {
1776
- return e === o;
1777
- },
1778
- parse: {
1779
- sync() {
1780
- return o;
1781
- },
1782
- async async() {
1783
- return await Promise.resolve(o);
1784
- },
1785
- stream() {
1786
- return o;
1787
- }
1788
- },
1789
- serialize() {
1790
- return v.toString();
1791
- },
1792
- deserialize() {
1793
- return o;
1794
- }
1795
- })],
1796
- test(e) {
1797
- return typeof FormData == "undefined" ? !1 : e instanceof FormData;
1798
- },
1799
- parse: {
1800
- sync(e, r) {
1801
- return {
1802
- factory: r.parse(o),
1803
- entries: r.parse(y(e))
1804
- };
1805
- },
1806
- async async(e, r) {
1807
- return {
1808
- factory: await r.parse(o),
1809
- entries: await r.parse(y(e))
1810
- };
1811
- },
1812
- stream(e, r) {
1813
- return {
1814
- factory: r.parse(o),
1815
- entries: r.parse(y(e))
1816
- };
1817
- }
1818
- },
1819
- serialize(e, r) {
1820
- return "(" + r.serialize(e.factory) + ")(" + r.serialize(e.entries) + ")";
1821
- },
1822
- deserialize(e, r) {
1823
- return v(r.deserialize(e.entries));
1824
- }
1825
- });
1826
- function g(e) {
1827
- let r = [];
1828
- return e.forEach((a, t) => {
1829
- r.push([t, a]);
1830
- }), r;
1831
- }
1832
- var l = ni({
1833
- tag: "seroval-plugins/web/Headers",
1834
- test(e) {
1835
- return typeof Headers == "undefined" ? !1 : e instanceof Headers;
1836
- },
1837
- parse: {
1838
- sync(e, r) {
1839
- return { value: r.parse(g(e)) };
1840
- },
1841
- async async(e, r) {
1842
- return { value: await r.parse(g(e)) };
1843
- },
1844
- stream(e, r) {
1845
- return { value: r.parse(g(e)) };
1846
- }
1847
- },
1848
- serialize(e, r) {
1849
- return "new Headers(" + r.serialize(e.value) + ")";
1850
- },
1851
- deserialize(e, r) {
1852
- return new Headers(r.deserialize(e.value));
1853
- }
1854
- });
1855
- var $ = ni({
1856
- tag: "seroval-plugins/web/ImageData",
1857
- test(e) {
1858
- return typeof ImageData == "undefined" ? !1 : e instanceof ImageData;
1859
- },
1860
- parse: {
1861
- sync(e, r) {
1862
- return {
1863
- data: r.parse(e.data),
1864
- width: r.parse(e.width),
1865
- height: r.parse(e.height),
1866
- options: r.parse({ colorSpace: e.colorSpace })
1867
- };
1868
- },
1869
- async async(e, r) {
1870
- return {
1871
- data: await r.parse(e.data),
1872
- width: await r.parse(e.width),
1873
- height: await r.parse(e.height),
1874
- options: await r.parse({ colorSpace: e.colorSpace })
1875
- };
1876
- },
1877
- stream(e, r) {
1878
- return {
1879
- data: r.parse(e.data),
1880
- width: r.parse(e.width),
1881
- height: r.parse(e.height),
1882
- options: r.parse({ colorSpace: e.colorSpace })
1883
- };
1884
- }
1885
- },
1886
- serialize(e, r) {
1887
- return "new ImageData(" + r.serialize(e.data) + "," + r.serialize(e.width) + "," + r.serialize(e.height) + "," + r.serialize(e.options) + ")";
1888
- },
1889
- deserialize(e, r) {
1890
- return new ImageData(r.deserialize(e.data), r.deserialize(e.width), r.deserialize(e.height), r.deserialize(e.options));
1891
- }
1892
- });
1893
- var n = {}, P = (e) => new ReadableStream({ start: (r) => {
1894
- e.on({
1895
- next: (a) => {
1896
- try {
1897
- r.enqueue(a);
1898
- } catch (t) {}
1899
- },
1900
- throw: (a) => {
1901
- r.error(a);
1902
- },
1903
- return: () => {
1904
- try {
1905
- r.close();
1906
- } catch (a) {}
1907
- }
1908
- });
1909
- } }), x = ni({
1910
- tag: "seroval-plugins/web/ReadableStreamFactory",
1911
- test(e) {
1912
- return e === n;
1913
- },
1914
- parse: {
1915
- sync() {
1916
- return n;
1917
- },
1918
- async async() {
1919
- return await Promise.resolve(n);
1920
- },
1921
- stream() {
1922
- return n;
1923
- }
1924
- },
1925
- serialize() {
1926
- return P.toString();
1927
- },
1928
- deserialize() {
1929
- return n;
1930
- }
1931
- });
1932
- function w(e) {
1933
- let r = te$1(), a = e.getReader();
1934
- async function t() {
1935
- try {
1936
- let s = await a.read();
1937
- s.done ? r.return(s.value) : (r.next(s.value), await t());
1938
- } catch (s) {
1939
- r.throw(s);
1940
- }
1941
- }
1942
- return t().catch(() => {}), r;
1943
- }
1944
- var p = ni({
1945
- tag: "seroval/plugins/web/ReadableStream",
1946
- extends: [x],
1947
- test(e) {
1948
- return typeof ReadableStream == "undefined" ? !1 : e instanceof ReadableStream;
1949
- },
1950
- parse: {
1951
- sync(e, r) {
1952
- return {
1953
- factory: r.parse(n),
1954
- stream: r.parse(te$1())
1955
- };
1956
- },
1957
- async async(e, r) {
1958
- return {
1959
- factory: await r.parse(n),
1960
- stream: await r.parse(w(e))
1961
- };
1962
- },
1963
- stream(e, r) {
1964
- return {
1965
- factory: r.parse(n),
1966
- stream: r.parse(w(e))
1967
- };
1968
- }
1969
- },
1970
- serialize(e, r) {
1971
- return "(" + r.serialize(e.factory) + ")(" + r.serialize(e.stream) + ")";
1972
- },
1973
- deserialize(e, r) {
1974
- return P(r.deserialize(e.stream));
1975
- }
1976
- });
1977
- function N(e, r) {
1978
- return {
1979
- body: r,
1980
- cache: e.cache,
1981
- credentials: e.credentials,
1982
- headers: e.headers,
1983
- integrity: e.integrity,
1984
- keepalive: e.keepalive,
1985
- method: e.method,
1986
- mode: e.mode,
1987
- redirect: e.redirect,
1988
- referrer: e.referrer,
1989
- referrerPolicy: e.referrerPolicy
1990
- };
1991
- }
1992
- var te = ni({
1993
- tag: "seroval-plugins/web/Request",
1994
- extends: [p, l],
1995
- test(e) {
1996
- return typeof Request == "undefined" ? !1 : e instanceof Request;
1997
- },
1998
- parse: {
1999
- async async(e, r) {
2000
- return {
2001
- url: await r.parse(e.url),
2002
- options: await r.parse(N(e, e.body && !e.bodyUsed ? await e.clone().arrayBuffer() : null))
2003
- };
2004
- },
2005
- stream(e, r) {
2006
- return {
2007
- url: r.parse(e.url),
2008
- options: r.parse(N(e, e.body && !e.bodyUsed ? e.clone().body : null))
2009
- };
2010
- }
2011
- },
2012
- serialize(e, r) {
2013
- return "new Request(" + r.serialize(e.url) + "," + r.serialize(e.options) + ")";
2014
- },
2015
- deserialize(e, r) {
2016
- return new Request(r.deserialize(e.url), r.deserialize(e.options));
2017
- }
2018
- });
2019
- function h(e) {
2020
- return {
2021
- headers: e.headers,
2022
- status: e.status,
2023
- statusText: e.statusText
2024
- };
2025
- }
2026
- var ne = ni({
2027
- tag: "seroval-plugins/web/Response",
2028
- extends: [p, l],
2029
- test(e) {
2030
- return typeof Response == "undefined" ? !1 : e instanceof Response;
2031
- },
2032
- parse: {
2033
- async async(e, r) {
2034
- return {
2035
- body: await r.parse(e.body && !e.bodyUsed ? await e.clone().arrayBuffer() : null),
2036
- options: await r.parse(h(e))
2037
- };
2038
- },
2039
- stream(e, r) {
2040
- return {
2041
- body: r.parse(e.body && !e.bodyUsed ? e.clone().body : null),
2042
- options: r.parse(h(e))
2043
- };
2044
- }
2045
- },
2046
- serialize(e, r) {
2047
- return "new Response(" + r.serialize(e.body) + "," + r.serialize(e.options) + ")";
2048
- },
2049
- deserialize(e, r) {
2050
- return new Response(r.deserialize(e.body), r.deserialize(e.options));
2051
- }
2052
- });
2053
- var pe = ni({
2054
- tag: "seroval-plugins/web/URL",
2055
- test(e) {
2056
- return typeof URL == "undefined" ? !1 : e instanceof URL;
2057
- },
2058
- parse: {
2059
- sync(e, r) {
2060
- return { value: r.parse(e.href) };
2061
- },
2062
- async async(e, r) {
2063
- return { value: await r.parse(e.href) };
2064
- },
2065
- stream(e, r) {
2066
- return { value: r.parse(e.href) };
2067
- }
2068
- },
2069
- serialize(e, r) {
2070
- return "new URL(" + r.serialize(e.value) + ")";
2071
- },
2072
- deserialize(e, r) {
2073
- return new URL(r.deserialize(e.value));
2074
- }
2075
- });
2076
- var fe = ni({
2077
- tag: "seroval-plugins/web/URLSearchParams",
2078
- test(e) {
2079
- return typeof URLSearchParams == "undefined" ? !1 : e instanceof URLSearchParams;
2080
- },
2081
- parse: {
2082
- sync(e, r) {
2083
- return { value: r.parse(e.toString()) };
2084
- },
2085
- async async(e, r) {
2086
- return { value: await r.parse(e.toString()) };
2087
- },
2088
- stream(e, r) {
2089
- return { value: r.parse(e.toString()) };
2090
618
  }
2091
- },
2092
- serialize(e, r) {
2093
- return "new URLSearchParams(" + r.serialize(e.value) + ")";
2094
- },
2095
- deserialize(e, r) {
2096
- return new URLSearchParams(r.deserialize(e.value));
619
+ const items = [];
620
+ for (const item of value) items.push(await serializeJsonSafeValue(item, refs, depth + 1));
621
+ refs.delete(value);
622
+ return compressNestedJsonValue(items, depth) ?? items;
2097
623
  }
2098
- });
2099
- //#endregion
2100
- //#region ../sdk/src/cacheSerialization.ts
2101
- const serializedCacheValueMarker = "__agentEvalsCacheSerialization";
2102
- const serializedCacheValueVersion = "seroval-web-v1";
2103
- const serovalWebPlugins = [
2104
- O,
2105
- B,
2106
- L,
2107
- q,
2108
- Y,
2109
- m,
2110
- K,
2111
- l,
2112
- $,
2113
- p,
2114
- te,
2115
- ne,
2116
- pe,
2117
- fe
2118
- ];
2119
- function isRecordLike$2(value) {
2120
- return typeof value === "object" && value !== null && !Array.isArray(value);
624
+ const entries = [];
625
+ for (const [key, entryValue] of Object.entries(value)) entries.push([key, await serializeJsonSafeValue(entryValue, refs, depth + 1)]);
626
+ refs.delete(value);
627
+ const serialized = hasSerializationMarkerKey(value) ? jsonSafeValue("Object", entries) : Object.fromEntries(entries);
628
+ return compressNestedJsonValue(serialized, depth) ?? serialized;
629
+ }
630
+ function serializeNumber(value) {
631
+ if (Number.isNaN(value)) return jsonSafeValue("Number", "NaN");
632
+ if (value === Infinity) return jsonSafeValue("Number", "Infinity");
633
+ if (value === -Infinity) return jsonSafeValue("Number", "-Infinity");
634
+ if (Object.is(value, -0)) return jsonSafeValue("Number", "-0");
635
+ return value;
636
+ }
637
+ function serializeString(value, depth) {
638
+ if (depth === 0) return value;
639
+ return compressNestedStringValue(value) ?? value;
640
+ }
641
+ function isDenseNumberArray(value) {
642
+ for (let index = 0; index < value.length; index++) if (typeof value[index] !== "number") return false;
643
+ return true;
644
+ }
645
+ function encodeFloat64Array(value) {
646
+ const bytes = /* @__PURE__ */ new ArrayBuffer(value.length * 8);
647
+ const view = new DataView(bytes);
648
+ for (const [index, item] of value.entries()) view.setFloat64(index * 8, item, true);
649
+ return bytesToBase64(new Uint8Array(bytes));
650
+ }
651
+ function packNumberArray(value) {
652
+ const serialized = {
653
+ [serializedCacheValueMarker]: jsonSafeCacheValueVersion,
654
+ length: value.length,
655
+ type: "Float64Array",
656
+ value: encodeFloat64Array(value)
657
+ };
658
+ return compressionIsWorthIt(serialized, Buffer$1.byteLength(JSON.stringify(value))) ? serialized : void 0;
659
+ }
660
+ function decodeFloat64Array(value, length) {
661
+ const bytes = base64ToArrayBuffer(value);
662
+ const view = new DataView(bytes);
663
+ return Array.from({ length }, (_, index) => view.getFloat64(index * 8, true));
664
+ }
665
+ function compressNestedStringValue(value) {
666
+ const rawSize = Buffer$1.byteLength(JSON.stringify(value));
667
+ if (rawSize < compressedStringMinBytes) return void 0;
668
+ const compressed = gzipSync(value);
669
+ const serialized = {
670
+ [serializedCacheValueMarker]: jsonSafeCacheValueVersion,
671
+ codec: "gzip",
672
+ length: Buffer$1.byteLength(value),
673
+ type: "CompressedString",
674
+ value: compressed.toString("base64")
675
+ };
676
+ return compressionIsWorthIt(serialized, rawSize) ? serialized : void 0;
677
+ }
678
+ function compressNestedJsonValue(value, depth) {
679
+ if (depth === 0) return void 0;
680
+ const raw = JSON.stringify(value);
681
+ const rawSize = Buffer$1.byteLength(raw);
682
+ if (rawSize < compressedJsonMinBytes) return void 0;
683
+ const serialized = {
684
+ [serializedCacheValueMarker]: jsonSafeCacheValueVersion,
685
+ codec: "gzip",
686
+ length: rawSize,
687
+ type: "CompressedJson",
688
+ value: gzipSync(raw).toString("base64")
689
+ };
690
+ return compressionIsWorthIt(serialized, rawSize) ? serialized : void 0;
2121
691
  }
2122
- function isSerializedCacheValue(value) {
2123
- return isRecordLike$2(value) && value[serializedCacheValueMarker] === serializedCacheValueVersion;
692
+ function compressionIsWorthIt(value, rawSize) {
693
+ return Buffer$1.byteLength(JSON.stringify(value)) < rawSize * maxCompressedSizeRatio;
2124
694
  }
2125
- /** Serialize one cached value with Seroval plus the Web API plugin set. */
2126
- async function serializeCacheValue(value) {
2127
- return {
2128
- [serializedCacheValueMarker]: serializedCacheValueVersion,
2129
- value: await Au(value, { plugins: serovalWebPlugins })
2130
- };
695
+ async function serializeMap(value, refs, depth) {
696
+ if (refs.has(value)) throw new Error("Circular cache values are not supported");
697
+ refs.add(value);
698
+ const entries = [];
699
+ for (const [key, entryValue] of value.entries()) entries.push([await serializeJsonSafeValue(key, refs, depth + 1), await serializeJsonSafeValue(entryValue, refs, depth + 1)]);
700
+ refs.delete(value);
701
+ return jsonSafeValue("Map", entries);
2131
702
  }
2132
- /** Revive one cached value, while preserving legacy JSON-round-tripped data. */
2133
- function deserializeCacheValue(value) {
2134
- if (!isSerializedCacheValue(value)) return value;
2135
- return Iu(value.value, { plugins: serovalWebPlugins });
703
+ async function serializeSet(value, refs, depth) {
704
+ if (refs.has(value)) throw new Error("Circular cache values are not supported");
705
+ refs.add(value);
706
+ const items = [];
707
+ for (const item of value.values()) items.push(await serializeJsonSafeValue(item, refs, depth + 1));
708
+ refs.delete(value);
709
+ return jsonSafeValue("Set", items);
2136
710
  }
2137
- /** Clone one value through the same Seroval path used for persisted cache data. */
2138
- async function cloneCacheValue(value) {
2139
- return deserializeCacheValue(await serializeCacheValue(value));
711
+ async function serializeError(value, refs, depth) {
712
+ if (refs.has(value)) throw new Error("Circular cache values are not supported");
713
+ refs.add(value);
714
+ const props = [];
715
+ for (const [key, entryValue] of Object.entries(value)) {
716
+ if (key === "cause") continue;
717
+ props.push([key, await serializeJsonSafeValue(entryValue, refs, depth + 1)]);
718
+ }
719
+ const serialized = jsonSafeValue("Error", {
720
+ cause: "cause" in value ? await serializeJsonSafeValue(value.cause, refs, depth + 1) : void 0,
721
+ message: value.message,
722
+ name: value.name,
723
+ props,
724
+ stack: value.stack
725
+ });
726
+ refs.delete(value);
727
+ return serialized;
728
+ }
729
+ async function blobToBase64(value) {
730
+ return bytesToBase64(new Uint8Array(await value.arrayBuffer()));
731
+ }
732
+ function bytesToBase64(value) {
733
+ return Buffer$1.from(value).toString("base64");
734
+ }
735
+ function base64ToArrayBuffer(value) {
736
+ const source = Buffer$1.from(value, "base64");
737
+ const target = new ArrayBuffer(source.byteLength);
738
+ new Uint8Array(target).set(source);
739
+ return target;
740
+ }
741
+ function deserializeJsonSafeValue(value) {
742
+ if (isJsonSafeSerializedCacheValue(value)) return deserializeJsonSafeWrapper(value);
743
+ if (Array.isArray(value)) return value.map(deserializeJsonSafeValue);
744
+ if (!isRecordLike$3(value)) return value;
745
+ return Object.fromEntries(Object.entries(value).map(([key, entryValue]) => [key, deserializeJsonSafeValue(entryValue)]));
746
+ }
747
+ function deserializeJsonSafeWrapper(value) {
748
+ switch (value.type) {
749
+ case "ArrayBuffer": return deserializeArrayBuffer(value.value);
750
+ case "BigInt": return typeof value.value === "string" ? BigInt(value.value) : value.value;
751
+ case "Blob": return deserializeBlob(value.value);
752
+ case "CompressedJson": return deserializeCompressedJson(value.value);
753
+ case "CompressedString": return deserializeCompressedString(value.value);
754
+ case "Date": return typeof value.value === "string" ? new Date(value.value) : value.value;
755
+ case "Error": return deserializeError(value.value);
756
+ case "File": return deserializeFile(value.value);
757
+ case "Float64Array": return deserializeFloat64Array(value.value, value.length);
758
+ case "Headers": return new Headers(deserializeStringPairArray(value.value));
759
+ case "Map": return new Map(deserializePairArray(value.value));
760
+ case "Number": return deserializeNumber(value.value);
761
+ case "Object": return Object.fromEntries(deserializeStringValuePairArray(value.value));
762
+ case "RegExp": return deserializeRegExp(value.value);
763
+ case "Set": return new Set(deserializeArray(value.value));
764
+ case "URL": return typeof value.value === "string" ? new URL(value.value) : value.value;
765
+ case "URLSearchParams": return typeof value.value === "string" ? new URLSearchParams(value.value) : value.value;
766
+ case "Undefined": return;
767
+ }
768
+ }
769
+ function deserializeNumber(value) {
770
+ if (value === "NaN") return NaN;
771
+ if (value === "Infinity") return Infinity;
772
+ if (value === "-Infinity") return -Infinity;
773
+ if (value === "-0") return -0;
774
+ return value;
775
+ }
776
+ function deserializeCompressedString(value) {
777
+ if (typeof value !== "string") return value;
778
+ return gunzipSync(Buffer$1.from(value, "base64")).toString("utf8");
779
+ }
780
+ function deserializeCompressedJson(value) {
781
+ if (typeof value !== "string") return value;
782
+ return deserializeJsonSafeValue(JSON.parse(gunzipSync(Buffer$1.from(value, "base64")).toString("utf8")));
783
+ }
784
+ function deserializeFloat64Array(value, length) {
785
+ if (typeof value !== "string" || typeof length !== "number") return value;
786
+ return decodeFloat64Array(value, length);
787
+ }
788
+ function deserializePairArray(value) {
789
+ if (!Array.isArray(value)) return [];
790
+ return value.flatMap((entry) => {
791
+ if (!Array.isArray(entry) || entry.length !== 2) return [];
792
+ return [[deserializeJsonSafeValue(entry[0]), deserializeJsonSafeValue(entry[1])]];
793
+ });
794
+ }
795
+ function deserializeStringPairArray(value) {
796
+ return deserializePairArray(value).flatMap(([key, entryValue]) => {
797
+ if (typeof key !== "string" || typeof entryValue !== "string") return [];
798
+ return [[key, entryValue]];
799
+ });
800
+ }
801
+ function deserializeStringValuePairArray(value) {
802
+ return deserializePairArray(value).flatMap(([key, entryValue]) => {
803
+ if (typeof key !== "string") return [];
804
+ return [[key, entryValue]];
805
+ });
806
+ }
807
+ function deserializeArray(value) {
808
+ if (!Array.isArray(value)) return [];
809
+ return value.map(deserializeJsonSafeValue);
810
+ }
811
+ function deserializeRegExp(value) {
812
+ if (!isRecordLike$3(value)) return value;
813
+ const source = value.source;
814
+ const flags = value.flags;
815
+ if (typeof source !== "string" || typeof flags !== "string") return value;
816
+ return new RegExp(source, flags);
817
+ }
818
+ function deserializeArrayBuffer(value) {
819
+ if (typeof value !== "string") return value;
820
+ return base64ToArrayBuffer(value);
821
+ }
822
+ function deserializeBlob(value) {
823
+ if (!isRecordLike$3(value)) return value;
824
+ const bytes = value.bytes;
825
+ const type = value.type;
826
+ if (typeof bytes !== "string" || typeof type !== "string") return value;
827
+ return new Blob([base64ToArrayBuffer(bytes)], { type });
828
+ }
829
+ function deserializeFile(value) {
830
+ if (!isRecordLike$3(value)) return value;
831
+ const bytes = value.bytes;
832
+ const lastModified = value.lastModified;
833
+ const name = value.name;
834
+ const type = value.type;
835
+ if (typeof bytes !== "string" || typeof lastModified !== "number" || typeof name !== "string" || typeof type !== "string") return value;
836
+ return new File([new Blob([base64ToArrayBuffer(bytes)], { type })], name, {
837
+ lastModified,
838
+ type
839
+ });
840
+ }
841
+ function deserializeError(value) {
842
+ if (!isRecordLike$3(value)) return value;
843
+ const message = value.message;
844
+ const error = new Error(typeof message === "string" ? message : void 0);
845
+ if (typeof value.name === "string") error.name = value.name;
846
+ if (typeof value.stack === "string") error.stack = value.stack;
847
+ if (value.cause !== void 0) Object.defineProperty(error, "cause", {
848
+ configurable: true,
849
+ enumerable: false,
850
+ value: deserializeJsonSafeValue(value.cause),
851
+ writable: true
852
+ });
853
+ for (const [key, entryValue] of deserializeStringValuePairArray(value.props)) Object.defineProperty(error, key, {
854
+ configurable: true,
855
+ enumerable: true,
856
+ value: entryValue,
857
+ writable: true
858
+ });
859
+ return error;
2140
860
  }
2141
861
  async function serializeRecordValues(record) {
2142
862
  const entries = [];
@@ -2223,6 +943,107 @@ function deserializeCacheRecording(recording) {
2223
943
  };
2224
944
  }
2225
945
  //#endregion
946
+ //#region ../sdk/src/cacheKey.ts
947
+ var SerializedCacheKeyValue = class {
948
+ value;
949
+ constructor(value) {
950
+ this.value = value;
951
+ }
952
+ };
953
+ /**
954
+ * Hash the components of a cache key into a deterministic hex digest.
955
+ *
956
+ * Native `Blob` and `File` values use stable metadata by default. Pass
957
+ * `serializeFileBytes: true` to read them asynchronously and include their byte
958
+ * hash in the key.
959
+ */
960
+ async function hashCacheKey(input, options = {}) {
961
+ return hashCacheKeySyncMaterialized(options.serializeFileBytes === true ? await materializeAsyncCacheKeyValue(input) : input);
962
+ }
963
+ /**
964
+ * Synchronously hash cache key components. This supports JSON-like data and
965
+ * in-memory binary values such as `Buffer`, `ArrayBuffer`, and typed arrays,
966
+ * plus stable metadata for native `Blob` and `File` values.
967
+ */
968
+ function hashCacheKeySync(input) {
969
+ return hashCacheKeySyncMaterialized(input);
970
+ }
971
+ function hashCacheKeySyncMaterialized(input) {
972
+ return createHash("sha256").update(getCompositeKey(input, { stringify: stringifyCacheKeyValue })).digest("hex");
973
+ }
974
+ function stringifyCacheKeyValue(value) {
975
+ if (value instanceof SerializedCacheKeyValue) return value.value;
976
+ if (Buffer$1.isBuffer(value)) return `$buffer:${hashBytes(value)}`;
977
+ if (isArrayBuffer(value)) return `$arrayBuffer:${hashBytes(new Uint8Array(value))}`;
978
+ if (isSharedArrayBuffer(value)) return `$sharedArrayBuffer:${hashBytes(new Uint8Array(value))}`;
979
+ if (isArrayBufferView(value)) {
980
+ const bytes = new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
981
+ return `$${value.constructor.name}:${hashBytes(bytes)}`;
982
+ }
983
+ if (isFile$1(value)) return `$file:${getCompositeKey({
984
+ lastModified: value.lastModified,
985
+ name: value.name,
986
+ size: value.size,
987
+ type: value.type
988
+ })}`;
989
+ if (isBlob$1(value)) return `$blob:${getCompositeKey({
990
+ size: value.size,
991
+ type: value.type
992
+ })}`;
993
+ }
994
+ async function materializeAsyncCacheKeyValue(value, refs = /* @__PURE__ */ new WeakSet()) {
995
+ const serialized = await stringifyAsyncCacheKeyValue(value);
996
+ if (serialized !== void 0) return new SerializedCacheKeyValue(serialized);
997
+ if (stringifyCacheKeyValue(value) !== void 0) return value;
998
+ if (!value || typeof value !== "object") return value;
999
+ if (Array.isArray(value)) {
1000
+ const items = [];
1001
+ for (const item of value) items.push(await materializeAsyncCacheKeyValue(item, refs));
1002
+ return items;
1003
+ }
1004
+ if (refs.has(value)) throw new Error("Circular reference detected");
1005
+ refs.add(value);
1006
+ const entries = [];
1007
+ for (const [key, entryValue] of Object.entries(value)) entries.push([key, await materializeAsyncCacheKeyValue(entryValue, refs)]);
1008
+ refs.delete(value);
1009
+ return Object.fromEntries(entries);
1010
+ }
1011
+ async function stringifyAsyncCacheKeyValue(value) {
1012
+ if (isFile$1(value)) return `$file:${getCompositeKey({
1013
+ bytes: await hashBlobBytes(value),
1014
+ lastModified: value.lastModified,
1015
+ name: value.name,
1016
+ size: value.size,
1017
+ type: value.type
1018
+ })}`;
1019
+ if (isBlob$1(value)) return `$blob:${getCompositeKey({
1020
+ bytes: await hashBlobBytes(value),
1021
+ size: value.size,
1022
+ type: value.type
1023
+ })}`;
1024
+ }
1025
+ async function hashBlobBytes(value) {
1026
+ return hashBytes(new Uint8Array(await value.arrayBuffer()));
1027
+ }
1028
+ function hashBytes(value) {
1029
+ return createHash("sha256").update(value).digest("hex");
1030
+ }
1031
+ function isArrayBuffer(value) {
1032
+ return value instanceof ArrayBuffer;
1033
+ }
1034
+ function isSharedArrayBuffer(value) {
1035
+ return value instanceof SharedArrayBuffer;
1036
+ }
1037
+ function isArrayBufferView(value) {
1038
+ return ArrayBuffer.isView(value);
1039
+ }
1040
+ function isBlob$1(value) {
1041
+ return value instanceof Blob;
1042
+ }
1043
+ function isFile$1(value) {
1044
+ return value instanceof File;
1045
+ }
1046
+ //#endregion
2226
1047
  //#region ../sdk/src/cacheRecording.ts
2227
1048
  function mergeSpanAttributes$1(span, attributes) {
2228
1049
  span.attributes = {
@@ -2230,7 +1051,7 @@ function mergeSpanAttributes$1(span, attributes) {
2230
1051
  ...attributes
2231
1052
  };
2232
1053
  }
2233
- function isRecordLike$1(value) {
1054
+ function isRecordLike$2(value) {
2234
1055
  return typeof value === "object" && value !== null && !Array.isArray(value);
2235
1056
  }
2236
1057
  function valueKind$1(value) {
@@ -2247,7 +1068,7 @@ function stripCacheAttributes(attributes) {
2247
1068
  }
2248
1069
  async function snapshotNonCacheAttributes(span) {
2249
1070
  const snapshot = await cloneCacheValue(stripCacheAttributes(span?.attributes));
2250
- return isRecordLike$1(snapshot) ? snapshot : {};
1071
+ return isRecordLike$2(snapshot) ? snapshot : {};
2251
1072
  }
2252
1073
  function diffNonCacheAttributes(before, after) {
2253
1074
  const result = {};
@@ -2343,7 +1164,7 @@ function applyRecordingOp(scope, parentSpan, op, options) {
2343
1164
  if (op.kind === "mergeOutput") {
2344
1165
  const existing = scope.outputs[op.key];
2345
1166
  if (existing === void 0) scope.outputs[op.key] = { ...op.patch };
2346
- else if (isRecordLike$1(existing)) scope.outputs[op.key] = {
1167
+ else if (isRecordLike$2(existing)) scope.outputs[op.key] = {
2347
1168
  ...existing,
2348
1169
  ...op.patch
2349
1170
  };
@@ -2571,6 +1392,11 @@ function createTraceCache(generateSpanId) {
2571
1392
  storedAt: (/* @__PURE__ */ new Date()).toISOString(),
2572
1393
  codeFingerprint: cacheCtx.codeFingerprint,
2573
1394
  recording: await serializeCacheRecording(recording)
1395
+ }, {
1396
+ rawKey: info.key,
1397
+ operationType: "value",
1398
+ operationName: info.name,
1399
+ codeFingerprint: cacheCtx.codeFingerprint
2574
1400
  });
2575
1401
  }
2576
1402
  return bodyResult;
@@ -2616,7 +1442,7 @@ function mergeSpanAttributes(span, attributes) {
2616
1442
  ...attributes
2617
1443
  };
2618
1444
  }
2619
- function isRecordLike(value) {
1445
+ function isRecordLike$1(value) {
2620
1446
  return typeof value === "object" && value !== null && !Array.isArray(value);
2621
1447
  }
2622
1448
  function valueKind(value) {
@@ -2658,7 +1484,7 @@ function mergeSpanAttribute(span, key, patch) {
2658
1484
  mergeSpanAttributes(span, { [key]: { ...patch } });
2659
1485
  return;
2660
1486
  }
2661
- if (!isRecordLike(existing)) {
1487
+ if (!isRecordLike$1(existing)) {
2662
1488
  recordSpanAttributeAssertion(`evalSpan.mergeAttribute("${key}"): existing value is ${valueKind(existing)}, expected object`);
2663
1489
  return;
2664
1490
  }
@@ -2996,7 +1822,12 @@ async function traceSpanInternal(info, fn) {
2996
1822
  codeFingerprint: ctx.codeFingerprint,
2997
1823
  recording: await serializeCacheRecording(recording)
2998
1824
  };
2999
- await ctx.adapter.write(entry);
1825
+ await ctx.adapter.write(entry, {
1826
+ rawKey: cacheOpts.key,
1827
+ operationType: "span",
1828
+ operationName: info.name,
1829
+ codeFingerprint: ctx.codeFingerprint
1830
+ });
3000
1831
  }
3001
1832
  return bodyResult;
3002
1833
  }
@@ -3415,12 +2246,31 @@ const cacheEntrySchema = z.object({
3415
2246
  codeFingerprint: z.string(),
3416
2247
  recording: cacheRecordingSchema
3417
2248
  });
2249
+ /** Debug-only raw key metadata stored outside the reusable cache entry. */
2250
+ const cacheDebugKeyEntrySchema = z.object({
2251
+ version: z.literal(1),
2252
+ key: z.string(),
2253
+ namespace: z.string(),
2254
+ operationType: cacheOperationTypeSchema,
2255
+ operationName: z.string(),
2256
+ storedAt: z.string(),
2257
+ codeFingerprint: z.string(),
2258
+ rawKey: z.unknown()
2259
+ });
2260
+ /** Cache lookup response with optional debug-only raw key data. */
2261
+ const cacheEntryWithDebugKeySchema = cacheEntrySchema.extend({ debugKey: cacheDebugKeyEntrySchema.optional() });
3418
2262
  /** Persisted per-owner cache file containing multiple cache entries. */
3419
2263
  const cacheFileSchema = z.object({
3420
2264
  version: z.literal(1),
3421
2265
  owner: z.string(),
3422
2266
  entries: z.record(z.string(), cacheEntrySchema)
3423
2267
  });
2268
+ /** Persisted per-owner debug file containing raw cache key metadata. */
2269
+ const cacheDebugKeyFileSchema = z.object({
2270
+ version: z.literal(1),
2271
+ owner: z.string(),
2272
+ entries: z.record(z.string(), cacheDebugKeyEntrySchema)
2273
+ });
3424
2274
  //#endregion
3425
2275
  //#region ../shared/src/schemas/chart.ts
3426
2276
  /** Chart type rendered for a single eval history chart. */
@@ -3623,6 +2473,51 @@ const assertionFailureSchema = z.object({
3623
2473
  stack: z.string().optional()
3624
2474
  });
3625
2475
  const legacyAssertionFailureSchema = z.string().transform((message) => ({ message }));
2476
+ /** Severity level for one log captured during a case run. */
2477
+ const runLogLevelSchema = z.enum([
2478
+ "log",
2479
+ "info",
2480
+ "warn",
2481
+ "error"
2482
+ ]);
2483
+ /** Eval runner phase that emitted a captured case log. */
2484
+ const runLogPhaseSchema = z.enum([
2485
+ "eval",
2486
+ "derive",
2487
+ "outputsSchema",
2488
+ "scorer"
2489
+ ]);
2490
+ /** Schema for one persisted log entry captured during a case run. */
2491
+ const runLogLocationSchema = z.object({
2492
+ /** File path reported by the JavaScript stack frame. */
2493
+ file: z.string(),
2494
+ /** 1-based source line reported by the JavaScript stack frame. */
2495
+ line: z.number(),
2496
+ /** 1-based source column reported by the JavaScript stack frame. */
2497
+ column: z.number()
2498
+ });
2499
+ /** Schema for one persisted log entry captured during a case run. */
2500
+ const runLogEntrySchema = z.object({
2501
+ /** ISO timestamp for when the log was captured. */
2502
+ timestamp: z.string(),
2503
+ /** Normalized log level. */
2504
+ level: runLogLevelSchema,
2505
+ /** Case-owned runner phase that emitted the log. */
2506
+ phase: runLogPhaseSchema,
2507
+ /** Human-readable preview formatted from the original log arguments. */
2508
+ message: z.string(),
2509
+ /** JSON-safe captured log arguments rendered in the UI. */
2510
+ args: z.array(z.unknown()).default([]),
2511
+ /** Whether `message` was capped before persistence. */
2512
+ truncated: z.boolean().default(false),
2513
+ /** Best-effort code location for the log call, when Node stack data is available. */
2514
+ location: runLogLocationSchema.optional(),
2515
+ /**
2516
+ * Optional source label for logs emitted from a nested case-owned activity,
2517
+ * such as a score key.
2518
+ */
2519
+ source: z.string().optional()
2520
+ });
3626
2521
  /** Trace payload captured while computing one score for a case. */
3627
2522
  const scoreTraceSchema = z.object({
3628
2523
  trace: z.array(traceSpanSchema),
@@ -3651,6 +2546,8 @@ const caseDetailSchema = z.object({
3651
2546
  scoringTraces: z.record(z.string(), scoreTraceSchema).optional(),
3652
2547
  columns: z.record(z.string(), cellValueSchema),
3653
2548
  assertionFailures: z.array(z.union([assertionFailureSchema, legacyAssertionFailureSchema])),
2549
+ /** Logs captured from manual `evalLog(...)` calls and enabled console calls. */
2550
+ logs: z.array(runLogEntrySchema).default([]),
3654
2551
  error: z.object({
3655
2552
  name: z.string().optional(),
3656
2553
  message: z.string(),
@@ -3802,6 +2699,14 @@ const apiCallsConfigSchema = z.object({
3802
2699
  /** Custom user-defined metrics surfaced on each API call. */
3803
2700
  metrics: z.array(apiCallMetricSchema).optional()
3804
2701
  });
2702
+ /** Schema for workspace-level run log capture options. */
2703
+ const runLogsConfigSchema = z.object({
2704
+ /**
2705
+ * Capture `console.log`, `console.info`, `console.warn`, and
2706
+ * `console.error` calls made inside active eval case scopes. Defaults to
2707
+ * `true`; manual `evalLog(...)` calls are always captured.
2708
+ */
2709
+ captureConsole: z.boolean().optional() });
3805
2710
  /** Default LLM-calls config the UI uses before the workspace fetch resolves. */
3806
2711
  const DEFAULT_LLM_CALLS_CONFIG = {
3807
2712
  kinds: ["llm"],
@@ -3917,6 +2822,7 @@ const agentEvalsConfigSchema = z.object({
3917
2822
  traceDisplay: traceDisplayInputConfigSchema.optional(),
3918
2823
  llmCalls: llmCallsConfigSchema.optional(),
3919
2824
  apiCalls: apiCallsConfigSchema.optional(),
2825
+ runLogs: runLogsConfigSchema.optional(),
3920
2826
  cache: z.object({
3921
2827
  enabled: z.boolean().optional(),
3922
2828
  dir: z.string().optional(),
@@ -4375,68 +3281,98 @@ function readArray(attributes, key) {
4375
3281
  const value = attributes[key];
4376
3282
  return Array.isArray(value) ? value : [];
4377
3283
  }
3284
+ function readCacheStatus(attributes) {
3285
+ if (!isRecord$2(attributes)) return void 0;
3286
+ const parsed = cacheStatusSchema.safeParse(attributes["cache.status"]);
3287
+ if (!parsed.success || parsed.data === "bypass") return void 0;
3288
+ return parsed.data;
3289
+ }
4378
3290
  /**
4379
- * Collect every `status === 'hit'` cache event recorded for a case run.
3291
+ * Collect every cache hit or cache write recorded for a case run.
4380
3292
  *
4381
- * Walks `spans` for span-level cache hits (`attributes['cache.status'] ===
4382
- * 'hit'`) and per-span value-cache refs (`attributes['cache.refs']`), then
4383
- * appends spanless value-cache refs persisted on the case scope. Non-hit
4384
- * statuses (`miss`/`refresh`/`bypass`) are skipped they remain visible
4385
- * inline in the Trace tab.
3293
+ * Walks `spans` for span-level cache activity (`attributes['cache.status']`)
3294
+ * and per-span value-cache refs (`attributes['cache.refs']`), then appends
3295
+ * spanless value-cache refs persisted on the case scope. Bypasses are skipped
3296
+ * because they do not read or write a persisted cache entry.
4386
3297
  */
4387
- function extractCacheHits(spans, caseCacheRefs) {
3298
+ function extractCacheEntries(spans, caseCacheRefs) {
4388
3299
  const entries = [];
4389
3300
  for (const span of spans) {
4390
- if (readString(span.attributes, "cache.status") === "hit") {
3301
+ const status = readCacheStatus(span.attributes);
3302
+ if (status !== void 0) {
4391
3303
  const key = readString(span.attributes, "cache.key");
4392
3304
  const namespace = readString(span.attributes, "cache.namespace");
4393
- if (key !== void 0 && namespace !== void 0) entries.push({
4394
- id: span.id,
4395
- source: "span",
4396
- origin: "span",
4397
- name: span.name,
4398
- namespace,
4399
- key,
4400
- storedAt: readString(span.attributes, "cache.storedAt"),
4401
- age: readNumber(span.attributes, "cache.age"),
4402
- spanId: span.id
4403
- });
3305
+ if (key !== void 0 && namespace !== void 0) {
3306
+ const isHit = status === "hit";
3307
+ entries.push({
3308
+ id: span.id,
3309
+ source: "span",
3310
+ origin: "span",
3311
+ action: isHit ? "hit" : "added",
3312
+ status,
3313
+ name: span.name,
3314
+ namespace,
3315
+ key,
3316
+ storedAt: isHit ? readString(span.attributes, "cache.storedAt") : void 0,
3317
+ age: isHit ? readNumber(span.attributes, "cache.age") : void 0,
3318
+ spanId: span.id
3319
+ });
3320
+ }
4404
3321
  }
4405
3322
  const rawRefs = readArray(span.attributes, "cache.refs");
4406
3323
  for (const [index, rawRef] of rawRefs.entries()) {
4407
3324
  const parsed = traceCacheRefSchema.safeParse(rawRef);
4408
3325
  if (!parsed.success) continue;
4409
3326
  const ref = parsed.data;
4410
- if (ref.status !== "hit") continue;
3327
+ if (ref.status === "bypass") continue;
3328
+ const isHit = ref.status === "hit";
4411
3329
  entries.push({
4412
3330
  id: `${span.id}:value:${String(index)}`,
4413
3331
  source: "value",
4414
3332
  origin: "span",
3333
+ action: isHit ? "hit" : "added",
3334
+ status: ref.status,
4415
3335
  name: ref.name,
4416
3336
  namespace: ref.namespace,
4417
3337
  key: ref.key,
4418
- storedAt: ref.storedAt,
4419
- age: ref.age,
3338
+ storedAt: isHit ? ref.storedAt : void 0,
3339
+ age: isHit ? ref.age : void 0,
4420
3340
  spanId: span.id
4421
3341
  });
4422
3342
  }
4423
3343
  }
4424
3344
  for (const [index, ref] of caseCacheRefs.entries()) {
4425
- if (ref.status !== "hit") continue;
3345
+ if (ref.status === "bypass") continue;
3346
+ const isHit = ref.status === "hit";
4426
3347
  entries.push({
4427
3348
  id: `case:value:${String(index)}`,
4428
3349
  source: "value",
4429
3350
  origin: "caseRoot",
3351
+ action: isHit ? "hit" : "added",
3352
+ status: ref.status,
4430
3353
  name: ref.name,
4431
3354
  namespace: ref.namespace,
4432
3355
  key: ref.key,
4433
- storedAt: ref.storedAt,
4434
- age: ref.age,
3356
+ storedAt: isHit ? ref.storedAt : void 0,
3357
+ age: isHit ? ref.age : void 0,
4435
3358
  spanId: void 0
4436
3359
  });
4437
3360
  }
4438
3361
  return entries;
4439
3362
  }
3363
+ /**
3364
+ * Collect every `status === 'hit'` cache event recorded for a case run.
3365
+ *
3366
+ * This compatibility helper returns only rows that reused an existing
3367
+ * persisted cache entry. Use `extractCacheEntries(...)` when the UI should
3368
+ * include cache misses and refreshes that wrote entries during the run.
3369
+ */
3370
+ function extractCacheHits(spans, caseCacheRefs) {
3371
+ return extractCacheEntries(spans, caseCacheRefs).filter(isCacheHitEntry);
3372
+ }
3373
+ function isCacheHitEntry(entry) {
3374
+ return entry.status === "hit";
3375
+ }
4440
3376
  z.enum([
4441
3377
  "discovery.updated",
4442
3378
  "run.started",
@@ -4481,6 +3417,8 @@ const updateManualScoreRequestSchema = z.object({ value: z.number().min(0).max(1
4481
3417
  //#endregion
4482
3418
  //#region ../runner/src/cacheStore.ts
4483
3419
  const defaultMaxEntriesPerNamespace = 100;
3420
+ const cacheSerializationMarker = "__agentEvalsCacheSerialization";
3421
+ const supportedCacheSerializationVersion = "json-safe-v1";
4484
3422
  /**
4485
3423
  * Create a filesystem-backed cache adapter rooted at `<workspaceRoot>/<dir>`.
4486
3424
  *
@@ -4490,15 +3428,33 @@ const defaultMaxEntriesPerNamespace = 100;
4490
3428
  */
4491
3429
  function createFsCacheStore(options) {
4492
3430
  const cacheDir = resolve(options.workspaceRoot, options.dir ?? ".agent-evals/cache");
3431
+ const debugDir = resolve(options.workspaceRoot, options.debugDir ?? ".agent-evals/cache-debug");
4493
3432
  const defaultMaxEntries = normalizeMaxEntries(options.maxEntriesPerNamespace);
4494
3433
  return {
4495
3434
  dir() {
4496
3435
  return cacheDir;
4497
3436
  },
3437
+ debugDir() {
3438
+ return debugDir;
3439
+ },
4498
3440
  async lookup(namespace, keyHash) {
4499
3441
  return (await readCacheFile(cacheDir, ownerFromNamespace(namespace)))?.entries[keyHash] ?? null;
4500
3442
  },
4501
- async write(entry) {
3443
+ async lookupWithDebug(namespace, keyHash) {
3444
+ const owner = ownerFromNamespace(namespace);
3445
+ const entry = (await readCacheFile(cacheDir, owner))?.entries[keyHash] ?? null;
3446
+ if (entry === null) return null;
3447
+ const debugKey = (await readDebugKeyFile(debugDir, owner))?.entries[keyHash];
3448
+ const deserializedEntry = {
3449
+ ...entry,
3450
+ recording: deserializeCacheRecording(entry.recording)
3451
+ };
3452
+ return debugKey === void 0 ? deserializedEntry : {
3453
+ ...deserializedEntry,
3454
+ debugKey
3455
+ };
3456
+ },
3457
+ async write(entry, debugKey) {
4502
3458
  const owner = ownerFromNamespace(entry.namespace);
4503
3459
  const filePath = ownerPath(cacheDir, owner);
4504
3460
  await mkdir(cacheDir, { recursive: true });
@@ -4512,6 +3468,17 @@ function createFsCacheStore(options) {
4512
3468
  }, entry.namespace, maxEntriesForNamespace(entry.namespace, defaultMaxEntries, options.maxEntriesByNamespace), entry.key)
4513
3469
  });
4514
3470
  });
3471
+ if (debugKey !== void 0) {
3472
+ if ((await resultify(() => writeDebugKeyEntry({
3473
+ debugDir,
3474
+ entry,
3475
+ debugKey,
3476
+ maxEntries: maxEntriesForNamespace(entry.namespace, defaultMaxEntries, options.maxEntriesByNamespace)
3477
+ }))).error) await resultify(() => clearDebugEntries(debugDir, {
3478
+ namespace: entry.namespace,
3479
+ key: entry.key
3480
+ }));
3481
+ }
4515
3482
  },
4516
3483
  async list() {
4517
3484
  if (!existsSync(cacheDir)) return [];
@@ -4544,17 +3511,21 @@ function createFsCacheStore(options) {
4544
3511
  return items;
4545
3512
  },
4546
3513
  async clear(filter) {
4547
- if (!existsSync(cacheDir)) return;
4548
3514
  if (!filter || filter.namespace === void 0 && filter.key === void 0) {
4549
3515
  await rm(cacheDir, {
4550
3516
  recursive: true,
4551
3517
  force: true
4552
3518
  });
3519
+ await rm(debugDir, {
3520
+ recursive: true,
3521
+ force: true
3522
+ });
4553
3523
  return;
4554
3524
  }
4555
3525
  if (filter.namespace !== void 0) {
4556
3526
  const owner = ownerFromNamespace(filter.namespace);
4557
- await withCacheFileLock(ownerPath(cacheDir, owner), async () => {
3527
+ const filePath = ownerPath(cacheDir, owner);
3528
+ if (existsSync(cacheDir)) await withCacheFileLock(filePath, async () => {
4558
3529
  const cacheFile = await readCacheFile(cacheDir, owner);
4559
3530
  if (cacheFile === null) return;
4560
3531
  await writeOrRemoveCacheFile(cacheDir, {
@@ -4566,23 +3537,27 @@ function createFsCacheStore(options) {
4566
3537
  }))
4567
3538
  });
4568
3539
  });
3540
+ await clearDebugEntries(debugDir, filter);
4569
3541
  return;
4570
3542
  }
4571
- const files = await readdir(cacheDir);
4572
- for (const fileName of files) {
4573
- if (!fileName.endsWith(".json")) continue;
4574
- const filePath = join(cacheDir, fileName);
4575
- await withCacheFileLock(filePath, async () => {
4576
- const cacheFile = await readCacheFilePath(filePath);
4577
- if (cacheFile === null) return;
4578
- const entries = Object.fromEntries(Object.entries(cacheFile.entries).filter(([key]) => key !== filter.key));
4579
- await writeOrRemoveCacheFile(cacheDir, {
4580
- version: 1,
4581
- owner: cacheFile.owner,
4582
- entries
3543
+ if (existsSync(cacheDir)) {
3544
+ const files = await readdir(cacheDir);
3545
+ for (const fileName of files) {
3546
+ if (!fileName.endsWith(".json")) continue;
3547
+ const filePath = join(cacheDir, fileName);
3548
+ await withCacheFileLock(filePath, async () => {
3549
+ const cacheFile = await readCacheFilePath(filePath);
3550
+ if (cacheFile === null) return;
3551
+ const entries = Object.fromEntries(Object.entries(cacheFile.entries).filter(([key]) => key !== filter.key));
3552
+ await writeOrRemoveCacheFile(cacheDir, {
3553
+ version: 1,
3554
+ owner: cacheFile.owner,
3555
+ entries
3556
+ });
4583
3557
  });
4584
- });
3558
+ }
4585
3559
  }
3560
+ await clearDebugEntries(debugDir, filter);
4586
3561
  }
4587
3562
  };
4588
3563
  }
@@ -4598,18 +3573,21 @@ function createBufferedCacheStore(backingStore) {
4598
3573
  return {
4599
3574
  async lookup(namespace, keyHash) {
4600
3575
  const buffered = pendingEntries.get(toPendingKey(namespace, keyHash));
4601
- if (buffered !== void 0) return buffered;
3576
+ if (buffered !== void 0) return buffered.entry;
4602
3577
  return backingStore.lookup(namespace, keyHash);
4603
3578
  },
4604
- write(entry) {
4605
- pendingEntries.set(toPendingKey(entry.namespace, entry.key), entry);
3579
+ write(entry, debugKey) {
3580
+ pendingEntries.set(toPendingKey(entry.namespace, entry.key), {
3581
+ entry,
3582
+ debugKey
3583
+ });
4606
3584
  return Promise.resolve();
4607
3585
  },
4608
3586
  async commit() {
4609
- for (const entry of pendingEntries.values()) await backingStore.write(entry);
3587
+ for (const pending of pendingEntries.values()) await backingStore.write(pending.entry, pending.debugKey);
4610
3588
  },
4611
3589
  getPendingEntries() {
4612
- return [...pendingEntries.values()];
3590
+ return [...pendingEntries.values()].map((pending) => pending.entry);
4613
3591
  }
4614
3592
  };
4615
3593
  }
@@ -4645,7 +3623,16 @@ async function readCacheFilePath(filePath) {
4645
3623
  if (json === null) return null;
4646
3624
  const parsed = cacheFileSchema.safeParse(json);
4647
3625
  if (!parsed.success) return null;
4648
- return parsed.data;
3626
+ return {
3627
+ ...parsed.data,
3628
+ entries: Object.fromEntries(Object.entries(parsed.data.entries).filter(([, entry]) => usesSupportedCacheSerialization(entry.recording)))
3629
+ };
3630
+ }
3631
+ function usesSupportedCacheSerialization(value) {
3632
+ if (Array.isArray(value)) return value.every(usesSupportedCacheSerialization);
3633
+ if (!isRecordLike(value)) return true;
3634
+ if (Object.hasOwn(value, cacheSerializationMarker) && value[cacheSerializationMarker] !== supportedCacheSerializationVersion) return false;
3635
+ return Object.values(value).every(usesSupportedCacheSerialization);
4649
3636
  }
4650
3637
  async function writeOrRemoveCacheFile(cacheDir, cacheFile) {
4651
3638
  if (Object.keys(cacheFile.entries).length === 0) {
@@ -4658,7 +3645,95 @@ async function writeCacheFile(cacheDir, cacheFile) {
4658
3645
  await mkdir(cacheDir, { recursive: true });
4659
3646
  const filePath = ownerPath(cacheDir, cacheFile.owner);
4660
3647
  const tmpPath = `${filePath}.${process.pid.toString()}.tmp`;
4661
- await writeFile(tmpPath, JSON.stringify(cacheFile, null, 2));
3648
+ await writeFile(tmpPath, JSON.stringify(cacheFile));
3649
+ await rename(tmpPath, filePath);
3650
+ }
3651
+ async function readDebugKeyFile(debugDir, owner) {
3652
+ return readDebugKeyFilePath(ownerPath(debugDir, owner));
3653
+ }
3654
+ async function readDebugKeyFilePath(filePath) {
3655
+ if (!existsSync(filePath)) return null;
3656
+ const rawResult = await resultify(() => readFile(filePath, "utf-8"));
3657
+ if (rawResult.error) return null;
3658
+ const json = safeJsonParse(rawResult.value);
3659
+ if (json === null) return null;
3660
+ const parsed = cacheDebugKeyFileSchema.safeParse(json);
3661
+ if (!parsed.success) return null;
3662
+ return parsed.data;
3663
+ }
3664
+ async function writeDebugKeyEntry(params) {
3665
+ const { debugDir, entry, debugKey, maxEntries } = params;
3666
+ const owner = ownerFromNamespace(entry.namespace);
3667
+ const filePath = ownerPath(debugDir, owner);
3668
+ await mkdir(debugDir, { recursive: true });
3669
+ await withCacheFileLock(filePath, async () => {
3670
+ const entries = (await readDebugKeyFile(debugDir, owner))?.entries ?? {};
3671
+ const debugEntry = {
3672
+ version: 1,
3673
+ key: entry.key,
3674
+ namespace: entry.namespace,
3675
+ operationType: debugKey.operationType,
3676
+ operationName: debugKey.operationName,
3677
+ storedAt: entry.storedAt,
3678
+ codeFingerprint: debugKey.codeFingerprint,
3679
+ rawKey: debugKey.rawKey
3680
+ };
3681
+ await writeDebugKeyFile(debugDir, {
3682
+ version: 1,
3683
+ owner,
3684
+ entries: pruneDebugKeyEntries({
3685
+ ...entries,
3686
+ [entry.key]: debugEntry
3687
+ }, entry.namespace, maxEntries, entry.key)
3688
+ });
3689
+ });
3690
+ }
3691
+ async function clearDebugEntries(debugDir, filter) {
3692
+ if (!existsSync(debugDir)) return;
3693
+ if (filter.namespace !== void 0) {
3694
+ const owner = ownerFromNamespace(filter.namespace);
3695
+ await withCacheFileLock(ownerPath(debugDir, owner), async () => {
3696
+ const debugFile = await readDebugKeyFile(debugDir, owner);
3697
+ if (debugFile === null) return;
3698
+ await writeOrRemoveDebugKeyFile(debugDir, {
3699
+ version: 1,
3700
+ owner,
3701
+ entries: Object.fromEntries(Object.entries(debugFile.entries).filter(([key, entry]) => {
3702
+ if (filter.key !== void 0) return key !== filter.key;
3703
+ return entry.namespace !== filter.namespace;
3704
+ }))
3705
+ });
3706
+ });
3707
+ return;
3708
+ }
3709
+ const files = await readdir(debugDir);
3710
+ for (const fileName of files) {
3711
+ if (!fileName.endsWith(".json")) continue;
3712
+ const filePath = join(debugDir, fileName);
3713
+ await withCacheFileLock(filePath, async () => {
3714
+ const debugFile = await readDebugKeyFilePath(filePath);
3715
+ if (debugFile === null) return;
3716
+ const entries = Object.fromEntries(Object.entries(debugFile.entries).filter(([key]) => key !== filter.key));
3717
+ await writeOrRemoveDebugKeyFile(debugDir, {
3718
+ version: 1,
3719
+ owner: debugFile.owner,
3720
+ entries
3721
+ });
3722
+ });
3723
+ }
3724
+ }
3725
+ async function writeOrRemoveDebugKeyFile(debugDir, debugFile) {
3726
+ if (Object.keys(debugFile.entries).length === 0) {
3727
+ await rm(ownerPath(debugDir, debugFile.owner), { force: true });
3728
+ return;
3729
+ }
3730
+ await writeDebugKeyFile(debugDir, debugFile);
3731
+ }
3732
+ async function writeDebugKeyFile(debugDir, debugFile) {
3733
+ await mkdir(debugDir, { recursive: true });
3734
+ const filePath = ownerPath(debugDir, debugFile.owner);
3735
+ const tmpPath = `${filePath}.${process.pid.toString()}.tmp`;
3736
+ await writeFile(tmpPath, JSON.stringify(debugFile));
4662
3737
  await rename(tmpPath, filePath);
4663
3738
  }
4664
3739
  function pruneEntries(entries, namespace, maxEntries, protectedKey) {
@@ -4672,6 +3747,17 @@ function pruneEntries(entries, namespace, maxEntries, protectedKey) {
4672
3747
  }
4673
3748
  return Object.fromEntries(Object.values(entries).filter((entry) => entry.namespace !== namespace || kept.has(entry.key)).toSorted((a, b) => a.key < b.key ? -1 : 1).map((entry) => [entry.key, entry]));
4674
3749
  }
3750
+ function pruneDebugKeyEntries(entries, namespace, maxEntries, protectedKey) {
3751
+ const sorted = Object.values(entries).filter((entry) => entry.namespace === namespace).toSorted((a, b) => a.storedAt < b.storedAt ? 1 : -1);
3752
+ const kept = /* @__PURE__ */ new Map();
3753
+ const protectedEntry = entries[protectedKey];
3754
+ if (protectedEntry?.namespace === namespace) kept.set(protectedEntry.key, protectedEntry);
3755
+ for (const entry of sorted) {
3756
+ if (kept.size >= maxEntries) break;
3757
+ kept.set(entry.key, entry);
3758
+ }
3759
+ return Object.fromEntries(Object.values(entries).filter((entry) => entry.namespace !== namespace || kept.has(entry.key)).toSorted((a, b) => a.key < b.key ? -1 : 1).map((entry) => [entry.key, entry]));
3760
+ }
4675
3761
  async function withCacheFileLock(filePath, fn) {
4676
3762
  const lockPath = `${filePath}.lock`;
4677
3763
  await acquireLock(lockPath);
@@ -4702,6 +3788,9 @@ function safeJsonParse(text) {
4702
3788
  if (parsed.error) return null;
4703
3789
  return parsed.value;
4704
3790
  }
3791
+ function isRecordLike(value) {
3792
+ return typeof value === "object" && value !== null && !Array.isArray(value);
3793
+ }
4705
3794
  //#endregion
4706
3795
  //#region ../runner/src/columnBuilder.ts
4707
3796
  /**
@@ -4893,7 +3982,8 @@ const defaultConfig = {
4893
3982
  label: "Output",
4894
3983
  format: "json",
4895
3984
  placements: ["section"]
4896
- }] }
3985
+ }] },
3986
+ runLogs: { captureConsole: true }
4897
3987
  };
4898
3988
  async function loadConfig() {
4899
3989
  const configPath = resolve(process.cwd(), "agent-evals.config.ts");
@@ -5657,6 +4747,10 @@ async function runCase(params) {
5657
4747
  } : void 0
5658
4748
  });
5659
4749
  const { trace, traceDisplay } = resolveTracePresentation(scoreRun.scope.spans, globalTraceDisplay, evalDef.traceDisplay);
4750
+ scope.logs.push(...scoreRun.scope.logs.map((entry) => ({
4751
+ ...entry,
4752
+ source: key
4753
+ })));
5660
4754
  if (trace.length > 0) scoringTraces[key] = {
5661
4755
  trace,
5662
4756
  traceDisplay
@@ -5727,6 +4821,7 @@ async function runCase(params) {
5727
4821
  traceDisplay,
5728
4822
  columns,
5729
4823
  assertionFailures: scope.assertionFailures,
4824
+ logs: scope.logs,
5730
4825
  error: errorInfo,
5731
4826
  trial,
5732
4827
  cacheRefs: scope.caseCacheRefs
@@ -6142,4 +5237,4 @@ function toLastRunStatus(status) {
6142
5237
  return status === "pending" ? null : status;
6143
5238
  }
6144
5239
  //#endregion
6145
- export { caseRowSchema as $, appendToEvalOutput as $t, getEvalTitle as A, traceDisplayConfigSchema as At, apiCallMetricFormatSchema as B, fileRefSchema as Bt, createRunRequestSchema as C, serializedCacheSpanSchema as Ct, extractApiCalls as D, traceAttributeDisplayInputSchema as Dt, extractCacheHits as E, traceAttributeDisplayFormatSchema as Et, runManifestSchema as F, traceSpanWarningSchema as Ft, llmCallMetricPlacementSchema as G, z$1 as Gt, apiCallMetricSchema as H, numberDisplayOptionsSchema as Ht, runSummarySchema as I, cellValueSchema as It, resolveApiCallsConfig as J, evalSpan as Jt, llmCallMetricSchema as K, buildTraceTree as Kt, DEFAULT_API_CALLS_CONFIG as L, columnDefSchema as Lt, deriveScopedSummaryFromCases as M, traceSpanErrorSchema as Mt, deriveStatusFromCaseRows as N, traceSpanKindSchema as Nt, extractLlmCalls as O, traceAttributeDisplayPlacementSchema as Ot, deriveStatusFromChildStatuses as P, traceSpanSchema as Pt, caseDetailSchema as Q, EvalAssertionError as Qt, DEFAULT_LLM_CALLS_CONFIG as R, columnFormatSchema as Rt, createFsCacheStore as S, cacheStatusSchema as St, sseEnvelopeSchema as T, traceCacheRefSchema as Tt, apiCallsConfigSchema as U, repoFileRefSchema as Ut, apiCallMetricPlacementSchema as V, jsonCellSchema as Vt, llmCallMetricFormatSchema as W, runArtifactRefSchema as Wt, trialSelectionModeSchema as X, hashCacheKey as Xt, resolveLlmCallsConfig as Y, evalTracer as Yt, assertionFailureSchema as Z, hashCacheKeySync as Zt, loadEvalModule as _, cacheListItemSchema as _t, loadPersistedRunSnapshot as a, mergeEvalOutput as an, scoreTraceSchema as at, buildDeclaredColumnDefs as b, cacheRecordingOpSchema as bt, persistCaseDetail as c, runInEvalScope as cn, evalChartBuiltinMetricSchema as ct, recomputePersistedCaseStatus as d, setScopeCacheContext as dn, evalChartMetricSchema as dt, evalAssert as en, evalFreshnessStatusSchema as et, runTouchesEval as f, startEvalBackgroundJob as fn, evalChartTooltipExtraSchema as ft, setLatestRunInfoMap as g, cacheFileSchema as gt, getTargetEvalIds as h, getEvalRegistry as hn, cacheEntrySchema as ht, getLatestRunInfos as i, isInEvalScope as in, evalSummarySchema as it, getEvalDisplayStatus as j, traceDisplayInputConfigSchema as jt, getNestedAttribute as k, traceAttributeDisplaySchema as kt, persistRunState as l, runInExistingEvalScope as ln, evalChartColorSchema as lt, buildEvalSummary as m, defineEval as mn, evalChartsConfigSchema as mt, generateRunId as n, getEvalCaseInput as nn, evalStatItemSchema as nt, loadPersistedRunSnapshots as o, nextEvalId as on, evalChartAggregateSchema as ot, resolveArtifactPath as p, repoFile as pn, evalChartTypeSchema as pt, llmCallsConfigSchema as q, captureEvalSpanError as qt, getLastRunStatuses as r, incrementEvalOutput as rn, evalStatsConfigSchema as rt, nextShortIdFromSnapshots as s, runInEvalRuntimeScope as sn, evalChartAxisSchema as st, executeRun as t, getCurrentScope as tn, evalStatAggregateSchema as tt, recomputeEvalStatusesInRuns as u, setEvalOutput as un, evalChartConfigSchema as ut, parseEvalMetas as v, cacheModeSchema as vt, updateManualScoreRequestSchema as w, spanCacheOptionsSchema as wt, normalizeScoreDef as x, cacheRecordingSchema as xt, loadConfig as y, cacheOperationTypeSchema as yt, agentEvalsConfigSchema as z, columnKindSchema as zt };
5240
+ export { assertionFailureSchema as $, runArtifactRefSchema as $t, getNestedAttribute as A, getEvalRegistry as An, cacheRecordingSchema as At, agentEvalsConfigSchema as B, traceDisplayInputConfigSchema as Bt, createRunRequestSchema as C, runInEvalScope as Cn, cacheEntrySchema as Ct, extractCacheHits as D, startEvalBackgroundJob as Dn, cacheModeSchema as Dt, extractCacheEntries as E, setScopeCacheContext as En, cacheListItemSchema as Et, deriveStatusFromChildStatuses as F, traceAttributeDisplayFormatSchema as Ft, llmCallMetricFormatSchema as G, cellValueSchema as Gt, apiCallMetricPlacementSchema as H, traceSpanKindSchema as Ht, runManifestSchema as I, traceAttributeDisplayInputSchema as It, llmCallsConfigSchema as J, columnKindSchema as Jt, llmCallMetricPlacementSchema as K, columnDefSchema as Kt, runSummarySchema as L, traceAttributeDisplayPlacementSchema as Lt, getEvalDisplayStatus as M, serializedCacheSpanSchema as Mt, deriveScopedSummaryFromCases as N, spanCacheOptionsSchema as Nt, extractApiCalls as O, repoFile as On, cacheOperationTypeSchema as Ot, deriveStatusFromCaseRows as P, traceCacheRefSchema as Pt, trialSelectionModeSchema as Q, repoFileRefSchema as Qt, DEFAULT_API_CALLS_CONFIG as R, traceAttributeDisplaySchema as Rt, createFsCacheStore as S, runInEvalRuntimeScope as Sn, cacheDebugKeyFileSchema as St, sseEnvelopeSchema as T, setEvalOutput as Tn, cacheFileSchema as Tt, apiCallMetricSchema as U, traceSpanSchema as Ut, apiCallMetricFormatSchema as V, traceSpanErrorSchema as Vt, apiCallsConfigSchema as W, traceSpanWarningSchema as Wt, resolveLlmCallsConfig as X, jsonCellSchema as Xt, resolveApiCallsConfig as Y, fileRefSchema as Yt, runLogsConfigSchema as Z, numberDisplayOptionsSchema as Zt, loadEvalModule as _, getEvalCaseInput as _n, evalChartMetricSchema as _t, loadPersistedRunSnapshot as a, hashCacheKey as an, evalStatsConfigSchema as at, buildDeclaredColumnDefs as b, mergeEvalOutput as bn, evalChartsConfigSchema as bt, persistCaseDetail as c, deserializeCacheValue as cn, runLogLevelSchema as ct, recomputePersistedCaseStatus as d, EvalAssertionError as dn, scoreTraceSchema as dt, z$1 as en, caseDetailSchema as et, runTouchesEval as f, appendToEvalOutput as fn, evalChartAggregateSchema as ft, setLatestRunInfoMap as g, getCurrentScope as gn, evalChartConfigSchema as gt, getTargetEvalIds as h, evalLog as hn, evalChartColorSchema as ht, getLatestRunInfos as i, evalTracer as in, evalStatItemSchema as it, getEvalTitle as j, cacheStatusSchema as jt, extractLlmCalls as k, defineEval as kn, cacheRecordingOpSchema as kt, persistRunState as l, serializeCacheRecording as ln, runLogLocationSchema as lt, buildEvalSummary as m, evalAssert as mn, evalChartBuiltinMetricSchema as mt, generateRunId as n, captureEvalSpanError as nn, evalFreshnessStatusSchema as nt, loadPersistedRunSnapshots as o, hashCacheKeySync as on, evalSummarySchema as ot, resolveArtifactPath as p, configureEvalRunLogs as pn, evalChartAxisSchema as pt, llmCallMetricSchema as q, columnFormatSchema as qt, getLastRunStatuses as r, evalSpan as rn, evalStatAggregateSchema as rt, nextShortIdFromSnapshots as s, deserializeCacheRecording as sn, runLogEntrySchema as st, executeRun as t, buildTraceTree as tn, caseRowSchema as tt, recomputeEvalStatusesInRuns as u, serializeCacheValue as un, runLogPhaseSchema as ut, parseEvalMetas as v, incrementEvalOutput as vn, evalChartTooltipExtraSchema as vt, updateManualScoreRequestSchema as w, runInExistingEvalScope as wn, cacheEntryWithDebugKeySchema as wt, normalizeScoreDef as x, nextEvalId as xn, cacheDebugKeyEntrySchema as xt, loadConfig as y, isInEvalScope as yn, evalChartTypeSchema as yt, DEFAULT_LLM_CALLS_CONFIG as z, traceDisplayConfigSchema as zt };