/** * Provider Manager * * Manages the registry of LLM providers, handling provider creation, * retrieval, and configuration updates. Provides a factory method for * creating provider instances based on their type. */ import { type Provider, type ProviderConfig, type ProviderType } from './types.js'; /** * Factory function type for creating provider instances. */ export type ProviderFactory = (config: ProviderConfig) => Provider; /** * Manager for LLM provider instances. * * Handles: * - Provider registration and retrieval * - Provider instance creation via factory methods * - Configuration updates with instance recreation * - Lazy instantiation of providers * * @example * ```ts * const manager = new ProviderManager(); * * // Update configurations (creates instances lazily) * manager.updateConfig({ * anthropic: { api_key: 'sk-...' }, * openai: { api_key: 'sk-...' } * }); * * // Get a provider instance * const provider = manager.get('anthropic'); * ``` */ export declare class ProviderManager { /** Registry of provider factories and instances by name */ private readonly providers; /** Registry of active provider instances */ private readonly instances; /** * Create a new ProviderManager with default factories registered. */ constructor(); /** * Register a provider factory for a given provider type. * The factory will be used to create provider instances when needed. * * @param name - Provider name (e.g., 'anthropic', 'openai') * @param factory - Factory function that creates provider instances */ registerFactory(name: string, factory: ProviderFactory): void; /** * Register a pre-created provider instance directly. * Useful for testing or custom provider implementations. * * @param name - Provider name * @param provider - Provider instance */ register(name: string, provider: Provider): void; /** * Get a provider instance by name. * Creates the instance lazily if it hasn't been created yet. * * @param name - Provider name * @returns The provider instance * @throws ConfigurationError if the provider is not registered or not configured */ get(name: string): Provider; /** * Check if a provider is registered (has a factory). * * @param name - Provider name * @returns True if the provider is registered */ has(name: string): boolean; /** * Check if a provider is configured and ready to use. * * @param name - Provider name * @returns True if the provider is configured */ isConfigured(name: string): boolean; /** * Update provider configurations. * This will invalidate existing instances so they are recreated with new configs. * * @param configs - Map of provider name to configuration */ updateConfig(configs: Record): void; /** * Get the configuration for a provider. * * @param name - Provider name * @returns The provider configuration, or undefined if not configured */ getConfig(name: string): ProviderConfig | undefined; /** * List all registered provider names. * * @returns Array of provider names */ listProviders(): string[]; /** * List all configured provider names (ready to use). * * @returns Array of configured provider names */ listConfigured(): string[]; /** * Remove a provider from the registry. * * @param name - Provider name to remove */ remove(name: string): void; /** * Clear all providers from the registry. */ clear(): void; /** * Run health checks on all configured providers. * * @returns Map of provider name to health check result (true = healthy, Error = failed) */ healthCheckAll(): Promise>; } /** * Create a provider instance based on provider type. * This is a factory function that maps provider types to their implementations. * * @param type - Provider type * @param config - Provider configuration * @param manager - Provider manager with registered factories * @returns Provider instance * @throws ConfigurationError if the provider type is not supported */ export declare function createProvider(type: ProviderType, config: ProviderConfig, manager: ProviderManager): Provider; /** * Create a ProviderManager with default provider factories registered. * * @returns Configured ProviderManager */ export declare function createProviderManager(): ProviderManager; //# sourceMappingURL=manager.d.ts.map