lean-ctx 3.9.18

Context Runtime for AI Agents with CCP. 71 MCP tools, 10 read modes, 95+ compression patterns, cross-session memory (CCP), persistent AI knowledge with temporal facts + contradiction detection, multi-agent context sharing, LITM-aware positioning, AAAK compact format, adaptive compression with Thompson Sampling bandits. Supports 24+ AI tools. Reduces LLM token consumption by up to 99%.
Documentation
//! Provider-neutral classification for content blocks compressed in place.

use serde_json::Value;

use super::tool_kind::{self, ToolResultKind};

/// Semantic type of a provider content block.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ToolKind {
    ToolUse,
    ToolResult,
    Text,
    Image,
    Other,
}

/// Classify the common content-block types used by provider request shapes.
pub fn classify_tool_kind(content: &Value) -> ToolKind {
    match content.get("type").and_then(Value::as_str) {
        Some("tool_use" | "function_call") => ToolKind::ToolUse,
        Some("tool_result" | "function_call_output") => ToolKind::ToolResult,
        Some("text" | "input_text" | "output_text") => ToolKind::Text,
        Some("image" | "image_url" | "input_image") => ToolKind::Image,
        _ => ToolKind::Other,
    }
}

/// Whether this block kind carries text that may be compressed in place.
pub const fn should_compress_content(kind: ToolKind) -> bool {
    matches!(kind, ToolKind::Text)
}

/// Resolve a tool name to its result kind, preserving the unknown-tool fallback.
pub fn tool_result_kind(tool_name: Option<&str>) -> ToolResultKind {
    tool_name.map_or(ToolResultKind::Other, tool_kind::classify_tool_name)
}