{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "context-meter",
  "title": "Context Meter",
  "description": "How full the context window is, as a ring and a percentage, with a breakdown, Compact, token counts, cost and usage limits in a popover or in the page.",
  "dependencies": [
    "@kind-ui/agent-ui@0.9.0",
    "@ui-sdk/core@0.1.0-beta.17",
    "@ui-sdk/react@0.1.0-beta.17"
  ],
  "registryDependencies": [
    "@kind-ui/agent-ui-setup"
  ],
  "files": [
    {
      "path": "packages/agent-ui/src/react/context-meter.tsx",
      "content": "\"use client\";\n\nimport { contextMeterPrimitive, WORDS } from \"@kind-ui/agent-ui/core\";\nimport { Meter, MeterIndicator, MeterLabel, MeterTrack, MeterValue } from \"@ui-sdk/react/meter\";\nimport { createParts, renderElement } from \"@ui-sdk/react/primitive\";\nimport type { ComponentProps, CSSProperties } from \"react\";\n\nconst parts = createParts(contextMeterPrimitive, {\n  root: \"div\",\n  trigger: \"button\",\n  value: \"span\",\n  content: \"div\",\n  title: \"h2\",\n  description: \"p\",\n  rows: \"dl\",\n  viewport: \"div\",\n  compact: \"button\",\n  compacting: \"span\",\n  \"compacting-icon\": \"span\",\n  bar: \"div\",\n  breakdown: \"ul\",\n  limits: \"div\",\n});\n\nexport type ContextMeterProps = ComponentProps<typeof parts.Root>;\n\n/**\n * How much of the context window a conversation uses, and how much of the plan's limits: a ring and its percentage,\n * with details that open on hover, keyboard focus and press, or sit in the page with `layout=\"inline\"`. Any\n * `children` replace the default parts.\n */\nexport function ContextMeter({ children, ...props }: ContextMeterProps) {\n  return (\n    <parts.Root {...props}>\n      {children ?? (props.layout === \"inline\" ? DEFAULT_DETAILS : DEFAULT_PARTS)}\n    </parts.Root>\n  );\n}\n\nexport type ContextMeterTriggerProps = ComponentProps<typeof parts.Trigger>;\n\n/** Opens the details. Holds the meter unless you pass children. */\nexport function ContextMeterTrigger({ children = DEFAULT_VALUE, ...props }: ContextMeterTriggerProps) {\n  return <parts.Trigger {...props}>{children}</parts.Trigger>;\n}\n\nexport type ContextMeterValueProps = ComponentProps<typeof parts.Value>;\n\n/**\n * UI SDK's Meter: a ring and the percentage, after the limit it shows from 80% used, unless you pass children, a\n * function that gets the Meter's props.\n */\nexport function ContextMeterValue({\n  children = ({ label, caption, ...meter }) => (\n    <Meter {...meter} aria-label={label} data-agent-hidden=\"\">\n      <MeterTrack />\n      {caption ? <span data-context-meter-caption=\"\">{`${caption} `}</span> : null}\n      <MeterValue />\n    </Meter>\n  ),\n  ...props\n}: ContextMeterValueProps) {\n  return <parts.Value {...props}>{children}</parts.Value>;\n}\n\nexport type ContextMeterContentProps = ComponentProps<typeof parts.Content>;\n\n/**\n * The details: how full, Compact, the breakdown, the counts and the limits, unless you pass children. Leaves focus\n * on the trigger.\n */\nexport function ContextMeterContent({\n  children = DEFAULT_DETAILS,\n  render,\n  ...props\n}: ContextMeterContentProps) {\n  return (\n    <parts.Content\n      initialFocus=\"none\"\n      {...props}\n      // A sheet sits in a full-screen viewport, which renders only while the content presents as one.\n      render={(content, state) => {\n        const element = renderElement(\"div\", content, render, state);\n        return state.presentation === \"sheet\" ? <parts.Viewport>{element}</parts.Viewport> : element;\n      }}\n    >\n      {children}\n    </parts.Content>\n  );\n}\n\nexport type ContextMeterTitleProps = ComponentProps<typeof parts.Title>;\n\n/** How full, like \"86% full · Filling up\", unless you pass children. Names the details. */\nexport function ContextMeterTitle({\n  children = ({ fullText, levelText }) => (\n    <>\n      {fullText}\n      {levelText ? <span data-context-meter-level=\"\">{` · ${levelText}`}</span> : null}\n    </>\n  ),\n  ...props\n}: ContextMeterTitleProps) {\n  return <parts.Title {...props}>{children}</parts.Title>;\n}\n\nexport type ContextMeterDescriptionProps = ComponentProps<typeof parts.Description>;\n\n/** Used and total tokens, unless you pass children. Describes the details. */\nexport function ContextMeterDescription({\n  children = ({ countText }) => countText,\n  ...props\n}: ContextMeterDescriptionProps) {\n  return <parts.Description {...props}>{children}</parts.Description>;\n}\n\nexport type ContextMeterRowsProps = ComponentProps<typeof parts.Rows>;\n\n/** Each count and the cost supplied, unless you pass children. Rendered only when there's one. */\nexport function ContextMeterRows({\n  children = ({ rows }) =>\n    rows.map(({ label, value }) => (\n      <div key={label}>\n        <dt>{label}</dt>\n        <dd>{value}</dd>\n      </div>\n    )),\n  ...props\n}: ContextMeterRowsProps) {\n  return <parts.Rows {...props}>{children}</parts.Rows>;\n}\n\nexport type ContextMeterCompactProps = ComponentProps<typeof parts.Compact>;\n\n/** Compacts the conversation. Rendered while `onCompact` is set and nothing is compacting. */\nexport function ContextMeterCompact({ children = WORDS.compact, ...props }: ContextMeterCompactProps) {\n  return <parts.Compact {...props}>{children}</parts.Compact>;\n}\n\nexport type ContextMeterCompactingProps = ComponentProps<typeof parts.Compacting>;\n\n/** A running mark and \"Compacting\", in Compact's place while the conversation compacts. */\nexport function ContextMeterCompacting({\n  children = ({ text }) => (\n    <>\n      <parts.CompactingIcon />\n      {text}\n    </>\n  ),\n  ...props\n}: ContextMeterCompactingProps) {\n  return <parts.Compacting {...props}>{children}</parts.Compacting>;\n}\n\nexport type ContextMeterBarProps = ComponentProps<typeof parts.Bar>;\n\n/** The breakdown as one stacked bar, with a tick at `compactAt`. One image, named by the breakdown as a sentence. */\nexport function ContextMeterBar({\n  children = ({ slices }) =>\n    slices.map((slice) =>\n      slice.color ? (\n        <span\n          key={slice.id}\n          data-context-meter-segment=\"\"\n          data-color={slice.color}\n          style={{ width: slice.width }}\n        />\n      ) : null,\n    ),\n  ...props\n}: ContextMeterBarProps) {\n  return <parts.Bar {...props}>{children}</parts.Bar>;\n}\n\nexport type ContextMeterBreakdownProps = ComponentProps<typeof parts.Breakdown>;\n\n/** A row per slice of the breakdown: its swatch, label, tokens and share, then Free space. */\nexport function ContextMeterBreakdown({\n  children = ({ slices }) =>\n    slices.map((slice) => (\n      <li key={slice.id} data-color={slice.color}>\n        <span data-context-meter-swatch=\"\" aria-hidden=\"true\" />\n        <span data-context-meter-label=\"\">{slice.label}</span>\n        <span data-context-meter-tokens=\"\">{slice.value}</span>\n        <span data-context-meter-share=\"\">{slice.percent}</span>\n      </li>\n    )),\n  ...props\n}: ContextMeterBreakdownProps) {\n  return <parts.Breakdown {...props}>{children}</parts.Breakdown>;\n}\n\nexport type ContextMeterLimitsProps = ComponentProps<typeof parts.Limits>;\n\n/** A UI SDK Meter per limit, with its share used, reset and pace. Rendered only with `limits`. */\nexport function ContextMeterLimits({\n  children = ({ limits }) =>\n    limits.map((limit) => (\n      <Meter\n        key={limit.id}\n        value={limit.value}\n        max={limit.max}\n        getValueLabel={() => limit.valueText}\n        data-agent-hidden=\"\"\n        data-level={limit.low ? \"high\" : \"normal\"}\n      >\n        <MeterLabel>{limit.label}</MeterLabel>\n        <MeterValue>{() => limit.percent}</MeterValue>\n        <MeterTrack\n          data-pace={limit.pace === undefined ? undefined : \"\"}\n          style={\n            limit.pace === undefined\n              ? undefined\n              : ({ \"--kind-limit-pace\": `${limit.pace * 100}%` } as CSSProperties)\n          }\n        >\n          <MeterIndicator />\n        </MeterTrack>\n        {limit.detail ? <span data-context-meter-detail=\"\">{limit.detail}</span> : null}\n      </Meter>\n    )),\n  ...props\n}: ContextMeterLimitsProps) {\n  return <parts.Limits {...props}>{children}</parts.Limits>;\n}\n\n// Shared, so an update doesn't render the default parts' wrappers again.\nconst DEFAULT_VALUE = <ContextMeterValue />;\n\nconst DEFAULT_DETAILS = (\n  <>\n    <ContextMeterTitle />\n    <ContextMeterCompact />\n    <ContextMeterCompacting />\n    <ContextMeterDescription />\n    <ContextMeterBar />\n    <ContextMeterBreakdown />\n    <ContextMeterRows />\n    <ContextMeterLimits />\n  </>\n);\n\nconst DEFAULT_PARTS = (\n  <>\n    <ContextMeterTrigger />\n    <ContextMeterContent />\n  </>\n);\n",
      "type": "registry:ui",
      "target": "@ui/context-meter.tsx"
    }
  ],
  "meta": {
    "layer": "react"
  },
  "type": "registry:ui"
}
