@ls-stack/agent-eval 0.8.0 → 0.10.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.
@@ -105,6 +105,8 @@ function setScopeCacheContext(scope, context) {
105
105
  async function runInEvalScope(caseId, fn, options = {}) {
106
106
  const scope = {
107
107
  caseId,
108
+ idPrefix: options.idPrefix,
109
+ nextEvalIdCounter: 0,
108
110
  input: options.input,
109
111
  outputs: {},
110
112
  assertionFailures: [],
@@ -114,7 +116,8 @@ async function runInEvalScope(caseId, fn, options = {}) {
114
116
  activeSpanStack: [],
115
117
  recordingStack: [],
116
118
  replayingDepth: 0,
117
- cacheContext: options.cacheContext
119
+ cacheContext: options.cacheContext,
120
+ caseCacheRefs: []
118
121
  };
119
122
  activeEvalScopeCount++;
120
123
  try {
@@ -137,6 +140,21 @@ async function runInEvalScope(caseId, fn, options = {}) {
137
140
  activeEvalScopeCount--;
138
141
  }
139
142
  }
143
+ /**
144
+ * Return the next deterministic ID for the active eval case execution.
145
+ *
146
+ * The runner derives the ID prefix from the eval file, eval id, and case id,
147
+ * then this helper appends a per-scope sequence number. Calls outside an
148
+ * active eval case scope throw so accidental product-code usage is caught
149
+ * immediately.
150
+ */
151
+ function nextEvalId() {
152
+ const scope = getCurrentScope();
153
+ if (!scope) throw new Error("nextEvalId() must be called inside an active eval case");
154
+ if (scope.idPrefix === void 0) throw new Error("nextEvalId() requires a runner-provided eval id prefix");
155
+ scope.nextEvalIdCounter++;
156
+ return `${scope.idPrefix}-${scope.nextEvalIdCounter}`;
157
+ }
140
158
  function recordOpIfActive(scope, op) {
141
159
  if (scope.replayingDepth > 0) return;
142
160
  const top = scope.recordingStack.at(-1);
@@ -235,135 +253,1921 @@ function incrementEvalOutput(key, delta) {
235
253
  });
236
254
  return;
237
255
  }
238
- if (typeof existing !== "number") {
239
- scope.assertionFailures.push(toAssertionFailure$1(`incrementEvalOutput("${key}"): existing value is ${typeof existing}, expected number`));
240
- return;
256
+ if (typeof existing !== "number") {
257
+ scope.assertionFailures.push(toAssertionFailure$1(`incrementEvalOutput("${key}"): existing value is ${typeof existing}, expected number`));
258
+ return;
259
+ }
260
+ scope.outputs[key] = existing + delta;
261
+ recordOpIfActive(scope, {
262
+ kind: "incrementOutput",
263
+ key,
264
+ delta
265
+ });
266
+ }
267
+ /**
268
+ * Assert a condition for the current eval case and throw on failure.
269
+ *
270
+ * Calls made outside `runInEvalScope(...)` are ignored so shared workflow code
271
+ * can safely reuse `evalAssert(...)` when it also runs outside an eval.
272
+ */
273
+ function evalAssert(condition, message) {
274
+ if (condition) return;
275
+ const scope = getCurrentScope();
276
+ if (!scope) return;
277
+ const error = new EvalAssertionError(message);
278
+ scope.assertionFailures.push(toAssertionFailure$1(message, error));
279
+ throw error;
280
+ }
281
+ //#endregion
282
+ //#region ../sdk/src/cacheKey.ts
283
+ var SerializedCacheKeyValue = class {
284
+ value;
285
+ constructor(value) {
286
+ this.value = value;
287
+ }
288
+ };
289
+ /**
290
+ * Hash the components of a cache key into a deterministic hex digest.
291
+ *
292
+ * Native `Blob` and `File` values use stable metadata by default. Pass
293
+ * `serializeFileBytes: true` to read them asynchronously and include their byte
294
+ * hash in the key.
295
+ */
296
+ async function hashCacheKey(input, options = {}) {
297
+ return hashCacheKeySyncMaterialized(options.serializeFileBytes === true ? await materializeAsyncCacheKeyValue(input) : input);
298
+ }
299
+ /**
300
+ * Synchronously hash cache key components. This supports JSON-like data and
301
+ * in-memory binary values such as `Buffer`, `ArrayBuffer`, and typed arrays,
302
+ * plus stable metadata for native `Blob` and `File` values.
303
+ */
304
+ function hashCacheKeySync(input) {
305
+ return hashCacheKeySyncMaterialized(input);
306
+ }
307
+ function hashCacheKeySyncMaterialized(input) {
308
+ return createHash("sha256").update(getCompositeKey(input, { stringify: stringifyCacheKeyValue })).digest("hex");
309
+ }
310
+ function stringifyCacheKeyValue(value) {
311
+ if (value instanceof SerializedCacheKeyValue) return value.value;
312
+ if (Buffer$1.isBuffer(value)) return `$buffer:${hashBytes(value)}`;
313
+ if (isArrayBuffer(value)) return `$arrayBuffer:${hashBytes(new Uint8Array(value))}`;
314
+ if (isSharedArrayBuffer(value)) return `$sharedArrayBuffer:${hashBytes(new Uint8Array(value))}`;
315
+ if (isArrayBufferView(value)) {
316
+ const bytes = new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
317
+ return `$${value.constructor.name}:${hashBytes(bytes)}`;
318
+ }
319
+ if (isFile$1(value)) return `$file:${getCompositeKey({
320
+ lastModified: value.lastModified,
321
+ name: value.name,
322
+ size: value.size,
323
+ type: value.type
324
+ })}`;
325
+ if (isBlob$1(value)) return `$blob:${getCompositeKey({
326
+ size: value.size,
327
+ type: value.type
328
+ })}`;
329
+ }
330
+ async function materializeAsyncCacheKeyValue(value, refs = /* @__PURE__ */ new WeakSet()) {
331
+ const serialized = await stringifyAsyncCacheKeyValue(value);
332
+ if (serialized !== void 0) return new SerializedCacheKeyValue(serialized);
333
+ if (stringifyCacheKeyValue(value) !== void 0) return value;
334
+ if (!value || typeof value !== "object") return value;
335
+ if (Array.isArray(value)) {
336
+ const items = [];
337
+ for (const item of value) items.push(await materializeAsyncCacheKeyValue(item, refs));
338
+ return items;
339
+ }
340
+ if (refs.has(value)) throw new Error("Circular reference detected");
341
+ refs.add(value);
342
+ const entries = [];
343
+ for (const [key, entryValue] of Object.entries(value)) entries.push([key, await materializeAsyncCacheKeyValue(entryValue, refs)]);
344
+ refs.delete(value);
345
+ return Object.fromEntries(entries);
346
+ }
347
+ async function stringifyAsyncCacheKeyValue(value) {
348
+ if (isFile$1(value)) return `$file:${getCompositeKey({
349
+ bytes: await hashBlobBytes(value),
350
+ lastModified: value.lastModified,
351
+ name: value.name,
352
+ size: value.size,
353
+ type: value.type
354
+ })}`;
355
+ if (isBlob$1(value)) return `$blob:${getCompositeKey({
356
+ bytes: await hashBlobBytes(value),
357
+ size: value.size,
358
+ type: value.type
359
+ })}`;
360
+ }
361
+ async function hashBlobBytes(value) {
362
+ return hashBytes(new Uint8Array(await value.arrayBuffer()));
363
+ }
364
+ function hashBytes(value) {
365
+ return createHash("sha256").update(value).digest("hex");
366
+ }
367
+ function isArrayBuffer(value) {
368
+ return value instanceof ArrayBuffer;
369
+ }
370
+ function isSharedArrayBuffer(value) {
371
+ return value instanceof SharedArrayBuffer;
372
+ }
373
+ function isArrayBufferView(value) {
374
+ return ArrayBuffer.isView(value);
375
+ }
376
+ function isBlob$1(value) {
377
+ return value instanceof Blob;
378
+ }
379
+ function isFile$1(value) {
380
+ return value instanceof File;
381
+ }
382
+ //#endregion
383
+ //#region ../../node_modules/.pnpm/seroval@1.5.2/node_modules/seroval/dist/esm/production/index.mjs
384
+ 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 || {});
385
+ 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 = {
386
+ [v$1]: 0,
387
+ [mr]: 1,
388
+ [R]: 2,
389
+ [C]: 3,
390
+ [pr]: 4,
391
+ [dr]: 5,
392
+ [gr]: 6,
393
+ [yr]: 7,
394
+ [Nr]: 8,
395
+ [br]: 9,
396
+ [vr]: 10,
397
+ [P$1]: 11,
398
+ [Cr]: 12
399
+ }, tt = {
400
+ 0: v$1,
401
+ 1: mr,
402
+ 2: R,
403
+ 3: C,
404
+ 4: pr,
405
+ 5: dr,
406
+ 6: gr,
407
+ 7: yr,
408
+ 8: Nr,
409
+ 9: br,
410
+ 10: vr,
411
+ 11: P$1,
412
+ 12: Cr
413
+ }, o$1 = void 0, ot = {
414
+ 2: !0,
415
+ 3: !1,
416
+ 1: o$1,
417
+ 0: null,
418
+ 4: -0,
419
+ 5: Number.POSITIVE_INFINITY,
420
+ 6: Number.NEGATIVE_INFINITY,
421
+ 7: NaN
422
+ };
423
+ var Ce = {
424
+ 0: "Error",
425
+ 1: "EvalError",
426
+ 2: "RangeError",
427
+ 3: "ReferenceError",
428
+ 4: "SyntaxError",
429
+ 5: "TypeError",
430
+ 6: "URIError"
431
+ }, at = {
432
+ 0: Error,
433
+ 1: EvalError,
434
+ 2: RangeError,
435
+ 3: ReferenceError,
436
+ 4: SyntaxError,
437
+ 5: TypeError,
438
+ 6: URIError
439
+ };
440
+ function c$1(e, r, t, n, a, s, i, u, l, g, S, d) {
441
+ return {
442
+ t: e,
443
+ i: r,
444
+ s: t,
445
+ c: n,
446
+ m: a,
447
+ p: s,
448
+ e: i,
449
+ a: u,
450
+ f: l,
451
+ b: g,
452
+ o: S,
453
+ l: d
454
+ };
455
+ }
456
+ function B$1(e) {
457
+ 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);
458
+ }
459
+ 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);
460
+ function fn(e) {
461
+ switch (e) {
462
+ case "\"": return "\\\"";
463
+ case "\\": return "\\\\";
464
+ case `
465
+ `: return "\\n";
466
+ case "\r": return "\\r";
467
+ case "\b": return "\\b";
468
+ case " ": return "\\t";
469
+ case "\f": return "\\f";
470
+ case "<": return "\\x3C";
471
+ case "\u2028": return "\\u2028";
472
+ case "\u2029": return "\\u2029";
473
+ default: return o$1;
474
+ }
475
+ }
476
+ function y$1(e) {
477
+ let r = "", t = 0, n;
478
+ for (let a = 0, s = e.length; a < s; a++) n = fn(e[a]), n && (r += e.slice(t, a) + n, t = a + 1);
479
+ return t === 0 ? r = e : r += e.slice(t), r;
480
+ }
481
+ function Sn(e) {
482
+ switch (e) {
483
+ case "\\\\": return "\\";
484
+ case "\\\"": return "\"";
485
+ case "\\n": return `
486
+ `;
487
+ case "\\r": return "\r";
488
+ case "\\b": return "\b";
489
+ case "\\t": return " ";
490
+ case "\\f": return "\f";
491
+ case "\\x3C": return "<";
492
+ case "\\u2028": return "\u2028";
493
+ case "\\u2029": return "\u2029";
494
+ default: return e;
495
+ }
496
+ }
497
+ function D$1(e) {
498
+ return e.replace(/(\\\\|\\"|\\n|\\r|\\b|\\t|\\f|\\u2028|\\u2029|\\x3C)/g, Sn);
499
+ }
500
+ var U = "__SEROVAL_REFS__";
501
+ var Ar = /* @__PURE__ */ new Map(), j = /* @__PURE__ */ new Map();
502
+ function Er(e) {
503
+ return Ar.has(e);
504
+ }
505
+ function dn(e) {
506
+ return j.has(e);
507
+ }
508
+ function ct(e) {
509
+ if (Er(e)) return Ar.get(e);
510
+ throw new Re(e);
511
+ }
512
+ function ft(e) {
513
+ if (dn(e)) return j.get(e);
514
+ throw new Pe(e);
515
+ }
516
+ typeof globalThis != "undefined" ? Object.defineProperty(globalThis, U, {
517
+ value: j,
518
+ configurable: !0,
519
+ writable: !1,
520
+ enumerable: !1
521
+ }) : typeof window != "undefined" ? Object.defineProperty(window, U, {
522
+ value: j,
523
+ configurable: !0,
524
+ writable: !1,
525
+ enumerable: !1
526
+ }) : typeof self != "undefined" ? Object.defineProperty(self, U, {
527
+ value: j,
528
+ configurable: !0,
529
+ writable: !1,
530
+ enumerable: !1
531
+ }) : typeof global != "undefined" && Object.defineProperty(global, U, {
532
+ value: j,
533
+ configurable: !0,
534
+ writable: !1,
535
+ enumerable: !1
536
+ });
537
+ function xe(e) {
538
+ 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;
539
+ }
540
+ function gn(e) {
541
+ let r = Ce[xe(e)];
542
+ return e.name !== r ? { name: e.name } : e.constructor.name !== r ? { name: e.constructor.name } : {};
543
+ }
544
+ function $$1(e, r) {
545
+ let t = gn(e), n = Object.getOwnPropertyNames(e);
546
+ 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]));
547
+ return t;
548
+ }
549
+ function Oe(e) {
550
+ return Object.isFrozen(e) ? 3 : Object.isSealed(e) ? 2 : Object.isExtensible(e) ? 0 : 1;
551
+ }
552
+ function Te(e) {
553
+ switch (e) {
554
+ case Number.POSITIVE_INFINITY: return it;
555
+ case Number.NEGATIVE_INFINITY: return ut;
556
+ }
557
+ 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);
558
+ }
559
+ function X(e) {
560
+ 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);
561
+ }
562
+ function we(e) {
563
+ 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);
564
+ }
565
+ function mt(e) {
566
+ 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);
567
+ }
568
+ function he(e, r) {
569
+ let t = r.valueOf();
570
+ 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);
571
+ }
572
+ function ze(e, r) {
573
+ 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);
574
+ }
575
+ function pt(e, r) {
576
+ 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);
577
+ }
578
+ function dt(e, r) {
579
+ 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);
580
+ }
581
+ function fe$1(e, r, t) {
582
+ 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);
583
+ }
584
+ function _e(e, r, t) {
585
+ return c$1(9, e, o$1, o$1, o$1, o$1, o$1, t, o$1, o$1, Oe(r), o$1);
586
+ }
587
+ function ke(e, r) {
588
+ return c$1(21, e, o$1, o$1, o$1, o$1, o$1, o$1, r, o$1, o$1, o$1);
589
+ }
590
+ function De(e, r, t) {
591
+ 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);
592
+ }
593
+ function Fe(e, r, t) {
594
+ 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);
595
+ }
596
+ function Be(e, r, t) {
597
+ return c$1(20, e, o$1, o$1, o$1, o$1, o$1, o$1, t, r.byteOffset, o$1, r.byteLength);
598
+ }
599
+ function Ve(e, r, t) {
600
+ 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);
601
+ }
602
+ function Me(e, r, t) {
603
+ 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);
604
+ }
605
+ function Le(e, r) {
606
+ return c$1(7, e, o$1, o$1, o$1, o$1, o$1, r, o$1, o$1, o$1, o$1);
607
+ }
608
+ function Ue(e, r) {
609
+ 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);
610
+ }
611
+ function je(e, r) {
612
+ 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);
613
+ }
614
+ function Ye(e, r, t) {
615
+ return c$1(31, e, o$1, o$1, o$1, o$1, o$1, t, r, o$1, o$1, o$1);
616
+ }
617
+ function qe(e, r) {
618
+ return c$1(32, e, o$1, o$1, o$1, o$1, o$1, o$1, r, o$1, o$1, o$1);
619
+ }
620
+ function We(e, r) {
621
+ return c$1(33, e, o$1, o$1, o$1, o$1, o$1, o$1, r, o$1, o$1, o$1);
622
+ }
623
+ function Ge(e, r) {
624
+ return c$1(34, e, o$1, o$1, o$1, o$1, o$1, o$1, r, o$1, o$1, o$1);
625
+ }
626
+ function Ke(e, r, t, n) {
627
+ return c$1(35, e, t, o$1, o$1, o$1, o$1, r, o$1, o$1, o$1, n);
628
+ }
629
+ var { toString: ys } = Object.prototype;
630
+ var yn = {
631
+ parsing: 1,
632
+ serialization: 2,
633
+ deserialization: 3
634
+ };
635
+ function Nn(e) {
636
+ return `Seroval Error (step: ${yn[e]})`;
637
+ }
638
+ var bn = (e, r) => Nn(e), Se = class extends Error {
639
+ constructor(t, n) {
640
+ super(bn(t, n));
641
+ this.cause = n;
642
+ }
643
+ }, z$2 = class extends Se {
644
+ constructor(r) {
645
+ super("parsing", r);
646
+ }
647
+ }, He = class extends Se {
648
+ constructor(r) {
649
+ super("deserialization", r);
650
+ }
651
+ };
652
+ function _(e) {
653
+ return `Seroval Error (specific: ${e})`;
654
+ }
655
+ var x$1 = class extends Error {
656
+ constructor(t) {
657
+ super(_(1));
658
+ this.value = t;
659
+ }
660
+ }, w$1 = class extends Error {
661
+ constructor(r) {
662
+ super(_(2));
663
+ }
664
+ }, Q = class extends Error {
665
+ constructor(r) {
666
+ super(_(3));
667
+ }
668
+ }, V = class extends Error {
669
+ constructor(r) {
670
+ super(_(4));
671
+ }
672
+ }, Re = class extends Error {
673
+ constructor(t) {
674
+ super(_(5));
675
+ this.value = t;
676
+ }
677
+ }, Pe = class extends Error {
678
+ constructor(r) {
679
+ super(_(6));
680
+ }
681
+ }, Je = class extends Error {
682
+ constructor(r) {
683
+ super(_(7));
684
+ }
685
+ }, h$1 = class extends Error {
686
+ constructor(r) {
687
+ super(_(8));
688
+ }
689
+ }, ee = class extends Error {
690
+ constructor(r) {
691
+ super(_(9));
692
+ }
693
+ }, Y$1 = class {
694
+ constructor(r, t) {
695
+ this.value = r;
696
+ this.replacement = t;
697
+ }
698
+ }, re = () => {
699
+ let e = {
700
+ p: 0,
701
+ s: 0,
702
+ f: 0
703
+ };
704
+ return e.p = new Promise((r, t) => {
705
+ e.s = r, e.f = t;
706
+ }), e;
707
+ }, vn = (e, r) => {
708
+ e.s(r), e.p.s = 1, e.p.v = r;
709
+ }, Cn = (e, r) => {
710
+ e.f(r), e.p.s = 2, e.p.v = r;
711
+ };
712
+ re.toString();
713
+ vn.toString();
714
+ Cn.toString();
715
+ var Rr = () => {
716
+ let e = [], r = [], t = !0, n = !1, a = 0, s = (l, g, S) => {
717
+ for (S = 0; S < a; S++) r[S] && r[S][g](l);
718
+ }, i = (l, g, S, d) => {
719
+ for (g = 0, S = e.length; g < S; g++) d = e[g], !t && g === S - 1 ? l[n ? "return" : "throw"](d) : l.next(d);
720
+ }, u = (l, g) => (t && (g = a++, r[g] = l), i(l), () => {
721
+ t && (r[g] = r[a], r[a--] = void 0);
722
+ });
723
+ return {
724
+ __SEROVAL_STREAM__: !0,
725
+ on: (l) => u(l),
726
+ next: (l) => {
727
+ t && (e.push(l), s(l, "next"));
728
+ },
729
+ throw: (l) => {
730
+ t && (e.push(l), s(l, "throw"), t = !1, n = !1, r.length = 0);
731
+ },
732
+ return: (l) => {
733
+ t && (e.push(l), s(l, "return"), t = !1, n = !0, r.length = 0);
734
+ }
735
+ };
736
+ };
737
+ Rr.toString();
738
+ var Pr = (e) => (r) => () => {
739
+ let t = 0, n = {
740
+ [e]: () => n,
741
+ next: () => {
742
+ if (t > r.d) return {
743
+ done: !0,
744
+ value: void 0
745
+ };
746
+ let a = t++, s = r.v[a];
747
+ if (a === r.t) throw s;
748
+ return {
749
+ done: a === r.d,
750
+ value: s
751
+ };
752
+ }
753
+ };
754
+ return n;
755
+ };
756
+ Pr.toString();
757
+ var xr = (e, r) => (t) => () => {
758
+ let n = 0, a = -1, s = !1, i = [], u = [], l = (S = 0, d = u.length) => {
759
+ for (; S < d; S++) u[S].s({
760
+ done: !0,
761
+ value: void 0
762
+ });
763
+ };
764
+ t.on({
765
+ next: (S) => {
766
+ let d = u.shift();
767
+ d && d.s({
768
+ done: !1,
769
+ value: S
770
+ }), i.push(S);
771
+ },
772
+ throw: (S) => {
773
+ let d = u.shift();
774
+ d && d.f(S), l(), a = i.length, s = !0, i.push(S);
775
+ },
776
+ return: (S) => {
777
+ let d = u.shift();
778
+ d && d.s({
779
+ done: !0,
780
+ value: S
781
+ }), l(), a = i.length, i.push(S);
782
+ }
783
+ });
784
+ let g = {
785
+ [e]: () => g,
786
+ next: () => {
787
+ if (a === -1) {
788
+ let K = n++;
789
+ if (K >= i.length) {
790
+ let et = r();
791
+ return u.push(et), et.p;
792
+ }
793
+ return {
794
+ done: !1,
795
+ value: i[K]
796
+ };
797
+ }
798
+ if (n > a) return {
799
+ done: !0,
800
+ value: void 0
801
+ };
802
+ let S = n++, d = i[S];
803
+ if (S !== a) return {
804
+ done: !1,
805
+ value: d
806
+ };
807
+ if (s) throw d;
808
+ return {
809
+ done: !0,
810
+ value: d
811
+ };
812
+ }
813
+ };
814
+ return g;
815
+ };
816
+ xr.toString();
817
+ var Or = (e) => {
818
+ let r = atob(e), t = r.length, n = new Uint8Array(t);
819
+ for (let a = 0; a < t; a++) n[a] = r.charCodeAt(a);
820
+ return n.buffer;
821
+ };
822
+ Or.toString();
823
+ function Ze(e) {
824
+ return "__SEROVAL_SEQUENCE__" in e;
825
+ }
826
+ function Tr(e, r, t) {
827
+ return {
828
+ __SEROVAL_SEQUENCE__: !0,
829
+ v: e,
830
+ t: r,
831
+ d: t
832
+ };
833
+ }
834
+ function $e(e) {
835
+ let r = [], t = -1, n = -1, a = e[C]();
836
+ for (;;) try {
837
+ let s = a.next();
838
+ if (r.push(s.value), s.done) {
839
+ n = r.length - 1;
840
+ break;
841
+ }
842
+ } catch (s) {
843
+ t = r.length, r.push(s);
844
+ }
845
+ return Tr(r, t, n);
846
+ }
847
+ var An = Pr(C);
848
+ function It(e) {
849
+ return An(e);
850
+ }
851
+ var Rt = {}, Pt = {}, xt = {
852
+ 0: {},
853
+ 1: {},
854
+ 2: {},
855
+ 3: {},
856
+ 4: {},
857
+ 5: {}
858
+ };
859
+ function M(e) {
860
+ return "__SEROVAL_STREAM__" in e;
861
+ }
862
+ function te$1() {
863
+ return Rr();
864
+ }
865
+ function Xe(e) {
866
+ let r = te$1(), t = e[v$1]();
867
+ async function n() {
868
+ try {
869
+ let a = await t.next();
870
+ a.done ? r.return(a.value) : (r.next(a.value), await n());
871
+ } catch (a) {
872
+ r.throw(a);
873
+ }
874
+ }
875
+ return n().catch(() => {}), r;
876
+ }
877
+ var En = xr(v$1, re);
878
+ function Tt(e) {
879
+ return En(e);
880
+ }
881
+ async function wr(e) {
882
+ try {
883
+ return [1, await e];
884
+ } catch (r) {
885
+ return [0, r];
886
+ }
887
+ }
888
+ function pe$1(e, r) {
889
+ return {
890
+ plugins: r.plugins,
891
+ mode: e,
892
+ marked: /* @__PURE__ */ new Set(),
893
+ features: 63 ^ (r.disabledFeatures || 0),
894
+ refs: r.refs || /* @__PURE__ */ new Map(),
895
+ depthLimit: r.depthLimit || 1e3
896
+ };
897
+ }
898
+ function de(e, r) {
899
+ e.marked.add(r);
900
+ }
901
+ function hr(e, r) {
902
+ let t = e.refs.size;
903
+ return e.refs.set(r, t), t;
904
+ }
905
+ function Qe(e, r) {
906
+ let t = e.refs.get(r);
907
+ return t != null ? (de(e, t), {
908
+ type: 1,
909
+ value: mt(t)
910
+ }) : {
911
+ type: 0,
912
+ value: hr(e, r)
913
+ };
914
+ }
915
+ function q$1(e, r) {
916
+ let t = Qe(e, r);
917
+ return t.type === 1 ? t : Er(r) ? {
918
+ type: 2,
919
+ value: dt(t.value, r)
920
+ } : t;
921
+ }
922
+ function I(e, r) {
923
+ let t = q$1(e, r);
924
+ if (t.type !== 0) return t.value;
925
+ if (r in ve) return pt(t.value, r);
926
+ throw new x$1(r);
927
+ }
928
+ function k(e, r) {
929
+ let t = Qe(e, xt[r]);
930
+ 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);
931
+ }
932
+ function er(e) {
933
+ let r = Qe(e, Rt);
934
+ 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);
935
+ }
936
+ function rr(e) {
937
+ let r = Qe(e, Pt);
938
+ 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);
939
+ }
940
+ function tr(e, r, t, n) {
941
+ 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);
942
+ }
943
+ function nr(e, r, t, n) {
944
+ return c$1(8, r, o$1, o$1, o$1, o$1, {
945
+ k: t,
946
+ v: n
947
+ }, o$1, k(e, 0), o$1, o$1, o$1);
948
+ }
949
+ function or(e, r, t) {
950
+ let n = new Uint8Array(t), a = "";
951
+ for (let s = 0, i = n.length; s < i; s++) a += String.fromCharCode(n[s]);
952
+ 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);
953
+ }
954
+ function ne$1(e, r) {
955
+ return {
956
+ base: pe$1(e, r),
957
+ child: void 0
958
+ };
959
+ }
960
+ var _r = class {
961
+ constructor(r, t) {
962
+ this._p = r;
963
+ this.depth = t;
964
+ }
965
+ parse(r) {
966
+ return N$1(this._p, this.depth, r);
967
+ }
968
+ };
969
+ async function Rn(e, r, t) {
970
+ let n = [];
971
+ 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;
972
+ return n;
973
+ }
974
+ async function Pn(e, r, t, n) {
975
+ return _e(t, n, await Rn(e, r, n));
976
+ }
977
+ async function kr(e, r, t) {
978
+ let n = Object.entries(t), a = [], s = [];
979
+ 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]));
980
+ 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)), {
981
+ k: a,
982
+ v: s
983
+ };
984
+ }
985
+ async function zr(e, r, t, n, a) {
986
+ return tr(t, n, a, await kr(e, r, n));
987
+ }
988
+ async function xn(e, r, t, n) {
989
+ return ke(t, await N$1(e, r, n.valueOf()));
990
+ }
991
+ async function On(e, r, t, n) {
992
+ return De(t, n, await N$1(e, r, n.buffer));
993
+ }
994
+ async function Tn(e, r, t, n) {
995
+ return Fe(t, n, await N$1(e, r, n.buffer));
996
+ }
997
+ async function wn(e, r, t, n) {
998
+ return Be(t, n, await N$1(e, r, n.buffer));
999
+ }
1000
+ async function zt(e, r, t, n) {
1001
+ let a = $$1(n, e.base.features);
1002
+ return Ve(t, n, a ? await kr(e, r, a) : o$1);
1003
+ }
1004
+ async function hn(e, r, t, n) {
1005
+ let a = $$1(n, e.base.features);
1006
+ return Me(t, n, a ? await kr(e, r, a) : o$1);
1007
+ }
1008
+ async function zn(e, r, t, n) {
1009
+ let a = [], s = [];
1010
+ for (let [i, u] of n.entries()) a.push(await N$1(e, r, i)), s.push(await N$1(e, r, u));
1011
+ return nr(e.base, t, a, s);
1012
+ }
1013
+ async function _n(e, r, t, n) {
1014
+ let a = [];
1015
+ for (let s of n.keys()) a.push(await N$1(e, r, s));
1016
+ return Le(t, a);
1017
+ }
1018
+ async function _t(e, r, t, n) {
1019
+ let a = e.base.plugins;
1020
+ if (a) for (let s = 0, i = a.length; s < i; s++) {
1021
+ let u = a[s];
1022
+ if (u.parse.async && u.test(n)) return fe$1(t, u.tag, await u.parse.async(n, new _r(e, r), { id: t }));
1023
+ }
1024
+ return o$1;
1025
+ }
1026
+ async function kn(e, r, t, n) {
1027
+ let [a, s] = await wr(n);
1028
+ 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);
1029
+ }
1030
+ function Dn(e, r, t, n, a) {
1031
+ let s = [], i = t.on({
1032
+ next: (u) => {
1033
+ de(this.base, r), N$1(this, e, u).then((l) => {
1034
+ s.push(qe(r, l));
1035
+ }, (l) => {
1036
+ a(l), i();
1037
+ });
1038
+ },
1039
+ throw: (u) => {
1040
+ de(this.base, r), N$1(this, e, u).then((l) => {
1041
+ s.push(We(r, l)), n(s), i();
1042
+ }, (l) => {
1043
+ a(l), i();
1044
+ });
1045
+ },
1046
+ return: (u) => {
1047
+ de(this.base, r), N$1(this, e, u).then((l) => {
1048
+ s.push(Ge(r, l)), n(s), i();
1049
+ }, (l) => {
1050
+ a(l), i();
1051
+ });
1052
+ }
1053
+ });
1054
+ }
1055
+ async function Fn(e, r, t, n) {
1056
+ return Ye(t, k(e.base, 4), await new Promise(Dn.bind(e, r, t, n)));
1057
+ }
1058
+ async function Bn(e, r, t, n) {
1059
+ let a = [];
1060
+ for (let s = 0, i = n.v.length; s < i; s++) a[s] = await N$1(e, r, n.v[s]);
1061
+ return Ke(t, a, n.t, n.d);
1062
+ }
1063
+ async function Vn(e, r, t, n) {
1064
+ if (Array.isArray(n)) return Pn(e, r, t, n);
1065
+ if (M(n)) return Fn(e, r, t, n);
1066
+ if (Ze(n)) return Bn(e, r, t, n);
1067
+ let a = n.constructor;
1068
+ if (a === Y$1) return N$1(e, r, n.replacement);
1069
+ let s = await _t(e, r, t, n);
1070
+ if (s) return s;
1071
+ switch (a) {
1072
+ case Object: return zr(e, r, t, n, !1);
1073
+ case o$1: return zr(e, r, t, n, !0);
1074
+ case Date: return he(t, n);
1075
+ case Error:
1076
+ case EvalError:
1077
+ case RangeError:
1078
+ case ReferenceError:
1079
+ case SyntaxError:
1080
+ case TypeError:
1081
+ case URIError: return zt(e, r, t, n);
1082
+ case Number:
1083
+ case Boolean:
1084
+ case String:
1085
+ case BigInt: return xn(e, r, t, n);
1086
+ case ArrayBuffer: return or(e.base, t, n);
1087
+ case Int8Array:
1088
+ case Int16Array:
1089
+ case Int32Array:
1090
+ case Uint8Array:
1091
+ case Uint16Array:
1092
+ case Uint32Array:
1093
+ case Uint8ClampedArray:
1094
+ case Float32Array:
1095
+ case Float64Array: return On(e, r, t, n);
1096
+ case DataView: return wn(e, r, t, n);
1097
+ case Map: return zn(e, r, t, n);
1098
+ case Set: return _n(e, r, t, n);
1099
+ default: break;
1100
+ }
1101
+ if (a === Promise || n instanceof Promise) return kn(e, r, t, n);
1102
+ let i = e.base.features;
1103
+ if (i & 32 && a === RegExp) return ze(t, n);
1104
+ if (i & 16) switch (a) {
1105
+ case BigInt64Array:
1106
+ case BigUint64Array: return Tn(e, r, t, n);
1107
+ default: break;
1108
+ }
1109
+ if (i & 1 && typeof AggregateError != "undefined" && (a === AggregateError || n instanceof AggregateError)) return hn(e, r, t, n);
1110
+ if (n instanceof Error) return zt(e, r, t, n);
1111
+ if (C in n || v$1 in n) return zr(e, r, t, n, !!a);
1112
+ throw new x$1(n);
1113
+ }
1114
+ async function Mn(e, r, t) {
1115
+ let n = q$1(e.base, t);
1116
+ if (n.type !== 0) return n.value;
1117
+ let a = await _t(e, r, n.value, t);
1118
+ if (a) return a;
1119
+ throw new x$1(t);
1120
+ }
1121
+ async function N$1(e, r, t) {
1122
+ switch (typeof t) {
1123
+ case "boolean": return t ? J : Z;
1124
+ case "undefined": return Ae;
1125
+ case "string": return X(t);
1126
+ case "number": return Te(t);
1127
+ case "bigint": return we(t);
1128
+ case "object":
1129
+ if (t) {
1130
+ let n = q$1(e.base, t);
1131
+ return n.type === 0 ? await Vn(e, r + 1, n.value, t) : n.value;
1132
+ }
1133
+ return Ee;
1134
+ case "symbol": return I(e.base, t);
1135
+ case "function": return Mn(e, r, t);
1136
+ default: throw new x$1(t);
1137
+ }
1138
+ }
1139
+ async function oe(e, r) {
1140
+ try {
1141
+ return await N$1(e, 0, r);
1142
+ } catch (t) {
1143
+ throw t instanceof z$2 ? t : new z$2(t);
1144
+ }
1145
+ }
1146
+ var ae = ((t) => (t[t.Vanilla = 1] = "Vanilla", t[t.Cross = 2] = "Cross", t))(ae || {});
1147
+ function ni(e) {
1148
+ return e;
1149
+ }
1150
+ function kt(e, r) {
1151
+ for (let t = 0, n = r.length; t < n; t++) {
1152
+ let a = r[t];
1153
+ e.has(a) || (e.add(a), a.extends && kt(e, a.extends));
1154
+ }
1155
+ }
1156
+ function A(e) {
1157
+ if (e) {
1158
+ let r = /* @__PURE__ */ new Set();
1159
+ return kt(r, e), [...r];
1160
+ }
1161
+ }
1162
+ function Dt(e) {
1163
+ switch (e) {
1164
+ case "Int8Array": return Int8Array;
1165
+ case "Int16Array": return Int16Array;
1166
+ case "Int32Array": return Int32Array;
1167
+ case "Uint8Array": return Uint8Array;
1168
+ case "Uint16Array": return Uint16Array;
1169
+ case "Uint32Array": return Uint32Array;
1170
+ case "Uint8ClampedArray": return Uint8ClampedArray;
1171
+ case "Float32Array": return Float32Array;
1172
+ case "Float64Array": return Float64Array;
1173
+ case "BigInt64Array": return BigInt64Array;
1174
+ case "BigUint64Array": return BigUint64Array;
1175
+ default: throw new Je(e);
1176
+ }
1177
+ }
1178
+ var Ln = 1e6, Un = 1e4, jn = 2e4;
1179
+ function Bt(e, r) {
1180
+ switch (r) {
1181
+ case 3: return Object.freeze(e);
1182
+ case 1: return Object.preventExtensions(e);
1183
+ case 2: return Object.seal(e);
1184
+ default: return e;
1185
+ }
1186
+ }
1187
+ var Yn = 1e3;
1188
+ function Vt(e, r) {
1189
+ var t;
1190
+ return {
1191
+ mode: e,
1192
+ plugins: r.plugins,
1193
+ refs: r.refs || /* @__PURE__ */ new Map(),
1194
+ features: (t = r.features) != null ? t : 63 ^ (r.disabledFeatures || 0),
1195
+ depthLimit: r.depthLimit || Yn
1196
+ };
1197
+ }
1198
+ function Mt(e) {
1199
+ return {
1200
+ mode: 1,
1201
+ base: Vt(1, e),
1202
+ child: o$1,
1203
+ state: { marked: new Set(e.markedRefs) }
1204
+ };
1205
+ }
1206
+ var Dr = class {
1207
+ constructor(r, t) {
1208
+ this._p = r;
1209
+ this.depth = t;
1210
+ }
1211
+ deserialize(r) {
1212
+ return p$1(this._p, this.depth, r);
1213
+ }
1214
+ };
1215
+ function Ut(e, r) {
1216
+ if (r < 0 || !Number.isFinite(r) || !Number.isInteger(r)) throw new h$1({
1217
+ t: 4,
1218
+ i: r
1219
+ });
1220
+ if (e.refs.has(r)) throw new Error("Conflicted ref id: " + r);
1221
+ }
1222
+ function qn(e, r, t) {
1223
+ return Ut(e.base, r), e.state.marked.has(r) && e.base.refs.set(r, t), t;
1224
+ }
1225
+ function Wn(e, r, t) {
1226
+ return Ut(e.base, r), e.base.refs.set(r, t), t;
1227
+ }
1228
+ function b(e, r, t) {
1229
+ return e.mode === 1 ? qn(e, r, t) : Wn(e, r, t);
1230
+ }
1231
+ function Fr(e, r, t) {
1232
+ if (Object.hasOwn(r, t)) return r[t];
1233
+ throw new h$1(e);
1234
+ }
1235
+ function Gn(e, r) {
1236
+ return b(e, r.i, ft(D$1(r.s)));
1237
+ }
1238
+ function Kn(e, r, t) {
1239
+ let n = t.a, a = n.length, s = b(e, t.i, new Array(a));
1240
+ for (let i = 0, u; i < a; i++) u = n[i], u && (s[i] = p$1(e, r, u));
1241
+ return Bt(s, t.o), s;
1242
+ }
1243
+ function Hn(e) {
1244
+ switch (e) {
1245
+ case "constructor":
1246
+ case "__proto__":
1247
+ case "prototype":
1248
+ case "__defineGetter__":
1249
+ case "__defineSetter__":
1250
+ case "__lookupGetter__":
1251
+ case "__lookupSetter__": return !1;
1252
+ default: return !0;
1253
+ }
1254
+ }
1255
+ function Jn(e) {
1256
+ switch (e) {
1257
+ case v$1:
1258
+ case R:
1259
+ case P$1:
1260
+ case C: return !0;
1261
+ default: return !1;
1262
+ }
1263
+ }
1264
+ function Ft(e, r, t) {
1265
+ Hn(r) ? e[r] = t : Object.defineProperty(e, r, {
1266
+ value: t,
1267
+ configurable: !0,
1268
+ enumerable: !0,
1269
+ writable: !0
1270
+ });
1271
+ }
1272
+ function Zn(e, r, t, n, a) {
1273
+ if (typeof n == "string") Ft(t, D$1(n), p$1(e, r, a));
1274
+ else {
1275
+ let s = p$1(e, r, n);
1276
+ switch (typeof s) {
1277
+ case "string":
1278
+ Ft(t, s, p$1(e, r, a));
1279
+ break;
1280
+ case "symbol":
1281
+ Jn(s) && (t[s] = p$1(e, r, a));
1282
+ break;
1283
+ default: throw new h$1(n);
1284
+ }
1285
+ }
1286
+ }
1287
+ function jt(e, r, t, n) {
1288
+ let a = t.k;
1289
+ 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]);
1290
+ return n;
1291
+ }
1292
+ function $n(e, r, t) {
1293
+ let n = b(e, t.i, t.t === 10 ? {} : Object.create(null));
1294
+ return jt(e, r, t.p, n), Bt(n, t.o), n;
1295
+ }
1296
+ function Xn(e, r) {
1297
+ return b(e, r.i, new Date(r.s));
1298
+ }
1299
+ function Qn(e, r) {
1300
+ if (e.base.features & 32) {
1301
+ let t = D$1(r.c);
1302
+ if (t.length > jn) throw new h$1(r);
1303
+ return b(e, r.i, new RegExp(t, r.m));
1304
+ }
1305
+ throw new w$1(r);
1306
+ }
1307
+ function eo(e, r, t) {
1308
+ let n = b(e, t.i, /* @__PURE__ */ new Set());
1309
+ for (let a = 0, s = t.a, i = s.length; a < i; a++) n.add(p$1(e, r, s[a]));
1310
+ return n;
1311
+ }
1312
+ function ro(e, r, t) {
1313
+ let n = b(e, t.i, /* @__PURE__ */ new Map());
1314
+ 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]));
1315
+ return n;
1316
+ }
1317
+ function to(e, r) {
1318
+ if (r.s.length > Ln) throw new h$1(r);
1319
+ return b(e, r.i, Or(D$1(r.s)));
1320
+ }
1321
+ function no(e, r, t) {
1322
+ var u;
1323
+ let n = Dt(t.c), a = p$1(e, r, t.f), s = (u = t.b) != null ? u : 0;
1324
+ if (s < 0 || s > a.byteLength) throw new h$1(t);
1325
+ return b(e, t.i, new n(a, s, t.l));
1326
+ }
1327
+ function oo(e, r, t) {
1328
+ var i;
1329
+ let n = p$1(e, r, t.f), a = (i = t.b) != null ? i : 0;
1330
+ if (a < 0 || a > n.byteLength) throw new h$1(t);
1331
+ return b(e, t.i, new DataView(n, a, t.l));
1332
+ }
1333
+ function Yt(e, r, t, n) {
1334
+ if (t.p) {
1335
+ let a = jt(e, r, t.p, {});
1336
+ Object.defineProperties(n, Object.getOwnPropertyDescriptors(a));
1337
+ }
1338
+ return n;
1339
+ }
1340
+ function ao(e, r, t) {
1341
+ return Yt(e, r, t, b(e, t.i, new AggregateError([], D$1(t.m))));
1342
+ }
1343
+ function so(e, r, t) {
1344
+ let n = Fr(t, at, t.s);
1345
+ return Yt(e, r, t, b(e, t.i, new n(D$1(t.m))));
1346
+ }
1347
+ function io(e, r, t) {
1348
+ let n = re(), a = b(e, t.i, n.p), s = p$1(e, r, t.f);
1349
+ return t.s ? n.s(s) : n.f(s), a;
1350
+ }
1351
+ function uo(e, r, t) {
1352
+ return b(e, t.i, Object(p$1(e, r, t.f)));
1353
+ }
1354
+ function lo(e, r, t) {
1355
+ let n = e.base.plugins;
1356
+ if (n) {
1357
+ let a = D$1(t.c);
1358
+ for (let s = 0, i = n.length; s < i; s++) {
1359
+ let u = n[s];
1360
+ if (u.tag === a) return b(e, t.i, u.deserialize(t.s, new Dr(e, r), { id: t.i }));
1361
+ }
1362
+ }
1363
+ throw new Q(t.c);
1364
+ }
1365
+ function co(e, r) {
1366
+ return b(e, r.i, b(e, r.s, re()).p);
1367
+ }
1368
+ function fo(e, r, t) {
1369
+ let n = e.base.refs.get(t.i);
1370
+ if (n) return n.s(p$1(e, r, t.a[1])), o$1;
1371
+ throw new V("Promise");
1372
+ }
1373
+ function So(e, r, t) {
1374
+ let n = e.base.refs.get(t.i);
1375
+ if (n) return n.f(p$1(e, r, t.a[1])), o$1;
1376
+ throw new V("Promise");
1377
+ }
1378
+ function mo(e, r, t) {
1379
+ p$1(e, r, t.a[0]);
1380
+ return It(p$1(e, r, t.a[1]));
1381
+ }
1382
+ function po(e, r, t) {
1383
+ p$1(e, r, t.a[0]);
1384
+ return Tt(p$1(e, r, t.a[1]));
1385
+ }
1386
+ function go(e, r, t) {
1387
+ let n = b(e, t.i, te$1()), a = t.a, s = a.length;
1388
+ if (s) for (let i = 0; i < s; i++) p$1(e, r, a[i]);
1389
+ return n;
1390
+ }
1391
+ function yo(e, r, t) {
1392
+ let n = e.base.refs.get(t.i);
1393
+ if (n && M(n)) return n.next(p$1(e, r, t.f)), o$1;
1394
+ throw new V("Stream");
1395
+ }
1396
+ function No(e, r, t) {
1397
+ let n = e.base.refs.get(t.i);
1398
+ if (n && M(n)) return n.throw(p$1(e, r, t.f)), o$1;
1399
+ throw new V("Stream");
1400
+ }
1401
+ function bo(e, r, t) {
1402
+ let n = e.base.refs.get(t.i);
1403
+ if (n && M(n)) return n.return(p$1(e, r, t.f)), o$1;
1404
+ throw new V("Stream");
1405
+ }
1406
+ function vo(e, r, t) {
1407
+ return p$1(e, r, t.f), o$1;
1408
+ }
1409
+ function Co(e, r, t) {
1410
+ return p$1(e, r, t.a[1]), o$1;
1411
+ }
1412
+ function Ao(e, r, t) {
1413
+ let n = b(e, t.i, Tr([], t.s, t.l));
1414
+ for (let a = 0, s = t.a.length; a < s; a++) n.v[a] = p$1(e, r, t.a[a]);
1415
+ return n;
1416
+ }
1417
+ function p$1(e, r, t) {
1418
+ if (r > e.base.depthLimit) throw new ee(e.base.depthLimit);
1419
+ switch (r += 1, t.t) {
1420
+ case 2: return Fr(t, ot, t.s);
1421
+ case 0: return Number(t.s);
1422
+ case 1: return D$1(String(t.s));
1423
+ case 3:
1424
+ if (String(t.s).length > Un) throw new h$1(t);
1425
+ return BigInt(t.s);
1426
+ case 4: return e.base.refs.get(t.i);
1427
+ case 18: return Gn(e, t);
1428
+ case 9: return Kn(e, r, t);
1429
+ case 10:
1430
+ case 11: return $n(e, r, t);
1431
+ case 5: return Xn(e, t);
1432
+ case 6: return Qn(e, t);
1433
+ case 7: return eo(e, r, t);
1434
+ case 8: return ro(e, r, t);
1435
+ case 19: return to(e, t);
1436
+ case 16:
1437
+ case 15: return no(e, r, t);
1438
+ case 20: return oo(e, r, t);
1439
+ case 14: return ao(e, r, t);
1440
+ case 13: return so(e, r, t);
1441
+ case 12: return io(e, r, t);
1442
+ case 17: return Fr(t, tt, t.s);
1443
+ case 21: return uo(e, r, t);
1444
+ case 25: return lo(e, r, t);
1445
+ case 22: return co(e, t);
1446
+ case 23: return fo(e, r, t);
1447
+ case 24: return So(e, r, t);
1448
+ case 28: return mo(e, r, t);
1449
+ case 30: return po(e, r, t);
1450
+ case 31: return go(e, r, t);
1451
+ case 32: return yo(e, r, t);
1452
+ case 33: return No(e, r, t);
1453
+ case 34: return bo(e, r, t);
1454
+ case 27: return vo(e, r, t);
1455
+ case 29: return Co(e, r, t);
1456
+ case 35: return Ao(e, r, t);
1457
+ default: throw new w$1(t);
1458
+ }
1459
+ }
1460
+ function ar(e, r) {
1461
+ try {
1462
+ return p$1(e, 0, r);
1463
+ } catch (t) {
1464
+ throw new He(t);
1465
+ }
1466
+ }
1467
+ var Eo = () => T, Io = Eo.toString();
1468
+ /=>/.test(Io);
1469
+ async function Au(e, r = {}) {
1470
+ let n = ne$1(1, {
1471
+ plugins: A(r.plugins),
1472
+ disabledFeatures: r.disabledFeatures
1473
+ });
1474
+ return {
1475
+ t: await oe(n, e),
1476
+ f: n.base.features,
1477
+ m: Array.from(n.base.marked)
1478
+ };
1479
+ }
1480
+ function Iu(e, r = {}) {
1481
+ var i;
1482
+ let t = A(r.plugins), n = r.disabledFeatures || 0, a = (i = e.f) != null ? i : 63;
1483
+ return ar(Mt({
1484
+ plugins: t,
1485
+ markedRefs: e.m,
1486
+ features: a & ~n,
1487
+ disabledFeatures: n
1488
+ }), e.t);
1489
+ }
1490
+ //#endregion
1491
+ //#region ../../node_modules/.pnpm/seroval-plugins@1.5.2_seroval@1.5.2/node_modules/seroval-plugins/dist/esm/production/web.mjs
1492
+ var u = (e) => {
1493
+ let r = new AbortController(), a = r.abort.bind(r);
1494
+ return e.then(a, a), r;
1495
+ };
1496
+ function E(e) {
1497
+ e(this.reason);
1498
+ }
1499
+ function D(e) {
1500
+ this.addEventListener("abort", E.bind(this, e), { once: !0 });
1501
+ }
1502
+ function c(e) {
1503
+ return new Promise(D.bind(e));
1504
+ }
1505
+ var i = {}, O = ni({
1506
+ tag: "seroval-plugins/web/AbortSignal",
1507
+ extends: [ni({
1508
+ tag: "seroval-plugins/web/AbortControllerFactoryPlugin",
1509
+ test(e) {
1510
+ return e === i;
1511
+ },
1512
+ parse: {
1513
+ sync() {
1514
+ return i;
1515
+ },
1516
+ async async() {
1517
+ return await Promise.resolve(i);
1518
+ },
1519
+ stream() {
1520
+ return i;
1521
+ }
1522
+ },
1523
+ serialize() {
1524
+ return u.toString();
1525
+ },
1526
+ deserialize() {
1527
+ return u;
1528
+ }
1529
+ })],
1530
+ test(e) {
1531
+ return typeof AbortSignal == "undefined" ? !1 : e instanceof AbortSignal;
1532
+ },
1533
+ parse: {
1534
+ sync(e, r) {
1535
+ return e.aborted ? { reason: r.parse(e.reason) } : {};
1536
+ },
1537
+ async async(e, r) {
1538
+ if (e.aborted) return { reason: await r.parse(e.reason) };
1539
+ let a = await c(e);
1540
+ return { reason: await r.parse(a) };
1541
+ },
1542
+ stream(e, r) {
1543
+ if (e.aborted) return { reason: r.parse(e.reason) };
1544
+ let a = c(e);
1545
+ return {
1546
+ factory: r.parse(i),
1547
+ controller: r.parse(a)
1548
+ };
1549
+ }
1550
+ },
1551
+ serialize(e, r) {
1552
+ 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";
1553
+ },
1554
+ deserialize(e, r) {
1555
+ return e.reason ? AbortSignal.abort(r.deserialize(e.reason)) : e.controller ? u(r.deserialize(e.controller)).signal : new AbortController().signal;
1556
+ }
1557
+ });
1558
+ var B = ni({
1559
+ tag: "seroval-plugins/web/Blob",
1560
+ test(e) {
1561
+ return typeof Blob == "undefined" ? !1 : e instanceof Blob;
1562
+ },
1563
+ parse: { async async(e, r) {
1564
+ return {
1565
+ type: await r.parse(e.type),
1566
+ buffer: await r.parse(await e.arrayBuffer())
1567
+ };
1568
+ } },
1569
+ serialize(e, r) {
1570
+ return "new Blob([" + r.serialize(e.buffer) + "],{type:" + r.serialize(e.type) + "})";
1571
+ },
1572
+ deserialize(e, r) {
1573
+ return new Blob([r.deserialize(e.buffer)], { type: r.deserialize(e.type) });
1574
+ }
1575
+ });
1576
+ function d(e) {
1577
+ return {
1578
+ detail: e.detail,
1579
+ bubbles: e.bubbles,
1580
+ cancelable: e.cancelable,
1581
+ composed: e.composed
1582
+ };
1583
+ }
1584
+ var L = ni({
1585
+ tag: "seroval-plugins/web/CustomEvent",
1586
+ test(e) {
1587
+ return typeof CustomEvent == "undefined" ? !1 : e instanceof CustomEvent;
1588
+ },
1589
+ parse: {
1590
+ sync(e, r) {
1591
+ return {
1592
+ type: r.parse(e.type),
1593
+ options: r.parse(d(e))
1594
+ };
1595
+ },
1596
+ async async(e, r) {
1597
+ return {
1598
+ type: await r.parse(e.type),
1599
+ options: await r.parse(d(e))
1600
+ };
1601
+ },
1602
+ stream(e, r) {
1603
+ return {
1604
+ type: r.parse(e.type),
1605
+ options: r.parse(d(e))
1606
+ };
1607
+ }
1608
+ },
1609
+ serialize(e, r) {
1610
+ return "new CustomEvent(" + r.serialize(e.type) + "," + r.serialize(e.options) + ")";
1611
+ },
1612
+ deserialize(e, r) {
1613
+ return new CustomEvent(r.deserialize(e.type), r.deserialize(e.options));
1614
+ }
1615
+ });
1616
+ var q = ni({
1617
+ tag: "seroval-plugins/web/DOMException",
1618
+ test(e) {
1619
+ return typeof DOMException == "undefined" ? !1 : e instanceof DOMException;
1620
+ },
1621
+ parse: {
1622
+ sync(e, r) {
1623
+ return {
1624
+ name: r.parse(e.name),
1625
+ message: r.parse(e.message)
1626
+ };
1627
+ },
1628
+ async async(e, r) {
1629
+ return {
1630
+ name: await r.parse(e.name),
1631
+ message: await r.parse(e.message)
1632
+ };
1633
+ },
1634
+ stream(e, r) {
1635
+ return {
1636
+ name: r.parse(e.name),
1637
+ message: r.parse(e.message)
1638
+ };
1639
+ }
1640
+ },
1641
+ serialize(e, r) {
1642
+ return "new DOMException(" + r.serialize(e.message) + "," + r.serialize(e.name) + ")";
1643
+ },
1644
+ deserialize(e, r) {
1645
+ return new DOMException(r.deserialize(e.message), r.deserialize(e.name));
1646
+ }
1647
+ });
1648
+ function f(e) {
1649
+ return {
1650
+ bubbles: e.bubbles,
1651
+ cancelable: e.cancelable,
1652
+ composed: e.composed
1653
+ };
1654
+ }
1655
+ var Y = ni({
1656
+ tag: "seroval-plugins/web/Event",
1657
+ test(e) {
1658
+ return typeof Event == "undefined" ? !1 : e instanceof Event;
1659
+ },
1660
+ parse: {
1661
+ sync(e, r) {
1662
+ return {
1663
+ type: r.parse(e.type),
1664
+ options: r.parse(f(e))
1665
+ };
1666
+ },
1667
+ async async(e, r) {
1668
+ return {
1669
+ type: await r.parse(e.type),
1670
+ options: await r.parse(f(e))
1671
+ };
1672
+ },
1673
+ stream(e, r) {
1674
+ return {
1675
+ type: r.parse(e.type),
1676
+ options: r.parse(f(e))
1677
+ };
1678
+ }
1679
+ },
1680
+ serialize(e, r) {
1681
+ return "new Event(" + r.serialize(e.type) + "," + r.serialize(e.options) + ")";
1682
+ },
1683
+ deserialize(e, r) {
1684
+ return new Event(r.deserialize(e.type), r.deserialize(e.options));
1685
+ }
1686
+ });
1687
+ var m = ni({
1688
+ tag: "seroval-plugins/web/File",
1689
+ test(e) {
1690
+ return typeof File == "undefined" ? !1 : e instanceof File;
1691
+ },
1692
+ parse: { async async(e, r) {
1693
+ return {
1694
+ name: await r.parse(e.name),
1695
+ options: await r.parse({
1696
+ type: e.type,
1697
+ lastModified: e.lastModified
1698
+ }),
1699
+ buffer: await r.parse(await e.arrayBuffer())
1700
+ };
1701
+ } },
1702
+ serialize(e, r) {
1703
+ return "new File([" + r.serialize(e.buffer) + "]," + r.serialize(e.name) + "," + r.serialize(e.options) + ")";
1704
+ },
1705
+ deserialize(e, r) {
1706
+ return new File([r.deserialize(e.buffer)], r.deserialize(e.name), r.deserialize(e.options));
1707
+ }
1708
+ });
1709
+ function y(e) {
1710
+ let r = [];
1711
+ return e.forEach((a, t) => {
1712
+ r.push([t, a]);
1713
+ }), r;
1714
+ }
1715
+ var o = {}, v = (e, r = new FormData(), a = 0, t = e.length, s) => {
1716
+ for (; a < t; a++) s = e[a], r.append(s[0], s[1]);
1717
+ return r;
1718
+ }, K = ni({
1719
+ tag: "seroval-plugins/web/FormData",
1720
+ extends: [m, ni({
1721
+ tag: "seroval-plugins/web/FormDataFactory",
1722
+ test(e) {
1723
+ return e === o;
1724
+ },
1725
+ parse: {
1726
+ sync() {
1727
+ return o;
1728
+ },
1729
+ async async() {
1730
+ return await Promise.resolve(o);
1731
+ },
1732
+ stream() {
1733
+ return o;
1734
+ }
1735
+ },
1736
+ serialize() {
1737
+ return v.toString();
1738
+ },
1739
+ deserialize() {
1740
+ return o;
1741
+ }
1742
+ })],
1743
+ test(e) {
1744
+ return typeof FormData == "undefined" ? !1 : e instanceof FormData;
1745
+ },
1746
+ parse: {
1747
+ sync(e, r) {
1748
+ return {
1749
+ factory: r.parse(o),
1750
+ entries: r.parse(y(e))
1751
+ };
1752
+ },
1753
+ async async(e, r) {
1754
+ return {
1755
+ factory: await r.parse(o),
1756
+ entries: await r.parse(y(e))
1757
+ };
1758
+ },
1759
+ stream(e, r) {
1760
+ return {
1761
+ factory: r.parse(o),
1762
+ entries: r.parse(y(e))
1763
+ };
1764
+ }
1765
+ },
1766
+ serialize(e, r) {
1767
+ return "(" + r.serialize(e.factory) + ")(" + r.serialize(e.entries) + ")";
1768
+ },
1769
+ deserialize(e, r) {
1770
+ return v(r.deserialize(e.entries));
1771
+ }
1772
+ });
1773
+ function g(e) {
1774
+ let r = [];
1775
+ return e.forEach((a, t) => {
1776
+ r.push([t, a]);
1777
+ }), r;
1778
+ }
1779
+ var l = ni({
1780
+ tag: "seroval-plugins/web/Headers",
1781
+ test(e) {
1782
+ return typeof Headers == "undefined" ? !1 : e instanceof Headers;
1783
+ },
1784
+ parse: {
1785
+ sync(e, r) {
1786
+ return { value: r.parse(g(e)) };
1787
+ },
1788
+ async async(e, r) {
1789
+ return { value: await r.parse(g(e)) };
1790
+ },
1791
+ stream(e, r) {
1792
+ return { value: r.parse(g(e)) };
1793
+ }
1794
+ },
1795
+ serialize(e, r) {
1796
+ return "new Headers(" + r.serialize(e.value) + ")";
1797
+ },
1798
+ deserialize(e, r) {
1799
+ return new Headers(r.deserialize(e.value));
1800
+ }
1801
+ });
1802
+ var $ = ni({
1803
+ tag: "seroval-plugins/web/ImageData",
1804
+ test(e) {
1805
+ return typeof ImageData == "undefined" ? !1 : e instanceof ImageData;
1806
+ },
1807
+ parse: {
1808
+ sync(e, r) {
1809
+ return {
1810
+ data: r.parse(e.data),
1811
+ width: r.parse(e.width),
1812
+ height: r.parse(e.height),
1813
+ options: r.parse({ colorSpace: e.colorSpace })
1814
+ };
1815
+ },
1816
+ async async(e, r) {
1817
+ return {
1818
+ data: await r.parse(e.data),
1819
+ width: await r.parse(e.width),
1820
+ height: await r.parse(e.height),
1821
+ options: await r.parse({ colorSpace: e.colorSpace })
1822
+ };
1823
+ },
1824
+ stream(e, r) {
1825
+ return {
1826
+ data: r.parse(e.data),
1827
+ width: r.parse(e.width),
1828
+ height: r.parse(e.height),
1829
+ options: r.parse({ colorSpace: e.colorSpace })
1830
+ };
1831
+ }
1832
+ },
1833
+ serialize(e, r) {
1834
+ return "new ImageData(" + r.serialize(e.data) + "," + r.serialize(e.width) + "," + r.serialize(e.height) + "," + r.serialize(e.options) + ")";
1835
+ },
1836
+ deserialize(e, r) {
1837
+ return new ImageData(r.deserialize(e.data), r.deserialize(e.width), r.deserialize(e.height), r.deserialize(e.options));
1838
+ }
1839
+ });
1840
+ var n = {}, P = (e) => new ReadableStream({ start: (r) => {
1841
+ e.on({
1842
+ next: (a) => {
1843
+ try {
1844
+ r.enqueue(a);
1845
+ } catch (t) {}
1846
+ },
1847
+ throw: (a) => {
1848
+ r.error(a);
1849
+ },
1850
+ return: () => {
1851
+ try {
1852
+ r.close();
1853
+ } catch (a) {}
1854
+ }
1855
+ });
1856
+ } }), x = ni({
1857
+ tag: "seroval-plugins/web/ReadableStreamFactory",
1858
+ test(e) {
1859
+ return e === n;
1860
+ },
1861
+ parse: {
1862
+ sync() {
1863
+ return n;
1864
+ },
1865
+ async async() {
1866
+ return await Promise.resolve(n);
1867
+ },
1868
+ stream() {
1869
+ return n;
1870
+ }
1871
+ },
1872
+ serialize() {
1873
+ return P.toString();
1874
+ },
1875
+ deserialize() {
1876
+ return n;
1877
+ }
1878
+ });
1879
+ function w(e) {
1880
+ let r = te$1(), a = e.getReader();
1881
+ async function t() {
1882
+ try {
1883
+ let s = await a.read();
1884
+ s.done ? r.return(s.value) : (r.next(s.value), await t());
1885
+ } catch (s) {
1886
+ r.throw(s);
1887
+ }
1888
+ }
1889
+ return t().catch(() => {}), r;
1890
+ }
1891
+ var p = ni({
1892
+ tag: "seroval/plugins/web/ReadableStream",
1893
+ extends: [x],
1894
+ test(e) {
1895
+ return typeof ReadableStream == "undefined" ? !1 : e instanceof ReadableStream;
1896
+ },
1897
+ parse: {
1898
+ sync(e, r) {
1899
+ return {
1900
+ factory: r.parse(n),
1901
+ stream: r.parse(te$1())
1902
+ };
1903
+ },
1904
+ async async(e, r) {
1905
+ return {
1906
+ factory: await r.parse(n),
1907
+ stream: await r.parse(w(e))
1908
+ };
1909
+ },
1910
+ stream(e, r) {
1911
+ return {
1912
+ factory: r.parse(n),
1913
+ stream: r.parse(w(e))
1914
+ };
1915
+ }
1916
+ },
1917
+ serialize(e, r) {
1918
+ return "(" + r.serialize(e.factory) + ")(" + r.serialize(e.stream) + ")";
1919
+ },
1920
+ deserialize(e, r) {
1921
+ return P(r.deserialize(e.stream));
1922
+ }
1923
+ });
1924
+ function N(e, r) {
1925
+ return {
1926
+ body: r,
1927
+ cache: e.cache,
1928
+ credentials: e.credentials,
1929
+ headers: e.headers,
1930
+ integrity: e.integrity,
1931
+ keepalive: e.keepalive,
1932
+ method: e.method,
1933
+ mode: e.mode,
1934
+ redirect: e.redirect,
1935
+ referrer: e.referrer,
1936
+ referrerPolicy: e.referrerPolicy
1937
+ };
1938
+ }
1939
+ var te = ni({
1940
+ tag: "seroval-plugins/web/Request",
1941
+ extends: [p, l],
1942
+ test(e) {
1943
+ return typeof Request == "undefined" ? !1 : e instanceof Request;
1944
+ },
1945
+ parse: {
1946
+ async async(e, r) {
1947
+ return {
1948
+ url: await r.parse(e.url),
1949
+ options: await r.parse(N(e, e.body && !e.bodyUsed ? await e.clone().arrayBuffer() : null))
1950
+ };
1951
+ },
1952
+ stream(e, r) {
1953
+ return {
1954
+ url: r.parse(e.url),
1955
+ options: r.parse(N(e, e.body && !e.bodyUsed ? e.clone().body : null))
1956
+ };
1957
+ }
1958
+ },
1959
+ serialize(e, r) {
1960
+ return "new Request(" + r.serialize(e.url) + "," + r.serialize(e.options) + ")";
1961
+ },
1962
+ deserialize(e, r) {
1963
+ return new Request(r.deserialize(e.url), r.deserialize(e.options));
1964
+ }
1965
+ });
1966
+ function h(e) {
1967
+ return {
1968
+ headers: e.headers,
1969
+ status: e.status,
1970
+ statusText: e.statusText
1971
+ };
1972
+ }
1973
+ var ne = ni({
1974
+ tag: "seroval-plugins/web/Response",
1975
+ extends: [p, l],
1976
+ test(e) {
1977
+ return typeof Response == "undefined" ? !1 : e instanceof Response;
1978
+ },
1979
+ parse: {
1980
+ async async(e, r) {
1981
+ return {
1982
+ body: await r.parse(e.body && !e.bodyUsed ? await e.clone().arrayBuffer() : null),
1983
+ options: await r.parse(h(e))
1984
+ };
1985
+ },
1986
+ stream(e, r) {
1987
+ return {
1988
+ body: r.parse(e.body && !e.bodyUsed ? e.clone().body : null),
1989
+ options: r.parse(h(e))
1990
+ };
1991
+ }
1992
+ },
1993
+ serialize(e, r) {
1994
+ return "new Response(" + r.serialize(e.body) + "," + r.serialize(e.options) + ")";
1995
+ },
1996
+ deserialize(e, r) {
1997
+ return new Response(r.deserialize(e.body), r.deserialize(e.options));
1998
+ }
1999
+ });
2000
+ var pe = ni({
2001
+ tag: "seroval-plugins/web/URL",
2002
+ test(e) {
2003
+ return typeof URL == "undefined" ? !1 : e instanceof URL;
2004
+ },
2005
+ parse: {
2006
+ sync(e, r) {
2007
+ return { value: r.parse(e.href) };
2008
+ },
2009
+ async async(e, r) {
2010
+ return { value: await r.parse(e.href) };
2011
+ },
2012
+ stream(e, r) {
2013
+ return { value: r.parse(e.href) };
2014
+ }
2015
+ },
2016
+ serialize(e, r) {
2017
+ return "new URL(" + r.serialize(e.value) + ")";
2018
+ },
2019
+ deserialize(e, r) {
2020
+ return new URL(r.deserialize(e.value));
241
2021
  }
242
- scope.outputs[key] = existing + delta;
243
- recordOpIfActive(scope, {
244
- kind: "incrementOutput",
245
- key,
246
- delta
247
- });
248
- }
249
- /**
250
- * Assert a condition for the current eval case and throw on failure.
251
- *
252
- * Calls made outside `runInEvalScope(...)` are ignored so shared workflow code
253
- * can safely reuse `evalAssert(...)` when it also runs outside an eval.
254
- */
255
- function evalAssert(condition, message) {
256
- if (condition) return;
257
- const scope = getCurrentScope();
258
- if (!scope) return;
259
- const error = new EvalAssertionError(message);
260
- scope.assertionFailures.push(toAssertionFailure$1(message, error));
261
- throw error;
262
- }
263
- //#endregion
264
- //#region ../sdk/src/cacheKey.ts
265
- var SerializedCacheKeyValue = class {
266
- value;
267
- constructor(value) {
268
- this.value = value;
2022
+ });
2023
+ var fe = ni({
2024
+ tag: "seroval-plugins/web/URLSearchParams",
2025
+ test(e) {
2026
+ return typeof URLSearchParams == "undefined" ? !1 : e instanceof URLSearchParams;
2027
+ },
2028
+ parse: {
2029
+ sync(e, r) {
2030
+ return { value: r.parse(e.toString()) };
2031
+ },
2032
+ async async(e, r) {
2033
+ return { value: await r.parse(e.toString()) };
2034
+ },
2035
+ stream(e, r) {
2036
+ return { value: r.parse(e.toString()) };
2037
+ }
2038
+ },
2039
+ serialize(e, r) {
2040
+ return "new URLSearchParams(" + r.serialize(e.value) + ")";
2041
+ },
2042
+ deserialize(e, r) {
2043
+ return new URLSearchParams(r.deserialize(e.value));
269
2044
  }
270
- };
271
- /**
272
- * Hash the components of a cache key into a deterministic hex digest.
273
- *
274
- * Native `Blob` and `File` values are read asynchronously and hashed by
275
- * content. Use `hashCacheKeySync` only when the key contains no async values.
276
- */
277
- async function hashCacheKey(input) {
278
- return hashCacheKeySyncMaterialized(await materializeAsyncCacheKeyValue(input));
2045
+ });
2046
+ //#endregion
2047
+ //#region ../sdk/src/cacheSerialization.ts
2048
+ const serializedCacheValueMarker = "__agentEvalsCacheSerialization";
2049
+ const serializedCacheValueVersion = "seroval-web-v1";
2050
+ const serovalWebPlugins = [
2051
+ O,
2052
+ B,
2053
+ L,
2054
+ q,
2055
+ Y,
2056
+ m,
2057
+ K,
2058
+ l,
2059
+ $,
2060
+ p,
2061
+ te,
2062
+ ne,
2063
+ pe,
2064
+ fe
2065
+ ];
2066
+ function isRecordLike$2(value) {
2067
+ return typeof value === "object" && value !== null && !Array.isArray(value);
279
2068
  }
280
- /**
281
- * Synchronously hash cache key components. This supports JSON-like data and
282
- * in-memory binary values such as `Buffer`, `ArrayBuffer`, and typed arrays,
283
- * but cannot content-hash native `Blob` or `File` values.
284
- */
285
- function hashCacheKeySync(input) {
286
- return hashCacheKeySyncMaterialized(input);
2069
+ function isSerializedCacheValue(value) {
2070
+ return isRecordLike$2(value) && value[serializedCacheValueMarker] === serializedCacheValueVersion;
287
2071
  }
288
- function hashCacheKeySyncMaterialized(input) {
289
- return createHash("sha256").update(getCompositeKey(input, { stringify: stringifyCacheKeyValue })).digest("hex");
2072
+ /** Serialize one cached value with Seroval plus the Web API plugin set. */
2073
+ async function serializeCacheValue(value) {
2074
+ return {
2075
+ [serializedCacheValueMarker]: serializedCacheValueVersion,
2076
+ value: await Au(value, { plugins: serovalWebPlugins })
2077
+ };
290
2078
  }
291
- function stringifyCacheKeyValue(value) {
292
- if (value instanceof SerializedCacheKeyValue) return value.value;
293
- if (Buffer$1.isBuffer(value)) return `$buffer:${hashBytes(value)}`;
294
- if (isArrayBuffer(value)) return `$arrayBuffer:${hashBytes(new Uint8Array(value))}`;
295
- if (isSharedArrayBuffer(value)) return `$sharedArrayBuffer:${hashBytes(new Uint8Array(value))}`;
296
- if (isArrayBufferView(value)) {
297
- const bytes = new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
298
- return `$${value.constructor.name}:${hashBytes(bytes)}`;
299
- }
300
- if (isFile$1(value)) return `$file:${getCompositeKey({
301
- lastModified: value.lastModified,
302
- name: value.name,
303
- size: value.size,
304
- type: value.type
305
- })}`;
306
- if (isBlob$1(value)) return `$blob:${getCompositeKey({
307
- size: value.size,
308
- type: value.type
309
- })}`;
2079
+ /** Revive one cached value, while preserving legacy JSON-round-tripped data. */
2080
+ function deserializeCacheValue(value) {
2081
+ if (!isSerializedCacheValue(value)) return value;
2082
+ return Iu(value.value, { plugins: serovalWebPlugins });
310
2083
  }
311
- async function materializeAsyncCacheKeyValue(value, refs = /* @__PURE__ */ new WeakSet()) {
312
- const serialized = await stringifyAsyncCacheKeyValue(value);
313
- if (serialized !== void 0) return new SerializedCacheKeyValue(serialized);
314
- if (stringifyCacheKeyValue(value) !== void 0) return value;
315
- if (!value || typeof value !== "object") return value;
316
- if (Array.isArray(value)) {
317
- const items = [];
318
- for (const item of value) items.push(await materializeAsyncCacheKeyValue(item, refs));
319
- return items;
320
- }
321
- if (refs.has(value)) throw new Error("Circular reference detected");
322
- refs.add(value);
2084
+ /** Clone one value through the same Seroval path used for persisted cache data. */
2085
+ async function cloneCacheValue(value) {
2086
+ return deserializeCacheValue(await serializeCacheValue(value));
2087
+ }
2088
+ async function serializeRecordValues(record) {
323
2089
  const entries = [];
324
- for (const [key, entryValue] of Object.entries(value)) entries.push([key, await materializeAsyncCacheKeyValue(entryValue, refs)]);
325
- refs.delete(value);
2090
+ for (const [key, value] of Object.entries(record)) entries.push([key, await serializeCacheValue(value)]);
326
2091
  return Object.fromEntries(entries);
327
2092
  }
328
- async function stringifyAsyncCacheKeyValue(value) {
329
- if (isFile$1(value)) return `$file:${getCompositeKey({
330
- bytes: await hashBlobBytes(value),
331
- lastModified: value.lastModified,
332
- name: value.name,
333
- size: value.size,
334
- type: value.type
335
- })}`;
336
- if (isBlob$1(value)) return `$blob:${getCompositeKey({
337
- bytes: await hashBlobBytes(value),
338
- size: value.size,
339
- type: value.type
340
- })}`;
341
- }
342
- async function hashBlobBytes(value) {
343
- return hashBytes(new Uint8Array(await value.arrayBuffer()));
344
- }
345
- function hashBytes(value) {
346
- return createHash("sha256").update(value).digest("hex");
2093
+ function deserializeRecordValues(record) {
2094
+ return Object.fromEntries(Object.entries(record).map(([key, value]) => [key, deserializeCacheValue(value)]));
347
2095
  }
348
- function isArrayBuffer(value) {
349
- return value instanceof ArrayBuffer;
2096
+ async function serializeCacheRecordingOp(op) {
2097
+ switch (op.kind) {
2098
+ case "setOutput":
2099
+ case "appendOutput": return {
2100
+ ...op,
2101
+ value: await serializeCacheValue(op.value)
2102
+ };
2103
+ case "mergeOutput": return {
2104
+ ...op,
2105
+ patch: await serializeRecordValues(op.patch)
2106
+ };
2107
+ case "incrementOutput": return op;
2108
+ case "checkpoint": return {
2109
+ ...op,
2110
+ data: await serializeCacheValue(op.data)
2111
+ };
2112
+ case "subSpan": return {
2113
+ ...op,
2114
+ span: await serializeCacheSpan(op.span)
2115
+ };
2116
+ }
350
2117
  }
351
- function isSharedArrayBuffer(value) {
352
- return value instanceof SharedArrayBuffer;
2118
+ function deserializeCacheRecordingOp(op) {
2119
+ switch (op.kind) {
2120
+ case "setOutput":
2121
+ case "appendOutput": return {
2122
+ ...op,
2123
+ value: deserializeCacheValue(op.value)
2124
+ };
2125
+ case "mergeOutput": return {
2126
+ ...op,
2127
+ patch: deserializeRecordValues(op.patch)
2128
+ };
2129
+ case "incrementOutput": return op;
2130
+ case "checkpoint": return {
2131
+ ...op,
2132
+ data: deserializeCacheValue(op.data)
2133
+ };
2134
+ case "subSpan": return {
2135
+ ...op,
2136
+ span: deserializeCacheSpan(op.span)
2137
+ };
2138
+ }
353
2139
  }
354
- function isArrayBufferView(value) {
355
- return ArrayBuffer.isView(value);
2140
+ async function serializeCacheSpan(span) {
2141
+ return {
2142
+ ...span,
2143
+ attributes: span.attributes === void 0 ? void 0 : await serializeRecordValues(span.attributes),
2144
+ children: await Promise.all(span.children.map(serializeCacheSpan))
2145
+ };
356
2146
  }
357
- function isBlob$1(value) {
358
- return value instanceof Blob;
2147
+ function deserializeCacheSpan(span) {
2148
+ return {
2149
+ ...span,
2150
+ attributes: span.attributes === void 0 ? void 0 : deserializeRecordValues(span.attributes),
2151
+ children: span.children.map(deserializeCacheSpan)
2152
+ };
359
2153
  }
360
- function isFile$1(value) {
361
- return value instanceof File;
2154
+ /** Serialize all rich values captured in a cache recording before persistence. */
2155
+ async function serializeCacheRecording(recording) {
2156
+ return {
2157
+ ...recording,
2158
+ returnValue: await serializeCacheValue(recording.returnValue),
2159
+ finalAttributes: await serializeRecordValues(recording.finalAttributes),
2160
+ ops: await Promise.all(recording.ops.map(serializeCacheRecordingOp))
2161
+ };
362
2162
  }
363
- function toJsonSafe(value) {
364
- if (value === void 0) return void 0;
365
- const text = JSON.stringify(value);
366
- return JSON.parse(text);
2163
+ /** Revive all rich values captured in a cache recording after lookup. */
2164
+ function deserializeCacheRecording(recording) {
2165
+ return {
2166
+ ...recording,
2167
+ returnValue: deserializeCacheValue(recording.returnValue),
2168
+ finalAttributes: deserializeRecordValues(recording.finalAttributes),
2169
+ ops: recording.ops.map(deserializeCacheRecordingOp)
2170
+ };
367
2171
  }
368
2172
  //#endregion
369
2173
  //#region ../sdk/src/cacheRecording.ts
@@ -388,8 +2192,8 @@ function stripCacheAttributes(attributes) {
388
2192
  for (const [key, value] of Object.entries(attributes)) if (!key.startsWith("cache.")) result[key] = value;
389
2193
  return result;
390
2194
  }
391
- function snapshotNonCacheAttributes(span) {
392
- const snapshot = toJsonSafe(stripCacheAttributes(span?.attributes));
2195
+ async function snapshotNonCacheAttributes(span) {
2196
+ const snapshot = await cloneCacheValue(stripCacheAttributes(span?.attributes));
393
2197
  return isRecordLike$1(snapshot) ? snapshot : {};
394
2198
  }
395
2199
  function diffNonCacheAttributes(before, after) {
@@ -410,6 +2214,19 @@ function appendCacheRef(span, ref) {
410
2214
  const existing = span.attributes?.["cache.refs"];
411
2215
  mergeSpanAttributes$1(span, { "cache.refs": [...Array.isArray(existing) ? copyArray(existing) : [], ref] });
412
2216
  }
2217
+ /**
2218
+ * Record a cache ref against the active span when present, or against the
2219
+ * case scope's `caseCacheRefs` bucket when the call originated from outside
2220
+ * any `traceSpan(...)` body. Without this, spanless refs would be silently
2221
+ * dropped and never surface in the trace or case detail.
2222
+ */
2223
+ function recordCacheRef(scope, span, ref) {
2224
+ if (span !== void 0) {
2225
+ appendCacheRef(span, ref);
2226
+ return;
2227
+ }
2228
+ scope.caseCacheRefs.push(ref);
2229
+ }
413
2230
  function serializeSubSpanTree(scope, spanId) {
414
2231
  const original = scope.spans.find((s) => s.id === spanId);
415
2232
  if (!original) return {
@@ -522,7 +2339,7 @@ const errorCoreFields = new Set([
522
2339
  "stack",
523
2340
  "capturedAt"
524
2341
  ]);
525
- function isRecord$2(value) {
2342
+ function isRecord$4(value) {
526
2343
  return typeof value === "object" && value !== null && !Array.isArray(value);
527
2344
  }
528
2345
  function formatUnknownErrorMessage(error) {
@@ -550,7 +2367,7 @@ function normalizeTraceError(error, capturedAt = void 0) {
550
2367
  stack: error.stack,
551
2368
  capturedAt
552
2369
  };
553
- if (isRecord$2(error)) {
2370
+ if (isRecord$4(error)) {
554
2371
  const extraFields = getErrorExtraFields(error);
555
2372
  const name = typeof error.name === "string" ? error.name : void 0;
556
2373
  const stack = typeof error.stack === "string" ? error.stack : void 0;
@@ -575,7 +2392,7 @@ function normalizeTraceWarnings(warningOrWarnings, additionalWarnings, capturedA
575
2392
  return (additionalWarnings.length > 0 ? [warningOrWarnings, ...additionalWarnings] : Array.isArray(warningOrWarnings) ? warningOrWarnings : [warningOrWarnings]).map((warning) => normalizeTraceError(warning, capturedAt));
576
2393
  }
577
2394
  function isCaptureEvalSpanErrorOptions(value) {
578
- if (!isRecord$2(value)) return false;
2395
+ if (!isRecord$4(value)) return false;
579
2396
  const keys = Object.keys(value);
580
2397
  if (keys.length === 0) return false;
581
2398
  if (!keys.every((key) => key === "level")) return false;
@@ -630,14 +2447,14 @@ function createTraceCache(generateSpanId) {
630
2447
  namespace,
631
2448
  codeFingerprint: cacheCtx.codeFingerprint,
632
2449
  key: info.key
633
- });
2450
+ }, { serializeFileBytes: info.serializeFileBytes === true });
634
2451
  const activeSpan = scope.activeSpanStack.at(-1);
635
2452
  if (cacheCtx.mode === "use") {
636
2453
  const hit = await cacheCtx.adapter.lookup(namespace, keyHash);
637
2454
  if (hit) {
638
2455
  const storedAt = hit.storedAt;
639
2456
  const age = Date.now() - new Date(storedAt).getTime();
640
- appendCacheRef(activeSpan, {
2457
+ recordCacheRef(scope, activeSpan, {
641
2458
  type: "value",
642
2459
  name: info.name,
643
2460
  namespace,
@@ -646,31 +2463,32 @@ function createTraceCache(generateSpanId) {
646
2463
  storedAt,
647
2464
  age
648
2465
  });
649
- replayRecording(scope, activeSpan, hit.recording, { generateSpanId });
650
- return hit.recording.returnValue;
2466
+ const recording = deserializeCacheRecording(hit.recording);
2467
+ replayRecording(scope, activeSpan, recording, { generateSpanId });
2468
+ return recording.returnValue;
651
2469
  }
652
- appendCacheRef(activeSpan, {
2470
+ recordCacheRef(scope, activeSpan, {
653
2471
  type: "value",
654
2472
  name: info.name,
655
2473
  namespace,
656
2474
  key: keyHash,
657
2475
  status: "miss"
658
2476
  });
659
- } else if (cacheCtx.mode === "refresh") appendCacheRef(activeSpan, {
2477
+ } else if (cacheCtx.mode === "refresh") recordCacheRef(scope, activeSpan, {
660
2478
  type: "value",
661
2479
  name: info.name,
662
2480
  namespace,
663
2481
  key: keyHash,
664
2482
  status: "refresh"
665
2483
  });
666
- else appendCacheRef(activeSpan, {
2484
+ else recordCacheRef(scope, activeSpan, {
667
2485
  type: "value",
668
2486
  name: info.name,
669
2487
  namespace,
670
2488
  key: keyHash,
671
2489
  status: "bypass"
672
2490
  });
673
- const beforeAttributes = snapshotNonCacheAttributes(activeSpan);
2491
+ const beforeAttributes = await snapshotNonCacheAttributes(activeSpan);
674
2492
  const frame = {
675
2493
  baseSpanIndex: scope.spans.length,
676
2494
  replayParentSpanId: activeSpan?.id ?? null,
@@ -685,9 +2503,9 @@ function createTraceCache(generateSpanId) {
685
2503
  }
686
2504
  appendSubSpanOps(scope, frame);
687
2505
  if (cacheCtx.mode !== "bypass") {
688
- const finalAttributes = diffNonCacheAttributes(beforeAttributes, snapshotNonCacheAttributes(activeSpan));
2506
+ const finalAttributes = diffNonCacheAttributes(beforeAttributes, await snapshotNonCacheAttributes(activeSpan));
689
2507
  const recording = {
690
- returnValue: toJsonSafe(bodyResult),
2508
+ returnValue: bodyResult,
691
2509
  finalAttributes,
692
2510
  ops: frame.ops
693
2511
  };
@@ -699,7 +2517,7 @@ function createTraceCache(generateSpanId) {
699
2517
  operationName: info.name,
700
2518
  storedAt: (/* @__PURE__ */ new Date()).toISOString(),
701
2519
  codeFingerprint: cacheCtx.codeFingerprint,
702
- recording
2520
+ recording: await serializeCacheRecording(recording)
703
2521
  });
704
2522
  }
705
2523
  return bodyResult;
@@ -1060,7 +2878,7 @@ async function traceSpan(info, fn) {
1060
2878
  namespace,
1061
2879
  codeFingerprint: ctx.codeFingerprint,
1062
2880
  key: cacheOpts.key
1063
- });
2881
+ }, { serializeFileBytes: cacheOpts.serializeFileBytes === true });
1064
2882
  mergeSpanAttributes(spanRecord, {
1065
2883
  "cache.key": keyHash,
1066
2884
  "cache.namespace": namespace
@@ -1074,10 +2892,11 @@ async function traceSpan(info, fn) {
1074
2892
  "cache.storedAt": storedAt,
1075
2893
  "cache.age": Date.now() - new Date(storedAt).getTime()
1076
2894
  });
1077
- replayRecording(scope, spanRecord, hit.recording, { generateSpanId });
1078
- spanRecord.status = hit.recording.finalStatus ?? (hasSpanError(spanRecord) ? "error" : "ok");
2895
+ const recording = deserializeCacheRecording(hit.recording);
2896
+ replayRecording(scope, spanRecord, recording, { generateSpanId });
2897
+ spanRecord.status = recording.finalStatus ?? (hasSpanError(spanRecord) ? "error" : "ok");
1079
2898
  spanRecord.endedAt = (/* @__PURE__ */ new Date()).toISOString();
1080
- return hit.recording.returnValue;
2899
+ return recording.returnValue;
1081
2900
  }
1082
2901
  mergeSpanAttributes(spanRecord, { "cache.status": "miss" });
1083
2902
  } else if (ctx.mode === "refresh") mergeSpanAttributes(spanRecord, { "cache.status": "refresh" });
@@ -1098,7 +2917,7 @@ async function traceSpan(info, fn) {
1098
2917
  finishSpanWithoutThrownError(spanRecord);
1099
2918
  if (ctx.mode !== "bypass") {
1100
2919
  const recording = {
1101
- returnValue: toJsonSafe(bodyResult),
2920
+ returnValue: bodyResult,
1102
2921
  finalAttributes: stripCacheAttributes(spanRecord.attributes),
1103
2922
  finalStatus: spanRecord.status,
1104
2923
  finalError: spanRecord.error,
@@ -1117,7 +2936,7 @@ async function traceSpan(info, fn) {
1117
2936
  spanKind: info.kind,
1118
2937
  storedAt: (/* @__PURE__ */ new Date()).toISOString(),
1119
2938
  codeFingerprint: ctx.codeFingerprint,
1120
- recording
2939
+ recording: await serializeCacheRecording(recording)
1121
2940
  };
1122
2941
  await ctx.adapter.write(entry);
1123
2942
  }
@@ -1386,12 +3205,163 @@ const traceSpanSchema = z.object({
1386
3205
  "ok",
1387
3206
  "error",
1388
3207
  "cancelled"
1389
- ]),
1390
- attributes: z.record(z.string(), z.unknown()).optional(),
1391
- error: traceSpanErrorSchema.optional(),
1392
- errors: z.array(traceSpanErrorSchema).optional(),
1393
- warning: traceSpanWarningSchema.optional(),
1394
- warnings: z.array(traceSpanWarningSchema).optional()
3208
+ ]),
3209
+ attributes: z.record(z.string(), z.unknown()).optional(),
3210
+ error: traceSpanErrorSchema.optional(),
3211
+ errors: z.array(traceSpanErrorSchema).optional(),
3212
+ warning: traceSpanWarningSchema.optional(),
3213
+ warnings: z.array(traceSpanWarningSchema).optional()
3214
+ });
3215
+ //#endregion
3216
+ //#region ../shared/src/schemas/cache.ts
3217
+ /**
3218
+ * Mode that controls how the cache is consulted for a given run.
3219
+ *
3220
+ * - `use`: read cache on hit, write on miss. Default.
3221
+ * - `bypass`: never read, never write.
3222
+ * - `refresh`: never read, always write (forces re-execution and overwrites).
3223
+ */
3224
+ const cacheModeSchema = z.enum([
3225
+ "use",
3226
+ "bypass",
3227
+ "refresh"
3228
+ ]);
3229
+ /** Options accepted by an `evalTracer.span` call to opt the span into caching. */
3230
+ const spanCacheOptionsSchema = z.object({
3231
+ /** Arbitrary JSON-safe value used to derive the cache key. */
3232
+ key: z.unknown(),
3233
+ /** Override the default namespace (`${evalId}__${spanName}`). */
3234
+ namespace: z.string().optional(),
3235
+ /**
3236
+ * Include native `Blob`/`File` bytes in the cache key. By default only stable
3237
+ * metadata (`type`, `size`, plus `name`/`lastModified` for `File`) is used.
3238
+ */
3239
+ serializeFileBytes: z.boolean().optional()
3240
+ });
3241
+ /** Category of operation stored in the eval cache. */
3242
+ const cacheOperationTypeSchema = z.enum(["span", "value"]);
3243
+ /** Status of a cache lookup recorded on a span or case scope. */
3244
+ const cacheStatusSchema = z.enum([
3245
+ "hit",
3246
+ "miss",
3247
+ "refresh",
3248
+ "bypass"
3249
+ ]);
3250
+ /**
3251
+ * Reference to a value-cache lookup performed via `evalTracer.cache(...)`.
3252
+ *
3253
+ * Refs are appended to the active span's `cache.refs` attribute when the call
3254
+ * happens inside a `traceSpan(...)` body, or to the case scope's
3255
+ * `caseCacheRefs` bucket when the call is made directly from the case body.
3256
+ */
3257
+ const traceCacheRefSchema = z.object({
3258
+ type: z.literal("value"),
3259
+ name: z.string(),
3260
+ namespace: z.string(),
3261
+ key: z.string(),
3262
+ status: cacheStatusSchema,
3263
+ storedAt: z.string().optional(),
3264
+ age: z.number().optional()
3265
+ });
3266
+ /** Summary of a single persisted cache entry, used by list/delete endpoints. */
3267
+ const cacheListItemSchema = z.object({
3268
+ key: z.string(),
3269
+ namespace: z.string(),
3270
+ operationType: cacheOperationTypeSchema,
3271
+ operationName: z.string(),
3272
+ spanName: z.string().optional(),
3273
+ spanKind: traceSpanKindSchema.optional(),
3274
+ storedAt: z.string(),
3275
+ codeFingerprint: z.string(),
3276
+ sizeBytes: z.number()
3277
+ });
3278
+ /** Zod schema for `SerializedCacheSpan`, defined lazily for recursion. */
3279
+ const serializedCacheSpanSchema = z.object({
3280
+ kind: traceSpanKindSchema,
3281
+ name: z.string(),
3282
+ attributes: z.record(z.string(), z.unknown()).optional(),
3283
+ status: z.enum([
3284
+ "running",
3285
+ "ok",
3286
+ "error",
3287
+ "cancelled"
3288
+ ]),
3289
+ error: traceSpanErrorSchema.optional(),
3290
+ errors: z.array(traceSpanErrorSchema).optional(),
3291
+ warning: traceSpanWarningSchema.optional(),
3292
+ warnings: z.array(traceSpanWarningSchema).optional()
3293
+ }).extend({ children: z.lazy(() => z.array(serializedCacheSpanSchema)) });
3294
+ /**
3295
+ * One captured operation performed while a cached span's body executed.
3296
+ *
3297
+ * Operations are replayed in order against a fresh scope on cache hit to
3298
+ * reproduce the observable effects of the original run.
3299
+ */
3300
+ const cacheRecordingOpSchema = z.discriminatedUnion("kind", [
3301
+ z.object({
3302
+ kind: z.literal("setOutput"),
3303
+ key: z.string(),
3304
+ value: z.unknown()
3305
+ }),
3306
+ z.object({
3307
+ kind: z.literal("appendOutput"),
3308
+ key: z.string(),
3309
+ value: z.unknown()
3310
+ }),
3311
+ z.object({
3312
+ kind: z.literal("mergeOutput"),
3313
+ key: z.string(),
3314
+ patch: z.record(z.string(), z.unknown())
3315
+ }),
3316
+ z.object({
3317
+ kind: z.literal("incrementOutput"),
3318
+ key: z.string(),
3319
+ delta: z.number()
3320
+ }),
3321
+ z.object({
3322
+ kind: z.literal("checkpoint"),
3323
+ name: z.string(),
3324
+ data: z.unknown()
3325
+ }),
3326
+ z.object({
3327
+ kind: z.literal("subSpan"),
3328
+ span: serializedCacheSpanSchema
3329
+ })
3330
+ ]);
3331
+ /** Captured observable effects + return value of a cached span body. */
3332
+ const cacheRecordingSchema = z.object({
3333
+ returnValue: z.unknown(),
3334
+ finalAttributes: z.record(z.string(), z.unknown()),
3335
+ finalStatus: z.enum([
3336
+ "running",
3337
+ "ok",
3338
+ "error",
3339
+ "cancelled"
3340
+ ]).optional(),
3341
+ finalError: traceSpanErrorSchema.optional(),
3342
+ finalErrors: z.array(traceSpanErrorSchema).optional(),
3343
+ finalWarning: traceSpanWarningSchema.optional(),
3344
+ finalWarnings: z.array(traceSpanWarningSchema).optional(),
3345
+ ops: z.array(cacheRecordingOpSchema)
3346
+ });
3347
+ /** Persisted cache file containing metadata and a recording. */
3348
+ const cacheEntrySchema = z.object({
3349
+ version: z.literal(1),
3350
+ key: z.string(),
3351
+ namespace: z.string(),
3352
+ operationType: cacheOperationTypeSchema.optional(),
3353
+ operationName: z.string().optional(),
3354
+ spanName: z.string().optional(),
3355
+ spanKind: traceSpanKindSchema.optional(),
3356
+ storedAt: z.string(),
3357
+ codeFingerprint: z.string(),
3358
+ recording: cacheRecordingSchema
3359
+ });
3360
+ /** Persisted per-owner cache file containing multiple cache entries. */
3361
+ const cacheFileSchema = z.object({
3362
+ version: z.literal(1),
3363
+ owner: z.string(),
3364
+ entries: z.record(z.string(), cacheEntrySchema)
1395
3365
  });
1396
3366
  //#endregion
1397
3367
  //#region ../shared/src/schemas/chart.ts
@@ -1629,135 +3599,149 @@ const caseDetailSchema = z.object({
1629
3599
  stack: z.string().optional()
1630
3600
  }).nullable(),
1631
3601
  /** Winning trial index for the persisted case detail. */
1632
- trial: z.number()
3602
+ trial: z.number(),
3603
+ /**
3604
+ * Value-cache refs recorded by `evalTracer.cache(...)` calls made directly
3605
+ * from the case body (with no surrounding `traceSpan`). Span-bound refs are
3606
+ * stored on each owning span's `cache.refs` attribute instead.
3607
+ */
3608
+ cacheRefs: z.array(traceCacheRefSchema).default([])
1633
3609
  });
1634
3610
  //#endregion
1635
- //#region ../shared/src/schemas/cache.ts
3611
+ //#region ../shared/src/schemas/config.ts
3612
+ /** Strategy used to collapse repeated trials into one stored case result. */
3613
+ const trialSelectionModeSchema = z.enum(["lowestScore", "median"]);
3614
+ /** Render formats supported by an LLM-call metric in the UI. */
3615
+ const llmCallMetricFormatSchema = z.enum([
3616
+ "string",
3617
+ "number",
3618
+ "duration",
3619
+ "json",
3620
+ "boolean"
3621
+ ]);
3622
+ /** Where an LLM-call metric is rendered inside the LLM calls tab. */
3623
+ const llmCallMetricPlacementSchema = z.enum(["header", "body"]);
1636
3624
  /**
1637
- * Mode that controls how the cache is consulted for a given run.
3625
+ * Schema for a single user-defined metric attached to LLM call rows.
1638
3626
  *
1639
- * - `use`: read cache on hit, write on miss. Default.
1640
- * - `bypass`: never read, never write.
1641
- * - `refresh`: never read, always write (forces re-execution and overwrites).
3627
+ * Each metric reads `path` from the span's `attributes` and renders the value
3628
+ * with the configured `format` and `numberFormat`. `placements` controls
3629
+ * whether the metric appears as a chip on the collapsed row header, as a row
3630
+ * inside the expanded body, or both. Defaults to `['body']` when omitted.
1642
3631
  */
1643
- const cacheModeSchema = z.enum([
1644
- "use",
1645
- "bypass",
1646
- "refresh"
1647
- ]);
1648
- /** Options accepted by an `evalTracer.span` call to opt the span into caching. */
1649
- const spanCacheOptionsSchema = z.object({
1650
- /** Arbitrary JSON-safe value used to derive the cache key. */
1651
- key: z.unknown(),
1652
- /** Override the default namespace (`${evalId}__${spanName}`). */
1653
- namespace: z.string().optional()
3632
+ const llmCallMetricSchema = z.object({
3633
+ /** Display label for the metric row or header chip. */
3634
+ label: z.string().min(1),
3635
+ /**
3636
+ * Optional hover tooltip shown on the metric. Useful when `label` is a
3637
+ * compact abbreviation (e.g. `'t/s'`) and the full meaning needs to be
3638
+ * surfaced on hover (e.g. `'Tokens per second'`).
3639
+ */
3640
+ tooltip: z.string().min(1).optional(),
3641
+ /** Dot-path inside `span.attributes` used to read the value. */
3642
+ path: z.string().min(1),
3643
+ /** Render hint applied to the resolved value. Defaults to `'string'`. */
3644
+ format: llmCallMetricFormatSchema.optional(),
3645
+ /** Number presentation options applied when `format: 'number'`. */
3646
+ numberFormat: numberDisplayOptionsSchema.optional(),
3647
+ /**
3648
+ * Where the metric should appear in the LLM calls tab. Defaults to
3649
+ * `['body']` so metrics surface inside the expanded detail view only.
3650
+ */
3651
+ placements: z.array(llmCallMetricPlacementSchema).nonempty().optional()
1654
3652
  });
1655
- /** Category of operation stored in the eval cache. */
1656
- const cacheOperationTypeSchema = z.enum(["span", "value"]);
1657
- /** Summary of a single persisted cache entry, used by list/delete endpoints. */
1658
- const cacheListItemSchema = z.object({
1659
- key: z.string(),
1660
- namespace: z.string(),
1661
- operationType: cacheOperationTypeSchema,
1662
- operationName: z.string(),
1663
- spanName: z.string().optional(),
1664
- spanKind: traceSpanKindSchema.optional(),
1665
- storedAt: z.string(),
1666
- codeFingerprint: z.string(),
1667
- sizeBytes: z.number()
3653
+ /** Schema for the global LLM calls config block in `agent-evals.config.ts`. */
3654
+ const llmCallsConfigSchema = z.object({
3655
+ /** Span kinds treated as LLM calls. Defaults to `['llm']`. */
3656
+ kinds: z.array(z.string().min(1)).optional(),
3657
+ /**
3658
+ * Attribute paths used to extract structured per-call fields. Each entry is
3659
+ * a dot-path inside `span.attributes`. Missing paths fall back to the
3660
+ * built-in defaults (e.g. `usage.inputTokens`, `costUsd`).
3661
+ *
3662
+ * Per-token-type cost paths (`inputCost`, `outputCost`, `cachedInputCost`,
3663
+ * `reasoningCost`) feed the cost breakdown table in the expanded row.
3664
+ * Record them as USD numbers alongside `costUsd` in your span attributes.
3665
+ */
3666
+ attributes: z.object({
3667
+ model: z.string().optional(),
3668
+ provider: z.string().optional(),
3669
+ inputTokens: z.string().optional(),
3670
+ outputTokens: z.string().optional(),
3671
+ cachedInputTokens: z.string().optional(),
3672
+ cacheCreationInputTokens: z.string().optional(),
3673
+ reasoningTokens: z.string().optional(),
3674
+ totalTokens: z.string().optional(),
3675
+ cost: z.string().optional(),
3676
+ inputCost: z.string().optional(),
3677
+ outputCost: z.string().optional(),
3678
+ cachedInputCost: z.string().optional(),
3679
+ cacheCreationInputCost: z.string().optional(),
3680
+ reasoningCost: z.string().optional(),
3681
+ steps: z.string().optional(),
3682
+ finishReason: z.string().optional(),
3683
+ input: z.string().optional(),
3684
+ output: z.string().optional(),
3685
+ reasoning: z.string().optional(),
3686
+ toolCalls: z.string().optional()
3687
+ }).optional(),
3688
+ /** Custom user-defined metrics surfaced on each LLM call. */
3689
+ metrics: z.array(llmCallMetricSchema).optional()
1668
3690
  });
1669
- /** Zod schema for `SerializedCacheSpan`, defined lazily for recursion. */
1670
- const serializedCacheSpanSchema = z.object({
1671
- kind: traceSpanKindSchema,
1672
- name: z.string(),
1673
- attributes: z.record(z.string(), z.unknown()).optional(),
1674
- status: z.enum([
1675
- "running",
1676
- "ok",
1677
- "error",
1678
- "cancelled"
1679
- ]),
1680
- error: traceSpanErrorSchema.optional(),
1681
- errors: z.array(traceSpanErrorSchema).optional(),
1682
- warning: traceSpanWarningSchema.optional(),
1683
- warnings: z.array(traceSpanWarningSchema).optional()
1684
- }).extend({ children: z.lazy(() => z.array(serializedCacheSpanSchema)) });
3691
+ /** Default LLM-calls config the UI uses before the workspace fetch resolves. */
3692
+ const DEFAULT_LLM_CALLS_CONFIG = {
3693
+ kinds: ["llm"],
3694
+ attributes: {
3695
+ model: "model",
3696
+ provider: "provider",
3697
+ inputTokens: "usage.inputTokens",
3698
+ outputTokens: "usage.outputTokens",
3699
+ cachedInputTokens: "usage.cachedInputTokens",
3700
+ cacheCreationInputTokens: "usage.cacheCreationInputTokens",
3701
+ reasoningTokens: "usage.reasoningTokens",
3702
+ totalTokens: "usage.totalTokens",
3703
+ cost: "costUsd",
3704
+ inputCost: "cost.inputUsd",
3705
+ outputCost: "cost.outputUsd",
3706
+ cachedInputCost: "cost.cachedInputUsd",
3707
+ cacheCreationInputCost: "cost.cacheCreationInputUsd",
3708
+ reasoningCost: "cost.reasoningUsd",
3709
+ steps: "steps",
3710
+ finishReason: "finishReason",
3711
+ input: "input",
3712
+ output: "output",
3713
+ reasoning: "reasoning",
3714
+ toolCalls: "toolCalls"
3715
+ },
3716
+ metrics: []
3717
+ };
1685
3718
  /**
1686
- * One captured operation performed while a cached span's body executed.
3719
+ * Resolve the user-authored LLM-calls config to a fully-defaulted shape used
3720
+ * by the UI to derive the LLM calls tab.
1687
3721
  *
1688
- * Operations are replayed in order against a fresh scope on cache hit to
1689
- * reproduce the observable effects of the original run.
3722
+ * - Missing or empty `kinds` falls back to `['llm']`.
3723
+ * - Missing `attributes.<field>` falls back to the corresponding default
3724
+ * attribute path.
3725
+ * - Missing `metrics[].format` defaults to `'string'`.
3726
+ * - Missing `metrics[].placements` defaults to `['body']`.
1690
3727
  */
1691
- const cacheRecordingOpSchema = z.discriminatedUnion("kind", [
1692
- z.object({
1693
- kind: z.literal("setOutput"),
1694
- key: z.string(),
1695
- value: z.unknown()
1696
- }),
1697
- z.object({
1698
- kind: z.literal("appendOutput"),
1699
- key: z.string(),
1700
- value: z.unknown()
1701
- }),
1702
- z.object({
1703
- kind: z.literal("mergeOutput"),
1704
- key: z.string(),
1705
- patch: z.record(z.string(), z.unknown())
1706
- }),
1707
- z.object({
1708
- kind: z.literal("incrementOutput"),
1709
- key: z.string(),
1710
- delta: z.number()
1711
- }),
1712
- z.object({
1713
- kind: z.literal("checkpoint"),
1714
- name: z.string(),
1715
- data: z.unknown()
1716
- }),
1717
- z.object({
1718
- kind: z.literal("subSpan"),
1719
- span: serializedCacheSpanSchema
1720
- })
1721
- ]);
1722
- /** Captured observable effects + return value of a cached span body. */
1723
- const cacheRecordingSchema = z.object({
1724
- returnValue: z.unknown(),
1725
- finalAttributes: z.record(z.string(), z.unknown()),
1726
- finalStatus: z.enum([
1727
- "running",
1728
- "ok",
1729
- "error",
1730
- "cancelled"
1731
- ]).optional(),
1732
- finalError: traceSpanErrorSchema.optional(),
1733
- finalErrors: z.array(traceSpanErrorSchema).optional(),
1734
- finalWarning: traceSpanWarningSchema.optional(),
1735
- finalWarnings: z.array(traceSpanWarningSchema).optional(),
1736
- ops: z.array(cacheRecordingOpSchema)
1737
- });
1738
- /** Persisted cache file containing metadata and a recording. */
1739
- const cacheEntrySchema = z.object({
1740
- version: z.literal(1),
1741
- key: z.string(),
1742
- namespace: z.string(),
1743
- operationType: cacheOperationTypeSchema.optional(),
1744
- operationName: z.string().optional(),
1745
- spanName: z.string().optional(),
1746
- spanKind: traceSpanKindSchema.optional(),
1747
- storedAt: z.string(),
1748
- codeFingerprint: z.string(),
1749
- recording: cacheRecordingSchema
1750
- });
1751
- /** Persisted per-owner cache file containing multiple cache entries. */
1752
- const cacheFileSchema = z.object({
1753
- version: z.literal(1),
1754
- owner: z.string(),
1755
- entries: z.record(z.string(), cacheEntrySchema)
1756
- });
1757
- //#endregion
1758
- //#region ../shared/src/schemas/config.ts
1759
- /** Strategy used to collapse repeated trials into one stored case result. */
1760
- const trialSelectionModeSchema = z.enum(["lowestScore", "median"]);
3728
+ function resolveLlmCallsConfig(input) {
3729
+ return {
3730
+ kinds: input?.kinds && input.kinds.length > 0 ? [...input.kinds] : [...DEFAULT_LLM_CALLS_CONFIG.kinds],
3731
+ attributes: {
3732
+ ...DEFAULT_LLM_CALLS_CONFIG.attributes,
3733
+ ...input?.attributes
3734
+ },
3735
+ metrics: (input?.metrics ?? []).map((m) => ({
3736
+ label: m.label,
3737
+ tooltip: m.tooltip,
3738
+ path: m.path,
3739
+ format: m.format ?? "string",
3740
+ numberFormat: m.numberFormat,
3741
+ placements: m.placements ? [...m.placements] : ["body"]
3742
+ }))
3743
+ };
3744
+ }
1761
3745
  /** Zod schema for validating `agent-evals.config.ts` input. */
1762
3746
  const agentEvalsConfigSchema = z.object({
1763
3747
  workspaceRoot: z.string().optional(),
@@ -1767,9 +3751,12 @@ const agentEvalsConfigSchema = z.object({
1767
3751
  concurrency: z.number().optional(),
1768
3752
  staleAfterDays: z.number().optional(),
1769
3753
  traceDisplay: traceDisplayInputConfigSchema.optional(),
3754
+ llmCalls: llmCallsConfigSchema.optional(),
1770
3755
  cache: z.object({
1771
3756
  enabled: z.boolean().optional(),
1772
3757
  dir: z.string().optional(),
3758
+ maxEntriesPerNamespace: z.preprocess((value) => typeof value === "number" && Number.isFinite(value) ? value : void 0, z.number().optional()),
3759
+ maxEntriesByNamespace: z.record(z.string(), z.number()).optional(),
1773
3760
  maxEntriesPerEval: z.preprocess((value) => typeof value === "number" && Number.isFinite(value) ? value : void 0, z.number().optional())
1774
3761
  }).optional()
1775
3762
  });
@@ -1966,6 +3953,240 @@ function getEvalTitle(evalLike) {
1966
3953
  if (evalLike.title !== void 0) return evalLike.title;
1967
3954
  return humanizeEvalId(evalLike.id);
1968
3955
  }
3956
+ //#endregion
3957
+ //#region ../shared/src/utils/getNestedAttribute.ts
3958
+ function isRecord$3(value) {
3959
+ return typeof value === "object" && value !== null;
3960
+ }
3961
+ /**
3962
+ * Read a value from `source` by walking a dot-separated path.
3963
+ *
3964
+ * Returns `undefined` when any segment of the path is missing or when an
3965
+ * intermediate value is not a plain object. Used by trace-attribute display,
3966
+ * the LLM calls extractor, and any consumer that needs to look up nested
3967
+ * properties from a span's `attributes` record.
3968
+ */
3969
+ function getNestedAttribute(value, path) {
3970
+ const parts = path.split(".");
3971
+ let current = value;
3972
+ for (const part of parts) {
3973
+ if (!isRecord$3(current) || !(part in current)) return;
3974
+ current = current[part];
3975
+ }
3976
+ return current;
3977
+ }
3978
+ //#endregion
3979
+ //#region ../shared/src/utils/extractLlmCalls.ts
3980
+ function readNumber$1(attributes, path) {
3981
+ const raw = getNestedAttribute(attributes, path);
3982
+ return typeof raw === "number" && Number.isFinite(raw) ? raw : null;
3983
+ }
3984
+ function readString$1(attributes, path) {
3985
+ const raw = getNestedAttribute(attributes, path);
3986
+ return typeof raw === "string" && raw.length > 0 ? raw : null;
3987
+ }
3988
+ function computeLatencyMs(span) {
3989
+ if (span.endedAt === null) return null;
3990
+ const started = Date.parse(span.startedAt);
3991
+ const ended = Date.parse(span.endedAt);
3992
+ if (!Number.isFinite(started) || !Number.isFinite(ended)) return null;
3993
+ const delta = ended - started;
3994
+ return delta >= 0 ? delta : null;
3995
+ }
3996
+ function computeTotalTokens({ declared, input, output, cached, cacheCreation }) {
3997
+ if (declared !== null) return declared;
3998
+ if (input === null && output === null && cached === null && cacheCreation === null) return null;
3999
+ return (input ?? 0) + (output ?? 0) + (cached ?? 0) + (cacheCreation ?? 0);
4000
+ }
4001
+ function readSteps(attributes, path) {
4002
+ const raw = getNestedAttribute(attributes, path);
4003
+ if (Array.isArray(raw)) return {
4004
+ stepCount: raw.length,
4005
+ stepDetails: raw
4006
+ };
4007
+ if (typeof raw === "number" && Number.isFinite(raw)) return {
4008
+ stepCount: raw,
4009
+ stepDetails: null
4010
+ };
4011
+ return {
4012
+ stepCount: null,
4013
+ stepDetails: null
4014
+ };
4015
+ }
4016
+ function collectWarnings(span) {
4017
+ const out = [];
4018
+ if (span.warning) out.push(span.warning);
4019
+ if (span.warnings) out.push(...span.warnings);
4020
+ return out;
4021
+ }
4022
+ function pickError(span) {
4023
+ if (span.error) return span.error;
4024
+ if (span.errors && span.errors.length > 0) return span.errors[0] ?? null;
4025
+ return null;
4026
+ }
4027
+ /**
4028
+ * Filter `spans` down to LLM calls and project each one to the structured
4029
+ * shape consumed by the LLM calls tab.
4030
+ *
4031
+ * Spans whose `kind` is not in `config.kinds` are dropped. Structured fields
4032
+ * (`model`, token counts, cost, etc.) are read via `getNestedAttribute` from
4033
+ * the configured paths, with safe coercion to `string | null` / `number |
4034
+ * null`. `totalTokens` falls back to a sum of input + output + cached when no
4035
+ * explicit total attribute is present. The `steps` attribute path may resolve
4036
+ * to either a number (rendered as the inference-round count) or an array of
4037
+ * per-step detail objects (rendered as a Steps section in the body, with
4038
+ * `stepCount` derived from the array length). `latencyMs` is `null` while the
4039
+ * span is still running. User-defined `metrics` whose path resolves to
4040
+ * `undefined` are dropped, but `null`, `0`, and `false` are preserved as
4041
+ * legitimate values worth displaying. Original span order is preserved so the
4042
+ * LLM calls tab matches the ordering in the Trace tab.
4043
+ */
4044
+ function extractLlmCalls(spans, config) {
4045
+ const kindSet = new Set(config.kinds);
4046
+ const result = [];
4047
+ for (const span of spans) {
4048
+ if (!kindSet.has(span.kind)) continue;
4049
+ const attrs = span.attributes;
4050
+ const inputTokens = readNumber$1(attrs, config.attributes.inputTokens);
4051
+ const outputTokens = readNumber$1(attrs, config.attributes.outputTokens);
4052
+ const cachedInputTokens = readNumber$1(attrs, config.attributes.cachedInputTokens);
4053
+ const cacheCreationInputTokens = readNumber$1(attrs, config.attributes.cacheCreationInputTokens);
4054
+ const reasoningTokens = readNumber$1(attrs, config.attributes.reasoningTokens);
4055
+ const declaredTotalTokens = readNumber$1(attrs, config.attributes.totalTokens);
4056
+ const metrics = [];
4057
+ for (const metric of config.metrics) {
4058
+ const rawValue = getNestedAttribute(attrs, metric.path);
4059
+ if (rawValue === void 0) continue;
4060
+ metrics.push({
4061
+ label: metric.label,
4062
+ tooltip: metric.tooltip,
4063
+ rawValue,
4064
+ format: metric.format,
4065
+ numberFormat: metric.numberFormat,
4066
+ placements: metric.placements
4067
+ });
4068
+ }
4069
+ result.push({
4070
+ id: span.id,
4071
+ name: span.name,
4072
+ kind: span.kind,
4073
+ status: span.status,
4074
+ model: readString$1(attrs, config.attributes.model),
4075
+ provider: readString$1(attrs, config.attributes.provider),
4076
+ inputTokens,
4077
+ outputTokens,
4078
+ cachedInputTokens,
4079
+ cacheCreationInputTokens,
4080
+ reasoningTokens,
4081
+ totalTokens: computeTotalTokens({
4082
+ declared: declaredTotalTokens,
4083
+ input: inputTokens,
4084
+ output: outputTokens,
4085
+ cached: cachedInputTokens,
4086
+ cacheCreation: cacheCreationInputTokens
4087
+ }),
4088
+ costUsd: readNumber$1(attrs, config.attributes.cost),
4089
+ inputCostUsd: readNumber$1(attrs, config.attributes.inputCost),
4090
+ outputCostUsd: readNumber$1(attrs, config.attributes.outputCost),
4091
+ cachedInputCostUsd: readNumber$1(attrs, config.attributes.cachedInputCost),
4092
+ cacheCreationInputCostUsd: readNumber$1(attrs, config.attributes.cacheCreationInputCost),
4093
+ reasoningCostUsd: readNumber$1(attrs, config.attributes.reasoningCost),
4094
+ ...readSteps(attrs, config.attributes.steps),
4095
+ finishReason: readString$1(attrs, config.attributes.finishReason),
4096
+ latencyMs: computeLatencyMs(span),
4097
+ input: getNestedAttribute(attrs, config.attributes.input),
4098
+ output: getNestedAttribute(attrs, config.attributes.output),
4099
+ reasoning: getNestedAttribute(attrs, config.attributes.reasoning),
4100
+ toolCalls: getNestedAttribute(attrs, config.attributes.toolCalls),
4101
+ metrics,
4102
+ warnings: collectWarnings(span),
4103
+ error: pickError(span)
4104
+ });
4105
+ }
4106
+ return result;
4107
+ }
4108
+ //#endregion
4109
+ //#region ../shared/src/utils/extractCacheHits.ts
4110
+ function isRecord$2(value) {
4111
+ return typeof value === "object" && value !== null && !Array.isArray(value);
4112
+ }
4113
+ function readString(attributes, key) {
4114
+ if (!isRecord$2(attributes)) return void 0;
4115
+ const value = attributes[key];
4116
+ return typeof value === "string" && value.length > 0 ? value : void 0;
4117
+ }
4118
+ function readNumber(attributes, key) {
4119
+ if (!isRecord$2(attributes)) return void 0;
4120
+ const value = attributes[key];
4121
+ return typeof value === "number" && Number.isFinite(value) ? value : void 0;
4122
+ }
4123
+ function readArray(attributes, key) {
4124
+ if (!isRecord$2(attributes)) return [];
4125
+ const value = attributes[key];
4126
+ return Array.isArray(value) ? value : [];
4127
+ }
4128
+ /**
4129
+ * Collect every `status === 'hit'` cache event recorded for a case run.
4130
+ *
4131
+ * Walks `spans` for span-level cache hits (`attributes['cache.status'] ===
4132
+ * 'hit'`) and per-span value-cache refs (`attributes['cache.refs']`), then
4133
+ * appends spanless value-cache refs persisted on the case scope. Non-hit
4134
+ * statuses (`miss`/`refresh`/`bypass`) are skipped — they remain visible
4135
+ * inline in the Trace tab.
4136
+ */
4137
+ function extractCacheHits(spans, caseCacheRefs) {
4138
+ const entries = [];
4139
+ for (const span of spans) {
4140
+ if (readString(span.attributes, "cache.status") === "hit") {
4141
+ const key = readString(span.attributes, "cache.key");
4142
+ const namespace = readString(span.attributes, "cache.namespace");
4143
+ if (key !== void 0 && namespace !== void 0) entries.push({
4144
+ id: span.id,
4145
+ source: "span",
4146
+ origin: "span",
4147
+ name: span.name,
4148
+ namespace,
4149
+ key,
4150
+ storedAt: readString(span.attributes, "cache.storedAt"),
4151
+ age: readNumber(span.attributes, "cache.age"),
4152
+ spanId: span.id
4153
+ });
4154
+ }
4155
+ const rawRefs = readArray(span.attributes, "cache.refs");
4156
+ for (const [index, rawRef] of rawRefs.entries()) {
4157
+ const parsed = traceCacheRefSchema.safeParse(rawRef);
4158
+ if (!parsed.success) continue;
4159
+ const ref = parsed.data;
4160
+ if (ref.status !== "hit") continue;
4161
+ entries.push({
4162
+ id: `${span.id}:value:${String(index)}`,
4163
+ source: "value",
4164
+ origin: "span",
4165
+ name: ref.name,
4166
+ namespace: ref.namespace,
4167
+ key: ref.key,
4168
+ storedAt: ref.storedAt,
4169
+ age: ref.age,
4170
+ spanId: span.id
4171
+ });
4172
+ }
4173
+ }
4174
+ for (const [index, ref] of caseCacheRefs.entries()) {
4175
+ if (ref.status !== "hit") continue;
4176
+ entries.push({
4177
+ id: `case:value:${String(index)}`,
4178
+ source: "value",
4179
+ origin: "caseRoot",
4180
+ name: ref.name,
4181
+ namespace: ref.namespace,
4182
+ key: ref.key,
4183
+ storedAt: ref.storedAt,
4184
+ age: ref.age,
4185
+ spanId: void 0
4186
+ });
4187
+ }
4188
+ return entries;
4189
+ }
1969
4190
  z.enum([
1970
4191
  "discovery.updated",
1971
4192
  "run.started",
@@ -2009,17 +4230,17 @@ const createRunRequestSchema = z.object({
2009
4230
  const updateManualScoreRequestSchema = z.object({ value: z.number().min(0).max(1).nullable() });
2010
4231
  //#endregion
2011
4232
  //#region ../runner/src/cacheStore.ts
2012
- const defaultMaxEntriesPerEval = 100;
4233
+ const defaultMaxEntriesPerNamespace = 100;
2013
4234
  /**
2014
4235
  * Create a filesystem-backed cache adapter rooted at `<workspaceRoot>/<dir>`.
2015
4236
  *
2016
- * Cache entries are grouped into one inspectable JSON file per eval/cache
2017
- * owner. Writes use a short-lived lock directory plus `<name>.tmp` + atomic
4237
+ * Cache entries are grouped into one inspectable JSON file per cache owner.
4238
+ * Writes use a short-lived lock directory plus `<name>.tmp` + atomic
2018
4239
  * `rename` to avoid partial reads and lost updates under concurrent access.
2019
4240
  */
2020
4241
  function createFsCacheStore(options) {
2021
4242
  const cacheDir = resolve(options.workspaceRoot, options.dir ?? ".agent-evals/cache");
2022
- const maxEntriesPerEval = normalizeMaxEntries(options.maxEntriesPerEval);
4243
+ const defaultMaxEntries = normalizeMaxEntries(options.maxEntriesPerNamespace);
2023
4244
  return {
2024
4245
  dir() {
2025
4246
  return cacheDir;
@@ -2038,7 +4259,7 @@ function createFsCacheStore(options) {
2038
4259
  entries: pruneEntries({
2039
4260
  ...(await readCacheFile(cacheDir, owner))?.entries ?? {},
2040
4261
  [entry.key]: entry
2041
- }, maxEntriesPerEval, entry.key)
4262
+ }, entry.namespace, maxEntriesForNamespace(entry.namespace, defaultMaxEntries, options.maxEntriesByNamespace), entry.key)
2042
4263
  });
2043
4264
  });
2044
4265
  },
@@ -2142,10 +4363,14 @@ function createBufferedCacheStore(backingStore) {
2142
4363
  }
2143
4364
  };
2144
4365
  }
2145
- function normalizeMaxEntries(value) {
2146
- if (value === void 0 || !Number.isFinite(value) || value <= 0) return defaultMaxEntriesPerEval;
4366
+ function normalizeMaxEntries(value, fallback = defaultMaxEntriesPerNamespace) {
4367
+ if (value === void 0 || !Number.isFinite(value) || value <= 0) return fallback;
2147
4368
  return Math.floor(value);
2148
4369
  }
4370
+ function maxEntriesForNamespace(namespace, defaultMaxEntries, maxEntriesByNamespace) {
4371
+ const namespaceMaxEntries = maxEntriesByNamespace?.[namespace];
4372
+ return namespaceMaxEntries === void 0 ? defaultMaxEntries : normalizeMaxEntries(namespaceMaxEntries, defaultMaxEntries);
4373
+ }
2149
4374
  function ownerFromNamespace(namespace) {
2150
4375
  const [owner] = namespace.split("__");
2151
4376
  return owner === void 0 || owner.length === 0 ? namespace : owner;
@@ -2186,16 +4411,16 @@ async function writeCacheFile(cacheDir, cacheFile) {
2186
4411
  await writeFile(tmpPath, JSON.stringify(cacheFile, null, 2));
2187
4412
  await rename(tmpPath, filePath);
2188
4413
  }
2189
- function pruneEntries(entries, maxEntries, protectedKey) {
2190
- const sorted = Object.values(entries).toSorted((a, b) => a.storedAt < b.storedAt ? 1 : -1);
4414
+ function pruneEntries(entries, namespace, maxEntries, protectedKey) {
4415
+ const sorted = Object.values(entries).filter((entry) => entry.namespace === namespace).toSorted((a, b) => a.storedAt < b.storedAt ? 1 : -1);
2191
4416
  const kept = /* @__PURE__ */ new Map();
2192
4417
  const protectedEntry = entries[protectedKey];
2193
- if (protectedEntry !== void 0) kept.set(protectedEntry.key, protectedEntry);
4418
+ if (protectedEntry?.namespace === namespace) kept.set(protectedEntry.key, protectedEntry);
2194
4419
  for (const entry of sorted) {
2195
4420
  if (kept.size >= maxEntries) break;
2196
4421
  kept.set(entry.key, entry);
2197
4422
  }
2198
- return Object.fromEntries([...kept.values()].toSorted((a, b) => a.key < b.key ? -1 : 1).map((entry) => [entry.key, entry]));
4423
+ 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]));
2199
4424
  }
2200
4425
  async function withCacheFileLock(filePath, fn) {
2201
4426
  const lockPath = `${filePath}.lock`;
@@ -2908,15 +5133,6 @@ async function runWithModuleIsolation(context, fn) {
2908
5133
  function isRecord$1(value) {
2909
5134
  return typeof value === "object" && value !== null;
2910
5135
  }
2911
- function getNestedAttribute(value, path) {
2912
- const parts = path.split(".");
2913
- let current = value;
2914
- for (const part of parts) {
2915
- if (!isRecord$1(current) || !(part in current)) return;
2916
- current = current[part];
2917
- }
2918
- return current;
2919
- }
2920
5136
  function mergeNestedAttribute(value, path, attributeValue) {
2921
5137
  const root = value === void 0 ? {} : { ...value };
2922
5138
  const parts = path.split(".");
@@ -2987,14 +5203,35 @@ function resolveRunnableEvalCases(params) {
2987
5203
  input: {}
2988
5204
  }];
2989
5205
  }
5206
+ function toStableIdSegment(value) {
5207
+ const segment = value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
5208
+ return segment.length > 0 ? segment : "id";
5209
+ }
5210
+ function buildScopedEvalIdPrefix(params) {
5211
+ const fileIdentity = relative(params.workspaceRoot, params.evalFilePath).replaceAll("\\", "/");
5212
+ return [
5213
+ toStableIdSegment(params.evalId),
5214
+ toStableIdSegment(fileIdentity),
5215
+ toStableIdSegment(params.caseId)
5216
+ ].join("-");
5217
+ }
2990
5218
  async function callWithUnknownResult(fn, args) {
2991
5219
  return await Reflect.apply(fn, void 0, args);
2992
5220
  }
2993
5221
  async function runCase(params) {
2994
- const { evalDef, evalId, evalCase, globalTraceDisplay, trial, startTime, cacheAdapter, cacheMode, codeFingerprint, moduleIsolation, artifactDir, runId } = params;
5222
+ const { evalDef, evalId, evalCase, globalTraceDisplay, trial, startTime, cacheAdapter, cacheMode, codeFingerprint, moduleIsolation, evalFilePath, workspaceRoot, artifactDir, runId } = params;
5223
+ const scopedIdPrefix = buildScopedEvalIdPrefix({
5224
+ evalId,
5225
+ evalFilePath,
5226
+ caseId: evalCase.id,
5227
+ workspaceRoot
5228
+ });
2995
5229
  const { scope, error: executeError } = await runInEvalScope(evalCase.id, async () => {
2996
5230
  const execute = async () => {
2997
- await Reflect.apply(evalDef.execute, evalDef, [{ input: evalCase.input }]);
5231
+ await Reflect.apply(evalDef.execute, evalDef, [{
5232
+ input: evalCase.input,
5233
+ setOutput: setEvalOutput
5234
+ }]);
2998
5235
  };
2999
5236
  if (moduleIsolation === void 0) {
3000
5237
  await execute();
@@ -3003,6 +5240,7 @@ async function runCase(params) {
3003
5240
  await runWithModuleIsolation(moduleIsolation, execute);
3004
5241
  }, {
3005
5242
  input: evalCase.input,
5243
+ idPrefix: scopedIdPrefix,
3006
5244
  cacheContext: cacheAdapter ? {
3007
5245
  adapter: cacheAdapter,
3008
5246
  mode: cacheMode,
@@ -3047,6 +5285,7 @@ async function runCase(params) {
3047
5285
  return await runWithModuleIsolation(moduleIsolation, computeScore);
3048
5286
  }, {
3049
5287
  input: evalCase.input,
5288
+ idPrefix: `${scopedIdPrefix}-score-${toStableIdSegment(key)}`,
3050
5289
  cacheContext: cacheAdapter ? {
3051
5290
  adapter: cacheAdapter,
3052
5291
  mode: cacheMode,
@@ -3126,7 +5365,8 @@ async function runCase(params) {
3126
5365
  columns,
3127
5366
  assertionFailures: scope.assertionFailures,
3128
5367
  error: errorInfo,
3129
- trial
5368
+ trial,
5369
+ cacheRefs: scope.caseCacheRefs
3130
5370
  };
3131
5371
  if (Object.keys(scoringTraces).length > 0) caseDetail.scoringTraces = scoringTraces;
3132
5372
  return {
@@ -3373,6 +5613,8 @@ async function executeRun({ runState, request, runDir, config, evals, cacheStore
3373
5613
  cacheMode,
3374
5614
  codeFingerprint,
3375
5615
  moduleIsolation,
5616
+ evalFilePath,
5617
+ workspaceRoot,
3376
5618
  artifactDir: join(runDir, "artifacts"),
3377
5619
  runId: runState.manifest.id
3378
5620
  });
@@ -3514,4 +5756,4 @@ function toLastRunStatus(status) {
3514
5756
  return status === "pending" ? null : status;
3515
5757
  }
3516
5758
  //#endregion
3517
- export { evalChartAxisSchema as $, runManifestSchema as A, evalTracer as At, cacheRecordingSchema as B, mergeEvalOutput as Bt, updateManualScoreRequestSchema as C, numberDisplayOptionsSchema as Ct, deriveScopedSummaryFromCases as D, buildTraceTree as Dt, getEvalDisplayStatus as E, z$1 as Et, cacheFileSchema as F, evalAssert as Ft, caseRowSchema as G, defineEval as Gt, spanCacheOptionsSchema as H, setEvalOutput as Ht, cacheListItemSchema as I, getCurrentScope as It, evalStatItemSchema as J, evalFreshnessStatusSchema as K, getEvalRegistry as Kt, cacheModeSchema as L, getEvalCaseInput as Lt, agentEvalsConfigSchema as M, hashCacheKeySync as Mt, trialSelectionModeSchema as N, EvalAssertionError as Nt, deriveStatusFromCaseRows as O, captureEvalSpanError as Ot, cacheEntrySchema as P, appendToEvalOutput as Pt, evalChartAggregateSchema as Q, cacheOperationTypeSchema as R, incrementEvalOutput as Rt, createRunRequestSchema as S, jsonCellSchema as St, getEvalTitle as T, runArtifactRefSchema as Tt, assertionFailureSchema as U, setScopeCacheContext as Ut, serializedCacheSpanSchema as V, runInEvalScope as Vt, caseDetailSchema as W, repoFile as Wt, evalSummarySchema as X, evalStatsConfigSchema as Y, scoreTraceSchema as Z, loadEvalModule as _, cellValueSchema as _t, loadPersistedRunSnapshot as a, evalChartTypeSchema as at, normalizeScoreDef as b, columnKindSchema as bt, persistCaseDetail as c, traceAttributeDisplayInputSchema as ct, recomputePersistedCaseStatus as d, traceDisplayConfigSchema as dt, evalChartBuiltinMetricSchema as et, runTouchesEval as f, traceDisplayInputConfigSchema as ft, setLatestRunInfoMap as g, traceSpanWarningSchema as gt, getTargetEvalIds as h, traceSpanSchema as ht, getLatestRunInfos as i, evalChartTooltipExtraSchema as it, runSummarySchema as j, hashCacheKey as jt, deriveStatusFromChildStatuses as k, evalSpan as kt, persistRunState as l, traceAttributeDisplayPlacementSchema as lt, buildEvalSummary as m, traceSpanKindSchema as mt, generateRunId as n, evalChartConfigSchema as nt, loadPersistedRunSnapshots as o, evalChartsConfigSchema as ot, resolveArtifactPath as p, traceSpanErrorSchema as pt, evalStatAggregateSchema as q, getLastRunStatuses as r, evalChartMetricSchema as rt, nextShortIdFromSnapshots as s, traceAttributeDisplayFormatSchema as st, executeRun as t, evalChartColorSchema as tt, recomputeEvalStatusesInRuns as u, traceAttributeDisplaySchema as ut, loadConfig as v, columnDefSchema as vt, sseEnvelopeSchema as w, repoFileRefSchema as wt, createFsCacheStore as x, fileRefSchema as xt, buildDeclaredColumnDefs as y, columnFormatSchema as yt, cacheRecordingOpSchema as z, isInEvalScope as zt };
5759
+ export { evalChartAxisSchema as $, runInEvalScope as $t, deriveScopedSummaryFromCases as A, columnFormatSchema as At, llmCallsConfigSchema as B, evalSpan as Bt, updateManualScoreRequestSchema as C, traceDisplayInputConfigSchema as Ct, getNestedAttribute as D, traceSpanWarningSchema as Dt, extractLlmCalls as E, traceSpanSchema as Et, DEFAULT_LLM_CALLS_CONFIG as F, repoFileRefSchema as Ft, caseRowSchema as G, appendToEvalOutput as Gt, trialSelectionModeSchema as H, hashCacheKey as Ht, agentEvalsConfigSchema as I, runArtifactRefSchema as It, evalStatItemSchema as J, getEvalCaseInput as Jt, evalFreshnessStatusSchema as K, evalAssert as Kt, llmCallMetricFormatSchema as L, z$1 as Lt, deriveStatusFromChildStatuses as M, fileRefSchema as Mt, runManifestSchema as N, jsonCellSchema as Nt, getEvalTitle as O, cellValueSchema as Ot, runSummarySchema as P, numberDisplayOptionsSchema as Pt, evalChartAggregateSchema as Q, nextEvalId as Qt, llmCallMetricPlacementSchema as R, buildTraceTree as Rt, createRunRequestSchema as S, traceDisplayConfigSchema as St, extractCacheHits as T, traceSpanKindSchema as Tt, assertionFailureSchema as U, hashCacheKeySync as Ut, resolveLlmCallsConfig as V, evalTracer as Vt, caseDetailSchema as W, EvalAssertionError as Wt, evalSummarySchema as X, isInEvalScope as Xt, evalStatsConfigSchema as Y, incrementEvalOutput as Yt, scoreTraceSchema as Z, mergeEvalOutput as Zt, loadEvalModule as _, traceCacheRefSchema as _t, loadPersistedRunSnapshot as a, evalChartTypeSchema as at, normalizeScoreDef as b, traceAttributeDisplayPlacementSchema as bt, persistCaseDetail as c, cacheFileSchema as ct, recomputePersistedCaseStatus as d, cacheOperationTypeSchema as dt, setEvalOutput as en, evalChartBuiltinMetricSchema as et, runTouchesEval as f, cacheRecordingOpSchema as ft, setLatestRunInfoMap as g, spanCacheOptionsSchema as gt, getTargetEvalIds as h, serializedCacheSpanSchema as ht, getLatestRunInfos as i, getEvalRegistry as in, evalChartTooltipExtraSchema as it, deriveStatusFromCaseRows as j, columnKindSchema as jt, getEvalDisplayStatus as k, columnDefSchema as kt, persistRunState as l, cacheListItemSchema as lt, buildEvalSummary as m, cacheStatusSchema as mt, generateRunId as n, repoFile as nn, evalChartConfigSchema as nt, loadPersistedRunSnapshots as o, evalChartsConfigSchema as ot, resolveArtifactPath as p, cacheRecordingSchema as pt, evalStatAggregateSchema as q, getCurrentScope as qt, getLastRunStatuses as r, defineEval as rn, evalChartMetricSchema as rt, nextShortIdFromSnapshots as s, cacheEntrySchema as st, executeRun as t, setScopeCacheContext as tn, evalChartColorSchema as tt, recomputeEvalStatusesInRuns as u, cacheModeSchema as ut, loadConfig as v, traceAttributeDisplayFormatSchema as vt, sseEnvelopeSchema as w, traceSpanErrorSchema as wt, createFsCacheStore as x, traceAttributeDisplaySchema as xt, buildDeclaredColumnDefs as y, traceAttributeDisplayInputSchema as yt, llmCallMetricSchema as z, captureEvalSpanError as zt };