ai-agent-sdk 0.4.0

Idiomatic agent sdk inspired by the claude code source leak
Documentation
//! Config tool - dynamic configuration.
//!
//! Provides tool for reading and updating configuration.

use crate::types::*;

/// Config tool - read and update dynamic configuration
pub struct ConfigTool;

impl ConfigTool {
    pub fn new() -> Self {
        Self
    }

    pub fn input_schema(&self) -> ToolInputSchema {
        ToolInputSchema {
            schema_type: "object".to_string(),
            properties: serde_json::json!({
                "action": {
                    "type": "string",
                    "enum": ["get", "set", "list"],
                    "description": "Action to perform: get, set, or list"
                },
                "key": {
                    "type": "string",
                    "description": "Configuration key (for get/set actions)"
                },
                "value": {
                    "type": "string",
                    "description": "Configuration value (for set action)"
                }
            }),
            required: Some(vec!["action".to_string()]),
        }
    }

    pub async fn execute(&self, input: serde_json::Value, _context: &ToolContext) -> Result<ToolResult, crate::error::AgentError> {
        let action = input["action"].as_str().unwrap_or("list");
        let key = input["key"].as_str().unwrap_or("");
        let value = input["value"].as_str().unwrap_or("");

        let response = match action {
            "get" => format!("Config '{}' = (placeholder value)", key),
            "set" => format!("Config '{}' set to '{}'", key, value),
            "list" => "Config:\n- (placeholder list)".to_string(),
            _ => "Invalid action".to_string(),
        };

        Ok(ToolResult {
            result_type: "text".to_string(),
            tool_use_id: "config".to_string(),
            content: response,
            is_error: Some(false),
        })
    }
}

impl Default for ConfigTool {
    fn default() -> Self {
        Self::new()
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_config_schema() {
        let tool = ConfigTool::new();
        let schema = tool.input_schema();
        assert!(schema.properties.get("action").is_some());
    }
}