Skip to content
English

Usage

import { ChatThread } from './ChatThread.jsx'

// Resolve with the answer's text, or with { text, card: 'trip' } to show the trip card under it.
const ask = (text, history) => fetch('/api/chat', { method: 'POST', body: JSON.stringify({ text, history }) }).then((response) => response.json())

export function TripChat({ messages }) {
  return <ChatThread locale="en" messages={messages} onSend={ask} />
}

Props

PropTypeDefaultWhat it does
locale'en' | 'zh-CN' | 'es' | 'ja''en'Language of the built-in text, sample messages and the trip’s dates and prices.
messages{ id, role: 'user' | 'assistant', text, card?: 'trip' }[]sampleThe conversation so far. An empty list shows ways to start; `card` shows the trip card under that answer.
trip{ title, dates, total, currency, tag, held?, cover?: string | ReactNode | null, days: { icon, at, title, detail }[] }sampleWhat the trip card shows. `at` is an ISO time; it is printed in the visitor’s language. `held` opens the card already held. `cover` (an image URL or an element; null for none) replaces the drawn coast.
ideas{ icon?, text }[]sampleStarting points offered in an empty conversation; choosing one sends its text. `icon` is a kit icon name.
suggestionsstring[]sampleReplies offered under the last answer. One that has been sent is not offered again.
onSend(text, messages) => Promise<string | { text, card? }>—Gets the answer. It streams in once it resolves; a rejection shows the failure line with Try again. Without it, the sample answers.
onStop() => void—Called when the visitor stops an answer (the stop button or Escape). What had arrived stays.
onRetry(messageId?) => void—Called before an answer is written again, or before a failed one is asked again.
onHold(trip) => Promise<boolean | void>—Holds the train and the room from the trip card; the button waits for it, then shows that it is held. Resolve with false, or fail, to put the button back.
loadingbooleanfalseShows the shape of the conversation while it loads.
errorbooleanfalseThe last question’s answer failed: the thread ends with the failure line and Try again.
labelsobject—Replaces any built-in text (see copy.js), such as placeholder, send, stop or emptyTitle.
classNamestring—Added to the root; other attributes go there too.

Add it to your project

Copy the prompt into Codex or Claude Code. The agent reads the published source, shows you what it will write and adds the block together with the components it is built from.

ChatThread.jsxchat-thread.csscopy.jskit.jsxkit.cssui/base-button/ui/copy-button/ui/status-tag/ui/textarea/ui/skeleton-shimmer/ui/typing-dots/tokens.cssREADME.md

The block, its stylesheet and text, the shared kit, the components it uses and tokens.css install together into one folder.