mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-31 14:18:35 +00:00
fix(media-understanding): normalize HEIC before image descriptions
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
}),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user