()
| 391 | }; |
| 392 | |
| 393 | const handleStop = async () => { |
| 394 | if (!run?.id) { |
| 395 | console.error('[AgentRunOutputViewer] No run ID available to stop'); |
| 396 | return; |
| 397 | } |
| 398 | |
| 399 | try { |
| 400 | // Call the API to kill the agent session |
| 401 | const success = await api.killAgentSession(run.id); |
| 402 | |
| 403 | if (success) { |
| 404 | console.log(`[AgentRunOutputViewer] Successfully stopped agent session ${run.id}`); |
| 405 | setToast({ message: 'Agent execution stopped', type: 'success' }); |
| 406 | |
| 407 | // Clean up listeners |
| 408 | unlistenRefs.current.forEach(unlisten => unlisten()); |
| 409 | unlistenRefs.current = []; |
| 410 | hasSetupListenersRef.current = false; |
| 411 | |
| 412 | // Add a message indicating execution was stopped |
| 413 | const stopMessage: ClaudeStreamMessage = { |
| 414 | type: "result", |
| 415 | subtype: "error", |
| 416 | is_error: true, |
| 417 | result: "Execution stopped by user", |
| 418 | duration_ms: 0, |
| 419 | usage: { |
| 420 | input_tokens: 0, |
| 421 | output_tokens: 0 |
| 422 | } |
| 423 | }; |
| 424 | setMessages(prev => [...prev, stopMessage]); |
| 425 | |
| 426 | // Update the tab status |
| 427 | updateTabStatus(tabId, 'idle'); |
| 428 | |
| 429 | // Refresh the output to get updated status |
| 430 | await loadOutput(true); |
| 431 | } else { |
| 432 | console.warn(`[AgentRunOutputViewer] Failed to stop agent session ${run.id} - it may have already finished`); |
| 433 | setToast({ message: 'Failed to stop agent - it may have already finished', type: 'error' }); |
| 434 | } |
| 435 | } catch (err) { |
| 436 | console.error('[AgentRunOutputViewer] Failed to stop agent:', err); |
| 437 | setToast({ |
| 438 | message: `Failed to stop execution: ${err instanceof Error ? err.message : 'Unknown error'}`, |
| 439 | type: 'error' |
| 440 | }); |
| 441 | } |
| 442 | }; |
| 443 | |
| 444 | const handleScroll = (e: React.UIEvent<HTMLDivElement>) => { |
| 445 | const target = e.currentTarget; |
nothing calls this directly
no test coverage detected