"use strict";
/**
 * TokenCostModel
 *
 * Pricing table for all supported LLM providers and models.
 * Prices are in USD per 1,000,000 tokens (consistent unit).
 *
 * Sources:
 *  - Gemini 3.1: https://ai.google.dev/pricing (March 2026)
 *  - Gemini 2.x: https://ai.google.dev/pricing
 *  - GitHub Models: $0.00001/token flat (all models, as of March 2026)
 *  - OpenRouter: varies by model — use gemini-2.5-flash defaults as fallback
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.MODEL_PRICING = void 0;
exports.calculateCostUSD = calculateCostUSD;
exports.formatCostUSD = formatCostUSD;
// ── Gemini 3.1 models ─────────────────────────────────────────────────────
const GEMINI_3_1_PRO_PREVIEW = {
    inputPricePerMToken: 2.00,
    inputPricePerMTokenLarge: 4.00,
    outputPricePerMToken: 12.00,
    outputPricePerMTokenLarge: 18.00,
};
const GEMINI_3_1_FLASH_LITE_PREVIEW = {
    inputPricePerMToken: 0.25,
    outputPricePerMToken: 1.50,
};
const GEMINI_3_1_FLASH_IMAGE_PREVIEW = {
    inputPricePerMToken: 0.50,
    outputPricePerMToken: 3.00, // text output; image output is $60/1M tokens (billed separately)
};
// ── Gemini 2.x models ─────────────────────────────────────────────────────
const GEMINI_2_5_FLASH = {
    inputPricePerMToken: 0.15,
    outputPricePerMToken: 0.60,
};
const GEMINI_2_0_FLASH = {
    inputPricePerMToken: 0.10,
    outputPricePerMToken: 0.40,
};
// ── Gemini 1.5 models ─────────────────────────────────────────────────────
const GEMINI_1_5_PRO = {
    inputPricePerMToken: 3.50,
    inputPricePerMTokenLarge: 7.00,
    outputPricePerMToken: 10.50,
    outputPricePerMTokenLarge: 21.00,
};
const GEMINI_1_5_FLASH = {
    inputPricePerMToken: 0.075,
    inputPricePerMTokenLarge: 0.15,
    outputPricePerMToken: 0.30,
    outputPricePerMTokenLarge: 0.60,
};
// ── GitHub Models (flat rate) ─────────────────────────────────────────────
const GITHUB_MODELS_FLAT = {
    // $0.00001 per token = $10.00 per 1M tokens
    inputPricePerMToken: 10.00,
    outputPricePerMToken: 10.00,
};
const GPT_4O_MINI = {
    inputPricePerMToken: 0.15,
    outputPricePerMToken: 0.60,
};
// ── Master pricing table ──────────────────────────────────────────────────
exports.MODEL_PRICING = {
    // Gemini 3.1
    "gemini-3.1-pro-preview": GEMINI_3_1_PRO_PREVIEW,
    "gemini-3.1-flash-lite-preview": GEMINI_3_1_FLASH_LITE_PREVIEW,
    "gemini-3.1-flash-image-preview": GEMINI_3_1_FLASH_IMAGE_PREVIEW,
    // Gemini 2.x
    "gemini-2.5-flash": GEMINI_2_5_FLASH,
    "gemini-2.0-flash": GEMINI_2_0_FLASH,
    "gemini-2.0-flash-exp": GEMINI_2_0_FLASH,
    // Gemini 1.5
    "gemini-1.5-pro": GEMINI_1_5_PRO,
    "gemini-1.5-flash": GEMINI_1_5_FLASH,
    // OpenAI / GitHub Models
    "gpt-4o-mini": GPT_4O_MINI,
    "gpt-4o-mini (github-models)": GPT_4O_MINI,
    "github-models": GITHUB_MODELS_FLAT,
};
/** Threshold in tokens above which large-context pricing applies */
const LARGE_CONTEXT_THRESHOLD = 200000;
/**
 * Calculate cost in USD for a single LLM call.
 *
 * @param modelName  The model string returned by the client (used as lookup key)
 * @param inputTokens  Number of prompt/input tokens
 * @param outputTokens  Number of completion/output tokens
 * @returns cost in USD
 */
function calculateCostUSD(modelName, inputTokens, outputTokens) {
    const pricing = findPricing(modelName);
    if (!pricing)
        return 0;
    const inputPrice = inputTokens > LARGE_CONTEXT_THRESHOLD
        ? (pricing.inputPricePerMTokenLarge ?? pricing.inputPricePerMToken)
        : pricing.inputPricePerMToken;
    const outputPrice = inputTokens > LARGE_CONTEXT_THRESHOLD
        ? (pricing.outputPricePerMTokenLarge ?? pricing.outputPricePerMToken)
        : pricing.outputPricePerMToken;
    return (inputTokens * inputPrice + outputTokens * outputPrice) / 1000000;
}
/**
 * Find pricing for a model name, with fuzzy matching for variant suffixes.
 */
function findPricing(modelName) {
    if (!modelName)
        return undefined;
    const key = modelName.toLowerCase();
    // Exact match first
    if (exports.MODEL_PRICING[key])
        return exports.MODEL_PRICING[key];
    // Prefix match (handles "models/gemini-2.0-flash" SDK format)
    for (const [k, v] of Object.entries(exports.MODEL_PRICING)) {
        if (key.includes(k) || k.includes(key))
            return v;
    }
    return undefined;
}
/**
 * Format a USD cost for display, e.g. "$0.000743" or "<$0.00001"
 */
function formatCostUSD(costUSD) {
    if (costUSD === 0)
        return "$0.000";
    if (costUSD < 0.00001)
        return "<$0.00001";
    return `$${costUSD.toFixed(6)}`;
}
//# sourceMappingURL=TokenCostModel.js.map