🤯 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: restore task agent panel toggle (#14321)
YuTengjing9aea74659fbb
diff --git a/src/features/AgentTasks/AgentTaskList/AgentTasksPage.test.ts b/src/features/AgentTasks/AgentTaskList/AgentTasksPage.test.tsnew file mode 100644index 00000000000..68ecdc14f42--- /dev/null+++ b/src/features/AgentTasks/AgentTaskList/AgentTasksPage.test.ts@@ -0,0 +1,15 @@+import { describe, expect, it } from 'vitest';++import { shouldRenderTaskAgentPanelToggle } from './taskAgentPanelToggle';++describe('AgentTasksPage', () => {+ describe('shouldRenderTaskAgentPanelToggle', () => {+ it('should render the task agent panel toggle on desktop layouts', () => {+ expect(shouldRenderTaskAgentPanelToggle(false)).toBe(true);+ });++ it('should hide the task agent panel toggle on mobile layouts', () => {+ expect(shouldRenderTaskAgentPanelToggle(true)).toBe(false);+ });+ });+});diff --git a/src/features/AgentTasks/AgentTaskList/AgentTasksPage.tsx b/src/features/AgentTasks/AgentTaskList/AgentTasksPage.tsxindex 562e3447d1c..fccca3b7ddc 100644--- a/src/features/AgentTasks/AgentTaskList/AgentTasksPage.tsx+++ b/src/features/AgentTasks/AgentTaskList/AgentTasksPage.tsx@@ -5,7 +5,9 @@ import { useNavigate } from 'react-router-dom';import { DESKTOP_HEADER_ICON_SIZE } from '@/const/layoutTokens';import NavHeader from '@/features/NavHeader';+import ToggleRightPanelButton from '@/features/RightPanel/ToggleRightPanelButton';import WideScreenContainer from '@/features/WideScreenContainer';+import { useIsMobile } from '@/hooks/useIsMobile';import { useGlobalStore } from '@/store/global';import { systemStatusSelectors } from '@/store/global/selectors';import { useTaskStore } from '@/store/task';@@ -17,17 +19,23 @@ import CreateTaskInlineEntry from './CreateTaskInlineEntry';import KanbanBoard from './KanbanBoard';import type { TaskListViewOptions } from './listViewOptions';import { normalizeTaskListViewOptions } from './listViewOptions';+import { shouldRenderTaskAgentPanelToggle } from './taskAgentPanelToggle';import TaskList from './TaskList';import TasksGroupConfig from './TasksGroupConfig';const AgentTasksPage = memo(() => {const navigate = useNavigate();+ const isMobile = useIsMobile();const viewMode = useTaskStore(taskListSelectors.viewMode);const useFetchTaskList = useTaskStore((s) => s.useFetchTaskList);useFetchTaskList({ allAgents: true });const rawViewOptions = useGlobalStore(systemStatusSelectors.taskListViewOptions);const viewOptions = useMemo(() => normalizeTaskListViewOptions(rawViewOptions), [rawViewOptions]);const inlineCollapsed = useGlobalStore(systemStatusSelectors.taskCreateInlineCollapsed);+ const [showTaskAgentPanel, toggleTaskAgentPanel] = useGlobalStore((s) => [+ systemStatusSelectors.showTaskAgentPanel(s),+ s.toggleTaskAgentPanel,+ ]);const updateSystemStatus = useGlobalStore((s) => s.updateSystemStatus);const setViewOptions = useCallback((updater: (prev: TaskListViewOptions) => TaskListViewOptions) => {@@ -49,6 +57,8 @@ const AgentTasksPage = memo(() => {setViewOptions((prev) => ({ ...prev, hideCompleted: false }));}, [setViewOptions]);+ const showTaskAgentPanelToggle = shouldRenderTaskAgentPanelToggle(isMobile);+return (<Flexbox flex={1} height={'100%'}><NavHeader@@ -59,6 +69,13 @@ const AgentTasksPage = memo(() => {<ActionIcon icon={Plus} size={DESKTOP_HEADER_ICON_SIZE} onClick={handleCreateTask} />)}<TasksGroupConfig options={viewOptions} setOptions={setViewOptions} />+ {showTaskAgentPanelToggle && (+ <ToggleRightPanelButton+ hideWhenExpanded+ expand={showTaskAgentPanel}+ onToggle={() => toggleTaskAgentPanel()}+ />+ )}</Flexbox>}styles={{diff --git a/src/features/AgentTasks/AgentTaskList/taskAgentPanelToggle.ts b/src/features/AgentTasks/AgentTaskList/taskAgentPanelToggle.tsnew file mode 100644index 00000000000..a8e64394c84--- /dev/null+++ b/src/features/AgentTasks/AgentTaskList/taskAgentPanelToggle.ts@@ -0,0 +1,5 @@+/**+ * Task routes only mount AgentTaskManager on desktop layouts, so mobile must not+ * expose a toggle that changes an invisible panel state.+ */+export const shouldRenderTaskAgentPanelToggle = (isMobile: boolean) => !isMobile;diff --git a/src/hooks/useHotkeys/globalScope.test.ts b/src/hooks/useHotkeys/globalScope.test.tsnew file mode 100644index 00000000000..d71c7209884--- /dev/null+++ b/src/hooks/useHotkeys/globalScope.test.ts@@ -0,0 +1,115 @@+import { HotkeyEnum } from '@lobechat/const/hotkeys';+import { act, renderHook } from '@testing-library/react';+import { beforeEach, describe, expect, it, vi } from 'vitest';++import type { HotkeyId } from '@/types/hotkey';++import { isTaskPanelRoute, useToggleRightPanelHotkey } from './globalScope';++interface MockGlobalState {+ status: { zenMode: boolean };+ toggleRightPanel: () => void;+ toggleTaskAgentPanel: () => void;+ updateSystemStatus: () => void;+}++type HotkeyRegistrationArgs = [HotkeyId, () => void, ...unknown[]];++const mocks = vi.hoisted(() => ({+ hotkeyCallback: undefined as (() => void) | undefined,+ pathname: '/',+ toggleRightPanel: vi.fn(),+ toggleTaskAgentPanel: vi.fn(),+ useHotkeyById: vi.fn(),+}));++vi.mock('react-router-dom', () => ({+ useLocation: () => ({ pathname: mocks.pathname }),+}));++vi.mock('@/hooks/useNavigateToAgent', () => ({+ useNavigateToAgent: () => vi.fn(),+}));++vi.mock('@/hooks/usePinnedAgentState', () => ({+ usePinnedAgentState: () => [undefined, { unpinAgent: vi.fn() }],+}));++vi.mock('@/store/global', () => ({+ useGlobalStore: (selector: (state: MockGlobalState) => unknown) =>+ selector({+ status: { zenMode: false },+ toggleRightPanel: mocks.toggleRightPanel,+ toggleTaskAgentPanel: mocks.toggleTaskAgentPanel,+ updateSystemStatus: vi.fn(),+ }),+}));++vi.mock('./useHotkeyById', () => ({+ useHotkeyById: (...args: HotkeyRegistrationArgs) => mocks.useHotkeyById(...args),+}));++describe('globalScope hotkeys', () => {+ beforeEach(() => {+ mocks.hotkeyCallback = undefined;+ mocks.pathname = '/';+ mocks.toggleRightPanel.mockReset();+ mocks.toggleTaskAgentPanel.mockReset();+ mocks.useHotkeyById.mockReset();+ mocks.useHotkeyById.mockImplementation((_, callback) => {+ mocks.hotkeyCallback = callback;+ return { id: HotkeyEnum.ToggleRightPanel };+ });+ });++ describe('isTaskPanelRoute', () => {+ it('should match task panel routes only', () => {+ expect(isTaskPanelRoute('/tasks')).toBe(true);+ expect(isTaskPanelRoute('/tasks/filter')).toBe(true);+ expect(isTaskPanelRoute('/task/T-1')).toBe(true);+ expect(isTaskPanelRoute('/agent/inbox')).toBe(false);+ expect(isTaskPanelRoute('/task-template')).toBe(false);+ });+ });++ describe('useToggleRightPanelHotkey', () => {+ it('should toggle task agent panel on task routes', () => {+ mocks.pathname = '/tasks';++ renderHook(() => useToggleRightPanelHotkey());++ act(() => {+ mocks.hotkeyCallback?.();+ });++ expect(mocks.toggleTaskAgentPanel).toHaveBeenCalledTimes(1);+ expect(mocks.toggleRightPanel).not.toHaveBeenCalled();+ });++ it('should toggle task agent panel on task detail routes', () => {+ mocks.pathname = '/task/T-1';++ renderHook(() => useToggleRightPanelHotkey());++ act(() => {+ mocks.hotkeyCallback?.();+ });++ expect(mocks.toggleTaskAgentPanel).toHaveBeenCalledTimes(1);+ expect(mocks.toggleRightPanel).not.toHaveBeenCalled();+ });++ it('should keep toggling the generic right panel on non-task routes', () => {+ mocks.pathname = '/agent/inbox';++ renderHook(() => useToggleRightPanelHotkey());++ act(() => {+ mocks.hotkeyCallback?.();+ });++ expect(mocks.toggleRightPanel).toHaveBeenCalledTimes(1);+ expect(mocks.toggleTaskAgentPanel).not.toHaveBeenCalled();+ });+ });+});diff --git a/src/hooks/useHotkeys/globalScope.ts b/src/hooks/useHotkeys/globalScope.tsindex a4fef8d190a..df71f9e3028 100644--- a/src/hooks/useHotkeys/globalScope.ts+++ b/src/hooks/useHotkeys/globalScope.ts@@ -1,5 +1,6 @@import { INBOX_SESSION_ID } from '@lobechat/const';import { HotkeyEnum } from '@lobechat/const/hotkeys';+import { useLocation } from 'react-router-dom';import { useNavigateToAgent } from '@/hooks/useNavigateToAgent';import { usePinnedAgentState } from '@/hooks/usePinnedAgentState';@@ -7,6 +8,13 @@ import { useGlobalStore } from '@/store/global';import { useHotkeyById } from './useHotkeyById';+/**+ * Task routes render AgentTaskManager, whose panel status is intentionally+ * independent from the generic right panel used by chat and page editor routes.+ */+export const isTaskPanelRoute = (pathname: string) =>+ pathname === '/tasks' || pathname.startsWith('/tasks/') || pathname.startsWith('/task/');+// Switch to chat tab (and focus on Lobe AI)export const useNavigateToChatHotkey = () => {const navigateToAgent = useNavigateToAgent();@@ -39,13 +47,30 @@ export const useToggleLeftPanelHotkey = () => {};export const useToggleRightPanelHotkey = () => {+ const { pathname } = useLocation();const isZenMode = useGlobalStore((s) => s.status.zenMode);- const toggleConfig = useGlobalStore((s) => s.toggleRightPanel);+ const [toggleRightPanel, toggleTaskAgentPanel] = useGlobalStore((s) => [+ s.toggleRightPanel,+ s.toggleTaskAgentPanel,+ ]);+ const isTaskRoute = isTaskPanelRoute(pathname);- return useHotkeyById(HotkeyEnum.ToggleRightPanel, () => toggleConfig(), {- enableOnContentEditable: true,- enabled: !isZenMode,- });+ return useHotkeyById(+ HotkeyEnum.ToggleRightPanel,+ () => {+ if (isTaskRoute) {+ toggleTaskAgentPanel();+ return;+ }++ toggleRightPanel();+ },+ {+ enableOnContentEditable: true,+ enabled: !isZenMode,+ },+ [isTaskRoute, toggleRightPanel, toggleTaskAgentPanel],+ );};// CMDK