Skip to content

Commit 00d986a

Browse files
committed
fix(cli): convert HEIC sequences for model runs
1 parent 8f54c1a commit 00d986a

2 files changed

Lines changed: 62 additions & 1 deletion

File tree

‎src/cli/capability-cli.test.ts‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ const PNG_1X1_BASE64 =
1414
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+yf7kAAAAASUVORK5CYII=";
1515
const tempDirs = useAutoCleanupTempDirTracker(afterEach);
1616

17+
function createIsomBrandBuffer(brand: "hevc" | "msf1"): Buffer {
18+
const buffer = Buffer.alloc(24);
19+
buffer.writeUInt32BE(buffer.length, 0);
20+
buffer.write("ftyp", 4, "ascii");
21+
buffer.write(brand, 8, "ascii");
22+
return buffer;
23+
}
24+
1725
async function runCap(...argv: string[]): Promise<void> {
1826
const program = new Command();
1927
await registerCapabilityCli(program, ["node", "openclaw", ...argv]);
@@ -1284,6 +1292,54 @@ describe("capability cli", () => {
12841292
expect(inputs[0]?.mimeType).toBe("image/jpeg");
12851293
});
12861294

1295+
it("normalizes sniffed HEIC sequences to JPEG before local model probes", async () => {
1296+
const source = createIsomBrandBuffer("hevc");
1297+
const tempInput = path.join(tempDirs.make("openclaw-model-run-heic-sequence-"), "opaque.bin");
1298+
await fs.writeFile(tempInput, source);
1299+
1300+
await runCapability("model", "run", "--prompt", "describe this", "--file", tempInput, "--json");
1301+
1302+
expect(mocks.convertHeicToJpeg).toHaveBeenCalledWith(source);
1303+
const call = firstCompletionCall();
1304+
expect(call?.context?.messages?.[0]?.content).toEqual([
1305+
{ type: "text", text: "describe this" },
1306+
{
1307+
type: "image",
1308+
data: Buffer.from("jpeg-normalized").toString("base64"),
1309+
mimeType: "image/jpeg",
1310+
},
1311+
]);
1312+
expect(firstJsonOutput()?.inputs).toEqual([{ path: tempInput, mimeType: "image/jpeg" }]);
1313+
});
1314+
1315+
it("normalizes sniffed HEIF sequences to JPEG before gateway model probes", async () => {
1316+
const source = createIsomBrandBuffer("msf1");
1317+
const tempInput = path.join(tempDirs.make("openclaw-model-run-heif-sequence-"), "opaque.bin");
1318+
await fs.writeFile(tempInput, source);
1319+
1320+
await runCapability(
1321+
"model",
1322+
"run",
1323+
"--prompt",
1324+
"describe this",
1325+
"--file",
1326+
tempInput,
1327+
"--gateway",
1328+
"--json",
1329+
);
1330+
1331+
expect(mocks.convertHeicToJpeg).toHaveBeenCalledWith(source);
1332+
expect(firstGatewayCall()?.params?.attachments).toEqual([
1333+
{
1334+
type: "image",
1335+
fileName: "opaque.bin",
1336+
mimeType: "image/jpeg",
1337+
content: Buffer.from("jpeg-normalized").toString("base64"),
1338+
},
1339+
]);
1340+
expect(firstJsonOutput()?.inputs).toEqual([{ path: tempInput, mimeType: "image/jpeg" }]);
1341+
});
1342+
12871343
it("rejects non-image files for model probes", async () => {
12881344
const tempInput = path.join(os.tmpdir(), `openclaw-model-run-audio-${Date.now()}.mp3`);
12891345
await fs.writeFile(tempInput, Buffer.from("not really audio"));

‎src/cli/capability-cli/model.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ import {
5353
} from "./shared.js";
5454

5555
const LOCAL_MODEL_RUN_SYSTEM_PROMPT = "You are a personal assistant running inside OpenClaw.";
56-
const HEIC_MODEL_RUN_MIMES = new Set(["image/heic", "image/heif"]);
56+
const HEIC_MODEL_RUN_MIMES = new Set([
57+
"image/heic",
58+
"image/heic-sequence",
59+
"image/heif",
60+
"image/heif-sequence",
61+
]);
5762

5863
async function loadModelCatalogForInspection(cfg: OpenClawConfig, agentId?: string) {
5964
const prepared = await loadPreparedModelCatalog({ config: cfg, agentId, readOnly: true });

0 commit comments

Comments
 (0)