Skip to content

Commit bef8292

Browse files
committed
refactor: Remove getCachedMessages and getMessagesByImportance methods
- Remove getCachedMessages from MemoryStorage interface, InMemoryStorage, and Memory class - Remove getMessagesByImportance from MemoryStorage interface, InMemoryStorage, and Memory class - Remove related tests (3 tests removed, 17 tests remaining, all passing) - Update usage examples to remove references to removed methods - Build successful with no TypeScript errors
1 parent b0ac8de commit bef8292

File tree

5 files changed

+2
-146
lines changed

5 files changed

+2
-146
lines changed

examples/memory-usage.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,11 @@ async function main() {
195195
cacheControl: { enabled: true, expiresAt: futureDate },
196196
});
197197

198-
const cachedMsgs = await memory.getCachedMessages(cacheThreadId);
199-
console.log(`Cached messages: ${cachedMsgs.length}`);
198+
console.log(`Cache control enabled for message: ${cacheMsg.id}`);
200199

201200
// Invalidate cache when needed
202201
await memory.invalidateCache(cacheThreadId);
203-
const cachedAfterInvalidate = await memory.getCachedMessages(cacheThreadId);
204-
console.log(`Cached messages after invalidation: ${cachedAfterInvalidate.length}`);
202+
console.log(`Cache invalidated for thread: ${cacheThreadId}`);
205203

206204
// Example 12: Message filtering by status and importance
207205
console.log("\n=== Example 12: Message Filtering ===");
@@ -235,10 +233,6 @@ async function main() {
235233

236234
const archivedMsgs = await memory.getMessagesByStatus(filterThreadId, "archived");
237235
console.log(`Archived messages: ${archivedMsgs.length}`);
238-
239-
// Filter by importance
240-
const importantMsgs = await memory.getMessagesByImportance(filterThreadId, 0.7);
241-
console.log(`Messages with importance >= 0.7: ${importantMsgs.length}`);
242236
}
243237

244238
main().catch(console.error);

src/lib/memory/memory.ts

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -344,19 +344,6 @@ export class Memory {
344344

345345
// ===== Cache Management =====
346346

347-
/**
348-
* Get messages with active cache
349-
* @param threadId The thread ID
350-
* @returns Array of cached messages, or empty if storage doesn't support caching
351-
*/
352-
async getCachedMessages(threadId: string): Promise<MemoryMessage[]> {
353-
if (!this.storage.getCachedMessages) {
354-
return [];
355-
}
356-
357-
return await this.storage.getCachedMessages(threadId);
358-
}
359-
360347
/**
361348
* Invalidate cache for messages
362349
* @param threadId The thread ID
@@ -391,27 +378,6 @@ export class Memory {
391378
return await this.storage.getMessagesByStatus(threadId, status);
392379
}
393380

394-
/**
395-
* Get messages by importance threshold
396-
* @param threadId The thread ID
397-
* @param minImportance Minimum importance score (0-1)
398-
* @returns Array of messages meeting importance threshold
399-
*/
400-
async getMessagesByImportance(
401-
threadId: string,
402-
minImportance: number,
403-
): Promise<MemoryMessage[]> {
404-
if (!this.storage.getMessagesByImportance) {
405-
// Fall back to getting all messages and filtering
406-
const all = await this.storage.getMessages(threadId);
407-
return all.filter(
408-
(m) => m.importance !== undefined && m.importance >= minImportance,
409-
);
410-
}
411-
412-
return await this.storage.getMessagesByImportance(threadId, minImportance);
413-
}
414-
415381
// ===== Utility Methods =====
416382

417383
/**

src/lib/memory/storage/in-memory.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -364,17 +364,6 @@ export class InMemoryStorage implements MemoryStorage {
364364

365365
// ===== Cache Management Operations =====
366366

367-
async getCachedMessages(threadId: string): Promise<MemoryMessage[]> {
368-
const messages = await this.getMessages(threadId);
369-
const now = new Date();
370-
371-
return messages.filter((msg) => {
372-
if (!msg.cacheControl?.enabled) return false;
373-
if (!msg.cacheControl.expiresAt) return true;
374-
return msg.cacheControl.expiresAt > now;
375-
});
376-
}
377-
378367
async invalidateCache(threadId: string, beforeDate?: Date): Promise<void> {
379368
const messages = await this.getMessages(threadId);
380369
const cutoff = beforeDate || new Date();
@@ -404,14 +393,4 @@ export class InMemoryStorage implements MemoryStorage {
404393
const messages = await this.getMessages(threadId);
405394
return messages.filter((m) => m.status === status);
406395
}
407-
408-
async getMessagesByImportance(
409-
threadId: string,
410-
minImportance: number,
411-
): Promise<MemoryMessage[]> {
412-
const messages = await this.getMessages(threadId);
413-
return messages.filter(
414-
(m) => m.importance !== undefined && m.importance >= minImportance,
415-
);
416-
}
417396
}

src/lib/memory/storage/interface.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,6 @@ export interface MemoryStorage {
205205

206206
// ===== Cache Management Operations (Optional) =====
207207

208-
/**
209-
* Get messages with active cache
210-
* @param threadId The thread ID
211-
* @returns Array of cached messages
212-
*/
213-
getCachedMessages?(threadId: string): Promise<MemoryMessage[]>;
214-
215208
/**
216209
* Invalidate cache for messages
217210
* @param threadId The thread ID
@@ -231,15 +224,4 @@ export interface MemoryStorage {
231224
threadId: string,
232225
status: string,
233226
): Promise<MemoryMessage[]>;
234-
235-
/**
236-
* Get messages by importance threshold
237-
* @param threadId The thread ID
238-
* @param minImportance Minimum importance score (0-1)
239-
* @returns Array of messages meeting importance threshold
240-
*/
241-
getMessagesByImportance?(
242-
threadId: string,
243-
minImportance: number,
244-
): Promise<MemoryMessage[]>;
245227
}

