fix(opencode): omit unsupported MCP blobs
This commit is contained in:
parent
f6a00292e6
commit
08609209bb
3 changed files with 64 additions and 1 deletions
|
|
@ -742,7 +742,8 @@ export const layer = Layer.effect(
|
||||||
} else if ("blob" in c && c.blob) {
|
} else if ("blob" in c && c.blob) {
|
||||||
const mime = ("mimeType" in c ? c.mimeType : undefined) ?? part.mime
|
const mime = ("mimeType" in c ? c.mimeType : undefined) ?? part.mime
|
||||||
const url = `data:${mime};base64,${c.blob}`
|
const url = `data:${mime};base64,${c.blob}`
|
||||||
if (mime.split(";")[0]?.trim().toLowerCase() === "text/plain") {
|
const mediaType = mime.split(";")[0]?.trim().toLowerCase()
|
||||||
|
if (mediaType === "text/plain") {
|
||||||
pieces.push({
|
pieces.push({
|
||||||
messageID: info.id,
|
messageID: info.id,
|
||||||
sessionID: input.sessionID,
|
sessionID: input.sessionID,
|
||||||
|
|
@ -751,6 +752,20 @@ export const layer = Layer.effect(
|
||||||
text: decodeDataUrl(url),
|
text: decodeDataUrl(url),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
const supported =
|
||||||
|
mediaType?.startsWith("image/") ||
|
||||||
|
mediaType?.startsWith("audio/") ||
|
||||||
|
mediaType?.startsWith("video/") ||
|
||||||
|
mediaType === "application/pdf"
|
||||||
|
if (mediaType !== "text/plain" && !supported) {
|
||||||
|
pieces.push({
|
||||||
|
messageID: info.id,
|
||||||
|
sessionID: input.sessionID,
|
||||||
|
type: "text",
|
||||||
|
synthetic: true,
|
||||||
|
text: `[Binary content: ${mime}]`,
|
||||||
|
})
|
||||||
|
}
|
||||||
pieces.push({
|
pieces.push({
|
||||||
messageID: info.id,
|
messageID: info.id,
|
||||||
sessionID: input.sessionID,
|
sessionID: input.sessionID,
|
||||||
|
|
@ -758,6 +773,7 @@ export const layer = Layer.effect(
|
||||||
mime,
|
mime,
|
||||||
filename: part.filename,
|
filename: part.filename,
|
||||||
url,
|
url,
|
||||||
|
source: supported || mediaType === "text/plain" ? undefined : part.source,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -351,6 +351,19 @@ describe("session.message-v2.toModelMessage", () => {
|
||||||
filename: "guide.txt",
|
filename: "guide.txt",
|
||||||
url: "data:text/plain; charset=utf-8;base64,IyBSZXNvdXJjZSBjb250ZW50cw==",
|
url: "data:text/plain; charset=utf-8;base64,IyBSZXNvdXJjZSBjb250ZW50cw==",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
...basePart(messageID, "p4"),
|
||||||
|
type: "file",
|
||||||
|
mime: "application/octet-stream",
|
||||||
|
filename: "resource.bin",
|
||||||
|
url: "data:application/octet-stream;base64,AAEC",
|
||||||
|
source: {
|
||||||
|
type: "resource",
|
||||||
|
clientName: "resource-only-fixture",
|
||||||
|
uri: "opencode-fixture://binary",
|
||||||
|
text: { value: "@fixture-binary", start: 15, end: 30 },
|
||||||
|
},
|
||||||
|
},
|
||||||
] as SessionV1.Part[],
|
] as SessionV1.Part[],
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -266,6 +266,14 @@ const resourceNoLLMServer = testEffect(
|
||||||
blob: Buffer.from("MCP text blob fixture").toString("base64"),
|
blob: Buffer.from("MCP text blob fixture").toString("base64"),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
: uri === "opencode-fixture://binary"
|
||||||
|
? [
|
||||||
|
{
|
||||||
|
uri,
|
||||||
|
mimeType: "application/octet-stream",
|
||||||
|
blob: "AAEC",
|
||||||
|
},
|
||||||
|
]
|
||||||
: [
|
: [
|
||||||
{
|
{
|
||||||
uri,
|
uri,
|
||||||
|
|
@ -2095,6 +2103,18 @@ resourceNoLLMServer.instance(
|
||||||
text: { value: "@fixture-text-blob", start: 15, end: 33 },
|
text: { value: "@fixture-text-blob", start: 15, end: 33 },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
type: "file",
|
||||||
|
mime: "application/octet-stream",
|
||||||
|
url: "opencode-fixture://binary",
|
||||||
|
filename: "fixture-binary",
|
||||||
|
source: {
|
||||||
|
type: "resource",
|
||||||
|
clientName: "resource-only-fixture",
|
||||||
|
uri: "opencode-fixture://binary",
|
||||||
|
text: { value: "@fixture-binary", start: 34, end: 49 },
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
type: "file",
|
type: "file",
|
||||||
mime: "image/png",
|
mime: "image/png",
|
||||||
|
|
@ -2112,6 +2132,11 @@ 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 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 === "text" && part.text === "MCP text blob fixture")).toBe(true)
|
||||||
|
expect(
|
||||||
|
message.parts.some(
|
||||||
|
(part) => part.type === "text" && part.text === "[Binary content: application/octet-stream]",
|
||||||
|
),
|
||||||
|
).toBe(true)
|
||||||
expect(
|
expect(
|
||||||
message.parts.some(
|
message.parts.some(
|
||||||
(part) =>
|
(part) =>
|
||||||
|
|
@ -2121,6 +2146,15 @@ resourceNoLLMServer.instance(
|
||||||
part.url.startsWith("data:text/plain; charset=utf-8;base64,"),
|
part.url.startsWith("data:text/plain; charset=utf-8;base64,"),
|
||||||
),
|
),
|
||||||
).toBe(true)
|
).toBe(true)
|
||||||
|
expect(
|
||||||
|
message.parts.some(
|
||||||
|
(part) =>
|
||||||
|
part.type === "file" &&
|
||||||
|
part.source?.type === "resource" &&
|
||||||
|
part.mime === "application/octet-stream" &&
|
||||||
|
part.url.startsWith("data:application/octet-stream;base64,"),
|
||||||
|
),
|
||||||
|
).toBe(true)
|
||||||
expect(
|
expect(
|
||||||
message.parts.some(
|
message.parts.some(
|
||||||
(part) => part.type === "file" && part.source?.type === "resource" && part.url === "opencode-fixture://pixel",
|
(part) => part.type === "file" && part.source?.type === "resource" && part.url === "opencode-fixture://pixel",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue