Skip to content

feat(chat): display sender identity and specific timestamps in conversation history#2432

Open
seoeaa wants to merge 1 commit intoagentscope-ai:mainfrom
seoeaa:feat/sender-identity-timestamps
Open

feat(chat): display sender identity and specific timestamps in conversation history#2432
seoeaa wants to merge 1 commit intoagentscope-ai:mainfrom
seoeaa:feat/sender-identity-timestamps

Conversation

@seoeaa
Copy link
Copy Markdown
Contributor

@seoeaa seoeaa commented Mar 27, 2026

Summary

  • Display the sender name (agent name or user) above each message bubble in the chat conversation history
  • Display the specific timestamp of each message alongside the sender name
  • Fully integrated with the existing custom card system of @agentscope-ai/chat

Changes

Backend (src/copaw/app/runner/utils.py)

  • Added original_timestamp field to message metadata in agentscope_msg_to_message, exposing Msg.timestamp to the frontend via message.metadata.original_timestamp

Frontend types (console/src/api/types/chat.ts)

  • Added MessageMetadata interface with original_name, original_timestamp, original_id fields
  • Extended Message type with explicit name and metadata fields

Frontend sessionApi (console/src/pages/Chat/sessionApi/index.ts)

  • Added CoPawSenderInfoCard custom card constant
  • buildUserCard now prepends a CoPawSenderInfoCard before AgentScopeRuntimeRequestCard with sender name and timestamp
  • Added extractSenderInfo helper to extract agent name and timestamp from grouped output messages
  • buildResponseCard now prepends a CoPawSenderInfoCard before AgentScopeRuntimeResponseCard
  • Fixed patchLastUserMessage to find AgentScopeRuntimeRequestCard by code field instead of array index 0 (necessary after inserting the sender card first)

Frontend component (console/src/pages/Chat/components/SenderInfoCard/)

  • Created SenderInfoCard React component that renders sender name (bold) and formatted timestamp
  • Registered as CoPawSenderInfoCard in Chat/index.tsx options cards map

How it works

The CoPawSenderInfoCard card 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 using toLocaleString with year/month/day/hour/minute/second precision.

Closes #P0 — Display sender identity and specific timestamps in conversation history (Chat Experience)

…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
@seoeaa seoeaa requested a deployment to maintainer-approved March 27, 2026 22:10 — with GitHub Actions Waiting
@github-actions
Copy link
Copy Markdown

Welcome to CoPaw! 🐾

Hi @seoeaa, this is your 19th Pull Request.

📋 About PR Template

To help maintainers review your PR faster, please make sure to include:

  • Description - What this PR does and why
  • Type of Change - Bug fix / Feature / Breaking change / Documentation / Refactoring
  • Component(s) Affected - Core / Console / Channels / Skills / CLI / Documentation / Tests / CI/CD / Scripts
  • Checklist:
    • Run and pass pre-commit run --all-files
    • Run and pass relevant tests (pytest or as applicable)
    • Update documentation if needed
  • Testing - How to test these changes
  • Local Verification Evidence:
    pre-commit run --all-files
    # paste summary result
    
    pytest
    # paste summary result

Complete PR information helps speed up the review process. You can edit the PR description to add these details.

🙌 Join Developer Community

Thanks 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:
https://copaw.agentscope.io/docs/community

We truly appreciate your enthusiasm—and look forward to your future contributions! 😊

We'll review your PR soon.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +203 to +226
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 };
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

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.

Comment on lines +6 to +8
name: string;
role: "user" | "assistant" | string;
timestamp: string | null;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
name: string;
role: "user" | "assistant" | string;
timestamp: string | null;
name: string;
timestamp: string | null;

Comment on lines +181 to +183
name: senderName,
role: ROLE_USER,
timestamp,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

As the role property is not used in the SenderInfoCard component, it can be removed from here.

Suggested change
name: senderName,
role: ROLE_USER,
timestamp,
name: senderName,
timestamp,

Comment on lines +255 to +257
name: senderInfo.name,
role: ROLE_ASSISTANT,
timestamp: senderInfo.timestamp,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

As the role property is not used in the SenderInfoCard component, it can be removed from here.

Suggested change
name: senderInfo.name,
role: ROLE_ASSISTANT,
timestamp: senderInfo.timestamp,
name: senderInfo.name,
timestamp: senderInfo.timestamp,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant