🤯 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 task drawer agent metadata hydration (#14315)
AmAzing-babdc6ade537
diff --git a/packages/context-engine/src/engine/messages/__tests__/MessagesEngine.test.ts b/packages/context-engine/src/engine/messages/__tests__/MessagesEngine.test.tsindex 054ca77daec..6ded4fe4504 100644--- a/packages/context-engine/src/engine/messages/__tests__/MessagesEngine.test.ts+++ b/packages/context-engine/src/engine/messages/__tests__/MessagesEngine.test.ts@@ -175,7 +175,7 @@ describe('MessagesEngine', () => {{function: {arguments: '{"path":"/tmp/a.ts"}',- name: 'lobe-local-system____readLocalFile____builtin',+ name: 'lobe-local-system____readLocalFile',},id: 'call_local-system-snapshot-1',type: 'function',@@ -184,7 +184,7 @@ describe('MessagesEngine', () => {});expect(result.messages).toContainEqual({content: 'File: /tmp/a.ts (lines 0-200)\n\nconst a = 1;\n',- name: 'lobe-local-system____readLocalFile____builtin',+ name: 'lobe-local-system____readLocalFile',role: 'tool',tool_call_id: 'call_local-system-snapshot-1',});diff --git a/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/index.test.tsx b/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/index.test.tsxnew file mode 100644index 00000000000..90787759f3b--- /dev/null+++ b/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/index.test.tsx@@ -0,0 +1,146 @@+/**+ * @vitest-environment happy-dom+ */+import { render } from '@testing-library/react';+import type { ReactNode } from 'react';+import { beforeEach, describe, expect, it, vi } from 'vitest';++import TopicChatDrawer from './index';++const mocks = vi.hoisted(() => ({+ agentState: {+ useHydrateAgentConfig: vi.fn(),+ },+ chatState: {+ dbMessagesMap: {} as Record<string, unknown[]>,+ replaceMessages: vi.fn(),+ },+ serverConfigState: {+ serverConfig: {+ enableBusinessFeatures: false,+ },+ },+ taskState: {+ activeTaskId: 'T-1',+ activeTopicDrawerTopicId: 'topic-1',+ closeTopicDrawer: vi.fn(),+ taskDetailMap: {+ 'T-1': {+ activities: [+ {+ id: 'topic-1',+ status: 'completed',+ time: '2026-04-29T00:00:00.000Z',+ title: 'Topic 1',+ type: 'topic',+ },+ ],+ agentId: 'agt_assignee',+ identifier: 'T-1',+ instruction: 'Do the task',+ status: 'completed',+ },+ },+ },+ userState: {+ isSignedIn: true,+ },+}));++vi.mock('@lobehub/ui', () => ({+ ActionIcon: ({ onClick }: { onClick?: () => void }) => <button onClick={onClick} />,+ copyToClipboard: vi.fn(),+ Drawer: ({ children, open }: { children?: ReactNode; open?: boolean }) =>+ open ? <div data-testid="topic-drawer">{children}</div> : null,+ DropdownMenu: ({ children }: { children?: ReactNode }) => <>{children}</>,+ Flexbox: ({ children }: { children?: ReactNode }) => <div>{children}</div>,+ Text: ({ children }: { children?: ReactNode }) => <span>{children}</span>,+}));++vi.mock('antd-style', () => ({+ cssVar: {+ colorBorderSecondary: '#ddd',+ },+}));++vi.mock('next/dynamic', () => ({+ default: () =>+ function DynamicComponent({ children }: { children?: ReactNode }) {+ return <>{children}</>;+ },+}));++vi.mock('react-i18next', () => ({+ useTranslation: () => ({+ t: (key: string) => key,+ }),+}));++vi.mock('@/features/Conversation', () => ({+ ChatList: () => <div data-testid="chat-list" />,+ ConversationProvider: ({ children }: { children?: ReactNode }) => <>{children}</>,+ MessageItem: ({ id }: { id: string }) => <div data-testid="message-item">{id}</div>,+}));++vi.mock('@/features/Conversation/Markdown/plugins/Task', () => ({+ TaskCardScopeProvider: ({ children }: { children?: ReactNode }) => <>{children}</>,+}));++vi.mock('@/features/ShareModal', () => ({+ useShareModal: () => ({+ openShareModal: vi.fn(),+ }),+}));++vi.mock('@/hooks/useGatewayReconnect', () => ({+ useGatewayReconnect: vi.fn(),+}));++vi.mock('@/hooks/useOperationState', () => ({+ useOperationState: () => undefined,+}));++vi.mock('@/store/agent', () => ({+ useAgentStore: (selector: (state: typeof mocks.agentState) => unknown) =>+ selector(mocks.agentState),+}));++vi.mock('@/store/chat', () => ({+ useChatStore: (selector: (state: typeof mocks.chatState) => unknown) => selector(mocks.chatState),+}));++vi.mock('@/store/serverConfig', () => ({+ useServerConfigStore: (selector: (state: typeof mocks.serverConfigState) => unknown) =>+ selector(mocks.serverConfigState),+}));++vi.mock('@/store/task', () => ({+ useTaskStore: (selector: (state: typeof mocks.taskState) => unknown) => selector(mocks.taskState),+}));++vi.mock('@/store/user', () => ({+ useUserStore: (selector: (state: typeof mocks.userState) => unknown) => selector(mocks.userState),+}));++vi.mock('@/store/chat/utils/messageMapKey', () => ({+ messageMapKey: () => 'topic-chat-key',+}));++vi.mock('../TopicStatusIcon', () => ({+ default: () => <span data-testid="topic-status-icon" />,+}));++describe('TopicChatDrawer', () => {+ beforeEach(() => {+ mocks.agentState.useHydrateAgentConfig.mockClear();+ mocks.chatState.replaceMessages.mockClear();+ mocks.taskState.closeTopicDrawer.mockClear();+ mocks.taskState.activeTopicDrawerTopicId = 'topic-1';+ });++ it('hydrates the task assignee agent config for drawer messages', () => {+ render(<TopicChatDrawer />);++ expect(mocks.agentState.useHydrateAgentConfig).toHaveBeenCalledWith(true, 'agt_assignee');+ });+});diff --git a/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/index.tsx b/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/index.tsxindex 6a6906804d3..4b013b341e8 100644--- a/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/index.tsx+++ b/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/index.tsx@@ -1,15 +1,8 @@'use client';-import { type ConversationContext } from '@lobechat/types';-import {- ActionIcon,- copyToClipboard,- Drawer,- type DropdownItem,- DropdownMenu,- Flexbox,- Text,-} from '@lobehub/ui';+import type { ConversationContext } from '@lobechat/types';+import type { DropdownItem } from '@lobehub/ui';+import { ActionIcon, copyToClipboard, Drawer, DropdownMenu, Flexbox, Text } from '@lobehub/ui';import { cssVar } from 'antd-style';import { Copy, MoreHorizontal, Share2 } from 'lucide-react';import dynamic from 'next/dynamic';@@ -21,12 +14,15 @@ import { TaskCardScopeProvider } from '@/features/Conversation/Markdown/plugins/import { useShareModal } from '@/features/ShareModal';import { useGatewayReconnect } from '@/hooks/useGatewayReconnect';import { useOperationState } from '@/hooks/useOperationState';+import { useAgentStore } from '@/store/agent';import { useChatStore } from '@/store/chat';import { messageMapKey } from '@/store/chat/utils/messageMapKey';import { useServerConfigStore } from '@/store/serverConfig';import { serverConfigSelectors } from '@/store/serverConfig/selectors';import { useTaskStore } from '@/store/task';import { taskActivitySelectors, taskDetailSelectors } from '@/store/task/selectors';+import { useUserStore } from '@/store/user';+import { authSelectors } from '@/store/user/selectors';import TopicStatusIcon from '../TopicStatusIcon';@@ -38,6 +34,11 @@ interface TopicChatDrawerBodyProps {}const TopicChatDrawerBody = memo<TopicChatDrawerBodyProps>(({ agentId, topicId }) => {+ const isLogin = useUserStore(authSelectors.isLogin);+ const useHydrateAgentConfig = useAgentStore((s) => s.useHydrateAgentConfig);++ useHydrateAgentConfig(isLogin, agentId);+const context = useMemo<ConversationContext>(() => ({agentId,diff --git a/src/store/agent/slices/agent/action.test.ts b/src/store/agent/slices/agent/action.test.tsindex 73e916d9f74..ac7d697b960 100644--- a/src/store/agent/slices/agent/action.test.ts+++ b/src/store/agent/slices/agent/action.test.ts@@ -464,4 +464,27 @@ describe('AgentSlice Actions', () => {expect(useAgentStore.getState().agentMap['agent-1']).toBeDefined();});});++ describe('useHydrateAgentConfig', () => {+ it('should hydrate agent config without changing activeAgentId', async () => {+ const mockAgentConfig = {+ id: 'agent-1',+ model: 'gpt-4',+ systemRole: 'You are a helpful assistant',+ } as LobeAgentConfig;++ useAgentStore.setState({ activeAgentId: 'agent-current' });+ vi.mocked(agentService.getAgentConfigById).mockResolvedValueOnce(mockAgentConfig as any);++ const { result } = renderHook(() => useAgentStore().useHydrateAgentConfig(true, 'agent-1'), {+ wrapper: withSWR,+ });++ await waitFor(() => expect(result.current.data).toEqual(mockAgentConfig));++ expect(agentService.getAgentConfigById).toHaveBeenCalledWith('agent-1');+ expect(useAgentStore.getState().activeAgentId).toBe('agent-current');+ expect(useAgentStore.getState().agentMap['agent-1']).toBeDefined();+ });+ });});diff --git a/src/store/agent/slices/agent/action.ts b/src/store/agent/slices/agent/action.tsindex ed027ffaec6..119f35b80ed 100644--- a/src/store/agent/slices/agent/action.ts+++ b/src/store/agent/slices/agent/action.ts@@ -290,6 +290,30 @@ export class AgentSliceActionImpl {);};+ useHydrateAgentConfig = (+ isLogin: boolean | undefined,+ agentId: string,+ ): SWRResponse<LobeAgentConfig> => {+ const swrKey =+ isLogin === true && agentId && !isChatGroupSessionId(agentId)+ ? ([FETCH_AGENT_CONFIG_KEY, agentId] as const)+ : null;++ return useClientDataSWRWithSync<LobeAgentConfig>(+ swrKey,+ async () => {+ const data = await agentService.getAgentConfigById(agentId);+ return data as LobeAgentConfig;+ },+ {+ onData: (data) => {+ if (!data) return;+ this.#get().internal_dispatchAgentMap(agentId, data);+ },+ },+ );+ };+useFetchAgentDocuments = (agentId?: string | null): SWRResponse<AgentContextDocument[]> => {return useClientDataSWRWithSync<AgentContextDocument[]>(agentId ? agentDocumentSWRKeys.documents(agentId) : null,