From 0b3f3ed728d3435fb583d9a962e9974f3ad52d74 Mon Sep 17 00:00:00 2001 From: Siddharth Ganesan Date: Sat, 4 Apr 2026 17:04:14 -0700 Subject: [PATCH] File types --- apps/sim/lib/copilot/vfs/file-reader.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/apps/sim/lib/copilot/vfs/file-reader.ts b/apps/sim/lib/copilot/vfs/file-reader.ts index d3fd77aaf3..00f2e2dc55 100644 --- a/apps/sim/lib/copilot/vfs/file-reader.ts +++ b/apps/sim/lib/copilot/vfs/file-reader.ts @@ -31,6 +31,16 @@ function getExtension(filename: string): string { return dot >= 0 ? filename.slice(dot + 1).toLowerCase() : '' } +function detectImageMime(buf: Buffer, claimed: string): string { + if (buf.length < 12) return claimed + if (buf[0] === 0xff && buf[1] === 0xd8 && buf[2] === 0xff) return 'image/jpeg' + if (buf[0] === 0x89 && buf[1] === 0x50 && buf[2] === 0x4e && buf[3] === 0x47) return 'image/png' + if (buf[0] === 0x47 && buf[1] === 0x49 && buf[2] === 0x46) return 'image/gif' + if (buf[8] === 0x57 && buf[9] === 0x45 && buf[10] === 0x42 && buf[11] === 0x50) + return 'image/webp' + return claimed +} + export interface FileReadResult { content: string totalLines: number @@ -59,14 +69,15 @@ export async function readFileRecord(record: WorkspaceFileRecord): Promise