2025-08-26 12:32:21 -07:00
|
|
|
/**
|
|
|
|
|
* Default Augmentations Registration
|
|
|
|
|
*
|
|
|
|
|
* Maintains zero-config philosophy by automatically registering
|
2025-09-11 16:23:32 -07:00
|
|
|
* core augmentations that were previously hardcoded in Brainy.
|
2025-08-26 12:32:21 -07:00
|
|
|
*
|
|
|
|
|
* These augmentations are optional but enabled by default for
|
|
|
|
|
* backward compatibility and optimal performance.
|
|
|
|
|
*/
|
|
|
|
|
|
2025-09-11 16:23:32 -07:00
|
|
|
import { Brainy } from '../brainy.js'
|
2025-08-26 12:32:21 -07:00
|
|
|
import { BaseAugmentation } from './brainyAugmentation.js'
|
|
|
|
|
import { CacheAugmentation } from './cacheAugmentation.js'
|
|
|
|
|
import { MetricsAugmentation } from './metricsAugmentation.js'
|
|
|
|
|
import { MonitoringAugmentation } from './monitoringAugmentation.js'
|
2025-08-28 12:37:07 -07:00
|
|
|
import { UniversalDisplayAugmentation } from './universalDisplayAugmentation.js'
|
2025-08-26 12:32:21 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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<string, any>
|
|
|
|
|
metrics?: boolean | Record<string, any>
|
|
|
|
|
monitoring?: boolean | Record<string, any>
|
2025-08-28 12:37:07 -07:00
|
|
|
display?: boolean | Record<string, any>
|
2025-08-26 12:32:21 -07:00
|
|
|
} = {}
|
|
|
|
|
): 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))
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-12 12:36:11 -07:00
|
|
|
// Note: Index augmentation removed - metadata indexing is now core functionality
|
2025-08-26 12:32:21 -07:00
|
|
|
|
|
|
|
|
// Metrics augmentation (was StatisticsCollector)
|
|
|
|
|
if (config.metrics !== false) {
|
|
|
|
|
const metricsConfig = typeof config.metrics === 'object' ? config.metrics : {}
|
|
|
|
|
augmentations.push(new MetricsAugmentation(metricsConfig))
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-28 12:37:07 -07:00
|
|
|
// Display augmentation (AI-powered intelligent display fields)
|
|
|
|
|
if (config.display !== false) {
|
|
|
|
|
const displayConfig = typeof config.display === 'object' ? config.display : {}
|
|
|
|
|
augmentations.push(new UniversalDisplayAugmentation(displayConfig))
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-26 12:32:21 -07:00
|
|
|
// Monitoring augmentation (was HealthMonitor)
|
|
|
|
|
// Only enable by default in distributed mode
|
2025-09-29 13:51:47 -07:00
|
|
|
const isDistributed = process.env.BRAINY_MODE === 'distributed' ||
|
2025-08-26 12:32:21 -07:00
|
|
|
process.env.BRAINY_DISTRIBUTED === 'true'
|
2025-09-29 13:51:47 -07:00
|
|
|
|
2025-08-26 12:32:21 -07:00
|
|
|
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
|
|
|
|
|
*/
|
2025-09-11 16:23:32 -07:00
|
|
|
export function getAugmentation<T>(brain: Brainy, name: string): T | null {
|
2025-08-26 12:32:21 -07:00
|
|
|
// 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
|
|
|
|
|
*/
|
2025-09-11 16:23:32 -07:00
|
|
|
getCache(brain: Brainy): CacheAugmentation | null {
|
2025-08-26 12:32:21 -07:00
|
|
|
return getAugmentation<CacheAugmentation>(brain, 'cache')
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
2025-09-12 12:36:11 -07:00
|
|
|
* Note: Index augmentation removed - metadata indexing is now core functionality
|
|
|
|
|
* Use brain.metadataIndex directly instead
|
2025-08-26 12:32:21 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get metrics augmentation
|
|
|
|
|
*/
|
2025-09-11 16:23:32 -07:00
|
|
|
getMetrics(brain: Brainy): MetricsAugmentation | null {
|
2025-08-26 12:32:21 -07:00
|
|
|
return getAugmentation<MetricsAugmentation>(brain, 'metrics')
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get monitoring augmentation
|
|
|
|
|
*/
|
2025-09-11 16:23:32 -07:00
|
|
|
getMonitoring(brain: Brainy): MonitoringAugmentation | null {
|
2025-08-26 12:32:21 -07:00
|
|
|
return getAugmentation<MonitoringAugmentation>(brain, 'monitoring')
|
2025-08-28 12:37:07 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get display augmentation
|
|
|
|
|
*/
|
2025-09-11 16:23:32 -07:00
|
|
|
getDisplay(brain: Brainy): UniversalDisplayAugmentation | null {
|
2025-08-28 12:37:07 -07:00
|
|
|
return getAugmentation<UniversalDisplayAugmentation>(brain, 'display')
|
2025-08-26 12:32:21 -07:00
|
|
|
}
|
|
|
|
|
}
|