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

@ -1,9 +1,12 @@
/**
* Base Format Handler
* Abstract class providing common functionality for all format handlers
*
* Uses MimeTypeDetector for comprehensive file type detection (2000+ types)
*/
import { FormatHandler, FormatHandlerOptions, ProcessedData } from '../types.js'
import { mimeDetector } from '../../../vfs/MimeTypeDetector.js'
export abstract class BaseFormatHandler implements FormatHandler {
abstract readonly format: string
@ -33,6 +36,38 @@ export abstract class BaseFormatHandler implements FormatHandler {
return match ? match[1].toLowerCase() : ''
}
/**
* Get MIME type using MimeTypeDetector
*
* Supports 2000+ file types via mime library + custom developer types
*/
protected getMimeType(data: Buffer | string | { filename?: string }): string {
if (typeof data === 'object' && 'filename' in data && data.filename) {
return mimeDetector.detectMimeType(data.filename)
}
if (Buffer.isBuffer(data)) {
// For buffers, we don't have a filename, so return generic
return 'application/octet-stream'
}
return 'text/plain'
}
/**
* Check if MIME type matches expected format
*
* @param mimeType - MIME type to check
* @param patterns - Patterns to match (e.g., ['text/csv', 'application/vnd.ms-excel'])
*/
protected mimeTypeMatches(mimeType: string, patterns: string[]): boolean {
return patterns.some(pattern => {
if (pattern.endsWith('/*')) {
const prefix = pattern.slice(0, -2)
return mimeType.startsWith(prefix)
}
return mimeType === pattern
})
}
/**
* Infer field types from data
* Analyzes multiple rows to determine the most appropriate type