feat(agents): implement add agent functionality and migration

- Add migration for new agents structure (version 155)
- Enable addAgent call in AddAgentModal
- Update dependencies array with addAgent
- Replace TODO comment with FIXME for model type issue
This commit is contained in:
icarus 2025-09-14 05:59:08 +08:00
parent 1bf63865a8
commit 941a6666e6
3 changed files with 13 additions and 5 deletions

View File

@ -57,7 +57,6 @@ export const AddAgentModal: React.FC = () => {
const { t } = useTranslation()
const loadingRef = useRef(false)
const { setTimeoutTimer } = useTimer()
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { addAgent } = useAgents()
// default values. may change to undefined.
@ -208,14 +207,14 @@ export const AddAgentModal: React.FC = () => {
model: form.model
} satisfies AgentEntity
logger.debug('Agent', agent)
// addAgent(agent)
addAgent(agent)
window.toast.success(t('common.add_success'))
loadingRef.current = false
setTimeoutTimer('onCreateAgent', () => EventEmitter.emit(EVENT_NAMES.SHOW_ASSISTANTS), 0)
onClose()
},
[form.type, form.model, form.name, form.description, form.instructions, t, setTimeoutTimer, onClose]
[form.type, form.model, form.name, form.description, form.instructions, addAgent, t, setTimeoutTimer, onClose]
)
return (
@ -250,7 +249,7 @@ export const AddAgentModal: React.FC = () => {
)}
</Select>
<Input isRequired value={form.name} onValueChange={onNameChange} label={t('common.name')} />
{/* Model type definition is string. It cannot be related to provider. Just mock a model now. */}
{/* FIXME: Model type definition is string. It cannot be related to provider. Just mock a model now. */}
<Select
isRequired
selectionMode="single"

View File

@ -67,7 +67,7 @@ const persistedReducer = persistReducer(
{
key: 'cherry-studio',
storage,
version: 154,
version: 155,
blacklist: ['runtime', 'messages', 'messageBlocks', 'tabs'],
migrate
},

View File

@ -2463,6 +2463,15 @@ const migrateConfig = {
logger.error('migrate 154 error', error as Error)
return state
}
},
'155': (state: RootState) => {
try {
state.agents.agentsNew = []
return state
} catch (error) {
logger.error('migrate 155 error', error as Error)
return state
}
}
}