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.
- package/dev/dist/index.d.mts +736 -0
- package/dev/dist/index.d.ts +736 -0
- package/dev/dist/index.js +1280 -428
- package/dev/dist/index.mjs +859 -7
- package/dist/apply-auto-instrumentation.js +281 -216
- package/dist/apply-auto-instrumentation.mjs +66 -1
- package/dist/auto-instrumentations/bundler/esbuild.cjs +104 -2
- package/dist/auto-instrumentations/bundler/esbuild.mjs +2 -2
- package/dist/auto-instrumentations/bundler/next.cjs +104 -2
- package/dist/auto-instrumentations/bundler/next.mjs +3 -3
- package/dist/auto-instrumentations/bundler/rollup.cjs +104 -2
- package/dist/auto-instrumentations/bundler/rollup.mjs +2 -2
- package/dist/auto-instrumentations/bundler/vite.cjs +104 -2
- package/dist/auto-instrumentations/bundler/vite.mjs +2 -2
- package/dist/auto-instrumentations/bundler/webpack-loader.cjs +104 -2
- package/dist/auto-instrumentations/bundler/webpack.cjs +104 -2
- package/dist/auto-instrumentations/bundler/webpack.mjs +3 -3
- package/dist/auto-instrumentations/{chunk-U64OYU4Q.mjs → chunk-AFND2U7E.mjs} +38 -1
- package/dist/auto-instrumentations/{chunk-OXINGIEZ.mjs → chunk-QEEPRBIS.mjs} +1 -1
- package/dist/auto-instrumentations/{chunk-LW4HDHXT.mjs → chunk-RI4Y55ZF.mjs} +69 -2
- package/dist/auto-instrumentations/hook.mjs +124 -3
- package/dist/auto-instrumentations/index.cjs +39 -1
- package/dist/auto-instrumentations/index.d.mts +3 -1
- package/dist/auto-instrumentations/index.d.ts +3 -1
- package/dist/auto-instrumentations/index.mjs +3 -1
- package/dist/browser.d.mts +2124 -2
- package/dist/browser.d.ts +2124 -2
- package/dist/browser.js +994 -10
- package/dist/browser.mjs +994 -10
- package/dist/{chunk-AJT4FR25.mjs → chunk-4QSAHP7D.mjs} +818 -5
- package/dist/{chunk-4AQGZS6X.js → chunk-AW4QECG5.js} +47 -4
- package/dist/{chunk-V32LW47Z.js → chunk-BTRLPQG5.js} +1663 -850
- package/dist/{chunk-CE3BLB2L.mjs → chunk-WV6QZI2W.mjs} +46 -3
- package/dist/cli.js +923 -8
- package/dist/edge-light.d.mts +1 -1
- package/dist/edge-light.d.ts +1 -1
- package/dist/edge-light.js +994 -10
- package/dist/edge-light.mjs +994 -10
- package/dist/index.d.mts +2124 -2
- package/dist/index.d.ts +2124 -2
- package/dist/index.js +581 -447
- package/dist/index.mjs +136 -2
- package/dist/instrumentation/index.d.mts +434 -0
- package/dist/instrumentation/index.d.ts +434 -0
- package/dist/instrumentation/index.js +859 -7
- package/dist/instrumentation/index.mjs +859 -7
- package/dist/vitest-evals-reporter.js +16 -16
- package/dist/vitest-evals-reporter.mjs +2 -2
- package/dist/workerd.d.mts +1 -1
- package/dist/workerd.d.ts +1 -1
- package/dist/workerd.js +994 -10
- package/dist/workerd.mjs +994 -10
- package/package.json +1 -1
- package/util/dist/index.d.mts +326 -0
- 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.
|
|
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({
|
|
@@ -7190,6 +7199,7 @@ var INSTRUMENTATION_NAMES = {
|
|
|
7190
7199
|
GENKIT: "genkit",
|
|
7191
7200
|
GITHUB_COPILOT: "github-copilot",
|
|
7192
7201
|
GOOGLE_ADK: "google-adk",
|
|
7202
|
+
GOOGLE_GENERATIVE_AI: "google-generative-ai",
|
|
7193
7203
|
GOOGLE_GENAI: "google-genai",
|
|
7194
7204
|
GROQ: "groq",
|
|
7195
7205
|
HUGGINGFACE: "huggingface",
|
|
@@ -7205,12 +7215,13 @@ var INSTRUMENTATION_NAMES = {
|
|
|
7205
7215
|
OPENROUTER_AGENT: "openrouter-agent",
|
|
7206
7216
|
PI_CODING_AGENT: "pi-coding-agent",
|
|
7207
7217
|
STRANDS_AGENT_SDK: "strands-agent-sdk",
|
|
7208
|
-
VOYAGEAI: "voyageai"
|
|
7218
|
+
VOYAGEAI: "voyageai",
|
|
7219
|
+
ELEVENLABS: "elevenlabs"
|
|
7209
7220
|
};
|
|
7210
7221
|
var INTERNAL_SPAN_INSTRUMENTATION_NAME = /* @__PURE__ */ Symbol.for(
|
|
7211
7222
|
"braintrust.spanInstrumentationName"
|
|
7212
7223
|
);
|
|
7213
|
-
var SDK_VERSION = true ? "3.
|
|
7224
|
+
var SDK_VERSION = true ? "3.32.0" : "0.0.0";
|
|
7214
7225
|
function withSpanInstrumentationName(args, instrumentationName) {
|
|
7215
7226
|
return {
|
|
7216
7227
|
...args,
|
|
@@ -12384,6 +12395,16 @@ function renderMessageImpl(render, message, variables) {
|
|
|
12384
12395
|
}
|
|
12385
12396
|
}
|
|
12386
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
|
+
];
|
|
12387
12408
|
case "file":
|
|
12388
12409
|
return [
|
|
12389
12410
|
{
|
|
@@ -28015,6 +28036,342 @@ var OpenAIAgentsPlugin = class extends BasePlugin {
|
|
|
28015
28036
|
}
|
|
28016
28037
|
};
|
|
28017
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
|
+
|
|
28018
28375
|
// src/instrumentation/plugins/google-genai-channels.ts
|
|
28019
28376
|
var googleGenAIChannels = defineChannels(
|
|
28020
28377
|
"@google/genai",
|
|
@@ -29658,7 +30015,7 @@ var HuggingFaceTransformersPlugin = class extends BasePlugin {
|
|
|
29658
30015
|
getTask(event)
|
|
29659
30016
|
),
|
|
29660
30017
|
extractInput: (args, event) => ({
|
|
29661
|
-
input:
|
|
30018
|
+
input: extractInput2(
|
|
29662
30019
|
getTask(event),
|
|
29663
30020
|
args
|
|
29664
30021
|
),
|
|
@@ -29748,7 +30105,7 @@ function modelIdentifier(pipeline) {
|
|
|
29748
30105
|
}
|
|
29749
30106
|
return void 0;
|
|
29750
30107
|
}
|
|
29751
|
-
function
|
|
30108
|
+
function extractInput2(task, args) {
|
|
29752
30109
|
switch (task) {
|
|
29753
30110
|
case "feature-extraction":
|
|
29754
30111
|
return args[0];
|
|
@@ -40102,6 +40459,477 @@ function logInstrumentationError5(context2, error2) {
|
|
|
40102
40459
|
debugLogger.debug(`${context2}:`, error2);
|
|
40103
40460
|
}
|
|
40104
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
|
+
|
|
40105
40933
|
// src/instrumentation/plugins/voyageai-channels.ts
|
|
40106
40934
|
var voyageAIChannels = defineChannels(
|
|
40107
40935
|
"voyageai",
|
|
@@ -40169,7 +40997,7 @@ var VoyageAIPlugin = class extends BasePlugin {
|
|
|
40169
40997
|
this.unsubscribers = unsubscribeAll(this.unsubscribers);
|
|
40170
40998
|
}
|
|
40171
40999
|
};
|
|
40172
|
-
function interceptVoyageAICall(channel2, name,
|
|
41000
|
+
function interceptVoyageAICall(channel2, name, extractInput3, extractOutput2, extractMetrics2 = extractUsageMetrics3) {
|
|
40173
41001
|
return channel2.intercept((target, thisArg, args) => {
|
|
40174
41002
|
const invokeTarget = () => Reflect.apply(target, thisArg, args);
|
|
40175
41003
|
if (isAutoInstrumentationSuppressed()) {
|
|
@@ -40177,7 +41005,7 @@ function interceptVoyageAICall(channel2, name, extractInput2, extractOutput2, ex
|
|
|
40177
41005
|
}
|
|
40178
41006
|
let span;
|
|
40179
41007
|
try {
|
|
40180
|
-
const { input, metadata } =
|
|
41008
|
+
const { input, metadata } = extractInput3(args);
|
|
40181
41009
|
span = startSpan(
|
|
40182
41010
|
withSpanInstrumentationName(
|
|
40183
41011
|
{
|
|
@@ -40953,6 +41781,7 @@ var BraintrustPlugin = class extends BasePlugin {
|
|
|
40953
41781
|
cloudflareThinkPlugin = null;
|
|
40954
41782
|
cursorSDKPlugin = null;
|
|
40955
41783
|
openAIAgentsPlugin = null;
|
|
41784
|
+
googleGenerativeAIPlugin = null;
|
|
40956
41785
|
googleGenAIPlugin = null;
|
|
40957
41786
|
huggingFacePlugin = null;
|
|
40958
41787
|
huggingFaceTransformersPlugin = null;
|
|
@@ -40971,6 +41800,7 @@ var BraintrustPlugin = class extends BasePlugin {
|
|
|
40971
41800
|
langSmithPlugin = null;
|
|
40972
41801
|
piCodingAgentPlugin = null;
|
|
40973
41802
|
strandsAgentSDKPlugin = null;
|
|
41803
|
+
elevenLabsPlugin = null;
|
|
40974
41804
|
voyageAIPlugin = null;
|
|
40975
41805
|
cloudflareAIChatPlugin = null;
|
|
40976
41806
|
cloudflareAgentsPlugin = null;
|
|
@@ -41012,6 +41842,10 @@ var BraintrustPlugin = class extends BasePlugin {
|
|
|
41012
41842
|
this.openAIAgentsPlugin = new OpenAIAgentsPlugin();
|
|
41013
41843
|
this.openAIAgentsPlugin.enable();
|
|
41014
41844
|
}
|
|
41845
|
+
if (integrations.googleGenerativeAI !== false) {
|
|
41846
|
+
this.googleGenerativeAIPlugin = new GoogleGenerativeAIPlugin();
|
|
41847
|
+
this.googleGenerativeAIPlugin.enable();
|
|
41848
|
+
}
|
|
41015
41849
|
if (integrations.googleGenAI !== false && integrations.google !== false) {
|
|
41016
41850
|
this.googleGenAIPlugin = new GoogleGenAIPlugin();
|
|
41017
41851
|
this.googleGenAIPlugin.enable();
|
|
@@ -41046,6 +41880,10 @@ var BraintrustPlugin = class extends BasePlugin {
|
|
|
41046
41880
|
this.coherePlugin = new CoherePlugin();
|
|
41047
41881
|
this.coherePlugin.enable();
|
|
41048
41882
|
}
|
|
41883
|
+
if (integrations.elevenlabs !== false) {
|
|
41884
|
+
this.elevenLabsPlugin = new ElevenLabsPlugin();
|
|
41885
|
+
this.elevenLabsPlugin.enable();
|
|
41886
|
+
}
|
|
41049
41887
|
if (integrations.voyageai !== false) {
|
|
41050
41888
|
this.voyageAIPlugin = new VoyageAIPlugin();
|
|
41051
41889
|
this.voyageAIPlugin.enable();
|
|
@@ -41130,6 +41968,10 @@ var BraintrustPlugin = class extends BasePlugin {
|
|
|
41130
41968
|
this.openAIAgentsPlugin.disable();
|
|
41131
41969
|
this.openAIAgentsPlugin = null;
|
|
41132
41970
|
}
|
|
41971
|
+
if (this.googleGenerativeAIPlugin) {
|
|
41972
|
+
this.googleGenerativeAIPlugin.disable();
|
|
41973
|
+
this.googleGenerativeAIPlugin = null;
|
|
41974
|
+
}
|
|
41133
41975
|
if (this.googleGenAIPlugin) {
|
|
41134
41976
|
this.googleGenAIPlugin.disable();
|
|
41135
41977
|
this.googleGenAIPlugin = null;
|
|
@@ -41166,6 +42008,10 @@ var BraintrustPlugin = class extends BasePlugin {
|
|
|
41166
42008
|
this.coherePlugin.disable();
|
|
41167
42009
|
this.coherePlugin = null;
|
|
41168
42010
|
}
|
|
42011
|
+
if (this.elevenLabsPlugin) {
|
|
42012
|
+
this.elevenLabsPlugin.disable();
|
|
42013
|
+
this.elevenLabsPlugin = null;
|
|
42014
|
+
}
|
|
41169
42015
|
if (this.voyageAIPlugin) {
|
|
41170
42016
|
this.voyageAIPlugin.disable();
|
|
41171
42017
|
this.voyageAIPlugin = null;
|
|
@@ -41259,6 +42105,8 @@ var envIntegrationAliases = {
|
|
|
41259
42105
|
"openai-agents-core": "openAIAgents",
|
|
41260
42106
|
openaiagentscore: "openAIAgents",
|
|
41261
42107
|
google: "google",
|
|
42108
|
+
"google-generative-ai": "googleGenerativeAI",
|
|
42109
|
+
googlegenerativeai: "googleGenerativeAI",
|
|
41262
42110
|
"google-genai": "googleGenAI",
|
|
41263
42111
|
googlegenai: "googleGenAI",
|
|
41264
42112
|
huggingface: "huggingface",
|
|
@@ -41292,7 +42140,9 @@ var envIntegrationAliases = {
|
|
|
41292
42140
|
langsmith: "langsmith",
|
|
41293
42141
|
voyage: "voyageai",
|
|
41294
42142
|
"voyage-ai": "voyageai",
|
|
41295
|
-
voyageai: "voyageai"
|
|
42143
|
+
voyageai: "voyageai",
|
|
42144
|
+
elevenlabs: "elevenlabs",
|
|
42145
|
+
"@elevenlabs/elevenlabs-js": "elevenlabs"
|
|
41296
42146
|
};
|
|
41297
42147
|
function getDefaultInstrumentationIntegrations() {
|
|
41298
42148
|
return {
|
|
@@ -41303,6 +42153,7 @@ function getDefaultInstrumentationIntegrations() {
|
|
|
41303
42153
|
aisdk: true,
|
|
41304
42154
|
google: true,
|
|
41305
42155
|
googleGenAI: true,
|
|
42156
|
+
googleGenerativeAI: true,
|
|
41306
42157
|
googleADK: true,
|
|
41307
42158
|
huggingface: true,
|
|
41308
42159
|
claudeAgentSDK: true,
|
|
@@ -41328,6 +42179,7 @@ function getDefaultInstrumentationIntegrations() {
|
|
|
41328
42179
|
langgraph: true,
|
|
41329
42180
|
langsmith: true,
|
|
41330
42181
|
voyageai: true,
|
|
42182
|
+
elevenlabs: true,
|
|
41331
42183
|
piCodingAgent: true,
|
|
41332
42184
|
strandsAgentSDK: true,
|
|
41333
42185
|
cloudflareAgents: true
|
|
@@ -43534,6 +44386,26 @@ var googleADKConfigs = [
|
|
|
43534
44386
|
}
|
|
43535
44387
|
];
|
|
43536
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
|
+
|
|
43537
44409
|
// src/auto-instrumentations/configs/google-genai.ts
|
|
43538
44410
|
var googleGenAIConfigs = [
|
|
43539
44411
|
// Models.generateContentInternal - The actual class method (Node.js entry point)
|
|
@@ -44722,6 +45594,41 @@ var strandsAgentSDKConfigs = [
|
|
|
44722
45594
|
}
|
|
44723
45595
|
];
|
|
44724
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
|
+
|
|
44725
45632
|
// src/auto-instrumentations/configs/voyageai.ts
|
|
44726
45633
|
var GENERATED_CLIENT_MODULES = [
|
|
44727
45634
|
"dist/cjs/Client.js",
|
|
@@ -44806,6 +45713,10 @@ var defaultInstrumentationConfigGroups = [
|
|
|
44806
45713
|
integrations: ["openAIAgents"],
|
|
44807
45714
|
configs: openAIAgentsCoreConfigs
|
|
44808
45715
|
},
|
|
45716
|
+
{
|
|
45717
|
+
integrations: ["googleGenerativeAI"],
|
|
45718
|
+
configs: googleGenerativeAIConfigs
|
|
45719
|
+
},
|
|
44809
45720
|
{
|
|
44810
45721
|
integrations: ["google", "googleGenAI"],
|
|
44811
45722
|
configs: googleGenAIConfigs
|
|
@@ -44849,6 +45760,10 @@ var defaultInstrumentationConfigGroups = [
|
|
|
44849
45760
|
integrations: ["flue"],
|
|
44850
45761
|
configs: flueConfigs
|
|
44851
45762
|
},
|
|
45763
|
+
{
|
|
45764
|
+
integrations: ["elevenlabs"],
|
|
45765
|
+
configs: elevenLabsConfigs
|
|
45766
|
+
},
|
|
44852
45767
|
{
|
|
44853
45768
|
integrations: ["voyageai"],
|
|
44854
45769
|
configs: voyageAIConfigs
|