@recallbricks/runtime 0.2.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/LICENSE +21 -0
- package/README.md +502 -0
- package/dist/adapters/api/index.d.ts +2 -0
- package/dist/adapters/api/index.d.ts.map +1 -0
- package/dist/adapters/api/index.js +6 -0
- package/dist/adapters/api/index.js.map +1 -0
- package/dist/adapters/api/server.d.ts +13 -0
- package/dist/adapters/api/server.d.ts.map +1 -0
- package/dist/adapters/api/server.js +241 -0
- package/dist/adapters/api/server.js.map +1 -0
- package/dist/adapters/mcp/index.d.ts +2 -0
- package/dist/adapters/mcp/index.d.ts.map +1 -0
- package/dist/adapters/mcp/index.js +6 -0
- package/dist/adapters/mcp/index.js.map +1 -0
- package/dist/adapters/mcp/server.d.ts +27 -0
- package/dist/adapters/mcp/server.d.ts.map +1 -0
- package/dist/adapters/mcp/server.js +227 -0
- package/dist/adapters/mcp/server.js.map +1 -0
- package/dist/adapters/typescript/index.d.ts +4 -0
- package/dist/adapters/typescript/index.d.ts.map +1 -0
- package/dist/adapters/typescript/index.js +24 -0
- package/dist/adapters/typescript/index.js.map +1 -0
- package/dist/api/RecallBricksClient.d.ts +53 -0
- package/dist/api/RecallBricksClient.d.ts.map +1 -0
- package/dist/api/RecallBricksClient.js +129 -0
- package/dist/api/RecallBricksClient.js.map +1 -0
- package/dist/api/TelemetryClient.d.ts +54 -0
- package/dist/api/TelemetryClient.d.ts.map +1 -0
- package/dist/api/TelemetryClient.js +190 -0
- package/dist/api/TelemetryClient.js.map +1 -0
- package/dist/api/index.d.ts +3 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +6 -0
- package/dist/api/index.js.map +1 -0
- package/dist/config/index.d.ts +13 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +206 -0
- package/dist/config/index.js.map +1 -0
- package/dist/core/AgentRuntime.d.ts +45 -0
- package/dist/core/AgentRuntime.d.ts.map +1 -0
- package/dist/core/AgentRuntime.js +328 -0
- package/dist/core/AgentRuntime.js.map +1 -0
- package/dist/core/AutoSaver.d.ts +26 -0
- package/dist/core/AutoSaver.d.ts.map +1 -0
- package/dist/core/AutoSaver.js +162 -0
- package/dist/core/AutoSaver.js.map +1 -0
- package/dist/core/CircuitBreaker.d.ts +64 -0
- package/dist/core/CircuitBreaker.d.ts.map +1 -0
- package/dist/core/CircuitBreaker.js +201 -0
- package/dist/core/CircuitBreaker.js.map +1 -0
- package/dist/core/ContextLoader.d.ts +31 -0
- package/dist/core/ContextLoader.d.ts.map +1 -0
- package/dist/core/ContextLoader.js +236 -0
- package/dist/core/ContextLoader.js.map +1 -0
- package/dist/core/ContextWeaver.d.ts +49 -0
- package/dist/core/ContextWeaver.d.ts.map +1 -0
- package/dist/core/ContextWeaver.js +216 -0
- package/dist/core/ContextWeaver.js.map +1 -0
- package/dist/core/IdentityValidator.d.ts +24 -0
- package/dist/core/IdentityValidator.d.ts.map +1 -0
- package/dist/core/IdentityValidator.js +161 -0
- package/dist/core/IdentityValidator.js.map +1 -0
- package/dist/core/LLMAdapter.d.ts +19 -0
- package/dist/core/LLMAdapter.d.ts.map +1 -0
- package/dist/core/LLMAdapter.js +223 -0
- package/dist/core/LLMAdapter.js.map +1 -0
- package/dist/core/Metrics.d.ts +96 -0
- package/dist/core/Metrics.d.ts.map +1 -0
- package/dist/core/Metrics.js +271 -0
- package/dist/core/Metrics.js.map +1 -0
- package/dist/core/RateLimiter.d.ts +39 -0
- package/dist/core/RateLimiter.d.ts.map +1 -0
- package/dist/core/RateLimiter.js +251 -0
- package/dist/core/RateLimiter.js.map +1 -0
- package/dist/core/ReflectionEngine.d.ts +70 -0
- package/dist/core/ReflectionEngine.d.ts.map +1 -0
- package/dist/core/ReflectionEngine.js +319 -0
- package/dist/core/ReflectionEngine.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +40 -0
- package/dist/index.js.map +1 -0
- package/dist/types/index.d.ts +259 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +38 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +91 -0
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.LLMAdapter = void 0;
|
|
7
|
+
const sdk_1 = __importDefault(require("@anthropic-ai/sdk"));
|
|
8
|
+
const openai_1 = __importDefault(require("openai"));
|
|
9
|
+
const generative_ai_1 = require("@google/generative-ai");
|
|
10
|
+
const types_1 = require("../types");
|
|
11
|
+
class LLMAdapter {
|
|
12
|
+
constructor(config, logger) {
|
|
13
|
+
this.config = config;
|
|
14
|
+
this.logger = logger;
|
|
15
|
+
this.initializeClient();
|
|
16
|
+
}
|
|
17
|
+
initializeClient() {
|
|
18
|
+
switch (this.config.provider) {
|
|
19
|
+
case 'anthropic':
|
|
20
|
+
this.anthropicClient = new sdk_1.default({
|
|
21
|
+
apiKey: this.config.apiKey,
|
|
22
|
+
...(this.config.baseUrl && { baseURL: this.config.baseUrl }),
|
|
23
|
+
});
|
|
24
|
+
this.logger.debug('Initialized Anthropic client');
|
|
25
|
+
break;
|
|
26
|
+
case 'openai':
|
|
27
|
+
this.openaiClient = new openai_1.default({
|
|
28
|
+
apiKey: this.config.apiKey,
|
|
29
|
+
...(this.config.baseUrl && { baseURL: this.config.baseUrl }),
|
|
30
|
+
});
|
|
31
|
+
this.logger.debug('Initialized OpenAI client');
|
|
32
|
+
break;
|
|
33
|
+
case 'gemini':
|
|
34
|
+
this.geminiClient = new generative_ai_1.GoogleGenerativeAI(this.config.apiKey);
|
|
35
|
+
this.geminiModel = this.geminiClient.getGenerativeModel({
|
|
36
|
+
model: this.config.model || 'gemini-1.5-pro',
|
|
37
|
+
});
|
|
38
|
+
this.logger.debug('Initialized Gemini client');
|
|
39
|
+
break;
|
|
40
|
+
case 'ollama':
|
|
41
|
+
this.logger.debug('Ollama provider - using OpenAI-compatible interface');
|
|
42
|
+
this.openaiClient = new openai_1.default({
|
|
43
|
+
apiKey: this.config.apiKey || 'ollama',
|
|
44
|
+
baseURL: this.config.baseUrl || 'http://localhost:11434/v1',
|
|
45
|
+
});
|
|
46
|
+
break;
|
|
47
|
+
case 'cohere':
|
|
48
|
+
this.logger.warn('Cohere provider not yet implemented, using OpenAI-compatible interface');
|
|
49
|
+
this.openaiClient = new openai_1.default({
|
|
50
|
+
apiKey: this.config.apiKey,
|
|
51
|
+
baseURL: this.config.baseUrl || 'https://api.cohere.ai/v1',
|
|
52
|
+
});
|
|
53
|
+
break;
|
|
54
|
+
case 'local':
|
|
55
|
+
this.logger.debug('Local model provider - using OpenAI-compatible interface');
|
|
56
|
+
this.openaiClient = new openai_1.default({
|
|
57
|
+
apiKey: this.config.apiKey || 'local',
|
|
58
|
+
baseURL: this.config.baseUrl || 'http://localhost:8000/v1',
|
|
59
|
+
});
|
|
60
|
+
break;
|
|
61
|
+
default:
|
|
62
|
+
throw new types_1.LLMError(`Unsupported LLM provider: ${this.config.provider}`, this.config.provider);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async chat(messages) {
|
|
66
|
+
this.logger.debug(`Sending chat request to ${this.config.provider}`, {
|
|
67
|
+
messageCount: messages.length,
|
|
68
|
+
model: this.config.model,
|
|
69
|
+
});
|
|
70
|
+
try {
|
|
71
|
+
switch (this.config.provider) {
|
|
72
|
+
case 'anthropic':
|
|
73
|
+
return await this.chatAnthropic(messages);
|
|
74
|
+
case 'gemini':
|
|
75
|
+
return await this.chatGemini(messages);
|
|
76
|
+
case 'openai':
|
|
77
|
+
case 'ollama':
|
|
78
|
+
case 'cohere':
|
|
79
|
+
case 'local':
|
|
80
|
+
return await this.chatOpenAI(messages);
|
|
81
|
+
default:
|
|
82
|
+
throw new types_1.LLMError(`Unsupported provider: ${this.config.provider}`, this.config.provider);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
this.logger.error('LLM chat request failed', { error });
|
|
87
|
+
throw this.handleError(error);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
async chatAnthropic(messages) {
|
|
91
|
+
if (!this.anthropicClient) {
|
|
92
|
+
throw new types_1.LLMError('Anthropic client not initialized', 'anthropic');
|
|
93
|
+
}
|
|
94
|
+
const systemMessages = messages
|
|
95
|
+
.filter((m) => m.role === 'system')
|
|
96
|
+
.map((m) => m.content)
|
|
97
|
+
.join('\n\n');
|
|
98
|
+
const conversationMessages = messages
|
|
99
|
+
.filter((m) => m.role !== 'system')
|
|
100
|
+
.map((m) => ({
|
|
101
|
+
role: m.role,
|
|
102
|
+
content: m.content,
|
|
103
|
+
}));
|
|
104
|
+
const response = await this.anthropicClient.messages.create({
|
|
105
|
+
model: this.config.model || 'claude-sonnet-4-5-20250929',
|
|
106
|
+
max_tokens: this.config.maxTokens || 2048,
|
|
107
|
+
temperature: this.config.temperature || 0.7,
|
|
108
|
+
system: systemMessages || undefined,
|
|
109
|
+
messages: conversationMessages,
|
|
110
|
+
});
|
|
111
|
+
const content = response.content[0].type === 'text' ? response.content[0].text : '';
|
|
112
|
+
this.logger.debug('Anthropic response received', {
|
|
113
|
+
model: response.model,
|
|
114
|
+
usage: response.usage,
|
|
115
|
+
});
|
|
116
|
+
return {
|
|
117
|
+
content,
|
|
118
|
+
provider: 'anthropic',
|
|
119
|
+
model: response.model,
|
|
120
|
+
usage: {
|
|
121
|
+
promptTokens: response.usage.input_tokens,
|
|
122
|
+
completionTokens: response.usage.output_tokens,
|
|
123
|
+
totalTokens: response.usage.input_tokens + response.usage.output_tokens,
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
async chatGemini(messages) {
|
|
128
|
+
if (!this.geminiModel) {
|
|
129
|
+
throw new types_1.LLMError('Gemini client not initialized', 'gemini');
|
|
130
|
+
}
|
|
131
|
+
const systemMessages = messages
|
|
132
|
+
.filter((m) => m.role === 'system')
|
|
133
|
+
.map((m) => m.content)
|
|
134
|
+
.join('\n\n');
|
|
135
|
+
const conversationMessages = messages
|
|
136
|
+
.filter((m) => m.role !== 'system')
|
|
137
|
+
.map((m) => ({
|
|
138
|
+
role: m.role === 'assistant' ? 'model' : 'user',
|
|
139
|
+
parts: [{ text: m.content }],
|
|
140
|
+
}));
|
|
141
|
+
const chat = this.geminiModel.startChat({
|
|
142
|
+
history: conversationMessages.slice(0, -1),
|
|
143
|
+
generationConfig: {
|
|
144
|
+
temperature: this.config.temperature || 0.7,
|
|
145
|
+
maxOutputTokens: this.config.maxTokens || 2048,
|
|
146
|
+
},
|
|
147
|
+
systemInstruction: systemMessages || undefined,
|
|
148
|
+
});
|
|
149
|
+
const lastMessage = conversationMessages[conversationMessages.length - 1];
|
|
150
|
+
const userMessage = lastMessage?.parts[0]?.text || '';
|
|
151
|
+
const result = await chat.sendMessage(userMessage);
|
|
152
|
+
const response = await result.response;
|
|
153
|
+
const content = response.text();
|
|
154
|
+
this.logger.debug('Gemini response received', {
|
|
155
|
+
model: this.config.model || 'gemini-1.5-pro',
|
|
156
|
+
});
|
|
157
|
+
return {
|
|
158
|
+
content,
|
|
159
|
+
provider: 'gemini',
|
|
160
|
+
model: this.config.model || 'gemini-1.5-pro',
|
|
161
|
+
usage: response.usageMetadata
|
|
162
|
+
? {
|
|
163
|
+
promptTokens: response.usageMetadata.promptTokenCount || 0,
|
|
164
|
+
completionTokens: response.usageMetadata.candidatesTokenCount || 0,
|
|
165
|
+
totalTokens: response.usageMetadata.totalTokenCount || 0,
|
|
166
|
+
}
|
|
167
|
+
: undefined,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
async chatOpenAI(messages) {
|
|
171
|
+
if (!this.openaiClient) {
|
|
172
|
+
throw new types_1.LLMError('OpenAI client not initialized', this.config.provider);
|
|
173
|
+
}
|
|
174
|
+
const response = await this.openaiClient.chat.completions.create({
|
|
175
|
+
model: this.config.model || 'gpt-4-turbo-preview',
|
|
176
|
+
messages: messages.map((m) => ({
|
|
177
|
+
role: m.role,
|
|
178
|
+
content: m.content,
|
|
179
|
+
})),
|
|
180
|
+
temperature: this.config.temperature || 0.7,
|
|
181
|
+
max_tokens: this.config.maxTokens || 2048,
|
|
182
|
+
});
|
|
183
|
+
const content = response.choices[0]?.message?.content || '';
|
|
184
|
+
this.logger.debug('OpenAI-compatible response received', {
|
|
185
|
+
model: response.model,
|
|
186
|
+
usage: response.usage,
|
|
187
|
+
});
|
|
188
|
+
return {
|
|
189
|
+
content,
|
|
190
|
+
provider: this.config.provider,
|
|
191
|
+
model: response.model,
|
|
192
|
+
usage: response.usage
|
|
193
|
+
? {
|
|
194
|
+
promptTokens: response.usage.prompt_tokens,
|
|
195
|
+
completionTokens: response.usage.completion_tokens,
|
|
196
|
+
totalTokens: response.usage.total_tokens,
|
|
197
|
+
}
|
|
198
|
+
: undefined,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
handleError(error) {
|
|
202
|
+
if (error instanceof types_1.LLMError) {
|
|
203
|
+
return error;
|
|
204
|
+
}
|
|
205
|
+
if (error instanceof Error) {
|
|
206
|
+
return new types_1.LLMError(`LLM request failed: ${error.message}`, this.config.provider, { originalError: error.message });
|
|
207
|
+
}
|
|
208
|
+
return new types_1.LLMError('Unknown LLM error occurred', this.config.provider, { error });
|
|
209
|
+
}
|
|
210
|
+
updateConfig(newConfig) {
|
|
211
|
+
this.config = { ...this.config, ...newConfig };
|
|
212
|
+
this.initializeClient();
|
|
213
|
+
this.logger.info('LLM configuration updated', {
|
|
214
|
+
provider: this.config.provider,
|
|
215
|
+
model: this.config.model,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
getConfig() {
|
|
219
|
+
return { ...this.config };
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
exports.LLMAdapter = LLMAdapter;
|
|
223
|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AK,CAAC,OAAO,EAAE,EACtC,IAAI,CAAC,MAAM,CAAC,QAAQ,EACpB,EAAE,aAAa,EAAE,KAAK,CAAC,OAAO,EAAE,CACjC,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,gBAAQ,CACjB,4BAA4B,EAC5B,IAAI,CAAC,MAAM,CAAC,QAAQ,EACpB,EAAE,KAAK,EAAE,CACV,CAAC;IACJ,CAAC;IAKD,YAAY,CAAC,SAA6B;QACxC,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,SAAS,EAAE,CAAC;QAC/C,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACxB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,2BAA2B,EAAE;YAC5C,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ;YAC9B,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK;SACzB,CAAC,CAAC;IACL,CAAC;IAKD,SAAS;QACP,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;IAC5B,CAAC;CACF;AAvSD,gCAuSC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { Logger } from '../types';
|
|
2
|
+
export interface MetricValue {
|
|
3
|
+
value: number;
|
|
4
|
+
timestamp: number;
|
|
5
|
+
labels?: Record<string, string>;
|
|
6
|
+
}
|
|
7
|
+
export interface Histogram {
|
|
8
|
+
count: number;
|
|
9
|
+
sum: number;
|
|
10
|
+
buckets: Map<number, number>;
|
|
11
|
+
}
|
|
12
|
+
export interface Summary {
|
|
13
|
+
count: number;
|
|
14
|
+
sum: number;
|
|
15
|
+
quantiles: Map<number, number>;
|
|
16
|
+
}
|
|
17
|
+
export type MetricType = 'counter' | 'gauge' | 'histogram' | 'summary';
|
|
18
|
+
export declare class Counter {
|
|
19
|
+
private name;
|
|
20
|
+
private help;
|
|
21
|
+
private value;
|
|
22
|
+
private labels;
|
|
23
|
+
constructor(name: string, help: string);
|
|
24
|
+
inc(value?: number, labels?: Record<string, string>): void;
|
|
25
|
+
getValue(labels?: Record<string, string>): number;
|
|
26
|
+
reset(): void;
|
|
27
|
+
export(): string;
|
|
28
|
+
}
|
|
29
|
+
export declare class Gauge {
|
|
30
|
+
private name;
|
|
31
|
+
private help;
|
|
32
|
+
private value;
|
|
33
|
+
private labels;
|
|
34
|
+
constructor(name: string, help: string);
|
|
35
|
+
set(value: number, labels?: Record<string, string>): void;
|
|
36
|
+
inc(value?: number, labels?: Record<string, string>): void;
|
|
37
|
+
dec(value?: number, labels?: Record<string, string>): void;
|
|
38
|
+
getValue(labels?: Record<string, string>): number;
|
|
39
|
+
reset(): void;
|
|
40
|
+
export(): string;
|
|
41
|
+
}
|
|
42
|
+
export declare class HistogramMetric {
|
|
43
|
+
private name;
|
|
44
|
+
private help;
|
|
45
|
+
private observations;
|
|
46
|
+
private buckets;
|
|
47
|
+
constructor(name: string, help: string, buckets?: number[]);
|
|
48
|
+
observe(value: number, labels?: Record<string, string>): void;
|
|
49
|
+
reset(): void;
|
|
50
|
+
export(): string;
|
|
51
|
+
}
|
|
52
|
+
export declare class MetricsRegistry {
|
|
53
|
+
private logger;
|
|
54
|
+
private counters;
|
|
55
|
+
private gauges;
|
|
56
|
+
private histograms;
|
|
57
|
+
constructor(logger: Logger);
|
|
58
|
+
counter(name: string, help: string): Counter;
|
|
59
|
+
gauge(name: string, help: string): Gauge;
|
|
60
|
+
histogram(name: string, help: string, buckets?: number[]): HistogramMetric;
|
|
61
|
+
export(): string;
|
|
62
|
+
resetAll(): void;
|
|
63
|
+
getSummary(): Record<string, unknown>;
|
|
64
|
+
}
|
|
65
|
+
export declare class RuntimeMetrics {
|
|
66
|
+
private registry;
|
|
67
|
+
requestsTotal: Counter;
|
|
68
|
+
requestDuration: HistogramMetric;
|
|
69
|
+
requestErrors: Counter;
|
|
70
|
+
requestsInFlight: Gauge;
|
|
71
|
+
llmRequestsTotal: Counter;
|
|
72
|
+
llmRequestDuration: HistogramMetric;
|
|
73
|
+
llmTokensUsed: Counter;
|
|
74
|
+
llmErrors: Counter;
|
|
75
|
+
contextLoadsTotal: Counter;
|
|
76
|
+
contextLoadDuration: HistogramMetric;
|
|
77
|
+
contextCacheHits: Counter;
|
|
78
|
+
contextCacheMisses: Counter;
|
|
79
|
+
savesTotal: Counter;
|
|
80
|
+
saveDuration: HistogramMetric;
|
|
81
|
+
saveQueueSize: Gauge;
|
|
82
|
+
saveErrors: Counter;
|
|
83
|
+
identityViolationsTotal: Counter;
|
|
84
|
+
identityCorrectionsTotal: Counter;
|
|
85
|
+
circuitBreakerState: Gauge;
|
|
86
|
+
circuitBreakerTrips: Counter;
|
|
87
|
+
uptimeSeconds: Gauge;
|
|
88
|
+
memoryUsageBytes: Gauge;
|
|
89
|
+
cpuUsagePercent: Gauge;
|
|
90
|
+
constructor(logger: Logger);
|
|
91
|
+
private startSystemMetricsCollection;
|
|
92
|
+
exportPrometheus(): string;
|
|
93
|
+
getSummary(): Record<string, unknown>;
|
|
94
|
+
resetAll(): void;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=Metrics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Metrics.d.ts","sourceRoot":"","sources":["../../src/core/Metrics.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAMlC,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC;AAED,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B;AAED,MAAM,WAAW,OAAO;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,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E,OAAO,CAAC;IAC3B,mBAAmB,EAAE,eAAe,CAAC;IACrC,gBAAgB,EAAE,OAAO,CAAC;IAC1B,kBAAkB,EAAE,OAAO,CAAC;IAG5B,UAAU,EAAE,OAAO,CAAC;IACpB,YAAY,EAAE,eAAe,CAAC;IAC9B,aAAa,EAAE,KAAK,CAAC;IACrB,UAAU,EAAE,OAAO,CAAC;IAGpB,uBAAuB,EAAE,OAAO,CAAC;IACjC,wBAAwB,EAAE,OAAO,CAAC;IAGlC,mBAAmB,EAAE,KAAK,CAAC;IAC3B,mBAAmB,EAAE,OAAO,CAAC;IAG7B,aAAa,EAAE,KAAK,CAAC;IACrB,gBAAgB,EAAE,KAAK,CAAC;IACxB,eAAe,EAAE,KAAK,CAAC;gBAElB,MAAM,EAAE,MAAM;IA+H1B,OAAO,CAAC,4BAA4B;IAqBpC,gBAAgB,IAAI,MAAM;IAO1B,UAAU,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAOrC,QAAQ,IAAI,IAAI;CAGjB"}
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RuntimeMetrics = exports.MetricsRegistry = exports.HistogramMetric = exports.Gauge = exports.Counter = void 0;
|
|
4
|
+
class Counter {
|
|
5
|
+
constructor(name, help) {
|
|
6
|
+
this.name = name;
|
|
7
|
+
this.help = help;
|
|
8
|
+
this.value = 0;
|
|
9
|
+
this.labels = new Map();
|
|
10
|
+
}
|
|
11
|
+
inc(value = 1, labels) {
|
|
12
|
+
if (labels) {
|
|
13
|
+
const key = JSON.stringify(labels);
|
|
14
|
+
this.labels.set(key, (this.labels.get(key) || 0) + value);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
this.value += value;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
getValue(labels) {
|
|
21
|
+
if (labels) {
|
|
22
|
+
const key = JSON.stringify(labels);
|
|
23
|
+
return this.labels.get(key) || 0;
|
|
24
|
+
}
|
|
25
|
+
return this.value;
|
|
26
|
+
}
|
|
27
|
+
reset() {
|
|
28
|
+
this.value = 0;
|
|
29
|
+
this.labels.clear();
|
|
30
|
+
}
|
|
31
|
+
export() {
|
|
32
|
+
let output = `# HELP ${this.name} ${this.help}\n`;
|
|
33
|
+
output += `# TYPE ${this.name} counter\n`;
|
|
34
|
+
if (this.labels.size === 0) {
|
|
35
|
+
output += `${this.name} ${this.value}\n`;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
for (const [labelsJson, value] of this.labels) {
|
|
39
|
+
const labels = JSON.parse(labelsJson);
|
|
40
|
+
const labelStr = Object.entries(labels)
|
|
41
|
+
.map(([k, v]) => `${k}="${v}"`)
|
|
42
|
+
.join(',');
|
|
43
|
+
output += `${this.name}{${labelStr}} ${value}\n`;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return output;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.Counter = Counter;
|
|
50
|
+
class Gauge {
|
|
51
|
+
constructor(name, help) {
|
|
52
|
+
this.name = name;
|
|
53
|
+
this.help = help;
|
|
54
|
+
this.value = 0;
|
|
55
|
+
this.labels = new Map();
|
|
56
|
+
}
|
|
57
|
+
set(value, labels) {
|
|
58
|
+
if (labels) {
|
|
59
|
+
const key = JSON.stringify(labels);
|
|
60
|
+
this.labels.set(key, value);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
this.value = value;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
inc(value = 1, labels) {
|
|
67
|
+
if (labels) {
|
|
68
|
+
const key = JSON.stringify(labels);
|
|
69
|
+
this.labels.set(key, (this.labels.get(key) || 0) + value);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
this.value += value;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
dec(value = 1, labels) {
|
|
76
|
+
this.inc(-value, labels);
|
|
77
|
+
}
|
|
78
|
+
getValue(labels) {
|
|
79
|
+
if (labels) {
|
|
80
|
+
const key = JSON.stringify(labels);
|
|
81
|
+
return this.labels.get(key) || 0;
|
|
82
|
+
}
|
|
83
|
+
return this.value;
|
|
84
|
+
}
|
|
85
|
+
reset() {
|
|
86
|
+
this.value = 0;
|
|
87
|
+
this.labels.clear();
|
|
88
|
+
}
|
|
89
|
+
export() {
|
|
90
|
+
let output = `# HELP ${this.name} ${this.help}\n`;
|
|
91
|
+
output += `# TYPE ${this.name} gauge\n`;
|
|
92
|
+
if (this.labels.size === 0) {
|
|
93
|
+
output += `${this.name} ${this.value}\n`;
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
for (const [labelsJson, value] of this.labels) {
|
|
97
|
+
const labels = JSON.parse(labelsJson);
|
|
98
|
+
const labelStr = Object.entries(labels)
|
|
99
|
+
.map(([k, v]) => `${k}="${v}"`)
|
|
100
|
+
.join(',');
|
|
101
|
+
output += `${this.name}{${labelStr}} ${value}\n`;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return output;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
exports.Gauge = Gauge;
|
|
108
|
+
class HistogramMetric {
|
|
109
|
+
constructor(name, help, buckets = [0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10]) {
|
|
110
|
+
this.name = name;
|
|
111
|
+
this.help = help;
|
|
112
|
+
this.observations = new Map();
|
|
113
|
+
this.buckets = [...buckets, Infinity].sort((a, b) => a - b);
|
|
114
|
+
}
|
|
115
|
+
observe(value, labels) {
|
|
116
|
+
const key = labels ? JSON.stringify(labels) : 'default';
|
|
117
|
+
let histogram = this.observations.get(key);
|
|
118
|
+
if (!histogram) {
|
|
119
|
+
histogram = {
|
|
120
|
+
count: 0,
|
|
121
|
+
sum: 0,
|
|
122
|
+
buckets: new Map(this.buckets.map((b) => [b, 0])),
|
|
123
|
+
};
|
|
124
|
+
this.observations.set(key, histogram);
|
|
125
|
+
}
|
|
126
|
+
histogram.count++;
|
|
127
|
+
histogram.sum += value;
|
|
128
|
+
for (const bucket of this.buckets) {
|
|
129
|
+
if (value <= bucket) {
|
|
130
|
+
histogram.buckets.set(bucket, (histogram.buckets.get(bucket) || 0) + 1);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
reset() {
|
|
135
|
+
this.observations.clear();
|
|
136
|
+
}
|
|
137
|
+
export() {
|
|
138
|
+
let output = `# HELP ${this.name} ${this.help}\n`;
|
|
139
|
+
output += `# TYPE ${this.name} histogram\n`;
|
|
140
|
+
for (const [labelsJson, histogram] of this.observations) {
|
|
141
|
+
const labels = labelsJson !== 'default' ? JSON.parse(labelsJson) : {};
|
|
142
|
+
const labelStr = Object.entries(labels).length > 0
|
|
143
|
+
? `{${Object.entries(labels).map(([k, v]) => `${k}="${v}"`).join(',')}}`
|
|
144
|
+
: '';
|
|
145
|
+
for (const [bucket, count] of histogram.buckets) {
|
|
146
|
+
const le = bucket === Infinity ? '+Inf' : bucket.toString();
|
|
147
|
+
output += `${this.name}_bucket${labelStr}{le="${le}"} ${count}\n`;
|
|
148
|
+
}
|
|
149
|
+
output += `${this.name}_sum${labelStr} ${histogram.sum}\n`;
|
|
150
|
+
output += `${this.name}_count${labelStr} ${histogram.count}\n`;
|
|
151
|
+
}
|
|
152
|
+
return output;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
exports.HistogramMetric = HistogramMetric;
|
|
156
|
+
class MetricsRegistry {
|
|
157
|
+
constructor(logger) {
|
|
158
|
+
this.logger = logger;
|
|
159
|
+
this.counters = new Map();
|
|
160
|
+
this.gauges = new Map();
|
|
161
|
+
this.histograms = new Map();
|
|
162
|
+
}
|
|
163
|
+
counter(name, help) {
|
|
164
|
+
if (!this.counters.has(name)) {
|
|
165
|
+
this.counters.set(name, new Counter(name, help));
|
|
166
|
+
this.logger.debug(`Counter registered: ${name}`);
|
|
167
|
+
}
|
|
168
|
+
return this.counters.get(name);
|
|
169
|
+
}
|
|
170
|
+
gauge(name, help) {
|
|
171
|
+
if (!this.gauges.has(name)) {
|
|
172
|
+
this.gauges.set(name, new Gauge(name, help));
|
|
173
|
+
this.logger.debug(`Gauge registered: ${name}`);
|
|
174
|
+
}
|
|
175
|
+
return this.gauges.get(name);
|
|
176
|
+
}
|
|
177
|
+
histogram(name, help, buckets) {
|
|
178
|
+
if (!this.histograms.has(name)) {
|
|
179
|
+
this.histograms.set(name, new HistogramMetric(name, help, buckets));
|
|
180
|
+
this.logger.debug(`Histogram registered: ${name}`);
|
|
181
|
+
}
|
|
182
|
+
return this.histograms.get(name);
|
|
183
|
+
}
|
|
184
|
+
export() {
|
|
185
|
+
let output = '';
|
|
186
|
+
for (const counter of this.counters.values()) {
|
|
187
|
+
output += counter.export() + '\n';
|
|
188
|
+
}
|
|
189
|
+
for (const gauge of this.gauges.values()) {
|
|
190
|
+
output += gauge.export() + '\n';
|
|
191
|
+
}
|
|
192
|
+
for (const histogram of this.histograms.values()) {
|
|
193
|
+
output += histogram.export() + '\n';
|
|
194
|
+
}
|
|
195
|
+
return output;
|
|
196
|
+
}
|
|
197
|
+
resetAll() {
|
|
198
|
+
for (const counter of this.counters.values()) {
|
|
199
|
+
counter.reset();
|
|
200
|
+
}
|
|
201
|
+
for (const gauge of this.gauges.values()) {
|
|
202
|
+
gauge.reset();
|
|
203
|
+
}
|
|
204
|
+
for (const histogram of this.histograms.values()) {
|
|
205
|
+
histogram.reset();
|
|
206
|
+
}
|
|
207
|
+
this.logger.info('All metrics reset');
|
|
208
|
+
}
|
|
209
|
+
getSummary() {
|
|
210
|
+
const summary = {};
|
|
211
|
+
for (const [name, counter] of this.counters) {
|
|
212
|
+
summary[name] = counter.getValue();
|
|
213
|
+
}
|
|
214
|
+
for (const [name, gauge] of this.gauges) {
|
|
215
|
+
summary[name] = gauge.getValue();
|
|
216
|
+
}
|
|
217
|
+
return summary;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
exports.MetricsRegistry = MetricsRegistry;
|
|
221
|
+
class RuntimeMetrics {
|
|
222
|
+
constructor(logger) {
|
|
223
|
+
this.registry = new MetricsRegistry(logger);
|
|
224
|
+
this.requestsTotal = this.registry.counter('recallbricks_requests_total', 'Total number of requests');
|
|
225
|
+
this.requestDuration = this.registry.histogram('recallbricks_request_duration_seconds', 'Request duration in seconds', [0.001, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, 30]);
|
|
226
|
+
this.requestErrors = this.registry.counter('recallbricks_request_errors_total', 'Total number of request errors');
|
|
227
|
+
this.requestsInFlight = this.registry.gauge('recallbricks_requests_in_flight', 'Number of requests currently being processed');
|
|
228
|
+
this.llmRequestsTotal = this.registry.counter('recallbricks_llm_requests_total', 'Total number of LLM requests');
|
|
229
|
+
this.llmRequestDuration = this.registry.histogram('recallbricks_llm_request_duration_seconds', 'LLM request duration in seconds');
|
|
230
|
+
this.llmTokensUsed = this.registry.counter('recallbricks_llm_tokens_used_total', 'Total number of LLM tokens used');
|
|
231
|
+
this.llmErrors = this.registry.counter('recallbricks_llm_errors_total', 'Total number of LLM errors');
|
|
232
|
+
this.contextLoadsTotal = this.registry.counter('recallbricks_context_loads_total', 'Total number of context loads');
|
|
233
|
+
this.contextLoadDuration = this.registry.histogram('recallbricks_context_load_duration_seconds', 'Context load duration in seconds');
|
|
234
|
+
this.contextCacheHits = this.registry.counter('recallbricks_context_cache_hits_total', 'Total number of context cache hits');
|
|
235
|
+
this.contextCacheMisses = this.registry.counter('recallbricks_context_cache_misses_total', 'Total number of context cache misses');
|
|
236
|
+
this.savesTotal = this.registry.counter('recallbricks_saves_total', 'Total number of conversation saves');
|
|
237
|
+
this.saveDuration = this.registry.histogram('recallbricks_save_duration_seconds', 'Save duration in seconds');
|
|
238
|
+
this.saveQueueSize = this.registry.gauge('recallbricks_save_queue_size', 'Current save queue size');
|
|
239
|
+
this.saveErrors = this.registry.counter('recallbricks_save_errors_total', 'Total number of save errors');
|
|
240
|
+
this.identityViolationsTotal = this.registry.counter('recallbricks_identity_violations_total', 'Total number of identity violations detected');
|
|
241
|
+
this.identityCorrectionsTotal = this.registry.counter('recallbricks_identity_corrections_total', 'Total number of identity corrections applied');
|
|
242
|
+
this.circuitBreakerState = this.registry.gauge('recallbricks_circuit_breaker_state', 'Circuit breaker state (0=closed, 1=half-open, 2=open)');
|
|
243
|
+
this.circuitBreakerTrips = this.registry.counter('recallbricks_circuit_breaker_trips_total', 'Total number of circuit breaker trips');
|
|
244
|
+
this.uptimeSeconds = this.registry.gauge('recallbricks_uptime_seconds', 'Uptime in seconds');
|
|
245
|
+
this.memoryUsageBytes = this.registry.gauge('recallbricks_memory_usage_bytes', 'Memory usage in bytes');
|
|
246
|
+
this.cpuUsagePercent = this.registry.gauge('recallbricks_cpu_usage_percent', 'CPU usage percentage');
|
|
247
|
+
this.startSystemMetricsCollection();
|
|
248
|
+
}
|
|
249
|
+
startSystemMetricsCollection() {
|
|
250
|
+
const startTime = Date.now();
|
|
251
|
+
setInterval(() => {
|
|
252
|
+
this.uptimeSeconds.set((Date.now() - startTime) / 1000);
|
|
253
|
+
const memUsage = process.memoryUsage();
|
|
254
|
+
this.memoryUsageBytes.set(memUsage.heapUsed);
|
|
255
|
+
const cpuUsage = process.cpuUsage();
|
|
256
|
+
const totalUsage = cpuUsage.user + cpuUsage.system;
|
|
257
|
+
this.cpuUsagePercent.set(totalUsage / 10000);
|
|
258
|
+
}, 5000);
|
|
259
|
+
}
|
|
260
|
+
exportPrometheus() {
|
|
261
|
+
return this.registry.export();
|
|
262
|
+
}
|
|
263
|
+
getSummary() {
|
|
264
|
+
return this.registry.getSummary();
|
|
265
|
+
}
|
|
266
|
+
resetAll() {
|
|
267
|
+
this.registry.resetAll();
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
exports.RuntimeMetrics = RuntimeMetrics;
|
|
271
|
+
//# sourceMappingURL=Metrics.js.map
|
|
@@ -0,0 +1 @@
|
|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