/**
 * Infrastructure Facade
 *
 * Encapsulates infrastructure services management.
 * This facade handles:
 * - MCP (Model Context Protocol) servers
 * - Sandbox management for command execution
 * - Lifecycle hooks
 * - Prompt cache management
 * - Plugin marketplace
 */
import { loadMCPConfig } from '../../mcp/config.js';
import { initializeMCPServers } from '../../codebuddy/tools.js';
import { getErrorMessage } from '../../errors/index.js';
import { logger } from '../../utils/logger.js';
/**
 * Facade for infrastructure services in agents.
 *
 * Responsibilities:
 * - Managing MCP server connections and tools
 * - Validating commands through sandbox
 * - Managing lifecycle hooks
 * - Prompt caching operations
 * - Plugin marketplace access
 */
export class InfrastructureFacade {
    mcpClient;
    sandboxManager;
    hooksManager;
    promptCacheManager;
    marketplace;
    constructor(deps) {
        this.mcpClient = deps.mcpClient;
        this.sandboxManager = deps.sandboxManager;
        this.hooksManager = deps.hooksManager;
        this.promptCacheManager = deps.promptCacheManager;
        this.marketplace = deps.marketplace;
    }
    // ============================================================================
    // MCP Management
    // ============================================================================
    /**
     * Connect to all configured MCP servers
     */
    async connectMCPServers() {
        await this.mcpClient.connectAll();
    }
    /**
     * Get MCP connection status as formatted string
     */
    getMCPStatus() {
        return this.mcpClient.formatStatus();
    }
    /**
     * Get all tools from connected MCP servers
     */
    async getMCPTools() {
        return this.mcpClient.getAllTools();
    }
    /**
     * Get the MCP client instance (for advanced operations)
     */
    getMCPClient() {
        return this.mcpClient;
    }
    /**
     * Initialize MCP servers asynchronously
     * This is a fire-and-forget operation
     */
    initializeMCP() {
        (async () => {
            try {
                const config = loadMCPConfig();
                if (config.servers.length > 0) {
                    await initializeMCPServers();
                }
            }
            catch (error) {
                logger.warn('MCP initialization failed', { error: getErrorMessage(error) });
            }
        })().catch((error) => {
            logger.warn('Uncaught error in MCP initialization', { error: getErrorMessage(error) });
        });
    }
    // ============================================================================
    // Sandbox Management
    // ============================================================================
    /**
     * Get sandbox status as formatted string
     */
    getSandboxStatus() {
        return this.sandboxManager.formatStatus();
    }
    /**
     * Validate a command against sandbox rules
     */
    validateCommand(command) {
        return this.sandboxManager.validateCommand(command);
    }
    /**
     * Get the sandbox manager instance (for advanced operations)
     */
    getSandboxManager() {
        return this.sandboxManager;
    }
    // ============================================================================
    // Lifecycle Hooks
    // ============================================================================
    /**
     * Get the hooks manager instance
     */
    getHooksManager() {
        return this.hooksManager;
    }
    /**
     * Get hooks status as formatted string
     */
    getHooksStatus() {
        return this.hooksManager.formatStatus();
    }
    // ============================================================================
    // Prompt Cache
    // ============================================================================
    /**
     * Get the prompt cache manager instance
     */
    getPromptCacheManager() {
        return this.promptCacheManager;
    }
    /**
     * Get prompt cache statistics
     */
    getPromptCacheStats() {
        return this.promptCacheManager.getStats();
    }
    /**
     * Format prompt cache statistics as string
     */
    formatPromptCacheStats() {
        return this.promptCacheManager.formatStats();
    }
    // ============================================================================
    // Plugin Marketplace
    // ============================================================================
    /**
     * Get the plugin marketplace instance
     */
    getMarketplace() {
        return this.marketplace;
    }
}
//# sourceMappingURL=infrastructure-facade.js.map