/**
 * cost/tracker.mjs — runtime-callable CostTracker for the CLI (C11).
 *
 * Mirror of cost/tracker.ts kept in .mjs so the CLI dispatcher can import
 * without a TypeScript build step. Behavior matches tracker.ts byte-for-byte
 * for the methods the CLI uses (record, summarize, fromJSON, toJSON). The
 * existing tracker.ts unit suite (cost-tracker.test.ts) covers the contract;
 * a drift between the two would surface as a divergence in the C11
 * integration tests (which exercise this .mjs version) versus the existing
 * cost-tracker tests (which exercise the .ts version).
 */
import { calculateCost } from './pricing.mjs';
export class CostTracker {
    constructor(customPricing) {
        this.entries = [];
        this.customPricing = customPricing;
    }
    record(entry) {
        const { costUsd } = calculateCost(entry.inputTokens, entry.outputTokens, entry.modelId, this.customPricing);
        this.entries.push({ ...entry, costUsd });
    }
    summarize(taskId) {
        const taskEntries = this.entries.filter((e) => e.taskId === taskId);
        const totalCostUsd = taskEntries.reduce((s, e) => s + e.costUsd, 0);
        const totalInputTokens = taskEntries.reduce((s, e) => s + e.inputTokens, 0);
        const totalOutputTokens = taskEntries.reduce((s, e) => s + e.outputTokens, 0);
        const totalThinkingTokens = taskEntries.reduce((s, e) => s + (e.thinkingTokens ?? 0), 0);
        const totalDurationMs = taskEntries.reduce((s, e) => s + (e.durationMs ?? 0), 0);
        const sessionCount = taskEntries.length;
        const costPerSession = sessionCount > 0 ? totalCostUsd / sessionCount : 0;
        return {
            taskId,
            totalCostUsd,
            totalInputTokens,
            totalOutputTokens,
            totalThinkingTokens,
            sessionCount,
            totalDurationMs,
            entries: taskEntries,
            costPerSession,
        };
    }
    toJSON() {
        return [...this.entries];
    }
    static fromJSON(entries) {
        const t = new CostTracker();
        t.entries = [...entries];
        return t;
    }
}
//# sourceMappingURL=tracker.mjs.map