"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ALL_TOOLS = void 0;
exports.executeTool = executeTool;
const vibn_tools_1 = require("./vibn-tools");
exports.ALL_TOOLS = vibn_tools_1.VIBN_TOOL_DEFINITIONS;
async function executeTool(name, args, ctx) {
    // Some tools might just be executed locally by the Runner in the future, 
    // but right now we forward all non-github/http tools to the frontend MCP.
    // Convert underscore to dot format as expected by MCP
    const action = name.replace(/_/g, ".");
    try {
        const response = await fetch(`${ctx.vibnApiUrl}/api/mcp`, {
            method: "POST",
            headers: {
                "Content-Type": "application/json",
                "Authorization": `Bearer ${ctx.mcpToken}`,
                ...(ctx.projectId ? { "X-Vibn-Project-Id": ctx.projectId } : {})
            },
            body: JSON.stringify({ action, params: args }),
        });
        const data = await response.json();
        if (!response.ok) {
            return { error: data.error || `HTTP ${response.status}: ${response.statusText}` };
        }
        return data.result || data;
    }
    catch (e) {
        return { error: `Failed to execute tool ${name} via MCP: ${e instanceof Error ? e.message : String(e)}` };
    }
}
