src / memory / MemoryService.ts
export interface MemoryEntry {
topic: string;
summary: string;
timestamp: number;
}
export class MemoryService {
private static memory = new Map<string, MemoryEntry[]>();
public static save(topic: string, summary: string): void {
const entry: MemoryEntry = {
topic,
summary,
timestamp: Date.now(),
};
const existing = this.memory.get(topic) || [];
existing.push(entry);
this.memory.set(topic, existing);
}
public static retrieve(topic: string): string {
const entries = this.memory.get(topic);
if (!entries || entries.length === 0) {
return "";
}
return entries
.slice(-3)
.map(entry => `- ${entry.summary}`)
.join("\n");
}
}