1use serde::{Deserialize, Serialize};
5use std::collections::HashMap;
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct Message {
11 pub role: Role,
12 pub content: MessageContent,
13}
14
15#[derive(Debug, Clone, Serialize, Deserialize)]
16#[serde(rename_all = "lowercase")]
17pub enum Role {
18 User,
19 Assistant,
20}
21
22#[derive(Debug, Clone, Serialize, Deserialize)]
23#[serde(untagged)]
24pub enum MessageContent {
25 Text(String),
26 Blocks(Vec<ContentBlock>),
27}
28
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(tag = "type")]
31pub enum ContentBlock {
32 #[serde(rename = "text")]
33 Text { text: String },
34 #[serde(rename = "tool_use")]
35 ToolUse {
36 id: String,
37 name: String,
38 input: serde_json::Value,
39 },
40 #[serde(rename = "tool_result")]
41 ToolResult {
42 tool_use_id: String,
43 content: String,
44 #[serde(default)]
45 is_error: bool,
46 },
47}
48
49#[derive(Debug, Clone)]
52pub struct ModelConfig {
53 pub id: &'static str,
54 pub max_tokens: u32,
55}
56
57#[derive(Debug, Clone, Serialize)]
58pub struct InferenceRequest {
59 pub model: String,
60 pub max_tokens: u32,
61 pub messages: Vec<Message>,
62 #[serde(skip_serializing_if = "Option::is_none")]
63 pub system: Option<String>,
64 #[serde(skip_serializing_if = "Option::is_none")]
65 pub tools: Option<Vec<ToolDefinition>>,
66}
67
68#[derive(Debug, Clone, Deserialize)]
69#[allow(dead_code)] pub struct InferenceResponse {
71 pub content: Vec<ContentBlock>,
72 pub stop_reason: Option<String>,
73 pub usage: Usage,
74 pub model: String,
75 #[serde(skip)]
76 pub cli_meta: Option<CliMeta>,
77}
78
79#[derive(Debug, Clone, Deserialize, Default)]
80pub struct Usage {
81 #[serde(default)]
82 pub input_tokens: u64,
83 #[serde(default)]
84 pub output_tokens: u64,
85 #[serde(default)]
86 pub cache_read_input_tokens: u64,
87 #[serde(default)]
88 pub cache_creation_input_tokens: u64,
89}
90
91#[derive(Debug, Clone, Serialize, Deserialize)]
94pub struct ToolDefinition {
95 pub name: String,
96 pub description: String,
97 pub input_schema: serde_json::Value,
98}
99
100#[derive(Debug, Clone)]
101pub struct ToolCall {
102 pub id: String,
103 pub name: String,
104 pub input: serde_json::Value,
105}
106
107#[derive(Debug, Clone)]
108pub struct ToolResult {
109 pub tool_use_id: String,
110 pub content: String,
111 pub is_error: bool,
112}
113
114#[derive(Debug, Clone)]
117pub struct PermissionRule {
118 pub pattern: String,
119}
120
121#[derive(Debug)]
122pub struct PermissionCheck {
123 pub allowed: bool,
124 pub reason: Option<String>,
125}
126
127#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
130pub enum HookEvent {
131 SessionStart,
132 PreToolUse,
133 PostToolUse,
134 PostToolFailure,
135 SessionStop,
136}
137
138#[derive(Debug)]
139pub struct HookResult {
140 pub allow: bool,
141 pub message: Option<String>,
142}
143
144#[derive(Debug, Clone, Copy, PartialEq)]
147pub enum McpDomain {
148 Specialized,
149}
150
151#[derive(Debug, Clone, Deserialize)]
152pub struct McpServerConfig {
153 pub command: String,
154 #[serde(default)]
155 pub args: Vec<String>,
156 #[serde(default)]
157 pub env: HashMap<String, String>,
158}
159
160#[derive(Debug, Clone)]
163pub struct FeatureFlags {
164 pub summarize_tool_results: bool,
165}
166
167impl Default for FeatureFlags {
168 fn default() -> Self {
169 Self {
170 summarize_tool_results: true,
171 }
172 }
173}
174
175#[derive(Debug, Clone)]
178#[allow(dead_code)] pub struct AgentConfig {
180 pub memory_path: String,
181 pub hooks_dir: String,
182 pub permissions_path: String,
183 pub mcp_config_path: String,
184}
185
186impl Default for AgentConfig {
187 fn default() -> Self {
188 let home = std::env::var("HOME").unwrap_or_else(|_| "/tmp".into());
189 Self {
190 memory_path: format!("{home}/.claude-agent/memory/MEMORY.md"),
191 hooks_dir: format!("{home}/.claude-agent/hooks"),
192 permissions_path: format!("{home}/.claude-agent/permissions.json"),
193 mcp_config_path: format!("{home}/.mcp.json"),
194 }
195 }
196}
197
198#[derive(Debug, Clone, Default, Serialize)]
199pub struct AgentStats {
200 pub session_id: String,
201 pub messages_count: u64,
202 pub tool_calls: HashMap<String, u64>,
203 pub tokens_in: u64,
204 pub tokens_out: u64,
205 pub cache_read: u64,
206 pub cache_create: u64,
207 pub started_at: i64,
208 pub cost_usd: f64,
209 pub total_duration_ms: u64,
210 pub total_api_ms: u64,
211 pub total_turns: u64,
212}
213
214#[derive(Debug, Clone, Default)]
216pub struct CliMeta {
217 pub cost_usd: f64,
218 pub duration_ms: u64,
219 pub duration_api_ms: u64,
220 pub num_turns: u64,
221}