From 2615f489d6a246cb2747e2627b35f9d1d622f06a Mon Sep 17 00:00:00 2001 From: Finn Phillips Date: Tue, 10 Feb 2026 09:29:09 +0700 Subject: [PATCH 1/7] fix(translator): remove broken type uppercasing in OpenAI Responses-to-Gemini translator The `ConvertOpenAIResponsesRequestToGemini` function had code that attempted to uppercase JSON Schema type values (e.g. "string" -> "STRING") for Gemini compatibility. This broke nullable types because when `type` is a JSON array like `["string", "null"]`: 1. `gjson.Result.String()` returns the raw JSON text `["string","null"]` 2. `strings.ToUpper()` produces `["STRING","NULL"]` 3. `sjson.Set()` stores it as a JSON **string** `"[\"STRING\",\"NULL\"]"` instead of a JSON array 4. The downstream `CleanJSONSchemaForGemini()` / `flattenTypeArrays()` cannot detect it (since `IsArray()` returns false on a string) 5. Gemini/Antigravity API rejects it with: `400 Invalid value at '...type' (Type), "["STRING","NULL"]"` This was confirmed and tested with Droid Factory (Antigravity) Gemini models where Claude Code sends tool schemas with nullable parameters. The fix removes the uppercasing logic entirely and passes the raw schema through to `parametersJsonSchema`. This is safe because: - Antigravity executor already runs `CleanJSONSchemaForGemini()` which properly handles type arrays, nullable fields, and all schema cleanup - Gemini/Vertex executors use `parametersJsonSchema` which accepts raw JSON Schema directly (no uppercasing needed) - The uppercasing code also only iterated top-level properties, missing nested schemas entirely Co-Authored-By: Claude Opus 4.6 --- .../gemini_openai-responses_request.go | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/internal/translator/gemini/openai/responses/gemini_openai-responses_request.go b/internal/translator/gemini/openai/responses/gemini_openai-responses_request.go index 1ddb1f36..e0881e52 100644 --- a/internal/translator/gemini/openai/responses/gemini_openai-responses_request.go +++ b/internal/translator/gemini/openai/responses/gemini_openai-responses_request.go @@ -330,22 +330,7 @@ func ConvertOpenAIResponsesRequestToGemini(modelName string, inputRawJSON []byte funcDecl, _ = sjson.Set(funcDecl, "description", desc.String()) } if params := tool.Get("parameters"); params.Exists() { - // Convert parameter types from OpenAI format to Gemini format - cleaned := params.Raw - // Convert type values to uppercase for Gemini - paramsResult := gjson.Parse(cleaned) - if properties := paramsResult.Get("properties"); properties.Exists() { - properties.ForEach(func(key, value gjson.Result) bool { - if propType := value.Get("type"); propType.Exists() { - upperType := strings.ToUpper(propType.String()) - cleaned, _ = sjson.Set(cleaned, "properties."+key.String()+".type", upperType) - } - return true - }) - } - // Set the overall type to OBJECT - cleaned, _ = sjson.Set(cleaned, "type", "OBJECT") - funcDecl, _ = sjson.SetRaw(funcDecl, "parametersJsonSchema", cleaned) + funcDecl, _ = sjson.SetRaw(funcDecl, "parametersJsonSchema", params.Raw) } geminiTools, _ = sjson.SetRaw(geminiTools, "0.functionDeclarations.-1", funcDecl) From 527e4b7f26f8fa089156fad227d780631e12fe21 Mon Sep 17 00:00:00 2001 From: sususu98 Date: Wed, 4 Mar 2026 10:04:58 +0800 Subject: [PATCH 2/7] fix(antigravity): pass through adaptive thinking effort level instead of always mapping to high --- .../claude/antigravity_claude_request.go | 19 +++++- .../claude/antigravity_claude_request_test.go | 61 +++++++++++++++++++ 2 files changed, 77 insertions(+), 3 deletions(-) diff --git a/internal/translator/antigravity/claude/antigravity_claude_request.go b/internal/translator/antigravity/claude/antigravity_claude_request.go index c4e07b6a..e6c74bdd 100644 --- a/internal/translator/antigravity/claude/antigravity_claude_request.go +++ b/internal/translator/antigravity/claude/antigravity_claude_request.go @@ -441,9 +441,22 @@ func ConvertClaudeRequestToAntigravity(modelName string, inputRawJSON []byte, _ out, _ = sjson.Set(out, "request.generationConfig.thinkingConfig.includeThoughts", true) } case "adaptive", "auto": - // Keep adaptive/auto as a high level sentinel; ApplyThinking resolves it - // to model-specific max capability. - out, _ = sjson.Set(out, "request.generationConfig.thinkingConfig.thinkingLevel", "high") + // For adaptive thinking: + // - If output_config.effort is explicitly present, pass through as thinkingLevel. + // - Otherwise, treat it as "enabled with target-model maximum" and emit high. + // ApplyThinking handles clamping to target model's supported levels. + effort := "" + if v := gjson.GetBytes(rawJSON, "output_config.effort"); v.Exists() && v.Type == gjson.String { + effort = strings.ToLower(strings.TrimSpace(v.String())) + } + if effort != "" { + if effort == "max" { + effort = "high" + } + out, _ = sjson.Set(out, "request.generationConfig.thinkingConfig.thinkingLevel", effort) + } else { + out, _ = sjson.Set(out, "request.generationConfig.thinkingConfig.thinkingLevel", "high") + } out, _ = sjson.Set(out, "request.generationConfig.thinkingConfig.includeThoughts", true) } } diff --git a/internal/translator/antigravity/claude/antigravity_claude_request_test.go b/internal/translator/antigravity/claude/antigravity_claude_request_test.go index 865db668..53a24339 100644 --- a/internal/translator/antigravity/claude/antigravity_claude_request_test.go +++ b/internal/translator/antigravity/claude/antigravity_claude_request_test.go @@ -1199,3 +1199,64 @@ func TestConvertClaudeRequestToAntigravity_ToolAndThinking_NoExistingSystem(t *t t.Errorf("Interleaved thinking hint should be in created systemInstruction, got: %v", sysInstruction.Raw) } } + +func TestConvertClaudeRequestToAntigravity_AdaptiveThinking_EffortLevels(t *testing.T) { + tests := []struct { + name string + effort string + expected string + }{ + {"low", "low", "low"}, + {"medium", "medium", "medium"}, + {"high", "high", "high"}, + {"max", "max", "high"}, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + inputJSON := []byte(`{ + "model": "claude-opus-4-6-thinking", + "messages": [{"role": "user", "content": [{"type": "text", "text": "Hello"}]}], + "thinking": {"type": "adaptive"}, + "output_config": {"effort": "` + tt.effort + `"} + }`) + + output := ConvertClaudeRequestToAntigravity("claude-opus-4-6-thinking", inputJSON, false) + outputStr := string(output) + + thinkingConfig := gjson.Get(outputStr, "request.generationConfig.thinkingConfig") + if !thinkingConfig.Exists() { + t.Fatal("thinkingConfig should exist for adaptive thinking") + } + if thinkingConfig.Get("thinkingLevel").String() != tt.expected { + t.Errorf("Expected thinkingLevel %q, got %q", tt.expected, thinkingConfig.Get("thinkingLevel").String()) + } + if !thinkingConfig.Get("includeThoughts").Bool() { + t.Error("includeThoughts should be true") + } + }) + } +} + +func TestConvertClaudeRequestToAntigravity_AdaptiveThinking_NoEffort(t *testing.T) { + inputJSON := []byte(`{ + "model": "claude-opus-4-6-thinking", + "messages": [{"role": "user", "content": [{"type": "text", "text": "Hello"}]}], + "thinking": {"type": "adaptive"} + }`) + + output := ConvertClaudeRequestToAntigravity("claude-opus-4-6-thinking", inputJSON, false) + outputStr := string(output) + + thinkingConfig := gjson.Get(outputStr, "request.generationConfig.thinkingConfig") + if !thinkingConfig.Exists() { + t.Fatal("thinkingConfig should exist for adaptive thinking without effort") + } + if thinkingConfig.Get("thinkingLevel").String() != "high" { + t.Errorf("Expected default thinkingLevel \"high\", got %q", thinkingConfig.Get("thinkingLevel").String()) + } + if !thinkingConfig.Get("includeThoughts").Bool() { + t.Error("includeThoughts should be true") + } +} From d26ad8224d6e3d0af2e912d0dbd9d996bfe3769c Mon Sep 17 00:00:00 2001 From: sususu98 Date: Wed, 4 Mar 2026 14:21:30 +0800 Subject: [PATCH 3/7] fix(translator): strip defer_loading from Claude tool declarations in Codex and Gemini translators Claude's Tool Search feature (advanced-tool-use-2025-11-20 beta) adds defer_loading field to tool definitions. When proxying Claude requests to Codex or Gemini, this unknown field causes 400 errors upstream. Strip defer_loading (and cache_control where missing) in all three Claude-to-upstream translation paths: - codex/claude: defer_loading + cache_control - gemini-cli/claude: defer_loading - gemini/claude: defer_loading Fixes #1725, Fixes #1375 --- internal/translator/codex/claude/codex_claude_request.go | 2 ++ .../translator/gemini-cli/claude/gemini-cli_claude_request.go | 1 + internal/translator/gemini/claude/gemini_claude_request.go | 1 + 3 files changed, 4 insertions(+) diff --git a/internal/translator/codex/claude/codex_claude_request.go b/internal/translator/codex/claude/codex_claude_request.go index e3ddd0b8..6373e693 100644 --- a/internal/translator/codex/claude/codex_claude_request.go +++ b/internal/translator/codex/claude/codex_claude_request.go @@ -255,6 +255,8 @@ func ConvertClaudeRequestToCodex(modelName string, inputRawJSON []byte, _ bool) tool, _ = sjson.SetRaw(tool, "parameters", normalizeToolParameters(toolResult.Get("input_schema").Raw)) tool, _ = sjson.Delete(tool, "input_schema") tool, _ = sjson.Delete(tool, "parameters.$schema") + tool, _ = sjson.Delete(tool, "cache_control") + tool, _ = sjson.Delete(tool, "defer_loading") tool, _ = sjson.Set(tool, "strict", false) template, _ = sjson.SetRaw(template, "tools.-1", tool) } diff --git a/internal/translator/gemini-cli/claude/gemini-cli_claude_request.go b/internal/translator/gemini-cli/claude/gemini-cli_claude_request.go index 3f8921dc..076e09db 100644 --- a/internal/translator/gemini-cli/claude/gemini-cli_claude_request.go +++ b/internal/translator/gemini-cli/claude/gemini-cli_claude_request.go @@ -156,6 +156,7 @@ func ConvertClaudeRequestToCLI(modelName string, inputRawJSON []byte, _ bool) [] tool, _ = sjson.Delete(tool, "input_examples") tool, _ = sjson.Delete(tool, "type") tool, _ = sjson.Delete(tool, "cache_control") + tool, _ = sjson.Delete(tool, "defer_loading") if gjson.Valid(tool) && gjson.Parse(tool).IsObject() { if !hasTools { out, _ = sjson.SetRaw(out, "request.tools", `[{"functionDeclarations":[]}]`) diff --git a/internal/translator/gemini/claude/gemini_claude_request.go b/internal/translator/gemini/claude/gemini_claude_request.go index 172884bd..0e367c0d 100644 --- a/internal/translator/gemini/claude/gemini_claude_request.go +++ b/internal/translator/gemini/claude/gemini_claude_request.go @@ -137,6 +137,7 @@ func ConvertClaudeRequestToGemini(modelName string, inputRawJSON []byte, _ bool) tool, _ = sjson.Delete(tool, "input_examples") tool, _ = sjson.Delete(tool, "type") tool, _ = sjson.Delete(tool, "cache_control") + tool, _ = sjson.Delete(tool, "defer_loading") if gjson.Valid(tool) && gjson.Parse(tool).IsObject() { if !hasTools { out, _ = sjson.SetRaw(out, "tools", `[{"functionDeclarations":[]}]`) From 48ffc4dee745bf291e8d40cf709091655f1e3e7b Mon Sep 17 00:00:00 2001 From: hkfires <10558748+hkfires@users.noreply.github.com> Date: Wed, 4 Mar 2026 18:47:42 +0800 Subject: [PATCH 4/7] feat(config): support excluded vertex models in config --- config.example.yaml | 3 +++ .../api/handlers/management/config_lists.go | 17 +++++++++++------ internal/config/vertex_compat.go | 4 ++++ internal/watcher/diff/config_diff.go | 5 +++++ internal/watcher/synthesizer/config.go | 2 +- sdk/cliproxy/service.go | 7 +++++-- 6 files changed, 29 insertions(+), 9 deletions(-) diff --git a/config.example.yaml b/config.example.yaml index 7a3265b4..40bb8721 100644 --- a/config.example.yaml +++ b/config.example.yaml @@ -201,6 +201,9 @@ nonstream-keepalive-interval: 0 # alias: "vertex-flash" # client-visible alias # - name: "gemini-2.5-pro" # alias: "vertex-pro" +# excluded-models: # optional: models to exclude from listing +# - "imagen-3.0-generate-002" +# - "imagen-*" # Amp Integration # ampcode: diff --git a/internal/api/handlers/management/config_lists.go b/internal/api/handlers/management/config_lists.go index 66e89992..503179c1 100644 --- a/internal/api/handlers/management/config_lists.go +++ b/internal/api/handlers/management/config_lists.go @@ -516,12 +516,13 @@ func (h *Handler) PutVertexCompatKeys(c *gin.Context) { } func (h *Handler) PatchVertexCompatKey(c *gin.Context) { type vertexCompatPatch struct { - APIKey *string `json:"api-key"` - Prefix *string `json:"prefix"` - BaseURL *string `json:"base-url"` - ProxyURL *string `json:"proxy-url"` - Headers *map[string]string `json:"headers"` - Models *[]config.VertexCompatModel `json:"models"` + APIKey *string `json:"api-key"` + Prefix *string `json:"prefix"` + BaseURL *string `json:"base-url"` + ProxyURL *string `json:"proxy-url"` + Headers *map[string]string `json:"headers"` + Models *[]config.VertexCompatModel `json:"models"` + ExcludedModels *[]string `json:"excluded-models"` } var body struct { Index *int `json:"index"` @@ -585,6 +586,9 @@ func (h *Handler) PatchVertexCompatKey(c *gin.Context) { if body.Value.Models != nil { entry.Models = append([]config.VertexCompatModel(nil), (*body.Value.Models)...) } + if body.Value.ExcludedModels != nil { + entry.ExcludedModels = config.NormalizeExcludedModels(*body.Value.ExcludedModels) + } normalizeVertexCompatKey(&entry) h.cfg.VertexCompatAPIKey[targetIndex] = entry h.cfg.SanitizeVertexCompatKeys() @@ -1025,6 +1029,7 @@ func normalizeVertexCompatKey(entry *config.VertexCompatKey) { entry.BaseURL = strings.TrimSpace(entry.BaseURL) entry.ProxyURL = strings.TrimSpace(entry.ProxyURL) entry.Headers = config.NormalizeHeaders(entry.Headers) + entry.ExcludedModels = config.NormalizeExcludedModels(entry.ExcludedModels) if len(entry.Models) == 0 { return } diff --git a/internal/config/vertex_compat.go b/internal/config/vertex_compat.go index 786c5318..5f6c7c88 100644 --- a/internal/config/vertex_compat.go +++ b/internal/config/vertex_compat.go @@ -34,6 +34,9 @@ type VertexCompatKey struct { // Models defines the model configurations including aliases for routing. Models []VertexCompatModel `yaml:"models,omitempty" json:"models,omitempty"` + + // ExcludedModels lists model IDs that should be excluded for this provider. + ExcludedModels []string `yaml:"excluded-models,omitempty" json:"excluded-models,omitempty"` } func (k VertexCompatKey) GetAPIKey() string { return k.APIKey } @@ -74,6 +77,7 @@ func (cfg *Config) SanitizeVertexCompatKeys() { } entry.ProxyURL = strings.TrimSpace(entry.ProxyURL) entry.Headers = NormalizeHeaders(entry.Headers) + entry.ExcludedModels = NormalizeExcludedModels(entry.ExcludedModels) // Sanitize models: remove entries without valid alias sanitizedModels := make([]VertexCompatModel, 0, len(entry.Models)) diff --git a/internal/watcher/diff/config_diff.go b/internal/watcher/diff/config_diff.go index b7d537da..7997f04e 100644 --- a/internal/watcher/diff/config_diff.go +++ b/internal/watcher/diff/config_diff.go @@ -304,6 +304,11 @@ func BuildConfigChangeDetails(oldCfg, newCfg *config.Config) []string { if oldModels.hash != newModels.hash { changes = append(changes, fmt.Sprintf("vertex[%d].models: updated (%d -> %d entries)", i, oldModels.count, newModels.count)) } + oldExcluded := SummarizeExcludedModels(o.ExcludedModels) + newExcluded := SummarizeExcludedModels(n.ExcludedModels) + if oldExcluded.hash != newExcluded.hash { + changes = append(changes, fmt.Sprintf("vertex[%d].excluded-models: updated (%d -> %d entries)", i, oldExcluded.count, newExcluded.count)) + } if !equalStringMap(o.Headers, n.Headers) { changes = append(changes, fmt.Sprintf("vertex[%d].headers: updated", i)) } diff --git a/internal/watcher/synthesizer/config.go b/internal/watcher/synthesizer/config.go index 69194efc..52ae9a48 100644 --- a/internal/watcher/synthesizer/config.go +++ b/internal/watcher/synthesizer/config.go @@ -315,7 +315,7 @@ func (s *ConfigSynthesizer) synthesizeVertexCompat(ctx *SynthesisContext) []*cor CreatedAt: now, UpdatedAt: now, } - ApplyAuthExcludedModelsMeta(a, cfg, nil, "apikey") + ApplyAuthExcludedModelsMeta(a, cfg, compat.ExcludedModels, "apikey") out = append(out, a) } return out diff --git a/sdk/cliproxy/service.go b/sdk/cliproxy/service.go index 9952e7b2..6124f8b1 100644 --- a/sdk/cliproxy/service.go +++ b/sdk/cliproxy/service.go @@ -791,10 +791,13 @@ func (s *Service) registerModelsForAuth(a *coreauth.Auth) { case "vertex": // Vertex AI Gemini supports the same model identifiers as Gemini. models = registry.GetGeminiVertexModels() - if authKind == "apikey" { - if entry := s.resolveConfigVertexCompatKey(a); entry != nil && len(entry.Models) > 0 { + if entry := s.resolveConfigVertexCompatKey(a); entry != nil { + if len(entry.Models) > 0 { models = buildVertexCompatConfigModels(entry) } + if authKind == "apikey" { + excluded = entry.ExcludedModels + } } models = applyExcludedModels(models, excluded) case "gemini-cli": From 4bbeb92e9aff5eeb7ec61986878e233bffd8091a Mon Sep 17 00:00:00 2001 From: Luis Pater Date: Wed, 4 Mar 2026 22:28:26 +0800 Subject: [PATCH 5/7] Fixed: #1135 **test(translator): add tests for `tool_choice` handling in Claude request conversions** --- .../claude/antigravity_claude_request.go | 27 ++++++++++++ .../claude/antigravity_claude_request_test.go | 36 ++++++++++++++++ .../claude/gemini-cli_claude_request.go | 27 ++++++++++++ .../claude/gemini-cli_claude_request_test.go | 42 +++++++++++++++++++ .../gemini/claude/gemini_claude_request.go | 27 ++++++++++++ .../claude/gemini_claude_request_test.go | 42 +++++++++++++++++++ 6 files changed, 201 insertions(+) create mode 100644 internal/translator/gemini-cli/claude/gemini-cli_claude_request_test.go create mode 100644 internal/translator/gemini/claude/gemini_claude_request_test.go diff --git a/internal/translator/antigravity/claude/antigravity_claude_request.go b/internal/translator/antigravity/claude/antigravity_claude_request.go index e6c74bdd..8c1a38c5 100644 --- a/internal/translator/antigravity/claude/antigravity_claude_request.go +++ b/internal/translator/antigravity/claude/antigravity_claude_request.go @@ -431,6 +431,33 @@ func ConvertClaudeRequestToAntigravity(modelName string, inputRawJSON []byte, _ out, _ = sjson.SetRaw(out, "request.tools", toolsJSON) } + // tool_choice + toolChoiceResult := gjson.GetBytes(rawJSON, "tool_choice") + if toolChoiceResult.Exists() { + toolChoiceType := "" + toolChoiceName := "" + if toolChoiceResult.IsObject() { + toolChoiceType = toolChoiceResult.Get("type").String() + toolChoiceName = toolChoiceResult.Get("name").String() + } else if toolChoiceResult.Type == gjson.String { + toolChoiceType = toolChoiceResult.String() + } + + switch toolChoiceType { + case "auto": + out, _ = sjson.Set(out, "request.toolConfig.functionCallingConfig.mode", "AUTO") + case "none": + out, _ = sjson.Set(out, "request.toolConfig.functionCallingConfig.mode", "NONE") + case "any": + out, _ = sjson.Set(out, "request.toolConfig.functionCallingConfig.mode", "ANY") + case "tool": + out, _ = sjson.Set(out, "request.toolConfig.functionCallingConfig.mode", "ANY") + if toolChoiceName != "" { + out, _ = sjson.Set(out, "request.toolConfig.functionCallingConfig.allowedFunctionNames", []string{toolChoiceName}) + } + } + } + // Map Anthropic thinking -> Gemini thinkingBudget/include_thoughts when type==enabled if t := gjson.GetBytes(rawJSON, "thinking"); enableThoughtTranslate && t.Exists() && t.IsObject() { switch t.Get("type").String() { diff --git a/internal/translator/antigravity/claude/antigravity_claude_request_test.go b/internal/translator/antigravity/claude/antigravity_claude_request_test.go index 53a24339..39dc493d 100644 --- a/internal/translator/antigravity/claude/antigravity_claude_request_test.go +++ b/internal/translator/antigravity/claude/antigravity_claude_request_test.go @@ -193,6 +193,42 @@ func TestConvertClaudeRequestToAntigravity_ToolDeclarations(t *testing.T) { } } +func TestConvertClaudeRequestToAntigravity_ToolChoice_SpecificTool(t *testing.T) { + inputJSON := []byte(`{ + "model": "gemini-3-flash-preview", + "messages": [ + { + "role": "user", + "content": [ + {"type": "text", "text": "hi"} + ] + } + ], + "tools": [ + { + "name": "json", + "description": "A JSON tool", + "input_schema": { + "type": "object", + "properties": {} + } + } + ], + "tool_choice": {"type": "tool", "name": "json"} + }`) + + output := ConvertClaudeRequestToAntigravity("gemini-3-flash-preview", inputJSON, false) + outputStr := string(output) + + if got := gjson.Get(outputStr, "request.toolConfig.functionCallingConfig.mode").String(); got != "ANY" { + t.Fatalf("Expected toolConfig.functionCallingConfig.mode 'ANY', got '%s'", got) + } + allowed := gjson.Get(outputStr, "request.toolConfig.functionCallingConfig.allowedFunctionNames").Array() + if len(allowed) != 1 || allowed[0].String() != "json" { + t.Fatalf("Expected allowedFunctionNames ['json'], got %s", gjson.Get(outputStr, "request.toolConfig.functionCallingConfig.allowedFunctionNames").Raw) + } +} + func TestConvertClaudeRequestToAntigravity_ToolUse(t *testing.T) { inputJSON := []byte(`{ "model": "claude-3-5-sonnet-20240620", diff --git a/internal/translator/gemini-cli/claude/gemini-cli_claude_request.go b/internal/translator/gemini-cli/claude/gemini-cli_claude_request.go index 076e09db..e3753b03 100644 --- a/internal/translator/gemini-cli/claude/gemini-cli_claude_request.go +++ b/internal/translator/gemini-cli/claude/gemini-cli_claude_request.go @@ -172,6 +172,33 @@ func ConvertClaudeRequestToCLI(modelName string, inputRawJSON []byte, _ bool) [] } } + // tool_choice + toolChoiceResult := gjson.GetBytes(rawJSON, "tool_choice") + if toolChoiceResult.Exists() { + toolChoiceType := "" + toolChoiceName := "" + if toolChoiceResult.IsObject() { + toolChoiceType = toolChoiceResult.Get("type").String() + toolChoiceName = toolChoiceResult.Get("name").String() + } else if toolChoiceResult.Type == gjson.String { + toolChoiceType = toolChoiceResult.String() + } + + switch toolChoiceType { + case "auto": + out, _ = sjson.Set(out, "request.toolConfig.functionCallingConfig.mode", "AUTO") + case "none": + out, _ = sjson.Set(out, "request.toolConfig.functionCallingConfig.mode", "NONE") + case "any": + out, _ = sjson.Set(out, "request.toolConfig.functionCallingConfig.mode", "ANY") + case "tool": + out, _ = sjson.Set(out, "request.toolConfig.functionCallingConfig.mode", "ANY") + if toolChoiceName != "" { + out, _ = sjson.Set(out, "request.toolConfig.functionCallingConfig.allowedFunctionNames", []string{toolChoiceName}) + } + } + } + // Map Anthropic thinking -> Gemini CLI thinkingConfig when enabled // Translator only does format conversion, ApplyThinking handles model capability validation. if t := gjson.GetBytes(rawJSON, "thinking"); t.Exists() && t.IsObject() { diff --git a/internal/translator/gemini-cli/claude/gemini-cli_claude_request_test.go b/internal/translator/gemini-cli/claude/gemini-cli_claude_request_test.go new file mode 100644 index 00000000..10364e75 --- /dev/null +++ b/internal/translator/gemini-cli/claude/gemini-cli_claude_request_test.go @@ -0,0 +1,42 @@ +package claude + +import ( + "testing" + + "github.com/tidwall/gjson" +) + +func TestConvertClaudeRequestToCLI_ToolChoice_SpecificTool(t *testing.T) { + inputJSON := []byte(`{ + "model": "gemini-3-flash-preview", + "messages": [ + { + "role": "user", + "content": [ + {"type": "text", "text": "hi"} + ] + } + ], + "tools": [ + { + "name": "json", + "description": "A JSON tool", + "input_schema": { + "type": "object", + "properties": {} + } + } + ], + "tool_choice": {"type": "tool", "name": "json"} + }`) + + output := ConvertClaudeRequestToCLI("gemini-3-flash-preview", inputJSON, false) + + if got := gjson.GetBytes(output, "request.toolConfig.functionCallingConfig.mode").String(); got != "ANY" { + t.Fatalf("Expected request.toolConfig.functionCallingConfig.mode 'ANY', got '%s'", got) + } + allowed := gjson.GetBytes(output, "request.toolConfig.functionCallingConfig.allowedFunctionNames").Array() + if len(allowed) != 1 || allowed[0].String() != "json" { + t.Fatalf("Expected allowedFunctionNames ['json'], got %s", gjson.GetBytes(output, "request.toolConfig.functionCallingConfig.allowedFunctionNames").Raw) + } +} diff --git a/internal/translator/gemini/claude/gemini_claude_request.go b/internal/translator/gemini/claude/gemini_claude_request.go index 0e367c0d..ff276ce3 100644 --- a/internal/translator/gemini/claude/gemini_claude_request.go +++ b/internal/translator/gemini/claude/gemini_claude_request.go @@ -153,6 +153,33 @@ func ConvertClaudeRequestToGemini(modelName string, inputRawJSON []byte, _ bool) } } + // tool_choice + toolChoiceResult := gjson.GetBytes(rawJSON, "tool_choice") + if toolChoiceResult.Exists() { + toolChoiceType := "" + toolChoiceName := "" + if toolChoiceResult.IsObject() { + toolChoiceType = toolChoiceResult.Get("type").String() + toolChoiceName = toolChoiceResult.Get("name").String() + } else if toolChoiceResult.Type == gjson.String { + toolChoiceType = toolChoiceResult.String() + } + + switch toolChoiceType { + case "auto": + out, _ = sjson.Set(out, "toolConfig.functionCallingConfig.mode", "AUTO") + case "none": + out, _ = sjson.Set(out, "toolConfig.functionCallingConfig.mode", "NONE") + case "any": + out, _ = sjson.Set(out, "toolConfig.functionCallingConfig.mode", "ANY") + case "tool": + out, _ = sjson.Set(out, "toolConfig.functionCallingConfig.mode", "ANY") + if toolChoiceName != "" { + out, _ = sjson.Set(out, "toolConfig.functionCallingConfig.allowedFunctionNames", []string{toolChoiceName}) + } + } + } + // Map Anthropic thinking -> Gemini thinking config when enabled // Translator only does format conversion, ApplyThinking handles model capability validation. if t := gjson.GetBytes(rawJSON, "thinking"); t.Exists() && t.IsObject() { diff --git a/internal/translator/gemini/claude/gemini_claude_request_test.go b/internal/translator/gemini/claude/gemini_claude_request_test.go new file mode 100644 index 00000000..e242c42c --- /dev/null +++ b/internal/translator/gemini/claude/gemini_claude_request_test.go @@ -0,0 +1,42 @@ +package claude + +import ( + "testing" + + "github.com/tidwall/gjson" +) + +func TestConvertClaudeRequestToGemini_ToolChoice_SpecificTool(t *testing.T) { + inputJSON := []byte(`{ + "model": "gemini-3-flash-preview", + "messages": [ + { + "role": "user", + "content": [ + {"type": "text", "text": "hi"} + ] + } + ], + "tools": [ + { + "name": "json", + "description": "A JSON tool", + "input_schema": { + "type": "object", + "properties": {} + } + } + ], + "tool_choice": {"type": "tool", "name": "json"} + }`) + + output := ConvertClaudeRequestToGemini("gemini-3-flash-preview", inputJSON, false) + + if got := gjson.GetBytes(output, "toolConfig.functionCallingConfig.mode").String(); got != "ANY" { + t.Fatalf("Expected toolConfig.functionCallingConfig.mode 'ANY', got '%s'", got) + } + allowed := gjson.GetBytes(output, "toolConfig.functionCallingConfig.allowedFunctionNames").Array() + if len(allowed) != 1 || allowed[0].String() != "json" { + t.Fatalf("Expected allowedFunctionNames ['json'], got %s", gjson.GetBytes(output, "toolConfig.functionCallingConfig.allowedFunctionNames").Raw) + } +} From fdbd4041ca4ca8fb8cac9bdc36a311f60fcb1566 Mon Sep 17 00:00:00 2001 From: Luis Pater Date: Thu, 5 Mar 2026 11:48:15 +0800 Subject: [PATCH 6/7] Fixed: #1531 fix(gemini): add `deprecated` to unsupported schema keywords Add `deprecated` to the list of unsupported schema metadata fields in Gemini and update tests to verify its removal. --- .../executor/antigravity_executor_buildrequest_test.go | 4 ++++ internal/util/gemini_schema.go | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/runtime/executor/antigravity_executor_buildrequest_test.go b/internal/runtime/executor/antigravity_executor_buildrequest_test.go index c5cba4ee..27dbeca4 100644 --- a/internal/runtime/executor/antigravity_executor_buildrequest_test.go +++ b/internal/runtime/executor/antigravity_executor_buildrequest_test.go @@ -59,6 +59,7 @@ func buildRequestBodyFromPayload(t *testing.T, modelName string) map[string]any "properties": { "mode": { "type": "string", + "deprecated": true, "enum": ["a", "b"], "enumTitles": ["A", "B"] } @@ -156,4 +157,7 @@ func assertSchemaSanitizedAndPropertyPreserved(t *testing.T, params map[string]a if _, ok := mode["enumTitles"]; ok { t.Fatalf("enumTitles should be removed from nested schema") } + if _, ok := mode["deprecated"]; ok { + t.Fatalf("deprecated should be removed from nested schema") + } } diff --git a/internal/util/gemini_schema.go b/internal/util/gemini_schema.go index b8d07bf4..8617b846 100644 --- a/internal/util/gemini_schema.go +++ b/internal/util/gemini_schema.go @@ -430,7 +430,7 @@ func removeUnsupportedKeywords(jsonStr string) string { keywords := append(unsupportedConstraints, "$schema", "$defs", "definitions", "const", "$ref", "$id", "additionalProperties", "propertyNames", "patternProperties", // Gemini doesn't support these schema keywords - "enumTitles", "prefill", // Claude/OpenCode schema metadata fields unsupported by Gemini + "enumTitles", "prefill", "deprecated", // Schema metadata fields unsupported by Gemini ) deletePaths := make([]string, 0) From 5850492a93c4db3404747f79d1a215ed702e454b Mon Sep 17 00:00:00 2001 From: Luis Pater Date: Thu, 5 Mar 2026 12:11:54 +0800 Subject: [PATCH 7/7] Fixed: #1548 test(translator): add unit tests for fallback logic in `ConvertCodexResponseToOpenAI` model assignment --- .../chat-completions/codex_openai_response.go | 5 ++ .../codex_openai_response_test.go | 47 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 internal/translator/codex/openai/chat-completions/codex_openai_response_test.go diff --git a/internal/translator/codex/openai/chat-completions/codex_openai_response.go b/internal/translator/codex/openai/chat-completions/codex_openai_response.go index f0e264c8..0054d995 100644 --- a/internal/translator/codex/openai/chat-completions/codex_openai_response.go +++ b/internal/translator/codex/openai/chat-completions/codex_openai_response.go @@ -74,8 +74,13 @@ func ConvertCodexResponseToOpenAI(_ context.Context, modelName string, originalR } // Extract and set the model version. + cachedModel := (*param).(*ConvertCliToOpenAIParams).Model if modelResult := gjson.GetBytes(rawJSON, "model"); modelResult.Exists() { template, _ = sjson.Set(template, "model", modelResult.String()) + } else if cachedModel != "" { + template, _ = sjson.Set(template, "model", cachedModel) + } else if modelName != "" { + template, _ = sjson.Set(template, "model", modelName) } template, _ = sjson.Set(template, "created", (*param).(*ConvertCliToOpenAIParams).CreatedAt) diff --git a/internal/translator/codex/openai/chat-completions/codex_openai_response_test.go b/internal/translator/codex/openai/chat-completions/codex_openai_response_test.go new file mode 100644 index 00000000..70aaea06 --- /dev/null +++ b/internal/translator/codex/openai/chat-completions/codex_openai_response_test.go @@ -0,0 +1,47 @@ +package chat_completions + +import ( + "context" + "testing" + + "github.com/tidwall/gjson" +) + +func TestConvertCodexResponseToOpenAI_StreamSetsModelFromResponseCreated(t *testing.T) { + ctx := context.Background() + var param any + + modelName := "gpt-5.3-codex" + + out := ConvertCodexResponseToOpenAI(ctx, modelName, nil, nil, []byte(`data: {"type":"response.created","response":{"id":"resp_123","created_at":1700000000,"model":"gpt-5.3-codex"}}`), ¶m) + if len(out) != 0 { + t.Fatalf("expected no output for response.created, got %d chunks", len(out)) + } + + out = ConvertCodexResponseToOpenAI(ctx, modelName, nil, nil, []byte(`data: {"type":"response.output_text.delta","delta":"hello"}`), ¶m) + if len(out) != 1 { + t.Fatalf("expected 1 chunk, got %d", len(out)) + } + + gotModel := gjson.Get(out[0], "model").String() + if gotModel != modelName { + t.Fatalf("expected model %q, got %q", modelName, gotModel) + } +} + +func TestConvertCodexResponseToOpenAI_FirstChunkUsesRequestModelName(t *testing.T) { + ctx := context.Background() + var param any + + modelName := "gpt-5.3-codex" + + out := ConvertCodexResponseToOpenAI(ctx, modelName, nil, nil, []byte(`data: {"type":"response.output_text.delta","delta":"hello"}`), ¶m) + if len(out) != 1 { + t.Fatalf("expected 1 chunk, got %d", len(out)) + } + + gotModel := gjson.Get(out[0], "model").String() + if gotModel != modelName { + t.Fatalf("expected model %q, got %q", modelName, gotModel) + } +}