@soulcraft/brainy 2.15.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +249 -152
  3. package/dist/api/ConfigAPI.d.ts +67 -0
  4. package/dist/api/ConfigAPI.js +166 -0
  5. package/dist/api/DataAPI.d.ts +123 -0
  6. package/dist/api/DataAPI.js +391 -0
  7. package/dist/api/SecurityAPI.d.ts +50 -0
  8. package/dist/api/SecurityAPI.js +139 -0
  9. package/dist/api/UniversalImportAPI.d.ts +134 -0
  10. package/dist/api/UniversalImportAPI.js +615 -0
  11. package/dist/augmentationManager.js +12 -7
  12. package/dist/augmentationPipeline.d.ts +0 -61
  13. package/dist/augmentationPipeline.js +0 -87
  14. package/dist/augmentationRegistry.d.ts +1 -1
  15. package/dist/augmentationRegistry.js +1 -1
  16. package/dist/augmentations/apiServerAugmentation.d.ts +27 -1
  17. package/dist/augmentations/apiServerAugmentation.js +288 -7
  18. package/dist/augmentations/auditLogAugmentation.d.ts +109 -0
  19. package/dist/augmentations/auditLogAugmentation.js +358 -0
  20. package/dist/augmentations/batchProcessingAugmentation.d.ts +3 -2
  21. package/dist/augmentations/batchProcessingAugmentation.js +123 -22
  22. package/dist/augmentations/brainyAugmentation.d.ts +87 -8
  23. package/dist/augmentations/brainyAugmentation.js +159 -2
  24. package/dist/augmentations/cacheAugmentation.d.ts +6 -5
  25. package/dist/augmentations/cacheAugmentation.js +113 -17
  26. package/dist/augmentations/conduitAugmentations.d.ts +2 -2
  27. package/dist/augmentations/conduitAugmentations.js +2 -2
  28. package/dist/augmentations/configResolver.d.ts +122 -0
  29. package/dist/augmentations/configResolver.js +440 -0
  30. package/dist/augmentations/connectionPoolAugmentation.d.ts +3 -1
  31. package/dist/augmentations/connectionPoolAugmentation.js +37 -12
  32. package/dist/augmentations/defaultAugmentations.d.ts +9 -11
  33. package/dist/augmentations/defaultAugmentations.js +4 -11
  34. package/dist/augmentations/discovery/catalogDiscovery.d.ts +142 -0
  35. package/dist/augmentations/discovery/catalogDiscovery.js +249 -0
  36. package/dist/augmentations/discovery/localDiscovery.d.ts +84 -0
  37. package/dist/augmentations/discovery/localDiscovery.js +246 -0
  38. package/dist/augmentations/discovery/runtimeLoader.d.ts +97 -0
  39. package/dist/augmentations/discovery/runtimeLoader.js +337 -0
  40. package/dist/augmentations/discovery.d.ts +152 -0
  41. package/dist/augmentations/discovery.js +441 -0
  42. package/dist/augmentations/display/intelligentComputation.d.ts +1 -1
  43. package/dist/augmentations/display/intelligentComputation.js +4 -4
  44. package/dist/augmentations/entityRegistryAugmentation.d.ts +3 -1
  45. package/dist/augmentations/entityRegistryAugmentation.js +5 -1
  46. package/dist/augmentations/indexAugmentation.d.ts +3 -3
  47. package/dist/augmentations/indexAugmentation.js +2 -2
  48. package/dist/augmentations/intelligentVerbScoringAugmentation.d.ts +22 -6
  49. package/dist/augmentations/intelligentVerbScoringAugmentation.js +106 -23
  50. package/dist/augmentations/manifest.d.ts +176 -0
  51. package/dist/augmentations/manifest.js +8 -0
  52. package/dist/augmentations/marketplace/AugmentationMarketplace.d.ts +168 -0
  53. package/dist/augmentations/marketplace/AugmentationMarketplace.js +329 -0
  54. package/dist/augmentations/marketplace/cli.d.ts +47 -0
  55. package/dist/augmentations/marketplace/cli.js +265 -0
  56. package/dist/augmentations/metricsAugmentation.d.ts +3 -3
  57. package/dist/augmentations/metricsAugmentation.js +2 -2
  58. package/dist/augmentations/monitoringAugmentation.d.ts +3 -3
  59. package/dist/augmentations/monitoringAugmentation.js +2 -2
  60. package/dist/augmentations/neuralImport.d.ts +1 -1
  61. package/dist/augmentations/rateLimitAugmentation.d.ts +82 -0
  62. package/dist/augmentations/rateLimitAugmentation.js +321 -0
  63. package/dist/augmentations/requestDeduplicatorAugmentation.d.ts +2 -2
  64. package/dist/augmentations/requestDeduplicatorAugmentation.js +1 -1
  65. package/dist/augmentations/storageAugmentation.d.ts +1 -1
  66. package/dist/augmentations/storageAugmentation.js +2 -2
  67. package/dist/augmentations/storageAugmentations.d.ts +37 -8
  68. package/dist/augmentations/storageAugmentations.js +204 -15
  69. package/dist/augmentations/synapseAugmentation.d.ts +1 -1
  70. package/dist/augmentations/synapseAugmentation.js +35 -16
  71. package/dist/augmentations/typeMatching/intelligentTypeMatcher.d.ts +39 -59
  72. package/dist/augmentations/typeMatching/intelligentTypeMatcher.js +103 -389
  73. package/dist/augmentations/universalDisplayAugmentation.d.ts +2 -2
  74. package/dist/augmentations/universalDisplayAugmentation.js +2 -2
  75. package/dist/brainy-unified.d.ts +106 -0
  76. package/dist/brainy-unified.js +327 -0
  77. package/dist/brainy.d.ts +273 -0
  78. package/dist/brainy.js +1181 -0
  79. package/dist/brainyData.d.ts +29 -72
  80. package/dist/brainyData.js +350 -304
  81. package/dist/brainyDataV3.d.ts +186 -0
  82. package/dist/brainyDataV3.js +337 -0
  83. package/dist/browserFramework.d.ts +6 -6
  84. package/dist/browserFramework.js +11 -8
  85. package/dist/browserFramework.minimal.d.ts +5 -5
  86. package/dist/browserFramework.minimal.js +11 -8
  87. package/dist/config/index.d.ts +2 -2
  88. package/dist/config/index.js +3 -3
  89. package/dist/config/modelAutoConfig.d.ts +6 -7
  90. package/dist/config/modelAutoConfig.js +17 -76
  91. package/dist/cortex/backupRestore.d.ts +2 -2
  92. package/dist/cortex/backupRestore.js +85 -27
  93. package/dist/cortex/healthCheck.d.ts +2 -2
  94. package/dist/cortex/neuralImport.d.ts +2 -2
  95. package/dist/cortex/neuralImport.js +18 -13
  96. package/dist/cortex/performanceMonitor.d.ts +2 -2
  97. package/dist/critical/model-guardian.d.ts +4 -0
  98. package/dist/critical/model-guardian.js +31 -11
  99. package/dist/demo.d.ts +4 -4
  100. package/dist/demo.js +7 -7
  101. package/dist/distributed/cacheSync.d.ts +112 -0
  102. package/dist/distributed/cacheSync.js +265 -0
  103. package/dist/distributed/coordinator.d.ts +193 -0
  104. package/dist/distributed/coordinator.js +548 -0
  105. package/dist/distributed/httpTransport.d.ts +120 -0
  106. package/dist/distributed/httpTransport.js +446 -0
  107. package/dist/distributed/index.d.ts +8 -0
  108. package/dist/distributed/index.js +5 -0
  109. package/dist/distributed/networkTransport.d.ts +132 -0
  110. package/dist/distributed/networkTransport.js +633 -0
  111. package/dist/distributed/queryPlanner.d.ts +104 -0
  112. package/dist/distributed/queryPlanner.js +327 -0
  113. package/dist/distributed/readWriteSeparation.d.ts +134 -0
  114. package/dist/distributed/readWriteSeparation.js +350 -0
  115. package/dist/distributed/shardManager.d.ts +114 -0
  116. package/dist/distributed/shardManager.js +357 -0
  117. package/dist/distributed/shardMigration.d.ts +110 -0
  118. package/dist/distributed/shardMigration.js +289 -0
  119. package/dist/distributed/storageDiscovery.d.ts +160 -0
  120. package/dist/distributed/storageDiscovery.js +551 -0
  121. package/dist/embeddings/EmbeddingManager.d.ts +0 -4
  122. package/dist/embeddings/EmbeddingManager.js +21 -26
  123. package/dist/errors/brainyError.d.ts +5 -1
  124. package/dist/errors/brainyError.js +12 -0
  125. package/dist/examples/basicUsage.js +3 -3
  126. package/dist/graph/graphAdjacencyIndex.d.ts +96 -0
  127. package/dist/graph/graphAdjacencyIndex.js +288 -0
  128. package/dist/graph/pathfinding.js +4 -2
  129. package/dist/hnsw/scaledHNSWSystem.js +11 -2
  130. package/dist/importManager.js +6 -3
  131. package/dist/index.d.ts +12 -21
  132. package/dist/index.js +14 -22
  133. package/dist/mcp/brainyMCPAdapter.d.ts +4 -4
  134. package/dist/mcp/brainyMCPAdapter.js +5 -5
  135. package/dist/mcp/brainyMCPService.d.ts +3 -3
  136. package/dist/mcp/brainyMCPService.js +3 -11
  137. package/dist/mcp/mcpAugmentationToolset.js +20 -30
  138. package/dist/neural/embeddedPatterns.d.ts +1 -1
  139. package/dist/neural/embeddedPatterns.js +2 -2
  140. package/dist/neural/entityExtractor.d.ts +65 -0
  141. package/dist/neural/entityExtractor.js +316 -0
  142. package/dist/neural/improvedNeuralAPI.js +90 -79
  143. package/dist/neural/naturalLanguageProcessor.d.ts +155 -10
  144. package/dist/neural/naturalLanguageProcessor.js +941 -66
  145. package/dist/neural/naturalLanguageProcessorStatic.d.ts +2 -2
  146. package/dist/neural/naturalLanguageProcessorStatic.js +3 -3
  147. package/dist/neural/neuralAPI.js +8 -2
  148. package/dist/neural/patternLibrary.d.ts +57 -3
  149. package/dist/neural/patternLibrary.js +348 -13
  150. package/dist/neural/staticPatternMatcher.d.ts +2 -2
  151. package/dist/neural/staticPatternMatcher.js +2 -2
  152. package/dist/shared/default-augmentations.d.ts +3 -3
  153. package/dist/shared/default-augmentations.js +5 -5
  154. package/dist/storage/adapters/fileSystemStorage.d.ts +4 -0
  155. package/dist/storage/adapters/fileSystemStorage.js +54 -1
  156. package/dist/storage/adapters/memoryStorage.js +13 -8
  157. package/dist/storage/backwardCompatibility.d.ts +10 -78
  158. package/dist/storage/backwardCompatibility.js +17 -132
  159. package/dist/storage/baseStorage.d.ts +6 -0
  160. package/dist/storage/baseStorage.js +17 -0
  161. package/dist/storage/cacheManager.js +2 -2
  162. package/dist/storage/readOnlyOptimizations.js +8 -3
  163. package/dist/streaming/pipeline.d.ts +154 -0
  164. package/dist/streaming/pipeline.js +551 -0
  165. package/dist/triple/TripleIntelligence.d.ts +25 -110
  166. package/dist/triple/TripleIntelligence.js +4 -574
  167. package/dist/triple/TripleIntelligenceSystem.d.ts +159 -0
  168. package/dist/triple/TripleIntelligenceSystem.js +519 -0
  169. package/dist/types/apiTypes.d.ts +278 -0
  170. package/dist/types/apiTypes.js +33 -0
  171. package/dist/types/brainy.types.d.ts +308 -0
  172. package/dist/types/brainy.types.js +8 -0
  173. package/dist/types/brainyDataInterface.d.ts +3 -3
  174. package/dist/types/brainyDataInterface.js +2 -2
  175. package/dist/types/graphTypes.js +2 -2
  176. package/dist/utils/cacheAutoConfig.d.ts +3 -3
  177. package/dist/utils/embedding.js +8 -14
  178. package/dist/utils/enhancedLogger.d.ts +104 -0
  179. package/dist/utils/enhancedLogger.js +232 -0
  180. package/dist/utils/index.d.ts +1 -1
  181. package/dist/utils/index.js +1 -1
  182. package/dist/utils/intelligentTypeMapper.d.ts +60 -0
  183. package/dist/utils/intelligentTypeMapper.js +349 -0
  184. package/dist/utils/metadataIndex.d.ts +118 -1
  185. package/dist/utils/metadataIndex.js +539 -16
  186. package/dist/utils/paramValidation.d.ts +39 -0
  187. package/dist/utils/paramValidation.js +192 -0
  188. package/dist/utils/rateLimiter.d.ts +160 -0
  189. package/dist/utils/rateLimiter.js +271 -0
  190. package/dist/utils/statistics.d.ts +4 -4
  191. package/dist/utils/statistics.js +3 -3
  192. package/dist/utils/structuredLogger.d.ts +146 -0
  193. package/dist/utils/structuredLogger.js +394 -0
  194. package/dist/utils/textEncoding.js +2 -1
  195. package/dist/utils/typeValidation.d.ts +34 -0
  196. package/dist/utils/typeValidation.js +247 -0
  197. package/package.json +14 -6
  198. package/scripts/download-models.cjs +6 -15
  199. package/dist/augmentations/walAugmentation.d.ts +0 -111
  200. package/dist/augmentations/walAugmentation.js +0 -519
  201. package/dist/chat/BrainyChat.d.ts +0 -121
  202. package/dist/chat/BrainyChat.js +0 -396
  203. package/dist/chat/ChatCLI.d.ts +0 -61
  204. package/dist/chat/ChatCLI.js +0 -351
