# Chat

`Chat` is the Console conversation view. It shows AI SDK `UIMessage[]` as a scrollable log. It follows a live reply while the reader is at the end, and stays in place when the reader scrolls back. Pair it with [`PromptInput`](https://vitehub.dev/docs/ui/prompt-input) to accept input.

_Interactive preview available on the rendered documentation page._


## Installation

Install `@vite-hub/ui` as [Installation](https://vitehub.dev/docs/ui/installation) shows. `vite-hub/nuxt` auto-imports the component. In Vue with Vite, import it from `vite-hub/ui`:

```ts
import { Chat } from "vite-hub/ui";
```

## Usage

```ts
import { Chat } from "vite-hub/ui";
```

```vue
<Chat :messages :status class="h-dvh" />
```

Give the chat a height, such as `h-dvh` or a grid row. It fills that space and scrolls inside it.

## Composition

`Chat` builds on the [Message Scroller](https://vitehub.dev/docs/ui/message-scroller) parts. It renders one `ChatMessage` per message, and each renders its parts with `MessageParts`.

```text
Chat (MessageScroller)
├── MessageScrollerViewport
│   └── MessageScrollerContent
│       └── MessageScrollerItem, one for each message
│           └── ChatMessage, or the message slot
│               └── MessageParts
├── MessageScrollerButton, with the scroll-button slot
├── composer slot
└── default slot
```

## Features

- Renders AI SDK `UIMessage[]` and reads the AI SDK `ChatStatus`.
- A scroll button returns to the live edge.
- Does not send, stop, or regenerate messages. Your app handles the transport.

## AI SDK

Pass the values from `useChat()`. The component never calls `sendMessage()`, `stop()`, or `regenerate()`, so the same UI works with AI SDK, ViteHub Agent routes, saved sessions, or replayed fixtures.

```vue [app/pages/chat.vue]
<script setup lang="ts">
import { useChat } from "@ai-sdk/vue";
import type { PromptInputSubmit } from "vite-hub/ui";

const { messages, status, sendMessage, stop } = useChat();
const input = ref("");

function submit({ text, files }: PromptInputSubmit) {
  sendMessage({ text, files: [...files] });
  input.value = "";
}
</script>

<template>
  <Chat :messages :status class="h-dvh">
    <template #composer>
      <PromptInput v-model="input" :status @submit="submit" @stop="stop" />
    </template>
  </Chat>
</template>
```

`useChat()` from `vite-hub/agent/vue` returns the same values and adds the ViteHub route and typed Agent metadata.

## Streaming

While `status` is `submitted` or `streaming`, the last message is in the `streaming` state and the log has `aria-busy="true"`.

While a reply is coming and nothing shows progress, a quiet `Working` line with a static dot sits under the last message. This happens before the first part, after a message ends, and after a tool finishes. Streaming text, a running tool step, and live reasoning show their own progress, so the line hides then. Use the `status` slot to draw it yourself, or `chatActivity(messages, status)` for the same text in a custom layout.

Select **Stream a reply** and scroll up while it runs. The chat stops following. The scroll control returns to the live edge.

_Interactive preview available on the rendered documentation page._


## Composer and Empty State

The `composer` slot puts a prompt under the messages, below the scroll control. Show your own empty state when `messages` is empty.

_Interactive preview available on the rendered documentation page._


## Custom Message Layout

The `message` slot replaces the default `ChatMessage` and receives `{ message, index }`. Use `MessageParts` inside it to keep the default part rendering.

_Interactive preview available on the rendered documentation page._


## Accessibility

- The viewport is a focusable region named **Messages**. The list has `role="log"` and announces new messages.
- The log is busy while a response is submitted or streaming, so screen readers do not announce partial text as final.
- The scroll button is a named native button. It is inert at the live edge and moves focus to the viewport when used.
- With reduced motion, scrolling is instant.

## API Reference

### Chat

Renders a scrollable log with one `ChatMessage` per message.

#### Props

| Prop                | Type                   | Default           | Description                                                                  |
| ------------------- | ---------------------- | ----------------- | ---------------------------------------------------------------------------- |
| `messages`          | `readonly UIMessage[]` | `[]`              | Messages to render, in order.                                                |
| `status`            | `ChatStatus`           | `"ready"`         | AI SDK chat status. `submitted` and `streaming` mark the last message as streaming. |
| `edgeThreshold`     | `number`               |                   | Pixels from the end that count as the end. Global default `8`. |
| `previousItemPeek`  | `number`               |                   | Pixels of the previous message kept visible when a new user message scrolls in. Global default `64`. |
| `scrollButtonLabel` | `string`               | `"Scroll to end"` | Scroll button name and default text. |

Other attributes go to the root element.

#### Slots

| Slot            | Scope                | Description                                                         |
| --------------- | -------------------- | ------------------------------------------------------------------- |
| `message`       | `{ message, index }` | Replaces the default `ChatMessage`. |
| `composer`      |                      | Content under the messages, such as `PromptInput`. |
| `scroll-button` |                      | Content of the scroll button.                                       |
| `status`        | `{ label }`          | Replaces the `Working` line. |
| `default`       |                      | Extra content inside the scroller root.                             |
| Other slots     |                      | Passed to each `ChatMessage`, such as `actions` or `tool`. |

## Related

- [Chat message](https://vitehub.dev/docs/ui/chat-message) renders one message.
- [Prompt input](https://vitehub.dev/docs/ui/prompt-input) collects text and files.
- [Chat session](https://vitehub.dev/docs/ui/chat-session) adds a title and session layout around the chat.
- [Message scroller](https://vitehub.dev/docs/ui/message-scroller) has the same scroll behavior without styles.
- [Chat app block](https://vitehub.dev/docs/ui/blocks/chat-app) combines sessions, chat, and attachments.

<!-- vitehub-docs:section-links -->
## In this section

- [Start](https://vitehub.dev/raw/docs/ui.md)
- [AI components](https://vitehub.dev/raw/docs/ui/ai-components.md)
- [Blocks](https://vitehub.dev/raw/docs/ui/blocks/chat-app.md)
- [Parts](https://vitehub.dev/raw/docs/ui/message.md)
- Chat
  - [Chat](https://vitehub.dev/raw/docs/ui/chat.md) (this page)
  - [Chat Message](https://vitehub.dev/raw/docs/ui/chat-message.md)
  - [Message Parts](https://vitehub.dev/raw/docs/ui/message-parts.md)
  - [Markdown](https://vitehub.dev/raw/docs/ui/markdown.md)
  - [Prompt Input](https://vitehub.dev/raw/docs/ui/prompt-input.md)
  - [Chat Session](https://vitehub.dev/raw/docs/ui/chat-session.md)
  - [Agent Session](https://vitehub.dev/raw/docs/ui/agent-session.md)
  - [Filter Search](https://vitehub.dev/raw/docs/ui/filter-search.md)
- [Collaboration](https://vitehub.dev/raw/docs/ui/avatar-stack.md)
- [Agent work](https://vitehub.dev/raw/docs/ui/tool-list.md)
- [Utilities](https://vitehub.dev/raw/docs/ui/attachments.md)

Next: [Chat Message](https://vitehub.dev/raw/docs/ui/chat-message.md)

All pages: [llms.txt](https://vitehub.dev/llms.txt)
