/**
 * Agent Teams
 *
 * Coordinates multiple agent instances working together on tasks.
 * Supports auto, in-process, and tmux teammate modes.
 */
import { logger } from '../../utils/logger.js';
const DEFAULT_TEAM_CONFIG = {
    mode: 'auto',
    maxTeammates: 5,
    sharedTaskList: true,
};
export class AgentTeam {
    teammates = new Map();
    messageQueue = [];
    config;
    constructor(config) {
        this.config = { ...DEFAULT_TEAM_CONFIG, ...config };
    }
    addTeammate(name, config = {}) {
        if (this.teammates.has(name)) {
            logger.warn(`Teammate "${name}" already exists`);
            return false;
        }
        if (this.teammates.size >= this.config.maxTeammates) {
            logger.warn(`Max teammates (${this.config.maxTeammates}) reached`);
            return false;
        }
        this.teammates.set(name, {
            name,
            config,
            status: 'idle',
            assignedTasks: [],
        });
        logger.info(`Teammate "${name}" added to team`);
        return true;
    }
    removeTeammate(name) {
        if (!this.teammates.has(name)) {
            logger.warn(`Teammate "${name}" not found`);
            return false;
        }
        this.teammates.delete(name);
        logger.info(`Teammate "${name}" removed from team`);
        return true;
    }
    getTeammates() {
        return Array.from(this.teammates.values());
    }
    delegateTask(taskId, teammateName) {
        const teammate = this.teammates.get(teammateName);
        if (!teammate) {
            logger.warn(`Teammate "${teammateName}" not found for task delegation`);
            return false;
        }
        teammate.assignedTasks.push(taskId);
        teammate.status = 'busy';
        logger.info(`Task "${taskId}" delegated to "${teammateName}"`);
        return true;
    }
    broadcastMessage(message, from = 'system') {
        const teamMessage = {
            from,
            to: 'all',
            content: message,
            timestamp: Date.now(),
        };
        this.messageQueue.push(teamMessage);
        logger.info(`Broadcast message from "${from}" to all teammates`);
    }
    sendMessage(from, to, content) {
        const teamMessage = {
            from,
            to,
            content,
            timestamp: Date.now(),
        };
        this.messageQueue.push(teamMessage);
        logger.debug(`Message from "${from}" to "${to}"`);
    }
    getMessages(forTeammate) {
        return this.messageQueue.filter((msg) => msg.to === forTeammate || msg.to === 'all');
    }
    getSharedContext() {
        const tasks = new Map();
        for (const teammate of this.teammates.values()) {
            for (const taskId of teammate.assignedTasks) {
                tasks.set(taskId, {
                    assignedTo: teammate.name,
                    status: teammate.status,
                });
            }
        }
        return {
            tasks,
            teammates: Array.from(this.teammates.keys()),
            messages: [...this.messageQueue],
        };
    }
    getConfig() {
        return { ...this.config };
    }
}
let agentTeamInstance = null;
export function getAgentTeam(config) {
    if (!agentTeamInstance) {
        agentTeamInstance = new AgentTeam(config);
    }
    return agentTeamInstance;
}
export function resetAgentTeam() {
    agentTeamInstance = null;
}
//# sourceMappingURL=agent-team.js.map