1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//! Neutral contracts for capability-contributed per-tool execution hooks.
use crate::tool_context::ToolContext;
use async_trait::async_trait;
use everruns_provider::tool_types::{ToolCall, ToolDefinition, ToolResult};
/// Decision returned by a [`PreToolUseHook`] before a tool is dispatched.
#[derive(Debug, Clone)]
pub enum PreToolUseDecision {
/// Continue with the possibly transformed call.
Continue(ToolCall),
/// Block this call without affecting sibling calls in the batch.
Block {
/// Call that was blocked.
tool_call: ToolCall,
/// Error text recorded for the model and audit stream.
reason: String,
/// Optional message for a user-facing runtime.
user_message: Option<String>,
},
}
/// Capability hook invoked before each individual tool execution.
#[async_trait]
pub trait PreToolUseHook: Send + Sync {
/// Transform or block a tool call before dispatch.
async fn before_exec(
&self,
tool_call: ToolCall,
tool_def: &ToolDefinition,
context: &ToolContext,
) -> PreToolUseDecision;
}
/// Ordering for capability-contributed post-tool hooks.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum PostToolExecHookPriority {
/// Inspect or block output before normal mutating hooks.
Guardrail = 0,
/// Default ordering for transformation and observability hooks.
Normal = 100,
}
/// Capability hook invoked after each individual tool execution.
#[async_trait]
pub trait PostToolExecHook: Send + Sync {
/// Ordering within the capability-contributed hook phase.
fn priority(&self) -> PostToolExecHookPriority {
PostToolExecHookPriority::Normal
}
/// Inspect or transform one tool result before engine event emission.
async fn after_exec(
&self,
tool_call: &ToolCall,
tool_def: &ToolDefinition,
result: &mut ToolResult,
context: &ToolContext,
);
}