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 deadline for each compaction summary LLM 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;
}
/**
 * Default token reserve for compaction.
 * Leaves headroom for the model's next response + system overhead.
 * Matches the widely-used Pi / Grok-CLI default of 16 384 tokens.
 */
export declare const COMPACTION_RESERVE_TOKENS = 16384;
/** Extra non-output headroom for prompt/cache/accounting overhead. */
export declare const COMPACTION_OVERHEAD_RESERVE_TOKENS = 5000;
/**
 * Calculate the context headroom to reserve before auto-compaction.
 *
 * Use the requested output cap, not the model registry's theoretical maximum.
 * GPT-5.5 over OpenAI Codex has a 272K effective input window but advertises a
 * 128K max output capability; reserving that full amount would compact at
 * ~139K tokens even though the CLI currently requests 16K output tokens.
 */
export declare function getCompactionReserveTokens(maxTokens: number): number;
/**
 * Check if compaction should be triggered.
 *
 * Uses the reserve-based approach (contextWindow − reserveTokens) used by
 * Pi, Grok-CLI, OpenClaw, BrowserOS, and most real-world agent frameworks.
 * A percentage-based threshold is still supported: when both are supplied the
 * more conservative (lower) limit wins.
 */
export declare function shouldCompact(messages: Message[], contextWindow: number, threshold?: number, 
/** Actual API-reported token count — preferred over char-based estimate when available. */
actualTokens?: number, 
/** Fixed token reserve subtracted from contextWindow. Defaults to 16 384. */
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 ~20K 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