mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-12-05 16:07:33 +00:00
fix(composite): 非 APIKey 多协议账号不得进入 generic 账号池
generic Forward 只对 APIKey 账号使用协议化 Anthropic base,其余类型回落官方 api.anthropic.com;池成员资格只校验协议 base 非空,异常配置的 OAuth 类型 国产 / Ollama 账号(api_protocol=anthropic/adaptive)被选中时会带自身凭据 发往 Anthropic。多协议分支要求 APIKey 类型。
This commit is contained in:
1 parent
6d17e26ece
commit
8d36844f39
2 files changed
+16
-4
No files matched your search
@@ -68,9 +68,9 @@ func (s *GatewayService) withCompositePoolQuotaAutoPauseContext(ctx context.Cont
|
||||
// 纯能力判定,不依赖候选池:
|
||||
// - PlatformAnthropic:generic 网关原生账号(OAuth/APIKey/ServiceAccount);
|
||||
// - gemini / antigravity:既有 generic 调度支持的平台;
|
||||
// - anthropic-协议 / adaptive 多协议账号:要求能解析出 Anthropic 协议上游 base
|
||||
// (GetAnthropicProtocolBaseURL 非空,含 api_base_urls.anthropic 与供应商×模式
|
||||
// 默认端点),避免入池后转发期才发现无端点可用;
|
||||
// - anthropic-协议 / adaptive 多协议账号:要求 APIKey 类型且能解析出 Anthropic 协议
|
||||
// 上游 base(GetAnthropicProtocolBaseURL 非空,含 api_base_urls.anthropic 与供应商×
|
||||
// 模式默认端点),避免入池后转发期才发现无端点可用或回落官方 Anthropic;
|
||||
// - OpenAI 兼容账号(openai/grok/国产供应商/opencode_go):转发由 handler 层
|
||||
// 委派协议转换链服务,不因账号停留在 Chat Completions 协议而被池排除。
|
||||
func genericCompositePoolAccountServable(account *Account) bool {
|
||||
@@ -87,7 +87,10 @@ func genericCompositePoolAccountServable(account *Account) bool {
|
||||
return true
|
||||
}
|
||||
if account.IsAnthropicProtocol() || account.IsAdaptiveAPIProtocol() {
|
||||
return strings.TrimSpace(account.GetAnthropicProtocolBaseURL()) != ""
|
||||
// generic Forward 只对 APIKey 账号使用协议化 base(buildUpstreamRequest),其余
|
||||
// 类型回落官方 api.anthropic.com:非 APIKey 的多协议账号(异常配置)入池会把
|
||||
// 自身凭据发往 Anthropic,一律不可服务。
|
||||
return account.Type == AccountTypeAPIKey && strings.TrimSpace(account.GetAnthropicProtocolBaseURL()) != ""
|
||||
}
|
||||
return account.IsOpenAICompatible()
|
||||
}
|
||||
|
||||
@@ -459,6 +459,15 @@ func TestCompositeGenericPoolPredicates(t *testing.T) {
|
||||
require.True(t, genericCompositePoolAccountServable(&gemini))
|
||||
require.True(t, genericCompositePoolAccountServable(&antigravity))
|
||||
|
||||
// 非 APIKey 的多协议账号(异常配置):generic Forward 不用协议化 base、回落官方
|
||||
// api.anthropic.com,入池会把自身凭据发往 Anthropic,不可服务。
|
||||
zhipuAnthropicOAuth := zhipuAnthropic
|
||||
zhipuAnthropicOAuth.Type = AccountTypeOAuth
|
||||
require.False(t, genericCompositePoolAccountServable(&zhipuAnthropicOAuth))
|
||||
kimiAdaptiveOAuth := kimiAdaptive
|
||||
kimiAdaptiveOAuth.Type = AccountTypeOAuth
|
||||
require.False(t, genericCompositePoolAccountServable(&kimiAdaptiveOAuth))
|
||||
|
||||
// 池成员资格:平台 ∈ 候选池为准;池外平台一律拒绝。
|
||||
require.True(t, genericCompositePoolAllowsAccount(poolCtx, &kimiAdaptive))
|
||||
require.True(t, genericCompositePoolAllowsAccount(poolCtx, &anthropicNative))
|
||||
|
||||
Reference in new issue
Block a user