@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/cjs/index.js
CHANGED
|
@@ -47,6 +47,7 @@ const WebSocketServer_1 = require("./core/WebSocketServer");
|
|
|
47
47
|
const AgentRegistry_1 = require("./core/AgentRegistry");
|
|
48
48
|
const router_1 = require("./core/router");
|
|
49
49
|
const IdeContextSync_1 = require("./observability/IdeContextSync");
|
|
50
|
+
const logger_1 = require("./utils/logger");
|
|
50
51
|
/**
|
|
51
52
|
* Subconscious Router Hub
|
|
52
53
|
* Orchestrates WebSocket connections, agent registry, and message routing
|
|
@@ -67,30 +68,30 @@ class SubconsciousHub {
|
|
|
67
68
|
setupEventHandlers() {
|
|
68
69
|
// WebSocket events
|
|
69
70
|
this.wsServer.on('ready', () => {
|
|
70
|
-
|
|
71
|
+
logger_1.logger.info('WebSocket server ready');
|
|
71
72
|
});
|
|
72
73
|
this.wsServer.on('error', (error) => {
|
|
73
|
-
|
|
74
|
+
logger_1.logger.error('WebSocket server error', error);
|
|
74
75
|
});
|
|
75
76
|
// Agent registry events
|
|
76
77
|
this.agentRegistry.on('agentRegistered', (agent) => {
|
|
77
|
-
|
|
78
|
+
logger_1.logger.info(`Agent registered: ${agent.agentId}`);
|
|
78
79
|
});
|
|
79
80
|
this.agentRegistry.on('agentUnregistered', (agent) => {
|
|
80
|
-
|
|
81
|
+
logger_1.logger.info(`Agent unregistered: ${agent.agentId}`);
|
|
81
82
|
});
|
|
82
83
|
this.agentRegistry.on('agentReconnected', (agent) => {
|
|
83
|
-
|
|
84
|
+
logger_1.logger.info(`Agent reconnected: ${agent.agentId}`);
|
|
84
85
|
});
|
|
85
86
|
// Router events
|
|
86
87
|
this.router.on('taskRouted', ({ taskId, routingDecision }) => {
|
|
87
|
-
|
|
88
|
+
logger_1.logger.info(`Task ${taskId} routed to ${routingDecision.selectedAgent?.agentId}`);
|
|
88
89
|
});
|
|
89
90
|
this.router.on('taskCompleted', ({ taskId, responseTime }) => {
|
|
90
|
-
|
|
91
|
+
logger_1.logger.info(`Task ${taskId} completed in ${responseTime}ms`);
|
|
91
92
|
});
|
|
92
93
|
this.router.on('taskFailed', ({ taskId, reason }) => {
|
|
93
|
-
|
|
94
|
+
logger_1.logger.error(`Task ${taskId} failed: ${reason}`);
|
|
94
95
|
this.ideContextSync.intercept({
|
|
95
96
|
type: 'agent_failure',
|
|
96
97
|
message: `Task ${taskId} failed: ${reason}`,
|
|
@@ -106,17 +107,18 @@ class SubconsciousHub {
|
|
|
106
107
|
timestamp: new Date().toISOString(),
|
|
107
108
|
stackTrace: error.stack,
|
|
108
109
|
}).finally(() => {
|
|
109
|
-
|
|
110
|
+
logger_1.logger.error('Uncaught Exception', error);
|
|
110
111
|
});
|
|
111
112
|
});
|
|
112
113
|
process.on('unhandledRejection', (reason, promise) => {
|
|
114
|
+
const error = reason instanceof Error ? reason : new Error(String(reason));
|
|
113
115
|
this.ideContextSync.intercept({
|
|
114
116
|
type: 'unhandled_rejection',
|
|
115
|
-
message:
|
|
117
|
+
message: error.message,
|
|
116
118
|
timestamp: new Date().toISOString(),
|
|
117
|
-
stackTrace:
|
|
119
|
+
stackTrace: error.stack,
|
|
118
120
|
}).finally(() => {
|
|
119
|
-
|
|
121
|
+
logger_1.logger.error('Unhandled Rejection at Promise', error);
|
|
120
122
|
});
|
|
121
123
|
});
|
|
122
124
|
}
|
|
@@ -127,10 +129,10 @@ class SubconsciousHub {
|
|
|
127
129
|
if (this.isRunning) {
|
|
128
130
|
throw new Error('Hub is already running');
|
|
129
131
|
}
|
|
130
|
-
|
|
132
|
+
logger_1.logger.info('Starting Subconscious Router Hub...');
|
|
131
133
|
await this.wsServer.start();
|
|
132
134
|
this.isRunning = true;
|
|
133
|
-
|
|
135
|
+
logger_1.logger.info('Hub is running');
|
|
134
136
|
this.printStatus();
|
|
135
137
|
}
|
|
136
138
|
/**
|
|
@@ -140,12 +142,12 @@ class SubconsciousHub {
|
|
|
140
142
|
if (!this.isRunning) {
|
|
141
143
|
return;
|
|
142
144
|
}
|
|
143
|
-
|
|
145
|
+
logger_1.logger.info('Stopping Subconscious Router Hub...');
|
|
144
146
|
this.router.stop();
|
|
145
147
|
this.agentRegistry.stop();
|
|
146
148
|
await this.wsServer.stop();
|
|
147
149
|
this.isRunning = false;
|
|
148
|
-
|
|
150
|
+
logger_1.logger.info('Hub stopped');
|
|
149
151
|
}
|
|
150
152
|
/**
|
|
151
153
|
* Get hub statistics
|
|
@@ -158,12 +160,12 @@ class SubconsciousHub {
|
|
|
158
160
|
*/
|
|
159
161
|
printStatus() {
|
|
160
162
|
const stats = this.getStats();
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
163
|
+
logger_1.logger.info('Hub Status', {
|
|
164
|
+
activeConnections: stats.connectionStats.activeConnections,
|
|
165
|
+
onlineAgents: stats.agentStats.onlineAgents,
|
|
166
|
+
pendingTasks: stats.pendingTasks,
|
|
167
|
+
totalTasksCompleted: stats.agentStats.totalTasksCompleted
|
|
168
|
+
});
|
|
167
169
|
}
|
|
168
170
|
/**
|
|
169
171
|
* Get WebSocket server instance
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,4DAAyD;AACzD,wDAAqD;AACrD,0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ACrB,OAAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;IAED;;OAEG;IACI,SAAS;QACd,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF;AAtKD,0CAsKC;AAED,uCAAuC;AACvC,0CAAwB;AACxB,yCAAuB;AACvB,6CAA2B;AAC3B,uDAAuC;AACvC,+DAA+C;AAC/C,yDAAyC;AACzC,6DAA6C;AAC7C,mCAAqE;AAA5D,gGAAA,MAAM,OAAA;AAAE,2GAAA,iBAAiB,OAAA;AAAE,wGAAA,cAAc,OAAA;AAElD,6CAA6C;AAC7C,iCAAwE;AAA/D,8FAAA,KAAK,OAAA;AAEd,sCAAsC;AACtC,kBAAe,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"}
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SemanticCache = void 0;
|
|
4
4
|
const EmbeddingService_1 = require("./EmbeddingService");
|
|
5
|
+
const logger_1 = require("../utils/logger");
|
|
6
|
+
const logger = (0, logger_1.createLogger)('SemanticCache');
|
|
5
7
|
/**
|
|
6
8
|
* SemanticCache implements the "short-circuit" logic for semantic caching.
|
|
7
9
|
* It checks if a similar task has been resolved before and returns cached results.
|
|
@@ -34,8 +36,10 @@ class SemanticCache {
|
|
|
34
36
|
// Cache hit!
|
|
35
37
|
this.cacheHits++;
|
|
36
38
|
const match = matches[0];
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
logger.info('Cache hit', {
|
|
40
|
+
similarity: match.similarity,
|
|
41
|
+
latencyMs,
|
|
42
|
+
});
|
|
39
43
|
return {
|
|
40
44
|
hit: true,
|
|
41
45
|
result: match.result,
|
|
@@ -47,7 +51,7 @@ class SemanticCache {
|
|
|
47
51
|
else {
|
|
48
52
|
// Cache miss
|
|
49
53
|
this.cacheMisses++;
|
|
50
|
-
|
|
54
|
+
logger.info('Cache miss', { latencyMs });
|
|
51
55
|
return {
|
|
52
56
|
hit: false,
|
|
53
57
|
latencyMs,
|
|
@@ -55,7 +59,7 @@ class SemanticCache {
|
|
|
55
59
|
}
|
|
56
60
|
}
|
|
57
61
|
catch (error) {
|
|
58
|
-
|
|
62
|
+
logger.error('Error during cache check', error);
|
|
59
63
|
// On error, treat as cache miss
|
|
60
64
|
this.cacheMisses++;
|
|
61
65
|
return {
|
|
@@ -78,10 +82,10 @@ class SemanticCache {
|
|
|
78
82
|
const embedding = await this.embeddingService.generateEmbedding(taskDescription);
|
|
79
83
|
// Store in vector database
|
|
80
84
|
await this.vectorStore.insertVector(taskId, embedding, taskDescription, result, metadata);
|
|
81
|
-
|
|
85
|
+
logger.info('Result stored in cache', { taskId });
|
|
82
86
|
}
|
|
83
87
|
catch (error) {
|
|
84
|
-
|
|
88
|
+
logger.error('Error storing result', error);
|
|
85
89
|
throw error;
|
|
86
90
|
}
|
|
87
91
|
}
|
|
@@ -102,7 +106,7 @@ class SemanticCache {
|
|
|
102
106
|
return EmbeddingService_1.EmbeddingService.cosineSimilarity(embeddingA, embeddingB);
|
|
103
107
|
}
|
|
104
108
|
catch (error) {
|
|
105
|
-
|
|
109
|
+
logger.error('Error calculating similarity', error);
|
|
106
110
|
throw error;
|
|
107
111
|
}
|
|
108
112
|
}
|
|
@@ -125,7 +129,7 @@ class SemanticCache {
|
|
|
125
129
|
resetMetrics() {
|
|
126
130
|
this.cacheHits = 0;
|
|
127
131
|
this.cacheMisses = 0;
|
|
128
|
-
|
|
132
|
+
logger.info('Metrics reset');
|
|
129
133
|
}
|
|
130
134
|
/**
|
|
131
135
|
* Update the similarity threshold.
|
|
@@ -137,7 +141,7 @@ class SemanticCache {
|
|
|
137
141
|
throw new Error('Threshold must be between 0 and 1');
|
|
138
142
|
}
|
|
139
143
|
this.threshold = threshold;
|
|
140
|
-
|
|
144
|
+
logger.info(`Threshold updated to ${threshold}`);
|
|
141
145
|
}
|
|
142
146
|
/**
|
|
143
147
|
* Get the current similarity threshold.
|
|
@@ -157,7 +161,7 @@ class SemanticCache {
|
|
|
157
161
|
async clear() {
|
|
158
162
|
await this.vectorStore.clear();
|
|
159
163
|
this.resetMetrics();
|
|
160
|
-
|
|
164
|
+
logger.info('Cache cleared');
|
|
161
165
|
}
|
|
162
166
|
}
|
|
163
167
|
exports.SemanticCache = SemanticCache;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SemanticCache.js","sourceRoot":"","sources":["../../../src/subconscious/SemanticCache.ts"],"names":[],"mappings":";;;AACA,yDAAsD;
|
|
1
|
+
{"version":3,"file":"SemanticCache.js","sourceRoot":"","sources":["../../../src/subconscious/SemanticCache.ts"],"names":[],"mappings":";;;AACA,yDAAsD;AACtD,4CAA+C;AAE/C,MAAM,MAAM,GAAG,IAAA,qBAAY,EAAC,eAAe,CAAC,CAAC;AAa7C;;;GAGG;AACH,MAAa,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,KAAK,CAAC,KAAK,CAAU,eAAuB;QAC1C,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAE7B,IAAI,CAAC;YACH,kCAAkC;YAClC,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,eAAe,CAAC,CAAC;YAEjF,2BAA2B;YAC3B,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,WAAW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AEG;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;AAxMD,sCAwMC"}
|
|
@@ -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,CAAC;AAE3B;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,cAAc,CAAC,E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,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/cjs/utils/logger.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.logger = exports.LogLevel = void 0;
|
|
4
7
|
exports.createLogger = createLogger;
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
5
10
|
const config_1 = require("../config");
|
|
6
11
|
/**
|
|
7
12
|
* Log levels
|
|
@@ -25,12 +30,29 @@ const colors = {
|
|
|
25
30
|
gray: '\x1b[90m',
|
|
26
31
|
};
|
|
27
32
|
/**
|
|
28
|
-
*
|
|
33
|
+
* Enterprise Structured Logger supporting standard console and file output streams.
|
|
29
34
|
*/
|
|
30
35
|
class Logger {
|
|
31
36
|
constructor(context = 'App') {
|
|
37
|
+
this.logFilePath = null;
|
|
38
|
+
this.disableConsole = false;
|
|
32
39
|
this.context = context;
|
|
33
|
-
|
|
40
|
+
// Resolve runtime settings dynamically
|
|
41
|
+
const rawLevel = process.env.LEMMA_LOG_LEVEL || process.env.LOG_LEVEL || config_1.config?.logLevel || 'info';
|
|
42
|
+
this.level = this.parseLogLevel(rawLevel);
|
|
43
|
+
this.format = (process.env.LEMMA_LOG_FORMAT || process.env.LOG_FORMAT || 'text').toLowerCase() === 'json' ? 'json' : 'text';
|
|
44
|
+
this.logFilePath = process.env.LEMMA_LOG_FILE || process.env.LOG_FILE || null;
|
|
45
|
+
this.disableConsole = (process.env.LEMMA_LOG_DISABLE_CONSOLE || 'false').toLowerCase() === 'true';
|
|
46
|
+
// Proactively construct base directory for log files if specified
|
|
47
|
+
if (this.logFilePath) {
|
|
48
|
+
try {
|
|
49
|
+
const dir = path_1.default.dirname(path_1.default.resolve(this.logFilePath));
|
|
50
|
+
if (!fs_1.default.existsSync(dir)) {
|
|
51
|
+
fs_1.default.mkdirSync(dir, { recursive: true });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
catch { }
|
|
55
|
+
}
|
|
34
56
|
}
|
|
35
57
|
/**
|
|
36
58
|
* Parse log level from string
|
|
@@ -50,64 +72,110 @@ class Logger {
|
|
|
50
72
|
}
|
|
51
73
|
}
|
|
52
74
|
/**
|
|
53
|
-
* Format
|
|
75
|
+
* Format text log line with color
|
|
54
76
|
*/
|
|
55
|
-
|
|
56
|
-
|
|
77
|
+
formatText(level, message, metaStr, colorCode) {
|
|
78
|
+
const timestamp = new Date().toISOString();
|
|
79
|
+
return `${colorCode}[${timestamp}] [${level}] [${this.context}] ${message}${metaStr}${colors.reset}`;
|
|
57
80
|
}
|
|
58
81
|
/**
|
|
59
|
-
*
|
|
82
|
+
* Safe file appending utility
|
|
60
83
|
*/
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
84
|
+
appendToFile(entry) {
|
|
85
|
+
if (!this.logFilePath)
|
|
86
|
+
return;
|
|
87
|
+
try {
|
|
88
|
+
const line = this.format === 'json'
|
|
89
|
+
? JSON.stringify(entry)
|
|
90
|
+
: `[${entry.timestamp}] [${entry.level}] [${entry.context}] ${entry.message}${entry.meta ? ' ' + JSON.stringify(entry.meta) : ''}${entry.error ? ' error: ' + entry.error.message + '\n' + (entry.error.stack || '') : ''}`;
|
|
91
|
+
fs_1.default.appendFileSync(this.logFilePath, line + '\n', 'utf8');
|
|
92
|
+
}
|
|
93
|
+
catch { }
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Unified writer for standard and file streams
|
|
97
|
+
*/
|
|
98
|
+
log(levelStr, levelVal, message, colorCode, meta, errObj) {
|
|
99
|
+
if (levelVal > this.level)
|
|
100
|
+
return;
|
|
101
|
+
const timestamp = new Date().toISOString();
|
|
102
|
+
const entry = {
|
|
103
|
+
timestamp,
|
|
104
|
+
level: levelStr,
|
|
105
|
+
context: this.context,
|
|
106
|
+
message,
|
|
107
|
+
};
|
|
108
|
+
if (meta !== undefined) {
|
|
109
|
+
entry.meta = meta;
|
|
110
|
+
}
|
|
111
|
+
if (errObj) {
|
|
112
|
+
entry.error = {
|
|
113
|
+
message: errObj instanceof Error ? errObj.message : String(errObj),
|
|
114
|
+
stack: errObj instanceof Error ? errObj.stack : undefined,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
// Output to Console
|
|
118
|
+
if (!this.disableConsole) {
|
|
119
|
+
if (this.format === 'json') {
|
|
120
|
+
const jsonLine = JSON.stringify(entry);
|
|
121
|
+
if (levelVal === LogLevel.ERROR) {
|
|
122
|
+
console.error(jsonLine);
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
console.log(jsonLine);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
const metaStr = meta ? ` ${JSON.stringify(meta)}` : '';
|
|
130
|
+
const colorLine = this.formatText(levelStr, message, metaStr, colorCode);
|
|
131
|
+
if (levelVal === LogLevel.ERROR) {
|
|
132
|
+
console.error(colorLine);
|
|
133
|
+
if (errObj && errObj.stack) {
|
|
134
|
+
console.error(`${colors.red}${errObj.stack}${colors.reset}`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
console.log(colorLine);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
// Write to File Sink
|
|
143
|
+
this.appendToFile(entry);
|
|
65
144
|
}
|
|
66
145
|
/**
|
|
67
146
|
* Log error message
|
|
68
147
|
*/
|
|
69
148
|
error(message, error) {
|
|
70
|
-
|
|
71
|
-
return;
|
|
72
|
-
const meta = error instanceof Error
|
|
73
|
-
? { error: error.message, stack: error.stack }
|
|
74
|
-
: error;
|
|
75
|
-
console.error(`${colors.red}${this.format('ERROR', message, meta)}${colors.reset}`);
|
|
149
|
+
this.log('ERROR', LogLevel.ERROR, message, colors.red, undefined, error);
|
|
76
150
|
}
|
|
77
151
|
/**
|
|
78
152
|
* Log warning message
|
|
79
153
|
*/
|
|
80
154
|
warn(message, meta) {
|
|
81
|
-
|
|
82
|
-
return;
|
|
83
|
-
console.warn(`${colors.yellow}${this.format('WARN', message, meta)}${colors.reset}`);
|
|
155
|
+
this.log('WARN', LogLevel.WARN, message, colors.yellow, meta);
|
|
84
156
|
}
|
|
85
157
|
/**
|
|
86
158
|
* Log info message
|
|
87
159
|
*/
|
|
88
160
|
info(message, meta) {
|
|
89
|
-
|
|
90
|
-
return;
|
|
91
|
-
console.log(`${colors.blue}${this.format('INFO', message, meta)}${colors.reset}`);
|
|
161
|
+
this.log('INFO', LogLevel.INFO, message, colors.blue, meta);
|
|
92
162
|
}
|
|
93
163
|
/**
|
|
94
164
|
* Log debug message
|
|
95
165
|
*/
|
|
96
166
|
debug(message, meta) {
|
|
97
|
-
|
|
98
|
-
return;
|
|
99
|
-
console.log(`${colors.gray}${this.format('DEBUG', message, meta)}${colors.reset}`);
|
|
167
|
+
this.log('DEBUG', LogLevel.DEBUG, message, colors.gray, meta);
|
|
100
168
|
}
|
|
101
169
|
/**
|
|
102
170
|
* Log performance metric
|
|
103
171
|
*/
|
|
104
172
|
metric(name, value, unit = 'ms') {
|
|
105
|
-
if (
|
|
173
|
+
if (LogLevel.INFO > this.level)
|
|
106
174
|
return;
|
|
107
|
-
|
|
175
|
+
this.log('METRIC', LogLevel.INFO, `${name}: ${value}${unit}`, colors.cyan);
|
|
108
176
|
}
|
|
109
177
|
/**
|
|
110
|
-
* Create child logger with
|
|
178
|
+
* Create child logger with parent context chaining
|
|
111
179
|
*/
|
|
112
180
|
child(context) {
|
|
113
181
|
return new Logger(`${this.context}:${context}`);
|