🤯 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(agent): switch the profile group from a sidebar instead of header tabs (#22630)
Arvin Xu089d97536c79
diff --git a/locales/en-US/chat.json b/locales/en-US/chat.jsonindex fed87b9944e..4b443776b92 100644--- a/locales/en-US/chat.json+++ b/locales/en-US/chat.json@@ -2362,6 +2362,7 @@"supervisor.todoList.allComplete": "All tasks completed","supervisor.todoList.title": "Tasks Completed","tab.groupProfile": "Group Profile",+ "tab.backToChat": "Back to chat","tab.integration": "IM Bots","tab.profile": "Agent Profile","tab.profileBasic": "Profile",diff --git a/locales/zh-CN/chat.json b/locales/zh-CN/chat.jsonindex cbf0285bfdb..e1582da6272 100644--- a/locales/zh-CN/chat.json+++ b/locales/zh-CN/chat.json@@ -2362,6 +2362,7 @@"supervisor.todoList.allComplete": "所有任务已完成","supervisor.todoList.title": "任务完成","tab.groupProfile": "群组档案",+ "tab.backToChat": "返回对话","tab.integration": "IM 机器人","tab.profile": "助理档案","tab.profileBasic": "基础档案",diff --git a/packages/locales/src/default/chat.ts b/packages/locales/src/default/chat.tsindex d4282254891..400382ec756 100644--- a/packages/locales/src/default/chat.ts+++ b/packages/locales/src/default/chat.ts@@ -1967,6 +1967,7 @@ export default {'supervisor.todoList.allComplete': 'All tasks completed','supervisor.todoList.title': 'Tasks Completed','tab.groupProfile': 'Group Profile',+ 'tab.backToChat': 'Back to chat','tab.integration': 'IM Bots','tab.profile': 'Agent Profile','tab.profileBasic': 'Profile',diff --git a/src/components/Skeleton/AgentProfileNav.tsx b/src/components/Skeleton/AgentProfileNav.tsxindex 224968b9caa..f55cfd7ef92 100644--- a/src/components/Skeleton/AgentProfileNav.tsx+++ b/src/components/Skeleton/AgentProfileNav.tsx@@ -2,6 +2,8 @@import { Center, cssVar, Flexbox } from '@lobehub/ui';+import { isMobileSurface } from '@/utils/mobileSurface';+import SkeletonBar from './Bar';export interface AgentProfileNavSkeletonProps {@@ -9,7 +11,7 @@ export interface AgentProfileNavSkeletonProps {actions?: number;/** Extra breadcrumb segments after the agent name (e.g. `Channels › Discord`). */breadcrumbItems?: number;- /** Whether the centred profile tab switcher is drawn (hidden on nested detail pages). */+ /** Whether the centred profile tab switcher is drawn (mobile only, and not on nested detail pages). */tabs?: boolean;}@@ -23,7 +25,7 @@ export interface AgentProfileNavSkeletonProps {const AgentProfileNavSkeleton = ({actions = 0,breadcrumbItems = 0,- tabs = true,+ tabs = isMobileSurface(),}: AgentProfileNavSkeletonProps) => (<Flexboxhorizontaldiff --git a/src/features/AgentProfileTabs/index.tsx b/src/features/AgentProfileTabs/index.tsxindex 9510df1dc0d..dad8d3a9058 100644--- a/src/features/AgentProfileTabs/index.tsx+++ b/src/features/AgentProfileTabs/index.tsx@@ -1,20 +1,13 @@'use client';import { Segmented } from '@lobehub/ui';-import { type CSSProperties, memo, useMemo } from 'react';-import { useTranslation } from 'react-i18next';+import { type CSSProperties, memo } from 'react';-import { useAgentShareSupported } from '@/business/client/useAgentShareSupported';-import { useResourceAccess } from '@/features/ResourcePermission/useResourceAccess';import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';-import { usePermission } from '@/hooks/usePermission';-import { featureFlagsSelectors, useServerConfigStore } from '@/store/serverConfig';+import { isMobileSurface } from '@/utils/mobileSurface';-import {- type AgentProfileTab,- buildAgentProfileTabOptions,- buildAgentProfileTabPath,-} from './tabOptions';+import { type AgentProfileTab, buildAgentProfileTabPath } from './tabOptions';+import { useAgentProfileTabOptions } from './useAgentProfileTabOptions';export type { AgentProfileTab } from './tabOptions';@@ -46,45 +39,9 @@ interface AgentProfileTabsProps {agentId: string;}-/**- * Segmented switcher shared by the agent profile group — Profile / Channels /- * Statistics / Share. The surfaces are separate routes, so a segment writes the- * URL rather than holding local state: deep links and back/forward keep working.- */-const AgentProfileTabs = memo<AgentProfileTabsProps>(({ active, agentId }) => {- const { t } = useTranslation(['chat', 'common', 'spend']);+const MobileAgentProfileTabs = memo<AgentProfileTabsProps>(({ active, agentId }) => {const navigate = useWorkspaceAwareNavigate();-- const { allowed: canEditContent } = usePermission('edit_own_content');- const { canEditResource, canManageResource, isAccessResolved } = useResourceAccess(- 'agent',- agentId,- );- const { isAgentEditable } = useServerConfigStore(featureFlagsSelectors);-- const canConfigure = !!isAgentEditable && isAccessResolved && canEditContent && canEditResource;- const canManageShare =- !!isAgentEditable && isAccessResolved && canEditContent && canManageResource;- const { visible: shareVisible } = useAgentShareSupported(agentId);-- const options = useMemo(- () =>- buildAgentProfileTabOptions({- active,- canConfigure,- labels: {- channel: t('tab.integration'),- // Inside the profile group the whole surface *is* the agent profile,- // so the first segment is the "basic" tab, not "Agent Profile" again —- // that broader name stays on the sidebar entry that opens the group.- profile: t('tab.profileBasic'),- share: t('share', { ns: 'common' }),- statistics: t('usageStats.title', { ns: 'spend' }),- },- shareSupported: shareVisible === true && canManageShare,- }),- [active, canConfigure, canManageShare, shareVisible, t],- );+ const options = useAgentProfileTabOptions(active, agentId);// A lone segment is a label, not a switcher.if (options.length < 2) return null;@@ -102,6 +59,16 @@ const AgentProfileTabs = memo<AgentProfileTabsProps>(({ active, agentId }) => {);});-AgentProfileTabs.displayName = 'AgentProfileTabs';+MobileAgentProfileTabs.displayName = 'MobileAgentProfileTabs';++/**+ * Segmented switcher for the agent profile group — Profile / Channels /+ * Statistics / Share — on mobile, which has no room for a sidebar. Desktop+ * switches them from the sidebar (`AgentSidebar/ProfileNav`). The surfaces are+ * separate routes, so a segment writes the URL rather than holding local state:+ * deep links and back/forward keep working.+ */+const AgentProfileTabs = (props: AgentProfileTabsProps) =>+ isMobileSurface() ? <MobileAgentProfileTabs {...props} /> : null;export default AgentProfileTabs;diff --git a/src/features/AgentProfileTabs/tabOptions.test.ts b/src/features/AgentProfileTabs/tabOptions.test.tsindex 1e4c60ddfcc..8879330abb9 100644--- a/src/features/AgentProfileTabs/tabOptions.test.ts+++ b/src/features/AgentProfileTabs/tabOptions.test.ts@@ -1,6 +1,10 @@import { describe, expect, it } from 'vitest';-import { buildAgentProfileTabOptions, buildAgentProfileTabPath } from './tabOptions';+import {+ buildAgentProfileTabOptions,+ buildAgentProfileTabPath,+ getAgentProfileTab,+} from './tabOptions';const labels = {channel: 'tab.integration',@@ -15,6 +19,24 @@ describe('buildAgentProfileTabPath', () => {});});+describe('getAgentProfileTab', () => {+ it.each([+ ['/agent/agt_1/profile', 'profile'],+ ['/agent/agt_1/channel/slack', 'channel'],+ ['/acme/agent/agt_1/statistics/', 'statistics'],+ ['/_dangerous_local_dev_proxy/acme/agent/agt_1/share', 'share'],+ ])('maps %s to its tab', (pathname, tab) => {+ expect(getAgentProfileTab(pathname)).toBe(tab);+ });++ it.each(['/agent/agt_1', '/agent/agt_1/tpc_1', '/agent/agt_1/share/extra', '/settings/profile'])(+ 'leaves %s outside the group',+ (pathname) => {+ expect(getAgentProfileTab(pathname)).toBeUndefined();+ },+ );+});+describe('buildAgentProfileTabOptions', () => {it('lists the full group for a member who can configure the agent', () => {const options = buildAgentProfileTabOptions({diff --git a/src/features/AgentProfileTabs/tabOptions.ts b/src/features/AgentProfileTabs/tabOptions.tsindex df9efbc8db6..149cc81e55d 100644--- a/src/features/AgentProfileTabs/tabOptions.ts+++ b/src/features/AgentProfileTabs/tabOptions.ts@@ -10,6 +10,22 @@ export interface AgentProfileTabOption {export const buildAgentProfileTabPath = (agentId: string, tab: AgentProfileTab) =>urlJoin('/agent', agentId, tab);+const AGENT_PROFILE_ROUTE =+ /^(?:\/[^/]+)?\/agent\/[^/]+\/(profile|channel(?:\/[^/]+)?|statistics|share)\/?$/;++/**+ * The profile-group tab a URL belongs to, if any. Anchored on Agent subroutes,+ * not substrings: `/channels/:id` and workspace slugs such as `channel-team`+ * are not part of the group.+ */+export const getAgentProfileTab = (pathname: string): AgentProfileTab | undefined => {+ const segment = AGENT_PROFILE_ROUTE.exec(+ pathname.replace(/^\/_dangerous_local_dev_proxy(?=\/)/, ''),+ )?.[1];++ return segment?.split('/')[0] as AgentProfileTab | undefined;+};+/*** Which segments the profile-group switcher shows.*diff --git a/src/features/AgentProfileTabs/useAgentProfileTabOptions.ts b/src/features/AgentProfileTabs/useAgentProfileTabOptions.tsnew file mode 100644index 00000000000..f0736062c9e--- /dev/null+++ b/src/features/AgentProfileTabs/useAgentProfileTabOptions.ts@@ -0,0 +1,45 @@+import { useMemo } from 'react';+import { useTranslation } from 'react-i18next';++import { useAgentShareSupported } from '@/business/client/useAgentShareSupported';+import { useResourceAccess } from '@/features/ResourcePermission/useResourceAccess';+import { usePermission } from '@/hooks/usePermission';+import { featureFlagsSelectors, useServerConfigStore } from '@/store/serverConfig';++import { type AgentProfileTab, buildAgentProfileTabOptions } from './tabOptions';++/** The profile-group entries this member may open, for any switcher of the group. */+export const useAgentProfileTabOptions = (active: AgentProfileTab, agentId: string) => {+ const { t } = useTranslation(['chat', 'common', 'spend']);++ const { allowed: canEditContent } = usePermission('edit_own_content');+ const { canEditResource, canManageResource, isAccessResolved } = useResourceAccess(+ 'agent',+ agentId,+ );+ const { isAgentEditable } = useServerConfigStore(featureFlagsSelectors);++ const canConfigure = !!isAgentEditable && isAccessResolved && canEditContent && canEditResource;+ const canManageShare =+ !!isAgentEditable && isAccessResolved && canEditContent && canManageResource;+ const { visible: shareVisible } = useAgentShareSupported(agentId);++ return useMemo(+ () =>+ buildAgentProfileTabOptions({+ active,+ canConfigure,+ labels: {+ channel: t('tab.integration'),+ // Inside the profile group the whole surface *is* the agent profile,+ // so the first entry is the "basic" tab, not "Agent Profile" again —+ // that broader name stays on the sidebar entry that opens the group.+ profile: t('tab.profileBasic'),+ share: t('share', { ns: 'common' }),+ statistics: t('usageStats.title', { ns: 'spend' }),+ },+ shareSupported: shareVisible === true && canManageShare,+ }),+ [active, canConfigure, canManageShare, shareVisible, t],+ );+};diff --git a/src/features/AgentSidebar/Content.test.tsx b/src/features/AgentSidebar/Content.test.tsxnew file mode 100644index 00000000000..e0fad60911c--- /dev/null+++ b/src/features/AgentSidebar/Content.test.tsx@@ -0,0 +1,52 @@+import { render, screen } from '@testing-library/react';+import { afterEach, describe, expect, it, vi } from 'vitest';++import AgentSidebarContent from './Content';++const mocks = vi.hoisted(() => ({ pathname: '/agent/agt_1' }));++vi.mock('@/hooks/useActiveLocation', () => ({+ useActiveLocation: () => ({ pathname: mocks.pathname }),+}));+vi.mock('@/features/NavPanel/SideBarLayout', () => ({+ default: ({ body }: { body: React.ReactNode }) => <div>{body}</div>,+}));+vi.mock('./Body', () => ({ default: () => <div>topics</div> }));+vi.mock('./Header', () => ({ default: () => null }));+vi.mock('./ProfileNav', () => ({+ default: ({ active }: { active: string }) => <div>profile-nav:{active}</div>,+}));++describe('AgentSidebarContent', () => {+ afterEach(() => {+ vi.unstubAllGlobals();+ });++ it.each([+ ['/agent/agt_1/profile', 'profile'],+ ['/agent/agt_1/channel/slack', 'channel'],+ ['/agent/agt_1/statistics', 'statistics'],+ ['/agent/agt_1/share', 'share'],+ ])('replaces the topic sidebar on %s', (pathname, tab) => {+ mocks.pathname = pathname;+ render(<AgentSidebarContent />);++ expect(screen.getByText(`profile-nav:${tab}`)).toBeInTheDocument();+ expect(screen.queryByText('topics')).not.toBeInTheDocument();+ });++ it('keeps the topic sidebar in the chat', () => {+ mocks.pathname = '/agent/agt_1';+ render(<AgentSidebarContent />);++ expect(screen.getByText('topics')).toBeInTheDocument();+ });++ it('keeps the topic sidebar on mobile, which still uses the header switcher', () => {+ vi.stubGlobal('__MOBILE__', true);+ mocks.pathname = '/agent/agt_1/profile';+ render(<AgentSidebarContent />);++ expect(screen.getByText('topics')).toBeInTheDocument();+ });+});diff --git a/src/features/AgentSidebar/Content.tsx b/src/features/AgentSidebar/Content.tsxindex 65cdd1130da..cf65897992e 100644--- a/src/features/AgentSidebar/Content.tsx+++ b/src/features/AgentSidebar/Content.tsx@@ -1,9 +1,19 @@+import { getAgentProfileTab } from '@/features/AgentProfileTabs/tabOptions';import SideBarLayout from '@/features/NavPanel/SideBarLayout';+import { useActiveLocation } from '@/hooks/useActiveLocation';+import { isMobileSurface } from '@/utils/mobileSurface';import Body from './Body';import Header from './Header';+import ProfileNav from './ProfileNav';const AgentSidebarContent = () => {+ const { pathname } = useActiveLocation();+ // Mobile keeps the header Segmented; this panel is only its chat drawer there.+ const profileTab = isMobileSurface() ? undefined : getAgentProfileTab(pathname);++ if (profileTab) return <ProfileNav active={profileTab} />;+return <SideBarLayout body={<Body />} header={<Header />} />;};diff --git a/src/features/AgentSidebar/Header/Nav.tsx b/src/features/AgentSidebar/Header/Nav.tsxindex f57fb501cf0..fa1ae73bf73 100644--- a/src/features/AgentSidebar/Header/Nav.tsx+++ b/src/features/AgentSidebar/Header/Nav.tsx@@ -39,9 +39,9 @@ const Nav = memo(() => {const params = useActiveRouteParams();const agentId = params.aid;const { pathname } = useActiveLocation();- // The profile entry now owns a group of sub-views — profile / channels /- // statistics — switched by a Segmented in the page header, so all three keep- // this entry lit instead of leaving the sidebar with nothing selected.+ // The profile entry owns a group of sub-views — profile / channels /+ // statistics / share. On mobile they stay switched by a Segmented while this+ // list remains in the drawer, so every one of them keeps this entry lit.const isProfileActive = isAgentProfileRoute(pathname);const isGoalsActive = pathname.endsWith('/goals');// 下钻页 /self-evolving/:domainId 也算在这个入口下,否则点进去侧边栏就失焦了diff --git a/src/features/AgentSidebar/Header/isAgentProfileRoute.test.ts b/src/features/AgentSidebar/Header/isAgentProfileRoute.test.tsindex 75d8848d2af..a0405f9168a 100644--- a/src/features/AgentSidebar/Header/isAgentProfileRoute.test.ts+++ b/src/features/AgentSidebar/Header/isAgentProfileRoute.test.ts@@ -8,6 +8,7 @@ describe('isAgentProfileRoute', () => {'/agent/agt_1/channel','/agent/agt_1/channel/slack','/agent/agt_1/statistics',+ '/agent/agt_1/share','/acme/agent/agt_1/profile','/acme/agent/agt_1/channel/slack','/acme/agent/agt_1/statistics/',diff --git a/src/features/AgentSidebar/Header/isAgentProfileRoute.ts b/src/features/AgentSidebar/Header/isAgentProfileRoute.tsindex bb2c9609690..776344f0d8f 100644--- a/src/features/AgentSidebar/Header/isAgentProfileRoute.ts+++ b/src/features/AgentSidebar/Header/isAgentProfileRoute.ts@@ -1,8 +1,3 @@-/**- * Match Agent subroutes, not arbitrary substrings: `/channels/:id` and workspace- * slugs such as `channel-team` must not light up the profile entry.- */-export const isAgentProfileRoute = (pathname: string) =>- /^(?:\/[^/]+)?\/agent\/[^/]+\/(?:profile|channel(?:\/[^/]+)?|statistics)\/?$/.test(- pathname.replace(/^\/_dangerous_local_dev_proxy(?=\/)/, ''),- );+import { getAgentProfileTab } from '@/features/AgentProfileTabs/tabOptions';++export const isAgentProfileRoute = (pathname: string) => !!getAgentProfileTab(pathname);diff --git a/src/features/AgentSidebar/ProfileNav.tsx b/src/features/AgentSidebar/ProfileNav.tsxnew file mode 100644index 00000000000..13efe673b1f--- /dev/null+++ b/src/features/AgentSidebar/ProfileNav.tsx@@ -0,0 +1,82 @@+'use client';++import { Flexbox } from '@lobehub/ui';+import type { LucideIcon } from 'lucide-react';+import {+ ChartColumnBigIcon,+ ChevronLeftIcon,+ FileUserIcon,+ RadioTowerIcon,+ Share2Icon,+} from 'lucide-react';+import { useTranslation } from 'react-i18next';+import urlJoin from 'url-join';++import {+ type AgentProfileTab,+ buildAgentProfileTabPath,+} from '@/features/AgentProfileTabs/tabOptions';+import { useAgentProfileTabOptions } from '@/features/AgentProfileTabs/useAgentProfileTabOptions';+import NavItem from '@/features/NavPanel/components/NavItem';+import SideBarHeaderLayout from '@/features/NavPanel/SideBarHeaderLayout';+import SideBarLayout from '@/features/NavPanel/SideBarLayout';+import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';+import { useActiveRouteParams } from '@/hooks/useActiveRouteParams';++import Agent from './Header/Agent';++const TAB_ICONS: Record<AgentProfileTab, LucideIcon> = {+ channel: RadioTowerIcon,+ profile: FileUserIcon,+ share: Share2Icon,+ statistics: ChartColumnBigIcon,+};++interface ProfileNavProps {+ active: AgentProfileTab;+}++/** Replaces the topic sidebar while the agent's profile group is open. */+const ProfileNav = ({ active }: ProfileNavProps) => {+ const { t } = useTranslation('chat');+ const navigate = useWorkspaceAwareNavigate();+ const agentId = useActiveRouteParams().aid!;+ const options = useAgentProfileTabOptions(active, agentId);++ return (+ <SideBarLayout+ body={+ <Flexbox gap={1} paddingInline={4}>+ {options.map(({ label, value }) => (+ <NavItem+ active={value === active}+ icon={TAB_ICONS[value]}+ key={value}+ title={label}+ onClick={() => navigate(buildAgentProfileTabPath(agentId, value))}+ />+ ))}+ </Flexbox>+ }+ header={+ <>+ <SideBarHeaderLayout+ showBack={false}+ left={+ <NavItem+ icon={ChevronLeftIcon}+ title={t('tab.backToChat')}+ onClick={() => navigate(urlJoin('/agent', agentId))}+ />+ }+ />+ <Flexbox paddingBlock={'0 8px'} paddingInline={6}>+ <Agent />+ </Flexbox>+ </>+ }+ />+ );+};++export default ProfileNav;