use super::task_list::TaskList;
use crate::error::Result;
use crate::llm::tools::{FunctionDescriptor, LlmTool, ToolDescriptor};
use serde_json::{json, Value};
use std::collections::HashMap;
use std::sync::{Arc, Mutex};
#[derive(Clone)]
pub struct ClearTasksTool {
task_list: Arc<Mutex<TaskList>>,
}
impl ClearTasksTool {
pub fn new(task_list: Arc<Mutex<TaskList>>) -> Self {
Self { task_list }
}
}
impl LlmTool for ClearTasksTool {
fn run(&self, _args: &HashMap<String, Value>) -> Result<Value> {
let mut task_list = self.task_list.lock().unwrap();
let count = task_list.clear_tasks();
Ok(json!({
"count": count,
"summary": format!("Cleared {} tasks from the list", count)
}))
}
fn descriptor(&self) -> ToolDescriptor {
ToolDescriptor {
r#type: "function".to_string(),
function: FunctionDescriptor {
name: "clear_tasks".to_string(),
description: "Remove all tasks from the task list.".to_string(),
parameters: json!({
"type": "object",
"properties": {}
}),
},
}
}
fn clone_box(&self) -> Box<dyn LlmTool> {
Box::new(self.clone())
}
}