Skip to content
Focsd homeFocsd homeFocsd
Forms

Chat thread

A conversation as a feed of messages that follows new text only while the reader is at the bottom.

  • Tag: focsd-chat-thread
  • Pattern: Feed (APG) with a jump-to-latest button
  • Category: AI

Example

HTML
<focsd-chat-thread id="thread-demo" label="Conversation"></focsd-chat-thread>
<script type="module">
const thread = document.getElementById('thread-demo');
thread.style.setProperty('--focsd-chat-thread-height', '18rem');
thread.messages = [
{ id: 'u1', role: 'user', status: 'done', createdAt: Date.now() - 60000, parts: [{ type: 'text', text: 'How is a reply announced?' }] },
{ id: 'a1', role: 'assistant', status: 'done', createdAt: Date.now(), parts: [{ type: 'text', text: 'Once, when it is **complete**. Never token by token.' }] },
];
</script>

Usage

Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.

<script type="module">
import '@focsd-dev/ai';
</script>
<focsd-chat-thread label="Conversation"></focsd-chat-thread>

API

Attributes

AttributePropertyTypeDefault
labellabelstring—

CSS parts

Style the inside of the component with ::part(), for example focsd-chat-thread::part(feed).

PartDescription
feedThe feed (the scroll container).
jumpThe "Jump to latest" button.

Accessibility

  • The thread is role="feed" named by label (default "Conversation"; until the first message it is a named group, because a feed must hold articles); each message is an article with aria-posinset and aria-setsize, and the one that is streaming has aria-busy="true".
  • There is no live region on the feed. When a reply finishes, the thread announces "Assistant replied:" and its text once, politely, cut at the last word before 300 characters. A stopped reply says "Response stopped"; a failed one says the error, assertively. History set all at once is silent.
  • It follows new content only while the reader is at the bottom. Scrolled up, a "Jump to latest" button appears; it scrolls down and moves focus to the latest message.
  • The feed is one tab stop (the last focused message, at first the latest). Page Down and Page Up move between messages; Ctrl+Home and Ctrl+End leave the feed, as the APG feed pattern describes.
  • Give it a chat controller with thread.chat = createChat({ transport }) and it shows and follows the controller; retry calls chat.retry(id) unless a listener cancels focsd-retry.

Keyboard

KeyAction
Page DownFocus the next message
Page UpFocus the previous message
Ctrl+HomeFocus the element before the feed
Ctrl+EndFocus the element after the feed
TabLeave the feed