@nxuss/lemma 0.5.2 → 0.5.3
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/README.md +1 -1
- package/dist/cjs/cli/lemma-proxy.d.ts.map +1 -1
- package/dist/cjs/cli/lemma-proxy.js +187 -98
- package/dist/cjs/cli/lemma-proxy.js.map +1 -1
- package/dist/cjs/config/index.d.ts.map +1 -1
- package/dist/cjs/config/index.js +2 -1
- package/dist/cjs/config/index.js.map +1 -1
- package/dist/cjs/errors/LemmaError.d.ts +52 -0
- package/dist/cjs/errors/LemmaError.d.ts.map +1 -0
- package/dist/cjs/errors/LemmaError.js +84 -0
- package/dist/cjs/errors/LemmaError.js.map +1 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +24 -22
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/subconscious/SemanticCache.d.ts +4 -4
- package/dist/cjs/subconscious/SemanticCache.d.ts.map +1 -1
- package/dist/cjs/subconscious/SemanticCache.js +14 -10
- package/dist/cjs/subconscious/SemanticCache.js.map +1 -1
- package/dist/cjs/types/index.d.ts +8 -8
- package/dist/cjs/types/index.d.ts.map +1 -1
- package/dist/cjs/utils/logger.d.ts +27 -6
- package/dist/cjs/utils/logger.d.ts.map +1 -1
- package/dist/cjs/utils/logger.js +96 -28
- package/dist/cjs/utils/logger.js.map +1 -1
- package/dist/esm/cli/lemma-proxy.d.ts.map +1 -1
- package/dist/esm/cli/lemma-proxy.js +187 -98
- package/dist/esm/cli/lemma-proxy.js.map +1 -1
- package/dist/esm/config/index.d.ts.map +1 -1
- package/dist/esm/config/index.js +2 -1
- package/dist/esm/config/index.js.map +1 -1
- package/dist/esm/errors/LemmaError.d.ts +52 -0
- package/dist/esm/errors/LemmaError.d.ts.map +1 -0
- package/dist/esm/errors/LemmaError.js +75 -0
- package/dist/esm/errors/LemmaError.js.map +1 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +24 -22
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/subconscious/SemanticCache.d.ts +4 -4
- package/dist/esm/subconscious/SemanticCache.d.ts.map +1 -1
- package/dist/esm/subconscious/SemanticCache.js +14 -10
- package/dist/esm/subconscious/SemanticCache.js.map +1 -1
- package/dist/esm/types/index.d.ts +8 -8
- package/dist/esm/types/index.d.ts.map +1 -1
- package/dist/esm/utils/logger.d.ts +27 -6
- package/dist/esm/utils/logger.d.ts.map +1 -1
- package/dist/esm/utils/logger.js +93 -28
- package/dist/esm/utils/logger.js.map +1 -1
- package/package.json +27 -24
package/dist/esm/index.js
CHANGED
|
@@ -8,6 +8,7 @@ import { WebSocketServer } from './core/WebSocketServer';
|
|
|
8
8
|
import { AgentRegistry } from './core/AgentRegistry';
|
|
9
9
|
import { Router } from './core/router';
|
|
10
10
|
import { IdeContextSync } from './observability/IdeContextSync';
|
|
11
|
+
import { logger } from './utils/logger';
|
|
11
12
|
/**
|
|
12
13
|
* Subconscious Router Hub
|
|
13
14
|
* Orchestrates WebSocket connections, agent registry, and message routing
|
|
@@ -28,30 +29,30 @@ export class SubconsciousHub {
|
|
|
28
29
|
setupEventHandlers() {
|
|
29
30
|
// WebSocket events
|
|
30
31
|
this.wsServer.on('ready', () => {
|
|
31
|
-
|
|
32
|
+
logger.info('WebSocket server ready');
|
|
32
33
|
});
|
|
33
34
|
this.wsServer.on('error', (error) => {
|
|
34
|
-
|
|
35
|
+
logger.error('WebSocket server error', error);
|
|
35
36
|
});
|
|
36
37
|
// Agent registry events
|
|
37
38
|
this.agentRegistry.on('agentRegistered', (agent) => {
|
|
38
|
-
|
|
39
|
+
logger.info(`Agent registered: ${agent.agentId}`);
|
|
39
40
|
});
|
|
40
41
|
this.agentRegistry.on('agentUnregistered', (agent) => {
|
|
41
|
-
|
|
42
|
+
logger.info(`Agent unregistered: ${agent.agentId}`);
|
|
42
43
|
});
|
|
43
44
|
this.agentRegistry.on('agentReconnected', (agent) => {
|
|
44
|
-
|
|
45
|
+
logger.info(`Agent reconnected: ${agent.agentId}`);
|
|
45
46
|
});
|
|
46
47
|
// Router events
|
|
47
48
|
this.router.on('taskRouted', ({ taskId, routingDecision }) => {
|
|
48
|
-
|
|
49
|
+
logger.info(`Task ${taskId} routed to ${routingDecision.selectedAgent?.agentId}`);
|
|
49
50
|
});
|
|
50
51
|
this.router.on('taskCompleted', ({ taskId, responseTime }) => {
|
|
51
|
-
|
|
52
|
+
logger.info(`Task ${taskId} completed in ${responseTime}ms`);
|
|
52
53
|
});
|
|
53
54
|
this.router.on('taskFailed', ({ taskId, reason }) => {
|
|
54
|
-
|
|
55
|
+
logger.error(`Task ${taskId} failed: ${reason}`);
|
|
55
56
|
this.ideContextSync.intercept({
|
|
56
57
|
type: 'agent_failure',
|
|
57
58
|
message: `Task ${taskId} failed: ${reason}`,
|
|
@@ -67,17 +68,18 @@ export class SubconsciousHub {
|
|
|
67
68
|
timestamp: new Date().toISOString(),
|
|
68
69
|
stackTrace: error.stack,
|
|
69
70
|
}).finally(() => {
|
|
70
|
-
|
|
71
|
+
logger.error('Uncaught Exception', error);
|
|
71
72
|
});
|
|
72
73
|
});
|
|
73
74
|
process.on('unhandledRejection', (reason, promise) => {
|
|
75
|
+
const error = reason instanceof Error ? reason : new Error(String(reason));
|
|
74
76
|
this.ideContextSync.intercept({
|
|
75
77
|
type: 'unhandled_rejection',
|
|
76
|
-
message:
|
|
78
|
+
message: error.message,
|
|
77
79
|
timestamp: new Date().toISOString(),
|
|
78
|
-
stackTrace:
|
|
80
|
+
stackTrace: error.stack,
|
|
79
81
|
}).finally(() => {
|
|
80
|
-
|
|
82
|
+
logger.error('Unhandled Rejection at Promise', error);
|
|
81
83
|
});
|
|
82
84
|
});
|
|
83
85
|
}
|
|
@@ -88,10 +90,10 @@ export class SubconsciousHub {
|
|
|
88
90
|
if (this.isRunning) {
|
|
89
91
|
throw new Error('Hub is already running');
|
|
90
92
|
}
|
|
91
|
-
|
|
93
|
+
logger.info('Starting Subconscious Router Hub...');
|
|
92
94
|
await this.wsServer.start();
|
|
93
95
|
this.isRunning = true;
|
|
94
|
-
|
|
96
|
+
logger.info('Hub is running');
|
|
95
97
|
this.printStatus();
|
|
96
98
|
}
|
|
97
99
|
/**
|
|
@@ -101,12 +103,12 @@ export class SubconsciousHub {
|
|
|
101
103
|
if (!this.isRunning) {
|
|
102
104
|
return;
|
|
103
105
|
}
|
|
104
|
-
|
|
106
|
+
logger.info('Stopping Subconscious Router Hub...');
|
|
105
107
|
this.router.stop();
|
|
106
108
|
this.agentRegistry.stop();
|
|
107
109
|
await this.wsServer.stop();
|
|
108
110
|
this.isRunning = false;
|
|
109
|
-
|
|
111
|
+
logger.info('Hub stopped');
|
|
110
112
|
}
|
|
111
113
|
/**
|
|
112
114
|
* Get hub statistics
|
|
@@ -119,12 +121,12 @@ export class SubconsciousHub {
|
|
|
119
121
|
*/
|
|
120
122
|
printStatus() {
|
|
121
123
|
const stats = this.getStats();
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
124
|
+
logger.info('Hub Status', {
|
|
125
|
+
activeConnections: stats.connectionStats.activeConnections,
|
|
126
|
+
onlineAgents: stats.agentStats.onlineAgents,
|
|
127
|
+
pendingTasks: stats.pendingTasks,
|
|
128
|
+
totalTasksCompleted: stats.agentStats.totalTasksCompleted
|
|
129
|
+
});
|
|
128
130
|
}
|
|
129
131
|
/**
|
|
130
132
|
* Get WebSocket server instance
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,OAAO,EAAE,cAAc,EAAE,MAAM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1D,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACI,kBAAkB;QACvB,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED;;OAEG;IACI,gBAAgB;QACrB,OAAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;IAED;;OAEG;IACI,SAAS;QACd,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF;AAED,uCAAuC;AACvC,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,YAAY,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,WAAW,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAErE,6CAA6C;AAC7C,OAAO,EAAE,KAAK,EAA0C,MAAM,SAAS,CAAC;AAExE,sCAAsC;AACtC,eAAe,eAAe,CAAC"}
|
|
@@ -3,9 +3,9 @@ import { EmbeddingService } from './EmbeddingService';
|
|
|
3
3
|
/**
|
|
4
4
|
* Result of a cache lookup operation.
|
|
5
5
|
*/
|
|
6
|
-
export interface CacheResult {
|
|
6
|
+
export interface CacheResult<T = any> {
|
|
7
7
|
hit: boolean;
|
|
8
|
-
result?:
|
|
8
|
+
result?: T;
|
|
9
9
|
similarity?: number;
|
|
10
10
|
taskId?: string;
|
|
11
11
|
latencyMs: number;
|
|
@@ -28,7 +28,7 @@ export declare class SemanticCache {
|
|
|
28
28
|
* @param taskDescription - Description of the task to check
|
|
29
29
|
* @returns CacheResult with hit status and cached data if found
|
|
30
30
|
*/
|
|
31
|
-
check(taskDescription: string): Promise<CacheResult
|
|
31
|
+
check<T = any>(taskDescription: string): Promise<CacheResult<T>>;
|
|
32
32
|
/**
|
|
33
33
|
* Store a task result in the cache for future lookups.
|
|
34
34
|
*
|
|
@@ -37,7 +37,7 @@ export declare class SemanticCache {
|
|
|
37
37
|
* @param result - Result to cache
|
|
38
38
|
* @param metadata - Additional metadata to store
|
|
39
39
|
*/
|
|
40
|
-
store(taskId: string, taskDescription: string, result:
|
|
40
|
+
store<T = any>(taskId: string, taskDescription: string, result: T, metadata?: Record<string, any>): Promise<void>;
|
|
41
41
|
/**
|
|
42
42
|
* Calculate cosine similarity between two task descriptions.
|
|
43
43
|
* Useful for debugging and testing.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SemanticCache.d.ts","sourceRoot":"","sources":["../../../src/subconscious/SemanticCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"SemanticCache.d.ts","sourceRoot":"","sources":["../../../src/subconscious/SemanticCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAKtD;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,GAAG;IAClC,GAAG,EAAE,OAAO,CAAC;IACb,MAAM,CAAC,EAAE,CAAC,CAAC;IACX,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,gBAAgB,CAAmB;IAC3C,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,SAAS,CAAa;IAC9B,OAAO,CAAC,WAAW,CAAa;gBAG9B,WAAW,EAAE,WAAW,EACxB,gBAAgB,EAAE,gBAAgB,EAClC,SAAS,GAAE,MAAa;IAO1B;;;;;;OAMG;IACG,KAAK,CAAC,CAAC,GAAG,GAAG,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAwDtE;;;;;;;OAOG;IACG,KAAK,CAAC,CAAC,GAAG,GAAG,EACjB,MAAM,EAAE,MAAM,EACd,eAAe,EAAE,MAAM,EACvB,MAAM,EAAE,CAAC,EACT,QAAQ,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,GACjC,OAAO,CAAC,IAAI,CAAC;IAqBhB;;;;;;;OAOG;IACG,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAcxE;;OAEG;IACH,UAAU,IAAI;QACZ,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,MAAM,CAAC;QACf,KAAK,EAAE,MAAM,CAAC;QACd,OAAO,EAAE,MAAM,CAAC;KACjB;IAYD;;OAEG;IACH,YAAY,IAAI,IAAI;IAMpB;;;;OAIG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAQrC;;OAEG;IACH,YAAY,IAAI,MAAM;IAItB;;OAEG;IACG,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC;IAIrC;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAK7B"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { EmbeddingService } from './EmbeddingService';
|
|
2
|
+
import { createLogger } from '../utils/logger';
|
|
3
|
+
const logger = createLogger('SemanticCache');
|
|
2
4
|
/**
|
|
3
5
|
* SemanticCache implements the "short-circuit" logic for semantic caching.
|
|
4
6
|
* It checks if a similar task has been resolved before and returns cached results.
|
|
@@ -31,8 +33,10 @@ export class SemanticCache {
|
|
|
31
33
|
// Cache hit!
|
|
32
34
|
this.cacheHits++;
|
|
33
35
|
const match = matches[0];
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
logger.info('Cache hit', {
|
|
37
|
+
similarity: match.similarity,
|
|
38
|
+
latencyMs,
|
|
39
|
+
});
|
|
36
40
|
return {
|
|
37
41
|
hit: true,
|
|
38
42
|
result: match.result,
|
|
@@ -44,7 +48,7 @@ export class SemanticCache {
|
|
|
44
48
|
else {
|
|
45
49
|
// Cache miss
|
|
46
50
|
this.cacheMisses++;
|
|
47
|
-
|
|
51
|
+
logger.info('Cache miss', { latencyMs });
|
|
48
52
|
return {
|
|
49
53
|
hit: false,
|
|
50
54
|
latencyMs,
|
|
@@ -52,7 +56,7 @@ export class SemanticCache {
|
|
|
52
56
|
}
|
|
53
57
|
}
|
|
54
58
|
catch (error) {
|
|
55
|
-
|
|
59
|
+
logger.error('Error during cache check', error);
|
|
56
60
|
// On error, treat as cache miss
|
|
57
61
|
this.cacheMisses++;
|
|
58
62
|
return {
|
|
@@ -75,10 +79,10 @@ export class SemanticCache {
|
|
|
75
79
|
const embedding = await this.embeddingService.generateEmbedding(taskDescription);
|
|
76
80
|
// Store in vector database
|
|
77
81
|
await this.vectorStore.insertVector(taskId, embedding, taskDescription, result, metadata);
|
|
78
|
-
|
|
82
|
+
logger.info('Result stored in cache', { taskId });
|
|
79
83
|
}
|
|
80
84
|
catch (error) {
|
|
81
|
-
|
|
85
|
+
logger.error('Error storing result', error);
|
|
82
86
|
throw error;
|
|
83
87
|
}
|
|
84
88
|
}
|
|
@@ -99,7 +103,7 @@ export class SemanticCache {
|
|
|
99
103
|
return EmbeddingService.cosineSimilarity(embeddingA, embeddingB);
|
|
100
104
|
}
|
|
101
105
|
catch (error) {
|
|
102
|
-
|
|
106
|
+
logger.error('Error calculating similarity', error);
|
|
103
107
|
throw error;
|
|
104
108
|
}
|
|
105
109
|
}
|
|
@@ -122,7 +126,7 @@ export class SemanticCache {
|
|
|
122
126
|
resetMetrics() {
|
|
123
127
|
this.cacheHits = 0;
|
|
124
128
|
this.cacheMisses = 0;
|
|
125
|
-
|
|
129
|
+
logger.info('Metrics reset');
|
|
126
130
|
}
|
|
127
131
|
/**
|
|
128
132
|
* Update the similarity threshold.
|
|
@@ -134,7 +138,7 @@ export class SemanticCache {
|
|
|
134
138
|
throw new Error('Threshold must be between 0 and 1');
|
|
135
139
|
}
|
|
136
140
|
this.threshold = threshold;
|
|
137
|
-
|
|
141
|
+
logger.info(`Threshold updated to ${threshold}`);
|
|
138
142
|
}
|
|
139
143
|
/**
|
|
140
144
|
* Get the current similarity threshold.
|
|
@@ -154,7 +158,7 @@ export class SemanticCache {
|
|
|
154
158
|
async clear() {
|
|
155
159
|
await this.vectorStore.clear();
|
|
156
160
|
this.resetMetrics();
|
|
157
|
-
|
|
161
|
+
logger.info('Cache cleared');
|
|
158
162
|
}
|
|
159
163
|
}
|
|
160
164
|
//# sourceMappingURL=SemanticCache.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SemanticCache.js","sourceRoot":"","sources":["../../../src/subconscious/SemanticCache.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"SemanticCache.js","sourceRoot":"","sources":["../../../src/subconscious/SemanticCache.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,MAAM,MAAM,GAAG,YAAY,CAAC,eAAe,CAAC,CAAC;AAa7C;;;GAGG;AACH,MAAM,OAAO,aAAa;IAOxB,YACE,WAAwB,EACxB,gBAAkC,EAClC,YAAoB,IAAI;QANlB,cAAS,GAAW,CAAC,CAAC;QACtB,gBAAW,GAAW,CAAC,CAAC;QAO9B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;QACzC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED;;;;;;OAMG;IACH,KAA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AAW,CAAC;QAChD,MAAM,OAAO,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAEvD,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,SAAS;YACpB,MAAM,EAAE,IAAI,CAAC,WAAW;YACxB,KAAK;YACL,OAAO;SACR,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,YAAY;QACV,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC;QACnB,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC;QACrB,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IAC/B,CAAC;IAED;;;;OAIG;IACH,YAAY,CAAC,SAAiB;QAC5B,IAAI,SAAS,GAAG,CAAC,IAAI,SAAS,GAAG,CAAC,EAAE,CAAC;YACnC,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;QACvD,CAAC;QACD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,MAAM,CAAC,IAAI,CAAC,wBAAwB,SAAS,EAAE,CAAC,CAAC;IACnD,CAAC;IAED;;OAEG;IACH,YAAY;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,YAAY;QAChB,OAAO,MAAM,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC;IAC3C,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAK;QACT,MAAM,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;QAC/B,IAAI,CAAC,YAAY,EAAE,CAAC;QACpB,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IAC/B,CAAC;CACF"}
|
|
@@ -116,12 +116,12 @@ export declare enum IAPMessageType {
|
|
|
116
116
|
/**
|
|
117
117
|
* Base I.A.P. Message Structure
|
|
118
118
|
*/
|
|
119
|
-
export interface IAPMessage {
|
|
119
|
+
export interface IAPMessage<T = any> {
|
|
120
120
|
type: IAPMessageType;
|
|
121
121
|
id?: string;
|
|
122
122
|
messageId?: string;
|
|
123
123
|
timestamp: number;
|
|
124
|
-
payload:
|
|
124
|
+
payload: T;
|
|
125
125
|
}
|
|
126
126
|
/**
|
|
127
127
|
* Task Request Payload
|
|
@@ -139,10 +139,10 @@ export interface TaskRequest {
|
|
|
139
139
|
/**
|
|
140
140
|
* Task Response Payload
|
|
141
141
|
*/
|
|
142
|
-
export interface TaskResponse {
|
|
142
|
+
export interface TaskResponse<R = any> {
|
|
143
143
|
taskId: string;
|
|
144
144
|
success: boolean;
|
|
145
|
-
result?:
|
|
145
|
+
result?: R;
|
|
146
146
|
error?: string;
|
|
147
147
|
executionTime?: number;
|
|
148
148
|
tokensUsed?: number;
|
|
@@ -180,11 +180,11 @@ export interface ErrorPayload {
|
|
|
180
180
|
/**
|
|
181
181
|
* Cache Entry for Semantic Cache
|
|
182
182
|
*/
|
|
183
|
-
export interface CacheEntry {
|
|
183
|
+
export interface CacheEntry<T = any> {
|
|
184
184
|
id: string;
|
|
185
185
|
query: string;
|
|
186
186
|
embedding: number[];
|
|
187
|
-
response:
|
|
187
|
+
response: T;
|
|
188
188
|
metadata: {
|
|
189
189
|
agentId: string;
|
|
190
190
|
timestamp: number;
|
|
@@ -247,10 +247,10 @@ export declare const MessageType: typeof IAPMessageType;
|
|
|
247
247
|
/**
|
|
248
248
|
* Semantic Match Result
|
|
249
249
|
*/
|
|
250
|
-
export interface SemanticMatch {
|
|
250
|
+
export interface SemanticMatch<T = any> {
|
|
251
251
|
id: string;
|
|
252
252
|
similarity: number;
|
|
253
|
-
response:
|
|
253
|
+
response: T;
|
|
254
254
|
metadata: {
|
|
255
255
|
agentId: string;
|
|
256
256
|
timestamp: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,IAAI,CAA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ACpB,YAAY,EAAE,MAAM,CAAC;IACrB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,OAAO,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAElB,YAAY,EAAE,OAAO,CAAC;IACtB,oBAAoB,EAAE,OAAO,CAAC;IAC9B,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAC/B,kBAAkB,EAAE,OAAO,CAAC;IAC5B,8BAA8B,EAAE,MAAM,CAAC;IACvC,4BAA4B,EAAE,MAAM,CAAC;IACrC,yBAAyB,EAAE,MAAM,CAAC;IAClC,oBAAoB,EAAE,OAAO,CAAC;IAC9B,8BAA8B,EAAE,MAAM,CAAC;IACvC,6BAA6B,EAAE,MAAM,CAAC;IACtC,6BAA6B,EAAE,MAAM,CAAC;IAGtC,gBAAgB,EAAE,OAAO,CAAC;IAC1B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,aAAa,EAAE,MAAM,CAAC;CACvB"}
|
|
@@ -8,24 +8,45 @@ export declare enum LogLevel {
|
|
|
8
8
|
DEBUG = 3
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Structured Logger Entry Schema
|
|
12
|
+
*/
|
|
13
|
+
export interface LogEntry {
|
|
14
|
+
timestamp: string;
|
|
15
|
+
level: string;
|
|
16
|
+
context: string;
|
|
17
|
+
message: string;
|
|
18
|
+
meta?: any;
|
|
19
|
+
error?: {
|
|
20
|
+
message: string;
|
|
21
|
+
stack?: string;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Enterprise Structured Logger supporting standard console and file output streams.
|
|
12
26
|
*/
|
|
13
27
|
declare class Logger {
|
|
14
28
|
private level;
|
|
15
29
|
private context;
|
|
30
|
+
private format;
|
|
31
|
+
private logFilePath;
|
|
32
|
+
private disableConsole;
|
|
16
33
|
constructor(context?: string);
|
|
17
34
|
/**
|
|
18
35
|
* Parse log level from string
|
|
19
36
|
*/
|
|
20
37
|
private parseLogLevel;
|
|
21
38
|
/**
|
|
22
|
-
* Format
|
|
39
|
+
* Format text log line with color
|
|
23
40
|
*/
|
|
24
|
-
private
|
|
41
|
+
private formatText;
|
|
25
42
|
/**
|
|
26
|
-
*
|
|
43
|
+
* Safe file appending utility
|
|
27
44
|
*/
|
|
28
|
-
private
|
|
45
|
+
private appendToFile;
|
|
46
|
+
/**
|
|
47
|
+
* Unified writer for standard and file streams
|
|
48
|
+
*/
|
|
49
|
+
private log;
|
|
29
50
|
/**
|
|
30
51
|
* Log error message
|
|
31
52
|
*/
|
|
@@ -47,7 +68,7 @@ declare class Logger {
|
|
|
47
68
|
*/
|
|
48
69
|
metric(name: string, value: number, unit?: string): void;
|
|
49
70
|
/**
|
|
50
|
-
* Create child logger with
|
|
71
|
+
* Create child logger with parent context chaining
|
|
51
72
|
*/
|
|
52
73
|
child(context: string): Logger;
|
|
53
74
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/utils/logger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/utils/logger.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,oBAAY,QAAQ;IAClB,KAAK,IAAI;IACT,IAAI,IAAI;IACR,IAAI,IAAI;IACR,KAAK,IAAI;CACV;AAcD;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,KAAK,CAAC,EAAE;QACN,OAAO,EAAE,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;CACH;AAED;;GAEG;AACH,cAAM,MAAM;IACV,OAAO,CAAC,KAAK,CAAW;IACxB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,WAAW,CAAuB;IAC1C,OAAO,CAAC,cAAc,CAAkB;gBAE5B,OAAO,GAAE,MAAc;IAsBnC;;OAEG;IACH,OAAO,CAAC,aAAa;IAerB;;OAEG;IACH,OAAO,CAAC,UAAU;IAKlB;;OAEG;IACH,OAAO,CAAC,YAAY;IAWpB;;OAEG;IACH,OAAO,CAAC,GAAG;IAkDX;;OAEG;IACI,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,GAAG,GAAG,GAAG,IAAI;IAIxD;;OAEG;IACI,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI;IAI9C;;OAEG;IACI,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI;IAI9C;;OAEG;IACI,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI;IAI/C;;OAEG;IACI,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,GAAE,MAAa,GAAG,IAAI;IAKrE;;OAEG;IACI,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;CAGtC;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,OAAO,GAAE,MAAc,GAAG,MAAM,CAE5D;AAED;;GAEG;AACH,eAAO,MAAM,MAAM,QAAqC,CAAC"}
|
package/dist/esm/utils/logger.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
1
3
|
import { config } from '../config';
|
|
2
4
|
/**
|
|
3
5
|
* Log levels
|
|
@@ -21,12 +23,29 @@ const colors = {
|
|
|
21
23
|
gray: '\x1b[90m',
|
|
22
24
|
};
|
|
23
25
|
/**
|
|
24
|
-
*
|
|
26
|
+
* Enterprise Structured Logger supporting standard console and file output streams.
|
|
25
27
|
*/
|
|
26
28
|
class Logger {
|
|
27
29
|
constructor(context = 'App') {
|
|
30
|
+
this.logFilePath = null;
|
|
31
|
+
this.disableConsole = false;
|
|
28
32
|
this.context = context;
|
|
29
|
-
|
|
33
|
+
// Resolve runtime settings dynamically
|
|
34
|
+
const rawLevel = process.env.LEMMA_LOG_LEVEL || process.env.LOG_LEVEL || config?.logLevel || 'info';
|
|
35
|
+
this.level = this.parseLogLevel(rawLevel);
|
|
36
|
+
this.format = (process.env.LEMMA_LOG_FORMAT || process.env.LOG_FORMAT || 'text').toLowerCase() === 'json' ? 'json' : 'text';
|
|
37
|
+
this.logFilePath = process.env.LEMMA_LOG_FILE || process.env.LOG_FILE || null;
|
|
38
|
+
this.disableConsole = (process.env.LEMMA_LOG_DISABLE_CONSOLE || 'false').toLowerCase() === 'true';
|
|
39
|
+
// Proactively construct base directory for log files if specified
|
|
40
|
+
if (this.logFilePath) {
|
|
41
|
+
try {
|
|
42
|
+
const dir = path.dirname(path.resolve(this.logFilePath));
|
|
43
|
+
if (!fs.existsSync(dir)) {
|
|
44
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
catch { }
|
|
48
|
+
}
|
|
30
49
|
}
|
|
31
50
|
/**
|
|
32
51
|
* Parse log level from string
|
|
@@ -46,64 +65,110 @@ class Logger {
|
|
|
46
65
|
}
|
|
47
66
|
}
|
|
48
67
|
/**
|
|
49
|
-
* Format
|
|
68
|
+
* Format text log line with color
|
|
50
69
|
*/
|
|
51
|
-
|
|
52
|
-
|
|
70
|
+
formatText(level, message, metaStr, colorCode) {
|
|
71
|
+
const timestamp = new Date().toISOString();
|
|
72
|
+
return `${colorCode}[${timestamp}] [${level}] [${this.context}] ${message}${metaStr}${colors.reset}`;
|
|
53
73
|
}
|
|
54
74
|
/**
|
|
55
|
-
*
|
|
75
|
+
* Safe file appending utility
|
|
56
76
|
*/
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
77
|
+
appendToFile(entry) {
|
|
78
|
+
if (!this.logFilePath)
|
|
79
|
+
return;
|
|
80
|
+
try {
|
|
81
|
+
const line = this.format === 'json'
|
|
82
|
+
? JSON.stringify(entry)
|
|
83
|
+
: `[${entry.timestamp}] [${entry.level}] [${entry.context}] ${entry.message}${entry.meta ? ' ' + JSON.stringify(entry.meta) : ''}${entry.error ? ' error: ' + entry.error.message + '\n' + (entry.error.stack || '') : ''}`;
|
|
84
|
+
fs.appendFileSync(this.logFilePath, line + '\n', 'utf8');
|
|
85
|
+
}
|
|
86
|
+
catch { }
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Unified writer for standard and file streams
|
|
90
|
+
*/
|
|
91
|
+
log(levelStr, levelVal, message, colorCode, meta, errObj) {
|
|
92
|
+
if (levelVal > this.level)
|
|
93
|
+
return;
|
|
94
|
+
const timestamp = new Date().toISOString();
|
|
95
|
+
const entry = {
|
|
96
|
+
timestamp,
|
|
97
|
+
level: levelStr,
|
|
98
|
+
context: this.context,
|
|
99
|
+
message,
|
|
100
|
+
};
|
|
101
|
+
if (meta !== undefined) {
|
|
102
|
+
entry.meta = meta;
|
|
103
|
+
}
|
|
104
|
+
if (errObj) {
|
|
105
|
+
entry.error = {
|
|
106
|
+
message: errObj instanceof Error ? errObj.message : String(errObj),
|
|
107
|
+
stack: errObj instanceof Error ? errObj.stack : undefined,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
// Output to Console
|
|
111
|
+
if (!this.disableConsole) {
|
|
112
|
+
if (this.format === 'json') {
|
|
113
|
+
const jsonLine = JSON.stringify(entry);
|
|
114
|
+
if (levelVal === LogLevel.ERROR) {
|
|
115
|
+
console.error(jsonLine);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
console.log(jsonLine);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
const metaStr = meta ? ` ${JSON.stringify(meta)}` : '';
|
|
123
|
+
const colorLine = this.formatText(levelStr, message, metaStr, colorCode);
|
|
124
|
+
if (levelVal === LogLevel.ERROR) {
|
|
125
|
+
console.error(colorLine);
|
|
126
|
+
if (errObj && errObj.stack) {
|
|
127
|
+
console.error(`${colors.red}${errObj.stack}${colors.reset}`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
console.log(colorLine);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// Write to File Sink
|
|
136
|
+
this.appendToFile(entry);
|
|
61
137
|
}
|
|
62
138
|
/**
|
|
63
139
|
* Log error message
|
|
64
140
|
*/
|
|
65
141
|
error(message, error) {
|
|
66
|
-
|
|
67
|
-
return;
|
|
68
|
-
const meta = error instanceof Error
|
|
69
|
-
? { error: error.message, stack: error.stack }
|
|
70
|
-
: error;
|
|
71
|
-
console.error(`${colors.red}${this.format('ERROR', message, meta)}${colors.reset}`);
|
|
142
|
+
this.log('ERROR', LogLevel.ERROR, message, colors.red, undefined, error);
|
|
72
143
|
}
|
|
73
144
|
/**
|
|
74
145
|
* Log warning message
|
|
75
146
|
*/
|
|
76
147
|
warn(message, meta) {
|
|
77
|
-
|
|
78
|
-
return;
|
|
79
|
-
console.warn(`${colors.yellow}${this.format('WARN', message, meta)}${colors.reset}`);
|
|
148
|
+
this.log('WARN', LogLevel.WARN, message, colors.yellow, meta);
|
|
80
149
|
}
|
|
81
150
|
/**
|
|
82
151
|
* Log info message
|
|
83
152
|
*/
|
|
84
153
|
info(message, meta) {
|
|
85
|
-
|
|
86
|
-
return;
|
|
87
|
-
console.log(`${colors.blue}${this.format('INFO', message, meta)}${colors.reset}`);
|
|
154
|
+
this.log('INFO', LogLevel.INFO, message, colors.blue, meta);
|
|
88
155
|
}
|
|
89
156
|
/**
|
|
90
157
|
* Log debug message
|
|
91
158
|
*/
|
|
92
159
|
debug(message, meta) {
|
|
93
|
-
|
|
94
|
-
return;
|
|
95
|
-
console.log(`${colors.gray}${this.format('DEBUG', message, meta)}${colors.reset}`);
|
|
160
|
+
this.log('DEBUG', LogLevel.DEBUG, message, colors.gray, meta);
|
|
96
161
|
}
|
|
97
162
|
/**
|
|
98
163
|
* Log performance metric
|
|
99
164
|
*/
|
|
100
165
|
metric(name, value, unit = 'ms') {
|
|
101
|
-
if (
|
|
166
|
+
if (LogLevel.INFO > this.level)
|
|
102
167
|
return;
|
|
103
|
-
|
|
168
|
+
this.log('METRIC', LogLevel.INFO, `${name}: ${value}${unit}`, colors.cyan);
|
|
104
169
|
}
|
|
105
170
|
/**
|
|
106
|
-
* Create child logger with
|
|
171
|
+
* Create child logger with parent context chaining
|
|
107
172
|
*/
|
|
108
173
|
child(context) {
|
|
109
174
|
return new Logger(`${this.context}:${context}`);
|