@mingxy/cerebro 1.5.0 โ 1.5.2
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/client.ts +2 -2
- package/src/hooks.ts +10 -38
- package/src/index.ts +1 -2
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -361,12 +361,12 @@ export class OmemClient {
|
|
|
361
361
|
}
|
|
362
362
|
|
|
363
363
|
async sessionIngest(
|
|
364
|
-
|
|
364
|
+
messages: Array<{ role: string; content: string }>,
|
|
365
365
|
sessionId?: string,
|
|
366
366
|
agentId?: string,
|
|
367
367
|
): Promise<unknown> {
|
|
368
368
|
return this.post("/v1/memories/session-ingest", {
|
|
369
|
-
|
|
369
|
+
messages,
|
|
370
370
|
session_id: sessionId,
|
|
371
371
|
agent_id: agentId,
|
|
372
372
|
});
|
package/src/hooks.ts
CHANGED
|
@@ -152,6 +152,8 @@ export function autoRecallHook(client: OmemClient, containerTags: string[], tui:
|
|
|
152
152
|
const query_text = userMessages[userMessages.length - 1]?.content || firstMessages.get(input.sessionID) || "";
|
|
153
153
|
const last_query_text = userMessages.length >= 2 ? userMessages[userMessages.length - 2].content : undefined;
|
|
154
154
|
|
|
155
|
+
if (!query_text.trim()) return;
|
|
156
|
+
|
|
155
157
|
const projectTags = containerTags.filter(t => t.startsWith("omem_project_"));
|
|
156
158
|
const shouldRecallRes = await client.shouldRecall(query_text, last_query_text, input.sessionID, similarityThreshold, maxRecallResults, projectTags.length > 0 ? projectTags : undefined);
|
|
157
159
|
|
|
@@ -347,10 +349,10 @@ const processedMessageIds = new Set<string>();
|
|
|
347
349
|
|
|
348
350
|
export function sessionIdleHook(
|
|
349
351
|
omemClient: OmemClient,
|
|
350
|
-
|
|
352
|
+
_containerTags: string[],
|
|
351
353
|
tui: any,
|
|
352
354
|
sdkClient: any,
|
|
353
|
-
|
|
355
|
+
_ingestMode: "smart" | "raw" = "smart",
|
|
354
356
|
) {
|
|
355
357
|
let idleTimeout: ReturnType<typeof setTimeout> | null = null;
|
|
356
358
|
let isCapturing = false;
|
|
@@ -373,7 +375,6 @@ export function sessionIdleHook(
|
|
|
373
375
|
|
|
374
376
|
const messages = response.data;
|
|
375
377
|
const conversationMessages: Array<{ role: string; content: string }> = [];
|
|
376
|
-
const dcpSummaries: Array<{ topic: string; content: string }> = [];
|
|
377
378
|
let hasNewMessages = false;
|
|
378
379
|
|
|
379
380
|
for (const msg of messages) {
|
|
@@ -391,45 +392,16 @@ export function sessionIdleHook(
|
|
|
391
392
|
|
|
392
393
|
hasNewMessages = true;
|
|
393
394
|
processedMessageIds.add(msgId);
|
|
394
|
-
|
|
395
|
-
if (text.includes("[Compressed conversation section]")) {
|
|
396
|
-
const blockRegex = /\[Compressed conversation section\]\n([\s\S]*?)(?=<dcp-block|$)/g;
|
|
397
|
-
let match;
|
|
398
|
-
while ((match = blockRegex.exec(text)) !== null) {
|
|
399
|
-
const summary = match[1].trim();
|
|
400
|
-
if (summary) {
|
|
401
|
-
dcpSummaries.push({ topic: "session-compress", content: summary });
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
|
|
406
395
|
conversationMessages.push({ role, content: text });
|
|
407
396
|
}
|
|
408
397
|
|
|
409
|
-
if (!hasNewMessages) return;
|
|
398
|
+
if (!hasNewMessages || conversationMessages.length === 0) return;
|
|
410
399
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
showToast(tui, "๐ด DCP Capture Failed", String(err).substring(0, 100), "error");
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
if (conversationMessages.length > 0) {
|
|
421
|
-
try {
|
|
422
|
-
const result = await omemClient.ingestMessages(conversationMessages, {
|
|
423
|
-
mode: ingestMode,
|
|
424
|
-
tags: [...containerTags, "session-idle"],
|
|
425
|
-
sessionId: sessionID,
|
|
426
|
-
});
|
|
427
|
-
if (result) {
|
|
428
|
-
showToast(tui, "๐ง Session Captured", `${conversationMessages.length} messages captured via session.idle`, "success");
|
|
429
|
-
}
|
|
430
|
-
} catch (err) {
|
|
431
|
-
showToast(tui, "๐ด Session Capture Failed", String(err).substring(0, 100), "error");
|
|
432
|
-
}
|
|
400
|
+
try {
|
|
401
|
+
await omemClient.sessionIngest(conversationMessages, sessionID);
|
|
402
|
+
showToast(tui, "๐ง Memory Sealed", `${conversationMessages.length} dialogues captured ยท entrusted to the heavens for refinement`, "success");
|
|
403
|
+
} catch (err) {
|
|
404
|
+
showToast(tui, "๐ด Session Capture Failed", String(err).substring(0, 100), "error");
|
|
433
405
|
}
|
|
434
406
|
} catch (err) {
|
|
435
407
|
const errMsg = err instanceof Error ? err.message : String(err);
|
package/src/index.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { readFileSync } from "node:fs";
|
|
|
3
3
|
import { join, dirname } from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import { OmemClient } from "./client.js";
|
|
6
|
-
import { autoRecallHook, compactingHook,
|
|
6
|
+
import { autoRecallHook, compactingHook, sessionIdleHook } from "./hooks.js";
|
|
7
7
|
import { getUserTag, getProjectTag } from "./tags.js";
|
|
8
8
|
import { buildTools } from "./tools.js";
|
|
9
9
|
import { logInfo, logError } from "./logger.js";
|
|
@@ -93,7 +93,6 @@ const OmemPlugin: Plugin = async (input) => {
|
|
|
93
93
|
if (input.sessionID) currentSessionId = input.sessionID;
|
|
94
94
|
return recallHook(input, output);
|
|
95
95
|
},
|
|
96
|
-
"chat.message": keywordDetectionHook(omemClient, containerTags, config.autoCaptureThreshold, tui, config.ingestMode),
|
|
97
96
|
"experimental.session.compacting": compactingHook(omemClient, containerTags, tui, config.ingestMode),
|
|
98
97
|
tool: buildTools(omemClient, containerTags, { agentId, getSessionId: () => currentSessionId }),
|
|
99
98
|
event: sessionIdleHook(omemClient, containerTags, tui, client, config.ingestMode),
|