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
@@ -2815,6 +2815,14 @@ var ChatCompletionContentPartImageWithTitle = z6.object({
2815
2815
  ttl: z6.enum(["5m", "1h"]).optional()
2816
2816
  }).optional()
2817
2817
  });
2818
+ var ChatCompletionContentPartInputAudioWithTitle = z6.object({
2819
+ input_audio: z6.object({ data: z6.string(), format: z6.enum(["wav", "mp3"]) }),
2820
+ type: z6.literal("input_audio"),
2821
+ cache_control: z6.object({
2822
+ type: z6.literal("ephemeral"),
2823
+ ttl: z6.enum(["5m", "1h"]).optional()
2824
+ }).optional()
2825
+ });
2818
2826
  var ChatCompletionContentPartFileFile = z6.object({ file_data: z6.string(), filename: z6.string(), file_id: z6.string() }).partial();
2819
2827
  var ChatCompletionContentPartFileWithTitle = z6.object({
2820
2828
  file: ChatCompletionContentPartFileFile,
@@ -2827,6 +2835,7 @@ var ChatCompletionContentPartFileWithTitle = z6.object({
2827
2835
  var ChatCompletionContentPart = z6.union([
2828
2836
  ChatCompletionContentPartTextWithTitle,
2829
2837
  ChatCompletionContentPartImageWithTitle,
2838
+ ChatCompletionContentPartInputAudioWithTitle,
2830
2839
  ChatCompletionContentPartFileWithTitle
2831
2840
  ]);
2832
2841
  var ChatCompletionContentPartText = z6.object({
@@ -3818,6 +3827,7 @@ var ProjectSettings = z6.union([
3818
3827
  ]),
3819
3828
  disable_realtime_queries: z6.union([z6.boolean(), z6.null()]),
3820
3829
  monitor_charts_use_metrics_start: z6.union([z6.boolean(), z6.null()]),
3830
+ blind_reviews: z6.union([z6.boolean(), z6.null()]),
3821
3831
  default_preprocessor: NullableSavedFunctionId
3822
3832
  }).partial(),
3823
3833
  z6.null()
@@ -3879,6 +3889,7 @@ var WindowedAutomationConfig = z6.object({
3879
3889
  auto_approve_tools: z6.array(z6.string().min(1)).optional().default([]),
3880
3890
  harness: z6.enum(["native", "codex", "claude-code"]).optional(),
3881
3891
  model: z6.string().min(1).optional(),
3892
+ endpoint_name: z6.string().min(1).optional(),
3882
3893
  reasoning_effort: z6.enum(["none", "minimal", "low", "medium", "high", "xhigh", "max"]).optional()
3883
3894
  }).optional(),
3884
3895
  actions: z6.array(
@@ -5652,6 +5663,7 @@ var INSTRUMENTATION_NAMES = {
5652
5663
  GENKIT: "genkit",
5653
5664
  GITHUB_COPILOT: "github-copilot",
5654
5665
  GOOGLE_ADK: "google-adk",
5666
+ GOOGLE_GENERATIVE_AI: "google-generative-ai",
5655
5667
  GOOGLE_GENAI: "google-genai",
5656
5668
  GROQ: "groq",
5657
5669
  HUGGINGFACE: "huggingface",
@@ -5667,12 +5679,13 @@ var INSTRUMENTATION_NAMES = {
5667
5679
  OPENROUTER_AGENT: "openrouter-agent",
5668
5680
  PI_CODING_AGENT: "pi-coding-agent",
5669
5681
  STRANDS_AGENT_SDK: "strands-agent-sdk",
5670
- VOYAGEAI: "voyageai"
5682
+ VOYAGEAI: "voyageai",
5683
+ ELEVENLABS: "elevenlabs"
5671
5684
  };
5672
5685
  var INTERNAL_SPAN_INSTRUMENTATION_NAME = /* @__PURE__ */ Symbol.for(
5673
5686
  "braintrust.spanInstrumentationName"
5674
5687
  );
5675
- var SDK_VERSION = true ? "3.30.0" : "0.0.0";
5688
+ var SDK_VERSION = true ? "3.32.0" : "0.0.0";
5676
5689
  function withSpanInstrumentationName(args, instrumentationName) {
5677
5690
  return {
5678
5691
  ...args,
@@ -11630,6 +11643,16 @@ function renderMessageImpl(render, message, variables) {
11630
11643
  }
11631
11644
  }
11632
11645
  ];
11646
+ case "input_audio":
11647
+ return [
11648
+ {
11649
+ ...c,
11650
+ input_audio: {
11651
+ ...c.input_audio,
11652
+ data: render(c.input_audio.data)
11653
+ }
11654
+ }
11655
+ ];
11633
11656
  case "file":
11634
11657
  return [
11635
11658
  {
@@ -19823,6 +19846,12 @@ function prepareAISDKChildTracing(params, self, parentSpan, denyOutputPaths, aiS
19823
19846
  if (!activeEntry) {
19824
19847
  return result;
19825
19848
  }
19849
+ const executionOptions = args[1];
19850
+ const toolCallId = isObject(executionOptions) ? executionOptions.toolCallId : void 0;
19851
+ const toolInput = {
19852
+ input: serializeToolExecutionInput(args),
19853
+ ...typeof toolCallId === "string" ? { metadata: { toolCallId } } : {}
19854
+ };
19826
19855
  if (isAsyncGenerator(result)) {
19827
19856
  return (async function* () {
19828
19857
  const span = activeEntry.parentSpan.startSpan(
@@ -19836,7 +19865,7 @@ function prepareAISDKChildTracing(params, self, parentSpan, denyOutputPaths, aiS
19836
19865
  INSTRUMENTATION_NAMES.AI_SDK
19837
19866
  )
19838
19867
  );
19839
- span.log({ input: serializeToolExecutionInput(args) });
19868
+ span.log(toolInput);
19840
19869
  try {
19841
19870
  let lastValue;
19842
19871
  for await (const value of result) {
@@ -19854,7 +19883,7 @@ function prepareAISDKChildTracing(params, self, parentSpan, denyOutputPaths, aiS
19854
19883
  }
19855
19884
  return activeEntry.parentSpan.traced(
19856
19885
  async (span) => {
19857
- span.log({ input: serializeToolExecutionInput(args) });
19886
+ span.log(toolInput);
19858
19887
  const awaitedResult = await result;
19859
19888
  span.log({ output: awaitedResult });
19860
19889
  return awaitedResult;
@@ -24258,6 +24287,342 @@ var OpenAIAgentsPlugin = class extends BasePlugin {
24258
24287
  }
24259
24288
  };
24260
24289
 
24290
+ // src/instrumentation/plugins/google-generative-ai-channels.ts
24291
+ var googleGenerativeAIChannels = defineChannels(
24292
+ "@google/generative-ai",
24293
+ {
24294
+ generateContent: channel({ channelName: "GenerativeModel.generateContent", kind: "async" }),
24295
+ generateContentStream: channel({ channelName: "GenerativeModel.generateContentStream", kind: "async" }),
24296
+ embedContent: channel({ channelName: "GenerativeModel.embedContent", kind: "async" }),
24297
+ batchEmbedContents: channel({ channelName: "GenerativeModel.batchEmbedContents", kind: "async" }),
24298
+ sendMessage: channel({ channelName: "ChatSession.sendMessage", kind: "async" }),
24299
+ sendMessageStream: channel({ channelName: "ChatSession.sendMessageStream", kind: "async" })
24300
+ },
24301
+ { instrumentationName: INSTRUMENTATION_NAMES.GOOGLE_GENERATIVE_AI }
24302
+ );
24303
+
24304
+ // src/instrumentation/plugins/google-generative-ai-plugin.ts
24305
+ var GENERATION_CONFIG_KEYS = [
24306
+ "temperature",
24307
+ "topP",
24308
+ "topK",
24309
+ "candidateCount",
24310
+ "maxOutputTokens",
24311
+ "stopSequences",
24312
+ "responseMimeType",
24313
+ "responseSchema",
24314
+ "presencePenalty",
24315
+ "frequencyPenalty",
24316
+ "responseLogprobs",
24317
+ "logprobs",
24318
+ "thinkingConfig"
24319
+ ];
24320
+ var GoogleGenerativeAIPlugin = class extends BasePlugin {
24321
+ onEnable() {
24322
+ this.unsubscribers.push(
24323
+ interceptCall(
24324
+ googleGenerativeAIChannels.generateContent,
24325
+ "generateContent"
24326
+ ),
24327
+ interceptCall(
24328
+ googleGenerativeAIChannels.generateContentStream,
24329
+ "generateContentStream"
24330
+ ),
24331
+ interceptCall(googleGenerativeAIChannels.sendMessage, "sendMessage"),
24332
+ interceptCall(
24333
+ googleGenerativeAIChannels.sendMessageStream,
24334
+ "sendMessageStream"
24335
+ ),
24336
+ interceptCall(googleGenerativeAIChannels.embedContent, "embedContent"),
24337
+ interceptCall(
24338
+ googleGenerativeAIChannels.batchEmbedContents,
24339
+ "batchEmbedContents"
24340
+ )
24341
+ );
24342
+ }
24343
+ onDisable() {
24344
+ this.unsubscribers = unsubscribeAll(this.unsubscribers);
24345
+ }
24346
+ };
24347
+ function interceptCall(channel2, operation) {
24348
+ return channel2.intercept((target, thisArg, args) => {
24349
+ const invokeTarget = () => Reflect.apply(target, thisArg, args);
24350
+ if (isAutoInstrumentationSuppressed()) return invokeTarget();
24351
+ const self = thisArg;
24352
+ const chat = operation.startsWith("sendMessage");
24353
+ const embedding = operation === "embedContent" || operation === "batchEmbedContents";
24354
+ const start = getCurrentUnixTimestamp();
24355
+ let span;
24356
+ try {
24357
+ span = startSpan(
24358
+ withSpanInstrumentationName(
24359
+ {
24360
+ name: embedding ? operation === "embedContent" ? "embed_content" : "batch_embed_contents" : "generate_content",
24361
+ spanAttributes: { type: "llm" /* LLM */ },
24362
+ event: extractInput(self, args[0], operation)
24363
+ },
24364
+ INSTRUMENTATION_NAMES.GOOGLE_GENERATIVE_AI
24365
+ )
24366
+ );
24367
+ } catch (error) {
24368
+ debugLogger.error("Error starting Google Generative AI span:", error);
24369
+ return invokeTarget();
24370
+ }
24371
+ let ended = false;
24372
+ const finish = (log3) => {
24373
+ if (ended) return;
24374
+ ended = true;
24375
+ try {
24376
+ log3();
24377
+ } catch (error) {
24378
+ debugLogger.error("Error logging Google Generative AI span:", error);
24379
+ }
24380
+ try {
24381
+ span.end();
24382
+ } catch (error) {
24383
+ debugLogger.error("Error ending Google Generative AI span:", error);
24384
+ }
24385
+ };
24386
+ if (chat) {
24387
+ try {
24388
+ void self._sendPromise.then(
24389
+ () => {
24390
+ try {
24391
+ span.log(extractInput(self, args[0], operation));
24392
+ } catch (error) {
24393
+ debugLogger.error("Error capturing Google chat history:", error);
24394
+ }
24395
+ },
24396
+ () => {
24397
+ }
24398
+ );
24399
+ } catch (error) {
24400
+ debugLogger.error("Error observing Google chat history:", error);
24401
+ }
24402
+ }
24403
+ let result;
24404
+ try {
24405
+ result = withCurrent(
24406
+ span,
24407
+ () => runWithAutoInstrumentationSuppressed(invokeTarget)
24408
+ );
24409
+ } catch (error) {
24410
+ finish(() => span.log({ error }));
24411
+ throw error;
24412
+ }
24413
+ void Promise.resolve(result).then(
24414
+ (value) => {
24415
+ try {
24416
+ if ("stream" in value) {
24417
+ let firstToken = false;
24418
+ const partial = { candidates: [] };
24419
+ const candidates = /* @__PURE__ */ new Map();
24420
+ patchStreamIfNeeded(value.stream, {
24421
+ aroundNext: (callback) => withCurrent(span, callback),
24422
+ onChunk: (chunk) => {
24423
+ for (const candidate of chunk.candidates ?? []) {
24424
+ const index = candidate.index ?? 0;
24425
+ const previous = candidates.get(index);
24426
+ const parts = [...previous?.content?.parts ?? []];
24427
+ for (const part of candidate.content?.parts ?? []) {
24428
+ const last = parts[parts.length - 1];
24429
+ if (part.text !== void 0 && last?.text !== void 0) {
24430
+ parts[parts.length - 1] = {
24431
+ ...last,
24432
+ text: last.text + part.text
24433
+ };
24434
+ } else parts.push(part);
24435
+ }
24436
+ candidates.set(index, {
24437
+ ...previous,
24438
+ ...candidate,
24439
+ content: {
24440
+ role: candidate.content?.role ?? previous?.content?.role ?? "model",
24441
+ parts
24442
+ }
24443
+ });
24444
+ }
24445
+ partial.candidates = Array.from(candidates.values());
24446
+ if (chunk.usageMetadata)
24447
+ partial.usageMetadata = chunk.usageMetadata;
24448
+ if (!firstToken && chunk.candidates?.some(
24449
+ (candidate) => candidate.content?.parts.some(
24450
+ (part) => part.text !== void 0 ? part.text.length > 0 : Object.keys(part).length > 0
24451
+ )
24452
+ )) {
24453
+ firstToken = true;
24454
+ span.log({
24455
+ metrics: {
24456
+ time_to_first_token: getCurrentUnixTimestamp() - start
24457
+ }
24458
+ });
24459
+ }
24460
+ },
24461
+ onComplete: () => {
24462
+ },
24463
+ onError: (error) => finish(() => {
24464
+ logResponse(span, partial);
24465
+ span.log({ error });
24466
+ }),
24467
+ onCancel: () => finish(() => logResponse(span, partial))
24468
+ });
24469
+ void value.response.then(
24470
+ (response) => finish(() => logResponse(span, response)),
24471
+ (error) => finish(() => {
24472
+ logResponse(span, partial);
24473
+ span.log({ error });
24474
+ })
24475
+ );
24476
+ } else if ("response" in value) {
24477
+ finish(() => logResponse(span, value.response));
24478
+ } else {
24479
+ const metrics = {};
24480
+ const promptTokens = value.usageMetadata?.promptTokenCount;
24481
+ if (typeof promptTokens === "number" && Number.isFinite(promptTokens) && promptTokens >= 0) {
24482
+ metrics.prompt_tokens = promptTokens;
24483
+ metrics.tokens = promptTokens;
24484
+ }
24485
+ for (const detail of value.usageMetadata?.promptTokenDetails ?? []) {
24486
+ if (detail.modality === "AUDIO" && typeof detail.tokenCount === "number" && Number.isFinite(detail.tokenCount) && detail.tokenCount >= 0) {
24487
+ metrics.prompt_audio_tokens = (metrics.prompt_audio_tokens ?? 0) + detail.tokenCount;
24488
+ }
24489
+ }
24490
+ finish(
24491
+ () => span.log({
24492
+ metrics,
24493
+ output: {
24494
+ count: value.embeddings?.length ?? (value.embedding ? 1 : 0)
24495
+ }
24496
+ })
24497
+ );
24498
+ }
24499
+ } catch (error) {
24500
+ debugLogger.error(
24501
+ "Error observing Google Generative AI result:",
24502
+ error
24503
+ );
24504
+ finish(() => {
24505
+ });
24506
+ }
24507
+ },
24508
+ (error) => finish(() => span.log({ error }))
24509
+ );
24510
+ return result;
24511
+ });
24512
+ }
24513
+ function normalizeContent(message) {
24514
+ const parts = (typeof message === "string" ? [message] : message).map(
24515
+ (part) => typeof part === "string" ? { text: part } : part
24516
+ );
24517
+ return {
24518
+ role: parts.some((part) => part.functionResponse) ? "function" : "user",
24519
+ parts
24520
+ };
24521
+ }
24522
+ function extractInput(self, request, operation) {
24523
+ const model = self.model.replace(/^models\//, "");
24524
+ if (operation === "embedContent" || operation === "batchEmbedContents") {
24525
+ const requests = operation === "batchEmbedContents" ? request.requests : [
24526
+ typeof request === "string" || Array.isArray(request) ? { content: normalizeContent(request) } : request
24527
+ ];
24528
+ const dimensions = requests[0]?.outputDimensionality;
24529
+ return {
24530
+ input: {
24531
+ inputs: convertAttachments(requests).map((item) => ({
24532
+ content: item.content.parts.length === 1 && item.content.parts[0].text !== void 0 ? item.content.parts[0].text : item.content.parts.map((part) => {
24533
+ if (part.text !== void 0)
24534
+ return { type: "text", text: part.text };
24535
+ const mimeType = part.inlineData?.mimeType ?? part.fileData?.mimeType;
24536
+ const data = part.inlineData ? typeof part.inlineData.data === "string" ? `data:${mimeType};base64,${part.inlineData.data}` : part.inlineData.data : part.fileData?.fileUri;
24537
+ return mimeType?.startsWith("image/") ? { type: "image_url", image_url: { url: data } } : { type: "file", file: { file_data: data } };
24538
+ })
24539
+ })),
24540
+ ...dimensions !== void 0 && requests.every((item) => item.outputDimensionality === dimensions) ? { output_dimensions: dimensions } : {}
24541
+ },
24542
+ metadata: { model, provider: "google" }
24543
+ };
24544
+ }
24545
+ const chat = operation.startsWith("sendMessage");
24546
+ const config = chat ? self.params ?? {} : self;
24547
+ const params = typeof request === "string" || Array.isArray(request) ? { contents: [normalizeContent(request)] } : request;
24548
+ const system = params.systemInstruction ?? config.systemInstruction;
24549
+ const systemContent = typeof system === "string" ? { role: "system", parts: [{ text: system }] } : system && "parts" in system ? { ...system, role: "system" } : system ? { role: "system", parts: [system] } : void 0;
24550
+ const contents = [
24551
+ ...systemContent ? [systemContent] : [],
24552
+ ...chat ? self._history : [],
24553
+ ...params.contents
24554
+ ];
24555
+ const metadata = { model, provider: "google" };
24556
+ const generation = params.generationConfig ?? config.generationConfig;
24557
+ for (const key of GENERATION_CONFIG_KEYS) {
24558
+ if (generation && Object.hasOwn(generation, key))
24559
+ metadata[key] = generation[key];
24560
+ }
24561
+ for (const key of ["tools", "toolConfig", "safetySettings"]) {
24562
+ const value = params[key] ?? config[key];
24563
+ if (value !== void 0) metadata[key] = value;
24564
+ }
24565
+ const cached = params.cachedContent ?? config.cachedContent;
24566
+ if (cached)
24567
+ metadata.cachedContent = typeof cached === "string" ? cached : cached.name;
24568
+ return { input: convertAttachments({ model, contents }), metadata };
24569
+ }
24570
+ function convertAttachments(value) {
24571
+ const convert = (node) => {
24572
+ if (Array.isArray(node)) return node.map(convert);
24573
+ if (!isObject(node)) return node;
24574
+ if (isObject(node.inlineData)) {
24575
+ const { data, mimeType } = node.inlineData;
24576
+ const processed = processInputAttachments({
24577
+ type: "file",
24578
+ file: { file_data: `data:${mimeType};base64,${data}` }
24579
+ });
24580
+ if (typeof processed.file.file_data === "string")
24581
+ throw new Error("Unable to convert Google inline data");
24582
+ return {
24583
+ ...node,
24584
+ inlineData: { ...node.inlineData, data: processed.file.file_data }
24585
+ };
24586
+ }
24587
+ return Object.fromEntries(
24588
+ Object.entries(node).map(([key, item]) => [key, convert(item)])
24589
+ );
24590
+ };
24591
+ try {
24592
+ return convert(value);
24593
+ } catch (error) {
24594
+ debugLogger.error(
24595
+ "Error converting Google Generative AI attachments:",
24596
+ error
24597
+ );
24598
+ return value;
24599
+ }
24600
+ }
24601
+ function logResponse(span, response) {
24602
+ const usage = response.usageMetadata;
24603
+ const metrics = {};
24604
+ if (usage) {
24605
+ if (usage.promptTokenCount !== void 0)
24606
+ metrics.prompt_tokens = usage.promptTokenCount;
24607
+ if (usage.candidatesTokenCount !== void 0 || usage.thoughtsTokenCount !== void 0)
24608
+ metrics.completion_tokens = (usage.candidatesTokenCount ?? 0) + (usage.thoughtsTokenCount ?? 0);
24609
+ if (usage.totalTokenCount !== void 0)
24610
+ metrics.tokens = usage.totalTokenCount;
24611
+ if (usage.cachedContentTokenCount !== void 0)
24612
+ metrics.prompt_cached_tokens = usage.cachedContentTokenCount;
24613
+ if (usage.thoughtsTokenCount !== void 0)
24614
+ metrics.completion_reasoning_tokens = usage.thoughtsTokenCount;
24615
+ }
24616
+ span.log({
24617
+ output: convertAttachments({
24618
+ candidates: response.candidates,
24619
+ promptFeedback: response.promptFeedback
24620
+ }),
24621
+ metrics,
24622
+ ...response.modelVersion ? { metadata: { model: response.modelVersion } } : {}
24623
+ });
24624
+ }
24625
+
24261
24626
  // src/instrumentation/plugins/google-genai-channels.ts
24262
24627
  var googleGenAIChannels = defineChannels(
24263
24628
  "@google/genai",
@@ -25901,7 +26266,7 @@ var HuggingFaceTransformersPlugin = class extends BasePlugin {
25901
26266
  getTask(event)
25902
26267
  ),
25903
26268
  extractInput: (args, event) => ({
25904
- input: extractInput(
26269
+ input: extractInput2(
25905
26270
  getTask(event),
25906
26271
  args
25907
26272
  ),
@@ -25991,7 +26356,7 @@ function modelIdentifier(pipeline) {
25991
26356
  }
25992
26357
  return void 0;
25993
26358
  }
25994
- function extractInput(task, args) {
26359
+ function extractInput2(task, args) {
25995
26360
  switch (task) {
25996
26361
  case "feature-extraction":
25997
26362
  return args[0];
@@ -33976,14 +34341,17 @@ function getMetricsFromResponse(response) {
33976
34341
  if (!isRecord(usageMetadata)) {
33977
34342
  continue;
33978
34343
  }
33979
- const inputTokenDetails = usageMetadata.input_token_details;
34344
+ const inputTokenDetails = isRecord(usageMetadata.input_token_details) ? usageMetadata.input_token_details : {};
33980
34345
  const outputTokenDetails = usageMetadata.output_token_details;
33981
34346
  return normalizeTokenMetrics({
33982
34347
  total_tokens: usageMetadata.total_tokens,
33983
34348
  prompt_tokens: usageMetadata.input_tokens,
33984
34349
  completion_tokens: usageMetadata.output_tokens,
33985
- prompt_cache_creation_tokens: isRecord(inputTokenDetails) ? inputTokenDetails.cache_creation : void 0,
33986
- prompt_cached_tokens: isRecord(inputTokenDetails) ? inputTokenDetails.cache_read : void 0,
34350
+ // Prefer TTL-specific cache writes over the aggregate when available.
34351
+ prompt_cache_creation_tokens: inputTokenDetails.ephemeral_5m_input_tokens == null && inputTokenDetails.ephemeral_1h_input_tokens == null ? inputTokenDetails.cache_creation : void 0,
34352
+ prompt_cache_creation_5m_tokens: inputTokenDetails.ephemeral_5m_input_tokens,
34353
+ prompt_cache_creation_1h_tokens: inputTokenDetails.ephemeral_1h_input_tokens,
34354
+ prompt_cached_tokens: inputTokenDetails.cache_read,
33987
34355
  completion_reasoning_tokens: isRecord(outputTokenDetails) ? outputTokenDetails.reasoning : void 0
33988
34356
  });
33989
34357
  }
@@ -36342,6 +36710,477 @@ function logInstrumentationError5(context, error) {
36342
36710
  debugLogger.debug(`${context}:`, error);
36343
36711
  }
36344
36712
 
36713
+ // src/instrumentation/plugins/elevenlabs-channels.ts
36714
+ var elevenLabsChannels = defineChannels(
36715
+ "@elevenlabs/elevenlabs-js",
36716
+ {
36717
+ convert: channel({
36718
+ channelName: "textToSpeech.convert",
36719
+ kind: "async"
36720
+ }),
36721
+ stream: channel({
36722
+ channelName: "textToSpeech.stream",
36723
+ kind: "async"
36724
+ }),
36725
+ convertWithTimestamps: channel({ channelName: "textToSpeech.convertWithTimestamps", kind: "async" }),
36726
+ streamWithTimestamps: channel({ channelName: "textToSpeech.streamWithTimestamps", kind: "async" }),
36727
+ transcribe: channel({ channelName: "speechToText.convert", kind: "async" })
36728
+ },
36729
+ { instrumentationName: INSTRUMENTATION_NAMES.ELEVENLABS }
36730
+ );
36731
+
36732
+ // src/instrumentation/plugins/elevenlabs-plugin.ts
36733
+ var ElevenLabsPlugin = class extends BasePlugin {
36734
+ onEnable() {
36735
+ for (const method of [
36736
+ "convert",
36737
+ "stream",
36738
+ "convertWithTimestamps",
36739
+ "streamWithTimestamps"
36740
+ ]) {
36741
+ this.unsubscribers.push(
36742
+ interceptCall2(
36743
+ elevenLabsChannels[method],
36744
+ `elevenlabs.textToSpeech.${method}`,
36745
+ ([voice, request]) => ({
36746
+ input: {
36747
+ operation: "speech",
36748
+ prompt: request.text,
36749
+ parameters: {
36750
+ voice,
36751
+ format: request.outputFormat,
36752
+ language: request.languageCode,
36753
+ speed: request.voiceSettings?.speed
36754
+ }
36755
+ },
36756
+ metadata: {
36757
+ provider: "elevenlabs",
36758
+ model: request.modelId ?? "eleven_multilingual_v2"
36759
+ }
36760
+ }),
36761
+ (value, args, span, finish, headers, started) => captureSpeech(
36762
+ value,
36763
+ args[1],
36764
+ method,
36765
+ span,
36766
+ finish,
36767
+ started,
36768
+ headers
36769
+ )
36770
+ )
36771
+ );
36772
+ }
36773
+ this.unsubscribers.push(
36774
+ interceptCall2(
36775
+ elevenLabsChannels.transcribe,
36776
+ "elevenlabs.speechToText.convert",
36777
+ ([request]) => {
36778
+ if (request.webhook) return void 0;
36779
+ const file = request.file;
36780
+ const filename = typeof File !== "undefined" && file instanceof File ? file.name : "audio";
36781
+ const contentType = file instanceof Blob ? file.type || "application/octet-stream" : "application/octet-stream";
36782
+ const blob = file instanceof Blob ? file : file instanceof Uint8Array ? new Blob([new Uint8Array(file)], { type: contentType }) : file instanceof ArrayBuffer ? new Blob([file.slice(0)], { type: contentType }) : void 0;
36783
+ const fileData = blob ? new Attachment({ data: blob, filename, contentType }) : request.cloudStorageUrl;
36784
+ return {
36785
+ input: {
36786
+ operation: "transcribe",
36787
+ content: fileData ? [{ type: "file", file: { filename, file_data: fileData } }] : [],
36788
+ parameters: {
36789
+ language: request.languageCode,
36790
+ timestamp_granularities: request.timestampsGranularity
36791
+ }
36792
+ },
36793
+ metadata: { provider: "elevenlabs", model: request.modelId }
36794
+ };
36795
+ },
36796
+ (value, _args, span, finish) => {
36797
+ const result = value;
36798
+ const transcripts = result.transcripts ?? [result];
36799
+ span.log({
36800
+ output: {
36801
+ content: transcripts.flatMap(
36802
+ (transcript) => typeof transcript.text === "string" ? [{ type: "text", text: transcript.text }] : []
36803
+ ),
36804
+ annotations: {
36805
+ language: result.languageCode,
36806
+ words: result.words ?? (result.transcripts ? result.transcripts.flatMap(
36807
+ (transcript) => transcript.words ?? []
36808
+ ) : void 0)
36809
+ }
36810
+ }
36811
+ });
36812
+ finish();
36813
+ },
36814
+ ([request], span) => {
36815
+ const file = request.file;
36816
+ if (!isAsyncIterable(file)) return;
36817
+ const chunks = [];
36818
+ const filename = isObject(file) && typeof file.path === "string" ? file.path.split(/[\\/]/).pop() || "audio" : "audio";
36819
+ observeAudioStream(
36820
+ file,
36821
+ (chunk) => chunks.push(new Uint8Array(chunk)),
36822
+ () => {
36823
+ const contentType = "application/octet-stream";
36824
+ const data = new Blob(chunks, {
36825
+ type: contentType
36826
+ });
36827
+ chunks.length = 0;
36828
+ span.log({
36829
+ input: {
36830
+ content: [
36831
+ {
36832
+ type: "file",
36833
+ file: {
36834
+ filename,
36835
+ file_data: new Attachment({
36836
+ data,
36837
+ filename,
36838
+ contentType
36839
+ })
36840
+ }
36841
+ }
36842
+ ]
36843
+ }
36844
+ });
36845
+ },
36846
+ () => {
36847
+ chunks.length = 0;
36848
+ },
36849
+ span
36850
+ );
36851
+ }
36852
+ )
36853
+ );
36854
+ }
36855
+ onDisable() {
36856
+ this.unsubscribers = unsubscribeAll(this.unsubscribers);
36857
+ }
36858
+ };
36859
+ function interceptCall2(channel2, name, input, output, beforeInvoke) {
36860
+ return channel2.intercept((target, self, args) => {
36861
+ const invoke2 = () => Reflect.apply(target, self, args);
36862
+ if (isAutoInstrumentationSuppressed()) return invoke2();
36863
+ const started = Date.now() / 1e3;
36864
+ let span;
36865
+ try {
36866
+ const event = input(args);
36867
+ if (event !== void 0)
36868
+ span = startSpan(
36869
+ withSpanInstrumentationName(
36870
+ {
36871
+ name,
36872
+ spanAttributes: { type: "llm" /* LLM */ },
36873
+ event
36874
+ },
36875
+ INSTRUMENTATION_NAMES.ELEVENLABS
36876
+ )
36877
+ );
36878
+ } catch (error) {
36879
+ debugLogger.error("Error starting ElevenLabs span", error);
36880
+ return invoke2();
36881
+ }
36882
+ if (!span) return invoke2();
36883
+ const activeSpan = span;
36884
+ let ended = false;
36885
+ const finish = (error) => {
36886
+ if (ended) return;
36887
+ ended = true;
36888
+ try {
36889
+ if (error !== void 0) activeSpan.log({ error });
36890
+ activeSpan.end();
36891
+ } catch (loggingError) {
36892
+ debugLogger.error("Error ending ElevenLabs span", loggingError);
36893
+ }
36894
+ };
36895
+ try {
36896
+ beforeInvoke?.(args, span);
36897
+ } catch (error) {
36898
+ debugLogger.error("Error observing ElevenLabs input", error);
36899
+ }
36900
+ let result;
36901
+ try {
36902
+ result = withCurrent(
36903
+ span,
36904
+ () => runWithAutoInstrumentationSuppressed(invoke2)
36905
+ );
36906
+ } catch (error) {
36907
+ finish(error);
36908
+ throw error;
36909
+ }
36910
+ const capture = (value, headers) => {
36911
+ try {
36912
+ output(value, args, span, finish, headers, started);
36913
+ } catch (error) {
36914
+ debugLogger.error("Error capturing ElevenLabs output", error);
36915
+ finish();
36916
+ }
36917
+ };
36918
+ try {
36919
+ if (isObject(result) && typeof result.withRawResponse === "function") {
36920
+ void result.withRawResponse().then(
36921
+ ({
36922
+ data,
36923
+ rawResponse
36924
+ }) => capture(data, rawResponse?.headers),
36925
+ finish
36926
+ );
36927
+ } else {
36928
+ void Promise.resolve(result).then((value) => capture(value), finish);
36929
+ }
36930
+ } catch (error) {
36931
+ debugLogger.error("Error observing ElevenLabs result", error);
36932
+ finish();
36933
+ }
36934
+ return result;
36935
+ });
36936
+ }
36937
+ function captureSpeech(value, request, method, span, finish, started, headers) {
36938
+ const format = request.outputFormat ?? "mp3_44100_128";
36939
+ const formatType = format.startsWith("mp3_") ? "audio/mpeg" : format.startsWith("pcm_") ? "audio/pcm" : format.startsWith("opus_") ? "audio/ogg" : format.startsWith("ulaw_") ? "audio/basic" : format.startsWith("alaw_") ? "audio/x-alaw" : void 0;
36940
+ const headerType = headers?.get("content-type")?.split(";")[0];
36941
+ const contentType = headerType?.startsWith("audio/") ? headerType : formatType;
36942
+ const disposition = headers?.get("content-disposition");
36943
+ const headerFilename = disposition?.match(
36944
+ /filename="([^"]+)"|filename=([^;]+)/i
36945
+ );
36946
+ const filename = headerFilename?.[1] ?? headerFilename?.[2]?.trim() ?? `speech.${contentType ? getExtensionFromMediaType(contentType) : "bin"}`;
36947
+ const chunks = [];
36948
+ const alignments = [];
36949
+ let bytes = 0;
36950
+ let first = true;
36951
+ let stopped = false;
36952
+ const observe = (chunk) => {
36953
+ if (stopped || chunk.byteLength === 0) return;
36954
+ if (first && method.startsWith("stream")) {
36955
+ span.log({
36956
+ metrics: { time_to_first_token: Date.now() / 1e3 - started }
36957
+ });
36958
+ }
36959
+ first = false;
36960
+ chunks.push(new Uint8Array(chunk));
36961
+ bytes += chunk.byteLength;
36962
+ };
36963
+ const complete = () => {
36964
+ if (stopped) return;
36965
+ stopped = true;
36966
+ try {
36967
+ const content = [];
36968
+ if (contentType && bytes) {
36969
+ const data = new Uint8Array(bytes);
36970
+ let offset = 0;
36971
+ for (const chunk of chunks) {
36972
+ data.set(chunk, offset);
36973
+ offset += chunk.length;
36974
+ }
36975
+ content.push({
36976
+ type: "file",
36977
+ file: {
36978
+ filename,
36979
+ byte_size: bytes,
36980
+ file_data: new Attachment({
36981
+ data: new Blob([data], { type: contentType }),
36982
+ filename,
36983
+ contentType
36984
+ })
36985
+ }
36986
+ });
36987
+ }
36988
+ span.log({
36989
+ output: {
36990
+ content,
36991
+ ...alignments.length ? { annotations: alignments } : {}
36992
+ }
36993
+ });
36994
+ } finally {
36995
+ chunks.length = 0;
36996
+ finish();
36997
+ }
36998
+ };
36999
+ const cancel = (error) => {
37000
+ stopped = true;
37001
+ chunks.length = 0;
37002
+ finish(error);
37003
+ };
37004
+ const timestampChunk = (chunk) => {
37005
+ const binary = atob(chunk.audioBase64);
37006
+ observe(Uint8Array.from(binary, (character) => character.charCodeAt(0)));
37007
+ if (chunk.alignment || chunk.normalizedAlignment)
37008
+ alignments.push({
37009
+ alignment: chunk.alignment,
37010
+ normalized_alignment: chunk.normalizedAlignment
37011
+ });
37012
+ };
37013
+ if (method === "convertWithTimestamps") {
37014
+ timestampChunk(value);
37015
+ complete();
37016
+ } else if (method === "streamWithTimestamps") {
37017
+ patchStreamIfNeeded(value, {
37018
+ shouldCollect: (chunk) => {
37019
+ try {
37020
+ timestampChunk(chunk);
37021
+ } catch (error) {
37022
+ debugLogger.error("Error collecting ElevenLabs timestamps", error);
37023
+ cancel();
37024
+ }
37025
+ return false;
37026
+ },
37027
+ onComplete: complete,
37028
+ onCancel: () => cancel(),
37029
+ onError: cancel,
37030
+ aroundNext: (next) => withCurrent(span, next)
37031
+ });
37032
+ } else {
37033
+ observeAudioStream(value, observe, complete, cancel, span);
37034
+ }
37035
+ }
37036
+ function observeAudioStream(value, observe, complete, cancel, span) {
37037
+ let ended = false;
37038
+ const safeObserve = (chunk) => {
37039
+ if (ended) return;
37040
+ try {
37041
+ observe(chunk);
37042
+ } catch (error) {
37043
+ debugLogger.error("Error collecting ElevenLabs audio", error);
37044
+ end(false);
37045
+ }
37046
+ };
37047
+ const end = (success, error) => {
37048
+ if (ended) return;
37049
+ ended = true;
37050
+ try {
37051
+ if (success) complete();
37052
+ else cancel(error);
37053
+ } catch (loggingError) {
37054
+ debugLogger.error("Error logging ElevenLabs audio", loggingError);
37055
+ cancel();
37056
+ }
37057
+ };
37058
+ if (!isObject(value) || !Object.isExtensible(value)) {
37059
+ end(false);
37060
+ return;
37061
+ }
37062
+ if (typeof value.read === "function" && typeof value.on === "function") {
37063
+ value.on("end", () => end(true));
37064
+ value.on("close", () => end(false));
37065
+ const emit2 = value.emit;
37066
+ if (typeof emit2 === "function")
37067
+ value.emit = function(event, ...args) {
37068
+ if (event === "data" && args[0] instanceof Uint8Array)
37069
+ safeObserve(args[0]);
37070
+ if (event === "error") end(false, args[0]);
37071
+ return Reflect.apply(emit2, this, [event, ...args]);
37072
+ };
37073
+ return;
37074
+ }
37075
+ if (typeof value.getReader === "function") {
37076
+ const webStream = value;
37077
+ const pipeTo = webStream.pipeTo;
37078
+ const pipeThrough = webStream.pipeThrough;
37079
+ webStream.pipeTo = function(destination, options) {
37080
+ if (!isObject(destination) || this.locked || destination.locked)
37081
+ return pipeTo.call(this, destination, options);
37082
+ const tap = new TransformStream({
37083
+ transform(chunk, controller) {
37084
+ safeObserve(chunk);
37085
+ controller.enqueue(chunk);
37086
+ },
37087
+ flush() {
37088
+ end(true);
37089
+ }
37090
+ });
37091
+ const observed = pipeThrough.call(
37092
+ this,
37093
+ tap,
37094
+ options
37095
+ );
37096
+ return observed.pipeTo(destination, options).catch((error) => {
37097
+ end(false, error);
37098
+ throw error;
37099
+ });
37100
+ };
37101
+ webStream.pipeThrough = function(transform, options) {
37102
+ if (this.locked || transform.writable.locked || transform.readable.locked)
37103
+ return pipeThrough.call(this, transform, options);
37104
+ const result = webStream.pipeTo.call(this, transform.writable, options);
37105
+ void result.catch(() => {
37106
+ });
37107
+ return transform.readable;
37108
+ };
37109
+ const getReader = value.getReader;
37110
+ value.getReader = function(...args) {
37111
+ const reader = Reflect.apply(getReader, this, args);
37112
+ const read3 = reader.read;
37113
+ reader.read = function(...readArgs) {
37114
+ return Promise.resolve(
37115
+ withCurrent(span, () => Reflect.apply(read3, this, readArgs))
37116
+ ).then(
37117
+ (result) => {
37118
+ if (result.value) safeObserve(result.value);
37119
+ if (result.done) end(true);
37120
+ return result;
37121
+ },
37122
+ (error) => {
37123
+ end(false, error);
37124
+ throw error;
37125
+ }
37126
+ );
37127
+ };
37128
+ const readerCancel = reader.cancel;
37129
+ reader.cancel = function(...cancelArgs) {
37130
+ const result = Reflect.apply(readerCancel, this, cancelArgs);
37131
+ end(false);
37132
+ return result;
37133
+ };
37134
+ return reader;
37135
+ };
37136
+ const streamCancel = value.cancel;
37137
+ if (typeof streamCancel === "function")
37138
+ value.cancel = function(...args) {
37139
+ const result = Reflect.apply(streamCancel, this, args);
37140
+ void Promise.resolve(result).then(
37141
+ () => end(false),
37142
+ () => {
37143
+ }
37144
+ );
37145
+ return result;
37146
+ };
37147
+ }
37148
+ if (typeof value.getReader === "function" && typeof value.values === "function") {
37149
+ const values = value.values;
37150
+ const iterate = function(...args) {
37151
+ const iterator = Reflect.apply(values, this, args);
37152
+ patchStreamIfNeeded(iterator, {
37153
+ shouldCollect(chunk) {
37154
+ safeObserve(chunk);
37155
+ return false;
37156
+ },
37157
+ onComplete: () => end(true),
37158
+ onCancel: () => end(false),
37159
+ onError: (error) => end(false, error),
37160
+ aroundNext: (next) => withCurrent(span, next)
37161
+ });
37162
+ return iterator;
37163
+ };
37164
+ value.values = iterate;
37165
+ Object.defineProperty(value, Symbol.asyncIterator, {
37166
+ configurable: true,
37167
+ writable: true,
37168
+ value: iterate
37169
+ });
37170
+ } else if (isAsyncIterable(value)) {
37171
+ patchStreamIfNeeded(value, {
37172
+ shouldCollect: (chunk) => {
37173
+ safeObserve(chunk);
37174
+ return false;
37175
+ },
37176
+ onComplete: () => end(true),
37177
+ onCancel: () => end(false),
37178
+ onError: (error) => end(false, error),
37179
+ aroundNext: (next) => withCurrent(span, next)
37180
+ });
37181
+ } else if (typeof value.getReader !== "function") end(false);
37182
+ }
37183
+
36345
37184
  // src/instrumentation/plugins/voyageai-channels.ts
36346
37185
  var voyageAIChannels = defineChannels(
36347
37186
  "voyageai",
@@ -36409,7 +37248,7 @@ var VoyageAIPlugin = class extends BasePlugin {
36409
37248
  this.unsubscribers = unsubscribeAll(this.unsubscribers);
36410
37249
  }
36411
37250
  };
36412
- function interceptVoyageAICall(channel2, name, extractInput3, extractOutput2, extractMetrics2 = extractUsageMetrics3) {
37251
+ function interceptVoyageAICall(channel2, name, extractInput4, extractOutput2, extractMetrics2 = extractUsageMetrics3) {
36413
37252
  return channel2.intercept((target, thisArg, args) => {
36414
37253
  const invokeTarget = () => Reflect.apply(target, thisArg, args);
36415
37254
  if (isAutoInstrumentationSuppressed()) {
@@ -36417,7 +37256,7 @@ function interceptVoyageAICall(channel2, name, extractInput3, extractOutput2, ex
36417
37256
  }
36418
37257
  let span;
36419
37258
  try {
36420
- const { input, metadata } = extractInput3(args);
37259
+ const { input, metadata } = extractInput4(args);
36421
37260
  span = startSpan(
36422
37261
  withSpanInstrumentationName(
36423
37262
  {
@@ -37216,6 +38055,7 @@ var BraintrustPlugin = class extends BasePlugin {
37216
38055
  cloudflareThinkPlugin = null;
37217
38056
  cursorSDKPlugin = null;
37218
38057
  openAIAgentsPlugin = null;
38058
+ googleGenerativeAIPlugin = null;
37219
38059
  googleGenAIPlugin = null;
37220
38060
  huggingFacePlugin = null;
37221
38061
  huggingFaceTransformersPlugin = null;
@@ -37234,6 +38074,7 @@ var BraintrustPlugin = class extends BasePlugin {
37234
38074
  langSmithPlugin = null;
37235
38075
  piCodingAgentPlugin = null;
37236
38076
  strandsAgentSDKPlugin = null;
38077
+ elevenLabsPlugin = null;
37237
38078
  voyageAIPlugin = null;
37238
38079
  cloudflareAIChatPlugin = null;
37239
38080
  cloudflareAgentsPlugin = null;
@@ -37275,6 +38116,10 @@ var BraintrustPlugin = class extends BasePlugin {
37275
38116
  this.openAIAgentsPlugin = new OpenAIAgentsPlugin();
37276
38117
  this.openAIAgentsPlugin.enable();
37277
38118
  }
38119
+ if (integrations.googleGenerativeAI !== false) {
38120
+ this.googleGenerativeAIPlugin = new GoogleGenerativeAIPlugin();
38121
+ this.googleGenerativeAIPlugin.enable();
38122
+ }
37278
38123
  if (integrations.googleGenAI !== false && integrations.google !== false) {
37279
38124
  this.googleGenAIPlugin = new GoogleGenAIPlugin();
37280
38125
  this.googleGenAIPlugin.enable();
@@ -37309,6 +38154,10 @@ var BraintrustPlugin = class extends BasePlugin {
37309
38154
  this.coherePlugin = new CoherePlugin();
37310
38155
  this.coherePlugin.enable();
37311
38156
  }
38157
+ if (integrations.elevenlabs !== false) {
38158
+ this.elevenLabsPlugin = new ElevenLabsPlugin();
38159
+ this.elevenLabsPlugin.enable();
38160
+ }
37312
38161
  if (integrations.voyageai !== false) {
37313
38162
  this.voyageAIPlugin = new VoyageAIPlugin();
37314
38163
  this.voyageAIPlugin.enable();
@@ -37393,6 +38242,10 @@ var BraintrustPlugin = class extends BasePlugin {
37393
38242
  this.openAIAgentsPlugin.disable();
37394
38243
  this.openAIAgentsPlugin = null;
37395
38244
  }
38245
+ if (this.googleGenerativeAIPlugin) {
38246
+ this.googleGenerativeAIPlugin.disable();
38247
+ this.googleGenerativeAIPlugin = null;
38248
+ }
37396
38249
  if (this.googleGenAIPlugin) {
37397
38250
  this.googleGenAIPlugin.disable();
37398
38251
  this.googleGenAIPlugin = null;
@@ -37429,6 +38282,10 @@ var BraintrustPlugin = class extends BasePlugin {
37429
38282
  this.coherePlugin.disable();
37430
38283
  this.coherePlugin = null;
37431
38284
  }
38285
+ if (this.elevenLabsPlugin) {
38286
+ this.elevenLabsPlugin.disable();
38287
+ this.elevenLabsPlugin = null;
38288
+ }
37432
38289
  if (this.voyageAIPlugin) {
37433
38290
  this.voyageAIPlugin.disable();
37434
38291
  this.voyageAIPlugin = null;
@@ -37522,6 +38379,8 @@ var envIntegrationAliases = {
37522
38379
  "openai-agents-core": "openAIAgents",
37523
38380
  openaiagentscore: "openAIAgents",
37524
38381
  google: "google",
38382
+ "google-generative-ai": "googleGenerativeAI",
38383
+ googlegenerativeai: "googleGenerativeAI",
37525
38384
  "google-genai": "googleGenAI",
37526
38385
  googlegenai: "googleGenAI",
37527
38386
  huggingface: "huggingface",
@@ -37555,7 +38414,9 @@ var envIntegrationAliases = {
37555
38414
  langsmith: "langsmith",
37556
38415
  voyage: "voyageai",
37557
38416
  "voyage-ai": "voyageai",
37558
- voyageai: "voyageai"
38417
+ voyageai: "voyageai",
38418
+ elevenlabs: "elevenlabs",
38419
+ "@elevenlabs/elevenlabs-js": "elevenlabs"
37559
38420
  };
37560
38421
  function getDefaultInstrumentationIntegrations() {
37561
38422
  return {
@@ -37566,6 +38427,7 @@ function getDefaultInstrumentationIntegrations() {
37566
38427
  aisdk: true,
37567
38428
  google: true,
37568
38429
  googleGenAI: true,
38430
+ googleGenerativeAI: true,
37569
38431
  googleADK: true,
37570
38432
  huggingface: true,
37571
38433
  claudeAgentSDK: true,
@@ -37591,6 +38453,7 @@ function getDefaultInstrumentationIntegrations() {
37591
38453
  langgraph: true,
37592
38454
  langsmith: true,
37593
38455
  voyageai: true,
38456
+ elevenlabs: true,
37594
38457
  piCodingAgent: true,
37595
38458
  strandsAgentSDK: true,
37596
38459
  cloudflareAgents: true
@@ -37907,9 +38770,11 @@ __export(exports_exports, {
37907
38770
  wrapCohere: () => wrapCohere,
37908
38771
  wrapCopilotClient: () => wrapCopilotClient,
37909
38772
  wrapCursorSDK: () => wrapCursorSDK,
38773
+ wrapElevenLabs: () => wrapElevenLabs,
37910
38774
  wrapGenkit: () => wrapGenkit,
37911
38775
  wrapGoogleADK: () => wrapGoogleADK,
37912
38776
  wrapGoogleGenAI: () => wrapGoogleGenAI,
38777
+ wrapGoogleGenerativeAI: () => wrapGoogleGenerativeAI,
37913
38778
  wrapGroq: () => wrapGroq,
37914
38779
  wrapHuggingFace: () => wrapHuggingFace,
37915
38780
  wrapHuggingFaceTransformers: () => wrapHuggingFaceTransformers,
@@ -39519,7 +40384,7 @@ function extractToolCallsFromBlocks(blocks) {
39519
40384
  if (!Array.isArray(blocks)) return [];
39520
40385
  return extractToolCallsFromSteps([{ content: blocks }]);
39521
40386
  }
39522
- function extractInput2(params) {
40387
+ function extractInput3(params) {
39523
40388
  return params?.prompt ?? params?.messages ?? params?.system;
39524
40389
  }
39525
40390
  var V2_EXCLUDE_KEYS = /* @__PURE__ */ new Set([
@@ -39541,7 +40406,7 @@ function BraintrustMiddleware(config = {}) {
39541
40406
  params,
39542
40407
  model: modelFromWrapGenerate
39543
40408
  }) => {
39544
- const rawInput = extractInput2(params);
40409
+ const rawInput = extractInput3(params);
39545
40410
  const processedInput = processInputAttachments(rawInput);
39546
40411
  const spanArgs = {
39547
40412
  name: config.spanInfo?.name || "ai-sdk.doGenerate",
@@ -39605,7 +40470,7 @@ function BraintrustMiddleware(config = {}) {
39605
40470
  }
39606
40471
  },
39607
40472
  wrapStream: async ({ doStream, params }) => {
39608
- const rawInput = extractInput2(params);
40473
+ const rawInput = extractInput3(params);
39609
40474
  const processedInput = processInputAttachments(rawInput);
39610
40475
  const spanArgs = {
39611
40476
  name: config.spanInfo?.name || "ai-sdk.doStream",
@@ -42998,6 +43863,75 @@ function isModuleNamespace5(value) {
42998
43863
  }
42999
43864
  }
43000
43865
 
43866
+ // src/wrappers/google-generative-ai.ts
43867
+ function wrapGoogleGenerativeAI(client) {
43868
+ if (!isObject(client) || typeof client.getGenerativeModel !== "function")
43869
+ return client;
43870
+ return wrapClient(client);
43871
+ }
43872
+ var proxies = /* @__PURE__ */ new WeakMap();
43873
+ function wrapClient(client) {
43874
+ const cached = proxies.get(client);
43875
+ if (cached) return cached;
43876
+ const proxy = new Proxy(client, {
43877
+ get(target, prop, receiver) {
43878
+ const value = Reflect.get(target, prop, receiver);
43879
+ if (typeof value !== "function") return value;
43880
+ if (prop === "getGenerativeModel" || prop === "getGenerativeModelFromCachedContent" || prop === "startChat") {
43881
+ return (...args) => wrapClient(Reflect.apply(value, target, args));
43882
+ }
43883
+ switch (prop) {
43884
+ case "generateContent":
43885
+ return (...args) => googleGenerativeAIChannels.generateContent.invoke(
43886
+ value,
43887
+ target,
43888
+ args,
43889
+ {}
43890
+ );
43891
+ case "generateContentStream":
43892
+ return (...args) => googleGenerativeAIChannels.generateContentStream.invoke(
43893
+ value,
43894
+ target,
43895
+ args,
43896
+ {}
43897
+ );
43898
+ case "embedContent":
43899
+ return (...args) => googleGenerativeAIChannels.embedContent.invoke(
43900
+ value,
43901
+ target,
43902
+ args,
43903
+ {}
43904
+ );
43905
+ case "batchEmbedContents":
43906
+ return (...args) => googleGenerativeAIChannels.batchEmbedContents.invoke(
43907
+ value,
43908
+ target,
43909
+ args,
43910
+ {}
43911
+ );
43912
+ case "sendMessage":
43913
+ return (...args) => googleGenerativeAIChannels.sendMessage.invoke(
43914
+ value,
43915
+ target,
43916
+ args,
43917
+ {}
43918
+ );
43919
+ case "sendMessageStream":
43920
+ return (...args) => googleGenerativeAIChannels.sendMessageStream.invoke(
43921
+ value,
43922
+ target,
43923
+ args,
43924
+ {}
43925
+ );
43926
+ }
43927
+ return value.bind(target);
43928
+ }
43929
+ });
43930
+ proxies.set(client, proxy);
43931
+ proxies.set(proxy, proxy);
43932
+ return proxy;
43933
+ }
43934
+
43001
43935
  // src/wrappers/google-genai.ts
43002
43936
  function wrapGoogleGenAI(googleGenAI) {
43003
43937
  if (!googleGenAI || typeof googleGenAI !== "object") {
@@ -44995,8 +45929,8 @@ function normalizeScores(result) {
44995
45929
  (s) => s !== null && s !== void 0 && typeof s === "object" && isScore(s)
44996
45930
  );
44997
45931
  }
44998
- if (typeof result === "object" && result !== null && isScore(result)) {
44999
- return [result];
45932
+ if (typeof result === "object" && result !== null && "score" in result) {
45933
+ return [{ ...result, name: result.name ?? "score" }];
45000
45934
  }
45001
45935
  return [];
45002
45936
  }
@@ -47579,19 +48513,29 @@ function buildSpanScores(results) {
47579
48513
  function _internalPrepareEvaluatorScore(scoreValue, name) {
47580
48514
  if (scoreValue === null) return { results: null };
47581
48515
  if (Array.isArray(scoreValue)) {
48516
+ const names = /* @__PURE__ */ new Set();
47582
48517
  for (const score of scoreValue) {
47583
48518
  if (!(typeof score === "object" && !isEmpty2(score))) {
47584
48519
  throw new Error(
47585
48520
  `When returning an array of scores, each score must be a non-empty object. Got: ${JSON.stringify(score)}`
47586
48521
  );
47587
48522
  }
48523
+ if (typeof score.name !== "string") {
48524
+ throw new Error(
48525
+ `When returning an array of scores, each score must have a name. Got: ${JSON.stringify(score)}`
48526
+ );
48527
+ }
48528
+ if (names.has(score.name)) {
48529
+ throw new Error(`Duplicate score name '${score.name}' in score array`);
48530
+ }
48531
+ names.add(score.name);
47588
48532
  }
47589
48533
  }
47590
48534
  let results;
47591
48535
  if (Array.isArray(scoreValue)) {
47592
48536
  results = scoreValue;
47593
48537
  } else if (typeof scoreValue === "object" && !isEmpty2(scoreValue)) {
47594
- results = [scoreValue];
48538
+ results = [{ ...scoreValue, name: scoreValue.name ?? name }];
47595
48539
  } else {
47596
48540
  results = [{ name, score: scoreValue }];
47597
48541
  }
@@ -50349,6 +51293,65 @@ var evaluatorDefinitionsSchema = z13.record(
50349
51293
  evaluatorDefinitionSchema
50350
51294
  );
50351
51295
 
51296
+ // src/wrappers/elevenlabs.ts
51297
+ var clients = /* @__PURE__ */ new WeakMap();
51298
+ function wrapElevenLabs(client) {
51299
+ if (!isObject(client) || !isObject(client.textToSpeech) || typeof client.textToSpeech.convert !== "function") {
51300
+ debugLogger.warn("Unsupported ElevenLabs client. Not wrapping.");
51301
+ return client;
51302
+ }
51303
+ const cached = clients.get(client);
51304
+ if (cached) return cached;
51305
+ const sdk = client;
51306
+ const speech = new Proxy(sdk.textToSpeech, {
51307
+ get(target, prop, receiver) {
51308
+ switch (prop) {
51309
+ case "convert":
51310
+ case "stream":
51311
+ return (...args) => elevenLabsChannels[prop].invoke(target[prop], target, args, {});
51312
+ case "convertWithTimestamps":
51313
+ return (...args) => elevenLabsChannels.convertWithTimestamps.invoke(
51314
+ target.convertWithTimestamps,
51315
+ target,
51316
+ args,
51317
+ {}
51318
+ );
51319
+ case "streamWithTimestamps":
51320
+ return (...args) => elevenLabsChannels.streamWithTimestamps.invoke(
51321
+ target.streamWithTimestamps,
51322
+ target,
51323
+ args,
51324
+ {}
51325
+ );
51326
+ default:
51327
+ return Reflect.get(target, prop, receiver);
51328
+ }
51329
+ }
51330
+ });
51331
+ const transcription = new Proxy(sdk.speechToText, {
51332
+ get(target, prop, receiver) {
51333
+ if (prop === "convert")
51334
+ return (request, options) => elevenLabsChannels.transcribe.invoke(
51335
+ target.convert,
51336
+ target,
51337
+ [request, options],
51338
+ {}
51339
+ );
51340
+ return Reflect.get(target, prop, receiver);
51341
+ }
51342
+ });
51343
+ const proxy = new Proxy(sdk, {
51344
+ get(target, prop, receiver) {
51345
+ if (prop === "textToSpeech") return speech;
51346
+ if (prop === "speechToText") return transcription;
51347
+ return Reflect.get(target, prop, receiver);
51348
+ }
51349
+ });
51350
+ clients.set(client, proxy);
51351
+ clients.set(proxy, proxy);
51352
+ return proxy;
51353
+ }
51354
+
50352
51355
  // src/edge-light/index.ts
50353
51356
  configureEdgeLight();
50354
51357
  export {
@@ -50514,9 +51517,11 @@ export {
50514
51517
  wrapCohere,
50515
51518
  wrapCopilotClient,
50516
51519
  wrapCursorSDK,
51520
+ wrapElevenLabs,
50517
51521
  wrapGenkit,
50518
51522
  wrapGoogleADK,
50519
51523
  wrapGoogleGenAI,
51524
+ wrapGoogleGenerativeAI,
50520
51525
  wrapGroq,
50521
51526
  wrapHuggingFace,
50522
51527
  wrapHuggingFaceTransformers,