fix(coding-agent): process BMP images from disk

closes #6047
This commit is contained in:
Armin Ronacher
2026-06-25 12:51:21 +02:00
parent 6ca7ba7c05
commit 4cc339f58d
9 changed files with 329 additions and 67 deletions
+13 -25
View File
@@ -7,7 +7,7 @@ import type { ImageContent } from "@earendil-works/pi-ai";
import chalk from "chalk";
import { resolve } from "path";
import { resolveReadPath } from "../core/tools/path-utils.ts";
import { formatDimensionNote, resizeImage } from "../utils/image-resize.ts";
import { processImage } from "../utils/image-process.ts";
import { detectSupportedImageMimeTypeFromFile } from "../utils/mime.ts";
export interface ProcessedFiles {
@@ -50,35 +50,23 @@ export async function processFileArguments(fileArgs: string[], options?: Process
if (mimeType) {
// Handle image file
const content = await readFile(absolutePath);
const processed = await processImage(content, mimeType, { autoResizeImages });
let attachment: ImageContent;
let dimensionNote: string | undefined;
if (autoResizeImages) {
const resized = await resizeImage(content, mimeType);
if (!resized) {
text += `<file name="${absolutePath}">[Image omitted: could not be resized below the inline image size limit.]</file>\n`;
continue;
}
dimensionNote = formatDimensionNote(resized);
attachment = {
type: "image",
mimeType: resized.mimeType,
data: resized.data,
};
} else {
attachment = {
type: "image",
mimeType,
data: content.toString("base64"),
};
if (!processed.ok) {
text += `<file name="${absolutePath}">${processed.message}</file>\n`;
continue;
}
const attachment: ImageContent = {
type: "image",
mimeType: processed.mimeType,
data: processed.data,
};
images.push(attachment);
// Add text reference to image with optional dimension note
if (dimensionNote) {
text += `<file name="${absolutePath}">${dimensionNote}</file>\n`;
// Add text reference to image with optional processing hints
if (processed.hints.length > 0) {
text += `<file name="${absolutePath}">${processed.hints.join("\n")}</file>\n`;
} else {
text += `<file name="${absolutePath}"></file>\n`;
}