Commit Graph

74 Commits

Author SHA1 Message Date
shaw
4913be3b21 Merge remote-tracking branch 'origin/main' into dev 2025-07-28 09:30:33 +08:00
KevinLiao
13eb28a77e Merge branch 'main' of github.com:kevinconan/claude-relay-service 2025-07-28 09:05:16 +08:00
KevinLiao
fcecb75c21 fix: 1.修正用户查询apikey时区问题
2.修正用户apikey查询,当日APIKey没有数据,显示数据不正确的问题
2025-07-28 09:04:04 +08:00
Wesley Liddick
e2f5c32cc0 Merge branch 'main' into main 2025-07-28 09:01:23 +08:00
Edric Li
9193d64d2a feat: 添加 OEM 设置功能并统一 API 统计页面样式
- 添加 OEM 设置管理功能,支持自定义网站名称和图标
- 支持图标文件上传和 Base64 编码存储
- 实现动态更新网站标题和 favicon
- 统一 API 统计页面与管理页面的样式和布局
- 修复文本颜色显示问题,提升可读性
- 优化错误处理和默认值回退机制
- 移除测试文件和冗余代码

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-27 23:20:44 +08:00
KevinLiao
75b4919693 feat: 优化APIKey查询
1. 查询相关接口修改为APIKey的UUID
2. 输入APIKey查询后,自动查询API的UUID并添加浏览器地址参数,后续可以直接复制链接进行查询。同时保证了APIKey的安全性
2025-07-27 23:20:15 +08:00
KevinLiao
bdf125e001 fix: APIKey查询页面数据不正确的情况 2025-07-27 19:51:37 +08:00
KevinLiao
85a8cae5ab feat: 新增用户统计页面,并作为默认路由 2025-07-27 18:12:50 +08:00
KevinLiao
a04dd06be9 feat: 新增ApiKey查询页面 2025-07-27 17:38:12 +08:00
KevinLiao
ac1e367a69 feat: 增加每日费用限制 2025-07-27 14:47:59 +08:00
KevinLiao
375d70ee1f feat: APIKeys 列表,统计周期选项增加今日。 2025-07-27 12:03:22 +08:00
shaw
2a6bb2ab01 feat: 改进 Gemini token 刷新机制和错误处理
- Token 刷新成功后自动将账户状态更新为 active
- 清空之前的错误信息
- 确保账户在成功刷新后可以正常使用

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-26 14:36:28 +08:00
shaw
4789c03ea3 fix: 修复 Gemini token 刷新时的二次解密错误
- refreshAccountToken 中的 account.refreshToken 已经是解密后的值
- 移除多余的 decrypt() 调用,避免二次解密导致的错误

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-26 14:34:45 +08:00
shaw
3d13542fff fix: 修复 Gemini 账户 refreshToken 解密错误
- 修复 updateAccount 中对已解密数据的二次解密问题
- 改进解密函数,使用固定长度的 IV 避免冒号分隔符问题
- 确保 refreshToken 能正确存储和使用

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-26 12:10:03 +08:00
shaw
dd73045223 feat: 改进 Gemini token 刷新机制和错误处理
- 修复 token 刷新时的错误处理逻辑
- 添加详细的错误日志记录
- 新增 test-gemini-refresh.js 测试脚本
- 更新 CLAUDE.md 文档,添加 Gemini token 刷新故障排除指南

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-26 11:41:17 +08:00
Wesley Liddick
383f33fa77 Merge pull request #72 from kevinconan/main
feat: 增加APIKey 客户端限制功能
2025-07-26 11:03:06 +08:00
KevinLiao
b8c7c3e9f5 feat: 增加APIKey 客户端限制功能 2025-07-25 23:36:48 +08:00
leslie
578d3ca34b 重复计次修复 2025-07-25 22:08:30 +08:00
leslie
53e0577e19 添加claude账号维度计算token费用前端修复 2025-07-25 21:48:54 +08:00
leslie
1cf70a627f 添加claude账号维度计算token费用 2025-07-25 21:36:17 +08:00
leslie
5522967792 添加claude账号维度计算token费用 2025-07-25 21:27:17 +08:00
leslie
4325de90e1 解决轮询问题 2025-07-25 20:27:20 +08:00
shaw
7936f1aa21 Merge branch 'dev' 2025-07-25 15:36:07 +08:00
shaw
3eba158387 fix: 修复管理员登录在Redis缓存失效后无法登录的问题
- 在登录时如果Redis中没有管理员凭据,自动从init.json重新加载
- 重新加载时不设置过期时间,避免24小时后再次失效
- 保持init.json作为唯一真实数据源的设计原则

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-25 15:30:50 +08:00
KevinLiao
e8d795713a feat: API页面增加统计时间选择 2025-07-25 10:42:19 +08:00
KevinLiao
f614d54ab5 fix: APIKey列表费用及Token显示不准确的问题,目前显示总数
feat: 增加APIKey过期设置,以及到期续期的能力
2025-07-25 09:53:16 +08:00
shaw
afdfdc8fe7 feat: 支持通过 LOG_LEVEL 环境变量动态设置日志级别
- 允许在不修改配置文件的情况下调整日志级别
- 便于生产环境调试和故障排查
- 环境变量优先级高于配置文件
2025-07-24 14:18:45 +08:00
Wesley Liddick
b67cf05f63 Merge pull request #52 from mouyong/patch-1
修复用户提供的 密钥太短导致无法保存授权的问题
2025-07-23 22:58:58 +08:00
mouyong
9c96f18a7c Update sessionHelper.js 2025-07-23 22:35:41 +08:00
mouyong
33561bcc80 修复用户提供的 密钥太短导致无法保存授权的问题 2025-07-23 22:34:26 +08:00
shaw
3553f5cc1f fix: 修复流式响应的 Parse Error 和缓冲问题
主要修改:
1. 从 compression 中间件中排除 SSE 流式响应,避免压缩导致的缓冲
2. 移除导致 Parse Error 的 res.flushHeaders() 调用
3. 改进流式响应的错误处理,发送 SSE 错误事件而不是破坏流
4. 在写入数据前检查流状态,避免写入已销毁的流
5. 优化响应结束时的处理逻辑,确保缓冲区数据正确处理

