import { useMemo } from "react" import { useTranslation } from "react-i18next" import { formatLargeNumber } from "@/utils/format" import { calculateTokenDistribution } from "@/utils/model-utils" import { StandardTooltip } from "@/components/ui" interface ContextWindowProgressProps { contextWindow: number contextTokens: number maxTokens?: number } export const ContextWindowProgress = ({ contextWindow, contextTokens, maxTokens }: ContextWindowProgressProps) => { const { t } = useTranslation() // Use the shared utility function to calculate all token distribution values const tokenDistribution = useMemo( () => calculateTokenDistribution(contextWindow, contextTokens, maxTokens), [contextWindow, contextTokens, maxTokens], ) // Destructure the values we need const { currentPercent, reservedPercent, availableSize, reservedForOutput, availablePercent } = tokenDistribution // For display purposes const safeContextWindow = Math.max(0, contextWindow) const safeContextTokens = Math.max(0, contextTokens) // Combine all tooltip content into a single tooltip const tooltipContent = (
{t("chat:tokenProgress.tokensUsed", { used: formatLargeNumber(safeContextTokens), total: formatLargeNumber(safeContextWindow), })}
{reservedForOutput > 0 && (
{t("chat:tokenProgress.reservedForResponse", { amount: formatLargeNumber(reservedForOutput), })}
)} {availableSize > 0 && (
{t("chat:tokenProgress.availableSpace", { amount: formatLargeNumber(availableSize), })}
)}
) return ( <>
{formatLargeNumber(safeContextTokens)}
{/* Main progress bar container */}
{/* Current tokens container */}
{/* Current tokens used - darkest */}
{/* Container for reserved tokens */}
{/* Reserved for output section - medium gray */}
{/* Empty section (if any) */} {availablePercent > 0 && (
{/* Available space - transparent */}
)}
{formatLargeNumber(safeContextWindow)}
) }