| |
| |
| |
| |
| |
| |
| |
| |
|
|
| import type { AppState } from '../../state/AppState.js' |
| import type { SetAppState, Task, TaskStateBase } from '../../Task.js' |
| import type { AgentId } from '../../types/ids.js' |
| import { logForDebugging } from '../../utils/debug.js' |
| import { dequeueAllMatching } from '../../utils/messageQueueManager.js' |
| import { evictTaskOutput } from '../../utils/task/diskOutput.js' |
| import { updateTaskState } from '../../utils/task/framework.js' |
| import { isLocalShellTask } from '../LocalShellTask/guards.js' |
| import { killTask } from '../LocalShellTask/killShellTasks.js' |
|
|
| export type MonitorMcpTaskState = TaskStateBase & { |
| type: 'monitor_mcp' |
| agentId?: AgentId |
| } |
|
|
| function isMonitorMcpTask(task: unknown): task is MonitorMcpTaskState { |
| return ( |
| typeof task === 'object' && |
| task !== null && |
| 'type' in task && |
| task.type === 'monitor_mcp' |
| ) |
| } |
|
|
| export const MonitorMcpTask: Task = { |
| name: 'MonitorMcpTask', |
| type: 'monitor_mcp', |
| async kill(taskId, setAppState) { |
| updateTaskState<MonitorMcpTaskState>(taskId, setAppState, task => { |
| if (task.status !== 'running') { |
| return task |
| } |
|
|
| return { |
| ...task, |
| status: 'killed', |
| notified: true, |
| endTime: Date.now(), |
| } |
| }) |
| void evictTaskOutput(taskId) |
| }, |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export function killMonitorMcpTasksForAgent( |
| agentId: AgentId, |
| getAppState: () => AppState, |
| setAppState: SetAppState, |
| ): void { |
| const tasks = getAppState().tasks ?? {} |
|
|
| for (const [taskId, task] of Object.entries(tasks)) { |
| |
| if ( |
| isMonitorMcpTask(task) && |
| task.agentId === agentId && |
| task.status === 'running' |
| ) { |
| logForDebugging( |
| `killMonitorMcpTasksForAgent: killing monitor_mcp task ${taskId} (agent ${agentId} exiting)`, |
| ) |
| void MonitorMcpTask.kill(taskId, setAppState) |
| } |
|
|
| |
| |
| |
| if ( |
| isLocalShellTask(task) && |
| task.kind === 'monitor' && |
| task.agentId === agentId && |
| task.status === 'running' |
| ) { |
| logForDebugging( |
| `killMonitorMcpTasksForAgent: killing monitor shell task ${taskId} (agent ${agentId} exiting)`, |
| ) |
| killTask(taskId, setAppState) |
| } |
| } |
|
|
| |
| |
| dequeueAllMatching(cmd => cmd.agentId === agentId) |
| } |
|
|