fix(opencode): resolve MCP resource content
This commit is contained in:
@@ -219,8 +219,13 @@ export const toModelMessagesEffect = Effect.fnUntraced(function* (
|
||||
type: "text",
|
||||
text: part.text,
|
||||
})
|
||||
// text/plain and directory files are converted into text parts, ignore them
|
||||
if (part.type === "file" && part.mime !== "text/plain" && part.mime !== "application/x-directory") {
|
||||
// Text, directories, and MCP references are resolved before provider conversion.
|
||||
if (
|
||||
part.type === "file" &&
|
||||
part.mime !== "text/plain" &&
|
||||
part.mime !== "application/x-directory" &&
|
||||
part.source?.type !== "resource"
|
||||
) {
|
||||
if (options?.stripMedia && isMedia(part.mime)) {
|
||||
userMessage.parts.push({
|
||||
type: "text",
|
||||
|
||||
@@ -728,7 +728,16 @@ export const layer = Layer.effect(
|
||||
const exit = yield* mcp.readResource(clientName, uri).pipe(Effect.exit)
|
||||
if (Exit.isSuccess(exit)) {
|
||||
const content = exit.value
|
||||
if (!content) throw new Error(`Resource not found: ${clientName}/${uri}`)
|
||||
if (!content) {
|
||||
pieces.push({
|
||||
messageID: info.id,
|
||||
sessionID: input.sessionID,
|
||||
type: "text",
|
||||
synthetic: true,
|
||||
text: `Failed to read MCP resource ${part.filename}: resource not found or could not be read`,
|
||||
})
|
||||
return pieces
|
||||
}
|
||||
const items = Array.isArray(content.contents) ? content.contents : [content.contents]
|
||||
for (const c of items) {
|
||||
if ("text" in c && c.text) {
|
||||
@@ -740,13 +749,14 @@ export const layer = Layer.effect(
|
||||
text: c.text,
|
||||
})
|
||||
} else if ("blob" in c && c.blob) {
|
||||
const mime = "mimeType" in c ? c.mimeType : part.mime
|
||||
const mime = ("mimeType" in c ? c.mimeType : undefined) ?? part.mime
|
||||
pieces.push({
|
||||
messageID: info.id,
|
||||
sessionID: input.sessionID,
|
||||
type: "text",
|
||||
synthetic: true,
|
||||
text: `[Binary content: ${mime}]`,
|
||||
type: "file",
|
||||
mime,
|
||||
filename: part.filename,
|
||||
url: `data:${mime};base64,${c.blob}`,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -992,7 +1002,7 @@ export const layer = Layer.effect(
|
||||
)
|
||||
|
||||
const parts = yield* Effect.forEach(resolvedParts, (part) =>
|
||||
part.type === "file" && part.mime.startsWith("image/")
|
||||
part.type === "file" && part.source?.type !== "resource" && part.mime.startsWith("image/")
|
||||
? image.normalize(part).pipe(
|
||||
Effect.catchIf(
|
||||
(error) => error instanceof Image.ResizerUnavailableError,
|
||||
|
||||
Reference in New Issue
Block a user