From 1c978e0684cc811d458553f983ebf8f09f7afe75 Mon Sep 17 00:00:00 2001 From: icarus Date: Thu, 18 Sep 2025 18:47:37 +0800 Subject: [PATCH] feat(agents): add agent selection functionality - Replace onTagClick with onPress handler in AgentItem - Add active agent state management in AgentsTab - Wrap AgentItem content in Button for better interaction --- .../src/pages/home/Tabs/AgentsTab.tsx | 23 +++++++++++++++++-- .../pages/home/Tabs/components/AgentItem.tsx | 10 ++++---- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/renderer/src/pages/home/Tabs/AgentsTab.tsx b/src/renderer/src/pages/home/Tabs/AgentsTab.tsx index 9f6e7f9ffc..93c95fa02a 100644 --- a/src/renderer/src/pages/home/Tabs/AgentsTab.tsx +++ b/src/renderer/src/pages/home/Tabs/AgentsTab.tsx @@ -2,8 +2,11 @@ import { Button } from '@heroui/react' import { AgentModal } from '@renderer/components/Popups/AgentModal' import { useAgents } from '@renderer/hooks/agents/useAgents' import { useRemoveAgent } from '@renderer/hooks/agents/useRemoveAgent' +import { useRuntime } from '@renderer/hooks/useRuntime' +import { useAppDispatch } from '@renderer/store' +import { setActiveAgentId as setActiveAgentIdAction } from '@renderer/store/runtime' import { Plus } from 'lucide-react' -import { FC } from 'react' +import { FC, useCallback } from 'react' import { useTranslation } from 'react-i18next' import AgentItem from './components/AgentItem' @@ -14,12 +17,28 @@ export const AgentsTab: FC = () => { const { agents } = useAgents() const { removeAgent } = useRemoveAgent() const { t } = useTranslation() + const { chat } = useRuntime() + const { activeAgentId } = chat + const dispatch = useAppDispatch() + + const setActiveAgentId = useCallback( + (id: string) => { + dispatch(setActiveAgentIdAction(id)) + }, + [dispatch] + ) return (
{t('common.agent_other')} {agents.map((agent) => ( - + setActiveAgentId(agent.id)} + /> ))} void - onTagClick?: (tag: string) => void + onPress: () => void } -const AgentItem: FC = ({ agent, isActive, onDelete }) => { +const AgentItem: FC = ({ agent, isActive, onDelete, onPress }) => { const { t } = useTranslation() const { isOpen, onOpen, onClose } = useDisclosure() // const { agents } = useAgents() @@ -26,10 +26,10 @@ const AgentItem: FC = ({ agent, isActive, onDelete }) => { const displayName = agent.name ?? agent.id const avatar = getAgentAvatar(agent.type) return ( - <> + ) }, [agent.id, agent.name, agent.type])