import { z } from 'zod';
import { handleOrchestrateRuntime } from './orchestrate-runtime.js';
import { handleAgentSwarmStatus } from './agent-swarm-status.js';
import { safeLicensed } from './safe-handler.js';
const taskDescriptionSchema = z.object({
    id: z.string().describe('Unique task identifier'),
    description: z.string().describe('Natural-language task description'),
    requirements: z.array(z.string()).describe('Capabilities required'),
    files: z.array(z.string()).describe('File paths this task works with'),
    dependencies: z.array(z.string()).describe('Task IDs that must complete first'),
    priority: z.number().describe('Priority (higher = more important)'),
    critical: z.boolean().describe('If true, orchestration fails if this task fails'),
});
const agentConfigSchema = z.object({
    id: z.string().describe('Unique agent identifier'),
    command: z.string().describe('CLI command to spawn (e.g. "claude", "python")'),
    args: z.array(z.string()).describe('Command arguments'),
    capabilities: z.array(z.string()).describe('Agent capabilities'),
    modelTier: z
        .enum(['haiku', 'sonnet', 'opus'])
        .optional()
        .describe('Model tier: haiku | sonnet | opus'),
    workDir: z.string().optional().describe('Working directory for the agent'),
});
export function registerOrchestratorTools(server) {
    server.registerTool('orchestrate_runtime', {
        description: 'Launch and coordinate parallel agents with configurable topologies (mesh, hierarchical, pipeline, star). Distributes tasks, manages file ownership, collects results, and resolves conflicts. Supports dryRun mode for planning without execution.',
        inputSchema: {
            topology: z
                .enum(['mesh', 'hierarchical', 'pipeline', 'star'])
                .describe('Topology: mesh (parallel) | hierarchical (coordinator+workers) | pipeline (sequential) | star (hub-spoke)'),
            tasks: z.array(taskDescriptionSchema).describe('Tasks to distribute'),
            agents: z
                .array(agentConfigSchema)
                .optional()
                .describe('Agent configs (auto-generated if omitted)'),
            maxRetries: z.number().optional().describe('Max retries per agent (default: 2)'),
            timeoutMs: z.number().optional().describe('Timeout per agent in ms (default: 600000)'),
            failFast: z.boolean().optional().describe('Stop on first failure (default: false)'),
            spawnMethod: z
                .enum(['cli-subprocess', 'mcp-client', 'http-endpoint'])
                .optional()
                .describe('Spawn method: cli-subprocess | mcp-client | http-endpoint'),
            conflictStrategy: z
                .enum(['last-wins', 'first-wins', 'merge-auto', 'flag-for-review'])
                .optional()
                .describe('Conflict strategy: last-wins | first-wins | merge-auto | flag-for-review'),
            dryRun: z.boolean().optional().describe('Plan without executing (default: false)'),
            templateId: z.string().optional().describe('Use a pre-defined template'),
        },
        annotations: { readOnlyHint: false },
    }, safeLicensed('orchestrate_runtime', async (args) => handleOrchestrateRuntime(args)));
    server.registerTool('agent_swarm_status', {
        description: 'Get status of orchestration sessions. Returns agent progress, task status, metrics, and cost. Without sessionId, lists all sessions.',
        inputSchema: {
            sessionId: z.string().optional().describe('Specific session ID to query'),
            status: z
                .enum(['running', 'completed', 'failed'])
                .optional()
                .describe('Filter by status: running | completed | failed'),
            agentId: z.string().optional().describe('Filter by specific agent ID'),
        },
        annotations: { readOnlyHint: true },
    }, safeLicensed('agent_swarm_status', (args) => {
        return Promise.resolve(handleAgentSwarmStatus(args));
    }));
}
//# sourceMappingURL=register-orchestrator-tools.js.map