import { createHash } from "node:crypto";
export function hashMemoryEventInput(event) {
    const stablePayload = JSON.stringify({
        type: event.type,
        summary: event.summary.trim(),
        content: event.content?.trim() ?? "",
        filePaths: [...(event.filePaths ?? [])].sort(),
        tags: [...(event.tags ?? [])].sort(),
        metadata: event.metadata
            ? Object.entries(event.metadata).sort(([left], [right]) => left.localeCompare(right))
            : [],
    });
    return createHash("sha256").update(stablePayload).digest("hex").slice(0, 16);
}
export class MemoryDedupeWindow {
    seen = new Set();
    order = [];
    maxEntries;
    constructor(maxEntries = 500) {
        this.maxEntries = maxEntries;
    }
    shouldRecord(event) {
        const hash = hashMemoryEventInput(event);
        if (this.seen.has(hash))
            return false;
        this.seen.add(hash);
        this.order.push(hash);
        while (this.order.length > this.maxEntries) {
            const removed = this.order.shift();
            if (removed)
                this.seen.delete(removed);
        }
        return true;
    }
}
//# sourceMappingURL=dedupe.js.map