Skip to content

feat(ai): TDesign React Chat UI, homepage chat entry, and admin-configurable assistant content - #1599

Open
lb1038678031 wants to merge 2 commits into
apache:mainfrom
lb1038678031:feat/tdesign-chat
Open

feat(ai): TDesign React Chat UI, homepage chat entry, and admin-configurable assistant content#1599
lb1038678031 wants to merge 2 commits into
apache:mainfrom
lb1038678031:feat/tdesign-chat

Conversation

@lb1038678031

Copy link
Copy Markdown

For #1598

What

Modernize the AI assistant chat UI with TDesign React Chat and make the assistant's opening content admin-configurable, as proposed in #1598. Two commits:

  1. feat: replace AI chat UI with TDesign React Chat and add homepage chat switches

    • 新建 AnswerChatBot adapter wiring the TDesign ChatBot component to Answer's existing /answer/api/v1/chat/completions SSE contract: delta.content streams into a markdown block, delta.reasoning_content into a thinking block, with per-message voting, replay, and history rehydration when switching conversations.
    • Chat completions moves to the unauthenticated router behind a guest gate: with the new home_chat_guest_enabled switch, logged-out visitors can chat; guest history stays client-side and voting is disabled.
    • Optional floating chat entry on the homepage (home_chat_enabled), reusing the same component.
  2. feat(ai): admin-configurable welcome text, suggested questions and system prompt

    • Admin can set the assistant welcome text and a suggested-questions list (one per line). Both render inside a single welcome message as tappable chips (the TDesign reference layout); empty values fall back to built-in i18n suggestions.
    • The existing prompt_config (zh/en system prompt) is now editable in the admin AI settings form, and saving always round-trips it — previously an omitted prompt_config silently reset stored prompts to the built-in defaults.
    • Refreshed language packs now apply via i18next.addResourceBundle as soon as they are fetched instead of waiting for the next full page load.

Why

We self-host Answer as a community FAQ and wanted a streaming chat experience with thinking blocks, markdown and suggestion chips, plus control over what the assistant says and which tools the prompt advertises. TDesign React Chat provides the chat primitives; this patch keeps Answer's own backend contract unchanged apart from the guest gate and the new site-info fields.

Testing

  • go build ./... and go test ./internal/schema ./internal/controller
  • Manual smoke on Windows (embedded UI): logged-in and guest flows, thinking display, per-message votes, replay, new-chat reset (including from a loaded history conversation), suggestion chips, and admin round-trip of welcome text / suggestions / system prompt.

Notes

  • The installed tdesign-web-components@1.3.0-alpha.2 does not implement suggestion directSend, so chip clicks are delivered through per-message handle操作 and sent from the adapter. A one-line defensive guard for the component library's setExportparts is applied in our deployment build; standard flows work without it.
  • Vision/image input is intentionally out of scope for this feature.

…t switches

- 新建 AnswerChatBot adapter component wraps @tdesign-react/chat ChatBot
  with the Answer backend contract: custom SSE parsing (markdown +
  thinking blocks from reasoning_content), vote actions bridged to the
  conversation vote API, conversation history rehydration.
- The AI assistant page now renders AnswerChatBot; the legacy
  Sender/Bubble components stay for other pages.
- 新建 site AI switches: home_chat_enabled (floating AI entry on the
  homepage) and home_chat_guest_enabled (logged-out visitors can chat;
  guest sessions stay client-side and are never persisted, voting off).
- POST /chat/completions moves to the unauthenticated route group; the
  handler enforces the guest switch itself and runs guest sessions
  fully in memory with a system prompt prepended.
- zh/en translations for the new switches and chat strings.
…stem prompt

- Expose the assistant welcome text and a suggested-questions list (one
  per line) as site AI settings; both render inside the single welcome
  message as tappable chips, matching the TDesign reference layout.
- Surface the existing prompt_config (zh/en system prompt) in the admin
  AI settings form, and always round-trip it on save so the backend no
  longer silently resets configured prompts to the built-in defaults.
- Localize new admin labels and assistant strings (zh_CN/en_US).
- apply refreshed language packs via i18next.addResourceBundle as soon
  as they are fetched instead of waiting for the next full page load.
- fix new-chat reset: remount the ChatBot instead of swapping the omi
  message store in place, which crashed the action-bar re-render for
  conversations with completed messages; abort in-flight streams on
  reset and unmount.
- fix suggestion chips: deliver clicks through per-message handle操作
  (the installed tdesign-web-components has no directSend support).
注册 for free to join this conversation on GitHub. Already have an account? 登录 to comment

标签

None yet

项目

None yet

Development

Successfully merging this pull request may close these issues.

1 participant