Commit Graph

734 Commits

Author SHA1 Message Date
shaw
2f0839c7da feat: 合并 PR #578 并接入统一定价服务 2025-10-16 14:12:25 +08:00
shaw
d606cb2e38 fix: 优化模型价格文件更新策略 2025-10-16 10:46:45 +08:00
liangjie.wanglj
b9d2e855f3 claude console类型中增加claude-haiku-4-5-20251001、GLM、Kimi、Qwen模型支持;增加计费消息通知;Claude console 及 ccr模型匹配大小写不敏感 2025-10-16 09:53:42 +08:00
shaw
472fb535cf Merge branch 'bottotl/main' into dev 2025-10-15 19:27:13 +08:00
shaw
77124aa501 fix: droid去掉count_tokens端点 2025-10-15 15:50:04 +08:00
shaw
c2669da4b3 fix: 更新factory user-agent 2025-10-15 15:26:58 +08:00
shaw
d72897f835 fix: droid转发增加runtimeAddon调试插件 2025-10-15 15:17:20 +08:00
jft0m
6bb74376ca fix: add /openai/v1/chat/completions route support
- Register unifiedRoutes under /openai prefix to enable /openai/v1/chat/completions
- Reuse existing intelligent routing logic from unified.js (no code duplication)
- Keep existing Codex API routes (/openai/responses, /openai/v1/responses) unchanged

Benefits:
- Fixes 404 error for /openai/v1/chat/completions endpoint
- Provides consistent API experience across /api and /openai prefixes
- Automatically routes to correct backend (Claude/OpenAI/Gemini) based on model

Tested:
-  /openai/v1/chat/completions now returns authentication error (route works)
-  /api/v1/chat/completions continues to work
-  Existing Codex routes remain functional

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-14 16:17:12 +00:00
jft0m
b886012f97 Merge branch 'Wei-Shaw:main' into main 2025-10-14 22:39:30 +08:00
jft0m
344599f318 refactor: extract intelligent routing to unified.js
- Created new src/routes/unified.js (225 lines)
  - detectBackendFromModel(): Detects backend from model name
  - routeToBackend(): Routes to Claude/OpenAI/Gemini with permission checks
  - POST /v1/chat/completions: OpenAI-compatible endpoint with intelligent routing
  - POST /v1/completions: Legacy completions endpoint with intelligent routing

- Updated src/routes/api.js (reduced from 1185 to 968 lines)
  - Removed ~217 lines of routing logic
  - Kept Claude-specific endpoints (/api/v1/messages)
  - Maintained all other Claude API functionality

- Updated src/app.js
  - Added unifiedRoutes registration at /api prefix

Benefits:
- Single responsibility: api.js focuses on Claude API routes
- Better organization: routing logic isolated in unified.js
- Easier maintenance: changes to routing won't affect Claude code
- File size reduction: api.js reduced by 18%

Tested:
-  Claude model routing via /v1/chat/completions
-  OpenAI model routing (correct backend detection)
-  Gemini model routing (correct backend detection)
-  Legacy /v1/completions endpoint
-  All tests pass, no regressions

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-14 14:30:23 +00:00
jft0m
e540ec3a52 feat: add intelligent backend routing and model service
- Add modelService for centralized model management
  - Support dynamic model list from config file (data/supported_models.json)
  - Include 2025 latest models: GPT-4.1, o3, o4-mini, Gemini 2.5, etc.
  - File watcher for hot-reload configuration changes

- Improve model detection logic in api.js
  - Priority: modelService lookup → prefix matching fallback
  - Smart backend routing based on model provider

- Add intelligent routing endpoints
  - /v1/chat/completions: unified OpenAI-compatible endpoint
  - /v1/completions: legacy format support
  - Auto-route to Claude/OpenAI/Gemini based on requested model

- Add Xcode system prompt support in openaiToClaude
  - Detect and preserve Xcode-specific system messages

- Export handler functions for reuse
  - openaiClaudeRoutes: export handleChatCompletion
  - openaiRoutes: export handleResponses

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-14 14:12:44 +00:00
shaw
62aea5a4a8 fix: 修复tokenExpiresAt混淆问题 2025-10-14 19:19:33 +08:00
mrlitong
aaa2bda407 fix: 修复账户过期时间字段映射问题
## 问题描述
移除 formatSubscriptionExpiry 函数后,API返回的 expiresAt 字段变成了OAuth token过期时间(通常1小时)
而不是订阅过期时间,导致前端显示错误的过期时间,并可能将短期token过期时间错误保存为订阅过期时间。

