use serde_json::Value;
use crate::Result;
use crate::bindings::oino::extension::control as wc;
use crate::error::parse;
pub use wc::{
abort, active_tools, has_pending_messages, is_idle, is_project_trusted, running_bash, shutdown,
system_prompt, thinking_level, tool_progress,
};
#[must_use]
pub fn model() -> Option<Value> {
wc::model().and_then(|t| serde_json::from_str(&t).ok())
}
pub fn set_model(provider: &str, id: &str) -> Result<bool> {
Ok(wc::set_model(provider, id)?)
}
pub fn set_default_model(provider: &str, id: &str, thinking: Option<&str>) -> Result<bool> {
Ok(wc::set_default_model(provider, id, thinking)?)
}
pub fn set_thinking_level(level: &str) -> Result<String> {
Ok(wc::set_thinking_level(level)?)
}
pub fn models() -> Result<Vec<Value>> {
parse(&wc::models_list())
}
pub fn context_usage() -> Result<Value> {
parse(&wc::context_usage())
}
pub fn session_stats() -> Result<Value> {
parse(&wc::session_stats())
}
pub fn run_state() -> Result<Value> {
parse(&wc::run_state())
}
pub fn settings() -> Result<Value> {
parse(&wc::get_settings())
}
pub fn set_active_tools(names: &[String]) -> Result<()> {
Ok(wc::set_active_tools(names)?)
}
pub fn all_tools() -> Result<Vec<Value>> {
parse(&wc::all_tools())
}
pub fn commands() -> Result<Vec<Value>> {
parse(&wc::commands_list())
}
pub async fn compact(custom_instructions: Option<&str>) -> Result<Value> {
parse(&wc::compact(custom_instructions.map(ToOwned::to_owned)).await?)
}
pub async fn invoke_command(name: &str, args: &str) -> Result<Option<Value>> {
wc::command_invoke(name.to_owned(), args.to_owned())
.await?
.map(|t| parse(&t))
.transpose()
}
pub async fn execute_tool(name: &str, args: &Value) -> Result<Value> {
parse(&wc::execute_tool(name.to_owned(), args.to_string(), None).await?)
}
pub fn bash_detach(tool_call_id: &str, reason: &str) -> Result<String> {
Ok(wc::bash_detach(tool_call_id, reason)?)
}
pub async fn wait_for_idle() -> Result<()> {
Ok(wc::wait_for_idle().await?)
}
pub async fn new_session(parent: Option<&str>) -> Result<bool> {
Ok(wc::new_session(parent.map(ToOwned::to_owned)).await?)
}
pub async fn fork(entry_id: &str, at: bool) -> Result<Value> {
parse(&wc::fork(entry_id.to_owned(), at).await?)
}
pub async fn switch_session(path: &str) -> Result<bool> {
Ok(wc::switch_session(path.to_owned()).await?)
}
pub async fn navigate_tree(target_id: &str, options: &Value) -> Result<Value> {
parse(&wc::navigate_tree(target_id.to_owned(), options.to_string()).await?)
}
pub async fn reload() -> Result<()> {
Ok(wc::reload().await?)
}