(
&self,
args: serde_json::Value,
ctx: ToolContext,
)
| 50 | } |
| 51 | |
| 52 | async fn execute( |
| 53 | &self, |
| 54 | args: serde_json::Value, |
| 55 | ctx: ToolContext, |
| 56 | ) -> Result<ToolResult, ToolError> { |
| 57 | let input: TodoReadInput = |
| 58 | serde_json::from_value(args).map_err(|e| ToolError::InvalidArguments(e.to_string()))?; |
| 59 | |
| 60 | let session_id = input |
| 61 | .session_id |
| 62 | .clone() |
| 63 | .unwrap_or_else(|| ctx.session_id.clone()); |
| 64 | |
| 65 | ctx.ask_permission( |
| 66 | crate::PermissionRequest::new("todoread") |
| 67 | .with_metadata("session_id", serde_json::json!(&session_id)) |
| 68 | .always_allow(), |
| 69 | ) |
| 70 | .await?; |
| 71 | |
| 72 | let todos = ctx.do_todo_get().await?; |
| 73 | |
| 74 | let output = format_todos_from_data(&todos); |
| 75 | |
| 76 | let todos_json: Vec<serde_json::Value> = todos |
| 77 | .iter() |
| 78 | .map(|t| { |
| 79 | serde_json::json!({ |
| 80 | "content": t.content, |
| 81 | "status": t.status, |
| 82 | "priority": t.priority |
| 83 | }) |
| 84 | }) |
| 85 | .collect(); |
| 86 | |
| 87 | let mut metadata = std::collections::HashMap::new(); |
| 88 | metadata.insert("todos".to_string(), serde_json::json!(todos_json)); |
| 89 | metadata.insert("count".to_string(), serde_json::json!(todos.len())); |
| 90 | |
| 91 | Ok(ToolResult { |
| 92 | title: format!("Todo List ({} items)", todos.len()), |
| 93 | output, |
| 94 | metadata, |
| 95 | truncated: false, |
| 96 | }) |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | #[async_trait] |
nothing calls this directly
no test coverage detected