/** Bridge factories wiring `SessionCompaction` + recovery to a host's session/agent. */
import type { AssistantMessage, Model } from '../../ai/types.js';
import type { AgentModelRegistry } from '../../contracts/agent-model.js';
import type { AgentSessionContext, AgentSessionEntry } from '../../contracts/agent-session-store.js';
import type { HeartbeatWrapFn } from '../agent-engine.js';
import type { AgentController, AgentMessage } from '../index.js';
import type { CompactionResult } from './compaction/index.js';
import { SessionCompaction, type CompactionActions } from './session-compaction.js';
export interface TriggerCompactionOptions {
    /** Per-turn heartbeat wrap. Captured synchronously by the caller while the
     *  agent loop is still active; outlives the loop's _activeWrap clear. */
    heartbeatWrap?: HeartbeatWrapFn;
}
/** Subset of an extension runner that compaction consults. */
export interface CompactionExtensionRunner {
    hasHandlers(eventType: string): boolean;
    emit(event: unknown): Promise<unknown>;
}
/** Result an extension's `session_before_compact` handler may return. */
export interface CompactionExtensionResult {
    cancel?: boolean;
    compaction?: CompactionResult;
}
/** Recovery actions returned by `createErrorRecoveryActions`. Implementation in `app/`. */
export interface ErrorRecoveryActions {
    removeLastAssistantMessage(): void;
    continue(): Promise<void>;
    runCompaction(keepRecentTokens: number): Promise<boolean>;
    switchToFallbackModel(fallbackModel: string, stripThinking: boolean): Promise<boolean>;
}
/** Narrow session-store contract compaction depends on. CLI + embedded both satisfy it. */
export interface CompactionSessionStore {
    appendCompaction<T = unknown>(summary: string, firstKeptEntryId: string, tokensBefore: number, details?: T, fromHook?: boolean): string;
    buildSessionContext(): AgentSessionContext;
    getBranch(): AgentSessionEntry[];
    getEntries(): AgentSessionEntry[];
}
export interface CompactionActionsDeps {
    extensionRunner: () => CompactionExtensionRunner | undefined;
    sessionManager: CompactionSessionStore;
    agent: AgentController;
    removeLastErrorGroup: () => void;
    onMessagesReplaced?: (context: AgentSessionContext) => void;
}
export interface ErrorRecoveryActionsDeps {
    agent: AgentController;
    model: () => Model<any> | undefined;
    modelRegistry: AgentModelRegistry;
    sessionManager: CompactionSessionStore;
    compaction: SessionCompaction;
    compactionActions: () => CompactionActions;
    removeLastErrorGroup: () => void;
    setModel: (model: Model<any>) => Promise<void>;
    onAgentMessagesReplaced?: (messages: readonly AgentMessage[]) => void;
}
export interface CompactionTriggerDeps {
    model: () => Model<any> | undefined;
    modelRegistry: AgentModelRegistry;
    sessionManager: CompactionSessionStore;
    compaction: SessionCompaction;
    compactionActions: CompactionActions;
    agent: AgentController;
    /**
     * Optional per-turn override for the compaction decision's context window.
     * Resolved by the embedded surface from `baseTokenLimit` /
     * `contextSize=extended`. CLI returns `undefined` and falls back to the
     * model's registered window.
     */
    getContextWindowOverride?: () => number | undefined;
    onAgentMessagesReplaced?: (messages: readonly AgentMessage[]) => void;
}
/** Build CompactionActions that bridge SessionCompaction to AgentSession internals. */
export declare function createCompactionActions(deps: CompactionActionsDeps): CompactionActions;
/** Build ErrorRecoveryActions that bridge SessionErrorRecovery to AgentSession internals. */
export declare function createErrorRecoveryActions(deps: ErrorRecoveryActionsDeps): ErrorRecoveryActions;
/** Check compaction decision and trigger if needed.
 *
 * `opts.heartbeatWrap` is the per-turn heartbeat wrap captured *synchronously*
 * by the caller before the agent loop's finally clears it. Forwarded into
 * runAuto so the LLM compaction + persist work emits compaction_* telemetry. */
export declare function triggerCompactionIfNeeded(deps: CompactionTriggerDeps, msg: AssistantMessage, skipAbortedCheck: boolean, opts?: TriggerCompactionOptions): Promise<void>;
//# sourceMappingURL=compaction-bridge.d.ts.map