Function estimate_history_tokens
pub fn estimate_history_tokens(history: &[ChatMessage]) -> usizeExpand description
Estimate token count for a message history using the ~4 chars/token heuristic plus ~4 framing tokens per message. Images are charged per image only where preparation dispatches them: the markers lifted from user turns and the attachments declared by the tool-result carriers of the current user turn. Stale tool-result carriers are priced as their bytes, and system or assistant content is priced as text. Trim probes estimate history suffixes that always retain the newest turn, so the current turn’s tool-result carriers carry the same disposition in every probe as in the full history.