feat: support images in mcp tool responses (#4100)

Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Co-authored-by: rekram1-node <rekram1-node@users.noreply.github.com>
This commit is contained in:
Brian Cheung
2025-11-14 15:00:52 -06:00
committed by GitHub
parent b939470302
commit 37cf365927

View File

@@ -671,15 +671,31 @@ export namespace SessionPrompt {
result,
)
const output = result.content
.filter((x: any) => x.type === "text")
.map((x: any) => x.text)
.join("\n\n")
const textParts: string[] = []
const attachments: MessageV2.FilePart[] = []
for (const item of result.content) {
if (item.type === "text") {
textParts.push(item.text)
} else if (item.type === "image") {
attachments.push({
id: Identifier.ascending("part"),
sessionID: input.sessionID,
messageID: input.processor.message.id,
type: "file",
mime: item.mimeType,
url: `data:${item.mimeType};base64,${item.data}`,
})
}
// Add support for other types if needed
}
return {
title: "",
metadata: result.metadata ?? {},
output,
output: textParts.join("\n\n"),
attachments,
content: result.content, // directly return content to preserve ordering when outputting to model
}
}
item.toModelOutput = (result) => {