Cancel active operation. last operation if no operation id is provided.
(&mut self, operation_id: Option<&str>)
| 409 | /// Cancel active operation. |
| 410 | /// last operation if no operation id is provided. |
| 411 | pub async fn cancel_operation(&mut self, operation_id: Option<&str>) -> Result<String, String> { |
| 412 | if let Some(short_id) = operation_id { |
| 413 | let available_ops = self.agent_client.list_operation_ids().await; |
| 414 | if available_ops.is_empty() { |
| 415 | return Ok("No active operations to cancel".to_string()); |
| 416 | } |
| 417 | |
| 418 | // Try to parse as full UUID first |
| 419 | if let Ok(uuid) = Uuid::parse_str(short_id) { |
| 420 | self.agent_client |
| 421 | .cancel_operation(uuid) |
| 422 | .await |
| 423 | .map_err(|e| e.to_string()) |
| 424 | } else { |
| 425 | // Try to find by short ID (first 8 characters) |
| 426 | if let Some(full_uuid) = self.agent_client.find_operation_by_short_id(short_id).await { |
| 427 | self.agent_client |
| 428 | .cancel_operation(full_uuid) |
| 429 | .await |
| 430 | .map_err(|e| e.to_string()) |
| 431 | } else { |
| 432 | let available_ops_str: Vec<String> = |
| 433 | available_ops.iter().map(|id| id.clone()[..8].to_string()).collect(); |
| 434 | Err(format!( |
| 435 | "Operation '{}' not found. Available operations: {}", |
| 436 | short_id, |
| 437 | available_ops_str.join(", ") |
| 438 | )) |
| 439 | } |
| 440 | } |
| 441 | } else { |
| 442 | // Cancel most recent operation |
| 443 | self.agent_client |
| 444 | .cancel_most_recent_operation() |
| 445 | .await |
| 446 | .map_err(|e| e.to_string()) |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | /// Clear all contexts (background operation) |
| 451 | pub async fn clear(&mut self) -> Result<String, String> { |
no test coverage detected