## 修复方案
1. 添加 formatAccountExpiry 函数,正确映射字段:
   - expiresAt: 映射为 subscriptionExpiresAt(订阅过期时间)供前端使用
   - tokenExpiresAt: 保留OAuth token过期时间供内部使用

2. 在所有账户端点应用格式化:
   - 所有账户类型的GET端点(Claude, Claude Console, CCR, Bedrock, Gemini, OpenAI等)
   - 所有账户类型的POST创建端点
   - 错误处理分支也正确格式化

## 影响范围
- 修复了9种账户类型的所有相关端点
- 共应用了28处格式化调用
- 确保前端获取正确的订阅过期时间,而非token过期时间

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-14 09:26:56 +00:00
mrlitong
1f61478fbc refactor: 优化账户过期检查逻辑和代码一致性
## 主要改进

### 1. 添加缺失的过期检查方法
- 在 `claudeConsoleAccountService` 中添加 `isSubscriptionExpired()` 方法
- 在 `ccrAccountService` 中添加 `isSubscriptionExpired()` 方法
- 与其他 7 个账户服务保持一致的实现方式

### 2. 统一过期检查逻辑
- 重构 `unifiedClaudeScheduler` 中的 5 处手动日期检查代码
- 统一调用服务层的 `isSubscriptionExpired()` 方法
- 消除重复代码,提升可维护性

### 3. 统一字段映射顺序
- 调整 Claude 账户更新端点的 `mapExpiryField()` 调用时机
- 与其他账户类型保持一致的处理顺序
- 提升代码可读性和一致性

## 技术细节

**修改文件**:
- `src/services/claudeConsoleAccountService.js`: 添加 `isSubscriptionExpired()`
- `src/services/ccrAccountService.js`: 添加 `isSubscriptionExpired()`
- `src/services/unifiedClaudeScheduler.js`: 5 处调用统一为服务方法
- `src/routes/admin.js`: 统一字段映射顺序

**改进效果**:
-  代码一致性提升:所有账户服务统一实现
-  可维护性提升:过期逻辑集中管理
-  减少重复代码:消除 4 处重复实现

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-14 08:35:13 +00:00
mrlitong
cd5df4f76b Merge remote-tracking branch 'upstream/main' into feature/account-subscription-expiry-check 2025-10-14 08:04:12 +00:00
mrlitong
cbc3a83f11 refactor: 统一账户过期时间字段映射和检查逻辑
主要改进:
1. 创建 mapExpiryField() 工具函数统一处理前后端字段映射(expiresAt -> subscriptionExpiresAt)
2. 统一 subscriptionExpiresAt 初始值为 null(替代空字符串)
3. 规范过期检查方法名为 isSubscriptionExpired(),返回 true 表示已过期
4. 优化过期检查条件判断,只检查 null 而非空字符串
5. 补充 OpenAI-Responses 和调度器中缺失的过期检查逻辑
6. 添加代码评审文档记录未修复问题

影响范围:
- 所有 9 种账户服务的过期字段处理
- admin.js 中所有账户更新路由
- 统一调度器的过期账户过滤逻辑

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-14 08:04:05 +00:00
Wesley Liddick
4b3ffa4136 Merge pull request #561 from AAEE86/new
feat: 添加Droid账户API Key管理功能
2025-10-14 14:34:07 +08:00
shaw
d6a9beff2f feat: 适配新版本gemini 2025-10-14 11:24:27 +08:00
litongtongxue
1e7465e533 feat: 为所有账户服务添加订阅过期检查功能
完成账户订阅到期时间功能的核心调度逻辑实现。

## 实现范围

 已添加订阅过期检查的服务(5个):
- Gemini 服务:添加 isSubscriptionExpired() 函数及调度过滤
- OpenAI 服务:添加 isSubscriptionExpired() 函数及调度过滤
- Droid 服务:添加 _isSubscriptionExpired() 方法及调度过滤
- Bedrock 服务:添加 _isSubscriptionExpired() 方法及调度过滤
- Azure OpenAI 服务:添加 isSubscriptionExpired() 函数及调度过滤

## 核心功能

