// tools/generate-sub-agent.ts — Create specialized sub-agents
// Uses agent-generator engine: generateSubAgent()
import { t, ti } from '../i18n/index.js';
import { knowledgeStore } from '../storage/index.js';
import { generateSubAgent } from '../engine/agent-generator.js';
export async function handleGenerateSubAgent(args) {
    const { projectId, framework, agentName, role, capabilities, tools = [], systemPrompt } = args;
    const knowledge = await knowledgeStore.getKnowledge(projectId);
    if (!knowledge) {
        return {
            content: [
                {
                    type: 'text',
                    text: ti('errors.projectNotFound', { projectId }),
                },
            ],
            isError: true,
        };
    }
    const result = await generateSubAgent(framework, agentName, role, capabilities, knowledge, tools, systemPrompt);
    // Format output
    const lines = [
        `## ${t('tools.generate_sub_agent.description')}`,
        '',
        `**Framework:** ${result.framework}`,
        `**Agent name:** ${result.agentDefinition.name}`,
        `**Role:** ${result.agentDefinition.role}`,
        `**Model:** ${result.agentDefinition.model}`,
        `**Max turns:** ${result.agentDefinition.maxTurns ?? 'default'}`,
        '',
    ];
    // Tools
    if (result.agentDefinition.tools.length > 0) {
        lines.push('### Available Tools');
        lines.push('');
        for (const tool of result.agentDefinition.tools) {
            lines.push(`- \`${tool}\``);
        }
        lines.push('');
    }
    // Handoff conditions
    if (result.agentDefinition.handoffConditions &&
        result.agentDefinition.handoffConditions.length > 0) {
        lines.push('### Handoff Conditions');
        lines.push('');
        for (const condition of result.agentDefinition.handoffConditions) {
            lines.push(`- ${condition}`);
        }
        lines.push('');
    }
    // System prompt
    lines.push('### System Prompt');
    lines.push('');
    lines.push('```');
    lines.push(result.agentDefinition.systemPrompt);
    lines.push('```');
    lines.push('');
    // Generated files
    for (const file of result.files) {
        lines.push(`### File: \`${file.path}\``);
        lines.push('');
        const lang = file.path.endsWith('.py')
            ? 'python'
            : file.path.endsWith('.ts')
                ? 'typescript'
                : file.path.endsWith('.json')
                    ? 'json'
                    : 'text';
        lines.push(`\`\`\`${lang}`);
        lines.push(file.content);
        lines.push('```');
        lines.push('');
    }
    // Install instructions
    lines.push('### Installation');
    lines.push('');
    lines.push(result.installInstructions);
    return {
        content: [{ type: 'text', text: lines.join('\n') }],
    };
}
//# sourceMappingURL=generate-sub-agent.js.map