@yulailai/openclaw-plugin-self-growth 3.1.19 → 3.1.21
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/dist/auth-client.js +26 -0
- package/dist/sync-client.js +28 -11
- package/package.json +1 -1
package/dist/auth-client.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// 认证客户端 - 获取和刷新 JWT token
|
|
2
2
|
import * as fs from 'fs/promises';
|
|
3
3
|
import * as path from 'path';
|
|
4
|
+
import { loadActivation } from './payment';
|
|
4
5
|
let _cache = null;
|
|
5
6
|
export function getCachedToken() {
|
|
6
7
|
return _cache;
|
|
@@ -17,6 +18,31 @@ export async function loginAndGetToken(serverUrl, email, basePath) {
|
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
catch { }
|
|
21
|
+
// 用 payment.json 里的 token 验证
|
|
22
|
+
try {
|
|
23
|
+
const activation = await loadActivation(basePath);
|
|
24
|
+
const token = activation?.license;
|
|
25
|
+
if (token) {
|
|
26
|
+
const res = await fetch(`${serverUrl}/api/auth/me`, {
|
|
27
|
+
headers: { 'Authorization': `Bearer ${token}` },
|
|
28
|
+
signal: AbortSignal.timeout(5000),
|
|
29
|
+
});
|
|
30
|
+
if (res.ok) {
|
|
31
|
+
const data = await res.json();
|
|
32
|
+
const tokenCache = {
|
|
33
|
+
token,
|
|
34
|
+
userId: data.user.id,
|
|
35
|
+
email: data.user.email,
|
|
36
|
+
plan: data.user.plan,
|
|
37
|
+
expiresAt: Date.now() + 6 * 86400000,
|
|
38
|
+
};
|
|
39
|
+
_cache = tokenCache;
|
|
40
|
+
await fs.writeFile(cacheFile, JSON.stringify(tokenCache));
|
|
41
|
+
return tokenCache;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch { }
|
|
20
46
|
try {
|
|
21
47
|
const res = await fetch(`${serverUrl}/api/auth/login`, {
|
|
22
48
|
method: 'POST',
|
package/dist/sync-client.js
CHANGED
|
@@ -82,29 +82,46 @@ export class SyncClient {
|
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
async syncFiles(basePath, token) {
|
|
85
|
-
// 同步编译后的记忆文件到 memory API
|
|
86
85
|
try {
|
|
86
|
+
// 1. 同步人格文件 memory.md
|
|
87
87
|
const compiledDir = path.join(basePath, 'memory', 'compiled');
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
88
|
+
const memoryContent = await fs.readFile(path.join(compiledDir, 'memory.md'), 'utf-8').catch(() => '');
|
|
89
|
+
if (memoryContent) {
|
|
90
|
+
await fetch(`${this.config.serverUrl}/api/sync/push`, {
|
|
91
|
+
method: 'POST',
|
|
92
|
+
headers: {
|
|
93
|
+
'Content-Type': 'application/json',
|
|
94
|
+
'Authorization': `Bearer ${token}`,
|
|
95
|
+
},
|
|
96
|
+
body: JSON.stringify({
|
|
97
|
+
type: 'compiled_memory',
|
|
98
|
+
items: [{ content: memoryContent, file_path: 'memory.md' }],
|
|
99
|
+
}),
|
|
100
|
+
signal: AbortSignal.timeout(15000),
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
// 2. 同步 chat_logs(今天的)
|
|
104
|
+
const today = new Date().toISOString().split('T')[0];
|
|
105
|
+
const chatLogPath = path.join(basePath, 'chat_logs', `${today}.md`);
|
|
106
|
+
const chatContent = await fs.readFile(chatLogPath, 'utf-8').catch(() => '');
|
|
107
|
+
if (chatContent) {
|
|
108
|
+
await fetch(`${this.config.serverUrl}/api/sync/push`, {
|
|
95
109
|
method: 'POST',
|
|
96
110
|
headers: {
|
|
97
111
|
'Content-Type': 'application/json',
|
|
98
112
|
'Authorization': `Bearer ${token}`,
|
|
99
113
|
},
|
|
100
|
-
body: JSON.stringify({
|
|
114
|
+
body: JSON.stringify({
|
|
115
|
+
type: 'chat_logs',
|
|
116
|
+
items: [{ content: chatContent, file_path: `${today}.md` }],
|
|
117
|
+
}),
|
|
101
118
|
signal: AbortSignal.timeout(15000),
|
|
102
119
|
});
|
|
103
120
|
}
|
|
104
|
-
console.log('[SyncClient]
|
|
121
|
+
console.log('[SyncClient] 同步文件完成');
|
|
105
122
|
}
|
|
106
123
|
catch (err) {
|
|
107
|
-
console.error('[SyncClient]
|
|
124
|
+
console.error('[SyncClient] 同步文件失败:', err);
|
|
108
125
|
}
|
|
109
126
|
}
|
|
110
127
|
parsePreferences(markdown) {
|