use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ToolDefinition {
pub name: String,
pub description: String,
pub input_schema: serde_json::Value,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ToolCall {
pub id: String,
pub name: String,
pub arguments: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ToolResult {
pub tool_call_id: String,
pub content: String,
}
#[cfg(test)]
mod tests {
use super::*;
use serde_json::json;
#[test]
fn tool_definition_roundtrip() {
let def = ToolDefinition {
name: "get_weather".into(),
description: "Get current weather".into(),
input_schema: json!({
"type": "object",
"properties": {
"location": { "type": "string" }
},
"required": ["location"]
}),
};
let json = serde_json::to_string(&def).unwrap();
let back: ToolDefinition = serde_json::from_str(&json).unwrap();
assert_eq!(back.name, "get_weather");
assert_eq!(back.description, "Get current weather");
}
#[test]
fn tool_call_roundtrip() {
let call = ToolCall {
id: "call_abc123".into(),
name: "search".into(),
arguments: r#"{"query": "rust"}"#.into(),
};
let json = serde_json::to_string(&call).unwrap();
let back: ToolCall = serde_json::from_str(&json).unwrap();
assert_eq!(back.id, "call_abc123");
assert_eq!(back.name, "search");
assert_eq!(back.arguments, r#"{"query": "rust"}"#);
}
#[test]
fn tool_result_roundtrip() {
let result = ToolResult {
tool_call_id: "call_abc123".into(),
content: "Found 3 results".into(),
};
let json = serde_json::to_string(&result).unwrap();
let back: ToolResult = serde_json::from_str(&json).unwrap();
assert_eq!(back.tool_call_id, "call_abc123");
assert_eq!(back.content, "Found 3 results");
}
}