/**
 * Subagent Execution Events
 *
 * Mutable state store for subagent progress, polled by the UI component.
 * Uses simple mutable objects instead of EventEmitter to avoid
 * Ink render flushing issues with in-process async execution.
 *
 * Supports multiple concurrent agents via a Map keyed by agentId.
 */
/** Map of agent instance ID → progress state for concurrent agents */
const subagentProgressMap = new Map();
/**
 * Legacy single-agent progress state.
 * Still used by single-agent callers and as a fallback.
 */
export const subagentProgress = {
    subagentName: '',
    status: 'running',
    toolCallCount: 0,
    turnCount: 0,
    tokenCount: 0,
    toolHistory: [],
};
/** Get progress for a specific agent instance */
export function getSubagentProgress(agentId) {
    return subagentProgressMap.get(agentId) ?? subagentProgress;
}
/** Get all active agent progress entries */
export function getAllSubagentProgress() {
    return subagentProgressMap;
}
/** Update progress for a specific agent instance */
export function updateSubagentProgressById(agentId, event) {
    const existing = subagentProgressMap.get(agentId);
    if (existing) {
        existing.subagentName = event.subagentName;
        existing.status = event.status;
        existing.currentTool = event.currentTool;
        existing.toolCallCount = event.toolCallCount;
        existing.turnCount = event.turnCount;
        existing.tokenCount = event.tokenCount;
    }
    else {
        subagentProgressMap.set(agentId, { ...event, toolHistory: [] });
    }
}
/** Update progress — called by the executor (legacy single-agent path) */
export function updateSubagentProgress(event) {
    subagentProgress.subagentName = event.subagentName;
    subagentProgress.status = event.status;
    subagentProgress.currentTool = event.currentTool;
    subagentProgress.toolCallCount = event.toolCallCount;
    subagentProgress.turnCount = event.turnCount;
    subagentProgress.tokenCount = event.tokenCount;
}
/**
 * Append a tool name to the subagent's tool history.
 * Mutates the existing toolHistory array so polling readers see the update
 * without needing to re-fetch the progress object.
 */
export function appendSubagentTool(agentId, toolName) {
    if (agentId) {
        const existing = subagentProgressMap.get(agentId);
        if (existing) {
            existing.toolHistory.push(toolName);
        }
    }
    else {
        subagentProgress.toolHistory.push(toolName);
    }
}
/** Reset progress for a specific agent instance */
export function resetSubagentProgressById(agentId) {
    subagentProgressMap.set(agentId, {
        subagentName: '',
        status: 'running',
        toolCallCount: 0,
        turnCount: 0,
        tokenCount: 0,
        toolHistory: [],
    });
}
/** Remove a specific agent's progress entry */
export function removeSubagentProgress(agentId) {
    subagentProgressMap.delete(agentId);
}
/** Clear all concurrent agent progress entries */
export function clearAllSubagentProgress() {
    subagentProgressMap.clear();
}
/** Reset legacy single-agent progress state */
export function resetSubagentProgress() {
    subagentProgress.subagentName = '';
    subagentProgress.status = 'running';
    subagentProgress.currentTool = undefined;
    subagentProgress.toolCallCount = 0;
    subagentProgress.turnCount = 0;
    subagentProgress.tokenCount = 0;
    subagentProgress.toolHistory.length = 0;
}
//# sourceMappingURL=subagent-events.js.map