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,12 +1,12 @@
/**
* Universal Neural Import API
*
*
* ALWAYS uses neural matching to map ANY data to our strict NounTypes and VerbTypes
* Never falls back to rules - neural matching is MANDATORY
*
*
* Handles:
* - Strings (text, JSON, CSV, YAML, Markdown)
* - Files (local paths, any format)
* - Files (local paths, any format) - uses MimeTypeDetector for 2000+ types
* - URLs (web pages, APIs, documents)
* - Objects (structured data)
* - Binary data (images, PDFs via extraction)
@ -18,6 +18,7 @@ import type { Brainy } from '../brainy.js'
import type { Entity, Relation } from '../types/brainy.types.js'
import { BrainyTypes, getBrainyTypes } from '../augmentations/typeMatching/brainyTypes.js'
import { NeuralImportAugmentation } from '../augmentations/neuralImport.js'
import { mimeDetector } from '../vfs/MimeTypeDetector.js'
export interface ImportSource {
type: 'string' | 'file' | 'url' | 'object' | 'binary'
@ -157,21 +158,27 @@ export class UniversalImportAPI {
/**
* Import from file - reads and processes
* Note: In browser environment, use File API instead
*
* Uses MimeTypeDetector for comprehensive format detection (2000+ types)
*/
async importFromFile(filePath: string): Promise<NeuralImportResult> {
// Read the actual file content
const { readFileSync } = await import('node:fs')
// Use MimeTypeDetector for comprehensive format detection
const mimeType = mimeDetector.detectMimeType(filePath)
const ext = filePath.split('.').pop()?.toLowerCase() || 'txt'
try {
const fileContent = readFileSync(filePath, 'utf-8')
return this.import({
type: 'file',
data: fileContent, // Actual file content
format: ext,
metadata: {
format: ext, // Keep ext for backward compatibility
metadata: {
path: filePath,
mimeType, // Add detected MIME type
importedAt: Date.now(),
fileSize: fileContent.length
}