/**
 * Session Registry
 *
 * Pure in-memory state container for the interactive session service.
 * Owns three maps:
 *
 * 1. `sessions`                 — live session state indexed by sessionId.
 * 2. `stoppedAgentSessionIds`   — agent SDK session ids cached after a
 *    session stops so the next boot can resume the same SDK conversation.
 * 3. `activeStepByFeature`      — currently-active workflow step id per
 *    feature scope, consulted by `persistMessage` so every row is tagged
 *    with the right `stepId`.
 *
 * No business logic. No repo access. No logger. No imports from the
 * application layer beyond the `StreamChunk` / `UnsubscribeFn` types
 * that `SessionState` needs (and those are type-only).
 */
/**
 * Plain in-memory state container. Methods are typed delegates over
 * the underlying `Map`s plus a few convenience lookups.
 */
export class SessionRegistry {
    sessions = new Map();
    stoppedAgentSessionIds = new Map();
    activeStepByFeature = new Map();
    // ── Session state ──
    get(sessionId) {
        return this.sessions.get(sessionId);
    }
    set(sessionId, state) {
        this.sessions.set(sessionId, state);
    }
    delete(sessionId) {
        this.sessions.delete(sessionId);
    }
    has(sessionId) {
        return this.sessions.has(sessionId);
    }
    values() {
        return this.sessions.values();
    }
    /** First in-memory state whose `featureId` matches, or undefined. */
    findActiveStateForFeature(featureId) {
        for (const state of this.sessions.values()) {
            if (state.featureId === featureId)
                return state;
        }
        return undefined;
    }
    // ── Stopped agent session id cache ──
    cacheStoppedAgentSessionId(featureId, agentSessionId) {
        this.stoppedAgentSessionIds.set(featureId, agentSessionId);
    }
    /** Read-only access — does NOT remove the cached entry. */
    takeStoppedAgentSessionId(featureId) {
        return this.stoppedAgentSessionIds.get(featureId);
    }
    deleteStoppedAgentSessionId(featureId) {
        this.stoppedAgentSessionIds.delete(featureId);
    }
    // ── Active workflow step tracking ──
    setActiveStep(featureId, stepId) {
        this.activeStepByFeature.set(featureId, stepId);
    }
    clearActiveStep(featureId) {
        this.activeStepByFeature.delete(featureId);
    }
    getActiveStep(featureId) {
        return this.activeStepByFeature.get(featureId);
    }
}
