mirror of
https://github.com/tiennm99/ccs.git
synced 2026-09-02 12:19:35 +00:00
feat(cliproxy): integrate pre-flight quota check
- skip paused accounts during rotation - check quota before request execution Refs #282
This commit is contained in:
@@ -58,7 +58,7 @@ import {
|
|||||||
import { detectRunningProxy, waitForProxyHealthy, reclaimOrphanedProxy } from './proxy-detector';
|
import { detectRunningProxy, waitForProxyHealthy, reclaimOrphanedProxy } from './proxy-detector';
|
||||||
import { withStartupLock } from './startup-lock';
|
import { withStartupLock } from './startup-lock';
|
||||||
import { loadOrCreateUnifiedConfig } from '../config/unified-config-loader';
|
import { loadOrCreateUnifiedConfig } from '../config/unified-config-loader';
|
||||||
import { fetchAccountQuota, findAvailableAccount } from './quota-fetcher';
|
import { preflightCheck } from './quota-manager';
|
||||||
|
|
||||||
/** Default executor configuration */
|
/** Default executor configuration */
|
||||||
const DEFAULT_CONFIG: ExecutorConfig = {
|
const DEFAULT_CONFIG: ExecutorConfig = {
|
||||||
@@ -465,35 +465,20 @@ export async function execClaudeWithCLIProxy(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 3b. Preflight quota check - auto-switch to account with quota before launch
|
// 3b. Preflight quota check - auto-switch to account with quota before launch
|
||||||
// Only for agy (Antigravity) which has quota tracking
|
// Uses quota-manager for caching, tier priority, and cooldown support
|
||||||
if (provider === 'agy') {
|
if (provider === 'agy') {
|
||||||
const defaultAccount = getDefaultAccount(provider);
|
const preflight = await preflightCheck(provider);
|
||||||
if (defaultAccount) {
|
|
||||||
log(`Checking quota for ${defaultAccount.email || defaultAccount.id}`);
|
|
||||||
const quota = await fetchAccountQuota(provider, defaultAccount.id);
|
|
||||||
|
|
||||||
// Check if current account is exhausted (no model with >5% quota)
|
if (!preflight.proceed) {
|
||||||
const hasQuota = quota.success && quota.models.some((m) => m.percentage > 5);
|
console.error(fail(`Cannot start session: ${preflight.reason}`));
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
if (!hasQuota && quota.success) {
|
if (preflight.switchedFrom) {
|
||||||
// Current account exhausted, try to find alternative
|
console.log(info(`Auto-switched to ${preflight.accountId}`));
|
||||||
log('Current account quota exhausted, searching for alternatives...');
|
console.log(` Reason: ${preflight.reason}`);
|
||||||
const alternative = await findAvailableAccount(provider, defaultAccount.id);
|
if (preflight.quotaPercent !== undefined) {
|
||||||
|
console.log(` New account quota: ${preflight.quotaPercent.toFixed(1)}%`);
|
||||||
if (alternative) {
|
|
||||||
// Auto-switch to account with remaining quota
|
|
||||||
setDefaultAccount(provider, alternative.account.id);
|
|
||||||
touchAccount(provider, alternative.account.id);
|
|
||||||
console.log(
|
|
||||||
info(
|
|
||||||
`Auto-switched to ${alternative.account.email || alternative.account.id} (current account quota exhausted)`
|
|
||||||
)
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
// No alternatives available - warn but continue
|
|
||||||
console.log(warn('All accounts appear quota-exhausted'));
|
|
||||||
console.log(` Run: ccs cliproxy doctor`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user