mirror of
https://github.com/anomalyco/opencode.git
synced 2026-08-11 13:43:35 +00:00
fix(opencode): normalize MCP text MIME types
This commit is contained in:
parent
805a004f89
commit
f6a00292e6
4 changed files with 12 additions and 5 deletions
|
|
@ -222,7 +222,7 @@ export const toModelMessagesEffect = Effect.fnUntraced(function* (
|
|||
// Text, directories, and MCP references are resolved before provider conversion.
|
||||
if (
|
||||
part.type === "file" &&
|
||||
part.mime !== "text/plain" &&
|
||||
part.mime.split(";")[0]?.trim().toLowerCase() !== "text/plain" &&
|
||||
part.mime !== "application/x-directory" &&
|
||||
part.source?.type !== "resource"
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -742,7 +742,7 @@ 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") {
|
||||
if (mime.split(";")[0]?.trim().toLowerCase() === "text/plain") {
|
||||
pieces.push({
|
||||
messageID: info.id,
|
||||
sessionID: input.sessionID,
|
||||
|
|
|
|||
|
|
@ -344,6 +344,13 @@ describe("session.message-v2.toModelMessage", () => {
|
|||
text: { value: "@fixture-guide", start: 0, end: 14 },
|
||||
},
|
||||
},
|
||||
{
|
||||
...basePart(messageID, "p3"),
|
||||
type: "file",
|
||||
mime: "text/plain; charset=utf-8",
|
||||
filename: "guide.txt",
|
||||
url: "data:text/plain; charset=utf-8;base64,IyBSZXNvdXJjZSBjb250ZW50cw==",
|
||||
},
|
||||
] as SessionV1.Part[],
|
||||
},
|
||||
]
|
||||
|
|
|
|||
|
|
@ -262,7 +262,7 @@ const resourceNoLLMServer = testEffect(
|
|||
? [
|
||||
{
|
||||
uri,
|
||||
mimeType: "text/plain",
|
||||
mimeType: "text/plain; charset=utf-8",
|
||||
blob: Buffer.from("MCP text blob fixture").toString("base64"),
|
||||
},
|
||||
]
|
||||
|
|
@ -2117,8 +2117,8 @@ resourceNoLLMServer.instance(
|
|||
(part) =>
|
||||
part.type === "file" &&
|
||||
!part.source &&
|
||||
part.mime === "text/plain" &&
|
||||
part.url.startsWith("data:text/plain;base64,"),
|
||||
part.mime === "text/plain; charset=utf-8" &&
|
||||
part.url.startsWith("data:text/plain; charset=utf-8;base64,"),
|
||||
),
|
||||
).toBe(true)
|
||||
expect(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue