refactor(logging): clean up oauth logs and debugs

This commit is contained in:
hkfires
2026-01-09 11:20:55 +08:00
parent ef6bafbf7e
commit ee62ef4745
4 changed files with 7 additions and 21 deletions

View File

@@ -304,11 +304,7 @@ func formatAuthInfo(info upstreamRequestLog) string {
parts = append(parts, "type=api_key") parts = append(parts, "type=api_key")
} }
case "oauth": case "oauth":
if authValue != "" {
parts = append(parts, fmt.Sprintf("type=oauth account=%s", authValue))
} else {
parts = append(parts, "type=oauth") parts = append(parts, "type=oauth")
}
default: default:
if authType != "" { if authType != "" {
if authValue != "" { if authValue != "" {

View File

@@ -14,7 +14,6 @@ import (
"github.com/router-for-me/CLIProxyAPI/v6/internal/cache" "github.com/router-for-me/CLIProxyAPI/v6/internal/cache"
"github.com/router-for-me/CLIProxyAPI/v6/internal/translator/gemini/common" "github.com/router-for-me/CLIProxyAPI/v6/internal/translator/gemini/common"
"github.com/router-for-me/CLIProxyAPI/v6/internal/util" "github.com/router-for-me/CLIProxyAPI/v6/internal/util"
log "github.com/sirupsen/logrus"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"github.com/tidwall/sjson" "github.com/tidwall/sjson"
) )
@@ -136,14 +135,14 @@ func ConvertClaudeRequestToAntigravity(modelName string, inputRawJSON []byte, _
if sessionID != "" && thinkingText != "" { if sessionID != "" && thinkingText != "" {
if cachedSig := cache.GetCachedSignature(sessionID, thinkingText); cachedSig != "" { if cachedSig := cache.GetCachedSignature(sessionID, thinkingText); cachedSig != "" {
signature = cachedSig signature = cachedSig
log.Debugf("Using cached signature for thinking block") // log.Debugf("Using cached signature for thinking block")
} }
} }
// Fallback to client signature only if cache miss and client signature is valid // Fallback to client signature only if cache miss and client signature is valid
if signature == "" && cache.HasValidSignature(clientSignature) { if signature == "" && cache.HasValidSignature(clientSignature) {
signature = clientSignature signature = clientSignature
log.Debugf("Using client-provided signature for thinking block") // log.Debugf("Using client-provided signature for thinking block")
} }
// Store for subsequent tool_use in the same message // Store for subsequent tool_use in the same message
@@ -158,8 +157,7 @@ func ConvertClaudeRequestToAntigravity(modelName string, inputRawJSON []byte, _
// Claude requires assistant messages to start with thinking blocks when thinking is enabled // Claude requires assistant messages to start with thinking blocks when thinking is enabled
// Converting to text would break this requirement // Converting to text would break this requirement
if isUnsigned { if isUnsigned {
// TypeScript plugin approach: drop unsigned thinking blocks entirely // log.Debugf("Dropping unsigned thinking block (no valid signature)")
log.Debugf("Dropping unsigned thinking block (no valid signature)")
continue continue
} }
@@ -183,7 +181,6 @@ func ConvertClaudeRequestToAntigravity(modelName string, inputRawJSON []byte, _
} else if contentTypeResult.Type == gjson.String && contentTypeResult.String() == "tool_use" { } else if contentTypeResult.Type == gjson.String && contentTypeResult.String() == "tool_use" {
// NOTE: Do NOT inject dummy thinking blocks here. // NOTE: Do NOT inject dummy thinking blocks here.
// Antigravity API validates signatures, so dummy values are rejected. // Antigravity API validates signatures, so dummy values are rejected.
// The TypeScript plugin removes unsigned thinking blocks instead of injecting dummies.
functionName := contentResult.Get("name").String() functionName := contentResult.Get("name").String()
argsResult := contentResult.Get("input") argsResult := contentResult.Get("input")

View File

@@ -136,11 +136,11 @@ func ConvertAntigravityResponseToClaude(_ context.Context, _ string, originalReq
// Process thinking content (internal reasoning) // Process thinking content (internal reasoning)
if partResult.Get("thought").Bool() { if partResult.Get("thought").Bool() {
if thoughtSignature := partResult.Get("thoughtSignature"); thoughtSignature.Exists() && thoughtSignature.String() != "" { if thoughtSignature := partResult.Get("thoughtSignature"); thoughtSignature.Exists() && thoughtSignature.String() != "" {
log.Debug("Branch: signature_delta") // log.Debug("Branch: signature_delta")
if params.SessionID != "" && params.CurrentThinkingText.Len() > 0 { if params.SessionID != "" && params.CurrentThinkingText.Len() > 0 {
cache.CacheSignature(params.SessionID, params.CurrentThinkingText.String(), thoughtSignature.String()) cache.CacheSignature(params.SessionID, params.CurrentThinkingText.String(), thoughtSignature.String())
log.Debugf("Cached signature for thinking block (sessionID=%s, textLen=%d)", params.SessionID, params.CurrentThinkingText.Len()) // log.Debugf("Cached signature for thinking block (sessionID=%s, textLen=%d)", params.SessionID, params.CurrentThinkingText.Len())
params.CurrentThinkingText.Reset() params.CurrentThinkingText.Reset()
} }

View File

@@ -1609,7 +1609,6 @@ func formatOauthIdentity(auth *Auth, provider string, accountInfo string) string
if auth == nil { if auth == nil {
return "" return ""
} }
authIndex := auth.EnsureIndex()
// Prefer the auth's provider when available. // Prefer the auth's provider when available.
providerName := strings.TrimSpace(auth.Provider) providerName := strings.TrimSpace(auth.Provider)
if providerName == "" { if providerName == "" {
@@ -1631,17 +1630,11 @@ func formatOauthIdentity(auth *Auth, provider string, accountInfo string) string
if authFile != "" { if authFile != "" {
parts = append(parts, "auth_file="+authFile) parts = append(parts, "auth_file="+authFile)
} }
if authIndex != "" {
parts = append(parts, "auth_index="+authIndex)
}
if len(parts) == 0 { if len(parts) == 0 {
return accountInfo return accountInfo
} }
if accountInfo == "" {
return strings.Join(parts, " ") return strings.Join(parts, " ")
} }
return strings.Join(parts, " ") + " account=" + strconv.Quote(accountInfo)
}
// InjectCredentials delegates per-provider HTTP request preparation when supported. // InjectCredentials delegates per-provider HTTP request preparation when supported.
// If the registered executor for the auth provider implements RequestPreparer, // If the registered executor for the auth provider implements RequestPreparer,