@soulcraft/brainy 2.15.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +249 -152
  3. package/dist/api/ConfigAPI.d.ts +67 -0
  4. package/dist/api/ConfigAPI.js +166 -0
  5. package/dist/api/DataAPI.d.ts +123 -0
  6. package/dist/api/DataAPI.js +391 -0
  7. package/dist/api/SecurityAPI.d.ts +50 -0
  8. package/dist/api/SecurityAPI.js +139 -0
  9. package/dist/api/UniversalImportAPI.d.ts +134 -0
  10. package/dist/api/UniversalImportAPI.js +615 -0
  11. package/dist/augmentationManager.js +12 -7
  12. package/dist/augmentationPipeline.d.ts +0 -61
  13. package/dist/augmentationPipeline.js +0 -87
  14. package/dist/augmentationRegistry.d.ts +1 -1
  15. package/dist/augmentationRegistry.js +1 -1
  16. package/dist/augmentations/apiServerAugmentation.d.ts +27 -1
  17. package/dist/augmentations/apiServerAugmentation.js +288 -7
  18. package/dist/augmentations/auditLogAugmentation.d.ts +109 -0
  19. package/dist/augmentations/auditLogAugmentation.js +358 -0
  20. package/dist/augmentations/batchProcessingAugmentation.d.ts +3 -2
  21. package/dist/augmentations/batchProcessingAugmentation.js +123 -22
  22. package/dist/augmentations/brainyAugmentation.d.ts +87 -8
  23. package/dist/augmentations/brainyAugmentation.js +159 -2
  24. package/dist/augmentations/cacheAugmentation.d.ts +6 -5
  25. package/dist/augmentations/cacheAugmentation.js +113 -17
  26. package/dist/augmentations/conduitAugmentations.d.ts +2 -2
  27. package/dist/augmentations/conduitAugmentations.js +2 -2
  28. package/dist/augmentations/configResolver.d.ts +122 -0
  29. package/dist/augmentations/configResolver.js +440 -0
  30. package/dist/augmentations/connectionPoolAugmentation.d.ts +3 -1
  31. package/dist/augmentations/connectionPoolAugmentation.js +37 -12
  32. package/dist/augmentations/defaultAugmentations.d.ts +9 -11
  33. package/dist/augmentations/defaultAugmentations.js +4 -11
  34. package/dist/augmentations/discovery/catalogDiscovery.d.ts +142 -0
  35. package/dist/augmentations/discovery/catalogDiscovery.js +249 -0
  36. package/dist/augmentations/discovery/localDiscovery.d.ts +84 -0
  37. package/dist/augmentations/discovery/localDiscovery.js +246 -0
  38. package/dist/augmentations/discovery/runtimeLoader.d.ts +97 -0
  39. package/dist/augmentations/discovery/runtimeLoader.js +337 -0
  40. package/dist/augmentations/discovery.d.ts +152 -0
  41. package/dist/augmentations/discovery.js +441 -0
  42. package/dist/augmentations/display/intelligentComputation.d.ts +1 -1
  43. package/dist/augmentations/display/intelligentComputation.js +4 -4
  44. package/dist/augmentations/entityRegistryAugmentation.d.ts +3 -1
  45. package/dist/augmentations/entityRegistryAugmentation.js +5 -1
  46. package/dist/augmentations/indexAugmentation.d.ts +3 -3
  47. package/dist/augmentations/indexAugmentation.js +2 -2
  48. package/dist/augmentations/intelligentVerbScoringAugmentation.d.ts +22 -6
  49. package/dist/augmentations/intelligentVerbScoringAugmentation.js +106 -23
  50. package/dist/augmentations/manifest.d.ts +176 -0
  51. package/dist/augmentations/manifest.js +8 -0
  52. package/dist/augmentations/marketplace/AugmentationMarketplace.d.ts +168 -0
  53. package/dist/augmentations/marketplace/AugmentationMarketplace.js +329 -0
  54. package/dist/augmentations/marketplace/cli.d.ts +47 -0
  55. package/dist/augmentations/marketplace/cli.js +265 -0
  56. package/dist/augmentations/metricsAugmentation.d.ts +3 -3
  57. package/dist/augmentations/metricsAugmentation.js +2 -2
  58. package/dist/augmentations/monitoringAugmentation.d.ts +3 -3
  59. package/dist/augmentations/monitoringAugmentation.js +2 -2
  60. package/dist/augmentations/neuralImport.d.ts +1 -1
  61. package/dist/augmentations/rateLimitAugmentation.d.ts +82 -0
  62. package/dist/augmentations/rateLimitAugmentation.js +321 -0
  63. package/dist/augmentations/requestDeduplicatorAugmentation.d.ts +2 -2
  64. package/dist/augmentations/requestDeduplicatorAugmentation.js +1 -1
  65. package/dist/augmentations/storageAugmentation.d.ts +1 -1
  66. package/dist/augmentations/storageAugmentation.js +2 -2
  67. package/dist/augmentations/storageAugmentations.d.ts +37 -8
  68. package/dist/augmentations/storageAugmentations.js +204 -15
  69. package/dist/augmentations/synapseAugmentation.d.ts +1 -1
  70. package/dist/augmentations/synapseAugmentation.js +35 -16
  71. package/dist/augmentations/typeMatching/intelligentTypeMatcher.d.ts +39 -59
  72. package/dist/augmentations/typeMatching/intelligentTypeMatcher.js +103 -389
  73. package/dist/augmentations/universalDisplayAugmentation.d.ts +2 -2
  74. package/dist/augmentations/universalDisplayAugmentation.js +2 -2
  75. package/dist/brainy-unified.d.ts +106 -0
  76. package/dist/brainy-unified.js +327 -0
  77. package/dist/brainy.d.ts +273 -0
  78. package/dist/brainy.js +1181 -0
  79. package/dist/brainyData.d.ts +29 -72
  80. package/dist/brainyData.js +350 -304
  81. package/dist/brainyDataV3.d.ts +186 -0
  82. package/dist/brainyDataV3.js +337 -0
  83. package/dist/browserFramework.d.ts +6 -6
  84. package/dist/browserFramework.js +11 -8
  85. package/dist/browserFramework.minimal.d.ts +5 -5
  86. package/dist/browserFramework.minimal.js +11 -8
  87. package/dist/config/index.d.ts +2 -2
  88. package/dist/config/index.js +3 -3
  89. package/dist/config/modelAutoConfig.d.ts +6 -7
  90. package/dist/config/modelAutoConfig.js +17 -76
  91. package/dist/cortex/backupRestore.d.ts +2 -2
  92. package/dist/cortex/backupRestore.js +85 -27
  93. package/dist/cortex/healthCheck.d.ts +2 -2
  94. package/dist/cortex/neuralImport.d.ts +2 -2
  95. package/dist/cortex/neuralImport.js +18 -13
  96. package/dist/cortex/performanceMonitor.d.ts +2 -2
  97. package/dist/critical/model-guardian.d.ts +4 -0
  98. package/dist/critical/model-guardian.js +31 -11
  99. package/dist/demo.d.ts +4 -4
  100. package/dist/demo.js +7 -7
  101. package/dist/distributed/cacheSync.d.ts +112 -0
  102. package/dist/distributed/cacheSync.js +265 -0
  103. package/dist/distributed/coordinator.d.ts +193 -0
  104. package/dist/distributed/coordinator.js +548 -0
  105. package/dist/distributed/httpTransport.d.ts +120 -0
  106. package/dist/distributed/httpTransport.js +446 -0
  107. package/dist/distributed/index.d.ts +8 -0
  108. package/dist/distributed/index.js +5 -0
  109. package/dist/distributed/networkTransport.d.ts +132 -0
  110. package/dist/distributed/networkTransport.js +633 -0
  111. package/dist/distributed/queryPlanner.d.ts +104 -0
  112. package/dist/distributed/queryPlanner.js +327 -0
  113. package/dist/distributed/readWriteSeparation.d.ts +134 -0
  114. package/dist/distributed/readWriteSeparation.js +350 -0
  115. package/dist/distributed/shardManager.d.ts +114 -0
  116. package/dist/distributed/shardManager.js +357 -0
  117. package/dist/distributed/shardMigration.d.ts +110 -0
  118. package/dist/distributed/shardMigration.js +289 -0
  119. package/dist/distributed/storageDiscovery.d.ts +160 -0
  120. package/dist/distributed/storageDiscovery.js +551 -0
  121. package/dist/embeddings/EmbeddingManager.d.ts +0 -4
  122. package/dist/embeddings/EmbeddingManager.js +21 -26
  123. package/dist/errors/brainyError.d.ts +5 -1
  124. package/dist/errors/brainyError.js +12 -0
  125. package/dist/examples/basicUsage.js +3 -3
  126. package/dist/graph/graphAdjacencyIndex.d.ts +96 -0
  127. package/dist/graph/graphAdjacencyIndex.js +288 -0
  128. package/dist/graph/pathfinding.js +4 -2
  129. package/dist/hnsw/scaledHNSWSystem.js +11 -2
  130. package/dist/importManager.js +6 -3
  131. package/dist/index.d.ts +12 -21
  132. package/dist/index.js +14 -22
  133. package/dist/mcp/brainyMCPAdapter.d.ts +4 -4
  134. package/dist/mcp/brainyMCPAdapter.js +5 -5
  135. package/dist/mcp/brainyMCPService.d.ts +3 -3
  136. package/dist/mcp/brainyMCPService.js +3 -11
  137. package/dist/mcp/mcpAugmentationToolset.js +20 -30
  138. package/dist/neural/embeddedPatterns.d.ts +1 -1
  139. package/dist/neural/embeddedPatterns.js +2 -2
  140. package/dist/neural/entityExtractor.d.ts +65 -0
  141. package/dist/neural/entityExtractor.js +316 -0
  142. package/dist/neural/improvedNeuralAPI.js +90 -79
  143. package/dist/neural/naturalLanguageProcessor.d.ts +155 -10
  144. package/dist/neural/naturalLanguageProcessor.js +941 -66
  145. package/dist/neural/naturalLanguageProcessorStatic.d.ts +2 -2
  146. package/dist/neural/naturalLanguageProcessorStatic.js +3 -3
  147. package/dist/neural/neuralAPI.js +8 -2
  148. package/dist/neural/patternLibrary.d.ts +57 -3
  149. package/dist/neural/patternLibrary.js +348 -13
  150. package/dist/neural/staticPatternMatcher.d.ts +2 -2
  151. package/dist/neural/staticPatternMatcher.js +2 -2
  152. package/dist/shared/default-augmentations.d.ts +3 -3
  153. package/dist/shared/default-augmentations.js +5 -5
  154. package/dist/storage/adapters/fileSystemStorage.d.ts +4 -0
  155. package/dist/storage/adapters/fileSystemStorage.js +54 -1
  156. package/dist/storage/adapters/memoryStorage.js +13 -8
  157. package/dist/storage/backwardCompatibility.d.ts +10 -78
  158. package/dist/storage/backwardCompatibility.js +17 -132
  159. package/dist/storage/baseStorage.d.ts +6 -0
  160. package/dist/storage/baseStorage.js +17 -0
  161. package/dist/storage/cacheManager.js +2 -2
  162. package/dist/storage/readOnlyOptimizations.js +8 -3
  163. package/dist/streaming/pipeline.d.ts +154 -0
  164. package/dist/streaming/pipeline.js +551 -0
  165. package/dist/triple/TripleIntelligence.d.ts +25 -110
  166. package/dist/triple/TripleIntelligence.js +4 -574
  167. package/dist/triple/TripleIntelligenceSystem.d.ts +159 -0
  168. package/dist/triple/TripleIntelligenceSystem.js +519 -0
  169. package/dist/types/apiTypes.d.ts +278 -0
  170. package/dist/types/apiTypes.js +33 -0
  171. package/dist/types/brainy.types.d.ts +308 -0
  172. package/dist/types/brainy.types.js +8 -0
  173. package/dist/types/brainyDataInterface.d.ts +3 -3
  174. package/dist/types/brainyDataInterface.js +2 -2
  175. package/dist/types/graphTypes.js +2 -2
  176. package/dist/utils/cacheAutoConfig.d.ts +3 -3
  177. package/dist/utils/embedding.js +8 -14
  178. package/dist/utils/enhancedLogger.d.ts +104 -0
  179. package/dist/utils/enhancedLogger.js +232 -0
  180. package/dist/utils/index.d.ts +1 -1
  181. package/dist/utils/index.js +1 -1
  182. package/dist/utils/intelligentTypeMapper.d.ts +60 -0
  183. package/dist/utils/intelligentTypeMapper.js +349 -0
  184. package/dist/utils/metadataIndex.d.ts +118 -1
  185. package/dist/utils/metadataIndex.js +539 -16
  186. package/dist/utils/paramValidation.d.ts +39 -0
  187. package/dist/utils/paramValidation.js +192 -0
  188. package/dist/utils/rateLimiter.d.ts +160 -0
  189. package/dist/utils/rateLimiter.js +271 -0
  190. package/dist/utils/statistics.d.ts +4 -4
  191. package/dist/utils/statistics.js +3 -3
  192. package/dist/utils/structuredLogger.d.ts +146 -0
  193. package/dist/utils/structuredLogger.js +394 -0
  194. package/dist/utils/textEncoding.js +2 -1
  195. package/dist/utils/typeValidation.d.ts +34 -0
  196. package/dist/utils/typeValidation.js +247 -0
  197. package/package.json +14 -6
  198. package/scripts/download-models.cjs +6 -15
  199. package/dist/augmentations/walAugmentation.d.ts +0 -111
  200. package/dist/augmentations/walAugmentation.js +0 -519
  201. package/dist/chat/BrainyChat.d.ts +0 -121
  202. package/dist/chat/BrainyChat.js +0 -396
  203. package/dist/chat/ChatCLI.d.ts +0 -61
  204. package/dist/chat/ChatCLI.js +0 -351
