Skip to content
Focsd homeFocsd homeFocsd
Forms

Chat message

One message as an article, named by its author and time, with its parts in order.

  • Tag: focsd-chat-message
  • Pattern: Article in a feed
  • Category: AI

Example

HTML
<focsd-chat-message id="message-demo"></focsd-chat-message>
<script type="module">
document.getElementById('message-demo').message = {
id: 'a1',
role: 'assistant',
status: 'done',
createdAt: Date.now(),
parts: [
{ type: 'reasoning', text: 'The docs answer this, so search them first.' },
{ type: 'tool-call', id: 'c1', name: 'search_docs', input: { query: 'feed' }, status: 'done', output: { hits: 1 } },
{ type: 'text', text: 'A feed announces **one** reply at a time.' },
{ type: 'source', url: 'https://www.w3.org/WAI/ARIA/apg/patterns/feed/', title: 'Feed pattern' },
],
};
</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-message></focsd-chat-message>

API

Attributes

AttributePropertyTypeDefault
fromfromMessage['role'] | ''—
posinsetposinsetnumber0
setsizesetsizenumber0
tab-stoptabStopbooleanfalse

Methods

MethodDescription
focus(options)Focuses the article.

CSS parts

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

PartDescription
bubbleThe article.
authorThe author.
bodyThe parts.
metaThe time, and a note when the reply was stopped.

Accessibility

  • An article named "You, 9:05 AM" or "Assistant, 9:05 AM" (author and time). The parts render in order: text, reasoning, tool calls, sources and files.
  • User text is shown as plain text; assistant text is markdown (see streaming text).
  • A failed reply shows its error in the message. A stopped one notes "Response stopped". An assistant reply that is done shows its message actions.
  • Retry and feedback from the actions are passed on as focsd-retry and focsd-feedback.