"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SDKToolsRegistry = void 0;
const ToolFactory_1 = require("../goatTools/ToolFactory");
const ToolNames_1 = require("../goatTools/ToolNames");
const SDKTool_1 = require("./SDKTool");
const INTERACTIVE_TOOL_NAMES = new Set([
    ToolNames_1.ToolNames.ChangeChainTool,
    ToolNames_1.ToolNames.PerformZapTool,
]);
const TOOL_NAME_VALUES = new Set(Object.values(ToolNames_1.ToolNames));
class SDKToolsRegistry {
    constructor(toolFactory = new ToolFactory_1.ToolFactory()) {
        this.tools = new Map();
        const toolNames = toolFactory.getToolNames();
        for (const toolName of toolNames) {
            const rawTool = toolFactory.getTool(toolName);
            const isInteractive = INTERACTIVE_TOOL_NAMES.has(toolName);
            this.tools.set(toolName, new SDKTool_1.SDKTool(toolName, rawTool, isInteractive));
        }
    }
    listTools() {
        return Array.from(this.tools.values())
            .map((tool) => ({
            name: tool.name,
            description: tool.description,
            isInteractive: tool.isInteractive,
        }))
            .sort((a, b) => a.name.localeCompare(b.name));
    }
    getTool(name) {
        const tool = this.tools.get(name);
        if (!tool) {
            throw new Error(`Tool "${name}" is not registered.`);
        }
        return tool;
    }
    getToolByName(name) {
        if (!this.isToolName(name)) {
            throw new Error(`Unknown tool "${name}".`);
        }
        return this.getTool(name);
    }
    async executeTool(name, input) {
        const tool = this.getTool(name);
        return tool.execute(input);
    }
    async executeToolByName(name, input) {
        const tool = this.getToolByName(name);
        return tool.execute(input);
    }
    isToolName(value) {
        return TOOL_NAME_VALUES.has(value);
    }
}
exports.SDKToolsRegistry = SDKToolsRegistry;
