use serde::{Deserialize, Serialize};
pub use haki_llm::{Message, Role};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ToolCall {
pub id: String,
pub name: String,
pub input: serde_json::Value,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ToolResult {
pub tool_call_id: String,
pub content: String,
pub is_error: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum ContentBlock {
Text { text: String },
ToolUse(ToolCall),
ToolResult(ToolResult),
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn tool_call_roundtrip() {
let tc = ToolCall {
id: "call_1".into(),
name: "bash".into(),
input: serde_json::json!({ "command": "ls" }),
};
let json = serde_json::to_string(&tc).unwrap();
let back: ToolCall = serde_json::from_str(&json).unwrap();
assert_eq!(back.name, "bash");
}
#[test]
fn tool_result_error_flag() {
let tr = ToolResult {
tool_call_id: "call_1".into(),
content: "permission denied".into(),
is_error: true,
};
assert!(tr.is_error);
}
#[test]
fn content_block_text_tag() {
let block = ContentBlock::Text { text: "hello".into() };
let json = serde_json::to_value(&block).unwrap();
assert_eq!(json["type"], "text");
}
}