Handle a confirmation response from the user Returns Ok(true) if the confirmation was found and processed, Ok(false) if no pending confirmation was found.
(
&self,
tool_id: &str,
approved: bool,
reason: Option<String>,
)
| 278 | /// Returns Ok(true) if the confirmation was found and processed, |
| 279 | /// Ok(false) if no pending confirmation was found. |
| 280 | pub async fn confirm( |
| 281 | &self, |
| 282 | tool_id: &str, |
| 283 | approved: bool, |
| 284 | reason: Option<String>, |
| 285 | ) -> Result<bool, String> { |
| 286 | let pending = { |
| 287 | let mut pending_map = self.pending.write().await; |
| 288 | pending_map.remove(tool_id) |
| 289 | }; |
| 290 | |
| 291 | if let Some(confirmation) = pending { |
| 292 | // Emit confirmation received event |
| 293 | let _ = self.event_tx.send(AgentEvent::ConfirmationReceived { |
| 294 | tool_id: tool_id.to_string(), |
| 295 | approved, |
| 296 | reason: reason.clone(), |
| 297 | }); |
| 298 | |
| 299 | // Send the response |
| 300 | let response = ConfirmationResponse { approved, reason }; |
| 301 | let _ = confirmation.response_tx.send(response); |
| 302 | |
| 303 | Ok(true) |
| 304 | } else { |
| 305 | Ok(false) |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | /// Check for and handle timed out confirmations |
| 310 | /// |