fix(gemini): abort default injection on existing thinking keys

This commit is contained in:
hkfires
2026-01-05 10:24:30 +08:00
parent 8edbda57cf
commit 05444cf32d

View File

@@ -71,10 +71,13 @@ func ApplyGeminiThinkingConfig(body []byte, budget *int, includeThoughts *bool)
incl = &defaultInclude incl = &defaultInclude
} }
if incl != nil { if incl != nil {
valuePath := "generationConfig.thinkingConfig.include_thoughts" if !gjson.GetBytes(updated, "generationConfig.thinkingConfig.includeThoughts").Exists() &&
rewritten, err := sjson.SetBytes(updated, valuePath, *incl) !gjson.GetBytes(updated, "generationConfig.thinkingConfig.include_thoughts").Exists() {
if err == nil { valuePath := "generationConfig.thinkingConfig.include_thoughts"
updated = rewritten rewritten, err := sjson.SetBytes(updated, valuePath, *incl)
if err == nil {
updated = rewritten
}
} }
} }
return updated return updated
@@ -99,10 +102,13 @@ func ApplyGeminiCLIThinkingConfig(body []byte, budget *int, includeThoughts *boo
incl = &defaultInclude incl = &defaultInclude
} }
if incl != nil { if incl != nil {
valuePath := "request.generationConfig.thinkingConfig.include_thoughts" if !gjson.GetBytes(updated, "request.generationConfig.thinkingConfig.includeThoughts").Exists() &&
rewritten, err := sjson.SetBytes(updated, valuePath, *incl) !gjson.GetBytes(updated, "request.generationConfig.thinkingConfig.include_thoughts").Exists() {
if err == nil { valuePath := "request.generationConfig.thinkingConfig.include_thoughts"
updated = rewritten rewritten, err := sjson.SetBytes(updated, valuePath, *incl)
if err == nil {
updated = rewritten
}
} }
} }
return updated return updated
@@ -130,15 +136,15 @@ func ApplyGeminiThinkingLevel(body []byte, level string, includeThoughts *bool)
incl = &defaultInclude incl = &defaultInclude
} }
if incl != nil { if incl != nil {
valuePath := "generationConfig.thinkingConfig.includeThoughts" if !gjson.GetBytes(updated, "generationConfig.thinkingConfig.includeThoughts").Exists() &&
rewritten, err := sjson.SetBytes(updated, valuePath, *incl) !gjson.GetBytes(updated, "generationConfig.thinkingConfig.include_thoughts").Exists() {
if err == nil { valuePath := "generationConfig.thinkingConfig.includeThoughts"
updated = rewritten rewritten, err := sjson.SetBytes(updated, valuePath, *incl)
if err == nil {
updated = rewritten
}
} }
} }
if it := gjson.GetBytes(body, "generationConfig.thinkingConfig.include_thoughts"); it.Exists() {
updated, _ = sjson.DeleteBytes(updated, "generationConfig.thinkingConfig.include_thoughts")
}
if tb := gjson.GetBytes(body, "generationConfig.thinkingConfig.thinkingBudget"); tb.Exists() { if tb := gjson.GetBytes(body, "generationConfig.thinkingConfig.thinkingBudget"); tb.Exists() {
updated, _ = sjson.DeleteBytes(updated, "generationConfig.thinkingConfig.thinkingBudget") updated, _ = sjson.DeleteBytes(updated, "generationConfig.thinkingConfig.thinkingBudget")
} }
@@ -167,15 +173,15 @@ func ApplyGeminiCLIThinkingLevel(body []byte, level string, includeThoughts *boo
incl = &defaultInclude incl = &defaultInclude
} }
if incl != nil { if incl != nil {
valuePath := "request.generationConfig.thinkingConfig.includeThoughts" if !gjson.GetBytes(updated, "request.generationConfig.thinkingConfig.includeThoughts").Exists() &&
rewritten, err := sjson.SetBytes(updated, valuePath, *incl) !gjson.GetBytes(updated, "request.generationConfig.thinkingConfig.include_thoughts").Exists() {
if err == nil { valuePath := "request.generationConfig.thinkingConfig.includeThoughts"
updated = rewritten rewritten, err := sjson.SetBytes(updated, valuePath, *incl)
if err == nil {
updated = rewritten
}
} }
} }
if it := gjson.GetBytes(body, "request.generationConfig.thinkingConfig.include_thoughts"); it.Exists() {
updated, _ = sjson.DeleteBytes(updated, "request.generationConfig.thinkingConfig.include_thoughts")
}
if tb := gjson.GetBytes(body, "request.generationConfig.thinkingConfig.thinkingBudget"); tb.Exists() { if tb := gjson.GetBytes(body, "request.generationConfig.thinkingConfig.thinkingBudget"); tb.Exists() {
updated, _ = sjson.DeleteBytes(updated, "request.generationConfig.thinkingConfig.thinkingBudget") updated, _ = sjson.DeleteBytes(updated, "request.generationConfig.thinkingConfig.thinkingBudget")
} }