MCPcopy Create free account
hub / github.com/aws/amazon-q-developer-cli / cancel_operation

Method cancel_operation

crates/chat-cli/src/util/knowledge_store.rs:411–448  ·  view source on GitHub ↗

Cancel active operation. last operation if no operation id is provided.

(&mut self, operation_id: Option<&str>)

Source from the content-addressed store, hash-verified

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> {

Callers 3

invokeMethod · 0.45
handle_clearMethod · 0.45
handle_cancelMethod · 0.45

Calls 7

to_stringMethod · 0.80
mapMethod · 0.80
list_operation_idsMethod · 0.45
is_emptyMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected