"use client"; import * as React from "react"; import { AlertTriangle, ArrowUpRight, FileText, Loader2, MessageSquarePlus } from "lucide-react"; import type { PolyModel } from "@/lib/client/types"; import type { ContextEstimate, CostEstimate } from "@/lib/client/tokens"; import { formatEstimate } from "@/lib/client/tokens"; import { Button } from "@/components/ui/button"; import { Tooltip } from "@/components/ui/tooltip"; import { cn, formatTokens } from "@/lib/utils"; interface Props { estimate: ContextEstimate; cost: CostEstimate; model?: PolyModel; showCost?: boolean; onNewChat: () => void; onSummarize?: () => void; summarizing?: boolean; largerModel?: PolyModel | null; onSwitchLarger?: (key: string) => void; className?: string; } function fmtK(n: number): string { if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(1).replace(/\.0$/, "")}M`; if (n >= 1000) return `${Math.round(n / 1000)}K`; return String(n); } /** * Compact "43K / 200K" context meter + cost estimate. Turns into an action banner at 80 % (warn), * 95 % (critical) and when the estimate exceeds the window. */ export function ContextIndicator({ estimate, cost, showCost = true, onNewChat, onSummarize, summarizing, largerModel, onSwitchLarger, className }: Props) { const ratio = estimate.ratio ?? 0; const level = estimate.level; const bar = level === "over" || level === "critical" ? "bg-danger" : level === "warn" ? "bg-warning" : "bg-accent"; const pct = Math.min(100, Math.round(ratio * 100)); const label = estimate.contextTokens ? `${fmtK(estimate.total)} / ${fmtK(estimate.contextTokens)}` : `~${fmtK(estimate.total)} tokens`; const costLabel = showCost ? formatEstimate(estimate.total, cost.usd) : `~${fmtK(estimate.total)} tokens`; return (