mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-08 14:29:15 +08:00
refactor(assistant): replace useAgents with useAssistants across components, streamline assistant management and enhance template handling
This commit is contained in:
parent
09fe2aa67b
commit
509632030b
@ -1,5 +1,4 @@
|
|||||||
import { TopView } from '@renderer/components/TopView'
|
import { TopView } from '@renderer/components/TopView'
|
||||||
import { useAgents } from '@renderer/hooks/useAgents'
|
|
||||||
import { useAssistants, useDefaultAssistant } from '@renderer/hooks/useAssistant'
|
import { useAssistants, useDefaultAssistant } from '@renderer/hooks/useAssistant'
|
||||||
import { useSystemAgents } from '@renderer/pages/agents'
|
import { useSystemAgents } from '@renderer/pages/agents'
|
||||||
import { createAssistantFromAgent } from '@renderer/services/AssistantService'
|
import { createAssistantFromAgent } from '@renderer/services/AssistantService'
|
||||||
@ -24,7 +23,7 @@ interface Props {
|
|||||||
const PopupContainer: React.FC<Props> = ({ resolve }) => {
|
const PopupContainer: React.FC<Props> = ({ resolve }) => {
|
||||||
const [open, setOpen] = useState(true)
|
const [open, setOpen] = useState(true)
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { agents: userAgents } = useAgents()
|
const { assistants: userAgents } = useAssistants()
|
||||||
const [searchText, setSearchText] = useState('')
|
const [searchText, setSearchText] = useState('')
|
||||||
const { defaultAssistant } = useDefaultAssistant()
|
const { defaultAssistant } = useDefaultAssistant()
|
||||||
const { assistants, addAssistant } = useAssistants()
|
const { assistants, addAssistant } = useAssistants()
|
||||||
|
|||||||
@ -1,28 +0,0 @@
|
|||||||
import { useAppDispatch, useAppSelector } from '@renderer/store'
|
|
||||||
import { addAgent, removeAgent, updateAgent, updateAgents, updateAgentSettings } from '@renderer/store/agents'
|
|
||||||
import { Agent, AssistantSettings } from '@renderer/types'
|
|
||||||
|
|
||||||
export function useAgents() {
|
|
||||||
const agents = useAppSelector((state) => state.agents.agents)
|
|
||||||
const dispatch = useAppDispatch()
|
|
||||||
|
|
||||||
return {
|
|
||||||
agents,
|
|
||||||
updateAgents: (agents: Agent[]) => dispatch(updateAgents(agents)),
|
|
||||||
addAgent: (agent: Agent) => dispatch(addAgent(agent)),
|
|
||||||
removeAgent: (id: string) => dispatch(removeAgent({ id }))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useAgent(id: string) {
|
|
||||||
const agent = useAppSelector((state) => state.agents.agents.find((a) => a.id === id) as Agent)
|
|
||||||
const dispatch = useAppDispatch()
|
|
||||||
|
|
||||||
return {
|
|
||||||
agent,
|
|
||||||
updateAgent: (agent: Agent) => dispatch(updateAgent(agent)),
|
|
||||||
updateAgentSettings: (settings: Partial<AssistantSettings>) => {
|
|
||||||
dispatch(updateAgentSettings({ assistantId: agent.id, settings }))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -2,7 +2,10 @@ import { db } from '@renderer/databases'
|
|||||||
import { useAppDispatch, useAppSelector } from '@renderer/store'
|
import { useAppDispatch, useAppSelector } from '@renderer/store'
|
||||||
import {
|
import {
|
||||||
addAssistant,
|
addAssistant,
|
||||||
|
createAssistantFromTemplate,
|
||||||
removeAssistant,
|
removeAssistant,
|
||||||
|
selectActiveAssistants,
|
||||||
|
selectTemplates,
|
||||||
setModel,
|
setModel,
|
||||||
updateAssistant,
|
updateAssistant,
|
||||||
updateAssistants,
|
updateAssistants,
|
||||||
@ -15,20 +18,32 @@ import { Assistant, AssistantSettings, Model, Topic } from '@renderer/types'
|
|||||||
import { useCallback, useMemo } from 'react'
|
import { useCallback, useMemo } from 'react'
|
||||||
|
|
||||||
export function useAssistants() {
|
export function useAssistants() {
|
||||||
const { assistants } = useAppSelector((state) => state.assistants)
|
const assistants = useAppSelector(selectActiveAssistants)
|
||||||
|
const templates = useAppSelector(selectTemplates)
|
||||||
const dispatch = useAppDispatch()
|
const dispatch = useAppDispatch()
|
||||||
|
|
||||||
|
const getAssistantById = useCallback((id: string) => assistants.find((a) => a.id === id), [assistants])
|
||||||
|
|
||||||
return {
|
return {
|
||||||
assistants,
|
assistants,
|
||||||
|
templates,
|
||||||
|
getAssistantById,
|
||||||
updateAssistants: (assistants: Assistant[]) => dispatch(updateAssistants(assistants)),
|
updateAssistants: (assistants: Assistant[]) => dispatch(updateAssistants(assistants)),
|
||||||
addAssistant: (assistant: Assistant) => {
|
addAssistant: (assistant: Assistant) => {
|
||||||
dispatch(addAssistant(assistant))
|
dispatch(addAssistant({ ...assistant, isTemplate: false }))
|
||||||
dispatch(topicsActions.addDefaultTopic({ assistantId: assistant.id }))
|
dispatch(topicsActions.addDefaultTopic({ assistantId: assistant.id }))
|
||||||
},
|
},
|
||||||
|
addTemplate: (template: Assistant) => {
|
||||||
|
dispatch(addAssistant({ ...template, isTemplate: true }))
|
||||||
|
},
|
||||||
removeAssistant: (id: string) => {
|
removeAssistant: (id: string) => {
|
||||||
dispatch(removeAssistant({ id }))
|
dispatch(removeAssistant({ id }))
|
||||||
// Remove all topics for this assistant
|
// Remove all topics for this assistant
|
||||||
dispatch(topicsActions.removeAllTopics({ assistantId: id }))
|
dispatch(topicsActions.removeAllTopics({ assistantId: id }))
|
||||||
|
},
|
||||||
|
createAssistantFromTemplate: (templateId: string, assistantId: string) => {
|
||||||
|
dispatch(createAssistantFromTemplate({ templateId, assistantId }))
|
||||||
|
dispatch(topicsActions.addDefaultTopic({ assistantId }))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,7 +26,6 @@ import { useEffect, useState } from 'react'
|
|||||||
import { useDispatch, useSelector } from 'react-redux'
|
import { useDispatch, useSelector } from 'react-redux'
|
||||||
import { v4 as uuidv4 } from 'uuid'
|
import { v4 as uuidv4 } from 'uuid'
|
||||||
|
|
||||||
import { useAgents } from './useAgents'
|
|
||||||
import { useAssistants } from './useAssistant'
|
import { useAssistants } from './useAssistant'
|
||||||
|
|
||||||
export const useKnowledge = (baseId: string) => {
|
export const useKnowledge = (baseId: string) => {
|
||||||
@ -319,7 +318,6 @@ export const useKnowledgeBases = () => {
|
|||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
const bases = useSelector((state: RootState) => state.knowledge.bases)
|
const bases = useSelector((state: RootState) => state.knowledge.bases)
|
||||||
const { assistants, updateAssistants } = useAssistants()
|
const { assistants, updateAssistants } = useAssistants()
|
||||||
const { agents, updateAgents } = useAgents()
|
|
||||||
|
|
||||||
const addKnowledgeBase = (base: KnowledgeBase) => {
|
const addKnowledgeBase = (base: KnowledgeBase) => {
|
||||||
dispatch(addBase(base))
|
dispatch(addBase(base))
|
||||||
@ -343,19 +341,7 @@ export const useKnowledgeBases = () => {
|
|||||||
return assistant
|
return assistant
|
||||||
})
|
})
|
||||||
|
|
||||||
// remove agent knowledge_base
|
|
||||||
const _agents = agents.map((agent) => {
|
|
||||||
if (agent.knowledge_bases?.find((kb) => kb.id === baseId)) {
|
|
||||||
return {
|
|
||||||
...agent,
|
|
||||||
knowledge_bases: agent.knowledge_bases.filter((kb) => kb.id !== baseId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return agent
|
|
||||||
})
|
|
||||||
|
|
||||||
updateAssistants(_assistants)
|
updateAssistants(_assistants)
|
||||||
updateAgents(_agents)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateKnowledgeBases = (bases: KnowledgeBase[]) => {
|
const updateKnowledgeBases = (bases: KnowledgeBase[]) => {
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import { NavbarCenter, NavbarMain } from '@renderer/components/app/Navbar'
|
|||||||
import CustomTag from '@renderer/components/CustomTag'
|
import CustomTag from '@renderer/components/CustomTag'
|
||||||
import ListItem from '@renderer/components/ListItem'
|
import ListItem from '@renderer/components/ListItem'
|
||||||
import Scrollbar from '@renderer/components/Scrollbar'
|
import Scrollbar from '@renderer/components/Scrollbar'
|
||||||
import { useAgents } from '@renderer/hooks/useAgents'
|
import { useAssistants } from '@renderer/hooks/useAssistant'
|
||||||
import { createAssistantFromAgent } from '@renderer/services/AssistantService'
|
import { createAssistantFromAgent } from '@renderer/services/AssistantService'
|
||||||
import { Agent } from '@renderer/types'
|
import { Agent } from '@renderer/types'
|
||||||
import { uuid } from '@renderer/utils'
|
import { uuid } from '@renderer/utils'
|
||||||
@ -28,7 +28,7 @@ const AgentsPage: FC = () => {
|
|||||||
const [activeGroup, setActiveGroup] = useState('我的')
|
const [activeGroup, setActiveGroup] = useState('我的')
|
||||||
const [agentGroups, setAgentGroups] = useState<Record<string, Agent[]>>({})
|
const [agentGroups, setAgentGroups] = useState<Record<string, Agent[]>>({})
|
||||||
const systemAgents = useSystemAgents()
|
const systemAgents = useSystemAgents()
|
||||||
const { agents: userAgents } = useAgents()
|
const { templates: userAgents } = useAssistants()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const systemAgentsGroupList = groupByCategories(systemAgents)
|
const systemAgentsGroupList = groupByCategories(systemAgents)
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import { CheckOutlined, LoadingOutlined, RollbackOutlined, ThunderboltOutlined }
|
|||||||
import EmojiPicker from '@renderer/components/EmojiPicker'
|
import EmojiPicker from '@renderer/components/EmojiPicker'
|
||||||
import { TopView } from '@renderer/components/TopView'
|
import { TopView } from '@renderer/components/TopView'
|
||||||
import { AGENT_PROMPT } from '@renderer/config/prompts'
|
import { AGENT_PROMPT } from '@renderer/config/prompts'
|
||||||
import { useAgents } from '@renderer/hooks/useAgents'
|
import { useAssistants } from '@renderer/hooks/useAssistant'
|
||||||
import { useSidebarIconShow } from '@renderer/hooks/useSidebarIcon'
|
import { useSidebarIconShow } from '@renderer/hooks/useSidebarIcon'
|
||||||
import { fetchGenerate } from '@renderer/services/ApiService'
|
import { fetchGenerate } from '@renderer/services/ApiService'
|
||||||
import { getDefaultModel } from '@renderer/services/AssistantService'
|
import { getDefaultModel } from '@renderer/services/AssistantService'
|
||||||
@ -34,7 +34,7 @@ const PopupContainer: React.FC<Props> = ({ resolve }) => {
|
|||||||
const [open, setOpen] = useState(true)
|
const [open, setOpen] = useState(true)
|
||||||
const [form] = Form.useForm()
|
const [form] = Form.useForm()
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { addAgent } = useAgents()
|
const { addTemplate } = useAssistants()
|
||||||
const formRef = useRef<FormInstance>(null)
|
const formRef = useRef<FormInstance>(null)
|
||||||
const [emoji, setEmoji] = useState('')
|
const [emoji, setEmoji] = useState('')
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
@ -82,12 +82,12 @@ const PopupContainer: React.FC<Props> = ({ resolve }) => {
|
|||||||
emoji: _emoji,
|
emoji: _emoji,
|
||||||
prompt: values.prompt,
|
prompt: values.prompt,
|
||||||
defaultModel: getDefaultModel(),
|
defaultModel: getDefaultModel(),
|
||||||
type: 'agent',
|
|
||||||
topics: [],
|
topics: [],
|
||||||
messages: []
|
messages: [],
|
||||||
|
isTemplate: true
|
||||||
}
|
}
|
||||||
|
|
||||||
addAgent(_agent)
|
addTemplate(_agent)
|
||||||
resolve(_agent)
|
resolve(_agent)
|
||||||
setOpen(false)
|
setOpen(false)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import {
|
|||||||
SortAscendingOutlined
|
SortAscendingOutlined
|
||||||
} from '@ant-design/icons'
|
} from '@ant-design/icons'
|
||||||
import CustomTag from '@renderer/components/CustomTag'
|
import CustomTag from '@renderer/components/CustomTag'
|
||||||
import { useAgents } from '@renderer/hooks/useAgents'
|
import { useAssistants } from '@renderer/hooks/useAssistant'
|
||||||
import AssistantSettingsPopup from '@renderer/pages/settings/AssistantSettings'
|
import AssistantSettingsPopup from '@renderer/pages/settings/AssistantSettings'
|
||||||
import { createAssistantFromAgent } from '@renderer/services/AssistantService'
|
import { createAssistantFromAgent } from '@renderer/services/AssistantService'
|
||||||
import type { Agent } from '@renderer/types'
|
import type { Agent } from '@renderer/types'
|
||||||
@ -27,7 +27,7 @@ interface Props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const AgentCard: FC<Props> = ({ agent, onClick, activegroup, getLocalizedGroupName }) => {
|
const AgentCard: FC<Props> = ({ agent, onClick, activegroup, getLocalizedGroupName }) => {
|
||||||
const { removeAgent } = useAgents()
|
const { removeAssistant: removeAgent } = useAssistants()
|
||||||
const [isVisible, setIsVisible] = useState(false)
|
const [isVisible, setIsVisible] = useState(false)
|
||||||
const cardRef = useRef<HTMLDivElement>(null)
|
const cardRef = useRef<HTMLDivElement>(null)
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { TopView } from '@renderer/components/TopView'
|
import { TopView } from '@renderer/components/TopView'
|
||||||
import { useAgents } from '@renderer/hooks/useAgents'
|
import { useAssistants } from '@renderer/hooks/useAssistant'
|
||||||
import { getDefaultModel } from '@renderer/services/AssistantService'
|
import { getDefaultModel } from '@renderer/services/AssistantService'
|
||||||
import { EVENT_NAMES, EventEmitter } from '@renderer/services/EventService'
|
import { EVENT_NAMES, EventEmitter } from '@renderer/services/EventService'
|
||||||
import { Agent } from '@renderer/types'
|
import { Agent } from '@renderer/types'
|
||||||
@ -16,7 +16,7 @@ const PopupContainer: React.FC<Props> = ({ resolve }) => {
|
|||||||
const [open, setOpen] = useState(true)
|
const [open, setOpen] = useState(true)
|
||||||
const [form] = Form.useForm()
|
const [form] = Form.useForm()
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { addAgent } = useAgents()
|
const { addTemplate: addAgent } = useAssistants()
|
||||||
const [importType, setImportType] = useState<'url' | 'file'>('url')
|
const [importType, setImportType] = useState<'url' | 'file'>('url')
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import { MenuOutlined } from '@ant-design/icons'
|
|||||||
import DragableList from '@renderer/components/DragableList'
|
import DragableList from '@renderer/components/DragableList'
|
||||||
import { Box, HStack } from '@renderer/components/Layout'
|
import { Box, HStack } from '@renderer/components/Layout'
|
||||||
import { TopView } from '@renderer/components/TopView'
|
import { TopView } from '@renderer/components/TopView'
|
||||||
import { useAgents } from '@renderer/hooks/useAgents'
|
import { useAssistants } from '@renderer/hooks/useAssistant'
|
||||||
import { Empty, Modal } from 'antd'
|
import { Empty, Modal } from 'antd'
|
||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
@ -11,7 +11,8 @@ import styled from 'styled-components'
|
|||||||
const PopupContainer: React.FC = () => {
|
const PopupContainer: React.FC = () => {
|
||||||
const [open, setOpen] = useState(true)
|
const [open, setOpen] = useState(true)
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { agents, updateAgents } = useAgents()
|
const { assistants, updateAssistants: updateAgents } = useAssistants()
|
||||||
|
const agents = assistants.filter((a) => a.isTemplate)
|
||||||
|
|
||||||
const onOk = () => {
|
const onOk = () => {
|
||||||
setOpen(false)
|
setOpen(false)
|
||||||
|
|||||||
@ -2,7 +2,6 @@ import EmojiAvatar from '@renderer/components/Avatar/EmojiAvatar'
|
|||||||
import UserPopup from '@renderer/components/Popups/UserPopup'
|
import UserPopup from '@renderer/components/Popups/UserPopup'
|
||||||
import { AppLogo, UserAvatar } from '@renderer/config/env'
|
import { AppLogo, UserAvatar } from '@renderer/config/env'
|
||||||
import { useTheme } from '@renderer/context/ThemeProvider'
|
import { useTheme } from '@renderer/context/ThemeProvider'
|
||||||
import { useAssistants } from '@renderer/hooks/useAssistant'
|
|
||||||
import useAvatar from '@renderer/hooks/useAvatar'
|
import useAvatar from '@renderer/hooks/useAvatar'
|
||||||
import { useChat } from '@renderer/hooks/useChat'
|
import { useChat } from '@renderer/hooks/useChat'
|
||||||
import { useMinappPopup } from '@renderer/hooks/useMinappPopup'
|
import { useMinappPopup } from '@renderer/hooks/useMinappPopup'
|
||||||
@ -11,6 +10,7 @@ import { useShortcut } from '@renderer/hooks/useShortcuts'
|
|||||||
import { useShowAssistants } from '@renderer/hooks/useStore'
|
import { useShowAssistants } from '@renderer/hooks/useStore'
|
||||||
import i18n from '@renderer/i18n'
|
import i18n from '@renderer/i18n'
|
||||||
import AssistantItem from '@renderer/pages/home/Tabs/components/AssistantItem'
|
import AssistantItem from '@renderer/pages/home/Tabs/components/AssistantItem'
|
||||||
|
import { getAssistantById } from '@renderer/services/AssistantService'
|
||||||
import { EVENT_NAMES, EventEmitter } from '@renderer/services/EventService'
|
import { EVENT_NAMES, EventEmitter } from '@renderer/services/EventService'
|
||||||
import { ThemeMode } from '@renderer/types'
|
import { ThemeMode } from '@renderer/types'
|
||||||
import { isEmoji } from '@renderer/utils'
|
import { isEmoji } from '@renderer/utils'
|
||||||
@ -57,7 +57,6 @@ import PinnedApps from './PinnedApps'
|
|||||||
type Tab = 'assistants' | 'topic'
|
type Tab = 'assistants' | 'topic'
|
||||||
|
|
||||||
const MainSidebar: FC = () => {
|
const MainSidebar: FC = () => {
|
||||||
const { assistants } = useAssistants()
|
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const [tab, setTab] = useState<Tab>('assistants')
|
const [tab, setTab] = useState<Tab>('assistants')
|
||||||
const avatar = useAvatar()
|
const avatar = useAvatar()
|
||||||
@ -92,7 +91,7 @@ const MainSidebar: FC = () => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const unsubscribes = [
|
const unsubscribes = [
|
||||||
EventEmitter.on(EVENT_NAMES.SWITCH_ASSISTANT, (assistantId: string) => {
|
EventEmitter.on(EVENT_NAMES.SWITCH_ASSISTANT, (assistantId: string) => {
|
||||||
const newAssistant = assistants.find((a) => a.id === assistantId)
|
const newAssistant = getAssistantById(assistantId)
|
||||||
if (newAssistant) {
|
if (newAssistant) {
|
||||||
setActiveAssistant(newAssistant)
|
setActiveAssistant(newAssistant)
|
||||||
}
|
}
|
||||||
@ -104,7 +103,7 @@ const MainSidebar: FC = () => {
|
|||||||
]
|
]
|
||||||
|
|
||||||
return () => unsubscribes.forEach((unsubscribe) => unsubscribe())
|
return () => unsubscribes.forEach((unsubscribe) => unsubscribe())
|
||||||
}, [assistants, setActiveAssistant, tab])
|
}, [setActiveAssistant, tab])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const canMinimize = !showAssistants && !showTopics
|
const canMinimize = !showAssistants && !showTopics
|
||||||
@ -204,7 +203,6 @@ const MainSidebar: FC = () => {
|
|||||||
sortBy="list"
|
sortBy="list"
|
||||||
onSwitch={() => {}}
|
onSwitch={() => {}}
|
||||||
onDelete={() => {}}
|
onDelete={() => {}}
|
||||||
addAgent={() => {}}
|
|
||||||
addAssistant={() => {}}
|
addAssistant={() => {}}
|
||||||
onCreateDefaultAssistant={() => {}}
|
onCreateDefaultAssistant={() => {}}
|
||||||
handleSortByChange={() => {}}
|
handleSortByChange={() => {}}
|
||||||
|
|||||||
@ -2,7 +2,6 @@ import { DownOutlined, PlusOutlined, RightOutlined } from '@ant-design/icons'
|
|||||||
import { Draggable, Droppable, DropResult } from '@hello-pangea/dnd'
|
import { Draggable, Droppable, DropResult } from '@hello-pangea/dnd'
|
||||||
import DragableList from '@renderer/components/DragableList'
|
import DragableList from '@renderer/components/DragableList'
|
||||||
import Scrollbar from '@renderer/components/Scrollbar'
|
import Scrollbar from '@renderer/components/Scrollbar'
|
||||||
import { useAgents } from '@renderer/hooks/useAgents'
|
|
||||||
import { useAssistants } from '@renderer/hooks/useAssistant'
|
import { useAssistants } from '@renderer/hooks/useAssistant'
|
||||||
import { useAssistantsTabSortType } from '@renderer/hooks/useStore'
|
import { useAssistantsTabSortType } from '@renderer/hooks/useStore'
|
||||||
import { useTags } from '@renderer/hooks/useTags'
|
import { useTags } from '@renderer/hooks/useTags'
|
||||||
@ -29,7 +28,6 @@ const Assistants: FC<AssistantsTabProps> = ({
|
|||||||
const { assistants, removeAssistant, addAssistant, updateAssistants } = useAssistants()
|
const { assistants, removeAssistant, addAssistant, updateAssistants } = useAssistants()
|
||||||
const [dragging, setDragging] = useState(false)
|
const [dragging, setDragging] = useState(false)
|
||||||
const [collapsedTags, setCollapsedTags] = useState<Record<string, boolean>>({})
|
const [collapsedTags, setCollapsedTags] = useState<Record<string, boolean>>({})
|
||||||
const { addAgent } = useAgents()
|
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { getGroupedAssistants, allTags, updateTagsOrder } = useTags()
|
const { getGroupedAssistants, allTags, updateTagsOrder } = useTags()
|
||||||
const { assistantsTabSortType = 'list', setAssistantsTabSortType } = useAssistantsTabSortType()
|
const { assistantsTabSortType = 'list', setAssistantsTabSortType } = useAssistantsTabSortType()
|
||||||
@ -206,7 +204,6 @@ const Assistants: FC<AssistantsTabProps> = ({
|
|||||||
isActive={assistant?.id === activeAssistant.id}
|
isActive={assistant?.id === activeAssistant.id}
|
||||||
onSwitch={setActiveAssistant}
|
onSwitch={setActiveAssistant}
|
||||||
onDelete={onDelete}
|
onDelete={onDelete}
|
||||||
addAgent={addAgent}
|
|
||||||
addAssistant={addAssistant}
|
addAssistant={addAssistant}
|
||||||
onCreateDefaultAssistant={() => {}}
|
onCreateDefaultAssistant={() => {}}
|
||||||
/>
|
/>
|
||||||
@ -249,7 +246,6 @@ const Assistants: FC<AssistantsTabProps> = ({
|
|||||||
sortBy={assistantsTabSortType}
|
sortBy={assistantsTabSortType}
|
||||||
onSwitch={setActiveAssistant}
|
onSwitch={setActiveAssistant}
|
||||||
onDelete={onDelete}
|
onDelete={onDelete}
|
||||||
addAgent={addAgent}
|
|
||||||
addAssistant={addAssistant}
|
addAssistant={addAssistant}
|
||||||
onCreateDefaultAssistant={onCreateDefaultAssistant}
|
onCreateDefaultAssistant={onCreateDefaultAssistant}
|
||||||
handleSortByChange={handleSortByChange}
|
handleSortByChange={handleSortByChange}
|
||||||
|
|||||||
@ -39,7 +39,6 @@ interface AssistantItemProps {
|
|||||||
onSwitch: (assistant: Assistant) => void
|
onSwitch: (assistant: Assistant) => void
|
||||||
onDelete: (assistant: Assistant) => void
|
onDelete: (assistant: Assistant) => void
|
||||||
onCreateDefaultAssistant: () => void
|
onCreateDefaultAssistant: () => void
|
||||||
addAgent: (agent: any) => void
|
|
||||||
addAssistant: (assistant: Assistant) => void
|
addAssistant: (assistant: Assistant) => void
|
||||||
onTagClick?: (tag: string) => void
|
onTagClick?: (tag: string) => void
|
||||||
handleSortByChange?: (sortType: AssistantsSortType) => void
|
handleSortByChange?: (sortType: AssistantsSortType) => void
|
||||||
@ -52,7 +51,6 @@ const AssistantItem: FC<AssistantItemProps> = ({
|
|||||||
sortBy,
|
sortBy,
|
||||||
onSwitch,
|
onSwitch,
|
||||||
onDelete,
|
onDelete,
|
||||||
addAgent,
|
|
||||||
addAssistant,
|
addAssistant,
|
||||||
handleSortByChange,
|
handleSortByChange,
|
||||||
singleLine = false
|
singleLine = false
|
||||||
@ -95,7 +93,6 @@ const AssistantItem: FC<AssistantItemProps> = ({
|
|||||||
allTags,
|
allTags,
|
||||||
assistants,
|
assistants,
|
||||||
updateAssistants,
|
updateAssistants,
|
||||||
addAgent,
|
|
||||||
addAssistant,
|
addAssistant,
|
||||||
onSwitch,
|
onSwitch,
|
||||||
onDelete,
|
onDelete,
|
||||||
@ -112,7 +109,6 @@ const AssistantItem: FC<AssistantItemProps> = ({
|
|||||||
allTags,
|
allTags,
|
||||||
assistants,
|
assistants,
|
||||||
updateAssistants,
|
updateAssistants,
|
||||||
addAgent,
|
|
||||||
addAssistant,
|
addAssistant,
|
||||||
onSwitch,
|
onSwitch,
|
||||||
onDelete,
|
onDelete,
|
||||||
@ -280,7 +276,6 @@ function getMenuItems({
|
|||||||
allTags,
|
allTags,
|
||||||
assistants,
|
assistants,
|
||||||
updateAssistants,
|
updateAssistants,
|
||||||
addAgent,
|
|
||||||
addAssistant,
|
addAssistant,
|
||||||
onSwitch,
|
onSwitch,
|
||||||
onDelete,
|
onDelete,
|
||||||
@ -329,8 +324,8 @@ function getMenuItems({
|
|||||||
onClick: async () => {
|
onClick: async () => {
|
||||||
const agent = omit(assistant, ['model', 'emoji'])
|
const agent = omit(assistant, ['model', 'emoji'])
|
||||||
agent.id = uuid()
|
agent.id = uuid()
|
||||||
agent.type = 'agent'
|
agent.isTemplate = true
|
||||||
addAgent(agent)
|
addAssistant(agent)
|
||||||
window.message.success({
|
window.message.success({
|
||||||
content: t('assistants.save.success'),
|
content: t('assistants.save.success'),
|
||||||
key: 'save-to-agent'
|
key: 'save-to-agent'
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
import { HStack } from '@renderer/components/Layout'
|
import { HStack } from '@renderer/components/Layout'
|
||||||
import { TopView } from '@renderer/components/TopView'
|
import { TopView } from '@renderer/components/TopView'
|
||||||
import { useAgent } from '@renderer/hooks/useAgents'
|
|
||||||
import { useAssistant } from '@renderer/hooks/useAssistant'
|
import { useAssistant } from '@renderer/hooks/useAssistant'
|
||||||
import { useSidebarIconShow } from '@renderer/hooks/useSidebarIcon'
|
import { useSidebarIconShow } from '@renderer/hooks/useSidebarIcon'
|
||||||
import { Assistant } from '@renderer/types'
|
import { Assistant } from '@renderer/types'
|
||||||
@ -31,13 +30,7 @@ const AssistantSettingPopupContainer: React.FC<Props> = ({ resolve, tab, ...prop
|
|||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const [menu, setMenu] = useState<AssistantSettingPopupTab>(tab || 'prompt')
|
const [menu, setMenu] = useState<AssistantSettingPopupTab>(tab || 'prompt')
|
||||||
|
|
||||||
const _useAssistant = useAssistant(props.assistant.id)
|
const { updateAssistant, updateAssistantSettings } = useAssistant(props.assistant.id)
|
||||||
const _useAgent = useAgent(props.assistant.id)
|
|
||||||
const isAgent = props.assistant.type === 'agent'
|
|
||||||
|
|
||||||
const assistant = isAgent ? _useAgent.agent : _useAssistant.assistant
|
|
||||||
const updateAssistant = isAgent ? _useAgent.updateAgent : _useAssistant.updateAssistant
|
|
||||||
const updateAssistantSettings = isAgent ? _useAgent.updateAgentSettings : _useAssistant.updateAssistantSettings
|
|
||||||
|
|
||||||
const showKnowledgeIcon = useSidebarIconShow('knowledge')
|
const showKnowledgeIcon = useSidebarIconShow('knowledge')
|
||||||
|
|
||||||
@ -50,7 +43,7 @@ const AssistantSettingPopupContainer: React.FC<Props> = ({ resolve, tab, ...prop
|
|||||||
}
|
}
|
||||||
|
|
||||||
const afterClose = () => {
|
const afterClose = () => {
|
||||||
resolve(assistant)
|
resolve(props.assistant)
|
||||||
}
|
}
|
||||||
|
|
||||||
const items = [
|
const items = [
|
||||||
@ -84,7 +77,7 @@ const AssistantSettingPopupContainer: React.FC<Props> = ({ resolve, tab, ...prop
|
|||||||
onCancel={onCancel}
|
onCancel={onCancel}
|
||||||
afterClose={afterClose}
|
afterClose={afterClose}
|
||||||
footer={null}
|
footer={null}
|
||||||
title={assistant.name}
|
title={props.assistant.name}
|
||||||
transitionName="animation-move-down"
|
transitionName="animation-move-down"
|
||||||
styles={{
|
styles={{
|
||||||
content: {
|
content: {
|
||||||
@ -112,34 +105,34 @@ const AssistantSettingPopupContainer: React.FC<Props> = ({ resolve, tab, ...prop
|
|||||||
<Settings>
|
<Settings>
|
||||||
{menu === 'prompt' && (
|
{menu === 'prompt' && (
|
||||||
<AssistantPromptSettings
|
<AssistantPromptSettings
|
||||||
assistant={assistant}
|
assistant={props.assistant}
|
||||||
updateAssistant={updateAssistant}
|
updateAssistant={updateAssistant}
|
||||||
updateAssistantSettings={updateAssistantSettings}
|
updateAssistantSettings={updateAssistantSettings}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{menu === 'model' && (
|
{menu === 'model' && (
|
||||||
<AssistantModelSettings
|
<AssistantModelSettings
|
||||||
assistant={assistant}
|
assistant={props.assistant}
|
||||||
updateAssistant={updateAssistant}
|
updateAssistant={updateAssistant}
|
||||||
updateAssistantSettings={updateAssistantSettings}
|
updateAssistantSettings={updateAssistantSettings}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{menu === 'knowledge_base' && showKnowledgeIcon && (
|
{menu === 'knowledge_base' && showKnowledgeIcon && (
|
||||||
<AssistantKnowledgeBaseSettings
|
<AssistantKnowledgeBaseSettings
|
||||||
assistant={assistant}
|
assistant={props.assistant}
|
||||||
updateAssistant={updateAssistant}
|
updateAssistant={updateAssistant}
|
||||||
updateAssistantSettings={updateAssistantSettings}
|
updateAssistantSettings={updateAssistantSettings}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{menu === 'mcp' && (
|
{menu === 'mcp' && (
|
||||||
<AssistantMCPSettings
|
<AssistantMCPSettings
|
||||||
assistant={assistant}
|
assistant={props.assistant}
|
||||||
updateAssistant={updateAssistant}
|
updateAssistant={updateAssistant}
|
||||||
updateAssistantSettings={updateAssistantSettings}
|
updateAssistantSettings={updateAssistantSettings}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{menu === 'regular_phrases' && (
|
{menu === 'regular_phrases' && (
|
||||||
<AssistantRegularPromptsSettings assistant={assistant} updateAssistant={updateAssistant} />
|
<AssistantRegularPromptsSettings assistant={props.assistant} updateAssistant={updateAssistant} />
|
||||||
)}
|
)}
|
||||||
</Settings>
|
</Settings>
|
||||||
</HStack>
|
</HStack>
|
||||||
|
|||||||
@ -14,8 +14,8 @@ export function getDefaultAssistant(): Assistant {
|
|||||||
prompt: '',
|
prompt: '',
|
||||||
topics: [],
|
topics: [],
|
||||||
messages: [],
|
messages: [],
|
||||||
type: 'assistant',
|
regularPhrases: [],
|
||||||
regularPhrases: [] // Added regularPhrases
|
isTemplate: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,8 +126,8 @@ export async function createAssistantFromAgent(agent: Agent) {
|
|||||||
name: agent.name,
|
name: agent.name,
|
||||||
emoji: agent.emoji,
|
emoji: agent.emoji,
|
||||||
model: agent.defaultModel,
|
model: agent.defaultModel,
|
||||||
type: 'assistant',
|
isTemplate: false,
|
||||||
regularPhrases: agent.regularPhrases || [] // Ensured regularPhrases
|
regularPhrases: agent.regularPhrases || []
|
||||||
}
|
}
|
||||||
|
|
||||||
store.dispatch(addAssistant(assistant))
|
store.dispatch(addAssistant(assistant))
|
||||||
@ -140,3 +140,17 @@ export async function createAssistantFromAgent(agent: Agent) {
|
|||||||
|
|
||||||
return assistant
|
return assistant
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function createTemplate(templateData: Partial<Assistant>): Assistant {
|
||||||
|
return {
|
||||||
|
id: uuid(),
|
||||||
|
name: templateData.name || 'New Template',
|
||||||
|
prompt: templateData.prompt || '',
|
||||||
|
topics: [],
|
||||||
|
messages: [],
|
||||||
|
type: 'assistant',
|
||||||
|
isTemplate: true,
|
||||||
|
regularPhrases: [],
|
||||||
|
...templateData
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,8 +1,13 @@
|
|||||||
import { createSlice, PayloadAction } from '@reduxjs/toolkit'
|
import { createSlice } from '@reduxjs/toolkit'
|
||||||
import { DEFAULT_CONTEXTCOUNT, DEFAULT_TEMPERATURE } from '@renderer/config/constant'
|
import { Agent } from '@renderer/types'
|
||||||
import { Agent, AssistantSettings } from '@renderer/types'
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated use assistants instead
|
||||||
|
*/
|
||||||
export interface AgentsState {
|
export interface AgentsState {
|
||||||
|
/**
|
||||||
|
* @deprecated use assistants instead
|
||||||
|
*/
|
||||||
agents: Agent[]
|
agents: Agent[]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -13,44 +18,7 @@ const initialState: AgentsState = {
|
|||||||
const assistantsSlice = createSlice({
|
const assistantsSlice = createSlice({
|
||||||
name: 'agents',
|
name: 'agents',
|
||||||
initialState,
|
initialState,
|
||||||
reducers: {
|
reducers: {}
|
||||||
updateAgents: (state, action: PayloadAction<Agent[]>) => {
|
|
||||||
state.agents = action.payload
|
|
||||||
},
|
|
||||||
addAgent: (state, action: PayloadAction<Agent>) => {
|
|
||||||
state.agents.push(action.payload)
|
|
||||||
},
|
|
||||||
removeAgent: (state, action: PayloadAction<{ id: string }>) => {
|
|
||||||
state.agents = state.agents.filter((c) => c.id !== action.payload.id)
|
|
||||||
},
|
|
||||||
updateAgent: (state, action: PayloadAction<Agent>) => {
|
|
||||||
state.agents = state.agents.map((c) => (c.id === action.payload.id ? action.payload : c))
|
|
||||||
},
|
|
||||||
updateAgentSettings: (
|
|
||||||
state,
|
|
||||||
action: PayloadAction<{ assistantId: string; settings: Partial<AssistantSettings> }>
|
|
||||||
) => {
|
|
||||||
for (const agent of state.agents) {
|
|
||||||
const settings = action.payload.settings
|
|
||||||
if (agent.id === action.payload.assistantId) {
|
|
||||||
for (const key in settings) {
|
|
||||||
if (!agent.settings) {
|
|
||||||
agent.settings = {
|
|
||||||
temperature: DEFAULT_TEMPERATURE,
|
|
||||||
contextCount: DEFAULT_CONTEXTCOUNT,
|
|
||||||
enableMaxTokens: false,
|
|
||||||
maxTokens: 0,
|
|
||||||
streamOutput: true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
agent.settings[key] = settings[key]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
export const { updateAgents, addAgent, removeAgent, updateAgent, updateAgentSettings } = assistantsSlice.actions
|
|
||||||
|
|
||||||
export default assistantsSlice.reducer
|
export default assistantsSlice.reducer
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import { createSlice, PayloadAction } from '@reduxjs/toolkit'
|
import { createSlice, PayloadAction } from '@reduxjs/toolkit'
|
||||||
|
import { createSelector } from '@reduxjs/toolkit'
|
||||||
import { DEFAULT_CONTEXTCOUNT, DEFAULT_TEMPERATURE } from '@renderer/config/constant'
|
import { DEFAULT_CONTEXTCOUNT, DEFAULT_TEMPERATURE } from '@renderer/config/constant'
|
||||||
import { getDefaultAssistant } from '@renderer/services/AssistantService'
|
import { getDefaultAssistant } from '@renderer/services/AssistantService'
|
||||||
import { Assistant, AssistantSettings, Model } from '@renderer/types'
|
import { Assistant, AssistantSettings, Model } from '@renderer/types'
|
||||||
@ -15,6 +16,30 @@ const initialState: AssistantsState = {
|
|||||||
tagsOrder: []
|
tagsOrder: []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------- selectors -----------
|
||||||
|
// 基础selector
|
||||||
|
export const selectAssistantsState = (state: { assistants: AssistantsState }) => state.assistants
|
||||||
|
|
||||||
|
// 获取所有助手(不含模板)
|
||||||
|
export const selectActiveAssistants = createSelector(selectAssistantsState, (state) =>
|
||||||
|
state.assistants.filter((a) => !a.isTemplate)
|
||||||
|
)
|
||||||
|
|
||||||
|
// 获取所有模板
|
||||||
|
export const selectTemplates = createSelector(selectAssistantsState, (state) =>
|
||||||
|
state.assistants.filter((a) => a.isTemplate)
|
||||||
|
)
|
||||||
|
|
||||||
|
// 通过id查找助手(不含模板)
|
||||||
|
export const selectAssistantById = (id: string) =>
|
||||||
|
createSelector(selectActiveAssistants, (assistants) => assistants.find((a) => a.id === id))
|
||||||
|
|
||||||
|
// 通过id查找模板
|
||||||
|
export const selectTemplateById = (id: string) =>
|
||||||
|
createSelector(selectTemplates, (templates) => templates.find((a) => a.id === id))
|
||||||
|
|
||||||
|
// ----------- end selectors -----------
|
||||||
|
|
||||||
const assistantsSlice = createSlice({
|
const assistantsSlice = createSlice({
|
||||||
name: 'assistants',
|
name: 'assistants',
|
||||||
initialState,
|
initialState,
|
||||||
@ -24,7 +49,14 @@ const assistantsSlice = createSlice({
|
|||||||
state.defaultAssistant = assistant
|
state.defaultAssistant = assistant
|
||||||
},
|
},
|
||||||
updateAssistants: (state, action: PayloadAction<Assistant[]>) => {
|
updateAssistants: (state, action: PayloadAction<Assistant[]>) => {
|
||||||
state.assistants = action.payload
|
const assistants = action.payload
|
||||||
|
const templates = assistants.filter((a) => a.isTemplate)
|
||||||
|
state.assistants = [...assistants.filter((a) => !a.isTemplate), ...templates]
|
||||||
|
},
|
||||||
|
updateTemplates: (state, action: PayloadAction<Assistant[]>) => {
|
||||||
|
const templates = action.payload
|
||||||
|
const assistants = state.assistants.filter((a) => !a.isTemplate)
|
||||||
|
state.assistants = [...assistants, ...templates]
|
||||||
},
|
},
|
||||||
addAssistant: (state, action: PayloadAction<Assistant>) => {
|
addAssistant: (state, action: PayloadAction<Assistant>) => {
|
||||||
state.assistants.push(action.payload)
|
state.assistants.push(action.payload)
|
||||||
@ -40,9 +72,9 @@ const assistantsSlice = createSlice({
|
|||||||
state,
|
state,
|
||||||
action: PayloadAction<{ assistantId: string; settings: Partial<AssistantSettings> }>
|
action: PayloadAction<{ assistantId: string; settings: Partial<AssistantSettings> }>
|
||||||
) => {
|
) => {
|
||||||
|
const { assistantId, settings } = action.payload
|
||||||
for (const assistant of state.assistants) {
|
for (const assistant of state.assistants) {
|
||||||
const settings = action.payload.settings
|
if (assistant.id === assistantId) {
|
||||||
if (assistant.id === action.payload.assistantId) {
|
|
||||||
for (const key in settings) {
|
for (const key in settings) {
|
||||||
if (!assistant.settings) {
|
if (!assistant.settings) {
|
||||||
assistant.settings = {
|
assistant.settings = {
|
||||||
@ -58,17 +90,30 @@ const assistantsSlice = createSlice({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
setModel: (state, action: PayloadAction<{ assistantId: string; model: Model }>) => {
|
setModel: (state, action: PayloadAction<{ assistantId: string; model: Model }>) => {
|
||||||
const { assistantId, model } = action.payload
|
const { assistantId, model } = action.payload
|
||||||
state.assistants = state.assistants.map((assistant) =>
|
for (let i = 0; i < state.assistants.length; i++) {
|
||||||
assistant.id === assistantId
|
if (state.assistants[i].id === assistantId) {
|
||||||
? {
|
state.assistants[i] = {
|
||||||
...assistant,
|
...state.assistants[i],
|
||||||
model: model
|
model: model
|
||||||
}
|
}
|
||||||
: assistant
|
break
|
||||||
)
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 从模板创建助手
|
||||||
|
createAssistantFromTemplate: (state, action: PayloadAction<{ templateId: string; assistantId: string }>) => {
|
||||||
|
const { templateId, assistantId } = action.payload
|
||||||
|
const template = state.assistants.find((t) => t.id === templateId && t.isTemplate)
|
||||||
|
if (template) {
|
||||||
|
const newAssistant: Assistant = {
|
||||||
|
...template,
|
||||||
|
id: assistantId,
|
||||||
|
isTemplate: false
|
||||||
|
}
|
||||||
|
state.assistants.push(newAssistant)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
setTagsOrder: (state, action: PayloadAction<string[]>) => {
|
setTagsOrder: (state, action: PayloadAction<string[]>) => {
|
||||||
state.tagsOrder = action.payload
|
state.tagsOrder = action.payload
|
||||||
@ -82,6 +127,7 @@ export const {
|
|||||||
addAssistant,
|
addAssistant,
|
||||||
removeAssistant,
|
removeAssistant,
|
||||||
updateAssistant,
|
updateAssistant,
|
||||||
|
createAssistantFromTemplate,
|
||||||
setModel,
|
setModel,
|
||||||
setTagsOrder,
|
setTagsOrder,
|
||||||
updateAssistantSettings
|
updateAssistantSettings
|
||||||
|
|||||||
@ -52,7 +52,7 @@ const persistedReducer = persistReducer(
|
|||||||
{
|
{
|
||||||
key: 'cherry-studio',
|
key: 'cherry-studio',
|
||||||
storage,
|
storage,
|
||||||
version: 113,
|
version: 114,
|
||||||
blacklist: ['runtime', 'messages', 'messageBlocks'],
|
blacklist: ['runtime', 'messages', 'messageBlocks'],
|
||||||
migrate
|
migrate
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1658,6 +1658,37 @@ const migrateConfig = {
|
|||||||
topicIdsByAssistant
|
topicIdsByAssistant
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return state
|
||||||
|
} catch (error) {
|
||||||
|
return state
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'114': (state: RootState) => {
|
||||||
|
try {
|
||||||
|
if (
|
||||||
|
state.assistants &&
|
||||||
|
state.assistants.defaultAssistant &&
|
||||||
|
state.assistants.defaultAssistant.isTemplate === undefined
|
||||||
|
) {
|
||||||
|
state.assistants.defaultAssistant.isTemplate = false
|
||||||
|
}
|
||||||
|
if (state.assistants && state.assistants.assistants.length > 0) {
|
||||||
|
state.assistants.assistants
|
||||||
|
.filter((assistant) => assistant.isTemplate !== undefined)
|
||||||
|
.forEach((assistant) => {
|
||||||
|
assistant.isTemplate = false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state.agents && state.agents.agents.length > 0) {
|
||||||
|
state.agents.agents.forEach((agent) => {
|
||||||
|
agent.isTemplate = true
|
||||||
|
state.assistants.assistants.push(agent)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// @ts-ignore eslint-disable-next-line
|
||||||
|
delete state.agents
|
||||||
return state
|
return state
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return state
|
return state
|
||||||
|
|||||||
@ -12,7 +12,8 @@ export type Assistant = {
|
|||||||
knowledge_bases?: KnowledgeBase[]
|
knowledge_bases?: KnowledgeBase[]
|
||||||
/** @deprecated 话题现在通过独立的 topics slice 管理,请使用 selectTopicsForAssistant selector */
|
/** @deprecated 话题现在通过独立的 topics slice 管理,请使用 selectTopicsForAssistant selector */
|
||||||
topics: Topic[]
|
topics: Topic[]
|
||||||
type: string
|
/** @deprecated 助手类型已废弃,请使用 isTemplate 字段 */
|
||||||
|
type?: string
|
||||||
emoji?: string
|
emoji?: string
|
||||||
description?: string
|
description?: string
|
||||||
model?: Model
|
model?: Model
|
||||||
@ -27,6 +28,8 @@ export type Assistant = {
|
|||||||
knowledgeRecognition?: 'off' | 'on'
|
knowledgeRecognition?: 'off' | 'on'
|
||||||
regularPhrases?: QuickPhrase[] // Added for regular phrase
|
regularPhrases?: QuickPhrase[] // Added for regular phrase
|
||||||
tags?: string[] // 助手标签
|
tags?: string[] // 助手标签
|
||||||
|
isTemplate?: boolean
|
||||||
|
group?: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export type AssistantsSortType = 'tags' | 'list'
|
export type AssistantsSortType = 'tags' | 'list'
|
||||||
@ -66,9 +69,8 @@ export type AssistantSettings = {
|
|||||||
toolUseMode?: 'function' | 'prompt'
|
toolUseMode?: 'function' | 'prompt'
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Agent = Omit<Assistant, 'model'> & {
|
// 为了兼容性,保留Agent类型别名
|
||||||
group?: string[]
|
export type Agent = Assistant
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated 旧版消息类型,已废弃
|
* @deprecated 旧版消息类型,已废弃
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user