feat: 添加统一Claude Code User-Agent支持及缓存管理功能

### **核心功能**
*   **自动更新**:自动获取并使用最新的 “Claude Code” 客户端版本号。
*   **智能缓存**:获取到的版本会缓存25小时,然后自动刷新。
*   **独立开关**:每个账户都可以单独设置是否启用此功能。

### **前端界面**
*   **新增开关**:账户设置里增加了“使用统一版本”的选项。
*   **信息显示**:能直接看到当前正在使用的版本号。
*   **手动刷新**:提供“清除缓存”按钮,可手动强制更新。

### **后端技术**
*   **核心方法**:开发了新的后台功能,用于捕获、比较和管理版本号。
*   **管理接口**:为管理员提供了新的API (`/admin/claude-code-version`),方便查询和刷新。
This commit is contained in:
sczheng189
2025-09-03 20:14:58 +08:00
parent 9c7ec8758d
commit 39c49fe2bb
4 changed files with 341 additions and 11 deletions

View File

@@ -59,7 +59,8 @@ class ClaudeAccountService {
priority = 50, // 调度优先级 (1-100数字越小优先级越高)
schedulable = true, // 是否可被调度
subscriptionInfo = null, // 手动设置的订阅信息
autoStopOnWarning = false // 5小时使用量接近限制时自动停止调度
autoStopOnWarning = false, // 5小时使用量接近限制时自动停止调度
useUnifiedUserAgent = false // 是否使用统一Claude Code版本的User-Agent
} = options
const accountId = uuidv4()
@@ -91,6 +92,7 @@ class ClaudeAccountService {
errorMessage: '',
schedulable: schedulable.toString(), // 是否可被调度
autoStopOnWarning: autoStopOnWarning.toString(), // 5小时使用量接近限制时自动停止调度
useUnifiedUserAgent: useUnifiedUserAgent.toString(), // 是否使用统一Claude Code版本的User-Agent
// 优先使用手动设置的订阅信息否则使用OAuth数据中的否则默认为空
subscriptionInfo: subscriptionInfo
? JSON.stringify(subscriptionInfo)
@@ -122,6 +124,7 @@ class ClaudeAccountService {
errorMessage: '',
schedulable: schedulable.toString(), // 是否可被调度
autoStopOnWarning: autoStopOnWarning.toString(), // 5小时使用量接近限制时自动停止调度
useUnifiedUserAgent: useUnifiedUserAgent.toString(), // 是否使用统一Claude Code版本的User-Agent
// 手动设置的订阅信息
subscriptionInfo: subscriptionInfo ? JSON.stringify(subscriptionInfo) : ''
}
@@ -487,6 +490,8 @@ class ClaudeAccountService {
schedulable: account.schedulable !== 'false', // 默认为true兼容历史数据
// 添加自动停止调度设置
autoStopOnWarning: account.autoStopOnWarning === 'true', // 默认为false
// 添加统一User-Agent设置
useUnifiedUserAgent: account.useUnifiedUserAgent === 'true', // 默认为false
// 添加停止原因
stoppedReason: account.stoppedReason || null
}
@@ -522,7 +527,8 @@ class ClaudeAccountService {
'priority',
'schedulable',
'subscriptionInfo',
'autoStopOnWarning'
'autoStopOnWarning',
'useUnifiedUserAgent'
]
const updatedData = { ...accountData }