Commit Graph

85 Commits

Author SHA1 Message Date
sczheng189
5366dc70e1 fix: 修复重置账号状态后仍被认为不可用的bug
问题描述:
- 重置账号状态时虽然正确设置了 schedulable: 'true'
- 但在账号选择逻辑中缺少对 schedulable !== 'false' 的检查
- 导致重置后的账号仍被认为不可用

修复内容:
- selectAvailableAccount: 在 activeAccounts 过滤中添加 schedulable 检查
- selectAccountForApiKey: 在绑定账户和 sharedAccounts 过滤中添加 schedulable 检查
- 确保重置状态后的账号能正确被识别为可用

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-25 19:18:51 +08:00
sczheng189
f4f88091c1 feat: 扩展熔断机制支持所有5xx错误码
- 扩展错误检测从单一500错误到所有5xx错误码(500-599)
- 新增temp_error状态,连续3次5xx错误触发临时熔断
- 支持流式和非流式请求的统一5xx错误处理
- 添加定时清理机制,60分钟后自动恢复temp_error状态
- 完善错误计数和清理逻辑,提高系统可靠性

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-25 19:14:14 +08:00
shaw
b426a759a8 feat: 支持后台配置webhook 2025-08-23 20:20:32 +08:00
shaw
cb29b3f7e4 fix: 代理ip使用重构为统一方法 2025-08-20 23:21:32 +08:00
shaw
a45c832278 feat: 统一代理配置管理,支持IPv4/IPv6协议族选择
- 新增统一代理工具 ProxyHelper,支持 SOCKS5/HTTP/HTTPS 代理
- 添加 IPv4/IPv6 协议族配置选项,默认使用 IPv4 确保兼容性
- 移除 OpenAI 路由中硬编码的 family: 4 限制
- 统一 8 个服务文件中的代理创建逻辑,避免重复维护
- 支持 OAuth 和 token 交换过程中的代理使用
- 新增配置项:PROXY_USE_IPV4(默认 true)
- 向后兼容:现有配置无需手动更新

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-20 22:36:34 +08:00
mouyong
5af8913954 refactor(backend): 统一账户平台标识字段
WHAT: 统一 Claude 账户的平台标识,从 claude-oauth 改为 claude
WHY: 简化平台标识命名规范,提高前后端数据一致性,为多平台支持奠定基础
HOW: 在账户创建和查询接口中添加 platform 字段支持;更新 claudeAccountService 默认平台标识;保持向后兼容性,旧数据自动使用默认值
2025-08-20 21:40:24 +08:00
shaw
3bcdb511fe feat: 实现多服务账户缓存优化系统
- 添加通用LRU缓存工具类,支持过期时间和内存限制
- 实现缓存监控系统,提供统计和健康检查接口
- 为所有账户服务(Claude、Gemini、OpenAI、Bedrock、Claude Console)添加缓存层
- 优化账户选择性能,减少Redis查询频率
- 添加缓存统计监控端点 /admin/cache/stats

性能提升:
- 账户列表查询从O(n)优化到O(1)
- 减少90%以上的Redis查询
- 响应时间降低50ms以上

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-17 15:38:49 +08:00
shaw
043e3768ab fix: 修复每次请求都要重新生成秘钥的问题 2025-08-16 23:49:19 +08:00
shaw
812e98355f feat: 实现 OpenAI token 自动刷新功能并优化账户管理界面
主要更改:
1. OpenAI Token 自动刷新
   - 实现 refreshAccessToken 函数,支持 OAuth 2.0 refresh_token grant type
   - 使用 Codex CLI 官方 CLIENT_ID (app_EMoamEEZ73f0CkXaXp7hrann)
   - 支持 SOCKS5 和 HTTP/HTTPS 代理
   - 自动更新 access token、id token 和 refresh token

2. 账户管理界面优化
   - 移除手动刷新 token 按钮(桌面端和移动端)
   - 保留后端自动刷新机制
   - 优化代码结构,删除不再需要的函数和变量

3. 测试和文档
   - 添加 test-openai-refresh.js 测试脚本
   - 创建详细的实现文档

技术细节:
- Token 端点: https://auth.openai.com/oauth/token
- 默认有效期: 1小时
- 加密存储: AES-256-CBC

所有平台现在都支持自动 token 刷新:
 Claude - OAuth 自动刷新
 Gemini - Google OAuth2 自动刷新
 OpenAI - OAuth 自动刷新(新实现)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-15 16:56:44 +08:00
