braintrust 0.0.114 → 0.0.116

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/browser.js CHANGED
@@ -24,9 +24,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
24
  mod
25
25
  ));
26
26
 
27
- // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.4.0_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/lib/zod-is-type.js
27
+ // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.3.1_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/lib/zod-is-type.js
28
28
  var require_zod_is_type = __commonJS({
29
- "../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.4.0_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/lib/zod-is-type.js"(exports) {
29
+ "../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.3.1_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/lib/zod-is-type.js"(exports) {
30
30
  "use strict";
31
31
  Object.defineProperty(exports, "__esModule", { value: true });
32
32
  exports.isAnyZodType = exports.isZodType = void 0;
@@ -42,9 +42,9 @@ var require_zod_is_type = __commonJS({
42
42
  }
43
43
  });
44
44
 
45
- // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.4.0_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/zod-extensions.js
45
+ // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.3.1_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/zod-extensions.js
46
46
  var require_zod_extensions = __commonJS({
47
- "../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.4.0_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/zod-extensions.js"(exports) {
47
+ "../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.3.1_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/zod-extensions.js"(exports) {
48
48
  "use strict";
49
49
  var __rest = exports && exports.__rest || function(s, e) {
50
50
  var t = {};
@@ -132,9 +132,9 @@ var require_zod_extensions = __commonJS({
132
132
  }
133
133
  });
134
134
 
135
- // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.4.0_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/lib/object-set.js
135
+ // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.3.1_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/lib/object-set.js
136
136
  var require_object_set = __commonJS({
137
- "../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.4.0_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/lib/object-set.js"(exports) {
137
+ "../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.3.1_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/lib/object-set.js"(exports) {
138
138
  "use strict";
139
139
  Object.defineProperty(exports, "__esModule", { value: true });
140
140
  exports.ObjectSet = exports.isEqual = void 0;
@@ -230,12 +230,12 @@ var require_object_set = __commonJS({
230
230
  }
231
231
  });
232
232
 
233
- // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.4.0_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/lib/lodash.js
233
+ // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.3.1_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/lib/lodash.js
234
234
  var require_lodash = __commonJS({
235
- "../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.4.0_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/lib/lodash.js"(exports) {
235
+ "../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.3.1_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/lib/lodash.js"(exports) {
236
236
  "use strict";
237
237
  Object.defineProperty(exports, "__esModule", { value: true });
238
- exports.isString = exports.uniq = exports.objectEquals = exports.compact = exports.omitBy = exports.omit = exports.mapValues = exports.isNil = exports.isUndefined = void 0;
238
+ exports.uniq = exports.objectEquals = exports.compact = exports.omitBy = exports.omit = exports.mapValues = exports.isNil = exports.isUndefined = void 0;
239
239
  var object_set_1 = require_object_set();
240
240
  function isUndefined(value) {
241
241
  return value === void 0;
@@ -284,16 +284,12 @@ var require_lodash = __commonJS({
284
284
  return [...set.values()];
285
285
  }
286
286
  exports.uniq = uniq;
287
- function isString(val) {
288
- return typeof val === "string";
289
- }
290
- exports.isString = isString;
291
287
  }
292
288
  });
293
289
 
294
- // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.4.0_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/openapi-metadata.js
290
+ // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.3.1_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/openapi-metadata.js
295
291
  var require_openapi_metadata = __commonJS({
296
- "../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.4.0_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/openapi-metadata.js"(exports) {
292
+ "../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.3.1_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/openapi-metadata.js"(exports) {
297
293
  "use strict";
298
294
  Object.defineProperty(exports, "__esModule", { value: true });
299
295
  exports.getOpenApiMetadata = void 0;
@@ -306,9 +302,9 @@ var require_openapi_metadata = __commonJS({
306
302
  }
307
303
  });
308
304
 
309
- // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.4.0_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/openapi-registry.js
305
+ // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.3.1_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/openapi-registry.js
310
306
  var require_openapi_registry = __commonJS({
311
- "../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.4.0_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/openapi-registry.js"(exports) {
307
+ "../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.3.1_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/openapi-registry.js"(exports) {
312
308
  "use strict";
313
309
  Object.defineProperty(exports, "__esModule", { value: true });
314
310
  exports.OpenAPIRegistry = void 0;
@@ -390,9 +386,9 @@ var require_openapi_registry = __commonJS({
390
386
  }
391
387
  });
392
388
 
393
- // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.4.0_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/errors.js
389
+ // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.3.1_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/errors.js
394
390
  var require_errors = __commonJS({
395
- "../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.4.0_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/errors.js"(exports) {
391
+ "../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.3.1_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/errors.js"(exports) {
396
392
  "use strict";
397
393
  Object.defineProperty(exports, "__esModule", { value: true });
398
394
  exports.UnknownZodTypeError = exports.MissingParameterDataError = exports.ConflictError = exports.ZodToOpenAPIError = void 0;
@@ -426,9 +422,9 @@ var require_errors = __commonJS({
426
422
  }
427
423
  });
428
424
 
429
- // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.4.0_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/lib/enum-info.js
425
+ // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.3.1_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/lib/enum-info.js
430
426
  var require_enum_info = __commonJS({
431
- "../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.4.0_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/lib/enum-info.js"(exports) {
427
+ "../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.3.1_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/lib/enum-info.js"(exports) {
432
428
  "use strict";
433
429
  Object.defineProperty(exports, "__esModule", { value: true });
434
430
  exports.enumInfo = void 0;
@@ -443,9 +439,9 @@ var require_enum_info = __commonJS({
443
439
  }
444
440
  });
445
441
 
446
- // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.4.0_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/openapi-generator.js
442
+ // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.3.1_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/openapi-generator.js
447
443
  var require_openapi_generator = __commonJS({
448
- "../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.4.0_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/openapi-generator.js"(exports) {
444
+ "../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.3.1_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/openapi-generator.js"(exports) {
449
445
  "use strict";
450
446
  var __rest = exports && exports.__rest || function(s, e) {
451
447
  var t = {};
@@ -786,7 +782,7 @@ var require_openapi_generator = __commonJS({
786
782
  }
787
783
  getBodyContent(content) {
788
784
  return (0, lodash_1.mapValues)(content, (config) => {
789
- if (!config || !(0, zod_is_type_1.isAnyZodType)(config.schema)) {
785
+ if (!(0, zod_is_type_1.isAnyZodType)(config.schema)) {
790
786
  return config;
791
787
  }
792
788
  const { schema: configSchema } = config, rest = __rest(config, ["schema"]);
@@ -974,14 +970,7 @@ var require_openapi_generator = __commonJS({
974
970
  }
975
971
  if ((0, zod_is_type_1.isZodType)(zodSchema, "ZodRecord")) {
976
972
  const propertiesType = zodSchema._def.valueType;
977
- const keyType = zodSchema._def.keyType;
978
- const propertiesSchema = this.generateSchemaWithRef(propertiesType);
979
- if ((0, zod_is_type_1.isZodType)(keyType, "ZodEnum") || (0, zod_is_type_1.isZodType)(keyType, "ZodNativeEnum")) {
980
- const keys = Object.values(keyType.enum).filter(lodash_1.isString);
981
- const properties = keys.reduce((acc, curr) => Object.assign(Object.assign({}, acc), { [curr]: propertiesSchema }), {});
982
- return Object.assign(Object.assign({}, this.mapNullableType("object", isNullable)), { properties, default: defaultValue });
983
- }
984
- return Object.assign(Object.assign({}, this.mapNullableType("object", isNullable)), { additionalProperties: propertiesSchema, default: defaultValue });
973
+ return Object.assign(Object.assign({}, this.mapNullableType("object", isNullable)), { additionalProperties: this.generateSchemaWithRef(propertiesType), default: defaultValue });
985
974
  }
986
975
  if ((0, zod_is_type_1.isZodType)(zodSchema, "ZodUnknown") || (0, zod_is_type_1.isZodType)(zodSchema, "ZodAny")) {
987
976
  return this.mapNullableType(void 0, isNullable);
@@ -1147,9 +1136,9 @@ var require_openapi_generator = __commonJS({
1147
1136
  }
1148
1137
  });
1149
1138
 
1150
- // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.4.0_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/v3.0/specifics.js
1139
+ // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.3.1_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/v3.0/specifics.js
1151
1140
  var require_specifics = __commonJS({
1152
- "../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.4.0_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/v3.0/specifics.js"(exports) {
1141
+ "../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.3.1_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/v3.0/specifics.js"(exports) {
1153
1142
  "use strict";
1154
1143
  Object.defineProperty(exports, "__esModule", { value: true });
1155
1144
  exports.OpenApiGeneratorV30Specifics = void 0;
@@ -1183,9 +1172,9 @@ var require_specifics = __commonJS({
1183
1172
  }
1184
1173
  });
1185
1174
 
1186
- // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.4.0_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/v3.0/openapi-generator.js
1175
+ // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.3.1_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/v3.0/openapi-generator.js
1187
1176
  var require_openapi_generator2 = __commonJS({
1188
- "../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.4.0_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/v3.0/openapi-generator.js"(exports) {
1177
+ "../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.3.1_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/v3.0/openapi-generator.js"(exports) {
1189
1178
  "use strict";
1190
1179
  Object.defineProperty(exports, "__esModule", { value: true });
1191
1180
  exports.OpenApiGeneratorV3 = void 0;
@@ -1208,9 +1197,9 @@ var require_openapi_generator2 = __commonJS({
1208
1197
  }
1209
1198
  });
1210
1199
 
1211
- // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.4.0_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/v3.1/specifics.js
1200
+ // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.3.1_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/v3.1/specifics.js
1212
1201
  var require_specifics2 = __commonJS({
1213
- "../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.4.0_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/v3.1/specifics.js"(exports) {
1202
+ "../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.3.1_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/v3.1/specifics.js"(exports) {
1214
1203
  "use strict";
1215
1204
  Object.defineProperty(exports, "__esModule", { value: true });
1216
1205
  exports.OpenApiGeneratorV31Specifics = void 0;
@@ -1254,9 +1243,9 @@ var require_specifics2 = __commonJS({
1254
1243
  }
1255
1244
  });
1256
1245
 
1257
- // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.4.0_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/v3.1/openapi-generator.js
1246
+ // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.3.1_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/v3.1/openapi-generator.js
1258
1247
  var require_openapi_generator3 = __commonJS({
1259
- "../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.4.0_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/v3.1/openapi-generator.js"(exports) {
1248
+ "../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.3.1_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/v3.1/openapi-generator.js"(exports) {
1260
1249
  "use strict";
1261
1250
  Object.defineProperty(exports, "__esModule", { value: true });
1262
1251
  exports.OpenApiGeneratorV31 = void 0;
@@ -1290,9 +1279,9 @@ var require_openapi_generator3 = __commonJS({
1290
1279
  }
1291
1280
  });
1292
1281
 
1293
- // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.4.0_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/index.js
1282
+ // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.3.1_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/index.js
1294
1283
  var require_dist = __commonJS({
1295
- "../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.4.0_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/index.js"(exports) {
1284
+ "../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.3.1_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/index.js"(exports) {
1296
1285
  "use strict";
1297
1286
  var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
1298
1287
  if (k2 === void 0)
@@ -1408,7 +1397,7 @@ function v4(options, buf, offset) {
1408
1397
  }
1409
1398
  var v4_default = v4;
1410
1399
 
1411
- // ../../node_modules/.pnpm/@braintrust+core@0.0.27/node_modules/@braintrust/core/dist/index.mjs
1400
+ // ../core/js/dist/index.mjs
1412
1401
  var TRANSACTION_ID_FIELD = "_xact_id";
1413
1402
  var IS_MERGE_FIELD = "_is_merge";
1414
1403
  var MERGE_PATHS_FIELD = "_merge_paths";
@@ -1681,6 +1670,88 @@ function makeLegacyEvent(e) {
1681
1670
  }
1682
1671
  return event;
1683
1672
  }
1673
+ var SpanParentObjectType = /* @__PURE__ */ ((SpanParentObjectType2) => {
1674
+ SpanParentObjectType2["EXPERIMENT"] = "experiment";
1675
+ SpanParentObjectType2["PROJECT_LOGS"] = "project_logs";
1676
+ return SpanParentObjectType2;
1677
+ })(SpanParentObjectType || {});
1678
+ var _OBJECT_TYPE_TO_PREFIX = {
1679
+ [
1680
+ "experiment"
1681
+ /* EXPERIMENT */
1682
+ ]: "ex",
1683
+ [
1684
+ "project_logs"
1685
+ /* PROJECT_LOGS */
1686
+ ]: "pl"
1687
+ };
1688
+ var _PREFIX_TO_OBJECT_TYPE = Object.fromEntries(
1689
+ Object.entries(_OBJECT_TYPE_TO_PREFIX).map(([k, v]) => [v, k])
1690
+ );
1691
+ var _SEP = ":";
1692
+ var SpanParentComponents = class _SpanParentComponents {
1693
+ constructor(args) {
1694
+ this.objectType = args.objectType;
1695
+ this.objectId = args.objectId;
1696
+ this.rowId = args.rowId;
1697
+ if (!(typeof this.objectType === "string")) {
1698
+ throw new Error("objectType must be a string");
1699
+ }
1700
+ if (!(typeof this.objectId === "string")) {
1701
+ throw new Error("objectId must be a string");
1702
+ }
1703
+ if (!(typeof this.rowId === "string")) {
1704
+ throw new Error("rowId must be a string");
1705
+ }
1706
+ const objectTypePrefix = _OBJECT_TYPE_TO_PREFIX[this.objectType];
1707
+ if (objectTypePrefix.includes(_SEP)) {
1708
+ throw new Error(
1709
+ `objectType prefix ${objectTypePrefix} may not contain separator character ${_SEP}`
1710
+ );
1711
+ }
1712
+ if (this.objectId.includes(_SEP)) {
1713
+ throw new Error(
1714
+ `objectId ${this.objectId} may not contain separator character ${_SEP}`
1715
+ );
1716
+ }
1717
+ }
1718
+ toStr() {
1719
+ return [
1720
+ _OBJECT_TYPE_TO_PREFIX[this.objectType],
1721
+ this.objectId,
1722
+ this.rowId
1723
+ ].join(_SEP);
1724
+ }
1725
+ static fromStr(s) {
1726
+ const items = s.split(_SEP);
1727
+ if (items.length < 3) {
1728
+ throw new Error(
1729
+ `Serialized parent components string must have at least three components. Provided string ${s} has only ${items.length}`
1730
+ );
1731
+ }
1732
+ return new _SpanParentComponents({
1733
+ objectType: _PREFIX_TO_OBJECT_TYPE[items[0]],
1734
+ objectId: items[1],
1735
+ rowId: items.slice(2).join(_SEP)
1736
+ });
1737
+ }
1738
+ asDict() {
1739
+ const out = (() => {
1740
+ switch (this.objectType) {
1741
+ case "experiment":
1742
+ return { experiment_id: this.objectId };
1743
+ case "project_logs":
1744
+ return { project_id: this.objectId, log_id: "g" };
1745
+ default:
1746
+ throw new Error("Impossible");
1747
+ }
1748
+ })();
1749
+ if (this.rowId) {
1750
+ out[PARENT_ID_FIELD] = this.rowId;
1751
+ }
1752
+ return out;
1753
+ }
1754
+ };
1684
1755
  var SpanTypeAttribute = /* @__PURE__ */ ((SpanTypeAttribute22) => {
1685
1756
  SpanTypeAttribute22["LLM"] = "llm";
1686
1757
  SpanTypeAttribute22["SCORE"] = "score";
@@ -1713,7 +1784,7 @@ var MOD = BigInt(1) << BigInt(64);
1713
1784
  var COPRIME = BigInt("205891132094649");
1714
1785
  var COPRIME_INVERSE = BigInt("1522336535492693385");
1715
1786
 
1716
- // ../../node_modules/.pnpm/@braintrust+core@0.0.27/node_modules/@braintrust/core/typespecs/dist/index.mjs
1787
+ // ../core/js/typespecs/dist/index.mjs
1717
1788
  var import_zod_to_openapi = __toESM(require_dist(), 1);
1718
1789
 
1719
1790
  // ../../node_modules/.pnpm/zod@3.22.4/node_modules/zod/lib/index.mjs
@@ -5449,7 +5520,7 @@ var z = /* @__PURE__ */ Object.freeze({
5449
5520
  ZodError
5450
5521
  });
5451
5522
 
5452
- // ../../node_modules/.pnpm/@braintrust+core@0.0.27/node_modules/@braintrust/core/typespecs/dist/index.mjs
5523
+ // ../core/js/typespecs/dist/index.mjs
5453
5524
  var import_zod_to_openapi2 = __toESM(require_dist(), 1);
5454
5525
  var import_zod_to_openapi3 = __toESM(require_dist(), 1);
5455
5526
  var literalSchema = z.union([
@@ -5493,65 +5564,66 @@ var modeToTypes = {
5493
5564
  }
5494
5565
  };
5495
5566
  var customTypes = modeToTypes[mode];
5496
- var chatCompletionSystemMessageParamSchema = z.object({
5567
+ var chatCompletionSystemMessageParamSchema = z.strictObject({
5497
5568
  content: z.string().default(""),
5498
5569
  role: z.literal("system"),
5499
5570
  name: z.string().optional()
5500
- });
5501
- var chatCompletionContentPartTextSchema = z.object({
5571
+ }).strip();
5572
+ var chatCompletionContentPartTextSchema = z.strictObject({
5502
5573
  text: z.string().default(""),
5503
5574
  type: z.literal("text")
5504
- });
5505
- var functionCallSchema = z.object({
5575
+ }).strip();
5576
+ var imageURLSchema = z.strictObject({
5577
+ url: z.string(),
5578
+ detail: z.union([z.literal("auto"), z.literal("low"), z.literal("high")]).optional()
5579
+ }).strip();
5580
+ var chatCompletionContentPartImageSchema = z.strictObject({
5581
+ image_url: imageURLSchema,
5582
+ type: z.literal("image_url")
5583
+ }).strip();
5584
+ var chatCompletionContentPartSchema = z.union([
5585
+ chatCompletionContentPartTextSchema,
5586
+ chatCompletionContentPartImageSchema
5587
+ ]);
5588
+ var chatCompletionContentSchema = z.union([
5589
+ z.string().default(""),
5590
+ z.array(chatCompletionContentPartSchema)
5591
+ ]);
5592
+ var chatCompletionUserMessageParamSchema = z.strictObject({
5593
+ content: chatCompletionContentSchema,
5594
+ role: z.literal("user"),
5595
+ name: z.string().optional()
5596
+ }).strip();
5597
+ var functionCallSchema = z.strictObject({
5506
5598
  arguments: z.string(),
5507
5599
  name: z.string()
5508
- });
5509
- var functionSchema = z.object({
5600
+ }).strip();
5601
+ var functionSchema = z.strictObject({
5510
5602
  arguments: z.string(),
5511
5603
  name: z.string()
5512
- });
5513
- var imageURLSchema = z.object({
5514
- url: z.string(),
5515
- detail: z.union([z.literal("auto"), z.literal("low"), z.literal("high")]).optional()
5516
- });
5517
- var chatCompletionToolMessageParamSchema = z.object({
5604
+ }).strip();
5605
+ var chatCompletionToolMessageParamSchema = z.strictObject({
5518
5606
  content: z.string().default(""),
5519
5607
  role: z.literal("tool"),
5520
5608
  tool_call_id: z.string()
5521
- });
5522
- var chatCompletionFunctionMessageParamSchema = z.object({
5609
+ }).strip();
5610
+ var chatCompletionFunctionMessageParamSchema = z.strictObject({
5523
5611
  content: z.string().default(""),
5524
5612
  name: z.string(),
5525
5613
  role: z.literal("function")
5526
- });
5527
- var chatCompletionContentPartImageSchema = z.object({
5528
- image_url: imageURLSchema,
5529
- type: z.literal("image_url")
5530
- });
5531
- var chatCompletionMessageToolCallSchema = z.object({
5614
+ }).strip();
5615
+ var chatCompletionMessageToolCallSchema = z.strictObject({
5532
5616
  id: z.string(),
5533
5617
  function: functionSchema,
5534
5618
  type: z.literal("function")
5535
- });
5536
- var chatCompletionContentPartSchema = z.union([
5537
- chatCompletionContentPartTextSchema,
5538
- chatCompletionContentPartImageSchema
5539
- ]);
5540
- var chatCompletionAssistantMessageParamSchema = z.object({
5619
+ }).strip();
5620
+ var chatCompletionAssistantMessageParamSchema = z.strictObject({
5541
5621
  role: z.literal("assistant"),
5542
5622
  content: z.string().nullish(),
5543
5623
  function_call: functionCallSchema.optional(),
5544
5624
  name: z.string().optional(),
5545
5625
  tool_calls: z.array(chatCompletionMessageToolCallSchema).optional()
5546
- });
5547
- var chatCompletionUserMessageParamSchema = z.object({
5548
- content: z.union([
5549
- z.string().default(""),
5550
- z.array(chatCompletionContentPartSchema)
5551
- ]),
5552
- role: z.literal("user"),
5553
- name: z.string().optional()
5554
- });
5626
+ }).strip();
5555
5627
  var chatCompletionMessageParamSchema = z.union([
5556
5628
  chatCompletionSystemMessageParamSchema,
5557
5629
  chatCompletionUserMessageParamSchema,
@@ -5560,15 +5632,15 @@ var chatCompletionMessageParamSchema = z.union([
5560
5632
  chatCompletionFunctionMessageParamSchema
5561
5633
  ]);
5562
5634
  var functionParametersSchema = z.record(z.unknown());
5563
- var functionDefinitionSchema = z.object({
5635
+ var functionDefinitionSchema = z.strictObject({
5564
5636
  name: z.string(),
5565
5637
  description: z.string().optional(),
5566
5638
  parameters: functionParametersSchema.optional()
5567
- });
5568
- var chatCompletionToolSchema = z.object({
5639
+ }).strip();
5640
+ var chatCompletionToolSchema = z.strictObject({
5569
5641
  function: functionDefinitionSchema,
5570
5642
  type: z.literal("function")
5571
- });
5643
+ }).strip();
5572
5644
  var toolsSchema = z.array(chatCompletionToolSchema);
5573
5645
  var messageRoleSchema = z.enum([
5574
5646
  "system",
@@ -5579,69 +5651,71 @@ var messageRoleSchema = z.enum([
5579
5651
  "model"
5580
5652
  ]);
5581
5653
  var promptBlockDataSchema = z.union([
5582
- z.object({
5654
+ z.strictObject({
5583
5655
  type: z.literal("completion"),
5584
5656
  content: z.string()
5585
5657
  }),
5586
- z.object({
5658
+ z.strictObject({
5587
5659
  type: z.literal("chat"),
5588
5660
  messages: z.array(chatCompletionMessageParamSchema),
5589
5661
  tools: z.string().optional()
5590
5662
  })
5591
5663
  ]);
5592
- var braintrustModelParamsSchema = z.object({
5664
+ var braintrustModelParamsSchema = z.strictObject({
5593
5665
  use_cache: z.boolean().optional()
5594
- });
5666
+ }).strip();
5595
5667
  var BRAINTRUST_PARAMS = Object.keys(braintrustModelParamsSchema.shape);
5596
- var openAIModelParamsSchema = z.object({
5597
- temperature: z.number(),
5668
+ var openAIModelParamsSchema = z.strictObject({
5669
+ temperature: z.number().optional(),
5598
5670
  top_p: z.number().optional(),
5599
5671
  max_tokens: z.number().optional(),
5600
5672
  frequency_penalty: z.number().optional(),
5601
5673
  presence_penalty: z.number().optional(),
5602
- response_format: z.union([z.literal(null), z.object({ type: z.literal("json_object") })]).optional(),
5674
+ response_format: z.union([
5675
+ z.literal(null),
5676
+ z.strictObject({ type: z.literal("json_object") }).strip()
5677
+ ]).optional(),
5603
5678
  tool_choice: z.union([
5604
5679
  z.literal("auto"),
5605
5680
  z.literal("none"),
5606
- z.object({
5681
+ z.strictObject({
5607
5682
  type: z.literal("function"),
5608
- function: z.object({ name: z.string() })
5609
- })
5683
+ function: z.strictObject({ name: z.string() }).strip()
5684
+ }).strip()
5610
5685
  ]).optional()
5611
- });
5612
- var anthropicModelParamsSchema = z.object({
5686
+ }).strip();
5687
+ var anthropicModelParamsSchema = z.strictObject({
5613
5688
  max_tokens: z.number(),
5614
5689
  temperature: z.number(),
5615
5690
  top_p: z.number().optional(),
5616
5691
  top_k: z.number().optional(),
5617
5692
  max_tokens_to_sample: z.number().optional().describe("This is a legacy parameter that should not be used.")
5618
- });
5619
- var googleModelParamsSchema = z.object({
5693
+ }).strip();
5694
+ var googleModelParamsSchema = z.strictObject({
5620
5695
  temperature: z.number(),
5621
5696
  maxOutputTokens: z.number().optional(),
5622
5697
  topP: z.number().optional(),
5623
5698
  topK: z.number().optional()
5624
- });
5625
- var jsCompletionParamsSchema = z.object({});
5626
- var modelParamsSchema = braintrustModelParamsSchema.and(
5627
- z.union([
5628
- openAIModelParamsSchema,
5629
- anthropicModelParamsSchema,
5630
- googleModelParamsSchema,
5631
- jsCompletionParamsSchema
5632
- ])
5633
- );
5634
- var anyModelParamsSchema = openAIModelParamsSchema.and(anthropicModelParamsSchema).and(googleModelParamsSchema).and(braintrustModelParamsSchema);
5635
- var promptOptionsSchema = z.object({
5699
+ }).strip();
5700
+ var jsCompletionParamsSchema = z.strictObject({}).strip();
5701
+ var modelParamsSchema = z.union([
5702
+ braintrustModelParamsSchema.merge(openAIModelParamsSchema),
5703
+ braintrustModelParamsSchema.merge(anthropicModelParamsSchema),
5704
+ braintrustModelParamsSchema.merge(googleModelParamsSchema),
5705
+ braintrustModelParamsSchema.merge(jsCompletionParamsSchema)
5706
+ ]);
5707
+ var anyModelParamsSchema = openAIModelParamsSchema.merge(anthropicModelParamsSchema).merge(googleModelParamsSchema).merge(braintrustModelParamsSchema);
5708
+ var promptOptionsSchema = z.strictObject({
5636
5709
  model: z.string().optional(),
5637
5710
  params: modelParamsSchema.optional(),
5638
5711
  position: z.string().optional()
5639
- });
5640
- var promptDataSchema = z.object({
5712
+ }).strip();
5713
+ var promptDataSchema = z.strictObject({
5641
5714
  prompt: promptBlockDataSchema.nullish(),
5642
5715
  options: promptOptionsSchema.nullish(),
5643
- origin: z.object({
5716
+ origin: z.strictObject({
5644
5717
  prompt_id: z.string().optional(),
5718
+ project_id: z.string().optional(),
5645
5719
  prompt_version: z.string().optional()
5646
5720
  }).nullish()
5647
5721
  }).openapi("PromptData");
@@ -5651,7 +5725,7 @@ function generateBaseTableSchema(objectName, opts) {
5651
5725
  if (opts == null ? void 0 : opts.uniqueName) {
5652
5726
  nameDescription += `. Within a project, ${objectName} names are unique`;
5653
5727
  }
5654
- return z.object({
5728
+ return z.strictObject({
5655
5729
  id: z.string().uuid().describe(`Unique identifier for the ${objectName}`),
5656
5730
  project_id: z.string().uuid().describe(
5657
5731
  `Unique identifier for the project that the ${objectName} belongs under`
@@ -5667,7 +5741,7 @@ function generateBaseTableSchema(objectName, opts) {
5667
5741
  });
5668
5742
  }
5669
5743
  var userBaseSchema = generateBaseTableSchema("user");
5670
- var userSchema = z.object({
5744
+ var userSchema = z.strictObject({
5671
5745
  id: userBaseSchema.shape.id,
5672
5746
  auth_id: z.string().uuid().nullish().describe("Internal authentication token used to identify the user"),
5673
5747
  given_name: z.string().nullish().describe("Given name of the user"),
@@ -5675,29 +5749,29 @@ var userSchema = z.object({
5675
5749
  email: z.string().nullish().describe("The user's email"),
5676
5750
  avatar_url: z.string().nullish().describe("URL of the user's Avatar image"),
5677
5751
  created: userBaseSchema.shape.created
5678
- }).strict().openapi("User");
5752
+ }).openapi("User");
5679
5753
  var organizationBaseSchema = generateBaseTableSchema("organization");
5680
- var organizationSchema = z.object({
5754
+ var organizationSchema = z.strictObject({
5681
5755
  id: organizationBaseSchema.shape.id,
5682
5756
  name: organizationBaseSchema.shape.name.nullish(),
5683
5757
  api_url: z.string().nullish(),
5684
5758
  created: organizationBaseSchema.shape.created
5685
- }).strict().openapi("Organization");
5686
- var memberSchema = z.object({
5759
+ }).openapi("Organization");
5760
+ var memberSchema = z.strictObject({
5687
5761
  org_id: organizationSchema.shape.id,
5688
5762
  user_id: userSchema.shape.id
5689
- }).strict().openapi("Member");
5690
- var meSchema = z.object({
5763
+ }).openapi("Member");
5764
+ var meSchema = z.strictObject({
5691
5765
  id: userSchema.shape.id,
5692
5766
  // By filtering by auth_id equality, we will ensure this is not-null.
5693
5767
  auth_id: userSchema.shape.auth_id.unwrap().unwrap(),
5694
- organizations: z.object({
5768
+ organizations: z.strictObject({
5695
5769
  id: memberSchema.shape.org_id,
5696
5770
  name: organizationSchema.shape.name
5697
5771
  }).array()
5698
- }).strict().openapi("Me");
5772
+ }).openapi("Me");
5699
5773
  var apiKeyBaseSchema = generateBaseTableSchema("api key");
5700
- var apiKeySchema = z.object({
5774
+ var apiKeySchema = z.strictObject({
5701
5775
  id: apiKeyBaseSchema.shape.id,
5702
5776
  created: apiKeyBaseSchema.shape.created,
5703
5777
  key_hash: z.string(),
@@ -5705,9 +5779,9 @@ var apiKeySchema = z.object({
5705
5779
  preview_name: z.string(),
5706
5780
  user_id: userSchema.shape.id.nullish(),
5707
5781
  org_id: organizationSchema.shape.id.nullish()
5708
- }).strict().openapi("ApiKey");
5782
+ }).openapi("ApiKey");
5709
5783
  var projectBaseSchema = generateBaseTableSchema("project");
5710
- var projectSchema = z.object({
5784
+ var projectSchema = z.strictObject({
5711
5785
  id: projectBaseSchema.shape.id,
5712
5786
  org_id: z.string().uuid().describe(
5713
5787
  "Unique id for the organization that the project belongs under"
@@ -5716,11 +5790,11 @@ var projectSchema = z.object({
5716
5790
  created: projectBaseSchema.shape.created,
5717
5791
  deleted_at: projectBaseSchema.shape.deleted_at,
5718
5792
  user_id: projectBaseSchema.shape.user_id
5719
- }).strict().openapi("Project");
5793
+ }).openapi("Project");
5720
5794
  var datasetBaseSchema = generateBaseTableSchema("dataset", {
5721
5795
  uniqueName: true
5722
5796
  });
5723
- var datasetSchema = z.object({
5797
+ var datasetSchema = z.strictObject({
5724
5798
  id: datasetBaseSchema.shape.id,
5725
5799
  project_id: datasetBaseSchema.shape.project_id.nullish(),
5726
5800
  name: datasetBaseSchema.shape.name,
@@ -5728,22 +5802,26 @@ var datasetSchema = z.object({
5728
5802
  created: datasetBaseSchema.shape.created,
5729
5803
  deleted_at: datasetBaseSchema.shape.deleted_at,
5730
5804
  user_id: datasetBaseSchema.shape.user_id
5731
- }).strict().openapi("Dataset");
5805
+ }).openapi("Dataset");
5732
5806
  var promptBaseSchema = generateBaseTableSchema("prompt");
5733
- var promptSchema = z.object({
5807
+ var promptSchema = z.strictObject({
5734
5808
  id: promptBaseSchema.shape.id,
5735
5809
  // This has to be copy/pasted because zod blows up when there are circular dependencies
5736
5810
  _xact_id: z.string().describe(
5737
5811
  `The transaction id of an event is unique to the network operation that processed the event insertion. Transaction ids are monotonically increasing over time and can be used to retrieve a versioned snapshot of the prompt (see the \`version\` parameter)`
5738
5812
  ),
5739
5813
  project_id: promptBaseSchema.shape.project_id,
5814
+ log_id: z.literal("p").describe("A literal 'p' which identifies the object as a project prompt"),
5815
+ org_id: organizationSchema.shape.id,
5740
5816
  name: promptBaseSchema.shape.name,
5741
5817
  slug: z.string().describe("Unique identifier for the prompt"),
5742
5818
  description: promptBaseSchema.shape.description,
5819
+ created: promptBaseSchema.shape.created,
5743
5820
  prompt_data: promptDataSchema.nullish().describe("The prompt, model, and its parameters"),
5744
- tags: z.array(z.string()).nullish().describe("A list of tags for the prompt")
5821
+ tags: z.array(z.string()).nullish().describe("A list of tags for the prompt"),
5822
+ metadata: promptBaseSchema.shape.metadata
5745
5823
  });
5746
- var repoInfoSchema = z.object({
5824
+ var repoInfoSchema = z.strictObject({
5747
5825
  commit: z.string().nullish().describe("SHA of most recent commit"),
5748
5826
  branch: z.string().nullish().describe("Name of the branch the most recent commit belongs to"),
5749
5827
  tag: z.string().nullish().describe("Name of the tag on the most recent commit"),
@@ -5763,7 +5841,7 @@ var repoInfoSchema = z.object({
5763
5841
  var experimentBaseSchema = generateBaseTableSchema("experiment", {
5764
5842
  uniqueName: true
5765
5843
  });
5766
- var experimentSchema = z.object({
5844
+ var experimentSchema = z.strictObject({
5767
5845
  id: experimentBaseSchema.shape.id,
5768
5846
  project_id: experimentBaseSchema.shape.project_id,
5769
5847
  name: experimentBaseSchema.shape.name,
@@ -5786,10 +5864,10 @@ var experimentSchema = z.object({
5786
5864
  ),
5787
5865
  user_id: experimentBaseSchema.shape.user_id,
5788
5866
  metadata: experimentBaseSchema.shape.metadata
5789
- }).strict().openapi("Experiment");
5867
+ }).openapi("Experiment");
5790
5868
  var appLimitSchema = z.number().int().nonnegative().describe("Limit the number of objects to return");
5791
5869
  function generateBaseTableOpSchema(objectName) {
5792
- return z.object({
5870
+ return z.strictObject({
5793
5871
  org_name: z.string().nullish().describe(
5794
5872
  `For nearly all users, this parameter should be unnecessary. But in the rare case that your API key belongs to multiple organizations, you may specify the name of the organization the ${objectName} belongs in.`
5795
5873
  )
@@ -5808,14 +5886,14 @@ var endingBeforeSchema = z.string().uuid().describe(
5808
5886
  ].join("\n\n")
5809
5887
  ).openapi("EndingBefore");
5810
5888
  var createProjectBaseSchema = generateBaseTableOpSchema("project");
5811
- var createProjectSchema = z.object({
5889
+ var createProjectSchema = z.strictObject({
5812
5890
  name: projectSchema.shape.name,
5813
5891
  org_name: createProjectBaseSchema.shape.org_name
5814
- }).strict().openapi("CreateProject");
5815
- var patchProjectSchema = z.object({
5892
+ }).openapi("CreateProject");
5893
+ var patchProjectSchema = z.strictObject({
5816
5894
  name: projectSchema.shape.name.nullish()
5817
- }).strict().openapi("PatchProject");
5818
- var createExperimentSchema = z.object({
5895
+ }).openapi("PatchProject");
5896
+ var createExperimentSchema = z.strictObject({
5819
5897
  project_id: experimentSchema.shape.project_id,
5820
5898
  name: experimentSchema.shape.name.nullish(),
5821
5899
  description: experimentSchema.shape.description,
@@ -5825,21 +5903,28 @@ var createExperimentSchema = z.object({
5825
5903
  dataset_version: experimentSchema.shape.dataset_version,
5826
5904
  public: experimentSchema.shape.public.nullish(),
5827
5905
  metadata: experimentSchema.shape.metadata
5828
- }).strict().openapi("CreateExperiment");
5829
- var patchExperimentSchema = createExperimentSchema.omit({ project_id: true }).strict().openapi("PatchExperiment");
5830
- var createDatasetSchema = z.object({
5906
+ }).openapi("CreateExperiment");
5907
+ var patchExperimentSchema = createExperimentSchema.omit({ project_id: true }).openapi("PatchExperiment");
5908
+ var createDatasetSchema = z.strictObject({
5831
5909
  project_id: datasetSchema.shape.project_id,
5832
5910
  name: datasetSchema.shape.name,
5833
5911
  description: datasetSchema.shape.description
5834
- }).strict().openapi("CreateDataset");
5835
- var patchDatasetSchema = createDatasetSchema.omit({ project_id: true }).strict().openapi("PatchDataset");
5836
- var createPromptSchema = promptSchema.omit({ id: true, _xact_id: true }).strict().openapi("CreatePrompt");
5837
- var patchPromptSchema = z.object({
5912
+ }).openapi("CreateDataset");
5913
+ var patchDatasetSchema = createDatasetSchema.omit({ project_id: true }).openapi("PatchDataset");
5914
+ var createPromptSchema = promptSchema.omit({
5915
+ id: true,
5916
+ _xact_id: true,
5917
+ org_id: true,
5918
+ log_id: true,
5919
+ created: true,
5920
+ metadata: true
5921
+ }).openapi("CreatePrompt");
5922
+ var patchPromptSchema = z.strictObject({
5838
5923
  name: promptSchema.shape.name.nullish(),
5839
5924
  description: promptSchema.shape.description.nullish(),
5840
5925
  prompt_data: promptSchema.shape.prompt_data.nullish(),
5841
5926
  tags: promptSchema.shape.tags.nullish()
5842
- }).strict().openapi("PatchPrompt");
5927
+ }).openapi("PatchPrompt");
5843
5928
  function capitalize(s, sep) {
5844
5929
  const items = sep ? s.split(sep) : [s];
5845
5930
  return items.map((s2) => s2 ? s2.charAt(0).toUpperCase() + s2.slice(1) : s2).join(sep || "");
@@ -5863,7 +5948,7 @@ var SpanTypeAttribute2 = /* @__PURE__ */ ((SpanTypeAttribute22) => {
5863
5948
  var auditSourcesSchema = z.enum(VALID_SOURCES2);
5864
5949
  function generateBaseEventOpSchema(objectType2) {
5865
5950
  const eventDescription = getEventObjectDescription(objectType2);
5866
- return z.object({
5951
+ return z.strictObject({
5867
5952
  id: z.string().describe(
5868
5953
  `A unique identifier for the ${eventDescription} event. If you don't provide one, BrainTrust will generate one for you`
5869
5954
  ),
@@ -5879,7 +5964,7 @@ function generateBaseEventOpSchema(objectType2) {
5879
5964
  metadata: z.record(customTypes.any).nullish().describe(
5880
5965
  "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"
5881
5966
  ),
5882
- metrics: z.object({
5967
+ metrics: z.strictObject({
5883
5968
  start: z.number().nullish().describe(
5884
5969
  `A unix timestamp recording when the section of code which produced the ${eventDescription} event started`
5885
5970
  ),
@@ -5889,7 +5974,7 @@ function generateBaseEventOpSchema(objectType2) {
5889
5974
  }).catchall(customTypes.any).nullish().describe(
5890
5975
  `Metrics are numerical measurements tracking the execution of the code that produced the ${eventDescription} event. Use "start" and "end" to track the time span over which the ${eventDescription} event was produced`
5891
5976
  ),
5892
- context: z.object({
5977
+ context: z.strictObject({
5893
5978
  caller_functionname: z.string().nullish().describe(
5894
5979
  `The function in code which created the ${eventDescription} event`
5895
5980
  ),
@@ -5911,7 +5996,7 @@ function generateBaseEventOpSchema(objectType2) {
5911
5996
  root_span_id: z.string().describe(
5912
5997
  `The \`span_id\` of the root of the trace this ${eventDescription} event belongs to`
5913
5998
  ),
5914
- span_attributes: z.object({
5999
+ span_attributes: z.strictObject({
5915
6000
  name: z.string().nullish().describe("Name of the span, for display purposes only"),
5916
6001
  type: z.nativeEnum(SpanTypeAttribute2).nullish().describe("Type of the span, for display purposes only")
5917
6002
  }).catchall(customTypes.any).nullish().describe(
@@ -5925,7 +6010,7 @@ function generateBaseEventOpSchema(objectType2) {
5925
6010
  function generateBaseEventFeedbackSchema(objectType2) {
5926
6011
  const eventObjectType = getEventObjectType(objectType2);
5927
6012
  const eventDescription = getEventObjectDescription(objectType2);
5928
- return z.object({
6013
+ return z.strictObject({
5929
6014
  id: z.string().describe(
5930
6015
  `The id of the ${eventDescription} event to log feedback for. This is the row \`id\` returned by \`POST /v1/${eventObjectType}/{${objectType2}_id}/insert\``
5931
6016
  ),
@@ -5966,7 +6051,7 @@ var versionSchema = z.string().describe(
5966
6051
  "The version id is essentially a filter on the latest event transaction id. You can use the `max_xact_id` returned by a past fetch as the version to reproduce that exact fetch."
5967
6052
  ].join("\n\n")
5968
6053
  );
5969
- var pathTypeFilterSchema = z.object({
6054
+ var pathTypeFilterSchema = z.strictObject({
5970
6055
  type: z.literal("path_lookup").describe("Denotes the type of filter as a path-lookup filter"),
5971
6056
  path: z.string().array().describe(
5972
6057
  'List of fields describing the path to the value to be checked against. For instance, if you wish to filter on the value of `c` in `{"input": {"a": {"b": {"c": "hello"}}}}`, pass `path=["input", "a", "b", "c"]`'
@@ -5977,7 +6062,7 @@ var pathTypeFilterSchema = z.object({
5977
6062
  }).describe(
5978
6063
  'A path-lookup filter describes an equality comparison against a specific sub-field in the event row. For instance, if you wish to filter on the value of `c` in `{"input": {"a": {"b": {"c": "hello"}}}}`, pass `path=["input", "a", "b", "c"]` and `value="hello"`'
5979
6064
  ).openapi("PathLookupFilter");
5980
- var sqlTypeFilterSchema = z.object({
6065
+ var sqlTypeFilterSchema = z.strictObject({
5981
6066
  type: z.literal("sql_filter").describe("Denotes the type of filter as a sql-type filter"),
5982
6067
  expr: z.string().describe(
5983
6068
  `A SQL expression in [duckDB syntax](https://duckdb.org/docs/sql/expressions/overview). For instance, if you wish to fuzzy-match the value of \`c\` in \`{"input": {"a": {"b": {"c": "hello"}}}}\`, pass \`expr="input->'a'->'b'->>'c' LIKE '%el%'"\`.`
@@ -5991,24 +6076,24 @@ var allFetchFiltersSchema = z.union([pathTypeFilterSchema, sqlTypeFilterSchema])
5991
6076
  var fetchFiltersSchema = pathTypeFilterSchema.array().describe(
5992
6077
  "A list of filters on the events to fetch. Currently, only path-lookup type filters are supported, but we may add more in the future"
5993
6078
  ).openapi("FetchEventsFilters");
5994
- var fetchEventsRequestSchema = z.object({
6079
+ var fetchEventsRequestSchema = z.strictObject({
5995
6080
  limit: fetchLimitSchema.nullish(),
5996
6081
  max_xact_id: maxXactIdSchema.nullish(),
5997
6082
  max_root_span_id: maxRootSpanIdSchema.nullish(),
5998
6083
  filters: fetchFiltersSchema.nullish(),
5999
6084
  version: versionSchema.nullish()
6000
- }).strict().openapi("FetchEventsRequest");
6085
+ }).openapi("FetchEventsRequest");
6001
6086
  function makeFetchEventsResponseSchema(objectType2, eventSchema) {
6002
6087
  const eventName = capitalize(getEventObjectType(objectType2), "_").replace(
6003
6088
  "_",
6004
6089
  ""
6005
6090
  );
6006
- return z.object({
6091
+ return z.strictObject({
6007
6092
  events: eventSchema.array().describe("A list of fetched events")
6008
- }).strict().openapi(`Fetch${eventName}EventsResponse`);
6093
+ }).openapi(`Fetch${eventName}EventsResponse`);
6009
6094
  }
6010
6095
  var experimentEventBaseSchema = generateBaseEventOpSchema("experiment");
6011
- var experimentEventSchema = z.object({
6096
+ var experimentEventSchema = z.strictObject({
6012
6097
  id: experimentEventBaseSchema.shape.id,
6013
6098
  dataset_record_id: z.string().nullish().describe(
6014
6099
  "If the experiment is associated to a dataset, this is the event-level dataset id this experiment event is tied to"
@@ -6037,9 +6122,9 @@ var experimentEventSchema = z.object({
6037
6122
  span_parents: experimentEventBaseSchema.shape.span_parents,
6038
6123
  root_span_id: experimentEventBaseSchema.shape.root_span_id,
6039
6124
  span_attributes: experimentEventBaseSchema.shape.span_attributes
6040
- }).strict().openapi("ExperimentEvent");
6125
+ }).openapi("ExperimentEvent");
6041
6126
  var datasetEventBaseSchema = generateBaseEventOpSchema("dataset");
6042
- var datasetEventSchema = z.object({
6127
+ var datasetEventSchema = z.strictObject({
6043
6128
  id: datasetEventBaseSchema.shape.id,
6044
6129
  [TRANSACTION_ID_FIELD2]: datasetEventBaseSchema.shape[TRANSACTION_ID_FIELD2],
6045
6130
  created: datasetEventBaseSchema.shape.created,
@@ -6055,9 +6140,9 @@ var datasetEventSchema = z.object({
6055
6140
  tags: datasetEventBaseSchema.shape.tags,
6056
6141
  span_id: datasetEventBaseSchema.shape.span_id,
6057
6142
  root_span_id: datasetEventBaseSchema.shape.root_span_id
6058
- }).strict().openapi("DatasetEvent");
6143
+ }).openapi("DatasetEvent");
6059
6144
  var projectLogsEventBaseSchema = generateBaseEventOpSchema("project");
6060
- var projectLogsEventSchema = z.object({
6145
+ var projectLogsEventSchema = z.strictObject({
6061
6146
  id: projectLogsEventBaseSchema.shape.id,
6062
6147
  [TRANSACTION_ID_FIELD2]: projectLogsEventBaseSchema.shape[TRANSACTION_ID_FIELD2],
6063
6148
  created: projectLogsEventBaseSchema.shape.created,
@@ -6084,12 +6169,12 @@ var projectLogsEventSchema = z.object({
6084
6169
  span_parents: projectLogsEventBaseSchema.shape.span_parents,
6085
6170
  root_span_id: projectLogsEventBaseSchema.shape.root_span_id,
6086
6171
  span_attributes: projectLogsEventBaseSchema.shape.span_attributes
6087
- }).strict().openapi("ProjectLogsEvent");
6172
+ }).openapi("ProjectLogsEvent");
6088
6173
  var isMergeDescription = [
6089
6174
  "The `_is_merge` field controls how the row is merged with any existing row with the same id in the DB. By default (or when set to `false`), the existing row is completely replaced by the new row. When set to `true`, the new row is deep-merged into the existing row",
6090
6175
  'For example, say there is an existing row in the DB `{"id": "foo", "input": {"a": 5, "b": 10}}`. If we merge a new row as `{"_is_merge": true, "id": "foo", "input": {"b": 11, "c": 20}}`, the new row will be `{"id": "foo", "input": {"a": 5, "b": 11, "c": 20}}`. If we replace the new row as `{"id": "foo", "input": {"b": 11, "c": 20}}`, the new row will be `{"id": "foo", "input": {"b": 11, "c": 20}}`'
6091
6176
  ].join("\n\n");
6092
- var mergeEventSchema = z.object({
6177
+ var mergeEventSchema = z.strictObject({
6093
6178
  [IS_MERGE_FIELD2]: customTypes.literalTrue.describe(isMergeDescription),
6094
6179
  [MERGE_PATHS_FIELD2]: z.string().array().array().nullish().describe(
6095
6180
  [
@@ -6098,7 +6183,7 @@ var mergeEventSchema = z.object({
6098
6183
  ].join("\n\n")
6099
6184
  )
6100
6185
  });
6101
- var replacementEventSchema = z.object({
6186
+ var replacementEventSchema = z.strictObject({
6102
6187
  [IS_MERGE_FIELD2]: customTypes.literalFalse.nullish().describe(isMergeDescription),
6103
6188
  [PARENT_ID_FIELD2]: z.string().nullish().describe(
6104
6189
  [
@@ -6114,25 +6199,25 @@ function makeInsertEventSchemas(objectType2, insertSchema) {
6114
6199
  getEventObjectType(objectType2),
6115
6200
  "_"
6116
6201
  ).replace("_", "");
6117
- const replaceVariantSchema = insertSchema.merge(replacementEventSchema).strict().openapi(`Insert${eventSchemaName}EventReplace`);
6118
- const mergeVariantSchema = insertSchema.merge(mergeEventSchema).strict().openapi(`Insert${eventSchemaName}EventMerge`);
6202
+ const replaceVariantSchema = insertSchema.merge(replacementEventSchema).openapi(`Insert${eventSchemaName}EventReplace`);
6203
+ const mergeVariantSchema = insertSchema.merge(mergeEventSchema).openapi(`Insert${eventSchemaName}EventMerge`);
6119
6204
  const eventSchema = z.union([replaceVariantSchema, mergeVariantSchema]).describe(`${capitalize(article)} ${eventDescription} event`).openapi(`Insert${eventSchemaName}Event`);
6120
- const requestSchema = z.object({
6205
+ const requestSchema = z.strictObject({
6121
6206
  events: eventSchema.array().describe(`A list of ${eventDescription} events to insert`)
6122
- }).strict().openapi(`Insert${eventSchemaName}EventRequest`);
6207
+ }).openapi(`Insert${eventSchemaName}EventRequest`);
6123
6208
  return { eventSchema, requestSchema };
6124
6209
  }
6125
- var insertEventsResponseSchema = z.object({
6210
+ var insertEventsResponseSchema = z.strictObject({
6126
6211
  row_ids: z.string().array().describe(
6127
6212
  "The ids of all rows that were inserted, aligning one-to-one with the rows provided as input"
6128
6213
  )
6129
- }).strict().openapi("InsertEventsResponse");
6214
+ }).openapi("InsertEventsResponse");
6130
6215
  var {
6131
6216
  eventSchema: insertExperimentEventSchema,
6132
6217
  requestSchema: insertExperimentEventsRequestSchema
6133
6218
  } = makeInsertEventSchemas(
6134
6219
  "experiment",
6135
- z.object({
6220
+ z.strictObject({
6136
6221
  input: experimentEventSchema.shape.input,
6137
6222
  output: experimentEventSchema.shape.output,
6138
6223
  expected: experimentEventSchema.shape.expected,
@@ -6145,28 +6230,28 @@ var {
6145
6230
  id: experimentEventSchema.shape.id.nullish(),
6146
6231
  dataset_record_id: experimentEventSchema.shape.dataset_record_id,
6147
6232
  [OBJECT_DELETE_FIELD]: experimentEventBaseSchema.shape[OBJECT_DELETE_FIELD]
6148
- }).strict()
6233
+ })
6149
6234
  );
6150
6235
  var {
6151
6236
  eventSchema: insertDatasetEventSchema,
6152
6237
  requestSchema: insertDatasetEventsRequestSchema
6153
6238
  } = makeInsertEventSchemas(
6154
6239
  "dataset",
6155
- z.object({
6240
+ z.strictObject({
6156
6241
  input: datasetEventSchema.shape.input,
6157
6242
  expected: datasetEventSchema.shape.expected,
6158
6243
  metadata: datasetEventSchema.shape.metadata,
6159
6244
  tags: datasetEventSchema.shape.tags,
6160
6245
  id: datasetEventSchema.shape.id.nullish(),
6161
6246
  [OBJECT_DELETE_FIELD]: datasetEventBaseSchema.shape[OBJECT_DELETE_FIELD]
6162
- }).strict()
6247
+ })
6163
6248
  );
6164
6249
  var {
6165
6250
  eventSchema: insertProjectLogsEventSchema,
6166
6251
  requestSchema: insertProjectLogsEventsRequestSchema
6167
6252
  } = makeInsertEventSchemas(
6168
6253
  "project",
6169
- z.object({
6254
+ z.strictObject({
6170
6255
  input: projectLogsEventSchema.shape.input,
6171
6256
  output: projectLogsEventSchema.shape.output,
6172
6257
  expected: projectLogsEventSchema.shape.expected,
@@ -6178,7 +6263,7 @@ var {
6178
6263
  span_attributes: projectLogsEventSchema.shape.span_attributes,
6179
6264
  id: projectLogsEventSchema.shape.id.nullish(),
6180
6265
  [OBJECT_DELETE_FIELD]: projectLogsEventBaseSchema.shape[OBJECT_DELETE_FIELD]
6181
- }).strict()
6266
+ })
6182
6267
  );
6183
6268
  function makeFeedbackRequestSchema(objectType2, feedbackSchema) {
6184
6269
  const eventDescription = getEventObjectDescription(objectType2);
@@ -6186,54 +6271,54 @@ function makeFeedbackRequestSchema(objectType2, feedbackSchema) {
6186
6271
  getEventObjectType(objectType2),
6187
6272
  "_"
6188
6273
  ).replace("_", "");
6189
- return z.object({
6274
+ return z.strictObject({
6190
6275
  feedback: feedbackSchema.array().describe(`A list of ${eventDescription} feedback items`)
6191
- }).strict().openapi(`Feedback${eventSchemaName}EventRequest`);
6276
+ }).openapi(`Feedback${eventSchemaName}EventRequest`);
6192
6277
  }
6193
6278
  var feedbackExperimentRequestBaseSchema = generateBaseEventFeedbackSchema("experiment");
6194
- var feedbackExperimentItemSchema = z.object({
6279
+ var feedbackExperimentItemSchema = z.strictObject({
6195
6280
  id: feedbackExperimentRequestBaseSchema.shape.id,
6196
6281
  scores: feedbackExperimentRequestBaseSchema.shape.scores,
6197
6282
  expected: feedbackExperimentRequestBaseSchema.shape.expected,
6198
6283
  comment: feedbackExperimentRequestBaseSchema.shape.comment,
6199
6284
  metadata: feedbackExperimentRequestBaseSchema.shape.metadata,
6200
6285
  source: feedbackExperimentRequestBaseSchema.shape.source
6201
- }).strict().openapi("FeedbackExperimentItem");
6286
+ }).openapi("FeedbackExperimentItem");
6202
6287
  var feedbackExperimentRequestSchema = makeFeedbackRequestSchema(
6203
6288
  "experiment",
6204
6289
  feedbackExperimentItemSchema
6205
6290
  );
6206
6291
  var feedbackDatasetRequestBaseSchema = generateBaseEventFeedbackSchema("dataset");
6207
- var feedbackDatasetItemSchema = z.object({
6292
+ var feedbackDatasetItemSchema = z.strictObject({
6208
6293
  id: feedbackDatasetRequestBaseSchema.shape.id,
6209
6294
  comment: feedbackDatasetRequestBaseSchema.shape.comment,
6210
6295
  metadata: feedbackDatasetRequestBaseSchema.shape.metadata,
6211
6296
  source: feedbackDatasetRequestBaseSchema.shape.source
6212
- }).strict().openapi("FeedbackDatasetItem");
6297
+ }).openapi("FeedbackDatasetItem");
6213
6298
  var feedbackDatasetRequestSchema = makeFeedbackRequestSchema(
6214
6299
  "dataset",
6215
6300
  feedbackDatasetItemSchema
6216
6301
  );
6217
6302
  var feedbackProjectLogsRequestBaseSchema = generateBaseEventFeedbackSchema("project");
6218
- var feedbackProjectLogsItemSchema = z.object({
6303
+ var feedbackProjectLogsItemSchema = z.strictObject({
6219
6304
  id: feedbackProjectLogsRequestBaseSchema.shape.id,
6220
6305
  scores: feedbackProjectLogsRequestBaseSchema.shape.scores,
6221
6306
  expected: feedbackProjectLogsRequestBaseSchema.shape.expected,
6222
6307
  comment: feedbackProjectLogsRequestBaseSchema.shape.comment,
6223
6308
  metadata: feedbackProjectLogsRequestBaseSchema.shape.metadata,
6224
6309
  source: feedbackProjectLogsRequestBaseSchema.shape.source
6225
- }).strict().openapi("FeedbackProjectLogsItem");
6310
+ }).openapi("FeedbackProjectLogsItem");
6226
6311
  var feedbackProjectLogsRequestSchema = makeFeedbackRequestSchema(
6227
6312
  "project",
6228
6313
  feedbackProjectLogsItemSchema
6229
6314
  );
6230
6315
  var feedbackPromptRequestBaseSchema = generateBaseEventFeedbackSchema("prompt");
6231
- var feedbackPromptItemSchema = z.object({
6316
+ var feedbackPromptItemSchema = z.strictObject({
6232
6317
  id: feedbackPromptRequestBaseSchema.shape.id,
6233
6318
  comment: feedbackPromptRequestBaseSchema.shape.comment,
6234
6319
  metadata: feedbackPromptRequestBaseSchema.shape.metadata,
6235
6320
  source: feedbackPromptRequestBaseSchema.shape.source
6236
- }).strict().openapi("FeedbackPromptItem");
6321
+ }).openapi("FeedbackPromptItem");
6237
6322
  var feedbackPromptRequestSchema = makeFeedbackRequestSchema(
6238
6323
  "prompt",
6239
6324
  feedbackPromptItemSchema
@@ -6278,12 +6363,12 @@ function makeCrossObjectIndividualRequestSchema(objectType2) {
6278
6363
  const eventObjectType = getEventObjectType(objectType2);
6279
6364
  const eventDescription = getEventObjectDescription(objectType2);
6280
6365
  const eventObjectSchema = eventObjectSchemas[eventObjectType];
6281
- const insertObject = z.object({
6366
+ const insertObject = z.strictObject({
6282
6367
  ...eventObjectSchema.insertEvent ? {
6283
6368
  events: eventObjectSchema.insertEvent.array().nullish().describe(`A list of ${eventDescription} events to insert`)
6284
6369
  } : {},
6285
6370
  feedback: eventObjectSchema.feedbackItem.array().nullish().describe(`A list of ${eventDescription} feedback items`)
6286
- }).strict();
6371
+ });
6287
6372
  return z.record(z.string().uuid(), insertObject).nullish().describe(
6288
6373
  `A mapping from ${objectType2} id to a set of log events and feedback items to insert`
6289
6374
  );
@@ -6293,18 +6378,16 @@ function makeCrossObjectIndividualResponseSchema(objectType2) {
6293
6378
  `A mapping from ${objectType2} id to row ids for inserted \`events\``
6294
6379
  );
6295
6380
  }
6296
- var crossObjectInsertRequestSchema = z.object({
6381
+ var crossObjectInsertRequestSchema = z.strictObject({
6297
6382
  experiment: makeCrossObjectIndividualRequestSchema("experiment"),
6298
6383
  dataset: makeCrossObjectIndividualRequestSchema("dataset"),
6299
- project_logs: makeCrossObjectIndividualRequestSchema("project"),
6300
- prompt: makeCrossObjectIndividualRequestSchema("prompt")
6301
- }).strict().openapi("CrossObjectInsertRequest");
6302
- var crossObjectInsertResponseSchema = z.object({
6384
+ project_logs: makeCrossObjectIndividualRequestSchema("project")
6385
+ }).openapi("CrossObjectInsertRequest");
6386
+ var crossObjectInsertResponseSchema = z.strictObject({
6303
6387
  experiment: makeCrossObjectIndividualResponseSchema("experiment"),
6304
6388
  dataset: makeCrossObjectIndividualResponseSchema("dataset"),
6305
- project_logs: makeCrossObjectIndividualResponseSchema("project"),
6306
- prompt: makeCrossObjectIndividualResponseSchema("prompt")
6307
- }).strict().openapi("CrossObjectInsertResponse");
6389
+ project_logs: makeCrossObjectIndividualResponseSchema("project")
6390
+ }).openapi("CrossObjectInsertResponse");
6308
6391
  var summarizeScoresParamSchema = z.boolean().describe(
6309
6392
  "Whether to summarize the scores and metrics. If false (or omitted), only the metadata will be returned."
6310
6393
  );
@@ -6314,14 +6397,14 @@ var comparisonExperimentIdParamSchema = z.string().uuid().describe(
6314
6397
  var summarizeDataParamSchema = z.boolean().describe(
6315
6398
  "Whether to summarize the data. If false (or omitted), only the metadata will be returned."
6316
6399
  );
6317
- var summarizeExperimentResponseSchema = z.object({
6400
+ var summarizeExperimentResponseSchema = z.strictObject({
6318
6401
  project_name: z.string().describe("Name of the project that the experiment belongs to"),
6319
6402
  experiment_name: z.string().describe("Name of the experiment"),
6320
6403
  project_url: z.string().url().describe("URL to the project's page in the Braintrust app"),
6321
6404
  experiment_url: z.string().url().describe("URL to the experiment's page in the Braintrust app"),
6322
6405
  comparison_experiment_name: z.string().nullish().describe("The experiment which scores are baselined against"),
6323
6406
  scores: z.record(
6324
- z.object({
6407
+ z.strictObject({
6325
6408
  name: z.string().describe("Name of the score"),
6326
6409
  score: z.number().min(0).max(1).describe("Average score across all examples"),
6327
6410
  diff: z.number().min(-1).max(1).describe(
@@ -6332,7 +6415,7 @@ var summarizeExperimentResponseSchema = z.object({
6332
6415
  }).describe("Summary of a score's performance").openapi("ScoreSummary")
6333
6416
  ).nullish().describe("Summary of the experiment's scores"),
6334
6417
  metrics: z.record(
6335
- z.object({
6418
+ z.strictObject({
6336
6419
  name: z.string().describe("Name of the metric"),
6337
6420
  metric: z.number().describe("Average metric across all examples"),
6338
6421
  unit: z.string().describe("Unit label for the metric"),
@@ -6343,16 +6426,16 @@ var summarizeExperimentResponseSchema = z.object({
6343
6426
  regressions: z.number().int().min(0).describe("Number of regressions in the metric")
6344
6427
  }).describe("Summary of a metric's performance").openapi("MetricSummary")
6345
6428
  ).nullish().describe("Summary of the experiment's metrics")
6346
- }).strict().describe("Summary of an experiment").openapi("SummarizeExperimentResponse");
6347
- var summarizeDatasetResponseSchema = z.object({
6429
+ }).describe("Summary of an experiment").openapi("SummarizeExperimentResponse");
6430
+ var summarizeDatasetResponseSchema = z.strictObject({
6348
6431
  project_name: z.string().describe("Name of the project that the dataset belongs to"),
6349
6432
  dataset_name: z.string().describe("Name of the dataset"),
6350
6433
  project_url: z.string().url().describe("URL to the project's page in the Braintrust app"),
6351
6434
  dataset_url: z.string().url().describe("URL to the dataset's page in the Braintrust app"),
6352
- data_summary: z.object({
6435
+ data_summary: z.strictObject({
6353
6436
  total_records: z.number().int().min(0).describe("Total number of records in the dataset")
6354
6437
  }).nullish().describe("Summary of a dataset's data").openapi("DataSummary")
6355
- }).strict().describe("Summary of a dataset").openapi("SummarizeDatasetResponse");
6438
+ }).describe("Summary of a dataset").openapi("SummarizeDatasetResponse");
6356
6439
 
6357
6440
  // src/util.ts
6358
6441
  var GLOBAL_PROJECT = "Global";
@@ -6866,7 +6949,7 @@ var NoopSpan = class {
6866
6949
  }
6867
6950
  log(_) {
6868
6951
  }
6869
- logFeedback(event) {
6952
+ logFeedback(_event) {
6870
6953
  }
6871
6954
  traced(callback, _1) {
6872
6955
  return callback(this);
@@ -6877,6 +6960,11 @@ var NoopSpan = class {
6877
6960
  end(args) {
6878
6961
  return args?.endTime ?? getCurrentUnixTimestamp();
6879
6962
  }
6963
+ async export() {
6964
+ return "";
6965
+ }
6966
+ async flush() {
6967
+ }
6880
6968
  close(args) {
6881
6969
  return this.end(args);
6882
6970
  }
@@ -6889,6 +6977,11 @@ var BraintrustState = class {
6889
6977
  // (safely) dynamically cast it whenever retrieving the logger.
6890
6978
  currentLogger;
6891
6979
  currentSpan;
6980
+ // Any time we re-log in, we directly update the logConn inside the logger.
6981
+ // This is preferable to replacing the whole logger, which would create the
6982
+ // possibility of multiple loggers floating around, which may not log in a
6983
+ // deterministic order.
6984
+ _globalBgLogger;
6892
6985
  appUrl = null;
6893
6986
  appPublicUrl = null;
6894
6987
  loginToken = null;
@@ -6904,6 +6997,13 @@ var BraintrustState = class {
6904
6997
  this.currentExperiment = void 0;
6905
6998
  this.currentLogger = void 0;
6906
6999
  this.currentSpan = isomorph_default.newAsyncLocalStorage();
7000
+ const defaultGetLogConn = async () => {
7001
+ await login();
7002
+ return this.logConn();
7003
+ };
7004
+ this._globalBgLogger = new BackgroundLogger(
7005
+ new LazyValue(defaultGetLogConn)
7006
+ );
6907
7007
  this.resetLoginInfo();
6908
7008
  globalThis.__inherited_braintrust_state = this;
6909
7009
  }
@@ -6936,6 +7036,13 @@ var BraintrustState = class {
6936
7036
  }
6937
7037
  return this._logConn;
6938
7038
  }
7039
+ globalBgLogger() {
7040
+ return this._globalBgLogger;
7041
+ }
7042
+ // Should only be called by the login function.
7043
+ loginReplaceLogConn(logConn) {
7044
+ this._globalBgLogger.internalReplaceLogConn(logConn);
7045
+ }
6939
7046
  };
6940
7047
  var _state;
6941
7048
  function _internalSetInitialState() {
@@ -7003,7 +7110,8 @@ var HTTPConnection = class _HTTPConnection {
7003
7110
  this.headers["Authorization"] = `Bearer ${this.token}`;
7004
7111
  }
7005
7112
  }
7006
- async get(path, params = void 0) {
7113
+ async get(path, params = void 0, config) {
7114
+ const { headers, ...rest } = config || {};
7007
7115
  const url = new URL(_urljoin(this.base_url, path));
7008
7116
  url.search = new URLSearchParams(
7009
7117
  params ? Object.fromEntries(
@@ -7013,8 +7121,12 @@ var HTTPConnection = class _HTTPConnection {
7013
7121
  return await checkResponse(
7014
7122
  // Using toString() here makes it work with isomorphic fetch
7015
7123
  await fetch(url.toString(), {
7016
- headers: this.headers,
7017
- keepalive: true
7124
+ headers: {
7125
+ ...this.headers,
7126
+ ...headers
7127
+ },
7128
+ keepalive: true,
7129
+ ...rest
7018
7130
  })
7019
7131
  );
7020
7132
  }
@@ -7058,7 +7170,7 @@ var HTTPConnection = class _HTTPConnection {
7058
7170
  return await resp.json();
7059
7171
  }
7060
7172
  };
7061
- function logFeedbackImpl(bgLogger, parentIds, {
7173
+ function logFeedbackImpl(parentObjectType, parentObjectId, {
7062
7174
  id,
7063
7175
  expected,
7064
7176
  scores,
@@ -7086,22 +7198,23 @@ function logFeedbackImpl(bgLogger, parentIds, {
7086
7198
  updateEvent = Object.fromEntries(
7087
7199
  Object.entries(updateEvent).filter(([_, v]) => !isEmpty(v))
7088
7200
  );
7089
- const trueParentIds = new LazyValue(async () => {
7090
- const { kind, ...ids } = await parentIds.get();
7091
- return ids;
7092
- });
7201
+ const parentIds = async () => new SpanParentComponents({
7202
+ objectType: parentObjectType,
7203
+ objectId: await parentObjectId.get(),
7204
+ rowId: ""
7205
+ }).asDict();
7093
7206
  if (Object.keys(updateEvent).length > 0) {
7094
7207
  const record = new LazyValue(async () => {
7095
7208
  return {
7096
7209
  id,
7097
7210
  ...updateEvent,
7098
- ...await trueParentIds.get(),
7211
+ ...await parentIds(),
7099
7212
  [AUDIT_SOURCE_FIELD]: source,
7100
7213
  [AUDIT_METADATA_FIELD]: metadata,
7101
7214
  [IS_MERGE_FIELD]: true
7102
7215
  };
7103
7216
  });
7104
- bgLogger.log([record]);
7217
+ _state.globalBgLogger().log([record]);
7105
7218
  }
7106
7219
  if (!isEmpty(comment)) {
7107
7220
  const record = new LazyValue(async () => {
@@ -7116,29 +7229,63 @@ function logFeedbackImpl(bgLogger, parentIds, {
7116
7229
  comment: {
7117
7230
  text: comment
7118
7231
  },
7119
- ...await trueParentIds.get(),
7232
+ ...await parentIds(),
7120
7233
  [AUDIT_SOURCE_FIELD]: source,
7121
7234
  [AUDIT_METADATA_FIELD]: metadata
7122
7235
  };
7123
7236
  });
7124
- bgLogger.log([record]);
7237
+ _state.globalBgLogger().log([record]);
7238
+ }
7239
+ }
7240
+ function startSpanParentArgs(args) {
7241
+ if (args.parent && args.parentId) {
7242
+ throw new Error(
7243
+ "Cannot specify both `parent` and `parentId`. Prefer `parent"
7244
+ );
7245
+ }
7246
+ let parentObjectId = void 0;
7247
+ let parentRowId = void 0;
7248
+ if (args.parent) {
7249
+ const parentComponents = SpanParentComponents.fromStr(args.parent);
7250
+ if (args.spanParentObjectType !== parentComponents.objectType) {
7251
+ throw new Error(
7252
+ `Mismatch between expected span parent object type ${args.spanParentObjectType} and provided type ${parentComponents.objectType}`
7253
+ );
7254
+ }
7255
+ const computeParentObjectId = async () => {
7256
+ if (await args.spanParentObjectId.get() !== parentComponents.objectId) {
7257
+ throw new Error(
7258
+ `Mismatch between expected span parent object id ${await args.spanParentObjectId.get()} and provided id ${parentComponents.objectId}`
7259
+ );
7260
+ }
7261
+ return await args.spanParentObjectId.get();
7262
+ };
7263
+ parentObjectId = new LazyValue(computeParentObjectId);
7264
+ parentRowId = parentComponents.rowId;
7265
+ } else {
7266
+ parentObjectId = args.spanParentObjectId;
7267
+ parentRowId = args.parentId ?? "";
7125
7268
  }
7269
+ return {
7270
+ parentObjectType: args.spanParentObjectType,
7271
+ parentObjectId,
7272
+ parentRowId
7273
+ };
7126
7274
  }
7127
7275
  var Logger = class {
7128
7276
  lazyMetadata;
7129
7277
  logOptions;
7130
- bgLogger;
7131
7278
  lastStartTime;
7279
+ lazyId;
7280
+ calledStartSpan;
7132
7281
  // For type identification.
7133
7282
  kind = "logger";
7134
7283
  constructor(lazyMetadata, logOptions = {}) {
7135
7284
  this.lazyMetadata = lazyMetadata;
7136
7285
  this.logOptions = logOptions;
7137
- const logConn = new LazyValue(
7138
- () => this.getState().then((state) => state.logConn())
7139
- );
7140
- this.bgLogger = new BackgroundLogger(logConn);
7141
7286
  this.lastStartTime = getCurrentUnixTimestamp();
7287
+ this.lazyId = new LazyValue(async () => await this.id);
7288
+ this.calledStartSpan = false;
7142
7289
  }
7143
7290
  get org_id() {
7144
7291
  return (async () => {
@@ -7150,6 +7297,12 @@ var Logger = class {
7150
7297
  return (await this.lazyMetadata.get()).project;
7151
7298
  })();
7152
7299
  }
7300
+ get id() {
7301
+ return (async () => (await this.project).id)();
7302
+ }
7303
+ spanParentObjectType() {
7304
+ return SpanParentObjectType.PROJECT_LOGS;
7305
+ }
7153
7306
  async getState() {
7154
7307
  await this.lazyMetadata.get();
7155
7308
  return _state;
@@ -7166,19 +7319,16 @@ var Logger = class {
7166
7319
  * @param event.metrics: (Optional) a dictionary of metrics to log. The following keys are populated automatically: "start", "end".
7167
7320
  * @param event.id: (Optional) a unique identifier for the event. If you don't provide one, BrainTrust will generate one for you.
7168
7321
  * @param options Additional logging options
7169
- * @param options.allowLogConcurrentWithActiveSpan in rare cases where you need to log at the top level separately from an active span on the logger, set this to true.
7322
+ * @param options.allowConcurrentWithSpans in rare cases where you need to log at the top level separately from spans on the logger elsewhere, set this to true.
7170
7323
  * :returns: The `id` of the logged event.
7171
7324
  */
7172
7325
  log(event, options) {
7173
- if (!options?.allowLogConcurrentWithActiveSpan) {
7174
- const checkCurrentSpan = currentSpan();
7175
- if (checkCurrentSpan instanceof SpanImpl && checkCurrentSpan.parentObject === this) {
7176
- throw new Error(
7177
- "Cannot run toplevel Logger.log method while there is an active span. To log to the span, use Span.log"
7178
- );
7179
- }
7326
+ if (this.calledStartSpan && !options?.allowConcurrentWithSpans) {
7327
+ throw new Error(
7328
+ "Cannot run toplevel `log` method while using spans. To log to the span, call `logger.traced` and then log with `span.log`"
7329
+ );
7180
7330
  }
7181
- const span = this.startSpan({ startTime: this.lastStartTime, event });
7331
+ const span = this.startSpanImpl({ startTime: this.lastStartTime, event });
7182
7332
  this.lastStartTime = span.end();
7183
7333
  const ret = span.id;
7184
7334
  if (this.logOptions.asyncFlush === true) {
@@ -7218,14 +7368,6 @@ var Logger = class {
7218
7368
  })();
7219
7369
  }
7220
7370
  }
7221
- async lazyParentIds() {
7222
- return {
7223
- kind: "project_log",
7224
- org_id: await this.org_id,
7225
- project_id: (await this.project).id,
7226
- log_id: "g"
7227
- };
7228
- }
7229
7371
  /**
7230
7372
  * Lower-level alternative to `traced`. This allows you to start a span yourself, and can be useful in situations
7231
7373
  * where you cannot use callbacks. However, spans started with `startSpan` will not be marked as the "current span",
@@ -7234,14 +7376,19 @@ var Logger = class {
7234
7376
  * See `traced` for full details.
7235
7377
  */
7236
7378
  startSpan(args) {
7237
- const { name, type, ...argsRest } = args ?? {};
7379
+ this.calledStartSpan = true;
7380
+ return this.startSpanImpl(args);
7381
+ }
7382
+ startSpanImpl(args) {
7238
7383
  return new SpanImpl({
7239
- parentObject: this,
7240
- parentIds: new LazyValue(() => this.lazyParentIds()),
7241
- bgLogger: this.bgLogger,
7242
- name: name ?? "root",
7243
- type: type ?? SpanTypeAttribute.TASK,
7244
- ...argsRest
7384
+ ...startSpanParentArgs({
7385
+ parent: args?.parent,
7386
+ parentId: args?.parentId,
7387
+ spanParentObjectType: this.spanParentObjectType(),
7388
+ spanParentObjectId: this.lazyId
7389
+ }),
7390
+ ...args,
7391
+ defaultRootType: SpanTypeAttribute.TASK
7245
7392
  });
7246
7393
  }
7247
7394
  /**
@@ -7256,17 +7403,23 @@ var Logger = class {
7256
7403
  * @param event.source (Optional) the source of the feedback. Must be one of "external" (default), "app", or "api".
7257
7404
  */
7258
7405
  logFeedback(event) {
7259
- logFeedbackImpl(
7260
- this.bgLogger,
7261
- new LazyValue(() => this.lazyParentIds()),
7262
- event
7263
- );
7406
+ logFeedbackImpl(this.spanParentObjectType(), this.lazyId, event);
7407
+ }
7408
+ /**
7409
+ * Return a serialized representation of the logger that can be used to start subspans in other places. See `Span.start_span` for more details.
7410
+ */
7411
+ async export() {
7412
+ return new SpanParentComponents({
7413
+ objectType: this.spanParentObjectType(),
7414
+ objectId: await this.id,
7415
+ rowId: ""
7416
+ }).toStr();
7264
7417
  }
7265
7418
  /*
7266
7419
  * Flush any pending logs to the server.
7267
7420
  */
7268
7421
  async flush() {
7269
- return await this.bgLogger.flush();
7422
+ return await _state.globalBgLogger().flush();
7270
7423
  }
7271
7424
  get asyncFlush() {
7272
7425
  return this.logOptions.asyncFlush;
@@ -7293,6 +7446,7 @@ var BackgroundLogger = class {
7293
7446
  items = [];
7294
7447
  activeFlush = Promise.resolve();
7295
7448
  activeFlushResolved = true;
7449
+ activeFlushError = void 0;
7296
7450
  syncFlush = false;
7297
7451
  // 6 MB for the AWS lambda gateway (from our own testing).
7298
7452
  maxRequestSize = 6 * 1024 * 1024;
@@ -7333,6 +7487,11 @@ var BackgroundLogger = class {
7333
7487
  this.triggerActiveFlush();
7334
7488
  }
7335
7489
  await this.activeFlush;
7490
+ if (this.activeFlushError) {
7491
+ const err = this.activeFlushError;
7492
+ this.activeFlushError = void 0;
7493
+ throw err;
7494
+ }
7336
7495
  }
7337
7496
  async flushOnce(args) {
7338
7497
  const batchSize = args?.batchSize ?? this.defaultBatchSize;
@@ -7450,11 +7609,22 @@ Error: ${errorText}`;
7450
7609
  triggerActiveFlush() {
7451
7610
  if (this.activeFlushResolved) {
7452
7611
  this.activeFlushResolved = false;
7453
- this.activeFlush = this.flushOnce().finally(() => {
7454
- this.activeFlushResolved = true;
7455
- });
7612
+ this.activeFlushError = void 0;
7613
+ this.activeFlush = (async () => {
7614
+ try {
7615
+ await this.flushOnce();
7616
+ } catch (err) {
7617
+ this.activeFlushError = err;
7618
+ } finally {
7619
+ this.activeFlushResolved = true;
7620
+ }
7621
+ })();
7456
7622
  }
7457
7623
  }
7624
+ // Should only be called by BraintrustState.
7625
+ internalReplaceLogConn(logConn) {
7626
+ this.logConn = new LazyValue(async () => logConn);
7627
+ }
7458
7628
  };
7459
7629
  function init(projectOrOptions, optionalOptions) {
7460
7630
  const options = (() => {
@@ -7520,7 +7690,7 @@ function init(projectOrOptions, optionalOptions) {
7520
7690
  return {
7521
7691
  project: {
7522
7692
  id: info.project_id,
7523
- name: "",
7693
+ name: project ?? "UNKNOWN_PROJECT",
7524
7694
  fullInfo: {}
7525
7695
  },
7526
7696
  experiment: {
@@ -7884,6 +8054,7 @@ async function login(options = {}) {
7884
8054
  _state.apiConn().set_token(apiKey);
7885
8055
  _state.loginToken = conn.token;
7886
8056
  _state.loggedIn = true;
8057
+ _state.loginReplaceLogConn(conn);
7887
8058
  }
7888
8059
  function log(event) {
7889
8060
  console.warn(
@@ -7930,7 +8101,7 @@ function getSpanParentObject(options) {
7930
8101
  return NOOP_SPAN;
7931
8102
  }
7932
8103
  function traced(callback, args) {
7933
- const { span, parentObject } = startSpanReturnParent(args);
8104
+ const { span, isLogger } = startSpanAndIsLogger(args);
7934
8105
  const ret = runFinally(
7935
8106
  () => {
7936
8107
  if (args?.setCurrent ?? true) {
@@ -7946,23 +8117,44 @@ function traced(callback, args) {
7946
8117
  } else {
7947
8118
  return (async () => {
7948
8119
  const awaitedRet = await ret;
7949
- if (parentObject.kind === "logger") {
7950
- await parentObject.flush();
8120
+ if (isLogger) {
8121
+ await span.flush();
7951
8122
  }
7952
8123
  return awaitedRet;
7953
8124
  })();
7954
8125
  }
7955
8126
  }
7956
8127
  function startSpan(args) {
7957
- return startSpanReturnParent(args).span;
8128
+ return startSpanAndIsLogger(args).span;
7958
8129
  }
7959
- function startSpanReturnParent(args) {
7960
- const parentObject = getSpanParentObject({
7961
- asyncFlush: args?.asyncFlush
7962
- });
7963
- const { name: nameOpt, ...argsRest } = args ?? {};
7964
- const name = parentObject.kind === "span" ? nameOpt : nameOpt ?? "root";
7965
- return { span: parentObject.startSpan({ name, ...argsRest }), parentObject };
8130
+ async function flush() {
8131
+ return await _state.globalBgLogger().flush();
8132
+ }
8133
+ function startSpanAndIsLogger(args) {
8134
+ if (args?.parent) {
8135
+ if (args?.parentId) {
8136
+ throw new Error(
8137
+ "Cannot specify both `parent` and `parent_id`. Prefer `parent`"
8138
+ );
8139
+ }
8140
+ const components = SpanParentComponents.fromStr(args?.parent);
8141
+ const span = new SpanImpl({
8142
+ ...args,
8143
+ parentObjectType: components.objectType,
8144
+ parentObjectId: new LazyValue(async () => components.objectId),
8145
+ parentRowId: components.rowId
8146
+ });
8147
+ return {
8148
+ span,
8149
+ isLogger: components.objectType === SpanParentObjectType.PROJECT_LOGS
8150
+ };
8151
+ } else {
8152
+ const parentObject = getSpanParentObject({
8153
+ asyncFlush: args?.asyncFlush
8154
+ });
8155
+ const span = parentObject.startSpan(args);
8156
+ return { span, isLogger: parentObject.kind === "logger" };
8157
+ }
7966
8158
  }
7967
8159
  function withCurrent(span, callback) {
7968
8160
  return _state.currentSpan.run(span, () => callback(span));
@@ -8099,23 +8291,14 @@ var ObjectFetcher = class {
8099
8291
  async fetchedData() {
8100
8292
  if (this._fetchedData === void 0) {
8101
8293
  const state = await this.getState();
8102
- let data = void 0;
8103
- try {
8104
- const resp = await state.logConn().get(`object3/${this.objectType}`, {
8105
- id: await this.id,
8106
- fmt: "json2",
8107
- version: this.pinnedVersion,
8108
- api_version: "2"
8109
- });
8110
- data = await resp.json();
8111
- } catch (e) {
8112
- const resp = await state.logConn().get(`object/${this.objectType}`, {
8113
- id: await this.id,
8114
- fmt: "json2",
8294
+ const resp = await state.logConn().get(
8295
+ `v1/${this.objectType}/${await this.id}/fetch`,
8296
+ {
8115
8297
  version: this.pinnedVersion
8116
- });
8117
- data = await resp.json();
8118
- }
8298
+ },
8299
+ { headers: { "Accept-Encoding": "identity" } }
8300
+ );
8301
+ const data = (await resp.json()).events;
8119
8302
  this._fetchedData = this.mutateRecord ? data?.map(this.mutateRecord) : data;
8120
8303
  }
8121
8304
  return this._fetchedData || [];
@@ -8142,19 +8325,18 @@ var ObjectFetcher = class {
8142
8325
  var Experiment = class extends ObjectFetcher {
8143
8326
  lazyMetadata;
8144
8327
  dataset;
8145
- bgLogger;
8146
8328
  lastStartTime;
8329
+ lazyId;
8330
+ calledStartSpan;
8147
8331
  // For type identification.
8148
8332
  kind = "experiment";
8149
8333
  constructor(lazyMetadata, dataset) {
8150
8334
  super("experiment", void 0);
8151
8335
  this.lazyMetadata = lazyMetadata;
8152
8336
  this.dataset = dataset;
8153
- const logConn = new LazyValue(
8154
- () => this.getState().then((state) => state.logConn())
8155
- );
8156
- this.bgLogger = new BackgroundLogger(logConn);
8157
8337
  this.lastStartTime = getCurrentUnixTimestamp();
8338
+ this.lazyId = new LazyValue(async () => await this.id);
8339
+ this.calledStartSpan = false;
8158
8340
  }
8159
8341
  get id() {
8160
8342
  return (async () => {
@@ -8171,6 +8353,9 @@ var Experiment = class extends ObjectFetcher {
8171
8353
  return (await this.lazyMetadata.get()).project;
8172
8354
  })();
8173
8355
  }
8356
+ spanParentObjectType() {
8357
+ return SpanParentObjectType.EXPERIMENT;
8358
+ }
8174
8359
  async getState() {
8175
8360
  await this.lazyMetadata.get();
8176
8361
  return _state;
@@ -8189,20 +8374,17 @@ var Experiment = class extends ObjectFetcher {
8189
8374
  * @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.
8190
8375
  * @param event.inputs: (Deprecated) the same as `input` (will be removed in a future version).
8191
8376
  * @param options Additional logging options
8192
- * @param options.allowLogConcurrentWithActiveSpan in rare cases where you need to log at the top level separately from an active span on the experiment, set this to true.
8377
+ * @param options.allowConcurrentWithSpans in rare cases where you need to log at the top level separately from spans on the experiment elsewhere, set this to true.
8193
8378
  * :returns: The `id` of the logged event.
8194
8379
  */
8195
8380
  log(event, options) {
8196
- if (!options?.allowLogConcurrentWithActiveSpan) {
8197
- const checkCurrentSpan = currentSpan();
8198
- if (checkCurrentSpan instanceof SpanImpl && checkCurrentSpan.parentObject === this) {
8199
- throw new Error(
8200
- "Cannot run toplevel Experiment.log method while there is an active span. To log to the span, use Span.log"
8201
- );
8202
- }
8381
+ if (this.calledStartSpan && !options?.allowConcurrentWithSpans) {
8382
+ throw new Error(
8383
+ "Cannot run toplevel `log` method while using spans. To log to the span, call `experiment.traced` and then log with `span.log`"
8384
+ );
8203
8385
  }
8204
8386
  event = validateAndSanitizeExperimentLogFullArgs(event, !!this.dataset);
8205
- const span = this.startSpan({ startTime: this.lastStartTime, event });
8387
+ const span = this.startSpanImpl({ startTime: this.lastStartTime, event });
8206
8388
  this.lastStartTime = span.end();
8207
8389
  return span.id;
8208
8390
  }
@@ -8225,13 +8407,6 @@ var Experiment = class extends ObjectFetcher {
8225
8407
  () => span.end()
8226
8408
  );
8227
8409
  }
8228
- async lazyParentIds() {
8229
- return {
8230
- kind: "experiment",
8231
- project_id: (await this.project).id,
8232
- experiment_id: await this.id
8233
- };
8234
- }
8235
8410
  /**
8236
8411
  * Lower-level alternative to `traced`. This allows you to start a span yourself, and can be useful in situations
8237
8412
  * where you cannot use callbacks. However, spans started with `startSpan` will not be marked as the "current span",
@@ -8240,14 +8415,19 @@ var Experiment = class extends ObjectFetcher {
8240
8415
  * See `traced` for full details.
8241
8416
  */
8242
8417
  startSpan(args) {
8243
- const { name, type, ...argsRest } = args ?? {};
8418
+ this.calledStartSpan = true;
8419
+ return this.startSpanImpl(args);
8420
+ }
8421
+ startSpanImpl(args) {
8244
8422
  return new SpanImpl({
8245
- parentObject: this,
8246
- parentIds: new LazyValue(() => this.lazyParentIds()),
8247
- bgLogger: this.bgLogger,
8248
- name: name ?? "root",
8249
- type: type ?? SpanTypeAttribute.EVAL,
8250
- ...argsRest
8423
+ ...startSpanParentArgs({
8424
+ parent: args?.parent,
8425
+ parentId: args?.parentId,
8426
+ spanParentObjectType: this.spanParentObjectType(),
8427
+ spanParentObjectId: this.lazyId
8428
+ }),
8429
+ ...args,
8430
+ defaultRootType: SpanTypeAttribute.EVAL
8251
8431
  });
8252
8432
  }
8253
8433
  async fetchBaseExperiment() {
@@ -8280,12 +8460,12 @@ var Experiment = class extends ObjectFetcher {
8280
8460
  */
8281
8461
  async summarize(options = {}) {
8282
8462
  let { summarizeScores = true, comparisonExperimentId = void 0 } = options || {};
8283
- await this.bgLogger.flush();
8463
+ await this.flush();
8284
8464
  const state = await this.getState();
8285
8465
  const projectUrl = `${state.appPublicUrl}/app/${encodeURIComponent(
8286
8466
  state.orgName
8287
8467
  )}/p/${encodeURIComponent((await this.project).name)}`;
8288
- const experimentUrl = `${projectUrl}/${encodeURIComponent(
8468
+ const experimentUrl = `${projectUrl}/experiments/${encodeURIComponent(
8289
8469
  await this.name
8290
8470
  )}`;
8291
8471
  let scores = void 0;
@@ -8334,17 +8514,23 @@ var Experiment = class extends ObjectFetcher {
8334
8514
  * @param event.source (Optional) the source of the feedback. Must be one of "external" (default), "app", or "api".
8335
8515
  */
8336
8516
  logFeedback(event) {
8337
- logFeedbackImpl(
8338
- this.bgLogger,
8339
- new LazyValue(() => this.lazyParentIds()),
8340
- event
8341
- );
8517
+ logFeedbackImpl(this.spanParentObjectType(), this.lazyId, event);
8518
+ }
8519
+ /**
8520
+ * Return a serialized representation of the experiment that can be used to start subspans in other places. See `Span.start_span` for more details.
8521
+ */
8522
+ async export() {
8523
+ return new SpanParentComponents({
8524
+ objectType: this.spanParentObjectType(),
8525
+ objectId: await this.id,
8526
+ rowId: ""
8527
+ }).toStr();
8342
8528
  }
8343
8529
  /**
8344
8530
  * Flush any pending rows to the server.
8345
8531
  */
8346
8532
  async flush() {
8347
- return await this.bgLogger.flush();
8533
+ return await _state.globalBgLogger().flush();
8348
8534
  }
8349
8535
  /**
8350
8536
  * This function is deprecated. You can simply remove it from your code.
@@ -8400,27 +8586,31 @@ var ReadonlyExperiment = class extends ObjectFetcher {
8400
8586
  };
8401
8587
  var executionCounter = 0;
8402
8588
  var SpanImpl = class _SpanImpl {
8403
- bgLogger;
8404
8589
  // `internalData` contains fields that are not part of the "user-sanitized"
8405
8590
  // set of fields which we want to log in just one of the span rows.
8406
8591
  internalData;
8407
8592
  isMerge;
8408
8593
  loggedEndTime;
8409
8594
  // For internal use only.
8410
- parentObject;
8411
- // These fields are logged to every span row.
8412
- parentIds;
8413
- rowIds;
8595
+ parentObjectType;
8596
+ parentObjectId;
8597
+ parentRowId;
8598
+ _id;
8414
8599
  kind = "span";
8415
- // root_experiment should only be specified for a root span. parent_span
8416
- // should only be specified for non-root spans.
8417
8600
  constructor(args) {
8601
+ const spanAttributes = args.spanAttributes ?? {};
8602
+ const event = args.event ?? {};
8603
+ const type = args.type ?? (args.parentRowId ? void 0 : args.defaultRootType);
8418
8604
  this.loggedEndTime = void 0;
8419
- this.bgLogger = args.bgLogger;
8605
+ this.parentObjectType = args.parentObjectType;
8606
+ this.parentObjectId = args.parentObjectId;
8607
+ this.parentRowId = args.parentRowId;
8420
8608
  const callerLocation = isomorph_default.getCallerLocation();
8421
8609
  const name = (() => {
8422
8610
  if (args.name)
8423
8611
  return args.name;
8612
+ if (!args.parentRowId)
8613
+ return "root";
8424
8614
  if (callerLocation) {
8425
8615
  const pathComponents = callerLocation.caller_filename.split("/");
8426
8616
  const filename = pathComponents[pathComponents.length - 1];
@@ -8436,72 +8626,52 @@ var SpanImpl = class _SpanImpl {
8436
8626
  },
8437
8627
  context: { ...callerLocation },
8438
8628
  span_attributes: {
8439
- type: args.type,
8440
- ...args.spanAttributes,
8441
8629
  name,
8630
+ type,
8631
+ ...spanAttributes,
8442
8632
  exec_counter: executionCounter++
8443
8633
  },
8444
8634
  created: (/* @__PURE__ */ new Date()).toISOString()
8445
8635
  };
8446
- this.parentObject = args.parentObject;
8447
- this.parentIds = args.parentIds;
8448
- const id = args.event?.id ?? v4_default();
8449
- this.rowIds = { id };
8450
- const parentSpanInfo = "parentSpanInfo" in args ? args.parentSpanInfo : void 0;
8451
- const parentId = "parentId" in args ? args.parentId : void 0;
8452
- if (parentSpanInfo && parentId) {
8453
- throw new Error(
8454
- "Only one of parentSpanInfo and parentId may be specified"
8455
- );
8456
- }
8457
- if (parentId) {
8458
- this.rowIds[PARENT_ID_FIELD] = parentId;
8459
- } else {
8460
- this.rowIds.span_id = v4_default();
8461
- if (parentSpanInfo) {
8462
- this.rowIds.root_span_id = parentSpanInfo.root_span_id;
8463
- this.internalData.span_parents = [parentSpanInfo.span_id];
8464
- } else {
8465
- this.rowIds.root_span_id = this.rowIds.span_id;
8466
- }
8467
- }
8636
+ this._id = event.id ?? v4_default();
8468
8637
  this.isMerge = false;
8469
- const { id: _id, ...eventRest } = args.event ?? {};
8638
+ const { id: _id, ...eventRest } = event;
8470
8639
  this.log(eventRest);
8471
8640
  this.isMerge = true;
8472
8641
  }
8473
8642
  get id() {
8474
- return this.rowIds.id;
8643
+ return this._id;
8475
8644
  }
8476
8645
  log(event) {
8477
8646
  const sanitized = validateAndSanitizeExperimentLogPartialArgs(event);
8478
8647
  let sanitizedAndInternalData = { ...this.internalData };
8479
8648
  mergeDicts(sanitizedAndInternalData, sanitized);
8480
8649
  this.internalData = {};
8481
- if (sanitizedAndInternalData.tags && sanitizedAndInternalData.tags.length > 0 && this.rowIds.span_id !== this.rowIds.root_span_id) {
8482
- throw new Error("Tags can only be logged to the root span");
8483
- }
8484
8650
  let partialRecord = {
8485
8651
  ...sanitizedAndInternalData,
8486
- ...this.rowIds,
8487
8652
  [IS_MERGE_FIELD]: this.isMerge
8488
8653
  };
8654
+ const serializedPartialRecord = JSON.stringify(partialRecord);
8655
+ partialRecord = JSON.parse(serializedPartialRecord);
8489
8656
  if (partialRecord.metrics?.end) {
8490
8657
  this.loggedEndTime = partialRecord.metrics?.end;
8491
8658
  }
8492
- const serializedPartialRecord = JSON.stringify(partialRecord);
8493
- partialRecord = JSON.parse(serializedPartialRecord);
8494
- const record = new LazyValue(async () => {
8495
- const { kind, ...parentIds } = await this.parentIds.get();
8496
- return {
8497
- ...partialRecord,
8498
- ...parentIds
8499
- };
8659
+ if ((partialRecord.tags ?? []).length > 0 && this.parentRowId) {
8660
+ throw new Error("Tags can only be logged to the root span");
8661
+ }
8662
+ const computeRecord = async () => ({
8663
+ ...partialRecord,
8664
+ ...new SpanParentComponents({
8665
+ objectType: this.parentObjectType,
8666
+ objectId: await this.parentObjectId.get(),
8667
+ rowId: this.parentRowId
8668
+ }).asDict(),
8669
+ id: this.id
8500
8670
  });
8501
- this.bgLogger.log([record]);
8671
+ _state.globalBgLogger().log([new LazyValue(computeRecord)]);
8502
8672
  }
8503
8673
  logFeedback(event) {
8504
- logFeedbackImpl(this.bgLogger, this.parentIds, {
8674
+ logFeedbackImpl(this.parentObjectType, this.parentObjectId, {
8505
8675
  ...event,
8506
8676
  id: this.id
8507
8677
  });
@@ -8521,25 +8691,14 @@ var SpanImpl = class _SpanImpl {
8521
8691
  );
8522
8692
  }
8523
8693
  startSpan(args) {
8524
- const parentId = args?.parentId ?? (this.rowIds[PARENT_ID_FIELD] ? this.id : void 0);
8525
- const parentSpanInfo = (() => {
8526
- if (parentId)
8527
- return void 0;
8528
- if (!(this.rowIds.span_id && this.rowIds.root_span_id)) {
8529
- throw new Error("Impossible");
8530
- }
8531
- return {
8532
- span_id: this.rowIds.span_id,
8533
- root_span_id: this.rowIds.root_span_id
8534
- };
8535
- })();
8536
8694
  return new _SpanImpl({
8537
- parentObject: this.parentObject,
8538
- parentIds: this.parentIds,
8539
- bgLogger: this.bgLogger,
8540
- parentSpanInfo,
8541
- parentId,
8542
- ...args
8695
+ ...args,
8696
+ ...startSpanParentArgs({
8697
+ parent: args?.parent,
8698
+ parentId: args?.parentId ?? (args?.parent ? void 0 : this.id),
8699
+ spanParentObjectType: this.parentObjectType,
8700
+ spanParentObjectId: this.parentObjectId
8701
+ })
8543
8702
  });
8544
8703
  }
8545
8704
  end(args) {
@@ -8553,13 +8712,22 @@ var SpanImpl = class _SpanImpl {
8553
8712
  this.log({});
8554
8713
  return endTime;
8555
8714
  }
8715
+ async export() {
8716
+ return new SpanParentComponents({
8717
+ objectType: this.parentObjectType,
8718
+ objectId: await this.parentObjectId.get(),
8719
+ rowId: this.id
8720
+ }).toStr();
8721
+ }
8722
+ async flush() {
8723
+ return await _state.globalBgLogger().flush();
8724
+ }
8556
8725
  close(args) {
8557
8726
  return this.end(args);
8558
8727
  }
8559
8728
  };
8560
8729
  var Dataset = class extends ObjectFetcher {
8561
8730
  lazyMetadata;
8562
- bgLogger;
8563
8731
  constructor(lazyMetadata, pinnedVersion, legacy) {
8564
8732
  const isLegacyDataset = legacy ?? DEFAULT_IS_LEGACY_DATASET;
8565
8733
  if (isLegacyDataset) {
@@ -8576,7 +8744,6 @@ var Dataset = class extends ObjectFetcher {
8576
8744
  const logConn = new LazyValue(
8577
8745
  () => this.getState().then((state) => state.logConn())
8578
8746
  );
8579
- this.bgLogger = new BackgroundLogger(logConn);
8580
8747
  }
8581
8748
  get id() {
8582
8749
  return (async () => {
@@ -8642,23 +8809,21 @@ var Dataset = class extends ObjectFetcher {
8642
8809
  input,
8643
8810
  expected: expected === void 0 ? output : expected,
8644
8811
  tags,
8645
- project_id: (await this.project).id,
8646
8812
  dataset_id: await this.id,
8647
8813
  created: (/* @__PURE__ */ new Date()).toISOString(),
8648
8814
  metadata
8649
8815
  }));
8650
- this.bgLogger.log([args]);
8816
+ _state.globalBgLogger().log([args]);
8651
8817
  return rowId;
8652
8818
  }
8653
8819
  delete(id) {
8654
8820
  const args = new LazyValue(async () => ({
8655
8821
  id,
8656
- project_id: (await this.project).id,
8657
8822
  dataset_id: await this.id,
8658
8823
  created: (/* @__PURE__ */ new Date()).toISOString(),
8659
8824
  _object_delete: true
8660
8825
  }));
8661
- this.bgLogger.log([args]);
8826
+ _state.globalBgLogger().log([args]);
8662
8827
  return id;
8663
8828
  }
8664
8829
  /**
@@ -8669,12 +8834,14 @@ var Dataset = class extends ObjectFetcher {
8669
8834
  */
8670
8835
  async summarize(options = {}) {
8671
8836
  let { summarizeData = true } = options || {};
8672
- await this.bgLogger.flush();
8837
+ await this.flush();
8673
8838
  const state = await this.getState();
8674
8839
  const projectUrl = `${state.appPublicUrl}/app/${encodeURIComponent(
8675
8840
  state.orgName
8676
8841
  )}/p/${encodeURIComponent((await this.project).name)}`;
8677
- const datasetUrl = `${projectUrl}/d/${encodeURIComponent(await this.name)}`;
8842
+ const datasetUrl = `${projectUrl}/datasets/${encodeURIComponent(
8843
+ await this.name
8844
+ )}`;
8678
8845
  let dataSummary = void 0;
8679
8846
  if (summarizeData) {
8680
8847
  dataSummary = await state.logConn().get_json(
@@ -8697,7 +8864,7 @@ var Dataset = class extends ObjectFetcher {
8697
8864
  * Flush any pending rows to the server.
8698
8865
  */
8699
8866
  async flush() {
8700
- return await this.bgLogger.flush();
8867
+ return await _state.globalBgLogger().flush();
8701
8868
  }
8702
8869
  /**
8703
8870
  * This function is deprecated. You can simply remove it from your code.
@@ -8754,7 +8921,7 @@ var Prompt = class {
8754
8921
  ...this.defaults,
8755
8922
  ...Object.fromEntries(
8756
8923
  Object.entries(this.options.params || {}).filter(
8757
- ([k, v]) => !BRAINTRUST_PARAMS.includes(k)
8924
+ ([k, _v]) => !BRAINTRUST_PARAMS.includes(k)
8758
8925
  )
8759
8926
  ),
8760
8927
  ...!isEmpty(this.options.model) ? {
@@ -8788,9 +8955,14 @@ var Prompt = class {
8788
8955
  "Prompt is a completion prompt. Use buildCompletion() instead"
8789
8956
  );
8790
8957
  }
8958
+ const render3 = (template) => mustache_default.render(template, buildArgs, void 0, {
8959
+ escape: (v) => typeof v === "string" ? v : JSON.stringify(v)
8960
+ });
8791
8961
  const messages = (prompt.messages || []).map((m) => ({
8792
8962
  ...m,
8793
- ..."content" in m && typeof m.content === "string" ? { content: mustache_default.render(m.content, buildArgs) } : {}
8963
+ ..."content" in m ? {
8964
+ content: typeof m.content === "string" ? render3(m.content) : JSON.parse(render3(JSON.stringify(m.content)))
8965
+ } : {}
8794
8966
  }));
8795
8967
  return {
8796
8968
  ...params,
@@ -8914,23 +9086,18 @@ function wrapOpenAIv4(openai) {
8914
9086
  }
8915
9087
  function wrapBetaChatCompletion(completion) {
8916
9088
  return (allParams) => {
8917
- const { span_info, ...params } = allParams;
8918
- const { messages, ...rest } = params;
8919
- const span = startSpan({
8920
- name: "OpenAI Chat Completion",
8921
- spanAttributes: {
8922
- type: SpanTypeAttribute.LLM
8923
- },
8924
- event: mergeDicts(
9089
+ const { span_info: _, ...params } = allParams;
9090
+ const span = startSpan(
9091
+ mergeDicts(
8925
9092
  {
8926
- input: messages,
8927
- metadata: {
8928
- ...rest
9093
+ name: "Chat Completion",
9094
+ spanAttributes: {
9095
+ type: SpanTypeAttribute.LLM
8929
9096
  }
8930
9097
  },
8931
- span_info || {}
9098
+ parseChatCompletionParams(allParams)
8932
9099
  )
8933
- });
9100
+ );
8934
9101
  const startTime = getCurrentUnixTimestamp();
8935
9102
  const ret = completion(params);
8936
9103
  let first = true;
@@ -8947,7 +9114,7 @@ function wrapBetaChatCompletion(completion) {
8947
9114
  });
8948
9115
  ret.on("chatCompletion", (completion2) => {
8949
9116
  span.log({
8950
- output: completion2.choices[0]
9117
+ output: completion2.choices
8951
9118
  });
8952
9119
  });
8953
9120
  ret.on("end", () => {
@@ -8958,26 +9125,24 @@ function wrapBetaChatCompletion(completion) {
8958
9125
  }
8959
9126
  function wrapChatCompletion(completion) {
8960
9127
  return async (allParams, options) => {
8961
- const { span_info, ...params } = allParams;
8962
- const { messages, ...rest } = params;
8963
- const span = startSpan({
8964
- name: "OpenAI Chat Completion",
8965
- spanAttributes: {
8966
- type: SpanTypeAttribute.LLM
8967
- },
8968
- event: mergeDicts(
9128
+ const { span_info: _, ...params } = allParams;
9129
+ const span = startSpan(
9130
+ mergeDicts(
8969
9131
  {
8970
- input: messages,
8971
- metadata: {
8972
- ...rest
9132
+ name: "Chat Completion",
9133
+ spanAttributes: {
9134
+ type: SpanTypeAttribute.LLM
8973
9135
  }
8974
9136
  },
8975
- span_info || {}
9137
+ parseChatCompletionParams(allParams)
8976
9138
  )
8977
- });
9139
+ );
9140
+ const startTime = getCurrentUnixTimestamp();
8978
9141
  if (params.stream) {
8979
- const startTime = getCurrentUnixTimestamp();
8980
9142
  const ret = await completion(
9143
+ // We could get rid of this type coercion if we could somehow enforce
9144
+ // that `P extends ChatParams` BUT does not have the property
9145
+ // `span_info`.
8981
9146
  params,
8982
9147
  options
8983
9148
  );
@@ -8990,14 +9155,15 @@ function wrapChatCompletion(completion) {
8990
9155
  params,
8991
9156
  options
8992
9157
  );
8993
- const { messages: messages2, ...rest2 } = params;
9158
+ const { messages, ...rest } = params;
8994
9159
  span.log({
8995
- input: messages2,
9160
+ input: messages,
8996
9161
  metadata: {
8997
- ...rest2
9162
+ ...rest
8998
9163
  },
8999
- output: ret.choices[0],
9164
+ output: ret.choices,
9000
9165
  metrics: {
9166
+ time_to_first_token: getCurrentUnixTimestamp() - startTime,
9001
9167
  tokens: ret.usage?.total_tokens,
9002
9168
  prompt_tokens: ret.usage?.prompt_tokens,
9003
9169
  completion_tokens: ret.usage?.completion_tokens
@@ -9010,10 +9176,21 @@ function wrapChatCompletion(completion) {
9010
9176
  }
9011
9177
  };
9012
9178
  }
9179
+ function parseChatCompletionParams(allParams) {
9180
+ const { span_info, ...params } = allParams;
9181
+ const { metadata: spanInfoMetadata, ...spanInfoRest } = span_info ?? {};
9182
+ let ret = {
9183
+ ...spanInfoRest,
9184
+ event: {
9185
+ metadata: spanInfoMetadata
9186
+ }
9187
+ };
9188
+ const { messages, ...paramsRest } = params;
9189
+ return mergeDicts(ret, { event: { input: messages, metadata: paramsRest } });
9190
+ }
9013
9191
  function wrapEmbeddings(create) {
9014
9192
  return async (allParams, options) => {
9015
- const { span_info, ...params } = allParams;
9016
- const { input, ...rest } = params;
9193
+ const { span_info: _, ...params } = allParams;
9017
9194
  return traced(
9018
9195
  async (span) => {
9019
9196
  const result = await create(params, options);
@@ -9029,24 +9206,76 @@ function wrapEmbeddings(create) {
9029
9206
  });
9030
9207
  return result;
9031
9208
  },
9032
- {
9033
- name: "OpenAI Embedding",
9034
- spanAttributes: {
9035
- type: SpanTypeAttribute.LLM
9209
+ mergeDicts(
9210
+ {
9211
+ name: "Embedding",
9212
+ spanAttributes: {
9213
+ type: SpanTypeAttribute.LLM
9214
+ }
9036
9215
  },
9037
- event: mergeDicts(
9038
- {
9039
- input,
9040
- metadata: {
9041
- ...rest
9042
- }
9043
- },
9044
- span_info || {}
9045
- )
9046
- }
9216
+ parseEmbeddingParams(allParams)
9217
+ )
9047
9218
  );
9048
9219
  };
9049
9220
  }
9221
+ function parseEmbeddingParams(allParams) {
9222
+ const { span_info, ...params } = allParams;
9223
+ const { metadata: spanInfoMetadata, ...spanInfoRest } = span_info ?? {};
9224
+ let ret = {
9225
+ ...spanInfoRest,
9226
+ event: {
9227
+ metadata: spanInfoMetadata
9228
+ }
9229
+ };
9230
+ const { input, ...paramsRest } = params;
9231
+ return mergeDicts(ret, { event: { input, metadata: paramsRest } });
9232
+ }
9233
+ function postprocessStreamingResults(allResults) {
9234
+ let role = void 0;
9235
+ let content = void 0;
9236
+ let tool_calls = void 0;
9237
+ let finish_reason = void 0;
9238
+ for (const result of allResults) {
9239
+ const delta = result.choices?.[0]?.delta;
9240
+ if (!delta) {
9241
+ continue;
9242
+ }
9243
+ if (!role && delta.role) {
9244
+ role = delta.role;
9245
+ }
9246
+ if (delta.finish_reason) {
9247
+ finish_reason = delta.finish_reason;
9248
+ }
9249
+ if (delta.content) {
9250
+ content = (content || "") + delta.content;
9251
+ }
9252
+ if (delta.tool_calls) {
9253
+ if (!tool_calls) {
9254
+ tool_calls = [
9255
+ {
9256
+ id: delta.tool_calls[0].id,
9257
+ type: delta.tool_calls[0].type,
9258
+ function: delta.tool_calls[0].function
9259
+ }
9260
+ ];
9261
+ } else {
9262
+ tool_calls[0].function.arguments += delta.tool_calls[0].function.arguments;
9263
+ }
9264
+ }
9265
+ }
9266
+ return [
9267
+ {
9268
+ index: 0,
9269
+ message: {
9270
+ role,
9271
+ content,
9272
+ tool_calls
9273
+ },
9274
+ logprobs: null,
9275
+ finish_reason
9276
+ }
9277
+ ];
9278
+ }
9050
9279
  var WrapperStream = class {
9051
9280
  span;
9052
9281
  iter;
@@ -9074,7 +9303,7 @@ var WrapperStream = class {
9074
9303
  yield item;
9075
9304
  }
9076
9305
  this.span.log({
9077
- output: allResults
9306
+ output: postprocessStreamingResults(allResults)
9078
9307
  });
9079
9308
  } finally {
9080
9309
  this.span.end();
@@ -9085,6 +9314,7 @@ var WrapperStream = class {
9085
9314
  // src/browser.ts
9086
9315
  configureBrowser();
9087
9316
  export {
9317
+ Dataset,
9088
9318
  Experiment,
9089
9319
  Logger,
9090
9320
  NOOP_SPAN,
@@ -9097,6 +9327,7 @@ export {
9097
9327
  currentExperiment,
9098
9328
  currentLogger,
9099
9329
  currentSpan,
9330
+ flush,
9100
9331
  getSpanParentObject,
9101
9332
  init,
9102
9333
  initDataset,