History

Merge branch 'router-for-me:main' into main

Luis Pater committed 8 months agov6.8.42-0

Commit 352cb982 parents 7ebd8f0 585049218 files · +360 −30Browse files

Unified · Split

18 files
  1. config.example.yaml +3 −0
  2. internal/api/handlers/management/config_lists.go +11 −6
  3. internal/config/vertex_compat.go +4 −0
  4. internal/runtime/executor/antigravity_executor_buildrequest_test.go +4 −0
  5. internal/translator/antigravity/claude/antigravity_claude_request.go +34 −4
  6. internal/translator/antigravity/claude/antigravity_claude_request_test.go +97 −0
  7. internal/translator/codex/claude/codex_claude_request.go +2 −0
  8. internal/translator/codex/openai/chat-completions/codex_openai_response.go +5 −0
  9. internal/translator/codex/openai/chat-completions/codex_openai_response_test.go +47 −0
  10. internal/translator/gemini-cli/claude/gemini-cli_claude_request.go +28 −0
  11. internal/translator/gemini-cli/claude/gemini-cli_claude_request_test.go +42 −0
  12. internal/translator/gemini/claude/gemini_claude_request.go +28 −0
  13. internal/translator/gemini/claude/gemini_claude_request_test.go +42 −0
  14. internal/translator/gemini/openai/responses/gemini_openai-responses_request.go +1 −16
  15. internal/util/gemini_schema.go +1 −1
  16. internal/watcher/diff/config_diff.go +5 −0
  17. internal/watcher/synthesizer/config.go +1 −1
  18. sdk/cliproxy/service.go +5 −2
