import { type Message, type Provider, type ContentPart } from "@kenkaiiii/gg-ai";
/** Max retries for empty LLM responses during summarization. */
export declare const MAX_SUMMARY_RETRIES = 2;
/**
 * Local INACTIVITY deadline for each compaction summary LLM attempt: the timer
 * resets on every stream event, so it only fires after this long with no sign
 * of life from the provider. A hard total deadline here used to kill every
 * large summary mid-generation (a multi-hundred-K-token input can stream for
 * well over 30s) — ~90% of summary attempts were falling back to the
 * low-quality extractive summary. Hung requests still fail fast: no first
 * token within the window aborts the attempt.
 */
export declare const SUMMARY_ATTEMPT_TIMEOUT_MS = 30000;
export interface CompactionResult {
    /** Whether messages were actually reduced. */
    compacted: boolean;
    /** Why compaction was skipped (only set when compacted is false). */
    reason?: string;
    originalCount: number;
    newCount: number;
    tokensBeforeEstimate: number;
    tokensAfterEstimate: number;
    /** How the collapse shifted message positions, so callers can move transcript
     *  anchors (Ken turns, autopilot verdicts, app markers) onto the rewritten
     *  message list instead of leaving them pointing at pre-compaction indices.
     *  Only set when `compacted` is true. */
    anchorRemap?: CompactionAnchorRemap;
}
/**
 * Position bookkeeping for a compaction: the leading `summarizedCount`
 * non-system messages were replaced by `prefixCount` non-system messages (the
 * summary, plus the assistant acknowledgement when one is emitted). Everything
 * after the collapsed region is kept verbatim, so it merely shifts.
 */
export interface CompactionAnchorRemap {
    /** Non-system messages that were folded into the summary. */
    summarizedCount: number;
    /** Non-system messages the summary block occupies in the new list. */
    prefixCount: number;
    /** Non-system messages in the FINAL compacted list. A hard ceiling for
     *  remapped anchors: tool-pairing repair and the trailing-assistant pop can
     *  shorten the retained tail after the collapse is decided. */
    newNonSystemCount: number;
}
/**
 * @deprecated Compaction now uses only the configured context-window percentage.
 * Retained for source compatibility until the next major release.
 */
export declare const COMPACTION_RESERVE_TOKENS = 16384;
/** @deprecated Retained for source compatibility until the next major release. */
export declare const COMPACTION_OVERHEAD_RESERVE_TOKENS = 5000;
/**
 * @deprecated Compaction no longer reserves output tokens when choosing its boundary.
 * Retained for source compatibility until the next major release.
 */
export declare function getCompactionReserveTokens(maxTokens: number): number;
/**
 * Check if compaction should be triggered.
 *
 * The boundary is the first whole token at or above the configured percentage
 * of the active transport's context window. Output-token ceilings do not move it.
 */
export declare function shouldCompact(messages: Message[], contextWindow: number, threshold?: number, 
/** Actual API-reported token count — preferred over char-based estimate when available. */
actualTokens?: number, 
/** @deprecated Output-token reserves no longer affect compaction decisions. */
_reserveTokens?: number): boolean;
/**
 * Find the index where recent messages should start, given a token budget.
 * Walks backward from the end, accumulating token estimates, and returns the
 * first index that fits within the budget. Never cuts at index 0 (system message).
 * Avoids splitting tool_call / tool_result pairs.
 */
export declare function findRecentCutPoint(messages: Message[], tokenBudget: number): number;
/** Maximum retained characters for each string argument in a completed tool call. */
export declare const HISTORICAL_TOOL_ARG_MAX_CHARS = 8000;
/**
 * Clone recent assistant tool-call messages and cap large historical arguments.
 * IDs, tool names, and short arguments remain byte-for-byte unchanged.
 */
export declare function compactHistoricalToolCallArgs(messages: Message[]): Message[];
/**
 * Prepare conversation messages for the summarizer by converting tool_call and
 * tool_result blocks to plain text, stripping thinking blocks, and truncating
 * large content. Converting tool blocks to text eliminates the tool_use/tool_result
 * pairing constraint entirely — the summarizer sees only user/assistant text messages.
 * Returns lightweight copies — the originals are not mutated.
 */
export declare function prepareMessagesForSummary(msgs: Message[]): Message[];
/**
 * Select messages that fit within a token budget for the summary LLM call.
 * Walks forward from the start, accumulating messages until the budget is
 * exceeded. Ensures tool_use / tool_result pairs are never split: if the last
 * selected message is an assistant with tool_call blocks, it is removed so the
 * API never sees an orphaned tool_use without a matching tool_result.
 */
export declare function selectMessagesInBudget(msgs: Message[], tokenBudget: number): Message[];
/**
 * Build a fallback summary from file operations and message roles when the
 * LLM summary call fails or returns empty.
 */
export declare function buildFallbackSummary(middleMessages: Message[], fileOps: {
    read: Set<string>;
    modified: Set<string>;
}): string;
/**
 * Extract summary text from an LLM response.
 */
export declare function extractSummaryText(content: string | ContentPart[]): string;
/**
 * Compact a conversation by summarizing older messages via LLM.
 *
 * Follows the pattern used by Continue and Nao: sends the actual conversation
 * messages to the summarizer (not a serialized string), bookended by a system
 * prompt and a "summarize this" user prompt. This lets the LLM see the real
 * message structure — roles, tool calls, tool results — and produce a much
 * better summary.
 *
 * - Keeps the system message (index 0) intact.
 * - Keeps the most recent ~8K tokens of conversation intact.
 * - Summarizes everything in between using an appropriate model.
 * - Tool results are truncated and thinking blocks stripped in the summary call.
 * - Messages are token-budgeted to avoid overflowing the summarizer's context.
 * - Retries on empty responses, falls back to extractive summary if all fail.
 */
export declare function compact(messages: Message[], options: {
    provider: Provider;
    model: string;
    apiKey?: string;
    accountId?: string;
    projectId?: string;
    baseUrl?: string;
    contextWindow: number;
    signal?: AbortSignal;
    approvedPlanPath?: string;
}): Promise<{
    messages: Message[];
    result: CompactionResult;
}>;
//# sourceMappingURL=compactor.d.ts.map