| 1 | use crate::commands::CommandResult; |
| 2 | use crate::tui::app::{App, AppAction}; |
| 3 | |
| 4 | pub(super) fn tools(app: &mut App, arg: Option<&str>) -> CommandResult { |
| 5 | let format = arg.unwrap_or("text").trim(); |
| 6 | let Some(snapshot) = app.session.last_tool_request_snapshot.as_ref() else { |
| 7 | return CommandResult::message( |
| 8 | "Tool request snapshot unavailable — no model request has been captured for the latest turn.", |
| 9 | ); |
| 10 | }; |
| 11 | |
| 12 | match format { |
| 13 | "" | "text" => CommandResult::action(AppAction::OpenTextPager { |
| 14 | title: "Prepared Tool Request".to_string(), |
| 15 | content: snapshot.render_text(), |
| 16 | }), |
| 17 | "json" => match snapshot.render_json() { |
| 18 | Ok(output) => CommandResult::action(AppAction::OpenTextPager { |
| 19 | title: "Prepared Tool Request (JSON)".to_string(), |
| 20 | content: output, |
| 21 | }), |
| 22 | Err(error) => CommandResult::error(format!( |
| 23 | "tool request snapshot could not be serialized: {error}" |
| 24 | )), |
| 25 | }, |
| 26 | _ => CommandResult::error("usage: /tools [text|json]"), |
| 27 | } |
| 28 | } |
| 29 |