vesper-memory 0.5.2 → 0.5.4
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 +49 -14
- package/config/claude-rules/memory-discipline.md +39 -0
- package/config/claude-rules/vesper.md +218 -0
- package/dist/cli.js +59 -0
- package/dist/cli.js.map +1 -1
- package/package.json +1 -2
- package/dist/cli 2.js +0 -583
- package/dist/cli.d 2.ts +0 -8
- package/dist/cli.d.ts 2.map +0 -1
- package/dist/cli.js 2.map +0 -1
- package/dist/config 2/rate-limits.d.ts +0 -76
- package/dist/config 2/rate-limits.d.ts.map +0 -1
- package/dist/config 2/rate-limits.js +0 -161
- package/dist/config 2/rate-limits.js.map +0 -1
- package/dist/consolidation 2/pipeline.d.ts +0 -52
- package/dist/consolidation 2/pipeline.d.ts.map +0 -1
- package/dist/consolidation 2/pipeline.js +0 -193
- package/dist/consolidation 2/pipeline.js.map +0 -1
- package/dist/embeddings 2/client.d.ts +0 -94
- package/dist/embeddings 2/client.d.ts.map +0 -1
- package/dist/embeddings 2/client.js +0 -144
- package/dist/embeddings 2/client.js.map +0 -1
- package/dist/memory-layers 2/semantic-memory.d.ts +0 -33
- package/dist/memory-layers 2/semantic-memory.d.ts.map +0 -1
- package/dist/memory-layers 2/semantic-memory.js +0 -114
- package/dist/memory-layers 2/semantic-memory.js.map +0 -1
- package/dist/memory-layers 2/skill-library.d.ts +0 -25
- package/dist/memory-layers 2/skill-library.d.ts.map +0 -1
- package/dist/memory-layers 2/skill-library.js +0 -54
- package/dist/memory-layers 2/skill-library.js.map +0 -1
- package/dist/memory-layers 2/working-memory.d.ts +0 -57
- package/dist/memory-layers 2/working-memory.d.ts.map +0 -1
- package/dist/memory-layers 2/working-memory.js +0 -153
- package/dist/memory-layers 2/working-memory.js.map +0 -1
- package/dist/middleware 2/auth.d.ts +0 -287
- package/dist/middleware 2/auth.d.ts.map +0 -1
- package/dist/middleware 2/auth.js +0 -610
- package/dist/middleware 2/auth.js.map +0 -1
- package/dist/monitoring 2/health.d.ts +0 -241
- package/dist/monitoring 2/health.d.ts.map +0 -1
- package/dist/monitoring 2/health.js +0 -649
- package/dist/monitoring 2/health.js.map +0 -1
- package/dist/monitoring 2/metrics.d.ts +0 -153
- package/dist/monitoring 2/metrics.d.ts.map +0 -1
- package/dist/monitoring 2/metrics.js +0 -349
- package/dist/monitoring 2/metrics.js.map +0 -1
- package/dist/retrieval 2/hybrid-search.d.ts +0 -186
- package/dist/retrieval 2/hybrid-search.d.ts.map +0 -1
- package/dist/retrieval 2/hybrid-search.js +0 -327
- package/dist/retrieval 2/hybrid-search.js.map +0 -1
- package/dist/router 2/smart-router.d.ts +0 -111
- package/dist/router 2/smart-router.d.ts.map +0 -1
- package/dist/router 2/smart-router.js +0 -383
- package/dist/router 2/smart-router.js.map +0 -1
- package/dist/security 2/rate-limit-middleware.d.ts +0 -119
- package/dist/security 2/rate-limit-middleware.d.ts.map +0 -1
- package/dist/security 2/rate-limit-middleware.js +0 -193
- package/dist/security 2/rate-limit-middleware.js.map +0 -1
- package/dist/server 2.js +0 -861
- package/dist/server-wrapper 2.js +0 -170
- package/dist/server-wrapper.d 2.ts +0 -12
- package/dist/server-wrapper.d.ts 2.map +0 -1
- package/dist/server-wrapper.js 2.map +0 -1
- package/dist/server.d 2.ts +0 -14
- package/dist/server.d.ts 2.map +0 -1
- package/dist/server.js 2.map +0 -1
- package/dist/synthesis 2/conflict-detector.d.ts +0 -43
- package/dist/synthesis 2/conflict-detector.d.ts.map +0 -1
- package/dist/synthesis 2/conflict-detector.js +0 -125
- package/dist/synthesis 2/conflict-detector.js.map +0 -1
- package/dist/utils 2/monitoring.d.ts +0 -25
- package/dist/utils 2/monitoring.d.ts.map +0 -1
- package/dist/utils 2/monitoring.js +0 -41
- package/dist/utils 2/monitoring.js.map +0 -1
- package/dist/utils 2/rate-limiter.d.ts +0 -97
- package/dist/utils 2/rate-limiter.d.ts.map +0 -1
- package/dist/utils 2/rate-limiter.js +0 -166
- package/dist/utils 2/rate-limiter.js.map +0 -1
- package/dist/utils 2/validation.d.ts +0 -139
- package/dist/utils 2/validation.d.ts.map +0 -1
- package/dist/utils 2/validation.js +0 -195
- package/dist/utils 2/validation.js.map +0 -1
|
@@ -1,383 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Smart Query Router
|
|
3
|
-
*
|
|
4
|
-
* Implements intelligent routing logic from v3.0 plan:
|
|
5
|
-
* 1. Always check working memory first (fast path)
|
|
6
|
-
* 2. Classify query type using regex patterns
|
|
7
|
-
* 3. Route to appropriate handler based on classification
|
|
8
|
-
* 4. Fall back to hybrid search for complex queries
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* Query type enumeration
|
|
12
|
-
* Used to classify queries and route to appropriate handlers
|
|
13
|
-
*/
|
|
14
|
-
export var QueryType;
|
|
15
|
-
(function (QueryType) {
|
|
16
|
-
QueryType["FACTUAL"] = "factual";
|
|
17
|
-
QueryType["PREFERENCE"] = "preference";
|
|
18
|
-
QueryType["PROJECT"] = "project";
|
|
19
|
-
QueryType["TEMPORAL"] = "temporal";
|
|
20
|
-
QueryType["SKILL"] = "skill";
|
|
21
|
-
QueryType["COMPLEX"] = "complex";
|
|
22
|
-
})(QueryType || (QueryType = {}));
|
|
23
|
-
/**
|
|
24
|
-
* Classify a query into one of the six query types
|
|
25
|
-
*
|
|
26
|
-
* Uses simple regex patterns to identify query intent without LLM calls.
|
|
27
|
-
* Falls back to 'complex' for ambiguous queries.
|
|
28
|
-
*
|
|
29
|
-
* Patterns (in order of specificity):
|
|
30
|
-
* - skill: "like before", "same as", "same way", "how you", "analyze"
|
|
31
|
-
* - factual: "what is", "who is", "where is"
|
|
32
|
-
* - temporal: "last week", "yesterday", "recently", etc.
|
|
33
|
-
* - preference: "prefer", "want", "style", "favorite"
|
|
34
|
-
* - project: "project", "working on", "decided", "building", "creating", "developing"
|
|
35
|
-
* - complex: fallback for anything else
|
|
36
|
-
*/
|
|
37
|
-
export function classifyQuery(query) {
|
|
38
|
-
const normalizedQuery = query.toLowerCase().trim();
|
|
39
|
-
// Pattern definitions with confidence scores
|
|
40
|
-
// NOTE: More specific patterns should be checked first to avoid ambiguity
|
|
41
|
-
const patterns = [
|
|
42
|
-
// Skill patterns are most specific - check before preference and temporal
|
|
43
|
-
{
|
|
44
|
-
type: QueryType.SKILL,
|
|
45
|
-
regex: /\b(like before|same as|same way|how you)\b/i,
|
|
46
|
-
confidence: 0.85,
|
|
47
|
-
label: "skill"
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
type: QueryType.SKILL,
|
|
51
|
-
regex: /\banalyze\b/i,
|
|
52
|
-
confidence: 0.75,
|
|
53
|
-
label: "skill_analyze"
|
|
54
|
-
},
|
|
55
|
-
// Temporal patterns - check before factual WH questions since temporal is more specific
|
|
56
|
-
{
|
|
57
|
-
type: QueryType.TEMPORAL,
|
|
58
|
-
regex: /\b(last week|last month|last year|last time)\b/i,
|
|
59
|
-
confidence: 0.95,
|
|
60
|
-
label: "temporal_specific"
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
type: QueryType.TEMPORAL,
|
|
64
|
-
regex: /\b(yesterday|recently|earlier)\b/i,
|
|
65
|
-
confidence: 0.9,
|
|
66
|
-
label: "temporal"
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
type: QueryType.TEMPORAL,
|
|
70
|
-
regex: /\bbefore\b/i,
|
|
71
|
-
confidence: 0.7,
|
|
72
|
-
label: "temporal_before"
|
|
73
|
-
},
|
|
74
|
-
// Factual patterns (WH questions) - after temporal to avoid misclassifying temporal queries
|
|
75
|
-
{
|
|
76
|
-
type: QueryType.FACTUAL,
|
|
77
|
-
regex: /\b(what|who|where)\s+(is|was|are|were)\b/i,
|
|
78
|
-
confidence: 0.95,
|
|
79
|
-
label: "factual_wh"
|
|
80
|
-
},
|
|
81
|
-
// Preference patterns
|
|
82
|
-
{
|
|
83
|
-
type: QueryType.PREFERENCE,
|
|
84
|
-
regex: /\b(prefer|want|style|favorite)\b/i,
|
|
85
|
-
confidence: 0.9,
|
|
86
|
-
label: "preference"
|
|
87
|
-
},
|
|
88
|
-
// Note: 'like' as preference is checked but has lower confidence due to ambiguity
|
|
89
|
-
{
|
|
90
|
-
type: QueryType.PREFERENCE,
|
|
91
|
-
regex: /\bhow do i like\b/i,
|
|
92
|
-
confidence: 0.85,
|
|
93
|
-
label: "preference_like"
|
|
94
|
-
},
|
|
95
|
-
// Project patterns
|
|
96
|
-
{
|
|
97
|
-
type: QueryType.PROJECT,
|
|
98
|
-
regex: /\b(working on|decided|decide|decision)\b/i,
|
|
99
|
-
confidence: 0.9,
|
|
100
|
-
label: "project_specific"
|
|
101
|
-
},
|
|
102
|
-
{
|
|
103
|
-
type: QueryType.PROJECT,
|
|
104
|
-
regex: /\b(project|building|creating|developing)\b/i,
|
|
105
|
-
confidence: 0.85,
|
|
106
|
-
label: "project"
|
|
107
|
-
}
|
|
108
|
-
];
|
|
109
|
-
// Check each pattern in order
|
|
110
|
-
for (const pattern of patterns) {
|
|
111
|
-
if (pattern.regex.test(normalizedQuery)) {
|
|
112
|
-
return {
|
|
113
|
-
type: pattern.type,
|
|
114
|
-
confidence: pattern.confidence,
|
|
115
|
-
matchedPattern: pattern.label
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
// Default to complex query
|
|
120
|
-
return {
|
|
121
|
-
type: QueryType.COMPLEX,
|
|
122
|
-
confidence: 0.5
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Smart query router following v3.0 plan retrieval strategy
|
|
127
|
-
*
|
|
128
|
-
* Routing decision tree:
|
|
129
|
-
* 1. Check working memory first (5ms, high confidence threshold)
|
|
130
|
-
* 2. Classify query type with regex
|
|
131
|
-
* 3. Route to appropriate handler:
|
|
132
|
-
* - factual: direct entity lookup
|
|
133
|
-
* - preference: preference retrieval
|
|
134
|
-
* - project: graph traversal with HippoRAG
|
|
135
|
-
* - temporal: time-based filtering
|
|
136
|
-
* - skill: skill library search
|
|
137
|
-
* - complex: hybrid search (dense + sparse + BM25)
|
|
138
|
-
*
|
|
139
|
-
* @param query - The user's query string
|
|
140
|
-
* @param context - Routing context (user, conversation, etc.)
|
|
141
|
-
* @returns Promise resolving to array of memory results
|
|
142
|
-
*
|
|
143
|
-
* @throws Error if query is empty or context is invalid
|
|
144
|
-
*/
|
|
145
|
-
export async function retrieve(query, context) {
|
|
146
|
-
// Input validation
|
|
147
|
-
if (!query || query.trim().length === 0) {
|
|
148
|
-
throw new Error("Query cannot be empty");
|
|
149
|
-
}
|
|
150
|
-
if (!context || !context.userId) {
|
|
151
|
-
throw new Error("Valid routing context with userId is required");
|
|
152
|
-
}
|
|
153
|
-
// Step 1: ALWAYS check working memory first (5ms fast path)
|
|
154
|
-
const recentMemories = await checkWorkingMemory(query, context);
|
|
155
|
-
// High similarity threshold suggests cache hit - return immediately
|
|
156
|
-
if (recentMemories.length > 0 && recentMemories[0].similarity > 0.85) {
|
|
157
|
-
console.debug(`[Router] Cache hit in working memory for query: "${query}"`);
|
|
158
|
-
return recentMemories;
|
|
159
|
-
}
|
|
160
|
-
// Step 2: Classify query type using regex patterns
|
|
161
|
-
const classification = classifyQuery(query);
|
|
162
|
-
console.debug(`[Router] Query classified as ${classification.type} ` +
|
|
163
|
-
`(confidence: ${classification.confidence}, pattern: ${classification.matchedPattern})`);
|
|
164
|
-
// Step 3: Route to appropriate handler based on classification
|
|
165
|
-
let results = [];
|
|
166
|
-
switch (classification.type) {
|
|
167
|
-
case QueryType.FACTUAL:
|
|
168
|
-
results = await handleFactualQuery(query, context);
|
|
169
|
-
break;
|
|
170
|
-
case QueryType.PREFERENCE:
|
|
171
|
-
results = await handlePreferenceQuery(query, context);
|
|
172
|
-
break;
|
|
173
|
-
case QueryType.PROJECT:
|
|
174
|
-
results = await handleProjectQuery(query, context);
|
|
175
|
-
break;
|
|
176
|
-
case QueryType.TEMPORAL:
|
|
177
|
-
results = await handleTemporalQuery(query, context);
|
|
178
|
-
break;
|
|
179
|
-
case QueryType.SKILL:
|
|
180
|
-
results = await handleSkillQuery(query, context);
|
|
181
|
-
break;
|
|
182
|
-
case QueryType.COMPLEX:
|
|
183
|
-
default:
|
|
184
|
-
results = await handleComplexQuery(query, context);
|
|
185
|
-
break;
|
|
186
|
-
}
|
|
187
|
-
return results;
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Check working memory for recent relevant memories
|
|
191
|
-
*
|
|
192
|
-
* Implementation stub - will integrate with Redis/Hopfield layer
|
|
193
|
-
* Current behavior: returns empty array (no working memory yet)
|
|
194
|
-
*
|
|
195
|
-
* @param query - Search query
|
|
196
|
-
* @param context - Routing context
|
|
197
|
-
* @returns Recent memory results matching query
|
|
198
|
-
*/
|
|
199
|
-
async function checkWorkingMemory(query, context) {
|
|
200
|
-
console.debug(`[Router] Checking working memory for: "${query}"`);
|
|
201
|
-
// TODO: Implement Redis working memory search with Hopfield network
|
|
202
|
-
// - Get user's working memory from Redis
|
|
203
|
-
// - Embed query using BGE-large
|
|
204
|
-
// - Perform Hopfield associative recall
|
|
205
|
-
// - Return top-K matches with similarity scores
|
|
206
|
-
return [];
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Handle factual queries
|
|
210
|
-
*
|
|
211
|
-
* Pattern: "What is X?", "Who is Y?", "Where is Z?"
|
|
212
|
-
* Handler: Direct entity lookup in semantic memory
|
|
213
|
-
*
|
|
214
|
-
* Implementation stub
|
|
215
|
-
*
|
|
216
|
-
* @param query - The factual query
|
|
217
|
-
* @param context - Routing context
|
|
218
|
-
* @returns Entity information
|
|
219
|
-
*/
|
|
220
|
-
async function handleFactualQuery(query, context) {
|
|
221
|
-
console.debug(`[Router] Handling factual query: "${query}"`);
|
|
222
|
-
// TODO: Implement factual query handler
|
|
223
|
-
// 1. Extract entity name from query (using NER or simple heuristics)
|
|
224
|
-
// 2. Lookup entity in semantic memory
|
|
225
|
-
// 3. Retrieve related facts and properties
|
|
226
|
-
// 4. Return with confidence scores
|
|
227
|
-
return [];
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* Handle preference queries
|
|
231
|
-
*
|
|
232
|
-
* Pattern: "How do I prefer X?", "What style do I like?"
|
|
233
|
-
* Handler: Preference retrieval from semantic memory
|
|
234
|
-
*
|
|
235
|
-
* Implementation stub
|
|
236
|
-
*
|
|
237
|
-
* @param query - The preference query
|
|
238
|
-
* @param context - Routing context
|
|
239
|
-
* @returns User preference information
|
|
240
|
-
*/
|
|
241
|
-
async function handlePreferenceQuery(query, context) {
|
|
242
|
-
console.debug(`[Router] Handling preference query: "${query}"`);
|
|
243
|
-
// TODO: Implement preference query handler
|
|
244
|
-
// 1. Extract preference domain from query
|
|
245
|
-
// 2. Search semantic memory for related preference facts
|
|
246
|
-
// 3. Apply temporal decay to weight recent preferences
|
|
247
|
-
// 4. Return ranked by recency and reinforcement
|
|
248
|
-
return [];
|
|
249
|
-
}
|
|
250
|
-
/**
|
|
251
|
-
* Handle project queries
|
|
252
|
-
*
|
|
253
|
-
* Pattern: "What did we decide about X?", "What's the status on Y?"
|
|
254
|
-
* Handler: Graph traversal with HippoRAG personalized PageRank
|
|
255
|
-
*
|
|
256
|
-
* Implementation stub
|
|
257
|
-
*
|
|
258
|
-
* @param query - The project query
|
|
259
|
-
* @param context - Routing context
|
|
260
|
-
* @returns Project-related information via graph traversal
|
|
261
|
-
*/
|
|
262
|
-
async function handleProjectQuery(query, context) {
|
|
263
|
-
console.debug(`[Router] Handling project query: "${query}"`);
|
|
264
|
-
// TODO: Implement project query handler
|
|
265
|
-
// 1. Extract project entity name from query
|
|
266
|
-
// 2. Lookup project entity in semantic memory
|
|
267
|
-
// 3. Run HippoRAG personalized PageRank from project node (depth=2)
|
|
268
|
-
// 4. Return connected entities and relationships
|
|
269
|
-
return [];
|
|
270
|
-
}
|
|
271
|
-
/**
|
|
272
|
-
* Handle temporal queries
|
|
273
|
-
*
|
|
274
|
-
* Pattern: "What were we working on last week?", "What was discussed yesterday?"
|
|
275
|
-
* Handler: Time-based filtering from semantic memory
|
|
276
|
-
*
|
|
277
|
-
* Implementation stub
|
|
278
|
-
*
|
|
279
|
-
* @param query - The temporal query
|
|
280
|
-
* @param context - Routing context
|
|
281
|
-
* @returns Memories from specified time range
|
|
282
|
-
*/
|
|
283
|
-
async function handleTemporalQuery(query, context) {
|
|
284
|
-
console.debug(`[Router] Handling temporal query: "${query}"`);
|
|
285
|
-
// TODO: Implement temporal query handler
|
|
286
|
-
// 1. Parse temporal references from query
|
|
287
|
-
// 2. Convert to time range (start_date, end_date)
|
|
288
|
-
// 3. Query semantic memory for memories in that range
|
|
289
|
-
// 4. Apply temporal decay based on specificity
|
|
290
|
-
return [];
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* Handle skill queries
|
|
294
|
-
*
|
|
295
|
-
* Pattern: "Analyze this like before", "Same way as last time"
|
|
296
|
-
* Handler: Skill library semantic search
|
|
297
|
-
*
|
|
298
|
-
* Implementation stub
|
|
299
|
-
*
|
|
300
|
-
* @param query - The skill query
|
|
301
|
-
* @param context - Routing context
|
|
302
|
-
* @returns Matching skills from skill library
|
|
303
|
-
*/
|
|
304
|
-
async function handleSkillQuery(query, context) {
|
|
305
|
-
console.debug(`[Router] Handling skill query: "${query}"`);
|
|
306
|
-
// TODO: Implement skill query handler
|
|
307
|
-
// 1. Embed query using BGE-large
|
|
308
|
-
// 2. Search skill library for matching triggers
|
|
309
|
-
// 3. Filter by prerequisites being met in context
|
|
310
|
-
// 4. Return skills ranked by success rate
|
|
311
|
-
return [];
|
|
312
|
-
}
|
|
313
|
-
/**
|
|
314
|
-
* Handle complex queries
|
|
315
|
-
*
|
|
316
|
-
* Pattern: Ambiguous queries that don't match specific patterns
|
|
317
|
-
* Handler: Hybrid search across all representations
|
|
318
|
-
*
|
|
319
|
-
* Hybrid search pipeline:
|
|
320
|
-
* 1. Parallel search: dense embeddings + sparse vectors + BM25
|
|
321
|
-
* 2. Reciprocal Rank Fusion (k=60) to combine results
|
|
322
|
-
* 3. Light reranking with cross-encoder on top-10
|
|
323
|
-
* 4. Return top-5 fused results
|
|
324
|
-
*
|
|
325
|
-
* Implementation stub
|
|
326
|
-
*
|
|
327
|
-
* @param query - The complex query
|
|
328
|
-
* @param context - Routing context
|
|
329
|
-
* @returns Hybrid search results
|
|
330
|
-
*/
|
|
331
|
-
async function handleComplexQuery(query, context) {
|
|
332
|
-
console.debug(`[Router] Handling complex query with hybrid search: "${query}"`);
|
|
333
|
-
// TODO: Implement hybrid search
|
|
334
|
-
// 1. Embed query in multiple representations:
|
|
335
|
-
// - Dense: BGE-large embeddings
|
|
336
|
-
// - Sparse: SPLADE++ sparse vectors
|
|
337
|
-
// - Keyword: BM25 tokenization
|
|
338
|
-
//
|
|
339
|
-
// 2. Parallel search in Qdrant:
|
|
340
|
-
// - Dense similarity search (limit: 20)
|
|
341
|
-
// - Sparse similarity search (limit: 20)
|
|
342
|
-
// - BM25 full-text search (limit: 20)
|
|
343
|
-
//
|
|
344
|
-
// 3. Reciprocal Rank Fusion:
|
|
345
|
-
// - Combine ranked lists from three searches
|
|
346
|
-
// - Weight scores using RRF formula with k=60
|
|
347
|
-
//
|
|
348
|
-
// 4. Light reranking:
|
|
349
|
-
// - Use cross-encoder (not ColBERT for speed)
|
|
350
|
-
// - Rerank only top-10 results
|
|
351
|
-
// - Adds ~20ms but significant accuracy gain
|
|
352
|
-
//
|
|
353
|
-
// 5. Return top-5 after reranking
|
|
354
|
-
return [];
|
|
355
|
-
}
|
|
356
|
-
/**
|
|
357
|
-
* Extract entity name from a query
|
|
358
|
-
*
|
|
359
|
-
* Implementation stub for entity extraction
|
|
360
|
-
* Will later integrate with NER or simple heuristics
|
|
361
|
-
*/
|
|
362
|
-
export function extractEntityName(query) {
|
|
363
|
-
// TODO: Implement entity extraction
|
|
364
|
-
// Current: just return null
|
|
365
|
-
return null;
|
|
366
|
-
}
|
|
367
|
-
/**
|
|
368
|
-
* Extract domain/category from a query
|
|
369
|
-
*
|
|
370
|
-
* Implementation stub for domain extraction
|
|
371
|
-
* Used for preference and skill queries
|
|
372
|
-
*/
|
|
373
|
-
export function extractDomain(query) {
|
|
374
|
-
// TODO: Implement domain extraction
|
|
375
|
-
// Current: just return null
|
|
376
|
-
return null;
|
|
377
|
-
}
|
|
378
|
-
export function parseTimeRange(query) {
|
|
379
|
-
// TODO: Implement temporal reference parsing
|
|
380
|
-
// Current: just return null
|
|
381
|
-
return null;
|
|
382
|
-
}
|
|
383
|
-
//# sourceMappingURL=smart-router.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"smart-router.js","sourceRoot":"","sources":["../../src/router/smart-router.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;GAGG;AACH,MAAM,CAAN,IAAY,SAOX;AAPD,WAAY,SAAS;IACnB,gCAAmB,CAAA;IACnB,sCAAyB,CAAA;IACzB,gCAAmB,CAAA;IACnB,kCAAqB,CAAA;IACrB,4BAAe,CAAA;IACf,gCAAmB,CAAA;AACrB,CAAC,EAPW,SAAS,KAAT,SAAS,QAOpB;AAiCD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,MAAM,eAAe,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,CAAC;IAEnD,6CAA6C;IAC7C,0EAA0E;IAC1E,MAAM,QAAQ,GAAG;QACf,0EAA0E;QAC1E;YACE,IAAI,EAAE,SAAS,CAAC,KAAK;YACrB,KAAK,EAAE,6CAA6C;YACpD,UAAU,EAAE,IAAI;YAChB,KAAK,EAAE,OAAO;SACf;QACD;YACE,IAAI,EAAE,SAAS,CAAC,KAAK;YACrB,KAAK,EAAE,cAAc;YACrB,UAAU,EAAE,IAAI;YAChB,KAAK,EAAE,eAAe;SACvB;QACD,wFAAwF;QACxF;YACE,IAAI,EAAE,SAAS,CAAC,QAAQ;YACxB,KAAK,EAAE,iDAAiD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gD;IAChD,iDAAiD;IACjD,EAAE;IACF,sBAAsB;IACtB,iDAAiD;IACjD,kCAAkC;IAClC,gDAAgD;IAChD,EAAE;IACF,kCAAkC;IAElC,OAAO,EAAE,CAAC;AACZ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAa;IAC7C,oCAAoC;IACpC,4BAA4B;IAC5B,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,oCAAoC;IACpC,4BAA4B;IAC5B,OAAO,IAAI,CAAC;AACd,CAAC;AAaD,MAAM,UAAU,cAAc,CAAC,KAAa;IAC1C,6CAA6C;IAC7C,4BAA4B;IAC5B,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Rate Limit Middleware
|
|
3
|
-
*
|
|
4
|
-
* Integrates rate limiting into the MCP server.
|
|
5
|
-
* Implements SEC-HIGH-001 and SEC-HIGH-002 from security audit.
|
|
6
|
-
*
|
|
7
|
-
* Security Features:
|
|
8
|
-
* - Fail-closed behavior when Redis unavailable (SEC-HIGH-002)
|
|
9
|
-
* - Tier-based rate limits
|
|
10
|
-
* - Standard rate limit headers
|
|
11
|
-
* - 429 error responses with Retry-After
|
|
12
|
-
*/
|
|
13
|
-
import { Redis } from "ioredis";
|
|
14
|
-
import { RateLimitConfig } from "../utils/rate-limiter.js";
|
|
15
|
-
import { TierName } from "../config/rate-limits.js";
|
|
16
|
-
/**
|
|
17
|
-
* Rate limit headers to include in responses
|
|
18
|
-
*/
|
|
19
|
-
export interface RateLimitHeaders {
|
|
20
|
-
"X-RateLimit-Limit": string;
|
|
21
|
-
"X-RateLimit-Remaining": string;
|
|
22
|
-
"X-RateLimit-Reset": string;
|
|
23
|
-
"Retry-After"?: string;
|
|
24
|
-
"X-RateLimit-Bypass"?: string;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Result from rate limit check
|
|
28
|
-
*/
|
|
29
|
-
export interface RateLimitCheckResult {
|
|
30
|
-
/** Whether the request is allowed */
|
|
31
|
-
allowed: boolean;
|
|
32
|
-
/** Remaining requests in current window */
|
|
33
|
-
remaining: number;
|
|
34
|
-
/** Unix timestamp when limit resets */
|
|
35
|
-
resetAt: number;
|
|
36
|
-
/** Rate limit headers to include in response */
|
|
37
|
-
headers: RateLimitHeaders;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Rate limit error for 429 responses
|
|
41
|
-
*/
|
|
42
|
-
export declare class RateLimitError extends Error {
|
|
43
|
-
readonly statusCode: number;
|
|
44
|
-
readonly retryAfter: number;
|
|
45
|
-
constructor(message: string, statusCode: number, retryAfter: number);
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Middleware options
|
|
49
|
-
*/
|
|
50
|
-
export interface RateLimitMiddlewareOptions {
|
|
51
|
-
/** Whether to allow requests when Redis is unavailable */
|
|
52
|
-
failOpen: boolean;
|
|
53
|
-
/** Rate limit tier to apply */
|
|
54
|
-
tier: TierName;
|
|
55
|
-
/** Custom limits that override tier defaults */
|
|
56
|
-
customLimits?: Record<string, RateLimitConfig>;
|
|
57
|
-
/** Emergency limit for in-memory fallback */
|
|
58
|
-
emergencyLimit?: number;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Rate Limit Middleware
|
|
62
|
-
*
|
|
63
|
-
* Wraps the RateLimiter class and provides:
|
|
64
|
-
* - Standard HTTP headers
|
|
65
|
-
* - Fail-closed behavior
|
|
66
|
-
* - Error handling for 429 responses
|
|
67
|
-
*/
|
|
68
|
-
export declare class RateLimitMiddleware {
|
|
69
|
-
private redis;
|
|
70
|
-
private rateLimiter;
|
|
71
|
-
private options;
|
|
72
|
-
private inMemoryLimits;
|
|
73
|
-
constructor(redis: Redis, options: RateLimitMiddlewareOptions);
|
|
74
|
-
/**
|
|
75
|
-
* Build rate limit configuration from options
|
|
76
|
-
*/
|
|
77
|
-
private buildConfig;
|
|
78
|
-
/**
|
|
79
|
-
* Check rate limit for a request
|
|
80
|
-
*
|
|
81
|
-
* @param userId - User identifier
|
|
82
|
-
* @param operation - MCP tool name
|
|
83
|
-
* @returns Rate limit check result
|
|
84
|
-
* @throws RateLimitError if rate limited or Redis unavailable (fail-closed)
|
|
85
|
-
*/
|
|
86
|
-
checkRateLimit(userId: string, operation: string): Promise<RateLimitCheckResult>;
|
|
87
|
-
/**
|
|
88
|
-
* Check rate limit using Redis
|
|
89
|
-
*/
|
|
90
|
-
private checkRateLimitRedis;
|
|
91
|
-
/**
|
|
92
|
-
* Create bypass result for fail-open mode
|
|
93
|
-
*/
|
|
94
|
-
private createBypassResult;
|
|
95
|
-
/**
|
|
96
|
-
* Get current configuration
|
|
97
|
-
*/
|
|
98
|
-
getConfig(): Record<string, RateLimitConfig>;
|
|
99
|
-
/**
|
|
100
|
-
* Update tier
|
|
101
|
-
*/
|
|
102
|
-
setTier(tier: TierName): void;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Factory function to create rate limit middleware
|
|
106
|
-
*
|
|
107
|
-
* @param redis - Redis client
|
|
108
|
-
* @param options - Middleware options
|
|
109
|
-
*/
|
|
110
|
-
export declare function createRateLimitMiddleware(redis: Redis, options: RateLimitMiddlewareOptions): RateLimitMiddleware;
|
|
111
|
-
/**
|
|
112
|
-
* Format rate limit error for MCP response
|
|
113
|
-
*/
|
|
114
|
-
export declare function formatRateLimitError(error: RateLimitError, operation: string): {
|
|
115
|
-
error: string;
|
|
116
|
-
retryAfter: number;
|
|
117
|
-
operation: string;
|
|
118
|
-
};
|
|
119
|
-
//# sourceMappingURL=rate-limit-middleware.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rate-limit-middleware.d.ts","sourceRoot":"","sources":["../../src/security/rate-limit-middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,KAAK,E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