use std::collections::HashMap;
use crate::types::{ContentBlock, RateLimitInfo};
#[derive(Debug, Clone)]
pub struct MessageResponse {
pub content: String,
pub blocks: Vec<ContentBlock>,
pub model: String,
pub stop_reason: Option<String>,
pub session_id: String,
pub usage: Option<HashMap<String, serde_json::Value>>,
}
#[derive(Debug, Clone)]
pub enum StreamEvent {
ContentChunk(String),
ThinkingChunk {
thinking: String,
signature: Option<String>,
},
ToolUseStart {
id: String,
name: String,
input: serde_json::Map<String, serde_json::Value>,
},
ToolUseDelta {
id: String,
partial_input: String,
},
ToolResult {
tool_use_id: String,
content: Option<serde_json::Value>,
is_error: Option<bool>,
},
RateLimit(RateLimitInfo),
Complete(MessageResponse),
TurnComplete(MessageResponse),
Error(String),
}
impl MessageResponse {
pub fn has_tool_uses(&self) -> bool {
self.blocks
.iter()
.any(|b| matches!(b, ContentBlock::ToolUse { .. }))
}
pub fn get_tool_uses(&self) -> Vec<&ContentBlock> {
self.blocks
.iter()
.filter(|b| matches!(b, ContentBlock::ToolUse { .. }))
.collect()
}
}