{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "token-budget-bar",
  "title": "Token Budget Bar",
  "description": "A compact context budget island with used and reserved tokens, expandable breakdown and near-limit or exceeded states.",
  "dependencies": [
    "motion",
    "lucide-react",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/token-budget-bar/token-budget-bar.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion, useReducedMotion } from \"motion/react\";\nimport { clsx } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\nimport { ChevronDown, ArrowUpRight, CircleAlert } from \"lucide-react\";\n\nexport interface TokenBudgetBarProps {\n  used?: number;\n  limit?: number;\n  reserved?: number;\n  model?: string;\n  defaultExpanded?: boolean;\n  onManage?: () => void;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst SHEEN = \"linear-gradient(115deg,rgba(255,255,255,.08),rgba(255,255,255,.02) 30%,transparent 48%,rgba(255,255,255,.04) 74%,transparent),linear-gradient(180deg,rgba(255,255,255,.05),transparent 60%)\";\nfunction Island({ children, theme, active = false, warm = false, className }: { children: React.ReactNode; theme: \"dark\" | \"light\"; active?: boolean; warm?: boolean; className?: string }) {\n  const reduce = useReducedMotion();\n  return <motion.div layout={!reduce} transition={{ type: \"spring\", stiffness: 260, damping: 30 }} className={twMerge(clsx(\"relative isolate w-full rounded-[32px] border font-sans antialiased [font-family:Inter,ui-sans-serif,system-ui,sans-serif]\", theme === \"dark\" ? \"border-white/[0.09] bg-[#0E0E10] text-[#EDEDED]\" : \"border-black/[0.09] bg-[#f7f7f8] text-[#202023]\", className))} style={{ backgroundImage: SHEEN, boxShadow: theme === \"dark\" ? \"inset 0 1px 0 #ffffff1f,0 16px 48px #00000025\" : \"inset 0 1px 0 #ffffff,0 16px 48px #00000008\" }}>\n    <motion.div aria-hidden=\"true\" className=\"pointer-events-none absolute -inset-px rounded-[inherit]\" animate={{ opacity: active && !reduce ? [0.35, 0.8, 0.35] : active ? 0.5 : 0.18 }} transition={{ duration: 3, repeat: active && !reduce ? Infinity : 0 }} style={{ padding: 1, background: warm ? \"conic-gradient(from 40deg,transparent 10%,#FF7BD5 32%,#FFB86B 45%,transparent 65%)\" : \"conic-gradient(from 40deg,transparent 10%,#7CF3FF 32%,#6EA8FF 45%,#9B7BFF 55%,transparent 75%)\", mask: \"linear-gradient(#fff 0 0) content-box,linear-gradient(#fff 0 0)\", maskComposite: \"exclude\", WebkitMaskComposite: \"xor\" }} />\n    {children}\n  </motion.div>;\n}\nfunction Orb({ active = false, warm = false, size = 40 }: { active?: boolean; warm?: boolean; size?: number }) {\n  const reduce = useReducedMotion();\n  return <span aria-hidden=\"true\" className=\"relative inline-flex shrink-0 items-center justify-center\" style={{ width: size, height: size }}>\n    <motion.span className=\"absolute inset-0 rounded-full blur-md\" style={{ background: warm ? \"radial-gradient(circle,#ffb86b55,transparent 70%)\" : \"radial-gradient(circle,#9b7bff55,transparent 70%)\" }} animate={{ opacity: active && !reduce ? [0.3, 0.9, 0.3] : 0.3 }} transition={{ duration: 2.5, repeat: active && !reduce ? Infinity : 0 }} />\n    <motion.svg viewBox=\"0 0 40 40\" className=\"relative size-full\" animate={active && !reduce ? { rotate: [0, 12, 0] } : { rotate: 0 }} transition={{ duration: 5, repeat: active && !reduce ? Infinity : 0 }}>{Array.from({ length: 81 }, (_, i) => { const x = i % 9 - 4; const y = Math.floor(i / 9) - 4; const d = Math.hypot(x, y); return d <= 4.1 ? <circle key={i} cx={20 + x * 3.9} cy={20 + y * 3.9} r={Number((1 - d * .13).toFixed(3))} fill=\"currentColor\" opacity={Number((.95 - d * .16).toFixed(3))} /> : null; })}</motion.svg>\n  </span>;\n}\nconst action = \"inline-flex min-h-10 shrink-0 items-center justify-center gap-2 rounded-full border border-current/[0.12] px-4 text-[11px] transition-colors hover:bg-current/[0.06] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[#9B7BFF] disabled:cursor-not-allowed disabled:opacity-35 motion-reduce:transition-none [&_svg]:shrink-0\";\n\n/** Counts are supplied by the host application; this component does not estimate token usage. */\nexport function TokenBudgetBar({ used = 18420, limit = 32000, reserved = 4000, model = \"Workspace model\", defaultExpanded = false, onManage, theme = \"dark\", className }: TokenBudgetBarProps) {\n  const [expanded, setExpanded] = React.useState(defaultExpanded);\n  const id = React.useId();\n  const reduce = useReducedMotion();\n  const finite = (n: number) => Number.isFinite(n) ? Math.max(0, n) : 0;\n  const maximum = Math.floor(finite(limit));\n  const consumed = Math.floor(finite(used));\n  const reserve = Math.floor(finite(reserved));\n  const total = consumed + reserve;\n  const ratio = maximum > 0 ? Math.min(1, consumed / maximum) : 0;\n  const reserveRatio = maximum > 0 ? Math.min(1 - ratio, reserve / maximum) : 0;\n  const over = maximum === 0 || total > maximum;\n  const near = !over && total / maximum >= .85;\n  const remaining = Math.max(0, maximum - total);\n  const number = (n: number) => n.toLocaleString(\"en-US\");\n  const color = over ? \"#f0a0a0\" : near ? \"#FFB86B\" : theme === \"dark\" ? \"#c5c0d0\" : \"#71677f\";\n  return <div className={twMerge(\"mx-auto w-full max-w-[460px]\", className)}><Island theme={theme} warm={near || over} active={near || over} className=\"p-5 sm:p-6\">\n    <button type=\"button\" aria-expanded={expanded} aria-controls={id} onClick={() => setExpanded(!expanded)} className=\"flex w-full items-center gap-3 rounded-xl text-left outline-none focus-visible:ring-2 focus-visible:ring-[#9B7BFF]/60\"><Orb size={40} warm={near || over} /><div className=\"min-w-0 flex-1\"><h3 className=\"text-[14px] font-medium tracking-[-0.025em]\">Room to think</h3><p className=\"mt-1 truncate text-[10px] opacity-40\">{model} <span className=\"mx-1 opacity-50\">/</span> Context budget</p></div><span className=\"text-[12px] tabular-nums\" style={{ color }}>{maximum ? Math.round(Math.min(1, total / maximum) * 100) : 0}%</span><ChevronDown size={17} className={clsx(\"opacity-40 transition-transform motion-reduce:transition-none\", expanded && \"rotate-180\")} /></button>\n    <div role=\"meter\" aria-label=\"Context token usage including reserved output\" aria-valuemin={0} aria-valuemax={maximum || 1} aria-valuenow={Math.min(maximum || 1, total)} aria-valuetext={`${number(consumed)} used, ${number(reserve)} reserved, ${number(maximum)} token limit`} className=\"relative mt-6 flex h-2 overflow-hidden rounded-full bg-current/[0.07]\">\n      <motion.span className=\"h-full rounded-l-full\" style={{ background: `linear-gradient(90deg,${theme === \"dark\" ? \"#62616a\" : \"#a29daa\"},${color})` }} initial={false} animate={{ width: `${ratio * 100}%` }} transition={{ duration: reduce ? 0 : .6, ease: [.2,.8,.2,1] }} />\n      <motion.span className=\"h-full border-l-2 border-[#0E0E10]/50\" style={{ backgroundColor: color, backgroundImage: \"repeating-linear-gradient(120deg,transparent,transparent 2px,#0e0e1060 2px,#0e0e1060 4px)\", opacity: .5 }} initial={false} animate={{ width: `${reserveRatio * 100}%` }} transition={{ duration: reduce ? 0 : .6 }} />\n    </div>\n    <div className=\"mt-3 flex justify-between gap-3 text-[10px] tabular-nums\"><span><span className=\"opacity-75\">{number(consumed)}</span><span className=\"opacity-35\"> / {number(maximum)} tokens</span></span><span className=\"opacity-40\">{number(remaining)} available</span></div>\n    <div id={id} hidden={!expanded} className=\"mt-5 border-t border-current/[0.08] pt-4\"><dl className=\"space-y-3 text-[11px]\">{[[\"Used by conversation\", consumed], [\"Reserved for response\", reserve], [\"Available context\", remaining]].map(([label, value], i) => <div key={label} className=\"flex items-center justify-between\"><dt className=\"flex items-center gap-2 opacity-45\"><span className={clsx(\"size-1.5 rounded-full\", i === 0 ? \"bg-current/80\" : i === 1 ? \"bg-current/40\" : \"border border-current/40\")} />{label}</dt><dd className=\"tabular-nums opacity-75\">{number(Number(value))}</dd></div>)}</dl>{onManage && <button type=\"button\" onClick={onManage} className={action + \" mt-5 w-full\"}>Manage context<ArrowUpRight size={16} /></button>}</div>\n    <p role=\"status\" className=\"mt-5 flex items-start gap-2 border-t border-current/[0.08] pt-4 text-[10px] leading-4\" style={{ color: near || over ? color : undefined }}>{near || over ? <CircleAlert size={16} className=\"mt-0.5 shrink-0\" /> : <span className=\"mt-1 size-1.5 shrink-0 rounded-full bg-current opacity-40\" />}<span className={near || over ? \"\" : \"opacity-40\"}>{maximum === 0 ? \"Set a token limit to track your available context.\" : over ? \"Budget exceeded. Reduce context or the response reserve.\" : near ? \"Context is nearly full. Leave a little room for the reply.\" : \"Plenty of space for your next idea.\"}</span></p>\n  </Island></div>;\n}\nexport default TokenBudgetBar;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}