Wesley Liddick
925da6fb22 Merge pull request #249 from iRubbish/feat/webhook-manual-disable-notification
feat: 增强 webhook 通知功能,支持手动禁用账号通知
2025-08-14 21:47:01 +08:00
iRubbish
c9b0c3eb82 feat: 增强 webhook 通知功能,支持手动禁用账号通知
- 添加手动禁用账号时的 webhook 通知功能
- 支持所有账号类型:Claude OAuth、Claude Console、Gemini
- 新增错误代码:MANUALLY_DISABLED 系列
- 更新 README.md 文档,添加完整的 webhook 配置说明
- 包含企业微信配置示例和测试方法

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-14 18:28:48 +08:00
KevinLiao
b0622bdcbd Merge branch 'main' of https://github.com/Wei-Shaw/claude-relay-service 2025-08-14 16:44:20 +08:00
KevinLiao
0e5f4e03c1 feat: 新增Claude账号订阅类型设置
1. OAuth可自动判断订阅类型,Setup Token请自行选择。无论那种类型都可以自己改
2. 优化调度,Pro账号不再接受opus模型请求的调度
2025-08-14 16:43:58 +08:00
weidian
e01e539108 feat: 添加账号异常状态 Webhook 通知功能
## 功能概述
- 新增账号禁用/异常状态的 Webhook 实时通知机制
- 支持 Claude OAuth、Claude Console、Gemini 三种平台的账号监控
- 提供完整的 Webhook 管理 API 和配置选项

## 主要变更

### 新增文件
- `src/utils/webhookNotifier.js`: Webhook 通知核心服务
- `src/routes/webhook.js`: Webhook 管理 API 路由

### 功能集成
- Claude OAuth 账号:unauthorized 状态 + token 刷新错误通知
- Claude Console 账号:blocked 状态通知
- Gemini 账号:token 刷新错误通知

### 配置支持
- 新增环境变量:WEBHOOK_ENABLED, WEBHOOK_URLS, WEBHOOK_TIMEOUT, WEBHOOK_RETRIES
- 支持多个 Webhook URL 并发通知
- 自动重试机制(指数退避)+ 超时保护

### 管理端点
- POST /admin/webhook/test: 测试连通性
- POST /admin/webhook/test-notification: 发送测试通知
- GET /admin/webhook/config: 查看配置信息

