@kervnet/opencode-kiro-auth 1.7.23 → 1.7.25
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.
|
@@ -34,6 +34,21 @@ export class AccountSelector {
|
|
|
34
34
|
await this.sleep(wait);
|
|
35
35
|
return null;
|
|
36
36
|
}
|
|
37
|
+
// Last resort: re-sync from kiro-cli and reset all accounts
|
|
38
|
+
if (this.config.auto_sync_kiro_cli) {
|
|
39
|
+
await this.syncFromKiroCli();
|
|
40
|
+
this.repository.invalidateCache();
|
|
41
|
+
const fresh = await this.repository.findAll();
|
|
42
|
+
this.accountManager.replaceAccounts(fresh);
|
|
43
|
+
for (const a of this.accountManager.getAccounts()) {
|
|
44
|
+
a.isHealthy = true;
|
|
45
|
+
a.failCount = 0;
|
|
46
|
+
a.unhealthyReason = undefined;
|
|
47
|
+
a.recoveryTime = undefined;
|
|
48
|
+
}
|
|
49
|
+
await this.repository.batchSave(this.accountManager.getAccounts());
|
|
50
|
+
return null; // retry on next loop iteration
|
|
51
|
+
}
|
|
37
52
|
throw new Error('All accounts are unhealthy or rate-limited');
|
|
38
53
|
}
|
|
39
54
|
this.resetCircuitBreaker();
|
|
@@ -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
|
-
|
|
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
|
}
|
package/package.json
CHANGED