1. 14 Apr, 2026 1 commit
    • sakurawztlt's avatar
      fix: Anthropic 非流式路径在上游终态事件 output 为空时从 delta 事件重建响应内容 · 777820c1
      sakurawztlt authored and 陈曦's avatar 陈曦 committed
      b2e379cf 引入的 BufferedResponseAccumulator 已修复了 chat_completions
      非流式路径和 responses OAuth 非流式路径,但遗漏了 Anthropic /v1/messages
      非流式路径 (handleAnthropicBufferedStreamingResponse)。
      
      当客户端请求 stream=false 且模型开启思考时,上游 response.completed
      终态事件的 output 字段可能为空,实际 message 内容通过
      response.output_text.delta 增量事件下发。旧代码只读终态事件的 Response,
      导致客户端收到的 content 字段为空 ([{"type":"text"}])。
      
      本 commit 将 b2e379cf 的相同修复模式镜像到 Anthropic 路径:在 SSE 扫描
      过程中用 BufferedResponseAccumulator 累积 delta 内容,终态 output 为空
      时通过 SupplementResponseOutput 补充重建。
      
      同时修复 handleAnthropicBufferedStreamingResponse 遗漏 response.done
      事件类型的问题,与 chat completions 路径保持一致,避免上游发送
      response.done 时 handler 认不出终态事件、最终返回 502 的潜在问题。
      
      BufferedResponseAccumulator 已在 chatcompletions_responses_test.go 有
      完整单元测试覆盖(TextOnly/ToolCalls/Reasoning/Mixed/SupplementEmpty/
      NoSupplementWhenOutputExists/EmptyDeltas/IgnoresNonFunctionCallItems),
      本次复用相同累加器无需新增测试。
      777820c1
  2. 12 Apr, 2026 1 commit
    • bot's avatar
      fix: handle Anthropic credit balance exhausted (400) as account error · cb016ad8
      bot authored
      When an Anthropic API key's credit balance is depleted, the upstream
      returns HTTP 400 with message containing "credit balance". Previously,
      the 400 handler only checked for "organization has been disabled",
      so credit-exhausted accounts kept being scheduled — every request
      returned the same error.
      
      Treat this case identically to 402 (Payment Required): call
      handleAuthError → SetError to stop scheduling the account until
      an admin manually recovers it after topping up credits.
      
      Closes #1586
      cb016ad8
  3. 11 Apr, 2026 2 commits
    • erio's avatar
      refactor(payment): code standards fixes and regression repairs · e3a000e0
      erio authored
      Backend:
      - Split payment_order.go (546→314 lines) into payment_order_lifecycle.go
      - Replace magic strings with constants in factory, easypay, webhook handler
      - Add rate limit/validity unit constants in payment_order_lifecycle, payment_service
      - Fix critical regression: add PaymentEnabled to GetPublicSettings response
      - Add missing migration 099_fix_migrated_purchase_menu_label_icon.sql
      
      Frontend:
      - Fix StripePopupView.vue: replace `as any` with typed interface, use extractApiErrorMessage
      - Fix AdminOrderTable.vue: replace hardcoded column labels with i18n t() calls
      - Fix SubscriptionsView.vue: replace hardcoded Today/Tomorrow with i18n
      - Extract duplicate statusBadgeClass/canRefund/formatOrderDateTime to orderUtils.ts
      - Add missing i18n keys: common.today, common.tomorrow, payment.orders.orderType/actions
      - Remove dead PurchaseSubscriptionView.vue (replaced by PaymentView)
      e3a000e0
    • erio's avatar
      feat(payment): add complete payment system with multi-provider support · 63d1860d
      erio authored
      Add a full payment and subscription system supporting EasyPay (Alipay/WeChat),
      Stripe, and direct Alipay/WeChat Pay providers with multi-instance load balancing.
      63d1860d
  4. 10 Apr, 2026 1 commit
  5. 09 Apr, 2026 11 commits
  6. 08 Apr, 2026 24 commits
    • ius's avatar
      265687b5
    • shaw's avatar
      fix: resolve errcheck lint and add missing enable_cch_signing to test · b5ea7fbb
      shaw authored and 陈曦's avatar 陈曦 committed
      - Suppress errcheck for xxhash Digest.Write (never returns error)
      - Add enable_cch_signing field to settings API contract test
      b5ea7fbb
    • shaw's avatar
      feat: sync billing header cc_version with User-Agent and add opt-in CCH signing · 8e69957b
      shaw authored and 陈曦's avatar 陈曦 committed
      - Sync cc_version in x-anthropic-billing-header with the fingerprint
        User-Agent version, preserving the message-derived suffix
      - Implement xxHash64-based CCH signing to replace the cch=00000
        placeholder with a computed hash
      - Add admin toggle (enable_cch_signing) under gateway forwarding settings,
        disabled by default
      8e69957b
    • shaw's avatar
      fix: 修复非CC客户端OAuth伪装被Anthropic检测为第三方应用的问题 · d845c3ce
      shaw authored and 陈曦's avatar 陈曦 committed
      commit f3aa54b7 的 rewriteSystemForNonClaudeCode 未能通过 Anthropic 第三方检测,
      根因是两个关键信号与真实 Claude Code 不一致:
      
      1. anthropic-beta 头缺少 claude-code-20250219:伪装路径主动将该 beta
         加入 drop set 并移除,但 Anthropic 依赖此 beta 识别 Claude Code 请求。
         修复:非 haiku 模型的伪装请求强制包含 claude-code beta。
      
      2. system 字段使用 string 格式而非 array+cache_control:真实 Claude Code
         始终以 [{type,text,cache_control:{type:"ephemeral"}}] 发送 system,
         string 格式成为第三方检测信号。
         修复:rewriteSystemForNonClaudeCode 改为注入 array 格式。
      
      附带调整:stripSystemCacheControl 按 system 是否被重写动态决定,
      重写时保留 CC prompt 的 cache_control,未重写时(haiku/已含CC前缀)
      保持原有剥离行为。
      d845c3ce
    • shaw's avatar
      feat: Beta策略支持按模型区分处理(模型白名单) · f1f9640c
      shaw authored and 陈曦's avatar 陈曦 committed
      f1f9640c
    • shaw's avatar
      fix: 非Claude Code客户端system prompt迁移至messages以绕过第三方应用检测 · b717956c
      shaw authored and 陈曦's avatar 陈曦 committed
      Anthropic近期引入基于system参数内容的第三方应用检测机制,原有的前置追加
      Claude Code提示词策略无法通过检测(后续内容仍为非Claude Code格式触发429)。
      
      新策略:对非Claude Code客户端的OAuth/SetupToken账号请求,将system字段
      完整替换为Claude Code标识提示词,原始system内容作为user/assistant消息对
      注入messages开头,模型仍接收完整指令。
      
      仅影响/v1/messages路径,chat_completions和responses路径保持原有逻辑不变。
      真正的Claude Code客户端请求完全不受影响(原样透传)。
      b717956c
    • 陈曦's avatar
      去除版本在页面的上的展示 · 4fee20ec
      陈曦 authored
      4fee20ec
    • shaw's avatar
      fix: resolve errcheck lint and add missing enable_cch_signing to test · b982076e
      shaw authored
      - Suppress errcheck for xxhash Digest.Write (never returns error)
      - Add enable_cch_signing field to settings API contract test
      b982076e
    • shaw's avatar
      feat: sync billing header cc_version with User-Agent and add opt-in CCH signing · e51c9e50
      shaw authored
      - Sync cc_version in x-anthropic-billing-header with the fingerprint
        User-Agent version, preserving the message-derived suffix
      - Implement xxHash64-based CCH signing to replace the cch=00000
        placeholder with a computed hash
      - Add admin toggle (enable_cch_signing) under gateway forwarding settings,
        disabled by default
      e51c9e50
    • YanzheL's avatar
      fix(openai): sanitize empty base64 input images · fb233463
      YanzheL authored and 陈曦's avatar 陈曦 committed
      fb233463
    • YanzheL's avatar
      fix(gemini): normalize ai studio google search tools · a8779a2c
      YanzheL authored and 陈曦's avatar 陈曦 committed
      a8779a2c
    • YanzheL's avatar
      fix(gemini): preserve google search in Claude compat tools · e31051f2
      YanzheL authored and 陈曦's avatar 陈曦 committed
      e31051f2
    • YanzheL's avatar
      fix(lint): satisfy errcheck for strings.Builder.WriteString calls · ac28ca64
      YanzheL authored and 陈曦's avatar 陈曦 committed
      ac28ca64
    • YanzheL's avatar
      test(gateway): add tests for content-based session hash fallback · 91a3cae5
      YanzheL authored and 陈曦's avatar 陈曦 committed
      - 20 unit tests for deriveOpenAIContentSessionSeed covering:
        - Empty/nil inputs, model-only, stable across turns
        - Different model/system/first-user produce different seeds
        - Tools, functions, developer role, structured content
        - Responses API: input string, input array, instructions, input_text typed items
        - JSON canonicalization (whitespace/key-order insensitive)
        - Prefix presence, empty tools ignored, messages preferred over input
      - 3 integration tests for GenerateSessionHash content fallback:
        - Content fallback produces stable hash
        - Explicit signals override content fallback
        - Empty body still returns empty hash
      91a3cae5
    • YanzheL's avatar
      fix(gateway): add content-based session hash fallback for non-Codex clients · 16c7bd31
      YanzheL authored and 陈曦's avatar 陈曦 committed
      When no explicit session signals (session_id, conversation_id, prompt_cache_key)
      are provided, derive a stable session seed from the request body content
      (model + tools + system prompt + first user message) to enable sticky routing
      and prompt caching for non-Codex clients using the Chat Completions API.
      
      This mirrors the content-based fallback already present in GatewayService.
      GenerateSessionHash, adapted for the OpenAI gateway's request formats (both
      Chat Completions messages and Responses API input).
      
      JSON fragments are canonicalized via normalizeCompatSeedJSON to ensure
      semantically identical requests produce the same seed regardless of
      whitespace or key ordering.
      
      Closes #1421
      16c7bd31
    • erio's avatar
      refactor(channel): split long functions, extract shared validation, move... · dca85c86
      erio authored and 陈曦's avatar 陈曦 committed
      refactor(channel): split long functions, extract shared validation, move billing validation to service
      
      - Split Update (98→25 lines), buildCache (54→20 lines), Create (51→25 lines)
        into focused sub-functions: applyUpdateInput, checkGroupConflicts,
        fetchChannelData, populateChannelCache, storeErrorCache, getOldGroupIDs,
        invalidateAuthCacheForGroups
      - Extract validateChannelConfig to eliminate duplicated validation calls
        between Create and Update
      - Move validatePricingBillingMode from handler to service layer for
        proper separation of concerns
      - Add error logging to IsModelRestricted (was silently swallowing errors)
      - Add 12 new tests: ToUsageFields, billing mode validation, antigravity
        wildcard mapping isolation, Create/Update mapping conflict integration
      dca85c86
    • Elysia's avatar
      fix: 非流式响应路径扩展SSE检测至所有账号类型 (#1493) · 70836c70
      Elysia authored and 陈曦's avatar 陈曦 committed
      
      
      当上游返回SSE格式响应(如sub2api链路)时,API Key账号的非流式路径
      未检测SSE,导致终态事件中空output直接透传给客户端。
      
      - 将Content-Type SSE检测从仅OAuth扩展至所有账号类型
      - 重命名handleOAuthSSEToJSON为handleSSEToJSON(无OAuth专属逻辑)
      - 为透传路径新增handlePassthroughSSEToJSON,支持SSE转JSON及空output重建
      Co-Authored-By: default avatarClaude Opus 4.6 (1M context) <noreply@anthropic.com>
      70836c70
    • shaw's avatar
      fix: 修复非CC客户端OAuth伪装被Anthropic检测为第三方应用的问题 · 49c19a55
      shaw authored and 陈曦's avatar 陈曦 committed
      commit f3aa54b7 的 rewriteSystemForNonClaudeCode 未能通过 Anthropic 第三方检测,
      根因是两个关键信号与真实 Claude Code 不一致:
      
      1. anthropic-beta 头缺少 claude-code-20250219:伪装路径主动将该 beta
         加入 drop set 并移除,但 Anthropic 依赖此 beta 识别 Claude Code 请求。
         修复:非 haiku 模型的伪装请求强制包含 claude-code beta。
      
      2. system 字段使用 string 格式而非 array+cache_control:真实 Claude Code
         始终以 [{type,text,cache_control:{type:"ephemeral"}}] 发送 system,
         string 格式成为第三方检测信号。
         修复:rewriteSystemForNonClaudeCode 改为注入 array 格式。
      
      附带调整:stripSystemCacheControl 按 system 是否被重写动态决定,
      重写时保留 CC prompt 的 cache_control,未重写时(haiku/已含CC前缀)
      保持原有剥离行为。
      49c19a55
    • shaw's avatar
      fix: 修复非CC客户端OAuth伪装被Anthropic检测为第三方应用的问题 · 1c9a2128
      shaw authored
      commit f3aa54b7 的 rewriteSystemForNonClaudeCode 未能通过 Anthropic 第三方检测,
      根因是两个关键信号与真实 Claude Code 不一致:
      
      1. anthropic-beta 头缺少 claude-code-20250219:伪装路径主动将该 beta
         加入 drop set 并移除,但 Anthropic 依赖此 beta 识别 Claude Code 请求。
         修复:非 haiku 模型的伪装请求强制包含 claude-code beta。
      
      2. system 字段使用 string 格式而非 array+cache_control:真实 Claude Code
         始终以 [{type,text,cache_control:{type:"ephemeral"}}] 发送 system,
         string 格式成为第三方检测信号。
         修复:rewriteSystemForNonClaudeCode 改为注入 array 格式。
      
      附带调整:stripSystemCacheControl 按 system 是否被重写动态决定,
      重写时保留 CC prompt 的 cache_control,未重写时(haiku/已含CC前缀)
      保持原有剥离行为。
      1c9a2128
    • haruka's avatar
      fix: resolve errcheck lint for sync.Map type assertion · 1e3ac5f0
      haruka authored and 陈曦's avatar 陈曦 committed
      
      Co-Authored-By: default avatarClaude Opus 4.6 (1M context) <noreply@anthropic.com>
      1e3ac5f0
    • haruka's avatar
      fix: resolve refresh token race condition causing false invalid_grant errors · ef8a7c0a
      haruka authored and 陈曦's avatar 陈曦 committed
      
      
      When multiple goroutines/workers concurrently refresh the same OAuth token,
      the first succeeds but invalidates the old refresh_token (rotation). Subsequent
      attempts using the stale token get invalid_grant, which was incorrectly treated
      as non-retryable, permanently marking the account as ERROR.
      
      Three complementary fixes:
      1. Race-aware recovery: after invalid_grant, re-read DB to check if another
         worker already refreshed (refresh_token changed) — return success instead
         of error
      2. In-process mutex (sync.Map of per-account locks): prevents concurrent
         refreshes within the same process, complementing the Redis distributed lock
      3. Increase default lock TTL from 30s to 60s to reduce TTL-expiry races
      Co-Authored-By: default avatarClaude Opus 4.6 (1M context) <noreply@anthropic.com>
      ef8a7c0a
    • Alex's avatar
      fix(openai): do not normalize /completion API token based accounts · 66e06527
      Alex authored and 陈曦's avatar 陈曦 committed
      66e06527
    • Alex's avatar
      fix(openai): do not normalize API token based accounts · e7439c32
      Alex authored and 陈曦's avatar 陈曦 committed
      e7439c32
    • shaw's avatar
      feat: Beta策略支持按模型区分处理(模型白名单) · 248fe092
      shaw authored and 陈曦's avatar 陈曦 committed
      248fe092