pub mod json_stream;
pub mod null;
pub mod terminal;
pub use json_stream::JsonStreamRenderer;
pub use null::NullRenderer;
pub use terminal::TerminalRenderer;
use std::io::{self, Write};
use agent_base::{AgentResult, RuntimeEvent};
pub trait EventRenderer: Send {
fn render(&mut self, event: RuntimeEvent) -> AgentResult<()>;
fn finish_turn(&mut self) -> AgentResult<()>;
fn finish_session(&mut self) -> AgentResult<()> {
Ok(())
}
}
#[derive(Clone, Debug)]
pub enum OutputFormat {
Terminal { show_thinking: bool, show_tool_args: bool, color: bool },
Json,
Quiet,
}
pub fn create_renderer(format: &OutputFormat, writer: Option<Box<dyn Write + Send>>) -> Box<dyn EventRenderer> {
match format {
OutputFormat::Terminal { show_thinking, show_tool_args, color } => {
let w = writer.unwrap_or_else(|| Box::new(io::stdout()));
Box::new(TerminalRenderer::new(*show_thinking, *show_tool_args, *color, w))
},
OutputFormat::Json => {
let w = writer.unwrap_or_else(|| Box::new(io::stdout()));
Box::new(JsonStreamRenderer::new(w))
},
OutputFormat::Quiet => Box::new(NullRenderer),
}
}
pub fn create_stdout_renderer(format: &OutputFormat) -> Box<dyn EventRenderer> {
create_renderer(format, None)
}