ai-agent-sdk 0.5.0

Idiomatic agent sdk inspired by the claude code source leak
Documentation
//! Ask user question tool.
//!
//! Provides tool for asking the user for input.

use crate::types::*;

/// AskUserQuestion tool - ask the user for input
pub struct AskUserQuestionTool;

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

    pub fn input_schema(&self) -> ToolInputSchema {
        ToolInputSchema {
            schema_type: "object".to_string(),
            properties: serde_json::json!({
                "question": {
                    "type": "string",
                    "description": "The question to ask the user"
                },
                "header": {
                    "type": "string",
                    "description": "Very short label displayed as a chip/tag"
                },
                "options": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {
                            "label": { "type": "string" },
                            "description": { "type": "string" }
                        }
                    },
                    "description": "Available choices for this question"
                },
                "multiSelect": {
                    "type": "boolean",
                    "description": "Set to true to allow multiple answers"
                }
            }),
            required: Some(vec!["question".to_string(), "header".to_string(), "options".to_string()]),
        }
    }

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

        let options = input["options"].as_array()
            .map(|arr| arr.iter().filter_map(|v| v.get("label").and_then(|l| l.as_str())).collect::<Vec<_>>())
            .unwrap_or_default();

        let response = format!(
            "Asking user: {}\nHeader: {}\nOptions: {:?}\nNote: Full implementation would present these options to the user and wait for their response.",
            question, header, options
        );

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

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

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

    #[test]
    fn test_ask_user_question_schema() {
        let tool = AskUserQuestionTool::new();
        let schema = tool.input_schema();
        assert!(schema.properties.get("question").is_some());
        assert!(schema.properties.get("header").is_some());
        assert!(schema.properties.get("options").is_some());
    }
}