import { DeepThinkingEngine } from '../thinking/engine.js';
export class AgentCoordinator {
    engine;
    constructor(maxDepth = 3) {
        this.engine = new DeepThinkingEngine(maxDepth);
    }
    async dispatch(prompt, parallelCount = 3) {
        const tasks = this.splitTask(prompt, parallelCount);
        const results = await Promise.all(tasks.map(task => this.executeTask(task)));
        return this.aggregate(results);
    }
    splitTask(prompt, count) {
        const words = prompt.split(/\s+/);
        const chunkSize = Math.ceil(words.length / count);
        const chunks = [];
        for (let i = 0; i < count; i++) {
            const chunk = words.slice(i * chunkSize, (i + 1) * chunkSize).join(' ');
            if (chunk) {
                chunks.push({
                    id: `task-${i}`,
                    description: chunk,
                    priority: i
                });
            }
        }
        return chunks;
    }
    async executeTask(task) {
        try {
            const thinkResult = await this.engine.think(task.description);
            return {
                taskId: task.id,
                output: thinkResult.finalOutput,
                success: true
            };
        }
        catch (error) {
            return {
                taskId: task.id,
                output: String(error),
                success: false
            };
        }
    }
    aggregate(results) {
        return results.sort((a, b) => a.taskId.localeCompare(b.taskId));
    }
}
