@soulcraft/brainy 3.3.1 → 3.5.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/bin/brainy.js +4 -5
- package/dist/api/DataAPI.js +1 -1
- package/dist/api/UniversalImportAPI.js +1 -1
- package/dist/augmentations/apiServerAugmentation.js +3 -3
- package/dist/augmentations/auditLogAugmentation.js +1 -1
- package/dist/augmentations/conduitAugmentations.d.ts +1 -1
- package/dist/augmentations/conduitAugmentations.js +8 -3
- package/dist/augmentations/configResolver.js +5 -5
- package/dist/augmentations/discovery/localDiscovery.js +2 -2
- package/dist/brainy.d.ts +6 -2
- package/dist/brainy.js +2 -0
- package/dist/config/storageAutoConfig.js +2 -2
- package/dist/cortex/backupRestore.js +7 -7
- package/dist/critical/model-guardian.js +5 -5
- package/dist/distributed/cacheSync.d.ts +1 -1
- package/dist/distributed/cacheSync.js +1 -1
- package/dist/distributed/coordinator.d.ts +1 -1
- package/dist/distributed/coordinator.js +2 -2
- package/dist/distributed/httpTransport.d.ts +2 -2
- package/dist/distributed/httpTransport.js +5 -5
- package/dist/distributed/networkTransport.d.ts +1 -1
- package/dist/distributed/networkTransport.js +3 -3
- package/dist/distributed/readWriteSeparation.d.ts +1 -1
- package/dist/distributed/readWriteSeparation.js +1 -1
- package/dist/distributed/shardManager.d.ts +1 -1
- package/dist/distributed/shardManager.js +2 -2
- package/dist/distributed/shardMigration.d.ts +1 -1
- package/dist/distributed/shardMigration.js +1 -1
- package/dist/distributed/storageDiscovery.d.ts +1 -1
- package/dist/distributed/storageDiscovery.js +2 -2
- package/dist/embeddings/EmbeddingManager.js +2 -2
- package/dist/importManager.js +9 -3
- package/dist/mcp/brainyMCPAdapter.js +5 -4
- package/dist/neural/improvedNeuralAPI.js +1 -1
- package/dist/storage/adapters/fileSystemStorage.js +2 -2
- package/dist/storage/cacheManager.js +1 -1
- package/dist/storage/enhancedClearOperations.js +1 -1
- package/dist/types/brainyDataInterface.d.ts +26 -33
- package/dist/types/brainyDataInterface.js +5 -3
- package/dist/universal/crypto.js +2 -1
- package/dist/universal/events.js +1 -1
- package/dist/universal/fs.js +2 -1
- package/dist/universal/path.js +2 -1
- package/dist/utils/adaptiveSocketManager.js +1 -1
- package/dist/utils/autoConfiguration.js +1 -1
- package/dist/utils/embedding.js +2 -2
- package/dist/utils/paramValidation.js +1 -1
- package/dist/utils/structuredLogger.js +2 -2
- package/dist/utils/version.js +3 -3
- package/package.json +1 -1
package/bin/brainy.js
CHANGED
|
@@ -546,7 +546,7 @@ program
|
|
|
546
546
|
metadata.encrypted = true
|
|
547
547
|
}
|
|
548
548
|
|
|
549
|
-
const id = await brainyInstance.
|
|
549
|
+
const id = await brainyInstance.add({ data: processedData, type: 'content', metadata })
|
|
550
550
|
console.log(colors.success(`✅ Added successfully! ID: ${id}`))
|
|
551
551
|
}))
|
|
552
552
|
|
|
@@ -1337,9 +1337,8 @@ program
|
|
|
1337
1337
|
}
|
|
1338
1338
|
|
|
1339
1339
|
try {
|
|
1340
|
-
//
|
|
1341
|
-
|
|
1342
|
-
const id = await brainy.addNoun(name, metadata)
|
|
1340
|
+
// Use modern 3.0 API with parameter object
|
|
1341
|
+
const id = await brainy.add({ data: name, type: options.type, metadata })
|
|
1343
1342
|
|
|
1344
1343
|
console.log(colors.success('✅ Noun added successfully!'))
|
|
1345
1344
|
console.log(colors.info(`🆔 ID: ${id}`))
|
|
@@ -1506,7 +1505,7 @@ program
|
|
|
1506
1505
|
|
|
1507
1506
|
// Use the provided type or fall back to RelatedTo
|
|
1508
1507
|
const verbType = VerbType[options.type] || options.type
|
|
1509
|
-
const id = await brainy.
|
|
1508
|
+
const id = await brainy.relate({ from: source, to: target, type: verbType, metadata })
|
|
1510
1509
|
|
|
1511
1510
|
console.log(colors.success('✅ Relationship added successfully!'))
|
|
1512
1511
|
console.log(colors.info(`🆔 ID: ${id}`))
|
package/dist/api/DataAPI.js
CHANGED
|
@@ -61,7 +61,7 @@ export class DataAPI {
|
|
|
61
61
|
// Compress if requested
|
|
62
62
|
if (compress) {
|
|
63
63
|
// Import zlib for compression
|
|
64
|
-
const { gzipSync } = await import('zlib');
|
|
64
|
+
const { gzipSync } = await import('node:zlib');
|
|
65
65
|
const jsonString = JSON.stringify(backupData);
|
|
66
66
|
const compressed = gzipSync(Buffer.from(jsonString));
|
|
67
67
|
return {
|
|
@@ -78,7 +78,7 @@ export class UniversalImportAPI {
|
|
|
78
78
|
*/
|
|
79
79
|
async importFromFile(filePath) {
|
|
80
80
|
// Read the actual file content
|
|
81
|
-
const { readFileSync } = await import('fs');
|
|
81
|
+
const { readFileSync } = await import('node:fs');
|
|
82
82
|
const ext = filePath.split('.').pop()?.toLowerCase() || 'txt';
|
|
83
83
|
try {
|
|
84
84
|
const fileContent = readFileSync(filePath, 'utf-8');
|
|
@@ -72,7 +72,7 @@ export class APIServerAugmentation extends BaseAugmentation {
|
|
|
72
72
|
const express = await import('express').catch(() => null);
|
|
73
73
|
const cors = await import('cors').catch(() => null);
|
|
74
74
|
const ws = await import('ws').catch(() => null);
|
|
75
|
-
const { createServer } = await import('http');
|
|
75
|
+
const { createServer } = await import('node:http');
|
|
76
76
|
if (!express || !cors || !ws) {
|
|
77
77
|
this.log('Express, cors, or ws not available. Install with: npm install express cors ws', 'error');
|
|
78
78
|
return;
|
|
@@ -139,7 +139,7 @@ export class APIServerAugmentation extends BaseAugmentation {
|
|
|
139
139
|
app.post('/api/add', async (req, res) => {
|
|
140
140
|
try {
|
|
141
141
|
const { content, metadata } = req.body;
|
|
142
|
-
const id = await this.context.brain.
|
|
142
|
+
const id = await this.context.brain.add({ data: content, type: 'content', metadata });
|
|
143
143
|
res.json({ success: true, id });
|
|
144
144
|
}
|
|
145
145
|
catch (error) {
|
|
@@ -301,7 +301,7 @@ export class APIServerAugmentation extends BaseAugmentation {
|
|
|
301
301
|
}));
|
|
302
302
|
break;
|
|
303
303
|
case 'add':
|
|
304
|
-
const id = await this.context.brain.
|
|
304
|
+
const id = await this.context.brain.add({ data: msg.content, type: 'content', metadata: msg.metadata });
|
|
305
305
|
socket.send(JSON.stringify({
|
|
306
306
|
type: 'addResult',
|
|
307
307
|
requestId: msg.requestId,
|
|
@@ -66,6 +66,6 @@ export {};
|
|
|
66
66
|
* await conduit.establishConnection('ws://localhost:3000/ws')
|
|
67
67
|
*
|
|
68
68
|
* // Now operations sync automatically!
|
|
69
|
-
* await clientBrain.
|
|
69
|
+
* await clientBrain.add({ data: 'synced data', type: 'content', metadata: { source: 'client' } })
|
|
70
70
|
* // This will automatically sync to the server
|
|
71
71
|
*/
|
|
@@ -168,13 +168,18 @@ export class WebSocketConduitAugmentation extends BaseConduitAugmentation {
|
|
|
168
168
|
try {
|
|
169
169
|
switch (operation) {
|
|
170
170
|
case 'addNoun':
|
|
171
|
-
await this.context?.brain.
|
|
171
|
+
await this.context?.brain.add({ data: params.content, type: 'content', metadata: params.metadata });
|
|
172
172
|
break;
|
|
173
173
|
case 'deleteNoun':
|
|
174
174
|
await this.context?.brain.deleteNoun(params.id);
|
|
175
175
|
break;
|
|
176
176
|
case 'addVerb':
|
|
177
|
-
await this.context?.brain.
|
|
177
|
+
await this.context?.brain.relate({
|
|
178
|
+
from: params.source,
|
|
179
|
+
to: params.target,
|
|
180
|
+
type: params.verb,
|
|
181
|
+
metadata: params.metadata
|
|
182
|
+
});
|
|
178
183
|
break;
|
|
179
184
|
}
|
|
180
185
|
}
|
|
@@ -227,7 +232,7 @@ export class WebSocketConduitAugmentation extends BaseConduitAugmentation {
|
|
|
227
232
|
* await conduit.establishConnection('ws://localhost:3000/ws')
|
|
228
233
|
*
|
|
229
234
|
* // Now operations sync automatically!
|
|
230
|
-
* await clientBrain.
|
|
235
|
+
* await clientBrain.add({ data: 'synced data', type: 'content', metadata: { source: 'client' } })
|
|
231
236
|
* // This will automatically sync to the server
|
|
232
237
|
*/
|
|
233
238
|
//# sourceMappingURL=conduitAugmentations.js.map
|
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
* - Runtime updates
|
|
8
8
|
* - Default values from schema
|
|
9
9
|
*/
|
|
10
|
-
import { existsSync, readFileSync } from 'fs';
|
|
11
|
-
import { join } from 'path';
|
|
12
|
-
import { homedir } from 'os';
|
|
10
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
11
|
+
import { join } from 'node:path';
|
|
12
|
+
import { homedir } from 'node:os';
|
|
13
13
|
/**
|
|
14
14
|
* Configuration source priority (highest to lowest)
|
|
15
15
|
*/
|
|
@@ -379,8 +379,8 @@ export class AugmentationConfigResolver {
|
|
|
379
379
|
if (typeof process === 'undefined' || typeof window !== 'undefined') {
|
|
380
380
|
throw new Error('Cannot save configuration files in browser environment');
|
|
381
381
|
}
|
|
382
|
-
const fs = await import('fs');
|
|
383
|
-
const path = await import('path');
|
|
382
|
+
const fs = await import('node:fs');
|
|
383
|
+
const path = await import('node:path');
|
|
384
384
|
const configPath = filepath || this.options.configPaths?.[0] || '.brainyrc';
|
|
385
385
|
const augId = this.options.augmentationId;
|
|
386
386
|
// Load existing config if it exists
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* Discovers augmentations installed locally in node_modules
|
|
5
5
|
* and built-in augmentations that ship with Brainy
|
|
6
6
|
*/
|
|
7
|
-
import { existsSync, readdirSync, readFileSync } from 'fs';
|
|
8
|
-
import { join } from 'path';
|
|
7
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
8
|
+
import { join } from 'node:path';
|
|
9
9
|
/**
|
|
10
10
|
* Discovers augmentations installed locally
|
|
11
11
|
*/
|
package/dist/brainy.d.ts
CHANGED
|
@@ -4,16 +4,20 @@
|
|
|
4
4
|
* Beautiful, Professional, Planet-Scale, Fun to Use
|
|
5
5
|
* NO STUBS, NO MOCKS, REAL IMPLEMENTATION
|
|
6
6
|
*/
|
|
7
|
+
import { Vector } from './coreTypes.js';
|
|
7
8
|
import { ImprovedNeuralAPI } from './neural/improvedNeuralAPI.js';
|
|
8
9
|
import { NaturalLanguageProcessor } from './neural/naturalLanguageProcessor.js';
|
|
9
10
|
import { TripleIntelligenceSystem } from './triple/TripleIntelligenceSystem.js';
|
|
10
11
|
import { Entity, Relation, Result, AddParams, UpdateParams, RelateParams, FindParams, SimilarParams, GetRelationsParams, AddManyParams, DeleteManyParams, RelateManyParams, BatchResult, BrainyConfig } from './types/brainy.types.js';
|
|
11
12
|
import { NounType } from './types/graphTypes.js';
|
|
13
|
+
import { BrainyInterface } from './types/brainyDataInterface.js';
|
|
12
14
|
/**
|
|
13
15
|
* The main Brainy class - Clean, Beautiful, Powerful
|
|
14
16
|
* REAL IMPLEMENTATION - No stubs, no mocks
|
|
17
|
+
*
|
|
18
|
+
* Implements BrainyInterface to ensure consistency across integrations
|
|
15
19
|
*/
|
|
16
|
-
export declare class Brainy<T = any> {
|
|
20
|
+
export declare class Brainy<T = any> implements BrainyInterface<T> {
|
|
17
21
|
private index;
|
|
18
22
|
private storage;
|
|
19
23
|
private metadataIndex;
|
|
@@ -316,7 +320,7 @@ export declare class Brainy<T = any> {
|
|
|
316
320
|
/**
|
|
317
321
|
* Embed data into vector
|
|
318
322
|
*/
|
|
319
|
-
|
|
323
|
+
embed(data: any): Promise<Vector>;
|
|
320
324
|
/**
|
|
321
325
|
* Warm up the system
|
|
322
326
|
*/
|
package/dist/brainy.js
CHANGED
|
@@ -22,6 +22,8 @@ import { NounType } from './types/graphTypes.js';
|
|
|
22
22
|
/**
|
|
23
23
|
* The main Brainy class - Clean, Beautiful, Powerful
|
|
24
24
|
* REAL IMPLEMENTATION - No stubs, no mocks
|
|
25
|
+
*
|
|
26
|
+
* Implements BrainyInterface to ensure consistency across integrations
|
|
25
27
|
*/
|
|
26
28
|
export class Brainy {
|
|
27
29
|
constructor(config) {
|
|
@@ -300,8 +300,8 @@ async function isWritable(dirPath) {
|
|
|
300
300
|
return false;
|
|
301
301
|
try {
|
|
302
302
|
// Dynamic import fs for Node.js
|
|
303
|
-
const { promises: fs } = await import('fs');
|
|
304
|
-
const path = await import('path');
|
|
303
|
+
const { promises: fs } = await import('node:fs');
|
|
304
|
+
const path = await import('node:path');
|
|
305
305
|
// Try to create directory if it doesn't exist
|
|
306
306
|
await fs.mkdir(dirPath, { recursive: true });
|
|
307
307
|
// Try to write a test file
|
|
@@ -257,16 +257,16 @@ export class BackupRestore {
|
|
|
257
257
|
}
|
|
258
258
|
async compressData(data) {
|
|
259
259
|
// Use zlib gzip compression
|
|
260
|
-
const { gzip } = await import('zlib');
|
|
261
|
-
const { promisify } = await import('util');
|
|
260
|
+
const { gzip } = await import('node:zlib');
|
|
261
|
+
const { promisify } = await import('node:util');
|
|
262
262
|
const gzipAsync = promisify(gzip);
|
|
263
263
|
const compressed = await gzipAsync(Buffer.from(data, 'utf-8'));
|
|
264
264
|
return compressed.toString('base64');
|
|
265
265
|
}
|
|
266
266
|
async decompressData(data) {
|
|
267
267
|
// Use zlib gunzip decompression
|
|
268
|
-
const { gunzip } = await import('zlib');
|
|
269
|
-
const { promisify } = await import('util');
|
|
268
|
+
const { gunzip } = await import('node:zlib');
|
|
269
|
+
const { promisify } = await import('node:util');
|
|
270
270
|
const gunzipAsync = promisify(gunzip);
|
|
271
271
|
const compressed = Buffer.from(data, 'base64');
|
|
272
272
|
const decompressed = await gunzipAsync(compressed);
|
|
@@ -274,7 +274,7 @@ export class BackupRestore {
|
|
|
274
274
|
}
|
|
275
275
|
async encryptData(data, password) {
|
|
276
276
|
// Use crypto module for AES-256 encryption
|
|
277
|
-
const crypto = await import('crypto');
|
|
277
|
+
const crypto = await import('node:crypto');
|
|
278
278
|
// Generate key from password
|
|
279
279
|
const key = crypto.createHash('sha256').update(password).digest();
|
|
280
280
|
const iv = crypto.randomBytes(16);
|
|
@@ -286,7 +286,7 @@ export class BackupRestore {
|
|
|
286
286
|
}
|
|
287
287
|
async decryptData(data, password) {
|
|
288
288
|
// Use crypto module for AES-256 decryption
|
|
289
|
-
const crypto = await import('crypto');
|
|
289
|
+
const crypto = await import('node:crypto');
|
|
290
290
|
// Split IV and encrypted data
|
|
291
291
|
const [ivString, encrypted] = data.split(':');
|
|
292
292
|
const iv = Buffer.from(ivString, 'base64');
|
|
@@ -367,7 +367,7 @@ export class BackupRestore {
|
|
|
367
367
|
}
|
|
368
368
|
async calculateChecksum(data) {
|
|
369
369
|
// Use crypto module for SHA-256 checksum
|
|
370
|
-
const crypto = await import('crypto');
|
|
370
|
+
const crypto = await import('node:crypto');
|
|
371
371
|
return crypto.createHash('sha256').update(data).digest('hex');
|
|
372
372
|
}
|
|
373
373
|
formatFileSize(bytes) {
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
* 3. Model MUST produce consistent 384-dim embeddings
|
|
11
11
|
* 4. System MUST fail fast if model unavailable in production
|
|
12
12
|
*/
|
|
13
|
-
import { existsSync } from 'fs';
|
|
14
|
-
import { stat } from 'fs/promises';
|
|
15
|
-
import { join } from 'path';
|
|
13
|
+
import { existsSync } from 'node:fs';
|
|
14
|
+
import { stat } from 'node:fs/promises';
|
|
15
|
+
import { join } from 'node:path';
|
|
16
16
|
import { env } from '@huggingface/transformers';
|
|
17
17
|
// CRITICAL: These values MUST NEVER CHANGE
|
|
18
18
|
const CRITICAL_MODEL_CONFIG = {
|
|
@@ -172,8 +172,8 @@ export class ModelGuardian {
|
|
|
172
172
|
*/
|
|
173
173
|
async computeFileHash(filePath) {
|
|
174
174
|
try {
|
|
175
|
-
const { readFile } = await import('fs/promises');
|
|
176
|
-
const { createHash } = await import('crypto');
|
|
175
|
+
const { readFile } = await import('node:fs/promises');
|
|
176
|
+
const { createHash } = await import('node:crypto');
|
|
177
177
|
const fileBuffer = await readFile(filePath);
|
|
178
178
|
const hash = createHash('sha256').update(fileBuffer).digest('hex');
|
|
179
179
|
return hash;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Distributed Cache Synchronization
|
|
3
3
|
* Provides cache coherence across multiple Brainy instances
|
|
4
4
|
*/
|
|
5
|
-
import { EventEmitter } from 'events';
|
|
5
|
+
import { EventEmitter } from 'node:events';
|
|
6
6
|
export interface CacheSyncConfig {
|
|
7
7
|
nodeId: string;
|
|
8
8
|
syncInterval?: number;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Distributed Coordinator for Brainy 3.0
|
|
3
3
|
* Provides leader election, consensus, and coordination for distributed instances
|
|
4
4
|
*/
|
|
5
|
-
import { EventEmitter } from 'events';
|
|
5
|
+
import { EventEmitter } from 'node:events';
|
|
6
6
|
import { NetworkTransport } from './networkTransport.js';
|
|
7
7
|
export interface NodeInfo {
|
|
8
8
|
id: string;
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Distributed Coordinator for Brainy 3.0
|
|
3
3
|
* Provides leader election, consensus, and coordination for distributed instances
|
|
4
4
|
*/
|
|
5
|
-
import { EventEmitter } from 'events';
|
|
6
|
-
import { createHash } from 'crypto';
|
|
5
|
+
import { EventEmitter } from 'node:events';
|
|
6
|
+
import { createHash } from 'node:crypto';
|
|
7
7
|
/**
|
|
8
8
|
* Distributed Coordinator implementing Raft-like consensus
|
|
9
9
|
*/
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* Simple, reliable, works everywhere - no WebSocket complexity!
|
|
4
4
|
* REAL PRODUCTION CODE - Handles millions of operations
|
|
5
5
|
*/
|
|
6
|
-
import * as http from 'http';
|
|
7
|
-
import { EventEmitter } from 'events';
|
|
6
|
+
import * as http from 'node:http';
|
|
7
|
+
import { EventEmitter } from 'node:events';
|
|
8
8
|
export interface TransportMessage {
|
|
9
9
|
id: string;
|
|
10
10
|
method: string;
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
* Simple, reliable, works everywhere - no WebSocket complexity!
|
|
4
4
|
* REAL PRODUCTION CODE - Handles millions of operations
|
|
5
5
|
*/
|
|
6
|
-
import * as http from 'http';
|
|
7
|
-
import * as https from 'https';
|
|
8
|
-
import { EventEmitter } from 'events';
|
|
9
|
-
import * as net from 'net';
|
|
10
|
-
import { URL } from 'url';
|
|
6
|
+
import * as http from 'node:http';
|
|
7
|
+
import * as https from 'node:https';
|
|
8
|
+
import { EventEmitter } from 'node:events';
|
|
9
|
+
import * as net from 'node:net';
|
|
10
|
+
import { URL } from 'node:url';
|
|
11
11
|
export class HTTPTransport extends EventEmitter {
|
|
12
12
|
constructor(nodeId) {
|
|
13
13
|
super();
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Network Transport Layer for Distributed Brainy
|
|
3
3
|
* Uses WebSocket + HTTP for maximum compatibility
|
|
4
4
|
*/
|
|
5
|
-
import * as http from 'http';
|
|
6
|
-
import { EventEmitter } from 'events';
|
|
5
|
+
import * as http from 'node:http';
|
|
6
|
+
import { EventEmitter } from 'node:events';
|
|
7
7
|
import { WebSocket } from 'ws';
|
|
8
8
|
// Use dynamic imports for Node.js specific modules
|
|
9
9
|
let WebSocketServer;
|
|
@@ -311,7 +311,7 @@ export class NetworkTransport extends EventEmitter {
|
|
|
311
311
|
const token = process.env.KUBERNETES_TOKEN || '';
|
|
312
312
|
try {
|
|
313
313
|
// Query Kubernetes API for pod endpoints
|
|
314
|
-
const https = await import('https');
|
|
314
|
+
const https = await import('node:https');
|
|
315
315
|
const response = await new Promise((resolve, reject) => {
|
|
316
316
|
https.get(`${apiServer}/api/v1/namespaces/${namespace}/endpoints/${serviceName}`, {
|
|
317
317
|
headers: {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Read/Write Separation for Distributed Scaling
|
|
3
3
|
* Implements primary-replica architecture for scalable reads
|
|
4
4
|
*/
|
|
5
|
-
import { EventEmitter } from 'events';
|
|
5
|
+
import { EventEmitter } from 'node:events';
|
|
6
6
|
import { DistributedCoordinator } from './coordinator.js';
|
|
7
7
|
import { ShardManager } from './shardManager.js';
|
|
8
8
|
import { CacheSync } from './cacheSync.js';
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Shard Manager for Horizontal Scaling
|
|
3
3
|
* Implements consistent hashing for data distribution across shards
|
|
4
4
|
*/
|
|
5
|
-
import { EventEmitter } from 'events';
|
|
5
|
+
import { EventEmitter } from 'node:events';
|
|
6
6
|
export interface ShardConfig {
|
|
7
7
|
shardCount?: number;
|
|
8
8
|
replicationFactor?: number;
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Shard Manager for Horizontal Scaling
|
|
3
3
|
* Implements consistent hashing for data distribution across shards
|
|
4
4
|
*/
|
|
5
|
-
import { createHash } from 'crypto';
|
|
6
|
-
import { EventEmitter } from 'events';
|
|
5
|
+
import { createHash } from 'node:crypto';
|
|
6
|
+
import { EventEmitter } from 'node:events';
|
|
7
7
|
/**
|
|
8
8
|
* Consistent Hash Ring for shard distribution
|
|
9
9
|
*/
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Handles zero-downtime migration of data between nodes
|
|
5
5
|
* Uses streaming for efficient transfer of large datasets
|
|
6
6
|
*/
|
|
7
|
-
import { EventEmitter } from 'events';
|
|
7
|
+
import { EventEmitter } from 'node:events';
|
|
8
8
|
import type { StorageAdapter } from '../coreTypes.js';
|
|
9
9
|
import type { ShardManager } from './shardManager.js';
|
|
10
10
|
import type { HTTPTransport } from './httpTransport.js';
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Handles zero-downtime migration of data between nodes
|
|
5
5
|
* Uses streaming for efficient transfer of large datasets
|
|
6
6
|
*/
|
|
7
|
-
import { EventEmitter } from 'events';
|
|
7
|
+
import { EventEmitter } from 'node:events';
|
|
8
8
|
export class ShardMigrationManager extends EventEmitter {
|
|
9
9
|
constructor(nodeId, storage, shardManager, transport, coordinator) {
|
|
10
10
|
super();
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Uses shared storage (S3/GCS/R2) as coordination point
|
|
4
4
|
* REAL PRODUCTION CODE - No mocks, no stubs!
|
|
5
5
|
*/
|
|
6
|
-
import { EventEmitter } from 'events';
|
|
6
|
+
import { EventEmitter } from 'node:events';
|
|
7
7
|
import { StorageAdapter } from '../coreTypes.js';
|
|
8
8
|
export interface NodeInfo {
|
|
9
9
|
id: string;
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* Uses shared storage (S3/GCS/R2) as coordination point
|
|
4
4
|
* REAL PRODUCTION CODE - No mocks, no stubs!
|
|
5
5
|
*/
|
|
6
|
-
import { EventEmitter } from 'events';
|
|
7
|
-
import * as os from 'os';
|
|
6
|
+
import { EventEmitter } from 'node:events';
|
|
7
|
+
import * as os from 'node:os';
|
|
8
8
|
export class StorageDiscovery extends EventEmitter {
|
|
9
9
|
constructor(storage, nodeId) {
|
|
10
10
|
super();
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
* hybridModelManager, universalMemoryManager, and more.
|
|
17
17
|
*/
|
|
18
18
|
import { pipeline, env } from '@huggingface/transformers';
|
|
19
|
-
import { existsSync } from 'fs';
|
|
20
|
-
import { join } from 'path';
|
|
19
|
+
import { existsSync } from 'node:fs';
|
|
20
|
+
import { join } from 'node:path';
|
|
21
21
|
// Global state for true singleton across entire process
|
|
22
22
|
let globalInstance = null;
|
|
23
23
|
let globalInitPromise = null;
|
package/dist/importManager.js
CHANGED
|
@@ -135,8 +135,8 @@ export class ImportManager {
|
|
|
135
135
|
_importedAt: new Date().toISOString(),
|
|
136
136
|
_confidence: item.confidence
|
|
137
137
|
};
|
|
138
|
-
// Add to brain using
|
|
139
|
-
const id = await this.brain.
|
|
138
|
+
// Add to brain using modern API signature
|
|
139
|
+
const id = await this.brain.add({ data: dataToImport, type: nounType || 'content', metadata });
|
|
140
140
|
result.nouns.push(id);
|
|
141
141
|
result.stats.imported++;
|
|
142
142
|
return id;
|
|
@@ -165,7 +165,13 @@ export class ImportManager {
|
|
|
165
165
|
const match = await this.typeMatcher.matchVerbType({ id: rel.sourceId }, { id: rel.targetId }, rel.verbType);
|
|
166
166
|
verbType = match.type;
|
|
167
167
|
}
|
|
168
|
-
const verbId = await this.brain.
|
|
168
|
+
const verbId = await this.brain.relate({
|
|
169
|
+
from: rel.sourceId,
|
|
170
|
+
to: rel.targetId,
|
|
171
|
+
type: verbType,
|
|
172
|
+
metadata: rel.metadata,
|
|
173
|
+
weight: rel.weight
|
|
174
|
+
});
|
|
169
175
|
result.verbs.push(verbId);
|
|
170
176
|
result.stats.relationships++;
|
|
171
177
|
}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* and getting relationships.
|
|
7
7
|
*/
|
|
8
8
|
import { v4 as uuidv4 } from '../universal/uuid.js';
|
|
9
|
+
import { NounType } from '../types/graphTypes.js';
|
|
9
10
|
import { MCP_VERSION } from '../types/mcpTypes.js';
|
|
10
11
|
export class BrainyMCPAdapter {
|
|
11
12
|
/**
|
|
@@ -49,7 +50,7 @@ export class BrainyMCPAdapter {
|
|
|
49
50
|
if (!id) {
|
|
50
51
|
return this.createErrorResponse(request.requestId, 'MISSING_PARAMETER', 'Parameter "id" is required');
|
|
51
52
|
}
|
|
52
|
-
const noun = await this.brainyData.
|
|
53
|
+
const noun = await this.brainyData.get(id);
|
|
53
54
|
if (!noun) {
|
|
54
55
|
return this.createErrorResponse(request.requestId, 'NOT_FOUND', `No noun found with id ${id}`);
|
|
55
56
|
}
|
|
@@ -65,7 +66,7 @@ export class BrainyMCPAdapter {
|
|
|
65
66
|
if (!query) {
|
|
66
67
|
return this.createErrorResponse(request.requestId, 'MISSING_PARAMETER', 'Parameter "query" is required');
|
|
67
68
|
}
|
|
68
|
-
const results = await this.brainyData.
|
|
69
|
+
const results = await this.brainyData.find({ query, limit: k });
|
|
69
70
|
return this.createSuccessResponse(request.requestId, results);
|
|
70
71
|
}
|
|
71
72
|
/**
|
|
@@ -78,8 +79,8 @@ export class BrainyMCPAdapter {
|
|
|
78
79
|
if (!text) {
|
|
79
80
|
return this.createErrorResponse(request.requestId, 'MISSING_PARAMETER', 'Parameter "text" is required');
|
|
80
81
|
}
|
|
81
|
-
// Add data
|
|
82
|
-
const id = await this.brainyData.
|
|
82
|
+
// Add data using modern API (interface only supports modern methods)
|
|
83
|
+
const id = await this.brainyData.add({ data: text, type: NounType.Document, metadata });
|
|
83
84
|
return this.createSuccessResponse(request.requestId, { id });
|
|
84
85
|
}
|
|
85
86
|
/**
|
|
@@ -2602,7 +2602,7 @@ export class ImprovedNeuralAPI {
|
|
|
2602
2602
|
if (clusters.length === 0)
|
|
2603
2603
|
break;
|
|
2604
2604
|
try {
|
|
2605
|
-
const noun = await this.brain.
|
|
2605
|
+
const noun = await this.brain.get(itemId);
|
|
2606
2606
|
const itemVector = noun?.vector || [];
|
|
2607
2607
|
if (itemVector.length === 0)
|
|
2608
2608
|
continue;
|
|
@@ -11,8 +11,8 @@ let moduleLoadingPromise = null;
|
|
|
11
11
|
// Try to load Node.js modules
|
|
12
12
|
try {
|
|
13
13
|
// Using dynamic imports to avoid issues in browser environments
|
|
14
|
-
const fsPromise = import('fs');
|
|
15
|
-
const pathPromise = import('path');
|
|
14
|
+
const fsPromise = import('node:fs');
|
|
15
|
+
const pathPromise = import('node:path');
|
|
16
16
|
moduleLoadingPromise = Promise.all([fsPromise, pathPromise])
|
|
17
17
|
.then(([fsModule, pathModule]) => {
|
|
18
18
|
fs = fsModule;
|
|
@@ -279,7 +279,7 @@ export class CacheManager {
|
|
|
279
279
|
if (this.environment === Environment.NODE) {
|
|
280
280
|
try {
|
|
281
281
|
// Use dynamic import for OS module
|
|
282
|
-
const os = await import('os');
|
|
282
|
+
const os = await import('node:os');
|
|
283
283
|
// Get actual system memory information
|
|
284
284
|
const totalMemory = os.totalmem();
|
|
285
285
|
const freeMemory = os.freemem();
|
|
@@ -139,7 +139,7 @@ export class EnhancedFileSystemClear {
|
|
|
139
139
|
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
140
140
|
const backupDir = `${this.rootDir}-backup-${timestamp}`;
|
|
141
141
|
// Use cp -r for efficient directory copying
|
|
142
|
-
const { spawn } = await import('child_process');
|
|
142
|
+
const { spawn } = await import('node:child_process');
|
|
143
143
|
return new Promise((resolve, reject) => {
|
|
144
144
|
const cp = spawn('cp', ['-r', this.rootDir, backupDir]);
|
|
145
145
|
cp.on('close', (code) => {
|
|
@@ -1,55 +1,48 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* BrainyInterface
|
|
2
|
+
* BrainyInterface - Modern API Only
|
|
3
3
|
*
|
|
4
|
-
* This interface defines the methods from Brainy
|
|
5
|
-
*
|
|
4
|
+
* This interface defines the MODERN methods from Brainy 3.0.
|
|
5
|
+
* Used to break circular dependencies while enforcing modern API usage.
|
|
6
|
+
*
|
|
7
|
+
* NO DEPRECATED METHODS - Only clean, modern API patterns.
|
|
6
8
|
*/
|
|
7
9
|
import { Vector } from '../coreTypes.js';
|
|
10
|
+
import { AddParams, RelateParams, Result, Entity, FindParams, SimilarParams } from './brainy.types.js';
|
|
8
11
|
export interface BrainyInterface<T = unknown> {
|
|
9
12
|
/**
|
|
10
13
|
* Initialize the database
|
|
11
14
|
*/
|
|
12
15
|
init(): Promise<void>;
|
|
13
16
|
/**
|
|
14
|
-
*
|
|
15
|
-
* @param
|
|
17
|
+
* Modern add method - unified entity creation
|
|
18
|
+
* @param params Parameters for adding entities
|
|
19
|
+
* @returns The ID of the created entity
|
|
16
20
|
*/
|
|
17
|
-
|
|
21
|
+
add(params: AddParams<T>): Promise<string>;
|
|
18
22
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* @
|
|
22
|
-
* @param nounType Required noun type (one of 31 types)
|
|
23
|
-
* @param metadata Optional metadata to associate with the noun
|
|
24
|
-
* @returns The ID of the added noun
|
|
23
|
+
* Modern relate method - unified relationship creation
|
|
24
|
+
* @param params Parameters for creating relationships
|
|
25
|
+
* @returns The ID of the created relationship
|
|
25
26
|
*/
|
|
26
|
-
|
|
27
|
+
relate(params: RelateParams<T>): Promise<string>;
|
|
27
28
|
/**
|
|
28
|
-
*
|
|
29
|
-
* @param
|
|
30
|
-
* @
|
|
31
|
-
* @returns Search results
|
|
29
|
+
* Modern find method - unified search and discovery
|
|
30
|
+
* @param query Search query or parameters object
|
|
31
|
+
* @returns Array of search results
|
|
32
32
|
*/
|
|
33
|
-
|
|
33
|
+
find(query: string | FindParams<T>): Promise<Result<T>[]>;
|
|
34
34
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* @
|
|
38
|
-
* @param targetId The ID of the target entity
|
|
39
|
-
* @param verbType The type of relationship
|
|
40
|
-
* @param metadata Optional metadata about the relationship
|
|
41
|
-
* @returns The ID of the created verb
|
|
35
|
+
* Modern get method - retrieve entities by ID
|
|
36
|
+
* @param id The entity ID to retrieve
|
|
37
|
+
* @returns Entity or null if not found
|
|
42
38
|
*/
|
|
43
|
-
|
|
39
|
+
get(id: string): Promise<Entity<T> | null>;
|
|
44
40
|
/**
|
|
45
|
-
*
|
|
46
|
-
* @param
|
|
47
|
-
* @
|
|
48
|
-
* @returns Array of search results with similarity scores
|
|
41
|
+
* Modern similar method - find similar entities
|
|
42
|
+
* @param params Parameters for similarity search
|
|
43
|
+
* @returns Array of similar entities with scores
|
|
49
44
|
*/
|
|
50
|
-
|
|
51
|
-
limit?: number;
|
|
52
|
-
}): Promise<unknown[]>;
|
|
45
|
+
similar(params: SimilarParams<T>): Promise<Result<T>[]>;
|
|
53
46
|
/**
|
|
54
47
|
* Generate embedding vector from text
|
|
55
48
|
* @param text The text to embed
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* BrainyInterface
|
|
2
|
+
* BrainyInterface - Modern API Only
|
|
3
3
|
*
|
|
4
|
-
* This interface defines the methods from Brainy
|
|
5
|
-
*
|
|
4
|
+
* This interface defines the MODERN methods from Brainy 3.0.
|
|
5
|
+
* Used to break circular dependencies while enforcing modern API usage.
|
|
6
|
+
*
|
|
7
|
+
* NO DEPRECATED METHODS - Only clean, modern API patterns.
|
|
6
8
|
*/
|
|
7
9
|
export {};
|
|
8
10
|
//# sourceMappingURL=brainyDataInterface.js.map
|
package/dist/universal/crypto.js
CHANGED
|
@@ -8,7 +8,8 @@ let nodeCrypto = null;
|
|
|
8
8
|
// Dynamic import for Node.js crypto (only in Node.js environment)
|
|
9
9
|
if (isNode()) {
|
|
10
10
|
try {
|
|
11
|
-
|
|
11
|
+
// Use node: protocol to prevent bundler polyfilling (requires Node 22+)
|
|
12
|
+
nodeCrypto = await import('node:crypto');
|
|
12
13
|
}
|
|
13
14
|
catch {
|
|
14
15
|
// Ignore import errors in non-Node environments
|
package/dist/universal/events.js
CHANGED
|
@@ -8,7 +8,7 @@ let nodeEvents = null;
|
|
|
8
8
|
// Dynamic import for Node.js events (only in Node.js environment)
|
|
9
9
|
if (isNode()) {
|
|
10
10
|
try {
|
|
11
|
-
nodeEvents = await import('events');
|
|
11
|
+
nodeEvents = await import('node:events');
|
|
12
12
|
}
|
|
13
13
|
catch {
|
|
14
14
|
// Ignore import errors in non-Node environments
|
package/dist/universal/fs.js
CHANGED
|
@@ -8,7 +8,8 @@ let nodeFs = null;
|
|
|
8
8
|
// Dynamic import for Node.js fs (only in Node.js environment)
|
|
9
9
|
if (isNode()) {
|
|
10
10
|
try {
|
|
11
|
-
|
|
11
|
+
// Use node: protocol to prevent bundler polyfilling (requires Node 22+)
|
|
12
|
+
nodeFs = await import('node:fs/promises');
|
|
12
13
|
}
|
|
13
14
|
catch {
|
|
14
15
|
// Ignore import errors in non-Node environments
|
package/dist/universal/path.js
CHANGED
|
@@ -8,7 +8,8 @@ let nodePath = null;
|
|
|
8
8
|
// Dynamic import for Node.js path (only in Node.js environment)
|
|
9
9
|
if (isNode()) {
|
|
10
10
|
try {
|
|
11
|
-
|
|
11
|
+
// Use node: protocol to prevent bundler polyfilling (requires Node 22+)
|
|
12
|
+
nodePath = await import('node:path');
|
|
12
13
|
}
|
|
13
14
|
catch {
|
|
14
15
|
// Ignore import errors in non-Node environments
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Automatically manages socket pools and connection settings based on load patterns
|
|
4
4
|
* Zero-configuration approach that learns and adapts to workload characteristics
|
|
5
5
|
*/
|
|
6
|
-
import { Agent as HttpsAgent } from 'https';
|
|
6
|
+
import { Agent as HttpsAgent } from 'node:https';
|
|
7
7
|
import { NodeHttpHandler } from '@smithy/node-http-handler';
|
|
8
8
|
import { createModuleLogger } from './logger.js';
|
|
9
9
|
/**
|
|
@@ -159,7 +159,7 @@ export class AutoConfiguration {
|
|
|
159
159
|
// Node.js memory detection
|
|
160
160
|
if (isNode()) {
|
|
161
161
|
try {
|
|
162
|
-
const os = await import('os');
|
|
162
|
+
const os = await import('node:os');
|
|
163
163
|
availableMemory = os.totalmem() * 0.7; // Use 70% of total memory
|
|
164
164
|
cpuCores = os.cpus().length;
|
|
165
165
|
}
|
package/dist/utils/embedding.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* Complete rewrite to eliminate TensorFlow.js and use ONNX-based models
|
|
4
4
|
*/
|
|
5
5
|
import { isBrowser } from './environment.js';
|
|
6
|
-
import { join } from 'path';
|
|
7
|
-
import { existsSync } from 'fs';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
import { existsSync } from 'node:fs';
|
|
8
8
|
// @ts-ignore - Transformers.js is now the primary embedding library
|
|
9
9
|
import { pipeline, env } from '@huggingface/transformers';
|
|
10
10
|
// CRITICAL: Disable ONNX memory arena to prevent 4-8GB allocation
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Only enforces universal truths, learns everything else
|
|
6
6
|
*/
|
|
7
7
|
import { NounType, VerbType } from '../types/graphTypes.js';
|
|
8
|
-
import * as os from 'os';
|
|
8
|
+
import * as os from 'node:os';
|
|
9
9
|
/**
|
|
10
10
|
* Auto-configured limits based on system resources
|
|
11
11
|
* These adapt to available memory and observed performance
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* performance tracking, and multiple transport support
|
|
5
5
|
*/
|
|
6
6
|
import { performance } from 'perf_hooks';
|
|
7
|
-
import { hostname } from 'os';
|
|
8
|
-
import { randomUUID } from 'crypto';
|
|
7
|
+
import { hostname } from 'node:os';
|
|
8
|
+
import { randomUUID } from 'node:crypto';
|
|
9
9
|
export var LogLevel;
|
|
10
10
|
(function (LogLevel) {
|
|
11
11
|
LogLevel[LogLevel["SILENT"] = -1] = "SILENT";
|
package/dist/utils/version.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Version utilities for Brainy
|
|
3
3
|
*/
|
|
4
|
-
import { readFileSync } from 'fs';
|
|
5
|
-
import { join, dirname } from 'path';
|
|
6
|
-
import { fileURLToPath } from 'url';
|
|
4
|
+
import { readFileSync } from 'node:fs';
|
|
5
|
+
import { join, dirname } from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
7
|
// Get package.json path relative to this file
|
|
8
8
|
const __filename = fileURLToPath(import.meta.url);
|
|
9
9
|
const __dirname = dirname(__filename);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soulcraft/brainy",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"description": "Universal Knowledge Protocol™ - World's first Triple Intelligence database unifying vector, graph, and document search in one API. 31 nouns × 40 verbs for infinite expressiveness.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|