AI chat surface primitives
patterns specs/patterns/ai-chat-surface.kmd
Six composable primitives for assembling an AI chat surface in any Koder product — Bubble, Sender, Suggestion, Attachment, Conversations, ThoughtChain. Modeled after Ant Design X, GitLab Duo Chat, ChatGPT / Claude desktop apps. Pairs with the AI visual language spec for marks + colors.
Quando este padrão se aplica
Triggers primários
- Implement chat UI for Koder Help / Kortex Assist / Eye Dialog / Koru Chat
Todos os triggers
- Build an AI chat surface in a Koder product
- Add a sidebar of past conversations
- Render an AI assistant reasoning trace
Corpo da especificação
Pattern — AI chat surface primitives
Status: v0.1.0 — Draft. Some primitives have a concrete companion spec under
specs/ai-ui/(chat-message-bubble); others are first- ratification here. Cross-link from each primitive page once shipped.
R1 — The six primitives
| Primitive | Role | Sub-spec (if any) |
|---|---|---|
| Bubble | Single message in the chat (user / assistant / system / error) | specs/ai-ui/chat-message-bubble.kmd |
| Sender | Composer with textarea + attachment slot + send-or-stop button | — |
| Suggestion | Chip row above sender (≤ 4 suggestions, dismissable) | — |
| Attachment | File/image preview cell inside Sender or Bubble | — |
| Conversations | Sidebar list of past sessions (new / rename / archive / delete) | — |
| ThoughtChain | Collapsible reasoning trace alongside the final answer | — |
R2 — Bubble
- Variants:
user,assistant,system,error. - Markdown rendering: per Koder markdown pipeline; code blocks use
specs/ai-ui/code-block.kmdwhen present. - Actions row (assistant only): copy, regenerate, edit, branch.
- Live-region announce:
aria-live="polite"on the bubble container so streamed assistant text reads progressively without jumping back. - Mandatory: AI mark + disclosure line per
specs/patterns/ai-feature-visual-language.kmd(assistant variant only).
R3 — Sender
- Auto-grow textarea (1 → 8 lines, then internal scroll).
- Attachment slot — paperclip icon opens picker; drag-and-drop also supported when the surface accepts files.
- Send button:
- Default state: disabled when textarea empty.
- During request: morphs to Stop button (square icon).
- Keyboard:
⌘+Enter(orCtrl+Enter) sends.Esccancels in-flight request.⌘+/(orCtrl+/) focuses the composer from anywhere on the page.
- Voice input slot (when
specs/voice/wake-word.kmdTalk Mode is enabled): mic icon adjacent to send.
R4 — Suggestion
- Maximum 4 chips, single row, horizontally scrollable on narrow viewports.
- Each chip: short label + optional leading icon.
- Tap chip → fills sender textarea (does NOT auto-send; user reviews before sending).
- Dismissable: chip set hides once user sends a message; new suggestions appear after each assistant reply.
R5 — Attachment
- Preview cell: 64×64 thumbnail for images; file-type icon + filename for non-images.
- Filename truncates with ellipsis at 24 chars; full name in title attr.
- Remove (×) button top-right; keyboard-accessible (Tab + Enter).
- Inside Bubble: shows the attachment that traveled with the message (read-only, no remove).
R6 — Conversations
- Sidebar list, ordered most-recent-first.
- Active conversation highlighted with
--kds-color-accentleft border. - Each row: title (auto-generated from first user message, max 32 chars)
- timestamp (relative for ≤ 7 days, absolute thereafter).
- Hover / focus actions: rename, archive, delete (with confirm modal).
- "New chat" button anchored at top.
- Date-grouped headings: Today / Yesterday / Last 7 days / Older
(per
specs/ai-ui/conversation-history.kmdif shipping that).
R7 — ThoughtChain
- Collapsible region between the user message and the final assistant answer.
- Collapsed by default; click to expand.
- Inside: ordered list of reasoning steps + tool calls + tool results, one per line with timestamp + step name.
- Streamed in same channel as the answer; consumer SHOULD render steps progressively as they arrive.
- Cross-link
specs/ai-ui/agent-step-trace.kmdfor richer agent-trace visualizations.
R8 — Live demo
/<locale>/patterns/patterns-ai-chat-surface.html (auto-rendered from
this spec via kind=pattern routing) embeds a fully-interactive demo
chat — HTMX-driven loop with mock responses simulating streaming and a
ThoughtChain expand. Backlog: a separate UI ticket in design-gen for
the demo page.
Não-escopo
- Streaming transport protocol (SSE / WebSocket — transport spec, not visual spec).
- Markdown rendering pipeline internals.
- Tool-call rendering (handled in dedicated
specs/ai-ui/companions).
Referências
specs/patterns/ai-feature-visual-language.kmdspecs/ai-ui/chat-message-bubble.kmdspecs/i18n/contract.kmdspecs/voice/wake-word.kmd