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>
213 lines
10 KiB
Go
213 lines
10 KiB
Go
package domain
|
||
|
||
// Status constants
|
||
const (
|
||
StatusActive = "active"
|
||
StatusDisabled = "disabled"
|
||
StatusError = "error"
|
||
StatusUnused = "unused"
|
||
StatusUsed = "used"
|
||
StatusExpired = "expired"
|
||
)
|
||
|
||
// Role constants
|
||
const (
|
||
RoleAdmin = "admin"
|
||
RoleUser = "user"
|
||
)
|
||
|
||
// Platform constants
|
||
const (
|
||
PlatformAnthropic = "anthropic"
|
||
PlatformOpenAI = "openai"
|
||
PlatformGemini = "gemini"
|
||
PlatformAntigravity = "antigravity"
|
||
PlatformGrok = "grok"
|
||
// 国产 OpenAI 兼容供应商(经 OpenAI 网关转发,按 Chat Completions 协议)。
|
||
PlatformKimi = "kimi" // Kimi (月之暗面 / Moonshot)
|
||
PlatformZhipu = "zhipu" // 智谱 GLM (bigmodel)
|
||
PlatformDeepseek = "deepseek" // DeepSeek
|
||
PlatformMiniMax = "minimax" // MiniMax (M 系列)
|
||
PlatformTypeSafe = "typesafe" // TypeSafe AI System One (Jev)
|
||
// PlatformOpenCodeGo 是 OpenCode 平台(账号类型 Zen 按量 / Go 订阅)。
|
||
// 值保持 opencode_go 以兼容已落库的账号、分组、配额与 Composite 路由。
|
||
PlatformOpenCodeGo = "opencode_go"
|
||
// PlatformCommandCode 是 Command Code Provider API(多模型聚合,积分计费,
|
||
// 订阅套餐另有 5 小时 / 每周滚动窗口)。
|
||
PlatformCommandCode = "command_code"
|
||
// PlatformCline 是 Cline API(多模型聚合,OpenAI 兼容 Chat Completions;按量积分计费,
|
||
// 另有 ClinePass 订阅)。
|
||
PlatformCline = "cline"
|
||
PlatformComposite = "composite"
|
||
)
|
||
|
||
// Account mode constants 区分国产供应商的「按量付费(余额)」与「Coding Plan」两种接入方式。
|
||
// 存储于 credentials["account_mode"],决定 base_url 预设与额度监控方式。
|
||
const (
|
||
AccountModePayG = "payg" // 按量付费:消耗余额,做余额检测冷却
|
||
AccountModeCoding = "coding" // Coding Plan:滚动用量窗口冷却(5h / weekly)
|
||
AccountModeZen = "zen" // OpenCode Zen:按量付费,https://opencode.ai/zen/v1
|
||
AccountModeGo = "go" // OpenCode Go:订阅额度窗口,https://opencode.ai/zen/go/v1
|
||
)
|
||
|
||
// API protocol constants 国产供应商的上游 API 协议维度。存储于
|
||
// credentials["api_protocol"],与 account_mode 正交:协议决定转发端点与格式,
|
||
// 模式决定额度监控方式。同协议请求零转换直通;跨协议组合才走转换链。
|
||
const (
|
||
APIProtocolChatCompletions = "chat_completions" // OpenAI Chat Completions(默认)
|
||
APIProtocolAnthropic = "anthropic" // 原生 Anthropic /v1/messages(适配 Claude Code)
|
||
APIProtocolResponses = "responses" // OpenAI Responses(deepseek / kimi / minimax 原生端点,适配 Codex)
|
||
APIProtocolAdaptive = "adaptive" // 按入站协议优先选择供应商原生端点
|
||
)
|
||
|
||
// Account type constants
|
||
const (
|
||
AccountTypeOAuth = "oauth" // OAuth类型账号(full scope: profile + inference)
|
||
AccountTypeSetupToken = "setup-token" // Setup Token类型账号(inference only scope)
|
||
AccountTypeAPIKey = "apikey" // API Key类型账号
|
||
AccountTypeUpstream = "upstream" // 上游透传类型账号(通过 Base URL + API Key 连接上游)
|
||
AccountTypeBedrock = "bedrock" // AWS Bedrock 类型账号(通过 SigV4 签名或 API Key 连接 Bedrock,由 credentials.auth_mode 区分)
|
||
AccountTypeServiceAccount = "service_account" // Google Service Account 类型账号(用于 Vertex AI)
|
||
)
|
||
|
||
// Redeem type constants
|
||
const (
|
||
RedeemTypeBalance = "balance"
|
||
RedeemTypeConcurrency = "concurrency"
|
||
RedeemTypeSubscription = "subscription"
|
||
RedeemTypeInvitation = "invitation"
|
||
)
|
||
|
||
// PromoCode status constants
|
||
const (
|
||
PromoCodeStatusActive = "active"
|
||
PromoCodeStatusDisabled = "disabled"
|
||
)
|
||
|
||
// Admin adjustment type constants
|
||
const (
|
||
AdjustmentTypeAdminBalance = "admin_balance" // 管理员调整余额
|
||
AdjustmentTypeAdminConcurrency = "admin_concurrency" // 管理员调整并发数
|
||
)
|
||
|
||
// Group subscription type constants
|
||
const (
|
||
SubscriptionTypeStandard = "standard" // 标准计费模式(按余额扣费)
|
||
SubscriptionTypeSubscription = "subscription" // 订阅模式(按限额控制)
|
||
)
|
||
|
||
// Subscription status constants
|
||
const (
|
||
SubscriptionStatusActive = "active"
|
||
SubscriptionStatusExpired = "expired"
|
||
SubscriptionStatusSuspended = "suspended"
|
||
)
|
||
|
||
// AntigravityGemini31ProAgentModel is the upstream route for Gemini 3.1 Pro High.
|
||
const AntigravityGemini31ProAgentModel = "gemini-pro-agent"
|
||
|
||
// DefaultAntigravityModelMapping 是 Antigravity 平台的默认模型映射
|
||
// 当账号未配置 model_mapping 时使用此默认值
|
||
// 与前端 useModelWhitelist.ts 中的 antigravityDefaultMappings 保持一致
|
||
var DefaultAntigravityModelMapping = map[string]string{
|
||
// Claude 白名单
|
||
"claude-fable-5-1": "claude-fable-5-1", // 官方模型
|
||
"claude-fable-5": "claude-fable-5", // 官方模型
|
||
"claude-opus-4-8": "claude-opus-4-8", // 官方模型
|
||
"claude-opus-4-7": "claude-opus-4-7", // 官方模型
|
||
"claude-opus-4-6-thinking": "claude-opus-4-6-thinking", // 官方模型
|
||
"claude-opus-4-6": "claude-opus-4-6-thinking", // 简称映射
|
||
"claude-opus-4-5-thinking": "claude-opus-4-6-thinking", // 迁移旧模型
|
||
"claude-sonnet-4-6": "claude-sonnet-4-6",
|
||
"claude-sonnet-4-5": "claude-sonnet-4-5", // 显式 canonical 选择透传
|
||
"claude-sonnet-4-5-thinking": "claude-sonnet-4-6", // 迁移旧兼容别名
|
||
// Claude 详细版本 ID 映射
|
||
"claude-opus-4-5-20251101": "claude-opus-4-6-thinking", // 迁移旧模型
|
||
"claude-sonnet-4-5-20250929": "claude-sonnet-4-6", // 迁移旧模型
|
||
// Claude Haiku → Sonnet(无 Haiku 支持)
|
||
"claude-haiku-4-5": "claude-sonnet-4-6",
|
||
"claude-haiku-4-5-20251001": "claude-sonnet-4-6",
|
||
// Gemini 2.5 白名单
|
||
"gemini-2.5-flash": "gemini-2.5-flash",
|
||
"gemini-2.5-flash-image": "gemini-2.5-flash-image",
|
||
"gemini-2.5-flash-image-preview": "gemini-2.5-flash-image",
|
||
"gemini-2.5-flash-lite": "gemini-2.5-flash-lite",
|
||
"gemini-2.5-flash-thinking": "gemini-2.5-flash-thinking",
|
||
"gemini-2.5-pro": "gemini-2.5-pro",
|
||
// Gemini 3 白名单
|
||
"gemini-3-flash": "gemini-3-flash",
|
||
"gemini-3-pro-high": "gemini-3-pro-high",
|
||
"gemini-3-pro-low": "gemini-3-pro-low",
|
||
// Gemini 3 preview 映射
|
||
"gemini-3-flash-preview": "gemini-3-flash",
|
||
"gemini-3-pro-preview": "gemini-3-pro-high",
|
||
// Gemini 3.1 白名单
|
||
AntigravityGemini31ProAgentModel: AntigravityGemini31ProAgentModel,
|
||
"gemini-3.1-pro": AntigravityGemini31ProAgentModel,
|
||
"gemini-3.1-pro-high": AntigravityGemini31ProAgentModel,
|
||
"gemini-3.1-pro-low": "gemini-3.1-pro-low",
|
||
// Gemini 3.1 preview 映射
|
||
"gemini-3.1-pro-preview": AntigravityGemini31ProAgentModel,
|
||
// Gemini 3.1 image 白名单
|
||
"gemini-3.1-flash-image": "gemini-3.1-flash-image",
|
||
// Gemini 3.1 image preview 映射
|
||
"gemini-3.1-flash-image-preview": "gemini-3.1-flash-image",
|
||
// Gemini 3.6 Flash tiered models
|
||
"gemini-3.6-flash": "gemini-3.6-flash",
|
||
"gemini-3.6-flash-high": "gemini-3.6-flash-high",
|
||
"gemini-3.6-flash-low": "gemini-3.6-flash-low",
|
||
"gemini-3.6-flash-medium": "gemini-3.6-flash-medium",
|
||
"gemini-3.6-flash-tiered": "gemini-3.6-flash-tiered",
|
||
// Gemini 3.7 Flash tiered models
|
||
"gemini-3.7-flash": "gemini-3.7-flash",
|
||
"gemini-3.7-flash-high": "gemini-3.7-flash-high",
|
||
"gemini-3.7-flash-low": "gemini-3.7-flash-low",
|
||
"gemini-3.7-flash-medium": "gemini-3.7-flash-medium",
|
||
"gemini-3.7-flash-tiered": "gemini-3.7-flash-tiered",
|
||
// Gemini 3.8 Flash tiered models
|
||
"gemini-3.8-flash": "gemini-3.8-flash",
|
||
"gemini-3.8-flash-high": "gemini-3.8-flash-high",
|
||
"gemini-3.8-flash-low": "gemini-3.8-flash-low",
|
||
"gemini-3.8-flash-medium": "gemini-3.8-flash-medium",
|
||
"gemini-3.8-flash-tiered": "gemini-3.8-flash-tiered",
|
||
// Gemini 3 image 兼容映射(向 3.1 image 迁移)
|
||
"gemini-3-pro-image": "gemini-3.1-flash-image",
|
||
"gemini-3-pro-image-preview": "gemini-3.1-flash-image",
|
||
// 其他官方模型
|
||
"gpt-oss-120b-medium": "gpt-oss-120b-medium",
|
||
"tab_flash_lite_preview": "tab_flash_lite_preview",
|
||
}
|
||
|
||
// DefaultBedrockModelMapping 是 AWS Bedrock 平台的默认模型映射
|
||
// 将 Anthropic 标准模型名映射到 Bedrock 模型 ID
|
||
// 注意:此处的 "us." 前缀仅为默认值,ResolveBedrockModelID 会根据账号配置的
|
||
// aws_region 自动调整为匹配的区域前缀(如 eu.、apac.、jp. 等)
|
||
var DefaultBedrockModelMapping = map[string]string{
|
||
// Claude Fable
|
||
"claude-fable-5-1": "anthropic.claude-fable-5-1",
|
||
"claude-fable-5": "anthropic.claude-fable-5",
|
||
// Claude Opus
|
||
"claude-opus-5": "us.anthropic.claude-opus-5-v1",
|
||
"claude-opus-4-8": "us.anthropic.claude-opus-4-8-v1",
|
||
"claude-opus-4-7": "us.anthropic.claude-opus-4-7-v1",
|
||
"claude-opus-4-6-thinking": "us.anthropic.claude-opus-4-6-v1",
|
||
"claude-opus-4-6": "us.anthropic.claude-opus-4-6-v1",
|
||
"claude-opus-4-5-thinking": "us.anthropic.claude-opus-4-5-20251101-v1:0",
|
||
"claude-opus-4-5-20251101": "us.anthropic.claude-opus-4-5-20251101-v1:0",
|
||
"claude-opus-4-1": "us.anthropic.claude-opus-4-1-20250805-v1:0",
|
||
"claude-opus-4-20250514": "us.anthropic.claude-opus-4-20250514-v1:0",
|
||
// Claude Sonnet
|
||
// Sonnet 5.5 is available on bedrock-runtime through Global inference only.
|
||
"claude-sonnet-5-5": "global.anthropic.claude-sonnet-5-5",
|
||
"claude-sonnet-5": "us.anthropic.claude-sonnet-5-v1",
|
||
"claude-sonnet-4-6-thinking": "us.anthropic.claude-sonnet-4-6",
|
||
"claude-sonnet-4-6": "us.anthropic.claude-sonnet-4-6",
|
||
"claude-sonnet-4-5": "us.anthropic.claude-sonnet-4-5-20250929-v1:0",
|
||
"claude-sonnet-4-5-thinking": "us.anthropic.claude-sonnet-4-5-20250929-v1:0",
|
||
"claude-sonnet-4-5-20250929": "us.anthropic.claude-sonnet-4-5-20250929-v1:0",
|
||
"claude-sonnet-4-20250514": "us.anthropic.claude-sonnet-4-20250514-v1:0",
|
||
// Claude Haiku
|
||
"claude-haiku-4-5": "us.anthropic.claude-haiku-4-5-20251001-v1:0",
|
||
"claude-haiku-4-5-20251001": "us.anthropic.claude-haiku-4-5-20251001-v1:0",
|
||
}
|