History

Merge pull request #862 from router-for-me/gemini

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

Luis Pater committed 10 months agov6.6.84

Commit e124db72 parents 8edbda5 05444cf1 file · +28 −22Browse files

Unified · Split

internal/util/gemini_thinking.go+28−22
@@ -71,10 +71,13 @@ func ApplyGeminiThinkingConfig(body []byte, budget *int, includeThoughts *bool) · 70 unmodified lines
71 incl = &defaultInclude71 incl = &defaultInclude
72 }72 }
73 if incl != nil {73 if incl != nil {
74 valuePath := "generationConfig.thinkingConfig.include_thoughts"74 if !gjson.GetBytes(updated, "generationConfig.thinkingConfig.includeThoughts").Exists() &&
75 rewritten, err := sjson.SetBytes(updated, valuePath, *incl)75 !gjson.GetBytes(updated, "generationConfig.thinkingConfig.include_thoughts").Exists() {
76 if err == nil {76 valuePath := "generationConfig.thinkingConfig.include_thoughts"
77 updated = rewritten77 rewritten, err := sjson.SetBytes(updated, valuePath, *incl)
78 if err == nil {
79 updated = rewritten
80 }
78 }81 }
79 }82 }
80 return updated83 return updated
@@ -99,10 +102,13 @@ func ApplyGeminiCLIThinkingConfig(body []byte, budget *int, includeThoughts *boo · 18 unmodified lines
99 incl = &defaultInclude102 incl = &defaultInclude
100 }103 }
101 if incl != nil {104 if incl != nil {
102 valuePath := "request.generationConfig.thinkingConfig.include_thoughts"105 if !gjson.GetBytes(updated, "request.generationConfig.thinkingConfig.includeThoughts").Exists() &&
103 rewritten, err := sjson.SetBytes(updated, valuePath, *incl)106 !gjson.GetBytes(updated, "request.generationConfig.thinkingConfig.include_thoughts").Exists() {
104 if err == nil {107 valuePath := "request.generationConfig.thinkingConfig.include_thoughts"
105 updated = rewritten108 rewritten, err := sjson.SetBytes(updated, valuePath, *incl)
109 if err == nil {
110 updated = rewritten
111 }
106 }112 }
107 }113 }
108 return updated114 return updated
@@ -130,15 +136,15 @@ func ApplyGeminiThinkingLevel(body []byte, level string, includeThoughts *bool) · 21 unmodified lines
130 incl = &defaultInclude136 incl = &defaultInclude
131 }137 }
132 if incl != nil {138 if incl != nil {
133 valuePath := "generationConfig.thinkingConfig.includeThoughts"139 if !gjson.GetBytes(updated, "generationConfig.thinkingConfig.includeThoughts").Exists() &&
134 rewritten, err := sjson.SetBytes(updated, valuePath, *incl)140 !gjson.GetBytes(updated, "generationConfig.thinkingConfig.include_thoughts").Exists() {
135 if err == nil {141 valuePath := "generationConfig.thinkingConfig.includeThoughts"
136 updated = rewritten142 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 if tb := gjson.GetBytes(body, "generationConfig.thinkingConfig.thinkingBudget"); tb.Exists() {148 if tb := gjson.GetBytes(body, "generationConfig.thinkingConfig.thinkingBudget"); tb.Exists() {
143 updated, _ = sjson.DeleteBytes(updated, "generationConfig.thinkingConfig.thinkingBudget")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 incl = &defaultInclude173 incl = &defaultInclude
168 }174 }
169 if incl != nil {175 if incl != nil {
170 valuePath := "request.generationConfig.thinkingConfig.includeThoughts"176 if !gjson.GetBytes(updated, "request.generationConfig.thinkingConfig.includeThoughts").Exists() &&
171 rewritten, err := sjson.SetBytes(updated, valuePath, *incl)177 !gjson.GetBytes(updated, "request.generationConfig.thinkingConfig.include_thoughts").Exists() {
172 if err == nil {178 valuePath := "request.generationConfig.thinkingConfig.includeThoughts"
173 updated = rewritten179 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 if tb := gjson.GetBytes(body, "request.generationConfig.thinkingConfig.thinkingBudget"); tb.Exists() {185 if tb := gjson.GetBytes(body, "request.generationConfig.thinkingConfig.thinkingBudget"); tb.Exists() {
180 updated, _ = sjson.DeleteBytes(updated, "request.generationConfig.thinkingConfig.thinkingBudget")186 updated, _ = sjson.DeleteBytes(updated, "request.generationConfig.thinkingConfig.thinkingBudget")
181 }187 }