erio
1563bd3dda
feat(upstream): passthrough all client headers instead of manual header setting
...
Replace manual header setting (Content-Type, anthropic-version, anthropic-beta)
with full client header passthrough in ForwardUpstream/ForwardUpstreamGemini.
Only authentication headers (Authorization, x-api-key) are overridden with
upstream account credentials. Hop-by-hop headers are excluded.
Add unit tests covering header passthrough, auth override, and hop-by-hop filtering.
2026-02-08 08:33:09 +08:00
erio
77b66653ed
fix(gateway): restore upstream account forwarding with dedicated methods
...
v0.1.74 merged upstream accounts into the OAuth path, causing requests
to hit the wrong protocol and endpoint. Add three upstream-specific
methods (testUpstreamConnection, ForwardUpstream, ForwardUpstreamGemini)
that use base_url + apiKey auth and passthrough the original body, while
reusing the existing response handling and error/retry logic.
2026-02-08 01:21:02 +08:00
shaw
6aaa4aee6a
fix: 收敛 Claude Code 探测拦截并补齐回归测试
2026-02-07 19:04:08 +08:00
shaw
1439eb39a9
fix(gateway): harden digest logging and align antigravity ops
...
- avoid panic by using safe UUID prefix truncation in Gemini digest fallback logs\n- remove unconditional Antigravity 429 full-body debug logs and honor log truncation config\n- align Antigravity quick preset mappings to opus 4.6-thinking targets only\n- restore scope rate-limit aggregation/output in ops availability stats
2026-02-07 17:12:15 +08:00
erio
fa28dcbf32
fix(test): update test calls to match method receivers on handleSmartRetry and antigravityRetryLoop
2026-02-07 16:05:09 +08:00
erio
2656320d04
fix(antigravity): fetch default mapping from API and sync Redis on rate limit
...
1. Frontend: replace hardcoded antigravityDefaultMappings with async
fetch from GET /admin/accounts/antigravity/default-model-mapping,
eliminating the duplicate data source that caused frontend/backend
mapping inconsistency.
2. Backend: convert handleSmartRetry and antigravityRetryLoop from
standalone functions to AntigravityGatewayService methods, enabling
Redis cache sync (updateAccountModelRateLimitInCache) after both
rate-limit write paths — long-delay branch and retry-exhausted branch.
2026-02-07 15:59:27 +08:00
erio
b4f6c4f9d5
style: fix gofmt formatting in gateway_service.go
...
Remove extra blank line that caused golangci-lint gofmt check to fail.
2026-02-07 14:51:20 +08:00
erio
14c6c9321a
refactor: remove unused IsAntigravityModelSupported function and its tests
2026-02-07 14:42:28 +08:00
erio
386126b1b2
test(antigravity): add missing unit tests for upstream and custom model_mapping
...
- Add GetAccessToken upstream branch tests (success/failure/empty/nil)
- Add mapAntigravityModel wildcard-target-equals-request edge case tests
- Add upstream account smart retry test case
- Add GeminiMessagesCompatService custom model_mapping and empty model tests
2026-02-07 14:39:25 +08:00
erio
de0927289e
fix(antigravity): support upstream accounts and custom model_mapping in scheduling
...
- GetAccessToken: add upstream branch to read api_key from credentials
- shouldTriggerAntigravitySmartRetry: relax check from IsOAuth to Platform-based
- isModelSupportedByAccount/WithContext: replace IsAntigravityModelSupported
whitelist with mapAntigravityModel for unified scheduling/forwarding logic
- mapAntigravityModel: fix edge case where wildcard target equals request model
- Update tests for new behavior and add custom model_mapping test cases
2026-02-07 14:32:08 +08:00
erio
edb0937024
fix: restore non-failover error passthrough from 7b156489
2026-02-07 14:24:55 +08:00
erio
43a4840daf
fix: restore error passthrough service improvements from 7b156489
2026-02-07 14:16:19 +08:00
erio
5e98445b22
feat(antigravity): comprehensive enhancements - model mapping, rate limiting, scheduling & ops
...
Key changes:
- Upgrade model mapping: Opus 4.5 → Opus 4.6-thinking with precise matching
- Unified rate limiting: scope-level → model-level with Redis snapshot sync
- Load-balanced scheduling by call count with smart retry mechanism
- Force cache billing support
- Model identity injection in prompts with leak prevention
- Thinking mode auto-handling (max_tokens/budget_tokens fix)
- Frontend: whitelist mode toggle, model mapping validation, status indicators
- Gemini session fallback with Redis Trie O(L) matching
- Ops: enhanced concurrency monitoring, account availability, retry logic
- Migration scripts: 049-051 for model mapping unification
2026-02-07 12:31:10 +08:00
Wesley Liddick
20283bb55b
Merge pull request #507 from touwaeriol/pr/fix-429-fallback-default
...
fix(antigravity): reduce 429 fallback cooldown from 5min to 30s
2026-02-07 12:19:14 +08:00
erio
8917afab2a
fix(antigravity): reduce 429 fallback cooldown from 5min to 30s
...
The default fallback cooldown when rate limit reset time cannot be
parsed was 5 minutes, which is too aggressive and causes accounts
to be unnecessarily locked out. Reduce to 30 seconds for faster
recovery. Config override still works (unit remains minutes).
2026-02-07 11:54:00 +08:00
erio
49233ec26a
fix(antigravity): auto-fix max_tokens <= budget_tokens causing 400 error
...
When extended thinking is enabled, Claude API requires max_tokens >
thinking.budget_tokens. If misconfigured, this auto-adjusts max_tokens
to budget_tokens + 1000 instead of returning a 400 error.
- Add ensureMaxTokensGreaterThanBudget helper function
- Extract Gemini25FlashThinkingBudgetLimit constant (24576)
- Log adjustment for debugging
2026-02-07 11:49:03 +08:00
shaw
39a5b17d31
fix: 账号测试根据类型使用不同的 beta header
...
- OAuth 账号:使用完整的 DefaultBetaHeader 和 Claude Code 客户端 headers
- API Key 账号:使用 APIKeyBetaHeader(不含 oauth beta)
2026-02-07 11:33:06 +08:00
shaw
5299f3dcf6
fix: ix: antigravity 添加 aude-opus-4-6-thinking 模型支持
2026-02-07 10:38:10 +08:00
shaw
7b1564898b
fix: make error passthrough effective for non-failover upstream errors
2026-02-07 10:25:56 +08:00
shaw
9f4c1ef9f9
fix(ops): 添加 token 相关字段白名单避免误脱敏
...
在敏感字段检测中添加白名单,排除 API 参数和用量统计字段:
- max_tokens, max_completion_tokens, max_output_tokens
- completion_tokens, prompt_tokens, total_tokens
- input_tokens, output_tokens
- cache_creation_input_tokens, cache_read_input_tokens
这些字段名虽然包含 "token" 但只是数值参数,不应被脱敏处理。
2026-02-06 19:47:14 +08:00
Wesley Liddick
a381910e86
Merge pull request #489 from LLLLLLiulei/feat/import-export-bundle
...
feat: implement account & proxy import/export with migration-ready JSON bundles
2026-02-06 16:29:52 +08:00
shaw
d182ef0391
fix(gateway): 移除 PR #316 引入的工具名转换逻辑
...
移除响应阶段的工具名/schema/description 转换逻辑,修复第三方工具调用时
工具名被错误转换的问题(如 Task → task)。
移除内容:
- 工具名相关正则变量(toolPrefixRe, toolNameBoundaryRe 等)
- openCodeToolOverrides 和 claudeToolNameOverrides 映射表
- 工具名转换函数(normalizeToolNameForClaude, normalizeToolNameForOpenCode 等)
- 响应体工具名替换函数(replaceToolNamesInText, replaceToolNamesInResponseBody 等)
- 参数名转换函数(normalizeParamNameForOpenCode, rewriteParamKeysInValue)
- 工具描述清理函数(sanitizeToolDescription)
- 输入 schema 转换函数(normalizeToolInputSchema)
- 模型 ID 正则替换函数(replaceModelIDInText)
保留内容:
- 系统提示词清理(sanitizeSystemText)
- Claude Code 指纹 headers 处理
- 模型 ID 映射(通过 JSON 对象操作)
2026-02-06 16:09:58 +08:00
LLLLLLiulei
7319122e92
merge upstream/main
2026-02-06 11:33:45 +08:00
yangjianbo
ee01f80dc1
test(backend): 修复 usage 类型断言未检查
2026-02-06 09:54:29 +08:00
yangjianbo
98671a73f4
Merge branch 'main' of https://github.com/mt21625457/aicodex2api
...
# Conflicts:
# backend/internal/service/gateway_cached_tokens_test.go
2026-02-06 09:35:46 +08:00
yangjianbo
f33a950103
fix(兼容): 将 Kimi cached_tokens 映射到 Claude 标准 cache_read_input_tokens
...
Kimi 等 Claude 兼容 API 返回缓存信息使用 OpenAI 风格的 cached_tokens 字段,
而非 Claude 标准的 cache_read_input_tokens,导致客户端收不到缓存命中信息且
内部计费缓存折扣为 0。
新增 reconcileCachedTokens 辅助函数,在 cache_read_input_tokens == 0 且
cached_tokens > 0 时自动填充,覆盖流式(message_start/message_delta)和
非流式两种响应路径。对 Claude 原生上游无影响。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com >
2026-02-06 09:27:42 +08:00
程序猿MT
132bf34b69
Merge branch 'Wei-Shaw:main' into main
2026-02-06 08:53:52 +08:00
shaw
01b08e1e43
chore: 前端增加opus4.6模型映射
2026-02-06 08:50:45 +08:00
yangjianbo
c6a456c7c7
fix(兼容): 将 Kimi cached_tokens 映射到 Claude 标准 cache_read_input_tokens
...
Kimi 等 Claude 兼容 API 返回缓存信息使用 OpenAI 风格的 cached_tokens 字段,
而非 Claude 标准的 cache_read_input_tokens,导致客户端收不到缓存命中信息且
内部计费缓存折扣为 0。
新增 reconcileCachedTokens 辅助函数,在 cache_read_input_tokens == 0 且
cached_tokens > 0 时自动填充,覆盖流式(message_start/message_delta)和
非流式两种响应路径。对 Claude 原生上游无影响。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com >
2026-02-06 08:42:55 +08:00
Wesley Liddick
cc2329d4fd
Merge pull request #496 from mt21625457/main
...
feat(模型): 添加 gpt-5.3 Codex 映射与价格配置
2026-02-06 08:37:24 +08:00
yangjianbo
a38bd413ab
fix(计费): gpt-5.3-codex 定价回退到 gpt-5.2-codex
2026-02-06 07:40:38 +08:00
yangjianbo
9e1535e203
feat(模型): 添加 gpt-5.3 Codex 映射与价格配置
2026-02-06 07:14:46 +08:00
iBenzene
037a409919
fix: 修复了 codex 更新用量窗口异常的 bug
2026-02-06 01:06:22 +08:00
Wesley Liddick
571d1479a4
Merge pull request #490 from IanShaw027/fix/gemini-oauth-registered-user
...
fix(gemini): 修复已注册用户 OAuth 授权问题并增强错误提示
2026-02-05 22:37:20 +08:00
shaw
ae1934f7db
fix: 修复管理页面活跃会话数始终显示为0的问题
...
问题原因:Redis Pipeline 执行 Lua 脚本时出现 NOSCRIPT 错误,
因为 redis.NewScript 使用 EVALSHA 执行脚本,当 Redis 重启或
脚本未被缓存时,Pipeline 模式无法自动回退到 EVAL。
解决方案:在 NewSessionLimitCache 初始化时预加载所有 Lua 脚本
到 Redis,确保后续 Pipeline 执行时脚本已被缓存。
2026-02-05 22:36:17 +08:00
shaw
39e05a2dad
feat: 新增全局错误透传规则功能
...
支持管理员配置上游错误如何返回给客户端:
- 新增 ErrorPassthroughRule 数据模型和 Ent Schema
- 实现规则的 CRUD API(/admin/error-passthrough-rules)
- 支持按错误码、关键词匹配,支持 any/all 匹配模式
- 支持按平台过滤(anthropic/openai/gemini/antigravity)
- 支持透传或自定义响应状态码和错误消息
- 实现两级缓存(Redis + 本地内存)和多实例同步
- 集成到 gateway_handler 的错误处理流程
- 新增前端管理界面组件
- 新增单元测试覆盖核心匹配逻辑
优化:
- 移除 refreshLocalCache 中的冗余排序(数据库已排序)
- 后端 Validate() 增加匹配条件非空校验
2026-02-05 21:52:54 +08:00
ianshaw
7b46bbb628
fix(lint): 修复错误消息大写问题以符合 Go 惯例
2026-02-05 20:47:15 +08:00
ianshaw
d2527e36eb
feat(gemini): 增强 API 授权错误处理,自动提取并显示激活 URL
...
当 Gemini for Google Cloud API 未启用时(SERVICE_DISABLED 错误),
系统现在会:
- 自动检测 403 PERMISSION_DENIED 错误
- 从错误响应中提取 API 激活 URL
- 向用户显示清晰的错误消息和可点击的激活链接
- 提供操作指引(启用后等待几分钟)
新增文件:
- internal/pkg/googleapi/error.go: Google API 错误解析器
- internal/pkg/googleapi/error_test.go: 完整的测试覆盖
- GEMINI_API_ERROR_HANDLING.md: 实现文档
修改文件:
- internal/repository/geminicli_codeassist_client.go:
在 LoadCodeAssist 和 OnboardUser 中增强错误处理
这大大改善了用户体验,用户不再需要手动从错误日志中查找激活 URL。
2026-02-05 20:17:53 +08:00
LLLLLLiulei
029994a83b
fix: remove unused listAllAccounts
2026-02-05 19:13:00 +08:00
LLLLLLiulei
37047919ab
fix: harden import/export flow
2026-02-05 18:59:30 +08:00
LLLLLLiulei
0b45d48e85
perf: batch fetch proxies for account export
2026-02-05 18:40:49 +08:00
LLLLLLiulei
0c660f8335
feat: refine proxy export and toolbar layout
2026-02-05 18:35:00 +08:00
LLLLLLiulei
ce9a247a9d
feat: add proxy import flow
2026-02-05 18:23:49 +08:00
LLLLLLiulei
b4bd46d067
feat: add data import/export bundle
2026-02-05 17:46:08 +08:00
shaw
2b192f7dca
feat: 支持用户专属分组倍率配置
2026-02-05 16:05:42 +08:00
IanShaw027
979114db45
fix(gemini): 修复已注册用户 OAuth 授权时错误调用 onboardUser 的问题
...
问题:Google One Ultra 等已注册用户在 OAuth 授权时,如果 LoadCodeAssist
返回了 currentTier/paidTier 但没有返回 cloudaicompanionProject,之前的
逻辑会继续调用 onboardUser,导致 INVALID_ARGUMENT 错误。
修复:对齐 Gemini CLI 的处理逻辑:
- 当检测到用户已注册(有 currentTier/paidTier)时,不再调用 onboardUser
- 先尝试从 Cloud Resource Manager 获取可用项目
- 如果仍无法获取,返回友好的错误提示,引导用户手动填写 Project ID
这个修复解决了 Google One 订阅用户无法正常授权的问题。
2026-02-05 13:57:02 +08:00
Wesley Liddick
dabed96af4
Merge pull request #486 from s-Joshua-s/feat/usage-filter-by-apikey
...
feat(gateway): filter /v1/usage stats by API Key instead of UserID
2026-02-05 13:37:31 +08:00
Lemon
7498035d24
Merge branch 'main' into mod
2026-02-05 12:49:43 +08:00
Lemon
39a0359dd5
feat: enhance HTTP/2 Cleartext (h2c) configuration options
2026-02-05 12:48:05 +08:00
shaw
49a3c43741
feat(auth): 实现 Refresh Token 机制
...
- 新增 Access Token + Refresh Token 双令牌认证
- 支持 Token 自动刷新和轮转
- 添加登出和撤销所有会话接口
- 前端实现无感刷新和主动刷新定时器
2026-02-05 12:42:54 +08:00