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 { addAgent, removeAgent, setAgents, updateAgent } from '@renderer/store/agents'
import { AgentEntity } from '@renderer/types'
import { uuid } from '@renderer/utils'
import { useCallback } from 'react'
export const useAgents = () => {
const dispatch = useAppDispatch()
/**
* 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(
(config: Omit<AgentEntity, 'id'>) => {
const entity = {
...config,
id: uuid()
} as const
dispatch(addAgent(entity))
(agent: AgentEntity) => {
dispatch(addAgent(agent))
},
[dispatch]
)