braintrust 3.30.0 → 3.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/dev/dist/index.d.mts +740 -1
  2. package/dev/dist/index.d.ts +740 -1
  3. package/dev/dist/index.js +1307 -434
  4. package/dev/dist/index.mjs +886 -13
  5. package/dist/apply-auto-instrumentation.js +281 -216
  6. package/dist/apply-auto-instrumentation.mjs +66 -1
  7. package/dist/auto-instrumentations/bundler/esbuild.cjs +104 -2
  8. package/dist/auto-instrumentations/bundler/esbuild.mjs +2 -2
  9. package/dist/auto-instrumentations/bundler/next.cjs +113 -5
  10. package/dist/auto-instrumentations/bundler/next.mjs +12 -6
  11. package/dist/auto-instrumentations/bundler/rollup.cjs +104 -2
  12. package/dist/auto-instrumentations/bundler/rollup.mjs +2 -2
  13. package/dist/auto-instrumentations/bundler/vite.cjs +104 -2
  14. package/dist/auto-instrumentations/bundler/vite.mjs +2 -2
  15. package/dist/auto-instrumentations/bundler/webpack-loader.cjs +104 -2
  16. package/dist/auto-instrumentations/bundler/webpack.cjs +104 -2
  17. package/dist/auto-instrumentations/bundler/webpack.mjs +3 -3
  18. package/dist/auto-instrumentations/{chunk-U64OYU4Q.mjs → chunk-AFND2U7E.mjs} +38 -1
  19. package/dist/auto-instrumentations/{chunk-OXINGIEZ.mjs → chunk-QEEPRBIS.mjs} +1 -1
  20. package/dist/auto-instrumentations/{chunk-LW4HDHXT.mjs → chunk-RI4Y55ZF.mjs} +69 -2
  21. package/dist/auto-instrumentations/hook.mjs +126 -3
  22. package/dist/auto-instrumentations/index.cjs +39 -1
  23. package/dist/auto-instrumentations/index.d.mts +3 -1
  24. package/dist/auto-instrumentations/index.d.ts +3 -1
  25. package/dist/auto-instrumentations/index.mjs +3 -1
  26. package/dist/browser.d.mts +3052 -927
  27. package/dist/browser.d.ts +3052 -927
  28. package/dist/browser.js +1023 -18
  29. package/dist/browser.mjs +1023 -18
  30. package/dist/{chunk-BU6SM54N.mjs → chunk-4QSAHP7D.mjs} +834 -10
  31. package/dist/{chunk-2XDW3UCG.js → chunk-AW4QECG5.js} +47 -4
  32. package/dist/{chunk-TWCDSYJN.js → chunk-BTRLPQG5.js} +1679 -855
  33. package/dist/{chunk-N3JKQ3D3.mjs → chunk-WV6QZI2W.mjs} +46 -3
  34. package/dist/cli.js +950 -14
  35. package/dist/edge-light.d.mts +1 -1
  36. package/dist/edge-light.d.ts +1 -1
  37. package/dist/edge-light.js +1023 -18
  38. package/dist/edge-light.mjs +1023 -18
  39. package/dist/index.d.mts +3052 -927
  40. package/dist/index.d.ts +3052 -927
  41. package/dist/index.js +594 -450
  42. package/dist/index.mjs +149 -5
  43. package/dist/instrumentation/index.d.mts +434 -0
  44. package/dist/instrumentation/index.d.ts +434 -0
  45. package/dist/instrumentation/index.js +875 -12
  46. package/dist/instrumentation/index.mjs +875 -12
  47. package/dist/vitest-evals-reporter.js +16 -16
  48. package/dist/vitest-evals-reporter.mjs +2 -2
  49. package/dist/workerd.d.mts +1 -1
  50. package/dist/workerd.d.ts +1 -1
  51. package/dist/workerd.js +1023 -18
  52. package/dist/workerd.mjs +1023 -18
  53. package/package.json +1 -1
  54. package/util/dist/index.d.mts +326 -0
  55. package/util/dist/index.d.ts +326 -0
