Project Files
src / promotionDedup.ts
// Module-level in-memory dedup cache for vision promotion.
// Prevents both title-gen and main-response from injecting the same attachment set
// within the same logical user turn.
// Source pattern: draw-things-chat/src/orchestrator.ts (recentlyInjected Map)
const DEDUP_TTL_MS = 10_000;
const recentlyInjected = new Map<string, number>(); // key → timestamp
/**
* Returns true if this key was NOT recently injected (→ should proceed with injection).
* Returns false if injection happened within the TTL (→ should skip).
* Always marks the key as injected on first call.
*/
export function checkAndMarkInjected(key: string): boolean {
const now = Date.now();
// Prune stale entries
for (const [k, ts] of recentlyInjected) {
if (now - ts > DEDUP_TTL_MS) recentlyInjected.delete(k);
}
if (recentlyInjected.has(key)) return false; // already injected this turn
recentlyInjected.set(key, now);
return true;
}
export function makeDedupKey(chatWd: string, attachmentNs: number[]): string {
return `${chatWd}:${[...attachmentNs].sort((a, b) => a - b).join(",")}`;
}