{ "name": "confidence-meter", "type": "registry:ui", "title": "Confidence Meter", "description": "How sure a model is, in five steps. Segmented on purpose — a smooth bar invites reading 0.834 as different from 0.851, which is not what a calibration score supports.", "category": "AI", "dependencies": [], "registryDependencies": [ "lib-motion", "lib-utils" ], "files": [ { "path": "components/ui/confidence-meter.tsx", "type": "registry:ui", "content": "import type { ComponentProps, ReactNode } from 'react'\nimport { enterFade } from '@/lib/motion'\nimport { cn } from '@/lib/utils'\n\n/**\n * A model's confidence in an answer.\n *\n * Segmented rather than continuous, deliberately. A smooth bar invites reading\n * 0.834 as meaningfully different from 0.851, which is not what a calibration\n * score supports. Five steps say \"fairly confident\" and stop there.\n *\n * The band label is the accessible name, so a screen reader hears \"confidence:\n * high\" instead of a percentage that implies more precision than exists.\n */\nconst BANDS = [\n { max: 0.2, label: 'Very low', tone: 'bg-[var(--destructive)]' },\n { max: 0.4, label: 'Low', tone: 'bg-[var(--destructive)]' },\n { max: 0.6, label: 'Moderate', tone: 'bg-[var(--amber)]' },\n { max: 0.8, label: 'High', tone: 'bg-[var(--green)]' },\n { max: 1.01, label: 'Very high', tone: 'bg-[var(--green)]' },\n] as const\n\nconst SEGMENTS = 5\n\nfunction ConfidenceMeter({\n value,\n label = 'Confidence',\n showLabel = true,\n hint,\n size = 'default',\n className,\n ...props\n}: Omit, 'children'> & {\n /** 0 to 1. */\n value: number\n label?: ReactNode\n showLabel?: boolean\n hint?: ReactNode\n size?: 'sm' | 'default'\n}) {\n const ratio = Math.max(0, Math.min(value, 1))\n const band = BANDS.find((entry) => ratio < entry.max) ?? BANDS[BANDS.length - 1]\n const filled = Math.max(1, Math.ceil(ratio * SEGMENTS))\n\n return (\n \n {showLabel && (\n
\n {label}\n {band.label}\n
\n )}\n\n \n {Array.from({ length: SEGMENTS }, (_, index) => (\n \n ))}\n \n\n {hint &&

{hint}

}\n \n )\n}\n\nexport { ConfidenceMeter }\n" } ] }