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(nav-rail): highlight Contacts on every agent and group page (#22843)

Arvin Xu4f5b6edf8622
diff --git a/src/features/AgentSidebar/Header/index.tsx b/src/features/AgentSidebar/Header/index.tsx
index 47bcb4fdcca..45f0b1a9cc1 100644
--- a/src/features/AgentSidebar/Header/index.tsx
+++ b/src/features/AgentSidebar/Header/index.tsx
@@ -3,14 +3,17 @@
import { type PropsWithChildren } from 'react';
import SideBarHeaderLayout from '@/features/NavPanel/SideBarHeaderLayout';
+import { useContactBackUrl } from '@/features/NavRail/useContactBackUrl';
import Agent from './Agent';
import Nav from './Nav';
const HeaderInfo = (_props: PropsWithChildren) => {
+ const backTo = useContactBackUrl();
+
return (
<>
- <SideBarHeaderLayout left={<Agent />} />
+ <SideBarHeaderLayout backTo={backTo} left={<Agent />} />
<Nav />
</>
);
diff --git a/src/features/NavPanel/railRouteKey.test.ts b/src/features/NavPanel/railRouteKey.test.ts
index d04ed31b812..17992d00cae 100644
--- a/src/features/NavPanel/railRouteKey.test.ts
+++ b/src/features/NavPanel/railRouteKey.test.ts
@@ -43,10 +43,15 @@ describe('isRailContactsRoute', () => {
['/lobe-team/agent/agent-1/channel/discord', 'lobe-team', true],
['/agent/agent-1/self-evolving/domain-1', null, true],
['/group/group-1/profile', null, true],
- ['/agent/agent-1', null, false],
- ['/agent/agent-1/tpc_1', null, false],
- ['/agent/agent-1/tasks', null, false],
- ['/group/group-1', null, false],
+ // An agent's or group's chats are its inner pages too.
+ ['/agent/agent-1', null, true],
+ ['/agent/agent-1/tpc_1', null, true],
+ ['/agent/agent-1/tasks', null, true],
+ ['/group/group-1', null, true],
+ ['/lobe-team/group/group-1/tpc_1', 'lobe-team', true],
+ ['/', null, false],
+ ['/agent', null, false],
+ ['/tasks', null, false],
])('%s β†’ %s', (pathname, activeWorkspaceSlug, expected) => {
expect(isRailContactsRoute(pathname, activeWorkspaceSlug)).toBe(expected);
});
diff --git a/src/features/NavPanel/railRouteKey.ts b/src/features/NavPanel/railRouteKey.ts
index 615789b4ba1..d79acf231ff 100644
--- a/src/features/NavPanel/railRouteKey.ts
+++ b/src/features/NavPanel/railRouteKey.ts
@@ -16,21 +16,10 @@ export const NAV_PANEL_TASKS_KEY = 'tasks';
export const NAV_PANEL_CONTACTS_KEY = 'contacts';
/**
- * Agent sub-pages that edit or describe the agent itself. The rail highlights
- * Contacts for them (profile β†’ edit); the list column stays the agent sidebar.
+ * Roots whose every page is an agent or group's own inner page β€” its chats,
+ * topics, profile and config β€” so the rail highlights Contacts for all of them.
*/
-const AGENT_CONTACT_PAGES = new Set([
- 'channel',
- 'permission',
- 'profile',
- 'self-evolving',
- 'self-learning',
- 'share',
- 'statistics',
- 'stats',
-]);
-
-const GROUP_CONTACT_PAGES = new Set(['permission', 'profile']);
+const CONTACT_ROOTS = new Set(['agent', 'group']);
const TASK_ROOTS = new Set(['goal', 'goals', 'task', 'tasks']);
@@ -45,18 +34,15 @@ const splitRoute = (pathname: string, activeWorkspaceSlug: string | null) => {
/**
* Whether the rail highlights Contacts for this route: the all-agents page and
- * agent / group profile and config pages.
+ * every page inside an agent or group, chats included.
*/
export const isRailContactsRoute = (
pathname: string,
activeWorkspaceSlug: string | null,
): boolean => {
- const [rootSegment, , pageSegment] = splitRoute(pathname, activeWorkspaceSlug);
+ const [rootSegment, id] = splitRoute(pathname, activeWorkspaceSlug);
if (rootSegment === 'agents') return true;
- if (!pageSegment) return false;
- if (rootSegment === 'agent') return AGENT_CONTACT_PAGES.has(pageSegment);
- if (rootSegment === 'group') return GROUP_CONTACT_PAGES.has(pageSegment);
- return false;
+ return !!id && !!rootSegment && CONTACT_ROOTS.has(rootSegment);
};
/**
diff --git a/src/features/NavRail/railTab.test.ts b/src/features/NavRail/railTab.test.ts
index 823cb7ec154..5e40dd2096d 100644
--- a/src/features/NavRail/railTab.test.ts
+++ b/src/features/NavRail/railTab.test.ts
@@ -5,8 +5,10 @@ import { resolveRailTab } from './railTab';
describe('resolveRailTab', () => {
it.each([
['/', null, 'messages'],
- ['/agent/agent-1', null, 'messages'],
- ['/lobe-team/group/group-1/tpc_1', 'lobe-team', 'messages'],
+ // Everything inside an agent or group is its inner page, chats included.
+ ['/agent/agent-1', null, 'contacts'],
+ ['/agent/agent-1/tpc_1', null, 'contacts'],
+ ['/lobe-team/group/group-1/tpc_1', 'lobe-team', 'contacts'],
['/agents', null, 'contacts'],
['/agent/agent-1/profile', null, 'contacts'],
['/lobe-team/group/group-1/profile', 'lobe-team', 'contacts'],
diff --git a/src/features/NavRail/railTab.ts b/src/features/NavRail/railTab.ts
index e5989d33085..292fa521278 100644
--- a/src/features/NavRail/railTab.ts
+++ b/src/features/NavRail/railTab.ts
@@ -22,8 +22,8 @@ const TAB_BY_ROOT: Record<string, RailTabKey> = {
};
/**
- * The rail tab a pathname belongs to. Agent / group chats and the home page
- * are Messages; their profile and config pages are Contacts.
+ * The rail tab a pathname belongs to. The home page is Messages; every page
+ * inside an agent or group, chats included, is Contacts.
*/
export const resolveRailTab = (
pathname: string,
diff --git a/src/features/NavRail/useContactBackUrl.test.ts b/src/features/NavRail/useContactBackUrl.test.ts
new file mode 100644
index 00000000000..7b9fbb15cb1
--- /dev/null
+++ b/src/features/NavRail/useContactBackUrl.test.ts
@@ -0,0 +1,20 @@
+import { renderHook } from '@testing-library/react';
+import { describe, expect, it, vi } from 'vitest';
+
+import { useContactBackUrl } from './useContactBackUrl';
+
+const imLayout = vi.hoisted(() => ({ value: false }));
+
+vi.mock('./useImLayout', () => ({ useImLayout: () => imLayout.value }));
+
+describe('useContactBackUrl', () => {
+ it('returns to the Contacts list in the rail layout', () => {
+ imLayout.value = true;
+ expect(renderHook(() => useContactBackUrl()).result.current).toBe('/agents');
+ });
+
+ it('returns home in the sidebar layout', () => {
+ imLayout.value = false;
+ expect(renderHook(() => useContactBackUrl()).result.current).toBe('/');
+ });
+});
diff --git a/src/features/NavRail/useContactBackUrl.ts b/src/features/NavRail/useContactBackUrl.ts
new file mode 100644
index 00000000000..8e7779c7b93
--- /dev/null
+++ b/src/features/NavRail/useContactBackUrl.ts
@@ -0,0 +1,7 @@
+import { useImLayout } from './useImLayout';
+
+/**
+ * Where back leaves an agent or group for. The rail files every page inside one
+ * under Contacts, so back returns to that list; the sidebar layout goes home.
+ */
+export const useContactBackUrl = (): string => (useImLayout() ? '/agents' : '/');
diff --git a/src/routes/(main)/group/_layout/Sidebar/Header/index.tsx b/src/routes/(main)/group/_layout/Sidebar/Header/index.tsx
index 47bcb4fdcca..45f0b1a9cc1 100644
--- a/src/routes/(main)/group/_layout/Sidebar/Header/index.tsx
+++ b/src/routes/(main)/group/_layout/Sidebar/Header/index.tsx
@@ -3,14 +3,17 @@
import { type PropsWithChildren } from 'react';
import SideBarHeaderLayout from '@/features/NavPanel/SideBarHeaderLayout';
+import { useContactBackUrl } from '@/features/NavRail/useContactBackUrl';
import Agent from './Agent';
import Nav from './Nav';
const HeaderInfo = (_props: PropsWithChildren) => {
+ const backTo = useContactBackUrl();
+
return (
<>
- <SideBarHeaderLayout left={<Agent />} />
+ <SideBarHeaderLayout backTo={backTo} left={<Agent />} />
<Nav />
</>
);