diff --git a/public/js/store.js b/public/js/store.js index 04c2f44..f89b826 100644 --- a/public/js/store.js +++ b/public/js/store.js @@ -267,9 +267,10 @@ document.addEventListener('alpine:init', () => { persistentSessions: "Persistent Sessions", persistTokenDesc: "Save OAuth sessions to disk for faster restarts", rateLimiting: "Account Rate Limiting & Timeouts", - defaultCooldown: "Default Cooldown Time", - maxWaitThreshold: "Max Wait Threshold (Sticky)", - maxWaitDesc: "Maximum time to wait for a sticky account to reset before switching.", + defaultCooldown: "Default Cooldown", + defaultCooldownDesc: "Fallback cooldown when API doesn't provide a reset time.", + maxWaitThreshold: "Max Wait Before Error", + maxWaitDesc: "If all accounts are rate-limited longer than this, error immediately instead of waiting.", saveConfigServer: "Save Configuration", serverRestartAlert: "Changes saved to {path}. Restart server to apply some settings.", changePassword: "Change WebUI Password", @@ -544,8 +545,9 @@ document.addEventListener('alpine:init', () => { persistTokenDesc: "将登录会话保存到磁盘以实现快速重启", rateLimiting: "账号限流与超时", defaultCooldown: "默认冷却时间", - maxWaitThreshold: "最大等待阈值 (粘性会话)", - maxWaitDesc: "粘性账号在失败或切换前等待重置的最长时间。", + defaultCooldownDesc: "当 API 未提供重置时间时的备用冷却时间。", + maxWaitThreshold: "最大等待阈值", + maxWaitDesc: "如果所有账号的限流时间超过此阈值,立即返回错误而非等待。", saveConfigServer: "保存配置", serverRestartAlert: "配置已保存至 {path}。部分更改可能需要重启服务器。", changePassword: "修改 WebUI 密码", diff --git a/public/views/settings.html b/public/views/settings.html index f2a02b4..cf2d1a5 100644 --- a/public/views/settings.html +++ b/public/views/settings.html @@ -1052,27 +1052,29 @@ Default Cooldown + x-text="Math.round((serverConfig.defaultCooldownMs || 10000) / 1000) + 's'">
Fallback cooldown when API doesn't provide a reset time.
Maximum time to wait for a sticky account to - reset before switching.
+ x-text="$store.global.t('maxWaitDesc')">If all accounts are rate-limited longer than this, error immediately. diff --git a/src/account-manager/index.js b/src/account-manager/index.js index 8259996..79212ea 100644 --- a/src/account-manager/index.js +++ b/src/account-manager/index.js @@ -191,7 +191,7 @@ export class AccountManager { * @param {string} [modelId] - Optional model ID to mark specific limit */ markRateLimited(email, resetMs = null, modelId = null) { - markLimited(this.#accounts, email, resetMs, this.#settings, modelId); + markLimited(this.#accounts, email, resetMs, modelId); this.saveToDisk(); } diff --git a/src/account-manager/rate-limits.js b/src/account-manager/rate-limits.js index 06b4b08..ffe75e6 100644 --- a/src/account-manager/rate-limits.js +++ b/src/account-manager/rate-limits.js @@ -110,16 +110,25 @@ export function resetAllRateLimits(accounts) { * * @param {Array} accounts - Array of account objects * @param {string} email - Email of the account to mark - * @param {number|null} resetMs - Time in ms until rate limit resets - * @param {Object} settings - Settings object with cooldownDurationMs + * @param {number|null} resetMs - Time in ms until rate limit resets (from API) * @param {string} modelId - Model ID to mark rate limit for * @returns {boolean} True if account was found and marked */ -export function markRateLimited(accounts, email, resetMs = null, settings = {}, modelId) { +export function markRateLimited(accounts, email, resetMs = null, modelId) { const account = accounts.find(a => a.email === email); if (!account) return false; - const cooldownMs = resetMs || settings.cooldownDurationMs || DEFAULT_COOLDOWN_MS; + // Use configured cooldown as the maximum wait time + // If API returns a reset time, cap it at DEFAULT_COOLDOWN_MS + // If API doesn't return a reset time, use DEFAULT_COOLDOWN_MS + let cooldownMs; + if (resetMs && resetMs > 0) { + // API provided a reset time - cap it at configured maximum + cooldownMs = Math.min(resetMs, DEFAULT_COOLDOWN_MS); + } else { + // No reset time from API - use configured default + cooldownMs = DEFAULT_COOLDOWN_MS; + } const resetTime = Date.now() + cooldownMs; if (!account.modelRateLimits) { diff --git a/src/cli/accounts.js b/src/cli/accounts.js index 7cb000e..8bf373a 100644 --- a/src/cli/accounts.js +++ b/src/cli/accounts.js @@ -142,7 +142,6 @@ function saveAccounts(accounts, settings = {}) { modelRateLimits: acc.modelRateLimits || {} })), settings: { - cooldownDurationMs: 60000, maxRetries: 5, ...settings },