# Chat

A complete chat interface in one element.

<p class="kai-tag-sub">kai-chat</p>

Ships the thread, the prompt box, and a header already wired, so a chat surface needs no assembly.

## Preview

> **tip:** 
Drop-in chat panel in a non-Solid app: React, Vue, plain HTML, an iframe. Give it an explicit height. Need a conversation sidebar and history too? Use [`<kai-workspace>`](/components/workspace/).

## Usage

Set rich data (arrays, objects) in JavaScript; scalar props work as attributes or properties:

```html
<kai-chat id="chat" style="display:block; height:100vh;"></kai-chat>

<script type="module">

  await customElements.whenDefined('kai-chat');

  const chat = document.getElementById('chat');

  chat.messages = [
    { id: '1', role: 'user', parts: [{ type: 'text', text: 'How do I center a div?' }] },
    { id: '2', role: 'assistant', parts: [{ type: 'text', text: 'Use `display: grid; place-items: center;`' }],
      actions: ['copy', 'like', 'dislike'] },
  ];

  chat.addEventListener('kai-submit', (e) => {
    console.log('user sent:', e.detail.value, 'attachments:', e.detail.attachments);
  });
  chat.addEventListener('kai-message-action', (e) => {
    console.log(e.detail.messageId, e.detail.action);
  });
</script>
```

- **`messages`**: `id`, `role` (`'user' | 'assistant'`), an ordered `parts` array, plus optional `actions`, `avatar`, and `feedback`.
- **`loading`**: disables the input and shows a typing indicator while you await a reply.

### Message actions

Add `actions: ['copy', 'like', 'dislike']` and the action row wires itself: `copy` writes to the clipboard and shows a check, a vote hides the other side and toggles off on a second tap, and each raises a [toast](/components/toast/). See [Message](/components/message/#the-action-row).

`kai-message-action` reports votes with a `state` field — `'on'` when set, `'off'` when cleared:

```js
chat.addEventListener('kai-message-action', (e) => {
  const { messageId, action, state } = e.detail;
  if ((action === 'like' || action === 'dislike') && state === 'on') {
    saveVote(messageId, action);
  }
});
```

Set `feedback: 'like' | 'dislike'` on a message to re-hydrate a persisted vote; it wins over the element's optimistic state.
- **Model switcher** — set `models` (`{ id, name, provider? }[]`) and `currentModel`; listen for `kai-model-change`.
- **Context meter** — set `context` (`{ usedTokens, maxTokens, … }`) to show a token-usage gauge in the header.

## Examples

### Basic Thread

### Loading State

### Starter Suggestions

`suggestion-mode="fill"` populates the input instead of submitting.

### Model Switcher and Header

### Context Token Meter

### Entity Pills

`triggers` turns `/` into a skill pill and `@` into a sectioned menu of agents and plugins; `kai-submit` carries the structured `doc` + `entities`.

## Slots

A frame: keep the built-in thread and project your own chrome into named slots. `inject` adds to a region, `replace` stands in for it, and you own that region's data and events. See [Compose your own shell](/patterns/compose-your-own/).

## Styling

## Props

## Events

## Methods

## Composed from
