import { Capabilities } from "./Capabilities.js";
import { ModelRegistry } from "../../models/ModelRegistry.js";
export class GeminiModels {
    baseUrl;
    apiKey;
    constructor(baseUrl, apiKey) {
        this.baseUrl = baseUrl;
        this.apiKey = apiKey;
    }
    async execute() {
        try {
            const response = await fetch(`${this.baseUrl}/models?key=${this.apiKey}`, {
                method: "GET",
                headers: {
                    "Content-Type": "application/json"
                }
            });
            if (response.ok) {
                const { models } = (await response.json());
                return models.map((m) => {
                    const modelId = m.name.replace("models/", "");
                    const registryModel = ModelRegistry.find(modelId, "gemini");
                    const info = {
                        id: modelId,
                        name: registryModel?.name || m.displayName || modelId,
                        provider: "gemini",
                        family: registryModel?.family || modelId,
                        context_window: registryModel?.context_window || Capabilities.getContextWindow(modelId),
                        max_output_tokens: registryModel?.max_output_tokens || Capabilities.getMaxOutputTokens(modelId),
                        modalities: registryModel?.modalities || Capabilities.getModalities(modelId),
                        capabilities: Capabilities.getCapabilities(modelId),
                        pricing: registryModel?.pricing || Capabilities.getPricing(modelId),
                        metadata: {
                            ...(registryModel?.metadata || {}),
                            description: m.description,
                            input_token_limit: m.inputTokenLimit,
                            output_token_limit: m.outputTokenLimit,
                            supported_generation_methods: m.supportedGenerationMethods
                        }
                    };
                    return info;
                });
            }
        }
        catch (_error) {
            // Fallback
        }
        return ModelRegistry.all()
            .filter((m) => m.provider === "gemini")
            .map((m) => ({
            ...m,
            capabilities: Capabilities.getCapabilities(m.id)
        }));
    }
    find(modelId) {
        return ModelRegistry.find(modelId, "gemini");
    }
}
