IanShaw
afcfbb458d
fix(gemini): Google One 强制使用内置 OAuth client + 自动获取 project_id + UI 优化 ( #212 )
...
* fix(gemini): Google One 强制使用内置 OAuth client + 自动获取 project_id + UI 优化
## 后端改动
### 1. Google One 强制使用内置 Gemini CLI OAuth Client
**问题**:
- Google One 之前允许使用自定义 OAuth client,导致认证流程不稳定
- 与 Code Assist 的行为不一致
**解决方案**:
- 修改 `gemini_oauth_service.go`: Google One 现在与 Code Assist 一样强制使用内置 client (L122-135)
- 更新 `gemini_oauth_client.go`: ExchangeCode 和 RefreshToken 方法支持强制内置 client (L31-44, L77-86)
- 简化 `geminicli/oauth.go`: Google One scope 选择逻辑 (L187-190)
- 标记 `geminicli/constants.go`: DefaultGoogleOneScopes 为 DEPRECATED (L30-33)
- 更新测试用例以反映新行为
**OAuth 类型对比**:
| OAuth类型 | Client来源 | Scopes | Redirect URI |
|-----------|-----------|--------|-----------------|
| code_assist | 内置 Gemini CLI | DefaultCodeAssistScopes | https://codeassist.google.com/authcode |
| google_one | 内置 Gemini CLI (新) | DefaultCodeAssistScopes | https://codeassist.google.com/authcode |
| ai_studio | 必须自定义 | DefaultAIStudioScopes | http://localhost:1455/auth/callback |
### 2. Google One 自动获取 project_id
**问题**:
- Google One 个人账号测试模型时返回 403/404 错误
- 原因:cloudaicompanion API 需要 project_id,但个人账号无需手动创建 GCP 项目
**解决方案**:
- 修改 `gemini_oauth_service.go`: OAuth 流程中自动调用 fetchProjectID
- Google 通过 LoadCodeAssist API 自动分配 project_id
- 与 Gemini CLI 行为保持一致
- 后端根据 project_id 自动选择正确的 API 端点
**影响**:
- Google One 账号现在可以正常使用(需要重新授权)
- Code Assist 和 AI Studio 账号不受影响
### 3. 修复 Gemini 测试账号无内容输出问题
**问题**:
- 测试 Gemini 账号时只显示"测试成功",没有显示 AI 响应内容
- 原因:processGeminiStream 在检查到 finishReason 时立即返回,跳过了内容提取
**解决方案**:
- 修改 `account_test_service.go`: 调整逻辑顺序,先提取内容再检查是否完成
- 确保最后一个 chunk 的内容也能被正确显示
**影响**:
- 所有 Gemini 账号类型(API Key、OAuth)的测试现在都会显示完整响应内容
- 用户可以看到流式输出效果
## 前端改动
### 1. 修复图标宽度压缩问题
**问题**:
- 账户类型选择按钮中的图标在某些情况下会被压缩变形
**解决方案**:
- 修改 `CreateAccountModal.vue`: 为所有平台图标容器添加 `shrink-0` 类
- 确保 Anthropic、OpenAI、Gemini、Antigravity 图标保持固定 8×8 尺寸 (32px × 32px)
### 2. 优化重新授权界面
**问题**:
- 重新授权时显示三个可点击的授权类型选择按钮,可能导致用户误切换到不兼容的授权方式
**解决方案**:
- 修改 `ReAuthAccountModal.vue` (admin 和普通用户版本):
- 将可点击的授权类型选择按钮改为只读信息展示框
- 根据账号的 `credentials.oauth_type` 动态显示对应图标和文本
- 删除 `geminiAIStudioOAuthEnabled` 状态和 `handleSelectGeminiOAuthType` 方法
- 防止用户误操作
## 测试验证
- ✅ 所有后端单元测试通过
- ✅ OAuth client 选择逻辑正确
- ✅ Google One 和 Code Assist 行为一致
- ✅ 测试账号显示完整响应内容
- ✅ UI 图标显示正常
- ✅ 重新授权界面只读展示正确
* fix(lint): 修复 golangci-lint 错误信息格式问题
- 将错误信息改为小写开头以符合 Go 代码规范
- 修复 ST1005: error strings should not be capitalized
2026-01-08 23:47:29 +08:00
Edric Li
b7a29a4bac
fix: update mock interfaces and fix gofmt issues for CI
...
- Update mockGatewayCacheForPlatform and mockGatewayCacheForGemini
to match new GatewayCache interface with groupID parameter
- Fix gofmt formatting in group_handler.go and admin_service.go
2026-01-08 23:13:57 +08:00
Edric Li
a42105881f
feat(groups): add Claude Code client restriction and session isolation
...
- Add claude_code_only field to restrict groups to Claude Code clients only
- Add fallback_group_id for non-Claude Code requests to use alternate group
- Implement ClaudeCodeValidator for User-Agent detection
- Add group-level session binding isolation (groupID in Redis key)
- Prevent cross-group sticky session pollution
- Update frontend with Claude Code restriction controls
2026-01-08 23:07:00 +08:00
Edric Li
958ffe7a8a
test: fix unit tests for user_agent and proxy repo interface
...
- Add user_agent field to API contract test expectation
- Add ListWithFiltersAndAccountCount stub to proxyRepoStub
2026-01-08 21:44:18 +08:00
Edric Li
b46b3c5c3c
Merge remote-tracking branch 'upstream/main'
2026-01-08 21:35:34 +08:00
Edric Li
eb198e5969
feat(proxies): add account count column to proxy list
...
Display the number of accounts bound to each proxy in the admin proxy
management page, similar to the groups list view.
2026-01-08 21:20:12 +08:00
shaw
b015a3bd8a
fix(antigravity): 修复频繁出现429错误的问题
2026-01-08 20:06:32 +08:00
shaw
6e8188ed64
fix(antigravity): 修复请求频繁429的问题
2026-01-08 17:27:35 +08:00
shaw
db6f53e2c9
fix(billing): 修复客户端取消请求时计费丢失问题
...
检测 context.Canceled 作为客户端断开信号,返回已收集的 usage 而非错误
2026-01-08 11:25:17 +08:00
shaw
169aa4716e
Merge branch 'feature/account-expires-at' into main: feat: add account expires-at field and auto-pause expired accounts
2026-01-08 09:27:57 +08:00
Edric Li
1ada6cf768
feat(usage-log): 增加请求 User-Agent 记录
...
在使用记录中添加 user_agent 字段,用于记录 API 请求的 User-Agent 头信息,
便于分析客户端类型和调试。
变更内容:
- 新增数据库迁移 028_add_usage_logs_user_agent.sql
- 更新 UsageLog 模型和 Ent Schema 添加 user_agent 字段
- 更新 Repository 层的 Create 和 scanUsageLog 方法
- 更新 RecordUsageInput 结构体支持传入 UserAgent
- 更新 Claude/OpenAI/Gemini 三个网关 Handler 传递 UserAgent
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2026-01-07 22:49:46 +08:00
LLLLLLiulei
2b528c5f81
feat: auto-pause expired accounts
2026-01-07 16:59:35 +08:00
shaw
d99a3ef14b
fix(gateway): 修复账号跨分组调度问题
...
问题:账号可能被调度到未分配的分组(如 simon 账号被调度到 claude_default)
根因:
- 强制平台模式下分组查询失败时回退到全平台查询
- listSchedulableAccounts 中分组为空时回退到无分组查询
- 粘性会话只检查平台匹配,未校验账号分组归属
修复:
- 移除强制平台模式的回退逻辑,分组内无账号时返回错误
- 移除 listSchedulableAccounts 的回退逻辑
- 新增 isAccountInGroup 方法用于分组校验
- 在三处粘性会话检查中增加分组归属验证
2026-01-07 10:56:52 +08:00
shaw
6dcd99468b
fix(gateway): 修复 cache_control 块超限问题并优化 Claude Code 检测
...
问题:
- OAuth/SetupToken 账号注入 system prompt 后可能导致 cache_control
块超过 Anthropic API 的 4 个限制
- Claude Code 检测使用精确匹配,无法识别 Agent SDK 等变体
修复:
- 新增 enforceCacheControlLimit 函数,强制执行 4 个块限制
- 优先从 messages 移除,再从 system 尾部移除(保护注入的 prompt)
- 改用前缀匹配检测 Claude Code 系统提示词,支持多种变体:
- 标准版、Agent SDK 版、Explore Agent 版、Compact 版
2026-01-07 10:17:09 +08:00
shaw
015974a27e
feat(admin/usage): 优化管理员用量页面功能和体验
...
后端改进:
- 新增 GetStatsWithFilters 方法支持完整筛选条件
- Stats 端点支持 account_id, group_id, model, stream, billing_type 参数
- 统一使用 filters 结构体,移除冗余的分支逻辑
前端改进:
- 统计卡片添加"所选范围内"文字提示
- 优化总消费显示格式,清晰展示实际费用和标准计费
- Token 和费用列添加问号图标 tooltip 显示详细信息
- API Key 搜索框体验优化:点击即显示下拉选项
- 选择用户后自动加载该用户的所有 API Key
2026-01-06 22:19:07 +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
song
195e227c04
merge: 合并 upstream/main 并保留本地图片计费功能
2026-01-06 10:49:26 +08:00
shaw
706af2920f
Merge branch 'fix/account-filters-menu-missing-features'
...
## Summary
- 修复账号管理页面组件拆分时遗漏的功能
- 统一所有内联 SVG 为 Icon 组件
- 修复 ProxySelector 选择"无代理"时发送错误值的问题
## Changes
- AccountTableFilters: 添加 Antigravity 平台选项、类型筛选器、inactive 状态
- AccountActionMenu: 恢复重置状态和清除限速按钮
- AccountsView: 修正 handleClearRateLimit 调用正确的 API
- ProxySelector: 修复选择"无代理"时发送 null 而不是 0
## Conflict Resolution
- ProxySelector.vue: 采用 PR 分支的正确逻辑(发送 null 而不是 0)
这是正确的修复,因为后端使用 *int64 类型,nil 会触发 ClearProxyID()
2026-01-05 21:16:05 +08:00
shaw
4d078a8854
fix(admin): 修复零值字段无法保存的问题
...
- 用户允许分组:前端发送空数组而非 null 表示"允许全部"
- 账户代理:前端发送 0 而非 null 表示"无代理"
- 后端 UpdateAccount/BulkUpdate 正确处理 ProxyID=0 为清除代理
2026-01-05 20:53:38 +08:00
IanShaw027
34aa77e4e1
fix(backend): 删除未使用的 sleepAntigravityBackoff 函数
...
修复 golangci-lint unused 检查失败
2026-01-05 20:15:36 +08:00
song
5b1907fe61
fix: 图片计费代码审查问题修复
...
- isImageGenerationModel 改为精确匹配/前缀匹配,避免误匹配
- 新增 normalizePrice 函数,支持负数清除价格配置
- 更新注释说明 Gemini API 每次请求只生成一张图片
- 添加测试用例验证不会误匹配自定义模型名
2026-01-05 17:14:06 +08:00
程序猿MT
e800af54f9
Merge branch 'Wei-Shaw:main' into main
2026-01-05 17:12:09 +08:00
song
d4c2b723a5
feat: 图片生成计费功能
...
- 新增 Group 图片价格配置(image_price_1k/2k/4k)
- BillingService 新增 CalculateImageCost 方法
- AntigravityGatewayService 支持识别图片生成模型并按次计费
- UsageLog 新增 image_count 和 image_size 字段
- 前端分组管理支持配置图片价格(antigravity 和 gemini 平台)
- 图片计费复用通用计费能力(余额检查、扣费、倍率、订阅限额)
2026-01-05 17:07:29 +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
ianshaw
471b1c3eeb
fix(frontend): 修复重构时遗漏的 SVG 图标,创建统一图标管理组件
...
- 创建 Icon.vue 统一管理 SVG 图标(20+ 常用图标)
- 修复 AccountActionMenu 中被错误替换为 emoji 的图标
- 修复 ProfileView 和 GroupsView 中的 emoji 图标
- 图标支持 size/strokeWidth 属性,便于复用
2026-01-04 22:26:33 -08:00
LLLLLLiulei
94750fb61f
feat: add account notes field
2026-01-05 14:07:33 +08:00
yangjianbo
794a9f969b
feat(安全): 添加安全开关并完善测试流程
...
实现安全开关默认关闭与响应头透传逻辑
- URL 校验与响应头过滤支持开关并覆盖流式路径
- 非流式 Content-Type 透传/默认值按配置生效
- 接入 go test、golangci-lint 与前端 lint/typecheck
- 补充相关测试与配置/文档说明
2026-01-05 13:54:43 +08:00
ianshaw
ae3d6fd776
fix(antigravity): 扩展 isSignatureRelatedError 检测 thinking 结构错误
...
- 添加对 "Expected thinking/redacted_thinking" 错误的检测
- 修复 antigravity 服务中 thinking 模式启用时的结构约束错误
- 确保此类错误能触发重试逻辑
2026-01-04 18:34:19 -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
IanShaw027
06216aad53
fix(backend): 修复 CI 失败问题
...
修复内容:
1. 修复 6 个 golangci-lint 错误
- 3 个 errcheck 错误:在 gateway_request_test.go 中添加类型断言检查
- 3 个 gofmt 格式化问题:修复代码格式
2. 修复 API 契约测试失败
- 在测试中添加缺失的字段:enable_identity_patch 和 identity_patch_prompt
所有测试和 linter 检查现已通过。
2026-01-05 00:56:48 +08:00
IanShaw027
aa6f253374
merge: 合并 upstream/main 并解决冲突
...
解决了以下文件的冲突:
- backend/internal/handler/admin/setting_handler.go
- 采用 upstream 的字段对齐风格和 *Configured 字段名
- 添加 EnableIdentityPatch 和 IdentityPatchPrompt 字段
- backend/internal/handler/gateway_handler.go
- 采用 upstream 的 billingErrorDetails 错误处理方式
- frontend/src/api/admin/settings.ts
- 采用 upstream 的 *_configured 字段名
- 添加 enable_identity_patch 和 identity_patch_prompt 字段
- frontend/src/views/admin/SettingsView.vue
- 合并 turnstile_secret_key_configured 字段
- 保留 enable_identity_patch 和 identity_patch_prompt 字段
2026-01-04 23:17:15 +08:00
IanShaw027
f60f943d0c
fix: 修复代码审查报告中的4个关键问题
...
1. 资源管理冗余(ForwardGemini双重Close)
- 错误分支读取body后立即关闭原始body,用内存副本重新包装
- defer添加nil guard,避免重复关闭
- fallback成功时显式关闭旧body,确保连接释放
2. Schema校验丢失(cleanJSONSchema移除字段无感知)
- 新增schemaCleaningWarningsEnabled()支持环境变量控制
- 实现warnSchemaKeyRemovedOnce()在非release模式下告警
- 移除关键验证字段时输出warning,包含key和path
3. UI响应式风险(UsersView操作菜单硬编码定位)
- 菜单改为先粗定位、渲染后测量、再clamp到视口内
- 添加max-height + overflow-auto,超出时可滚动
- 增强交互:点击其它位置/滚动/resize自动关闭或重新定位
4. 身份补丁干扰(TransformClaudeToGemini默认注入)
- 新增TransformOptions + TransformClaudeToGeminiWithOptions
- 系统设置新增enable_identity_patch、identity_patch_prompt
- 完整打通handler/dto/service/frontend配置链路
- 默认保持启用,向后兼容现有行为
测试:
- 后端单测全量通过:go test ./...
- 前端类型检查通过:npm run typecheck
2026-01-04 22:49:40 +08:00
IanShaw027
87426e5dda
fix(backend): 改进 thinking/tool block 签名处理和重试策略
...
主要改动:
- request_transformer: thinking block 缺少签名时降级为文本而非丢弃,保留内容并在上层禁用 thinking mode
- antigravity_gateway_service: 新增两阶段降级策略,先处理 thinking blocks,如仍失败且涉及 tool 签名错误则进一步降级 tool blocks
- gateway_request: 新增 FilterSignatureSensitiveBlocksForRetry 函数,支持将 tool_use/tool_result 降级为文本
- gateway_request: 改进 FilterThinkingBlocksForRetry,禁用顶层 thinking 配置以避免结构约束冲突
- gateway_service: 实现保守的两阶段重试逻辑,优先保留内容,仅在必要时降级工具调用
- 新增 antigravity_gateway_service_test.go 测试签名块剥离逻辑
- 更新相关测试用例以验证降级行为
此修复解决了跨平台/账户切换时历史消息签名失效导致的请求失败问题。
2026-01-04 22:32:36 +08:00
yangjianbo
5dd8b8802b
fix(后端): 修复 lint 失败并清理无用代码
...
修正测试中的 APIKey 名称引用
移除不可达返回与未使用函数
统一 gofmt 格式并处理 Close 错误
2026-01-04 22:10:32 +08:00
IanShaw027
7122b3b3b6
fix(backend): 修复 P0/P1 严重安全和稳定性问题
...
P0 严重问题修复:
- 优化重试机制:降至 5 次 + 指数退避 + 10s 上限,防止请求堆积
- 修复 SSE 错误格式:符合 Anthropic API 规范,添加错误类型标准化
P1 重要问题修复:
- 防止 DOS 攻击:使用 io.LimitReader 限制请求体 10MB,流式解析
- 修复计费数据丢失:改为同步计费,使用独立 context 防止中断
技术细节:
- 新增 retryBackoffDelay() 和 sleepWithContext() 支持 context 取消
- 新增 normalizeAnthropicErrorType() 和 sanitizePublicErrorMessage()
- 新增 parseGatewayRequestStream() 实现流式解析
- 新增 recordUsageSync() 确保计费数据持久化
影响:
- 极端场景重试时间从 30s 降至 ≤10s
- 防止高并发 OOM 攻击
- 消除计费数据丢失风险
- 提升客户端兼容性
2026-01-04 21:29:09 +08:00
IanShaw027
d36392b74f
fix(frontend): comprehensive i18n cleanup and Select component hardening
2026-01-04 21:09:14 +08:00
yangjianbo
7dddd06583
Merge branch 'main' of https://github.com/mt21625457/aicodex2api
2026-01-04 21:06:12 +08:00
shaw
e78c864650
Merge PR #142 : feat: 多平台网关优化与用户系统增强
...
主要功能:
- Gemini OAuth 配额系统优化:Google One tier 自动推断
- Antigravity 网关增强:Thinking Block 重试、Claude 模型 signature 透传
- 账号调度改进:临时不可调度功能、负载感知调度优化
- 前端用户体验:账号管理界面优化、使用教程改进
冲突解决:保留 handleUpstreamError 的 prefix 参数和日志记录能力,
同时合并 PR 的 thinking block 重试和 model fallback 功能。
2026-01-04 20:30:19 +08:00
yangjianbo
25a0d49af9
chore(合并): 同步主分支变更并解决冲突
...
- 合并 wire/httpclient/http_upstream/proxy_probe 冲突并保留校验逻辑
- 引入 proxyutil 及测试,完善代理配置
- 更新 goreleaser/workflow 与前端细节调整
测试: go test ./...
2026-01-04 20:29:39 +08:00
yangjianbo
7489da49cb
fix(流式): 以上游读取判定超时并调大事件缓冲
...
- 以读取时间戳判定流式间隔超时,避免下游阻塞误判
- antigravity 流式读取使用 MaxLineSize 配置
- 事件通道缓冲提升到 16
测试: go test ./...
2026-01-04 20:19:07 +08:00
shaw
4df712624e
Merge branch 'slovx2/main'
2026-01-04 19:51:17 +08:00
yangjianbo
73ffb58518
fix(流式): 提升SSE稳定性并统一超时配置
...
- 扩展SSE行长与间隔超时处理,补充keepalive
- 写入失败与超长行时发送错误事件,修复并发释放
- 同步默认配置与示例配置,更新Caddy超时/压缩规则
- 新增OpenAI流式超时与超长行测试
测试: go test ./...
2026-01-04 19:49:59 +08:00
IanShaw027
a4953785d9
fix(lint): 修复所有 Go 命名规范问题
...
- 全局替换 ApiKey → APIKey(类型、字段、方法、变量)
- 修复所有 initialism 命名(API, SMTP, HTML, URL 等)
- 添加所有缺失的包注释
- 修复导出符号的注释格式
主要修改:
- ApiKey → APIKey(所有出现的地方)
- ApiKeyID → APIKeyID
- ApiKeyIDs → APIKeyIDs
- TestSmtpConnection → TestSMTPConnection
- HtmlURL → HTMLURL
- 添加 20+ 个包注释
- 修复 10+ 个导出符号注释格式
验证结果:
- ✓ golangci-lint: 0 issues
- ✓ 单元测试: 通过
- ✓ 集成测试: 通过
2026-01-04 19:28:20 +08:00
IanShaw027
a8c3dfb0c1
merge: 合并 upstream/main 解决冲突
...
- 接受上游 wire_gen.go 的简化构造函数参数
- 接受上游 account_test_service.go 的优化实现
2026-01-04 17:41:06 +08:00
shaw
a527559526
fix(test): 修复claude、openai oauth账号test刷新token的bug
2026-01-04 17:29:34 +08:00
IanShaw027
2632a7102d
refactor(settings): 规范化缩写词命名并优化前端帮助界面
...
- 后端:将 Smtp/Api/Doc 字段改为 SMTP/API/Doc(遵循 Go 命名规范)
- 前端:添加 Gemini 帮助按钮,简化配额说明展示
2026-01-04 17:02:38 +08:00
song
63453fbfa0
style: gofmt
2026-01-04 16:58:51 +08:00
song
50f9272850
feat(antigravity): gemini-2.5-flash-image 转发到 gemini-3-pro-image
2026-01-04 16:53:35 +08:00