descry-tool-core 0.3.1

Core traits and types for descry-tool framework
Documentation
//! Simple Tower middleware example
//!
//! Demonstrates basic Tower Service usage

use descry_tool_core::{
    tower::{tool_service, ToolRequest, ToolService},
    Tool, ToolContext, ToolError,
};
use tower::Service;
use descry_tool_macros::tool;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::sync::Arc;

// Define a simple tool
#[derive(Deserialize, JsonSchema)]
struct EchoParams {
    message: String,
}

#[derive(Serialize, JsonSchema)]
struct EchoOutput {
    reply: String,
}

#[tool(
    name = "echo",
    description = "Echo back a message"
)]
async fn echo(_ctx: Arc<ToolContext>, params: EchoParams) -> Result<EchoOutput, ToolError> {
    Ok(EchoOutput {
        reply: format!("Echo: {}", params.message),
    })
}

#[tokio::main]
async fn main() {
    println!("=== Tower Middleware Example ===\n");

    // Create a tool service
    let mut service = tool_service();

    // Create a request
    let ctx = Arc::new(ToolContext::new());
    let request = ToolRequest {
        name: "echo".to_string(),
        params: serde_json::json!({"message": "Hello from Tower!"}),
        ctx,
    };

    // Call the service
    match service.call(request).await {
        Ok(response) => {
            println!("Response: {:?}", serde_json::to_string_pretty(&response.output).unwrap());
        }
        Err(e) => {
            eprintln!("Error: {}", e);
        }
    }
}