mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-16 07:04:25 +00:00
Fix non-PNG images not displaying in Kitty protocol terminals
JPEG/GIF/WebP images were not rendering in terminals using the Kitty graphics protocol (Kitty, Ghostty, WezTerm) because it requires PNG format (f=100). Non-PNG images are now converted to PNG using sharp before being sent to the terminal.
This commit is contained in:
parent
9b0ec02405
commit
79c56475e0
3 changed files with 80 additions and 3 deletions
26
packages/coding-agent/src/utils/image-convert.ts
Normal file
26
packages/coding-agent/src/utils/image-convert.ts
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/**
|
||||
* Convert image to PNG format for terminal display.
|
||||
* Kitty graphics protocol requires PNG format (f=100).
|
||||
*/
|
||||
export async function convertToPng(
|
||||
base64Data: string,
|
||||
mimeType: string,
|
||||
): Promise<{ data: string; mimeType: string } | null> {
|
||||
// Already PNG, no conversion needed
|
||||
if (mimeType === "image/png") {
|
||||
return { data: base64Data, mimeType };
|
||||
}
|
||||
|
||||
try {
|
||||
const sharp = (await import("sharp")).default;
|
||||
const buffer = Buffer.from(base64Data, "base64");
|
||||
const pngBuffer = await sharp(buffer).png().toBuffer();
|
||||
return {
|
||||
data: pngBuffer.toString("base64"),
|
||||
mimeType: "image/png",
|
||||
};
|
||||
} catch {
|
||||
// Sharp not available or conversion failed
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue