Chat

A message list and message row for AI chat transcripts.

VerifiedSince 0.3.4

Usage

Basic

Loading demo...

Best Practices

  • Use stable ids from the conversation store for id, never array indexes.
  • Normalize image URLs at the data boundary; the component doesn't validate or rewrite attachment sources.
  • Turn off stagger for virtualized lists or when streaming reorders messages.
  • Handle imageClick in the host; there is no built-in preview.
  • To customize a row, render TxChatMessage and its slots directly.

API Reference

TxChatList

Props

PropTypeDefaultDescription
messagesChatMessageModel[]requiredMessages, rendered in array order.
markdownbooleantrueRenders bodies with TxMarkdownView; off renders plain text.
staggerbooleantrueAnimates rows in with TxStagger.

Events

EventParamsDescription
imageClick{ url: string, name?: string, messageId: string }Forwards imageClick from TxChatMessage.

TxChatMessage

Props

PropTypeDefaultDescription
messageChatMessageModelrequiredThe message to render.
markdownbooleantrueRenders the body as Markdown or plain text.
attachmentLabelstring'Open image attachment'Accessible name of an image thumbnail without a name.

Events

EventParamsDescription
imageClick{ url: string, name?: string, messageId: string }Fires when an image thumbnail is clicked.

Slots

SlotPropsDescription
avatar{ message: ChatMessageModel }Replaces the avatar.
header{ message: ChatMessageModel }Replaces the timestamp header.
content{ message: ChatMessageModel }Replaces the body rendering.

Types

ChatMessageModel

FieldTypeDefaultDescription
idstringrequiredStable message key.
role'user' | 'assistant' | 'system'requiredMessage role; sets the row alignment.
contentstringrequiredMarkdown or plain-text body.
createdAtnumber-Epoch timestamp, rendered as HH:mm after mount.
avatarUrlstring-Avatar image URL.
attachmentsChatMessageAttachment[]-Image attachments, rendered as thumbnails.

ChatMessageAttachment

FieldTypeDefaultDescription
type'image'requiredAttachment kind; only images today.
urlstringrequiredThumbnail URL, also sent with imageClick.
namestring-Accessible name of the thumbnail button, also sent with imageClick.

Overview

  • TxChatList renders a TxChatMessage per item in messages order, keyed by id.
  • Image attachments are native <button type="button"> thumbnails with lazy-loaded images; the button carries the accessible name and the <img> is decorative.
  • createdAt is formatted only after mount, so SSR and client output match.

Technologies

  • Source: packages/tuffex/packages/components/src/chat/ (TxChatList.vue, TxChatMessage.vue, types.ts).
查看源码
packages/tuffex/packages/components/src/chat/index.ts