@@ -5,12 +5,12 @@
5
5
  * Each augmentation knows its place and when to execute automatically.
6
6
  *
7
7
  * The Vision: Components that enhance Brainy's capabilities seamlessly
8
- * - WAL: Adds durability to storage operations
9
8
  * - RequestDeduplicator: Prevents duplicate concurrent requests
10
9
  * - ConnectionPool: Optimizes cloud storage throughput
11
10
  * - IntelligentVerbScoring: Enhances relationship analysis
12
11
  * - StreamingPipeline: Enables unlimited data processing
13
12
  */
13
+ import { AugmentationManifest } from './manifest.js';
14
14
  /**
15
15
  * Metadata access declaration for augmentations
16
16
  */
@@ -43,10 +43,10 @@ export interface BrainyAugmentation {
43
43
  * Which operations this augmentation applies to
44
44
  * Granular operation matching for precise augmentation targeting
45
45
  */
46
- operations: ('add' | 'addNoun' | 'addVerb' | 'saveNoun' | 'saveVerb' | 'updateMetadata' | 'delete' | 'deleteVerb' | 'clear' | 'get' | 'search' | 'searchText' | 'searchByNounTypes' | 'findSimilar' | 'searchWithCursor' | 'relate' | 'getConnections' | 'storage' | 'backup' | 'restore' | 'all')[];
46
+ operations: ('add' | 'addNoun' | 'addVerb' | 'saveNoun' | 'saveVerb' | 'updateMetadata' | 'update' | 'delete' | 'deleteVerb' | 'clear' | 'get' | 'search' | 'searchText' | 'searchByNounTypes' | 'find' | 'findSimilar' | 'searchWithCursor' | 'similar' | 'relate' | 'unrelate' | 'getConnections' | 'getRelations' | 'storage' | 'backup' | 'restore' | 'all')[];
47
47
  /**
48
48
  * Priority for execution order (higher numbers execute first)
49
- * - 100: Critical system operations (WAL, ConnectionPool)
49
+ * - 100: Critical system operations (ConnectionPool)
50
50
  * - 50: Performance optimizations (RequestDeduplicator, Caching)
51
51
  * - 10: Enhancement features (IntelligentVerbScoring)
52
52
  * - 1: Optional features (Logging, Analytics)
@@ -54,9 +54,9 @@ export interface BrainyAugmentation {
54
54
  priority: number;
55
55
  /**
56
56
  * Initialize the augmentation
57
- * Called once during BrainyData initialization
57
+ * Called once during Brainy initialization
58
58
  *
59
- * @param context - The BrainyData instance and storage
59
+ * @param context - The Brainy instance and storage
60
60
  */
61
61
  initialize(context: AugmentationContext): Promise<void>;
62
62
  /**
@@ -74,7 +74,7 @@ export interface BrainyAugmentation {
74
74
  */
75
75
  shouldExecute?(operation: string, params: any): boolean;
76
76
  /**
77
- * Optional: Cleanup when BrainyData is destroyed
77
+ * Optional: Cleanup when Brainy is destroyed
78
78
  */
79
79
  shutdown?(): Promise<void>;
80
80
  /**
@@ -105,7 +105,7 @@ export interface BrainyAugmentation {
105
105
  */
106
106
  export interface AugmentationContext {
107
107
  /**
108
- * The BrainyData instance (for accessing methods and config)
108
+ * The Brainy instance (for accessing methods and config)
109
109
  */
110
110
  brain: any;
111
111
  /**
@@ -123,18 +123,69 @@ export interface AugmentationContext {
123
123
  }
124
124
  /**
125
125
  * Base class for augmentations with common functionality
126
+ *
127
+ * This is the unified base class that combines the features of both
128
+ * BaseAugmentation and ConfigurableAugmentation. All augmentations
129
+ * should extend this class for consistent configuration support.
126
130
  */
127
131
  export declare abstract class BaseAugmentation implements BrainyAugmentation {
128
132
  abstract name: string;
129
133
  abstract timing: 'before' | 'after' | 'around' | 'replace';
130
134
  abstract metadata: 'none' | 'readonly' | MetadataAccess;
131
- abstract operations: ('add' | 'addNoun' | 'addVerb' | 'saveNoun' | 'saveVerb' | 'updateMetadata' | 'delete' | 'deleteVerb' | 'clear' | 'get' | 'search' | 'searchText' | 'searchByNounTypes' | 'findSimilar' | 'searchWithCursor' | 'relate' | 'getConnections' | 'storage' | 'backup' | 'restore' | 'all')[];
135
+ abstract operations: ('add' | 'addNoun' | 'addVerb' | 'saveNoun' | 'saveVerb' | 'updateMetadata' | 'update' | 'delete' | 'deleteVerb' | 'clear' | 'get' | 'search' | 'searchText' | 'searchByNounTypes' | 'find' | 'findSimilar' | 'searchWithCursor' | 'similar' | 'relate' | 'unrelate' | 'getConnections' | 'getRelations' | 'storage' | 'backup' | 'restore' | 'all')[];
132
136
  abstract priority: number;
133
137
  category: 'internal' | 'core' | 'premium' | 'community' | 'external';
134
138
  description: string;
135
139
  enabled: boolean;
136
140
  protected context?: AugmentationContext;
137
141
  protected isInitialized: boolean;
142
+ protected config: any;
143
+ private configResolver?;
144
+ /**
145
+ * Constructor with optional configuration
146
+ * @param config Optional configuration to override defaults
147
+ */
148
+ constructor(config?: any);
149
+ /**
150
+ * Get the augmentation manifest for discovery
151
+ * Override this to enable configuration support
152
+ * CRITICAL: This enables tools to discover parameters and configuration
153
+ */
154
+ getManifest?(): AugmentationManifest;
155
+ /**
156
+ * Get parameter schema for operations
157
+ * Enables tools to know what parameters each operation needs
158
+ */
159
+ getParameterSchema?(operation: string): any;
160
+ /**
161
+ * Get operation descriptions
162
+ * Enables tools to show what each operation does
163
+ */
164
+ getOperationInfo?(): Record<string, {
165
+ description: string;
166
+ parameters?: any;
167
+ returns?: any;
168
+ examples?: any[];
169
+ }>;
170
+ /**
171
+ * Get current configuration
172
+ */
173
+ getConfig(): any;
174
+ /**
175
+ * Update configuration at runtime
176
+ * @param partial Partial configuration to merge
177
+ */
178
+ updateConfig(partial: any): Promise<void>;
179
+ /**
180
+ * Optional: Handle configuration changes
181
+ * Override this to react to runtime configuration updates
182
+ */
183
+ protected onConfigChange?(newConfig: any, oldConfig: any): Promise<void>;
184
+ /**
185
+ * Resolve configuration from all sources
186
+ * Priority: constructor > env > files > defaults
187
+ */
188
+ private resolveConfiguration;
138
189
  initialize(context: AugmentationContext): Promise<void>;
139
190
  /**
140
191
  * Override this in subclasses for initialization logic
@@ -171,6 +222,12 @@ export declare abstract class BaseAugmentation implements BrainyAugmentation {
171
222
  */
172
223
  protected log(message: string, level?: 'info' | 'warn' | 'error'): void;
173
224
  }
225
+ /**
226
+ * Alias for backward compatibility
227
+ * ConfigurableAugmentation is now merged into BaseAugmentation
228
+ * @deprecated Use BaseAugmentation instead
229
+ */
230
+ export declare const ConfigurableAugmentation: typeof BaseAugmentation;
174
231
  /**
175
232
  * Registry for managing augmentations
176
233
  */
@@ -217,6 +274,28 @@ export declare class AugmentationRegistry {
217
274
  * Get augmentations by name
218
275
  */
219
276
  get(name: string): BrainyAugmentation | undefined;
277
+ /**
278
+ * Discover augmentation parameters and schemas
279
+ * Critical for tools like brain-cloud to generate UIs
280
+ */
281
+ discover(name?: string): any;
282
+ /**
283
+ * Get configuration schema for an augmentation
284
+ * Enables UI generation for configuration
285
+ */
286
+ getConfigSchema(name: string): any;
287
+ /**
288
+ * Configure an augmentation at runtime
289
+ */
290
+ configure(name: string, config: any): Promise<void>;
291
+ /**
292
+ * Get metrics for an augmentation
293
+ */
294
+ metrics(name?: string): any;
295
+ /**
296
+ * Get health status
297
+ */
298
+ health(): any;
220
299
  /**
221
300
  * Shutdown all augmentations
222
301
  */
@@ -5,22 +5,89 @@
5
5
  * Each augmentation knows its place and when to execute automatically.
6
6
  *
7
7
  * The Vision: Components that enhance Brainy's capabilities seamlessly
8
- * - WAL: Adds durability to storage operations
9
8
  * - RequestDeduplicator: Prevents duplicate concurrent requests
10
9
  * - ConnectionPool: Optimizes cloud storage throughput
11
10
  * - IntelligentVerbScoring: Enhances relationship analysis
12
11
  * - StreamingPipeline: Enables unlimited data processing
13
12
  */
13
+ import { AugmentationConfigResolver } from './configResolver.js';
14
14
  /**
15
15
  * Base class for augmentations with common functionality
16
+ *
17
+ * This is the unified base class that combines the features of both
18
+ * BaseAugmentation and ConfigurableAugmentation. All augmentations
19
+ * should extend this class for consistent configuration support.
16
20
  */
17
21
  export class BaseAugmentation {
18
- constructor() {
22
+ /**
23
+ * Constructor with optional configuration
24
+ * @param config Optional configuration to override defaults
25
+ */
26
+ constructor(config) {
19
27
  // Metadata for augmentation listing and management
20
28
  this.category = 'core';
21
29
  this.description = '';
22
30
  this.enabled = true;
23
31
  this.isInitialized = false;
32
+ this.config = {};
33
+ // Only resolve configuration if getManifest is implemented
34
+ if (this.getManifest) {
35
+ this.config = this.resolveConfiguration(config);
36
+ }
37
+ else if (config) {
38
+ // Legacy support: direct config assignment for augmentations without manifests
39
+ this.config = config;
40
+ }
41
+ }
42
+ /**
43
+ * Get current configuration
44
+ */
45
+ getConfig() {
46
+ return { ...this.config };
47
+ }
48
+ /**
49
+ * Update configuration at runtime
50
+ * @param partial Partial configuration to merge
51
+ */
52
+ async updateConfig(partial) {
53
+ if (!this.configResolver) {
54
+ // For legacy augmentations without manifest, just merge config
55
+ const oldConfig = this.config;
56
+ this.config = { ...this.config, ...partial };
57
+ if (this.onConfigChange) {
58
+ await this.onConfigChange(this.config, oldConfig);
59
+ }
60
+ return;
61
+ }
62
+ const oldConfig = this.config;
63
+ try {
64
+ // Use resolver to update and validate
65
+ this.config = this.configResolver.updateRuntime(partial);
66
+ // Call config change handler if implemented
67
+ if (this.onConfigChange) {
68
+ await this.onConfigChange(this.config, oldConfig);
69
+ }
70
+ }
71
+ catch (error) {
72
+ // Revert on error
73
+ this.config = oldConfig;
74
+ throw error;
75
+ }
76
+ }
77
+ /**
78
+ * Resolve configuration from all sources
79
+ * Priority: constructor > env > files > defaults
80
+ */
81
+ resolveConfiguration(constructorConfig) {
82
+ const manifest = this.getManifest();
83
+ // Create config resolver
84
+ this.configResolver = new AugmentationConfigResolver({
85
+ augmentationId: manifest.id,
86
+ schema: manifest.configSchema,
87
+ defaults: manifest.configDefaults
88
+ });
89
+ // Resolve configuration from all sources
90
+ return this.configResolver.resolve(constructorConfig);
24
91
  }
25
92
  async initialize(context) {
26
93
  this.context = context;
@@ -58,6 +125,12 @@ export class BaseAugmentation {
58
125
  }
59
126
  }
60
127
  }
128
+ /**
129
+ * Alias for backward compatibility
130
+ * ConfigurableAugmentation is now merged into BaseAugmentation
131
+ * @deprecated Use BaseAugmentation instead
132
+ */
133
+ export const ConfigurableAugmentation = BaseAugmentation;
61
134
  /**
62
135
  * Registry for managing augmentations
63
136
  */
@@ -150,6 +223,90 @@ export class AugmentationRegistry {
150
223
  get(name) {
151
224
  return this.augmentations.find(aug => aug.name === name);
152
225
  }
226
+ /**
227
+ * Discover augmentation parameters and schemas
228
+ * Critical for tools like brain-cloud to generate UIs
229
+ */
230
+ discover(name) {
231
+ if (name) {
232
+ const aug = this.get(name);
233
+ if (!aug)
234
+ return null;
235
+ const baseAug = aug;
236
+ return {
237
+ name: aug.name,
238
+ operations: aug.operations,
239
+ priority: aug.priority,
240
+ timing: aug.timing,
241
+ metadata: aug.metadata,
242
+ manifest: baseAug.getManifest ? baseAug.getManifest() : undefined,
243
+ parameters: baseAug.getParameterSchema ?
244
+ aug.operations.reduce((acc, op) => {
245
+ acc[op] = baseAug.getParameterSchema(op);
246
+ return acc;
247
+ }, {}) : undefined,
248
+ operationInfo: baseAug.getOperationInfo ? baseAug.getOperationInfo() : undefined,
249
+ config: baseAug.getConfig ? baseAug.getConfig() : undefined
250
+ };
251
+ }
252
+ // Return all augmentations discovery info
253
+ return this.augmentations.map(aug => this.discover(aug.name));
254
+ }
255
+ /**
256
+ * Get configuration schema for an augmentation
257
+ * Enables UI generation for configuration
258
+ */
259
+ getConfigSchema(name) {
260
+ const aug = this.get(name);
261
+ if (!aug || !aug.getManifest)
262
+ return null;
263
+ const manifest = aug.getManifest();
264
+ return manifest?.configSchema;
265
+ }
266
+ /**
267
+ * Configure an augmentation at runtime
268
+ */
269
+ async configure(name, config) {
270
+ const aug = this.get(name);
271
+ if (!aug || !aug.updateConfig) {
272
+ throw new Error(`Augmentation ${name} does not support configuration`);
273
+ }
274
+ await aug.updateConfig(config);
275
+ }
276
+ /**
277
+ * Get metrics for an augmentation
278
+ */
279
+ metrics(name) {
280
+ if (name) {
281
+ const aug = this.get(name);
282
+ if (!aug || !aug.metrics)
283
+ return null;
284
+ return aug.metrics();
285
+ }
286
+ // Return all metrics
287
+ const allMetrics = {};
288
+ for (const aug of this.augmentations) {
289
+ const a = aug;
290
+ if (a.metrics) {
291
+ allMetrics[aug.name] = a.metrics();
292
+ }
293
+ }
294
+ return allMetrics;
295
+ }
296
+ /**
297
+ * Get health status
298
+ */
299
+ health() {
300
+ const health = {
301
+ overall: 'healthy',
302
+ augmentations: {}
303
+ };
304
+ for (const aug of this.augmentations) {
305
+ const a = aug;
306
+ health.augmentations[aug.name] = a.health ? a.health() : 'unknown';
307
+ }
308
+ return health;
309
+ }
153
310
  /**
154
311
  * Shutdown all augmentations
155
312
  */
@@ -1,13 +1,14 @@
1
1
  /**
2
2
  * Cache Augmentation - Optional Search Result Caching
3
3
  *
4
- * Replaces the hardcoded SearchCache in BrainyData with an optional augmentation.
4
+ * Replaces the hardcoded SearchCache in Brainy with an optional augmentation.
5
5
  * This reduces core size and allows custom cache implementations.
6
6
  *
7
7
  * Zero-config: Automatically enabled with sensible defaults
8
8
  * Can be disabled or customized via augmentation registry
9
9
  */
10
10
  import { BaseAugmentation } from './brainyAugmentation.js';
11
+ import { AugmentationManifest } from './manifest.js';
11
12
  import { SearchCache } from '../utils/searchCache.js';
12
13
  import type { GraphNoun } from '../types/graphTypes.js';
13
14
  export interface CacheConfig {
@@ -29,13 +30,13 @@ export declare class CacheAugmentation extends BaseAugmentation {
29
30
  readonly name = "cache";
30
31
  readonly timing: "around";
31
32
  readonly metadata: "none";
32
- operations: ("search" | "add" | "delete" | "clear" | "all")[];
33
+ operations: ("search" | "find" | "similar" | "add" | "update" | "delete" | "clear" | "all")[];
33
34
  readonly priority = 50;
34
35
  readonly category: "core";
35
36
  readonly description = "Transparent search result caching with automatic invalidation";
36
37
  private searchCache;
37
- private config;
38
38
  constructor(config?: CacheConfig);
39
+ getManifest(): AugmentationManifest;
39
40
  protected onInitialize(): Promise<void>;
40
41
  protected onShutdown(): Promise<void>;
41
42
  /**
@@ -70,9 +71,9 @@ export declare class CacheAugmentation extends BaseAugmentation {
70
71
  */
71
72
  clear(): void;
72
73
  /**
73
- * Update cache configuration
74
+ * Handle runtime configuration changes
74
75
  */
75
- updateConfig(config: Partial<CacheConfig>): void;
76
+ protected onConfigChange(newConfig: CacheConfig, oldConfig: CacheConfig): Promise<void>;
76
77
  /**
77
78
  * Clean up expired entries
78
79
  */
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Cache Augmentation - Optional Search Result Caching
3
3
  *
4
- * Replaces the hardcoded SearchCache in BrainyData with an optional augmentation.
4
+ * Replaces the hardcoded SearchCache in Brainy with an optional augmentation.
5
5
  * This reduces core size and allows custom cache implementations.
6
6
  *
7
7
  * Zero-config: Automatically enabled with sensible defaults
@@ -19,23 +19,116 @@ import { SearchCache } from '../utils/searchCache.js';
19
19
  * - Zero-config with smart defaults
20
20
  */
21
21
  export class CacheAugmentation extends BaseAugmentation {
22
- constructor(config = {}) {
23
- super();
22
+ constructor(config) {
23
+ super(config);
24
24
  this.name = 'cache';
25
25
  this.timing = 'around';
26
26
  this.metadata = 'none'; // Cache doesn't access metadata
27
- this.operations = ['search', 'add', 'delete', 'clear', 'all'];
27
+ this.operations = ['search', 'find', 'similar', 'add', 'update', 'delete', 'clear', 'all'];
28
28
  this.priority = 50; // Mid-priority, runs after data operations
29
29
  // Augmentation metadata
30
30
  this.category = 'core';
31
31
  this.description = 'Transparent search result caching with automatic invalidation';
32
32
  this.searchCache = null;
33
- this.config = {
34
- maxSize: 1000,
35
- ttl: 300000, // 5 minutes default
36
- enabled: true,
37
- invalidateOnWrite: true,
38
- ...config
33
+ }
34
+ getManifest() {
35
+ return {
36
+ id: 'cache',
37
+ name: 'Cache',
38
+ version: '2.0.0',
39
+ description: 'Intelligent caching for search and query operations',
40
+ longDescription: 'Provides transparent caching for search results with automatic invalidation on data changes. Significantly improves performance for repeated queries while maintaining data consistency.',
41
+ category: 'performance',
42
+ configSchema: {
43
+ type: 'object',
44
+ properties: {
45
+ enabled: {
46
+ type: 'boolean',
47
+ default: true,
48
+ description: 'Enable or disable caching'
49
+ },
50
+ maxSize: {
51
+ type: 'number',
52
+ default: 1000,
53
+ minimum: 10,
54
+ maximum: 100000,
55
+ description: 'Maximum number of cached entries'
56
+ },
57
+ ttl: {
58
+ type: 'number',
59
+ default: 300000, // 5 minutes
60
+ minimum: 1000, // 1 second
61
+ maximum: 3600000, // 1 hour
62
+ description: 'Time to live for cache entries in milliseconds'
63
+ },
64
+ invalidateOnWrite: {
65
+ type: 'boolean',
66
+ default: true,
67
+ description: 'Automatically invalidate cache on data modifications'
68
+ }
69
+ },
70
+ additionalProperties: false
71
+ },
72
+ configDefaults: {
73
+ enabled: true,
74
+ maxSize: 1000,
75
+ ttl: 300000,
76
+ invalidateOnWrite: true
77
+ },
78
+ configExamples: [
79
+ {
80
+ name: 'High Performance',
81
+ description: 'Large cache with longer TTL for read-heavy workloads',
82
+ config: {
83
+ enabled: true,
84
+ maxSize: 10000,
85
+ ttl: 1800000, // 30 minutes
86
+ invalidateOnWrite: true
87
+ }
88
+ },
89
+ {
90
+ name: 'Conservative',
91
+ description: 'Small cache with short TTL for frequently changing data',
92
+ config: {
93
+ enabled: true,
94
+ maxSize: 100,
95
+ ttl: 60000, // 1 minute
96
+ invalidateOnWrite: true
97
+ }
98
+ }
99
+ ],
100
+ minBrainyVersion: '2.0.0',
101
+ keywords: ['cache', 'performance', 'search', 'optimization'],
102
+ documentation: 'https://docs.brainy.dev/augmentations/cache',
103
+ status: 'stable',
104
+ performance: {
105
+ memoryUsage: 'medium',
106
+ cpuUsage: 'low',
107
+ networkUsage: 'none'
108
+ },
109
+ features: ['search-caching', 'auto-invalidation', 'ttl-support', 'memory-management'],
110
+ enhancedOperations: ['search', 'searchText', 'findSimilar'],
111
+ metrics: [
112
+ {
113
+ name: 'cache_hits',
114
+ type: 'counter',
115
+ description: 'Number of cache hits'
116
+ },
117
+ {
118
+ name: 'cache_misses',
119
+ type: 'counter',
120
+ description: 'Number of cache misses'
121
+ },
122
+ {
123
+ name: 'cache_size',
124
+ type: 'gauge',
125
+ description: 'Current cache size'
126
+ }
127
+ ],
128
+ ui: {
129
+ icon: '⚡',
130
+ color: '#FFC107'
131
+ }
39
132
  };
40
133
  }
41
134
  async onInitialize() {
@@ -160,18 +253,21 @@ export class CacheAugmentation extends BaseAugmentation {
160
253
  }
161
254
  }
162
255
  /**
163
- * Update cache configuration
256
+ * Handle runtime configuration changes
164
257
  */
165
- updateConfig(config) {
166
- this.config = { ...this.config, ...config };
167
- if (this.searchCache && this.config.enabled) {
258
+ async onConfigChange(newConfig, oldConfig) {
259
+ if (this.searchCache && newConfig.enabled) {
168
260
  this.searchCache.updateConfig({
169
- maxSize: this.config.maxSize,
170
- maxAge: this.config.ttl, // SearchCache uses maxAge
171
- enabled: this.config.enabled
261
+ maxSize: newConfig.maxSize,
262
+ maxAge: newConfig.ttl, // SearchCache uses maxAge
263
+ enabled: newConfig.enabled
172
264
  });
173
265
  this.log('Cache configuration updated');
174
266
  }
267
+ else if (!newConfig.enabled && this.searchCache) {
268
+ this.searchCache.clear();
269
+ this.log('Cache disabled and cleared');
270
+ }
175
271
  }
176
272
  /**
177
273
  * Clean up expired entries
@@ -52,12 +52,12 @@ export {};
52
52
  * Example usage:
53
53
  *
54
54
  * // Server instance
55
- * const serverBrain = new BrainyData()
55
+ * const serverBrain = new Brainy()
56
56
  * serverBrain.augmentations.register(new APIServerAugmentation())
57
57
  * await serverBrain.init()
58
58
  *
59
59
  * // Client instance
60
- * const clientBrain = new BrainyData()
60
+ * const clientBrain = new Brainy()
61
61
  * const conduit = new WebSocketConduitAugmentation()
62
62
  * clientBrain.augmentations.register(conduit)
63
63
  * await clientBrain.init()
@@ -213,12 +213,12 @@ export class WebSocketConduitAugmentation extends BaseConduitAugmentation {
213
213
  * Example usage:
214
214
  *
215
215
  * // Server instance
216
- * const serverBrain = new BrainyData()
216
+ * const serverBrain = new Brainy()
217
217
  * serverBrain.augmentations.register(new APIServerAugmentation())
218
218
  * await serverBrain.init()
219
219
  *
220
220
  * // Client instance
221
- * const clientBrain = new BrainyData()
221
+ * const clientBrain = new Brainy()
222
222
  * const conduit = new WebSocketConduitAugmentation()
223
223
  * clientBrain.augmentations.register(conduit)
224
224
  * await clientBrain.init()