fix(gateway): apply D/E/F mimicry to native /v1/messages and count_tokens paths
The previous commit only wired stripMessageCacheControl, addMessageCacheBreakpoints, and tool-name obfuscation into applyClaudeCodeOAuthMimicryToBody (used by /chat/completions and /responses). The native /v1/messages path and count_tokens path have their own independent mimicry code blocks and were missed. Now all three entry points share the same D/E/F pipeline: - /v1/messages (gateway_service.go forwardAnthropic) - /v1/messages/count_tokens (gateway_service.go countTokens) - OpenAI compat (applyClaudeCodeOAuthMimicryToBody)
This commit is contained in:
@@ -4187,6 +4187,18 @@ func (s *GatewayService) Forward(ctx context.Context, c *gin.Context, account *A
|
|||||||
}
|
}
|
||||||
|
|
||||||
body, reqModel = normalizeClaudeOAuthRequestBody(body, reqModel, normalizeOpts)
|
body, reqModel = normalizeClaudeOAuthRequestBody(body, reqModel, normalizeOpts)
|
||||||
|
|
||||||
|
// D/E/F: messages cache 策略 + 工具名混淆 + tools[-1] 断点
|
||||||
|
// 与 forward_as_chat_completions / forward_as_responses 路径对齐,
|
||||||
|
// 保证原生 /v1/messages 路径也经过完整的 Parrot 字段级改写。
|
||||||
|
body = stripMessageCacheControl(body)
|
||||||
|
body = addMessageCacheBreakpoints(body)
|
||||||
|
if rw := buildToolNameRewriteFromBody(body); rw != nil {
|
||||||
|
body = applyToolNameRewriteToBody(body, rw)
|
||||||
|
c.Set(toolNameRewriteKey, rw)
|
||||||
|
} else {
|
||||||
|
body = applyToolsLastCacheBreakpoint(body)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 强制执行 cache_control 块数量限制(最多 4 个)
|
// 强制执行 cache_control 块数量限制(最多 4 个)
|
||||||
@@ -8380,6 +8392,14 @@ func (s *GatewayService) ForwardCountTokens(ctx context.Context, c *gin.Context,
|
|||||||
if shouldMimicClaudeCode {
|
if shouldMimicClaudeCode {
|
||||||
normalizeOpts := claudeOAuthNormalizeOptions{stripSystemCacheControl: true}
|
normalizeOpts := claudeOAuthNormalizeOptions{stripSystemCacheControl: true}
|
||||||
body, reqModel = normalizeClaudeOAuthRequestBody(body, reqModel, normalizeOpts)
|
body, reqModel = normalizeClaudeOAuthRequestBody(body, reqModel, normalizeOpts)
|
||||||
|
|
||||||
|
body = stripMessageCacheControl(body)
|
||||||
|
body = addMessageCacheBreakpoints(body)
|
||||||
|
if rw := buildToolNameRewriteFromBody(body); rw != nil {
|
||||||
|
body = applyToolNameRewriteToBody(body, rw)
|
||||||
|
} else {
|
||||||
|
body = applyToolsLastCacheBreakpoint(body)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Antigravity 账户不支持 count_tokens,返回 404 让客户端 fallback 到本地估算。
|
// Antigravity 账户不支持 count_tokens,返回 404 让客户端 fallback 到本地估算。
|
||||||
|
|||||||
Reference in New Issue
Block a user