(taskId, setAppState)
| 809 | name: 'RemoteAgentTask', |
| 810 | type: 'remote_agent', |
| 811 | async kill(taskId, setAppState) { |
| 812 | let toolUseId: string | undefined; |
| 813 | let description: string | undefined; |
| 814 | let sessionId: string | undefined; |
| 815 | let killed = false; |
| 816 | updateTaskState<RemoteAgentTaskState>(taskId, setAppState, task => { |
| 817 | if (task.status !== 'running') { |
| 818 | return task; |
| 819 | } |
| 820 | toolUseId = task.toolUseId; |
| 821 | description = task.description; |
| 822 | sessionId = task.sessionId; |
| 823 | killed = true; |
| 824 | return { |
| 825 | ...task, |
| 826 | status: 'killed', |
| 827 | notified: true, |
| 828 | endTime: Date.now() |
| 829 | }; |
| 830 | }); |
| 831 | |
| 832 | // Close the task_started bookend for SDK consumers. The poll loop's |
| 833 | // early-return when status!=='running' won't emit a notification. |
| 834 | if (killed) { |
| 835 | emitTaskTerminatedSdk(taskId, 'stopped', { |
| 836 | toolUseId, |
| 837 | summary: description |
| 838 | }); |
| 839 | // Archive the remote session so it stops consuming cloud resources. |
| 840 | if (sessionId) { |
| 841 | void archiveRemoteSession(sessionId).catch(e => logForDebugging(`RemoteAgentTask archive failed: ${String(e)}`)); |
| 842 | } |
| 843 | } |
| 844 | void evictTaskOutput(taskId); |
| 845 | void removeRemoteAgentMetadata(taskId); |
| 846 | logForDebugging(`RemoteAgentTask ${taskId} killed, archiving session ${sessionId ?? 'unknown'}`); |
| 847 | } |
| 848 | }; |
| 849 | |
| 850 | /** |
nothing calls this directly
no test coverage detected