1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
9#[serde(untagged)]
10pub enum UserInput {
11 Text(String),
13 Parts(Vec<ContentPart>),
15}
16
17impl From<String> for UserInput {
18 fn from(value: String) -> Self {
19 UserInput::Text(value)
20 }
21}
22
23impl From<&str> for UserInput {
24 fn from(value: &str) -> Self {
25 UserInput::Text(value.to_string())
26 }
27}
28
29impl From<Vec<ContentPart>> for UserInput {
30 fn from(value: Vec<ContentPart>) -> Self {
31 UserInput::Parts(value)
32 }
33}
34
35#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
41#[serde(tag = "type", rename_all = "snake_case")]
42pub enum ContentPart {
43 Text(TextPart),
45 Think(ThinkPart),
47 #[serde(rename = "image_url")]
49 ImageUrl(ImageUrlPart),
50 #[serde(rename = "audio_url")]
52 AudioUrl(AudioUrlPart),
53 #[serde(rename = "video_url")]
55 VideoUrl(VideoUrlPart),
56}
57
58#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
60pub struct TextPart {
61 pub text: String,
63}
64
65#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
67pub struct ThinkPart {
68 pub think: String,
70 #[serde(skip_serializing_if = "Option::is_none")]
72 pub encrypted: Option<String>,
73}
74
75#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
77pub struct ImageUrlPart {
78 pub image_url: MediaUrl,
80}
81
82#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
84pub struct AudioUrlPart {
85 pub audio_url: MediaUrl,
87}
88
89#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
91pub struct VideoUrlPart {
92 pub video_url: MediaUrl,
94}
95
96#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
98pub struct MediaUrl {
99 pub url: String,
101 #[serde(skip_serializing_if = "Option::is_none")]
103 pub id: Option<String>,
104}
105
106#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
115pub struct DisplayBlock {
116 #[serde(rename = "type")]
118 pub block_type: DisplayBlockType,
119 #[serde(skip_serializing_if = "Option::is_none")]
121 pub text: Option<String>,
122 #[serde(skip_serializing_if = "Option::is_none")]
124 pub path: Option<String>,
125 #[serde(skip_serializing_if = "Option::is_none")]
127 pub old_text: Option<String>,
128 #[serde(skip_serializing_if = "Option::is_none")]
130 pub new_text: Option<String>,
131 #[serde(skip_serializing_if = "Option::is_none")]
133 pub items: Option<Vec<TodoDisplayItem>>,
134 #[serde(skip_serializing_if = "Option::is_none")]
136 pub language: Option<String>,
137 #[serde(skip_serializing_if = "Option::is_none")]
139 pub command: Option<String>,
140 #[serde(skip_serializing_if = "Option::is_none")]
142 pub data: Option<serde_json::Value>,
143}
144
145#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
147#[serde(rename_all = "snake_case")]
148pub enum DisplayBlockType {
149 Brief,
151 Diff,
153 Todo,
155 Shell,
157 #[serde(rename = "unknown")]
159 Unknown,
160}
161
162#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
164pub struct TodoDisplayItem {
165 pub title: String,
167 pub status: TodoStatus,
169}
170
171#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
173#[serde(rename_all = "snake_case")]
174pub enum TodoStatus {
175 Pending,
177 InProgress,
179 Done,
181}
182
183#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
189pub struct ToolReturnValue {
190 pub is_error: bool,
192 pub output: ToolOutput,
194 pub message: String,
196 pub display: Vec<DisplayBlock>,
198 #[serde(skip_serializing_if = "Option::is_none")]
200 pub extras: Option<serde_json::Value>,
201}
202
203#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
205#[serde(untagged)]
206pub enum ToolOutput {
207 Text(String),
209 Parts(Vec<ContentPart>),
211}
212
213impl From<String> for ToolOutput {
214 fn from(value: String) -> Self {
215 ToolOutput::Text(value)
216 }
217}
218
219impl From<&str> for ToolOutput {
220 fn from(value: &str) -> Self {
221 ToolOutput::Text(value.to_string())
222 }
223}
224
225impl From<Vec<ContentPart>> for ToolOutput {
226 fn from(value: Vec<ContentPart>) -> Self {
227 ToolOutput::Parts(value)
228 }
229}