- 账户调度时自动检查 subscriptionExpiresAt 字段
- 过期账户将不再被系统调度使用
- 未设置过期时间的账户视为永不过期(向后兼容)
- 使用 <= 比较判断过期(精确到过期时刻)
- 跳过过期账户时记录 debug 日志便于排查

## 技术实现

- 统一的实现模式:过期检查函数 + 账户选择逻辑集成
- 不影响现有功能,完全向后兼容
- 业务字段 subscriptionExpiresAt 与技术字段 expiresAt(OAuth token过期)独立管理

## 相关文档

参考 account_expire_bugfix.md 了解问题背景和实现细节

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-14 02:42:03 +00:00
AAEE86
8d84e2fa6e refactor: 优化API Key状态更新和日志记录格式 2025-10-14 09:33:17 +08:00
AAEE86
ea3ad2157f fix: 优化API Key错误状态码的显示方式 2025-10-14 00:53:19 +08:00
AAEE86
1f9afc788b feat: 添加Droid账户API Key管理功能
(cherry picked from commit 0cf3ca6c7eafcf28a2da7e8bfd6814b4883bb752)
2025-10-13 18:24:49 +08:00
Wesley Liddick
222b2862cc Merge pull request #560 from looksgood/main
优化Claude OAuth 账户的模型检查
2025-10-13 11:41:39 +08:00
liangjie.wanglj
8093dfb11c 优化Claude OAuth 账户的模型检查 2025-10-13 10:55:19 +08:00
shaw
1145fb7b7d fix: 修复apikey的并发控制问题 2025-10-13 09:48:13 +08:00
shaw
508d9aad1b fix: 继续修复PR-541引发的系列bug 2025-10-13 08:41:24 +08:00
shaw
a67c34bee1 fix: 修复claude SSE捕获usage问题 2025-10-12 23:05:48 +08:00
shaw
6f6c274877 fix: 继续修复PR-541遗留的系列bug 2025-10-12 22:13:38 +08:00
shaw
5611e86154 fix: 修复console计费问题 2025-10-12 20:56:27 +08:00
shaw
22928aeae3 fix: 优化droid默认启用推理的问题 2025-10-12 20:16:13 +08:00
shaw
33e69ac6e2 fix: 修复droid claude的temperature参数问题 2025-10-12 19:14:25 +08:00
shaw
45dab2af40 fix: 修复temperature参数传递问题 2025-10-12 18:35:28 +08:00
shaw
40b7c68694 fix: 修复账号过期时间的一系列bug 2025-10-12 18:35:05 +08:00
shaw
0d7a200505 Merge PR #512: 添加 OpenAI chat/completions 兼容支持
## 主要功能
-  使用策略模式处理不同后端(Claude/OpenAI/Gemini)
-  添加 OpenAI chat/completions 兼容支持
-  修复代码缩进符合 ESLint 规范

## 核心变更

### 1. 后端检测机制
添加 `detectBackendFromModel()` 函数:
- 根据模型名称前缀检测后端(claude-/gpt-/gemini-)
- 默认使用 Claude 后端

### 2. 扩展模型列表
/v1/models 端点现在返回:
- Claude 模型:Sonnet 4.5, Opus 4.1, Sonnet 4, Haiku等
- OpenAI 模型:gpt-4o, gpt-4o-mini, gpt-4-turbo等
- Gemini 模型:gemini-1.5-pro, gemini-1.5-flash等

### 3. OpenAI 兼容支持
- 添加 `validateChatCompletionRequest()` 验证函数
- 支持 OpenAI chat/completions 请求格式
- 实现流式和非流式响应处理

### 4. 代码规范
- 修复 ESLint 缩进问题
- 统一代码格式

