diff --git a/frontend/src/components/ChatBox.tsx b/frontend/src/components/ChatBox.tsx index 218cde79..7129b4ed 100644 --- a/frontend/src/components/ChatBox.tsx +++ b/frontend/src/components/ChatBox.tsx @@ -22,13 +22,17 @@ function TokenWarning({ currentInput, chatId, className, - billingStatus + billingStatus, + onCompress, + isCompressing = false }: { messages: ChatMessage[]; currentInput: string; chatId?: string; className?: string; billingStatus?: BillingStatus; + onCompress?: () => void; + isCompressing?: boolean; }) { const totalTokens = messages.reduce((acc, msg) => acc + estimateTokenCount(msg.content), 0) + @@ -37,7 +41,7 @@ function TokenWarning({ const navigate = useNavigate(); // Check if user is on starter plan - const isStarter = billingStatus?.product_name.toLowerCase().includes("starter") || false; + const isStarter = billingStatus?.product_name?.toLowerCase().includes("starter") || false; // Token thresholds for different plan types const STARTER_WARNING_THRESHOLD = 4000; @@ -60,6 +64,19 @@ function TokenWarning({ } }; + // Determine button text based on compression state + const getButtonText = () => { + if (isCompressing) { + return { desktop: "Compressing...", mobile: "Compressing..." }; + } + if (onCompress) { + return { desktop: "Compress chat", mobile: "Compress" }; + } + return { desktop: "Start a new chat", mobile: "New chat" }; + }; + + const buttonText = getButtonText(); + return (