@soulcraft/brainy 4.8.3 → 4.8.5

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/brainy.js CHANGED
@@ -464,6 +464,13 @@ export class Brainy {
464
464
  async convertNounToEntity(noun) {
465
465
  // v4.8.0: Storage adapters ALREADY extract standard fields to top-level!
466
466
  // Just read from top-level fields of HNSWNounWithMetadata
467
+ console.log(`[DEBUG convertNounToEntity] Converting noun ${noun.id}:`, {
468
+ nounMetadataKeys: noun.metadata ? Object.keys(noun.metadata) : [],
469
+ nounType: noun.type,
470
+ hasName: !!noun.metadata?.name,
471
+ hasPath: !!noun.metadata?.path,
472
+ hasVfsType: !!noun.metadata?.vfsType
473
+ });
467
474
  // v4.8.0: Clean structure with standard fields at top-level
468
475
  const entity = {
469
476
  id: noun.id,
@@ -480,6 +487,12 @@ export class Brainy {
480
487
  // ONLY custom user fields in metadata (v4.8.0: already separated by storage adapter)
481
488
  metadata: noun.metadata
482
489
  };
490
+ console.log(`[DEBUG convertNounToEntity] Converted entity metadata:`, {
491
+ entityMetadataKeys: entity.metadata ? Object.keys(entity.metadata) : [],
492
+ metadata_name: entity.metadata?.name,
493
+ metadata_path: entity.metadata?.path,
494
+ metadata_vfsType: entity.metadata?.vfsType
495
+ });
483
496
  return entity;
484
497
  }
485
498
  /**
@@ -1057,41 +1057,33 @@ export class FileSystemStorage extends BaseStorage {
1057
1057
  * Get verbs by source
1058
1058
  */
1059
1059
  async getVerbsBySource_internal(sourceId) {
1060
- console.log(`[DEBUG] getVerbsBySource_internal called for sourceId: ${sourceId}`);
1061
- console.log(`[DEBUG] verbsDir: ${this.verbsDir}`);
1062
1060
  // Use the working pagination method with source filter
1063
1061
  const result = await this.getVerbsWithPagination({
1064
1062
  limit: 10000,
1065
1063
  filter: { sourceId: [sourceId] }
1066
1064
  });
1067
- console.log(`[DEBUG] Found ${result.items.length} verbs for source ${sourceId}`);
1068
- console.log(`[DEBUG] Total verb files found: ${result.totalCount}`);
1069
1065
  return result.items;
1070
1066
  }
1071
1067
  /**
1072
1068
  * Get verbs by target
1073
1069
  */
1074
1070
  async getVerbsByTarget_internal(targetId) {
1075
- console.log(`[DEBUG] getVerbsByTarget_internal called for targetId: ${targetId}`);
1076
1071
  // Use the working pagination method with target filter
1077
1072
  const result = await this.getVerbsWithPagination({
1078
1073
  limit: 10000,
1079
1074
  filter: { targetId: [targetId] }
1080
1075
  });
1081
- console.log(`[DEBUG] Found ${result.items.length} verbs for target ${targetId}`);
1082
1076
  return result.items;
1083
1077
  }
1084
1078
  /**
1085
1079
  * Get verbs by type
1086
1080
  */
1087
1081
  async getVerbsByType_internal(type) {
1088
- console.log(`[DEBUG] getVerbsByType_internal called for type: ${type}`);
1089
1082
  // Use the working pagination method with type filter
1090
1083
  const result = await this.getVerbsWithPagination({
1091
1084
  limit: 10000,
1092
1085
  filter: { verbType: [type] }
1093
1086
  });
1094
- console.log(`[DEBUG] Found ${result.items.length} verbs for type ${type}`);
1095
1087
  return result.items;
1096
1088
  }
1097
1089
  /**
@@ -1105,12 +1097,10 @@ export class FileSystemStorage extends BaseStorage {
1105
1097
  try {
1106
1098
  // Get actual verb files first (critical for accuracy)
1107
1099
  const verbFiles = await this.getAllShardedFiles(this.verbsDir);
1108
- console.log(`[DEBUG] getAllShardedFiles returned ${verbFiles.length} files from ${this.verbsDir}`);
1109
1100
  verbFiles.sort(); // Consistent ordering for pagination
1110
1101
  // Use actual file count - don't trust cached totalVerbCount
1111
1102
  // This prevents accessing undefined array elements
1112
1103
  const actualFileCount = verbFiles.length;
1113
- console.log(`[DEBUG] actualFileCount: ${actualFileCount}, startIndex: ${startIndex}, limit: ${limit}`);
1114
1104
  // For large datasets, warn about performance
1115
1105
  if (actualFileCount > 1000000) {
1116
1106
  console.warn(`Very large verb dataset detected (${actualFileCount} verbs). Performance may be degraded. Consider database storage for optimal performance.`);
@@ -1182,12 +1172,8 @@ export class FileSystemStorage extends BaseStorage {
1182
1172
  // Check sourceId filter
1183
1173
  if (filter.sourceId) {
1184
1174
  const sources = Array.isArray(filter.sourceId) ? filter.sourceId : [filter.sourceId];
1185
- console.log(`[DEBUG] Checking verb ${verbWithMetadata.id}: sourceId=${verbWithMetadata.sourceId}, filter=${JSON.stringify(sources)}`);
1186
- if (!sources.includes(verbWithMetadata.sourceId)) {
1187
- console.log(`[DEBUG] Verb ${verbWithMetadata.id} filtered out (sourceId mismatch)`);
1175
+ if (!sources.includes(verbWithMetadata.sourceId))
1188
1176
  continue;
1189
- }
1190
- console.log(`[DEBUG] Verb ${verbWithMetadata.id} MATCHES source filter!`);
1191
1177
  }
1192
1178
  // Check targetId filter
1193
1179
  if (filter.targetId) {
@@ -1969,67 +1955,34 @@ export class FileSystemStorage extends BaseStorage {
1969
1955
  * Traverses all shard subdirectories (00-ff)
1970
1956
  */
1971
1957
  async getAllShardedFiles(baseDir) {
1972
- console.log(`[DEBUG] getAllShardedFiles called with baseDir: ${baseDir}`);
1973
- console.log(`[DEBUG] Current working directory: ${process.cwd()}`);
1974
- console.log(`[DEBUG] Resolved absolute path: ${path.resolve(baseDir)}`);
1975
1958
  const allFiles = [];
1976
1959
  try {
1977
- // Check if directory exists
1978
- try {
1979
- const baseStat = await fs.promises.stat(baseDir);
1980
- console.log(`[DEBUG] baseDir exists: ${baseStat.isDirectory() ? 'is directory' : 'is NOT directory'}`);
1981
- }
1982
- catch (statError) {
1983
- console.log(`[DEBUG] baseDir stat failed: ${statError.message}`);
1984
- if (statError.code === 'ENOENT') {
1985
- console.log(`[DEBUG] baseDir does not exist, returning empty array`);
1986
- return [];
1987
- }
1988
- throw statError;
1989
- }
1990
1960
  const shardDirs = await fs.promises.readdir(baseDir);
1991
- console.log(`[DEBUG] Found ${shardDirs.length} entries in baseDir: ${JSON.stringify(shardDirs.slice(0, 10))}${shardDirs.length > 10 ? '...' : ''}`);
1992
- let dirsProcessed = 0;
1993
- let filesFound = 0;
1994
1961
  for (const shardDir of shardDirs) {
1995
1962
  const shardPath = path.join(baseDir, shardDir);
1996
1963
  try {
1997
1964
  const stat = await fs.promises.stat(shardPath);
1998
1965
  if (stat.isDirectory()) {
1999
- dirsProcessed++;
2000
- console.log(`[DEBUG] Processing shard directory ${dirsProcessed}: ${shardDir}`);
2001
1966
  const shardFiles = await fs.promises.readdir(shardPath);
2002
- console.log(`[DEBUG] Found ${shardFiles.length} entries in ${shardDir}`);
2003
- let jsonCount = 0;
2004
1967
  for (const file of shardFiles) {
2005
1968
  if (file.endsWith('.json')) {
2006
1969
  allFiles.push(file);
2007
- jsonCount++;
2008
- filesFound++;
2009
1970
  }
2010
1971
  }
2011
- console.log(`[DEBUG] Added ${jsonCount} .json files from ${shardDir} (total so far: ${filesFound})`);
2012
- }
2013
- else {
2014
- console.log(`[DEBUG] Skipping non-directory entry: ${shardDir}`);
2015
1972
  }
2016
1973
  }
2017
1974
  catch (shardError) {
2018
1975
  // Skip inaccessible shard directories
2019
- console.log(`[DEBUG] Error accessing shard ${shardDir}: ${shardError.message}`);
2020
1976
  continue;
2021
1977
  }
2022
1978
  }
2023
- console.log(`[DEBUG] getAllShardedFiles complete: processed ${dirsProcessed} directories, found ${allFiles.length} total .json files`);
2024
1979
  // Sort for consistent ordering
2025
1980
  allFiles.sort();
2026
1981
  return allFiles;
2027
1982
  }
2028
1983
  catch (error) {
2029
- console.log(`[DEBUG] getAllShardedFiles error: ${error.message}, code: ${error.code}`);
2030
1984
  if (error.code === 'ENOENT') {
2031
1985
  // Directory doesn't exist yet
2032
- console.log(`[DEBUG] Directory does not exist, returning empty array`);
2033
1986
  return [];
2034
1987
  }
2035
1988
  throw error;
@@ -162,16 +162,29 @@ export class PathResolver {
162
162
  from: dirId,
163
163
  type: VerbType.Contains
164
164
  });
165
+ console.log(`[DEBUG PathResolver] getChildren(${dirId}): Found ${relations.length} Contains relations`);
165
166
  const validChildren = [];
166
167
  const childNames = new Set();
167
168
  // Fetch all child entities via relationships
168
169
  for (const relation of relations) {
169
170
  const entity = await this.brain.get(relation.to);
171
+ console.log(`[DEBUG PathResolver] Retrieved entity ${relation.to}:`, {
172
+ exists: !!entity,
173
+ type: entity?.type,
174
+ hasMetadata: !!entity?.metadata,
175
+ metadataKeys: entity?.metadata ? Object.keys(entity.metadata) : [],
176
+ metadata_vfsType: entity?.metadata?.vfsType,
177
+ metadata_name: entity?.metadata?.name
178
+ });
170
179
  if (entity && entity.metadata?.vfsType && entity.metadata?.name) {
171
180
  validChildren.push(entity);
172
181
  childNames.add(entity.metadata.name);
173
182
  }
183
+ else {
184
+ console.log(`[DEBUG PathResolver] ❌ FILTERED OUT entity ${relation.to} - missing vfsType or name`);
185
+ }
174
186
  }
187
+ console.log(`[DEBUG PathResolver] Returning ${validChildren.length} valid children (filtered from ${relations.length})`);
175
188
  // Update cache
176
189
  this.parentCache.set(dirId, childNames);
177
190
  return validChildren;
@@ -683,6 +683,19 @@ export class VirtualFileSystem {
683
683
  }
684
684
  // Get children
685
685
  let children = await this.pathResolver.getChildren(entityId);
686
+ console.log(`[DEBUG VFS] readdir(${path}): Found ${children.length} children`);
687
+ // Debug first child
688
+ if (children.length > 0) {
689
+ const firstChild = children[0];
690
+ console.log(`[DEBUG VFS] First child structure:`, {
691
+ id: firstChild.id,
692
+ type: firstChild.type,
693
+ metadataKeys: Object.keys(firstChild.metadata || {}),
694
+ metadata_name: firstChild.metadata?.name,
695
+ metadata_path: firstChild.metadata?.path,
696
+ metadata_vfsType: firstChild.metadata?.vfsType
697
+ });
698
+ }
686
699
  // Apply filters
687
700
  if (options?.filter) {
688
701
  children = this.filterDirectoryEntries(children, options.filter);
@@ -702,12 +715,17 @@ export class VirtualFileSystem {
702
715
  await this.updateAccessTime(entityId);
703
716
  // Return appropriate format
704
717
  if (options?.withFileTypes) {
705
- return children.map(child => ({
718
+ const result = children.map(child => ({
706
719
  name: child.metadata.name,
707
720
  path: child.metadata.path,
708
721
  type: child.metadata.vfsType,
709
722
  entityId: child.id
710
723
  }));
724
+ console.log(`[DEBUG VFS] Returning ${result.length} VFSDirent items`);
725
+ if (result.length > 0) {
726
+ console.log(`[DEBUG VFS] First VFSDirent:`, result[0]);
727
+ }
728
+ return result;
711
729
  }
712
730
  return children.map(child => child.metadata.name);
713
731
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soulcraft/brainy",
3
- "version": "4.8.3",
3
+ "version": "4.8.5",
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",