yangjianbo
abf5de69fb
Merge branch 'main' into test
2026-02-12 23:43:47 +08:00
程序猿MT
174d7c774d
Merge branch 'Wei-Shaw:main' into main
2026-02-12 23:12:41 +08:00
sususu98
d21d70a5cf
fix: include Gemini thoughtsTokenCount in output token billing
...
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
2026-02-11 15:41:54 +08:00
yangjianbo
9634494ba9
fix: 修复代码审核发现的10个问题(P0安全+P1数据一致性+P2性能优化)
...
P0: OpenAI SSE 错误消息 JSON 注入 — 使用 json.Marshal 替代 fmt.Sprintf
P1: subscription 续期包裹 Ent 事务确保原子性
P1: CSP nonce 生成处理 crypto/rand 错误,失败降级为 unsafe-inline
P1: singleflight 透传数据库真实错误,不再吞没为 not found
P1: GetUserSubscriptionsWithProgress 提取 calculateProgress 消除 N+1
P2: billing_cache/gateway_helper 迁移到 math/rand/v2 消除全局锁争用
P2: generateRandomID 降级分支增加原子计数器防碰撞
P2: CORS 非白名单 origin 不再设置 Allow-Headers/Methods/Max-Age
P2: Turnstile 验证移除 VerifyCode 空值跳过条件防绕过
P2: Redis Cluster Lua 脚本空 KEYS 添加兼容性警告注释
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com >
2026-02-07 22:13:45 +08:00
yangjianbo
4a20a2a8ba
fix: 修复批量更新凭证明细与缓存TTL抖动
...
- BatchUpdateCredentials 返回 success/failed/results 及 success_ids/failed_ids
- billing jitteredTTL 改为只减不增,确保TTL不超上界
- crypto/rand 失败时随机ID降级避免 panic
- OpenAI SelectAccount 失败日志去重并补充字段
- 修复两处类型断言以通过 errcheck
2026-02-07 21:18:03 +08:00
yangjianbo
2588fa6a8f
fix(audit): 第二批审计修复 — P0 生产 Bug、安全加固、性能优化、缓存一致性、代码质量
...
基于 backend-code-audit 审计报告,修复剩余 P0/P1/P2 共 34 项问题:
P0 生产 Bug:
- 修复 time.Since(time.Now()) 计时逻辑错误 (P0-03)
- generateRandomID 改用 crypto/rand 替代固定索引 (P0-04)
- IncrementQuotaUsed 重写为 Ent 原子操作消除 TOCTOU 竞态 (P0-05)
安全加固:
- gateway/openai handler 错误响应替换为泛化消息,防止内部信息泄露 (P1-14)
- usage_log_repo dateFormat 参数改用白名单映射,防止 SQL 注入 (P1-16)
- 默认配置安全加固:sslmode=prefer、response_headers=true、mode=release (P1-18/19, P2-15)
性能优化:
- gateway handler 循环内 defer 替换为显式 releaseWait 闭包 (P1-02)
- group_repo/promo_code_repo Count 前 Clone 查询避免状态污染 (P1-03)
- usage_log_repo 四个查询添加 LIMIT 10000 防止 OOM (P1-07)
- GetBatchUsageStats 添加时间范围参数,默认最近 30 天 (P1-10)
- ip.go CIDR 预编译为包级变量 (P1-11)
- BatchUpdateCredentials 重构为先验证后更新 (P1-13)
缓存一致性:
- billing_cache 添加 jitteredTTL 防止缓存雪崩 (P2-10)
- DeductUserBalance/UpdateSubscriptionUsage 错误传播修复 (P2-12)
- UserService.UpdateBalance 成功后异步失效 billingCache (P2-13)
代码质量:
- search 截断改为按 rune 处理,支持多字节字符 (P2-01)
- TLS Handshake 改为 HandshakeContext 支持 context 取消 (P2-07)
- CORS 预检添加 Access-Control-Max-Age: 86400 (P2-16)
测试覆盖:
- 新增 user_service_test.go(UpdateBalance 缓存失效 6 个用例)
- 新增 batch_update_credentials_test.go(fail-fast + 类型验证 7 个用例)
- 新增 response_transformer_test.go、ip_test.go、usage_log_repo_unit_test.go、search_truncate_test.go
- 集成测试:IncrementQuotaUsed 并发测试、billing_cache 错误传播测试
- config_test.go 补充 server.mode/sslmode 默认值断言
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com >
2026-02-07 19:46:42 +08:00
0xff26b9a8
e756064c19
fix(antigravity): 修复非流式 Claude To Antigravity 响应内容为空的问题
...
- 修复 TransformGeminiToClaude 的 JSON 解析逻辑,当 V1InternalResponse
解析成功但 candidates 为空时,尝试直接解析为 GeminiResponse 格式
- 修复 handleClaudeStreamToNonStreaming 收集流式响应的逻辑,累积所有
chunks 的内容而不是只保留最后一个(最后一个 chunk 通常 text 为空)
- 新增 mergeCollectedPartsToResponse 函数,合并所有类型的 parts
(text、thinking、functionCall、inlineData),保持原始顺序
- 连续的普通 text parts 合并为一个,thinking/functionCall/inlineData 保持原样
2026-01-22 14:17:59 +08:00
0xff26b9a8
da48df06d2
refactor(antigravity): 提取并同步 Schema 清理逻辑至 schema_cleaner.go
...
主要变更:
1. 重构代码结构:
- 将 CleanJSONSchema 及其相关辅助函数从 request_transformer.go 提取到独立的 schema_cleaner.go 文件中,实现逻辑解耦。
2. 逻辑优化与修正:
- 参考 Antigravity-Manager (json_schema.rs) 的实现逻辑,修正了 Schema 清洗策略。
2026-01-20 23:41:53 +08:00
song
c115c9e048
fix: address lint errors
2026-01-18 01:22:40 +08:00
song
6941315432
feat: add antigravity web search support
2026-01-18 01:09:40 +08:00
song
0452f32003
feat(antigravity): 支持 Gemini cachedContentTokenCount 映射到 Claude cache_read_input_tokens
...
- 在 GeminiUsageMetadata 添加 CachedContentTokenCount 字段
- 修正 token 映射:Gemini promptTokenCount 包含缓存,Claude input_tokens 不包含
- 流式和非流式响应均已支持
2026-01-03 01:26:18 +08:00
song
b0389ca4d2
feat: 实现 Antigravity Claude → Gemini 协议转换,haiku 映射到 gemini-3-flash
2025-12-28 18:41:55 +08:00