// engine/model-router/cost-estimator.ts — Token and USD cost estimation per model tier.
// SPEC-076 AC-04
import pricingJson from '../../config/ai-model-pricing.json' with { type: 'json' };
// ---------------------------------------------------------------------------
// Pricing lookup
// ---------------------------------------------------------------------------
const MODEL_IDS = {
    haiku: 'claude-haiku-3-5',
    sonnet: 'claude-sonnet-4',
    opus: 'claude-opus-4',
};
function getPricing(tier) {
    const modelId = MODEL_IDS[tier];
    const entry = pricingJson.models.find((m) => m.id === modelId);
    /* c8 ignore next 3 */
    if (!entry) {
        return { id: modelId, inputPricePerMillion: 3, outputPricePerMillion: 15 };
    }
    return entry;
}
// ---------------------------------------------------------------------------
// Token estimation heuristic
// ---------------------------------------------------------------------------
/** Base token estimates per complexity range (overall score brackets). */
function estimateTokens(signals) {
    const score = signals.overallScore;
    // Read-only tasks consume less output
    const outputMultiplier = signals.isReadOnly ? 0.3 : 1;
    if (score < 0.3) {
        return { input: 2_000, output: Math.round(1_000 * outputMultiplier) };
    }
    if (score < 0.6) {
        return { input: 8_000, output: Math.round(5_000 * outputMultiplier) };
    }
    return { input: 20_000, output: Math.round(15_000 * outputMultiplier) };
}
// ---------------------------------------------------------------------------
// Public API
// ---------------------------------------------------------------------------
/** Calculate the cost estimate for a given model tier and complexity signals. */
export function calculateCost(tier, signals) {
    const pricing = getPricing(tier);
    const tokens = estimateTokens(signals);
    const inputCost = (tokens.input / 1_000_000) * pricing.inputPricePerMillion;
    const outputCost = (tokens.output / 1_000_000) * pricing.outputPricePerMillion;
    return {
        estimatedTokens: tokens.input + tokens.output,
        estimatedUSD: Math.round((inputCost + outputCost) * 10_000) / 10_000,
        breakdown: { input: tokens.input, output: tokens.output },
    };
}
/** Calculate costs for all three tiers so the user can compare. */
export function calculateAllTierCosts(signals) {
    return {
        haiku: calculateCost('haiku', signals),
        sonnet: calculateCost('sonnet', signals),
        opus: calculateCost('opus', signals),
    };
}
//# sourceMappingURL=cost-estimator.js.map