🤯 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
🐛 fix: add the inbox agentid Sync to resume the /agnet/inbox/message=xxx link (#14035)
LiJian9e4bcf88c612
diff --git a/src/routes/(main)/agent/_layout/AgentIdSync.test.tsx b/src/routes/(main)/agent/_layout/AgentIdSync.test.tsxindex bce2b816e1e..81dda8048aa 100644--- a/src/routes/(main)/agent/_layout/AgentIdSync.test.tsx+++ b/src/routes/(main)/agent/_layout/AgentIdSync.test.tsx@@ -12,6 +12,8 @@ import AgentIdSync from './AgentIdSync';const useParamsMock = vi.hoisted(() => vi.fn());const useSearchParamsMock = vi.hoisted(() => vi.fn());+const useNavigateMock = vi.hoisted(() => vi.fn());+const useLocationMock = vi.hoisted(() => vi.fn());vi.mock('react-router-dom', async () => {// eslint-disable-next-line @typescript-eslint/consistent-type-imports@@ -19,6 +21,8 @@ vi.mock('react-router-dom', async () => {return {...actual,+ useLocation: useLocationMock,+ useNavigate: () => useNavigateMock,useParams: useParamsMock,useSearchParams: useSearchParamsMock,};@@ -28,6 +32,9 @@ describe('AgentIdSync', () => {beforeEach(() => {useParamsMock.mockReset();useSearchParamsMock.mockReset();+ useNavigateMock.mockReset();+ useLocationMock.mockReset();+ useLocationMock.mockReturnValue({ pathname: '/agent/agent-1' });useChatStore.setState({@@ -50,6 +57,7 @@ describe('AgentIdSync', () => {expect(useChatStore.getState().showPortal).toBe(true);useParamsMock.mockReturnValue({ aid: 'agent-2' });+ useLocationMock.mockReturnValue({ pathname: '/agent/agent-2' });rerender(<AgentIdSync />);expect(useChatStore.getState().activeTopicId).toBeNull();@@ -64,6 +72,7 @@ describe('AgentIdSync', () => {const { rerender } = render(<AgentIdSync />);useParamsMock.mockReturnValue({ aid: 'agent-2' });+ useLocationMock.mockReturnValue({ pathname: '/agent/agent-2' });rerender(<AgentIdSync />);expect(useChatStore.getState().portalStack).toEqual([]);diff --git a/src/routes/(main)/agent/_layout/AgentIdSync.tsx b/src/routes/(main)/agent/_layout/AgentIdSync.tsxindex f61161403a4..f404edbb91d 100644--- a/src/routes/(main)/agent/_layout/AgentIdSync.tsx+++ b/src/routes/(main)/agent/_layout/AgentIdSync.tsx@@ -1,11 +1,15 @@+import { BUILTIN_AGENT_SLUGS } from '@lobechat/builtin-agents';import { useMount, usePrevious, useUnmount } from 'ahooks';-import { useEffect, useRef } from 'react';-import { useParams, useSearchParams } from 'react-router-dom';+import { useEffect, useMemo, useRef } from 'react';+import { useLocation, useNavigate, useParams, useSearchParams } from 'react-router-dom';import { useAgentStore } from '@/store/agent';+import { builtinAgentSelectors } from '@/store/agent/selectors';import { useChatStore } from '@/store/chat';import { createStoreUpdater } from '@/store/utils/createStoreUpdater';+const BUILTIN_SLUG_SET = new Set<string>(Object.values(BUILTIN_AGENT_SLUGS));+const AgentIdSync = () => {const useStoreUpdater = createStoreUpdater(useAgentStore);const useChatStoreUpdater = createStoreUpdater(useChatStore);@@ -13,16 +17,40 @@ const AgentIdSync = () => {const [searchParams] = useSearchParams();const searchParamsRef = useRef(searchParams);searchParamsRef.current = searchParams;- const prevAgentId = usePrevious(params.aid);+ const navigate = useNavigate();+ const location = useLocation();++ // Resolve builtin agent slug to real agent ID+ const isBuiltinSlug = !!params.aid && BUILTIN_SLUG_SET.has(params.aid);+ const resolvedId = useAgentStore(+ builtinAgentSelectors.getBuiltinAgentId(isBuiltinSlug ? params.aid! : ''),+ );++ // Redirect slug URL to real agent ID URL, preserving child path and query string+ useEffect(() => {+ if (isBuiltinSlug && resolvedId) {+ const suffix = location.pathname.replace(`/agent/${params.aid}`, '');+ const qs = searchParams.toString();+ navigate(`/agent/${resolvedId}${suffix}${qs ? `?${qs}` : ''}`, { replace: true });+ }+ }, [isBuiltinSlug, resolvedId, navigate, searchParams, location.pathname, params.aid]);++ // Use resolved ID when available, fall back to URL param (e.g. anonymous mode)+ const activeId = useMemo(+ () => (isBuiltinSlug ? resolvedId || params.aid : params.aid),+ [isBuiltinSlug, resolvedId, params.aid],+ );++ const prevAgentId = usePrevious(activeId);- useStoreUpdater('activeAgentId', params.aid);- useChatStoreUpdater('activeAgentId', params.aid);+ useStoreUpdater('activeAgentId', activeId);+ useChatStoreUpdater('activeAgentId', activeId);// Reset activeTopicId when switching to a different agent// This prevents messages from being saved to the wrong topic bucketuseEffect(() => {// Only reset topic when switching between agents (not on initial mount)- if (prevAgentId !== undefined && prevAgentId !== params.aid) {+ if (prevAgentId !== undefined && prevAgentId !== activeId) {useChatStore.getState().clearPortalStack();// Preserve topic if the URL already carries one (e.g. tab navigation)@@ -34,10 +62,10 @@ const AgentIdSync = () => {}// Note: we no longer clear all unread topics on agent visit — the badge counts// unread topics and is cleared per-topic when the user actually opens each one.- }, [params.aid, prevAgentId]);+ }, [activeId, prevAgentId]);useMount(() => {- useChatStore.setState({ activeAgentId: params.aid }, false, 'AgentIdSync/mountAgentId');+ useChatStore.setState({ activeAgentId: activeId }, false, 'AgentIdSync/mountAgentId');});// Clear activeAgentId when unmounting (leaving chat page)