Skip to content

Commit 3f9f99f

Browse files
committed
tool: let unsupported image mimes fall through
1 parent 2a84253 commit 3f9f99f

2 files changed

Lines changed: 13 additions & 38 deletions

File tree

packages/opencode/src/tool/read.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -222,16 +222,6 @@ export const ReadTool = Tool.define(
222222

223223
const mime = sniffAttachmentMime(sample, AppFileSystem.mimeType(filepath))
224224
const isImage = SUPPORTED_IMAGE_MIMES.has(mime)
225-
const isUnsupportedImage =
226-
!isImage && mime.startsWith("image/") && mime !== "image/svg+xml" && mime !== "image/vnd.fastbidsheet"
227-
228-
if (isUnsupportedImage) {
229-
return yield* Effect.fail(
230-
new Error(
231-
`Cannot read image: ${mime} is not a supported format. Supported image formats: JPEG, PNG, GIF, WebP.`,
232-
),
233-
)
234-
}
235225

236226
if (isImage || isPdfAttachment(mime)) {
237227
const bytes = yield* fs.readFile(filepath)

packages/opencode/test/tool/read.test.ts

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -441,36 +441,21 @@ root_type Monster;`
441441
}),
442442
)
443443

444-
it.live("rejects unsupported image formats like BMP", () =>
444+
it.live("falls through unsupported image mime types to text", () =>
445445
Effect.gen(function* () {
446446
const dir = yield* tmpdirScoped()
447-
// minimal BMP file header
448-
const bmp = Buffer.from("BM", "ascii")
449-
yield* put(path.join(dir, "image.bmp"), bmp)
450-
451-
const err = yield* fail(dir, { filePath: path.join(dir, "image.bmp") })
452-
expect(err.message).toContain("image/bmp is not a supported format")
453-
expect(err.message).toContain("JPEG, PNG, GIF, WebP")
454-
}),
455-
)
456-
457-
it.live("rejects unsupported image formats like TIFF", () =>
458-
Effect.gen(function* () {
459-
const dir = yield* tmpdirScoped()
460-
yield* put(path.join(dir, "photo.tiff"), Buffer.from("II", "ascii"))
461-
462-
const err = yield* fail(dir, { filePath: path.join(dir, "photo.tiff") })
463-
expect(err.message).toContain("is not a supported format")
464-
}),
465-
)
466-
467-
it.live("rejects unsupported image formats like AVIF", () =>
468-
Effect.gen(function* () {
469-
const dir = yield* tmpdirScoped()
470-
yield* put(path.join(dir, "photo.avif"), Buffer.from([0x00, 0x00, 0x00, 0x1c]))
471-
472-
const err = yield* fail(dir, { filePath: path.join(dir, "photo.avif") })
473-
expect(err.message).toContain("is not a supported format")
447+
const cases = [
448+
["image.bmp", "BM text content"],
449+
["photo.tiff", "II text content"],
450+
["photo.avif", "avif text content"],
451+
] as const
452+
453+
for (const item of cases) {
454+
yield* put(path.join(dir, item[0]), item[1])
455+
const result = yield* exec(dir, { filePath: path.join(dir, item[0]) })
456+
expect(result.attachments).toBeUndefined()
457+
expect(result.output).toContain(item[1])
458+
}
474459
}),
475460
)
476461
})

0 commit comments

Comments
 (0)