Merge branch 'main' of github.com:Wei-Shaw/claude-relay-service

* 'main' of github.com:Wei-Shaw/claude-relay-service:
  fix: 修复 Gemini 统计功能的多个问题
  fix: 修复API Keys页面时间窗口进度条和Token数值显示问题
  chore: 清理 dist 目录
This commit is contained in:
mouyong
2025-08-04 17:42:08 +08:00
2 changed files with 44 additions and 13 deletions

View File

@@ -1423,13 +1423,29 @@ router.get('/gemini-accounts', authenticateAdmin, async (req, res) => {
try {
const accounts = await geminiAccountService.getAllAccounts();
// 为Gemini账户添加空的使用统计(暂时
const accountsWithStats = accounts.map(account => ({
...account,
usage: {
daily: { tokens: 0, requests: 0, allTokens: 0 },
total: { tokens: 0, requests: 0, allTokens: 0 },
averages: { rpm: 0, tpm: 0 }
// 为每个账户添加使用统计信息与Claude账户相同的逻辑
const accountsWithStats = await Promise.all(accounts.map(async (account) => {
try {
const usageStats = await redis.getAccountUsageStats(account.id);
return {
...account,
usage: {
daily: usageStats.daily,
total: usageStats.total,
averages: usageStats.averages
}
};
} catch (statsError) {
logger.warn(`⚠️ Failed to get usage stats for Gemini account ${account.id}:`, statsError.message);
// 如果获取统计失败,返回空统计
return {
...account,
usage: {
daily: { tokens: 0, requests: 0, allTokens: 0 },
total: { tokens: 0, requests: 0, allTokens: 0 },
averages: { rpm: 0, tpm: 0 }
}
};
}
}));

View File

@@ -66,16 +66,31 @@ router.post('/messages', authenticateApiKey, async (req, res) => {
// 生成会话哈希用于粘性会话
const sessionHash = generateSessionHash(req);
// 选择可用的 Gemini 账户
const account = await geminiAccountService.selectAvailableAccount(
apiKeyData.id,
sessionHash
);
// 使用统一调度选择可用的 Gemini 账户(传递请求的模型)
let accountId;
try {
const schedulerResult = await unifiedGeminiScheduler.selectAccountForApiKey(
apiKeyData,
sessionHash,
model // 传递请求的模型进行过滤
);
accountId = schedulerResult.accountId;
} catch (error) {
logger.error('Failed to select Gemini account:', error);
return res.status(503).json({
error: {
message: error.message || 'No available Gemini accounts',
type: 'service_unavailable'
}
});
}
// 获取账户详情
const account = await geminiAccountService.getAccount(accountId);
if (!account) {
return res.status(503).json({
error: {
message: 'No available Gemini accounts',
message: 'Selected account not found',
type: 'service_unavailable'
}
});