import { SHORTCUT_PROVIDER_ID } from '../../model-ids.js';
const DOLLARS_PER_CREDIT = 0.1;
const COST_UNITS_PER_CREDIT = 1_000_000 * DOLLARS_PER_CREDIT;
function roundCredits(value) {
    return Math.round(value * 100) / 100;
}
export function computeSessionCreditsUsed(messages, modelRegistry) {
    let creditsUsed = 0;
    for (const message of messages) {
        if (message.role !== 'assistant' || message.provider !== SHORTCUT_PROVIDER_ID) {
            continue;
        }
        const assistant = message;
        const model = modelRegistry.find(message.provider, message.model) ??
            modelRegistry.getAll().find((candidate) => candidate.id === message.model);
        if (!model) {
            continue;
        }
        const uncachedInput = Math.max(0, assistant.usage.input - assistant.usage.cacheRead - assistant.usage.cacheWrite);
        creditsUsed += (uncachedInput * model.cost.input) / COST_UNITS_PER_CREDIT;
        creditsUsed += (assistant.usage.output * model.cost.output) / COST_UNITS_PER_CREDIT;
        creditsUsed += (assistant.usage.cacheRead * model.cost.cacheRead) / COST_UNITS_PER_CREDIT;
        creditsUsed += (assistant.usage.cacheWrite * model.cost.cacheWrite) / COST_UNITS_PER_CREDIT;
    }
    return roundCredits(creditsUsed);
}
//# sourceMappingURL=session-credits.js.map