braintrust 3.30.0 → 3.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/dev/dist/index.d.mts +740 -1
  2. package/dev/dist/index.d.ts +740 -1
  3. package/dev/dist/index.js +1307 -434
  4. package/dev/dist/index.mjs +886 -13
  5. package/dist/apply-auto-instrumentation.js +281 -216
  6. package/dist/apply-auto-instrumentation.mjs +66 -1
  7. package/dist/auto-instrumentations/bundler/esbuild.cjs +104 -2
  8. package/dist/auto-instrumentations/bundler/esbuild.mjs +2 -2
  9. package/dist/auto-instrumentations/bundler/next.cjs +113 -5
  10. package/dist/auto-instrumentations/bundler/next.mjs +12 -6
  11. package/dist/auto-instrumentations/bundler/rollup.cjs +104 -2
  12. package/dist/auto-instrumentations/bundler/rollup.mjs +2 -2
  13. package/dist/auto-instrumentations/bundler/vite.cjs +104 -2
  14. package/dist/auto-instrumentations/bundler/vite.mjs +2 -2
  15. package/dist/auto-instrumentations/bundler/webpack-loader.cjs +104 -2
  16. package/dist/auto-instrumentations/bundler/webpack.cjs +104 -2
  17. package/dist/auto-instrumentations/bundler/webpack.mjs +3 -3
  18. package/dist/auto-instrumentations/{chunk-U64OYU4Q.mjs → chunk-AFND2U7E.mjs} +38 -1
  19. package/dist/auto-instrumentations/{chunk-OXINGIEZ.mjs → chunk-QEEPRBIS.mjs} +1 -1
  20. package/dist/auto-instrumentations/{chunk-LW4HDHXT.mjs → chunk-RI4Y55ZF.mjs} +69 -2
  21. package/dist/auto-instrumentations/hook.mjs +126 -3
  22. package/dist/auto-instrumentations/index.cjs +39 -1
  23. package/dist/auto-instrumentations/index.d.mts +3 -1
  24. package/dist/auto-instrumentations/index.d.ts +3 -1
  25. package/dist/auto-instrumentations/index.mjs +3 -1
  26. package/dist/browser.d.mts +3052 -927
  27. package/dist/browser.d.ts +3052 -927
  28. package/dist/browser.js +1023 -18
  29. package/dist/browser.mjs +1023 -18
  30. package/dist/{chunk-BU6SM54N.mjs → chunk-4QSAHP7D.mjs} +834 -10
  31. package/dist/{chunk-2XDW3UCG.js → chunk-AW4QECG5.js} +47 -4
  32. package/dist/{chunk-TWCDSYJN.js → chunk-BTRLPQG5.js} +1679 -855
  33. package/dist/{chunk-N3JKQ3D3.mjs → chunk-WV6QZI2W.mjs} +46 -3
  34. package/dist/cli.js +950 -14
  35. package/dist/edge-light.d.mts +1 -1
  36. package/dist/edge-light.d.ts +1 -1
  37. package/dist/edge-light.js +1023 -18
  38. package/dist/edge-light.mjs +1023 -18
  39. package/dist/index.d.mts +3052 -927
  40. package/dist/index.d.ts +3052 -927
  41. package/dist/index.js +594 -450
  42. package/dist/index.mjs +149 -5
  43. package/dist/instrumentation/index.d.mts +434 -0
  44. package/dist/instrumentation/index.d.ts +434 -0
  45. package/dist/instrumentation/index.js +875 -12
  46. package/dist/instrumentation/index.mjs +875 -12
  47. package/dist/vitest-evals-reporter.js +16 -16
  48. package/dist/vitest-evals-reporter.mjs +2 -2
  49. package/dist/workerd.d.mts +1 -1
  50. package/dist/workerd.d.ts +1 -1
  51. package/dist/workerd.js +1023 -18
  52. package/dist/workerd.mjs +1023 -18
  53. package/package.json +1 -1
  54. package/util/dist/index.d.mts +326 -0
  55. package/util/dist/index.d.ts +326 -0
