@kervnet/opencode-kiro-auth 1.7.5 → 1.7.7

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();
@@ -62,9 +62,9 @@ export class ErrorHandler {
62
62
  await this.sleep(w);
63
63
  return { shouldRetry: true };
64
64
  }
65
- if ((response.status === 402 || response.status === 403) &&
66
- this.accountManager.getAccountCount() > 1) {
67
- let errorReason = response.status === 402 ? 'Quota' : 'Forbidden';
65
+ // Handle 403 Forbidden - might be invalid/stale token
66
+ if (response.status === 403) {
67
+ let errorReason = 'Forbidden';
68
68
  let isPermanent = false;
69
69
  try {
70
70
  const errorBody = await response.text();
@@ -84,10 +84,25 @@ export class ErrorHandler {
84
84
  }
85
85
  if (isPermanent) {
86
86
  account.failCount = 10;
87
+ this.accountManager.markUnhealthy(account, errorReason);
88
+ await this.repository.batchSave(this.accountManager.getAccounts());
89
+ if (this.accountManager.getAccountCount() > 1) {
90
+ showToast(`${errorReason} (${account.email}). Switching account...`, 'warning');
91
+ return { shouldRetry: true, switchAccount: true };
92
+ }
93
+ throw new Error(errorReason);
87
94
  }
88
- this.accountManager.markUnhealthy(account, errorReason);
95
+ // For non-permanent 403, force token expiry to trigger refresh
96
+ account.expiresAt = 0;
97
+ await this.repository.batchSave(this.accountManager.getAccounts());
98
+ showToast('Token expired. Refreshing...', 'info');
99
+ return { shouldRetry: true };
100
+ }
101
+ // Handle 402 Payment Required (quota exceeded)
102
+ if (response.status === 402 && this.accountManager.getAccountCount() > 1) {
103
+ this.accountManager.markUnhealthy(account, 'Quota');
89
104
  await this.repository.batchSave(this.accountManager.getAccounts());
90
- showToast(`${errorReason} (${account.email}). Switching account...`, 'warning');
105
+ showToast(`Quota exceeded (${account.email}). Switching account...`, 'warning');
91
106
  return { shouldRetry: true, switchAccount: true };
92
107
  }
93
108
  return { shouldRetry: false };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kervnet/opencode-kiro-auth",
3
- "version": "1.7.5",
3
+ "version": "1.7.7",
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",