fix(gemini): abort default injection on existing thinking keys
Unified · Split
| @@ -71,10 +71,13 @@ func ApplyGeminiThinkingConfig(body []byte, budget *int, includeThoughts *bool) · 70 unmodified lines | ||
| 71 | 71 | incl = &defaultInclude |
| 72 | 72 | } |
| 73 | 73 | if incl != nil { |
| 74 | − valuePath := "generationConfig.thinkingConfig.include_thoughts" | |
| 75 | − rewritten, err := sjson.SetBytes(updated, valuePath, *incl) | |
| 76 | − if err == nil { | |
| 77 | − updated = rewritten | |
| 74 | + if !gjson.GetBytes(updated, "generationConfig.thinkingConfig.includeThoughts").Exists() && | |
| 75 | + !gjson.GetBytes(updated, "generationConfig.thinkingConfig.include_thoughts").Exists() { | |
| 76 | + valuePath := "generationConfig.thinkingConfig.include_thoughts" | |
| 77 | + rewritten, err := sjson.SetBytes(updated, valuePath, *incl) | |
| 78 | + if err == nil { | |
| 79 | + updated = rewritten | |
| 80 | + } | |
| 78 | 81 | } |
| 79 | 82 | } |
| 80 | 83 | return updated |
| @@ -99,10 +102,13 @@ func ApplyGeminiCLIThinkingConfig(body []byte, budget *int, includeThoughts *boo · 18 unmodified lines | ||
| 99 | 102 | incl = &defaultInclude |
| 100 | 103 | } |
| 101 | 104 | if incl != nil { |
| 102 | − valuePath := "request.generationConfig.thinkingConfig.include_thoughts" | |
| 103 | − rewritten, err := sjson.SetBytes(updated, valuePath, *incl) | |
| 104 | − if err == nil { | |
| 105 | − updated = rewritten | |
| 105 | + if !gjson.GetBytes(updated, "request.generationConfig.thinkingConfig.includeThoughts").Exists() && | |
| 106 | + !gjson.GetBytes(updated, "request.generationConfig.thinkingConfig.include_thoughts").Exists() { | |
| 107 | + valuePath := "request.generationConfig.thinkingConfig.include_thoughts" | |
| 108 | + rewritten, err := sjson.SetBytes(updated, valuePath, *incl) | |
| 109 | + if err == nil { | |
| 110 | + updated = rewritten | |
| 111 | + } | |
| 106 | 112 | } |
| 107 | 113 | } |
| 108 | 114 | return updated |
| @@ -130,15 +136,15 @@ func ApplyGeminiThinkingLevel(body []byte, level string, includeThoughts *bool) · 21 unmodified lines | ||
| 130 | 136 | incl = &defaultInclude |
| 131 | 137 | } |
| 132 | 138 | if incl != nil { |
| 133 | − valuePath := "generationConfig.thinkingConfig.includeThoughts" | |
| 134 | − rewritten, err := sjson.SetBytes(updated, valuePath, *incl) | |
| 135 | − if err == nil { | |
| 136 | − updated = rewritten | |
| 139 | + if !gjson.GetBytes(updated, "generationConfig.thinkingConfig.includeThoughts").Exists() && | |
| 140 | + !gjson.GetBytes(updated, "generationConfig.thinkingConfig.include_thoughts").Exists() { | |
| 141 | + valuePath := "generationConfig.thinkingConfig.includeThoughts" | |
| 142 | + rewritten, err := sjson.SetBytes(updated, valuePath, *incl) | |
| 143 | + if err == nil { | |
| 144 | + updated = rewritten | |
| 145 | + } | |
| 137 | 146 | } |
| 138 | 147 | } |
| 139 | − if it := gjson.GetBytes(body, "generationConfig.thinkingConfig.include_thoughts"); it.Exists() { | |
| 140 | − updated, _ = sjson.DeleteBytes(updated, "generationConfig.thinkingConfig.include_thoughts") | |
| 141 | − } | |
| 142 | 148 | if tb := gjson.GetBytes(body, "generationConfig.thinkingConfig.thinkingBudget"); tb.Exists() { |
| 143 | 149 | updated, _ = sjson.DeleteBytes(updated, "generationConfig.thinkingConfig.thinkingBudget") |
| 144 | 150 | } |
| @@ -167,15 +173,15 @@ func ApplyGeminiCLIThinkingLevel(body []byte, level string, includeThoughts *boo · 22 unmodified lines | ||
| 167 | 173 | incl = &defaultInclude |
| 168 | 174 | } |
| 169 | 175 | if incl != nil { |
| 170 | − valuePath := "request.generationConfig.thinkingConfig.includeThoughts" | |
| 171 | − rewritten, err := sjson.SetBytes(updated, valuePath, *incl) | |
| 172 | − if err == nil { | |
| 173 | − updated = rewritten | |
| 176 | + if !gjson.GetBytes(updated, "request.generationConfig.thinkingConfig.includeThoughts").Exists() && | |
| 177 | + !gjson.GetBytes(updated, "request.generationConfig.thinkingConfig.include_thoughts").Exists() { | |
| 178 | + valuePath := "request.generationConfig.thinkingConfig.includeThoughts" | |
| 179 | + rewritten, err := sjson.SetBytes(updated, valuePath, *incl) | |
| 180 | + if err == nil { | |
| 181 | + updated = rewritten | |
| 182 | + } | |
| 174 | 183 | } |
| 175 | 184 | } |
| 176 | − if it := gjson.GetBytes(body, "request.generationConfig.thinkingConfig.include_thoughts"); it.Exists() { | |
| 177 | − updated, _ = sjson.DeleteBytes(updated, "request.generationConfig.thinkingConfig.include_thoughts") | |
| 178 | − } | |
| 179 | 185 | if tb := gjson.GetBytes(body, "request.generationConfig.thinkingConfig.thinkingBudget"); tb.Exists() { |
| 180 | 186 | updated, _ = sjson.DeleteBytes(updated, "request.generationConfig.thinkingConfig.thinkingBudget") |
| 181 | 187 | } |