{
  "$schema": "https://shadcn-vue.com/schema/registry-item.json",
  "name": "chat",
  "type": "registry:ui",
  "title": "Chat",
  "description": "A complete AI chat for vue-llm useChat: streaming Markdown, reasoning, tool calls, Generative UI, attachments and auto-scroll.",
  "dependencies": [
    "vue-llm",
    "@lucide/vue"
  ],
  "files": [
    {
      "path": "ui/chat/Chat.vue",
      "content": "<script setup lang=\"ts\">\nimport { computed, type Component } from 'vue'\nimport { ArrowDown, CircleAlert } from '@lucide/vue'\nimport { useAutoScroll, type UseChatReturn } from 'vue-llm'\nimport { cn } from '@/lib/utils'\nimport ChatMessage from './ChatMessage.vue'\nimport ChatPromptInput from './ChatPromptInput.vue'\n\nconst props = withDefaults(defineProps<{\n  chat: UseChatReturn\n  /** Components that render tool calls, keyed by tool name (Generative UI) */\n  components?: Record<string, Component>\n  /** Prompts shown while the chat is empty */\n  suggestions?: string[]\n  placeholder?: string\n  /** Accepted attachments, as in `<input accept>`. `false` hides the attach button. */\n  accept?: string | false\n  class?: string\n}>(), {\n  components: undefined,\n  suggestions: () => [],\n  placeholder: undefined,\n  accept: undefined,\n  class: undefined,\n})\n\nconst { messages, status, error } = props.chat\nconst scroll = useAutoScroll()\nconst { isAtBottom, scrollToBottom } = scroll\n\nconst visible = computed(() => messages.value.filter(m => m.role !== 'system'))\nconst busy = computed(() => status.value === 'submitted' || status.value === 'streaming')\nconst lastAssistantId = computed(() => [...visible.value].reverse().find(m => m.role === 'assistant')?.id)\n\nfunction send(text: string): void {\n  if (!busy.value) void props.chat.sendMessage(text)\n}\n</script>\n\n<template>\n  <div :class=\"cn('relative flex h-full min-h-0 flex-col', props.class)\">\n    <div :ref=\"scroll.container\" class=\"min-h-0 flex-1 overflow-y-auto\">\n      <div class=\"mx-auto flex w-full max-w-3xl flex-col gap-6 px-4 py-6\">\n        <div v-if=\"!visible.length\" class=\"flex flex-1 flex-col items-center justify-center gap-4 py-16 text-center\">\n          <slot name=\"empty\">\n            <p class=\"text-lg font-medium\">\n              How can I help?\n            </p>\n          </slot>\n          <div v-if=\"suggestions.length\" class=\"flex flex-wrap justify-center gap-2\">\n            <button\n              v-for=\"s in suggestions\"\n              :key=\"s\"\n              type=\"button\"\n              class=\"rounded-full border px-3 py-1.5 text-sm text-muted-foreground transition-colors hover:bg-muted hover:text-foreground\"\n              @click=\"send(s)\"\n            >\n              {{ s }}\n            </button>\n          </div>\n        </div>\n\n        <ChatMessage\n          v-for=\"message in visible\"\n          :key=\"message.id\"\n          :message=\"message\"\n          :components=\"components\"\n          :is-last=\"message.id === lastAssistantId\"\n          :streaming=\"busy && message.id === lastAssistantId\"\n          @tool-result=\"chat.addToolResult\"\n          @regenerate=\"chat.regenerate()\"\n        />\n\n        <div v-if=\"status === 'submitted'\" class=\"flex gap-1 py-2\" aria-label=\"Generating\">\n          <span v-for=\"i in 3\" :key=\"i\" class=\"size-1.5 animate-bounce rounded-full bg-muted-foreground\" :style=\"{ animationDelay: `${(i - 1) * 150}ms` }\" />\n        </div>\n\n        <div v-if=\"error\" class=\"flex items-start gap-2 rounded-lg border border-destructive/30 bg-destructive/5 px-3 py-2 text-sm text-destructive\">\n          <CircleAlert class=\"mt-0.5 size-4 shrink-0\" />\n          <span class=\"flex-1\">{{ error.message }}</span>\n          <button type=\"button\" class=\"shrink-0 font-medium underline underline-offset-4\" @click=\"chat.regenerate()\">\n            Retry\n          </button>\n        </div>\n      </div>\n    </div>\n\n    <div class=\"mx-auto w-full max-w-3xl px-4 pb-4\">\n      <div class=\"relative\">\n        <button\n          v-if=\"!isAtBottom\"\n          type=\"button\"\n          class=\"absolute -top-12 left-1/2 inline-flex size-8 -translate-x-1/2 items-center justify-center rounded-full border bg-background text-muted-foreground shadow-sm hover:text-foreground\"\n          aria-label=\"Scroll to bottom\"\n          @click=\"scrollToBottom('smooth')\"\n        >\n          <ArrowDown class=\"size-4\" />\n        </button>\n        <ChatPromptInput :chat=\"chat\" :placeholder=\"placeholder\" :accept=\"accept\" />\n      </div>\n    </div>\n  </div>\n</template>\n",
      "type": "registry:ui"
    },
    {
      "path": "ui/chat/ChatMessage.vue",
      "content": "<script setup lang=\"ts\">\nimport { computed, ref, type Component } from 'vue'\nimport { Check, Copy, FileText, RotateCcw } from '@lucide/vue'\nimport type { ToolCallPart, UIMessage } from 'vue-llm'\nimport { StreamMarkdown } from 'vue-llm/components'\nimport { cn } from '@/lib/utils'\nimport ChatReasoning from './ChatReasoning.vue'\nimport ChatToolCall from './ChatToolCall.vue'\n\nconst props = defineProps<{\n  message: UIMessage\n  /** Components that render tool calls, keyed by tool name (Generative UI) */\n  components?: Record<string, Component>\n  /** Show actions for the latest assistant message */\n  isLast?: boolean\n  /** The chat is generating this message */\n  streaming?: boolean\n  class?: string\n}>()\n\nconst emit = defineEmits<{\n  'tool-result': [payload: { toolCallId: string; result: unknown }]\n  'regenerate': []\n}>()\n\nconst isUser = computed(() => props.message.role === 'user')\nconst text = computed(() => props.message.parts.map(p => (p.type === 'text' ? p.text : '')).join(''))\n\nconst copied = ref(false)\nasync function copy(): Promise<void> {\n  try {\n    await navigator.clipboard.writeText(text.value)\n  } catch {\n    // Clipboard blocked (insecure context or denied permission)\n    return\n  }\n  copied.value = true\n  setTimeout(() => (copied.value = false), 1500)\n}\n\nconst toolProps = (part: ToolCallPart) => ({\n  toolCallId: part.toolCallId,\n  toolName: part.toolName,\n  args: part.args,\n  state: part.state,\n  result: part.result,\n  error: part.error,\n  addResult: (result: unknown) => emit('tool-result', { toolCallId: part.toolCallId, result }),\n})\n</script>\n\n<template>\n  <div :class=\"cn('group flex w-full flex-col gap-2', isUser ? 'items-end' : 'items-start', props.class)\" :data-role=\"message.role\">\n    <template v-for=\"(part, index) in message.parts\" :key=\"part.type === 'tool-call' ? part.toolCallId : index\">\n      <template v-if=\"part.type === 'text'\">\n        <div v-if=\"isUser\" class=\"max-w-[85%] whitespace-pre-wrap rounded-2xl bg-primary px-4 py-2 text-primary-foreground\">\n          {{ part.text }}\n        </div>\n        <div v-else class=\"chat-markdown w-full leading-relaxed\">\n          <StreamMarkdown :content=\"part.text\" :streaming=\"part.state === 'streaming'\" />\n        </div>\n      </template>\n\n      <ChatReasoning v-else-if=\"part.type === 'reasoning'\" :text=\"part.text\" :streaming=\"part.state === 'streaming'\" />\n\n      <template v-else-if=\"part.type === 'tool-call'\">\n        <component :is=\"components[part.toolName]\" v-if=\"components?.[part.toolName]\" v-bind=\"toolProps(part)\" />\n        <ChatToolCall v-else class=\"w-full max-w-md\" v-bind=\"toolProps(part)\" />\n      </template>\n\n      <template v-else-if=\"part.type === 'file'\">\n        <img\n          v-if=\"part.mediaType.startsWith('image/')\"\n          :src=\"part.url\"\n          :alt=\"part.filename ?? ''\"\n          class=\"max-h-48 max-w-[60%] rounded-xl border object-cover\"\n        >\n        <span v-else class=\"inline-flex items-center gap-1.5 rounded-lg border bg-muted px-2.5 py-1.5 text-sm\">\n          <FileText class=\"size-4 text-muted-foreground\" />\n          {{ part.filename ?? part.mediaType }}\n        </span>\n      </template>\n\n      <a\n        v-else-if=\"part.type === 'source' && /^https?:/i.test(part.url)\"\n        :href=\"part.url\"\n        target=\"_blank\"\n        rel=\"noopener noreferrer\"\n        class=\"text-sm text-muted-foreground underline underline-offset-4 hover:text-foreground\"\n      >{{ part.title ?? part.url }}</a>\n    </template>\n\n    <div\n      v-if=\"!isUser && text && !streaming\"\n      :class=\"cn('flex gap-1 text-muted-foreground transition-opacity', !isLast && 'opacity-0 group-hover:opacity-100 focus-within:opacity-100')\"\n    >\n      <button type=\"button\" class=\"rounded-md p-1.5 hover:bg-muted hover:text-foreground\" :aria-label=\"copied ? 'Copied' : 'Copy'\" @click=\"copy\">\n        <Check v-if=\"copied\" class=\"size-4\" />\n        <Copy v-else class=\"size-4\" />\n      </button>\n      <button v-if=\"isLast\" type=\"button\" class=\"rounded-md p-1.5 hover:bg-muted hover:text-foreground\" aria-label=\"Regenerate\" @click=\"emit('regenerate')\">\n        <RotateCcw class=\"size-4\" />\n      </button>\n    </div>\n  </div>\n</template>\n\n<style scoped>\n/* Markdown from the model; uses the shadcn theme variables */\n.chat-markdown :deep(.vue-llm-cursor) { display: none; }\n.chat-markdown :deep(.vue-llm-markdown > :first-child) { margin-top: 0; }\n.chat-markdown :deep(.vue-llm-markdown > :last-child) { margin-bottom: 0; }\n.chat-markdown :deep(p),\n.chat-markdown :deep(ul),\n.chat-markdown :deep(ol),\n.chat-markdown :deep(pre),\n.chat-markdown :deep(blockquote),\n.chat-markdown :deep(table) { margin: 0.75em 0; }\n.chat-markdown :deep(h1),\n.chat-markdown :deep(h2),\n.chat-markdown :deep(h3) { margin: 1em 0 0.5em; font-weight: 600; line-height: 1.3; }\n.chat-markdown :deep(h1) { font-size: 1.4em; }\n.chat-markdown :deep(h2) { font-size: 1.2em; }\n.chat-markdown :deep(h3) { font-size: 1.05em; }\n.chat-markdown :deep(ul) { list-style: disc; padding-left: 1.5em; }\n.chat-markdown :deep(ol) { list-style: decimal; padding-left: 1.5em; }\n.chat-markdown :deep(li) { margin: 0.25em 0; }\n.chat-markdown :deep(a) { text-decoration: underline; text-underline-offset: 4px; }\n.chat-markdown :deep(code) { font-size: 0.875em; background: var(--muted); border-radius: 0.375rem; padding: 0.1em 0.35em; }\n.chat-markdown :deep(pre) { overflow-x: auto; background: var(--muted); border-radius: 0.5rem; padding: 0.75em 1em; }\n.chat-markdown :deep(pre code) { background: none; padding: 0; }\n.chat-markdown :deep(blockquote) { border-left: 2px solid var(--border); padding-left: 1em; color: var(--muted-foreground); }\n.chat-markdown :deep(table) { display: block; overflow-x: auto; border-collapse: collapse; font-size: 0.9em; }\n.chat-markdown :deep(th),\n.chat-markdown :deep(td) { border: 1px solid var(--border); padding: 0.4em 0.75em; }\n.chat-markdown :deep(hr) { border-color: var(--border); margin: 1.5em 0; }\n</style>\n",
      "type": "registry:ui"
    },
    {
      "path": "ui/chat/ChatPromptInput.vue",
      "content": "<script setup lang=\"ts\">\nimport { computed, ref } from 'vue'\nimport { ArrowUp, FileText, Paperclip, Square, X } from '@lucide/vue'\nimport { usePromptInput, type PromptInputChat } from 'vue-llm'\nimport { cn } from '@/lib/utils'\n\nconst props = withDefaults(defineProps<{\n  chat: PromptInputChat & { stop: () => void }\n  placeholder?: string\n  /** Accepted attachments, as in `<input accept>`. Set to `false` to hide the attach button. */\n  accept?: string | false\n  maxFiles?: number\n  class?: string\n}>(), {\n  placeholder: 'Send a message…',\n  accept: 'image/*,application/pdf,text/*',\n  maxFiles: undefined,\n  class: undefined,\n})\n\nconst prompt = usePromptInput(props.chat, {\n  accept: props.accept || undefined,\n  maxFiles: props.maxFiles,\n})\nconst { files, isDragging, canSubmit, handlers, dropzone } = prompt\nconst input = props.chat.input\n\nconst busy = computed(() => props.chat.status.value === 'submitted' || props.chat.status.value === 'streaming')\nconst fileInput = ref<HTMLInputElement | null>(null)\n\nconst previews = new WeakMap<File, string>()\nfunction preview(file: File): string | undefined {\n  if (!file.type.startsWith('image/')) return undefined\n  if (!previews.has(file)) previews.set(file, URL.createObjectURL(file))\n  return previews.get(file)\n}\n\nfunction onPick(event: Event): void {\n  const input = event.target as HTMLInputElement\n  prompt.addFiles(input.files)\n  input.value = ''\n}\n\nfunction remove(file: File): void {\n  const url = previews.get(file)\n  if (url) URL.revokeObjectURL(url)\n  prompt.removeFile(file)\n}\n</script>\n\n<template>\n  <form\n    :class=\"cn(\n      'relative flex flex-col rounded-2xl border bg-background shadow-xs transition-colors focus-within:border-ring',\n      isDragging && 'border-primary bg-primary/5',\n      props.class,\n    )\"\n    v-bind=\"dropzone\"\n    @submit.prevent=\"prompt.submit()\"\n  >\n    <div v-if=\"files.length\" class=\"flex flex-wrap gap-2 px-3 pt-3\">\n      <div v-for=\"file in files\" :key=\"file.name + file.size + file.lastModified\" class=\"group relative\">\n        <img v-if=\"preview(file)\" :src=\"preview(file)\" :alt=\"file.name\" class=\"size-14 rounded-lg border object-cover\">\n        <div v-else class=\"flex h-14 max-w-40 items-center gap-1.5 rounded-lg border bg-muted px-2.5 text-xs\">\n          <FileText class=\"size-4 shrink-0 text-muted-foreground\" />\n          <span class=\"truncate\">{{ file.name }}</span>\n        </div>\n        <button\n          type=\"button\"\n          class=\"absolute -top-1.5 -right-1.5 rounded-full border bg-background p-0.5 text-muted-foreground shadow-xs hover:text-foreground\"\n          :aria-label=\"`Remove ${file.name}`\"\n          @click=\"remove(file)\"\n        >\n          <X class=\"size-3\" />\n        </button>\n      </div>\n    </div>\n\n    <textarea\n      :ref=\"prompt.textarea\"\n      v-model=\"input\"\n      rows=\"1\"\n      :placeholder=\"placeholder\"\n      class=\"max-h-60 w-full resize-none bg-transparent px-4 pt-3 pb-1 text-base outline-none placeholder:text-muted-foreground md:text-sm\"\n      v-bind=\"handlers\"\n    />\n\n    <div class=\"flex items-center gap-2 p-2\">\n      <template v-if=\"accept !== false\">\n        <input ref=\"fileInput\" type=\"file\" multiple :accept=\"accept || undefined\" class=\"hidden\" @change=\"onPick\">\n        <button\n          type=\"button\"\n          class=\"inline-flex size-8 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-muted hover:text-foreground\"\n          aria-label=\"Attach files\"\n          @click=\"fileInput?.click()\"\n        >\n          <Paperclip class=\"size-4\" />\n        </button>\n      </template>\n\n      <button\n        v-if=\"busy\"\n        type=\"button\"\n        class=\"ml-auto inline-flex size-8 items-center justify-center rounded-full bg-primary text-primary-foreground transition-opacity hover:opacity-90\"\n        aria-label=\"Stop generating\"\n        @click=\"chat.stop()\"\n      >\n        <Square class=\"size-3.5 fill-current\" />\n      </button>\n      <button\n        v-else\n        type=\"submit\"\n        class=\"ml-auto inline-flex size-8 items-center justify-center rounded-full bg-primary text-primary-foreground transition-opacity hover:opacity-90 disabled:opacity-30\"\n        :disabled=\"!canSubmit\"\n        aria-label=\"Send\"\n      >\n        <ArrowUp class=\"size-4\" />\n      </button>\n    </div>\n\n    <div\n      v-if=\"isDragging\"\n      class=\"pointer-events-none absolute inset-0 flex items-center justify-center rounded-2xl text-sm font-medium text-primary\"\n    >\n      Drop files to attach\n    </div>\n  </form>\n</template>\n",
      "type": "registry:ui"
    },
    {
      "path": "ui/chat/ChatReasoning.vue",
      "content": "<script setup lang=\"ts\">\nimport { ref, watch } from 'vue'\nimport { Brain, ChevronRight } from '@lucide/vue'\nimport { cn } from '@/lib/utils'\n\nconst props = defineProps<{\n  text: string\n  streaming?: boolean\n  class?: string\n}>()\n\n// Open while the model thinks, collapse when it starts answering, unless the user toggled it\nconst open = ref(!!props.streaming)\nconst touched = ref(false)\nwatch(() => props.streaming, (streaming) => {\n  if (!touched.value) open.value = !!streaming\n})\n\nfunction toggle(): void {\n  touched.value = true\n  open.value = !open.value\n}\n</script>\n\n<template>\n  <div :class=\"cn('text-sm text-muted-foreground', props.class)\">\n    <button\n      type=\"button\"\n      class=\"inline-flex items-center gap-1.5 rounded-md py-1 transition-colors hover:text-foreground\"\n      :aria-expanded=\"open\"\n      @click=\"toggle\"\n    >\n      <Brain class=\"size-4\" />\n      <span :class=\"streaming && 'animate-pulse'\">{{ streaming ? 'Thinking…' : 'Reasoning' }}</span>\n      <ChevronRight :class=\"cn('size-4 transition-transform', open && 'rotate-90')\" />\n    </button>\n    <div v-if=\"open\" class=\"mt-1 whitespace-pre-wrap border-l-2 pl-3 leading-relaxed\">\n      {{ text }}\n    </div>\n  </div>\n</template>\n",
      "type": "registry:ui"
    },
    {
      "path": "ui/chat/ChatToolCall.vue",
      "content": "<script setup lang=\"ts\">\nimport { computed, ref } from 'vue'\nimport { Check, ChevronRight, CircleAlert, LoaderCircle, Wrench } from '@lucide/vue'\nimport type { ToolCallState } from 'vue-llm'\nimport { cn } from '@/lib/utils'\n\nconst props = defineProps<{\n  toolName: string\n  state: ToolCallState\n  args?: unknown\n  result?: unknown\n  error?: string\n  class?: string\n}>()\n\nconst open = ref(false)\n\nconst label = computed(() => ({\n  streaming: 'Preparing',\n  pending: 'Waiting',\n  running: 'Running',\n  result: 'Done',\n  error: 'Failed',\n})[props.state])\n\nconst json = (value: unknown): string => (typeof value === 'string' ? value : JSON.stringify(value, null, 2))\n</script>\n\n<template>\n  <div :class=\"cn('rounded-lg border bg-card text-card-foreground text-sm', props.class)\">\n    <button\n      type=\"button\"\n      class=\"flex w-full items-center gap-2 px-3 py-2 text-left\"\n      :aria-expanded=\"open\"\n      @click=\"open = !open\"\n    >\n      <Wrench class=\"size-4 shrink-0 text-muted-foreground\" />\n      <span class=\"truncate font-mono text-xs\">{{ toolName }}</span>\n      <span\n        :class=\"cn(\n          'ml-auto inline-flex shrink-0 items-center gap-1 rounded-full px-2 py-0.5 text-xs',\n          state === 'error' ? 'bg-destructive/10 text-destructive' : 'bg-muted text-muted-foreground',\n        )\"\n      >\n        <LoaderCircle v-if=\"state === 'streaming' || state === 'running'\" class=\"size-3 animate-spin\" />\n        <Check v-else-if=\"state === 'result'\" class=\"size-3\" />\n        <CircleAlert v-else-if=\"state === 'error'\" class=\"size-3\" />\n        {{ label }}\n      </span>\n      <ChevronRight :class=\"cn('size-4 shrink-0 text-muted-foreground transition-transform', open && 'rotate-90')\" />\n    </button>\n    <div v-if=\"open\" class=\"space-y-2 border-t px-3 py-2\">\n      <div>\n        <div class=\"mb-1 text-xs font-medium text-muted-foreground\">\n          Arguments\n        </div>\n        <pre class=\"overflow-x-auto rounded-md bg-muted p-2 text-xs\">{{ json(args ?? {}) }}</pre>\n      </div>\n      <div v-if=\"state === 'result'\">\n        <div class=\"mb-1 text-xs font-medium text-muted-foreground\">\n          Result\n        </div>\n        <pre class=\"overflow-x-auto rounded-md bg-muted p-2 text-xs\">{{ json(result) }}</pre>\n      </div>\n      <p v-if=\"error\" class=\"text-xs text-destructive\">\n        {{ error }}\n      </p>\n    </div>\n  </div>\n</template>\n",
      "type": "registry:ui"
    },
    {
      "path": "ui/chat/index.ts",
      "content": "export { default as Chat } from './Chat.vue'\nexport { default as ChatMessage } from './ChatMessage.vue'\nexport { default as ChatPromptInput } from './ChatPromptInput.vue'\nexport { default as ChatReasoning } from './ChatReasoning.vue'\nexport { default as ChatToolCall } from './ChatToolCall.vue'\n",
      "type": "registry:ui"
    }
  ]
}