deepseek/agent/builtin_tools/
cron_delete.rs1use std::sync::{Arc, Mutex};
4
5use async_trait::async_trait;
6use serde_json::{json, Value};
7
8use crate::agent::scheduler::{Scheduler, TaskId};
9use crate::agent::tool::{Tool, ToolDefinition};
10
11pub struct CronDeleteTool {
12 pub scheduler: Arc<Mutex<Scheduler>>,
13}
14
15impl CronDeleteTool {
16 pub fn new(scheduler: Arc<Mutex<Scheduler>>) -> Self {
17 Self { scheduler }
18 }
19}
20
21#[async_trait]
22impl Tool for CronDeleteTool {
23 fn name(&self) -> &str {
24 "CronDelete"
25 }
26
27 fn definition(&self) -> ToolDefinition {
28 ToolDefinition {
29 name: self.name().to_string(),
30 description: "Cancel a scheduled task by its 8-character `task_id` \
31 (as returned by CronCreate or CronList)."
32 .into(),
33 parameters: json!({
34 "type": "object",
35 "properties": {
36 "task_id": { "type": "string" }
37 },
38 "required": ["task_id"]
39 }),
40 }
41 }
42
43 async fn call_json(&self, args: Value) -> Result<String, String> {
44 let raw = args
45 .get("task_id")
46 .and_then(Value::as_str)
47 .ok_or_else(|| "CronDelete: missing string `task_id`".to_string())?;
48 let id = TaskId::from_raw(raw);
49
50 let mut sched = self
51 .scheduler
52 .lock()
53 .map_err(|_| "CronDelete: scheduler lock poisoned".to_string())?;
54
55 let deleted = sched.delete(&id);
56 Ok(serde_json::to_string(&json!({
57 "task_id": id.as_str(),
58 "deleted": deleted,
59 }))
60 .unwrap())
61 }
62}