descry-tool-core 0.3.1

Core traits and types for descry-tool framework
Documentation
//! Debug schema generation

use descry_tool_core::Tool;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::sync::Arc;

#[derive(Deserialize, JsonSchema)]
struct AddParams {
    a: i32,
    b: i32,
}

#[derive(Serialize, JsonSchema)]
struct AddOutput {
    result: i32,
}

struct AddTool;

impl Tool for AddTool {
    type Params = AddParams;
    type Output = AddOutput;

    const NAME: &'static str = "add";
    const DESCRIPTION: &'static str = "Add two numbers";

    async fn call(
        _ctx: Arc<descry_tool_core::ToolContext>,
        params: Self::Params,
    ) -> Result<Self::Output, descry_tool_core::ToolError> {
        Ok(AddOutput {
            result: params.a + params.b,
        })
    }
}

#[derive(Deserialize, JsonSchema)]
struct SubtractParams {
    x: i32,
    y: i32,
}

#[derive(Serialize, JsonSchema)]
struct SubtractOutput {
    result: i32,
}

struct SubtractTool;

impl Tool for SubtractTool {
    type Params = SubtractParams;
    type Output = SubtractOutput;

    const NAME: &'static str = "subtract";
    const DESCRIPTION: &'static str = "Subtract two numbers";

    async fn call(
        _ctx: Arc<descry_tool_core::ToolContext>,
        params: Self::Params,
    ) -> Result<Self::Output, descry_tool_core::ToolError> {
        Ok(SubtractOutput {
            result: params.x - params.y,
        })
    }
}

fn main() {
    let add_schema = AddTool::schema();
    let sub_schema = SubtractTool::schema();

    println!("Add schema:");
    println!("{}", serde_json::to_string_pretty(add_schema).unwrap());
    
    println!("\nSubtract schema:");
    println!("{}", serde_json::to_string_pretty(sub_schema).unwrap());
}