From d8a1a86fd5036d99bd99159937e795b776fe1554 Mon Sep 17 00:00:00 2001 From: alice maz Date: Tue, 20 Jan 2026 01:06:58 -0800 Subject: [PATCH] fix: Support Claude tool responses --- api/claude/src/client/types.rs | 35 ++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/api/claude/src/client/types.rs b/api/claude/src/client/types.rs index 3f3c16e..e6478ff 100644 --- a/api/claude/src/client/types.rs +++ b/api/claude/src/client/types.rs @@ -406,8 +406,10 @@ mod private { self.content .iter() - .find( | content | content.r#type == "text" ) - .and_then( | content | content.text.as_deref() ) + .find_map( | content | match content { + ResponseContent::Text { text } => Some(text.as_str()), + _ => None, + }) } /// Check if the response was truncated due to `max_tokens` @@ -419,13 +421,30 @@ mod private /// Content in response #[ derive( Debug, Clone, Serialize, Deserialize, PartialEq ) ] - pub struct ResponseContent + #[serde(tag = "type")] + pub enum ResponseContent { - /// Type of content - pub r#type : String, - /// Text content (only present for text content) - #[ serde( skip_serializing_if = "Option::is_none" ) ] - pub text : Option< String >, + /// Text response type. + #[serde(rename = "text")] + Text { + /// Text response content. + text: String + }, + + /// Tool use response type. + #[serde(rename = "tool_use")] + ToolUse { + /// Tool use ID. + id: String, + /// Name of tool called. + name: String, + /// Tool use content, corresponding to user-provided schema. + input: serde_json::Value, + }, + + /// Other response types without present support. + #[serde(other)] + Unsupported, } /// Usage statistics