xiaozuoassistant 0.1.70 → 0.1.72

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
- const meta = this.sessions.get(id) || null;
184
+ let meta = this.sessions.get(id) || null;
185
+ // 如果内存中没有,尝试重新加载磁盘(可能是其他进程创建的)
183
186
  if (!meta) {
184
- console.log(`[ShortTermMemory] Session not found in memory: ${id}`);
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
  }
@@ -276,6 +286,11 @@ export class ShortTermMemory {
276
286
  }
277
287
  async createRun(sessionId, userContent, runId) {
278
288
  await this.ensureReady();
289
+ // Check if session exists, try reload if not
290
+ if (!this.sessions.has(sessionId)) {
291
+ console.log(`[ShortTermMemory:${this.instanceId}] Session ${sessionId} not found for createRun, reloading...`);
292
+ await this.loadSessionsFromDisk();
293
+ }
279
294
  if (!this.sessions.has(sessionId))
280
295
  throw new Error('Session not found');
281
296
  const now = Date.now();
@@ -345,9 +360,17 @@ export class ShortTermMemory {
345
360
  }
346
361
  async addMessage(sessionId, message) {
347
362
  await this.ensureReady();
348
- const sessionMeta = this.sessions.get(sessionId);
349
- if (!sessionMeta)
363
+ let sessionMeta = this.sessions.get(sessionId);
364
+ // 如果内存中没有,尝试重载
365
+ if (!sessionMeta) {
366
+ console.log(`[ShortTermMemory:${this.instanceId}] Session ${sessionId} not found in memory for addMessage, reloading...`);
367
+ await this.loadSessionsFromDisk();
368
+ sessionMeta = this.sessions.get(sessionId);
369
+ }
370
+ if (!sessionMeta) {
371
+ console.error(`[ShortTermMemory:${this.instanceId}] Session ${sessionId} not found even after reload.`);
350
372
  throw new Error(`Session ${sessionId} not found`);
373
+ }
351
374
  const msg = { ...message };
352
375
  if (!msg.timestamp)
353
376
  msg.timestamp = Date.now();
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "xiaozuoassistant",
3
3
  "private": false,
4
4
  "description": "Your personal, locally-hosted AI assistant for office productivity.",
5
- "version": "0.1.70",
5
+ "version": "0.1.72",
6
6
  "author": "mantle.lau",
7
7
  "license": "MIT",
8
8
  "repository": {