import { PersistentStore } from '../state/persistent-store.js';
import type { RuntimeEventBus } from '../runtime/events/index.js';
import { RouteBindingManager } from '../channels/index.js';
import type { AutomationRouteBinding } from '../automation/routes.js';
import type { SharedSessionCompletion, SharedSessionContinuationRunner, SharedSessionInputRecord } from './session-intents.js';
import type { FindSharedSessionOptions, SharedSessionMessage, SharedSessionParticipant, SharedSessionRecord, SharedSessionSubmission, SteerSharedSessionMessageInput, SubmitSharedSessionMessageInput } from './session-types.js';
import { type SharedSessionAgentStatusProvider, type SharedSessionEventPublisher, type SharedSessionMessageSender, type SharedSessionStoreSnapshot } from './session-broker-helpers.js';
export declare class SharedSessionBroker {
    private readonly store;
    private readonly routeBindings;
    private readonly agentStatusProvider;
    private readonly messageSender;
    private readonly sessions;
    private readonly messages;
    private readonly inputs;
    private readonly runtimeBusBridge;
    private eventPublisher;
    private continuationRunner;
    private loaded;
    private _gcInterval;
    /** Default idle threshold for zero-message sessions (ms). */
    private readonly _idleEmptyMs;
    /** Default idle threshold for sessions with content (ms). */
    private readonly _idleLongMs;
    /**
     * @param config.idleEmptyMs - Idle timeout for empty (0-message) sessions (default: 10 minutes).
     * @param config.idleLongMs  - Idle timeout for sessions with content (default: 24 hours).
     */
    constructor(config: {
        readonly store?: PersistentStore<SharedSessionStoreSnapshot> | undefined;
        readonly storePath?: string | undefined;
        readonly routeBindings: RouteBindingManager;
        readonly agentStatusProvider: SharedSessionAgentStatusProvider;
        readonly messageSender: SharedSessionMessageSender;
        readonly idleEmptyMs?: number | undefined;
        readonly idleLongMs?: number | undefined;
    });
    setEventPublisher(publisher: SharedSessionEventPublisher | null): void;
    /**
     * Returns the number of sessions that currently have a pending input
     * (i.e. pendingInputCount > 0). Used by WorkspaceSwapManager to determine
     * whether the daemon is busy before allowing a workspace swap.
     */
    countBusySessions(): number;
    /**
     * Gracefully stop the broker by clearing the GC interval, tearing down bus
     * subscriptions, and persisting state. Call from DaemonServer.stop().
     */
    stop(): Promise<void>;
    /**
     * Wire the broker to a RuntimeEventBus so agent terminal events automatically
     * reconcile session inputs and task state.
     *
     * Call once after both the broker and the bus are constructed. Returns an
     * unsubscribe function that tears down the subscriptions.
     *
     * @param bus - The active RuntimeEventBus.
     * @param sessionResolver - Maps agentId → sessionId for the active session.
     *   Return `null` when the agent is not associated with a shared session.
     */
    attachRuntimeBus(bus: RuntimeEventBus, sessionResolver: (agentId: string) => string | null): () => void;
    setContinuationRunner(runner: SharedSessionContinuationRunner | null): void;
    start(): Promise<void>;
    listSessions(limit?: number): SharedSessionRecord[];
    getSession(sessionId: string): SharedSessionRecord | null;
    findPreferredSession(options?: FindSharedSessionOptions): Promise<SharedSessionRecord | null>;
    ensureSession(input?: {
        readonly sessionId?: string | undefined;
        readonly title?: string | undefined;
        readonly metadata?: Record<string, unknown> | undefined;
        readonly routeBinding?: AutomationRouteBinding | undefined;
        readonly participant?: SharedSessionParticipant | undefined;
    }): Promise<SharedSessionRecord>;
    getMessages(sessionId: string, limit?: number): SharedSessionMessage[];
    getInputs(sessionId: string, limit?: number): SharedSessionInputRecord[];
    createSession(input?: {
        readonly id?: string | undefined;
        readonly title?: string | undefined;
        readonly metadata?: Record<string, unknown> | undefined;
        readonly routeBinding?: AutomationRouteBinding | undefined;
        readonly participant?: SharedSessionParticipant | undefined;
        readonly kind?: SharedSessionRecord['kind'] | undefined;
    }): Promise<SharedSessionRecord>;
    closeSession(sessionId: string): Promise<SharedSessionRecord | null>;
    reopenSession(sessionId: string): Promise<SharedSessionRecord | null>;
    bindAgent(sessionId: string, agentId: string): Promise<SharedSessionRecord | null>;
    submitMessage(input: SubmitSharedSessionMessageInput): Promise<SharedSessionSubmission>;
    steerMessage(input: SteerSharedSessionMessageInput): Promise<SharedSessionSubmission>;
    followUpMessage(input: SubmitSharedSessionMessageInput): Promise<SharedSessionSubmission>;
    appendSystemMessage(sessionId: string, body: string, metadata?: Record<string, unknown>): Promise<SharedSessionMessage | null>;
    /**
     * Persist a companion follow-up message to the shared session message log
     * without spawning an agent. Called by the companion main-chat send path
     * (kind='message') so that GET /api/sessions/:id/messages surfaces the message
     * and TUI subscribers can render it.
     */
    appendCompanionMessage(sessionId: string, input: {
        readonly messageId: string;
        readonly body: string;
        readonly timestamp: number;
        readonly source: string;
        readonly metadata?: Readonly<Record<string, unknown>> | undefined;
    }): Promise<SharedSessionMessage | null>;
    completeAgent(sessionId: string, agentId: string, body: string, metadata?: Record<string, unknown>): Promise<SharedSessionCompletion | null>;
    cancelInput(sessionId: string, inputId: string): Promise<SharedSessionInputRecord | null>;
    rebindRoute(bindingId: string, sessionId: string): Promise<SharedSessionRecord | null>;
    private appendMessage;
    private attachParticipantAndRoute;
    private resolveActiveAgentId;
    private resolveBinding;
    private buildContinuationTask;
    private persist;
    private publishUpdate;
    private publishInputLifecycleEvent;
    private handleIntent;
    private recordInput;
    private updateInput;
    private claimNextQueuedInput;
    private finalizeAgentInputs;
    private runQueuedFollowUp;
    private sessionInputStore;
    private messageStore;
    private touch;
    private refreshPendingInputCount;
    /**
     * Periodic idle-session GC sweep.
     *
     * Policy:
     * - Sessions with messageCount === 0 AND no active agent AND idle longer than
     *   `_idleEmptyMs` (default 10min) are closed with reason `idle-empty`.
     * - Sessions with messageCount > 0 AND no active agent AND idle longer than
     *   `_idleLongMs` (default 24h) are closed with reason `idle-long`.
     *
     * "Idle" is measured from `lastActivityAt` (updated on createInput/bindAgent/
     * appendMessage). Sessions with an active agent are never GC'd.
     */
    private gcSweep;
}
//# sourceMappingURL=session-broker.d.ts.map