@kervnet/opencode-kiro-auth 1.7.6 → 1.7.8

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.
@@ -12,6 +12,8 @@ export declare class TokenRefresher {
12
12
  private accountManager;
13
13
  private syncFromKiroCli;
14
14
  private repository;
15
+ private lastSyncTime;
16
+ private readonly SYNC_COOLDOWN_MS;
15
17
  constructor(config: TokenRefresherConfig, accountManager: AccountManager, syncFromKiroCli: () => Promise<void>, repository: AccountRepository);
16
18
  refreshIfNeeded(account: ManagedAccount, auth: KiroAuthDetails, showToast: ToastFunction): Promise<{
17
19
  account: ManagedAccount;
@@ -6,6 +6,8 @@ export class TokenRefresher {
6
6
  accountManager;
7
7
  syncFromKiroCli;
8
8
  repository;
9
+ lastSyncTime = 0;
10
+ SYNC_COOLDOWN_MS = 5000; // Only sync once per 5 seconds
9
11
  constructor(config, accountManager, syncFromKiroCli, repository) {
10
12
  this.config = config;
11
13
  this.accountManager = accountManager;
@@ -27,7 +29,10 @@ export class TokenRefresher {
27
29
  }
28
30
  }
29
31
  async handleRefreshError(error, account, showToast) {
30
- if (this.config.auto_sync_kiro_cli) {
32
+ // Only sync if cooldown period has passed
33
+ const now = Date.now();
34
+ if (this.config.auto_sync_kiro_cli && now - this.lastSyncTime > this.SYNC_COOLDOWN_MS) {
35
+ this.lastSyncTime = now;
31
36
  await this.syncFromKiroCli();
32
37
  }
33
38
  this.repository.invalidateCache();
@@ -52,6 +52,22 @@ export class RequestHandler {
52
52
  throw new Error(check.error);
53
53
  }
54
54
  if (this.allAccountsPermanentlyUnhealthy()) {
55
+ // Try to recover by syncing from kiro-cli
56
+ if (this.config.auto_sync_kiro_cli) {
57
+ showToast('All accounts unhealthy. Attempting recovery from Kiro CLI...', 'warning');
58
+ const { syncFromKiroCli } = await import('../../plugin/sync/kiro-cli.js');
59
+ await syncFromKiroCli();
60
+ // Reset all accounts to healthy and clear fail counts
61
+ const accounts = this.accountManager.getAccounts();
62
+ for (const acc of accounts) {
63
+ acc.isHealthy = true;
64
+ acc.failCount = 0;
65
+ acc.unhealthyReason = undefined;
66
+ }
67
+ await this.repository.batchSave(accounts);
68
+ // Give it one more chance
69
+ continue;
70
+ }
55
71
  throw new Error('All accounts are permanently unhealthy (quota exceeded or suspended)');
56
72
  }
57
73
  let acc = await this.accountSelector.selectHealthyAccount(showToast);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kervnet/opencode-kiro-auth",
3
- "version": "1.7.6",
3
+ "version": "1.7.8",
4
4
  "description": "OpenCode plugin for AWS Kiro (CodeWhisperer) with IAM Identity Center profile support",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",