{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "metrics",
  "title": "Metrics",
  "description": "Metrics dashboard block with a Performance/Usage tab navigator: per-processor latency tiles and charts, plus running token/character/audio usage totals, on the stock shadcn chart (recharts).",
  "dependencies": [
    "recharts@^3.8.0"
  ],
  "registryDependencies": [
    "chart",
    "tabs",
    "@pipecat/metric",
    "@pipecat/use-pipecat-metrics"
  ],
  "files": [
    {
      "path": "src/blocks/metrics/metrics.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nimport {\n  MetricsPerformance,\n  MetricsPerformanceView,\n  type MetricsPerformanceProps,\n  type MetricsPerformanceViewProps,\n} from \"@/components/pipecat/metrics/performance\";\nimport {\n  MetricsUsage,\n  MetricsUsageView,\n  type MetricsUsageProps,\n  type MetricsUsageViewProps,\n} from \"@/components/pipecat/metrics/usage\";\nimport { Tabs, TabsContent, TabsList, TabsTrigger } from \"@/components/ui/tabs\";\nimport type { MetricSeries, TokenTotals } from \"@/hooks/use-pipecat-metrics\";\nimport { cn } from \"@/lib/utils\";\n\nexport type MetricsTab = \"performance\" | \"usage\";\n\nexport interface MetricsViewProps {\n  /** Metric series for both sections (see use-pipecat-metrics). */\n  series: MetricSeries[];\n  /** Running token totals for the usage section. */\n  tokens?: TokenTotals;\n  /** Which tab is selected initially (default \"performance\"). */\n  defaultTab?: MetricsTab;\n  /** Overrides for the performance section. */\n  performanceProps?: Omit<MetricsPerformanceViewProps, \"series\">;\n  /** Overrides for the usage section. */\n  usageProps?: Omit<MetricsUsageViewProps, \"series\" | \"tokens\">;\n  className?: string;\n}\n\nfunction MetricsTabs({\n  defaultTab = \"performance\",\n  className,\n  performance,\n  usage,\n}: {\n  defaultTab?: MetricsTab;\n  className?: string;\n  performance: React.ReactNode;\n  usage: React.ReactNode;\n}) {\n  return (\n    <Tabs\n      data-slot=\"metrics\"\n      defaultValue={defaultTab}\n      className={cn(\"flex flex-col gap-4\", className)}\n    >\n      <TabsList>\n        <TabsTrigger value=\"performance\">Performance</TabsTrigger>\n        <TabsTrigger value=\"usage\">Usage</TabsTrigger>\n      </TabsList>\n      <TabsContent value=\"performance\">{performance}</TabsContent>\n      <TabsContent value=\"usage\">{usage}</TabsContent>\n    </Tabs>\n  );\n}\n\n/** Props-driven performance and usage tabs. */\nexport function MetricsView({\n  series,\n  tokens,\n  defaultTab,\n  performanceProps,\n  usageProps,\n  className,\n}: MetricsViewProps) {\n  return (\n    <MetricsTabs\n      defaultTab={defaultTab}\n      className={className}\n      performance={\n        <MetricsPerformanceView series={series} {...performanceProps} />\n      }\n      usage={\n        <MetricsUsageView series={series} tokens={tokens} {...usageProps} />\n      }\n    />\n  );\n}\n\nexport interface MetricsProps {\n  /** Which tab is selected initially (default \"performance\"). */\n  defaultTab?: MetricsTab;\n  /** Overrides for the performance section. */\n  performanceProps?: MetricsPerformanceProps;\n  /** Overrides for the usage section. */\n  usageProps?: MetricsUsageProps;\n  className?: string;\n}\n\n/** Requires PipecatClientProvider. Keeps collection active while individual tabs are unmounted. */\nexport function Metrics({\n  defaultTab,\n  performanceProps,\n  usageProps,\n  className,\n}: MetricsProps) {\n  return (\n    <MetricsTabs\n      defaultTab={defaultTab}\n      className={className}\n      performance={<MetricsPerformance {...performanceProps} />}\n      usage={<MetricsUsage {...usageProps} />}\n    />\n  );\n}\n",
      "type": "registry:block",
      "target": "components/pipecat/metrics/metrics.tsx"
    },
    {
      "path": "src/blocks/metrics/performance.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nimport { Metric } from \"@/components/pipecat/metric\";\nimport {\n  METRIC_CATEGORY_TITLES,\n  METRIC_CATEGORY_UNITS,\n  MetricSeriesChart,\n  MetricsEmpty,\n} from \"@/components/pipecat/metrics/chart\";\nimport {\n  usePipecatMetrics,\n  type MetricSeries,\n} from \"@/hooks/use-pipecat-metrics\";\nimport { cn } from \"@/lib/utils\";\n\nexport type MetricsPerformanceCategory = \"ttfb\" | \"ttfa\" | \"processing\";\n\nexport interface MetricsPerformanceViewProps {\n  /** Metric series; non-performance categories are ignored. */\n  series: MetricSeries[];\n  /** Which categories get tiles and charts (default [\"ttfb\"]). */\n  categories?: MetricsPerformanceCategory[];\n  /** Hides the tile grid. Default false. */\n  noTiles?: boolean;\n  /** Hides the charts. Default false. */\n  noCharts?: boolean;\n  /** Processor names excluded from tiles and charts. */\n  ignoreProcessors?: string[];\n  /** Rendered when there is nothing to show yet. */\n  empty?: React.ReactNode;\n  className?: string;\n}\n\n/** Latency tiles and charts in milliseconds. ttfa requires Pipecat server ≥1.7. */\nexport function MetricsPerformanceView({\n  series,\n  categories = [\"ttfb\"],\n  noTiles = false,\n  noCharts = false,\n  ignoreProcessors,\n  empty,\n  className,\n}: MetricsPerformanceViewProps) {\n  const visible = React.useMemo(() => {\n    const bySelection = series.filter((s) =>\n      (categories as string[]).includes(s.category),\n    );\n    return ignoreProcessors?.length\n      ? bySelection.filter((s) => !ignoreProcessors.includes(s.processor))\n      : bySelection;\n  }, [series, categories, ignoreProcessors]);\n\n  if (visible.length === 0) {\n    return (\n      <MetricsEmpty slot=\"metrics-performance\" className={className}>\n        {empty}\n      </MetricsEmpty>\n    );\n  }\n\n  return (\n    <div\n      data-slot=\"metrics-performance\"\n      data-state=\"live\"\n      className={cn(\"@container/metrics flex flex-col gap-6\", className)}\n    >\n      {!noTiles && (\n        <div\n          data-slot=\"metrics-tiles\"\n          className=\"grid grid-cols-2 gap-4 @md/metrics:grid-cols-3 @xl/metrics:grid-cols-4\"\n        >\n          {visible.map((s) => (\n            <Metric\n              key={`${s.category}:${s.processor}`}\n              label={`${METRIC_CATEGORY_TITLES[s.category]} · ${s.processor}`}\n              value={s.latest * 1000}\n              unit=\"ms\"\n            />\n          ))}\n        </div>\n      )}\n\n      {!noCharts &&\n        categories.map((category) => {\n          const categorySeries = visible.filter((s) => s.category === category);\n          if (categorySeries.length === 0) return null;\n          return (\n            <div\n              key={category}\n              data-slot=\"metrics-chart\"\n              className=\"flex flex-col gap-2\"\n            >\n              <h3 className=\"text-muted-foreground text-xs font-medium\">\n                {METRIC_CATEGORY_TITLES[category]}\n                {METRIC_CATEGORY_UNITS[category]}\n              </h3>\n              <MetricSeriesChart series={categorySeries} scale={1000} />\n            </div>\n          );\n        })}\n    </div>\n  );\n}\n\nexport type MetricsPerformanceProps = Omit<\n  MetricsPerformanceViewProps,\n  \"series\"\n>;\n\n/**\n * Performance metrics wired to the shared RTVI metrics store — populates\n * live and resets with each new session. Must be rendered inside a\n * PipecatClientProvider.\n */\nexport function MetricsPerformance(props: MetricsPerformanceProps) {\n  const { series } = usePipecatMetrics();\n  return <MetricsPerformanceView series={series} {...props} />;\n}\n",
      "type": "registry:component",
      "target": "components/pipecat/metrics/performance.tsx"
    },
    {
      "path": "src/blocks/metrics/usage.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nimport { Metric } from \"@/components/pipecat/metric\";\nimport {\n  METRIC_CATEGORY_TITLES,\n  METRIC_CATEGORY_UNITS,\n  MetricSeriesChart,\n  MetricsEmpty,\n} from \"@/components/pipecat/metrics/chart\";\nimport {\n  usePipecatMetrics,\n  type MetricSeries,\n  type TokenTotals,\n} from \"@/hooks/use-pipecat-metrics\";\nimport { cn } from \"@/lib/utils\";\n\nexport type MetricsUsageCategory = \"characters\" | \"stt_usage\";\n\nconst USAGE_UNITS: Record<MetricsUsageCategory, string | undefined> = {\n  characters: undefined,\n  stt_usage: \"s\",\n};\n\nexport interface MetricsUsageViewProps {\n  /** Metric series; non-usage categories are ignored. */\n  series: MetricSeries[];\n  /** Running token totals; omit to hide the token tiles. */\n  tokens?: TokenTotals;\n  /** Which categories get charts (default both). */\n  categories?: MetricsUsageCategory[];\n  /** Hides the tile grid. Default false. */\n  noTiles?: boolean;\n  /** Hides the charts. Default false. */\n  noCharts?: boolean;\n  /** Processor names excluded from tiles and charts. */\n  ignoreProcessors?: string[];\n  /** Rendered when there is nothing to show yet. */\n  empty?: React.ReactNode;\n  className?: string;\n}\n\n/** Session usage totals. STT audio requires Pipecat server ≥1.7 with usage metrics enabled. */\nexport function MetricsUsageView({\n  series,\n  tokens,\n  categories = [\"characters\", \"stt_usage\"],\n  noTiles = false,\n  noCharts = false,\n  ignoreProcessors,\n  empty,\n  className,\n}: MetricsUsageViewProps) {\n  const visible = React.useMemo(() => {\n    const bySelection = series.filter(\n      (s) => s.category === \"characters\" || s.category === \"stt_usage\",\n    );\n    return ignoreProcessors?.length\n      ? bySelection.filter((s) => !ignoreProcessors.includes(s.processor))\n      : bySelection;\n  }, [series, ignoreProcessors]);\n\n  if (visible.length === 0 && !tokens) {\n    return (\n      <MetricsEmpty slot=\"metrics-usage\" className={className}>\n        {empty}\n      </MetricsEmpty>\n    );\n  }\n\n  return (\n    <div\n      data-slot=\"metrics-usage\"\n      data-state=\"live\"\n      className={cn(\"@container/metrics flex flex-col gap-6\", className)}\n    >\n      {!noTiles && (\n        <div\n          data-slot=\"metrics-tiles\"\n          className=\"grid grid-cols-2 gap-4 @md/metrics:grid-cols-3 @xl/metrics:grid-cols-4\"\n        >\n          {tokens ? (\n            <>\n              <Metric label=\"Prompt tokens\" value={tokens.prompt} />\n              <Metric label=\"Completion tokens\" value={tokens.completion} />\n              <Metric label=\"Total tokens\" value={tokens.total} />\n              {tokens.cacheRead > 0 && (\n                <Metric label=\"Cache read tokens\" value={tokens.cacheRead} />\n              )}\n              {tokens.reasoning > 0 && (\n                <Metric label=\"Reasoning tokens\" value={tokens.reasoning} />\n              )}\n            </>\n          ) : null}\n          {visible.map((s) => (\n            <Metric\n              key={`${s.category}:${s.processor}`}\n              label={`${METRIC_CATEGORY_TITLES[s.category]} · ${s.processor}`}\n              value={s.latest}\n              unit={USAGE_UNITS[s.category as MetricsUsageCategory]}\n            />\n          ))}\n        </div>\n      )}\n\n      {!noCharts &&\n        categories.map((category) => {\n          const categorySeries = visible.filter((s) => s.category === category);\n          if (categorySeries.length === 0) return null;\n          return (\n            <div\n              key={category}\n              data-slot=\"metrics-chart\"\n              className=\"flex flex-col gap-2\"\n            >\n              <h3 className=\"text-muted-foreground text-xs font-medium\">\n                {METRIC_CATEGORY_TITLES[category]}\n                {METRIC_CATEGORY_UNITS[category]}\n              </h3>\n              <MetricSeriesChart series={categorySeries} />\n            </div>\n          );\n        })}\n    </div>\n  );\n}\n\nexport type MetricsUsageProps = Omit<\n  MetricsUsageViewProps,\n  \"series\" | \"tokens\"\n>;\n\n/**\n * Usage metrics wired to the shared RTVI metrics store — running totals\n * populate live and reset with each new session. Must be rendered inside a\n * PipecatClientProvider.\n */\nexport function MetricsUsage(props: MetricsUsageProps) {\n  const { series, tokens, hasTokens } = usePipecatMetrics();\n  return (\n    <MetricsUsageView\n      series={series}\n      tokens={hasTokens ? tokens : undefined}\n      {...props}\n    />\n  );\n}\n",
      "type": "registry:component",
      "target": "components/pipecat/metrics/usage.tsx"
    },
    {
      "path": "src/blocks/metrics/chart.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { CartesianGrid, Line, LineChart, XAxis, YAxis } from \"recharts\";\n\nimport type { MetricCategory, MetricSeries } from \"@/hooks/use-pipecat-metrics\";\nimport {\n  ChartContainer,\n  ChartLegend,\n  ChartLegendContent,\n  ChartTooltip,\n  ChartTooltipContent,\n  type ChartConfig,\n} from \"@/components/ui/chart\";\nimport { cn } from \"@/lib/utils\";\n\n/** Display titles shared by the metrics blocks. */\nexport const METRIC_CATEGORY_TITLES: Record<MetricCategory, string> = {\n  ttfb: \"TTFB\",\n  ttfa: \"TTFA\",\n  processing: \"Processing time\",\n  characters: \"TTS characters\",\n  stt_usage: \"STT audio\",\n};\n\n/** Chart heading unit suffix per category. */\nexport const METRIC_CATEGORY_UNITS: Record<MetricCategory, string> = {\n  ttfb: \" (ms)\",\n  ttfa: \" (ms)\",\n  processing: \" (ms)\",\n  characters: \"\",\n  stt_usage: \" (s)\",\n};\n\n/** Processor names become ChartConfig keys, which become CSS variable names. */\nfunction sanitizeKey(processor: string): string {\n  return processor.replace(/[^a-zA-Z0-9_-]/g, \"-\");\n}\n\nfunction formatTime(time: number): string {\n  return new Date(time).toLocaleTimeString(undefined, { hour12: false });\n}\n\n/**\n * Merges per-processor point series into recharts rows keyed by the metrics\n * batch timestamp (one RTVI metrics event carries all processors at once, so\n * timestamps align across series).\n */\nfunction chartRows(\n  seriesList: MetricSeries[],\n  scale: number,\n): Array<Record<string, number>> {\n  const rows = new Map<number, Record<string, number>>();\n  for (const series of seriesList) {\n    const key = sanitizeKey(series.processor);\n    for (const point of series.points) {\n      const row = rows.get(point.time) ?? { time: point.time };\n      row[key] = point.value * scale;\n      rows.set(point.time, row);\n    }\n  }\n  return [...rows.values()].sort((a, b) => a.time! - b.time!);\n}\n\nexport interface MetricSeriesChartProps {\n  /** Series drawn as one line per processor. */\n  series: MetricSeries[];\n  /** Multiplier applied to raw values before plotting (e.g. 1000 for s → ms). */\n  scale?: number;\n  className?: string;\n}\n\n/** Linear interpolation preserves sparse per-turn samples; colors use the chart palette. */\nexport function MetricSeriesChart({\n  series,\n  scale = 1,\n  className,\n}: MetricSeriesChartProps) {\n  const rows = chartRows(series, scale);\n  const config: ChartConfig = {};\n  series.forEach((s, index) => {\n    config[sanitizeKey(s.processor)] = {\n      label: s.processor,\n      color: `var(--chart-${(index % 5) + 1})`,\n    };\n  });\n\n  return (\n    <ChartContainer config={config} className={cn(\"h-48 w-full\", className)}>\n      <LineChart data={rows} accessibilityLayer>\n        <CartesianGrid vertical={false} />\n        <XAxis\n          dataKey=\"time\"\n          tickFormatter={formatTime}\n          tickLine={false}\n          axisLine={false}\n          tickMargin={8}\n          minTickGap={32}\n        />\n        <YAxis width={40} tickLine={false} axisLine={false} tickMargin={4} />\n        <ChartTooltip\n          content={\n            <ChartTooltipContent\n              labelFormatter={(_, payload) => {\n                const time = payload?.[0]?.payload?.time;\n                return typeof time === \"number\" ? formatTime(time) : \"\";\n              }}\n            />\n          }\n        />\n        {series.length > 1 && <ChartLegend content={<ChartLegendContent />} />}\n        {series.map((s) => {\n          const key = sanitizeKey(s.processor);\n          return (\n            <Line\n              key={key}\n              dataKey={key}\n              type=\"linear\"\n              stroke={`var(--color-${key})`}\n              strokeWidth={2}\n              dot={{ r: 2 }}\n              isAnimationActive={false}\n              connectNulls\n            />\n          );\n        })}\n      </LineChart>\n    </ChartContainer>\n  );\n}\n\nexport interface MetricsEmptyProps {\n  children?: React.ReactNode;\n  /** data-slot for the empty container, e.g. \"metrics-performance\". */\n  slot: string;\n  className?: string;\n}\n\n/** Shared empty state for the metrics blocks. */\nexport function MetricsEmpty({ children, slot, className }: MetricsEmptyProps) {\n  return (\n    <div\n      data-slot={slot}\n      data-state=\"empty\"\n      className={cn(\n        \"text-muted-foreground flex h-full min-h-24 flex-col items-center justify-center gap-1 text-sm\",\n        className,\n      )}\n    >\n      {children ?? (\n        <>\n          <span>No metrics yet</span>\n          <span className=\"text-xs\">\n            Metrics stream in once an agent session is live.\n          </span>\n        </>\n      )}\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/pipecat/metrics/chart.tsx"
    }
  ],
  "docs": "Metrics reads the shared use-pipecat-metrics store inside a PipecatClientProvider; MetricsView takes fixtures. MetricsPerformance and MetricsUsage also export standalone. Chrome-free — wrap in your own card or panel.",
  "categories": [
    "voice",
    "blocks"
  ],
  "type": "registry:block"
}