claude-codex-proxy 1.0.5-beta.45 → 1.0.5-beta.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-codex-proxy",
3
- "version": "1.0.5-beta.45",
3
+ "version": "1.0.5-beta.46",
4
4
  "description": "Multi-account proxy server for OpenAI Codex CLI with Claude API compatibility",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -278,6 +278,25 @@ body::before {
278
278
  opacity: 0.7;
279
279
  }
280
280
 
281
+ .account-availability-button {
282
+ padding: 0.25rem 0.75rem;
283
+ border-radius: 0.25rem;
284
+ background-color: rgba(234, 179, 8, 0.1);
285
+ border-color: rgba(234, 179, 8, 0.3);
286
+ color: #facc15;
287
+ }
288
+ .account-availability-button:not(:disabled):hover { background-color: rgba(234, 179, 8, 0.2); }
289
+ .account-availability-button[data-enabled="false"] {
290
+ background-color: rgba(34, 197, 94, 0.1);
291
+ border-color: rgba(34, 197, 94, 0.3);
292
+ color: var(--color-neon-green);
293
+ }
294
+ .account-availability-button[data-enabled="false"]:not(:disabled):hover { background-color: rgba(34, 197, 94, 0.2); }
295
+ .account-availability-button:focus-visible {
296
+ outline: 2px solid var(--color-neon-cyan);
297
+ outline-offset: 2px;
298
+ }
299
+
281
300
  .input {
282
301
  width: 100%;
283
302
  padding: 0.5rem 0.75rem;
package/public/js/app.js CHANGED
@@ -4,7 +4,7 @@ const adminUrl = (path) => `${adminPath}${path}`;
4
4
  document.addEventListener('alpine:init', () => {
5
5
  Alpine.data('app', () => ({
6
6
  version: '', connectionStatus: 'connecting', activeTab: '', sidebarOpen: window.innerWidth >= 1024,
7
- loading: false, refreshingTokenEmails: [], toast: null, currentTime: '', authRequired: false,
7
+ loading: false, refreshingTokenEmails: [], updatingAccountEmails: [], toast: null, currentTime: '', authRequired: false,
8
8
  authChecked: false, apiKey: localStorage.getItem('codexProxyApiKey') || '', loginApiKey: '', loginError: '',
9
9
  accounts: [], searchQuery: '', stats: { total: 0, active: 0, expired: 0, planType: '-' },
10
10
  accountStrategy: 'sticky', modelMappings: { sonnet: '', opus: '', haiku: '' }, modelMapLoading: false,
@@ -106,6 +106,25 @@ document.addEventListener('alpine:init', () => {
106
106
  async copyToClipboard(text) { try { await navigator.clipboard.writeText(text); this.showToast('Copied to clipboard', 'success'); } catch { this.showToast('Failed to copy', 'error'); } },
107
107
  async importFromCodex() { const { ok, data } = await this.api('/accounts/import', { method: 'POST' }); if (ok && data.success) { this.showAddModal = false; this.refreshAccounts(); } else this.showToast(data?.message || 'Import failed', 'error'); },
108
108
  async switchAccount(email) { const { ok, data } = await this.api('/accounts/switch', { method: 'POST', body: JSON.stringify({ email }) }); if (ok && data.success) this.refreshAccounts(); else this.showToast(data?.message || 'Failed to switch', 'error'); },
109
+ async setAccountEnabled(account, enabled) {
110
+ const email = account.email;
111
+ if (this.updatingAccountEmails.includes(email)) return;
112
+ this.updatingAccountEmails.push(email);
113
+ try {
114
+ const { ok, data } = await this.api(`/accounts/${encodeURIComponent(email)}/enabled`, {
115
+ method: 'PUT',
116
+ body: JSON.stringify({ enabled })
117
+ });
118
+ if (ok && data?.success) {
119
+ await this.refreshAccounts();
120
+ this.showToast(enabled ? 'Account enabled' : 'Account disabled', 'success');
121
+ } else {
122
+ this.showToast(data?.message || 'Failed to update account status', 'error');
123
+ }
124
+ } finally {
125
+ this.updatingAccountEmails = this.updatingAccountEmails.filter(item => item !== email);
126
+ }
127
+ },
109
128
  accountExpirationLabel(account) { if (!account?.accountExpiresAt) return 'Never'; const date = new Date(account.accountExpiresAt); if (Number.isNaN(date.getTime())) return 'Never'; return date.toLocaleString([], { year: '2-digit', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' }); },
110
129
  showAccountExpirationModal(account) { this.expirationTarget = account; const date = account?.accountExpiresAt ? new Date(account.accountExpiresAt) : null; if (date && !Number.isNaN(date.getTime())) { const local = new Date(date.getTime() - date.getTimezoneOffset() * 60000); this.accountExpirationInput = local.toISOString().slice(0, 16); } else this.accountExpirationInput = ''; this.showAccountExpirationModalView = true; },
111
130
  closeAccountExpirationModal() { if (this.accountExpirationSaving) return; this.showAccountExpirationModalView = false; this.expirationTarget = null; this.accountExpirationInput = ''; },
@@ -48,7 +48,7 @@
48
48
  <th class="py-3 text-left text-[10px] font-bold text-gray-500 uppercase tracking-wider w-32">Token</th>
49
49
  <th class="py-3 text-left text-[10px] font-bold text-gray-500 uppercase tracking-wider w-24">Quota</th>
50
50
  <th class="w-52 min-w-[13rem] py-3 text-center text-[10px] font-bold text-gray-500 uppercase tracking-wider">Account Expiry</th>
51
- <th class="py-3 pr-6 text-right text-[10px] font-bold text-gray-500 uppercase tracking-wider w-40">Operations</th>
51
+ <th class="py-3 pr-6 text-right text-[10px] font-bold text-gray-500 uppercase tracking-wider w-56">Operations</th>
52
52
  </tr>
53
53
  </thead>
54
54
  <tbody>
@@ -82,15 +82,23 @@
82
82
  <template x-for="acc in filteredAccounts" :key="acc.email">
83
83
  <tr class="border-b border-space-border/30 last:border-0 hover:bg-white/5 transition-colors group">
84
84
  <td class="py-4 pl-6">
85
- <div class="flex items-center gap-2">
86
- <div class="w-2 h-2 rounded-full flex-shrink-0"
87
- :class="acc.accountExpired ? 'bg-red-500' : acc.isActive ? 'bg-neon-green shadow-[0_0_8px_rgba(34,197,94,0.6)] animate-pulse' : 'bg-gray-500'">
85
+ <template x-if="acc.enabled === false">
86
+ <div class="flex items-center gap-2 text-yellow-400" title="This account is excluded from new requests">
87
+ <div class="w-2 h-2 rounded-full flex-shrink-0 bg-yellow-500"></div>
88
+ <span class="text-xs font-mono font-semibold">DISABLED</span>
88
89
  </div>
89
- <span class="text-xs font-mono font-semibold"
90
- :class="acc.accountExpired ? 'text-red-400' : acc.isActive ? 'text-neon-green' : 'text-gray-500'"
91
- x-text="acc.accountExpired ? 'EXPIRED' : acc.isActive ? 'ACTIVE' : 'IDLE'">
92
- </span>
93
- </div>
90
+ </template>
91
+ <template x-if="acc.enabled !== false">
92
+ <div class="flex items-center gap-2">
93
+ <div class="w-2 h-2 rounded-full flex-shrink-0"
94
+ :class="acc.accountExpired ? 'bg-red-500' : acc.isActive ? 'bg-neon-green shadow-[0_0_8px_rgba(34,197,94,0.6)] animate-pulse' : 'bg-gray-500'">
95
+ </div>
96
+ <span class="text-xs font-mono font-semibold"
97
+ :class="acc.accountExpired ? 'text-red-400' : acc.isActive ? 'text-neon-green' : 'text-gray-500'"
98
+ x-text="acc.accountExpired ? 'EXPIRED' : acc.isActive ? 'ACTIVE' : 'IDLE'">
99
+ </span>
100
+ </div>
101
+ </template>
94
102
  </td>
95
103
  <td class="w-56 max-w-56 py-4 text-center">
96
104
  <span class="inline-block max-w-[13rem] truncate font-mono text-sm text-gray-300 transition-colors group-hover:text-white"
@@ -166,8 +174,17 @@
166
174
  </div>
167
175
  </td>
168
176
  <td class="py-4 pr-6">
169
- <div class="flex justify-end gap-2">
170
- <button x-show="!acc.isActive && !acc.accountExpired"
177
+ <div class="flex flex-wrap justify-end gap-2">
178
+ <button type="button"
179
+ class="btn btn-xs account-availability-button text-[10px] font-bold font-mono uppercase tracking-wider"
180
+ :data-enabled="acc.enabled === false ? 'false' : 'true'"
181
+ :disabled="updatingAccountEmails.includes(acc.email)"
182
+ :aria-label="(acc.enabled === false ? 'Enable account ' : 'Disable account ') + acc.email"
183
+ :title="acc.enabled === false ? 'Allow new requests to use this account' : 'Stop new requests from using this account; in-flight requests continue'"
184
+ @click="setAccountEnabled(acc, acc.enabled === false)"
185
+ x-text="updatingAccountEmails.includes(acc.email) ? 'Saving...' : acc.enabled === false ? 'Enable' : 'Disable'">
186
+ </button>
187
+ <button x-show="acc.enabled !== false && !acc.isActive && !acc.accountExpired"
171
188
  class="cursor-pointer px-3 py-1 text-[10px] font-bold font-mono uppercase tracking-wider rounded bg-neon-purple/10 text-neon-purple hover:bg-neon-purple/20 border border-neon-purple/30 hover:border-neon-purple/50 transition-all"
172
189
  @click="switchAccount(acc.email)">
173
190
  SWITCH
@@ -95,7 +95,7 @@ function getAccount(email) {
95
95
  function getActiveAccount() {
96
96
  const data = loadAccounts();
97
97
  if (!data.activeAccount) return null;
98
- return data.accounts.find(a => a.email === data.activeAccount) || null;
98
+ return data.accounts.find(a => a.email === data.activeAccount && a.enabled !== false) || null;
99
99
  }
100
100
 
101
101
  function isAccountExpired(account, now = Date.now()) {
@@ -117,6 +117,42 @@ function updateAccountExpiration(email, accountExpiresAt) {
117
117
  return { success: true, message: `Account expiration updated: ${email}` };
118
118
  }
119
119
 
120
+ /**
121
+ * Persists account availability. Disabling the active account selects an
122
+ * enabled, unexpired replacement; in-flight requests are not interrupted.
123
+ */
124
+ function updateAccountEnabled(email, enabled) {
125
+ const data = loadAccounts();
126
+ const account = data.accounts.find(a => a.email === email);
127
+
128
+ if (!account) {
129
+ return { success: false, message: `Account not found: ${email}` };
130
+ }
131
+
132
+ account.enabled = enabled;
133
+ let nextActive = null;
134
+
135
+ if (!enabled && data.activeAccount === email) {
136
+ nextActive = data.accounts.find(a => a.enabled !== false && !isAccountExpired(a)) || null;
137
+ data.activeAccount = nextActive?.email || null;
138
+ } else if (enabled && !data.activeAccount && !isAccountExpired(account)) {
139
+ nextActive = account;
140
+ data.activeAccount = email;
141
+ }
142
+
143
+ saveAccounts(data);
144
+ if (nextActive) {
145
+ updateAccountAuth(nextActive);
146
+ }
147
+
148
+ return {
149
+ success: true,
150
+ message: `Account ${enabled ? 'enabled' : 'disabled'}: ${email}`,
151
+ enabled,
152
+ activeAccount: data.activeAccount
153
+ };
154
+ }
155
+
120
156
  function updateAccountAuth(account) {
121
157
  if (!account) return;
122
158
 
@@ -155,6 +191,10 @@ function setActiveAccount(email) {
155
191
  return { success: false, message: `Account not found: ${email}` };
156
192
  }
157
193
 
194
+ if (account.enabled === false) {
195
+ return { success: false, message: `Account is disabled: ${email}` };
196
+ }
197
+
158
198
  if (isAccountExpired(account)) {
159
199
  return { success: false, message: `Account has expired: ${email}` };
160
200
  }
@@ -187,8 +227,9 @@ function removeAccount(email) {
187
227
  data.accounts.splice(index, 1);
188
228
 
189
229
  if (data.activeAccount === email) {
190
- data.activeAccount = data.accounts[0]?.email || null;
191
-
230
+ const replacement = data.accounts.find(a => a.enabled !== false && !isAccountExpired(a));
231
+ data.activeAccount = replacement?.email || null;
232
+
192
233
  if (data.activeAccount) {
193
234
  const newActive = data.accounts.find(a => a.email === data.activeAccount);
194
235
  updateAccountAuth(newActive);
@@ -211,7 +252,8 @@ function listAccounts() {
211
252
  planType: info?.planType || account.planType || 'unknown',
212
253
  addedAt: account.addedAt,
213
254
  lastUsed: account.lastUsed,
214
- isActive: account.email === data.activeAccount,
255
+ isActive: account.email === data.activeAccount && account.enabled !== false,
256
+ enabled: account.enabled !== false,
215
257
  tokenExpired: info?.expiresAt ? info.expiresAt < Date.now() : false,
216
258
  accountExpiresAt: account.accountExpiresAt || null,
217
259
  accountExpired: isAccountExpired(account),
@@ -332,7 +374,7 @@ async function refreshAllAccounts() {
332
374
  const results = [];
333
375
 
334
376
  for (const account of data.accounts) {
335
- if (account.refreshToken) {
377
+ if (account.enabled !== false && account.refreshToken) {
336
378
  const result = await refreshAccountToken(account.email);
337
379
  results.push({ email: account.email, ...result });
338
380
  }
@@ -346,7 +388,7 @@ async function refreshAllAccountQuotas() {
346
388
  const results = [];
347
389
 
348
390
  for (const account of data.accounts) {
349
- if (!account.accessToken || !account.accountId) continue;
391
+ if (account.enabled === false || !account.accessToken || !account.accountId) continue;
350
392
 
351
393
  try {
352
394
  if (isTokenExpiredOrExpiringSoon(account) && account.refreshToken) {
@@ -380,7 +422,7 @@ function startAutoRefresh() {
380
422
  console.log('[AccountManager] Startup: refreshing all account tokens...');
381
423
  const data = loadAccounts();
382
424
  for (const account of data.accounts) {
383
- if (account.refreshToken) {
425
+ if (account.enabled !== false && account.refreshToken) {
384
426
  console.log(`[AccountManager] Startup refresh for ${account.email}`);
385
427
  await refreshAccountToken(account.email);
386
428
  }
@@ -391,7 +433,7 @@ function startAutoRefresh() {
391
433
  const data = loadAccounts();
392
434
 
393
435
  for (const account of data.accounts) {
394
- if (account.refreshToken) {
436
+ if (account.enabled !== false && account.refreshToken) {
395
437
  console.log(`[AccountManager] Periodic token refresh for ${account.email}`);
396
438
  await refreshAccountToken(account.email);
397
439
  }
@@ -506,12 +548,13 @@ function importFromCodex() {
506
548
  data.accounts.push(newAccount);
507
549
  }
508
550
 
509
- if (!data.activeAccount) {
551
+ const importedAccount = data.accounts.find(a => a.email === newAccount.email);
552
+ if (!data.activeAccount && importedAccount.enabled !== false && !isAccountExpired(importedAccount)) {
510
553
  data.activeAccount = newAccount.email;
511
554
  }
512
-
555
+
513
556
  saveAccounts(data);
514
- updateAccountAuth(newAccount);
557
+ updateAccountAuth(importedAccount);
515
558
 
516
559
  return {
517
560
  success: true,
@@ -529,7 +572,8 @@ function getStatus() {
529
572
  return {
530
573
  email: a.email,
531
574
  planType: a.planType,
532
- isActive: a.email === data.activeAccount,
575
+ isActive: a.email === data.activeAccount && a.enabled !== false,
576
+ enabled: a.enabled !== false,
533
577
  quota: a.quota || null,
534
578
  tokenExpired: info?.expiresAt ? info.expiresAt < Date.now() : false,
535
579
  accountExpiresAt: a.accountExpiresAt || null,
@@ -549,7 +593,7 @@ function ensureAccountsPersist() {
549
593
  const data = loadAccounts();
550
594
  if (data.accounts.length > 0 && data.activeAccount) {
551
595
  const active = data.accounts.find(a => a.email === data.activeAccount);
552
- if (active) {
596
+ if (active && active.enabled !== false) {
553
597
  updateAccountAuth(active);
554
598
  console.log(`[AccountManager] Restored active account: ${active.email}`);
555
599
  }
@@ -576,6 +620,7 @@ export {
576
620
  updateAccountQuota,
577
621
  getAccountQuota,
578
622
  updateAccountExpiration,
623
+ updateAccountEnabled,
579
624
  isAccountExpired,
580
625
  startAutoRefresh,
581
626
  stopAutoRefresh,
@@ -604,6 +649,7 @@ export default {
604
649
  updateAccountQuota,
605
650
  getAccountQuota,
606
651
  updateAccountExpiration,
652
+ updateAccountEnabled,
607
653
  isAccountExpired,
608
654
  startAutoRefresh,
609
655
  stopAutoRefresh,
@@ -203,7 +203,7 @@ export function getMinWaitTimeMs(accounts, modelId) {
203
203
  let minWait = Infinity;
204
204
 
205
205
  for (const account of accounts) {
206
- if (account.isInvalid) continue;
206
+ if (account.isInvalid || account.enabled === false) continue;
207
207
 
208
208
  const cooldownRemaining = getCooldownRemaining(account);
209
209
  if (cooldownRemaining > 0 && cooldownRemaining < minWait) {
@@ -299,7 +299,7 @@ async function addAccountManual(rl) {
299
299
  };
300
300
 
301
301
  if (existingIndex >= 0) {
302
- data.accounts[existingIndex] = newAccount;
302
+ data.accounts[existingIndex] = { ...data.accounts[existingIndex], ...newAccount };
303
303
  console.log(`\n⚠ Account ${newAccount.email} already exists. Updating tokens.`);
304
304
  } else {
305
305
  data.accounts.push(newAccount);
@@ -358,7 +358,7 @@ async function addAccountBrowser(rl) {
358
358
  };
359
359
 
360
360
  if (existingIndex >= 0) {
361
- data.accounts[existingIndex] = newAccount;
361
+ data.accounts[existingIndex] = { ...data.accounts[existingIndex], ...newAccount };
362
362
  console.log(`\n⚠ Account ${newAccount.email} already exists. Updating tokens.`);
363
363
  } else {
364
364
  data.accounts.push(newAccount);
@@ -433,7 +433,7 @@ async function interactiveRemove(rl) {
433
433
  if (confirm.toLowerCase() === 'y') {
434
434
  data.accounts.splice(index - 1, 1);
435
435
  if (data.activeAccount === removed.email) {
436
- data.activeAccount = data.accounts[0]?.email || null;
436
+ data.activeAccount = data.accounts.find(account => account.enabled !== false)?.email || null;
437
437
  }
438
438
  saveAccounts(data);
439
439
  console.log(`\n✓ Removed ${removed.email}`);
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Daily Anchor Ping
3
3
  * Every day at a fixed local hour (default 09:00) this module sends a minimal
4
- * "你好" message to every configured account so the upstream Codex five-hour
4
+ * "你好" message to every enabled account so the upstream Codex five-hour
5
5
  * usage window is re-anchored to that moment. Because the upstream window
6
6
  * advances from the first usage of the window, an anchor ping at 09:00 local
7
7
  * time makes the upstream reset time settle at 14:00 local time (09:00 + 5h).
@@ -69,14 +69,14 @@ function buildAnchorRequest() {
69
69
  }
70
70
 
71
71
  /**
72
- * Sends the anchor message to every configured account. Each account is
72
+ * Sends the anchor message to every enabled account. Each account is
73
73
  * handled independently so a single failure never aborts the rest.
74
74
  */
75
75
  async function pingAllAccounts() {
76
76
  const data = loadAccounts();
77
- const accounts = data.accounts || [];
77
+ const accounts = (data.accounts || []).filter(account => account.enabled !== false);
78
78
  if (accounts.length === 0) {
79
- logger.info('[AnchorPing] No accounts configured; skipping daily ping');
79
+ logger.info('[AnchorPing] No enabled accounts; skipping daily ping');
80
80
  return;
81
81
  }
82
82
 
@@ -28,8 +28,8 @@ export async function getCredentialsOrError() {
28
28
  return null;
29
29
  }
30
30
 
31
- if (isAccountExpired(account)) {
32
- logger.info(`Account ${account.email} has expired`);
31
+ if (account.enabled === false || isAccountExpired(account)) {
32
+ logger.info(`Account ${account.email} is disabled or has expired`);
33
33
  return null;
34
34
  }
35
35
 
@@ -47,8 +47,9 @@ export async function getCredentialsOrError() {
47
47
  return null;
48
48
  }
49
49
 
50
- const refreshedAccount = getActiveAccount();
51
- if (!refreshedAccount || isAccountExpired(refreshedAccount)) {
50
+ // Keep the original identity: disabling it may have activated another account.
51
+ const refreshedAccount = loadAccounts().accounts.find(a => a.email === account.email);
52
+ if (!refreshedAccount || refreshedAccount.enabled === false || isAccountExpired(refreshedAccount)) {
52
53
  logger.error('Failed to get refreshed active account');
53
54
  return null;
54
55
  }
@@ -81,7 +82,7 @@ export async function getCredentialsForAccount(email) {
81
82
  return null;
82
83
  }
83
84
 
84
- if (isAccountExpired(account)) {
85
+ if (account.enabled === false || isAccountExpired(account)) {
85
86
  return null;
86
87
  }
87
88
 
@@ -96,7 +97,7 @@ export async function getCredentialsForAccount(email) {
96
97
  }
97
98
  const refreshedData = loadAccounts();
98
99
  const refreshedAccount = refreshedData.accounts.find(a => a.email === email);
99
- if (!refreshedAccount || isAccountExpired(refreshedAccount)) return null;
100
+ if (!refreshedAccount || refreshedAccount.enabled === false || isAccountExpired(refreshedAccount)) return null;
100
101
 
101
102
  return {
102
103
  accessToken: refreshedAccount.accessToken,
@@ -15,6 +15,7 @@
15
15
  * POST /accounts/refresh/all
16
16
  * POST /accounts/:email/refresh
17
17
  * PUT /accounts/:email/expiration
18
+ * PUT /accounts/:email/enabled
18
19
  * POST /accounts/oauth/cleanup
19
20
  * DELETE /accounts/:email
20
21
  */
@@ -31,10 +32,10 @@ import {
31
32
  getStatus,
32
33
  loadAccounts,
33
34
  saveAccounts,
34
- updateAccountAuth,
35
35
  updateAccountQuota,
36
36
  getAccountQuota,
37
- updateAccountExpiration
37
+ updateAccountExpiration,
38
+ updateAccountEnabled
38
39
  } from '../account-manager.js';
39
40
 
40
41
  import {
@@ -204,6 +205,22 @@ export function handleUpdateAccountExpiration(req, res) {
204
205
  return res.status(result.success ? 200 : 404).json(result);
205
206
  }
206
207
 
208
+ /** Updates the persisted account switch without toggling on repeated requests. */
209
+ export function handleUpdateAccountEnabled(req, res) {
210
+ const { email } = req.params;
211
+ const { enabled } = req.body || {};
212
+
213
+ if (typeof enabled !== 'boolean') {
214
+ return res.status(400).json({ success: false, message: 'enabled must be a boolean' });
215
+ }
216
+
217
+ const result = updateAccountEnabled(email, enabled);
218
+ if (result.success) {
219
+ logger.info(`Account ${enabled ? 'enabled' : 'disabled'}: ${email}`);
220
+ }
221
+ return res.status(result.success ? 200 : 404).json(result);
222
+ }
223
+
207
224
  export async function handleRefreshActiveAccount(req, res) {
208
225
  const result = await refreshActiveAccount();
209
226
  res.json(result);
@@ -369,7 +386,7 @@ export function createAccountInfoFromTokens(tokens) {
369
386
 
370
387
  /**
371
388
  * Inserts or updates an account in the persisted accounts store,
372
- * and sets it as the active account.
389
+ * and activates it only if it is enabled and unexpired.
373
390
  * @param {object} accountInfo
374
391
  */
375
392
  async function _upsertAccount(accountInfo) {
@@ -382,9 +399,9 @@ async function _upsertAccount(accountInfo) {
382
399
  data.accounts.push(accountInfo);
383
400
  }
384
401
 
385
- data.activeAccount = accountInfo.email;
386
402
  saveAccounts(data);
387
- updateAccountAuth(accountInfo);
403
+ // Reauthorizing an existing account must not undo its manual disable state.
404
+ setActiveAccount(accountInfo.email);
388
405
 
389
406
  // Fetch initial quota immediately
390
407
  try {
@@ -406,6 +423,7 @@ export default {
406
423
  handleRefreshAccount,
407
424
  handleRefreshAllAccounts,
408
425
  handleUpdateAccountExpiration,
426
+ handleUpdateAccountEnabled,
409
427
  handleRefreshActiveAccount,
410
428
  handleRemoveAccount,
411
429
  handleImportAccount,
@@ -43,6 +43,7 @@ import {
43
43
  handleRefreshAccount,
44
44
  handleRefreshAllAccounts,
45
45
  handleUpdateAccountExpiration,
46
+ handleUpdateAccountEnabled,
46
47
  handleRefreshActiveAccount,
47
48
  handleRemoveAccount,
48
49
  handleImportAccount,
@@ -139,6 +140,7 @@ export function registerApiRoutes(app, { port }) {
139
140
  adminRouter.post('/accounts/oauth/cleanup', handleOAuthCleanup);
140
141
  adminRouter.post('/accounts/:email/refresh', handleRefreshAccount);
141
142
  adminRouter.put('/accounts/:email/expiration', handleUpdateAccountExpiration);
143
+ adminRouter.put('/accounts/:email/enabled', handleUpdateAccountEnabled);
142
144
 
143
145
  adminRouter.delete('/accounts/:email', handleRemoveAccount);
144
146
 
@@ -115,7 +115,10 @@ export async function handleMessages(req, res) {
115
115
  const creds = await getCredentialsForAccount(account.email);
116
116
  if (!creds) {
117
117
  attemptedEmails.add(account.email);
118
- rotator.markInvalid(account.email, 'Failed to get credentials');
118
+ // A manual disable during token refresh is not an authentication failure.
119
+ if (account.enabled !== false) {
120
+ rotator.markInvalid(account.email, 'Failed to get credentials');
121
+ }
119
122
  const replacement = switchToReplacementAccount(rotator, account.email, upstreamModel, {
120
123
  sessionId: requestContext.sessionId,
121
124
  excludeEmails: attemptedEmails