fix(image): support data URLs

This commit is contained in:
Peter Steinberger
2026-01-12 18:17:39 +00:00
parent 2ed95634fe
commit 0a2dcd844b
2 changed files with 67 additions and 12 deletions

View File

@@ -6,6 +6,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type { ClawdbotConfig } from "../../config/config.js";
import {
__testing,
createImageTool,
resolveImageModelConfigForTool,
} from "./image-tool.js";
@@ -132,3 +133,20 @@ describe("image tool implicit imageModel config", () => {
).rejects.toThrow(/escapes sandbox root/i);
});
});
describe("image tool data URL support", () => {
it("decodes base64 image data URLs", () => {
const pngB64 =
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/woAAn8B9FD5fHAAAAAASUVORK5CYII=";
const out = __testing.decodeDataUrl(`data:image/png;base64,${pngB64}`);
expect(out.kind).toBe("image");
expect(out.mimeType).toBe("image/png");
expect(out.buffer.length).toBeGreaterThan(0);
});
it("rejects non-image data URLs", () => {
expect(() =>
__testing.decodeDataUrl("data:text/plain;base64,SGVsbG8="),
).toThrow(/Unsupported data URL type/i);
});
});