From 1ce773c2884cb057407138308ebf2a0ef654411e Mon Sep 17 00:00:00 2001 From: chuikingshek Date: Mon, 13 Apr 2026 15:03:55 +0800 Subject: [PATCH 1/3] fix(opencode): fix the read tool reports image/pdf read successfully when the LLM lacks vision capabilities --- packages/opencode/src/tool/read.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/packages/opencode/src/tool/read.ts b/packages/opencode/src/tool/read.ts index 501a8c97ed3f..b1a9255c65da 100644 --- a/packages/opencode/src/tool/read.ts +++ b/packages/opencode/src/tool/read.ts @@ -12,6 +12,7 @@ import DESCRIPTION from "./read.txt" import { Instance } from "../project/instance" import { assertExternalDirectoryEffect } from "./external-directory" import { Instruction } from "../session/instruction" +import type { Provider } from "../provider/provider" const DEFAULT_READ_LIMIT = 2000 const MAX_LINE_LENGTH = 2000 @@ -149,7 +150,35 @@ export const ReadTool = Tool.define( const isImage = mime.startsWith("image/") && mime !== "image/svg+xml" && mime !== "image/vnd.fastbidsheet" const isPdf = mime === "application/pdf" if (isImage || isPdf) { + const model = ctx.extra?.model as Provider.Model | undefined + const supportsVision = model?.capabilities.input.image ?? false + const supportsPdf = model?.capabilities.input.pdf ?? false const msg = `${isImage ? "Image" : "PDF"} read successfully` + + if (isImage && !supportsVision) { + return { + title, + output: `This model does not support image input. Image file: ${filepath}`, + metadata: { + preview: `Image file skipped (model does not support image input): ${filepath}`, + truncated: false, + loaded: loaded.map((item) => item.filepath), + }, + } + } + + if (isPdf && !supportsPdf) { + return { + title, + output: `This model does not support PDF input. PDF file: ${filepath}`, + metadata: { + preview: `PDF file skipped (model does not support PDF input): ${filepath}`, + truncated: false, + loaded: loaded.map((item) => item.filepath), + }, + } + } + return { title, output: msg, From c75d991ce7fa51dfbd2ad6a59574670f31b5768d Mon Sep 17 00:00:00 2001 From: chuikingshek Date: Mon, 13 Apr 2026 15:32:07 +0800 Subject: [PATCH 2/3] fix(opencode): fix the read tool reports image/pdf read successfully when the LLM lacks vision capabilities (Effect.fail) --- packages/opencode/src/tool/read.ts | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/packages/opencode/src/tool/read.ts b/packages/opencode/src/tool/read.ts index b1a9255c65da..a364bc199ca6 100644 --- a/packages/opencode/src/tool/read.ts +++ b/packages/opencode/src/tool/read.ts @@ -155,28 +155,8 @@ export const ReadTool = Tool.define( const supportsPdf = model?.capabilities.input.pdf ?? false const msg = `${isImage ? "Image" : "PDF"} read successfully` - if (isImage && !supportsVision) { - return { - title, - output: `This model does not support image input. Image file: ${filepath}`, - metadata: { - preview: `Image file skipped (model does not support image input): ${filepath}`, - truncated: false, - loaded: loaded.map((item) => item.filepath), - }, - } - } - - if (isPdf && !supportsPdf) { - return { - title, - output: `This model does not support PDF input. PDF file: ${filepath}`, - metadata: { - preview: `PDF file skipped (model does not support PDF input): ${filepath}`, - truncated: false, - loaded: loaded.map((item) => item.filepath), - }, - } + if ((isImage && !supportsVision) || (isPdf && !supportsPdf)) { + return yield* Effect.fail(new Error(`This model does not support ${isImage ? "image" : "pdf"} input`)) } return { From d3d652bc961ef3aee3b2aad77efec6a139967909 Mon Sep 17 00:00:00 2001 From: chuikingshek Date: Mon, 13 Apr 2026 15:35:13 +0800 Subject: [PATCH 3/3] fix(opencode): fix the read tool reports image/pdf read successfully when the LLM lacks vision capabilities (update error message) --- packages/opencode/src/tool/read.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/opencode/src/tool/read.ts b/packages/opencode/src/tool/read.ts index a364bc199ca6..cb406c9c6337 100644 --- a/packages/opencode/src/tool/read.ts +++ b/packages/opencode/src/tool/read.ts @@ -156,7 +156,7 @@ export const ReadTool = Tool.define( const msg = `${isImage ? "Image" : "PDF"} read successfully` if ((isImage && !supportsVision) || (isPdf && !supportsPdf)) { - return yield* Effect.fail(new Error(`This model does not support ${isImage ? "image" : "pdf"} input`)) + return yield* Effect.fail(new Error(`This model does not support ${isImage ? "image" : "pdf"} input, please try other tools`)) } return {