import type { ContextOverrides, ResolvedSessionProfile, SessionData, TabState } from '../types'; import type { ResolvedContextOptions } from '../utils/presets'; import { type PoolEntry } from './context-pool'; export interface CanonicalProfile { resolvedOverrides: ResolvedContextOptions | null; hash: string; establishedAt: number; } export interface EstablishedSessionProfile { userId: string; sessionKey: string; signature: string; resolvedProfile: ResolvedSessionProfile; establishedAt: number; } export interface SessionProfileLaunchSettings { contextOverrides: ContextOverrides | null; proxy: ResolvedSessionProfile['proxy']; } interface CleanupSessionsForUserIdOptions { allowInternalSessionKey?: boolean; } export declare function __getUserConcurrencyStateForTests(userId: string): { active: number; queueLength: number; } | null; export declare function __getSessionsMapForTests(): Map; export declare function withUserLimit(userId: string, maxConcurrent: number, operation: () => Promise, operationTimeoutMs?: number): Promise; export declare function cleanupSessionsForUserId(userId: string, reason: string, clearCanonical?: boolean, options?: CleanupSessionsForUserIdOptions): void; export declare const SESSION_TIMEOUT_MS: number; export declare const MAX_SESSIONS: number; export declare const MAX_TABS_PER_SESSION: number; export declare function normalizeUserId(userId: unknown): string; export declare function getSessionMapKey(userId: unknown, contextOverridesOrSessionKey: ContextOverrides | null | undefined | string, profileSignature?: string): string; export declare function getEstablishedSessionProfile(userId: unknown, sessionKey: string): EstablishedSessionProfile | undefined; export declare function hasDefaultSessionProfileRuntime(userId: unknown, sessionKey: string): boolean; export declare function claimDefaultSessionProfileRuntime(userId: unknown, sessionKey: string): boolean; export declare function clearDefaultSessionProfileClaim(userId: unknown, sessionKey: string): void; export declare function getSessionProfileLaunchSettings(userId: unknown, profileKey: string): SessionProfileLaunchSettings | undefined; export declare function getCanonicalProfile(userId: unknown): CanonicalProfile | undefined; export declare function hasCanonicalProfile(userId: unknown): boolean; /** * Try to acquire the first-create mutex for a user. * Returns { acquired: true } if we are the first creator (mutex acquired). * Returns { acquired: false, wait: Promise } if another request is first-creating. * The promise resolves to true (committed) or false (rolled back). * If canonical already exists (committed), returns { acquired: false, wait: resolved-true }. */ export declare function acquireFirstCreateMutex(userId: unknown): { acquired: true; } | { acquired: false; wait: Promise; }; /** * Commit: store the canonical profile and release the mutex (signaling success to waiters). */ export declare function commitCanonicalProfile(userId: unknown, resolved: ResolvedContextOptions | null): CanonicalProfile; /** * Rollback: release the mutex (signaling failure to waiters). No canonical is stored. */ export declare function rollbackCanonicalMutex(userId: unknown): void; /** * Create a CanonicalProfile object without storing it (for hash comparison during first-create). */ export declare function createCanonicalProfile(resolved: ResolvedContextOptions | null): CanonicalProfile; export declare function clearCanonicalProfile(userId: unknown): void; /** * Store or validate a session profile for a specific userId + sessionKey combination. * Returns the established profile if successful. * Throws if a conflicting profile is already established for the same userId + sessionKey. */ export declare function establishSessionProfile(userId: unknown, sessionKey: string, profile: ResolvedSessionProfile): EstablishedSessionProfile; export declare function clearSessionProfile(userId: unknown, sessionKey: string): void; export declare function acquireSessionProfileCreateMutex(userId: unknown, sessionKey: string, signature: string): { acquired: true; release: (committed: boolean) => void; } | { acquired: false; wait: Promise; }; export declare function waitForSessionProfileCreate(userId: unknown, sessionKey: string): Promise; export declare function rollbackSessionProfileRuntime(userId: unknown, sessionKey: string, profileSignature: string): Promise; export declare function getSessionsForUser(userId: unknown): Array<[string, SessionData]>; export declare function getAllSessions(): Map; export declare function countTotalTabsForSessions(sessionsForUser?: Array<[string, SessionData]>): number; export declare function getLifecycleSessionSnapshot(): { liveSessions: number; liveTabs: number; stagedCreates: number; }; export declare function getSessionsSnapshot(): Map; export declare function getTabGroup(session: SessionData, sessionKey: string): Map; declare function findTab(session: SessionData, tabId: string): { tabState: TabState; listItemId: string; group: Map; } | null; export declare function unindexSessionTabs(session: SessionData): void; export declare function findTabById(tabId: string, userId: unknown): (ReturnType & { sessionKey: string; session: SessionData; }) | null; export interface StagedFirstUse { session: SessionData; contextEntry: PoolEntry; generation: string; } export declare function createStagedSession(userId: unknown, contextOverrides?: ContextOverrides | null, sessionKey?: string): Promise; export declare function commitStagedFirstUse(userId: unknown, session: SessionData, contextOverrides: ContextOverrides | null, tabInfo: { tabId: string; sessionMapKey: string; sessionKey: string; tabState: TabState; }, generation: string): boolean; export declare function rollbackStagedFirstUse(userId: unknown, generation: string): Promise; export declare function getSession(userId: unknown, contextOverrides?: ContextOverrides | null, sessionKey?: string): Promise; export declare function indexTab(tabId: string, sessionKey: string): void; export declare function unindexTab(tabId: string): void; export declare function clearAllState(): void; export interface CloseSessionsForUserOptions { clearProfiles?: boolean; } export declare function closeSessionsForUser(userId: string, options?: CloseSessionsForUserOptions): Promise; export declare function closeAllSessions(): Promise; export declare function startCleanupInterval(): NodeJS.Timeout; export declare function stopCleanupInterval(): void; /** * Stage 1 idle cleanup: close runtime state (contexts, session data) for users with no tabs. * Does NOT clear stored session profiles - they survive idle cleanup. * Does NOT exit the daemon - that is Stage 2 (Task 4). * @param sessionSnapshot Snapshot of sessions map taken before cleanup started * @param contextSnapshot Snapshot of context pool entries taken before cleanup started * @param cleanupStartedMs Timestamp when cleanup was triggered (used to avoid closing newly-created contexts) */ export declare function runLifecycleIdleCleanup(sessionSnapshot: Map, contextSnapshot: Map, cleanupStartedMs: number): Promise<{ closedUsers: string[]; }>; export {}; //# sourceMappingURL=session.d.ts.map