braintrust 3.31.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 +736 -0
  2. package/dev/dist/index.d.ts +736 -0
  3. package/dev/dist/index.js +1280 -428
  4. package/dev/dist/index.mjs +859 -7
  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 +104 -2
  10. package/dist/auto-instrumentations/bundler/next.mjs +3 -3
  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 +124 -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 +2124 -2
  27. package/dist/browser.d.ts +2124 -2
  28. package/dist/browser.js +994 -10
  29. package/dist/browser.mjs +994 -10
  30. package/dist/{chunk-AJT4FR25.mjs → chunk-4QSAHP7D.mjs} +818 -5
  31. package/dist/{chunk-4AQGZS6X.js → chunk-AW4QECG5.js} +47 -4
  32. package/dist/{chunk-V32LW47Z.js → chunk-BTRLPQG5.js} +1663 -850
  33. package/dist/{chunk-CE3BLB2L.mjs → chunk-WV6QZI2W.mjs} +46 -3
  34. package/dist/cli.js +923 -8
  35. package/dist/edge-light.d.mts +1 -1
  36. package/dist/edge-light.d.ts +1 -1
  37. package/dist/edge-light.js +994 -10
  38. package/dist/edge-light.mjs +994 -10
  39. package/dist/index.d.mts +2124 -2
  40. package/dist/index.d.ts +2124 -2
  41. package/dist/index.js +581 -447
  42. package/dist/index.mjs +136 -2
  43. package/dist/instrumentation/index.d.mts +434 -0
  44. package/dist/instrumentation/index.d.ts +434 -0
  45. package/dist/instrumentation/index.js +859 -7
  46. package/dist/instrumentation/index.mjs +859 -7
  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 +994 -10
  52. package/dist/workerd.mjs +994 -10
  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/browser.mjs CHANGED
