@soulcraft/brainy 3.0.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +53 -3
- package/README.md +353 -110
- 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 +273 -0
- package/dist/brainy.js +1181 -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/browserFramework.d.ts +6 -6
- package/dist/browserFramework.js +11 -8
- package/dist/browserFramework.minimal.d.ts +5 -5
- package/dist/browserFramework.minimal.js +11 -8
- package/dist/config/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/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 -4
- package/scripts/download-models.cjs +94 -20
- package/dist/augmentations/walAugmentation.d.ts +0 -109
- package/dist/augmentations/walAugmentation.js +0 -516
- 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
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Security API for Brainy 3.0
|
|
3
|
+
* Provides encryption, decryption, hashing, and secure storage
|
|
4
|
+
*/
|
|
5
|
+
export declare class SecurityAPI {
|
|
6
|
+
private config?;
|
|
7
|
+
private encryptionKey?;
|
|
8
|
+
constructor(config?: {
|
|
9
|
+
encryptionKey?: string;
|
|
10
|
+
} | undefined);
|
|
11
|
+
/**
|
|
12
|
+
* Encrypt data using AES-256-CBC
|
|
13
|
+
*/
|
|
14
|
+
encrypt(data: string): Promise<string>;
|
|
15
|
+
/**
|
|
16
|
+
* Decrypt data encrypted with encrypt()
|
|
17
|
+
*/
|
|
18
|
+
decrypt(encryptedData: string): Promise<string>;
|
|
19
|
+
/**
|
|
20
|
+
* Create a one-way hash of data (for passwords, etc)
|
|
21
|
+
*/
|
|
22
|
+
hash(data: string, algorithm?: 'sha256' | 'sha512'): Promise<string>;
|
|
23
|
+
/**
|
|
24
|
+
* Compare data with a hash (for password verification)
|
|
25
|
+
*/
|
|
26
|
+
compare(data: string, hash: string, algorithm?: 'sha256' | 'sha512'): Promise<boolean>;
|
|
27
|
+
/**
|
|
28
|
+
* Generate a secure random token
|
|
29
|
+
*/
|
|
30
|
+
generateToken(bytes?: number): Promise<string>;
|
|
31
|
+
/**
|
|
32
|
+
* Derive a key from a password using PBKDF2
|
|
33
|
+
* Note: Simplified version using hash instead of PBKDF2 which may not be available
|
|
34
|
+
*/
|
|
35
|
+
deriveKey(password: string, salt?: string, iterations?: number): Promise<{
|
|
36
|
+
key: string;
|
|
37
|
+
salt: string;
|
|
38
|
+
}>;
|
|
39
|
+
/**
|
|
40
|
+
* Sign data with HMAC
|
|
41
|
+
*/
|
|
42
|
+
sign(data: string, secret?: string): Promise<string>;
|
|
43
|
+
/**
|
|
44
|
+
* Verify HMAC signature
|
|
45
|
+
*/
|
|
46
|
+
verify(data: string, signature: string, secret: string): Promise<boolean>;
|
|
47
|
+
private hexToBytes;
|
|
48
|
+
private bytesToHex;
|
|
49
|
+
private constantTimeCompare;
|
|
50
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Security API for Brainy 3.0
|
|
3
|
+
* Provides encryption, decryption, hashing, and secure storage
|
|
4
|
+
*/
|
|
5
|
+
export class SecurityAPI {
|
|
6
|
+
constructor(config) {
|
|
7
|
+
this.config = config;
|
|
8
|
+
if (config?.encryptionKey) {
|
|
9
|
+
// Use provided key (must be 32 bytes hex string)
|
|
10
|
+
this.encryptionKey = this.hexToBytes(config.encryptionKey);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Encrypt data using AES-256-CBC
|
|
15
|
+
*/
|
|
16
|
+
async encrypt(data) {
|
|
17
|
+
const crypto = await import('../universal/crypto.js');
|
|
18
|
+
// Generate or use existing key
|
|
19
|
+
const key = this.encryptionKey || crypto.randomBytes(32);
|
|
20
|
+
const iv = crypto.randomBytes(16);
|
|
21
|
+
const cipher = crypto.createCipheriv('aes-256-cbc', key, iv);
|
|
22
|
+
let encrypted = cipher.update(data, 'utf8', 'hex');
|
|
23
|
+
encrypted += cipher.final('hex');
|
|
24
|
+
// Package encrypted data with metadata
|
|
25
|
+
// In production, store keys separately in a key management service
|
|
26
|
+
return JSON.stringify({
|
|
27
|
+
encrypted,
|
|
28
|
+
key: this.bytesToHex(key),
|
|
29
|
+
iv: this.bytesToHex(iv),
|
|
30
|
+
algorithm: 'aes-256-cbc',
|
|
31
|
+
timestamp: Date.now()
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Decrypt data encrypted with encrypt()
|
|
36
|
+
*/
|
|
37
|
+
async decrypt(encryptedData) {
|
|
38
|
+
const crypto = await import('../universal/crypto.js');
|
|
39
|
+
try {
|
|
40
|
+
const parsed = JSON.parse(encryptedData);
|
|
41
|
+
const { encrypted, key: keyHex, iv: ivHex, algorithm } = parsed;
|
|
42
|
+
if (algorithm && algorithm !== 'aes-256-cbc') {
|
|
43
|
+
throw new Error(`Unsupported encryption algorithm: ${algorithm}`);
|
|
44
|
+
}
|
|
45
|
+
const key = this.hexToBytes(keyHex);
|
|
46
|
+
const iv = this.hexToBytes(ivHex);
|
|
47
|
+
const decipher = crypto.createDecipheriv('aes-256-cbc', key, iv);
|
|
48
|
+
let decrypted = decipher.update(encrypted, 'hex', 'utf8');
|
|
49
|
+
decrypted += decipher.final('utf8');
|
|
50
|
+
return decrypted;
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
throw new Error(`Decryption failed: ${error.message}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Create a one-way hash of data (for passwords, etc)
|
|
58
|
+
*/
|
|
59
|
+
async hash(data, algorithm = 'sha256') {
|
|
60
|
+
const crypto = await import('../universal/crypto.js');
|
|
61
|
+
const hash = crypto.createHash(algorithm);
|
|
62
|
+
hash.update(data);
|
|
63
|
+
return hash.digest('hex');
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Compare data with a hash (for password verification)
|
|
67
|
+
*/
|
|
68
|
+
async compare(data, hash, algorithm = 'sha256') {
|
|
69
|
+
const dataHash = await this.hash(data, algorithm);
|
|
70
|
+
return this.constantTimeCompare(dataHash, hash);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Generate a secure random token
|
|
74
|
+
*/
|
|
75
|
+
async generateToken(bytes = 32) {
|
|
76
|
+
const crypto = await import('../universal/crypto.js');
|
|
77
|
+
const buffer = crypto.randomBytes(bytes);
|
|
78
|
+
return this.bytesToHex(buffer);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Derive a key from a password using PBKDF2
|
|
82
|
+
* Note: Simplified version using hash instead of PBKDF2 which may not be available
|
|
83
|
+
*/
|
|
84
|
+
async deriveKey(password, salt, iterations = 100000) {
|
|
85
|
+
const crypto = await import('../universal/crypto.js');
|
|
86
|
+
const actualSalt = salt || this.bytesToHex(crypto.randomBytes(32));
|
|
87
|
+
// Simplified key derivation using repeated hashing
|
|
88
|
+
// In production, use a proper PBKDF2 implementation
|
|
89
|
+
let derived = password + actualSalt;
|
|
90
|
+
for (let i = 0; i < Math.min(iterations, 1000); i++) {
|
|
91
|
+
const hash = crypto.createHash('sha256');
|
|
92
|
+
hash.update(derived);
|
|
93
|
+
derived = hash.digest('hex');
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
key: derived,
|
|
97
|
+
salt: actualSalt
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Sign data with HMAC
|
|
102
|
+
*/
|
|
103
|
+
async sign(data, secret) {
|
|
104
|
+
const crypto = await import('../universal/crypto.js');
|
|
105
|
+
const actualSecret = secret || (await this.generateToken());
|
|
106
|
+
const hmac = crypto.createHmac('sha256', actualSecret);
|
|
107
|
+
hmac.update(data);
|
|
108
|
+
return hmac.digest('hex');
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Verify HMAC signature
|
|
112
|
+
*/
|
|
113
|
+
async verify(data, signature, secret) {
|
|
114
|
+
const expectedSignature = await this.sign(data, secret);
|
|
115
|
+
return this.constantTimeCompare(signature, expectedSignature);
|
|
116
|
+
}
|
|
117
|
+
// Helper methods
|
|
118
|
+
hexToBytes(hex) {
|
|
119
|
+
const matches = hex.match(/.{1,2}/g);
|
|
120
|
+
if (!matches)
|
|
121
|
+
throw new Error('Invalid hex string');
|
|
122
|
+
return new Uint8Array(matches.map(byte => parseInt(byte, 16)));
|
|
123
|
+
}
|
|
124
|
+
bytesToHex(bytes) {
|
|
125
|
+
return Array.from(bytes)
|
|
126
|
+
.map(b => b.toString(16).padStart(2, '0'))
|
|
127
|
+
.join('');
|
|
128
|
+
}
|
|
129
|
+
constantTimeCompare(a, b) {
|
|
130
|
+
if (a.length !== b.length)
|
|
131
|
+
return false;
|
|
132
|
+
let result = 0;
|
|
133
|
+
for (let i = 0; i < a.length; i++) {
|
|
134
|
+
result |= a.charCodeAt(i) ^ b.charCodeAt(i);
|
|
135
|
+
}
|
|
136
|
+
return result === 0;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=SecurityAPI.js.map
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Universal Neural Import API
|
|
3
|
+
*
|
|
4
|
+
* ALWAYS uses neural matching to map ANY data to our strict NounTypes and VerbTypes
|
|
5
|
+
* Never falls back to rules - neural matching is MANDATORY
|
|
6
|
+
*
|
|
7
|
+
* Handles:
|
|
8
|
+
* - Strings (text, JSON, CSV, YAML, Markdown)
|
|
9
|
+
* - Files (local paths, any format)
|
|
10
|
+
* - URLs (web pages, APIs, documents)
|
|
11
|
+
* - Objects (structured data)
|
|
12
|
+
* - Binary data (images, PDFs via extraction)
|
|
13
|
+
*/
|
|
14
|
+
import { NounType, VerbType } from '../types/graphTypes.js';
|
|
15
|
+
import { Vector } from '../coreTypes.js';
|
|
16
|
+
import type { Brainy } from '../brainy.js';
|
|
17
|
+
export interface ImportSource {
|
|
18
|
+
type: 'string' | 'file' | 'url' | 'object' | 'binary';
|
|
19
|
+
data: any;
|
|
20
|
+
format?: string;
|
|
21
|
+
metadata?: any;
|
|
22
|
+
}
|
|
23
|
+
export interface NeuralImportResult {
|
|
24
|
+
entities: Array<{
|
|
25
|
+
id: string;
|
|
26
|
+
type: NounType;
|
|
27
|
+
data: any;
|
|
28
|
+
vector: Vector;
|
|
29
|
+
confidence: number;
|
|
30
|
+
metadata: any;
|
|
31
|
+
}>;
|
|
32
|
+
relationships: Array<{
|
|
33
|
+
id: string;
|
|
34
|
+
from: string;
|
|
35
|
+
to: string;
|
|
36
|
+
type: VerbType;
|
|
37
|
+
weight: number;
|
|
38
|
+
confidence: number;
|
|
39
|
+
metadata?: any;
|
|
40
|
+
}>;
|
|
41
|
+
stats: {
|
|
42
|
+
totalProcessed: number;
|
|
43
|
+
entitiesCreated: number;
|
|
44
|
+
relationshipsCreated: number;
|
|
45
|
+
averageConfidence: number;
|
|
46
|
+
processingTimeMs: number;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export declare class UniversalImportAPI {
|
|
50
|
+
private brain;
|
|
51
|
+
private typeMatcher;
|
|
52
|
+
private neuralImport;
|
|
53
|
+
private embedCache;
|
|
54
|
+
constructor(brain: Brainy<any>);
|
|
55
|
+
/**
|
|
56
|
+
* Initialize the neural import system
|
|
57
|
+
*/
|
|
58
|
+
init(): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Universal import - handles ANY data source
|
|
61
|
+
* ALWAYS uses neural matching, NEVER falls back
|
|
62
|
+
*/
|
|
63
|
+
import(source: ImportSource | string | any): Promise<NeuralImportResult>;
|
|
64
|
+
/**
|
|
65
|
+
* Import from URL - fetches and processes
|
|
66
|
+
*/
|
|
67
|
+
importFromURL(url: string): Promise<NeuralImportResult>;
|
|
68
|
+
/**
|
|
69
|
+
* Import from file - reads and processes
|
|
70
|
+
* Note: In browser environment, use File API instead
|
|
71
|
+
*/
|
|
72
|
+
importFromFile(filePath: string): Promise<NeuralImportResult>;
|
|
73
|
+
/**
|
|
74
|
+
* Normalize any input to ImportSource
|
|
75
|
+
*/
|
|
76
|
+
private normalizeSource;
|
|
77
|
+
/**
|
|
78
|
+
* Extract structured data from source
|
|
79
|
+
*/
|
|
80
|
+
private extractData;
|
|
81
|
+
/**
|
|
82
|
+
* Extract data from URL
|
|
83
|
+
*/
|
|
84
|
+
private extractFromURL;
|
|
85
|
+
/**
|
|
86
|
+
* Extract data from file
|
|
87
|
+
*/
|
|
88
|
+
private extractFromFile;
|
|
89
|
+
/**
|
|
90
|
+
* Extract data from string based on format
|
|
91
|
+
*/
|
|
92
|
+
private extractFromString;
|
|
93
|
+
/**
|
|
94
|
+
* Extract from binary data (images, PDFs, etc)
|
|
95
|
+
*/
|
|
96
|
+
private extractFromBinary;
|
|
97
|
+
/**
|
|
98
|
+
* Extract entities from plain text
|
|
99
|
+
*/
|
|
100
|
+
private extractFromText;
|
|
101
|
+
/**
|
|
102
|
+
* Neural processing - CORE of the system
|
|
103
|
+
* ALWAYS uses embeddings and neural matching
|
|
104
|
+
*/
|
|
105
|
+
private neuralProcess;
|
|
106
|
+
/**
|
|
107
|
+
* Generate embedding for any data
|
|
108
|
+
*/
|
|
109
|
+
private generateEmbedding;
|
|
110
|
+
/**
|
|
111
|
+
* Convert any data to text for embedding
|
|
112
|
+
*/
|
|
113
|
+
private dataToText;
|
|
114
|
+
/**
|
|
115
|
+
* Detect relationships using neural matching
|
|
116
|
+
*/
|
|
117
|
+
private detectNeuralRelationships;
|
|
118
|
+
/**
|
|
119
|
+
* Check if a field looks like a reference
|
|
120
|
+
*/
|
|
121
|
+
private looksLikeReference;
|
|
122
|
+
/**
|
|
123
|
+
* Store processed data in brain
|
|
124
|
+
*/
|
|
125
|
+
private storeInBrain;
|
|
126
|
+
private detectFormat;
|
|
127
|
+
private parseCSV;
|
|
128
|
+
private parseYAML;
|
|
129
|
+
private parseMarkdown;
|
|
130
|
+
private parseHTML;
|
|
131
|
+
private generateId;
|
|
132
|
+
private simpleHash;
|
|
133
|
+
private hashBinary;
|
|
134
|
+
}
|