inProcessTeammateHelpers.ts
utils/inProcessTeammateHelpers.ts
No strong subsystem tag
103
Lines
2988
Bytes
4
Exports
4
Imports
10
Keywords
What this is
This page documents one file from the repository and includes its full source so you can read it without leaving the docs site.
Beginner explanation
This file is one piece of the larger system. Its name, directory, imports, and exports show where it fits. Start by reading the exports and related files first.
How it is used
Start from the exports list and related files. Those are the easiest clues for where this file fits into the system.
Expert explanation
Architecturally, this file intersects with general runtime concerns. It contains 103 lines, 4 detected imports, and 4 detected exports.
Important relationships
Detected exports
findInProcessTeammateTaskIdsetAwaitingPlanApprovalhandlePlanApprovalResponseisPermissionRelatedResponse
Keywords
taskappstateteammatesetappstateparamin-processresponsetaskidmessageagent
Detected imports
../state/AppState.js../tasks/InProcessTeammateTask/types.js./task/framework.js./teammateMailbox.js
Source notes
This page embeds the full file contents. Small or leaf files are still indexed honestly instead of being over-explained.
Full source
/**
* In-Process Teammate Helpers
*
* Helper functions for in-process teammate integration.
* Provides utilities to:
* - Find task ID by agent name
* - Handle plan approval responses
* - Update awaitingPlanApproval state
* - Detect permission-related messages
*/
import type { AppState } from '../state/AppState.js'
import {
type InProcessTeammateTaskState,
isInProcessTeammateTask,
} from '../tasks/InProcessTeammateTask/types.js'
import { updateTaskState } from './task/framework.js'
import {
isPermissionResponse,
isSandboxPermissionResponse,
type PlanApprovalResponseMessage,
} from './teammateMailbox.js'
type SetAppState = (updater: (prev: AppState) => AppState) => void
/**
* Find the task ID for an in-process teammate by agent name.
*
* @param agentName - The agent name (e.g., "researcher")
* @param appState - Current AppState
* @returns Task ID if found, undefined otherwise
*/
export function findInProcessTeammateTaskId(
agentName: string,
appState: AppState,
): string | undefined {
for (const task of Object.values(appState.tasks)) {
if (
isInProcessTeammateTask(task) &&
task.identity.agentName === agentName
) {
return task.id
}
}
return undefined
}
/**
* Set awaitingPlanApproval state for an in-process teammate.
*
* @param taskId - Task ID of the in-process teammate
* @param setAppState - AppState setter
* @param awaiting - Whether teammate is awaiting plan approval
*/
export function setAwaitingPlanApproval(
taskId: string,
setAppState: SetAppState,
awaiting: boolean,
): void {
updateTaskState<InProcessTeammateTaskState>(taskId, setAppState, task => ({
...task,
awaitingPlanApproval: awaiting,
}))
}
/**
* Handle plan approval response for an in-process teammate.
* Called by the message callback when a plan_approval_response arrives.
*
* This resets awaitingPlanApproval to false. The permissionMode from the
* response is handled separately by the agent loop (Task #11).
*
* @param taskId - Task ID of the in-process teammate
* @param _response - The plan approval response message (for future use)
* @param setAppState - AppState setter
*/
export function handlePlanApprovalResponse(
taskId: string,
_response: PlanApprovalResponseMessage,
setAppState: SetAppState,
): void {
setAwaitingPlanApproval(taskId, setAppState, false)
}
// ============ Permission Delegation Helpers ============
/**
* Check if a message is a permission-related response.
* Used by in-process teammate message handlers to detect and process
* permission responses from the team leader.
*
* Handles both tool permissions and sandbox (network host) permissions.
*
* @param messageText - The raw message text to check
* @returns true if the message is a permission response
*/
export function isPermissionRelatedResponse(messageText: string): boolean {
return (
!!isPermissionResponse(messageText) ||
!!isSandboxPermissionResponse(messageText)
)
}