{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ai-assistant-01",
  "description": "An assistant docked beside the page with suggested prompts, the page as context, and New conversation and Close buttons.",
  "registryDependencies": [
    "button",
    "https://www.dashboardblocks.com/r/radix/ai-assistant.json",
    "https://www.dashboardblocks.com/r/radix/ai-chat.json",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/format.json",
    "https://www.dashboardblocks.com/r/radix/stat-group.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/ai-assistant/ai-assistant-01.tsx",
      "content": "'use client'\n\nimport {\n  ChatContextChip,\n  ChatPanel,\n  type SuggestedPrompt,\n} from '@/registry/components/dashboardblocks/ai-assistant'\nimport type { AIChat } from '@/registry/components/dashboardblocks/ai-message'\nimport type { AIToolLabel } from '@/registry/components/dashboardblocks/ai-parts'\nimport {\n  BlockReady,\n  BlockStateProvider,\n  BlockStateRows,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  Stat,\n  StatChange,\n  StatGroup,\n  StatLabel,\n  type StatMetric,\n  StatSparkline,\n  StatValue,\n  formatStatValue,\n  getStatPlaceholders,\n} from '@/registry/components/dashboardblocks/stat-group'\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport { formatCurrency, formatPercent } from '@/registry/lib/dashboardblocks/format'\nimport { useEffect, useId, useRef, useState } from 'react'\n\nimport { Button } from '@/components/ui/button'\n\ninterface Metric extends StatMetric {\n  /** Oldest first, ending with `value`. */\n  history: number[]\n}\n\ninterface Account {\n  mrr: number\n  name: string\n  plan: string\n}\n\ninterface AiAssistant1Props extends BlockStateProps {\n  accounts?: Account[]\n  /**\n   * The chat the panel runs: `useChat()` from `@ai-sdk/react`, or `useChatStream` for any other stream.\n   * While the page shows in the message box, each question carries `metadata: { context }`, so the server knows to add the page's data.\n   */\n  chat: AIChat\n  /** Follows each previous value, such as `last month`. */\n  comparison: string\n  context: string\n  defaultOpen?: boolean\n  description: string\n  /** Names each point of a metric's history, oldest first. */\n  historyLabels: string[]\n  /** Leave out, or pass none, to show the empty state. */\n  metrics?: Metric[]\n  suggestions: SuggestedPrompt[]\n  title: string\n  /** What each tool is called, by its name, or `{ running, done }` for what it's doing while it runs. Others read as their name in words. */\n  toolLabels?: Record<string, AIToolLabel>\n}\n\nconst asCurrency = (value: number) => formatCurrency(value)\nconst asPercent = (value: number) => formatPercent(value / 100)\n\nconst exampleProps: Omit<AiAssistant1Props, 'chat'> = {\n  accounts: [\n    { mrr: 12_400, name: 'Northwind Logistics', plan: 'Enterprise' },\n    { mrr: 8_950, name: 'Helio Health', plan: 'Enterprise' },\n    { mrr: 4_200, name: 'Brightline Studio', plan: 'Growth' },\n    { mrr: 3_780, name: 'Kestrel Analytics', plan: 'Growth' },\n    { mrr: 2_640, name: 'Oakridge Dental Group', plan: 'Growth' },\n  ],\n  comparison: 'last month',\n  context: 'Revenue, last 30 days',\n  defaultOpen: true,\n  description: 'Recurring revenue and customers over the last 30 days.',\n  historyLabels: ['Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep'],\n  metrics: [\n    {\n      formatter: asCurrency,\n      history: [151_200, 158_900, 164_400, 171_050, 176_890, 184_320],\n      key: 'mrr',\n      label: 'MRR',\n      previous: 176_890,\n      value: 184_320,\n    },\n    {\n      history: [241, 266, 258, 289, 274, 312],\n      key: 'customers',\n      label: 'New customers',\n      previous: 274,\n      value: 312,\n    },\n    {\n      changeType: 'points',\n      formatter: asPercent,\n      goodDirection: 'down',\n      history: [1.6, 1.5, 1.3, 1.5, 1.4, 1.8],\n      key: 'churn',\n      label: 'Churn',\n      previous: 1.4,\n      value: 1.8,\n    },\n    {\n      changeType: 'points',\n      formatter: asPercent,\n      history: [106, 107, 109, 108, 110, 112],\n      key: 'retention',\n      label: 'Net retention',\n      previous: 110,\n      value: 112,\n    },\n  ],\n  suggestions: [\n    {\n      icon: (\n        <IconPlaceholder\n          lucide='TrendingDownIcon'\n          tabler='IconTrendingDown'\n          hugeicons='ChartDownIcon'\n          phosphor='TrendDownIcon'\n          remixicon='RiArrowDownLine'\n        />\n      ),\n      label: 'Why did churn go up this month?',\n    },\n    {\n      icon: (\n        <IconPlaceholder\n          lucide='TriangleAlertIcon'\n          tabler='IconAlertTriangle'\n          hugeicons='Alert02Icon'\n          phosphor='WarningIcon'\n          remixicon='RiErrorWarningLine'\n        />\n      ),\n      label: 'Which accounts are at risk?',\n    },\n    {\n      icon: (\n        <IconPlaceholder\n          lucide='PencilIcon'\n          tabler='IconPencil'\n          hugeicons='PencilEdit02Icon'\n          phosphor='PencilSimpleIcon'\n          remixicon='RiPencilLine'\n        />\n      ),\n      label: 'Draft a revenue update for the team',\n    },\n  ],\n  title: 'Revenue',\n  toolLabels: {\n    find_at_risk_accounts: {\n      done: 'Checked accounts for warning signs',\n      running: 'Checking accounts for warning signs',\n    },\n  },\n}\n\nconst AiAssistant1 = (props: AiAssistant1Props) => {\n  const {\n    accounts = [],\n    comparison,\n    context: contextLabel,\n    defaultOpen = true,\n    description,\n    historyLabels,\n    metrics = [],\n    errorMessage,\n    status: blockStatus,\n    suggestions,\n    title,\n    toolLabels,\n  } = props\n  const state = getBlockState(blockStatus, metrics)\n  const shown: (StatMetric & { history?: number[] })[] =\n    blockStatus === 'loading' ? getStatPlaceholders(4) : metrics\n  const accountsMrr = accounts.reduce((sum, account) => sum + account.mrr, 0)\n  const panelId = useId()\n  const [open, setOpen] = useState(defaultOpen)\n  const [withContext, setWithContext] = useState(true)\n  const baseChat = props.chat\n  const chat: AIChat = {\n    ...baseChat,\n    sendMessage: (message) =>\n      baseChat.sendMessage({\n        ...message,\n        metadata: withContext ? { context: contextLabel } : undefined,\n      }),\n  }\n  const composerRef = useRef<HTMLTextAreaElement>(null)\n  const toggleRef = useRef<HTMLButtonElement>(null)\n  const focusNext = useRef<'composer' | 'toggle' | null>(null)\n\n  useEffect(() => {\n    const target = focusNext.current === 'composer' ? composerRef : toggleRef\n    if (focusNext.current) target.current?.focus()\n    focusNext.current = null\n  }, [open])\n\n  function close() {\n    focusNext.current = 'toggle'\n    setOpen(false)\n  }\n\n  return (\n    <div className='bg-background @container flex h-svh'>\n      <BlockStateProvider errorMessage={errorMessage} state={state}>\n        <div\n          className={\n            open\n              ? '@container/main hidden min-w-0 flex-1 flex-col @3xl:flex'\n              : '@container/main flex min-w-0 flex-1 flex-col'\n          }\n        >\n          <div className='flex flex-1 flex-col gap-8 overflow-y-auto p-4 [scrollbar-width:thin] @xl/main:p-6'>\n            <header className='flex items-end justify-between gap-4'>\n              <div className='flex min-w-0 flex-col gap-0.5'>\n                <h1 className='truncate text-2xl font-semibold tracking-tight'>\n                  {title}\n                </h1>\n                <p className='text-muted-foreground truncate text-sm'>{description}</p>\n              </div>\n              <Button\n                ref={toggleRef}\n                variant='outline'\n                size='sm'\n                aria-expanded={open}\n                aria-controls={open ? panelId : undefined}\n                onClick={() => {\n                  focusNext.current = open ? 'toggle' : 'composer'\n                  setOpen(!open)\n                }}\n              >\n                <IconPlaceholder\n                  lucide='SparklesIcon'\n                  tabler='IconSparkles'\n                  hugeicons='SparklesIcon'\n                  phosphor='SparkleIcon'\n                  remixicon='RiSparklingLine'\n                  data-icon='inline-start'\n                />\n                Ask AI\n              </Button>\n            </header>\n            <StatGroup className='grid-cols-1 @md/main:grid-cols-2 @4xl/main:grid-cols-4'>\n              {shown.map((metric) => (\n                <Stat key={metric.key}>\n                  <StatLabel>{metric.label}</StatLabel>\n                  <StatValue className='text-3xl @2xl/main:text-4xl'>\n                    {formatStatValue(metric)}\n                  </StatValue>\n                  <StatChange comparison={comparison} metric={metric} />\n                  <dd className='mt-2'>\n                    <StatSparkline\n                      data={metric.history ?? []}\n                      formatter={metric.formatter}\n                      label={`${metric.label} by month, ${historyLabels[0]} to ${historyLabels.at(-1)}`}\n                      labels={historyLabels}\n                    />\n                  </dd>\n                </Stat>\n              ))}\n            </StatGroup>\n            {state !== 'empty' && state !== 'error' && (\n              <section\n                aria-labelledby={`${panelId}-accounts`}\n                className='flex flex-col gap-3'\n              >\n                <header className='flex flex-col gap-0.5'>\n                  <h2 id={`${panelId}-accounts`} className='font-semibold tracking-tight'>\n                    Top accounts\n                  </h2>\n                  <BlockReady className='text-sm'>\n                    <p className='text-muted-foreground text-sm'>\n                      Your {accounts.length} largest accounts pay{' '}\n                      {formatCurrency(accountsMrr)} a month.\n                    </p>\n                  </BlockReady>\n                </header>\n                {state === 'loading' ? (\n                  <BlockStateRows className='border-y' rows={5} />\n                ) : (\n                  <ul className='divide-y border-y'>\n                    {accounts.map((account) => (\n                      <li\n                        key={account.name}\n                        className='flex items-center justify-between gap-4 py-2.5 text-sm'\n                      >\n                        <span className='flex min-w-0 flex-col'>\n                          <span className='truncate font-medium'>{account.name}</span>\n                          <span className='text-muted-foreground text-xs'>\n                            {account.plan}\n                          </span>\n                        </span>\n                        <span className='tabular-nums'>\n                          {formatCurrency(account.mrr)}\n                          <span className='text-muted-foreground'>/mo</span>\n                        </span>\n                      </li>\n                    ))}\n                  </ul>\n                )}\n              </section>\n            )}\n          </div>\n        </div>\n      </BlockStateProvider>\n      {open && (\n        <ChatPanel\n          id={panelId}\n          className='w-full border-s @3xl:w-96'\n          chat={chat}\n          title='Assistant'\n          description='Answers from your revenue data'\n          placeholder='Ask about this page'\n          suggestions={suggestions}\n          textareaRef={composerRef}\n          toolLabels={toolLabels}\n          onClose={close}\n          context={\n            withContext && (\n              <ChatContextChip\n                label={contextLabel}\n                icon={\n                  <IconPlaceholder\n                    lucide='LayoutDashboardIcon'\n                    tabler='IconDashboard'\n                    hugeicons='DashboardSquare01Icon'\n                    phosphor='SquaresFourIcon'\n                    remixicon='RiDashboardLine'\n                  />\n                }\n                onRemove={() => {\n                  setWithContext(false)\n                  composerRef.current?.focus()\n                }}\n              />\n            )\n          }\n        />\n      )}\n    </div>\n  )\n}\n\nexport { AiAssistant1, exampleProps as aiAssistant1ExampleProps, type AiAssistant1Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/ai-assistant/ai-assistant-01.tsx"
    }
  ],
  "meta": {
    "shows": "An assistant docked beside the page with suggested prompts, the page as context, and New conversation and Close buttons.",
    "size": "page",
    "usedWith": [
      "ai-assistant-02"
    ],
    "component": "AiAssistant1",
    "props": "{ accounts?: { mrr: number; name: string; plan: string }[]; chat: { addToolApprovalResponse?: (response: { approved: boolean; id: string; reason?: string }) => unknown; error?: Error; messages: { id: string; metadata?: unknown; parts: ({ citations?: { endIndex?: number; source: { id: string; sourceType: \"url\"; title?: string; url: string } | { id: string; sourceType: \"document\"; title: string } }[]; state?: \"done\" | \"streaming\"; text: string; type: \"text\" } | { state?: \"done\" | \"streaming\"; text: string; type: \"reasoning\" } | { type: `tool-${string}`; approval?: { approved?: boolean; id: string; isAutomatic?: boolean; reason?: string; requestReason?: string }; errorText?: string; input?: unknown; output?: unknown; preliminary?: boolean; state: \"input-streaming\" | \"input-available\" | \"approval-requested\" | \"approval-responded\" | \"output-available\" | \"output-error\" | \"output-denied\"; title?: string; toolCallId: string } | { toolName: string; type: \"dynamic-tool\"; approval?: { approved?: boolean; id: string; isAutomatic?: boolean; reason?: string; requestReason?: string }; errorText?: string; input?: unknown; output?: unknown; preliminary?: boolean; state: \"input-streaming\" | \"input-available\" | \"approval-requested\" | \"approval-responded\" | \"output-available\" | \"output-error\" | \"output-denied\"; title?: string; toolCallId: string } | { sourceId: string; title?: string; type: \"source-url\"; url: string } | { filename?: string; mediaType: string; sourceId: string; title: string; type: \"source-document\" } | { filename?: string; mediaType: string; type: \"file\"; url: string } | { data: unknown; id?: string; type: `data-${string}` } | { type: \"step-start\" | \"custom\" | \"reasoning-file\" | \"steering-message\" })[]; role: \"system\" | \"user\" | \"assistant\" }[]; regenerate: (options: { messageId?: string }) => unknown; selectVersion?: (messageId: string, index: number) => unknown; sendMessage: (message: { files?: { filename?: string; mediaType: string; type: \"file\"; url: string }[]; messageId?: string; metadata?: unknown; text: string }) => unknown; setMessages?: (messages: []) => void; status: \"error\" | \"streaming\" | \"ready\" | \"submitted\"; stop: () => unknown; versions?: {  } }; comparison: string; context: string; defaultOpen?: boolean; description: string; historyLabels: string[]; metrics?: { history: number[]; changeType?: \"percent\" | \"points\" | \"count\"; detail?: ReactNode; formatter?: (value: number) => string; goodDirection?: \"up\" | \"down\"; key: string; label: string; previous?: number; tone?: \"warning\" | \"bad\"; value: number }[]; suggestions: { icon?: ReactNode; label: string; prompt?: string }[]; title: string; toolLabels?: Record<string, string | { done: string; running: string }>; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
