@soulcraft/brainy 3.0.0 → 3.1.0

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 (270) hide show
  1. package/CHANGELOG.md +53 -3
  2. package/README.md +427 -111
  3. package/bin/brainy.js +340 -62
  4. package/dist/api/ConfigAPI.d.ts +67 -0
  5. package/dist/api/ConfigAPI.js +166 -0
  6. package/dist/api/DataAPI.d.ts +123 -0
  7. package/dist/api/DataAPI.js +391 -0
  8. package/dist/api/SecurityAPI.d.ts +50 -0
  9. package/dist/api/SecurityAPI.js +139 -0
  10. package/dist/api/UniversalImportAPI.d.ts +134 -0
  11. package/dist/api/UniversalImportAPI.js +615 -0
  12. package/dist/augmentationManager.js +12 -7
  13. package/dist/augmentationPipeline.d.ts +0 -61
  14. package/dist/augmentationPipeline.js +0 -87
  15. package/dist/augmentationRegistry.d.ts +1 -1
  16. package/dist/augmentationRegistry.js +1 -1
  17. package/dist/augmentations/apiServerAugmentation.d.ts +27 -1
  18. package/dist/augmentations/apiServerAugmentation.js +290 -9
  19. package/dist/augmentations/auditLogAugmentation.d.ts +109 -0
  20. package/dist/augmentations/auditLogAugmentation.js +358 -0
  21. package/dist/augmentations/batchProcessingAugmentation.d.ts +3 -2
  22. package/dist/augmentations/batchProcessingAugmentation.js +123 -22
  23. package/dist/augmentations/brainyAugmentation.d.ts +142 -8
  24. package/dist/augmentations/brainyAugmentation.js +179 -2
  25. package/dist/augmentations/cacheAugmentation.d.ts +8 -5
  26. package/dist/augmentations/cacheAugmentation.js +116 -17
  27. package/dist/augmentations/conduitAugmentations.d.ts +2 -2
  28. package/dist/augmentations/conduitAugmentations.js +2 -2
  29. package/dist/augmentations/configResolver.d.ts +122 -0
  30. package/dist/augmentations/configResolver.js +440 -0
  31. package/dist/augmentations/connectionPoolAugmentation.d.ts +3 -1
  32. package/dist/augmentations/connectionPoolAugmentation.js +37 -12
  33. package/dist/augmentations/defaultAugmentations.d.ts +14 -10
  34. package/dist/augmentations/defaultAugmentations.js +16 -11
  35. package/dist/augmentations/discovery/catalogDiscovery.d.ts +142 -0
  36. package/dist/augmentations/discovery/catalogDiscovery.js +249 -0
  37. package/dist/augmentations/discovery/localDiscovery.d.ts +84 -0
  38. package/dist/augmentations/discovery/localDiscovery.js +246 -0
  39. package/dist/augmentations/discovery/runtimeLoader.d.ts +97 -0
  40. package/dist/augmentations/discovery/runtimeLoader.js +337 -0
  41. package/dist/augmentations/discovery.d.ts +152 -0
  42. package/dist/augmentations/discovery.js +441 -0
  43. package/dist/augmentations/display/cache.d.ts +130 -0
  44. package/dist/augmentations/display/cache.js +319 -0
  45. package/dist/augmentations/display/fieldPatterns.d.ts +52 -0
  46. package/dist/augmentations/display/fieldPatterns.js +393 -0
  47. package/dist/augmentations/display/iconMappings.d.ts +57 -0
  48. package/dist/augmentations/display/iconMappings.js +68 -0
  49. package/dist/augmentations/display/intelligentComputation.d.ts +109 -0
  50. package/dist/augmentations/display/intelligentComputation.js +462 -0
  51. package/dist/augmentations/display/types.d.ts +203 -0
  52. package/dist/augmentations/display/types.js +7 -0
  53. package/dist/augmentations/entityRegistryAugmentation.d.ts +3 -1
  54. package/dist/augmentations/entityRegistryAugmentation.js +5 -1
  55. package/dist/augmentations/indexAugmentation.d.ts +5 -3
  56. package/dist/augmentations/indexAugmentation.js +5 -2
  57. package/dist/augmentations/intelligentVerbScoringAugmentation.d.ts +24 -7
  58. package/dist/augmentations/intelligentVerbScoringAugmentation.js +111 -27
  59. package/dist/augmentations/manifest.d.ts +176 -0
  60. package/dist/augmentations/manifest.js +8 -0
  61. package/dist/augmentations/marketplace/AugmentationMarketplace.d.ts +168 -0
  62. package/dist/augmentations/marketplace/AugmentationMarketplace.js +329 -0
  63. package/dist/augmentations/marketplace/cli.d.ts +47 -0
  64. package/dist/augmentations/marketplace/cli.js +265 -0
  65. package/dist/augmentations/metricsAugmentation.d.ts +3 -3
  66. package/dist/augmentations/metricsAugmentation.js +2 -2
  67. package/dist/augmentations/monitoringAugmentation.d.ts +3 -3
  68. package/dist/augmentations/monitoringAugmentation.js +2 -2
  69. package/dist/augmentations/neuralImport.d.ts +1 -1
  70. package/dist/augmentations/neuralImport.js +4 -4
  71. package/dist/augmentations/rateLimitAugmentation.d.ts +82 -0
  72. package/dist/augmentations/rateLimitAugmentation.js +321 -0
  73. package/dist/augmentations/requestDeduplicatorAugmentation.d.ts +2 -2
  74. package/dist/augmentations/requestDeduplicatorAugmentation.js +1 -1
  75. package/dist/augmentations/storageAugmentation.d.ts +1 -1
  76. package/dist/augmentations/storageAugmentation.js +2 -2
  77. package/dist/augmentations/storageAugmentations.d.ts +37 -8
  78. package/dist/augmentations/storageAugmentations.js +204 -15
  79. package/dist/augmentations/synapseAugmentation.d.ts +1 -1
  80. package/dist/augmentations/synapseAugmentation.js +35 -16
  81. package/dist/augmentations/typeMatching/brainyTypes.d.ts +83 -0
  82. package/dist/augmentations/typeMatching/brainyTypes.js +425 -0
  83. package/dist/augmentations/typeMatching/intelligentTypeMatcher.d.ts +39 -59
  84. package/dist/augmentations/typeMatching/intelligentTypeMatcher.js +103 -389
  85. package/dist/augmentations/universalDisplayAugmentation.d.ts +191 -0
  86. package/dist/augmentations/universalDisplayAugmentation.js +371 -0
  87. package/dist/brainy-unified.d.ts +106 -0
  88. package/dist/brainy-unified.js +327 -0
  89. package/dist/brainy.d.ts +277 -0
  90. package/dist/brainy.js +1241 -0
  91. package/dist/brainyData.d.ts +56 -111
  92. package/dist/brainyData.js +912 -756
  93. package/dist/brainyDataV3.d.ts +186 -0
  94. package/dist/brainyDataV3.js +337 -0
  95. package/dist/config/distributedPresets-new.d.ts +118 -0
  96. package/dist/config/distributedPresets-new.js +318 -0
  97. package/dist/config/distributedPresets.d.ts +118 -0
  98. package/dist/config/distributedPresets.js +318 -0
  99. package/dist/config/extensibleConfig.d.ts +99 -0
  100. package/dist/config/extensibleConfig.js +268 -0
  101. package/dist/config/index.d.ts +17 -0
  102. package/dist/config/index.js +35 -0
  103. package/dist/config/modelAutoConfig.d.ts +32 -0
  104. package/dist/config/modelAutoConfig.js +139 -0
  105. package/dist/config/modelPrecisionManager.d.ts +42 -0
  106. package/dist/config/modelPrecisionManager.js +98 -0
  107. package/dist/config/sharedConfigManager.d.ts +67 -0
  108. package/dist/config/sharedConfigManager.js +215 -0
  109. package/dist/config/storageAutoConfig.d.ts +41 -0
  110. package/dist/config/storageAutoConfig.js +328 -0
  111. package/dist/config/zeroConfig.d.ts +68 -0
  112. package/dist/config/zeroConfig.js +301 -0
  113. package/dist/cortex/backupRestore.d.ts +2 -2
  114. package/dist/cortex/backupRestore.js +85 -27
  115. package/dist/cortex/healthCheck.d.ts +2 -2
  116. package/dist/cortex/neuralImport.d.ts +2 -2
  117. package/dist/cortex/neuralImport.js +18 -13
  118. package/dist/cortex/performanceMonitor.d.ts +2 -2
  119. package/dist/critical/model-guardian.d.ts +4 -0
  120. package/dist/critical/model-guardian.js +31 -11
  121. package/dist/demo.d.ts +4 -4
  122. package/dist/demo.js +7 -7
  123. package/dist/distributed/cacheSync.d.ts +112 -0
  124. package/dist/distributed/cacheSync.js +265 -0
  125. package/dist/distributed/coordinator.d.ts +193 -0
  126. package/dist/distributed/coordinator.js +548 -0
  127. package/dist/distributed/httpTransport.d.ts +120 -0
  128. package/dist/distributed/httpTransport.js +446 -0
  129. package/dist/distributed/index.d.ts +8 -0
  130. package/dist/distributed/index.js +5 -0
  131. package/dist/distributed/networkTransport.d.ts +132 -0
  132. package/dist/distributed/networkTransport.js +633 -0
  133. package/dist/distributed/queryPlanner.d.ts +104 -0
  134. package/dist/distributed/queryPlanner.js +327 -0
  135. package/dist/distributed/readWriteSeparation.d.ts +134 -0
  136. package/dist/distributed/readWriteSeparation.js +350 -0
  137. package/dist/distributed/shardManager.d.ts +114 -0
  138. package/dist/distributed/shardManager.js +357 -0
  139. package/dist/distributed/shardMigration.d.ts +110 -0
  140. package/dist/distributed/shardMigration.js +289 -0
  141. package/dist/distributed/storageDiscovery.d.ts +160 -0
  142. package/dist/distributed/storageDiscovery.js +551 -0
  143. package/dist/embeddings/CachedEmbeddings.d.ts +40 -0
  144. package/dist/embeddings/CachedEmbeddings.js +146 -0
  145. package/dist/embeddings/EmbeddingManager.d.ts +102 -0
  146. package/dist/embeddings/EmbeddingManager.js +291 -0
  147. package/dist/embeddings/SingletonModelManager.d.ts +95 -0
  148. package/dist/embeddings/SingletonModelManager.js +220 -0
  149. package/dist/embeddings/index.d.ts +12 -0
  150. package/dist/embeddings/index.js +16 -0
  151. package/dist/embeddings/lightweight-embedder.d.ts +0 -1
  152. package/dist/embeddings/lightweight-embedder.js +4 -12
  153. package/dist/embeddings/model-manager.d.ts +11 -0
  154. package/dist/embeddings/model-manager.js +43 -7
  155. package/dist/embeddings/universal-memory-manager.d.ts +1 -1
  156. package/dist/embeddings/universal-memory-manager.js +27 -67
  157. package/dist/embeddings/worker-embedding.js +4 -8
  158. package/dist/errors/brainyError.d.ts +5 -1
  159. package/dist/errors/brainyError.js +12 -0
  160. package/dist/examples/basicUsage.js +7 -4
  161. package/dist/graph/graphAdjacencyIndex.d.ts +96 -0
  162. package/dist/graph/graphAdjacencyIndex.js +288 -0
  163. package/dist/graph/pathfinding.js +4 -2
  164. package/dist/hnsw/scaledHNSWSystem.js +11 -2
  165. package/dist/importManager.js +8 -5
  166. package/dist/index.d.ts +17 -22
  167. package/dist/index.js +37 -23
  168. package/dist/mcp/brainyMCPAdapter.d.ts +4 -4
  169. package/dist/mcp/brainyMCPAdapter.js +5 -5
  170. package/dist/mcp/brainyMCPService.d.ts +3 -3
  171. package/dist/mcp/brainyMCPService.js +3 -11
  172. package/dist/mcp/mcpAugmentationToolset.js +20 -30
  173. package/dist/neural/embeddedPatterns.d.ts +1 -1
  174. package/dist/neural/embeddedPatterns.js +2 -2
  175. package/dist/neural/entityExtractor.d.ts +65 -0
  176. package/dist/neural/entityExtractor.js +316 -0
  177. package/dist/neural/improvedNeuralAPI.d.ts +357 -0
  178. package/dist/neural/improvedNeuralAPI.js +2628 -0
  179. package/dist/neural/naturalLanguageProcessor.d.ts +155 -10
  180. package/dist/neural/naturalLanguageProcessor.js +941 -66
  181. package/dist/neural/naturalLanguageProcessorStatic.d.ts +2 -2
  182. package/dist/neural/naturalLanguageProcessorStatic.js +3 -3
  183. package/dist/neural/neuralAPI.js +8 -2
  184. package/dist/neural/patternLibrary.d.ts +57 -3
  185. package/dist/neural/patternLibrary.js +348 -13
  186. package/dist/neural/staticPatternMatcher.d.ts +2 -2
  187. package/dist/neural/staticPatternMatcher.js +2 -2
  188. package/dist/neural/types.d.ts +287 -0
  189. package/dist/neural/types.js +24 -0
  190. package/dist/shared/default-augmentations.d.ts +3 -3
  191. package/dist/shared/default-augmentations.js +5 -5
  192. package/dist/storage/adapters/baseStorageAdapter.d.ts +42 -0
  193. package/dist/storage/adapters/fileSystemStorage.d.ts +26 -2
  194. package/dist/storage/adapters/fileSystemStorage.js +218 -15
  195. package/dist/storage/adapters/memoryStorage.d.ts +4 -4
  196. package/dist/storage/adapters/memoryStorage.js +17 -12
  197. package/dist/storage/adapters/opfsStorage.d.ts +2 -2
  198. package/dist/storage/adapters/opfsStorage.js +2 -2
  199. package/dist/storage/adapters/s3CompatibleStorage.d.ts +2 -2
  200. package/dist/storage/adapters/s3CompatibleStorage.js +2 -2
  201. package/dist/storage/backwardCompatibility.d.ts +10 -78
  202. package/dist/storage/backwardCompatibility.js +17 -132
  203. package/dist/storage/baseStorage.d.ts +18 -2
  204. package/dist/storage/baseStorage.js +74 -3
  205. package/dist/storage/cacheManager.js +2 -2
  206. package/dist/storage/readOnlyOptimizations.js +8 -3
  207. package/dist/streaming/pipeline.d.ts +154 -0
  208. package/dist/streaming/pipeline.js +551 -0
  209. package/dist/triple/TripleIntelligence.d.ts +25 -110
  210. package/dist/triple/TripleIntelligence.js +4 -574
  211. package/dist/triple/TripleIntelligenceSystem.d.ts +159 -0
  212. package/dist/triple/TripleIntelligenceSystem.js +519 -0
  213. package/dist/types/apiTypes.d.ts +278 -0
  214. package/dist/types/apiTypes.js +33 -0
  215. package/dist/types/brainy.types.d.ts +308 -0
  216. package/dist/types/brainy.types.js +8 -0
  217. package/dist/types/brainyDataInterface.d.ts +5 -8
  218. package/dist/types/brainyDataInterface.js +2 -2
  219. package/dist/types/graphTypes.js +2 -2
  220. package/dist/universal/crypto.d.ts +11 -1
  221. package/dist/universal/crypto.js +24 -93
  222. package/dist/universal/events.d.ts +3 -2
  223. package/dist/universal/events.js +6 -75
  224. package/dist/universal/fs.d.ts +2 -3
  225. package/dist/universal/fs.js +5 -211
  226. package/dist/universal/path.d.ts +3 -2
  227. package/dist/universal/path.js +22 -78
  228. package/dist/universal/uuid.d.ts +1 -1
  229. package/dist/universal/uuid.js +1 -1
  230. package/dist/utils/brainyTypes.d.ts +217 -0
  231. package/dist/utils/brainyTypes.js +261 -0
  232. package/dist/utils/cacheAutoConfig.d.ts +3 -3
  233. package/dist/utils/embedding.d.ts +9 -4
  234. package/dist/utils/embedding.js +89 -26
  235. package/dist/utils/enhancedLogger.d.ts +104 -0
  236. package/dist/utils/enhancedLogger.js +232 -0
  237. package/dist/utils/hybridModelManager.d.ts +19 -28
  238. package/dist/utils/hybridModelManager.js +36 -200
  239. package/dist/utils/index.d.ts +1 -1
  240. package/dist/utils/index.js +1 -1
  241. package/dist/utils/intelligentTypeMapper.d.ts +60 -0
  242. package/dist/utils/intelligentTypeMapper.js +349 -0
  243. package/dist/utils/metadataIndex.d.ts +118 -1
  244. package/dist/utils/metadataIndex.js +539 -16
  245. package/dist/utils/nodeVersionCheck.d.ts +24 -0
  246. package/dist/utils/nodeVersionCheck.js +65 -0
  247. package/dist/utils/paramValidation.d.ts +39 -0
  248. package/dist/utils/paramValidation.js +192 -0
  249. package/dist/utils/rateLimiter.d.ts +160 -0
  250. package/dist/utils/rateLimiter.js +271 -0
  251. package/dist/utils/statistics.d.ts +4 -4
  252. package/dist/utils/statistics.js +3 -3
  253. package/dist/utils/structuredLogger.d.ts +146 -0
  254. package/dist/utils/structuredLogger.js +394 -0
  255. package/dist/utils/textEncoding.js +2 -1
  256. package/dist/utils/typeValidation.d.ts +59 -0
  257. package/dist/utils/typeValidation.js +374 -0
  258. package/dist/utils/version.js +19 -3
  259. package/package.json +15 -17
  260. package/scripts/download-models.cjs +94 -20
  261. package/dist/augmentations/walAugmentation.d.ts +0 -109
  262. package/dist/augmentations/walAugmentation.js +0 -516
  263. package/dist/browserFramework.d.ts +0 -15
  264. package/dist/browserFramework.js +0 -31
  265. package/dist/browserFramework.minimal.d.ts +0 -14
  266. package/dist/browserFramework.minimal.js +0 -31
  267. package/dist/chat/BrainyChat.d.ts +0 -121
  268. package/dist/chat/BrainyChat.js +0 -396
  269. package/dist/chat/ChatCLI.d.ts +0 -61
  270. package/dist/chat/ChatCLI.js +0 -351
