Skip to content
kitn AI/UI

Chat

kai-chat

A full-featured chat UI — thread, composer, and optional header — packaged as a single Shadow DOM web component for any framework.

  • Shadow DOM
  • 8 events
  • Markdown + syntax highlighting
  • Model switcher
  • Slash-command palette
  • Starter suggestions

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

<kai-chat id="chat" style="display:block; height:100vh;"></kai-chat>
<script type="module">
import '@kitn.ai/ui/elements';
const chat = document.getElementById('chat');
chat.messages = [
{ id: '1', role: 'user', content: 'How do I center a div?' },
{ id: '2', role: 'assistant', content: '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 — each entry: id, role ('user' | 'assistant'), content (markdown for assistant), plus optional actions, attachments, reasoning, tools, and avatar.
  • loading — flip to true while awaiting a reply; the input disables and a typing indicator appears.
  • 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.

suggestions — clickable prompts above an empty thread; suggestion-mode="fill" populates the input instead of submitting.

models + chat-title activates the header bar with a model-switcher dropdown.

Add context to show a live token-usage gauge — yellow near the warning threshold, red near danger.

slashCommands opens a palette on /; slash-compact uses single-line rows for dense layouts.

PropertyTypeDefaultNotes
messages [] The full message thread to render, newest last. Each entry carries its role, content, and optional reasoning/tools/attachments/actions. Set as a JS property (`el.messages = [...]`).
value Controlled value of the input. When set, the host owns the input text and must update it on `kai-value-change`; leave unset for uncontrolled behavior.
placeholder 'Send a message...' Placeholder text shown in the empty input.
loading false When true, shows the loading/streaming state and disables submit (use while awaiting the assistant's reply).
suggestions Starter prompts shown above the input when the thread is empty. Clicking one follows `suggestionMode`. Set as a JS property.
suggestionMode 'submit' What clicking a suggestion does: `'submit'` (default) sends it immediately as if typed and submitted; `'fill'` just places it in the input.
persistSuggestions false Keep suggestions visible after the conversation starts. By default suggestions are conversation starters and hide once `messages` is non-empty; set this to keep them always shown. Default false.
proseSize 'sm' Body/prose font scale for rendered markdown (`'xs' | 'sm' | 'base' | 'lg'`). Defaults to `'sm'`.
codeTheme 'github-dark-dimmed' Shiki theme name for syntax-highlighted code blocks (e.g. `'github-dark-dimmed'`).
codeHighlight true Enable Shiki syntax highlighting in code blocks. Turn off to render plain `<pre>` blocks (lighter, no highlighter load). Default true.
chatTitle Optional header title shown on the left of the header.
models Optional model list. When set (>1 model) a ModelSwitcher is shown in the header and a `kai-model-change` event fires on selection.
currentModel The currently selected model id (pairs with `models`).
context Optional context-window token usage. When set, a Context token meter is shown in the header.
scrollButton true Show the scroll-to-bottom button inside the scroll area. Default true.
headerStart Whether the host has `slot="header-start"` content (left of the title) — set by the `<kai-chat>` facade so a custom control forces the header open.
headerEnd Whether the host has `slot="header-end"` content (right of the controls).
search false Show a Search (Globe) button in the input toolbar; fires a `search` event.
voice false Show a Voice (Mic) button in the input toolbar; fires a `voice` event.
slashCommands Slash commands — when set, typing `/` in the input opens the command palette and fires `kai-slash-select`. Set as a JS property.
slashActiveIds Command ids to highlight as active in the palette.
slashCompact false Single-line palette rows.
actionsReveal 'always' Whether each message's action bar is always visible (`'always'`, default) or only revealed on hover of that message row (`'hover'`).
EventDetailNotes
An action button on a message was clicked. `action` is the built-in name or custom id.
The header model switcher changed.
Record<string, never> The Search button was clicked.
A slash command was chosen from the palette.
User submitted a message.
A suggestion chip was clicked (only in `suggestion-mode="fill"`).
Fired on every input change.
Record<string, never> The Mic / voice button was clicked.

This element wraps these SolidJS components — reach for them directly when you need finer control than the props expose.

ChatThread