这些修改确保了流式请求能够正常显示打字机效果,同时保留了 usage token 收集功能。

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-23 16:13:07 +08:00
shaw
1e372dd365 fix: 修复流式响应缓冲问题,实现真正的实时流传输
- 配置 compression 中间件排除 SSE 流式响应,避免压缩导致的缓冲
- 添加 X-Accel-Buffering: no 响应头,禁用 Nginx 等代理的缓冲
- 使用 res.flushHeaders() 立即发送响应头
- 禁用 Nagle 算法确保数据立即发送
- 在每次写入流数据后调用 flush() 确保实时传输

这些修复确保了流式请求能够正常显示打字机效果,数据从上游 Claude API 接收后能够立即转发给客户端。

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-23 15:56:27 +08:00
shaw
2f4730baba 优化: 替换第三方CDN资源以提升加载速度
- 将所有第三方资源从 bootcdn 迁移到 cdnjs.cloudflare.com
- 移除 SRI 完整性校验以避免哈希值不匹配问题
- 添加 DNS 预取和预连接以加速资源加载
- 调整脚本加载顺序,确保依赖关系正确
- 保持所有库版本号不变 (Vue 3.3.4, Element Plus 2.4.4, Chart.js 4.4.0)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-23 11:15:33 +08:00
shaw
d6675a4d8e feat: 添加 /claude/v1/messages 路由别名并优化非 Claude Code 客户端支持
- 添加 /claude 路由作为 /api 的别名,支持 /claude/v1/messages 端点
- 实现智能判断请求来源,通过 user-agent 和系统提示词识别真实的 Claude Code 请求
- 为非 Claude Code 客户端自动设置系统提示词和必要的 headers
- 优化 headers 更新逻辑,只有真实的 Claude Code 请求才更新缓存
- 确保 /api 和 /claude 路由功能完全一致

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-22 21:07:25 +08:00
shaw
e2cece6162 fix 修复x-request-id问题 2025-07-22 18:36:53 +08:00
shaw
a431778363 fix 修复openai格式流式响应的结束标记问题 2025-07-22 18:00:24 +08:00
shaw
6150ed4258 fix openai兼容格式转发claude固定系统提示词 2025-07-22 16:26:17 +08:00
shaw
dabf3bf7ea feat: 实现 Claude Code headers 动态管理功能
- 创建 claudeCodeHeadersService 管理各账号的 Claude Code headers
- 自动捕获成功请求的 headers 并按账号存储在 Redis
- 智能版本管理,只保留最新版本的 headers
- OpenAI 转发时根据账号动态获取对应的 headers
- 添加管理端点查看和清除各账号的 headers 信息
- 完整支持 Claude Code 必需的 beta headers

