use super::shared::*;
use crate::DriverCallback;
use crate::DriverContext;
use crate::DriverResult;
use crate::{
DriverCategory,
types::{Driver, DriverParameter},
};
use serde_json::{Value, json};
use std::collections::HashMap;
use tracing::{debug, info, warn};
#[derive(Debug)]
pub struct HaveHeadBrowserTabCloseDriver;
#[async_trait::async_trait]
impl Driver for HaveHeadBrowserTabCloseDriver {
fn name(&self) -> &str {
"have_head_browser_tab_close"
}
fn description(&self) -> &str {
"Close the current browser tab"
}
fn usage_hint(&self) -> &str {
"Use this skill to close the current tab"
}
fn parameters(&self) -> Vec<DriverParameter> {
return vec![];
}
fn example_call(&self) -> DriverResult<Value> {
return Ok(json!({
"action": "have_head_browser_tab_close"
}));
}
fn example_output(&self) -> String {
return "Closed current tab".to_string();
}
fn category(&self) -> DriverCategory {
return DriverCategory::HaveHeadBrowser;
}
async fn execute(
&self,
parameters: &HashMap<String, Value>,
callback: Option<&dyn DriverCallback>,
context: Option<&DriverContext>,
) -> DriverResult<String> {
debug!("Executing have_head_browser_tab_close driver");
let tab = get_current_tab().map_err(|e| {
debug!("Failed to get current tab: {}", e);
return crate::DriverError::execution(format!("Failed to get current tab: {}", e));
})?;
tab.close(false).map_err(|e| {
warn!("Failed to close tab: {}", e);
return crate::DriverError::execution(format!("Failed to close tab: {}", e));
})?;
clear_current_tab();
info!("Closed current tab");
return Ok("Closed current tab".to_string());
}
}