xiaozuoassistant 0.1.70 → 0.1.71
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.
|
@@ -14,11 +14,13 @@ function normalizeWorkspace(input) {
|
|
|
14
14
|
}
|
|
15
15
|
export class ShortTermMemory {
|
|
16
16
|
constructor() {
|
|
17
|
+
this.instanceId = Math.random().toString(36).substring(7);
|
|
17
18
|
// 主存:所有 Session Meta 数据
|
|
18
19
|
this.sessions = new Map();
|
|
19
20
|
this.initPromise = null;
|
|
20
21
|
// 持久化队列,确保串行写入 index.json
|
|
21
22
|
this.saveQueue = Promise.resolve();
|
|
23
|
+
console.log(`[ShortTermMemory] Instance created: ${this.instanceId}`);
|
|
22
24
|
fs.ensureDirSync(SESSIONS_DIR);
|
|
23
25
|
}
|
|
24
26
|
static getInstance() {
|
|
@@ -146,7 +148,7 @@ export class ShortTermMemory {
|
|
|
146
148
|
async createSession(input) {
|
|
147
149
|
await this.ensureReady();
|
|
148
150
|
const id = uuidv4();
|
|
149
|
-
console.log(`[ShortTermMemory] Creating session: ${id}`);
|
|
151
|
+
console.log(`[ShortTermMemory:${this.instanceId}] Creating session: ${id}`);
|
|
150
152
|
const now = Date.now();
|
|
151
153
|
const meta = {
|
|
152
154
|
id,
|
|
@@ -179,9 +181,17 @@ export class ShortTermMemory {
|
|
|
179
181
|
}
|
|
180
182
|
async getSessionMeta(id) {
|
|
181
183
|
await this.ensureReady();
|
|
182
|
-
|
|
184
|
+
let meta = this.sessions.get(id) || null;
|
|
185
|
+
// 如果内存中没有,尝试重新加载磁盘(可能是其他进程创建的)
|
|
183
186
|
if (!meta) {
|
|
184
|
-
console.log(`[ShortTermMemory]
|
|
187
|
+
console.log(`[ShortTermMemory:${this.instanceId}] Cache miss for ${id}, reloading from disk...`);
|
|
188
|
+
await this.loadSessionsFromDisk();
|
|
189
|
+
meta = this.sessions.get(id) || null;
|
|
190
|
+
}
|
|
191
|
+
if (!meta) {
|
|
192
|
+
console.log(`[ShortTermMemory:${this.instanceId}] Session not found in memory after reload: ${id}. Total sessions: ${this.sessions.size}`);
|
|
193
|
+
// Log all available IDs for debugging
|
|
194
|
+
// console.log(`[ShortTermMemory:${this.instanceId}] Available IDs: ${Array.from(this.sessions.keys()).join(', ')}`);
|
|
185
195
|
}
|
|
186
196
|
return meta;
|
|
187
197
|
}
|
package/package.json
CHANGED