yangjianbo
ef5a41057f
feat(usage): 添加清理任务与统计过滤
2026-01-18 10:52:18 +08:00
yangjianbo
74a3c74514
perf(Caddy): 添加静态资源长期缓存配置
...
- 为 /assets/* 设置 1 年缓存 + immutable 标记
- 包含 logo.png 和 favicon.ico
- 移除可能干扰缓存的 Pragma/Expires 头
效果:
- 浏览器缓存命中后不再发送请求
- Cloudflare CDN 可正确缓存静态资源
- 重复访问页面秒开
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2026-01-16 22:49:05 +08:00
yangjianbo
c9f79dee66
feat(安全): 实现 CSP nonce 支持解决内联脚本安全问题
...
- 添加 GenerateNonce() 生成加密安全的随机 nonce
- SecurityHeaders 中间件为每个请求生成唯一 nonce
- CSP 策略支持 __CSP_NONCE__ 占位符动态替换
- embed_on.go 注入的内联脚本添加 nonce 属性
- 添加 Cloudflare Insights 域名到 CSP 允许列表
- 添加完整单元测试,覆盖率达到 89.8%
解决的问题:
- 内联脚本违反 CSP script-src 指令
- Cloudflare Insights beacon.min.js 加载被阻止
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2026-01-16 17:05:49 +08:00
yangjianbo
a458e684bc
fix(认证): OAuth 401 直接标记错误状态
...
- OAuth 401 清理缓存并设置错误状态
- 移除 oauth_401_cooldown_minutes 配置及示例
- 更新 401 相关单测
破坏性变更: OAuth 401 不再临时不可调度,需手动恢复
2026-01-15 15:06:34 +08:00
yangjianbo
daf10907e4
fix(认证): 修复 OAuth token 缓存失效与 401 处理
...
新增 token 缓存失效接口并在刷新后清理
401 限流支持自定义规则与可配置冷却时间
补齐缓存失效与 401 处理测试
测试: make test
2026-01-14 15:55:44 +08:00
yangjianbo
202ec21bab
fix(config): 提升粘性会话默认等待时长
...
- 默认值调整为 120s
- 同步示例配置与环境变量
2026-01-12 14:26:31 +08:00
yangjianbo
3141aa5144
feat(scheduler): 引入调度快照缓存与 outbox 回放
...
- 调度热路径优先读 Redis 快照,保留分组排序语义
- outbox 回放 + 全量重建纠偏,失败重试不推进水位
- 自动 Atlas 基线对齐并同步调度配置示例
2026-01-12 14:19:06 +08:00
IanShaw027
3dfb62e996
merge: 合并main分支最新改动
...
解决冲突:
- backend/internal/config/config.go: 合并Ops和Dashboard配置
- backend/internal/server/api_contract_test.go: 合并handler初始化
- backend/internal/service/openai_gateway_service.go: 保留Ops错误追踪逻辑
- backend/internal/service/wire.go: 合并Ops和APIKeyAuth provider
主要合并内容:
- Dashboard缓存和预聚合功能
- API Key认证缓存优化
- Codex转换支持
- 使用日志分区表
2026-01-11 23:15:01 +08:00
IanShaw027
c1a3dd41dd
feat(ops): 添加运维监控配置开关
...
- 在 .env.example 和 config.example.yaml 中添加 ops.enabled 配置项
- 默认值为 true,保持现有行为
- 当设置为 false 时,左侧栏隐藏运维监控菜单并禁用所有运维监控功能
- 修改后端 GetSettings API,让 ops_monitoring_enabled 受 config.ops.enabled 控制
- 数据清理和预聚合任务默认保持开启状态(通过运维监控设置对话框配置)
2026-01-11 20:10:08 +08:00
yangjianbo
6271a33d08
fix(仪表盘): 兼容禁用聚合与回填限制
2026-01-11 18:20:15 +08:00
yangjianbo
1a869547d7
feat(仪表盘): 引入预聚合统计与聚合作业
2026-01-11 16:01:35 +08:00
IanShaw027
e5857161ff
feat(ops): 增强错误详情弹窗与API支持
...
**前端改动**:
1. OpsErrorDetailModal.vue:
- 新增上游错误详情展示功能
- 支持查看上游错误的请求头、响应体等调试信息
- 改进错误信息格式化与可读性
2. ops.ts API:
- 新增getUpstreamErrors接口调用上游错误查询API
**后端配置**:
- config.go/config.yaml/deploy/config.example.yaml:
- 更新配置支持上游错误事件记录开关
- 添加相关配置项文档说明
2026-01-11 15:31:48 +08:00
yangjianbo
c2c865b0cb
perf(仪表盘): 增强统计缓存与隔离配置
...
新增仪表盘缓存开关与 TTL 配置,支持 Redis key 前缀隔离,并补充单测与校验。
测试: make test-backend
2026-01-11 10:07:03 +08:00
yangjianbo
9d0a4f3d68
perf(认证): 引入 API Key 认证缓存与轻量删除查询
...
增加 L1/L2 缓存、负缓存与单飞回源
使用 key+owner 轻量查询替代全量加载并清理旧接口
补充缓存失效与余额更新测试,修复随机抖动 lint
测试: make test
2026-01-10 22:23:51 +08:00
Song Siyu
7d1fe818be
feat: antigravity 配额域限流 + SSE 上限 ( #222 )
...
* fix: 添加 gemini-3-flash 前缀映射支持 gemini-3-flash-preview
* feat(antigravity): 增强请求参数和注入 Antigravity 身份 system prompt
* feat: antigravity 配额域限流
* chore: 调整 SSE 单行上限到 25MB
* chore: 提升 SSE 单行上限到 40MB
2026-01-09 22:00:14 +08:00
Edric.Li
0a4641c24e
feat(api-key): 添加 IP 白名单/黑名单限制功能 ( #221 )
...
* 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.
2026-01-09 21:59:32 +08:00
admin
152d0cdec6
feat(auth): 添加 Linux DO Connect OAuth 登录支持
...
- 新增 Linux DO OAuth 配置项和环境变量支持
- 实现 OAuth 授权流程和回调处理
- 前端添加 Linux DO 登录按钮和回调页面
- 支持通过 Linux DO 账号注册/登录
- 添加相关国际化文本
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2026-01-09 18:26:32 +08:00
shaw
27291f2e5f
fix(docker): 修改 Redis 配置以支持可选的密码设置
2026-01-09 17:28:55 +08:00
Edric Li
38d875b06f
feat(update): 添加在线更新和定价数据获取的代理支持
...
针对国内服务器访问 GitHub 困难的问题,为在线更新和定价数据获取功能添加代理支持。
主要变更:
- 新增 update.proxy_url 配置项,支持 http/https/socks5/socks5h 协议
- 修改 GitHubReleaseClient 和 PricingRemoteClient 支持代理配置
- 更新 Wire 依赖注入,通过 Provider 函数传递配置
- 更新 Docker 配置文件,支持通过 UPDATE_PROXY_URL 环境变量设置代理
配置示例:
update:
proxy_url: "http://127.0.0.1:7890 "
Docker 环境变量:
UPDATE_PROXY_URL=http://host.docker.internal:7890
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2026-01-07 23:15:20 +08:00
yangjianbo
17ae51c0a0
merge: 合并远程分支并修复代码冲突
...
合并了远程分支 cb72262 的功能更新,同时保留了 ESLint 修复:
**冲突解决详情:**
1. AccountTableFilters.vue
- ✅ 保留 emit 模式修复(避免 vue/no-mutating-props 错误)
- ✅ 添加第三个筛选器 type(账户类型)
- ✅ 新增 antigravity 平台和 inactive 状态选项
2. UserBalanceModal.vue
- ✅ 保留 console.error 错误日志
- ✅ 添加输入验证(金额校验、余额不足检查)
- ✅ 使用 appStore.showError 向用户显示友好错误
3. AccountsView.vue
- ✅ 保留所有 console.error 错误日志(避免 no-empty 错误)
- ✅ 使用新 API:clearRateLimit 和 setSchedulable
4. UsageView.vue
- ✅ 添加 console.error 错误日志
- ✅ 添加图表功能(模型分布、使用趋势)
- ✅ 添加粒度选择(按天/按小时)
- ✅ 保留 XLSX 动态导入优化
**测试结果:**
- ✅ Go tests: PASS
- ✅ golangci-lint: 0 issues
- ✅ ESLint: 0 errors
- ✅ TypeScript: PASS
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2026-01-06 12:50:51 +08:00
yangjianbo
3f0017d1f1
fix(安全): 修复依赖漏洞并强化安全扫描
...
主要改动:
- 固定 Go 1.25.5 与 CI 校验并更新扫描流程
- 升级 quic-go、x/crypto、req 等依赖并通过 govulncheck
- 强化 JWT 校验、TLS 配置与 xlsx 动态加载
- 新增审计豁免清单与校验脚本
2026-01-06 11:36:38 +08:00
shaw
2920409404
docs: 更新 Docker 部署文档强调 JWT_SECRET 配置重要性
...
- docker-compose.yml: 添加注释说明设置固定 JWT_SECRET 可防止容器重启后登录失效
- .env.example: 添加 openssl rand -hex 32 生成安全密钥的命令
2026-01-06 09:44:54 +08:00
shaw
aaaa68ea7f
fix: 修复 CSP 策略阻止 Cloudflare Turnstile 加载的问题
...
在 script-src 和 frame-src 中添加 challenges.cloudflare.com 域名,
允许 Turnstile 脚本加载和 iframe 渲染。
2026-01-06 09:15:03 +08:00
yangjianbo
6451b3cd83
Merge branch 'test'
2026-01-05 17:05:30 +08:00
yangjianbo
c4628d4604
fix(安全): 允许在禁用白名单时使用不安全的 HTTP URL
2026-01-05 16:09:42 +08:00
yangjianbo
ee6d01fd1c
fix(配置): 更新配置文件,添加中文注释并优化部分字段说明
2026-01-05 16:06:03 +08:00
yangjianbo
5668736389
fix(依赖): 更新 Redis 镜像版本至 8-alpine
2026-01-05 15:54:47 +08:00
yangjianbo
1aef4ce20d
fix(部署): 配置文件挂载改为可选,避免 Docker 自动创建目录
...
当挂载的源文件不存在时,Docker 会自动创建同名目录而非文件。
将配置文件挂载默认注释,用户需要时先创建文件再取消注释。
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2026-01-05 15:50:29 +08:00
yangjianbo
ce7893ee44
feat(部署): 支持通过环境变量配置挂载的配置文件路径
...
- docker-compose.yml 配置文件挂载路径改为 ${CONFIG_FILE:-./config.yaml}
- .env.example 添加 CONFIG_FILE 配置项,方便用户指定自定义配置文件
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2026-01-05 15:40:30 +08:00
yangjianbo
4c1293a74c
fix(安全): CSP 策略添加 Google Fonts 支持
...
在 style-src 中添加 fonts.googleapis.com,在 font-src 中添加
fonts.gstatic.com,解决浏览器控制台因 CSP 策略阻止加载
Google Fonts 样式表的错误。
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2026-01-05 15:32:36 +08:00
yangjianbo
fb313356f7
Merge branch 'main' into test-dev
2026-01-05 14:43:08 +08:00
yangjianbo
048ed061c2
fix(安全): 关闭白名单时保留最小校验与默认白名单
...
实现 allow_insecure_http 并在关闭校验时执行最小格式验证
- 关闭 allowlist 时要求 URL 可解析且 scheme 合规
- 响应头过滤关闭时使用默认白名单策略
- 更新相关文档、示例与测试覆盖
2026-01-05 14:41:08 +08:00
yangjianbo
794a9f969b
feat(安全): 添加安全开关并完善测试流程
...
实现安全开关默认关闭与响应头透传逻辑
- URL 校验与响应头过滤支持开关并覆盖流式路径
- 非流式 Content-Type 透传/默认值按配置生效
- 接入 go test、golangci-lint 与前端 lint/typecheck
- 补充相关测试与配置/文档说明
2026-01-05 13:54:43 +08:00
Jiahao Luo
204190f807
feat(crs-sync): improve error messages and add private IP allowlist support
...
## Changes
### 1. Enhanced Error Messages
- Modified CRS sync error handling to show detailed error messages
- Changed from generic "internal error" to "CRS sync failed: <details>"
- Helps diagnose connection issues with private CRS deployments
### 2. Security Configuration
- Added SECURITY_URL_ALLOWLIST_ALLOW_PRIVATE_HOSTS environment variable
- Allows administrators to enable/disable private IP access for CRS sync
- Production default: false (secure)
- Test environment default: true (convenient for internal testing)
### 3. Flexible Configuration Support
- Added config.yaml mount support in both production and test environments
- Supports dual configuration methods:
* config.yaml for detailed/complex configurations
* Environment variables for quick overrides
- Priority: ENV vars > config.yaml > defaults
## Use Case
Enables CRS sync from internal deployments where CRS resolves to private IPs
(e.g., 10.x.x.x, 192.168.x.x) while maintaining security by default.
## Files Modified
- backend/internal/handler/admin/account_handler.go
- deploy/docker-compose.yml
- deploy/docker-compose-test.yml
2026-01-05 12:57:03 +08:00
shaw
7cc7e15174
Merge branch 'IanShaw027/main'
2026-01-05 11:20:28 +08:00
Jiahao Luo
0f79c3cc0e
fix(docker): 修复 Dockerfile npm 构建错误并优化测试配置
...
- 修复 Dockerfile 使用 pnpm 替代 npm ci(适配 pnpm 迁移)
- 为 docker-compose-test.yml 添加自动构建配置
- 更新测试配置文档说明一键构建命令
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2026-01-05 11:10:31 +08:00
ianshaw
118ca5cf6d
fix: 修复空content处理及更新Gemini使用指南链接
...
- 修复FilterThinkingBlocksForRetry对空content数组的处理
- docker-compose添加SECURITY_URL_ALLOWLIST_UPSTREAM_HOSTS配置
- 更新Gemini使用指南链接:检查归属地、修改归属地、激活Gemini Web
2026-01-04 18:26:39 -08:00
yangjianbo
c8e5455df0
chore(配置): 更新上游白名单默认值
...
新增 Kimi/BigModel/Minimax 官方域名到 allowlist
保持示例配置与默认值一致
2026-01-05 09:18:17 +08:00
yangjianbo
7dddd06583
Merge branch 'main' of https://github.com/mt21625457/aicodex2api
2026-01-04 21:06:12 +08:00
yangjianbo
73ffb58518
fix(流式): 提升SSE稳定性并统一超时配置
...
- 扩展SSE行长与间隔超时处理,补充keepalive
- 写入失败与超长行时发送错误事件,修复并发释放
- 同步默认配置与示例配置,更新Caddy超时/压缩规则
- 新增OpenAI流式超时与超长行测试
测试: go test ./...
2026-01-04 19:49:59 +08:00
yangjianbo
e51a32881b
merge: 合并 test 分支到 test-dev,解决冲突
...
解决的冲突文件:
- wire_gen.go: 合并 ConcurrencyService/CRSSyncService 参数和 userAttributeHandler
- gateway_handler.go: 合并 pkg/errors 和 antigravity 导入
- gateway_service.go: 合并 validateUpstreamBaseURL 和 GetAvailableModels
- config.example.yaml: 合并 billing/turnstile 配置和额外 gateway 选项
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2026-01-03 11:36:31 +08:00
IanShaw
7fdc2b2d29
Fix/multiple issues ( #24 )
...
* fix(gemini): 修复 google_one OAuth 配置和 scopes 问题
- 修复 google_one 类型在 ExchangeCode 和 RefreshToken 中使用内置客户端
- 添加 DefaultGoogleOneScopes,包含 generative-language 和 drive.readonly 权限
- 在 EffectiveOAuthConfig 中为 google_one 类型使用专门的 scopes
- 将 docker-compose.override.yml 重命名为 .example 并添加到 .gitignore
- 完善 docker-compose.override.yml.example 示例文档
解决问题:
1. google_one OAuth 授权后 API 调用返回 403 权限不足
2. 缺少访问 Gemini API 所需的 generative-language scope
3. 缺少获取 Drive 存储配额所需的 drive.readonly scope
* fix(antigravity): 完全跳过 Claude 模型的所有 thinking 块
问题分析:
- 当前代码尝试保留有 signature 的 thinking 块
- 但 Vertex AI 的 signature 是完整性令牌,无法在本地验证
- 导致 400 错误:Invalid signature in thinking block
根本原因:
1. thinking 功能已对非 Gemini 模型禁用 (isThinkingEnabled=false)
2. Vertex AI 要求原样重放 (thinking, signature) 对或完全不发送
3. 本地无法复制 Vertex 的加密验证逻辑
修复方案:
- 对 Claude 模型完全跳过所有 thinking 块(无论是否有 signature)
- 保持 Gemini 模型使用 dummy signature 的行为不变
- 更新测试用例以反映新的预期行为
影响:
- 消除 thinking 相关的 400 错误
- 与现有的 thinking 禁用策略保持一致
- 不影响 Gemini 模型的 thinking 功能
测试:
- ✅ TestBuildParts_ThinkingBlockWithoutSignature 全部通过
- ✅ TestBuildTools_CustomTypeTools 全部通过
参考:Codex review 建议
* fix(gateway): 修复 count_tokens 端点 400 错误
问题分析:
- count_tokens 请求包含 thinking 块时返回 400 错误
- 原因:thinking 块未被过滤,直接转发到上游 API
- 上游 API 拒绝无效的 thinking signature
根本原因:
1. /v1/messages 请求通过 TransformClaudeToGemini 过滤 thinking 块
2. count_tokens 请求绕过转换,直接转发原始请求体
3. 导致包含无效 signature 的 thinking 块被发送到上游
修复方案:
- 创建 FilterThinkingBlocks 工具函数
- 在 buildCountTokensRequest 中应用过滤(1 行修改)
- 与 /v1/messages 行为保持一致
实现细节:
- FilterThinkingBlocks: 解析 JSON,过滤 thinking 块,重新序列化
- 失败安全:解析/序列化失败时返回原始请求体
- 性能优化:仅在发现 thinking 块时重新序列化
测试:
- ✅ 6 个单元测试全部通过
- ✅ 覆盖正常过滤、无 thinking 块、无效 JSON 等场景
- ✅ 现有测试不受影响
影响:
- 消除 count_tokens 的 400 错误
- 不影响 Antigravity 账号(仍返回模拟响应)
- 适用于所有账号类型(OAuth、API Key)
文件修改:
- backend/internal/service/gateway_request.go: +62 行(新函数)
- backend/internal/service/gateway_service.go: +2 行(应用过滤)
- backend/internal/service/gateway_request_test.go: +62 行(测试)
* fix(gateway): 增强 thinking 块过滤逻辑
基于 Codex 分析和建议的改进:
问题分析:
- 新错误:signature: Field required(signature 字段缺失)
- 旧错误:Invalid signature(signature 存在但无效)
- 两者都说明 thinking 块在请求中是危险的
Codex 建议:
- 保持 Option A:完全跳过所有 thinking 块
- 原因:thinking 块应该是只输出的,除非有服务端来源证明
- 在无状态代理中,无法安全区分上游来源 vs 客户端注入
改进内容:
1. 增强 FilterThinkingBlocks 函数
- 过滤显式的 thinking 块:{"type":"thinking", ...}
- 过滤无 type 的 thinking 对象:{"thinking": {...}}
- 保留 tool_use 等其他类型块中的 thinking 字段
- 修复:只在实际过滤时更新 content 数组
2. 扩展过滤范围
- 将 FilterThinkingBlocks 应用到 /v1/messages 主路径
- 之前只应用于 count_tokens,现在两个端点都过滤
- 防止所有端点的 thinking 相关 400 错误
3. 改进测试
- 新增:过滤无 type discriminator 的 thinking 块
- 新增:不过滤 tool_use 中的 thinking 字段
- 使用 containsThinkingBlock 辅助函数验证
测试:
- ✅ 8 个测试用例全部通过
- ✅ 覆盖各种 thinking 块格式
- ✅ 确保不误伤其他类型的块
影响:
- 消除 signature required 和 invalid signature 错误
- 统一 /v1/messages 和 count_tokens 的行为
- 更健壮的 thinking 块检测逻辑
参考:Codex review 和代码改进
* refactor: 根据 Codex 审查建议进行代码优化
基于 Codex 代码审查的 P1 和 P2 改进:
P1 改进(重要问题):
1. 优化日志输出
- 移除 thinking 块跳过时的 log.Printf
- 避免高频请求下的日志噪音
- 添加注释说明可通过指标监控
2. 清理遗留代码
- 删除未使用的 isValidThoughtSignature 函数(27行)
- 该函数在改为完全跳过 thinking 块后不再需要
P2 改进(性能优化):
3. 添加快速路径检查
- 在 FilterThinkingBlocks 中添加 bytes.Contains 预检查
- 如果请求体不包含 "thinking" 字符串,直接返回
- 避免不必要的 JSON 解析,提升性能
技术细节:
- request_transformer.go: -27行(删除函数),+1行(优化注释)
- gateway_request.go: +5行(快速路径 + bytes 导入)
测试:
- ✅ TestBuildParts_ThinkingBlockWithoutSignature 全部通过
- ✅ TestFilterThinkingBlocks 全部通过(8个测试用例)
影响:
- 减少日志噪音
- 提升性能(快速路径)
- 代码更简洁(删除未使用代码)
参考:Codex 代码审查建议
* fix: 修复 golangci-lint 检查问题
- 格式化 gateway_request_test.go
- 使用 switch 语句替代 if-else 链(staticcheck QF1003)
* fix(antigravity): 修复 thinking signature 处理并实现 Auto 模式降级
问题分析:
1. 原先代码错误地禁用了 Claude via Vertex 的 thinkingConfig
2. 历史 thinking 块的 signature 被完全跳过,导致验证失败
3. 跨模型混用时 dummy signature 会导致 400 错误
修复内容:
**request_transformer.go**:
- 删除第 38-43 行的错误逻辑(禁用 thinkingConfig)
- 引入 thoughtSignatureMode(Preserve/Dummy)策略
- Claude 模式:透传真实 signature,过滤空/dummy
- Gemini 模式:使用 dummy signature
- 支持 signature-only thinking 块
- tool_use 的 signature 也透传
**antigravity_gateway_service.go**:
- 新增 isSignatureRelatedError() 检测 signature 相关错误
- 新增 stripThinkingFromClaudeRequest() 移除 thinking 块
- 实现 Auto 模式:检测 400 + signature 关键词时自动降级重试
- 重试时完全移除 thinking 配置和消息中的 thinking 块
- 最多重试一次,避免循环
**测试**:
- 更新并新增测试覆盖 Claude preserve/Gemini dummy 模式
- 新增 tool_use signature 处理测试
- 所有测试通过(6/6)
影响:
- ✅ Claude via Vertex 可以正常使用 thinking 功能
- ✅ 历史 signature 正确透传,避免验证失败
- ✅ 跨模型混用时自动过滤无效 signature
- ✅ 错误驱动降级,自动修复 signature 问题
- ✅ 不影响纯 Claude API 和其他渠道
参考:Codex 深度分析和实现建议
* fix(lint): 修复 gofmt 格式问题
* fix(antigravity): 修复 stripThinkingFromClaudeRequest 遗漏 untyped thinking blocks
问题:
- Codex 审查指出 stripThinkingFromClaudeRequest 只移除了 type="thinking" 的块
- 没有处理没有 type 字段的 thinking 对象(如 {"thinking": "...", "signature": "..."})
- 导致重试时仍包含无效 thinking 块,上游 400 错误持续
修复:
- 添加检查:跳过没有 type 但有 thinking 字段的块
- 现在会移除两种格式:
1. {"type": "thinking", "thinking": "...", "signature": "..."}
2. {"thinking": "...", "signature": "..."}(untyped)
测试:所有测试通过
参考:Codex P1 审查意见
2026-01-02 17:47:49 +08:00
yangjianbo
bd4bf00856
feat(安全): 强化安全策略与配置校验
...
- 增加 CORS/CSP/安全响应头与代理信任配置
- 引入 URL 白名单与私网开关,校验上游与价格源
- 改善 API Key 处理与网关错误返回
- 管理端设置隐藏敏感字段并优化前端提示
- 增加计费熔断与相关配置示例
测试: go test ./...
2026-01-02 17:40:57 +08:00
shaw
2a395d12a6
Merge branch 'feature/atomic-scheduling'
2026-01-01 11:05:22 +08:00
IanShaw027
d3cba34bc6
flow
2026-01-01 08:45:49 +08:00
IanShaw027
06d483fa8d
feat(backend): implement gemini quota simulation and rate limiting
...
- feat: add local quota tracking for gemini tiers (Legacy/Pro/Ultra)
- feat: implement PreCheckUsage in RateLimitService
- feat: align gemini daily reset window with PST
- fix: sticky session fallback logic
2026-01-01 04:29:22 +08:00
IanShaw
34c102045a
fix: 修复 /v1/messages 间歇性 400 错误 ( #18 )
...
* fix(upstream): 修复上游格式兼容性问题
- 跳过Claude模型无signature的thinking block
- 支持custom类型工具(MCP)格式转换
- 添加ClaudeCustomToolSpec结构体支持MCP工具
- 添加Custom字段验证,跳过无效custom工具
- 在convertClaudeToolsToGeminiTools中添加schema清理
- 完整的单元测试覆盖,包含边界情况
修复: Issue 0.1 signature缺失, Issue 0.2 custom工具格式
改进: Codex审查发现的2个重要问题
测试:
- TestBuildParts_ThinkingBlockWithoutSignature: 验证thinking block处理
- TestBuildTools_CustomTypeTools: 验证custom工具转换和边界情况
- TestConvertClaudeToolsToGeminiTools_CustomType: 验证service层转换
* feat(gemini): 添加Gemini限额与TierID支持
实现PR1:Gemini限额与TierID功能
后端修改:
- GeminiTokenInfo结构体添加TierID字段
- fetchProjectID函数返回(projectID, tierID, error)
- 从LoadCodeAssist响应中提取tierID(优先IsDefault,回退到第一个非空tier)
- ExchangeCode、RefreshAccountToken、GetAccessToken函数更新以处理tierID
- BuildAccountCredentials函数保存tier_id到credentials
前端修改:
- AccountStatusIndicator组件添加tier显示
- 支持LEGACY/PRO/ULTRA等tier类型的友好显示
- 使用蓝色badge展示tier信息
技术细节:
- tierID提取逻辑:优先选择IsDefault的tier,否则选择第一个非空tier
- 所有fetchProjectID调用点已更新以处理新的返回签名
- 前端gracefully处理missing/unknown tier_id
* refactor(gemini): 优化TierID实现并添加安全验证
根据并发代码审查(code-reviewer, security-auditor, gemini, codex)的反馈进行改进:
安全改进:
- 添加validateTierID函数验证tier_id格式和长度(最大64字符)
- 限制tier_id字符集为字母数字、下划线、连字符和斜杠
- 在BuildAccountCredentials中验证tier_id后再存储
- 静默跳过无效tier_id,不阻塞账户创建
代码质量改进:
- 提取extractTierIDFromAllowedTiers辅助函数消除重复代码
- 重构fetchProjectID函数,tierID提取逻辑只执行一次
- 改进代码可读性和可维护性
审查工具:
- code-reviewer agent (a09848e)
- security-auditor agent (a9a149c)
- gemini CLI (bcc7c81)
- codex (b5d8919)
修复问题:
- HIGH: 未验证的tier_id输入
- MEDIUM: 代码重复(tierID提取逻辑重复2次)
* fix(format): 修复 gofmt 格式问题
- 修复 claude_types.go 中的字段对齐问题
- 修复 gemini_messages_compat_service.go 中的缩进问题
* fix(upstream): 修复上游格式兼容性问题 (#14 )
* fix(upstream): 修复上游格式兼容性问题
- 跳过Claude模型无signature的thinking block
- 支持custom类型工具(MCP)格式转换
- 添加ClaudeCustomToolSpec结构体支持MCP工具
- 添加Custom字段验证,跳过无效custom工具
- 在convertClaudeToolsToGeminiTools中添加schema清理
- 完整的单元测试覆盖,包含边界情况
修复: Issue 0.1 signature缺失, Issue 0.2 custom工具格式
改进: Codex审查发现的2个重要问题
测试:
- TestBuildParts_ThinkingBlockWithoutSignature: 验证thinking block处理
- TestBuildTools_CustomTypeTools: 验证custom工具转换和边界情况
- TestConvertClaudeToolsToGeminiTools_CustomType: 验证service层转换
* fix(format): 修复 gofmt 格式问题
- 修复 claude_types.go 中的字段对齐问题
- 修复 gemini_messages_compat_service.go 中的缩进问题
* fix(format): 修复 claude_types.go 的 gofmt 格式问题
* feat(antigravity): 优化 thinking block 和 schema 处理
- 为 dummy thinking block 添加 ThoughtSignature
- 重构 thinking block 处理逻辑,在每个条件分支内创建 part
- 优化 excludedSchemaKeys,移除 Gemini 实际支持的字段
(minItems, maxItems, minimum, maximum, additionalProperties, format)
- 添加详细注释说明 Gemini API 支持的 schema 字段
* fix(antigravity): 增强 schema 清理的安全性
基于 Codex review 建议:
- 添加 format 字段白名单过滤,只保留 Gemini 支持的 date-time/date/time
- 补充更多不支持的 schema 关键字到黑名单:
* 组合 schema: oneOf, anyOf, allOf, not, if/then/else
* 对象验证: minProperties, maxProperties, patternProperties 等
* 定义引用: $defs, definitions
- 避免不支持的 schema 字段导致 Gemini API 校验失败
* fix(lint): 修复 gemini_messages_compat_service 空分支警告
- 在 cleanToolSchema 的 if 语句中添加 continue
- 移除重复的注释
* fix(antigravity): 移除 minItems/maxItems 以兼容 Claude API
- 将 minItems 和 maxItems 添加到 schema 黑名单
- Claude API (Vertex AI) 不支持这些数组验证字段
- 添加调试日志记录工具 schema 转换过程
- 修复 tools.14.custom.input_schema 验证错误
* fix(antigravity): 修复 additionalProperties schema 对象问题
- 将 additionalProperties 的 schema 对象转换为布尔值 true
- Claude API 只支持 additionalProperties: false,不支持 schema 对象
- 修复 tools.14.custom.input_schema 验证错误
- 参考 Claude 官方文档的 JSON Schema 限制
* fix(antigravity): 修复 Claude 模型 thinking 块兼容性问题
- 完全跳过 Claude 模型的 thinking 块以避免 signature 验证失败
- 只在 Gemini 模型中使用 dummy thought signature
- 修改 additionalProperties 默认值为 false(更安全)
- 添加调试日志以便排查问题
* fix(upstream): 修复跨模型切换时的 dummy signature 问题
基于 Codex review 和用户场景分析的修复:
1. 问题场景
- Gemini (thinking) → Claude (thinking) 切换时
- Gemini 返回的 thinking 块使用 dummy signature
- Claude API 会拒绝 dummy signature,导致 400 错误
2. 修复内容
- request_transformer.go:262: 跳过 dummy signature
- 只保留真实的 Claude signature
- 支持频繁的跨模型切换
3. 其他修复(基于 Codex review)
- gateway_service.go:691: 修复 io.ReadAll 错误处理
- gateway_service.go:687: 条件日志(尊重 LogUpstreamErrorBody 配置)
- gateway_service.go:915: 收紧 400 failover 启发式
- request_transformer.go:188: 移除签名成功日志
4. 新增功能(默认关闭)
- 阶段 1: 上游错误日志(GATEWAY_LOG_UPSTREAM_ERROR_BODY)
- 阶段 2: Antigravity thinking 修复
- 阶段 3: API-key beta 注入(GATEWAY_INJECT_BETA_FOR_APIKEY)
- 阶段 3: 智能 400 failover(GATEWAY_FAILOVER_ON_400)
测试:所有测试通过
* fix(lint): 修复 golangci-lint 问题
- 应用 De Morgan 定律简化条件判断
- 修复 gofmt 格式问题
- 移除未使用的 min 函数
2026-01-01 04:21:18 +08:00
yangjianbo
d1c9889609
perf(网关): 实现上游账号连接池隔离
...
新增隔离策略与连接池缓存回收
连接池大小跟随账号并发并处理代理切换
同步配置默认值与示例并补充测试
2025-12-31 11:43:58 +08:00
yangjianbo
7efa8b54c4
perf(后端): 完成性能优化与连接池配置
...
新增 DB/Redis 连接池配置与校验,并补充单测
网关请求体大小限制与 413 处理
HTTP/req 客户端池化并调整上游连接池默认值
并发槽位改为 ZSET+Lua 与指数退避
用量统计改 SQL 聚合并新增索引迁移
计费缓存写入改工作池并补测试/基准
测试: 在 backend/ 下运行 go test ./...
2025-12-31 08:50:12 +08:00
yangjianbo
5376786694
chore(配置): 提升容器文件描述符上限到10万
...
调整原因:
- 防止高并发下出现 "too many open files" 错误
- 统一测试与生产环境的 ulimits 配置
改动内容:
- 为 sub2api、postgres、redis 设置 nofile
- 软硬限制均为 100000
测试: 未运行
2025-12-30 20:28:41 +08:00