@kervnet/opencode-kiro-auth 1.7.7 → 1.7.9
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.
|
@@ -3,8 +3,10 @@ export declare class AuthHandler {
|
|
|
3
3
|
private config;
|
|
4
4
|
private repository;
|
|
5
5
|
private accountManager?;
|
|
6
|
+
private refreshTimer?;
|
|
6
7
|
constructor(config: any, repository: AccountRepository);
|
|
7
8
|
initialize(): Promise<void>;
|
|
9
|
+
private startBackgroundRefresh;
|
|
8
10
|
setAccountManager(am: any): void;
|
|
9
11
|
getMethods(): Array<{
|
|
10
12
|
id: string;
|
|
@@ -4,6 +4,7 @@ export class AuthHandler {
|
|
|
4
4
|
config;
|
|
5
5
|
repository;
|
|
6
6
|
accountManager;
|
|
7
|
+
refreshTimer;
|
|
7
8
|
constructor(config, repository) {
|
|
8
9
|
this.config = config;
|
|
9
10
|
this.repository = repository;
|
|
@@ -11,6 +12,24 @@ export class AuthHandler {
|
|
|
11
12
|
async initialize() {
|
|
12
13
|
const { syncFromKiroCli } = await import('../../plugin/sync/kiro-cli.js');
|
|
13
14
|
await syncFromKiroCli();
|
|
15
|
+
// Start background token refresh every 15 minutes
|
|
16
|
+
this.startBackgroundRefresh();
|
|
17
|
+
}
|
|
18
|
+
startBackgroundRefresh() {
|
|
19
|
+
// Clear existing timer if any
|
|
20
|
+
if (this.refreshTimer) {
|
|
21
|
+
clearInterval(this.refreshTimer);
|
|
22
|
+
}
|
|
23
|
+
// Refresh every 15 minutes
|
|
24
|
+
this.refreshTimer = setInterval(async () => {
|
|
25
|
+
try {
|
|
26
|
+
const { syncFromKiroCli } = await import('../../plugin/sync/kiro-cli.js');
|
|
27
|
+
await syncFromKiroCli();
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
// Silent fail - will retry in 15 minutes
|
|
31
|
+
}
|
|
32
|
+
}, 15 * 60 * 1000);
|
|
14
33
|
}
|
|
15
34
|
setAccountManager(am) {
|
|
16
35
|
this.accountManager = am;
|
|
@@ -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