domain_constants.go 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  1. package service
  2. import (
  3. "fmt"
  4. "github.com/Wei-Shaw/sub2api/internal/domain"
  5. )
  6. // Status constants
  7. const (
  8. StatusActive = domain.StatusActive
  9. StatusDisabled = domain.StatusDisabled
  10. StatusError = domain.StatusError
  11. StatusUnused = domain.StatusUnused
  12. StatusUsed = domain.StatusUsed
  13. StatusExpired = domain.StatusExpired
  14. )
  15. // Role constants
  16. const (
  17. RoleAdmin = domain.RoleAdmin
  18. RoleSuperAdmin = domain.RoleSuperAdmin
  19. RoleUser = domain.RoleUser
  20. )
  21. // Affiliate rebate settings
  22. const (
  23. AffiliateRebateRateDefault = 20.0
  24. AffiliateRebateRateMin = 0.0
  25. AffiliateRebateRateMax = 100.0
  26. AffiliateEnabledDefault = false // 邀请返利总开关默认关闭
  27. AffiliateRebateFreezeHoursDefault = 0 // 0 = 不冻结(向后兼容)
  28. AffiliateRebateFreezeHoursMax = 720 // 最大 30 天
  29. AffiliateRebateDurationDaysDefault = 0 // 0 = 永久有效
  30. AffiliateRebateDurationDaysMax = 3650 // ~10 年
  31. AffiliateRebatePerInviteeCapDefault = 0.0 // 0 = 无上限
  32. AdminRechargeRebateEnabledDefault = false // 管理员充值默认不产生返利
  33. )
  34. // Platform constants
  35. const (
  36. PlatformAnthropic = domain.PlatformAnthropic
  37. PlatformOpenAI = domain.PlatformOpenAI
  38. PlatformGemini = domain.PlatformGemini
  39. PlatformAntigravity = domain.PlatformAntigravity
  40. PlatformGrok = domain.PlatformGrok
  41. // 国产 OpenAI 兼容供应商(与 grok 一样经 OpenAI 网关转发)。
  42. PlatformKimi = domain.PlatformKimi
  43. PlatformZhipu = domain.PlatformZhipu
  44. PlatformDeepseek = domain.PlatformDeepseek
  45. PlatformMiniMax = domain.PlatformMiniMax
  46. PlatformComposite = domain.PlatformComposite
  47. // PlatformKiro is retained for unsupported-platform threshold tests and legacy
  48. // account rows. Scheduling-threshold evaluation never pauses kiro accounts.
  49. PlatformKiro = "kiro"
  50. )
  51. // 账号接入模式(国产供应商):按量付费 vs Coding Plan。
  52. const (
  53. AccountModePayG = domain.AccountModePayG
  54. AccountModeCoding = domain.AccountModeCoding
  55. )
  56. // 上游 API 协议(国产供应商):决定转发端点与格式,与接入模式正交。
  57. const (
  58. APIProtocolChatCompletions = domain.APIProtocolChatCompletions
  59. APIProtocolAnthropic = domain.APIProtocolAnthropic
  60. APIProtocolResponses = domain.APIProtocolResponses
  61. APIProtocolAdaptive = domain.APIProtocolAdaptive
  62. )
  63. // 国产 OpenAI 兼容供应商各模式的默认 base_url。
  64. // 与前端 credentialsBuilder.ts 中的预设保持一致。
  65. const (
  66. DefaultKimiPayGBaseURL = "https://api.moonshot.cn/v1"
  67. DefaultKimiCodingBaseURL = "https://api.kimi.com/coding/v1"
  68. DefaultZhipuPayGBaseURL = "https://open.bigmodel.cn/api/paas/v4"
  69. DefaultZhipuCodingBaseURL = "https://open.bigmodel.cn/api/coding/paas/v4"
  70. DefaultDeepseekBaseURL = "https://api.deepseek.com"
  71. // MiniMax 按量付费与 Coding/Token Plan 共用推理域名,靠 API Key 区分套餐。
  72. DefaultMiniMaxBaseURL = "https://api.minimaxi.com/v1"
  73. )
  74. // 国产供应商 Anthropic 协议端点的默认 base_url(上游路径为 {base}/v1/messages)。
  75. // 与前端 credentialsBuilder.ts 中的预设保持一致。
  76. const (
  77. DefaultKimiPayGAnthropicBaseURL = "https://api.moonshot.cn/anthropic"
  78. DefaultKimiCodingAnthropicBaseURL = "https://api.kimi.com/coding"
  79. DefaultZhipuAnthropicBaseURL = "https://open.bigmodel.cn/api/anthropic"
  80. DefaultDeepseekAnthropicBaseURL = "https://api.deepseek.com/anthropic"
  81. DefaultMiniMaxAnthropicBaseURL = "https://api.minimaxi.com/anthropic"
  82. )
  83. // IsCNProvider 报告 platform 是否为国产 OpenAI 兼容供应商(kimi/zhipu/deepseek/minimax)。
  84. func IsCNProvider(platform string) bool {
  85. switch platform {
  86. case PlatformKimi, PlatformZhipu, PlatformDeepseek, PlatformMiniMax:
  87. return true
  88. default:
  89. return false
  90. }
  91. }
  92. // AllowedQuotaPlatforms 是允许设置 user × platform quota 的平台列表(单一权威来源)。
  93. // ent/schema/user_platform_quota.go 的 Validate 函数独立维护(构建期约束),
  94. // 若新增平台需同步修改该 schema。
  95. var AllowedQuotaPlatforms = []string{
  96. PlatformAnthropic,
  97. PlatformOpenAI,
  98. PlatformGemini,
  99. PlatformAntigravity,
  100. PlatformGrok,
  101. PlatformKimi,
  102. PlatformZhipu,
  103. PlatformDeepseek,
  104. PlatformMiniMax,
  105. }
  106. // AllowedSchedulingThresholdPlatforms 是允许设置账号自动停调阈值的平台列表。
  107. // openai/anthropic/grok 有原生用量窗口;kimi/zhipu/minimax 的 Coding Plan 同样暴露
  108. // 5h/weekly 滚动窗口,纳入阈值评估。deepseek 为余额型,走余额检测而非阈值。
  109. var AllowedSchedulingThresholdPlatforms = []string{
  110. PlatformOpenAI,
  111. PlatformAnthropic,
  112. PlatformGrok,
  113. PlatformKimi,
  114. PlatformZhipu,
  115. PlatformMiniMax,
  116. }
  117. // IsAllowedQuotaPlatform 报告 s 是否为合法的 quota platform 标识。
  118. func IsAllowedQuotaPlatform(s string) bool {
  119. for _, p := range AllowedQuotaPlatforms {
  120. if p == s {
  121. return true
  122. }
  123. }
  124. return false
  125. }
  126. // Account type constants
  127. const (
  128. AccountTypeOAuth = domain.AccountTypeOAuth // OAuth类型账号(full scope: profile + inference)
  129. AccountTypeSetupToken = domain.AccountTypeSetupToken // Setup Token类型账号(inference only scope)
  130. AccountTypeAPIKey = domain.AccountTypeAPIKey // API Key类型账号
  131. AccountTypeUpstream = domain.AccountTypeUpstream // 上游透传类型账号(通过 Base URL + API Key 连接上游)
  132. AccountTypeBedrock = domain.AccountTypeBedrock // AWS Bedrock 类型账号(通过 SigV4 签名或 API Key 连接 Bedrock,由 credentials.auth_mode 区分)
  133. AccountTypeServiceAccount = domain.AccountTypeServiceAccount // Google Service Account 类型账号(用于 Vertex AI)
  134. )
  135. // Redeem type constants
  136. const (
  137. RedeemTypeBalance = domain.RedeemTypeBalance
  138. RedeemTypeConcurrency = domain.RedeemTypeConcurrency
  139. RedeemTypeSubscription = domain.RedeemTypeSubscription
  140. RedeemTypeInvitation = domain.RedeemTypeInvitation
  141. RedeemTypeAffiliateBalance = "affiliate_balance"
  142. )
  143. // PromoCode status constants
  144. const (
  145. PromoCodeStatusActive = domain.PromoCodeStatusActive
  146. PromoCodeStatusDisabled = domain.PromoCodeStatusDisabled
  147. )
  148. // Admin adjustment type constants
  149. const (
  150. AdjustmentTypeAdminBalance = domain.AdjustmentTypeAdminBalance // 管理员调整余额
  151. AdjustmentTypeAdminConcurrency = domain.AdjustmentTypeAdminConcurrency // 管理员调整并发数
  152. )
  153. // Group subscription type constants
  154. const (
  155. SubscriptionTypeStandard = domain.SubscriptionTypeStandard // 标准计费模式(按余额扣费)
  156. SubscriptionTypeSubscription = domain.SubscriptionTypeSubscription // 订阅模式(按限额控制)
  157. )
  158. // Subscription status constants
  159. const (
  160. SubscriptionStatusActive = domain.SubscriptionStatusActive
  161. SubscriptionStatusExpired = domain.SubscriptionStatusExpired
  162. SubscriptionStatusSuspended = domain.SubscriptionStatusSuspended
  163. // SubscriptionStatusRevoked 是 soft-deleted 订阅的 API 展示态,不写入 status 字段。
  164. SubscriptionStatusRevoked = "revoked"
  165. )
  166. // LinuxDoConnectSyntheticEmailDomain 是 LinuxDo Connect 用户的合成邮箱后缀(RFC 保留域名)。
  167. const LinuxDoConnectSyntheticEmailDomain = "@linuxdo-connect.invalid"
  168. // OIDCConnectSyntheticEmailDomain 是 OIDC 用户的合成邮箱后缀(RFC 保留域名)。
  169. const OIDCConnectSyntheticEmailDomain = "@oidc-connect.invalid"
  170. // WeChatConnectSyntheticEmailDomain 是 WeChat Connect 用户的合成邮箱后缀(RFC 保留域名)。
  171. const WeChatConnectSyntheticEmailDomain = "@wechat-connect.invalid"
  172. // DingTalkConnectSyntheticEmailDomain 是 DingTalk Connect 用户的合成邮箱后缀(RFC 保留域名)。
  173. const DingTalkConnectSyntheticEmailDomain = "@dingtalk-connect.invalid"
  174. // Setting keys
  175. const (
  176. // 注册设置
  177. SettingKeyRegistrationEnabled = "registration_enabled" // 是否开放注册
  178. SettingKeyEmailVerifyEnabled = "email_verify_enabled" // 是否开启邮件验证
  179. SettingKeyRegistrationEmailSuffixWhitelist = "registration_email_suffix_whitelist" // 注册邮箱后缀白名单(JSON 数组)
  180. // 白名单非空时,是否放行非白名单域名按主域名限量注册(每域名 1 个账户)。
  181. // 默认 false:非白名单域名直接拒绝(白名单严格模式)。
  182. SettingKeyRegistrationEmailDomainQuotaEnabled = "registration_email_domain_quota_enabled"
  183. SettingKeyPromoCodeEnabled = "promo_code_enabled" // 是否启用优惠码功能
  184. SettingKeyPasswordResetEnabled = "password_reset_enabled" // 是否启用忘记密码功能(需要先开启邮件验证)
  185. SettingKeyFrontendURL = "frontend_url" // 前端基础URL,用于生成邮件中的重置密码链接
  186. SettingKeyInvitationCodeEnabled = "invitation_code_enabled" // 是否启用邀请码注册
  187. SettingKeyAffiliateEnabled = "affiliate_enabled" // 邀请返利功能总开关
  188. SettingKeyAffiliateRebateRate = "affiliate_rebate_rate" // 邀请返利比例(百分比,0-100)
  189. SettingKeyAffiliateRebateFreezeHours = "affiliate_rebate_freeze_hours" // 返利冻结期(小时,0=不冻结)
  190. SettingKeyAffiliateRebateDurationDays = "affiliate_rebate_duration_days" // 返利有效期(天,0=永久)
  191. SettingKeyAffiliateRebatePerInviteeCap = "affiliate_rebate_per_invitee_cap" // 单人返利上限(0=无上限)
  192. SettingKeyAffiliateAdminRechargeEnabled = "affiliate_admin_recharge_enabled" // 管理员充值是否产生返利
  193. SettingKeyRiskControlEnabled = "risk_control_enabled" // 是否启用风控中心入口与审计链路
  194. SettingKeyContentModerationConfig = "content_moderation_config" // 内容审计配置(JSON)
  195. SettingKeyCyberSessionBlockEnabled = "cyber_session_block_enabled" // cyber 命中后会话级自动屏蔽总开关(默认关)
  196. SettingKeyCyberSessionBlockTTLSeconds = "cyber_session_block_ttl_seconds" // 会话屏蔽 TTL 秒数(默认 3600)
  197. SettingKeyLoginAgreementEnabled = "login_agreement_enabled" // 登录前是否要求同意条款
  198. SettingKeyLoginAgreementMode = "login_agreement_mode" // 条款确认展示模式:modal / checkbox
  199. SettingKeyLoginAgreementUpdatedAt = "login_agreement_updated_at" // 条款更新日期(展示用)
  200. SettingKeyLoginAgreementDocuments = "login_agreement_documents" // 条款文档列表(JSON,Markdown 内容)
  201. // 邮件服务设置
  202. SettingKeySMTPHost = "smtp_host" // SMTP服务器地址
  203. SettingKeySMTPPort = "smtp_port" // SMTP端口
  204. SettingKeySMTPUsername = "smtp_username" // SMTP用户名
  205. SettingKeySMTPPassword = "smtp_password" // SMTP密码(加密存储)
  206. SettingKeySMTPFrom = "smtp_from" // 发件人地址
  207. SettingKeySMTPFromName = "smtp_from_name" // 发件人名称
  208. SettingKeySMTPUseTLS = "smtp_use_tls" // 是否使用TLS
  209. // Cloudflare Turnstile 设置
  210. SettingKeyTurnstileEnabled = "turnstile_enabled" // 是否启用 Turnstile 验证
  211. SettingKeyTurnstileSiteKey = "turnstile_site_key" // Turnstile Site Key
  212. SettingKeyTurnstileSecretKey = "turnstile_secret_key" // Turnstile Secret Key
  213. // 腾讯天御验证码设置
  214. SettingKeyTencentCaptchaEnabled = "tencent_captcha_enabled"
  215. SettingKeyTencentCaptchaAppID = "tencent_captcha_app_id"
  216. SettingKeyTencentCaptchaAppSecretKey = "tencent_captcha_app_secret_key"
  217. SettingKeyTencentCaptchaCloudSecretID = "tencent_captcha_cloud_secret_id"
  218. SettingKeyTencentCaptchaCloudSecretKey = "tencent_captcha_cloud_secret_key"
  219. SettingKeyTencentCaptchaRegion = "tencent_captcha_region" // 站点:"cn"|"intl",决定前端 SDK 脚本与服务端接入点
  220. // 阿里云验证码 2.0 设置(与 Turnstile、腾讯天御互斥,同一时间仅可启用一家)
  221. SettingKeyAliyunCaptchaEnabled = "aliyun_captcha_enabled" // 是否启用阿里云验证码
  222. SettingKeyAliyunCaptchaAccessKeyID = "aliyun_captcha_access_key_id" // 阿里云 AccessKey ID
  223. SettingKeyAliyunCaptchaAccessKeySecret = "aliyun_captcha_access_key_secret" // 阿里云 AccessKey Secret
  224. SettingKeyAliyunCaptchaSceneID = "aliyun_captcha_scene_id" // 验证场景 ID(所有认证流程共用)
  225. SettingKeyAliyunCaptchaPrefix = "aliyun_captcha_prefix" // 身份标,前端 SDK 初始化用
  226. SettingKeyAliyunCaptchaRegion = "aliyun_captcha_region" // 地域:"cn"|"sgp",决定前端脚本区域与服务端接入点
  227. // API Key IP 访问控制设置
  228. SettingKeyAPIKeyACLTrustForwardedIP = "api_key_acl_trust_forwarded_ip" // API Key IP 白/黑名单是否信任转发 IP
  229. SettingKeyForwardedClientIPHeaders = "forwarded_client_ip_headers" // 自定义 CDN 客户端 IP 请求头(JSON 数组)
  230. settingKeyForwardedClientIPModeV2 = "forwarded_client_ip_mode_v2_migrated"
  231. // TOTP 双因素认证设置
  232. SettingKeyTotpEnabled = "totp_enabled" // 是否启用 TOTP 2FA 功能
  233. SettingKeyPasskeyEnabled = "passkey_enabled" // 是否启用 Passkey 登录(仍要求有效的 WebAuthn 部署配置)
  234. // 会话安全设置
  235. SettingKeySessionBindingEnabled = "session_binding_enabled" // 会话 IP/UA 绑定(变更即失效),默认关闭
  236. // 敏感操作 step-up 2FA 设置
  237. SettingKeyStepUpEnabled = "step_up_enabled" // 敏感操作(导出/备份/S3配置/提升管理员等)要求 step-up 2FA,默认关闭
  238. // 面板 API 限流设置(JSON:PanelRateLimitSettings)
  239. SettingKeyPanelRateLimitSettings = "panel_rate_limit_settings"
  240. // 操作审计日志设置
  241. SettingKeyAuditLogRetentionDays = "audit_log_retention_days" // 审计日志保留天数(<=0 永久保留),默认 180
  242. // LinuxDo Connect OAuth 登录设置
  243. SettingKeyLinuxDoConnectEnabled = "linuxdo_connect_enabled"
  244. SettingKeyLinuxDoConnectClientID = "linuxdo_connect_client_id"
  245. SettingKeyLinuxDoConnectClientSecret = "linuxdo_connect_client_secret"
  246. SettingKeyLinuxDoConnectRedirectURL = "linuxdo_connect_redirect_url"
  247. // DingTalk Connect OAuth 登录设置
  248. SettingKeyDingTalkConnectEnabled = "dingtalk_connect_enabled"
  249. SettingKeyDingTalkConnectClientID = "dingtalk_connect_client_id"
  250. SettingKeyDingTalkConnectClientSecret = "dingtalk_connect_client_secret"
  251. SettingKeyDingTalkConnectRedirectURL = "dingtalk_connect_redirect_url"
  252. SettingKeyDingTalkConnectCorpRestrictionPolicy = "dingtalk_connect_corp_restriction_policy"
  253. SettingKeyDingTalkConnectInternalCorpID = "dingtalk_connect_internal_corp_id"
  254. SettingKeyDingTalkConnectBypassRegistration = "dingtalk_connect_bypass_registration"
  255. SettingKeyDingTalkConnectSyncCorpEmail = "dingtalk_connect_sync_corp_email"
  256. SettingKeyDingTalkConnectSyncDisplayName = "dingtalk_connect_sync_display_name"
  257. SettingKeyDingTalkConnectSyncDept = "dingtalk_connect_sync_dept"
  258. SettingKeyDingTalkConnectSyncCorpEmailAttrKey = "dingtalk_connect_sync_corp_email_attr_key"
  259. SettingKeyDingTalkConnectSyncDisplayNameAttrKey = "dingtalk_connect_sync_display_name_attr_key"
  260. SettingKeyDingTalkConnectSyncDeptAttrKey = "dingtalk_connect_sync_dept_attr_key"
  261. SettingKeyDingTalkConnectSyncCorpEmailAttrName = "dingtalk_connect_sync_corp_email_attr_name"
  262. SettingKeyDingTalkConnectSyncDisplayNameAttrName = "dingtalk_connect_sync_display_name_attr_name"
  263. SettingKeyDingTalkConnectSyncDeptAttrName = "dingtalk_connect_sync_dept_attr_name"
  264. // WeChat Connect OAuth 登录设置
  265. SettingKeyWeChatConnectEnabled = "wechat_connect_enabled"
  266. SettingKeyWeChatConnectAppID = "wechat_connect_app_id"
  267. SettingKeyWeChatConnectAppSecret = "wechat_connect_app_secret"
  268. SettingKeyWeChatConnectOpenAppID = "wechat_connect_open_app_id"
  269. SettingKeyWeChatConnectOpenAppSecret = "wechat_connect_open_app_secret"
  270. SettingKeyWeChatConnectMPAppID = "wechat_connect_mp_app_id"
  271. SettingKeyWeChatConnectMPAppSecret = "wechat_connect_mp_app_secret"
  272. SettingKeyWeChatConnectMobileAppID = "wechat_connect_mobile_app_id"
  273. SettingKeyWeChatConnectMobileAppSecret = "wechat_connect_mobile_app_secret"
  274. SettingKeyWeChatConnectOpenEnabled = "wechat_connect_open_enabled"
  275. SettingKeyWeChatConnectMPEnabled = "wechat_connect_mp_enabled"
  276. SettingKeyWeChatConnectMobileEnabled = "wechat_connect_mobile_enabled"
  277. SettingKeyWeChatConnectMode = "wechat_connect_mode"
  278. SettingKeyWeChatConnectScopes = "wechat_connect_scopes"
  279. SettingKeyWeChatConnectRedirectURL = "wechat_connect_redirect_url"
  280. SettingKeyWeChatConnectFrontendRedirectURL = "wechat_connect_frontend_redirect_url"
  281. // Generic OIDC OAuth 登录设置
  282. SettingKeyOIDCConnectEnabled = "oidc_connect_enabled"
  283. SettingKeyOIDCConnectProviderName = "oidc_connect_provider_name"
  284. SettingKeyOIDCConnectClientID = "oidc_connect_client_id"
  285. SettingKeyOIDCConnectClientSecret = "oidc_connect_client_secret"
  286. SettingKeyOIDCConnectIssuerURL = "oidc_connect_issuer_url"
  287. SettingKeyOIDCConnectDiscoveryURL = "oidc_connect_discovery_url"
  288. SettingKeyOIDCConnectAuthorizeURL = "oidc_connect_authorize_url"
  289. SettingKeyOIDCConnectTokenURL = "oidc_connect_token_url"
  290. SettingKeyOIDCConnectUserInfoURL = "oidc_connect_userinfo_url"
  291. SettingKeyOIDCConnectJWKSURL = "oidc_connect_jwks_url"
  292. SettingKeyOIDCConnectScopes = "oidc_connect_scopes"
  293. SettingKeyOIDCConnectRedirectURL = "oidc_connect_redirect_url"
  294. SettingKeyOIDCConnectFrontendRedirectURL = "oidc_connect_frontend_redirect_url"
  295. SettingKeyOIDCConnectTokenAuthMethod = "oidc_connect_token_auth_method"
  296. SettingKeyOIDCConnectUsePKCE = "oidc_connect_use_pkce"
  297. SettingKeyOIDCConnectValidateIDToken = "oidc_connect_validate_id_token"
  298. SettingKeyOIDCConnectAllowedSigningAlgs = "oidc_connect_allowed_signing_algs"
  299. SettingKeyOIDCConnectClockSkewSeconds = "oidc_connect_clock_skew_seconds"
  300. SettingKeyOIDCConnectRequireEmailVerified = "oidc_connect_require_email_verified"
  301. SettingKeyOIDCConnectUserInfoEmailPath = "oidc_connect_userinfo_email_path"
  302. SettingKeyOIDCConnectUserInfoIDPath = "oidc_connect_userinfo_id_path"
  303. SettingKeyOIDCConnectUserInfoUsernamePath = "oidc_connect_userinfo_username_path"
  304. // GitHub / Google 邮箱快捷登录设置
  305. SettingKeyGitHubOAuthEnabled = "github_oauth_enabled"
  306. SettingKeyGitHubOAuthClientID = "github_oauth_client_id"
  307. SettingKeyGitHubOAuthClientSecret = "github_oauth_client_secret"
  308. SettingKeyGitHubOAuthRedirectURL = "github_oauth_redirect_url"
  309. SettingKeyGitHubOAuthFrontendRedirectURL = "github_oauth_frontend_redirect_url"
  310. SettingKeyGoogleOAuthEnabled = "google_oauth_enabled"
  311. SettingKeyGoogleOAuthClientID = "google_oauth_client_id"
  312. SettingKeyGoogleOAuthClientSecret = "google_oauth_client_secret"
  313. SettingKeyGoogleOAuthRedirectURL = "google_oauth_redirect_url"
  314. SettingKeyGoogleOAuthFrontendRedirectURL = "google_oauth_frontend_redirect_url"
  315. // OEM设置
  316. SettingKeySiteName = "site_name" // 网站名称
  317. SettingKeySiteLogo = "site_logo" // 网站Logo (base64)
  318. SettingKeySiteSubtitle = "site_subtitle" // 网站副标题
  319. SettingKeyAPIBaseURL = "api_base_url" // API端点地址(用于客户端配置和导入)
  320. SettingKeyContactInfo = "contact_info" // 客服联系方式
  321. SettingKeyDocURL = "doc_url" // 文档链接
  322. SettingKeyHomeContent = "home_content" // 首页内容(支持 Markdown/HTML,或 URL 作为 iframe src)
  323. SettingKeyCompactHomeEnabled = "compact_home_enabled" // 是否启用内置简洁首页
  324. SettingKeyHideCcsImportButton = "hide_ccs_import_button" // 是否隐藏 API Keys 页面的导入 CCS 按钮
  325. SettingKeyPurchaseSubscriptionEnabled = "purchase_subscription_enabled" // 是否展示"购买订阅"页面入口
  326. SettingKeyPurchaseSubscriptionURL = "purchase_subscription_url" // "购买订阅"页面 URL(作为 iframe src)
  327. SettingKeyTableDefaultPageSize = "table_default_page_size" // 表格默认每页条数
  328. SettingKeyTablePageSizeOptions = "table_page_size_options" // 表格可选每页条数(JSON 数组)
  329. SettingKeyCustomMenuItems = "custom_menu_items" // 自定义菜单项(JSON 数组)
  330. SettingKeyCustomEndpoints = "custom_endpoints" // 自定义端点列表(JSON 数组)
  331. // 默认配置
  332. SettingKeyDefaultConcurrency = "default_concurrency" // 新用户默认并发量
  333. SettingKeyDefaultBalance = "default_balance" // 新用户默认余额
  334. SettingKeyDefaultSubscriptions = "default_subscriptions" // 新用户默认订阅列表(JSON)
  335. SettingKeyDefaultUserRPMLimit = "default_user_rpm_limit" // 新用户默认 RPM 限制(0 = 不限制)
  336. // 第三方认证来源默认授予配置
  337. SettingKeyAuthSourceDefaultEmailBalance = "auth_source_default_email_balance"
  338. SettingKeyAuthSourceDefaultEmailConcurrency = "auth_source_default_email_concurrency"
  339. SettingKeyAuthSourceDefaultEmailSubscriptions = "auth_source_default_email_subscriptions"
  340. SettingKeyAuthSourceDefaultEmailGrantOnSignup = "auth_source_default_email_grant_on_signup"
  341. SettingKeyAuthSourceDefaultEmailGrantOnFirstBind = "auth_source_default_email_grant_on_first_bind"
  342. SettingKeyAuthSourceDefaultLinuxDoBalance = "auth_source_default_linuxdo_balance"
  343. SettingKeyAuthSourceDefaultLinuxDoConcurrency = "auth_source_default_linuxdo_concurrency"
  344. SettingKeyAuthSourceDefaultLinuxDoSubscriptions = "auth_source_default_linuxdo_subscriptions"
  345. SettingKeyAuthSourceDefaultLinuxDoGrantOnSignup = "auth_source_default_linuxdo_grant_on_signup"
  346. SettingKeyAuthSourceDefaultLinuxDoGrantOnFirstBind = "auth_source_default_linuxdo_grant_on_first_bind"
  347. SettingKeyAuthSourceDefaultOIDCBalance = "auth_source_default_oidc_balance"
  348. SettingKeyAuthSourceDefaultOIDCConcurrency = "auth_source_default_oidc_concurrency"
  349. SettingKeyAuthSourceDefaultOIDCSubscriptions = "auth_source_default_oidc_subscriptions"
  350. SettingKeyAuthSourceDefaultOIDCGrantOnSignup = "auth_source_default_oidc_grant_on_signup"
  351. SettingKeyAuthSourceDefaultOIDCGrantOnFirstBind = "auth_source_default_oidc_grant_on_first_bind"
  352. SettingKeyAuthSourceDefaultWeChatBalance = "auth_source_default_wechat_balance"
  353. SettingKeyAuthSourceDefaultWeChatConcurrency = "auth_source_default_wechat_concurrency"
  354. SettingKeyAuthSourceDefaultWeChatSubscriptions = "auth_source_default_wechat_subscriptions"
  355. SettingKeyAuthSourceDefaultWeChatGrantOnSignup = "auth_source_default_wechat_grant_on_signup"
  356. SettingKeyAuthSourceDefaultWeChatGrantOnFirstBind = "auth_source_default_wechat_grant_on_first_bind"
  357. SettingKeyAuthSourceDefaultGitHubBalance = "auth_source_default_github_balance"
  358. SettingKeyAuthSourceDefaultGitHubConcurrency = "auth_source_default_github_concurrency"
  359. SettingKeyAuthSourceDefaultGitHubSubscriptions = "auth_source_default_github_subscriptions"
  360. SettingKeyAuthSourceDefaultGitHubGrantOnSignup = "auth_source_default_github_grant_on_signup"
  361. SettingKeyAuthSourceDefaultGitHubGrantOnFirstBind = "auth_source_default_github_grant_on_first_bind"
  362. SettingKeyAuthSourceDefaultGoogleBalance = "auth_source_default_google_balance"
  363. SettingKeyAuthSourceDefaultGoogleConcurrency = "auth_source_default_google_concurrency"
  364. SettingKeyAuthSourceDefaultGoogleSubscriptions = "auth_source_default_google_subscriptions"
  365. SettingKeyAuthSourceDefaultGoogleGrantOnSignup = "auth_source_default_google_grant_on_signup"
  366. SettingKeyAuthSourceDefaultGoogleGrantOnFirstBind = "auth_source_default_google_grant_on_first_bind"
  367. SettingKeyAuthSourceDefaultDingTalkBalance = "auth_source_default_dingtalk_balance"
  368. SettingKeyAuthSourceDefaultDingTalkConcurrency = "auth_source_default_dingtalk_concurrency"
  369. SettingKeyAuthSourceDefaultDingTalkSubscriptions = "auth_source_default_dingtalk_subscriptions"
  370. SettingKeyAuthSourceDefaultDingTalkGrantOnSignup = "auth_source_default_dingtalk_grant_on_signup"
  371. SettingKeyAuthSourceDefaultDingTalkGrantOnFirstBind = "auth_source_default_dingtalk_grant_on_first_bind"
  372. SettingKeyForceEmailOnThirdPartySignup = "force_email_on_third_party_signup"
  373. // 管理员 API Key
  374. SettingKeyAdminAPIKey = "admin_api_key" // 全局管理员 API Key(用于外部系统集成)
  375. // Gemini 配额策略(JSON)
  376. SettingKeyGeminiQuotaPolicy = "gemini_quota_policy"
  377. // Model fallback settings
  378. SettingKeyEnableModelFallback = "enable_model_fallback"
  379. SettingKeyFallbackModelAnthropic = "fallback_model_anthropic"
  380. SettingKeyFallbackModelOpenAI = "fallback_model_openai"
  381. SettingKeyFallbackModelGemini = "fallback_model_gemini"
  382. SettingKeyFallbackModelAntigravity = "fallback_model_antigravity"
  383. // Request identity patch (Claude -> Gemini systemInstruction injection)
  384. SettingKeyEnableIdentityPatch = "enable_identity_patch"
  385. SettingKeyIdentityPatchPrompt = "identity_patch_prompt"
  386. // =========================
  387. // Ops Monitoring (vNext)
  388. // =========================
  389. // SettingKeyOpsMonitoringEnabled is a DB-backed soft switch to enable/disable ops module at runtime.
  390. SettingKeyOpsMonitoringEnabled = "ops_monitoring_enabled"
  391. // SettingKeyOpsRealtimeMonitoringEnabled controls realtime features (e.g. WS/QPS push).
  392. SettingKeyOpsRealtimeMonitoringEnabled = "ops_realtime_monitoring_enabled"
  393. // SettingKeyOpsQueryModeDefault controls the default query mode for ops dashboard (auto/raw/preagg).
  394. SettingKeyOpsQueryModeDefault = "ops_query_mode_default"
  395. // SettingKeyOpsEmailNotificationConfig stores JSON config for ops email notifications.
  396. SettingKeyOpsEmailNotificationConfig = "ops_email_notification_config"
  397. // SettingKeyOpsAlertRuntimeSettings stores JSON config for ops alert evaluator runtime settings.
  398. SettingKeyOpsAlertRuntimeSettings = "ops_alert_runtime_settings"
  399. // SettingKeyOpsMetricsIntervalSeconds controls the ops metrics collector interval (>=60).
  400. SettingKeyOpsMetricsIntervalSeconds = "ops_metrics_interval_seconds"
  401. // SettingKeyOpsAdvancedSettings stores JSON config for ops advanced settings (data retention, aggregation).
  402. SettingKeyOpsAdvancedSettings = "ops_advanced_settings"
  403. // SettingKeyOpsRuntimeLogConfig stores JSON config for runtime log settings.
  404. SettingKeyOpsRuntimeLogConfig = "ops_runtime_log_config"
  405. // =========================
  406. // Channel Monitor (渠道监控)
  407. // =========================
  408. // SettingKeyChannelMonitorEnabled is a DB-backed soft switch for the channel monitor feature.
  409. // When false: runner skips scheduling and user-facing endpoints return an empty list.
  410. SettingKeyChannelMonitorEnabled = "channel_monitor_enabled"
  411. // SettingKeyChannelMonitorMode selects exclusive implementation:
  412. // "v1" active probes, "v2" passive aggregation. Default "v1" (opt-in to v2).
  413. SettingKeyChannelMonitorMode = "channel_monitor_mode"
  414. // ChannelMonitorModeV1/V2 are the only accepted mode values.
  415. ChannelMonitorModeV1 = "v1"
  416. ChannelMonitorModeV2 = "v2"
  417. // SettingKeyChannelMonitorDefaultIntervalSeconds controls the default interval (seconds)
  418. // pre-filled when creating a new channel monitor from the admin UI. Range: [15, 3600].
  419. SettingKeyChannelMonitorDefaultIntervalSeconds = "channel_monitor_default_interval_seconds"
  420. // SettingKeyChannelMonitorHideThroughput hides RPM/TPM (and similar absolute
  421. // throughput rates) from non-admin user-facing monitor APIs and UI, so users
  422. // cannot reverse-estimate fleet volume from rates × window length.
  423. // Default false (show rates). Admin endpoints always keep full metrics.
  424. SettingKeyChannelMonitorHideThroughput = "channel_monitor_hide_throughput"
  425. // SettingKeyChannelMonitorShowQuota controls whether quota/balance snapshots
  426. // attached to channel monitors (check_mode=quota/quota_probe) are exposed on
  427. // the user-facing monitor APIs and UI. Default false (hidden); parsed
  428. // fail-closed (only the literal "true" enables it). Admin endpoints always
  429. // keep the full snapshots regardless of this flag.
  430. SettingKeyChannelMonitorShowQuota = "channel_monitor_show_quota"
  431. // SettingKeyChannelMonitorHideUserRanking hides the user ranking tab and
  432. // /users payload from non-admin channel-monitor v2 viewers.
  433. // Default false (keep the current ranking tab). Admin endpoints always keep it.
  434. SettingKeyChannelMonitorHideUserRanking = "channel_monitor_hide_user_ranking"
  435. // SettingKeyGrokDefaultTextModel is the fallback Grok text model for empty
  436. // request models and built-in Grok aliases (e.g. "grok" → this id). Default grok-4.5.
  437. SettingKeyGrokDefaultTextModel = "grok_default_text_model"
  438. // SettingKeyGrokCrossClientModelMapEnabled, when true, includes gpt-*/codex-*/o*/claude-*
  439. // wildcards in the default Grok account model_mapping so foreign client model names
  440. // can reach Grok groups. Default false (no silent cross-vendor rewrite).
  441. SettingKeyGrokCrossClientModelMapEnabled = "grok_cross_client_model_map_enabled"
  442. // SettingKeyGrokDefaultBaseURLMode controls the default text upstream for
  443. // Grok accounts without an explicit credentials.base_url.
  444. SettingKeyGrokDefaultBaseURLMode = "grok_default_base_url_mode"
  445. // SettingKeyAvailableChannelsEnabled is a DB-backed soft switch for the "Available Channels"
  446. // user-facing aggregate view. When false: user endpoint returns an empty list and the
  447. // sidebar entry is hidden. Defaults to false (opt-in feature).
  448. SettingKeyAvailableChannelsEnabled = "available_channels_enabled"
  449. // SettingKeyModelPlazaEnabled is a DB-backed soft switch for the Model Plaza page
  450. // (public group/model pricing showcase). When false: the plaza endpoint returns 404
  451. // and the header entry is hidden. Defaults to false (opt-in feature).
  452. SettingKeyModelPlazaEnabled = "model_plaza_enabled"
  453. // SettingKeyModelPlazaRequireAuth controls whether the Model Plaza page requires a
  454. // logged-in user. When false the page is public and anonymous visitors see only
  455. // non-exclusive groups.
  456. SettingKeyModelPlazaRequireAuth = "model_plaza_require_auth"
  457. // SettingKeyModelPlazaDescription stores the Markdown blurb rendered at the top of
  458. // the Model Plaza page (global pricing notes, exchange rate, promotions, ...).
  459. SettingKeyModelPlazaDescription = "model_plaza_description"
  460. // SettingKeyPluginManagementEnabled controls sidebar visibility only; it does
  461. // not stop or otherwise change already loaded plugin runtimes.
  462. SettingKeyPluginManagementEnabled = "plugin_management_enabled"
  463. // SettingKeyUpstreamBillingProbeSettings stores the global enable switch and interval
  464. // for probing remote Sub2API API-key billing metadata.
  465. SettingKeyUpstreamBillingProbeSettings = "upstream_billing_probe_settings"
  466. // SettingKeyOllamaCloudUsageSettings stores the opt-in global runner switch and interval.
  467. SettingKeyOllamaCloudUsageSettings = "ollama_cloud_usage_settings"
  468. // =========================
  469. // Overload Cooldown (529)
  470. // =========================
  471. // SettingKeyOverloadCooldownSettings stores JSON config for 529 overload cooldown handling.
  472. SettingKeyOverloadCooldownSettings = "overload_cooldown_settings"
  473. // SettingKeyRateLimit429CooldownSettings stores JSON config for 429 fallback cooldown handling.
  474. SettingKeyRateLimit429CooldownSettings = "rate_limit_429_cooldown_settings"
  475. // SettingKeyOpenAIImagesOAuthUnavailableCooldownSettings stores the cooldown applied when the OAuth image tool is unavailable.
  476. SettingKeyOpenAIImagesOAuthUnavailableCooldownSettings = "openai_images_oauth_unavailable_cooldown_settings"
  477. // SettingKeyOpenAIAPIKeyHealthBreakerSettings stores the opt-in OpenAI pool API-key breaker config.
  478. SettingKeyOpenAIAPIKeyHealthBreakerSettings = "openai_apikey_health_breaker_settings"
  479. // =========================
  480. // Stream Timeout Handling
  481. // =========================
  482. // SettingKeyStreamTimeoutSettings stores JSON config for stream timeout handling.
  483. SettingKeyStreamTimeoutSettings = "stream_timeout_settings"
  484. // =========================
  485. // Request Rectifier (请求整流器)
  486. // =========================
  487. // SettingKeyRectifierSettings stores JSON config for rectifier settings (thinking signature + budget).
  488. SettingKeyRectifierSettings = "rectifier_settings"
  489. // =========================
  490. // Beta Policy Settings
  491. // =========================
  492. // SettingKeyBetaPolicySettings stores JSON config for beta policy rules.
  493. SettingKeyBetaPolicySettings = "beta_policy_settings"
  494. // SettingKeyOpenAIFastPolicySettings stores JSON config for OpenAI
  495. // service_tier (fast/flex) policy rules. Mirrors BetaPolicySettings but
  496. // targets OpenAI's body-level service_tier field instead of Claude's
  497. // anthropic-beta header.
  498. SettingKeyOpenAIFastPolicySettings = "openai_fast_policy_settings"
  499. // =========================
  500. // Claude Code Version Check
  501. // =========================
  502. // SettingKeyMinClaudeCodeVersion 最低 Claude Code 版本号要求 (semver, 如 "2.1.0",空值=不检查)
  503. SettingKeyMinClaudeCodeVersion = "min_claude_code_version"
  504. // SettingKeyMinCodexVersion 最低 Codex 引擎版本要求 (semver, 如 "0.141.0",空值=不检查)
  505. SettingKeyMinCodexVersion = "min_codex_version"
  506. // SettingKeyMaxCodexVersion 最高 Codex 引擎版本限制 (semver, 如 "0.200.0",空值=不检查)
  507. SettingKeyMaxCodexVersion = "max_codex_version"
  508. // SettingKeyCodexCLIOnlyBlacklist codex_cli_only 全局黑名单([]AllowedClientEntry JSON,OR deny)。
  509. SettingKeyCodexCLIOnlyBlacklist = "codex_cli_only_blacklist"
  510. // SettingKeyCodexCLIOnlyWhitelist codex_cli_only 全局白名单([]AllowedClientEntry JSON,双因子 AND allow)。
  511. SettingKeyCodexCLIOnlyWhitelist = "codex_cli_only_whitelist"
  512. // SettingKeyCodexCLIOnlyAllowAppServerClients App Server 开关:对未列名客户端开闸(默认 false;仅显式 "true" 开)。
  513. SettingKeyCodexCLIOnlyAllowAppServerClients = "codex_cli_only_allow_app_server_clients"
  514. // SettingKeyCodexCLIOnlyAllowBodyEngineFingerprint 引擎门 body 通道开关:接受 client_metadata 引擎指纹(默认 false;仅显式 "true" 开)。(已废弃,迁移并入信号列表)
  515. SettingKeyCodexCLIOnlyAllowBodyEngineFingerprint = "codex_cli_only_allow_body_engine_fingerprint"
  516. // SettingKeyCodexCLIOnlyEngineFingerprintSignals codex_cli_only 引擎指纹门信号列表([]EngineFingerprintSignal JSON)。
  517. // 勾选(required)信号之间 AND;每条 match 变体行内 OR;缺失/空/非法 → 默认种子(只勾 x-codex-)。
  518. SettingKeyCodexCLIOnlyEngineFingerprintSignals = "codex_cli_only_engine_fingerprint_signals"
  519. // SettingKeyMaxClaudeCodeVersion 最高 Claude Code 版本号限制 (semver, 如 "3.0.0",空值=不检查)
  520. SettingKeyMaxClaudeCodeVersion = "max_claude_code_version"
  521. // SettingKeyAllowUngroupedKeyScheduling 允许未分组 API Key 调度(默认 false:未分组 Key 返回 403)
  522. SettingKeyAllowUngroupedKeyScheduling = "allow_ungrouped_key_scheduling"
  523. // SettingKeyOpenAILowUpstreamRatePriorityEnabled 旧调度是否按上游 token 倍率优先。
  524. SettingKeyOpenAILowUpstreamRatePriorityEnabled = "openai_low_upstream_rate_priority_enabled"
  525. // SettingKeyOpenAIOAuthSchedulingRateMultiplier OAuth 账号参与成本调度时使用的参考倍率。
  526. SettingKeyOpenAIOAuthSchedulingRateMultiplier = "openai_oauth_scheduling_rate_multiplier"
  527. // SettingKeyOpenAIAdvancedSchedulerStickyWeightedEnabled OpenAI 高级调度下是否启用粘性加权。
  528. SettingKeyOpenAIAdvancedSchedulerStickyWeightedEnabled = "openai_advanced_scheduler_sticky_weighted_enabled"
  529. // SettingKeyOpenAIAdvancedSchedulerSubscriptionPriorityEnabled OpenAI 高级调度下是否优先使用订阅账号池。
  530. SettingKeyOpenAIAdvancedSchedulerSubscriptionPriorityEnabled = "openai_advanced_scheduler_subscription_priority_enabled"
  531. SettingKeyOpenAIAdvancedSchedulerLBTopK = "openai_advanced_scheduler_lb_top_k"
  532. SettingKeyOpenAIAdvancedSchedulerWeightPriority = "openai_advanced_scheduler_weight_priority"
  533. SettingKeyOpenAIAdvancedSchedulerWeightLoad = "openai_advanced_scheduler_weight_load"
  534. SettingKeyOpenAIAdvancedSchedulerWeightQueue = "openai_advanced_scheduler_weight_queue"
  535. SettingKeyOpenAIAdvancedSchedulerWeightErrorRate = "openai_advanced_scheduler_weight_error_rate"
  536. SettingKeyOpenAIAdvancedSchedulerWeightTTFT = "openai_advanced_scheduler_weight_ttft"
  537. SettingKeyOpenAIAdvancedSchedulerWeightReset = "openai_advanced_scheduler_weight_reset"
  538. SettingKeyOpenAIAdvancedSchedulerWeightQuotaHeadroom = "openai_advanced_scheduler_weight_quota_headroom"
  539. SettingKeyOpenAIAdvancedSchedulerWeightUpstreamCost = "openai_advanced_scheduler_weight_upstream_cost"
  540. SettingKeyOpenAIAdvancedSchedulerWeightPreviousResponse = "openai_advanced_scheduler_weight_previous_response"
  541. SettingKeyOpenAIAdvancedSchedulerWeightSessionSticky = "openai_advanced_scheduler_weight_session_sticky"
  542. // SettingKeyBackendModeEnabled Backend 模式:禁用用户注册和自助服务,仅管理员可登录
  543. SettingKeyBackendModeEnabled = "backend_mode_enabled"
  544. // Gateway Forwarding Behavior
  545. // SettingKeyOpenAITTFTMode 控制 first_token_ms 的统计口径。
  546. SettingKeyOpenAITTFTMode = "openai_ttft_mode"
  547. OpenAITTFTModeSemantic = "semantic"
  548. OpenAITTFTModeVisible = "visible"
  549. // SettingKeyEnableFingerprintUnification 是否统一 OAuth 账号的 X-Stainless-* 指纹头(默认 true)
  550. SettingKeyEnableFingerprintUnification = "enable_fingerprint_unification"
  551. // SettingKeyEnableMetadataPassthrough 是否透传客户端原始 metadata.user_id(默认 false)
  552. SettingKeyEnableMetadataPassthrough = "enable_metadata_passthrough"
  553. // SettingKeyEnableCCHSigning 已废弃(no-op):新版 Claude Code CLI 已取消 cch 签名字段,
  554. // 网关随之不再注入/签名 cch(见 buildBillingAttributionText)。保留该 key 仅为向后兼容,
  555. // 开关不再产生任何效果。
  556. SettingKeyEnableCCHSigning = "enable_cch_signing"
  557. // SettingKeyEnableClaudeOAuthSystemPromptInjection 是否对 Claude OAuth mimic 路径注入 Claude Code system blocks(默认 true)
  558. SettingKeyEnableClaudeOAuthSystemPromptInjection = "enable_claude_oauth_system_prompt_injection"
  559. // SettingKeyClaudeOAuthSystemPrompt Claude OAuth mimic 路径注入的通用扩展 system prompt(空值使用内置默认)
  560. SettingKeyClaudeOAuthSystemPrompt = "claude_oauth_system_prompt"
  561. // SettingKeyClaudeOAuthSystemPromptBlocks Claude OAuth mimic 路径注入的 system blocks JSON 配置(空值使用内置默认)
  562. SettingKeyClaudeOAuthSystemPromptBlocks = "claude_oauth_system_prompt_blocks"
  563. // SettingKeyEnableAnthropicCacheTTL1hInjection 是否对 Anthropic OAuth/SetupToken 请求体注入 1h cache_control ttl(默认 false)
  564. SettingKeyEnableAnthropicCacheTTL1hInjection = "enable_anthropic_cache_ttl_1h_injection"
  565. // SettingKeyEnableClientDatelineNormalization 是否对 Anthropic OAuth/SetupToken 账号
  566. // 的 /v1/messages 请求体做客户端 dateline 归一化(默认 true)。
  567. // 归一化把 system prompt / <system-reminder> 块中 "Today's date is …" 语句里的
  568. // 非 ASCII 撇号与 "/" 日期分隔符还原为 ASCII 撇号 + "-" 分隔符,抹除某些客户端
  569. // 在检测到非官方 base URL 时注入的 3 bit 隐写指纹。仅适用于 Anthropic OAuth/SetupToken
  570. // 账号;API Key 账号不受影响。
  571. SettingKeyEnableClientDatelineNormalization = "enable_client_dateline_normalization"
  572. // SettingKeyRewriteMessageCacheControl 是否改写 messages[*].content[*].cache_control(默认 false)
  573. SettingKeyRewriteMessageCacheControl = "rewrite_message_cache_control"
  574. // SettingKeyAntigravityUserAgentVersion Antigravity 上游 User-Agent 版本号(空值使用环境变量/默认值)
  575. SettingKeyAntigravityUserAgentVersion = "antigravity_user_agent_version"
  576. // SettingKeyOpenAICodexUserAgent OpenAI Codex 完整 User-Agent(空值使用内置默认)
  577. // 当客户端 UA 被识别为浏览器(Chrome/Firefox/Safari/Edge 等)时,转发给 OpenAI 上游前会替换为此值,
  578. // 用于避免 Cloudflare 对浏览器型 UA 的质询拦截。
  579. SettingKeyOpenAICodexUserAgent = "openai_codex_user_agent"
  580. // SettingKeyOpenAICodexClientVersion 网关对 ChatGPT 上游声明的 Codex 客户端版本号(管理员覆写)。
  581. // 空值表示跟随自动同步值;自动同步也没有结果时回退到内置常量。
  582. // 上游在容量紧张时按客户端身份分优先级降载,陈旧版本会被优先丢弃,故该值需保持跟随官方发布。
  583. SettingKeyOpenAICodexClientVersion = "openai_codex_client_version"
  584. // SettingKeyOpenAICodexClientVersionSynced 自动同步任务写入的官方 Codex 最新稳定版版本号。
  585. // 由 OpenAICodexVersionSyncService 独占写入,面板只读展示;管理员覆写请用
  586. // SettingKeyOpenAICodexClientVersion。
  587. SettingKeyOpenAICodexClientVersionSynced = "openai_codex_client_version_synced"
  588. // SettingKeyOpenAICodexVersionAutoSyncEnabled 是否启用 Codex 客户端版本号自动同步(默认 true)。
  589. SettingKeyOpenAICodexVersionAutoSyncEnabled = "openai_codex_version_auto_sync_enabled"
  590. // SettingKeyOpenAIAllowClaudeCodeCodexPlugin 已废弃:历史全局开关只作为升级迁移输入读取。
  591. // 迁移后等价规则写入 SettingKeyCodexCLIOnlyWhitelist,不再参与运行时判定。
  592. SettingKeyOpenAIAllowClaudeCodeCodexPlugin = "openai_allow_claude_code_codex_plugin"
  593. // 余额不足提醒
  594. SettingKeyBalanceLowNotifyEnabled = "balance_low_notify_enabled" // 全局开关
  595. SettingKeyBalanceLowNotifyThreshold = "balance_low_notify_threshold" // 默认阈值(USD)
  596. SettingKeyBalanceLowNotifyRechargeURL = "balance_low_notify_recharge_url" // 充值页面 URL
  597. // 订阅到期提醒
  598. SettingKeySubscriptionExpiryNotifyEnabled = "subscription_expiry_notify_enabled" // 订阅到期提醒全局开关,默认开启
  599. // 账号限额通知
  600. SettingKeyAccountQuotaNotifyEnabled = "account_quota_notify_enabled" // 全局开关
  601. SettingKeyAccountQuotaNotifyEmails = "account_quota_notify_emails" // 管理员通知邮箱列表(JSON 数组)
  602. // Web Search Emulation
  603. SettingKeyWebSearchEmulationConfig = "web_search_emulation_config" // JSON 配置
  604. )
  605. // SettingKeyDefaultPlatformQuotas —— 系统全局:每用户 × 平台日/周/月 USD 上限(JSON)。
  606. // 值为 map[platform]{daily,weekly,monthly},null/缺省 = 不限制;0 = 禁用;>0 = USD 上限。
  607. const SettingKeyDefaultPlatformQuotas = "default_platform_quotas"
  608. // SettingKeyAccountSchedulingThresholds —— 系统全局:按平台自动停调阈值(JSON map)。
  609. // 值为 map[platform]percent,1..100;100 = 禁用该平台自动停调。
  610. const SettingKeyAccountSchedulingThresholds = "account_scheduling_thresholds"
  611. // SettingKeyAuthSourcePlatformQuotas 返回某 auth source 的 platform quota JSON key。
  612. // 形如 auth_source_default_{source}_platform_quotas
  613. func SettingKeyAuthSourcePlatformQuotas(source string) string {
  614. return fmt.Sprintf("auth_source_default_%s_platform_quotas", source)
  615. }
  616. // QuotaDimension constants for spark shadow accounts.
  617. const (
  618. QuotaDimensionGlobal = "global"
  619. QuotaDimensionSpark = "spark"
  620. )
  621. // AdminAPIKeyPrefix is the prefix for admin API keys (distinct from user "sk-" keys).
  622. const AdminAPIKeyPrefix = "admin-"
  623. // SettingKeyAllowUserViewErrorRequests controls whether end users can view
  624. // their own failed requests on the usage page. Default false (opt-in).
  625. const SettingKeyAllowUserViewErrorRequests = "allow_user_view_error_requests"