chaimi-keep-mcp 3.3.0-beta.1 → 3.3.0-beta.3
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.
- package/oauth.js +15 -1
- package/package.json +1 -1
- package/server.js +19 -1
package/oauth.js
CHANGED
|
@@ -431,6 +431,10 @@ class FileTokenStorage extends TokenStorage {
|
|
|
431
431
|
const dir = this.path.dirname(this.filePath);
|
|
432
432
|
await this.fs.mkdir(dir, { recursive: true });
|
|
433
433
|
|
|
434
|
+
console.error('🔍 [DEBUG] 开始保存 Token');
|
|
435
|
+
console.error('🔍 [DEBUG] 加密密钥 (前8位):', this.key.substring(0, 8));
|
|
436
|
+
console.error('🔍 [DEBUG] Token 过期时间:', token.expiresAt);
|
|
437
|
+
|
|
434
438
|
// 加密 Token 后保存
|
|
435
439
|
const encrypted = encryptToken(token, this.key);
|
|
436
440
|
const data = {
|
|
@@ -445,6 +449,7 @@ class FileTokenStorage extends TokenStorage {
|
|
|
445
449
|
JSON.stringify(data, null, 2),
|
|
446
450
|
{ mode: 0o600 }
|
|
447
451
|
);
|
|
452
|
+
console.error('🔍 [DEBUG] Token 保存成功:', this.filePath);
|
|
448
453
|
}
|
|
449
454
|
|
|
450
455
|
async load() {
|
|
@@ -452,6 +457,10 @@ class FileTokenStorage extends TokenStorage {
|
|
|
452
457
|
const data = await this.fs.readFile(this.filePath, 'utf8');
|
|
453
458
|
const parsed = JSON.parse(data);
|
|
454
459
|
|
|
460
|
+
console.error('🔍 [DEBUG] 开始加载 Token 文件');
|
|
461
|
+
console.error('🔍 [DEBUG] 文件版本:', parsed.version);
|
|
462
|
+
console.error('🔍 [DEBUG] 加密密钥 (前8位):', this.key.substring(0, 8));
|
|
463
|
+
|
|
455
464
|
// 向后兼容:检测旧版明文格式
|
|
456
465
|
if (!parsed.version || parsed.version === '1.0') {
|
|
457
466
|
console.error('检测到旧版 Token 格式,自动升级...');
|
|
@@ -466,11 +475,16 @@ class FileTokenStorage extends TokenStorage {
|
|
|
466
475
|
}
|
|
467
476
|
|
|
468
477
|
// 新版加密格式,解密后返回
|
|
469
|
-
|
|
478
|
+
console.error('🔍 [DEBUG] 开始解密 Token...');
|
|
479
|
+
const decrypted = decryptToken(parsed.encrypted, this.key);
|
|
480
|
+
console.error('🔍 [DEBUG] 解密成功,Token 过期时间:', decrypted.expiresAt);
|
|
481
|
+
return decrypted;
|
|
470
482
|
} catch (err) {
|
|
471
483
|
if (err.code === 'ENOENT') {
|
|
484
|
+
console.error('🔍 [DEBUG] Token 文件不存在');
|
|
472
485
|
return null;
|
|
473
486
|
}
|
|
487
|
+
console.error('🔍 [DEBUG] 加载 Token 失败:', err.message);
|
|
474
488
|
throw err;
|
|
475
489
|
}
|
|
476
490
|
}
|
package/package.json
CHANGED
package/server.js
CHANGED
|
@@ -475,10 +475,27 @@ async function getToken() {
|
|
|
475
475
|
|
|
476
476
|
// 【优化2】尝试从文件加载 token(优先级高于授权状态检查)
|
|
477
477
|
try {
|
|
478
|
+
console.error('🔍 [DEBUG] 尝试从文件加载 Token...');
|
|
478
479
|
const existingToken = await oauthManager.tokenStorage.load();
|
|
480
|
+
console.error('🔍 [DEBUG] Token 加载结果:', existingToken ? '成功' : '为空');
|
|
481
|
+
if (existingToken) {
|
|
482
|
+
console.error('🔍 [DEBUG] Token 字段检查:', {
|
|
483
|
+
hasAccessToken: !!existingToken.accessToken,
|
|
484
|
+
hasExpiresAt: !!existingToken.expiresAt,
|
|
485
|
+
expiresAt: existingToken.expiresAt
|
|
486
|
+
});
|
|
487
|
+
}
|
|
479
488
|
if (existingToken && existingToken.accessToken && existingToken.expiresAt) {
|
|
480
489
|
const expiresAt = new Date(existingToken.expiresAt).getTime();
|
|
481
|
-
|
|
490
|
+
const now = Date.now();
|
|
491
|
+
const threshold = now + 5 * 60 * 1000;
|
|
492
|
+
console.error('🔍 [DEBUG] 过期时间检查:', {
|
|
493
|
+
expiresAt,
|
|
494
|
+
now,
|
|
495
|
+
threshold,
|
|
496
|
+
isValid: expiresAt > threshold
|
|
497
|
+
});
|
|
498
|
+
if (expiresAt > threshold) {
|
|
482
499
|
// Token 有效,直接使用
|
|
483
500
|
cachedToken = existingToken.accessToken;
|
|
484
501
|
tokenExpireTime = expiresAt;
|
|
@@ -492,6 +509,7 @@ async function getToken() {
|
|
|
492
509
|
}
|
|
493
510
|
} catch (err) {
|
|
494
511
|
console.error('⚠️ 加载保存的 Token 失败:', err.message);
|
|
512
|
+
console.error('⚠️ 错误堆栈:', err.stack);
|
|
495
513
|
}
|
|
496
514
|
|
|
497
515
|
// 【优化3】Token 不存在或已过期,检查是否需要授权
|