mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-31 08:29:07 +08:00
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
This commit is contained in:
parent
e938e1572c
commit
1c978e0684
@ -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<AssistantsTabProps> = () => {
|
||||
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 (
|
||||
<div className="agents-tab h-full w-full">
|
||||
<span className="mb-2 text-foreground-400 text-xs">{t('common.agent_other')}</span>
|
||||
{agents.map((agent) => (
|
||||
<AgentItem key={agent.id} agent={agent} isActive={false} onDelete={removeAgent} />
|
||||
<AgentItem
|
||||
key={agent.id}
|
||||
agent={agent}
|
||||
isActive={agent.id === activeAgentId}
|
||||
onDelete={removeAgent}
|
||||
onPress={() => setActiveAgentId(agent.id)}
|
||||
/>
|
||||
))}
|
||||
<AgentModal
|
||||
trigger={{
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Avatar, cn, useDisclosure } from '@heroui/react'
|
||||
import { Avatar, Button, cn, useDisclosure } from '@heroui/react'
|
||||
import { loggerService } from '@logger'
|
||||
import { DeleteIcon, EditIcon } from '@renderer/components/Icons'
|
||||
import { AgentModal } from '@renderer/components/Popups/AgentModal'
|
||||
@ -14,10 +14,10 @@ interface AgentItemProps {
|
||||
agent: AgentEntity
|
||||
isActive: boolean
|
||||
onDelete: (agent: AgentEntity) => void
|
||||
onTagClick?: (tag: string) => void
|
||||
onPress: () => void
|
||||
}
|
||||
|
||||
const AgentItem: FC<AgentItemProps> = ({ agent, isActive, onDelete }) => {
|
||||
const AgentItem: FC<AgentItemProps> = ({ agent, isActive, onDelete, onPress }) => {
|
||||
const { t } = useTranslation()
|
||||
const { isOpen, onOpen, onClose } = useDisclosure()
|
||||
// const { agents } = useAgents()
|
||||
@ -26,10 +26,10 @@ const AgentItem: FC<AgentItemProps> = ({ agent, isActive, onDelete }) => {
|
||||
const displayName = agent.name ?? agent.id
|
||||
const avatar = getAgentAvatar(agent.type)
|
||||
return (
|
||||
<>
|
||||
<Button onPress={onPress}>
|
||||
<Avatar className="h-6 w-6" src={avatar} name={displayName} />
|
||||
<span className="text-sm">{displayName}</span>
|
||||
</>
|
||||
</Button>
|
||||
)
|
||||
}, [agent.id, agent.name, agent.type])
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user