Unified · Split
| @@ -233,6 +233,9 @@ nonstream-keepalive-interval: 0 · 232 unmodified lines | ||
| 233 | 233 | # alias: "vertex-flash" # client-visible alias |
| 234 | 234 | # - name: "gemini-2.5-pro" |
| 235 | 235 | # alias: "vertex-pro" |
| 236 | +# excluded-models: # optional: models to exclude from listing | |
| 237 | +# - "imagen-3.0-generate-002" | |
| 238 | +# - "imagen-*" | |
| 236 | 239 | |
| 237 | 240 | # Amp Integration |
| 238 | 241 | # ampcode: |
| @@ -516,12 +516,13 @@ func (h *Handler) PutVertexCompatKeys(c *gin.Context) { · 515 unmodified lines | ||
| 516 | 516 | } |
| 517 | 517 | func (h *Handler) PatchVertexCompatKey(c *gin.Context) { |
| 518 | 518 | type vertexCompatPatch struct { |
| 519 | − APIKey *string `json:"api-key"` | |
| 520 | − Prefix *string `json:"prefix"` | |
| 521 | − BaseURL *string `json:"base-url"` | |
| 522 | − ProxyURL *string `json:"proxy-url"` | |
| 523 | − Headers *map[string]string `json:"headers"` | |
| 524 | − Models *[]config.VertexCompatModel `json:"models"` | |
| 519 | + APIKey *string `json:"api-key"` | |
| 520 | + Prefix *string `json:"prefix"` | |
| 521 | + BaseURL *string `json:"base-url"` | |
| 522 | + ProxyURL *string `json:"proxy-url"` | |
| 523 | + Headers *map[string]string `json:"headers"` | |
| 524 | + Models *[]config.VertexCompatModel `json:"models"` | |
| 525 | + ExcludedModels *[]string `json:"excluded-models"` | |
| 525 | 526 | } |
| 526 | 527 | var body struct { |
| 527 | 528 | Index *int `json:"index"` |
| @@ -585,6 +586,9 @@ func (h *Handler) PatchVertexCompatKey(c *gin.Context) { · 57 unmodified lines | ||
| 585 | 586 | if body.Value.Models != nil { |
| 586 | 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 | 592 | normalizeVertexCompatKey(&entry) |
| 589 | 593 | h.cfg.VertexCompatAPIKey[targetIndex] = entry |
| 590 | 594 | h.cfg.SanitizeVertexCompatKeys() |
| @@ -1029,6 +1033,7 @@ func normalizeVertexCompatKey(entry *config.VertexCompatKey) { · 438 unmodified lines | ||
| 1029 | 1033 | entry.BaseURL = strings.TrimSpace(entry.BaseURL) |
| 1030 | 1034 | entry.ProxyURL = strings.TrimSpace(entry.ProxyURL) |
| 1031 | 1035 | entry.Headers = config.NormalizeHeaders(entry.Headers) |
| 1036 | + entry.ExcludedModels = config.NormalizeExcludedModels(entry.ExcludedModels) | |
| 1032 | 1037 | if len(entry.Models) == 0 { |
| 1033 | 1038 | return |
| 1034 | 1039 | } |
| @@ -34,6 +34,9 @@ type VertexCompatKey struct { · 33 unmodified lines | ||
| 34 | 34 | |
| 35 | 35 | // Models defines the model configurations including aliases for routing. |
| 36 | 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 | |
| 39 | 42 | func (k VertexCompatKey) GetAPIKey() string { return k.APIKey } |
| @@ -74,6 +77,7 @@ func (cfg *Config) SanitizeVertexCompatKeys() { · 34 unmodified lines | ||
| 74 | 77 | } |
| 75 | 78 | entry.ProxyURL = strings.TrimSpace(entry.ProxyURL) |
| 76 | 79 | entry.Headers = NormalizeHeaders(entry.Headers) |
| 80 | + entry.ExcludedModels = NormalizeExcludedModels(entry.ExcludedModels) | |
| 77 | 81 | |
| 78 | 82 | // Sanitize models: remove entries without valid alias |
| 79 | 83 | sanitizedModels := make([]VertexCompatModel, 0, len(entry.Models)) |
| @@ -59,6 +59,7 @@ func buildRequestBodyFromPayload(t *testing.T, modelName string) map[string]any · 58 unmodified lines | ||
| 59 | 59 | "properties": { |
| 60 | 60 | "mode": { |
| 61 | 61 | "type": "string", |
| 62 | + "deprecated": true, | |
| 62 | 63 | "enum": ["a", "b"], |
| 63 | 64 | "enumTitles": ["A", "B"] |
| 64 | 65 | } |
| @@ -156,4 +157,7 @@ func assertSchemaSanitizedAndPropertyPreserved(t *testing.T, params map[string]a · 91 unmodified lines | ||
| 156 | 157 | if _, ok := mode["enumTitles"]; ok { |
| 157 | 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 | } |
| @@ -431,6 +431,33 @@ func ConvertClaudeRequestToAntigravity(modelName string, inputRawJSON []byte, _ · 430 unmodified lines | ||
| 431 | 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 | 461 | // Map Anthropic thinking -> Gemini thinkingBudget/include_thoughts when type==enabled |
| 435 | 462 | if t := gjson.GetBytes(rawJSON, "thinking"); enableThoughtTranslate && t.Exists() && t.IsObject() { |
| 436 | 463 | switch t.Get("type").String() { |
| @@ -441,15 +468,18 @@ func ConvertClaudeRequestToAntigravity(modelName string, inputRawJSON []byte, _ · 4 unmodified lines | ||
| 441 | 468 | out, _ = sjson.Set(out, "request.generationConfig.thinkingConfig.includeThoughts", true) |
| 442 | 469 | } |
| 443 | 470 | case "adaptive", "auto": |
| 444 | − // Adaptive/auto thinking: | |
| 445 | − // - If output_config.effort is present, pass it through as thinkingLevel. | |
| 446 | − // - Otherwise, default to "high". | |
| 447 | − // ApplyThinking later normalizes/clamps and may convert level → budget per target model. | |
| 471 | + // For adaptive thinking: | |
| 472 | + // - If output_config.effort is explicitly present, pass through as thinkingLevel. | |
| 473 | + // - Otherwise, treat it as "enabled with target-model maximum" and emit high. | |
| 474 | + // ApplyThinking handles clamping to target model's supported levels. | |
| 448 | 475 | effort := "" |
| 449 | 476 | if v := gjson.GetBytes(rawJSON, "output_config.effort"); v.Exists() && v.Type == gjson.String { |
| 450 | 477 | effort = strings.ToLower(strings.TrimSpace(v.String())) |
| 451 | 478 | } |
| 452 | 479 | if effort != "" { |
| 480 | + if effort == "max" { | |
| 481 | + effort = "high" | |
| 482 | + } | |
| 453 | 483 | out, _ = sjson.Set(out, "request.generationConfig.thinkingConfig.thinkingLevel", effort) |
| 454 | 484 | } else { |
| 455 | 485 | out, _ = sjson.Set(out, "request.generationConfig.thinkingConfig.thinkingLevel", "high") |
| @@ -193,6 +193,42 @@ func TestConvertClaudeRequestToAntigravity_ToolDeclarations(t *testing.T) { · 192 unmodified lines | ||
| 193 | 193 | } |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | +func 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 | + | |
| 196 | 232 | func TestConvertClaudeRequestToAntigravity_ToolUse(t *testing.T) { |
| 197 | 233 | inputJSON := []byte(`{ |
| 198 | 234 | "model": "claude-3-5-sonnet-20240620", |
| @@ -1199,3 +1235,64 @@ func TestConvertClaudeRequestToAntigravity_ToolAndThinking_NoExistingSystem(t *t · 1000 unmodified lines | ||
| 1199 | 1235 | t.Errorf("Interleaved thinking hint should be in created systemInstruction, got: %v", sysInstruction.Raw) |
| 1200 | 1236 | } |
| 1201 | 1237 | } |
| 1238 | + | |
| 1239 | +func 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 | + | |
| 1278 | +func 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 | +} | |
| @@ -255,6 +255,8 @@ func ConvertClaudeRequestToCodex(modelName string, inputRawJSON []byte, _ bool) · 254 unmodified lines | ||
| 255 | 255 | tool, _ = sjson.SetRaw(tool, "parameters", normalizeToolParameters(toolResult.Get("input_schema").Raw)) |
| 256 | 256 | tool, _ = sjson.Delete(tool, "input_schema") |
| 257 | 257 | tool, _ = sjson.Delete(tool, "parameters.$schema") |
| 258 | + tool, _ = sjson.Delete(tool, "cache_control") | |
| 259 | + tool, _ = sjson.Delete(tool, "defer_loading") | |
| 258 | 260 | tool, _ = sjson.Set(tool, "strict", false) |
| 259 | 261 | template, _ = sjson.SetRaw(template, "tools.-1", tool) |
| 260 | 262 | } |
| @@ -74,8 +74,13 @@ func ConvertCodexResponseToOpenAI(_ context.Context, modelName string, originalR · 73 unmodified lines | ||
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | // Extract and set the model version. |
| 77 | + cachedModel := (*param).(*ConvertCliToOpenAIParams).Model | |
| 77 | 78 | if modelResult := gjson.GetBytes(rawJSON, "model"); modelResult.Exists() { |
| 78 | 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 | 86 | template, _ = sjson.Set(template, "created", (*param).(*ConvertCliToOpenAIParams).CreatedAt) |
| @@ -0,0 +1,47 @@ | ||
| 1 | +package chat_completions | |
| 2 | + | |
| 3 | +import ( | |
| 4 | + "context" | |
| 5 | + "testing" | |
| 6 | + | |
| 7 | + "github.com/tidwall/gjson" | |
| 8 | +) | |
| 9 | + | |
| 10 | +func 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"}}`), ¶m) | |
| 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"}`), ¶m) | |
| 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 | + | |
| 32 | +func 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"}`), ¶m) | |
| 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 | +} | |
| @@ -156,6 +156,7 @@ func ConvertClaudeRequestToCLI(modelName string, inputRawJSON []byte, _ bool) [] · 155 unmodified lines | ||
| 156 | 156 | tool, _ = sjson.Delete(tool, "input_examples") |
| 157 | 157 | tool, _ = sjson.Delete(tool, "type") |
| 158 | 158 | tool, _ = sjson.Delete(tool, "cache_control") |
| 159 | + tool, _ = sjson.Delete(tool, "defer_loading") | |
| 159 | 160 | if gjson.Valid(tool) && gjson.Parse(tool).IsObject() { |
| 160 | 161 | if !hasTools { |
| 161 | 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 | 202 | // Map Anthropic thinking -> Gemini CLI thinkingConfig when enabled |
| 175 | 203 | // Translator only does format conversion, ApplyThinking handles model capability validation. |
| 176 | 204 | if t := gjson.GetBytes(rawJSON, "thinking"); t.Exists() && t.IsObject() { |
| @@ -0,0 +1,42 @@ | ||
| 1 | +package claude | |
| 2 | + | |
| 3 | +import ( | |
| 4 | + "testing" | |
| 5 | + | |
| 6 | + "github.com/tidwall/gjson" | |
| 7 | +) | |
| 8 | + | |
| 9 | +func 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 | +} | |
| @@ -137,6 +137,7 @@ func ConvertClaudeRequestToGemini(modelName string, inputRawJSON []byte, _ bool) · 136 unmodified lines | ||
| 137 | 137 | tool, _ = sjson.Delete(tool, "input_examples") |
| 138 | 138 | tool, _ = sjson.Delete(tool, "type") |
| 139 | 139 | tool, _ = sjson.Delete(tool, "cache_control") |
| 140 | + tool, _ = sjson.Delete(tool, "defer_loading") | |
| 140 | 141 | if gjson.Valid(tool) && gjson.Parse(tool).IsObject() { |
| 141 | 142 | if !hasTools { |
| 142 | 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 | 183 | // Map Anthropic thinking -> Gemini thinking config when enabled |
| 156 | 184 | // Translator only does format conversion, ApplyThinking handles model capability validation. |
| 157 | 185 | if t := gjson.GetBytes(rawJSON, "thinking"); t.Exists() && t.IsObject() { |
| @@ -0,0 +1,42 @@ | ||
| 1 | +package claude | |
| 2 | + | |
| 3 | +import ( | |
| 4 | + "testing" | |
| 5 | + | |
| 6 | + "github.com/tidwall/gjson" | |
| 7 | +) | |
| 8 | + | |
| 9 | +func 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 | +} | |
| @@ -354,22 +354,7 @@ func ConvertOpenAIResponsesRequestToGemini(modelName string, inputRawJSON []byte · 353 unmodified lines | ||
| 354 | 354 | funcDecl, _ = sjson.Set(funcDecl, "description", desc.String()) |
| 355 | 355 | } |
| 356 | 356 | if params := tool.Get("parameters"); params.Exists() { |
| 357 | − // Convert parameter types from OpenAI format to Gemini format | |
| 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) | |
| 357 | + funcDecl, _ = sjson.SetRaw(funcDecl, "parametersJsonSchema", params.Raw) | |
| 373 | 358 | } |
| 374 | 359 | |
| 375 | 360 | geminiTools, _ = sjson.SetRaw(geminiTools, "0.functionDeclarations.-1", funcDecl) |
| @@ -430,7 +430,7 @@ func removeUnsupportedKeywords(jsonStr string) string { · 429 unmodified lines | ||
| 430 | 430 | keywords := append(unsupportedConstraints, |
| 431 | 431 | "$schema", "$defs", "definitions", "const", "$ref", "$id", "additionalProperties", |
| 432 | 432 | "propertyNames", "patternProperties", // Gemini doesn't support these schema keywords |
| 433 | − "enumTitles", "prefill", // Claude/OpenCode schema metadata fields unsupported by Gemini | |
| 433 | + "enumTitles", "prefill", "deprecated", // Schema metadata fields unsupported by Gemini | |
| 434 | 434 | ) |
| 435 | 435 | |
| 436 | 436 | deletePaths := make([]string, 0) |
| @@ -304,6 +304,11 @@ func BuildConfigChangeDetails(oldCfg, newCfg *config.Config) []string { · 303 unmodified lines | ||
| 304 | 304 | if oldModels.hash != newModels.hash { |
| 305 | 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 | 312 | if !equalStringMap(o.Headers, n.Headers) { |
| 308 | 313 | changes = append(changes, fmt.Sprintf("vertex[%d].headers: updated", i)) |
| 309 | 314 | } |
| @@ -319,7 +319,7 @@ func (s *ConfigSynthesizer) synthesizeVertexCompat(ctx *SynthesisContext) []*cor · 318 unmodified lines | ||
| 319 | 319 | CreatedAt: now, |
| 320 | 320 | UpdatedAt: now, |
| 321 | 321 | } |
| 322 | − ApplyAuthExcludedModelsMeta(a, cfg, nil, "apikey") | |
| 322 | + ApplyAuthExcludedModelsMeta(a, cfg, compat.ExcludedModels, "apikey") | |
| 323 | 323 | out = append(out, a) |
| 324 | 324 | } |
| 325 | 325 | return out |
| @@ -820,10 +820,13 @@ func (s *Service) registerModelsForAuth(a *coreauth.Auth) { · 819 unmodified lines | ||
| 820 | 820 | case "vertex": |
| 821 | 821 | // Vertex AI Gemini supports the same model identifiers as Gemini. |
| 822 | 822 | models = registry.GetGeminiVertexModels() |
| 823 | − if authKind == "apikey" { | |
| 824 | − if entry := s.resolveConfigVertexCompatKey(a); entry != nil && len(entry.Models) > 0 { | |
| 823 | + if entry := s.resolveConfigVertexCompatKey(a); entry != nil { | |
| 824 | + if len(entry.Models) > 0 { | |
| 825 | 825 | models = buildVertexCompatConfigModels(entry) |
| 826 | 826 | } |
| 827 | + if authKind == "apikey" { | |
| 828 | + excluded = entry.ExcludedModels | |
| 829 | + } | |
| 827 | 830 | } |
| 828 | 831 | models = applyExcludedModels(models, excluded) |
| 829 | 832 | case "gemini-cli": |