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:
Phantom 2025-09-24 12:24:28 +08:00 committed by GitHub
parent 4a4a1686d3
commit fe0c0fac1e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 3 deletions

View File

@ -172,7 +172,10 @@ export function useAssistant(id: string) {
(model: Model) => assistant && dispatch(setModel({ assistantId: assistant?.id, model })),
[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
}
}

View File

@ -46,8 +46,9 @@ const assistantsSlice = createSlice({
removeAssistant: (state, action: PayloadAction<{ id: string }>) => {
state.assistants = state.assistants.filter((c) => c.id !== action.payload.id)
},
updateAssistant: (state, action: PayloadAction<Partial<Assistant>>) => {
state.assistants = state.assistants.map((c) => (c.id === action.payload.id ? { ...c, ...action.payload } : c))
updateAssistant: (state, action: PayloadAction<Partial<Assistant> & { id: string }>) => {
const { id, ...update } = action.payload
state.assistants = state.assistants.map((c) => (c.id === id ? { ...c, ...update } : c))
},
updateAssistantSettings: (
state,