# Angular Chat Component

Chat is an accessible conversation UI for AI assistants: answers streamed as Markdown with a stop button, a composer with attachments and suggestions, copy, regenerate, feedback and edit actions, older messages loaded on scroll, and screen reader announcements of each complete answer. It works with any model or backend.

## Basic

Chat displays the messages , each with a unique id , a role ( user , assistant or system ) and a Markdown content . When the user sends a message, send emits its text: add it to the messages with an empty assistant message whose status is streaming , then append the tokens of the answer to its content and set its status to done at the end. This demo streams a fake answer, without network.

```typescript
import { Component, DestroyRef, inject, signal } from '@angular/core';
import { ChatMessage, ChatModule, ChatSendEvent } from '@exhaustive-ui/core/chat';

@Component({
    template: `
        <div class="card">
            <p-chat class="h-[28rem]" [messages]="messages()" placeholder="Ask about ExhaustiveUI" (send)="onSend($event)" (stop)="stop()" />
        </div>
    `,
    standalone: true,
    imports: [ChatModule]
})
export class ChatBasicDemo {
    messages = signal<ChatMessage[]>([{ id: 1, role: 'assistant', content: 'Hi! I am a **demo assistant**: my answers are written in advance and streamed token by token. Ask me anything.' }]);

    private nextId = 2;

    private timer?: ReturnType<typeof setInterval>;

    constructor() {
        inject(DestroyRef).onDestroy(() => clearInterval(this.timer));
    }

    onSend({ text }: ChatSendEvent) {
        const answerId = this.nextId + 1;
        this.messages.update((messages) => [...messages, { id: this.nextId, role: 'user', content: text }, { id: answerId, role: 'assistant', content: '', status: 'streaming' }]);
        this.nextId += 2;
        this.stream(answerId, this.answer(text));
    }

    stop() {
        clearInterval(this.timer);
        this.messages.update((messages) => messages.map((message) => (message.status === 'streaming' ? { ...message, status: 'done' } : message)));
    }

    // a fake language model: appends a few characters every 30ms
    private stream(id: number, answer: string) {
        let length = 0;
        clearInterval(this.timer);
        this.timer = setInterval(() => {
            length = Math.min(answer.length, length + 2 + Math.floor(Math.random() * 5));
            const done = length >= answer.length;
            this.messages.update((messages) => messages.map((message) => (message.id === id ? { ...message, content: answer.slice(0, length), status: done ? 'done' : 'streaming' } : message)));
            if (done) {
                clearInterval(this.timer);
            }
        }, 30);
    }

    private answer(question: string) {
        return [
            `You asked: *${question}*. Here is what a streamed answer can hold:`,
            '',
            '- **Markdown**, rendered while it arrives',
            '- `inline code` and code blocks with a copy button',
            '',
            '```ts',
            "messages.update((list) => [...list, { id, role: 'assistant', content: '', status: 'streaming' }]);",
            '```',
            '',
            'Screen readers hear the answer once it is complete, not token by token.'
        ].join('\n');
    }
}
```

## Streaming and Stop

While a message has the streaming status, or while generating is set, the send button becomes a stop button that emits stop : cancel the request there, keep the text received so far and set the status to done . The conversation is aria-busy and the answer shows a caret. Enter does not send another message until the answer is complete. A request that fails sets the error status, with an optional error text: the answer shows the error and a Retry button that emits retry . The conversation stays at its newest message while the answer grows, only if the reader is already there: scroll up during an answer and a Jump to latest button appears instead.

```typescript
import { Component, DestroyRef, inject, signal } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { ChatMessage, ChatMessageEvent, ChatModule, ChatSendEvent } from '@exhaustive-ui/core/chat';
import { ToggleSwitchModule } from '@exhaustive-ui/core/toggleswitch';

@Component({
    template: `
        <div class="card flex flex-col gap-4">
            <div class="flex items-center gap-2">
                <p-toggle-switch inputId="chat-fail" [(ngModel)]="fail" />
                <label for="chat-fail">Fail the next answer</label>
            </div>
            <p-chat class="h-[28rem]" [messages]="messages()" placeholder="Ask for a long answer" (send)="onSend($event)" (stop)="stop()" (retry)="onRetry($event)" />
        </div>
    `,
    standalone: true,
    imports: [ChatModule, FormsModule, ToggleSwitchModule]
})
export class ChatStreamingDemo {
    messages = signal<ChatMessage[]>([]);

    fail = false;

    private nextId = 1;

    private timer?: ReturnType<typeof setInterval>;

    constructor() {
        inject(DestroyRef).onDestroy(() => clearInterval(this.timer));
    }

    onSend({ text }: ChatSendEvent) {
        this.messages.update((messages) => [...messages, { id: this.nextId++, role: 'user', content: text }]);
        this.ask();
    }

    onRetry({ message }: ChatMessageEvent) {
        // drop the failed answer and ask again
        this.messages.update((messages) => messages.filter((item) => item.id !== message.id));
        this.ask();
    }

    stop() {
        clearInterval(this.timer);
        this.messages.update((messages) => messages.map((message) => (message.status === 'streaming' ? { ...message, status: 'done' } : message)));
    }

    private ask() {
        const id = this.nextId++;
        const fail = this.fail;
        this.fail = false;
        this.messages.update((messages) => [...messages, { id, role: 'assistant', content: '', status: 'streaming' }]);
        const answer = Array.from({ length: 24 }, (_, index) => `${index + 1}. A **step** of a long answer, streamed token by token so that you have time to stop it.`).join('\n');
        let length = 0;
        clearInterval(this.timer);
        this.timer = setInterval(() => {
            length = Math.min(answer.length, length + 3 + Math.floor(Math.random() * 4));
            if (fail && length > answer.length / 3) {
                clearInterval(this.timer);
                this.update(id, { status: 'error', error: 'The connection was lost. Your question was not lost: retry it.' });
                return;
            }
            const done = length >= answer.length;
            this.update(id, { content: answer.slice(0, length), status: done ? 'done' : 'streaming' });
            if (done) {
                clearInterval(this.timer);
            }
        }, 30);
    }

