use serde_json::Value;
use std::collections::HashMap;
use crate::core::auth_generator::{AuthCache, GenContext};
use crate::core::{
http,
keyring::Keyring,
manifest::{Provider, Tool},
response,
};
use crate::output;
use crate::OutputFormat;
pub async fn execute(
provider: &Provider,
tool: &Tool,
args: &HashMap<String, Value>,
keyring: &Keyring,
output_format: &OutputFormat,
) -> Result<String, Box<dyn std::error::Error>> {
execute_with_gen(provider, tool, args, keyring, output_format, None, None).await
}
pub async fn execute_with_gen(
provider: &Provider,
tool: &Tool,
args: &HashMap<String, Value>,
keyring: &Keyring,
output_format: &OutputFormat,
gen_ctx: Option<&GenContext>,
auth_cache: Option<&AuthCache>,
) -> Result<String, Box<dyn std::error::Error>> {
let raw_response =
http::execute_tool_with_gen(provider, tool, args, keyring, gen_ctx, auth_cache).await?;
let processed = response::process_response(&raw_response, tool.response.as_ref())?;
let formatted = output::format_output(&processed, output_format);
Ok(formatted)
}