import { compact, type CompactionSettings } from '@earendil-works/pi-agent-core'; import type { Model } from '@earendil-works/pi-ai'; import { type ContextBudgetSettings } from './context-budget.js'; export type CompactionActivityEmitter = (step: { id: string; kind: 'status'; label: string; status: 'running' | 'success' | 'error'; startedAt: number; finishedAt?: number; preview?: string; }) => void; export interface TranscriptCompactionSession { getBranch(): Promise; buildContext(): Promise<{ messages: import('@earendil-works/pi-agent-core').AgentMessage[]; }>; appendCompaction(summary: string, firstKeptEntryId: string, tokensBefore: number, details: unknown, fromHook: boolean): Promise; } export interface RunTranscriptCompactionArgs { session: TranscriptCompactionSession; model: Model; getApiKeyAndHeaders: () => Promise<{ apiKey: string; headers?: Record; }>; budget: ContextBudgetSettings; /** Used for costKnown accounting. */ costKnown: boolean; thinkingLevel: Parameters[6]; signal: AbortSignal; customInstructions: string | undefined; emitActivity: CompactionActivityEmitter; /** Log label: 'pre-turn' | 'mid-turn'. */ reason: 'pre-turn' | 'mid-turn'; } export interface RunTranscriptCompactionResult { compacted: boolean; tokensBefore?: number; approxIn: number; approxOut: number; estimatedCostUsd?: number; } /** Whether context is over the late-compaction line (same as pre-turn). */ export declare function contextExceedsReserve(contextTokens: number, contextWindow: number, compaction: CompactionSettings): boolean; /** * Mid-turn gate (with foresight): after tools land, project the next hop * (`current + lookahead`). If emergency clearing still cannot bring the * *projected* total under the hard line (`window − reserve`), run transcript * compact before the next model call. */ export declare function shouldRunMidTurnCompaction(messages: import('@earendil-works/pi-agent-core').AgentMessage[], budget: ContextBudgetSettings, contextWindow: number): boolean; export declare function measureContextTokens(session: TranscriptCompactionSession): Promise; /** * Run one compaction cycle. Best-effort: throws on failure so the caller can * log and continue the turn. Emits Compacting context activity steps. */ export declare function runTranscriptCompaction(args: RunTranscriptCompactionArgs): Promise; //# sourceMappingURL=transcript-compaction.d.ts.map