lean_ctx/proxy/
compress_shared.rs1use serde_json::Value;
4
5use super::tool_kind::{self, ToolResultKind};
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub enum ToolKind {
10 ToolUse,
11 ToolResult,
12 Text,
13 Image,
14 Other,
15}
16
17pub fn classify_tool_kind(content: &Value) -> ToolKind {
19 match content.get("type").and_then(Value::as_str) {
20 Some("tool_use" | "function_call") => ToolKind::ToolUse,
21 Some("tool_result" | "function_call_output") => ToolKind::ToolResult,
22 Some("text" | "input_text" | "output_text") => ToolKind::Text,
23 Some("image" | "image_url" | "input_image") => ToolKind::Image,
24 _ => ToolKind::Other,
25 }
26}
27
28pub const fn should_compress_content(kind: ToolKind) -> bool {
30 matches!(kind, ToolKind::Text)
31}
32
33pub fn tool_result_kind(tool_name: Option<&str>) -> ToolResultKind {
35 tool_name.map_or(ToolResultKind::Other, tool_kind::classify_tool_name)
36}