/** * cost-control — Turn-end result compaction and flash-first defaults. * * Harvested from reasonix Pillar 3 (Cost Control). * * DeepSeek v4-flash is ~12× cheaper than v4-pro, and tool results that * accumulate across turns inflate context (and thus cost) unnecessarily. * * This module provides: * 1. Turn-end auto-compaction of large tool results * 2. Context-window pressure detection */ import type { DeepSeekChatMessage } from "./types.js"; /** Default token cap per tool result after compaction. */ export declare const RESULT_CAP_TOKENS = 3000; /** Emergency context pressure threshold (% of window). */ export declare const EMERGENCY_THRESHOLD = 0.8; /** Proactive shrink threshold. */ export declare const PROACTIVE_THRESHOLD = 0.4; /** * Rough estimate of token count from string length. * DeepSeek models use ~4 chars/token for English text. */ export declare function estimateTokens(text: string): number; /** * Compact a tool result message to a summary. * Truncates to the cap and appends a summary suffix. */ export declare function compactToolResult(message: DeepSeekChatMessage, capTokens?: number): DeepSeekChatMessage; export interface CompactionResult { compacted: DeepSeekChatMessage[]; compactedCount: number; } /** * Compact all tool messages in the list that exceed the token cap. */ export declare function compactToolResults(messages: DeepSeekChatMessage[], capTokens?: number): CompactionResult; /** * Estimate total context usage from the messages array. */ export declare function estimateContextUsage(messages: DeepSeekChatMessage[]): number; /** * Check whether context is under pressure. * Returns a string indicating the pressure level or null if fine. */ export declare function checkContextPressure(currentTokens: number, contextWindow: number): "none" | "proactive" | "emergency"; /** * Summarize a tool result for roll-up during compaction. * Used when a tool result is too large to keep inline. */ export declare function summarizeToolResult(message: DeepSeekChatMessage): string;