use serde::{Deserialize, Serialize};
use crate::role_orchestration::roles::AgentRole;
use super::capability::ToolCapability;
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ToolRequest {
pub tool_name: String,
pub capability: ToolCapability,
pub params: serde_json::Value,
pub requesting_role: AgentRole,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum PolicyVerdict {
Allowed,
Denied { reason: String },
RequiresApproval { reason: String },
}
impl PolicyVerdict {
pub fn is_allowed(&self) -> bool {
matches!(self, PolicyVerdict::Allowed)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_policy_verdict_is_allowed() {
assert!(PolicyVerdict::Allowed.is_allowed());
assert!(!PolicyVerdict::Denied {
reason: "nope".into()
}
.is_allowed());
assert!(!PolicyVerdict::RequiresApproval {
reason: "ask".into()
}
.is_allowed());
}
#[test]
fn test_tool_request_serde_roundtrip() {
let req = ToolRequest {
tool_name: "bash".into(),
capability: ToolCapability::ShellExec,
params: serde_json::json!({"cmd": "ls"}),
requesting_role: AgentRole::Coder,
};
let json = serde_json::to_string(&req).unwrap();
let back: ToolRequest = serde_json::from_str(&json).unwrap();
assert_eq!(req, back);
}
}