Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

AI Chatbot

ProNew

An assistant window for your own model: launcher with optional delayed greeting, quick replies, streamed answers with a thinking state and Stop, plus copy, rating and retry.

Installation

pnpm dlx shadcn@latest add @viewport/ai-chatbot

First time? Add the @viewport registry to components.json. Setup takes one minute.

Usage

The code behind the preview above comes with Truffle Pro.

Props

PropTypeDefault
onSend*(message: string, context: ChatbotContext) => ChatbotReply | Promise<ChatbotReply>

Answers a message. Return a string, or an async iterable of text chunks to stream the answer in as it is generated. Throw to show the error state.

—
namestring

The assistant's name, in the header and the welcome screen.

"AI Assistant"
captionstring

One line under the name on the welcome screen.

"Ask me anything. I answer in seconds."
avatarstring

Picture for the assistant. A sparkle on your accent color is used without one.

—
welcomestring

The assistant's opening message.

"Hi! How can I help you today?"
suggestionsstring[]

Quick replies offered until the visitor sends a first message.

[]
placeholderstring"Write a message..."
disclaimerstring

Small print under the input.

—
initialMessagesChatbotMessage[]

A conversation to start from, for example one restored from storage.

[]
onFeedback(message: ChatbotMessage, value: "up" | "down" | null) => void

Called when a thumb is pressed. `null` means the rating was taken back.

—
layout"floating" | "inline"

`floating` pins a launcher to a corner of the viewport and fills the screen on phones; `inline` renders the open window in the page.

"floating"
accentstring

Any CSS color, for the launcher, your messages, quick replies and focus rings.

"#006dff"
launcherLabelstring

Accessible name of the launcher.

"Ask the AI assistant"
position"bottom-right" | "bottom-left""bottom-right"
openboolean

Controlled open state for the floating layout.

—
defaultOpenbooleanfalse
onOpenChange(open: boolean) => void—
teaserstring

Optional floating greeting shown once before the visitor first opens the assistant.

—
teaserDelaynumber

Seconds to wait before showing the greeting; defaults to 10.

10
errorMessagestring

Shown when `onSend` throws without a message of its own.

"Something went wrong while answering. Please try again."
classNamestring—

Accessibility

  • The launcher reports expanded state; opening puts focus in the input and Escape or Close returns it to the launcher.
  • The optional greeting is a button that opens chat; its dismissal is a separate named button and it does not return after the visitor opens chat.
  • Answers are announced once, when complete, through a status region rather than chunk by chunk; “thinking” and “stopped” are announced too.
  • Enter sends and Shift+Enter adds a line; Stop replaces Send while an answer streams.
  • Thumbs are toggle buttons with pressed state; a failed answer is an alert with a Try again button.
  • On phones the window fills the screen and keeps Tab inside it. Dots, shimmer and the caret hold still under reduced motion.