Skip to main content

tycode_core/formatter/
mod.rs

1mod compact;
2mod verbose;
3
4use crate::ai::model::Model;
5use crate::ai::TokenUsage;
6use crate::chat::events::{ChatMessage, ToolExecutionResult, ToolRequest};
7use crate::chat::ModelInfo;
8use crate::modules::task_list::TaskList;
9
10pub use compact::CompactFormatter;
11pub use verbose::VerboseFormatter;
12
13/// Trait for formatting and displaying events in the terminal
14pub trait EventFormatter: Send + Sync {
15    fn print_system(&mut self, msg: &str);
16
17    fn print_ai(
18        &mut self,
19        msg: &str,
20        agent: &str,
21        model_info: &Option<ModelInfo>,
22        token_usage: &Option<TokenUsage>,
23    );
24
25    fn print_warning(&mut self, msg: &str);
26
27    fn print_error(&mut self, msg: &str);
28
29    fn print_retry_attempt(&mut self, attempt: u32, max_retries: u32, error: &str);
30
31    fn print_tool_request(&mut self, tool_request: &ToolRequest);
32
33    fn print_tool_result(
34        &mut self,
35        name: &str,
36        success: bool,
37        result: ToolExecutionResult,
38        verbose: bool,
39    );
40
41    fn print_thinking(&mut self);
42
43    fn print_task_update(&mut self, task_list: &TaskList);
44
45    fn on_typing_status_changed(&mut self, _typing: bool) {}
46
47    fn print_stream_start(&mut self, _message_id: &str, _agent: &str, _model: &Model) {}
48
49    fn print_stream_delta(&mut self, _message_id: &str, _text: &str) {}
50
51    fn print_stream_end(&mut self, _message: &ChatMessage) {}
52
53    fn clone_box(&self) -> Box<dyn EventFormatter>;
54}
55
56impl Clone for Box<dyn EventFormatter> {
57    fn clone(&self) -> Self {
58        self.clone_box()
59    }
60}