feat(chat): display sender identity and specific timestamps in conversation history#2432
feat(chat): display sender identity and specific timestamps in conversation history#2432seoeaa wants to merge 1 commit intoagentscope-ai:mainfrom
Conversation
…story - Add original_timestamp field to message metadata in agentscope_msg_to_message - Extend Message type to include name and metadata fields - Create CoPawSenderInfoCard component that renders sender name and timestamp - Register CoPawSenderInfoCard as custom card in chat options - Build SenderInfoCard cards before each request/response card in sessionApi - Fix patchLastUserMessage to find AgentScopeRuntimeRequestCard by code
|
Hi @seoeaa, this is your 19th Pull Request. 📋 About PR TemplateTo help maintainers review your PR faster, please make sure to include:
Complete PR information helps speed up the review process. You can edit the PR description to add these details. 🙌 Join Developer CommunityThanks so much for your contribution! We'd love to invite you to join the official CoPaw developer group! You can find the Discord and DingTalk group links under the "Developer Community" section on our docs page: We truly appreciate your enthusiasm—and look forward to your future contributions! 😊 We'll review your PR soon. |
There was a problem hiding this comment.
Code Review
This pull request introduces a SenderInfoCard component to display sender names and timestamps within the chat interface, along with the necessary backend and frontend changes to support message metadata. Feedback identifies a critical issue where assistant message timestamps are not displayed because metadata is stripped during message conversion. Additionally, it is recommended to remove the unused role property from the SenderInfoCard component and its associated data structures to improve code cleanliness.
| function extractSenderInfo(outputMessages: OutputMessage[]): { | ||
| name: string; | ||
| timestamp: string | null; | ||
| } { | ||
| // Use the first message's metadata for the sender name and timestamp | ||
| for (const msg of outputMessages) { | ||
| const metadata = (msg.metadata as | ||
| | { | ||
| original_name?: string; | ||
| original_timestamp?: string | null; | ||
| } | ||
| | null | ||
| | undefined); | ||
| const name = | ||
| metadata?.original_name || | ||
| (msg.name as string | undefined) || | ||
| ROLE_ASSISTANT; | ||
| const timestamp = metadata?.original_timestamp || null; | ||
| if (name !== ROLE_ASSISTANT || timestamp) { | ||
| return { name, timestamp }; | ||
| } | ||
| } | ||
| return { name: ROLE_ASSISTANT, timestamp: null }; | ||
| } |
There was a problem hiding this comment.
There's a critical issue in this function that will prevent assistant message timestamps from being displayed. The outputMessages this function receives are of type OutputMessage[]. These are created by toOutputMessage, which explicitly sets msg.metadata to null.
Consequently, metadata?.original_timestamp will always be null, and timestamps for assistant messages will not be available.
To fix this, you'll need to ensure that the original message metadata is available when extractSenderInfo is called. One approach is to modify toOutputMessage and the OutputMessage type to not strip metadata, if that doesn't break AgentScopeRuntimeResponseCard. Another way is to refactor convertMessages and buildResponseCard to pass the original Message[] array to extractSenderInfo.
| name: string; | ||
| role: "user" | "assistant" | string; | ||
| timestamp: string | null; |
There was a problem hiding this comment.
The role property is defined in SenderInfoCardProps but it's not used within the component. To improve code clarity and maintainability, it's best to remove unused props. The corresponding role properties passed when constructing CoPawSenderInfoCard in console/src/pages/Chat/sessionApi/index.ts should also be removed.
| name: string; | |
| role: "user" | "assistant" | string; | |
| timestamp: string | null; | |
| name: string; | |
| timestamp: string | null; |
| name: senderName, | ||
| role: ROLE_USER, | ||
| timestamp, |
| name: senderInfo.name, | ||
| role: ROLE_ASSISTANT, | ||
| timestamp: senderInfo.timestamp, |
Summary
@agentscope-ai/chatChanges
Backend (
src/copaw/app/runner/utils.py)original_timestampfield to message metadata inagentscope_msg_to_message, exposingMsg.timestampto the frontend viamessage.metadata.original_timestampFrontend types (
console/src/api/types/chat.ts)MessageMetadatainterface withoriginal_name,original_timestamp,original_idfieldsMessagetype with explicitnameandmetadatafieldsFrontend
sessionApi(console/src/pages/Chat/sessionApi/index.ts)CoPawSenderInfoCardcustom card constantbuildUserCardnow prepends aCoPawSenderInfoCardbeforeAgentScopeRuntimeRequestCardwith sender name and timestampextractSenderInfohelper to extract agent name and timestamp from grouped output messagesbuildResponseCardnow prepends aCoPawSenderInfoCardbeforeAgentScopeRuntimeResponseCardpatchLastUserMessageto findAgentScopeRuntimeRequestCardbycodefield instead of array index0(necessary after inserting the sender card first)Frontend component (
console/src/pages/Chat/components/SenderInfoCard/)SenderInfoCardReact component that renders sender name (bold) and formatted timestampCoPawSenderInfoCardinChat/index.tsxoptionscardsmapHow it works
The
CoPawSenderInfoCardcard is inserted as the first card in every message (both user and assistant). The card receives{ name, role, timestamp }props and renders a compact header line above the message bubble content. Timestamp is formatted usingtoLocaleStringwith year/month/day/hour/minute/second precision.Closes #P0 — Display sender identity and specific timestamps in conversation history (Chat Experience)