braintrust 2.2.0 → 2.2.1

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
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } async function _asyncOptionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = await fn(value); } else if (op === 'call' || op === 'optionalCall') { value = await fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10; var _class11; var _class12; var _class13; var _class14; var _class15; var _class16; var _class17; var _class18; var _class19; var _class20; var _class21; var _class22;var __defProp = Object.defineProperty;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } async function _asyncOptionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = await fn(value); } else if (op === 'call' || op === 'optionalCall') { value = await fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10; var _class11; var _class12; var _class13; var _class14; var _class15; var _class16; var _class17; var _class18; var _class19; var _class20; var _class21; var _class22; var _class23;var __defProp = Object.defineProperty;
2
2
  var __export = (target, all) => {
3
3
  for (var name in all)
4
4
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -332,11 +332,19 @@ function getIdGenerator() {
332
332
 
333
333
  // util/db_fields.ts
334
334
  var TRANSACTION_ID_FIELD = "_xact_id";
335
+ var OBJECT_DELETE_FIELD = "_object_delete";
335
336
  var IS_MERGE_FIELD = "_is_merge";
336
337
  var AUDIT_SOURCE_FIELD = "_audit_source";
337
338
  var AUDIT_METADATA_FIELD = "_audit_metadata";
338
339
  var VALID_SOURCES = ["app", "api", "external"];
339
- var PARENT_ID_FIELD = "_parent_id";
340
+ var OBJECT_ID_KEYS = [
341
+ "experiment_id",
342
+ "dataset_id",
343
+ "prompt_session_id",
344
+ "project_id",
345
+ "log_id",
346
+ "function_data"
347
+ ];
340
348
 
341
349
  // util/span_identifier_v3.ts
342
350
 
@@ -1007,13 +1015,6 @@ function mergeDictsWithPathsHelper({
1007
1015
  function mergeDicts(mergeInto, mergeFrom) {
1008
1016
  return mergeDictsWithPaths({ mergeInto, mergeFrom, mergePaths: [] });
1009
1017
  }
1010
- function mapAt(m, k) {
1011
- const ret = m.get(k);
1012
- if (ret === void 0) {
1013
- throw new Error(`Map does not contain key ${k}`);
1014
- }
1015
- return ret;
1016
- }
1017
1018
  function recordFind(m, k) {
1018
1019
  return m[k];
1019
1020
  }
@@ -1028,72 +1029,8 @@ function getObjValueByPath(row, path2) {
1028
1029
  return curr;
1029
1030
  }
1030
1031
 
1031
- // util/graph_util.ts
1032
- function depthFirstSearch(args) {
1033
- const { graph, firstVisitF, lastVisitF } = args;
1034
- for (const vs of graph.values()) {
1035
- for (const v of vs.values()) {
1036
- if (!graph.has(v)) {
1037
- throw new Error(`Outgoing vertex ${v} must be a key in the graph`);
1038
- }
1039
- }
1040
- }
1041
- const firstVisitedVertices = /* @__PURE__ */ new Set();
1042
- const visitationOrder = _nullishCoalesce(args.visitationOrder, () => ( [...graph.keys()]));
1043
- const events = visitationOrder.map((vertex) => ({ eventType: "first", vertex, extras: {} })).reverse();
1044
- while (events.length) {
1045
- const { eventType, vertex, extras } = events.pop();
1046
- if (eventType === "last") {
1047
- _optionalChain([lastVisitF, 'optionalCall', _17 => _17(vertex)]);
1048
- continue;
1049
- }
1050
- if (firstVisitedVertices.has(vertex)) {
1051
- continue;
1052
- }
1053
- firstVisitedVertices.add(vertex);
1054
- _optionalChain([firstVisitF, 'optionalCall', _18 => _18(vertex, { parentVertex: extras.parentVertex })]);
1055
- events.push({ eventType: "last", vertex, extras: {} });
1056
- mapAt(graph, vertex).forEach((child) => {
1057
- events.push({
1058
- eventType: "first",
1059
- vertex: child,
1060
- extras: { parentVertex: vertex }
1061
- });
1062
- });
1063
- }
1064
- }
1065
- function undirectedConnectedComponents(graph) {
1066
- const directedGraph = new Map(
1067
- [...graph.vertices].map((v) => [v, /* @__PURE__ */ new Set()])
1068
- );
1069
- for (const [i, j] of graph.edges) {
1070
- mapAt(directedGraph, i).add(j);
1071
- mapAt(directedGraph, j).add(i);
1072
- }
1073
- let labelCounter = 0;
1074
- const vertexLabels = /* @__PURE__ */ new Map();
1075
- const firstVisitF = (vertex, args) => {
1076
- const label = _optionalChain([args, 'optionalAccess', _19 => _19.parentVertex]) !== void 0 ? mapAt(vertexLabels, _optionalChain([args, 'optionalAccess', _20 => _20.parentVertex])) : labelCounter++;
1077
- vertexLabels.set(vertex, label);
1078
- };
1079
- depthFirstSearch({ graph: directedGraph, firstVisitF });
1080
- const output = Array.from({ length: labelCounter }).map(() => []);
1081
- for (const [vertex, label] of vertexLabels.entries()) {
1082
- output[label].push(vertex);
1083
- }
1084
- return output;
1085
- }
1086
- function topologicalSort(graph, visitationOrder) {
1087
- const reverseOrdering = [];
1088
- const lastVisitF = (vertex) => {
1089
- reverseOrdering.push(vertex);
1090
- };
1091
- depthFirstSearch({ graph, lastVisitF, visitationOrder });
1092
- return reverseOrdering.reverse();
1093
- }
1094
-
1095
1032
  // util/merge_row_batch.ts
1096
- function generateMergedRowKey(row, useParentIdForId) {
1033
+ function generateMergedRowKey(row) {
1097
1034
  return JSON.stringify(
1098
1035
  [
1099
1036
  "org_id",
@@ -1102,7 +1039,7 @@ function generateMergedRowKey(row, useParentIdForId) {
1102
1039
  "dataset_id",
1103
1040
  "prompt_session_id",
1104
1041
  "log_id",
1105
- _nullishCoalesce(useParentIdForId, () => ( false)) ? PARENT_ID_FIELD : "id"
1042
+ "id"
1106
1043
  ].map((k) => row[k])
1107
1044
  );
1108
1045
  }
@@ -1156,96 +1093,34 @@ function mergeRowBatch(rows) {
1156
1093
  rowGroups.set(key, row);
1157
1094
  }
1158
1095
  }
1159
- const merged = [...rowGroups.values()];
1160
- const rowToLabel = new Map(
1161
- merged.map((r, i) => [generateMergedRowKey(r), i])
1162
- );
1163
- const graph = new Map(
1164
- Array.from({ length: merged.length }).map((_, i) => [i, /* @__PURE__ */ new Set()])
1165
- );
1166
- merged.forEach((r, i) => {
1167
- const parentId = r[PARENT_ID_FIELD];
1168
- if (!parentId) {
1169
- return;
1170
- }
1171
- const parentRowKey = generateMergedRowKey(
1172
- r,
1173
- true
1174
- /* useParentIdForId */
1175
- );
1176
- const parentLabel = rowToLabel.get(parentRowKey);
1177
- if (parentLabel !== void 0) {
1178
- mapAt(graph, parentLabel).add(i);
1179
- }
1180
- });
1181
- const connectedComponents = undirectedConnectedComponents({
1182
- vertices: new Set(graph.keys()),
1183
- edges: new Set(
1184
- [...graph.entries()].flatMap(
1185
- ([k, vs]) => [...vs].map((v) => {
1186
- const ret = [k, v];
1187
- return ret;
1188
- })
1189
- )
1190
- )
1191
- });
1192
- const buckets = connectedComponents.map(
1193
- (cc) => topologicalSort(
1194
- graph,
1195
- cc
1196
- /* visitationOrder */
1197
- )
1198
- );
1199
- return buckets.map((bucket) => bucket.map((i) => merged[i]));
1096
+ return [...rowGroups.values()];
1200
1097
  }
1201
1098
  function batchItems(args) {
1202
- let { items } = args;
1099
+ const { items } = args;
1203
1100
  const batchMaxNumItems = _nullishCoalesce(args.batchMaxNumItems, () => ( Number.POSITIVE_INFINITY));
1204
1101
  const batchMaxNumBytes = _nullishCoalesce(args.batchMaxNumBytes, () => ( Number.POSITIVE_INFINITY));
1102
+ const getByteSize = args.getByteSize;
1205
1103
  const output = [];
1206
- let nextItems = [];
1207
- let batchSet = [];
1208
1104
  let batch = [];
1209
1105
  let batchLen = 0;
1210
1106
  function addToBatch(item) {
1211
1107
  batch.push(item);
1212
- batchLen += item.length;
1108
+ batchLen += getByteSize(item);
1213
1109
  }
1214
1110
  function flushBatch() {
1215
- batchSet.push(batch);
1111
+ output.push(batch);
1216
1112
  batch = [];
1217
1113
  batchLen = 0;
1218
1114
  }
1219
- while (items.length) {
1220
- for (const bucket of items) {
1221
- let i = 0;
1222
- for (const item of bucket) {
1223
- if (batch.length === 0 || item.length + batchLen < batchMaxNumBytes && batch.length < batchMaxNumItems) {
1224
- addToBatch(item);
1225
- } else if (i === 0) {
1226
- flushBatch();
1227
- addToBatch(item);
1228
- } else {
1229
- break;
1230
- }
1231
- ++i;
1232
- }
1233
- if (i < bucket.length) {
1234
- nextItems.push(bucket.slice(i));
1235
- }
1236
- if (batchLen >= batchMaxNumBytes || batch.length > batchMaxNumItems) {
1237
- flushBatch();
1238
- }
1239
- }
1240
- if (batch.length) {
1115
+ for (const item of items) {
1116
+ const itemSize = getByteSize(item);
1117
+ if (batch.length > 0 && !(itemSize + batchLen < batchMaxNumBytes && batch.length < batchMaxNumItems)) {
1241
1118
  flushBatch();
1242
1119
  }
1243
- if (batchSet.length) {
1244
- output.push(batchSet);
1245
- batchSet = [];
1246
- }
1247
- items = nextItems;
1248
- nextItems = [];
1120
+ addToBatch(item);
1121
+ }
1122
+ if (batch.length > 0) {
1123
+ flushBatch();
1249
1124
  }
1250
1125
  return output;
1251
1126
  }
@@ -1363,20 +1238,20 @@ function slugify(text, options) {
1363
1238
  \u00FF: "y"
1364
1239
  };
1365
1240
  const replacement = "-";
1366
- const trim = _optionalChain([options, 'optionalAccess', _21 => _21.trim]) !== false;
1241
+ const trim = _optionalChain([options, 'optionalAccess', _17 => _17.trim]) !== false;
1367
1242
  let slug = text.normalize().split("").reduce((result, ch) => {
1368
1243
  const mapped = charMap[ch] || ch;
1369
1244
  const appendChar = mapped === replacement ? " " : mapped;
1370
1245
  return result + appendChar.replace(/[^\w\s$*_+~.()'"!\-:@]+/g, "");
1371
1246
  }, "");
1372
- if (_optionalChain([options, 'optionalAccess', _22 => _22.strict])) {
1247
+ if (_optionalChain([options, 'optionalAccess', _18 => _18.strict])) {
1373
1248
  slug = slug.replace(/[^A-Za-z0-9\s]/g, "");
1374
1249
  }
1375
1250
  if (trim) {
1376
1251
  slug = slug.trim();
1377
1252
  }
1378
1253
  slug = slug.replace(/\s+/g, replacement);
1379
- if (_optionalChain([options, 'optionalAccess', _23 => _23.lower])) {
1254
+ if (_optionalChain([options, 'optionalAccess', _19 => _19.lower])) {
1380
1255
  slug = slug.toLowerCase();
1381
1256
  }
1382
1257
  return slug;
@@ -1832,10 +1707,15 @@ var FunctionTypeEnum = _v3.z.enum([
1832
1707
  "preprocessor",
1833
1708
  "facet",
1834
1709
  "classifier",
1835
- "tag"
1710
+ "tag",
1711
+ "parameters"
1836
1712
  ]);
1837
1713
  var NullableSavedFunctionId = _v3.z.union([
1838
- _v3.z.object({ type: _v3.z.literal("function"), id: _v3.z.string() }),
1714
+ _v3.z.object({
1715
+ type: _v3.z.literal("function"),
1716
+ id: _v3.z.string(),
1717
+ version: _v3.z.string().optional()
1718
+ }),
1839
1719
  _v3.z.object({
1840
1720
  type: _v3.z.literal("global"),
1841
1721
  name: _v3.z.string(),
@@ -1843,6 +1723,67 @@ var NullableSavedFunctionId = _v3.z.union([
1843
1723
  }),
1844
1724
  _v3.z.null()
1845
1725
  ]);
1726
+ var TopicMapReport = _v3.z.object({
1727
+ version: _v3.z.literal(1),
1728
+ created_at: _v3.z.string().optional(),
1729
+ settings: _v3.z.object({
1730
+ algorithm: _v3.z.enum(["hdbscan", "kmeans", "hierarchical"]),
1731
+ dimension_reduction: _v3.z.enum(["umap", "pca", "none"]),
1732
+ vector_field: _v3.z.string(),
1733
+ embedding_model: _v3.z.string(),
1734
+ n_clusters: _v3.z.union([_v3.z.number(), _v3.z.null()]).optional(),
1735
+ umap_dimensions: _v3.z.union([_v3.z.number(), _v3.z.null()]).optional(),
1736
+ min_cluster_size: _v3.z.union([_v3.z.number(), _v3.z.null()]).optional(),
1737
+ min_samples: _v3.z.union([_v3.z.number(), _v3.z.null()]).optional()
1738
+ }),
1739
+ query_settings: _v3.z.object({
1740
+ hierarchy_threshold: _v3.z.union([_v3.z.number(), _v3.z.null()]),
1741
+ auto_naming: _v3.z.boolean(),
1742
+ skip_cache: _v3.z.boolean(),
1743
+ viz_mode: _v3.z.enum(["bar", "scatter"]),
1744
+ naming_model: _v3.z.string()
1745
+ }).partial(),
1746
+ clusters: _v3.z.array(
1747
+ _v3.z.object({
1748
+ cluster_id: _v3.z.number(),
1749
+ parent_cluster_id: _v3.z.union([_v3.z.number(), _v3.z.null()]).optional(),
1750
+ topic_id: _v3.z.string(),
1751
+ count: _v3.z.number(),
1752
+ sample_texts: _v3.z.array(_v3.z.string()),
1753
+ samples: _v3.z.array(
1754
+ _v3.z.object({
1755
+ id: _v3.z.string(),
1756
+ text: _v3.z.string(),
1757
+ root_span_id: _v3.z.string(),
1758
+ span_id: _v3.z.string()
1759
+ })
1760
+ ),
1761
+ name: _v3.z.string().optional(),
1762
+ description: _v3.z.string().optional(),
1763
+ keywords: _v3.z.array(_v3.z.string()).optional(),
1764
+ centroid: _v3.z.array(_v3.z.number()).optional(),
1765
+ parent_id: _v3.z.union([_v3.z.number(), _v3.z.null()]).optional(),
1766
+ is_leaf: _v3.z.boolean().optional(),
1767
+ depth: _v3.z.number().optional()
1768
+ })
1769
+ ),
1770
+ embedding_points: _v3.z.array(
1771
+ _v3.z.object({
1772
+ x: _v3.z.number(),
1773
+ y: _v3.z.number(),
1774
+ cluster: _v3.z.number(),
1775
+ text: _v3.z.string().optional()
1776
+ })
1777
+ ).optional()
1778
+ });
1779
+ var TopicMapData = _v3.z.object({
1780
+ type: _v3.z.literal("topic_map"),
1781
+ source_facet: _v3.z.string(),
1782
+ embedding_model: _v3.z.string(),
1783
+ bundle_key: _v3.z.string(),
1784
+ distance_threshold: _v3.z.number().optional(),
1785
+ report: TopicMapReport.optional()
1786
+ });
1846
1787
  var BatchedFacetData = _v3.z.object({
1847
1788
  type: _v3.z.literal("batched_facet"),
1848
1789
  preprocessor: NullableSavedFunctionId.and(_v3.z.unknown()).optional(),
@@ -1851,9 +1792,17 @@ var BatchedFacetData = _v3.z.object({
1851
1792
  name: _v3.z.string(),
1852
1793
  prompt: _v3.z.string(),
1853
1794
  model: _v3.z.string().optional(),
1795
+ embedding_model: _v3.z.string().optional(),
1854
1796
  no_match_pattern: _v3.z.string().optional()
1855
1797
  })
1856
- )
1798
+ ),
1799
+ topic_maps: _v3.z.record(
1800
+ _v3.z.object({
1801
+ function_name: _v3.z.string(),
1802
+ topic_map_id: _v3.z.string().optional(),
1803
+ topic_map_data: TopicMapData
1804
+ })
1805
+ ).optional()
1857
1806
  });
1858
1807
  var BraintrustModelParams = _v3.z.object({
1859
1808
  use_cache: _v3.z.boolean(),
@@ -2064,6 +2013,18 @@ var ObjectReferenceNullish = _v3.z.union([
2064
2013
  }),
2065
2014
  _v3.z.null()
2066
2015
  ]);
2016
+ var SavedFunctionId = _v3.z.union([
2017
+ _v3.z.object({
2018
+ type: _v3.z.literal("function"),
2019
+ id: _v3.z.string(),
2020
+ version: _v3.z.string().optional()
2021
+ }),
2022
+ _v3.z.object({
2023
+ type: _v3.z.literal("global"),
2024
+ name: _v3.z.string(),
2025
+ function_type: FunctionTypeEnum.optional().default("scorer")
2026
+ })
2027
+ ]);
2067
2028
  var DatasetEvent = _v3.z.object({
2068
2029
  id: _v3.z.string(),
2069
2030
  _xact_id: _v3.z.string(),
@@ -2083,7 +2044,36 @@ var DatasetEvent = _v3.z.object({
2083
2044
  is_root: _v3.z.union([_v3.z.boolean(), _v3.z.null()]).optional(),
2084
2045
  origin: ObjectReferenceNullish.optional(),
2085
2046
  comments: _v3.z.union([_v3.z.array(_v3.z.unknown()), _v3.z.null()]).optional(),
2086
- audit_data: _v3.z.union([_v3.z.array(_v3.z.unknown()), _v3.z.null()]).optional()
2047
+ audit_data: _v3.z.union([_v3.z.array(_v3.z.unknown()), _v3.z.null()]).optional(),
2048
+ facets: _v3.z.union([_v3.z.object({}).partial().passthrough(), _v3.z.null()]).optional(),
2049
+ classifications: _v3.z.union([
2050
+ _v3.z.record(
2051
+ _v3.z.array(
2052
+ _v3.z.object({
2053
+ id: _v3.z.string(),
2054
+ label: _v3.z.string().optional(),
2055
+ confidence: _v3.z.union([_v3.z.number(), _v3.z.null()]).optional(),
2056
+ metadata: _v3.z.union([_v3.z.object({}).partial().passthrough(), _v3.z.null()]).optional(),
2057
+ source: SavedFunctionId.and(
2058
+ _v3.z.union([
2059
+ _v3.z.object({
2060
+ type: _v3.z.literal("function"),
2061
+ id: _v3.z.string(),
2062
+ version: _v3.z.string().optional()
2063
+ }),
2064
+ _v3.z.object({
2065
+ type: _v3.z.literal("global"),
2066
+ name: _v3.z.string(),
2067
+ function_type: FunctionTypeEnum.optional().default("scorer")
2068
+ }),
2069
+ _v3.z.null()
2070
+ ])
2071
+ ).optional()
2072
+ })
2073
+ )
2074
+ ),
2075
+ _v3.z.null()
2076
+ ]).optional()
2087
2077
  });
2088
2078
  var EnvVar = _v3.z.object({
2089
2079
  id: _v3.z.string().uuid(),
@@ -2160,7 +2150,8 @@ var SpanType = _v3.z.union([
2160
2150
  "automation",
2161
2151
  "facet",
2162
2152
  "preprocessor",
2163
- "classifier"
2153
+ "classifier",
2154
+ "review"
2164
2155
  ]),
2165
2156
  _v3.z.null()
2166
2157
  ]);
@@ -2201,10 +2192,43 @@ var ExperimentEvent = _v3.z.object({
2201
2192
  is_root: _v3.z.union([_v3.z.boolean(), _v3.z.null()]).optional(),
2202
2193
  origin: ObjectReferenceNullish.optional(),
2203
2194
  comments: _v3.z.union([_v3.z.array(_v3.z.unknown()), _v3.z.null()]).optional(),
2204
- audit_data: _v3.z.union([_v3.z.array(_v3.z.unknown()), _v3.z.null()]).optional()
2195
+ audit_data: _v3.z.union([_v3.z.array(_v3.z.unknown()), _v3.z.null()]).optional(),
2196
+ facets: _v3.z.union([_v3.z.object({}).partial().passthrough(), _v3.z.null()]).optional(),
2197
+ classifications: _v3.z.union([
2198
+ _v3.z.record(
2199
+ _v3.z.array(
2200
+ _v3.z.object({
2201
+ id: _v3.z.string(),
2202
+ label: _v3.z.string().optional(),
2203
+ confidence: _v3.z.union([_v3.z.number(), _v3.z.null()]).optional(),
2204
+ metadata: _v3.z.union([_v3.z.object({}).partial().passthrough(), _v3.z.null()]).optional(),
2205
+ source: SavedFunctionId.and(
2206
+ _v3.z.union([
2207
+ _v3.z.object({
2208
+ type: _v3.z.literal("function"),
2209
+ id: _v3.z.string(),
2210
+ version: _v3.z.string().optional()
2211
+ }),
2212
+ _v3.z.object({
2213
+ type: _v3.z.literal("global"),
2214
+ name: _v3.z.string(),
2215
+ function_type: FunctionTypeEnum.optional().default("scorer")
2216
+ }),
2217
+ _v3.z.null()
2218
+ ])
2219
+ ).optional()
2220
+ })
2221
+ )
2222
+ ),
2223
+ _v3.z.null()
2224
+ ]).optional()
2205
2225
  });
2206
2226
  var ExtendedSavedFunctionId = _v3.z.union([
2207
- _v3.z.object({ type: _v3.z.literal("function"), id: _v3.z.string() }),
2227
+ _v3.z.object({
2228
+ type: _v3.z.literal("function"),
2229
+ id: _v3.z.string(),
2230
+ version: _v3.z.string().optional()
2231
+ }),
2208
2232
  _v3.z.object({
2209
2233
  type: _v3.z.literal("global"),
2210
2234
  name: _v3.z.string(),
@@ -2221,6 +2245,7 @@ var FacetData = _v3.z.object({
2221
2245
  preprocessor: NullableSavedFunctionId.and(_v3.z.unknown()).optional(),
2222
2246
  prompt: _v3.z.string(),
2223
2247
  model: _v3.z.string().optional(),
2248
+ embedding_model: _v3.z.string().optional(),
2224
2249
  no_match_pattern: _v3.z.string().optional()
2225
2250
  });
2226
2251
  var PromptBlockDataNullish = _v3.z.union([
@@ -2310,14 +2335,6 @@ var PromptParserNullish = _v3.z.union([
2310
2335
  }),
2311
2336
  _v3.z.null()
2312
2337
  ]);
2313
- var SavedFunctionId = _v3.z.union([
2314
- _v3.z.object({ type: _v3.z.literal("function"), id: _v3.z.string() }),
2315
- _v3.z.object({
2316
- type: _v3.z.literal("global"),
2317
- name: _v3.z.string(),
2318
- function_type: FunctionTypeEnum.optional().default("scorer")
2319
- })
2320
- ]);
2321
2338
  var PromptDataNullish = _v3.z.union([
2322
2339
  _v3.z.object({
2323
2340
  prompt: PromptBlockDataNullish,
@@ -2368,7 +2385,8 @@ var FunctionTypeEnumNullish = _v3.z.union([
2368
2385
  "preprocessor",
2369
2386
  "facet",
2370
2387
  "classifier",
2371
- "tag"
2388
+ "tag",
2389
+ "parameters"
2372
2390
  ]),
2373
2391
  _v3.z.null()
2374
2392
  ]);
@@ -2460,7 +2478,8 @@ var FunctionData = _v3.z.union([
2460
2478
  type: _v3.z.literal("remote_eval"),
2461
2479
  endpoint: _v3.z.string(),
2462
2480
  eval_name: _v3.z.string(),
2463
- parameters: _v3.z.object({}).partial().passthrough()
2481
+ parameters: _v3.z.object({}).partial().passthrough(),
2482
+ parameters_version: _v3.z.union([_v3.z.string(), _v3.z.null()]).optional()
2464
2483
  }),
2465
2484
  _v3.z.object({
2466
2485
  type: _v3.z.literal("global"),
@@ -2469,7 +2488,18 @@ var FunctionData = _v3.z.union([
2469
2488
  config: _v3.z.union([_v3.z.object({}).partial().passthrough(), _v3.z.null()]).optional()
2470
2489
  }),
2471
2490
  FacetData,
2472
- BatchedFacetData
2491
+ BatchedFacetData,
2492
+ _v3.z.object({
2493
+ type: _v3.z.literal("parameters"),
2494
+ data: _v3.z.object({}).partial().passthrough(),
2495
+ __schema: _v3.z.object({
2496
+ type: _v3.z.literal("object"),
2497
+ properties: _v3.z.record(_v3.z.object({}).partial().passthrough()),
2498
+ required: _v3.z.array(_v3.z.string()).optional(),
2499
+ additionalProperties: _v3.z.boolean().optional()
2500
+ })
2501
+ }),
2502
+ TopicMapData.and(_v3.z.unknown())
2473
2503
  ]);
2474
2504
  var Function = _v3.z.object({
2475
2505
  id: _v3.z.string().uuid(),
@@ -2499,7 +2529,13 @@ var Function = _v3.z.object({
2499
2529
  _v3.z.null()
2500
2530
  ]).optional()
2501
2531
  });
2502
- var FunctionFormat = _v3.z.enum(["llm", "code", "global", "graph"]);
2532
+ var FunctionFormat = _v3.z.enum([
2533
+ "llm",
2534
+ "code",
2535
+ "global",
2536
+ "graph",
2537
+ "topic_map"
2538
+ ]);
2503
2539
  var PromptData = _v3.z.object({
2504
2540
  prompt: PromptBlockDataNullish,
2505
2541
  options: PromptOptionsNullish,
@@ -2582,13 +2618,14 @@ var FunctionObjectType = _v3.z.enum([
2582
2618
  "custom_view",
2583
2619
  "preprocessor",
2584
2620
  "facet",
2585
- "classifier"
2621
+ "classifier",
2622
+ "parameters"
2586
2623
  ]);
2587
2624
  var FunctionOutputType = _v3.z.enum([
2588
2625
  "completion",
2589
2626
  "score",
2590
2627
  "facet",
2591
- "tag",
2628
+ "classification",
2592
2629
  "any"
2593
2630
  ]);
2594
2631
  var GitMetadataSettings = _v3.z.object({
@@ -2624,6 +2661,10 @@ var GroupScope = _v3.z.object({
2624
2661
  idle_seconds: _v3.z.number().optional()
2625
2662
  });
2626
2663
  var IfExists = _v3.z.enum(["error", "ignore", "replace"]);
2664
+ var ImageRenderingMode = _v3.z.union([
2665
+ _v3.z.enum(["auto", "click_to_load", "blocked"]),
2666
+ _v3.z.null()
2667
+ ]);
2627
2668
  var InvokeParent = _v3.z.union([
2628
2669
  _v3.z.object({
2629
2670
  object_type: _v3.z.enum(["project_logs", "experiment", "playground_logs"]),
@@ -2716,7 +2757,8 @@ var Organization = _v3.z.object({
2716
2757
  is_universal_api: _v3.z.union([_v3.z.boolean(), _v3.z.null()]).optional(),
2717
2758
  proxy_url: _v3.z.union([_v3.z.string(), _v3.z.null()]).optional(),
2718
2759
  realtime_url: _v3.z.union([_v3.z.string(), _v3.z.null()]).optional(),
2719
- created: _v3.z.union([_v3.z.string(), _v3.z.null()]).optional()
2760
+ created: _v3.z.union([_v3.z.string(), _v3.z.null()]).optional(),
2761
+ image_rendering_mode: ImageRenderingMode.optional()
2720
2762
  });
2721
2763
  var ProjectSettings = _v3.z.union([
2722
2764
  _v3.z.object({
@@ -2857,7 +2899,36 @@ var ProjectLogsEvent = _v3.z.object({
2857
2899
  origin: ObjectReferenceNullish.optional(),
2858
2900
  comments: _v3.z.union([_v3.z.array(_v3.z.unknown()), _v3.z.null()]).optional(),
2859
2901
  audit_data: _v3.z.union([_v3.z.array(_v3.z.unknown()), _v3.z.null()]).optional(),
2860
- _async_scoring_state: _v3.z.unknown().optional()
2902
+ _async_scoring_state: _v3.z.unknown().optional(),
2903
+ facets: _v3.z.union([_v3.z.object({}).partial().passthrough(), _v3.z.null()]).optional(),
2904
+ classifications: _v3.z.union([
2905
+ _v3.z.record(
2906
+ _v3.z.array(
2907
+ _v3.z.object({
2908
+ id: _v3.z.string(),
2909
+ label: _v3.z.string().optional(),
2910
+ confidence: _v3.z.union([_v3.z.number(), _v3.z.null()]).optional(),
2911
+ metadata: _v3.z.union([_v3.z.object({}).partial().passthrough(), _v3.z.null()]).optional(),
2912
+ source: SavedFunctionId.and(
2913
+ _v3.z.union([
2914
+ _v3.z.object({
2915
+ type: _v3.z.literal("function"),
2916
+ id: _v3.z.string(),
2917
+ version: _v3.z.string().optional()
2918
+ }),
2919
+ _v3.z.object({
2920
+ type: _v3.z.literal("global"),
2921
+ name: _v3.z.string(),
2922
+ function_type: FunctionTypeEnum.optional().default("scorer")
2923
+ }),
2924
+ _v3.z.null()
2925
+ ])
2926
+ ).optional()
2927
+ })
2928
+ )
2929
+ ),
2930
+ _v3.z.null()
2931
+ ]).optional()
2861
2932
  });
2862
2933
  var ProjectScoreType = _v3.z.enum([
2863
2934
  "slider",
@@ -3159,12 +3230,15 @@ var View = _v3.z.object({
3159
3230
  "datasets",
3160
3231
  "dataset",
3161
3232
  "prompts",
3233
+ "parameters",
3162
3234
  "tools",
3163
3235
  "scorers",
3164
3236
  "classifiers",
3165
3237
  "logs",
3166
3238
  "monitor",
3167
- "for_review"
3239
+ "for_review_project_log",
3240
+ "for_review_experiments",
3241
+ "for_review_datasets"
3168
3242
  ]),
3169
3243
  name: _v3.z.string(),
3170
3244
  created: _v3.z.union([_v3.z.string(), _v3.z.null()]).optional(),
@@ -3909,6 +3983,52 @@ var PromptCache = class {
3909
3983
  }
3910
3984
  };
3911
3985
 
3986
+ // src/prompt-cache/parameters-cache.ts
3987
+ function createCacheKey2(key) {
3988
+ if (key.id) {
3989
+ return `parameters:id:${key.id}`;
3990
+ }
3991
+ const prefix = _nullishCoalesce(key.projectId, () => ( key.projectName));
3992
+ if (!prefix) {
3993
+ throw new Error("Either projectId or projectName must be provided");
3994
+ }
3995
+ if (!key.slug) {
3996
+ throw new Error("Slug must be provided when not using ID");
3997
+ }
3998
+ return `parameters:${prefix}:${key.slug}:${_nullishCoalesce(key.version, () => ( "latest"))}`;
3999
+ }
4000
+ var ParametersCache = class {
4001
+
4002
+
4003
+ constructor(options) {
4004
+ this.memoryCache = options.memoryCache;
4005
+ this.diskCache = options.diskCache;
4006
+ }
4007
+ async get(key) {
4008
+ const cacheKey = createCacheKey2(key);
4009
+ const memoryParams = this.memoryCache.get(cacheKey);
4010
+ if (memoryParams !== void 0) {
4011
+ return memoryParams;
4012
+ }
4013
+ if (this.diskCache) {
4014
+ const diskParams = await this.diskCache.get(cacheKey);
4015
+ if (!diskParams) {
4016
+ return void 0;
4017
+ }
4018
+ this.memoryCache.set(cacheKey, diskParams);
4019
+ return diskParams;
4020
+ }
4021
+ return void 0;
4022
+ }
4023
+ async set(key, value) {
4024
+ const cacheKey = createCacheKey2(key);
4025
+ this.memoryCache.set(cacheKey, value);
4026
+ if (this.diskCache) {
4027
+ await this.diskCache.set(cacheKey, value);
4028
+ }
4029
+ }
4030
+ };
4031
+
3912
4032
  // src/span-cache.ts
3913
4033
  var activeCaches = /* @__PURE__ */ new Set();
3914
4034
  var exitHandlersRegistered = false;
@@ -3930,7 +4050,7 @@ var SpanCache = (_class4 = class {
3930
4050
  // Small in-memory index tracking which rootSpanIds have data
3931
4051
  __init12() {this.rootSpanIndex = /* @__PURE__ */ new Set()}
3932
4052
  constructor(options) {;_class4.prototype.__init6.call(this);_class4.prototype.__init7.call(this);_class4.prototype.__init8.call(this);_class4.prototype.__init9.call(this);_class4.prototype.__init10.call(this);_class4.prototype.__init11.call(this);_class4.prototype.__init12.call(this);_class4.prototype.__init13.call(this);_class4.prototype.__init14.call(this);_class4.prototype.__init15.call(this);
3933
- this._explicitlyDisabled = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _24 => _24.disabled]), () => ( false));
4053
+ this._explicitlyDisabled = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _20 => _20.disabled]), () => ( false));
3934
4054
  }
3935
4055
  /**
3936
4056
  * Disable the cache at runtime. This is called automatically when
@@ -4199,7 +4319,24 @@ var SpanCache = (_class4 = class {
4199
4319
  // src/logger.ts
4200
4320
  var BRAINTRUST_ATTACHMENT = BraintrustAttachmentReference.shape.type.value;
4201
4321
  var EXTERNAL_ATTACHMENT = ExternalAttachmentReference.shape.type.value;
4322
+ var LOGS3_OVERFLOW_REFERENCE_TYPE = "logs3_overflow";
4202
4323
  var BRAINTRUST_PARAMS = Object.keys(BraintrustModelParams.shape);
4324
+ var DEFAULT_MAX_REQUEST_SIZE = 6 * 1024 * 1024;
4325
+ var parametersRowSchema = _v3.z.object({
4326
+ id: _v3.z.string().uuid(),
4327
+ _xact_id: _v3.z.string(),
4328
+ project_id: _v3.z.string().uuid(),
4329
+ name: _v3.z.string(),
4330
+ slug: _v3.z.string(),
4331
+ description: _v3.z.union([_v3.z.string(), _v3.z.null()]).optional(),
4332
+ function_type: _v3.z.literal("parameters"),
4333
+ function_data: _v3.z.object({
4334
+ type: _v3.z.literal("parameters"),
4335
+ data: _v3.z.record(_v3.z.unknown()).optional(),
4336
+ __schema: _v3.z.record(_v3.z.unknown())
4337
+ }),
4338
+ metadata: _v3.z.union([_v3.z.object({}).partial().passthrough(), _v3.z.null()]).optional()
4339
+ });
4203
4340
  var LoginInvalidOrgError = class extends Error {
4204
4341
  constructor(message) {
4205
4342
  super(message);
@@ -4297,7 +4434,7 @@ var NoopSpan = (_class5 = class {
4297
4434
  return this;
4298
4435
  }
4299
4436
  end(args) {
4300
- return _nullishCoalesce(_optionalChain([args, 'optionalAccess', _25 => _25.endTime]), () => ( getCurrentUnixTimestamp()));
4437
+ return _nullishCoalesce(_optionalChain([args, 'optionalAccess', _21 => _21.endTime]), () => ( getCurrentUnixTimestamp()));
4301
4438
  }
4302
4439
  async export() {
4303
4440
  return "";
@@ -4376,6 +4513,17 @@ var BraintrustState = (_class6 = class _BraintrustState {
4376
4513
  max: _nullishCoalesce(Number(isomorph_default.getEnv("BRAINTRUST_PROMPT_CACHE_DISK_MAX")), () => ( 1 << 20))
4377
4514
  }) : void 0;
4378
4515
  this.promptCache = new PromptCache({ memoryCache, diskCache });
4516
+ const parametersMemoryCache = new LRUCache({
4517
+ max: _nullishCoalesce(Number(isomorph_default.getEnv("BRAINTRUST_PARAMETERS_CACHE_MEMORY_MAX")), () => ( 1 << 10))
4518
+ });
4519
+ const parametersDiskCache = canUseDiskCache() ? new DiskCache({
4520
+ cacheDir: _nullishCoalesce(isomorph_default.getEnv("BRAINTRUST_PARAMETERS_CACHE_DIR"), () => ( `${_nullishCoalesce(isomorph_default.getEnv("HOME"), () => ( isomorph_default.homedir()))}/.braintrust/parameters_cache`)),
4521
+ max: _nullishCoalesce(Number(isomorph_default.getEnv("BRAINTRUST_PARAMETERS_CACHE_DISK_MAX")), () => ( 1 << 20))
4522
+ }) : void 0;
4523
+ this.parametersCache = new ParametersCache({
4524
+ memoryCache: parametersMemoryCache,
4525
+ diskCache: parametersDiskCache
4526
+ });
4379
4527
  this.spanCache = new SpanCache({ disabled: loginParams.disableSpanCache });
4380
4528
  }
4381
4529
 
@@ -4406,6 +4554,7 @@ var BraintrustState = (_class6 = class _BraintrustState {
4406
4554
  __init29() {this._proxyConn = null}
4407
4555
 
4408
4556
 
4557
+
4409
4558
  __init30() {this._idGenerator = null}
4410
4559
  __init31() {this._contextManager = null}
4411
4560
  __init32() {this._otelFlushCallback = null}
@@ -4521,8 +4670,8 @@ var BraintrustState = (_class6 = class _BraintrustState {
4521
4670
  setFetch(fetch2) {
4522
4671
  this.loginParams.fetch = fetch2;
4523
4672
  this.fetch = fetch2;
4524
- _optionalChain([this, 'access', _26 => _26._apiConn, 'optionalAccess', _27 => _27.setFetch, 'call', _28 => _28(fetch2)]);
4525
- _optionalChain([this, 'access', _29 => _29._appConn, 'optionalAccess', _30 => _30.setFetch, 'call', _31 => _31(fetch2)]);
4673
+ _optionalChain([this, 'access', _22 => _22._apiConn, 'optionalAccess', _23 => _23.setFetch, 'call', _24 => _24(fetch2)]);
4674
+ _optionalChain([this, 'access', _25 => _25._appConn, 'optionalAccess', _26 => _26.setFetch, 'call', _27 => _27(fetch2)]);
4526
4675
  }
4527
4676
  setMaskingFunction(maskingFunction) {
4528
4677
  this.bgLogger().setMaskingFunction(maskingFunction);
@@ -4634,7 +4783,7 @@ function useTestBackgroundLogger() {
4634
4783
  return logger;
4635
4784
  }
4636
4785
  function clearTestBackgroundLogger() {
4637
- _optionalChain([_internalGetGlobalState, 'call', _32 => _32(), 'optionalAccess', _33 => _33.setOverrideBgLogger, 'call', _34 => _34(null)]);
4786
+ _optionalChain([_internalGetGlobalState, 'call', _28 => _28(), 'optionalAccess', _29 => _29.setOverrideBgLogger, 'call', _30 => _30(null)]);
4638
4787
  }
4639
4788
  function initTestExperiment(experimentName, projectName) {
4640
4789
  setInitialTestState();
@@ -4661,8 +4810,8 @@ function _internalSetInitialState() {
4661
4810
  }
4662
4811
  var _internalGetGlobalState = () => _globalState;
4663
4812
  function registerOtelFlush(callback) {
4664
- _optionalChain([_globalState, 'optionalAccess', _35 => _35.registerOtelFlush, 'call', _36 => _36(callback)]);
4665
- _optionalChain([_globalState, 'optionalAccess', _37 => _37.spanCache, 'optionalAccess', _38 => _38.disable, 'call', _39 => _39()]);
4813
+ _optionalChain([_globalState, 'optionalAccess', _31 => _31.registerOtelFlush, 'call', _32 => _32(callback)]);
4814
+ _optionalChain([_globalState, 'optionalAccess', _33 => _33.spanCache, 'optionalAccess', _34 => _34.disable, 'call', _35 => _35()]);
4666
4815
  }
4667
4816
  var FailedHTTPResponse = class extends Error {
4668
4817
 
@@ -5352,8 +5501,8 @@ function _getOrgName(orgName) {
5352
5501
  return orgName || isomorph_default.getEnv("BRAINTRUST_ORG_NAME") || void 0;
5353
5502
  }
5354
5503
  function _getLinkBaseUrl(state, linkArgs) {
5355
- const appUrl = _getAppUrl(state.appUrl || _optionalChain([linkArgs, 'optionalAccess', _40 => _40.app_url]));
5356
- const orgName = _getOrgName(state.orgName || _optionalChain([linkArgs, 'optionalAccess', _41 => _41.org_name]));
5504
+ const appUrl = _getAppUrl(state.appUrl || _optionalChain([linkArgs, 'optionalAccess', _36 => _36.app_url]));
5505
+ const orgName = _getOrgName(state.orgName || _optionalChain([linkArgs, 'optionalAccess', _37 => _37.org_name]));
5357
5506
  if (!orgName) {
5358
5507
  return null;
5359
5508
  }
@@ -5363,9 +5512,9 @@ async function permalink(slug, opts) {
5363
5512
  if (slug === "") {
5364
5513
  return NOOP_SPAN_PERMALINK;
5365
5514
  }
5366
- const state = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _42 => _42.state]), () => ( _globalState));
5515
+ const state = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _38 => _38.state]), () => ( _globalState));
5367
5516
  const getOrgName = async () => {
5368
- if (_optionalChain([opts, 'optionalAccess', _43 => _43.orgName])) {
5517
+ if (_optionalChain([opts, 'optionalAccess', _39 => _39.orgName])) {
5369
5518
  return opts.orgName;
5370
5519
  }
5371
5520
  await state.login({});
@@ -5375,7 +5524,7 @@ async function permalink(slug, opts) {
5375
5524
  return state.orgName;
5376
5525
  };
5377
5526
  const getAppUrl = async () => {
5378
- if (_optionalChain([opts, 'optionalAccess', _44 => _44.appUrl])) {
5527
+ if (_optionalChain([opts, 'optionalAccess', _40 => _40.appUrl])) {
5379
5528
  return opts.appUrl;
5380
5529
  }
5381
5530
  await state.login({});
@@ -5510,7 +5659,7 @@ var Logger = (_class7 = class {
5510
5659
  * @returns The `id` of the logged event.
5511
5660
  */
5512
5661
  log(event, options) {
5513
- if (this.calledStartSpan && !_optionalChain([options, 'optionalAccess', _45 => _45.allowConcurrentWithSpans])) {
5662
+ if (this.calledStartSpan && !_optionalChain([options, 'optionalAccess', _41 => _41.allowConcurrentWithSpans])) {
5514
5663
  throw new Error(
5515
5664
  "Cannot run toplevel `log` method while using spans. To log to the span, call `logger.traced` and then log with `span.log`"
5516
5665
  );
@@ -5578,12 +5727,12 @@ var Logger = (_class7 = class {
5578
5727
  state: this.state,
5579
5728
  ...startSpanParentArgs({
5580
5729
  state: this.state,
5581
- parent: _optionalChain([args, 'optionalAccess', _46 => _46.parent]),
5730
+ parent: _optionalChain([args, 'optionalAccess', _42 => _42.parent]),
5582
5731
  parentObjectType: this.parentObjectType(),
5583
5732
  parentObjectId: this.lazyId,
5584
5733
  parentComputeObjectMetadataArgs: this.computeMetadataArgs,
5585
- parentSpanIds: _optionalChain([args, 'optionalAccess', _47 => _47.parentSpanIds]),
5586
- propagatedEvent: _optionalChain([args, 'optionalAccess', _48 => _48.propagatedEvent])
5734
+ parentSpanIds: _optionalChain([args, 'optionalAccess', _43 => _43.parentSpanIds]),
5735
+ propagatedEvent: _optionalChain([args, 'optionalAccess', _44 => _44.propagatedEvent])
5587
5736
  }),
5588
5737
  defaultRootType: "task" /* TASK */
5589
5738
  });
@@ -5659,8 +5808,100 @@ function castLogger(logger, asyncFlush) {
5659
5808
  }
5660
5809
  return logger;
5661
5810
  }
5811
+ var logs3OverflowUploadSchema = _v3.z.object({
5812
+ method: _v3.z.enum(["PUT", "POST"]),
5813
+ signedUrl: _v3.z.string().url(),
5814
+ headers: _v3.z.record(_v3.z.string()).optional(),
5815
+ fields: _v3.z.record(_v3.z.string()).optional(),
5816
+ key: _v3.z.string().min(1)
5817
+ });
5662
5818
  function constructLogs3Data(items) {
5663
- return `{"rows": ${constructJsonArray(items)}, "api_version": 2}`;
5819
+ return `{"rows": ${constructJsonArray(items.map((i) => i.str))}, "api_version": 2}`;
5820
+ }
5821
+ function constructLogs3OverflowRequest(key) {
5822
+ return {
5823
+ rows: {
5824
+ type: LOGS3_OVERFLOW_REFERENCE_TYPE,
5825
+ key
5826
+ },
5827
+ api_version: 2
5828
+ };
5829
+ }
5830
+ function pickLogs3OverflowObjectIds(row) {
5831
+ const objectIds = {};
5832
+ for (const key of OBJECT_ID_KEYS) {
5833
+ if (key in row) {
5834
+ objectIds[key] = row[key];
5835
+ }
5836
+ }
5837
+ return objectIds;
5838
+ }
5839
+ async function uploadLogs3OverflowPayload(upload, payload, fetchFn = fetch) {
5840
+ if (upload.method === "POST") {
5841
+ if (!upload.fields) {
5842
+ throw new Error("Missing logs3 overflow upload fields");
5843
+ }
5844
+ if (typeof FormData === "undefined" || typeof Blob === "undefined") {
5845
+ throw new Error("FormData is not available for logs3 overflow upload");
5846
+ }
5847
+ const form = new FormData();
5848
+ for (const [key, value] of Object.entries(upload.fields)) {
5849
+ form.append(key, value);
5850
+ }
5851
+ const contentType = _nullishCoalesce(upload.fields["Content-Type"], () => ( "application/json"));
5852
+ form.append("file", new Blob([payload], { type: contentType }));
5853
+ const headers2 = {};
5854
+ for (const [key, value] of Object.entries(_nullishCoalesce(upload.headers, () => ( {})))) {
5855
+ if (key.toLowerCase() !== "content-type") {
5856
+ headers2[key] = value;
5857
+ }
5858
+ }
5859
+ const response2 = await fetchFn(upload.signedUrl, {
5860
+ method: "POST",
5861
+ headers: headers2,
5862
+ body: form
5863
+ });
5864
+ if (!response2.ok) {
5865
+ const responseText = await response2.text().catch(() => "");
5866
+ throw new Error(
5867
+ `Failed to upload logs3 overflow payload: ${response2.status} ${responseText}`
5868
+ );
5869
+ }
5870
+ return;
5871
+ }
5872
+ const headers = { ..._nullishCoalesce(upload.headers, () => ( {})) };
5873
+ addAzureBlobHeaders(headers, upload.signedUrl);
5874
+ const response = await fetchFn(upload.signedUrl, {
5875
+ method: "PUT",
5876
+ headers,
5877
+ body: payload
5878
+ });
5879
+ if (!response.ok) {
5880
+ const responseText = await response.text().catch(() => "");
5881
+ throw new Error(
5882
+ `Failed to upload logs3 overflow payload: ${response.status} ${responseText}`
5883
+ );
5884
+ }
5885
+ }
5886
+ function stringifyWithOverflowMeta(item) {
5887
+ const str = JSON.stringify(item);
5888
+ const record = item;
5889
+ return {
5890
+ str,
5891
+ overflowMeta: {
5892
+ object_ids: pickLogs3OverflowObjectIds(record),
5893
+ is_delete: record[OBJECT_DELETE_FIELD] === true,
5894
+ input_row: {
5895
+ byte_size: utf8ByteLength(str)
5896
+ }
5897
+ }
5898
+ };
5899
+ }
5900
+ function utf8ByteLength(value) {
5901
+ if (typeof TextEncoder !== "undefined") {
5902
+ return new TextEncoder().encode(value).length;
5903
+ }
5904
+ return value.length;
5664
5905
  }
5665
5906
  function now() {
5666
5907
  return (/* @__PURE__ */ new Date()).getTime();
@@ -5686,10 +5927,9 @@ var TestBackgroundLogger = (_class8 = class {constructor() { _class8.prototype._
5686
5927
  events.push(await event.get());
5687
5928
  }
5688
5929
  }
5689
- const batch = mergeRowBatch(events);
5690
- let flatBatch = batch.flat();
5930
+ let batch = mergeRowBatch(events);
5691
5931
  if (this.maskingFunction) {
5692
- flatBatch = flatBatch.map((item) => {
5932
+ batch = batch.map((item) => {
5693
5933
  const maskedItem = { ...item };
5694
5934
  for (const field of REDACTION_FIELDS) {
5695
5935
  if (item[field] !== void 0) {
@@ -5714,7 +5954,7 @@ var TestBackgroundLogger = (_class8 = class {constructor() { _class8.prototype._
5714
5954
  return maskedItem;
5715
5955
  });
5716
5956
  }
5717
- return flatBatch;
5957
+ return batch;
5718
5958
  }
5719
5959
  }, _class8);
5720
5960
  var BACKGROUND_LOGGER_BASE_SLEEP_TIME_S = 1;
@@ -5727,21 +5967,21 @@ var HTTPBackgroundLogger = (_class9 = class _HTTPBackgroundLogger {
5727
5967
 
5728
5968
  __init39() {this.maskingFunction = null}
5729
5969
  __init40() {this.syncFlush = false}
5730
- // 6 MB for the AWS lambda gateway (from our own testing).
5731
- __init41() {this.maxRequestSize = 6 * 1024 * 1024}
5732
- __init42() {this.defaultBatchSize = 100}
5733
- __init43() {this.numTries = 3}
5734
- __init44() {this.queueDropExceedingMaxsize = DEFAULT_QUEUE_SIZE}
5735
- __init45() {this.queueDropLoggingPeriod = 60}
5736
- __init46() {this.failedPublishPayloadsDir = void 0}
5737
- __init47() {this.allPublishPayloadsDir = void 0}
5738
- __init48() {this.flushChunkSize = 25}
5739
- __init49() {this._disabled = false}
5740
- __init50() {this.queueDropLoggingState = {
5970
+ __init41() {this.maxRequestSizeOverride = null}
5971
+ __init42() {this._maxRequestSizePromise = null}
5972
+ __init43() {this.defaultBatchSize = 100}
5973
+ __init44() {this.numTries = 3}
5974
+ __init45() {this.queueDropExceedingMaxsize = DEFAULT_QUEUE_SIZE}
5975
+ __init46() {this.queueDropLoggingPeriod = 60}
5976
+ __init47() {this.failedPublishPayloadsDir = void 0}
5977
+ __init48() {this.allPublishPayloadsDir = void 0}
5978
+ __init49() {this.flushChunkSize = 25}
5979
+ __init50() {this._disabled = false}
5980
+ __init51() {this.queueDropLoggingState = {
5741
5981
  numDropped: 0,
5742
5982
  lastLoggedTimestamp: 0
5743
5983
  }}
5744
- constructor(apiConn, opts) {;_class9.prototype.__init36.call(this);_class9.prototype.__init37.call(this);_class9.prototype.__init38.call(this);_class9.prototype.__init39.call(this);_class9.prototype.__init40.call(this);_class9.prototype.__init41.call(this);_class9.prototype.__init42.call(this);_class9.prototype.__init43.call(this);_class9.prototype.__init44.call(this);_class9.prototype.__init45.call(this);_class9.prototype.__init46.call(this);_class9.prototype.__init47.call(this);_class9.prototype.__init48.call(this);_class9.prototype.__init49.call(this);_class9.prototype.__init50.call(this);
5984
+ constructor(apiConn, opts) {;_class9.prototype.__init36.call(this);_class9.prototype.__init37.call(this);_class9.prototype.__init38.call(this);_class9.prototype.__init39.call(this);_class9.prototype.__init40.call(this);_class9.prototype.__init41.call(this);_class9.prototype.__init42.call(this);_class9.prototype.__init43.call(this);_class9.prototype.__init44.call(this);_class9.prototype.__init45.call(this);_class9.prototype.__init46.call(this);_class9.prototype.__init47.call(this);_class9.prototype.__init48.call(this);_class9.prototype.__init49.call(this);_class9.prototype.__init50.call(this);_class9.prototype.__init51.call(this);
5745
5985
  opts = _nullishCoalesce(opts, () => ( {}));
5746
5986
  this.apiConn = apiConn;
5747
5987
  const syncFlushEnv = Number(isomorph_default.getEnv("BRAINTRUST_SYNC_FLUSH"));
@@ -5756,7 +5996,7 @@ var HTTPBackgroundLogger = (_class9 = class _HTTPBackgroundLogger {
5756
5996
  }
5757
5997
  const maxRequestSizeEnv = Number(isomorph_default.getEnv("BRAINTRUST_MAX_REQUEST_SIZE"));
5758
5998
  if (!isNaN(maxRequestSizeEnv)) {
5759
- this.maxRequestSize = maxRequestSizeEnv;
5999
+ this.maxRequestSizeOverride = maxRequestSizeEnv;
5760
6000
  }
5761
6001
  const numTriesEnv = Number(isomorph_default.getEnv("BRAINTRUST_NUM_RETRIES"));
5762
6002
  if (!isNaN(numTriesEnv)) {
@@ -5818,6 +6058,30 @@ var HTTPBackgroundLogger = (_class9 = class _HTTPBackgroundLogger {
5818
6058
  }
5819
6059
  }
5820
6060
  }
6061
+ getMaxRequestSize() {
6062
+ if (!this._maxRequestSizePromise) {
6063
+ this._maxRequestSizePromise = (async () => {
6064
+ let serverLimit = null;
6065
+ try {
6066
+ const conn = await this.apiConn.get();
6067
+ const versionInfo = await conn.get_json("version");
6068
+ serverLimit = _nullishCoalesce(_v3.z.object({ logs3_payload_max_bytes: _v3.z.number().nullish() }).parse(versionInfo).logs3_payload_max_bytes, () => ( null));
6069
+ } catch (e) {
6070
+ console.warn("Failed to fetch version info for payload limit:", e);
6071
+ }
6072
+ const validServerLimit = serverLimit !== null && serverLimit > 0 ? serverLimit : null;
6073
+ const canUseOverflow = validServerLimit !== null;
6074
+ let maxRequestSize = DEFAULT_MAX_REQUEST_SIZE;
6075
+ if (this.maxRequestSizeOverride !== null) {
6076
+ maxRequestSize = validServerLimit !== null ? Math.min(this.maxRequestSizeOverride, validServerLimit) : this.maxRequestSizeOverride;
6077
+ } else if (validServerLimit !== null) {
6078
+ maxRequestSize = validServerLimit;
6079
+ }
6080
+ return { maxRequestSize, canUseOverflow };
6081
+ })();
6082
+ }
6083
+ return this._maxRequestSizePromise;
6084
+ }
5821
6085
  async flush() {
5822
6086
  if (this.syncFlush) {
5823
6087
  this.triggerActiveFlush();
@@ -5836,7 +6100,7 @@ var HTTPBackgroundLogger = (_class9 = class _HTTPBackgroundLogger {
5836
6100
  this.queue.clear();
5837
6101
  return;
5838
6102
  }
5839
- const batchSize = _nullishCoalesce(_optionalChain([args, 'optionalAccess', _49 => _49.batchSize]), () => ( this.defaultBatchSize));
6103
+ const batchSize = _nullishCoalesce(_optionalChain([args, 'optionalAccess', _45 => _45.batchSize]), () => ( this.defaultBatchSize));
5840
6104
  const wrappedItems = this.queue.drain();
5841
6105
  if (wrappedItems.length === 0) {
5842
6106
  return;
@@ -5861,33 +6125,33 @@ var HTTPBackgroundLogger = (_class9 = class _HTTPBackgroundLogger {
5861
6125
  if (allItems.length === 0) {
5862
6126
  return;
5863
6127
  }
5864
- const allItemsStr = allItems.map(
5865
- (bucket) => bucket.map((item) => JSON.stringify(item))
6128
+ const allItemsWithMeta = allItems.map(
6129
+ (item) => stringifyWithOverflowMeta(item)
5866
6130
  );
5867
- const batchSets = batchItems({
5868
- items: allItemsStr,
6131
+ const maxRequestSizeResult = await this.getMaxRequestSize();
6132
+ const batches = batchItems({
6133
+ items: allItemsWithMeta,
5869
6134
  batchMaxNumItems: batchSize,
5870
- batchMaxNumBytes: this.maxRequestSize / 2
6135
+ batchMaxNumBytes: maxRequestSizeResult.maxRequestSize / 2,
6136
+ getByteSize: (item) => item.str.length
5871
6137
  });
5872
- for (const batchSet of batchSets) {
5873
- const postPromises = batchSet.map(
5874
- (batch) => (async () => {
5875
- try {
5876
- await this.submitLogsRequest(batch);
5877
- return { type: "success" };
5878
- } catch (e) {
5879
- return { type: "error", value: e };
5880
- }
5881
- })()
6138
+ const postPromises = batches.map(
6139
+ (batch) => (async () => {
6140
+ try {
6141
+ await this.submitLogsRequest(batch, maxRequestSizeResult);
6142
+ return { type: "success" };
6143
+ } catch (e) {
6144
+ return { type: "error", value: e };
6145
+ }
6146
+ })()
6147
+ );
6148
+ const results = await Promise.all(postPromises);
6149
+ const failingResultErrors = results.map((r) => r.type === "success" ? void 0 : r.value).filter((r) => r !== void 0);
6150
+ if (failingResultErrors.length) {
6151
+ throw new AggregateError(
6152
+ failingResultErrors,
6153
+ `Encountered the following errors while logging:`
5882
6154
  );
5883
- const results = await Promise.all(postPromises);
5884
- const failingResultErrors = results.map((r) => r.type === "success" ? void 0 : r.value).filter((r) => r !== void 0);
5885
- if (failingResultErrors.length) {
5886
- throw new AggregateError(
5887
- failingResultErrors,
5888
- `Encountered the following errors while logging:`
5889
- );
5890
- }
5891
6155
  }
5892
6156
  const attachmentErrors = [];
5893
6157
  for (const attachment of attachments) {
@@ -5917,32 +6181,30 @@ var HTTPBackgroundLogger = (_class9 = class _HTTPBackgroundLogger {
5917
6181
  items.forEach((item) => extractAttachments(item, attachments));
5918
6182
  let mergedItems = mergeRowBatch(items);
5919
6183
  if (this.maskingFunction) {
5920
- mergedItems = mergedItems.map(
5921
- (batch) => batch.map((item) => {
5922
- const maskedItem = { ...item };
5923
- for (const field of REDACTION_FIELDS) {
5924
- if (item[field] !== void 0) {
5925
- const maskedValue = applyMaskingToField(
5926
- this.maskingFunction,
5927
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
5928
- item[field],
5929
- field
5930
- );
5931
- if (maskedValue instanceof MaskingError) {
5932
- delete maskedItem[field];
5933
- if (maskedItem.error) {
5934
- maskedItem.error = `${maskedItem.error}; ${maskedValue.errorMsg}`;
5935
- } else {
5936
- maskedItem.error = maskedValue.errorMsg;
5937
- }
6184
+ mergedItems = mergedItems.map((item) => {
6185
+ const maskedItem = { ...item };
6186
+ for (const field of REDACTION_FIELDS) {
6187
+ if (item[field] !== void 0) {
6188
+ const maskedValue = applyMaskingToField(
6189
+ this.maskingFunction,
6190
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6191
+ item[field],
6192
+ field
6193
+ );
6194
+ if (maskedValue instanceof MaskingError) {
6195
+ delete maskedItem[field];
6196
+ if (maskedItem.error) {
6197
+ maskedItem.error = `${maskedItem.error}; ${maskedValue.errorMsg}`;
5938
6198
  } else {
5939
- maskedItem[field] = maskedValue;
6199
+ maskedItem.error = maskedValue.errorMsg;
5940
6200
  }
6201
+ } else {
6202
+ maskedItem[field] = maskedValue;
5941
6203
  }
5942
6204
  }
5943
- return maskedItem;
5944
- })
5945
- );
6205
+ }
6206
+ return maskedItem;
6207
+ });
5946
6208
  }
5947
6209
  return [mergedItems, attachments];
5948
6210
  } catch (e) {
@@ -5969,20 +6231,73 @@ var HTTPBackgroundLogger = (_class9 = class _HTTPBackgroundLogger {
5969
6231
  }
5970
6232
  throw new Error("Impossible");
5971
6233
  }
5972
- async submitLogsRequest(items) {
6234
+ async requestLogs3OverflowUpload(conn, args) {
6235
+ let response;
6236
+ try {
6237
+ response = await conn.post_json("logs3/overflow", {
6238
+ content_type: "application/json",
6239
+ size_bytes: args.sizeBytes,
6240
+ rows: args.rows
6241
+ });
6242
+ } catch (error) {
6243
+ const errorStr = JSON.stringify(error);
6244
+ throw new Error(
6245
+ `Failed to request logs3 overflow upload URL: ${errorStr}`
6246
+ );
6247
+ }
6248
+ try {
6249
+ return logs3OverflowUploadSchema.parse(response);
6250
+ } catch (error) {
6251
+ if (error instanceof _v3.ZodError) {
6252
+ const errorStr = JSON.stringify(error.flatten());
6253
+ throw new Error(`Invalid response from API server: ${errorStr}`);
6254
+ }
6255
+ throw error;
6256
+ }
6257
+ }
6258
+ async _uploadLogs3OverflowPayload(conn, upload, payload) {
6259
+ await uploadLogs3OverflowPayload(upload, payload, conn.fetch.bind(conn));
6260
+ }
6261
+ async submitLogsRequest(items, {
6262
+ maxRequestSize,
6263
+ canUseOverflow
6264
+ }) {
5973
6265
  const conn = await this.apiConn.get();
5974
6266
  const dataStr = constructLogs3Data(items);
6267
+ const payloadBytes = utf8ByteLength(dataStr);
6268
+ const useOverflow = canUseOverflow && payloadBytes > maxRequestSize;
5975
6269
  if (this.allPublishPayloadsDir) {
5976
6270
  await _HTTPBackgroundLogger.writePayloadToDir({
5977
6271
  payloadDir: this.allPublishPayloadsDir,
5978
6272
  payload: dataStr
5979
6273
  });
5980
6274
  }
6275
+ let overflowUpload = null;
6276
+ const overflowRows = useOverflow ? items.map((item) => item.overflowMeta) : null;
5981
6277
  for (let i = 0; i < this.numTries; i++) {
5982
6278
  const startTime = now();
5983
6279
  let error = void 0;
5984
6280
  try {
5985
- await conn.post_json("logs3", dataStr);
6281
+ if (overflowRows) {
6282
+ if (!overflowUpload) {
6283
+ const currentUpload = await this.requestLogs3OverflowUpload(conn, {
6284
+ rows: overflowRows,
6285
+ sizeBytes: payloadBytes
6286
+ });
6287
+ await this._uploadLogs3OverflowPayload(
6288
+ conn,
6289
+ currentUpload,
6290
+ dataStr
6291
+ );
6292
+ overflowUpload = currentUpload;
6293
+ }
6294
+ await conn.post_json(
6295
+ "logs3",
6296
+ constructLogs3OverflowRequest(overflowUpload.key)
6297
+ );
6298
+ } else {
6299
+ await conn.post_json("logs3", dataStr);
6300
+ }
5986
6301
  } catch (e) {
5987
6302
  error = e;
5988
6303
  }
@@ -5998,7 +6313,7 @@ var HTTPBackgroundLogger = (_class9 = class _HTTPBackgroundLogger {
5998
6313
  return `${error}`;
5999
6314
  }
6000
6315
  })();
6001
- const errMsg = `log request failed. Elapsed time: ${(now() - startTime) / 1e3} seconds. Payload size: ${dataStr.length}.${retryingText}
6316
+ const errMsg = `log request failed. Elapsed time: ${(now() - startTime) / 1e3} seconds. Payload size: ${payloadBytes}.${retryingText}
6002
6317
  Error: ${errorText}`;
6003
6318
  if (!isRetrying && this.failedPublishPayloadsDir) {
6004
6319
  await _HTTPBackgroundLogger.writePayloadToDir({
@@ -6052,7 +6367,7 @@ Error: ${errorText}`;
6052
6367
  try {
6053
6368
  const [allItems, allAttachments] = await this.unwrapLazyValues(wrappedItems);
6054
6369
  const dataStr = constructLogs3Data(
6055
- allItems.map((x) => JSON.stringify(x))
6370
+ allItems.map((x) => stringifyWithOverflowMeta(x))
6056
6371
  );
6057
6372
  const attachmentStr = JSON.stringify(
6058
6373
  allAttachments.map((a) => a.debugInfo())
@@ -6101,10 +6416,10 @@ Error: ${errorText}`;
6101
6416
  } catch (err) {
6102
6417
  if (err instanceof AggregateError) {
6103
6418
  for (const e of err.errors) {
6104
- _optionalChain([this, 'access', _50 => _50.onFlushError, 'optionalCall', _51 => _51(e)]);
6419
+ _optionalChain([this, 'access', _46 => _46.onFlushError, 'optionalCall', _47 => _47(e)]);
6105
6420
  }
6106
6421
  } else {
6107
- _optionalChain([this, 'access', _52 => _52.onFlushError, 'optionalCall', _53 => _53(err)]);
6422
+ _optionalChain([this, 'access', _48 => _48.onFlushError, 'optionalCall', _49 => _49(err)]);
6108
6423
  }
6109
6424
  this.activeFlushError = err;
6110
6425
  } finally {
@@ -6619,12 +6934,133 @@ async function loadPrompt({
6619
6934
  }
6620
6935
  return prompt;
6621
6936
  }
6622
- function setMaskingFunction(maskingFunction) {
6623
- _globalState.setMaskingFunction(maskingFunction);
6624
- }
6625
- async function login(options = {}) {
6626
- const { forceLogin = false } = options || {};
6627
- if (_globalState.loggedIn && !forceLogin) {
6937
+ async function loadParameters({
6938
+ projectName,
6939
+ projectId,
6940
+ slug,
6941
+ version,
6942
+ environment,
6943
+ id,
6944
+ appUrl,
6945
+ apiKey,
6946
+ orgName,
6947
+ fetch: fetch2,
6948
+ forceLogin,
6949
+ state: stateArg
6950
+ }) {
6951
+ if (version && environment) {
6952
+ throw new Error(
6953
+ "Cannot specify both 'version' and 'environment' parameters. Please use only one (remove the other)."
6954
+ );
6955
+ }
6956
+ if (id) {
6957
+ } else if (isEmpty2(projectName) && isEmpty2(projectId)) {
6958
+ throw new Error("Must specify either projectName or projectId");
6959
+ } else if (isEmpty2(slug)) {
6960
+ throw new Error("Must specify slug");
6961
+ }
6962
+ const state = _nullishCoalesce(stateArg, () => ( _globalState));
6963
+ let response;
6964
+ try {
6965
+ await state.login({
6966
+ orgName,
6967
+ apiKey,
6968
+ appUrl,
6969
+ fetch: fetch2,
6970
+ forceLogin
6971
+ });
6972
+ if (id) {
6973
+ response = await state.apiConn().get_json(`v1/function/${id}`, {
6974
+ ...version && { version },
6975
+ ...environment && { environment }
6976
+ });
6977
+ if (response) {
6978
+ response = { objects: [response] };
6979
+ }
6980
+ } else {
6981
+ response = await state.apiConn().get_json("v1/function", {
6982
+ project_name: projectName,
6983
+ project_id: projectId,
6984
+ slug,
6985
+ version,
6986
+ function_type: "parameters",
6987
+ ...environment && { environment }
6988
+ });
6989
+ }
6990
+ } catch (e) {
6991
+ if (environment || version) {
6992
+ throw new Error(`Parameters not found with specified parameters: ${e}`);
6993
+ }
6994
+ console.warn(
6995
+ "Failed to load parameters, attempting to fall back to cache:",
6996
+ e
6997
+ );
6998
+ let parameters2;
6999
+ if (id) {
7000
+ parameters2 = await state.parametersCache.get({ id });
7001
+ if (!parameters2) {
7002
+ throw new Error(
7003
+ `Parameters with id ${id} not found (not found on server or in local cache): ${e}`
7004
+ );
7005
+ }
7006
+ } else {
7007
+ parameters2 = await state.parametersCache.get({
7008
+ slug,
7009
+ projectId,
7010
+ projectName,
7011
+ version: _nullishCoalesce(version, () => ( "latest"))
7012
+ });
7013
+ if (!parameters2) {
7014
+ throw new Error(
7015
+ `Parameters ${slug} (version ${_nullishCoalesce(version, () => ( "latest"))}) not found in ${[
7016
+ _nullishCoalesce(projectName, () => ( projectId))
7017
+ ]} (not found on server or in local cache): ${e}`
7018
+ );
7019
+ }
7020
+ }
7021
+ return parameters2;
7022
+ }
7023
+ if (!("objects" in response) || response.objects.length === 0) {
7024
+ if (id) {
7025
+ throw new Error(`Parameters with id ${id} not found.`);
7026
+ } else {
7027
+ throw new Error(
7028
+ `Parameters ${slug} not found in ${[_nullishCoalesce(projectName, () => ( projectId))]}`
7029
+ );
7030
+ }
7031
+ } else if (response.objects.length > 1) {
7032
+ if (id) {
7033
+ throw new Error(
7034
+ `Multiple parameters found with id ${id}. This should never happen.`
7035
+ );
7036
+ } else {
7037
+ throw new Error(
7038
+ `Multiple parameters found with slug ${slug} in project ${_nullishCoalesce(projectName, () => ( projectId))}. This should never happen.`
7039
+ );
7040
+ }
7041
+ }
7042
+ const metadata = parametersRowSchema.parse(response["objects"][0]);
7043
+ const parameters = new RemoteEvalParameters(metadata);
7044
+ try {
7045
+ if (id) {
7046
+ await state.parametersCache.set({ id }, parameters);
7047
+ } else if (slug) {
7048
+ await state.parametersCache.set(
7049
+ { slug, projectId, projectName, version: _nullishCoalesce(version, () => ( "latest")) },
7050
+ parameters
7051
+ );
7052
+ }
7053
+ } catch (e) {
7054
+ console.warn("Failed to set parameters in cache:", e);
7055
+ }
7056
+ return parameters;
7057
+ }
7058
+ function setMaskingFunction(maskingFunction) {
7059
+ _globalState.setMaskingFunction(maskingFunction);
7060
+ }
7061
+ async function login(options = {}) {
7062
+ const { forceLogin = false } = options || {};
7063
+ if (_globalState.loggedIn && !forceLogin) {
6628
7064
  let checkUpdatedParam2 = function(varname, arg, orig) {
6629
7065
  if (!isEmpty2(arg) && !isEmpty2(orig) && arg !== orig) {
6630
7066
  throw new Error(
@@ -6735,24 +7171,24 @@ async function summarize(options = {}) {
6735
7171
  return await e.summarize(options);
6736
7172
  }
6737
7173
  function currentExperiment(options) {
6738
- const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _54 => _54.state]), () => ( _globalState));
7174
+ const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _50 => _50.state]), () => ( _globalState));
6739
7175
  return state.currentExperiment;
6740
7176
  }
6741
7177
  function currentLogger(options) {
6742
- const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _55 => _55.state]), () => ( _globalState));
6743
- return castLogger(state.currentLogger, _optionalChain([options, 'optionalAccess', _56 => _56.asyncFlush]));
7178
+ const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _51 => _51.state]), () => ( _globalState));
7179
+ return castLogger(state.currentLogger, _optionalChain([options, 'optionalAccess', _52 => _52.asyncFlush]));
6744
7180
  }
6745
7181
  function currentSpan(options) {
6746
- const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _57 => _57.state]), () => ( _globalState));
7182
+ const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _53 => _53.state]), () => ( _globalState));
6747
7183
  return _nullishCoalesce(state.contextManager.getCurrentSpan(), () => ( NOOP_SPAN));
6748
7184
  }
6749
7185
  function getSpanParentObject(options) {
6750
- const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _58 => _58.state]), () => ( _globalState));
7186
+ const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _54 => _54.state]), () => ( _globalState));
6751
7187
  const parentSpan = currentSpan({ state });
6752
7188
  if (!Object.is(parentSpan, NOOP_SPAN)) {
6753
7189
  return parentSpan;
6754
7190
  }
6755
- const parentStr = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _59 => _59.parent]), () => ( state.currentParent.getStore()));
7191
+ const parentStr = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _55 => _55.parent]), () => ( state.currentParent.getStore()));
6756
7192
  if (parentStr) return getSpanComponentsClass().fromStr(parentStr);
6757
7193
  const experiment = currentExperiment();
6758
7194
  if (experiment) {
@@ -6781,7 +7217,7 @@ function traced(callback, args) {
6781
7217
  const { span, isSyncFlushLogger } = startSpanAndIsLogger(args);
6782
7218
  const ret = runCatchFinally(
6783
7219
  () => {
6784
- if (_nullishCoalesce(_optionalChain([args, 'optionalAccess', _60 => _60.setCurrent]), () => ( true))) {
7220
+ if (_nullishCoalesce(_optionalChain([args, 'optionalAccess', _56 => _56.setCurrent]), () => ( true))) {
6785
7221
  return withCurrent(span, callback);
6786
7222
  } else {
6787
7223
  return callback(span);
@@ -6793,7 +7229,7 @@ function traced(callback, args) {
6793
7229
  },
6794
7230
  () => span.end()
6795
7231
  );
6796
- if (_optionalChain([args, 'optionalAccess', _61 => _61.asyncFlush]) === void 0 || _optionalChain([args, 'optionalAccess', _62 => _62.asyncFlush])) {
7232
+ if (_optionalChain([args, 'optionalAccess', _57 => _57.asyncFlush]) === void 0 || _optionalChain([args, 'optionalAccess', _58 => _58.asyncFlush])) {
6797
7233
  return ret;
6798
7234
  } else {
6799
7235
  return (async () => {
@@ -6917,14 +7353,14 @@ function wrapTraced(fn, args) {
6917
7353
  };
6918
7354
  const hasExplicitInput = args && args.event && "input" in args.event && args.event.input !== void 0;
6919
7355
  const hasExplicitOutput = args && args.event && args.event.output !== void 0;
6920
- const noTraceIO = _optionalChain([args, 'optionalAccess', _63 => _63.noTraceIO]) || hasExplicitInput || hasExplicitOutput;
7356
+ const noTraceIO = _optionalChain([args, 'optionalAccess', _59 => _59.noTraceIO]) || hasExplicitInput || hasExplicitOutput;
6921
7357
  if (isGeneratorFunction(fn)) {
6922
7358
  return wrapTracedSyncGenerator(fn, spanArgs, !!noTraceIO);
6923
7359
  }
6924
7360
  if (isAsyncGeneratorFunction(fn)) {
6925
7361
  return wrapTracedAsyncGenerator(fn, spanArgs, !!noTraceIO);
6926
7362
  }
6927
- if (_optionalChain([args, 'optionalAccess', _64 => _64.asyncFlush])) {
7363
+ if (_optionalChain([args, 'optionalAccess', _60 => _60.asyncFlush])) {
6928
7364
  return ((...fnArgs) => traced((span) => {
6929
7365
  if (!hasExplicitInput) {
6930
7366
  span.log({ input: fnArgs });
@@ -6962,17 +7398,17 @@ function startSpan(args) {
6962
7398
  return startSpanAndIsLogger(args).span;
6963
7399
  }
6964
7400
  async function flush(options) {
6965
- const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _65 => _65.state]), () => ( _globalState));
7401
+ const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _61 => _61.state]), () => ( _globalState));
6966
7402
  return await state.bgLogger().flush();
6967
7403
  }
6968
7404
  function setFetch(fetch2) {
6969
7405
  _globalState.setFetch(fetch2);
6970
7406
  }
6971
7407
  function startSpanAndIsLogger(args) {
6972
- const state = _nullishCoalesce(_optionalChain([args, 'optionalAccess', _66 => _66.state]), () => ( _globalState));
7408
+ const state = _nullishCoalesce(_optionalChain([args, 'optionalAccess', _62 => _62.state]), () => ( _globalState));
6973
7409
  const parentObject = getSpanParentObject({
6974
- asyncFlush: _optionalChain([args, 'optionalAccess', _67 => _67.asyncFlush]),
6975
- parent: _optionalChain([args, 'optionalAccess', _68 => _68.parent]),
7410
+ asyncFlush: _optionalChain([args, 'optionalAccess', _63 => _63.asyncFlush]),
7411
+ parent: _optionalChain([args, 'optionalAccess', _64 => _64.parent]),
6976
7412
  state
6977
7413
  });
6978
7414
  if (parentObject instanceof SpanComponentsV3 || parentObject instanceof SpanComponentsV4) {
@@ -6989,14 +7425,14 @@ function startSpanAndIsLogger(args) {
6989
7425
  ),
6990
7426
  parentComputeObjectMetadataArgs: _nullishCoalesce(parentObject.data.compute_object_metadata_args, () => ( void 0)),
6991
7427
  parentSpanIds,
6992
- propagatedEvent: _nullishCoalesce(_optionalChain([args, 'optionalAccess', _69 => _69.propagatedEvent]), () => ( // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
7428
+ propagatedEvent: _nullishCoalesce(_optionalChain([args, 'optionalAccess', _65 => _65.propagatedEvent]), () => ( // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
6993
7429
  (_nullishCoalesce(parentObject.data.propagated_event, () => ( void 0)))))
6994
7430
  });
6995
7431
  return {
6996
7432
  span,
6997
7433
  isSyncFlushLogger: parentObject.data.object_type === 2 /* PROJECT_LOGS */ && // Since there's no parent logger here, we're free to choose the async flush
6998
7434
  // behavior, and therefore propagate along whatever we get from the arguments
6999
- _optionalChain([args, 'optionalAccess', _70 => _70.asyncFlush]) === false
7435
+ _optionalChain([args, 'optionalAccess', _66 => _66.asyncFlush]) === false
7000
7436
  };
7001
7437
  } else {
7002
7438
  const span = parentObject.startSpan(args);
@@ -7188,10 +7624,10 @@ function extractAttachments(event, attachments) {
7188
7624
  event[key] = value.reference;
7189
7625
  continue;
7190
7626
  }
7191
- if (_optionalChain([value, 'optionalAccess', _71 => _71.type]) === BRAINTRUST_ATTACHMENT && value.key && !value.uploader) {
7627
+ if (_optionalChain([value, 'optionalAccess', _67 => _67.type]) === BRAINTRUST_ATTACHMENT && value.key && !value.uploader) {
7192
7628
  continue;
7193
7629
  }
7194
- if (_optionalChain([value, 'optionalAccess', _72 => _72.reference, 'optionalAccess', _73 => _73.type]) === BRAINTRUST_ATTACHMENT && _optionalChain([value, 'optionalAccess', _74 => _74.uploader])) {
7630
+ if (_optionalChain([value, 'optionalAccess', _68 => _68.reference, 'optionalAccess', _69 => _69.type]) === BRAINTRUST_ATTACHMENT && _optionalChain([value, 'optionalAccess', _70 => _70.uploader])) {
7195
7631
  const attachment = new Attachment({
7196
7632
  data: value.dataDebugString,
7197
7633
  filename: value.reference.filename,
@@ -7258,13 +7694,13 @@ function validateAndSanitizeExperimentLogFullArgs(event, hasDataset) {
7258
7694
  var DEFAULT_FETCH_BATCH_SIZE = 1e3;
7259
7695
  var MAX_BTQL_ITERATIONS = 1e4;
7260
7696
  var ObjectFetcher = (_class10 = class {
7261
- constructor(objectType, pinnedVersion, mutateRecord, _internal_btql) {;_class10.prototype.__init51.call(this);
7697
+ constructor(objectType, pinnedVersion, mutateRecord, _internal_btql) {;_class10.prototype.__init52.call(this);
7262
7698
  this.objectType = objectType;
7263
7699
  this.pinnedVersion = pinnedVersion;
7264
7700
  this.mutateRecord = mutateRecord;
7265
7701
  this._internal_btql = _internal_btql;
7266
7702
  }
7267
- __init51() {this._fetchedData = void 0}
7703
+ __init52() {this._fetchedData = void 0}
7268
7704
  get id() {
7269
7705
  throw new Error("ObjectFetcher subclasses must have an 'id' attribute");
7270
7706
  }
@@ -7342,7 +7778,7 @@ var ObjectFetcher = (_class10 = class {
7342
7778
  }
7343
7779
  return;
7344
7780
  }
7345
- for await (const record of this.fetchRecordsFromApi(_optionalChain([options, 'optionalAccess', _75 => _75.batchSize]))) {
7781
+ for await (const record of this.fetchRecordsFromApi(_optionalChain([options, 'optionalAccess', _71 => _71.batchSize]))) {
7346
7782
  yield record;
7347
7783
  }
7348
7784
  }
@@ -7352,7 +7788,7 @@ var ObjectFetcher = (_class10 = class {
7352
7788
  async fetchedData(options) {
7353
7789
  if (this._fetchedData === void 0) {
7354
7790
  const data = [];
7355
- for await (const record of this.fetchRecordsFromApi(_optionalChain([options, 'optionalAccess', _76 => _76.batchSize]))) {
7791
+ for await (const record of this.fetchRecordsFromApi(_optionalChain([options, 'optionalAccess', _72 => _72.batchSize]))) {
7356
7792
  data.push(record);
7357
7793
  }
7358
7794
  this._fetchedData = data;
@@ -7385,9 +7821,9 @@ var Experiment2 = (_class11 = class extends ObjectFetcher {
7385
7821
 
7386
7822
 
7387
7823
  // For type identification.
7388
- __init52() {this.kind = "experiment"}
7824
+ __init53() {this.kind = "experiment"}
7389
7825
  constructor(state, lazyMetadata, dataset) {
7390
- super("experiment", void 0, (r) => enrichAttachments(r, state));_class11.prototype.__init52.call(this);;
7826
+ super("experiment", void 0, (r) => enrichAttachments(r, state));_class11.prototype.__init53.call(this);;
7391
7827
  this.lazyMetadata = lazyMetadata;
7392
7828
  this.dataset = dataset;
7393
7829
  this.lastStartTime = getCurrentUnixTimestamp();
@@ -7447,7 +7883,7 @@ var Experiment2 = (_class11 = class extends ObjectFetcher {
7447
7883
  * @returns The `id` of the logged event.
7448
7884
  */
7449
7885
  log(event, options) {
7450
- if (this.calledStartSpan && !_optionalChain([options, 'optionalAccess', _77 => _77.allowConcurrentWithSpans])) {
7886
+ if (this.calledStartSpan && !_optionalChain([options, 'optionalAccess', _73 => _73.allowConcurrentWithSpans])) {
7451
7887
  throw new Error(
7452
7888
  "Cannot run toplevel `log` method while using spans. To log to the span, call `experiment.traced` and then log with `span.log`"
7453
7889
  );
@@ -7500,12 +7936,12 @@ var Experiment2 = (_class11 = class extends ObjectFetcher {
7500
7936
  state: this.state,
7501
7937
  ...startSpanParentArgs({
7502
7938
  state: this.state,
7503
- parent: _optionalChain([args, 'optionalAccess', _78 => _78.parent]),
7939
+ parent: _optionalChain([args, 'optionalAccess', _74 => _74.parent]),
7504
7940
  parentObjectType: this.parentObjectType(),
7505
7941
  parentObjectId: this.lazyId,
7506
7942
  parentComputeObjectMetadataArgs: void 0,
7507
7943
  parentSpanIds: void 0,
7508
- propagatedEvent: _optionalChain([args, 'optionalAccess', _79 => _79.propagatedEvent])
7944
+ propagatedEvent: _optionalChain([args, 'optionalAccess', _75 => _75.propagatedEvent])
7509
7945
  }),
7510
7946
  defaultRootType: "eval" /* EVAL */
7511
7947
  });
@@ -7740,8 +8176,8 @@ var SpanImpl = (_class12 = class _SpanImpl {
7740
8176
 
7741
8177
 
7742
8178
 
7743
- __init53() {this.kind = "span"}
7744
- constructor(args) {;_class12.prototype.__init53.call(this);
8179
+ __init54() {this.kind = "span"}
8180
+ constructor(args) {;_class12.prototype.__init54.call(this);
7745
8181
  this._state = args.state;
7746
8182
  const spanAttributes = _nullishCoalesce(args.spanAttributes, () => ( {}));
7747
8183
  const rawEvent = _nullishCoalesce(args.event, () => ( {}));
@@ -7843,8 +8279,8 @@ var SpanImpl = (_class12 = class _SpanImpl {
7843
8279
  ...serializableInternalData,
7844
8280
  [IS_MERGE_FIELD]: this.isMerge
7845
8281
  });
7846
- if (_optionalChain([partialRecord, 'access', _80 => _80.metrics, 'optionalAccess', _81 => _81.end])) {
7847
- this.loggedEndTime = _optionalChain([partialRecord, 'access', _82 => _82.metrics, 'optionalAccess', _83 => _83.end]);
8282
+ if (_optionalChain([partialRecord, 'access', _76 => _76.metrics, 'optionalAccess', _77 => _77.end])) {
8283
+ this.loggedEndTime = _optionalChain([partialRecord, 'access', _78 => _78.metrics, 'optionalAccess', _79 => _79.end]);
7848
8284
  }
7849
8285
  if (this.parentObjectType === 1 /* EXPERIMENT */) {
7850
8286
  const cachedSpan = {
@@ -7903,18 +8339,18 @@ var SpanImpl = (_class12 = class _SpanImpl {
7903
8339
  );
7904
8340
  }
7905
8341
  startSpan(args) {
7906
- const parentSpanIds = _optionalChain([args, 'optionalAccess', _84 => _84.parent]) ? void 0 : { spanId: this._spanId, rootSpanId: this._rootSpanId };
8342
+ const parentSpanIds = _optionalChain([args, 'optionalAccess', _80 => _80.parent]) ? void 0 : { spanId: this._spanId, rootSpanId: this._rootSpanId };
7907
8343
  return new _SpanImpl({
7908
8344
  state: this._state,
7909
8345
  ...args,
7910
8346
  ...startSpanParentArgs({
7911
8347
  state: this._state,
7912
- parent: _optionalChain([args, 'optionalAccess', _85 => _85.parent]),
8348
+ parent: _optionalChain([args, 'optionalAccess', _81 => _81.parent]),
7913
8349
  parentObjectType: this.parentObjectType,
7914
8350
  parentObjectId: this.parentObjectId,
7915
8351
  parentComputeObjectMetadataArgs: this.parentComputeObjectMetadataArgs,
7916
8352
  parentSpanIds,
7917
- propagatedEvent: _nullishCoalesce(_optionalChain([args, 'optionalAccess', _86 => _86.propagatedEvent]), () => ( this.propagatedEvent))
8353
+ propagatedEvent: _nullishCoalesce(_optionalChain([args, 'optionalAccess', _82 => _82.propagatedEvent]), () => ( this.propagatedEvent))
7918
8354
  })
7919
8355
  });
7920
8356
  }
@@ -7928,12 +8364,12 @@ var SpanImpl = (_class12 = class _SpanImpl {
7928
8364
  ...args,
7929
8365
  ...startSpanParentArgs({
7930
8366
  state: this._state,
7931
- parent: _optionalChain([args, 'optionalAccess', _87 => _87.parent]),
8367
+ parent: _optionalChain([args, 'optionalAccess', _83 => _83.parent]),
7932
8368
  parentObjectType: this.parentObjectType,
7933
8369
  parentObjectId: this.parentObjectId,
7934
8370
  parentComputeObjectMetadataArgs: this.parentComputeObjectMetadataArgs,
7935
8371
  parentSpanIds,
7936
- propagatedEvent: _nullishCoalesce(_optionalChain([args, 'optionalAccess', _88 => _88.propagatedEvent]), () => ( this.propagatedEvent))
8372
+ propagatedEvent: _nullishCoalesce(_optionalChain([args, 'optionalAccess', _84 => _84.propagatedEvent]), () => ( this.propagatedEvent))
7937
8373
  }),
7938
8374
  spanId
7939
8375
  });
@@ -7942,7 +8378,7 @@ var SpanImpl = (_class12 = class _SpanImpl {
7942
8378
  let endTime;
7943
8379
  let internalData = {};
7944
8380
  if (!this.loggedEndTime) {
7945
- endTime = _nullishCoalesce(_optionalChain([args, 'optionalAccess', _89 => _89.endTime]), () => ( getCurrentUnixTimestamp()));
8381
+ endTime = _nullishCoalesce(_optionalChain([args, 'optionalAccess', _85 => _85.endTime]), () => ( getCurrentUnixTimestamp()));
7946
8382
  internalData = { metrics: { end: endTime } };
7947
8383
  } else {
7948
8384
  endTime = this.loggedEndTime;
@@ -7993,8 +8429,8 @@ var SpanImpl = (_class12 = class _SpanImpl {
7993
8429
  const args = this.parentComputeObjectMetadataArgs;
7994
8430
  switch (this.parentObjectType) {
7995
8431
  case 2 /* PROJECT_LOGS */: {
7996
- const projectID = _optionalChain([args, 'optionalAccess', _90 => _90.project_id]) || this.parentObjectId.getSync().value;
7997
- const projectName = _optionalChain([args, 'optionalAccess', _91 => _91.project_name]);
8432
+ const projectID = _optionalChain([args, 'optionalAccess', _86 => _86.project_id]) || this.parentObjectId.getSync().value;
8433
+ const projectName = _optionalChain([args, 'optionalAccess', _87 => _87.project_name]);
7998
8434
  if (projectID) {
7999
8435
  return `${baseUrl}/object?object_type=project_logs&object_id=${projectID}&id=${this._id}`;
8000
8436
  } else if (projectName) {
@@ -8004,7 +8440,7 @@ var SpanImpl = (_class12 = class _SpanImpl {
8004
8440
  }
8005
8441
  }
8006
8442
  case 1 /* EXPERIMENT */: {
8007
- const expID = _optionalChain([args, 'optionalAccess', _92 => _92.experiment_id]) || _optionalChain([this, 'access', _93 => _93.parentObjectId, 'optionalAccess', _94 => _94.getSync, 'call', _95 => _95(), 'optionalAccess', _96 => _96.value]);
8443
+ const expID = _optionalChain([args, 'optionalAccess', _88 => _88.experiment_id]) || _optionalChain([this, 'access', _89 => _89.parentObjectId, 'optionalAccess', _90 => _90.getSync, 'call', _91 => _91(), 'optionalAccess', _92 => _92.value]);
8008
8444
  if (!expID) {
8009
8445
  return getErrPermlink("provide-experiment-id");
8010
8446
  } else {
@@ -8094,13 +8530,13 @@ var Dataset2 = (_class13 = class extends ObjectFetcher {
8094
8530
  )
8095
8531
  ),
8096
8532
  _internal_btql
8097
- );_class13.prototype.__init54.call(this);_class13.prototype.__init55.call(this);;
8533
+ );_class13.prototype.__init55.call(this);_class13.prototype.__init56.call(this);;
8098
8534
  this.state = state;
8099
8535
  this.lazyMetadata = lazyMetadata;
8100
8536
  }
8101
8537
 
8102
- __init54() {this.__braintrust_dataset_marker = true}
8103
- __init55() {this.newRecords = 0}
8538
+ __init55() {this.__braintrust_dataset_marker = true}
8539
+ __init56() {this.newRecords = 0}
8104
8540
  get id() {
8105
8541
  return (async () => {
8106
8542
  return (await this.lazyMetadata.get()).dataset.id;
@@ -8454,14 +8890,14 @@ function renderPromptParams(params, args, options = {}) {
8454
8890
  return params;
8455
8891
  }
8456
8892
  var Prompt2 = (_class14 = class _Prompt {
8457
- constructor(metadata, defaults, noTrace) {;_class14.prototype.__init56.call(this);_class14.prototype.__init57.call(this);
8893
+ constructor(metadata, defaults, noTrace) {;_class14.prototype.__init57.call(this);_class14.prototype.__init58.call(this);
8458
8894
  this.metadata = metadata;
8459
8895
  this.defaults = defaults;
8460
8896
  this.noTrace = noTrace;
8461
8897
  }
8462
8898
 
8463
- __init56() {this.hasParsedPromptData = false}
8464
- __init57() {this.__braintrust_prompt_marker = true}
8899
+ __init57() {this.hasParsedPromptData = false}
8900
+ __init58() {this.__braintrust_prompt_marker = true}
8465
8901
  get id() {
8466
8902
  return this.metadata.id;
8467
8903
  }
@@ -8475,16 +8911,16 @@ var Prompt2 = (_class14 = class _Prompt {
8475
8911
  return "slug" in this.metadata ? this.metadata.slug : this.metadata.id;
8476
8912
  }
8477
8913
  get prompt() {
8478
- return _optionalChain([this, 'access', _97 => _97.getParsedPromptData, 'call', _98 => _98(), 'optionalAccess', _99 => _99.prompt]);
8914
+ return _optionalChain([this, 'access', _93 => _93.getParsedPromptData, 'call', _94 => _94(), 'optionalAccess', _95 => _95.prompt]);
8479
8915
  }
8480
8916
  get version() {
8481
8917
  return this.metadata[TRANSACTION_ID_FIELD];
8482
8918
  }
8483
8919
  get options() {
8484
- return _optionalChain([this, 'access', _100 => _100.getParsedPromptData, 'call', _101 => _101(), 'optionalAccess', _102 => _102.options]) || {};
8920
+ return _optionalChain([this, 'access', _96 => _96.getParsedPromptData, 'call', _97 => _97(), 'optionalAccess', _98 => _98.options]) || {};
8485
8921
  }
8486
8922
  get templateFormat() {
8487
- return _optionalChain([this, 'access', _103 => _103.getParsedPromptData, 'call', _104 => _104(), 'optionalAccess', _105 => _105.template_format]);
8923
+ return _optionalChain([this, 'access', _99 => _99.getParsedPromptData, 'call', _100 => _100(), 'optionalAccess', _101 => _101.template_format]);
8488
8924
  }
8489
8925
  get promptData() {
8490
8926
  return this.getParsedPromptData();
@@ -8644,7 +9080,7 @@ var Prompt2 = (_class14 = class _Prompt {
8644
9080
  return {
8645
9081
  type: "chat",
8646
9082
  messages,
8647
- ..._optionalChain([prompt, 'access', _106 => _106.tools, 'optionalAccess', _107 => _107.trim, 'call', _108 => _108()]) ? {
9083
+ ..._optionalChain([prompt, 'access', _102 => _102.tools, 'optionalAccess', _103 => _103.trim, 'call', _104 => _104()]) ? {
8648
9084
  tools: render(prompt.tools)
8649
9085
  } : void 0
8650
9086
  };
@@ -8689,6 +9125,55 @@ var Prompt2 = (_class14 = class _Prompt {
8689
9125
  );
8690
9126
  }
8691
9127
  }, _class14);
9128
+ var RemoteEvalParameters = (_class15 = class {
9129
+ constructor(metadata) {;_class15.prototype.__init59.call(this);
9130
+ this.metadata = metadata;
9131
+ }
9132
+ __init59() {this.__braintrust_parameters_marker = true}
9133
+ get id() {
9134
+ return this.metadata.id;
9135
+ }
9136
+ get projectId() {
9137
+ return this.metadata.project_id;
9138
+ }
9139
+ get name() {
9140
+ return this.metadata.name;
9141
+ }
9142
+ get slug() {
9143
+ return this.metadata.slug;
9144
+ }
9145
+ get version() {
9146
+ return this.metadata[TRANSACTION_ID_FIELD];
9147
+ }
9148
+ get schema() {
9149
+ return this.metadata.function_data.__schema;
9150
+ }
9151
+ get data() {
9152
+ return _nullishCoalesce(this.metadata.function_data.data, () => ( {}));
9153
+ }
9154
+ validate(data) {
9155
+ if (typeof data !== "object" || data === null) {
9156
+ return false;
9157
+ }
9158
+ const schemaProps = this.schema.properties;
9159
+ if (typeof schemaProps !== "object" || schemaProps === null) {
9160
+ return true;
9161
+ }
9162
+ for (const key of Object.keys(schemaProps)) {
9163
+ if (!(key in data)) {
9164
+ const required = Array.isArray(this.schema.required) ? this.schema.required : [];
9165
+ if (required.includes(key)) {
9166
+ return false;
9167
+ }
9168
+ }
9169
+ }
9170
+ return true;
9171
+ }
9172
+ static isParameters(x) {
9173
+ return typeof x === "object" && x !== null && "__braintrust_parameters_marker" in x && // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
9174
+ x.__braintrust_parameters_marker === true;
9175
+ }
9176
+ }, _class15);
8692
9177
  var TEST_API_KEY = "___TEST_API_KEY__THIS_IS_NOT_REAL___";
8693
9178
  function setInitialTestState() {
8694
9179
  if (!_internalGetGlobalState()) {
@@ -8753,9 +9238,9 @@ async function getPromptVersions(projectId, promptId) {
8753
9238
  );
8754
9239
  }
8755
9240
  const result = await response.json();
8756
- return _optionalChain([result, 'access', _109 => _109.data, 'optionalAccess', _110 => _110.filter, 'call', _111 => _111(
8757
- (entry) => ["upsert", "merge"].includes(_optionalChain([entry, 'access', _112 => _112.audit_data, 'optionalAccess', _113 => _113.action]))
8758
- ), 'access', _114 => _114.map, 'call', _115 => _115((entry) => prettifyXact(entry._xact_id))]) || [];
9241
+ return _optionalChain([result, 'access', _105 => _105.data, 'optionalAccess', _106 => _106.filter, 'call', _107 => _107(
9242
+ (entry) => ["upsert", "merge"].includes(_optionalChain([entry, 'access', _108 => _108.audit_data, 'optionalAccess', _109 => _109.action]))
9243
+ ), 'access', _110 => _110.map, 'call', _111 => _111((entry) => prettifyXact(entry._xact_id))]) || [];
8759
9244
  }
8760
9245
  function resetIdGenStateForTests() {
8761
9246
  const state = _internalGetGlobalState();
@@ -8829,6 +9314,7 @@ __export(exports_exports, {
8829
9314
  CodePrompt: () => CodePrompt,
8830
9315
  ContextManager: () => ContextManager,
8831
9316
  DEFAULT_FETCH_BATCH_SIZE: () => DEFAULT_FETCH_BATCH_SIZE,
9317
+ DEFAULT_MAX_REQUEST_SIZE: () => DEFAULT_MAX_REQUEST_SIZE,
8832
9318
  Dataset: () => Dataset2,
8833
9319
  ERR_PERMALINK: () => ERR_PERMALINK,
8834
9320
  Eval: () => Eval,
@@ -8839,6 +9325,7 @@ __export(exports_exports, {
8839
9325
  IDGenerator: () => IDGenerator,
8840
9326
  JSONAttachment: () => JSONAttachment,
8841
9327
  LEGACY_CACHED_HEADER: () => LEGACY_CACHED_HEADER,
9328
+ LOGS3_OVERFLOW_REFERENCE_TYPE: () => LOGS3_OVERFLOW_REFERENCE_TYPE,
8842
9329
  LazyValue: () => LazyValue,
8843
9330
  Logger: () => Logger,
8844
9331
  LoginInvalidOrgError: () => LoginInvalidOrgError,
@@ -8863,8 +9350,10 @@ __export(exports_exports, {
8863
9350
  _exportsForTestingOnly: () => _exportsForTestingOnly,
8864
9351
  _internalGetGlobalState: () => _internalGetGlobalState,
8865
9352
  _internalSetInitialState: () => _internalSetInitialState,
9353
+ addAzureBlobHeaders: () => addAzureBlobHeaders,
8866
9354
  braintrustStreamChunkSchema: () => braintrustStreamChunkSchema,
8867
9355
  buildLocalSummary: () => buildLocalSummary,
9356
+ constructLogs3OverflowRequest: () => constructLogs3OverflowRequest,
8868
9357
  createFinalValuePassThroughStream: () => createFinalValuePassThroughStream,
8869
9358
  currentExperiment: () => currentExperiment,
8870
9359
  currentLogger: () => currentLogger,
@@ -8888,15 +9377,18 @@ __export(exports_exports, {
8888
9377
  initLogger: () => initLogger,
8889
9378
  invoke: () => invoke,
8890
9379
  isTemplateFormat: () => isTemplateFormat,
9380
+ loadParameters: () => loadParameters,
8891
9381
  loadPrompt: () => loadPrompt,
8892
9382
  log: () => log,
8893
9383
  logError: () => logError,
8894
9384
  login: () => login,
8895
9385
  loginToState: () => loginToState,
9386
+ logs3OverflowUploadSchema: () => logs3OverflowUploadSchema,
8896
9387
  newId: () => newId,
8897
9388
  parseCachedHeader: () => parseCachedHeader,
8898
9389
  parseTemplateFormat: () => parseTemplateFormat,
8899
9390
  permalink: () => permalink,
9391
+ pickLogs3OverflowObjectIds: () => pickLogs3OverflowObjectIds,
8900
9392
  projects: () => projects,
8901
9393
  promptContentsSchema: () => promptContentsSchema,
8902
9394
  promptDefinitionSchema: () => promptDefinitionSchema,
@@ -8917,6 +9409,8 @@ __export(exports_exports, {
8917
9409
  traceable: () => traceable,
8918
9410
  traced: () => traced,
8919
9411
  updateSpan: () => updateSpan,
9412
+ uploadLogs3OverflowPayload: () => uploadLogs3OverflowPayload,
9413
+ utf8ByteLength: () => utf8ByteLength,
8920
9414
  withCurrent: () => withCurrent,
8921
9415
  withDataset: () => withDataset,
8922
9416
  withExperiment: () => withExperiment,
@@ -9019,7 +9513,7 @@ function initFunction({
9019
9513
  state
9020
9514
  }) {
9021
9515
  const s = _nullishCoalesce(state, () => ( _internalGetGlobalState()));
9022
- _optionalChain([s, 'optionalAccess', _116 => _116.spanCache, 'optionalAccess', _117 => _117.disable, 'call', _118 => _118()]);
9516
+ _optionalChain([s, 'optionalAccess', _112 => _112.spanCache, 'optionalAccess', _113 => _113.disable, 'call', _114 => _114()]);
9023
9517
  const f = async (input) => {
9024
9518
  return await invoke({
9025
9519
  projectName,
@@ -9083,7 +9577,7 @@ function parseSpanFromResponseCreateParams(params) {
9083
9577
  }
9084
9578
  function parseEventFromResponseCreateResult(result) {
9085
9579
  const data = {};
9086
- if (_optionalChain([result, 'optionalAccess', _119 => _119.output]) !== void 0) {
9580
+ if (_optionalChain([result, 'optionalAccess', _115 => _115.output]) !== void 0) {
9087
9581
  data.output = processImagesInOutput(result.output);
9088
9582
  }
9089
9583
  if (result) {
@@ -9092,7 +9586,7 @@ function parseEventFromResponseCreateResult(result) {
9092
9586
  data.metadata = metadata;
9093
9587
  }
9094
9588
  }
9095
- data.metrics = parseMetricsFromUsage(_optionalChain([result, 'optionalAccess', _120 => _120.usage]));
9589
+ data.metrics = parseMetricsFromUsage(_optionalChain([result, 'optionalAccess', _116 => _116.usage]));
9096
9590
  return data;
9097
9591
  }
9098
9592
  function processImagesInOutput(output) {
@@ -9146,7 +9640,7 @@ function parseSpanFromResponseParseParams(params) {
9146
9640
  }
9147
9641
  function parseEventFromResponseParseResult(result) {
9148
9642
  const data = {};
9149
- if (_optionalChain([result, 'optionalAccess', _121 => _121.output]) !== void 0) {
9643
+ if (_optionalChain([result, 'optionalAccess', _117 => _117.output]) !== void 0) {
9150
9644
  data.output = processImagesInOutput(result.output);
9151
9645
  }
9152
9646
  if (result) {
@@ -9155,7 +9649,7 @@ function parseEventFromResponseParseResult(result) {
9155
9649
  data.metadata = metadata;
9156
9650
  }
9157
9651
  }
9158
- data.metrics = parseMetricsFromUsage(_optionalChain([result, 'optionalAccess', _122 => _122.usage]));
9652
+ data.metrics = parseMetricsFromUsage(_optionalChain([result, 'optionalAccess', _118 => _118.usage]));
9159
9653
  return data;
9160
9654
  }
9161
9655
  function traceResponseCreateStream(stream, timedSpan) {
@@ -9172,7 +9666,7 @@ function traceResponseCreateStream(stream, timedSpan) {
9172
9666
  return result;
9173
9667
  }
9174
9668
  const item = result.value;
9175
- if (!item || !_optionalChain([item, 'optionalAccess', _123 => _123.type]) || !_optionalChain([item, 'optionalAccess', _124 => _124.response])) {
9669
+ if (!item || !_optionalChain([item, 'optionalAccess', _119 => _119.type]) || !_optionalChain([item, 'optionalAccess', _120 => _120.response])) {
9176
9670
  return result;
9177
9671
  }
9178
9672
  const event = parseLogFromItem(item);
@@ -9183,14 +9677,14 @@ function traceResponseCreateStream(stream, timedSpan) {
9183
9677
  };
9184
9678
  }
9185
9679
  function parseLogFromItem(item) {
9186
- if (!item || !_optionalChain([item, 'optionalAccess', _125 => _125.type]) || !_optionalChain([item, 'optionalAccess', _126 => _126.response])) {
9680
+ if (!item || !_optionalChain([item, 'optionalAccess', _121 => _121.type]) || !_optionalChain([item, 'optionalAccess', _122 => _122.response])) {
9187
9681
  return {};
9188
9682
  }
9189
9683
  const response = item.response;
9190
9684
  switch (item.type) {
9191
9685
  case "response.completed":
9192
9686
  const data = {};
9193
- if (_optionalChain([response, 'optionalAccess', _127 => _127.output]) !== void 0) {
9687
+ if (_optionalChain([response, 'optionalAccess', _123 => _123.output]) !== void 0) {
9194
9688
  data.output = processImagesInOutput(response.output);
9195
9689
  }
9196
9690
  if (response) {
@@ -9199,7 +9693,7 @@ function parseLogFromItem(item) {
9199
9693
  data.metadata = metadata;
9200
9694
  }
9201
9695
  }
9202
- data.metrics = parseMetricsFromUsage(_optionalChain([response, 'optionalAccess', _128 => _128.usage]));
9696
+ data.metrics = parseMetricsFromUsage(_optionalChain([response, 'optionalAccess', _124 => _124.usage]));
9203
9697
  return data;
9204
9698
  default:
9205
9699
  return {};
@@ -9396,8 +9890,8 @@ function wrapOpenAIv4(openai) {
9396
9890
  const embeddingProxy = createEndpointProxy(openai.embeddings, wrapEmbeddings);
9397
9891
  const moderationProxy = createEndpointProxy(openai.moderations, wrapModerations);
9398
9892
  let betaProxy2;
9399
- if (_optionalChain([openai, 'access', _129 => _129.beta, 'optionalAccess', _130 => _130.chat, 'optionalAccess', _131 => _131.completions, 'optionalAccess', _132 => _132.stream])) {
9400
- const betaChatCompletionProxy = new Proxy(_optionalChain([openai, 'optionalAccess', _133 => _133.beta, 'optionalAccess', _134 => _134.chat, 'access', _135 => _135.completions]), {
9893
+ if (_optionalChain([openai, 'access', _125 => _125.beta, 'optionalAccess', _126 => _126.chat, 'optionalAccess', _127 => _127.completions, 'optionalAccess', _128 => _128.stream])) {
9894
+ const betaChatCompletionProxy = new Proxy(_optionalChain([openai, 'optionalAccess', _129 => _129.beta, 'optionalAccess', _130 => _130.chat, 'access', _131 => _131.completions]), {
9401
9895
  get(target, name, receiver) {
9402
9896
  const baseVal = Reflect.get(target, name, receiver);
9403
9897
  if (name === "parse") {
@@ -9445,7 +9939,7 @@ function wrapOpenAIv4(openai) {
9445
9939
  });
9446
9940
  }
9447
9941
  function logCompletionResponse(startTime, response, span) {
9448
- const metrics = parseMetricsFromUsage(_optionalChain([response, 'optionalAccess', _136 => _136.usage]));
9942
+ const metrics = parseMetricsFromUsage(_optionalChain([response, 'optionalAccess', _132 => _132.usage]));
9449
9943
  metrics.time_to_first_token = getCurrentUnixTimestamp() - startTime;
9450
9944
  span.log({
9451
9945
  output: response.choices,
@@ -9743,7 +10237,7 @@ function parseChatCompletionParams(params) {
9743
10237
  function processEmbeddingResponse(result, span) {
9744
10238
  span.log({
9745
10239
  output: { embedding_length: result.data[0].embedding.length },
9746
- metrics: parseMetricsFromUsage(_optionalChain([result, 'optionalAccess', _137 => _137.usage]))
10240
+ metrics: parseMetricsFromUsage(_optionalChain([result, 'optionalAccess', _133 => _133.usage]))
9747
10241
  });
9748
10242
  }
9749
10243
  function processModerationResponse(result, span) {
@@ -9773,10 +10267,10 @@ function postprocessStreamingResults(allResults) {
9773
10267
  if (result.usage) {
9774
10268
  metrics = {
9775
10269
  ...metrics,
9776
- ...parseMetricsFromUsage(_optionalChain([result, 'optionalAccess', _138 => _138.usage]))
10270
+ ...parseMetricsFromUsage(_optionalChain([result, 'optionalAccess', _134 => _134.usage]))
9777
10271
  };
9778
10272
  }
9779
- const delta = _optionalChain([result, 'access', _139 => _139.choices, 'optionalAccess', _140 => _140[0], 'optionalAccess', _141 => _141.delta]);
10273
+ const delta = _optionalChain([result, 'access', _135 => _135.choices, 'optionalAccess', _136 => _136[0], 'optionalAccess', _137 => _137.delta]);
9780
10274
  if (!delta) {
9781
10275
  continue;
9782
10276
  }
@@ -10020,7 +10514,7 @@ function isModuleNamespace(obj) {
10020
10514
  if (!obj || typeof obj !== "object") {
10021
10515
  return false;
10022
10516
  }
10023
- if (_optionalChain([obj, 'access', _142 => _142.constructor, 'optionalAccess', _143 => _143.name]) === "Module") {
10517
+ if (_optionalChain([obj, 'access', _138 => _138.constructor, 'optionalAccess', _139 => _139.name]) === "Module") {
10024
10518
  return true;
10025
10519
  }
10026
10520
  try {
@@ -10119,10 +10613,10 @@ var makeGenerateTextWrapper = (name, options, generateText, aiSDK) => {
10119
10613
  });
10120
10614
  const gatewayInfo = extractGatewayRoutingInfo(result);
10121
10615
  const resolvedMetadata = {};
10122
- if (_optionalChain([gatewayInfo, 'optionalAccess', _144 => _144.provider])) {
10616
+ if (_optionalChain([gatewayInfo, 'optionalAccess', _140 => _140.provider])) {
10123
10617
  resolvedMetadata.provider = gatewayInfo.provider;
10124
10618
  }
10125
- if (_optionalChain([gatewayInfo, 'optionalAccess', _145 => _145.model])) {
10619
+ if (_optionalChain([gatewayInfo, 'optionalAccess', _141 => _141.model])) {
10126
10620
  resolvedMetadata.model = gatewayInfo.model;
10127
10621
  }
10128
10622
  span.log({
@@ -10160,7 +10654,7 @@ var resolveModel = (model, ai) => {
10160
10654
  if (typeof model !== "string") {
10161
10655
  return model;
10162
10656
  }
10163
- const provider = _nullishCoalesce(_nullishCoalesce(globalThis.AI_SDK_DEFAULT_PROVIDER, () => ( _optionalChain([ai, 'optionalAccess', _146 => _146.gateway]))), () => ( null));
10657
+ const provider = _nullishCoalesce(_nullishCoalesce(globalThis.AI_SDK_DEFAULT_PROVIDER, () => ( _optionalChain([ai, 'optionalAccess', _142 => _142.gateway]))), () => ( null));
10164
10658
  if (provider && typeof provider.languageModel === "function") {
10165
10659
  return provider.languageModel(model);
10166
10660
  }
@@ -10175,7 +10669,7 @@ var wrapModel = (model, ai) => {
10175
10669
  return resolvedModel;
10176
10670
  }
10177
10671
  const originalDoGenerate = resolvedModel.doGenerate.bind(resolvedModel);
10178
- const originalDoStream = _optionalChain([resolvedModel, 'access', _147 => _147.doStream, 'optionalAccess', _148 => _148.bind, 'call', _149 => _149(resolvedModel)]);
10672
+ const originalDoStream = _optionalChain([resolvedModel, 'access', _143 => _143.doStream, 'optionalAccess', _144 => _144.bind, 'call', _145 => _145(resolvedModel)]);
10179
10673
  const { model: modelId, provider } = serializeModelWithProvider(resolvedModel);
10180
10674
  const wrappedDoGenerate = async (options) => {
10181
10675
  const processedInput = await processInputAttachments2(options);
@@ -10184,10 +10678,10 @@ var wrapModel = (model, ai) => {
10184
10678
  const result = await originalDoGenerate(options);
10185
10679
  const gatewayInfo = extractGatewayRoutingInfo(result);
10186
10680
  const resolvedMetadata = {};
10187
- if (_optionalChain([gatewayInfo, 'optionalAccess', _150 => _150.provider])) {
10681
+ if (_optionalChain([gatewayInfo, 'optionalAccess', _146 => _146.provider])) {
10188
10682
  resolvedMetadata.provider = gatewayInfo.provider;
10189
10683
  }
10190
- if (_optionalChain([gatewayInfo, 'optionalAccess', _151 => _151.model])) {
10684
+ if (_optionalChain([gatewayInfo, 'optionalAccess', _147 => _147.model])) {
10191
10685
  resolvedMetadata.model = gatewayInfo.model;
10192
10686
  }
10193
10687
  if (result.finishReason !== void 0) {
@@ -10283,9 +10777,9 @@ var wrapModel = (model, ai) => {
10283
10777
  case "raw":
10284
10778
  if (chunk.rawValue) {
10285
10779
  const rawVal = chunk.rawValue;
10286
- if (_optionalChain([rawVal, 'access', _152 => _152.delta, 'optionalAccess', _153 => _153.content])) {
10780
+ if (_optionalChain([rawVal, 'access', _148 => _148.delta, 'optionalAccess', _149 => _149.content])) {
10287
10781
  text += rawVal.delta.content;
10288
- } else if (_optionalChain([rawVal, 'access', _154 => _154.choices, 'optionalAccess', _155 => _155[0], 'optionalAccess', _156 => _156.delta, 'optionalAccess', _157 => _157.content])) {
10782
+ } else if (_optionalChain([rawVal, 'access', _150 => _150.choices, 'optionalAccess', _151 => _151[0], 'optionalAccess', _152 => _152.delta, 'optionalAccess', _153 => _153.content])) {
10289
10783
  text += rawVal.choices[0].delta.content;
10290
10784
  } else if (typeof rawVal.text === "string") {
10291
10785
  text += rawVal.text;
@@ -10305,10 +10799,10 @@ var wrapModel = (model, ai) => {
10305
10799
  }
10306
10800
  const gatewayInfo = extractGatewayRoutingInfo(output);
10307
10801
  const resolvedMetadata = {};
10308
- if (_optionalChain([gatewayInfo, 'optionalAccess', _158 => _158.provider])) {
10802
+ if (_optionalChain([gatewayInfo, 'optionalAccess', _154 => _154.provider])) {
10309
10803
  resolvedMetadata.provider = gatewayInfo.provider;
10310
10804
  }
10311
- if (_optionalChain([gatewayInfo, 'optionalAccess', _159 => _159.model])) {
10805
+ if (_optionalChain([gatewayInfo, 'optionalAccess', _155 => _155.model])) {
10312
10806
  resolvedMetadata.model = gatewayInfo.model;
10313
10807
  }
10314
10808
  if (chunk.finishReason !== void 0) {
@@ -10368,10 +10862,10 @@ var wrapGenerateObject = (generateObject, options = {}, aiSDK) => {
10368
10862
  const output = await processOutput(result, options.denyOutputPaths);
10369
10863
  const gatewayInfo = extractGatewayRoutingInfo(result);
10370
10864
  const resolvedMetadata = {};
10371
- if (_optionalChain([gatewayInfo, 'optionalAccess', _160 => _160.provider])) {
10865
+ if (_optionalChain([gatewayInfo, 'optionalAccess', _156 => _156.provider])) {
10372
10866
  resolvedMetadata.provider = gatewayInfo.provider;
10373
10867
  }
10374
- if (_optionalChain([gatewayInfo, 'optionalAccess', _161 => _161.model])) {
10868
+ if (_optionalChain([gatewayInfo, 'optionalAccess', _157 => _157.model])) {
10375
10869
  resolvedMetadata.model = gatewayInfo.model;
10376
10870
  }
10377
10871
  span.log({
@@ -10456,16 +10950,16 @@ var makeStreamTextWrapper = (name, options, streamText, aiSDK) => {
10456
10950
  }
10457
10951
  });
10458
10952
  }
10459
- _optionalChain([params, 'access', _162 => _162.onChunk, 'optionalCall', _163 => _163(chunk)]);
10953
+ _optionalChain([params, 'access', _158 => _158.onChunk, 'optionalCall', _159 => _159(chunk)]);
10460
10954
  },
10461
10955
  onFinish: async (event) => {
10462
- _optionalChain([params, 'access', _164 => _164.onFinish, 'optionalCall', _165 => _165(event)]);
10956
+ _optionalChain([params, 'access', _160 => _160.onFinish, 'optionalCall', _161 => _161(event)]);
10463
10957
  const gatewayInfo = extractGatewayRoutingInfo(event);
10464
10958
  const resolvedMetadata = {};
10465
- if (_optionalChain([gatewayInfo, 'optionalAccess', _166 => _166.provider])) {
10959
+ if (_optionalChain([gatewayInfo, 'optionalAccess', _162 => _162.provider])) {
10466
10960
  resolvedMetadata.provider = gatewayInfo.provider;
10467
10961
  }
10468
- if (_optionalChain([gatewayInfo, 'optionalAccess', _167 => _167.model])) {
10962
+ if (_optionalChain([gatewayInfo, 'optionalAccess', _163 => _163.model])) {
10469
10963
  resolvedMetadata.model = gatewayInfo.model;
10470
10964
  }
10471
10965
  span.log({
@@ -10476,7 +10970,7 @@ var makeStreamTextWrapper = (name, options, streamText, aiSDK) => {
10476
10970
  span.end();
10477
10971
  },
10478
10972
  onError: async (err) => {
10479
- _optionalChain([params, 'access', _168 => _168.onError, 'optionalCall', _169 => _169(err)]);
10973
+ _optionalChain([params, 'access', _164 => _164.onError, 'optionalCall', _165 => _165(err)]);
10480
10974
  span.log({
10481
10975
  error: serializeError(err)
10482
10976
  });
@@ -10580,16 +11074,16 @@ var wrapStreamObject = (streamObject, options = {}, aiSDK) => {
10580
11074
  }
10581
11075
  });
10582
11076
  }
10583
- _optionalChain([params, 'access', _170 => _170.onChunk, 'optionalCall', _171 => _171(chunk)]);
11077
+ _optionalChain([params, 'access', _166 => _166.onChunk, 'optionalCall', _167 => _167(chunk)]);
10584
11078
  },
10585
11079
  onFinish: async (event) => {
10586
- _optionalChain([params, 'access', _172 => _172.onFinish, 'optionalCall', _173 => _173(event)]);
11080
+ _optionalChain([params, 'access', _168 => _168.onFinish, 'optionalCall', _169 => _169(event)]);
10587
11081
  const gatewayInfo = extractGatewayRoutingInfo(event);
10588
11082
  const resolvedMetadata = {};
10589
- if (_optionalChain([gatewayInfo, 'optionalAccess', _174 => _174.provider])) {
11083
+ if (_optionalChain([gatewayInfo, 'optionalAccess', _170 => _170.provider])) {
10590
11084
  resolvedMetadata.provider = gatewayInfo.provider;
10591
11085
  }
10592
- if (_optionalChain([gatewayInfo, 'optionalAccess', _175 => _175.model])) {
11086
+ if (_optionalChain([gatewayInfo, 'optionalAccess', _171 => _171.model])) {
10593
11087
  resolvedMetadata.model = gatewayInfo.model;
10594
11088
  }
10595
11089
  span.log({
@@ -10600,7 +11094,7 @@ var wrapStreamObject = (streamObject, options = {}, aiSDK) => {
10600
11094
  span.end();
10601
11095
  },
10602
11096
  onError: async (err) => {
10603
- _optionalChain([params, 'access', _176 => _176.onError, 'optionalCall', _177 => _177(err)]);
11097
+ _optionalChain([params, 'access', _172 => _172.onError, 'optionalCall', _173 => _173(err)]);
10604
11098
  span.log({
10605
11099
  error: serializeError(err)
10606
11100
  });
@@ -10781,8 +11275,8 @@ function parseGatewayModelString(modelString) {
10781
11275
  return { model: modelString };
10782
11276
  }
10783
11277
  function serializeModelWithProvider(model) {
10784
- const modelId = typeof model === "string" ? model : _optionalChain([model, 'optionalAccess', _178 => _178.modelId]);
10785
- const explicitProvider = typeof model === "object" ? _optionalChain([model, 'optionalAccess', _179 => _179.provider]) : void 0;
11278
+ const modelId = typeof model === "string" ? model : _optionalChain([model, 'optionalAccess', _174 => _174.modelId]);
11279
+ const explicitProvider = typeof model === "object" ? _optionalChain([model, 'optionalAccess', _175 => _175.provider]) : void 0;
10786
11280
  if (!modelId) {
10787
11281
  return { model: modelId, provider: explicitProvider };
10788
11282
  }
@@ -10793,8 +11287,8 @@ function serializeModelWithProvider(model) {
10793
11287
  };
10794
11288
  }
10795
11289
  function extractGatewayRoutingInfo(result) {
10796
- if (_optionalChain([result, 'optionalAccess', _180 => _180.steps]) && Array.isArray(result.steps) && result.steps.length > 0) {
10797
- const routing2 = _optionalChain([result, 'access', _181 => _181.steps, 'access', _182 => _182[0], 'optionalAccess', _183 => _183.providerMetadata, 'optionalAccess', _184 => _184.gateway, 'optionalAccess', _185 => _185.routing]);
11290
+ if (_optionalChain([result, 'optionalAccess', _176 => _176.steps]) && Array.isArray(result.steps) && result.steps.length > 0) {
11291
+ const routing2 = _optionalChain([result, 'access', _177 => _177.steps, 'access', _178 => _178[0], 'optionalAccess', _179 => _179.providerMetadata, 'optionalAccess', _180 => _180.gateway, 'optionalAccess', _181 => _181.routing]);
10798
11292
  if (routing2) {
10799
11293
  return {
10800
11294
  provider: routing2.resolvedProvider || routing2.finalProvider,
@@ -10802,7 +11296,7 @@ function extractGatewayRoutingInfo(result) {
10802
11296
  };
10803
11297
  }
10804
11298
  }
10805
- const routing = _optionalChain([result, 'optionalAccess', _186 => _186.providerMetadata, 'optionalAccess', _187 => _187.gateway, 'optionalAccess', _188 => _188.routing]);
11299
+ const routing = _optionalChain([result, 'optionalAccess', _182 => _182.providerMetadata, 'optionalAccess', _183 => _183.gateway, 'optionalAccess', _184 => _184.routing]);
10806
11300
  if (routing) {
10807
11301
  return {
10808
11302
  provider: routing.resolvedProvider || routing.finalProvider,
@@ -11074,7 +11568,7 @@ var convertImageToAttachment = (image, explicitMimeType) => {
11074
11568
  try {
11075
11569
  if (typeof image === "string" && image.startsWith("data:")) {
11076
11570
  const [mimeTypeSection, base64Data] = image.split(",");
11077
- const mimeType = _optionalChain([mimeTypeSection, 'access', _189 => _189.match, 'call', _190 => _190(/data:(.*?);/), 'optionalAccess', _191 => _191[1]]);
11571
+ const mimeType = _optionalChain([mimeTypeSection, 'access', _185 => _185.match, 'call', _186 => _186(/data:(.*?);/), 'optionalAccess', _187 => _187[1]]);
11078
11572
  if (mimeType && base64Data) {
11079
11573
  const blob = convertDataToBlob(base64Data, mimeType);
11080
11574
  if (blob) {
@@ -11241,7 +11735,7 @@ function firstNumber(...values) {
11241
11735
  }
11242
11736
  function extractTokenMetrics(result) {
11243
11737
  const metrics = {};
11244
- let usage = _optionalChain([result, 'optionalAccess', _192 => _192.totalUsage]) || _optionalChain([result, 'optionalAccess', _193 => _193.usage]);
11738
+ let usage = _optionalChain([result, 'optionalAccess', _188 => _188.totalUsage]) || _optionalChain([result, 'optionalAccess', _189 => _189.usage]);
11245
11739
  if (!usage && result) {
11246
11740
  try {
11247
11741
  if ("totalUsage" in result && typeof result.totalUsage !== "function") {
@@ -11256,7 +11750,7 @@ function extractTokenMetrics(result) {
11256
11750
  return metrics;
11257
11751
  }
11258
11752
  const promptTokens = firstNumber(
11259
- _optionalChain([usage, 'access', _194 => _194.inputTokens, 'optionalAccess', _195 => _195.total]),
11753
+ _optionalChain([usage, 'access', _190 => _190.inputTokens, 'optionalAccess', _191 => _191.total]),
11260
11754
  usage.inputTokens,
11261
11755
  usage.promptTokens,
11262
11756
  usage.prompt_tokens
@@ -11265,7 +11759,7 @@ function extractTokenMetrics(result) {
11265
11759
  metrics.prompt_tokens = promptTokens;
11266
11760
  }
11267
11761
  const completionTokens = firstNumber(
11268
- _optionalChain([usage, 'access', _196 => _196.outputTokens, 'optionalAccess', _197 => _197.total]),
11762
+ _optionalChain([usage, 'access', _192 => _192.outputTokens, 'optionalAccess', _193 => _193.total]),
11269
11763
  usage.outputTokens,
11270
11764
  usage.completionTokens,
11271
11765
  usage.completion_tokens
@@ -11282,7 +11776,7 @@ function extractTokenMetrics(result) {
11282
11776
  metrics.tokens = totalTokens;
11283
11777
  }
11284
11778
  const promptCachedTokens = firstNumber(
11285
- _optionalChain([usage, 'access', _198 => _198.inputTokens, 'optionalAccess', _199 => _199.cacheRead]),
11779
+ _optionalChain([usage, 'access', _194 => _194.inputTokens, 'optionalAccess', _195 => _195.cacheRead]),
11286
11780
  usage.cachedInputTokens,
11287
11781
  usage.promptCachedTokens,
11288
11782
  usage.prompt_cached_tokens
@@ -11312,7 +11806,7 @@ function extractTokenMetrics(result) {
11312
11806
  metrics.completion_cached_tokens = completionCachedTokens;
11313
11807
  }
11314
11808
  const reasoningTokenCount = firstNumber(
11315
- _optionalChain([usage, 'access', _200 => _200.outputTokens, 'optionalAccess', _201 => _201.reasoning]),
11809
+ _optionalChain([usage, 'access', _196 => _196.outputTokens, 'optionalAccess', _197 => _197.reasoning]),
11316
11810
  usage.reasoningTokens,
11317
11811
  usage.completionReasoningTokens,
11318
11812
  usage.completion_reasoning_tokens,
@@ -11338,12 +11832,12 @@ function extractTokenMetrics(result) {
11338
11832
  return metrics;
11339
11833
  }
11340
11834
  function extractCostFromResult(result) {
11341
- if (_optionalChain([result, 'optionalAccess', _202 => _202.steps]) && Array.isArray(result.steps) && result.steps.length > 0) {
11835
+ if (_optionalChain([result, 'optionalAccess', _198 => _198.steps]) && Array.isArray(result.steps) && result.steps.length > 0) {
11342
11836
  let totalCost = 0;
11343
11837
  let foundCost = false;
11344
11838
  for (const step of result.steps) {
11345
- const gateway2 = _optionalChain([step, 'optionalAccess', _203 => _203.providerMetadata, 'optionalAccess', _204 => _204.gateway]);
11346
- const stepCost = parseGatewayCost(_optionalChain([gateway2, 'optionalAccess', _205 => _205.cost])) || parseGatewayCost(_optionalChain([gateway2, 'optionalAccess', _206 => _206.marketCost]));
11839
+ const gateway2 = _optionalChain([step, 'optionalAccess', _199 => _199.providerMetadata, 'optionalAccess', _200 => _200.gateway]);
11840
+ const stepCost = parseGatewayCost(_optionalChain([gateway2, 'optionalAccess', _201 => _201.cost])) || parseGatewayCost(_optionalChain([gateway2, 'optionalAccess', _202 => _202.marketCost]));
11347
11841
  if (stepCost !== void 0 && stepCost > 0) {
11348
11842
  totalCost += stepCost;
11349
11843
  foundCost = true;
@@ -11353,8 +11847,8 @@ function extractCostFromResult(result) {
11353
11847
  return totalCost;
11354
11848
  }
11355
11849
  }
11356
- const gateway = _optionalChain([result, 'optionalAccess', _207 => _207.providerMetadata, 'optionalAccess', _208 => _208.gateway]);
11357
- const directCost = parseGatewayCost(_optionalChain([gateway, 'optionalAccess', _209 => _209.cost])) || parseGatewayCost(_optionalChain([gateway, 'optionalAccess', _210 => _210.marketCost]));
11850
+ const gateway = _optionalChain([result, 'optionalAccess', _203 => _203.providerMetadata, 'optionalAccess', _204 => _204.gateway]);
11851
+ const directCost = parseGatewayCost(_optionalChain([gateway, 'optionalAccess', _205 => _205.cost])) || parseGatewayCost(_optionalChain([gateway, 'optionalAccess', _206 => _206.marketCost]));
11358
11852
  if (directCost !== void 0 && directCost > 0) {
11359
11853
  return directCost;
11360
11854
  }
@@ -11448,7 +11942,7 @@ var omit = (obj, paths) => {
11448
11942
  // src/wrappers/ai-sdk/deprecated/wrapAISDKModel.ts
11449
11943
  function wrapAISDKModel(model) {
11450
11944
  const m = model;
11451
- if (_optionalChain([m, 'optionalAccess', _211 => _211.specificationVersion]) === "v1" && typeof _optionalChain([m, 'optionalAccess', _212 => _212.provider]) === "string" && typeof _optionalChain([m, 'optionalAccess', _213 => _213.modelId]) === "string") {
11945
+ if (_optionalChain([m, 'optionalAccess', _207 => _207.specificationVersion]) === "v1" && typeof _optionalChain([m, 'optionalAccess', _208 => _208.provider]) === "string" && typeof _optionalChain([m, 'optionalAccess', _209 => _209.modelId]) === "string") {
11452
11946
  return new BraintrustLanguageModelWrapper(m);
11453
11947
  } else {
11454
11948
  console.warn("Unsupported AI SDK model. Not wrapping.");
@@ -11505,10 +11999,10 @@ var BraintrustLanguageModelWrapper = class {
11505
11999
  metrics: {
11506
12000
  time_to_first_token: getCurrentUnixTimestamp() - startTime,
11507
12001
  tokens: !isEmpty2(ret.usage) ? ret.usage.promptTokens + ret.usage.completionTokens : void 0,
11508
- prompt_tokens: _optionalChain([ret, 'access', _214 => _214.usage, 'optionalAccess', _215 => _215.promptTokens]),
11509
- completion_tokens: _optionalChain([ret, 'access', _216 => _216.usage, 'optionalAccess', _217 => _217.completionTokens]),
12002
+ prompt_tokens: _optionalChain([ret, 'access', _210 => _210.usage, 'optionalAccess', _211 => _211.promptTokens]),
12003
+ completion_tokens: _optionalChain([ret, 'access', _212 => _212.usage, 'optionalAccess', _213 => _213.completionTokens]),
11510
12004
  cached: parseCachedHeader(
11511
- _nullishCoalesce(_optionalChain([ret, 'access', _218 => _218.rawResponse, 'optionalAccess', _219 => _219.headers, 'optionalAccess', _220 => _220[X_CACHED_HEADER]]), () => ( _optionalChain([ret, 'access', _221 => _221.rawResponse, 'optionalAccess', _222 => _222.headers, 'optionalAccess', _223 => _223[LEGACY_CACHED_HEADER]])))
12005
+ _nullishCoalesce(_optionalChain([ret, 'access', _214 => _214.rawResponse, 'optionalAccess', _215 => _215.headers, 'optionalAccess', _216 => _216[X_CACHED_HEADER]]), () => ( _optionalChain([ret, 'access', _217 => _217.rawResponse, 'optionalAccess', _218 => _218.headers, 'optionalAccess', _219 => _219[LEGACY_CACHED_HEADER]])))
11512
12006
  )
11513
12007
  }
11514
12008
  });
@@ -11600,10 +12094,10 @@ var BraintrustLanguageModelWrapper = class {
11600
12094
  metrics: {
11601
12095
  time_to_first_token,
11602
12096
  tokens: !isEmpty2(usage) ? usage.promptTokens + usage.completionTokens : void 0,
11603
- prompt_tokens: _optionalChain([usage, 'optionalAccess', _224 => _224.promptTokens]),
11604
- completion_tokens: _optionalChain([usage, 'optionalAccess', _225 => _225.completionTokens]),
12097
+ prompt_tokens: _optionalChain([usage, 'optionalAccess', _220 => _220.promptTokens]),
12098
+ completion_tokens: _optionalChain([usage, 'optionalAccess', _221 => _221.completionTokens]),
11605
12099
  cached: parseCachedHeader(
11606
- _nullishCoalesce(_optionalChain([ret, 'access', _226 => _226.rawResponse, 'optionalAccess', _227 => _227.headers, 'optionalAccess', _228 => _228[X_CACHED_HEADER]]), () => ( _optionalChain([ret, 'access', _229 => _229.rawResponse, 'optionalAccess', _230 => _230.headers, 'optionalAccess', _231 => _231[LEGACY_CACHED_HEADER]])))
12100
+ _nullishCoalesce(_optionalChain([ret, 'access', _222 => _222.rawResponse, 'optionalAccess', _223 => _223.headers, 'optionalAccess', _224 => _224[X_CACHED_HEADER]]), () => ( _optionalChain([ret, 'access', _225 => _225.rawResponse, 'optionalAccess', _226 => _226.headers, 'optionalAccess', _227 => _227[LEGACY_CACHED_HEADER]])))
11607
12101
  )
11608
12102
  }
11609
12103
  });
@@ -11647,7 +12141,7 @@ function postProcessPrompt(prompt) {
11647
12141
  return [
11648
12142
  {
11649
12143
  role: "assistant",
11650
- content: _optionalChain([textPart, 'optionalAccess', _232 => _232.text]),
12144
+ content: _optionalChain([textPart, 'optionalAccess', _228 => _228.text]),
11651
12145
  ...toolCallParts.length > 0 ? {
11652
12146
  tool_calls: toolCallParts.map((part) => ({
11653
12147
  id: part.toolCallId,
@@ -11740,23 +12234,23 @@ function extractAnthropicCacheTokens(cacheReadTokens = 0, cacheCreationTokens =
11740
12234
 
11741
12235
  // src/wrappers/ai-sdk/deprecated/BraintrustMiddleware.ts
11742
12236
  function detectProviderFromResult(result) {
11743
- if (!_optionalChain([result, 'optionalAccess', _233 => _233.providerMetadata])) {
12237
+ if (!_optionalChain([result, 'optionalAccess', _229 => _229.providerMetadata])) {
11744
12238
  return void 0;
11745
12239
  }
11746
12240
  const keys = Object.keys(result.providerMetadata);
11747
- return _optionalChain([keys, 'optionalAccess', _234 => _234.at, 'call', _235 => _235(0)]);
12241
+ return _optionalChain([keys, 'optionalAccess', _230 => _230.at, 'call', _231 => _231(0)]);
11748
12242
  }
11749
12243
  function extractModelFromResult(result) {
11750
- if (_optionalChain([result, 'optionalAccess', _236 => _236.response, 'optionalAccess', _237 => _237.modelId])) {
12244
+ if (_optionalChain([result, 'optionalAccess', _232 => _232.response, 'optionalAccess', _233 => _233.modelId])) {
11751
12245
  return result.response.modelId;
11752
12246
  }
11753
- if (_optionalChain([result, 'optionalAccess', _238 => _238.request, 'optionalAccess', _239 => _239.body, 'optionalAccess', _240 => _240.model])) {
12247
+ if (_optionalChain([result, 'optionalAccess', _234 => _234.request, 'optionalAccess', _235 => _235.body, 'optionalAccess', _236 => _236.model])) {
11754
12248
  return result.request.body.model;
11755
12249
  }
11756
12250
  return void 0;
11757
12251
  }
11758
12252
  function extractModelFromWrapGenerateCallback(model) {
11759
- return _optionalChain([model, 'optionalAccess', _241 => _241.modelId]);
12253
+ return _optionalChain([model, 'optionalAccess', _237 => _237.modelId]);
11760
12254
  }
11761
12255
  function camelToSnake(str) {
11762
12256
  return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
@@ -11801,7 +12295,7 @@ function normalizeUsageMetrics(usage, provider, providerMetadata) {
11801
12295
  metrics.prompt_cached_tokens = cachedInputTokens;
11802
12296
  }
11803
12297
  if (provider === "anthropic") {
11804
- const anthropicMetadata = _optionalChain([providerMetadata, 'optionalAccess', _242 => _242.anthropic]);
12298
+ const anthropicMetadata = _optionalChain([providerMetadata, 'optionalAccess', _238 => _238.anthropic]);
11805
12299
  if (anthropicMetadata) {
11806
12300
  const cacheReadTokens = getNumberProperty(anthropicMetadata.usage, "cache_read_input_tokens") || 0;
11807
12301
  const cacheCreationTokens = getNumberProperty(
@@ -11827,7 +12321,7 @@ function buildAssistantOutputWithToolCalls(result, toolCalls) {
11827
12321
  {
11828
12322
  index: 0,
11829
12323
  logprobs: null,
11830
- finish_reason: _nullishCoalesce(normalizeFinishReason(_optionalChain([result, 'optionalAccess', _243 => _243.finishReason])), () => ( (toolCalls.length ? "tool_calls" : void 0))),
12324
+ finish_reason: _nullishCoalesce(normalizeFinishReason(_optionalChain([result, 'optionalAccess', _239 => _239.finishReason])), () => ( (toolCalls.length ? "tool_calls" : void 0))),
11831
12325
  message: {
11832
12326
  role: "assistant",
11833
12327
  tool_calls: toolCalls.length > 0 ? toolCalls : void 0
@@ -11840,7 +12334,7 @@ function extractToolCallsFromSteps(steps) {
11840
12334
  if (!Array.isArray(steps)) return toolCalls;
11841
12335
  let idx = 0;
11842
12336
  for (const step of steps) {
11843
- const blocks = _optionalChain([step, 'optionalAccess', _244 => _244.content]);
12337
+ const blocks = _optionalChain([step, 'optionalAccess', _240 => _240.content]);
11844
12338
  if (!Array.isArray(blocks)) continue;
11845
12339
  for (const block of blocks) {
11846
12340
  if (block && typeof block === "object" && block.type === "tool-call") {
@@ -11863,7 +12357,7 @@ function extractToolCallsFromBlocks(blocks) {
11863
12357
  return extractToolCallsFromSteps([{ content: blocks }]);
11864
12358
  }
11865
12359
  function extractInput(params) {
11866
- return _nullishCoalesce(_nullishCoalesce(_optionalChain([params, 'optionalAccess', _245 => _245.prompt]), () => ( _optionalChain([params, 'optionalAccess', _246 => _246.messages]))), () => ( _optionalChain([params, 'optionalAccess', _247 => _247.system])));
12360
+ return _nullishCoalesce(_nullishCoalesce(_optionalChain([params, 'optionalAccess', _241 => _241.prompt]), () => ( _optionalChain([params, 'optionalAccess', _242 => _242.messages]))), () => ( _optionalChain([params, 'optionalAccess', _243 => _243.system])));
11867
12361
  }
11868
12362
  var V2_EXCLUDE_KEYS = /* @__PURE__ */ new Set([
11869
12363
  "prompt",
@@ -11887,16 +12381,16 @@ function BraintrustMiddleware(config = {}) {
11887
12381
  const rawInput = extractInput(params);
11888
12382
  const processedInput = processInputAttachments(rawInput);
11889
12383
  const spanArgs = {
11890
- name: _optionalChain([config, 'access', _248 => _248.spanInfo, 'optionalAccess', _249 => _249.name]) || "ai-sdk.doGenerate",
12384
+ name: _optionalChain([config, 'access', _244 => _244.spanInfo, 'optionalAccess', _245 => _245.name]) || "ai-sdk.doGenerate",
11891
12385
  spanAttributes: {
11892
12386
  type: "llm" /* LLM */,
11893
- ..._optionalChain([config, 'access', _250 => _250.spanInfo, 'optionalAccess', _251 => _251.spanAttributes]) || {}
12387
+ ..._optionalChain([config, 'access', _246 => _246.spanInfo, 'optionalAccess', _247 => _247.spanAttributes]) || {}
11894
12388
  },
11895
12389
  event: {
11896
12390
  input: processedInput,
11897
12391
  metadata: {
11898
12392
  ...extractModelParameters(params, V2_EXCLUDE_KEYS),
11899
- ..._optionalChain([config, 'access', _252 => _252.spanInfo, 'optionalAccess', _253 => _253.metadata]) || {}
12393
+ ..._optionalChain([config, 'access', _248 => _248.spanInfo, 'optionalAccess', _249 => _249.metadata]) || {}
11900
12394
  }
11901
12395
  }
11902
12396
  };
@@ -11922,12 +12416,12 @@ function BraintrustMiddleware(config = {}) {
11922
12416
  metadata.model = modelId;
11923
12417
  }
11924
12418
  }
11925
- let toolCalls = extractToolCallsFromSteps(_optionalChain([result, 'optionalAccess', _254 => _254.steps]));
12419
+ let toolCalls = extractToolCallsFromSteps(_optionalChain([result, 'optionalAccess', _250 => _250.steps]));
11926
12420
  if (!toolCalls || toolCalls.length === 0) {
11927
- toolCalls = extractToolCallsFromBlocks(_optionalChain([result, 'optionalAccess', _255 => _255.content]));
12421
+ toolCalls = extractToolCallsFromBlocks(_optionalChain([result, 'optionalAccess', _251 => _251.content]));
11928
12422
  }
11929
12423
  span.log({
11930
- output: toolCalls.length > 0 ? buildAssistantOutputWithToolCalls(result, toolCalls) : _optionalChain([result, 'optionalAccess', _256 => _256.content]),
12424
+ output: toolCalls.length > 0 ? buildAssistantOutputWithToolCalls(result, toolCalls) : _optionalChain([result, 'optionalAccess', _252 => _252.content]),
11931
12425
  metadata,
11932
12426
  metrics: normalizeUsageMetrics(
11933
12427
  result.usage,
@@ -11949,16 +12443,16 @@ function BraintrustMiddleware(config = {}) {
11949
12443
  const rawInput = extractInput(params);
11950
12444
  const processedInput = processInputAttachments(rawInput);
11951
12445
  const spanArgs = {
11952
- name: _optionalChain([config, 'access', _257 => _257.spanInfo, 'optionalAccess', _258 => _258.name]) || "ai-sdk.doStream",
12446
+ name: _optionalChain([config, 'access', _253 => _253.spanInfo, 'optionalAccess', _254 => _254.name]) || "ai-sdk.doStream",
11953
12447
  spanAttributes: {
11954
12448
  type: "llm" /* LLM */,
11955
- ..._optionalChain([config, 'access', _259 => _259.spanInfo, 'optionalAccess', _260 => _260.spanAttributes]) || {}
12449
+ ..._optionalChain([config, 'access', _255 => _255.spanInfo, 'optionalAccess', _256 => _256.spanAttributes]) || {}
11956
12450
  },
11957
12451
  event: {
11958
12452
  input: processedInput,
11959
12453
  metadata: {
11960
12454
  ...extractModelParameters(params, V2_EXCLUDE_KEYS),
11961
- ..._optionalChain([config, 'access', _261 => _261.spanInfo, 'optionalAccess', _262 => _262.metadata]) || {}
12455
+ ..._optionalChain([config, 'access', _257 => _257.spanInfo, 'optionalAccess', _258 => _258.metadata]) || {}
11962
12456
  }
11963
12457
  }
11964
12458
  };
@@ -12229,9 +12723,9 @@ function streamNextProxy(stream, sspan) {
12229
12723
  }
12230
12724
  const item = result.value;
12231
12725
  const blockIndex = item.index;
12232
- switch (_optionalChain([item, 'optionalAccess', _263 => _263.type])) {
12726
+ switch (_optionalChain([item, 'optionalAccess', _259 => _259.type])) {
12233
12727
  case "message_start":
12234
- const msg = _optionalChain([item, 'optionalAccess', _264 => _264.message]);
12728
+ const msg = _optionalChain([item, 'optionalAccess', _260 => _260.message]);
12235
12729
  if (msg) {
12236
12730
  const event = parseEventFromMessage(msg);
12237
12731
  totals = { ...totals, ...event.metrics };
@@ -12248,23 +12742,23 @@ function streamNextProxy(stream, sspan) {
12248
12742
  if (!contentBlockDeltas[blockIndex]) {
12249
12743
  contentBlockDeltas[blockIndex] = [];
12250
12744
  }
12251
- if (_optionalChain([item, 'optionalAccess', _265 => _265.delta, 'optionalAccess', _266 => _266.type]) === "text_delta") {
12252
- const text2 = _optionalChain([item, 'optionalAccess', _267 => _267.delta, 'optionalAccess', _268 => _268.text]);
12745
+ if (_optionalChain([item, 'optionalAccess', _261 => _261.delta, 'optionalAccess', _262 => _262.type]) === "text_delta") {
12746
+ const text2 = _optionalChain([item, 'optionalAccess', _263 => _263.delta, 'optionalAccess', _264 => _264.text]);
12253
12747
  if (text2) {
12254
12748
  contentBlockDeltas[blockIndex].push(text2);
12255
12749
  }
12256
- } else if (_optionalChain([item, 'optionalAccess', _269 => _269.delta, 'optionalAccess', _270 => _270.type]) === "input_json_delta") {
12257
- const partialJson = _optionalChain([item, 'optionalAccess', _271 => _271.delta, 'optionalAccess', _272 => _272.partial_json]);
12750
+ } else if (_optionalChain([item, 'optionalAccess', _265 => _265.delta, 'optionalAccess', _266 => _266.type]) === "input_json_delta") {
12751
+ const partialJson = _optionalChain([item, 'optionalAccess', _267 => _267.delta, 'optionalAccess', _268 => _268.partial_json]);
12258
12752
  if (partialJson) {
12259
12753
  contentBlockDeltas[blockIndex].push(partialJson);
12260
12754
  }
12261
12755
  }
12262
12756
  break;
12263
12757
  case "content_block_stop":
12264
- const text = _optionalChain([contentBlockDeltas, 'access', _273 => _273[blockIndex], 'optionalAccess', _274 => _274.join, 'call', _275 => _275("")]);
12758
+ const text = _optionalChain([contentBlockDeltas, 'access', _269 => _269[blockIndex], 'optionalAccess', _270 => _270.join, 'call', _271 => _271("")]);
12265
12759
  if (!text) break;
12266
12760
  const block = contentBlocks[blockIndex];
12267
- if (_optionalChain([block, 'optionalAccess', _276 => _276.type]) === "tool_use") {
12761
+ if (_optionalChain([block, 'optionalAccess', _272 => _272.type]) === "tool_use") {
12268
12762
  try {
12269
12763
  span.log({
12270
12764
  output: {
@@ -12280,12 +12774,12 @@ function streamNextProxy(stream, sspan) {
12280
12774
  }
12281
12775
  break;
12282
12776
  case "message_delta":
12283
- const usage = _optionalChain([item, 'optionalAccess', _277 => _277.usage]);
12777
+ const usage = _optionalChain([item, 'optionalAccess', _273 => _273.usage]);
12284
12778
  if (usage) {
12285
12779
  const metrics = parseMetricsFromUsage2(usage);
12286
12780
  totals = { ...totals, ...metrics };
12287
12781
  }
12288
- const delta = _optionalChain([item, 'optionalAccess', _278 => _278.delta]);
12782
+ const delta = _optionalChain([item, 'optionalAccess', _274 => _274.delta]);
12289
12783
  if (delta) {
12290
12784
  metadata = { ...metadata, ...delta };
12291
12785
  }
@@ -12298,7 +12792,7 @@ function streamNextProxy(stream, sspan) {
12298
12792
  }
12299
12793
  function parseEventFromMessage(message) {
12300
12794
  const output = message ? { role: message.role, content: message.content } : null;
12301
- const metrics = parseMetricsFromUsage2(_optionalChain([message, 'optionalAccess', _279 => _279.usage]));
12795
+ const metrics = parseMetricsFromUsage2(_optionalChain([message, 'optionalAccess', _275 => _275.usage]));
12302
12796
  const metas = ["stop_reason", "stop_sequence"];
12303
12797
  const metadata = {};
12304
12798
  for (const m of metas) {
@@ -12387,6 +12881,189 @@ function wrapMastraAgent(agent, _options) {
12387
12881
  }
12388
12882
 
12389
12883
  // src/wrappers/claude-agent-sdk/claude-agent-sdk.ts
12884
+ function getMcpServerMetadata(serverName, mcpServers) {
12885
+ if (!serverName || !mcpServers) {
12886
+ return {};
12887
+ }
12888
+ const serverConfig = mcpServers[serverName];
12889
+ if (!serverConfig) {
12890
+ return {};
12891
+ }
12892
+ const metadata = {};
12893
+ if (serverConfig.type) {
12894
+ metadata["mcp.type"] = serverConfig.type;
12895
+ } else if (typeof serverConfig === "object" && "transport" in serverConfig) {
12896
+ metadata["mcp.type"] = "sdk";
12897
+ }
12898
+ if (serverConfig.url) {
12899
+ metadata["mcp.url"] = serverConfig.url;
12900
+ }
12901
+ if (serverConfig.command) {
12902
+ metadata["mcp.command"] = serverConfig.command;
12903
+ if (serverConfig.args) {
12904
+ metadata["mcp.args"] = serverConfig.args.join(" ");
12905
+ }
12906
+ }
12907
+ return metadata;
12908
+ }
12909
+ function parseToolName(rawToolName) {
12910
+ const mcpMatch = rawToolName.match(/^mcp__([^_]+)__(.+)$/);
12911
+ if (mcpMatch) {
12912
+ const [, mcpServer, toolName] = mcpMatch;
12913
+ return {
12914
+ displayName: `tool: ${mcpServer}/${toolName}`,
12915
+ toolName,
12916
+ mcpServer,
12917
+ rawToolName
12918
+ };
12919
+ }
12920
+ return {
12921
+ displayName: `tool: ${rawToolName}`,
12922
+ toolName: rawToolName,
12923
+ rawToolName
12924
+ };
12925
+ }
12926
+ function createToolTracingHooks(resolveParentSpan, activeToolSpans, mcpServers, subAgentSpans, endedSubAgentSpans) {
12927
+ const preToolUse = async (input, toolUseID) => {
12928
+ if (input.hook_event_name !== "PreToolUse" || !toolUseID) {
12929
+ return {};
12930
+ }
12931
+ if (input.tool_name === "Task") {
12932
+ return {};
12933
+ }
12934
+ const parsed = parseToolName(input.tool_name);
12935
+ const mcpMetadata = getMcpServerMetadata(parsed.mcpServer, mcpServers);
12936
+ const parentExport = await resolveParentSpan(toolUseID);
12937
+ const toolSpan = startSpan({
12938
+ name: parsed.displayName,
12939
+ spanAttributes: { type: "tool" /* TOOL */ },
12940
+ event: {
12941
+ input: input.tool_input,
12942
+ metadata: {
12943
+ // GenAI semantic conventions
12944
+ "gen_ai.tool.name": parsed.toolName,
12945
+ "gen_ai.tool.call.id": toolUseID,
12946
+ // MCP-specific metadata
12947
+ ...parsed.mcpServer && { "mcp.server": parsed.mcpServer },
12948
+ ...mcpMetadata,
12949
+ // Claude SDK metadata
12950
+ "claude_agent_sdk.raw_tool_name": parsed.rawToolName,
12951
+ "claude_agent_sdk.session_id": input.session_id,
12952
+ "claude_agent_sdk.cwd": input.cwd
12953
+ }
12954
+ },
12955
+ parent: parentExport
12956
+ });
12957
+ activeToolSpans.set(toolUseID, toolSpan);
12958
+ return {};
12959
+ };
12960
+ const postToolUse = async (input, toolUseID) => {
12961
+ if (input.hook_event_name !== "PostToolUse" || !toolUseID) {
12962
+ return {};
12963
+ }
12964
+ const subAgentSpan = subAgentSpans.get(toolUseID);
12965
+ if (subAgentSpan) {
12966
+ try {
12967
+ const response = input.tool_response;
12968
+ const metadata = {};
12969
+ if (_optionalChain([response, 'optionalAccess', _276 => _276.status])) {
12970
+ metadata["claude_agent_sdk.status"] = response.status;
12971
+ }
12972
+ if (_optionalChain([response, 'optionalAccess', _277 => _277.totalDurationMs])) {
12973
+ metadata["claude_agent_sdk.duration_ms"] = response.totalDurationMs;
12974
+ }
12975
+ if (_optionalChain([response, 'optionalAccess', _278 => _278.totalToolUseCount]) !== void 0) {
12976
+ metadata["claude_agent_sdk.tool_use_count"] = response.totalToolUseCount;
12977
+ }
12978
+ subAgentSpan.log({
12979
+ output: _optionalChain([response, 'optionalAccess', _279 => _279.content]),
12980
+ metadata
12981
+ });
12982
+ } finally {
12983
+ subAgentSpan.end();
12984
+ endedSubAgentSpans.add(toolUseID);
12985
+ }
12986
+ return {};
12987
+ }
12988
+ const toolSpan = activeToolSpans.get(toolUseID);
12989
+ if (!toolSpan) {
12990
+ return {};
12991
+ }
12992
+ try {
12993
+ toolSpan.log({ output: input.tool_response });
12994
+ } finally {
12995
+ toolSpan.end();
12996
+ activeToolSpans.delete(toolUseID);
12997
+ }
12998
+ return {};
12999
+ };
13000
+ const postToolUseFailure = async (input, toolUseID) => {
13001
+ if (input.hook_event_name !== "PostToolUseFailure" || !toolUseID) {
13002
+ return {};
13003
+ }
13004
+ const subAgentSpan = subAgentSpans.get(toolUseID);
13005
+ if (subAgentSpan) {
13006
+ try {
13007
+ subAgentSpan.log({ error: input.error });
13008
+ } finally {
13009
+ subAgentSpan.end();
13010
+ endedSubAgentSpans.add(toolUseID);
13011
+ }
13012
+ return {};
13013
+ }
13014
+ const toolSpan = activeToolSpans.get(toolUseID);
13015
+ if (!toolSpan) {
13016
+ return {};
13017
+ }
13018
+ const parsed = parseToolName(input.tool_name);
13019
+ try {
13020
+ toolSpan.log({
13021
+ error: input.error,
13022
+ metadata: {
13023
+ "gen_ai.tool.name": parsed.toolName,
13024
+ "gen_ai.tool.call.id": toolUseID,
13025
+ ...parsed.mcpServer && { "mcp.server": parsed.mcpServer },
13026
+ "claude_agent_sdk.is_interrupt": input.is_interrupt,
13027
+ "claude_agent_sdk.session_id": input.session_id
13028
+ }
13029
+ });
13030
+ } finally {
13031
+ toolSpan.end();
13032
+ activeToolSpans.delete(toolUseID);
13033
+ }
13034
+ return {};
13035
+ };
13036
+ return { preToolUse, postToolUse, postToolUseFailure };
13037
+ }
13038
+ function injectTracingHooks(options, resolveParentSpan, activeToolSpans, subAgentSpans, endedSubAgentSpans) {
13039
+ const mcpServers = options.mcpServers;
13040
+ const { preToolUse, postToolUse, postToolUseFailure } = createToolTracingHooks(
13041
+ resolveParentSpan,
13042
+ activeToolSpans,
13043
+ mcpServers,
13044
+ subAgentSpans,
13045
+ endedSubAgentSpans
13046
+ );
13047
+ const existingHooks = _nullishCoalesce(options.hooks, () => ( {}));
13048
+ return {
13049
+ ...options,
13050
+ hooks: {
13051
+ ...existingHooks,
13052
+ PreToolUse: [
13053
+ ..._nullishCoalesce(existingHooks.PreToolUse, () => ( [])),
13054
+ { hooks: [preToolUse] }
13055
+ ],
13056
+ PostToolUse: [
13057
+ ..._nullishCoalesce(existingHooks.PostToolUse, () => ( [])),
13058
+ { hooks: [postToolUse] }
13059
+ ],
13060
+ PostToolUseFailure: [
13061
+ ..._nullishCoalesce(existingHooks.PostToolUseFailure, () => ( [])),
13062
+ { hooks: [postToolUseFailure] }
13063
+ ]
13064
+ }
13065
+ };
13066
+ }
12390
13067
  function filterSerializableOptions(options) {
12391
13068
  const allowedKeys = [
12392
13069
  "model",
@@ -12411,18 +13088,45 @@ function filterSerializableOptions(options) {
12411
13088
  }
12412
13089
  return filtered;
12413
13090
  }
13091
+ function isAsyncIterable(value) {
13092
+ return value !== null && value !== void 0 && typeof value[Symbol.asyncIterator] === "function";
13093
+ }
12414
13094
  function wrapClaudeAgentQuery(queryFn, defaultThis) {
12415
13095
  const proxy = new Proxy(queryFn, {
12416
13096
  apply(target, thisArg, argArray) {
12417
13097
  const params = _nullishCoalesce(argArray[0], () => ( {}));
12418
13098
  const { prompt, options = {} } = params;
13099
+ const promptIsAsyncIterable = isAsyncIterable(prompt);
13100
+ let capturedPromptMessages;
13101
+ let promptForQuery = prompt;
13102
+ let promptStarted = false;
13103
+ let resolvePromptDone;
13104
+ const promptDone = new Promise((resolve) => {
13105
+ resolvePromptDone = resolve;
13106
+ });
13107
+ if (promptIsAsyncIterable) {
13108
+ capturedPromptMessages = [];
13109
+ const originalPrompt = prompt;
13110
+ const capturingPrompt = (async function* () {
13111
+ promptStarted = true;
13112
+ try {
13113
+ for await (const msg of originalPrompt) {
13114
+ capturedPromptMessages.push(msg);
13115
+ yield msg;
13116
+ }
13117
+ } finally {
13118
+ _optionalChain([resolvePromptDone, 'optionalCall', _280 => _280()]);
13119
+ }
13120
+ })();
13121
+ promptForQuery = capturingPrompt;
13122
+ }
12419
13123
  const span = startSpan({
12420
13124
  name: "Claude Agent",
12421
13125
  spanAttributes: {
12422
13126
  type: "task" /* TASK */
12423
13127
  },
12424
13128
  event: {
12425
- input: typeof prompt === "string" ? prompt : { type: "streaming", description: "AsyncIterable<SDKMessage>" },
13129
+ input: typeof prompt === "string" ? prompt : promptIsAsyncIterable ? void 0 : prompt !== void 0 ? String(prompt) : void 0,
12426
13130
  metadata: filterSerializableOptions(options)
12427
13131
  }
12428
13132
  });
@@ -12433,47 +13137,120 @@ function wrapClaudeAgentQuery(queryFn, defaultThis) {
12433
13137
  let currentMessageStartTime = getCurrentUnixTimestamp();
12434
13138
  const currentMessages = [];
12435
13139
  const createLLMSpan = async () => {
13140
+ const parentToolUseId = _nullishCoalesce(_optionalChain([currentMessages, 'access', _281 => _281[0], 'optionalAccess', _282 => _282.parent_tool_use_id]), () => ( null));
13141
+ let parentSpanExport;
13142
+ if (parentToolUseId) {
13143
+ const subAgentSpan = subAgentSpans.get(parentToolUseId);
13144
+ parentSpanExport = subAgentSpan ? await subAgentSpan.export() : await span.export();
13145
+ } else {
13146
+ parentSpanExport = await span.export();
13147
+ }
12436
13148
  const finalMessageContent = await _createLLMSpanForMessages(
12437
13149
  currentMessages,
12438
13150
  prompt,
12439
13151
  finalResults,
12440
13152
  options,
12441
13153
  currentMessageStartTime,
12442
- await span.export()
13154
+ capturedPromptMessages,
13155
+ parentSpanExport
12443
13156
  );
12444
13157
  if (finalMessageContent) {
12445
13158
  finalResults.push(finalMessageContent);
12446
13159
  }
12447
13160
  const lastMessage = currentMessages[currentMessages.length - 1];
12448
- if (_optionalChain([lastMessage, 'optionalAccess', _280 => _280.message, 'optionalAccess', _281 => _281.usage])) {
13161
+ if (_optionalChain([lastMessage, 'optionalAccess', _283 => _283.message, 'optionalAccess', _284 => _284.usage])) {
12449
13162
  const outputTokens = getNumberProperty2(lastMessage.message.usage, "output_tokens") || 0;
12450
13163
  accumulatedOutputTokens += outputTokens;
12451
13164
  }
12452
13165
  currentMessages.length = 0;
12453
13166
  };
12454
13167
  const invocationTarget = thisArg === proxy || thisArg === void 0 ? _nullishCoalesce(defaultThis, () => ( thisArg)) : thisArg;
13168
+ const activeToolSpans = /* @__PURE__ */ new Map();
13169
+ const subAgentSpans = /* @__PURE__ */ new Map();
13170
+ const endedSubAgentSpans = /* @__PURE__ */ new Set();
13171
+ const toolUseToParent = /* @__PURE__ */ new Map();
13172
+ const pendingSubAgentNames = /* @__PURE__ */ new Map();
13173
+ const resolveParentSpan = async (toolUseID) => {
13174
+ const parentToolUseId = toolUseToParent.get(toolUseID);
13175
+ if (parentToolUseId) {
13176
+ const subAgentSpan = subAgentSpans.get(parentToolUseId);
13177
+ if (subAgentSpan) {
13178
+ return subAgentSpan.export();
13179
+ }
13180
+ }
13181
+ return span.export();
13182
+ };
13183
+ const optionsWithHooks = injectTracingHooks(
13184
+ options,
13185
+ resolveParentSpan,
13186
+ activeToolSpans,
13187
+ subAgentSpans,
13188
+ endedSubAgentSpans
13189
+ );
13190
+ const modifiedArgArray = [
13191
+ {
13192
+ ...params,
13193
+ ...promptForQuery !== void 0 ? { prompt: promptForQuery } : {},
13194
+ options: optionsWithHooks
13195
+ }
13196
+ ];
12455
13197
  const originalGenerator = withCurrent(
12456
13198
  span,
12457
- () => Reflect.apply(target, invocationTarget, argArray)
13199
+ () => Reflect.apply(target, invocationTarget, modifiedArgArray)
12458
13200
  );
12459
13201
  const wrappedGenerator = (async function* () {
12460
13202
  try {
12461
13203
  for await (const message of originalGenerator) {
12462
13204
  const currentTime = getCurrentUnixTimestamp();
12463
- const messageId = _optionalChain([message, 'access', _282 => _282.message, 'optionalAccess', _283 => _283.id]);
13205
+ if (message.type === "assistant" && Array.isArray(_optionalChain([message, 'access', _285 => _285.message, 'optionalAccess', _286 => _286.content]))) {
13206
+ const parentToolUseId = _nullishCoalesce(message.parent_tool_use_id, () => ( null));
13207
+ for (const block of message.message.content) {
13208
+ if (block.type === "tool_use" && block.id) {
13209
+ toolUseToParent.set(block.id, parentToolUseId);
13210
+ if (block.name === "Task" && _optionalChain([block, 'access', _287 => _287.input, 'optionalAccess', _288 => _288.subagent_type])) {
13211
+ pendingSubAgentNames.set(
13212
+ block.id,
13213
+ block.input.subagent_type
13214
+ );
13215
+ }
13216
+ }
13217
+ }
13218
+ }
13219
+ if ("parent_tool_use_id" in message) {
13220
+ const parentToolUseId = message.parent_tool_use_id;
13221
+ if (parentToolUseId && !subAgentSpans.has(parentToolUseId)) {
13222
+ const agentName = pendingSubAgentNames.get(parentToolUseId);
13223
+ const spanName = agentName ? `Agent: ${agentName}` : "Agent: sub-agent";
13224
+ const parentExport = await span.export();
13225
+ const subAgentSpan = startSpan({
13226
+ name: spanName,
13227
+ spanAttributes: { type: "task" /* TASK */ },
13228
+ event: {
13229
+ metadata: {
13230
+ ...agentName && {
13231
+ "claude_agent_sdk.agent_type": agentName
13232
+ }
13233
+ }
13234
+ },
13235
+ parent: parentExport
13236
+ });
13237
+ subAgentSpans.set(parentToolUseId, subAgentSpan);
13238
+ }
13239
+ }
13240
+ const messageId = _optionalChain([message, 'access', _289 => _289.message, 'optionalAccess', _290 => _290.id]);
12464
13241
  if (messageId && messageId !== currentMessageId) {
12465
13242
  await createLLMSpan();
12466
13243
  currentMessageId = messageId;
12467
13244
  currentMessageStartTime = currentTime;
12468
13245
  }
12469
- if (message.type === "assistant" && _optionalChain([message, 'access', _284 => _284.message, 'optionalAccess', _285 => _285.usage])) {
13246
+ if (message.type === "assistant" && _optionalChain([message, 'access', _291 => _291.message, 'optionalAccess', _292 => _292.usage])) {
12470
13247
  currentMessages.push(message);
12471
13248
  }
12472
13249
  if (message.type === "result" && message.usage) {
12473
13250
  finalUsageMetrics = _extractUsageFromMessage(message);
12474
13251
  if (currentMessages.length > 0 && finalUsageMetrics.completion_tokens !== void 0) {
12475
13252
  const lastMessage = currentMessages[currentMessages.length - 1];
12476
- if (_optionalChain([lastMessage, 'optionalAccess', _286 => _286.message, 'optionalAccess', _287 => _287.usage])) {
13253
+ if (_optionalChain([lastMessage, 'optionalAccess', _293 => _293.message, 'optionalAccess', _294 => _294.usage])) {
12477
13254
  const adjustedTokens = finalUsageMetrics.completion_tokens - accumulatedOutputTokens;
12478
13255
  if (adjustedTokens >= 0) {
12479
13256
  lastMessage.message.usage.output_tokens = adjustedTokens;
@@ -12505,6 +13282,22 @@ function wrapClaudeAgentQuery(queryFn, defaultThis) {
12505
13282
  });
12506
13283
  throw error;
12507
13284
  } finally {
13285
+ for (const [id, subSpan] of subAgentSpans) {
13286
+ if (!endedSubAgentSpans.has(id)) {
13287
+ subSpan.end();
13288
+ }
13289
+ }
13290
+ subAgentSpans.clear();
13291
+ if (capturedPromptMessages) {
13292
+ if (promptStarted) {
13293
+ await promptDone;
13294
+ }
13295
+ if (capturedPromptMessages.length > 0) {
13296
+ span.log({
13297
+ input: _formatCapturedMessages(capturedPromptMessages)
13298
+ });
13299
+ }
13300
+ }
12508
13301
  span.end();
12509
13302
  }
12510
13303
  })();
@@ -12532,48 +13325,30 @@ function wrapClaudeAgentQuery(queryFn, defaultThis) {
12532
13325
  });
12533
13326
  return proxy;
12534
13327
  }
12535
- function wrapClaudeAgentTool(toolDef) {
12536
- const originalHandler = toolDef.handler;
12537
- const wrappedHandler = (args, extra) => traced(
12538
- async (span) => {
12539
- span.log({
12540
- input: args,
12541
- metadata: {
12542
- tool_name: toolDef.name,
12543
- tool_description: toolDef.description
12544
- }
12545
- });
12546
- const result = await originalHandler(args, extra);
12547
- span.log({
12548
- output: result
12549
- });
12550
- return result;
12551
- },
12552
- {
12553
- name: `${toolDef.name}`,
12554
- spanAttributes: {
12555
- type: "tool" /* TOOL */
13328
+ function _buildLLMInput(prompt, conversationHistory, capturedPromptMessages) {
13329
+ const promptMessages = [];
13330
+ if (typeof prompt === "string") {
13331
+ promptMessages.push({ content: prompt, role: "user" });
13332
+ } else if (capturedPromptMessages && capturedPromptMessages.length > 0) {
13333
+ for (const msg of capturedPromptMessages) {
13334
+ const role = _optionalChain([msg, 'access', _295 => _295.message, 'optionalAccess', _296 => _296.role]);
13335
+ const content = _optionalChain([msg, 'access', _297 => _297.message, 'optionalAccess', _298 => _298.content]);
13336
+ if (role && content !== void 0) {
13337
+ promptMessages.push({ content, role });
12556
13338
  }
12557
13339
  }
12558
- );
12559
- return {
12560
- ...toolDef,
12561
- handler: wrappedHandler
12562
- };
12563
- }
12564
- function _buildLLMInput(prompt, conversationHistory) {
12565
- const promptMessage = typeof prompt === "string" ? { content: prompt, role: "user" } : void 0;
12566
- const inputParts = [
12567
- ...promptMessage ? [promptMessage] : [],
12568
- ...conversationHistory
12569
- ];
13340
+ }
13341
+ const inputParts = [...promptMessages, ...conversationHistory];
12570
13342
  return inputParts.length > 0 ? inputParts : void 0;
12571
13343
  }
13344
+ function _formatCapturedMessages(messages) {
13345
+ return messages.length > 0 ? messages : [];
13346
+ }
12572
13347
  function _extractUsageFromMessage(message) {
12573
13348
  const metrics = {};
12574
13349
  let usage;
12575
13350
  if (message.type === "assistant") {
12576
- usage = _optionalChain([message, 'access', _288 => _288.message, 'optionalAccess', _289 => _289.usage]);
13351
+ usage = _optionalChain([message, 'access', _299 => _299.message, 'optionalAccess', _300 => _300.usage]);
12577
13352
  } else if (message.type === "result") {
12578
13353
  usage = message.usage;
12579
13354
  }
@@ -12602,17 +13377,21 @@ function _extractUsageFromMessage(message) {
12602
13377
  }
12603
13378
  return metrics;
12604
13379
  }
12605
- async function _createLLMSpanForMessages(messages, prompt, conversationHistory, options, startTime, parentSpan) {
13380
+ async function _createLLMSpanForMessages(messages, prompt, conversationHistory, options, startTime, capturedPromptMessages, parentSpan) {
12606
13381
  if (messages.length === 0) return void 0;
12607
13382
  const lastMessage = messages[messages.length - 1];
12608
- if (lastMessage.type !== "assistant" || !_optionalChain([lastMessage, 'access', _290 => _290.message, 'optionalAccess', _291 => _291.usage])) {
13383
+ if (lastMessage.type !== "assistant" || !_optionalChain([lastMessage, 'access', _301 => _301.message, 'optionalAccess', _302 => _302.usage])) {
12609
13384
  return void 0;
12610
13385
  }
12611
13386
  const model = lastMessage.message.model || options.model;
12612
13387
  const usage = _extractUsageFromMessage(lastMessage);
12613
- const input = _buildLLMInput(prompt, conversationHistory);
13388
+ const input = _buildLLMInput(
13389
+ prompt,
13390
+ conversationHistory,
13391
+ capturedPromptMessages
13392
+ );
12614
13393
  const outputs = messages.map(
12615
- (m) => _optionalChain([m, 'access', _292 => _292.message, 'optionalAccess', _293 => _293.content]) && _optionalChain([m, 'access', _294 => _294.message, 'optionalAccess', _295 => _295.role]) ? { content: m.message.content, role: m.message.role } : void 0
13394
+ (m) => _optionalChain([m, 'access', _303 => _303.message, 'optionalAccess', _304 => _304.content]) && _optionalChain([m, 'access', _305 => _305.message, 'optionalAccess', _306 => _306.role]) ? { content: m.message.content, role: m.message.role } : void 0
12616
13395
  ).filter((c) => c !== void 0);
12617
13396
  await traced(
12618
13397
  (llmSpan) => {
@@ -12632,7 +13411,7 @@ async function _createLLMSpanForMessages(messages, prompt, conversationHistory,
12632
13411
  parent: parentSpan
12633
13412
  }
12634
13413
  );
12635
- return _optionalChain([lastMessage, 'access', _296 => _296.message, 'optionalAccess', _297 => _297.content]) && _optionalChain([lastMessage, 'access', _298 => _298.message, 'optionalAccess', _299 => _299.role]) ? { content: lastMessage.message.content, role: lastMessage.message.role } : void 0;
13414
+ return _optionalChain([lastMessage, 'access', _307 => _307.message, 'optionalAccess', _308 => _308.content]) && _optionalChain([lastMessage, 'access', _309 => _309.message, 'optionalAccess', _310 => _310.role]) ? { content: lastMessage.message.content, role: lastMessage.message.role } : void 0;
12636
13415
  }
12637
13416
  function wrapClaudeAgentSDK(sdk) {
12638
13417
  const cache = /* @__PURE__ */ new Map();
@@ -12651,25 +13430,9 @@ function wrapClaudeAgentSDK(sdk) {
12651
13430
  return wrappedQuery;
12652
13431
  }
12653
13432
  if (prop === "tool" && typeof value === "function") {
12654
- const toolFn = value;
12655
- const wrappedToolFactory = new Proxy(toolFn, {
12656
- apply(toolTarget, thisArg, argArray) {
12657
- const invocationTarget = thisArg === receiver || thisArg === void 0 ? target : thisArg;
12658
- const toolDef = Reflect.apply(
12659
- toolTarget,
12660
- invocationTarget,
12661
- argArray
12662
- );
12663
- if (toolDef && typeof toolDef === "object" && "handler" in toolDef) {
12664
- return wrapClaudeAgentTool(
12665
- toolDef
12666
- );
12667
- }
12668
- return toolDef;
12669
- }
12670
- });
12671
- cache.set(prop, wrappedToolFactory);
12672
- return wrappedToolFactory;
13433
+ const bound = value.bind(target);
13434
+ cache.set(prop, bound);
13435
+ return bound;
12673
13436
  }
12674
13437
  if (typeof value === "function") {
12675
13438
  const bound = value.bind(target);
@@ -12922,7 +13685,7 @@ function serializePart(part) {
12922
13685
  return part;
12923
13686
  }
12924
13687
  function serializeTools(params) {
12925
- if (!_optionalChain([params, 'access', _300 => _300.config, 'optionalAccess', _301 => _301.tools])) {
13688
+ if (!_optionalChain([params, 'access', _311 => _311.config, 'optionalAccess', _312 => _312.tools])) {
12926
13689
  return null;
12927
13690
  }
12928
13691
  try {
@@ -13005,7 +13768,7 @@ function aggregateGenerateContentChunks(chunks, start, firstTokenTime) {
13005
13768
  }
13006
13769
  if (chunk.candidates && Array.isArray(chunk.candidates)) {
13007
13770
  for (const candidate of chunk.candidates) {
13008
- if (_optionalChain([candidate, 'access', _302 => _302.content, 'optionalAccess', _303 => _303.parts])) {
13771
+ if (_optionalChain([candidate, 'access', _313 => _313.content, 'optionalAccess', _314 => _314.parts])) {
13009
13772
  for (const part of candidate.content.parts) {
13010
13773
  if (part.text !== void 0) {
13011
13774
  if (part.thought) {
@@ -13036,7 +13799,7 @@ function aggregateGenerateContentChunks(chunks, start, firstTokenTime) {
13036
13799
  parts.push({ text });
13037
13800
  }
13038
13801
  parts.push(...otherParts);
13039
- if (parts.length > 0 && _optionalChain([lastResponse, 'optionalAccess', _304 => _304.candidates])) {
13802
+ if (parts.length > 0 && _optionalChain([lastResponse, 'optionalAccess', _315 => _315.candidates])) {
13040
13803
  const candidates = [];
13041
13804
  for (const candidate of lastResponse.candidates) {
13042
13805
  const candidateDict = {
@@ -13116,15 +13879,15 @@ __export(graph_framework_exports, {
13116
13879
  escapePath: () => escapePath,
13117
13880
  unescapePath: () => unescapePath
13118
13881
  });
13119
- var GraphBuilder = (_class15 = class {
13120
- __init58() {this.nodes = /* @__PURE__ */ new Map()}
13121
- __init59() {this.edges = {}}
13122
- __init60() {this.nodeLikeNodes = /* @__PURE__ */ new Map()}
13882
+ var GraphBuilder = (_class16 = class {
13883
+ __init60() {this.nodes = /* @__PURE__ */ new Map()}
13884
+ __init61() {this.edges = {}}
13885
+ __init62() {this.nodeLikeNodes = /* @__PURE__ */ new Map()}
13123
13886
  // Maps node-like objects, like prompts, to their nodes
13124
13887
  // Special nodes
13125
13888
 
13126
13889
 
13127
- constructor() {;_class15.prototype.__init58.call(this);_class15.prototype.__init59.call(this);_class15.prototype.__init60.call(this);
13890
+ constructor() {;_class16.prototype.__init60.call(this);_class16.prototype.__init61.call(this);_class16.prototype.__init62.call(this);
13128
13891
  this.IN = this.createInputNode();
13129
13892
  this.OUT = this.createOutputNode();
13130
13893
  }
@@ -13254,7 +14017,7 @@ var GraphBuilder = (_class15 = class {
13254
14017
  this.nodes.set(id, promptNode);
13255
14018
  return promptNode;
13256
14019
  }
13257
- }, _class15);
14020
+ }, _class16);
13258
14021
  function isProxyVariable(node) {
13259
14022
  return typeof node === "object" && node !== null && "__type" in node && // @ts-ignore
13260
14023
  node.__type === "proxy-variable";
@@ -13262,17 +14025,17 @@ function isProxyVariable(node) {
13262
14025
  function proxyVariableToNode(proxy) {
13263
14026
  return [proxy.__node, proxy.__path];
13264
14027
  }
13265
- var BaseNode = (_class16 = class {
13266
- constructor(graph, id) {;_class16.prototype.__init61.call(this);_class16.prototype.__init62.call(this);
14028
+ var BaseNode = (_class17 = class {
14029
+ constructor(graph, id) {;_class17.prototype.__init63.call(this);_class17.prototype.__init64.call(this);
13267
14030
  this.graph = graph;
13268
14031
  this.id = id;
13269
14032
  }
13270
- __init61() {this.__type = "node"}
13271
- __init62() {this.dependencies = []}
14033
+ __init63() {this.__type = "node"}
14034
+ __init64() {this.dependencies = []}
13272
14035
  addDependency(dependency) {
13273
14036
  this.dependencies.push(dependency);
13274
14037
  }
13275
- }, _class16);
14038
+ }, _class17);
13276
14039
  var InputNode = class extends BaseNode {
13277
14040
  constructor(graph, id) {
13278
14041
  super(graph, id);
@@ -13454,7 +14217,7 @@ function isAsync(fn) {
13454
14217
  function isAsyncGenerator2(fn) {
13455
14218
  return fn[Symbol.toStringTag] === "AsyncGenerator";
13456
14219
  }
13457
- function isAsyncIterable(obj) {
14220
+ function isAsyncIterable2(obj) {
13458
14221
  return typeof obj[Symbol.asyncIterator] === "function";
13459
14222
  }
13460
14223
  function wrapAsync(asyncFn) {
@@ -13625,7 +14388,7 @@ var eachOfLimit$2 = (limit) => {
13625
14388
  if (isAsyncGenerator2(obj)) {
13626
14389
  return asyncEachOfLimit(obj, limit, iteratee, callback);
13627
14390
  }
13628
- if (isAsyncIterable(obj)) {
14391
+ if (isAsyncIterable2(obj)) {
13629
14392
  return asyncEachOfLimit(obj[Symbol.asyncIterator](), limit, iteratee, callback);
13630
14393
  }
13631
14394
  var nextElem = createIterator(obj);
@@ -14474,11 +15237,11 @@ var SpanFetcher = class _SpanFetcher extends ObjectFetcher {
14474
15237
  return this._state;
14475
15238
  }
14476
15239
  };
14477
- var CachedSpanFetcher = (_class17 = class {
14478
- __init63() {this.spanCache = /* @__PURE__ */ new Map()}
14479
- __init64() {this.allFetched = false}
15240
+ var CachedSpanFetcher = (_class18 = class {
15241
+ __init65() {this.spanCache = /* @__PURE__ */ new Map()}
15242
+ __init66() {this.allFetched = false}
14480
15243
 
14481
- constructor(objectTypeOrFetchFn, objectId, rootSpanId, getState) {;_class17.prototype.__init63.call(this);_class17.prototype.__init64.call(this);
15244
+ constructor(objectTypeOrFetchFn, objectId, rootSpanId, getState) {;_class18.prototype.__init65.call(this);_class18.prototype.__init66.call(this);
14482
15245
  if (typeof objectTypeOrFetchFn === "function") {
14483
15246
  this.fetchFn = objectTypeOrFetchFn;
14484
15247
  } else {
@@ -14493,7 +15256,7 @@ var CachedSpanFetcher = (_class17 = class {
14493
15256
  spanType
14494
15257
  );
14495
15258
  const rows = await fetcher.fetchedData();
14496
- return rows.filter((row) => _optionalChain([row, 'access', _305 => _305.span_attributes, 'optionalAccess', _306 => _306.purpose]) !== "scorer").map((row) => ({
15259
+ return rows.filter((row) => _optionalChain([row, 'access', _316 => _316.span_attributes, 'optionalAccess', _317 => _317.purpose]) !== "scorer").map((row) => ({
14497
15260
  input: row.input,
14498
15261
  output: row.output,
14499
15262
  metadata: row.metadata,
@@ -14527,7 +15290,7 @@ var CachedSpanFetcher = (_class17 = class {
14527
15290
  async fetchSpans(spanType) {
14528
15291
  const spans = await this.fetchFn(spanType);
14529
15292
  for (const span of spans) {
14530
- const type = _nullishCoalesce(_optionalChain([span, 'access', _307 => _307.span_attributes, 'optionalAccess', _308 => _308.type]), () => ( ""));
15293
+ const type = _nullishCoalesce(_optionalChain([span, 'access', _318 => _318.span_attributes, 'optionalAccess', _319 => _319.type]), () => ( ""));
14531
15294
  const existing = _nullishCoalesce(this.spanCache.get(type), () => ( []));
14532
15295
  existing.push(span);
14533
15296
  this.spanCache.set(type, existing);
@@ -14544,23 +15307,24 @@ var CachedSpanFetcher = (_class17 = class {
14544
15307
  }
14545
15308
  return result;
14546
15309
  }
14547
- }, _class17);
14548
- var LocalTrace = (_class18 = class {
15310
+ }, _class18);
15311
+ var LocalTrace = (_class19 = class {
14549
15312
 
14550
15313
 
14551
15314
 
14552
15315
 
14553
15316
 
14554
- __init65() {this.spansFlushed = false}
14555
- __init66() {this.spansFlushPromise = null}
15317
+ __init67() {this.spansFlushed = false}
15318
+ __init68() {this.spansFlushPromise = null}
14556
15319
 
15320
+ __init69() {this.threadCache = /* @__PURE__ */ new Map()}
14557
15321
  constructor({
14558
15322
  objectType,
14559
15323
  objectId,
14560
15324
  rootSpanId,
14561
15325
  ensureSpansFlushed,
14562
15326
  state
14563
- }) {;_class18.prototype.__init65.call(this);_class18.prototype.__init66.call(this);
15327
+ }) {;_class19.prototype.__init67.call(this);_class19.prototype.__init68.call(this);_class19.prototype.__init69.call(this);
14564
15328
  this.objectType = objectType;
14565
15329
  this.objectId = objectId;
14566
15330
  this.rootSpanId = rootSpanId;
@@ -14606,11 +15370,11 @@ var LocalTrace = (_class18 = class {
14606
15370
  const cachedSpans = this.state.spanCache.getByRootSpanId(this.rootSpanId);
14607
15371
  if (cachedSpans && cachedSpans.length > 0) {
14608
15372
  let spans = cachedSpans.filter(
14609
- (span) => _optionalChain([span, 'access', _309 => _309.span_attributes, 'optionalAccess', _310 => _310.purpose]) !== "scorer"
15373
+ (span) => _optionalChain([span, 'access', _320 => _320.span_attributes, 'optionalAccess', _321 => _321.purpose]) !== "scorer"
14610
15374
  );
14611
15375
  if (spanType && spanType.length > 0) {
14612
15376
  spans = spans.filter(
14613
- (span) => spanType.includes(_nullishCoalesce(_optionalChain([span, 'access', _311 => _311.span_attributes, 'optionalAccess', _312 => _312.type]), () => ( "")))
15377
+ (span) => spanType.includes(_nullishCoalesce(_optionalChain([span, 'access', _322 => _322.span_attributes, 'optionalAccess', _323 => _323.type]), () => ( "")))
14614
15378
  );
14615
15379
  }
14616
15380
  return spans.map((span) => ({
@@ -14624,6 +15388,36 @@ var LocalTrace = (_class18 = class {
14624
15388
  }
14625
15389
  return this.cachedFetcher.getSpans({ spanType });
14626
15390
  }
15391
+ /**
15392
+ * Get the thread (preprocessed messages) for this trace.
15393
+ * Calls the API with the project_default preprocessor (which falls back to "thread").
15394
+ */
15395
+ async getThread(options) {
15396
+ const cacheKey = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _324 => _324.preprocessor]), () => ( "project_default"));
15397
+ if (!this.threadCache.has(cacheKey)) {
15398
+ const promise = this.fetchThread(options);
15399
+ this.threadCache.set(cacheKey, promise);
15400
+ }
15401
+ return this.threadCache.get(cacheKey);
15402
+ }
15403
+ async fetchThread(options) {
15404
+ await this.ensureSpansReady();
15405
+ await this.state.login({});
15406
+ const result = await invoke({
15407
+ globalFunction: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _325 => _325.preprocessor]), () => ( "project_default")),
15408
+ functionType: "preprocessor",
15409
+ input: {
15410
+ trace_ref: {
15411
+ object_type: this.objectType,
15412
+ object_id: this.objectId,
15413
+ root_span_id: this.rootSpanId
15414
+ }
15415
+ },
15416
+ mode: "json",
15417
+ state: this.state
15418
+ });
15419
+ return Array.isArray(result) ? result : [];
15420
+ }
14627
15421
  async ensureSpansReady() {
14628
15422
  if (this.spansFlushed || !this.ensureSpansFlushed) {
14629
15423
  return;
@@ -14641,7 +15435,7 @@ var LocalTrace = (_class18 = class {
14641
15435
  }
14642
15436
  await this.spansFlushPromise;
14643
15437
  }
14644
- }, _class18);
15438
+ }, _class19);
14645
15439
 
14646
15440
  // src/reporters/progress.ts
14647
15441
  var SimpleProgressReporter = class {
@@ -14658,248 +15452,10 @@ var SimpleProgressReporter = class {
14658
15452
 
14659
15453
  // src/eval-parameters.ts
14660
15454
 
15455
+ var _ajv = require('ajv'); var _ajv2 = _interopRequireDefault(_ajv);
14661
15456
 
14662
- // src/framework2.ts
15457
+ // src/prompt-schemas.ts
14663
15458
 
14664
- var currentFilename = typeof __filename !== "undefined" ? __filename : "unknown";
14665
- var ProjectBuilder = class {
14666
- create(opts) {
14667
- return new Project2(opts);
14668
- }
14669
- };
14670
- var projects = new ProjectBuilder();
14671
- var Project2 = (_class19 = class {
14672
-
14673
-
14674
-
14675
-
14676
-
14677
- __init67() {this._publishableCodeFunctions = []}
14678
- __init68() {this._publishablePrompts = []}
14679
- constructor(args) {;_class19.prototype.__init67.call(this);_class19.prototype.__init68.call(this);
14680
- _initializeSpanContext();
14681
- this.name = "name" in args ? args.name : void 0;
14682
- this.id = "id" in args ? args.id : void 0;
14683
- this.tools = new ToolBuilder(this);
14684
- this.prompts = new PromptBuilder(this);
14685
- this.scorers = new ScorerBuilder(this);
14686
- }
14687
- addPrompt(prompt) {
14688
- this._publishablePrompts.push(prompt);
14689
- if (globalThis._lazy_load) {
14690
- globalThis._evals.prompts.push(prompt);
14691
- }
14692
- }
14693
- addCodeFunction(fn) {
14694
- this._publishableCodeFunctions.push(fn);
14695
- if (globalThis._lazy_load) {
14696
- globalThis._evals.functions.push(fn);
14697
- }
14698
- }
14699
- async publish() {
14700
- if (globalThis._lazy_load) {
14701
- console.warn("publish() is a no-op when running `braintrust push`.");
14702
- return;
14703
- }
14704
- await login();
14705
- const projectMap = new ProjectNameIdMap();
14706
- const functionDefinitions = [];
14707
- if (this._publishableCodeFunctions.length > 0) {
14708
- console.warn(
14709
- "Code functions cannot be published directly. Use `braintrust push` instead."
14710
- );
14711
- }
14712
- if (this._publishablePrompts.length > 0) {
14713
- for (const prompt of this._publishablePrompts) {
14714
- const functionDefinition = await prompt.toFunctionDefinition(projectMap);
14715
- functionDefinitions.push(functionDefinition);
14716
- }
14717
- }
14718
- await _internalGetGlobalState().apiConn().post_json("insert-functions", {
14719
- functions: functionDefinitions
14720
- });
14721
- }
14722
- }, _class19);
14723
- var ToolBuilder = (_class20 = class {
14724
- constructor(project) {;_class20.prototype.__init69.call(this);
14725
- this.project = project;
14726
- }
14727
- __init69() {this.taskCounter = 0}
14728
- // This type definition is just a catch all so that the implementation can be
14729
- // less specific than the two more specific declarations above.
14730
- create(opts) {
14731
- this.taskCounter++;
14732
- opts = _nullishCoalesce(opts, () => ( {}));
14733
- const { handler, name, slug, parameters, returns, ...rest } = opts;
14734
- let resolvedName = _nullishCoalesce(name, () => ( handler.name));
14735
- if (resolvedName.trim().length === 0) {
14736
- resolvedName = `Tool ${isomorph_default.basename(currentFilename)} ${this.taskCounter}`;
14737
- }
14738
- const tool = new CodeFunction(this.project, {
14739
- handler,
14740
- name: resolvedName,
14741
- slug: _nullishCoalesce(slug, () => ( slugify(resolvedName, { lower: true, strict: true }))),
14742
- type: "tool",
14743
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/consistent-type-assertions
14744
- parameters,
14745
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/consistent-type-assertions
14746
- returns,
14747
- ...rest
14748
- });
14749
- this.project.addCodeFunction(tool);
14750
- return tool;
14751
- }
14752
- }, _class20);
14753
- var ScorerBuilder = (_class21 = class {
14754
- constructor(project) {;_class21.prototype.__init70.call(this);
14755
- this.project = project;
14756
- }
14757
- __init70() {this.taskCounter = 0}
14758
- create(opts) {
14759
- this.taskCounter++;
14760
- let resolvedName = opts.name;
14761
- if (!resolvedName && "handler" in opts) {
14762
- resolvedName = opts.handler.name;
14763
- }
14764
- if (!resolvedName || resolvedName.trim().length === 0) {
14765
- resolvedName = `Scorer ${isomorph_default.basename(currentFilename)} ${this.taskCounter}`;
14766
- }
14767
- const slug = _nullishCoalesce(opts.slug, () => ( slugify(resolvedName, { lower: true, strict: true })));
14768
- if ("handler" in opts) {
14769
- const scorer = new CodeFunction(this.project, {
14770
- ...opts,
14771
- name: resolvedName,
14772
- slug,
14773
- type: "scorer"
14774
- });
14775
- this.project.addCodeFunction(scorer);
14776
- } else {
14777
- const promptBlock = "messages" in opts ? {
14778
- type: "chat",
14779
- messages: opts.messages
14780
- } : {
14781
- type: "completion",
14782
- content: opts.prompt
14783
- };
14784
- const promptData = {
14785
- prompt: promptBlock,
14786
- options: {
14787
- model: opts.model,
14788
- params: opts.params
14789
- },
14790
- parser: {
14791
- type: "llm_classifier",
14792
- use_cot: opts.useCot,
14793
- choice_scores: opts.choiceScores
14794
- }
14795
- };
14796
- const codePrompt = new CodePrompt(
14797
- this.project,
14798
- promptData,
14799
- [],
14800
- {
14801
- ...opts,
14802
- name: resolvedName,
14803
- slug
14804
- },
14805
- "scorer"
14806
- );
14807
- this.project.addPrompt(codePrompt);
14808
- }
14809
- }
14810
- }, _class21);
14811
- var CodeFunction = class {
14812
- constructor(project, opts) {
14813
- this.project = project;
14814
- this.handler = opts.handler;
14815
- this.name = opts.name;
14816
- this.slug = opts.slug;
14817
- this.description = opts.description;
14818
- this.type = opts.type;
14819
- this.ifExists = opts.ifExists;
14820
- this.metadata = opts.metadata;
14821
- this.parameters = opts.parameters;
14822
- this.returns = opts.returns;
14823
- if (this.returns && !this.parameters) {
14824
- throw new Error("parameters are required if return type is defined");
14825
- }
14826
- }
14827
-
14828
-
14829
-
14830
-
14831
-
14832
-
14833
-
14834
-
14835
-
14836
- key() {
14837
- return JSON.stringify([
14838
- _nullishCoalesce(this.project.id, () => ( "")),
14839
- _nullishCoalesce(this.project.name, () => ( "")),
14840
- this.slug
14841
- ]);
14842
- }
14843
- };
14844
- var CodePrompt = class {
14845
-
14846
-
14847
-
14848
-
14849
-
14850
-
14851
-
14852
-
14853
-
14854
-
14855
- constructor(project, prompt, toolFunctions, opts, functionType) {
14856
- this.project = project;
14857
- this.name = opts.name;
14858
- this.slug = opts.slug;
14859
- this.prompt = prompt;
14860
- this.toolFunctions = toolFunctions;
14861
- this.ifExists = opts.ifExists;
14862
- this.description = opts.description;
14863
- this.id = opts.id;
14864
- this.functionType = functionType;
14865
- this.metadata = opts.metadata;
14866
- }
14867
- async toFunctionDefinition(projectNameToId) {
14868
- const prompt_data = {
14869
- ...this.prompt
14870
- };
14871
- if (this.toolFunctions.length > 0) {
14872
- const resolvableToolFunctions = await Promise.all(
14873
- this.toolFunctions.map(async (fn) => {
14874
- if ("slug" in fn) {
14875
- return {
14876
- type: "slug",
14877
- project_id: await projectNameToId.resolve(fn.project),
14878
- slug: fn.slug
14879
- };
14880
- } else {
14881
- return fn;
14882
- }
14883
- })
14884
- );
14885
- prompt_data.tool_functions = // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
14886
- resolvableToolFunctions;
14887
- }
14888
- return {
14889
- project_id: await projectNameToId.resolve(this.project),
14890
- name: this.name,
14891
- slug: this.slug,
14892
- description: _nullishCoalesce(this.description, () => ( "")),
14893
- function_data: {
14894
- type: "prompt"
14895
- },
14896
- function_type: this.functionType,
14897
- prompt_data,
14898
- if_exists: this.ifExists,
14899
- metadata: this.metadata
14900
- };
14901
- }
14902
- };
14903
15459
  var promptContentsSchema = _v3.z.union([
14904
15460
  _v3.z.object({
14905
15461
  prompt: _v3.z.string()
@@ -14920,46 +15476,6 @@ var promptDefinitionWithToolsSchema = promptDefinitionSchema.and(
14920
15476
  tools: _v3.z.array(ToolFunctionDefinition).optional()
14921
15477
  })
14922
15478
  );
14923
- var PromptBuilder = class {
14924
- constructor(project) {
14925
- this.project = project;
14926
- }
14927
- create(opts) {
14928
- const toolFunctions = [];
14929
- const rawTools = [];
14930
- for (const tool of _nullishCoalesce(opts.tools, () => ( []))) {
14931
- if (tool instanceof CodeFunction) {
14932
- toolFunctions.push(tool);
14933
- } else if ("type" in tool && !("function" in tool)) {
14934
- toolFunctions.push(tool);
14935
- } else {
14936
- rawTools.push(tool);
14937
- }
14938
- }
14939
- const slug = _nullishCoalesce(opts.slug, () => ( slugify(opts.name, { lower: true, strict: true })));
14940
- const promptData = promptDefinitionToPromptData(opts, rawTools);
14941
- const promptRow = {
14942
- id: opts.id,
14943
- _xact_id: opts.version ? loadPrettyXact(opts.version) : void 0,
14944
- name: opts.name,
14945
- slug,
14946
- prompt_data: promptData,
14947
- ...this.project.id !== void 0 ? { project_id: this.project.id } : {}
14948
- };
14949
- const prompt = new Prompt2(
14950
- promptRow,
14951
- {},
14952
- // It doesn't make sense to specify defaults here.
14953
- _nullishCoalesce(opts.noTrace, () => ( false))
14954
- );
14955
- const codePrompt = new CodePrompt(this.project, promptData, toolFunctions, {
14956
- ...opts,
14957
- slug
14958
- });
14959
- this.project.addPrompt(codePrompt);
14960
- return prompt;
14961
- }
14962
- };
14963
15479
  function promptDefinitionToPromptData(promptDefinition, rawTools) {
14964
15480
  const promptBlock = "messages" in promptDefinition ? {
14965
15481
  type: "chat",
@@ -14978,42 +15494,6 @@ function promptDefinitionToPromptData(promptDefinition, rawTools) {
14978
15494
  ...promptDefinition.templateFormat ? { template_format: promptDefinition.templateFormat } : {}
14979
15495
  };
14980
15496
  }
14981
- var ProjectNameIdMap = (_class22 = class {constructor() { _class22.prototype.__init71.call(this);_class22.prototype.__init72.call(this); }
14982
- __init71() {this.nameToId = {}}
14983
- __init72() {this.idToName = {}}
14984
- async getId(projectName) {
14985
- if (!(projectName in this.nameToId)) {
14986
- const response = await _internalGetGlobalState().appConn().post_json("api/project/register", {
14987
- project_name: projectName
14988
- });
14989
- const result = _v3.z.object({
14990
- project: Project
14991
- }).parse(response);
14992
- const projectId = result.project.id;
14993
- this.nameToId[projectName] = projectId;
14994
- this.idToName[projectId] = projectName;
14995
- }
14996
- return this.nameToId[projectName];
14997
- }
14998
- async getName(projectId) {
14999
- if (!(projectId in this.idToName)) {
15000
- const response = await _internalGetGlobalState().appConn().post_json("api/project/get", {
15001
- id: projectId
15002
- });
15003
- const result = _v3.z.array(Project).nonempty().parse(response);
15004
- const projectName = result[0].name;
15005
- this.idToName[projectId] = projectName;
15006
- this.nameToId[projectName] = projectId;
15007
- }
15008
- return this.idToName[projectId];
15009
- }
15010
- async resolve(project) {
15011
- if (project.id) {
15012
- return project.id;
15013
- }
15014
- return this.getId(project.name);
15015
- }
15016
- }, _class22);
15017
15497
 
15018
15498
  // src/eval-parameters.ts
15019
15499
  var evalParametersSchema = _v3.z.record(
@@ -15028,7 +15508,31 @@ var evalParametersSchema = _v3.z.record(
15028
15508
  // For Zod schemas
15029
15509
  ])
15030
15510
  );
15031
- function validateParameters(parameters, parameterSchema) {
15511
+ async function validateParameters(parameters, parameterSchema) {
15512
+ let resolvedSchema = parameterSchema;
15513
+ if (resolvedSchema instanceof Promise) {
15514
+ resolvedSchema = await resolvedSchema;
15515
+ }
15516
+ if (resolvedSchema === void 0 || resolvedSchema === null) {
15517
+ return parameters;
15518
+ }
15519
+ if (RemoteEvalParameters.isParameters(resolvedSchema)) {
15520
+ const mergedParameters = parameters && Object.keys(parameters).length > 0 ? {
15521
+ ...resolvedSchema.data,
15522
+ ...parameters
15523
+ } : resolvedSchema.data;
15524
+ return validateParametersWithJsonSchema(
15525
+ mergedParameters,
15526
+ resolvedSchema.schema
15527
+ );
15528
+ }
15529
+ return validateParametersWithZod(
15530
+ parameters,
15531
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
15532
+ resolvedSchema
15533
+ );
15534
+ }
15535
+ function validateParametersWithZod(parameters, parameterSchema) {
15032
15536
  return Object.fromEntries(
15033
15537
  Object.entries(parameterSchema).map(([name, schema]) => {
15034
15538
  const value = parameters[name];
@@ -15055,6 +15559,18 @@ function validateParameters(parameters, parameterSchema) {
15055
15559
  })
15056
15560
  );
15057
15561
  }
15562
+ function validateParametersWithJsonSchema(parameters, schema) {
15563
+ const ajv = new (0, _ajv2.default)({ coerceTypes: true, useDefaults: true, strict: false });
15564
+ const validate = ajv.compile(schema);
15565
+ if (!validate(parameters)) {
15566
+ const errorMessages = _optionalChain([validate, 'access', _326 => _326.errors, 'optionalAccess', _327 => _327.map, 'call', _328 => _328((err) => {
15567
+ const path2 = err.instancePath || "root";
15568
+ return `${path2}: ${err.message}`;
15569
+ }), 'access', _329 => _329.join, 'call', _330 => _330(", ")]);
15570
+ throw Error(`Invalid parameters: ${errorMessages}`);
15571
+ }
15572
+ return parameters;
15573
+ }
15058
15574
 
15059
15575
  // src/framework.ts
15060
15576
  function BaseExperiment(options = {}) {
@@ -15106,7 +15622,7 @@ function callEvaluatorData(data) {
15106
15622
  baseExperiment
15107
15623
  };
15108
15624
  }
15109
- function isAsyncIterable2(value) {
15625
+ function isAsyncIterable3(value) {
15110
15626
  return typeof value === "object" && value !== null && typeof value[Symbol.asyncIterator] === "function";
15111
15627
  }
15112
15628
  function isIterable(value) {
@@ -15115,6 +15631,7 @@ function isIterable(value) {
15115
15631
  globalThis._evals = {
15116
15632
  functions: [],
15117
15633
  prompts: [],
15634
+ parameters: [],
15118
15635
  evaluators: {},
15119
15636
  reporters: {}
15120
15637
  };
@@ -15290,16 +15807,16 @@ var defaultErrorScoreHandler = ({
15290
15807
  };
15291
15808
  async function runEvaluatorInternal(experiment, evaluator, progressReporter, filters, stream, parameters, collectResults, enableCache) {
15292
15809
  if (enableCache) {
15293
- _optionalChain([(_nullishCoalesce(evaluator.state, () => ( _internalGetGlobalState()))), 'optionalAccess', _313 => _313.spanCache, 'optionalAccess', _314 => _314.start, 'call', _315 => _315()]);
15810
+ _optionalChain([(_nullishCoalesce(evaluator.state, () => ( _internalGetGlobalState()))), 'optionalAccess', _331 => _331.spanCache, 'optionalAccess', _332 => _332.start, 'call', _333 => _333()]);
15294
15811
  }
15295
15812
  try {
15296
15813
  if (typeof evaluator.data === "string") {
15297
15814
  throw new Error("Unimplemented: string data paths");
15298
15815
  }
15299
15816
  let dataResult = typeof evaluator.data === "function" ? evaluator.data() : evaluator.data;
15300
- parameters = validateParameters(
15817
+ parameters = await validateParameters(
15301
15818
  _nullishCoalesce(parameters, () => ( {})),
15302
- _nullishCoalesce(evaluator.parameters, () => ( {}))
15819
+ evaluator.parameters
15303
15820
  );
15304
15821
  if ("_type" in dataResult) {
15305
15822
  if (dataResult._type !== "BaseExperiment") {
@@ -15326,7 +15843,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
15326
15843
  }
15327
15844
  const resolvedDataResult = dataResult instanceof Promise ? await dataResult : dataResult;
15328
15845
  const dataIterable = (() => {
15329
- if (isAsyncIterable2(resolvedDataResult)) {
15846
+ if (isAsyncIterable3(resolvedDataResult)) {
15330
15847
  return resolvedDataResult;
15331
15848
  }
15332
15849
  if (Array.isArray(resolvedDataResult) || isIterable(resolvedDataResult)) {
@@ -15401,7 +15918,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
15401
15918
  objectType: parentComponents ? spanObjectTypeV3ToTypedString(
15402
15919
  parentComponents.data.object_type
15403
15920
  ) : "experiment",
15404
- objectId: await _asyncNullishCoalesce(await _asyncOptionalChain([parentComponents, 'optionalAccess', async _316 => _316.data, 'access', async _317 => _317.object_id]), async () => ( (experimentIdPromise ? await _asyncNullishCoalesce(await experimentIdPromise, async () => ( "")) : ""))),
15921
+ objectId: await _asyncNullishCoalesce(await _asyncOptionalChain([parentComponents, 'optionalAccess', async _334 => _334.data, 'access', async _335 => _335.object_id]), async () => ( (experimentIdPromise ? await _asyncNullishCoalesce(await experimentIdPromise, async () => ( "")) : ""))),
15405
15922
  rootSpanId: rootSpan.rootSpanId,
15406
15923
  ensureSpansFlushed,
15407
15924
  state
@@ -15427,10 +15944,10 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
15427
15944
  span,
15428
15945
  parameters: _nullishCoalesce(parameters, () => ( {})),
15429
15946
  reportProgress: (event) => {
15430
- _optionalChain([stream, 'optionalCall', _318 => _318({
15947
+ _optionalChain([stream, 'optionalCall', _336 => _336({
15431
15948
  ...event,
15432
15949
  id: rootSpan.id,
15433
- origin: _optionalChain([baseEvent, 'access', _319 => _319.event, 'optionalAccess', _320 => _320.origin]),
15950
+ origin: _optionalChain([baseEvent, 'access', _337 => _337.event, 'optionalAccess', _338 => _338.origin]),
15434
15951
  name: evaluator.evalName,
15435
15952
  object_type: "task"
15436
15953
  })]);
@@ -15458,6 +15975,9 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
15458
15975
  } else {
15459
15976
  rootSpan.log({ output, metadata, expected });
15460
15977
  }
15978
+ if (evaluator.flushBeforeScoring) {
15979
+ await rootSpan.flush();
15980
+ }
15461
15981
  const scoringArgs = {
15462
15982
  input: datum.input,
15463
15983
  expected: "expected" in datum ? datum.expected : void 0,
@@ -15591,7 +16111,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
15591
16111
  metadata,
15592
16112
  scores: mergedScores,
15593
16113
  error,
15594
- origin: _optionalChain([baseEvent, 'access', _321 => _321.event, 'optionalAccess', _322 => _322.origin])
16114
+ origin: _optionalChain([baseEvent, 'access', _339 => _339.event, 'optionalAccess', _340 => _340.origin])
15595
16115
  });
15596
16116
  }
15597
16117
  };
@@ -15624,7 +16144,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
15624
16144
  break;
15625
16145
  }
15626
16146
  scheduledTrials++;
15627
- _optionalChain([progressReporter, 'access', _323 => _323.setTotal, 'optionalCall', _324 => _324(evaluator.evalName, scheduledTrials)]);
16147
+ _optionalChain([progressReporter, 'access', _341 => _341.setTotal, 'optionalCall', _342 => _342(evaluator.evalName, scheduledTrials)]);
15628
16148
  q.push({ datum, trialIndex });
15629
16149
  }
15630
16150
  }
@@ -15699,9 +16219,9 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
15699
16219
  );
15700
16220
  } finally {
15701
16221
  if (enableCache) {
15702
- const spanCache = _optionalChain([(_nullishCoalesce(evaluator.state, () => ( _internalGetGlobalState()))), 'optionalAccess', _325 => _325.spanCache]);
15703
- _optionalChain([spanCache, 'optionalAccess', _326 => _326.dispose, 'call', _327 => _327()]);
15704
- _optionalChain([spanCache, 'optionalAccess', _328 => _328.stop, 'call', _329 => _329()]);
16222
+ const spanCache = _optionalChain([(_nullishCoalesce(evaluator.state, () => ( _internalGetGlobalState()))), 'optionalAccess', _343 => _343.spanCache]);
16223
+ _optionalChain([spanCache, 'optionalAccess', _344 => _344.dispose, 'call', _345 => _345()]);
16224
+ _optionalChain([spanCache, 'optionalAccess', _346 => _346.stop, 'call', _347 => _347()]);
15705
16225
  }
15706
16226
  }
15707
16227
  }
@@ -15865,6 +16385,417 @@ var defaultReporter = {
15865
16385
  }
15866
16386
  };
15867
16387
 
16388
+ // src/framework2.ts
16389
+
16390
+ var currentFilename = typeof __filename !== "undefined" ? __filename : "unknown";
16391
+ var ProjectBuilder = class {
16392
+ create(opts) {
16393
+ return new Project2(opts);
16394
+ }
16395
+ };
16396
+ var projects = new ProjectBuilder();
16397
+ var Project2 = (_class20 = class {
16398
+
16399
+
16400
+
16401
+
16402
+
16403
+
16404
+ __init70() {this._publishableCodeFunctions = []}
16405
+ __init71() {this._publishablePrompts = []}
16406
+ __init72() {this._publishableParameters = []}
16407
+ constructor(args) {;_class20.prototype.__init70.call(this);_class20.prototype.__init71.call(this);_class20.prototype.__init72.call(this);
16408
+ _initializeSpanContext();
16409
+ this.name = "name" in args ? args.name : void 0;
16410
+ this.id = "id" in args ? args.id : void 0;
16411
+ this.tools = new ToolBuilder(this);
16412
+ this.prompts = new PromptBuilder(this);
16413
+ this.parameters = new ParametersBuilder(this);
16414
+ this.scorers = new ScorerBuilder(this);
16415
+ }
16416
+ addPrompt(prompt) {
16417
+ this._publishablePrompts.push(prompt);
16418
+ if (globalThis._lazy_load) {
16419
+ globalThis._evals.prompts.push(prompt);
16420
+ }
16421
+ }
16422
+ addParameters(parameters) {
16423
+ this._publishableParameters.push(parameters);
16424
+ if (globalThis._lazy_load) {
16425
+ if (globalThis._evals.parameters == null)
16426
+ globalThis._evals.parameters = [];
16427
+ globalThis._evals.parameters.push(parameters);
16428
+ }
16429
+ }
16430
+ addCodeFunction(fn) {
16431
+ this._publishableCodeFunctions.push(fn);
16432
+ if (globalThis._lazy_load) {
16433
+ globalThis._evals.functions.push(fn);
16434
+ }
16435
+ }
16436
+ async publish() {
16437
+ if (globalThis._lazy_load) {
16438
+ console.warn("publish() is a no-op when running `braintrust push`.");
16439
+ return;
16440
+ }
16441
+ await login();
16442
+ const projectMap = new ProjectNameIdMap();
16443
+ const functionDefinitions = [];
16444
+ if (this._publishableCodeFunctions.length > 0) {
16445
+ console.warn(
16446
+ "Code functions cannot be published directly. Use `braintrust push` instead."
16447
+ );
16448
+ }
16449
+ if (this._publishablePrompts.length > 0) {
16450
+ for (const prompt of this._publishablePrompts) {
16451
+ const functionDefinition = await prompt.toFunctionDefinition(projectMap);
16452
+ functionDefinitions.push(functionDefinition);
16453
+ }
16454
+ }
16455
+ await _internalGetGlobalState().apiConn().post_json("insert-functions", {
16456
+ functions: functionDefinitions
16457
+ });
16458
+ }
16459
+ }, _class20);
16460
+ var ToolBuilder = (_class21 = class {
16461
+ constructor(project) {;_class21.prototype.__init73.call(this);
16462
+ this.project = project;
16463
+ }
16464
+ __init73() {this.taskCounter = 0}
16465
+ // This type definition is just a catch all so that the implementation can be
16466
+ // less specific than the two more specific declarations above.
16467
+ create(opts) {
16468
+ this.taskCounter++;
16469
+ opts = _nullishCoalesce(opts, () => ( {}));
16470
+ const { handler, name, slug, parameters, returns, ...rest } = opts;
16471
+ let resolvedName = _nullishCoalesce(name, () => ( handler.name));
16472
+ if (resolvedName.trim().length === 0) {
16473
+ resolvedName = `Tool ${isomorph_default.basename(currentFilename)} ${this.taskCounter}`;
16474
+ }
16475
+ const tool = new CodeFunction(this.project, {
16476
+ handler,
16477
+ name: resolvedName,
16478
+ slug: _nullishCoalesce(slug, () => ( slugify(resolvedName, { lower: true, strict: true }))),
16479
+ type: "tool",
16480
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/consistent-type-assertions
16481
+ parameters,
16482
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/consistent-type-assertions
16483
+ returns,
16484
+ ...rest
16485
+ });
16486
+ this.project.addCodeFunction(tool);
16487
+ return tool;
16488
+ }
16489
+ }, _class21);
16490
+ var ScorerBuilder = (_class22 = class {
16491
+ constructor(project) {;_class22.prototype.__init74.call(this);
16492
+ this.project = project;
16493
+ }
16494
+ __init74() {this.taskCounter = 0}
16495
+ create(opts) {
16496
+ this.taskCounter++;
16497
+ let resolvedName = opts.name;
16498
+ if (!resolvedName && "handler" in opts) {
16499
+ resolvedName = opts.handler.name;
16500
+ }
16501
+ if (!resolvedName || resolvedName.trim().length === 0) {
16502
+ resolvedName = `Scorer ${isomorph_default.basename(currentFilename)} ${this.taskCounter}`;
16503
+ }
16504
+ const slug = _nullishCoalesce(opts.slug, () => ( slugify(resolvedName, { lower: true, strict: true })));
16505
+ if ("handler" in opts) {
16506
+ const scorer = new CodeFunction(this.project, {
16507
+ ...opts,
16508
+ name: resolvedName,
16509
+ slug,
16510
+ type: "scorer"
16511
+ });
16512
+ this.project.addCodeFunction(scorer);
16513
+ } else {
16514
+ const promptBlock = "messages" in opts ? {
16515
+ type: "chat",
16516
+ messages: opts.messages
16517
+ } : {
16518
+ type: "completion",
16519
+ content: opts.prompt
16520
+ };
16521
+ const promptData = {
16522
+ prompt: promptBlock,
16523
+ options: {
16524
+ model: opts.model,
16525
+ params: opts.params
16526
+ },
16527
+ parser: {
16528
+ type: "llm_classifier",
16529
+ use_cot: opts.useCot,
16530
+ choice_scores: opts.choiceScores
16531
+ }
16532
+ };
16533
+ const codePrompt = new CodePrompt(
16534
+ this.project,
16535
+ promptData,
16536
+ [],
16537
+ {
16538
+ ...opts,
16539
+ name: resolvedName,
16540
+ slug
16541
+ },
16542
+ "scorer"
16543
+ );
16544
+ this.project.addPrompt(codePrompt);
16545
+ }
16546
+ }
16547
+ }, _class22);
16548
+ var CodeFunction = class {
16549
+ constructor(project, opts) {
16550
+ this.project = project;
16551
+ this.handler = opts.handler;
16552
+ this.name = opts.name;
16553
+ this.slug = opts.slug;
16554
+ this.description = opts.description;
16555
+ this.type = opts.type;
16556
+ this.ifExists = opts.ifExists;
16557
+ this.metadata = opts.metadata;
16558
+ this.parameters = opts.parameters;
16559
+ this.returns = opts.returns;
16560
+ if (this.returns && !this.parameters) {
16561
+ throw new Error("parameters are required if return type is defined");
16562
+ }
16563
+ }
16564
+
16565
+
16566
+
16567
+
16568
+
16569
+
16570
+
16571
+
16572
+
16573
+ key() {
16574
+ return JSON.stringify([
16575
+ _nullishCoalesce(this.project.id, () => ( "")),
16576
+ _nullishCoalesce(this.project.name, () => ( "")),
16577
+ this.slug
16578
+ ]);
16579
+ }
16580
+ };
16581
+ var CodePrompt = class {
16582
+
16583
+
16584
+
16585
+
16586
+
16587
+
16588
+
16589
+
16590
+
16591
+
16592
+ constructor(project, prompt, toolFunctions, opts, functionType) {
16593
+ this.project = project;
16594
+ this.name = opts.name;
16595
+ this.slug = opts.slug;
16596
+ this.prompt = prompt;
16597
+ this.toolFunctions = toolFunctions;
16598
+ this.ifExists = opts.ifExists;
16599
+ this.description = opts.description;
16600
+ this.id = opts.id;
16601
+ this.functionType = functionType;
16602
+ this.metadata = opts.metadata;
16603
+ }
16604
+ async toFunctionDefinition(projectNameToId) {
16605
+ const prompt_data = {
16606
+ ...this.prompt
16607
+ };
16608
+ if (this.toolFunctions.length > 0) {
16609
+ const resolvableToolFunctions = await Promise.all(
16610
+ this.toolFunctions.map(async (fn) => {
16611
+ if ("slug" in fn) {
16612
+ return {
16613
+ type: "slug",
16614
+ project_id: await projectNameToId.resolve(fn.project),
16615
+ slug: fn.slug
16616
+ };
16617
+ } else {
16618
+ return fn;
16619
+ }
16620
+ })
16621
+ );
16622
+ prompt_data.tool_functions = // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
16623
+ resolvableToolFunctions;
16624
+ }
16625
+ return {
16626
+ project_id: await projectNameToId.resolve(this.project),
16627
+ name: this.name,
16628
+ slug: this.slug,
16629
+ description: _nullishCoalesce(this.description, () => ( "")),
16630
+ function_data: {
16631
+ type: "prompt"
16632
+ },
16633
+ function_type: this.functionType,
16634
+ prompt_data,
16635
+ if_exists: this.ifExists,
16636
+ metadata: this.metadata
16637
+ };
16638
+ }
16639
+ };
16640
+ var PromptBuilder = class {
16641
+ constructor(project) {
16642
+ this.project = project;
16643
+ }
16644
+ create(opts) {
16645
+ const toolFunctions = [];
16646
+ const rawTools = [];
16647
+ for (const tool of _nullishCoalesce(opts.tools, () => ( []))) {
16648
+ if (tool instanceof CodeFunction) {
16649
+ toolFunctions.push(tool);
16650
+ } else if ("type" in tool && !("function" in tool)) {
16651
+ toolFunctions.push(tool);
16652
+ } else {
16653
+ rawTools.push(tool);
16654
+ }
16655
+ }
16656
+ const slug = _nullishCoalesce(opts.slug, () => ( slugify(opts.name, { lower: true, strict: true })));
16657
+ const promptData = promptDefinitionToPromptData(opts, rawTools);
16658
+ const promptRow = {
16659
+ id: opts.id,
16660
+ _xact_id: opts.version ? loadPrettyXact(opts.version) : void 0,
16661
+ name: opts.name,
16662
+ slug,
16663
+ prompt_data: promptData,
16664
+ ...this.project.id !== void 0 ? { project_id: this.project.id } : {}
16665
+ };
16666
+ const prompt = new Prompt2(
16667
+ promptRow,
16668
+ {},
16669
+ // It doesn't make sense to specify defaults here.
16670
+ _nullishCoalesce(opts.noTrace, () => ( false))
16671
+ );
16672
+ const codePrompt = new CodePrompt(this.project, promptData, toolFunctions, {
16673
+ ...opts,
16674
+ slug
16675
+ });
16676
+ this.project.addPrompt(codePrompt);
16677
+ return prompt;
16678
+ }
16679
+ };
16680
+ var CodeParameters = class {
16681
+
16682
+
16683
+
16684
+
16685
+
16686
+
16687
+
16688
+ constructor(project, opts) {
16689
+ this.project = project;
16690
+ this.name = opts.name;
16691
+ this.slug = opts.slug;
16692
+ this.description = opts.description;
16693
+ this.schema = opts.schema;
16694
+ this.ifExists = opts.ifExists;
16695
+ this.metadata = opts.metadata;
16696
+ }
16697
+ async toFunctionDefinition(projectNameToId) {
16698
+ return {
16699
+ project_id: await projectNameToId.resolve(this.project),
16700
+ name: this.name,
16701
+ slug: this.slug,
16702
+ description: _nullishCoalesce(this.description, () => ( "")),
16703
+ function_type: "parameters",
16704
+ function_data: {
16705
+ type: "parameters",
16706
+ data: {},
16707
+ __schema: serializeEvalParameterstoParametersSchema(this.schema)
16708
+ },
16709
+ if_exists: this.ifExists,
16710
+ metadata: this.metadata
16711
+ };
16712
+ }
16713
+ };
16714
+ var ParametersBuilder = class {
16715
+ constructor(project) {
16716
+ this.project = project;
16717
+ }
16718
+ create(opts) {
16719
+ const slug = _nullishCoalesce(opts.slug, () => ( slugify(opts.name, { lower: true, strict: true })));
16720
+ const codeParameters = new CodeParameters(this.project, {
16721
+ name: opts.name,
16722
+ slug,
16723
+ description: opts.description,
16724
+ schema: opts.schema,
16725
+ ifExists: opts.ifExists,
16726
+ metadata: opts.metadata
16727
+ });
16728
+ this.project.addParameters(codeParameters);
16729
+ return opts.schema;
16730
+ }
16731
+ };
16732
+ function serializeEvalParameterstoParametersSchema(parameters) {
16733
+ const properties = {};
16734
+ const required = [];
16735
+ for (const [name, value] of Object.entries(parameters)) {
16736
+ if ("type" in value && value.type === "prompt") {
16737
+ const defaultPromptData = value.default ? promptDefinitionToPromptData(value.default) : void 0;
16738
+ properties[name] = {
16739
+ type: "object",
16740
+ "x-bt-type": "prompt",
16741
+ ...value.description ? { description: value.description } : {},
16742
+ ...defaultPromptData ? { default: defaultPromptData } : {}
16743
+ };
16744
+ if (!defaultPromptData) {
16745
+ required.push(name);
16746
+ }
16747
+ } else {
16748
+ const schemaObj = zodToJsonSchema(value);
16749
+ properties[name] = schemaObj;
16750
+ if (!("default" in schemaObj)) {
16751
+ required.push(name);
16752
+ }
16753
+ }
16754
+ }
16755
+ return {
16756
+ type: "object",
16757
+ properties,
16758
+ ...required.length > 0 ? { required } : {},
16759
+ additionalProperties: true
16760
+ };
16761
+ }
16762
+ var ProjectNameIdMap = (_class23 = class {constructor() { _class23.prototype.__init75.call(this);_class23.prototype.__init76.call(this); }
16763
+ __init75() {this.nameToId = {}}
16764
+ __init76() {this.idToName = {}}
16765
+ async getId(projectName) {
16766
+ if (!(projectName in this.nameToId)) {
16767
+ const response = await _internalGetGlobalState().appConn().post_json("api/project/register", {
16768
+ project_name: projectName
16769
+ });
16770
+ const result = _v3.z.object({
16771
+ project: Project
16772
+ }).parse(response);
16773
+ const projectId = result.project.id;
16774
+ this.nameToId[projectName] = projectId;
16775
+ this.idToName[projectId] = projectName;
16776
+ }
16777
+ return this.nameToId[projectName];
16778
+ }
16779
+ async getName(projectId) {
16780
+ if (!(projectId in this.idToName)) {
16781
+ const response = await _internalGetGlobalState().appConn().post_json("api/project/get", {
16782
+ id: projectId
16783
+ });
16784
+ const result = _v3.z.array(Project).nonempty().parse(response);
16785
+ const projectName = result[0].name;
16786
+ this.idToName[projectId] = projectName;
16787
+ this.nameToId[projectName] = projectId;
16788
+ }
16789
+ return this.idToName[projectId];
16790
+ }
16791
+ async resolve(project) {
16792
+ if (project.id) {
16793
+ return project.id;
16794
+ }
16795
+ return this.getId(project.name);
16796
+ }
16797
+ }, _class23);
16798
+
15868
16799
  // dev/types.ts
15869
16800
 
15870
16801
  var evalBodySchema = _v3.z.object({
@@ -15882,7 +16813,7 @@ var evalBodySchema = _v3.z.object({
15882
16813
  parent: InvokeParent.optional(),
15883
16814
  stream: _v3.z.boolean().optional()
15884
16815
  });
15885
- var evalParametersSerializedSchema = _v3.z.record(
16816
+ var staticParametersSchema = _v3.z.record(
15886
16817
  _v3.z.string(),
15887
16818
  _v3.z.union([
15888
16819
  _v3.z.object({
@@ -15893,14 +16824,43 @@ var evalParametersSerializedSchema = _v3.z.record(
15893
16824
  _v3.z.object({
15894
16825
  type: _v3.z.literal("data"),
15895
16826
  schema: _v3.z.record(_v3.z.unknown()),
15896
- // JSON Schema
15897
16827
  default: _v3.z.unknown().optional(),
15898
16828
  description: _v3.z.string().optional()
15899
16829
  })
15900
16830
  ])
15901
16831
  );
16832
+ var parametersSchema = _v3.z.object({
16833
+ type: _v3.z.literal("object"),
16834
+ properties: _v3.z.record(_v3.z.string(), _v3.z.record(_v3.z.unknown())),
16835
+ required: _v3.z.array(_v3.z.string()).optional(),
16836
+ additionalProperties: _v3.z.boolean().optional()
16837
+ });
16838
+ var parametersSourceSchema = _v3.z.object({
16839
+ parametersId: _v3.z.string().optional(),
16840
+ slug: _v3.z.string(),
16841
+ name: _v3.z.string(),
16842
+ projectId: _v3.z.string().optional(),
16843
+ version: _v3.z.string().optional()
16844
+ });
16845
+ var parametersContainerSchema = _v3.z.object({
16846
+ type: _v3.z.literal("braintrust.parameters"),
16847
+ schema: parametersSchema,
16848
+ source: parametersSourceSchema
16849
+ });
16850
+ var staticParametersContainerSchema = _v3.z.object({
16851
+ type: _v3.z.literal("braintrust.staticParameters"),
16852
+ schema: staticParametersSchema,
16853
+ source: _v3.z.null()
16854
+ });
16855
+ var serializedParametersContainerSchema = _v3.z.union([
16856
+ parametersContainerSchema,
16857
+ staticParametersContainerSchema,
16858
+ // keeping this type here since old versions of the SDK will still pass the unwrapped schema and we need to handle this in the app
16859
+ staticParametersSchema
16860
+ ]);
15902
16861
  var evaluatorDefinitionSchema = _v3.z.object({
15903
- parameters: evalParametersSerializedSchema.optional()
16862
+ parameters: serializedParametersContainerSchema.optional(),
16863
+ scores: _v3.z.array(_v3.z.object({ name: _v3.z.string() })).optional()
15904
16864
  });
15905
16865
  var evaluatorDefinitionsSchema = _v3.z.record(
15906
16866
  _v3.z.string(),
@@ -16026,4 +16986,13 @@ configureNode();
16026
16986
 
16027
16987
 
16028
16988
 
16029
- exports.Attachment = Attachment; exports.AttachmentReference = AttachmentReference; exports.BaseAttachment = BaseAttachment; exports.BaseExperiment = BaseExperiment; exports.BraintrustMiddleware = BraintrustMiddleware; exports.BraintrustState = BraintrustState; exports.BraintrustStream = BraintrustStream; exports.CachedSpanFetcher = CachedSpanFetcher; exports.CodeFunction = CodeFunction; exports.CodePrompt = CodePrompt; exports.ContextManager = ContextManager; exports.DEFAULT_FETCH_BATCH_SIZE = DEFAULT_FETCH_BATCH_SIZE; exports.Dataset = Dataset2; exports.ERR_PERMALINK = ERR_PERMALINK; exports.Eval = Eval; exports.EvalResultWithSummary = EvalResultWithSummary; exports.Experiment = Experiment2; exports.ExternalAttachment = ExternalAttachment; exports.FailedHTTPResponse = FailedHTTPResponse; exports.IDGenerator = IDGenerator; exports.JSONAttachment = JSONAttachment; exports.LEGACY_CACHED_HEADER = LEGACY_CACHED_HEADER; exports.LazyValue = LazyValue; exports.Logger = Logger; exports.LoginInvalidOrgError = LoginInvalidOrgError; exports.NOOP_SPAN = NOOP_SPAN; exports.NOOP_SPAN_PERMALINK = NOOP_SPAN_PERMALINK; exports.NoopSpan = NoopSpan; exports.ObjectFetcher = ObjectFetcher; exports.Project = Project2; exports.ProjectNameIdMap = ProjectNameIdMap; exports.Prompt = Prompt2; exports.PromptBuilder = PromptBuilder; exports.ReadonlyAttachment = ReadonlyAttachment; exports.ReadonlyExperiment = ReadonlyExperiment; exports.Reporter = Reporter; exports.ScorerBuilder = ScorerBuilder; exports.SpanFetcher = SpanFetcher; exports.SpanImpl = SpanImpl; exports.TestBackgroundLogger = TestBackgroundLogger; exports.ToolBuilder = ToolBuilder; exports.UUIDGenerator = UUIDGenerator; exports.X_CACHED_HEADER = X_CACHED_HEADER; exports._exportsForTestingOnly = _exportsForTestingOnly; exports._internalGetGlobalState = _internalGetGlobalState; exports._internalSetInitialState = _internalSetInitialState; exports.braintrustStreamChunkSchema = braintrustStreamChunkSchema; exports.buildLocalSummary = buildLocalSummary; exports.createFinalValuePassThroughStream = createFinalValuePassThroughStream; exports.currentExperiment = currentExperiment; exports.currentLogger = currentLogger; exports.currentSpan = currentSpan; exports.deepCopyEvent = deepCopyEvent; exports.default = exports_exports; exports.defaultErrorScoreHandler = defaultErrorScoreHandler; exports.deserializePlainStringAsJSON = deserializePlainStringAsJSON; exports.devNullWritableStream = devNullWritableStream; exports.evaluatorDefinitionSchema = evaluatorDefinitionSchema; exports.evaluatorDefinitionsSchema = evaluatorDefinitionsSchema; exports.flush = flush; exports.getContextManager = getContextManager; exports.getIdGenerator = getIdGenerator; exports.getPromptVersions = getPromptVersions; exports.getSpanParentObject = getSpanParentObject; exports.graph = graph_framework_exports; exports.init = init; exports.initDataset = initDataset; exports.initExperiment = initExperiment; exports.initFunction = initFunction; exports.initLogger = initLogger; exports.invoke = invoke; exports.isTemplateFormat = isTemplateFormat; exports.loadPrompt = loadPrompt; exports.log = log; exports.logError = logError; exports.login = login; exports.loginToState = loginToState; exports.newId = newId; exports.parseCachedHeader = parseCachedHeader; exports.parseTemplateFormat = parseTemplateFormat; exports.permalink = permalink; exports.projects = projects; exports.promptContentsSchema = promptContentsSchema; exports.promptDefinitionSchema = promptDefinitionSchema; exports.promptDefinitionToPromptData = promptDefinitionToPromptData; exports.promptDefinitionWithToolsSchema = promptDefinitionWithToolsSchema; exports.registerOtelFlush = registerOtelFlush; exports.renderMessage = renderMessage; exports.renderPromptParams = renderPromptParams; exports.renderTemplateContent = renderTemplateContent; exports.reportFailures = reportFailures; exports.runEvaluator = runEvaluator; exports.setFetch = setFetch; exports.setMaskingFunction = setMaskingFunction; exports.spanComponentsToObjectId = spanComponentsToObjectId; exports.startSpan = startSpan; exports.summarize = summarize; exports.toolFunctionDefinitionSchema = ToolFunctionDefinition; exports.traceable = traceable; exports.traced = traced; exports.updateSpan = updateSpan; exports.withCurrent = withCurrent; exports.withDataset = withDataset; exports.withExperiment = withExperiment; exports.withLogger = withLogger; exports.withParent = withParent; exports.wrapAISDK = wrapAISDK; exports.wrapAISDKModel = wrapAISDKModel; exports.wrapAgentClass = wrapAgentClass; exports.wrapAnthropic = wrapAnthropic; exports.wrapClaudeAgentSDK = wrapClaudeAgentSDK; exports.wrapGoogleGenAI = wrapGoogleGenAI; exports.wrapMastraAgent = wrapMastraAgent; exports.wrapOpenAI = wrapOpenAI; exports.wrapOpenAIv4 = wrapOpenAIv4; exports.wrapTraced = wrapTraced;
16989
+
16990
+
16991
+
16992
+
16993
+
16994
+
16995
+
16996
+
16997
+
16998
+ exports.Attachment = Attachment; exports.AttachmentReference = AttachmentReference; exports.BaseAttachment = BaseAttachment; exports.BaseExperiment = BaseExperiment; exports.BraintrustMiddleware = BraintrustMiddleware; exports.BraintrustState = BraintrustState; exports.BraintrustStream = BraintrustStream; exports.CachedSpanFetcher = CachedSpanFetcher; exports.CodeFunction = CodeFunction; exports.CodePrompt = CodePrompt; exports.ContextManager = ContextManager; exports.DEFAULT_FETCH_BATCH_SIZE = DEFAULT_FETCH_BATCH_SIZE; exports.DEFAULT_MAX_REQUEST_SIZE = DEFAULT_MAX_REQUEST_SIZE; exports.Dataset = Dataset2; exports.ERR_PERMALINK = ERR_PERMALINK; exports.Eval = Eval; exports.EvalResultWithSummary = EvalResultWithSummary; exports.Experiment = Experiment2; exports.ExternalAttachment = ExternalAttachment; exports.FailedHTTPResponse = FailedHTTPResponse; exports.IDGenerator = IDGenerator; exports.JSONAttachment = JSONAttachment; exports.LEGACY_CACHED_HEADER = LEGACY_CACHED_HEADER; exports.LOGS3_OVERFLOW_REFERENCE_TYPE = LOGS3_OVERFLOW_REFERENCE_TYPE; exports.LazyValue = LazyValue; exports.Logger = Logger; exports.LoginInvalidOrgError = LoginInvalidOrgError; exports.NOOP_SPAN = NOOP_SPAN; exports.NOOP_SPAN_PERMALINK = NOOP_SPAN_PERMALINK; exports.NoopSpan = NoopSpan; exports.ObjectFetcher = ObjectFetcher; exports.Project = Project2; exports.ProjectNameIdMap = ProjectNameIdMap; exports.Prompt = Prompt2; exports.PromptBuilder = PromptBuilder; exports.ReadonlyAttachment = ReadonlyAttachment; exports.ReadonlyExperiment = ReadonlyExperiment; exports.Reporter = Reporter; exports.ScorerBuilder = ScorerBuilder; exports.SpanFetcher = SpanFetcher; exports.SpanImpl = SpanImpl; exports.TestBackgroundLogger = TestBackgroundLogger; exports.ToolBuilder = ToolBuilder; exports.UUIDGenerator = UUIDGenerator; exports.X_CACHED_HEADER = X_CACHED_HEADER; exports._exportsForTestingOnly = _exportsForTestingOnly; exports._internalGetGlobalState = _internalGetGlobalState; exports._internalSetInitialState = _internalSetInitialState; exports.addAzureBlobHeaders = addAzureBlobHeaders; exports.braintrustStreamChunkSchema = braintrustStreamChunkSchema; exports.buildLocalSummary = buildLocalSummary; exports.constructLogs3OverflowRequest = constructLogs3OverflowRequest; exports.createFinalValuePassThroughStream = createFinalValuePassThroughStream; exports.currentExperiment = currentExperiment; exports.currentLogger = currentLogger; exports.currentSpan = currentSpan; exports.deepCopyEvent = deepCopyEvent; exports.default = exports_exports; exports.defaultErrorScoreHandler = defaultErrorScoreHandler; exports.deserializePlainStringAsJSON = deserializePlainStringAsJSON; exports.devNullWritableStream = devNullWritableStream; exports.evaluatorDefinitionSchema = evaluatorDefinitionSchema; exports.evaluatorDefinitionsSchema = evaluatorDefinitionsSchema; exports.flush = flush; exports.getContextManager = getContextManager; exports.getIdGenerator = getIdGenerator; exports.getPromptVersions = getPromptVersions; exports.getSpanParentObject = getSpanParentObject; exports.graph = graph_framework_exports; exports.init = init; exports.initDataset = initDataset; exports.initExperiment = initExperiment; exports.initFunction = initFunction; exports.initLogger = initLogger; exports.invoke = invoke; exports.isTemplateFormat = isTemplateFormat; exports.loadParameters = loadParameters; exports.loadPrompt = loadPrompt; exports.log = log; exports.logError = logError; exports.login = login; exports.loginToState = loginToState; exports.logs3OverflowUploadSchema = logs3OverflowUploadSchema; exports.newId = newId; exports.parseCachedHeader = parseCachedHeader; exports.parseTemplateFormat = parseTemplateFormat; exports.permalink = permalink; exports.pickLogs3OverflowObjectIds = pickLogs3OverflowObjectIds; exports.projects = projects; exports.promptContentsSchema = promptContentsSchema; exports.promptDefinitionSchema = promptDefinitionSchema; exports.promptDefinitionToPromptData = promptDefinitionToPromptData; exports.promptDefinitionWithToolsSchema = promptDefinitionWithToolsSchema; exports.registerOtelFlush = registerOtelFlush; exports.renderMessage = renderMessage; exports.renderPromptParams = renderPromptParams; exports.renderTemplateContent = renderTemplateContent; exports.reportFailures = reportFailures; exports.runEvaluator = runEvaluator; exports.setFetch = setFetch; exports.setMaskingFunction = setMaskingFunction; exports.spanComponentsToObjectId = spanComponentsToObjectId; exports.startSpan = startSpan; exports.summarize = summarize; exports.toolFunctionDefinitionSchema = ToolFunctionDefinition; exports.traceable = traceable; exports.traced = traced; exports.updateSpan = updateSpan; exports.uploadLogs3OverflowPayload = uploadLogs3OverflowPayload; exports.utf8ByteLength = utf8ByteLength; exports.withCurrent = withCurrent; exports.withDataset = withDataset; exports.withExperiment = withExperiment; exports.withLogger = withLogger; exports.withParent = withParent; exports.wrapAISDK = wrapAISDK; exports.wrapAISDKModel = wrapAISDKModel; exports.wrapAgentClass = wrapAgentClass; exports.wrapAnthropic = wrapAnthropic; exports.wrapClaudeAgentSDK = wrapClaudeAgentSDK; exports.wrapGoogleGenAI = wrapGoogleGenAI; exports.wrapMastraAgent = wrapMastraAgent; exports.wrapOpenAI = wrapOpenAI; exports.wrapOpenAIv4 = wrapOpenAIv4; exports.wrapTraced = wrapTraced;