    private update(id: number, changes: Partial<ChatMessage>) {
        this.messages.update((messages) => messages.map((message) => (message.id === id ? { ...message, ...changes } : message)));
    }
}
```

## Suggestions

suggestions are prompts shown above the composer while the conversation is empty. A suggestion is a text, or an object with a visible label and the text to send. Choosing one emits send right away. Use maxLength to limit the length of a message: a counter appears in the composer.

```typescript
import { Component, signal } from '@angular/core';
import { ChatMessage, ChatModule, ChatSendEvent, ChatSuggestion } from '@exhaustive-ui/core/chat';

@Component({
    template: `
        <div class="card">
            <p-chat class="h-96" [messages]="messages()" [suggestions]="suggestions" [maxLength]="500" (send)="onSend($event)" />
        </div>
    `,
    standalone: true,
    imports: [ChatModule]
})
export class ChatSuggestionsDemo {
    messages = signal<ChatMessage[]>([]);

    suggestions: (string | ChatSuggestion)[] = ['What is a signal?', 'Write a unit test for a pipe', { label: 'Explain OnPush', text: 'Explain the OnPush change detection strategy in two sentences.' }];

    private nextId = 1;

    onSend({ text }: ChatSendEvent) {
        this.messages.update((messages) => [...messages, { id: this.nextId++, role: 'user', content: text }]);
        setTimeout(() => {
            this.messages.update((messages) => [...messages, { id: this.nextId++, role: 'assistant', content: `Good question! This demo does not call a model, but your app would answer *${text}* here.` }]);
        }, 500);
    }
}
```

## Attachments

With allowAttachments , the composer has an attach button that opens the file picker, filtered by accept ; files can also be pasted in the textarea. The files to send are listed as chips with a labelled remove button, up to maxAttachments , and send emits them with the text, each with its file . A message can then show its attachments , with a link when they have a url . draftAttachments holds the files to send, to validate or add them from the application.

```typescript
import { Component, signal } from '@angular/core';
import { ChatMessage, ChatModule, ChatSendEvent } from '@exhaustive-ui/core/chat';

@Component({
    template: `
        <div class="card">
            <p-chat class="h-96" [messages]="messages()" allowAttachments accept="image/*,.pdf,.txt,.md" [maxAttachments]="3" placeholder="Attach up to 3 files" (send)="onSend($event)" />
        </div>
    `,
    standalone: true,
    imports: [ChatModule]
})
export class ChatAttachmentsDemo {
    messages = signal<ChatMessage[]>([]);

    private nextId = 1;

    onSend({ text, attachments }: ChatSendEvent) {
        // keep the name and size only: upload the files to your server to give them a url
        const files = attachments.map(({ id, name, size, type }) => ({ id, name, size, type }));
        this.messages.update((messages) => [...messages, { id: this.nextId++, role: 'user', content: text, attachments: files }]);
        const names = files.map((file) => `\`${file.name}\``).join(', ');
        setTimeout(() => {
            this.messages.update((messages) => [...messages, { id: this.nextId++, role: 'assistant', content: files.length ? `I received ${files.length} file(s): ${names}.` : 'Attach a file to try it.' }]);
        }, 500);
    }
}
```

## Actions

Every complete message has a copy button, hidden with copyButton false: it copies the Markdown of the message, shows Copied , announces it and emits messageCopy . The last answer has a regenerate button that emits retry , hidden with retryButton false. With feedback , the answers have thumbs up and down toggle buttons: feedbackChange emits the new value, store it in the feedback of the message. With editable , the last user message has an edit button that opens it in a textarea: Enter saves and emits edit with the new text, Escape cancels.

```typescript
import { Component, DestroyRef, inject, signal } from '@angular/core';
import { ChatEditEvent, ChatFeedbackEvent, ChatMessage, ChatMessageEvent, ChatModule, ChatSendEvent } from '@exhaustive-ui/core/chat';

@Component({
    template: `
        <div class="card">
            <p-chat class="h-[30rem]" [messages]="messages()" feedback editable (send)="onSend($event)" (stop)="stop()" (retry)="onRetry($event)" (feedbackChange)="onFeedback($event)" (edit)="onEdit($event)" />
        </div>
    `,
    standalone: true,
    imports: [ChatModule]
})
export class ChatActionsDemo {
    messages = signal<ChatMessage[]>([
        { id: 1, role: 'user', content: 'Give me a name for a cat.' },
        { id: 2, role: 'assistant', content: 'How about **Pixel**? It is short, modern and easy to call.' }
    ]);

    private nextId = 3;

    private names = ['Miso', 'Biscuit', 'Nimbus', 'Pepper', 'Mochi', 'Ziggy'];

    private timer?: ReturnType<typeof setInterval>;

    constructor() {
        inject(DestroyRef).onDestroy(() => clearInterval(this.timer));
    }

    onSend({ text }: ChatSendEvent) {
        this.messages.update((messages) => [...messages, { id: this.nextId++, role: 'user', content: text }]);
        this.answer();
    }

    onRetry({ message }: ChatMessageEvent) {
        // regenerate: replace the answer with a new one
        this.messages.update((messages) => messages.filter((item) => item.id !== message.id));
        this.answer();
    }

    onFeedback({ message, value }: ChatFeedbackEvent) {
        this.messages.update((messages) => messages.map((item) => (item.id === message.id ? { ...item, feedback: value } : item)));
    }

    onEdit({ message, text }: ChatEditEvent) {
        // keep the conversation up to the edited message, then answer it again
        const index = this.messages().findIndex((item) => item.id === message.id);
        this.messages.update((messages) => [...messages.slice(0, index), { ...message, content: text }]);
        this.answer();
    }

