use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum ClaudeEvent {
#[serde(rename = "system")]
System {
subtype: Option<String>,
session_id: Option<String>,
#[serde(flatten)]
extra: serde_json::Value,
},
#[serde(rename = "assistant")]
Assistant {
subtype: Option<String>,
message: Option<AssistantMessage>,
#[serde(flatten)]
extra: serde_json::Value,
},
#[serde(rename = "user")]
User {
subtype: Option<String>,
message: Option<UserMessage>,
#[serde(flatten)]
extra: serde_json::Value,
},
#[serde(rename = "result")]
Result {
subtype: Option<String>,
result: Option<String>,
cost_usd: Option<f64>,
duration_ms: Option<u64>,
session_id: Option<String>,
#[serde(flatten)]
extra: serde_json::Value,
},
#[serde(rename = "stream_event")]
StreamEvent {
event: StreamEventInner,
session_id: Option<String>,
#[serde(flatten)]
extra: serde_json::Value,
},
#[serde(rename = "rate_limit_event")]
RateLimitEvent {
#[serde(flatten)]
extra: serde_json::Value,
},
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StreamEventInner {
#[serde(rename = "type")]
pub event_type: String,
pub delta: Option<StreamDelta>,
pub content_block: Option<ContentBlock>,
#[serde(flatten)]
pub extra: serde_json::Value,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StreamDelta {
#[serde(rename = "type")]
pub delta_type: Option<String>,
pub text: Option<String>,
pub partial_json: Option<String>,
pub thinking: Option<String>,
#[serde(flatten)]
pub extra: serde_json::Value,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AssistantMessage {
pub content: Option<Vec<ContentBlock>>,
#[serde(flatten)]
pub extra: serde_json::Value,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UserMessage {
pub content: Option<serde_json::Value>,
#[serde(flatten)]
pub extra: serde_json::Value,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum ContentBlock {
#[serde(rename = "text")]
Text { text: String },
#[serde(rename = "thinking")]
Thinking { thinking: Option<String> },
#[serde(rename = "tool_use")]
ToolUse {
id: Option<String>,
name: Option<String>,
input: Option<serde_json::Value>,
},
#[serde(rename = "tool_result")]
ToolResult {
tool_use_id: Option<String>,
content: Option<serde_json::Value>,
is_error: Option<bool>,
},
#[serde(other)]
Unknown,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(tag = "feed_type", content = "data", rename_all = "snake_case")]
pub enum FeedItem {
AssistantText(String),
AssistantTextStreaming(String),
Thinking(String),
ThinkingStreaming(String),
UserMessage(String),
ToolCall {
name: String,
input: serde_json::Value,
},
ToolResult { content: String, is_error: bool },
SystemMessage(String),
FinalResult {
result: String,
cost_usd: Option<f64>,
duration_ms: Option<u64>,
},
}
#[derive(Default, Clone, PartialEq)]
pub struct SessionFeedBuffer {
pub items: Vec<FeedItem>,
pub dropped_count: usize,
}
#[derive(Debug, Clone, PartialEq)]
pub enum SessionStatus {
Starting,
Running,
Completed,
Error(String),
}