import { OpenAIProvider } from './openai-provider';
import { AnthropicProvider } from './anthropic-provider';
export class AIProviderManager {
    providers = new Map();
    defaultProvider;
    constructor() {
        this.registerProvider(new OpenAIProvider());
        this.registerProvider(new AnthropicProvider());
    }
    registerProvider(provider) {
        this.providers.set(provider.type, provider);
        console.log(`[AIProviders] Registered provider: ${provider.name} (${provider.type})`);
    }
    getProvider(type) {
        return this.providers.get(type);
    }
    getProviders() {
        return Array.from(this.providers.values());
    }
    async getConfiguredProviders() {
        const providers = this.getProviders();
        const configured = [];
        for (const provider of providers) {
            if (await provider.isConfigured()) {
                configured.push(provider);
            }
        }
        return configured;
    }
    setDefaultProvider(type) {
        if (!this.providers.has(type)) {
            throw new Error(`Provider not found: ${type}`);
        }
        this.defaultProvider = type;
    }
    getDefaultProvider() {
        if (this.defaultProvider) {
            return this.providers.get(this.defaultProvider);
        }
        for (const provider of this.providers.values()) {
            return provider;
        }
        return undefined;
    }
    async selectProviderForModel(model) {
        if (model.startsWith('gpt-')) {
            const provider = this.providers.get('openai');
            if (provider && await provider.isConfigured()) {
                return provider;
            }
        }
        if (model.startsWith('claude-')) {
            const provider = this.providers.get('anthropic');
            if (provider && await provider.isConfigured()) {
                return provider;
            }
        }
        return this.getDefaultProvider();
    }
    async complete(params) {
        const provider = await this.selectProviderForModel(params.model);
        if (!provider) {
            throw new Error(`No configured provider found for model: ${params.model}`);
        }
        console.log(`[AIProviders] Using ${provider.name} for model: ${params.model}`);
        return provider.complete(params);
    }
    async getAvailableModels() {
        const models = {};
        for (const [type, provider] of this.providers) {
            if (await provider.isConfigured()) {
                models[type] = await provider.getAvailableModels();
            }
        }
        return models;
    }
    async testAllProviders() {
        const results = {};
        for (const [type, provider] of this.providers) {
            if (await provider.isConfigured()) {
                results[type] = await provider.testConnection();
            }
            else {
                results[type] = false;
            }
        }
        return results;
    }
}
export const aiProviderManager = new AIProviderManager();
//# sourceMappingURL=provider-manager.js.map