@kervnet/opencode-kiro-auth 1.7.18 → 1.7.19
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.
|
@@ -25,7 +25,19 @@ export class AuthHandler {
|
|
|
25
25
|
try {
|
|
26
26
|
const logger = await import('../../plugin/logger.js');
|
|
27
27
|
logger.log('Background token refresh starting...');
|
|
28
|
-
|
|
28
|
+
const bufferMs = this.config.token_expiry_buffer_ms || 120000;
|
|
29
|
+
let needsRefresh = false;
|
|
30
|
+
// Check if any plugin account token is expiring within buffer
|
|
31
|
+
if (this.accountManager) {
|
|
32
|
+
const accounts = this.accountManager.getAccounts();
|
|
33
|
+
for (const acc of accounts) {
|
|
34
|
+
if (acc.expiresAt && Date.now() >= acc.expiresAt - bufferMs - 5 * 60 * 1000) {
|
|
35
|
+
logger.log(`Background token refresh: account ${acc.email} token expiring soon (${new Date(acc.expiresAt).toLocaleString()}), forcing refresh`);
|
|
36
|
+
needsRefresh = true;
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
29
41
|
try {
|
|
30
42
|
const { existsSync } = await import('node:fs');
|
|
31
43
|
const { Database } = await import('bun:sqlite');
|
|
@@ -41,24 +53,28 @@ export class AuthHandler {
|
|
|
41
53
|
.prepare("SELECT json_extract(value, '$.expires_at') as expires FROM auth_kv WHERE key LIKE '%token' LIMIT 1")
|
|
42
54
|
.get();
|
|
43
55
|
cliDb.close();
|
|
44
|
-
|
|
45
|
-
|
|
56
|
+
const cliExpires = tokenRow?.expires ? new Date(tokenRow.expires).getTime() : 0;
|
|
57
|
+
if (!cliExpires || Date.now() >= cliExpires - bufferMs - 5 * 60 * 1000) {
|
|
58
|
+
needsRefresh = true;
|
|
59
|
+
}
|
|
60
|
+
if (needsRefresh) {
|
|
61
|
+
logger.log('Background token refresh: forcing kiro-cli whoami...');
|
|
62
|
+
const { execSync } = await import('node:child_process');
|
|
46
63
|
try {
|
|
47
|
-
const { execSync } = await import('node:child_process');
|
|
48
64
|
execSync('kiro-cli whoami', { timeout: 15000, stdio: 'pipe' });
|
|
49
|
-
logger.log('Background token refresh: kiro-cli
|
|
65
|
+
logger.log('Background token refresh: kiro-cli whoami succeeded');
|
|
50
66
|
}
|
|
51
67
|
catch {
|
|
52
|
-
logger.log('Background token refresh: kiro-cli
|
|
68
|
+
logger.log('Background token refresh: kiro-cli whoami failed, skipping');
|
|
53
69
|
return;
|
|
54
70
|
}
|
|
55
71
|
}
|
|
56
72
|
else {
|
|
57
|
-
logger.log(`Background token refresh:
|
|
73
|
+
logger.log(`Background token refresh: tokens valid, syncing`);
|
|
58
74
|
}
|
|
59
75
|
}
|
|
60
76
|
catch (e) {
|
|
61
|
-
logger.warn('Background token refresh: failed to check
|
|
77
|
+
logger.warn('Background token refresh: failed to check token status', e);
|
|
62
78
|
return;
|
|
63
79
|
}
|
|
64
80
|
const { syncFromKiroCli } = await import('../../plugin/sync/kiro-cli.js');
|
package/package.json
CHANGED