oxios_kernel/tools/
pending_tool_approvals.rs1use parking_lot::Mutex;
10use std::collections::HashMap;
11use tokio::sync::oneshot;
12use uuid::Uuid;
13
14#[derive(Debug, Clone, Copy, PartialEq, Eq)]
16pub enum ToolApprovalResult {
17 Approved,
19 Denied,
21}
22
23struct PendingEntry {
24 tool_name: String,
25 sender: oneshot::Sender<ToolApprovalResult>,
26}
27
28#[derive(Default)]
30pub struct PendingToolApprovals {
31 inner: Mutex<HashMap<Uuid, PendingEntry>>,
32}
33
34impl PendingToolApprovals {
35 pub fn new() -> Self {
37 Self::default()
38 }
39
40 pub fn register(&self, tool_name: String) -> (Uuid, oneshot::Receiver<ToolApprovalResult>) {
43 let id = Uuid::new_v4();
44 let (tx, rx) = oneshot::channel();
45 self.inner.lock().insert(
46 id,
47 PendingEntry {
48 tool_name,
49 sender: tx,
50 },
51 );
52 (id, rx)
53 }
54
55 pub fn resolve(&self, id: Uuid, result: ToolApprovalResult) -> Option<String> {
58 let entry = self.inner.lock().remove(&id)?;
59 let _ = entry.sender.send(result);
60 Some(entry.tool_name)
61 }
62
63 pub fn cancel_all(&self) {
65 let mut guard = self.inner.lock();
66 for (_, entry) in guard.drain() {
67 let _ = entry.sender.send(ToolApprovalResult::Denied);
68 }
69 }
70}