mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-22 20:00:47 +00:00
fix: giảm spam 429 từ Claude OAuth usage endpoint
- claudeAutoPing: cache resetAt in-mem, bỏ qua poll usage cho tới gần reset - ProviderLimits: throttle auto-refresh Claude 3 phút, nút bấm tay vẫn refresh ngay - claude.js: 429 ở OAuth usage → cooldown 3 phút, fallback legacy (không ảnh hưởng chat) Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -12,7 +12,7 @@ import { CLAUDE_AUTOPING_CONFIG } from "@/shared/constants/config";
|
||||
const C = CLAUDE_AUTOPING_CONFIG;
|
||||
const PING_URL = "https://api.anthropic.com/v1/messages?beta=true";
|
||||
|
||||
const g = (global.__claudeAutoPing ??= { interval: null, running: false });
|
||||
const g = (global.__claudeAutoPing ??= { interval: null, running: false, resetCache: {} });
|
||||
|
||||
function buildProxyOptions(cfg) {
|
||||
return {
|
||||
@@ -43,6 +43,10 @@ async function sendPing(accessToken, proxyOptions) {
|
||||
}
|
||||
|
||||
async function pingConnection(conn) {
|
||||
// Cached resetAt is stable for the whole 5h window; skip usage poll until near reset
|
||||
const cachedReset = g.resetCache[conn.id];
|
||||
if (cachedReset && Date.now() < new Date(cachedReset).getTime() - C.refreshAheadMs) return;
|
||||
|
||||
const proxyCfg = await resolveConnectionProxyConfig(conn.providerSpecificData);
|
||||
const proxyOptions = buildProxyOptions(proxyCfg);
|
||||
|
||||
@@ -60,6 +64,9 @@ async function pingConnection(conn) {
|
||||
const resetAt = usage?.quotas?.[C.fiveHourKey]?.resetAt;
|
||||
if (!resetAt) return;
|
||||
|
||||
// Cache resetAt to gate future ticks
|
||||
g.resetCache[conn.id] = resetAt;
|
||||
|
||||
const resetMs = new Date(resetAt).getTime();
|
||||
const now = Date.now();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user