"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SystemModule = void 0;
const BaseChatModule_1 = require("./BaseChatModule");
const utils_1 = require("../../utils");
const types_1 = require("../../types");
class SystemModule extends BaseChatModule_1.BaseChatModule {
    name = "system";
    description = "System commands for model, provider, debug, and clear";
    getCommands() {
        return [
            {
                name: "model",
                description: "Select AI model",
                handler: this.handleModelCommand.bind(this),
            },
            {
                name: "provider",
                description: "Select AI provider",
                handler: this.handleProviderCommand.bind(this),
            },
            {
                name: "debug",
                description: "Toggle debug mode",
                handler: this.handleDebugCommand.bind(this),
            },
            {
                name: "clear",
                description: "Clear chat history - AI will not remember previous messages",
                handler: this.handleClearCommand.bind(this),
            },
        ];
    }
    getModes() {
        return [];
    }
    async handleModelCommand(args) {
        const context = this.chatService?.getContext();
        const agent = context?.selectedAgent;
        const Clients = agent.clientService;
        const currentProvider = context?.currentProvider || "openai";
        const currentModel = context?.currentModel || "gpt-5.4-nano";
        const models = Clients.getRegisteredModels(currentProvider);
        console.log(models);
        const selectedModel = await (0, utils_1.ask)(`\n\nCurrent Provider: ${currentProvider}\nCurrent Model: ${currentModel}\n\nWhich model would you like to use: `, models);
        if (!selectedModel) {
            return;
        }
        this.chatService?.setContext({
            currentModel: selectedModel,
            currentProvider,
        });
        console.log(`Model set to: ${selectedModel} for provider: ${currentProvider}`);
        if (context?.selectedAgent) {
            console.log(`Updating active agent ${context.currentAgent} model to: ${selectedModel}`);
            context?.selectedAgent?.updatePreferences({
                model: selectedModel,
                provider: currentProvider,
            });
        }
    }
    async handleProviderCommand(args) {
        const context = this.chatService?.getContext();
        const agent = context?.selectedAgent;
        const Clients = agent.clientService;
        const currentProvider = context?.currentProvider || "openai";
        const currentModel = context?.currentModel || "gpt-5.4-nano";
        const providers = Object.keys(Clients.clients);
        console.log(providers);
        const selectedProvider = await (0, utils_1.ask)(`\n\nCurrent Provider: ${currentProvider}\nCurrent Model: ${currentModel}\n\nWhich provider would you like to use: `, providers);
        if (!selectedProvider) {
            return;
        }
        const ChatModelDefaults = {
            openai: types_1.Models.openai.GPT_53_Codex,
            anthropic: types_1.Models.anthropic.Sonnet4_6,
            google: types_1.Models.google.Gemini_3_Flash_Preview,
            xai: types_1.Models.xai.Grok4_1_Fast_NonReasoning,
            knowhow: "anthropic/" + types_1.Models.anthropic.Sonnet4_6,
        };
        const newModel = ChatModelDefaults[selectedProvider] ||
            (await Clients.getRegisteredModels(selectedProvider))[0];
        this.chatService?.setContext({
            currentProvider: selectedProvider,
            currentModel: newModel,
        });
        console.log(`Provider set to: ${selectedProvider}, Model set to: ${newModel}`);
        if (context?.selectedAgent) {
            console.log(`Updating active agent ${context.currentAgent} provider to: ${selectedProvider} and model to: ${newModel}`);
            context?.selectedAgent?.updatePreferences({
                model: newModel,
                provider: selectedProvider,
            });
        }
    }
    async handleDebugCommand(args) {
        const context = this.chatService?.getContext();
        const newDebugMode = !context?.debugMode;
        this.chatService?.setContext({ debugMode: newDebugMode });
        console.log(`Debug mode: ${newDebugMode ? "enabled" : "disabled"}`);
    }
    async handleClearCommand(args) {
        this.chatService?.clearHistory();
        console.log("Chat history cleared.");
    }
    async handleInput(input, context) {
        return false;
    }
    async cleanup() {
    }
}
exports.SystemModule = SystemModule;
//# sourceMappingURL=SystemModule.js.map