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
|
@@ -2960,6 +2960,14 @@ var ChatCompletionContentPartImageWithTitle = import_v36.z.object({
|
|
|
2960
2960
|
ttl: import_v36.z.enum(["5m", "1h"]).optional()
|
|
2961
2961
|
}).optional()
|
|
2962
2962
|
});
|
|
2963
|
+
var ChatCompletionContentPartInputAudioWithTitle = import_v36.z.object({
|
|
2964
|
+
input_audio: import_v36.z.object({ data: import_v36.z.string(), format: import_v36.z.enum(["wav", "mp3"]) }),
|
|
2965
|
+
type: import_v36.z.literal("input_audio"),
|
|
2966
|
+
cache_control: import_v36.z.object({
|
|
2967
|
+
type: import_v36.z.literal("ephemeral"),
|
|
2968
|
+
ttl: import_v36.z.enum(["5m", "1h"]).optional()
|
|
2969
|
+
}).optional()
|
|
2970
|
+
});
|
|
2963
2971
|
var ChatCompletionContentPartFileFile = import_v36.z.object({ file_data: import_v36.z.string(), filename: import_v36.z.string(), file_id: import_v36.z.string() }).partial();
|
|
2964
2972
|
var ChatCompletionContentPartFileWithTitle = import_v36.z.object({
|
|
2965
2973
|
file: ChatCompletionContentPartFileFile,
|
|
@@ -2972,6 +2980,7 @@ var ChatCompletionContentPartFileWithTitle = import_v36.z.object({
|
|
|
2972
2980
|
var ChatCompletionContentPart = import_v36.z.union([
|
|
2973
2981
|
ChatCompletionContentPartTextWithTitle,
|
|
2974
2982
|
ChatCompletionContentPartImageWithTitle,
|
|
2983
|
+
ChatCompletionContentPartInputAudioWithTitle,
|
|
2975
2984
|
ChatCompletionContentPartFileWithTitle
|
|
2976
2985
|
]);
|
|
2977
2986
|
var ChatCompletionContentPartText = import_v36.z.object({
|
|
@@ -5797,6 +5806,7 @@ var INSTRUMENTATION_NAMES = {
|
|
|
5797
5806
|
GENKIT: "genkit",
|
|
5798
5807
|
GITHUB_COPILOT: "github-copilot",
|
|
5799
5808
|
GOOGLE_ADK: "google-adk",
|
|
5809
|
+
GOOGLE_GENERATIVE_AI: "google-generative-ai",
|
|
5800
5810
|
GOOGLE_GENAI: "google-genai",
|
|
5801
5811
|
GROQ: "groq",
|
|
5802
5812
|
HUGGINGFACE: "huggingface",
|
|
@@ -5812,12 +5822,13 @@ var INSTRUMENTATION_NAMES = {
|
|
|
5812
5822
|
OPENROUTER_AGENT: "openrouter-agent",
|
|
5813
5823
|
PI_CODING_AGENT: "pi-coding-agent",
|
|
5814
5824
|
STRANDS_AGENT_SDK: "strands-agent-sdk",
|
|
5815
|
-
VOYAGEAI: "voyageai"
|
|
5825
|
+
VOYAGEAI: "voyageai",
|
|
5826
|
+
ELEVENLABS: "elevenlabs"
|
|
5816
5827
|
};
|
|
5817
5828
|
var INTERNAL_SPAN_INSTRUMENTATION_NAME = /* @__PURE__ */ Symbol.for(
|
|
5818
5829
|
"braintrust.spanInstrumentationName"
|
|
5819
5830
|
);
|
|
5820
|
-
var SDK_VERSION = true ? "3.
|
|
5831
|
+
var SDK_VERSION = true ? "3.32.0" : "0.0.0";
|
|
5821
5832
|
function withSpanInstrumentationName(args, instrumentationName) {
|
|
5822
5833
|
return {
|
|
5823
5834
|
...args,
|
|
@@ -10395,6 +10406,16 @@ function renderMessageImpl(render, message, variables) {
|
|
|
10395
10406
|
}
|
|
10396
10407
|
}
|
|
10397
10408
|
];
|
|
10409
|
+
case "input_audio":
|
|
10410
|
+
return [
|
|
10411
|
+
{
|
|
10412
|
+
...c,
|
|
10413
|
+
input_audio: {
|
|
10414
|
+
...c.input_audio,
|
|
10415
|
+
data: render(c.input_audio.data)
|
|
10416
|
+
}
|
|
10417
|
+
}
|
|
10418
|
+
];
|
|
10398
10419
|
case "file":
|
|
10399
10420
|
return [
|
|
10400
10421
|
{
|
|
@@ -22663,6 +22684,342 @@ var OpenAIAgentsPlugin = class extends BasePlugin {
|
|
|
22663
22684
|
}
|
|
22664
22685
|
};
|
|
22665
22686
|
|
|
22687
|
+
// src/instrumentation/plugins/google-generative-ai-channels.ts
|
|
22688
|
+
var googleGenerativeAIChannels = defineChannels(
|
|
22689
|
+
"@google/generative-ai",
|
|
22690
|
+
{
|
|
22691
|
+
generateContent: channel({ channelName: "GenerativeModel.generateContent", kind: "async" }),
|
|
22692
|
+
generateContentStream: channel({ channelName: "GenerativeModel.generateContentStream", kind: "async" }),
|
|
22693
|
+
embedContent: channel({ channelName: "GenerativeModel.embedContent", kind: "async" }),
|
|
22694
|
+
batchEmbedContents: channel({ channelName: "GenerativeModel.batchEmbedContents", kind: "async" }),
|
|
22695
|
+
sendMessage: channel({ channelName: "ChatSession.sendMessage", kind: "async" }),
|
|
22696
|
+
sendMessageStream: channel({ channelName: "ChatSession.sendMessageStream", kind: "async" })
|
|
22697
|
+
},
|
|
22698
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.GOOGLE_GENERATIVE_AI }
|
|
22699
|
+
);
|
|
22700
|
+
|
|
22701
|
+
// src/instrumentation/plugins/google-generative-ai-plugin.ts
|
|
22702
|
+
var GENERATION_CONFIG_KEYS = [
|
|
22703
|
+
"temperature",
|
|
22704
|
+
"topP",
|
|
22705
|
+
"topK",
|
|
22706
|
+
"candidateCount",
|
|
22707
|
+
"maxOutputTokens",
|
|
22708
|
+
"stopSequences",
|
|
22709
|
+
"responseMimeType",
|
|
22710
|
+
"responseSchema",
|
|
22711
|
+
"presencePenalty",
|
|
22712
|
+
"frequencyPenalty",
|
|
22713
|
+
"responseLogprobs",
|
|
22714
|
+
"logprobs",
|
|
22715
|
+
"thinkingConfig"
|
|
22716
|
+
];
|
|
22717
|
+
var GoogleGenerativeAIPlugin = class extends BasePlugin {
|
|
22718
|
+
onEnable() {
|
|
22719
|
+
this.unsubscribers.push(
|
|
22720
|
+
interceptCall(
|
|
22721
|
+
googleGenerativeAIChannels.generateContent,
|
|
22722
|
+
"generateContent"
|
|
22723
|
+
),
|
|
22724
|
+
interceptCall(
|
|
22725
|
+
googleGenerativeAIChannels.generateContentStream,
|
|
22726
|
+
"generateContentStream"
|
|
22727
|
+
),
|
|
22728
|
+
interceptCall(googleGenerativeAIChannels.sendMessage, "sendMessage"),
|
|
22729
|
+
interceptCall(
|
|
22730
|
+
googleGenerativeAIChannels.sendMessageStream,
|
|
22731
|
+
"sendMessageStream"
|
|
22732
|
+
),
|
|
22733
|
+
interceptCall(googleGenerativeAIChannels.embedContent, "embedContent"),
|
|
22734
|
+
interceptCall(
|
|
22735
|
+
googleGenerativeAIChannels.batchEmbedContents,
|
|
22736
|
+
"batchEmbedContents"
|
|
22737
|
+
)
|
|
22738
|
+
);
|
|
22739
|
+
}
|
|
22740
|
+
onDisable() {
|
|
22741
|
+
this.unsubscribers = unsubscribeAll(this.unsubscribers);
|
|
22742
|
+
}
|
|
22743
|
+
};
|
|
22744
|
+
function interceptCall(channel2, operation) {
|
|
22745
|
+
return channel2.intercept((target, thisArg, args) => {
|
|
22746
|
+
const invokeTarget = () => Reflect.apply(target, thisArg, args);
|
|
22747
|
+
if (isAutoInstrumentationSuppressed()) return invokeTarget();
|
|
22748
|
+
const self = thisArg;
|
|
22749
|
+
const chat = operation.startsWith("sendMessage");
|
|
22750
|
+
const embedding = operation === "embedContent" || operation === "batchEmbedContents";
|
|
22751
|
+
const start = getCurrentUnixTimestamp();
|
|
22752
|
+
let span;
|
|
22753
|
+
try {
|
|
22754
|
+
span = startSpan(
|
|
22755
|
+
withSpanInstrumentationName(
|
|
22756
|
+
{
|
|
22757
|
+
name: embedding ? operation === "embedContent" ? "embed_content" : "batch_embed_contents" : "generate_content",
|
|
22758
|
+
spanAttributes: { type: "llm" /* LLM */ },
|
|
22759
|
+
event: extractInput(self, args[0], operation)
|
|
22760
|
+
},
|
|
22761
|
+
INSTRUMENTATION_NAMES.GOOGLE_GENERATIVE_AI
|
|
22762
|
+
)
|
|
22763
|
+
);
|
|
22764
|
+
} catch (error) {
|
|
22765
|
+
debugLogger.error("Error starting Google Generative AI span:", error);
|
|
22766
|
+
return invokeTarget();
|
|
22767
|
+
}
|
|
22768
|
+
let ended = false;
|
|
22769
|
+
const finish = (log) => {
|
|
22770
|
+
if (ended) return;
|
|
22771
|
+
ended = true;
|
|
22772
|
+
try {
|
|
22773
|
+
log();
|
|
22774
|
+
} catch (error) {
|
|
22775
|
+
debugLogger.error("Error logging Google Generative AI span:", error);
|
|
22776
|
+
}
|
|
22777
|
+
try {
|
|
22778
|
+
span.end();
|
|
22779
|
+
} catch (error) {
|
|
22780
|
+
debugLogger.error("Error ending Google Generative AI span:", error);
|
|
22781
|
+
}
|
|
22782
|
+
};
|
|
22783
|
+
if (chat) {
|
|
22784
|
+
try {
|
|
22785
|
+
void self._sendPromise.then(
|
|
22786
|
+
() => {
|
|
22787
|
+
try {
|
|
22788
|
+
span.log(extractInput(self, args[0], operation));
|
|
22789
|
+
} catch (error) {
|
|
22790
|
+
debugLogger.error("Error capturing Google chat history:", error);
|
|
22791
|
+
}
|
|
22792
|
+
},
|
|
22793
|
+
() => {
|
|
22794
|
+
}
|
|
22795
|
+
);
|
|
22796
|
+
} catch (error) {
|
|
22797
|
+
debugLogger.error("Error observing Google chat history:", error);
|
|
22798
|
+
}
|
|
22799
|
+
}
|
|
22800
|
+
let result;
|
|
22801
|
+
try {
|
|
22802
|
+
result = withCurrent(
|
|
22803
|
+
span,
|
|
22804
|
+
() => runWithAutoInstrumentationSuppressed(invokeTarget)
|
|
22805
|
+
);
|
|
22806
|
+
} catch (error) {
|
|
22807
|
+
finish(() => span.log({ error }));
|
|
22808
|
+
throw error;
|
|
22809
|
+
}
|
|
22810
|
+
void Promise.resolve(result).then(
|
|
22811
|
+
(value) => {
|
|
22812
|
+
try {
|
|
22813
|
+
if ("stream" in value) {
|
|
22814
|
+
let firstToken = false;
|
|
22815
|
+
const partial = { candidates: [] };
|
|
22816
|
+
const candidates = /* @__PURE__ */ new Map();
|
|
22817
|
+
patchStreamIfNeeded(value.stream, {
|
|
22818
|
+
aroundNext: (callback) => withCurrent(span, callback),
|
|
22819
|
+
onChunk: (chunk) => {
|
|
22820
|
+
for (const candidate of chunk.candidates ?? []) {
|
|
22821
|
+
const index = candidate.index ?? 0;
|
|
22822
|
+
const previous = candidates.get(index);
|
|
22823
|
+
const parts = [...previous?.content?.parts ?? []];
|
|
22824
|
+
for (const part of candidate.content?.parts ?? []) {
|
|
22825
|
+
const last = parts[parts.length - 1];
|
|
22826
|
+
if (part.text !== void 0 && last?.text !== void 0) {
|
|
22827
|
+
parts[parts.length - 1] = {
|
|
22828
|
+
...last,
|
|
22829
|
+
text: last.text + part.text
|
|
22830
|
+
};
|
|
22831
|
+
} else parts.push(part);
|
|
22832
|
+
}
|
|
22833
|
+
candidates.set(index, {
|
|
22834
|
+
...previous,
|
|
22835
|
+
...candidate,
|
|
22836
|
+
content: {
|
|
22837
|
+
role: candidate.content?.role ?? previous?.content?.role ?? "model",
|
|
22838
|
+
parts
|
|
22839
|
+
}
|
|
22840
|
+
});
|
|
22841
|
+
}
|
|
22842
|
+
partial.candidates = Array.from(candidates.values());
|
|
22843
|
+
if (chunk.usageMetadata)
|
|
22844
|
+
partial.usageMetadata = chunk.usageMetadata;
|
|
22845
|
+
if (!firstToken && chunk.candidates?.some(
|
|
22846
|
+
(candidate) => candidate.content?.parts.some(
|
|
22847
|
+
(part) => part.text !== void 0 ? part.text.length > 0 : Object.keys(part).length > 0
|
|
22848
|
+
)
|
|
22849
|
+
)) {
|
|
22850
|
+
firstToken = true;
|
|
22851
|
+
span.log({
|
|
22852
|
+
metrics: {
|
|
22853
|
+
time_to_first_token: getCurrentUnixTimestamp() - start
|
|
22854
|
+
}
|
|
22855
|
+
});
|
|
22856
|
+
}
|
|
22857
|
+
},
|
|
22858
|
+
onComplete: () => {
|
|
22859
|
+
},
|
|
22860
|
+
onError: (error) => finish(() => {
|
|
22861
|
+
logResponse(span, partial);
|
|
22862
|
+
span.log({ error });
|
|
22863
|
+
}),
|
|
22864
|
+
onCancel: () => finish(() => logResponse(span, partial))
|
|
22865
|
+
});
|
|
22866
|
+
void value.response.then(
|
|
22867
|
+
(response) => finish(() => logResponse(span, response)),
|
|
22868
|
+
(error) => finish(() => {
|
|
22869
|
+
logResponse(span, partial);
|
|
22870
|
+
span.log({ error });
|
|
22871
|
+
})
|
|
22872
|
+
);
|
|
22873
|
+
} else if ("response" in value) {
|
|
22874
|
+
finish(() => logResponse(span, value.response));
|
|
22875
|
+
} else {
|
|
22876
|
+
const metrics = {};
|
|
22877
|
+
const promptTokens = value.usageMetadata?.promptTokenCount;
|
|
22878
|
+
if (typeof promptTokens === "number" && Number.isFinite(promptTokens) && promptTokens >= 0) {
|
|
22879
|
+
metrics.prompt_tokens = promptTokens;
|
|
22880
|
+
metrics.tokens = promptTokens;
|
|
22881
|
+
}
|
|
22882
|
+
for (const detail of value.usageMetadata?.promptTokenDetails ?? []) {
|
|
22883
|
+
if (detail.modality === "AUDIO" && typeof detail.tokenCount === "number" && Number.isFinite(detail.tokenCount) && detail.tokenCount >= 0) {
|
|
22884
|
+
metrics.prompt_audio_tokens = (metrics.prompt_audio_tokens ?? 0) + detail.tokenCount;
|
|
22885
|
+
}
|
|
22886
|
+
}
|
|
22887
|
+
finish(
|
|
22888
|
+
() => span.log({
|
|
22889
|
+
metrics,
|
|
22890
|
+
output: {
|
|
22891
|
+
count: value.embeddings?.length ?? (value.embedding ? 1 : 0)
|
|
22892
|
+
}
|
|
22893
|
+
})
|
|
22894
|
+
);
|
|
22895
|
+
}
|
|
22896
|
+
} catch (error) {
|
|
22897
|
+
debugLogger.error(
|
|
22898
|
+
"Error observing Google Generative AI result:",
|
|
22899
|
+
error
|
|
22900
|
+
);
|
|
22901
|
+
finish(() => {
|
|
22902
|
+
});
|
|
22903
|
+
}
|
|
22904
|
+
},
|
|
22905
|
+
(error) => finish(() => span.log({ error }))
|
|
22906
|
+
);
|
|
22907
|
+
return result;
|
|
22908
|
+
});
|
|
22909
|
+
}
|
|
22910
|
+
function normalizeContent(message) {
|
|
22911
|
+
const parts = (typeof message === "string" ? [message] : message).map(
|
|
22912
|
+
(part) => typeof part === "string" ? { text: part } : part
|
|
22913
|
+
);
|
|
22914
|
+
return {
|
|
22915
|
+
role: parts.some((part) => part.functionResponse) ? "function" : "user",
|
|
22916
|
+
parts
|
|
22917
|
+
};
|
|
22918
|
+
}
|
|
22919
|
+
function extractInput(self, request, operation) {
|
|
22920
|
+
const model = self.model.replace(/^models\//, "");
|
|
22921
|
+
if (operation === "embedContent" || operation === "batchEmbedContents") {
|
|
22922
|
+
const requests = operation === "batchEmbedContents" ? request.requests : [
|
|
22923
|
+
typeof request === "string" || Array.isArray(request) ? { content: normalizeContent(request) } : request
|
|
22924
|
+
];
|
|
22925
|
+
const dimensions = requests[0]?.outputDimensionality;
|
|
22926
|
+
return {
|
|
22927
|
+
input: {
|
|
22928
|
+
inputs: convertAttachments(requests).map((item) => ({
|
|
22929
|
+
content: item.content.parts.length === 1 && item.content.parts[0].text !== void 0 ? item.content.parts[0].text : item.content.parts.map((part) => {
|
|
22930
|
+
if (part.text !== void 0)
|
|
22931
|
+
return { type: "text", text: part.text };
|
|
22932
|
+
const mimeType = part.inlineData?.mimeType ?? part.fileData?.mimeType;
|
|
22933
|
+
const data = part.inlineData ? typeof part.inlineData.data === "string" ? `data:${mimeType};base64,${part.inlineData.data}` : part.inlineData.data : part.fileData?.fileUri;
|
|
22934
|
+
return mimeType?.startsWith("image/") ? { type: "image_url", image_url: { url: data } } : { type: "file", file: { file_data: data } };
|
|
22935
|
+
})
|
|
22936
|
+
})),
|
|
22937
|
+
...dimensions !== void 0 && requests.every((item) => item.outputDimensionality === dimensions) ? { output_dimensions: dimensions } : {}
|
|
22938
|
+
},
|
|
22939
|
+
metadata: { model, provider: "google" }
|
|
22940
|
+
};
|
|
22941
|
+
}
|
|
22942
|
+
const chat = operation.startsWith("sendMessage");
|
|
22943
|
+
const config = chat ? self.params ?? {} : self;
|
|
22944
|
+
const params = typeof request === "string" || Array.isArray(request) ? { contents: [normalizeContent(request)] } : request;
|
|
22945
|
+
const system = params.systemInstruction ?? config.systemInstruction;
|
|
22946
|
+
const systemContent = typeof system === "string" ? { role: "system", parts: [{ text: system }] } : system && "parts" in system ? { ...system, role: "system" } : system ? { role: "system", parts: [system] } : void 0;
|
|
22947
|
+
const contents = [
|
|
22948
|
+
...systemContent ? [systemContent] : [],
|
|
22949
|
+
...chat ? self._history : [],
|
|
22950
|
+
...params.contents
|
|
22951
|
+
];
|
|
22952
|
+
const metadata = { model, provider: "google" };
|
|
22953
|
+
const generation = params.generationConfig ?? config.generationConfig;
|
|
22954
|
+
for (const key of GENERATION_CONFIG_KEYS) {
|
|
22955
|
+
if (generation && Object.hasOwn(generation, key))
|
|
22956
|
+
metadata[key] = generation[key];
|
|
22957
|
+
}
|
|
22958
|
+
for (const key of ["tools", "toolConfig", "safetySettings"]) {
|
|
22959
|
+
const value = params[key] ?? config[key];
|
|
22960
|
+
if (value !== void 0) metadata[key] = value;
|
|
22961
|
+
}
|
|
22962
|
+
const cached = params.cachedContent ?? config.cachedContent;
|
|
22963
|
+
if (cached)
|
|
22964
|
+
metadata.cachedContent = typeof cached === "string" ? cached : cached.name;
|
|
22965
|
+
return { input: convertAttachments({ model, contents }), metadata };
|
|
22966
|
+
}
|
|
22967
|
+
function convertAttachments(value) {
|
|
22968
|
+
const convert = (node) => {
|
|
22969
|
+
if (Array.isArray(node)) return node.map(convert);
|
|
22970
|
+
if (!isObject(node)) return node;
|
|
22971
|
+
if (isObject(node.inlineData)) {
|
|
22972
|
+
const { data, mimeType } = node.inlineData;
|
|
22973
|
+
const processed = processInputAttachments({
|
|
22974
|
+
type: "file",
|
|
22975
|
+
file: { file_data: `data:${mimeType};base64,${data}` }
|
|
22976
|
+
});
|
|
22977
|
+
if (typeof processed.file.file_data === "string")
|
|
22978
|
+
throw new Error("Unable to convert Google inline data");
|
|
22979
|
+
return {
|
|
22980
|
+
...node,
|
|
22981
|
+
inlineData: { ...node.inlineData, data: processed.file.file_data }
|
|
22982
|
+
};
|
|
22983
|
+
}
|
|
22984
|
+
return Object.fromEntries(
|
|
22985
|
+
Object.entries(node).map(([key, item]) => [key, convert(item)])
|
|
22986
|
+
);
|
|
22987
|
+
};
|
|
22988
|
+
try {
|
|
22989
|
+
return convert(value);
|
|
22990
|
+
} catch (error) {
|
|
22991
|
+
debugLogger.error(
|
|
22992
|
+
"Error converting Google Generative AI attachments:",
|
|
22993
|
+
error
|
|
22994
|
+
);
|
|
22995
|
+
return value;
|
|
22996
|
+
}
|
|
22997
|
+
}
|
|
22998
|
+
function logResponse(span, response) {
|
|
22999
|
+
const usage = response.usageMetadata;
|
|
23000
|
+
const metrics = {};
|
|
23001
|
+
if (usage) {
|
|
23002
|
+
if (usage.promptTokenCount !== void 0)
|
|
23003
|
+
metrics.prompt_tokens = usage.promptTokenCount;
|
|
23004
|
+
if (usage.candidatesTokenCount !== void 0 || usage.thoughtsTokenCount !== void 0)
|
|
23005
|
+
metrics.completion_tokens = (usage.candidatesTokenCount ?? 0) + (usage.thoughtsTokenCount ?? 0);
|
|
23006
|
+
if (usage.totalTokenCount !== void 0)
|
|
23007
|
+
metrics.tokens = usage.totalTokenCount;
|
|
23008
|
+
if (usage.cachedContentTokenCount !== void 0)
|
|
23009
|
+
metrics.prompt_cached_tokens = usage.cachedContentTokenCount;
|
|
23010
|
+
if (usage.thoughtsTokenCount !== void 0)
|
|
23011
|
+
metrics.completion_reasoning_tokens = usage.thoughtsTokenCount;
|
|
23012
|
+
}
|
|
23013
|
+
span.log({
|
|
23014
|
+
output: convertAttachments({
|
|
23015
|
+
candidates: response.candidates,
|
|
23016
|
+
promptFeedback: response.promptFeedback
|
|
23017
|
+
}),
|
|
23018
|
+
metrics,
|
|
23019
|
+
...response.modelVersion ? { metadata: { model: response.modelVersion } } : {}
|
|
23020
|
+
});
|
|
23021
|
+
}
|
|
23022
|
+
|
|
22666
23023
|
// src/instrumentation/plugins/google-genai-channels.ts
|
|
22667
23024
|
var googleGenAIChannels = defineChannels(
|
|
22668
23025
|
"@google/genai",
|
|
@@ -24306,7 +24663,7 @@ var HuggingFaceTransformersPlugin = class extends BasePlugin {
|
|
|
24306
24663
|
getTask(event)
|
|
24307
24664
|
),
|
|
24308
24665
|
extractInput: (args, event) => ({
|
|
24309
|
-
input:
|
|
24666
|
+
input: extractInput2(
|
|
24310
24667
|
getTask(event),
|
|
24311
24668
|
args
|
|
24312
24669
|
),
|
|
@@ -24396,7 +24753,7 @@ function modelIdentifier(pipeline) {
|
|
|
24396
24753
|
}
|
|
24397
24754
|
return void 0;
|
|
24398
24755
|
}
|
|
24399
|
-
function
|
|
24756
|
+
function extractInput2(task, args) {
|
|
24400
24757
|
switch (task) {
|
|
24401
24758
|
case "feature-extraction":
|
|
24402
24759
|
return args[0];
|
|
@@ -34750,6 +35107,477 @@ function logInstrumentationError5(context, error) {
|
|
|
34750
35107
|
debugLogger.debug(`${context}:`, error);
|
|
34751
35108
|
}
|
|
34752
35109
|
|
|
35110
|
+
// src/instrumentation/plugins/elevenlabs-channels.ts
|
|
35111
|
+
var elevenLabsChannels = defineChannels(
|
|
35112
|
+
"@elevenlabs/elevenlabs-js",
|
|
35113
|
+
{
|
|
35114
|
+
convert: channel({
|
|
35115
|
+
channelName: "textToSpeech.convert",
|
|
35116
|
+
kind: "async"
|
|
35117
|
+
}),
|
|
35118
|
+
stream: channel({
|
|
35119
|
+
channelName: "textToSpeech.stream",
|
|
35120
|
+
kind: "async"
|
|
35121
|
+
}),
|
|
35122
|
+
convertWithTimestamps: channel({ channelName: "textToSpeech.convertWithTimestamps", kind: "async" }),
|
|
35123
|
+
streamWithTimestamps: channel({ channelName: "textToSpeech.streamWithTimestamps", kind: "async" }),
|
|
35124
|
+
transcribe: channel({ channelName: "speechToText.convert", kind: "async" })
|
|
35125
|
+
},
|
|
35126
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.ELEVENLABS }
|
|
35127
|
+
);
|
|
35128
|
+
|
|
35129
|
+
// src/instrumentation/plugins/elevenlabs-plugin.ts
|
|
35130
|
+
var ElevenLabsPlugin = class extends BasePlugin {
|
|
35131
|
+
onEnable() {
|
|
35132
|
+
for (const method of [
|
|
35133
|
+
"convert",
|
|
35134
|
+
"stream",
|
|
35135
|
+
"convertWithTimestamps",
|
|
35136
|
+
"streamWithTimestamps"
|
|
35137
|
+
]) {
|
|
35138
|
+
this.unsubscribers.push(
|
|
35139
|
+
interceptCall2(
|
|
35140
|
+
elevenLabsChannels[method],
|
|
35141
|
+
`elevenlabs.textToSpeech.${method}`,
|
|
35142
|
+
([voice, request]) => ({
|
|
35143
|
+
input: {
|
|
35144
|
+
operation: "speech",
|
|
35145
|
+
prompt: request.text,
|
|
35146
|
+
parameters: {
|
|
35147
|
+
voice,
|
|
35148
|
+
format: request.outputFormat,
|
|
35149
|
+
language: request.languageCode,
|
|
35150
|
+
speed: request.voiceSettings?.speed
|
|
35151
|
+
}
|
|
35152
|
+
},
|
|
35153
|
+
metadata: {
|
|
35154
|
+
provider: "elevenlabs",
|
|
35155
|
+
model: request.modelId ?? "eleven_multilingual_v2"
|
|
35156
|
+
}
|
|
35157
|
+
}),
|
|
35158
|
+
(value, args, span, finish, headers, started) => captureSpeech(
|
|
35159
|
+
value,
|
|
35160
|
+
args[1],
|
|
35161
|
+
method,
|
|
35162
|
+
span,
|
|
35163
|
+
finish,
|
|
35164
|
+
started,
|
|
35165
|
+
headers
|
|
35166
|
+
)
|
|
35167
|
+
)
|
|
35168
|
+
);
|
|
35169
|
+
}
|
|
35170
|
+
this.unsubscribers.push(
|
|
35171
|
+
interceptCall2(
|
|
35172
|
+
elevenLabsChannels.transcribe,
|
|
35173
|
+
"elevenlabs.speechToText.convert",
|
|
35174
|
+
([request]) => {
|
|
35175
|
+
if (request.webhook) return void 0;
|
|
35176
|
+
const file = request.file;
|
|
35177
|
+
const filename = typeof File !== "undefined" && file instanceof File ? file.name : "audio";
|
|
35178
|
+
const contentType = file instanceof Blob ? file.type || "application/octet-stream" : "application/octet-stream";
|
|
35179
|
+
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;
|
|
35180
|
+
const fileData = blob ? new Attachment({ data: blob, filename, contentType }) : request.cloudStorageUrl;
|
|
35181
|
+
return {
|
|
35182
|
+
input: {
|
|
35183
|
+
operation: "transcribe",
|
|
35184
|
+
content: fileData ? [{ type: "file", file: { filename, file_data: fileData } }] : [],
|
|
35185
|
+
parameters: {
|
|
35186
|
+
language: request.languageCode,
|
|
35187
|
+
timestamp_granularities: request.timestampsGranularity
|
|
35188
|
+
}
|
|
35189
|
+
},
|
|
35190
|
+
metadata: { provider: "elevenlabs", model: request.modelId }
|
|
35191
|
+
};
|
|
35192
|
+
},
|
|
35193
|
+
(value, _args, span, finish) => {
|
|
35194
|
+
const result = value;
|
|
35195
|
+
const transcripts = result.transcripts ?? [result];
|
|
35196
|
+
span.log({
|
|
35197
|
+
output: {
|
|
35198
|
+
content: transcripts.flatMap(
|
|
35199
|
+
(transcript) => typeof transcript.text === "string" ? [{ type: "text", text: transcript.text }] : []
|
|
35200
|
+
),
|
|
35201
|
+
annotations: {
|
|
35202
|
+
language: result.languageCode,
|
|
35203
|
+
words: result.words ?? (result.transcripts ? result.transcripts.flatMap(
|
|
35204
|
+
(transcript) => transcript.words ?? []
|
|
35205
|
+
) : void 0)
|
|
35206
|
+
}
|
|
35207
|
+
}
|
|
35208
|
+
});
|
|
35209
|
+
finish();
|
|
35210
|
+
},
|
|
35211
|
+
([request], span) => {
|
|
35212
|
+
const file = request.file;
|
|
35213
|
+
if (!isAsyncIterable(file)) return;
|
|
35214
|
+
const chunks = [];
|
|
35215
|
+
const filename = isObject(file) && typeof file.path === "string" ? file.path.split(/[\\/]/).pop() || "audio" : "audio";
|
|
35216
|
+
observeAudioStream(
|
|
35217
|
+
file,
|
|
35218
|
+
(chunk) => chunks.push(new Uint8Array(chunk)),
|
|
35219
|
+
() => {
|
|
35220
|
+
const contentType = "application/octet-stream";
|
|
35221
|
+
const data = new Blob(chunks, {
|
|
35222
|
+
type: contentType
|
|
35223
|
+
});
|
|
35224
|
+
chunks.length = 0;
|
|
35225
|
+
span.log({
|
|
35226
|
+
input: {
|
|
35227
|
+
content: [
|
|
35228
|
+
{
|
|
35229
|
+
type: "file",
|
|
35230
|
+
file: {
|
|
35231
|
+
filename,
|
|
35232
|
+
file_data: new Attachment({
|
|
35233
|
+
data,
|
|
35234
|
+
filename,
|
|
35235
|
+
contentType
|
|
35236
|
+
})
|
|
35237
|
+
}
|
|
35238
|
+
}
|
|
35239
|
+
]
|
|
35240
|
+
}
|
|
35241
|
+
});
|
|
35242
|
+
},
|
|
35243
|
+
() => {
|
|
35244
|
+
chunks.length = 0;
|
|
35245
|
+
},
|
|
35246
|
+
span
|
|
35247
|
+
);
|
|
35248
|
+
}
|
|
35249
|
+
)
|
|
35250
|
+
);
|
|
35251
|
+
}
|
|
35252
|
+
onDisable() {
|
|
35253
|
+
this.unsubscribers = unsubscribeAll(this.unsubscribers);
|
|
35254
|
+
}
|
|
35255
|
+
};
|
|
35256
|
+
function interceptCall2(channel2, name, input, output, beforeInvoke) {
|
|
35257
|
+
return channel2.intercept((target, self, args) => {
|
|
35258
|
+
const invoke = () => Reflect.apply(target, self, args);
|
|
35259
|
+
if (isAutoInstrumentationSuppressed()) return invoke();
|
|
35260
|
+
const started = Date.now() / 1e3;
|
|
35261
|
+
let span;
|
|
35262
|
+
try {
|
|
35263
|
+
const event = input(args);
|
|
35264
|
+
if (event !== void 0)
|
|
35265
|
+
span = startSpan(
|
|
35266
|
+
withSpanInstrumentationName(
|
|
35267
|
+
{
|
|
35268
|
+
name,
|
|
35269
|
+
spanAttributes: { type: "llm" /* LLM */ },
|
|
35270
|
+
event
|
|
35271
|
+
},
|
|
35272
|
+
INSTRUMENTATION_NAMES.ELEVENLABS
|
|
35273
|
+
)
|
|
35274
|
+
);
|
|
35275
|
+
} catch (error) {
|
|
35276
|
+
debugLogger.error("Error starting ElevenLabs span", error);
|
|
35277
|
+
return invoke();
|
|
35278
|
+
}
|
|
35279
|
+
if (!span) return invoke();
|
|
35280
|
+
const activeSpan = span;
|
|
35281
|
+
let ended = false;
|
|
35282
|
+
const finish = (error) => {
|
|
35283
|
+
if (ended) return;
|
|
35284
|
+
ended = true;
|
|
35285
|
+
try {
|
|
35286
|
+
if (error !== void 0) activeSpan.log({ error });
|
|
35287
|
+
activeSpan.end();
|
|
35288
|
+
} catch (loggingError) {
|
|
35289
|
+
debugLogger.error("Error ending ElevenLabs span", loggingError);
|
|
35290
|
+
}
|
|
35291
|
+
};
|
|
35292
|
+
try {
|
|
35293
|
+
beforeInvoke?.(args, span);
|
|
35294
|
+
} catch (error) {
|
|
35295
|
+
debugLogger.error("Error observing ElevenLabs input", error);
|
|
35296
|
+
}
|
|
35297
|
+
let result;
|
|
35298
|
+
try {
|
|
35299
|
+
result = withCurrent(
|
|
35300
|
+
span,
|
|
35301
|
+
() => runWithAutoInstrumentationSuppressed(invoke)
|
|
35302
|
+
);
|
|
35303
|
+
} catch (error) {
|
|
35304
|
+
finish(error);
|
|
35305
|
+
throw error;
|
|
35306
|
+
}
|
|
35307
|
+
const capture = (value, headers) => {
|
|
35308
|
+
try {
|
|
35309
|
+
output(value, args, span, finish, headers, started);
|
|
35310
|
+
} catch (error) {
|
|
35311
|
+
debugLogger.error("Error capturing ElevenLabs output", error);
|
|
35312
|
+
finish();
|
|
35313
|
+
}
|
|
35314
|
+
};
|
|
35315
|
+
try {
|
|
35316
|
+
if (isObject(result) && typeof result.withRawResponse === "function") {
|
|
35317
|
+
void result.withRawResponse().then(
|
|
35318
|
+
({
|
|
35319
|
+
data,
|
|
35320
|
+
rawResponse
|
|
35321
|
+
}) => capture(data, rawResponse?.headers),
|
|
35322
|
+
finish
|
|
35323
|
+
);
|
|
35324
|
+
} else {
|
|
35325
|
+
void Promise.resolve(result).then((value) => capture(value), finish);
|
|
35326
|
+
}
|
|
35327
|
+
} catch (error) {
|
|
35328
|
+
debugLogger.error("Error observing ElevenLabs result", error);
|
|
35329
|
+
finish();
|
|
35330
|
+
}
|
|
35331
|
+
return result;
|
|
35332
|
+
});
|
|
35333
|
+
}
|
|
35334
|
+
function captureSpeech(value, request, method, span, finish, started, headers) {
|
|
35335
|
+
const format = request.outputFormat ?? "mp3_44100_128";
|
|
35336
|
+
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;
|
|
35337
|
+
const headerType = headers?.get("content-type")?.split(";")[0];
|
|
35338
|
+
const contentType = headerType?.startsWith("audio/") ? headerType : formatType;
|
|
35339
|
+
const disposition = headers?.get("content-disposition");
|
|
35340
|
+
const headerFilename = disposition?.match(
|
|
35341
|
+
/filename="([^"]+)"|filename=([^;]+)/i
|
|
35342
|
+
);
|
|
35343
|
+
const filename = headerFilename?.[1] ?? headerFilename?.[2]?.trim() ?? `speech.${contentType ? getExtensionFromMediaType(contentType) : "bin"}`;
|
|
35344
|
+
const chunks = [];
|
|
35345
|
+
const alignments = [];
|
|
35346
|
+
let bytes = 0;
|
|
35347
|
+
let first = true;
|
|
35348
|
+
let stopped = false;
|
|
35349
|
+
const observe = (chunk) => {
|
|
35350
|
+
if (stopped || chunk.byteLength === 0) return;
|
|
35351
|
+
if (first && method.startsWith("stream")) {
|
|
35352
|
+
span.log({
|
|
35353
|
+
metrics: { time_to_first_token: Date.now() / 1e3 - started }
|
|
35354
|
+
});
|
|
35355
|
+
}
|
|
35356
|
+
first = false;
|
|
35357
|
+
chunks.push(new Uint8Array(chunk));
|
|
35358
|
+
bytes += chunk.byteLength;
|
|
35359
|
+
};
|
|
35360
|
+
const complete = () => {
|
|
35361
|
+
if (stopped) return;
|
|
35362
|
+
stopped = true;
|
|
35363
|
+
try {
|
|
35364
|
+
const content = [];
|
|
35365
|
+
if (contentType && bytes) {
|
|
35366
|
+
const data = new Uint8Array(bytes);
|
|
35367
|
+
let offset = 0;
|
|
35368
|
+
for (const chunk of chunks) {
|
|
35369
|
+
data.set(chunk, offset);
|
|
35370
|
+
offset += chunk.length;
|
|
35371
|
+
}
|
|
35372
|
+
content.push({
|
|
35373
|
+
type: "file",
|
|
35374
|
+
file: {
|
|
35375
|
+
filename,
|
|
35376
|
+
byte_size: bytes,
|
|
35377
|
+
file_data: new Attachment({
|
|
35378
|
+
data: new Blob([data], { type: contentType }),
|
|
35379
|
+
filename,
|
|
35380
|
+
contentType
|
|
35381
|
+
})
|
|
35382
|
+
}
|
|
35383
|
+
});
|
|
35384
|
+
}
|
|
35385
|
+
span.log({
|
|
35386
|
+
output: {
|
|
35387
|
+
content,
|
|
35388
|
+
...alignments.length ? { annotations: alignments } : {}
|
|
35389
|
+
}
|
|
35390
|
+
});
|
|
35391
|
+
} finally {
|
|
35392
|
+
chunks.length = 0;
|
|
35393
|
+
finish();
|
|
35394
|
+
}
|
|
35395
|
+
};
|
|
35396
|
+
const cancel = (error) => {
|
|
35397
|
+
stopped = true;
|
|
35398
|
+
chunks.length = 0;
|
|
35399
|
+
finish(error);
|
|
35400
|
+
};
|
|
35401
|
+
const timestampChunk = (chunk) => {
|
|
35402
|
+
const binary = atob(chunk.audioBase64);
|
|
35403
|
+
observe(Uint8Array.from(binary, (character) => character.charCodeAt(0)));
|
|
35404
|
+
if (chunk.alignment || chunk.normalizedAlignment)
|
|
35405
|
+
alignments.push({
|
|
35406
|
+
alignment: chunk.alignment,
|
|
35407
|
+
normalized_alignment: chunk.normalizedAlignment
|
|
35408
|
+
});
|
|
35409
|
+
};
|
|
35410
|
+
if (method === "convertWithTimestamps") {
|
|
35411
|
+
timestampChunk(value);
|
|
35412
|
+
complete();
|
|
35413
|
+
} else if (method === "streamWithTimestamps") {
|
|
35414
|
+
patchStreamIfNeeded(value, {
|
|
35415
|
+
shouldCollect: (chunk) => {
|
|
35416
|
+
try {
|
|
35417
|
+
timestampChunk(chunk);
|
|
35418
|
+
} catch (error) {
|
|
35419
|
+
debugLogger.error("Error collecting ElevenLabs timestamps", error);
|
|
35420
|
+
cancel();
|
|
35421
|
+
}
|
|
35422
|
+
return false;
|
|
35423
|
+
},
|
|
35424
|
+
onComplete: complete,
|
|
35425
|
+
onCancel: () => cancel(),
|
|
35426
|
+
onError: cancel,
|
|
35427
|
+
aroundNext: (next) => withCurrent(span, next)
|
|
35428
|
+
});
|
|
35429
|
+
} else {
|
|
35430
|
+
observeAudioStream(value, observe, complete, cancel, span);
|
|
35431
|
+
}
|
|
35432
|
+
}
|
|
35433
|
+
function observeAudioStream(value, observe, complete, cancel, span) {
|
|
35434
|
+
let ended = false;
|
|
35435
|
+
const safeObserve = (chunk) => {
|
|
35436
|
+
if (ended) return;
|
|
35437
|
+
try {
|
|
35438
|
+
observe(chunk);
|
|
35439
|
+
} catch (error) {
|
|
35440
|
+
debugLogger.error("Error collecting ElevenLabs audio", error);
|
|
35441
|
+
end(false);
|
|
35442
|
+
}
|
|
35443
|
+
};
|
|
35444
|
+
const end = (success, error) => {
|
|
35445
|
+
if (ended) return;
|
|
35446
|
+
ended = true;
|
|
35447
|
+
try {
|
|
35448
|
+
if (success) complete();
|
|
35449
|
+
else cancel(error);
|
|
35450
|
+
} catch (loggingError) {
|
|
35451
|
+
debugLogger.error("Error logging ElevenLabs audio", loggingError);
|
|
35452
|
+
cancel();
|
|
35453
|
+
}
|
|
35454
|
+
};
|
|
35455
|
+
if (!isObject(value) || !Object.isExtensible(value)) {
|
|
35456
|
+
end(false);
|
|
35457
|
+
return;
|
|
35458
|
+
}
|
|
35459
|
+
if (typeof value.read === "function" && typeof value.on === "function") {
|
|
35460
|
+
value.on("end", () => end(true));
|
|
35461
|
+
value.on("close", () => end(false));
|
|
35462
|
+
const emit2 = value.emit;
|
|
35463
|
+
if (typeof emit2 === "function")
|
|
35464
|
+
value.emit = function(event, ...args) {
|
|
35465
|
+
if (event === "data" && args[0] instanceof Uint8Array)
|
|
35466
|
+
safeObserve(args[0]);
|
|
35467
|
+
if (event === "error") end(false, args[0]);
|
|
35468
|
+
return Reflect.apply(emit2, this, [event, ...args]);
|
|
35469
|
+
};
|
|
35470
|
+
return;
|
|
35471
|
+
}
|
|
35472
|
+
if (typeof value.getReader === "function") {
|
|
35473
|
+
const webStream = value;
|
|
35474
|
+
const pipeTo = webStream.pipeTo;
|
|
35475
|
+
const pipeThrough = webStream.pipeThrough;
|
|
35476
|
+
webStream.pipeTo = function(destination, options) {
|
|
35477
|
+
if (!isObject(destination) || this.locked || destination.locked)
|
|
35478
|
+
return pipeTo.call(this, destination, options);
|
|
35479
|
+
const tap = new TransformStream({
|
|
35480
|
+
transform(chunk, controller) {
|
|
35481
|
+
safeObserve(chunk);
|
|
35482
|
+
controller.enqueue(chunk);
|
|
35483
|
+
},
|
|
35484
|
+
flush() {
|
|
35485
|
+
end(true);
|
|
35486
|
+
}
|
|
35487
|
+
});
|
|
35488
|
+
const observed = pipeThrough.call(
|
|
35489
|
+
this,
|
|
35490
|
+
tap,
|
|
35491
|
+
options
|
|
35492
|
+
);
|
|
35493
|
+
return observed.pipeTo(destination, options).catch((error) => {
|
|
35494
|
+
end(false, error);
|
|
35495
|
+
throw error;
|
|
35496
|
+
});
|
|
35497
|
+
};
|
|
35498
|
+
webStream.pipeThrough = function(transform, options) {
|
|
35499
|
+
if (this.locked || transform.writable.locked || transform.readable.locked)
|
|
35500
|
+
return pipeThrough.call(this, transform, options);
|
|
35501
|
+
const result = webStream.pipeTo.call(this, transform.writable, options);
|
|
35502
|
+
void result.catch(() => {
|
|
35503
|
+
});
|
|
35504
|
+
return transform.readable;
|
|
35505
|
+
};
|
|
35506
|
+
const getReader = value.getReader;
|
|
35507
|
+
value.getReader = function(...args) {
|
|
35508
|
+
const reader = Reflect.apply(getReader, this, args);
|
|
35509
|
+
const read2 = reader.read;
|
|
35510
|
+
reader.read = function(...readArgs) {
|
|
35511
|
+
return Promise.resolve(
|
|
35512
|
+
withCurrent(span, () => Reflect.apply(read2, this, readArgs))
|
|
35513
|
+
).then(
|
|
35514
|
+
(result) => {
|
|
35515
|
+
if (result.value) safeObserve(result.value);
|
|
35516
|
+
if (result.done) end(true);
|
|
35517
|
+
return result;
|
|
35518
|
+
},
|
|
35519
|
+
(error) => {
|
|
35520
|
+
end(false, error);
|
|
35521
|
+
throw error;
|
|
35522
|
+
}
|
|
35523
|
+
);
|
|
35524
|
+
};
|
|
35525
|
+
const readerCancel = reader.cancel;
|
|
35526
|
+
reader.cancel = function(...cancelArgs) {
|
|
35527
|
+
const result = Reflect.apply(readerCancel, this, cancelArgs);
|
|
35528
|
+
end(false);
|
|
35529
|
+
return result;
|
|
35530
|
+
};
|
|
35531
|
+
return reader;
|
|
35532
|
+
};
|
|
35533
|
+
const streamCancel = value.cancel;
|
|
35534
|
+
if (typeof streamCancel === "function")
|
|
35535
|
+
value.cancel = function(...args) {
|
|
35536
|
+
const result = Reflect.apply(streamCancel, this, args);
|
|
35537
|
+
void Promise.resolve(result).then(
|
|
35538
|
+
() => end(false),
|
|
35539
|
+
() => {
|
|
35540
|
+
}
|
|
35541
|
+
);
|
|
35542
|
+
return result;
|
|
35543
|
+
};
|
|
35544
|
+
}
|
|
35545
|
+
if (typeof value.getReader === "function" && typeof value.values === "function") {
|
|
35546
|
+
const values = value.values;
|
|
35547
|
+
const iterate = function(...args) {
|
|
35548
|
+
const iterator = Reflect.apply(values, this, args);
|
|
35549
|
+
patchStreamIfNeeded(iterator, {
|
|
35550
|
+
shouldCollect(chunk) {
|
|
35551
|
+
safeObserve(chunk);
|
|
35552
|
+
return false;
|
|
35553
|
+
},
|
|
35554
|
+
onComplete: () => end(true),
|
|
35555
|
+
onCancel: () => end(false),
|
|
35556
|
+
onError: (error) => end(false, error),
|
|
35557
|
+
aroundNext: (next) => withCurrent(span, next)
|
|
35558
|
+
});
|
|
35559
|
+
return iterator;
|
|
35560
|
+
};
|
|
35561
|
+
value.values = iterate;
|
|
35562
|
+
Object.defineProperty(value, Symbol.asyncIterator, {
|
|
35563
|
+
configurable: true,
|
|
35564
|
+
writable: true,
|
|
35565
|
+
value: iterate
|
|
35566
|
+
});
|
|
35567
|
+
} else if (isAsyncIterable(value)) {
|
|
35568
|
+
patchStreamIfNeeded(value, {
|
|
35569
|
+
shouldCollect: (chunk) => {
|
|
35570
|
+
safeObserve(chunk);
|
|
35571
|
+
return false;
|
|
35572
|
+
},
|
|
35573
|
+
onComplete: () => end(true),
|
|
35574
|
+
onCancel: () => end(false),
|
|
35575
|
+
onError: (error) => end(false, error),
|
|
35576
|
+
aroundNext: (next) => withCurrent(span, next)
|
|
35577
|
+
});
|
|
35578
|
+
} else if (typeof value.getReader !== "function") end(false);
|
|
35579
|
+
}
|
|
35580
|
+
|
|
34753
35581
|
// src/instrumentation/plugins/voyageai-channels.ts
|
|
34754
35582
|
var voyageAIChannels = defineChannels(
|
|
34755
35583
|
"voyageai",
|
|
@@ -34817,7 +35645,7 @@ var VoyageAIPlugin = class extends BasePlugin {
|
|
|
34817
35645
|
this.unsubscribers = unsubscribeAll(this.unsubscribers);
|
|
34818
35646
|
}
|
|
34819
35647
|
};
|
|
34820
|
-
function interceptVoyageAICall(channel2, name,
|
|
35648
|
+
function interceptVoyageAICall(channel2, name, extractInput3, extractOutput2, extractMetrics2 = extractUsageMetrics3) {
|
|
34821
35649
|
return channel2.intercept((target, thisArg, args) => {
|
|
34822
35650
|
const invokeTarget = () => Reflect.apply(target, thisArg, args);
|
|
34823
35651
|
if (isAutoInstrumentationSuppressed()) {
|
|
@@ -34825,7 +35653,7 @@ function interceptVoyageAICall(channel2, name, extractInput2, extractOutput2, ex
|
|
|
34825
35653
|
}
|
|
34826
35654
|
let span;
|
|
34827
35655
|
try {
|
|
34828
|
-
const { input, metadata } =
|
|
35656
|
+
const { input, metadata } = extractInput3(args);
|
|
34829
35657
|
span = startSpan(
|
|
34830
35658
|
withSpanInstrumentationName(
|
|
34831
35659
|
{
|
|
@@ -35601,6 +36429,7 @@ var BraintrustPlugin = class extends BasePlugin {
|
|
|
35601
36429
|
cloudflareThinkPlugin = null;
|
|
35602
36430
|
cursorSDKPlugin = null;
|
|
35603
36431
|
openAIAgentsPlugin = null;
|
|
36432
|
+
googleGenerativeAIPlugin = null;
|
|
35604
36433
|
googleGenAIPlugin = null;
|
|
35605
36434
|
huggingFacePlugin = null;
|
|
35606
36435
|
huggingFaceTransformersPlugin = null;
|
|
@@ -35619,6 +36448,7 @@ var BraintrustPlugin = class extends BasePlugin {
|
|
|
35619
36448
|
langSmithPlugin = null;
|
|
35620
36449
|
piCodingAgentPlugin = null;
|
|
35621
36450
|
strandsAgentSDKPlugin = null;
|
|
36451
|
+
elevenLabsPlugin = null;
|
|
35622
36452
|
voyageAIPlugin = null;
|
|
35623
36453
|
cloudflareAIChatPlugin = null;
|
|
35624
36454
|
cloudflareAgentsPlugin = null;
|
|
@@ -35660,6 +36490,10 @@ var BraintrustPlugin = class extends BasePlugin {
|
|
|
35660
36490
|
this.openAIAgentsPlugin = new OpenAIAgentsPlugin();
|
|
35661
36491
|
this.openAIAgentsPlugin.enable();
|
|
35662
36492
|
}
|
|
36493
|
+
if (integrations.googleGenerativeAI !== false) {
|
|
36494
|
+
this.googleGenerativeAIPlugin = new GoogleGenerativeAIPlugin();
|
|
36495
|
+
this.googleGenerativeAIPlugin.enable();
|
|
36496
|
+
}
|
|
35663
36497
|
if (integrations.googleGenAI !== false && integrations.google !== false) {
|
|
35664
36498
|
this.googleGenAIPlugin = new GoogleGenAIPlugin();
|
|
35665
36499
|
this.googleGenAIPlugin.enable();
|
|
@@ -35694,6 +36528,10 @@ var BraintrustPlugin = class extends BasePlugin {
|
|
|
35694
36528
|
this.coherePlugin = new CoherePlugin();
|
|
35695
36529
|
this.coherePlugin.enable();
|
|
35696
36530
|
}
|
|
36531
|
+
if (integrations.elevenlabs !== false) {
|
|
36532
|
+
this.elevenLabsPlugin = new ElevenLabsPlugin();
|
|
36533
|
+
this.elevenLabsPlugin.enable();
|
|
36534
|
+
}
|
|
35697
36535
|
if (integrations.voyageai !== false) {
|
|
35698
36536
|
this.voyageAIPlugin = new VoyageAIPlugin();
|
|
35699
36537
|
this.voyageAIPlugin.enable();
|
|
@@ -35778,6 +36616,10 @@ var BraintrustPlugin = class extends BasePlugin {
|
|
|
35778
36616
|
this.openAIAgentsPlugin.disable();
|
|
35779
36617
|
this.openAIAgentsPlugin = null;
|
|
35780
36618
|
}
|
|
36619
|
+
if (this.googleGenerativeAIPlugin) {
|
|
36620
|
+
this.googleGenerativeAIPlugin.disable();
|
|
36621
|
+
this.googleGenerativeAIPlugin = null;
|
|
36622
|
+
}
|
|
35781
36623
|
if (this.googleGenAIPlugin) {
|
|
35782
36624
|
this.googleGenAIPlugin.disable();
|
|
35783
36625
|
this.googleGenAIPlugin = null;
|
|
@@ -35814,6 +36656,10 @@ var BraintrustPlugin = class extends BasePlugin {
|
|
|
35814
36656
|
this.coherePlugin.disable();
|
|
35815
36657
|
this.coherePlugin = null;
|
|
35816
36658
|
}
|
|
36659
|
+
if (this.elevenLabsPlugin) {
|
|
36660
|
+
this.elevenLabsPlugin.disable();
|
|
36661
|
+
this.elevenLabsPlugin = null;
|
|
36662
|
+
}
|
|
35817
36663
|
if (this.voyageAIPlugin) {
|
|
35818
36664
|
this.voyageAIPlugin.disable();
|
|
35819
36665
|
this.voyageAIPlugin = null;
|
|
@@ -38026,6 +38872,8 @@ var envIntegrationAliases = {
|
|
|
38026
38872
|
"openai-agents-core": "openAIAgents",
|
|
38027
38873
|
openaiagentscore: "openAIAgents",
|
|
38028
38874
|
google: "google",
|
|
38875
|
+
"google-generative-ai": "googleGenerativeAI",
|
|
38876
|
+
googlegenerativeai: "googleGenerativeAI",
|
|
38029
38877
|
"google-genai": "googleGenAI",
|
|
38030
38878
|
googlegenai: "googleGenAI",
|
|
38031
38879
|
huggingface: "huggingface",
|
|
@@ -38059,7 +38907,9 @@ var envIntegrationAliases = {
|
|
|
38059
38907
|
langsmith: "langsmith",
|
|
38060
38908
|
voyage: "voyageai",
|
|
38061
38909
|
"voyage-ai": "voyageai",
|
|
38062
|
-
voyageai: "voyageai"
|
|
38910
|
+
voyageai: "voyageai",
|
|
38911
|
+
elevenlabs: "elevenlabs",
|
|
38912
|
+
"@elevenlabs/elevenlabs-js": "elevenlabs"
|
|
38063
38913
|
};
|
|
38064
38914
|
function getDefaultInstrumentationIntegrations() {
|
|
38065
38915
|
return {
|
|
@@ -38070,6 +38920,7 @@ function getDefaultInstrumentationIntegrations() {
|
|
|
38070
38920
|
aisdk: true,
|
|
38071
38921
|
google: true,
|
|
38072
38922
|
googleGenAI: true,
|
|
38923
|
+
googleGenerativeAI: true,
|
|
38073
38924
|
googleADK: true,
|
|
38074
38925
|
huggingface: true,
|
|
38075
38926
|
claudeAgentSDK: true,
|
|
@@ -38095,6 +38946,7 @@ function getDefaultInstrumentationIntegrations() {
|
|
|
38095
38946
|
langgraph: true,
|
|
38096
38947
|
langsmith: true,
|
|
38097
38948
|
voyageai: true,
|
|
38949
|
+
elevenlabs: true,
|
|
38098
38950
|
piCodingAgent: true,
|
|
38099
38951
|
strandsAgentSDK: true,
|
|
38100
38952
|
cloudflareAgents: true
|