@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.
- package/CHANGELOG.md +53 -3
- package/README.md +427 -111
- package/bin/brainy.js +340 -62
- 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 +290 -9
- 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 +142 -8
- package/dist/augmentations/brainyAugmentation.js +179 -2
- package/dist/augmentations/cacheAugmentation.d.ts +8 -5
- package/dist/augmentations/cacheAugmentation.js +116 -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 +14 -10
- package/dist/augmentations/defaultAugmentations.js +16 -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/cache.d.ts +130 -0
- package/dist/augmentations/display/cache.js +319 -0
- package/dist/augmentations/display/fieldPatterns.d.ts +52 -0
- package/dist/augmentations/display/fieldPatterns.js +393 -0
- package/dist/augmentations/display/iconMappings.d.ts +57 -0
- package/dist/augmentations/display/iconMappings.js +68 -0
- package/dist/augmentations/display/intelligentComputation.d.ts +109 -0
- package/dist/augmentations/display/intelligentComputation.js +462 -0
- package/dist/augmentations/display/types.d.ts +203 -0
- package/dist/augmentations/display/types.js +7 -0
- package/dist/augmentations/entityRegistryAugmentation.d.ts +3 -1
- package/dist/augmentations/entityRegistryAugmentation.js +5 -1
- package/dist/augmentations/indexAugmentation.d.ts +5 -3
- package/dist/augmentations/indexAugmentation.js +5 -2
- package/dist/augmentations/intelligentVerbScoringAugmentation.d.ts +24 -7
- package/dist/augmentations/intelligentVerbScoringAugmentation.js +111 -27
- 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/neuralImport.js +4 -4
- 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/brainyTypes.d.ts +83 -0
- package/dist/augmentations/typeMatching/brainyTypes.js +425 -0
- package/dist/augmentations/typeMatching/intelligentTypeMatcher.d.ts +39 -59
- package/dist/augmentations/typeMatching/intelligentTypeMatcher.js +103 -389
- package/dist/augmentations/universalDisplayAugmentation.d.ts +191 -0
- package/dist/augmentations/universalDisplayAugmentation.js +371 -0
- package/dist/brainy-unified.d.ts +106 -0
- package/dist/brainy-unified.js +327 -0
- package/dist/brainy.d.ts +277 -0
- package/dist/brainy.js +1241 -0
- package/dist/brainyData.d.ts +56 -111
- package/dist/brainyData.js +912 -756
- package/dist/brainyDataV3.d.ts +186 -0
- package/dist/brainyDataV3.js +337 -0
- package/dist/config/distributedPresets-new.d.ts +118 -0
- package/dist/config/distributedPresets-new.js +318 -0
- package/dist/config/distributedPresets.d.ts +118 -0
- package/dist/config/distributedPresets.js +318 -0
- package/dist/config/extensibleConfig.d.ts +99 -0
- package/dist/config/extensibleConfig.js +268 -0
- package/dist/config/index.d.ts +17 -0
- package/dist/config/index.js +35 -0
- package/dist/config/modelAutoConfig.d.ts +32 -0
- package/dist/config/modelAutoConfig.js +139 -0
- package/dist/config/modelPrecisionManager.d.ts +42 -0
- package/dist/config/modelPrecisionManager.js +98 -0
- package/dist/config/sharedConfigManager.d.ts +67 -0
- package/dist/config/sharedConfigManager.js +215 -0
- package/dist/config/storageAutoConfig.d.ts +41 -0
- package/dist/config/storageAutoConfig.js +328 -0
- package/dist/config/zeroConfig.d.ts +68 -0
- package/dist/config/zeroConfig.js +301 -0
- 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/CachedEmbeddings.d.ts +40 -0
- package/dist/embeddings/CachedEmbeddings.js +146 -0
- package/dist/embeddings/EmbeddingManager.d.ts +102 -0
- package/dist/embeddings/EmbeddingManager.js +291 -0
- package/dist/embeddings/SingletonModelManager.d.ts +95 -0
- package/dist/embeddings/SingletonModelManager.js +220 -0
- package/dist/embeddings/index.d.ts +12 -0
- package/dist/embeddings/index.js +16 -0
- package/dist/embeddings/lightweight-embedder.d.ts +0 -1
- package/dist/embeddings/lightweight-embedder.js +4 -12
- package/dist/embeddings/model-manager.d.ts +11 -0
- package/dist/embeddings/model-manager.js +43 -7
- package/dist/embeddings/universal-memory-manager.d.ts +1 -1
- package/dist/embeddings/universal-memory-manager.js +27 -67
- package/dist/embeddings/worker-embedding.js +4 -8
- package/dist/errors/brainyError.d.ts +5 -1
- package/dist/errors/brainyError.js +12 -0
- package/dist/examples/basicUsage.js +7 -4
- 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 +8 -5
- package/dist/index.d.ts +17 -22
- package/dist/index.js +37 -23
- 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.d.ts +357 -0
- package/dist/neural/improvedNeuralAPI.js +2628 -0
- 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/neural/types.d.ts +287 -0
- package/dist/neural/types.js +24 -0
- package/dist/shared/default-augmentations.d.ts +3 -3
- package/dist/shared/default-augmentations.js +5 -5
- package/dist/storage/adapters/baseStorageAdapter.d.ts +42 -0
- package/dist/storage/adapters/fileSystemStorage.d.ts +26 -2
- package/dist/storage/adapters/fileSystemStorage.js +218 -15
- package/dist/storage/adapters/memoryStorage.d.ts +4 -4
- package/dist/storage/adapters/memoryStorage.js +17 -12
- package/dist/storage/adapters/opfsStorage.d.ts +2 -2
- package/dist/storage/adapters/opfsStorage.js +2 -2
- package/dist/storage/adapters/s3CompatibleStorage.d.ts +2 -2
- package/dist/storage/adapters/s3CompatibleStorage.js +2 -2
- package/dist/storage/backwardCompatibility.d.ts +10 -78
- package/dist/storage/backwardCompatibility.js +17 -132
- package/dist/storage/baseStorage.d.ts +18 -2
- package/dist/storage/baseStorage.js +74 -3
- 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 +5 -8
- package/dist/types/brainyDataInterface.js +2 -2
- package/dist/types/graphTypes.js +2 -2
- package/dist/universal/crypto.d.ts +11 -1
- package/dist/universal/crypto.js +24 -93
- package/dist/universal/events.d.ts +3 -2
- package/dist/universal/events.js +6 -75
- package/dist/universal/fs.d.ts +2 -3
- package/dist/universal/fs.js +5 -211
- package/dist/universal/path.d.ts +3 -2
- package/dist/universal/path.js +22 -78
- package/dist/universal/uuid.d.ts +1 -1
- package/dist/universal/uuid.js +1 -1
- package/dist/utils/brainyTypes.d.ts +217 -0
- package/dist/utils/brainyTypes.js +261 -0
- package/dist/utils/cacheAutoConfig.d.ts +3 -3
- package/dist/utils/embedding.d.ts +9 -4
- package/dist/utils/embedding.js +89 -26
- package/dist/utils/enhancedLogger.d.ts +104 -0
- package/dist/utils/enhancedLogger.js +232 -0
- package/dist/utils/hybridModelManager.d.ts +19 -28
- package/dist/utils/hybridModelManager.js +36 -200
- 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/nodeVersionCheck.d.ts +24 -0
- package/dist/utils/nodeVersionCheck.js +65 -0
- 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 +59 -0
- package/dist/utils/typeValidation.js +374 -0
- package/dist/utils/version.js +19 -3
- package/package.json +15 -17
- package/scripts/download-models.cjs +94 -20
- package/dist/augmentations/walAugmentation.d.ts +0 -109
- package/dist/augmentations/walAugmentation.js +0 -516
- package/dist/browserFramework.d.ts +0 -15
- package/dist/browserFramework.js +0 -31
- package/dist/browserFramework.minimal.d.ts +0 -14
- package/dist/browserFramework.minimal.js +0 -31
- 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
|
@@ -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 {
|
|
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:
|
|
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
|
|
224
|
+
// Statistics not yet implemented
|
|
225
225
|
if (options.includeStatistics) {
|
|
226
|
-
|
|
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
|
-
//
|
|
263
|
-
|
|
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
|
-
//
|
|
267
|
-
|
|
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
|
-
//
|
|
271
|
-
|
|
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
|
-
//
|
|
275
|
-
|
|
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
|
-
|
|
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:
|
|
294
|
-
console.log(this.colors.
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
// Phase
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
//
|
|
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
|
-
//
|
|
313
|
-
|
|
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 {
|
|
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:
|
|
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 {
|
|
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:
|
|
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.
|
|
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.
|
|
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.
|
|
323
|
-
const
|
|
324
|
-
|
|
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 (
|
|
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.
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
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.
|
|
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 {
|
|
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:
|
|
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
|
-
//
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
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
|
-
//
|
|
187
|
-
//
|
|
188
|
-
|
|
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
|
|
24
|
+
* Simplified Brainy class for demo purposes
|
|
25
25
|
* Only includes browser-compatible functionality
|
|
26
26
|
*/
|
|
27
|
-
export declare class
|
|
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 {
|
|
106
|
-
export default
|
|
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
|
|
10
|
+
* Simplified Brainy class for demo purposes
|
|
11
11
|
* Only includes browser-compatible functionality
|
|
12
12
|
*/
|
|
13
|
-
export class
|
|
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
|
|
35
|
+
console.log('✅ Demo Brainy initialized successfully');
|
|
36
36
|
}
|
|
37
37
|
catch (error) {
|
|
38
|
-
console.error('Failed to initialize demo
|
|
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
|
|
198
|
-
export {
|
|
197
|
+
// Export the main class as Brainy for compatibility
|
|
198
|
+
export { DemoBrainy as Brainy };
|
|
199
199
|
// Default export
|
|
200
|
-
export default
|
|
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;
|