{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ai-usage",
  "title": "AI Usage",
  "description": "Primitives for LLM usage: token cost at per-million prices with cached input billed separately, cache savings and hit rate, compact token and dollar formatting, model colours in a fixed order and an input, cached and output token bar.",
  "registryDependencies": [
    "https://www.dashboardblocks.com/r/radix/format.json",
    "https://www.dashboardblocks.com/r/radix/block-state.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/ai-usage.tsx",
      "content": "'use client'\n\nimport { useBlockState } from '@/registry/components/dashboardblocks/block-state'\nimport { formatCompact, formatCurrency } from '@/registry/lib/dashboardblocks/format'\n\nimport { cn } from '@/lib/utils'\n\ninterface TokenCounts {\n  cached?: number\n  input: number\n  output: number\n}\n\ninterface TokenPrices {\n  /** Per million cached input tokens. */\n  cached?: number\n  /** Per million input tokens. */\n  input: number\n  /** Per million output tokens. */\n  output: number\n}\n\nfunction getTokenCost({ cached = 0, input, output }: TokenCounts, prices: TokenPrices) {\n  return (\n    (input * prices.input +\n      output * prices.output +\n      cached * (prices.cached ?? prices.input)) /\n    1_000_000\n  )\n}\n\nfunction getCacheSavings(cachedTokens: number, prices: TokenPrices) {\n  return (cachedTokens * (prices.input - (prices.cached ?? prices.input))) / 1_000_000\n}\n\n/** Share of input tokens served from the cache, 0–1. */\nfunction getCacheHitRate({ cached = 0, input }: TokenCounts) {\n  const total = input + cached\n  return total > 0 ? cached / total : 0\n}\n\nfunction formatTokens(count: number) {\n  return formatCompact(count)\n}\n\nfunction formatUsd(value: number) {\n  return formatCurrency(value, { precision: 'fine' })\n}\n\nconst modelPalette = [\n  'var(--color-chart-2)',\n  'var(--color-chart-3)',\n  'var(--color-chart-4)',\n  'var(--color-chart-5)',\n  'var(--color-chart-1)',\n]\n\nconst tokenPartColors = {\n  cached: 'var(--color-chart-3)',\n  input: 'var(--color-chart-2)',\n  output: 'var(--color-chart-4)',\n} as const\n\ninterface TokenSplitBarProps {\n  className?: string\n  tokens: TokenCounts\n}\n\nfunction TokenSplitBar({ className, tokens }: TokenSplitBarProps) {\n  const state = useBlockState()\n  if (state === 'loading') {\n    return (\n      <div\n        aria-hidden\n        className={cn(\n          'bg-muted h-2.5 animate-pulse rounded-full motion-reduce:animate-none',\n          className,\n        )}\n      />\n    )\n  }\n  if (state) return null\n\n  const cached = tokens.cached ?? 0\n  const total = tokens.input + cached + tokens.output || 1\n  const parts = [\n    { color: tokenPartColors.input, value: tokens.input },\n    { color: tokenPartColors.cached, value: cached },\n    { color: tokenPartColors.output, value: tokens.output },\n  ]\n  return (\n    <div\n      aria-hidden\n      className={cn('flex h-2.5 gap-0.5 overflow-hidden rounded-full', className)}\n    >\n      {parts.map((part, index) =>\n        part.value > 0 ? (\n          <span\n            key={index}\n            className='h-full'\n            style={{\n              backgroundColor: part.color,\n              width: `${(part.value / total) * 100}%`,\n            }}\n          />\n        ) : null,\n      )}\n    </div>\n  )\n}\n\nexport {\n  TokenSplitBar,\n  formatTokens,\n  formatUsd,\n  getCacheHitRate,\n  getCacheSavings,\n  getTokenCost,\n  modelPalette,\n  tokenPartColors,\n}\n\nexport type { TokenCounts, TokenPrices, TokenSplitBarProps }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/ai-usage.tsx"
    }
  ],
  "type": "registry:component"
}
