Execute the interrupt command.
(self, **kwargs)
| 57 | return True |
| 58 | |
| 59 | async def execute(self, **kwargs) -> CommandResult: |
| 60 | """Execute the interrupt command.""" |
| 61 | # Get chat context |
| 62 | chat_context = kwargs.get("chat_context") |
| 63 | if not chat_context: |
| 64 | return CommandResult( |
| 65 | success=False, |
| 66 | error="Interrupt command requires chat context.", |
| 67 | ) |
| 68 | |
| 69 | # Check if there's anything to interrupt |
| 70 | interrupted_something = False |
| 71 | |
| 72 | # Try to interrupt streaming |
| 73 | if hasattr(chat_context, "is_streaming") and chat_context.is_streaming: |
| 74 | if hasattr(chat_context, "interrupt_streaming"): |
| 75 | chat_context.interrupt_streaming() |
| 76 | interrupted_something = True |
| 77 | message = "Streaming response interrupted." |
| 78 | |
| 79 | # Try to interrupt tool execution |
| 80 | if ( |
| 81 | not interrupted_something |
| 82 | and hasattr(chat_context, "is_executing_tool") |
| 83 | and chat_context.is_executing_tool |
| 84 | ): |
| 85 | if hasattr(chat_context, "interrupt_tool_execution"): |
| 86 | chat_context.interrupt_tool_execution() |
| 87 | interrupted_something = True |
| 88 | message = "Tool execution interrupted." |
| 89 | |
| 90 | # Try general cancellation |
| 91 | if not interrupted_something and hasattr( |
| 92 | chat_context, "cancel_current_operation" |
| 93 | ): |
| 94 | chat_context.cancel_current_operation() |
| 95 | interrupted_something = True |
| 96 | message = "Current operation cancelled." |
| 97 | |
| 98 | if interrupted_something: |
| 99 | return CommandResult( |
| 100 | success=True, |
| 101 | output=message, |
| 102 | ) |
| 103 | else: |
| 104 | return CommandResult( |
| 105 | success=True, |
| 106 | output="Nothing to interrupt.", |
| 107 | ) |
nothing calls this directly
no test coverage detected