fix(server): HTML and Markdown attachments no longer fail OpenCode turns (#19319)
Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
4f909be2c1
commit
c8a6768f07
2 files changed
+10
-4
No files matched your search
@@ -293,11 +293,15 @@ describe("toOpenCodeFileParts", () => {
|
||||
const parts = OpenCodeRuntime.toOpenCodeFileParts({
|
||||
attachments: [
|
||||
attachment("application/pdf"),
|
||||
attachment("text/markdown"),
|
||||
attachment("text/plain"),
|
||||
attachment("image/png"),
|
||||
// A ZIP file part makes OpenCode's Anthropic path throw before the
|
||||
// turn starts; it must ride only as the prompt's file path line.
|
||||
attachment("application/zip"),
|
||||
// OpenCode inlines only text/plain itself. Other text types reach the
|
||||
// model API as raw file parts, which Anthropic and OpenAI reject.
|
||||
attachment("text/html"),
|
||||
attachment("text/markdown"),
|
||||
attachment("application/octet-stream"),
|
||||
// Image formats the model APIs reject stay on the fallback path too.
|
||||
attachment("image/bmp"),
|
||||
@@ -310,7 +314,7 @@ describe("toOpenCodeFileParts", () => {
|
||||
|
||||
NodeAssert.deepEqual(
|
||||
parts.map((part) => part.mime),
|
||||
["application/pdf", "text/markdown", "image/png"],
|
||||
["application/pdf", "text/plain", "image/png"],
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -469,7 +469,9 @@ export function openCodeQuestionId(
|
||||
* else (ZIP, binaries, image formats like BMP/AVIF/SVG that model APIs
|
||||
* reject, or files over the direct-attachment size limit) would make the turn
|
||||
* fail before it starts, so those ride only as the file path ProviderService
|
||||
* puts in the prompt.
|
||||
* puts in the prompt. Text is native only as text/plain, which OpenCode reads
|
||||
* itself; other text types (HTML, Markdown, CSV) reach the model API as raw
|
||||
* file parts, which Anthropic and OpenAI reject.
|
||||
*/
|
||||
const OPENCODE_NATIVE_IMAGE_MIMES = new Set(["image/png", "image/jpeg", "image/gif", "image/webp"]);
|
||||
const OPENCODE_NATIVE_FILE_PART_MAX_BYTES = 20 * 1024 * 1024;
|
||||
@@ -484,7 +486,7 @@ function isOpenCodeNativeFilePart(input: {
|
||||
const normalized = input.mimeType.trim().toLowerCase();
|
||||
return (
|
||||
OPENCODE_NATIVE_IMAGE_MIMES.has(normalized) ||
|
||||
normalized.startsWith("text/") ||
|
||||
normalized === "text/plain" ||
|
||||
normalized === "application/pdf"
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user