Skip to main content

base/interface/
plugin_call.rs

1//! A host's call of a tool object outside any turn, through the session's
2//! whole tool pipeline — permission, `PreToolUse`, `tool.around`, the call,
3//! `PostToolUse`, telemetry — the way the model's calls go, beside a turn
4//! that may be running. The tool is handed over, so it need not be one the model can call.
5//!
6//! The call itself is the host's approval: what the session would ask about
7//! runs, what its rules deny or its mode refuses does not. Nobody is asked
8//! anything, neither about it nor about the calls it makes. `permission_rules`
9//! hold after the session's own for this call and the calls it makes: a deny
10//! refuses in any mode, an allow answers only what the mode would ask.
11
12use std::sync::Arc;
13
14use serde_json::Value;
15use tokio_util::sync::CancellationToken;
16
17use crate::interface::tool::Tool;
18use crate::interface::tool_middleware::ToolOutcome;
19use crate::permission::PermissionRule;
20
21#[async_trait::async_trait]
22pub trait HostToolRunner: Send + Sync {
23    async fn run(
24        &self,
25        tool: Arc<dyn Tool>,
26        input: Value,
27        permission_rules: Vec<PermissionRule>,
28        cancel: CancellationToken,
29    ) -> HostCallOutcome;
30    /// The session's tool `name`, if its tool policy lets it have one.
31    fn tool(&self, name: &str) -> Option<Arc<dyn Tool>>;
32}
33
34/// `outcome` `Err`: no answer — refused, invalid, failed, the session gone. `by_middleware`: the
35/// answer is not the tool's own — a `tool.around` gave or changed it, or a `tool.result` rewrote
36/// it. `stopped`: the host or the session's end told the call to stop.
37#[derive(Debug, Clone, PartialEq)]
38pub struct HostCallOutcome {
39    pub outcome: ToolOutcome,
40    pub by_middleware: bool,
41    pub stopped: bool,
42}