const cursorsByKey = new Map();
const freshCursors = () => ({
    restoredMsgKeys: new Set(),
    emittedMsgKeys: new Set(),
    emittedTurnKeys: new Set(),
    lastEventIndex: -1,
    lastMetaJson: '',
});
/** The shared cursors for `key`, created (empty) on first access. @internal */
export function getDiagnosticsCursors(key) {
    let cursors = cursorsByKey.get(key);
    if (!cursors) {
        cursors = freshCursors();
        cursorsByKey.set(key, cursors);
    }
    return cursors;
}
/**
 * Restart the per-conversation cursors for `key` on Clear — a new conversation in
 * the same page load. `lastEventIndex` is intentionally kept: Clear does NOT reset
 * the meta-event buffer, so its indices keep climbing and mustn't be re-emitted.
 *
 * @internal
 */
export function resetDiagnosticsCursorsFor(key) {
    const cursors = getDiagnosticsCursors(key);
    cursors.restoredMsgKeys = new Set();
    cursors.emittedMsgKeys = new Set();
    cursors.emittedTurnKeys = new Set();
}
/**
 * Drop the cursors for `key` entirely — the in-place session switch teardown
 * (GENC-1351 §5.12). Unlike {@link resetDiagnosticsCursorsFor}, this does NOT keep
 * `lastEventIndex`: a switch also tears down the session's meta-event buffer (its
 * indices restart at 0 on a later return), so a kept high-water index would skip
 * every event of the resumed session. A return re-creates fresh cursors on first
 * access.
 *
 * @internal
 */
export function deleteDiagnosticsCursorsFor(key) {
    cursorsByKey.delete(key);
}
/** Drop all cursors — test isolation only. @internal */
export function clearDiagnosticsCursorRegistry() {
    cursorsByKey.clear();
}