## 通知格式
```json
{
  "type": "account_anomaly",
  "data": {
    "accountId": "uuid",
    "accountName": "账号名称",
    "platform": "claude-oauth|claude-console|gemini",
    "status": "unauthorized|blocked|error",
    "errorCode": "CLAUDE_OAUTH_UNAUTHORIZED",
    "reason": "具体异常原因",
    "timestamp": "2025-01-13T10:30:00.000Z"
  }
}
```

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-13 17:52:46 +08:00
shaw
31bdb4aa8c feat: add comprehensive 401 error handling and account status management
- Add 401 error detection and automatic account suspension after 3 consecutive failures
- Implement account status reset functionality for clearing all error states
- Enhance admin interface with status reset controls and improved status display
- Upgrade service management script with backup protection and retry mechanisms
- Add mandatory code formatting requirements using Prettier
- Improve account selector with detailed status information and color coding

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-08 00:35:26 +08:00
千羽
8a74bf5afe refactor: standardize code formatting and linting configuration
- Replace .eslintrc.js with .eslintrc.cjs for better ES module compatibility
- Add .prettierrc configuration for consistent code formatting
- Update package.json with new lint and format scripts
- Add nodemon.json for development hot reloading configuration
- Standardize code formatting across all JavaScript and Vue files
- Update web admin SPA with improved linting rules and formatting
- Add prettier configuration to web admin SPA

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-07 18:19:31 +09:00
shaw
a5c7eeaf84 fix: 修复专属账号下拉框,仅显示dedicated类型账号
- 修改CreateApiKeyModal和EditApiKeyModal的过滤逻辑
- 专属账号下拉框只显示accountType='dedicated'的账号
- 移除accountType='group'的账号,这些账号通过分组调度
- 更新标签文字为'专属账号'以更准确描述
2025-08-03 22:34:44 +08:00
shaw
9c9afe1528 feat: 实现账户分组管理功能和优化响应式设计
主要更新:
- 实现账户分组管理功能,支持创建、编辑、删除分组
- 支持将账户添加到分组进行统一调度
- 优化 API Keys 页面响应式设计,解决操作栏被隐藏的问题
- 优化账户管理页面布局,合并平台/类型列,改进操作按钮布局
- 修复代理信息显示溢出问题
- 改进表格列宽分配,充分利用屏幕空间

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-03 22:34:43 +08:00
shaw
8e89311dac feat: 使用API响应头中的准确时间戳修正会话窗口和限流时间
- 从429响应中提取 anthropic-ratelimit-unified-reset 响应头
- 使用准确的重置时间戳设置限流结束时间和会话窗口
- 会话窗口开始时间 = 重置时间戳 - 5小时
- 兼容旧逻辑:无响应头时使用预估的会话窗口时间

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-31 16:29:44 +08:00
KevinLiao
b7f4c2a560 Merge branch 'main' of https://github.com/Wei-Shaw/claude-relay-service 2025-07-31 13:37:23 +08:00
KevinLiao
0e84a979e9 fix: 继续修正会话窗口的计算问题,这回应该正确了 2025-07-31 13:36:24 +08:00
shaw
7ebcdbe72d fix: 优化限流机制,使限流时间与Claude会话窗口保持一致
- 限流结束时间现在基于5小时会话窗口而非硬编码1小时
- 新增 rateLimitEndAt 字段追踪限流结束时间
- 自动解除限流基于会话窗口结束时间
- 保持向后兼容,支持旧数据格式

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-31 13:00:19 +08:00
KevinLiao
d93ce8713d fix: 修复session窗口计算问题 2025-07-31 09:15:33 +08:00
KevinLiao
b86adcd6d2 fix: 1.修复ClaudeConsole账号设置为专属绑定的功能
2. 修复Claude 官方账号会话窗口计算错误的问题
2025-07-30 20:20:12 +08:00
KevinLiao
34dca961ef fix: 1. 修复调度优先级以及手动禁止调度逻辑的问题
2. 优化列表优先级显示
2025-07-30 09:30:11 +08:00
KevinLiao
fddd5ee3e9 feat: 新增标准Claude Console API账号支持 2025-07-30 08:19:44 +08:00
KevinLiao
718733b78b feat: 增加账号session窗口管理与显示。后续可以据此优化账号轮转逻辑。
scripts目录有相关管理脚本,请自行探索
2025-07-28 15:51:38 +08:00
leslie
4325de90e1 解决轮询问题 2025-07-25 20:27:20 +08:00
shaw
38c1fc4785 feat: 添加多模型支持和OpenAI兼容接口
- 新增 Gemini 模型支持和账户管理功能
- 实现 OpenAI 格式到 Claude/Gemini 的请求转换
- 添加自动 token 刷新服务,支持提前刷新策略
- 增强 Web 管理界面,支持 Gemini 账户管理
- 优化 token 显示,添加掩码功能
- 完善日志记录和错误处理

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-22 10:17:39 +08:00
shaw
f5968e518e feat: 改进管理界面弹窗体验和滚动条美化
- 修复API Key创建/编辑弹窗和账户信息修改弹窗在低高度屏幕上被遮挡的问题
- 为所有弹窗添加自适应高度支持,最大高度限制为90vh
- 美化Claude账户弹窗的滚动条样式,使用紫蓝渐变色与主题保持一致
- 添加响应式适配,移动设备上弹窗高度调整为85vh
- 优化滚动条交互体验,支持悬停和激活状态

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-18 23:49:55 +08:00
shaw
ee9bd4aea4 feat: 实现Claude账户专属绑定功能
- 添加账户类型(dedicated/shared)支持
- API Key可绑定专属账户,优先使用绑定账户
- 未绑定的API Key继续使用共享池和粘性会话
- 修复专属账户下拉框显示问题(isActive类型不匹配)
- 修复getBoundAccountName方法未定义错误
- 添加删除账户前的API Key绑定检查
- 完全保留原有粘性会话机制

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-17 08:50:12 +08:00
shaw
48c09b1286 feat: 优化SSL证书获取推荐和token刷新机制
- 将README中的certbot推荐改为acme.sh,更轻量且功能更强
- 中英文文档同步更新SSL证书获取方式
- 调整token刷新提前时间从10秒改为60秒,提供更充足的缓冲时间

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-16 16:15:17 +08:00
shaw
fbf942a5fd feat: 支持手动添加 Claude 账户 Access Token
- 添加 OAuth 和手动输入两种账户添加方式
- 支持直接输入 Access Token 和 Refresh Token
- 新增账户编辑功能,可更新 Token 和代理设置
- 优化 Token 刷新失败时的回退机制
- 改进用户体验,支持手动维护长期有效的 Token

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-15 19:28:14 +08:00
shaw
b2b8d8c719 feat: 添加智能sticky会话保持功能
- 新增 sessionHelper.js 实现会话哈希生成,基于Anthropic的prompt caching机制
- 扩展 claudeAccountService.selectAvailableAccount 支持会话绑定
- 更新 claudeRelayService 集成会话保持功能
- 添加 Redis 会话映射存储,支持1小时过期
- 支持故障转移:绑定账户不可用时自动重新选择
- 三级fallback策略:cacheable内容 → system内容 → 第一条消息
- 完全向后兼容,自动启用无需配置

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-15 18:15:53 +08:00
shaw
b1ca3f307e first commit 2025-07-14 18:14:13 +08:00