Skip to main content

claude_agent_sdk/
client_types.rs

1use std::collections::HashMap;
2
3use crate::types::{ContentBlock, RateLimitInfo};
4
5/// Response from sending a message to Claude.
6#[derive(Debug, Clone)]
7pub struct MessageResponse {
8    pub content: String,
9    pub blocks: Vec<ContentBlock>,
10    pub model: String,
11    pub stop_reason: Option<String>,
12    pub session_id: String,
13    pub usage: Option<HashMap<String, serde_json::Value>>,
14}
15
16/// Events that can occur during streaming.
17#[derive(Debug, Clone)]
18pub enum StreamEvent {
19    ContentChunk(String),
20    ThinkingChunk {
21        thinking: String,
22        signature: Option<String>,
23    },
24    ToolUseStart {
25        id: String,
26        name: String,
27        input: serde_json::Map<String, serde_json::Value>,
28    },
29    ToolUseDelta {
30        id: String,
31        partial_input: String,
32    },
33    ToolResult {
34        tool_use_id: String,
35        content: Option<serde_json::Value>,
36        is_error: Option<bool>,
37    },
38    RateLimit(RateLimitInfo),
39    Complete(MessageResponse),
40    Error(String),
41}
42
43impl MessageResponse {
44    pub fn has_tool_uses(&self) -> bool {
45        self.blocks
46            .iter()
47            .any(|b| matches!(b, ContentBlock::ToolUse { .. }))
48    }
49
50    pub fn get_tool_uses(&self) -> Vec<&ContentBlock> {
51        self.blocks
52            .iter()
53            .filter(|b| matches!(b, ContentBlock::ToolUse { .. }))
54            .collect()
55    }
56}