use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ToolCall {
pub id: String,
pub name: String,
pub arguments: serde_json::Value,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ToolResult {
pub call_id: String,
pub content: String,
pub is_error: bool,
}
impl ToolResult {
pub fn success(call_id: impl Into<String>, content: impl Into<String>) -> Self {
Self {
call_id: call_id.into(),
content: content.into(),
is_error: false,
}
}
pub fn error(call_id: impl Into<String>, content: impl Into<String>) -> Self {
Self {
call_id: call_id.into(),
content: content.into(),
is_error: true,
}
}
}
#[cfg(test)]
#[allow(clippy::unwrap_used, clippy::expect_used)]
mod tests {
use super::*;
#[test]
fn test_tool_result_success() {
let result = ToolResult::success("call_1", "output");
assert!(!result.is_error);
assert_eq!(result.content, "output");
}
#[test]
fn test_tool_result_error() {
let result = ToolResult::error("call_1", "failed");
assert!(result.is_error);
}
}