@@ -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({
@@ -5654,6 +5663,7 @@ var INSTRUMENTATION_NAMES = {
5654
5663
  GENKIT: "genkit",
5655
5664
  GITHUB_COPILOT: "github-copilot",
5656
5665
  GOOGLE_ADK: "google-adk",
5666
+ GOOGLE_GENERATIVE_AI: "google-generative-ai",
5657
5667
  GOOGLE_GENAI: "google-genai",
5658
5668
  GROQ: "groq",
5659
5669
  HUGGINGFACE: "huggingface",
@@ -5669,12 +5679,13 @@ var INSTRUMENTATION_NAMES = {
5669
5679
  OPENROUTER_AGENT: "openrouter-agent",
5670
5680
  PI_CODING_AGENT: "pi-coding-agent",
5671
5681
  STRANDS_AGENT_SDK: "strands-agent-sdk",
5672
- VOYAGEAI: "voyageai"
5682
+ VOYAGEAI: "voyageai",
5683
+ ELEVENLABS: "elevenlabs"
5673
5684
  };
5674
5685
  var INTERNAL_SPAN_INSTRUMENTATION_NAME = /* @__PURE__ */ Symbol.for(
5675
5686
  "braintrust.spanInstrumentationName"
5676
5687
  );
5677
- var SDK_VERSION = true ? "3.31.0" : "0.0.0";
5688
+ var SDK_VERSION = true ? "3.32.0" : "0.0.0";
5678
5689
  function withSpanInstrumentationName(args, instrumentationName) {
5679
5690
  return {
5680
5691
  ...args,
@@ -11632,6 +11643,16 @@ function renderMessageImpl(render, message, variables) {
11632
11643
  }
11633
11644
  }
11634
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
+ ];
11635
11656
  case "file":
11636
11657
  return [
11637
11658
  {
@@ -24232,6 +24253,342 @@ var OpenAIAgentsPlugin = class extends BasePlugin {
24232
24253
  }
24233
24254
  };
24234
24255
 
24256
+ // src/instrumentation/plugins/google-generative-ai-channels.ts
24257
+ var googleGenerativeAIChannels = defineChannels(
24258
+ "@google/generative-ai",
24259
+ {
24260
+ generateContent: channel({ channelName: "GenerativeModel.generateContent", kind: "async" }),
24261
+ generateContentStream: channel({ channelName: "GenerativeModel.generateContentStream", kind: "async" }),
24262
+ embedContent: channel({ channelName: "GenerativeModel.embedContent", kind: "async" }),
24263
+ batchEmbedContents: channel({ channelName: "GenerativeModel.batchEmbedContents", kind: "async" }),
24264
+ sendMessage: channel({ channelName: "ChatSession.sendMessage", kind: "async" }),
24265
+ sendMessageStream: channel({ channelName: "ChatSession.sendMessageStream", kind: "async" })
24266
+ },
24267
+ { instrumentationName: INSTRUMENTATION_NAMES.GOOGLE_GENERATIVE_AI }
24268
+ );
24269
+
24270
+ // src/instrumentation/plugins/google-generative-ai-plugin.ts
24271
+ var GENERATION_CONFIG_KEYS = [
24272
+ "temperature",
24273
+ "topP",
24274
+ "topK",
24275
+ "candidateCount",
24276
+ "maxOutputTokens",
24277
+ "stopSequences",
24278
+ "responseMimeType",
24279
+ "responseSchema",
24280
+ "presencePenalty",
24281
+ "frequencyPenalty",
24282
+ "responseLogprobs",
24283
+ "logprobs",
24284
+ "thinkingConfig"
24285
+ ];
24286
+ var GoogleGenerativeAIPlugin = class extends BasePlugin {
24287
+ onEnable() {
24288
+ this.unsubscribers.push(
24289
+ interceptCall(
24290
+ googleGenerativeAIChannels.generateContent,
24291
+ "generateContent"
24292
+ ),
24293
+ interceptCall(
24294
+ googleGenerativeAIChannels.generateContentStream,
24295
+ "generateContentStream"
24296
+ ),
24297
+ interceptCall(googleGenerativeAIChannels.sendMessage, "sendMessage"),
24298
+ interceptCall(
24299
+ googleGenerativeAIChannels.sendMessageStream,
24300
+ "sendMessageStream"
24301
+ ),
24302
+ interceptCall(googleGenerativeAIChannels.embedContent, "embedContent"),
24303
+ interceptCall(
24304
+ googleGenerativeAIChannels.batchEmbedContents,
24305
+ "batchEmbedContents"
24306
+ )
24307
+ );
24308
+ }
24309
+ onDisable() {
24310
+ this.unsubscribers = unsubscribeAll(this.unsubscribers);
24311
+ }
24312
+ };
24313
+ function interceptCall(channel2, operation) {
24314
+ return channel2.intercept((target, thisArg, args) => {
24315
+ const invokeTarget = () => Reflect.apply(target, thisArg, args);
24316
+ if (isAutoInstrumentationSuppressed()) return invokeTarget();
24317
+ const self = thisArg;
24318
+ const chat = operation.startsWith("sendMessage");
24319
+ const embedding = operation === "embedContent" || operation === "batchEmbedContents";
24320
+ const start = getCurrentUnixTimestamp();
24321
+ let span;
24322
+ try {
24323
+ span = startSpan(
24324
+ withSpanInstrumentationName(
24325
+ {
24326
+ name: embedding ? operation === "embedContent" ? "embed_content" : "batch_embed_contents" : "generate_content",
24327
+ spanAttributes: { type: "llm" /* LLM */ },
24328
+ event: extractInput(self, args[0], operation)
24329
+ },
24330
+ INSTRUMENTATION_NAMES.GOOGLE_GENERATIVE_AI
24331
+ )
24332
+ );
24333
+ } catch (error) {
24334
+ debugLogger.error("Error starting Google Generative AI span:", error);
24335
+ return invokeTarget();
24336
+ }
24337
+ let ended = false;
24338
+ const finish = (log3) => {
24339
+ if (ended) return;
24340
+ ended = true;
24341
+ try {
24342
+ log3();
24343
+ } catch (error) {
24344
+ debugLogger.error("Error logging Google Generative AI span:", error);
24345
+ }
24346
+ try {
24347
+ span.end();
24348
+ } catch (error) {
24349
+ debugLogger.error("Error ending Google Generative AI span:", error);
24350
+ }
24351
+ };
24352
+ if (chat) {
24353
+ try {
24354
+ void self._sendPromise.then(
24355
+ () => {
24356
+ try {
24357
+ span.log(extractInput(self, args[0], operation));
24358
+ } catch (error) {
24359
+ debugLogger.error("Error capturing Google chat history:", error);
24360
+ }
24361
+ },
24362
+ () => {
24363
+ }
24364
+ );
24365
+ } catch (error) {
24366
+ debugLogger.error("Error observing Google chat history:", error);
24367
+ }
24368
+ }
24369
+ let result;
24370
+ try {
24371
+ result = withCurrent(
24372
+ span,
24373
+ () => runWithAutoInstrumentationSuppressed(invokeTarget)
24374
+ );
24375
+ } catch (error) {
24376
+ finish(() => span.log({ error }));
24377
+ throw error;
24378
+ }
24379
+ void Promise.resolve(result).then(
24380
+ (value) => {
24381
+ try {
24382
+ if ("stream" in value) {
24383
+ let firstToken = false;
24384
+ const partial = { candidates: [] };
24385
+ const candidates = /* @__PURE__ */ new Map();
24386
+ patchStreamIfNeeded(value.stream, {
24387
+ aroundNext: (callback) => withCurrent(span, callback),
24388
+ onChunk: (chunk) => {
24389
+ for (const candidate of chunk.candidates ?? []) {
24390
+ const index = candidate.index ?? 0;
24391
+ const previous = candidates.get(index);
24392
+ const parts = [...previous?.content?.parts ?? []];
24393
+ for (const part of candidate.content?.parts ?? []) {
24394
+ const last = parts[parts.length - 1];
24395
+ if (part.text !== void 0 && last?.text !== void 0) {
24396
+ parts[parts.length - 1] = {
24397
+ ...last,
24398
+ text: last.text + part.text
24399
+ };
24400
+ } else parts.push(part);
24401
+ }
24402
+ candidates.set(index, {
24403
+ ...previous,
24404
+ ...candidate,
24405
+ content: {
24406
+ role: candidate.content?.role ?? previous?.content?.role ?? "model",
24407
+ parts
24408
+ }
24409
+ });
24410
+ }
24411
+ partial.candidates = Array.from(candidates.values());
24412
+ if (chunk.usageMetadata)
24413
+ partial.usageMetadata = chunk.usageMetadata;
24414
+ if (!firstToken && chunk.candidates?.some(
24415
+ (candidate) => candidate.content?.parts.some(
24416
+ (part) => part.text !== void 0 ? part.text.length > 0 : Object.keys(part).length > 0
24417
+ )
24418
+ )) {
24419
+ firstToken = true;
24420
+ span.log({
24421
+ metrics: {
24422
+ time_to_first_token: getCurrentUnixTimestamp() - start
24423
+ }
24424
+ });
24425
+ }
24426
+ },
24427
+ onComplete: () => {
24428
+ },
24429
+ onError: (error) => finish(() => {
24430
+ logResponse(span, partial);
24431
+ span.log({ error });
24432
+ }),
24433
+ onCancel: () => finish(() => logResponse(span, partial))
24434
+ });
24435
+ void value.response.then(
24436
+ (response) => finish(() => logResponse(span, response)),
24437
+ (error) => finish(() => {
24438
+ logResponse(span, partial);
24439
+ span.log({ error });
24440
+ })
24441
+ );
24442
+ } else if ("response" in value) {
24443
+ finish(() => logResponse(span, value.response));
24444
+ } else {
24445
+ const metrics = {};
24446
+ const promptTokens = value.usageMetadata?.promptTokenCount;
24447
+ if (typeof promptTokens === "number" && Number.isFinite(promptTokens) && promptTokens >= 0) {
24448
+ metrics.prompt_tokens = promptTokens;
24449
+ metrics.tokens = promptTokens;
24450
+ }
24451
+ for (const detail of value.usageMetadata?.promptTokenDetails ?? []) {
24452
+ if (detail.modality === "AUDIO" && typeof detail.tokenCount === "number" && Number.isFinite(detail.tokenCount) && detail.tokenCount >= 0) {
24453
+ metrics.prompt_audio_tokens = (metrics.prompt_audio_tokens ?? 0) + detail.tokenCount;
24454
+ }
24455
+ }
24456
+ finish(
24457
+ () => span.log({
24458
+ metrics,
24459
+ output: {
24460
+ count: value.embeddings?.length ?? (value.embedding ? 1 : 0)
24461
+ }
24462
+ })
24463
+ );
24464
+ }
24465
+ } catch (error) {
24466
+ debugLogger.error(
24467
+ "Error observing Google Generative AI result:",
24468
+ error
24469
+ );
24470
+ finish(() => {
24471
+ });
24472
+ }
24473
+ },
24474
+ (error) => finish(() => span.log({ error }))
24475
+ );
24476
+ return result;
24477
+ });
24478
+ }
24479
+ function normalizeContent(message) {
24480
+ const parts = (typeof message === "string" ? [message] : message).map(
24481
+ (part) => typeof part === "string" ? { text: part } : part
24482
+ );
24483
+ return {
24484
+ role: parts.some((part) => part.functionResponse) ? "function" : "user",
24485
+ parts
24486
+ };
24487
+ }
24488
+ function extractInput(self, request, operation) {
24489
+ const model = self.model.replace(/^models\//, "");
24490
+ if (operation === "embedContent" || operation === "batchEmbedContents") {
24491
+ const requests = operation === "batchEmbedContents" ? request.requests : [
24492
+ typeof request === "string" || Array.isArray(request) ? { content: normalizeContent(request) } : request
24493
+ ];
24494
+ const dimensions = requests[0]?.outputDimensionality;
24495
+ return {
24496
+ input: {
24497
+ inputs: convertAttachments(requests).map((item) => ({
24498
+ content: item.content.parts.length === 1 && item.content.parts[0].text !== void 0 ? item.content.parts[0].text : item.content.parts.map((part) => {
24499
+ if (part.text !== void 0)
24500
+ return { type: "text", text: part.text };
24501
+ const mimeType = part.inlineData?.mimeType ?? part.fileData?.mimeType;
24502
+ const data = part.inlineData ? typeof part.inlineData.data === "string" ? `data:${mimeType};base64,${part.inlineData.data}` : part.inlineData.data : part.fileData?.fileUri;
24503
+ return mimeType?.startsWith("image/") ? { type: "image_url", image_url: { url: data } } : { type: "file", file: { file_data: data } };
24504
+ })
24505
+ })),
24506
+ ...dimensions !== void 0 && requests.every((item) => item.outputDimensionality === dimensions) ? { output_dimensions: dimensions } : {}
24507
+ },
24508
+ metadata: { model, provider: "google" }
24509
+ };
24510
+ }
24511
+ const chat = operation.startsWith("sendMessage");
24512
+ const config = chat ? self.params ?? {} : self;
24513
+ const params = typeof request === "string" || Array.isArray(request) ? { contents: [normalizeContent(request)] } : request;
24514
+ const system = params.systemInstruction ?? config.systemInstruction;
24515
+ const systemContent = typeof system === "string" ? { role: "system", parts: [{ text: system }] } : system && "parts" in system ? { ...system, role: "system" } : system ? { role: "system", parts: [system] } : void 0;
24516
+ const contents = [
24517
+ ...systemContent ? [systemContent] : [],
24518
+ ...chat ? self._history : [],
24519
+ ...params.contents
24520
+ ];
24521
+ const metadata = { model, provider: "google" };
24522
+ const generation = params.generationConfig ?? config.generationConfig;
24523
+ for (const key of GENERATION_CONFIG_KEYS) {
24524
+ if (generation && Object.hasOwn(generation, key))
24525
+ metadata[key] = generation[key];
24526
+ }
24527
+ for (const key of ["tools", "toolConfig", "safetySettings"]) {
24528
+ const value = params[key] ?? config[key];
24529
+ if (value !== void 0) metadata[key] = value;
24530
+ }
24531
+ const cached = params.cachedContent ?? config.cachedContent;
24532
+ if (cached)
24533
+ metadata.cachedContent = typeof cached === "string" ? cached : cached.name;
24534
+ return { input: convertAttachments({ model, contents }), metadata };
24535
+ }
24536
+ function convertAttachments(value) {
24537
+ const convert = (node) => {
24538
+ if (Array.isArray(node)) return node.map(convert);
24539
+ if (!isObject(node)) return node;
24540
+ if (isObject(node.inlineData)) {
24541
+ const { data, mimeType } = node.inlineData;
24542
+ const processed = processInputAttachments({
24543
+ type: "file",
24544
+ file: { file_data: `data:${mimeType};base64,${data}` }
24545
+ });
24546
+ if (typeof processed.file.file_data === "string")
24547
+ throw new Error("Unable to convert Google inline data");
24548
+ return {
24549
+ ...node,
24550
+ inlineData: { ...node.inlineData, data: processed.file.file_data }
24551
+ };
24552
+ }
24553
+ return Object.fromEntries(
24554
+ Object.entries(node).map(([key, item]) => [key, convert(item)])
24555
+ );
24556
+ };
24557
+ try {
24558
+ return convert(value);
24559
+ } catch (error) {
24560
+ debugLogger.error(
24561
+ "Error converting Google Generative AI attachments:",
24562
+ error
24563
+ );
24564
+ return value;
24565
+ }
24566
+ }
24567
+ function logResponse(span, response) {
24568
+ const usage = response.usageMetadata;
24569
+ const metrics = {};
24570
+ if (usage) {
24571
+ if (usage.promptTokenCount !== void 0)
24572
+ metrics.prompt_tokens = usage.promptTokenCount;
24573
+ if (usage.candidatesTokenCount !== void 0 || usage.thoughtsTokenCount !== void 0)
24574
+ metrics.completion_tokens = (usage.candidatesTokenCount ?? 0) + (usage.thoughtsTokenCount ?? 0);
24575
+ if (usage.totalTokenCount !== void 0)
24576
+ metrics.tokens = usage.totalTokenCount;
24577
+ if (usage.cachedContentTokenCount !== void 0)
24578
+ metrics.prompt_cached_tokens = usage.cachedContentTokenCount;
24579
+ if (usage.thoughtsTokenCount !== void 0)
24580
+ metrics.completion_reasoning_tokens = usage.thoughtsTokenCount;
24581
+ }
24582
+ span.log({
24583
+ output: convertAttachments({
24584
+ candidates: response.candidates,
24585
+ promptFeedback: response.promptFeedback
24586
+ }),
24587
+ metrics,
24588
+ ...response.modelVersion ? { metadata: { model: response.modelVersion } } : {}
24589
+ });
24590
+ }
24591
+
24235
24592
  // src/instrumentation/plugins/google-genai-channels.ts
24236
24593
  var googleGenAIChannels = defineChannels(
24237
24594
  "@google/genai",
@@ -25875,7 +26232,7 @@ var HuggingFaceTransformersPlugin = class extends BasePlugin {
25875
26232
  getTask(event)
25876
26233
  ),
25877
26234
  extractInput: (args, event) => ({
25878
- input: extractInput(
26235
+ input: extractInput2(
25879
26236
  getTask(event),
25880
26237
  args
25881
26238
  ),
@@ -25965,7 +26322,7 @@ function modelIdentifier(pipeline) {
25965
26322
  }
25966
26323
  return void 0;
25967
26324
  }
25968
- function extractInput(task, args) {
26325
+ function extractInput2(task, args) {
25969
26326
  switch (task) {
25970
26327
  case "feature-extraction":
25971
26328
  return args[0];
@@ -36319,6 +36676,477 @@ function logInstrumentationError5(context, error) {
36319
36676
  debugLogger.debug(`${context}:`, error);
36320
36677
  }
36321
36678
 
36679
+ // src/instrumentation/plugins/elevenlabs-channels.ts
36680
+ var elevenLabsChannels = defineChannels(
36681
+ "@elevenlabs/elevenlabs-js",
36682
+ {
36683
+ convert: channel({
36684
+ channelName: "textToSpeech.convert",
36685
+ kind: "async"
36686
+ }),
36687
+ stream: channel({
36688
+ channelName: "textToSpeech.stream",
36689
+ kind: "async"
36690
+ }),
36691
+ convertWithTimestamps: channel({ channelName: "textToSpeech.convertWithTimestamps", kind: "async" }),
36692
+ streamWithTimestamps: channel({ channelName: "textToSpeech.streamWithTimestamps", kind: "async" }),
36693
+ transcribe: channel({ channelName: "speechToText.convert", kind: "async" })
36694
+ },
36695
+ { instrumentationName: INSTRUMENTATION_NAMES.ELEVENLABS }
36696
+ );
36697
+
36698
+ // src/instrumentation/plugins/elevenlabs-plugin.ts
36699
+ var ElevenLabsPlugin = class extends BasePlugin {
36700
+ onEnable() {
36701
+ for (const method of [
36702
+ "convert",
36703
+ "stream",
36704
+ "convertWithTimestamps",
36705
+ "streamWithTimestamps"
36706
+ ]) {
36707
+ this.unsubscribers.push(
36708
+ interceptCall2(
36709
+ elevenLabsChannels[method],
36710
+ `elevenlabs.textToSpeech.${method}`,
36711
+ ([voice, request]) => ({
36712
+ input: {
36713
+ operation: "speech",
36714
+ prompt: request.text,
36715
+ parameters: {
36716
+ voice,
36717
+ format: request.outputFormat,
36718
+ language: request.languageCode,
36719
+ speed: request.voiceSettings?.speed
36720
+ }
36721
+ },
36722
+ metadata: {
36723
+ provider: "elevenlabs",
36724
+ model: request.modelId ?? "eleven_multilingual_v2"
36725
+ }
36726
+ }),
36727
+ (value, args, span, finish, headers, started) => captureSpeech(
36728
+ value,
36729
+ args[1],
36730
+ method,
36731
+ span,
36732
+ finish,
36733
+ started,
36734
+ headers
36735
+ )
36736
+ )
36737
+ );
36738
+ }
36739
+ this.unsubscribers.push(
36740
+ interceptCall2(
36741
+ elevenLabsChannels.transcribe,
36742
+ "elevenlabs.speechToText.convert",
36743
+ ([request]) => {
36744
+ if (request.webhook) return void 0;
36745
+ const file = request.file;
36746
+ const filename = typeof File !== "undefined" && file instanceof File ? file.name : "audio";
36747
+ const contentType = file instanceof Blob ? file.type || "application/octet-stream" : "application/octet-stream";
36748
+ 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;
36749
+ const fileData = blob ? new Attachment({ data: blob, filename, contentType }) : request.cloudStorageUrl;
36750
+ return {
36751
+ input: {
36752
+ operation: "transcribe",
36753
+ content: fileData ? [{ type: "file", file: { filename, file_data: fileData } }] : [],
36754
+ parameters: {
36755
+ language: request.languageCode,
36756
+ timestamp_granularities: request.timestampsGranularity
36757
+ }
36758
+ },
36759
+ metadata: { provider: "elevenlabs", model: request.modelId }
36760
+ };
36761
+ },
36762
+ (value, _args, span, finish) => {
36763
+ const result = value;
36764
+ const transcripts = result.transcripts ?? [result];
36765
+ span.log({
36766
+ output: {
36767
+ content: transcripts.flatMap(
36768
+ (transcript) => typeof transcript.text === "string" ? [{ type: "text", text: transcript.text }] : []
36769
+ ),
36770
+ annotations: {
36771
+ language: result.languageCode,
36772
+ words: result.words ?? (result.transcripts ? result.transcripts.flatMap(
36773
+ (transcript) => transcript.words ?? []
36774
+ ) : void 0)
36775
+ }
36776
+ }
36777
+ });
36778
+ finish();
36779
+ },
36780
+ ([request], span) => {
36781
+ const file = request.file;
36782
+ if (!isAsyncIterable(file)) return;
36783
+ const chunks = [];
36784
+ const filename = isObject(file) && typeof file.path === "string" ? file.path.split(/[\\/]/).pop() || "audio" : "audio";
36785
+ observeAudioStream(
36786
+ file,
36787
+ (chunk) => chunks.push(new Uint8Array(chunk)),
36788
+ () => {
36789
+ const contentType = "application/octet-stream";
36790
+ const data = new Blob(chunks, {
36791
+ type: contentType
36792
+ });
36793
+ chunks.length = 0;
36794
+ span.log({
36795
+ input: {
36796
+ content: [
36797
+ {
36798
+ type: "file",
36799
+ file: {
36800
+ filename,
36801
+ file_data: new Attachment({
36802
+ data,
36803
+ filename,
36804
+ contentType
36805
+ })
36806
+ }
36807
+ }
36808
+ ]
36809
+ }
36810
+ });
36811
+ },
36812
+ () => {
36813
+ chunks.length = 0;
36814
+ },
36815
+ span
36816
+ );
36817
+ }
36818
+ )
36819
+ );
36820
+ }
36821
+ onDisable() {
36822
+ this.unsubscribers = unsubscribeAll(this.unsubscribers);
36823
+ }
36824
+ };
36825
+ function interceptCall2(channel2, name, input, output, beforeInvoke) {
36826
+ return channel2.intercept((target, self, args) => {
36827
+ const invoke2 = () => Reflect.apply(target, self, args);
36828
+ if (isAutoInstrumentationSuppressed()) return invoke2();
36829
+ const started = Date.now() / 1e3;
36830
+ let span;
36831
+ try {
36832
+ const event = input(args);
36833
+ if (event !== void 0)
36834
+ span = startSpan(
36835
+ withSpanInstrumentationName(
36836
+ {
36837
+ name,
36838
+ spanAttributes: { type: "llm" /* LLM */ },
36839
+ event
36840
+ },
36841
+ INSTRUMENTATION_NAMES.ELEVENLABS
36842
+ )
36843
+ );
36844
+ } catch (error) {
36845
+ debugLogger.error("Error starting ElevenLabs span", error);
36846
+ return invoke2();
36847
+ }
36848
+ if (!span) return invoke2();
36849
+ const activeSpan = span;
36850
+ let ended = false;
36851
+ const finish = (error) => {
36852
+ if (ended) return;
36853
+ ended = true;
36854
+ try {
36855
+ if (error !== void 0) activeSpan.log({ error });
36856
+ activeSpan.end();
36857
+ } catch (loggingError) {
36858
+ debugLogger.error("Error ending ElevenLabs span", loggingError);
36859
+ }
36860
+ };
36861
+ try {
36862
+ beforeInvoke?.(args, span);
36863
+ } catch (error) {
36864
+ debugLogger.error("Error observing ElevenLabs input", error);
36865
+ }
36866
+ let result;
36867
+ try {
36868
+ result = withCurrent(
36869
+ span,
36870
+ () => runWithAutoInstrumentationSuppressed(invoke2)
36871
+ );
36872
+ } catch (error) {
36873
+ finish(error);
36874
+ throw error;
36875
+ }
36876
+ const capture = (value, headers) => {
36877
+ try {
36878
+ output(value, args, span, finish, headers, started);
36879
+ } catch (error) {
36880
+ debugLogger.error("Error capturing ElevenLabs output", error);
36881
+ finish();
36882
+ }
36883
+ };
36884
+ try {
36885
+ if (isObject(result) && typeof result.withRawResponse === "function") {
36886
+ void result.withRawResponse().then(
36887
+ ({
36888
+ data,
36889
+ rawResponse
36890
+ }) => capture(data, rawResponse?.headers),
36891
+ finish
36892
+ );
36893
+ } else {
36894
+ void Promise.resolve(result).then((value) => capture(value), finish);
36895
+ }
36896
+ } catch (error) {
36897
+ debugLogger.error("Error observing ElevenLabs result", error);
36898
+ finish();
36899
+ }
36900
+ return result;
36901
+ });
36902
+ }
36903
+ function captureSpeech(value, request, method, span, finish, started, headers) {
36904
+ const format = request.outputFormat ?? "mp3_44100_128";
36905
+ 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;
36906
+ const headerType = headers?.get("content-type")?.split(";")[0];
36907
+ const contentType = headerType?.startsWith("audio/") ? headerType : formatType;
36908
+ const disposition = headers?.get("content-disposition");
36909
+ const headerFilename = disposition?.match(
36910
+ /filename="([^"]+)"|filename=([^;]+)/i
36911
+ );
36912
+ const filename = headerFilename?.[1] ?? headerFilename?.[2]?.trim() ?? `speech.${contentType ? getExtensionFromMediaType(contentType) : "bin"}`;
36913
+ const chunks = [];
36914
+ const alignments = [];
36915
+ let bytes = 0;
36916
+ let first = true;
36917
+ let stopped = false;
36918
+ const observe = (chunk) => {
36919
+ if (stopped || chunk.byteLength === 0) return;
36920
+ if (first && method.startsWith("stream")) {
36921
+ span.log({
36922
+ metrics: { time_to_first_token: Date.now() / 1e3 - started }
36923
+ });
36924
+ }
36925
+ first = false;
36926
+ chunks.push(new Uint8Array(chunk));
36927
+ bytes += chunk.byteLength;
36928
+ };
36929
+ const complete = () => {
36930
+ if (stopped) return;
36931
+ stopped = true;
36932
+ try {
36933
+ const content = [];
36934
+ if (contentType && bytes) {
36935
+ const data = new Uint8Array(bytes);
36936
+ let offset = 0;
36937
+ for (const chunk of chunks) {
36938
+ data.set(chunk, offset);
36939
+ offset += chunk.length;
36940
+ }
36941
+ content.push({
36942
+ type: "file",
36943
+ file: {
36944
+ filename,
36945
+ byte_size: bytes,
36946
+ file_data: new Attachment({
36947
+ data: new Blob([data], { type: contentType }),
36948
+ filename,
36949
+ contentType
36950
+ })
36951
+ }
36952
+ });
36953
+ }
36954
+ span.log({
36955
+ output: {
36956
+ content,
36957
+ ...alignments.length ? { annotations: alignments } : {}
36958
+ }
36959
+ });
36960
+ } finally {
36961
+ chunks.length = 0;
36962
+ finish();
36963
+ }
36964
+ };
36965
+ const cancel = (error) => {
36966
+ stopped = true;
36967
+ chunks.length = 0;
36968
+ finish(error);
36969
+ };
36970
+ const timestampChunk = (chunk) => {
36971
+ const binary = atob(chunk.audioBase64);
36972
+ observe(Uint8Array.from(binary, (character) => character.charCodeAt(0)));
36973
+ if (chunk.alignment || chunk.normalizedAlignment)
36974
+ alignments.push({
36975
+ alignment: chunk.alignment,
36976
+ normalized_alignment: chunk.normalizedAlignment
36977
+ });
36978
+ };
36979
+ if (method === "convertWithTimestamps") {
36980
+ timestampChunk(value);
36981
+ complete();
36982
+ } else if (method === "streamWithTimestamps") {
36983
+ patchStreamIfNeeded(value, {
36984
+ shouldCollect: (chunk) => {
36985
+ try {
36986
+ timestampChunk(chunk);
36987
+ } catch (error) {
36988
+ debugLogger.error("Error collecting ElevenLabs timestamps", error);
36989
+ cancel();
36990
+ }
36991
+ return false;
36992
+ },
36993
+ onComplete: complete,
36994
+ onCancel: () => cancel(),
36995
+ onError: cancel,
36996
+ aroundNext: (next) => withCurrent(span, next)
36997
+ });
36998
+ } else {
36999
+ observeAudioStream(value, observe, complete, cancel, span);
37000
+ }
37001
+ }
37002
+ function observeAudioStream(value, observe, complete, cancel, span) {
37003
+ let ended = false;
37004
+ const safeObserve = (chunk) => {
37005
+ if (ended) return;
37006
+ try {
37007
+ observe(chunk);
37008
+ } catch (error) {
37009
+ debugLogger.error("Error collecting ElevenLabs audio", error);
37010
+ end(false);
37011
+ }
37012
+ };
37013
+ const end = (success, error) => {
37014
+ if (ended) return;
37015
+ ended = true;
37016
+ try {
37017
+ if (success) complete();
37018
+ else cancel(error);
37019
+ } catch (loggingError) {
37020
+ debugLogger.error("Error logging ElevenLabs audio", loggingError);
37021
+ cancel();
37022
+ }
37023
+ };
37024
+ if (!isObject(value) || !Object.isExtensible(value)) {
37025
+ end(false);
37026
+ return;
37027
+ }
37028
+ if (typeof value.read === "function" && typeof value.on === "function") {
37029
+ value.on("end", () => end(true));
37030
+ value.on("close", () => end(false));
37031
+ const emit2 = value.emit;
37032
+ if (typeof emit2 === "function")
37033
+ value.emit = function(event, ...args) {
37034
+ if (event === "data" && args[0] instanceof Uint8Array)
37035
+ safeObserve(args[0]);
37036
+ if (event === "error") end(false, args[0]);
37037
+ return Reflect.apply(emit2, this, [event, ...args]);
37038
+ };
37039
+ return;
37040
+ }
37041
+ if (typeof value.getReader === "function") {
37042
+ const webStream = value;
37043
+ const pipeTo = webStream.pipeTo;
37044
+ const pipeThrough = webStream.pipeThrough;
37045
+ webStream.pipeTo = function(destination, options) {
37046
+ if (!isObject(destination) || this.locked || destination.locked)
37047
+ return pipeTo.call(this, destination, options);
37048
+ const tap = new TransformStream({
37049
+ transform(chunk, controller) {
37050
+ safeObserve(chunk);
37051
+ controller.enqueue(chunk);
37052
+ },
37053
+ flush() {
37054
+ end(true);
37055
+ }
37056
+ });
37057
+ const observed = pipeThrough.call(
37058
+ this,
37059
+ tap,
37060
+ options
37061
+ );
37062
+ return observed.pipeTo(destination, options).catch((error) => {
37063
+ end(false, error);
37064
+ throw error;
37065
+ });
37066
+ };
37067
+ webStream.pipeThrough = function(transform, options) {
37068
+ if (this.locked || transform.writable.locked || transform.readable.locked)
37069
+ return pipeThrough.call(this, transform, options);
37070
+ const result = webStream.pipeTo.call(this, transform.writable, options);
37071
+ void result.catch(() => {
37072
+ });
37073
+ return transform.readable;
37074
+ };
37075
+ const getReader = value.getReader;
37076
+ value.getReader = function(...args) {
37077
+ const reader = Reflect.apply(getReader, this, args);
37078
+ const read3 = reader.read;
37079
+ reader.read = function(...readArgs) {
37080
+ return Promise.resolve(
37081
+ withCurrent(span, () => Reflect.apply(read3, this, readArgs))
37082
+ ).then(
37083
+ (result) => {
37084
+ if (result.value) safeObserve(result.value);
37085
+ if (result.done) end(true);
37086
+ return result;
37087
+ },
37088
+ (error) => {
37089
+ end(false, error);
37090
+ throw error;
37091
+ }
37092
+ );
37093
+ };
37094
+ const readerCancel = reader.cancel;
37095
+ reader.cancel = function(...cancelArgs) {
37096
+ const result = Reflect.apply(readerCancel, this, cancelArgs);
37097
+ end(false);
37098
+ return result;
37099
+ };
37100
+ return reader;
37101
+ };
37102
+ const streamCancel = value.cancel;
37103
+ if (typeof streamCancel === "function")
37104
+ value.cancel = function(...args) {
37105
+ const result = Reflect.apply(streamCancel, this, args);
37106
+ void Promise.resolve(result).then(
37107
+ () => end(false),
37108
+ () => {
37109
+ }
37110
+ );
37111
+ return result;
37112
+ };
37113
+ }
37114
+ if (typeof value.getReader === "function" && typeof value.values === "function") {
37115
+ const values = value.values;
37116
+ const iterate = function(...args) {
37117
+ const iterator = Reflect.apply(values, this, args);
37118
+ patchStreamIfNeeded(iterator, {
37119
+ shouldCollect(chunk) {
37120
+ safeObserve(chunk);
37121
+ return false;
37122
+ },
37123
+ onComplete: () => end(true),
37124
+ onCancel: () => end(false),
37125
+ onError: (error) => end(false, error),
37126
+ aroundNext: (next) => withCurrent(span, next)
37127
+ });
37128
+ return iterator;
37129
+ };
37130
+ value.values = iterate;
37131
+ Object.defineProperty(value, Symbol.asyncIterator, {
37132
+ configurable: true,
37133
+ writable: true,
37134
+ value: iterate
37135
+ });
37136
+ } else if (isAsyncIterable(value)) {
37137
+ patchStreamIfNeeded(value, {
37138
+ shouldCollect: (chunk) => {
37139
+ safeObserve(chunk);
37140
+ return false;
37141
+ },
37142
+ onComplete: () => end(true),
37143
+ onCancel: () => end(false),
37144
+ onError: (error) => end(false, error),
37145
+ aroundNext: (next) => withCurrent(span, next)
37146
+ });
37147
+ } else if (typeof value.getReader !== "function") end(false);
37148
+ }
37149
+
36322
37150
  // src/instrumentation/plugins/voyageai-channels.ts
36323
37151
  var voyageAIChannels = defineChannels(
36324
37152
  "voyageai",
@@ -36386,7 +37214,7 @@ var VoyageAIPlugin = class extends BasePlugin {
36386
37214
  this.unsubscribers = unsubscribeAll(this.unsubscribers);
36387
37215
  }
36388
37216
  };
36389
- function interceptVoyageAICall(channel2, name, extractInput3, extractOutput2, extractMetrics2 = extractUsageMetrics3) {
37217
+ function interceptVoyageAICall(channel2, name, extractInput4, extractOutput2, extractMetrics2 = extractUsageMetrics3) {
36390
37218
  return channel2.intercept((target, thisArg, args) => {
36391
37219
  const invokeTarget = () => Reflect.apply(target, thisArg, args);
36392
37220
  if (isAutoInstrumentationSuppressed()) {
@@ -36394,7 +37222,7 @@ function interceptVoyageAICall(channel2, name, extractInput3, extractOutput2, ex
36394
37222
  }
36395
37223
  let span;
36396
37224
  try {
36397
- const { input, metadata } = extractInput3(args);
37225
+ const { input, metadata } = extractInput4(args);
36398
37226
  span = startSpan(
36399
37227
  withSpanInstrumentationName(
36400
37228
  {
@@ -37193,6 +38021,7 @@ var BraintrustPlugin = class extends BasePlugin {
37193
38021
  cloudflareThinkPlugin = null;
37194
38022
  cursorSDKPlugin = null;
37195
38023
  openAIAgentsPlugin = null;
38024
+ googleGenerativeAIPlugin = null;
37196
38025
  googleGenAIPlugin = null;
37197
38026
  huggingFacePlugin = null;
37198
38027
  huggingFaceTransformersPlugin = null;
@@ -37211,6 +38040,7 @@ var BraintrustPlugin = class extends BasePlugin {
37211
38040
  langSmithPlugin = null;
37212
38041
  piCodingAgentPlugin = null;
37213
38042
  strandsAgentSDKPlugin = null;
38043
+ elevenLabsPlugin = null;
37214
38044
  voyageAIPlugin = null;
37215
38045
  cloudflareAIChatPlugin = null;
37216
38046
  cloudflareAgentsPlugin = null;
@@ -37252,6 +38082,10 @@ var BraintrustPlugin = class extends BasePlugin {
37252
38082
  this.openAIAgentsPlugin = new OpenAIAgentsPlugin();
37253
38083
  this.openAIAgentsPlugin.enable();
37254
38084
  }
38085
+ if (integrations.googleGenerativeAI !== false) {
38086
+ this.googleGenerativeAIPlugin = new GoogleGenerativeAIPlugin();
38087
+ this.googleGenerativeAIPlugin.enable();
38088
+ }
37255
38089
  if (integrations.googleGenAI !== false && integrations.google !== false) {
37256
38090
  this.googleGenAIPlugin = new GoogleGenAIPlugin();
37257
38091
  this.googleGenAIPlugin.enable();
@@ -37286,6 +38120,10 @@ var BraintrustPlugin = class extends BasePlugin {
37286
38120
  this.coherePlugin = new CoherePlugin();
37287
38121
  this.coherePlugin.enable();
37288
38122
  }
38123
+ if (integrations.elevenlabs !== false) {
38124
+ this.elevenLabsPlugin = new ElevenLabsPlugin();
38125
+ this.elevenLabsPlugin.enable();
38126
+ }
37289
38127
  if (integrations.voyageai !== false) {
37290
38128
  this.voyageAIPlugin = new VoyageAIPlugin();
37291
38129
  this.voyageAIPlugin.enable();
@@ -37370,6 +38208,10 @@ var BraintrustPlugin = class extends BasePlugin {
37370
38208
  this.openAIAgentsPlugin.disable();
37371
38209
  this.openAIAgentsPlugin = null;
37372
38210
  }
38211
+ if (this.googleGenerativeAIPlugin) {
38212
+ this.googleGenerativeAIPlugin.disable();
38213
+ this.googleGenerativeAIPlugin = null;
38214
+ }
37373
38215
  if (this.googleGenAIPlugin) {
37374
38216
  this.googleGenAIPlugin.disable();
37375
38217
  this.googleGenAIPlugin = null;
@@ -37406,6 +38248,10 @@ var BraintrustPlugin = class extends BasePlugin {
37406
38248
  this.coherePlugin.disable();
37407
38249
  this.coherePlugin = null;
37408
38250
  }
38251
+ if (this.elevenLabsPlugin) {
38252
+ this.elevenLabsPlugin.disable();
38253
+ this.elevenLabsPlugin = null;
38254
+ }
37409
38255
  if (this.voyageAIPlugin) {
37410
38256
  this.voyageAIPlugin.disable();
37411
38257
  this.voyageAIPlugin = null;
@@ -37499,6 +38345,8 @@ var envIntegrationAliases = {
37499
38345
  "openai-agents-core": "openAIAgents",
37500
38346
  openaiagentscore: "openAIAgents",
37501
38347
  google: "google",
38348
+ "google-generative-ai": "googleGenerativeAI",
38349
+ googlegenerativeai: "googleGenerativeAI",
37502
38350
  "google-genai": "googleGenAI",
37503
38351
  googlegenai: "googleGenAI",
37504
38352
  huggingface: "huggingface",
@@ -37532,7 +38380,9 @@ var envIntegrationAliases = {
37532
38380
  langsmith: "langsmith",
37533
38381
  voyage: "voyageai",
37534
38382
  "voyage-ai": "voyageai",
37535
- voyageai: "voyageai"
38383
+ voyageai: "voyageai",
38384
+ elevenlabs: "elevenlabs",
38385
+ "@elevenlabs/elevenlabs-js": "elevenlabs"
37536
38386
  };
37537
38387
  function getDefaultInstrumentationIntegrations() {
37538
38388
  return {
@@ -37543,6 +38393,7 @@ function getDefaultInstrumentationIntegrations() {
37543
38393
  aisdk: true,
37544
38394
  google: true,
37545
38395
  googleGenAI: true,
38396
+ googleGenerativeAI: true,
37546
38397
  googleADK: true,
37547
38398
  huggingface: true,
37548
38399
  claudeAgentSDK: true,
@@ -37568,6 +38419,7 @@ function getDefaultInstrumentationIntegrations() {
37568
38419
  langgraph: true,
37569
38420
  langsmith: true,
37570
38421
  voyageai: true,
38422
+ elevenlabs: true,
37571
38423
  piCodingAgent: true,
37572
38424
  strandsAgentSDK: true,
37573
38425
  cloudflareAgents: true
@@ -37886,9 +38738,11 @@ __export(exports_exports, {
37886
38738
  wrapCohere: () => wrapCohere,
37887
38739
  wrapCopilotClient: () => wrapCopilotClient,
37888
38740
  wrapCursorSDK: () => wrapCursorSDK,
38741
+ wrapElevenLabs: () => wrapElevenLabs,
37889
38742
  wrapGenkit: () => wrapGenkit,
37890
38743
  wrapGoogleADK: () => wrapGoogleADK,
37891
38744
  wrapGoogleGenAI: () => wrapGoogleGenAI,
38745
+ wrapGoogleGenerativeAI: () => wrapGoogleGenerativeAI,
37892
38746
  wrapGroq: () => wrapGroq,
37893
38747
  wrapHuggingFace: () => wrapHuggingFace,
37894
38748
  wrapHuggingFaceTransformers: () => wrapHuggingFaceTransformers,
@@ -39498,7 +40352,7 @@ function extractToolCallsFromBlocks(blocks) {
39498
40352
  if (!Array.isArray(blocks)) return [];
39499
40353
  return extractToolCallsFromSteps([{ content: blocks }]);
39500
40354
  }
39501
- function extractInput2(params) {
40355
+ function extractInput3(params) {
39502
40356
  return params?.prompt ?? params?.messages ?? params?.system;
39503
40357
  }
39504
40358
  var V2_EXCLUDE_KEYS = /* @__PURE__ */ new Set([
@@ -39520,7 +40374,7 @@ function BraintrustMiddleware(config = {}) {
39520
40374
  params,
39521
40375
  model: modelFromWrapGenerate
39522
40376
  }) => {
39523
- const rawInput = extractInput2(params);
40377
+ const rawInput = extractInput3(params);
39524
40378
  const processedInput = processInputAttachments(rawInput);
39525
40379
  const spanArgs = {
39526
40380
  name: config.spanInfo?.name || "ai-sdk.doGenerate",
@@ -39584,7 +40438,7 @@ function BraintrustMiddleware(config = {}) {
39584
40438
  }
39585
40439
  },
39586
40440
  wrapStream: async ({ doStream, params }) => {
39587
- const rawInput = extractInput2(params);
40441
+ const rawInput = extractInput3(params);
39588
40442
  const processedInput = processInputAttachments(rawInput);
39589
40443
  const spanArgs = {
39590
40444
  name: config.spanInfo?.name || "ai-sdk.doStream",
@@ -42977,6 +43831,75 @@ function isModuleNamespace5(value) {
42977
43831
  }
42978
43832
  }
42979
43833
 
43834
+ // src/wrappers/google-generative-ai.ts
43835
+ function wrapGoogleGenerativeAI(client) {
43836
+ if (!isObject(client) || typeof client.getGenerativeModel !== "function")
43837
+ return client;
43838
+ return wrapClient(client);
43839
+ }
43840
+ var proxies = /* @__PURE__ */ new WeakMap();
43841
+ function wrapClient(client) {
43842
+ const cached = proxies.get(client);
43843
+ if (cached) return cached;
43844
+ const proxy = new Proxy(client, {
43845
+ get(target, prop, receiver) {
43846
+ const value = Reflect.get(target, prop, receiver);
43847
+ if (typeof value !== "function") return value;
43848
+ if (prop === "getGenerativeModel" || prop === "getGenerativeModelFromCachedContent" || prop === "startChat") {
43849
+ return (...args) => wrapClient(Reflect.apply(value, target, args));
43850
+ }
43851
+ switch (prop) {
43852
+ case "generateContent":
43853
+ return (...args) => googleGenerativeAIChannels.generateContent.invoke(
43854
+ value,
43855
+ target,
43856
+ args,
43857
+ {}
43858
+ );
43859
+ case "generateContentStream":
43860
+ return (...args) => googleGenerativeAIChannels.generateContentStream.invoke(
43861
+ value,
43862
+ target,
43863
+ args,
43864
+ {}
43865
+ );
43866
+ case "embedContent":
43867
+ return (...args) => googleGenerativeAIChannels.embedContent.invoke(
43868
+ value,
43869
+ target,
43870
+ args,
43871
+ {}
43872
+ );
43873
+ case "batchEmbedContents":
43874
+ return (...args) => googleGenerativeAIChannels.batchEmbedContents.invoke(
43875
+ value,
43876
+ target,
43877
+ args,
43878
+ {}
43879
+ );
43880
+ case "sendMessage":
43881
+ return (...args) => googleGenerativeAIChannels.sendMessage.invoke(
43882
+ value,
43883
+ target,
43884
+ args,
43885
+ {}
43886
+ );
43887
+ case "sendMessageStream":
43888
+ return (...args) => googleGenerativeAIChannels.sendMessageStream.invoke(
43889
+ value,
43890
+ target,
43891
+ args,
43892
+ {}
43893
+ );
43894
+ }
43895
+ return value.bind(target);
43896
+ }
43897
+ });
43898
+ proxies.set(client, proxy);
43899
+ proxies.set(proxy, proxy);
43900
+ return proxy;
43901
+ }
43902
+
42980
43903
  // src/wrappers/google-genai.ts
42981
43904
  function wrapGoogleGenAI(googleGenAI) {
42982
43905
  if (!googleGenAI || typeof googleGenAI !== "object") {
@@ -50338,6 +51261,65 @@ var evaluatorDefinitionsSchema = z13.record(
50338
51261
  evaluatorDefinitionSchema
50339
51262
  );
50340
51263
 
51264
+ // src/wrappers/elevenlabs.ts
51265
+ var clients = /* @__PURE__ */ new WeakMap();
51266
+ function wrapElevenLabs(client) {
51267
+ if (!isObject(client) || !isObject(client.textToSpeech) || typeof client.textToSpeech.convert !== "function") {
51268
+ debugLogger.warn("Unsupported ElevenLabs client. Not wrapping.");
51269
+ return client;
51270
+ }
51271
+ const cached = clients.get(client);
51272
+ if (cached) return cached;
51273
+ const sdk = client;
51274
+ const speech = new Proxy(sdk.textToSpeech, {
51275
+ get(target, prop, receiver) {
51276
+ switch (prop) {
51277
+ case "convert":
51278
+ case "stream":
51279
+ return (...args) => elevenLabsChannels[prop].invoke(target[prop], target, args, {});
51280
+ case "convertWithTimestamps":
51281
+ return (...args) => elevenLabsChannels.convertWithTimestamps.invoke(
51282
+ target.convertWithTimestamps,
51283
+ target,
51284
+ args,
51285
+ {}
51286
+ );
51287
+ case "streamWithTimestamps":
51288
+ return (...args) => elevenLabsChannels.streamWithTimestamps.invoke(
51289
+ target.streamWithTimestamps,
51290
+ target,
51291
+ args,
51292
+ {}
51293
+ );
51294
+ default:
51295
+ return Reflect.get(target, prop, receiver);
51296
+ }
51297
+ }
51298
+ });
51299
+ const transcription = new Proxy(sdk.speechToText, {
51300
+ get(target, prop, receiver) {
51301
+ if (prop === "convert")
51302
+ return (request, options) => elevenLabsChannels.transcribe.invoke(
51303
+ target.convert,
51304
+ target,
51305
+ [request, options],
51306
+ {}
51307
+ );
51308
+ return Reflect.get(target, prop, receiver);
51309
+ }
51310
+ });
51311
+ const proxy = new Proxy(sdk, {
51312
+ get(target, prop, receiver) {
51313
+ if (prop === "textToSpeech") return speech;
51314
+ if (prop === "speechToText") return transcription;
51315
+ return Reflect.get(target, prop, receiver);
51316
+ }
51317
+ });
51318
+ clients.set(client, proxy);
51319
+ clients.set(proxy, proxy);
51320
+ return proxy;
51321
+ }
51322
+
50341
51323
  // src/browser/index.ts
50342
51324
  configureBrowser();
50343
51325
  export {
@@ -50503,9 +51485,11 @@ export {
50503
51485
  wrapCohere,
50504
51486
  wrapCopilotClient,
50505
51487
  wrapCursorSDK,
51488
+ wrapElevenLabs,
50506
51489
  wrapGenkit,
50507
51490
  wrapGoogleADK,
50508
51491
  wrapGoogleGenAI,
51492
+ wrapGoogleGenerativeAI,
50509
51493
  wrapGroq,
50510
51494
  wrapHuggingFace,
50511
51495
  wrapHuggingFaceTransformers,