mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-12-05 16:07:33 +00:00
refactor(provider): 以 provider profile 收敛多协议供应商默认端点表
多协议 API Key 供应商(kimi/zhipu/deepseek/minimax/opencode_go)的默认端点 此前在 account.go 的 GetOpenAIBaseURL / defaultCNProtocolBaseURL / GetAnthropicProtocolBaseURL / GetOpenAIFormatBaseURL 中按平台 switch 重复了 四遍,Responses 能力与 OpenCode 内置分流表也各自散落。 新增 provider_profile.go 作为单一数据来源:每个供应商登记各接入模式的 Chat/Anthropic 默认基址、内置 protocol_rules 与原生 Responses 能力; 上述函数、SupportsNativeCNResponses、IsMultiProtocolAPIKeyProvider 与 defaultOpenCodeProtocolRules 改为查表。纯重构,行为不变:新增测试以旧 switch 逻辑为基准,逐一核对平台 × account_mode × 协议的全部组合。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5fc0e486c3
commit
c063a4016e
5 files changed
+311
-126
No files matched your search
@@ -1399,27 +1399,11 @@ func (a *Account) GetOpenAIBaseURL() string {
|
||||
return baseURL
|
||||
}
|
||||
}
|
||||
// 平台默认 base_url:CN 供应商按 account_mode 选择 payg / coding 默认值。
|
||||
switch a.Platform {
|
||||
case PlatformKimi:
|
||||
if a.GetAccountMode() == AccountModeCoding {
|
||||
return DefaultKimiCodingBaseURL
|
||||
}
|
||||
return DefaultKimiPayGBaseURL
|
||||
case PlatformZhipu:
|
||||
if a.GetAccountMode() == AccountModeCoding {
|
||||
return DefaultZhipuCodingBaseURL
|
||||
}
|
||||
return DefaultZhipuPayGBaseURL
|
||||
case PlatformDeepseek:
|
||||
return DefaultDeepseekBaseURL
|
||||
case PlatformMiniMax:
|
||||
return DefaultMiniMaxBaseURL
|
||||
case PlatformOpenCodeGo:
|
||||
return a.openCodeDefaultChatBaseURL()
|
||||
default:
|
||||
return "https://api.openai.com"
|
||||
// 平台默认 base_url:多协议供应商按 account_mode 查 provider profile。
|
||||
if baseURL := a.defaultProviderBaseURL(APIProtocolChatCompletions); baseURL != "" {
|
||||
return baseURL
|
||||
}
|
||||
return "https://api.openai.com"
|
||||
}
|
||||
|
||||
// GetAccountMode 返回国产供应商账号的接入模式(payg / coding);非国产供应商或未设置时
|
||||
@@ -1470,15 +1454,8 @@ func (a *Account) GetAPIProtocol() string {
|
||||
// DeepSeek 官方为 /responses(无 /v1);Kimi 按量付费与 Coding Plan 均为
|
||||
// /v1/responses(moonshot.cn / kimi.com/coding);MiniMax 为 /v1/responses。
|
||||
func (a *Account) SupportsNativeCNResponses() bool {
|
||||
if a == nil {
|
||||
return false
|
||||
}
|
||||
switch a.Platform {
|
||||
case PlatformDeepseek, PlatformKimi, PlatformMiniMax, PlatformOpenCodeGo:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
profile := a.providerProfile()
|
||||
return profile != nil && profile.NativeResponses
|
||||
}
|
||||
|
||||
// UsesNativeCNResponses 报告当前账号是否应按原生 Responses 协议转发
|
||||
@@ -1519,48 +1496,7 @@ func (a *Account) GetCNProtocolBaseURL(protocol string) string {
|
||||
}
|
||||
}
|
||||
}
|
||||
return a.defaultCNProtocolBaseURL(protocol)
|
||||
}
|
||||
|
||||
func (a *Account) defaultCNProtocolBaseURL(protocol string) string {
|
||||
switch protocol {
|
||||
case APIProtocolAnthropic:
|
||||
switch a.Platform {
|
||||
case PlatformKimi:
|
||||
if a.GetAccountMode() == AccountModeCoding {
|
||||
return DefaultKimiCodingAnthropicBaseURL
|
||||
}
|
||||
return DefaultKimiPayGAnthropicBaseURL
|
||||
case PlatformZhipu:
|
||||
return DefaultZhipuAnthropicBaseURL
|
||||
case PlatformDeepseek:
|
||||
return DefaultDeepseekAnthropicBaseURL
|
||||
case PlatformMiniMax:
|
||||
return DefaultMiniMaxAnthropicBaseURL
|
||||
case PlatformOpenCodeGo:
|
||||
return a.openCodeDefaultAnthropicBaseURL()
|
||||
}
|
||||
case APIProtocolChatCompletions, APIProtocolResponses:
|
||||
switch a.Platform {
|
||||
case PlatformKimi:
|
||||
if a.GetAccountMode() == AccountModeCoding {
|
||||
return DefaultKimiCodingBaseURL
|
||||
}
|
||||
return DefaultKimiPayGBaseURL
|
||||
case PlatformZhipu:
|
||||
if a.GetAccountMode() == AccountModeCoding {
|
||||
return DefaultZhipuCodingBaseURL
|
||||
}
|
||||
return DefaultZhipuPayGBaseURL
|
||||
case PlatformDeepseek:
|
||||
return DefaultDeepseekBaseURL
|
||||
case PlatformMiniMax:
|
||||
return DefaultMiniMaxBaseURL
|
||||
case PlatformOpenCodeGo:
|
||||
return a.openCodeDefaultChatBaseURL()
|
||||
}
|
||||
}
|
||||
return ""
|
||||
return a.defaultProviderBaseURL(protocol)
|
||||
}
|
||||
|
||||
// IsAnthropicProtocol 报告账号是否以原生 Anthropic 协议接入上游
|
||||
@@ -1584,23 +1520,7 @@ func (a *Account) GetAnthropicProtocolBaseURL() string {
|
||||
return baseURL
|
||||
}
|
||||
}
|
||||
switch a.Platform {
|
||||
case PlatformKimi:
|
||||
if a.GetAccountMode() == AccountModeCoding {
|
||||
return DefaultKimiCodingAnthropicBaseURL
|
||||
}
|
||||
return DefaultKimiPayGAnthropicBaseURL
|
||||
case PlatformZhipu:
|
||||
return DefaultZhipuAnthropicBaseURL
|
||||
case PlatformDeepseek:
|
||||
return DefaultDeepseekAnthropicBaseURL
|
||||
case PlatformMiniMax:
|
||||
return DefaultMiniMaxAnthropicBaseURL
|
||||
case PlatformOpenCodeGo:
|
||||
return a.openCodeDefaultAnthropicBaseURL()
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
return a.defaultProviderBaseURL(APIProtocolAnthropic)
|
||||
}
|
||||
|
||||
// GetOpenAIFormatBaseURL 返回供 OpenAI 格式端点(/v1/models、/v1/chat/completions
|
||||
@@ -1612,26 +1532,10 @@ func (a *Account) GetOpenAIFormatBaseURL() string {
|
||||
if a == nil || !a.IsAnthropicProtocol() {
|
||||
return a.GetOpenAIBaseURL()
|
||||
}
|
||||
switch a.Platform {
|
||||
case PlatformKimi:
|
||||
if a.GetAccountMode() == AccountModeCoding {
|
||||
return DefaultKimiCodingBaseURL
|
||||
}
|
||||
return DefaultKimiPayGBaseURL
|
||||
case PlatformZhipu:
|
||||
if a.GetAccountMode() == AccountModeCoding {
|
||||
return DefaultZhipuCodingBaseURL
|
||||
}
|
||||
return DefaultZhipuPayGBaseURL
|
||||
case PlatformDeepseek:
|
||||
return DefaultDeepseekBaseURL
|
||||
case PlatformMiniMax:
|
||||
return DefaultMiniMaxBaseURL
|
||||
case PlatformOpenCodeGo:
|
||||
return a.openCodeDefaultChatBaseURL()
|
||||
default:
|
||||
return a.GetOpenAIBaseURL()
|
||||
if baseURL := a.defaultProviderBaseURL(APIProtocolChatCompletions); baseURL != "" {
|
||||
return baseURL
|
||||
}
|
||||
return a.GetOpenAIBaseURL()
|
||||
}
|
||||
|
||||
// GetCNAPIKey 返回国产 OpenAI 兼容供应商账号的 api_key 凭据(kimi/zhipu/deepseek)。
|
||||
|
||||
@@ -118,8 +118,9 @@ func IsOpenCodeGo(platform string) bool {
|
||||
|
||||
// IsMultiProtocolAPIKeyProvider 报告 platform 是否为多协议 API Key 网关
|
||||
// (国产供应商 + OpenCode):走 OpenAI 网关、支持 adaptive 协议分流。
|
||||
// 归属以 provider profile 登记为准(见 provider_profile.go)。
|
||||
func IsMultiProtocolAPIKeyProvider(platform string) bool {
|
||||
return IsCNProvider(platform) || platform == PlatformOpenCodeGo
|
||||
return LookupProviderProfile(platform) != nil
|
||||
}
|
||||
|
||||
// AllowedQuotaPlatforms 是允许设置 user × platform quota 的平台列表(单一权威来源)。
|
||||
|
||||
@@ -133,11 +133,9 @@ func DefaultOpenCodeZenProtocolRules() []OpenCodeGoProtocolRule {
|
||||
}
|
||||
}
|
||||
|
||||
// defaultOpenCodeProtocolRules 从 provider profile 取该接入模式的内置分流表。
|
||||
func defaultOpenCodeProtocolRules(mode string) []OpenCodeGoProtocolRule {
|
||||
if mode == AccountModeZen {
|
||||
return DefaultOpenCodeZenProtocolRules()
|
||||
}
|
||||
return DefaultOpenCodeGoProtocolRules()
|
||||
return LookupProviderProfile(PlatformOpenCodeGo).Endpoints(mode).ProtocolRules
|
||||
}
|
||||
|
||||
func isNativeOpenCodeGoProtocol(protocol string) bool {
|
||||
@@ -308,20 +306,6 @@ func (a *Account) IsOpenCodeGoPlan() bool {
|
||||
return a.GetOpenCodeAccountMode() == AccountModeGo
|
||||
}
|
||||
|
||||
func (a *Account) openCodeDefaultChatBaseURL() string {
|
||||
if a.IsOpenCodeZen() {
|
||||
return DefaultOpenCodeZenBaseURL
|
||||
}
|
||||
return DefaultOpenCodeGoBaseURL
|
||||
}
|
||||
|
||||
func (a *Account) openCodeDefaultAnthropicBaseURL() string {
|
||||
if a.IsOpenCodeZen() {
|
||||
return DefaultOpenCodeZenAnthropicBaseURL
|
||||
}
|
||||
return DefaultOpenCodeGoAnthropicBaseURL
|
||||
}
|
||||
|
||||
func (a *Account) IsMultiProtocolAPIKey() bool {
|
||||
return a != nil && IsMultiProtocolAPIKeyProvider(a.Platform)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
package service
|
||||
|
||||
import "strings"
|
||||
|
||||
// ProviderEndpoints 是多协议 API Key 供应商在某个接入模式下的官方默认端点与
|
||||
// 内置分流规则。账号凭证里的 base_url / api_base_urls / protocol_rules 仍优先于这里。
|
||||
type ProviderEndpoints struct {
|
||||
// ChatBaseURL 供 Chat Completions / Responses / models 共用。
|
||||
ChatBaseURL string
|
||||
// AnthropicBaseURL 是 Anthropic 协议基址,上游路径为 {base}/v1/messages。
|
||||
AnthropicBaseURL string
|
||||
// ProtocolRules 是按模型分流的内置默认表(首条命中生效);为空表示该模式
|
||||
// 不按模型分流,由账号 api_protocol 决定上游协议。
|
||||
ProtocolRules []OpenCodeGoProtocolRule
|
||||
}
|
||||
|
||||
// ProviderProfile 描述一个多协议 API Key 供应商(国产厂商或多模型聚合平台)的
|
||||
// 静态数据:各接入模式的默认端点、能力开关与内置分流规则。
|
||||
// 额度解析、会话头等行为差异不在这里,仍由各自的代码路径处理。
|
||||
type ProviderProfile struct {
|
||||
Platform string
|
||||
// DefaultMode 在 credentials.account_mode 缺失或不在 Modes 中时使用。
|
||||
DefaultMode string
|
||||
Modes map[string]ProviderEndpoints
|
||||
// NativeResponses 表示上游提供原生 Responses 端点。
|
||||
NativeResponses bool
|
||||
}
|
||||
|
||||
// Endpoints 返回指定接入模式的端点;未知模式回落 DefaultMode。
|
||||
func (p *ProviderProfile) Endpoints(mode string) ProviderEndpoints {
|
||||
if p == nil {
|
||||
return ProviderEndpoints{}
|
||||
}
|
||||
if endpoints, ok := p.Modes[strings.TrimSpace(mode)]; ok {
|
||||
return endpoints
|
||||
}
|
||||
return p.Modes[p.DefaultMode]
|
||||
}
|
||||
|
||||
// DefaultBaseURL 返回指定接入模式与上游协议的官方默认基址;协议未知时为空串。
|
||||
func (p *ProviderProfile) DefaultBaseURL(mode, protocol string) string {
|
||||
endpoints := p.Endpoints(mode)
|
||||
switch protocol {
|
||||
case APIProtocolAnthropic:
|
||||
return endpoints.AnthropicBaseURL
|
||||
case APIProtocolChatCompletions, APIProtocolResponses:
|
||||
return endpoints.ChatBaseURL
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
// providerProfiles 是多协议 API Key 供应商的单一数据来源。新增同类供应商时在此
|
||||
// 登记一条即可获得默认端点、Responses 能力判定与 IsMultiProtocolAPIKeyProvider 归属。
|
||||
// 默认端点需与前端 credentialsBuilder.ts 的预设保持一致。
|
||||
var providerProfiles = map[string]*ProviderProfile{
|
||||
PlatformKimi: {
|
||||
Platform: PlatformKimi,
|
||||
DefaultMode: AccountModePayG,
|
||||
NativeResponses: true,
|
||||
Modes: map[string]ProviderEndpoints{
|
||||
AccountModePayG: {
|
||||
ChatBaseURL: DefaultKimiPayGBaseURL,
|
||||
AnthropicBaseURL: DefaultKimiPayGAnthropicBaseURL,
|
||||
},
|
||||
AccountModeCoding: {
|
||||
ChatBaseURL: DefaultKimiCodingBaseURL,
|
||||
AnthropicBaseURL: DefaultKimiCodingAnthropicBaseURL,
|
||||
},
|
||||
},
|
||||
},
|
||||
PlatformZhipu: {
|
||||
Platform: PlatformZhipu,
|
||||
DefaultMode: AccountModePayG,
|
||||
Modes: map[string]ProviderEndpoints{
|
||||
AccountModePayG: {
|
||||
ChatBaseURL: DefaultZhipuPayGBaseURL,
|
||||
AnthropicBaseURL: DefaultZhipuAnthropicBaseURL,
|
||||
},
|
||||
AccountModeCoding: {
|
||||
ChatBaseURL: DefaultZhipuCodingBaseURL,
|
||||
AnthropicBaseURL: DefaultZhipuAnthropicBaseURL,
|
||||
},
|
||||
},
|
||||
},
|
||||
PlatformDeepseek: {
|
||||
Platform: PlatformDeepseek,
|
||||
DefaultMode: AccountModePayG,
|
||||
NativeResponses: true,
|
||||
Modes: map[string]ProviderEndpoints{
|
||||
AccountModePayG: {
|
||||
ChatBaseURL: DefaultDeepseekBaseURL,
|
||||
AnthropicBaseURL: DefaultDeepseekAnthropicBaseURL,
|
||||
},
|
||||
},
|
||||
},
|
||||
PlatformMiniMax: {
|
||||
Platform: PlatformMiniMax,
|
||||
DefaultMode: AccountModePayG,
|
||||
NativeResponses: true,
|
||||
Modes: map[string]ProviderEndpoints{
|
||||
// 按量付费与 Coding/Token Plan 共用推理域名,靠 API Key 区分套餐。
|
||||
AccountModePayG: {
|
||||
ChatBaseURL: DefaultMiniMaxBaseURL,
|
||||
AnthropicBaseURL: DefaultMiniMaxAnthropicBaseURL,
|
||||
},
|
||||
AccountModeCoding: {
|
||||
ChatBaseURL: DefaultMiniMaxBaseURL,
|
||||
AnthropicBaseURL: DefaultMiniMaxAnthropicBaseURL,
|
||||
},
|
||||
},
|
||||
},
|
||||
PlatformOpenCodeGo: {
|
||||
Platform: PlatformOpenCodeGo,
|
||||
DefaultMode: AccountModeGo,
|
||||
NativeResponses: true,
|
||||
Modes: map[string]ProviderEndpoints{
|
||||
AccountModeGo: {
|
||||
ChatBaseURL: DefaultOpenCodeGoBaseURL,
|
||||
AnthropicBaseURL: DefaultOpenCodeGoAnthropicBaseURL,
|
||||
ProtocolRules: DefaultOpenCodeGoProtocolRules(),
|
||||
},
|
||||
AccountModeZen: {
|
||||
ChatBaseURL: DefaultOpenCodeZenBaseURL,
|
||||
AnthropicBaseURL: DefaultOpenCodeZenAnthropicBaseURL,
|
||||
ProtocolRules: DefaultOpenCodeZenProtocolRules(),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// LookupProviderProfile 返回 platform 对应的多协议供应商 profile;非此类平台返回 nil。
|
||||
func LookupProviderProfile(platform string) *ProviderProfile {
|
||||
return providerProfiles[platform]
|
||||
}
|
||||
|
||||
func (a *Account) providerProfile() *ProviderProfile {
|
||||
if a == nil {
|
||||
return nil
|
||||
}
|
||||
return LookupProviderProfile(a.Platform)
|
||||
}
|
||||
|
||||
// defaultProviderBaseURL 按账号 account_mode 返回多协议供应商指定协议的官方默认基址;
|
||||
// 非多协议供应商或协议未知时为空串。
|
||||
func (a *Account) defaultProviderBaseURL(protocol string) string {
|
||||
profile := a.providerProfile()
|
||||
if profile == nil {
|
||||
return ""
|
||||
}
|
||||
return profile.DefaultBaseURL(a.GetCredential("account_mode"), protocol)
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
//go:build unit
|
||||
|
||||
package service
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// legacyProviderDefaultBaseURL 复述 provider profile 引入前 account.go 中逐平台
|
||||
// switch 的默认端点逻辑,作为等价性基准。
|
||||
func legacyProviderDefaultBaseURL(platform, mode, protocol string) string {
|
||||
coding := mode == AccountModeCoding
|
||||
zen := mode == AccountModeZen
|
||||
switch protocol {
|
||||
case APIProtocolAnthropic:
|
||||
switch platform {
|
||||
case PlatformKimi:
|
||||
if coding {
|
||||
return DefaultKimiCodingAnthropicBaseURL
|
||||
}
|
||||
return DefaultKimiPayGAnthropicBaseURL
|
||||
case PlatformZhipu:
|
||||
return DefaultZhipuAnthropicBaseURL
|
||||
case PlatformDeepseek:
|
||||
return DefaultDeepseekAnthropicBaseURL
|
||||
case PlatformMiniMax:
|
||||
return DefaultMiniMaxAnthropicBaseURL
|
||||
case PlatformOpenCodeGo:
|
||||
if zen {
|
||||
return DefaultOpenCodeZenAnthropicBaseURL
|
||||
}
|
||||
return DefaultOpenCodeGoAnthropicBaseURL
|
||||
}
|
||||
case APIProtocolChatCompletions, APIProtocolResponses:
|
||||
switch platform {
|
||||
case PlatformKimi:
|
||||
if coding {
|
||||
return DefaultKimiCodingBaseURL
|
||||
}
|
||||
return DefaultKimiPayGBaseURL
|
||||
case PlatformZhipu:
|
||||
if coding {
|
||||
return DefaultZhipuCodingBaseURL
|
||||
}
|
||||
return DefaultZhipuPayGBaseURL
|
||||
case PlatformDeepseek:
|
||||
return DefaultDeepseekBaseURL
|
||||
case PlatformMiniMax:
|
||||
return DefaultMiniMaxBaseURL
|
||||
case PlatformOpenCodeGo:
|
||||
if zen {
|
||||
return DefaultOpenCodeZenBaseURL
|
||||
}
|
||||
return DefaultOpenCodeGoBaseURL
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func TestProviderProfile_DefaultBaseURLsMatchLegacySwitches(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
platforms := []string{PlatformKimi, PlatformZhipu, PlatformDeepseek, PlatformMiniMax, PlatformOpenCodeGo}
|
||||
modes := []string{"", AccountModePayG, AccountModeCoding, AccountModeZen, AccountModeGo, " coding ", "unknown"}
|
||||
|
||||
for _, platform := range platforms {
|
||||
for _, mode := range modes {
|
||||
legacyMode := mode
|
||||
if legacyMode == " coding " {
|
||||
legacyMode = AccountModeCoding
|
||||
}
|
||||
newAccount := func(protocol string) *Account {
|
||||
return &Account{
|
||||
Platform: platform,
|
||||
Type: AccountTypeAPIKey,
|
||||
Credentials: map[string]any{
|
||||
"api_key": "sk-test",
|
||||
"account_mode": mode,
|
||||
"api_protocol": protocol,
|
||||
},
|
||||
}
|
||||
}
|
||||
name := platform + "/" + mode
|
||||
|
||||
chat := newAccount(APIProtocolChatCompletions)
|
||||
require.Equal(t, legacyProviderDefaultBaseURL(platform, legacyMode, APIProtocolChatCompletions), chat.GetOpenAIBaseURL(), name)
|
||||
|
||||
anthropic := newAccount(APIProtocolAnthropic)
|
||||
require.Equal(t, legacyProviderDefaultBaseURL(platform, legacyMode, APIProtocolAnthropic), anthropic.GetAnthropicProtocolBaseURL(), name)
|
||||
require.Equal(t, legacyProviderDefaultBaseURL(platform, legacyMode, APIProtocolChatCompletions), anthropic.GetOpenAIFormatBaseURL(), name)
|
||||
|
||||
adaptive := newAccount(APIProtocolAdaptive)
|
||||
for _, protocol := range []string{APIProtocolChatCompletions, APIProtocolResponses, APIProtocolAnthropic, "unknown"} {
|
||||
require.Equal(t, legacyProviderDefaultBaseURL(platform, legacyMode, protocol), adaptive.GetCNProtocolBaseURL(protocol), name+"/"+protocol)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestProviderProfile_ProfilesMatchMultiProtocolPlatforms(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
for _, platform := range []string{
|
||||
PlatformAnthropic, PlatformOpenAI, PlatformGemini, PlatformAntigravity, PlatformGrok,
|
||||
PlatformKimi, PlatformZhipu, PlatformDeepseek, PlatformMiniMax, PlatformOpenCodeGo, PlatformComposite, "",
|
||||
} {
|
||||
want := IsCNProvider(platform) || platform == PlatformOpenCodeGo
|
||||
require.Equal(t, want, IsMultiProtocolAPIKeyProvider(platform), platform)
|
||||
require.Equal(t, want, LookupProviderProfile(platform) != nil, platform)
|
||||
}
|
||||
|
||||
for platform, profile := range providerProfiles {
|
||||
require.Equal(t, platform, profile.Platform)
|
||||
_, ok := profile.Modes[profile.DefaultMode]
|
||||
require.True(t, ok, "%s default mode %q must be registered", platform, profile.DefaultMode)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProviderProfile_NativeResponsesMatchesLegacy(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
legacy := map[string]bool{
|
||||
PlatformDeepseek: true,
|
||||
PlatformKimi: true,
|
||||
PlatformMiniMax: true,
|
||||
PlatformOpenCodeGo: true,
|
||||
}
|
||||
for _, platform := range []string{PlatformOpenAI, PlatformGrok, PlatformKimi, PlatformZhipu, PlatformDeepseek, PlatformMiniMax, PlatformOpenCodeGo} {
|
||||
account := &Account{Platform: platform, Type: AccountTypeAPIKey}
|
||||
require.Equal(t, legacy[platform], account.SupportsNativeCNResponses(), platform)
|
||||
}
|
||||
require.False(t, (*Account)(nil).SupportsNativeCNResponses())
|
||||
}
|
||||
|
||||
func TestProviderProfile_OpenCodeProtocolRulesByMode(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
require.Equal(t, DefaultOpenCodeGoProtocolRules(), defaultOpenCodeProtocolRules(AccountModeGo))
|
||||
require.Equal(t, DefaultOpenCodeGoProtocolRules(), defaultOpenCodeProtocolRules(""))
|
||||
require.Equal(t, DefaultOpenCodeZenProtocolRules(), defaultOpenCodeProtocolRules(AccountModeZen))
|
||||
require.Empty(t, LookupProviderProfile(PlatformKimi).Endpoints(AccountModeCoding).ProtocolRules)
|
||||
}
|
||||
Reference in new issue
Block a user