{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ai-assistant-02",
  "description": "A chat with an assistant whose replies include a table and a SQL query, with attachments, copy, rating, regenerate and follow-up questions.",
  "registryDependencies": [
    "card",
    "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"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/ai-assistant/ai-assistant-02.tsx",
      "content": "'use client'\n\nimport {\n  type ChatFeedback,\n  ChatComposer,\n  ChatConversation,\n  ChatMessages,\n  ChatWelcome,\n  type SuggestedPrompt,\n  SuggestedPrompts,\n} from '@/registry/components/dashboardblocks/ai-assistant'\nimport {\n  type AIChat,\n  getMessageText,\n} from '@/registry/components/dashboardblocks/ai-message'\nimport type { AIToolLabel } from '@/registry/components/dashboardblocks/ai-parts'\nimport {\n  BlockStateProvider,\n  BlockStateRows,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport { useRef, useState } from 'react'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface AiAssistant2Props extends BlockStateProps {\n  /** The chat it runs: `useChat()` from `@ai-sdk/react`, or `useChatStream` for any other stream. */\n  chat: AIChat\n  description: string\n  /** Suggested next questions, under the last reply and in a new chat. */\n  followUps: SuggestedPrompt[]\n  onFeedback?: (messageId: string, feedback: ChatFeedback | null) => void\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 exampleProps: Omit<AiAssistant2Props, 'chat'> = {\n  description: 'Answers from your product analytics, with the query behind each one.',\n  followUps: [\n    { label: 'Compare with last week', prompt: 'Compare with the week before' },\n    {\n      label: 'Pages that lost sessions',\n      prompt: 'Which pages lost the most sessions?',\n    },\n    {\n      label: 'Note for payments',\n      prompt: 'Draft a note for the payments team',\n    },\n  ],\n  title: 'Analytics assistant',\n  toolLabels: {\n    compare_weeks: {\n      done: 'Compared the two weeks',\n      running: 'Comparing the two weeks',\n    },\n  },\n}\n\nconst AiAssistant2 = (props: AiAssistant2Props) => {\n  const {\n    description,\n    followUps,\n    onFeedback = () => {},\n    errorMessage,\n    status: blockStatus,\n    title,\n    toolLabels,\n  } = props\n  const { chat } = props\n  const { messages, status } = chat\n  const state = getBlockState(blockStatus, messages)\n  const composerRef = useRef<HTMLTextAreaElement>(null)\n  const [feedback, setFeedback] = useState<Record<string, ChatFeedback | null>>({})\n  const asked = new Set(messages.map(getMessageText))\n  const send = (question: string) => chat.sendMessage({ text: question })\n\n  function rate(messageId: string, value: ChatFeedback | null) {\n    setFeedback((current) => ({ ...current, [messageId]: value }))\n    onFeedback(messageId, value)\n  }\n\n  return (\n    <Card>\n      <CardContent>\n        <BlockStateProvider errorMessage={errorMessage} state={state}>\n          <section className='@container flex h-[40rem] flex-col gap-3'>\n            <header className='flex flex-col gap-0.5'>\n              <h2 className='font-semibold tracking-tight'>{title}</h2>\n              <p className='text-muted-foreground text-sm'>{description}</p>\n            </header>\n            <ChatMessages\n              status={status}\n              latest={messages.at(-1)}\n              className='min-h-0 border-t'\n              contentClassName='ps-0 pe-4'\n            >\n              {state === 'empty' ? (\n                <ChatWelcome\n                  className='my-auto py-8'\n                  title='Ask about your product'\n                  description='Answers come with the query behind them.'\n                >\n                  <SuggestedPrompts\n                    variant='list'\n                    label='Suggested questions'\n                    prompts={followUps}\n                    onSelect={send}\n                  />\n                </ChatWelcome>\n              ) : (\n                state && <BlockStateRows rows={3} />\n              )}\n              {!state && (\n                <ChatConversation\n                  chat={chat}\n                  composerRef={composerRef}\n                  feedback={feedback}\n                  onFeedback={rate}\n                  toolLabels={toolLabels}\n                  followUps={() =>\n                    followUps.filter(\n                      (prompt) => !asked.has(prompt.prompt ?? prompt.label),\n                    )\n                  }\n                />\n              )}\n            </ChatMessages>\n            <ChatComposer\n              accept='.csv,image/*'\n              disabled={blockStatus !== undefined}\n              status={status}\n              textareaRef={composerRef}\n              onSubmit={chat.sendMessage}\n              onStop={chat.stop}\n              placeholder='Ask a follow-up'\n            />\n          </section>\n        </BlockStateProvider>\n      </CardContent>\n    </Card>\n  )\n}\n\nexport { AiAssistant2, exampleProps as aiAssistant2ExampleProps, type AiAssistant2Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/ai-assistant/ai-assistant-02.tsx"
    }
  ],
  "meta": {
    "shows": "A chat with an assistant whose replies include a table and a SQL query, with attachments, copy, rating, regenerate and follow-up questions.",
    "size": "half",
    "usedWith": [
      "ai-assistant-01",
      "ai-assistant-04"
    ],
    "component": "AiAssistant2",
    "props": "{ 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?: {  } }; description: string; followUps: { icon?: ReactNode; label: string; prompt?: string }[]; onFeedback?: (messageId: string, feedback: null | \"up\" | \"down\") => void; title: string; toolLabels?: Record<string, string | { done: string; running: string }>; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
