Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix(channel): show Agent profile card when hovering its message avatar (#22515)

Arvin Xuefd400afe80b
diff --git a/src/features/Channels/ChannelMessage.test.tsx b/src/features/Channels/ChannelMessage.test.tsx
new file mode 100644
index 00000000000..00f5eee4450
--- /dev/null
+++ b/src/features/Channels/ChannelMessage.test.tsx
@@ -0,0 +1,103 @@
+/**
+ * @vitest-environment happy-dom
+ */
+import type { ChannelDetail, ChannelPublicMessage } from '@lobechat/types';
+import { render, screen } from '@testing-library/react';
+import { createElement, type ReactNode } from 'react';
+import { describe, expect, it, vi } from 'vitest';
+
+import { ChannelMessage } from './ChannelMessage';
+
+vi.mock('react-i18next', () => ({
+ useTranslation: () => ({ i18n: { language: 'en-US' }, t: (key: string) => key }),
+}));
+vi.mock('@/features/Conversation/ChatItem', () => ({
+ // Renders only the avatar slot, the way ChatItem hands it to customAvatarRender.
+ ChatItem: ({
+ customAvatarRender,
+ }: {
+ customAvatarRender: (a: unknown, n: ReactNode) => ReactNode;
+ }) => createElement('div', {}, customAvatarRender({}, createElement('img', { alt: 'avatar' }))),
+}));
+vi.mock('@/features/AgentProfileCard/AgentProfilePopup', () => ({
+ default: ({
+ agentId,
+ agent,
+ children,
+ trigger,
+ }: {
+ agent?: { description?: string };
+ agentId: string;
+ children: ReactNode;
+ trigger?: string;
+ }) =>
+ createElement(
+ 'div',
+ {
+ 'data-agent-id': agentId,
+ 'data-description': agent?.description,
+ 'data-testid': 'agent-profile-popup',
+ 'data-trigger': trigger,
+ },
+ children,
+ ),
+}));
+vi.mock('@/features/Conversation/Markdown', () => ({ default: () => null }));
+vi.mock('@/features/User/UserAvatar', () => ({ default: () => createElement('i', {}, 'me') }));
+vi.mock('@/store/user', () => ({
+ useUserStore: (selector: (s: unknown) => unknown) => selector({}),
+}));
+vi.mock('@/store/user/selectors', () => ({
+ userProfileSelectors: { userId: () => 'user-self' },
+}));
+vi.mock('./MessageAttachments', () => ({ MessageAttachments: () => null }));
+vi.mock('./MessageReceipts', () => ({
+ MessageFailureMark: () => null,
+ MessageRoutingStatus: () => null,
+}));
+
+const detail = {
+ attachments: [],
+ jobs: [],
+ members: [{ agentId: 'agt_1', description: 'Architect', id: 'mem_1' }],
+ threads: [],
+} as unknown as ChannelDetail;
+
+const message = (author: ChannelPublicMessage['author']) =>
+ ({
+ author,
+ content: '',
+ createdAt: new Date('2026-11-07T10:18:00Z'),
+ fileIds: [],
+ id: 'msg_1',
+ mentions: [],
+ routingStatus: author.type === 'agent' ? 'reply' : 'routed',
+ }) as unknown as ChannelPublicMessage;
+
+describe('ChannelMessage avatar', () => {
+ it('shows the Agent profile card when hovering an Agent author', () => {
+ render(
+ <ChannelMessage
+ detail={detail}
+ message={message({ avatar: null, id: 'agt_1', name: 'Sanjo', type: 'agent' })}
+ />,
+ );
+
+ const popup = screen.getByTestId('agent-profile-popup');
+ expect(popup.dataset.agentId).toBe('agt_1');
+ expect(popup.dataset.trigger).toBe('hover');
+ expect(popup.dataset.description).toBe('Architect');
+ });
+
+ it('keeps a plain avatar for a human author', () => {
+ render(
+ <ChannelMessage
+ detail={detail}
+ message={message({ avatar: null, id: 'user-other', name: 'Ann', type: 'user' })}
+ />,
+ );
+
+ expect(screen.queryByTestId('agent-profile-popup')).toBeNull();
+ expect(screen.getByAltText('avatar')).toBeTruthy();
+ });
+});
diff --git a/src/features/Channels/ChannelMessage.tsx b/src/features/Channels/ChannelMessage.tsx
index 0755c5e62d2..2693cd09a66 100644
--- a/src/features/Channels/ChannelMessage.tsx
+++ b/src/features/Channels/ChannelMessage.tsx
@@ -7,6 +7,7 @@ import { useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import CollapsibleContent from '@/components/CollapsibleContent';
+import AgentProfilePopup from '@/features/AgentProfileCard/AgentProfilePopup';
import { ChatItem } from '@/features/Conversation/ChatItem';
import Markdown from '@/features/Conversation/Markdown';
import UserAvatar from '@/features/User/UserAvatar';
@@ -101,6 +102,10 @@ export const ChannelMessage = ({
attachments: detail.attachments.filter((file) => message.fileIds.includes(file.id)),
});
const isRequest = message.author.type === 'user' && !isRoot;
+ const agentAuthorId = message.author.type === 'agent' ? message.author.id : null;
+ const agentMember = agentAuthorId
+ ? detail.members.find((member) => member.agentId === agentAuthorId)
+ : undefined;
const mentionNames = detail.members
.filter((member) => message.mentions.includes(member.id))
.map((member) => memberName(member, ''))
@@ -153,7 +158,24 @@ export const ChannelMessage = ({
}
customAvatarRender={(_, avatar) => (
<Flexbox {...stylex.props(styles.messageAvatar)}>
- {isOwnMessage ? <UserAvatar size={36} /> : avatar}
+ {isOwnMessage ? (
+ <UserAvatar size={36} />
+ ) : agentAuthorId ? (
+ // Same profile card an Agent shows on hover in goals and tasks.
+ <AgentProfilePopup
+ agentId={agentAuthorId}
+ trigger={'hover'}
+ agent={{
+ avatar: message.author.avatar,
+ description: agentMember?.description,
+ title: message.author.name,
+ }}
+ >
+ <span style={{ cursor: 'pointer', display: 'inline-flex' }}>{avatar}</span>
+ </AgentProfilePopup>
+ ) : (
+ avatar
+ )}
</Flexbox>
)}
message={