AI Elements
Conversation and message primitives for AI chat surfaces.
AI Elements
Conversation
Use TxAiConversation when the host owns the message array and only needs a consistent transcript layout.
AI Conversation
Loading demo...
Interaction Contract
messagesis filtered before render: emptycontentis hidden unlessstatusispendingorstreaming.markdowndefaults totrue, so message bodies are rendered byTxMarkdownView.showAvatarenables a role/name initial fallback whenmessage.avataris not provided.- Pending or streaming messages with empty content render the built-in typing indicator.
TxAiConversationusesaria-live="polite"so appended transcript updates are announced without stealing focus.
API
AiElementMessage
| Field | Type | Default | Description |
|---|---|---|---|
id | string | required | Stable key for rendering the message. |
role | 'user' | 'assistant' | 'system' | 'tool' | required | Visual and semantic role. |
content | string | required | Message text or Markdown source. |
createdAt | number | string | Date | - | Optional host timestamp. |
name | string | - | Display name; falls back to You / AI / Tool / System. |
avatar | string | - | Image URL used when avatars are enabled. |
status | 'pending' | 'streaming' | 'complete' | 'error' | - | Message lifecycle state. |
TxAiConversation Props
| Prop | Type | Default | Description |
|---|---|---|---|
messages | AiElementMessage[] | required | Transcript data. Empty content is filtered unless the message is pending or streaming. |
markdown | boolean | true | Render message content through TxMarkdownView. |
compact | boolean | false | Use tighter message spacing. |
emptyText | string | 'No messages yet' | Built-in empty state copy when no renderable messages remain. |
showAvatar | boolean | false | Show avatar column for every rendered message. |
TxAiMessage Props
| Prop | Type | Default | Description |
|---|---|---|---|
message | AiElementMessage | required | Single message to render. |
markdown | boolean | true | Render message content through TxMarkdownView; false preserves plain text with wrapping. |
compact | boolean | false | Use compact row density and smaller avatar dimensions. |
showAvatar | boolean | false | Enable avatar rendering for this message. |
Events
TxAiConversation and TxAiMessage do not emit component events. Update the host conversation store, then pass the new messages array back into TxAiConversation.
Slots
TxAiConversation
| Slot | Props | Description |
|---|---|---|
empty | - | Replaces the built-in empty paragraph after message filtering. |
TxAiMessage
| Slot | Props | Description |
|---|---|---|
default | { message } | Replaces the message content region; use for tool cards, attachments, or custom renderers. |
avatar | { message } | Replaces the avatar image/fallback when showAvatar is enabled. |
Best Practices
- Keep provider-specific streaming state in the host and map it into
status. - Use stable message ids from the conversation store; do not use array indexes.
- Keep Markdown enabled for assistant output, but sanitize or pre-normalize untrusted Markdown at the data boundary when needed.
- Use the
defaultslot for tool cards or attachments instead of overloadingcontentwith custom HTML.
Review Notes
- Source:
packages/tuffex/packages/components/src/ai-elements/src/TxAiConversation.vueconfirms message filtering, polite live region, empty slot, and child message forwarding. - Source:
packages/tuffex/packages/components/src/ai-elements/src/TxAiMessage.vueconfirms role labels, status labels, Markdown/plain rendering, typing indicator, anddefault/avatarslots. - Type contracts:
packages/tuffex/packages/components/src/ai-elements/src/types.tsdefinesAiElementMessage,AiConversationProps, andAiMessageProps. - Verified coverage: Coverage: no dedicated
ai-elementscomponent unit test currently exists;apps/nexus/test/docs/tuffex-component-docs-coverage.test.tsverifies this page is present in English and Chinese and thatAiElementsAiConversationDemostays registered with an existing Vue demo. - Export:
packages/tuffex/packages/components/src/ai-elements/index.tsexports installableAiConversation,AiMessage,TxAiConversation, andTxAiMessage.
Source
查看源码
packages/tuffex/packages/components/src/ai-elements/index.ts