const itemizedCostKeys = [
    "inputCost",
    "outputCost",
    "cachedCost",
    "cacheWriteCost",
    "inputAudioCost",
    "outputAudioCost",
    "outputImageCost",
    "imageCost",
    "markupCost",
];
function toNonNegativeCost(value) {
    const numericValue = Number(value);
    return Number.isFinite(numericValue) && numericValue > 0 ? numericValue : 0;
}
export function calculateItemizedCostTotal(costs) {
    return itemizedCostKeys.reduce((total, key) => total + toNonNegativeCost(costs[key]), 0);
}
/**
 * A cumulative snapshot can briefly carry a stale declared total while already
 * containing newer itemized costs (notably generated-image tool costs). Never
 * display or enforce a total below the costs represented by its own rows.
 */
export function reconcileAgentCostTotal(declaredTotal, costs) {
    return Math.max(toNonNegativeCost(declaredTotal), calculateItemizedCostTotal(costs));
}
export function formatAgentCost(value, currency = "USD") {
    const normalizedCurrency = currency.trim() || "USD";
    return `${toNonNegativeCost(value).toFixed(2)} ${normalizedCurrency}`;
}
//# sourceMappingURL=agentCost.js.map