feat(proxy-pools): auto-rotate strategy for no-auth providers (#2409)

Add round-robin/random proxy pool rotation for no-auth free providers
(e.g. OpenCode Free) to distribute load across all active pools and
avoid per-IP rate limits. Rotation strategy is selectable per provider
in NoAuthProxyCard and persisted to settings.providerStrategies.
This commit is contained in:
Fadjrir Herlambang
2026-07-10 16:05:07 +07:00
committed by decolua
parent f1f9d27061
commit e1f3399b73
3 changed files with 93 additions and 11 deletions
+27
View File
@@ -6,6 +6,33 @@ function normalizeString(value) {
return String(value).trim();
}
// ─── Proxy pool rotation state (in-memory) ─────────────────────────
const rotateState = new Map(); // providerId → { index }
/**
* Pick one proxy pool ID from a list based on strategy.
* round-robin: cycle sequentially (in-memory, resets on restart)
* random: uniform random pick
* none/single: return first entry
*/
export function pickProxyPoolId(poolIds, strategy, providerId) {
if (!poolIds || poolIds.length === 0) return null;
if (poolIds.length === 1) return poolIds[0];
if (strategy === "round-robin") {
const state = rotateState.get(providerId) || { index: -1 };
state.index = (state.index + 1) % poolIds.length;
rotateState.set(providerId, state);
return poolIds[state.index];
}
if (strategy === "random") {
return poolIds[Math.floor(Math.random() * poolIds.length)];
}
return poolIds[0]; // "none" or unknown
}
/**
* Normalize legacy proxy configuration.
*/