@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.
- package/CHANGELOG.md +18 -0
- package/README.md +249 -152
- package/dist/api/ConfigAPI.d.ts +67 -0
- package/dist/api/ConfigAPI.js +166 -0
- package/dist/api/DataAPI.d.ts +123 -0
- package/dist/api/DataAPI.js +391 -0
- package/dist/api/SecurityAPI.d.ts +50 -0
- package/dist/api/SecurityAPI.js +139 -0
- package/dist/api/UniversalImportAPI.d.ts +134 -0
- package/dist/api/UniversalImportAPI.js +615 -0
- package/dist/augmentationManager.js +12 -7
- package/dist/augmentationPipeline.d.ts +0 -61
- package/dist/augmentationPipeline.js +0 -87
- package/dist/augmentationRegistry.d.ts +1 -1
- package/dist/augmentationRegistry.js +1 -1
- package/dist/augmentations/apiServerAugmentation.d.ts +27 -1
- package/dist/augmentations/apiServerAugmentation.js +288 -7
- package/dist/augmentations/auditLogAugmentation.d.ts +109 -0
- package/dist/augmentations/auditLogAugmentation.js +358 -0
- package/dist/augmentations/batchProcessingAugmentation.d.ts +3 -2
- package/dist/augmentations/batchProcessingAugmentation.js +123 -22
- package/dist/augmentations/brainyAugmentation.d.ts +87 -8
- package/dist/augmentations/brainyAugmentation.js +159 -2
- package/dist/augmentations/cacheAugmentation.d.ts +6 -5
- package/dist/augmentations/cacheAugmentation.js +113 -17
- package/dist/augmentations/conduitAugmentations.d.ts +2 -2
- package/dist/augmentations/conduitAugmentations.js +2 -2
- package/dist/augmentations/configResolver.d.ts +122 -0
- package/dist/augmentations/configResolver.js +440 -0
- package/dist/augmentations/connectionPoolAugmentation.d.ts +3 -1
- package/dist/augmentations/connectionPoolAugmentation.js +37 -12
- package/dist/augmentations/defaultAugmentations.d.ts +9 -11
- package/dist/augmentations/defaultAugmentations.js +4 -11
- package/dist/augmentations/discovery/catalogDiscovery.d.ts +142 -0
- package/dist/augmentations/discovery/catalogDiscovery.js +249 -0
- package/dist/augmentations/discovery/localDiscovery.d.ts +84 -0
- package/dist/augmentations/discovery/localDiscovery.js +246 -0
- package/dist/augmentations/discovery/runtimeLoader.d.ts +97 -0
- package/dist/augmentations/discovery/runtimeLoader.js +337 -0
- package/dist/augmentations/discovery.d.ts +152 -0
- package/dist/augmentations/discovery.js +441 -0
- package/dist/augmentations/display/intelligentComputation.d.ts +1 -1
- package/dist/augmentations/display/intelligentComputation.js +4 -4
- package/dist/augmentations/entityRegistryAugmentation.d.ts +3 -1
- package/dist/augmentations/entityRegistryAugmentation.js +5 -1
- package/dist/augmentations/indexAugmentation.d.ts +3 -3
- package/dist/augmentations/indexAugmentation.js +2 -2
- package/dist/augmentations/intelligentVerbScoringAugmentation.d.ts +22 -6
- package/dist/augmentations/intelligentVerbScoringAugmentation.js +106 -23
- package/dist/augmentations/manifest.d.ts +176 -0
- package/dist/augmentations/manifest.js +8 -0
- package/dist/augmentations/marketplace/AugmentationMarketplace.d.ts +168 -0
- package/dist/augmentations/marketplace/AugmentationMarketplace.js +329 -0
- package/dist/augmentations/marketplace/cli.d.ts +47 -0
- package/dist/augmentations/marketplace/cli.js +265 -0
- package/dist/augmentations/metricsAugmentation.d.ts +3 -3
- package/dist/augmentations/metricsAugmentation.js +2 -2
- package/dist/augmentations/monitoringAugmentation.d.ts +3 -3
- package/dist/augmentations/monitoringAugmentation.js +2 -2
- package/dist/augmentations/neuralImport.d.ts +1 -1
- package/dist/augmentations/rateLimitAugmentation.d.ts +82 -0
- package/dist/augmentations/rateLimitAugmentation.js +321 -0
- package/dist/augmentations/requestDeduplicatorAugmentation.d.ts +2 -2
- package/dist/augmentations/requestDeduplicatorAugmentation.js +1 -1
- package/dist/augmentations/storageAugmentation.d.ts +1 -1
- package/dist/augmentations/storageAugmentation.js +2 -2
- package/dist/augmentations/storageAugmentations.d.ts +37 -8
- package/dist/augmentations/storageAugmentations.js +204 -15
- package/dist/augmentations/synapseAugmentation.d.ts +1 -1
- package/dist/augmentations/synapseAugmentation.js +35 -16
- package/dist/augmentations/typeMatching/intelligentTypeMatcher.d.ts +39 -59
- package/dist/augmentations/typeMatching/intelligentTypeMatcher.js +103 -389
- package/dist/augmentations/universalDisplayAugmentation.d.ts +2 -2
- package/dist/augmentations/universalDisplayAugmentation.js +2 -2
- package/dist/brainy-unified.d.ts +106 -0
- package/dist/brainy-unified.js +327 -0
- package/dist/brainy.d.ts +273 -0
- package/dist/brainy.js +1181 -0
- package/dist/brainyData.d.ts +29 -72
- package/dist/brainyData.js +350 -304
- package/dist/brainyDataV3.d.ts +186 -0
- package/dist/brainyDataV3.js +337 -0
- package/dist/browserFramework.d.ts +6 -6
- package/dist/browserFramework.js +11 -8
- package/dist/browserFramework.minimal.d.ts +5 -5
- package/dist/browserFramework.minimal.js +11 -8
- package/dist/config/index.d.ts +2 -2
- package/dist/config/index.js +3 -3
- package/dist/config/modelAutoConfig.d.ts +6 -7
- package/dist/config/modelAutoConfig.js +17 -76
- package/dist/cortex/backupRestore.d.ts +2 -2
- package/dist/cortex/backupRestore.js +85 -27
- package/dist/cortex/healthCheck.d.ts +2 -2
- package/dist/cortex/neuralImport.d.ts +2 -2
- package/dist/cortex/neuralImport.js +18 -13
- package/dist/cortex/performanceMonitor.d.ts +2 -2
- package/dist/critical/model-guardian.d.ts +4 -0
- package/dist/critical/model-guardian.js +31 -11
- package/dist/demo.d.ts +4 -4
- package/dist/demo.js +7 -7
- package/dist/distributed/cacheSync.d.ts +112 -0
- package/dist/distributed/cacheSync.js +265 -0
- package/dist/distributed/coordinator.d.ts +193 -0
- package/dist/distributed/coordinator.js +548 -0
- package/dist/distributed/httpTransport.d.ts +120 -0
- package/dist/distributed/httpTransport.js +446 -0
- package/dist/distributed/index.d.ts +8 -0
- package/dist/distributed/index.js +5 -0
- package/dist/distributed/networkTransport.d.ts +132 -0
- package/dist/distributed/networkTransport.js +633 -0
- package/dist/distributed/queryPlanner.d.ts +104 -0
- package/dist/distributed/queryPlanner.js +327 -0
- package/dist/distributed/readWriteSeparation.d.ts +134 -0
- package/dist/distributed/readWriteSeparation.js +350 -0
- package/dist/distributed/shardManager.d.ts +114 -0
- package/dist/distributed/shardManager.js +357 -0
- package/dist/distributed/shardMigration.d.ts +110 -0
- package/dist/distributed/shardMigration.js +289 -0
- package/dist/distributed/storageDiscovery.d.ts +160 -0
- package/dist/distributed/storageDiscovery.js +551 -0
- package/dist/embeddings/EmbeddingManager.d.ts +0 -4
- package/dist/embeddings/EmbeddingManager.js +21 -26
- package/dist/errors/brainyError.d.ts +5 -1
- package/dist/errors/brainyError.js +12 -0
- package/dist/examples/basicUsage.js +3 -3
- package/dist/graph/graphAdjacencyIndex.d.ts +96 -0
- package/dist/graph/graphAdjacencyIndex.js +288 -0
- package/dist/graph/pathfinding.js +4 -2
- package/dist/hnsw/scaledHNSWSystem.js +11 -2
- package/dist/importManager.js +6 -3
- package/dist/index.d.ts +12 -21
- package/dist/index.js +14 -22
- package/dist/mcp/brainyMCPAdapter.d.ts +4 -4
- package/dist/mcp/brainyMCPAdapter.js +5 -5
- package/dist/mcp/brainyMCPService.d.ts +3 -3
- package/dist/mcp/brainyMCPService.js +3 -11
- package/dist/mcp/mcpAugmentationToolset.js +20 -30
- package/dist/neural/embeddedPatterns.d.ts +1 -1
- package/dist/neural/embeddedPatterns.js +2 -2
- package/dist/neural/entityExtractor.d.ts +65 -0
- package/dist/neural/entityExtractor.js +316 -0
- package/dist/neural/improvedNeuralAPI.js +90 -79
- package/dist/neural/naturalLanguageProcessor.d.ts +155 -10
- package/dist/neural/naturalLanguageProcessor.js +941 -66
- package/dist/neural/naturalLanguageProcessorStatic.d.ts +2 -2
- package/dist/neural/naturalLanguageProcessorStatic.js +3 -3
- package/dist/neural/neuralAPI.js +8 -2
- package/dist/neural/patternLibrary.d.ts +57 -3
- package/dist/neural/patternLibrary.js +348 -13
- package/dist/neural/staticPatternMatcher.d.ts +2 -2
- package/dist/neural/staticPatternMatcher.js +2 -2
- package/dist/shared/default-augmentations.d.ts +3 -3
- package/dist/shared/default-augmentations.js +5 -5
- package/dist/storage/adapters/fileSystemStorage.d.ts +4 -0
- package/dist/storage/adapters/fileSystemStorage.js +54 -1
- package/dist/storage/adapters/memoryStorage.js +13 -8
- package/dist/storage/backwardCompatibility.d.ts +10 -78
- package/dist/storage/backwardCompatibility.js +17 -132
- package/dist/storage/baseStorage.d.ts +6 -0
- package/dist/storage/baseStorage.js +17 -0
- package/dist/storage/cacheManager.js +2 -2
- package/dist/storage/readOnlyOptimizations.js +8 -3
- package/dist/streaming/pipeline.d.ts +154 -0
- package/dist/streaming/pipeline.js +551 -0
- package/dist/triple/TripleIntelligence.d.ts +25 -110
- package/dist/triple/TripleIntelligence.js +4 -574
- package/dist/triple/TripleIntelligenceSystem.d.ts +159 -0
- package/dist/triple/TripleIntelligenceSystem.js +519 -0
- package/dist/types/apiTypes.d.ts +278 -0
- package/dist/types/apiTypes.js +33 -0
- package/dist/types/brainy.types.d.ts +308 -0
- package/dist/types/brainy.types.js +8 -0
- package/dist/types/brainyDataInterface.d.ts +3 -3
- package/dist/types/brainyDataInterface.js +2 -2
- package/dist/types/graphTypes.js +2 -2
- package/dist/utils/cacheAutoConfig.d.ts +3 -3
- package/dist/utils/embedding.js +8 -14
- package/dist/utils/enhancedLogger.d.ts +104 -0
- package/dist/utils/enhancedLogger.js +232 -0
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +1 -1
- package/dist/utils/intelligentTypeMapper.d.ts +60 -0
- package/dist/utils/intelligentTypeMapper.js +349 -0
- package/dist/utils/metadataIndex.d.ts +118 -1
- package/dist/utils/metadataIndex.js +539 -16
- package/dist/utils/paramValidation.d.ts +39 -0
- package/dist/utils/paramValidation.js +192 -0
- package/dist/utils/rateLimiter.d.ts +160 -0
- package/dist/utils/rateLimiter.js +271 -0
- package/dist/utils/statistics.d.ts +4 -4
- package/dist/utils/statistics.js +3 -3
- package/dist/utils/structuredLogger.d.ts +146 -0
- package/dist/utils/structuredLogger.js +394 -0
- package/dist/utils/textEncoding.js +2 -1
- package/dist/utils/typeValidation.d.ts +34 -0
- package/dist/utils/typeValidation.js +247 -0
- package/package.json +14 -6
- package/scripts/download-models.cjs +6 -15
- package/dist/augmentations/walAugmentation.d.ts +0 -111
- package/dist/augmentations/walAugmentation.js +0 -519
- package/dist/chat/BrainyChat.d.ts +0 -121
- package/dist/chat/BrainyChat.js +0 -396
- package/dist/chat/ChatCLI.d.ts +0 -61
- 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 (
|
|
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
|
|
57
|
+
* Called once during Brainy initialization
|
|
58
58
|
*
|
|
59
|
-
* @param context - The
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
-
*
|
|
74
|
+
* Handle runtime configuration changes
|
|
74
75
|
*/
|
|
75
|
-
|
|
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
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
*
|
|
256
|
+
* Handle runtime configuration changes
|
|
164
257
|
*/
|
|
165
|
-
|
|
166
|
-
this.
|
|
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:
|
|
170
|
-
maxAge:
|
|
171
|
-
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
|
|
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
|
|
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
|
|
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
|
|
221
|
+
* const clientBrain = new Brainy()
|
|
222
222
|
* const conduit = new WebSocketConduitAugmentation()
|
|
223
223
|
* clientBrain.augmentations.register(conduit)
|
|
224
224
|
* await clientBrain.init()
|