import { ModelRegistry } from "../../models/ModelRegistry.js";
import { PricingRegistry } from "../../models/PricingRegistry.js";
export class Capabilities {
    static getContextWindow(modelId) {
        const val = ModelRegistry.getContextWindow(modelId, "gemini");
        if (val !== undefined && val !== null)
            return val;
        const id = this.normalizeModelId(modelId);
        if (id.match(/gemini-2\.5-pro-exp-03-25|gemini-2\.0-flash|gemini-2\.0-flash-lite|gemini-1\.5-flash|gemini-1\.5-flash-8b/)) {
            return 1_048_576;
        }
        if (id.match(/gemini-1\.5-pro/)) {
            return 2_097_152;
        }
        if (id.match(/gemini-embedding-exp/)) {
            return 8_192;
        }
        if (id.match(/text-embedding-004|embedding-001/)) {
            return 2_048;
        }
        if (id.match(/aqa/)) {
            return 7_168;
        }
        return 32_768;
    }
    static getMaxOutputTokens(modelId) {
        const val = ModelRegistry.getMaxOutputTokens(modelId, "gemini");
        if (val !== undefined && val !== null)
            return val;
        const id = this.normalizeModelId(modelId);
        if (id.match(/gemini-2\.5-pro-exp-03-25/)) {
            return 64_000;
        }
        if (id.match(/gemini-2\.0-flash|gemini-2\.0-flash-lite|gemini-1\.5-flash|gemini-1\.5-flash-8b|gemini-1\.5-pro/)) {
            return 8_192;
        }
        if (id.match(/text-embedding-004|embedding-001/)) {
            return 768;
        }
        if (id.match(/imagen-3/)) {
            return 4;
        }
        return 4_096;
    }
    static supportsVision(modelId) {
        const model = this.findModel(modelId);
        if (model?.modalities?.input?.includes("image"))
            return true;
        const id = this.normalizeModelId(modelId);
        if (id.match(/text-embedding|embedding-001|aqa/)) {
            return false;
        }
        return !!id.match(/gemini|flash|pro|imagen/);
    }
    static supportsTools(modelId) {
        const model = this.findModel(modelId);
        if (model?.capabilities?.includes("function_calling"))
            return true;
        const id = this.normalizeModelId(modelId);
        if (id.match(/text-embedding|embedding-001|aqa|flash-lite|imagen|gemini-2\.0-flash-lite/)) {
            return false;
        }
        return !!id.match(/gemini|pro|flash/);
    }
    static supportsStructuredOutput(modelId) {
        const model = this.findModel(modelId);
        if (model?.capabilities?.includes("structured_output"))
            return true;
        const id = this.normalizeModelId(modelId);
        if (id.match(/text-embedding|embedding-001|aqa|imagen/)) {
            return false;
        }
        return true;
    }
    static supportsSystemInstructions(_modelId) {
        return true;
    }
    static supportsJsonMode(modelId) {
        return this.supportsStructuredOutput(modelId);
    }
    static supportsEmbeddings(modelId) {
        const model = this.findModel(modelId);
        if (model?.modalities?.output?.includes("embeddings"))
            return true;
        const id = this.normalizeModelId(modelId);
        return !!id.match(/text-embedding|embedding|gemini-embedding/);
    }
    static supportsImageGeneration(modelId) {
        const model = this.findModel(modelId);
        if (model?.capabilities?.includes("image_generation") ||
            model?.modalities?.output?.includes("image"))
            return true;
        const id = this.normalizeModelId(modelId);
        return !!id.match(/imagen/);
    }
    static supportsTranscription(modelId) {
        const model = this.findModel(modelId);
        if (model?.modalities?.input?.includes("audio"))
            return true;
        const id = this.normalizeModelId(modelId);
        return !!id.match(/gemini|flash|pro/);
    }
    static supportsModeration(_modelId) {
        return false;
    }
    static normalizeTemperature(temperature, _model) {
        return temperature;
    }
    static getModalities(modelId) {
        const input = ["text"];
        const output = ["text"];
        const id = this.normalizeModelId(modelId);
        if (this.supportsVision(id))
            input.push("image", "video", "audio", "pdf");
        if (this.supportsImageGeneration(id))
            output.push("image");
        if (this.supportsEmbeddings(id))
            output.push("embeddings");
        return { input, output };
    }
    static getCapabilities(modelId) {
        const caps = ["streaming"];
        const id = this.normalizeModelId(modelId);
        if (this.supportsTools(id))
            caps.push("function_calling");
        if (this.supportsStructuredOutput(id))
            caps.push("structured_output");
        if (this.supportsEmbeddings(id))
            caps.push("embeddings");
        if (this.supportsImageGeneration(id))
            caps.push("image_generation");
        return caps;
    }
    static getPricing(modelId) {
        return PricingRegistry.getPricing(modelId, "gemini");
    }
    static normalizeModelId(modelId) {
        return modelId.replace("models/", "");
    }
    static findModel(modelId) {
        return ModelRegistry.find(modelId, "gemini");
    }
}