@@ -4,7 +4,7 @@
4
4
  * 🧠 Complete backup/restore with compression and verification
5
5
  * ⚛️ 1950s retro sci-fi aesthetic maintained throughout
6
6
  */
7
- import { BrainyData } from '../brainyData.js';
7
+ import { Brainy } from '../brainy.js';
8
8
  export interface BackupOptions {
9
9
  compress?: boolean;
10
10
  output?: string;
@@ -42,7 +42,7 @@ export declare class BackupRestore {
42
42
  private brainy;
43
43
  private colors;
44
44
  private emojis;
45
- constructor(brainy: BrainyData);
45
+ constructor(brainy: Brainy);
46
46
  /**
47
47
  * Create a complete backup of Brainy data
48
48
  */
@@ -221,12 +221,9 @@ export class BackupRestore {
221
221
  if (options.includeMetadata) {
222
222
  data.metadata = await this.collectMetadata();
223
223
  }
224
- // Statistics placeholder
224
+ // Statistics not yet implemented
225
225
  if (options.includeStatistics) {
226
- data.statistics = {
227
- timestamp: new Date().toISOString(),
228
- placeholder: true
229
- };
226
+ console.warn('Statistics collection not yet implemented in backup');
230
227
  }
231
228
  return data;
232
229
  }
@@ -259,20 +256,46 @@ export class BackupRestore {
259
256
  return `./brainy-backup-${timestamp}.brainy`;
260
257
  }
261
258
  async compressData(data) {
262
- // Placeholder - would use zlib or similar
263
- return data; // For now, no compression
259
+ // Use zlib gzip compression
260
+ const { gzip } = await import('zlib');
261
+ const { promisify } = await import('util');
262
+ const gzipAsync = promisify(gzip);
263
+ const compressed = await gzipAsync(Buffer.from(data, 'utf-8'));
264
+ return compressed.toString('base64');
264
265
  }
265
266
  async decompressData(data) {
266
- // Placeholder - would use zlib or similar
267
- return data; // For now, no decompression
267
+ // Use zlib gunzip decompression
268
+ const { gunzip } = await import('zlib');
269
+ const { promisify } = await import('util');
270
+ const gunzipAsync = promisify(gunzip);
271
+ const compressed = Buffer.from(data, 'base64');
272
+ const decompressed = await gunzipAsync(compressed);
273
+ return decompressed.toString('utf-8');
268
274
  }
269
275
  async encryptData(data, password) {
270
- // Placeholder - would use crypto module
271
- return data; // For now, no encryption
276
+ // Use crypto module for AES-256 encryption
277
+ const crypto = await import('crypto');
278
+ // Generate key from password
279
+ const key = crypto.createHash('sha256').update(password).digest();
280
+ const iv = crypto.randomBytes(16);
281
+ const cipher = crypto.createCipheriv('aes-256-cbc', key, iv);
282
+ let encrypted = cipher.update(data, 'utf8', 'base64');
283
+ encrypted += cipher.final('base64');
284
+ // Prepend IV to encrypted data for decryption
285
+ return iv.toString('base64') + ':' + encrypted;
272
286
  }
273
287
  async decryptData(data, password) {
274
- // Placeholder - would use crypto module
275
- return data; // For now, no decryption
288
+ // Use crypto module for AES-256 decryption
289
+ const crypto = await import('crypto');
290
+ // Split IV and encrypted data
291
+ const [ivString, encrypted] = data.split(':');
292
+ const iv = Buffer.from(ivString, 'base64');
293
+ // Generate key from password
294
+ const key = crypto.createHash('sha256').update(password).digest();
295
+ const decipher = crypto.createDecipheriv('aes-256-cbc', key, iv);
296
+ let decrypted = decipher.update(encrypted, 'base64', 'utf8');
297
+ decrypted += decipher.final('utf8');
298
+ return decrypted;
276
299
  }
277
300
  async verifyBackup(backupPath, options) {
278
301
  // Placeholder - would verify backup integrity
@@ -284,33 +307,68 @@ export class BackupRestore {
284
307
  }
285
308
  }
286
309
  async executeRestore(data, manifest) {
287
- // Placeholder restore implementation
288
- console.log(this.colors.warning('Note: Restore system is in beta - limited functionality'));
310
+ console.log(this.colors.info('🔄 Starting restore process...'));
289
311
  // Phase 1: Validate data structure
290
312
  if (!data.entities || !Array.isArray(data.entities)) {
291
313
  throw new Error('Invalid backup data structure');
292
314
  }
293
- // Phase 2: Restore entities (placeholder)
294
- console.log(this.colors.info(`Would restore ${data.entities.length} entities`));
295
- // Phase 3: Restore relationships (placeholder)
296
- console.log(this.colors.info(`Would restore ${data.relationships.length} relationships`));
297
- // Phase 4: Restore metadata (placeholder)
315
+ // Phase 2: Clear existing data if overwriting
316
+ console.log(this.colors.dim('Clearing existing data...'));
317
+ const dataAPI = await this.brainy.data();
318
+ await dataAPI.clear();
319
+ // Phase 3: Restore entities
320
+ console.log(this.colors.dim(`Restoring ${data.entities.length} entities...`));
321
+ const entityMap = new Map(); // old ID -> new ID mapping
322
+ for (const entity of data.entities) {
323
+ const newId = await this.brainy.add({
324
+ data: entity.metadata || entity.data,
325
+ type: entity.type,
326
+ metadata: entity.metadata,
327
+ vector: entity.vector, // Preserve original vectors if available
328
+ service: entity.service
329
+ });
330
+ entityMap.set(entity.id, newId);
331
+ }
332
+ // Phase 4: Restore relationships if they exist
333
+ if (data.relationships && Array.isArray(data.relationships)) {
334
+ console.log(this.colors.dim(`Restoring ${data.relationships.length} relationships...`));
335
+ for (const rel of data.relationships) {
336
+ // Map old IDs to new IDs
337
+ const fromId = entityMap.get(rel.from) || rel.from;
338
+ const toId = entityMap.get(rel.to) || rel.to;
339
+ await this.brainy.relate({
340
+ from: fromId,
341
+ to: toId,
342
+ type: rel.type,
343
+ metadata: rel.metadata || {}
344
+ });
345
+ }
346
+ }
347
+ // Phase 5: Restore metadata if present
298
348
  if (data.metadata) {
299
349
  await this.restoreMetadata(data.metadata);
300
350
  }
301
- // Phase 5: Simulate successful restore
302
- console.log(this.colors.success('Backup structure validated - restore would be successful'));
351
+ console.log(this.colors.success('✅ Restore completed successfully'));
303
352
  }
304
353
  async collectMetadata() {
305
- // Collect global metadata
306
- return {};
354
+ // Collect global metadata like statistics, configuration, etc.
355
+ const dataApi = await this.brainy.data();
356
+ const stats = await dataApi.getStats();
357
+ return {
358
+ totalEntities: stats.entities || 0,
359
+ timestamp: new Date().toISOString(),
360
+ version: '3.0.0'
361
+ };
307
362
  }
308
363
  async restoreMetadata(metadata) {
309
- // Restore global metadata
364
+ // Store restored metadata for reference
365
+ // Could be saved to a config store or logged
366
+ console.log(this.colors.dim(`Restored from backup created at: ${metadata.timestamp}`));
310
367
  }
311
368
  async calculateChecksum(data) {
312
- // Placeholder - would calculate SHA-256 hash
313
- return 'checksum-placeholder';
369
+ // Use crypto module for SHA-256 checksum
370
+ const crypto = await import('crypto');
371
+ return crypto.createHash('sha256').update(data).digest('hex');
314
372
  }
315
373
  formatFileSize(bytes) {
316
374
  const units = ['B', 'KB', 'MB', 'GB'];
@@ -5,7 +5,7 @@
5
5
  * ⚛️ Auto-repair capabilities with 1950s retro sci-fi aesthetics
6
6
  * 🚀 Scalable health monitoring for high-performance databases
7
7
  */
8
- import { BrainyData } from '../brainyData.js';
8
+ import { Brainy } from '../brainy.js';
9
9
  export interface HealthCheckResult {
10
10
  component: string;
11
11
  status: 'healthy' | 'warning' | 'critical' | 'offline';
@@ -44,7 +44,7 @@ export declare class HealthCheck {
44
44
  private brainy;
45
45
  private colors;
46
46
  private emojis;
47
- constructor(brainy: BrainyData);
47
+ constructor(brainy: Brainy);
48
48
  /**
49
49
  * Run comprehensive system health check
50
50
  */
@@ -4,7 +4,7 @@
4
4
  * 🧠 Leveraging the brain-in-jar to understand and automatically structure data
5
5
  * ⚛️ Complete with confidence scoring and relationship weight calculation
6
6
  */
7
- import { BrainyData } from '../brainyData.js';
7
+ import { Brainy } from '../brainy.js';
8
8
  export interface NeuralAnalysisResult {
9
9
  detectedEntities: DetectedEntity[];
10
10
  detectedRelationships: DetectedRelationship[];
@@ -67,7 +67,7 @@ export declare class NeuralImport {
67
67
  private brainy;
68
68
  private colors;
69
69
  private emojis;
70
- constructor(brainy: BrainyData);
70
+ constructor(brainy: Brainy);
71
71
  /**
72
72
  * Main Neural Import Function - The Master Controller
73
73
  */
@@ -188,7 +188,7 @@ export class NeuralImport {
188
188
  */
189
189
  async calculateEntityTypeConfidence(text, data, nounType) {
190
190
  // Base semantic similarity using search instead of similarity method
191
- const searchResults = await this.brainy.search(text + ' ' + nounType, { limit: 1 });
191
+ const searchResults = await this.brainy.find(text + ' ' + nounType);
192
192
  const textSimilarity = searchResults.length > 0 ? searchResults[0].score : 0.5;
193
193
  // Field-based confidence boost
194
194
  const fieldBoost = this.calculateFieldBasedConfidence(data, nounType);
@@ -258,7 +258,7 @@ export class NeuralImport {
258
258
  async generateEntityReasoning(text, data, nounType) {
259
259
  const reasons = [];
260
260
  // Semantic similarity reason using search
261
- const searchResults = await this.brainy.search(text + ' ' + nounType, { limit: 1 });
261
+ const searchResults = await this.brainy.find(text + ' ' + nounType);
262
262
  const similarity = searchResults.length > 0 ? searchResults[0].score : 0.5;
263
263
  if (similarity > 0.7) {
264
264
  reasons.push(`High semantic similarity (${(similarity * 100).toFixed(1)}%)`);
@@ -319,15 +319,14 @@ export class NeuralImport {
319
319
  async calculateRelationshipConfidence(source, target, verbType, context) {
320
320
  // Semantic similarity between entities and verb type using search
321
321
  const relationshipText = `${this.extractMainText(source.originalData)} ${verbType} ${this.extractMainText(target.originalData)}`;
322
- const directResults = await this.brainy.search(relationshipText, { limit: 1 });
323
- const directSimilarity = directResults.length > 0 ? directResults[0].score : 0.5;
324
- // Context-based similarity using search
325
- const contextResults = await this.brainy.search(context + ' ' + verbType, { limit: 1 });
322
+ const directResults = await this.brainy.find(relationshipText);
323
+ const directScore = directResults.length > 0 ? directResults[0].score : 0.4;
324
+ const contextResults = await this.brainy.find(context + ' ' + verbType);
326
325
  const contextSimilarity = contextResults.length > 0 ? contextResults[0].score : 0.5;
327
326
  // Entity type compatibility
328
327
  const typeCompatibility = this.calculateTypeCompatibility(source.nounType, target.nounType, verbType);
329
328
  // Combine with weights
330
- return (directSimilarity * 0.4) + (contextSimilarity * 0.4) + (typeCompatibility * 0.2);
329
+ return (directScore * 0.4) + (contextSimilarity * 0.4) + (typeCompatibility * 0.2);
331
330
  }
332
331
  /**
333
332
  * Calculate relationship weight/strength
@@ -576,16 +575,22 @@ export class NeuralImport {
576
575
  try {
577
576
  // Add entities to Brainy
578
577
  for (const entity of result.detectedEntities) {
579
- await this.brainy.addNoun(this.extractMainText(entity.originalData), {
580
- ...entity.originalData,
581
- nounType: entity.nounType,
582
- confidence: entity.confidence,
583
- id: entity.suggestedId
578
+ await this.brainy.add({
579
+ data: this.extractMainText(entity.originalData),
580
+ type: entity.nounType,
581
+ metadata: {
582
+ ...entity.originalData,
583
+ confidence: entity.confidence,
584
+ id: entity.suggestedId
585
+ }
584
586
  });
585
587
  }
586
588
  // Add relationships to Brainy
587
589
  for (const relationship of result.detectedRelationships) {
588
- await this.brainy.addVerb(relationship.sourceId, relationship.targetId, relationship.verbType, {
590
+ await this.brainy.relate({
591
+ from: relationship.sourceId,
592
+ to: relationship.targetId,
593
+ type: relationship.verbType,
589
594
  weight: relationship.weight,
590
595
  metadata: {
591
596
  confidence: relationship.confidence,
@@ -5,7 +5,7 @@
5
5
  * ⚛️ Monitors query performance, storage usage, and system health
6
6
  * 🚀 Scalable performance analytics with atomic age aesthetics
7
7
  */
8
- import { BrainyData } from '../brainyData.js';
8
+ import { Brainy } from '../brainy.js';
9
9
  export interface PerformanceMetrics {
10
10
  queryLatency: {
11
11
  vector: {
@@ -92,7 +92,7 @@ export declare class PerformanceMonitor {
92
92
  private monitoringInterval?;
93
93
  private colors;
94
94
  private emojis;
95
- constructor(brainy: BrainyData);
95
+ constructor(brainy: Brainy);
96
96
  /**
97
97
  * Start real-time monitoring
98
98
  */
@@ -26,6 +26,10 @@ export declare class ModelGuardian {
26
26
  * Verify the local model files exist and are correct
27
27
  */
28
28
  private verifyLocalModel;
29
+ /**
30
+ * Compute SHA256 hash of a file
31
+ */
32
+ private computeFileHash;
29
33
  /**
30
34
  * Download model from a fallback source
31
35
  */
@@ -153,17 +153,36 @@ export class ModelGuardian {
153
153
  return false;
154
154
  }
155
155
  }
156
- // TODO: Add SHA256 verification for ultimate security
157
- // if (CRITICAL_MODEL_CONFIG.modelHash[file]) {
158
- // const hash = await this.computeFileHash(filePath)
159
- // if (hash !== CRITICAL_MODEL_CONFIG.modelHash[file]) {
160
- // console.error('❌ CRITICAL: Model hash mismatch!')
161
- // return false
162
- // }
163
- // }
156
+ // SHA256 verification for ultimate security
157
+ if (CRITICAL_MODEL_CONFIG.modelHash && CRITICAL_MODEL_CONFIG.modelHash[file]) {
158
+ const hash = await this.computeFileHash(filePath);
159
+ if (hash !== CRITICAL_MODEL_CONFIG.modelHash[file]) {
160
+ console.error(`❌ CRITICAL: Model hash mismatch for ${file}!\n` +
161
+ `Expected: ${CRITICAL_MODEL_CONFIG.modelHash[file]}\n` +
162
+ `Got: ${hash}\n` +
163
+ `This indicates model tampering or corruption!`);
164
+ return false;
165
+ }
166
+ }
164
167
  }
165
168
  return true;
166
169
  }
170
+ /**
171
+ * Compute SHA256 hash of a file
172
+ */
173
+ async computeFileHash(filePath) {
174
+ try {
175
+ const { readFile } = await import('fs/promises');
176
+ const { createHash } = await import('crypto');
177
+ const fileBuffer = await readFile(filePath);
178
+ const hash = createHash('sha256').update(fileBuffer).digest('hex');
179
+ return hash;
180
+ }
181
+ catch (error) {
182
+ console.error(`Failed to compute hash for ${filePath}:`, error);
183
+ return '';
184
+ }
185
+ }
167
186
  /**
168
187
  * Download model from a fallback source
169
188
  */
@@ -183,9 +202,10 @@ export class ModelGuardian {
183
202
  }
184
203
  }
185
204
  else if (source.type === 'tarball') {
186
- // Download and extract tarball
187
- // This would require implementation with proper tar extraction
188
- throw new Error('Tarball extraction not yet implemented');
205
+ // Tarball extraction would require additional dependencies
206
+ // Skip this source and try next fallback
207
+ console.warn(`⚠️ Tarball extraction not available for ${source.name}. Trying next source...`);
208
+ return; // Will continue to next source in the loop
189
209
  }
190
210
  }
191
211
  /**
package/dist/demo.d.ts CHANGED
@@ -21,10 +21,10 @@ export interface VerbData {
21
21
  timestamp: number;
22
22
  }
23
23
  /**
24
- * Simplified BrainyData class for demo purposes
24
+ * Simplified Brainy class for demo purposes
25
25
  * Only includes browser-compatible functionality
26
26
  */
27
- export declare class DemoBrainyData {
27
+ export declare class DemoBrainy {
28
28
  private storage;
29
29
  private embedder;
30
30
  private initialized;
@@ -102,5 +102,5 @@ export declare const VerbType: {
102
102
  readonly Likes: "likes";
103
103
  readonly Follows: "follows";
104
104
  };
105
- export { DemoBrainyData as BrainyData };
106
- export default DemoBrainyData;
105
+ export { DemoBrainy as Brainy };
106
+ export default DemoBrainy;
package/dist/demo.js CHANGED
@@ -7,10 +7,10 @@ import { MemoryStorage } from './storage/adapters/memoryStorage.js';
7
7
  import { TransformerEmbedding } from './utils/embedding.js';
8
8
  import { cosineDistance } from './utils/distance.js';
9
9
  /**
10
- * Simplified BrainyData class for demo purposes
10
+ * Simplified Brainy class for demo purposes
11
11
  * Only includes browser-compatible functionality
12
12
  */
13
- export class DemoBrainyData {
13
+ export class DemoBrainy {
14
14
  constructor() {
15
15
  this.embedder = null;
16
16
  this.initialized = false;
@@ -32,10 +32,10 @@ export class DemoBrainyData {
32
32
  this.embedder = new TransformerEmbedding({ verbose: false });
33
33
  await this.embedder.init();
34
34
  this.initialized = true;
35
- console.log('✅ Demo BrainyData initialized successfully');
35
+ console.log('✅ Demo Brainy initialized successfully');
36
36
  }
37
37
  catch (error) {
38
- console.error('Failed to initialize demo BrainyData:', error);
38
+ console.error('Failed to initialize demo Brainy:', error);
39
39
  throw error;
40
40
  }
41
41
  }
@@ -194,8 +194,8 @@ export const VerbType = {
194
194
  Likes: 'likes',
195
195
  Follows: 'follows'
196
196
  };
197
- // Export the main class as BrainyData for compatibility
198
- export { DemoBrainyData as BrainyData };
197
+ // Export the main class as Brainy for compatibility
198
+ export { DemoBrainy as Brainy };
199
199
  // Default export
200
- export default DemoBrainyData;
200
+ export default DemoBrainy;
201
201
  //# sourceMappingURL=demo.js.map
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Distributed Cache Synchronization
3
+ * Provides cache coherence across multiple Brainy instances
4
+ */
5
+ import { EventEmitter } from 'events';
6
+ export interface CacheSyncConfig {
7
+ nodeId: string;
8
+ syncInterval?: number;
9
+ maxSyncBatchSize?: number;
10
+ compressionEnabled?: boolean;
11
+ }
12
+ export interface CacheEntry {
13
+ key: string;
14
+ value: any;
15
+ version: number;
16
+ timestamp: number;
17
+ ttl?: number;
18
+ nodeId: string;
19
+ }
20
+ export interface SyncMessage {
21
+ type: 'invalidate' | 'update' | 'delete' | 'batch';
22
+ entries: CacheEntry[];
23
+ source: string;
24
+ timestamp: number;
25
+ }
26
+ /**
27
+ * Distributed Cache Synchronizer
28
+ */
29
+ export declare class CacheSync extends EventEmitter {
30
+ private nodeId;
31
+ private localCache;
32
+ private versionVector;
33
+ private syncQueue;
34
+ private syncInterval;
35
+ private maxSyncBatchSize;
36
+ private syncTimer?;
37
+ private isRunning;
38
+ constructor(config: CacheSyncConfig);
39
+ /**
40
+ * Start cache synchronization
41
+ */
42
+ start(): void;
43
+ /**
44
+ * Stop cache synchronization
45
+ */
46
+ stop(): void;
47
+ /**
48
+ * Get a value from cache
49
+ */
50
+ get(key: string): any | undefined;
51
+ /**
52
+ * Set a value in cache and propagate
53
+ */
54
+ set(key: string, value: any, ttl?: number): void;
55
+ /**
56
+ * Delete a value from cache and propagate
57
+ */
58
+ delete(key: string): boolean;
59
+ /**
60
+ * Invalidate a cache entry across all nodes
61
+ */
62
+ invalidate(key: string): void;
63
+ /**
64
+ * Clear all cache entries
65
+ */
66
+ clear(): void;
67
+ /**
68
+ * Handle incoming sync message from another node
69
+ */
70
+ handleSyncMessage(message: SyncMessage): void;
71
+ /**
72
+ * Handle a remote cache entry
73
+ */
74
+ private handleRemoteEntry;
75
+ /**
76
+ * Queue a sync message
77
+ */
78
+ private queueSync;
79
+ /**
80
+ * Start sync timer
81
+ */
82
+ private startSyncTimer;
83
+ /**
84
+ * Perform sync operation
85
+ */
86
+ private performSync;
87
+ /**
88
+ * Increment version for a key
89
+ */
90
+ private incrementVersion;
91
+ /**
92
+ * Get cache statistics
93
+ */
94
+ getStats(): {
95
+ entries: number;
96
+ pendingSync: number;
97
+ versionedKeys: number;
98
+ memoryUsage: number;
99
+ };
100
+ /**
101
+ * Get cache entries for debugging
102
+ */
103
+ getEntries(): CacheEntry[];
104
+ /**
105
+ * Merge cache state from another node (for recovery)
106
+ */
107
+ mergeState(entries: CacheEntry[]): void;
108
+ }
109
+ /**
110
+ * Create a cache sync instance
111
+ */
112
+ export declare function createCacheSync(config: CacheSyncConfig): CacheSync;