diff options
| author | Brian Cheung <[email protected]> | 2025-11-14 15:00:52 -0600 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-11-14 15:00:52 -0600 |
| commit | 37cf36592750afc0ffef08aa6a20fd64ae9d7d34 (patch) | |
| tree | c64d6d70d9ef818a85f403cbea133294ae99841f | |
| parent | b9394703026bffb984297634b7d16db3c4555def (diff) | |
| download | opencode-37cf36592750afc0ffef08aa6a20fd64ae9d7d34.tar.gz opencode-37cf36592750afc0ffef08aa6a20fd64ae9d7d34.zip | |
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 <[email protected]>
| -rw-r--r-- | packages/opencode/src/session/prompt.ts | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/packages/opencode/src/session/prompt.ts b/packages/opencode/src/session/prompt.ts index 0fb7ad226..8e27d7148 100644 --- a/packages/opencode/src/session/prompt.ts +++ b/packages/opencode/src/session/prompt.ts @@ -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) => { |
