1use async_trait::async_trait;
4use serde_json::Value;
5
6use crate::{Identity, Permissions, ToolError};
7
8#[derive(Debug, Clone)]
16#[non_exhaustive]
17pub struct CallContext {
18 pub session_id: String,
19 pub identity: Identity,
20 pub permissions: Permissions,
21 pub key_id: Option<String>,
23}
24
25impl CallContext {
26 pub fn new(session_id: String, identity: Identity, permissions: Permissions) -> Self {
27 Self {
28 session_id,
29 identity,
30 permissions,
31 key_id: None,
32 }
33 }
34
35 pub fn with_key_id(mut self, key_id: Option<String>) -> Self {
37 self.key_id = key_id;
38 self
39 }
40}
41
42#[async_trait]
43pub trait ToolHandler: Send + Sync {
44 fn name(&self) -> &str;
46
47 fn description(&self) -> &str;
49
50 async fn call(&self, ctx: &CallContext, args: Value) -> Result<Value, ToolError>;
52}