"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.setupServices = setupServices;
const list_1 = require("../agents/tools/list");
const allTools = __importStar(require("../agents/tools"));
const services_1 = require("../services");
const agents_1 = require("../agents");
const modules_1 = require("../services/modules");
async function setupServices() {
    const { Agents, Mcp, Clients, Tools: AllTools, Embeddings, Plugins, Events, MediaProcessor, } = (0, services_1.services)();
    const Tools = new services_1.LazyToolsService();
    Tools.setContext({
        ...AllTools.getContext(),
    });
    const agentContext = {
        ...(0, services_1.services)(),
        Tools,
    };
    const { Researcher, Developer, Patcher, Setup } = (0, agents_1.agents)({
        ...agentContext,
    });
    Agents.registerAgent(Researcher);
    Agents.registerAgent(Patcher);
    Agents.registerAgent(Developer);
    Agents.registerAgent(Setup);
    Agents.loadAgentsFromConfig(agentContext);
    Tools.defineTools(list_1.includedTools, allTools);
    Tools.addContext("Mcp", Mcp);
    Agents.setAgentContext(agentContext);
    console.log("🔌 Connecting to MCP...");
    try {
        await Mcp.connectToConfigured(Tools);
    }
    catch (mcpError) {
        const msg = mcpError instanceof Error ? mcpError.message : String(mcpError);
        console.warn(`⚠ Some MCP servers failed to connect (continuing without them): ${msg}`);
    }
    console.log("Connecting to clients...");
    await Clients.registerConfiguredModels();
    console.log("✓ Services are set up and ready to go!");
    console.log("📦 Loading modules from config...");
    const modulesService = new modules_1.ModulesService();
    await modulesService.loadModulesFromConfig({
        Agents,
        Embeddings,
        Plugins,
        Clients,
        Tools,
        MediaProcessor,
        Events
    });
    return { Tools, Clients };
}
//# sourceMappingURL=services.js.map