feat: add ImageHandler with EXIF extraction and comprehensive MIME detection (v5.2.0)

Implements Phase 1.5 (Comprehensive MIME Type Detection) and adds built-in image processing support to IntelligentImportAugmentation.

**New Features:**
- ImageHandler: Extracts image metadata (dimensions, format, color space) using sharp
- EXIF extraction: Camera data, GPS, timestamps using exifr library
- Support for JPEG, PNG, WebP, GIF, TIFF, BMP, SVG, HEIC, AVIF formats
- MimeTypeDetector: Unified MIME type detection with magic byte support
- FormatDetector: Enhanced with image format detection via MIME + magic bytes

**Architecture Fixes:**
- Fixed brain.import() augmentation pipeline integration (src/brainy.ts:3140-3154)
- Added parameter spreading for ImportSource objects to enable augmentation access
- Fixed metadata propagation through ImportCoordinator to final results
- Added augmentation data check in ImportCoordinator.extract()

**Integration:**
- ImageHandler registered as built-in handler alongside CSV, Excel, PDF
- Images import as 'media' entities with 'image' subtype
- Full metadata preserved in knowledge graph entities
- Configuration options: enableImage, extractEXIF, imageDefaults

**Test Coverage:**
- 15 integration tests (image-import.test.ts) - 100% passing
- 27 unit tests (image-handler.test.ts) - 100% passing
- Format detection tests for all supported image types
- Error handling and resilience tests

**Breaking Changes:** None - backward compatible

Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
David Snelling 2025-11-03 14:06:17 -08:00
parent 6345f87eb2
commit 1874b77896
26 changed files with 5079 additions and 434 deletions

View file

@ -14,6 +14,7 @@ import { VirtualFileSystem } from '../VirtualFileSystem.js'
import { Brainy } from '../../brainy.js'
import { NounType } from '../../types/graphTypes.js'
import { v4 as uuidv4 } from '../../universal/uuid.js'
import { mimeDetector } from '../MimeTypeDetector.js'
export interface ImportOptions {
targetPath?: string // VFS target path (default: '/')
@ -381,46 +382,6 @@ export class DirectoryImporter {
return false
}
/**
* Detect MIME type from file content and extension
*/
private detectMimeType(filePath: string, content?: Buffer): string {
const ext = path.extname(filePath).toLowerCase()
// Common extensions
const mimeTypes: Record<string, string> = {
'.js': 'application/javascript',
'.ts': 'application/typescript',
'.jsx': 'application/javascript',
'.tsx': 'application/typescript',
'.json': 'application/json',
'.md': 'text/markdown',
'.html': 'text/html',
'.css': 'text/css',
'.py': 'text/x-python',
'.go': 'text/x-go',
'.rs': 'text/x-rust',
'.java': 'text/x-java',
'.cpp': 'text/x-c++',
'.c': 'text/x-c',
'.h': 'text/x-c',
'.txt': 'text/plain',
'.xml': 'application/xml',
'.yaml': 'text/yaml',
'.yml': 'text/yaml',
'.toml': 'text/toml',
'.sh': 'text/x-shellscript',
'.pdf': 'application/pdf',
'.jpg': 'image/jpeg',
'.jpeg': 'image/jpeg',
'.png': 'image/png',
'.gif': 'image/gif',
'.svg': 'image/svg+xml',
'.mp3': 'audio/mpeg',
'.mp4': 'video/mp4',
'.zip': 'application/zip'
}
return mimeTypes[ext] || 'application/octet-stream'
}
// v5.2.0: MIME detection moved to MimeTypeDetector service
// Removed detectMimeType() - now using mimeDetector singleton
}