22 * Image-related constants shared across the codebase
33 */
44
5- // Supported image formats for multimodal messages
6- export const SUPPORTED_IMAGE_EXTENSIONS = new Set ( [
7- '.jpg' ,
8- '.jpeg' ,
9- '.png' ,
10- '.webp' ,
11- '.gif' ,
12- '.bmp' ,
13- '.tiff' ,
14- '.tif' ,
15- ] )
16-
17- /**
18- * Check if a file extension is a supported image format
19- */
20- export function isSupportedImageExtension ( ext : string ) : boolean {
21- return SUPPORTED_IMAGE_EXTENSIONS . has ( ext . toLowerCase ( ) )
22- }
23-
24- /**
25- * Image extensions as a regex alternation pattern (without dots)
26- * e.g., "jpg|jpeg|png|webp|gif|bmp|tiff|tif"
27- */
28- export const IMAGE_EXTENSIONS_PATTERN = Array . from ( SUPPORTED_IMAGE_EXTENSIONS )
29- . map ( ( ext ) => ext . slice ( 1 ) ) // Remove leading dot
30- . join ( '|' )
31-
325/**
336 * Extension to MIME type mapping for supported image formats
347 */
@@ -43,13 +16,33 @@ export const IMAGE_EXTENSION_TO_MIME: Record<string, string> = {
4316 '.tif' : 'image/tiff' ,
4417}
4518
19+ /**
20+ * Supported image extensions (derived from IMAGE_EXTENSION_TO_MIME)
21+ */
22+ export const SUPPORTED_IMAGE_EXTENSIONS = new Set ( Object . keys ( IMAGE_EXTENSION_TO_MIME ) )
23+
24+ /**
25+ * Check if a file extension is a supported image format
26+ */
27+ export function isSupportedImageExtension ( ext : string ) : boolean {
28+ return SUPPORTED_IMAGE_EXTENSIONS . has ( ext . toLowerCase ( ) )
29+ }
30+
4631/**
4732 * Get MIME type for an image extension
4833 */
4934export function getImageMimeType ( ext : string ) : string | null {
5035 return IMAGE_EXTENSION_TO_MIME [ ext . toLowerCase ( ) ] ?? null
5136}
5237
38+ /**
39+ * Image extensions as a regex alternation pattern (without dots)
40+ * e.g., "jpg|jpeg|png|webp|gif|bmp|tiff|tif"
41+ */
42+ export const IMAGE_EXTENSIONS_PATTERN = Object . keys ( IMAGE_EXTENSION_TO_MIME )
43+ . map ( ( ext ) => ext . slice ( 1 ) ) // Remove leading dot
44+ . join ( '|' )
45+
5346// Size limits for image uploads
5447// Research shows Claude/GPT-4V support up to 20MB, but we use practical limits
5548// for good performance and token efficiency
0 commit comments