@soulcraft/brainy 3.0.0 → 3.1.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/CHANGELOG.md +53 -3
- package/README.md +427 -111
- package/bin/brainy.js +340 -62
- package/dist/api/ConfigAPI.d.ts +67 -0
- package/dist/api/ConfigAPI.js +166 -0
- package/dist/api/DataAPI.d.ts +123 -0
- package/dist/api/DataAPI.js +391 -0
- package/dist/api/SecurityAPI.d.ts +50 -0
- package/dist/api/SecurityAPI.js +139 -0
- package/dist/api/UniversalImportAPI.d.ts +134 -0
- package/dist/api/UniversalImportAPI.js +615 -0
- package/dist/augmentationManager.js +12 -7
- package/dist/augmentationPipeline.d.ts +0 -61
- package/dist/augmentationPipeline.js +0 -87
- package/dist/augmentationRegistry.d.ts +1 -1
- package/dist/augmentationRegistry.js +1 -1
- package/dist/augmentations/apiServerAugmentation.d.ts +27 -1
- package/dist/augmentations/apiServerAugmentation.js +290 -9
- package/dist/augmentations/auditLogAugmentation.d.ts +109 -0
- package/dist/augmentations/auditLogAugmentation.js +358 -0
- package/dist/augmentations/batchProcessingAugmentation.d.ts +3 -2
- package/dist/augmentations/batchProcessingAugmentation.js +123 -22
- package/dist/augmentations/brainyAugmentation.d.ts +142 -8
- package/dist/augmentations/brainyAugmentation.js +179 -2
- package/dist/augmentations/cacheAugmentation.d.ts +8 -5
- package/dist/augmentations/cacheAugmentation.js +116 -17
- package/dist/augmentations/conduitAugmentations.d.ts +2 -2
- package/dist/augmentations/conduitAugmentations.js +2 -2
- package/dist/augmentations/configResolver.d.ts +122 -0
- package/dist/augmentations/configResolver.js +440 -0
- package/dist/augmentations/connectionPoolAugmentation.d.ts +3 -1
- package/dist/augmentations/connectionPoolAugmentation.js +37 -12
- package/dist/augmentations/defaultAugmentations.d.ts +14 -10
- package/dist/augmentations/defaultAugmentations.js +16 -11
- package/dist/augmentations/discovery/catalogDiscovery.d.ts +142 -0
- package/dist/augmentations/discovery/catalogDiscovery.js +249 -0
- package/dist/augmentations/discovery/localDiscovery.d.ts +84 -0
- package/dist/augmentations/discovery/localDiscovery.js +246 -0
- package/dist/augmentations/discovery/runtimeLoader.d.ts +97 -0
- package/dist/augmentations/discovery/runtimeLoader.js +337 -0
- package/dist/augmentations/discovery.d.ts +152 -0
- package/dist/augmentations/discovery.js +441 -0
- package/dist/augmentations/display/cache.d.ts +130 -0
- package/dist/augmentations/display/cache.js +319 -0
- package/dist/augmentations/display/fieldPatterns.d.ts +52 -0
- package/dist/augmentations/display/fieldPatterns.js +393 -0
- package/dist/augmentations/display/iconMappings.d.ts +57 -0
- package/dist/augmentations/display/iconMappings.js +68 -0
- package/dist/augmentations/display/intelligentComputation.d.ts +109 -0
- package/dist/augmentations/display/intelligentComputation.js +462 -0
- package/dist/augmentations/display/types.d.ts +203 -0
- package/dist/augmentations/display/types.js +7 -0
- package/dist/augmentations/entityRegistryAugmentation.d.ts +3 -1
- package/dist/augmentations/entityRegistryAugmentation.js +5 -1
- package/dist/augmentations/indexAugmentation.d.ts +5 -3
- package/dist/augmentations/indexAugmentation.js +5 -2
- package/dist/augmentations/intelligentVerbScoringAugmentation.d.ts +24 -7
- package/dist/augmentations/intelligentVerbScoringAugmentation.js +111 -27
- package/dist/augmentations/manifest.d.ts +176 -0
- package/dist/augmentations/manifest.js +8 -0
- package/dist/augmentations/marketplace/AugmentationMarketplace.d.ts +168 -0
- package/dist/augmentations/marketplace/AugmentationMarketplace.js +329 -0
- package/dist/augmentations/marketplace/cli.d.ts +47 -0
- package/dist/augmentations/marketplace/cli.js +265 -0
- package/dist/augmentations/metricsAugmentation.d.ts +3 -3
- package/dist/augmentations/metricsAugmentation.js +2 -2
- package/dist/augmentations/monitoringAugmentation.d.ts +3 -3
- package/dist/augmentations/monitoringAugmentation.js +2 -2
- package/dist/augmentations/neuralImport.d.ts +1 -1
- package/dist/augmentations/neuralImport.js +4 -4
- package/dist/augmentations/rateLimitAugmentation.d.ts +82 -0
- package/dist/augmentations/rateLimitAugmentation.js +321 -0
- package/dist/augmentations/requestDeduplicatorAugmentation.d.ts +2 -2
- package/dist/augmentations/requestDeduplicatorAugmentation.js +1 -1
- package/dist/augmentations/storageAugmentation.d.ts +1 -1
- package/dist/augmentations/storageAugmentation.js +2 -2
- package/dist/augmentations/storageAugmentations.d.ts +37 -8
- package/dist/augmentations/storageAugmentations.js +204 -15
- package/dist/augmentations/synapseAugmentation.d.ts +1 -1
- package/dist/augmentations/synapseAugmentation.js +35 -16
- package/dist/augmentations/typeMatching/brainyTypes.d.ts +83 -0
- package/dist/augmentations/typeMatching/brainyTypes.js +425 -0
- package/dist/augmentations/typeMatching/intelligentTypeMatcher.d.ts +39 -59
- package/dist/augmentations/typeMatching/intelligentTypeMatcher.js +103 -389
- package/dist/augmentations/universalDisplayAugmentation.d.ts +191 -0
- package/dist/augmentations/universalDisplayAugmentation.js +371 -0
- package/dist/brainy-unified.d.ts +106 -0
- package/dist/brainy-unified.js +327 -0
- package/dist/brainy.d.ts +277 -0
- package/dist/brainy.js +1241 -0
- package/dist/brainyData.d.ts +56 -111
- package/dist/brainyData.js +912 -756
- package/dist/brainyDataV3.d.ts +186 -0
- package/dist/brainyDataV3.js +337 -0
- package/dist/config/distributedPresets-new.d.ts +118 -0
- package/dist/config/distributedPresets-new.js +318 -0
- package/dist/config/distributedPresets.d.ts +118 -0
- package/dist/config/distributedPresets.js +318 -0
- package/dist/config/extensibleConfig.d.ts +99 -0
- package/dist/config/extensibleConfig.js +268 -0
- package/dist/config/index.d.ts +17 -0
- package/dist/config/index.js +35 -0
- package/dist/config/modelAutoConfig.d.ts +32 -0
- package/dist/config/modelAutoConfig.js +139 -0
- package/dist/config/modelPrecisionManager.d.ts +42 -0
- package/dist/config/modelPrecisionManager.js +98 -0
- package/dist/config/sharedConfigManager.d.ts +67 -0
- package/dist/config/sharedConfigManager.js +215 -0
- package/dist/config/storageAutoConfig.d.ts +41 -0
- package/dist/config/storageAutoConfig.js +328 -0
- package/dist/config/zeroConfig.d.ts +68 -0
- package/dist/config/zeroConfig.js +301 -0
- package/dist/cortex/backupRestore.d.ts +2 -2
- package/dist/cortex/backupRestore.js +85 -27
- package/dist/cortex/healthCheck.d.ts +2 -2
- package/dist/cortex/neuralImport.d.ts +2 -2
- package/dist/cortex/neuralImport.js +18 -13
- package/dist/cortex/performanceMonitor.d.ts +2 -2
- package/dist/critical/model-guardian.d.ts +4 -0
- package/dist/critical/model-guardian.js +31 -11
- package/dist/demo.d.ts +4 -4
- package/dist/demo.js +7 -7
- package/dist/distributed/cacheSync.d.ts +112 -0
- package/dist/distributed/cacheSync.js +265 -0
- package/dist/distributed/coordinator.d.ts +193 -0
- package/dist/distributed/coordinator.js +548 -0
- package/dist/distributed/httpTransport.d.ts +120 -0
- package/dist/distributed/httpTransport.js +446 -0
- package/dist/distributed/index.d.ts +8 -0
- package/dist/distributed/index.js +5 -0
- package/dist/distributed/networkTransport.d.ts +132 -0
- package/dist/distributed/networkTransport.js +633 -0
- package/dist/distributed/queryPlanner.d.ts +104 -0
- package/dist/distributed/queryPlanner.js +327 -0
- package/dist/distributed/readWriteSeparation.d.ts +134 -0
- package/dist/distributed/readWriteSeparation.js +350 -0
- package/dist/distributed/shardManager.d.ts +114 -0
- package/dist/distributed/shardManager.js +357 -0
- package/dist/distributed/shardMigration.d.ts +110 -0
- package/dist/distributed/shardMigration.js +289 -0
- package/dist/distributed/storageDiscovery.d.ts +160 -0
- package/dist/distributed/storageDiscovery.js +551 -0
- package/dist/embeddings/CachedEmbeddings.d.ts +40 -0
- package/dist/embeddings/CachedEmbeddings.js +146 -0
- package/dist/embeddings/EmbeddingManager.d.ts +102 -0
- package/dist/embeddings/EmbeddingManager.js +291 -0
- package/dist/embeddings/SingletonModelManager.d.ts +95 -0
- package/dist/embeddings/SingletonModelManager.js +220 -0
- package/dist/embeddings/index.d.ts +12 -0
- package/dist/embeddings/index.js +16 -0
- package/dist/embeddings/lightweight-embedder.d.ts +0 -1
- package/dist/embeddings/lightweight-embedder.js +4 -12
- package/dist/embeddings/model-manager.d.ts +11 -0
- package/dist/embeddings/model-manager.js +43 -7
- package/dist/embeddings/universal-memory-manager.d.ts +1 -1
- package/dist/embeddings/universal-memory-manager.js +27 -67
- package/dist/embeddings/worker-embedding.js +4 -8
- package/dist/errors/brainyError.d.ts +5 -1
- package/dist/errors/brainyError.js +12 -0
- package/dist/examples/basicUsage.js +7 -4
- package/dist/graph/graphAdjacencyIndex.d.ts +96 -0
- package/dist/graph/graphAdjacencyIndex.js +288 -0
- package/dist/graph/pathfinding.js +4 -2
- package/dist/hnsw/scaledHNSWSystem.js +11 -2
- package/dist/importManager.js +8 -5
- package/dist/index.d.ts +17 -22
- package/dist/index.js +37 -23
- package/dist/mcp/brainyMCPAdapter.d.ts +4 -4
- package/dist/mcp/brainyMCPAdapter.js +5 -5
- package/dist/mcp/brainyMCPService.d.ts +3 -3
- package/dist/mcp/brainyMCPService.js +3 -11
- package/dist/mcp/mcpAugmentationToolset.js +20 -30
- package/dist/neural/embeddedPatterns.d.ts +1 -1
- package/dist/neural/embeddedPatterns.js +2 -2
- package/dist/neural/entityExtractor.d.ts +65 -0
- package/dist/neural/entityExtractor.js +316 -0
- package/dist/neural/improvedNeuralAPI.d.ts +357 -0
- package/dist/neural/improvedNeuralAPI.js +2628 -0
- package/dist/neural/naturalLanguageProcessor.d.ts +155 -10
- package/dist/neural/naturalLanguageProcessor.js +941 -66
- package/dist/neural/naturalLanguageProcessorStatic.d.ts +2 -2
- package/dist/neural/naturalLanguageProcessorStatic.js +3 -3
- package/dist/neural/neuralAPI.js +8 -2
- package/dist/neural/patternLibrary.d.ts +57 -3
- package/dist/neural/patternLibrary.js +348 -13
- package/dist/neural/staticPatternMatcher.d.ts +2 -2
- package/dist/neural/staticPatternMatcher.js +2 -2
- package/dist/neural/types.d.ts +287 -0
- package/dist/neural/types.js +24 -0
- package/dist/shared/default-augmentations.d.ts +3 -3
- package/dist/shared/default-augmentations.js +5 -5
- package/dist/storage/adapters/baseStorageAdapter.d.ts +42 -0
- package/dist/storage/adapters/fileSystemStorage.d.ts +26 -2
- package/dist/storage/adapters/fileSystemStorage.js +218 -15
- package/dist/storage/adapters/memoryStorage.d.ts +4 -4
- package/dist/storage/adapters/memoryStorage.js +17 -12
- package/dist/storage/adapters/opfsStorage.d.ts +2 -2
- package/dist/storage/adapters/opfsStorage.js +2 -2
- package/dist/storage/adapters/s3CompatibleStorage.d.ts +2 -2
- package/dist/storage/adapters/s3CompatibleStorage.js +2 -2
- package/dist/storage/backwardCompatibility.d.ts +10 -78
- package/dist/storage/backwardCompatibility.js +17 -132
- package/dist/storage/baseStorage.d.ts +18 -2
- package/dist/storage/baseStorage.js +74 -3
- package/dist/storage/cacheManager.js +2 -2
- package/dist/storage/readOnlyOptimizations.js +8 -3
- package/dist/streaming/pipeline.d.ts +154 -0
- package/dist/streaming/pipeline.js +551 -0
- package/dist/triple/TripleIntelligence.d.ts +25 -110
- package/dist/triple/TripleIntelligence.js +4 -574
- package/dist/triple/TripleIntelligenceSystem.d.ts +159 -0
- package/dist/triple/TripleIntelligenceSystem.js +519 -0
- package/dist/types/apiTypes.d.ts +278 -0
- package/dist/types/apiTypes.js +33 -0
- package/dist/types/brainy.types.d.ts +308 -0
- package/dist/types/brainy.types.js +8 -0
- package/dist/types/brainyDataInterface.d.ts +5 -8
- package/dist/types/brainyDataInterface.js +2 -2
- package/dist/types/graphTypes.js +2 -2
- package/dist/universal/crypto.d.ts +11 -1
- package/dist/universal/crypto.js +24 -93
- package/dist/universal/events.d.ts +3 -2
- package/dist/universal/events.js +6 -75
- package/dist/universal/fs.d.ts +2 -3
- package/dist/universal/fs.js +5 -211
- package/dist/universal/path.d.ts +3 -2
- package/dist/universal/path.js +22 -78
- package/dist/universal/uuid.d.ts +1 -1
- package/dist/universal/uuid.js +1 -1
- package/dist/utils/brainyTypes.d.ts +217 -0
- package/dist/utils/brainyTypes.js +261 -0
- package/dist/utils/cacheAutoConfig.d.ts +3 -3
- package/dist/utils/embedding.d.ts +9 -4
- package/dist/utils/embedding.js +89 -26
- package/dist/utils/enhancedLogger.d.ts +104 -0
- package/dist/utils/enhancedLogger.js +232 -0
- package/dist/utils/hybridModelManager.d.ts +19 -28
- package/dist/utils/hybridModelManager.js +36 -200
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +1 -1
- package/dist/utils/intelligentTypeMapper.d.ts +60 -0
- package/dist/utils/intelligentTypeMapper.js +349 -0
- package/dist/utils/metadataIndex.d.ts +118 -1
- package/dist/utils/metadataIndex.js +539 -16
- package/dist/utils/nodeVersionCheck.d.ts +24 -0
- package/dist/utils/nodeVersionCheck.js +65 -0
- package/dist/utils/paramValidation.d.ts +39 -0
- package/dist/utils/paramValidation.js +192 -0
- package/dist/utils/rateLimiter.d.ts +160 -0
- package/dist/utils/rateLimiter.js +271 -0
- package/dist/utils/statistics.d.ts +4 -4
- package/dist/utils/statistics.js +3 -3
- package/dist/utils/structuredLogger.d.ts +146 -0
- package/dist/utils/structuredLogger.js +394 -0
- package/dist/utils/textEncoding.js +2 -1
- package/dist/utils/typeValidation.d.ts +59 -0
- package/dist/utils/typeValidation.js +374 -0
- package/dist/utils/version.js +19 -3
- package/package.json +15 -17
- package/scripts/download-models.cjs +94 -20
- package/dist/augmentations/walAugmentation.d.ts +0 -109
- package/dist/augmentations/walAugmentation.js +0 -516
- package/dist/browserFramework.d.ts +0 -15
- package/dist/browserFramework.js +0 -31
- package/dist/browserFramework.minimal.d.ts +0 -14
- package/dist/browserFramework.minimal.js +0 -31
- package/dist/chat/BrainyChat.d.ts +0 -121
- package/dist/chat/BrainyChat.js +0 -396
- package/dist/chat/ChatCLI.d.ts +0 -61
- package/dist/chat/ChatCLI.js +0 -351
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enhanced Structured Logging System for Brainy
|
|
3
|
+
* Provides production-ready logging with structured output, context preservation,
|
|
4
|
+
* performance tracking, and multiple transport support
|
|
5
|
+
*/
|
|
6
|
+
import { performance } from 'perf_hooks';
|
|
7
|
+
import { hostname } from 'os';
|
|
8
|
+
import { randomUUID } from 'crypto';
|
|
9
|
+
export var LogLevel;
|
|
10
|
+
(function (LogLevel) {
|
|
11
|
+
LogLevel[LogLevel["SILENT"] = -1] = "SILENT";
|
|
12
|
+
LogLevel[LogLevel["FATAL"] = 0] = "FATAL";
|
|
13
|
+
LogLevel[LogLevel["ERROR"] = 1] = "ERROR";
|
|
14
|
+
LogLevel[LogLevel["WARN"] = 2] = "WARN";
|
|
15
|
+
LogLevel[LogLevel["INFO"] = 3] = "INFO";
|
|
16
|
+
LogLevel[LogLevel["DEBUG"] = 4] = "DEBUG";
|
|
17
|
+
LogLevel[LogLevel["TRACE"] = 5] = "TRACE";
|
|
18
|
+
})(LogLevel || (LogLevel = {}));
|
|
19
|
+
class ConsoleTransport {
|
|
20
|
+
constructor(format = 'json') {
|
|
21
|
+
this.name = 'console';
|
|
22
|
+
this.format = format;
|
|
23
|
+
}
|
|
24
|
+
log(entry) {
|
|
25
|
+
const method = this.getConsoleMethod(entry.levelNumeric);
|
|
26
|
+
if (this.format === 'json') {
|
|
27
|
+
method(JSON.stringify(entry));
|
|
28
|
+
}
|
|
29
|
+
else if (this.format === 'pretty') {
|
|
30
|
+
const color = this.getColor(entry.levelNumeric);
|
|
31
|
+
const prefix = `${entry.timestamp} ${color}[${entry.level}]\\x1b[0m [${entry.module}]`;
|
|
32
|
+
const message = entry.message;
|
|
33
|
+
if (entry.error) {
|
|
34
|
+
method(`${prefix} ${message}`, entry.error);
|
|
35
|
+
}
|
|
36
|
+
else if (entry.data) {
|
|
37
|
+
method(`${prefix} ${message}`, entry.data);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
method(`${prefix} ${message}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
// Simple format
|
|
45
|
+
method(`[${entry.level}] ${entry.message}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
getConsoleMethod(level) {
|
|
49
|
+
switch (level) {
|
|
50
|
+
case LogLevel.FATAL:
|
|
51
|
+
case LogLevel.ERROR:
|
|
52
|
+
return console.error;
|
|
53
|
+
case LogLevel.WARN:
|
|
54
|
+
return console.warn;
|
|
55
|
+
case LogLevel.INFO:
|
|
56
|
+
return console.info;
|
|
57
|
+
default:
|
|
58
|
+
return console.log;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
getColor(level) {
|
|
62
|
+
switch (level) {
|
|
63
|
+
case LogLevel.FATAL:
|
|
64
|
+
return '\\x1b[35m'; // Magenta
|
|
65
|
+
case LogLevel.ERROR:
|
|
66
|
+
return '\\x1b[31m'; // Red
|
|
67
|
+
case LogLevel.WARN:
|
|
68
|
+
return '\\x1b[33m'; // Yellow
|
|
69
|
+
case LogLevel.INFO:
|
|
70
|
+
return '\\x1b[36m'; // Cyan
|
|
71
|
+
case LogLevel.DEBUG:
|
|
72
|
+
return '\\x1b[32m'; // Green
|
|
73
|
+
case LogLevel.TRACE:
|
|
74
|
+
return '\\x1b[90m'; // Gray
|
|
75
|
+
default:
|
|
76
|
+
return '\\x1b[0m'; // Reset
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
class BufferedTransport {
|
|
81
|
+
constructor(innerTransport, bufferSize = 100, flushInterval = 5000) {
|
|
82
|
+
this.name = 'buffered';
|
|
83
|
+
this.buffer = [];
|
|
84
|
+
this.innerTransport = innerTransport;
|
|
85
|
+
this.bufferSize = bufferSize;
|
|
86
|
+
if (flushInterval > 0) {
|
|
87
|
+
this.flushTimer = setInterval(() => this.flush(), flushInterval);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
log(entry) {
|
|
91
|
+
this.buffer.push(entry);
|
|
92
|
+
if (this.buffer.length >= this.bufferSize) {
|
|
93
|
+
this.flush();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
async flush() {
|
|
97
|
+
const entries = this.buffer.splice(0);
|
|
98
|
+
for (const entry of entries) {
|
|
99
|
+
await this.innerTransport.log(entry);
|
|
100
|
+
}
|
|
101
|
+
if (this.innerTransport.flush) {
|
|
102
|
+
await this.innerTransport.flush();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
destroy() {
|
|
106
|
+
if (this.flushTimer) {
|
|
107
|
+
clearInterval(this.flushTimer);
|
|
108
|
+
}
|
|
109
|
+
this.flush();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
export class StructuredLogger {
|
|
113
|
+
constructor() {
|
|
114
|
+
this.defaultContext = {};
|
|
115
|
+
this.performanceMarks = new Map();
|
|
116
|
+
const isDevelopment = process.env.NODE_ENV !== 'production';
|
|
117
|
+
const format = isDevelopment ? 'pretty' : 'json';
|
|
118
|
+
this.config = {
|
|
119
|
+
level: isDevelopment ? LogLevel.DEBUG : LogLevel.INFO,
|
|
120
|
+
format,
|
|
121
|
+
transports: [new ConsoleTransport(format)],
|
|
122
|
+
includeHost: !isDevelopment,
|
|
123
|
+
includeMemory: false,
|
|
124
|
+
bufferSize: 100,
|
|
125
|
+
flushInterval: 5000,
|
|
126
|
+
version: process.env.npm_package_version
|
|
127
|
+
};
|
|
128
|
+
// Load from environment
|
|
129
|
+
this.loadEnvironmentConfig();
|
|
130
|
+
}
|
|
131
|
+
loadEnvironmentConfig() {
|
|
132
|
+
const envLevel = process.env.BRAINY_LOG_LEVEL;
|
|
133
|
+
if (envLevel) {
|
|
134
|
+
const level = LogLevel[envLevel.toUpperCase()];
|
|
135
|
+
if (level !== undefined) {
|
|
136
|
+
this.config.level = level;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const envFormat = process.env.BRAINY_LOG_FORMAT;
|
|
140
|
+
if (envFormat && ['json', 'pretty', 'simple'].includes(envFormat)) {
|
|
141
|
+
this.config.format = envFormat;
|
|
142
|
+
}
|
|
143
|
+
const moduleConfig = process.env.BRAINY_MODULE_LOG_LEVELS;
|
|
144
|
+
if (moduleConfig) {
|
|
145
|
+
try {
|
|
146
|
+
this.config.modules = JSON.parse(moduleConfig);
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
// Ignore parse errors
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
static getInstance() {
|
|
154
|
+
if (!StructuredLogger.instance) {
|
|
155
|
+
StructuredLogger.instance = new StructuredLogger();
|
|
156
|
+
}
|
|
157
|
+
return StructuredLogger.instance;
|
|
158
|
+
}
|
|
159
|
+
configure(config) {
|
|
160
|
+
this.config = { ...this.config, ...config };
|
|
161
|
+
}
|
|
162
|
+
setContext(context) {
|
|
163
|
+
this.defaultContext = { ...this.defaultContext, ...context };
|
|
164
|
+
}
|
|
165
|
+
clearContext() {
|
|
166
|
+
this.defaultContext = {};
|
|
167
|
+
}
|
|
168
|
+
withContext(context) {
|
|
169
|
+
const contextualLogger = Object.create(this);
|
|
170
|
+
contextualLogger.defaultContext = { ...this.defaultContext, ...context };
|
|
171
|
+
return contextualLogger;
|
|
172
|
+
}
|
|
173
|
+
startTimer(label) {
|
|
174
|
+
this.performanceMarks.set(label, performance.now());
|
|
175
|
+
}
|
|
176
|
+
endTimer(label) {
|
|
177
|
+
const start = this.performanceMarks.get(label);
|
|
178
|
+
if (start === undefined)
|
|
179
|
+
return undefined;
|
|
180
|
+
const duration = performance.now() - start;
|
|
181
|
+
this.performanceMarks.delete(label);
|
|
182
|
+
return duration;
|
|
183
|
+
}
|
|
184
|
+
shouldLog(level, module) {
|
|
185
|
+
if (this.config.modules?.[module] !== undefined) {
|
|
186
|
+
return level <= this.config.modules[module];
|
|
187
|
+
}
|
|
188
|
+
return level <= this.config.level;
|
|
189
|
+
}
|
|
190
|
+
createLogEntry(level, module, message, context, data, error) {
|
|
191
|
+
const entry = {
|
|
192
|
+
timestamp: new Date().toISOString(),
|
|
193
|
+
level: LogLevel[level],
|
|
194
|
+
levelNumeric: level,
|
|
195
|
+
module,
|
|
196
|
+
message,
|
|
197
|
+
pid: process.pid,
|
|
198
|
+
version: this.config.version
|
|
199
|
+
};
|
|
200
|
+
// Merge contexts
|
|
201
|
+
const mergedContext = { ...this.defaultContext, ...context };
|
|
202
|
+
if (Object.keys(mergedContext).length > 0) {
|
|
203
|
+
entry.context = mergedContext;
|
|
204
|
+
}
|
|
205
|
+
if (data !== undefined) {
|
|
206
|
+
entry.data = data;
|
|
207
|
+
}
|
|
208
|
+
if (error) {
|
|
209
|
+
entry.error = {
|
|
210
|
+
name: error.name,
|
|
211
|
+
message: error.message,
|
|
212
|
+
stack: error.stack,
|
|
213
|
+
code: error.code
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
if (this.config.includeHost) {
|
|
217
|
+
entry.host = hostname();
|
|
218
|
+
}
|
|
219
|
+
if (this.config.includeMemory) {
|
|
220
|
+
const mem = process.memoryUsage();
|
|
221
|
+
entry.performance = {
|
|
222
|
+
memory: {
|
|
223
|
+
used: Math.round(mem.heapUsed / 1024 / 1024),
|
|
224
|
+
total: Math.round(mem.heapTotal / 1024 / 1024)
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
return entry;
|
|
229
|
+
}
|
|
230
|
+
log(level, module, message, contextOrData, data) {
|
|
231
|
+
if (!this.shouldLog(level, module)) {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
// Handle overloaded parameters
|
|
235
|
+
let context;
|
|
236
|
+
let logData;
|
|
237
|
+
if (contextOrData && typeof contextOrData === 'object' && !Array.isArray(contextOrData)) {
|
|
238
|
+
// Check if it looks like a context object
|
|
239
|
+
const hasContextKeys = ['requestId', 'userId', 'operation', 'entityId', 'entityType']
|
|
240
|
+
.some(key => key in contextOrData);
|
|
241
|
+
if (hasContextKeys) {
|
|
242
|
+
context = contextOrData;
|
|
243
|
+
logData = data;
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
logData = contextOrData;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
logData = contextOrData;
|
|
251
|
+
}
|
|
252
|
+
// Extract error if present
|
|
253
|
+
let error;
|
|
254
|
+
if (logData instanceof Error) {
|
|
255
|
+
error = logData;
|
|
256
|
+
logData = undefined;
|
|
257
|
+
}
|
|
258
|
+
else if (logData?.error instanceof Error) {
|
|
259
|
+
error = logData.error;
|
|
260
|
+
delete logData.error;
|
|
261
|
+
}
|
|
262
|
+
const entry = this.createLogEntry(level, module, message, context, logData, error);
|
|
263
|
+
// Send to all transports
|
|
264
|
+
for (const transport of this.config.transports) {
|
|
265
|
+
try {
|
|
266
|
+
transport.log(entry);
|
|
267
|
+
}
|
|
268
|
+
catch (err) {
|
|
269
|
+
// Fallback to console.error if transport fails
|
|
270
|
+
console.error('Logger transport error:', err);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
fatal(module, message, contextOrData, data) {
|
|
275
|
+
this.log(LogLevel.FATAL, module, message, contextOrData, data);
|
|
276
|
+
}
|
|
277
|
+
error(module, message, contextOrData, data) {
|
|
278
|
+
this.log(LogLevel.ERROR, module, message, contextOrData, data);
|
|
279
|
+
}
|
|
280
|
+
warn(module, message, contextOrData, data) {
|
|
281
|
+
this.log(LogLevel.WARN, module, message, contextOrData, data);
|
|
282
|
+
}
|
|
283
|
+
info(module, message, contextOrData, data) {
|
|
284
|
+
this.log(LogLevel.INFO, module, message, contextOrData, data);
|
|
285
|
+
}
|
|
286
|
+
debug(module, message, contextOrData, data) {
|
|
287
|
+
this.log(LogLevel.DEBUG, module, message, contextOrData, data);
|
|
288
|
+
}
|
|
289
|
+
trace(module, message, contextOrData, data) {
|
|
290
|
+
this.log(LogLevel.TRACE, module, message, contextOrData, data);
|
|
291
|
+
}
|
|
292
|
+
createModuleLogger(module) {
|
|
293
|
+
const self = this;
|
|
294
|
+
return {
|
|
295
|
+
fatal: (message, contextOrData, data) => self.fatal(module, message, contextOrData, data),
|
|
296
|
+
error: (message, contextOrData, data) => self.error(module, message, contextOrData, data),
|
|
297
|
+
warn: (message, contextOrData, data) => self.warn(module, message, contextOrData, data),
|
|
298
|
+
info: (message, contextOrData, data) => self.info(module, message, contextOrData, data),
|
|
299
|
+
debug: (message, contextOrData, data) => self.debug(module, message, contextOrData, data),
|
|
300
|
+
trace: (message, contextOrData, data) => self.trace(module, message, contextOrData, data),
|
|
301
|
+
withContext: (context) => {
|
|
302
|
+
const contextual = self.withContext(context);
|
|
303
|
+
return contextual.createModuleLogger(module);
|
|
304
|
+
},
|
|
305
|
+
startTimer: (label) => self.startTimer(`${module}:${label}`),
|
|
306
|
+
endTimer: (label) => self.endTimer(`${module}:${label}`)
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
async flush() {
|
|
310
|
+
const flushPromises = this.config.transports
|
|
311
|
+
.filter(t => t.flush)
|
|
312
|
+
.map(t => t.flush());
|
|
313
|
+
await Promise.all(flushPromises);
|
|
314
|
+
}
|
|
315
|
+
addTransport(transport) {
|
|
316
|
+
this.config.transports.push(transport);
|
|
317
|
+
}
|
|
318
|
+
removeTransport(name) {
|
|
319
|
+
this.config.transports = this.config.transports.filter(t => t.name !== name);
|
|
320
|
+
}
|
|
321
|
+
child(context) {
|
|
322
|
+
return this.withContext(context);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
// Singleton instance
|
|
326
|
+
export const structuredLogger = StructuredLogger.getInstance();
|
|
327
|
+
// Convenience functions
|
|
328
|
+
export function createModuleLogger(module) {
|
|
329
|
+
return structuredLogger.createModuleLogger(module);
|
|
330
|
+
}
|
|
331
|
+
export function setLogContext(context) {
|
|
332
|
+
structuredLogger.setContext(context);
|
|
333
|
+
}
|
|
334
|
+
export function withLogContext(context) {
|
|
335
|
+
return structuredLogger.withContext(context);
|
|
336
|
+
}
|
|
337
|
+
// Correlation ID middleware helper
|
|
338
|
+
export function createCorrelationId() {
|
|
339
|
+
return randomUUID();
|
|
340
|
+
}
|
|
341
|
+
// Performance logging helper
|
|
342
|
+
export function logPerformance(logger, operation, fn) {
|
|
343
|
+
logger.startTimer(operation);
|
|
344
|
+
try {
|
|
345
|
+
const result = fn();
|
|
346
|
+
if (result && typeof result.then === 'function') {
|
|
347
|
+
return result.finally(() => {
|
|
348
|
+
const duration = logger.endTimer(operation);
|
|
349
|
+
logger.debug(`${operation} completed`, { duration });
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
const duration = logger.endTimer(operation);
|
|
353
|
+
logger.debug(`${operation} completed`, { duration });
|
|
354
|
+
return result;
|
|
355
|
+
}
|
|
356
|
+
catch (error) {
|
|
357
|
+
const duration = logger.endTimer(operation);
|
|
358
|
+
logger.error(`${operation} failed`, { duration, error });
|
|
359
|
+
throw error;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
// Backward compatibility wrapper for existing logger
|
|
363
|
+
export class LoggerCompatibilityWrapper {
|
|
364
|
+
constructor(module = 'legacy') {
|
|
365
|
+
this.moduleLogger = createModuleLogger(module);
|
|
366
|
+
}
|
|
367
|
+
error(module, message, ...args) {
|
|
368
|
+
this.moduleLogger.error(message, { module, data: args });
|
|
369
|
+
}
|
|
370
|
+
warn(module, message, ...args) {
|
|
371
|
+
this.moduleLogger.warn(message, { module, data: args });
|
|
372
|
+
}
|
|
373
|
+
info(module, message, ...args) {
|
|
374
|
+
this.moduleLogger.info(message, { module, data: args });
|
|
375
|
+
}
|
|
376
|
+
debug(module, message, ...args) {
|
|
377
|
+
this.moduleLogger.debug(message, { module, data: args });
|
|
378
|
+
}
|
|
379
|
+
trace(module, message, ...args) {
|
|
380
|
+
this.moduleLogger.trace(message, { module, data: args });
|
|
381
|
+
}
|
|
382
|
+
createModuleLogger(module) {
|
|
383
|
+
const logger = createModuleLogger(module);
|
|
384
|
+
return {
|
|
385
|
+
error: (message, ...args) => logger.error(message, { data: args }),
|
|
386
|
+
warn: (message, ...args) => logger.warn(message, { data: args }),
|
|
387
|
+
info: (message, ...args) => logger.info(message, { data: args }),
|
|
388
|
+
debug: (message, ...args) => logger.debug(message, { data: args }),
|
|
389
|
+
trace: (message, ...args) => logger.trace(message, { data: args })
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
// Types are already exported above, no need to re-export
|
|
394
|
+
//# sourceMappingURL=structuredLogger.js.map
|
|
@@ -26,7 +26,8 @@ export async function applyTensorFlowPatch() {
|
|
|
26
26
|
return globalThis;
|
|
27
27
|
if (typeof global !== 'undefined')
|
|
28
28
|
return global;
|
|
29
|
-
|
|
29
|
+
throw new Error('Cannot apply TextEncoder/TextDecoder patches: No global object found. ' +
|
|
30
|
+
'This environment does not have globalThis or global defined.');
|
|
30
31
|
})();
|
|
31
32
|
// Make sure TextEncoder and TextDecoder are available globally
|
|
32
33
|
if (!globalObj.TextEncoder) {
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { NounType, VerbType } from '../types/graphTypes.js';
|
|
2
|
+
export declare function isValidNounType(type: unknown): type is NounType;
|
|
3
|
+
export declare function isValidVerbType(type: unknown): type is VerbType;
|
|
4
|
+
export declare function validateNounType(type: unknown): NounType;
|
|
5
|
+
export declare function validateVerbType(type: unknown): VerbType;
|
|
6
|
+
export interface ValidatedGraphNoun {
|
|
7
|
+
noun: NounType;
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
}
|
|
10
|
+
export interface ValidatedGraphVerb {
|
|
11
|
+
verb: VerbType;
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
}
|
|
14
|
+
export declare function validateGraphNoun(noun: unknown): ValidatedGraphNoun;
|
|
15
|
+
export declare function validateGraphVerb(verb: unknown): ValidatedGraphVerb;
|
|
16
|
+
export declare function validateNounTypes(types: unknown[]): NounType[];
|
|
17
|
+
export declare function validateVerbTypes(types: unknown[]): VerbType[];
|
|
18
|
+
export interface ValidationStats {
|
|
19
|
+
validated: number;
|
|
20
|
+
failed: number;
|
|
21
|
+
inferred: number;
|
|
22
|
+
suggestions: number;
|
|
23
|
+
}
|
|
24
|
+
export declare function getValidationStats(): ValidationStats;
|
|
25
|
+
export declare function resetValidationStats(): void;
|
|
26
|
+
export declare class ValidationError extends Error {
|
|
27
|
+
readonly parameter: string;
|
|
28
|
+
readonly value: any;
|
|
29
|
+
readonly constraint: string;
|
|
30
|
+
constructor(parameter: string, value: any, constraint: string);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Validate required ID parameter
|
|
34
|
+
* Standard validation for all ID-based operations
|
|
35
|
+
*/
|
|
36
|
+
export declare function validateId(id: unknown, paramName?: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* Validate search query input
|
|
39
|
+
* Handles string queries, vectors, and objects for search operations
|
|
40
|
+
*/
|
|
41
|
+
export declare function validateSearchQuery(query: unknown, paramName?: string): any;
|
|
42
|
+
/**
|
|
43
|
+
* Validate data input for addNoun/updateNoun operations
|
|
44
|
+
* Handles vectors, objects, strings, and validates structure
|
|
45
|
+
*/
|
|
46
|
+
export declare function validateDataInput(data: unknown, paramName?: string, allowNull?: boolean): any;
|
|
47
|
+
/**
|
|
48
|
+
* Validate search options
|
|
49
|
+
* Comprehensive validation for search API options
|
|
50
|
+
*/
|
|
51
|
+
export declare function validateSearchOptions(options: unknown, paramName?: string): any;
|
|
52
|
+
/**
|
|
53
|
+
* Validate ID arrays (for bulk operations)
|
|
54
|
+
*/
|
|
55
|
+
export declare function validateIdArray(ids: unknown, paramName?: string): string[];
|
|
56
|
+
/**
|
|
57
|
+
* Track validation stats for monitoring
|
|
58
|
+
*/
|
|
59
|
+
export declare function recordValidation(success: boolean): void;
|