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 { t } = useTranslation()
const loadingRef = useRef(false) const loadingRef = useRef(false)
const { setTimeoutTimer } = useTimer() const { setTimeoutTimer } = useTimer()
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { addAgent } = useAgents() const { addAgent } = useAgents()
// default values. may change to undefined. // default values. may change to undefined.
@ -208,14 +207,14 @@ export const AddAgentModal: React.FC = () => {
model: form.model model: form.model
} satisfies AgentEntity } satisfies AgentEntity
logger.debug('Agent', agent) logger.debug('Agent', agent)
// addAgent(agent) addAgent(agent)
window.toast.success(t('common.add_success')) window.toast.success(t('common.add_success'))
loadingRef.current = false loadingRef.current = false
setTimeoutTimer('onCreateAgent', () => EventEmitter.emit(EVENT_NAMES.SHOW_ASSISTANTS), 0) setTimeoutTimer('onCreateAgent', () => EventEmitter.emit(EVENT_NAMES.SHOW_ASSISTANTS), 0)
onClose() 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 ( return (
@ -250,7 +249,7 @@ export const AddAgentModal: React.FC = () => {
)} )}
</Select> </Select>
<Input isRequired value={form.name} onValueChange={onNameChange} label={t('common.name')} /> <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 <Select
isRequired isRequired
selectionMode="single" selectionMode="single"

View File

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

View File

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