Chat message
One message as an article, named by its author and time, with its parts in order.
Example
<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>import { useEffect, useRef } from 'react';import '@focsd-dev/ai';
export function Example() { const ref = useRef(null); return <focsd-chat-message ref={ref}></focsd-chat-message>;}<script setup>import '@focsd-dev/ai';</script>
<template> <focsd-chat-message></focsd-chat-message></template>// Add CUSTOM_ELEMENTS_SCHEMA to the component's schemas, then:import '@focsd-dev/ai';
// template<focsd-chat-message></focsd-chat-message><script> import '@focsd-dev/ai';</script>
<focsd-chat-message></focsd-chat-message>API
Attributes
| Attribute | Property | Type | Default |
|---|---|---|---|
from | from | Message['role'] | '' | — |
posinset | posinset | number | 0 |
setsize | setsize | number | 0 |
tab-stop | tabStop | boolean | false |
Methods
| Method | Description |
|---|---|
focus(options) | Focuses the article. |
CSS parts
Style the inside of the component with ::part(), for example focsd-chat-message::part(bubble).
| Part | Description |
|---|---|
bubble | The article. |
author | The author. |
body | The parts. |
meta | The time, and a note when the reply was stopped. |
Accessibility
- An
articlenamed "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-retryandfocsd-feedback.
Ask the docs
Hi, what are you building?
Ask about any component, theming, forms or frameworks. I answer with the right component, a snippet and a link to its docs.