1use crate::output_fmt;
2use crate::types::Output;
3use agent_first_data::OutputFormat;
4
5pub fn emit_cli_error(
6 msg: &str,
7 hint: Option<&str>,
8 format: OutputFormat,
9) -> Result<(), agent_first_data::CliEmitterError> {
10 let stdout = std::io::stdout();
11 let mut emitter =
12 agent_first_data::CliEmitter::new(stdout.lock(), format).with_strict_protocol();
13 let event = agent_first_data::json_error(crate::protocol::error_code::INVALID_REQUEST, msg)
14 .hint_if_some(hint)
15 .build()
16 .map_err(agent_first_data::CliEmitterError::Build)?;
17 emitter.emit(event)
18}
19
20pub fn emit_output(
21 out: &Output,
22 format: OutputFormat,
23) -> Result<(), agent_first_data::CliEmitterError> {
24 let stdout = std::io::stdout();
25 output_fmt::emit_output(stdout.lock(), out, format)
26}