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

This commit is contained in:
Aiden Cline
2026-01-16 10:47:43 -08:00
committed by GitHub
parent 22e3240296
commit 8fd1b92e6e
3 changed files with 89 additions and 43 deletions

View File

@@ -597,7 +597,7 @@ export namespace SessionPrompt {
sessionID,
system: [...(await SystemPrompt.environment()), ...(await SystemPrompt.custom())],
messages: [
...MessageV2.toModelMessage(sessionMessages),
...MessageV2.toModelMessage(sessionMessages, { tools }),
...(isLastStep
? [
{
@@ -718,8 +718,22 @@ export namespace SessionPrompt {
},
toModelOutput(result) {
return {
type: "text",
value: result.output,
type: "content",
value: [
{
type: "text",
text: result.output,
},
...(result.attachments?.map((attachment: MessageV2.FilePart) => {
const base64 = attachment.url.startsWith("data:") ? attachment.url.split(",", 2)[1] : attachment.url
return {
type: "media",
data: base64,
mediaType: attachment.mime,
}
}) ?? []),
],
}
},
})
@@ -808,8 +822,22 @@ export namespace SessionPrompt {
}
item.toModelOutput = (result) => {
return {
type: "text",
value: result.output,
type: "content",
value: [
{
type: "text",
text: result.output,
},
...(result.attachments?.map((attachment: MessageV2.FilePart) => {
const base64 = attachment.url.startsWith("data:") ? attachment.url.split(",", 2)[1] : attachment.url
return {
type: "media",
data: base64,
mediaType: attachment.mime,
}
}) ?? []),
],
}
}
tools[key] = item