use crate::protocol::{AgentEvent, ToolCall, ToolResultSummary};
pub use aios_protocol;
pub fn to_protocol_event_kind(event: &AgentEvent) -> Option<aios_protocol::EventKind> {
let json = serde_json::to_value(event).ok()?;
serde_json::from_value(json).ok()
}
impl From<&ToolCall> for aios_protocol::tool::ToolCall {
fn from(call: &ToolCall) -> Self {
aios_protocol::tool::ToolCall {
call_id: call.call_id.clone(),
tool_name: call.tool_name.clone(),
input: call.input.clone(),
requested_capabilities: Vec::new(),
}
}
}
impl ToolResultSummary {
pub fn to_protocol_json(&self) -> serde_json::Value {
serde_json::json!({
"call_id": self.call_id,
"tool_name": self.tool_name,
"output": self.output,
})
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::protocol::AgentEvent;
#[test]
fn agent_event_to_protocol_run_started() {
let event = AgentEvent::RunStarted {
run_id: "run-1".into(),
session_id: "sess-1".into(),
provider: "anthropic".into(),
max_iterations: 10,
};
let kind = to_protocol_event_kind(&event);
assert!(kind.is_some());
}
#[test]
fn tool_call_conversion() {
let arcan_call = ToolCall {
call_id: "c1".into(),
tool_name: "read_file".into(),
input: serde_json::json!({"path": "/tmp"}),
};
let proto_call: aios_protocol::tool::ToolCall = (&arcan_call).into();
assert_eq!(proto_call.call_id, "c1");
assert_eq!(proto_call.tool_name, "read_file");
}
}