/**
 * Plugin Manager for dot-ai Plugin System
 *
 * Discovers plugins at startup and manages tool routing.
 * Provides discovered tools to the MCP server for registration.
 *
 * PRD #343: kubectl Plugin Migration
 *
 * Background Retry: If plugins aren't ready at startup, discovery continues
 * in the background every 30 seconds. MCP server starts immediately and
 * remains observable via the version tool.
 */
import { PluginConfig, DiscoveredPlugin, InvokeResponse } from './plugin-types';
import { Logger } from './error-handling';
import { AITool, ToolExecutor } from './ai-provider.interface';
/**
 * Callback invoked when a plugin is discovered in the background
 */
export type PluginDiscoveredCallback = (plugin: DiscoveredPlugin) => void;
/**
 * Error thrown when plugin discovery fails
 */
export declare class PluginDiscoveryError extends Error {
    readonly failedPlugins: Array<{
        name: string;
        error: string;
    }>;
    constructor(message: string, failedPlugins: Array<{
        name: string;
        error: string;
    }>);
}
/**
 * Manages plugin discovery, registration, and tool routing
 */
export declare class PluginManager {
    private readonly logger;
    private readonly plugins;
    private readonly discoveredPlugins;
    private readonly toolToPlugin;
    /** Plugins pending background discovery */
    private pendingPlugins;
    /** Background retry timer */
    private backgroundRetryTimer;
    /** When background retry started */
    private backgroundRetryStartTime;
    /** Callback for background discovery */
    private onPluginDiscovered;
    constructor(logger: Logger);
    /**
     * Parse plugin configuration from file
     *
     * Reads from /etc/dot-ai/plugins.json (mounted from ConfigMap in K8s).
     * Returns empty array if file doesn't exist (plugins only work in-cluster).
     * Throws on invalid JSON or malformed plugin configuration.
     */
    static parsePluginConfig(): PluginConfig[];
    /**
     * Set callback for when plugins are discovered in the background
     *
     * This allows the MCP server to register new tools when plugins
     * become available after initial startup.
     */
    setOnPluginDiscovered(callback: PluginDiscoveredCallback): void;
    /**
     * Discover all configured plugins
     *
     * Does a quick initial discovery attempt (2 retries, 1s apart).
     * Plugins that fail are queued for background retry.
     * Required plugins that fail will throw PluginDiscoveryError.
     *
     * Call startBackgroundDiscovery() after this to enable background retries.
     */
    discoverPlugins(configs: PluginConfig[]): Promise<void>;
    /**
     * Start background discovery for plugins that failed initial discovery
     *
     * Retries every 30 seconds for up to 10 minutes.
     * When a plugin is discovered, calls the onPluginDiscovered callback.
     */
    startBackgroundDiscovery(): void;
    /**
     * Stop background discovery
     */
    stopBackgroundDiscovery(): void;
    /**
     * Get pending plugins that are still awaiting discovery
     */
    getPendingPlugins(): string[];
    /**
     * Check if background discovery is active
     */
    isBackgroundDiscoveryActive(): boolean;
    /**
     * Schedule the next background retry attempt
     */
    private scheduleBackgroundRetry;
    /**
     * Run a background retry attempt for all pending plugins
     */
    private runBackgroundRetry;
    /**
     * Quick discovery attempt for a single plugin
     *
     * Does 2 retries with 1 second delay. Returns true if discovered,
     * false if should be queued for background retry.
     */
    private discoverPluginQuick;
    /**
     * Get all discovered tools as AITool format for registration
     *
     * Only returns tools where the tool-to-plugin mapping is canonical.
     * This filters out duplicate tools when multiple plugins define the same tool name.
     */
    getDiscoveredTools(): AITool[];
    /**
     * Get tools from a specific plugin
     */
    getPluginTools(pluginName: string): AITool[];
    /**
     * Check if a tool is provided by a plugin
     */
    isPluginTool(toolName: string): boolean;
    /**
     * Get the plugin name for a tool
     */
    getToolPlugin(toolName: string): string | undefined;
    /**
     * Invoke a tool on a specific plugin (explicit routing)
     *
     * PRD #359: Unified plugin invocation with explicit plugin specification.
     * Use this when you know which plugin provides the tool, avoiding
     * ambiguity when multiple plugins might have tools with the same name.
     */
    invokeToolOnPlugin(pluginName: string, toolName: string, args: Record<string, unknown>, state?: Record<string, unknown>, sessionId?: string): Promise<InvokeResponse>;
    /**
     * Create a ToolExecutor that routes plugin tools to plugins
     *
     * Returns a function compatible with toolLoop's toolExecutor parameter.
     * Plugin tools are routed to their plugins via HTTP; non-plugin tools
     * are routed to the optional fallback executor.
     *
     * @param fallbackExecutor Optional executor for non-plugin tools
     * @returns ToolExecutor function for use in agentic tool loops
     */
    createToolExecutor(fallbackExecutor?: ToolExecutor): ToolExecutor;
    /**
     * Get list of discovered plugin names
     */
    getDiscoveredPluginNames(): string[];
    /**
     * Get discovered plugin metadata
     */
    getDiscoveredPlugin(name: string): DiscoveredPlugin | undefined;
    /**
     * Get all discovered plugins
     */
    getAllDiscoveredPlugins(): DiscoveredPlugin[];
    /**
     * Get plugin statistics
     */
    getStats(): {
        pluginCount: number;
        toolCount: number;
        plugins: Array<{
            name: string;
            version: string;
            toolCount: number;
        }>;
        pendingDiscovery: string[];
        backgroundDiscoveryActive: boolean;
    };
    /**
     * Convert PluginToolDefinition to AITool format
     */
    private convertToAITool;
}
//# sourceMappingURL=plugin-manager.d.ts.map