braintrust 0.3.6 → 0.3.8
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.
- package/dev/dist/index.d.mts +234 -16
- package/dev/dist/index.d.ts +234 -16
- package/dev/dist/index.js +2192 -1134
- package/dev/dist/index.mjs +2148 -1090
- package/dist/browser.d.mts +339 -39
- package/dist/browser.d.ts +339 -39
- package/dist/browser.js +2170 -1114
- package/dist/browser.mjs +2105 -1049
- package/dist/cli.js +2326 -1219
- package/dist/index.d.mts +403 -28
- package/dist/index.d.ts +403 -28
- package/dist/index.js +2799 -1233
- package/dist/index.mjs +2711 -1145
- package/package.json +15 -9
- package/util/dist/index.d.mts +5229 -0
- package/util/dist/index.d.ts +5229 -0
- package/util/dist/index.js +1264 -0
- package/util/dist/index.mjs +1264 -0
package/dist/index.mjs
CHANGED
|
@@ -481,15 +481,15 @@ function mergeTwoObjects(one, two, level = 0, objects) {
|
|
|
481
481
|
for (let i = 0, j = two.length; i < j; i++) {
|
|
482
482
|
result.push(takeValue(two[i]));
|
|
483
483
|
}
|
|
484
|
-
} else if (
|
|
484
|
+
} else if (isObject2(two)) {
|
|
485
485
|
const keys = Object.keys(two);
|
|
486
486
|
for (let i = 0, j = keys.length; i < j; i++) {
|
|
487
487
|
const key = keys[i];
|
|
488
488
|
result[key] = takeValue(two[key]);
|
|
489
489
|
}
|
|
490
490
|
}
|
|
491
|
-
} else if (
|
|
492
|
-
if (
|
|
491
|
+
} else if (isObject2(one)) {
|
|
492
|
+
if (isObject2(two)) {
|
|
493
493
|
if (!shouldMerge(one, two)) {
|
|
494
494
|
return two;
|
|
495
495
|
}
|
|
@@ -510,7 +510,7 @@ function mergeTwoObjects(one, two, level = 0, objects) {
|
|
|
510
510
|
if (wasObjectReferenced(one, key, objects) || wasObjectReferenced(two, key, objects)) {
|
|
511
511
|
delete result[key];
|
|
512
512
|
} else {
|
|
513
|
-
if (
|
|
513
|
+
if (isObject2(obj1) && isObject2(obj2)) {
|
|
514
514
|
const arr1 = objects.get(obj1) || [];
|
|
515
515
|
const arr2 = objects.get(obj2) || [];
|
|
516
516
|
arr1.push({ obj: one, key });
|
|
@@ -544,7 +544,7 @@ function isArray2(value) {
|
|
|
544
544
|
function isFunction(value) {
|
|
545
545
|
return typeof value === "function";
|
|
546
546
|
}
|
|
547
|
-
function
|
|
547
|
+
function isObject2(value) {
|
|
548
548
|
return !isPrimitive(value) && !isArray2(value) && !isFunction(value) && typeof value === "object";
|
|
549
549
|
}
|
|
550
550
|
function isPrimitive(value) {
|
|
@@ -3498,33 +3498,999 @@ var Queue = class {
|
|
|
3498
3498
|
}
|
|
3499
3499
|
};
|
|
3500
3500
|
|
|
3501
|
-
//
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3501
|
+
// util/db_fields.ts
|
|
3502
|
+
var TRANSACTION_ID_FIELD = "_xact_id";
|
|
3503
|
+
var IS_MERGE_FIELD = "_is_merge";
|
|
3504
|
+
var AUDIT_SOURCE_FIELD = "_audit_source";
|
|
3505
|
+
var AUDIT_METADATA_FIELD = "_audit_metadata";
|
|
3506
|
+
var VALID_SOURCES = ["app", "api", "external"];
|
|
3507
|
+
var PARENT_ID_FIELD = "_parent_id";
|
|
3508
|
+
|
|
3509
|
+
// util/span_identifier_v3.ts
|
|
3510
|
+
import * as uuid3 from "uuid";
|
|
3511
|
+
|
|
3512
|
+
// util/span_identifier_v2.ts
|
|
3513
|
+
import * as uuid2 from "uuid";
|
|
3514
|
+
|
|
3515
|
+
// util/span_identifier_v1.ts
|
|
3516
|
+
import * as uuid from "uuid";
|
|
3517
|
+
import { z } from "zod/v3";
|
|
3518
|
+
function tryMakeUuid(s) {
|
|
3519
|
+
try {
|
|
3520
|
+
const ret = uuid.parse(s);
|
|
3521
|
+
if (ret.length !== 16) {
|
|
3522
|
+
throw new Error();
|
|
3523
|
+
}
|
|
3524
|
+
return { bytes: Buffer.from(ret), isUUID: true };
|
|
3525
|
+
} catch (e) {
|
|
3526
|
+
return { bytes: Buffer.from(s, "utf-8"), isUUID: false };
|
|
3527
|
+
}
|
|
3528
|
+
}
|
|
3529
|
+
var ENCODING_VERSION_NUMBER = 1;
|
|
3530
|
+
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";
|
|
3531
|
+
var SpanObjectTypeV1 = /* @__PURE__ */ ((SpanObjectTypeV12) => {
|
|
3532
|
+
SpanObjectTypeV12[SpanObjectTypeV12["EXPERIMENT"] = 1] = "EXPERIMENT";
|
|
3533
|
+
SpanObjectTypeV12[SpanObjectTypeV12["PROJECT_LOGS"] = 2] = "PROJECT_LOGS";
|
|
3534
|
+
return SpanObjectTypeV12;
|
|
3535
|
+
})(SpanObjectTypeV1 || {});
|
|
3536
|
+
var SpanObjectTypeV1EnumSchema = z.nativeEnum(SpanObjectTypeV1);
|
|
3537
|
+
var SpanRowIdsV1 = class {
|
|
3538
|
+
rowId;
|
|
3539
|
+
spanId;
|
|
3540
|
+
rootSpanId;
|
|
3541
|
+
constructor(args) {
|
|
3542
|
+
this.rowId = args.rowId;
|
|
3543
|
+
this.spanId = args.spanId;
|
|
3544
|
+
this.rootSpanId = args.rootSpanId;
|
|
3545
|
+
if (!this.rowId) {
|
|
3546
|
+
throw new Error("rowId must be nonempty string");
|
|
3547
|
+
}
|
|
3548
|
+
if (!this.spanId) {
|
|
3549
|
+
throw new Error("spanId must be nonempty string");
|
|
3550
|
+
}
|
|
3551
|
+
if (!this.rootSpanId) {
|
|
3552
|
+
throw new Error("rootSpanId must be nonempty string");
|
|
3553
|
+
}
|
|
3554
|
+
}
|
|
3555
|
+
toObject() {
|
|
3556
|
+
return {
|
|
3557
|
+
rowId: this.rowId,
|
|
3558
|
+
spanId: this.spanId,
|
|
3559
|
+
rootSpanId: this.rootSpanId
|
|
3560
|
+
};
|
|
3561
|
+
}
|
|
3562
|
+
};
|
|
3563
|
+
var SpanComponentsV1 = class _SpanComponentsV1 {
|
|
3564
|
+
objectType;
|
|
3565
|
+
objectId;
|
|
3566
|
+
rowIds;
|
|
3567
|
+
constructor(args) {
|
|
3568
|
+
this.objectType = args.objectType;
|
|
3569
|
+
this.objectId = args.objectId;
|
|
3570
|
+
this.rowIds = args.rowIds;
|
|
3571
|
+
}
|
|
3572
|
+
toStr() {
|
|
3573
|
+
const allBuffers = [];
|
|
3574
|
+
const { bytes: rowIdBytes, isUUID: rowIdIsUUID } = this.rowIds ? tryMakeUuid(this.rowIds.rowId) : { bytes: Buffer.from(""), isUUID: false };
|
|
3575
|
+
allBuffers.push(
|
|
3576
|
+
Buffer.from([
|
|
3577
|
+
ENCODING_VERSION_NUMBER,
|
|
3578
|
+
this.objectType,
|
|
3579
|
+
this.rowIds ? 1 : 0,
|
|
3580
|
+
rowIdIsUUID ? 1 : 0
|
|
3581
|
+
])
|
|
3582
|
+
);
|
|
3583
|
+
const { bytes: objectIdBytes, isUUID: objectIdIsUUID } = tryMakeUuid(
|
|
3584
|
+
this.objectId
|
|
3585
|
+
);
|
|
3586
|
+
if (!objectIdIsUUID) {
|
|
3587
|
+
throw new Error("object_id component must be a valid UUID");
|
|
3588
|
+
}
|
|
3589
|
+
allBuffers.push(objectIdBytes);
|
|
3590
|
+
if (this.rowIds) {
|
|
3591
|
+
const { bytes: spanIdBytes, isUUID: spanIdIsUUID } = tryMakeUuid(
|
|
3592
|
+
this.rowIds.spanId
|
|
3593
|
+
);
|
|
3594
|
+
if (!spanIdIsUUID) {
|
|
3595
|
+
throw new Error("span_id component must be a valid UUID");
|
|
3596
|
+
}
|
|
3597
|
+
const { bytes: rootSpanIdBytes, isUUID: rootSpanIdIsUUID } = tryMakeUuid(
|
|
3598
|
+
this.rowIds.rootSpanId
|
|
3599
|
+
);
|
|
3600
|
+
if (!rootSpanIdIsUUID) {
|
|
3601
|
+
throw new Error("root_span_id component must be a valid UUID");
|
|
3602
|
+
}
|
|
3603
|
+
allBuffers.push(spanIdBytes, rootSpanIdBytes, rowIdBytes);
|
|
3604
|
+
}
|
|
3605
|
+
return Buffer.concat(allBuffers).toString("base64");
|
|
3606
|
+
}
|
|
3607
|
+
static fromStr(s) {
|
|
3608
|
+
try {
|
|
3609
|
+
const rawBytes = Buffer.from(s, "base64");
|
|
3610
|
+
if (rawBytes[0] !== ENCODING_VERSION_NUMBER) {
|
|
3611
|
+
throw new Error();
|
|
3612
|
+
}
|
|
3613
|
+
const objectType = SpanObjectTypeV1EnumSchema.parse(rawBytes[1]);
|
|
3614
|
+
if (![0, 1].includes(rawBytes[2])) {
|
|
3615
|
+
throw new Error();
|
|
3616
|
+
}
|
|
3617
|
+
if (![0, 1].includes(rawBytes[3])) {
|
|
3618
|
+
throw new Error();
|
|
3619
|
+
}
|
|
3620
|
+
const hasRowId = rawBytes[2] == 1;
|
|
3621
|
+
const rowIdIsUUID = rawBytes[3] == 1;
|
|
3622
|
+
const objectId = uuid.stringify(rawBytes.subarray(4, 20));
|
|
3623
|
+
const rowIds = (() => {
|
|
3624
|
+
if (!hasRowId) {
|
|
3625
|
+
return void 0;
|
|
3626
|
+
}
|
|
3627
|
+
const spanId = uuid.stringify(rawBytes.subarray(20, 36));
|
|
3628
|
+
const rootSpanId = uuid.stringify(rawBytes.subarray(36, 52));
|
|
3629
|
+
const rowId = rowIdIsUUID ? uuid.stringify(rawBytes.subarray(52)) : rawBytes.subarray(52).toString("utf-8");
|
|
3630
|
+
return new SpanRowIdsV1({ rowId, spanId, rootSpanId });
|
|
3631
|
+
})();
|
|
3632
|
+
return new _SpanComponentsV1({ objectType, objectId, rowIds });
|
|
3633
|
+
} catch (e) {
|
|
3634
|
+
throw new Error(INVALID_ENCODING_ERRMSG);
|
|
3635
|
+
}
|
|
3636
|
+
}
|
|
3637
|
+
objectIdFields() {
|
|
3638
|
+
switch (this.objectType) {
|
|
3639
|
+
case 1 /* EXPERIMENT */:
|
|
3640
|
+
return { experiment_id: this.objectId };
|
|
3641
|
+
case 2 /* PROJECT_LOGS */:
|
|
3642
|
+
return { project_id: this.objectId, log_id: "g" };
|
|
3643
|
+
default:
|
|
3644
|
+
throw new Error("Impossible");
|
|
3645
|
+
}
|
|
3646
|
+
}
|
|
3647
|
+
toObject() {
|
|
3648
|
+
return {
|
|
3649
|
+
objectType: this.objectType,
|
|
3650
|
+
objectId: this.objectId,
|
|
3651
|
+
rowIds: this.rowIds?.toObject()
|
|
3652
|
+
};
|
|
3653
|
+
}
|
|
3654
|
+
};
|
|
3655
|
+
|
|
3656
|
+
// util/span_identifier_v2.ts
|
|
3657
|
+
import { z as z2 } from "zod/v3";
|
|
3658
|
+
function tryMakeUuid2(s) {
|
|
3659
|
+
try {
|
|
3660
|
+
const ret = uuid2.parse(s);
|
|
3661
|
+
if (ret.length !== 16) {
|
|
3662
|
+
throw new Error();
|
|
3663
|
+
}
|
|
3664
|
+
return { bytes: Buffer.from(ret), isUUID: true };
|
|
3665
|
+
} catch (e) {
|
|
3666
|
+
return { bytes: Buffer.from(s, "utf-8"), isUUID: false };
|
|
3667
|
+
}
|
|
3668
|
+
}
|
|
3669
|
+
var ENCODING_VERSION_NUMBER2 = 2;
|
|
3670
|
+
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.`;
|
|
3671
|
+
var INTEGER_ENCODING_NUM_BYTES = 4;
|
|
3672
|
+
var SpanObjectTypeV2 = /* @__PURE__ */ ((SpanObjectTypeV22) => {
|
|
3673
|
+
SpanObjectTypeV22[SpanObjectTypeV22["EXPERIMENT"] = 1] = "EXPERIMENT";
|
|
3674
|
+
SpanObjectTypeV22[SpanObjectTypeV22["PROJECT_LOGS"] = 2] = "PROJECT_LOGS";
|
|
3675
|
+
return SpanObjectTypeV22;
|
|
3676
|
+
})(SpanObjectTypeV2 || {});
|
|
3677
|
+
var SpanObjectTypeV2EnumSchema = z2.nativeEnum(SpanObjectTypeV2);
|
|
3678
|
+
var SpanRowIdsV2 = class {
|
|
3679
|
+
rowId;
|
|
3680
|
+
spanId;
|
|
3681
|
+
rootSpanId;
|
|
3682
|
+
constructor(args) {
|
|
3683
|
+
this.rowId = args.rowId;
|
|
3684
|
+
this.spanId = args.spanId;
|
|
3685
|
+
this.rootSpanId = args.rootSpanId;
|
|
3686
|
+
if (!this.rowId) {
|
|
3687
|
+
throw new Error("rowId must be nonempty string");
|
|
3688
|
+
}
|
|
3689
|
+
if (!this.spanId) {
|
|
3690
|
+
throw new Error("spanId must be nonempty string");
|
|
3691
|
+
}
|
|
3692
|
+
if (!this.rootSpanId) {
|
|
3693
|
+
throw new Error("rootSpanId must be nonempty string");
|
|
3694
|
+
}
|
|
3695
|
+
}
|
|
3696
|
+
toObject() {
|
|
3697
|
+
return {
|
|
3698
|
+
rowId: this.rowId,
|
|
3699
|
+
spanId: this.spanId,
|
|
3700
|
+
rootSpanId: this.rootSpanId
|
|
3701
|
+
};
|
|
3702
|
+
}
|
|
3703
|
+
};
|
|
3704
|
+
var SpanComponentsV2 = class _SpanComponentsV2 {
|
|
3705
|
+
objectType;
|
|
3706
|
+
objectId;
|
|
3707
|
+
computeObjectMetadataArgs;
|
|
3708
|
+
rowIds;
|
|
3709
|
+
constructor(args) {
|
|
3710
|
+
this.objectType = args.objectType;
|
|
3711
|
+
this.objectId = args.objectId;
|
|
3712
|
+
this.computeObjectMetadataArgs = args.computeObjectMetadataArgs;
|
|
3713
|
+
this.rowIds = args.rowIds;
|
|
3714
|
+
if (!(this.objectId || this.computeObjectMetadataArgs)) {
|
|
3715
|
+
throw new Error(
|
|
3716
|
+
"Must provide either objectId or computeObjectMetadataArgs"
|
|
3717
|
+
);
|
|
3718
|
+
}
|
|
3719
|
+
}
|
|
3720
|
+
toStr() {
|
|
3721
|
+
const allBuffers = [];
|
|
3722
|
+
const { bytes: rowIdBytes, isUUID: rowIdIsUUID } = this.rowIds ? tryMakeUuid2(this.rowIds.rowId) : { bytes: Buffer.from(""), isUUID: false };
|
|
3723
|
+
allBuffers.push(
|
|
3724
|
+
Buffer.from([
|
|
3725
|
+
ENCODING_VERSION_NUMBER2,
|
|
3726
|
+
this.objectType,
|
|
3727
|
+
this.objectId ? 1 : 0,
|
|
3728
|
+
this.computeObjectMetadataArgs ? 1 : 0,
|
|
3729
|
+
this.rowIds ? 1 : 0,
|
|
3730
|
+
rowIdIsUUID ? 1 : 0
|
|
3731
|
+
])
|
|
3732
|
+
);
|
|
3733
|
+
if (this.objectId) {
|
|
3734
|
+
const { bytes: objectIdBytes, isUUID: objectIdIsUUID } = tryMakeUuid2(
|
|
3735
|
+
this.objectId
|
|
3736
|
+
);
|
|
3737
|
+
if (!objectIdIsUUID) {
|
|
3738
|
+
throw new Error("object_id component must be a valid UUID");
|
|
3739
|
+
}
|
|
3740
|
+
allBuffers.push(objectIdBytes);
|
|
3741
|
+
}
|
|
3742
|
+
if (this.computeObjectMetadataArgs) {
|
|
3743
|
+
const computeObjectMetadataBytes = Buffer.from(
|
|
3744
|
+
JSON.stringify(this.computeObjectMetadataArgs),
|
|
3745
|
+
"utf-8"
|
|
3746
|
+
);
|
|
3747
|
+
const serializedLenBytes = Buffer.alloc(INTEGER_ENCODING_NUM_BYTES);
|
|
3748
|
+
serializedLenBytes.writeInt32BE(computeObjectMetadataBytes.length);
|
|
3749
|
+
allBuffers.push(serializedLenBytes, computeObjectMetadataBytes);
|
|
3750
|
+
}
|
|
3751
|
+
if (this.rowIds) {
|
|
3752
|
+
const { bytes: spanIdBytes, isUUID: spanIdIsUUID } = tryMakeUuid2(
|
|
3753
|
+
this.rowIds.spanId
|
|
3754
|
+
);
|
|
3755
|
+
if (!spanIdIsUUID) {
|
|
3756
|
+
throw new Error("span_id component must be a valid UUID");
|
|
3757
|
+
}
|
|
3758
|
+
const { bytes: rootSpanIdBytes, isUUID: rootSpanIdIsUUID } = tryMakeUuid2(
|
|
3759
|
+
this.rowIds.rootSpanId
|
|
3760
|
+
);
|
|
3761
|
+
if (!rootSpanIdIsUUID) {
|
|
3762
|
+
throw new Error("root_span_id component must be a valid UUID");
|
|
3763
|
+
}
|
|
3764
|
+
allBuffers.push(spanIdBytes, rootSpanIdBytes, rowIdBytes);
|
|
3765
|
+
}
|
|
3766
|
+
return Buffer.concat(allBuffers).toString("base64");
|
|
3767
|
+
}
|
|
3768
|
+
static fromStr(s) {
|
|
3769
|
+
try {
|
|
3770
|
+
const rawBytes = Buffer.from(s, "base64");
|
|
3771
|
+
if (rawBytes[0] < ENCODING_VERSION_NUMBER2) {
|
|
3772
|
+
const spanComponentsOld = SpanComponentsV1.fromStr(s);
|
|
3773
|
+
return new _SpanComponentsV2({
|
|
3774
|
+
objectType: SpanObjectTypeV2EnumSchema.parse(
|
|
3775
|
+
spanComponentsOld.objectType
|
|
3776
|
+
),
|
|
3777
|
+
objectId: spanComponentsOld.objectId,
|
|
3778
|
+
rowIds: spanComponentsOld.rowIds ? new SpanRowIdsV2({
|
|
3779
|
+
rowId: spanComponentsOld.rowIds.rowId,
|
|
3780
|
+
spanId: spanComponentsOld.rowIds.spanId,
|
|
3781
|
+
rootSpanId: spanComponentsOld.rowIds.rootSpanId
|
|
3782
|
+
}) : void 0
|
|
3783
|
+
});
|
|
3784
|
+
}
|
|
3785
|
+
if (rawBytes[0] !== ENCODING_VERSION_NUMBER2) {
|
|
3786
|
+
throw new Error();
|
|
3787
|
+
}
|
|
3788
|
+
const objectType = SpanObjectTypeV2EnumSchema.parse(rawBytes[1]);
|
|
3789
|
+
for (let i = 2; i < 6; ++i) {
|
|
3790
|
+
if (![0, 1].includes(rawBytes[i])) {
|
|
3791
|
+
throw new Error();
|
|
3792
|
+
}
|
|
3793
|
+
}
|
|
3794
|
+
const hasObjectId = rawBytes[2] == 1;
|
|
3795
|
+
const hasComputeObjectMetadataArgs = rawBytes[3] == 1;
|
|
3796
|
+
const hasRowId = rawBytes[4] == 1;
|
|
3797
|
+
const rowIdIsUUID = rawBytes[5] == 1;
|
|
3798
|
+
let byteCursor = 6;
|
|
3799
|
+
let objectId = void 0;
|
|
3800
|
+
if (hasObjectId) {
|
|
3801
|
+
const nextByteCursor = byteCursor + 16;
|
|
3802
|
+
objectId = uuid2.stringify(
|
|
3803
|
+
rawBytes.subarray(byteCursor, nextByteCursor)
|
|
3804
|
+
);
|
|
3805
|
+
byteCursor = nextByteCursor;
|
|
3806
|
+
}
|
|
3807
|
+
let computeObjectMetadataArgs;
|
|
3808
|
+
if (hasComputeObjectMetadataArgs) {
|
|
3809
|
+
let nextByteCursor = byteCursor + INTEGER_ENCODING_NUM_BYTES;
|
|
3810
|
+
const serializedLenBytes = rawBytes.readInt32BE(byteCursor);
|
|
3811
|
+
byteCursor = nextByteCursor;
|
|
3812
|
+
nextByteCursor = byteCursor + serializedLenBytes;
|
|
3813
|
+
computeObjectMetadataArgs = JSON.parse(
|
|
3814
|
+
rawBytes.subarray(byteCursor, nextByteCursor).toString("utf-8")
|
|
3815
|
+
);
|
|
3816
|
+
byteCursor = nextByteCursor;
|
|
3817
|
+
}
|
|
3818
|
+
const rowIds = (() => {
|
|
3819
|
+
if (!hasRowId) {
|
|
3820
|
+
return void 0;
|
|
3821
|
+
}
|
|
3822
|
+
let nextByteCursor = byteCursor + 16;
|
|
3823
|
+
const spanId = uuid2.stringify(
|
|
3824
|
+
rawBytes.subarray(byteCursor, nextByteCursor)
|
|
3825
|
+
);
|
|
3826
|
+
byteCursor = nextByteCursor;
|
|
3827
|
+
nextByteCursor = byteCursor + 16;
|
|
3828
|
+
const rootSpanId = uuid2.stringify(
|
|
3829
|
+
rawBytes.subarray(byteCursor, nextByteCursor)
|
|
3830
|
+
);
|
|
3831
|
+
byteCursor = nextByteCursor;
|
|
3832
|
+
const rowId = rowIdIsUUID ? uuid2.stringify(rawBytes.subarray(byteCursor)) : rawBytes.subarray(byteCursor).toString("utf-8");
|
|
3833
|
+
return new SpanRowIdsV2({ rowId, spanId, rootSpanId });
|
|
3834
|
+
})();
|
|
3835
|
+
return new _SpanComponentsV2({
|
|
3836
|
+
objectType,
|
|
3837
|
+
objectId,
|
|
3838
|
+
computeObjectMetadataArgs,
|
|
3839
|
+
rowIds
|
|
3840
|
+
});
|
|
3841
|
+
} catch (e) {
|
|
3842
|
+
throw new Error(INVALID_ENCODING_ERRMSG2);
|
|
3843
|
+
}
|
|
3844
|
+
}
|
|
3845
|
+
objectIdFields() {
|
|
3846
|
+
if (!this.objectId) {
|
|
3847
|
+
throw new Error(
|
|
3848
|
+
"Impossible: cannot invoke `object_id_fields` unless SpanComponentsV2 is initialized with an `object_id`"
|
|
3849
|
+
);
|
|
3850
|
+
}
|
|
3851
|
+
switch (this.objectType) {
|
|
3852
|
+
case 1 /* EXPERIMENT */:
|
|
3853
|
+
return { experiment_id: this.objectId };
|
|
3854
|
+
case 2 /* PROJECT_LOGS */:
|
|
3855
|
+
return { project_id: this.objectId, log_id: "g" };
|
|
3856
|
+
default:
|
|
3857
|
+
throw new Error("Impossible");
|
|
3858
|
+
}
|
|
3859
|
+
}
|
|
3860
|
+
toObject() {
|
|
3861
|
+
return {
|
|
3862
|
+
objectType: this.objectType,
|
|
3863
|
+
objectId: this.objectId,
|
|
3864
|
+
computeObjectMetadataArgs: this.computeObjectMetadataArgs,
|
|
3865
|
+
rowIds: this.rowIds?.toObject()
|
|
3866
|
+
};
|
|
3867
|
+
}
|
|
3868
|
+
};
|
|
3869
|
+
|
|
3870
|
+
// util/span_identifier_v3.ts
|
|
3871
|
+
import { z as z3 } from "zod/v3";
|
|
3872
|
+
|
|
3873
|
+
// util/bytes.ts
|
|
3874
|
+
function concatUint8Arrays(...arrays) {
|
|
3875
|
+
const totalLength = arrays.reduce((acc, arr) => acc + arr.length, 0);
|
|
3876
|
+
const result = new Uint8Array(totalLength);
|
|
3877
|
+
let offset = 0;
|
|
3878
|
+
for (const arr of arrays) {
|
|
3879
|
+
result.set(arr, offset);
|
|
3880
|
+
offset += arr.length;
|
|
3881
|
+
}
|
|
3882
|
+
return result;
|
|
3883
|
+
}
|
|
3884
|
+
function uint8ArrayToBase64(uint8Array) {
|
|
3885
|
+
let binary = "";
|
|
3886
|
+
for (let i = 0; i < uint8Array.length; i++) {
|
|
3887
|
+
binary += String.fromCharCode(uint8Array[i]);
|
|
3888
|
+
}
|
|
3889
|
+
return btoa(binary);
|
|
3890
|
+
}
|
|
3891
|
+
function base64ToUint8Array(base64) {
|
|
3892
|
+
const binary = atob(base64);
|
|
3893
|
+
const uint8Array = new Uint8Array(binary.length);
|
|
3894
|
+
for (let i = 0; i < binary.length; i++) {
|
|
3895
|
+
uint8Array[i] = binary.charCodeAt(i);
|
|
3896
|
+
}
|
|
3897
|
+
return uint8Array;
|
|
3898
|
+
}
|
|
3899
|
+
function uint8ArrayToString(uint8Array) {
|
|
3900
|
+
const decoder = new TextDecoder("utf-8");
|
|
3901
|
+
return decoder.decode(uint8Array);
|
|
3902
|
+
}
|
|
3903
|
+
function stringToUint8Array(str) {
|
|
3904
|
+
const encoder = new TextEncoder();
|
|
3905
|
+
return encoder.encode(str);
|
|
3906
|
+
}
|
|
3907
|
+
|
|
3908
|
+
// util/span_identifier_v3.ts
|
|
3909
|
+
function tryMakeUuid3(s) {
|
|
3910
|
+
try {
|
|
3911
|
+
const ret = uuid3.parse(s);
|
|
3912
|
+
if (ret.length !== 16) {
|
|
3913
|
+
throw new Error();
|
|
3914
|
+
}
|
|
3915
|
+
return { bytes: new Uint8Array(ret), isUUID: true };
|
|
3916
|
+
} catch {
|
|
3917
|
+
return { bytes: void 0, isUUID: false };
|
|
3918
|
+
}
|
|
3919
|
+
}
|
|
3920
|
+
var ENCODING_VERSION_NUMBER3 = 3;
|
|
3921
|
+
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.`;
|
|
3922
|
+
var SpanObjectTypeV3 = /* @__PURE__ */ ((SpanObjectTypeV32) => {
|
|
3923
|
+
SpanObjectTypeV32[SpanObjectTypeV32["EXPERIMENT"] = 1] = "EXPERIMENT";
|
|
3924
|
+
SpanObjectTypeV32[SpanObjectTypeV32["PROJECT_LOGS"] = 2] = "PROJECT_LOGS";
|
|
3925
|
+
SpanObjectTypeV32[SpanObjectTypeV32["PLAYGROUND_LOGS"] = 3] = "PLAYGROUND_LOGS";
|
|
3926
|
+
return SpanObjectTypeV32;
|
|
3927
|
+
})(SpanObjectTypeV3 || {});
|
|
3928
|
+
var spanObjectTypeV3EnumSchema = z3.nativeEnum(SpanObjectTypeV3);
|
|
3929
|
+
function spanObjectTypeV3ToString(objectType) {
|
|
3930
|
+
switch (objectType) {
|
|
3931
|
+
case 1 /* EXPERIMENT */:
|
|
3932
|
+
return "experiment";
|
|
3933
|
+
case 2 /* PROJECT_LOGS */:
|
|
3934
|
+
return "project_logs";
|
|
3935
|
+
case 3 /* PLAYGROUND_LOGS */:
|
|
3936
|
+
return "playground_logs";
|
|
3937
|
+
default:
|
|
3938
|
+
const x = objectType;
|
|
3939
|
+
throw new Error(`Unknown SpanObjectTypeV3: ${x}`);
|
|
3940
|
+
}
|
|
3941
|
+
}
|
|
3942
|
+
var InternalSpanComponentUUIDFields = /* @__PURE__ */ ((InternalSpanComponentUUIDFields2) => {
|
|
3943
|
+
InternalSpanComponentUUIDFields2[InternalSpanComponentUUIDFields2["OBJECT_ID"] = 1] = "OBJECT_ID";
|
|
3944
|
+
InternalSpanComponentUUIDFields2[InternalSpanComponentUUIDFields2["ROW_ID"] = 2] = "ROW_ID";
|
|
3945
|
+
InternalSpanComponentUUIDFields2[InternalSpanComponentUUIDFields2["SPAN_ID"] = 3] = "SPAN_ID";
|
|
3946
|
+
InternalSpanComponentUUIDFields2[InternalSpanComponentUUIDFields2["ROOT_SPAN_ID"] = 4] = "ROOT_SPAN_ID";
|
|
3947
|
+
return InternalSpanComponentUUIDFields2;
|
|
3948
|
+
})(InternalSpanComponentUUIDFields || {});
|
|
3949
|
+
var internalSpanComponentUUIDFieldsEnumSchema = z3.nativeEnum(
|
|
3950
|
+
InternalSpanComponentUUIDFields
|
|
3951
|
+
);
|
|
3952
|
+
var _INTERNAL_SPAN_COMPONENT_UUID_FIELDS_ID_TO_NAME = {
|
|
3953
|
+
[1 /* OBJECT_ID */]: "object_id",
|
|
3954
|
+
[2 /* ROW_ID */]: "row_id",
|
|
3955
|
+
[3 /* SPAN_ID */]: "span_id",
|
|
3956
|
+
[4 /* ROOT_SPAN_ID */]: "root_span_id"
|
|
3957
|
+
};
|
|
3958
|
+
var spanComponentsV3Schema = z3.object({
|
|
3959
|
+
object_type: spanObjectTypeV3EnumSchema,
|
|
3960
|
+
// TODO(manu): We should have a more elaborate zod schema for
|
|
3961
|
+
// `propagated_event`. This will required zod-ifying the contents of
|
|
3962
|
+
// sdk/js/util/object.ts.
|
|
3963
|
+
propagated_event: z3.record(z3.unknown()).nullish()
|
|
3964
|
+
}).and(
|
|
3965
|
+
z3.union([
|
|
3966
|
+
// Must provide one or the other.
|
|
3967
|
+
z3.object({
|
|
3968
|
+
object_id: z3.string().nullish(),
|
|
3969
|
+
compute_object_metadata_args: z3.optional(z3.null())
|
|
3970
|
+
}),
|
|
3971
|
+
z3.object({
|
|
3972
|
+
object_id: z3.optional(z3.null()),
|
|
3973
|
+
compute_object_metadata_args: z3.record(z3.unknown())
|
|
3974
|
+
})
|
|
3975
|
+
])
|
|
3976
|
+
).and(
|
|
3977
|
+
z3.union([
|
|
3978
|
+
// Either all of these must be provided or none.
|
|
3979
|
+
z3.object({
|
|
3980
|
+
row_id: z3.string(),
|
|
3981
|
+
span_id: z3.string(),
|
|
3982
|
+
root_span_id: z3.string()
|
|
3983
|
+
}),
|
|
3984
|
+
z3.object({
|
|
3985
|
+
row_id: z3.optional(z3.null()),
|
|
3986
|
+
span_id: z3.optional(z3.null()),
|
|
3987
|
+
root_span_id: z3.optional(z3.null())
|
|
3988
|
+
})
|
|
3989
|
+
])
|
|
3990
|
+
);
|
|
3991
|
+
var SpanComponentsV3 = class _SpanComponentsV3 {
|
|
3992
|
+
constructor(data) {
|
|
3993
|
+
this.data = data;
|
|
3994
|
+
}
|
|
3995
|
+
toStr() {
|
|
3996
|
+
const jsonObj = {
|
|
3997
|
+
compute_object_metadata_args: this.data.compute_object_metadata_args || void 0,
|
|
3998
|
+
propagated_event: this.data.propagated_event || void 0
|
|
3999
|
+
};
|
|
4000
|
+
const allBuffers = [];
|
|
4001
|
+
allBuffers.push(
|
|
4002
|
+
new Uint8Array([ENCODING_VERSION_NUMBER3, this.data.object_type])
|
|
4003
|
+
);
|
|
4004
|
+
const uuidEntries = [];
|
|
4005
|
+
function addUuidField(origVal, fieldId) {
|
|
4006
|
+
const ret = tryMakeUuid3(origVal);
|
|
4007
|
+
if (ret.isUUID) {
|
|
4008
|
+
uuidEntries.push(
|
|
4009
|
+
concatUint8Arrays(new Uint8Array([fieldId]), ret.bytes)
|
|
4010
|
+
);
|
|
4011
|
+
} else {
|
|
4012
|
+
jsonObj[_INTERNAL_SPAN_COMPONENT_UUID_FIELDS_ID_TO_NAME[fieldId]] = origVal;
|
|
4013
|
+
}
|
|
4014
|
+
}
|
|
4015
|
+
if (this.data.object_id) {
|
|
4016
|
+
addUuidField(
|
|
4017
|
+
this.data.object_id,
|
|
4018
|
+
1 /* OBJECT_ID */
|
|
4019
|
+
);
|
|
4020
|
+
}
|
|
4021
|
+
if (this.data.row_id) {
|
|
4022
|
+
addUuidField(this.data.row_id, 2 /* ROW_ID */);
|
|
4023
|
+
}
|
|
4024
|
+
if (this.data.span_id) {
|
|
4025
|
+
addUuidField(this.data.span_id, 3 /* SPAN_ID */);
|
|
4026
|
+
}
|
|
4027
|
+
if (this.data.root_span_id) {
|
|
4028
|
+
addUuidField(
|
|
4029
|
+
this.data.root_span_id,
|
|
4030
|
+
4 /* ROOT_SPAN_ID */
|
|
4031
|
+
);
|
|
4032
|
+
}
|
|
4033
|
+
if (uuidEntries.length > 255) {
|
|
4034
|
+
throw new Error("Impossible: too many UUID entries to encode");
|
|
4035
|
+
}
|
|
4036
|
+
allBuffers.push(new Uint8Array([uuidEntries.length]));
|
|
4037
|
+
allBuffers.push(...uuidEntries);
|
|
4038
|
+
if (Object.keys(jsonObj).length > 0) {
|
|
4039
|
+
allBuffers.push(stringToUint8Array(JSON.stringify(jsonObj)));
|
|
4040
|
+
}
|
|
4041
|
+
return uint8ArrayToBase64(concatUint8Arrays(...allBuffers));
|
|
4042
|
+
}
|
|
4043
|
+
static fromStr(s) {
|
|
4044
|
+
try {
|
|
4045
|
+
const rawBytes = base64ToUint8Array(s);
|
|
4046
|
+
const jsonObj = {};
|
|
4047
|
+
if (rawBytes[0] < ENCODING_VERSION_NUMBER3) {
|
|
4048
|
+
const spanComponentsOld = SpanComponentsV2.fromStr(s);
|
|
4049
|
+
jsonObj["object_type"] = spanComponentsOld.objectType;
|
|
4050
|
+
jsonObj["object_id"] = spanComponentsOld.objectId;
|
|
4051
|
+
jsonObj["compute_object_metadata_args"] = spanComponentsOld.computeObjectMetadataArgs;
|
|
4052
|
+
if (spanComponentsOld.rowIds) {
|
|
4053
|
+
jsonObj["row_id"] = spanComponentsOld.rowIds.rowId;
|
|
4054
|
+
jsonObj["span_id"] = spanComponentsOld.rowIds.spanId;
|
|
4055
|
+
jsonObj["root_span_id"] = spanComponentsOld.rowIds.rootSpanId;
|
|
4056
|
+
}
|
|
4057
|
+
} else {
|
|
4058
|
+
jsonObj["object_type"] = rawBytes[1];
|
|
4059
|
+
const numUuidEntries = rawBytes[2];
|
|
4060
|
+
let byteOffset = 3;
|
|
4061
|
+
for (let i = 0; i < numUuidEntries; ++i) {
|
|
4062
|
+
const fieldId = internalSpanComponentUUIDFieldsEnumSchema.parse(
|
|
4063
|
+
rawBytes[byteOffset]
|
|
4064
|
+
);
|
|
4065
|
+
const fieldBytes = rawBytes.subarray(byteOffset + 1, byteOffset + 17);
|
|
4066
|
+
byteOffset += 17;
|
|
4067
|
+
jsonObj[_INTERNAL_SPAN_COMPONENT_UUID_FIELDS_ID_TO_NAME[fieldId]] = uuid3.stringify(fieldBytes);
|
|
4068
|
+
}
|
|
4069
|
+
if (byteOffset < rawBytes.length) {
|
|
4070
|
+
const remainingJsonObj = JSON.parse(
|
|
4071
|
+
uint8ArrayToString(rawBytes.subarray(byteOffset))
|
|
4072
|
+
);
|
|
4073
|
+
Object.assign(jsonObj, remainingJsonObj);
|
|
4074
|
+
}
|
|
4075
|
+
}
|
|
4076
|
+
return _SpanComponentsV3.fromJsonObj(jsonObj);
|
|
4077
|
+
} catch {
|
|
4078
|
+
throw new Error(INVALID_ENCODING_ERRMSG3);
|
|
4079
|
+
}
|
|
4080
|
+
}
|
|
4081
|
+
objectIdFields() {
|
|
4082
|
+
if (!this.data.object_id) {
|
|
4083
|
+
throw new Error(
|
|
4084
|
+
"Impossible: cannot invoke `objectIdFields` unless SpanComponentsV3 is initialized with an `object_id`"
|
|
4085
|
+
);
|
|
4086
|
+
}
|
|
4087
|
+
switch (this.data.object_type) {
|
|
4088
|
+
case 1 /* EXPERIMENT */:
|
|
4089
|
+
return { experiment_id: this.data.object_id };
|
|
4090
|
+
case 2 /* PROJECT_LOGS */:
|
|
4091
|
+
return { project_id: this.data.object_id, log_id: "g" };
|
|
4092
|
+
case 3 /* PLAYGROUND_LOGS */:
|
|
4093
|
+
return { prompt_session_id: this.data.object_id, log_id: "x" };
|
|
4094
|
+
default:
|
|
4095
|
+
const _ = this.data.object_type;
|
|
4096
|
+
throw new Error("Impossible");
|
|
4097
|
+
}
|
|
4098
|
+
}
|
|
4099
|
+
async export() {
|
|
4100
|
+
return this.toStr();
|
|
4101
|
+
}
|
|
4102
|
+
static fromJsonObj(jsonObj) {
|
|
4103
|
+
return new _SpanComponentsV3(spanComponentsV3Schema.parse(jsonObj));
|
|
4104
|
+
}
|
|
4105
|
+
};
|
|
4106
|
+
|
|
4107
|
+
// util/type_util.ts
|
|
4108
|
+
function isObject(value) {
|
|
4109
|
+
return value instanceof Object && !(value instanceof Array);
|
|
4110
|
+
}
|
|
4111
|
+
function isArray(value) {
|
|
4112
|
+
return value instanceof Array;
|
|
4113
|
+
}
|
|
4114
|
+
function isObjectOrArray(value) {
|
|
4115
|
+
return value instanceof Object;
|
|
4116
|
+
}
|
|
4117
|
+
|
|
4118
|
+
// util/object_util.ts
|
|
4119
|
+
function mergeDictsWithPaths({
|
|
4120
|
+
mergeInto,
|
|
4121
|
+
mergeFrom,
|
|
4122
|
+
mergePaths
|
|
4123
|
+
}) {
|
|
4124
|
+
const mergePathsSerialized = new Set(
|
|
4125
|
+
mergePaths.map((p) => JSON.stringify(p))
|
|
4126
|
+
);
|
|
4127
|
+
return mergeDictsWithPathsHelper({
|
|
4128
|
+
mergeInto,
|
|
4129
|
+
mergeFrom,
|
|
4130
|
+
path: [],
|
|
4131
|
+
mergePaths: mergePathsSerialized
|
|
4132
|
+
});
|
|
4133
|
+
}
|
|
4134
|
+
function mergeDictsWithPathsHelper({
|
|
4135
|
+
mergeInto,
|
|
4136
|
+
mergeFrom,
|
|
4137
|
+
path: path3,
|
|
4138
|
+
mergePaths
|
|
4139
|
+
}) {
|
|
4140
|
+
Object.entries(mergeFrom).forEach(([k, mergeFromV]) => {
|
|
4141
|
+
const fullPath = path3.concat([k]);
|
|
4142
|
+
const fullPathSerialized = JSON.stringify(fullPath);
|
|
4143
|
+
const mergeIntoV = recordFind(mergeInto, k);
|
|
4144
|
+
if (isObject(mergeIntoV) && isObject(mergeFromV) && !mergePaths.has(fullPathSerialized)) {
|
|
4145
|
+
mergeDictsWithPathsHelper({
|
|
4146
|
+
mergeInto: mergeIntoV,
|
|
4147
|
+
mergeFrom: mergeFromV,
|
|
4148
|
+
path: fullPath,
|
|
4149
|
+
mergePaths
|
|
4150
|
+
});
|
|
4151
|
+
} else {
|
|
4152
|
+
mergeInto[k] = mergeFromV;
|
|
4153
|
+
}
|
|
4154
|
+
});
|
|
4155
|
+
return mergeInto;
|
|
4156
|
+
}
|
|
4157
|
+
function mergeDicts(mergeInto, mergeFrom) {
|
|
4158
|
+
return mergeDictsWithPaths({ mergeInto, mergeFrom, mergePaths: [] });
|
|
4159
|
+
}
|
|
4160
|
+
function mapAt(m, k) {
|
|
4161
|
+
const ret = m.get(k);
|
|
4162
|
+
if (ret === void 0) {
|
|
4163
|
+
throw new Error(`Map does not contain key ${k}`);
|
|
4164
|
+
}
|
|
4165
|
+
return ret;
|
|
4166
|
+
}
|
|
4167
|
+
function recordFind(m, k) {
|
|
4168
|
+
return m[k];
|
|
4169
|
+
}
|
|
4170
|
+
function getObjValueByPath(row, path3) {
|
|
4171
|
+
let curr = row;
|
|
4172
|
+
for (const p of path3) {
|
|
4173
|
+
if (!isObjectOrArray(curr)) {
|
|
4174
|
+
return null;
|
|
4175
|
+
}
|
|
4176
|
+
curr = curr[p];
|
|
4177
|
+
}
|
|
4178
|
+
return curr;
|
|
4179
|
+
}
|
|
4180
|
+
|
|
4181
|
+
// util/graph_util.ts
|
|
4182
|
+
function depthFirstSearch(args) {
|
|
4183
|
+
const { graph, firstVisitF, lastVisitF } = args;
|
|
4184
|
+
for (const vs of graph.values()) {
|
|
4185
|
+
for (const v of vs.values()) {
|
|
4186
|
+
if (!graph.has(v)) {
|
|
4187
|
+
throw new Error(`Outgoing vertex ${v} must be a key in the graph`);
|
|
4188
|
+
}
|
|
4189
|
+
}
|
|
4190
|
+
}
|
|
4191
|
+
const firstVisitedVertices = /* @__PURE__ */ new Set();
|
|
4192
|
+
const visitationOrder = args.visitationOrder ?? [...graph.keys()];
|
|
4193
|
+
const events = visitationOrder.map((vertex) => ({ eventType: "first", vertex, extras: {} })).reverse();
|
|
4194
|
+
while (events.length) {
|
|
4195
|
+
const { eventType, vertex, extras } = events.pop();
|
|
4196
|
+
if (eventType === "last") {
|
|
4197
|
+
lastVisitF?.(vertex);
|
|
4198
|
+
continue;
|
|
4199
|
+
}
|
|
4200
|
+
if (firstVisitedVertices.has(vertex)) {
|
|
4201
|
+
continue;
|
|
4202
|
+
}
|
|
4203
|
+
firstVisitedVertices.add(vertex);
|
|
4204
|
+
firstVisitF?.(vertex, { parentVertex: extras.parentVertex });
|
|
4205
|
+
events.push({ eventType: "last", vertex, extras: {} });
|
|
4206
|
+
mapAt(graph, vertex).forEach((child) => {
|
|
4207
|
+
events.push({
|
|
4208
|
+
eventType: "first",
|
|
4209
|
+
vertex: child,
|
|
4210
|
+
extras: { parentVertex: vertex }
|
|
4211
|
+
});
|
|
4212
|
+
});
|
|
4213
|
+
}
|
|
4214
|
+
}
|
|
4215
|
+
function undirectedConnectedComponents(graph) {
|
|
4216
|
+
const directedGraph = new Map(
|
|
4217
|
+
[...graph.vertices].map((v) => [v, /* @__PURE__ */ new Set()])
|
|
4218
|
+
);
|
|
4219
|
+
for (const [i, j] of graph.edges) {
|
|
4220
|
+
mapAt(directedGraph, i).add(j);
|
|
4221
|
+
mapAt(directedGraph, j).add(i);
|
|
4222
|
+
}
|
|
4223
|
+
let labelCounter = 0;
|
|
4224
|
+
const vertexLabels = /* @__PURE__ */ new Map();
|
|
4225
|
+
const firstVisitF = (vertex, args) => {
|
|
4226
|
+
const label = args?.parentVertex !== void 0 ? mapAt(vertexLabels, args?.parentVertex) : labelCounter++;
|
|
4227
|
+
vertexLabels.set(vertex, label);
|
|
4228
|
+
};
|
|
4229
|
+
depthFirstSearch({ graph: directedGraph, firstVisitF });
|
|
4230
|
+
const output = Array.from({ length: labelCounter }).map(() => []);
|
|
4231
|
+
for (const [vertex, label] of vertexLabels.entries()) {
|
|
4232
|
+
output[label].push(vertex);
|
|
4233
|
+
}
|
|
4234
|
+
return output;
|
|
4235
|
+
}
|
|
4236
|
+
function topologicalSort(graph, visitationOrder) {
|
|
4237
|
+
const reverseOrdering = [];
|
|
4238
|
+
const lastVisitF = (vertex) => {
|
|
4239
|
+
reverseOrdering.push(vertex);
|
|
4240
|
+
};
|
|
4241
|
+
depthFirstSearch({ graph, lastVisitF, visitationOrder });
|
|
4242
|
+
return reverseOrdering.reverse();
|
|
4243
|
+
}
|
|
4244
|
+
|
|
4245
|
+
// util/merge_row_batch.ts
|
|
4246
|
+
function generateMergedRowKey(row, useParentIdForId) {
|
|
4247
|
+
return JSON.stringify(
|
|
4248
|
+
[
|
|
4249
|
+
"org_id",
|
|
4250
|
+
"project_id",
|
|
4251
|
+
"experiment_id",
|
|
4252
|
+
"dataset_id",
|
|
4253
|
+
"prompt_session_id",
|
|
4254
|
+
"log_id",
|
|
4255
|
+
useParentIdForId ?? false ? PARENT_ID_FIELD : "id"
|
|
4256
|
+
].map((k) => row[k])
|
|
4257
|
+
);
|
|
4258
|
+
}
|
|
4259
|
+
var MERGE_ROW_SKIP_FIELDS = [
|
|
4260
|
+
"created",
|
|
4261
|
+
"span_id",
|
|
4262
|
+
"root_span_id",
|
|
4263
|
+
"span_parents",
|
|
4264
|
+
"_parent_id"
|
|
4265
|
+
// TODO: handle merge paths.
|
|
4266
|
+
];
|
|
4267
|
+
function popMergeRowSkipFields(row) {
|
|
4268
|
+
const popped = {};
|
|
4269
|
+
for (const field of MERGE_ROW_SKIP_FIELDS) {
|
|
4270
|
+
if (field in row) {
|
|
4271
|
+
popped[field] = row[field];
|
|
4272
|
+
delete row[field];
|
|
4273
|
+
}
|
|
4274
|
+
}
|
|
4275
|
+
return popped;
|
|
4276
|
+
}
|
|
4277
|
+
function restoreMergeRowSkipFields(row, skipFields) {
|
|
4278
|
+
for (const field of MERGE_ROW_SKIP_FIELDS) {
|
|
4279
|
+
delete row[field];
|
|
4280
|
+
if (field in skipFields) {
|
|
4281
|
+
row[field] = skipFields[field];
|
|
4282
|
+
}
|
|
4283
|
+
}
|
|
4284
|
+
}
|
|
4285
|
+
function mergeRowBatch(rows) {
|
|
4286
|
+
for (const row of rows) {
|
|
4287
|
+
if (row.id === void 0) {
|
|
4288
|
+
throw new Error(
|
|
4289
|
+
"Logged row is missing an id. This is an internal braintrust error. Please contact us at info@braintrust.dev for help"
|
|
4290
|
+
);
|
|
4291
|
+
}
|
|
4292
|
+
}
|
|
4293
|
+
const rowGroups = /* @__PURE__ */ new Map();
|
|
4294
|
+
for (const row of rows) {
|
|
4295
|
+
const key = generateMergedRowKey(row);
|
|
4296
|
+
const existingRow = rowGroups.get(key);
|
|
4297
|
+
if (existingRow !== void 0 && row[IS_MERGE_FIELD]) {
|
|
4298
|
+
const skipFields = popMergeRowSkipFields(existingRow);
|
|
4299
|
+
const preserveNoMerge = !existingRow[IS_MERGE_FIELD];
|
|
4300
|
+
mergeDicts(existingRow, row);
|
|
4301
|
+
restoreMergeRowSkipFields(existingRow, skipFields);
|
|
4302
|
+
if (preserveNoMerge) {
|
|
4303
|
+
delete existingRow[IS_MERGE_FIELD];
|
|
4304
|
+
}
|
|
4305
|
+
} else {
|
|
4306
|
+
rowGroups.set(key, row);
|
|
4307
|
+
}
|
|
4308
|
+
}
|
|
4309
|
+
const merged = [...rowGroups.values()];
|
|
4310
|
+
const rowToLabel = new Map(
|
|
4311
|
+
merged.map((r, i) => [generateMergedRowKey(r), i])
|
|
4312
|
+
);
|
|
4313
|
+
const graph = new Map(
|
|
4314
|
+
Array.from({ length: merged.length }).map((_, i) => [i, /* @__PURE__ */ new Set()])
|
|
4315
|
+
);
|
|
4316
|
+
merged.forEach((r, i) => {
|
|
4317
|
+
const parentId = r[PARENT_ID_FIELD];
|
|
4318
|
+
if (!parentId) {
|
|
4319
|
+
return;
|
|
4320
|
+
}
|
|
4321
|
+
const parentRowKey = generateMergedRowKey(
|
|
4322
|
+
r,
|
|
4323
|
+
true
|
|
4324
|
+
/* useParentIdForId */
|
|
4325
|
+
);
|
|
4326
|
+
const parentLabel = rowToLabel.get(parentRowKey);
|
|
4327
|
+
if (parentLabel !== void 0) {
|
|
4328
|
+
mapAt(graph, parentLabel).add(i);
|
|
4329
|
+
}
|
|
4330
|
+
});
|
|
4331
|
+
const connectedComponents = undirectedConnectedComponents({
|
|
4332
|
+
vertices: new Set(graph.keys()),
|
|
4333
|
+
edges: new Set(
|
|
4334
|
+
[...graph.entries()].flatMap(
|
|
4335
|
+
([k, vs]) => [...vs].map((v) => {
|
|
4336
|
+
const ret = [k, v];
|
|
4337
|
+
return ret;
|
|
4338
|
+
})
|
|
4339
|
+
)
|
|
4340
|
+
)
|
|
4341
|
+
});
|
|
4342
|
+
const buckets = connectedComponents.map(
|
|
4343
|
+
(cc) => topologicalSort(
|
|
4344
|
+
graph,
|
|
4345
|
+
cc
|
|
4346
|
+
/* visitationOrder */
|
|
4347
|
+
)
|
|
4348
|
+
);
|
|
4349
|
+
return buckets.map((bucket) => bucket.map((i) => merged[i]));
|
|
4350
|
+
}
|
|
4351
|
+
function batchItems(args) {
|
|
4352
|
+
let { items } = args;
|
|
4353
|
+
const batchMaxNumItems = args.batchMaxNumItems ?? Number.POSITIVE_INFINITY;
|
|
4354
|
+
const batchMaxNumBytes = args.batchMaxNumBytes ?? Number.POSITIVE_INFINITY;
|
|
4355
|
+
const output = [];
|
|
4356
|
+
let nextItems = [];
|
|
4357
|
+
let batchSet = [];
|
|
4358
|
+
let batch = [];
|
|
4359
|
+
let batchLen = 0;
|
|
4360
|
+
function addToBatch(item) {
|
|
4361
|
+
batch.push(item);
|
|
4362
|
+
batchLen += item.length;
|
|
4363
|
+
}
|
|
4364
|
+
function flushBatch() {
|
|
4365
|
+
batchSet.push(batch);
|
|
4366
|
+
batch = [];
|
|
4367
|
+
batchLen = 0;
|
|
4368
|
+
}
|
|
4369
|
+
while (items.length) {
|
|
4370
|
+
for (const bucket of items) {
|
|
4371
|
+
let i = 0;
|
|
4372
|
+
for (const item of bucket) {
|
|
4373
|
+
if (batch.length === 0 || item.length + batchLen < batchMaxNumBytes && batch.length < batchMaxNumItems) {
|
|
4374
|
+
addToBatch(item);
|
|
4375
|
+
} else if (i === 0) {
|
|
4376
|
+
flushBatch();
|
|
4377
|
+
addToBatch(item);
|
|
4378
|
+
} else {
|
|
4379
|
+
break;
|
|
4380
|
+
}
|
|
4381
|
+
++i;
|
|
4382
|
+
}
|
|
4383
|
+
if (i < bucket.length) {
|
|
4384
|
+
nextItems.push(bucket.slice(i));
|
|
4385
|
+
}
|
|
4386
|
+
if (batchLen >= batchMaxNumBytes || batch.length > batchMaxNumItems) {
|
|
4387
|
+
flushBatch();
|
|
4388
|
+
}
|
|
4389
|
+
}
|
|
4390
|
+
if (batch.length) {
|
|
4391
|
+
flushBatch();
|
|
4392
|
+
}
|
|
4393
|
+
if (batchSet.length) {
|
|
4394
|
+
output.push(batchSet);
|
|
4395
|
+
batchSet = [];
|
|
4396
|
+
}
|
|
4397
|
+
items = nextItems;
|
|
4398
|
+
nextItems = [];
|
|
4399
|
+
}
|
|
4400
|
+
return output;
|
|
4401
|
+
}
|
|
4402
|
+
|
|
4403
|
+
// util/object.ts
|
|
4404
|
+
var DEFAULT_IS_LEGACY_DATASET = false;
|
|
4405
|
+
function ensureDatasetRecord(r, legacy) {
|
|
4406
|
+
if (legacy) {
|
|
4407
|
+
return ensureLegacyDatasetRecord(r);
|
|
4408
|
+
} else {
|
|
4409
|
+
return ensureNewDatasetRecord(r);
|
|
4410
|
+
}
|
|
4411
|
+
}
|
|
4412
|
+
function ensureLegacyDatasetRecord(r) {
|
|
4413
|
+
if ("output" in r) {
|
|
4414
|
+
return r;
|
|
4415
|
+
}
|
|
4416
|
+
const row = {
|
|
4417
|
+
...r,
|
|
4418
|
+
output: r.expected
|
|
4419
|
+
};
|
|
4420
|
+
delete row.expected;
|
|
4421
|
+
return row;
|
|
4422
|
+
}
|
|
4423
|
+
function ensureNewDatasetRecord(r) {
|
|
4424
|
+
if ("expected" in r) {
|
|
4425
|
+
return r;
|
|
4426
|
+
}
|
|
4427
|
+
const row = {
|
|
4428
|
+
...r,
|
|
4429
|
+
tags: null,
|
|
4430
|
+
expected: r.output
|
|
4431
|
+
};
|
|
4432
|
+
delete row.output;
|
|
4433
|
+
return row;
|
|
4434
|
+
}
|
|
4435
|
+
|
|
4436
|
+
// util/json_util.ts
|
|
4437
|
+
function constructJsonArray(items) {
|
|
4438
|
+
return `[${items.join(",")}]`;
|
|
4439
|
+
}
|
|
4440
|
+
|
|
4441
|
+
// util/string_util.ts
|
|
4442
|
+
function _urljoin(...parts) {
|
|
4443
|
+
return parts.map(
|
|
4444
|
+
(x, i) => x.replace(/^\//, "").replace(i < parts.length - 1 ? /\/$/ : "", "")
|
|
4445
|
+
).filter((x) => x.trim() !== "").join("/");
|
|
4446
|
+
}
|
|
4447
|
+
|
|
4448
|
+
// util/git_fields.ts
|
|
4449
|
+
function mergeGitMetadataSettings(s1, s2) {
|
|
4450
|
+
if (s1.collect === "all") {
|
|
4451
|
+
return s2;
|
|
4452
|
+
} else if (s2.collect === "all") {
|
|
4453
|
+
return s1;
|
|
4454
|
+
} else if (s1.collect === "none") {
|
|
4455
|
+
return s1;
|
|
4456
|
+
} else if (s2.collect === "none") {
|
|
4457
|
+
return s2;
|
|
4458
|
+
}
|
|
4459
|
+
const fields = (s1.fields ?? []).filter((f) => (s2.fields ?? []).includes(f));
|
|
4460
|
+
const collect = fields.length > 0 ? "some" : "none";
|
|
4461
|
+
return { collect, fields };
|
|
4462
|
+
}
|
|
4463
|
+
|
|
4464
|
+
// util/xact-ids.ts
|
|
4465
|
+
var TOP_BITS = BigInt("0x0DE1") << BigInt(48);
|
|
4466
|
+
var MOD = BigInt(1) << BigInt(64);
|
|
4467
|
+
var COPRIME = BigInt("205891132094649");
|
|
4468
|
+
var COPRIME_INVERSE = BigInt("1522336535492693385");
|
|
4469
|
+
function modularMultiply(value, prime) {
|
|
4470
|
+
return value * prime % MOD;
|
|
4471
|
+
}
|
|
4472
|
+
function prettifyXact(valueString) {
|
|
4473
|
+
const value = BigInt(valueString);
|
|
4474
|
+
const encoded = modularMultiply(value, COPRIME);
|
|
4475
|
+
return encoded.toString(16).padStart(16, "0");
|
|
4476
|
+
}
|
|
4477
|
+
function loadPrettyXact(encodedHex) {
|
|
4478
|
+
if (encodedHex.length !== 16) {
|
|
4479
|
+
return encodedHex;
|
|
4480
|
+
}
|
|
4481
|
+
const value = BigInt(`0x${encodedHex}`);
|
|
4482
|
+
const multipliedInverse = modularMultiply(value, COPRIME_INVERSE);
|
|
4483
|
+
const withTopBits = TOP_BITS | multipliedInverse;
|
|
4484
|
+
return withTopBits.toString();
|
|
4485
|
+
}
|
|
4486
|
+
|
|
4487
|
+
// util/zod_util.ts
|
|
4488
|
+
import { z as z4 } from "zod/v3";
|
|
3523
4489
|
|
|
3524
4490
|
// src/generated_types.ts
|
|
3525
|
-
import { z } from "zod";
|
|
3526
|
-
var AclObjectType =
|
|
3527
|
-
|
|
4491
|
+
import { z as z5 } from "zod/v3";
|
|
4492
|
+
var AclObjectType = z5.union([
|
|
4493
|
+
z5.enum([
|
|
3528
4494
|
"organization",
|
|
3529
4495
|
"project",
|
|
3530
4496
|
"experiment",
|
|
@@ -3537,9 +4503,9 @@ var AclObjectType = z.union([
|
|
|
3537
4503
|
"project_log",
|
|
3538
4504
|
"org_project"
|
|
3539
4505
|
]),
|
|
3540
|
-
|
|
4506
|
+
z5.null()
|
|
3541
4507
|
]);
|
|
3542
|
-
var Permission =
|
|
4508
|
+
var Permission = z5.enum([
|
|
3543
4509
|
"create",
|
|
3544
4510
|
"read",
|
|
3545
4511
|
"update",
|
|
@@ -3549,310 +4515,310 @@ var Permission = z.enum([
|
|
|
3549
4515
|
"update_acls",
|
|
3550
4516
|
"delete_acls"
|
|
3551
4517
|
]);
|
|
3552
|
-
var Acl =
|
|
3553
|
-
id:
|
|
3554
|
-
object_type: AclObjectType.and(
|
|
3555
|
-
object_id:
|
|
3556
|
-
user_id:
|
|
3557
|
-
group_id:
|
|
3558
|
-
permission: Permission.and(
|
|
3559
|
-
restrict_object_type: AclObjectType.and(
|
|
3560
|
-
role_id:
|
|
3561
|
-
_object_org_id:
|
|
3562
|
-
created:
|
|
3563
|
-
});
|
|
3564
|
-
var AISecret =
|
|
3565
|
-
id:
|
|
3566
|
-
created:
|
|
3567
|
-
updated_at:
|
|
3568
|
-
org_id:
|
|
3569
|
-
name:
|
|
3570
|
-
type:
|
|
3571
|
-
metadata:
|
|
3572
|
-
preview_secret:
|
|
3573
|
-
});
|
|
3574
|
-
var ResponseFormatJsonSchema =
|
|
3575
|
-
name:
|
|
3576
|
-
description:
|
|
3577
|
-
schema:
|
|
3578
|
-
strict:
|
|
3579
|
-
});
|
|
3580
|
-
var ResponseFormatNullish =
|
|
3581
|
-
|
|
3582
|
-
|
|
3583
|
-
type:
|
|
4518
|
+
var Acl = z5.object({
|
|
4519
|
+
id: z5.string().uuid(),
|
|
4520
|
+
object_type: AclObjectType.and(z5.string()),
|
|
4521
|
+
object_id: z5.string().uuid(),
|
|
4522
|
+
user_id: z5.union([z5.string(), z5.null()]).optional(),
|
|
4523
|
+
group_id: z5.union([z5.string(), z5.null()]).optional(),
|
|
4524
|
+
permission: Permission.and(z5.union([z5.string(), z5.null()])).optional(),
|
|
4525
|
+
restrict_object_type: AclObjectType.and(z5.unknown()).optional(),
|
|
4526
|
+
role_id: z5.union([z5.string(), z5.null()]).optional(),
|
|
4527
|
+
_object_org_id: z5.string().uuid(),
|
|
4528
|
+
created: z5.union([z5.string(), z5.null()]).optional()
|
|
4529
|
+
});
|
|
4530
|
+
var AISecret = z5.object({
|
|
4531
|
+
id: z5.string().uuid(),
|
|
4532
|
+
created: z5.union([z5.string(), z5.null()]).optional(),
|
|
4533
|
+
updated_at: z5.union([z5.string(), z5.null()]).optional(),
|
|
4534
|
+
org_id: z5.string().uuid(),
|
|
4535
|
+
name: z5.string(),
|
|
4536
|
+
type: z5.union([z5.string(), z5.null()]).optional(),
|
|
4537
|
+
metadata: z5.union([z5.object({}).partial().passthrough(), z5.null()]).optional(),
|
|
4538
|
+
preview_secret: z5.union([z5.string(), z5.null()]).optional()
|
|
4539
|
+
});
|
|
4540
|
+
var ResponseFormatJsonSchema = z5.object({
|
|
4541
|
+
name: z5.string(),
|
|
4542
|
+
description: z5.string().optional(),
|
|
4543
|
+
schema: z5.union([z5.object({}).partial().passthrough(), z5.string()]).optional(),
|
|
4544
|
+
strict: z5.union([z5.boolean(), z5.null()]).optional()
|
|
4545
|
+
});
|
|
4546
|
+
var ResponseFormatNullish = z5.union([
|
|
4547
|
+
z5.object({ type: z5.literal("json_object") }),
|
|
4548
|
+
z5.object({
|
|
4549
|
+
type: z5.literal("json_schema"),
|
|
3584
4550
|
json_schema: ResponseFormatJsonSchema
|
|
3585
4551
|
}),
|
|
3586
|
-
|
|
3587
|
-
|
|
4552
|
+
z5.object({ type: z5.literal("text") }),
|
|
4553
|
+
z5.null()
|
|
3588
4554
|
]);
|
|
3589
|
-
var AnyModelParams =
|
|
3590
|
-
temperature:
|
|
3591
|
-
top_p:
|
|
3592
|
-
max_tokens:
|
|
3593
|
-
max_completion_tokens:
|
|
3594
|
-
frequency_penalty:
|
|
3595
|
-
presence_penalty:
|
|
4555
|
+
var AnyModelParams = z5.object({
|
|
4556
|
+
temperature: z5.number().optional(),
|
|
4557
|
+
top_p: z5.number().optional(),
|
|
4558
|
+
max_tokens: z5.number(),
|
|
4559
|
+
max_completion_tokens: z5.number().optional(),
|
|
4560
|
+
frequency_penalty: z5.number().optional(),
|
|
4561
|
+
presence_penalty: z5.number().optional(),
|
|
3596
4562
|
response_format: ResponseFormatNullish.optional(),
|
|
3597
|
-
tool_choice:
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
type:
|
|
3603
|
-
function:
|
|
4563
|
+
tool_choice: z5.union([
|
|
4564
|
+
z5.literal("auto"),
|
|
4565
|
+
z5.literal("none"),
|
|
4566
|
+
z5.literal("required"),
|
|
4567
|
+
z5.object({
|
|
4568
|
+
type: z5.literal("function"),
|
|
4569
|
+
function: z5.object({ name: z5.string() })
|
|
3604
4570
|
})
|
|
3605
4571
|
]).optional(),
|
|
3606
|
-
function_call:
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
4572
|
+
function_call: z5.union([
|
|
4573
|
+
z5.literal("auto"),
|
|
4574
|
+
z5.literal("none"),
|
|
4575
|
+
z5.object({ name: z5.string() })
|
|
3610
4576
|
]).optional(),
|
|
3611
|
-
n:
|
|
3612
|
-
stop:
|
|
3613
|
-
reasoning_effort:
|
|
3614
|
-
verbosity:
|
|
3615
|
-
top_k:
|
|
3616
|
-
stop_sequences:
|
|
3617
|
-
max_tokens_to_sample:
|
|
3618
|
-
maxOutputTokens:
|
|
3619
|
-
topP:
|
|
3620
|
-
topK:
|
|
3621
|
-
use_cache:
|
|
3622
|
-
});
|
|
3623
|
-
var ApiKey =
|
|
3624
|
-
id:
|
|
3625
|
-
created:
|
|
3626
|
-
name:
|
|
3627
|
-
preview_name:
|
|
3628
|
-
user_id:
|
|
3629
|
-
user_email:
|
|
3630
|
-
user_given_name:
|
|
3631
|
-
user_family_name:
|
|
3632
|
-
org_id:
|
|
3633
|
-
});
|
|
3634
|
-
var AsyncScoringState =
|
|
3635
|
-
|
|
3636
|
-
status:
|
|
3637
|
-
token:
|
|
3638
|
-
function_ids:
|
|
3639
|
-
skip_logging:
|
|
4577
|
+
n: z5.number().optional(),
|
|
4578
|
+
stop: z5.array(z5.string()).optional(),
|
|
4579
|
+
reasoning_effort: z5.enum(["minimal", "low", "medium", "high"]).optional(),
|
|
4580
|
+
verbosity: z5.enum(["low", "medium", "high"]).optional(),
|
|
4581
|
+
top_k: z5.number().optional(),
|
|
4582
|
+
stop_sequences: z5.array(z5.string()).optional(),
|
|
4583
|
+
max_tokens_to_sample: z5.number().optional(),
|
|
4584
|
+
maxOutputTokens: z5.number().optional(),
|
|
4585
|
+
topP: z5.number().optional(),
|
|
4586
|
+
topK: z5.number().optional(),
|
|
4587
|
+
use_cache: z5.boolean().optional()
|
|
4588
|
+
});
|
|
4589
|
+
var ApiKey = z5.object({
|
|
4590
|
+
id: z5.string().uuid(),
|
|
4591
|
+
created: z5.union([z5.string(), z5.null()]).optional(),
|
|
4592
|
+
name: z5.string(),
|
|
4593
|
+
preview_name: z5.string(),
|
|
4594
|
+
user_id: z5.union([z5.string(), z5.null()]).optional(),
|
|
4595
|
+
user_email: z5.union([z5.string(), z5.null()]).optional(),
|
|
4596
|
+
user_given_name: z5.union([z5.string(), z5.null()]).optional(),
|
|
4597
|
+
user_family_name: z5.union([z5.string(), z5.null()]).optional(),
|
|
4598
|
+
org_id: z5.union([z5.string(), z5.null()]).optional()
|
|
4599
|
+
});
|
|
4600
|
+
var AsyncScoringState = z5.union([
|
|
4601
|
+
z5.object({
|
|
4602
|
+
status: z5.literal("enabled"),
|
|
4603
|
+
token: z5.string(),
|
|
4604
|
+
function_ids: z5.array(z5.unknown()).min(1),
|
|
4605
|
+
skip_logging: z5.union([z5.boolean(), z5.null()]).optional()
|
|
3640
4606
|
}),
|
|
3641
|
-
|
|
3642
|
-
|
|
3643
|
-
|
|
4607
|
+
z5.object({ status: z5.literal("disabled") }),
|
|
4608
|
+
z5.null(),
|
|
4609
|
+
z5.null()
|
|
3644
4610
|
]);
|
|
3645
|
-
var AsyncScoringControl =
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
-
|
|
4611
|
+
var AsyncScoringControl = z5.union([
|
|
4612
|
+
z5.object({ kind: z5.literal("score_update"), token: z5.string() }),
|
|
4613
|
+
z5.object({ kind: z5.literal("state_override"), state: AsyncScoringState }),
|
|
4614
|
+
z5.object({ kind: z5.literal("state_force_reselect") }),
|
|
4615
|
+
z5.object({ kind: z5.literal("state_enabled_force_rescore") })
|
|
3650
4616
|
]);
|
|
3651
|
-
var BraintrustAttachmentReference =
|
|
3652
|
-
type:
|
|
3653
|
-
filename:
|
|
3654
|
-
content_type:
|
|
3655
|
-
key:
|
|
3656
|
-
});
|
|
3657
|
-
var ExternalAttachmentReference =
|
|
3658
|
-
type:
|
|
3659
|
-
filename:
|
|
3660
|
-
content_type:
|
|
3661
|
-
url:
|
|
3662
|
-
});
|
|
3663
|
-
var AttachmentReference =
|
|
4617
|
+
var BraintrustAttachmentReference = z5.object({
|
|
4618
|
+
type: z5.literal("braintrust_attachment"),
|
|
4619
|
+
filename: z5.string().min(1),
|
|
4620
|
+
content_type: z5.string().min(1),
|
|
4621
|
+
key: z5.string().min(1)
|
|
4622
|
+
});
|
|
4623
|
+
var ExternalAttachmentReference = z5.object({
|
|
4624
|
+
type: z5.literal("external_attachment"),
|
|
4625
|
+
filename: z5.string().min(1),
|
|
4626
|
+
content_type: z5.string().min(1),
|
|
4627
|
+
url: z5.string().min(1)
|
|
4628
|
+
});
|
|
4629
|
+
var AttachmentReference = z5.discriminatedUnion("type", [
|
|
3664
4630
|
BraintrustAttachmentReference,
|
|
3665
4631
|
ExternalAttachmentReference
|
|
3666
4632
|
]);
|
|
3667
|
-
var UploadStatus =
|
|
3668
|
-
var AttachmentStatus =
|
|
4633
|
+
var UploadStatus = z5.enum(["uploading", "done", "error"]);
|
|
4634
|
+
var AttachmentStatus = z5.object({
|
|
3669
4635
|
upload_status: UploadStatus,
|
|
3670
|
-
error_message:
|
|
3671
|
-
});
|
|
3672
|
-
var BraintrustModelParams =
|
|
3673
|
-
var CallEvent =
|
|
3674
|
-
|
|
3675
|
-
id:
|
|
3676
|
-
data:
|
|
3677
|
-
event:
|
|
4636
|
+
error_message: z5.string().optional()
|
|
4637
|
+
});
|
|
4638
|
+
var BraintrustModelParams = z5.object({ use_cache: z5.boolean() }).partial();
|
|
4639
|
+
var CallEvent = z5.union([
|
|
4640
|
+
z5.object({
|
|
4641
|
+
id: z5.string().optional(),
|
|
4642
|
+
data: z5.string(),
|
|
4643
|
+
event: z5.literal("text_delta")
|
|
3678
4644
|
}),
|
|
3679
|
-
|
|
3680
|
-
id:
|
|
3681
|
-
data:
|
|
3682
|
-
event:
|
|
4645
|
+
z5.object({
|
|
4646
|
+
id: z5.string().optional(),
|
|
4647
|
+
data: z5.string(),
|
|
4648
|
+
event: z5.literal("reasoning_delta")
|
|
3683
4649
|
}),
|
|
3684
|
-
|
|
3685
|
-
id:
|
|
3686
|
-
data:
|
|
3687
|
-
event:
|
|
4650
|
+
z5.object({
|
|
4651
|
+
id: z5.string().optional(),
|
|
4652
|
+
data: z5.string(),
|
|
4653
|
+
event: z5.literal("json_delta")
|
|
3688
4654
|
}),
|
|
3689
|
-
|
|
3690
|
-
id:
|
|
3691
|
-
data:
|
|
3692
|
-
event:
|
|
4655
|
+
z5.object({
|
|
4656
|
+
id: z5.string().optional(),
|
|
4657
|
+
data: z5.string(),
|
|
4658
|
+
event: z5.literal("progress")
|
|
3693
4659
|
}),
|
|
3694
|
-
|
|
3695
|
-
id:
|
|
3696
|
-
data:
|
|
3697
|
-
event:
|
|
4660
|
+
z5.object({
|
|
4661
|
+
id: z5.string().optional(),
|
|
4662
|
+
data: z5.string(),
|
|
4663
|
+
event: z5.literal("error")
|
|
3698
4664
|
}),
|
|
3699
|
-
|
|
3700
|
-
id:
|
|
3701
|
-
data:
|
|
3702
|
-
event:
|
|
4665
|
+
z5.object({
|
|
4666
|
+
id: z5.string().optional(),
|
|
4667
|
+
data: z5.string(),
|
|
4668
|
+
event: z5.literal("console")
|
|
3703
4669
|
}),
|
|
3704
|
-
|
|
3705
|
-
id:
|
|
3706
|
-
event:
|
|
3707
|
-
data:
|
|
4670
|
+
z5.object({
|
|
4671
|
+
id: z5.string().optional(),
|
|
4672
|
+
event: z5.literal("start"),
|
|
4673
|
+
data: z5.literal("")
|
|
3708
4674
|
}),
|
|
3709
|
-
|
|
3710
|
-
id:
|
|
3711
|
-
event:
|
|
3712
|
-
data:
|
|
4675
|
+
z5.object({
|
|
4676
|
+
id: z5.string().optional(),
|
|
4677
|
+
event: z5.literal("done"),
|
|
4678
|
+
data: z5.literal("")
|
|
3713
4679
|
})
|
|
3714
4680
|
]);
|
|
3715
|
-
var ChatCompletionContentPartTextWithTitle =
|
|
3716
|
-
text:
|
|
3717
|
-
type:
|
|
3718
|
-
cache_control:
|
|
3719
|
-
});
|
|
3720
|
-
var ChatCompletionContentPartImageWithTitle =
|
|
3721
|
-
image_url:
|
|
3722
|
-
url:
|
|
3723
|
-
detail:
|
|
4681
|
+
var ChatCompletionContentPartTextWithTitle = z5.object({
|
|
4682
|
+
text: z5.string().default(""),
|
|
4683
|
+
type: z5.literal("text"),
|
|
4684
|
+
cache_control: z5.object({ type: z5.literal("ephemeral") }).optional()
|
|
4685
|
+
});
|
|
4686
|
+
var ChatCompletionContentPartImageWithTitle = z5.object({
|
|
4687
|
+
image_url: z5.object({
|
|
4688
|
+
url: z5.string(),
|
|
4689
|
+
detail: z5.union([z5.literal("auto"), z5.literal("low"), z5.literal("high")]).optional()
|
|
3724
4690
|
}),
|
|
3725
|
-
type:
|
|
4691
|
+
type: z5.literal("image_url")
|
|
3726
4692
|
});
|
|
3727
|
-
var ChatCompletionContentPart =
|
|
4693
|
+
var ChatCompletionContentPart = z5.union([
|
|
3728
4694
|
ChatCompletionContentPartTextWithTitle,
|
|
3729
4695
|
ChatCompletionContentPartImageWithTitle
|
|
3730
4696
|
]);
|
|
3731
|
-
var ChatCompletionContentPartText =
|
|
3732
|
-
text:
|
|
3733
|
-
type:
|
|
3734
|
-
cache_control:
|
|
3735
|
-
});
|
|
3736
|
-
var ChatCompletionMessageToolCall =
|
|
3737
|
-
id:
|
|
3738
|
-
function:
|
|
3739
|
-
type:
|
|
3740
|
-
});
|
|
3741
|
-
var ChatCompletionMessageReasoning =
|
|
3742
|
-
var ChatCompletionMessageParam =
|
|
3743
|
-
|
|
3744
|
-
content:
|
|
3745
|
-
role:
|
|
3746
|
-
name:
|
|
4697
|
+
var ChatCompletionContentPartText = z5.object({
|
|
4698
|
+
text: z5.string().default(""),
|
|
4699
|
+
type: z5.literal("text"),
|
|
4700
|
+
cache_control: z5.object({ type: z5.literal("ephemeral") }).optional()
|
|
4701
|
+
});
|
|
4702
|
+
var ChatCompletionMessageToolCall = z5.object({
|
|
4703
|
+
id: z5.string(),
|
|
4704
|
+
function: z5.object({ arguments: z5.string(), name: z5.string() }),
|
|
4705
|
+
type: z5.literal("function")
|
|
4706
|
+
});
|
|
4707
|
+
var ChatCompletionMessageReasoning = z5.object({ id: z5.string(), content: z5.string() }).partial();
|
|
4708
|
+
var ChatCompletionMessageParam = z5.union([
|
|
4709
|
+
z5.object({
|
|
4710
|
+
content: z5.union([z5.string(), z5.array(ChatCompletionContentPartText)]),
|
|
4711
|
+
role: z5.literal("system"),
|
|
4712
|
+
name: z5.string().optional()
|
|
3747
4713
|
}),
|
|
3748
|
-
|
|
3749
|
-
content:
|
|
3750
|
-
role:
|
|
3751
|
-
name:
|
|
4714
|
+
z5.object({
|
|
4715
|
+
content: z5.union([z5.string(), z5.array(ChatCompletionContentPart)]),
|
|
4716
|
+
role: z5.literal("user"),
|
|
4717
|
+
name: z5.string().optional()
|
|
3752
4718
|
}),
|
|
3753
|
-
|
|
3754
|
-
role:
|
|
3755
|
-
content:
|
|
3756
|
-
function_call:
|
|
3757
|
-
name:
|
|
3758
|
-
tool_calls:
|
|
3759
|
-
reasoning:
|
|
4719
|
+
z5.object({
|
|
4720
|
+
role: z5.literal("assistant"),
|
|
4721
|
+
content: z5.union([z5.string(), z5.array(ChatCompletionContentPartText), z5.null()]).optional(),
|
|
4722
|
+
function_call: z5.object({ arguments: z5.string(), name: z5.string() }).optional(),
|
|
4723
|
+
name: z5.string().optional(),
|
|
4724
|
+
tool_calls: z5.array(ChatCompletionMessageToolCall).optional(),
|
|
4725
|
+
reasoning: z5.array(ChatCompletionMessageReasoning).optional()
|
|
3760
4726
|
}),
|
|
3761
|
-
|
|
3762
|
-
content:
|
|
3763
|
-
role:
|
|
3764
|
-
tool_call_id:
|
|
4727
|
+
z5.object({
|
|
4728
|
+
content: z5.union([z5.string(), z5.array(ChatCompletionContentPartText)]),
|
|
4729
|
+
role: z5.literal("tool"),
|
|
4730
|
+
tool_call_id: z5.string().default("")
|
|
3765
4731
|
}),
|
|
3766
|
-
|
|
3767
|
-
content:
|
|
3768
|
-
name:
|
|
3769
|
-
role:
|
|
4732
|
+
z5.object({
|
|
4733
|
+
content: z5.union([z5.string(), z5.null()]),
|
|
4734
|
+
name: z5.string(),
|
|
4735
|
+
role: z5.literal("function")
|
|
3770
4736
|
}),
|
|
3771
|
-
|
|
3772
|
-
content:
|
|
3773
|
-
role:
|
|
3774
|
-
name:
|
|
4737
|
+
z5.object({
|
|
4738
|
+
content: z5.union([z5.string(), z5.array(ChatCompletionContentPartText)]),
|
|
4739
|
+
role: z5.literal("developer"),
|
|
4740
|
+
name: z5.string().optional()
|
|
3775
4741
|
}),
|
|
3776
|
-
|
|
3777
|
-
role:
|
|
3778
|
-
content:
|
|
4742
|
+
z5.object({
|
|
4743
|
+
role: z5.literal("model"),
|
|
4744
|
+
content: z5.union([z5.string(), z5.null()]).optional()
|
|
3779
4745
|
})
|
|
3780
4746
|
]);
|
|
3781
|
-
var ChatCompletionOpenAIMessageParam =
|
|
3782
|
-
|
|
3783
|
-
content:
|
|
3784
|
-
role:
|
|
3785
|
-
name:
|
|
4747
|
+
var ChatCompletionOpenAIMessageParam = z5.union([
|
|
4748
|
+
z5.object({
|
|
4749
|
+
content: z5.union([z5.string(), z5.array(ChatCompletionContentPartText)]),
|
|
4750
|
+
role: z5.literal("system"),
|
|
4751
|
+
name: z5.string().optional()
|
|
3786
4752
|
}),
|
|
3787
|
-
|
|
3788
|
-
content:
|
|
3789
|
-
role:
|
|
3790
|
-
name:
|
|
4753
|
+
z5.object({
|
|
4754
|
+
content: z5.union([z5.string(), z5.array(ChatCompletionContentPart)]),
|
|
4755
|
+
role: z5.literal("user"),
|
|
4756
|
+
name: z5.string().optional()
|
|
3791
4757
|
}),
|
|
3792
|
-
|
|
3793
|
-
role:
|
|
3794
|
-
content:
|
|
3795
|
-
function_call:
|
|
3796
|
-
name:
|
|
3797
|
-
tool_calls:
|
|
3798
|
-
reasoning:
|
|
4758
|
+
z5.object({
|
|
4759
|
+
role: z5.literal("assistant"),
|
|
4760
|
+
content: z5.union([z5.string(), z5.array(ChatCompletionContentPartText), z5.null()]).optional(),
|
|
4761
|
+
function_call: z5.object({ arguments: z5.string(), name: z5.string() }).optional(),
|
|
4762
|
+
name: z5.string().optional(),
|
|
4763
|
+
tool_calls: z5.array(ChatCompletionMessageToolCall).optional(),
|
|
4764
|
+
reasoning: z5.array(ChatCompletionMessageReasoning).optional()
|
|
3799
4765
|
}),
|
|
3800
|
-
|
|
3801
|
-
content:
|
|
3802
|
-
role:
|
|
3803
|
-
tool_call_id:
|
|
4766
|
+
z5.object({
|
|
4767
|
+
content: z5.union([z5.string(), z5.array(ChatCompletionContentPartText)]),
|
|
4768
|
+
role: z5.literal("tool"),
|
|
4769
|
+
tool_call_id: z5.string().default("")
|
|
3804
4770
|
}),
|
|
3805
|
-
|
|
3806
|
-
content:
|
|
3807
|
-
name:
|
|
3808
|
-
role:
|
|
4771
|
+
z5.object({
|
|
4772
|
+
content: z5.union([z5.string(), z5.null()]),
|
|
4773
|
+
name: z5.string(),
|
|
4774
|
+
role: z5.literal("function")
|
|
3809
4775
|
}),
|
|
3810
|
-
|
|
3811
|
-
content:
|
|
3812
|
-
role:
|
|
3813
|
-
name:
|
|
4776
|
+
z5.object({
|
|
4777
|
+
content: z5.union([z5.string(), z5.array(ChatCompletionContentPartText)]),
|
|
4778
|
+
role: z5.literal("developer"),
|
|
4779
|
+
name: z5.string().optional()
|
|
3814
4780
|
})
|
|
3815
4781
|
]);
|
|
3816
|
-
var ChatCompletionTool =
|
|
3817
|
-
function:
|
|
3818
|
-
name:
|
|
3819
|
-
description:
|
|
3820
|
-
parameters:
|
|
4782
|
+
var ChatCompletionTool = z5.object({
|
|
4783
|
+
function: z5.object({
|
|
4784
|
+
name: z5.string(),
|
|
4785
|
+
description: z5.string().optional(),
|
|
4786
|
+
parameters: z5.object({}).partial().passthrough().optional()
|
|
3821
4787
|
}),
|
|
3822
|
-
type:
|
|
4788
|
+
type: z5.literal("function")
|
|
3823
4789
|
});
|
|
3824
|
-
var CodeBundle =
|
|
3825
|
-
runtime_context:
|
|
3826
|
-
runtime:
|
|
3827
|
-
version:
|
|
4790
|
+
var CodeBundle = z5.object({
|
|
4791
|
+
runtime_context: z5.object({
|
|
4792
|
+
runtime: z5.enum(["node", "python"]),
|
|
4793
|
+
version: z5.string()
|
|
3828
4794
|
}),
|
|
3829
|
-
location:
|
|
3830
|
-
|
|
3831
|
-
type:
|
|
3832
|
-
eval_name:
|
|
3833
|
-
position:
|
|
3834
|
-
|
|
3835
|
-
|
|
4795
|
+
location: z5.union([
|
|
4796
|
+
z5.object({
|
|
4797
|
+
type: z5.literal("experiment"),
|
|
4798
|
+
eval_name: z5.string(),
|
|
4799
|
+
position: z5.union([
|
|
4800
|
+
z5.object({ type: z5.literal("task") }),
|
|
4801
|
+
z5.object({ type: z5.literal("scorer"), index: z5.number().int().gte(0) })
|
|
3836
4802
|
])
|
|
3837
4803
|
}),
|
|
3838
|
-
|
|
4804
|
+
z5.object({ type: z5.literal("function"), index: z5.number().int().gte(0) })
|
|
3839
4805
|
]),
|
|
3840
|
-
bundle_id:
|
|
3841
|
-
preview:
|
|
3842
|
-
});
|
|
3843
|
-
var Dataset =
|
|
3844
|
-
id:
|
|
3845
|
-
project_id:
|
|
3846
|
-
name:
|
|
3847
|
-
description:
|
|
3848
|
-
created:
|
|
3849
|
-
deleted_at:
|
|
3850
|
-
user_id:
|
|
3851
|
-
metadata:
|
|
3852
|
-
});
|
|
3853
|
-
var ObjectReferenceNullish =
|
|
3854
|
-
|
|
3855
|
-
object_type:
|
|
4806
|
+
bundle_id: z5.string(),
|
|
4807
|
+
preview: z5.union([z5.string(), z5.null()]).optional()
|
|
4808
|
+
});
|
|
4809
|
+
var Dataset = z5.object({
|
|
4810
|
+
id: z5.string().uuid(),
|
|
4811
|
+
project_id: z5.string().uuid(),
|
|
4812
|
+
name: z5.string(),
|
|
4813
|
+
description: z5.union([z5.string(), z5.null()]).optional(),
|
|
4814
|
+
created: z5.union([z5.string(), z5.null()]).optional(),
|
|
4815
|
+
deleted_at: z5.union([z5.string(), z5.null()]).optional(),
|
|
4816
|
+
user_id: z5.union([z5.string(), z5.null()]).optional(),
|
|
4817
|
+
metadata: z5.union([z5.object({}).partial().passthrough(), z5.null()]).optional()
|
|
4818
|
+
});
|
|
4819
|
+
var ObjectReferenceNullish = z5.union([
|
|
4820
|
+
z5.object({
|
|
4821
|
+
object_type: z5.enum([
|
|
3856
4822
|
"project_logs",
|
|
3857
4823
|
"experiment",
|
|
3858
4824
|
"dataset",
|
|
@@ -3860,399 +4826,399 @@ var ObjectReferenceNullish = z.union([
|
|
|
3860
4826
|
"function",
|
|
3861
4827
|
"prompt_session"
|
|
3862
4828
|
]),
|
|
3863
|
-
object_id:
|
|
3864
|
-
id:
|
|
3865
|
-
_xact_id:
|
|
3866
|
-
created:
|
|
4829
|
+
object_id: z5.string().uuid(),
|
|
4830
|
+
id: z5.string(),
|
|
4831
|
+
_xact_id: z5.union([z5.string(), z5.null()]).optional(),
|
|
4832
|
+
created: z5.union([z5.string(), z5.null()]).optional()
|
|
3867
4833
|
}),
|
|
3868
|
-
|
|
4834
|
+
z5.null()
|
|
3869
4835
|
]);
|
|
3870
|
-
var DatasetEvent =
|
|
3871
|
-
id:
|
|
3872
|
-
_xact_id:
|
|
3873
|
-
created:
|
|
3874
|
-
_pagination_key:
|
|
3875
|
-
project_id:
|
|
3876
|
-
dataset_id:
|
|
3877
|
-
input:
|
|
3878
|
-
expected:
|
|
3879
|
-
metadata:
|
|
3880
|
-
|
|
3881
|
-
|
|
4836
|
+
var DatasetEvent = z5.object({
|
|
4837
|
+
id: z5.string(),
|
|
4838
|
+
_xact_id: z5.string(),
|
|
4839
|
+
created: z5.string().datetime({ offset: true }),
|
|
4840
|
+
_pagination_key: z5.union([z5.string(), z5.null()]).optional(),
|
|
4841
|
+
project_id: z5.string().uuid(),
|
|
4842
|
+
dataset_id: z5.string().uuid(),
|
|
4843
|
+
input: z5.unknown().optional(),
|
|
4844
|
+
expected: z5.unknown().optional(),
|
|
4845
|
+
metadata: z5.union([
|
|
4846
|
+
z5.object({ model: z5.union([z5.string(), z5.null()]) }).partial().passthrough(),
|
|
4847
|
+
z5.null()
|
|
3882
4848
|
]).optional(),
|
|
3883
|
-
tags:
|
|
3884
|
-
span_id:
|
|
3885
|
-
root_span_id:
|
|
3886
|
-
is_root:
|
|
4849
|
+
tags: z5.union([z5.array(z5.string()), z5.null()]).optional(),
|
|
4850
|
+
span_id: z5.string(),
|
|
4851
|
+
root_span_id: z5.string(),
|
|
4852
|
+
is_root: z5.union([z5.boolean(), z5.null()]).optional(),
|
|
3887
4853
|
origin: ObjectReferenceNullish.optional()
|
|
3888
4854
|
});
|
|
3889
|
-
var EnvVar =
|
|
3890
|
-
id:
|
|
3891
|
-
object_type:
|
|
3892
|
-
object_id:
|
|
3893
|
-
name:
|
|
3894
|
-
created:
|
|
3895
|
-
used:
|
|
3896
|
-
});
|
|
3897
|
-
var RepoInfo =
|
|
3898
|
-
|
|
3899
|
-
commit:
|
|
3900
|
-
branch:
|
|
3901
|
-
tag:
|
|
3902
|
-
dirty:
|
|
3903
|
-
author_name:
|
|
3904
|
-
author_email:
|
|
3905
|
-
commit_message:
|
|
3906
|
-
commit_time:
|
|
3907
|
-
git_diff:
|
|
4855
|
+
var EnvVar = z5.object({
|
|
4856
|
+
id: z5.string().uuid(),
|
|
4857
|
+
object_type: z5.enum(["organization", "project", "function"]),
|
|
4858
|
+
object_id: z5.string().uuid(),
|
|
4859
|
+
name: z5.string(),
|
|
4860
|
+
created: z5.union([z5.string(), z5.null()]).optional(),
|
|
4861
|
+
used: z5.union([z5.string(), z5.null()]).optional()
|
|
4862
|
+
});
|
|
4863
|
+
var RepoInfo = z5.union([
|
|
4864
|
+
z5.object({
|
|
4865
|
+
commit: z5.union([z5.string(), z5.null()]),
|
|
4866
|
+
branch: z5.union([z5.string(), z5.null()]),
|
|
4867
|
+
tag: z5.union([z5.string(), z5.null()]),
|
|
4868
|
+
dirty: z5.union([z5.boolean(), z5.null()]),
|
|
4869
|
+
author_name: z5.union([z5.string(), z5.null()]),
|
|
4870
|
+
author_email: z5.union([z5.string(), z5.null()]),
|
|
4871
|
+
commit_message: z5.union([z5.string(), z5.null()]),
|
|
4872
|
+
commit_time: z5.union([z5.string(), z5.null()]),
|
|
4873
|
+
git_diff: z5.union([z5.string(), z5.null()])
|
|
3908
4874
|
}).partial(),
|
|
3909
|
-
|
|
4875
|
+
z5.null()
|
|
3910
4876
|
]);
|
|
3911
|
-
var Experiment =
|
|
3912
|
-
id:
|
|
3913
|
-
project_id:
|
|
3914
|
-
name:
|
|
3915
|
-
description:
|
|
3916
|
-
created:
|
|
4877
|
+
var Experiment = z5.object({
|
|
4878
|
+
id: z5.string().uuid(),
|
|
4879
|
+
project_id: z5.string().uuid(),
|
|
4880
|
+
name: z5.string(),
|
|
4881
|
+
description: z5.union([z5.string(), z5.null()]).optional(),
|
|
4882
|
+
created: z5.union([z5.string(), z5.null()]).optional(),
|
|
3917
4883
|
repo_info: RepoInfo.optional(),
|
|
3918
|
-
commit:
|
|
3919
|
-
base_exp_id:
|
|
3920
|
-
deleted_at:
|
|
3921
|
-
dataset_id:
|
|
3922
|
-
dataset_version:
|
|
3923
|
-
public:
|
|
3924
|
-
user_id:
|
|
3925
|
-
metadata:
|
|
3926
|
-
tags:
|
|
3927
|
-
});
|
|
3928
|
-
var SpanType =
|
|
3929
|
-
|
|
3930
|
-
|
|
4884
|
+
commit: z5.union([z5.string(), z5.null()]).optional(),
|
|
4885
|
+
base_exp_id: z5.union([z5.string(), z5.null()]).optional(),
|
|
4886
|
+
deleted_at: z5.union([z5.string(), z5.null()]).optional(),
|
|
4887
|
+
dataset_id: z5.union([z5.string(), z5.null()]).optional(),
|
|
4888
|
+
dataset_version: z5.union([z5.string(), z5.null()]).optional(),
|
|
4889
|
+
public: z5.boolean(),
|
|
4890
|
+
user_id: z5.union([z5.string(), z5.null()]).optional(),
|
|
4891
|
+
metadata: z5.union([z5.object({}).partial().passthrough(), z5.null()]).optional(),
|
|
4892
|
+
tags: z5.union([z5.array(z5.string()), z5.null()]).optional()
|
|
4893
|
+
});
|
|
4894
|
+
var SpanType = z5.union([
|
|
4895
|
+
z5.enum(["llm", "score", "function", "eval", "task", "tool"]),
|
|
4896
|
+
z5.null()
|
|
3931
4897
|
]);
|
|
3932
|
-
var SpanAttributes =
|
|
3933
|
-
|
|
3934
|
-
|
|
4898
|
+
var SpanAttributes = z5.union([
|
|
4899
|
+
z5.object({ name: z5.union([z5.string(), z5.null()]), type: SpanType }).partial().passthrough(),
|
|
4900
|
+
z5.null()
|
|
3935
4901
|
]);
|
|
3936
|
-
var ExperimentEvent =
|
|
3937
|
-
id:
|
|
3938
|
-
_xact_id:
|
|
3939
|
-
created:
|
|
3940
|
-
_pagination_key:
|
|
3941
|
-
project_id:
|
|
3942
|
-
experiment_id:
|
|
3943
|
-
input:
|
|
3944
|
-
output:
|
|
3945
|
-
expected:
|
|
3946
|
-
error:
|
|
3947
|
-
scores:
|
|
3948
|
-
metadata:
|
|
3949
|
-
|
|
3950
|
-
|
|
4902
|
+
var ExperimentEvent = z5.object({
|
|
4903
|
+
id: z5.string(),
|
|
4904
|
+
_xact_id: z5.string(),
|
|
4905
|
+
created: z5.string().datetime({ offset: true }),
|
|
4906
|
+
_pagination_key: z5.union([z5.string(), z5.null()]).optional(),
|
|
4907
|
+
project_id: z5.string().uuid(),
|
|
4908
|
+
experiment_id: z5.string().uuid(),
|
|
4909
|
+
input: z5.unknown().optional(),
|
|
4910
|
+
output: z5.unknown().optional(),
|
|
4911
|
+
expected: z5.unknown().optional(),
|
|
4912
|
+
error: z5.unknown().optional(),
|
|
4913
|
+
scores: z5.union([z5.record(z5.union([z5.number(), z5.null()])), z5.null()]).optional(),
|
|
4914
|
+
metadata: z5.union([
|
|
4915
|
+
z5.object({ model: z5.union([z5.string(), z5.null()]) }).partial().passthrough(),
|
|
4916
|
+
z5.null()
|
|
3951
4917
|
]).optional(),
|
|
3952
|
-
tags:
|
|
3953
|
-
metrics:
|
|
3954
|
-
context:
|
|
3955
|
-
|
|
3956
|
-
caller_functionname:
|
|
3957
|
-
caller_filename:
|
|
3958
|
-
caller_lineno:
|
|
4918
|
+
tags: z5.union([z5.array(z5.string()), z5.null()]).optional(),
|
|
4919
|
+
metrics: z5.union([z5.record(z5.number()), z5.null()]).optional(),
|
|
4920
|
+
context: z5.union([
|
|
4921
|
+
z5.object({
|
|
4922
|
+
caller_functionname: z5.union([z5.string(), z5.null()]),
|
|
4923
|
+
caller_filename: z5.union([z5.string(), z5.null()]),
|
|
4924
|
+
caller_lineno: z5.union([z5.number(), z5.null()])
|
|
3959
4925
|
}).partial().passthrough(),
|
|
3960
|
-
|
|
4926
|
+
z5.null()
|
|
3961
4927
|
]).optional(),
|
|
3962
|
-
span_id:
|
|
3963
|
-
span_parents:
|
|
3964
|
-
root_span_id:
|
|
4928
|
+
span_id: z5.string(),
|
|
4929
|
+
span_parents: z5.union([z5.array(z5.string()), z5.null()]).optional(),
|
|
4930
|
+
root_span_id: z5.string(),
|
|
3965
4931
|
span_attributes: SpanAttributes.optional(),
|
|
3966
|
-
is_root:
|
|
4932
|
+
is_root: z5.union([z5.boolean(), z5.null()]).optional(),
|
|
3967
4933
|
origin: ObjectReferenceNullish.optional()
|
|
3968
4934
|
});
|
|
3969
|
-
var ExtendedSavedFunctionId =
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
|
|
3973
|
-
type:
|
|
3974
|
-
project_id:
|
|
3975
|
-
slug:
|
|
4935
|
+
var ExtendedSavedFunctionId = z5.union([
|
|
4936
|
+
z5.object({ type: z5.literal("function"), id: z5.string() }),
|
|
4937
|
+
z5.object({ type: z5.literal("global"), name: z5.string() }),
|
|
4938
|
+
z5.object({
|
|
4939
|
+
type: z5.literal("slug"),
|
|
4940
|
+
project_id: z5.string(),
|
|
4941
|
+
slug: z5.string()
|
|
3976
4942
|
})
|
|
3977
4943
|
]);
|
|
3978
|
-
var PromptBlockDataNullish =
|
|
3979
|
-
|
|
3980
|
-
|
|
3981
|
-
type:
|
|
3982
|
-
messages:
|
|
3983
|
-
tools:
|
|
4944
|
+
var PromptBlockDataNullish = z5.union([
|
|
4945
|
+
z5.object({ type: z5.literal("completion"), content: z5.string() }),
|
|
4946
|
+
z5.object({
|
|
4947
|
+
type: z5.literal("chat"),
|
|
4948
|
+
messages: z5.array(ChatCompletionMessageParam),
|
|
4949
|
+
tools: z5.string().optional()
|
|
3984
4950
|
}),
|
|
3985
|
-
|
|
4951
|
+
z5.null()
|
|
3986
4952
|
]);
|
|
3987
|
-
var ModelParams =
|
|
3988
|
-
|
|
3989
|
-
use_cache:
|
|
3990
|
-
temperature:
|
|
3991
|
-
top_p:
|
|
3992
|
-
max_tokens:
|
|
3993
|
-
max_completion_tokens:
|
|
3994
|
-
frequency_penalty:
|
|
3995
|
-
presence_penalty:
|
|
4953
|
+
var ModelParams = z5.union([
|
|
4954
|
+
z5.object({
|
|
4955
|
+
use_cache: z5.boolean(),
|
|
4956
|
+
temperature: z5.number(),
|
|
4957
|
+
top_p: z5.number(),
|
|
4958
|
+
max_tokens: z5.number(),
|
|
4959
|
+
max_completion_tokens: z5.number(),
|
|
4960
|
+
frequency_penalty: z5.number(),
|
|
4961
|
+
presence_penalty: z5.number(),
|
|
3996
4962
|
response_format: ResponseFormatNullish,
|
|
3997
|
-
tool_choice:
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
type:
|
|
4003
|
-
function:
|
|
4963
|
+
tool_choice: z5.union([
|
|
4964
|
+
z5.literal("auto"),
|
|
4965
|
+
z5.literal("none"),
|
|
4966
|
+
z5.literal("required"),
|
|
4967
|
+
z5.object({
|
|
4968
|
+
type: z5.literal("function"),
|
|
4969
|
+
function: z5.object({ name: z5.string() })
|
|
4004
4970
|
})
|
|
4005
4971
|
]),
|
|
4006
|
-
function_call:
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4972
|
+
function_call: z5.union([
|
|
4973
|
+
z5.literal("auto"),
|
|
4974
|
+
z5.literal("none"),
|
|
4975
|
+
z5.object({ name: z5.string() })
|
|
4010
4976
|
]),
|
|
4011
|
-
n:
|
|
4012
|
-
stop:
|
|
4013
|
-
reasoning_effort:
|
|
4014
|
-
verbosity:
|
|
4977
|
+
n: z5.number(),
|
|
4978
|
+
stop: z5.array(z5.string()),
|
|
4979
|
+
reasoning_effort: z5.enum(["minimal", "low", "medium", "high"]),
|
|
4980
|
+
verbosity: z5.enum(["low", "medium", "high"])
|
|
4015
4981
|
}).partial().passthrough(),
|
|
4016
|
-
|
|
4017
|
-
use_cache:
|
|
4018
|
-
max_tokens:
|
|
4019
|
-
temperature:
|
|
4020
|
-
top_p:
|
|
4021
|
-
top_k:
|
|
4022
|
-
stop_sequences:
|
|
4023
|
-
max_tokens_to_sample:
|
|
4982
|
+
z5.object({
|
|
4983
|
+
use_cache: z5.boolean().optional(),
|
|
4984
|
+
max_tokens: z5.number(),
|
|
4985
|
+
temperature: z5.number(),
|
|
4986
|
+
top_p: z5.number().optional(),
|
|
4987
|
+
top_k: z5.number().optional(),
|
|
4988
|
+
stop_sequences: z5.array(z5.string()).optional(),
|
|
4989
|
+
max_tokens_to_sample: z5.number().optional()
|
|
4024
4990
|
}).passthrough(),
|
|
4025
|
-
|
|
4026
|
-
use_cache:
|
|
4027
|
-
temperature:
|
|
4028
|
-
maxOutputTokens:
|
|
4029
|
-
topP:
|
|
4030
|
-
topK:
|
|
4991
|
+
z5.object({
|
|
4992
|
+
use_cache: z5.boolean(),
|
|
4993
|
+
temperature: z5.number(),
|
|
4994
|
+
maxOutputTokens: z5.number(),
|
|
4995
|
+
topP: z5.number(),
|
|
4996
|
+
topK: z5.number()
|
|
4031
4997
|
}).partial().passthrough(),
|
|
4032
|
-
|
|
4033
|
-
use_cache:
|
|
4034
|
-
temperature:
|
|
4035
|
-
topK:
|
|
4998
|
+
z5.object({
|
|
4999
|
+
use_cache: z5.boolean(),
|
|
5000
|
+
temperature: z5.number(),
|
|
5001
|
+
topK: z5.number()
|
|
4036
5002
|
}).partial().passthrough(),
|
|
4037
|
-
|
|
5003
|
+
z5.object({ use_cache: z5.boolean() }).partial().passthrough()
|
|
4038
5004
|
]);
|
|
4039
|
-
var PromptOptionsNullish =
|
|
4040
|
-
|
|
4041
|
-
|
|
5005
|
+
var PromptOptionsNullish = z5.union([
|
|
5006
|
+
z5.object({ model: z5.string(), params: ModelParams, position: z5.string() }).partial(),
|
|
5007
|
+
z5.null()
|
|
4042
5008
|
]);
|
|
4043
|
-
var PromptParserNullish =
|
|
4044
|
-
|
|
4045
|
-
type:
|
|
4046
|
-
use_cot:
|
|
4047
|
-
choice_scores:
|
|
5009
|
+
var PromptParserNullish = z5.union([
|
|
5010
|
+
z5.object({
|
|
5011
|
+
type: z5.literal("llm_classifier"),
|
|
5012
|
+
use_cot: z5.boolean(),
|
|
5013
|
+
choice_scores: z5.record(z5.number().gte(0).lte(1))
|
|
4048
5014
|
}),
|
|
4049
|
-
|
|
5015
|
+
z5.null()
|
|
4050
5016
|
]);
|
|
4051
|
-
var SavedFunctionId =
|
|
4052
|
-
|
|
4053
|
-
|
|
5017
|
+
var SavedFunctionId = z5.union([
|
|
5018
|
+
z5.object({ type: z5.literal("function"), id: z5.string() }),
|
|
5019
|
+
z5.object({ type: z5.literal("global"), name: z5.string() })
|
|
4054
5020
|
]);
|
|
4055
|
-
var PromptDataNullish =
|
|
4056
|
-
|
|
5021
|
+
var PromptDataNullish = z5.union([
|
|
5022
|
+
z5.object({
|
|
4057
5023
|
prompt: PromptBlockDataNullish,
|
|
4058
5024
|
options: PromptOptionsNullish,
|
|
4059
5025
|
parser: PromptParserNullish,
|
|
4060
|
-
tool_functions:
|
|
4061
|
-
origin:
|
|
4062
|
-
|
|
4063
|
-
prompt_id:
|
|
4064
|
-
project_id:
|
|
4065
|
-
prompt_version:
|
|
5026
|
+
tool_functions: z5.union([z5.array(SavedFunctionId), z5.null()]),
|
|
5027
|
+
origin: z5.union([
|
|
5028
|
+
z5.object({
|
|
5029
|
+
prompt_id: z5.string(),
|
|
5030
|
+
project_id: z5.string(),
|
|
5031
|
+
prompt_version: z5.string()
|
|
4066
5032
|
}).partial(),
|
|
4067
|
-
|
|
5033
|
+
z5.null()
|
|
4068
5034
|
])
|
|
4069
5035
|
}).partial(),
|
|
4070
|
-
|
|
5036
|
+
z5.null()
|
|
4071
5037
|
]);
|
|
4072
|
-
var FunctionTypeEnumNullish =
|
|
4073
|
-
|
|
4074
|
-
|
|
5038
|
+
var FunctionTypeEnumNullish = z5.union([
|
|
5039
|
+
z5.enum(["llm", "scorer", "task", "tool"]),
|
|
5040
|
+
z5.null()
|
|
4075
5041
|
]);
|
|
4076
|
-
var FunctionIdRef =
|
|
4077
|
-
var PromptBlockData =
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
type:
|
|
4081
|
-
messages:
|
|
4082
|
-
tools:
|
|
5042
|
+
var FunctionIdRef = z5.object({}).partial().passthrough();
|
|
5043
|
+
var PromptBlockData = z5.union([
|
|
5044
|
+
z5.object({ type: z5.literal("completion"), content: z5.string() }),
|
|
5045
|
+
z5.object({
|
|
5046
|
+
type: z5.literal("chat"),
|
|
5047
|
+
messages: z5.array(ChatCompletionMessageParam),
|
|
5048
|
+
tools: z5.string().optional()
|
|
4083
5049
|
})
|
|
4084
5050
|
]);
|
|
4085
|
-
var GraphNode =
|
|
4086
|
-
|
|
4087
|
-
description:
|
|
4088
|
-
position:
|
|
4089
|
-
type:
|
|
5051
|
+
var GraphNode = z5.union([
|
|
5052
|
+
z5.object({
|
|
5053
|
+
description: z5.union([z5.string(), z5.null()]).optional(),
|
|
5054
|
+
position: z5.union([z5.object({ x: z5.number(), y: z5.number() }), z5.null()]).optional(),
|
|
5055
|
+
type: z5.literal("function"),
|
|
4090
5056
|
function: FunctionIdRef
|
|
4091
5057
|
}),
|
|
4092
|
-
|
|
4093
|
-
description:
|
|
4094
|
-
position:
|
|
4095
|
-
type:
|
|
5058
|
+
z5.object({
|
|
5059
|
+
description: z5.union([z5.string(), z5.null()]).optional(),
|
|
5060
|
+
position: z5.union([z5.object({ x: z5.number(), y: z5.number() }), z5.null()]).optional(),
|
|
5061
|
+
type: z5.literal("input")
|
|
4096
5062
|
}),
|
|
4097
|
-
|
|
4098
|
-
description:
|
|
4099
|
-
position:
|
|
4100
|
-
type:
|
|
5063
|
+
z5.object({
|
|
5064
|
+
description: z5.union([z5.string(), z5.null()]).optional(),
|
|
5065
|
+
position: z5.union([z5.object({ x: z5.number(), y: z5.number() }), z5.null()]).optional(),
|
|
5066
|
+
type: z5.literal("output")
|
|
4101
5067
|
}),
|
|
4102
|
-
|
|
4103
|
-
description:
|
|
4104
|
-
position:
|
|
4105
|
-
type:
|
|
4106
|
-
value:
|
|
5068
|
+
z5.object({
|
|
5069
|
+
description: z5.union([z5.string(), z5.null()]).optional(),
|
|
5070
|
+
position: z5.union([z5.object({ x: z5.number(), y: z5.number() }), z5.null()]).optional(),
|
|
5071
|
+
type: z5.literal("literal"),
|
|
5072
|
+
value: z5.unknown().optional()
|
|
4107
5073
|
}),
|
|
4108
|
-
|
|
4109
|
-
description:
|
|
4110
|
-
position:
|
|
4111
|
-
type:
|
|
4112
|
-
expr:
|
|
5074
|
+
z5.object({
|
|
5075
|
+
description: z5.union([z5.string(), z5.null()]).optional(),
|
|
5076
|
+
position: z5.union([z5.object({ x: z5.number(), y: z5.number() }), z5.null()]).optional(),
|
|
5077
|
+
type: z5.literal("btql"),
|
|
5078
|
+
expr: z5.string()
|
|
4113
5079
|
}),
|
|
4114
|
-
|
|
4115
|
-
description:
|
|
4116
|
-
position:
|
|
4117
|
-
type:
|
|
4118
|
-
condition:
|
|
5080
|
+
z5.object({
|
|
5081
|
+
description: z5.union([z5.string(), z5.null()]).optional(),
|
|
5082
|
+
position: z5.union([z5.object({ x: z5.number(), y: z5.number() }), z5.null()]).optional(),
|
|
5083
|
+
type: z5.literal("gate"),
|
|
5084
|
+
condition: z5.union([z5.string(), z5.null()]).optional()
|
|
4119
5085
|
}),
|
|
4120
|
-
|
|
4121
|
-
description:
|
|
4122
|
-
position:
|
|
4123
|
-
type:
|
|
5086
|
+
z5.object({
|
|
5087
|
+
description: z5.union([z5.string(), z5.null()]).optional(),
|
|
5088
|
+
position: z5.union([z5.object({ x: z5.number(), y: z5.number() }), z5.null()]).optional(),
|
|
5089
|
+
type: z5.literal("aggregator")
|
|
4124
5090
|
}),
|
|
4125
|
-
|
|
4126
|
-
description:
|
|
4127
|
-
position:
|
|
4128
|
-
type:
|
|
5091
|
+
z5.object({
|
|
5092
|
+
description: z5.union([z5.string(), z5.null()]).optional(),
|
|
5093
|
+
position: z5.union([z5.object({ x: z5.number(), y: z5.number() }), z5.null()]).optional(),
|
|
5094
|
+
type: z5.literal("prompt_template"),
|
|
4129
5095
|
prompt: PromptBlockData
|
|
4130
5096
|
})
|
|
4131
5097
|
]);
|
|
4132
|
-
var GraphEdge =
|
|
4133
|
-
source:
|
|
4134
|
-
target:
|
|
4135
|
-
purpose:
|
|
4136
|
-
});
|
|
4137
|
-
var GraphData =
|
|
4138
|
-
type:
|
|
4139
|
-
nodes:
|
|
4140
|
-
edges:
|
|
4141
|
-
});
|
|
4142
|
-
var FunctionData =
|
|
4143
|
-
|
|
4144
|
-
|
|
4145
|
-
type:
|
|
4146
|
-
data:
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
type:
|
|
4150
|
-
runtime_context:
|
|
4151
|
-
runtime:
|
|
4152
|
-
version:
|
|
5098
|
+
var GraphEdge = z5.object({
|
|
5099
|
+
source: z5.object({ node: z5.string().max(1024), variable: z5.string() }),
|
|
5100
|
+
target: z5.object({ node: z5.string().max(1024), variable: z5.string() }),
|
|
5101
|
+
purpose: z5.enum(["control", "data", "messages"])
|
|
5102
|
+
});
|
|
5103
|
+
var GraphData = z5.object({
|
|
5104
|
+
type: z5.literal("graph"),
|
|
5105
|
+
nodes: z5.record(GraphNode),
|
|
5106
|
+
edges: z5.record(GraphEdge)
|
|
5107
|
+
});
|
|
5108
|
+
var FunctionData = z5.union([
|
|
5109
|
+
z5.object({ type: z5.literal("prompt") }),
|
|
5110
|
+
z5.object({
|
|
5111
|
+
type: z5.literal("code"),
|
|
5112
|
+
data: z5.union([
|
|
5113
|
+
z5.object({ type: z5.literal("bundle") }).and(CodeBundle),
|
|
5114
|
+
z5.object({
|
|
5115
|
+
type: z5.literal("inline"),
|
|
5116
|
+
runtime_context: z5.object({
|
|
5117
|
+
runtime: z5.enum(["node", "python"]),
|
|
5118
|
+
version: z5.string()
|
|
4153
5119
|
}),
|
|
4154
|
-
code:
|
|
5120
|
+
code: z5.string()
|
|
4155
5121
|
})
|
|
4156
5122
|
])
|
|
4157
5123
|
}),
|
|
4158
5124
|
GraphData,
|
|
4159
|
-
|
|
4160
|
-
type:
|
|
4161
|
-
endpoint:
|
|
4162
|
-
eval_name:
|
|
4163
|
-
parameters:
|
|
5125
|
+
z5.object({
|
|
5126
|
+
type: z5.literal("remote_eval"),
|
|
5127
|
+
endpoint: z5.string(),
|
|
5128
|
+
eval_name: z5.string(),
|
|
5129
|
+
parameters: z5.object({}).partial().passthrough()
|
|
4164
5130
|
}),
|
|
4165
|
-
|
|
5131
|
+
z5.object({ type: z5.literal("global"), name: z5.string() })
|
|
4166
5132
|
]);
|
|
4167
|
-
var Function2 =
|
|
4168
|
-
id:
|
|
4169
|
-
_xact_id:
|
|
4170
|
-
project_id:
|
|
4171
|
-
log_id:
|
|
4172
|
-
org_id:
|
|
4173
|
-
name:
|
|
4174
|
-
slug:
|
|
4175
|
-
description:
|
|
4176
|
-
created:
|
|
5133
|
+
var Function2 = z5.object({
|
|
5134
|
+
id: z5.string().uuid(),
|
|
5135
|
+
_xact_id: z5.string(),
|
|
5136
|
+
project_id: z5.string().uuid(),
|
|
5137
|
+
log_id: z5.literal("p"),
|
|
5138
|
+
org_id: z5.string().uuid(),
|
|
5139
|
+
name: z5.string(),
|
|
5140
|
+
slug: z5.string(),
|
|
5141
|
+
description: z5.union([z5.string(), z5.null()]).optional(),
|
|
5142
|
+
created: z5.union([z5.string(), z5.null()]).optional(),
|
|
4177
5143
|
prompt_data: PromptDataNullish.optional(),
|
|
4178
|
-
tags:
|
|
4179
|
-
metadata:
|
|
5144
|
+
tags: z5.union([z5.array(z5.string()), z5.null()]).optional(),
|
|
5145
|
+
metadata: z5.union([z5.object({}).partial().passthrough(), z5.null()]).optional(),
|
|
4180
5146
|
function_type: FunctionTypeEnumNullish.optional(),
|
|
4181
5147
|
function_data: FunctionData,
|
|
4182
|
-
origin:
|
|
4183
|
-
|
|
4184
|
-
object_type: AclObjectType.and(
|
|
4185
|
-
object_id:
|
|
4186
|
-
internal:
|
|
5148
|
+
origin: z5.union([
|
|
5149
|
+
z5.object({
|
|
5150
|
+
object_type: AclObjectType.and(z5.string()),
|
|
5151
|
+
object_id: z5.string().uuid(),
|
|
5152
|
+
internal: z5.union([z5.boolean(), z5.null()]).optional()
|
|
4187
5153
|
}),
|
|
4188
|
-
|
|
5154
|
+
z5.null()
|
|
4189
5155
|
]).optional(),
|
|
4190
|
-
function_schema:
|
|
4191
|
-
|
|
4192
|
-
|
|
5156
|
+
function_schema: z5.union([
|
|
5157
|
+
z5.object({ parameters: z5.unknown(), returns: z5.unknown() }).partial(),
|
|
5158
|
+
z5.null()
|
|
4193
5159
|
]).optional()
|
|
4194
5160
|
});
|
|
4195
|
-
var FunctionFormat =
|
|
4196
|
-
var PromptData =
|
|
5161
|
+
var FunctionFormat = z5.enum(["llm", "code", "global", "graph"]);
|
|
5162
|
+
var PromptData = z5.object({
|
|
4197
5163
|
prompt: PromptBlockDataNullish,
|
|
4198
5164
|
options: PromptOptionsNullish,
|
|
4199
5165
|
parser: PromptParserNullish,
|
|
4200
|
-
tool_functions:
|
|
4201
|
-
origin:
|
|
4202
|
-
|
|
4203
|
-
prompt_id:
|
|
4204
|
-
project_id:
|
|
4205
|
-
prompt_version:
|
|
5166
|
+
tool_functions: z5.union([z5.array(SavedFunctionId), z5.null()]),
|
|
5167
|
+
origin: z5.union([
|
|
5168
|
+
z5.object({
|
|
5169
|
+
prompt_id: z5.string(),
|
|
5170
|
+
project_id: z5.string(),
|
|
5171
|
+
prompt_version: z5.string()
|
|
4206
5172
|
}).partial(),
|
|
4207
|
-
|
|
5173
|
+
z5.null()
|
|
4208
5174
|
])
|
|
4209
5175
|
}).partial();
|
|
4210
|
-
var FunctionTypeEnum =
|
|
4211
|
-
var FunctionId =
|
|
4212
|
-
|
|
4213
|
-
|
|
4214
|
-
project_name:
|
|
4215
|
-
slug:
|
|
4216
|
-
version:
|
|
5176
|
+
var FunctionTypeEnum = z5.enum(["llm", "scorer", "task", "tool"]);
|
|
5177
|
+
var FunctionId = z5.union([
|
|
5178
|
+
z5.object({ function_id: z5.string(), version: z5.string().optional() }),
|
|
5179
|
+
z5.object({
|
|
5180
|
+
project_name: z5.string(),
|
|
5181
|
+
slug: z5.string(),
|
|
5182
|
+
version: z5.string().optional()
|
|
4217
5183
|
}),
|
|
4218
|
-
|
|
4219
|
-
|
|
4220
|
-
prompt_session_id:
|
|
4221
|
-
prompt_session_function_id:
|
|
4222
|
-
version:
|
|
5184
|
+
z5.object({ global_function: z5.string() }),
|
|
5185
|
+
z5.object({
|
|
5186
|
+
prompt_session_id: z5.string(),
|
|
5187
|
+
prompt_session_function_id: z5.string(),
|
|
5188
|
+
version: z5.string().optional()
|
|
4223
5189
|
}),
|
|
4224
|
-
|
|
4225
|
-
inline_context:
|
|
4226
|
-
runtime:
|
|
4227
|
-
version:
|
|
5190
|
+
z5.object({
|
|
5191
|
+
inline_context: z5.object({
|
|
5192
|
+
runtime: z5.enum(["node", "python"]),
|
|
5193
|
+
version: z5.string()
|
|
4228
5194
|
}),
|
|
4229
|
-
code:
|
|
4230
|
-
name:
|
|
5195
|
+
code: z5.string(),
|
|
5196
|
+
name: z5.union([z5.string(), z5.null()]).optional()
|
|
4231
5197
|
}),
|
|
4232
|
-
|
|
5198
|
+
z5.object({
|
|
4233
5199
|
inline_prompt: PromptData.optional(),
|
|
4234
|
-
inline_function:
|
|
5200
|
+
inline_function: z5.object({}).partial().passthrough(),
|
|
4235
5201
|
function_type: FunctionTypeEnum.optional(),
|
|
4236
|
-
name:
|
|
5202
|
+
name: z5.union([z5.string(), z5.null()]).optional()
|
|
4237
5203
|
}),
|
|
4238
|
-
|
|
5204
|
+
z5.object({
|
|
4239
5205
|
inline_prompt: PromptData,
|
|
4240
5206
|
function_type: FunctionTypeEnum.optional(),
|
|
4241
|
-
name:
|
|
5207
|
+
name: z5.union([z5.string(), z5.null()]).optional()
|
|
4242
5208
|
})
|
|
4243
5209
|
]);
|
|
4244
|
-
var FunctionObjectType =
|
|
5210
|
+
var FunctionObjectType = z5.enum([
|
|
4245
5211
|
"prompt",
|
|
4246
5212
|
"tool",
|
|
4247
5213
|
"scorer",
|
|
4248
5214
|
"task",
|
|
4249
5215
|
"agent"
|
|
4250
5216
|
]);
|
|
4251
|
-
var FunctionOutputType =
|
|
4252
|
-
var GitMetadataSettings =
|
|
4253
|
-
collect:
|
|
4254
|
-
fields:
|
|
4255
|
-
|
|
5217
|
+
var FunctionOutputType = z5.enum(["completion", "score", "any"]);
|
|
5218
|
+
var GitMetadataSettings = z5.object({
|
|
5219
|
+
collect: z5.enum(["all", "none", "some"]),
|
|
5220
|
+
fields: z5.array(
|
|
5221
|
+
z5.enum([
|
|
4256
5222
|
"commit",
|
|
4257
5223
|
"branch",
|
|
4258
5224
|
"tag",
|
|
@@ -4265,49 +5231,49 @@ var GitMetadataSettings = z.object({
|
|
|
4265
5231
|
])
|
|
4266
5232
|
).optional()
|
|
4267
5233
|
});
|
|
4268
|
-
var Group =
|
|
4269
|
-
id:
|
|
4270
|
-
org_id:
|
|
4271
|
-
user_id:
|
|
4272
|
-
created:
|
|
4273
|
-
name:
|
|
4274
|
-
description:
|
|
4275
|
-
deleted_at:
|
|
4276
|
-
member_users:
|
|
4277
|
-
member_groups:
|
|
4278
|
-
});
|
|
4279
|
-
var IfExists =
|
|
4280
|
-
var InvokeParent =
|
|
4281
|
-
|
|
4282
|
-
object_type:
|
|
4283
|
-
object_id:
|
|
4284
|
-
row_ids:
|
|
4285
|
-
|
|
4286
|
-
id:
|
|
4287
|
-
span_id:
|
|
4288
|
-
root_span_id:
|
|
5234
|
+
var Group = z5.object({
|
|
5235
|
+
id: z5.string().uuid(),
|
|
5236
|
+
org_id: z5.string().uuid(),
|
|
5237
|
+
user_id: z5.union([z5.string(), z5.null()]).optional(),
|
|
5238
|
+
created: z5.union([z5.string(), z5.null()]).optional(),
|
|
5239
|
+
name: z5.string(),
|
|
5240
|
+
description: z5.union([z5.string(), z5.null()]).optional(),
|
|
5241
|
+
deleted_at: z5.union([z5.string(), z5.null()]).optional(),
|
|
5242
|
+
member_users: z5.union([z5.array(z5.string().uuid()), z5.null()]).optional(),
|
|
5243
|
+
member_groups: z5.union([z5.array(z5.string().uuid()), z5.null()]).optional()
|
|
5244
|
+
});
|
|
5245
|
+
var IfExists = z5.enum(["error", "ignore", "replace"]);
|
|
5246
|
+
var InvokeParent = z5.union([
|
|
5247
|
+
z5.object({
|
|
5248
|
+
object_type: z5.enum(["project_logs", "experiment", "playground_logs"]),
|
|
5249
|
+
object_id: z5.string(),
|
|
5250
|
+
row_ids: z5.union([
|
|
5251
|
+
z5.object({
|
|
5252
|
+
id: z5.string(),
|
|
5253
|
+
span_id: z5.string(),
|
|
5254
|
+
root_span_id: z5.string()
|
|
4289
5255
|
}),
|
|
4290
|
-
|
|
5256
|
+
z5.null()
|
|
4291
5257
|
]).optional(),
|
|
4292
|
-
propagated_event:
|
|
5258
|
+
propagated_event: z5.union([z5.object({}).partial().passthrough(), z5.null()]).optional()
|
|
4293
5259
|
}),
|
|
4294
|
-
|
|
5260
|
+
z5.string()
|
|
4295
5261
|
]);
|
|
4296
|
-
var StreamingMode =
|
|
5262
|
+
var StreamingMode = z5.union([z5.enum(["auto", "parallel"]), z5.null()]);
|
|
4297
5263
|
var InvokeFunction = FunctionId.and(
|
|
4298
|
-
|
|
4299
|
-
input:
|
|
4300
|
-
expected:
|
|
4301
|
-
metadata:
|
|
4302
|
-
tags:
|
|
4303
|
-
messages:
|
|
5264
|
+
z5.object({
|
|
5265
|
+
input: z5.unknown(),
|
|
5266
|
+
expected: z5.unknown(),
|
|
5267
|
+
metadata: z5.union([z5.object({}).partial().passthrough(), z5.null()]),
|
|
5268
|
+
tags: z5.union([z5.array(z5.string()), z5.null()]),
|
|
5269
|
+
messages: z5.array(ChatCompletionMessageParam),
|
|
4304
5270
|
parent: InvokeParent,
|
|
4305
|
-
stream:
|
|
5271
|
+
stream: z5.union([z5.boolean(), z5.null()]),
|
|
4306
5272
|
mode: StreamingMode,
|
|
4307
|
-
strict:
|
|
5273
|
+
strict: z5.union([z5.boolean(), z5.null()])
|
|
4308
5274
|
}).partial()
|
|
4309
5275
|
);
|
|
4310
|
-
var MessageRole =
|
|
5276
|
+
var MessageRole = z5.enum([
|
|
4311
5277
|
"system",
|
|
4312
5278
|
"user",
|
|
4313
5279
|
"assistant",
|
|
@@ -4316,8 +5282,8 @@ var MessageRole = z.enum([
|
|
|
4316
5282
|
"model",
|
|
4317
5283
|
"developer"
|
|
4318
5284
|
]);
|
|
4319
|
-
var ObjectReference =
|
|
4320
|
-
object_type:
|
|
5285
|
+
var ObjectReference = z5.object({
|
|
5286
|
+
object_type: z5.enum([
|
|
4321
5287
|
"project_logs",
|
|
4322
5288
|
"experiment",
|
|
4323
5289
|
"dataset",
|
|
@@ -4325,146 +5291,146 @@ var ObjectReference = z.object({
|
|
|
4325
5291
|
"function",
|
|
4326
5292
|
"prompt_session"
|
|
4327
5293
|
]),
|
|
4328
|
-
object_id:
|
|
4329
|
-
id:
|
|
4330
|
-
_xact_id:
|
|
4331
|
-
created:
|
|
4332
|
-
});
|
|
4333
|
-
var OnlineScoreConfig =
|
|
4334
|
-
|
|
4335
|
-
sampling_rate:
|
|
4336
|
-
scorers:
|
|
4337
|
-
btql_filter:
|
|
4338
|
-
apply_to_root_span:
|
|
4339
|
-
apply_to_span_names:
|
|
4340
|
-
skip_logging:
|
|
5294
|
+
object_id: z5.string().uuid(),
|
|
5295
|
+
id: z5.string(),
|
|
5296
|
+
_xact_id: z5.union([z5.string(), z5.null()]).optional(),
|
|
5297
|
+
created: z5.union([z5.string(), z5.null()]).optional()
|
|
5298
|
+
});
|
|
5299
|
+
var OnlineScoreConfig = z5.union([
|
|
5300
|
+
z5.object({
|
|
5301
|
+
sampling_rate: z5.number().gte(0).lte(1),
|
|
5302
|
+
scorers: z5.array(SavedFunctionId),
|
|
5303
|
+
btql_filter: z5.union([z5.string(), z5.null()]).optional(),
|
|
5304
|
+
apply_to_root_span: z5.union([z5.boolean(), z5.null()]).optional(),
|
|
5305
|
+
apply_to_span_names: z5.union([z5.array(z5.string()), z5.null()]).optional(),
|
|
5306
|
+
skip_logging: z5.union([z5.boolean(), z5.null()]).optional()
|
|
4341
5307
|
}),
|
|
4342
|
-
|
|
5308
|
+
z5.null()
|
|
4343
5309
|
]);
|
|
4344
|
-
var Organization =
|
|
4345
|
-
id:
|
|
4346
|
-
name:
|
|
4347
|
-
api_url:
|
|
4348
|
-
is_universal_api:
|
|
4349
|
-
proxy_url:
|
|
4350
|
-
realtime_url:
|
|
4351
|
-
created:
|
|
4352
|
-
});
|
|
4353
|
-
var ProjectSettings =
|
|
4354
|
-
|
|
4355
|
-
comparison_key:
|
|
4356
|
-
baseline_experiment_id:
|
|
4357
|
-
spanFieldOrder:
|
|
4358
|
-
|
|
4359
|
-
|
|
4360
|
-
object_type:
|
|
4361
|
-
column_id:
|
|
4362
|
-
position:
|
|
4363
|
-
layout:
|
|
5310
|
+
var Organization = z5.object({
|
|
5311
|
+
id: z5.string().uuid(),
|
|
5312
|
+
name: z5.string(),
|
|
5313
|
+
api_url: z5.union([z5.string(), z5.null()]).optional(),
|
|
5314
|
+
is_universal_api: z5.union([z5.boolean(), z5.null()]).optional(),
|
|
5315
|
+
proxy_url: z5.union([z5.string(), z5.null()]).optional(),
|
|
5316
|
+
realtime_url: z5.union([z5.string(), z5.null()]).optional(),
|
|
5317
|
+
created: z5.union([z5.string(), z5.null()]).optional()
|
|
5318
|
+
});
|
|
5319
|
+
var ProjectSettings = z5.union([
|
|
5320
|
+
z5.object({
|
|
5321
|
+
comparison_key: z5.union([z5.string(), z5.null()]),
|
|
5322
|
+
baseline_experiment_id: z5.union([z5.string(), z5.null()]),
|
|
5323
|
+
spanFieldOrder: z5.union([
|
|
5324
|
+
z5.array(
|
|
5325
|
+
z5.object({
|
|
5326
|
+
object_type: z5.string(),
|
|
5327
|
+
column_id: z5.string(),
|
|
5328
|
+
position: z5.string(),
|
|
5329
|
+
layout: z5.union([z5.literal("full"), z5.literal("two_column"), z5.null()]).optional()
|
|
4364
5330
|
})
|
|
4365
5331
|
),
|
|
4366
|
-
|
|
5332
|
+
z5.null()
|
|
4367
5333
|
]),
|
|
4368
|
-
remote_eval_sources:
|
|
4369
|
-
|
|
4370
|
-
|
|
4371
|
-
url:
|
|
4372
|
-
name:
|
|
4373
|
-
description:
|
|
5334
|
+
remote_eval_sources: z5.union([
|
|
5335
|
+
z5.array(
|
|
5336
|
+
z5.object({
|
|
5337
|
+
url: z5.string(),
|
|
5338
|
+
name: z5.string(),
|
|
5339
|
+
description: z5.union([z5.string(), z5.null()]).optional()
|
|
4374
5340
|
})
|
|
4375
5341
|
),
|
|
4376
|
-
|
|
5342
|
+
z5.null()
|
|
4377
5343
|
])
|
|
4378
5344
|
}).partial(),
|
|
4379
|
-
|
|
5345
|
+
z5.null()
|
|
4380
5346
|
]);
|
|
4381
|
-
var Project =
|
|
4382
|
-
id:
|
|
4383
|
-
org_id:
|
|
4384
|
-
name:
|
|
4385
|
-
created:
|
|
4386
|
-
deleted_at:
|
|
4387
|
-
user_id:
|
|
5347
|
+
var Project = z5.object({
|
|
5348
|
+
id: z5.string().uuid(),
|
|
5349
|
+
org_id: z5.string().uuid(),
|
|
5350
|
+
name: z5.string(),
|
|
5351
|
+
created: z5.union([z5.string(), z5.null()]).optional(),
|
|
5352
|
+
deleted_at: z5.union([z5.string(), z5.null()]).optional(),
|
|
5353
|
+
user_id: z5.union([z5.string(), z5.null()]).optional(),
|
|
4388
5354
|
settings: ProjectSettings.optional()
|
|
4389
5355
|
});
|
|
4390
|
-
var RetentionObjectType =
|
|
5356
|
+
var RetentionObjectType = z5.enum([
|
|
4391
5357
|
"project_logs",
|
|
4392
5358
|
"experiment",
|
|
4393
5359
|
"dataset"
|
|
4394
5360
|
]);
|
|
4395
|
-
var ProjectAutomation =
|
|
4396
|
-
id:
|
|
4397
|
-
project_id:
|
|
4398
|
-
user_id:
|
|
4399
|
-
created:
|
|
4400
|
-
name:
|
|
4401
|
-
description:
|
|
4402
|
-
config:
|
|
4403
|
-
|
|
4404
|
-
event_type:
|
|
4405
|
-
btql_filter:
|
|
4406
|
-
interval_seconds:
|
|
4407
|
-
action:
|
|
5361
|
+
var ProjectAutomation = z5.object({
|
|
5362
|
+
id: z5.string().uuid(),
|
|
5363
|
+
project_id: z5.string().uuid(),
|
|
5364
|
+
user_id: z5.union([z5.string(), z5.null()]).optional(),
|
|
5365
|
+
created: z5.union([z5.string(), z5.null()]).optional(),
|
|
5366
|
+
name: z5.string(),
|
|
5367
|
+
description: z5.union([z5.string(), z5.null()]).optional(),
|
|
5368
|
+
config: z5.union([
|
|
5369
|
+
z5.object({
|
|
5370
|
+
event_type: z5.literal("logs"),
|
|
5371
|
+
btql_filter: z5.string(),
|
|
5372
|
+
interval_seconds: z5.number().gte(1).lte(2592e3),
|
|
5373
|
+
action: z5.object({ type: z5.literal("webhook"), url: z5.string() })
|
|
4408
5374
|
}),
|
|
4409
|
-
|
|
4410
|
-
event_type:
|
|
4411
|
-
export_definition:
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
|
|
5375
|
+
z5.object({
|
|
5376
|
+
event_type: z5.literal("btql_export"),
|
|
5377
|
+
export_definition: z5.union([
|
|
5378
|
+
z5.object({ type: z5.literal("log_traces") }),
|
|
5379
|
+
z5.object({ type: z5.literal("log_spans") }),
|
|
5380
|
+
z5.object({ type: z5.literal("btql_query"), btql_query: z5.string() })
|
|
4415
5381
|
]),
|
|
4416
|
-
export_path:
|
|
4417
|
-
format:
|
|
4418
|
-
interval_seconds:
|
|
4419
|
-
credentials:
|
|
4420
|
-
type:
|
|
4421
|
-
role_arn:
|
|
4422
|
-
external_id:
|
|
5382
|
+
export_path: z5.string(),
|
|
5383
|
+
format: z5.enum(["jsonl", "parquet"]),
|
|
5384
|
+
interval_seconds: z5.number().gte(1).lte(2592e3),
|
|
5385
|
+
credentials: z5.object({
|
|
5386
|
+
type: z5.literal("aws_iam"),
|
|
5387
|
+
role_arn: z5.string(),
|
|
5388
|
+
external_id: z5.string()
|
|
4423
5389
|
}),
|
|
4424
|
-
batch_size:
|
|
5390
|
+
batch_size: z5.union([z5.number(), z5.null()]).optional()
|
|
4425
5391
|
}),
|
|
4426
|
-
|
|
4427
|
-
event_type:
|
|
5392
|
+
z5.object({
|
|
5393
|
+
event_type: z5.literal("retention"),
|
|
4428
5394
|
object_type: RetentionObjectType,
|
|
4429
|
-
retention_days:
|
|
5395
|
+
retention_days: z5.number().gte(0)
|
|
4430
5396
|
})
|
|
4431
5397
|
])
|
|
4432
5398
|
});
|
|
4433
|
-
var ProjectLogsEvent =
|
|
4434
|
-
id:
|
|
4435
|
-
_xact_id:
|
|
4436
|
-
_pagination_key:
|
|
4437
|
-
created:
|
|
4438
|
-
org_id:
|
|
4439
|
-
project_id:
|
|
4440
|
-
log_id:
|
|
4441
|
-
input:
|
|
4442
|
-
output:
|
|
4443
|
-
expected:
|
|
4444
|
-
error:
|
|
4445
|
-
scores:
|
|
4446
|
-
metadata:
|
|
4447
|
-
|
|
4448
|
-
|
|
5399
|
+
var ProjectLogsEvent = z5.object({
|
|
5400
|
+
id: z5.string(),
|
|
5401
|
+
_xact_id: z5.string(),
|
|
5402
|
+
_pagination_key: z5.union([z5.string(), z5.null()]).optional(),
|
|
5403
|
+
created: z5.string().datetime({ offset: true }),
|
|
5404
|
+
org_id: z5.string().uuid(),
|
|
5405
|
+
project_id: z5.string().uuid(),
|
|
5406
|
+
log_id: z5.literal("g"),
|
|
5407
|
+
input: z5.unknown().optional(),
|
|
5408
|
+
output: z5.unknown().optional(),
|
|
5409
|
+
expected: z5.unknown().optional(),
|
|
5410
|
+
error: z5.unknown().optional(),
|
|
5411
|
+
scores: z5.union([z5.record(z5.union([z5.number(), z5.null()])), z5.null()]).optional(),
|
|
5412
|
+
metadata: z5.union([
|
|
5413
|
+
z5.object({ model: z5.union([z5.string(), z5.null()]) }).partial().passthrough(),
|
|
5414
|
+
z5.null()
|
|
4449
5415
|
]).optional(),
|
|
4450
|
-
tags:
|
|
4451
|
-
metrics:
|
|
4452
|
-
context:
|
|
4453
|
-
|
|
4454
|
-
caller_functionname:
|
|
4455
|
-
caller_filename:
|
|
4456
|
-
caller_lineno:
|
|
5416
|
+
tags: z5.union([z5.array(z5.string()), z5.null()]).optional(),
|
|
5417
|
+
metrics: z5.union([z5.record(z5.number()), z5.null()]).optional(),
|
|
5418
|
+
context: z5.union([
|
|
5419
|
+
z5.object({
|
|
5420
|
+
caller_functionname: z5.union([z5.string(), z5.null()]),
|
|
5421
|
+
caller_filename: z5.union([z5.string(), z5.null()]),
|
|
5422
|
+
caller_lineno: z5.union([z5.number(), z5.null()])
|
|
4457
5423
|
}).partial().passthrough(),
|
|
4458
|
-
|
|
5424
|
+
z5.null()
|
|
4459
5425
|
]).optional(),
|
|
4460
|
-
span_id:
|
|
4461
|
-
span_parents:
|
|
4462
|
-
root_span_id:
|
|
4463
|
-
is_root:
|
|
5426
|
+
span_id: z5.string(),
|
|
5427
|
+
span_parents: z5.union([z5.array(z5.string()), z5.null()]).optional(),
|
|
5428
|
+
root_span_id: z5.string(),
|
|
5429
|
+
is_root: z5.union([z5.boolean(), z5.null()]).optional(),
|
|
4464
5430
|
span_attributes: SpanAttributes.optional(),
|
|
4465
5431
|
origin: ObjectReferenceNullish.optional()
|
|
4466
5432
|
});
|
|
4467
|
-
var ProjectScoreType =
|
|
5433
|
+
var ProjectScoreType = z5.enum([
|
|
4468
5434
|
"slider",
|
|
4469
5435
|
"categorical",
|
|
4470
5436
|
"weighted",
|
|
@@ -4473,172 +5439,172 @@ var ProjectScoreType = z.enum([
|
|
|
4473
5439
|
"online",
|
|
4474
5440
|
"free-form"
|
|
4475
5441
|
]);
|
|
4476
|
-
var ProjectScoreCategory =
|
|
4477
|
-
name:
|
|
4478
|
-
value:
|
|
4479
|
-
});
|
|
4480
|
-
var ProjectScoreCategories =
|
|
4481
|
-
|
|
4482
|
-
|
|
4483
|
-
|
|
4484
|
-
|
|
5442
|
+
var ProjectScoreCategory = z5.object({
|
|
5443
|
+
name: z5.string(),
|
|
5444
|
+
value: z5.number()
|
|
5445
|
+
});
|
|
5446
|
+
var ProjectScoreCategories = z5.union([
|
|
5447
|
+
z5.array(ProjectScoreCategory),
|
|
5448
|
+
z5.record(z5.number()),
|
|
5449
|
+
z5.array(z5.string()),
|
|
5450
|
+
z5.null()
|
|
4485
5451
|
]);
|
|
4486
|
-
var ProjectScoreConfig =
|
|
4487
|
-
|
|
4488
|
-
multi_select:
|
|
4489
|
-
destination:
|
|
5452
|
+
var ProjectScoreConfig = z5.union([
|
|
5453
|
+
z5.object({
|
|
5454
|
+
multi_select: z5.union([z5.boolean(), z5.null()]),
|
|
5455
|
+
destination: z5.union([z5.string(), z5.null()]),
|
|
4490
5456
|
online: OnlineScoreConfig
|
|
4491
5457
|
}).partial(),
|
|
4492
|
-
|
|
5458
|
+
z5.null()
|
|
4493
5459
|
]);
|
|
4494
|
-
var ProjectScore =
|
|
4495
|
-
id:
|
|
4496
|
-
project_id:
|
|
4497
|
-
user_id:
|
|
4498
|
-
created:
|
|
4499
|
-
name:
|
|
4500
|
-
description:
|
|
5460
|
+
var ProjectScore = z5.object({
|
|
5461
|
+
id: z5.string().uuid(),
|
|
5462
|
+
project_id: z5.string().uuid(),
|
|
5463
|
+
user_id: z5.string().uuid(),
|
|
5464
|
+
created: z5.union([z5.string(), z5.null()]).optional(),
|
|
5465
|
+
name: z5.string(),
|
|
5466
|
+
description: z5.union([z5.string(), z5.null()]).optional(),
|
|
4501
5467
|
score_type: ProjectScoreType,
|
|
4502
5468
|
categories: ProjectScoreCategories.optional(),
|
|
4503
5469
|
config: ProjectScoreConfig.optional(),
|
|
4504
|
-
position:
|
|
4505
|
-
});
|
|
4506
|
-
var ProjectTag =
|
|
4507
|
-
id:
|
|
4508
|
-
project_id:
|
|
4509
|
-
user_id:
|
|
4510
|
-
created:
|
|
4511
|
-
name:
|
|
4512
|
-
description:
|
|
4513
|
-
color:
|
|
4514
|
-
position:
|
|
4515
|
-
});
|
|
4516
|
-
var Prompt =
|
|
4517
|
-
id:
|
|
4518
|
-
_xact_id:
|
|
4519
|
-
project_id:
|
|
4520
|
-
log_id:
|
|
4521
|
-
org_id:
|
|
4522
|
-
name:
|
|
4523
|
-
slug:
|
|
4524
|
-
description:
|
|
4525
|
-
created:
|
|
5470
|
+
position: z5.union([z5.string(), z5.null()]).optional()
|
|
5471
|
+
});
|
|
5472
|
+
var ProjectTag = z5.object({
|
|
5473
|
+
id: z5.string().uuid(),
|
|
5474
|
+
project_id: z5.string().uuid(),
|
|
5475
|
+
user_id: z5.string().uuid(),
|
|
5476
|
+
created: z5.union([z5.string(), z5.null()]).optional(),
|
|
5477
|
+
name: z5.string(),
|
|
5478
|
+
description: z5.union([z5.string(), z5.null()]).optional(),
|
|
5479
|
+
color: z5.union([z5.string(), z5.null()]).optional(),
|
|
5480
|
+
position: z5.union([z5.string(), z5.null()]).optional()
|
|
5481
|
+
});
|
|
5482
|
+
var Prompt = z5.object({
|
|
5483
|
+
id: z5.string().uuid(),
|
|
5484
|
+
_xact_id: z5.string(),
|
|
5485
|
+
project_id: z5.string().uuid(),
|
|
5486
|
+
log_id: z5.literal("p"),
|
|
5487
|
+
org_id: z5.string().uuid(),
|
|
5488
|
+
name: z5.string(),
|
|
5489
|
+
slug: z5.string(),
|
|
5490
|
+
description: z5.union([z5.string(), z5.null()]).optional(),
|
|
5491
|
+
created: z5.union([z5.string(), z5.null()]).optional(),
|
|
4526
5492
|
prompt_data: PromptDataNullish.optional(),
|
|
4527
|
-
tags:
|
|
4528
|
-
metadata:
|
|
5493
|
+
tags: z5.union([z5.array(z5.string()), z5.null()]).optional(),
|
|
5494
|
+
metadata: z5.union([z5.object({}).partial().passthrough(), z5.null()]).optional(),
|
|
4529
5495
|
function_type: FunctionTypeEnumNullish.optional()
|
|
4530
5496
|
});
|
|
4531
|
-
var PromptOptions =
|
|
4532
|
-
var PromptSessionEvent =
|
|
4533
|
-
id:
|
|
4534
|
-
_xact_id:
|
|
4535
|
-
created:
|
|
4536
|
-
_pagination_key:
|
|
4537
|
-
project_id:
|
|
4538
|
-
prompt_session_id:
|
|
4539
|
-
prompt_session_data:
|
|
4540
|
-
prompt_data:
|
|
4541
|
-
function_data:
|
|
5497
|
+
var PromptOptions = z5.object({ model: z5.string(), params: ModelParams, position: z5.string() }).partial();
|
|
5498
|
+
var PromptSessionEvent = z5.object({
|
|
5499
|
+
id: z5.string(),
|
|
5500
|
+
_xact_id: z5.string(),
|
|
5501
|
+
created: z5.string().datetime({ offset: true }),
|
|
5502
|
+
_pagination_key: z5.union([z5.string(), z5.null()]).optional(),
|
|
5503
|
+
project_id: z5.string().uuid(),
|
|
5504
|
+
prompt_session_id: z5.string().uuid(),
|
|
5505
|
+
prompt_session_data: z5.unknown().optional(),
|
|
5506
|
+
prompt_data: z5.unknown().optional(),
|
|
5507
|
+
function_data: z5.unknown().optional(),
|
|
4542
5508
|
function_type: FunctionTypeEnumNullish.optional(),
|
|
4543
|
-
object_data:
|
|
4544
|
-
completion:
|
|
4545
|
-
tags:
|
|
4546
|
-
});
|
|
4547
|
-
var ResponseFormat =
|
|
4548
|
-
|
|
4549
|
-
|
|
4550
|
-
type:
|
|
5509
|
+
object_data: z5.unknown().optional(),
|
|
5510
|
+
completion: z5.unknown().optional(),
|
|
5511
|
+
tags: z5.union([z5.array(z5.string()), z5.null()]).optional()
|
|
5512
|
+
});
|
|
5513
|
+
var ResponseFormat = z5.union([
|
|
5514
|
+
z5.object({ type: z5.literal("json_object") }),
|
|
5515
|
+
z5.object({
|
|
5516
|
+
type: z5.literal("json_schema"),
|
|
4551
5517
|
json_schema: ResponseFormatJsonSchema
|
|
4552
5518
|
}),
|
|
4553
|
-
|
|
5519
|
+
z5.object({ type: z5.literal("text") })
|
|
4554
5520
|
]);
|
|
4555
|
-
var Role =
|
|
4556
|
-
id:
|
|
4557
|
-
org_id:
|
|
4558
|
-
user_id:
|
|
4559
|
-
created:
|
|
4560
|
-
name:
|
|
4561
|
-
description:
|
|
4562
|
-
deleted_at:
|
|
4563
|
-
member_permissions:
|
|
4564
|
-
|
|
4565
|
-
|
|
5521
|
+
var Role = z5.object({
|
|
5522
|
+
id: z5.string().uuid(),
|
|
5523
|
+
org_id: z5.union([z5.string(), z5.null()]).optional(),
|
|
5524
|
+
user_id: z5.union([z5.string(), z5.null()]).optional(),
|
|
5525
|
+
created: z5.union([z5.string(), z5.null()]).optional(),
|
|
5526
|
+
name: z5.string(),
|
|
5527
|
+
description: z5.union([z5.string(), z5.null()]).optional(),
|
|
5528
|
+
deleted_at: z5.union([z5.string(), z5.null()]).optional(),
|
|
5529
|
+
member_permissions: z5.union([
|
|
5530
|
+
z5.array(
|
|
5531
|
+
z5.object({
|
|
4566
5532
|
permission: Permission,
|
|
4567
5533
|
restrict_object_type: AclObjectType.optional()
|
|
4568
5534
|
})
|
|
4569
5535
|
),
|
|
4570
|
-
|
|
5536
|
+
z5.null()
|
|
4571
5537
|
]).optional(),
|
|
4572
|
-
member_roles:
|
|
4573
|
-
});
|
|
4574
|
-
var RunEval =
|
|
4575
|
-
project_id:
|
|
4576
|
-
data:
|
|
4577
|
-
|
|
4578
|
-
dataset_id:
|
|
4579
|
-
_internal_btql:
|
|
5538
|
+
member_roles: z5.union([z5.array(z5.string().uuid()), z5.null()]).optional()
|
|
5539
|
+
});
|
|
5540
|
+
var RunEval = z5.object({
|
|
5541
|
+
project_id: z5.string(),
|
|
5542
|
+
data: z5.union([
|
|
5543
|
+
z5.object({
|
|
5544
|
+
dataset_id: z5.string(),
|
|
5545
|
+
_internal_btql: z5.union([z5.object({}).partial().passthrough(), z5.null()]).optional()
|
|
4580
5546
|
}),
|
|
4581
|
-
|
|
4582
|
-
project_name:
|
|
4583
|
-
dataset_name:
|
|
4584
|
-
_internal_btql:
|
|
5547
|
+
z5.object({
|
|
5548
|
+
project_name: z5.string(),
|
|
5549
|
+
dataset_name: z5.string(),
|
|
5550
|
+
_internal_btql: z5.union([z5.object({}).partial().passthrough(), z5.null()]).optional()
|
|
4585
5551
|
}),
|
|
4586
|
-
|
|
5552
|
+
z5.object({ data: z5.array(z5.unknown()) })
|
|
4587
5553
|
]),
|
|
4588
|
-
task: FunctionId.and(
|
|
4589
|
-
scores:
|
|
4590
|
-
experiment_name:
|
|
4591
|
-
metadata:
|
|
4592
|
-
parent: InvokeParent.and(
|
|
4593
|
-
stream:
|
|
4594
|
-
trial_count:
|
|
4595
|
-
is_public:
|
|
4596
|
-
timeout:
|
|
4597
|
-
max_concurrency:
|
|
4598
|
-
base_experiment_name:
|
|
4599
|
-
base_experiment_id:
|
|
5554
|
+
task: FunctionId.and(z5.unknown()),
|
|
5555
|
+
scores: z5.array(FunctionId),
|
|
5556
|
+
experiment_name: z5.string().optional(),
|
|
5557
|
+
metadata: z5.object({}).partial().passthrough().optional(),
|
|
5558
|
+
parent: InvokeParent.and(z5.unknown()).optional(),
|
|
5559
|
+
stream: z5.boolean().optional(),
|
|
5560
|
+
trial_count: z5.union([z5.number(), z5.null()]).optional(),
|
|
5561
|
+
is_public: z5.union([z5.boolean(), z5.null()]).optional(),
|
|
5562
|
+
timeout: z5.union([z5.number(), z5.null()]).optional(),
|
|
5563
|
+
max_concurrency: z5.union([z5.number(), z5.null()]).optional().default(10),
|
|
5564
|
+
base_experiment_name: z5.union([z5.string(), z5.null()]).optional(),
|
|
5565
|
+
base_experiment_id: z5.union([z5.string(), z5.null()]).optional(),
|
|
4600
5566
|
git_metadata_settings: GitMetadataSettings.and(
|
|
4601
|
-
|
|
5567
|
+
z5.union([z5.object({}).partial(), z5.null()])
|
|
4602
5568
|
).optional(),
|
|
4603
|
-
repo_info: RepoInfo.and(
|
|
4604
|
-
strict:
|
|
4605
|
-
stop_token:
|
|
4606
|
-
extra_messages:
|
|
4607
|
-
tags:
|
|
4608
|
-
});
|
|
4609
|
-
var ServiceToken =
|
|
4610
|
-
id:
|
|
4611
|
-
created:
|
|
4612
|
-
name:
|
|
4613
|
-
preview_name:
|
|
4614
|
-
service_account_id:
|
|
4615
|
-
service_account_email:
|
|
4616
|
-
service_account_name:
|
|
4617
|
-
org_id:
|
|
4618
|
-
});
|
|
4619
|
-
var SpanIFrame =
|
|
4620
|
-
id:
|
|
4621
|
-
project_id:
|
|
4622
|
-
user_id:
|
|
4623
|
-
created:
|
|
4624
|
-
deleted_at:
|
|
4625
|
-
name:
|
|
4626
|
-
description:
|
|
4627
|
-
url:
|
|
4628
|
-
post_message:
|
|
4629
|
-
});
|
|
4630
|
-
var SSEConsoleEventData =
|
|
4631
|
-
stream:
|
|
4632
|
-
message:
|
|
4633
|
-
});
|
|
4634
|
-
var SSEProgressEventData =
|
|
4635
|
-
id:
|
|
5569
|
+
repo_info: RepoInfo.and(z5.unknown()).optional(),
|
|
5570
|
+
strict: z5.union([z5.boolean(), z5.null()]).optional(),
|
|
5571
|
+
stop_token: z5.union([z5.string(), z5.null()]).optional(),
|
|
5572
|
+
extra_messages: z5.string().optional(),
|
|
5573
|
+
tags: z5.array(z5.string()).optional()
|
|
5574
|
+
});
|
|
5575
|
+
var ServiceToken = z5.object({
|
|
5576
|
+
id: z5.string().uuid(),
|
|
5577
|
+
created: z5.union([z5.string(), z5.null()]).optional(),
|
|
5578
|
+
name: z5.string(),
|
|
5579
|
+
preview_name: z5.string(),
|
|
5580
|
+
service_account_id: z5.union([z5.string(), z5.null()]).optional(),
|
|
5581
|
+
service_account_email: z5.union([z5.string(), z5.null()]).optional(),
|
|
5582
|
+
service_account_name: z5.union([z5.string(), z5.null()]).optional(),
|
|
5583
|
+
org_id: z5.union([z5.string(), z5.null()]).optional()
|
|
5584
|
+
});
|
|
5585
|
+
var SpanIFrame = z5.object({
|
|
5586
|
+
id: z5.string().uuid(),
|
|
5587
|
+
project_id: z5.string().uuid(),
|
|
5588
|
+
user_id: z5.union([z5.string(), z5.null()]).optional(),
|
|
5589
|
+
created: z5.union([z5.string(), z5.null()]).optional(),
|
|
5590
|
+
deleted_at: z5.union([z5.string(), z5.null()]).optional(),
|
|
5591
|
+
name: z5.string(),
|
|
5592
|
+
description: z5.union([z5.string(), z5.null()]).optional(),
|
|
5593
|
+
url: z5.string(),
|
|
5594
|
+
post_message: z5.union([z5.boolean(), z5.null()]).optional()
|
|
5595
|
+
});
|
|
5596
|
+
var SSEConsoleEventData = z5.object({
|
|
5597
|
+
stream: z5.enum(["stderr", "stdout"]),
|
|
5598
|
+
message: z5.string()
|
|
5599
|
+
});
|
|
5600
|
+
var SSEProgressEventData = z5.object({
|
|
5601
|
+
id: z5.string(),
|
|
4636
5602
|
object_type: FunctionObjectType,
|
|
4637
|
-
origin: ObjectReferenceNullish.and(
|
|
5603
|
+
origin: ObjectReferenceNullish.and(z5.unknown()).optional(),
|
|
4638
5604
|
format: FunctionFormat,
|
|
4639
5605
|
output_type: FunctionOutputType,
|
|
4640
|
-
name:
|
|
4641
|
-
event:
|
|
5606
|
+
name: z5.string(),
|
|
5607
|
+
event: z5.enum([
|
|
4642
5608
|
"reasoning_delta",
|
|
4643
5609
|
"text_delta",
|
|
4644
5610
|
"json_delta",
|
|
@@ -4648,110 +5614,110 @@ var SSEProgressEventData = z.object({
|
|
|
4648
5614
|
"done",
|
|
4649
5615
|
"progress"
|
|
4650
5616
|
]),
|
|
4651
|
-
data:
|
|
4652
|
-
});
|
|
4653
|
-
var ToolFunctionDefinition =
|
|
4654
|
-
type:
|
|
4655
|
-
function:
|
|
4656
|
-
name:
|
|
4657
|
-
description:
|
|
4658
|
-
parameters:
|
|
4659
|
-
strict:
|
|
5617
|
+
data: z5.string()
|
|
5618
|
+
});
|
|
5619
|
+
var ToolFunctionDefinition = z5.object({
|
|
5620
|
+
type: z5.literal("function"),
|
|
5621
|
+
function: z5.object({
|
|
5622
|
+
name: z5.string(),
|
|
5623
|
+
description: z5.string().optional(),
|
|
5624
|
+
parameters: z5.object({}).partial().passthrough().optional(),
|
|
5625
|
+
strict: z5.union([z5.boolean(), z5.null()]).optional()
|
|
4660
5626
|
})
|
|
4661
5627
|
});
|
|
4662
|
-
var User =
|
|
4663
|
-
id:
|
|
4664
|
-
given_name:
|
|
4665
|
-
family_name:
|
|
4666
|
-
email:
|
|
4667
|
-
avatar_url:
|
|
4668
|
-
created:
|
|
4669
|
-
});
|
|
4670
|
-
var ViewDataSearch =
|
|
4671
|
-
|
|
4672
|
-
filter:
|
|
4673
|
-
tag:
|
|
4674
|
-
match:
|
|
4675
|
-
sort:
|
|
5628
|
+
var User = z5.object({
|
|
5629
|
+
id: z5.string().uuid(),
|
|
5630
|
+
given_name: z5.union([z5.string(), z5.null()]).optional(),
|
|
5631
|
+
family_name: z5.union([z5.string(), z5.null()]).optional(),
|
|
5632
|
+
email: z5.union([z5.string(), z5.null()]).optional(),
|
|
5633
|
+
avatar_url: z5.union([z5.string(), z5.null()]).optional(),
|
|
5634
|
+
created: z5.union([z5.string(), z5.null()]).optional()
|
|
5635
|
+
});
|
|
5636
|
+
var ViewDataSearch = z5.union([
|
|
5637
|
+
z5.object({
|
|
5638
|
+
filter: z5.union([z5.array(z5.unknown()), z5.null()]),
|
|
5639
|
+
tag: z5.union([z5.array(z5.unknown()), z5.null()]),
|
|
5640
|
+
match: z5.union([z5.array(z5.unknown()), z5.null()]),
|
|
5641
|
+
sort: z5.union([z5.array(z5.unknown()), z5.null()])
|
|
4676
5642
|
}).partial(),
|
|
4677
|
-
|
|
5643
|
+
z5.null()
|
|
4678
5644
|
]);
|
|
4679
|
-
var ViewData =
|
|
4680
|
-
|
|
4681
|
-
|
|
5645
|
+
var ViewData = z5.union([
|
|
5646
|
+
z5.object({ search: ViewDataSearch }).partial(),
|
|
5647
|
+
z5.null()
|
|
4682
5648
|
]);
|
|
4683
|
-
var ViewOptions =
|
|
4684
|
-
|
|
4685
|
-
viewType:
|
|
4686
|
-
options:
|
|
4687
|
-
spanType:
|
|
4688
|
-
rangeValue:
|
|
4689
|
-
frameStart:
|
|
4690
|
-
frameEnd:
|
|
4691
|
-
tzUTC:
|
|
4692
|
-
chartVisibility:
|
|
4693
|
-
projectId:
|
|
4694
|
-
type:
|
|
4695
|
-
groupBy:
|
|
5649
|
+
var ViewOptions = z5.union([
|
|
5650
|
+
z5.object({
|
|
5651
|
+
viewType: z5.literal("monitor"),
|
|
5652
|
+
options: z5.object({
|
|
5653
|
+
spanType: z5.union([z5.enum(["range", "frame"]), z5.null()]),
|
|
5654
|
+
rangeValue: z5.union([z5.string(), z5.null()]),
|
|
5655
|
+
frameStart: z5.union([z5.string(), z5.null()]),
|
|
5656
|
+
frameEnd: z5.union([z5.string(), z5.null()]),
|
|
5657
|
+
tzUTC: z5.union([z5.boolean(), z5.null()]),
|
|
5658
|
+
chartVisibility: z5.union([z5.record(z5.boolean()), z5.null()]),
|
|
5659
|
+
projectId: z5.union([z5.string(), z5.null()]),
|
|
5660
|
+
type: z5.union([z5.enum(["project", "experiment"]), z5.null()]),
|
|
5661
|
+
groupBy: z5.union([z5.string(), z5.null()])
|
|
4696
5662
|
}).partial()
|
|
4697
5663
|
}),
|
|
4698
|
-
|
|
4699
|
-
columnVisibility:
|
|
4700
|
-
columnOrder:
|
|
4701
|
-
columnSizing:
|
|
4702
|
-
grouping:
|
|
4703
|
-
rowHeight:
|
|
4704
|
-
tallGroupRows:
|
|
4705
|
-
layout:
|
|
4706
|
-
chartHeight:
|
|
4707
|
-
excludedMeasures:
|
|
4708
|
-
|
|
4709
|
-
|
|
4710
|
-
type:
|
|
4711
|
-
value:
|
|
5664
|
+
z5.object({
|
|
5665
|
+
columnVisibility: z5.union([z5.record(z5.boolean()), z5.null()]),
|
|
5666
|
+
columnOrder: z5.union([z5.array(z5.string()), z5.null()]),
|
|
5667
|
+
columnSizing: z5.union([z5.record(z5.number()), z5.null()]),
|
|
5668
|
+
grouping: z5.union([z5.string(), z5.null()]),
|
|
5669
|
+
rowHeight: z5.union([z5.string(), z5.null()]),
|
|
5670
|
+
tallGroupRows: z5.union([z5.boolean(), z5.null()]),
|
|
5671
|
+
layout: z5.union([z5.string(), z5.null()]),
|
|
5672
|
+
chartHeight: z5.union([z5.number(), z5.null()]),
|
|
5673
|
+
excludedMeasures: z5.union([
|
|
5674
|
+
z5.array(
|
|
5675
|
+
z5.object({
|
|
5676
|
+
type: z5.enum(["none", "score", "metric", "metadata"]),
|
|
5677
|
+
value: z5.string()
|
|
4712
5678
|
})
|
|
4713
5679
|
),
|
|
4714
|
-
|
|
5680
|
+
z5.null()
|
|
4715
5681
|
]),
|
|
4716
|
-
yMetric:
|
|
4717
|
-
|
|
4718
|
-
type:
|
|
4719
|
-
value:
|
|
5682
|
+
yMetric: z5.union([
|
|
5683
|
+
z5.object({
|
|
5684
|
+
type: z5.enum(["none", "score", "metric", "metadata"]),
|
|
5685
|
+
value: z5.string()
|
|
4720
5686
|
}),
|
|
4721
|
-
|
|
5687
|
+
z5.null()
|
|
4722
5688
|
]),
|
|
4723
|
-
xAxis:
|
|
4724
|
-
|
|
4725
|
-
type:
|
|
4726
|
-
value:
|
|
5689
|
+
xAxis: z5.union([
|
|
5690
|
+
z5.object({
|
|
5691
|
+
type: z5.enum(["none", "score", "metric", "metadata"]),
|
|
5692
|
+
value: z5.string()
|
|
4727
5693
|
}),
|
|
4728
|
-
|
|
5694
|
+
z5.null()
|
|
4729
5695
|
]),
|
|
4730
|
-
symbolGrouping:
|
|
4731
|
-
|
|
4732
|
-
type:
|
|
4733
|
-
value:
|
|
5696
|
+
symbolGrouping: z5.union([
|
|
5697
|
+
z5.object({
|
|
5698
|
+
type: z5.enum(["none", "score", "metric", "metadata"]),
|
|
5699
|
+
value: z5.string()
|
|
4734
5700
|
}),
|
|
4735
|
-
|
|
5701
|
+
z5.null()
|
|
4736
5702
|
]),
|
|
4737
|
-
xAxisAggregation:
|
|
4738
|
-
chartAnnotations:
|
|
4739
|
-
|
|
4740
|
-
|
|
5703
|
+
xAxisAggregation: z5.union([z5.string(), z5.null()]),
|
|
5704
|
+
chartAnnotations: z5.union([
|
|
5705
|
+
z5.array(z5.object({ id: z5.string(), text: z5.string() })),
|
|
5706
|
+
z5.null()
|
|
4741
5707
|
]),
|
|
4742
|
-
timeRangeFilter:
|
|
4743
|
-
|
|
4744
|
-
|
|
4745
|
-
|
|
5708
|
+
timeRangeFilter: z5.union([
|
|
5709
|
+
z5.string(),
|
|
5710
|
+
z5.object({ from: z5.string(), to: z5.string() }),
|
|
5711
|
+
z5.null()
|
|
4746
5712
|
])
|
|
4747
5713
|
}).partial(),
|
|
4748
|
-
|
|
5714
|
+
z5.null()
|
|
4749
5715
|
]);
|
|
4750
|
-
var View =
|
|
4751
|
-
id:
|
|
4752
|
-
object_type: AclObjectType.and(
|
|
4753
|
-
object_id:
|
|
4754
|
-
view_type:
|
|
5716
|
+
var View = z5.object({
|
|
5717
|
+
id: z5.string().uuid(),
|
|
5718
|
+
object_type: AclObjectType.and(z5.string()),
|
|
5719
|
+
object_id: z5.string().uuid(),
|
|
5720
|
+
view_type: z5.enum([
|
|
4755
5721
|
"projects",
|
|
4756
5722
|
"experiments",
|
|
4757
5723
|
"experiment",
|
|
@@ -4766,56 +5732,56 @@ var View = z.object({
|
|
|
4766
5732
|
"agents",
|
|
4767
5733
|
"monitor"
|
|
4768
5734
|
]),
|
|
4769
|
-
name:
|
|
4770
|
-
created:
|
|
5735
|
+
name: z5.string(),
|
|
5736
|
+
created: z5.union([z5.string(), z5.null()]).optional(),
|
|
4771
5737
|
view_data: ViewData.optional(),
|
|
4772
5738
|
options: ViewOptions.optional(),
|
|
4773
|
-
user_id:
|
|
4774
|
-
deleted_at:
|
|
5739
|
+
user_id: z5.union([z5.string(), z5.null()]).optional(),
|
|
5740
|
+
deleted_at: z5.union([z5.string(), z5.null()]).optional()
|
|
4775
5741
|
});
|
|
4776
5742
|
|
|
4777
5743
|
// src/logger.ts
|
|
4778
5744
|
import { waitUntil } from "@vercel/functions";
|
|
4779
5745
|
import Mustache2 from "mustache";
|
|
4780
|
-
import { z as
|
|
5746
|
+
import { z as z7, ZodError } from "zod";
|
|
4781
5747
|
|
|
4782
5748
|
// src/functions/stream.ts
|
|
4783
5749
|
import {
|
|
4784
5750
|
createParser
|
|
4785
5751
|
} from "eventsource-parser";
|
|
4786
|
-
import { z as
|
|
4787
|
-
var braintrustStreamChunkSchema =
|
|
4788
|
-
|
|
4789
|
-
type:
|
|
4790
|
-
data:
|
|
5752
|
+
import { z as z6 } from "zod/v3";
|
|
5753
|
+
var braintrustStreamChunkSchema = z6.union([
|
|
5754
|
+
z6.object({
|
|
5755
|
+
type: z6.literal("text_delta"),
|
|
5756
|
+
data: z6.string()
|
|
4791
5757
|
}),
|
|
4792
|
-
|
|
4793
|
-
type:
|
|
4794
|
-
data:
|
|
5758
|
+
z6.object({
|
|
5759
|
+
type: z6.literal("reasoning_delta"),
|
|
5760
|
+
data: z6.string()
|
|
4795
5761
|
}),
|
|
4796
|
-
|
|
4797
|
-
type:
|
|
4798
|
-
data:
|
|
5762
|
+
z6.object({
|
|
5763
|
+
type: z6.literal("json_delta"),
|
|
5764
|
+
data: z6.string()
|
|
4799
5765
|
}),
|
|
4800
|
-
|
|
4801
|
-
type:
|
|
4802
|
-
data:
|
|
5766
|
+
z6.object({
|
|
5767
|
+
type: z6.literal("error"),
|
|
5768
|
+
data: z6.string()
|
|
4803
5769
|
}),
|
|
4804
|
-
|
|
4805
|
-
type:
|
|
5770
|
+
z6.object({
|
|
5771
|
+
type: z6.literal("console"),
|
|
4806
5772
|
data: SSEConsoleEventData
|
|
4807
5773
|
}),
|
|
4808
|
-
|
|
4809
|
-
type:
|
|
5774
|
+
z6.object({
|
|
5775
|
+
type: z6.literal("progress"),
|
|
4810
5776
|
data: SSEProgressEventData
|
|
4811
5777
|
}),
|
|
4812
|
-
|
|
4813
|
-
type:
|
|
4814
|
-
data:
|
|
5778
|
+
z6.object({
|
|
5779
|
+
type: z6.literal("start"),
|
|
5780
|
+
data: z6.string()
|
|
4815
5781
|
}),
|
|
4816
|
-
|
|
4817
|
-
type:
|
|
4818
|
-
data:
|
|
5782
|
+
z6.object({
|
|
5783
|
+
type: z6.literal("done"),
|
|
5784
|
+
data: z6.string()
|
|
4819
5785
|
})
|
|
4820
5786
|
]);
|
|
4821
5787
|
var BraintrustStream = class _BraintrustStream {
|
|
@@ -5412,7 +6378,6 @@ function objectIsEmpty(obj) {
|
|
|
5412
6378
|
}
|
|
5413
6379
|
|
|
5414
6380
|
// src/mustache-utils.ts
|
|
5415
|
-
import { getObjValueByPath } from "@braintrust/core";
|
|
5416
6381
|
import Mustache from "mustache";
|
|
5417
6382
|
function lintTemplate(template, context2) {
|
|
5418
6383
|
const variables = getMustacheVars(template);
|
|
@@ -5435,7 +6400,6 @@ function getMustacheVars(prompt) {
|
|
|
5435
6400
|
}
|
|
5436
6401
|
|
|
5437
6402
|
// src/logger.ts
|
|
5438
|
-
import { prettifyXact } from "@braintrust/core";
|
|
5439
6403
|
var BRAINTRUST_ATTACHMENT = BraintrustAttachmentReference.shape.type.value;
|
|
5440
6404
|
var EXTERNAL_ATTACHMENT = ExternalAttachmentReference.shape.type.value;
|
|
5441
6405
|
var BRAINTRUST_PARAMS = Object.keys(BraintrustModelParams.shape);
|
|
@@ -5520,17 +6484,31 @@ var NoopSpan = class {
|
|
|
5520
6484
|
state() {
|
|
5521
6485
|
return _internalGetGlobalState();
|
|
5522
6486
|
}
|
|
6487
|
+
// Custom inspect for Node.js console.log
|
|
6488
|
+
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
6489
|
+
return `NoopSpan {
|
|
6490
|
+
kind: '${this.kind}',
|
|
6491
|
+
id: '${this.id}',
|
|
6492
|
+
spanId: '${this.spanId}',
|
|
6493
|
+
rootSpanId: '${this.rootSpanId}',
|
|
6494
|
+
spanParents: ${JSON.stringify(this.spanParents)}
|
|
6495
|
+
}`;
|
|
6496
|
+
}
|
|
6497
|
+
// Custom toString
|
|
6498
|
+
toString() {
|
|
6499
|
+
return `NoopSpan(id=${this.id}, spanId=${this.spanId})`;
|
|
6500
|
+
}
|
|
5523
6501
|
};
|
|
5524
6502
|
var NOOP_SPAN = new NoopSpan();
|
|
5525
6503
|
var NOOP_SPAN_PERMALINK = "https://braintrust.dev/noop-span";
|
|
5526
|
-
var loginSchema =
|
|
5527
|
-
appUrl:
|
|
5528
|
-
appPublicUrl:
|
|
5529
|
-
orgName:
|
|
5530
|
-
apiUrl:
|
|
5531
|
-
proxyUrl:
|
|
5532
|
-
loginToken:
|
|
5533
|
-
orgId:
|
|
6504
|
+
var loginSchema = z7.strictObject({
|
|
6505
|
+
appUrl: z7.string(),
|
|
6506
|
+
appPublicUrl: z7.string(),
|
|
6507
|
+
orgName: z7.string(),
|
|
6508
|
+
apiUrl: z7.string(),
|
|
6509
|
+
proxyUrl: z7.string(),
|
|
6510
|
+
loginToken: z7.string(),
|
|
6511
|
+
orgId: z7.string().nullish(),
|
|
5534
6512
|
gitMetadataSettings: GitMetadataSettings.nullish()
|
|
5535
6513
|
});
|
|
5536
6514
|
var stateNonce = 0;
|
|
@@ -5740,6 +6718,37 @@ var BraintrustState = class _BraintrustState {
|
|
|
5740
6718
|
enforceQueueSizeLimit(enforce) {
|
|
5741
6719
|
this._bgLogger.get().enforceQueueSizeLimit(enforce);
|
|
5742
6720
|
}
|
|
6721
|
+
// Custom serialization to avoid logging sensitive data
|
|
6722
|
+
toJSON() {
|
|
6723
|
+
return {
|
|
6724
|
+
id: this.id,
|
|
6725
|
+
orgId: this.orgId,
|
|
6726
|
+
orgName: this.orgName,
|
|
6727
|
+
appUrl: this.appUrl,
|
|
6728
|
+
appPublicUrl: this.appPublicUrl,
|
|
6729
|
+
apiUrl: this.apiUrl,
|
|
6730
|
+
proxyUrl: this.proxyUrl,
|
|
6731
|
+
loggedIn: this.loggedIn
|
|
6732
|
+
// Explicitly exclude loginToken, _apiConn, _appConn, _proxyConn and other sensitive fields
|
|
6733
|
+
};
|
|
6734
|
+
}
|
|
6735
|
+
// Custom inspect for Node.js console.log
|
|
6736
|
+
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
6737
|
+
return `BraintrustState {
|
|
6738
|
+
id: '${this.id}',
|
|
6739
|
+
orgId: ${this.orgId ? `'${this.orgId}'` : "null"},
|
|
6740
|
+
orgName: ${this.orgName ? `'${this.orgName}'` : "null"},
|
|
6741
|
+
appUrl: ${this.appUrl ? `'${this.appUrl}'` : "null"},
|
|
6742
|
+
apiUrl: ${this.apiUrl ? `'${this.apiUrl}'` : "null"},
|
|
6743
|
+
proxyUrl: ${this.proxyUrl ? `'${this.proxyUrl}'` : "null"},
|
|
6744
|
+
loggedIn: ${this.loggedIn},
|
|
6745
|
+
loginToken: '[REDACTED]'
|
|
6746
|
+
}`;
|
|
6747
|
+
}
|
|
6748
|
+
// Custom toString
|
|
6749
|
+
toString() {
|
|
6750
|
+
return `BraintrustState(id=${this.id}, org=${this.orgName || "none"}, loggedIn=${this.loggedIn})`;
|
|
6751
|
+
}
|
|
5743
6752
|
};
|
|
5744
6753
|
var _globalState;
|
|
5745
6754
|
function useTestBackgroundLogger() {
|
|
@@ -5907,6 +6916,17 @@ var HTTPConnection = class _HTTPConnection {
|
|
|
5907
6916
|
});
|
|
5908
6917
|
return await resp.json();
|
|
5909
6918
|
}
|
|
6919
|
+
// Custom inspect for Node.js console.log
|
|
6920
|
+
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
6921
|
+
return `HTTPConnection {
|
|
6922
|
+
base_url: '${this.base_url}',
|
|
6923
|
+
token: '[REDACTED]'
|
|
6924
|
+
}`;
|
|
6925
|
+
}
|
|
6926
|
+
// Custom toString
|
|
6927
|
+
toString() {
|
|
6928
|
+
return `HTTPConnection(${this.base_url})`;
|
|
6929
|
+
}
|
|
5910
6930
|
};
|
|
5911
6931
|
var BaseAttachment = class {
|
|
5912
6932
|
reference;
|
|
@@ -6007,9 +7027,9 @@ var Attachment = class extends BaseAttachment {
|
|
|
6007
7027
|
let signedUrl;
|
|
6008
7028
|
let headers;
|
|
6009
7029
|
try {
|
|
6010
|
-
({ signedUrl, headers } =
|
|
6011
|
-
signedUrl:
|
|
6012
|
-
headers:
|
|
7030
|
+
({ signedUrl, headers } = z7.object({
|
|
7031
|
+
signedUrl: z7.string().url(),
|
|
7032
|
+
headers: z7.record(z7.string())
|
|
6013
7033
|
}).parse(await metadataResponse.json()));
|
|
6014
7034
|
} catch (error2) {
|
|
6015
7035
|
if (error2 instanceof ZodError) {
|
|
@@ -6164,8 +7184,8 @@ var ExternalAttachment = class extends BaseAttachment {
|
|
|
6164
7184
|
});
|
|
6165
7185
|
}
|
|
6166
7186
|
};
|
|
6167
|
-
var attachmentMetadataSchema =
|
|
6168
|
-
downloadUrl:
|
|
7187
|
+
var attachmentMetadataSchema = z7.object({
|
|
7188
|
+
downloadUrl: z7.string(),
|
|
6169
7189
|
status: AttachmentStatus
|
|
6170
7190
|
});
|
|
6171
7191
|
var ReadonlyAttachment = class {
|
|
@@ -6377,15 +7397,15 @@ function spanComponentsToObjectIdLambda(state, components) {
|
|
|
6377
7397
|
);
|
|
6378
7398
|
}
|
|
6379
7399
|
switch (components.data.object_type) {
|
|
6380
|
-
case
|
|
7400
|
+
case 1 /* EXPERIMENT */:
|
|
6381
7401
|
throw new Error(
|
|
6382
7402
|
"Impossible: computeObjectMetadataArgs not supported for experiments"
|
|
6383
7403
|
);
|
|
6384
|
-
case
|
|
7404
|
+
case 3 /* PLAYGROUND_LOGS */:
|
|
6385
7405
|
throw new Error(
|
|
6386
7406
|
"Impossible: computeObjectMetadataArgs not supported for prompt sessions"
|
|
6387
7407
|
);
|
|
6388
|
-
case
|
|
7408
|
+
case 2 /* PROJECT_LOGS */:
|
|
6389
7409
|
return async () => (await computeLoggerMetadata(state, {
|
|
6390
7410
|
...components.data.compute_object_metadata_args
|
|
6391
7411
|
})).project.id;
|
|
@@ -6537,7 +7557,7 @@ var Logger = class {
|
|
|
6537
7557
|
return (async () => (await this.project).id)();
|
|
6538
7558
|
}
|
|
6539
7559
|
parentObjectType() {
|
|
6540
|
-
return
|
|
7560
|
+
return 2 /* PROJECT_LOGS */;
|
|
6541
7561
|
}
|
|
6542
7562
|
/**
|
|
6543
7563
|
* Log a single event. The event will be batched and uploaded behind the scenes if `logOptions.asyncFlush` is true.
|
|
@@ -6631,7 +7651,7 @@ var Logger = class {
|
|
|
6631
7651
|
parentSpanIds: args?.parentSpanIds,
|
|
6632
7652
|
propagatedEvent: args?.propagatedEvent
|
|
6633
7653
|
}),
|
|
6634
|
-
defaultRootType:
|
|
7654
|
+
defaultRootType: "task" /* TASK */
|
|
6635
7655
|
});
|
|
6636
7656
|
}
|
|
6637
7657
|
/**
|
|
@@ -7749,6 +8769,8 @@ function getSpanParentObject(options) {
|
|
|
7749
8769
|
if (!Object.is(parentSpan, NOOP_SPAN)) {
|
|
7750
8770
|
return parentSpan;
|
|
7751
8771
|
}
|
|
8772
|
+
const parentStr = options?.parent ?? state.currentParent.getStore();
|
|
8773
|
+
if (parentStr) return SpanComponentsV3.fromStr(parentStr);
|
|
7752
8774
|
const experiment = currentExperiment();
|
|
7753
8775
|
if (experiment) {
|
|
7754
8776
|
return experiment;
|
|
@@ -7965,35 +8987,35 @@ function setFetch(fetch2) {
|
|
|
7965
8987
|
}
|
|
7966
8988
|
function startSpanAndIsLogger(args) {
|
|
7967
8989
|
const state = args?.state ?? _globalState;
|
|
7968
|
-
const
|
|
7969
|
-
|
|
7970
|
-
|
|
7971
|
-
|
|
7972
|
-
|
|
7973
|
-
|
|
8990
|
+
const parentObject = getSpanParentObject({
|
|
8991
|
+
asyncFlush: args?.asyncFlush,
|
|
8992
|
+
parent: args?.parent,
|
|
8993
|
+
state
|
|
8994
|
+
});
|
|
8995
|
+
if (parentObject instanceof SpanComponentsV3) {
|
|
8996
|
+
const parentSpanIds = parentObject.data.row_id ? {
|
|
8997
|
+
spanId: parentObject.data.span_id,
|
|
8998
|
+
rootSpanId: parentObject.data.root_span_id
|
|
7974
8999
|
} : void 0;
|
|
7975
9000
|
const span = new SpanImpl({
|
|
7976
9001
|
state,
|
|
7977
9002
|
...args,
|
|
7978
|
-
parentObjectType:
|
|
9003
|
+
parentObjectType: parentObject.data.object_type,
|
|
7979
9004
|
parentObjectId: new LazyValue(
|
|
7980
|
-
spanComponentsToObjectIdLambda(state,
|
|
9005
|
+
spanComponentsToObjectIdLambda(state, parentObject)
|
|
7981
9006
|
),
|
|
7982
|
-
parentComputeObjectMetadataArgs:
|
|
9007
|
+
parentComputeObjectMetadataArgs: parentObject.data.compute_object_metadata_args ?? void 0,
|
|
7983
9008
|
parentSpanIds,
|
|
7984
9009
|
propagatedEvent: args?.propagatedEvent ?? // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
7985
|
-
(
|
|
9010
|
+
(parentObject.data.propagated_event ?? void 0)
|
|
7986
9011
|
});
|
|
7987
9012
|
return {
|
|
7988
9013
|
span,
|
|
7989
|
-
isSyncFlushLogger:
|
|
9014
|
+
isSyncFlushLogger: parentObject.data.object_type === 2 /* PROJECT_LOGS */ && // Since there's no parent logger here, we're free to choose the async flush
|
|
7990
9015
|
// behavior, and therefore propagate along whatever we get from the arguments
|
|
7991
9016
|
args?.asyncFlush === false
|
|
7992
9017
|
};
|
|
7993
9018
|
} else {
|
|
7994
|
-
const parentObject = getSpanParentObject({
|
|
7995
|
-
asyncFlush: args?.asyncFlush
|
|
7996
|
-
});
|
|
7997
9019
|
const span = parentObject.startSpan(args);
|
|
7998
9020
|
return {
|
|
7999
9021
|
span,
|
|
@@ -8143,7 +9165,7 @@ function validateAndSanitizeExperimentLogPartialArgs(event) {
|
|
|
8143
9165
|
function deepCopyEvent(event) {
|
|
8144
9166
|
const attachments = [];
|
|
8145
9167
|
const IDENTIFIER = "_bt_internal_saved_attachment";
|
|
8146
|
-
const savedAttachmentSchema =
|
|
9168
|
+
const savedAttachmentSchema = z7.strictObject({ [IDENTIFIER]: z7.number() });
|
|
8147
9169
|
const serialized = JSON.stringify(event, (_k, v) => {
|
|
8148
9170
|
if (v instanceof SpanImpl || v instanceof NoopSpan) {
|
|
8149
9171
|
return `<span>`;
|
|
@@ -8378,7 +9400,7 @@ var Experiment2 = class extends ObjectFetcher {
|
|
|
8378
9400
|
})();
|
|
8379
9401
|
}
|
|
8380
9402
|
parentObjectType() {
|
|
8381
|
-
return
|
|
9403
|
+
return 1 /* EXPERIMENT */;
|
|
8382
9404
|
}
|
|
8383
9405
|
async getState() {
|
|
8384
9406
|
await this.lazyMetadata.get();
|
|
@@ -8462,7 +9484,7 @@ var Experiment2 = class extends ObjectFetcher {
|
|
|
8462
9484
|
parentSpanIds: void 0,
|
|
8463
9485
|
propagatedEvent: args?.propagatedEvent
|
|
8464
9486
|
}),
|
|
8465
|
-
defaultRootType:
|
|
9487
|
+
defaultRootType: "eval" /* EVAL */
|
|
8466
9488
|
});
|
|
8467
9489
|
}
|
|
8468
9490
|
async fetchBaseExperiment() {
|
|
@@ -8881,7 +9903,7 @@ var SpanImpl = class _SpanImpl {
|
|
|
8881
9903
|
const baseUrl = `${appUrl}/app/${orgName}`;
|
|
8882
9904
|
const args = this.parentComputeObjectMetadataArgs;
|
|
8883
9905
|
switch (this.parentObjectType) {
|
|
8884
|
-
case
|
|
9906
|
+
case 2 /* PROJECT_LOGS */: {
|
|
8885
9907
|
const projectID = args?.project_id || this.parentObjectId.getSync().value;
|
|
8886
9908
|
const projectName = args?.project_name;
|
|
8887
9909
|
if (projectID) {
|
|
@@ -8892,7 +9914,7 @@ var SpanImpl = class _SpanImpl {
|
|
|
8892
9914
|
return getErrPermlink("provide-project-name-or-id");
|
|
8893
9915
|
}
|
|
8894
9916
|
}
|
|
8895
|
-
case
|
|
9917
|
+
case 1 /* EXPERIMENT */: {
|
|
8896
9918
|
const expID = args?.experiment_id || this.parentObjectId?.getSync()?.value;
|
|
8897
9919
|
if (!expID) {
|
|
8898
9920
|
return getErrPermlink("provide-experiment-id");
|
|
@@ -8900,7 +9922,7 @@ var SpanImpl = class _SpanImpl {
|
|
|
8900
9922
|
return `${baseUrl}/object?object_type=experiment&object_id=${expID}&id=${this._id}`;
|
|
8901
9923
|
}
|
|
8902
9924
|
}
|
|
8903
|
-
case
|
|
9925
|
+
case 3 /* PLAYGROUND_LOGS */: {
|
|
8904
9926
|
return NOOP_SPAN_PERMALINK;
|
|
8905
9927
|
}
|
|
8906
9928
|
default: {
|
|
@@ -8919,6 +9941,20 @@ var SpanImpl = class _SpanImpl {
|
|
|
8919
9941
|
state() {
|
|
8920
9942
|
return this._state;
|
|
8921
9943
|
}
|
|
9944
|
+
// Custom inspect for Node.js console.log
|
|
9945
|
+
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
9946
|
+
return `SpanImpl {
|
|
9947
|
+
kind: '${this.kind}',
|
|
9948
|
+
id: '${this.id}',
|
|
9949
|
+
spanId: '${this.spanId}',
|
|
9950
|
+
rootSpanId: '${this.rootSpanId}',
|
|
9951
|
+
spanParents: ${JSON.stringify(this.spanParents)}
|
|
9952
|
+
}`;
|
|
9953
|
+
}
|
|
9954
|
+
// Custom toString
|
|
9955
|
+
toString() {
|
|
9956
|
+
return `SpanImpl(id=${this.id}, spanId=${this.spanId})`;
|
|
9957
|
+
}
|
|
8922
9958
|
};
|
|
8923
9959
|
function splitLoggingData({
|
|
8924
9960
|
event,
|
|
@@ -9148,8 +10184,8 @@ var Dataset2 = class extends ObjectFetcher {
|
|
|
9148
10184
|
)}`;
|
|
9149
10185
|
let dataSummary;
|
|
9150
10186
|
if (summarizeData) {
|
|
9151
|
-
const rawDataSummary =
|
|
9152
|
-
total_records:
|
|
10187
|
+
const rawDataSummary = z7.object({
|
|
10188
|
+
total_records: z7.number()
|
|
9153
10189
|
}).parse(
|
|
9154
10190
|
await state.apiConn().get_json(
|
|
9155
10191
|
"dataset-summary",
|
|
@@ -9272,11 +10308,11 @@ function renderTemplatedObject(obj, args, options) {
|
|
|
9272
10308
|
return obj;
|
|
9273
10309
|
}
|
|
9274
10310
|
function renderPromptParams(params, args, options) {
|
|
9275
|
-
const schemaParsed =
|
|
9276
|
-
response_format:
|
|
9277
|
-
type:
|
|
10311
|
+
const schemaParsed = z7.object({
|
|
10312
|
+
response_format: z7.object({
|
|
10313
|
+
type: z7.literal("json_schema"),
|
|
9278
10314
|
json_schema: ResponseFormatJsonSchema.omit({ schema: true }).extend({
|
|
9279
|
-
schema:
|
|
10315
|
+
schema: z7.unknown()
|
|
9280
10316
|
})
|
|
9281
10317
|
})
|
|
9282
10318
|
}).safeParse(params);
|
|
@@ -9394,7 +10430,7 @@ var Prompt2 = class _Prompt {
|
|
|
9394
10430
|
if (!prompt) {
|
|
9395
10431
|
throw new Error("Empty prompt");
|
|
9396
10432
|
}
|
|
9397
|
-
const dictArgParsed =
|
|
10433
|
+
const dictArgParsed = z7.record(z7.unknown()).safeParse(buildArgs);
|
|
9398
10434
|
const variables = {
|
|
9399
10435
|
input: buildArgs,
|
|
9400
10436
|
...dictArgParsed.success ? dictArgParsed.data : {}
|
|
@@ -9449,7 +10485,7 @@ var Prompt2 = class _Prompt {
|
|
|
9449
10485
|
return JSON.stringify(v);
|
|
9450
10486
|
}
|
|
9451
10487
|
};
|
|
9452
|
-
const dictArgParsed =
|
|
10488
|
+
const dictArgParsed = z7.record(z7.unknown()).safeParse(buildArgs);
|
|
9453
10489
|
const variables = {
|
|
9454
10490
|
input: buildArgs,
|
|
9455
10491
|
...dictArgParsed.success ? dictArgParsed.data : {}
|
|
@@ -9681,6 +10717,7 @@ __export(exports_node_exports, {
|
|
|
9681
10717
|
currentExperiment: () => currentExperiment,
|
|
9682
10718
|
currentLogger: () => currentLogger,
|
|
9683
10719
|
currentSpan: () => currentSpan,
|
|
10720
|
+
deepCopyEvent: () => deepCopyEvent,
|
|
9684
10721
|
defaultErrorScoreHandler: () => defaultErrorScoreHandler,
|
|
9685
10722
|
deserializePlainStringAsJSON: () => deserializePlainStringAsJSON,
|
|
9686
10723
|
devNullWritableStream: () => devNullWritableStream,
|
|
@@ -9725,8 +10762,10 @@ __export(exports_node_exports, {
|
|
|
9725
10762
|
withExperiment: () => withExperiment,
|
|
9726
10763
|
withLogger: () => withLogger,
|
|
9727
10764
|
withParent: () => withParent,
|
|
10765
|
+
wrapAISDK: () => wrapAISDK,
|
|
9728
10766
|
wrapAISDKModel: () => wrapAISDKModel,
|
|
9729
10767
|
wrapAnthropic: () => wrapAnthropic,
|
|
10768
|
+
wrapMastraAgent: () => wrapMastraAgent,
|
|
9730
10769
|
wrapOpenAI: () => wrapOpenAI,
|
|
9731
10770
|
wrapOpenAIv4: () => wrapOpenAIv4,
|
|
9732
10771
|
wrapTraced: () => wrapTraced
|
|
@@ -9820,10 +10859,7 @@ function initFunction({
|
|
|
9820
10859
|
return f;
|
|
9821
10860
|
}
|
|
9822
10861
|
|
|
9823
|
-
//
|
|
9824
|
-
import { SpanTypeAttribute as SpanTypeAttribute2, mergeDicts as mergeDicts2 } from "@braintrust/core";
|
|
9825
|
-
|
|
9826
|
-
// ../../node_modules/.pnpm/async@3.2.5/node_modules/async/dist/async.mjs
|
|
10862
|
+
// ../node_modules/.pnpm/async@3.2.5/node_modules/async/dist/async.mjs
|
|
9827
10863
|
function initialParams(fn) {
|
|
9828
10864
|
return function(...args) {
|
|
9829
10865
|
var callback = args.pop();
|
|
@@ -10902,13 +11938,12 @@ var BarProgressReporter = class {
|
|
|
10902
11938
|
};
|
|
10903
11939
|
|
|
10904
11940
|
// src/eval-parameters.ts
|
|
10905
|
-
import { z as
|
|
11941
|
+
import { z as z9 } from "zod/v3";
|
|
10906
11942
|
|
|
10907
11943
|
// src/framework2.ts
|
|
10908
11944
|
import path2 from "path";
|
|
10909
11945
|
import slugifyLib from "slugify";
|
|
10910
|
-
import { z as
|
|
10911
|
-
import { loadPrettyXact } from "@braintrust/core";
|
|
11946
|
+
import { z as z8 } from "zod/v3";
|
|
10912
11947
|
var ProjectBuilder = class {
|
|
10913
11948
|
create(opts) {
|
|
10914
11949
|
return new Project2(opts);
|
|
@@ -11142,23 +12177,23 @@ var CodePrompt = class {
|
|
|
11142
12177
|
};
|
|
11143
12178
|
}
|
|
11144
12179
|
};
|
|
11145
|
-
var promptContentsSchema =
|
|
11146
|
-
|
|
11147
|
-
prompt:
|
|
12180
|
+
var promptContentsSchema = z8.union([
|
|
12181
|
+
z8.object({
|
|
12182
|
+
prompt: z8.string()
|
|
11148
12183
|
}),
|
|
11149
|
-
|
|
11150
|
-
messages:
|
|
12184
|
+
z8.object({
|
|
12185
|
+
messages: z8.array(ChatCompletionMessageParam)
|
|
11151
12186
|
})
|
|
11152
12187
|
]);
|
|
11153
12188
|
var promptDefinitionSchema = promptContentsSchema.and(
|
|
11154
|
-
|
|
11155
|
-
model:
|
|
12189
|
+
z8.object({
|
|
12190
|
+
model: z8.string(),
|
|
11156
12191
|
params: ModelParams.optional()
|
|
11157
12192
|
})
|
|
11158
12193
|
);
|
|
11159
12194
|
var promptDefinitionWithToolsSchema = promptDefinitionSchema.and(
|
|
11160
|
-
|
|
11161
|
-
tools:
|
|
12195
|
+
z8.object({
|
|
12196
|
+
tools: z8.array(ToolFunctionDefinition).optional()
|
|
11162
12197
|
})
|
|
11163
12198
|
);
|
|
11164
12199
|
var PromptBuilder = class {
|
|
@@ -11226,7 +12261,7 @@ var ProjectNameIdMap = class {
|
|
|
11226
12261
|
const response = await _internalGetGlobalState().appConn().post_json("api/project/register", {
|
|
11227
12262
|
project_name: projectName
|
|
11228
12263
|
});
|
|
11229
|
-
const result =
|
|
12264
|
+
const result = z8.object({
|
|
11230
12265
|
project: Project
|
|
11231
12266
|
}).parse(response);
|
|
11232
12267
|
const projectId = result.project.id;
|
|
@@ -11240,7 +12275,7 @@ var ProjectNameIdMap = class {
|
|
|
11240
12275
|
const response = await _internalGetGlobalState().appConn().post_json("api/project/get", {
|
|
11241
12276
|
id: projectId
|
|
11242
12277
|
});
|
|
11243
|
-
const result =
|
|
12278
|
+
const result = z8.array(Project).nonempty().parse(response);
|
|
11244
12279
|
const projectName = result[0].name;
|
|
11245
12280
|
this.idToName[projectId] = projectName;
|
|
11246
12281
|
this.nameToId[projectName] = projectId;
|
|
@@ -11256,15 +12291,15 @@ var ProjectNameIdMap = class {
|
|
|
11256
12291
|
};
|
|
11257
12292
|
|
|
11258
12293
|
// src/eval-parameters.ts
|
|
11259
|
-
var evalParametersSchema =
|
|
11260
|
-
|
|
11261
|
-
|
|
11262
|
-
|
|
11263
|
-
type:
|
|
12294
|
+
var evalParametersSchema = z9.record(
|
|
12295
|
+
z9.string(),
|
|
12296
|
+
z9.union([
|
|
12297
|
+
z9.object({
|
|
12298
|
+
type: z9.literal("prompt"),
|
|
11264
12299
|
default: promptDefinitionWithToolsSchema.optional(),
|
|
11265
|
-
description:
|
|
12300
|
+
description: z9.string().optional()
|
|
11266
12301
|
}),
|
|
11267
|
-
|
|
12302
|
+
z9.instanceof(z9.ZodType)
|
|
11268
12303
|
// For Zod schemas
|
|
11269
12304
|
])
|
|
11270
12305
|
);
|
|
@@ -11566,7 +12601,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
11566
12601
|
const baseEvent = {
|
|
11567
12602
|
name: "eval",
|
|
11568
12603
|
spanAttributes: {
|
|
11569
|
-
type:
|
|
12604
|
+
type: "eval" /* EVAL */
|
|
11570
12605
|
},
|
|
11571
12606
|
event: {
|
|
11572
12607
|
input: datum.input,
|
|
@@ -11626,7 +12661,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
11626
12661
|
},
|
|
11627
12662
|
{
|
|
11628
12663
|
name: "task",
|
|
11629
|
-
spanAttributes: { type:
|
|
12664
|
+
spanAttributes: { type: "task" /* TASK */ },
|
|
11630
12665
|
event: { input: datum.input }
|
|
11631
12666
|
}
|
|
11632
12667
|
);
|
|
@@ -11672,17 +12707,17 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
11672
12707
|
return rest;
|
|
11673
12708
|
};
|
|
11674
12709
|
const resultMetadata = results3.length === 1 ? results3[0].metadata : results3.reduce(
|
|
11675
|
-
(prev, s) =>
|
|
12710
|
+
(prev, s) => mergeDicts(prev, {
|
|
11676
12711
|
[s.name]: s.metadata
|
|
11677
12712
|
}),
|
|
11678
12713
|
{}
|
|
11679
12714
|
);
|
|
11680
12715
|
const resultOutput = results3.length === 1 ? getOtherFields(results3[0]) : results3.reduce(
|
|
11681
|
-
(prev, s) =>
|
|
12716
|
+
(prev, s) => mergeDicts(prev, { [s.name]: getOtherFields(s) }),
|
|
11682
12717
|
{}
|
|
11683
12718
|
);
|
|
11684
12719
|
const scores2 = results3.reduce(
|
|
11685
|
-
(prev, s) =>
|
|
12720
|
+
(prev, s) => mergeDicts(prev, { [s.name]: s.score }),
|
|
11686
12721
|
{}
|
|
11687
12722
|
);
|
|
11688
12723
|
span.log({
|
|
@@ -11695,7 +12730,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
11695
12730
|
const results2 = await rootSpan.traced(runScorer, {
|
|
11696
12731
|
name: scorerNames[score_idx],
|
|
11697
12732
|
spanAttributes: {
|
|
11698
|
-
type:
|
|
12733
|
+
type: "score" /* SCORE */
|
|
11699
12734
|
},
|
|
11700
12735
|
event: { input: scoringArgs }
|
|
11701
12736
|
});
|
|
@@ -12038,11 +13073,11 @@ var GraphBuilder = class {
|
|
|
12038
13073
|
// }
|
|
12039
13074
|
// Helper to generate node IDs
|
|
12040
13075
|
generateId(name) {
|
|
12041
|
-
const
|
|
13076
|
+
const uuid4 = newId();
|
|
12042
13077
|
if (name) {
|
|
12043
|
-
return `${name}-${
|
|
13078
|
+
return `${name}-${uuid4.slice(0, 8)}`;
|
|
12044
13079
|
} else {
|
|
12045
|
-
return
|
|
13080
|
+
return uuid4;
|
|
12046
13081
|
}
|
|
12047
13082
|
}
|
|
12048
13083
|
// Create an input node
|
|
@@ -12195,12 +13230,7 @@ function unescapePath(path3) {
|
|
|
12195
13230
|
}
|
|
12196
13231
|
var graph_framework_default = { createGraph };
|
|
12197
13232
|
|
|
12198
|
-
// src/wrappers/oai.ts
|
|
12199
|
-
import { SpanTypeAttribute as SpanTypeAttribute3 } from "@braintrust/core";
|
|
12200
|
-
import { mergeDicts as mergeDicts3 } from "@braintrust/core";
|
|
12201
|
-
|
|
12202
13233
|
// src/wrappers/oai_responses.ts
|
|
12203
|
-
import { isObject as isObject2 } from "@braintrust/core";
|
|
12204
13234
|
function responsesProxy(openai) {
|
|
12205
13235
|
if (!openai.responses) {
|
|
12206
13236
|
return openai;
|
|
@@ -12250,7 +13280,7 @@ function parseSpanFromResponseCreateParams(params) {
|
|
|
12250
13280
|
function parseEventFromResponseCreateResult(result) {
|
|
12251
13281
|
const data = {};
|
|
12252
13282
|
if (result?.output !== void 0) {
|
|
12253
|
-
data.output = result.output;
|
|
13283
|
+
data.output = processImagesInOutput(result.output);
|
|
12254
13284
|
}
|
|
12255
13285
|
if (result) {
|
|
12256
13286
|
const { output, usage, ...metadata } = result;
|
|
@@ -12261,6 +13291,35 @@ function parseEventFromResponseCreateResult(result) {
|
|
|
12261
13291
|
data.metrics = parseMetricsFromUsage(result?.usage);
|
|
12262
13292
|
return data;
|
|
12263
13293
|
}
|
|
13294
|
+
function processImagesInOutput(output) {
|
|
13295
|
+
if (Array.isArray(output)) {
|
|
13296
|
+
return output.map(processImagesInOutput);
|
|
13297
|
+
}
|
|
13298
|
+
if (isObject(output)) {
|
|
13299
|
+
if (output.type === "image_generation_call" && output.result && typeof output.result === "string") {
|
|
13300
|
+
const fileExtension = output.output_format || "png";
|
|
13301
|
+
const contentType = `image/${fileExtension}`;
|
|
13302
|
+
const baseFilename = output.revised_prompt && typeof output.revised_prompt === "string" ? output.revised_prompt.slice(0, 50).replace(/[^a-zA-Z0-9]/g, "_") : "generated_image";
|
|
13303
|
+
const filename = `${baseFilename}.${fileExtension}`;
|
|
13304
|
+
const binaryString = atob(output.result);
|
|
13305
|
+
const bytes = new Uint8Array(binaryString.length);
|
|
13306
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
13307
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
13308
|
+
}
|
|
13309
|
+
const blob = new Blob([bytes], { type: contentType });
|
|
13310
|
+
const attachment = new Attachment({
|
|
13311
|
+
data: blob,
|
|
13312
|
+
filename,
|
|
13313
|
+
contentType
|
|
13314
|
+
});
|
|
13315
|
+
return {
|
|
13316
|
+
...output,
|
|
13317
|
+
result: attachment
|
|
13318
|
+
};
|
|
13319
|
+
}
|
|
13320
|
+
}
|
|
13321
|
+
return output;
|
|
13322
|
+
}
|
|
12264
13323
|
function parseSpanFromResponseParseParams(params) {
|
|
12265
13324
|
const spanArgs = {
|
|
12266
13325
|
name: "openai.responses.parse",
|
|
@@ -12284,7 +13343,7 @@ function parseSpanFromResponseParseParams(params) {
|
|
|
12284
13343
|
function parseEventFromResponseParseResult(result) {
|
|
12285
13344
|
const data = {};
|
|
12286
13345
|
if (result?.output !== void 0) {
|
|
12287
|
-
data.output = result.output;
|
|
13346
|
+
data.output = processImagesInOutput(result.output);
|
|
12288
13347
|
}
|
|
12289
13348
|
if (result) {
|
|
12290
13349
|
const { output, usage, ...metadata } = result;
|
|
@@ -12328,7 +13387,7 @@ function parseLogFromItem(item) {
|
|
|
12328
13387
|
case "response.completed":
|
|
12329
13388
|
const data = {};
|
|
12330
13389
|
if (response?.output !== void 0) {
|
|
12331
|
-
data.output = response.output;
|
|
13390
|
+
data.output = processImagesInOutput(response.output);
|
|
12332
13391
|
}
|
|
12333
13392
|
if (response) {
|
|
12334
13393
|
const { usage, output, ...metadata } = response;
|
|
@@ -12398,7 +13457,7 @@ function parseMetricsFromUsage(usage) {
|
|
|
12398
13457
|
const metricName = TOKEN_NAME_MAP[oai_name] || oai_name;
|
|
12399
13458
|
metrics[metricName] = value;
|
|
12400
13459
|
} else if (oai_name.endsWith("_tokens_details")) {
|
|
12401
|
-
if (!
|
|
13460
|
+
if (!isObject(value)) {
|
|
12402
13461
|
continue;
|
|
12403
13462
|
}
|
|
12404
13463
|
const rawPrefix = oai_name.slice(0, -"_tokens_details".length);
|
|
@@ -12580,11 +13639,11 @@ function wrapBetaChatCompletionParse(completion) {
|
|
|
12580
13639
|
return async (allParams) => {
|
|
12581
13640
|
const { span_info: _, ...params } = allParams;
|
|
12582
13641
|
const span = startSpan(
|
|
12583
|
-
|
|
13642
|
+
mergeDicts(
|
|
12584
13643
|
{
|
|
12585
13644
|
name: "Chat Completion",
|
|
12586
13645
|
spanAttributes: {
|
|
12587
|
-
type:
|
|
13646
|
+
type: "llm" /* LLM */
|
|
12588
13647
|
}
|
|
12589
13648
|
},
|
|
12590
13649
|
parseChatCompletionParams(allParams)
|
|
@@ -12604,11 +13663,11 @@ function wrapBetaChatCompletionStream(completion) {
|
|
|
12604
13663
|
return (allParams) => {
|
|
12605
13664
|
const { span_info: _, ...params } = allParams;
|
|
12606
13665
|
const span = startSpan(
|
|
12607
|
-
|
|
13666
|
+
mergeDicts(
|
|
12608
13667
|
{
|
|
12609
13668
|
name: "Chat Completion",
|
|
12610
13669
|
spanAttributes: {
|
|
12611
|
-
type:
|
|
13670
|
+
type: "llm" /* LLM */
|
|
12612
13671
|
}
|
|
12613
13672
|
},
|
|
12614
13673
|
parseChatCompletionParams(allParams)
|
|
@@ -12667,15 +13726,16 @@ function wrapChatCompletion(completion) {
|
|
|
12667
13726
|
return (allParams, options) => {
|
|
12668
13727
|
const { span_info: _, ...params } = allParams;
|
|
12669
13728
|
let executionPromise = null;
|
|
12670
|
-
|
|
13729
|
+
let dataPromise = null;
|
|
13730
|
+
const ensureExecuted = () => {
|
|
12671
13731
|
if (!executionPromise) {
|
|
12672
13732
|
executionPromise = (async () => {
|
|
12673
13733
|
const span = startSpan(
|
|
12674
|
-
|
|
13734
|
+
mergeDicts(
|
|
12675
13735
|
{
|
|
12676
13736
|
name: "Chat Completion",
|
|
12677
13737
|
spanAttributes: {
|
|
12678
|
-
type:
|
|
13738
|
+
type: "llm" /* LLM */
|
|
12679
13739
|
}
|
|
12680
13740
|
},
|
|
12681
13741
|
parseChatCompletionParams(allParams)
|
|
@@ -12725,17 +13785,19 @@ function wrapChatCompletion(completion) {
|
|
|
12725
13785
|
}
|
|
12726
13786
|
return executionPromise;
|
|
12727
13787
|
};
|
|
12728
|
-
|
|
12729
|
-
return new Proxy(dataPromise, {
|
|
13788
|
+
return new Proxy({}, {
|
|
12730
13789
|
get(target, prop, receiver) {
|
|
12731
13790
|
if (prop === "withResponse") {
|
|
12732
|
-
return
|
|
13791
|
+
return () => ensureExecuted();
|
|
12733
13792
|
}
|
|
12734
|
-
|
|
12735
|
-
|
|
12736
|
-
|
|
13793
|
+
if (prop === "then" || prop === "catch" || prop === "finally" || prop in Promise.prototype) {
|
|
13794
|
+
if (!dataPromise) {
|
|
13795
|
+
dataPromise = ensureExecuted().then((result) => result.data);
|
|
13796
|
+
}
|
|
13797
|
+
const value = Reflect.get(dataPromise, prop, receiver);
|
|
13798
|
+
return typeof value === "function" ? value.bind(dataPromise) : value;
|
|
12737
13799
|
}
|
|
12738
|
-
return
|
|
13800
|
+
return Reflect.get(target, prop, receiver);
|
|
12739
13801
|
}
|
|
12740
13802
|
});
|
|
12741
13803
|
};
|
|
@@ -12752,7 +13814,7 @@ function parseBaseParams(allParams, inputField) {
|
|
|
12752
13814
|
const input = params[inputField];
|
|
12753
13815
|
const paramsRest = { ...params, provider: "openai" };
|
|
12754
13816
|
delete paramsRest[inputField];
|
|
12755
|
-
return
|
|
13817
|
+
return mergeDicts(ret, { event: { input, metadata: paramsRest } });
|
|
12756
13818
|
}
|
|
12757
13819
|
function createApiWrapper(name, create, processResponse, parseParams) {
|
|
12758
13820
|
return async (allParams, options) => {
|
|
@@ -12767,11 +13829,11 @@ function createApiWrapper(name, create, processResponse, parseParams) {
|
|
|
12767
13829
|
processResponse(result, span);
|
|
12768
13830
|
return result;
|
|
12769
13831
|
},
|
|
12770
|
-
|
|
13832
|
+
mergeDicts(
|
|
12771
13833
|
{
|
|
12772
13834
|
name,
|
|
12773
13835
|
spanAttributes: {
|
|
12774
|
-
type:
|
|
13836
|
+
type: "llm" /* LLM */
|
|
12775
13837
|
}
|
|
12776
13838
|
},
|
|
12777
13839
|
parseParams(allParams)
|
|
@@ -12909,9 +13971,6 @@ var WrapperStream = class {
|
|
|
12909
13971
|
}
|
|
12910
13972
|
};
|
|
12911
13973
|
|
|
12912
|
-
// src/wrappers/ai-sdk-v2.ts
|
|
12913
|
-
import { SpanTypeAttribute as SpanTypeAttribute4 } from "@braintrust/core";
|
|
12914
|
-
|
|
12915
13974
|
// src/wrappers/anthropic-tokens-util.ts
|
|
12916
13975
|
function finalizeAnthropicTokens(metrics) {
|
|
12917
13976
|
const prompt_tokens = (metrics.prompt_tokens || 0) + (metrics.prompt_cached_tokens || 0) + (metrics.prompt_cache_creation_tokens || 0);
|
|
@@ -12932,7 +13991,7 @@ function extractAnthropicCacheTokens(cacheReadTokens = 0, cacheCreationTokens =
|
|
|
12932
13991
|
return cacheTokens;
|
|
12933
13992
|
}
|
|
12934
13993
|
|
|
12935
|
-
// src/wrappers/ai-sdk-
|
|
13994
|
+
// src/wrappers/ai-sdk-shared.ts
|
|
12936
13995
|
function detectProviderFromResult(result) {
|
|
12937
13996
|
if (!result?.providerMetadata) {
|
|
12938
13997
|
return void 0;
|
|
@@ -12952,20 +14011,8 @@ function extractModelFromResult(result) {
|
|
|
12952
14011
|
function camelToSnake(str) {
|
|
12953
14012
|
return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
|
|
12954
14013
|
}
|
|
12955
|
-
function extractModelParameters(params) {
|
|
14014
|
+
function extractModelParameters(params, excludeKeys) {
|
|
12956
14015
|
const modelParams = {};
|
|
12957
|
-
const excludeKeys = /* @__PURE__ */ new Set([
|
|
12958
|
-
"prompt",
|
|
12959
|
-
// Already captured as input
|
|
12960
|
-
"system",
|
|
12961
|
-
// Already captured as input
|
|
12962
|
-
"messages",
|
|
12963
|
-
// Already captured as input
|
|
12964
|
-
"model",
|
|
12965
|
-
// Already captured in metadata.model
|
|
12966
|
-
"providerOptions"
|
|
12967
|
-
// Internal AI SDK configuration
|
|
12968
|
-
]);
|
|
12969
14016
|
for (const [key, value] of Object.entries(params)) {
|
|
12970
14017
|
if (value !== void 0 && !excludeKeys.has(key)) {
|
|
12971
14018
|
const snakeKey = camelToSnake(key);
|
|
@@ -13021,18 +14068,128 @@ function normalizeUsageMetrics(usage, provider, providerMetadata) {
|
|
|
13021
14068
|
}
|
|
13022
14069
|
return metrics;
|
|
13023
14070
|
}
|
|
14071
|
+
function normalizeFinishReason(reason) {
|
|
14072
|
+
if (typeof reason !== "string") return void 0;
|
|
14073
|
+
return reason.replace(/-/g, "_");
|
|
14074
|
+
}
|
|
14075
|
+
function extractToolCallsFromSteps(steps) {
|
|
14076
|
+
const toolCalls = [];
|
|
14077
|
+
if (!Array.isArray(steps)) return toolCalls;
|
|
14078
|
+
let idx = 0;
|
|
14079
|
+
for (const step of steps) {
|
|
14080
|
+
const blocks = step?.content;
|
|
14081
|
+
if (!Array.isArray(blocks)) continue;
|
|
14082
|
+
for (const block of blocks) {
|
|
14083
|
+
if (block && typeof block === "object" && block.type === "tool-call") {
|
|
14084
|
+
toolCalls.push({
|
|
14085
|
+
id: block.toolCallId,
|
|
14086
|
+
type: "function",
|
|
14087
|
+
index: idx++,
|
|
14088
|
+
function: {
|
|
14089
|
+
name: block.toolName,
|
|
14090
|
+
arguments: typeof block.input === "string" ? block.input : JSON.stringify(block.input ?? {})
|
|
14091
|
+
}
|
|
14092
|
+
});
|
|
14093
|
+
}
|
|
14094
|
+
}
|
|
14095
|
+
}
|
|
14096
|
+
return toolCalls;
|
|
14097
|
+
}
|
|
14098
|
+
function buildAssistantOutputWithToolCalls(result, toolCalls) {
|
|
14099
|
+
return [
|
|
14100
|
+
{
|
|
14101
|
+
index: 0,
|
|
14102
|
+
logprobs: null,
|
|
14103
|
+
finish_reason: normalizeFinishReason(result?.finishReason) ?? (toolCalls.length ? "tool_calls" : void 0),
|
|
14104
|
+
message: {
|
|
14105
|
+
role: "assistant",
|
|
14106
|
+
tool_calls: toolCalls.length > 0 ? toolCalls : void 0
|
|
14107
|
+
}
|
|
14108
|
+
}
|
|
14109
|
+
];
|
|
14110
|
+
}
|
|
14111
|
+
function extractToolCallsFromBlocks(blocks) {
|
|
14112
|
+
if (!Array.isArray(blocks)) return [];
|
|
14113
|
+
return extractToolCallsFromSteps([{ content: blocks }]);
|
|
14114
|
+
}
|
|
14115
|
+
function wrapTools(tools) {
|
|
14116
|
+
if (!tools) return tools;
|
|
14117
|
+
const inferName = (tool, fallback2) => tool && (tool.name || tool.toolName || tool.id) || fallback2;
|
|
14118
|
+
if (Array.isArray(tools)) {
|
|
14119
|
+
const arr = tools;
|
|
14120
|
+
const out = arr.map((tool, idx) => {
|
|
14121
|
+
if (tool != null && typeof tool === "object" && "execute" in tool && typeof tool.execute === "function") {
|
|
14122
|
+
const name = inferName(tool, `tool[${idx}]`);
|
|
14123
|
+
return {
|
|
14124
|
+
...tool,
|
|
14125
|
+
execute: wrapTraced(tool.execute.bind(tool), {
|
|
14126
|
+
name,
|
|
14127
|
+
type: "tool"
|
|
14128
|
+
})
|
|
14129
|
+
};
|
|
14130
|
+
}
|
|
14131
|
+
return tool;
|
|
14132
|
+
});
|
|
14133
|
+
return out;
|
|
14134
|
+
}
|
|
14135
|
+
const wrappedTools = {};
|
|
14136
|
+
for (const [key, tool] of Object.entries(tools)) {
|
|
14137
|
+
if (tool != null && typeof tool === "object" && "execute" in tool && typeof tool.execute === "function") {
|
|
14138
|
+
wrappedTools[key] = {
|
|
14139
|
+
...tool,
|
|
14140
|
+
execute: wrapTraced(tool.execute.bind(tool), {
|
|
14141
|
+
name: key,
|
|
14142
|
+
type: "tool"
|
|
14143
|
+
})
|
|
14144
|
+
};
|
|
14145
|
+
} else {
|
|
14146
|
+
wrappedTools[key] = tool;
|
|
14147
|
+
}
|
|
14148
|
+
}
|
|
14149
|
+
return wrappedTools;
|
|
14150
|
+
}
|
|
14151
|
+
function extractInput(params) {
|
|
14152
|
+
return params?.prompt ?? params?.messages ?? params?.system;
|
|
14153
|
+
}
|
|
14154
|
+
function wrapStreamObject(iterable, onFirst) {
|
|
14155
|
+
let sawFirst = false;
|
|
14156
|
+
async function* wrapStream() {
|
|
14157
|
+
for await (const chunk of iterable) {
|
|
14158
|
+
if (!sawFirst) {
|
|
14159
|
+
sawFirst = true;
|
|
14160
|
+
onFirst();
|
|
14161
|
+
}
|
|
14162
|
+
yield chunk;
|
|
14163
|
+
}
|
|
14164
|
+
}
|
|
14165
|
+
return wrapStream();
|
|
14166
|
+
}
|
|
14167
|
+
|
|
14168
|
+
// src/wrappers/ai-sdk-v2.ts
|
|
14169
|
+
var V2_EXCLUDE_KEYS = /* @__PURE__ */ new Set([
|
|
14170
|
+
"prompt",
|
|
14171
|
+
// Already captured as input
|
|
14172
|
+
"system",
|
|
14173
|
+
// Already captured as input
|
|
14174
|
+
"messages",
|
|
14175
|
+
// Already captured as input
|
|
14176
|
+
"model",
|
|
14177
|
+
// Already captured in metadata.model
|
|
14178
|
+
"providerOptions"
|
|
14179
|
+
// Internal AI SDK configuration
|
|
14180
|
+
]);
|
|
13024
14181
|
function BraintrustMiddleware(config = {}) {
|
|
13025
14182
|
return {
|
|
13026
14183
|
wrapGenerate: async ({ doGenerate, params }) => {
|
|
13027
14184
|
const spanArgs = {
|
|
13028
14185
|
name: "ai-sdk.generateText",
|
|
13029
14186
|
spanAttributes: {
|
|
13030
|
-
type:
|
|
14187
|
+
type: "llm" /* LLM */
|
|
13031
14188
|
},
|
|
13032
14189
|
event: {
|
|
13033
14190
|
input: params.prompt,
|
|
13034
14191
|
metadata: {
|
|
13035
|
-
...extractModelParameters(params)
|
|
14192
|
+
...extractModelParameters(params, V2_EXCLUDE_KEYS)
|
|
13036
14193
|
}
|
|
13037
14194
|
}
|
|
13038
14195
|
};
|
|
@@ -13051,8 +14208,12 @@ function BraintrustMiddleware(config = {}) {
|
|
|
13051
14208
|
if (model !== void 0) {
|
|
13052
14209
|
metadata.model = model;
|
|
13053
14210
|
}
|
|
14211
|
+
let toolCalls = extractToolCallsFromSteps(result?.steps);
|
|
14212
|
+
if (!toolCalls || toolCalls.length === 0) {
|
|
14213
|
+
toolCalls = extractToolCallsFromBlocks(result?.content);
|
|
14214
|
+
}
|
|
13054
14215
|
span.log({
|
|
13055
|
-
output: result
|
|
14216
|
+
output: toolCalls.length > 0 ? buildAssistantOutputWithToolCalls(result, toolCalls) : result?.content,
|
|
13056
14217
|
metadata,
|
|
13057
14218
|
metrics: normalizeUsageMetrics(
|
|
13058
14219
|
result.usage,
|
|
@@ -13074,12 +14235,12 @@ function BraintrustMiddleware(config = {}) {
|
|
|
13074
14235
|
const spanArgs = {
|
|
13075
14236
|
name: "ai-sdk.streamText",
|
|
13076
14237
|
spanAttributes: {
|
|
13077
|
-
type:
|
|
14238
|
+
type: "llm" /* LLM */
|
|
13078
14239
|
},
|
|
13079
14240
|
event: {
|
|
13080
14241
|
input: params.prompt,
|
|
13081
14242
|
metadata: {
|
|
13082
|
-
...extractModelParameters(params)
|
|
14243
|
+
...extractModelParameters(params, V2_EXCLUDE_KEYS)
|
|
13083
14244
|
}
|
|
13084
14245
|
}
|
|
13085
14246
|
};
|
|
@@ -13087,6 +14248,7 @@ function BraintrustMiddleware(config = {}) {
|
|
|
13087
14248
|
try {
|
|
13088
14249
|
const { stream, ...rest } = await doStream();
|
|
13089
14250
|
const textChunks = [];
|
|
14251
|
+
const toolBlocks = [];
|
|
13090
14252
|
let finalUsage = {};
|
|
13091
14253
|
let finalFinishReason = void 0;
|
|
13092
14254
|
let providerMetadata = {};
|
|
@@ -13097,6 +14259,9 @@ function BraintrustMiddleware(config = {}) {
|
|
|
13097
14259
|
if (chunk.type === "text-delta" && chunk.delta) {
|
|
13098
14260
|
textChunks.push(chunk.delta);
|
|
13099
14261
|
}
|
|
14262
|
+
if (chunk.type === "tool-call" || chunk.type === "tool-result") {
|
|
14263
|
+
toolBlocks.push(chunk);
|
|
14264
|
+
}
|
|
13100
14265
|
if (chunk.type === "finish") {
|
|
13101
14266
|
finalFinishReason = chunk.finishReason;
|
|
13102
14267
|
finalUsage = chunk.usage || {};
|
|
@@ -13114,11 +14279,12 @@ function BraintrustMiddleware(config = {}) {
|
|
|
13114
14279
|
flush() {
|
|
13115
14280
|
try {
|
|
13116
14281
|
const generatedText = textChunks.join("");
|
|
13117
|
-
|
|
14282
|
+
let output = generatedText ? [{ type: "text", text: generatedText }] : [];
|
|
13118
14283
|
const resultForDetection = {
|
|
13119
14284
|
providerMetadata,
|
|
13120
14285
|
response: rest.response,
|
|
13121
|
-
...rest
|
|
14286
|
+
...rest,
|
|
14287
|
+
finishReason: finalFinishReason
|
|
13122
14288
|
};
|
|
13123
14289
|
const metadata = {};
|
|
13124
14290
|
const provider = detectProviderFromResult(resultForDetection);
|
|
@@ -13132,6 +14298,17 @@ function BraintrustMiddleware(config = {}) {
|
|
|
13132
14298
|
if (model !== void 0) {
|
|
13133
14299
|
metadata.model = model;
|
|
13134
14300
|
}
|
|
14301
|
+
if (toolBlocks.length > 0) {
|
|
14302
|
+
const toolCalls = extractToolCallsFromSteps([
|
|
14303
|
+
{ content: toolBlocks }
|
|
14304
|
+
]);
|
|
14305
|
+
if (toolCalls.length > 0) {
|
|
14306
|
+
output = buildAssistantOutputWithToolCalls(
|
|
14307
|
+
resultForDetection,
|
|
14308
|
+
toolCalls
|
|
14309
|
+
);
|
|
14310
|
+
}
|
|
14311
|
+
}
|
|
13135
14312
|
span.log({
|
|
13136
14313
|
output,
|
|
13137
14314
|
metadata,
|
|
@@ -13441,8 +14618,385 @@ function postProcessOutput(text, toolCalls, finishReason) {
|
|
|
13441
14618
|
];
|
|
13442
14619
|
}
|
|
13443
14620
|
|
|
14621
|
+
// src/wrappers/ai-sdk-v3.ts
|
|
14622
|
+
var V3_EXCLUDE_KEYS = /* @__PURE__ */ new Set([
|
|
14623
|
+
"prompt",
|
|
14624
|
+
// Already captured as input
|
|
14625
|
+
"system",
|
|
14626
|
+
// Already captured as input
|
|
14627
|
+
"messages",
|
|
14628
|
+
// Already captured as input
|
|
14629
|
+
"model",
|
|
14630
|
+
// Already captured in metadata.model
|
|
14631
|
+
"providerOptions",
|
|
14632
|
+
// Internal AI SDK configuration
|
|
14633
|
+
"tools"
|
|
14634
|
+
// Already captured in metadata.tools
|
|
14635
|
+
]);
|
|
14636
|
+
function wrapAISDK(ai) {
|
|
14637
|
+
const {
|
|
14638
|
+
wrapLanguageModel,
|
|
14639
|
+
generateText,
|
|
14640
|
+
streamText,
|
|
14641
|
+
generateObject,
|
|
14642
|
+
streamObject
|
|
14643
|
+
} = ai;
|
|
14644
|
+
const wrappedGenerateText = (params) => {
|
|
14645
|
+
return traced(
|
|
14646
|
+
async (span) => {
|
|
14647
|
+
const wrappedModel = wrapLanguageModel({
|
|
14648
|
+
model: params.model,
|
|
14649
|
+
middleware: BraintrustMiddleware()
|
|
14650
|
+
});
|
|
14651
|
+
const result = await generateText({
|
|
14652
|
+
...params,
|
|
14653
|
+
tools: params.tools ? wrapTools(params.tools) : void 0,
|
|
14654
|
+
model: wrappedModel
|
|
14655
|
+
});
|
|
14656
|
+
const provider = detectProviderFromResult(result);
|
|
14657
|
+
const model = extractModelFromResult(result);
|
|
14658
|
+
const finishReason = normalizeFinishReason(result?.finishReason);
|
|
14659
|
+
span.log({
|
|
14660
|
+
input: extractInput(params),
|
|
14661
|
+
output: result.text,
|
|
14662
|
+
metadata: {
|
|
14663
|
+
...extractModelParameters(params, V3_EXCLUDE_KEYS),
|
|
14664
|
+
...provider ? { provider } : {},
|
|
14665
|
+
...model ? { model } : {},
|
|
14666
|
+
...finishReason ? { finish_reason: finishReason } : {}
|
|
14667
|
+
}
|
|
14668
|
+
});
|
|
14669
|
+
return result;
|
|
14670
|
+
},
|
|
14671
|
+
{
|
|
14672
|
+
name: "ai-sdk.generateText"
|
|
14673
|
+
}
|
|
14674
|
+
);
|
|
14675
|
+
};
|
|
14676
|
+
const wrappedGenerateObject = (params) => {
|
|
14677
|
+
return traced(
|
|
14678
|
+
async (span) => {
|
|
14679
|
+
const wrappedModel = wrapLanguageModel({
|
|
14680
|
+
model: params.model,
|
|
14681
|
+
middleware: BraintrustMiddleware()
|
|
14682
|
+
});
|
|
14683
|
+
const result = await generateObject({
|
|
14684
|
+
...params,
|
|
14685
|
+
tools: params.tools ? wrapTools(params.tools) : void 0,
|
|
14686
|
+
model: wrappedModel
|
|
14687
|
+
});
|
|
14688
|
+
const provider = detectProviderFromResult(result);
|
|
14689
|
+
const model = extractModelFromResult(result);
|
|
14690
|
+
const finishReason = normalizeFinishReason(result.finishReason);
|
|
14691
|
+
span.log({
|
|
14692
|
+
input: extractInput(params),
|
|
14693
|
+
output: result.object,
|
|
14694
|
+
metadata: {
|
|
14695
|
+
...extractModelParameters(params, V3_EXCLUDE_KEYS),
|
|
14696
|
+
...provider ? { provider } : {},
|
|
14697
|
+
...model ? { model } : {},
|
|
14698
|
+
...finishReason ? { finish_reason: finishReason } : {}
|
|
14699
|
+
}
|
|
14700
|
+
});
|
|
14701
|
+
return result;
|
|
14702
|
+
},
|
|
14703
|
+
{
|
|
14704
|
+
name: "ai-sdk.generateObject"
|
|
14705
|
+
}
|
|
14706
|
+
);
|
|
14707
|
+
};
|
|
14708
|
+
const wrappedStreamText = (params) => {
|
|
14709
|
+
const span = startSpan({
|
|
14710
|
+
name: "ai-sdk.streamText",
|
|
14711
|
+
event: {
|
|
14712
|
+
input: extractInput(params),
|
|
14713
|
+
metadata: extractModelParameters(params, V3_EXCLUDE_KEYS)
|
|
14714
|
+
}
|
|
14715
|
+
});
|
|
14716
|
+
const userOnFinish = params.onFinish;
|
|
14717
|
+
const userOnError = params.onError;
|
|
14718
|
+
const userOnChunk = params.onChunk;
|
|
14719
|
+
try {
|
|
14720
|
+
const wrappedModel = wrapLanguageModel({
|
|
14721
|
+
model: params.model,
|
|
14722
|
+
middleware: BraintrustMiddleware()
|
|
14723
|
+
});
|
|
14724
|
+
const startTime = Date.now();
|
|
14725
|
+
let receivedFirst = false;
|
|
14726
|
+
const result = withCurrent(
|
|
14727
|
+
span,
|
|
14728
|
+
() => streamText({
|
|
14729
|
+
...params,
|
|
14730
|
+
tools: params.tools ? wrapTools(params.tools) : void 0,
|
|
14731
|
+
model: wrappedModel,
|
|
14732
|
+
onChunk: (chunk) => {
|
|
14733
|
+
if (!receivedFirst) {
|
|
14734
|
+
receivedFirst = true;
|
|
14735
|
+
span.log({
|
|
14736
|
+
metrics: {
|
|
14737
|
+
time_to_first_token: (Date.now() - startTime) / 1e3
|
|
14738
|
+
}
|
|
14739
|
+
});
|
|
14740
|
+
}
|
|
14741
|
+
if (typeof userOnChunk === "function") {
|
|
14742
|
+
userOnChunk(chunk);
|
|
14743
|
+
}
|
|
14744
|
+
},
|
|
14745
|
+
onFinish: async (event) => {
|
|
14746
|
+
if (typeof userOnFinish === "function") {
|
|
14747
|
+
await userOnFinish(event);
|
|
14748
|
+
}
|
|
14749
|
+
const provider = detectProviderFromResult(event);
|
|
14750
|
+
const model = extractModelFromResult(event);
|
|
14751
|
+
const finishReason = normalizeFinishReason(event?.finishReason);
|
|
14752
|
+
span.log({
|
|
14753
|
+
output: event?.text,
|
|
14754
|
+
metadata: {
|
|
14755
|
+
...extractModelParameters(params, V3_EXCLUDE_KEYS),
|
|
14756
|
+
...provider ? { provider } : {},
|
|
14757
|
+
...model ? { model } : {},
|
|
14758
|
+
...finishReason ? { finish_reason: finishReason } : {}
|
|
14759
|
+
}
|
|
14760
|
+
});
|
|
14761
|
+
span.end();
|
|
14762
|
+
},
|
|
14763
|
+
onError: async (err) => {
|
|
14764
|
+
if (typeof userOnError === "function") {
|
|
14765
|
+
await userOnError(err);
|
|
14766
|
+
}
|
|
14767
|
+
span.log({
|
|
14768
|
+
error: err instanceof Error ? err.message : String(err)
|
|
14769
|
+
});
|
|
14770
|
+
span.end();
|
|
14771
|
+
}
|
|
14772
|
+
})
|
|
14773
|
+
);
|
|
14774
|
+
return result;
|
|
14775
|
+
} catch (error2) {
|
|
14776
|
+
span.log({
|
|
14777
|
+
error: error2 instanceof Error ? error2.message : String(error2)
|
|
14778
|
+
});
|
|
14779
|
+
span.end();
|
|
14780
|
+
throw error2;
|
|
14781
|
+
}
|
|
14782
|
+
};
|
|
14783
|
+
const wrappedStreamObject = (params) => {
|
|
14784
|
+
const span = startSpan({
|
|
14785
|
+
name: "ai-sdk.streamObject",
|
|
14786
|
+
event: {
|
|
14787
|
+
input: extractInput(params),
|
|
14788
|
+
metadata: extractModelParameters(params, V3_EXCLUDE_KEYS)
|
|
14789
|
+
}
|
|
14790
|
+
});
|
|
14791
|
+
const userOnFinish = params.onFinish;
|
|
14792
|
+
const userOnError = params.onError;
|
|
14793
|
+
try {
|
|
14794
|
+
const wrappedModel = wrapLanguageModel({
|
|
14795
|
+
model: params.model,
|
|
14796
|
+
middleware: BraintrustMiddleware()
|
|
14797
|
+
});
|
|
14798
|
+
const startTime = Date.now();
|
|
14799
|
+
const result = withCurrent(
|
|
14800
|
+
span,
|
|
14801
|
+
() => streamObject({
|
|
14802
|
+
...params,
|
|
14803
|
+
tools: params.tools ? wrapTools(params.tools) : void 0,
|
|
14804
|
+
model: wrappedModel,
|
|
14805
|
+
onFinish: async (event) => {
|
|
14806
|
+
if (typeof userOnFinish === "function") {
|
|
14807
|
+
await userOnFinish(event);
|
|
14808
|
+
}
|
|
14809
|
+
const provider = detectProviderFromResult(event);
|
|
14810
|
+
const model = extractModelFromResult(event);
|
|
14811
|
+
const finishReason = normalizeFinishReason(event?.finishReason);
|
|
14812
|
+
span.log({
|
|
14813
|
+
output: event?.object,
|
|
14814
|
+
metadata: {
|
|
14815
|
+
...extractModelParameters(params, V3_EXCLUDE_KEYS),
|
|
14816
|
+
...provider ? { provider } : {},
|
|
14817
|
+
...model ? { model } : {},
|
|
14818
|
+
...finishReason ? { finish_reason: finishReason } : {}
|
|
14819
|
+
}
|
|
14820
|
+
});
|
|
14821
|
+
span.end();
|
|
14822
|
+
},
|
|
14823
|
+
onError: async (err) => {
|
|
14824
|
+
if (typeof userOnError === "function") {
|
|
14825
|
+
await userOnError(err);
|
|
14826
|
+
}
|
|
14827
|
+
span.log({
|
|
14828
|
+
error: err instanceof Error ? err.message : String(err)
|
|
14829
|
+
});
|
|
14830
|
+
span.end();
|
|
14831
|
+
}
|
|
14832
|
+
})
|
|
14833
|
+
);
|
|
14834
|
+
const wrapStream = wrapStreamObject(result.partialObjectStream, () => {
|
|
14835
|
+
span.log({
|
|
14836
|
+
metrics: { time_to_first_token: (Date.now() - startTime) / 1e3 }
|
|
14837
|
+
});
|
|
14838
|
+
});
|
|
14839
|
+
return {
|
|
14840
|
+
...result,
|
|
14841
|
+
partialObjectStream: wrapStream
|
|
14842
|
+
};
|
|
14843
|
+
} catch (error2) {
|
|
14844
|
+
span.log({
|
|
14845
|
+
error: error2 instanceof Error ? error2.message : String(error2)
|
|
14846
|
+
});
|
|
14847
|
+
span.end();
|
|
14848
|
+
throw error2;
|
|
14849
|
+
}
|
|
14850
|
+
};
|
|
14851
|
+
return {
|
|
14852
|
+
generateText: wrappedGenerateText,
|
|
14853
|
+
generateObject: wrappedGenerateObject,
|
|
14854
|
+
streamText: wrappedStreamText,
|
|
14855
|
+
streamObject: wrappedStreamObject
|
|
14856
|
+
};
|
|
14857
|
+
}
|
|
14858
|
+
|
|
14859
|
+
// src/wrappers/mastra.ts
|
|
14860
|
+
var aiSDKFormatWarning = false;
|
|
14861
|
+
function wrapMastraAgent(agent, options) {
|
|
14862
|
+
const prefix = options?.name ?? options?.span_name ?? agent.name ?? "Agent";
|
|
14863
|
+
if (!hasAllMethods(agent)) {
|
|
14864
|
+
return agent;
|
|
14865
|
+
}
|
|
14866
|
+
if (agent.tools) {
|
|
14867
|
+
agent.__setTools(wrapTools(agent.tools));
|
|
14868
|
+
}
|
|
14869
|
+
return new Proxy(agent, {
|
|
14870
|
+
get(target, prop, receiver) {
|
|
14871
|
+
const value = Reflect.get(target, prop, receiver);
|
|
14872
|
+
if (prop === "generateVNext" && typeof value === "function") {
|
|
14873
|
+
return wrapGenerateVNext(value, target, prefix);
|
|
14874
|
+
}
|
|
14875
|
+
if (prop === "streamVNext" && typeof value === "function") {
|
|
14876
|
+
return wrapStreamVNext(value, target, prefix);
|
|
14877
|
+
}
|
|
14878
|
+
if (typeof value === "function") {
|
|
14879
|
+
return value.bind(target);
|
|
14880
|
+
}
|
|
14881
|
+
return value;
|
|
14882
|
+
}
|
|
14883
|
+
});
|
|
14884
|
+
}
|
|
14885
|
+
function hasAllMethods(a) {
|
|
14886
|
+
return typeof a.generateVNext === "function" && typeof a.streamVNext === "function";
|
|
14887
|
+
}
|
|
14888
|
+
function wrapGenerateVNext(original, target, prefix) {
|
|
14889
|
+
return function(...args) {
|
|
14890
|
+
const input = args[0];
|
|
14891
|
+
return traced(
|
|
14892
|
+
async (span) => {
|
|
14893
|
+
const result = await original.apply(target, args);
|
|
14894
|
+
const provider = detectProviderFromResult(result);
|
|
14895
|
+
const model = extractModelFromResult(result);
|
|
14896
|
+
const finishReason = normalizeFinishReason(result?.finishReason);
|
|
14897
|
+
const metrics = result?.usage ? normalizeUsageMetrics(
|
|
14898
|
+
result.usage,
|
|
14899
|
+
provider,
|
|
14900
|
+
result.providerMetadata
|
|
14901
|
+
) : {};
|
|
14902
|
+
span.log({
|
|
14903
|
+
input,
|
|
14904
|
+
output: result,
|
|
14905
|
+
metadata: {
|
|
14906
|
+
agent_name: target.name ?? prefix,
|
|
14907
|
+
...provider ? { provider } : {},
|
|
14908
|
+
...model ? { model } : {},
|
|
14909
|
+
...finishReason ? { finish_reason: finishReason } : {}
|
|
14910
|
+
},
|
|
14911
|
+
metrics
|
|
14912
|
+
});
|
|
14913
|
+
return result;
|
|
14914
|
+
},
|
|
14915
|
+
{
|
|
14916
|
+
name: `${prefix}.generateVNext`
|
|
14917
|
+
}
|
|
14918
|
+
);
|
|
14919
|
+
};
|
|
14920
|
+
}
|
|
14921
|
+
function wrapStreamVNext(original, target, prefix) {
|
|
14922
|
+
return function(...args) {
|
|
14923
|
+
const input = args[0];
|
|
14924
|
+
const span = startSpan({
|
|
14925
|
+
name: `${prefix}.streamVNext`,
|
|
14926
|
+
event: {
|
|
14927
|
+
input,
|
|
14928
|
+
metadata: {
|
|
14929
|
+
agent_name: target.name ?? prefix
|
|
14930
|
+
}
|
|
14931
|
+
}
|
|
14932
|
+
});
|
|
14933
|
+
const baseOpts = typeof args[1] === "object" && args[1] !== null ? args[1] : {};
|
|
14934
|
+
if (baseOpts.format && baseOpts.format !== "aisdk" && !aiSDKFormatWarning) {
|
|
14935
|
+
aiSDKFormatWarning = true;
|
|
14936
|
+
console.warn(
|
|
14937
|
+
`Braintrust Mastra wrapper: For best compatibility, use { format: 'aisdk' } (AI SDK v5) instead of format: '${baseOpts.format}'. See https://mastra.ai/en/docs/frameworks/agentic-uis/ai-sdk for more details.`
|
|
14938
|
+
);
|
|
14939
|
+
}
|
|
14940
|
+
const wrappedOpts = {
|
|
14941
|
+
...baseOpts,
|
|
14942
|
+
format: baseOpts.format || "aisdk"
|
|
14943
|
+
// Default to AI SDK v5 format if not specified
|
|
14944
|
+
};
|
|
14945
|
+
const userOnChunk = baseOpts?.onChunk;
|
|
14946
|
+
const userOnFinish = baseOpts?.onFinish;
|
|
14947
|
+
const userOnError = baseOpts?.onError;
|
|
14948
|
+
const startTime = Date.now();
|
|
14949
|
+
let receivedFirst = false;
|
|
14950
|
+
wrappedOpts.onChunk = (chunk) => {
|
|
14951
|
+
try {
|
|
14952
|
+
userOnChunk?.(chunk);
|
|
14953
|
+
} finally {
|
|
14954
|
+
if (!receivedFirst) {
|
|
14955
|
+
receivedFirst = true;
|
|
14956
|
+
span.log({
|
|
14957
|
+
metrics: { time_to_first_token: (Date.now() - startTime) / 1e3 }
|
|
14958
|
+
});
|
|
14959
|
+
}
|
|
14960
|
+
}
|
|
14961
|
+
};
|
|
14962
|
+
wrappedOpts.onFinish = async (event) => {
|
|
14963
|
+
try {
|
|
14964
|
+
await userOnFinish?.(event);
|
|
14965
|
+
} finally {
|
|
14966
|
+
const e = event;
|
|
14967
|
+
const provider = detectProviderFromResult(e);
|
|
14968
|
+
const model = extractModelFromResult(e);
|
|
14969
|
+
const finishReason = normalizeFinishReason(e?.finishReason);
|
|
14970
|
+
const metrics = e?.usage ? normalizeUsageMetrics(e.usage, provider, e.providerMetadata) : {};
|
|
14971
|
+
span.log({
|
|
14972
|
+
output: e.text ?? e.content ?? e,
|
|
14973
|
+
metadata: {
|
|
14974
|
+
agent_name: target.name ?? prefix,
|
|
14975
|
+
...provider ? { provider } : {},
|
|
14976
|
+
...model ? { model } : {},
|
|
14977
|
+
...finishReason ? { finish_reason: finishReason } : {}
|
|
14978
|
+
},
|
|
14979
|
+
metrics
|
|
14980
|
+
});
|
|
14981
|
+
span.end();
|
|
14982
|
+
}
|
|
14983
|
+
};
|
|
14984
|
+
wrappedOpts.onError = async (err) => {
|
|
14985
|
+
try {
|
|
14986
|
+
await userOnError?.(err);
|
|
14987
|
+
} finally {
|
|
14988
|
+
logError(span, err);
|
|
14989
|
+
span.end();
|
|
14990
|
+
}
|
|
14991
|
+
};
|
|
14992
|
+
return withCurrent(
|
|
14993
|
+
span,
|
|
14994
|
+
() => original.apply(target, [args[0], wrappedOpts, ...args.slice(2)])
|
|
14995
|
+
);
|
|
14996
|
+
};
|
|
14997
|
+
}
|
|
14998
|
+
|
|
13444
14999
|
// src/wrappers/anthropic.ts
|
|
13445
|
-
import { SpanTypeAttribute as SpanTypeAttribute5 } from "@braintrust/core";
|
|
13446
15000
|
function wrapAnthropic(anthropic) {
|
|
13447
15001
|
const au = anthropic;
|
|
13448
15002
|
if (au && typeof au === "object" && "messages" in au && typeof au.messages === "object" && au.messages && "create" in au.messages) {
|
|
@@ -13500,7 +15054,7 @@ function createProxy(create) {
|
|
|
13500
15054
|
const spanArgs = {
|
|
13501
15055
|
name: "anthropic.messages.create",
|
|
13502
15056
|
spanAttributes: {
|
|
13503
|
-
type:
|
|
15057
|
+
type: "llm" /* LLM */
|
|
13504
15058
|
},
|
|
13505
15059
|
event: {
|
|
13506
15060
|
input,
|
|
@@ -13844,6 +15398,15 @@ var BraintrustSpanProcessor = class _BraintrustSpanProcessor {
|
|
|
13844
15398
|
if (!span.instrumentationScope && span.instrumentationLibrary) {
|
|
13845
15399
|
span.instrumentationScope = span.instrumentationLibrary;
|
|
13846
15400
|
}
|
|
15401
|
+
if (!span.parentSpanContext && span.parentSpanId) {
|
|
15402
|
+
const spanContext = span.spanContext?.();
|
|
15403
|
+
if (spanContext?.traceId) {
|
|
15404
|
+
span.parentSpanContext = {
|
|
15405
|
+
spanId: span.parentSpanId,
|
|
15406
|
+
traceId: spanContext.traceId
|
|
15407
|
+
};
|
|
15408
|
+
}
|
|
15409
|
+
}
|
|
13847
15410
|
return span;
|
|
13848
15411
|
});
|
|
13849
15412
|
return Reflect.apply(target.export, target, [
|
|
@@ -13934,44 +15497,44 @@ var BraintrustExporter = class _BraintrustExporter {
|
|
|
13934
15497
|
};
|
|
13935
15498
|
|
|
13936
15499
|
// dev/types.ts
|
|
13937
|
-
import { z as
|
|
13938
|
-
var evalBodySchema =
|
|
13939
|
-
name:
|
|
13940
|
-
parameters:
|
|
15500
|
+
import { z as z10 } from "zod/v3";
|
|
15501
|
+
var evalBodySchema = z10.object({
|
|
15502
|
+
name: z10.string(),
|
|
15503
|
+
parameters: z10.record(z10.string(), z10.unknown()).nullish(),
|
|
13941
15504
|
data: RunEval.shape.data,
|
|
13942
|
-
scores:
|
|
13943
|
-
|
|
15505
|
+
scores: z10.array(
|
|
15506
|
+
z10.object({
|
|
13944
15507
|
function_id: FunctionId,
|
|
13945
|
-
name:
|
|
15508
|
+
name: z10.string()
|
|
13946
15509
|
})
|
|
13947
15510
|
).nullish(),
|
|
13948
|
-
experiment_name:
|
|
13949
|
-
project_id:
|
|
15511
|
+
experiment_name: z10.string().nullish(),
|
|
15512
|
+
project_id: z10.string().nullish(),
|
|
13950
15513
|
parent: InvokeParent.optional(),
|
|
13951
|
-
stream:
|
|
15514
|
+
stream: z10.boolean().optional()
|
|
13952
15515
|
});
|
|
13953
|
-
var evalParametersSerializedSchema =
|
|
13954
|
-
|
|
13955
|
-
|
|
13956
|
-
|
|
13957
|
-
type:
|
|
15516
|
+
var evalParametersSerializedSchema = z10.record(
|
|
15517
|
+
z10.string(),
|
|
15518
|
+
z10.union([
|
|
15519
|
+
z10.object({
|
|
15520
|
+
type: z10.literal("prompt"),
|
|
13958
15521
|
default: PromptData.optional(),
|
|
13959
|
-
description:
|
|
15522
|
+
description: z10.string().optional()
|
|
13960
15523
|
}),
|
|
13961
|
-
|
|
13962
|
-
type:
|
|
13963
|
-
schema:
|
|
15524
|
+
z10.object({
|
|
15525
|
+
type: z10.literal("data"),
|
|
15526
|
+
schema: z10.record(z10.unknown()),
|
|
13964
15527
|
// JSON Schema
|
|
13965
|
-
default:
|
|
13966
|
-
description:
|
|
15528
|
+
default: z10.unknown().optional(),
|
|
15529
|
+
description: z10.string().optional()
|
|
13967
15530
|
})
|
|
13968
15531
|
])
|
|
13969
15532
|
);
|
|
13970
|
-
var evaluatorDefinitionSchema =
|
|
15533
|
+
var evaluatorDefinitionSchema = z10.object({
|
|
13971
15534
|
parameters: evalParametersSerializedSchema.optional()
|
|
13972
15535
|
});
|
|
13973
|
-
var evaluatorDefinitionsSchema =
|
|
13974
|
-
|
|
15536
|
+
var evaluatorDefinitionsSchema = z10.record(
|
|
15537
|
+
z10.string(),
|
|
13975
15538
|
evaluatorDefinitionSchema
|
|
13976
15539
|
);
|
|
13977
15540
|
|
|
@@ -14025,6 +15588,7 @@ export {
|
|
|
14025
15588
|
currentExperiment,
|
|
14026
15589
|
currentLogger,
|
|
14027
15590
|
currentSpan,
|
|
15591
|
+
deepCopyEvent,
|
|
14028
15592
|
index_default as default,
|
|
14029
15593
|
defaultErrorScoreHandler,
|
|
14030
15594
|
deserializePlainStringAsJSON,
|
|
@@ -14072,8 +15636,10 @@ export {
|
|
|
14072
15636
|
withExperiment,
|
|
14073
15637
|
withLogger,
|
|
14074
15638
|
withParent,
|
|
15639
|
+
wrapAISDK,
|
|
14075
15640
|
wrapAISDKModel,
|
|
14076
15641
|
wrapAnthropic,
|
|
15642
|
+
wrapMastraAgent,
|
|
14077
15643
|
wrapOpenAI,
|
|
14078
15644
|
wrapOpenAIv4,
|
|
14079
15645
|
wrapTraced
|