braintrust 0.3.6 → 0.3.7

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.
@@ -303,33 +303,1014 @@ var Queue = class {
303
303
  }
304
304
  };
305
305
 
306
- // src/logger.ts
307
- import {
308
- _urljoin,
309
- AUDIT_METADATA_FIELD,
310
- AUDIT_SOURCE_FIELD,
311
- batchItems,
312
- constructJsonArray,
313
- DEFAULT_IS_LEGACY_DATASET,
314
- ensureDatasetRecord,
315
- IS_MERGE_FIELD,
316
- mergeDicts,
317
- mergeGitMetadataSettings,
318
- mergeRowBatch,
319
- SpanComponentsV3,
320
- SpanObjectTypeV3,
321
- spanObjectTypeV3ToString,
322
- SpanTypeAttribute,
323
- TRANSACTION_ID_FIELD,
324
- VALID_SOURCES,
325
- isArray,
326
- isObject
327
- } from "@braintrust/core";
306
+ // util/db_fields.ts
307
+ var TRANSACTION_ID_FIELD = "_xact_id";
308
+ var IS_MERGE_FIELD = "_is_merge";
309
+ var AUDIT_SOURCE_FIELD = "_audit_source";
310
+ var AUDIT_METADATA_FIELD = "_audit_metadata";
311
+ var VALID_SOURCES = ["app", "api", "external"];
312
+ var PARENT_ID_FIELD = "_parent_id";
313
+
314
+ // util/span_identifier_v3.ts
315
+ import * as uuid3 from "uuid";
316
+
317
+ // util/span_identifier_v2.ts
318
+ import * as uuid2 from "uuid";
319
+
320
+ // util/span_identifier_v1.ts
321
+ import * as uuid from "uuid";
322
+ import { z } from "zod/v3";
323
+ function tryMakeUuid(s) {
324
+ try {
325
+ const ret = uuid.parse(s);
326
+ if (ret.length !== 16) {
327
+ throw new Error();
328
+ }
329
+ return { bytes: Buffer.from(ret), isUUID: true };
330
+ } catch (e) {
331
+ return { bytes: Buffer.from(s, "utf-8"), isUUID: false };
332
+ }
333
+ }
334
+ var ENCODING_VERSION_NUMBER = 1;
335
+ var INVALID_ENCODING_ERRMSG = "SpanComponents string is not properly encoded. This may be due to a version mismatch between the SDK library used to export the span and the library used to decode it. Please make sure you are using the same SDK version across the board";
336
+ var SpanObjectTypeV1 = /* @__PURE__ */ ((SpanObjectTypeV12) => {
337
+ SpanObjectTypeV12[SpanObjectTypeV12["EXPERIMENT"] = 1] = "EXPERIMENT";
338
+ SpanObjectTypeV12[SpanObjectTypeV12["PROJECT_LOGS"] = 2] = "PROJECT_LOGS";
339
+ return SpanObjectTypeV12;
340
+ })(SpanObjectTypeV1 || {});
341
+ var SpanObjectTypeV1EnumSchema = z.nativeEnum(SpanObjectTypeV1);
342
+ var SpanRowIdsV1 = class {
343
+ rowId;
344
+ spanId;
345
+ rootSpanId;
346
+ constructor(args) {
347
+ this.rowId = args.rowId;
348
+ this.spanId = args.spanId;
349
+ this.rootSpanId = args.rootSpanId;
350
+ if (!this.rowId) {
351
+ throw new Error("rowId must be nonempty string");
352
+ }
353
+ if (!this.spanId) {
354
+ throw new Error("spanId must be nonempty string");
355
+ }
356
+ if (!this.rootSpanId) {
357
+ throw new Error("rootSpanId must be nonempty string");
358
+ }
359
+ }
360
+ toObject() {
361
+ return {
362
+ rowId: this.rowId,
363
+ spanId: this.spanId,
364
+ rootSpanId: this.rootSpanId
365
+ };
366
+ }
367
+ };
368
+ var SpanComponentsV1 = class _SpanComponentsV1 {
369
+ objectType;
370
+ objectId;
371
+ rowIds;
372
+ constructor(args) {
373
+ this.objectType = args.objectType;
374
+ this.objectId = args.objectId;
375
+ this.rowIds = args.rowIds;
376
+ }
377
+ toStr() {
378
+ const allBuffers = [];
379
+ const { bytes: rowIdBytes, isUUID: rowIdIsUUID } = this.rowIds ? tryMakeUuid(this.rowIds.rowId) : { bytes: Buffer.from(""), isUUID: false };
380
+ allBuffers.push(
381
+ Buffer.from([
382
+ ENCODING_VERSION_NUMBER,
383
+ this.objectType,
384
+ this.rowIds ? 1 : 0,
385
+ rowIdIsUUID ? 1 : 0
386
+ ])
387
+ );
388
+ const { bytes: objectIdBytes, isUUID: objectIdIsUUID } = tryMakeUuid(
389
+ this.objectId
390
+ );
391
+ if (!objectIdIsUUID) {
392
+ throw new Error("object_id component must be a valid UUID");
393
+ }
394
+ allBuffers.push(objectIdBytes);
395
+ if (this.rowIds) {
396
+ const { bytes: spanIdBytes, isUUID: spanIdIsUUID } = tryMakeUuid(
397
+ this.rowIds.spanId
398
+ );
399
+ if (!spanIdIsUUID) {
400
+ throw new Error("span_id component must be a valid UUID");
401
+ }
402
+ const { bytes: rootSpanIdBytes, isUUID: rootSpanIdIsUUID } = tryMakeUuid(
403
+ this.rowIds.rootSpanId
404
+ );
405
+ if (!rootSpanIdIsUUID) {
406
+ throw new Error("root_span_id component must be a valid UUID");
407
+ }
408
+ allBuffers.push(spanIdBytes, rootSpanIdBytes, rowIdBytes);
409
+ }
410
+ return Buffer.concat(allBuffers).toString("base64");
411
+ }
412
+ static fromStr(s) {
413
+ try {
414
+ const rawBytes = Buffer.from(s, "base64");
415
+ if (rawBytes[0] !== ENCODING_VERSION_NUMBER) {
416
+ throw new Error();
417
+ }
418
+ const objectType = SpanObjectTypeV1EnumSchema.parse(rawBytes[1]);
419
+ if (![0, 1].includes(rawBytes[2])) {
420
+ throw new Error();
421
+ }
422
+ if (![0, 1].includes(rawBytes[3])) {
423
+ throw new Error();
424
+ }
425
+ const hasRowId = rawBytes[2] == 1;
426
+ const rowIdIsUUID = rawBytes[3] == 1;
427
+ const objectId = uuid.stringify(rawBytes.subarray(4, 20));
428
+ const rowIds = (() => {
429
+ if (!hasRowId) {
430
+ return void 0;
431
+ }
432
+ const spanId = uuid.stringify(rawBytes.subarray(20, 36));
433
+ const rootSpanId = uuid.stringify(rawBytes.subarray(36, 52));
434
+ const rowId = rowIdIsUUID ? uuid.stringify(rawBytes.subarray(52)) : rawBytes.subarray(52).toString("utf-8");
435
+ return new SpanRowIdsV1({ rowId, spanId, rootSpanId });
436
+ })();
437
+ return new _SpanComponentsV1({ objectType, objectId, rowIds });
438
+ } catch (e) {
439
+ throw new Error(INVALID_ENCODING_ERRMSG);
440
+ }
441
+ }
442
+ objectIdFields() {
443
+ switch (this.objectType) {
444
+ case 1 /* EXPERIMENT */:
445
+ return { experiment_id: this.objectId };
446
+ case 2 /* PROJECT_LOGS */:
447
+ return { project_id: this.objectId, log_id: "g" };
448
+ default:
449
+ throw new Error("Impossible");
450
+ }
451
+ }
452
+ toObject() {
453
+ return {
454
+ objectType: this.objectType,
455
+ objectId: this.objectId,
456
+ rowIds: this.rowIds?.toObject()
457
+ };
458
+ }
459
+ };
460
+
461
+ // util/span_identifier_v2.ts
462
+ import { z as z2 } from "zod/v3";
463
+ function tryMakeUuid2(s) {
464
+ try {
465
+ const ret = uuid2.parse(s);
466
+ if (ret.length !== 16) {
467
+ throw new Error();
468
+ }
469
+ return { bytes: Buffer.from(ret), isUUID: true };
470
+ } catch (e) {
471
+ return { bytes: Buffer.from(s, "utf-8"), isUUID: false };
472
+ }
473
+ }
474
+ var ENCODING_VERSION_NUMBER2 = 2;
475
+ var INVALID_ENCODING_ERRMSG2 = `SpanComponents string is not properly encoded. This library only supports encoding versions up to ${ENCODING_VERSION_NUMBER2}. Please make sure the SDK library used to decode the SpanComponents is at least as new as any library used to encode it.`;
476
+ var INTEGER_ENCODING_NUM_BYTES = 4;
477
+ var SpanObjectTypeV2 = /* @__PURE__ */ ((SpanObjectTypeV22) => {
478
+ SpanObjectTypeV22[SpanObjectTypeV22["EXPERIMENT"] = 1] = "EXPERIMENT";
479
+ SpanObjectTypeV22[SpanObjectTypeV22["PROJECT_LOGS"] = 2] = "PROJECT_LOGS";
480
+ return SpanObjectTypeV22;
481
+ })(SpanObjectTypeV2 || {});
482
+ var SpanObjectTypeV2EnumSchema = z2.nativeEnum(SpanObjectTypeV2);
483
+ var SpanRowIdsV2 = class {
484
+ rowId;
485
+ spanId;
486
+ rootSpanId;
487
+ constructor(args) {
488
+ this.rowId = args.rowId;
489
+ this.spanId = args.spanId;
490
+ this.rootSpanId = args.rootSpanId;
491
+ if (!this.rowId) {
492
+ throw new Error("rowId must be nonempty string");
493
+ }
494
+ if (!this.spanId) {
495
+ throw new Error("spanId must be nonempty string");
496
+ }
497
+ if (!this.rootSpanId) {
498
+ throw new Error("rootSpanId must be nonempty string");
499
+ }
500
+ }
501
+ toObject() {
502
+ return {
503
+ rowId: this.rowId,
504
+ spanId: this.spanId,
505
+ rootSpanId: this.rootSpanId
506
+ };
507
+ }
508
+ };
509
+ var SpanComponentsV2 = class _SpanComponentsV2 {
510
+ objectType;
511
+ objectId;
512
+ computeObjectMetadataArgs;
513
+ rowIds;
514
+ constructor(args) {
515
+ this.objectType = args.objectType;
516
+ this.objectId = args.objectId;
517
+ this.computeObjectMetadataArgs = args.computeObjectMetadataArgs;
518
+ this.rowIds = args.rowIds;
519
+ if (!(this.objectId || this.computeObjectMetadataArgs)) {
520
+ throw new Error(
521
+ "Must provide either objectId or computeObjectMetadataArgs"
522
+ );
523
+ }
524
+ }
525
+ toStr() {
526
+ const allBuffers = [];
527
+ const { bytes: rowIdBytes, isUUID: rowIdIsUUID } = this.rowIds ? tryMakeUuid2(this.rowIds.rowId) : { bytes: Buffer.from(""), isUUID: false };
528
+ allBuffers.push(
529
+ Buffer.from([
530
+ ENCODING_VERSION_NUMBER2,
531
+ this.objectType,
532
+ this.objectId ? 1 : 0,
533
+ this.computeObjectMetadataArgs ? 1 : 0,
534
+ this.rowIds ? 1 : 0,
535
+ rowIdIsUUID ? 1 : 0
536
+ ])
537
+ );
538
+ if (this.objectId) {
539
+ const { bytes: objectIdBytes, isUUID: objectIdIsUUID } = tryMakeUuid2(
540
+ this.objectId
541
+ );
542
+ if (!objectIdIsUUID) {
543
+ throw new Error("object_id component must be a valid UUID");
544
+ }
545
+ allBuffers.push(objectIdBytes);
546
+ }
547
+ if (this.computeObjectMetadataArgs) {
548
+ const computeObjectMetadataBytes = Buffer.from(
549
+ JSON.stringify(this.computeObjectMetadataArgs),
550
+ "utf-8"
551
+ );
552
+ const serializedLenBytes = Buffer.alloc(INTEGER_ENCODING_NUM_BYTES);
553
+ serializedLenBytes.writeInt32BE(computeObjectMetadataBytes.length);
554
+ allBuffers.push(serializedLenBytes, computeObjectMetadataBytes);
555
+ }
556
+ if (this.rowIds) {
557
+ const { bytes: spanIdBytes, isUUID: spanIdIsUUID } = tryMakeUuid2(
558
+ this.rowIds.spanId
559
+ );
560
+ if (!spanIdIsUUID) {
561
+ throw new Error("span_id component must be a valid UUID");
562
+ }
563
+ const { bytes: rootSpanIdBytes, isUUID: rootSpanIdIsUUID } = tryMakeUuid2(
564
+ this.rowIds.rootSpanId
565
+ );
566
+ if (!rootSpanIdIsUUID) {
567
+ throw new Error("root_span_id component must be a valid UUID");
568
+ }
569
+ allBuffers.push(spanIdBytes, rootSpanIdBytes, rowIdBytes);
570
+ }
571
+ return Buffer.concat(allBuffers).toString("base64");
572
+ }
573
+ static fromStr(s) {
574
+ try {
575
+ const rawBytes = Buffer.from(s, "base64");
576
+ if (rawBytes[0] < ENCODING_VERSION_NUMBER2) {
577
+ const spanComponentsOld = SpanComponentsV1.fromStr(s);
578
+ return new _SpanComponentsV2({
579
+ objectType: SpanObjectTypeV2EnumSchema.parse(
580
+ spanComponentsOld.objectType
581
+ ),
582
+ objectId: spanComponentsOld.objectId,
583
+ rowIds: spanComponentsOld.rowIds ? new SpanRowIdsV2({
584
+ rowId: spanComponentsOld.rowIds.rowId,
585
+ spanId: spanComponentsOld.rowIds.spanId,
586
+ rootSpanId: spanComponentsOld.rowIds.rootSpanId
587
+ }) : void 0
588
+ });
589
+ }
590
+ if (rawBytes[0] !== ENCODING_VERSION_NUMBER2) {
591
+ throw new Error();
592
+ }
593
+ const objectType = SpanObjectTypeV2EnumSchema.parse(rawBytes[1]);
594
+ for (let i = 2; i < 6; ++i) {
595
+ if (![0, 1].includes(rawBytes[i])) {
596
+ throw new Error();
597
+ }
598
+ }
599
+ const hasObjectId = rawBytes[2] == 1;
600
+ const hasComputeObjectMetadataArgs = rawBytes[3] == 1;
601
+ const hasRowId = rawBytes[4] == 1;
602
+ const rowIdIsUUID = rawBytes[5] == 1;
603
+ let byteCursor = 6;
604
+ let objectId = void 0;
605
+ if (hasObjectId) {
606
+ const nextByteCursor = byteCursor + 16;
607
+ objectId = uuid2.stringify(
608
+ rawBytes.subarray(byteCursor, nextByteCursor)
609
+ );
610
+ byteCursor = nextByteCursor;
611
+ }
612
+ let computeObjectMetadataArgs;
613
+ if (hasComputeObjectMetadataArgs) {
614
+ let nextByteCursor = byteCursor + INTEGER_ENCODING_NUM_BYTES;
615
+ const serializedLenBytes = rawBytes.readInt32BE(byteCursor);
616
+ byteCursor = nextByteCursor;
617
+ nextByteCursor = byteCursor + serializedLenBytes;
618
+ computeObjectMetadataArgs = JSON.parse(
619
+ rawBytes.subarray(byteCursor, nextByteCursor).toString("utf-8")
620
+ );
621
+ byteCursor = nextByteCursor;
622
+ }
623
+ const rowIds = (() => {
624
+ if (!hasRowId) {
625
+ return void 0;
626
+ }
627
+ let nextByteCursor = byteCursor + 16;
628
+ const spanId = uuid2.stringify(
629
+ rawBytes.subarray(byteCursor, nextByteCursor)
630
+ );
631
+ byteCursor = nextByteCursor;
632
+ nextByteCursor = byteCursor + 16;
633
+ const rootSpanId = uuid2.stringify(
634
+ rawBytes.subarray(byteCursor, nextByteCursor)
635
+ );
636
+ byteCursor = nextByteCursor;
637
+ const rowId = rowIdIsUUID ? uuid2.stringify(rawBytes.subarray(byteCursor)) : rawBytes.subarray(byteCursor).toString("utf-8");
638
+ return new SpanRowIdsV2({ rowId, spanId, rootSpanId });
639
+ })();
640
+ return new _SpanComponentsV2({
641
+ objectType,
642
+ objectId,
643
+ computeObjectMetadataArgs,
644
+ rowIds
645
+ });
646
+ } catch (e) {
647
+ throw new Error(INVALID_ENCODING_ERRMSG2);
648
+ }
649
+ }
650
+ objectIdFields() {
651
+ if (!this.objectId) {
652
+ throw new Error(
653
+ "Impossible: cannot invoke `object_id_fields` unless SpanComponentsV2 is initialized with an `object_id`"
654
+ );
655
+ }
656
+ switch (this.objectType) {
657
+ case 1 /* EXPERIMENT */:
658
+ return { experiment_id: this.objectId };
659
+ case 2 /* PROJECT_LOGS */:
660
+ return { project_id: this.objectId, log_id: "g" };
661
+ default:
662
+ throw new Error("Impossible");
663
+ }
664
+ }
665
+ toObject() {
666
+ return {
667
+ objectType: this.objectType,
668
+ objectId: this.objectId,
669
+ computeObjectMetadataArgs: this.computeObjectMetadataArgs,
670
+ rowIds: this.rowIds?.toObject()
671
+ };
672
+ }
673
+ };
674
+
675
+ // util/span_identifier_v3.ts
676
+ import { z as z3 } from "zod/v3";
677
+
678
+ // util/bytes.ts
679
+ function concatUint8Arrays(...arrays) {
680
+ const totalLength = arrays.reduce((acc, arr) => acc + arr.length, 0);
681
+ const result = new Uint8Array(totalLength);
682
+ let offset = 0;
683
+ for (const arr of arrays) {
684
+ result.set(arr, offset);
685
+ offset += arr.length;
686
+ }
687
+ return result;
688
+ }
689
+ function uint8ArrayToBase64(uint8Array) {
690
+ let binary = "";
691
+ for (let i = 0; i < uint8Array.length; i++) {
692
+ binary += String.fromCharCode(uint8Array[i]);
693
+ }
694
+ return btoa(binary);
695
+ }
696
+ function base64ToUint8Array(base64) {
697
+ const binary = atob(base64);
698
+ const uint8Array = new Uint8Array(binary.length);
699
+ for (let i = 0; i < binary.length; i++) {
700
+ uint8Array[i] = binary.charCodeAt(i);
701
+ }
702
+ return uint8Array;
703
+ }
704
+ function uint8ArrayToString(uint8Array) {
705
+ const decoder = new TextDecoder("utf-8");
706
+ return decoder.decode(uint8Array);
707
+ }
708
+ function stringToUint8Array(str) {
709
+ const encoder = new TextEncoder();
710
+ return encoder.encode(str);
711
+ }
712
+
713
+ // util/span_identifier_v3.ts
714
+ function tryMakeUuid3(s) {
715
+ try {
716
+ const ret = uuid3.parse(s);
717
+ if (ret.length !== 16) {
718
+ throw new Error();
719
+ }
720
+ return { bytes: new Uint8Array(ret), isUUID: true };
721
+ } catch {
722
+ return { bytes: void 0, isUUID: false };
723
+ }
724
+ }
725
+ var ENCODING_VERSION_NUMBER3 = 3;
726
+ var INVALID_ENCODING_ERRMSG3 = `SpanComponents string is not properly encoded. This library only supports encoding versions up to ${ENCODING_VERSION_NUMBER3}. Please make sure the SDK library used to decode the SpanComponents is at least as new as any library used to encode it.`;
727
+ var SpanObjectTypeV3 = /* @__PURE__ */ ((SpanObjectTypeV32) => {
728
+ SpanObjectTypeV32[SpanObjectTypeV32["EXPERIMENT"] = 1] = "EXPERIMENT";
729
+ SpanObjectTypeV32[SpanObjectTypeV32["PROJECT_LOGS"] = 2] = "PROJECT_LOGS";
730
+ SpanObjectTypeV32[SpanObjectTypeV32["PLAYGROUND_LOGS"] = 3] = "PLAYGROUND_LOGS";
731
+ return SpanObjectTypeV32;
732
+ })(SpanObjectTypeV3 || {});
733
+ var spanObjectTypeV3EnumSchema = z3.nativeEnum(SpanObjectTypeV3);
734
+ function spanObjectTypeV3ToString(objectType) {
735
+ switch (objectType) {
736
+ case 1 /* EXPERIMENT */:
737
+ return "experiment";
738
+ case 2 /* PROJECT_LOGS */:
739
+ return "project_logs";
740
+ case 3 /* PLAYGROUND_LOGS */:
741
+ return "playground_logs";
742
+ default:
743
+ const x = objectType;
744
+ throw new Error(`Unknown SpanObjectTypeV3: ${x}`);
745
+ }
746
+ }
747
+ var InternalSpanComponentUUIDFields = /* @__PURE__ */ ((InternalSpanComponentUUIDFields2) => {
748
+ InternalSpanComponentUUIDFields2[InternalSpanComponentUUIDFields2["OBJECT_ID"] = 1] = "OBJECT_ID";
749
+ InternalSpanComponentUUIDFields2[InternalSpanComponentUUIDFields2["ROW_ID"] = 2] = "ROW_ID";
750
+ InternalSpanComponentUUIDFields2[InternalSpanComponentUUIDFields2["SPAN_ID"] = 3] = "SPAN_ID";
751
+ InternalSpanComponentUUIDFields2[InternalSpanComponentUUIDFields2["ROOT_SPAN_ID"] = 4] = "ROOT_SPAN_ID";
752
+ return InternalSpanComponentUUIDFields2;
753
+ })(InternalSpanComponentUUIDFields || {});
754
+ var internalSpanComponentUUIDFieldsEnumSchema = z3.nativeEnum(
755
+ InternalSpanComponentUUIDFields
756
+ );
757
+ var _INTERNAL_SPAN_COMPONENT_UUID_FIELDS_ID_TO_NAME = {
758
+ [1 /* OBJECT_ID */]: "object_id",
759
+ [2 /* ROW_ID */]: "row_id",
760
+ [3 /* SPAN_ID */]: "span_id",
761
+ [4 /* ROOT_SPAN_ID */]: "root_span_id"
762
+ };
763
+ var spanComponentsV3Schema = z3.object({
764
+ object_type: spanObjectTypeV3EnumSchema,
765
+ // TODO(manu): We should have a more elaborate zod schema for
766
+ // `propagated_event`. This will required zod-ifying the contents of
767
+ // sdk/js/util/object.ts.
768
+ propagated_event: z3.record(z3.unknown()).nullish()
769
+ }).and(
770
+ z3.union([
771
+ // Must provide one or the other.
772
+ z3.object({
773
+ object_id: z3.string().nullish(),
774
+ compute_object_metadata_args: z3.optional(z3.null())
775
+ }),
776
+ z3.object({
777
+ object_id: z3.optional(z3.null()),
778
+ compute_object_metadata_args: z3.record(z3.unknown())
779
+ })
780
+ ])
781
+ ).and(
782
+ z3.union([
783
+ // Either all of these must be provided or none.
784
+ z3.object({
785
+ row_id: z3.string(),
786
+ span_id: z3.string(),
787
+ root_span_id: z3.string()
788
+ }),
789
+ z3.object({
790
+ row_id: z3.optional(z3.null()),
791
+ span_id: z3.optional(z3.null()),
792
+ root_span_id: z3.optional(z3.null())
793
+ })
794
+ ])
795
+ );
796
+ var SpanComponentsV3 = class _SpanComponentsV3 {
797
+ constructor(data) {
798
+ this.data = data;
799
+ }
800
+ toStr() {
801
+ const jsonObj = {
802
+ compute_object_metadata_args: this.data.compute_object_metadata_args || void 0,
803
+ propagated_event: this.data.propagated_event || void 0
804
+ };
805
+ const allBuffers = [];
806
+ allBuffers.push(
807
+ new Uint8Array([ENCODING_VERSION_NUMBER3, this.data.object_type])
808
+ );
809
+ const uuidEntries = [];
810
+ function addUuidField(origVal, fieldId) {
811
+ const ret = tryMakeUuid3(origVal);
812
+ if (ret.isUUID) {
813
+ uuidEntries.push(
814
+ concatUint8Arrays(new Uint8Array([fieldId]), ret.bytes)
815
+ );
816
+ } else {
817
+ jsonObj[_INTERNAL_SPAN_COMPONENT_UUID_FIELDS_ID_TO_NAME[fieldId]] = origVal;
818
+ }
819
+ }
820
+ if (this.data.object_id) {
821
+ addUuidField(
822
+ this.data.object_id,
823
+ 1 /* OBJECT_ID */
824
+ );
825
+ }
826
+ if (this.data.row_id) {
827
+ addUuidField(this.data.row_id, 2 /* ROW_ID */);
828
+ }
829
+ if (this.data.span_id) {
830
+ addUuidField(this.data.span_id, 3 /* SPAN_ID */);
831
+ }
832
+ if (this.data.root_span_id) {
833
+ addUuidField(
834
+ this.data.root_span_id,
835
+ 4 /* ROOT_SPAN_ID */
836
+ );
837
+ }
838
+ if (uuidEntries.length > 255) {
839
+ throw new Error("Impossible: too many UUID entries to encode");
840
+ }
841
+ allBuffers.push(new Uint8Array([uuidEntries.length]));
842
+ allBuffers.push(...uuidEntries);
843
+ if (Object.keys(jsonObj).length > 0) {
844
+ allBuffers.push(stringToUint8Array(JSON.stringify(jsonObj)));
845
+ }
846
+ return uint8ArrayToBase64(concatUint8Arrays(...allBuffers));
847
+ }
848
+ static fromStr(s) {
849
+ try {
850
+ const rawBytes = base64ToUint8Array(s);
851
+ const jsonObj = {};
852
+ if (rawBytes[0] < ENCODING_VERSION_NUMBER3) {
853
+ const spanComponentsOld = SpanComponentsV2.fromStr(s);
854
+ jsonObj["object_type"] = spanComponentsOld.objectType;
855
+ jsonObj["object_id"] = spanComponentsOld.objectId;
856
+ jsonObj["compute_object_metadata_args"] = spanComponentsOld.computeObjectMetadataArgs;
857
+ if (spanComponentsOld.rowIds) {
858
+ jsonObj["row_id"] = spanComponentsOld.rowIds.rowId;
859
+ jsonObj["span_id"] = spanComponentsOld.rowIds.spanId;
860
+ jsonObj["root_span_id"] = spanComponentsOld.rowIds.rootSpanId;
861
+ }
862
+ } else {
863
+ jsonObj["object_type"] = rawBytes[1];
864
+ const numUuidEntries = rawBytes[2];
865
+ let byteOffset = 3;
866
+ for (let i = 0; i < numUuidEntries; ++i) {
867
+ const fieldId = internalSpanComponentUUIDFieldsEnumSchema.parse(
868
+ rawBytes[byteOffset]
869
+ );
870
+ const fieldBytes = rawBytes.subarray(byteOffset + 1, byteOffset + 17);
871
+ byteOffset += 17;
872
+ jsonObj[_INTERNAL_SPAN_COMPONENT_UUID_FIELDS_ID_TO_NAME[fieldId]] = uuid3.stringify(fieldBytes);
873
+ }
874
+ if (byteOffset < rawBytes.length) {
875
+ const remainingJsonObj = JSON.parse(
876
+ uint8ArrayToString(rawBytes.subarray(byteOffset))
877
+ );
878
+ Object.assign(jsonObj, remainingJsonObj);
879
+ }
880
+ }
881
+ return _SpanComponentsV3.fromJsonObj(jsonObj);
882
+ } catch {
883
+ throw new Error(INVALID_ENCODING_ERRMSG3);
884
+ }
885
+ }
886
+ objectIdFields() {
887
+ if (!this.data.object_id) {
888
+ throw new Error(
889
+ "Impossible: cannot invoke `objectIdFields` unless SpanComponentsV3 is initialized with an `object_id`"
890
+ );
891
+ }
892
+ switch (this.data.object_type) {
893
+ case 1 /* EXPERIMENT */:
894
+ return { experiment_id: this.data.object_id };
895
+ case 2 /* PROJECT_LOGS */:
896
+ return { project_id: this.data.object_id, log_id: "g" };
897
+ case 3 /* PLAYGROUND_LOGS */:
898
+ return { prompt_session_id: this.data.object_id, log_id: "x" };
899
+ default:
900
+ const _ = this.data.object_type;
901
+ throw new Error("Impossible");
902
+ }
903
+ }
904
+ async export() {
905
+ return this.toStr();
906
+ }
907
+ static fromJsonObj(jsonObj) {
908
+ return new _SpanComponentsV3(spanComponentsV3Schema.parse(jsonObj));
909
+ }
910
+ };
911
+ function parseParent(parent) {
912
+ return typeof parent === "string" ? parent : parent ? new SpanComponentsV3({
913
+ object_type: parent.object_type === "experiment" ? 1 /* EXPERIMENT */ : parent.object_type === "playground_logs" ? 3 /* PLAYGROUND_LOGS */ : 2 /* PROJECT_LOGS */,
914
+ object_id: parent.object_id,
915
+ ...parent.row_ids ? {
916
+ row_id: parent.row_ids.id,
917
+ span_id: parent.row_ids.span_id,
918
+ root_span_id: parent.row_ids.root_span_id
919
+ } : {
920
+ row_id: void 0,
921
+ span_id: void 0,
922
+ root_span_id: void 0
923
+ },
924
+ propagated_event: parent.propagated_event
925
+ }).toStr() : void 0;
926
+ }
927
+
928
+ // util/http_headers.ts
929
+ var BT_FOUND_EXISTING_HEADER = "x-bt-found-existing";
930
+ var BT_CURSOR_HEADER = "x-bt-cursor";
931
+
932
+ // util/type_util.ts
933
+ function isObject(value) {
934
+ return value instanceof Object && !(value instanceof Array);
935
+ }
936
+ function isArray(value) {
937
+ return value instanceof Array;
938
+ }
939
+ function isObjectOrArray(value) {
940
+ return value instanceof Object;
941
+ }
942
+
943
+ // util/object_util.ts
944
+ function mergeDictsWithPaths({
945
+ mergeInto,
946
+ mergeFrom,
947
+ mergePaths
948
+ }) {
949
+ const mergePathsSerialized = new Set(
950
+ mergePaths.map((p) => JSON.stringify(p))
951
+ );
952
+ return mergeDictsWithPathsHelper({
953
+ mergeInto,
954
+ mergeFrom,
955
+ path: [],
956
+ mergePaths: mergePathsSerialized
957
+ });
958
+ }
959
+ function mergeDictsWithPathsHelper({
960
+ mergeInto,
961
+ mergeFrom,
962
+ path: path3,
963
+ mergePaths
964
+ }) {
965
+ Object.entries(mergeFrom).forEach(([k, mergeFromV]) => {
966
+ const fullPath = path3.concat([k]);
967
+ const fullPathSerialized = JSON.stringify(fullPath);
968
+ const mergeIntoV = recordFind(mergeInto, k);
969
+ if (isObject(mergeIntoV) && isObject(mergeFromV) && !mergePaths.has(fullPathSerialized)) {
970
+ mergeDictsWithPathsHelper({
971
+ mergeInto: mergeIntoV,
972
+ mergeFrom: mergeFromV,
973
+ path: fullPath,
974
+ mergePaths
975
+ });
976
+ } else {
977
+ mergeInto[k] = mergeFromV;
978
+ }
979
+ });
980
+ return mergeInto;
981
+ }
982
+ function mergeDicts(mergeInto, mergeFrom) {
983
+ return mergeDictsWithPaths({ mergeInto, mergeFrom, mergePaths: [] });
984
+ }
985
+ function mapAt(m, k) {
986
+ const ret = m.get(k);
987
+ if (ret === void 0) {
988
+ throw new Error(`Map does not contain key ${k}`);
989
+ }
990
+ return ret;
991
+ }
992
+ function recordFind(m, k) {
993
+ return m[k];
994
+ }
995
+ function getObjValueByPath(row, path3) {
996
+ let curr = row;
997
+ for (const p of path3) {
998
+ if (!isObjectOrArray(curr)) {
999
+ return null;
1000
+ }
1001
+ curr = curr[p];
1002
+ }
1003
+ return curr;
1004
+ }
1005
+
1006
+ // util/graph_util.ts
1007
+ function depthFirstSearch(args) {
1008
+ const { graph, firstVisitF, lastVisitF } = args;
1009
+ for (const vs of graph.values()) {
1010
+ for (const v of vs.values()) {
1011
+ if (!graph.has(v)) {
1012
+ throw new Error(`Outgoing vertex ${v} must be a key in the graph`);
1013
+ }
1014
+ }
1015
+ }
1016
+ const firstVisitedVertices = /* @__PURE__ */ new Set();
1017
+ const visitationOrder = args.visitationOrder ?? [...graph.keys()];
1018
+ const events = visitationOrder.map((vertex) => ({ eventType: "first", vertex, extras: {} })).reverse();
1019
+ while (events.length) {
1020
+ const { eventType, vertex, extras } = events.pop();
1021
+ if (eventType === "last") {
1022
+ lastVisitF?.(vertex);
1023
+ continue;
1024
+ }
1025
+ if (firstVisitedVertices.has(vertex)) {
1026
+ continue;
1027
+ }
1028
+ firstVisitedVertices.add(vertex);
1029
+ firstVisitF?.(vertex, { parentVertex: extras.parentVertex });
1030
+ events.push({ eventType: "last", vertex, extras: {} });
1031
+ mapAt(graph, vertex).forEach((child) => {
1032
+ events.push({
1033
+ eventType: "first",
1034
+ vertex: child,
1035
+ extras: { parentVertex: vertex }
1036
+ });
1037
+ });
1038
+ }
1039
+ }
1040
+ function undirectedConnectedComponents(graph) {
1041
+ const directedGraph = new Map(
1042
+ [...graph.vertices].map((v) => [v, /* @__PURE__ */ new Set()])
1043
+ );
1044
+ for (const [i, j] of graph.edges) {
1045
+ mapAt(directedGraph, i).add(j);
1046
+ mapAt(directedGraph, j).add(i);
1047
+ }
1048
+ let labelCounter = 0;
1049
+ const vertexLabels = /* @__PURE__ */ new Map();
1050
+ const firstVisitF = (vertex, args) => {
1051
+ const label = args?.parentVertex !== void 0 ? mapAt(vertexLabels, args?.parentVertex) : labelCounter++;
1052
+ vertexLabels.set(vertex, label);
1053
+ };
1054
+ depthFirstSearch({ graph: directedGraph, firstVisitF });
1055
+ const output = Array.from({ length: labelCounter }).map(() => []);
1056
+ for (const [vertex, label] of vertexLabels.entries()) {
1057
+ output[label].push(vertex);
1058
+ }
1059
+ return output;
1060
+ }
1061
+ function topologicalSort(graph, visitationOrder) {
1062
+ const reverseOrdering = [];
1063
+ const lastVisitF = (vertex) => {
1064
+ reverseOrdering.push(vertex);
1065
+ };
1066
+ depthFirstSearch({ graph, lastVisitF, visitationOrder });
1067
+ return reverseOrdering.reverse();
1068
+ }
1069
+
1070
+ // util/merge_row_batch.ts
1071
+ function generateMergedRowKey(row, useParentIdForId) {
1072
+ return JSON.stringify(
1073
+ [
1074
+ "org_id",
1075
+ "project_id",
1076
+ "experiment_id",
1077
+ "dataset_id",
1078
+ "prompt_session_id",
1079
+ "log_id",
1080
+ useParentIdForId ?? false ? PARENT_ID_FIELD : "id"
1081
+ ].map((k) => row[k])
1082
+ );
1083
+ }
1084
+ var MERGE_ROW_SKIP_FIELDS = [
1085
+ "created",
1086
+ "span_id",
1087
+ "root_span_id",
1088
+ "span_parents",
1089
+ "_parent_id"
1090
+ // TODO: handle merge paths.
1091
+ ];
1092
+ function popMergeRowSkipFields(row) {
1093
+ const popped = {};
1094
+ for (const field of MERGE_ROW_SKIP_FIELDS) {
1095
+ if (field in row) {
1096
+ popped[field] = row[field];
1097
+ delete row[field];
1098
+ }
1099
+ }
1100
+ return popped;
1101
+ }
1102
+ function restoreMergeRowSkipFields(row, skipFields) {
1103
+ for (const field of MERGE_ROW_SKIP_FIELDS) {
1104
+ delete row[field];
1105
+ if (field in skipFields) {
1106
+ row[field] = skipFields[field];
1107
+ }
1108
+ }
1109
+ }
1110
+ function mergeRowBatch(rows) {
1111
+ for (const row of rows) {
1112
+ if (row.id === void 0) {
1113
+ throw new Error(
1114
+ "Logged row is missing an id. This is an internal braintrust error. Please contact us at info@braintrust.dev for help"
1115
+ );
1116
+ }
1117
+ }
1118
+ const rowGroups = /* @__PURE__ */ new Map();
1119
+ for (const row of rows) {
1120
+ const key = generateMergedRowKey(row);
1121
+ const existingRow = rowGroups.get(key);
1122
+ if (existingRow !== void 0 && row[IS_MERGE_FIELD]) {
1123
+ const skipFields = popMergeRowSkipFields(existingRow);
1124
+ const preserveNoMerge = !existingRow[IS_MERGE_FIELD];
1125
+ mergeDicts(existingRow, row);
1126
+ restoreMergeRowSkipFields(existingRow, skipFields);
1127
+ if (preserveNoMerge) {
1128
+ delete existingRow[IS_MERGE_FIELD];
1129
+ }
1130
+ } else {
1131
+ rowGroups.set(key, row);
1132
+ }
1133
+ }
1134
+ const merged = [...rowGroups.values()];
1135
+ const rowToLabel = new Map(
1136
+ merged.map((r, i) => [generateMergedRowKey(r), i])
1137
+ );
1138
+ const graph = new Map(
1139
+ Array.from({ length: merged.length }).map((_, i) => [i, /* @__PURE__ */ new Set()])
1140
+ );
1141
+ merged.forEach((r, i) => {
1142
+ const parentId = r[PARENT_ID_FIELD];
1143
+ if (!parentId) {
1144
+ return;
1145
+ }
1146
+ const parentRowKey = generateMergedRowKey(
1147
+ r,
1148
+ true
1149
+ /* useParentIdForId */
1150
+ );
1151
+ const parentLabel = rowToLabel.get(parentRowKey);
1152
+ if (parentLabel !== void 0) {
1153
+ mapAt(graph, parentLabel).add(i);
1154
+ }
1155
+ });
1156
+ const connectedComponents = undirectedConnectedComponents({
1157
+ vertices: new Set(graph.keys()),
1158
+ edges: new Set(
1159
+ [...graph.entries()].flatMap(
1160
+ ([k, vs]) => [...vs].map((v) => {
1161
+ const ret = [k, v];
1162
+ return ret;
1163
+ })
1164
+ )
1165
+ )
1166
+ });
1167
+ const buckets = connectedComponents.map(
1168
+ (cc) => topologicalSort(
1169
+ graph,
1170
+ cc
1171
+ /* visitationOrder */
1172
+ )
1173
+ );
1174
+ return buckets.map((bucket) => bucket.map((i) => merged[i]));
1175
+ }
1176
+ function batchItems(args) {
1177
+ let { items } = args;
1178
+ const batchMaxNumItems = args.batchMaxNumItems ?? Number.POSITIVE_INFINITY;
1179
+ const batchMaxNumBytes = args.batchMaxNumBytes ?? Number.POSITIVE_INFINITY;
1180
+ const output = [];
1181
+ let nextItems = [];
1182
+ let batchSet = [];
1183
+ let batch = [];
1184
+ let batchLen = 0;
1185
+ function addToBatch(item) {
1186
+ batch.push(item);
1187
+ batchLen += item.length;
1188
+ }
1189
+ function flushBatch() {
1190
+ batchSet.push(batch);
1191
+ batch = [];
1192
+ batchLen = 0;
1193
+ }
1194
+ while (items.length) {
1195
+ for (const bucket of items) {
1196
+ let i = 0;
1197
+ for (const item of bucket) {
1198
+ if (batch.length === 0 || item.length + batchLen < batchMaxNumBytes && batch.length < batchMaxNumItems) {
1199
+ addToBatch(item);
1200
+ } else if (i === 0) {
1201
+ flushBatch();
1202
+ addToBatch(item);
1203
+ } else {
1204
+ break;
1205
+ }
1206
+ ++i;
1207
+ }
1208
+ if (i < bucket.length) {
1209
+ nextItems.push(bucket.slice(i));
1210
+ }
1211
+ if (batchLen >= batchMaxNumBytes || batch.length > batchMaxNumItems) {
1212
+ flushBatch();
1213
+ }
1214
+ }
1215
+ if (batch.length) {
1216
+ flushBatch();
1217
+ }
1218
+ if (batchSet.length) {
1219
+ output.push(batchSet);
1220
+ batchSet = [];
1221
+ }
1222
+ items = nextItems;
1223
+ nextItems = [];
1224
+ }
1225
+ return output;
1226
+ }
1227
+
1228
+ // util/object.ts
1229
+ var DEFAULT_IS_LEGACY_DATASET = false;
1230
+ function ensureDatasetRecord(r, legacy) {
1231
+ if (legacy) {
1232
+ return ensureLegacyDatasetRecord(r);
1233
+ } else {
1234
+ return ensureNewDatasetRecord(r);
1235
+ }
1236
+ }
1237
+ function ensureLegacyDatasetRecord(r) {
1238
+ if ("output" in r) {
1239
+ return r;
1240
+ }
1241
+ const row = {
1242
+ ...r,
1243
+ output: r.expected
1244
+ };
1245
+ delete row.expected;
1246
+ return row;
1247
+ }
1248
+ function ensureNewDatasetRecord(r) {
1249
+ if ("expected" in r) {
1250
+ return r;
1251
+ }
1252
+ const row = {
1253
+ ...r,
1254
+ tags: null,
1255
+ expected: r.output
1256
+ };
1257
+ delete row.output;
1258
+ return row;
1259
+ }
1260
+
1261
+ // util/json_util.ts
1262
+ function constructJsonArray(items) {
1263
+ return `[${items.join(",")}]`;
1264
+ }
1265
+
1266
+ // util/string_util.ts
1267
+ function _urljoin(...parts) {
1268
+ return parts.map(
1269
+ (x, i) => x.replace(/^\//, "").replace(i < parts.length - 1 ? /\/$/ : "", "")
1270
+ ).filter((x) => x.trim() !== "").join("/");
1271
+ }
1272
+
1273
+ // util/git_fields.ts
1274
+ function mergeGitMetadataSettings(s1, s2) {
1275
+ if (s1.collect === "all") {
1276
+ return s2;
1277
+ } else if (s2.collect === "all") {
1278
+ return s1;
1279
+ } else if (s1.collect === "none") {
1280
+ return s1;
1281
+ } else if (s2.collect === "none") {
1282
+ return s2;
1283
+ }
1284
+ const fields = (s1.fields ?? []).filter((f) => (s2.fields ?? []).includes(f));
1285
+ const collect = fields.length > 0 ? "some" : "none";
1286
+ return { collect, fields };
1287
+ }
1288
+
1289
+ // util/xact-ids.ts
1290
+ var TOP_BITS = BigInt("0x0DE1") << BigInt(48);
1291
+ var MOD = BigInt(1) << BigInt(64);
1292
+ var COPRIME = BigInt("205891132094649");
1293
+ var COPRIME_INVERSE = BigInt("1522336535492693385");
1294
+ function modularMultiply(value, prime) {
1295
+ return value * prime % MOD;
1296
+ }
1297
+ function loadPrettyXact(encodedHex) {
1298
+ if (encodedHex.length !== 16) {
1299
+ return encodedHex;
1300
+ }
1301
+ const value = BigInt(`0x${encodedHex}`);
1302
+ const multipliedInverse = modularMultiply(value, COPRIME_INVERSE);
1303
+ const withTopBits = TOP_BITS | multipliedInverse;
1304
+ return withTopBits.toString();
1305
+ }
1306
+
1307
+ // util/zod_util.ts
1308
+ import { z as z4 } from "zod/v3";
328
1309
 
329
1310
  // src/generated_types.ts
330
- import { z } from "zod";
331
- var AclObjectType = z.union([
332
- z.enum([
1311
+ import { z as z5 } from "zod/v3";
1312
+ var AclObjectType = z5.union([
1313
+ z5.enum([
333
1314
  "organization",
334
1315
  "project",
335
1316
  "experiment",
@@ -342,9 +1323,9 @@ var AclObjectType = z.union([
342
1323
  "project_log",
343
1324
  "org_project"
344
1325
  ]),
345
- z.null()
1326
+ z5.null()
346
1327
  ]);
347
- var Permission = z.enum([
1328
+ var Permission = z5.enum([
348
1329
  "create",
349
1330
  "read",
350
1331
  "update",
@@ -354,310 +1335,310 @@ var Permission = z.enum([
354
1335
  "update_acls",
355
1336
  "delete_acls"
356
1337
  ]);
357
- var Acl = z.object({
358
- id: z.string().uuid(),
359
- object_type: AclObjectType.and(z.string()),
360
- object_id: z.string().uuid(),
361
- user_id: z.union([z.string(), z.null()]).optional(),
362
- group_id: z.union([z.string(), z.null()]).optional(),
363
- permission: Permission.and(z.union([z.string(), z.null()])).optional(),
364
- restrict_object_type: AclObjectType.and(z.unknown()).optional(),
365
- role_id: z.union([z.string(), z.null()]).optional(),
366
- _object_org_id: z.string().uuid(),
367
- created: z.union([z.string(), z.null()]).optional()
1338
+ var Acl = z5.object({
1339
+ id: z5.string().uuid(),
1340
+ object_type: AclObjectType.and(z5.string()),
1341
+ object_id: z5.string().uuid(),
1342
+ user_id: z5.union([z5.string(), z5.null()]).optional(),
1343
+ group_id: z5.union([z5.string(), z5.null()]).optional(),
1344
+ permission: Permission.and(z5.union([z5.string(), z5.null()])).optional(),
1345
+ restrict_object_type: AclObjectType.and(z5.unknown()).optional(),
1346
+ role_id: z5.union([z5.string(), z5.null()]).optional(),
1347
+ _object_org_id: z5.string().uuid(),
1348
+ created: z5.union([z5.string(), z5.null()]).optional()
368
1349
  });
369
- var AISecret = z.object({
370
- id: z.string().uuid(),
371
- created: z.union([z.string(), z.null()]).optional(),
372
- updated_at: z.union([z.string(), z.null()]).optional(),
373
- org_id: z.string().uuid(),
374
- name: z.string(),
375
- type: z.union([z.string(), z.null()]).optional(),
376
- metadata: z.union([z.object({}).partial().passthrough(), z.null()]).optional(),
377
- preview_secret: z.union([z.string(), z.null()]).optional()
1350
+ var AISecret = z5.object({
1351
+ id: z5.string().uuid(),
1352
+ created: z5.union([z5.string(), z5.null()]).optional(),
1353
+ updated_at: z5.union([z5.string(), z5.null()]).optional(),
1354
+ org_id: z5.string().uuid(),
1355
+ name: z5.string(),
1356
+ type: z5.union([z5.string(), z5.null()]).optional(),
1357
+ metadata: z5.union([z5.object({}).partial().passthrough(), z5.null()]).optional(),
1358
+ preview_secret: z5.union([z5.string(), z5.null()]).optional()
378
1359
  });
379
- var ResponseFormatJsonSchema = z.object({
380
- name: z.string(),
381
- description: z.string().optional(),
382
- schema: z.union([z.object({}).partial().passthrough(), z.string()]).optional(),
383
- strict: z.union([z.boolean(), z.null()]).optional()
1360
+ var ResponseFormatJsonSchema = z5.object({
1361
+ name: z5.string(),
1362
+ description: z5.string().optional(),
1363
+ schema: z5.union([z5.object({}).partial().passthrough(), z5.string()]).optional(),
1364
+ strict: z5.union([z5.boolean(), z5.null()]).optional()
384
1365
  });
385
- var ResponseFormatNullish = z.union([
386
- z.object({ type: z.literal("json_object") }),
387
- z.object({
388
- type: z.literal("json_schema"),
1366
+ var ResponseFormatNullish = z5.union([
1367
+ z5.object({ type: z5.literal("json_object") }),
1368
+ z5.object({
1369
+ type: z5.literal("json_schema"),
389
1370
  json_schema: ResponseFormatJsonSchema
390
1371
  }),
391
- z.object({ type: z.literal("text") }),
392
- z.null()
1372
+ z5.object({ type: z5.literal("text") }),
1373
+ z5.null()
393
1374
  ]);
394
- var AnyModelParams = z.object({
395
- temperature: z.number().optional(),
396
- top_p: z.number().optional(),
397
- max_tokens: z.number(),
398
- max_completion_tokens: z.number().optional(),
399
- frequency_penalty: z.number().optional(),
400
- presence_penalty: z.number().optional(),
1375
+ var AnyModelParams = z5.object({
1376
+ temperature: z5.number().optional(),
1377
+ top_p: z5.number().optional(),
1378
+ max_tokens: z5.number(),
1379
+ max_completion_tokens: z5.number().optional(),
1380
+ frequency_penalty: z5.number().optional(),
1381
+ presence_penalty: z5.number().optional(),
401
1382
  response_format: ResponseFormatNullish.optional(),
402
- tool_choice: z.union([
403
- z.literal("auto"),
404
- z.literal("none"),
405
- z.literal("required"),
406
- z.object({
407
- type: z.literal("function"),
408
- function: z.object({ name: z.string() })
1383
+ tool_choice: z5.union([
1384
+ z5.literal("auto"),
1385
+ z5.literal("none"),
1386
+ z5.literal("required"),
1387
+ z5.object({
1388
+ type: z5.literal("function"),
1389
+ function: z5.object({ name: z5.string() })
409
1390
  })
410
1391
  ]).optional(),
411
- function_call: z.union([
412
- z.literal("auto"),
413
- z.literal("none"),
414
- z.object({ name: z.string() })
1392
+ function_call: z5.union([
1393
+ z5.literal("auto"),
1394
+ z5.literal("none"),
1395
+ z5.object({ name: z5.string() })
415
1396
  ]).optional(),
416
- n: z.number().optional(),
417
- stop: z.array(z.string()).optional(),
418
- reasoning_effort: z.enum(["minimal", "low", "medium", "high"]).optional(),
419
- verbosity: z.enum(["low", "medium", "high"]).optional(),
420
- top_k: z.number().optional(),
421
- stop_sequences: z.array(z.string()).optional(),
422
- max_tokens_to_sample: z.number().optional(),
423
- maxOutputTokens: z.number().optional(),
424
- topP: z.number().optional(),
425
- topK: z.number().optional(),
426
- use_cache: z.boolean().optional()
1397
+ n: z5.number().optional(),
1398
+ stop: z5.array(z5.string()).optional(),
1399
+ reasoning_effort: z5.enum(["minimal", "low", "medium", "high"]).optional(),
1400
+ verbosity: z5.enum(["low", "medium", "high"]).optional(),
1401
+ top_k: z5.number().optional(),
1402
+ stop_sequences: z5.array(z5.string()).optional(),
1403
+ max_tokens_to_sample: z5.number().optional(),
1404
+ maxOutputTokens: z5.number().optional(),
1405
+ topP: z5.number().optional(),
1406
+ topK: z5.number().optional(),
1407
+ use_cache: z5.boolean().optional()
427
1408
  });
428
- var ApiKey = z.object({
429
- id: z.string().uuid(),
430
- created: z.union([z.string(), z.null()]).optional(),
431
- name: z.string(),
432
- preview_name: z.string(),
433
- user_id: z.union([z.string(), z.null()]).optional(),
434
- user_email: z.union([z.string(), z.null()]).optional(),
435
- user_given_name: z.union([z.string(), z.null()]).optional(),
436
- user_family_name: z.union([z.string(), z.null()]).optional(),
437
- org_id: z.union([z.string(), z.null()]).optional()
1409
+ var ApiKey = z5.object({
1410
+ id: z5.string().uuid(),
1411
+ created: z5.union([z5.string(), z5.null()]).optional(),
1412
+ name: z5.string(),
1413
+ preview_name: z5.string(),
1414
+ user_id: z5.union([z5.string(), z5.null()]).optional(),
1415
+ user_email: z5.union([z5.string(), z5.null()]).optional(),
1416
+ user_given_name: z5.union([z5.string(), z5.null()]).optional(),
1417
+ user_family_name: z5.union([z5.string(), z5.null()]).optional(),
1418
+ org_id: z5.union([z5.string(), z5.null()]).optional()
438
1419
  });
439
- var AsyncScoringState = z.union([
440
- z.object({
441
- status: z.literal("enabled"),
442
- token: z.string(),
443
- function_ids: z.array(z.unknown()).min(1),
444
- skip_logging: z.union([z.boolean(), z.null()]).optional()
1420
+ var AsyncScoringState = z5.union([
1421
+ z5.object({
1422
+ status: z5.literal("enabled"),
1423
+ token: z5.string(),
1424
+ function_ids: z5.array(z5.unknown()).min(1),
1425
+ skip_logging: z5.union([z5.boolean(), z5.null()]).optional()
445
1426
  }),
446
- z.object({ status: z.literal("disabled") }),
447
- z.null(),
448
- z.null()
1427
+ z5.object({ status: z5.literal("disabled") }),
1428
+ z5.null(),
1429
+ z5.null()
449
1430
  ]);
450
- var AsyncScoringControl = z.union([
451
- z.object({ kind: z.literal("score_update"), token: z.string() }),
452
- z.object({ kind: z.literal("state_override"), state: AsyncScoringState }),
453
- z.object({ kind: z.literal("state_force_reselect") }),
454
- z.object({ kind: z.literal("state_enabled_force_rescore") })
1431
+ var AsyncScoringControl = z5.union([
1432
+ z5.object({ kind: z5.literal("score_update"), token: z5.string() }),
1433
+ z5.object({ kind: z5.literal("state_override"), state: AsyncScoringState }),
1434
+ z5.object({ kind: z5.literal("state_force_reselect") }),
1435
+ z5.object({ kind: z5.literal("state_enabled_force_rescore") })
455
1436
  ]);
456
- var BraintrustAttachmentReference = z.object({
457
- type: z.literal("braintrust_attachment"),
458
- filename: z.string().min(1),
459
- content_type: z.string().min(1),
460
- key: z.string().min(1)
1437
+ var BraintrustAttachmentReference = z5.object({
1438
+ type: z5.literal("braintrust_attachment"),
1439
+ filename: z5.string().min(1),
1440
+ content_type: z5.string().min(1),
1441
+ key: z5.string().min(1)
461
1442
  });
462
- var ExternalAttachmentReference = z.object({
463
- type: z.literal("external_attachment"),
464
- filename: z.string().min(1),
465
- content_type: z.string().min(1),
466
- url: z.string().min(1)
1443
+ var ExternalAttachmentReference = z5.object({
1444
+ type: z5.literal("external_attachment"),
1445
+ filename: z5.string().min(1),
1446
+ content_type: z5.string().min(1),
1447
+ url: z5.string().min(1)
467
1448
  });
468
- var AttachmentReference = z.discriminatedUnion("type", [
1449
+ var AttachmentReference = z5.discriminatedUnion("type", [
469
1450
  BraintrustAttachmentReference,
470
1451
  ExternalAttachmentReference
471
1452
  ]);
472
- var UploadStatus = z.enum(["uploading", "done", "error"]);
473
- var AttachmentStatus = z.object({
1453
+ var UploadStatus = z5.enum(["uploading", "done", "error"]);
1454
+ var AttachmentStatus = z5.object({
474
1455
  upload_status: UploadStatus,
475
- error_message: z.string().optional()
1456
+ error_message: z5.string().optional()
476
1457
  });
477
- var BraintrustModelParams = z.object({ use_cache: z.boolean() }).partial();
478
- var CallEvent = z.union([
479
- z.object({
480
- id: z.string().optional(),
481
- data: z.string(),
482
- event: z.literal("text_delta")
1458
+ var BraintrustModelParams = z5.object({ use_cache: z5.boolean() }).partial();
1459
+ var CallEvent = z5.union([
1460
+ z5.object({
1461
+ id: z5.string().optional(),
1462
+ data: z5.string(),
1463
+ event: z5.literal("text_delta")
483
1464
  }),
484
- z.object({
485
- id: z.string().optional(),
486
- data: z.string(),
487
- event: z.literal("reasoning_delta")
1465
+ z5.object({
1466
+ id: z5.string().optional(),
1467
+ data: z5.string(),
1468
+ event: z5.literal("reasoning_delta")
488
1469
  }),
489
- z.object({
490
- id: z.string().optional(),
491
- data: z.string(),
492
- event: z.literal("json_delta")
1470
+ z5.object({
1471
+ id: z5.string().optional(),
1472
+ data: z5.string(),
1473
+ event: z5.literal("json_delta")
493
1474
  }),
494
- z.object({
495
- id: z.string().optional(),
496
- data: z.string(),
497
- event: z.literal("progress")
1475
+ z5.object({
1476
+ id: z5.string().optional(),
1477
+ data: z5.string(),
1478
+ event: z5.literal("progress")
498
1479
  }),
499
- z.object({
500
- id: z.string().optional(),
501
- data: z.string(),
502
- event: z.literal("error")
1480
+ z5.object({
1481
+ id: z5.string().optional(),
1482
+ data: z5.string(),
1483
+ event: z5.literal("error")
503
1484
  }),
504
- z.object({
505
- id: z.string().optional(),
506
- data: z.string(),
507
- event: z.literal("console")
1485
+ z5.object({
1486
+ id: z5.string().optional(),
1487
+ data: z5.string(),
1488
+ event: z5.literal("console")
508
1489
  }),
509
- z.object({
510
- id: z.string().optional(),
511
- event: z.literal("start"),
512
- data: z.literal("")
1490
+ z5.object({
1491
+ id: z5.string().optional(),
1492
+ event: z5.literal("start"),
1493
+ data: z5.literal("")
513
1494
  }),
514
- z.object({
515
- id: z.string().optional(),
516
- event: z.literal("done"),
517
- data: z.literal("")
1495
+ z5.object({
1496
+ id: z5.string().optional(),
1497
+ event: z5.literal("done"),
1498
+ data: z5.literal("")
518
1499
  })
519
1500
  ]);
520
- var ChatCompletionContentPartTextWithTitle = z.object({
521
- text: z.string().default(""),
522
- type: z.literal("text"),
523
- cache_control: z.object({ type: z.literal("ephemeral") }).optional()
1501
+ var ChatCompletionContentPartTextWithTitle = z5.object({
1502
+ text: z5.string().default(""),
1503
+ type: z5.literal("text"),
1504
+ cache_control: z5.object({ type: z5.literal("ephemeral") }).optional()
524
1505
  });
525
- var ChatCompletionContentPartImageWithTitle = z.object({
526
- image_url: z.object({
527
- url: z.string(),
528
- detail: z.union([z.literal("auto"), z.literal("low"), z.literal("high")]).optional()
1506
+ var ChatCompletionContentPartImageWithTitle = z5.object({
1507
+ image_url: z5.object({
1508
+ url: z5.string(),
1509
+ detail: z5.union([z5.literal("auto"), z5.literal("low"), z5.literal("high")]).optional()
529
1510
  }),
530
- type: z.literal("image_url")
1511
+ type: z5.literal("image_url")
531
1512
  });
532
- var ChatCompletionContentPart = z.union([
1513
+ var ChatCompletionContentPart = z5.union([
533
1514
  ChatCompletionContentPartTextWithTitle,
534
1515
  ChatCompletionContentPartImageWithTitle
535
1516
  ]);
536
- var ChatCompletionContentPartText = z.object({
537
- text: z.string().default(""),
538
- type: z.literal("text"),
539
- cache_control: z.object({ type: z.literal("ephemeral") }).optional()
1517
+ var ChatCompletionContentPartText = z5.object({
1518
+ text: z5.string().default(""),
1519
+ type: z5.literal("text"),
1520
+ cache_control: z5.object({ type: z5.literal("ephemeral") }).optional()
540
1521
  });
541
- var ChatCompletionMessageToolCall = z.object({
542
- id: z.string(),
543
- function: z.object({ arguments: z.string(), name: z.string() }),
544
- type: z.literal("function")
1522
+ var ChatCompletionMessageToolCall = z5.object({
1523
+ id: z5.string(),
1524
+ function: z5.object({ arguments: z5.string(), name: z5.string() }),
1525
+ type: z5.literal("function")
545
1526
  });
546
- var ChatCompletionMessageReasoning = z.object({ id: z.string(), content: z.string() }).partial();
547
- var ChatCompletionMessageParam = z.union([
548
- z.object({
549
- content: z.union([z.string(), z.array(ChatCompletionContentPartText)]),
550
- role: z.literal("system"),
551
- name: z.string().optional()
1527
+ var ChatCompletionMessageReasoning = z5.object({ id: z5.string(), content: z5.string() }).partial();
1528
+ var ChatCompletionMessageParam = z5.union([
1529
+ z5.object({
1530
+ content: z5.union([z5.string(), z5.array(ChatCompletionContentPartText)]),
1531
+ role: z5.literal("system"),
1532
+ name: z5.string().optional()
552
1533
  }),
553
- z.object({
554
- content: z.union([z.string(), z.array(ChatCompletionContentPart)]),
555
- role: z.literal("user"),
556
- name: z.string().optional()
1534
+ z5.object({
1535
+ content: z5.union([z5.string(), z5.array(ChatCompletionContentPart)]),
1536
+ role: z5.literal("user"),
1537
+ name: z5.string().optional()
557
1538
  }),
558
- z.object({
559
- role: z.literal("assistant"),
560
- content: z.union([z.string(), z.array(ChatCompletionContentPartText), z.null()]).optional(),
561
- function_call: z.object({ arguments: z.string(), name: z.string() }).optional(),
562
- name: z.string().optional(),
563
- tool_calls: z.array(ChatCompletionMessageToolCall).optional(),
564
- reasoning: z.array(ChatCompletionMessageReasoning).optional()
1539
+ z5.object({
1540
+ role: z5.literal("assistant"),
1541
+ content: z5.union([z5.string(), z5.array(ChatCompletionContentPartText), z5.null()]).optional(),
1542
+ function_call: z5.object({ arguments: z5.string(), name: z5.string() }).optional(),
1543
+ name: z5.string().optional(),
1544
+ tool_calls: z5.array(ChatCompletionMessageToolCall).optional(),
1545
+ reasoning: z5.array(ChatCompletionMessageReasoning).optional()
565
1546
  }),
566
- z.object({
567
- content: z.union([z.string(), z.array(ChatCompletionContentPartText)]),
568
- role: z.literal("tool"),
569
- tool_call_id: z.string().default("")
1547
+ z5.object({
1548
+ content: z5.union([z5.string(), z5.array(ChatCompletionContentPartText)]),
1549
+ role: z5.literal("tool"),
1550
+ tool_call_id: z5.string().default("")
570
1551
  }),
571
- z.object({
572
- content: z.union([z.string(), z.null()]),
573
- name: z.string(),
574
- role: z.literal("function")
1552
+ z5.object({
1553
+ content: z5.union([z5.string(), z5.null()]),
1554
+ name: z5.string(),
1555
+ role: z5.literal("function")
575
1556
  }),
576
- z.object({
577
- content: z.union([z.string(), z.array(ChatCompletionContentPartText)]),
578
- role: z.literal("developer"),
579
- name: z.string().optional()
1557
+ z5.object({
1558
+ content: z5.union([z5.string(), z5.array(ChatCompletionContentPartText)]),
1559
+ role: z5.literal("developer"),
1560
+ name: z5.string().optional()
580
1561
  }),
581
- z.object({
582
- role: z.literal("model"),
583
- content: z.union([z.string(), z.null()]).optional()
1562
+ z5.object({
1563
+ role: z5.literal("model"),
1564
+ content: z5.union([z5.string(), z5.null()]).optional()
584
1565
  })
585
1566
  ]);
586
- var ChatCompletionOpenAIMessageParam = z.union([
587
- z.object({
588
- content: z.union([z.string(), z.array(ChatCompletionContentPartText)]),
589
- role: z.literal("system"),
590
- name: z.string().optional()
1567
+ var ChatCompletionOpenAIMessageParam = z5.union([
1568
+ z5.object({
1569
+ content: z5.union([z5.string(), z5.array(ChatCompletionContentPartText)]),
1570
+ role: z5.literal("system"),
1571
+ name: z5.string().optional()
591
1572
  }),
592
- z.object({
593
- content: z.union([z.string(), z.array(ChatCompletionContentPart)]),
594
- role: z.literal("user"),
595
- name: z.string().optional()
1573
+ z5.object({
1574
+ content: z5.union([z5.string(), z5.array(ChatCompletionContentPart)]),
1575
+ role: z5.literal("user"),
1576
+ name: z5.string().optional()
596
1577
  }),
597
- z.object({
598
- role: z.literal("assistant"),
599
- content: z.union([z.string(), z.array(ChatCompletionContentPartText), z.null()]).optional(),
600
- function_call: z.object({ arguments: z.string(), name: z.string() }).optional(),
601
- name: z.string().optional(),
602
- tool_calls: z.array(ChatCompletionMessageToolCall).optional(),
603
- reasoning: z.array(ChatCompletionMessageReasoning).optional()
1578
+ z5.object({
1579
+ role: z5.literal("assistant"),
1580
+ content: z5.union([z5.string(), z5.array(ChatCompletionContentPartText), z5.null()]).optional(),
1581
+ function_call: z5.object({ arguments: z5.string(), name: z5.string() }).optional(),
1582
+ name: z5.string().optional(),
1583
+ tool_calls: z5.array(ChatCompletionMessageToolCall).optional(),
1584
+ reasoning: z5.array(ChatCompletionMessageReasoning).optional()
604
1585
  }),
605
- z.object({
606
- content: z.union([z.string(), z.array(ChatCompletionContentPartText)]),
607
- role: z.literal("tool"),
608
- tool_call_id: z.string().default("")
1586
+ z5.object({
1587
+ content: z5.union([z5.string(), z5.array(ChatCompletionContentPartText)]),
1588
+ role: z5.literal("tool"),
1589
+ tool_call_id: z5.string().default("")
609
1590
  }),
610
- z.object({
611
- content: z.union([z.string(), z.null()]),
612
- name: z.string(),
613
- role: z.literal("function")
1591
+ z5.object({
1592
+ content: z5.union([z5.string(), z5.null()]),
1593
+ name: z5.string(),
1594
+ role: z5.literal("function")
614
1595
  }),
615
- z.object({
616
- content: z.union([z.string(), z.array(ChatCompletionContentPartText)]),
617
- role: z.literal("developer"),
618
- name: z.string().optional()
1596
+ z5.object({
1597
+ content: z5.union([z5.string(), z5.array(ChatCompletionContentPartText)]),
1598
+ role: z5.literal("developer"),
1599
+ name: z5.string().optional()
619
1600
  })
620
1601
  ]);
621
- var ChatCompletionTool = z.object({
622
- function: z.object({
623
- name: z.string(),
624
- description: z.string().optional(),
625
- parameters: z.object({}).partial().passthrough().optional()
1602
+ var ChatCompletionTool = z5.object({
1603
+ function: z5.object({
1604
+ name: z5.string(),
1605
+ description: z5.string().optional(),
1606
+ parameters: z5.object({}).partial().passthrough().optional()
626
1607
  }),
627
- type: z.literal("function")
1608
+ type: z5.literal("function")
628
1609
  });
629
- var CodeBundle = z.object({
630
- runtime_context: z.object({
631
- runtime: z.enum(["node", "python"]),
632
- version: z.string()
1610
+ var CodeBundle = z5.object({
1611
+ runtime_context: z5.object({
1612
+ runtime: z5.enum(["node", "python"]),
1613
+ version: z5.string()
633
1614
  }),
634
- location: z.union([
635
- z.object({
636
- type: z.literal("experiment"),
637
- eval_name: z.string(),
638
- position: z.union([
639
- z.object({ type: z.literal("task") }),
640
- z.object({ type: z.literal("scorer"), index: z.number().int().gte(0) })
1615
+ location: z5.union([
1616
+ z5.object({
1617
+ type: z5.literal("experiment"),
1618
+ eval_name: z5.string(),
1619
+ position: z5.union([
1620
+ z5.object({ type: z5.literal("task") }),
1621
+ z5.object({ type: z5.literal("scorer"), index: z5.number().int().gte(0) })
641
1622
  ])
642
1623
  }),
643
- z.object({ type: z.literal("function"), index: z.number().int().gte(0) })
1624
+ z5.object({ type: z5.literal("function"), index: z5.number().int().gte(0) })
644
1625
  ]),
645
- bundle_id: z.string(),
646
- preview: z.union([z.string(), z.null()]).optional()
1626
+ bundle_id: z5.string(),
1627
+ preview: z5.union([z5.string(), z5.null()]).optional()
647
1628
  });
648
- var Dataset = z.object({
649
- id: z.string().uuid(),
650
- project_id: z.string().uuid(),
651
- name: z.string(),
652
- description: z.union([z.string(), z.null()]).optional(),
653
- created: z.union([z.string(), z.null()]).optional(),
654
- deleted_at: z.union([z.string(), z.null()]).optional(),
655
- user_id: z.union([z.string(), z.null()]).optional(),
656
- metadata: z.union([z.object({}).partial().passthrough(), z.null()]).optional()
1629
+ var Dataset = z5.object({
1630
+ id: z5.string().uuid(),
1631
+ project_id: z5.string().uuid(),
1632
+ name: z5.string(),
1633
+ description: z5.union([z5.string(), z5.null()]).optional(),
1634
+ created: z5.union([z5.string(), z5.null()]).optional(),
1635
+ deleted_at: z5.union([z5.string(), z5.null()]).optional(),
1636
+ user_id: z5.union([z5.string(), z5.null()]).optional(),
1637
+ metadata: z5.union([z5.object({}).partial().passthrough(), z5.null()]).optional()
657
1638
  });
658
- var ObjectReferenceNullish = z.union([
659
- z.object({
660
- object_type: z.enum([
1639
+ var ObjectReferenceNullish = z5.union([
1640
+ z5.object({
1641
+ object_type: z5.enum([
661
1642
  "project_logs",
662
1643
  "experiment",
663
1644
  "dataset",
@@ -665,399 +1646,399 @@ var ObjectReferenceNullish = z.union([
665
1646
  "function",
666
1647
  "prompt_session"
667
1648
  ]),
668
- object_id: z.string().uuid(),
669
- id: z.string(),
670
- _xact_id: z.union([z.string(), z.null()]).optional(),
671
- created: z.union([z.string(), z.null()]).optional()
1649
+ object_id: z5.string().uuid(),
1650
+ id: z5.string(),
1651
+ _xact_id: z5.union([z5.string(), z5.null()]).optional(),
1652
+ created: z5.union([z5.string(), z5.null()]).optional()
672
1653
  }),
673
- z.null()
1654
+ z5.null()
674
1655
  ]);
675
- var DatasetEvent = z.object({
676
- id: z.string(),
677
- _xact_id: z.string(),
678
- created: z.string().datetime({ offset: true }),
679
- _pagination_key: z.union([z.string(), z.null()]).optional(),
680
- project_id: z.string().uuid(),
681
- dataset_id: z.string().uuid(),
682
- input: z.unknown().optional(),
683
- expected: z.unknown().optional(),
684
- metadata: z.union([
685
- z.object({ model: z.union([z.string(), z.null()]) }).partial().passthrough(),
686
- z.null()
1656
+ var DatasetEvent = z5.object({
1657
+ id: z5.string(),
1658
+ _xact_id: z5.string(),
1659
+ created: z5.string().datetime({ offset: true }),
1660
+ _pagination_key: z5.union([z5.string(), z5.null()]).optional(),
1661
+ project_id: z5.string().uuid(),
1662
+ dataset_id: z5.string().uuid(),
1663
+ input: z5.unknown().optional(),
1664
+ expected: z5.unknown().optional(),
1665
+ metadata: z5.union([
1666
+ z5.object({ model: z5.union([z5.string(), z5.null()]) }).partial().passthrough(),
1667
+ z5.null()
687
1668
  ]).optional(),
688
- tags: z.union([z.array(z.string()), z.null()]).optional(),
689
- span_id: z.string(),
690
- root_span_id: z.string(),
691
- is_root: z.union([z.boolean(), z.null()]).optional(),
1669
+ tags: z5.union([z5.array(z5.string()), z5.null()]).optional(),
1670
+ span_id: z5.string(),
1671
+ root_span_id: z5.string(),
1672
+ is_root: z5.union([z5.boolean(), z5.null()]).optional(),
692
1673
  origin: ObjectReferenceNullish.optional()
693
1674
  });
694
- var EnvVar = z.object({
695
- id: z.string().uuid(),
696
- object_type: z.enum(["organization", "project", "function"]),
697
- object_id: z.string().uuid(),
698
- name: z.string(),
699
- created: z.union([z.string(), z.null()]).optional(),
700
- used: z.union([z.string(), z.null()]).optional()
1675
+ var EnvVar = z5.object({
1676
+ id: z5.string().uuid(),
1677
+ object_type: z5.enum(["organization", "project", "function"]),
1678
+ object_id: z5.string().uuid(),
1679
+ name: z5.string(),
1680
+ created: z5.union([z5.string(), z5.null()]).optional(),
1681
+ used: z5.union([z5.string(), z5.null()]).optional()
701
1682
  });
702
- var RepoInfo = z.union([
703
- z.object({
704
- commit: z.union([z.string(), z.null()]),
705
- branch: z.union([z.string(), z.null()]),
706
- tag: z.union([z.string(), z.null()]),
707
- dirty: z.union([z.boolean(), z.null()]),
708
- author_name: z.union([z.string(), z.null()]),
709
- author_email: z.union([z.string(), z.null()]),
710
- commit_message: z.union([z.string(), z.null()]),
711
- commit_time: z.union([z.string(), z.null()]),
712
- git_diff: z.union([z.string(), z.null()])
1683
+ var RepoInfo = z5.union([
1684
+ z5.object({
1685
+ commit: z5.union([z5.string(), z5.null()]),
1686
+ branch: z5.union([z5.string(), z5.null()]),
1687
+ tag: z5.union([z5.string(), z5.null()]),
1688
+ dirty: z5.union([z5.boolean(), z5.null()]),
1689
+ author_name: z5.union([z5.string(), z5.null()]),
1690
+ author_email: z5.union([z5.string(), z5.null()]),
1691
+ commit_message: z5.union([z5.string(), z5.null()]),
1692
+ commit_time: z5.union([z5.string(), z5.null()]),
1693
+ git_diff: z5.union([z5.string(), z5.null()])
713
1694
  }).partial(),
714
- z.null()
1695
+ z5.null()
715
1696
  ]);
716
- var Experiment = z.object({
717
- id: z.string().uuid(),
718
- project_id: z.string().uuid(),
719
- name: z.string(),
720
- description: z.union([z.string(), z.null()]).optional(),
721
- created: z.union([z.string(), z.null()]).optional(),
1697
+ var Experiment = z5.object({
1698
+ id: z5.string().uuid(),
1699
+ project_id: z5.string().uuid(),
1700
+ name: z5.string(),
1701
+ description: z5.union([z5.string(), z5.null()]).optional(),
1702
+ created: z5.union([z5.string(), z5.null()]).optional(),
722
1703
  repo_info: RepoInfo.optional(),
723
- commit: z.union([z.string(), z.null()]).optional(),
724
- base_exp_id: z.union([z.string(), z.null()]).optional(),
725
- deleted_at: z.union([z.string(), z.null()]).optional(),
726
- dataset_id: z.union([z.string(), z.null()]).optional(),
727
- dataset_version: z.union([z.string(), z.null()]).optional(),
728
- public: z.boolean(),
729
- user_id: z.union([z.string(), z.null()]).optional(),
730
- metadata: z.union([z.object({}).partial().passthrough(), z.null()]).optional(),
731
- tags: z.union([z.array(z.string()), z.null()]).optional()
1704
+ commit: z5.union([z5.string(), z5.null()]).optional(),
1705
+ base_exp_id: z5.union([z5.string(), z5.null()]).optional(),
1706
+ deleted_at: z5.union([z5.string(), z5.null()]).optional(),
1707
+ dataset_id: z5.union([z5.string(), z5.null()]).optional(),
1708
+ dataset_version: z5.union([z5.string(), z5.null()]).optional(),
1709
+ public: z5.boolean(),
1710
+ user_id: z5.union([z5.string(), z5.null()]).optional(),
1711
+ metadata: z5.union([z5.object({}).partial().passthrough(), z5.null()]).optional(),
1712
+ tags: z5.union([z5.array(z5.string()), z5.null()]).optional()
732
1713
  });
733
- var SpanType = z.union([
734
- z.enum(["llm", "score", "function", "eval", "task", "tool"]),
735
- z.null()
1714
+ var SpanType = z5.union([
1715
+ z5.enum(["llm", "score", "function", "eval", "task", "tool"]),
1716
+ z5.null()
736
1717
  ]);
737
- var SpanAttributes = z.union([
738
- z.object({ name: z.union([z.string(), z.null()]), type: SpanType }).partial().passthrough(),
739
- z.null()
1718
+ var SpanAttributes = z5.union([
1719
+ z5.object({ name: z5.union([z5.string(), z5.null()]), type: SpanType }).partial().passthrough(),
1720
+ z5.null()
740
1721
  ]);
741
- var ExperimentEvent = z.object({
742
- id: z.string(),
743
- _xact_id: z.string(),
744
- created: z.string().datetime({ offset: true }),
745
- _pagination_key: z.union([z.string(), z.null()]).optional(),
746
- project_id: z.string().uuid(),
747
- experiment_id: z.string().uuid(),
748
- input: z.unknown().optional(),
749
- output: z.unknown().optional(),
750
- expected: z.unknown().optional(),
751
- error: z.unknown().optional(),
752
- scores: z.union([z.record(z.union([z.number(), z.null()])), z.null()]).optional(),
753
- metadata: z.union([
754
- z.object({ model: z.union([z.string(), z.null()]) }).partial().passthrough(),
755
- z.null()
1722
+ var ExperimentEvent = z5.object({
1723
+ id: z5.string(),
1724
+ _xact_id: z5.string(),
1725
+ created: z5.string().datetime({ offset: true }),
1726
+ _pagination_key: z5.union([z5.string(), z5.null()]).optional(),
1727
+ project_id: z5.string().uuid(),
1728
+ experiment_id: z5.string().uuid(),
1729
+ input: z5.unknown().optional(),
1730
+ output: z5.unknown().optional(),
1731
+ expected: z5.unknown().optional(),
1732
+ error: z5.unknown().optional(),
1733
+ scores: z5.union([z5.record(z5.union([z5.number(), z5.null()])), z5.null()]).optional(),
1734
+ metadata: z5.union([
1735
+ z5.object({ model: z5.union([z5.string(), z5.null()]) }).partial().passthrough(),
1736
+ z5.null()
756
1737
  ]).optional(),
757
- tags: z.union([z.array(z.string()), z.null()]).optional(),
758
- metrics: z.union([z.record(z.number()), z.null()]).optional(),
759
- context: z.union([
760
- z.object({
761
- caller_functionname: z.union([z.string(), z.null()]),
762
- caller_filename: z.union([z.string(), z.null()]),
763
- caller_lineno: z.union([z.number(), z.null()])
1738
+ tags: z5.union([z5.array(z5.string()), z5.null()]).optional(),
1739
+ metrics: z5.union([z5.record(z5.number()), z5.null()]).optional(),
1740
+ context: z5.union([
1741
+ z5.object({
1742
+ caller_functionname: z5.union([z5.string(), z5.null()]),
1743
+ caller_filename: z5.union([z5.string(), z5.null()]),
1744
+ caller_lineno: z5.union([z5.number(), z5.null()])
764
1745
  }).partial().passthrough(),
765
- z.null()
1746
+ z5.null()
766
1747
  ]).optional(),
767
- span_id: z.string(),
768
- span_parents: z.union([z.array(z.string()), z.null()]).optional(),
769
- root_span_id: z.string(),
1748
+ span_id: z5.string(),
1749
+ span_parents: z5.union([z5.array(z5.string()), z5.null()]).optional(),
1750
+ root_span_id: z5.string(),
770
1751
  span_attributes: SpanAttributes.optional(),
771
- is_root: z.union([z.boolean(), z.null()]).optional(),
1752
+ is_root: z5.union([z5.boolean(), z5.null()]).optional(),
772
1753
  origin: ObjectReferenceNullish.optional()
773
1754
  });
774
- var ExtendedSavedFunctionId = z.union([
775
- z.object({ type: z.literal("function"), id: z.string() }),
776
- z.object({ type: z.literal("global"), name: z.string() }),
777
- z.object({
778
- type: z.literal("slug"),
779
- project_id: z.string(),
780
- slug: z.string()
1755
+ var ExtendedSavedFunctionId = z5.union([
1756
+ z5.object({ type: z5.literal("function"), id: z5.string() }),
1757
+ z5.object({ type: z5.literal("global"), name: z5.string() }),
1758
+ z5.object({
1759
+ type: z5.literal("slug"),
1760
+ project_id: z5.string(),
1761
+ slug: z5.string()
781
1762
  })
782
1763
  ]);
783
- var PromptBlockDataNullish = z.union([
784
- z.object({ type: z.literal("completion"), content: z.string() }),
785
- z.object({
786
- type: z.literal("chat"),
787
- messages: z.array(ChatCompletionMessageParam),
788
- tools: z.string().optional()
1764
+ var PromptBlockDataNullish = z5.union([
1765
+ z5.object({ type: z5.literal("completion"), content: z5.string() }),
1766
+ z5.object({
1767
+ type: z5.literal("chat"),
1768
+ messages: z5.array(ChatCompletionMessageParam),
1769
+ tools: z5.string().optional()
789
1770
  }),
790
- z.null()
1771
+ z5.null()
791
1772
  ]);
792
- var ModelParams = z.union([
793
- z.object({
794
- use_cache: z.boolean(),
795
- temperature: z.number(),
796
- top_p: z.number(),
797
- max_tokens: z.number(),
798
- max_completion_tokens: z.number(),
799
- frequency_penalty: z.number(),
800
- presence_penalty: z.number(),
1773
+ var ModelParams = z5.union([
1774
+ z5.object({
1775
+ use_cache: z5.boolean(),
1776
+ temperature: z5.number(),
1777
+ top_p: z5.number(),
1778
+ max_tokens: z5.number(),
1779
+ max_completion_tokens: z5.number(),
1780
+ frequency_penalty: z5.number(),
1781
+ presence_penalty: z5.number(),
801
1782
  response_format: ResponseFormatNullish,
802
- tool_choice: z.union([
803
- z.literal("auto"),
804
- z.literal("none"),
805
- z.literal("required"),
806
- z.object({
807
- type: z.literal("function"),
808
- function: z.object({ name: z.string() })
1783
+ tool_choice: z5.union([
1784
+ z5.literal("auto"),
1785
+ z5.literal("none"),
1786
+ z5.literal("required"),
1787
+ z5.object({
1788
+ type: z5.literal("function"),
1789
+ function: z5.object({ name: z5.string() })
809
1790
  })
810
1791
  ]),
811
- function_call: z.union([
812
- z.literal("auto"),
813
- z.literal("none"),
814
- z.object({ name: z.string() })
1792
+ function_call: z5.union([
1793
+ z5.literal("auto"),
1794
+ z5.literal("none"),
1795
+ z5.object({ name: z5.string() })
815
1796
  ]),
816
- n: z.number(),
817
- stop: z.array(z.string()),
818
- reasoning_effort: z.enum(["minimal", "low", "medium", "high"]),
819
- verbosity: z.enum(["low", "medium", "high"])
1797
+ n: z5.number(),
1798
+ stop: z5.array(z5.string()),
1799
+ reasoning_effort: z5.enum(["minimal", "low", "medium", "high"]),
1800
+ verbosity: z5.enum(["low", "medium", "high"])
820
1801
  }).partial().passthrough(),
821
- z.object({
822
- use_cache: z.boolean().optional(),
823
- max_tokens: z.number(),
824
- temperature: z.number(),
825
- top_p: z.number().optional(),
826
- top_k: z.number().optional(),
827
- stop_sequences: z.array(z.string()).optional(),
828
- max_tokens_to_sample: z.number().optional()
1802
+ z5.object({
1803
+ use_cache: z5.boolean().optional(),
1804
+ max_tokens: z5.number(),
1805
+ temperature: z5.number(),
1806
+ top_p: z5.number().optional(),
1807
+ top_k: z5.number().optional(),
1808
+ stop_sequences: z5.array(z5.string()).optional(),
1809
+ max_tokens_to_sample: z5.number().optional()
829
1810
  }).passthrough(),
830
- z.object({
831
- use_cache: z.boolean(),
832
- temperature: z.number(),
833
- maxOutputTokens: z.number(),
834
- topP: z.number(),
835
- topK: z.number()
1811
+ z5.object({
1812
+ use_cache: z5.boolean(),
1813
+ temperature: z5.number(),
1814
+ maxOutputTokens: z5.number(),
1815
+ topP: z5.number(),
1816
+ topK: z5.number()
836
1817
  }).partial().passthrough(),
837
- z.object({
838
- use_cache: z.boolean(),
839
- temperature: z.number(),
840
- topK: z.number()
1818
+ z5.object({
1819
+ use_cache: z5.boolean(),
1820
+ temperature: z5.number(),
1821
+ topK: z5.number()
841
1822
  }).partial().passthrough(),
842
- z.object({ use_cache: z.boolean() }).partial().passthrough()
1823
+ z5.object({ use_cache: z5.boolean() }).partial().passthrough()
843
1824
  ]);
844
- var PromptOptionsNullish = z.union([
845
- z.object({ model: z.string(), params: ModelParams, position: z.string() }).partial(),
846
- z.null()
1825
+ var PromptOptionsNullish = z5.union([
1826
+ z5.object({ model: z5.string(), params: ModelParams, position: z5.string() }).partial(),
1827
+ z5.null()
847
1828
  ]);
848
- var PromptParserNullish = z.union([
849
- z.object({
850
- type: z.literal("llm_classifier"),
851
- use_cot: z.boolean(),
852
- choice_scores: z.record(z.number().gte(0).lte(1))
1829
+ var PromptParserNullish = z5.union([
1830
+ z5.object({
1831
+ type: z5.literal("llm_classifier"),
1832
+ use_cot: z5.boolean(),
1833
+ choice_scores: z5.record(z5.number().gte(0).lte(1))
853
1834
  }),
854
- z.null()
1835
+ z5.null()
855
1836
  ]);
856
- var SavedFunctionId = z.union([
857
- z.object({ type: z.literal("function"), id: z.string() }),
858
- z.object({ type: z.literal("global"), name: z.string() })
1837
+ var SavedFunctionId = z5.union([
1838
+ z5.object({ type: z5.literal("function"), id: z5.string() }),
1839
+ z5.object({ type: z5.literal("global"), name: z5.string() })
859
1840
  ]);
860
- var PromptDataNullish = z.union([
861
- z.object({
1841
+ var PromptDataNullish = z5.union([
1842
+ z5.object({
862
1843
  prompt: PromptBlockDataNullish,
863
1844
  options: PromptOptionsNullish,
864
1845
  parser: PromptParserNullish,
865
- tool_functions: z.union([z.array(SavedFunctionId), z.null()]),
866
- origin: z.union([
867
- z.object({
868
- prompt_id: z.string(),
869
- project_id: z.string(),
870
- prompt_version: z.string()
1846
+ tool_functions: z5.union([z5.array(SavedFunctionId), z5.null()]),
1847
+ origin: z5.union([
1848
+ z5.object({
1849
+ prompt_id: z5.string(),
1850
+ project_id: z5.string(),
1851
+ prompt_version: z5.string()
871
1852
  }).partial(),
872
- z.null()
1853
+ z5.null()
873
1854
  ])
874
1855
  }).partial(),
875
- z.null()
1856
+ z5.null()
876
1857
  ]);
877
- var FunctionTypeEnumNullish = z.union([
878
- z.enum(["llm", "scorer", "task", "tool"]),
879
- z.null()
1858
+ var FunctionTypeEnumNullish = z5.union([
1859
+ z5.enum(["llm", "scorer", "task", "tool"]),
1860
+ z5.null()
880
1861
  ]);
881
- var FunctionIdRef = z.object({}).partial().passthrough();
882
- var PromptBlockData = z.union([
883
- z.object({ type: z.literal("completion"), content: z.string() }),
884
- z.object({
885
- type: z.literal("chat"),
886
- messages: z.array(ChatCompletionMessageParam),
887
- tools: z.string().optional()
1862
+ var FunctionIdRef = z5.object({}).partial().passthrough();
1863
+ var PromptBlockData = z5.union([
1864
+ z5.object({ type: z5.literal("completion"), content: z5.string() }),
1865
+ z5.object({
1866
+ type: z5.literal("chat"),
1867
+ messages: z5.array(ChatCompletionMessageParam),
1868
+ tools: z5.string().optional()
888
1869
  })
889
1870
  ]);
890
- var GraphNode = z.union([
891
- z.object({
892
- description: z.union([z.string(), z.null()]).optional(),
893
- position: z.union([z.object({ x: z.number(), y: z.number() }), z.null()]).optional(),
894
- type: z.literal("function"),
1871
+ var GraphNode = z5.union([
1872
+ z5.object({
1873
+ description: z5.union([z5.string(), z5.null()]).optional(),
1874
+ position: z5.union([z5.object({ x: z5.number(), y: z5.number() }), z5.null()]).optional(),
1875
+ type: z5.literal("function"),
895
1876
  function: FunctionIdRef
896
1877
  }),
897
- z.object({
898
- description: z.union([z.string(), z.null()]).optional(),
899
- position: z.union([z.object({ x: z.number(), y: z.number() }), z.null()]).optional(),
900
- type: z.literal("input")
1878
+ z5.object({
1879
+ description: z5.union([z5.string(), z5.null()]).optional(),
1880
+ position: z5.union([z5.object({ x: z5.number(), y: z5.number() }), z5.null()]).optional(),
1881
+ type: z5.literal("input")
901
1882
  }),
902
- z.object({
903
- description: z.union([z.string(), z.null()]).optional(),
904
- position: z.union([z.object({ x: z.number(), y: z.number() }), z.null()]).optional(),
905
- type: z.literal("output")
1883
+ z5.object({
1884
+ description: z5.union([z5.string(), z5.null()]).optional(),
1885
+ position: z5.union([z5.object({ x: z5.number(), y: z5.number() }), z5.null()]).optional(),
1886
+ type: z5.literal("output")
906
1887
  }),
907
- z.object({
908
- description: z.union([z.string(), z.null()]).optional(),
909
- position: z.union([z.object({ x: z.number(), y: z.number() }), z.null()]).optional(),
910
- type: z.literal("literal"),
911
- value: z.unknown().optional()
1888
+ z5.object({
1889
+ description: z5.union([z5.string(), z5.null()]).optional(),
1890
+ position: z5.union([z5.object({ x: z5.number(), y: z5.number() }), z5.null()]).optional(),
1891
+ type: z5.literal("literal"),
1892
+ value: z5.unknown().optional()
912
1893
  }),
913
- z.object({
914
- description: z.union([z.string(), z.null()]).optional(),
915
- position: z.union([z.object({ x: z.number(), y: z.number() }), z.null()]).optional(),
916
- type: z.literal("btql"),
917
- expr: z.string()
1894
+ z5.object({
1895
+ description: z5.union([z5.string(), z5.null()]).optional(),
1896
+ position: z5.union([z5.object({ x: z5.number(), y: z5.number() }), z5.null()]).optional(),
1897
+ type: z5.literal("btql"),
1898
+ expr: z5.string()
918
1899
  }),
919
- z.object({
920
- description: z.union([z.string(), z.null()]).optional(),
921
- position: z.union([z.object({ x: z.number(), y: z.number() }), z.null()]).optional(),
922
- type: z.literal("gate"),
923
- condition: z.union([z.string(), z.null()]).optional()
1900
+ z5.object({
1901
+ description: z5.union([z5.string(), z5.null()]).optional(),
1902
+ position: z5.union([z5.object({ x: z5.number(), y: z5.number() }), z5.null()]).optional(),
1903
+ type: z5.literal("gate"),
1904
+ condition: z5.union([z5.string(), z5.null()]).optional()
924
1905
  }),
925
- z.object({
926
- description: z.union([z.string(), z.null()]).optional(),
927
- position: z.union([z.object({ x: z.number(), y: z.number() }), z.null()]).optional(),
928
- type: z.literal("aggregator")
1906
+ z5.object({
1907
+ description: z5.union([z5.string(), z5.null()]).optional(),
1908
+ position: z5.union([z5.object({ x: z5.number(), y: z5.number() }), z5.null()]).optional(),
1909
+ type: z5.literal("aggregator")
929
1910
  }),
930
- z.object({
931
- description: z.union([z.string(), z.null()]).optional(),
932
- position: z.union([z.object({ x: z.number(), y: z.number() }), z.null()]).optional(),
933
- type: z.literal("prompt_template"),
1911
+ z5.object({
1912
+ description: z5.union([z5.string(), z5.null()]).optional(),
1913
+ position: z5.union([z5.object({ x: z5.number(), y: z5.number() }), z5.null()]).optional(),
1914
+ type: z5.literal("prompt_template"),
934
1915
  prompt: PromptBlockData
935
1916
  })
936
1917
  ]);
937
- var GraphEdge = z.object({
938
- source: z.object({ node: z.string().max(1024), variable: z.string() }),
939
- target: z.object({ node: z.string().max(1024), variable: z.string() }),
940
- purpose: z.enum(["control", "data", "messages"])
1918
+ var GraphEdge = z5.object({
1919
+ source: z5.object({ node: z5.string().max(1024), variable: z5.string() }),
1920
+ target: z5.object({ node: z5.string().max(1024), variable: z5.string() }),
1921
+ purpose: z5.enum(["control", "data", "messages"])
941
1922
  });
942
- var GraphData = z.object({
943
- type: z.literal("graph"),
944
- nodes: z.record(GraphNode),
945
- edges: z.record(GraphEdge)
1923
+ var GraphData = z5.object({
1924
+ type: z5.literal("graph"),
1925
+ nodes: z5.record(GraphNode),
1926
+ edges: z5.record(GraphEdge)
946
1927
  });
947
- var FunctionData = z.union([
948
- z.object({ type: z.literal("prompt") }),
949
- z.object({
950
- type: z.literal("code"),
951
- data: z.union([
952
- z.object({ type: z.literal("bundle") }).and(CodeBundle),
953
- z.object({
954
- type: z.literal("inline"),
955
- runtime_context: z.object({
956
- runtime: z.enum(["node", "python"]),
957
- version: z.string()
1928
+ var FunctionData = z5.union([
1929
+ z5.object({ type: z5.literal("prompt") }),
1930
+ z5.object({
1931
+ type: z5.literal("code"),
1932
+ data: z5.union([
1933
+ z5.object({ type: z5.literal("bundle") }).and(CodeBundle),
1934
+ z5.object({
1935
+ type: z5.literal("inline"),
1936
+ runtime_context: z5.object({
1937
+ runtime: z5.enum(["node", "python"]),
1938
+ version: z5.string()
958
1939
  }),
959
- code: z.string()
1940
+ code: z5.string()
960
1941
  })
961
1942
  ])
962
1943
  }),
963
1944
  GraphData,
964
- z.object({
965
- type: z.literal("remote_eval"),
966
- endpoint: z.string(),
967
- eval_name: z.string(),
968
- parameters: z.object({}).partial().passthrough()
1945
+ z5.object({
1946
+ type: z5.literal("remote_eval"),
1947
+ endpoint: z5.string(),
1948
+ eval_name: z5.string(),
1949
+ parameters: z5.object({}).partial().passthrough()
969
1950
  }),
970
- z.object({ type: z.literal("global"), name: z.string() })
1951
+ z5.object({ type: z5.literal("global"), name: z5.string() })
971
1952
  ]);
972
- var Function = z.object({
973
- id: z.string().uuid(),
974
- _xact_id: z.string(),
975
- project_id: z.string().uuid(),
976
- log_id: z.literal("p"),
977
- org_id: z.string().uuid(),
978
- name: z.string(),
979
- slug: z.string(),
980
- description: z.union([z.string(), z.null()]).optional(),
981
- created: z.union([z.string(), z.null()]).optional(),
1953
+ var Function = z5.object({
1954
+ id: z5.string().uuid(),
1955
+ _xact_id: z5.string(),
1956
+ project_id: z5.string().uuid(),
1957
+ log_id: z5.literal("p"),
1958
+ org_id: z5.string().uuid(),
1959
+ name: z5.string(),
1960
+ slug: z5.string(),
1961
+ description: z5.union([z5.string(), z5.null()]).optional(),
1962
+ created: z5.union([z5.string(), z5.null()]).optional(),
982
1963
  prompt_data: PromptDataNullish.optional(),
983
- tags: z.union([z.array(z.string()), z.null()]).optional(),
984
- metadata: z.union([z.object({}).partial().passthrough(), z.null()]).optional(),
1964
+ tags: z5.union([z5.array(z5.string()), z5.null()]).optional(),
1965
+ metadata: z5.union([z5.object({}).partial().passthrough(), z5.null()]).optional(),
985
1966
  function_type: FunctionTypeEnumNullish.optional(),
986
1967
  function_data: FunctionData,
987
- origin: z.union([
988
- z.object({
989
- object_type: AclObjectType.and(z.string()),
990
- object_id: z.string().uuid(),
991
- internal: z.union([z.boolean(), z.null()]).optional()
1968
+ origin: z5.union([
1969
+ z5.object({
1970
+ object_type: AclObjectType.and(z5.string()),
1971
+ object_id: z5.string().uuid(),
1972
+ internal: z5.union([z5.boolean(), z5.null()]).optional()
992
1973
  }),
993
- z.null()
1974
+ z5.null()
994
1975
  ]).optional(),
995
- function_schema: z.union([
996
- z.object({ parameters: z.unknown(), returns: z.unknown() }).partial(),
997
- z.null()
1976
+ function_schema: z5.union([
1977
+ z5.object({ parameters: z5.unknown(), returns: z5.unknown() }).partial(),
1978
+ z5.null()
998
1979
  ]).optional()
999
1980
  });
1000
- var FunctionFormat = z.enum(["llm", "code", "global", "graph"]);
1001
- var PromptData = z.object({
1981
+ var FunctionFormat = z5.enum(["llm", "code", "global", "graph"]);
1982
+ var PromptData = z5.object({
1002
1983
  prompt: PromptBlockDataNullish,
1003
1984
  options: PromptOptionsNullish,
1004
1985
  parser: PromptParserNullish,
1005
- tool_functions: z.union([z.array(SavedFunctionId), z.null()]),
1006
- origin: z.union([
1007
- z.object({
1008
- prompt_id: z.string(),
1009
- project_id: z.string(),
1010
- prompt_version: z.string()
1986
+ tool_functions: z5.union([z5.array(SavedFunctionId), z5.null()]),
1987
+ origin: z5.union([
1988
+ z5.object({
1989
+ prompt_id: z5.string(),
1990
+ project_id: z5.string(),
1991
+ prompt_version: z5.string()
1011
1992
  }).partial(),
1012
- z.null()
1993
+ z5.null()
1013
1994
  ])
1014
1995
  }).partial();
1015
- var FunctionTypeEnum = z.enum(["llm", "scorer", "task", "tool"]);
1016
- var FunctionId = z.union([
1017
- z.object({ function_id: z.string(), version: z.string().optional() }),
1018
- z.object({
1019
- project_name: z.string(),
1020
- slug: z.string(),
1021
- version: z.string().optional()
1996
+ var FunctionTypeEnum = z5.enum(["llm", "scorer", "task", "tool"]);
1997
+ var FunctionId = z5.union([
1998
+ z5.object({ function_id: z5.string(), version: z5.string().optional() }),
1999
+ z5.object({
2000
+ project_name: z5.string(),
2001
+ slug: z5.string(),
2002
+ version: z5.string().optional()
1022
2003
  }),
1023
- z.object({ global_function: z.string() }),
1024
- z.object({
1025
- prompt_session_id: z.string(),
1026
- prompt_session_function_id: z.string(),
1027
- version: z.string().optional()
2004
+ z5.object({ global_function: z5.string() }),
2005
+ z5.object({
2006
+ prompt_session_id: z5.string(),
2007
+ prompt_session_function_id: z5.string(),
2008
+ version: z5.string().optional()
1028
2009
  }),
1029
- z.object({
1030
- inline_context: z.object({
1031
- runtime: z.enum(["node", "python"]),
1032
- version: z.string()
2010
+ z5.object({
2011
+ inline_context: z5.object({
2012
+ runtime: z5.enum(["node", "python"]),
2013
+ version: z5.string()
1033
2014
  }),
1034
- code: z.string(),
1035
- name: z.union([z.string(), z.null()]).optional()
2015
+ code: z5.string(),
2016
+ name: z5.union([z5.string(), z5.null()]).optional()
1036
2017
  }),
1037
- z.object({
2018
+ z5.object({
1038
2019
  inline_prompt: PromptData.optional(),
1039
- inline_function: z.object({}).partial().passthrough(),
2020
+ inline_function: z5.object({}).partial().passthrough(),
1040
2021
  function_type: FunctionTypeEnum.optional(),
1041
- name: z.union([z.string(), z.null()]).optional()
2022
+ name: z5.union([z5.string(), z5.null()]).optional()
1042
2023
  }),
1043
- z.object({
2024
+ z5.object({
1044
2025
  inline_prompt: PromptData,
1045
2026
  function_type: FunctionTypeEnum.optional(),
1046
- name: z.union([z.string(), z.null()]).optional()
2027
+ name: z5.union([z5.string(), z5.null()]).optional()
1047
2028
  })
1048
2029
  ]);
1049
- var FunctionObjectType = z.enum([
2030
+ var FunctionObjectType = z5.enum([
1050
2031
  "prompt",
1051
2032
  "tool",
1052
2033
  "scorer",
1053
2034
  "task",
1054
2035
  "agent"
1055
2036
  ]);
1056
- var FunctionOutputType = z.enum(["completion", "score", "any"]);
1057
- var GitMetadataSettings = z.object({
1058
- collect: z.enum(["all", "none", "some"]),
1059
- fields: z.array(
1060
- z.enum([
2037
+ var FunctionOutputType = z5.enum(["completion", "score", "any"]);
2038
+ var GitMetadataSettings = z5.object({
2039
+ collect: z5.enum(["all", "none", "some"]),
2040
+ fields: z5.array(
2041
+ z5.enum([
1061
2042
  "commit",
1062
2043
  "branch",
1063
2044
  "tag",
@@ -1070,49 +2051,49 @@ var GitMetadataSettings = z.object({
1070
2051
  ])
1071
2052
  ).optional()
1072
2053
  });
1073
- var Group = z.object({
1074
- id: z.string().uuid(),
1075
- org_id: z.string().uuid(),
1076
- user_id: z.union([z.string(), z.null()]).optional(),
1077
- created: z.union([z.string(), z.null()]).optional(),
1078
- name: z.string(),
1079
- description: z.union([z.string(), z.null()]).optional(),
1080
- deleted_at: z.union([z.string(), z.null()]).optional(),
1081
- member_users: z.union([z.array(z.string().uuid()), z.null()]).optional(),
1082
- member_groups: z.union([z.array(z.string().uuid()), z.null()]).optional()
2054
+ var Group = z5.object({
2055
+ id: z5.string().uuid(),
2056
+ org_id: z5.string().uuid(),
2057
+ user_id: z5.union([z5.string(), z5.null()]).optional(),
2058
+ created: z5.union([z5.string(), z5.null()]).optional(),
2059
+ name: z5.string(),
2060
+ description: z5.union([z5.string(), z5.null()]).optional(),
2061
+ deleted_at: z5.union([z5.string(), z5.null()]).optional(),
2062
+ member_users: z5.union([z5.array(z5.string().uuid()), z5.null()]).optional(),
2063
+ member_groups: z5.union([z5.array(z5.string().uuid()), z5.null()]).optional()
1083
2064
  });
1084
- var IfExists = z.enum(["error", "ignore", "replace"]);
1085
- var InvokeParent = z.union([
1086
- z.object({
1087
- object_type: z.enum(["project_logs", "experiment", "playground_logs"]),
1088
- object_id: z.string(),
1089
- row_ids: z.union([
1090
- z.object({
1091
- id: z.string(),
1092
- span_id: z.string(),
1093
- root_span_id: z.string()
2065
+ var IfExists = z5.enum(["error", "ignore", "replace"]);
2066
+ var InvokeParent = z5.union([
2067
+ z5.object({
2068
+ object_type: z5.enum(["project_logs", "experiment", "playground_logs"]),
2069
+ object_id: z5.string(),
2070
+ row_ids: z5.union([
2071
+ z5.object({
2072
+ id: z5.string(),
2073
+ span_id: z5.string(),
2074
+ root_span_id: z5.string()
1094
2075
  }),
1095
- z.null()
2076
+ z5.null()
1096
2077
  ]).optional(),
1097
- propagated_event: z.union([z.object({}).partial().passthrough(), z.null()]).optional()
2078
+ propagated_event: z5.union([z5.object({}).partial().passthrough(), z5.null()]).optional()
1098
2079
  }),
1099
- z.string()
2080
+ z5.string()
1100
2081
  ]);
1101
- var StreamingMode = z.union([z.enum(["auto", "parallel"]), z.null()]);
2082
+ var StreamingMode = z5.union([z5.enum(["auto", "parallel"]), z5.null()]);
1102
2083
  var InvokeFunction = FunctionId.and(
1103
- z.object({
1104
- input: z.unknown(),
1105
- expected: z.unknown(),
1106
- metadata: z.union([z.object({}).partial().passthrough(), z.null()]),
1107
- tags: z.union([z.array(z.string()), z.null()]),
1108
- messages: z.array(ChatCompletionMessageParam),
2084
+ z5.object({
2085
+ input: z5.unknown(),
2086
+ expected: z5.unknown(),
2087
+ metadata: z5.union([z5.object({}).partial().passthrough(), z5.null()]),
2088
+ tags: z5.union([z5.array(z5.string()), z5.null()]),
2089
+ messages: z5.array(ChatCompletionMessageParam),
1109
2090
  parent: InvokeParent,
1110
- stream: z.union([z.boolean(), z.null()]),
2091
+ stream: z5.union([z5.boolean(), z5.null()]),
1111
2092
  mode: StreamingMode,
1112
- strict: z.union([z.boolean(), z.null()])
2093
+ strict: z5.union([z5.boolean(), z5.null()])
1113
2094
  }).partial()
1114
2095
  );
1115
- var MessageRole = z.enum([
2096
+ var MessageRole = z5.enum([
1116
2097
  "system",
1117
2098
  "user",
1118
2099
  "assistant",
@@ -1121,8 +2102,8 @@ var MessageRole = z.enum([
1121
2102
  "model",
1122
2103
  "developer"
1123
2104
  ]);
1124
- var ObjectReference = z.object({
1125
- object_type: z.enum([
2105
+ var ObjectReference = z5.object({
2106
+ object_type: z5.enum([
1126
2107
  "project_logs",
1127
2108
  "experiment",
1128
2109
  "dataset",
@@ -1130,146 +2111,146 @@ var ObjectReference = z.object({
1130
2111
  "function",
1131
2112
  "prompt_session"
1132
2113
  ]),
1133
- object_id: z.string().uuid(),
1134
- id: z.string(),
1135
- _xact_id: z.union([z.string(), z.null()]).optional(),
1136
- created: z.union([z.string(), z.null()]).optional()
2114
+ object_id: z5.string().uuid(),
2115
+ id: z5.string(),
2116
+ _xact_id: z5.union([z5.string(), z5.null()]).optional(),
2117
+ created: z5.union([z5.string(), z5.null()]).optional()
1137
2118
  });
1138
- var OnlineScoreConfig = z.union([
1139
- z.object({
1140
- sampling_rate: z.number().gte(0).lte(1),
1141
- scorers: z.array(SavedFunctionId),
1142
- btql_filter: z.union([z.string(), z.null()]).optional(),
1143
- apply_to_root_span: z.union([z.boolean(), z.null()]).optional(),
1144
- apply_to_span_names: z.union([z.array(z.string()), z.null()]).optional(),
1145
- skip_logging: z.union([z.boolean(), z.null()]).optional()
2119
+ var OnlineScoreConfig = z5.union([
2120
+ z5.object({
2121
+ sampling_rate: z5.number().gte(0).lte(1),
2122
+ scorers: z5.array(SavedFunctionId),
2123
+ btql_filter: z5.union([z5.string(), z5.null()]).optional(),
2124
+ apply_to_root_span: z5.union([z5.boolean(), z5.null()]).optional(),
2125
+ apply_to_span_names: z5.union([z5.array(z5.string()), z5.null()]).optional(),
2126
+ skip_logging: z5.union([z5.boolean(), z5.null()]).optional()
1146
2127
  }),
1147
- z.null()
2128
+ z5.null()
1148
2129
  ]);
1149
- var Organization = z.object({
1150
- id: z.string().uuid(),
1151
- name: z.string(),
1152
- api_url: z.union([z.string(), z.null()]).optional(),
1153
- is_universal_api: z.union([z.boolean(), z.null()]).optional(),
1154
- proxy_url: z.union([z.string(), z.null()]).optional(),
1155
- realtime_url: z.union([z.string(), z.null()]).optional(),
1156
- created: z.union([z.string(), z.null()]).optional()
2130
+ var Organization = z5.object({
2131
+ id: z5.string().uuid(),
2132
+ name: z5.string(),
2133
+ api_url: z5.union([z5.string(), z5.null()]).optional(),
2134
+ is_universal_api: z5.union([z5.boolean(), z5.null()]).optional(),
2135
+ proxy_url: z5.union([z5.string(), z5.null()]).optional(),
2136
+ realtime_url: z5.union([z5.string(), z5.null()]).optional(),
2137
+ created: z5.union([z5.string(), z5.null()]).optional()
1157
2138
  });
1158
- var ProjectSettings = z.union([
1159
- z.object({
1160
- comparison_key: z.union([z.string(), z.null()]),
1161
- baseline_experiment_id: z.union([z.string(), z.null()]),
1162
- spanFieldOrder: z.union([
1163
- z.array(
1164
- z.object({
1165
- object_type: z.string(),
1166
- column_id: z.string(),
1167
- position: z.string(),
1168
- layout: z.union([z.literal("full"), z.literal("two_column"), z.null()]).optional()
2139
+ var ProjectSettings = z5.union([
2140
+ z5.object({
2141
+ comparison_key: z5.union([z5.string(), z5.null()]),
2142
+ baseline_experiment_id: z5.union([z5.string(), z5.null()]),
2143
+ spanFieldOrder: z5.union([
2144
+ z5.array(
2145
+ z5.object({
2146
+ object_type: z5.string(),
2147
+ column_id: z5.string(),
2148
+ position: z5.string(),
2149
+ layout: z5.union([z5.literal("full"), z5.literal("two_column"), z5.null()]).optional()
1169
2150
  })
1170
2151
  ),
1171
- z.null()
2152
+ z5.null()
1172
2153
  ]),
1173
- remote_eval_sources: z.union([
1174
- z.array(
1175
- z.object({
1176
- url: z.string(),
1177
- name: z.string(),
1178
- description: z.union([z.string(), z.null()]).optional()
2154
+ remote_eval_sources: z5.union([
2155
+ z5.array(
2156
+ z5.object({
2157
+ url: z5.string(),
2158
+ name: z5.string(),
2159
+ description: z5.union([z5.string(), z5.null()]).optional()
1179
2160
  })
1180
2161
  ),
1181
- z.null()
2162
+ z5.null()
1182
2163
  ])
1183
2164
  }).partial(),
1184
- z.null()
2165
+ z5.null()
1185
2166
  ]);
1186
- var Project = z.object({
1187
- id: z.string().uuid(),
1188
- org_id: z.string().uuid(),
1189
- name: z.string(),
1190
- created: z.union([z.string(), z.null()]).optional(),
1191
- deleted_at: z.union([z.string(), z.null()]).optional(),
1192
- user_id: z.union([z.string(), z.null()]).optional(),
2167
+ var Project = z5.object({
2168
+ id: z5.string().uuid(),
2169
+ org_id: z5.string().uuid(),
2170
+ name: z5.string(),
2171
+ created: z5.union([z5.string(), z5.null()]).optional(),
2172
+ deleted_at: z5.union([z5.string(), z5.null()]).optional(),
2173
+ user_id: z5.union([z5.string(), z5.null()]).optional(),
1193
2174
  settings: ProjectSettings.optional()
1194
2175
  });
1195
- var RetentionObjectType = z.enum([
2176
+ var RetentionObjectType = z5.enum([
1196
2177
  "project_logs",
1197
2178
  "experiment",
1198
2179
  "dataset"
1199
2180
  ]);
1200
- var ProjectAutomation = z.object({
1201
- id: z.string().uuid(),
1202
- project_id: z.string().uuid(),
1203
- user_id: z.union([z.string(), z.null()]).optional(),
1204
- created: z.union([z.string(), z.null()]).optional(),
1205
- name: z.string(),
1206
- description: z.union([z.string(), z.null()]).optional(),
1207
- config: z.union([
1208
- z.object({
1209
- event_type: z.literal("logs"),
1210
- btql_filter: z.string(),
1211
- interval_seconds: z.number().gte(1).lte(2592e3),
1212
- action: z.object({ type: z.literal("webhook"), url: z.string() })
2181
+ var ProjectAutomation = z5.object({
2182
+ id: z5.string().uuid(),
2183
+ project_id: z5.string().uuid(),
2184
+ user_id: z5.union([z5.string(), z5.null()]).optional(),
2185
+ created: z5.union([z5.string(), z5.null()]).optional(),
2186
+ name: z5.string(),
2187
+ description: z5.union([z5.string(), z5.null()]).optional(),
2188
+ config: z5.union([
2189
+ z5.object({
2190
+ event_type: z5.literal("logs"),
2191
+ btql_filter: z5.string(),
2192
+ interval_seconds: z5.number().gte(1).lte(2592e3),
2193
+ action: z5.object({ type: z5.literal("webhook"), url: z5.string() })
1213
2194
  }),
1214
- z.object({
1215
- event_type: z.literal("btql_export"),
1216
- export_definition: z.union([
1217
- z.object({ type: z.literal("log_traces") }),
1218
- z.object({ type: z.literal("log_spans") }),
1219
- z.object({ type: z.literal("btql_query"), btql_query: z.string() })
2195
+ z5.object({
2196
+ event_type: z5.literal("btql_export"),
2197
+ export_definition: z5.union([
2198
+ z5.object({ type: z5.literal("log_traces") }),
2199
+ z5.object({ type: z5.literal("log_spans") }),
2200
+ z5.object({ type: z5.literal("btql_query"), btql_query: z5.string() })
1220
2201
  ]),
1221
- export_path: z.string(),
1222
- format: z.enum(["jsonl", "parquet"]),
1223
- interval_seconds: z.number().gte(1).lte(2592e3),
1224
- credentials: z.object({
1225
- type: z.literal("aws_iam"),
1226
- role_arn: z.string(),
1227
- external_id: z.string()
2202
+ export_path: z5.string(),
2203
+ format: z5.enum(["jsonl", "parquet"]),
2204
+ interval_seconds: z5.number().gte(1).lte(2592e3),
2205
+ credentials: z5.object({
2206
+ type: z5.literal("aws_iam"),
2207
+ role_arn: z5.string(),
2208
+ external_id: z5.string()
1228
2209
  }),
1229
- batch_size: z.union([z.number(), z.null()]).optional()
2210
+ batch_size: z5.union([z5.number(), z5.null()]).optional()
1230
2211
  }),
1231
- z.object({
1232
- event_type: z.literal("retention"),
2212
+ z5.object({
2213
+ event_type: z5.literal("retention"),
1233
2214
  object_type: RetentionObjectType,
1234
- retention_days: z.number().gte(0)
2215
+ retention_days: z5.number().gte(0)
1235
2216
  })
1236
2217
  ])
1237
2218
  });
1238
- var ProjectLogsEvent = z.object({
1239
- id: z.string(),
1240
- _xact_id: z.string(),
1241
- _pagination_key: z.union([z.string(), z.null()]).optional(),
1242
- created: z.string().datetime({ offset: true }),
1243
- org_id: z.string().uuid(),
1244
- project_id: z.string().uuid(),
1245
- log_id: z.literal("g"),
1246
- input: z.unknown().optional(),
1247
- output: z.unknown().optional(),
1248
- expected: z.unknown().optional(),
1249
- error: z.unknown().optional(),
1250
- scores: z.union([z.record(z.union([z.number(), z.null()])), z.null()]).optional(),
1251
- metadata: z.union([
1252
- z.object({ model: z.union([z.string(), z.null()]) }).partial().passthrough(),
1253
- z.null()
2219
+ var ProjectLogsEvent = z5.object({
2220
+ id: z5.string(),
2221
+ _xact_id: z5.string(),
2222
+ _pagination_key: z5.union([z5.string(), z5.null()]).optional(),
2223
+ created: z5.string().datetime({ offset: true }),
2224
+ org_id: z5.string().uuid(),
2225
+ project_id: z5.string().uuid(),
2226
+ log_id: z5.literal("g"),
2227
+ input: z5.unknown().optional(),
2228
+ output: z5.unknown().optional(),
2229
+ expected: z5.unknown().optional(),
2230
+ error: z5.unknown().optional(),
2231
+ scores: z5.union([z5.record(z5.union([z5.number(), z5.null()])), z5.null()]).optional(),
2232
+ metadata: z5.union([
2233
+ z5.object({ model: z5.union([z5.string(), z5.null()]) }).partial().passthrough(),
2234
+ z5.null()
1254
2235
  ]).optional(),
1255
- tags: z.union([z.array(z.string()), z.null()]).optional(),
1256
- metrics: z.union([z.record(z.number()), z.null()]).optional(),
1257
- context: z.union([
1258
- z.object({
1259
- caller_functionname: z.union([z.string(), z.null()]),
1260
- caller_filename: z.union([z.string(), z.null()]),
1261
- caller_lineno: z.union([z.number(), z.null()])
2236
+ tags: z5.union([z5.array(z5.string()), z5.null()]).optional(),
2237
+ metrics: z5.union([z5.record(z5.number()), z5.null()]).optional(),
2238
+ context: z5.union([
2239
+ z5.object({
2240
+ caller_functionname: z5.union([z5.string(), z5.null()]),
2241
+ caller_filename: z5.union([z5.string(), z5.null()]),
2242
+ caller_lineno: z5.union([z5.number(), z5.null()])
1262
2243
  }).partial().passthrough(),
1263
- z.null()
2244
+ z5.null()
1264
2245
  ]).optional(),
1265
- span_id: z.string(),
1266
- span_parents: z.union([z.array(z.string()), z.null()]).optional(),
1267
- root_span_id: z.string(),
1268
- is_root: z.union([z.boolean(), z.null()]).optional(),
2246
+ span_id: z5.string(),
2247
+ span_parents: z5.union([z5.array(z5.string()), z5.null()]).optional(),
2248
+ root_span_id: z5.string(),
2249
+ is_root: z5.union([z5.boolean(), z5.null()]).optional(),
1269
2250
  span_attributes: SpanAttributes.optional(),
1270
2251
  origin: ObjectReferenceNullish.optional()
1271
2252
  });
1272
- var ProjectScoreType = z.enum([
2253
+ var ProjectScoreType = z5.enum([
1273
2254
  "slider",
1274
2255
  "categorical",
1275
2256
  "weighted",
@@ -1278,172 +2259,172 @@ var ProjectScoreType = z.enum([
1278
2259
  "online",
1279
2260
  "free-form"
1280
2261
  ]);
1281
- var ProjectScoreCategory = z.object({
1282
- name: z.string(),
1283
- value: z.number()
2262
+ var ProjectScoreCategory = z5.object({
2263
+ name: z5.string(),
2264
+ value: z5.number()
1284
2265
  });
1285
- var ProjectScoreCategories = z.union([
1286
- z.array(ProjectScoreCategory),
1287
- z.record(z.number()),
1288
- z.array(z.string()),
1289
- z.null()
2266
+ var ProjectScoreCategories = z5.union([
2267
+ z5.array(ProjectScoreCategory),
2268
+ z5.record(z5.number()),
2269
+ z5.array(z5.string()),
2270
+ z5.null()
1290
2271
  ]);
1291
- var ProjectScoreConfig = z.union([
1292
- z.object({
1293
- multi_select: z.union([z.boolean(), z.null()]),
1294
- destination: z.union([z.string(), z.null()]),
2272
+ var ProjectScoreConfig = z5.union([
2273
+ z5.object({
2274
+ multi_select: z5.union([z5.boolean(), z5.null()]),
2275
+ destination: z5.union([z5.string(), z5.null()]),
1295
2276
  online: OnlineScoreConfig
1296
2277
  }).partial(),
1297
- z.null()
2278
+ z5.null()
1298
2279
  ]);
1299
- var ProjectScore = z.object({
1300
- id: z.string().uuid(),
1301
- project_id: z.string().uuid(),
1302
- user_id: z.string().uuid(),
1303
- created: z.union([z.string(), z.null()]).optional(),
1304
- name: z.string(),
1305
- description: z.union([z.string(), z.null()]).optional(),
2280
+ var ProjectScore = z5.object({
2281
+ id: z5.string().uuid(),
2282
+ project_id: z5.string().uuid(),
2283
+ user_id: z5.string().uuid(),
2284
+ created: z5.union([z5.string(), z5.null()]).optional(),
2285
+ name: z5.string(),
2286
+ description: z5.union([z5.string(), z5.null()]).optional(),
1306
2287
  score_type: ProjectScoreType,
1307
2288
  categories: ProjectScoreCategories.optional(),
1308
2289
  config: ProjectScoreConfig.optional(),
1309
- position: z.union([z.string(), z.null()]).optional()
2290
+ position: z5.union([z5.string(), z5.null()]).optional()
1310
2291
  });
1311
- var ProjectTag = z.object({
1312
- id: z.string().uuid(),
1313
- project_id: z.string().uuid(),
1314
- user_id: z.string().uuid(),
1315
- created: z.union([z.string(), z.null()]).optional(),
1316
- name: z.string(),
1317
- description: z.union([z.string(), z.null()]).optional(),
1318
- color: z.union([z.string(), z.null()]).optional(),
1319
- position: z.union([z.string(), z.null()]).optional()
2292
+ var ProjectTag = z5.object({
2293
+ id: z5.string().uuid(),
2294
+ project_id: z5.string().uuid(),
2295
+ user_id: z5.string().uuid(),
2296
+ created: z5.union([z5.string(), z5.null()]).optional(),
2297
+ name: z5.string(),
2298
+ description: z5.union([z5.string(), z5.null()]).optional(),
2299
+ color: z5.union([z5.string(), z5.null()]).optional(),
2300
+ position: z5.union([z5.string(), z5.null()]).optional()
1320
2301
  });
1321
- var Prompt = z.object({
1322
- id: z.string().uuid(),
1323
- _xact_id: z.string(),
1324
- project_id: z.string().uuid(),
1325
- log_id: z.literal("p"),
1326
- org_id: z.string().uuid(),
1327
- name: z.string(),
1328
- slug: z.string(),
1329
- description: z.union([z.string(), z.null()]).optional(),
1330
- created: z.union([z.string(), z.null()]).optional(),
2302
+ var Prompt = z5.object({
2303
+ id: z5.string().uuid(),
2304
+ _xact_id: z5.string(),
2305
+ project_id: z5.string().uuid(),
2306
+ log_id: z5.literal("p"),
2307
+ org_id: z5.string().uuid(),
2308
+ name: z5.string(),
2309
+ slug: z5.string(),
2310
+ description: z5.union([z5.string(), z5.null()]).optional(),
2311
+ created: z5.union([z5.string(), z5.null()]).optional(),
1331
2312
  prompt_data: PromptDataNullish.optional(),
1332
- tags: z.union([z.array(z.string()), z.null()]).optional(),
1333
- metadata: z.union([z.object({}).partial().passthrough(), z.null()]).optional(),
2313
+ tags: z5.union([z5.array(z5.string()), z5.null()]).optional(),
2314
+ metadata: z5.union([z5.object({}).partial().passthrough(), z5.null()]).optional(),
1334
2315
  function_type: FunctionTypeEnumNullish.optional()
1335
2316
  });
1336
- var PromptOptions = z.object({ model: z.string(), params: ModelParams, position: z.string() }).partial();
1337
- var PromptSessionEvent = z.object({
1338
- id: z.string(),
1339
- _xact_id: z.string(),
1340
- created: z.string().datetime({ offset: true }),
1341
- _pagination_key: z.union([z.string(), z.null()]).optional(),
1342
- project_id: z.string().uuid(),
1343
- prompt_session_id: z.string().uuid(),
1344
- prompt_session_data: z.unknown().optional(),
1345
- prompt_data: z.unknown().optional(),
1346
- function_data: z.unknown().optional(),
2317
+ var PromptOptions = z5.object({ model: z5.string(), params: ModelParams, position: z5.string() }).partial();
2318
+ var PromptSessionEvent = z5.object({
2319
+ id: z5.string(),
2320
+ _xact_id: z5.string(),
2321
+ created: z5.string().datetime({ offset: true }),
2322
+ _pagination_key: z5.union([z5.string(), z5.null()]).optional(),
2323
+ project_id: z5.string().uuid(),
2324
+ prompt_session_id: z5.string().uuid(),
2325
+ prompt_session_data: z5.unknown().optional(),
2326
+ prompt_data: z5.unknown().optional(),
2327
+ function_data: z5.unknown().optional(),
1347
2328
  function_type: FunctionTypeEnumNullish.optional(),
1348
- object_data: z.unknown().optional(),
1349
- completion: z.unknown().optional(),
1350
- tags: z.union([z.array(z.string()), z.null()]).optional()
2329
+ object_data: z5.unknown().optional(),
2330
+ completion: z5.unknown().optional(),
2331
+ tags: z5.union([z5.array(z5.string()), z5.null()]).optional()
1351
2332
  });
1352
- var ResponseFormat = z.union([
1353
- z.object({ type: z.literal("json_object") }),
1354
- z.object({
1355
- type: z.literal("json_schema"),
2333
+ var ResponseFormat = z5.union([
2334
+ z5.object({ type: z5.literal("json_object") }),
2335
+ z5.object({
2336
+ type: z5.literal("json_schema"),
1356
2337
  json_schema: ResponseFormatJsonSchema
1357
2338
  }),
1358
- z.object({ type: z.literal("text") })
2339
+ z5.object({ type: z5.literal("text") })
1359
2340
  ]);
1360
- var Role = z.object({
1361
- id: z.string().uuid(),
1362
- org_id: z.union([z.string(), z.null()]).optional(),
1363
- user_id: z.union([z.string(), z.null()]).optional(),
1364
- created: z.union([z.string(), z.null()]).optional(),
1365
- name: z.string(),
1366
- description: z.union([z.string(), z.null()]).optional(),
1367
- deleted_at: z.union([z.string(), z.null()]).optional(),
1368
- member_permissions: z.union([
1369
- z.array(
1370
- z.object({
2341
+ var Role = z5.object({
2342
+ id: z5.string().uuid(),
2343
+ org_id: z5.union([z5.string(), z5.null()]).optional(),
2344
+ user_id: z5.union([z5.string(), z5.null()]).optional(),
2345
+ created: z5.union([z5.string(), z5.null()]).optional(),
2346
+ name: z5.string(),
2347
+ description: z5.union([z5.string(), z5.null()]).optional(),
2348
+ deleted_at: z5.union([z5.string(), z5.null()]).optional(),
2349
+ member_permissions: z5.union([
2350
+ z5.array(
2351
+ z5.object({
1371
2352
  permission: Permission,
1372
2353
  restrict_object_type: AclObjectType.optional()
1373
2354
  })
1374
2355
  ),
1375
- z.null()
2356
+ z5.null()
1376
2357
  ]).optional(),
1377
- member_roles: z.union([z.array(z.string().uuid()), z.null()]).optional()
2358
+ member_roles: z5.union([z5.array(z5.string().uuid()), z5.null()]).optional()
1378
2359
  });
1379
- var RunEval = z.object({
1380
- project_id: z.string(),
1381
- data: z.union([
1382
- z.object({
1383
- dataset_id: z.string(),
1384
- _internal_btql: z.union([z.object({}).partial().passthrough(), z.null()]).optional()
2360
+ var RunEval = z5.object({
2361
+ project_id: z5.string(),
2362
+ data: z5.union([
2363
+ z5.object({
2364
+ dataset_id: z5.string(),
2365
+ _internal_btql: z5.union([z5.object({}).partial().passthrough(), z5.null()]).optional()
1385
2366
  }),
1386
- z.object({
1387
- project_name: z.string(),
1388
- dataset_name: z.string(),
1389
- _internal_btql: z.union([z.object({}).partial().passthrough(), z.null()]).optional()
2367
+ z5.object({
2368
+ project_name: z5.string(),
2369
+ dataset_name: z5.string(),
2370
+ _internal_btql: z5.union([z5.object({}).partial().passthrough(), z5.null()]).optional()
1390
2371
  }),
1391
- z.object({ data: z.array(z.unknown()) })
2372
+ z5.object({ data: z5.array(z5.unknown()) })
1392
2373
  ]),
1393
- task: FunctionId.and(z.unknown()),
1394
- scores: z.array(FunctionId),
1395
- experiment_name: z.string().optional(),
1396
- metadata: z.object({}).partial().passthrough().optional(),
1397
- parent: InvokeParent.and(z.unknown()).optional(),
1398
- stream: z.boolean().optional(),
1399
- trial_count: z.union([z.number(), z.null()]).optional(),
1400
- is_public: z.union([z.boolean(), z.null()]).optional(),
1401
- timeout: z.union([z.number(), z.null()]).optional(),
1402
- max_concurrency: z.union([z.number(), z.null()]).optional().default(10),
1403
- base_experiment_name: z.union([z.string(), z.null()]).optional(),
1404
- base_experiment_id: z.union([z.string(), z.null()]).optional(),
2374
+ task: FunctionId.and(z5.unknown()),
2375
+ scores: z5.array(FunctionId),
2376
+ experiment_name: z5.string().optional(),
2377
+ metadata: z5.object({}).partial().passthrough().optional(),
2378
+ parent: InvokeParent.and(z5.unknown()).optional(),
2379
+ stream: z5.boolean().optional(),
2380
+ trial_count: z5.union([z5.number(), z5.null()]).optional(),
2381
+ is_public: z5.union([z5.boolean(), z5.null()]).optional(),
2382
+ timeout: z5.union([z5.number(), z5.null()]).optional(),
2383
+ max_concurrency: z5.union([z5.number(), z5.null()]).optional().default(10),
2384
+ base_experiment_name: z5.union([z5.string(), z5.null()]).optional(),
2385
+ base_experiment_id: z5.union([z5.string(), z5.null()]).optional(),
1405
2386
  git_metadata_settings: GitMetadataSettings.and(
1406
- z.union([z.object({}).partial(), z.null()])
2387
+ z5.union([z5.object({}).partial(), z5.null()])
1407
2388
  ).optional(),
1408
- repo_info: RepoInfo.and(z.unknown()).optional(),
1409
- strict: z.union([z.boolean(), z.null()]).optional(),
1410
- stop_token: z.union([z.string(), z.null()]).optional(),
1411
- extra_messages: z.string().optional(),
1412
- tags: z.array(z.string()).optional()
2389
+ repo_info: RepoInfo.and(z5.unknown()).optional(),
2390
+ strict: z5.union([z5.boolean(), z5.null()]).optional(),
2391
+ stop_token: z5.union([z5.string(), z5.null()]).optional(),
2392
+ extra_messages: z5.string().optional(),
2393
+ tags: z5.array(z5.string()).optional()
1413
2394
  });
1414
- var ServiceToken = z.object({
1415
- id: z.string().uuid(),
1416
- created: z.union([z.string(), z.null()]).optional(),
1417
- name: z.string(),
1418
- preview_name: z.string(),
1419
- service_account_id: z.union([z.string(), z.null()]).optional(),
1420
- service_account_email: z.union([z.string(), z.null()]).optional(),
1421
- service_account_name: z.union([z.string(), z.null()]).optional(),
1422
- org_id: z.union([z.string(), z.null()]).optional()
2395
+ var ServiceToken = z5.object({
2396
+ id: z5.string().uuid(),
2397
+ created: z5.union([z5.string(), z5.null()]).optional(),
2398
+ name: z5.string(),
2399
+ preview_name: z5.string(),
2400
+ service_account_id: z5.union([z5.string(), z5.null()]).optional(),
2401
+ service_account_email: z5.union([z5.string(), z5.null()]).optional(),
2402
+ service_account_name: z5.union([z5.string(), z5.null()]).optional(),
2403
+ org_id: z5.union([z5.string(), z5.null()]).optional()
1423
2404
  });
1424
- var SpanIFrame = z.object({
1425
- id: z.string().uuid(),
1426
- project_id: z.string().uuid(),
1427
- user_id: z.union([z.string(), z.null()]).optional(),
1428
- created: z.union([z.string(), z.null()]).optional(),
1429
- deleted_at: z.union([z.string(), z.null()]).optional(),
1430
- name: z.string(),
1431
- description: z.union([z.string(), z.null()]).optional(),
1432
- url: z.string(),
1433
- post_message: z.union([z.boolean(), z.null()]).optional()
2405
+ var SpanIFrame = z5.object({
2406
+ id: z5.string().uuid(),
2407
+ project_id: z5.string().uuid(),
2408
+ user_id: z5.union([z5.string(), z5.null()]).optional(),
2409
+ created: z5.union([z5.string(), z5.null()]).optional(),
2410
+ deleted_at: z5.union([z5.string(), z5.null()]).optional(),
2411
+ name: z5.string(),
2412
+ description: z5.union([z5.string(), z5.null()]).optional(),
2413
+ url: z5.string(),
2414
+ post_message: z5.union([z5.boolean(), z5.null()]).optional()
1434
2415
  });
1435
- var SSEConsoleEventData = z.object({
1436
- stream: z.enum(["stderr", "stdout"]),
1437
- message: z.string()
2416
+ var SSEConsoleEventData = z5.object({
2417
+ stream: z5.enum(["stderr", "stdout"]),
2418
+ message: z5.string()
1438
2419
  });
1439
- var SSEProgressEventData = z.object({
1440
- id: z.string(),
2420
+ var SSEProgressEventData = z5.object({
2421
+ id: z5.string(),
1441
2422
  object_type: FunctionObjectType,
1442
- origin: ObjectReferenceNullish.and(z.unknown()).optional(),
2423
+ origin: ObjectReferenceNullish.and(z5.unknown()).optional(),
1443
2424
  format: FunctionFormat,
1444
2425
  output_type: FunctionOutputType,
1445
- name: z.string(),
1446
- event: z.enum([
2426
+ name: z5.string(),
2427
+ event: z5.enum([
1447
2428
  "reasoning_delta",
1448
2429
  "text_delta",
1449
2430
  "json_delta",
@@ -1453,110 +2434,110 @@ var SSEProgressEventData = z.object({
1453
2434
  "done",
1454
2435
  "progress"
1455
2436
  ]),
1456
- data: z.string()
2437
+ data: z5.string()
1457
2438
  });
1458
- var ToolFunctionDefinition = z.object({
1459
- type: z.literal("function"),
1460
- function: z.object({
1461
- name: z.string(),
1462
- description: z.string().optional(),
1463
- parameters: z.object({}).partial().passthrough().optional(),
1464
- strict: z.union([z.boolean(), z.null()]).optional()
2439
+ var ToolFunctionDefinition = z5.object({
2440
+ type: z5.literal("function"),
2441
+ function: z5.object({
2442
+ name: z5.string(),
2443
+ description: z5.string().optional(),
2444
+ parameters: z5.object({}).partial().passthrough().optional(),
2445
+ strict: z5.union([z5.boolean(), z5.null()]).optional()
1465
2446
  })
1466
2447
  });
1467
- var User = z.object({
1468
- id: z.string().uuid(),
1469
- given_name: z.union([z.string(), z.null()]).optional(),
1470
- family_name: z.union([z.string(), z.null()]).optional(),
1471
- email: z.union([z.string(), z.null()]).optional(),
1472
- avatar_url: z.union([z.string(), z.null()]).optional(),
1473
- created: z.union([z.string(), z.null()]).optional()
2448
+ var User = z5.object({
2449
+ id: z5.string().uuid(),
2450
+ given_name: z5.union([z5.string(), z5.null()]).optional(),
2451
+ family_name: z5.union([z5.string(), z5.null()]).optional(),
2452
+ email: z5.union([z5.string(), z5.null()]).optional(),
2453
+ avatar_url: z5.union([z5.string(), z5.null()]).optional(),
2454
+ created: z5.union([z5.string(), z5.null()]).optional()
1474
2455
  });
1475
- var ViewDataSearch = z.union([
1476
- z.object({
1477
- filter: z.union([z.array(z.unknown()), z.null()]),
1478
- tag: z.union([z.array(z.unknown()), z.null()]),
1479
- match: z.union([z.array(z.unknown()), z.null()]),
1480
- sort: z.union([z.array(z.unknown()), z.null()])
2456
+ var ViewDataSearch = z5.union([
2457
+ z5.object({
2458
+ filter: z5.union([z5.array(z5.unknown()), z5.null()]),
2459
+ tag: z5.union([z5.array(z5.unknown()), z5.null()]),
2460
+ match: z5.union([z5.array(z5.unknown()), z5.null()]),
2461
+ sort: z5.union([z5.array(z5.unknown()), z5.null()])
1481
2462
  }).partial(),
1482
- z.null()
2463
+ z5.null()
1483
2464
  ]);
1484
- var ViewData = z.union([
1485
- z.object({ search: ViewDataSearch }).partial(),
1486
- z.null()
2465
+ var ViewData = z5.union([
2466
+ z5.object({ search: ViewDataSearch }).partial(),
2467
+ z5.null()
1487
2468
  ]);
1488
- var ViewOptions = z.union([
1489
- z.object({
1490
- viewType: z.literal("monitor"),
1491
- options: z.object({
1492
- spanType: z.union([z.enum(["range", "frame"]), z.null()]),
1493
- rangeValue: z.union([z.string(), z.null()]),
1494
- frameStart: z.union([z.string(), z.null()]),
1495
- frameEnd: z.union([z.string(), z.null()]),
1496
- tzUTC: z.union([z.boolean(), z.null()]),
1497
- chartVisibility: z.union([z.record(z.boolean()), z.null()]),
1498
- projectId: z.union([z.string(), z.null()]),
1499
- type: z.union([z.enum(["project", "experiment"]), z.null()]),
1500
- groupBy: z.union([z.string(), z.null()])
2469
+ var ViewOptions = z5.union([
2470
+ z5.object({
2471
+ viewType: z5.literal("monitor"),
2472
+ options: z5.object({
2473
+ spanType: z5.union([z5.enum(["range", "frame"]), z5.null()]),
2474
+ rangeValue: z5.union([z5.string(), z5.null()]),
2475
+ frameStart: z5.union([z5.string(), z5.null()]),
2476
+ frameEnd: z5.union([z5.string(), z5.null()]),
2477
+ tzUTC: z5.union([z5.boolean(), z5.null()]),
2478
+ chartVisibility: z5.union([z5.record(z5.boolean()), z5.null()]),
2479
+ projectId: z5.union([z5.string(), z5.null()]),
2480
+ type: z5.union([z5.enum(["project", "experiment"]), z5.null()]),
2481
+ groupBy: z5.union([z5.string(), z5.null()])
1501
2482
  }).partial()
1502
2483
  }),
1503
- z.object({
1504
- columnVisibility: z.union([z.record(z.boolean()), z.null()]),
1505
- columnOrder: z.union([z.array(z.string()), z.null()]),
1506
- columnSizing: z.union([z.record(z.number()), z.null()]),
1507
- grouping: z.union([z.string(), z.null()]),
1508
- rowHeight: z.union([z.string(), z.null()]),
1509
- tallGroupRows: z.union([z.boolean(), z.null()]),
1510
- layout: z.union([z.string(), z.null()]),
1511
- chartHeight: z.union([z.number(), z.null()]),
1512
- excludedMeasures: z.union([
1513
- z.array(
1514
- z.object({
1515
- type: z.enum(["none", "score", "metric", "metadata"]),
1516
- value: z.string()
2484
+ z5.object({
2485
+ columnVisibility: z5.union([z5.record(z5.boolean()), z5.null()]),
2486
+ columnOrder: z5.union([z5.array(z5.string()), z5.null()]),
2487
+ columnSizing: z5.union([z5.record(z5.number()), z5.null()]),
2488
+ grouping: z5.union([z5.string(), z5.null()]),
2489
+ rowHeight: z5.union([z5.string(), z5.null()]),
2490
+ tallGroupRows: z5.union([z5.boolean(), z5.null()]),
2491
+ layout: z5.union([z5.string(), z5.null()]),
2492
+ chartHeight: z5.union([z5.number(), z5.null()]),
2493
+ excludedMeasures: z5.union([
2494
+ z5.array(
2495
+ z5.object({
2496
+ type: z5.enum(["none", "score", "metric", "metadata"]),
2497
+ value: z5.string()
1517
2498
  })
1518
2499
  ),
1519
- z.null()
2500
+ z5.null()
1520
2501
  ]),
1521
- yMetric: z.union([
1522
- z.object({
1523
- type: z.enum(["none", "score", "metric", "metadata"]),
1524
- value: z.string()
2502
+ yMetric: z5.union([
2503
+ z5.object({
2504
+ type: z5.enum(["none", "score", "metric", "metadata"]),
2505
+ value: z5.string()
1525
2506
  }),
1526
- z.null()
2507
+ z5.null()
1527
2508
  ]),
1528
- xAxis: z.union([
1529
- z.object({
1530
- type: z.enum(["none", "score", "metric", "metadata"]),
1531
- value: z.string()
2509
+ xAxis: z5.union([
2510
+ z5.object({
2511
+ type: z5.enum(["none", "score", "metric", "metadata"]),
2512
+ value: z5.string()
1532
2513
  }),
1533
- z.null()
2514
+ z5.null()
1534
2515
  ]),
1535
- symbolGrouping: z.union([
1536
- z.object({
1537
- type: z.enum(["none", "score", "metric", "metadata"]),
1538
- value: z.string()
2516
+ symbolGrouping: z5.union([
2517
+ z5.object({
2518
+ type: z5.enum(["none", "score", "metric", "metadata"]),
2519
+ value: z5.string()
1539
2520
  }),
1540
- z.null()
2521
+ z5.null()
1541
2522
  ]),
1542
- xAxisAggregation: z.union([z.string(), z.null()]),
1543
- chartAnnotations: z.union([
1544
- z.array(z.object({ id: z.string(), text: z.string() })),
1545
- z.null()
2523
+ xAxisAggregation: z5.union([z5.string(), z5.null()]),
2524
+ chartAnnotations: z5.union([
2525
+ z5.array(z5.object({ id: z5.string(), text: z5.string() })),
2526
+ z5.null()
1546
2527
  ]),
1547
- timeRangeFilter: z.union([
1548
- z.string(),
1549
- z.object({ from: z.string(), to: z.string() }),
1550
- z.null()
2528
+ timeRangeFilter: z5.union([
2529
+ z5.string(),
2530
+ z5.object({ from: z5.string(), to: z5.string() }),
2531
+ z5.null()
1551
2532
  ])
1552
2533
  }).partial(),
1553
- z.null()
2534
+ z5.null()
1554
2535
  ]);
1555
- var View = z.object({
1556
- id: z.string().uuid(),
1557
- object_type: AclObjectType.and(z.string()),
1558
- object_id: z.string().uuid(),
1559
- view_type: z.enum([
2536
+ var View = z5.object({
2537
+ id: z5.string().uuid(),
2538
+ object_type: AclObjectType.and(z5.string()),
2539
+ object_id: z5.string().uuid(),
2540
+ view_type: z5.enum([
1560
2541
  "projects",
1561
2542
  "experiments",
1562
2543
  "experiment",
@@ -1571,56 +2552,56 @@ var View = z.object({
1571
2552
  "agents",
1572
2553
  "monitor"
1573
2554
  ]),
1574
- name: z.string(),
1575
- created: z.union([z.string(), z.null()]).optional(),
2555
+ name: z5.string(),
2556
+ created: z5.union([z5.string(), z5.null()]).optional(),
1576
2557
  view_data: ViewData.optional(),
1577
2558
  options: ViewOptions.optional(),
1578
- user_id: z.union([z.string(), z.null()]).optional(),
1579
- deleted_at: z.union([z.string(), z.null()]).optional()
2559
+ user_id: z5.union([z5.string(), z5.null()]).optional(),
2560
+ deleted_at: z5.union([z5.string(), z5.null()]).optional()
1580
2561
  });
1581
2562
 
1582
2563
  // src/logger.ts
1583
2564
  import { waitUntil } from "@vercel/functions";
1584
2565
  import Mustache2 from "mustache";
1585
- import { z as z3, ZodError } from "zod";
2566
+ import { z as z7, ZodError } from "zod";
1586
2567
 
1587
2568
  // src/functions/stream.ts
1588
2569
  import {
1589
2570
  createParser
1590
2571
  } from "eventsource-parser";
1591
- import { z as z2 } from "zod";
1592
- var braintrustStreamChunkSchema = z2.union([
1593
- z2.object({
1594
- type: z2.literal("text_delta"),
1595
- data: z2.string()
2572
+ import { z as z6 } from "zod/v3";
2573
+ var braintrustStreamChunkSchema = z6.union([
2574
+ z6.object({
2575
+ type: z6.literal("text_delta"),
2576
+ data: z6.string()
1596
2577
  }),
1597
- z2.object({
1598
- type: z2.literal("reasoning_delta"),
1599
- data: z2.string()
2578
+ z6.object({
2579
+ type: z6.literal("reasoning_delta"),
2580
+ data: z6.string()
1600
2581
  }),
1601
- z2.object({
1602
- type: z2.literal("json_delta"),
1603
- data: z2.string()
2582
+ z6.object({
2583
+ type: z6.literal("json_delta"),
2584
+ data: z6.string()
1604
2585
  }),
1605
- z2.object({
1606
- type: z2.literal("error"),
1607
- data: z2.string()
2586
+ z6.object({
2587
+ type: z6.literal("error"),
2588
+ data: z6.string()
1608
2589
  }),
1609
- z2.object({
1610
- type: z2.literal("console"),
2590
+ z6.object({
2591
+ type: z6.literal("console"),
1611
2592
  data: SSEConsoleEventData
1612
2593
  }),
1613
- z2.object({
1614
- type: z2.literal("progress"),
2594
+ z6.object({
2595
+ type: z6.literal("progress"),
1615
2596
  data: SSEProgressEventData
1616
2597
  }),
1617
- z2.object({
1618
- type: z2.literal("start"),
1619
- data: z2.string()
2598
+ z6.object({
2599
+ type: z6.literal("start"),
2600
+ data: z6.string()
1620
2601
  }),
1621
- z2.object({
1622
- type: z2.literal("done"),
1623
- data: z2.string()
2602
+ z6.object({
2603
+ type: z6.literal("done"),
2604
+ data: z6.string()
1624
2605
  })
1625
2606
  ]);
1626
2607
  var BraintrustStream = class _BraintrustStream {
@@ -2205,7 +3186,6 @@ var InternalAbortError = class extends Error {
2205
3186
  };
2206
3187
 
2207
3188
  // src/mustache-utils.ts
2208
- import { getObjValueByPath } from "@braintrust/core";
2209
3189
  import Mustache from "mustache";
2210
3190
  function lintTemplate(template, context) {
2211
3191
  const variables = getMustacheVars(template);
@@ -2228,7 +3208,6 @@ function getMustacheVars(prompt) {
2228
3208
  }
2229
3209
 
2230
3210
  // src/logger.ts
2231
- import { prettifyXact } from "@braintrust/core";
2232
3211
  var BRAINTRUST_ATTACHMENT = BraintrustAttachmentReference.shape.type.value;
2233
3212
  var EXTERNAL_ATTACHMENT = ExternalAttachmentReference.shape.type.value;
2234
3213
  var BRAINTRUST_PARAMS = Object.keys(BraintrustModelParams.shape);
@@ -2316,14 +3295,14 @@ var NoopSpan = class {
2316
3295
  };
2317
3296
  var NOOP_SPAN = new NoopSpan();
2318
3297
  var NOOP_SPAN_PERMALINK = "https://braintrust.dev/noop-span";
2319
- var loginSchema = z3.strictObject({
2320
- appUrl: z3.string(),
2321
- appPublicUrl: z3.string(),
2322
- orgName: z3.string(),
2323
- apiUrl: z3.string(),
2324
- proxyUrl: z3.string(),
2325
- loginToken: z3.string(),
2326
- orgId: z3.string().nullish(),
3298
+ var loginSchema = z7.strictObject({
3299
+ appUrl: z7.string(),
3300
+ appPublicUrl: z7.string(),
3301
+ orgName: z7.string(),
3302
+ apiUrl: z7.string(),
3303
+ proxyUrl: z7.string(),
3304
+ loginToken: z7.string(),
3305
+ orgId: z7.string().nullish(),
2327
3306
  gitMetadataSettings: GitMetadataSettings.nullish()
2328
3307
  });
2329
3308
  var stateNonce = 0;
@@ -2776,9 +3755,9 @@ var Attachment = class extends BaseAttachment {
2776
3755
  let signedUrl;
2777
3756
  let headers;
2778
3757
  try {
2779
- ({ signedUrl, headers } = z3.object({
2780
- signedUrl: z3.string().url(),
2781
- headers: z3.record(z3.string())
3758
+ ({ signedUrl, headers } = z7.object({
3759
+ signedUrl: z7.string().url(),
3760
+ headers: z7.record(z7.string())
2782
3761
  }).parse(await metadataResponse.json()));
2783
3762
  } catch (error2) {
2784
3763
  if (error2 instanceof ZodError) {
@@ -2866,8 +3845,8 @@ with a Blob/ArrayBuffer, or run the program on Node.js.`
2866
3845
  }
2867
3846
  }
2868
3847
  };
2869
- var attachmentMetadataSchema = z3.object({
2870
- downloadUrl: z3.string(),
3848
+ var attachmentMetadataSchema = z7.object({
3849
+ downloadUrl: z7.string(),
2871
3850
  status: AttachmentStatus
2872
3851
  });
2873
3852
  var ReadonlyAttachment = class {
@@ -3059,15 +4038,15 @@ function spanComponentsToObjectIdLambda(state, components) {
3059
4038
  );
3060
4039
  }
3061
4040
  switch (components.data.object_type) {
3062
- case SpanObjectTypeV3.EXPERIMENT:
4041
+ case 1 /* EXPERIMENT */:
3063
4042
  throw new Error(
3064
4043
  "Impossible: computeObjectMetadataArgs not supported for experiments"
3065
4044
  );
3066
- case SpanObjectTypeV3.PLAYGROUND_LOGS:
4045
+ case 3 /* PLAYGROUND_LOGS */:
3067
4046
  throw new Error(
3068
4047
  "Impossible: computeObjectMetadataArgs not supported for prompt sessions"
3069
4048
  );
3070
- case SpanObjectTypeV3.PROJECT_LOGS:
4049
+ case 2 /* PROJECT_LOGS */:
3071
4050
  return async () => (await computeLoggerMetadata(state, {
3072
4051
  ...components.data.compute_object_metadata_args
3073
4052
  })).project.id;
@@ -3219,7 +4198,7 @@ var Logger = class {
3219
4198
  return (async () => (await this.project).id)();
3220
4199
  }
3221
4200
  parentObjectType() {
3222
- return SpanObjectTypeV3.PROJECT_LOGS;
4201
+ return 2 /* PROJECT_LOGS */;
3223
4202
  }
3224
4203
  /**
3225
4204
  * Log a single event. The event will be batched and uploaded behind the scenes if `logOptions.asyncFlush` is true.
@@ -3313,7 +4292,7 @@ var Logger = class {
3313
4292
  parentSpanIds: args?.parentSpanIds,
3314
4293
  propagatedEvent: args?.propagatedEvent
3315
4294
  }),
3316
- defaultRootType: SpanTypeAttribute.TASK
4295
+ defaultRootType: "task" /* TASK */
3317
4296
  });
3318
4297
  }
3319
4298
  /**
@@ -4161,6 +5140,8 @@ function getSpanParentObject(options) {
4161
5140
  if (!Object.is(parentSpan, NOOP_SPAN)) {
4162
5141
  return parentSpan;
4163
5142
  }
5143
+ const parentStr = options?.parent ?? state.currentParent.getStore();
5144
+ if (parentStr) return SpanComponentsV3.fromStr(parentStr);
4164
5145
  const experiment = currentExperiment();
4165
5146
  if (experiment) {
4166
5147
  return experiment;
@@ -4221,35 +5202,35 @@ async function flush(options) {
4221
5202
  }
4222
5203
  function startSpanAndIsLogger(args) {
4223
5204
  const state = args?.state ?? _globalState;
4224
- const parentStr = args?.parent ?? state.currentParent.getStore();
4225
- const components = parentStr ? SpanComponentsV3.fromStr(parentStr) : void 0;
4226
- if (components) {
4227
- const parentSpanIds = components.data.row_id ? {
4228
- spanId: components.data.span_id,
4229
- rootSpanId: components.data.root_span_id
5205
+ const parentObject = getSpanParentObject({
5206
+ asyncFlush: args?.asyncFlush,
5207
+ parent: args?.parent,
5208
+ state
5209
+ });
5210
+ if (parentObject instanceof SpanComponentsV3) {
5211
+ const parentSpanIds = parentObject.data.row_id ? {
5212
+ spanId: parentObject.data.span_id,
5213
+ rootSpanId: parentObject.data.root_span_id
4230
5214
  } : void 0;
4231
5215
  const span = new SpanImpl({
4232
5216
  state,
4233
5217
  ...args,
4234
- parentObjectType: components.data.object_type,
5218
+ parentObjectType: parentObject.data.object_type,
4235
5219
  parentObjectId: new LazyValue(
4236
- spanComponentsToObjectIdLambda(state, components)
5220
+ spanComponentsToObjectIdLambda(state, parentObject)
4237
5221
  ),
4238
- parentComputeObjectMetadataArgs: components.data.compute_object_metadata_args ?? void 0,
5222
+ parentComputeObjectMetadataArgs: parentObject.data.compute_object_metadata_args ?? void 0,
4239
5223
  parentSpanIds,
4240
5224
  propagatedEvent: args?.propagatedEvent ?? // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
4241
- (components.data.propagated_event ?? void 0)
5225
+ (parentObject.data.propagated_event ?? void 0)
4242
5226
  });
4243
5227
  return {
4244
5228
  span,
4245
- isSyncFlushLogger: components.data.object_type === SpanObjectTypeV3.PROJECT_LOGS && // Since there's no parent logger here, we're free to choose the async flush
5229
+ isSyncFlushLogger: parentObject.data.object_type === 2 /* PROJECT_LOGS */ && // Since there's no parent logger here, we're free to choose the async flush
4246
5230
  // behavior, and therefore propagate along whatever we get from the arguments
4247
5231
  args?.asyncFlush === false
4248
5232
  };
4249
5233
  } else {
4250
- const parentObject = getSpanParentObject({
4251
- asyncFlush: args?.asyncFlush
4252
- });
4253
5234
  const span = parentObject.startSpan(args);
4254
5235
  return {
4255
5236
  span,
@@ -4353,7 +5334,7 @@ function validateAndSanitizeExperimentLogPartialArgs(event) {
4353
5334
  function deepCopyEvent(event) {
4354
5335
  const attachments = [];
4355
5336
  const IDENTIFIER = "_bt_internal_saved_attachment";
4356
- const savedAttachmentSchema = z3.strictObject({ [IDENTIFIER]: z3.number() });
5337
+ const savedAttachmentSchema = z7.strictObject({ [IDENTIFIER]: z7.number() });
4357
5338
  const serialized = JSON.stringify(event, (_k, v) => {
4358
5339
  if (v instanceof SpanImpl || v instanceof NoopSpan) {
4359
5340
  return `<span>`;
@@ -4588,7 +5569,7 @@ var Experiment2 = class extends ObjectFetcher {
4588
5569
  })();
4589
5570
  }
4590
5571
  parentObjectType() {
4591
- return SpanObjectTypeV3.EXPERIMENT;
5572
+ return 1 /* EXPERIMENT */;
4592
5573
  }
4593
5574
  async getState() {
4594
5575
  await this.lazyMetadata.get();
@@ -4672,7 +5653,7 @@ var Experiment2 = class extends ObjectFetcher {
4672
5653
  parentSpanIds: void 0,
4673
5654
  propagatedEvent: args?.propagatedEvent
4674
5655
  }),
4675
- defaultRootType: SpanTypeAttribute.EVAL
5656
+ defaultRootType: "eval" /* EVAL */
4676
5657
  });
4677
5658
  }
4678
5659
  async fetchBaseExperiment() {
@@ -5091,7 +6072,7 @@ var SpanImpl = class _SpanImpl {
5091
6072
  const baseUrl = `${appUrl}/app/${orgName}`;
5092
6073
  const args = this.parentComputeObjectMetadataArgs;
5093
6074
  switch (this.parentObjectType) {
5094
- case SpanObjectTypeV3.PROJECT_LOGS: {
6075
+ case 2 /* PROJECT_LOGS */: {
5095
6076
  const projectID = args?.project_id || this.parentObjectId.getSync().value;
5096
6077
  const projectName = args?.project_name;
5097
6078
  if (projectID) {
@@ -5102,7 +6083,7 @@ var SpanImpl = class _SpanImpl {
5102
6083
  return getErrPermlink("provide-project-name-or-id");
5103
6084
  }
5104
6085
  }
5105
- case SpanObjectTypeV3.EXPERIMENT: {
6086
+ case 1 /* EXPERIMENT */: {
5106
6087
  const expID = args?.experiment_id || this.parentObjectId?.getSync()?.value;
5107
6088
  if (!expID) {
5108
6089
  return getErrPermlink("provide-experiment-id");
@@ -5110,7 +6091,7 @@ var SpanImpl = class _SpanImpl {
5110
6091
  return `${baseUrl}/object?object_type=experiment&object_id=${expID}&id=${this._id}`;
5111
6092
  }
5112
6093
  }
5113
- case SpanObjectTypeV3.PLAYGROUND_LOGS: {
6094
+ case 3 /* PLAYGROUND_LOGS */: {
5114
6095
  return NOOP_SPAN_PERMALINK;
5115
6096
  }
5116
6097
  default: {
@@ -5358,8 +6339,8 @@ var Dataset2 = class extends ObjectFetcher {
5358
6339
  )}`;
5359
6340
  let dataSummary;
5360
6341
  if (summarizeData) {
5361
- const rawDataSummary = z3.object({
5362
- total_records: z3.number()
6342
+ const rawDataSummary = z7.object({
6343
+ total_records: z7.number()
5363
6344
  }).parse(
5364
6345
  await state.apiConn().get_json(
5365
6346
  "dataset-summary",
@@ -5482,11 +6463,11 @@ function renderTemplatedObject(obj, args, options) {
5482
6463
  return obj;
5483
6464
  }
5484
6465
  function renderPromptParams(params, args, options) {
5485
- const schemaParsed = z3.object({
5486
- response_format: z3.object({
5487
- type: z3.literal("json_schema"),
6466
+ const schemaParsed = z7.object({
6467
+ response_format: z7.object({
6468
+ type: z7.literal("json_schema"),
5488
6469
  json_schema: ResponseFormatJsonSchema.omit({ schema: true }).extend({
5489
- schema: z3.unknown()
6470
+ schema: z7.unknown()
5490
6471
  })
5491
6472
  })
5492
6473
  }).safeParse(params);
@@ -5604,7 +6585,7 @@ var Prompt2 = class _Prompt {
5604
6585
  if (!prompt) {
5605
6586
  throw new Error("Empty prompt");
5606
6587
  }
5607
- const dictArgParsed = z3.record(z3.unknown()).safeParse(buildArgs);
6588
+ const dictArgParsed = z7.record(z7.unknown()).safeParse(buildArgs);
5608
6589
  const variables = {
5609
6590
  input: buildArgs,
5610
6591
  ...dictArgParsed.success ? dictArgParsed.data : {}
@@ -5659,7 +6640,7 @@ var Prompt2 = class _Prompt {
5659
6640
  return JSON.stringify(v);
5660
6641
  }
5661
6642
  };
5662
- const dictArgParsed = z3.record(z3.unknown()).safeParse(buildArgs);
6643
+ const dictArgParsed = z7.record(z7.unknown()).safeParse(buildArgs);
5663
6644
  const variables = {
5664
6645
  input: buildArgs,
5665
6646
  ...dictArgParsed.success ? dictArgParsed.data : {}
@@ -5767,9 +6748,6 @@ function configureNode() {
5767
6748
  import express from "express";
5768
6749
  import cors from "cors";
5769
6750
 
5770
- // src/framework.ts
5771
- import { SpanTypeAttribute as SpanTypeAttribute2, mergeDicts as mergeDicts2 } from "@braintrust/core";
5772
-
5773
6751
  // ../../node_modules/.pnpm/async@3.2.5/node_modules/async/dist/async.mjs
5774
6752
  function initialParams(fn) {
5775
6753
  return function(...args) {
@@ -6849,13 +7827,12 @@ var BarProgressReporter = class {
6849
7827
  };
6850
7828
 
6851
7829
  // src/eval-parameters.ts
6852
- import { z as z5 } from "zod";
7830
+ import { z as z9 } from "zod/v3";
6853
7831
 
6854
7832
  // src/framework2.ts
6855
7833
  import path2 from "path";
6856
7834
  import slugifyLib from "slugify";
6857
- import { z as z4 } from "zod";
6858
- import { loadPrettyXact } from "@braintrust/core";
7835
+ import { z as z8 } from "zod/v3";
6859
7836
  var ProjectBuilder = class {
6860
7837
  create(opts) {
6861
7838
  return new Project2(opts);
@@ -7089,23 +8066,23 @@ var CodePrompt = class {
7089
8066
  };
7090
8067
  }
7091
8068
  };
7092
- var promptContentsSchema = z4.union([
7093
- z4.object({
7094
- prompt: z4.string()
8069
+ var promptContentsSchema = z8.union([
8070
+ z8.object({
8071
+ prompt: z8.string()
7095
8072
  }),
7096
- z4.object({
7097
- messages: z4.array(ChatCompletionMessageParam)
8073
+ z8.object({
8074
+ messages: z8.array(ChatCompletionMessageParam)
7098
8075
  })
7099
8076
  ]);
7100
8077
  var promptDefinitionSchema = promptContentsSchema.and(
7101
- z4.object({
7102
- model: z4.string(),
8078
+ z8.object({
8079
+ model: z8.string(),
7103
8080
  params: ModelParams.optional()
7104
8081
  })
7105
8082
  );
7106
8083
  var promptDefinitionWithToolsSchema = promptDefinitionSchema.and(
7107
- z4.object({
7108
- tools: z4.array(ToolFunctionDefinition).optional()
8084
+ z8.object({
8085
+ tools: z8.array(ToolFunctionDefinition).optional()
7109
8086
  })
7110
8087
  );
7111
8088
  var PromptBuilder = class {
@@ -7173,7 +8150,7 @@ var ProjectNameIdMap = class {
7173
8150
  const response = await _internalGetGlobalState().appConn().post_json("api/project/register", {
7174
8151
  project_name: projectName
7175
8152
  });
7176
- const result = z4.object({
8153
+ const result = z8.object({
7177
8154
  project: Project
7178
8155
  }).parse(response);
7179
8156
  const projectId = result.project.id;
@@ -7187,7 +8164,7 @@ var ProjectNameIdMap = class {
7187
8164
  const response = await _internalGetGlobalState().appConn().post_json("api/project/get", {
7188
8165
  id: projectId
7189
8166
  });
7190
- const result = z4.array(Project).nonempty().parse(response);
8167
+ const result = z8.array(Project).nonempty().parse(response);
7191
8168
  const projectName = result[0].name;
7192
8169
  this.idToName[projectId] = projectName;
7193
8170
  this.nameToId[projectName] = projectId;
@@ -7203,15 +8180,15 @@ var ProjectNameIdMap = class {
7203
8180
  };
7204
8181
 
7205
8182
  // src/eval-parameters.ts
7206
- var evalParametersSchema = z5.record(
7207
- z5.string(),
7208
- z5.union([
7209
- z5.object({
7210
- type: z5.literal("prompt"),
8183
+ var evalParametersSchema = z9.record(
8184
+ z9.string(),
8185
+ z9.union([
8186
+ z9.object({
8187
+ type: z9.literal("prompt"),
7211
8188
  default: promptDefinitionWithToolsSchema.optional(),
7212
- description: z5.string().optional()
8189
+ description: z9.string().optional()
7213
8190
  }),
7214
- z5.instanceof(z5.ZodType)
8191
+ z9.instanceof(z9.ZodType)
7215
8192
  // For Zod schemas
7216
8193
  ])
7217
8194
  );
@@ -7491,7 +8468,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
7491
8468
  const baseEvent = {
7492
8469
  name: "eval",
7493
8470
  spanAttributes: {
7494
- type: SpanTypeAttribute2.EVAL
8471
+ type: "eval" /* EVAL */
7495
8472
  },
7496
8473
  event: {
7497
8474
  input: datum.input,
@@ -7551,7 +8528,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
7551
8528
  },
7552
8529
  {
7553
8530
  name: "task",
7554
- spanAttributes: { type: SpanTypeAttribute2.TASK },
8531
+ spanAttributes: { type: "task" /* TASK */ },
7555
8532
  event: { input: datum.input }
7556
8533
  }
7557
8534
  );
@@ -7597,17 +8574,17 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
7597
8574
  return rest;
7598
8575
  };
7599
8576
  const resultMetadata = results3.length === 1 ? results3[0].metadata : results3.reduce(
7600
- (prev, s) => mergeDicts2(prev, {
8577
+ (prev, s) => mergeDicts(prev, {
7601
8578
  [s.name]: s.metadata
7602
8579
  }),
7603
8580
  {}
7604
8581
  );
7605
8582
  const resultOutput = results3.length === 1 ? getOtherFields(results3[0]) : results3.reduce(
7606
- (prev, s) => mergeDicts2(prev, { [s.name]: getOtherFields(s) }),
8583
+ (prev, s) => mergeDicts(prev, { [s.name]: getOtherFields(s) }),
7607
8584
  {}
7608
8585
  );
7609
8586
  const scores2 = results3.reduce(
7610
- (prev, s) => mergeDicts2(prev, { [s.name]: s.score }),
8587
+ (prev, s) => mergeDicts(prev, { [s.name]: s.score }),
7611
8588
  {}
7612
8589
  );
7613
8590
  span.log({
@@ -7620,7 +8597,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
7620
8597
  const results2 = await rootSpan.traced(runScorer, {
7621
8598
  name: scorerNames[score_idx],
7622
8599
  spanAttributes: {
7623
- type: SpanTypeAttribute2.SCORE
8600
+ type: "score" /* SCORE */
7624
8601
  },
7625
8602
  event: { input: scoringArgs }
7626
8603
  });
@@ -7838,7 +8815,7 @@ function formatMetricSummary(summary, longestMetricName) {
7838
8815
  }
7839
8816
 
7840
8817
  // dev/errorHandler.ts
7841
- import { z as z6 } from "zod";
8818
+ import { z as z10 } from "zod/v3";
7842
8819
  var errorHandler = (err, req, res, next) => {
7843
8820
  if ("status" in err) {
7844
8821
  res.status(err.status).json({
@@ -7849,7 +8826,7 @@ var errorHandler = (err, req, res, next) => {
7849
8826
  });
7850
8827
  return;
7851
8828
  }
7852
- if (err instanceof z6.ZodError) {
8829
+ if (err instanceof z10.ZodError) {
7853
8830
  res.status(400).json({
7854
8831
  error: {
7855
8832
  message: "Invalid request",
@@ -7873,7 +8850,8 @@ function authorizeRequest(req, res, next) {
7873
8850
  try {
7874
8851
  const ctx = {
7875
8852
  appOrigin: extractAllowedOrigin(req.headers[ORIGIN_HEADER]),
7876
- token: void 0
8853
+ token: void 0,
8854
+ state: void 0
7877
8855
  };
7878
8856
  if (req.headers.authorization || req.headers[BRAINTRUST_AUTH_TOKEN_HEADER]) {
7879
8857
  const tokenText = parseBraintrustAuthHeader(req.headers);
@@ -7888,11 +8866,37 @@ function authorizeRequest(req, res, next) {
7888
8866
  next(e);
7889
8867
  }
7890
8868
  }
7891
- function checkAuthorized(req, res, next) {
7892
- if (!req.ctx?.token) {
7893
- return next(createError(401, "Unauthorized"));
8869
+ var loginCache = new LRUCache({
8870
+ max: 32
8871
+ // TODO: Make this configurable
8872
+ });
8873
+ async function cachedLogin(options) {
8874
+ const key = JSON.stringify(options);
8875
+ const cached = loginCache.get(key);
8876
+ if (cached) {
8877
+ return cached;
7894
8878
  }
7895
- next();
8879
+ const state = await loginToState(options);
8880
+ loginCache.set(key, state);
8881
+ return state;
8882
+ }
8883
+ function makeCheckAuthorized(allowedOrgName) {
8884
+ return async (req, _res, next) => {
8885
+ if (!req.ctx?.token) {
8886
+ return next(createError(401, "Unauthorized"));
8887
+ }
8888
+ try {
8889
+ const state = await cachedLogin({
8890
+ apiKey: req.ctx?.token,
8891
+ orgName: allowedOrgName
8892
+ });
8893
+ req.ctx.state = state;
8894
+ next();
8895
+ } catch (e) {
8896
+ console.error("Authorization error:", e);
8897
+ return next(createError(401, "Unauthorized"));
8898
+ }
8899
+ };
7896
8900
  }
7897
8901
  function parseBraintrustAuthHeader(headers) {
7898
8902
  const tokenString = parseHeader(headers, BRAINTRUST_AUTH_TOKEN_HEADER);
@@ -7977,62 +8981,55 @@ var baseAllowedHeaders = [
7977
8981
  "x-stainless-arch"
7978
8982
  ];
7979
8983
 
7980
- // dev/server.ts
7981
- import {
7982
- BT_CURSOR_HEADER,
7983
- BT_FOUND_EXISTING_HEADER,
7984
- parseParent
7985
- } from "@braintrust/core";
7986
-
7987
8984
  // dev/stream.ts
7988
8985
  function serializeSSEEvent(event) {
7989
8986
  return Object.entries(event).filter(([_key, value]) => value !== void 0).map(([key, value]) => `${key}: ${value}`).join("\n") + "\n\n";
7990
8987
  }
7991
8988
 
7992
8989
  // dev/types.ts
7993
- import { z as z7 } from "zod";
7994
- var evalBodySchema = z7.object({
7995
- name: z7.string(),
7996
- parameters: z7.record(z7.string(), z7.unknown()).nullish(),
8990
+ import { z as z11 } from "zod/v3";
8991
+ var evalBodySchema = z11.object({
8992
+ name: z11.string(),
8993
+ parameters: z11.record(z11.string(), z11.unknown()).nullish(),
7997
8994
  data: RunEval.shape.data,
7998
- scores: z7.array(
7999
- z7.object({
8995
+ scores: z11.array(
8996
+ z11.object({
8000
8997
  function_id: FunctionId,
8001
- name: z7.string()
8998
+ name: z11.string()
8002
8999
  })
8003
9000
  ).nullish(),
8004
- experiment_name: z7.string().nullish(),
8005
- project_id: z7.string().nullish(),
9001
+ experiment_name: z11.string().nullish(),
9002
+ project_id: z11.string().nullish(),
8006
9003
  parent: InvokeParent.optional(),
8007
- stream: z7.boolean().optional()
9004
+ stream: z11.boolean().optional()
8008
9005
  });
8009
- var evalParametersSerializedSchema = z7.record(
8010
- z7.string(),
8011
- z7.union([
8012
- z7.object({
8013
- type: z7.literal("prompt"),
9006
+ var evalParametersSerializedSchema = z11.record(
9007
+ z11.string(),
9008
+ z11.union([
9009
+ z11.object({
9010
+ type: z11.literal("prompt"),
8014
9011
  default: PromptData.optional(),
8015
- description: z7.string().optional()
9012
+ description: z11.string().optional()
8016
9013
  }),
8017
- z7.object({
8018
- type: z7.literal("data"),
8019
- schema: z7.record(z7.unknown()),
9014
+ z11.object({
9015
+ type: z11.literal("data"),
9016
+ schema: z11.record(z11.unknown()),
8020
9017
  // JSON Schema
8021
- default: z7.unknown().optional(),
8022
- description: z7.string().optional()
9018
+ default: z11.unknown().optional(),
9019
+ description: z11.string().optional()
8023
9020
  })
8024
9021
  ])
8025
9022
  );
8026
- var evaluatorDefinitionSchema = z7.object({
9023
+ var evaluatorDefinitionSchema = z11.object({
8027
9024
  parameters: evalParametersSerializedSchema.optional()
8028
9025
  });
8029
- var evaluatorDefinitionsSchema = z7.record(
8030
- z7.string(),
9026
+ var evaluatorDefinitionsSchema = z11.record(
9027
+ z11.string(),
8031
9028
  evaluatorDefinitionSchema
8032
9029
  );
8033
9030
 
8034
9031
  // dev/server.ts
8035
- import { z as z8 } from "zod";
9032
+ import { z as z12 } from "zod/v3";
8036
9033
  import zodToJsonSchema from "zod-to-json-schema";
8037
9034
  function runDevServer(evaluators, opts) {
8038
9035
  const allEvaluators = Object.fromEntries(
@@ -8048,6 +9045,7 @@ function runDevServer(evaluators, opts) {
8048
9045
  }
8049
9046
  next();
8050
9047
  });
9048
+ const checkAuthorized = makeCheckAuthorized(opts.orgName);
8051
9049
  app.use(
8052
9050
  cors({
8053
9051
  origin: checkOrigin,
@@ -8067,7 +9065,7 @@ function runDevServer(evaluators, opts) {
8067
9065
  app.get("/", (req, res) => {
8068
9066
  res.send("Hello, world!");
8069
9067
  });
8070
- app.get("/list", (req, res) => {
9068
+ app.get("/list", checkAuthorized, (req, res) => {
8071
9069
  const evalDefs = Object.fromEntries(
8072
9070
  Object.entries(allEvaluators).map(([name, evaluator]) => [
8073
9071
  name,
@@ -8095,7 +9093,11 @@ function runDevServer(evaluators, opts) {
8095
9093
  scores,
8096
9094
  stream
8097
9095
  } = evalBodySchema.parse(req.body);
8098
- const state = await cachedLogin({ apiKey: req.ctx?.token });
9096
+ if (!req.ctx?.state) {
9097
+ res.status(500).json({ error: "Braintrust state not initialized in request" });
9098
+ return;
9099
+ }
9100
+ const state = req.ctx.state;
8099
9101
  const evaluator = allEvaluators[name];
8100
9102
  if (!evaluator) {
8101
9103
  res.status(404).json({ error: `Evaluator '${name}' not found` });
@@ -8112,7 +9114,7 @@ function runDevServer(evaluators, opts) {
8112
9114
  validateParameters(parameters ?? {}, evaluator.parameters);
8113
9115
  } catch (e) {
8114
9116
  console.error("Error validating parameters", e);
8115
- if (e instanceof z8.ZodError || e instanceof Error) {
9117
+ if (e instanceof z12.ZodError || e instanceof Error) {
8116
9118
  res.status(400).json({
8117
9119
  error: e.message
8118
9120
  });
@@ -8233,20 +9235,6 @@ function runDevServer(evaluators, opts) {
8233
9235
  var asyncHandler = (fn) => (req, res, next) => {
8234
9236
  Promise.resolve(fn(req, res, next)).catch(next);
8235
9237
  };
8236
- var loginCache = new LRUCache({
8237
- max: 32
8238
- // TODO: Make this configurable
8239
- });
8240
- async function cachedLogin(options) {
8241
- const key = JSON.stringify(options);
8242
- const cached = loginCache.get(key);
8243
- if (cached) {
8244
- return cached;
8245
- }
8246
- const state = await loginToState(options);
8247
- loginCache.set(key, state);
8248
- return state;
8249
- }
8250
9238
  async function getDataset(state, data) {
8251
9239
  if ("project_name" in data) {
8252
9240
  return initDataset({
@@ -8270,9 +9258,9 @@ async function getDataset(state, data) {
8270
9258
  return data.data;
8271
9259
  }
8272
9260
  }
8273
- var datasetFetchSchema = z8.object({
8274
- project_id: z8.string(),
8275
- name: z8.string()
9261
+ var datasetFetchSchema = z12.object({
9262
+ project_id: z12.string(),
9263
+ name: z12.string()
8276
9264
  });
8277
9265
  async function getDatasetById({
8278
9266
  state,
@@ -8281,7 +9269,7 @@ async function getDatasetById({
8281
9269
  const dataset = await state.appConn().post_json("api/dataset/get", {
8282
9270
  id: datasetId
8283
9271
  });
8284
- const parsed = z8.array(datasetFetchSchema).parse(dataset);
9272
+ const parsed = z12.array(datasetFetchSchema).parse(dataset);
8285
9273
  if (parsed.length === 0) {
8286
9274
  throw new Error(`Dataset '${datasetId}' not found`);
8287
9275
  }