braintrust 0.3.8 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dev/dist/index.js CHANGED
@@ -303,6 +303,44 @@ var Queue = (_class = class {
303
303
  }
304
304
  }, _class);
305
305
 
306
+ // src/id-gen.ts
307
+
308
+ function generateHexId(bytes) {
309
+ let result = "";
310
+ for (let i = 0; i < bytes; i++) {
311
+ result += Math.floor(Math.random() * 256).toString(16).padStart(2, "0");
312
+ }
313
+ return result;
314
+ }
315
+ var IDGenerator = class {
316
+ };
317
+ var UUIDGenerator = class extends IDGenerator {
318
+ getSpanId() {
319
+ return _uuid.v4.call(void 0, );
320
+ }
321
+ getTraceId() {
322
+ return _uuid.v4.call(void 0, );
323
+ }
324
+ shareRootSpanId() {
325
+ return true;
326
+ }
327
+ };
328
+ var OTELIDGenerator = class extends IDGenerator {
329
+ getSpanId() {
330
+ return generateHexId(8);
331
+ }
332
+ getTraceId() {
333
+ return generateHexId(16);
334
+ }
335
+ shareRootSpanId() {
336
+ return false;
337
+ }
338
+ };
339
+ function getIdGenerator() {
340
+ const useOtel = typeof process !== "undefined" && _optionalChain([process, 'access', _11 => _11.env, 'optionalAccess', _12 => _12.BRAINTRUST_OTEL_COMPAT, 'optionalAccess', _13 => _13.toLowerCase, 'call', _14 => _14()]) === "true";
341
+ return useOtel ? new OTELIDGenerator() : new UUIDGenerator();
342
+ }
343
+
306
344
  // util/db_fields.ts
307
345
  var TRANSACTION_ID_FIELD = "_xact_id";
308
346
  var IS_MERGE_FIELD = "_is_merge";
@@ -453,7 +491,7 @@ var SpanComponentsV1 = class _SpanComponentsV1 {
453
491
  return {
454
492
  objectType: this.objectType,
455
493
  objectId: this.objectId,
456
- rowIds: _optionalChain([this, 'access', _11 => _11.rowIds, 'optionalAccess', _12 => _12.toObject, 'call', _13 => _13()])
494
+ rowIds: _optionalChain([this, 'access', _15 => _15.rowIds, 'optionalAccess', _16 => _16.toObject, 'call', _17 => _17()])
457
495
  };
458
496
  }
459
497
  };
@@ -667,7 +705,7 @@ var SpanComponentsV2 = class _SpanComponentsV2 {
667
705
  objectType: this.objectType,
668
706
  objectId: this.objectId,
669
707
  computeObjectMetadataArgs: this.computeObjectMetadataArgs,
670
- rowIds: _optionalChain([this, 'access', _14 => _14.rowIds, 'optionalAccess', _15 => _15.toObject, 'call', _16 => _16()])
708
+ rowIds: _optionalChain([this, 'access', _18 => _18.rowIds, 'optionalAccess', _19 => _19.toObject, 'call', _20 => _20()])
671
709
  };
672
710
  }
673
711
  };
@@ -908,22 +946,6 @@ var SpanComponentsV3 = class _SpanComponentsV3 {
908
946
  return new _SpanComponentsV3(spanComponentsV3Schema.parse(jsonObj));
909
947
  }
910
948
  };
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
949
 
928
950
  // util/http_headers.ts
929
951
  var BT_FOUND_EXISTING_HEADER = "x-bt-found-existing";
