Import
import { NuiChat, NuiChatSession, nuiEventStream } from '@needless-ui/angular/chat';NuiChat
The conversation and the box to write in, together.
| Name | Type | Default | Description |
|---|---|---|---|
sessionInput | NuiChatSession | The conversation to show. | |
assistantInput | string | 'Assistant' | The assistant’s name, in the headings screen readers hear. |
headingLevelInput | number | 3 | The level of each message’s heading, which only screen readers show. Headings in replies go one deeper. |
announceInput | 'reply' | 'notice' | 'off' | 'reply' | What screen readers hear when a reply is complete: all of it, a short notice, or nothing. |
imagesInput | boolean | false | Shows images in replies. Otherwise their text links to them. |
valueTwo-way | string | '' | The text being written. |
placeholderInput | string | The hint in the empty field. | |
suggestionsInput | string[] | [] | Prompts to send with a click, until the first message. |
sendOnInput | 'enter' | 'mod+enter' | 'enter' | Whether Enter sends, or Ctrl or ⌘ + Enter. |
disabledInput | boolean | false | Stops the composer from sending. |
attachInput | boolean | false | Takes files: picked, pasted or dropped. |
acceptInput | string | '' | The kinds of file to take, as for <input type="file">. |
maxFilesInput | number | 10 | How many files a message can carry. |
maxSizeInput | number | 20_000_000 | The largest file to take, in bytes. |
labelsInput | NuiChatLabelsInput | Every text the chat shows or announces, to translate. | |
ratedOutput | { message, rating } | Emits a reply the reader rated, with the rating, or null when taken back. | |
focusMethod | () => void | Focuses the text field. | |
scrollToEndMethod | (behavior?) => void | Scrolls to the latest message, and follows it. |
NuiChatSession
The conversation, without any DOM. Create it in a component, with the options respond, messages and id.
| Name | Type | Default | Description |
|---|---|---|---|
respondProperty | (request) => NuiChatReply | Yours: writes the reply to request.messages, and stops when request.signal aborts. | |
messagesProperty | Signal<NuiChatMessage[]> | The conversation on screen. | |
allProperty | Signal<NuiChatMessage[]> | Every message of every version, to save and pass back as messages. | |
busyProperty | Signal<boolean> | Whether a reply is on its way. | |
sendMethod | (text, files?) => Promise<void> | Sends a message and asks for a reply. | |
stopMethod | () => void | Stops the reply, keeping what it wrote. | |
retryMethod | (message?) => Promise<void> | Asks again. The new reply is a version beside the old one. | |
editMethod | (message, text) => Promise<void> | Sends a new version of one of the user’s messages. | |
versionsMethod | (message) => NuiChatMessage[] | Every version of a message, oldest first. | |
showMethod | (message) => void | Switches the conversation to this version. | |
rateMethod | (message, 'up' | 'down' | null) => void | Records the reader’s verdict on a reply. | |
remove, load, clearMethod | (…) => void | Removes a message and what follows it, replaces the conversation, or starts over. |
NuiChatMessage
One message. Messages with the same parent are versions of each other.
| Name | Type | Default | Description |
|---|---|---|---|
id, parentProperty | string, string | null | The message’s key, and the one it follows. | |
roleProperty | 'user' | 'assistant' | Who wrote it. | |
textProperty | string | Markdown from the assistant, plain text from the user. | |
statusProperty | 'pending' | 'streaming' | 'done' | 'stopped' | 'error' | Where a reply stands, from waiting to done. | |
reasoningProperty | string | What the model thought before it answered. | |
toolsProperty | NuiChatTool[] | The tools it called, with their state, input and output. | |
sourcesProperty | { url, title? }[] | The pages it used. | |
attachmentsProperty | NuiChatAttachment[] | The files sent with it. | |
ratingProperty | 'up' | 'down' | null | The reader’s verdict. | |
dataProperty | unknown | Anything else to keep with it, such as the model’s name. |
NuiChatToolTemplate
Draws a tool call, such as a card for the weather. The context holds the call and its message.
| Name | Type | Default | Description |
|---|---|---|---|
nuiChatToolInput | string | The tool’s name. Without one, it draws every call no other template names. |
NuiChatThread
The conversation on its own, for a layout of yours. It takes the inputs of nui-chat that concern the conversation.
NuiChatComposer
The box to write in, on its own. It takes the inputs of nui-chat that concern writing.
NuiServerEvent
What nuiEventStream yields for each event. nuiTextStream reads plain text and nuiJsonStream JSON lines; all three take a fetch response.
| Name | Type | Default | Description |
|---|---|---|---|
eventProperty | string | 'message' | The event’s name. |
dataProperty | string | Its data lines, joined. | |
idProperty | string | The last id the stream sent. |
NuiChatError
Throw it from respond to show its message. Any other error shows a general one, so nothing internal leaks.