import type { SearchResult } from "./providers/types.js"; export function deduplicateResults(results: SearchResult[]): SearchResult[] { const seen = new Set(); return results.filter((r) => { const key = r.url || r.title; if (seen.has(key)) return false; seen.add(key); return true; }); } export class SafeMemoryCache { private cache = new Map(); constructor(private ttlMs: number, private maxSize: number) {} get(key: string): T | undefined { const entry = this.cache.get(key); if (!entry) return undefined; if (Date.now() > entry.expiry) { this.cache.delete(key); return undefined; } return entry.value; } set(key: string, value: T): void { if (this.cache.size >= this.maxSize) { const firstKey = this.cache.keys().next().value; if (firstKey) this.cache.delete(firstKey); } this.cache.set(key, { value, expiry: Date.now() + this.ttlMs }); } }