config.example.yaml+3−0
@@ -233,6 +233,9 @@ nonstream-keepalive-interval: 0 · 232 unmodified lines
233# alias: "vertex-flash" # client-visible alias233# alias: "vertex-flash" # client-visible alias
234# - name: "gemini-2.5-pro"234# - name: "gemini-2.5-pro"
235# alias: "vertex-pro"235# alias: "vertex-pro"
236# excluded-models: # optional: models to exclude from listing
237# - "imagen-3.0-generate-002"
238# - "imagen-*"
236 239
237# Amp Integration240# Amp Integration
238# ampcode:241# ampcode:
internal/api/handlers/management/config_lists.go+11−6
@@ -516,12 +516,13 @@ func (h *Handler) PutVertexCompatKeys(c *gin.Context) { · 515 unmodified lines
516}516}
517func (h *Handler) PatchVertexCompatKey(c *gin.Context) {517func (h *Handler) PatchVertexCompatKey(c *gin.Context) {
518 type vertexCompatPatch struct {518 type vertexCompatPatch struct {
519 APIKey *string `json:"api-key"`519 APIKey *string `json:"api-key"`
520 Prefix *string `json:"prefix"`520 Prefix *string `json:"prefix"`
521 BaseURL *string `json:"base-url"`521 BaseURL *string `json:"base-url"`
522 ProxyURL *string `json:"proxy-url"`522 ProxyURL *string `json:"proxy-url"`
523 Headers *map[string]string `json:"headers"`523 Headers *map[string]string `json:"headers"`
524 Models *[]config.VertexCompatModel `json:"models"`524 Models *[]config.VertexCompatModel `json:"models"`
525 ExcludedModels *[]string `json:"excluded-models"`
525 }526 }
526 var body struct {527 var body struct {
527 Index *int `json:"index"`528 Index *int `json:"index"`
@@ -585,6 +586,9 @@ func (h *Handler) PatchVertexCompatKey(c *gin.Context) { · 57 unmodified lines
585 if body.Value.Models != nil {586 if body.Value.Models != nil {
586 entry.Models = append([]config.VertexCompatModel(nil), (*body.Value.Models)...)587 entry.Models = append([]config.VertexCompatModel(nil), (*body.Value.Models)...)
587 }588 }
589 if body.Value.ExcludedModels != nil {
590 entry.ExcludedModels = config.NormalizeExcludedModels(*body.Value.ExcludedModels)
591 }
588 normalizeVertexCompatKey(&entry)592 normalizeVertexCompatKey(&entry)
589 h.cfg.VertexCompatAPIKey[targetIndex] = entry593 h.cfg.VertexCompatAPIKey[targetIndex] = entry
590 h.cfg.SanitizeVertexCompatKeys()594 h.cfg.SanitizeVertexCompatKeys()
@@ -1029,6 +1033,7 @@ func normalizeVertexCompatKey(entry *config.VertexCompatKey) { · 438 unmodified lines
1029 entry.BaseURL = strings.TrimSpace(entry.BaseURL)1033 entry.BaseURL = strings.TrimSpace(entry.BaseURL)
1030 entry.ProxyURL = strings.TrimSpace(entry.ProxyURL)1034 entry.ProxyURL = strings.TrimSpace(entry.ProxyURL)
1031 entry.Headers = config.NormalizeHeaders(entry.Headers)1035 entry.Headers = config.NormalizeHeaders(entry.Headers)
1036 entry.ExcludedModels = config.NormalizeExcludedModels(entry.ExcludedModels)
1032 if len(entry.Models) == 0 {1037 if len(entry.Models) == 0 {
1033 return1038 return
1034 }1039 }
internal/config/vertex_compat.go+4−0
@@ -34,6 +34,9 @@ type VertexCompatKey struct { · 33 unmodified lines
34 34
35 // Models defines the model configurations including aliases for routing.35 // Models defines the model configurations including aliases for routing.
36 Models []VertexCompatModel `yaml:"models,omitempty" json:"models,omitempty"`36 Models []VertexCompatModel `yaml:"models,omitempty" json:"models,omitempty"`
37
38 // ExcludedModels lists model IDs that should be excluded for this provider.
39 ExcludedModels []string `yaml:"excluded-models,omitempty" json:"excluded-models,omitempty"`
37}40}
38 41
39func (k VertexCompatKey) GetAPIKey() string { return k.APIKey }42func (k VertexCompatKey) GetAPIKey() string { return k.APIKey }
@@ -74,6 +77,7 @@ func (cfg *Config) SanitizeVertexCompatKeys() { · 34 unmodified lines
74 }77 }
75 entry.ProxyURL = strings.TrimSpace(entry.ProxyURL)78 entry.ProxyURL = strings.TrimSpace(entry.ProxyURL)
76 entry.Headers = NormalizeHeaders(entry.Headers)79 entry.Headers = NormalizeHeaders(entry.Headers)
80 entry.ExcludedModels = NormalizeExcludedModels(entry.ExcludedModels)
77 81
78 // Sanitize models: remove entries without valid alias82 // Sanitize models: remove entries without valid alias
79 sanitizedModels := make([]VertexCompatModel, 0, len(entry.Models))83 sanitizedModels := make([]VertexCompatModel, 0, len(entry.Models))
internal/runtime/executor/antigravity_executor_buildrequest_test.go+4−0
@@ -59,6 +59,7 @@ func buildRequestBodyFromPayload(t *testing.T, modelName string) map[string]any · 58 unmodified lines
59 "properties": {59 "properties": {
60 "mode": {60 "mode": {
61 "type": "string",61 "type": "string",
62 "deprecated": true,
62 "enum": ["a", "b"],63 "enum": ["a", "b"],
63 "enumTitles": ["A", "B"]64 "enumTitles": ["A", "B"]
64 }65 }
@@ -156,4 +157,7 @@ func assertSchemaSanitizedAndPropertyPreserved(t *testing.T, params map[string]a · 91 unmodified lines
156 if _, ok := mode["enumTitles"]; ok {157 if _, ok := mode["enumTitles"]; ok {
157 t.Fatalf("enumTitles should be removed from nested schema")158 t.Fatalf("enumTitles should be removed from nested schema")
158 }159 }
160 if _, ok := mode["deprecated"]; ok {
161 t.Fatalf("deprecated should be removed from nested schema")
162 }
159}163}
internal/translator/antigravity/claude/antigravity_claude_request.go+34−4
@@ -431,6 +431,33 @@ func ConvertClaudeRequestToAntigravity(modelName string, inputRawJSON []byte, _ · 430 unmodified lines
431 out, _ = sjson.SetRaw(out, "request.tools", toolsJSON)431 out, _ = sjson.SetRaw(out, "request.tools", toolsJSON)
432 }432 }
433 433
434 // tool_choice
435 toolChoiceResult := gjson.GetBytes(rawJSON, "tool_choice")
436 if toolChoiceResult.Exists() {
437 toolChoiceType := ""
438 toolChoiceName := ""
439 if toolChoiceResult.IsObject() {
440 toolChoiceType = toolChoiceResult.Get("type").String()
441 toolChoiceName = toolChoiceResult.Get("name").String()
442 } else if toolChoiceResult.Type == gjson.String {
443 toolChoiceType = toolChoiceResult.String()
444 }
445
446 switch toolChoiceType {
447 case "auto":
448 out, _ = sjson.Set(out, "request.toolConfig.functionCallingConfig.mode", "AUTO")
449 case "none":
450 out, _ = sjson.Set(out, "request.toolConfig.functionCallingConfig.mode", "NONE")
451 case "any":
452 out, _ = sjson.Set(out, "request.toolConfig.functionCallingConfig.mode", "ANY")
453 case "tool":
454 out, _ = sjson.Set(out, "request.toolConfig.functionCallingConfig.mode", "ANY")
455 if toolChoiceName != "" {
456 out, _ = sjson.Set(out, "request.toolConfig.functionCallingConfig.allowedFunctionNames", []string{toolChoiceName})
457 }
458 }
459 }
460
434 // Map Anthropic thinking -> Gemini thinkingBudget/include_thoughts when type==enabled461 // Map Anthropic thinking -> Gemini thinkingBudget/include_thoughts when type==enabled
435 if t := gjson.GetBytes(rawJSON, "thinking"); enableThoughtTranslate && t.Exists() && t.IsObject() {462 if t := gjson.GetBytes(rawJSON, "thinking"); enableThoughtTranslate && t.Exists() && t.IsObject() {
436 switch t.Get("type").String() {463 switch t.Get("type").String() {
@@ -441,15 +468,18 @@ func ConvertClaudeRequestToAntigravity(modelName string, inputRawJSON []byte, _ · 4 unmodified lines
441 out, _ = sjson.Set(out, "request.generationConfig.thinkingConfig.includeThoughts", true)468 out, _ = sjson.Set(out, "request.generationConfig.thinkingConfig.includeThoughts", true)
442 }469 }
443 case "adaptive", "auto":470 case "adaptive", "auto":
444 // Adaptive/auto thinking:471 // For adaptive thinking:
445 // - If output_config.effort is present, pass it through as thinkingLevel.472 // - If output_config.effort is explicitly present, pass through as thinkingLevel.
446 // - Otherwise, default to "high".473 // - Otherwise, treat it as "enabled with target-model maximum" and emit high.
447 // ApplyThinking later normalizes/clamps and may convert level → budget per target model.474 // ApplyThinking handles clamping to target model's supported levels.
448 effort := ""475 effort := ""
449 if v := gjson.GetBytes(rawJSON, "output_config.effort"); v.Exists() && v.Type == gjson.String {476 if v := gjson.GetBytes(rawJSON, "output_config.effort"); v.Exists() && v.Type == gjson.String {
450 effort = strings.ToLower(strings.TrimSpace(v.String()))477 effort = strings.ToLower(strings.TrimSpace(v.String()))
451 }478 }
452 if effort != "" {479 if effort != "" {
480 if effort == "max" {
481 effort = "high"
482 }
453 out, _ = sjson.Set(out, "request.generationConfig.thinkingConfig.thinkingLevel", effort)483 out, _ = sjson.Set(out, "request.generationConfig.thinkingConfig.thinkingLevel", effort)
454 } else {484 } else {
455 out, _ = sjson.Set(out, "request.generationConfig.thinkingConfig.thinkingLevel", "high")485 out, _ = sjson.Set(out, "request.generationConfig.thinkingConfig.thinkingLevel", "high")
internal/translator/antigravity/claude/antigravity_claude_request_test.go+97−0
@@ -193,6 +193,42 @@ func TestConvertClaudeRequestToAntigravity_ToolDeclarations(t *testing.T) { · 192 unmodified lines
193 }193 }
194}194}
195 195
196func TestConvertClaudeRequestToAntigravity_ToolChoice_SpecificTool(t *testing.T) {
197 inputJSON := []byte(`{
198 "model": "gemini-3-flash-preview",
199 "messages": [
200 {
201 "role": "user",
202 "content": [
203 {"type": "text", "text": "hi"}
204 ]
205 }
206 ],
207 "tools": [
208 {
209 "name": "json",
210 "description": "A JSON tool",
211 "input_schema": {
212 "type": "object",
213 "properties": {}
214 }
215 }
216 ],
217 "tool_choice": {"type": "tool", "name": "json"}
218 }`)
219
220 output := ConvertClaudeRequestToAntigravity("gemini-3-flash-preview", inputJSON, false)
221 outputStr := string(output)
222
223 if got := gjson.Get(outputStr, "request.toolConfig.functionCallingConfig.mode").String(); got != "ANY" {
224 t.Fatalf("Expected toolConfig.functionCallingConfig.mode 'ANY', got '%s'", got)
225 }
226 allowed := gjson.Get(outputStr, "request.toolConfig.functionCallingConfig.allowedFunctionNames").Array()
227 if len(allowed) != 1 || allowed[0].String() != "json" {
228 t.Fatalf("Expected allowedFunctionNames ['json'], got %s", gjson.Get(outputStr, "request.toolConfig.functionCallingConfig.allowedFunctionNames").Raw)
229 }
230}
231
196func TestConvertClaudeRequestToAntigravity_ToolUse(t *testing.T) {232func TestConvertClaudeRequestToAntigravity_ToolUse(t *testing.T) {
197 inputJSON := []byte(`{233 inputJSON := []byte(`{
198 "model": "claude-3-5-sonnet-20240620",234 "model": "claude-3-5-sonnet-20240620",
@@ -1199,3 +1235,64 @@ func TestConvertClaudeRequestToAntigravity_ToolAndThinking_NoExistingSystem(t *t · 1000 unmodified lines
1199 t.Errorf("Interleaved thinking hint should be in created systemInstruction, got: %v", sysInstruction.Raw)1235 t.Errorf("Interleaved thinking hint should be in created systemInstruction, got: %v", sysInstruction.Raw)
1200 }1236 }
1201}1237}
1238
1239func TestConvertClaudeRequestToAntigravity_AdaptiveThinking_EffortLevels(t *testing.T) {
1240 tests := []struct {
1241 name string
1242 effort string
1243 expected string
1244 }{
1245 {"low", "low", "low"},
1246 {"medium", "medium", "medium"},
1247 {"high", "high", "high"},
1248 {"max", "max", "high"},
1249 }
1250
1251 for _, tt := range tests {
1252 tt := tt
1253 t.Run(tt.name, func(t *testing.T) {
1254 inputJSON := []byte(`{
1255 "model": "claude-opus-4-6-thinking",
1256 "messages": [{"role": "user", "content": [{"type": "text", "text": "Hello"}]}],
1257 "thinking": {"type": "adaptive"},
1258 "output_config": {"effort": "` + tt.effort + `"}
1259 }`)
1260
1261 output := ConvertClaudeRequestToAntigravity("claude-opus-4-6-thinking", inputJSON, false)
1262 outputStr := string(output)
1263
1264 thinkingConfig := gjson.Get(outputStr, "request.generationConfig.thinkingConfig")
1265 if !thinkingConfig.Exists() {
1266 t.Fatal("thinkingConfig should exist for adaptive thinking")
1267 }
1268 if thinkingConfig.Get("thinkingLevel").String() != tt.expected {
1269 t.Errorf("Expected thinkingLevel %q, got %q", tt.expected, thinkingConfig.Get("thinkingLevel").String())
1270 }
1271 if !thinkingConfig.Get("includeThoughts").Bool() {
1272 t.Error("includeThoughts should be true")
1273 }
1274 })
1275 }
1276}
1277
1278func TestConvertClaudeRequestToAntigravity_AdaptiveThinking_NoEffort(t *testing.T) {
1279 inputJSON := []byte(`{
1280 "model": "claude-opus-4-6-thinking",
1281 "messages": [{"role": "user", "content": [{"type": "text", "text": "Hello"}]}],
1282 "thinking": {"type": "adaptive"}
1283 }`)
1284
1285 output := ConvertClaudeRequestToAntigravity("claude-opus-4-6-thinking", inputJSON, false)
1286 outputStr := string(output)
1287
1288 thinkingConfig := gjson.Get(outputStr, "request.generationConfig.thinkingConfig")
1289 if !thinkingConfig.Exists() {
1290 t.Fatal("thinkingConfig should exist for adaptive thinking without effort")
1291 }
1292 if thinkingConfig.Get("thinkingLevel").String() != "high" {
1293 t.Errorf("Expected default thinkingLevel \"high\", got %q", thinkingConfig.Get("thinkingLevel").String())
1294 }
1295 if !thinkingConfig.Get("includeThoughts").Bool() {
1296 t.Error("includeThoughts should be true")
1297 }
1298}
internal/translator/codex/claude/codex_claude_request.go+2−0
@@ -255,6 +255,8 @@ func ConvertClaudeRequestToCodex(modelName string, inputRawJSON []byte, _ bool) · 254 unmodified lines
255 tool, _ = sjson.SetRaw(tool, "parameters", normalizeToolParameters(toolResult.Get("input_schema").Raw))255 tool, _ = sjson.SetRaw(tool, "parameters", normalizeToolParameters(toolResult.Get("input_schema").Raw))
256 tool, _ = sjson.Delete(tool, "input_schema")256 tool, _ = sjson.Delete(tool, "input_schema")
257 tool, _ = sjson.Delete(tool, "parameters.$schema")257 tool, _ = sjson.Delete(tool, "parameters.$schema")
258 tool, _ = sjson.Delete(tool, "cache_control")
259 tool, _ = sjson.Delete(tool, "defer_loading")
258 tool, _ = sjson.Set(tool, "strict", false)260 tool, _ = sjson.Set(tool, "strict", false)
259 template, _ = sjson.SetRaw(template, "tools.-1", tool)261 template, _ = sjson.SetRaw(template, "tools.-1", tool)
260 }262 }
internal/translator/codex/openai/chat-completions/codex_openai_response.go+5−0
@@ -74,8 +74,13 @@ func ConvertCodexResponseToOpenAI(_ context.Context, modelName string, originalR · 73 unmodified lines
74 }74 }
75 75
76 // Extract and set the model version.76 // Extract and set the model version.
77 cachedModel := (*param).(*ConvertCliToOpenAIParams).Model
77 if modelResult := gjson.GetBytes(rawJSON, "model"); modelResult.Exists() {78 if modelResult := gjson.GetBytes(rawJSON, "model"); modelResult.Exists() {
78 template, _ = sjson.Set(template, "model", modelResult.String())79 template, _ = sjson.Set(template, "model", modelResult.String())
80 } else if cachedModel != "" {
81 template, _ = sjson.Set(template, "model", cachedModel)
82 } else if modelName != "" {
83 template, _ = sjson.Set(template, "model", modelName)
79 }84 }
80 85
81 template, _ = sjson.Set(template, "created", (*param).(*ConvertCliToOpenAIParams).CreatedAt)86 template, _ = sjson.Set(template, "created", (*param).(*ConvertCliToOpenAIParams).CreatedAt)
internal/translator/codex/openai/chat-completions/codex_openai_response_test.go+47−0
@@ -0,0 +1,47 @@
1package chat_completions
2
3import (
4 "context"
5 "testing"
6
7 "github.com/tidwall/gjson"
8)
9
10func TestConvertCodexResponseToOpenAI_StreamSetsModelFromResponseCreated(t *testing.T) {
11 ctx := context.Background()
12 var param any
13
14 modelName := "gpt-5.3-codex"
15
16 out := ConvertCodexResponseToOpenAI(ctx, modelName, nil, nil, []byte(`data: {"type":"response.created","response":{"id":"resp_123","created_at":1700000000,"model":"gpt-5.3-codex"}}`), &param)
17 if len(out) != 0 {
18 t.Fatalf("expected no output for response.created, got %d chunks", len(out))
19 }
20
21 out = ConvertCodexResponseToOpenAI(ctx, modelName, nil, nil, []byte(`data: {"type":"response.output_text.delta","delta":"hello"}`), &param)
22 if len(out) != 1 {
23 t.Fatalf("expected 1 chunk, got %d", len(out))
24 }
25
26 gotModel := gjson.Get(out[0], "model").String()
27 if gotModel != modelName {
28 t.Fatalf("expected model %q, got %q", modelName, gotModel)
29 }
30}
31
32func TestConvertCodexResponseToOpenAI_FirstChunkUsesRequestModelName(t *testing.T) {
33 ctx := context.Background()
34 var param any
35
36 modelName := "gpt-5.3-codex"
37
38 out := ConvertCodexResponseToOpenAI(ctx, modelName, nil, nil, []byte(`data: {"type":"response.output_text.delta","delta":"hello"}`), &param)
39 if len(out) != 1 {
40 t.Fatalf("expected 1 chunk, got %d", len(out))
41 }
42
43 gotModel := gjson.Get(out[0], "model").String()
44 if gotModel != modelName {
45 t.Fatalf("expected model %q, got %q", modelName, gotModel)
46 }
47}
internal/translator/gemini-cli/claude/gemini-cli_claude_request.go+28−0
@@ -156,6 +156,7 @@ func ConvertClaudeRequestToCLI(modelName string, inputRawJSON []byte, _ bool) [] · 155 unmodified lines
156 tool, _ = sjson.Delete(tool, "input_examples")156 tool, _ = sjson.Delete(tool, "input_examples")
157 tool, _ = sjson.Delete(tool, "type")157 tool, _ = sjson.Delete(tool, "type")
158 tool, _ = sjson.Delete(tool, "cache_control")158 tool, _ = sjson.Delete(tool, "cache_control")
159 tool, _ = sjson.Delete(tool, "defer_loading")
159 if gjson.Valid(tool) && gjson.Parse(tool).IsObject() {160 if gjson.Valid(tool) && gjson.Parse(tool).IsObject() {
160 if !hasTools {161 if !hasTools {
161 out, _ = sjson.SetRaw(out, "request.tools", `[{"functionDeclarations":[]}]`)162 out, _ = sjson.SetRaw(out, "request.tools", `[{"functionDeclarations":[]}]`)
@@ -171,6 +172,33 @@ func ConvertClaudeRequestToCLI(modelName string, inputRawJSON []byte, _ bool) [] · 9 unmodified lines
171 }172 }
172 }173 }
173 174
175 // tool_choice
176 toolChoiceResult := gjson.GetBytes(rawJSON, "tool_choice")
177 if toolChoiceResult.Exists() {
178 toolChoiceType := ""
179 toolChoiceName := ""
180 if toolChoiceResult.IsObject() {
181 toolChoiceType = toolChoiceResult.Get("type").String()
182 toolChoiceName = toolChoiceResult.Get("name").String()
183 } else if toolChoiceResult.Type == gjson.String {
184 toolChoiceType = toolChoiceResult.String()
185 }
186
187 switch toolChoiceType {
188 case "auto":
189 out, _ = sjson.Set(out, "request.toolConfig.functionCallingConfig.mode", "AUTO")
190 case "none":
191 out, _ = sjson.Set(out, "request.toolConfig.functionCallingConfig.mode", "NONE")
192 case "any":
193 out, _ = sjson.Set(out, "request.toolConfig.functionCallingConfig.mode", "ANY")
194 case "tool":
195 out, _ = sjson.Set(out, "request.toolConfig.functionCallingConfig.mode", "ANY")
196 if toolChoiceName != "" {
197 out, _ = sjson.Set(out, "request.toolConfig.functionCallingConfig.allowedFunctionNames", []string{toolChoiceName})
198 }
199 }
200 }
201
174 // Map Anthropic thinking -> Gemini CLI thinkingConfig when enabled202 // Map Anthropic thinking -> Gemini CLI thinkingConfig when enabled
175 // Translator only does format conversion, ApplyThinking handles model capability validation.203 // Translator only does format conversion, ApplyThinking handles model capability validation.
176 if t := gjson.GetBytes(rawJSON, "thinking"); t.Exists() && t.IsObject() {204 if t := gjson.GetBytes(rawJSON, "thinking"); t.Exists() && t.IsObject() {
internal/translator/gemini-cli/claude/gemini-cli_claude_request_test.go+42−0
@@ -0,0 +1,42 @@
1package claude
2
3import (
4 "testing"
5
6 "github.com/tidwall/gjson"
7)
8
9func TestConvertClaudeRequestToCLI_ToolChoice_SpecificTool(t *testing.T) {
10 inputJSON := []byte(`{
11 "model": "gemini-3-flash-preview",
12 "messages": [
13 {
14 "role": "user",
15 "content": [
16 {"type": "text", "text": "hi"}
17 ]
18 }
19 ],
20 "tools": [
21 {
22 "name": "json",
23 "description": "A JSON tool",
24 "input_schema": {
25 "type": "object",
26 "properties": {}
27 }
28 }
29 ],
30 "tool_choice": {"type": "tool", "name": "json"}
31 }`)
32
33 output := ConvertClaudeRequestToCLI("gemini-3-flash-preview", inputJSON, false)
34
35 if got := gjson.GetBytes(output, "request.toolConfig.functionCallingConfig.mode").String(); got != "ANY" {
36 t.Fatalf("Expected request.toolConfig.functionCallingConfig.mode 'ANY', got '%s'", got)
37 }
38 allowed := gjson.GetBytes(output, "request.toolConfig.functionCallingConfig.allowedFunctionNames").Array()
39 if len(allowed) != 1 || allowed[0].String() != "json" {
40 t.Fatalf("Expected allowedFunctionNames ['json'], got %s", gjson.GetBytes(output, "request.toolConfig.functionCallingConfig.allowedFunctionNames").Raw)
41 }
42}
internal/translator/gemini/claude/gemini_claude_request.go+28−0
@@ -137,6 +137,7 @@ func ConvertClaudeRequestToGemini(modelName string, inputRawJSON []byte, _ bool) · 136 unmodified lines
137 tool, _ = sjson.Delete(tool, "input_examples")137 tool, _ = sjson.Delete(tool, "input_examples")
138 tool, _ = sjson.Delete(tool, "type")138 tool, _ = sjson.Delete(tool, "type")
139 tool, _ = sjson.Delete(tool, "cache_control")139 tool, _ = sjson.Delete(tool, "cache_control")
140 tool, _ = sjson.Delete(tool, "defer_loading")
140 if gjson.Valid(tool) && gjson.Parse(tool).IsObject() {141 if gjson.Valid(tool) && gjson.Parse(tool).IsObject() {
141 if !hasTools {142 if !hasTools {
142 out, _ = sjson.SetRaw(out, "tools", `[{"functionDeclarations":[]}]`)143 out, _ = sjson.SetRaw(out, "tools", `[{"functionDeclarations":[]}]`)
@@ -152,6 +153,33 @@ func ConvertClaudeRequestToGemini(modelName string, inputRawJSON []byte, _ bool) · 9 unmodified lines
152 }153 }
153 }154 }
154 155
156 // tool_choice
157 toolChoiceResult := gjson.GetBytes(rawJSON, "tool_choice")
158 if toolChoiceResult.Exists() {
159 toolChoiceType := ""
160 toolChoiceName := ""
161 if toolChoiceResult.IsObject() {
162 toolChoiceType = toolChoiceResult.Get("type").String()
163 toolChoiceName = toolChoiceResult.Get("name").String()
164 } else if toolChoiceResult.Type == gjson.String {
165 toolChoiceType = toolChoiceResult.String()
166 }
167
168 switch toolChoiceType {
169 case "auto":
170 out, _ = sjson.Set(out, "toolConfig.functionCallingConfig.mode", "AUTO")
171 case "none":
172 out, _ = sjson.Set(out, "toolConfig.functionCallingConfig.mode", "NONE")
173 case "any":
174 out, _ = sjson.Set(out, "toolConfig.functionCallingConfig.mode", "ANY")
175 case "tool":
176 out, _ = sjson.Set(out, "toolConfig.functionCallingConfig.mode", "ANY")
177 if toolChoiceName != "" {
178 out, _ = sjson.Set(out, "toolConfig.functionCallingConfig.allowedFunctionNames", []string{toolChoiceName})
179 }
180 }
181 }
182
155 // Map Anthropic thinking -> Gemini thinking config when enabled183 // Map Anthropic thinking -> Gemini thinking config when enabled
156 // Translator only does format conversion, ApplyThinking handles model capability validation.184 // Translator only does format conversion, ApplyThinking handles model capability validation.
157 if t := gjson.GetBytes(rawJSON, "thinking"); t.Exists() && t.IsObject() {185 if t := gjson.GetBytes(rawJSON, "thinking"); t.Exists() && t.IsObject() {
internal/translator/gemini/claude/gemini_claude_request_test.go+42−0
@@ -0,0 +1,42 @@
1package claude
2
3import (
4 "testing"
5
6 "github.com/tidwall/gjson"
7)
8
9func TestConvertClaudeRequestToGemini_ToolChoice_SpecificTool(t *testing.T) {
10 inputJSON := []byte(`{
11 "model": "gemini-3-flash-preview",
12 "messages": [
13 {
14 "role": "user",
15 "content": [
16 {"type": "text", "text": "hi"}
17 ]
18 }
19 ],
20 "tools": [
21 {
22 "name": "json",
23 "description": "A JSON tool",
24 "input_schema": {
25 "type": "object",
26 "properties": {}
27 }
28 }
29 ],
30 "tool_choice": {"type": "tool", "name": "json"}
31 }`)
32
33 output := ConvertClaudeRequestToGemini("gemini-3-flash-preview", inputJSON, false)
34
35 if got := gjson.GetBytes(output, "toolConfig.functionCallingConfig.mode").String(); got != "ANY" {
36 t.Fatalf("Expected toolConfig.functionCallingConfig.mode 'ANY', got '%s'", got)
37 }
38 allowed := gjson.GetBytes(output, "toolConfig.functionCallingConfig.allowedFunctionNames").Array()
39 if len(allowed) != 1 || allowed[0].String() != "json" {
40 t.Fatalf("Expected allowedFunctionNames ['json'], got %s", gjson.GetBytes(output, "toolConfig.functionCallingConfig.allowedFunctionNames").Raw)
41 }
42}
internal/translator/gemini/openai/responses/gemini_openai-responses_request.go+1−16
@@ -354,22 +354,7 @@ func ConvertOpenAIResponsesRequestToGemini(modelName string, inputRawJSON []byte · 353 unmodified lines
354 funcDecl, _ = sjson.Set(funcDecl, "description", desc.String())354 funcDecl, _ = sjson.Set(funcDecl, "description", desc.String())
355 }355 }
356 if params := tool.Get("parameters"); params.Exists() {356 if params := tool.Get("parameters"); params.Exists() {
357 // Convert parameter types from OpenAI format to Gemini format357 funcDecl, _ = sjson.SetRaw(funcDecl, "parametersJsonSchema", params.Raw)
358 cleaned := params.Raw
359 // Convert type values to uppercase for Gemini
360 paramsResult := gjson.Parse(cleaned)
361 if properties := paramsResult.Get("properties"); properties.Exists() {
362 properties.ForEach(func(key, value gjson.Result) bool {
363 if propType := value.Get("type"); propType.Exists() {
364 upperType := strings.ToUpper(propType.String())
365 cleaned, _ = sjson.Set(cleaned, "properties."+key.String()+".type", upperType)
366 }
367 return true
368 })
369 }
370 // Set the overall type to OBJECT
371 cleaned, _ = sjson.Set(cleaned, "type", "OBJECT")
372 funcDecl, _ = sjson.SetRaw(funcDecl, "parametersJsonSchema", cleaned)
373 }358 }
374 359
375 geminiTools, _ = sjson.SetRaw(geminiTools, "0.functionDeclarations.-1", funcDecl)360 geminiTools, _ = sjson.SetRaw(geminiTools, "0.functionDeclarations.-1", funcDecl)
internal/util/gemini_schema.go+1−1
@@ -430,7 +430,7 @@ func removeUnsupportedKeywords(jsonStr string) string { · 429 unmodified lines
430 keywords := append(unsupportedConstraints,430 keywords := append(unsupportedConstraints,
431 "$schema", "$defs", "definitions", "const", "$ref", "$id", "additionalProperties",431 "$schema", "$defs", "definitions", "const", "$ref", "$id", "additionalProperties",
432 "propertyNames", "patternProperties", // Gemini doesn't support these schema keywords432 "propertyNames", "patternProperties", // Gemini doesn't support these schema keywords
433 "enumTitles", "prefill", // Claude/OpenCode schema metadata fields unsupported by Gemini433 "enumTitles", "prefill", "deprecated", // Schema metadata fields unsupported by Gemini
434 )434 )
435 435
436 deletePaths := make([]string, 0)436 deletePaths := make([]string, 0)
internal/watcher/diff/config_diff.go+5−0
@@ -304,6 +304,11 @@ func BuildConfigChangeDetails(oldCfg, newCfg *config.Config) []string { · 303 unmodified lines
304 if oldModels.hash != newModels.hash {304 if oldModels.hash != newModels.hash {
305 changes = append(changes, fmt.Sprintf("vertex[%d].models: updated (%d -> %d entries)", i, oldModels.count, newModels.count))305 changes = append(changes, fmt.Sprintf("vertex[%d].models: updated (%d -> %d entries)", i, oldModels.count, newModels.count))
306 }306 }
307 oldExcluded := SummarizeExcludedModels(o.ExcludedModels)
308 newExcluded := SummarizeExcludedModels(n.ExcludedModels)
309 if oldExcluded.hash != newExcluded.hash {
310 changes = append(changes, fmt.Sprintf("vertex[%d].excluded-models: updated (%d -> %d entries)", i, oldExcluded.count, newExcluded.count))
311 }
307 if !equalStringMap(o.Headers, n.Headers) {312 if !equalStringMap(o.Headers, n.Headers) {
308 changes = append(changes, fmt.Sprintf("vertex[%d].headers: updated", i))313 changes = append(changes, fmt.Sprintf("vertex[%d].headers: updated", i))
309 }314 }
internal/watcher/synthesizer/config.go+1−1
@@ -319,7 +319,7 @@ func (s *ConfigSynthesizer) synthesizeVertexCompat(ctx *SynthesisContext) []*cor · 318 unmodified lines
319 CreatedAt: now,319 CreatedAt: now,
320 UpdatedAt: now,320 UpdatedAt: now,
321 }321 }
322 ApplyAuthExcludedModelsMeta(a, cfg, nil, "apikey")322 ApplyAuthExcludedModelsMeta(a, cfg, compat.ExcludedModels, "apikey")
323 out = append(out, a)323 out = append(out, a)
324 }324 }
325 return out325 return out
sdk/cliproxy/service.go+5−2
@@ -820,10 +820,13 @@ func (s *Service) registerModelsForAuth(a *coreauth.Auth) { · 819 unmodified lines
820 case "vertex":820 case "vertex":
821 // Vertex AI Gemini supports the same model identifiers as Gemini.821 // Vertex AI Gemini supports the same model identifiers as Gemini.
822 models = registry.GetGeminiVertexModels()822 models = registry.GetGeminiVertexModels()
823 if authKind == "apikey" {823 if entry := s.resolveConfigVertexCompatKey(a); entry != nil {
824 if entry := s.resolveConfigVertexCompatKey(a); entry != nil && len(entry.Models) > 0 {824 if len(entry.Models) > 0 {
825 models = buildVertexCompatConfigModels(entry)825 models = buildVertexCompatConfigModels(entry)
826 }826 }
827 if authKind == "apikey" {
828 excluded = entry.ExcludedModels
829 }
827 }830 }
828 models = applyExcludedModels(models, excluded)831 models = applyExcludedModels(models, excluded)
829 case "gemini-cli":832 case "gemini-cli":

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t