{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "context-meter-solid",
  "title": "Context Meter (Solid)",
  "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/solid@0.1.0-beta.17"
  ],
  "registryDependencies": [
    "@kind-ui/agent-ui-setup"
  ],
  "files": [
    {
      "path": "packages/agent-ui/src/solid/context-meter.tsx",
      "content": "import {\n  type ContextLimitRow,\n  type ContextMeterBarState,\n  type ContextMeterValueState,\n  type ContextRow,\n  contextMeterPrimitive,\n  WORDS,\n} from \"@kind-ui/agent-ui/core\";\nimport type { ComponentProps, JSX } from \"@solidjs/web\";\nimport { Meter, MeterIndicator, MeterLabel, MeterTrack, MeterValue } from \"@ui-sdk/solid/meter\";\nimport { createParts } from \"@ui-sdk/solid/primitive\";\nimport { For, omit, Show } from \"solid-js\";\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(props: ContextMeterProps) {\n  return (\n    <parts.Root {...omit(props, \"children\")}>\n      {props.children ?? (props.layout === \"inline\" ? <DefaultDetails /> : <DefaultParts />)}\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(props: ContextMeterTriggerProps) {\n  return (\n    <parts.Trigger {...omit(props, \"children\")}>{props.children ?? <ContextMeterValue />}</parts.Trigger>\n  );\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(props: ContextMeterValueProps) {\n  return (\n    <parts.Value {...omit(props, \"children\")}>\n      {props.children ??\n        ((meter: ContextMeterValueState) => (\n          <Meter\n            value={meter.value}\n            max={meter.max}\n            locale={meter.locale}\n            getValueLabel={meter.getValueLabel}\n            aria-label={meter.label}\n            data-agent-hidden=\"\"\n          >\n            <MeterTrack />\n            <Show when={meter.caption}>\n              <span data-context-meter-caption=\"\">{`${meter.caption} `}</span>\n            </Show>\n            <MeterValue />\n          </Meter>\n        ))}\n    </parts.Value>\n  );\n}\n\nexport type ContextMeterContentProps = ComponentProps<typeof parts.Content>;\n\ntype Render = (props: Record<string, unknown>, state: { presentation?: string }) => JSX.Element;\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(props: ContextMeterContentProps) {\n  const render = (content: Record<string, unknown>, state: { presentation?: string }) => {\n    const element = () => {\n      const own = props.render as Render | undefined;\n      return own ? own(content, state) : <div {...content} />;\n    };\n    // A sheet sits in a full-screen viewport, which renders only while the content presents as one.\n    return (\n      <Show when={state.presentation === \"sheet\"} fallback={element()}>\n        <parts.Viewport>{element()}</parts.Viewport>\n      </Show>\n    );\n  };\n  return (\n    <parts.Content\n      initialFocus=\"none\"\n      {...omit(props, \"children\", \"render\")}\n      render={render as ContextMeterContentProps[\"render\"]}\n    >\n      {props.children ?? <DefaultDetails />}\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(props: ContextMeterTitleProps) {\n  return (\n    <parts.Title {...omit(props, \"children\")}>\n      {props.children ??\n        ((state: { fullText: string; levelText: string | undefined }) => (\n          <>\n            {state.fullText}\n            <Show when={state.levelText}>\n              <span data-context-meter-level=\"\">{` · ${state.levelText}`}</span>\n            </Show>\n          </>\n        ))}\n    </parts.Title>\n  );\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(props: ContextMeterDescriptionProps) {\n  return (\n    <parts.Description {...omit(props, \"children\")}>\n      {props.children ?? ((state: { countText: string }) => state.countText)}\n    </parts.Description>\n  );\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(props: ContextMeterRowsProps) {\n  return (\n    <parts.Rows {...omit(props, \"children\")}>\n      {props.children ??\n        ((state: { rows: ContextRow[] }) => (\n          <For each={state.rows} keyed={(row) => row.label}>\n            {(row) => (\n              <div>\n                <dt>{row().label}</dt>\n                <dd>{row().value}</dd>\n              </div>\n            )}\n          </For>\n        ))}\n    </parts.Rows>\n  );\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(props: ContextMeterCompactProps) {\n  return <parts.Compact {...omit(props, \"children\")}>{props.children ?? WORDS.compact}</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(props: ContextMeterCompactingProps) {\n  return (\n    <parts.Compacting {...omit(props, \"children\")}>\n      {props.children ??\n        ((state: { text: string }) => (\n          <>\n            <parts.CompactingIcon />\n            {state.text}\n          </>\n        ))}\n    </parts.Compacting>\n  );\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(props: ContextMeterBarProps) {\n  return (\n    <parts.Bar {...omit(props, \"children\")}>\n      {props.children ??\n        ((state: ContextMeterBarState) => (\n          <For each={state.slices} keyed={(slice) => slice.id}>\n            {(slice) => (\n              <Show when={slice().color}>\n                <span\n                  data-context-meter-segment=\"\"\n                  data-color={slice().color}\n                  style={{ width: slice().width }}\n                />\n              </Show>\n            )}\n          </For>\n        ))}\n    </parts.Bar>\n  );\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(props: ContextMeterBreakdownProps) {\n  return (\n    <parts.Breakdown {...omit(props, \"children\")}>\n      {props.children ??\n        ((state: ContextMeterBarState) => (\n          <For each={state.slices} keyed={(slice) => slice.id}>\n            {(slice) => (\n              <li 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          </For>\n        ))}\n    </parts.Breakdown>\n  );\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(props: ContextMeterLimitsProps) {\n  return (\n    <parts.Limits {...omit(props, \"children\")}>\n      {props.children ??\n        ((state: { limits: ContextLimitRow[] }) => (\n          <For each={state.limits} keyed={(limit) => limit.id}>\n            {(limit) => (\n              <Meter\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 ?? 0) * 100}%` }\n                  }\n                >\n                  <MeterIndicator />\n                </MeterTrack>\n                <Show when={limit().detail}>\n                  <span data-context-meter-detail=\"\">{limit().detail}</span>\n                </Show>\n              </Meter>\n            )}\n          </For>\n        ))}\n    </parts.Limits>\n  );\n}\n\nconst DefaultDetails = () => (\n  <>\n    <ContextMeterTitle />\n    <ContextMeterCompact />\n    <ContextMeterCompacting />\n    <ContextMeterDescription />\n    <ContextMeterBar />\n    <ContextMeterBreakdown />\n    <ContextMeterRows />\n    <ContextMeterLimits />\n  </>\n);\n\nconst DefaultParts = () => (\n  <>\n    <ContextMeterTrigger />\n    <ContextMeterContent />\n  </>\n);\n",
      "type": "registry:ui",
      "target": "@ui/solid/context-meter.tsx"
    }
  ],
  "meta": {
    "layer": "solid"
  },
  "type": "registry:ui"
}
