mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-03 02:59:07 +08:00
refactor(agents): remove unused agent entities and related code
Clean up agents store by removing deprecated AgentEntity-related code that is no longer used. This simplifies the store structure as we're moving away from redux.
This commit is contained in:
parent
6aaef9b7be
commit
d7052b547f
@ -1,24 +1,17 @@
|
||||
import { loggerService } from '@logger'
|
||||
import { createSlice, PayloadAction } from '@reduxjs/toolkit'
|
||||
import { DEFAULT_CONTEXTCOUNT, DEFAULT_TEMPERATURE } from '@renderer/config/constant'
|
||||
import { AgentEntity, AssistantPreset, AssistantSettings } from '@renderer/types'
|
||||
import { cloneDeep, mergeWith } from 'lodash'
|
||||
import { AssistantPreset, AssistantSettings } from '@renderer/types'
|
||||
|
||||
const logger = loggerService.withContext('Agents')
|
||||
// const logger = loggerService.withContext('Agents')
|
||||
export interface AgentsState {
|
||||
/** They are actually assistant presets.
|
||||
* They should not be in this slice. However, since redux will be removed
|
||||
* in the future, I just don't care where should they are. */
|
||||
agents: AssistantPreset[]
|
||||
/** For new autonomous agent feature. They are actual agent entities.
|
||||
* They won't be used anymore when sqlite api is ready.
|
||||
*/
|
||||
agentsNew: AgentEntity[]
|
||||
}
|
||||
|
||||
const initialState: AgentsState = {
|
||||
agents: [],
|
||||
agentsNew: []
|
||||
agents: []
|
||||
}
|
||||
|
||||
const assistantsSlice = createSlice({
|
||||
@ -58,28 +51,6 @@ const assistantsSlice = createSlice({
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
setAgents: (state, action: PayloadAction<AgentEntity[]>) => {
|
||||
state.agentsNew = action.payload
|
||||
},
|
||||
addAgent: (state, action: PayloadAction<AgentEntity>) => {
|
||||
state.agentsNew.push(action.payload)
|
||||
},
|
||||
removeAgent: (state, action: PayloadAction<{ id: string }>) => {
|
||||
state.agentsNew = state.agentsNew.filter((agent) => agent.id !== action.payload.id)
|
||||
},
|
||||
updateAgent: (state, action: PayloadAction<Partial<AgentEntity> & { id: string }>) => {
|
||||
const { id, ...update } = action.payload
|
||||
const agent = state.agentsNew.find((agent) => agent.id === id)
|
||||
if (agent) {
|
||||
mergeWith(agent, update, (_, srcVal) => {
|
||||
// cut reference
|
||||
if (Array.isArray(srcVal)) return cloneDeep(srcVal)
|
||||
else return undefined
|
||||
})
|
||||
} else {
|
||||
logger.warn('Agent not found when trying to update')
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -89,11 +60,7 @@ export const {
|
||||
addAssistantPreset,
|
||||
removeAssistantPreset,
|
||||
updateAssistantPreset,
|
||||
updateAssistantPresetSettings,
|
||||
setAgents,
|
||||
addAgent,
|
||||
removeAgent,
|
||||
updateAgent
|
||||
updateAssistantPresetSettings
|
||||
} = assistantsSlice.actions
|
||||
|
||||
export default assistantsSlice.reducer
|
||||
|
||||
Loading…
Reference in New Issue
Block a user