package/dist/index.mjs CHANGED
@@ -143,7 +143,7 @@ import {
143
143
  wrapMastraAgent,
144
144
  wrapTraced,
145
145
  zodToJsonSchema
146
- } from "./chunk-BU6SM54N.mjs";
146
+ } from "./chunk-4QSAHP7D.mjs";
147
147
  import {
148
148
  INSTRUMENTATION_NAMES,
149
149
  __export,
@@ -156,10 +156,12 @@ import {
156
156
  cohereChannels,
157
157
  cursorSDKChannels,
158
158
  debugLogger,
159
+ elevenLabsChannels,
159
160
  genkitChannels,
160
161
  gitHubCopilotChannels,
161
162
  googleADKChannels,
162
163
  googleGenAIChannels,
164
+ googleGenerativeAIChannels,
163
165
  groqChannels,
164
166
  harnessAgentChannels,
165
167
  huggingFaceChannels,
@@ -177,7 +179,7 @@ import {
177
179
  strandsAgentSDKChannels,
178
180
  voyageAIChannels,
179
181
  withSpanInstrumentationName
180
- } from "./chunk-N3JKQ3D3.mjs";
182
+ } from "./chunk-WV6QZI2W.mjs";
181
183
 
182
184
  // src/exports.ts
183
185
  var exports_exports = {};
@@ -343,9 +345,11 @@ __export(exports_exports, {
343
345
  wrapCohere: () => wrapCohere,
344
346
  wrapCopilotClient: () => wrapCopilotClient,
345
347
  wrapCursorSDK: () => wrapCursorSDK,
348
+ wrapElevenLabs: () => wrapElevenLabs,
346
349
  wrapGenkit: () => wrapGenkit,
347
350
  wrapGoogleADK: () => wrapGoogleADK,
348
351
  wrapGoogleGenAI: () => wrapGoogleGenAI,
352
+ wrapGoogleGenerativeAI: () => wrapGoogleGenerativeAI,
349
353
  wrapGroq: () => wrapGroq,
350
354
  wrapHuggingFace: () => wrapHuggingFace,
351
355
  wrapHuggingFaceTransformers: () => wrapHuggingFaceTransformers,
@@ -5214,6 +5218,75 @@ function isModuleNamespace5(value) {
5214
5218
  }
5215
5219
  }
5216
5220
 
5221
+ // src/wrappers/google-generative-ai.ts
5222
+ function wrapGoogleGenerativeAI(client) {
5223
+ if (!isObject(client) || typeof client.getGenerativeModel !== "function")
5224
+ return client;
5225
+ return wrapClient(client);
5226
+ }
5227
+ var proxies = /* @__PURE__ */ new WeakMap();
5228
+ function wrapClient(client) {
5229
+ const cached = proxies.get(client);
5230
+ if (cached) return cached;
5231
+ const proxy = new Proxy(client, {
5232
+ get(target, prop, receiver) {
5233
+ const value = Reflect.get(target, prop, receiver);
5234
+ if (typeof value !== "function") return value;
5235
+ if (prop === "getGenerativeModel" || prop === "getGenerativeModelFromCachedContent" || prop === "startChat") {
5236
+ return (...args) => wrapClient(Reflect.apply(value, target, args));
5237
+ }
5238
+ switch (prop) {
5239
+ case "generateContent":
5240
+ return (...args) => googleGenerativeAIChannels.generateContent.invoke(
5241
+ value,
5242
+ target,
5243
+ args,
5244
+ {}
5245
+ );
5246
+ case "generateContentStream":
5247
+ return (...args) => googleGenerativeAIChannels.generateContentStream.invoke(
5248
+ value,
5249
+ target,
5250
+ args,
5251
+ {}
5252
+ );
5253
+ case "embedContent":
5254
+ return (...args) => googleGenerativeAIChannels.embedContent.invoke(
5255
+ value,
5256
+ target,
5257
+ args,
5258
+ {}
5259
+ );
5260
+ case "batchEmbedContents":
5261
+ return (...args) => googleGenerativeAIChannels.batchEmbedContents.invoke(
5262
+ value,
5263
+ target,
5264
+ args,
5265
+ {}
5266
+ );
5267
+ case "sendMessage":
5268
+ return (...args) => googleGenerativeAIChannels.sendMessage.invoke(
5269
+ value,
5270
+ target,
5271
+ args,
5272
+ {}
5273
+ );
5274
+ case "sendMessageStream":
5275
+ return (...args) => googleGenerativeAIChannels.sendMessageStream.invoke(
5276
+ value,
5277
+ target,
5278
+ args,
5279
+ {}
5280
+ );
5281
+ }
5282
+ return value.bind(target);
5283
+ }
5284
+ });
5285
+ proxies.set(client, proxy);
5286
+ proxies.set(proxy, proxy);
5287
+ return proxy;
5288
+ }
5289
+
5217
5290
  // src/wrappers/google-genai.ts
5218
5291
  function wrapGoogleGenAI(googleGenAI) {
5219
5292
  if (!googleGenAI || typeof googleGenAI !== "object") {
@@ -7170,8 +7243,8 @@ function normalizeScores(result) {
7170
7243
  (s) => s !== null && s !== void 0 && typeof s === "object" && isScore(s)
7171
7244
  );
7172
7245
  }
7173
- if (typeof result === "object" && result !== null && isScore(result)) {
7174
- return [result];
7246
+ if (typeof result === "object" && result !== null && "score" in result) {
7247
+ return [{ ...result, name: result.name ?? "score" }];
7175
7248
  }
7176
7249
  return [];
7177
7250
  }
@@ -9754,19 +9827,29 @@ function buildSpanScores(results) {
9754
9827
  function _internalPrepareEvaluatorScore(scoreValue, name) {
9755
9828
  if (scoreValue === null) return { results: null };
9756
9829
  if (Array.isArray(scoreValue)) {
9830
+ const names = /* @__PURE__ */ new Set();
9757
9831
  for (const score of scoreValue) {
9758
9832
  if (!(typeof score === "object" && !isEmpty(score))) {
9759
9833
  throw new Error(
9760
9834
  `When returning an array of scores, each score must be a non-empty object. Got: ${JSON.stringify(score)}`
9761
9835
  );
9762
9836
  }
9837
+ if (typeof score.name !== "string") {
9838
+ throw new Error(
9839
+ `When returning an array of scores, each score must have a name. Got: ${JSON.stringify(score)}`
9840
+ );
9841
+ }
9842
+ if (names.has(score.name)) {
9843
+ throw new Error(`Duplicate score name '${score.name}' in score array`);
9844
+ }
9845
+ names.add(score.name);
9763
9846
  }
9764
9847
  }
9765
9848
  let results;
9766
9849
  if (Array.isArray(scoreValue)) {
9767
9850
  results = scoreValue;
9768
9851
  } else if (typeof scoreValue === "object" && !isEmpty(scoreValue)) {
9769
- results = [scoreValue];
9852
+ results = [{ ...scoreValue, name: scoreValue.name ?? name }];
9770
9853
  } else {
9771
9854
  results = [{ name, score: scoreValue }];
9772
9855
  }
@@ -12524,6 +12607,65 @@ var evaluatorDefinitionsSchema = z5.record(
12524
12607
  evaluatorDefinitionSchema
12525
12608
  );
12526
12609
 
12610
+ // src/wrappers/elevenlabs.ts
12611
+ var clients = /* @__PURE__ */ new WeakMap();
12612
+ function wrapElevenLabs(client) {
12613
+ if (!isObject(client) || !isObject(client.textToSpeech) || typeof client.textToSpeech.convert !== "function") {
12614
+ debugLogger.warn("Unsupported ElevenLabs client. Not wrapping.");
12615
+ return client;
12616
+ }
12617
+ const cached = clients.get(client);
12618
+ if (cached) return cached;
12619
+ const sdk = client;
12620
+ const speech = new Proxy(sdk.textToSpeech, {
12621
+ get(target, prop, receiver) {
12622
+ switch (prop) {
12623
+ case "convert":
12624
+ case "stream":
12625
+ return (...args) => elevenLabsChannels[prop].invoke(target[prop], target, args, {});
12626
+ case "convertWithTimestamps":
12627
+ return (...args) => elevenLabsChannels.convertWithTimestamps.invoke(
12628
+ target.convertWithTimestamps,
12629
+ target,
12630
+ args,
12631
+ {}
12632
+ );
12633
+ case "streamWithTimestamps":
12634
+ return (...args) => elevenLabsChannels.streamWithTimestamps.invoke(
12635
+ target.streamWithTimestamps,
12636
+ target,
12637
+ args,
12638
+ {}
12639
+ );
12640
+ default:
12641
+ return Reflect.get(target, prop, receiver);
12642
+ }
12643
+ }
12644
+ });
12645
+ const transcription = new Proxy(sdk.speechToText, {
12646
+ get(target, prop, receiver) {
12647
+ if (prop === "convert")
12648
+ return (request, options) => elevenLabsChannels.transcribe.invoke(
12649
+ target.convert,
12650
+ target,
12651
+ [request, options],
12652
+ {}
12653
+ );
12654
+ return Reflect.get(target, prop, receiver);
12655
+ }
12656
+ });
12657
+ const proxy = new Proxy(sdk, {
12658
+ get(target, prop, receiver) {
12659
+ if (prop === "textToSpeech") return speech;
12660
+ if (prop === "speechToText") return transcription;
12661
+ return Reflect.get(target, prop, receiver);
12662
+ }
12663
+ });
12664
+ clients.set(client, proxy);
12665
+ clients.set(proxy, proxy);
12666
+ return proxy;
12667
+ }
12668
+
12527
12669
  // src/node/index.ts
12528
12670
  configureNode();
12529
12671
  export {
@@ -12689,9 +12831,11 @@ export {
12689
12831
  wrapCohere,
12690
12832
  wrapCopilotClient,
12691
12833
  wrapCursorSDK,
12834
+ wrapElevenLabs,
12692
12835
  wrapGenkit,
12693
12836
  wrapGoogleADK,
12694
12837
  wrapGoogleGenAI,
12838
+ wrapGoogleGenerativeAI,
12695
12839
  wrapGroq,
12696
12840
  wrapHuggingFace,
12697
12841
  wrapHuggingFaceTransformers,