Components/AI Elements

AI Elements

Conversation and message primitives for AI chat surfaces.

VerifiedSince 1.0.0

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

  • messages is filtered before render: empty content is hidden unless status is pending or streaming.
  • markdown defaults to true, so message bodies are rendered by TxMarkdownView.
  • showAvatar enables a role/name initial fallback when message.avatar is not provided.
  • Pending or streaming messages with empty content render the built-in typing indicator.
  • TxAiConversation uses aria-live="polite" so appended transcript updates are announced without stealing focus.

API

AiElementMessage

FieldTypeDefaultDescription
idstringrequiredStable key for rendering the message.
role'user' | 'assistant' | 'system' | 'tool'requiredVisual and semantic role.
contentstringrequiredMessage text or Markdown source.
createdAtnumber | string | Date-Optional host timestamp.
namestring-Display name; falls back to You / AI / Tool / System.
avatarstring-Image URL used when avatars are enabled.
status'pending' | 'streaming' | 'complete' | 'error'-Message lifecycle state.

TxAiConversation Props

PropTypeDefaultDescription
messagesAiElementMessage[]requiredTranscript data. Empty content is filtered unless the message is pending or streaming.
markdownbooleantrueRender message content through TxMarkdownView.
compactbooleanfalseUse tighter message spacing.
emptyTextstring'No messages yet'Built-in empty state copy when no renderable messages remain.
showAvatarbooleanfalseShow avatar column for every rendered message.

TxAiMessage Props

PropTypeDefaultDescription
messageAiElementMessagerequiredSingle message to render.
markdownbooleantrueRender message content through TxMarkdownView; false preserves plain text with wrapping.
compactbooleanfalseUse compact row density and smaller avatar dimensions.
showAvatarbooleanfalseEnable 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

SlotPropsDescription
empty-Replaces the built-in empty paragraph after message filtering.

TxAiMessage

SlotPropsDescription
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 default slot for tool cards or attachments instead of overloading content with custom HTML.

Review Notes

  • Source: packages/tuffex/packages/components/src/ai-elements/src/TxAiConversation.vue confirms message filtering, polite live region, empty slot, and child message forwarding.
  • Source: packages/tuffex/packages/components/src/ai-elements/src/TxAiMessage.vue confirms role labels, status labels, Markdown/plain rendering, typing indicator, and default / avatar slots.
  • Type contracts: packages/tuffex/packages/components/src/ai-elements/src/types.ts defines AiElementMessage, AiConversationProps, and AiMessageProps.
  • Verified coverage: Coverage: no dedicated ai-elements component unit test currently exists; apps/nexus/test/docs/tuffex-component-docs-coverage.test.ts verifies this page is present in English and Chinese and that AiElementsAiConversationDemo stays registered with an existing Vue demo.
  • Export: packages/tuffex/packages/components/src/ai-elements/index.ts exports installable AiConversation, AiMessage, TxAiConversation, and TxAiMessage.

Source

查看源码
packages/tuffex/packages/components/src/ai-elements/index.ts