Skip to content

Commit 887e20f

Browse files
committed
fix(llm): cover media mime aliases in tool replay
1 parent 4a92599 commit 887e20f

3 files changed

Lines changed: 38 additions & 6 deletions

File tree

src/llm/providers/tool-result-text.test.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,21 @@ describe("extractToolResultText", () => {
8282

8383

8484

85-
it("treats snake-case mime_type aliases as binary structured payloads", () => {
85+
it.each([
86+
["mime_type", { mime_type: "application/octet-stream" }],
87+
["mediaType", { mediaType: "audio/mpeg" }],
88+
["contentType", { contentType: "application/pdf" }],
89+
["content_type", { content_type: "video/mp4" }],
90+
])("treats %s aliases as binary structured payloads", (_label, alias) => {
8691
expect(
8792
extractToolResultText([
8893
{
8994
type: "resource",
90-
mime_type: "application/octet-stream",
95+
...alias,
9196
data: "binary-payload-bytes",
9297
},
9398
]),
94-
).toBe(
95-
'{"type":"resource","mime_type":"application/octet-stream","data":"[binary omitted: 20 chars]"}',
96-
);
99+
).toBe(JSON.stringify({ type: "resource", ...alias, data: "[binary omitted: 20 chars]" }));
97100
});
98101

99102
it("handles circular structured payloads without throwing", () => {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { describe, expect, it } from "vitest";
2+
3+
import { serializeStructuredToolResultBlock } from "./tool-result-serialization.js";
4+
5+
describe("serializeStructuredToolResultBlock", () => {
6+
it.each([
7+
["media_type", { media_type: "image/png" }],
8+
["mime_type", { mime_type: "application/octet-stream" }],
9+
["mimeType", { mimeType: "application/pdf" }],
10+
["mediaType", { mediaType: "audio/mpeg" }],
11+
["contentType", { contentType: "application/pdf" }],
12+
["content_type", { content_type: "video/mp4" }],
13+
])("omits binary data for %s media aliases", (_label, alias) => {
14+
expect(
15+
serializeStructuredToolResultBlock({
16+
type: "resource",
17+
...alias,
18+
data: "binary-payload-bytes",
19+
}),
20+
).toBe(JSON.stringify({ type: "resource", ...alias, data: "[binary omitted: 20 chars]" }));
21+
});
22+
});

src/logging/tool-result-serialization.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,14 @@ function carriesBinaryData(record: Record<string, unknown>): boolean {
146146
if (type === "audio" || type === "image" || type === "base64") {
147147
return true;
148148
}
149-
const mediaType = readLowercaseString(record.media_type ?? record.mime_type ?? record.mimeType);
149+
const mediaType = readLowercaseString(
150+
record.media_type ??
151+
record.mime_type ??
152+
record.mimeType ??
153+
record.mediaType ??
154+
record.contentType ??
155+
record.content_type,
156+
);
150157
return (
151158
mediaType?.startsWith("image/") === true ||
152159
mediaType?.startsWith("audio/") === true ||

0 commit comments

Comments
 (0)