@@ -1019,14 +1041,14 @@ function depthFirstSearch(args) {
1019
1041
  while (events.length) {
1020
1042
  const { eventType, vertex, extras } = events.pop();
1021
1043
  if (eventType === "last") {
1022
- _optionalChain([lastVisitF, 'optionalCall', _17 => _17(vertex)]);
1044
+ _optionalChain([lastVisitF, 'optionalCall', _21 => _21(vertex)]);
1023
1045
  continue;
1024
1046
  }
1025
1047
  if (firstVisitedVertices.has(vertex)) {
1026
1048
  continue;
1027
1049
  }
1028
1050
  firstVisitedVertices.add(vertex);
1029
- _optionalChain([firstVisitF, 'optionalCall', _18 => _18(vertex, { parentVertex: extras.parentVertex })]);
1051
+ _optionalChain([firstVisitF, 'optionalCall', _22 => _22(vertex, { parentVertex: extras.parentVertex })]);
1030
1052
  events.push({ eventType: "last", vertex, extras: {} });
1031
1053
  mapAt(graph, vertex).forEach((child) => {
1032
1054
  events.push({
@@ -1048,7 +1070,7 @@ function undirectedConnectedComponents(graph) {
1048
1070
  let labelCounter = 0;
1049
1071
  const vertexLabels = /* @__PURE__ */ new Map();
1050
1072
  const firstVisitF = (vertex, args) => {
1051
- const label = _optionalChain([args, 'optionalAccess', _19 => _19.parentVertex]) !== void 0 ? mapAt(vertexLabels, _optionalChain([args, 'optionalAccess', _20 => _20.parentVertex])) : labelCounter++;
1073
+ const label = _optionalChain([args, 'optionalAccess', _23 => _23.parentVertex]) !== void 0 ? mapAt(vertexLabels, _optionalChain([args, 'optionalAccess', _24 => _24.parentVertex])) : labelCounter++;
1052
1074
  vertexLabels.set(vertex, label);
1053
1075
  };
1054
1076
  depthFirstSearch({ graph: directedGraph, firstVisitF });
@@ -1270,6 +1292,232 @@ function _urljoin(...parts) {
1270
1292
  ).filter((x) => x.trim() !== "").join("/");
1271
1293
  }
1272
1294
 
1295
+ // util/span_identifier_v4.ts
1296
+
1297
+ var ENCODING_VERSION_NUMBER_V4 = 4;
1298
+ function tryMakeHexTraceId(s) {
1299
+ try {
1300
+ if (typeof s === "string" && s.length === 32) {
1301
+ const bytes = new Uint8Array(16);
1302
+ for (let i = 0; i < 16; i++) {
1303
+ const hex = s.substr(i * 2, 2);
1304
+ const byte = parseInt(hex, 16);
1305
+ if (isNaN(byte)) throw new Error();
1306
+ bytes[i] = byte;
1307
+ }
1308
+ return { bytes, isHex: true };
1309
+ }
1310
+ } catch (e5) {
1311
+ }
1312
+ return { bytes: void 0, isHex: false };
1313
+ }
1314
+ function tryMakeHexSpanId(s) {
1315
+ try {
1316
+ if (typeof s === "string" && s.length === 16) {
1317
+ const bytes = new Uint8Array(8);
1318
+ for (let i = 0; i < 8; i++) {
1319
+ const hex = s.substr(i * 2, 2);
1320
+ const byte = parseInt(hex, 16);
1321
+ if (isNaN(byte)) throw new Error();
1322
+ bytes[i] = byte;
1323
+ }
1324
+ return { bytes, isHex: true };
1325
+ }
1326
+ } catch (e6) {
1327
+ }
1328
+ return { bytes: void 0, isHex: false };
1329
+ }
1330
+ var INVALID_ENCODING_ERRMSG_V4 = `SpanComponents string is not properly encoded. This library only supports encoding versions up to ${ENCODING_VERSION_NUMBER_V4}. Please make sure the SDK library used to decode the SpanComponents is at least as new as any library used to encode it.`;
1331
+ var FIELDS_ID_TO_NAME = {
1332
+ [1 /* OBJECT_ID */]: "object_id",
1333
+ [2 /* ROW_ID */]: "row_id",
1334
+ [3 /* SPAN_ID */]: "span_id",
1335
+ [4 /* ROOT_SPAN_ID */]: "root_span_id"
1336
+ };
1337
+ var spanComponentsV4Schema = _v3.z.object({
1338
+ object_type: spanObjectTypeV3EnumSchema,
1339
+ propagated_event: _v3.z.record(_v3.z.unknown()).nullish()
1340
+ }).and(
1341
+ _v3.z.union([
1342
+ // Must provide one or the other.
1343
+ _v3.z.object({
1344
+ object_id: _v3.z.string().nullish(),
1345
+ compute_object_metadata_args: _v3.z.optional(_v3.z.null())
1346
+ }),
1347
+ _v3.z.object({
1348
+ object_id: _v3.z.optional(_v3.z.null()),
1349
+ compute_object_metadata_args: _v3.z.record(_v3.z.unknown())
1350
+ })
1351
+ ])
1352
+ ).and(
1353
+ _v3.z.union([
1354
+ // Either all of these must be provided or none.
1355
+ _v3.z.object({
1356
+ row_id: _v3.z.string(),
1357
+ span_id: _v3.z.string(),
1358
+ root_span_id: _v3.z.string()
1359
+ }),
1360
+ _v3.z.object({
1361
+ row_id: _v3.z.optional(_v3.z.null()),
1362
+ span_id: _v3.z.optional(_v3.z.null()),
1363
+ root_span_id: _v3.z.optional(_v3.z.null())
1364
+ })
1365
+ ])
1366
+ );
1367
+ var SpanComponentsV4 = class _SpanComponentsV4 {
1368
+ constructor(data) {
1369
+ this.data = data;
1370
+ }
1371
+ toStr() {
1372
+ const jsonObj = {
1373
+ compute_object_metadata_args: this.data.compute_object_metadata_args || void 0,
1374
+ propagated_event: this.data.propagated_event || void 0
1375
+ };
1376
+ Object.keys(jsonObj).forEach((key) => {
1377
+ if (jsonObj[key] === void 0) {
1378
+ delete jsonObj[key];
1379
+ }
1380
+ });
1381
+ const allBuffers = [];
1382
+ allBuffers.push(
1383
+ new Uint8Array([ENCODING_VERSION_NUMBER_V4, this.data.object_type])
1384
+ );
1385
+ const hexEntries = [];
1386
+ function addHexField(origVal, fieldId) {
1387
+ let hexResult;
1388
+ if (fieldId === 3 /* SPAN_ID */) {
1389
+ hexResult = tryMakeHexSpanId(origVal);
1390
+ } else if (fieldId === 4 /* ROOT_SPAN_ID */) {
1391
+ hexResult = tryMakeHexTraceId(origVal);
1392
+ } else {
1393
+ hexResult = { bytes: void 0, isHex: false };
1394
+ }
1395
+ if (hexResult.isHex) {
1396
+ hexEntries.push(
1397
+ concatUint8Arrays(new Uint8Array([fieldId]), hexResult.bytes)
1398
+ );
1399
+ } else {
1400
+ jsonObj[FIELDS_ID_TO_NAME[fieldId]] = origVal;
1401
+ }
1402
+ }
1403
+ if (this.data.object_id) {
1404
+ addHexField(this.data.object_id, 1 /* OBJECT_ID */);
1405
+ }
1406
+ if (this.data.row_id) {
1407
+ addHexField(this.data.row_id, 2 /* ROW_ID */);
1408
+ }
1409
+ if (this.data.span_id) {
1410
+ addHexField(this.data.span_id, 3 /* SPAN_ID */);
1411
+ }
1412
+ if (this.data.root_span_id) {
1413
+ addHexField(this.data.root_span_id, 4 /* ROOT_SPAN_ID */);
1414
+ }
1415
+ if (hexEntries.length > 255) {
1416
+ throw new Error("Impossible: too many hex entries to encode");
1417
+ }
1418
+ allBuffers.push(new Uint8Array([hexEntries.length]));
1419
+ allBuffers.push(...hexEntries);
1420
+ if (Object.keys(jsonObj).length > 0) {
1421
+ allBuffers.push(stringToUint8Array(JSON.stringify(jsonObj)));
1422
+ }
1423
+ return uint8ArrayToBase64(concatUint8Arrays(...allBuffers));
1424
+ }
1425
+ static fromStr(s) {
1426
+ try {
1427
+ const rawBytes = base64ToUint8Array(s);
1428
+ const jsonObj = {};
1429
+ if (rawBytes[0] < ENCODING_VERSION_NUMBER_V4) {
1430
+ const v3Components = SpanComponentsV3.fromStr(s);
1431
+ jsonObj["object_type"] = v3Components.data.object_type;
1432
+ jsonObj["object_id"] = v3Components.data.object_id;
1433
+ jsonObj["compute_object_metadata_args"] = v3Components.data.compute_object_metadata_args;
1434
+ jsonObj["row_id"] = v3Components.data.row_id;
1435
+ jsonObj["span_id"] = v3Components.data.span_id;
1436
+ jsonObj["root_span_id"] = v3Components.data.root_span_id;
1437
+ jsonObj["propagated_event"] = v3Components.data.propagated_event;
1438
+ } else {
1439
+ jsonObj["object_type"] = rawBytes[1];
1440
+ const numHexEntries = rawBytes[2];
1441
+ let byteOffset = 3;
1442
+ for (let i = 0; i < numHexEntries; i++) {
1443
+ const fieldId = rawBytes[byteOffset];
1444
+ if (fieldId === 3 /* SPAN_ID */) {
1445
+ const hexBytes = rawBytes.subarray(byteOffset + 1, byteOffset + 9);
1446
+ byteOffset += 9;
1447
+ jsonObj[FIELDS_ID_TO_NAME[fieldId]] = Array.from(
1448
+ hexBytes,
1449
+ (b) => b.toString(16).padStart(2, "0")
1450
+ ).join("");
1451
+ } else if (fieldId === 4 /* ROOT_SPAN_ID */) {
1452
+ const hexBytes = rawBytes.subarray(byteOffset + 1, byteOffset + 17);
1453
+ byteOffset += 17;
1454
+ jsonObj[FIELDS_ID_TO_NAME[fieldId]] = Array.from(
1455
+ hexBytes,
1456
+ (b) => b.toString(16).padStart(2, "0")
1457
+ ).join("");
1458
+ } else {
1459
+ const hexBytes = rawBytes.subarray(byteOffset + 1, byteOffset + 17);
1460
+ byteOffset += 17;
1461
+ jsonObj[FIELDS_ID_TO_NAME[fieldId]] = Array.from(
1462
+ hexBytes,
1463
+ (b) => b.toString(16).padStart(2, "0")
1464
+ ).join("");
1465
+ }
1466
+ }
1467
+ if (byteOffset < rawBytes.length) {
1468
+ const remainingJsonObj = JSON.parse(
1469
+ uint8ArrayToString(rawBytes.subarray(byteOffset))
1470
+ );
1471
+ Object.assign(jsonObj, remainingJsonObj);
1472
+ }
1473
+ }
1474
+ return _SpanComponentsV4.fromJsonObj(jsonObj);
1475
+ } catch (e7) {
1476
+ throw new Error(INVALID_ENCODING_ERRMSG_V4);
1477
+ }
1478
+ }
1479
+ objectIdFields() {
1480
+ if (!this.data.object_id) {
1481
+ throw new Error(
1482
+ "Impossible: cannot invoke `objectIdFields` unless SpanComponentsV4 is initialized with an `object_id`"
1483
+ );
1484
+ }
1485
+ switch (this.data.object_type) {
1486
+ case 1 /* EXPERIMENT */:
1487
+ return { experiment_id: this.data.object_id };
1488
+ case 2 /* PROJECT_LOGS */:
1489
+ return { project_id: this.data.object_id, log_id: "g" };
1490
+ case 3 /* PLAYGROUND_LOGS */:
1491
+ return { prompt_session_id: this.data.object_id, log_id: "x" };
1492
+ default:
1493
+ const _ = this.data.object_type;
1494
+ throw new Error(`Invalid object_type ${this.data.object_type}`);
1495
+ }
1496
+ }
1497
+ async export() {
1498
+ return this.toStr();
1499
+ }
1500
+ static fromJsonObj(jsonObj) {
1501
+ return new _SpanComponentsV4(spanComponentsV4Schema.parse(jsonObj));
1502
+ }
1503
+ };
1504
+ function parseParent(parent) {
1505
+ return typeof parent === "string" ? parent : parent ? new SpanComponentsV4({
1506
+ object_type: parent.object_type === "experiment" ? 1 /* EXPERIMENT */ : parent.object_type === "playground_logs" ? 3 /* PLAYGROUND_LOGS */ : 2 /* PROJECT_LOGS */,
1507
+ object_id: parent.object_id,
1508
+ ...parent.row_ids ? {
1509
+ row_id: parent.row_ids.id,
1510
+ span_id: parent.row_ids.span_id,
1511
+ root_span_id: parent.row_ids.root_span_id
1512
+ } : {
1513
+ row_id: void 0,
1514
+ span_id: void 0,
1515
+ root_span_id: void 0
1516
+ },
1517
+ propagated_event: parent.propagated_event
1518
+ }).toStr() : void 0;
1519
+ }
1520
+
1273
1521
  // util/git_fields.ts
1274
1522
  function mergeGitMetadataSettings(s1, s2) {
1275
1523
  if (s1.collect === "all") {
@@ -3202,7 +3450,7 @@ function getMustacheVars(prompt) {
3202
3450
  return _mustache2.default.parse(prompt).filter(
3203
3451
  (span) => span[0] === "name" || span[0] === "&"
3204
3452
  );
3205
- } catch (e5) {
3453
+ } catch (e8) {
3206
3454
  return [];
3207
3455
  }
3208
3456
  }
@@ -3268,7 +3516,7 @@ var NoopSpan = (_class4 = class {
3268
3516
  return this;
3269
3517
  }
3270
3518
  end(args) {
3271
- return _nullishCoalesce(_optionalChain([args, 'optionalAccess', _21 => _21.endTime]), () => ( getCurrentUnixTimestamp()));
3519
+ return _nullishCoalesce(_optionalChain([args, 'optionalAccess', _25 => _25.endTime]), () => ( getCurrentUnixTimestamp()));
3272
3520
  }
3273
3521
  async export() {
3274
3522
  return "";
@@ -3321,7 +3569,7 @@ var loginSchema = _zod.z.strictObject({
3321
3569
  });
3322
3570
  var stateNonce = 0;
3323
3571
  var BraintrustState = (_class5 = class _BraintrustState {
3324
- constructor(loginParams) {;_class5.prototype.__init7.call(this);_class5.prototype.__init8.call(this);_class5.prototype.__init9.call(this);_class5.prototype.__init10.call(this);_class5.prototype.__init11.call(this);_class5.prototype.__init12.call(this);_class5.prototype.__init13.call(this);_class5.prototype.__init14.call(this);_class5.prototype.__init15.call(this);_class5.prototype.__init16.call(this);_class5.prototype.__init17.call(this);_class5.prototype.__init18.call(this);_class5.prototype.__init19.call(this);
3572
+ constructor(loginParams) {;_class5.prototype.__init7.call(this);_class5.prototype.__init8.call(this);_class5.prototype.__init9.call(this);_class5.prototype.__init10.call(this);_class5.prototype.__init11.call(this);_class5.prototype.__init12.call(this);_class5.prototype.__init13.call(this);_class5.prototype.__init14.call(this);_class5.prototype.__init15.call(this);_class5.prototype.__init16.call(this);_class5.prototype.__init17.call(this);_class5.prototype.__init18.call(this);_class5.prototype.__init19.call(this);_class5.prototype.__init20.call(this);
3325
3573
  this.loginParams = loginParams;
3326
3574
  this.id = `${(/* @__PURE__ */ new Date()).toLocaleString()}-${stateNonce++}`;
3327
3575
  this.currentExperiment = void 0;
@@ -3375,6 +3623,7 @@ var BraintrustState = (_class5 = class _BraintrustState {
3375
3623
  __init18() {this._apiConn = null}
3376
3624
  __init19() {this._proxyConn = null}
3377
3625
 
3626
+ __init20() {this._idGenerator = null}
3378
3627
  resetLoginInfo() {
3379
3628
  this.appUrl = null;
3380
3629
  this.appPublicUrl = null;
@@ -3389,6 +3638,15 @@ var BraintrustState = (_class5 = class _BraintrustState {
3389
3638
  this._apiConn = null;
3390
3639
  this._proxyConn = null;
3391
3640
  }
3641
+ resetIdGenState() {
3642
+ this._idGenerator = null;
3643
+ }
3644
+ get idGenerator() {
3645
+ if (this._idGenerator === null) {
3646
+ this._idGenerator = getIdGenerator();
3647
+ }
3648
+ return this._idGenerator;
3649
+ }
3392
3650
  copyLoginInfo(other) {
3393
3651
  this.appUrl = other.appUrl;
3394
3652
  this.appPublicUrl = other.appPublicUrl;
@@ -3456,8 +3714,8 @@ var BraintrustState = (_class5 = class _BraintrustState {
3456
3714
  setFetch(fetch2) {
3457
3715
  this.loginParams.fetch = fetch2;
3458
3716
  this.fetch = fetch2;
3459
- _optionalChain([this, 'access', _22 => _22._apiConn, 'optionalAccess', _23 => _23.setFetch, 'call', _24 => _24(fetch2)]);
3460
- _optionalChain([this, 'access', _25 => _25._appConn, 'optionalAccess', _26 => _26.setFetch, 'call', _27 => _27(fetch2)]);
3717
+ _optionalChain([this, 'access', _26 => _26._apiConn, 'optionalAccess', _27 => _27.setFetch, 'call', _28 => _28(fetch2)]);
3718
+ _optionalChain([this, 'access', _29 => _29._appConn, 'optionalAccess', _30 => _30.setFetch, 'call', _31 => _31(fetch2)]);
3461
3719
  }
3462
3720
  setMaskingFunction(maskingFunction) {
3463
3721
  this.bgLogger().setMaskingFunction(maskingFunction);
@@ -4131,9 +4389,9 @@ async function permalink(slug, opts) {
4131
4389
  if (slug === "") {
4132
4390
  return NOOP_SPAN_PERMALINK;
4133
4391
  }
4134
- const state = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _28 => _28.state]), () => ( _globalState));
4392
+ const state = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _32 => _32.state]), () => ( _globalState));
4135
4393
  const getOrgName = async () => {
4136
- if (_optionalChain([opts, 'optionalAccess', _29 => _29.orgName])) {
4394
+ if (_optionalChain([opts, 'optionalAccess', _33 => _33.orgName])) {
4137
4395
  return opts.orgName;
4138
4396
  }
4139
4397
  await state.login({});
@@ -4143,7 +4401,7 @@ async function permalink(slug, opts) {
4143
4401
  return state.orgName;
4144
4402
  };
4145
4403
  const getAppUrl = async () => {
4146
- if (_optionalChain([opts, 'optionalAccess', _30 => _30.appUrl])) {
4404
+ if (_optionalChain([opts, 'optionalAccess', _34 => _34.appUrl])) {
4147
4405
  return opts.appUrl;
4148
4406
  }
4149
4407
  await state.login({});
@@ -4230,8 +4488,8 @@ var Logger = (_class6 = class {
4230
4488
 
4231
4489
 
4232
4490
  // For type identification.
4233
- __init20() {this.kind = "logger"}
4234
- constructor(state, lazyMetadata, logOptions = {}) {;_class6.prototype.__init20.call(this);
4491
+ __init21() {this.kind = "logger"}
4492
+ constructor(state, lazyMetadata, logOptions = {}) {;_class6.prototype.__init21.call(this);
4235
4493
  this.lazyMetadata = lazyMetadata;
4236
4494
  this._asyncFlush = logOptions.asyncFlush;
4237
4495
  this.computeMetadataArgs = logOptions.computeMetadataArgs;
@@ -4273,7 +4531,7 @@ var Logger = (_class6 = class {
4273
4531
  * @returns The `id` of the logged event.
4274
4532
  */
4275
4533
  log(event, options) {
4276
- if (this.calledStartSpan && !_optionalChain([options, 'optionalAccess', _31 => _31.allowConcurrentWithSpans])) {
4534
+ if (this.calledStartSpan && !_optionalChain([options, 'optionalAccess', _35 => _35.allowConcurrentWithSpans])) {
4277
4535
  throw new Error(
4278
4536
  "Cannot run toplevel `log` method while using spans. To log to the span, call `logger.traced` and then log with `span.log`"
4279
4537
  );
@@ -4341,12 +4599,12 @@ var Logger = (_class6 = class {
4341
4599
  state: this.state,
4342
4600
  ...startSpanParentArgs({
4343
4601
  state: this.state,
4344
- parent: _optionalChain([args, 'optionalAccess', _32 => _32.parent]),
4602
+ parent: _optionalChain([args, 'optionalAccess', _36 => _36.parent]),
4345
4603
  parentObjectType: this.parentObjectType(),
4346
4604
  parentObjectId: this.lazyId,
4347
4605
  parentComputeObjectMetadataArgs: this.computeMetadataArgs,
4348
- parentSpanIds: _optionalChain([args, 'optionalAccess', _33 => _33.parentSpanIds]),
4349
- propagatedEvent: _optionalChain([args, 'optionalAccess', _34 => _34.propagatedEvent])
4606
+ parentSpanIds: _optionalChain([args, 'optionalAccess', _37 => _37.parentSpanIds]),
4607
+ propagatedEvent: _optionalChain([args, 'optionalAccess', _38 => _38.propagatedEvent])
4350
4608
  }),
4351
4609
  defaultRootType: "task" /* TASK */
4352
4610
  });
@@ -4424,26 +4682,26 @@ var BACKGROUND_LOGGER_BASE_SLEEP_TIME_S = 1;
4424
4682
  var HTTPBackgroundLogger = (_class7 = class _HTTPBackgroundLogger {
4425
4683
 
4426
4684
 
4427
- __init21() {this.activeFlush = Promise.resolve()}
4428
- __init22() {this.activeFlushResolved = true}
4429
- __init23() {this.activeFlushError = void 0}
4685
+ __init22() {this.activeFlush = Promise.resolve()}
4686
+ __init23() {this.activeFlushResolved = true}
4687
+ __init24() {this.activeFlushError = void 0}
4430
4688
 
4431
- __init24() {this.maskingFunction = null}
4432
- __init25() {this.syncFlush = false}
4689
+ __init25() {this.maskingFunction = null}
4690
+ __init26() {this.syncFlush = false}
4433
4691
  // 6 MB for the AWS lambda gateway (from our own testing).
4434
- __init26() {this.maxRequestSize = 6 * 1024 * 1024}
4435
- __init27() {this.defaultBatchSize = 100}
4436
- __init28() {this.numTries = 3}
4437
- __init29() {this.queueDropExceedingMaxsize = DEFAULT_QUEUE_SIZE}
4438
- __init30() {this.queueDropLoggingPeriod = 60}
4439
- __init31() {this.failedPublishPayloadsDir = void 0}
4440
- __init32() {this.allPublishPayloadsDir = void 0}
4441
- __init33() {this._disabled = false}
4442
- __init34() {this.queueDropLoggingState = {
4692
+ __init27() {this.maxRequestSize = 6 * 1024 * 1024}
4693
+ __init28() {this.defaultBatchSize = 100}
4694
+ __init29() {this.numTries = 3}
4695
+ __init30() {this.queueDropExceedingMaxsize = DEFAULT_QUEUE_SIZE}
4696
+ __init31() {this.queueDropLoggingPeriod = 60}
4697
+ __init32() {this.failedPublishPayloadsDir = void 0}
4698
+ __init33() {this.allPublishPayloadsDir = void 0}
4699
+ __init34() {this._disabled = false}
4700
+ __init35() {this.queueDropLoggingState = {
4443
4701
  numDropped: 0,
4444
4702
  lastLoggedTimestamp: 0
4445
4703
  }}
4446
- constructor(apiConn, opts) {;_class7.prototype.__init21.call(this);_class7.prototype.__init22.call(this);_class7.prototype.__init23.call(this);_class7.prototype.__init24.call(this);_class7.prototype.__init25.call(this);_class7.prototype.__init26.call(this);_class7.prototype.__init27.call(this);_class7.prototype.__init28.call(this);_class7.prototype.__init29.call(this);_class7.prototype.__init30.call(this);_class7.prototype.__init31.call(this);_class7.prototype.__init32.call(this);_class7.prototype.__init33.call(this);_class7.prototype.__init34.call(this);
4704
+ constructor(apiConn, opts) {;_class7.prototype.__init22.call(this);_class7.prototype.__init23.call(this);_class7.prototype.__init24.call(this);_class7.prototype.__init25.call(this);_class7.prototype.__init26.call(this);_class7.prototype.__init27.call(this);_class7.prototype.__init28.call(this);_class7.prototype.__init29.call(this);_class7.prototype.__init30.call(this);_class7.prototype.__init31.call(this);_class7.prototype.__init32.call(this);_class7.prototype.__init33.call(this);_class7.prototype.__init34.call(this);_class7.prototype.__init35.call(this);
4447
4705
  opts = _nullishCoalesce(opts, () => ( {}));
4448
4706
  this.apiConn = apiConn;
4449
4707
  const syncFlushEnv = Number(isomorph_default.getEnv("BRAINTRUST_SYNC_FLUSH"));
@@ -4532,7 +4790,7 @@ var HTTPBackgroundLogger = (_class7 = class _HTTPBackgroundLogger {
4532
4790
  this.queue.clear();
4533
4791
  return;
4534
4792
  }
4535
- const batchSize = _nullishCoalesce(_optionalChain([args, 'optionalAccess', _35 => _35.batchSize]), () => ( this.defaultBatchSize));
4793
+ const batchSize = _nullishCoalesce(_optionalChain([args, 'optionalAccess', _39 => _39.batchSize]), () => ( this.defaultBatchSize));
4536
4794
  const wrappedItems = this.queue.drain();
4537
4795
  const [allItems, attachments] = await this.unwrapLazyValues(wrappedItems);
4538
4796
  if (allItems.length === 0) {
@@ -4781,10 +5039,10 @@ Error: ${errorText}`;
4781
5039
  } catch (err) {
4782
5040
  if (err instanceof AggregateError) {
4783
5041
  for (const e of err.errors) {
4784
- _optionalChain([this, 'access', _36 => _36.onFlushError, 'optionalCall', _37 => _37(e)]);
5042
+ _optionalChain([this, 'access', _40 => _40.onFlushError, 'optionalCall', _41 => _41(e)]);
4785
5043
  }
4786
5044
  } else {
4787
- _optionalChain([this, 'access', _38 => _38.onFlushError, 'optionalCall', _39 => _39(err)]);
5045
+ _optionalChain([this, 'access', _42 => _42.onFlushError, 'optionalCall', _43 => _43(err)]);
4788
5046
  }
4789
5047
  this.activeFlushError = err;
4790
5048
  } finally {
@@ -5179,24 +5437,24 @@ async function loginToState(options = {}) {
5179
5437
  return state;
5180
5438
  }
5181
5439
  function currentExperiment(options) {
5182
- const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _40 => _40.state]), () => ( _globalState));
5440
+ const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _44 => _44.state]), () => ( _globalState));
5183
5441
  return state.currentExperiment;
5184
5442
  }
5185
5443
  function currentLogger(options) {
5186
- const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _41 => _41.state]), () => ( _globalState));
5187
- return castLogger(state.currentLogger, _optionalChain([options, 'optionalAccess', _42 => _42.asyncFlush]));
5444
+ const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _45 => _45.state]), () => ( _globalState));
5445
+ return castLogger(state.currentLogger, _optionalChain([options, 'optionalAccess', _46 => _46.asyncFlush]));
5188
5446
  }
5189
5447
  function currentSpan(options) {
5190
- const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _43 => _43.state]), () => ( _globalState));
5448
+ const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _47 => _47.state]), () => ( _globalState));
5191
5449
  return _nullishCoalesce(state.currentSpan.getStore(), () => ( NOOP_SPAN));
5192
5450
  }
5193
5451
  function getSpanParentObject(options) {
5194
- const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _44 => _44.state]), () => ( _globalState));
5452
+ const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _48 => _48.state]), () => ( _globalState));
5195
5453
  const parentSpan = currentSpan({ state });
5196
5454
  if (!Object.is(parentSpan, NOOP_SPAN)) {
5197
5455
  return parentSpan;
5198
5456
  }
5199
- const parentStr = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _45 => _45.parent]), () => ( state.currentParent.getStore()));
5457
+ const parentStr = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _49 => _49.parent]), () => ( state.currentParent.getStore()));
5200
5458
  if (parentStr) return SpanComponentsV3.fromStr(parentStr);
5201
5459
  const experiment = currentExperiment();
5202
5460
  if (experiment) {
@@ -5225,7 +5483,7 @@ function traced(callback, args) {
5225
5483
  const { span, isSyncFlushLogger } = startSpanAndIsLogger(args);
5226
5484
  const ret = runCatchFinally(
5227
5485
  () => {
5228
- if (_nullishCoalesce(_optionalChain([args, 'optionalAccess', _46 => _46.setCurrent]), () => ( true))) {
5486
+ if (_nullishCoalesce(_optionalChain([args, 'optionalAccess', _50 => _50.setCurrent]), () => ( true))) {
5229
5487
  return withCurrent(span, callback);
5230
5488
  } else {
5231
5489
  return callback(span);
@@ -5237,7 +5495,7 @@ function traced(callback, args) {
5237
5495
  },
5238
5496
  () => span.end()
5239
5497
  );
5240
- if (_optionalChain([args, 'optionalAccess', _47 => _47.asyncFlush]) === void 0 || _optionalChain([args, 'optionalAccess', _48 => _48.asyncFlush])) {
5498
+ if (_optionalChain([args, 'optionalAccess', _51 => _51.asyncFlush]) === void 0 || _optionalChain([args, 'optionalAccess', _52 => _52.asyncFlush])) {
5241
5499
  return ret;
5242
5500
  } else {
5243
5501
  return (async () => {
@@ -5253,14 +5511,14 @@ function startSpan(args) {
5253
5511
  return startSpanAndIsLogger(args).span;
5254
5512
  }
5255
5513
  async function flush(options) {
5256
- const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _49 => _49.state]), () => ( _globalState));
5514
+ const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _53 => _53.state]), () => ( _globalState));
5257
5515
  return await state.bgLogger().flush();
5258
5516
  }
5259
5517
  function startSpanAndIsLogger(args) {
5260
- const state = _nullishCoalesce(_optionalChain([args, 'optionalAccess', _50 => _50.state]), () => ( _globalState));
5518
+ const state = _nullishCoalesce(_optionalChain([args, 'optionalAccess', _54 => _54.state]), () => ( _globalState));
5261
5519
  const parentObject = getSpanParentObject({
5262
- asyncFlush: _optionalChain([args, 'optionalAccess', _51 => _51.asyncFlush]),
5263
- parent: _optionalChain([args, 'optionalAccess', _52 => _52.parent]),
5520
+ asyncFlush: _optionalChain([args, 'optionalAccess', _55 => _55.asyncFlush]),
5521
+ parent: _optionalChain([args, 'optionalAccess', _56 => _56.parent]),
5264
5522
  state
5265
5523
  });
5266
5524
  if (parentObject instanceof SpanComponentsV3) {
@@ -5277,14 +5535,14 @@ function startSpanAndIsLogger(args) {
5277
5535
  ),
5278
5536
  parentComputeObjectMetadataArgs: _nullishCoalesce(parentObject.data.compute_object_metadata_args, () => ( void 0)),
5279
5537
  parentSpanIds,
5280
- propagatedEvent: _nullishCoalesce(_optionalChain([args, 'optionalAccess', _53 => _53.propagatedEvent]), () => ( // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
5538
+ propagatedEvent: _nullishCoalesce(_optionalChain([args, 'optionalAccess', _57 => _57.propagatedEvent]), () => ( // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
5281
5539
  (_nullishCoalesce(parentObject.data.propagated_event, () => ( void 0)))))
5282
5540
  });
5283
5541
  return {
5284
5542
  span,
5285
5543
  isSyncFlushLogger: parentObject.data.object_type === 2 /* PROJECT_LOGS */ && // Since there's no parent logger here, we're free to choose the async flush
5286
5544
  // behavior, and therefore propagate along whatever we get from the arguments
5287
- _optionalChain([args, 'optionalAccess', _54 => _54.asyncFlush]) === false
5545
+ _optionalChain([args, 'optionalAccess', _58 => _58.asyncFlush]) === false
5288
5546
  };
5289
5547
  } else {
5290
5548
  const span = parentObject.startSpan(args);
@@ -5427,10 +5685,10 @@ function extractAttachments(event, attachments) {
5427
5685
  event[key] = value.reference;
5428
5686
  continue;
5429
5687
  }
5430
- if (_optionalChain([value, 'optionalAccess', _55 => _55.type]) === BRAINTRUST_ATTACHMENT && value.key && !value.uploader) {
5688
+ if (_optionalChain([value, 'optionalAccess', _59 => _59.type]) === BRAINTRUST_ATTACHMENT && value.key && !value.uploader) {
5431
5689
  continue;
5432
5690
  }
5433
- if (_optionalChain([value, 'optionalAccess', _56 => _56.reference, 'optionalAccess', _57 => _57.type]) === BRAINTRUST_ATTACHMENT && _optionalChain([value, 'optionalAccess', _58 => _58.uploader])) {
5691
+ if (_optionalChain([value, 'optionalAccess', _60 => _60.reference, 'optionalAccess', _61 => _61.type]) === BRAINTRUST_ATTACHMENT && _optionalChain([value, 'optionalAccess', _62 => _62.uploader])) {
5434
5692
  const attachment = new Attachment({
5435
5693
  data: value.dataDebugString,
5436
5694
  filename: value.reference.filename,
@@ -5497,13 +5755,13 @@ function validateAndSanitizeExperimentLogFullArgs(event, hasDataset) {
5497
5755
  var INTERNAL_BTQL_LIMIT = 1e3;
5498
5756
  var MAX_BTQL_ITERATIONS = 1e4;
5499
5757
  var ObjectFetcher = (_class8 = class {
5500
- constructor(objectType, pinnedVersion, mutateRecord, _internal_btql) {;_class8.prototype.__init35.call(this);
5758
+ constructor(objectType, pinnedVersion, mutateRecord, _internal_btql) {;_class8.prototype.__init36.call(this);
5501
5759
  this.objectType = objectType;
5502
5760
  this.pinnedVersion = pinnedVersion;
5503
5761
  this.mutateRecord = mutateRecord;
5504
5762
  this._internal_btql = _internal_btql;
5505
5763
  }
5506
- __init35() {this._fetchedData = void 0}
5764
+ __init36() {this._fetchedData = void 0}
5507
5765
  get id() {
5508
5766
  throw new Error("ObjectFetcher subclasses must have an 'id' attribute");
5509
5767
  }
@@ -5568,7 +5826,7 @@ var ObjectFetcher = (_class8 = class {
5568
5826
  throw new Error("Too many BTQL iterations");
5569
5827
  }
5570
5828
  }
5571
- this._fetchedData = this.mutateRecord ? _optionalChain([data, 'optionalAccess', _59 => _59.map, 'call', _60 => _60(this.mutateRecord)]) : data;
5829
+ this._fetchedData = this.mutateRecord ? _optionalChain([data, 'optionalAccess', _63 => _63.map, 'call', _64 => _64(this.mutateRecord)]) : data;
5572
5830
  }
5573
5831
  return this._fetchedData || [];
5574
5832
  }
@@ -5599,9 +5857,9 @@ var Experiment2 = (_class9 = class extends ObjectFetcher {
5599
5857
 
5600
5858
 
5601
5859
  // For type identification.
5602
- __init36() {this.kind = "experiment"}
5860
+ __init37() {this.kind = "experiment"}
5603
5861
  constructor(state, lazyMetadata, dataset) {
5604
- super("experiment", void 0, (r) => enrichAttachments(r, state));_class9.prototype.__init36.call(this);;
5862
+ super("experiment", void 0, (r) => enrichAttachments(r, state));_class9.prototype.__init37.call(this);;
5605
5863
  this.lazyMetadata = lazyMetadata;
5606
5864
  this.dataset = dataset;
5607
5865
  this.lastStartTime = getCurrentUnixTimestamp();
@@ -5649,7 +5907,7 @@ var Experiment2 = (_class9 = class extends ObjectFetcher {
5649
5907
  * @returns The `id` of the logged event.
5650
5908
  */
5651
5909
  log(event, options) {
5652
- if (this.calledStartSpan && !_optionalChain([options, 'optionalAccess', _61 => _61.allowConcurrentWithSpans])) {
5910
+ if (this.calledStartSpan && !_optionalChain([options, 'optionalAccess', _65 => _65.allowConcurrentWithSpans])) {
5653
5911
  throw new Error(
5654
5912
  "Cannot run toplevel `log` method while using spans. To log to the span, call `experiment.traced` and then log with `span.log`"
5655
5913
  );
@@ -5702,12 +5960,12 @@ var Experiment2 = (_class9 = class extends ObjectFetcher {
5702
5960
  state: this.state,
5703
5961
  ...startSpanParentArgs({
5704
5962
  state: this.state,
5705
- parent: _optionalChain([args, 'optionalAccess', _62 => _62.parent]),
5963
+ parent: _optionalChain([args, 'optionalAccess', _66 => _66.parent]),
5706
5964
  parentObjectType: this.parentObjectType(),
5707
5965
  parentObjectId: this.lazyId,
5708
5966
  parentComputeObjectMetadataArgs: void 0,
5709
5967
  parentSpanIds: void 0,
5710
- propagatedEvent: _optionalChain([args, 'optionalAccess', _63 => _63.propagatedEvent])
5968
+ propagatedEvent: _optionalChain([args, 'optionalAccess', _67 => _67.propagatedEvent])
5711
5969
  }),
5712
5970
  defaultRootType: "eval" /* EVAL */
5713
5971
  });
@@ -5908,8 +6166,8 @@ var SpanImpl = (_class10 = class _SpanImpl {
5908
6166
 
5909
6167
 
5910
6168
 
5911
- __init37() {this.kind = "span"}
5912
- constructor(args) {;_class10.prototype.__init37.call(this);
6169
+ __init38() {this.kind = "span"}
6170
+ constructor(args) {;_class10.prototype.__init38.call(this);
5913
6171
  this._state = args.state;
5914
6172
  const spanAttributes = _nullishCoalesce(args.spanAttributes, () => ( {}));
5915
6173
  const rawEvent = _nullishCoalesce(args.event, () => ( {}));
@@ -5949,13 +6207,17 @@ var SpanImpl = (_class10 = class _SpanImpl {
5949
6207
  },
5950
6208
  created: (/* @__PURE__ */ new Date()).toISOString()
5951
6209
  };
5952
- this._id = _nullishCoalesce(eventId, () => ( _uuid.v4.call(void 0, )));
5953
- this._spanId = _nullishCoalesce(args.spanId, () => ( _uuid.v4.call(void 0, )));
6210
+ this._id = _nullishCoalesce(eventId, () => ( this._state.idGenerator.getSpanId()));
6211
+ this._spanId = _nullishCoalesce(args.spanId, () => ( this._state.idGenerator.getSpanId()));
5954
6212
  if (args.parentSpanIds) {
5955
6213
  this._rootSpanId = args.parentSpanIds.rootSpanId;
5956
6214
  this._spanParents = "parentSpanIds" in args.parentSpanIds ? args.parentSpanIds.parentSpanIds : [args.parentSpanIds.spanId];
5957
6215
  } else {
5958
- this._rootSpanId = this._spanId;
6216
+ if (this._state.idGenerator.shareRootSpanId()) {
6217
+ this._rootSpanId = this._spanId;
6218
+ } else {
6219
+ this._rootSpanId = this._state.idGenerator.getTraceId();
6220
+ }
5959
6221
  this._spanParents = void 0;
5960
6222
  }
5961
6223
  this.isMerge = false;
@@ -5999,10 +6261,10 @@ var SpanImpl = (_class10 = class _SpanImpl {
5999
6261
  ...serializableInternalData,
6000
6262
  [IS_MERGE_FIELD]: this.isMerge
6001
6263
  });
6002
- if (_optionalChain([partialRecord, 'access', _64 => _64.metrics, 'optionalAccess', _65 => _65.end])) {
6003
- this.loggedEndTime = _optionalChain([partialRecord, 'access', _66 => _66.metrics, 'optionalAccess', _67 => _67.end]);
6264
+ if (_optionalChain([partialRecord, 'access', _68 => _68.metrics, 'optionalAccess', _69 => _69.end])) {
6265
+ this.loggedEndTime = _optionalChain([partialRecord, 'access', _70 => _70.metrics, 'optionalAccess', _71 => _71.end]);
6004
6266
  }
6005
- if ((_nullishCoalesce(partialRecord.tags, () => ( []))).length > 0 && _optionalChain([this, 'access', _68 => _68._spanParents, 'optionalAccess', _69 => _69.length])) {
6267
+ if ((_nullishCoalesce(partialRecord.tags, () => ( []))).length > 0 && _optionalChain([this, 'access', _72 => _72._spanParents, 'optionalAccess', _73 => _73.length])) {
6006
6268
  throw new Error("Tags can only be logged to the root span");
6007
6269
  }
6008
6270
  const computeRecord = async () => ({
@@ -6047,18 +6309,18 @@ var SpanImpl = (_class10 = class _SpanImpl {
6047
6309
  );
6048
6310
  }
6049
6311
  startSpan(args) {
6050
- const parentSpanIds = _optionalChain([args, 'optionalAccess', _70 => _70.parent]) ? void 0 : { spanId: this._spanId, rootSpanId: this._rootSpanId };
6312
+ const parentSpanIds = _optionalChain([args, 'optionalAccess', _74 => _74.parent]) ? void 0 : { spanId: this._spanId, rootSpanId: this._rootSpanId };
6051
6313
  return new _SpanImpl({
6052
6314
  state: this._state,
6053
6315
  ...args,
6054
6316
  ...startSpanParentArgs({
6055
6317
  state: this._state,
6056
- parent: _optionalChain([args, 'optionalAccess', _71 => _71.parent]),
6318
+ parent: _optionalChain([args, 'optionalAccess', _75 => _75.parent]),
6057
6319
  parentObjectType: this.parentObjectType,
6058
6320
  parentObjectId: this.parentObjectId,
6059
6321
  parentComputeObjectMetadataArgs: this.parentComputeObjectMetadataArgs,
6060
6322
  parentSpanIds,
6061
- propagatedEvent: _nullishCoalesce(_optionalChain([args, 'optionalAccess', _72 => _72.propagatedEvent]), () => ( this.propagatedEvent))
6323
+ propagatedEvent: _nullishCoalesce(_optionalChain([args, 'optionalAccess', _76 => _76.propagatedEvent]), () => ( this.propagatedEvent))
6062
6324
  })
6063
6325
  });
6064
6326
  }
@@ -6072,12 +6334,12 @@ var SpanImpl = (_class10 = class _SpanImpl {
6072
6334
  ...args,
6073
6335
  ...startSpanParentArgs({
6074
6336
  state: this._state,
6075
- parent: _optionalChain([args, 'optionalAccess', _73 => _73.parent]),
6337
+ parent: _optionalChain([args, 'optionalAccess', _77 => _77.parent]),
6076
6338
  parentObjectType: this.parentObjectType,
6077
6339
  parentObjectId: this.parentObjectId,
6078
6340
  parentComputeObjectMetadataArgs: this.parentComputeObjectMetadataArgs,
6079
6341
  parentSpanIds,
6080
- propagatedEvent: _nullishCoalesce(_optionalChain([args, 'optionalAccess', _74 => _74.propagatedEvent]), () => ( this.propagatedEvent))
6342
+ propagatedEvent: _nullishCoalesce(_optionalChain([args, 'optionalAccess', _78 => _78.propagatedEvent]), () => ( this.propagatedEvent))
6081
6343
  }),
6082
6344
  spanId
6083
6345
  });
@@ -6086,7 +6348,7 @@ var SpanImpl = (_class10 = class _SpanImpl {
6086
6348
  let endTime;
6087
6349
  let internalData = {};
6088
6350
  if (!this.loggedEndTime) {
6089
- endTime = _nullishCoalesce(_optionalChain([args, 'optionalAccess', _75 => _75.endTime]), () => ( getCurrentUnixTimestamp()));
6351
+ endTime = _nullishCoalesce(_optionalChain([args, 'optionalAccess', _79 => _79.endTime]), () => ( getCurrentUnixTimestamp()));
6090
6352
  internalData = { metrics: { end: endTime } };
6091
6353
  } else {
6092
6354
  endTime = this.loggedEndTime;
@@ -6129,8 +6391,8 @@ var SpanImpl = (_class10 = class _SpanImpl {
6129
6391
  const args = this.parentComputeObjectMetadataArgs;
6130
6392
  switch (this.parentObjectType) {
6131
6393
  case 2 /* PROJECT_LOGS */: {
6132
- const projectID = _optionalChain([args, 'optionalAccess', _76 => _76.project_id]) || this.parentObjectId.getSync().value;
6133
- const projectName = _optionalChain([args, 'optionalAccess', _77 => _77.project_name]);
6394
+ const projectID = _optionalChain([args, 'optionalAccess', _80 => _80.project_id]) || this.parentObjectId.getSync().value;
6395
+ const projectName = _optionalChain([args, 'optionalAccess', _81 => _81.project_name]);
6134
6396
  if (projectID) {
6135
6397
  return `${baseUrl}/object?object_type=project_logs&object_id=${projectID}&id=${this._id}`;
6136
6398
  } else if (projectName) {
@@ -6140,7 +6402,7 @@ var SpanImpl = (_class10 = class _SpanImpl {
6140
6402
  }
6141
6403
  }
6142
6404
  case 1 /* EXPERIMENT */: {
6143
- const expID = _optionalChain([args, 'optionalAccess', _78 => _78.experiment_id]) || _optionalChain([this, 'access', _79 => _79.parentObjectId, 'optionalAccess', _80 => _80.getSync, 'call', _81 => _81(), 'optionalAccess', _82 => _82.value]);
6405
+ const expID = _optionalChain([args, 'optionalAccess', _82 => _82.experiment_id]) || _optionalChain([this, 'access', _83 => _83.parentObjectId, 'optionalAccess', _84 => _84.getSync, 'call', _85 => _85(), 'optionalAccess', _86 => _86.value]);
6144
6406
  if (!expID) {
6145
6407
  return getErrPermlink("provide-experiment-id");
6146
6408
  } else {
@@ -6230,13 +6492,13 @@ var Dataset2 = (_class11 = class extends ObjectFetcher {
6230
6492
  )
6231
6493
  ),
6232
6494
  _internal_btql
6233
- );_class11.prototype.__init38.call(this);_class11.prototype.__init39.call(this);;
6495
+ );_class11.prototype.__init39.call(this);_class11.prototype.__init40.call(this);;
6234
6496
  this.state = state;
6235
6497
  this.lazyMetadata = lazyMetadata;
6236
6498
  }
6237
6499
 
6238
- __init38() {this.__braintrust_dataset_marker = true}
6239
- __init39() {this.newRecords = 0}
6500
+ __init39() {this.__braintrust_dataset_marker = true}
6501
+ __init40() {this.newRecords = 0}
6240
6502
  get id() {
6241
6503
  return (async () => {
6242
6504
  return (await this.lazyMetadata.get()).dataset.id;
@@ -6559,14 +6821,14 @@ function renderPromptParams(params, args, options) {
6559
6821
  return params;
6560
6822
  }
6561
6823
  var Prompt2 = (_class12 = class _Prompt {
6562
- constructor(metadata, defaults, noTrace) {;_class12.prototype.__init40.call(this);_class12.prototype.__init41.call(this);
6824
+ constructor(metadata, defaults, noTrace) {;_class12.prototype.__init41.call(this);_class12.prototype.__init42.call(this);
6563
6825
  this.metadata = metadata;
6564
6826
  this.defaults = defaults;
6565
6827
  this.noTrace = noTrace;
6566
6828
  }
6567
6829
 
6568
- __init40() {this.hasParsedPromptData = false}
6569
- __init41() {this.__braintrust_prompt_marker = true}
6830
+ __init41() {this.hasParsedPromptData = false}
6831
+ __init42() {this.__braintrust_prompt_marker = true}
6570
6832
  get id() {
6571
6833
  return this.metadata.id;
6572
6834
  }
@@ -6580,13 +6842,13 @@ var Prompt2 = (_class12 = class _Prompt {
6580
6842
  return "slug" in this.metadata ? this.metadata.slug : this.metadata.id;
6581
6843
  }
6582
6844
  get prompt() {
6583
- return _optionalChain([this, 'access', _83 => _83.getParsedPromptData, 'call', _84 => _84(), 'optionalAccess', _85 => _85.prompt]);
6845
+ return _optionalChain([this, 'access', _87 => _87.getParsedPromptData, 'call', _88 => _88(), 'optionalAccess', _89 => _89.prompt]);
6584
6846
  }
6585
6847
  get version() {
6586
6848
  return this.metadata[TRANSACTION_ID_FIELD];
6587
6849
  }
6588
6850
  get options() {
6589
- return _optionalChain([this, 'access', _86 => _86.getParsedPromptData, 'call', _87 => _87(), 'optionalAccess', _88 => _88.options]) || {};
6851
+ return _optionalChain([this, 'access', _90 => _90.getParsedPromptData, 'call', _91 => _91(), 'optionalAccess', _92 => _92.options]) || {};
6590
6852
  }
6591
6853
  get promptData() {
6592
6854
  return this.getParsedPromptData();
@@ -6737,7 +6999,7 @@ var Prompt2 = (_class12 = class _Prompt {
6737
6999
  return {
6738
7000
  type: "chat",
6739
7001
  messages,
6740
- ..._optionalChain([prompt, 'access', _89 => _89.tools, 'optionalAccess', _90 => _90.trim, 'call', _91 => _91()]) ? {
7002
+ ..._optionalChain([prompt, 'access', _93 => _93.tools, 'optionalAccess', _94 => _94.trim, 'call', _95 => _95()]) ? {
6741
7003
  tools: render(prompt.tools)
6742
7004
  } : void 0
6743
7005
  };
@@ -6818,7 +7080,7 @@ function configureNode() {
6818
7080
  var _express = require('express'); var _express2 = _interopRequireDefault(_express);
6819
7081
  var _cors = require('cors'); var _cors2 = _interopRequireDefault(_cors);
6820
7082
 
6821
- // ../node_modules/.pnpm/async@3.2.5/node_modules/async/dist/async.mjs
7083
+ // ../../node_modules/.pnpm/async@3.2.5/node_modules/async/dist/async.mjs
6822
7084
  function initialParams(fn) {
6823
7085
  return function(...args) {
6824
7086
  var callback = args.pop();
@@ -7871,8 +8133,8 @@ function fitNameToSpaces(name, length) {
7871
8133
  }
7872
8134
  var BarProgressReporter = (_class13 = class {
7873
8135
 
7874
- __init42() {this.bars = {}}
7875
- constructor() {;_class13.prototype.__init42.call(this);
8136
+ __init43() {this.bars = {}}
8137
+ constructor() {;_class13.prototype.__init43.call(this);
7876
8138
  this.multiBar = new cliProgress.MultiBar(
7877
8139
  {
7878
8140
  clearOnComplete: false,
@@ -7915,9 +8177,9 @@ var Project2 = (_class14 = class {
7915
8177
 
7916
8178
 
7917
8179
 
7918
- __init43() {this._publishableCodeFunctions = []}
7919
- __init44() {this._publishablePrompts = []}
7920
- constructor(args) {;_class14.prototype.__init43.call(this);_class14.prototype.__init44.call(this);
8180
+ __init44() {this._publishableCodeFunctions = []}
8181
+ __init45() {this._publishablePrompts = []}
8182
+ constructor(args) {;_class14.prototype.__init44.call(this);_class14.prototype.__init45.call(this);
7921
8183
  _initializeSpanContext();
7922
8184
  this.name = "name" in args ? args.name : void 0;
7923
8185
  this.id = "id" in args ? args.id : void 0;
@@ -7962,10 +8224,10 @@ var Project2 = (_class14 = class {
7962
8224
  }
7963
8225
  }, _class14);
7964
8226
  var ToolBuilder = (_class15 = class {
7965
- constructor(project) {;_class15.prototype.__init45.call(this);
8227
+ constructor(project) {;_class15.prototype.__init46.call(this);
7966
8228
  this.project = project;
7967
8229
  }
7968
- __init45() {this.taskCounter = 0}
8230
+ __init46() {this.taskCounter = 0}
7969
8231
  // This type definition is just a catch all so that the implementation can be
7970
8232
  // less specific than the two more specific declarations above.
7971
8233
  create(opts) {
@@ -7992,10 +8254,10 @@ var ToolBuilder = (_class15 = class {
7992
8254
  }
7993
8255
  }, _class15);
7994
8256
  var ScorerBuilder = (_class16 = class {
7995
- constructor(project) {;_class16.prototype.__init46.call(this);
8257
+ constructor(project) {;_class16.prototype.__init47.call(this);
7996
8258
  this.project = project;
7997
8259
  }
7998
- __init46() {this.taskCounter = 0}
8260
+ __init47() {this.taskCounter = 0}
7999
8261
  create(opts) {
8000
8262
  this.taskCounter++;
8001
8263
  let resolvedName = opts.name;
@@ -8212,9 +8474,9 @@ function promptDefinitionToPromptData(promptDefinition, rawTools) {
8212
8474
  }
8213
8475
  };
8214
8476
  }
8215
- var ProjectNameIdMap = (_class17 = class {constructor() { _class17.prototype.__init47.call(this);_class17.prototype.__init48.call(this); }
8216
- __init47() {this.nameToId = {}}
8217
- __init48() {this.idToName = {}}
8477
+ var ProjectNameIdMap = (_class17 = class {constructor() { _class17.prototype.__init48.call(this);_class17.prototype.__init49.call(this); }
8478
+ __init48() {this.nameToId = {}}
8479
+ __init49() {this.idToName = {}}
8218
8480
  async getId(projectName) {
8219
8481
  if (!(projectName in this.nameToId)) {
8220
8482
  const response = await _internalGetGlobalState().appConn().post_json("api/project/register", {
@@ -8576,10 +8838,10 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
8576
8838
  span,
8577
8839
  parameters: _nullishCoalesce(parameters, () => ( {})),
8578
8840
  reportProgress: (event) => {
8579
- _optionalChain([stream, 'optionalCall', _92 => _92({
8841
+ _optionalChain([stream, 'optionalCall', _96 => _96({
8580
8842
  ...event,
8581
8843
  id: rootSpan.id,
8582
- origin: _optionalChain([baseEvent, 'access', _93 => _93.event, 'optionalAccess', _94 => _94.origin]),
8844
+ origin: _optionalChain([baseEvent, 'access', _97 => _97.event, 'optionalAccess', _98 => _98.origin]),
8583
8845
  name: evaluator.evalName,
8584
8846
  object_type: "task"
8585
8847
  })]);
@@ -8729,7 +8991,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
8729
8991
  ...scores
8730
8992
  },
8731
8993
  error: error2,
8732
- origin: _optionalChain([baseEvent, 'access', _95 => _95.event, 'optionalAccess', _96 => _96.origin])
8994
+ origin: _optionalChain([baseEvent, 'access', _99 => _99.event, 'optionalAccess', _100 => _100.origin])
8733
8995
  });
8734
8996
  };
8735
8997
  if (!experiment) {
@@ -8952,12 +9214,12 @@ async function cachedLogin(options) {
8952
9214
  }
8953
9215
  function makeCheckAuthorized(allowedOrgName) {
8954
9216
  return async (req, _res, next) => {
8955
- if (!_optionalChain([req, 'access', _97 => _97.ctx, 'optionalAccess', _98 => _98.token])) {
9217
+ if (!_optionalChain([req, 'access', _101 => _101.ctx, 'optionalAccess', _102 => _102.token])) {
8956
9218
  return next(_httperrors2.default.call(void 0, 401, "Unauthorized"));
8957
9219
  }
8958
9220
  try {
8959
9221
  const state = await cachedLogin({
8960
- apiKey: _optionalChain([req, 'access', _99 => _99.ctx, 'optionalAccess', _100 => _100.token]),
9222
+ apiKey: _optionalChain([req, 'access', _103 => _103.ctx, 'optionalAccess', _104 => _104.token]),
8961
9223
  orgName: allowedOrgName
8962
9224
  });
8963
9225
  req.ctx.state = state;
@@ -9163,7 +9425,7 @@ function runDevServer(evaluators, opts) {
9163
9425
  scores,
9164
9426
  stream
9165
9427
  } = evalBodySchema.parse(req.body);
9166
- if (!_optionalChain([req, 'access', _101 => _101.ctx, 'optionalAccess', _102 => _102.state])) {
9428
+ if (!_optionalChain([req, 'access', _105 => _105.ctx, 'optionalAccess', _106 => _106.state])) {
9167
9429
  res.status(500).json({ error: "Braintrust state not initialized in request" });
9168
9430
  return;
9169
9431
  }
@@ -9220,7 +9482,7 @@ function runDevServer(evaluators, opts) {
9220
9482
  ...evaluator,
9221
9483
  data: evalData.data,
9222
9484
  scores: evaluator.scores.concat(
9223
- _nullishCoalesce(_optionalChain([scores, 'optionalAccess', _103 => _103.map, 'call', _104 => _104(
9485
+ _nullishCoalesce(_optionalChain([scores, 'optionalAccess', _107 => _107.map, 'call', _108 => _108(
9224
9486
  (score) => makeScorer(state, score.name, score.function_id)
9225
9487
  )]), () => ( []))
9226
9488
  ),