tests/e2e/memory.test.ts

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -257,50 +257,6 @@ describe("Memory Integration E2E Tests", () => {
257257
expect(messages.length).toBeLessThanOrEqual(4);
258258
});
259259

260-
it("should manage cache control for messages", async () => {
261-
await memory.createThread("thread-1", "user-1");
262-
263-
const saved = await memory.saveMessages("thread-1", "user-1", [
264-
{ role: "user" as const, content: "Cached message" },
265-
{ role: "assistant" as const, content: "Not cached" },
266-
]);
267-
268-
// Enable cache for first message
269-
const futureDate = new Date(Date.now() + 60000); // 1 minute from now
270-
await storage.updateMessage(saved[0].id, {
271-
cacheControl: { enabled: true, expiresAt: futureDate },
272-
});
273-
274-
const cachedMessages = await memory.getCachedMessages("thread-1");
275-
expect(cachedMessages).toHaveLength(1);
276-
expect(cachedMessages[0].message.content).toBe("Cached message");
277-
});
278-
279-
it("should invalidate cache for messages", async () => {
280-
await memory.createThread("thread-1", "user-1");
281-
282-
const saved = await memory.saveMessages("thread-1", "user-1", [
283-
{ role: "user" as const, content: "Cached message" },
284-
]);
285-
286-
// Enable cache
287-
const futureDate = new Date(Date.now() + 60000);
288-
await storage.updateMessage(saved[0].id, {
289-
cacheControl: { enabled: true, expiresAt: futureDate },
290-
});
291-
292-
// Verify cache is active
293-
let cachedMessages = await memory.getCachedMessages("thread-1");
294-
expect(cachedMessages).toHaveLength(1);
295-
296-
// Invalidate cache
297-
await memory.invalidateCache("thread-1");
298-
299-
// Verify cache is invalidated
300-
cachedMessages = await memory.getCachedMessages("thread-1");
301-
expect(cachedMessages).toHaveLength(0);
302-
});
303-
304260
it("should filter messages by status", async () => {
305261
await memory.createThread("thread-1", "user-1");
306262

@@ -324,27 +280,6 @@ describe("Memory Integration E2E Tests", () => {
324280
expect(archivedMessages[0].message.content).toBe("Archived message");
325281
});
326282

327-
it("should filter messages by importance threshold", async () => {
328-
await memory.createThread("thread-1", "user-1");
329-
330-
const saved = await memory.saveMessages("thread-1", "user-1", [
331-
{ role: "user" as const, content: "Low importance" },
332-
{ role: "assistant" as const, content: "Medium importance" },
333-
{ role: "user" as const, content: "High importance" },
334-
]);
335-
336-
// Set importance scores
337-
await storage.updateMessage(saved[0].id, { importance: 0.3 });
338-
await storage.updateMessage(saved[1].id, { importance: 0.6 });
339-
await storage.updateMessage(saved[2].id, { importance: 0.9 });
340-
341-
// Get messages with importance >= 0.5
342-
const importantMessages = await memory.getMessagesByImportance("thread-1", 0.5);
343-
expect(importantMessages).toHaveLength(2);
344-
expect(importantMessages[0].importance).toBeGreaterThanOrEqual(0.5);
345-
expect(importantMessages[1].importance).toBeGreaterThanOrEqual(0.5);
346-
});
347-
348283
it("should handle graceful degradation when storage doesn't support features", async () => {
349284
// Create a storage that doesn't implement optional methods
350285
class BasicStorage extends InMemoryStorage {

0 commit comments

Comments
 (0)