mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-11 08:19:01 +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 { createSlice, PayloadAction } from '@reduxjs/toolkit'
|
||||||
import { DEFAULT_CONTEXTCOUNT, DEFAULT_TEMPERATURE } from '@renderer/config/constant'
|
import { DEFAULT_CONTEXTCOUNT, DEFAULT_TEMPERATURE } from '@renderer/config/constant'
|
||||||
import { AgentEntity, AssistantPreset, AssistantSettings } from '@renderer/types'
|
import { AssistantPreset, AssistantSettings } from '@renderer/types'
|
||||||
import { cloneDeep, mergeWith } from 'lodash'
|
|
||||||
|
|
||||||
const logger = loggerService.withContext('Agents')
|
// const logger = loggerService.withContext('Agents')
|
||||||
export interface AgentsState {
|
export interface AgentsState {
|
||||||
/** They are actually assistant presets.
|
/** They are actually assistant presets.
|
||||||
* They should not be in this slice. However, since redux will be removed
|
* 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. */
|
* in the future, I just don't care where should they are. */
|
||||||
agents: AssistantPreset[]
|
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 = {
|
const initialState: AgentsState = {
|
||||||
agents: [],
|
agents: []
|
||||||
agentsNew: []
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const assistantsSlice = createSlice({
|
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,
|
addAssistantPreset,
|
||||||
removeAssistantPreset,
|
removeAssistantPreset,
|
||||||
updateAssistantPreset,
|
updateAssistantPreset,
|
||||||
updateAssistantPresetSettings,
|
updateAssistantPresetSettings
|
||||||
setAgents,
|
|
||||||
addAgent,
|
|
||||||
removeAgent,
|
|
||||||
updateAgent
|
|
||||||
} = assistantsSlice.actions
|
} = assistantsSlice.actions
|
||||||
|
|
||||||
export default assistantsSlice.reducer
|
export default assistantsSlice.reducer
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user