@soulcraft/brainy 0.40.0 → 0.41.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/dist/index.d.ts +2 -1
- package/dist/storage/adapters/optimizedS3Search.d.ts +79 -0
- package/dist/storage/adapters/optimizedS3Search.d.ts.map +1 -0
- package/dist/storage/adapters/s3CompatibleStorage.d.ts +21 -0
- package/dist/storage/adapters/s3CompatibleStorage.d.ts.map +1 -1
- package/dist/storage/baseStorage.d.ts +1 -0
- package/dist/storage/baseStorage.d.ts.map +1 -1
- package/dist/unified.js +304 -101
- package/dist/unified.min.js +991 -991
- package/dist/utils/logger.d.ts +45 -92
- package/dist/utils/logger.d.ts.map +1 -1
- package/package.json +4 -1
package/dist/unified.js
CHANGED
|
@@ -6278,6 +6278,7 @@ class BaseStorage extends BaseStorageAdapter {
|
|
|
6278
6278
|
constructor() {
|
|
6279
6279
|
super(...arguments);
|
|
6280
6280
|
this.isInitialized = false;
|
|
6281
|
+
this.readOnly = false;
|
|
6281
6282
|
}
|
|
6282
6283
|
/**
|
|
6283
6284
|
* Ensure the storage adapter is initialized
|
|
@@ -10039,6 +10040,135 @@ class CacheManager {
|
|
|
10039
10040
|
}
|
|
10040
10041
|
}
|
|
10041
10042
|
|
|
10043
|
+
/**
|
|
10044
|
+
* Centralized logging utility for Brainy
|
|
10045
|
+
* Provides configurable log levels and consistent logging across the codebase
|
|
10046
|
+
*/
|
|
10047
|
+
var LogLevel;
|
|
10048
|
+
(function (LogLevel) {
|
|
10049
|
+
LogLevel[LogLevel["ERROR"] = 0] = "ERROR";
|
|
10050
|
+
LogLevel[LogLevel["WARN"] = 1] = "WARN";
|
|
10051
|
+
LogLevel[LogLevel["INFO"] = 2] = "INFO";
|
|
10052
|
+
LogLevel[LogLevel["DEBUG"] = 3] = "DEBUG";
|
|
10053
|
+
LogLevel[LogLevel["TRACE"] = 4] = "TRACE";
|
|
10054
|
+
})(LogLevel || (LogLevel = {}));
|
|
10055
|
+
let Logger$1 = class Logger {
|
|
10056
|
+
constructor() {
|
|
10057
|
+
this.config = {
|
|
10058
|
+
level: LogLevel.WARN, // Default to WARN - only critical messages
|
|
10059
|
+
timestamps: true,
|
|
10060
|
+
includeModule: true
|
|
10061
|
+
};
|
|
10062
|
+
// Set log level from environment variable if available
|
|
10063
|
+
const envLogLevel = process.env.BRAINY_LOG_LEVEL;
|
|
10064
|
+
if (envLogLevel) {
|
|
10065
|
+
const level = LogLevel[envLogLevel.toUpperCase()];
|
|
10066
|
+
if (level !== undefined) {
|
|
10067
|
+
this.config.level = level;
|
|
10068
|
+
}
|
|
10069
|
+
}
|
|
10070
|
+
// Parse module-specific log levels
|
|
10071
|
+
const moduleLogLevels = process.env.BRAINY_MODULE_LOG_LEVELS;
|
|
10072
|
+
if (moduleLogLevels) {
|
|
10073
|
+
try {
|
|
10074
|
+
this.config.modules = JSON.parse(moduleLogLevels);
|
|
10075
|
+
}
|
|
10076
|
+
catch (e) {
|
|
10077
|
+
// Ignore parsing errors
|
|
10078
|
+
}
|
|
10079
|
+
}
|
|
10080
|
+
}
|
|
10081
|
+
static getInstance() {
|
|
10082
|
+
if (!Logger.instance) {
|
|
10083
|
+
Logger.instance = new Logger();
|
|
10084
|
+
}
|
|
10085
|
+
return Logger.instance;
|
|
10086
|
+
}
|
|
10087
|
+
configure(config) {
|
|
10088
|
+
this.config = { ...this.config, ...config };
|
|
10089
|
+
}
|
|
10090
|
+
shouldLog(level, module) {
|
|
10091
|
+
// Check module-specific level first
|
|
10092
|
+
if (this.config.modules && this.config.modules[module] !== undefined) {
|
|
10093
|
+
return level <= this.config.modules[module];
|
|
10094
|
+
}
|
|
10095
|
+
// Otherwise use global level
|
|
10096
|
+
return level <= this.config.level;
|
|
10097
|
+
}
|
|
10098
|
+
formatMessage(level, module, message) {
|
|
10099
|
+
const parts = [];
|
|
10100
|
+
if (this.config.timestamps) {
|
|
10101
|
+
parts.push(`[${new Date().toISOString()}]`);
|
|
10102
|
+
}
|
|
10103
|
+
parts.push(`[${LogLevel[level]}]`);
|
|
10104
|
+
if (this.config.includeModule) {
|
|
10105
|
+
parts.push(`[${module}]`);
|
|
10106
|
+
}
|
|
10107
|
+
parts.push(message);
|
|
10108
|
+
return parts.join(' ');
|
|
10109
|
+
}
|
|
10110
|
+
log(level, module, message, ...args) {
|
|
10111
|
+
if (!this.shouldLog(level, module)) {
|
|
10112
|
+
return;
|
|
10113
|
+
}
|
|
10114
|
+
if (this.config.handler) {
|
|
10115
|
+
this.config.handler(level, module, message, ...args);
|
|
10116
|
+
return;
|
|
10117
|
+
}
|
|
10118
|
+
const formattedMessage = this.formatMessage(level, module, message);
|
|
10119
|
+
switch (level) {
|
|
10120
|
+
case LogLevel.ERROR:
|
|
10121
|
+
console.error(formattedMessage, ...args);
|
|
10122
|
+
break;
|
|
10123
|
+
case LogLevel.WARN:
|
|
10124
|
+
console.warn(formattedMessage, ...args);
|
|
10125
|
+
break;
|
|
10126
|
+
case LogLevel.INFO:
|
|
10127
|
+
console.info(formattedMessage, ...args);
|
|
10128
|
+
break;
|
|
10129
|
+
case LogLevel.DEBUG:
|
|
10130
|
+
case LogLevel.TRACE:
|
|
10131
|
+
console.log(formattedMessage, ...args);
|
|
10132
|
+
break;
|
|
10133
|
+
}
|
|
10134
|
+
}
|
|
10135
|
+
error(module, message, ...args) {
|
|
10136
|
+
this.log(LogLevel.ERROR, module, message, ...args);
|
|
10137
|
+
}
|
|
10138
|
+
warn(module, message, ...args) {
|
|
10139
|
+
this.log(LogLevel.WARN, module, message, ...args);
|
|
10140
|
+
}
|
|
10141
|
+
info(module, message, ...args) {
|
|
10142
|
+
this.log(LogLevel.INFO, module, message, ...args);
|
|
10143
|
+
}
|
|
10144
|
+
debug(module, message, ...args) {
|
|
10145
|
+
this.log(LogLevel.DEBUG, module, message, ...args);
|
|
10146
|
+
}
|
|
10147
|
+
trace(module, message, ...args) {
|
|
10148
|
+
this.log(LogLevel.TRACE, module, message, ...args);
|
|
10149
|
+
}
|
|
10150
|
+
// Create a module-specific logger
|
|
10151
|
+
createModuleLogger(module) {
|
|
10152
|
+
return {
|
|
10153
|
+
error: (message, ...args) => this.error(module, message, ...args),
|
|
10154
|
+
warn: (message, ...args) => this.warn(module, message, ...args),
|
|
10155
|
+
info: (message, ...args) => this.info(module, message, ...args),
|
|
10156
|
+
debug: (message, ...args) => this.debug(module, message, ...args),
|
|
10157
|
+
trace: (message, ...args) => this.trace(module, message, ...args)
|
|
10158
|
+
};
|
|
10159
|
+
}
|
|
10160
|
+
};
|
|
10161
|
+
// Export singleton instance
|
|
10162
|
+
const logger = Logger$1.getInstance();
|
|
10163
|
+
// Export convenience function for creating module loggers
|
|
10164
|
+
function createModuleLogger(module) {
|
|
10165
|
+
return logger.createModuleLogger(module);
|
|
10166
|
+
}
|
|
10167
|
+
// Export function to configure logger
|
|
10168
|
+
function configureLogger(config) {
|
|
10169
|
+
logger.configure(config);
|
|
10170
|
+
}
|
|
10171
|
+
|
|
10042
10172
|
/**
|
|
10043
10173
|
* S3-Compatible Storage Adapter
|
|
10044
10174
|
* Uses the AWS S3 client to interact with S3-compatible storage services
|
|
@@ -10081,6 +10211,8 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
10081
10211
|
this.activeLocks = new Set();
|
|
10082
10212
|
// Change log for efficient synchronization
|
|
10083
10213
|
this.changeLogPrefix = 'change-log/';
|
|
10214
|
+
// Module logger
|
|
10215
|
+
this.logger = createModuleLogger('S3Storage');
|
|
10084
10216
|
// Node cache to avoid redundant API calls
|
|
10085
10217
|
this.nodeCache = new Map();
|
|
10086
10218
|
// Batch update timer ID
|
|
@@ -10101,6 +10233,7 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
10101
10233
|
this.secretAccessKey = options.secretAccessKey;
|
|
10102
10234
|
this.sessionToken = options.sessionToken;
|
|
10103
10235
|
this.serviceType = options.serviceType || 's3';
|
|
10236
|
+
this.readOnly = options.readOnly || false;
|
|
10104
10237
|
// Initialize operation executors with timeout and retry configuration
|
|
10105
10238
|
this.operationExecutors = new StorageOperationExecutors(options.operationConfig);
|
|
10106
10239
|
// Set up prefixes for different types of data
|
|
@@ -10222,9 +10355,10 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
10222
10355
|
this.nounCacheManager.setStorageAdapters(nounStorageAdapter, nounStorageAdapter);
|
|
10223
10356
|
this.verbCacheManager.setStorageAdapters(verbStorageAdapter, verbStorageAdapter);
|
|
10224
10357
|
this.isInitialized = true;
|
|
10358
|
+
this.logger.info(`Initialized ${this.serviceType} storage with bucket ${this.bucketName}`);
|
|
10225
10359
|
}
|
|
10226
10360
|
catch (error) {
|
|
10227
|
-
|
|
10361
|
+
this.logger.error(`Failed to initialize ${this.serviceType} storage:`, error);
|
|
10228
10362
|
throw new Error(`Failed to initialize ${this.serviceType} storage: ${error}`);
|
|
10229
10363
|
}
|
|
10230
10364
|
}
|
|
@@ -10240,7 +10374,7 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
10240
10374
|
async saveNode(node) {
|
|
10241
10375
|
await this.ensureInitialized();
|
|
10242
10376
|
try {
|
|
10243
|
-
|
|
10377
|
+
this.logger.trace(`Saving node ${node.id}`);
|
|
10244
10378
|
// Convert connections Map to a serializable format
|
|
10245
10379
|
const serializableNode = {
|
|
10246
10380
|
...node,
|
|
@@ -10250,8 +10384,7 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
10250
10384
|
const { PutObjectCommand } = await import('@aws-sdk/client-s3');
|
|
10251
10385
|
const key = `${this.nounPrefix}${node.id}.json`;
|
|
10252
10386
|
const body = JSON.stringify(serializableNode, null, 2);
|
|
10253
|
-
|
|
10254
|
-
console.log(`Node data: ${body.substring(0, 100)}${body.length > 100 ? '...' : ''}`);
|
|
10387
|
+
this.logger.trace(`Saving to key: ${key}`);
|
|
10255
10388
|
// Save the node to S3-compatible storage
|
|
10256
10389
|
const result = await this.s3Client.send(new PutObjectCommand({
|
|
10257
10390
|
Bucket: this.bucketName,
|
|
@@ -10259,7 +10392,7 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
10259
10392
|
Body: body,
|
|
10260
10393
|
ContentType: 'application/json'
|
|
10261
10394
|
}));
|
|
10262
|
-
|
|
10395
|
+
this.logger.debug(`Node ${node.id} saved successfully`);
|
|
10263
10396
|
// Log the change for efficient synchronization
|
|
10264
10397
|
await this.appendToChangeLog({
|
|
10265
10398
|
timestamp: Date.now(),
|
|
@@ -10279,18 +10412,18 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
10279
10412
|
Key: key
|
|
10280
10413
|
}));
|
|
10281
10414
|
if (verifyResponse && verifyResponse.Body) {
|
|
10282
|
-
|
|
10415
|
+
this.logger.trace(`Verified node ${node.id} was saved correctly`);
|
|
10283
10416
|
}
|
|
10284
10417
|
else {
|
|
10285
|
-
|
|
10418
|
+
this.logger.warn(`Failed to verify node ${node.id} was saved correctly: no response or body`);
|
|
10286
10419
|
}
|
|
10287
10420
|
}
|
|
10288
10421
|
catch (verifyError) {
|
|
10289
|
-
|
|
10422
|
+
this.logger.warn(`Failed to verify node ${node.id} was saved correctly:`, verifyError);
|
|
10290
10423
|
}
|
|
10291
10424
|
}
|
|
10292
10425
|
catch (error) {
|
|
10293
|
-
|
|
10426
|
+
this.logger.error(`Failed to save node ${node.id}:`, error);
|
|
10294
10427
|
throw new Error(`Failed to save node ${node.id}: ${error}`);
|
|
10295
10428
|
}
|
|
10296
10429
|
}
|
|
@@ -10308,9 +10441,8 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
10308
10441
|
try {
|
|
10309
10442
|
// Import the GetObjectCommand only when needed
|
|
10310
10443
|
const { GetObjectCommand } = await import('@aws-sdk/client-s3');
|
|
10311
|
-
console.log(`Getting node ${id} from bucket ${this.bucketName}`);
|
|
10312
10444
|
const key = `${this.nounPrefix}${id}.json`;
|
|
10313
|
-
|
|
10445
|
+
this.logger.trace(`Getting node ${id} from key: ${key}`);
|
|
10314
10446
|
// Try to get the node from the nouns directory
|
|
10315
10447
|
const response = await this.s3Client.send(new GetObjectCommand({
|
|
10316
10448
|
Bucket: this.bucketName,
|
|
@@ -10318,22 +10450,22 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
10318
10450
|
}));
|
|
10319
10451
|
// Check if response is null or undefined
|
|
10320
10452
|
if (!response || !response.Body) {
|
|
10321
|
-
|
|
10453
|
+
this.logger.trace(`No node found for ${id}`);
|
|
10322
10454
|
return null;
|
|
10323
10455
|
}
|
|
10324
10456
|
// Convert the response body to a string
|
|
10325
10457
|
const bodyContents = await response.Body.transformToString();
|
|
10326
|
-
|
|
10458
|
+
this.logger.trace(`Retrieved node body for ${id}`);
|
|
10327
10459
|
// Parse the JSON string
|
|
10328
10460
|
try {
|
|
10329
10461
|
const parsedNode = JSON.parse(bodyContents);
|
|
10330
|
-
|
|
10462
|
+
this.logger.trace(`Parsed node data for ${id}`);
|
|
10331
10463
|
// Ensure the parsed node has the expected properties
|
|
10332
10464
|
if (!parsedNode ||
|
|
10333
10465
|
!parsedNode.id ||
|
|
10334
10466
|
!parsedNode.vector ||
|
|
10335
10467
|
!parsedNode.connections) {
|
|
10336
|
-
|
|
10468
|
+
this.logger.warn(`Invalid node data for ${id}`);
|
|
10337
10469
|
return null;
|
|
10338
10470
|
}
|
|
10339
10471
|
// Convert serialized connections back to Map<number, Set<string>>
|
|
@@ -10347,17 +10479,17 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
10347
10479
|
connections,
|
|
10348
10480
|
level: parsedNode.level || 0
|
|
10349
10481
|
};
|
|
10350
|
-
|
|
10482
|
+
this.logger.trace(`Successfully retrieved node ${id}`);
|
|
10351
10483
|
return node;
|
|
10352
10484
|
}
|
|
10353
10485
|
catch (parseError) {
|
|
10354
|
-
|
|
10486
|
+
this.logger.error(`Failed to parse node data for ${id}:`, parseError);
|
|
10355
10487
|
return null;
|
|
10356
10488
|
}
|
|
10357
10489
|
}
|
|
10358
10490
|
catch (error) {
|
|
10359
10491
|
// Node not found or other error
|
|
10360
|
-
|
|
10492
|
+
this.logger.trace(`Node not found for ${id}`);
|
|
10361
10493
|
return null;
|
|
10362
10494
|
}
|
|
10363
10495
|
}
|
|
@@ -10365,7 +10497,12 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
10365
10497
|
* Get all nouns from storage (internal implementation)
|
|
10366
10498
|
*/
|
|
10367
10499
|
async getAllNouns_internal() {
|
|
10368
|
-
|
|
10500
|
+
// Use paginated method to avoid deprecation warning
|
|
10501
|
+
const result = await this.getNodesWithPagination({
|
|
10502
|
+
limit: 1000,
|
|
10503
|
+
useCache: true
|
|
10504
|
+
});
|
|
10505
|
+
return result.nodes;
|
|
10369
10506
|
}
|
|
10370
10507
|
/**
|
|
10371
10508
|
* Get all nodes from storage
|
|
@@ -10374,7 +10511,7 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
10374
10511
|
*/
|
|
10375
10512
|
async getAllNodes() {
|
|
10376
10513
|
await this.ensureInitialized();
|
|
10377
|
-
|
|
10514
|
+
this.logger.warn('getAllNodes() is deprecated and will be removed in a future version. Use getNodesWithPagination() instead.');
|
|
10378
10515
|
try {
|
|
10379
10516
|
// Use the paginated method with a large limit to maintain backward compatibility
|
|
10380
10517
|
// but warn about potential issues
|
|
@@ -10383,12 +10520,12 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
10383
10520
|
useCache: true
|
|
10384
10521
|
});
|
|
10385
10522
|
if (result.hasMore) {
|
|
10386
|
-
|
|
10523
|
+
this.logger.warn(`Only returning the first 1000 nodes. There are more nodes available. Use getNodesWithPagination() for proper pagination.`);
|
|
10387
10524
|
}
|
|
10388
10525
|
return result.nodes;
|
|
10389
10526
|
}
|
|
10390
10527
|
catch (error) {
|
|
10391
|
-
|
|
10528
|
+
this.logger.error('Failed to get all nodes:', error);
|
|
10392
10529
|
return [];
|
|
10393
10530
|
}
|
|
10394
10531
|
}
|
|
@@ -10476,7 +10613,7 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
10476
10613
|
};
|
|
10477
10614
|
}
|
|
10478
10615
|
catch (error) {
|
|
10479
|
-
|
|
10616
|
+
this.logger.error('Failed to get nodes with pagination:', error);
|
|
10480
10617
|
return {
|
|
10481
10618
|
nodes: [],
|
|
10482
10619
|
hasMore: false
|
|
@@ -10522,14 +10659,14 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
10522
10659
|
cursor = result.nextCursor;
|
|
10523
10660
|
// Safety check to prevent infinite loops
|
|
10524
10661
|
if (!cursor && hasMore) {
|
|
10525
|
-
|
|
10662
|
+
this.logger.warn('No cursor returned but hasMore is true, breaking loop');
|
|
10526
10663
|
break;
|
|
10527
10664
|
}
|
|
10528
10665
|
}
|
|
10529
10666
|
return filteredNodes;
|
|
10530
10667
|
}
|
|
10531
10668
|
catch (error) {
|
|
10532
|
-
|
|
10669
|
+
this.logger.error(`Failed to get nodes by noun type ${nounType}:`, error);
|
|
10533
10670
|
return [];
|
|
10534
10671
|
}
|
|
10535
10672
|
}
|
|
@@ -10561,7 +10698,7 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
10561
10698
|
});
|
|
10562
10699
|
}
|
|
10563
10700
|
catch (error) {
|
|
10564
|
-
|
|
10701
|
+
this.logger.error(`Failed to delete node ${id}:`, error);
|
|
10565
10702
|
throw new Error(`Failed to delete node ${id}: ${error}`);
|
|
10566
10703
|
}
|
|
10567
10704
|
}
|
|
@@ -10603,7 +10740,7 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
10603
10740
|
});
|
|
10604
10741
|
}
|
|
10605
10742
|
catch (error) {
|
|
10606
|
-
|
|
10743
|
+
this.logger.error(`Failed to save edge ${edge.id}:`, error);
|
|
10607
10744
|
throw new Error(`Failed to save edge ${edge.id}: ${error}`);
|
|
10608
10745
|
}
|
|
10609
10746
|
}
|
|
@@ -10621,9 +10758,8 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
10621
10758
|
try {
|
|
10622
10759
|
// Import the GetObjectCommand only when needed
|
|
10623
10760
|
const { GetObjectCommand } = await import('@aws-sdk/client-s3');
|
|
10624
|
-
console.log(`Getting edge ${id} from bucket ${this.bucketName}`);
|
|
10625
10761
|
const key = `${this.verbPrefix}${id}.json`;
|
|
10626
|
-
|
|
10762
|
+
this.logger.trace(`Getting edge ${id} from key: ${key}`);
|
|
10627
10763
|
// Try to get the edge from the verbs directory
|
|
10628
10764
|
const response = await this.s3Client.send(new GetObjectCommand({
|
|
10629
10765
|
Bucket: this.bucketName,
|
|
@@ -10631,22 +10767,22 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
10631
10767
|
}));
|
|
10632
10768
|
// Check if response is null or undefined
|
|
10633
10769
|
if (!response || !response.Body) {
|
|
10634
|
-
|
|
10770
|
+
this.logger.trace(`No edge found for ${id}`);
|
|
10635
10771
|
return null;
|
|
10636
10772
|
}
|
|
10637
10773
|
// Convert the response body to a string
|
|
10638
10774
|
const bodyContents = await response.Body.transformToString();
|
|
10639
|
-
|
|
10775
|
+
this.logger.trace(`Retrieved edge body for ${id}`);
|
|
10640
10776
|
// Parse the JSON string
|
|
10641
10777
|
try {
|
|
10642
10778
|
const parsedEdge = JSON.parse(bodyContents);
|
|
10643
|
-
|
|
10779
|
+
this.logger.trace(`Parsed edge data for ${id}`);
|
|
10644
10780
|
// Ensure the parsed edge has the expected properties
|
|
10645
10781
|
if (!parsedEdge ||
|
|
10646
10782
|
!parsedEdge.id ||
|
|
10647
10783
|
!parsedEdge.vector ||
|
|
10648
10784
|
!parsedEdge.connections) {
|
|
10649
|
-
|
|
10785
|
+
this.logger.warn(`Invalid edge data for ${id}`);
|
|
10650
10786
|
return null;
|
|
10651
10787
|
}
|
|
10652
10788
|
// Convert serialized connections back to Map<number, Set<string>>
|
|
@@ -10659,17 +10795,17 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
10659
10795
|
vector: parsedEdge.vector,
|
|
10660
10796
|
connections
|
|
10661
10797
|
};
|
|
10662
|
-
|
|
10798
|
+
this.logger.trace(`Successfully retrieved edge ${id}`);
|
|
10663
10799
|
return edge;
|
|
10664
10800
|
}
|
|
10665
10801
|
catch (parseError) {
|
|
10666
|
-
|
|
10802
|
+
this.logger.error(`Failed to parse edge data for ${id}:`, parseError);
|
|
10667
10803
|
return null;
|
|
10668
10804
|
}
|
|
10669
10805
|
}
|
|
10670
10806
|
catch (error) {
|
|
10671
10807
|
// Edge not found or other error
|
|
10672
|
-
|
|
10808
|
+
this.logger.trace(`Edge not found for ${id}`);
|
|
10673
10809
|
return null;
|
|
10674
10810
|
}
|
|
10675
10811
|
}
|
|
@@ -10679,7 +10815,7 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
10679
10815
|
* It can cause memory issues with large datasets. Use getVerbsWithPagination() instead.
|
|
10680
10816
|
*/
|
|
10681
10817
|
async getAllVerbs_internal() {
|
|
10682
|
-
|
|
10818
|
+
this.logger.warn('getAllVerbs_internal() is deprecated and will be removed in a future version. Use getVerbsWithPagination() instead.');
|
|
10683
10819
|
return this.getAllEdges();
|
|
10684
10820
|
}
|
|
10685
10821
|
/**
|
|
@@ -10689,7 +10825,7 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
10689
10825
|
*/
|
|
10690
10826
|
async getAllEdges() {
|
|
10691
10827
|
await this.ensureInitialized();
|
|
10692
|
-
|
|
10828
|
+
this.logger.warn('getAllEdges() is deprecated and will be removed in a future version. Use getEdgesWithPagination() instead.');
|
|
10693
10829
|
try {
|
|
10694
10830
|
// Use the paginated method with a large limit to maintain backward compatibility
|
|
10695
10831
|
// but warn about potential issues
|
|
@@ -10698,12 +10834,12 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
10698
10834
|
useCache: true
|
|
10699
10835
|
});
|
|
10700
10836
|
if (result.hasMore) {
|
|
10701
|
-
|
|
10837
|
+
this.logger.warn(`Only returning the first 1000 edges. There are more edges available. Use getEdgesWithPagination() for proper pagination.`);
|
|
10702
10838
|
}
|
|
10703
10839
|
return result.edges;
|
|
10704
10840
|
}
|
|
10705
10841
|
catch (error) {
|
|
10706
|
-
|
|
10842
|
+
this.logger.error('Failed to get all edges:', error);
|
|
10707
10843
|
return [];
|
|
10708
10844
|
}
|
|
10709
10845
|
}
|
|
@@ -10800,7 +10936,7 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
10800
10936
|
};
|
|
10801
10937
|
}
|
|
10802
10938
|
catch (error) {
|
|
10803
|
-
|
|
10939
|
+
this.logger.error('Failed to get edges with pagination:', error);
|
|
10804
10940
|
return {
|
|
10805
10941
|
edges: [],
|
|
10806
10942
|
hasMore: false
|
|
@@ -10816,7 +10952,7 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
10816
10952
|
filterEdge(edge, filter) {
|
|
10817
10953
|
// HNSWVerb filtering is not supported since metadata is stored separately
|
|
10818
10954
|
// This method is deprecated and should not be used with the new storage pattern
|
|
10819
|
-
|
|
10955
|
+
this.logger.trace('Edge filtering is deprecated and not supported with the new storage pattern');
|
|
10820
10956
|
return true; // Return all edges since filtering requires metadata
|
|
10821
10957
|
}
|
|
10822
10958
|
/**
|
|
@@ -10881,7 +11017,7 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
10881
11017
|
async getEdgesBySource(sourceId) {
|
|
10882
11018
|
// This method is deprecated and would require loading metadata for each edge
|
|
10883
11019
|
// For now, return empty array since this is not efficiently implementable with new storage pattern
|
|
10884
|
-
|
|
11020
|
+
this.logger.trace('getEdgesBySource is deprecated and not efficiently supported in new storage pattern');
|
|
10885
11021
|
return [];
|
|
10886
11022
|
}
|
|
10887
11023
|
/**
|
|
@@ -10896,7 +11032,7 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
10896
11032
|
async getEdgesByTarget(targetId) {
|
|
10897
11033
|
// This method is deprecated and would require loading metadata for each edge
|
|
10898
11034
|
// For now, return empty array since this is not efficiently implementable with new storage pattern
|
|
10899
|
-
|
|
11035
|
+
this.logger.trace('getEdgesByTarget is deprecated and not efficiently supported in new storage pattern');
|
|
10900
11036
|
return [];
|
|
10901
11037
|
}
|
|
10902
11038
|
/**
|
|
@@ -10911,7 +11047,7 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
10911
11047
|
async getEdgesByType(type) {
|
|
10912
11048
|
// This method is deprecated and would require loading metadata for each edge
|
|
10913
11049
|
// For now, return empty array since this is not efficiently implementable with new storage pattern
|
|
10914
|
-
|
|
11050
|
+
this.logger.trace('getEdgesByType is deprecated and not efficiently supported in new storage pattern');
|
|
10915
11051
|
return [];
|
|
10916
11052
|
}
|
|
10917
11053
|
/**
|
|
@@ -10942,7 +11078,7 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
10942
11078
|
});
|
|
10943
11079
|
}
|
|
10944
11080
|
catch (error) {
|
|
10945
|
-
|
|
11081
|
+
this.logger.error(`Failed to delete edge ${id}:`, error);
|
|
10946
11082
|
throw new Error(`Failed to delete edge ${id}: ${error}`);
|
|
10947
11083
|
}
|
|
10948
11084
|
}
|
|
@@ -10952,13 +11088,11 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
10952
11088
|
async saveMetadata(id, metadata) {
|
|
10953
11089
|
await this.ensureInitialized();
|
|
10954
11090
|
try {
|
|
10955
|
-
console.log(`Saving metadata for ${id} to bucket ${this.bucketName}`);
|
|
10956
11091
|
// Import the PutObjectCommand only when needed
|
|
10957
11092
|
const { PutObjectCommand } = await import('@aws-sdk/client-s3');
|
|
10958
11093
|
const key = `${this.metadataPrefix}${id}.json`;
|
|
10959
11094
|
const body = JSON.stringify(metadata, null, 2);
|
|
10960
|
-
|
|
10961
|
-
console.log(`Metadata: ${body}`);
|
|
11095
|
+
this.logger.trace(`Saving metadata for ${id} to key: ${key}`);
|
|
10962
11096
|
// Save the metadata to S3-compatible storage
|
|
10963
11097
|
const result = await this.s3Client.send(new PutObjectCommand({
|
|
10964
11098
|
Bucket: this.bucketName,
|
|
@@ -10966,7 +11100,7 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
10966
11100
|
Body: body,
|
|
10967
11101
|
ContentType: 'application/json'
|
|
10968
11102
|
}));
|
|
10969
|
-
|
|
11103
|
+
this.logger.debug(`Metadata for ${id} saved successfully`);
|
|
10970
11104
|
// Log the change for efficient synchronization
|
|
10971
11105
|
await this.appendToChangeLog({
|
|
10972
11106
|
timestamp: Date.now(),
|
|
@@ -10983,19 +11117,18 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
10983
11117
|
Key: key
|
|
10984
11118
|
}));
|
|
10985
11119
|
if (verifyResponse && verifyResponse.Body) {
|
|
10986
|
-
|
|
10987
|
-
console.log(`Verified metadata for ${id} was saved correctly: ${bodyContents}`);
|
|
11120
|
+
this.logger.trace(`Verified metadata for ${id} was saved correctly`);
|
|
10988
11121
|
}
|
|
10989
11122
|
else {
|
|
10990
|
-
|
|
11123
|
+
this.logger.warn(`Failed to verify metadata for ${id} was saved correctly: no response or body`);
|
|
10991
11124
|
}
|
|
10992
11125
|
}
|
|
10993
11126
|
catch (verifyError) {
|
|
10994
|
-
|
|
11127
|
+
this.logger.warn(`Failed to verify metadata for ${id} was saved correctly:`, verifyError);
|
|
10995
11128
|
}
|
|
10996
11129
|
}
|
|
10997
11130
|
catch (error) {
|
|
10998
|
-
|
|
11131
|
+
this.logger.error(`Failed to save metadata for ${id}:`, error);
|
|
10999
11132
|
throw new Error(`Failed to save metadata for ${id}: ${error}`);
|
|
11000
11133
|
}
|
|
11001
11134
|
}
|
|
@@ -11005,13 +11138,11 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
11005
11138
|
async saveVerbMetadata(id, metadata) {
|
|
11006
11139
|
await this.ensureInitialized();
|
|
11007
11140
|
try {
|
|
11008
|
-
console.log(`Saving verb metadata for ${id} to bucket ${this.bucketName}`);
|
|
11009
11141
|
// Import the PutObjectCommand only when needed
|
|
11010
11142
|
const { PutObjectCommand } = await import('@aws-sdk/client-s3');
|
|
11011
11143
|
const key = `verb-metadata/${id}.json`;
|
|
11012
11144
|
const body = JSON.stringify(metadata, null, 2);
|
|
11013
|
-
|
|
11014
|
-
console.log(`Verb Metadata: ${body}`);
|
|
11145
|
+
this.logger.trace(`Saving verb metadata for ${id} to key: ${key}`);
|
|
11015
11146
|
// Save the verb metadata to S3-compatible storage
|
|
11016
11147
|
const result = await this.s3Client.send(new PutObjectCommand({
|
|
11017
11148
|
Bucket: this.bucketName,
|
|
@@ -11019,10 +11150,10 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
11019
11150
|
Body: body,
|
|
11020
11151
|
ContentType: 'application/json'
|
|
11021
11152
|
}));
|
|
11022
|
-
|
|
11153
|
+
this.logger.debug(`Verb metadata for ${id} saved successfully`);
|
|
11023
11154
|
}
|
|
11024
11155
|
catch (error) {
|
|
11025
|
-
|
|
11156
|
+
this.logger.error(`Failed to save verb metadata for ${id}:`, error);
|
|
11026
11157
|
throw new Error(`Failed to save verb metadata for ${id}: ${error}`);
|
|
11027
11158
|
}
|
|
11028
11159
|
}
|
|
@@ -11034,9 +11165,8 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
11034
11165
|
try {
|
|
11035
11166
|
// Import the GetObjectCommand only when needed
|
|
11036
11167
|
const { GetObjectCommand } = await import('@aws-sdk/client-s3');
|
|
11037
|
-
console.log(`Getting verb metadata for ${id} from bucket ${this.bucketName}`);
|
|
11038
11168
|
const key = `verb-metadata/${id}.json`;
|
|
11039
|
-
|
|
11169
|
+
this.logger.trace(`Getting verb metadata for ${id} from key: ${key}`);
|
|
11040
11170
|
// Try to get the verb metadata
|
|
11041
11171
|
const response = await this.s3Client.send(new GetObjectCommand({
|
|
11042
11172
|
Bucket: this.bucketName,
|
|
@@ -11044,20 +11174,20 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
11044
11174
|
}));
|
|
11045
11175
|
// Check if response is null or undefined
|
|
11046
11176
|
if (!response || !response.Body) {
|
|
11047
|
-
|
|
11177
|
+
this.logger.trace(`No verb metadata found for ${id}`);
|
|
11048
11178
|
return null;
|
|
11049
11179
|
}
|
|
11050
11180
|
// Convert the response body to a string
|
|
11051
11181
|
const bodyContents = await response.Body.transformToString();
|
|
11052
|
-
|
|
11182
|
+
this.logger.trace(`Retrieved verb metadata body for ${id}`);
|
|
11053
11183
|
// Parse the JSON string
|
|
11054
11184
|
try {
|
|
11055
11185
|
const parsedMetadata = JSON.parse(bodyContents);
|
|
11056
|
-
|
|
11186
|
+
this.logger.trace(`Successfully retrieved verb metadata for ${id}`);
|
|
11057
11187
|
return parsedMetadata;
|
|
11058
11188
|
}
|
|
11059
11189
|
catch (parseError) {
|
|
11060
|
-
|
|
11190
|
+
this.logger.error(`Failed to parse verb metadata for ${id}:`, parseError);
|
|
11061
11191
|
return null;
|
|
11062
11192
|
}
|
|
11063
11193
|
}
|
|
@@ -11068,7 +11198,7 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
11068
11198
|
(error.message.includes('NoSuchKey') ||
|
|
11069
11199
|
error.message.includes('not found') ||
|
|
11070
11200
|
error.message.includes('does not exist')))) {
|
|
11071
|
-
|
|
11201
|
+
this.logger.trace(`Verb metadata not found for ${id}`);
|
|
11072
11202
|
return null;
|
|
11073
11203
|
}
|
|
11074
11204
|
// For other types of errors, convert to BrainyError for better classification
|
|
@@ -11081,13 +11211,11 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
11081
11211
|
async saveNounMetadata(id, metadata) {
|
|
11082
11212
|
await this.ensureInitialized();
|
|
11083
11213
|
try {
|
|
11084
|
-
console.log(`Saving noun metadata for ${id} to bucket ${this.bucketName}`);
|
|
11085
11214
|
// Import the PutObjectCommand only when needed
|
|
11086
11215
|
const { PutObjectCommand } = await import('@aws-sdk/client-s3');
|
|
11087
11216
|
const key = `noun-metadata/${id}.json`;
|
|
11088
11217
|
const body = JSON.stringify(metadata, null, 2);
|
|
11089
|
-
|
|
11090
|
-
console.log(`Noun Metadata: ${body}`);
|
|
11218
|
+
this.logger.trace(`Saving noun metadata for ${id} to key: ${key}`);
|
|
11091
11219
|
// Save the noun metadata to S3-compatible storage
|
|
11092
11220
|
const result = await this.s3Client.send(new PutObjectCommand({
|
|
11093
11221
|
Bucket: this.bucketName,
|
|
@@ -11095,10 +11223,10 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
11095
11223
|
Body: body,
|
|
11096
11224
|
ContentType: 'application/json'
|
|
11097
11225
|
}));
|
|
11098
|
-
|
|
11226
|
+
this.logger.debug(`Noun metadata for ${id} saved successfully`);
|
|
11099
11227
|
}
|
|
11100
11228
|
catch (error) {
|
|
11101
|
-
|
|
11229
|
+
this.logger.error(`Failed to save noun metadata for ${id}:`, error);
|
|
11102
11230
|
throw new Error(`Failed to save noun metadata for ${id}: ${error}`);
|
|
11103
11231
|
}
|
|
11104
11232
|
}
|
|
@@ -11110,9 +11238,8 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
11110
11238
|
try {
|
|
11111
11239
|
// Import the GetObjectCommand only when needed
|
|
11112
11240
|
const { GetObjectCommand } = await import('@aws-sdk/client-s3');
|
|
11113
|
-
console.log(`Getting noun metadata for ${id} from bucket ${this.bucketName}`);
|
|
11114
11241
|
const key = `noun-metadata/${id}.json`;
|
|
11115
|
-
|
|
11242
|
+
this.logger.trace(`Getting noun metadata for ${id} from key: ${key}`);
|
|
11116
11243
|
// Try to get the noun metadata
|
|
11117
11244
|
const response = await this.s3Client.send(new GetObjectCommand({
|
|
11118
11245
|
Bucket: this.bucketName,
|
|
@@ -11120,20 +11247,20 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
11120
11247
|
}));
|
|
11121
11248
|
// Check if response is null or undefined
|
|
11122
11249
|
if (!response || !response.Body) {
|
|
11123
|
-
|
|
11250
|
+
this.logger.trace(`No noun metadata found for ${id}`);
|
|
11124
11251
|
return null;
|
|
11125
11252
|
}
|
|
11126
11253
|
// Convert the response body to a string
|
|
11127
11254
|
const bodyContents = await response.Body.transformToString();
|
|
11128
|
-
|
|
11255
|
+
this.logger.trace(`Retrieved noun metadata body for ${id}`);
|
|
11129
11256
|
// Parse the JSON string
|
|
11130
11257
|
try {
|
|
11131
11258
|
const parsedMetadata = JSON.parse(bodyContents);
|
|
11132
|
-
|
|
11259
|
+
this.logger.trace(`Successfully retrieved noun metadata for ${id}`);
|
|
11133
11260
|
return parsedMetadata;
|
|
11134
11261
|
}
|
|
11135
11262
|
catch (parseError) {
|
|
11136
|
-
|
|
11263
|
+
this.logger.error(`Failed to parse noun metadata for ${id}:`, parseError);
|
|
11137
11264
|
return null;
|
|
11138
11265
|
}
|
|
11139
11266
|
}
|
|
@@ -11144,7 +11271,7 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
11144
11271
|
(error.message.includes('NoSuchKey') ||
|
|
11145
11272
|
error.message.includes('not found') ||
|
|
11146
11273
|
error.message.includes('does not exist')))) {
|
|
11147
|
-
|
|
11274
|
+
this.logger.trace(`Noun metadata not found for ${id}`);
|
|
11148
11275
|
return null;
|
|
11149
11276
|
}
|
|
11150
11277
|
// For other types of errors, convert to BrainyError for better classification
|
|
@@ -11361,7 +11488,7 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
11361
11488
|
}
|
|
11362
11489
|
}
|
|
11363
11490
|
catch (error) {
|
|
11364
|
-
|
|
11491
|
+
this.logger.warn(`Error getting metadata from ${object.Key}:`, error);
|
|
11365
11492
|
}
|
|
11366
11493
|
}
|
|
11367
11494
|
}
|
|
@@ -11382,7 +11509,7 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
11382
11509
|
};
|
|
11383
11510
|
}
|
|
11384
11511
|
catch (error) {
|
|
11385
|
-
|
|
11512
|
+
this.logger.error('Failed to get storage status:', error);
|
|
11386
11513
|
return {
|
|
11387
11514
|
type: this.serviceType,
|
|
11388
11515
|
used: 0,
|
|
@@ -11422,6 +11549,11 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
11422
11549
|
scheduleBatchUpdate() {
|
|
11423
11550
|
// Mark statistics as modified
|
|
11424
11551
|
this.statisticsModified = true;
|
|
11552
|
+
// If we're in read-only mode, don't update statistics
|
|
11553
|
+
if (this.readOnly) {
|
|
11554
|
+
this.logger.trace('Skipping statistics update in read-only mode');
|
|
11555
|
+
return;
|
|
11556
|
+
}
|
|
11425
11557
|
// If a timer is already set, don't set another one
|
|
11426
11558
|
if (this.statisticsBatchUpdateTimerId !== null) {
|
|
11427
11559
|
return;
|
|
@@ -11458,7 +11590,7 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
11458
11590
|
if (!lockAcquired) {
|
|
11459
11591
|
// Another instance is updating statistics, skip this flush
|
|
11460
11592
|
// but keep the modified flag so we'll try again later
|
|
11461
|
-
|
|
11593
|
+
this.logger.debug('Statistics flush skipped - another instance is updating');
|
|
11462
11594
|
return;
|
|
11463
11595
|
}
|
|
11464
11596
|
try {
|
|
@@ -11477,7 +11609,7 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
11477
11609
|
}
|
|
11478
11610
|
catch (error) {
|
|
11479
11611
|
// If we can't read current stats, proceed with local cache
|
|
11480
|
-
|
|
11612
|
+
this.logger.warn('Could not read current statistics from storage, using local cache:', error);
|
|
11481
11613
|
}
|
|
11482
11614
|
// Merge local statistics with storage statistics
|
|
11483
11615
|
let mergedStats = this.statisticsCache;
|
|
@@ -11515,7 +11647,7 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
11515
11647
|
}
|
|
11516
11648
|
}
|
|
11517
11649
|
catch (error) {
|
|
11518
|
-
|
|
11650
|
+
this.logger.error('Failed to flush statistics data:', error);
|
|
11519
11651
|
// Mark as still modified so we'll try again later
|
|
11520
11652
|
this.statisticsModified = true;
|
|
11521
11653
|
// Don't throw the error to avoid disrupting the application
|
|
@@ -11580,7 +11712,7 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
11580
11712
|
this.scheduleBatchUpdate();
|
|
11581
11713
|
}
|
|
11582
11714
|
catch (error) {
|
|
11583
|
-
|
|
11715
|
+
this.logger.error('Failed to save statistics data:', error);
|
|
11584
11716
|
throw new Error(`Failed to save statistics data: ${error}`);
|
|
11585
11717
|
}
|
|
11586
11718
|
}
|
|
@@ -11590,8 +11722,11 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
11590
11722
|
*/
|
|
11591
11723
|
async getStatisticsData() {
|
|
11592
11724
|
await this.ensureInitialized();
|
|
11593
|
-
//
|
|
11594
|
-
if
|
|
11725
|
+
// Always fetch fresh statistics from storage to avoid inconsistencies
|
|
11726
|
+
// Only use cache if explicitly in read-only mode
|
|
11727
|
+
const shouldUseCache = this.readOnly && this.statisticsCache &&
|
|
11728
|
+
(Date.now() - this.lastStatisticsFlushTime < this.MIN_FLUSH_INTERVAL_MS);
|
|
11729
|
+
if (shouldUseCache && this.statisticsCache) {
|
|
11595
11730
|
return {
|
|
11596
11731
|
nounCount: { ...this.statisticsCache.nounCount },
|
|
11597
11732
|
verbCount: { ...this.statisticsCache.verbCount },
|
|
@@ -11632,7 +11767,7 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
11632
11767
|
return statistics;
|
|
11633
11768
|
}
|
|
11634
11769
|
catch (error) {
|
|
11635
|
-
|
|
11770
|
+
this.logger.error('Error getting statistics data:', error);
|
|
11636
11771
|
throw error;
|
|
11637
11772
|
}
|
|
11638
11773
|
}
|
|
@@ -11702,7 +11837,7 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
11702
11837
|
}));
|
|
11703
11838
|
}
|
|
11704
11839
|
catch (error) {
|
|
11705
|
-
|
|
11840
|
+
this.logger.warn('Failed to append to change log:', error);
|
|
11706
11841
|
// Don't throw error to avoid disrupting main operations
|
|
11707
11842
|
}
|
|
11708
11843
|
}
|
|
@@ -11747,7 +11882,7 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
11747
11882
|
}
|
|
11748
11883
|
}
|
|
11749
11884
|
catch (error) {
|
|
11750
|
-
|
|
11885
|
+
this.logger.warn(`Failed to read change log entry ${object.Key}:`, error);
|
|
11751
11886
|
// Continue processing other entries
|
|
11752
11887
|
}
|
|
11753
11888
|
}
|
|
@@ -11756,7 +11891,7 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
11756
11891
|
return changes.slice(0, maxEntries);
|
|
11757
11892
|
}
|
|
11758
11893
|
catch (error) {
|
|
11759
|
-
|
|
11894
|
+
this.logger.error('Failed to get changes from change log:', error);
|
|
11760
11895
|
return [];
|
|
11761
11896
|
}
|
|
11762
11897
|
}
|
|
@@ -11803,15 +11938,15 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
11803
11938
|
}));
|
|
11804
11939
|
}
|
|
11805
11940
|
catch (error) {
|
|
11806
|
-
|
|
11941
|
+
this.logger.warn(`Failed to delete old change log entry ${key}:`, error);
|
|
11807
11942
|
}
|
|
11808
11943
|
}
|
|
11809
11944
|
if (entriesToDelete.length > 0) {
|
|
11810
|
-
|
|
11945
|
+
this.logger.debug(`Cleaned up ${entriesToDelete.length} old change log entries`);
|
|
11811
11946
|
}
|
|
11812
11947
|
}
|
|
11813
11948
|
catch (error) {
|
|
11814
|
-
|
|
11949
|
+
this.logger.warn('Failed to cleanup old change logs:', error);
|
|
11815
11950
|
}
|
|
11816
11951
|
}
|
|
11817
11952
|
/**
|
|
@@ -11866,13 +12001,13 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
11866
12001
|
// Schedule automatic cleanup when lock expires
|
|
11867
12002
|
setTimeout(() => {
|
|
11868
12003
|
this.releaseLock(lockKey, lockValue).catch((error) => {
|
|
11869
|
-
|
|
12004
|
+
this.logger.warn(`Failed to auto-release expired lock ${lockKey}:`, error);
|
|
11870
12005
|
});
|
|
11871
12006
|
}, ttl);
|
|
11872
12007
|
return true;
|
|
11873
12008
|
}
|
|
11874
12009
|
catch (error) {
|
|
11875
|
-
|
|
12010
|
+
this.logger.warn(`Failed to acquire lock ${lockKey}:`, error);
|
|
11876
12011
|
return false;
|
|
11877
12012
|
}
|
|
11878
12013
|
}
|
|
@@ -11921,7 +12056,7 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
11921
12056
|
this.activeLocks.delete(lockKey);
|
|
11922
12057
|
}
|
|
11923
12058
|
catch (error) {
|
|
11924
|
-
|
|
12059
|
+
this.logger.warn(`Failed to release lock ${lockKey}:`, error);
|
|
11925
12060
|
}
|
|
11926
12061
|
}
|
|
11927
12062
|
/**
|
|
@@ -11972,17 +12107,85 @@ class S3CompatibleStorage extends BaseStorage {
|
|
|
11972
12107
|
}));
|
|
11973
12108
|
}
|
|
11974
12109
|
catch (error) {
|
|
11975
|
-
|
|
12110
|
+
this.logger.warn(`Failed to delete expired lock ${lockKey}:`, error);
|
|
11976
12111
|
}
|
|
11977
12112
|
}
|
|
11978
12113
|
if (expiredLocks.length > 0) {
|
|
11979
|
-
|
|
12114
|
+
this.logger.debug(`Cleaned up ${expiredLocks.length} expired locks`);
|
|
11980
12115
|
}
|
|
11981
12116
|
}
|
|
11982
12117
|
catch (error) {
|
|
11983
|
-
|
|
12118
|
+
this.logger.warn('Failed to cleanup expired locks:', error);
|
|
11984
12119
|
}
|
|
11985
12120
|
}
|
|
12121
|
+
/**
|
|
12122
|
+
* Get nouns with pagination support
|
|
12123
|
+
* @param options Pagination options
|
|
12124
|
+
* @returns Promise that resolves to a paginated result of nouns
|
|
12125
|
+
*/
|
|
12126
|
+
async getNounsWithPagination(options = {}) {
|
|
12127
|
+
await this.ensureInitialized();
|
|
12128
|
+
const limit = options.limit || 100;
|
|
12129
|
+
const cursor = options.cursor;
|
|
12130
|
+
// Get paginated nodes
|
|
12131
|
+
const result = await this.getNodesWithPagination({
|
|
12132
|
+
limit,
|
|
12133
|
+
cursor,
|
|
12134
|
+
useCache: true
|
|
12135
|
+
});
|
|
12136
|
+
// Apply filters if provided
|
|
12137
|
+
let filteredNodes = result.nodes;
|
|
12138
|
+
if (options.filter) {
|
|
12139
|
+
// Filter by noun type
|
|
12140
|
+
if (options.filter.nounType) {
|
|
12141
|
+
const nounTypes = Array.isArray(options.filter.nounType)
|
|
12142
|
+
? options.filter.nounType
|
|
12143
|
+
: [options.filter.nounType];
|
|
12144
|
+
const filteredByType = [];
|
|
12145
|
+
for (const node of filteredNodes) {
|
|
12146
|
+
const metadata = await this.getNounMetadata(node.id);
|
|
12147
|
+
if (metadata && nounTypes.includes(metadata.type || metadata.noun)) {
|
|
12148
|
+
filteredByType.push(node);
|
|
12149
|
+
}
|
|
12150
|
+
}
|
|
12151
|
+
filteredNodes = filteredByType;
|
|
12152
|
+
}
|
|
12153
|
+
// Filter by service
|
|
12154
|
+
if (options.filter.service) {
|
|
12155
|
+
const services = Array.isArray(options.filter.service)
|
|
12156
|
+
? options.filter.service
|
|
12157
|
+
: [options.filter.service];
|
|
12158
|
+
const filteredByService = [];
|
|
12159
|
+
for (const node of filteredNodes) {
|
|
12160
|
+
const metadata = await this.getNounMetadata(node.id);
|
|
12161
|
+
if (metadata && services.includes(metadata.service)) {
|
|
12162
|
+
filteredByService.push(node);
|
|
12163
|
+
}
|
|
12164
|
+
}
|
|
12165
|
+
filteredNodes = filteredByService;
|
|
12166
|
+
}
|
|
12167
|
+
// Filter by metadata
|
|
12168
|
+
if (options.filter.metadata) {
|
|
12169
|
+
const metadataFilter = options.filter.metadata;
|
|
12170
|
+
const filteredByMetadata = [];
|
|
12171
|
+
for (const node of filteredNodes) {
|
|
12172
|
+
const metadata = await this.getNounMetadata(node.id);
|
|
12173
|
+
if (metadata) {
|
|
12174
|
+
const matches = Object.entries(metadataFilter).every(([key, value]) => metadata[key] === value);
|
|
12175
|
+
if (matches) {
|
|
12176
|
+
filteredByMetadata.push(node);
|
|
12177
|
+
}
|
|
12178
|
+
}
|
|
12179
|
+
}
|
|
12180
|
+
filteredNodes = filteredByMetadata;
|
|
12181
|
+
}
|
|
12182
|
+
}
|
|
12183
|
+
return {
|
|
12184
|
+
items: filteredNodes,
|
|
12185
|
+
hasMore: result.hasMore,
|
|
12186
|
+
nextCursor: result.nextCursor
|
|
12187
|
+
};
|
|
12188
|
+
}
|
|
11986
12189
|
}
|
|
11987
12190
|
|
|
11988
12191
|
/**
|
|
@@ -128049,5 +128252,5 @@ var _osShim$1 = /*#__PURE__*/Object.freeze({
|
|
|
128049
128252
|
totalmem: totalmem
|
|
128050
128253
|
});
|
|
128051
128254
|
|
|
128052
|
-
export { AugmentationType, BrainyData, BrainyMCPAdapter, BrainyMCPService, ExecutionMode, FileSystemStorage, FileSystemStorageAugmentation, HNSWIndex, HNSWIndexOptimized, MCPAugmentationToolset, MCPRequestType, MCP_VERSION, MemoryStorage, MemoryStorageAugmentation, NounType, OPFSStorage, OPFSStorageAugmentation, Pipeline, S3CompatibleStorage as R2Storage, S3CompatibleStorage, SequentialPipeline, ServerSearchActivationAugmentation, ServerSearchConduitAugmentation, StreamlinedExecutionMode, UniversalSentenceEncoder$1 as UniversalSentenceEncoder, VerbType, WebRTCConduitAugmentation, WebSocketConduitAugmentation, addWebSocketSupport, applyTensorFlowPatch, areWebWorkersAvailable, areWorkerThreadsAvailable, areWorkerThreadsAvailableSync, augmentationPipeline, availableAugmentations, cleanupWorkerPools, cosineDistance$1 as cosineDistance, createAugmentationRegistryPlugin, createAugmentationRegistryRollupPlugin, createConduitAugmentation, createEmbeddingFunction, createMemoryAugmentation, createPipeline, createSenseAugmentation, createServerSearchAugmentations, createStorage, createStreamingPipeline, createTensorFlowEmbeddingFunction, createThreadedEmbeddingFunction, defaultEmbeddingFunction, dotProductDistance, environment, euclideanDistance, executeAugmentation, executeByType, executeInThread, executeSingle, executeStreamlined, getAugmentationsByType, getNounTypeMap, getNounTypes, getStatistics, getVerbTypeMap, getVerbTypes, initializeAugmentationPipeline, isBrowser$1 as isBrowser, isNode, isThreadingAvailable, isThreadingAvailableAsync, isWebWorker, loadAugmentationModule, loadAugmentationsFromModules, manhattanDistance, pipeline, processStaticData, processStreamingData, registerAugmentation, sequentialPipeline, setAugmentationEnabled };
|
|
128255
|
+
export { AugmentationType, BrainyData, BrainyMCPAdapter, BrainyMCPService, ExecutionMode, FileSystemStorage, FileSystemStorageAugmentation, HNSWIndex, HNSWIndexOptimized, LogLevel, MCPAugmentationToolset, MCPRequestType, MCP_VERSION, MemoryStorage, MemoryStorageAugmentation, NounType, OPFSStorage, OPFSStorageAugmentation, Pipeline, S3CompatibleStorage as R2Storage, S3CompatibleStorage, SequentialPipeline, ServerSearchActivationAugmentation, ServerSearchConduitAugmentation, StreamlinedExecutionMode, UniversalSentenceEncoder$1 as UniversalSentenceEncoder, VerbType, WebRTCConduitAugmentation, WebSocketConduitAugmentation, addWebSocketSupport, applyTensorFlowPatch, areWebWorkersAvailable, areWorkerThreadsAvailable, areWorkerThreadsAvailableSync, augmentationPipeline, availableAugmentations, cleanupWorkerPools, configureLogger, cosineDistance$1 as cosineDistance, createAugmentationRegistryPlugin, createAugmentationRegistryRollupPlugin, createConduitAugmentation, createEmbeddingFunction, createMemoryAugmentation, createModuleLogger, createPipeline, createSenseAugmentation, createServerSearchAugmentations, createStorage, createStreamingPipeline, createTensorFlowEmbeddingFunction, createThreadedEmbeddingFunction, defaultEmbeddingFunction, dotProductDistance, environment, euclideanDistance, executeAugmentation, executeByType, executeInThread, executeSingle, executeStreamlined, getAugmentationsByType, getNounTypeMap, getNounTypes, getStatistics, getVerbTypeMap, getVerbTypes, initializeAugmentationPipeline, isBrowser$1 as isBrowser, isNode, isThreadingAvailable, isThreadingAvailableAsync, isWebWorker, loadAugmentationModule, loadAugmentationsFromModules, logger, manhattanDistance, pipeline, processStaticData, processStreamingData, registerAugmentation, sequentialPipeline, setAugmentationEnabled };
|
|
128053
128256
|
//# sourceMappingURL=unified.js.map
|