// Planu — Agent Generator: Framework-Specific File Generators
// Generates code files for each supported multi-agent framework.
import { camelCase, pascalCase, escapeTemplateLiteral, buildInstallInstructions, } from './framework-files-helpers.js';
export { buildInstallInstructions };
// === Framework File Generators ===
function generateClaudeAgentSdkFiles(agent, _knowledge) {
    const slug = agent.name.toLowerCase().replace(/\s+/g, '-');
    const content = `// ${agent.name} — Generated by Planu SDD MCP Server
// Framework: Anthropic Agent SDK
// Docs: https://docs.anthropic.com/en/docs/agents

import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic();

export const ${camelCase(agent.name)}Agent = {
  name: "${agent.name}",
  role: "${agent.role}",
  model: "${agent.model}",
  maxTurns: ${agent.maxTurns ?? 10},

  systemPrompt: \`${escapeTemplateLiteral(agent.systemPrompt)}\`,

  tools: ${JSON.stringify(agent.tools, null, 4)},

  ${agent.handoffConditions ? `handoffConditions: ${JSON.stringify(agent.handoffConditions, null, 4)},` : ''}

  async run(input: string) {
    const response = await client.messages.create({
      model: this.model,
      max_tokens: 4096,
      system: this.systemPrompt,
      messages: [{ role: "user", content: input }],
    });
    return response;
  },
};
`;
    return [
        {
            path: `agents/${slug}.ts`,
            content,
            format: 'markdown', // TypeScript content, markdown format for SkillFile
        },
    ];
}
function generateCrewAiFiles(agent, knowledge) {
    const slug = agent.name.toLowerCase().replace(/\s+/g, '_');
    const content = `# ${agent.name} — Generated by Planu SDD MCP Server
# Framework: CrewAI
# Docs: https://docs.crewai.com

from crewai import Agent, Task

${slug}_agent = Agent(
    role="${agent.role}",
    goal="${agent.role} for ${knowledge.language}/${knowledge.framework ?? 'native'} project",
    backstory="""${agent.systemPrompt.replace(/"/g, '\\"').substring(0, 500)}""",
    verbose=True,
    allow_delegation=${agent.handoffConditions ? 'True' : 'False'},
    tools=[${agent.tools.map((t) => `"${t}"`).join(', ')}],
    max_iter=${agent.maxTurns ?? 10},
)

# Example task
${slug}_task = Task(
    description="Execute the assigned ${agent.role} task.",
    expected_output="Structured result of the ${agent.role} analysis.",
    agent=${slug}_agent,
)
`;
    return [
        {
            path: `agents/${slug}_agent.py`,
            content,
            format: 'markdown',
        },
    ];
}
function generateLangGraphFiles(agent, _knowledge) {
    const slug = agent.name.toLowerCase().replace(/\s+/g, '_');
    const content = `# ${agent.name} — Generated by Planu SDD MCP Server
# Framework: LangGraph
# Docs: https://langchain-ai.github.io/langgraph

from langgraph.graph import StateGraph, END
from langchain_anthropic import ChatAnthropic
from typing import TypedDict, Annotated

class ${pascalCase(agent.name)}State(TypedDict):
    messages: list
    context: dict
    result: str | None

llm = ChatAnthropic(model="${agent.model}")

def ${slug}_node(state: ${pascalCase(agent.name)}State) -> ${pascalCase(agent.name)}State:
    """${agent.role} node."""
    system_prompt = """${agent.systemPrompt.replace(/"/g, '\\"').substring(0, 500)}"""

    response = llm.invoke([
        {"role": "system", "content": system_prompt},
        *state["messages"],
    ])

    return {
        **state,
        "result": response.content,
        "messages": [*state["messages"], {"role": "assistant", "content": response.content}],
    }

# Build the graph
graph = StateGraph(${pascalCase(agent.name)}State)
graph.add_node("${slug}", ${slug}_node)
graph.set_entry_point("${slug}")
graph.add_edge("${slug}", END)

${slug}_graph = graph.compile()
`;
    return [
        {
            path: `agents/${slug}_graph.py`,
            content,
            format: 'markdown',
        },
    ];
}
function generateAutoGenFiles(agent, _knowledge) {
    const slug = agent.name.toLowerCase().replace(/\s+/g, '_');
    const content = `# ${agent.name} — Generated by Planu SDD MCP Server
# Framework: AutoGen (Microsoft)
# Docs: https://microsoft.github.io/autogen

from autogen import AssistantAgent, UserProxyAgent

${slug}_agent = AssistantAgent(
    name="${agent.name}",
    system_message="""${agent.systemPrompt.replace(/"/g, '\\"').substring(0, 500)}""",
    llm_config={
        "model": "${agent.model}",
        "temperature": 0,
    },
    max_consecutive_auto_reply=${agent.maxTurns ?? 10},
)

# User proxy for human-in-the-loop
user_proxy = UserProxyAgent(
    name="user",
    human_input_mode="TERMINATE",
    max_consecutive_auto_reply=0,
)

# Example usage:
# user_proxy.initiate_chat(${slug}_agent, message="Analyze the codebase")
`;
    return [
        {
            path: `agents/${slug}_autogen.py`,
            content,
            format: 'markdown',
        },
    ];
}
function generateMastraFiles(agent, _knowledge) {
    const slug = agent.name.toLowerCase().replace(/\s+/g, '-');
    const content = `// ${agent.name} — Generated by Planu SDD MCP Server
// Framework: Mastra
// Docs: https://mastra.ai/docs

import { Agent } from "@mastra/core";

export const ${camelCase(agent.name)}Agent = new Agent({
  name: "${agent.name}",
  instructions: \`${escapeTemplateLiteral(agent.systemPrompt)}\`,
  model: {
    provider: "ANTHROPIC",
    name: "${agent.model}",
  },
  tools: {
    ${agent.tools.map((t) => `// ${t}: imported from your tools registry`).join('\n    ')}
  },
});
`;
    return [
        {
            path: `agents/${slug}.ts`,
            content,
            format: 'markdown',
        },
    ];
}
function generateVercelAiSdkFiles(agent, _knowledge) {
    const slug = agent.name.toLowerCase().replace(/\s+/g, '-');
    const content = `// ${agent.name} — Generated by Planu SDD MCP Server
