fix(media-understanding): normalize HEIC before image descriptions

This commit is contained in:
clawsweeper
2026-05-25 12:58:32 +00:00
parent 2a096f3d63
commit ed34620bd7
2 changed files with 6 additions and 6 deletions

View File

@@ -1,11 +1,11 @@
import { extractImageContentFromSource } from "../media/input-files.js";
import { extractImageContentFromSource, normalizeMimeType } from "../media/input-files.js";
import { DEFAULT_MAX_BYTES } from "./defaults.constants.js";
const HEIC_MIME_RE = /^image\/hei[cf]$/i;
const HEIC_EXT_RE = /\.(heic|heif)$/i;
function isHeicInput(params: { mime?: string; fileName?: string }): boolean {
const mime = params.mime?.trim();
const mime = normalizeMimeType(params.mime);
if (mime && HEIC_MIME_RE.test(mime)) {
return true;
}
@@ -22,7 +22,7 @@ export async function normalizeImageDescriptionInput(params: {
if (!isHeicInput(params)) {
return { buffer: params.buffer, mime: params.mime };
}
const sourceMime = params.mime?.trim() || "image/heic";
const sourceMime = normalizeMimeType(params.mime) ?? "image/heic";
const image = await extractImageContentFromSource(
{
type: "base64",

View File

@@ -476,8 +476,8 @@ describe("media-understanding runtime", () => {
mocks.readLocalFileSafely.mockResolvedValue({ buffer: Buffer.from("heic-source") });
await describeImageFileWithModel({
filePath: "/tmp/sample.heic",
mime: "image/heic",
filePath: "/tmp/sample.bin",
mime: "image/heic; charset=binary",
provider: "zai",
model: "glm-4.6v",
prompt: "Describe it",
@@ -489,7 +489,7 @@ describe("media-understanding runtime", () => {
expect(mocks.describeImageWithModel).toHaveBeenCalledWith(
expect.objectContaining({
buffer: Buffer.from("jpeg-normalized"),
fileName: "sample.heic",
fileName: "sample.bin",
mime: "image/jpeg",
}),
);