"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AskModule = void 0;
const BaseChatModule_1 = require("./BaseChatModule");
const ai_1 = require("../../ai");
const index_1 = require("../../services/index");
const index_2 = require("../../utils/index");
class AskModule extends BaseChatModule_1.BaseChatModule {
    name = "ask";
    description = "Basic AI question/answer functionality";
    getCommands() {
        return [];
    }
    getModes() {
        return [
            {
                name: "chat",
                description: "Basic AI chat mode",
                active: true,
            },
        ];
    }
    async handleInput(input, context) {
        if (context.mode === "agent") {
            return false;
        }
        return await this.processAIQuery(input, context);
    }
    async processAIQuery(input, context) {
        try {
            const { Clients } = (0, index_1.services)();
            const provider = context.currentProvider;
            const model = context.currentModel || ai_1.Models.openai.GPT_4o;
            const formattedPrompt = await this.chatService.formatChatInput(input, context.plugins || [], context.chatHistory || []);
            const response = await Clients.createCompletion(provider, {
                messages: [
                    {
                        role: "system",
                        content: "Helpful Codebase assistant. Answer users questions using the embedding data that is provided with the user's question. You have limited access to the codebase based off of how similar the codebase is to the user's question. You may reference file paths by using the IDs present in the embedding data, but be sure to remove the chunk from the end of the filepaths.",
                    },
                    { role: "user", content: formattedPrompt },
                ],
                model,
            });
            const result = response.choices[0].message.content || "No response from the AI";
            const interaction = {
                input,
                output: result,
            };
            context.chatHistory?.push(interaction);
            console.log(index_2.Marked.parse(result));
            return true;
        }
        catch (error) {
            console.error("Error getting AI response:", error);
            console.log("Failed to get AI response. Please try again.");
            return false;
        }
    }
}
exports.AskModule = AskModule;
//# sourceMappingURL=AskModule.js.map