Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions debug_provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package main

import (
"fmt"

"github.com/router-for-me/CLIProxyAPI/v6/internal/registry"
"github.com/router-for-me/CLIProxyAPI/v6/internal/util"
)

func main() {
modelName := "gemini-3-pro-preview"

// 1. Check if model exists in registry
modelInfo := registry.LookupStaticModelInfo(modelName)
if modelInfo != nil {
fmt.Printf("✅ Model found in static definitions: %+v\n", modelInfo)
} else {
fmt.Printf("❌ Model NOT found in static definitions\n")
}

// 2. Check provider resolution
providers := util.GetProviderName(modelName)
fmt.Printf("Providers for '%s': %v\n", modelName, providers)

if len(providers) == 0 {
fmt.Println("❌ No providers found! This explains the 'unknown provider' error.")

// Debug: check GetGeminiModels directly
fmt.Println("\nDebugging GetGeminiModels:")
for _, m := range registry.GetGeminiModels() {
if m.ID == modelName {
fmt.Printf(" Found in GetGeminiModels: %+v\n", m)
}
}
} else {
fmt.Println("✅ Providers resolved successfully.")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func ConvertClaudeRequestToAntigravity(modelName string, inputRawJSON []byte, _
rawFuncName := toolCallID
toolCallIDs := strings.Split(toolCallID, "-")
if len(toolCallIDs) > 1 {
rawFuncName = strings.Join(toolCallIDs[0:len(toolCallIDs)-1], "-")
rawFuncName = strings.Join(toolCallIDs[0:len(toolCallIDs)-2], "-")
}
funcName := util.SanitizeFunctionName(rawFuncName)
functionResponseResult := contentResult.Get("content")
Expand Down
15 changes: 1 addition & 14 deletions internal/translator/codex/claude/codex_claude_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,20 +285,7 @@ func buildShortNameMap(names []string) map[string]string {
used := map[string]struct{}{}
m := map[string]string{}

baseCandidate := func(n string) string {
const limit = 64
if len(n) <= limit {
return util.SanitizeFunctionName(n)
}
if strings.HasPrefix(n, "mcp__") {
idx := strings.LastIndex(n, "__")
if idx > 0 {
cand := "mcp__" + n[idx+2:]
return util.SanitizeFunctionName(cand)
}
}
return util.SanitizeFunctionName(n)
}
baseCandidate := shortenNameIfNeeded

makeUnique := func(cand string) string {
if _, ok := used[cand]; !ok {
Expand Down
7 changes: 5 additions & 2 deletions internal/translator/codex/claude/codex_claude_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,12 @@ func ConvertCodexResponseToClaude(_ context.Context, _ string, originalRequestRa
output = "event: content_block_stop\n"
output += fmt.Sprintf("data: %s\n\n", template)
} else if typeStr == "response.completed" {
template = `{"type":"message_delta","delta":{"stop_reason":"tool_use","stop_sequence":null},"usage":{"input_tokens":0,"output_tokens":0}}`
template = `{"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":0,"output_tokens":0}}`
p := (*param).(*bool)
if *p {
stopReason := rootResult.Get("response.stop_reason").String()
if stopReason != "" {
template, _ = sjson.Set(template, "delta.stop_reason", stopReason)
} else if *p {
template, _ = sjson.Set(template, "delta.stop_reason", "tool_use")
} else {
template, _ = sjson.Set(template, "delta.stop_reason", "end_turn")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func ConvertClaudeRequestToCLI(modelName string, inputRawJSON []byte, _ bool) []
rawFuncName := toolCallID
toolCallIDs := strings.Split(toolCallID, "-")
if len(toolCallIDs) > 1 {
rawFuncName = strings.Join(toolCallIDs[0:len(toolCallIDs)-1], "-")
rawFuncName = strings.Join(toolCallIDs[0:len(toolCallIDs)-2], "-")
}
funcName := util.SanitizeFunctionName(rawFuncName)
responseData := contentResult.Get("content").Raw
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,19 @@ func ConvertGeminiCLIResponseToClaude(_ context.Context, _ string, originalReque
output = output + "event: message_delta\n"
output = output + `data: `

// Create the message delta template with appropriate stop reason
template := `{"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":0,"output_tokens":0}}`
// Set tool_use stop reason if tools were used in this response
stopReason := "end_turn"
if usedTool {
template = `{"type":"message_delta","delta":{"stop_reason":"tool_use","stop_sequence":null},"usage":{"input_tokens":0,"output_tokens":0}}`
stopReason = "tool_use"
} else {
if finish := gjson.GetBytes(rawJSON, "response.candidates.0.finishReason"); finish.Exists() && finish.String() == "MAX_TOKENS" {
stopReason = "max_tokens"
}
}

// Create the message delta template with appropriate stop reason
template := `{"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":0,"output_tokens":0}}`
template, _ = sjson.Set(template, "delta.stop_reason", stopReason)

// Include thinking tokens in output token count if present
thoughtsTokenCount := usageResult.Get("thoughtsTokenCount").Int()
template, _ = sjson.Set(template, "usage.output_tokens", candidatesTokenCountResult.Int()+thoughtsTokenCount)
Expand Down
2 changes: 1 addition & 1 deletion internal/translator/gemini/claude/gemini_claude_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func ConvertClaudeRequestToGemini(modelName string, inputRawJSON []byte, _ bool)
rawFuncName := toolCallID
toolCallIDs := strings.Split(toolCallID, "-")
if len(toolCallIDs) > 1 {
rawFuncName = strings.Join(toolCallIDs[0:len(toolCallIDs)-1], "-")
rawFuncName = strings.Join(toolCallIDs[0:len(toolCallIDs)-2], "-")
}
funcName := util.SanitizeFunctionName(rawFuncName)
responseData := contentResult.Get("content").Raw
Expand Down
11 changes: 9 additions & 2 deletions internal/translator/gemini/claude/gemini_claude_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,18 @@ func ConvertGeminiResponseToClaude(_ context.Context, _ string, originalRequestR
output = output + "event: message_delta\n"
output = output + `data: `

template := `{"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":0,"output_tokens":0}}`
stopReason := "end_turn"
if usedTool {
template = `{"type":"message_delta","delta":{"stop_reason":"tool_use","stop_sequence":null},"usage":{"input_tokens":0,"output_tokens":0}}`
stopReason = "tool_use"
} else {
if finish := gjson.GetBytes(rawJSON, "candidates.0.finishReason"); finish.Exists() && finish.String() == "MAX_TOKENS" {
stopReason = "max_tokens"
}
}

template := `{"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":0,"output_tokens":0}}`
template, _ = sjson.Set(template, "delta.stop_reason", stopReason)

thoughtsTokenCount := usageResult.Get("thoughtsTokenCount").Int()
template, _ = sjson.Set(template, "usage.output_tokens", candidatesTokenCountResult.Int()+thoughtsTokenCount)
template, _ = sjson.Set(template, "usage.input_tokens", usageResult.Get("promptTokenCount").Int())
Expand Down
Loading