π€― 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.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
β¨ feat(topic): show creator avatar for others' topics in workspace sidebar (#17386)
Arvin Xu6b0efde4d018
diff --git a/src/features/TopicCreatorAvatar/index.test.tsx b/src/features/TopicCreatorAvatar/index.test.tsxnew file mode 100644index 00000000000..41e4b5738f1--- /dev/null+++ b/src/features/TopicCreatorAvatar/index.test.tsx@@ -0,0 +1,54 @@+/**+ * @vitest-environment happy-dom+ */+import { render } from '@testing-library/react';+import type { ReactNode } from 'react';+import { describe, expect, it, vi } from 'vitest';++import TopicCreatorAvatar from './index';++const useAuthorInfoMock = vi.hoisted(() => vi.fn());++vi.mock('@/business/client/hooks/useAuthorInfo', () => ({+ useAuthorInfo: useAuthorInfoMock,+}));++vi.mock('@lobehub/ui', () => ({+ Avatar: ({ avatar, title }: { avatar?: string; title?: string }) => (+ <span data-avatar={avatar ?? ''} data-testid="avatar" data-title={title ?? ''} />+ ),+ Tooltip: ({ children }: { children?: ReactNode }) => <>{children}</>,+}));++describe('TopicCreatorAvatar', () => {+ it("renders a workspace member's avatar (including the current user's own topics)", () => {+ // In a workspace `useAuthorInfo` resolves the creator profile from members β+ // for every topic, not just other members'.+ useAuthorInfoMock.mockReturnValue({ avatar: 'https://x/y.png', fullName: 'Alice' });++ const { getByTestId } = render(<TopicCreatorAvatar userId="any-member" />);++ expect(useAuthorInfoMock).toHaveBeenCalledWith('any-member');+ const avatar = getByTestId('avatar');+ expect(avatar.getAttribute('data-avatar')).toBe('https://x/y.png');+ expect(avatar.getAttribute('data-title')).toBe('Alice');+ });++ it('renders nothing in personal mode / when the creator is not a resolvable member', () => {+ // No active workspace β the slot resolves to undefined β no avatar.+ useAuthorInfoMock.mockReturnValue(undefined);++ const { queryByTestId } = render(<TopicCreatorAvatar userId="someone" />);++ expect(queryByTestId('avatar')).toBeNull();+ });++ it('renders nothing when no userId is provided (default / temp topic)', () => {+ useAuthorInfoMock.mockReturnValue(undefined);++ const { queryByTestId } = render(<TopicCreatorAvatar />);++ expect(useAuthorInfoMock).toHaveBeenCalledWith(undefined);+ expect(queryByTestId('avatar')).toBeNull();+ });+});diff --git a/src/features/TopicCreatorAvatar/index.tsx b/src/features/TopicCreatorAvatar/index.tsxnew file mode 100644index 00000000000..f3a6eeccbaf--- /dev/null+++ b/src/features/TopicCreatorAvatar/index.tsx@@ -0,0 +1,44 @@+'use client';++import { Avatar, Tooltip } from '@lobehub/ui';+import { memo } from 'react';++import { useAuthorInfo } from '@/business/client/hooks/useAuthorInfo';++interface TopicCreatorAvatarProps {+ /** Size of the avatar in px. */+ size?: number;+ /** Creator (author) of the topic. */+ userId?: string;+}++/**+ * In a workspace the topic list mixes topics from every member. Show each+ * topic's creator avatar as a trailing indicator β including the current user's+ * own topics β so the list reads as a shared space.+ *+ * `useAuthorInfo` is a business slot that resolves the creator profile from the+ * *active workspace* members (cloud) or a no-op (open-source). It returns+ * `undefined` when there is no active workspace, so this renders nothing in+ * personal mode.+ */+const TopicCreatorAvatar = memo<TopicCreatorAvatarProps>(({ userId, size = 16 }) => {+ const author = useAuthorInfo(userId);++ if (!author) return null;++ return (+ <Tooltip title={author.fullName}>+ <Avatar+ avatar={author.avatar ?? undefined}+ size={size}+ style={{ flex: 'none' }}+ title={author.fullName ?? undefined}+ />+ </Tooltip>+ );+});++TopicCreatorAvatar.displayName = 'TopicCreatorAvatar';++export default TopicCreatorAvatar;diff --git a/src/routes/(main)/agent/_layout/Sidebar/Topic/AllTopicsDrawer/Content.tsx b/src/routes/(main)/agent/_layout/Sidebar/Topic/AllTopicsDrawer/Content.tsxindex b8cbf1ded21..9048f0d2169 100644--- a/src/routes/(main)/agent/_layout/Sidebar/Topic/AllTopicsDrawer/Content.tsx+++ b/src/routes/(main)/agent/_layout/Sidebar/Topic/AllTopicsDrawer/Content.tsx@@ -191,6 +191,7 @@ const Content = memo<ContentProps>(({ open, searchKeyword }) => {status={topic.status}threadId={activeThreadId}title={topic.title}+ userId={topic.userId}/></Flexbox>))}diff --git a/src/routes/(main)/agent/_layout/Sidebar/Topic/List/Item/index.tsx b/src/routes/(main)/agent/_layout/Sidebar/Topic/List/Item/index.tsxindex 204b59e2082..57c772fa1e4 100644--- a/src/routes/(main)/agent/_layout/Sidebar/Topic/List/Item/index.tsx+++ b/src/routes/(main)/agent/_layout/Sidebar/Topic/List/Item/index.tsx@@ -23,6 +23,7 @@ import DirIcon from '@/features/ChatInput/ControlBar/DirIcon';import { useHasDraft } from '@/features/ChatInput/draftStorage';import { startTopicDrag } from '@/features/ChatInput/InputEditor/ReferTopic/topicDragData';import NavItem from '@/features/NavPanel/components/NavItem';+import TopicCreatorAvatar from '@/features/TopicCreatorAvatar';import { buildWorkspaceAwarePath } from '@/features/Workspace/workspaceAwarePath';import { getWorkingDirectoryName } from '@/helpers/workingDirectoryPath';import { getPlatformIcon } from '@/routes/(main)/agent/channel/const';@@ -145,10 +146,12 @@ interface TopicItemProps {status?: ChatTopicStatus | null;threadId?: string;title: string;+ /** Creator of the topic; drives the workspace creator avatar. */+ userId?: string;}const TopicItem = memo<TopicItemProps>(- ({ id, title, fav, active, threadId, metadata, status, showWorkingDirectory }) => {+ ({ id, title, fav, active, threadId, metadata, status, showWorkingDirectory, userId }) => {const { t } = useTranslation('topic');const { isDarkMode } = useTheme();const activeAgentId = useAgentStore((s) => s.activeAgentId);@@ -357,11 +360,16 @@ const TopicItem = memo<TopicItemProps>(description={workingDirectoryNode}disabled={editing}draggable={!editing}- extra={<RunningElapsedTime agentId={activeAgentId} topicId={id} />}href={href}slots={{ titlePrefix: draftPrefix }}title={title === '...' ? <DotsLoading gap={3} size={4} /> : title}titleColor={cssVar.colorText}+ extra={+ <>+ <RunningElapsedTime agentId={activeAgentId} topicId={id} />+ <TopicCreatorAvatar userId={userId} />+ </>+ }icon={(() => {// A scheduled topic hasn't run yet β nothing else can be true of it,// so its clock outranks the other states.diff --git a/src/routes/(main)/agent/_layout/Sidebar/Topic/TopicListContent/ByProjectMode/GroupItem.tsx b/src/routes/(main)/agent/_layout/Sidebar/Topic/TopicListContent/ByProjectMode/GroupItem.tsxindex e2d3020c0f5..ddf601be180 100644--- a/src/routes/(main)/agent/_layout/Sidebar/Topic/TopicListContent/ByProjectMode/GroupItem.tsx+++ b/src/routes/(main)/agent/_layout/Sidebar/Topic/TopicListContent/ByProjectMode/GroupItem.tsx@@ -284,6 +284,7 @@ const GroupItem = memo<GroupItemComponentProps>(status={topic.status}threadId={activeThreadId}title={topic.title}+ userId={topic.userId}/>))}</Flexbox>diff --git a/src/routes/(main)/agent/_layout/Sidebar/Topic/TopicListContent/ByStatusMode/GroupItem.tsx b/src/routes/(main)/agent/_layout/Sidebar/Topic/TopicListContent/ByStatusMode/GroupItem.tsxindex 020399c04ec..7036b810628 100644--- a/src/routes/(main)/agent/_layout/Sidebar/Topic/TopicListContent/ByStatusMode/GroupItem.tsx+++ b/src/routes/(main)/agent/_layout/Sidebar/Topic/TopicListContent/ByStatusMode/GroupItem.tsx@@ -52,6 +52,7 @@ const GroupItem = memo<GroupItemComponentProps>(({ group, activeTopicId, activeTstatus={topic.status}threadId={activeThreadId}title={topic.title}+ userId={topic.userId}/>))}</Flexbox>diff --git a/src/routes/(main)/agent/_layout/Sidebar/Topic/TopicListContent/ByTimeMode/GroupItem.tsx b/src/routes/(main)/agent/_layout/Sidebar/Topic/TopicListContent/ByTimeMode/GroupItem.tsxindex 0978a3df4c7..2be33b25440 100644--- a/src/routes/(main)/agent/_layout/Sidebar/Topic/TopicListContent/ByTimeMode/GroupItem.tsx+++ b/src/routes/(main)/agent/_layout/Sidebar/Topic/TopicListContent/ByTimeMode/GroupItem.tsx@@ -39,6 +39,7 @@ const GroupItem = memo<GroupItemComponentProps>(({ group, activeTopicId, activeTstatus={topic.status}threadId={activeThreadId}title={topic.title}+ userId={topic.userId}/>))}</Flexbox>diff --git a/src/routes/(main)/agent/_layout/Sidebar/Topic/TopicListContent/FlatMode/index.tsx b/src/routes/(main)/agent/_layout/Sidebar/Topic/TopicListContent/FlatMode/index.tsxindex 3f4486933df..dc59dd7a738 100644--- a/src/routes/(main)/agent/_layout/Sidebar/Topic/TopicListContent/FlatMode/index.tsx+++ b/src/routes/(main)/agent/_layout/Sidebar/Topic/TopicListContent/FlatMode/index.tsx@@ -52,6 +52,7 @@ const FlatMode = memo(() => {status={topic.status}threadId={activeThreadId}title={topic.title}+ userId={topic.userId}/>))}{isExpandingPageSize && <SkeletonList rows={3} />}diff --git a/src/routes/(main)/agent/_layout/Sidebar/Topic/TopicListContent/SearchResult/index.tsx b/src/routes/(main)/agent/_layout/Sidebar/Topic/TopicListContent/SearchResult/index.tsxindex c550fef08ee..f7accc5a1c3 100644--- a/src/routes/(main)/agent/_layout/Sidebar/Topic/TopicListContent/SearchResult/index.tsx+++ b/src/routes/(main)/agent/_layout/Sidebar/Topic/TopicListContent/SearchResult/index.tsx@@ -39,6 +39,7 @@ const SearchResult = memo(() => {metadata={topic.metadata}status={topic.status}title={topic.title}+ userId={topic.userId}/>))}</>diff --git a/src/routes/(main)/group/_layout/Sidebar/Topic/List/Item/index.tsx b/src/routes/(main)/group/_layout/Sidebar/Topic/List/Item/index.tsxindex 7388e725986..a0ddef9a030 100644--- a/src/routes/(main)/group/_layout/Sidebar/Topic/List/Item/index.tsx+++ b/src/routes/(main)/group/_layout/Sidebar/Topic/List/Item/index.tsx@@ -14,6 +14,7 @@ import RingLoadingIcon from '@/components/RingLoading';import { isDesktop } from '@/const/version';import { useHasDraft } from '@/features/ChatInput/draftStorage';import NavItem from '@/features/NavPanel/components/NavItem';+import TopicCreatorAvatar from '@/features/TopicCreatorAvatar';import { useFocusTopicPopup } from '@/features/TopicPopupGuard/useTopicPopupsRegistry';import { buildWorkspaceAwarePath } from '@/features/Workspace/workspaceAwarePath';import { useAgentGroupStore } from '@/store/agentGroup';@@ -83,9 +84,11 @@ interface TopicItemProps {status?: ChatTopicStatus | null;threadId?: string;title: string;+ /** Creator of the topic; drives the workspace creator avatar. */+ userId?: string;}-const TopicItem = memo<TopicItemProps>(({ id, title, fav, active, threadId, status }) => {+const TopicItem = memo<TopicItemProps>(({ id, title, fav, active, threadId, status, userId }) => {const { t } = useTranslation('topic');const { isDarkMode } = useTheme();// Same live-running ring as the agent sidebar topic rows (see List/Item there).@@ -276,6 +279,7 @@ const TopicItem = memo<TopicItemProps>(({ id, title, fav, active, threadId, statactive={active && !threadId}contextMenuItems={dropdownMenu}disabled={editing}+ extra={<TopicCreatorAvatar userId={userId} />}href={!editing ? href : undefined}title={title === '...' ? <DotsLoading gap={3} size={4} /> : title}titleColor={cssVar.colorText}diff --git a/src/routes/(main)/group/_layout/Sidebar/Topic/TopicListContent/ByTimeMode/GroupItem.tsx b/src/routes/(main)/group/_layout/Sidebar/Topic/TopicListContent/ByTimeMode/GroupItem.tsxindex 3534a3cc7bc..b47efde57cc 100644--- a/src/routes/(main)/group/_layout/Sidebar/Topic/TopicListContent/ByTimeMode/GroupItem.tsx+++ b/src/routes/(main)/group/_layout/Sidebar/Topic/TopicListContent/ByTimeMode/GroupItem.tsx@@ -45,6 +45,7 @@ const GroupItem = memo<GroupItemProps>(({ group, activeTopicId, activeThreadId }status={topic.status}threadId={activeThreadId}title={topic.title}+ userId={topic.userId}/>))}</Flexbox>diff --git a/src/routes/(main)/group/_layout/Sidebar/Topic/TopicListContent/FlatMode/index.tsx b/src/routes/(main)/group/_layout/Sidebar/Topic/TopicListContent/FlatMode/index.tsxindex eecc8e8d4ac..73f5b6888ba 100644--- a/src/routes/(main)/group/_layout/Sidebar/Topic/TopicListContent/FlatMode/index.tsx+++ b/src/routes/(main)/group/_layout/Sidebar/Topic/TopicListContent/FlatMode/index.tsx@@ -48,6 +48,7 @@ const FlatMode = memo(() => {status={topic.status}threadId={activeThreadId}title={topic.title}+ userId={topic.userId}/>))}{isExpandingPageSize && <SkeletonList rows={3} />}