braintrust 0.0.56 → 0.0.57

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/dist/cli.js CHANGED
@@ -896,15 +896,15 @@ var require_route = __commonJS({
896
896
  };
897
897
  }
898
898
  function wrapConversion(toModel, graph) {
899
- const path4 = [graph[toModel].parent, toModel];
899
+ const path5 = [graph[toModel].parent, toModel];
900
900
  let fn = conversions[graph[toModel].parent][toModel];
901
901
  let cur = graph[toModel].parent;
902
902
  while (graph[cur].parent) {
903
- path4.unshift(graph[cur].parent);
903
+ path5.unshift(graph[cur].parent);
904
904
  fn = link(conversions[graph[cur].parent][cur], fn);
905
905
  cur = graph[cur].parent;
906
906
  }
907
- fn.conversion = path4;
907
+ fn.conversion = path5;
908
908
  return fn;
909
909
  }
910
910
  module2.exports = function(fromModel) {
@@ -1579,8 +1579,8 @@ var require_async = __commonJS({
1579
1579
  "use strict";
1580
1580
  Object.defineProperty(exports2, "__esModule", { value: true });
1581
1581
  exports2.read = void 0;
1582
- function read(path4, settings, callback) {
1583
- settings.fs.lstat(path4, (lstatError, lstat) => {
1582
+ function read(path5, settings, callback) {
1583
+ settings.fs.lstat(path5, (lstatError, lstat) => {
1584
1584
  if (lstatError !== null) {
1585
1585
  callFailureCallback(callback, lstatError);
1586
1586
  return;
@@ -1589,7 +1589,7 @@ var require_async = __commonJS({
1589
1589
  callSuccessCallback(callback, lstat);
1590
1590
  return;
1591
1591
  }
1592
- settings.fs.stat(path4, (statError, stat) => {
1592
+ settings.fs.stat(path5, (statError, stat) => {
1593
1593
  if (statError !== null) {
1594
1594
  if (settings.throwErrorOnBrokenSymbolicLink) {
1595
1595
  callFailureCallback(callback, statError);
@@ -1621,13 +1621,13 @@ var require_sync = __commonJS({
1621
1621
  "use strict";
1622
1622
  Object.defineProperty(exports2, "__esModule", { value: true });
1623
1623
  exports2.read = void 0;
1624
- function read(path4, settings) {
1625
- const lstat = settings.fs.lstatSync(path4);
1624
+ function read(path5, settings) {
1625
+ const lstat = settings.fs.lstatSync(path5);
1626
1626
  if (!lstat.isSymbolicLink() || !settings.followSymbolicLink) {
1627
1627
  return lstat;
1628
1628
  }
1629
1629
  try {
1630
- const stat = settings.fs.statSync(path4);
1630
+ const stat = settings.fs.statSync(path5);
1631
1631
  if (settings.markSymbolicLink) {
1632
1632
  stat.isSymbolicLink = () => true;
1633
1633
  }
@@ -1698,17 +1698,17 @@ var require_out = __commonJS({
1698
1698
  var sync = require_sync();
1699
1699
  var settings_1 = require_settings();
1700
1700
  exports2.Settings = settings_1.default;
1701
- function stat(path4, optionsOrSettingsOrCallback, callback) {
1701
+ function stat(path5, optionsOrSettingsOrCallback, callback) {
1702
1702
  if (typeof optionsOrSettingsOrCallback === "function") {
1703
- async.read(path4, getSettings(), optionsOrSettingsOrCallback);
1703
+ async.read(path5, getSettings(), optionsOrSettingsOrCallback);
1704
1704
  return;
1705
1705
  }
1706
- async.read(path4, getSettings(optionsOrSettingsOrCallback), callback);
1706
+ async.read(path5, getSettings(optionsOrSettingsOrCallback), callback);
1707
1707
  }
1708
1708
  exports2.stat = stat;
1709
- function statSync(path4, optionsOrSettings) {
1709
+ function statSync(path5, optionsOrSettings) {
1710
1710
  const settings = getSettings(optionsOrSettings);
1711
- return sync.read(path4, settings);
1711
+ return sync.read(path5, settings);
1712
1712
  }
1713
1713
  exports2.statSync = statSync;
1714
1714
  function getSettings(settingsOrOptions = {}) {
@@ -1927,16 +1927,16 @@ var require_async2 = __commonJS({
1927
1927
  return;
1928
1928
  }
1929
1929
  const tasks = names.map((name) => {
1930
- const path4 = common.joinPathSegments(directory, name, settings.pathSegmentSeparator);
1930
+ const path5 = common.joinPathSegments(directory, name, settings.pathSegmentSeparator);
1931
1931
  return (done) => {
1932
- fsStat.stat(path4, settings.fsStatSettings, (error2, stats) => {
1932
+ fsStat.stat(path5, settings.fsStatSettings, (error2, stats) => {
1933
1933
  if (error2 !== null) {
1934
1934
  done(error2);
1935
1935
  return;
1936
1936
  }
1937
1937
  const entry = {
1938
1938
  name,
1939
- path: path4,
1939
+ path: path5,
1940
1940
  dirent: utils.fs.createDirentFromStats(name, stats)
1941
1941
  };
1942
1942
  if (settings.stats) {
@@ -2054,7 +2054,7 @@ var require_settings2 = __commonJS({
2054
2054
  "node_modules/@nodelib/fs.scandir/out/settings.js"(exports2) {
2055
2055
  "use strict";
2056
2056
  Object.defineProperty(exports2, "__esModule", { value: true });
2057
- var path4 = require("path");
2057
+ var path5 = require("path");
2058
2058
  var fsStat = require_out();
2059
2059
  var fs2 = require_fs3();
2060
2060
  var Settings = class {
@@ -2062,7 +2062,7 @@ var require_settings2 = __commonJS({
2062
2062
  this._options = _options;
2063
2063
  this.followSymbolicLinks = this._getValue(this._options.followSymbolicLinks, false);
2064
2064
  this.fs = fs2.createFileSystemAdapter(this._options.fs);
2065
- this.pathSegmentSeparator = this._getValue(this._options.pathSegmentSeparator, path4.sep);
2065
+ this.pathSegmentSeparator = this._getValue(this._options.pathSegmentSeparator, path5.sep);
2066
2066
  this.stats = this._getValue(this._options.stats, false);
2067
2067
  this.throwErrorOnBrokenSymbolicLink = this._getValue(this._options.throwErrorOnBrokenSymbolicLink, true);
2068
2068
  this.fsStatSettings = new fsStat.Settings({
@@ -2089,17 +2089,17 @@ var require_out2 = __commonJS({
2089
2089
  var sync = require_sync2();
2090
2090
  var settings_1 = require_settings2();
2091
2091
  exports2.Settings = settings_1.default;
2092
- function scandir(path4, optionsOrSettingsOrCallback, callback) {
2092
+ function scandir(path5, optionsOrSettingsOrCallback, callback) {
2093
2093
  if (typeof optionsOrSettingsOrCallback === "function") {
2094
- async.read(path4, getSettings(), optionsOrSettingsOrCallback);
2094
+ async.read(path5, getSettings(), optionsOrSettingsOrCallback);
2095
2095
  return;
2096
2096
  }
2097
- async.read(path4, getSettings(optionsOrSettingsOrCallback), callback);
2097
+ async.read(path5, getSettings(optionsOrSettingsOrCallback), callback);
2098
2098
  }
2099
2099
  exports2.scandir = scandir;
2100
- function scandirSync(path4, optionsOrSettings) {
2100
+ function scandirSync(path5, optionsOrSettings) {
2101
2101
  const settings = getSettings(optionsOrSettings);
2102
- return sync.read(path4, settings);
2102
+ return sync.read(path5, settings);
2103
2103
  }
2104
2104
  exports2.scandirSync = scandirSync;
2105
2105
  function getSettings(settingsOrOptions = {}) {
@@ -2703,7 +2703,7 @@ var require_settings3 = __commonJS({
2703
2703
  "node_modules/@nodelib/fs.walk/out/settings.js"(exports2) {
2704
2704
  "use strict";
2705
2705
  Object.defineProperty(exports2, "__esModule", { value: true });
2706
- var path4 = require("path");
2706
+ var path5 = require("path");
2707
2707
  var fsScandir = require_out2();
2708
2708
  var Settings = class {
2709
2709
  constructor(_options = {}) {
@@ -2713,7 +2713,7 @@ var require_settings3 = __commonJS({
2713
2713
  this.deepFilter = this._getValue(this._options.deepFilter, null);
2714
2714
  this.entryFilter = this._getValue(this._options.entryFilter, null);
2715
2715
  this.errorFilter = this._getValue(this._options.errorFilter, null);
2716
- this.pathSegmentSeparator = this._getValue(this._options.pathSegmentSeparator, path4.sep);
2716
+ this.pathSegmentSeparator = this._getValue(this._options.pathSegmentSeparator, path5.sep);
2717
2717
  this.fsScandirSettings = new fsScandir.Settings({
2718
2718
  followSymbolicLinks: this._options.followSymbolicLinks,
2719
2719
  fs: this._options.fs,
@@ -3304,7 +3304,7 @@ var require_argparse = __commonJS({
3304
3304
  var util3 = require("util");
3305
3305
  var fs2 = require("fs");
3306
3306
  var sub = require_sub();
3307
- var path4 = require("path");
3307
+ var path5 = require("path");
3308
3308
  var repr = util3.inspect;
3309
3309
  function get_argv() {
3310
3310
  return process.argv.slice(1);
@@ -5359,7 +5359,7 @@ var require_argparse = __commonJS({
5359
5359
  conflict_handler
5360
5360
  });
5361
5361
  if (prog === void 0) {
5362
- prog = path4.basename(get_argv()[0] || "");
5362
+ prog = path5.basename(get_argv()[0] || "");
5363
5363
  }
5364
5364
  this.prog = prog;
5365
5365
  this.usage = usage;
@@ -15391,11 +15391,11 @@ var require_mime_types = __commonJS({
15391
15391
  }
15392
15392
  return exts[0];
15393
15393
  }
15394
- function lookup(path4) {
15395
- if (!path4 || typeof path4 !== "string") {
15394
+ function lookup(path5) {
15395
+ if (!path5 || typeof path5 !== "string") {
15396
15396
  return false;
15397
15397
  }
15398
- var extension2 = extname("x." + path4).toLowerCase().substr(1);
15398
+ var extension2 = extname("x." + path5).toLowerCase().substr(1);
15399
15399
  if (!extension2) {
15400
15400
  return false;
15401
15401
  }
@@ -15652,7 +15652,7 @@ var require_form_data = __commonJS({
15652
15652
  "node_modules/form-data/lib/form_data.js"(exports2, module2) {
15653
15653
  var CombinedStream = require_combined_stream();
15654
15654
  var util3 = require("util");
15655
- var path4 = require("path");
15655
+ var path5 = require("path");
15656
15656
  var http3 = require("http");
15657
15657
  var https3 = require("https");
15658
15658
  var parseUrl = require("url").parse;
@@ -15779,11 +15779,11 @@ var require_form_data = __commonJS({
15779
15779
  FormData3.prototype._getContentDisposition = function(value, options) {
15780
15780
  var filename, contentDisposition;
15781
15781
  if (typeof options.filepath === "string") {
15782
- filename = path4.normalize(options.filepath).replace(/\\/g, "/");
15782
+ filename = path5.normalize(options.filepath).replace(/\\/g, "/");
15783
15783
  } else if (options.filename || value.name || value.path) {
15784
- filename = path4.basename(options.filename || value.name || value.path);
15784
+ filename = path5.basename(options.filename || value.name || value.path);
15785
15785
  } else if (value.readable && value.hasOwnProperty("httpVersion")) {
15786
- filename = path4.basename(value.client._httpMessage.path || "");
15786
+ filename = path5.basename(value.client._httpMessage.path || "");
15787
15787
  }
15788
15788
  if (filename) {
15789
15789
  contentDisposition = 'filename="' + filename + '"';
@@ -18055,7 +18055,7 @@ var require_polyfills = __commonJS({
18055
18055
  fs2.fstatSync = statFixSync(fs2.fstatSync);
18056
18056
  fs2.lstatSync = statFixSync(fs2.lstatSync);
18057
18057
  if (fs2.chmod && !fs2.lchmod) {
18058
- fs2.lchmod = function(path4, mode, cb) {
18058
+ fs2.lchmod = function(path5, mode, cb) {
18059
18059
  if (cb)
18060
18060
  process.nextTick(cb);
18061
18061
  };
@@ -18063,7 +18063,7 @@ var require_polyfills = __commonJS({
18063
18063
  };
18064
18064
  }
18065
18065
  if (fs2.chown && !fs2.lchown) {
18066
- fs2.lchown = function(path4, uid, gid, cb) {
18066
+ fs2.lchown = function(path5, uid, gid, cb) {
18067
18067
  if (cb)
18068
18068
  process.nextTick(cb);
18069
18069
  };
@@ -18134,9 +18134,9 @@ var require_polyfills = __commonJS({
18134
18134
  };
18135
18135
  }(fs2.readSync);
18136
18136
  function patchLchmod(fs3) {
18137
- fs3.lchmod = function(path4, mode, callback) {
18137
+ fs3.lchmod = function(path5, mode, callback) {
18138
18138
  fs3.open(
18139
- path4,
18139
+ path5,
18140
18140
  constants.O_WRONLY | constants.O_SYMLINK,
18141
18141
  mode,
18142
18142
  function(err, fd) {
@@ -18154,8 +18154,8 @@ var require_polyfills = __commonJS({
18154
18154
  }
18155
18155
  );
18156
18156
  };
18157
- fs3.lchmodSync = function(path4, mode) {
18158
- var fd = fs3.openSync(path4, constants.O_WRONLY | constants.O_SYMLINK, mode);
18157
+ fs3.lchmodSync = function(path5, mode) {
18158
+ var fd = fs3.openSync(path5, constants.O_WRONLY | constants.O_SYMLINK, mode);
18159
18159
  var threw = true;
18160
18160
  var ret;
18161
18161
  try {
@@ -18176,8 +18176,8 @@ var require_polyfills = __commonJS({
18176
18176
  }
18177
18177
  function patchLutimes(fs3) {
18178
18178
  if (constants.hasOwnProperty("O_SYMLINK") && fs3.futimes) {
18179
- fs3.lutimes = function(path4, at, mt, cb) {
18180
- fs3.open(path4, constants.O_SYMLINK, function(er, fd) {
18179
+ fs3.lutimes = function(path5, at, mt, cb) {
18180
+ fs3.open(path5, constants.O_SYMLINK, function(er, fd) {
18181
18181
  if (er) {
18182
18182
  if (cb)
18183
18183
  cb(er);
@@ -18191,8 +18191,8 @@ var require_polyfills = __commonJS({
18191
18191
  });
18192
18192
  });
18193
18193
  };
18194
- fs3.lutimesSync = function(path4, at, mt) {
18195
- var fd = fs3.openSync(path4, constants.O_SYMLINK);
18194
+ fs3.lutimesSync = function(path5, at, mt) {
18195
+ var fd = fs3.openSync(path5, constants.O_SYMLINK);
18196
18196
  var ret;
18197
18197
  var threw = true;
18198
18198
  try {
@@ -18328,12 +18328,12 @@ var require_legacy_streams = __commonJS({
18328
18328
  ReadStream,
18329
18329
  WriteStream
18330
18330
  };
18331
- function ReadStream(path4, options) {
18331
+ function ReadStream(path5, options) {
18332
18332
  if (!(this instanceof ReadStream))
18333
- return new ReadStream(path4, options);
18333
+ return new ReadStream(path5, options);
18334
18334
  Stream.call(this);
18335
18335
  var self2 = this;
18336
- this.path = path4;
18336
+ this.path = path5;
18337
18337
  this.fd = null;
18338
18338
  this.readable = true;
18339
18339
  this.paused = false;
@@ -18379,11 +18379,11 @@ var require_legacy_streams = __commonJS({
18379
18379
  self2._read();
18380
18380
  });
18381
18381
  }
18382
- function WriteStream(path4, options) {
18382
+ function WriteStream(path5, options) {
18383
18383
  if (!(this instanceof WriteStream))
18384
- return new WriteStream(path4, options);
18384
+ return new WriteStream(path5, options);
18385
18385
  Stream.call(this);
18386
- this.path = path4;
18386
+ this.path = path5;
18387
18387
  this.fd = null;
18388
18388
  this.writable = true;
18389
18389
  this.flags = "w";
@@ -18526,14 +18526,14 @@ var require_graceful_fs = __commonJS({
18526
18526
  fs3.createWriteStream = createWriteStream;
18527
18527
  var fs$readFile = fs3.readFile;
18528
18528
  fs3.readFile = readFile;
18529
- function readFile(path4, options, cb) {
18529
+ function readFile(path5, options, cb) {
18530
18530
  if (typeof options === "function")
18531
18531
  cb = options, options = null;
18532
- return go$readFile(path4, options, cb);
18533
- function go$readFile(path5, options2, cb2, startTime) {
18534
- return fs$readFile(path5, options2, function(err) {
18532
+ return go$readFile(path5, options, cb);
18533
+ function go$readFile(path6, options2, cb2, startTime) {
18534
+ return fs$readFile(path6, options2, function(err) {
18535
18535
  if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
18536
- enqueue([go$readFile, [path5, options2, cb2], err, startTime || Date.now(), Date.now()]);
18536
+ enqueue([go$readFile, [path6, options2, cb2], err, startTime || Date.now(), Date.now()]);
18537
18537
  else {
18538
18538
  if (typeof cb2 === "function")
18539
18539
  cb2.apply(this, arguments);
@@ -18543,14 +18543,14 @@ var require_graceful_fs = __commonJS({
18543
18543
  }
18544
18544
  var fs$writeFile = fs3.writeFile;
18545
18545
  fs3.writeFile = writeFile;
18546
- function writeFile(path4, data, options, cb) {
18546
+ function writeFile(path5, data, options, cb) {
18547
18547
  if (typeof options === "function")
18548
18548
  cb = options, options = null;
18549
- return go$writeFile(path4, data, options, cb);
18550
- function go$writeFile(path5, data2, options2, cb2, startTime) {
18551
- return fs$writeFile(path5, data2, options2, function(err) {
18549
+ return go$writeFile(path5, data, options, cb);
18550
+ function go$writeFile(path6, data2, options2, cb2, startTime) {
18551
+ return fs$writeFile(path6, data2, options2, function(err) {
18552
18552
  if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
18553
- enqueue([go$writeFile, [path5, data2, options2, cb2], err, startTime || Date.now(), Date.now()]);
18553
+ enqueue([go$writeFile, [path6, data2, options2, cb2], err, startTime || Date.now(), Date.now()]);
18554
18554
  else {
18555
18555
  if (typeof cb2 === "function")
18556
18556
  cb2.apply(this, arguments);
@@ -18561,14 +18561,14 @@ var require_graceful_fs = __commonJS({
18561
18561
  var fs$appendFile = fs3.appendFile;
18562
18562
  if (fs$appendFile)
18563
18563
  fs3.appendFile = appendFile;
18564
- function appendFile(path4, data, options, cb) {
18564
+ function appendFile(path5, data, options, cb) {
18565
18565
  if (typeof options === "function")
18566
18566
  cb = options, options = null;
18567
- return go$appendFile(path4, data, options, cb);
18568
- function go$appendFile(path5, data2, options2, cb2, startTime) {
18569
- return fs$appendFile(path5, data2, options2, function(err) {
18567
+ return go$appendFile(path5, data, options, cb);
18568
+ function go$appendFile(path6, data2, options2, cb2, startTime) {
18569
+ return fs$appendFile(path6, data2, options2, function(err) {
18570
18570
  if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
18571
- enqueue([go$appendFile, [path5, data2, options2, cb2], err, startTime || Date.now(), Date.now()]);
18571
+ enqueue([go$appendFile, [path6, data2, options2, cb2], err, startTime || Date.now(), Date.now()]);
18572
18572
  else {
18573
18573
  if (typeof cb2 === "function")
18574
18574
  cb2.apply(this, arguments);
@@ -18599,31 +18599,31 @@ var require_graceful_fs = __commonJS({
18599
18599
  var fs$readdir = fs3.readdir;
18600
18600
  fs3.readdir = readdir;
18601
18601
  var noReaddirOptionVersions = /^v[0-5]\./;
18602
- function readdir(path4, options, cb) {
18602
+ function readdir(path5, options, cb) {
18603
18603
  if (typeof options === "function")
18604
18604
  cb = options, options = null;
18605
- var go$readdir = noReaddirOptionVersions.test(process.version) ? function go$readdir2(path5, options2, cb2, startTime) {
18606
- return fs$readdir(path5, fs$readdirCallback(
18607
- path5,
18605
+ var go$readdir = noReaddirOptionVersions.test(process.version) ? function go$readdir2(path6, options2, cb2, startTime) {
18606
+ return fs$readdir(path6, fs$readdirCallback(
18607
+ path6,
18608
18608
  options2,
18609
18609
  cb2,
18610
18610
  startTime
18611
18611
  ));
18612
- } : function go$readdir2(path5, options2, cb2, startTime) {
18613
- return fs$readdir(path5, options2, fs$readdirCallback(
18614
- path5,
18612
+ } : function go$readdir2(path6, options2, cb2, startTime) {
18613
+ return fs$readdir(path6, options2, fs$readdirCallback(
18614
+ path6,
18615
18615
  options2,
18616
18616
  cb2,
18617
18617
  startTime
18618
18618
  ));
18619
18619
  };
18620
- return go$readdir(path4, options, cb);
18621
- function fs$readdirCallback(path5, options2, cb2, startTime) {
18620
+ return go$readdir(path5, options, cb);
18621
+ function fs$readdirCallback(path6, options2, cb2, startTime) {
18622
18622
  return function(err, files) {
18623
18623
  if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
18624
18624
  enqueue([
18625
18625
  go$readdir,
18626
- [path5, options2, cb2],
18626
+ [path6, options2, cb2],
18627
18627
  err,
18628
18628
  startTime || Date.now(),
18629
18629
  Date.now()
@@ -18694,7 +18694,7 @@ var require_graceful_fs = __commonJS({
18694
18694
  enumerable: true,
18695
18695
  configurable: true
18696
18696
  });
18697
- function ReadStream(path4, options) {
18697
+ function ReadStream(path5, options) {
18698
18698
  if (this instanceof ReadStream)
18699
18699
  return fs$ReadStream.apply(this, arguments), this;
18700
18700
  else
@@ -18714,7 +18714,7 @@ var require_graceful_fs = __commonJS({
18714
18714
  }
18715
18715
  });
18716
18716
  }
18717
- function WriteStream(path4, options) {
18717
+ function WriteStream(path5, options) {
18718
18718
  if (this instanceof WriteStream)
18719
18719
  return fs$WriteStream.apply(this, arguments), this;
18720
18720
  else
@@ -18732,22 +18732,22 @@ var require_graceful_fs = __commonJS({
18732
18732
  }
18733
18733
  });
18734
18734
  }
18735
- function createReadStream(path4, options) {
18736
- return new fs3.ReadStream(path4, options);
18735
+ function createReadStream(path5, options) {
18736
+ return new fs3.ReadStream(path5, options);
18737
18737
  }
18738
- function createWriteStream(path4, options) {
18739
- return new fs3.WriteStream(path4, options);
18738
+ function createWriteStream(path5, options) {
18739
+ return new fs3.WriteStream(path5, options);
18740
18740
  }
18741
18741
  var fs$open = fs3.open;
18742
18742
  fs3.open = open;
18743
- function open(path4, flags, mode, cb) {
18743
+ function open(path5, flags, mode, cb) {
18744
18744
  if (typeof mode === "function")
18745
18745
  cb = mode, mode = null;
18746
- return go$open(path4, flags, mode, cb);
18747
- function go$open(path5, flags2, mode2, cb2, startTime) {
18748
- return fs$open(path5, flags2, mode2, function(err, fd) {
18746
+ return go$open(path5, flags, mode, cb);
18747
+ function go$open(path6, flags2, mode2, cb2, startTime) {
18748
+ return fs$open(path6, flags2, mode2, function(err, fd) {
18749
18749
  if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
18750
- enqueue([go$open, [path5, flags2, mode2, cb2], err, startTime || Date.now(), Date.now()]);
18750
+ enqueue([go$open, [path6, flags2, mode2, cb2], err, startTime || Date.now(), Date.now()]);
18751
18751
  else {
18752
18752
  if (typeof cb2 === "function")
18753
18753
  cb2.apply(this, arguments);
@@ -18821,10 +18821,10 @@ var require_src2 = __commonJS({
18821
18821
  var fs_1 = require("fs");
18822
18822
  var debug_1 = __importDefault(require_src());
18823
18823
  var log = debug_1.default("@kwsites/file-exists");
18824
- function check(path4, isFile2, isDirectory) {
18825
- log(`checking %s`, path4);
18824
+ function check(path5, isFile2, isDirectory) {
18825
+ log(`checking %s`, path5);
18826
18826
  try {
18827
- const stat = fs_1.statSync(path4);
18827
+ const stat = fs_1.statSync(path5);
18828
18828
  if (stat.isFile() && isFile2) {
18829
18829
  log(`[OK] path represents a file`);
18830
18830
  return true;
@@ -18844,8 +18844,8 @@ var require_src2 = __commonJS({
18844
18844
  throw e;
18845
18845
  }
18846
18846
  }
18847
- function exists2(path4, type = exports2.READABLE) {
18848
- return check(path4, (type & exports2.FILE) > 0, (type & exports2.FOLDER) > 0);
18847
+ function exists2(path5, type = exports2.READABLE) {
18848
+ return check(path5, (type & exports2.FILE) > 0, (type & exports2.FOLDER) > 0);
18849
18849
  }
18850
18850
  exports2.exists = exists2;
18851
18851
  exports2.FILE = 1;
@@ -18915,7 +18915,7 @@ var require_package = __commonJS({
18915
18915
  "package.json"(exports2, module2) {
18916
18916
  module2.exports = {
18917
18917
  name: "braintrust",
18918
- version: "0.0.56",
18918
+ version: "0.0.57",
18919
18919
  description: "SDK for integrating Braintrust",
18920
18920
  main: "./dist/index.js",
18921
18921
  browser: {
@@ -18960,7 +18960,7 @@ var require_package = __commonJS({
18960
18960
  },
18961
18961
  dependencies: {
18962
18962
  argparse: "^2.0.1",
18963
- autoevals: "^0.0.24",
18963
+ autoevals: "^0.0.26",
18964
18964
  axios: "^1.4.0",
18965
18965
  chalk: "^4.1.2",
18966
18966
  "cli-progress": "^3.12.0",
@@ -18982,7 +18982,7 @@ var import_chalk = __toESM(require_source());
18982
18982
  var import_fs = __toESM(require("fs"));
18983
18983
  var import_os = __toESM(require("os"));
18984
18984
  var import_path = __toESM(require("path"));
18985
- var import_util3 = __toESM(require("util"));
18985
+ var import_util4 = __toESM(require("util"));
18986
18986
  var fsWalk = __toESM(require_out3());
18987
18987
 
18988
18988
  // node_modules/minimatch/dist/mjs/index.js
@@ -20810,10 +20810,10 @@ function isVisitable(thing) {
20810
20810
  function removeBrackets(key) {
20811
20811
  return utils_default.endsWith(key, "[]") ? key.slice(0, -2) : key;
20812
20812
  }
20813
- function renderKey(path4, key, dots) {
20814
- if (!path4)
20813
+ function renderKey(path5, key, dots) {
20814
+ if (!path5)
20815
20815
  return key;
20816
- return path4.concat(key).map(function each(token, i) {
20816
+ return path5.concat(key).map(function each(token, i) {
20817
20817
  token = removeBrackets(token);
20818
20818
  return !dots && i ? "[" + token + "]" : token;
20819
20819
  }).join(dots ? "." : "");
@@ -20859,9 +20859,9 @@ function toFormData(obj, formData, options) {
20859
20859
  }
20860
20860
  return value;
20861
20861
  }
20862
- function defaultVisitor(value, key, path4) {
20862
+ function defaultVisitor(value, key, path5) {
20863
20863
  let arr = value;
20864
- if (value && !path4 && typeof value === "object") {
20864
+ if (value && !path5 && typeof value === "object") {
20865
20865
  if (utils_default.endsWith(key, "{}")) {
20866
20866
  key = metaTokens ? key : key.slice(0, -2);
20867
20867
  value = JSON.stringify(value);
@@ -20880,7 +20880,7 @@ function toFormData(obj, formData, options) {
20880
20880
  if (isVisitable(value)) {
20881
20881
  return true;
20882
20882
  }
20883
- formData.append(renderKey(path4, key, dots), convertValue(value));
20883
+ formData.append(renderKey(path5, key, dots), convertValue(value));
20884
20884
  return false;
20885
20885
  }
20886
20886
  const stack = [];
@@ -20889,11 +20889,11 @@ function toFormData(obj, formData, options) {
20889
20889
  convertValue,
20890
20890
  isVisitable
20891
20891
  });
20892
- function build(value, path4) {
20892
+ function build(value, path5) {
20893
20893
  if (utils_default.isUndefined(value))
20894
20894
  return;
20895
20895
  if (stack.indexOf(value) !== -1) {
20896
- throw Error("Circular reference detected in " + path4.join("."));
20896
+ throw Error("Circular reference detected in " + path5.join("."));
20897
20897
  }
20898
20898
  stack.push(value);
20899
20899
  utils_default.forEach(value, function each(el, key) {
@@ -20901,11 +20901,11 @@ function toFormData(obj, formData, options) {
20901
20901
  formData,
20902
20902
  el,
20903
20903
  utils_default.isString(key) ? key.trim() : key,
20904
- path4,
20904
+ path5,
20905
20905
  exposedHelpers
20906
20906
  );
20907
20907
  if (result === true) {
20908
- build(el, path4 ? path4.concat(key) : [key]);
20908
+ build(el, path5 ? path5.concat(key) : [key]);
20909
20909
  }
20910
20910
  });
20911
20911
  stack.pop();
@@ -21066,7 +21066,7 @@ var node_default = {
21066
21066
  // node_modules/axios/lib/helpers/toURLEncodedForm.js
21067
21067
  function toURLEncodedForm(data, options) {
21068
21068
  return toFormData_default(data, new node_default.classes.URLSearchParams(), Object.assign({
21069
- visitor: function(value, key, path4, helpers) {
21069
+ visitor: function(value, key, path5, helpers) {
21070
21070
  if (node_default.isNode && utils_default.isBuffer(value)) {
21071
21071
  this.append(key, value.toString("base64"));
21072
21072
  return false;
@@ -21095,10 +21095,10 @@ function arrayToObject(arr) {
21095
21095
  return obj;
21096
21096
  }
21097
21097
  function formDataToJSON(formData) {
21098
- function buildPath(path4, value, target, index) {
21099
- let name = path4[index++];
21098
+ function buildPath(path5, value, target, index) {
21099
+ let name = path5[index++];
21100
21100
  const isNumericKey = Number.isFinite(+name);
21101
- const isLast = index >= path4.length;
21101
+ const isLast = index >= path5.length;
21102
21102
  name = !name && utils_default.isArray(target) ? target.length : name;
21103
21103
  if (isLast) {
21104
21104
  if (utils_default.hasOwnProp(target, name)) {
@@ -21111,7 +21111,7 @@ function formDataToJSON(formData) {
21111
21111
  if (!target[name] || !utils_default.isObject(target[name])) {
21112
21112
  target[name] = [];
21113
21113
  }
21114
- const result = buildPath(path4, value, target[name], index);
21114
+ const result = buildPath(path5, value, target[name], index);
21115
21115
  if (result && utils_default.isArray(target[name])) {
21116
21116
  target[name] = arrayToObject(target[name]);
21117
21117
  }
@@ -22210,9 +22210,9 @@ var http_default = isHttpAdapterSupported && function httpAdapter(config) {
22210
22210
  auth = urlUsername + ":" + urlPassword;
22211
22211
  }
22212
22212
  auth && headers.delete("authorization");
22213
- let path4;
22213
+ let path5;
22214
22214
  try {
22215
- path4 = buildURL(
22215
+ path5 = buildURL(
22216
22216
  parsed.pathname + parsed.search,
22217
22217
  config.params,
22218
22218
  config.paramsSerializer
@@ -22230,7 +22230,7 @@ var http_default = isHttpAdapterSupported && function httpAdapter(config) {
22230
22230
  false
22231
22231
  );
22232
22232
  const options = {
22233
- path: path4,
22233
+ path: path5,
22234
22234
  method,
22235
22235
  headers: headers.toJSON(),
22236
22236
  agents: { http: config.httpAgent, https: config.httpsAgent },
@@ -22453,14 +22453,14 @@ var cookies_default = node_default.isStandardBrowserEnv ? (
22453
22453
  // Standard browser envs support document.cookie
22454
22454
  function standardBrowserEnv() {
22455
22455
  return {
22456
- write: function write(name, value, expires, path4, domain, secure) {
22456
+ write: function write(name, value, expires, path5, domain, secure) {
22457
22457
  const cookie = [];
22458
22458
  cookie.push(name + "=" + encodeURIComponent(value));
22459
22459
  if (utils_default.isNumber(expires)) {
22460
22460
  cookie.push("expires=" + new Date(expires).toGMTString());
22461
22461
  }
22462
- if (utils_default.isString(path4)) {
22463
- cookie.push("path=" + path4);
22462
+ if (utils_default.isString(path5)) {
22463
+ cookie.push("path=" + path5);
22464
22464
  }
22465
22465
  if (utils_default.isString(domain)) {
22466
22466
  cookie.push("domain=" + domain);
@@ -23296,27 +23296,150 @@ var {
23296
23296
  } = axios_default;
23297
23297
 
23298
23298
  // src/isomorph.ts
23299
+ var DefaultAsyncLocalStorage = class {
23300
+ constructor() {
23301
+ }
23302
+ enterWith(_) {
23303
+ }
23304
+ run(_, callback) {
23305
+ return callback();
23306
+ }
23307
+ getStore() {
23308
+ return void 0;
23309
+ }
23310
+ };
23299
23311
  var iso = {
23300
23312
  makeAxios: (conf) => axios_default.create({
23301
23313
  ...conf
23302
23314
  }),
23303
23315
  getRepoStatus: async () => void 0,
23304
23316
  getPastNAncestors: async () => [],
23305
- getEnv: (_name) => void 0
23317
+ getEnv: (_name) => void 0,
23318
+ getCallerLocation: () => void 0,
23319
+ newAsyncLocalStorage: () => new DefaultAsyncLocalStorage()
23306
23320
  };
23307
23321
  var isomorph_default = iso;
23308
23322
 
23323
+ // src/util.ts
23324
+ function runFinally(f, finallyF) {
23325
+ let runSyncCleanup = true;
23326
+ try {
23327
+ const ret = f();
23328
+ if (ret instanceof Promise) {
23329
+ runSyncCleanup = false;
23330
+ return ret.finally(finallyF);
23331
+ } else {
23332
+ return ret;
23333
+ }
23334
+ } finally {
23335
+ if (runSyncCleanup) {
23336
+ finallyF();
23337
+ }
23338
+ }
23339
+ }
23340
+
23309
23341
  // src/logger.ts
23310
- var _state = {
23311
- current_project: null,
23312
- current_experiment: null
23342
+ var NoopSpan = class {
23343
+ constructor() {
23344
+ this.kind = "span";
23345
+ this.id = "";
23346
+ this.span_id = "";
23347
+ this.root_span_id = "";
23348
+ }
23349
+ log(_) {
23350
+ }
23351
+ startSpan(_0, _1) {
23352
+ return this;
23353
+ }
23354
+ traced(_0, callback, _1) {
23355
+ return callback(this);
23356
+ }
23357
+ end(args) {
23358
+ return args?.endTime ?? getCurrentUnixTimestamp();
23359
+ }
23360
+ close(args) {
23361
+ return this.end(args);
23362
+ }
23313
23363
  };
23314
- var API_URL = null;
23315
- var LOGIN_TOKEN = null;
23316
- var ORG_ID = null;
23317
- var ORG_NAME = null;
23318
- var LOG_URL = null;
23319
- var LOGGED_IN = false;
23364
+ var noopSpan = new NoopSpan();
23365
+ var BraintrustState = class {
23366
+ constructor() {
23367
+ this.id = v4_default();
23368
+ this.currentExperiment = isomorph_default.newAsyncLocalStorage();
23369
+ this.currentSpan = isomorph_default.newAsyncLocalStorage();
23370
+ this.apiUrl = null;
23371
+ this.loginToken = null;
23372
+ this.orgId = null;
23373
+ this.orgName = null;
23374
+ this.logUrl = null;
23375
+ this.loggedIn = false;
23376
+ this._apiConn = null;
23377
+ this._logConn = null;
23378
+ this._userInfo = null;
23379
+ globalThis.__inherited_braintrust_state = this;
23380
+ }
23381
+ apiConn() {
23382
+ if (!this._apiConn) {
23383
+ if (!this.apiUrl) {
23384
+ throw new Error("Must initialize apiUrl before requesting apiConn");
23385
+ }
23386
+ this._apiConn = new HTTPConnection(this.apiUrl);
23387
+ }
23388
+ return this._apiConn;
23389
+ }
23390
+ logConn() {
23391
+ if (!this._logConn) {
23392
+ if (!this.logUrl) {
23393
+ throw new Error("Must initialize logUrl before requesting logConn");
23394
+ }
23395
+ this._logConn = new HTTPConnection(this.logUrl);
23396
+ }
23397
+ return this._logConn;
23398
+ }
23399
+ async userInfo() {
23400
+ if (!this._userInfo) {
23401
+ this._userInfo = await this.logConn().get_json("ping");
23402
+ }
23403
+ return this._userInfo;
23404
+ }
23405
+ setUserInfoIfNull(info) {
23406
+ if (!this._userInfo) {
23407
+ this._userInfo = info;
23408
+ }
23409
+ }
23410
+ };
23411
+ var _state = globalThis.__inherited_braintrust_state || new BraintrustState();
23412
+ var _internalGetGlobalState = () => _state;
23413
+ var UnterminatedObjectsHandler = class {
23414
+ constructor() {
23415
+ this.unterminatedObjects = /* @__PURE__ */ new Map();
23416
+ process.on("exit", () => {
23417
+ this.warnUnterminated();
23418
+ });
23419
+ }
23420
+ addUnterminated(obj, createdLocation) {
23421
+ this.unterminatedObjects.set(obj, createdLocation);
23422
+ }
23423
+ removeUnterminated(obj) {
23424
+ this.unterminatedObjects.delete(obj);
23425
+ }
23426
+ warnUnterminated() {
23427
+ if (this.unterminatedObjects.size === 0) {
23428
+ return;
23429
+ }
23430
+ let warningMessage = "WARNING: Did not close the following braintrust objects. We recommend running `.close` on the listed objects, or by running them inside a callback so they are closed automatically:";
23431
+ this.unterminatedObjects.forEach((createdLocation, obj) => {
23432
+ let msg = `
23433
+ Object of type ${obj?.constructor?.name}`;
23434
+ if (createdLocation) {
23435
+ msg += ` created at ${JSON.stringify(createdLocation)}`;
23436
+ }
23437
+ warningMessage += msg;
23438
+ });
23439
+ console.warn(warningMessage);
23440
+ }
23441
+ };
23442
+ var unterminatedObjects = new UnterminatedObjectsHandler();
23320
23443
  var TRANSACTION_ID_FIELD = "_xact_id";
23321
23444
  var HTTPConnection = class _HTTPConnection {
23322
23445
  constructor(base_url) {
@@ -23328,9 +23451,7 @@ var HTTPConnection = class _HTTPConnection {
23328
23451
  async ping() {
23329
23452
  try {
23330
23453
  const resp = await this.get("ping");
23331
- if (_var_user_info === null) {
23332
- _var_user_info = resp.data;
23333
- }
23454
+ _state.setUserInfoIfNull(resp.data);
23334
23455
  return resp.status === 200;
23335
23456
  } catch (e) {
23336
23457
  return false;
@@ -23355,12 +23476,12 @@ var HTTPConnection = class _HTTPConnection {
23355
23476
  }
23356
23477
  this.session = isomorph_default.makeAxios({ headers });
23357
23478
  }
23358
- async get(path4, params = void 0) {
23359
- return await this.session.get(_urljoin(this.base_url, path4), { params });
23479
+ async get(path5, params = void 0) {
23480
+ return await this.session.get(_urljoin(this.base_url, path5), { params });
23360
23481
  }
23361
- async post(path4, params = void 0, config = void 0) {
23482
+ async post(path5, params = void 0, config = void 0) {
23362
23483
  return await this.session.post(
23363
- _urljoin(this.base_url, path4),
23484
+ _urljoin(this.base_url, path5),
23364
23485
  params,
23365
23486
  config
23366
23487
  );
@@ -23390,32 +23511,6 @@ var HTTPConnection = class _HTTPConnection {
23390
23511
  return resp.data;
23391
23512
  }
23392
23513
  };
23393
- var _api_conn = null;
23394
- function api_conn() {
23395
- if (!_api_conn) {
23396
- _api_conn = new HTTPConnection(API_URL);
23397
- }
23398
- return _api_conn;
23399
- }
23400
- var _log_conn = null;
23401
- function log_conn() {
23402
- if (!_log_conn) {
23403
- _log_conn = new HTTPConnection(LOG_URL);
23404
- }
23405
- return _log_conn;
23406
- }
23407
- var _var_user_info = null;
23408
- async function _user_info() {
23409
- if (_var_user_info === null) {
23410
- _var_user_info = await log_conn().get_json("ping");
23411
- }
23412
- return _var_user_info;
23413
- }
23414
- function clear_cached_globals() {
23415
- _api_conn = null;
23416
- _log_conn = null;
23417
- _var_user_info = null;
23418
- }
23419
23514
  var MaxRequestSize = 10 * 1024 * 1024;
23420
23515
  function constructJsonArray(items) {
23421
23516
  return `[${items.join(",")}]`;
@@ -23453,10 +23548,7 @@ var LogThread = class {
23453
23548
  itemsLen += itemS.length;
23454
23549
  }
23455
23550
  if (items.length > 0) {
23456
- const resp = await log_conn().post_json(
23457
- "logs",
23458
- constructJsonArray(items)
23459
- );
23551
+ const resp = await _state.logConn().post_json("logs", constructJsonArray(items));
23460
23552
  ret = resp.data;
23461
23553
  } else {
23462
23554
  break;
@@ -23497,7 +23589,7 @@ async function init(project, options = {}) {
23497
23589
  apiKey,
23498
23590
  apiUrl
23499
23591
  });
23500
- const ret = await _initExperiment(project, {
23592
+ return await _initExperiment(project, {
23501
23593
  experimentName: experiment,
23502
23594
  description,
23503
23595
  dataset,
@@ -23505,8 +23597,6 @@ async function init(project, options = {}) {
23505
23597
  baseExperiment,
23506
23598
  isPublic
23507
23599
  });
23508
- _state.current_experiment = ret;
23509
- return ret;
23510
23600
  }
23511
23601
  async function login(options = {}) {
23512
23602
  const {
@@ -23516,24 +23606,27 @@ async function login(options = {}) {
23516
23606
  disableCache = false
23517
23607
  } = options || {};
23518
23608
  let { forceLogin = false } = options || {};
23519
- if (apiUrl != API_URL || apiKey !== void 0 && HTTPConnection.sanitize_token(apiKey) != LOGIN_TOKEN || orgName !== void 0 && orgName != ORG_NAME) {
23609
+ if (apiUrl != _state.apiUrl || apiKey !== void 0 && HTTPConnection.sanitize_token(apiKey) != _state.loginToken || orgName !== void 0 && orgName != _state.orgName) {
23520
23610
  forceLogin = true;
23521
23611
  }
23522
- if (LOGGED_IN && !forceLogin) {
23612
+ if (_state.loggedIn && !forceLogin) {
23523
23613
  return;
23524
23614
  }
23525
- clear_cached_globals();
23526
- API_URL = apiUrl;
23615
+ _state = new BraintrustState();
23616
+ _state.apiUrl = apiUrl;
23527
23617
  let login_key_info = null;
23528
23618
  let ping_ok = false;
23529
23619
  let conn = null;
23530
23620
  if (apiKey !== void 0) {
23531
- const resp = await axios_default.post(_urljoin(API_URL, `/api/apikey/login`), {
23532
- token: apiKey
23533
- });
23621
+ const resp = await axios_default.post(
23622
+ _urljoin(_state.apiUrl, `/api/apikey/login`),
23623
+ {
23624
+ token: apiKey
23625
+ }
23626
+ );
23534
23627
  const info = resp.data;
23535
23628
  _check_org_info(info.org_info, orgName);
23536
- conn = log_conn();
23629
+ conn = _state.logConn();
23537
23630
  conn.set_token(apiKey);
23538
23631
  ping_ok = await conn.ping();
23539
23632
  } else {
@@ -23548,9 +23641,52 @@ async function login(options = {}) {
23548
23641
  await conn.get("ping");
23549
23642
  }
23550
23643
  conn.make_long_lived();
23551
- api_conn().set_token(apiKey);
23552
- LOGIN_TOKEN = conn.token;
23553
- LOGGED_IN = true;
23644
+ _state.apiConn().set_token(apiKey);
23645
+ _state.loginToken = conn.token;
23646
+ _state.loggedIn = true;
23647
+ }
23648
+ function currentExperiment() {
23649
+ return _state.currentExperiment.getStore();
23650
+ }
23651
+ function currentSpan() {
23652
+ return _state.currentSpan.getStore();
23653
+ }
23654
+ function startSpan(args) {
23655
+ const { name: nameOpt, ...argsRest } = args ?? {};
23656
+ const name = (nameOpt ?? isomorph_default.getCallerLocation()?.caller_functionname) || "root";
23657
+ const parentSpan = currentSpan();
23658
+ if (!Object.is(parentSpan, noopSpan)) {
23659
+ return parentSpan.startSpan(name, argsRest);
23660
+ }
23661
+ const experiment = currentExperiment();
23662
+ if (experiment) {
23663
+ return experiment.startSpan({ name, ...argsRest });
23664
+ }
23665
+ return noopSpan;
23666
+ }
23667
+ function traced(callback, args) {
23668
+ const span = startSpan(args);
23669
+ return runFinally(
23670
+ () => {
23671
+ if (args?.setCurrent ?? true) {
23672
+ return withCurrent(span, () => callback(span));
23673
+ } else {
23674
+ return callback(span);
23675
+ }
23676
+ },
23677
+ () => span.end()
23678
+ );
23679
+ }
23680
+ function withCurrent(object, callback) {
23681
+ if (object.kind === "experiment") {
23682
+ return _state.currentExperiment.run(object, callback);
23683
+ } else if (object.kind === "span") {
23684
+ return _state.currentSpan.run(object, callback);
23685
+ } else {
23686
+ throw new Error(
23687
+ `Invalid object of type ${object.constructor.name}`
23688
+ );
23689
+ }
23554
23690
  }
23555
23691
  function _check_org_info(org_info, org_name) {
23556
23692
  if (org_info.length === 0) {
@@ -23558,13 +23694,13 @@ function _check_org_info(org_info, org_name) {
23558
23694
  }
23559
23695
  for (const org of org_info) {
23560
23696
  if (org_name === void 0 || org.name === org_name) {
23561
- ORG_ID = org.id;
23562
- ORG_NAME = org.name;
23563
- LOG_URL = org.api_url;
23697
+ _state.orgId = org.id;
23698
+ _state.orgName = org.name;
23699
+ _state.logUrl = org.api_url;
23564
23700
  break;
23565
23701
  }
23566
23702
  }
23567
- if (ORG_ID === void 0) {
23703
+ if (_state.orgId === void 0) {
23568
23704
  throw new Error(
23569
23705
  `Organization ${org_name} not found. Must be one of ${org_info.map((x) => x.name).join(", ")}`
23570
23706
  );
@@ -23573,6 +23709,82 @@ function _check_org_info(org_info, org_name) {
23573
23709
  function _urljoin(...parts) {
23574
23710
  return parts.map((x) => x.replace(/^\//, "")).join("/");
23575
23711
  }
23712
+ function getCurrentUnixTimestamp() {
23713
+ return (/* @__PURE__ */ new Date()).getTime() / 1e3;
23714
+ }
23715
+ function validateAndSanitizeExperimentLogPartialArgs(event) {
23716
+ if (event.scores) {
23717
+ for (let [name, score] of Object.entries(event.scores)) {
23718
+ if (typeof name !== "string") {
23719
+ throw new Error("score names must be strings");
23720
+ }
23721
+ if (typeof score === "boolean") {
23722
+ score = score ? 1 : 0;
23723
+ event.scores[name] = score;
23724
+ }
23725
+ if (typeof score !== "number") {
23726
+ throw new Error("score values must be numbers");
23727
+ }
23728
+ if (score < 0 || score > 1) {
23729
+ throw new Error("score values must be between 0 and 1");
23730
+ }
23731
+ }
23732
+ }
23733
+ if (event.metadata) {
23734
+ for (const key of Object.keys(event.metadata)) {
23735
+ if (typeof key !== "string") {
23736
+ throw new Error("metadata keys must be strings");
23737
+ }
23738
+ }
23739
+ }
23740
+ if (event.metrics) {
23741
+ for (const key of Object.keys(event.metrics)) {
23742
+ if (typeof key !== "string") {
23743
+ throw new Error("metric keys must be strings");
23744
+ }
23745
+ }
23746
+ for (const forbiddenKey of [
23747
+ "start",
23748
+ "end",
23749
+ "caller_functionname",
23750
+ "caller_filename",
23751
+ "caller_lineno"
23752
+ ]) {
23753
+ if (forbiddenKey in event.metrics) {
23754
+ throw new Error(`Key ${forbiddenKey} may not be specified in metrics`);
23755
+ }
23756
+ }
23757
+ }
23758
+ if ("input" in event && event.input && "inputs" in event && event.inputs) {
23759
+ throw new Error(
23760
+ "Only one of input or inputs (deprecated) can be specified. Prefer input."
23761
+ );
23762
+ }
23763
+ if ("inputs" in event) {
23764
+ const { inputs, ...rest } = event;
23765
+ return { input: inputs, ...rest };
23766
+ } else {
23767
+ return { ...event };
23768
+ }
23769
+ }
23770
+ function validateAndSanitizeExperimentLogFullArgs(event, hasDataset) {
23771
+ if ("input" in event && event.input && "inputs" in event && event.inputs || !("input" in event) && !("inputs" in event)) {
23772
+ throw new Error(
23773
+ "Exactly one of input or inputs (deprecated) must be specified. Prefer input."
23774
+ );
23775
+ }
23776
+ if (!event.scores) {
23777
+ throw new Error("scores must be specified");
23778
+ }
23779
+ if (hasDataset && event.datasetRecordId === void 0) {
23780
+ throw new Error("datasetRecordId must be specified when using a dataset");
23781
+ } else if (!hasDataset && event.datasetRecordId !== void 0) {
23782
+ throw new Error(
23783
+ "datasetRecordId cannot be specified when not using a dataset"
23784
+ );
23785
+ }
23786
+ return event;
23787
+ }
23576
23788
  async function _initExperiment(projectName, {
23577
23789
  experimentName,
23578
23790
  description,
@@ -23588,7 +23800,7 @@ async function _initExperiment(projectName, {
23588
23800
  }) {
23589
23801
  const args = {
23590
23802
  project_name: projectName,
23591
- org_id: ORG_ID
23803
+ org_id: _state.orgId
23592
23804
  };
23593
23805
  if (experimentName) {
23594
23806
  args["experiment_name"] = experimentName;
@@ -23615,10 +23827,10 @@ async function _initExperiment(projectName, {
23615
23827
  if (isPublic !== void 0) {
23616
23828
  args["public"] = isPublic;
23617
23829
  }
23618
- const response = await api_conn().post_json("api/experiment/register", args);
23830
+ const response = await _state.apiConn().post_json("api/experiment/register", args);
23619
23831
  const project = response.project;
23620
23832
  const experiment = response.experiment;
23621
- const user_id = (await _user_info())["id"];
23833
+ const user_id = (await _state.userInfo())["id"];
23622
23834
  return new Experiment(
23623
23835
  project,
23624
23836
  experiment.id,
@@ -23629,106 +23841,71 @@ async function _initExperiment(projectName, {
23629
23841
  }
23630
23842
  var Experiment = class {
23631
23843
  constructor(project, id, name, user_id, dataset) {
23844
+ // For type identification.
23845
+ this.kind = "experiment";
23846
+ this.finished = false;
23632
23847
  this.project = project;
23633
23848
  this.id = id;
23634
23849
  this.name = name;
23635
23850
  this.user_id = user_id;
23636
23851
  this.dataset = dataset;
23637
23852
  this.logger = new LogThread();
23853
+ this.lastStartTime = getCurrentUnixTimestamp();
23854
+ unterminatedObjects.addUnterminated(this, isomorph_default.getCallerLocation());
23638
23855
  }
23639
23856
  /**
23640
23857
  * Log a single event to the experiment. The event will be batched and uploaded behind the scenes.
23641
23858
  *
23642
23859
  * @param event The event to log.
23643
- * @param event.input The arguments that uniquely define a test case (an arbitrary, JSON serializable object). Later on,
23644
- * Braintrust will use the `input` to know whether two test cases are the same between experiments, so they should
23645
- * not contain experiment-specific state. A simple rule of thumb is that if you run the same experiment twice, the
23646
- * `input` should be identical.
23647
- * @param event.output The output of your application, including post-processing (an arbitrary, JSON serializable object),
23648
- * that allows you to determine whether the result is correct or not. For example, in an app that generates SQL queries,
23649
- * the `output` should be the _result_ of the SQL query generated by the model, not the query itself, because there may
23650
- * be multiple valid queries that answer a single question.
23651
- * @param event.expected The ground truth value (an arbitrary, JSON serializable object) that you'd compare to `output` to
23652
- * determine if your `output` value is correct or not. Braintrust currently does not compare `output` to `expected` for
23653
- * you, since there are so many different ways to do that correctly. Instead, these values are just used to help you
23654
- * navigate your experiments while digging into analyses. However, we may later use these values to re-score outputs or
23655
- * fine-tune your models.
23656
- * @param event.scores A dictionary of numeric values (between 0 and 1) to log. The scores should give you a variety of signals
23657
- * that help you determine how accurate the outputs are compared to what you expect and diagnose failures. For example, a
23658
- * summarization app might have one score that tells you how accurate the summary is, and another that measures the word similarity
23659
- * between the generated and grouth truth summary. The word similarity score could help you determine whether the summarization was
23660
- * covering similar concepts or not. You can use these scores to help you sort, filter, and compare experiments.
23661
- * @param event.metadata (Optional) a dictionary with additional data about the test example, model outputs, or just
23662
- * about anything else that's relevant, that you can use to help find and analyze examples later. For example, you could log the
23663
- * `prompt`, example's `id`, or anything else that would be useful to slice/dice later. The values in `metadata` can be any
23664
- * JSON-serializable type, but its keys must be strings.
23665
- * @param event.id (Optional) a unique identifier for the event. If you don't provide one, Braintrust will generate one for you.
23666
- * @param event.inputs (Deprecated) the same as `input` (will be removed in a future version)
23667
- * @returns The `id` of the logged event.
23860
+ * @param event.input: The arguments that uniquely define a test case (an arbitrary, JSON serializable object). Later on, Braintrust will use the `input` to know whether two test cases are the same between experiments, so they should not contain experiment-specific state. A simple rule of thumb is that if you run the same experiment twice, the `input` should be identical.
23861
+ * @param event.output: The output of your application, including post-processing (an arbitrary, JSON serializable object), that allows you to determine whether the result is correct or not. For example, in an app that generates SQL queries, the `output` should be the _result_ of the SQL query generated by the model, not the query itself, because there may be multiple valid queries that answer a single question.
23862
+ * @param event.expected: The ground truth value (an arbitrary, JSON serializable object) that you'd compare to `output` to determine if your `output` value is correct or not. Braintrust currently does not compare `output` to `expected` for you, since there are so many different ways to do that correctly. Instead, these values are just used to help you navigate your experiments while digging into analyses. However, we may later use these values to re-score outputs or fine-tune your models.
23863
+ * @param event.scores: A dictionary of numeric values (between 0 and 1) to log. The scores should give you a variety of signals that help you determine how accurate the outputs are compared to what you expect and diagnose failures. For example, a summarization app might have one score that tells you how accurate the summary is, and another that measures the word similarity between the generated and grouth truth summary. The word similarity score could help you determine whether the summarization was covering similar concepts or not. You can use these scores to help you sort, filter, and compare experiments.
23864
+ * @param event.metadata: (Optional) a dictionary with additional data about the test example, model outputs, or just about anything else that's relevant, that you can use to help find and analyze examples later. For example, you could log the `prompt`, example's `id`, or anything else that would be useful to slice/dice later. The values in `metadata` can be any JSON-serializable type, but its keys must be strings.
23865
+ * @param event.metrics: (Optional) a dictionary of metrics to log. The following keys are populated automatically and should not be specified: "start", "end", "caller_functionname", "caller_filename", "caller_lineno".
23866
+ * @param event.id: (Optional) a unique identifier for the event. If you don't provide one, BrainTrust will generate one for you.
23867
+ * @param event.dataset_record_id: (Optional) the id of the dataset record that this event is associated with. This field is required if and only if the experiment is associated with a dataset.
23868
+ * @param event.inputs: (Deprecated) the same as `input` (will be removed in a future version).
23869
+ * :returns: The `id` of the logged event.
23668
23870
  */
23669
- log({
23670
- input,
23671
- output,
23672
- expected,
23673
- scores,
23674
- metadata,
23675
- id,
23676
- datasetRecordId,
23677
- inputs
23678
- }) {
23679
- if (input === void 0 && inputs === void 0) {
23680
- throw new Error(
23681
- "Either input or inputs (deprecated) must be specified. Prefer input."
23682
- );
23683
- } else if (input !== void 0 && inputs !== void 0) {
23684
- throw new Error(
23685
- "Only one of input or inputs (deprecated) can be specified. Prefer input."
23686
- );
23687
- }
23688
- for (let [name, score] of Object.entries(scores)) {
23689
- if (typeof name !== "string") {
23690
- throw new Error("score names must be strings");
23691
- }
23692
- if (typeof score === "boolean") {
23693
- score = score ? 1 : 0;
23694
- scores[name] = score;
23695
- }
23696
- if (typeof score !== "number") {
23697
- throw new Error("score values must be numbers");
23698
- }
23699
- if (score < 0 || score > 1) {
23700
- throw new Error("score values must be between 0 and 1");
23701
- }
23702
- }
23703
- if (metadata !== void 0) {
23704
- for (const key of Object.keys(metadata)) {
23705
- if (typeof key !== "string") {
23706
- throw new Error("metadata keys must be strings");
23871
+ log(event) {
23872
+ this.checkNotFinished();
23873
+ event = validateAndSanitizeExperimentLogFullArgs(event, !!this.dataset);
23874
+ const span = this.startSpan({ startTime: this.lastStartTime, event });
23875
+ this.lastStartTime = span.end();
23876
+ return span.id;
23877
+ }
23878
+ /**
23879
+ * Create a new toplevel span. The name parameter is optional and defaults to "root".
23880
+ *
23881
+ * See `Span.startSpan` for full details.
23882
+ */
23883
+ startSpan(args) {
23884
+ this.checkNotFinished();
23885
+ const { name, ...argsRest } = args ?? {};
23886
+ return new SpanImpl({
23887
+ experimentLogger: this.logger,
23888
+ name: name ?? "root",
23889
+ ...argsRest,
23890
+ rootExperiment: this
23891
+ });
23892
+ }
23893
+ /**
23894
+ * Wrapper over `Experiment.startSpan`, which passes the initialized `Span` it to the given callback and ends it afterwards. See `Span.traced` for full details.
23895
+ */
23896
+ traced(callback, args) {
23897
+ const { setCurrent, ...argsRest } = args ?? {};
23898
+ const span = this.startSpan(argsRest);
23899
+ return runFinally(
23900
+ () => {
23901
+ if (setCurrent ?? true) {
23902
+ return withCurrent(span, () => callback(span));
23903
+ } else {
23904
+ return callback(span);
23707
23905
  }
23708
- }
23709
- }
23710
- if (this.dataset && datasetRecordId === void 0) {
23711
- throw new Error("datasetRecordId must be specified when using a dataset");
23712
- } else if (!this.dataset && datasetRecordId !== void 0) {
23713
- throw new Error(
23714
- "datasetRecordId cannot be specified when not using a dataset"
23715
- );
23716
- }
23717
- const args = {
23718
- id: id || v4_default(),
23719
- inputs: input ?? inputs,
23720
- output,
23721
- expected,
23722
- scores,
23723
- project_id: this.project.id,
23724
- experiment_id: this.id,
23725
- user_id: this.user_id,
23726
- created: (/* @__PURE__ */ new Date()).toISOString(),
23727
- dataset_record_id: datasetRecordId,
23728
- metadata
23729
- };
23730
- this.logger.log([args]);
23731
- return args.id;
23906
+ },
23907
+ () => span.end()
23908
+ );
23732
23909
  }
23733
23910
  /**
23734
23911
  * Summarize the experiment, including the scores (compared to the closest reference experiment) and metadata.
@@ -23741,15 +23918,15 @@ var Experiment = class {
23741
23918
  async summarize(options = {}) {
23742
23919
  let { summarizeScores = true, comparisonExperimentId = void 0 } = options || {};
23743
23920
  await this.logger.flush();
23744
- const projectUrl = `${API_URL}/app/${encodeURIComponent(
23745
- ORG_NAME
23921
+ const projectUrl = `${_state.apiUrl}/app/${encodeURIComponent(
23922
+ _state.orgName
23746
23923
  )}/p/${encodeURIComponent(this.project.name)}`;
23747
23924
  const experimentUrl = `${projectUrl}/${encodeURIComponent(this.name)}`;
23748
23925
  let scores = void 0;
23749
23926
  let comparisonExperimentName = void 0;
23750
23927
  if (summarizeScores) {
23751
23928
  if (comparisonExperimentId === void 0) {
23752
- const conn = log_conn();
23929
+ const conn = _state.logConn();
23753
23930
  const resp = await conn.get("/crud/base_experiments", {
23754
23931
  id: this.id
23755
23932
  });
@@ -23760,7 +23937,7 @@ var Experiment = class {
23760
23937
  }
23761
23938
  }
23762
23939
  if (comparisonExperimentId !== void 0) {
23763
- scores = await log_conn().get_json(
23940
+ scores = await _state.logConn().get_json(
23764
23941
  "/experiment-comparison",
23765
23942
  {
23766
23943
  experiment_id: this.id,
@@ -23779,16 +23956,134 @@ var Experiment = class {
23779
23956
  scores
23780
23957
  };
23781
23958
  }
23959
+ /**
23960
+ * Finish the experiment and return its id. After calling close, you may not invoke any further methods on the experiment object.
23961
+ *
23962
+ * Will be invoked automatically if the experiment is wrapped in a callback passed to `braintrust.withExperiment`.
23963
+ *
23964
+ * @returns The experiment id.
23965
+ */
23966
+ async close() {
23967
+ this.checkNotFinished();
23968
+ await this.logger.flush();
23969
+ this.finished = true;
23970
+ unterminatedObjects.removeUnterminated(this);
23971
+ return this.id;
23972
+ }
23973
+ checkNotFinished() {
23974
+ if (this.finished) {
23975
+ throw new Error("Cannot invoke method on finished experiment");
23976
+ }
23977
+ }
23978
+ };
23979
+ var SpanImpl = class _SpanImpl {
23980
+ // root_experiment should only be specified for a root span. parent_span
23981
+ // should only be specified for non-root spans.
23982
+ constructor(args) {
23983
+ this.kind = "span";
23984
+ this.finished = false;
23985
+ this.experimentLogger = args.experimentLogger;
23986
+ const callerLocation = isomorph_default.getCallerLocation();
23987
+ this.internalData = {
23988
+ metrics: {
23989
+ start: args.startTime ?? getCurrentUnixTimestamp(),
23990
+ ...callerLocation
23991
+ },
23992
+ span_attributes: { ...args.spanAttributes, name: args.name }
23993
+ };
23994
+ this.id = args.event?.id ?? v4_default();
23995
+ this.span_id = v4_default();
23996
+ if ("rootExperiment" in args) {
23997
+ this.root_span_id = this.span_id;
23998
+ this._project_id = args.rootExperiment.project.id;
23999
+ this._experiment_id = args.rootExperiment.id;
24000
+ this.internalData = Object.assign(this.internalData, {
24001
+ // TODO: Hopefully we can remove this.
24002
+ user_id: args.rootExperiment.user_id,
24003
+ created: (/* @__PURE__ */ new Date()).toISOString()
24004
+ });
24005
+ } else if ("parentSpan" in args) {
24006
+ this.root_span_id = args.parentSpan.root_span_id;
24007
+ this._project_id = args.parentSpan._project_id;
24008
+ this._experiment_id = args.parentSpan._experiment_id;
24009
+ this.internalData.span_parents = [args.parentSpan.span_id];
24010
+ } else {
24011
+ throw new Error("Must provide either 'rootExperiment' or 'parentSpan'");
24012
+ }
24013
+ this.isMerge = false;
24014
+ const { id, ...eventRest } = args.event ?? {};
24015
+ this.log(eventRest);
24016
+ this.isMerge = true;
24017
+ unterminatedObjects.addUnterminated(this, callerLocation);
24018
+ }
24019
+ log(event) {
24020
+ this.checkNotFinished();
24021
+ const sanitized = validateAndSanitizeExperimentLogPartialArgs(event);
24022
+ const record = {
24023
+ ...sanitized,
24024
+ ...this.internalData,
24025
+ id: this.id,
24026
+ span_id: this.span_id,
24027
+ root_span_id: this.root_span_id,
24028
+ project_id: this._project_id,
24029
+ experiment_id: this._experiment_id,
24030
+ _is_merge: this.isMerge
24031
+ };
24032
+ this.internalData = {};
24033
+ this.experimentLogger.log([record]);
24034
+ }
24035
+ startSpan(name, args) {
24036
+ this.checkNotFinished();
24037
+ return new _SpanImpl({
24038
+ experimentLogger: this.experimentLogger,
24039
+ name,
24040
+ ...args,
24041
+ parentSpan: this
24042
+ });
24043
+ }
24044
+ traced(name, callback, args) {
24045
+ const { setCurrent, ...argsRest } = args ?? {};
24046
+ const span = this.startSpan(name, argsRest);
24047
+ return runFinally(
24048
+ () => {
24049
+ if (setCurrent ?? true) {
24050
+ return withCurrent(span, () => callback(span));
24051
+ } else {
24052
+ return callback(span);
24053
+ }
24054
+ },
24055
+ () => span.end()
24056
+ );
24057
+ }
24058
+ end(args) {
24059
+ this.checkNotFinished();
24060
+ const endTime = args?.endTime ?? getCurrentUnixTimestamp();
24061
+ this.internalData = { metrics: { end: endTime } };
24062
+ this.log({});
24063
+ this.finished = true;
24064
+ unterminatedObjects.removeUnterminated(this);
24065
+ return endTime;
24066
+ }
24067
+ close(args) {
24068
+ return this.end(args);
24069
+ }
24070
+ checkNotFinished() {
24071
+ if (this.finished) {
24072
+ throw new Error("Cannot invoke method on finished span");
24073
+ }
24074
+ }
23782
24075
  };
23783
24076
  var Dataset = class {
23784
24077
  constructor(project, id, name, user_id, pinnedVersion) {
23785
24078
  this._fetchedData = void 0;
24079
+ this.finished = false;
23786
24080
  this.project = project;
23787
24081
  this.id = id;
23788
24082
  this.name = name;
23789
24083
  this.user_id = user_id;
23790
24084
  this.pinnedVersion = pinnedVersion;
23791
24085
  this.logger = new LogThread();
24086
+ unterminatedObjects.addUnterminated(this, isomorph_default.getCallerLocation());
23792
24087
  }
23793
24088
  /**
23794
24089
  * Insert a single record to the dataset. The record will be batched and uploaded behind the scenes. If you pass in an `id`,
@@ -23810,6 +24105,7 @@ var Dataset = class {
23810
24105
  metadata,
23811
24106
  id
23812
24107
  }) {
24108
+ this.checkNotFinished();
23813
24109
  if (metadata !== void 0) {
23814
24110
  for (const key of Object.keys(metadata)) {
23815
24111
  if (typeof key !== "string") {
@@ -23831,6 +24127,7 @@ var Dataset = class {
23831
24127
  return args.id;
23832
24128
  }
23833
24129
  delete(id) {
24130
+ this.checkNotFinished();
23834
24131
  const user_id = this.user_id;
23835
24132
  const args = {
23836
24133
  id,
@@ -23850,15 +24147,16 @@ var Dataset = class {
23850
24147
  * @returns A summary of the dataset.
23851
24148
  */
23852
24149
  async summarize(options = {}) {
24150
+ this.checkNotFinished();
23853
24151
  let { summarizeData = true } = options || {};
23854
24152
  await this.logger.flush();
23855
- const projectUrl = `${API_URL}/app/${encodeURIComponent(
23856
- ORG_NAME
24153
+ const projectUrl = `${_state.apiUrl}/app/${encodeURIComponent(
24154
+ _state.orgName
23857
24155
  )}/p/${encodeURIComponent(this.project.name)}`;
23858
24156
  const datasetUrl = `${projectUrl}/d/${encodeURIComponent(this.name)}`;
23859
24157
  let dataSummary = void 0;
23860
24158
  if (summarizeData) {
23861
- dataSummary = await log_conn().get_json(
24159
+ dataSummary = await _state.logConn().get_json(
23862
24160
  "dataset-summary",
23863
24161
  {
23864
24162
  dataset_id: this.id
@@ -23893,6 +24191,7 @@ var Dataset = class {
23893
24191
  * @returns An iterator over the dataset's records.
23894
24192
  */
23895
24193
  async *fetch() {
24194
+ this.checkNotFinished();
23896
24195
  const records = await this.fetchedData();
23897
24196
  for (const record of records) {
23898
24197
  yield {
@@ -23916,11 +24215,13 @@ var Dataset = class {
23916
24215
  * ```
23917
24216
  */
23918
24217
  [Symbol.asyncIterator]() {
24218
+ this.checkNotFinished();
23919
24219
  return this.fetch();
23920
24220
  }
23921
24221
  async fetchedData() {
24222
+ this.checkNotFinished();
23922
24223
  if (this._fetchedData === void 0) {
23923
- const resp = await log_conn().get("object/dataset", {
24224
+ const resp = await _state.logConn().get("object/dataset", {
23924
24225
  id: this.id,
23925
24226
  fmt: "json",
23926
24227
  version: this.pinnedVersion
@@ -23931,9 +24232,11 @@ var Dataset = class {
23931
24232
  return this._fetchedData || [];
23932
24233
  }
23933
24234
  clearCache() {
24235
+ this.checkNotFinished();
23934
24236
  this._fetchedData = void 0;
23935
24237
  }
23936
24238
  async version() {
24239
+ this.checkNotFinished();
23937
24240
  if (this.pinnedVersion !== void 0) {
23938
24241
  return this.pinnedVersion;
23939
24242
  } else {
@@ -23948,6 +24251,25 @@ var Dataset = class {
23948
24251
  return maxVersion;
23949
24252
  }
23950
24253
  }
24254
+ /**
24255
+ * Terminate connection to the dataset and return its id. After calling close, you may not invoke any further methods on the dataset object.
24256
+ *
24257
+ * Will be invoked automatically if the dataset is bound as a context manager.
24258
+ *
24259
+ * @returns The dataset id.
24260
+ */
24261
+ async close() {
24262
+ this.checkNotFinished();
24263
+ await this.logger.flush();
24264
+ this.finished = true;
24265
+ unterminatedObjects.removeUnterminated(this);
24266
+ return this.id;
24267
+ }
24268
+ checkNotFinished() {
24269
+ if (this.finished) {
24270
+ throw new Error("Cannot invoke method on finished dataset");
24271
+ }
24272
+ }
23951
24273
  };
23952
24274
 
23953
24275
  // src/progress.ts
@@ -24000,15 +24322,15 @@ var path2 = __toESM(require("path"));
24000
24322
 
24001
24323
  // src/jest/tryRealpath.ts
24002
24324
  var import_graceful_fs = __toESM(require_graceful_fs());
24003
- function tryRealpath(path4) {
24325
+ function tryRealpath(path5) {
24004
24326
  try {
24005
- path4 = import_graceful_fs.realpathSync.native(path4);
24327
+ path5 = import_graceful_fs.realpathSync.native(path5);
24006
24328
  } catch (error2) {
24007
24329
  if (error2.code !== "ENOENT" && error2.code !== "EISDIR") {
24008
24330
  throw error2;
24009
24331
  }
24010
24332
  }
24011
- return path4;
24333
+ return path5;
24012
24334
  }
24013
24335
 
24014
24336
  // src/jest/nodeModulesPaths.ts
@@ -24085,21 +24407,21 @@ function parseFilters(filters) {
24085
24407
  if (equalsIdx === -1) {
24086
24408
  throw new Error(`Invalid filter ${f}`);
24087
24409
  }
24088
- const [path4, value] = [f.slice(0, equalsIdx), f.slice(equalsIdx + 1)];
24410
+ const [path5, value] = [f.slice(0, equalsIdx), f.slice(equalsIdx + 1)];
24089
24411
  let deserializedValue = deserializePlainStringAsJSON(value).value;
24090
24412
  if (typeof deserializedValue !== "string") {
24091
24413
  deserializedValue = value;
24092
24414
  }
24093
24415
  result.push({
24094
- path: path4.split("."),
24416
+ path: path5.split("."),
24095
24417
  pattern: new RegExp(deserializedValue)
24096
24418
  });
24097
24419
  }
24098
24420
  return result;
24099
24421
  }
24100
24422
  function evaluateFilter(object, filter3) {
24101
- const { path: path4, pattern } = filter3;
24102
- const key = path4.reduce((acc, p) => acc?.[p], object);
24423
+ const { path: path5, pattern } = filter3;
24424
+ const key = path5.reduce((acc, p) => acc?.[p], object);
24103
24425
  if (key === void 0) {
24104
24426
  return false;
24105
24427
  }
@@ -24123,65 +24445,91 @@ async function runEvaluator(experiment, evaluator, progressReporter, filters) {
24123
24445
  let output = void 0;
24124
24446
  let error2 = void 0;
24125
24447
  let scores = {};
24126
- try {
24127
- const meta = (o) => metadata = { ...metadata, ...o };
24128
- const outputResult = evaluator.task(datum.input, {
24129
- meta
24130
- });
24131
- if (outputResult instanceof Promise) {
24132
- output = await outputResult;
24133
- } else {
24134
- output = outputResult;
24135
- }
24136
- const scoringArgs = { ...datum, metadata, output };
24137
- const scoreResults = await Promise.all(
24138
- evaluator.scores.map(async (score) => {
24139
- const scoreResult = score(scoringArgs);
24140
- if (scoreResult instanceof Promise) {
24141
- return await scoreResult;
24142
- } else {
24143
- return scoreResult;
24448
+ const callback = async () => {
24449
+ try {
24450
+ const meta = (o) => metadata = { ...metadata, ...o };
24451
+ await traced(
24452
+ async () => {
24453
+ const outputResult = evaluator.task(datum.input, {
24454
+ meta,
24455
+ span: currentSpan()
24456
+ });
24457
+ if (outputResult instanceof Promise) {
24458
+ output = await outputResult;
24459
+ } else {
24460
+ output = outputResult;
24461
+ }
24462
+ currentSpan().log({ input: datum.input, output });
24463
+ },
24464
+ { name: "task" }
24465
+ );
24466
+ currentSpan().log({ output });
24467
+ const scoringArgs = { ...datum, metadata, output };
24468
+ const scoreResults = await Promise.all(
24469
+ evaluator.scores.map(async (score, score_idx) => {
24470
+ return traced(
24471
+ async () => {
24472
+ const scoreResult = score(scoringArgs);
24473
+ const result = scoreResult instanceof Promise ? await scoreResult : scoreResult;
24474
+ const {
24475
+ metadata: resultMetadata,
24476
+ name: _,
24477
+ ...resultRest
24478
+ } = result;
24479
+ currentSpan().log({
24480
+ output: resultRest,
24481
+ metadata: resultMetadata
24482
+ });
24483
+ return result;
24484
+ },
24485
+ {
24486
+ name: score.name || `scorer_${score_idx}`,
24487
+ event: { input: scoringArgs }
24488
+ }
24489
+ );
24490
+ })
24491
+ );
24492
+ const scoreMetadata = {};
24493
+ for (const scoreResult of scoreResults) {
24494
+ scores[scoreResult.name] = scoreResult.score;
24495
+ const metadata2 = {
24496
+ ...scoreResult.metadata
24497
+ };
24498
+ if (scoreResult.error !== void 0) {
24499
+ metadata2.error = scoreResult.error;
24500
+ }
24501
+ if (Object.keys(metadata2).length > 0) {
24502
+ scoreMetadata[scoreResult.name] = metadata2;
24144
24503
  }
24145
- })
24146
- );
24147
- const scoreMetadata = {};
24148
- for (const scoreResult of scoreResults) {
24149
- scores[scoreResult.name] = scoreResult.score;
24150
- const metadata2 = {
24151
- ...scoreResult.metadata
24152
- };
24153
- if (scoreResult.error !== void 0) {
24154
- metadata2.error = scoreResult.error;
24155
24504
  }
24156
- if (Object.keys(metadata2).length > 0) {
24157
- scoreMetadata[scoreResult.name] = metadata2;
24505
+ if (Object.keys(scoreMetadata).length > 0) {
24506
+ meta({ scores: scoreMetadata });
24158
24507
  }
24508
+ currentSpan().log({ scores, metadata });
24509
+ } catch (e) {
24510
+ error2 = e;
24511
+ } finally {
24512
+ progressReporter.increment(evaluator.name);
24159
24513
  }
24160
- if (Object.keys(scoreMetadata).length > 0) {
24161
- meta({ scores: scoreMetadata });
24514
+ return {
24515
+ output,
24516
+ metadata,
24517
+ scores,
24518
+ error: error2
24519
+ };
24520
+ };
24521
+ const rootSpan = experiment ? experiment.startSpan({
24522
+ name: "eval",
24523
+ event: {
24524
+ input: datum.input,
24525
+ expected: datum.expected
24162
24526
  }
24163
- } catch (e) {
24164
- error2 = e;
24527
+ }) : noopSpan;
24528
+ try {
24529
+ return await withCurrent(rootSpan, callback);
24165
24530
  } finally {
24166
- progressReporter.increment(evaluator.name);
24167
- }
24168
- if (experiment && !error2) {
24169
- experiment.log({
24170
- // TODO We should rename this from inputs -> input in the logger, etc.
24171
- // https://github.com/braintrustdata/braintrust/issues/217
24172
- input: datum.input,
24173
- metadata,
24174
- expected: datum.expected,
24175
- output,
24176
- scores
24177
- });
24531
+ rootSpan.end();
24178
24532
  }
24179
- return {
24180
- output,
24181
- metadata,
24182
- scores,
24183
- error: error2
24184
- };
24185
24533
  });
24186
24534
  const results = await Promise.all(evals);
24187
24535
  const summary = experiment ? await experiment.summarize() : null;
@@ -24194,6 +24542,7 @@ async function runEvaluator(experiment, evaluator, progressReporter, filters) {
24194
24542
  // src/node.ts
24195
24543
  var http2 = __toESM(require("http"));
24196
24544
  var https2 = __toESM(require("https"));
24545
+ var import_node_async_hooks = require("node:async_hooks");
24197
24546
 
24198
24547
  // node_modules/simple-git/dist/esm/index.js
24199
24548
  var import_file_exists = __toESM(require_dist(), 1);
@@ -24266,8 +24615,8 @@ var __async = (__this, __arguments, generator) => {
24266
24615
  step((generator = generator.apply(__this, __arguments)).next());
24267
24616
  });
24268
24617
  };
24269
- function isPathSpec(path4) {
24270
- return path4 instanceof String && cache.has(path4);
24618
+ function isPathSpec(path5) {
24619
+ return path5 instanceof String && cache.has(path5);
24271
24620
  }
24272
24621
  function toPaths(pathSpec) {
24273
24622
  return cache.get(pathSpec) || [];
@@ -24349,8 +24698,8 @@ function toLinesWithContent(input = "", trimmed2 = true, separator = "\n") {
24349
24698
  function forEachLineWithContent(input, callback) {
24350
24699
  return toLinesWithContent(input, true).map((line) => callback(line));
24351
24700
  }
24352
- function folderExists(path4) {
24353
- return (0, import_file_exists.exists)(path4, import_file_exists.FOLDER);
24701
+ function folderExists(path5) {
24702
+ return (0, import_file_exists.exists)(path5, import_file_exists.FOLDER);
24354
24703
  }
24355
24704
  function append2(target, item) {
24356
24705
  if (Array.isArray(target)) {
@@ -24713,8 +25062,8 @@ function checkIsRepoRootTask() {
24713
25062
  commands,
24714
25063
  format: "utf-8",
24715
25064
  onError,
24716
- parser(path4) {
24717
- return /^\.(git)?$/.test(path4.trim());
25065
+ parser(path5) {
25066
+ return /^\.(git)?$/.test(path5.trim());
24718
25067
  }
24719
25068
  };
24720
25069
  }
@@ -25105,11 +25454,11 @@ function parseGrep(grep) {
25105
25454
  const paths = /* @__PURE__ */ new Set();
25106
25455
  const results = {};
25107
25456
  forEachLineWithContent(grep, (input) => {
25108
- const [path4, line, preview] = input.split(NULL);
25109
- paths.add(path4);
25110
- (results[path4] = results[path4] || []).push({
25457
+ const [path5, line, preview] = input.split(NULL);
25458
+ paths.add(path5);
25459
+ (results[path5] = results[path5] || []).push({
25111
25460
  line: asNumber(line),
25112
- path: path4,
25461
+ path: path5,
25113
25462
  preview
25114
25463
  });
25115
25464
  });
@@ -25726,14 +26075,14 @@ var init_hash_object = __esm({
25726
26075
  init_task();
25727
26076
  }
25728
26077
  });
25729
- function parseInit(bare, path4, text) {
26078
+ function parseInit(bare, path5, text) {
25730
26079
  const response = String(text).trim();
25731
26080
  let result;
25732
26081
  if (result = initResponseRegex.exec(response)) {
25733
- return new InitSummary(bare, path4, false, result[1]);
26082
+ return new InitSummary(bare, path5, false, result[1]);
25734
26083
  }
25735
26084
  if (result = reInitResponseRegex.exec(response)) {
25736
- return new InitSummary(bare, path4, true, result[1]);
26085
+ return new InitSummary(bare, path5, true, result[1]);
25737
26086
  }
25738
26087
  let gitDir = "";
25739
26088
  const tokens = response.split(" ");
@@ -25744,7 +26093,7 @@ function parseInit(bare, path4, text) {
25744
26093
  break;
25745
26094
  }
25746
26095
  }
25747
- return new InitSummary(bare, path4, /^re/i.test(response), gitDir);
26096
+ return new InitSummary(bare, path5, /^re/i.test(response), gitDir);
25748
26097
  }
25749
26098
  var InitSummary;
25750
26099
  var initResponseRegex;
@@ -25752,9 +26101,9 @@ var reInitResponseRegex;
25752
26101
  var init_InitSummary = __esm({
25753
26102
  "src/lib/responses/InitSummary.ts"() {
25754
26103
  InitSummary = class {
25755
- constructor(bare, path4, existing, gitDir) {
26104
+ constructor(bare, path5, existing, gitDir) {
25756
26105
  this.bare = bare;
25757
- this.path = path4;
26106
+ this.path = path5;
25758
26107
  this.existing = existing;
25759
26108
  this.gitDir = gitDir;
25760
26109
  }
@@ -25766,7 +26115,7 @@ var init_InitSummary = __esm({
25766
26115
  function hasBareCommand(command) {
25767
26116
  return command.includes(bareCommand);
25768
26117
  }
25769
- function initTask(bare = false, path4, customArgs) {
26118
+ function initTask(bare = false, path5, customArgs) {
25770
26119
  const commands = ["init", ...customArgs];
25771
26120
  if (bare && !hasBareCommand(commands)) {
25772
26121
  commands.splice(1, 0, bareCommand);
@@ -25775,7 +26124,7 @@ function initTask(bare = false, path4, customArgs) {
25775
26124
  commands,
25776
26125
  format: "utf-8",
25777
26126
  parser(text) {
25778
- return parseInit(commands.includes("--bare"), path4, text);
26127
+ return parseInit(commands.includes("--bare"), path5, text);
25779
26128
  }
25780
26129
  };
25781
26130
  }
@@ -26495,12 +26844,12 @@ var init_FileStatusSummary = __esm({
26495
26844
  "src/lib/responses/FileStatusSummary.ts"() {
26496
26845
  fromPathRegex = /^(.+) -> (.+)$/;
26497
26846
  FileStatusSummary = class {
26498
- constructor(path4, index, working_dir) {
26499
- this.path = path4;
26847
+ constructor(path5, index, working_dir) {
26848
+ this.path = path5;
26500
26849
  this.index = index;
26501
26850
  this.working_dir = working_dir;
26502
26851
  if (index + working_dir === "R") {
26503
- const detail = fromPathRegex.exec(path4) || [null, path4, path4];
26852
+ const detail = fromPathRegex.exec(path5) || [null, path5, path5];
26504
26853
  this.from = detail[1] || "";
26505
26854
  this.path = detail[2] || "";
26506
26855
  }
@@ -26531,14 +26880,14 @@ function splitLine(result, lineStr) {
26531
26880
  default:
26532
26881
  return;
26533
26882
  }
26534
- function data(index, workingDir, path4) {
26883
+ function data(index, workingDir, path5) {
26535
26884
  const raw = `${index}${workingDir}`;
26536
26885
  const handler = parsers6.get(raw);
26537
26886
  if (handler) {
26538
- handler(result, path4);
26887
+ handler(result, path5);
26539
26888
  }
26540
26889
  if (raw !== "##" && raw !== "!!") {
26541
- result.files.push(new FileStatusSummary(path4.replace(/\0.+$/, ""), index, workingDir));
26890
+ result.files.push(new FileStatusSummary(path5.replace(/\0.+$/, ""), index, workingDir));
26542
26891
  }
26543
26892
  }
26544
26893
  }
@@ -26783,8 +27132,8 @@ var init_simple_git_api = __esm({
26783
27132
  }
26784
27133
  return this._runTask(configurationErrorTask("Git.cwd: workingDirectory must be supplied as a string"), next);
26785
27134
  }
26786
- hashObject(path4, write) {
26787
- return this._runTask(hashObjectTask(path4, write === true), trailingFunctionArgument(arguments));
27135
+ hashObject(path5, write) {
27136
+ return this._runTask(hashObjectTask(path5, write === true), trailingFunctionArgument(arguments));
26788
27137
  }
26789
27138
  init(bare) {
26790
27139
  return this._runTask(initTask(bare === true, this._executor.cwd, getTrailingOptions(arguments)), trailingFunctionArgument(arguments));
@@ -27361,8 +27710,8 @@ __export(sub_module_exports, {
27361
27710
  subModuleTask: () => subModuleTask,
27362
27711
  updateSubModuleTask: () => updateSubModuleTask
27363
27712
  });
27364
- function addSubModuleTask(repo, path4) {
27365
- return subModuleTask(["add", repo, path4]);
27713
+ function addSubModuleTask(repo, path5) {
27714
+ return subModuleTask(["add", repo, path5]);
27366
27715
  }
27367
27716
  function initSubModuleTask(customArgs) {
27368
27717
  return subModuleTask(["init", ...customArgs]);
@@ -27628,8 +27977,8 @@ var require_git = __commonJS2({
27628
27977
  }
27629
27978
  return this._runTask(straightThroughStringTask2(command, this._trimmed), next);
27630
27979
  };
27631
- Git2.prototype.submoduleAdd = function(repo, path4, then) {
27632
- return this._runTask(addSubModuleTask2(repo, path4), trailingFunctionArgument2(arguments));
27980
+ Git2.prototype.submoduleAdd = function(repo, path5, then) {
27981
+ return this._runTask(addSubModuleTask2(repo, path5), trailingFunctionArgument2(arguments));
27633
27982
  };
27634
27983
  Git2.prototype.submoduleUpdate = function(args, then) {
27635
27984
  return this._runTask(updateSubModuleTask2(getTrailingOptions2(arguments, true)), trailingFunctionArgument2(arguments));
@@ -28218,6 +28567,50 @@ async function getRepoStatus() {
28218
28567
  };
28219
28568
  }
28220
28569
 
28570
+ // src/stackutil.ts
28571
+ var path3 = __toESM(require("path"));
28572
+ function getStackTrace() {
28573
+ const trace = new Error().stack;
28574
+ if (trace === void 0) {
28575
+ return [];
28576
+ }
28577
+ const traceLines = trace.split("\n");
28578
+ const out = [];
28579
+ const stackFrameRegex = /at(.*)\((.*):(\d+):(\d+)\)/;
28580
+ for (const traceLine of traceLines.slice(1)) {
28581
+ const matches = traceLine.match(stackFrameRegex);
28582
+ if (matches === null || matches.length !== 5) {
28583
+ continue;
28584
+ }
28585
+ const entry = {
28586
+ functionName: matches[1].trim(),
28587
+ fileName: matches[2],
28588
+ lineNo: parseInt(matches[3])
28589
+ };
28590
+ if (!isNaN(entry.lineNo)) {
28591
+ out.push(entry);
28592
+ }
28593
+ }
28594
+ return out;
28595
+ }
28596
+ function getCallerLocation() {
28597
+ let thisDir = void 0;
28598
+ const entries = getStackTrace();
28599
+ for (const frame of entries) {
28600
+ if (thisDir === void 0) {
28601
+ thisDir = path3.dirname(frame.fileName);
28602
+ }
28603
+ if (path3.dirname(frame.fileName) !== thisDir) {
28604
+ return {
28605
+ caller_functionname: frame.functionName,
28606
+ caller_filename: frame.fileName,
28607
+ caller_lineno: frame.lineNo
28608
+ };
28609
+ }
28610
+ }
28611
+ return void 0;
28612
+ }
28613
+
28221
28614
  // src/node.ts
28222
28615
  function configureNode() {
28223
28616
  isomorph_default.makeAxios = (options) => {
@@ -28232,6 +28625,8 @@ function configureNode() {
28232
28625
  isomorph_default.getRepoStatus = getRepoStatus;
28233
28626
  isomorph_default.getPastNAncestors = getPastNAncestors;
28234
28627
  isomorph_default.getEnv = (name) => process.env[name];
28628
+ isomorph_default.getCallerLocation = getCallerLocation;
28629
+ isomorph_default.newAsyncLocalStorage = () => new import_node_async_hooks.AsyncLocalStorage();
28235
28630
  }
28236
28631
 
28237
28632
  // src/cli.ts
@@ -28270,6 +28665,7 @@ function evaluateBuildResults(inFile, buildResult) {
28270
28665
  const moduleText = buildResult.outputFiles[0].text;
28271
28666
  return evalWithModuleContext(inFile, () => {
28272
28667
  globalThis._evals = {};
28668
+ globalThis.__inherited_braintrust_state = _internalGetGlobalState();
28273
28669
  const __filename = inFile;
28274
28670
  const __dirname = (0, import_path.dirname)(__filename);
28275
28671
  new Function("require", "__filename", "__dirname", moduleText)(
@@ -28447,12 +28843,18 @@ async function runOnce(handles, opts) {
28447
28843
  updateEvaluators(evaluators, buildResults, opts);
28448
28844
  const resultPromises = Object.values(evaluators).map(async (evaluator) => {
28449
28845
  const logger = opts.noSendLogs ? null : await initLogger(evaluator.evaluator.name);
28450
- return await runEvaluator(
28451
- logger,
28452
- evaluator.evaluator,
28453
- opts.progressReporter,
28454
- opts.filters
28455
- );
28846
+ try {
28847
+ return await runEvaluator(
28848
+ logger,
28849
+ evaluator.evaluator,
28850
+ opts.progressReporter,
28851
+ opts.filters
28852
+ );
28853
+ } finally {
28854
+ if (logger) {
28855
+ await logger.close();
28856
+ }
28857
+ }
28456
28858
  });
28457
28859
  console.log(`Processing ${resultPromises.length} evaluators...`);
28458
28860
  const allEvalsResults = await Promise.all(resultPromises);
@@ -28509,7 +28911,7 @@ async function collectFiles(inputPath) {
28509
28911
  files.push(inputPath);
28510
28912
  }
28511
28913
  } else {
28512
- const walked = await import_util3.default.promisify(fsWalk.walk)(inputPath, {
28914
+ const walked = await import_util4.default.promisify(fsWalk.walk)(inputPath, {
28513
28915
  deepFilter: (entry) => {
28514
28916
  return checkMatch(entry.path, null, EXCLUDE);
28515
28917
  },