Revert "fix: ensure that tool attachments arent sent as user messages (#8944)"

This reverts commit 8fd1b92e6e.
This commit is contained in:
Aiden Cline
2026-01-16 15:49:39 -06:00
parent 6e00348bd7
commit f5a6a4af7f
3 changed files with 43 additions and 89 deletions

View File

@@ -1,35 +1,8 @@
import { describe, expect, test } from "bun:test"
import { MessageV2 } from "../../src/session/message-v2"
import type { ToolSet } from "ai"
const sessionID = "session"
// Mock tool that transforms output to content format with media support
function createMockTools(): ToolSet {
return {
bash: {
description: "mock bash tool",
inputSchema: { type: "object", properties: {} } as any,
toModelOutput(result: { output: string; attachments?: MessageV2.FilePart[] }) {
return {
type: "content" as const,
value: [
{ type: "text" as const, text: result.output },
...(result.attachments?.map((attachment) => {
const base64 = attachment.url.startsWith("data:") ? attachment.url.split(",", 2)[1] : attachment.url
return {
type: "media" as const,
data: base64,
mediaType: attachment.mime,
}
}) ?? []),
],
}
},
},
} as ToolSet
}
function userInfo(id: string): MessageV2.User {
return {
id,
@@ -286,11 +259,23 @@ describe("session.message-v2.toModelMessage", () => {
},
]
expect(MessageV2.toModelMessage(input, { tools: createMockTools() })).toStrictEqual([
expect(MessageV2.toModelMessage(input)).toStrictEqual([
{
role: "user",
content: [{ type: "text", text: "run tool" }],
},
{
role: "user",
content: [
{ type: "text", text: "Tool bash returned an attachment:" },
{
type: "file",
mediaType: "image/png",
filename: "attachment.png",
data: "https://example.com/attachment.png",
},
],
},
{
role: "assistant",
content: [
@@ -312,13 +297,7 @@ describe("session.message-v2.toModelMessage", () => {
type: "tool-result",
toolCallId: "call-1",
toolName: "bash",
output: {
type: "content",
value: [
{ type: "text", text: "ok" },
{ type: "media", data: "https://example.com/attachment.png", mediaType: "image/png" },
],
},
output: { type: "text", value: "ok" },
providerOptions: { openai: { tool: "meta" } },
},
],
@@ -362,7 +341,7 @@ describe("session.message-v2.toModelMessage", () => {
},
]
expect(MessageV2.toModelMessage(input, { tools: createMockTools() })).toStrictEqual([
expect(MessageV2.toModelMessage(input)).toStrictEqual([
{
role: "user",
content: [{ type: "text", text: "run tool" }],
@@ -386,10 +365,7 @@ describe("session.message-v2.toModelMessage", () => {
type: "tool-result",
toolCallId: "call-1",
toolName: "bash",
output: {
type: "content",
value: [{ type: "text", text: "[Old tool result content cleared]" }],
},
output: { type: "text", value: "[Old tool result content cleared]" },
},
],
},