/** * Default Augmentations Registration * * Maintains zero-config philosophy by automatically registering * core augmentations that were previously hardcoded in BrainyData. * * These augmentations are optional but enabled by default for * backward compatibility and optimal performance. */ import { BrainyData } from '../brainyData.js' import { BaseAugmentation } from './brainyAugmentation.js' import { CacheAugmentation } from './cacheAugmentation.js' import { IndexAugmentation } from './indexAugmentation.js' import { MetricsAugmentation } from './metricsAugmentation.js' import { MonitoringAugmentation } from './monitoringAugmentation.js' /** * Create default augmentations for zero-config operation * Returns an array of augmentations to be registered * * @param config - Configuration options * @returns Array of augmentations to register */ export function createDefaultAugmentations( config: { cache?: boolean | Record index?: boolean | Record metrics?: boolean | Record monitoring?: boolean | Record } = {} ): BaseAugmentation[] { const augmentations: BaseAugmentation[] = [] // Cache augmentation (was SearchCache) if (config.cache !== false) { const cacheConfig = typeof config.cache === 'object' ? config.cache : {} augmentations.push(new CacheAugmentation(cacheConfig)) } // Index augmentation (was MetadataIndex) if (config.index !== false) { const indexConfig = typeof config.index === 'object' ? config.index : {} augmentations.push(new IndexAugmentation(indexConfig)) } // Metrics augmentation (was StatisticsCollector) if (config.metrics !== false) { const metricsConfig = typeof config.metrics === 'object' ? config.metrics : {} augmentations.push(new MetricsAugmentation(metricsConfig)) } // Monitoring augmentation (was HealthMonitor) // Only enable by default in distributed mode const isDistributed = process.env.BRAINY_MODE === 'distributed' || process.env.BRAINY_DISTRIBUTED === 'true' if (config.monitoring !== false && (config.monitoring || isDistributed)) { const monitoringConfig = typeof config.monitoring === 'object' ? config.monitoring : {} augmentations.push(new MonitoringAugmentation(monitoringConfig)) } return augmentations } /** * Get augmentation by name with type safety */ export function getAugmentation(brain: BrainyData, name: string): T | null { // Access augmentations through a public method or property const augmentations = (brain as any).augmentations if (!augmentations) return null const aug = augmentations.get(name) return aug as T | null } /** * Compatibility helpers for migrating from hardcoded features */ export const AugmentationHelpers = { /** * Get cache augmentation */ getCache(brain: BrainyData): CacheAugmentation | null { return getAugmentation(brain, 'cache') }, /** * Get index augmentation */ getIndex(brain: BrainyData): IndexAugmentation | null { return getAugmentation(brain, 'index') }, /** * Get metrics augmentation */ getMetrics(brain: BrainyData): MetricsAugmentation | null { return getAugmentation(brain, 'metrics') }, /** * Get monitoring augmentation */ getMonitoring(brain: BrainyData): MonitoringAugmentation | null { return getAugmentation(brain, 'monitoring') } }