@mingxy/cerebro 1.5.4 โ 1.5.6
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/package.json +1 -1
- package/src/hooks.ts +13 -1
- package/src/index.ts +1 -1
package/package.json
CHANGED
package/src/hooks.ts
CHANGED
|
@@ -353,6 +353,7 @@ export function sessionIdleHook(
|
|
|
353
353
|
tui: any,
|
|
354
354
|
sdkClient: any,
|
|
355
355
|
_ingestMode: "smart" | "raw" = "smart",
|
|
356
|
+
getMainSessionId?: () => string | undefined,
|
|
356
357
|
) {
|
|
357
358
|
let idleTimeout: ReturnType<typeof setTimeout> | null = null;
|
|
358
359
|
let isCapturing = false;
|
|
@@ -363,6 +364,11 @@ export function sessionIdleHook(
|
|
|
363
364
|
const sessionID = input.event.properties?.sessionID;
|
|
364
365
|
if (!sessionID) return;
|
|
365
366
|
|
|
367
|
+
if (getMainSessionId) {
|
|
368
|
+
const mainId = getMainSessionId();
|
|
369
|
+
if (mainId && sessionID !== mainId) return;
|
|
370
|
+
}
|
|
371
|
+
|
|
366
372
|
if (idleTimeout) clearTimeout(idleTimeout);
|
|
367
373
|
|
|
368
374
|
idleTimeout = setTimeout(async () => {
|
|
@@ -375,6 +381,7 @@ export function sessionIdleHook(
|
|
|
375
381
|
|
|
376
382
|
const messages = response.data;
|
|
377
383
|
const conversationMessages: Array<{ role: string; content: string }> = [];
|
|
384
|
+
const newMessageIds: string[] = [];
|
|
378
385
|
let hasNewMessages = false;
|
|
379
386
|
|
|
380
387
|
for (const msg of messages) {
|
|
@@ -391,7 +398,7 @@ export function sessionIdleHook(
|
|
|
391
398
|
if (!text) continue;
|
|
392
399
|
|
|
393
400
|
hasNewMessages = true;
|
|
394
|
-
|
|
401
|
+
newMessageIds.push(msgId);
|
|
395
402
|
conversationMessages.push({ role, content: text });
|
|
396
403
|
}
|
|
397
404
|
|
|
@@ -399,8 +406,13 @@ export function sessionIdleHook(
|
|
|
399
406
|
|
|
400
407
|
try {
|
|
401
408
|
await omemClient.sessionIngest(conversationMessages, sessionID);
|
|
409
|
+
// Only mark as processed after successful ingest to prevent message loss on server errors
|
|
410
|
+
for (const id of newMessageIds) {
|
|
411
|
+
processedMessageIds.add(id);
|
|
412
|
+
}
|
|
402
413
|
showToast(tui, "๐ง Memory Sealed", `${conversationMessages.length} dialogues captured ยท entrusted to the heavens for refinement`, "success");
|
|
403
414
|
} catch (err) {
|
|
415
|
+
// Do NOT mark as processed โ messages will be retried on next idle event
|
|
404
416
|
showToast(tui, "๐ด Session Capture Failed", String(err).substring(0, 100), "error");
|
|
405
417
|
}
|
|
406
418
|
} catch (err) {
|
package/src/index.ts
CHANGED
|
@@ -96,7 +96,7 @@ const OmemPlugin: Plugin = async (input) => {
|
|
|
96
96
|
"chat.message": keywordDetectionHook(omemClient, containerTags, config.autoCaptureThreshold, tui, config.ingestMode),
|
|
97
97
|
"experimental.session.compacting": compactingHook(omemClient, containerTags, tui, config.ingestMode),
|
|
98
98
|
tool: buildTools(omemClient, containerTags, { agentId, getSessionId: () => currentSessionId }),
|
|
99
|
-
event: sessionIdleHook(omemClient, containerTags, tui, client, config.ingestMode),
|
|
99
|
+
event: sessionIdleHook(omemClient, containerTags, tui, client, config.ingestMode, () => currentSessionId),
|
|
100
100
|
"shell.env": async (_input: any, output: any) => {
|
|
101
101
|
if (directory) {
|
|
102
102
|
output.env.OMEM_PROJECT_DIR = directory;
|