/**
 * Shared usage/cost calculation for Shortcut LLM providers.
 *
 * Both shortcut-stream.ts and shortcut-invoke.ts need identical logic
 * to convert raw token counts into owned AI Usage objects with cost breakdown.
 */
/**
 * Build a owned AI Usage object from raw token counts and model cost rates.
 */
export function buildUsage(rawUsage, model) {
    const input = rawUsage.input_tokens ?? 0;
    const output = rawUsage.output_tokens ?? 0;
    // LangChain nests cache stats under input_token_details; Anthropic's raw API
    // uses top-level cache_read_input_tokens. Support both.
    const details = rawUsage.input_token_details;
    const cacheRead = details?.cache_read ?? rawUsage.cache_read_input_tokens ?? 0;
    const cacheWrite = details?.cache_creation ?? rawUsage.cache_creation_input_tokens ?? 0;
    const uncachedInput = Math.max(0, input - cacheRead - cacheWrite);
    const costInput = (uncachedInput * model.cost.input) / 1_000_000;
    const costOutput = (output * model.cost.output) / 1_000_000;
    const costCacheRead = (cacheRead * model.cost.cacheRead) / 1_000_000;
    const costCacheWrite = (cacheWrite * model.cost.cacheWrite) / 1_000_000;
    return {
        input,
        output,
        cacheRead,
        cacheWrite,
        totalTokens: input + output,
        cost: {
            input: costInput,
            output: costOutput,
            cacheRead: costCacheRead,
            cacheWrite: costCacheWrite,
            total: costInput + costOutput + costCacheRead + costCacheWrite
        }
    };
}
/** Map backend stop_reason strings to owned AI StopReason values. */
export function mapStopReason(raw) {
    return raw === 'tool_use' ? 'toolUse' : raw === 'max_tokens' ? 'length' : 'stop';
}
//# sourceMappingURL=llm-usage.js.map