/**
 * Context Window Guard
 *
 * Inspired by OpenClaw's context-window-guard.ts
 * Provides token limit management with warnings and hard limits.
 */
import { EventEmitter } from 'events';
/** Minimum tokens below which execution is blocked */
export declare const CONTEXT_WINDOW_HARD_MIN_TOKENS = 16000;
/** Warning threshold - below this, user is warned */
export declare const CONTEXT_WINDOW_WARN_BELOW_TOKENS = 32000;
/** Default context window if not specified */
export declare const DEFAULT_CONTEXT_WINDOW_TOKENS = 128000;
/** Safety margin for token estimation (1.2 = 20% buffer) */
export declare const TOKEN_ESTIMATION_SAFETY_MARGIN = 1.2;
/** Source of context window value */
export type ContextWindowSource = 'model' | 'modelsConfig' | 'agentConfig' | 'sessionConfig' | 'default';
/** Context window information */
export interface ContextWindowInfo {
    /** Token count for context window */
    tokens: number;
    /** Source of this value */
    source: ContextWindowSource;
    /** Model ID if applicable */
    modelId?: string;
}
/** Result of guard evaluation */
export interface ContextWindowGuardResult extends ContextWindowInfo {
    /** Whether to show a warning to user */
    shouldWarn: boolean;
    /** Whether to block execution */
    shouldBlock: boolean;
    /** Current usage tokens */
    currentUsage: number;
    /** Remaining tokens */
    remaining: number;
    /** Usage percentage */
    usagePercent: number;
    /** Warning message if applicable */
    warningMessage?: string;
    /** Block message if applicable */
    blockMessage?: string;
}
/** Guard configuration */
export interface ContextWindowGuardConfig {
    /** Hard minimum tokens (blocks below this) */
    hardMinTokens: number;
    /** Warning threshold */
    warnBelowTokens: number;
    /** Default context window */
    defaultTokens: number;
    /** Safety margin for estimates */
    safetyMargin: number;
    /** Enable warnings */
    enableWarnings: boolean;
    /** Enable blocking */
    enableBlocking: boolean;
}
/** Events emitted by guard */
export interface ContextWindowGuardEvents {
    'warning': (result: ContextWindowGuardResult) => void;
    'blocked': (result: ContextWindowGuardResult) => void;
    'threshold-crossed': (result: ContextWindowGuardResult) => void;
}
export declare const DEFAULT_GUARD_CONFIG: ContextWindowGuardConfig;
/**
 * Normalize value to positive integer
 */
export declare function normalizePositiveInt(value: unknown): number | null;
/**
 * Resolve context window info from multiple sources
 */
export declare function resolveContextWindowInfo(options: {
    modelTokens?: number;
    configTokens?: number;
    agentTokens?: number;
    sessionTokens?: number;
    defaultTokens?: number;
    modelId?: string;
}): ContextWindowInfo;
/**
 * Evaluate context window guard
 */
export declare function evaluateContextWindowGuard(info: ContextWindowInfo, currentUsage: number, config?: Partial<ContextWindowGuardConfig>): ContextWindowGuardResult;
export declare class ContextWindowGuard extends EventEmitter {
    private config;
    private lastResult;
    private warningEmitted;
    private contextInfo;
    constructor(config?: Partial<ContextWindowGuardConfig>);
    /**
     * Set context window info
     */
    setContextWindow(info: ContextWindowInfo): void;
    /**
     * Set context window from multiple sources
     */
    resolveContextWindow(options: Parameters<typeof resolveContextWindowInfo>[0]): ContextWindowInfo;
    /**
     * Check current usage against limits
     */
    check(currentUsage: number): ContextWindowGuardResult;
    /**
     * Get last check result
     */
    getLastResult(): ContextWindowGuardResult | null;
    /**
     * Get current context info
     */
    getContextInfo(): ContextWindowInfo | null;
    /**
     * Reset warning state (e.g., after compaction)
     */
    resetWarning(): void;
    /**
     * Update configuration
     */
    updateConfig(config: Partial<ContextWindowGuardConfig>): void;
    /**
     * Get configuration
     */
    getConfig(): ContextWindowGuardConfig;
    /**
     * Calculate safe token budget with margin
     */
    getSafeTokenBudget(): number;
    /**
     * Check if compaction is recommended
     */
    shouldCompact(currentUsage: number, compactionThreshold?: number): boolean;
}
export declare function getContextWindowGuard(config?: Partial<ContextWindowGuardConfig>): ContextWindowGuard;
export declare function resetContextWindowGuard(): void;
