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(topic): name by-agent topic groups after the agent's name (#21469)

LiJian45762308dd6e
diff --git a/packages/utils/src/client/topic.test.ts b/packages/utils/src/client/topic.test.ts
index e4db4dd29fd..a65411142b6 100644
--- a/packages/utils/src/client/topic.test.ts
+++ b/packages/utils/src/client/topic.test.ts
@@ -804,16 +804,30 @@ describe('groupTopicsByAgent', () => {
]);
});
- it('falls back to agentName when agentTitle is absent', () => {
- const topics = [createRow('a1', 1, { agentId: 'agent-x', agentName: 'lobehub' })];
+ it('titles the group with agentName over agentTitle', () => {
+ const topics = [
+ createRow('a1', 1, {
+ agentId: 'agent-x',
+ agentName: 'Cook',
+ agentTitle: '公共CC(美国 100刀)',
+ }),
+ ];
expect(groupTopicsByAgent(topics, 'updatedAt')[0]).toEqual({
children: topics,
id: 'agent:agent-x',
- title: 'lobehub',
+ title: 'Cook',
});
});
+ it('falls back to agentTitle when agentName is blank', () => {
+ const topics = [
+ createRow('a1', 1, { agentId: 'agent-x', agentName: ' ', agentTitle: 'LobeHub' }),
+ ];
+
+ expect(groupTopicsByAgent(topics, 'updatedAt')[0].title).toBe('LobeHub');
+ });
+
it('buckets rows without agent attribution as a title-less no-agent group', () => {
const topics = [createRow('a', 2), createRow('b', 1)];
diff --git a/packages/utils/src/client/topic.ts b/packages/utils/src/client/topic.ts
index d6fe8e7b959..170195f4bf5 100644
--- a/packages/utils/src/client/topic.ts
+++ b/packages/utils/src/client/topic.ts
@@ -5,7 +5,11 @@ import type {
GroupedTopic,
TimeGroupId,
} from '@lobechat/types';
-import { getWorkingDirEffectivePath, getWorkingDirSourcePath } from '@lobechat/types';
+import {
+ agentDisplayName,
+ getWorkingDirEffectivePath,
+ getWorkingDirSourcePath,
+} from '@lobechat/types';
import dayjs from 'dayjs';
import isToday from 'dayjs/plugin/isToday';
import isYesterday from 'dayjs/plugin/isYesterday';
@@ -314,9 +318,10 @@ interface AgentAttributedTopic extends ChatTopic {
* multiple agents (e.g. the project topic list).
*
* Returns:
- * - `agent:{agentId}` groups sorted by most recent activity, titled from the
- * first row's agent metadata, and a title-less `no-agent` bucket for rows
- * without attribution (the renderer names those from its agent context).
+ * - `agent:{agentId}` groups sorted by most recent activity, titled with the
+ * first row's agent display name (name, else title), and a title-less
+ * `no-agent` bucket for rows without attribution (the renderer names those
+ * from its agent context).
*/
export const groupTopicsByAgent = (
topics: AgentAttributedTopic[],
@@ -343,7 +348,10 @@ export const groupTopicsByAgent = (
.map(([id, children]) => ({
children,
id,
- title: children[0]?.agentTitle ?? children[0]?.agentName ?? undefined,
+ title: agentDisplayName({
+ name: children[0]?.agentName,
+ title: children[0]?.agentTitle,
+ }),
}))
.sort((a, b) => {
const aTime = a.children[0] ? getTopicSortTime(a.children[0], field) : 0;
diff --git a/src/features/AgentSidebar/Topic/TopicListContent/ByAgentMode/GroupItem.test.tsx b/src/features/AgentSidebar/Topic/TopicListContent/ByAgentMode/GroupItem.test.tsx
index 8534f0041b2..b85588c4b78 100644
--- a/src/features/AgentSidebar/Topic/TopicListContent/ByAgentMode/GroupItem.test.tsx
+++ b/src/features/AgentSidebar/Topic/TopicListContent/ByAgentMode/GroupItem.test.tsx
@@ -9,6 +9,7 @@ import { TopicListScopeContext } from '../../TopicListScope';
import GroupItem from './GroupItem';
const subGroupModes: Record<string, string> = {};
+let registeredMeta: { avatar?: string; name?: string; title?: string } = {};
vi.mock('@/store/agent', () => ({
useAgentStore: (selector: (state: unknown) => unknown) => selector({ activeAgentId: 'agent-1' }),
@@ -17,7 +18,7 @@ vi.mock('@/store/agent', () => ({
vi.mock('@/store/agent/selectors', () => ({
agentSelectors: {
currentAgentMeta: () => ({ title: '验收合并-Alpha', avatar: '🅰️' }),
- getAgentMetaById: () => () => ({}),
+ getAgentMetaById: () => () => registeredMeta,
},
}));
@@ -135,6 +136,7 @@ const renderGroup = () =>
describe('TopicByAgentGroupItem', () => {
beforeEach(() => {
for (const key of Object.keys(subGroupModes)) delete subGroupModes[key];
+ registeredMeta = {};
directories.splice(
0,
directories.length,
@@ -199,6 +201,29 @@ describe('TopicByAgentGroupItem', () => {
</TopicListScopeContext>,
);
+ /** @example User report: the project sidebar named an agent bucket by its role, not its name. */
+ it('names an untitled bucket after the registered agent name, not its title', () => {
+ // ROOT CAUSE: the registry fallback read `title` before `name`, so a named
+ // agent ("Cook") showed its role ("公共CC(美国 100刀)") as the group label.
+ registeredMeta = { name: 'Cook', title: '公共CC(美国 100刀)' };
+ render(
+ <TopicListScopeContext value={{ coordinatorAgentId: 'agt_lead', projectId: 'prj_1' }}>
+ <AccordionRoot>
+ <GroupItem
+ expanded={false}
+ group={{
+ children: [{ createdAt: 1, id: 't1', title: 'Plan', updatedAt: 1 }],
+ id: 'agent:agt_cook',
+ }}
+ />
+ </AccordionRoot>
+ </TopicListScopeContext>,
+ );
+
+ expect(screen.getAllByText('Cook').length).toBeGreaterThan(0);
+ expect(screen.queryByText('公共CC(美国 100刀)')).toBeNull();
+ });
+
it("tags the project's main agent as its lead", () => {
renderInProject('agt_lead');
diff --git a/src/features/AgentSidebar/Topic/TopicListContent/ByAgentMode/GroupItem.tsx b/src/features/AgentSidebar/Topic/TopicListContent/ByAgentMode/GroupItem.tsx
index 9b83680664a..6c03862c50a 100644
--- a/src/features/AgentSidebar/Topic/TopicListContent/ByAgentMode/GroupItem.tsx
+++ b/src/features/AgentSidebar/Topic/TopicListContent/ByAgentMode/GroupItem.tsx
@@ -1,5 +1,6 @@
'use client';
+import { agentDisplayName } from '@lobechat/types';
import {
AccordionHeader,
AccordionItem,
@@ -85,9 +86,8 @@ const GroupItem = memo<GroupItemComponentProps>(({ group }) => {
row?.agentAvatar || registeredMeta?.avatar || (isOwnBucket ? activeMeta.avatar : undefined);
const name =
title ??
- registeredMeta?.title ??
- registeredMeta?.name ??
- (isOwnBucket ? (activeMeta.title ?? activeMeta.name) : undefined) ??
+ agentDisplayName(registeredMeta) ??
+ (isOwnBucket ? agentDisplayName(activeMeta) : undefined) ??
t('groupTitle.byAgent.unknown');
const isCoordinator = !!agentId && agentId === scope?.coordinatorAgentId;