"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createGeminiUsageMetadata = void 0;
const createGeminiUsageMetadata = (usage) => {
    const usageMetadata = {
        input_tokens: usage.promptTokenCount || 0,
        output_tokens: (() => {
            if ("responseTokenCount" in usage) {
                return usage.responseTokenCount || 0;
            }
            if ("candidatesTokenCount" in usage) {
                return usage.candidatesTokenCount || 0;
            }
            return 0;
        })(),
        total_tokens: usage.totalTokenCount || 0,
    };
    // Add input token details if available
    usageMetadata.input_token_details = {
        cache_read: usage.cachedContentTokenCount != null
            ? Math.min(usage.cachedContentTokenCount, 200_000)
            : undefined,
        cache_read_over_200k: usage.cachedContentTokenCount != null
            ? Math.max(0, usage.cachedContentTokenCount - 200_000)
            : undefined,
        over_200k: usage.promptTokenCount != null
            ? Math.max(0, usage.promptTokenCount -
                (usage.cachedContentTokenCount || 0) -
                200_000)
            : undefined,
    };
    // Add output token details if available
    usageMetadata.output_token_details = {
        over_200k: "candidatesTokenCount" in usage && usage.candidatesTokenCount != null
            ? Math.max(0, usage.candidatesTokenCount - 200_000)
            : undefined,
        reasoning: usage.thoughtsTokenCount ?? undefined,
    };
    return usageMetadata;
};
exports.createGeminiUsageMetadata = createGeminiUsageMetadata;
