1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize)]
5pub enum AgentAction {
6 ReadFile {
8 paths: Vec<String>,
9 },
10 WriteFile {
12 path: String,
13 content: String,
14 },
15 EditFile {
17 path: String,
18 old_string: String,
19 new_string: String,
20 },
21 DeleteFile {
23 path: String,
24 },
25 CreateDirectory {
27 path: String,
28 },
29 ExecuteCommand {
31 command: String,
32 working_dir: Option<String>,
33 timeout: Option<u64>,
34 },
35 WebSearch {
37 queries: Vec<(String, usize)>,
38 },
39 WebFetch {
41 url: String,
42 },
43 SpawnAgent {
45 prompt: String,
46 description: String,
47 },
48 ParseError {
50 message: String,
51 },
52}
53
54#[derive(Debug, Clone, Serialize, Deserialize)]
56#[must_use]
57pub enum ActionResult {
58 Success { output: String },
59 Error { error: String },
60}
61
62impl AgentAction {
63 pub fn display_info(&self) -> (&str, String) {
65 match self {
66 AgentAction::ReadFile { paths } => {
67 if paths.len() == 1 {
68 ("Read", paths[0].clone())
69 } else {
70 ("Read", format!("{} files", paths.len()))
71 }
72 },
73 AgentAction::WriteFile { path, .. } => ("Write", path.clone()),
74 AgentAction::EditFile { path, .. } => ("Edit", path.clone()),
75 AgentAction::DeleteFile { path } => ("Delete", path.clone()),
76 AgentAction::CreateDirectory { path } => ("Bash", format!("mkdir -p {}", path)),
77 AgentAction::ExecuteCommand { command, .. } => ("Bash", command.clone()),
78 AgentAction::WebSearch { queries } => {
79 if queries.len() == 1 {
80 ("Web Search", queries[0].0.clone())
81 } else {
82 ("Web Search", format!("{} queries", queries.len()))
83 }
84 },
85 AgentAction::WebFetch { url } => ("Web Fetch", url.clone()),
86 AgentAction::SpawnAgent { description, .. } => ("Agent", description.clone()),
87 AgentAction::ParseError { message } => ("Error", message.clone()),
88 }
89 }
90}
91
92#[derive(Debug, Clone, Serialize, Deserialize)]
94pub struct ActionDisplay {
95 pub action_type: String,
97 pub target: String,
99 pub result: ActionResult,
101 #[serde(default)]
103 pub details: ActionDetails,
104 pub duration_seconds: Option<f64>,
106}
107
108#[derive(Debug, Clone, Default, Serialize, Deserialize)]
110pub enum ActionDetails {
111 #[default]
113 Simple,
114 Preview {
116 text: String,
117 line_count: Option<usize>,
118 },
119 FileContent { line_count: usize, content: String },
121 Diff { summary: String, diff: String },
123 Agent { summary: String, tool_uses: usize },
125}
126