@@ -251,21 +251,17 @@ export class TransformerEmbedding {
251
251
  let actualType = embeddingManager.getPrecision();
252
252
  // CRITICAL: Control which model precision transformers.js uses
253
253
  // Q8 models use quantized int8 weights for 75% size reduction
254
- // FP32 models use full precision floating point
255
- if (actualType === 'q8') {
256
- this.logger('log', '🎯 Selecting Q8 quantized model (75% smaller, 99% accuracy)');
257
- }
258
- else {
259
- this.logger('log', '📦 Using FP32 model (full precision, larger size)');
260
- }
254
+ // Always use Q8 for optimal balance
255
+ actualType = 'q8'; // Always Q8
256
+ this.logger('log', '🎯 Using Q8 quantized model (75% smaller, 99% accuracy)');
261
257
  // Load the feature extraction pipeline with memory optimizations
262
258
  const pipelineOptions = {
263
259
  cache_dir: cacheDir,
264
260
  local_files_only: isBrowser() ? false : this.options.localFilesOnly,
265
261
  // CRITICAL: Specify dtype for model precision
266
- dtype: actualType === 'q8' ? 'q8' : 'fp32',
262
+ dtype: 'q8',
267
263
  // CRITICAL: For Q8, explicitly use quantized model
268
- quantized: actualType === 'q8',
264
+ quantized: true,
269
265
  // CRITICAL: ONNX memory optimizations
270
266
  session_options: {
271
267
  enableCpuMemArena: false, // Disable pre-allocated memory arena
@@ -292,8 +288,8 @@ export class TransformerEmbedding {
292
288
  this.logger('log', '✅ Q8 model found locally');
293
289
  }
294
290
  else {
295
- this.logger('warn', '⚠️ Q8 model not found, will fall back to FP32');
296
- actualType = 'fp32'; // Fall back to fp32
291
+ this.logger('warn', '⚠️ Q8 model not found');
292
+ actualType = 'q8'; // Always Q8
297
293
  }
298
294
  }
299
295
  this.extractor = await pipeline('feature-extraction', this.options.model, pipelineOptions);
@@ -462,9 +458,7 @@ export function createEmbeddingFunction(options = {}) {
462
458
  return async (data) => {
463
459
  const { embeddingManager } = await import('../embeddings/EmbeddingManager.js');
464
460
  // Validate precision if specified
465
- if (options.precision) {
466
- embeddingManager.validatePrecision(options.precision);
467
- }
461
+ // Precision is always Q8 now
468
462
  return await embeddingManager.embed(data);
469
463
  };
470
464
  }
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Enhanced logging system that bridges old logger with new structured logger
3
+ * Provides backward compatibility while enabling gradual migration
4
+ */
5
+ import { type LogContext } from './structuredLogger.js';
6
+ export declare enum LogLevel {
7
+ ERROR = 0,
8
+ WARN = 1,
9
+ INFO = 2,
10
+ DEBUG = 3,
11
+ TRACE = 4
12
+ }
13
+ export interface LoggerConfig {
14
+ level: LogLevel;
15
+ modules?: {
16
+ [moduleName: string]: LogLevel;
17
+ };
18
+ timestamps?: boolean;
19
+ includeModule?: boolean;
20
+ handler?: (level: LogLevel, module: string, message: string, ...args: any[]) => void;
21
+ }
22
+ /**
23
+ * Enhanced Logger that uses structured logger internally
24
+ * Maintains backward compatibility with existing code
25
+ */
26
+ declare class EnhancedLogger {
27
+ private static instance;
28
+ private config;
29
+ private constructor();
30
+ private applyEnvironmentDefaults;
31
+ private syncWithStructuredLogger;
32
+ static getInstance(): EnhancedLogger;
33
+ configure(config: Partial<LoggerConfig>): void;
34
+ private shouldLog;
35
+ error(module: string, message: string, ...args: any[]): void;
36
+ warn(module: string, message: string, ...args: any[]): void;
37
+ info(module: string, message: string, ...args: any[]): void;
38
+ debug(module: string, message: string, ...args: any[]): void;
39
+ trace(module: string, message: string, ...args: any[]): void;
40
+ createModuleLogger(module: string): {
41
+ error: (message: string, ...args: any[]) => void;
42
+ warn: (message: string, ...args: any[]) => void;
43
+ info: (message: string, ...args: any[]) => void;
44
+ debug: (message: string, ...args: any[]) => void;
45
+ trace: (message: string, ...args: any[]) => void;
46
+ withContext: (context: LogContext) => {
47
+ fatal: (message: string, contextOrData?: LogContext | any, data?: any) => void;
48
+ error: (message: string, contextOrData?: LogContext | any, data?: any) => void;
49
+ warn: (message: string, contextOrData?: LogContext | any, data?: any) => void;
50
+ info: (message: string, contextOrData?: LogContext | any, data?: any) => void;
51
+ debug: (message: string, contextOrData?: LogContext | any, data?: any) => void;
52
+ trace: (message: string, contextOrData?: LogContext | any, data?: any) => void;
53
+ withContext: (context: LogContext) => /*elided*/ any;
54
+ startTimer: (label: string) => void;
55
+ endTimer: (label: string) => number | undefined;
56
+ };
57
+ startTimer: (label: string) => void;
58
+ endTimer: (label: string) => number | undefined;
59
+ };
60
+ }
61
+ export declare const logger: EnhancedLogger;
62
+ export declare function createModuleLogger(module: string): {
63
+ error: (message: string, ...args: any[]) => void;
64
+ warn: (message: string, ...args: any[]) => void;
65
+ info: (message: string, ...args: any[]) => void;
66
+ debug: (message: string, ...args: any[]) => void;
67
+ trace: (message: string, ...args: any[]) => void;
68
+ withContext: (context: LogContext) => {
69
+ fatal: (message: string, contextOrData?: LogContext | any, data?: any) => void;
70
+ error: (message: string, contextOrData?: LogContext | any, data?: any) => void;
71
+ warn: (message: string, contextOrData?: LogContext | any, data?: any) => void;
72
+ info: (message: string, contextOrData?: LogContext | any, data?: any) => void;
73
+ debug: (message: string, contextOrData?: LogContext | any, data?: any) => void;
74
+ trace: (message: string, contextOrData?: LogContext | any, data?: any) => void;
75
+ withContext: (context: LogContext) => /*elided*/ any;
76
+ startTimer: (label: string) => void;
77
+ endTimer: (label: string) => number | undefined;
78
+ };
79
+ startTimer: (label: string) => void;
80
+ endTimer: (label: string) => number | undefined;
81
+ };
82
+ export declare function configureLogger(config: Partial<LoggerConfig>): void;
83
+ /**
84
+ * Smart console replacement that uses structured logger
85
+ */
86
+ export declare const smartConsole: {
87
+ log: (message?: any, ...args: any[]) => void;
88
+ info: (message?: any, ...args: any[]) => void;
89
+ warn: (message?: any, ...args: any[]) => void;
90
+ error: (message?: any, ...args: any[]) => void;
91
+ debug: (message?: any, ...args: any[]) => void;
92
+ trace: (message?: any, ...args: any[]) => void;
93
+ };
94
+ /**
95
+ * Production-optimized logging functions
96
+ */
97
+ export declare const prodLog: {
98
+ error: (message?: any, ...args: any[]) => void;
99
+ warn: (message?: any, ...args: any[]) => void;
100
+ info: (message?: any, ...args: any[]) => void;
101
+ debug: (message?: any, ...args: any[]) => void;
102
+ log: (message?: any, ...args: any[]) => void;
103
+ };
104
+ export { createModuleLogger as createStructuredModuleLogger, type LogContext, type ModuleLogger } from './structuredLogger.js';
@@ -0,0 +1,232 @@
1
+ /**
2
+ * Enhanced logging system that bridges old logger with new structured logger
3
+ * Provides backward compatibility while enabling gradual migration
4
+ */
5
+ import { structuredLogger, createModuleLogger as createStructuredModuleLogger, LogLevel as StructuredLogLevel } from './structuredLogger.js';
6
+ import { isProductionEnvironment, getLogLevel } from './environment.js';
7
+ // Re-export LogLevel for compatibility
8
+ export var LogLevel;
9
+ (function (LogLevel) {
10
+ LogLevel[LogLevel["ERROR"] = 0] = "ERROR";
11
+ LogLevel[LogLevel["WARN"] = 1] = "WARN";
12
+ LogLevel[LogLevel["INFO"] = 2] = "INFO";
13
+ LogLevel[LogLevel["DEBUG"] = 3] = "DEBUG";
14
+ LogLevel[LogLevel["TRACE"] = 4] = "TRACE";
15
+ })(LogLevel || (LogLevel = {}));
16
+ // Map old LogLevel to new StructuredLogLevel
17
+ function mapLogLevel(level) {
18
+ switch (level) {
19
+ case LogLevel.ERROR: return StructuredLogLevel.ERROR;
20
+ case LogLevel.WARN: return StructuredLogLevel.WARN;
21
+ case LogLevel.INFO: return StructuredLogLevel.INFO;
22
+ case LogLevel.DEBUG: return StructuredLogLevel.DEBUG;
23
+ case LogLevel.TRACE: return StructuredLogLevel.TRACE;
24
+ default: return StructuredLogLevel.INFO;
25
+ }
26
+ }
27
+ /**
28
+ * Enhanced Logger that uses structured logger internally
29
+ * Maintains backward compatibility with existing code
30
+ */
31
+ class EnhancedLogger {
32
+ constructor() {
33
+ this.config = {
34
+ level: LogLevel.ERROR,
35
+ timestamps: false,
36
+ includeModule: true
37
+ };
38
+ this.applyEnvironmentDefaults();
39
+ // Sync with structured logger
40
+ this.syncWithStructuredLogger();
41
+ // Set log level from environment variable if available
42
+ const envLogLevel = process.env.BRAINY_LOG_LEVEL;
43
+ if (envLogLevel) {
44
+ const level = LogLevel[envLogLevel.toUpperCase()];
45
+ if (level !== undefined) {
46
+ this.config.level = level;
47
+ this.syncWithStructuredLogger();
48
+ }
49
+ }
50
+ // Parse module-specific log levels
51
+ const moduleLogLevels = process.env.BRAINY_MODULE_LOG_LEVELS;
52
+ if (moduleLogLevels) {
53
+ try {
54
+ this.config.modules = JSON.parse(moduleLogLevels);
55
+ this.syncWithStructuredLogger();
56
+ }
57
+ catch (e) {
58
+ // Ignore parsing errors
59
+ }
60
+ }
61
+ }
62
+ applyEnvironmentDefaults() {
63
+ const envLogLevel = getLogLevel();
64
+ switch (envLogLevel) {
65
+ case 'silent':
66
+ this.config.level = -1;
67
+ break;
68
+ case 'error':
69
+ this.config.level = LogLevel.ERROR;
70
+ this.config.timestamps = false;
71
+ break;
72
+ case 'warn':
73
+ this.config.level = LogLevel.WARN;
74
+ this.config.timestamps = false;
75
+ break;
76
+ case 'info':
77
+ this.config.level = LogLevel.INFO;
78
+ this.config.timestamps = true;
79
+ break;
80
+ case 'verbose':
81
+ this.config.level = LogLevel.DEBUG;
82
+ this.config.timestamps = true;
83
+ break;
84
+ }
85
+ if (isProductionEnvironment()) {
86
+ this.config.level = Math.min(this.config.level, LogLevel.ERROR);
87
+ this.config.timestamps = false;
88
+ this.config.includeModule = false;
89
+ }
90
+ }
91
+ syncWithStructuredLogger() {
92
+ // Convert modules config
93
+ const modules = {};
94
+ if (this.config.modules) {
95
+ for (const [module, level] of Object.entries(this.config.modules)) {
96
+ modules[module] = mapLogLevel(level);
97
+ }
98
+ }
99
+ // Configure structured logger
100
+ structuredLogger.configure({
101
+ level: mapLogLevel(this.config.level),
102
+ modules,
103
+ format: this.config.timestamps ? 'pretty' : 'simple'
104
+ });
105
+ }
106
+ static getInstance() {
107
+ if (!EnhancedLogger.instance) {
108
+ EnhancedLogger.instance = new EnhancedLogger();
109
+ }
110
+ return EnhancedLogger.instance;
111
+ }
112
+ configure(config) {
113
+ this.config = { ...this.config, ...config };
114
+ this.syncWithStructuredLogger();
115
+ }
116
+ shouldLog(level, module) {
117
+ if (this.config.modules && this.config.modules[module] !== undefined) {
118
+ return level <= this.config.modules[module];
119
+ }
120
+ return level <= this.config.level;
121
+ }
122
+ error(module, message, ...args) {
123
+ const logger = createStructuredModuleLogger(module);
124
+ logger.error(message, { data: args });
125
+ }
126
+ warn(module, message, ...args) {
127
+ const logger = createStructuredModuleLogger(module);
128
+ logger.warn(message, { data: args });
129
+ }
130
+ info(module, message, ...args) {
131
+ const logger = createStructuredModuleLogger(module);
132
+ logger.info(message, { data: args });
133
+ }
134
+ debug(module, message, ...args) {
135
+ const logger = createStructuredModuleLogger(module);
136
+ logger.debug(message, { data: args });
137
+ }
138
+ trace(module, message, ...args) {
139
+ const logger = createStructuredModuleLogger(module);
140
+ logger.trace(message, { data: args });
141
+ }
142
+ createModuleLogger(module) {
143
+ const structuredLogger = createStructuredModuleLogger(module);
144
+ // Return a backward-compatible interface
145
+ return {
146
+ error: (message, ...args) => structuredLogger.error(message, { data: args }),
147
+ warn: (message, ...args) => structuredLogger.warn(message, { data: args }),
148
+ info: (message, ...args) => structuredLogger.info(message, { data: args }),
149
+ debug: (message, ...args) => structuredLogger.debug(message, { data: args }),
150
+ trace: (message, ...args) => structuredLogger.trace(message, { data: args }),
151
+ // New structured logging methods
152
+ withContext: (context) => structuredLogger.withContext(context),
153
+ startTimer: (label) => structuredLogger.startTimer(label),
154
+ endTimer: (label) => structuredLogger.endTimer(label)
155
+ };
156
+ }
157
+ }
158
+ // Export singleton instance
159
+ export const logger = EnhancedLogger.getInstance();
160
+ // Export convenience function for creating module loggers
161
+ export function createModuleLogger(module) {
162
+ return logger.createModuleLogger(module);
163
+ }
164
+ // Export function to configure logger
165
+ export function configureLogger(config) {
166
+ logger.configure(config);
167
+ }
168
+ /**
169
+ * Smart console replacement that uses structured logger
170
+ */
171
+ export const smartConsole = {
172
+ log: (message, ...args) => {
173
+ const logger = createStructuredModuleLogger('console');
174
+ logger.info(typeof message === 'string' ? message : JSON.stringify(message), { data: args });
175
+ },
176
+ info: (message, ...args) => {
177
+ const logger = createStructuredModuleLogger('console');
178
+ logger.info(typeof message === 'string' ? message : JSON.stringify(message), { data: args });
179
+ },
180
+ warn: (message, ...args) => {
181
+ const logger = createStructuredModuleLogger('console');
182
+ logger.warn(typeof message === 'string' ? message : JSON.stringify(message), { data: args });
183
+ },
184
+ error: (message, ...args) => {
185
+ const logger = createStructuredModuleLogger('console');
186
+ logger.error(typeof message === 'string' ? message : JSON.stringify(message), { data: args });
187
+ },
188
+ debug: (message, ...args) => {
189
+ const logger = createStructuredModuleLogger('console');
190
+ logger.debug(typeof message === 'string' ? message : JSON.stringify(message), { data: args });
191
+ },
192
+ trace: (message, ...args) => {
193
+ const logger = createStructuredModuleLogger('console');
194
+ logger.trace(typeof message === 'string' ? message : JSON.stringify(message), { data: args });
195
+ }
196
+ };
197
+ /**
198
+ * Production-optimized logging functions
199
+ */
200
+ export const prodLog = {
201
+ error: (message, ...args) => {
202
+ const logger = createStructuredModuleLogger('prod');
203
+ logger.error(typeof message === 'string' ? message : JSON.stringify(message), { data: args });
204
+ },
205
+ warn: (message, ...args) => {
206
+ if (!isProductionEnvironment() || process.env.BRAINY_LOG_LEVEL) {
207
+ const logger = createStructuredModuleLogger('prod');
208
+ logger.warn(typeof message === 'string' ? message : JSON.stringify(message), { data: args });
209
+ }
210
+ },
211
+ info: (message, ...args) => {
212
+ if (!isProductionEnvironment() || process.env.BRAINY_LOG_LEVEL) {
213
+ const logger = createStructuredModuleLogger('prod');
214
+ logger.info(typeof message === 'string' ? message : JSON.stringify(message), { data: args });
215
+ }
216
+ },
217
+ debug: (message, ...args) => {
218
+ if (!isProductionEnvironment() || process.env.BRAINY_LOG_LEVEL) {
219
+ const logger = createStructuredModuleLogger('prod');
220
+ logger.debug(typeof message === 'string' ? message : JSON.stringify(message), { data: args });
221
+ }
222
+ },
223
+ log: (message, ...args) => {
224
+ if (!isProductionEnvironment() || process.env.BRAINY_LOG_LEVEL) {
225
+ const logger = createStructuredModuleLogger('prod');
226
+ logger.info(typeof message === 'string' ? message : JSON.stringify(message), { data: args });
227
+ }
228
+ }
229
+ };
230
+ // Re-export structured logger utilities for new code
231
+ export { createModuleLogger as createStructuredModuleLogger } from './structuredLogger.js';
232
+ //# sourceMappingURL=enhancedLogger.js.map
@@ -1,7 +1,7 @@
1
1
  export * from './distance.js';
2
2
  export * from './embedding.js';
3
3
  export * from './workerUtils.js';
4
- export * from './statistics.js';
4
+ export * from './statisticsCollector.js';
5
5
  export * from './jsonProcessing.js';
6
6
  export * from './fieldNameTracking.js';
7
7
  export * from './version.js';
@@ -1,7 +1,7 @@
1
1
  export * from './distance.js';
2
2
  export * from './embedding.js';
3
3
  export * from './workerUtils.js';
4
- export * from './statistics.js';
4
+ export * from './statisticsCollector.js';
5
5
  export * from './jsonProcessing.js';
6
6
  export * from './fieldNameTracking.js';
7
7
  export * from './version.js';
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Intelligent Type Mapper
3
+ * Maps generic/invalid type names to specific semantic types based on data analysis
4
+ * Prevents semantic degradation from overuse of generic types
5
+ */
6
+ /**
7
+ * Intelligent Type Mapper
8
+ */
9
+ export declare class IntelligentTypeMapper {
10
+ private typeCache;
11
+ private inferenceStats;
12
+ /**
13
+ * Map a noun type, with intelligent inference for generic types
14
+ */
15
+ mapNounType(inputType: string, data?: any): string;
16
+ /**
17
+ * Map a verb type
18
+ */
19
+ mapVerbType(inputType: string): string;
20
+ /**
21
+ * Infer type from data structure
22
+ */
23
+ private inferTypeFromData;
24
+ /**
25
+ * Get direct mapping for common aliases
26
+ */
27
+ private getDirectMapping;
28
+ /**
29
+ * Check if a type is valid
30
+ */
31
+ private isValidNounType;
32
+ /**
33
+ * Check if a verb type is valid
34
+ */
35
+ private isValidVerbType;
36
+ /**
37
+ * Get inference statistics
38
+ */
39
+ getStats(): {
40
+ cacheSize: number;
41
+ inferenceRate: number;
42
+ total: number;
43
+ inferred: number;
44
+ defaulted: number;
45
+ cached: number;
46
+ };
47
+ /**
48
+ * Clear the type cache
49
+ */
50
+ clearCache(): void;
51
+ }
52
+ export declare const typeMapper: IntelligentTypeMapper;
53
+ /**
54
+ * Helper function for easy type mapping
55
+ */
56
+ export declare function mapNounType(inputType: string, data?: any): string;
57
+ /**
58
+ * Helper function for verb mapping
59
+ */
60
+ export declare function mapVerbType(inputType: string): string;