## 技术细节
- 修改文件:src/routes/api.js, src/services/openaiToClaude.js 等
- 版本更新:1.1.168 → 1.1.169
- 保留了之前添加的账户过期检查逻辑(来自PR #541)

作者: bottotl
PR: https://github.com/Wei-Shaw/claude-relay-service/pull/512
2025-10-12 13:49:20 +08:00
shaw
a84f344df6 Merge PR #541: 添加账户订阅到期时间管理功能 + 修复核心过期检查逻辑
## 原PR功能
-  后端添加subscriptionExpiresAt字段支持
-  前端提供到期时间设置界面(快捷选项 + 自定义日期)
-  账户列表显示到期状态(已过期🔴/即将过期🟠/永不过期)
-  新增AccountExpiryEditModal.vue编辑弹窗组件
-  支持创建和更新账户时设置到期时间
-  完整支持暗黑模式

## 🔧 关键修复(本次提交)
原PR缺少核心过期检查逻辑,过期账户仍会被调度使用。本次合并时添加了:

1. **新增isAccountNotExpired()方法**:
   - 检查账户subscriptionExpiresAt字段
   - 未设置过期时间视为永不过期
   - 添加debug日志记录过期账户

2. **在selectAvailableAccount()中添加过期检查**:
   - 过滤逻辑中集成this.isAccountNotExpired(account)
   - 确保过期账户不被选择

3. **在selectAccountForApiKey()中添加过期检查**:
   - 绑定账户检查中添加过期验证
   - 共享池过滤中添加过期验证

## 🗑️ 清理工作
- 移除了不应提交的account_expire_feature.md评审文档(756行)

## 技术细节
- API层使用expiresAt,存储层使用subscriptionExpiresAt
- 存储格式:ISO 8601 (UTC)
- 空值表示:null表示永不过期
- 时区处理:后端UTC,前端自动转换本地时区

作者: mrlitong (原PR) + Claude Code (修复)
PR: https://github.com/Wei-Shaw/claude-relay-service/pull/541
2025-10-12 13:42:57 +08:00
shaw
df2527a86c Merge PR #548: 修复Claude Console流式响应usage统计不完整问题
- 完善message_delta中usage数据提取逻辑,支持提取input_tokens、cache_read_input_tokens等所有字段
- 添加兜底保护机制,确保流结束时不会丢失未保存的usage数据
- 提升关键日志级别从debug到info,便于问题排查
- 修复流式请求中input_tokens和cache_read_input_tokens为0的统计bug

作者: DokiDoki1103
PR: https://github.com/Wei-Shaw/claude-relay-service/pull/548
2025-10-12 13:30:25 +08:00
shaw
b7cd143b4c fix: 修复temperature参数冲突问题 2025-10-12 13:25:43 +08:00
shaw
a58d67940c fix: 优化并发计数过期清理 2025-10-12 13:14:15 +08:00
jft0m
44c6be129b Merge branch 'Wei-Shaw:main' into main 2025-10-12 09:28:12 +08:00
litongtongxue
c8c337099e Merge upstream/main into feature/account-expiry-management
解决与 upstream/main 的代码冲突:
- 保留账户到期时间 (expiresAt) 功能
- 采用 buildProxyPayload() 函数重构代理配置
- 同步最新的 Droid 平台功能和修复

主要改动:
- AccountForm.vue: 整合到期时间字段和新的 proxy 处理方式
- 合并 upstream 的 Droid 多 API Key 支持等新特性

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-12 00:55:25 +08:00
shaw
0b2610842a feat: droid apikey异常自动移除 2025-10-11 22:39:41 +08:00
shaw
53dee11a10 feat: droid的apikey模式适配多种更新方式 2025-10-11 22:15:38 +08:00
shaw
6dcb8b9449 fix: 修复droid转发流式请求判断 2025-10-11 20:46:05 +08:00
DokiDoki1103
b7fe75cb60 fix: 修复Claude Console流式响应usage统计不完整问题
- 完善message_delta中usage数据提取逻辑,支持提取input_tokens、cache_read_input_tokens等所有字段
- 添加兜底保护机制,确保流结束时不会丢失未保存的usage数据
- 提升关键日志级别从debug到info,便于问题排查
- 修复流式请求中input_tokens和cache_read_input_tokens为0的统计bug

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-11 20:16:44 +08:00
shaw
56fe7be8ec fix: 优化claude code系统提示词判断 2025-10-11 17:34:17 +08:00
shaw
cd9a2025b2 fix: 适配droid调用claude code订阅接口 2025-10-11 14:17:08 +08:00
shaw
9b211b063b feat: 适配claude的400错误码 2025-10-11 13:00:02 +08:00
shaw
6f2307721b fix: 修复droid账号调度接口404问题 2025-10-11 11:34:13 +08:00
shaw
6c2ef2eef3 fix: 修复droid账号更新丢失apikey的问题 2025-10-11 11:23:24 +08:00
shaw
c56bebdbe5 fix: 修复droid分组调度保存无效的问题 2025-10-11 11:07:05 +08:00