/**
 * Session Isolation
 *
 * OpenClaw-inspired session scoping for multi-channel DM handling.
 *
 * Session scopes:
 * - per-channel-peer: Separate session per (channel, peer) pair
 *   Prevents cross-user context leakage
 * - per-account-channel-peer: Per (account, channel, peer) triple
 *   For multiple bot accounts on the same channel
 * - global: Single session for all peers (default for CLI)
 *
 * Usage:
 * ```typescript
 * const isolator = getSessionIsolator();
 *
 * // Get session key for a message
 * const sessionKey = isolator.getSessionKey(message);
 *
 * // Check if sessions are isolated
 * isolator.areIsolated(sessionKey1, sessionKey2); // true if different scopes
 * ```
 */
import { EventEmitter } from 'events';
import type { InboundMessage, ChannelType } from './index.js';
import type { IdentityLinker } from './identity-links.js';
/**
 * Session scope determines how sessions are partitioned
 */
export type SessionScope = 'global' | 'per-channel' | 'per-channel-peer' | 'per-account-channel-peer';
/**
 * Session key components
 */
export interface SessionKeyComponents {
    /** Bot account ID (for multi-account setups) */
    accountId?: string;
    /** Channel type (telegram, discord, etc.) */
    channelType: ChannelType;
    /** Channel ID */
    channelId: string;
    /** Peer/user ID */
    peerId: string;
}
/**
 * Session isolation configuration
 */
export interface SessionIsolationConfig {
    /** Default session scope */
    defaultScope: SessionScope;
    /** Per-channel scope overrides */
    channelScopes?: Partial<Record<ChannelType, SessionScope>>;
    /** Maximum sessions per scope */
    maxSessions: number;
    /** Session TTL in milliseconds (0 = no expiry) */
    sessionTtlMs: number;
    /** Enable session activity tracking */
    trackActivity: boolean;
    /** Optional identity linker for cross-channel identity unification */
    identityLinker?: IdentityLinker;
}
/**
 * Session metadata
 */
export interface SessionInfo {
    /** Computed session key */
    key: string;
    /** Key components */
    components: SessionKeyComponents;
    /** Session scope used */
    scope: SessionScope;
    /** Creation timestamp */
    createdAt: Date;
    /** Last activity timestamp */
    lastActivityAt: Date;
    /** Message count */
    messageCount: number;
}
export declare const DEFAULT_SESSION_ISOLATION_CONFIG: SessionIsolationConfig;
export declare class SessionIsolator extends EventEmitter {
    private config;
    private sessions;
    private cleanupTimer;
    constructor(config?: Partial<SessionIsolationConfig>);
    /**
     * Set or replace the identity linker used for canonical identity resolution
     */
    setIdentityLinker(linker: IdentityLinker | undefined): void;
    /**
     * Generate session key for an inbound message.
     *
     * If an identity linker is configured, the sender's peer ID is resolved
     * to its canonical identity ID before computing the session key. This
     * allows the same person on different channels to share a session when
     * their identities are linked.
     */
    getSessionKey(message: InboundMessage, accountId?: string): string;
    /**
     * Generate session key from explicit components
     */
    computeSessionKey(components: SessionKeyComponents): string;
    /**
     * Get the scope for a given channel type
     */
    getScopeForChannel(channelType: ChannelType): SessionScope;
    /**
     * Check if two session keys are isolated from each other
     */
    areIsolated(key1: string, key2: string): boolean;
    /**
     * Get session info
     */
    getSession(key: string): SessionInfo | undefined;
    /**
     * List all active sessions
     */
    listSessions(): SessionInfo[];
    /**
     * List sessions for a specific channel
     */
    listSessionsForChannel(channelType: ChannelType): SessionInfo[];
    /**
     * List sessions for a specific peer across all channels
     */
    listSessionsForPeer(peerId: string): SessionInfo[];
    /**
     * Remove a session
     */
    removeSession(key: string): boolean;
    /**
     * Set scope for a specific channel
     */
    setChannelScope(channelType: ChannelType, scope: SessionScope): void;
    /**
     * Clean up expired sessions
     */
    private cleanupExpiredSessions;
    /**
     * Evict the oldest session when at capacity
     */
    private evictOldestSession;
    /**
     * Get isolation statistics
     */
    getStats(): {
        totalSessions: number;
        sessionsByScope: Record<SessionScope, number>;
        sessionsByChannel: Record<string, number>;
        oldestSession: Date | null;
        newestSession: Date | null;
    };
    /**
     * Dispose the isolator
     */
    dispose(): void;
}
export declare function getSessionIsolator(config?: Partial<SessionIsolationConfig>): SessionIsolator;
export declare function resetSessionIsolator(): void;
