refactor(useAgents): simplify addAgent_ by accepting complete agent entity

This commit is contained in:
icarus 2025-09-14 00:15:45 +08:00
parent e0d2d44f35
commit 943fccf655

View File

@ -1,22 +1,17 @@
import { useAppDispatch } from '@renderer/store' import { useAppDispatch } from '@renderer/store'
import { addAgent, removeAgent, setAgents, updateAgent } from '@renderer/store/agents' import { addAgent, removeAgent, setAgents, updateAgent } from '@renderer/store/agents'
import { AgentEntity } from '@renderer/types' import { AgentEntity } from '@renderer/types'
import { uuid } from '@renderer/utils'
import { useCallback } from 'react' import { useCallback } from 'react'
export const useAgents = () => { export const useAgents = () => {
const dispatch = useAppDispatch() const dispatch = useAppDispatch()
/** /**
* Adds a new agent to the store * Adds a new agent to the store
* @param config - The configuration object for the new agent (without id) * @param agent - The complete agent entity to add
*/ */
const addAgent_ = useCallback( const addAgent_ = useCallback(
(config: Omit<AgentEntity, 'id'>) => { (agent: AgentEntity) => {
const entity = { dispatch(addAgent(agent))
...config,
id: uuid()
} as const
dispatch(addAgent(entity))
}, },
[dispatch] [dispatch]
) )