feat: 新增Claude账号订阅类型设置

1. OAuth可自动判断订阅类型,Setup Token请自行选择。无论那种类型都可以自己改
2. 优化调度,Pro账号不再接受opus模型请求的调度
This commit is contained in:
KevinLiao
2025-08-14 16:43:58 +08:00
parent 1224ade5a7
commit 0e5f4e03c1
7 changed files with 697 additions and 22 deletions

View File

@@ -6,11 +6,13 @@ const fs = require('fs')
const os = require('os')
// 安全的 JSON 序列化函数,处理循环引用
const safeStringify = (obj, maxDepth = 3) => {
const safeStringify = (obj, maxDepth = 3, fullDepth = false) => {
const seen = new WeakSet()
// 如果是fullDepth模式增加深度限制
const actualMaxDepth = fullDepth ? 10 : maxDepth
const replacer = (key, value, depth = 0) => {
if (depth > maxDepth) {
if (depth > actualMaxDepth) {
return '[Max Depth Reached]'
}
@@ -152,6 +154,21 @@ const securityLogger = winston.createLogger({
silent: false
})
// 🔐 创建专门的认证详细日志记录器(记录完整的认证响应)
const authDetailLogger = winston.createLogger({
level: 'info',
format: winston.format.combine(
winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
winston.format.printf(({ level, message, timestamp, data }) => {
// 使用更深的深度和格式化的JSON输出
const jsonData = data ? JSON.stringify(data, null, 2) : '{}'
return `[${timestamp}] ${level.toUpperCase()}: ${message}\n${jsonData}\n${'='.repeat(80)}`
})
),
transports: [createRotateTransport('claude-relay-auth-detail-%DATE%.log', 'info')],
silent: false
})
// 🌟 增强的 Winston logger
const logger = winston.createLogger({
level: process.env.LOG_LEVEL || config.logging.level,
@@ -327,6 +344,28 @@ logger.healthCheck = () => {
}
}
// 🔐 记录认证详细信息的方法
logger.authDetail = (message, data = {}) => {
try {
// 记录到主日志(简化版)
logger.info(`🔐 ${message}`, {
type: 'auth-detail',
summary: {
hasAccessToken: !!data.access_token,
hasRefreshToken: !!data.refresh_token,
scopes: data.scope || data.scopes,
organization: data.organization?.name,
account: data.account?.email_address
}
})
// 记录到专门的认证详细日志文件(完整数据)
authDetailLogger.info(message, { data })
} catch (error) {
logger.error('Failed to log auth detail:', error)
}
}
// 🎬 启动日志记录系统
logger.start('Logger initialized', {
level: process.env.LOG_LEVEL || config.logging.level,