mirror of
https://github.com/anomalyco/opencode.git
synced 2026-08-05 02:09:52 +00:00
fix(opencode): decode MCP text blobs
This commit is contained in:
parent
0ecc41c83c
commit
805a004f89
2 changed files with 41 additions and 1 deletions
|
|
@ -741,13 +741,23 @@ export const layer = Layer.effect(
|
|||
})
|
||||
} else if ("blob" in c && c.blob) {
|
||||
const mime = ("mimeType" in c ? c.mimeType : undefined) ?? part.mime
|
||||
const url = `data:${mime};base64,${c.blob}`
|
||||
if (mime === "text/plain") {
|
||||
pieces.push({
|
||||
messageID: info.id,
|
||||
sessionID: input.sessionID,
|
||||
type: "text",
|
||||
synthetic: true,
|
||||
text: decodeDataUrl(url),
|
||||
})
|
||||
}
|
||||
pieces.push({
|
||||
messageID: info.id,
|
||||
sessionID: input.sessionID,
|
||||
type: "file",
|
||||
mime,
|
||||
filename: part.filename,
|
||||
url: `data:${mime};base64,${c.blob}`,
|
||||
url,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -258,6 +258,14 @@ const resourceNoLLMServer = testEffect(
|
|||
text: "# MCP resource fixture",
|
||||
},
|
||||
]
|
||||
: uri === "opencode-fixture://text-blob"
|
||||
? [
|
||||
{
|
||||
uri,
|
||||
mimeType: "text/plain",
|
||||
blob: Buffer.from("MCP text blob fixture").toString("base64"),
|
||||
},
|
||||
]
|
||||
: [
|
||||
{
|
||||
uri,
|
||||
|
|
@ -2075,6 +2083,18 @@ resourceNoLLMServer.instance(
|
|||
text: { value: "@fixture-guide", start: 0, end: 14 },
|
||||
},
|
||||
},
|
||||
{
|
||||
type: "file",
|
||||
mime: "text/plain",
|
||||
url: "opencode-fixture://text-blob",
|
||||
filename: "fixture-text-blob",
|
||||
source: {
|
||||
type: "resource",
|
||||
clientName: "resource-only-fixture",
|
||||
uri: "opencode-fixture://text-blob",
|
||||
text: { value: "@fixture-text-blob", start: 15, end: 33 },
|
||||
},
|
||||
},
|
||||
{
|
||||
type: "file",
|
||||
mime: "image/png",
|
||||
|
|
@ -2091,6 +2111,16 @@ resourceNoLLMServer.instance(
|
|||
})
|
||||
|
||||
expect(message.parts.some((part) => part.type === "text" && part.text === "# MCP resource fixture")).toBe(true)
|
||||
expect(message.parts.some((part) => part.type === "text" && part.text === "MCP text blob fixture")).toBe(true)
|
||||
expect(
|
||||
message.parts.some(
|
||||
(part) =>
|
||||
part.type === "file" &&
|
||||
!part.source &&
|
||||
part.mime === "text/plain" &&
|
||||
part.url.startsWith("data:text/plain;base64,"),
|
||||
),
|
||||
).toBe(true)
|
||||
expect(
|
||||
message.parts.some(
|
||||
(part) => part.type === "file" && part.source?.type === "resource" && part.url === "opencode-fixture://pixel",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue