Handle ExtraBody clearing when frontend sends empty object

The backend now interprets an empty object sent from the frontend as a
signal to clear the ExtraBody field, while nil/undefined preserves the
existing value. Frontend changed to send {} instead of undefined when
the field is empty.
This commit is contained in:
uiyzzi 2026-03-25 10:46:40 +08:00
parent 47a796b08f
commit f9e4b6cc36
2 changed files with 6 additions and 1 deletions

View file

@ -202,8 +202,13 @@ func (h *Handler) handleUpdateModel(w http.ResponseWriter, r *http.Request) {
} else {
mc.ModelConfig.SetAPIKey(mc.APIKey)
}
// Preserve existing ExtraBody when omitted (nil), but clear it when
// the frontend sends an empty object {} to indicate the field should
// be removed.
if mc.ExtraBody == nil {
mc.ExtraBody = cfg.ModelList[idx].ExtraBody
} else if len(mc.ExtraBody) == 0 {
mc.ExtraBody = nil
}
cfg.ModelList[idx] = &mc.ModelConfig

View file

@ -117,7 +117,7 @@ export function EditModelSheet({
thinking_level: form.thinkingLevel || undefined,
extra_body: form.extraBody.trim()
? JSON.parse(form.extraBody.trim())
: undefined,
: {},
})
if (setAsDefault && !model.is_default) {
await setDefaultModel(model.model_name)