mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-14 03:52:26 +08:00
Cline API(https://api.cline.bot/api/v1)是 OpenAI 兼容的多模型聚合端点, 只提供 Chat Completions(Cline 自己的客户端同样只走该端点),模型名带厂商 前缀。同一个 API Key 下有两个互不影响的额度来源,由模型名决定扣哪一边: cline-pass/* 走 ClinePass 订阅(5 小时 / 7 天 / 30 天滚动上限),其余付费 模型扣账户积分;cline-free/* 免费模型只有逐模型的每日额度。 转发: - 平台清单与 provider profile 新增 cline:按入站协议分流,只登记 Chat Completions 端点,Responses / Anthropic 入站由现有转换链转为 Chat Completions,无需新增转发代码。 - 只有一个接入模式,不需要选择账号类型。 - 连接测试未指定模型时使用 profile 默认模型(固定 Chat Completions 的账号 此前落到不带厂商前缀的通用默认模型);订阅了 ClinePass 的账号改用订阅 模型,不消耗积分,ClinePass 冷却中时仍用按量模型。 用量与余额:API Key 调 /api/v1/users/me/plan/usage-limits(三档窗口的已用 百分比与重置时间,未订阅时 404)与 /api/v1/users/me、/users/{id}/balance (余额单位为百万分之一积分,1 积分 = 1 美元),兼容 {success, data} 信封, 只查官方主机。复用额度探测与周期检测:账号列表显示 ClinePass 窗口与积分 余额;窗口用满时 ClinePass 模型冷却到重置时间,未订阅时不调度 ClinePass 模型,积分低于阈值时冷却付费模型;数据显示恢复后自动解除,但只解除探测能 证明已恢复的原因(窗口用满、未订阅、积分不足),组织账户、所需订阅档位、推理 额度与花费上限的冷却到期后由请求重新确认。周期检测中走账号接口探测的平台 改为登记表(平台、支持判定、检测函数一一对应),按账号所属平台分派。 上游错误(依据 docs.cline.bot/api/errors 与 Cline 客户端的错误分类,按文案 识别):积分不足(含其他 402)、组织花费上限、推理额度上限、ClinePass 超限、 未订阅 ClinePass / 组织账户、免费模型每日额度。两边的超限只冷却请求模型所属 的一边(模型级冷却键 cline:pass / cline:credits,调度按请求模型检查),不停 整个账号;免费模型只限该模型,冷却到文案中的 "try again in …"。ClinePass 超限冷却到快照中对应窗口的重置时间,没有快照时 5 小时窗口 1 小时、7 天 6 小时、30 天 24 小时。普通频率限制走默认 429 逻辑。402 的冷却写入失败时 也不落入默认分支永久置 error(探测只覆盖激活账号,置 error 后无法自动恢复)。 余额类冷却时长抽为 cnBalanceCheckCooldown 共用。 上游计费探测的官方域名加入 cline.bot。 前端:官方标志(机器人头像)、violet 配色(品牌紫)、复用额度与余额单元格 (同样只对官方主机上的 API Key 账号显示);接入模式展示名抽为共用函数,编辑 弹窗不再显示原始模式值。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
75 lines
3.0 KiB
Go
75 lines
3.0 KiB
Go
package domain
|
||
|
||
import (
|
||
"testing"
|
||
|
||
"github.com/stretchr/testify/require"
|
||
)
|
||
|
||
// 重构前各处手写的平台列表,作为平台清单派生结果的等价基准;重构后新登记的平台
|
||
// (Command Code、Cline)按同类平台(OpenCode)的位置补入。
|
||
var (
|
||
legacyDisplayOrder = []string{
|
||
PlatformAnthropic, PlatformOpenAI, PlatformGemini, PlatformAntigravity, PlatformGrok,
|
||
PlatformKimi, PlatformZhipu, PlatformDeepseek, PlatformMiniMax, PlatformOpenCodeGo, PlatformTypeSafe,
|
||
PlatformCommandCode,
|
||
PlatformCline,
|
||
}
|
||
legacyCompositePrecedence = []string{
|
||
PlatformAnthropic, PlatformGemini, PlatformOpenAI, PlatformAntigravity, PlatformGrok,
|
||
PlatformKimi, PlatformZhipu, PlatformDeepseek, PlatformMiniMax, PlatformOpenCodeGo, PlatformTypeSafe,
|
||
PlatformCommandCode,
|
||
PlatformCline,
|
||
}
|
||
legacyOpenAIGateway = []string{
|
||
PlatformOpenAI, PlatformGrok, PlatformKimi, PlatformZhipu, PlatformDeepseek, PlatformMiniMax, PlatformOpenCodeGo,
|
||
PlatformCommandCode,
|
||
PlatformCline,
|
||
}
|
||
legacyCNProviders = []string{PlatformKimi, PlatformZhipu, PlatformDeepseek, PlatformMiniMax}
|
||
legacyLiteLLMByPlatf = map[string]string{
|
||
PlatformAnthropic: "anthropic", PlatformOpenAI: "openai", PlatformGemini: "gemini",
|
||
PlatformAntigravity: "anthropic", PlatformGrok: "xai", PlatformKimi: "moonshot",
|
||
PlatformZhipu: "zhipu", PlatformDeepseek: "deepseek", PlatformMiniMax: "minimax",
|
||
PlatformOpenCodeGo: "opencode-go", PlatformTypeSafe: "typesafe", PlatformCommandCode: "", PlatformCline: "",
|
||
}
|
||
)
|
||
|
||
func TestPlatformListMatchesLegacyLists(t *testing.T) {
|
||
require.Equal(t, legacyDisplayOrder, ConcretePlatformIDs())
|
||
require.Equal(t, legacyCompositePrecedence, CompositePrecedencePlatformIDs())
|
||
require.Equal(t, legacyOpenAIGateway, PlatformIDsWhere(func(spec PlatformSpec) bool {
|
||
return spec.Gateway == PlatformGatewayOpenAI
|
||
}))
|
||
require.Equal(t, legacyCNProviders, PlatformIDsWhere(func(spec PlatformSpec) bool { return spec.CNProvider }))
|
||
for platform, provider := range legacyLiteLLMByPlatf {
|
||
spec, ok := LookupPlatform(platform)
|
||
require.True(t, ok, platform)
|
||
require.Equal(t, provider, spec.LiteLLMProvider, platform)
|
||
}
|
||
}
|
||
|
||
func TestPlatformListPredicates(t *testing.T) {
|
||
for _, platform := range legacyDisplayOrder {
|
||
require.True(t, IsConcretePlatform(platform), platform)
|
||
require.True(t, IsGroupPlatform(platform), platform)
|
||
spec, ok := LookupPlatform(platform)
|
||
require.True(t, ok, platform)
|
||
require.NotEmpty(t, spec.DisplayName, platform)
|
||
require.NotEmpty(t, spec.Gateway, platform)
|
||
}
|
||
require.False(t, IsConcretePlatform(PlatformComposite))
|
||
require.True(t, IsGroupPlatform(PlatformComposite))
|
||
for _, invalid := range []string{"", "moonshot", "Kimi", "openai ", "glm", "bogus"} {
|
||
require.False(t, IsConcretePlatform(invalid), invalid)
|
||
require.False(t, IsGroupPlatform(invalid), invalid)
|
||
require.False(t, UsesOpenAIGateway(invalid), invalid)
|
||
}
|
||
}
|
||
|
||
func TestPlatformsReturnsCopy(t *testing.T) {
|
||
platforms := Platforms()
|
||
platforms[0].ID = "mutated"
|
||
require.Equal(t, PlatformAnthropic, Platforms()[0].ID)
|
||
}
|