group-button.tsx


Overview

group-button.tsx defines two React functional components — AssistantGroupButton and UserGroupButton — which render grouped button controls related to chat messages in a conversational UI. These components provide interactive elements such as copying message content, playing audio, feedback submission, message regeneration, and deletion.

These components leverage hooks for state management, translation (i18n), speech synthesis, and modal visibility, integrating with various UI elements from Ant Design and custom components.


Detailed Component Documentation

AssistantGroupButton

interface IProps {
  messageId: string;
  content: string;
  prompt?: string;
  showLikeButton: boolean;
  audioBinary?: string;
  showLoudspeaker?: boolean;
}

export const AssistantGroupButton: React.FC<IProps> = ({ ... }) => { ... }

Description

Renders a group of buttons associated with an assistant's message, enabling users to:

Parameters

Prop

Type

Description

Optional

Default

messageId

string

Unique identifier of the message

No

N/A

content

string

Text content of the message

No

N/A

prompt

string

Optional prompt text related to the message

Yes

undefined

showLikeButton

boolean

Controls visibility of like/dislike feedback buttons

No

N/A

audioBinary

string

Optional audio data (base64 or binary) for speech playback

Yes

undefined

showLoudspeaker

boolean

Whether to show the loudspeaker (audio) button

Yes

true

Return Value

Usage Example

<AssistantGroupButton
  messageId="msg-123"
  content="Hello, how can I help you?"
  prompt="Try asking about the weather."
  showLikeButton={true}
  audioBinary={audioData}
/>

Implementation Details


UserGroupButton

interface UserGroupButtonProps extends Partial<IRemoveMessageById> {
  messageId: string;
  content: string;
  regenerateMessage?: () => void;
  sendLoading: boolean;
}

export const UserGroupButton: React.FC<UserGroupButtonProps> = ({ ... }) => { ... }

Description

Renders a group of buttons associated with a user's message, enabling users to:

Parameters

Prop

Type

Description

Optional

Default

messageId

string

Unique identifier of the message

No

N/A

content

string

Text content of the message

No

N/A

regenerateMessage

() => void

Function to trigger message regeneration

Yes

undefined

sendLoading

boolean

Flag indicating if message is currently sending/loading

No

N/A

removeMessageById

() => void (optional)

Optional callback to remove message by ID

Yes

undefined

Return Value

Usage Example

<UserGroupButton
  messageId="user-msg-456"
  content="What is the weather today?"
  regenerateMessage={handleRegenerate}
  sendLoading={false}
  removeMessageById={handleRemoveMessage}
/>

Implementation Details


Important Implementation Details and Algorithms


Interaction with Other Parts of the System


Visual Diagram

componentDiagram
    AssistantGroupButton --> CopyToClipboard : uses
    AssistantGroupButton --> useSendFeedback : uses
    AssistantGroupButton --> useSetModalState : uses
    AssistantGroupButton --> useSpeech : uses
    AssistantGroupButton --> FeedbackModal : renders
    AssistantGroupButton --> PromptModal : renders
    AssistantGroupButton --> Radio.Group : UI container
    AssistantGroupButton --> Radio.Button : UI buttons
    AssistantGroupButton --> Tooltip : UI tooltips

    UserGroupButton --> CopyToClipboard : uses
    UserGroupButton --> useRemoveMessage : uses
    UserGroupButton --> Radio.Group : UI container
    UserGroupButton --> Radio.Button : UI buttons
    UserGroupButton --> Tooltip : UI tooltips

Summary

This file provides essential interactive button groups tightly integrated with the chat message UI, offering features tailored to assistant and user messages. It emphasizes modularity through hooks and reusable components, with a strong focus on user experience via audio playback, feedback, message management, and localization. The design leverages Ant Design UI primitives for consistency and clean interaction flows.