package/dist/cli.js CHANGED
@@ -1236,7 +1236,7 @@ var require_package = __commonJS({
1236
1236
  "package.json"(exports2, module2) {
1237
1237
  module2.exports = {
1238
1238
  name: "braintrust",
1239
- version: "3.30.0",
1239
+ version: "3.32.0",
1240
1240
  description: "SDK for integrating Braintrust",
1241
1241
  repository: {
1242
1242
  type: "git",
@@ -4353,6 +4353,14 @@ var ChatCompletionContentPartImageWithTitle = import_v36.z.object({
4353
4353
  ttl: import_v36.z.enum(["5m", "1h"]).optional()
4354
4354
  }).optional()
4355
4355
  });
4356
+ var ChatCompletionContentPartInputAudioWithTitle = import_v36.z.object({
4357
+ input_audio: import_v36.z.object({ data: import_v36.z.string(), format: import_v36.z.enum(["wav", "mp3"]) }),
4358
+ type: import_v36.z.literal("input_audio"),
4359
+ cache_control: import_v36.z.object({
4360
+ type: import_v36.z.literal("ephemeral"),
4361
+ ttl: import_v36.z.enum(["5m", "1h"]).optional()
4362
+ }).optional()
4363
+ });
4356
4364
  var ChatCompletionContentPartFileFile = import_v36.z.object({ file_data: import_v36.z.string(), filename: import_v36.z.string(), file_id: import_v36.z.string() }).partial();
4357
4365
  var ChatCompletionContentPartFileWithTitle = import_v36.z.object({
4358
4366
  file: ChatCompletionContentPartFileFile,
@@ -4365,6 +4373,7 @@ var ChatCompletionContentPartFileWithTitle = import_v36.z.object({
4365
4373
  var ChatCompletionContentPart = import_v36.z.union([
4366
4374
  ChatCompletionContentPartTextWithTitle,
4367
4375
  ChatCompletionContentPartImageWithTitle,
4376
+ ChatCompletionContentPartInputAudioWithTitle,
4368
4377
  ChatCompletionContentPartFileWithTitle
4369
4378
  ]);
4370
4379
  var ChatCompletionContentPartText = import_v36.z.object({
@@ -5356,6 +5365,7 @@ var ProjectSettings = import_v36.z.union([
5356
5365
  ]),
5357
5366
  disable_realtime_queries: import_v36.z.union([import_v36.z.boolean(), import_v36.z.null()]),
5358
5367
  monitor_charts_use_metrics_start: import_v36.z.union([import_v36.z.boolean(), import_v36.z.null()]),
5368
+ blind_reviews: import_v36.z.union([import_v36.z.boolean(), import_v36.z.null()]),
5359
5369
  default_preprocessor: NullableSavedFunctionId
5360
5370
  }).partial(),
5361
5371
  import_v36.z.null()
@@ -5417,6 +5427,7 @@ var WindowedAutomationConfig = import_v36.z.object({
5417
5427
  auto_approve_tools: import_v36.z.array(import_v36.z.string().min(1)).optional().default([]),
5418
5428
  harness: import_v36.z.enum(["native", "codex", "claude-code"]).optional(),
5419
5429
  model: import_v36.z.string().min(1).optional(),
5430
+ endpoint_name: import_v36.z.string().min(1).optional(),
5420
5431
  reasoning_effort: import_v36.z.enum(["none", "minimal", "low", "medium", "high", "xhigh", "max"]).optional()
5421
5432
  }).optional(),
5422
5433
  actions: import_v36.z.array(
@@ -7188,6 +7199,7 @@ var INSTRUMENTATION_NAMES = {
7188
7199
  GENKIT: "genkit",
7189
7200
  GITHUB_COPILOT: "github-copilot",
7190
7201
  GOOGLE_ADK: "google-adk",
7202
+ GOOGLE_GENERATIVE_AI: "google-generative-ai",
7191
7203
  GOOGLE_GENAI: "google-genai",
7192
7204
  GROQ: "groq",
7193
7205
  HUGGINGFACE: "huggingface",
@@ -7203,12 +7215,13 @@ var INSTRUMENTATION_NAMES = {
7203
7215
  OPENROUTER_AGENT: "openrouter-agent",
7204
7216
  PI_CODING_AGENT: "pi-coding-agent",
7205
7217
  STRANDS_AGENT_SDK: "strands-agent-sdk",
7206
- VOYAGEAI: "voyageai"
7218
+ VOYAGEAI: "voyageai",
7219
+ ELEVENLABS: "elevenlabs"
7207
7220
  };
7208
7221
  var INTERNAL_SPAN_INSTRUMENTATION_NAME = /* @__PURE__ */ Symbol.for(
7209
7222
  "braintrust.spanInstrumentationName"
7210
7223
  );
7211
- var SDK_VERSION = true ? "3.30.0" : "0.0.0";
7224
+ var SDK_VERSION = true ? "3.32.0" : "0.0.0";
7212
7225
  function withSpanInstrumentationName(args, instrumentationName) {
7213
7226
  return {
7214
7227
  ...args,
@@ -12382,6 +12395,16 @@ function renderMessageImpl(render, message, variables) {
12382
12395
  }
12383
12396
  }
12384
12397
  ];
12398
+ case "input_audio":
12399
+ return [
12400
+ {
12401
+ ...c,
12402
+ input_audio: {
12403
+ ...c.input_audio,
12404
+ data: render(c.input_audio.data)
12405
+ }
12406
+ }
12407
+ ];
12385
12408
  case "file":
12386
12409
  return [
12387
12410
  {
@@ -14769,19 +14792,29 @@ function buildSpanScores(results) {
14769
14792
  function _internalPrepareEvaluatorScore(scoreValue, name) {
14770
14793
  if (scoreValue === null) return { results: null };
14771
14794
  if (Array.isArray(scoreValue)) {
14795
+ const names = /* @__PURE__ */ new Set();
14772
14796
  for (const score of scoreValue) {
14773
14797
  if (!(typeof score === "object" && !isEmpty2(score))) {
14774
14798
  throw new Error(
14775
14799
  `When returning an array of scores, each score must be a non-empty object. Got: ${JSON.stringify(score)}`
14776
14800
  );
14777
14801
  }
14802
+ if (typeof score.name !== "string") {
14803
+ throw new Error(
14804
+ `When returning an array of scores, each score must have a name. Got: ${JSON.stringify(score)}`
14805
+ );
14806
+ }
14807
+ if (names.has(score.name)) {
14808
+ throw new Error(`Duplicate score name '${score.name}' in score array`);
14809
+ }
14810
+ names.add(score.name);
14778
14811
  }
14779
14812
  }
14780
14813
  let results;
14781
14814
  if (Array.isArray(scoreValue)) {
14782
14815
  results = scoreValue;
14783
14816
  } else if (typeof scoreValue === "object" && !isEmpty2(scoreValue)) {
14784
- results = [scoreValue];
14817
+ results = [{ ...scoreValue, name: scoreValue.name ?? name }];
14785
14818
  } else {
14786
14819
  results = [{ name, score: scoreValue }];
14787
14820
  }
@@ -23562,6 +23595,12 @@ function prepareAISDKChildTracing(params, self, parentSpan, denyOutputPaths, aiS
23562
23595
  if (!activeEntry) {
23563
23596
  return result;
23564
23597
  }
23598
+ const executionOptions = args[1];
23599
+ const toolCallId = isObject(executionOptions) ? executionOptions.toolCallId : void 0;
23600
+ const toolInput = {
23601
+ input: serializeToolExecutionInput(args),
23602
+ ...typeof toolCallId === "string" ? { metadata: { toolCallId } } : {}
23603
+ };
23565
23604
  if (isAsyncGenerator2(result)) {
23566
23605
  return (async function* () {
23567
23606
  const span = activeEntry.parentSpan.startSpan(
@@ -23575,7 +23614,7 @@ function prepareAISDKChildTracing(params, self, parentSpan, denyOutputPaths, aiS
23575
23614
  INSTRUMENTATION_NAMES.AI_SDK
23576
23615
  )
23577
23616
  );
23578
- span.log({ input: serializeToolExecutionInput(args) });
23617
+ span.log(toolInput);
23579
23618
  try {
23580
23619
  let lastValue;
23581
23620
  for await (const value of result) {
@@ -23593,7 +23632,7 @@ function prepareAISDKChildTracing(params, self, parentSpan, denyOutputPaths, aiS
23593
23632
  }
23594
23633
  return activeEntry.parentSpan.traced(
23595
23634
  async (span) => {
23596
- span.log({ input: serializeToolExecutionInput(args) });
23635
+ span.log(toolInput);
23597
23636
  const awaitedResult = await result;
23598
23637
  span.log({ output: awaitedResult });
23599
23638
  return awaitedResult;
@@ -27997,6 +28036,342 @@ var OpenAIAgentsPlugin = class extends BasePlugin {
27997
28036
  }
27998
28037
  };
27999
28038
 
28039
+ // src/instrumentation/plugins/google-generative-ai-channels.ts
28040
+ var googleGenerativeAIChannels = defineChannels(
28041
+ "@google/generative-ai",
28042
+ {
28043
+ generateContent: channel({ channelName: "GenerativeModel.generateContent", kind: "async" }),
28044
+ generateContentStream: channel({ channelName: "GenerativeModel.generateContentStream", kind: "async" }),
28045
+ embedContent: channel({ channelName: "GenerativeModel.embedContent", kind: "async" }),
28046
+ batchEmbedContents: channel({ channelName: "GenerativeModel.batchEmbedContents", kind: "async" }),
28047
+ sendMessage: channel({ channelName: "ChatSession.sendMessage", kind: "async" }),
28048
+ sendMessageStream: channel({ channelName: "ChatSession.sendMessageStream", kind: "async" })
28049
+ },
28050
+ { instrumentationName: INSTRUMENTATION_NAMES.GOOGLE_GENERATIVE_AI }
28051
+ );
28052
+
28053
+ // src/instrumentation/plugins/google-generative-ai-plugin.ts
28054
+ var GENERATION_CONFIG_KEYS = [
28055
+ "temperature",
28056
+ "topP",
28057
+ "topK",
28058
+ "candidateCount",
28059
+ "maxOutputTokens",
28060
+ "stopSequences",
28061
+ "responseMimeType",
28062
+ "responseSchema",
28063
+ "presencePenalty",
28064
+ "frequencyPenalty",
28065
+ "responseLogprobs",
28066
+ "logprobs",
28067
+ "thinkingConfig"
28068
+ ];
28069
+ var GoogleGenerativeAIPlugin = class extends BasePlugin {
28070
+ onEnable() {
28071
+ this.unsubscribers.push(
28072
+ interceptCall(
28073
+ googleGenerativeAIChannels.generateContent,
28074
+ "generateContent"
28075
+ ),
28076
+ interceptCall(
28077
+ googleGenerativeAIChannels.generateContentStream,
28078
+ "generateContentStream"
28079
+ ),
28080
+ interceptCall(googleGenerativeAIChannels.sendMessage, "sendMessage"),
28081
+ interceptCall(
28082
+ googleGenerativeAIChannels.sendMessageStream,
28083
+ "sendMessageStream"
28084
+ ),
28085
+ interceptCall(googleGenerativeAIChannels.embedContent, "embedContent"),
28086
+ interceptCall(
28087
+ googleGenerativeAIChannels.batchEmbedContents,
28088
+ "batchEmbedContents"
28089
+ )
28090
+ );
28091
+ }
28092
+ onDisable() {
28093
+ this.unsubscribers = unsubscribeAll(this.unsubscribers);
28094
+ }
28095
+ };
28096
+ function interceptCall(channel2, operation) {
28097
+ return channel2.intercept((target, thisArg, args) => {
28098
+ const invokeTarget = () => Reflect.apply(target, thisArg, args);
28099
+ if (isAutoInstrumentationSuppressed()) return invokeTarget();
28100
+ const self = thisArg;
28101
+ const chat = operation.startsWith("sendMessage");
28102
+ const embedding = operation === "embedContent" || operation === "batchEmbedContents";
28103
+ const start = getCurrentUnixTimestamp();
28104
+ let span;
28105
+ try {
28106
+ span = startSpan(
28107
+ withSpanInstrumentationName(
28108
+ {
28109
+ name: embedding ? operation === "embedContent" ? "embed_content" : "batch_embed_contents" : "generate_content",
28110
+ spanAttributes: { type: "llm" /* LLM */ },
28111
+ event: extractInput(self, args[0], operation)
28112
+ },
28113
+ INSTRUMENTATION_NAMES.GOOGLE_GENERATIVE_AI
28114
+ )
28115
+ );
28116
+ } catch (error2) {
28117
+ debugLogger.error("Error starting Google Generative AI span:", error2);
28118
+ return invokeTarget();
28119
+ }
28120
+ let ended = false;
28121
+ const finish = (log2) => {
28122
+ if (ended) return;
28123
+ ended = true;
28124
+ try {
28125
+ log2();
28126
+ } catch (error2) {
28127
+ debugLogger.error("Error logging Google Generative AI span:", error2);
28128
+ }
28129
+ try {
28130
+ span.end();
28131
+ } catch (error2) {
28132
+ debugLogger.error("Error ending Google Generative AI span:", error2);
28133
+ }
28134
+ };
28135
+ if (chat) {
28136
+ try {
28137
+ void self._sendPromise.then(
28138
+ () => {
28139
+ try {
28140
+ span.log(extractInput(self, args[0], operation));
28141
+ } catch (error2) {
28142
+ debugLogger.error("Error capturing Google chat history:", error2);
28143
+ }
28144
+ },
28145
+ () => {
28146
+ }
28147
+ );
28148
+ } catch (error2) {
28149
+ debugLogger.error("Error observing Google chat history:", error2);
28150
+ }
28151
+ }
28152
+ let result;
28153
+ try {
28154
+ result = withCurrent(
28155
+ span,
28156
+ () => runWithAutoInstrumentationSuppressed(invokeTarget)
28157
+ );
28158
+ } catch (error2) {
28159
+ finish(() => span.log({ error: error2 }));
28160
+ throw error2;
28161
+ }
28162
+ void Promise.resolve(result).then(
28163
+ (value) => {
28164
+ try {
28165
+ if ("stream" in value) {
28166
+ let firstToken = false;
28167
+ const partial = { candidates: [] };
28168
+ const candidates = /* @__PURE__ */ new Map();
28169
+ patchStreamIfNeeded(value.stream, {
28170
+ aroundNext: (callback) => withCurrent(span, callback),
28171
+ onChunk: (chunk) => {
28172
+ for (const candidate of chunk.candidates ?? []) {
28173
+ const index = candidate.index ?? 0;
28174
+ const previous = candidates.get(index);
28175
+ const parts = [...previous?.content?.parts ?? []];
28176
+ for (const part of candidate.content?.parts ?? []) {
28177
+ const last = parts[parts.length - 1];
28178
+ if (part.text !== void 0 && last?.text !== void 0) {
28179
+ parts[parts.length - 1] = {
28180
+ ...last,
28181
+ text: last.text + part.text
28182
+ };
28183
+ } else parts.push(part);
28184
+ }
28185
+ candidates.set(index, {
28186
+ ...previous,
28187
+ ...candidate,
28188
+ content: {
28189
+ role: candidate.content?.role ?? previous?.content?.role ?? "model",
28190
+ parts
28191
+ }
28192
+ });
28193
+ }
28194
+ partial.candidates = Array.from(candidates.values());
28195
+ if (chunk.usageMetadata)
28196
+ partial.usageMetadata = chunk.usageMetadata;
28197
+ if (!firstToken && chunk.candidates?.some(
28198
+ (candidate) => candidate.content?.parts.some(
28199
+ (part) => part.text !== void 0 ? part.text.length > 0 : Object.keys(part).length > 0
28200
+ )
28201
+ )) {
28202
+ firstToken = true;
28203
+ span.log({
28204
+ metrics: {
28205
+ time_to_first_token: getCurrentUnixTimestamp() - start
28206
+ }
28207
+ });
28208
+ }
28209
+ },
28210
+ onComplete: () => {
28211
+ },
28212
+ onError: (error2) => finish(() => {
28213
+ logResponse(span, partial);
28214
+ span.log({ error: error2 });
28215
+ }),
28216
+ onCancel: () => finish(() => logResponse(span, partial))
28217
+ });
28218
+ void value.response.then(
28219
+ (response) => finish(() => logResponse(span, response)),
28220
+ (error2) => finish(() => {
28221
+ logResponse(span, partial);
28222
+ span.log({ error: error2 });
28223
+ })
28224
+ );
28225
+ } else if ("response" in value) {
28226
+ finish(() => logResponse(span, value.response));
28227
+ } else {
28228
+ const metrics = {};
28229
+ const promptTokens = value.usageMetadata?.promptTokenCount;
28230
+ if (typeof promptTokens === "number" && Number.isFinite(promptTokens) && promptTokens >= 0) {
28231
+ metrics.prompt_tokens = promptTokens;
28232
+ metrics.tokens = promptTokens;
28233
+ }
28234
+ for (const detail of value.usageMetadata?.promptTokenDetails ?? []) {
28235
+ if (detail.modality === "AUDIO" && typeof detail.tokenCount === "number" && Number.isFinite(detail.tokenCount) && detail.tokenCount >= 0) {
28236
+ metrics.prompt_audio_tokens = (metrics.prompt_audio_tokens ?? 0) + detail.tokenCount;
28237
+ }
28238
+ }
28239
+ finish(
28240
+ () => span.log({
28241
+ metrics,
28242
+ output: {
28243
+ count: value.embeddings?.length ?? (value.embedding ? 1 : 0)
28244
+ }
28245
+ })
28246
+ );
28247
+ }
28248
+ } catch (error2) {
28249
+ debugLogger.error(
28250
+ "Error observing Google Generative AI result:",
28251
+ error2
28252
+ );
28253
+ finish(() => {
28254
+ });
28255
+ }
28256
+ },
28257
+ (error2) => finish(() => span.log({ error: error2 }))
28258
+ );
28259
+ return result;
28260
+ });
28261
+ }
28262
+ function normalizeContent(message) {
28263
+ const parts = (typeof message === "string" ? [message] : message).map(
28264
+ (part) => typeof part === "string" ? { text: part } : part
28265
+ );
28266
+ return {
28267
+ role: parts.some((part) => part.functionResponse) ? "function" : "user",
28268
+ parts
28269
+ };
28270
+ }
28271
+ function extractInput(self, request, operation) {
28272
+ const model = self.model.replace(/^models\//, "");
28273
+ if (operation === "embedContent" || operation === "batchEmbedContents") {
28274
+ const requests = operation === "batchEmbedContents" ? request.requests : [
28275
+ typeof request === "string" || Array.isArray(request) ? { content: normalizeContent(request) } : request
28276
+ ];
28277
+ const dimensions = requests[0]?.outputDimensionality;
28278
+ return {
28279
+ input: {
28280
+ inputs: convertAttachments(requests).map((item) => ({
28281
+ content: item.content.parts.length === 1 && item.content.parts[0].text !== void 0 ? item.content.parts[0].text : item.content.parts.map((part) => {
28282
+ if (part.text !== void 0)
28283
+ return { type: "text", text: part.text };
28284
+ const mimeType = part.inlineData?.mimeType ?? part.fileData?.mimeType;
28285
+ const data = part.inlineData ? typeof part.inlineData.data === "string" ? `data:${mimeType};base64,${part.inlineData.data}` : part.inlineData.data : part.fileData?.fileUri;
28286
+ return mimeType?.startsWith("image/") ? { type: "image_url", image_url: { url: data } } : { type: "file", file: { file_data: data } };
28287
+ })
28288
+ })),
28289
+ ...dimensions !== void 0 && requests.every((item) => item.outputDimensionality === dimensions) ? { output_dimensions: dimensions } : {}
28290
+ },
28291
+ metadata: { model, provider: "google" }
28292
+ };
28293
+ }
28294
+ const chat = operation.startsWith("sendMessage");
28295
+ const config3 = chat ? self.params ?? {} : self;
28296
+ const params = typeof request === "string" || Array.isArray(request) ? { contents: [normalizeContent(request)] } : request;
28297
+ const system = params.systemInstruction ?? config3.systemInstruction;
28298
+ const systemContent = typeof system === "string" ? { role: "system", parts: [{ text: system }] } : system && "parts" in system ? { ...system, role: "system" } : system ? { role: "system", parts: [system] } : void 0;
28299
+ const contents = [
28300
+ ...systemContent ? [systemContent] : [],
28301
+ ...chat ? self._history : [],
28302
+ ...params.contents
28303
+ ];
28304
+ const metadata = { model, provider: "google" };
28305
+ const generation = params.generationConfig ?? config3.generationConfig;
28306
+ for (const key of GENERATION_CONFIG_KEYS) {
28307
+ if (generation && Object.hasOwn(generation, key))
28308
+ metadata[key] = generation[key];
28309
+ }
28310
+ for (const key of ["tools", "toolConfig", "safetySettings"]) {
28311
+ const value = params[key] ?? config3[key];
28312
+ if (value !== void 0) metadata[key] = value;
28313
+ }
28314
+ const cached = params.cachedContent ?? config3.cachedContent;
28315
+ if (cached)
28316
+ metadata.cachedContent = typeof cached === "string" ? cached : cached.name;
28317
+ return { input: convertAttachments({ model, contents }), metadata };
28318
+ }
28319
+ function convertAttachments(value) {
28320
+ const convert = (node) => {
28321
+ if (Array.isArray(node)) return node.map(convert);
28322
+ if (!isObject(node)) return node;
28323
+ if (isObject(node.inlineData)) {
28324
+ const { data, mimeType } = node.inlineData;
28325
+ const processed = processInputAttachments({
28326
+ type: "file",
28327
+ file: { file_data: `data:${mimeType};base64,${data}` }
28328
+ });
28329
+ if (typeof processed.file.file_data === "string")
28330
+ throw new Error("Unable to convert Google inline data");
28331
+ return {
28332
+ ...node,
28333
+ inlineData: { ...node.inlineData, data: processed.file.file_data }
28334
+ };
28335
+ }
28336
+ return Object.fromEntries(
28337
+ Object.entries(node).map(([key, item]) => [key, convert(item)])
28338
+ );
28339
+ };
28340
+ try {
28341
+ return convert(value);
28342
+ } catch (error2) {
28343
+ debugLogger.error(
28344
+ "Error converting Google Generative AI attachments:",
28345
+ error2
28346
+ );
28347
+ return value;
28348
+ }
28349
+ }
28350
+ function logResponse(span, response) {
28351
+ const usage = response.usageMetadata;
28352
+ const metrics = {};
28353
+ if (usage) {
28354
+ if (usage.promptTokenCount !== void 0)
28355
+ metrics.prompt_tokens = usage.promptTokenCount;
28356
+ if (usage.candidatesTokenCount !== void 0 || usage.thoughtsTokenCount !== void 0)
28357
+ metrics.completion_tokens = (usage.candidatesTokenCount ?? 0) + (usage.thoughtsTokenCount ?? 0);
28358
+ if (usage.totalTokenCount !== void 0)
28359
+ metrics.tokens = usage.totalTokenCount;
28360
+ if (usage.cachedContentTokenCount !== void 0)
28361
+ metrics.prompt_cached_tokens = usage.cachedContentTokenCount;
28362
+ if (usage.thoughtsTokenCount !== void 0)
28363
+ metrics.completion_reasoning_tokens = usage.thoughtsTokenCount;
28364
+ }
28365
+ span.log({
28366
+ output: convertAttachments({
28367
+ candidates: response.candidates,
28368
+ promptFeedback: response.promptFeedback
28369
+ }),
28370
+ metrics,
28371
+ ...response.modelVersion ? { metadata: { model: response.modelVersion } } : {}
28372
+ });
28373
+ }
28374
+
28000
28375
  // src/instrumentation/plugins/google-genai-channels.ts
28001
28376
  var googleGenAIChannels = defineChannels(
28002
28377
  "@google/genai",
@@ -29640,7 +30015,7 @@ var HuggingFaceTransformersPlugin = class extends BasePlugin {
29640
30015
  getTask(event)
29641
30016
  ),
29642
30017
  extractInput: (args, event) => ({
29643
- input: extractInput(
30018
+ input: extractInput2(
29644
30019
  getTask(event),
29645
30020
  args
29646
30021
  ),
@@ -29730,7 +30105,7 @@ function modelIdentifier(pipeline) {
29730
30105
  }
29731
30106
  return void 0;
29732
30107
  }
29733
- function extractInput(task, args) {
30108
+ function extractInput2(task, args) {
29734
30109
  switch (task) {
29735
30110
  case "feature-extraction":
29736
30111
  return args[0];
@@ -37715,14 +38090,17 @@ function getMetricsFromResponse(response) {
37715
38090
  if (!isRecord(usageMetadata)) {
37716
38091
  continue;
37717
38092
  }
37718
- const inputTokenDetails = usageMetadata.input_token_details;
38093
+ const inputTokenDetails = isRecord(usageMetadata.input_token_details) ? usageMetadata.input_token_details : {};
37719
38094
  const outputTokenDetails = usageMetadata.output_token_details;
37720
38095
  return normalizeTokenMetrics({
37721
38096
  total_tokens: usageMetadata.total_tokens,
37722
38097
  prompt_tokens: usageMetadata.input_tokens,
37723
38098
  completion_tokens: usageMetadata.output_tokens,
37724
- prompt_cache_creation_tokens: isRecord(inputTokenDetails) ? inputTokenDetails.cache_creation : void 0,
37725
- prompt_cached_tokens: isRecord(inputTokenDetails) ? inputTokenDetails.cache_read : void 0,
38099
+ // Prefer TTL-specific cache writes over the aggregate when available.
38100
+ prompt_cache_creation_tokens: inputTokenDetails.ephemeral_5m_input_tokens == null && inputTokenDetails.ephemeral_1h_input_tokens == null ? inputTokenDetails.cache_creation : void 0,
38101
+ prompt_cache_creation_5m_tokens: inputTokenDetails.ephemeral_5m_input_tokens,
38102
+ prompt_cache_creation_1h_tokens: inputTokenDetails.ephemeral_1h_input_tokens,
38103
+ prompt_cached_tokens: inputTokenDetails.cache_read,
37726
38104
  completion_reasoning_tokens: isRecord(outputTokenDetails) ? outputTokenDetails.reasoning : void 0
37727
38105
  });
37728
38106
  }
@@ -40081,6 +40459,477 @@ function logInstrumentationError5(context2, error2) {
40081
40459
  debugLogger.debug(`${context2}:`, error2);
40082
40460
  }
40083
40461
 
40462
+ // src/instrumentation/plugins/elevenlabs-channels.ts
40463
+ var elevenLabsChannels = defineChannels(
40464
+ "@elevenlabs/elevenlabs-js",
40465
+ {
40466
+ convert: channel({
40467
+ channelName: "textToSpeech.convert",
40468
+ kind: "async"
40469
+ }),
40470
+ stream: channel({
40471
+ channelName: "textToSpeech.stream",
40472
+ kind: "async"
40473
+ }),
40474
+ convertWithTimestamps: channel({ channelName: "textToSpeech.convertWithTimestamps", kind: "async" }),
40475
+ streamWithTimestamps: channel({ channelName: "textToSpeech.streamWithTimestamps", kind: "async" }),
40476
+ transcribe: channel({ channelName: "speechToText.convert", kind: "async" })
40477
+ },
40478
+ { instrumentationName: INSTRUMENTATION_NAMES.ELEVENLABS }
40479
+ );
40480
+
40481
+ // src/instrumentation/plugins/elevenlabs-plugin.ts
40482
+ var ElevenLabsPlugin = class extends BasePlugin {
40483
+ onEnable() {
40484
+ for (const method of [
40485
+ "convert",
40486
+ "stream",
40487
+ "convertWithTimestamps",
40488
+ "streamWithTimestamps"
40489
+ ]) {
40490
+ this.unsubscribers.push(
40491
+ interceptCall2(
40492
+ elevenLabsChannels[method],
40493
+ `elevenlabs.textToSpeech.${method}`,
40494
+ ([voice, request]) => ({
40495
+ input: {
40496
+ operation: "speech",
40497
+ prompt: request.text,
40498
+ parameters: {
40499
+ voice,
40500
+ format: request.outputFormat,
40501
+ language: request.languageCode,
40502
+ speed: request.voiceSettings?.speed
40503
+ }
40504
+ },
40505
+ metadata: {
40506
+ provider: "elevenlabs",
40507
+ model: request.modelId ?? "eleven_multilingual_v2"
40508
+ }
40509
+ }),
40510
+ (value, args, span, finish, headers, started) => captureSpeech(
40511
+ value,
40512
+ args[1],
40513
+ method,
40514
+ span,
40515
+ finish,
40516
+ started,
40517
+ headers
40518
+ )
40519
+ )
40520
+ );
40521
+ }
40522
+ this.unsubscribers.push(
40523
+ interceptCall2(
40524
+ elevenLabsChannels.transcribe,
40525
+ "elevenlabs.speechToText.convert",
40526
+ ([request]) => {
40527
+ if (request.webhook) return void 0;
40528
+ const file = request.file;
40529
+ const filename = typeof File !== "undefined" && file instanceof File ? file.name : "audio";
40530
+ const contentType = file instanceof Blob ? file.type || "application/octet-stream" : "application/octet-stream";
40531
+ 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;
40532
+ const fileData = blob ? new Attachment({ data: blob, filename, contentType }) : request.cloudStorageUrl;
40533
+ return {
40534
+ input: {
40535
+ operation: "transcribe",
40536
+ content: fileData ? [{ type: "file", file: { filename, file_data: fileData } }] : [],
40537
+ parameters: {
40538
+ language: request.languageCode,
40539
+ timestamp_granularities: request.timestampsGranularity
40540
+ }
40541
+ },
40542
+ metadata: { provider: "elevenlabs", model: request.modelId }
40543
+ };
40544
+ },
40545
+ (value, _args, span, finish) => {
40546
+ const result = value;
40547
+ const transcripts = result.transcripts ?? [result];
40548
+ span.log({
40549
+ output: {
40550
+ content: transcripts.flatMap(
40551
+ (transcript) => typeof transcript.text === "string" ? [{ type: "text", text: transcript.text }] : []
40552
+ ),
40553
+ annotations: {
40554
+ language: result.languageCode,
40555
+ words: result.words ?? (result.transcripts ? result.transcripts.flatMap(
40556
+ (transcript) => transcript.words ?? []
40557
+ ) : void 0)
40558
+ }
40559
+ }
40560
+ });
40561
+ finish();
40562
+ },
40563
+ ([request], span) => {
40564
+ const file = request.file;
40565
+ if (!isAsyncIterable3(file)) return;
40566
+ const chunks = [];
40567
+ const filename = isObject(file) && typeof file.path === "string" ? file.path.split(/[\\/]/).pop() || "audio" : "audio";
40568
+ observeAudioStream(
40569
+ file,
40570
+ (chunk) => chunks.push(new Uint8Array(chunk)),
40571
+ () => {
40572
+ const contentType = "application/octet-stream";
40573
+ const data = new Blob(chunks, {
40574
+ type: contentType
40575
+ });
40576
+ chunks.length = 0;
40577
+ span.log({
40578
+ input: {
40579
+ content: [
40580
+ {
40581
+ type: "file",
40582
+ file: {
40583
+ filename,
40584
+ file_data: new Attachment({
40585
+ data,
40586
+ filename,
40587
+ contentType
40588
+ })
40589
+ }
40590
+ }
40591
+ ]
40592
+ }
40593
+ });
40594
+ },
40595
+ () => {
40596
+ chunks.length = 0;
40597
+ },
40598
+ span
40599
+ );
40600
+ }
40601
+ )
40602
+ );
40603
+ }
40604
+ onDisable() {
40605
+ this.unsubscribers = unsubscribeAll(this.unsubscribers);
40606
+ }
40607
+ };
40608
+ function interceptCall2(channel2, name, input, output, beforeInvoke) {
40609
+ return channel2.intercept((target, self, args) => {
40610
+ const invoke2 = () => Reflect.apply(target, self, args);
40611
+ if (isAutoInstrumentationSuppressed()) return invoke2();
40612
+ const started = Date.now() / 1e3;
40613
+ let span;
40614
+ try {
40615
+ const event = input(args);
40616
+ if (event !== void 0)
40617
+ span = startSpan(
40618
+ withSpanInstrumentationName(
40619
+ {
40620
+ name,
40621
+ spanAttributes: { type: "llm" /* LLM */ },
40622
+ event
40623
+ },
40624
+ INSTRUMENTATION_NAMES.ELEVENLABS
40625
+ )
40626
+ );
40627
+ } catch (error2) {
40628
+ debugLogger.error("Error starting ElevenLabs span", error2);
40629
+ return invoke2();
40630
+ }
40631
+ if (!span) return invoke2();
40632
+ const activeSpan = span;
40633
+ let ended = false;
40634
+ const finish = (error2) => {
40635
+ if (ended) return;
40636
+ ended = true;
40637
+ try {
40638
+ if (error2 !== void 0) activeSpan.log({ error: error2 });
40639
+ activeSpan.end();
40640
+ } catch (loggingError) {
40641
+ debugLogger.error("Error ending ElevenLabs span", loggingError);
40642
+ }
40643
+ };
40644
+ try {
40645
+ beforeInvoke?.(args, span);
40646
+ } catch (error2) {
40647
+ debugLogger.error("Error observing ElevenLabs input", error2);
40648
+ }
40649
+ let result;
40650
+ try {
40651
+ result = withCurrent(
40652
+ span,
40653
+ () => runWithAutoInstrumentationSuppressed(invoke2)
40654
+ );
40655
+ } catch (error2) {
40656
+ finish(error2);
40657
+ throw error2;
40658
+ }
40659
+ const capture = (value, headers) => {
40660
+ try {
40661
+ output(value, args, span, finish, headers, started);
40662
+ } catch (error2) {
40663
+ debugLogger.error("Error capturing ElevenLabs output", error2);
40664
+ finish();
40665
+ }
40666
+ };
40667
+ try {
40668
+ if (isObject(result) && typeof result.withRawResponse === "function") {
40669
+ void result.withRawResponse().then(
40670
+ ({
40671
+ data,
40672
+ rawResponse
40673
+ }) => capture(data, rawResponse?.headers),
40674
+ finish
40675
+ );
40676
+ } else {
40677
+ void Promise.resolve(result).then((value) => capture(value), finish);
40678
+ }
40679
+ } catch (error2) {
40680
+ debugLogger.error("Error observing ElevenLabs result", error2);
40681
+ finish();
40682
+ }
40683
+ return result;
40684
+ });
40685
+ }
40686
+ function captureSpeech(value, request, method, span, finish, started, headers) {
40687
+ const format = request.outputFormat ?? "mp3_44100_128";
40688
+ 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;
40689
+ const headerType = headers?.get("content-type")?.split(";")[0];
40690
+ const contentType = headerType?.startsWith("audio/") ? headerType : formatType;
40691
+ const disposition = headers?.get("content-disposition");
40692
+ const headerFilename = disposition?.match(
40693
+ /filename="([^"]+)"|filename=([^;]+)/i
40694
+ );
40695
+ const filename = headerFilename?.[1] ?? headerFilename?.[2]?.trim() ?? `speech.${contentType ? getExtensionFromMediaType(contentType) : "bin"}`;
40696
+ const chunks = [];
40697
+ const alignments = [];
40698
+ let bytes = 0;
40699
+ let first = true;
40700
+ let stopped = false;
40701
+ const observe = (chunk) => {
40702
+ if (stopped || chunk.byteLength === 0) return;
40703
+ if (first && method.startsWith("stream")) {
40704
+ span.log({
40705
+ metrics: { time_to_first_token: Date.now() / 1e3 - started }
40706
+ });
40707
+ }
40708
+ first = false;
40709
+ chunks.push(new Uint8Array(chunk));
40710
+ bytes += chunk.byteLength;
40711
+ };
40712
+ const complete = () => {
40713
+ if (stopped) return;
40714
+ stopped = true;
40715
+ try {
40716
+ const content = [];
40717
+ if (contentType && bytes) {
40718
+ const data = new Uint8Array(bytes);
40719
+ let offset = 0;
40720
+ for (const chunk of chunks) {
40721
+ data.set(chunk, offset);
40722
+ offset += chunk.length;
40723
+ }
40724
+ content.push({
40725
+ type: "file",
40726
+ file: {
40727
+ filename,
40728
+ byte_size: bytes,
40729
+ file_data: new Attachment({
40730
+ data: new Blob([data], { type: contentType }),
40731
+ filename,
40732
+ contentType
40733
+ })
40734
+ }
40735
+ });
40736
+ }
40737
+ span.log({
40738
+ output: {
40739
+ content,
40740
+ ...alignments.length ? { annotations: alignments } : {}
40741
+ }
40742
+ });
40743
+ } finally {
40744
+ chunks.length = 0;
40745
+ finish();
40746
+ }
40747
+ };
40748
+ const cancel = (error2) => {
40749
+ stopped = true;
40750
+ chunks.length = 0;
40751
+ finish(error2);
40752
+ };
40753
+ const timestampChunk = (chunk) => {
40754
+ const binary = atob(chunk.audioBase64);
40755
+ observe(Uint8Array.from(binary, (character) => character.charCodeAt(0)));
40756
+ if (chunk.alignment || chunk.normalizedAlignment)
40757
+ alignments.push({
40758
+ alignment: chunk.alignment,
40759
+ normalized_alignment: chunk.normalizedAlignment
40760
+ });
40761
+ };
40762
+ if (method === "convertWithTimestamps") {
40763
+ timestampChunk(value);
40764
+ complete();
40765
+ } else if (method === "streamWithTimestamps") {
40766
+ patchStreamIfNeeded(value, {
40767
+ shouldCollect: (chunk) => {
40768
+ try {
40769
+ timestampChunk(chunk);
40770
+ } catch (error2) {
40771
+ debugLogger.error("Error collecting ElevenLabs timestamps", error2);
40772
+ cancel();
40773
+ }
40774
+ return false;
40775
+ },
40776
+ onComplete: complete,
40777
+ onCancel: () => cancel(),
40778
+ onError: cancel,
40779
+ aroundNext: (next) => withCurrent(span, next)
40780
+ });
40781
+ } else {
40782
+ observeAudioStream(value, observe, complete, cancel, span);
40783
+ }
40784
+ }
40785
+ function observeAudioStream(value, observe, complete, cancel, span) {
40786
+ let ended = false;
40787
+ const safeObserve = (chunk) => {
40788
+ if (ended) return;
40789
+ try {
40790
+ observe(chunk);
40791
+ } catch (error2) {
40792
+ debugLogger.error("Error collecting ElevenLabs audio", error2);
40793
+ end(false);
40794
+ }
40795
+ };
40796
+ const end = (success, error2) => {
40797
+ if (ended) return;
40798
+ ended = true;
40799
+ try {
40800
+ if (success) complete();
40801
+ else cancel(error2);
40802
+ } catch (loggingError) {
40803
+ debugLogger.error("Error logging ElevenLabs audio", loggingError);
40804
+ cancel();
40805
+ }
40806
+ };
40807
+ if (!isObject(value) || !Object.isExtensible(value)) {
40808
+ end(false);
40809
+ return;
40810
+ }
40811
+ if (typeof value.read === "function" && typeof value.on === "function") {
40812
+ value.on("end", () => end(true));
40813
+ value.on("close", () => end(false));
40814
+ const emit2 = value.emit;
40815
+ if (typeof emit2 === "function")
40816
+ value.emit = function(event, ...args) {
40817
+ if (event === "data" && args[0] instanceof Uint8Array)
40818
+ safeObserve(args[0]);
40819
+ if (event === "error") end(false, args[0]);
40820
+ return Reflect.apply(emit2, this, [event, ...args]);
40821
+ };
40822
+ return;
40823
+ }
40824
+ if (typeof value.getReader === "function") {
40825
+ const webStream = value;
40826
+ const pipeTo = webStream.pipeTo;
40827
+ const pipeThrough = webStream.pipeThrough;
40828
+ webStream.pipeTo = function(destination, options) {
40829
+ if (!isObject(destination) || this.locked || destination.locked)
40830
+ return pipeTo.call(this, destination, options);
40831
+ const tap = new TransformStream({
40832
+ transform(chunk, controller) {
40833
+ safeObserve(chunk);
40834
+ controller.enqueue(chunk);
40835
+ },
40836
+ flush() {
40837
+ end(true);
40838
+ }
40839
+ });
40840
+ const observed = pipeThrough.call(
40841
+ this,
40842
+ tap,
40843
+ options
40844
+ );
40845
+ return observed.pipeTo(destination, options).catch((error2) => {
40846
+ end(false, error2);
40847
+ throw error2;
40848
+ });
40849
+ };
40850
+ webStream.pipeThrough = function(transform, options) {
40851
+ if (this.locked || transform.writable.locked || transform.readable.locked)
40852
+ return pipeThrough.call(this, transform, options);
40853
+ const result = webStream.pipeTo.call(this, transform.writable, options);
40854
+ void result.catch(() => {
40855
+ });
40856
+ return transform.readable;
40857
+ };
40858
+ const getReader = value.getReader;
40859
+ value.getReader = function(...args) {
40860
+ const reader = Reflect.apply(getReader, this, args);
40861
+ const read2 = reader.read;
40862
+ reader.read = function(...readArgs) {
40863
+ return Promise.resolve(
40864
+ withCurrent(span, () => Reflect.apply(read2, this, readArgs))
40865
+ ).then(
40866
+ (result) => {
40867
+ if (result.value) safeObserve(result.value);
40868
+ if (result.done) end(true);
40869
+ return result;
40870
+ },
40871
+ (error2) => {
40872
+ end(false, error2);
40873
+ throw error2;
40874
+ }
40875
+ );
40876
+ };
40877
+ const readerCancel = reader.cancel;
40878
+ reader.cancel = function(...cancelArgs) {
40879
+ const result = Reflect.apply(readerCancel, this, cancelArgs);
40880
+ end(false);
40881
+ return result;
40882
+ };
40883
+ return reader;
40884
+ };
40885
+ const streamCancel = value.cancel;
40886
+ if (typeof streamCancel === "function")
40887
+ value.cancel = function(...args) {
40888
+ const result = Reflect.apply(streamCancel, this, args);
40889
+ void Promise.resolve(result).then(
40890
+ () => end(false),
40891
+ () => {
40892
+ }
40893
+ );
40894
+ return result;
40895
+ };
40896
+ }
40897
+ if (typeof value.getReader === "function" && typeof value.values === "function") {
40898
+ const values = value.values;
40899
+ const iterate = function(...args) {
40900
+ const iterator = Reflect.apply(values, this, args);
40901
+ patchStreamIfNeeded(iterator, {
40902
+ shouldCollect(chunk) {
40903
+ safeObserve(chunk);
40904
+ return false;
40905
+ },
40906
+ onComplete: () => end(true),
40907
+ onCancel: () => end(false),
40908
+ onError: (error2) => end(false, error2),
40909
+ aroundNext: (next) => withCurrent(span, next)
40910
+ });
40911
+ return iterator;
40912
+ };
40913
+ value.values = iterate;
40914
+ Object.defineProperty(value, Symbol.asyncIterator, {
40915
+ configurable: true,
40916
+ writable: true,
40917
+ value: iterate
40918
+ });
40919
+ } else if (isAsyncIterable3(value)) {
40920
+ patchStreamIfNeeded(value, {
40921
+ shouldCollect: (chunk) => {
40922
+ safeObserve(chunk);
40923
+ return false;
40924
+ },
40925
+ onComplete: () => end(true),
40926
+ onCancel: () => end(false),
40927
+ onError: (error2) => end(false, error2),
40928
+ aroundNext: (next) => withCurrent(span, next)
40929
+ });
40930
+ } else if (typeof value.getReader !== "function") end(false);
40931
+ }
40932
+
40084
40933
  // src/instrumentation/plugins/voyageai-channels.ts
40085
40934
  var voyageAIChannels = defineChannels(
40086
40935
  "voyageai",
@@ -40148,7 +40997,7 @@ var VoyageAIPlugin = class extends BasePlugin {
40148
40997
  this.unsubscribers = unsubscribeAll(this.unsubscribers);
40149
40998
  }
40150
40999
  };
40151
- function interceptVoyageAICall(channel2, name, extractInput2, extractOutput2, extractMetrics2 = extractUsageMetrics3) {
41000
+ function interceptVoyageAICall(channel2, name, extractInput3, extractOutput2, extractMetrics2 = extractUsageMetrics3) {
40152
41001
  return channel2.intercept((target, thisArg, args) => {
40153
41002
  const invokeTarget = () => Reflect.apply(target, thisArg, args);
40154
41003
  if (isAutoInstrumentationSuppressed()) {
@@ -40156,7 +41005,7 @@ function interceptVoyageAICall(channel2, name, extractInput2, extractOutput2, ex
40156
41005
  }
40157
41006
  let span;
40158
41007
  try {
40159
- const { input, metadata } = extractInput2(args);
41008
+ const { input, metadata } = extractInput3(args);
40160
41009
  span = startSpan(
40161
41010
  withSpanInstrumentationName(
40162
41011
  {
@@ -40932,6 +41781,7 @@ var BraintrustPlugin = class extends BasePlugin {
40932
41781
  cloudflareThinkPlugin = null;
40933
41782
  cursorSDKPlugin = null;
40934
41783
  openAIAgentsPlugin = null;
41784
+ googleGenerativeAIPlugin = null;
40935
41785
  googleGenAIPlugin = null;
40936
41786
  huggingFacePlugin = null;
40937
41787
  huggingFaceTransformersPlugin = null;
@@ -40950,6 +41800,7 @@ var BraintrustPlugin = class extends BasePlugin {
40950
41800
  langSmithPlugin = null;
40951
41801
  piCodingAgentPlugin = null;
40952
41802
  strandsAgentSDKPlugin = null;
41803
+ elevenLabsPlugin = null;
40953
41804
  voyageAIPlugin = null;
40954
41805
  cloudflareAIChatPlugin = null;
40955
41806
  cloudflareAgentsPlugin = null;
@@ -40991,6 +41842,10 @@ var BraintrustPlugin = class extends BasePlugin {
40991
41842
  this.openAIAgentsPlugin = new OpenAIAgentsPlugin();
40992
41843
  this.openAIAgentsPlugin.enable();
40993
41844
  }
41845
+ if (integrations.googleGenerativeAI !== false) {
41846
+ this.googleGenerativeAIPlugin = new GoogleGenerativeAIPlugin();
41847
+ this.googleGenerativeAIPlugin.enable();
41848
+ }
40994
41849
  if (integrations.googleGenAI !== false && integrations.google !== false) {
40995
41850
  this.googleGenAIPlugin = new GoogleGenAIPlugin();
40996
41851
  this.googleGenAIPlugin.enable();
@@ -41025,6 +41880,10 @@ var BraintrustPlugin = class extends BasePlugin {
41025
41880
  this.coherePlugin = new CoherePlugin();
41026
41881
  this.coherePlugin.enable();
41027
41882
  }
41883
+ if (integrations.elevenlabs !== false) {
41884
+ this.elevenLabsPlugin = new ElevenLabsPlugin();
41885
+ this.elevenLabsPlugin.enable();
41886
+ }
41028
41887
  if (integrations.voyageai !== false) {
41029
41888
  this.voyageAIPlugin = new VoyageAIPlugin();
41030
41889
  this.voyageAIPlugin.enable();
@@ -41109,6 +41968,10 @@ var BraintrustPlugin = class extends BasePlugin {
41109
41968
  this.openAIAgentsPlugin.disable();
41110
41969
  this.openAIAgentsPlugin = null;
41111
41970
  }
41971
+ if (this.googleGenerativeAIPlugin) {
41972
+ this.googleGenerativeAIPlugin.disable();
41973
+ this.googleGenerativeAIPlugin = null;
41974
+ }
41112
41975
  if (this.googleGenAIPlugin) {
41113
41976
  this.googleGenAIPlugin.disable();
41114
41977
  this.googleGenAIPlugin = null;
@@ -41145,6 +42008,10 @@ var BraintrustPlugin = class extends BasePlugin {
41145
42008
  this.coherePlugin.disable();
41146
42009
  this.coherePlugin = null;
41147
42010
  }
42011
+ if (this.elevenLabsPlugin) {
42012
+ this.elevenLabsPlugin.disable();
42013
+ this.elevenLabsPlugin = null;
42014
+ }
41148
42015
  if (this.voyageAIPlugin) {
41149
42016
  this.voyageAIPlugin.disable();
41150
42017
  this.voyageAIPlugin = null;
@@ -41238,6 +42105,8 @@ var envIntegrationAliases = {
41238
42105
  "openai-agents-core": "openAIAgents",
41239
42106
  openaiagentscore: "openAIAgents",
41240
42107
  google: "google",
42108
+ "google-generative-ai": "googleGenerativeAI",
42109
+ googlegenerativeai: "googleGenerativeAI",
41241
42110
  "google-genai": "googleGenAI",
41242
42111
  googlegenai: "googleGenAI",
41243
42112
  huggingface: "huggingface",
@@ -41271,7 +42140,9 @@ var envIntegrationAliases = {
41271
42140
  langsmith: "langsmith",
41272
42141
  voyage: "voyageai",
41273
42142
  "voyage-ai": "voyageai",
41274
- voyageai: "voyageai"
42143
+ voyageai: "voyageai",
42144
+ elevenlabs: "elevenlabs",
42145
+ "@elevenlabs/elevenlabs-js": "elevenlabs"
41275
42146
  };
41276
42147
  function getDefaultInstrumentationIntegrations() {
41277
42148
  return {
@@ -41282,6 +42153,7 @@ function getDefaultInstrumentationIntegrations() {
41282
42153
  aisdk: true,
41283
42154
  google: true,
41284
42155
  googleGenAI: true,
42156
+ googleGenerativeAI: true,
41285
42157
  googleADK: true,
41286
42158
  huggingface: true,
41287
42159
  claudeAgentSDK: true,
@@ -41307,6 +42179,7 @@ function getDefaultInstrumentationIntegrations() {
41307
42179
  langgraph: true,
41308
42180
  langsmith: true,
41309
42181
  voyageai: true,
42182
+ elevenlabs: true,
41310
42183
  piCodingAgent: true,
41311
42184
  strandsAgentSDK: true,
41312
42185
  cloudflareAgents: true
@@ -43513,6 +44386,26 @@ var googleADKConfigs = [
43513
44386
  }
43514
44387
  ];
43515
44388
 
44389
+ // src/auto-instrumentations/configs/google-generative-ai.ts
44390
+ var googleGenerativeAIConfigs = [
44391
+ "dist/index.js",
44392
+ "dist/index.mjs"
44393
+ ].flatMap(
44394
+ (filePath) => Object.entries(googleGenerativeAIChannels).map(([methodName, channel2]) => ({
44395
+ channelName: channel2.channelName,
44396
+ module: {
44397
+ name: "@google/generative-ai",
44398
+ versionRange: ">=0.24.0 <0.25.0",
44399
+ filePath
44400
+ },
44401
+ functionQuery: {
44402
+ className: methodName.startsWith("sendMessage") ? "ChatSession" : "GenerativeModel",
44403
+ methodName,
44404
+ kind: "Async"
44405
+ }
44406
+ }))
44407
+ );
44408
+
43516
44409
  // src/auto-instrumentations/configs/google-genai.ts
43517
44410
  var googleGenAIConfigs = [
43518
44411
  // Models.generateContentInternal - The actual class method (Node.js entry point)
@@ -44701,6 +45594,41 @@ var strandsAgentSDKConfigs = [
44701
45594
  }
44702
45595
  ];
44703
45596
 
45597
+ // src/auto-instrumentations/configs/elevenlabs.ts
45598
+ var elevenLabsConfigs = [
45599
+ ...[
45600
+ "convert",
45601
+ "stream",
45602
+ "convertWithTimestamps",
45603
+ "streamWithTimestamps"
45604
+ ].map((methodName) => ({
45605
+ channelName: elevenLabsChannels[methodName].channelName,
45606
+ module: {
45607
+ name: "@elevenlabs/elevenlabs-js",
45608
+ versionRange: ">=2.67.0 <3.0.0",
45609
+ filePath: "api/resources/textToSpeech/client/Client.js"
45610
+ },
45611
+ functionQuery: {
45612
+ className: "TextToSpeechClient",
45613
+ methodName,
45614
+ kind: "Async"
45615
+ }
45616
+ })),
45617
+ {
45618
+ channelName: elevenLabsChannels.transcribe.channelName,
45619
+ module: {
45620
+ name: "@elevenlabs/elevenlabs-js",
45621
+ versionRange: ">=2.67.0 <3.0.0",
45622
+ filePath: "api/resources/speechToText/client/Client.js"
45623
+ },
45624
+ functionQuery: {
45625
+ className: "SpeechToTextClient",
45626
+ methodName: "convert",
45627
+ kind: "Async"
45628
+ }
45629
+ }
45630
+ ];
45631
+
44704
45632
  // src/auto-instrumentations/configs/voyageai.ts
44705
45633
  var GENERATED_CLIENT_MODULES = [
44706
45634
  "dist/cjs/Client.js",
@@ -44785,6 +45713,10 @@ var defaultInstrumentationConfigGroups = [
44785
45713
  integrations: ["openAIAgents"],
44786
45714
  configs: openAIAgentsCoreConfigs
44787
45715
  },
45716
+ {
45717
+ integrations: ["googleGenerativeAI"],
45718
+ configs: googleGenerativeAIConfigs
45719
+ },
44788
45720
  {
44789
45721
  integrations: ["google", "googleGenAI"],
44790
45722
  configs: googleGenAIConfigs
@@ -44828,6 +45760,10 @@ var defaultInstrumentationConfigGroups = [
44828
45760
  integrations: ["flue"],
44829
45761
  configs: flueConfigs
44830
45762
  },
45763
+ {
45764
+ integrations: ["elevenlabs"],
45765
+ configs: elevenLabsConfigs
45766
+ },
44831
45767
  {
44832
45768
  integrations: ["voyageai"],
44833
45769
  configs: voyageAIConfigs