diff --git a/internal/util/gemini_thinking.go b/internal/util/gemini_thinking.go index 19397f0dc..8e76f3bc7 100644 --- a/internal/util/gemini_thinking.go +++ b/internal/util/gemini_thinking.go @@ -71,10 +71,13 @@ func ApplyGeminiThinkingConfig(body []byte, budget *int, includeThoughts *bool) incl = &defaultInclude } if incl != nil { - valuePath := "generationConfig.thinkingConfig.include_thoughts" - rewritten, err := sjson.SetBytes(updated, valuePath, *incl) - if err == nil { - updated = rewritten + if !gjson.GetBytes(updated, "generationConfig.thinkingConfig.includeThoughts").Exists() && + !gjson.GetBytes(updated, "generationConfig.thinkingConfig.include_thoughts").Exists() { + valuePath := "generationConfig.thinkingConfig.include_thoughts" + rewritten, err := sjson.SetBytes(updated, valuePath, *incl) + if err == nil { + updated = rewritten + } } } return updated @@ -99,10 +102,13 @@ func ApplyGeminiCLIThinkingConfig(body []byte, budget *int, includeThoughts *boo incl = &defaultInclude } if incl != nil { - valuePath := "request.generationConfig.thinkingConfig.include_thoughts" - rewritten, err := sjson.SetBytes(updated, valuePath, *incl) - if err == nil { - updated = rewritten + if !gjson.GetBytes(updated, "request.generationConfig.thinkingConfig.includeThoughts").Exists() && + !gjson.GetBytes(updated, "request.generationConfig.thinkingConfig.include_thoughts").Exists() { + valuePath := "request.generationConfig.thinkingConfig.include_thoughts" + rewritten, err := sjson.SetBytes(updated, valuePath, *incl) + if err == nil { + updated = rewritten + } } } return updated @@ -130,15 +136,15 @@ func ApplyGeminiThinkingLevel(body []byte, level string, includeThoughts *bool) incl = &defaultInclude } if incl != nil { - valuePath := "generationConfig.thinkingConfig.includeThoughts" - rewritten, err := sjson.SetBytes(updated, valuePath, *incl) - if err == nil { - updated = rewritten + if !gjson.GetBytes(updated, "generationConfig.thinkingConfig.includeThoughts").Exists() && + !gjson.GetBytes(updated, "generationConfig.thinkingConfig.include_thoughts").Exists() { + valuePath := "generationConfig.thinkingConfig.includeThoughts" + 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() { updated, _ = sjson.DeleteBytes(updated, "generationConfig.thinkingConfig.thinkingBudget") } @@ -167,15 +173,15 @@ func ApplyGeminiCLIThinkingLevel(body []byte, level string, includeThoughts *boo incl = &defaultInclude } if incl != nil { - valuePath := "request.generationConfig.thinkingConfig.includeThoughts" - rewritten, err := sjson.SetBytes(updated, valuePath, *incl) - if err == nil { - updated = rewritten + if !gjson.GetBytes(updated, "request.generationConfig.thinkingConfig.includeThoughts").Exists() && + !gjson.GetBytes(updated, "request.generationConfig.thinkingConfig.include_thoughts").Exists() { + valuePath := "request.generationConfig.thinkingConfig.includeThoughts" + 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() { updated, _ = sjson.DeleteBytes(updated, "request.generationConfig.thinkingConfig.thinkingBudget") }