解决了 "This credential is only authorized for use with Claude Code" 错误
避免了固定版本号带来的风控问题

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-22 16:03:31 +08:00
shaw
b2ad2a4a61 fix: 修复 OpenAI 兼容路由的 Claude API 认证和 Function Calling 支持
- 添加必需的系统消息 "You are Claude Code, Anthropic's official CLI for Claude."
- 修改 anthropic-beta header 为 OAuth-only 模式 (oauth-2025-04-20)
- 不再传递客户端 headers,使用固定的 4 个必需 headers
- 增强流式响应的 Function Calling 支持,正确处理 tool_use 事件
- 支持自定义 beta header 参数,允许不同路由使用不同的认证模式

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-22 14:38:30 +08:00
shaw
6ceed5c3ee fix 修复openai格式转发失败的问题 2025-07-22 13:55:14 +08:00
shaw
9ad7feb94c fix: 修复 OpenAI 路由中的 req.apiKeyData undefined 错误
- 将所有路由中的 req.apiKeyData 改为 req.apiKey(与中间件一致)
- 在 authenticateApiKey 中间件中添加缺失的字段(permissions, geminiAccountId, usage)
- 修复 openaiClaudeRoutes.js、openaiGeminiRoutes.js 和 geminiRoutes.js 中的引用错误
- 确保 API 权限检查正常工作

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-22 13:08:24 +08:00
shaw
6b0832bc2d fix: 修复 OpenAI 兼容路由中的 router.handle() 错误
- 移除了 openaiClaudeRoutes.js 中错误的 router.handle() 调用
- 提取 handleChatCompletion 函数作为共享处理逻辑
- 修复了 /v1/completions 端点的实现
- 确保 /openai/claude 和 /openai/gemini 路由正常工作

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-22 12:58:11 +08:00
shaw
12d68af421 update default redirectUri 2025-07-22 11:52:07 +08:00
shaw
11318c22b0 feat: 优化 Gemini OAuth 授权流程,使用固定的 localhost 回调地址
- 将 Gemini OAuth 回调地址固定为 http://localhost:45462
- 更新前端提示文字为"复制oauth后的链接"
- 实现自动提取 localhost:45462 链接中的 code 参数功能
- 删除不再需要的 web/auth_gemini 路由
- 添加详细的用户操作说明和错误处理提示
- 支持两种输入方式:完整链接或仅授权码

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-22 11:42:54 +08:00
shaw
ed99043127 fix: 修复 geminiAccountService 配置读取错误并添加 secret scanning 排除规则
- 直接使用硬编码的 Gemini OAuth 凭据,避免配置依赖
- 添加 .github/secret_scanning.yml 排除公开的 OAuth 凭据文件

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-22 10:37:43 +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
4f0d8db757 fix: 修复总Token消耗USD计算重复统计问题
- 将usage-costs的all模式改为只使用monthly数据,避免daily、monthly、hourly重复计算
- 更新正则表达式只匹配monthly格式的key
- 确保总消耗与模型统计表格的USD计算保持一致

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-20 21:36:51 +08:00
shaw
ff554d7c70 fix: 修复总Token消耗USD计算与模型统计不一致的问题
- 修正Redis key匹配模式从 'usage:model:*:*' 到 'usage:model:*:*:*'
- 更新正则表达式以支持hourly统计数据
- 确保所有模型都使用正确的价格计算费用

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-20 21:18:39 +08:00
shaw
088ce266ba feat: 添加API Key时间窗口限流功能并移除累计总量限制
- 新增时间窗口限流功能,支持按分钟设置时间窗口
- 支持在时间窗口内限制请求次数和Token使用量
- 移除原有的累计总量限制,只保留时间窗口限制
- Token统计包含所有4种类型:输入、输出、缓存创建、缓存读取
- 前端UI优化,明确显示限流参数的作用范围
- 限流触发时提供友好的错误提示和重置时间

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-20 15:58:00 +08:00
shaw
4291983c87 chore: remove raw sse chunk logging 2025-07-20 00:19:00 +08:00