    stop() {
        clearInterval(this.timer);
        this.messages.update((messages) => messages.map((message) => (message.status === 'streaming' ? { ...message, status: 'done' } : message)));
    }

    private answer() {
        const id = this.nextId++;
        const name = this.names[Math.floor(Math.random() * this.names.length)];
        const answer = `What about **${name}**? Press the regenerate button for another idea, or rate this one.`;
        this.messages.update((messages) => [...messages, { id, role: 'assistant', content: '', status: 'streaming' }]);
        let length = 0;
        clearInterval(this.timer);
        this.timer = setInterval(() => {
            length = Math.min(answer.length, length + 3);
            const done = length >= answer.length;
            this.messages.update((messages) => messages.map((message) => (message.id === id ? { ...message, content: answer.slice(0, length), status: done ? 'done' : 'streaming' } : message)));
            if (done) {
                clearInterval(this.timer);
            }
        }, 30);
    }
}
```

## History

A long conversation can be loaded page by page. With hasMoreHistory , scrolling to the start of the conversation emits loadHistory with the oldest message shown: set loadingHistory while older messages load, prepend them, and turn hasMoreHistory off at the start of the conversation. The messages in view keep their position while older ones are inserted above them. The list is built on the InfiniteScroll directive: screen readers hear when older messages load and when the start is reached, and Page Up and Page Down move the focus from message to message. The messages loaded this way are not announced as new answers.

```typescript
import { Component, DestroyRef, inject, signal } from '@angular/core';
import { ChatMessage, ChatModule, ChatSendEvent } from '@exhaustive-ui/core/chat';

@Component({
    template: `
        <div class="card">
            <p-chat class="h-96" [messages]="messages()" [hasMoreHistory]="hasMore()" [loadingHistory]="loading()" (loadHistory)="loadOlder()" (send)="onSend($event)" />
        </div>
    `,
    standalone: true,
    imports: [ChatModule]
})
export class ChatHistoryDemo {
    // a conversation of 60 messages, of which the 10 newest are shown first
    private archive: ChatMessage[] = Array.from({ length: 60 }, (_, index) => ({
        id: index + 1,
        role: index % 2 ? 'assistant' : 'user',
        content: index % 2 ? `Answer **${(index + 1) / 2}**, loaded from the history.` : `Question ${index / 2 + 1}`,
        createdAt: new Date(2026, 10, 30, 9, index)
    }));

    messages = signal<ChatMessage[]>(this.archive.slice(-10));

    loading = signal(false);

    hasMore = signal(true);

    private nextId = 1000;

    private timer?: ReturnType<typeof setTimeout>;

    constructor() {
        inject(DestroyRef).onDestroy(() => clearTimeout(this.timer));
    }

    loadOlder() {
        this.loading.set(true);
        // simulates a request for the 10 messages before the oldest one shown
        this.timer = setTimeout(() => {
            const oldest = this.archive.findIndex((message) => message.id === this.messages()[0].id);
            const older = this.archive.slice(Math.max(0, oldest - 10), oldest);
            this.messages.update((messages) => [...older, ...messages]);
            this.hasMore.set(oldest - 10 > 0);
            this.loading.set(false);
        }, 700);
    }

    onSend({ text }: ChatSendEvent) {
        this.messages.update((messages) => [...messages, { id: this.nextId++, role: 'user', content: text, createdAt: new Date() }]);
    }
}
```

## Template

The header and footer templates frame the conversation, and the empty template replaces the empty state; it receives a send function. The avatar template receives the message, its role and the name of its author, and is shown for the roles of avatars . The message template replaces the content of the messages: it receives the message, its index , last and streaming . The composerActions template adds buttons to the toolbar of the composer, with the text being written and an insert function that inserts a text at the caret.

```typescript
import { Component, signal } from '@angular/core';
import { AvatarModule } from '@exhaustive-ui/core/avatar';
import { ButtonModule } from '@exhaustive-ui/core/button';
import { ChatMessage, ChatModule, ChatSendEvent } from '@exhaustive-ui/core/chat';
import { MarkdownModule } from '@exhaustive-ui/core/markdown';
import { book, plus, sparkles } from '@exhaustive-ui/icons/round';
import { SvgIcon } from '@exhaustive-ui/core/icon';

@Component({
    template: `
        <div class="card">
            <p-chat class="h-[30rem]" [messages]="messages()" avatars="all" (send)="onSend($event)">
                <ng-template #header>
                    <div class="flex items-center justify-between gap-2">
                        <div class="flex items-center gap-2">
                            <svg pIcon [icon]="sparkles" class="text-primary" aria-hidden="true"></svg>
                            <h3 class="m-0 text-base font-semibold">Recipe assistant</h3>
                        </div>
                        <p-button label="New chat" [icon]="plus" [text]="true" size="small" (onClick)="messages.set([])" />
                    </div>
                </ng-template>
                <ng-template #empty let-send="send">
                    <div class="flex flex-col items-center gap-3">
                        <svg pIcon [icon]="book" class="text-3xl text-primary" aria-hidden="true"></svg>
                        <p class="m-0 text-lg font-semibold">What shall we cook today?</p>
                        <p-button label="Surprise me" [outlined]="true" size="small" (onClick)="send('Suggest a dinner recipe')" />
                    </div>
                </ng-template>
                <ng-template #avatar let-role="role">
                    @if (role === 'user') {
                        <p-avatar label="JD" shape="circle" />
                    } @else {
                        <p-avatar [icon]="sparkles" shape="circle" />
                    }
                </ng-template>
                <ng-template #message let-message let-streaming="streaming">
                    @if (message.role === 'user') {
                        <span class="whitespace-pre-wrap">{{ message.content }}</span>
                    } @else {
                        <p-markdown [value]="message.content" [streaming]="streaming" />
                        <span class="block mt-2 text-xs text-muted-color">Chef model · demo</span>
                    }
                </ng-template>
                <ng-template #composerActions let-insert="insert" let-disabled="disabled">
                    <p-button label="Vegetarian" [icon]="plus" [text]="true" size="small" [disabled]="disabled" (onClick)="insert('vegetarian ')" />
                </ng-template>
                <ng-template #footer>Answers are generated and may be inaccurate.</ng-template>
            </p-chat>
        </div>
    `,
    standalone: true,
    imports: [SvgIcon, ChatModule, AvatarModule, ButtonModule, MarkdownModule]
})
export class ChatTemplateDemo {
    sparkles = sparkles;
    plus = plus;
    book = book;

