Chat
Chat is the thread of a conversation with the agent. Message Scroller keeps your place while the reply streams.
Each turn is a Message inside a Message Scroller. The message of the person is the scroll anchor. A new question thus settles near the top, and the reply streams in under it. The field is a Prompt Input. The steps of the agent are Trace lines.
Installation#
Chat is built with the Message Scroller, Message, Bubble, Trace, and Input Group components.
npx shadcn@latest add @formance/message-scroller @formance/message @formance/bubble @formance/trace @formance/input-groupUsage#
<MessageScrollerProvider autoScroll> <MessageScroller> <MessageScrollerViewport> <MessageScrollerContent> <MessageScrollerItem messageId={id} scrollAnchor> <Message align="end"> <MessageContent> <Bubble align="end" variant="muted"> <BubbleContent>{text}</BubbleContent> </Bubble> </MessageContent> </Message> </MessageScrollerItem> </MessageScrollerContent> </MessageScrollerViewport> <MessageScrollerButton /> </MessageScroller></MessageScrollerProvider>Set scrollAnchor on the turn of the person. autoScroll follows the reply while the person stays at the live edge.
Refer to Message Scroller.
Edit mode#
In Edit mode, the agent proposes a change to the schema as a diff. The person applies or discards it, and a short status replaces the buttons.
Files#
A turn can carry AI SDK file parts. The person sends a statement and a photo, and the agent answers with a report. Each file part is an Attachment: an image shows its preview, a document shows its media type.
Thinking logo#
While the reply is submitted, the agent has no token to show yet. A Formance Thinking Logo takes the place of its avatar. When the first token arrives, the reply replaces it, with the Formance icon as the avatar.
AI SDK helper#
To build without a model, write the conversation as a script with createChat from @shadcn/helpers/ai-sdk. Each agent turn streams reasoning, a tool call, and a reply. chat.next() fills the field with the next message of the script. When the script has no more turns, the string fallback is the reply.
import { createChat } from '@shadcn/helpers/ai-sdk';
const chat = createChat() .user('Add daily interest accrual on client balances.') .assistant(({ writer }) => { writer.reasoning('I need to know which accounts hold client balances.'); writer .tool('runCommand', { input: { command: 'fctl ledger accounts list' } }) .output({ stdout: 'clients:001:available' }); writer.text('I added a clients:$id:interest account.'); });
const transport = chat.transport({ fallback: 'This demo only knows the scripted turns. Press reset to start over.',});
const nextMessage = chat.next(messages);