braintrust 0.0.113 → 0.0.114

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/index.js CHANGED
@@ -872,9 +872,9 @@ var require_dist2 = __commonJS({
872
872
  }
873
873
  });
874
874
 
875
- // ../../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
875
+ // ../../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
876
876
  var require_zod_is_type = __commonJS({
877
- "../../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) {
877
+ "../../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) {
878
878
  "use strict";
879
879
  Object.defineProperty(exports, "__esModule", { value: true });
880
880
  exports.isAnyZodType = exports.isZodType = void 0;
@@ -890,9 +890,9 @@ var require_zod_is_type = __commonJS({
890
890
  }
891
891
  });
892
892
 
893
- // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.3.1_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/zod-extensions.js
893
+ // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.4.0_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/zod-extensions.js
894
894
  var require_zod_extensions = __commonJS({
895
- "../../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) {
895
+ "../../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) {
896
896
  "use strict";
897
897
  var __rest = exports && exports.__rest || function(s, e) {
898
898
  var t = {};
@@ -980,9 +980,9 @@ var require_zod_extensions = __commonJS({
980
980
  }
981
981
  });
982
982
 
983
- // ../../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
983
+ // ../../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
984
984
  var require_object_set = __commonJS({
985
- "../../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) {
985
+ "../../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) {
986
986
  "use strict";
987
987
  Object.defineProperty(exports, "__esModule", { value: true });
988
988
  exports.ObjectSet = exports.isEqual = void 0;
@@ -1078,12 +1078,12 @@ var require_object_set = __commonJS({
1078
1078
  }
1079
1079
  });
1080
1080
 
1081
- // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.3.1_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/lib/lodash.js
1081
+ // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.4.0_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/lib/lodash.js
1082
1082
  var require_lodash = __commonJS({
1083
- "../../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) {
1083
+ "../../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) {
1084
1084
  "use strict";
1085
1085
  Object.defineProperty(exports, "__esModule", { value: true });
1086
- exports.uniq = exports.objectEquals = exports.compact = exports.omitBy = exports.omit = exports.mapValues = exports.isNil = exports.isUndefined = void 0;
1086
+ exports.isString = exports.uniq = exports.objectEquals = exports.compact = exports.omitBy = exports.omit = exports.mapValues = exports.isNil = exports.isUndefined = void 0;
1087
1087
  var object_set_1 = require_object_set();
1088
1088
  function isUndefined(value) {
1089
1089
  return value === void 0;
@@ -1132,12 +1132,16 @@ var require_lodash = __commonJS({
1132
1132
  return [...set.values()];
1133
1133
  }
1134
1134
  exports.uniq = uniq;
1135
+ function isString(val) {
1136
+ return typeof val === "string";
1137
+ }
1138
+ exports.isString = isString;
1135
1139
  }
1136
1140
  });
1137
1141
 
1138
- // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.3.1_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/openapi-metadata.js
1142
+ // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.4.0_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/openapi-metadata.js
1139
1143
  var require_openapi_metadata = __commonJS({
1140
- "../../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) {
1144
+ "../../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) {
1141
1145
  "use strict";
1142
1146
  Object.defineProperty(exports, "__esModule", { value: true });
1143
1147
  exports.getOpenApiMetadata = void 0;
@@ -1150,9 +1154,9 @@ var require_openapi_metadata = __commonJS({
1150
1154
  }
1151
1155
  });
1152
1156
 
1153
- // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.3.1_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/openapi-registry.js
1157
+ // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.4.0_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/openapi-registry.js
1154
1158
  var require_openapi_registry = __commonJS({
1155
- "../../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) {
1159
+ "../../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) {
1156
1160
  "use strict";
1157
1161
  Object.defineProperty(exports, "__esModule", { value: true });
1158
1162
  exports.OpenAPIRegistry = void 0;
@@ -1234,9 +1238,9 @@ var require_openapi_registry = __commonJS({
1234
1238
  }
1235
1239
  });
1236
1240
 
1237
- // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.3.1_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/errors.js
1241
+ // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.4.0_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/errors.js
1238
1242
  var require_errors = __commonJS({
1239
- "../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.3.1_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/errors.js"(exports) {
1243
+ "../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.4.0_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/errors.js"(exports) {
1240
1244
  "use strict";
1241
1245
  Object.defineProperty(exports, "__esModule", { value: true });
1242
1246
  exports.UnknownZodTypeError = exports.MissingParameterDataError = exports.ConflictError = exports.ZodToOpenAPIError = void 0;
@@ -1270,9 +1274,9 @@ var require_errors = __commonJS({
1270
1274
  }
1271
1275
  });
1272
1276
 
1273
- // ../../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
1277
+ // ../../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
1274
1278
  var require_enum_info = __commonJS({
1275
- "../../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) {
1279
+ "../../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) {
1276
1280
  "use strict";
1277
1281
  Object.defineProperty(exports, "__esModule", { value: true });
1278
1282
  exports.enumInfo = void 0;
@@ -1287,9 +1291,9 @@ var require_enum_info = __commonJS({
1287
1291
  }
1288
1292
  });
1289
1293
 
1290
- // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.3.1_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/openapi-generator.js
1294
+ // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.4.0_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/openapi-generator.js
1291
1295
  var require_openapi_generator = __commonJS({
1292
- "../../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) {
1296
+ "../../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) {
1293
1297
  "use strict";
1294
1298
  var __rest = exports && exports.__rest || function(s, e) {
1295
1299
  var t = {};
@@ -1630,7 +1634,7 @@ var require_openapi_generator = __commonJS({
1630
1634
  }
1631
1635
  getBodyContent(content) {
1632
1636
  return (0, lodash_1.mapValues)(content, (config) => {
1633
- if (!(0, zod_is_type_1.isAnyZodType)(config.schema)) {
1637
+ if (!config || !(0, zod_is_type_1.isAnyZodType)(config.schema)) {
1634
1638
  return config;
1635
1639
  }
1636
1640
  const { schema: configSchema } = config, rest = __rest(config, ["schema"]);
@@ -1818,7 +1822,14 @@ var require_openapi_generator = __commonJS({
1818
1822
  }
1819
1823
  if ((0, zod_is_type_1.isZodType)(zodSchema, "ZodRecord")) {
1820
1824
  const propertiesType = zodSchema._def.valueType;
1821
- return Object.assign(Object.assign({}, this.mapNullableType("object", isNullable)), { additionalProperties: this.generateSchemaWithRef(propertiesType), default: defaultValue });
1825
+ const keyType = zodSchema._def.keyType;
1826
+ const propertiesSchema = this.generateSchemaWithRef(propertiesType);
1827
+ if ((0, zod_is_type_1.isZodType)(keyType, "ZodEnum") || (0, zod_is_type_1.isZodType)(keyType, "ZodNativeEnum")) {
1828
+ const keys = Object.values(keyType.enum).filter(lodash_1.isString);
1829
+ const properties = keys.reduce((acc, curr) => Object.assign(Object.assign({}, acc), { [curr]: propertiesSchema }), {});
1830
+ return Object.assign(Object.assign({}, this.mapNullableType("object", isNullable)), { properties, default: defaultValue });
1831
+ }
1832
+ return Object.assign(Object.assign({}, this.mapNullableType("object", isNullable)), { additionalProperties: propertiesSchema, default: defaultValue });
1822
1833
  }
1823
1834
  if ((0, zod_is_type_1.isZodType)(zodSchema, "ZodUnknown") || (0, zod_is_type_1.isZodType)(zodSchema, "ZodAny")) {
1824
1835
  return this.mapNullableType(void 0, isNullable);
@@ -1984,9 +1995,9 @@ var require_openapi_generator = __commonJS({
1984
1995
  }
1985
1996
  });
1986
1997
 
1987
- // ../../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
1998
+ // ../../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
1988
1999
  var require_specifics = __commonJS({
1989
- "../../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) {
2000
+ "../../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) {
1990
2001
  "use strict";
1991
2002
  Object.defineProperty(exports, "__esModule", { value: true });
1992
2003
  exports.OpenApiGeneratorV30Specifics = void 0;
@@ -2020,9 +2031,9 @@ var require_specifics = __commonJS({
2020
2031
  }
2021
2032
  });
2022
2033
 
2023
- // ../../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
2034
+ // ../../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
2024
2035
  var require_openapi_generator2 = __commonJS({
2025
- "../../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) {
2036
+ "../../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) {
2026
2037
  "use strict";
2027
2038
  Object.defineProperty(exports, "__esModule", { value: true });
2028
2039
  exports.OpenApiGeneratorV3 = void 0;
@@ -2045,9 +2056,9 @@ var require_openapi_generator2 = __commonJS({
2045
2056
  }
2046
2057
  });
2047
2058
 
2048
- // ../../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
2059
+ // ../../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
2049
2060
  var require_specifics2 = __commonJS({
2050
- "../../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) {
2061
+ "../../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) {
2051
2062
  "use strict";
2052
2063
  Object.defineProperty(exports, "__esModule", { value: true });
2053
2064
  exports.OpenApiGeneratorV31Specifics = void 0;
@@ -2091,9 +2102,9 @@ var require_specifics2 = __commonJS({
2091
2102
  }
2092
2103
  });
2093
2104
 
2094
- // ../../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
2105
+ // ../../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
2095
2106
  var require_openapi_generator3 = __commonJS({
2096
- "../../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) {
2107
+ "../../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) {
2097
2108
  "use strict";
2098
2109
  Object.defineProperty(exports, "__esModule", { value: true });
2099
2110
  exports.OpenApiGeneratorV31 = void 0;
@@ -2127,9 +2138,9 @@ var require_openapi_generator3 = __commonJS({
2127
2138
  }
2128
2139
  });
2129
2140
 
2130
- // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.3.1_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/index.js
2141
+ // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.4.0_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/index.js
2131
2142
  var require_dist3 = __commonJS({
2132
- "../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.3.1_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/index.js"(exports) {
2143
+ "../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@6.4.0_zod@3.22.4/node_modules/@asteasolutions/zod-to-openapi/dist/index.js"(exports) {
2133
2144
  "use strict";
2134
2145
  var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
2135
2146
  if (k2 === void 0)
@@ -4956,9 +4967,11 @@ __export(src_exports, {
4956
4967
  NoopSpan: () => NoopSpan,
4957
4968
  Prompt: () => Prompt,
4958
4969
  ReadonlyExperiment: () => ReadonlyExperiment,
4970
+ Reporter: () => Reporter,
4959
4971
  SpanImpl: () => SpanImpl,
4960
4972
  _internalGetGlobalState: () => _internalGetGlobalState,
4961
4973
  _internalSetInitialState: () => _internalSetInitialState,
4974
+ buildLocalSummary: () => buildLocalSummary,
4962
4975
  currentExperiment: () => currentExperiment,
4963
4976
  currentLogger: () => currentLogger,
4964
4977
  currentSpan: () => currentSpan,
@@ -4970,6 +4983,7 @@ __export(src_exports, {
4970
4983
  loadPrompt: () => loadPrompt,
4971
4984
  log: () => log,
4972
4985
  login: () => login,
4986
+ reportFailures: () => reportFailures,
4973
4987
  startSpan: () => startSpan,
4974
4988
  summarize: () => summarize,
4975
4989
  traced: () => traced,
@@ -9193,7 +9207,7 @@ function v4(options, buf, offset) {
9193
9207
  }
9194
9208
  var v4_default = v4;
9195
9209
 
9196
- // ../core/js/dist/index.mjs
9210
+ // ../../node_modules/.pnpm/@braintrust+core@0.0.27/node_modules/@braintrust/core/dist/index.mjs
9197
9211
  var TRANSACTION_ID_FIELD = "_xact_id";
9198
9212
  var IS_MERGE_FIELD = "_is_merge";
9199
9213
  var MERGE_PATHS_FIELD = "_merge_paths";
@@ -9498,7 +9512,7 @@ var MOD = BigInt(1) << BigInt(64);
9498
9512
  var COPRIME = BigInt("205891132094649");
9499
9513
  var COPRIME_INVERSE = BigInt("1522336535492693385");
9500
9514
 
9501
- // ../core/js/typespecs/dist/index.mjs
9515
+ // ../../node_modules/.pnpm/@braintrust+core@0.0.27/node_modules/@braintrust/core/typespecs/dist/index.mjs
9502
9516
  var import_zod_to_openapi = __toESM(require_dist3(), 1);
9503
9517
 
9504
9518
  // ../../node_modules/.pnpm/zod@3.22.4/node_modules/zod/lib/index.mjs
@@ -13234,7 +13248,7 @@ var z = /* @__PURE__ */ Object.freeze({
13234
13248
  ZodError
13235
13249
  });
13236
13250
 
13237
- // ../core/js/typespecs/dist/index.mjs
13251
+ // ../../node_modules/.pnpm/@braintrust+core@0.0.27/node_modules/@braintrust/core/typespecs/dist/index.mjs
13238
13252
  var import_zod_to_openapi2 = __toESM(require_dist3(), 1);
13239
13253
  var import_zod_to_openapi3 = __toESM(require_dist3(), 1);
13240
13254
  var literalSchema = z.union([
@@ -13279,12 +13293,12 @@ var modeToTypes = {
13279
13293
  };
13280
13294
  var customTypes = modeToTypes[mode];
13281
13295
  var chatCompletionSystemMessageParamSchema = z.object({
13282
- content: z.string(),
13296
+ content: z.string().default(""),
13283
13297
  role: z.literal("system"),
13284
13298
  name: z.string().optional()
13285
13299
  });
13286
13300
  var chatCompletionContentPartTextSchema = z.object({
13287
- text: z.string(),
13301
+ text: z.string().default(""),
13288
13302
  type: z.literal("text")
13289
13303
  });
13290
13304
  var functionCallSchema = z.object({
@@ -13300,12 +13314,12 @@ var imageURLSchema = z.object({
13300
13314
  detail: z.union([z.literal("auto"), z.literal("low"), z.literal("high")]).optional()
13301
13315
  });
13302
13316
  var chatCompletionToolMessageParamSchema = z.object({
13303
- content: z.string(),
13317
+ content: z.string().default(""),
13304
13318
  role: z.literal("tool"),
13305
13319
  tool_call_id: z.string()
13306
13320
  });
13307
13321
  var chatCompletionFunctionMessageParamSchema = z.object({
13308
- content: z.string().nullable(),
13322
+ content: z.string().default(""),
13309
13323
  name: z.string(),
13310
13324
  role: z.literal("function")
13311
13325
  });
@@ -13324,13 +13338,16 @@ var chatCompletionContentPartSchema = z.union([
13324
13338
  ]);
13325
13339
  var chatCompletionAssistantMessageParamSchema = z.object({
13326
13340
  role: z.literal("assistant"),
13327
- content: z.string().optional().nullable(),
13341
+ content: z.string().nullish(),
13328
13342
  function_call: functionCallSchema.optional(),
13329
13343
  name: z.string().optional(),
13330
13344
  tool_calls: z.array(chatCompletionMessageToolCallSchema).optional()
13331
13345
  });
13332
13346
  var chatCompletionUserMessageParamSchema = z.object({
13333
- content: z.union([z.string(), z.array(chatCompletionContentPartSchema)]),
13347
+ content: z.union([
13348
+ z.string().default(""),
13349
+ z.array(chatCompletionContentPartSchema)
13350
+ ]),
13334
13351
  role: z.literal("user"),
13335
13352
  name: z.string().optional()
13336
13353
  });
@@ -14672,6 +14689,7 @@ var BraintrustState = class {
14672
14689
  currentLogger;
14673
14690
  currentSpan;
14674
14691
  appUrl = null;
14692
+ appPublicUrl = null;
14675
14693
  loginToken = null;
14676
14694
  orgId = null;
14677
14695
  orgName = null;
@@ -15015,12 +15033,13 @@ var Logger = class {
15015
15033
  * See `traced` for full details.
15016
15034
  */
15017
15035
  startSpan(args) {
15018
- const { name, ...argsRest } = args ?? {};
15036
+ const { name, type, ...argsRest } = args ?? {};
15019
15037
  return new SpanImpl({
15020
15038
  parentObject: this,
15021
15039
  parentIds: new LazyValue(() => this.lazyParentIds()),
15022
15040
  bgLogger: this.bgLogger,
15023
15041
  name: name ?? "root",
15042
+ type: type ?? SpanTypeAttribute.TASK,
15024
15043
  ...argsRest
15025
15044
  });
15026
15045
  }
@@ -15631,8 +15650,10 @@ async function login(options = {}) {
15631
15650
  apiKey = isomorph_default.getEnv("BRAINTRUST_API_KEY"),
15632
15651
  orgName = isomorph_default.getEnv("BRAINTRUST_ORG_NAME")
15633
15652
  } = options || {};
15653
+ const appPublicUrl = isomorph_default.getEnv("BRAINTRUST_APP_PUBLIC_URL") || appUrl;
15634
15654
  _state.resetLoginInfo();
15635
15655
  _state.appUrl = appUrl;
15656
+ _state.appPublicUrl = appPublicUrl;
15636
15657
  let conn = null;
15637
15658
  if (apiKey !== void 0) {
15638
15659
  const resp = await checkResponse(
@@ -16018,12 +16039,13 @@ var Experiment = class extends ObjectFetcher {
16018
16039
  * See `traced` for full details.
16019
16040
  */
16020
16041
  startSpan(args) {
16021
- const { name, ...argsRest } = args ?? {};
16042
+ const { name, type, ...argsRest } = args ?? {};
16022
16043
  return new SpanImpl({
16023
16044
  parentObject: this,
16024
16045
  parentIds: new LazyValue(() => this.lazyParentIds()),
16025
16046
  bgLogger: this.bgLogger,
16026
16047
  name: name ?? "root",
16048
+ type: type ?? SpanTypeAttribute.EVAL,
16027
16049
  ...argsRest
16028
16050
  });
16029
16051
  }
@@ -16059,7 +16081,7 @@ var Experiment = class extends ObjectFetcher {
16059
16081
  let { summarizeScores = true, comparisonExperimentId = void 0 } = options || {};
16060
16082
  await this.bgLogger.flush();
16061
16083
  const state = await this.getState();
16062
- const projectUrl = `${state.appUrl}/app/${encodeURIComponent(
16084
+ const projectUrl = `${state.appPublicUrl}/app/${encodeURIComponent(
16063
16085
  state.orgName
16064
16086
  )}/p/${encodeURIComponent((await this.project).name)}`;
16065
16087
  const experimentUrl = `${projectUrl}/${encodeURIComponent(
@@ -16095,7 +16117,7 @@ var Experiment = class extends ObjectFetcher {
16095
16117
  projectUrl,
16096
16118
  experimentUrl,
16097
16119
  comparisonExperimentName,
16098
- scores,
16120
+ scores: scores ?? {},
16099
16121
  metrics
16100
16122
  };
16101
16123
  }
@@ -16213,6 +16235,7 @@ var SpanImpl = class _SpanImpl {
16213
16235
  },
16214
16236
  context: { ...callerLocation },
16215
16237
  span_attributes: {
16238
+ type: args.type,
16216
16239
  ...args.spanAttributes,
16217
16240
  name,
16218
16241
  exec_counter: executionCounter++
@@ -16447,7 +16470,7 @@ var Dataset = class extends ObjectFetcher {
16447
16470
  let { summarizeData = true } = options || {};
16448
16471
  await this.bgLogger.flush();
16449
16472
  const state = await this.getState();
16450
- const projectUrl = `${state.appUrl}/app/${encodeURIComponent(
16473
+ const projectUrl = `${state.appPublicUrl}/app/${encodeURIComponent(
16451
16474
  state.orgName
16452
16475
  )}/p/${encodeURIComponent((await this.project).name)}`;
16453
16476
  const datasetUrl = `${projectUrl}/d/${encodeURIComponent(await this.name)}`;
@@ -16662,25 +16685,37 @@ function initExperiment2(projectName, options = {}) {
16662
16685
  setCurrent: false
16663
16686
  });
16664
16687
  }
16665
- globalThis._evals = {};
16666
- async function Eval(name, evaluator) {
16688
+ globalThis._evals = {
16689
+ evaluators: {},
16690
+ reporters: {}
16691
+ };
16692
+ async function Eval(name, evaluator, reporter) {
16667
16693
  let evalName = makeEvalName(name, evaluator.experimentName);
16668
- if (_evals[evalName]) {
16694
+ if (_evals.evaluators[evalName]) {
16669
16695
  evalName = `${evalName}_${Object.keys(_evals).length}`;
16670
16696
  }
16671
16697
  if (globalThis._lazy_load) {
16672
- _evals[evalName] = { evalName, projectName: name, ...evaluator };
16698
+ _evals.evaluators[evalName] = {
16699
+ evaluator: { evalName, projectName: name, ...evaluator },
16700
+ reporter
16701
+ };
16673
16702
  return {
16674
- projectName: "_lazy_load",
16675
- experimentName: "_lazy_load",
16676
- projectUrl: "",
16677
- experimentUrl: "",
16678
- comparisonExperimentName: "",
16679
- scores: {},
16680
- metrics: {}
16703
+ summary: {
16704
+ scores: {},
16705
+ metrics: {},
16706
+ projectName: "",
16707
+ experimentName: ""
16708
+ },
16709
+ results: []
16681
16710
  };
16682
16711
  }
16683
16712
  const progressReporter = new BarProgressReporter();
16713
+ if (typeof reporter === "string") {
16714
+ throw new Error(
16715
+ "Must specify a reporter object, not a name. Can only specify reporter names when running 'braintrust eval'"
16716
+ );
16717
+ }
16718
+ const resolvedReporter = reporter || defaultReporter;
16684
16719
  try {
16685
16720
  const experiment = initExperiment2(name, {
16686
16721
  experiment: evaluator.experimentName,
@@ -16688,18 +16723,17 @@ async function Eval(name, evaluator) {
16688
16723
  isPublic: evaluator.isPublic
16689
16724
  });
16690
16725
  try {
16691
- const ret = await runEvaluator(
16692
- experiment,
16693
- {
16694
- evalName,
16695
- projectName: name,
16696
- ...evaluator
16697
- },
16698
- progressReporter,
16699
- []
16700
- );
16701
- reportEvaluatorResult(name, ret, { verbose: true, jsonl: false });
16702
- return ret.summary;
16726
+ const evalDef = {
16727
+ evalName,
16728
+ projectName: name,
16729
+ ...evaluator
16730
+ };
16731
+ const ret = await runEvaluator(experiment, evalDef, progressReporter, []);
16732
+ resolvedReporter.reportEval(evalDef, ret, {
16733
+ verbose: true,
16734
+ jsonl: false
16735
+ });
16736
+ return ret;
16703
16737
  } finally {
16704
16738
  experiment.flush();
16705
16739
  }
@@ -16707,6 +16741,16 @@ async function Eval(name, evaluator) {
16707
16741
  progressReporter.stop();
16708
16742
  }
16709
16743
  }
16744
+ function Reporter(name, reporter) {
16745
+ const ret = { name, ...reporter };
16746
+ if (_evals.reporters[name]) {
16747
+ throw new Error(`Reporter ${name} already exists`);
16748
+ }
16749
+ if (globalThis._lazy_load) {
16750
+ _evals.reporters[name] = ret;
16751
+ }
16752
+ return ret;
16753
+ }
16710
16754
  function serializeJSONWithPlainString(v) {
16711
16755
  if (typeof v === "string") {
16712
16756
  return v;
@@ -16799,27 +16843,44 @@ async function runEvaluator(experiment, evaluator, progressReporter, filters) {
16799
16843
  const scoreResults = await Promise.all(
16800
16844
  evaluator.scores.map(async (score, score_idx) => {
16801
16845
  try {
16802
- const result = await rootSpan.traced(
16846
+ const results2 = await rootSpan.traced(
16803
16847
  async (span) => {
16804
16848
  const scoreResult = score(scoringArgs);
16805
16849
  const scoreValue = scoreResult instanceof Promise ? await scoreResult : scoreResult;
16806
16850
  if (scoreValue === null) {
16807
16851
  return null;
16808
16852
  }
16809
- const result2 = typeof scoreValue === "object" ? scoreValue : { name: scorerNames[score_idx], score: scoreValue };
16810
- const {
16811
- metadata: resultMetadata,
16812
- name,
16813
- ...resultRest
16814
- } = result2;
16853
+ const scoreValues = Array.isArray(scoreValue) ? scoreValue : [scoreValue];
16854
+ const results3 = scoreValues.map(
16855
+ (scoreValue2, idx) => typeof scoreValue2 === "object" ? scoreValue2 : {
16856
+ name: scoreValues.length > 1 ? `${scorerNames[score_idx]}_${idx}` : scorerNames[score_idx],
16857
+ score: scoreValue2
16858
+ }
16859
+ );
16860
+ const getOtherFields = (s) => {
16861
+ const { metadata: metadata2, name, ...rest } = s;
16862
+ return rest;
16863
+ };
16864
+ const resultMetadata = results3.length === 1 ? results3[0].metadata : results3.reduce(
16865
+ (prev, s) => mergeDicts(prev, {
16866
+ [s.name]: s.metadata
16867
+ }),
16868
+ {}
16869
+ );
16870
+ const resultOutput = results3.length === 1 ? getOtherFields(results3[0]) : results3.reduce(
16871
+ (prev, s) => mergeDicts(prev, { [s.name]: getOtherFields(s) }),
16872
+ {}
16873
+ );
16874
+ const scores2 = results3.reduce(
16875
+ (prev, s) => mergeDicts(prev, { [s.name]: s.score }),
16876
+ {}
16877
+ );
16815
16878
  span.log({
16816
- output: resultRest,
16879
+ output: resultOutput,
16817
16880
  metadata: resultMetadata,
16818
- scores: {
16819
- [name]: resultRest.score
16820
- }
16881
+ scores: scores2
16821
16882
  });
16822
- return result2;
16883
+ return results3;
16823
16884
  },
16824
16885
  {
16825
16886
  name: scorerNames[score_idx],
@@ -16829,7 +16890,7 @@ async function runEvaluator(experiment, evaluator, progressReporter, filters) {
16829
16890
  event: { input: scoringArgs }
16830
16891
  }
16831
16892
  );
16832
- return { kind: "score", value: result };
16893
+ return { kind: "score", value: results2 };
16833
16894
  } catch (e) {
16834
16895
  return { kind: "error", value: e };
16835
16896
  }
@@ -16837,12 +16898,18 @@ async function runEvaluator(experiment, evaluator, progressReporter, filters) {
16837
16898
  );
16838
16899
  const passingScorersAndResults = [];
16839
16900
  const failingScorersAndResults = [];
16840
- scoreResults.forEach((result, i) => {
16901
+ scoreResults.forEach((results2, i) => {
16841
16902
  const name = scorerNames[i];
16842
- if (result.kind === "score") {
16843
- passingScorersAndResults.push({ name, score: result.value });
16903
+ if (results2.kind === "score") {
16904
+ (results2.value || []).forEach((result) => {
16905
+ passingScorersAndResults.push({
16906
+ name: result.name,
16907
+ score: result
16908
+ });
16909
+ scores[result.name] = result.score;
16910
+ });
16844
16911
  } else {
16845
- failingScorersAndResults.push({ name, error: result.value });
16912
+ failingScorersAndResults.push({ name, error: results2.value });
16846
16913
  }
16847
16914
  });
16848
16915
  if (failingScorersAndResults.length) {
@@ -16867,7 +16934,10 @@ async function runEvaluator(experiment, evaluator, progressReporter, filters) {
16867
16934
  progressReporter.increment(evaluator.evalName);
16868
16935
  }
16869
16936
  return {
16937
+ input: datum.input,
16938
+ ..."expected" in datum ? { expected: datum.expected } : {},
16870
16939
  output,
16940
+ tags: datum.tags,
16871
16941
  metadata,
16872
16942
  scores,
16873
16943
  error: error2
@@ -16890,10 +16960,10 @@ async function runEvaluator(experiment, evaluator, progressReporter, filters) {
16890
16960
  }
16891
16961
  });
16892
16962
  const results = await Promise.all(evals);
16893
- const summary = experiment ? await experiment.summarize() : null;
16963
+ const summary = experiment ? await experiment.summarize() : buildLocalSummary(evaluator, results);
16894
16964
  return {
16895
- results,
16896
- summary
16965
+ summary,
16966
+ results
16897
16967
  };
16898
16968
  }
16899
16969
  var error = import_chalk.default.bold.red;
@@ -16905,28 +16975,46 @@ function logError(e, verbose) {
16905
16975
  console.error(e);
16906
16976
  }
16907
16977
  }
16908
- function reportEvaluatorResult(evaluatorName, evaluatorResult, {
16909
- verbose,
16910
- jsonl
16911
- }) {
16912
- const { results, summary } = evaluatorResult;
16913
- const failingResults = results.filter(
16914
- (r) => r.error !== void 0
16915
- );
16978
+ function buildLocalSummary(evaluator, results) {
16979
+ const scoresByName = {};
16980
+ for (const result of results) {
16981
+ for (const [name, score] of Object.entries(result.scores)) {
16982
+ const { total, count } = scoresByName[name] || { total: 0, count: 0 };
16983
+ if (score === null) {
16984
+ continue;
16985
+ }
16986
+ scoresByName[name] = { total: total + score, count: count + 1 };
16987
+ }
16988
+ }
16989
+ return {
16990
+ projectName: evaluator.projectName,
16991
+ experimentName: evaluator.evalName,
16992
+ scores: Object.fromEntries(
16993
+ Object.entries(scoresByName).map(([name, { total, count }]) => [
16994
+ name,
16995
+ {
16996
+ name,
16997
+ score: total / count
16998
+ }
16999
+ ])
17000
+ )
17001
+ };
17002
+ }
17003
+ function reportFailures(evaluator, failingResults, { verbose, jsonl }) {
16916
17004
  if (failingResults.length > 0) {
16917
17005
  console.error(
16918
17006
  warning(
16919
- `Evaluator ${evaluatorName} failed with ${(0, import_pluralize.default)(
17007
+ `Evaluator ${evaluator.evalName} failed with ${(0, import_pluralize.default)(
16920
17008
  "error",
16921
17009
  failingResults.length,
16922
17010
  true
16923
- )}. This evaluation ("${evaluatorName}") will not be fully logged.`
17011
+ )}. This evaluation ("${evaluator.evalName}") will not be fully logged.`
16924
17012
  )
16925
17013
  );
16926
17014
  if (jsonl) {
16927
17015
  console.log(
16928
17016
  JSON.stringify({
16929
- evaluatorName,
17017
+ evaluatorName: evaluator.evalName,
16930
17018
  errors: failingResults.map(
16931
17019
  (r) => `${r.error instanceof Error ? r.error.stack : r.error}`
16932
17020
  )
@@ -16941,33 +17029,24 @@ function reportEvaluatorResult(evaluatorName, evaluatorResult, {
16941
17029
  console.error(warning("Add --verbose to see full stack traces."));
16942
17030
  }
16943
17031
  }
16944
- if (summary) {
16945
- console.log(jsonl ? JSON.stringify(summary) : summary);
16946
- } else {
16947
- const scoresByName = {};
16948
- for (const result of results) {
16949
- for (const [name, score] of Object.entries(result.scores)) {
16950
- const { total, count } = scoresByName[name] || { total: 0, count: 0 };
16951
- if (score === null) {
16952
- continue;
16953
- }
16954
- scoresByName[name] = { total: total + score, count: count + 1 };
16955
- }
17032
+ }
17033
+ var defaultReporter = {
17034
+ name: "Braintrust default reporter",
17035
+ async reportEval(evaluator, result, { verbose, jsonl }) {
17036
+ const { results, summary } = result;
17037
+ const failingResults = results.filter(
17038
+ (r) => r.error !== void 0
17039
+ );
17040
+ if (failingResults.length > 0) {
17041
+ reportFailures(evaluator, failingResults, { verbose, jsonl });
16956
17042
  }
16957
- const summary2 = {
16958
- scores: Object.fromEntries(
16959
- Object.entries(scoresByName).map(([name, { total, count }]) => [
16960
- name,
16961
- {
16962
- name,
16963
- score: total / count
16964
- }
16965
- ])
16966
- )
16967
- };
16968
- console.log(jsonl ? JSON.stringify(summary2) : summary2);
17043
+ console.log(jsonl ? JSON.stringify(summary) : summary);
17044
+ return failingResults.length === 0;
17045
+ },
17046
+ async reportRun(evalReports) {
17047
+ return evalReports.every((r) => r);
16969
17048
  }
16970
- }
17049
+ };
16971
17050
 
16972
17051
  // src/oai.ts
16973
17052
  function wrapOpenAI(openai) {
@@ -17232,9 +17311,11 @@ configureNode();
17232
17311
  NoopSpan,
17233
17312
  Prompt,
17234
17313
  ReadonlyExperiment,
17314
+ Reporter,
17235
17315
  SpanImpl,
17236
17316
  _internalGetGlobalState,
17237
17317
  _internalSetInitialState,
17318
+ buildLocalSummary,
17238
17319
  currentExperiment,
17239
17320
  currentLogger,
17240
17321
  currentSpan,
@@ -17246,6 +17327,7 @@ configureNode();
17246
17327
  loadPrompt,
17247
17328
  log,
17248
17329
  login,
17330
+ reportFailures,
17249
17331
  startSpan,
17250
17332
  summarize,
17251
17333
  traced,