const CONTEXT_BREAKDOWN_LABELS = {
    messages: "Messages",
    systemPrompt: "System prompt",
    tools: "Tools",
    skills: "Skills",
    documents: "Documents",
    context: "Editor context",
    compressedHistory: "Compressed history",
};
export function formatContextBreakdownLabel(key) {
    const known = CONTEXT_BREAKDOWN_LABELS[key];
    if (known)
        return known;
    const spaced = key.replace(/([a-z0-9])([A-Z])/g, "$1 $2").toLowerCase();
    return spaced.charAt(0).toUpperCase() + spaced.slice(1);
}
/**
 * Turns the per-category context breakdown into display rows sorted by size,
 * with a trailing "Free space" row. The breakdown snapshot may be slightly
 * older than the latest usage value (e.g. a totals-derived fallback update),
 * so the categories are rescaled to sum to the displayed usage.
 */
export function buildContextBreakdownRows(status) {
    const breakdown = status.breakdown;
    if (!breakdown)
        return [];
    const entries = Object.entries(breakdown).filter(([, tokens]) => Number.isFinite(tokens) && tokens > 0);
    if (entries.length === 0)
        return [];
    const sum = entries.reduce((acc, [, tokens]) => acc + tokens, 0);
    if (sum <= 0)
        return [];
    const scale = status.estimatedInputTokens > 0 ? status.estimatedInputTokens / sum : 1;
    const windowTokens = status.contextWindowTokens;
    const rows = entries
        .map(([key, tokens]) => {
        const scaled = tokens * scale;
        return {
            key,
            label: formatContextBreakdownLabel(key),
            tokens: scaled,
            percent: windowTokens > 0 ? (scaled / windowTokens) * 100 : 0,
        };
    })
        .sort((a, b) => b.tokens - a.tokens);
    if (windowTokens > 0) {
        const free = Math.max(0, windowTokens - status.estimatedInputTokens);
        rows.push({
            key: "free",
            label: "Free space",
            tokens: free,
            percent: (free / windowTokens) * 100,
            isFree: true,
        });
    }
    return rows;
}
//# sourceMappingURL=contextBreakdown.js.map