|
|
@@ -46,7 +46,7 @@ function loadPluginCfg() {
|
|
|
recentKeep: Number(
|
|
|
process.env.MEM0_RECENT_KEEP || fileCfg.recentKeep || 5
|
|
|
),
|
|
|
- // Knowledge-base settings
|
|
|
+ // Knowledge-base settings (tool-only; hook no longer injects knowledge)
|
|
|
knowledgeUserId:
|
|
|
process.env.MEM0_KNOWLEDGE_USER_ID ||
|
|
|
(fileCfg.knowledgeUserId as string) ||
|
|
|
@@ -182,7 +182,11 @@ function readLastAssistantMessage(sessionKey?: string): string | undefined {
|
|
|
) {
|
|
|
continue;
|
|
|
}
|
|
|
- const assistantText = entry?.messages?.[1]?.content;
|
|
|
+ const candidate = entry?.messages?.[1];
|
|
|
+ if (candidate?.role && candidate.role !== "assistant") {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ const assistantText = candidate?.content;
|
|
|
if (typeof assistantText === "string" && assistantText.trim()) {
|
|
|
return assistantText.trim();
|
|
|
}
|
|
|
@@ -196,7 +200,11 @@ function readLastAssistantMessage(sessionKey?: string): string | undefined {
|
|
|
for (let i = lines.length - 1; i >= 0; i--) {
|
|
|
try {
|
|
|
const entry = JSON.parse(lines[i]);
|
|
|
- const assistantText = entry?.messages?.[1]?.content;
|
|
|
+ const candidate = entry?.messages?.[1];
|
|
|
+ if (candidate?.role && candidate.role !== "assistant") {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ const assistantText = candidate?.content;
|
|
|
if (typeof assistantText === "string" && assistantText.trim()) {
|
|
|
console.warn(
|
|
|
"[mem0-auto-capture] assistant lookup fallback to global latest",
|
|
|
@@ -470,32 +478,26 @@ export default async function handler(event: HookEvent) {
|
|
|
const runAutoRecall = async (text: string) => {
|
|
|
if (!pluginCfg.autoRecall) return;
|
|
|
|
|
|
- const {
|
|
|
- baseUrl,
|
|
|
- knowledgeUserId,
|
|
|
- recallLimit,
|
|
|
- knowledgeLimit,
|
|
|
- rerankThreshold,
|
|
|
- } = pluginCfg;
|
|
|
+ const { baseUrl, recallLimit, rerankThreshold } = pluginCfg;
|
|
|
|
|
|
console.log("[mem0-auto-recall] query:", text.slice(0, 120));
|
|
|
|
|
|
- // Fire both searches in parallel — neither blocks the other
|
|
|
- const [personalResults, knowledgeResults] = await Promise.all([
|
|
|
- mem0SearchMemories(baseUrl, userId, text, recallLimit),
|
|
|
- mem0SearchKnowledge(baseUrl, knowledgeUserId, text, knowledgeLimit),
|
|
|
- ]);
|
|
|
+ const personalResults = await mem0SearchMemories(
|
|
|
+ baseUrl,
|
|
|
+ userId,
|
|
|
+ text,
|
|
|
+ recallLimit
|
|
|
+ );
|
|
|
|
|
|
console.log("[mem0-auto-recall]", {
|
|
|
userId,
|
|
|
personalCount: personalResults?.length ?? "error",
|
|
|
- knowledgeCount: knowledgeResults?.length ?? "error",
|
|
|
threshold: rerankThreshold,
|
|
|
});
|
|
|
|
|
|
const injectionBlock = buildInjectionBlock(
|
|
|
personalResults,
|
|
|
- knowledgeResults,
|
|
|
+ null,
|
|
|
rerankThreshold
|
|
|
);
|
|
|
|