    messages = signal<ChatMessage[]>([]);

    private nextId = 1;

    onSend({ text }: ChatSendEvent) {
        this.messages.update((messages) => [...messages, { id: this.nextId++, role: 'user', content: text }]);
        setTimeout(() => {
            const answer = `Here is an idea for *${text}*:\n\n1. **Lemon risotto** with peas\n2. A green salad\n3. Strawberries for dessert`;
            this.messages.update((messages) => [...messages, { id: this.nextId++, role: 'assistant', content: answer }]);
        }, 500);
    }
}
```

## Integration

Chat does not talk to a model itself: wire send , stop and retry to your backend. Keep the API key of the model provider on the server: the browser calls an endpoint of your application, here /api/chat , that forwards the conversation to the model and streams the answer back, for example as plain text chunks or server-sent events. In the browser, fetch reads the response body as a stream and each chunk is appended to the content of the streaming message. An AbortController cancels the request when the stop button is pressed, and a failed request sets the error status so that the answer offers to retry. This example is not run on this page: it needs your own endpoint. The endpoint can stream the text of the model as it arrives, for example with Node.js and the SDK of the provider of your choice:

## Accessibility

Screen Reader The conversation is a scrollable group named "Conversation" that can be focused to scroll it with the keyboard; it is not a landmark, so that a page can hold several chats. Each message is an article named by its author, "You" or "Assistant" by default or the author.name of the message; the name of the user is visually hidden. Avatars are decorative and hidden from screen readers. The answers are rendered with Markdown: headings, lists, tables and code blocks keep their native semantics. The text of an answer is not announced token by token. A visually hidden log region, polite, receives each answer once it is complete, as plain text: an answer whose status leaves streaming , or a complete answer added at the end of the conversation. The messages present at start and the older messages loaded with the history are not announced, and an answer in error is announced with its error. announceMessages turns this off. While an answer is generated, the conversation and the answer are aria-busy and a polite status announces "Generating an answer"; stopping it announces "Generation stopped". The textarea of the composer is named "Message" and described by the character counter when maxLength is set. The send button is named "Send"; it keeps the focus and becomes "Stop generating" while an answer is generated. It is never disabled while it has the focus: when there is nothing to send it is aria-disabled . The icon buttons of the messages are named "Copy", "Regenerate", "Good response", "Bad response" and "Edit"; the thumbs are toggle buttons with aria-pressed , and a copy announces "Copied". The actions of a message are grouped and named "Message actions". The suggestions and the attachments are lists named "Suggestions" and "Attached files", and each remove button is named "Remove" followed by the file name. Every text, announcements included, can be translated with labels .

```typescript
<p-chat [messages]="messages()" [labels]="{ messages: 'Conversation avec l’assistant', input: 'Votre message', send: 'Envoyer', stop: 'Arrêter', user: 'Vous' }" />
```

## Chat

Chat is an accessible conversation UI for AI assistants: streamed Markdown answers, a composer with attachments and suggestions, copy, regenerate, feedback and edit actions, older messages loaded on scroll and screen reader announcements of the complete answers.

### Props

| Name | Type | Default | Description |
|------|------|---------|-------------|
| dt | Object | undefined | Defines scoped design tokens of the component. |
| unstyled | boolean | undefined | Indicates whether the component should be rendered without styles. |
| pt | ChatPassThrough | undefined | Used to pass attributes to DOM elements inside the component. |
| ptOptions | PassThroughOptions | undefined | Used to configure passthrough(pt) options of the component. |
| messages | ChatMessage[] | [] | Messages of the conversation, from the oldest to the newest. Each message needs a unique id. |
| generating | boolean | false | Whether an answer is being generated: the send button becomes a stop button and the conversation is aria-busy. A message with the streaming status has the same effect. |
| draft | string | '' | Text being written in the composer. |
| draftAttachments | ChatAttachment[] | [] | Files attached to the message being written. |
| placeholder | string | - | Placeholder of the composer. |
| disabled | boolean | false | When present, the composer and the suggestions are disabled. |
| maxLength | number | - | Maximum number of characters of a message. Shows a counter. |
| sendOnEnter | boolean | true | Whether Enter sends the message and Shift+Enter adds a line. When false, Enter adds a line and Ctrl+Enter or ⌘+Enter sends. |
| autofocus | boolean | false | Whether the composer takes the focus once rendered. |
| suggestions | (string \| ChatSuggestion)[] | - | Suggested prompts shown while the conversation is empty. Choosing one sends it. |
| allowAttachments | boolean | false | Whether files can be attached, with the attach button or by pasting them. |
| accept | string | - | File types accepted by the file picker, as in the accept attribute. |
| maxAttachments | number | - | Maximum number of files attached to a message. |
| copyButton | boolean | true | Whether the messages have a copy button. |
| retryButton | boolean | true | Whether the last answer has a regenerate button and the answers in error a retry button. |
| feedback | boolean | false | Whether the answers have thumbs up and down buttons. |
| editable | boolean | false | Whether the last user message can be edited. |
| avatars | ChatAvatars | 'assistant' | Messages that show an avatar. |
| markdown | boolean | true | Whether the answers are rendered as Markdown. When false, they are shown as plain text. |
| linkTarget | string | - | Target of the links of the answers to other sites, such as  `_blank` . |
| dateFormat | string | 'shortTime' | Format of the time of the messages, as in the date pipe. |
| hasMoreHistory | boolean | false | Whether there are older messages to load when the conversation is scrolled to its start. |
| loadingHistory | boolean | false | Whether older messages are loading. |
| announceMessages | boolean | true | Whether the complete answers are announced to screen readers. |
| labels | Partial<ChatLabels> | - | Texts of the component, merged with the default ones. |

### Emits

| Name | Parameters | Description |
|------|------------|-------------|
| send | event: ChatSendEvent | Callback to invoke when a message is sent, with its text and its attachments. The composer is then emptied. |
| stop | value: void | Callback to invoke when the stop button is pressed while an answer is generated. |
| retry | event: ChatMessageEvent | Callback to invoke when the retry button of an answer in error or the regenerate button of the last answer is pressed. |
| feedbackChange | event: ChatFeedbackEvent | Callback to invoke when a thumb is pressed. |
| edit | event: ChatEditEvent | Callback to invoke when the last user message is edited. |
| messageCopy | event: ChatCopyEvent | Callback to invoke when a message is copied. |
| loadHistory | event: ChatLoadHistoryEvent | Callback to invoke when the conversation is scrolled to its start and hasMoreHistory is set, to load older messages. |

### Templates

| Name | Type | Description |
|------|------|-------------|
| message | TemplateRef<ChatMessageTemplateContext> | Custom content of a message. |
| avatar | TemplateRef<ChatAvatarTemplateContext> | Custom avatar. |
| empty | TemplateRef<ChatEmptyTemplateContext> | Custom empty state. |
| header | TemplateRef<void> | Custom header. |
| footer | TemplateRef<void> | Custom footer. |
| composerActions | TemplateRef<ChatComposerActionsTemplateContext> | Custom buttons of the composer toolbar. |

### Methods

| Name | Parameters | Return Type | Description |
|------|------------|-------------|-------------|
| submit |  | void | Sends the text of the composer with its attachments, unless it is empty, disabled or an answer is being generated. |
| sendText | text: string | void | Sends a text, with the attachments of the composer, as when a suggestion is chosen. |
| insert | text: string | void | Inserts a text at the caret of the composer. |
| focus |  | void | Moves the focus to the composer. |
| addFiles | files: File[] | void | Attaches files to the message being written, up to maxAttachments. |
| copy | message: ChatMessage | void | Copies the content of a message to the clipboard and announces it. |
| scrollToBottom | smooth: boolean | void | Scrolls the conversation to its newest message. |

## Pass Through Options

| Name | Type | Description |
|------|------|-------------|
| root | PassThroughOption<HTMLElement, I> | Used to pass attributes to the root's DOM element. |
| header | PassThroughOption<HTMLDivElement, I> | Used to pass attributes to the header, around the header template. |
| body | PassThroughOption<HTMLDivElement, I> | Used to pass attributes to the container of the message list and the jump to latest button. |
| messages | PassThroughOption<HTMLDivElement, I> | Used to pass attributes to the scrollable region of the conversation. |
| list | PassThroughOption<HTMLDivElement, I> | Used to pass attributes to the list of messages. |
| historyLoader | PassThroughOption<HTMLDivElement, I> | Used to pass attributes to the indicator shown while older messages load. |
| message | PassThroughOption<HTMLElement, I> | Used to pass attributes to each message. |
| avatar | PassThroughOption<HTMLDivElement, I> | Used to pass attributes to the avatar of a message. |
| bubble | PassThroughOption<HTMLDivElement, I> | Used to pass attributes to the bubble of a message, around its author, content, attachments and actions. |
| meta | PassThroughOption<HTMLDivElement, I> | Used to pass attributes to the author and time of a message. |
| author | PassThroughOption<HTMLSpanElement, I> | Used to pass attributes to the name of the author of a message. |
| time | PassThroughOption<HTMLTimeElement, I> | Used to pass attributes to the time of a message. |
| content | PassThroughOption<HTMLDivElement, I> | Used to pass attributes to the content of a message. |
| messageAttachments | PassThroughOption<HTMLUListElement, I> | Used to pass attributes to the list of the attachments of a message. |
| messageAttachment | PassThroughOption<HTMLLIElement, I> | Used to pass attributes to an attachment of a message. |
| error | PassThroughOption<HTMLDivElement, I> | Used to pass attributes to the error of a message. |
| retryButton | PassThroughOption<HTMLButtonElement, I> | Used to pass attributes to the retry button of a message in error. |
| actions | PassThroughOption<HTMLDivElement, I> | Used to pass attributes to the actions of a message. |
| action | PassThroughOption<HTMLButtonElement, I> | Used to pass attributes to the action buttons of a message: copy, regenerate, feedback and edit. |
| editor | PassThroughOption<HTMLDivElement, I> | Used to pass attributes to the form that edits a message. |
| editInput | PassThroughOption<HTMLTextAreaElement, I> | Used to pass attributes to the textarea that edits a message. |
| editButton | PassThroughOption<HTMLButtonElement, I> | Used to pass attributes to the save and cancel buttons of the edit form. |
| jumpButton | PassThroughOption<HTMLButtonElement, I> | Used to pass attributes to the jump to latest button. |
| empty | PassThroughOption<HTMLDivElement, I> | Used to pass attributes to the empty state. |
| emptyTitle | PassThroughOption<HTMLParagraphElement, I> | Used to pass attributes to the title of the empty state. |
| suggestions | PassThroughOption<HTMLUListElement, I> | Used to pass attributes to the list of suggestions. |
| suggestion | PassThroughOption<HTMLButtonElement, I> | Used to pass attributes to each suggestion button. |
| composer | PassThroughOption<HTMLDivElement, I> | Used to pass attributes to the composer, at the bottom. |
| composerBox | PassThroughOption<HTMLDivElement, I> | Used to pass attributes to the frame of the composer, around the attachments, the textarea and the buttons. |
| attachmentList | PassThroughOption<HTMLUListElement, I> | Used to pass attributes to the list of the attachments to send. |
| attachment | PassThroughOption<HTMLLIElement, I> | Used to pass attributes to an attachment to send. |
| attachmentRemoveButton | PassThroughOption<HTMLButtonElement, I> | Used to pass attributes to the remove button of an attachment to send. |
| input | PassThroughOption<HTMLTextAreaElement, I> | Used to pass attributes to the textarea of the composer. |
| toolbar | PassThroughOption<HTMLDivElement, I> | Used to pass attributes to the toolbar of the composer. |
| attachButton | PassThroughOption<HTMLButtonElement, I> | Used to pass attributes to the attach button. |
| fileInput | PassThroughOption<HTMLInputElement, I> | Used to pass attributes to the hidden file input. |
| counter | PassThroughOption<HTMLSpanElement, I> | Used to pass attributes to the character counter. |
| sendButton | PassThroughOption<HTMLButtonElement, I> | Used to pass attributes to the send button, which is the stop button while an answer is generated. |
| footer | PassThroughOption<HTMLDivElement, I> | Used to pass attributes to the footer, around the footer template. |

## Theming

### CSS Classes

| Class | Description |
|-------|-------------|
| p-chat | Class name of the root element |
| p-chat-generating | Class name of the root element while an answer is generated |
| p-chat-header | Class name of the header element |
| p-chat-body | Class name of the element around the conversation and the jump to latest button |
| p-chat-messages | Class name of the scrollable region of the conversation |
| p-chat-list | Class name of the list of messages |
| p-chat-history-loader | Class name of the indicator shown while older messages load |
| p-chat-message | Class name of a message |
| p-chat-message-user | Class name of a user message |
| p-chat-message-assistant | Class name of an assistant message |
| p-chat-message-system | Class name of a system message |
| p-chat-message-streaming | Class name of a message being streamed |
| p-chat-message-error | Class name of a message in error |
| p-chat-avatar | Class name of the avatar of a message |
| p-chat-bubble | Class name of the bubble of a message |
| p-chat-meta | Class name of the author and time of a message |
| p-chat-author | Class name of the author of a message |
| p-chat-time | Class name of the time of a message |
| p-chat-content | Class name of the content of a message |
| p-chat-message-attachments | Class name of the attachments of a message |
| p-chat-error | Class name of the error of a message |
| p-chat-retry-button | Class name of the retry button |
| p-chat-actions | Class name of the actions of a message |
| p-chat-action | Class name of an action button |
| p-chat-editor | Class name of the edit form |
| p-chat-jump-button | Class name of the jump to latest button |
| p-chat-empty | Class name of the empty state |
| p-chat-suggestions | Class name of the list of suggestions |
| p-chat-suggestion | Class name of a suggestion |
| p-chat-composer | Class name of the composer |
| p-chat-composer-box | Class name of the frame of the composer |
| p-chat-attachment | Class name of an attachment to send |
| p-chat-input | Class name of the textarea of the composer |
| p-chat-toolbar | Class name of the toolbar of the composer |
| p-chat-attach-button | Class name of the attach button |
| p-chat-counter | Class name of the character counter |
| p-chat-send-button | Class name of the send button |
| p-chat-stop-button | Class name of the send button while it stops the generation |
| p-chat-footer | Class name of the footer |

### Design Tokens

| Token | CSS Variable | Description |
|-------|--------------|-------------|
| chat.background | --p-chat-background | Background of the component |
| chat.border.color | --p-chat-border-color | Border color of the component |
| chat.border.radius | --p-chat-border-radius | Border radius of the component |
| chat.color | --p-chat-color | Color of the component |
| chat.transition.duration | --p-chat-transition-duration | Transition duration of the component |
| chat.header.padding | --p-chat-header-padding | Padding of the header |
| chat.header.border.color | --p-chat-header-border-color | Border color of the header |
| chat.messages.focus.ring.width | --p-chat-messages-focus-ring-width | Focus ring width of the scrollable conversation |
| chat.messages.focus.ring.style | --p-chat-messages-focus-ring-style | Focus ring style of the scrollable conversation |
| chat.messages.focus.ring.color | --p-chat-messages-focus-ring-color | Focus ring color of the scrollable conversation |
| chat.messages.focus.ring.offset | --p-chat-messages-focus-ring-offset | Focus ring offset of the scrollable conversation |
| chat.messages.focus.ring.shadow | --p-chat-messages-focus-ring-shadow | Focus ring shadow of the scrollable conversation |
| chat.list.padding | --p-chat-list-padding | Padding of the list of messages |
| chat.list.gap | --p-chat-list-gap | Gap of the list of messages |
| chat.message.gap | --p-chat-message-gap | Gap of a message |
| chat.message.user.max.width | --p-chat-message-user-max-width | Maximum width of the user messages |
| chat.avatar.size | --p-chat-avatar-size | Size of the avatar |
| chat.avatar.border.radius | --p-chat-avatar-border-radius | Border radius of the avatar |
| chat.avatar.font.size | --p-chat-avatar-font-size | Font size of the avatar |
| chat.avatar.icon.size | --p-chat-avatar-icon-size | Size of the icon of the avatar |
| chat.avatar.background | --p-chat-avatar-background | Background of the avatar |
| chat.avatar.color | --p-chat-avatar-color | Color of the avatar |
| chat.bubble.padding | --p-chat-bubble-padding | Padding of the bubble of a message |
| chat.bubble.border.radius | --p-chat-bubble-border-radius | Border radius of the bubble of a message |
| chat.bubble.gap | --p-chat-bubble-gap | Gap of the bubble of a message |
| chat.bubble.user.background | --p-chat-bubble-user-background | Background of the user messages |
| chat.bubble.user.color | --p-chat-bubble-user-color | Text color of the user messages |
| chat.meta.color | --p-chat-meta-color | Color of the author and time of a message |
| chat.meta.author.color | --p-chat-meta-author-color | Color of the author name |
| chat.meta.author.font.weight | --p-chat-meta-author-font-weight | Font weight of the author name |
| chat.meta.font.size | --p-chat-meta-font-size | Font size of the author and time of a message |
| chat.meta.gap | --p-chat-meta-gap | Gap of the author and time of a message |
| chat.system.color | --p-chat-system-color | Color of a system message |
| chat.system.font.size | --p-chat-system-font-size | Font size of a system message |
| chat.error.border.radius | --p-chat-error-border-radius | Border radius of the error of a message |
| chat.error.padding | --p-chat-error-padding | Padding of the error of a message |
| chat.error.gap | --p-chat-error-gap | Gap of the error of a message |
| chat.error.font.size | --p-chat-error-font-size | Font size of the error of a message |
| chat.error.background | --p-chat-error-background | Background of the error of a message |
| chat.error.border.color | --p-chat-error-border-color | Border color of the error of a message |
| chat.error.color | --p-chat-error-color | Color of the error of a message |
| chat.action.size | --p-chat-action-size | Size of the action buttons of a message |
| chat.action.icon.size | --p-chat-action-icon-size | Size of the icon of the action buttons of a message |
| chat.action.border.radius | --p-chat-action-border-radius | Border radius of the action buttons of a message |
| chat.action.color | --p-chat-action-color | Color of the action buttons of a message |
| chat.action.hover.color | --p-chat-action-hover-color | Hover color of the action buttons of a message |
| chat.action.pressed.color | --p-chat-action-pressed-color | Color of a pressed button of the action buttons of a message |
| chat.action.focus.ring.width | --p-chat-action-focus-ring-width | Focus ring width of the action buttons of a message |
| chat.action.focus.ring.style | --p-chat-action-focus-ring-style | Focus ring style of the action buttons of a message |
| chat.action.focus.ring.color | --p-chat-action-focus-ring-color | Focus ring color of the action buttons of a message |
| chat.action.focus.ring.offset | --p-chat-action-focus-ring-offset | Focus ring offset of the action buttons of a message |
| chat.action.focus.ring.shadow | --p-chat-action-focus-ring-shadow | Focus ring shadow of the action buttons of a message |
| chat.action.hover.background | --p-chat-action-hover-background | Hover background of the action buttons of a message |
| chat.jump.button.background | --p-chat-jump-button-background | Background of the jump to latest button |
| chat.jump.button.hover.background | --p-chat-jump-button-hover-background | Hover background of the jump to latest button |
| chat.jump.button.border.color | --p-chat-jump-button-border-color | Border color of the jump to latest button |
| chat.jump.button.color | --p-chat-jump-button-color | Color of the jump to latest button |
| chat.jump.button.border.radius | --p-chat-jump-button-border-radius | Border radius of the jump to latest button |
| chat.jump.button.padding | --p-chat-jump-button-padding | Padding of the jump to latest button |
| chat.jump.button.gap | --p-chat-jump-button-gap | Gap of the jump to latest button |
| chat.jump.button.font.size | --p-chat-jump-button-font-size | Font size of the jump to latest button |
| chat.jump.button.shadow | --p-chat-jump-button-shadow | Shadow of the jump to latest button |
| chat.jump.button.focus.ring.width | --p-chat-jump-button-focus-ring-width | Focus ring width of the jump to latest button |
| chat.jump.button.focus.ring.style | --p-chat-jump-button-focus-ring-style | Focus ring style of the jump to latest button |
| chat.jump.button.focus.ring.color | --p-chat-jump-button-focus-ring-color | Focus ring color of the jump to latest button |
| chat.jump.button.focus.ring.offset | --p-chat-jump-button-focus-ring-offset | Focus ring offset of the jump to latest button |
| chat.jump.button.focus.ring.shadow | --p-chat-jump-button-focus-ring-shadow | Focus ring shadow of the jump to latest button |
| chat.empty.padding | --p-chat-empty-padding | Padding of the title of the empty state |
| chat.empty.color | --p-chat-empty-color | Color of the title of the empty state |
| chat.empty.font.size | --p-chat-empty-font-size | Font size of the title of the empty state |
| chat.empty.font.weight | --p-chat-empty-font-weight | Font weight of the title of the empty state |
| chat.suggestion.background | --p-chat-suggestion-background | Background of a suggestion |
| chat.suggestion.hover.background | --p-chat-suggestion-hover-background | Hover background of a suggestion |
| chat.suggestion.border.color | --p-chat-suggestion-border-color | Border color of a suggestion |
| chat.suggestion.color | --p-chat-suggestion-color | Color of a suggestion |
| chat.suggestion.border.radius | --p-chat-suggestion-border-radius | Border radius of a suggestion |
| chat.suggestion.padding | --p-chat-suggestion-padding | Padding of a suggestion |
| chat.suggestion.font.size | --p-chat-suggestion-font-size | Font size of a suggestion |
| chat.suggestion.gap | --p-chat-suggestion-gap | Gap of a suggestion |
| chat.suggestion.focus.ring.width | --p-chat-suggestion-focus-ring-width | Focus ring width of a suggestion |
| chat.suggestion.focus.ring.style | --p-chat-suggestion-focus-ring-style | Focus ring style of a suggestion |
| chat.suggestion.focus.ring.color | --p-chat-suggestion-focus-ring-color | Focus ring color of a suggestion |
| chat.suggestion.focus.ring.offset | --p-chat-suggestion-focus-ring-offset | Focus ring offset of a suggestion |
| chat.suggestion.focus.ring.shadow | --p-chat-suggestion-focus-ring-shadow | Focus ring shadow of a suggestion |
| chat.composer.padding | --p-chat-composer-padding | Padding of the composer |
| chat.composer.gap | --p-chat-composer-gap | Gap of the composer |
| chat.composer.box.background | --p-chat-composer-box-background | Background of the frame of the composer |
| chat.composer.box.disabled.background | --p-chat-composer-box-disabled-background | Background when disabled of the frame of the composer |
| chat.composer.box.border.color | --p-chat-composer-box-border-color | Border color of the frame of the composer |
| chat.composer.box.hover.border.color | --p-chat-composer-box-hover-border-color | Hover border color of the frame of the composer |
| chat.composer.box.focus.border.color | --p-chat-composer-box-focus-border-color | Focus border color of the frame of the composer |
| chat.composer.box.border.radius | --p-chat-composer-box-border-radius | Border radius of the frame of the composer |
| chat.composer.box.padding | --p-chat-composer-box-padding | Padding of the frame of the composer |
| chat.composer.box.gap | --p-chat-composer-box-gap | Gap of the frame of the composer |
| chat.composer.box.shadow | --p-chat-composer-box-shadow | Shadow of the frame of the composer |
| chat.composer.box.focus.ring.width | --p-chat-composer-box-focus-ring-width | Focus ring width of the frame of the composer |
| chat.composer.box.focus.ring.style | --p-chat-composer-box-focus-ring-style | Focus ring style of the frame of the composer |
| chat.composer.box.focus.ring.color | --p-chat-composer-box-focus-ring-color | Focus ring color of the frame of the composer |
| chat.composer.box.focus.ring.offset | --p-chat-composer-box-focus-ring-offset | Focus ring offset of the frame of the composer |
| chat.composer.box.focus.ring.shadow | --p-chat-composer-box-focus-ring-shadow | Focus ring shadow of the frame of the composer |
| chat.input.color | --p-chat-input-color | Color of the textarea of the composer |
| chat.input.disabled.color | --p-chat-input-disabled-color | Color when disabled of the textarea of the composer |
| chat.input.placeholder.color | --p-chat-input-placeholder-color | Placeholder color of the textarea of the composer |
| chat.input.padding | --p-chat-input-padding | Padding of the textarea of the composer |
| chat.input.line.height | --p-chat-input-line-height | Line height of the textarea of the composer |
| chat.input.max.height | --p-chat-input-max-height | Maximum height before the textarea scrolls |
| chat.attachment.color | --p-chat-attachment-color | Color of an attachment |
| chat.attachment.size.color | --p-chat-attachment-size-color | Color of the file size of an attachment |
| chat.attachment.border.radius | --p-chat-attachment-border-radius | Border radius of an attachment |
| chat.attachment.padding | --p-chat-attachment-padding | Padding of an attachment |
| chat.attachment.gap | --p-chat-attachment-gap | Gap of an attachment |
| chat.attachment.font.size | --p-chat-attachment-font-size | Font size of an attachment |
| chat.attachment.background | --p-chat-attachment-background | Background of an attachment |
| chat.send.button.size | --p-chat-send-button-size | Size of the send button |
| chat.send.button.icon.size | --p-chat-send-button-icon-size | Size of the icon of the send button |
| chat.send.button.border.radius | --p-chat-send-button-border-radius | Border radius of the send button |
| chat.send.button.background | --p-chat-send-button-background | Background of the send button |
| chat.send.button.hover.background | --p-chat-send-button-hover-background | Hover background of the send button |
| chat.send.button.color | --p-chat-send-button-color | Color of the send button |
| chat.send.button.focus.ring.width | --p-chat-send-button-focus-ring-width | Focus ring width of the send button |
| chat.send.button.focus.ring.style | --p-chat-send-button-focus-ring-style | Focus ring style of the send button |
| chat.send.button.focus.ring.color | --p-chat-send-button-focus-ring-color | Focus ring color of the send button |
| chat.send.button.focus.ring.offset | --p-chat-send-button-focus-ring-offset | Focus ring offset of the send button |
| chat.send.button.focus.ring.shadow | --p-chat-send-button-focus-ring-shadow | Focus ring shadow of the send button |
| chat.send.button.disabled.background | --p-chat-send-button-disabled-background | Background when disabled of the send button |
| chat.send.button.disabled.color | --p-chat-send-button-disabled-color | Color when disabled of the send button |
| chat.edit.button.padding | --p-chat-edit-button-padding | Padding of the buttons of the edit form |
| chat.edit.button.border.radius | --p-chat-edit-button-border-radius | Border radius of the buttons of the edit form |
| chat.edit.button.font.size | --p-chat-edit-button-font-size | Font size of the buttons of the edit form |
| chat.edit.button.background | --p-chat-edit-button-background | Background of the buttons of the edit form |
| chat.edit.button.hover.background | --p-chat-edit-button-hover-background | Hover background of the buttons of the edit form |
| chat.edit.button.color | --p-chat-edit-button-color | Color of the buttons of the edit form |
| chat.edit.button.secondary.color | --p-chat-edit-button-secondary-color | Text color of the cancel button |
| chat.edit.button.secondary.border.color | --p-chat-edit-button-secondary-border-color | Border color of the cancel button |
| chat.edit.button.secondary.hover.background | --p-chat-edit-button-secondary-hover-background | Hover background of the cancel button |
| chat.counter.color | --p-chat-counter-color | Color of the character counter |
| chat.counter.font.size | --p-chat-counter-font-size | Font size of the character counter |
| chat.spinner.size | --p-chat-spinner-size | Size of the indicator shown while older messages load |
| chat.spinner.color | --p-chat-spinner-color | Color of the indicator shown while older messages load |
| chat.footer.padding | --p-chat-footer-padding | Padding of the footer |
| chat.footer.color | --p-chat-footer-color | Color of the footer |
| chat.footer.font.size | --p-chat-footer-font-size | Font size of the footer |

