@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
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Monitoring Augmentation - Optional Health & Performance Monitoring
3
3
  *
4
- * Replaces the hardcoded HealthMonitor in BrainyData with an optional augmentation.
4
+ * Replaces the hardcoded HealthMonitor in Brainy with an optional augmentation.
5
5
  * Provides health checks, performance monitoring, and distributed system tracking.
6
6
  *
7
7
  * Zero-config: Automatically enabled for distributed deployments
@@ -31,11 +31,11 @@ export declare class MonitoringAugmentation extends BaseAugmentation {
31
31
  readonly metadata: "readonly";
32
32
  readonly name = "monitoring";
33
33
  readonly timing: "after";
34
- operations: ("search" | "add" | "delete" | "all")[];
34
+ operations: ("search" | "find" | "similar" | "add" | "update" | "delete" | "relate" | "unrelate" | "all")[];
35
35
  readonly priority = 30;
36
36
  private healthMonitor;
37
37
  private configManager;
38
- private config;
38
+ protected config: MonitoringConfig;
39
39
  private requestStartTimes;
40
40
  constructor(config?: MonitoringConfig);
41
41
  protected onInitialize(): Promise<void>;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Monitoring Augmentation - Optional Health & Performance Monitoring
3
3
  *
4
- * Replaces the hardcoded HealthMonitor in BrainyData with an optional augmentation.
4
+ * Replaces the hardcoded HealthMonitor in Brainy with an optional augmentation.
5
5
  * Provides health checks, performance monitoring, and distributed system tracking.
6
6
  *
7
7
  * Zero-config: Automatically enabled for distributed deployments
@@ -26,7 +26,7 @@ export class MonitoringAugmentation extends BaseAugmentation {
26
26
  this.metadata = 'readonly'; // Reads metadata for monitoring
27
27
  this.name = 'monitoring';
28
28
  this.timing = 'after';
29
- this.operations = ['search', 'add', 'delete', 'all'];
29
+ this.operations = ['search', 'find', 'similar', 'add', 'update', 'delete', 'relate', 'unrelate', 'all'];
30
30
  this.priority = 30; // Low priority, observability layer
31
31
  this.healthMonitor = null;
32
32
  this.configManager = null;
@@ -61,7 +61,7 @@ export declare class NeuralImportAugmentation extends BaseAugmentation {
61
61
  };
62
62
  operations: ("add" | "addNoun" | "addVerb" | "all")[];
63
63
  readonly priority = 80;
64
- private config;
64
+ protected config: NeuralImportConfig;
65
65
  private analysisCache;
66
66
  private typeMatcher;
67
67
  constructor(config?: Partial<NeuralImportConfig>);
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Rate Limiting Augmentation
3
+ * Provides configurable rate limiting for Brainy operations
4
+ */
5
+ import { BaseAugmentation } from './brainyAugmentation.js';
6
+ import { AugmentationManifest } from './manifest.js';
7
+ export interface RateLimitConfig {
8
+ enabled?: boolean;
9
+ limits?: {
10
+ searches?: number;
11
+ writes?: number;
12
+ reads?: number;
13
+ deletes?: number;
14
+ };
15
+ windowMs?: number;
16
+ skipSuccessfulRequests?: boolean;
17
+ skipFailedRequests?: boolean;
18
+ keyGenerator?: (context: any) => string;
19
+ }
20
+ /**
21
+ * Rate Limit Augmentation
22
+ */
23
+ export declare class RateLimitAugmentation extends BaseAugmentation {
24
+ readonly name = "rateLimiter";
25
+ readonly timing: "before";
26
+ readonly metadata: "none";
27
+ operations: any;
28
+ readonly priority = 10;
29
+ readonly category: "core";
30
+ readonly description = "Provides rate limiting for Brainy operations";
31
+ private limiters;
32
+ private windowMs;
33
+ constructor(config?: RateLimitConfig);
34
+ getManifest(): AugmentationManifest;
35
+ /**
36
+ * Initialize rate limiters for each operation type
37
+ */
38
+ private initializeLimiters;
39
+ /**
40
+ * Default key generator (could be IP, user ID, etc.)
41
+ */
42
+ private defaultKeyGenerator;
43
+ /**
44
+ * Check if request should be rate limited
45
+ */
46
+ private checkRateLimit;
47
+ /**
48
+ * Get remaining requests for an operation
49
+ */
50
+ private getRemainingRequests;
51
+ /**
52
+ * Get time until reset
53
+ */
54
+ private getResetTime;
55
+ protected onInitialize(): Promise<void>;
56
+ protected onShutdown(): Promise<void>;
57
+ /**
58
+ * Execute augmentation - apply rate limiting
59
+ */
60
+ execute<T = any>(operation: string, params: any, next: () => Promise<T>): Promise<T>;
61
+ /**
62
+ * Get rate limit statistics
63
+ */
64
+ getStats(): {
65
+ operations: Record<string, {
66
+ activeKeys: number;
67
+ totalRequests: number;
68
+ }>;
69
+ };
70
+ /**
71
+ * Clear all rate limit entries
72
+ */
73
+ clear(): void;
74
+ /**
75
+ * Clear expired entries (cleanup)
76
+ */
77
+ cleanup(): void;
78
+ }
79
+ /**
80
+ * Create rate limit augmentation
81
+ */
82
+ export declare function createRateLimitAugmentation(config?: RateLimitConfig): RateLimitAugmentation;
@@ -0,0 +1,321 @@
1
+ /**
2
+ * Rate Limiting Augmentation
3
+ * Provides configurable rate limiting for Brainy operations
4
+ */
5
+ import { BaseAugmentation } from './brainyAugmentation.js';
6
+ /**
7
+ * Rate Limit Augmentation
8
+ */
9
+ export class RateLimitAugmentation extends BaseAugmentation {
10
+ constructor(config = {}) {
11
+ super(config);
12
+ this.name = 'rateLimiter';
13
+ this.timing = 'before';
14
+ this.metadata = 'none';
15
+ this.operations = ['search', 'find', 'add', 'update', 'delete', 'get'];
16
+ this.priority = 10; // High priority, runs early
17
+ // Augmentation metadata
18
+ this.category = 'core'; // Use 'core' as security isn't a valid category
19
+ this.description = 'Provides rate limiting for Brainy operations';
20
+ this.limiters = new Map();
21
+ // Merge with defaults
22
+ this.config = {
23
+ enabled: config.enabled ?? true,
24
+ limits: {
25
+ searches: config.limits?.searches ?? 1000,
26
+ writes: config.limits?.writes ?? 100,
27
+ reads: config.limits?.reads ?? 5000,
28
+ deletes: config.limits?.deletes ?? 50
29
+ },
30
+ windowMs: config.windowMs ?? 60000, // 1 minute default
31
+ skipSuccessfulRequests: config.skipSuccessfulRequests ?? false,
32
+ skipFailedRequests: config.skipFailedRequests ?? true,
33
+ keyGenerator: config.keyGenerator || this.defaultKeyGenerator
34
+ };
35
+ this.windowMs = this.config.windowMs;
36
+ // Initialize operation limiters
37
+ this.initializeLimiters();
38
+ }
39
+ getManifest() {
40
+ return {
41
+ id: 'rate-limiter',
42
+ name: 'Rate Limiter',
43
+ version: '1.0.0',
44
+ description: 'Configurable rate limiting for API operations',
45
+ longDescription: 'Provides per-operation rate limiting with configurable windows and limits. Helps prevent abuse and ensures fair resource usage.',
46
+ category: 'core',
47
+ configSchema: {
48
+ type: 'object',
49
+ properties: {
50
+ enabled: {
51
+ type: 'boolean',
52
+ default: true,
53
+ description: 'Enable or disable rate limiting'
54
+ },
55
+ limits: {
56
+ type: 'object',
57
+ properties: {
58
+ searches: {
59
+ type: 'number',
60
+ default: 1000,
61
+ description: 'Search operations per minute'
62
+ },
63
+ writes: {
64
+ type: 'number',
65
+ default: 100,
66
+ description: 'Write operations per minute'
67
+ },
68
+ reads: {
69
+ type: 'number',
70
+ default: 5000,
71
+ description: 'Read operations per minute'
72
+ },
73
+ deletes: {
74
+ type: 'number',
75
+ default: 50,
76
+ description: 'Delete operations per minute'
77
+ }
78
+ }
79
+ },
80
+ windowMs: {
81
+ type: 'number',
82
+ default: 60000,
83
+ description: 'Time window in milliseconds'
84
+ }
85
+ }
86
+ },
87
+ configDefaults: {
88
+ enabled: true,
89
+ limits: {
90
+ searches: 1000,
91
+ writes: 100,
92
+ reads: 5000,
93
+ deletes: 50
94
+ },
95
+ windowMs: 60000
96
+ },
97
+ minBrainyVersion: '3.0.0',
98
+ keywords: ['rate-limit', 'security', 'throttle'],
99
+ documentation: 'https://docs.brainy.dev/augmentations/rate-limit',
100
+ status: 'stable',
101
+ performance: {
102
+ memoryUsage: 'low',
103
+ cpuUsage: 'low',
104
+ networkUsage: 'none'
105
+ },
106
+ features: ['per-operation-limits', 'configurable-windows', 'key-based-limiting'],
107
+ enhancedOperations: ['search', 'add', 'update', 'delete', 'get'],
108
+ metrics: [
109
+ {
110
+ name: 'rate_limit_exceeded',
111
+ type: 'counter',
112
+ description: 'Number of rate limit violations'
113
+ },
114
+ {
115
+ name: 'rate_limit_requests',
116
+ type: 'counter',
117
+ description: 'Total requests checked'
118
+ }
119
+ ]
120
+ };
121
+ }
122
+ /**
123
+ * Initialize rate limiters for each operation type
124
+ */
125
+ initializeLimiters() {
126
+ const operations = ['searches', 'writes', 'reads', 'deletes'];
127
+ for (const op of operations) {
128
+ this.limiters.set(op, new Map());
129
+ }
130
+ }
131
+ /**
132
+ * Default key generator (could be IP, user ID, etc.)
133
+ */
134
+ defaultKeyGenerator(_context) {
135
+ // In a real implementation, this would extract IP or user ID
136
+ return 'default';
137
+ }
138
+ /**
139
+ * Check if request should be rate limited
140
+ */
141
+ checkRateLimit(operation, key) {
142
+ const limiter = this.limiters.get(operation);
143
+ if (!limiter)
144
+ return false;
145
+ const limit = this.config.limits[operation];
146
+ if (!limit)
147
+ return false;
148
+ const now = Date.now();
149
+ let entry = limiter.get(key);
150
+ // Initialize or reset entry
151
+ if (!entry || now >= entry.resetTime) {
152
+ entry = {
153
+ count: 0,
154
+ resetTime: now + this.windowMs
155
+ };
156
+ limiter.set(key, entry);
157
+ }
158
+ // Check if limit exceeded
159
+ if (entry.count >= limit) {
160
+ return true; // Rate limited
161
+ }
162
+ // Increment counter
163
+ entry.count++;
164
+ return false;
165
+ }
166
+ /**
167
+ * Get remaining requests for an operation
168
+ */
169
+ getRemainingRequests(operation, key) {
170
+ const limiter = this.limiters.get(operation);
171
+ if (!limiter)
172
+ return -1;
173
+ const limit = this.config.limits[operation];
174
+ if (!limit)
175
+ return -1;
176
+ const entry = limiter.get(key);
177
+ if (!entry)
178
+ return limit;
179
+ const now = Date.now();
180
+ if (now >= entry.resetTime)
181
+ return limit;
182
+ return Math.max(0, limit - entry.count);
183
+ }
184
+ /**
185
+ * Get time until reset
186
+ */
187
+ getResetTime(operation, key) {
188
+ const limiter = this.limiters.get(operation);
189
+ if (!limiter)
190
+ return 0;
191
+ const entry = limiter.get(key);
192
+ if (!entry)
193
+ return 0;
194
+ const now = Date.now();
195
+ return Math.max(0, entry.resetTime - now);
196
+ }
197
+ async onInitialize() {
198
+ if (!this.config.enabled) {
199
+ this.log('Rate limiter disabled by configuration');
200
+ return;
201
+ }
202
+ this.log(`Rate limiter initialized (window: ${this.windowMs}ms)`);
203
+ // Start cleanup timer
204
+ setInterval(() => {
205
+ this.cleanup();
206
+ }, this.windowMs);
207
+ }
208
+ async onShutdown() {
209
+ this.clear();
210
+ this.log('Rate limiter shut down');
211
+ }
212
+ /**
213
+ * Execute augmentation - apply rate limiting
214
+ */
215
+ async execute(operation, params, next) {
216
+ // If rate limiting is disabled, just pass through
217
+ if (!this.config.enabled) {
218
+ return next();
219
+ }
220
+ // Map operations to rate limit categories
221
+ let rateLimitOperation;
222
+ switch (operation) {
223
+ case 'search':
224
+ case 'find':
225
+ case 'similar':
226
+ rateLimitOperation = 'searches';
227
+ break;
228
+ case 'add':
229
+ case 'update':
230
+ rateLimitOperation = 'writes';
231
+ break;
232
+ case 'delete':
233
+ rateLimitOperation = 'deletes';
234
+ break;
235
+ case 'get':
236
+ rateLimitOperation = 'reads';
237
+ break;
238
+ default:
239
+ return next(); // Don't rate limit unknown operations
240
+ }
241
+ const key = this.config.keyGenerator(params);
242
+ if (this.checkRateLimit(rateLimitOperation, key)) {
243
+ const error = new Error(`Rate limit exceeded for ${operation}`);
244
+ error.statusCode = 429;
245
+ error.retryAfter = this.getResetTime(rateLimitOperation, key);
246
+ error.rateLimit = {
247
+ limit: this.config.limits[rateLimitOperation],
248
+ remaining: 0,
249
+ reset: Date.now() + this.getResetTime(rateLimitOperation, key)
250
+ };
251
+ throw error;
252
+ }
253
+ try {
254
+ const result = await next();
255
+ // Add rate limit info to result if possible
256
+ if (result && typeof result === 'object' && !Array.isArray(result)) {
257
+ result._rateLimit = {
258
+ limit: this.config.limits[rateLimitOperation],
259
+ remaining: this.getRemainingRequests(rateLimitOperation, key),
260
+ reset: Date.now() + this.getResetTime(rateLimitOperation, key)
261
+ };
262
+ }
263
+ return result;
264
+ }
265
+ catch (error) {
266
+ // Optionally don't count failed requests
267
+ if (this.config.skipFailedRequests) {
268
+ const limiter = this.limiters.get(rateLimitOperation);
269
+ const entry = limiter.get(key);
270
+ if (entry && entry.count > 0)
271
+ entry.count--;
272
+ }
273
+ throw error;
274
+ }
275
+ }
276
+ /**
277
+ * Get rate limit statistics
278
+ */
279
+ getStats() {
280
+ const stats = { operations: {} };
281
+ for (const [operation, limiter] of this.limiters) {
282
+ let totalRequests = 0;
283
+ for (const entry of limiter.values()) {
284
+ totalRequests += entry.count;
285
+ }
286
+ stats.operations[operation] = {
287
+ activeKeys: limiter.size,
288
+ totalRequests
289
+ };
290
+ }
291
+ return stats;
292
+ }
293
+ /**
294
+ * Clear all rate limit entries
295
+ */
296
+ clear() {
297
+ for (const limiter of this.limiters.values()) {
298
+ limiter.clear();
299
+ }
300
+ }
301
+ /**
302
+ * Clear expired entries (cleanup)
303
+ */
304
+ cleanup() {
305
+ const now = Date.now();
306
+ for (const limiter of this.limiters.values()) {
307
+ for (const [key, entry] of limiter) {
308
+ if (now >= entry.resetTime) {
309
+ limiter.delete(key);
310
+ }
311
+ }
312
+ }
313
+ }
314
+ }
315
+ /**
316
+ * Create rate limit augmentation
317
+ */
318
+ export function createRateLimitAugmentation(config) {
319
+ return new RateLimitAugmentation(config);
320
+ }
321
+ //# sourceMappingURL=rateLimitAugmentation.js.map
@@ -14,10 +14,10 @@ export declare class RequestDeduplicatorAugmentation extends BaseAugmentation {
14
14
  name: string;
15
15
  timing: "around";
16
16
  metadata: "none";
17
- operations: ("search" | "searchText" | "searchByNounTypes" | "findSimilar" | "get")[];
17
+ operations: ("search" | "find" | "similar" | "searchText" | "searchByNounTypes" | "findSimilar" | "get")[];
18
18
  priority: number;
19
19
  private pendingRequests;
20
- private config;
20
+ protected config: Required<DeduplicatorConfig>;
21
21
  private cleanupInterval?;
22
22
  constructor(config?: DeduplicatorConfig);
23
23
  protected onInitialize(): Promise<void>;
@@ -11,7 +11,7 @@ export class RequestDeduplicatorAugmentation extends BaseAugmentation {
11
11
  this.name = 'RequestDeduplicator';
12
12
  this.timing = 'around';
13
13
  this.metadata = 'none'; // Doesn't access metadata
14
- this.operations = ['search', 'searchText', 'searchByNounTypes', 'findSimilar', 'get'];
14
+ this.operations = ['search', 'find', 'similar', 'searchText', 'searchByNounTypes', 'findSimilar', 'get'];
15
15
  this.priority = 50; // Performance optimization
16
16
  this.pendingRequests = new Map();
17
17
  this.config = {
@@ -16,7 +16,7 @@ export declare abstract class StorageAugmentation extends BaseAugmentation imple
16
16
  operations: ("storage")[];
17
17
  readonly priority = 100;
18
18
  protected storageAdapter: StorageAdapter | null;
19
- constructor();
19
+ constructor(config?: any);
20
20
  /**
21
21
  * Provide the storage adapter before full initialization
22
22
  * This is called during the storage resolution phase
@@ -11,8 +11,8 @@ import { BaseAugmentation } from './brainyAugmentation.js';
11
11
  */
12
12
  export class StorageAugmentation extends BaseAugmentation {
13
13
  // Storage augmentations must provide their name via readonly property
14
- constructor() {
15
- super();
14
+ constructor(config) {
15
+ super(config);
16
16
  this.timing = 'replace';
17
17
  this.metadata = 'none'; // Storage doesn't directly access metadata
18
18
  this.operations = ['storage']; // Make mutable for TypeScript compatibility
@@ -6,12 +6,16 @@
6
6
  */
7
7
  import { StorageAugmentation } from './storageAugmentation.js';
8
8
  import { StorageAdapter } from '../coreTypes.js';
9
+ import { AugmentationManifest } from './manifest.js';
9
10
  /**
10
11
  * Memory Storage Augmentation - Fast in-memory storage
11
12
  */
12
13
  export declare class MemoryStorageAugmentation extends StorageAugmentation {
13
14
  readonly name = "memory-storage";
14
- constructor();
15
+ readonly category: "core";
16
+ readonly description = "High-performance in-memory storage for development and testing";
17
+ constructor(config?: any);
18
+ getManifest(): AugmentationManifest;
15
19
  provideStorage(): Promise<StorageAdapter>;
16
20
  protected onInitialize(): Promise<void>;
17
21
  }
@@ -20,8 +24,10 @@ export declare class MemoryStorageAugmentation extends StorageAugmentation {
20
24
  */
21
25
  export declare class FileSystemStorageAugmentation extends StorageAugmentation {
22
26
  readonly name = "filesystem-storage";
23
- private rootDirectory;
24
- constructor(rootDirectory?: string);
27
+ readonly category: "core";
28
+ readonly description = "Persistent file-based storage for Node.js environments";
29
+ constructor(config?: any);
30
+ getManifest(): AugmentationManifest;
25
31
  provideStorage(): Promise<StorageAdapter>;
26
32
  protected onInitialize(): Promise<void>;
27
33
  }
@@ -30,8 +36,10 @@ export declare class FileSystemStorageAugmentation extends StorageAugmentation {
30
36
  */
31
37
  export declare class OPFSStorageAugmentation extends StorageAugmentation {
32
38
  readonly name = "opfs-storage";
33
- private requestPersistent;
34
- constructor(requestPersistent?: boolean);
39
+ readonly category: "core";
40
+ readonly description = "Persistent browser storage using Origin Private File System";
41
+ constructor(config?: any);
42
+ getManifest(): AugmentationManifest;
35
43
  provideStorage(): Promise<StorageAdapter>;
36
44
  protected onInitialize(): Promise<void>;
37
45
  }
@@ -40,7 +48,15 @@ export declare class OPFSStorageAugmentation extends StorageAugmentation {
40
48
  */
41
49
  export declare class S3StorageAugmentation extends StorageAugmentation {
42
50
  readonly name = "s3-storage";
43
- private config;
51
+ protected config: {
52
+ bucketName: string;
53
+ region?: string;
54
+ accessKeyId: string;
55
+ secretAccessKey: string;
56
+ sessionToken?: string;
57
+ cacheConfig?: any;
58
+ operationConfig?: any;
59
+ };
44
60
  constructor(config: {
45
61
  bucketName: string;
46
62
  region?: string;
@@ -58,7 +74,13 @@ export declare class S3StorageAugmentation extends StorageAugmentation {
58
74
  */
59
75
  export declare class R2StorageAugmentation extends StorageAugmentation {
60
76
  readonly name = "r2-storage";
61
- private config;
77
+ protected config: {
78
+ bucketName: string;
79
+ accountId: string;
80
+ accessKeyId: string;
81
+ secretAccessKey: string;
82
+ cacheConfig?: any;
83
+ };
62
84
  constructor(config: {
63
85
  bucketName: string;
64
86
  accountId: string;
@@ -74,7 +96,14 @@ export declare class R2StorageAugmentation extends StorageAugmentation {
74
96
  */
75
97
  export declare class GCSStorageAugmentation extends StorageAugmentation {
76
98
  readonly name = "gcs-storage";
77
- private config;
99
+ protected config: {
100
+ bucketName: string;
101
+ region?: string;
102
+ accessKeyId: string;
103
+ secretAccessKey: string;
104
+ endpoint?: string;
105
+ cacheConfig?: any;
106
+ };
78
107
  constructor(config: {
79
108
  bucketName: string;
80
109
  region?: string;