import { estimateTokens as estimateMessageTokens } from "../sdk/coding-agent/index.js";
export function estimateStringTokens(text) {
    return Math.ceil(text.length / 4);
}
export function estimateEntryTokens(entry) {
    if (entry.type === "message" && entry.message) {
        return estimateMessageTokens(entry.message);
    }
    if (entry.type === "custom_message" && entry.content) {
        const content = entry.content;
        if (typeof content === "string")
            return estimateStringTokens(content);
        if (Array.isArray(content)) {
            let total = 0;
            for (const block of content) {
                if (block.type === "text" && block.text)
                    total += estimateStringTokens(block.text);
            }
            return total;
        }
    }
    if (entry.type === "branch_summary" && typeof entry.summary === "string") {
        return estimateStringTokens(entry.summary);
    }
    return 0;
}
