services/tokens/tokens
Token estimation for context window awareness. Uses character-based heuristics: ~4 chars per token for English/Latin, ~1 char per token for CJK and other dense scripts. Directionally correct for overflow warnings — not a tiktoken port.
Values
pub fn context_usage_percent(
estimated_tokens: Int,
context_window: Int,
) -> Int
pub fn context_window_warning(
tokens_used: Int,
context_window: Int,
warn_percent: Int,
) -> String
pub fn estimate_messages(messages: List(message.Message)) -> Int
pub fn estimate_request(
system_prompt: String,
messages: List(message.Message),
tool_definitions: List(tool_def.ToolDefinition),
) -> Int
pub fn estimate_string(text: String) -> Int
pub fn service() -> service.Service
pub fn token_estimator() -> behaviours.TokenEstimator