@@ -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`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user