@kervnet/opencode-kiro-auth 1.7.22 → 1.7.24

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.
@@ -49,7 +49,7 @@ export class AuthHandler {
49
49
  }
50
50
  const cliDb = new Database(cliDbPath, { readonly: true });
51
51
  const tokenRow = cliDb
52
- .prepare("SELECT json_extract(value, '$.expires_at') as expires FROM auth_kv WHERE key LIKE '%token' LIMIT 1")
52
+ .prepare("SELECT json_extract(value, '$.expires_at') as expires FROM auth_kv WHERE key LIKE '%token' ORDER BY json_extract(value, '$.expires_at') DESC LIMIT 1")
53
53
  .get();
54
54
  cliDb.close();
55
55
  const cliExpires = tokenRow?.expires ? new Date(tokenRow.expires).getTime() : 0;
@@ -47,7 +47,10 @@ export function mergeAccounts(existing, incoming) {
47
47
  for (const acc of incoming) {
48
48
  const existingAcc = accountMap.get(acc.id);
49
49
  if (existingAcc) {
50
- const hasPermanentError = isPermanentError(existingAcc.unhealthyReason) || isPermanentError(acc.unhealthyReason);
50
+ // If incoming has fresh tokens and no unhealthy reason, it's a recovery — clear permanent errors
51
+ const incomingIsRecovery = acc.isHealthy && !acc.unhealthyReason && acc.expiresAt > (existingAcc.expiresAt || 0);
52
+ const hasPermanentError = incomingIsRecovery ? false :
53
+ isPermanentError(existingAcc.unhealthyReason) || isPermanentError(acc.unhealthyReason);
51
54
  accountMap.set(acc.id, {
52
55
  ...existingAcc,
53
56
  ...acc,
@@ -56,7 +59,9 @@ export function mergeAccounts(existing, incoming) {
56
59
  limitCount: Math.max(existingAcc.limitCount || 0, acc.limitCount || 0),
57
60
  rateLimitResetTime: Math.max(existingAcc.rateLimitResetTime || 0, acc.rateLimitResetTime || 0),
58
61
  isHealthy: hasPermanentError ? false : existingAcc.isHealthy || acc.isHealthy,
59
- failCount: Math.max(existingAcc.failCount || 0, acc.failCount || 0),
62
+ failCount: incomingIsRecovery ? 0 : Math.max(existingAcc.failCount || 0, acc.failCount || 0),
63
+ unhealthyReason: incomingIsRecovery ? undefined : (acc.unhealthyReason || existingAcc.unhealthyReason),
64
+ recoveryTime: incomingIsRecovery ? undefined : (acc.recoveryTime || existingAcc.recoveryTime),
60
65
  lastSync: Math.max(existingAcc.lastSync || 0, acc.lastSync || 0)
61
66
  });
62
67
  }
@@ -49,10 +49,11 @@ export class KiroDatabase {
49
49
  is_healthy, unhealthy_reason, recovery_time, fail_count, last_used,
50
50
  used_count, limit_count, last_sync
51
51
  ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
52
- ON CONFLICT(refresh_token) DO UPDATE SET
53
- id=excluded.id, email=excluded.email, auth_method=excluded.auth_method,
52
+ ON CONFLICT(id) DO UPDATE SET
53
+ email=excluded.email, auth_method=excluded.auth_method,
54
54
  region=excluded.region, client_id=excluded.client_id, client_secret=excluded.client_secret,
55
- profile_arn=excluded.profile_arn, access_token=excluded.access_token, expires_at=excluded.expires_at,
55
+ profile_arn=excluded.profile_arn, refresh_token=excluded.refresh_token,
56
+ access_token=excluded.access_token, expires_at=excluded.expires_at,
56
57
  rate_limit_reset=excluded.rate_limit_reset, is_healthy=excluded.is_healthy,
57
58
  unhealthy_reason=excluded.unhealthy_reason, recovery_time=excluded.recovery_time,
58
59
  fail_count=excluded.fail_count, last_used=excluded.last_used,
@@ -162,6 +162,8 @@ export async function syncFromKiroCli() {
162
162
  rateLimitResetTime: 0,
163
163
  isHealthy: true,
164
164
  failCount: 0,
165
+ unhealthyReason: undefined,
166
+ recoveryTime: undefined,
165
167
  usedCount,
166
168
  limitCount,
167
169
  lastSync: Date.now()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kervnet/opencode-kiro-auth",
3
- "version": "1.7.22",
3
+ "version": "1.7.24",
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",