import { countRequestTokens } from './token-counter.js';
export function computeRequestTokens(request, fallbackText) {
    try {
        return countRequestTokens(request);
    }
    catch {
        return fallbackEstimateTokens(fallbackText, request.messages?.length ?? 0);
    }
}
function fallbackEstimateTokens(text, messageCount) {
    if (!text) {
        return Math.max(32, Math.max(messageCount, 1) * 16);
    }
    const rough = Math.ceil(text.length / 4);
    return Math.max(rough, Math.max(messageCount, 1) * 32);
}
