feat: edit agent

This commit is contained in:
kangfenmao 2024-07-02 16:25:15 +08:00
parent 2583f7299a
commit b56fea49ca
2 changed files with 38 additions and 18 deletions

View File

@ -3,6 +3,7 @@ import { useState } from 'react'
import { TopView } from '../TopView' import { TopView } from '../TopView'
import { Box } from '../Layout' import { Box } from '../Layout'
import { Agent } from '@renderer/types' import { Agent } from '@renderer/types'
import TextArea from 'antd/es/input/TextArea'
interface AgentSettingPopupShowParams { interface AgentSettingPopupShowParams {
agent: Agent agent: Agent
@ -32,13 +33,15 @@ const AgentSettingPopupContainer: React.FC<Props> = ({ agent, resolve }) => {
return ( return (
<Modal title={agent.name} open={open} onOk={onOk} onCancel={handleCancel} afterClose={onClose}> <Modal title={agent.name} open={open} onOk={onOk} onCancel={handleCancel} afterClose={onClose}>
<Box mb={8}>Agent name</Box> <Box mb={8}>Agent name</Box>
<Input placeholder="Agent Name" value={name} onChange={(e) => setName(e.target.value)} allowClear autoFocus /> <Input placeholder="Agent Name" value={name} onChange={(e) => setName(e.target.value)} autoFocus />
<Box mb={8}>Description</Box> <Box mt={8} mb={8}>
<Input Description
</Box>
<TextArea
rows={4}
placeholder="Agent Description" placeholder="Agent Description"
value={description} value={description}
onChange={(e) => setDescription(e.target.value)} onChange={(e) => setDescription(e.target.value)}
allowClear
autoFocus autoFocus
/> />
</Modal> </Modal>

View File

@ -3,7 +3,7 @@ import styled from 'styled-components'
import useAgents from '@renderer/hooks/useAgents' import useAgents from '@renderer/hooks/useAgents'
import { Agent } from '@renderer/types' import { Agent } from '@renderer/types'
import { Dropdown, MenuProps } from 'antd' import { Dropdown, MenuProps } from 'antd'
import { EllipsisOutlined } from '@ant-design/icons' import { MoreOutlined } from '@ant-design/icons'
import { last } from 'lodash' import { last } from 'lodash'
import AgentSettingPopup from '@renderer/components/Popups/AgentSettingPopup' import AgentSettingPopup from '@renderer/components/Popups/AgentSettingPopup'
@ -13,7 +13,7 @@ interface Props {
} }
const Agents: FC<Props> = ({ activeAgent, onActive }) => { const Agents: FC<Props> = ({ activeAgent, onActive }) => {
const { agents, removeAgent } = useAgents() const { agents, removeAgent, updateAgent } = useAgents()
const targetAgent = useRef<Agent | null>(null) const targetAgent = useRef<Agent | null>(null)
const onDelete = (agent: Agent) => { const onDelete = (agent: Agent) => {
@ -31,13 +31,10 @@ const Agents: FC<Props> = ({ activeAgent, onActive }) => {
async onClick() { async onClick() {
if (targetAgent.current) { if (targetAgent.current) {
const _agent = await AgentSettingPopup.show({ agent: targetAgent.current }) const _agent = await AgentSettingPopup.show({ agent: targetAgent.current })
updateAgent(_agent)
} }
} }
}, },
{
label: 'Favorite',
key: 'favorite'
},
{ type: 'divider' }, { type: 'divider' },
{ {
label: 'Delete', label: 'Delete',
@ -55,14 +52,15 @@ const Agents: FC<Props> = ({ activeAgent, onActive }) => {
key={agent.id} key={agent.id}
onClick={() => onActive(agent)} onClick={() => onActive(agent)}
className={agent.id === activeAgent?.id ? 'active' : ''}> className={agent.id === activeAgent?.id ? 'active' : ''}>
<Dropdown menu={{ items }} trigger={['click']} placement="bottom" arrow> <Dropdown
<EllipsisOutlined menu={{ items }}
style={{ position: 'absolute', right: 12, top: 12 }} trigger={['click']}
onClick={(e) => { placement="bottom"
e.stopPropagation() arrow
targetAgent.current = agent onOpenChange={() => (targetAgent.current = agent)}>
}} <MenuButton className="menu-button" onClick={(e) => e.stopPropagation()}>
/> <MoreOutlined />
</MenuButton>
</Dropdown> </Dropdown>
<AgentName>{agent.name}</AgentName> <AgentName>{agent.name}</AgentName>
<AgentLastMessage>{agent.description}</AgentLastMessage> <AgentLastMessage>{agent.description}</AgentLastMessage>
@ -98,6 +96,7 @@ const AgentItem = styled.div`
background-color: var(--color-background-soft); background-color: var(--color-background-soft);
.anticon { .anticon {
display: block; display: block;
color: var(--color-text-1);
} }
} }
&.active { &.active {
@ -124,4 +123,22 @@ const AgentLastMessage = styled.div`
height: 20px; height: 20px;
` `
const MenuButton = styled.div`
padding: 5px;
position: absolute;
width: 30px;
height: 30px;
right: 10px;
top: 10px;
font-size: 18px;
border-radius: 50%;
transition: background-color 0.2s ease;
&:hover {
background-color: #ffffff30;
.anticon {
color: white;
}
}
`
export default Agents export default Agents