@yulailai/openclaw-plugin-self-growth 3.1.20 → 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/sync-client.js +28 -11
- package/package.json +1 -1
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) {
|