mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-23 01:50:13 +08:00
fix(assistant): enforce id requirement when updating assistant (#10321)
* fix(assistant): enforce id requirement when updating assistant Ensure assistant id is always provided when updating assistant properties by making it a required field in the update payload. This prevents potential bugs where updates might be applied to wrong assistants. * refactor(useAssistant): simplify updateAssistant callback by removing redundant id Update InputbarTools to use simplified callback signature
This commit is contained in:
parent
4a4a1686d3
commit
fe0c0fac1e
@ -172,7 +172,10 @@ export function useAssistant(id: string) {
|
|||||||
(model: Model) => assistant && dispatch(setModel({ assistantId: assistant?.id, model })),
|
(model: Model) => assistant && dispatch(setModel({ assistantId: assistant?.id, model })),
|
||||||
[assistant, dispatch]
|
[assistant, dispatch]
|
||||||
),
|
),
|
||||||
updateAssistant: useCallback((assistant: Partial<Assistant>) => dispatch(updateAssistant(assistant)), [dispatch]),
|
updateAssistant: useCallback(
|
||||||
|
(update: Partial<Omit<Assistant, 'id'>>) => dispatch(updateAssistant({ id, ...update })),
|
||||||
|
[dispatch, id]
|
||||||
|
),
|
||||||
updateAssistantSettings
|
updateAssistantSettings
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -46,8 +46,9 @@ const assistantsSlice = createSlice({
|
|||||||
removeAssistant: (state, action: PayloadAction<{ id: string }>) => {
|
removeAssistant: (state, action: PayloadAction<{ id: string }>) => {
|
||||||
state.assistants = state.assistants.filter((c) => c.id !== action.payload.id)
|
state.assistants = state.assistants.filter((c) => c.id !== action.payload.id)
|
||||||
},
|
},
|
||||||
updateAssistant: (state, action: PayloadAction<Partial<Assistant>>) => {
|
updateAssistant: (state, action: PayloadAction<Partial<Assistant> & { id: string }>) => {
|
||||||
state.assistants = state.assistants.map((c) => (c.id === action.payload.id ? { ...c, ...action.payload } : c))
|
const { id, ...update } = action.payload
|
||||||
|
state.assistants = state.assistants.map((c) => (c.id === id ? { ...c, ...update } : c))
|
||||||
},
|
},
|
||||||
updateAssistantSettings: (
|
updateAssistantSettings: (
|
||||||
state,
|
state,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user