1pub mod json_stream;
2pub mod null;
3pub mod terminal;
4
5pub use json_stream::JsonStreamRenderer;
6pub use null::NullRenderer;
7pub use terminal::TerminalRenderer;
8
9use std::io::{self, Write};
10
11use agent_base::{AgentResult, RuntimeEvent};
12
13pub trait EventRenderer: Send {
18 fn render(&mut self, event: RuntimeEvent) -> AgentResult<()>;
20
21 fn finish_turn(&mut self) -> AgentResult<()>;
23
24 fn finish_session(&mut self) -> AgentResult<()> {
26 Ok(())
27 }
28}
29
30#[derive(Clone, Debug)]
32pub enum OutputFormat {
33 Terminal { show_thinking: bool, show_tool_args: bool, color: bool },
35 Json,
37 Quiet,
39}
40
41pub fn create_renderer(format: &OutputFormat, writer: Option<Box<dyn Write + Send>>) -> Box<dyn EventRenderer> {
46 match format {
47 OutputFormat::Terminal { show_thinking, show_tool_args, color } => {
48 let w = writer.unwrap_or_else(|| Box::new(io::stdout()));
49 Box::new(TerminalRenderer::new(*show_thinking, *show_tool_args, *color, w))
50 },
51 OutputFormat::Json => {
52 let w = writer.unwrap_or_else(|| Box::new(io::stdout()));
53 Box::new(JsonStreamRenderer::new(w))
54 },
55 OutputFormat::Quiet => Box::new(NullRenderer),
56 }
57}
58
59pub fn create_stdout_renderer(format: &OutputFormat) -> Box<dyn EventRenderer> {
61 create_renderer(format, None)
62}