@ai-sdk/otel 1.0.173 → 1.0.175
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/CHANGELOG.md +31 -0
- package/dist/index.d.ts +13 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +187 -139
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/gen-ai-format-messages.ts +253 -196
- package/src/index.ts +1 -0
- package/src/open-telemetry.ts +5 -23
- package/src/redact-tool-definition.ts +14 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
# @ai-sdk/otel
|
|
2
2
|
|
|
3
|
+
## 1.0.175
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- ai@7.0.175
|
|
8
|
+
|
|
9
|
+
## 1.0.174
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 71410a4: fix(otel): record `gen_ai.output.messages` parts in the order the model produced them
|
|
14
|
+
|
|
15
|
+
Output messages previously grouped parts by type (reasoning, then all text joined into one part, then tool calls), so they did not match the same assistant message in the next step's `gen_ai.input.messages`. Output parts now follow the content order, text blocks are no longer merged, and file, reasoning file, custom, tool error, and tool approval parts are emitted on both the output and input side. The root span records the content of all steps in order, including text from earlier steps. Adds `formatOutputContent` and deprecates `formatOutputMessages`.
|
|
16
|
+
|
|
17
|
+
- b0fccbd: fix(otel): redact Google MCP server credentials in tool definitions
|
|
18
|
+
|
|
19
|
+
Plain `google.mcp_server` tool definitions do not carry a provider-owned
|
|
20
|
+
telemetry redaction annotation, for example when they are built by hand or come
|
|
21
|
+
from an older `@ai-sdk/google` version. Both OTel integrations now redact every
|
|
22
|
+
`google.mcp_server` header value in telemetry-only copies, so MCP connector
|
|
23
|
+
credentials no longer reach `ai.prompt.tools` or `gen_ai.tool.definitions`.
|
|
24
|
+
|
|
25
|
+
- Updated dependencies [3bea041]
|
|
26
|
+
- Updated dependencies [30d35eb]
|
|
27
|
+
- Updated dependencies [fab7478]
|
|
28
|
+
- Updated dependencies [10ff0b1]
|
|
29
|
+
- Updated dependencies [718824c]
|
|
30
|
+
- Updated dependencies [d99098a]
|
|
31
|
+
- ai@7.0.174
|
|
32
|
+
- @ai-sdk/provider@4.0.39
|
|
33
|
+
|
|
3
34
|
## 1.0.173
|
|
4
35
|
|
|
5
36
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Attributes, Context, Link, SpanKind, TraceState, Tracer } from "@opentelemetry/api";
|
|
2
|
-
import { DurableTelemetryContext, EmbedEndEvent, EmbedStartEvent, EmbeddingModelCallEndEvent, EmbeddingModelCallStartEvent, Experimental_DecideEndEvent, Experimental_DecideStartEvent, Experimental_DecisionModelCallEndEvent, Experimental_DecisionModelCallStartEvent, Experimental_StreamTranscriptionEndEvent, Experimental_StreamTranscriptionStartEvent, GenerateObjectEndEvent, GenerateObjectStartEvent, GenerateObjectStepEndEvent, GenerateObjectStepStartEvent, GenerateSpeechEndEvent, GenerateSpeechStartEvent, GenerateTextAbortEvent, GenerateTextEndEvent, GenerateTextStartEvent, GenerateTextStepEndEvent, GenerateTextStepErrorEvent, GenerateTextStepStartEvent, InferTelemetryEvent, LanguageModelCallEndEvent, LanguageModelCallStartEvent, Output, RerankEndEvent, RerankStartEvent, RerankingModelCallEndEvent, RerankingModelCallStartEvent, Telemetry, ToolExecutionEndEvent, ToolExecutionStartEvent, ToolSet, TranscriptionEndEvent, TranscriptionStartEvent } from "ai";
|
|
3
2
|
import { APICallError, JSONValue, LanguageModelV4Prompt, SharedV4FileDataReference, SharedV4FileDataText, SharedV4FileDataUrl, SharedV4ProviderOptions, SharedV4ProviderReference } from "@ai-sdk/provider";
|
|
3
|
+
import { ContentPart, DurableTelemetryContext, EmbedEndEvent, EmbedStartEvent, EmbeddingModelCallEndEvent, EmbeddingModelCallStartEvent, Experimental_DecideEndEvent, Experimental_DecideStartEvent, Experimental_DecisionModelCallEndEvent, Experimental_DecisionModelCallStartEvent, Experimental_StreamTranscriptionEndEvent, Experimental_StreamTranscriptionStartEvent, GenerateObjectEndEvent, GenerateObjectStartEvent, GenerateObjectStepEndEvent, GenerateObjectStepStartEvent, GenerateSpeechEndEvent, GenerateSpeechStartEvent, GenerateTextAbortEvent, GenerateTextEndEvent, GenerateTextStartEvent, GenerateTextStepEndEvent, GenerateTextStepErrorEvent, GenerateTextStepStartEvent, InferTelemetryEvent, LanguageModelCallEndEvent, LanguageModelCallStartEvent, Output, RerankEndEvent, RerankStartEvent, RerankingModelCallEndEvent, RerankingModelCallStartEvent, Telemetry, ToolExecutionEndEvent, ToolExecutionStartEvent, ToolSet, TranscriptionEndEvent, TranscriptionStartEvent } from "ai";
|
|
4
4
|
//#region src/durable-span-ids.d.ts
|
|
5
5
|
/** Compatible with the OpenTelemetry SDK's Sampler interface. */
|
|
6
6
|
type Sampler = {
|
|
@@ -780,8 +780,20 @@ export declare function formatModelMessages({ prompt, messages }: {
|
|
|
780
780
|
prompt: string | Array<ModelMessage> | undefined;
|
|
781
781
|
messages: Array<ModelMessage> | undefined;
|
|
782
782
|
}): SemConvInputMessage[];
|
|
783
|
+
/**
|
|
784
|
+
* Converts content parts produced by a model call or step to the
|
|
785
|
+
* gen_ai.output.messages SemConv format.
|
|
786
|
+
* Parts are preserved in the order they were produced.
|
|
787
|
+
*/
|
|
788
|
+
export declare function formatOutputContent({ content, finishReason }: {
|
|
789
|
+
content: ReadonlyArray<ContentPart<ToolSet>>;
|
|
790
|
+
finishReason: string;
|
|
791
|
+
}): SemConvOutputMessage[];
|
|
783
792
|
/**
|
|
784
793
|
* Converts step result data to the gen_ai.output.messages SemConv format.
|
|
794
|
+
*
|
|
795
|
+
* @deprecated Use `formatOutputContent` instead. This function groups parts
|
|
796
|
+
* by type and does not preserve the order in which they were produced.
|
|
785
797
|
*/
|
|
786
798
|
export declare function formatOutputMessages({ text, reasoning, toolCalls, toolResults, files, finishReason }: {
|
|
787
799
|
text?: string;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["Context","OtelStepStartEvent","StreamTranscriptionStartEvent","StreamTranscriptionEndEvent","DecideStartEvent","DecideEndEvent","DecisionModelCallStartEvent","DecisionModelCallEndEvent","AISDKContext","StreamTranscriptionStartEvent","StreamTranscriptionEndEvent","DecideStartEvent","DecideEndEvent","DecisionModelCallStartEvent","DecisionModelCallEndEvent"],"sources":["../src/durable-span-ids.ts","../../provider-utils/dist/index.d.ts","../src/gen-ai-format-messages.ts","../src/supplemental-attributes.ts","../src/open-telemetry.ts","../src/legacy-open-telemetry.ts"],"mappings":";;;;;KAeK;EACH,aACE,eAAe,SACf,iBACA,kBACA,UAAU,UACV,YAAY,YACZ,OAAO;IAEP;IACA,aAAa;IACb,aAAa;;;;;;;;qBASJ;mBAQkB;UAPrB;EAOqB,YAAA;IAAW,UAAU;;EAElD;EAOA;EAOA,gBACK,MAAM,WAAW,2BACnB,WAAW;EAwBd;EAIA,eACE,gBACA,cACA,MAAM,UACN,YAAY,aACX;;EAsCH,QAAQ,GACN;IACE;IACA;IACA;IACA;KAEF,iBAAiB,IAChB;;;;;;;;;KCzBA,uBAAuB,aAAa,cAAc;;;;;;;;;UAS7C;EACR;EACA,MAAM;;;;;KAKH,cAAc;;;;KAId,oBAAoB;;;;;KAKpB,eAAe;;;;;;;;;;KAUf,WAAW,eAAe,cAAc,oBAAoB;;;;;;;;;KAS5D,kBAAkB;;;;;;;;;;KAUlB,oBAAoB;;;;;;UAMf;EACR;;;;EAIA;;;;;;EAMA,kBAAkB;;;;;;;;UAQV;EACR;;;;;;;;EAQA,OAAO,cAAc,MAAM;;;;;;EAM3B;;;;;;EAMA,kBAAkB;;;;;UAKV;EACR;;;;;;;;;;;EAWA,MAAM,WAAW,cAAc,MAAM;;;;EAIrC;;;;;;;;;;;;;EAaA;;;;;;EAMA,kBAAkB;;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H;EACA,SAAS;;;;;;EAMT,kBAAkB;;;;;;KAMf,4BAA4B,MAAM,WAAW,aAAa,WAAW,gBAAgB,oBAAoB,eAAe,iBAAiB;;;;;;;;;;KAUzI;EACH;EACA;;;;;;EAMA,kBAAkB;;;;;;;KAOf;EACH;;;;EAIA;;;;EAIA;;;;;;;;;;;EAWA;;;;;EAKA;;;;;;;KAOG;EACH;EACA,SAAS;;;;;;EAMT,kBAAkB;;;;;KAKf,cAAc,MAAM,iBAAiB;;;;;;KAMrC;EACH;EACA,SAAS;;;;;;EAMT,kBAAkB;;;;;KAKf,uBAAuB,MAAM,WAAW,YAAY;;;;;;;KAOpD,eAAe,qBAAqB,mBAAmB,wBAAwB;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["Context","OtelStepStartEvent","StreamTranscriptionStartEvent","StreamTranscriptionEndEvent","DecideStartEvent","DecideEndEvent","DecisionModelCallStartEvent","DecisionModelCallEndEvent","AISDKContext","StreamTranscriptionStartEvent","StreamTranscriptionEndEvent","DecideStartEvent","DecideEndEvent","DecisionModelCallStartEvent","DecisionModelCallEndEvent"],"sources":["../src/durable-span-ids.ts","../../provider-utils/dist/index.d.ts","../src/gen-ai-format-messages.ts","../src/supplemental-attributes.ts","../src/open-telemetry.ts","../src/legacy-open-telemetry.ts"],"mappings":";;;;;KAeK;EACH,aACE,eAAe,SACf,iBACA,kBACA,UAAU,UACV,YAAY,YACZ,OAAO;IAEP;IACA,aAAa;IACb,aAAa;;;;;;;;qBASJ;mBAQkB;UAPrB;EAOqB,YAAA;IAAW,UAAU;;EAElD;EAOA;EAOA,gBACK,MAAM,WAAW,2BACnB,WAAW;EAwBd;EAIA,eACE,gBACA,cACA,MAAM,UACN,YAAY,aACX;;EAsCH,QAAQ,GACN;IACE;IACA;IACA;IACA;KAEF,iBAAiB,IAChB;;;;;;;;;KCzBA,uBAAuB,aAAa,cAAc;;;;;;;;;UAS7C;EACR;EACA,MAAM;;;;;KAKH,cAAc;;;;KAId,oBAAo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,sCACE,OAAO,oBAAoBC;UAKrB;UA+CA;UA6EA;UAmCA;EA6BR,aAAa,OAAO;EA8BpB,WAAW,OAAO;UAwBV;UAkDA;EAQR,cAAc,OAAO;EA2BrB,YAAY,OAAO;UAoBX;UA8CA;EAgBR,2BACE,OAAO,oBAAoBC;EAK7B,yBAAyB,OAAOC;EAIhC,sCACE,OAAOC;EAKT,oCAAoC,OAAOC;;EAK3C,6BACE,OAAO,oBAAoBH;;EAM7B,2BAA2B,OAAOC;;EAKlC,wCACE,OAAO,oBAAoBC;;EA8B7B,sCACE,OAAO,oBAAoBC;EAqB7B,QAAQ,OAAO,uBAAuB;EAkCtC,QAAQ"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SpanKind, SpanStatusCode, TraceFlags, context, createTraceState, isSpanContextValid, metrics, trace } from "@opentelemetry/api";
|
|
2
|
+
import { APICallError, getErrorMessage } from "@ai-sdk/provider";
|
|
2
3
|
import { RetryError, convertDataContentToBase64String } from "ai";
|
|
3
|
-
import { APICallError } from "@ai-sdk/provider";
|
|
4
4
|
//#region src/durable-span-ids.ts
|
|
5
5
|
/**
|
|
6
6
|
* Instance-scoped SDK bridge for durable tracing. Pass the same instance as
|
|
@@ -192,59 +192,16 @@ function convertMessagePartToSemConv(part) {
|
|
|
192
192
|
name: part.toolName,
|
|
193
193
|
arguments: part.input
|
|
194
194
|
};
|
|
195
|
-
case "tool-result": {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
else response = output;
|
|
206
|
-
}
|
|
207
|
-
return {
|
|
208
|
-
type: "tool_call_response",
|
|
209
|
-
id: part.toolCallId ?? null,
|
|
210
|
-
response
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
case "file": {
|
|
214
|
-
const rawData = part.data;
|
|
215
|
-
const data = (() => {
|
|
216
|
-
if (typeof rawData === "object" && rawData !== null && !(rawData instanceof URL) && !(rawData instanceof Uint8Array) && !(rawData instanceof ArrayBuffer) && "type" in rawData) switch (rawData.type) {
|
|
217
|
-
case "data": return rawData.data;
|
|
218
|
-
case "url": return rawData.url;
|
|
219
|
-
case "text": return rawData.text;
|
|
220
|
-
default: return "";
|
|
221
|
-
}
|
|
222
|
-
return rawData;
|
|
223
|
-
})();
|
|
224
|
-
let content;
|
|
225
|
-
if (data instanceof Uint8Array) content = convertDataContentToBase64String(data);
|
|
226
|
-
else if (typeof data === "string") {
|
|
227
|
-
if (data.startsWith("http://") || data.startsWith("https://")) return {
|
|
228
|
-
type: "uri",
|
|
229
|
-
modality: getModality(part.mediaType),
|
|
230
|
-
mime_type: part.mediaType ?? null,
|
|
231
|
-
uri: data
|
|
232
|
-
};
|
|
233
|
-
content = data;
|
|
234
|
-
} else if (data instanceof URL) return {
|
|
235
|
-
type: "uri",
|
|
236
|
-
modality: getModality(part.mediaType),
|
|
237
|
-
mime_type: part.mediaType ?? null,
|
|
238
|
-
uri: data.toString()
|
|
239
|
-
};
|
|
240
|
-
else content = String(data);
|
|
241
|
-
return {
|
|
242
|
-
type: "blob",
|
|
243
|
-
modality: getModality(part.mediaType),
|
|
244
|
-
mime_type: part.mediaType ?? null,
|
|
245
|
-
content
|
|
246
|
-
};
|
|
247
|
-
}
|
|
195
|
+
case "tool-result": return {
|
|
196
|
+
type: "tool_call_response",
|
|
197
|
+
id: part.toolCallId ?? null,
|
|
198
|
+
response: convertToolResultOutputToResponse(part.output)
|
|
199
|
+
};
|
|
200
|
+
case "file":
|
|
201
|
+
case "reasoning-file": return convertFileDataToSemConv({
|
|
202
|
+
data: part.data,
|
|
203
|
+
mediaType: part.mediaType
|
|
204
|
+
});
|
|
248
205
|
case "tool-approval-response": return {
|
|
249
206
|
type: "tool_approval_response",
|
|
250
207
|
approval_id: part.approvalId,
|
|
@@ -255,10 +212,50 @@ function convertMessagePartToSemConv(part) {
|
|
|
255
212
|
type: "custom",
|
|
256
213
|
kind: part.kind
|
|
257
214
|
};
|
|
258
|
-
case "reasoning-file": return { type: String(part.type) };
|
|
259
215
|
default: return { type: String(part.type) };
|
|
260
216
|
}
|
|
261
217
|
}
|
|
218
|
+
function convertToolResultOutputToResponse(output) {
|
|
219
|
+
if (output == null || typeof output !== "object" || !("type" in output)) return output;
|
|
220
|
+
const typedOutput = output;
|
|
221
|
+
switch (typedOutput.type) {
|
|
222
|
+
case "text":
|
|
223
|
+
case "error-text":
|
|
224
|
+
case "json":
|
|
225
|
+
case "error-json": return typedOutput.value;
|
|
226
|
+
case "execution-denied": return {
|
|
227
|
+
denied: true,
|
|
228
|
+
reason: typedOutput.reason
|
|
229
|
+
};
|
|
230
|
+
default: return output;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
function convertFileDataToSemConv({ data: rawData, mediaType }) {
|
|
234
|
+
const data = (() => {
|
|
235
|
+
if (typeof rawData === "object" && rawData !== null && !(rawData instanceof URL) && !(rawData instanceof Uint8Array) && !(rawData instanceof ArrayBuffer) && "type" in rawData) {
|
|
236
|
+
const fileData = rawData;
|
|
237
|
+
switch (fileData.type) {
|
|
238
|
+
case "data": return fileData.data;
|
|
239
|
+
case "url": return fileData.url;
|
|
240
|
+
case "text": return fileData.text;
|
|
241
|
+
default: return "";
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return rawData;
|
|
245
|
+
})();
|
|
246
|
+
if (data instanceof URL || typeof data === "string" && (data.startsWith("http://") || data.startsWith("https://"))) return {
|
|
247
|
+
type: "uri",
|
|
248
|
+
modality: getModality(mediaType),
|
|
249
|
+
mime_type: mediaType ?? null,
|
|
250
|
+
uri: data.toString()
|
|
251
|
+
};
|
|
252
|
+
return {
|
|
253
|
+
type: "blob",
|
|
254
|
+
modality: getModality(mediaType),
|
|
255
|
+
mime_type: mediaType ?? null,
|
|
256
|
+
content: convertDataContentToBase64String(data)
|
|
257
|
+
};
|
|
258
|
+
}
|
|
262
259
|
function getModality(mediaType) {
|
|
263
260
|
if (!mediaType) return "image";
|
|
264
261
|
if (mediaType.startsWith("image/")) return "image";
|
|
@@ -362,44 +359,10 @@ function convertModelMessageToSemConv(msg) {
|
|
|
362
359
|
content: convertDataContentToBase64String(data)
|
|
363
360
|
};
|
|
364
361
|
}
|
|
365
|
-
case "file": {
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
case "data": return rawData.data;
|
|
370
|
-
case "url": return rawData.url;
|
|
371
|
-
case "text": return rawData.text;
|
|
372
|
-
default: return "";
|
|
373
|
-
}
|
|
374
|
-
return rawData;
|
|
375
|
-
})();
|
|
376
|
-
if (data instanceof URL) return {
|
|
377
|
-
type: "uri",
|
|
378
|
-
modality: getModality(part.mediaType),
|
|
379
|
-
mime_type: part.mediaType ?? null,
|
|
380
|
-
uri: data.toString()
|
|
381
|
-
};
|
|
382
|
-
if (typeof data === "string") {
|
|
383
|
-
if (data.startsWith("http://") || data.startsWith("https://")) return {
|
|
384
|
-
type: "uri",
|
|
385
|
-
modality: getModality(part.mediaType),
|
|
386
|
-
mime_type: part.mediaType ?? null,
|
|
387
|
-
uri: data
|
|
388
|
-
};
|
|
389
|
-
return {
|
|
390
|
-
type: "blob",
|
|
391
|
-
modality: getModality(part.mediaType),
|
|
392
|
-
mime_type: part.mediaType ?? null,
|
|
393
|
-
content: data
|
|
394
|
-
};
|
|
395
|
-
}
|
|
396
|
-
return {
|
|
397
|
-
type: "blob",
|
|
398
|
-
modality: getModality(part.mediaType),
|
|
399
|
-
mime_type: part.mediaType ?? null,
|
|
400
|
-
content: convertDataContentToBase64String(data)
|
|
401
|
-
};
|
|
402
|
-
}
|
|
362
|
+
case "file": return convertFileDataToSemConv({
|
|
363
|
+
data: part.data,
|
|
364
|
+
mediaType: part.mediaType
|
|
365
|
+
});
|
|
403
366
|
default: return { type: String(part.type) };
|
|
404
367
|
}
|
|
405
368
|
})
|
|
@@ -425,30 +388,32 @@ function convertModelMessageToSemConv(msg) {
|
|
|
425
388
|
type: "reasoning",
|
|
426
389
|
content: part.text
|
|
427
390
|
};
|
|
391
|
+
case "file":
|
|
392
|
+
case "reasoning-file": return convertFileDataToSemConv({
|
|
393
|
+
data: part.data,
|
|
394
|
+
mediaType: part.mediaType
|
|
395
|
+
});
|
|
396
|
+
case "custom": return {
|
|
397
|
+
type: "custom",
|
|
398
|
+
kind: part.kind
|
|
399
|
+
};
|
|
428
400
|
case "tool-call": return {
|
|
429
401
|
type: "tool_call",
|
|
430
402
|
id: part.toolCallId ?? null,
|
|
431
403
|
name: part.toolName,
|
|
432
404
|
arguments: part.input
|
|
433
405
|
};
|
|
434
|
-
case "tool-result": {
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
}
|
|
446
|
-
return {
|
|
447
|
-
type: "tool_call_response",
|
|
448
|
-
id: part.toolCallId ?? null,
|
|
449
|
-
response
|
|
450
|
-
};
|
|
451
|
-
}
|
|
406
|
+
case "tool-result": return {
|
|
407
|
+
type: "tool_call_response",
|
|
408
|
+
id: part.toolCallId ?? null,
|
|
409
|
+
response: convertToolResultOutputToResponse(part.output)
|
|
410
|
+
};
|
|
411
|
+
case "tool-approval-request": return {
|
|
412
|
+
type: "tool_approval_request",
|
|
413
|
+
approval_id: part.approvalId,
|
|
414
|
+
tool_call_id: part.toolCallId,
|
|
415
|
+
reason: part.reason
|
|
416
|
+
};
|
|
452
417
|
default: return { type: String(part.type) };
|
|
453
418
|
}
|
|
454
419
|
})
|
|
@@ -457,31 +422,112 @@ function convertModelMessageToSemConv(msg) {
|
|
|
457
422
|
if (msg.role === "tool") return {
|
|
458
423
|
role: "tool",
|
|
459
424
|
parts: msg.content.map((part) => {
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
let response;
|
|
463
|
-
if (output) {
|
|
464
|
-
if (output.type === "text" || output.type === "error-text") response = output.value;
|
|
465
|
-
else if (output.type === "json" || output.type === "error-json") response = output.value;
|
|
466
|
-
else if (output.type === "execution-denied") response = {
|
|
467
|
-
denied: true,
|
|
468
|
-
reason: output.reason
|
|
469
|
-
};
|
|
470
|
-
else response = output;
|
|
471
|
-
}
|
|
472
|
-
return {
|
|
425
|
+
switch (part.type) {
|
|
426
|
+
case "tool-result": return {
|
|
473
427
|
type: "tool_call_response",
|
|
474
428
|
id: part.toolCallId ?? null,
|
|
475
|
-
response
|
|
429
|
+
response: convertToolResultOutputToResponse(part.output)
|
|
430
|
+
};
|
|
431
|
+
case "tool-approval-response": return {
|
|
432
|
+
type: "tool_approval_response",
|
|
433
|
+
approval_id: part.approvalId,
|
|
434
|
+
approved: part.approved,
|
|
435
|
+
reason: part.reason
|
|
476
436
|
};
|
|
437
|
+
default: return { type: String(part.type) };
|
|
477
438
|
}
|
|
478
|
-
return { type: String(part.type) };
|
|
479
439
|
})
|
|
480
440
|
};
|
|
481
441
|
return msg;
|
|
482
442
|
}
|
|
483
443
|
/**
|
|
444
|
+
* Converts content parts produced by a model call or step to the
|
|
445
|
+
* gen_ai.output.messages SemConv format.
|
|
446
|
+
* Parts are preserved in the order they were produced.
|
|
447
|
+
*/
|
|
448
|
+
function formatOutputContent({ content, finishReason }) {
|
|
449
|
+
const parts = [];
|
|
450
|
+
for (const part of content) switch (part.type) {
|
|
451
|
+
case "text":
|
|
452
|
+
if (part.text.length > 0 || part.providerMetadata != null) parts.push({
|
|
453
|
+
type: "text",
|
|
454
|
+
content: part.text
|
|
455
|
+
});
|
|
456
|
+
break;
|
|
457
|
+
case "reasoning":
|
|
458
|
+
parts.push({
|
|
459
|
+
type: "reasoning",
|
|
460
|
+
content: part.text
|
|
461
|
+
});
|
|
462
|
+
break;
|
|
463
|
+
case "file":
|
|
464
|
+
case "reasoning-file":
|
|
465
|
+
parts.push(convertFileDataToSemConv({
|
|
466
|
+
data: part.file.base64,
|
|
467
|
+
mediaType: part.file.mediaType
|
|
468
|
+
}));
|
|
469
|
+
break;
|
|
470
|
+
case "custom":
|
|
471
|
+
parts.push({
|
|
472
|
+
type: "custom",
|
|
473
|
+
kind: part.kind
|
|
474
|
+
});
|
|
475
|
+
break;
|
|
476
|
+
case "tool-call":
|
|
477
|
+
parts.push({
|
|
478
|
+
type: "tool_call",
|
|
479
|
+
id: part.toolCallId,
|
|
480
|
+
name: part.toolName,
|
|
481
|
+
arguments: part.input
|
|
482
|
+
});
|
|
483
|
+
break;
|
|
484
|
+
case "tool-result":
|
|
485
|
+
parts.push({
|
|
486
|
+
type: "tool_call_response",
|
|
487
|
+
id: part.toolCallId,
|
|
488
|
+
response: part.output
|
|
489
|
+
});
|
|
490
|
+
break;
|
|
491
|
+
case "tool-error":
|
|
492
|
+
parts.push({
|
|
493
|
+
type: "tool_call_response",
|
|
494
|
+
id: part.toolCallId,
|
|
495
|
+
response: part.providerExecuted ? part.error : getErrorMessage(part.error)
|
|
496
|
+
});
|
|
497
|
+
break;
|
|
498
|
+
case "tool-approval-request":
|
|
499
|
+
parts.push({
|
|
500
|
+
type: "tool_approval_request",
|
|
501
|
+
approval_id: part.approvalId,
|
|
502
|
+
tool_call_id: part.toolCall.toolCallId,
|
|
503
|
+
reason: part.reason
|
|
504
|
+
});
|
|
505
|
+
break;
|
|
506
|
+
case "tool-approval-response":
|
|
507
|
+
parts.push({
|
|
508
|
+
type: "tool_approval_response",
|
|
509
|
+
approval_id: part.approvalId,
|
|
510
|
+
approved: part.approved,
|
|
511
|
+
reason: part.reason
|
|
512
|
+
});
|
|
513
|
+
break;
|
|
514
|
+
case "source": break;
|
|
515
|
+
default: {
|
|
516
|
+
const _exhaustive = part;
|
|
517
|
+
parts.push({ type: String(_exhaustive.type) });
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
return [{
|
|
521
|
+
role: "assistant",
|
|
522
|
+
parts,
|
|
523
|
+
finish_reason: mapFinishReason(finishReason)
|
|
524
|
+
}];
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
484
527
|
* Converts step result data to the gen_ai.output.messages SemConv format.
|
|
528
|
+
*
|
|
529
|
+
* @deprecated Use `formatOutputContent` instead. This function groups parts
|
|
530
|
+
* by type and does not preserve the order in which they were produced.
|
|
485
531
|
*/
|
|
486
532
|
function formatOutputMessages({ text, reasoning, toolCalls, toolResults, files, finishReason }) {
|
|
487
533
|
const parts = [];
|
|
@@ -561,6 +607,16 @@ function redactToolDefinition(tool) {
|
|
|
561
607
|
...isRecord(args.headers) ? { headers: Object.fromEntries(Object.keys(args.headers).map((name) => [name, "[redacted]"])) } : {}
|
|
562
608
|
}
|
|
563
609
|
};
|
|
610
|
+
if (tool.id === "google.mcp_server") {
|
|
611
|
+
if (!isRecord(args.headers)) return tool;
|
|
612
|
+
return {
|
|
613
|
+
...tool,
|
|
614
|
+
args: {
|
|
615
|
+
...args,
|
|
616
|
+
headers: Object.fromEntries(Object.keys(args.headers).map((name) => [name, "[redacted]"]))
|
|
617
|
+
}
|
|
618
|
+
};
|
|
619
|
+
}
|
|
564
620
|
const containerKey = tool.id === "openai.code_interpreter" ? "container" : tool.id === "openai.shell" ? "environment" : void 0;
|
|
565
621
|
if (containerKey == null) return tool;
|
|
566
622
|
const container = args[containerKey];
|
|
@@ -1496,12 +1552,8 @@ var OpenTelemetry = class {
|
|
|
1496
1552
|
"gen_ai.usage.output_tokens": event.usage.outputTokens,
|
|
1497
1553
|
"gen_ai.usage.cache_read.input_tokens": event.usage.inputTokenDetails?.cacheReadTokens,
|
|
1498
1554
|
"gen_ai.usage.cache_creation.input_tokens": event.usage.inputTokenDetails?.cacheWriteTokens,
|
|
1499
|
-
"gen_ai.output.messages": { output: () => JSON.stringify(
|
|
1500
|
-
|
|
1501
|
-
reasoning: event.content.filter((p) => p.type === "reasoning"),
|
|
1502
|
-
toolCalls: event.content.filter((p) => p.type === "tool-call"),
|
|
1503
|
-
toolResults: event.content.filter((p) => p.type === "tool-result"),
|
|
1504
|
-
files: event.content.filter((p) => p.type === "file").map((p) => p.file),
|
|
1555
|
+
"gen_ai.output.messages": { output: () => JSON.stringify(formatOutputContent({
|
|
1556
|
+
content: event.content,
|
|
1505
1557
|
finishReason: event.finishReason
|
|
1506
1558
|
})) },
|
|
1507
1559
|
"gen_ai.tool.definitions": hasObservedProviderTools ? { input: () => JSON.stringify(toolDefinitions) } : void 0,
|
|
@@ -1778,12 +1830,8 @@ var OpenTelemetry = class {
|
|
|
1778
1830
|
"gen_ai.usage.output_tokens": event.usage.outputTokens,
|
|
1779
1831
|
"gen_ai.usage.cache_read.input_tokens": event.usage.inputTokenDetails?.cacheReadTokens,
|
|
1780
1832
|
"gen_ai.usage.cache_creation.input_tokens": event.usage.inputTokenDetails?.cacheWriteTokens,
|
|
1781
|
-
"gen_ai.output.messages": { output: () => JSON.stringify(
|
|
1782
|
-
|
|
1783
|
-
reasoning: event.finalStep.reasoning,
|
|
1784
|
-
toolCalls: event.toolCalls,
|
|
1785
|
-
toolResults: event.toolResults,
|
|
1786
|
-
files: event.files,
|
|
1833
|
+
"gen_ai.output.messages": { output: () => JSON.stringify(formatOutputContent({
|
|
1834
|
+
content: event.content,
|
|
1787
1835
|
finishReason: event.finishReason
|
|
1788
1836
|
})) },
|
|
1789
1837
|
...selectSupplementalAttributes(telemetry, this.supplementalAttributes, {
|
|
@@ -3073,6 +3121,6 @@ var LegacyOpenTelemetry = class {
|
|
|
3073
3121
|
}
|
|
3074
3122
|
};
|
|
3075
3123
|
//#endregion
|
|
3076
|
-
export { LegacyOpenTelemetry, OpenTelemetry, OpenTelemetryIdGenerator, formatInputMessages, formatModelMessages, formatObjectOutputMessages, formatOutputMessages, formatSystemInstructions };
|
|
3124
|
+
export { LegacyOpenTelemetry, OpenTelemetry, OpenTelemetryIdGenerator, formatInputMessages, formatModelMessages, formatObjectOutputMessages, formatOutputContent, formatOutputMessages, formatSystemInstructions };
|
|
3077
3125
|
|
|
3078
3126
|
//# sourceMappingURL=index.js.map
|