1. 08 Feb, 2026 4 commits
    • erio's avatar
    • erio's avatar
      fix: parse Gemini native request format in ParseGatewayRequest for correct session hash generation · 35598d56
      erio authored
      ParseGatewayRequest only parsed Anthropic format (system/messages),
      ignoring Gemini native format (systemInstruction/contents). This caused
      GenerateSessionHash to produce identical hashes for all Gemini sessions.
      
      Add protocol parameter to ParseGatewayRequest to branch between
      Anthropic and Gemini parsing. Update GenerateSessionHash message
      traversal to extract text from both formats.
      35598d56
    • erio's avatar
      fix: prevent sessionHash collision for different users with same messages · 5c76b9e4
      erio authored
      Mix SessionContext (ClientIP, UserAgent, APIKeyID) into
      GenerateSessionHash 3rd-level fallback to differentiate requests
      from different users sending identical content.
      
      Also switch hashContent from SHA256-truncated to XXHash64 for
      better performance, and optimize Trie Lua script to match from
      longest prefix first.
      5c76b9e4
    • erio's avatar
      refactor(upstream): replace upstream account type with apikey, auto-append /antigravity · fb58560d
      erio authored
      Upstream accounts now use the standard APIKey type instead of a dedicated
      upstream type. GetBaseURL() and new GetGeminiBaseURL() automatically append
      /antigravity for Antigravity platform APIKey accounts, eliminating the need
      for separate upstream forwarding methods.
      
      - Remove ForwardUpstream, ForwardUpstreamGemini, testUpstreamConnection
      - Remove upstream branch guards in Forward/ForwardGemini/TestConnection
      - Add migration 052 to convert existing upstream accounts to apikey
      - Update frontend CreateAccountModal to create apikey type
      - Add unit tests for GetBaseURL and GetGeminiBaseURL
      fb58560d
  2. 07 Feb, 2026 6 commits
  3. 05 Feb, 2026 2 commits
    • shaw's avatar
      feat: 新增全局错误透传规则功能 · 39e05a2d
      shaw authored
      支持管理员配置上游错误如何返回给客户端:
      - 新增 ErrorPassthroughRule 数据模型和 Ent Schema
      - 实现规则的 CRUD API(/admin/error-passthrough-rules)
      - 支持按错误码、关键词匹配,支持 any/all 匹配模式
      - 支持按平台过滤(anthropic/openai/gemini/antigravity)
      - 支持透传或自定义响应状态码和错误消息
      - 实现两级缓存(Redis + 本地内存)和多实例同步
      - 集成到 gateway_handler 的错误处理流程
      - 新增前端管理界面组件
      - 新增单元测试覆盖核心匹配逻辑
      
      优化:
      - 移除 refreshLocalCache 中的冗余排序(数据库已排序)
      - 后端 Validate() 增加匹配条件非空校验
      39e05a2d
    • JIA-ss's avatar
      feat(gateway): filter /v1/usage stats by API Key instead of UserID · fa3ea5ee
      JIA-ss authored
      
      
      Previously the /v1/usage endpoint aggregated usage stats (today/total
      tokens, cost, RPM/TPM) across all API Keys belonging to the user.
      This made it impossible to distinguish usage from different API Keys
      (e.g. balance vs subscription keys).
      
      Now the usage stats are filtered by the current request's API Key ID,
      so each key only sees its own usage data. The balance/remaining fields
      are unaffected and still reflect the user-level wallet balance.
      
      Changes:
      - Add GetAPIKeyDashboardStats to repository interface and implementation
      - Add getPerformanceStatsByAPIKey helper (also fixes TPM to include
        cache_creation_tokens and cache_read_tokens)
      - Add GetAPIKeyDashboardStats to UsageService
      - Update Usage handler to call GetAPIKeyDashboardStats(apiKey.ID)
      Co-Authored-By: default avatarClaude Opus 4.5 <noreply@anthropic.com>
      fa3ea5ee
  4. 03 Feb, 2026 3 commits
    • shaw's avatar
      chore: fix gofmt formatting · df1c2383
      shaw authored
      df1c2383
    • bayma888's avatar
      feat(api-key): add independent quota and expiration support · 6146be14
      bayma888 authored
      This feature allows API Keys to have their own quota limits and expiration
      times, independent of the user's balance.
      
      Backend:
      - Add quota, quota_used, expires_at fields to api_key schema
      - Implement IsExpired() and IsQuotaExhausted() checks in middleware
      - Add ResetQuota and ClearExpiration API endpoints
      - Integrate quota billing in gateway handlers (OpenAI, Anthropic, Gemini)
      - Include quota/expiration fields in auth cache for performance
      - Expiration check returns 403, quota exhausted returns 429
      
      Frontend:
      - Add quota and expiration inputs to key create/edit dialog
      - Add quick-select buttons for expiration (+7, +30, +90 days)
      - Add reset quota confirmation dialog
      - Add expires_at column to keys list
      - Add i18n translations for new features (en/zh)
      
      Migration:
      - Add 045_add_api_key_quota.sql for new columns
      6146be14
    • song's avatar
      chore: gofmt · f1aafbc0
      song authored
      f1aafbc0
  5. 02 Feb, 2026 2 commits
    • song's avatar
      merge upstream main · 0170d19f
      song authored
      0170d19f
    • JIA-ss's avatar
      feat(gateway): 增强 /v1/usage 端点返回完整用量统计 · c441638f
      JIA-ss authored
      
      
      为 CC Switch 集成增强 /v1/usage 网关端点,在保持原有 4 字段
      (isValid, planName, remaining, unit) 向后兼容的基础上,新增:
      
      - usage 对象:今日/累计的请求数、token 用量、费用,以及 RPM/TPM
      - subscription 对象(订阅模式):日/周/月用量和限额、过期时间
      - balance 字段(余额模式):当前钱包余额
      
      用量数据获取采用 best-effort 策略,失败不影响基础响应。
      Co-Authored-By: default avatarClaude Opus 4.5 <noreply@anthropic.com>
      c441638f
  6. 27 Jan, 2026 1 commit
  7. 23 Jan, 2026 2 commits
    • song's avatar
      Add invalid-request fallback routing · fd0370c0
      song authored
      fd0370c0
    • shaw's avatar
      feat(gateway): 增加 SUGGESTION MODE 请求拦截 · 4a0fe3b1
      shaw authored
      扩展现有的预热请求拦截功能,新增对 SUGGESTION MODE 请求的拦截:
      - 检测 messages 最后一条 user 消息是否以 [SUGGESTION MODE: 开头
      - 拦截后返回空内容响应,节省 token 消耗
      - 重构检测逻辑,合并为单一函数,只解析一次 JSON
      4a0fe3b1
  8. 16 Jan, 2026 3 commits
  9. 15 Jan, 2026 1 commit
  10. 12 Jan, 2026 3 commits
    • xiluo's avatar
      feat(gateway): 优化 Antigravity/Gemini 思考块处理 · 524d80ae
      xiluo authored
      此提交解决了思考块 (thinking blocks) 在转发过程中的兼容性问题。
      
      主要变更:
      
      1. **思考块优化 (Thinking Blocks)**:
         - 在 AntigravityGatewayService 中增加了 sanitizeThinkingBlocks 处理,强制移除思考块中不支持的 cache_control 字段(避免 Anthropic/Vertex AI 报错)
         - 实现历史思考块展平 (Flattening):将非最后一条消息中的思考块转换为普通文本块,以绕过上游对历史思考块签名的严格校验
         - 增加 cleanCacheControlFromGeminiJSON 作为最后一道防线,确保转换后的 Gemini 请求中不残留非法的 cache_control
      
      2. **GatewayService 缓存控制优化**:
         - 更新缓存控制逻辑,跳过 thinking 块(thinking 块不支持 cache_control 字段)
         - 增加 removeCacheControlFromThinkingBlocks 函数强制清理
      
      关联 Issue: #225
      524d80ae
    • shaw's avatar
      fix(gateway): 修复 usage_logs 记录 IP 不正确的问题 · 8363663e
      shaw authored
      在 nginx 反向代理场景下,使用 ip.GetClientIP() 替代 c.ClientIP()
      以正确获取客户端真实 IP 地址
      8363663e
    • shaw's avatar
      fix(gateway): 修复 Claude Code 客户端检测和请求信息记录 · cf313d57
      shaw authored
      - 在 Messages 方法中调用 SetClaudeCodeClientContext 启用客户端检测
      - 修复 RecordUsageInput 未传递 UserAgent 和 IPAddress 的问题
      cf313d57
  11. 11 Jan, 2026 1 commit
    • IanShaw027's avatar
      fix: 临时保存编译错误修复 · fc4ea659
      IanShaw027 authored
      - 添加 LinuxDo 和 Update 配置(从 main 分支缺失)
      - 添加 LinuxDoConnectSyntheticEmailDomain 常量
      - 添加 IsClaudeCodeClient context key
      - 添加 GetLinuxDoConnectOAuthConfig 方法
      - 修复 BindStickySession 调用签名
      - 修复前端 i18n 重复属性
      - 重新生成 wire 依赖注入代码
      
      这个提交准备被合并替换,先保存以防丢失。
      fc4ea659
  12. 09 Jan, 2026 3 commits
    • Edric.Li's avatar
      feat(api-key): 添加 IP 白名单/黑名单限制功能 (#221) · 0a4641c2
      Edric.Li authored
      * feat(api-key): add IP whitelist/blacklist restriction and usage log IP tracking
      
      - Add IP restriction feature for API keys (whitelist/blacklist with CIDR support)
      - Add IP address logging to usage logs (admin-only visibility)
      - Remove billing_type column from usage logs UI (redundant)
      - Use generic "Access denied" error message for security
      
      Backend:
      - New ip package with IP/CIDR validation and matching utilities
      - Database migrations for ip_whitelist, ip_blacklist (api_keys) and ip_address (usage_logs)
      - Middleware IP restriction check after API key validation
      - Input validation for IP/CIDR patterns on create/update
      
      Frontend:
      - API key form with enable toggle for IP restriction
      - Shield icon indicator in table for keys with IP restriction
      - Removed billing_type filter and column from usage views
      
      * fix: update API contract tests for ip_whitelist/ip_blacklist fields
      
      Add ip_whitelist and ip_blacklist fields to expected JSON responses
      in API contract tests to match the new API key schema.
      0a4641c2
    • Edric Li's avatar
      feat(api-key): add IP whitelist/blacklist restriction and usage log IP tracking · 90798f14
      Edric Li authored
      - Add IP restriction feature for API keys (whitelist/blacklist with CIDR support)
      - Add IP address logging to usage logs (admin-only visibility)
      - Remove billing_type column from usage logs UI (redundant)
      - Use generic "Access denied" error message for security
      
      Backend:
      - New ip package with IP/CIDR validation and matching utilities
      - Database migrations for ip_whitelist, ip_blacklist (api_keys) and ip_address (usage_logs)
      - Middleware IP restriction check after API key validation
      - Input validation for IP/CIDR patterns on create/update
      
      Frontend:
      - API key form with enable toggle for IP restriction
      - Shield icon indicator in table for keys with IP restriction
      - Removed billing_type filter and column from usage views
      90798f14
    • IanShaw027's avatar
      feat(网关): 集成运维监控到 API 网关处理器 · fcdf839b
      IanShaw027 authored
      - 在 gateway_handler 中添加请求监控和错误追踪
      - 在 openai_gateway_handler 中集成 ops 指标采集
      - 在 gemini_v1beta_handler 中集成 ops 指标采集
      - 更新 handler 基类支持 ops 错误日志记录
      fcdf839b
  13. 08 Jan, 2026 1 commit
    • Edric Li's avatar
      feat(groups): add Claude Code client restriction and session isolation · a4210588
      Edric Li authored
      - Add claude_code_only field to restrict groups to Claude Code clients only
      - Add fallback_group_id for non-Claude Code requests to use alternate group
      - Implement ClaudeCodeValidator for User-Agent detection
      - Add group-level session binding isolation (groupID in Redis key)
      - Prevent cross-group sticky session pollution
      - Update frontend with Claude Code restriction controls
      a4210588
  14. 07 Jan, 2026 1 commit
    • Edric Li's avatar
      feat(usage-log): 增加请求 User-Agent 记录 · 1ada6cf7
      Edric Li authored
      在使用记录中添加 user_agent 字段,用于记录 API 请求的 User-Agent 头信息,
      便于分析客户端类型和调试。
      
      变更内容:
      - 新增数据库迁移 028_add_usage_logs_user_agent.sql
      - 更新 UsageLog 模型和 Ent Schema 添加 user_agent 字段
      - 更新 Repository 层的 Create 和 scanUsageLog 方法
      - 更新 RecordUsageInput 结构体支持传入 UserAgent
      - 更新 Claude/OpenAI/Gemini 三个网关 Handler 传递 UserAgent
      
      🤖 Generated with [Claude Code](https://claude.com/claude-code
      
      )
      Co-Authored-By: default avatarClaude Opus 4.5 <noreply@anthropic.com>
      1ada6cf7
  15. 04 Jan, 2026 6 commits
    • yangjianbo's avatar
      fix(后端): 修复 lint 失败并清理无用代码 · 5dd8b880
      yangjianbo authored
      修正测试中的 APIKey 名称引用
      移除不可达返回与未使用函数
      统一 gofmt 格式并处理 Close 错误
      5dd8b880
    • IanShaw027's avatar
      fix(backend): 修复 P0/P1 严重安全和稳定性问题 · 7122b3b3
      IanShaw027 authored
      P0 严重问题修复:
      - 优化重试机制:降至 5 次 + 指数退避 + 10s 上限,防止请求堆积
      - 修复 SSE 错误格式:符合 Anthropic API 规范,添加错误类型标准化
      
      P1 重要问题修复:
      - 防止 DOS 攻击:使用 io.LimitReader 限制请求体 10MB,流式解析
      - 修复计费数据丢失:改为同步计费,使用独立 context 防止中断
      
      技术细节:
      - 新增 retryBackoffDelay() 和 sleepWithContext() 支持 context 取消
      - 新增 normalizeAnthropicErrorType() 和 sanitizePublicErrorMessage()
      - 新增 parseGatewayRequestStream() 实现流式解析
      - 新增 recordUsageSync() 确保计费数据持久化
      
      影响:
      - 极端场景重试时间从 30s 降至 ≤10s
      - 防止高并发 OOM 攻击
      - 消除计费数据丢失风险
      - 提升客户端兼容性
      7122b3b3
    • IanShaw027's avatar
    • yangjianbo's avatar
      fix(流式): 提升SSE稳定性并统一超时配置 · 73ffb585
      yangjianbo authored
      - 扩展SSE行长与间隔超时处理,补充keepalive
      
      - 写入失败与超长行时发送错误事件,修复并发释放
      
      - 同步默认配置与示例配置,更新Caddy超时/压缩规则
      
      - 新增OpenAI流式超时与超长行测试
      
      测试: go test ./...
      73ffb585
    • IanShaw027's avatar
      fix(lint): 修复所有 Go 命名规范问题 · a4953785
      IanShaw027 authored
      - 全局替换 ApiKey → APIKey(类型、字段、方法、变量)
      - 修复所有 initialism 命名(API, SMTP, HTML, URL 等)
      - 添加所有缺失的包注释
      - 修复导出符号的注释格式
      
      主要修改:
      - ApiKey → APIKey(所有出现的地方)
      - ApiKeyID → APIKeyID
      - ApiKeyIDs → APIKeyIDs
      - TestSmtpConnection → TestSMTPConnection
      - HtmlURL → HTMLURL
      - 添加 20+ 个包注释
      - 修复 10+ 个导出符号注释格式
      
      验证结果:
      - ✓ golangci-lint: 0 issues
      - ✓ 单元测试: 通过
      - ✓ 集成测试: 通过
      a4953785
    • song's avatar
      fix: 转发失败日志添加账户ID信息 · 3932bf03
      song authored
      3932bf03
  16. 03 Jan, 2026 1 commit
    • ianshaw's avatar
      feat(antigravity): 增强网关功能和 thinking 块处理 · 26438f72
      ianshaw authored
      主要改进:
      - 优化 thinking blocks 过滤策略,支持 Auto 模式降级
      - 将无效 thinking block 内容转为普通 text
      - 保留单个空白 text block,不过滤
      - 重构配额刷新机制,统一与 Claude 一致
      - 支持 cachedContentTokenCount 映射到 cache_read_input_tokens
      - Haiku 模型映射到 Sonnet
      - 添加 /antigravity/v1/models 端点支持
      - countTokens 端点直接返回空值
      26438f72