1. 08 Apr, 2026 2 commits
  2. 04 Apr, 2026 1 commit
    • erio's avatar
      feat: image output token billing, channel-mapped billing source, credits balance precheck · d72ac926
      erio authored
      - Parse candidatesTokensDetails from Gemini API to separate image/text output tokens
      - Add image_output_tokens and image_output_cost to usage_log (migration 089)
      - Support per-image-token pricing via output_cost_per_image_token from model pricing data
      - Channel pricing ImageOutputPrice override works in token billing mode
      - Auto-fill image_output_price in channel pricing form from model defaults
      - Add "channel_mapped" billing model source as new default (migration 088)
      - Bills by model name after channel mapping, before account mapping
      - Fix channel cache error TTL sign error (115s → 5s)
      - Fix Update channel only invalidating new groups, not removed groups
      - Fix frontend model_mapping clearing sending undefined instead of {}
      - Credits balance precheck via shared AccountUsageService cache before injection
      - Skip credits injection for accounts with insufficient balance
      - Don't mark credits exhausted for "exhausted your capacity on this model" 429s
      d72ac926
  3. 20 Mar, 2026 1 commit
  4. 15 Mar, 2026 1 commit
  5. 03 Mar, 2026 1 commit
    • QTom's avatar
      fix(gateway): 分组隔离 — 禁止未分组账号被跨组调度 · 530a1629
      QTom authored
      当 API Key 无分组时,调度仅从未分组账号池中选取。
      修复 isAccountInGroup 在 groupID==nil 时的逻辑,
      同时补全 scheduler_snapshot_service 和 gemini_compat_service
      中的 SimpleMode 保护,确保分组隔离在所有调度路径生效。
      
      新增 ListSchedulableUngroupedByPlatform/s 方法,
      使用 Ent 的 Not(HasAccountGroups()) 谓词实现未分组账号隔离。
      新增 17 个单元和端到端隔离测试,覆盖所有分支和边界条件。
      530a1629
  6. 28 Feb, 2026 1 commit
  7. 14 Feb, 2026 1 commit
  8. 12 Feb, 2026 1 commit
    • yangjianbo's avatar
      chore(logging): 完成后端日志审计与结构化迁移 · 584cfc3d
      yangjianbo authored
      - 将高密度服务与处理器日志迁移到新日志系统(LegacyPrintf/结构化日志)
      - 增加 stdlog bridge 与兼容测试,保留旧日志捕获能力
      - 将 OpenAI 断流告警改为结构化 Warn 并改造对应测试为 sink 捕获
      - 补齐后端相关文件 logger 引用并通过全量 go test
      584cfc3d
  9. 11 Feb, 2026 1 commit
    • sususu98's avatar
      fix: include Gemini thoughtsTokenCount in output token billing · d21d70a5
      sususu98 authored
      Gemini 2.5 Pro/Flash thinking models return thoughtsTokenCount separately
      from candidatesTokenCount in usageMetadata, but this field was not parsed
      or included in billing calculations, causing thinking tokens to be
      unbilled.
      
      - Add ThoughtsTokenCount field to GeminiUsageMetadata struct
      - Include thoughtsTokenCount in OutputTokens across all 3 Gemini usage
        parsing paths (non-streaming, streaming, compat layer)
      - Add tests covering thinking token scenarios
      
      Closes #554
      d21d70a5
  10. 10 Feb, 2026 1 commit
    • yangjianbo's avatar
      perf(backend): 使用 gjson/sjson 优化热路径 JSON 处理 · 58912d4a
      yangjianbo authored
      
      
      将 API 网关热路径中的 json.Unmarshal+json.Marshal 替换为 gjson 零拷贝查询和 sjson 精准写入:
      - unwrapV1InternalResponse 性能提升 22x(4009ns→182ns),内存分配减少 28.5x
      - unwrapGeminiResponse、extractGeminiUsage、estimateGeminiCountTokens、ParseGeminiRateLimitResetTime 改为接收 []byte 使用 gjson 提取
      - ParseGatewayRequest 的 model/stream/metadata/thinking/max_tokens 改用 gjson 类型安全提取
      - Handler 层(sora/openai)改用 gjson 提取字段、sjson 注入/修改字段,移除 map[string]any 中间变量
      - Sora Client 响应解析改用 gjson ForEach 遍历,减少内存分配
      - 新增约 100 个单元测试用例,所有改动函数覆盖率 >85%
      Co-Authored-By: default avatarClaude Opus 4.6 <noreply@anthropic.com>
      58912d4a
  11. 09 Feb, 2026 5 commits
    • Edric Li's avatar
      feat: same-account retry before failover for transient errors · d6c2921f
      Edric Li authored
      For retryable transient errors (Google 400 "invalid project resource name"
      and empty stream responses), retry on the same account up to 2 times
      (with 500ms delay) before switching to another account.
      
      - Add RetryableOnSameAccount field to UpstreamFailoverError
      - Add same-account retry loop in both Gemini and Claude/OpenAI handler paths
      - Move temp-unschedule from service layer to handler layer (only after
        all same-account retries exhausted)
      - Reduce temp-unschedule cooldown from 30 minutes to 1 minute
      d6c2921f
    • Edric Li's avatar
      feat: failover and temp-unschedule on Google "Invalid project resource name" 400 · 89905ec4
      Edric Li authored
      Google 后端间歇性返回 400 "Invalid project resource name" 错误,
      此前该错误直接透传给客户端且不触发账号切换,导致请求失败。
      
      - 在 Antigravity 和 Gemini 两个平台的所有转发路径中,
        精确匹配该错误消息后触发 failover 自动换号重试
      - 命中后将账号临时封禁 1 小时,避免反复调度到同一故障账号
      - 提取共享函数 isGoogleProjectConfigError / tempUnscheduleGoogleConfigError
        消除跨 Service 的代码重复
      89905ec4
    • erio's avatar
      a70d37a6
    • erio's avatar
      fix: skip rate limiting when custom error codes don't match upstream status · 6892e84a
      erio authored
      Add ShouldHandleErrorCode guard at the entry of handleGeminiUpstreamError
      and AntigravityGatewayService.handleUpstreamError so that accounts with
      custom error codes (e.g. [599]) are not rate-limited when the upstream
      returns a non-matching status (e.g. 429).
      6892e84a
    • erio's avatar
      feat: ErrorPolicySkipped returns 500 instead of upstream status code · 73f45574
      erio authored
      When custom error codes are enabled and the upstream error code is NOT
      in the configured list, return HTTP 500 to the client instead of
      transparently forwarding the original status code.
      
      Also adds integration test TestCustomErrorCode599 verifying that 429,
      500, 503, 401, 403 all return 500 without triggering SetRateLimited
      or SetError.
      73f45574
  12. 08 Feb, 2026 2 commits
    • erio's avatar
      a67d9337
    • 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
  13. 07 Feb, 2026 3 commits
  14. 05 Feb, 2026 1 commit
    • 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
  15. 02 Feb, 2026 3 commits
  16. 29 Jan, 2026 1 commit
    • song's avatar
      fix(gateway): 过滤 Gemini 请求中 parts 为空的消息 · 7ade9baa
      song authored
      Gemini API 不接受 contents 数组中 parts 为空的消息,会返回 400 INVALID_ARGUMENT 错误。
      添加 filterEmptyPartsFromGeminiRequest 函数在转发前过滤这类消息。
      
      影响范围:ForwardGemini (antigravity) 和 ForwardNative (gemini)
      7ade9baa
  17. 26 Jan, 2026 2 commits
  18. 23 Jan, 2026 1 commit
    • lynoot's avatar
      fix(gateway): aggregate all text chunks in non-streaming Gemini responses · 909b8a8f
      lynoot authored
      Previously, collectGeminiSSE() only returned the last chunk received
      from the upstream streaming response when converting to non-streaming.
      This caused incomplete responses where only the final text fragment
      was returned to clients.
      
      For example, a request asking to "count from 1 to 10" would only
      return "\n" (the last chunk) instead of "1\n2\n3\n...\n10\n".
      
      This was especially problematic for JSON structured output where
      the opening brace "{" from the first chunk was lost, resulting
      in invalid JSON like: colors": ["red", "blue"]}
      
      The fix:
      - Collect all text parts from each SSE chunk into a slice
      - Merge all collected text parts into the final response
      - Reuse the same pattern as handleGeminiStreamToNonStreaming
        in antigravity_gateway_service.go
      
      Fixes: non-streaming responses returning incomplete text
      Fixes: structured output (JSON schema) returning invalid JSON
      909b8a8f
  19. 20 Jan, 2026 2 commits
  20. 15 Jan, 2026 1 commit
  21. 14 Jan, 2026 2 commits
  22. 12 Jan, 2026 1 commit
  23. 11 Jan, 2026 1 commit
    • IanShaw027's avatar
      feat(ops): 实现上游错误事件记录与查询功能 · 7ebca553
      IanShaw027 authored
      **新增功能**:
      - 新建ops_upstream_error_events表存储上游服务错误详情
      - 支持记录上游429/529/5xx错误的详细上下文信息
      - 提供按时间范围查询上游错误事件的API
      
      **后端改动**:
      1. 模型层(ops_models.go, ops_port.go):
         - 新增UpstreamErrorEvent结构体
         - 扩展Repository接口支持上游错误事件CRUD
      
      2. 仓储层(ops_repo.go):
         - 实现InsertUpstreamErrorEvent写入上游错误
         - 实现GetUpstreamErrorEvents按时间范围查询
      
      3. 服务层(ops_service.go, ops_upstream_context.go):
         - ops_service: 新增GetUpstreamErrorEvents查询方法
         - ops_upstream_context: 封装上游错误上下文构建逻辑
      
      4. Handler层(ops_error_logger.go):
         - 新增GetUpstreamErrorsHandler处理上游错误查询请求
      
      5. Gateway层集成:
         - antigravity_gateway_service.go: 429/529错误时记录上游事件
         - gateway_service.go: OpenAI 429/5xx错误时记录
         - gemini_messages_compat_service.go: Gemini 429/5xx错误时记录
         - openai_gateway_service.go: OpenAI 429/5xx错误时记录
         - ratelimit_service.go: 429限流错误时记录
      
      **数据记录字段**:
      - request_id: 关联ops_logs主记录
      - platform/model: 上游服务标识
      - status_code/error_message: 错误详情
      - request_headers/response_body: 调试信息(可选)
      - created_at: 错误发生时间
      7ebca553
  24. 09 Jan, 2026 4 commits