// Framework: Vercel AI SDK
// Docs: https://sdk.vercel.ai/docs

import { generateText } from "ai";
import { anthropic } from "@ai-sdk/anthropic";

export async function run${pascalCase(agent.name)}(input: string) {
  const result = await generateText({
    model: anthropic("${agent.model}"),
    system: \`${escapeTemplateLiteral(agent.systemPrompt)}\`,
    prompt: input,
    maxSteps: ${agent.maxTurns ?? 10},
  });

  return result.text;
}
`;
    return [
        {
            path: `agents/${slug}.ts`,
            content,
            format: 'markdown',
        },
    ];
}
function generateGenericFiles(agent, _knowledge) {
    const content = JSON.stringify({
        name: agent.name,
        role: agent.role,
        model: agent.model,
        systemPrompt: agent.systemPrompt,
        tools: agent.tools,
        maxTurns: agent.maxTurns,
        handoffConditions: agent.handoffConditions,
    }, null, 2);
    return [
        {
            path: `agents/${agent.name.toLowerCase().replace(/\s+/g, '-')}.json`,
            content,
            format: 'json',
        },
    ];
}
// === Public Entry Point ===
export function generateFrameworkFiles(framework, agent, knowledge, _config) {
    switch (framework) {
        case 'claude-agent-sdk':
            return generateClaudeAgentSdkFiles(agent, knowledge);
        case 'crewai':
            return generateCrewAiFiles(agent, knowledge);
        case 'langgraph':
            return generateLangGraphFiles(agent, knowledge);
        case 'autogen':
            return generateAutoGenFiles(agent, knowledge);
        case 'mastra':
            return generateMastraFiles(agent, knowledge);
        case 'vercel-ai-sdk':
            return generateVercelAiSdkFiles(agent, knowledge);
        case 'custom':
            return generateGenericFiles(agent, knowledge);
        default:
            return generateGenericFiles(agent, knowledge);
    }
}
//# sourceMappingURL=framework-files.js.map