use pe_core::message::ToolCall;
pub trait ToolCallInterceptor: Send + Sync {
fn intercept(&self, call: ToolCall) -> ToolCall;
}
pub struct PassthroughInterceptor;
impl ToolCallInterceptor for PassthroughInterceptor {
fn intercept(&self, call: ToolCall) -> ToolCall {
call
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn passthrough_interceptor_returns_unchanged() {
let interceptor = PassthroughInterceptor;
let call = ToolCall {
id: "tc_1".into(),
name: "search".into(),
args: serde_json::json!({"query": "test"}),
};
let result = interceptor.intercept(call.clone());
assert_eq!(result.id, "tc_1");
assert_eq!(result.name, "search");
assert_eq!(result.args, serde_json::json!({"query": "test"}));
}
struct PrefixInterceptor {
prefix: String,
}
impl ToolCallInterceptor for PrefixInterceptor {
fn intercept(&self, mut call: ToolCall) -> ToolCall {
call.name = format!("{}_{}", self.prefix, call.name);
call
}
}
#[test]
fn custom_interceptor_modifies_call() {
let interceptor = PrefixInterceptor {
prefix: "safe".into(),
};
let call = ToolCall {
id: "tc_2".into(),
name: "delete".into(),
args: serde_json::json!({}),
};
let result = interceptor.intercept(call);
assert_eq!(result.name, "safe_delete");
assert_eq!(result.id, "tc_2");
}
}