use async_trait::async_trait;
use rucora_core::{
error::ToolError,
tool::{Tool, ToolCategory},
};
use serde_json::{Value, json};
pub struct EchoTool;
#[async_trait]
impl Tool for EchoTool {
fn name(&self) -> &str {
"echo"
}
fn description(&self) -> Option<&str> {
Some("回显输入参数,用于测试和调试")
}
fn categories(&self) -> &'static [ToolCategory] {
&[ToolCategory::Basic]
}
fn input_schema(&self) -> Value {
json!({
"type": "object",
"properties": {
"text": {
"type": "string",
"description": "要回显的文本内容"
}
},
"required": ["text"]
})
}
async fn call(&self, input: Value) -> Result<Value, ToolError> {
if input.get("text").is_none() {
return Err(ToolError::Message("缺少必需的 'text' 字段".to_string()));
}
Ok(input)
}
}