1use serde::{Deserialize, Serialize};
4
5use super::request::AgentConfig;
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct AgentCreateResponse {
10 pub id: String,
12
13 pub name: String,
15
16 pub description: Option<String>,
18
19 pub created_at: Option<u64>,
21
22 pub model: Option<String>,
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28pub struct AgentDetails {
29 pub id: String,
31
32 pub name: String,
34
35 pub description: Option<String>,
37
38 pub system_prompt: Option<String>,
40
41 pub model: Option<String>,
43
44 pub tools: Option<Vec<serde_json::Value>>,
46
47 pub config: Option<AgentConfig>,
49
50 pub created_at: Option<u64>,
52
53 pub updated_at: Option<u64>,
55}
56
57#[derive(Debug, Clone, Serialize, Deserialize)]
59pub struct AgentUpdateResponse {
60 pub id: String,
62
63 pub success: bool,
65
66 pub updated_at: Option<u64>,
68}
69
70#[derive(Debug, Clone, Serialize, Deserialize)]
72pub struct AgentDeleteResponse {
73 pub id: String,
75
76 pub success: bool,
78
79 pub deleted_at: Option<u64>,
81}
82
83#[derive(Debug, Clone, Serialize, Deserialize)]
85pub struct AgentChatResponse {
86 pub conversation_id: Option<String>,
88
89 pub session_id: Option<String>,
91
92 pub response: AgentMessage,
94
95 pub tool_calls: Option<Vec<AgentToolCall>>,
97
98 pub usage: Option<AgentUsage>,
100}
101
102#[derive(Debug, Clone, Serialize, Deserialize)]
104pub struct AgentMessage {
105 pub role: String,
107
108 pub content: String,
110
111 pub reasoning_content: Option<String>,
113
114 pub timestamp: Option<u64>,
116}
117
118#[derive(Debug, Clone, Serialize, Deserialize)]
120pub struct AgentToolCall {
121 pub id: String,
123
124 pub name: String,
126
127 pub arguments: String,
129
130 pub result: Option<serde_json::Value>,
132}
133
134#[derive(Debug, Clone, Serialize, Deserialize)]
136pub struct AgentUsage {
137 pub prompt_tokens: Option<u32>,
139
140 pub completion_tokens: Option<u32>,
142
143 pub total_tokens: Option<u32>,
145}
146
147#[derive(Debug, Clone, Serialize, Deserialize)]
149pub struct ConversationHistory {
150 pub conversation_id: String,
152
153 pub messages: Vec<AgentMessage>,
155
156 pub total_count: Option<u32>,
158
159 pub has_more: Option<bool>,
161}
162
163#[cfg(test)]
164mod tests {
165 use super::*;
166
167 #[test]
168 fn test_agent_create_response_serde_roundtrip() {
169 let resp = AgentCreateResponse {
170 id: "agent_123".to_string(),
171 name: "TestAgent".to_string(),
172 description: Some("A test agent".to_string()),
173 created_at: Some(1700000000),
174 model: Some("glm-4.5".to_string()),
175 };
176 let json = serde_json::to_string(&resp).unwrap();
177 let parsed: AgentCreateResponse = serde_json::from_str(&json).unwrap();
178 assert_eq!(parsed.id, "agent_123");
179 assert_eq!(parsed.name, "TestAgent");
180 assert_eq!(parsed.description, Some("A test agent".to_string()));
181 }
182
183 #[test]
184 fn test_agent_details_serde_roundtrip() {
185 let details = AgentDetails {
186 id: "agent_456".to_string(),
187 name: "DetailAgent".to_string(),
188 description: None,
189 system_prompt: Some("Be helpful".to_string()),
190 model: Some("glm-4.5-flash".to_string()),
191 tools: None,
192 config: None,
193 created_at: Some(1700000000),
194 updated_at: Some(1700000100),
195 };
196 let json = serde_json::to_string(&details).unwrap();
197 let parsed: AgentDetails = serde_json::from_str(&json).unwrap();
198 assert_eq!(parsed.id, "agent_456");
199 assert!(parsed.description.is_none());
200 }
201
202 #[test]
203 fn test_agent_chat_response_serde_roundtrip() {
204 let resp = AgentChatResponse {
205 conversation_id: Some("conv_789".to_string()),
206 session_id: Some("sess_012".to_string()),
207 response: AgentMessage {
208 role: "assistant".to_string(),
209 content: "Hello!".to_string(),
210 reasoning_content: None,
211 timestamp: Some(1700000000),
212 },
213 tool_calls: None,
214 usage: Some(AgentUsage {
215 prompt_tokens: Some(10),
216 completion_tokens: Some(5),
217 total_tokens: Some(15),
218 }),
219 };
220 let json = serde_json::to_string(&resp).unwrap();
221 let parsed: AgentChatResponse = serde_json::from_str(&json).unwrap();
222 assert_eq!(parsed.response.content, "Hello!");
223 assert_eq!(parsed.usage.unwrap().total_tokens, Some(15));
224 }
225
226 #[test]
227 fn test_agent_update_response_serde_roundtrip() {
228 let resp = AgentUpdateResponse {
229 id: "agent_123".to_string(),
230 success: true,
231 updated_at: Some(1700000200),
232 };
233 let json = serde_json::to_string(&resp).unwrap();
234 let parsed: AgentUpdateResponse = serde_json::from_str(&json).unwrap();
235 assert!(parsed.success);
236 }
237
238 #[test]
239 fn test_agent_delete_response_serde_roundtrip() {
240 let resp = AgentDeleteResponse {
241 id: "agent_123".to_string(),
242 success: true,
243 deleted_at: Some(1700000300),
244 };
245 let json = serde_json::to_string(&resp).unwrap();
246 let parsed: AgentDeleteResponse = serde_json::from_str(&json).unwrap();
247 assert!(parsed.success);
248 }
249
250 #[test]
251 fn test_conversation_history_serde_roundtrip() {
252 let history = ConversationHistory {
253 conversation_id: "conv_abc".to_string(),
254 messages: vec![AgentMessage {
255 role: "user".to_string(),
256 content: "Hi".to_string(),
257 reasoning_content: None,
258 timestamp: None,
259 }],
260 total_count: Some(1),
261 has_more: Some(false),
262 };
263 let json = serde_json::to_string(&history).unwrap();
264 let parsed: ConversationHistory = serde_json::from_str(&json).unwrap();
265 assert_eq!(parsed.messages.len(), 1);
266 assert_eq!(parsed.messages[0].role, "user");
267 }
268}