export function hasNonZeroLiveTotals(totals) {
    return ((totals.totalCost || 0) > 0 ||
        (totals.input || 0) > 0 ||
        (totals.output || 0) > 0 ||
        (totals.cached || 0) > 0 ||
        (totals.cacheWrite || 0) > 0);
}
export function liveTotalsFromStreamCost(cost) {
    if (!cost || (cost.total === undefined && cost.tokens?.total === undefined)) {
        return null;
    }
    return {
        input: Number(cost.tokens?.input) || 0,
        output: Number(cost.tokens?.output) || 0,
        cached: Number(cost.tokens?.cached) || 0,
        cacheWrite: Number(cost.tokens?.cacheWrite) || 0,
        inputAudio: Number(cost.tokens?.inputAudio) || 0,
        outputAudio: Number(cost.tokens?.outputAudio) || 0,
        outputImage: Number(cost.tokens?.outputImage) || 0,
        reasoning: Number(cost.tokens?.reasoning) || 0,
        inputCost: Number(cost.input) || 0,
        outputCost: Number(cost.output) || 0,
        cachedCost: Number(cost.cached) || 0,
        cacheWriteCost: Number(cost.cacheWrite) || 0,
        inputAudioCost: Number(cost.inputAudio) || 0,
        outputAudioCost: Number(cost.outputAudio) || 0,
        outputImageCost: Number(cost.outputImage) || 0,
        imageCost: Number(cost.imageCost ?? cost.totalImageCost) || 0,
        markupCost: Number(cost.markup) || 0,
        reportedTotalCost: Number(cost.reportedTotal) || 0,
        totalCost: Number(cost.total) || 0,
        currency: "USD",
    };
}
export function liveTotalsFromToolResultData(data) {
    if (!data ||
        (data.totalCost === undefined && data.totalTokens === undefined)) {
        return null;
    }
    return {
        input: Number(data.totalInputTokens) || 0,
        output: Number(data.totalOutputTokens) || 0,
        cached: Number(data.totalCachedTokens) || 0,
        cacheWrite: Number(data.totalCacheWriteTokens) || 0,
        inputAudio: Number(data.totalInputAudioTokens) || 0,
        outputAudio: Number(data.totalOutputAudioTokens) || 0,
        outputImage: Number(data.totalOutputImageTokens) || 0,
        reasoning: Number(data.totalReasoningTokens) || 0,
        inputCost: Number(data.totalInputTokenCost) || 0,
        outputCost: Number(data.totalOutputTokenCost) || 0,
        cachedCost: Number(data.totalCachedTokenCost) || 0,
        cacheWriteCost: Number(data.totalCacheWriteTokenCost) || 0,
        inputAudioCost: Number(data.totalInputAudioCost) || 0,
        outputAudioCost: Number(data.totalOutputAudioCost) || 0,
        outputImageCost: Number(data.totalOutputImageCost) || 0,
        imageCost: Number(data.totalImageCost) || 0,
        markupCost: Number(data.totalMarkupCost) || 0,
        reportedTotalCost: Number(data.totalReportedCost) || 0,
        totalCost: Number(data.totalCost) || 0,
        currency: data.currency || "USD",
    };
}
export function liveTotalsFromStatusTotals(totals) {
    if (!totals)
        return null;
    const totalCost = Number(totals.totalCost) || 0;
    return {
        input: Number(totals.totalInputTokens) || 0,
        output: Number(totals.totalOutputTokens) || 0,
        cached: Number(totals.totalCachedInputTokens) || 0,
        cacheWrite: Number(totals.totalCacheWriteTokens) || 0,
        inputAudio: Number(totals.totalInputAudioTokens) || 0,
        outputAudio: Number(totals.totalOutputAudioTokens) || 0,
        outputImage: Number(totals.totalOutputImageTokens) || 0,
        reasoning: Number(totals.totalReasoningTokens) || 0,
        inputCost: Number(totals.totalInputTokenCost) || 0,
        outputCost: Number(totals.totalOutputTokenCost) || 0,
        cachedCost: Number(totals.totalCachedInputTokenCost) || 0,
        cacheWriteCost: Number(totals.totalCacheWriteTokenCost) || 0,
        inputAudioCost: Number(totals.totalInputAudioCost) || 0,
        outputAudioCost: Number(totals.totalOutputAudioCost) || 0,
        outputImageCost: Number(totals.totalOutputImageCost) || 0,
        imageCost: Number(totals.totalImageCost) || 0,
        markupCost: Number(totals.totalMarkupCost) || 0,
        reportedTotalCost: Number(totals.totalReportedCost) || 0,
        totalCost,
        currency: totals.currency,
    };
}
export function contextWindowStatusFromStreamCost(cost, model) {
    const contextWindowRaw = cost?.contextWindow;
    const contextUsedRaw = cost?.contextUsed;
    if (contextWindowRaw === undefined ||
        contextWindowRaw === null ||
        contextUsedRaw === undefined ||
        contextUsedRaw === null) {
        return null;
    }
    const contextWindowTokens = Number(contextWindowRaw);
    const estimatedInputTokens = Number(contextUsedRaw);
    if (contextWindowTokens <= 0 ||
        !Number.isFinite(estimatedInputTokens) ||
        estimatedInputTokens < 0) {
        return null;
    }
    return {
        contextWindowTokens,
        estimatedInputTokens,
        contextUsedPercent: (estimatedInputTokens / contextWindowTokens) * 100,
        model,
    };
}
//# sourceMappingURL=agentSessionLiveTotals.js.map