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