Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/ai-sdk-v7-inline-file-attachments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"braintrust": patch
---

fix(ai-sdk): log AI SDK v7 inline file data as attachments instead of copying the bytes into the span
23 changes: 23 additions & 0 deletions js/src/instrumentation/plugins/ai-sdk-plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
BRAINTRUST_AI_SDK_V7_OPERATION_KEY as AI_SDK_V7_OPERATION_KEY,
} from "../../vendor-sdk-types/ai-sdk-v7-telemetry";
import { serializeAISDKToolsForLogging } from "../../wrappers/ai-sdk/tool-serialization";
import { Attachment } from "../../logger";
import {
AISDKPlugin,
DEFAULT_DENY_OUTPUT_PATHS,
Expand Down Expand Up @@ -221,6 +222,28 @@ describe("AISDKPlugin", () => {
expect(processed.model).not.toHaveProperty("doStream");
expect(processed.model.config).not.toHaveProperty("url");
});

it("logs AI SDK v7 inline file data as attachments", () => {
const processed = processAISDKCallInput({
prompt: [
{
role: "user",
content: [
{
type: "file",
mediaType: "image/png",
data: {
type: "data",
data: new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10]),
},
},
],
},
],
}).input as Record<string, any>;

expect(processed.prompt[0].content[0].data).toBeInstanceOf(Attachment);
});
});

describe("enable/disable", () => {
Expand Down
6 changes: 5 additions & 1 deletion js/src/instrumentation/plugins/ai-sdk-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1939,7 +1939,7 @@ const processContentPart = (part: any): any => {
(part.mimeType || part.mediaType)
) {
const fileAttachment = convertDataToAttachment(
part.data,
unwrapInlineFileData(part.data),
part.mimeType || part.mediaType,
part.name || part.filename,
);
Expand Down Expand Up @@ -1972,6 +1972,10 @@ const processContentPart = (part: any): any => {
return part;
};

// AI SDK v7 tags inline file bytes as { type: "data", data }.
const unwrapInlineFileData = (data: unknown): unknown =>
isObject(data) && data.type === "data" && "data" in data ? data.data : data;

const convertImageToAttachment = (
image: any,
explicitMimeType?: string,
Expand Down