mr-memory 2.9.11 → 2.9.12
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/index.ts +11 -3
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -15,10 +15,17 @@ import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
|
|
|
15
15
|
|
|
16
16
|
const DEFAULT_ENDPOINT = "https://api.memoryrouter.ai";
|
|
17
17
|
|
|
18
|
+
/** Strip media-attached references so OpenClaw's image detection doesn't
|
|
19
|
+
* load old screenshots/photos from file paths embedded in memories. */
|
|
20
|
+
const MEDIA_ATTACHED_RE = /\[media attached:\s*[^\]]*\]/gi;
|
|
21
|
+
function stripMediaReferences(text: string): string {
|
|
22
|
+
return text.replace(MEDIA_ATTACHED_RE, "[media reference removed]");
|
|
23
|
+
}
|
|
24
|
+
|
|
18
25
|
/** Wrap raw memory context in XML tags with a strong instruction */
|
|
19
26
|
/** Wrap API response in extraction markers so we can strip it next turn. */
|
|
20
27
|
function wrapForInjection(context: string): string {
|
|
21
|
-
return `<mr-memory>\n${context}\n</mr-memory>`;
|
|
28
|
+
return `<mr-memory>\n${stripMediaReferences(context)}\n</mr-memory>`;
|
|
22
29
|
}
|
|
23
30
|
|
|
24
31
|
/** Strip previous memory injections from message text to prevent stacking.
|
|
@@ -400,7 +407,7 @@ const memoryRouterPlugin = {
|
|
|
400
407
|
if (lastUserIdx >= 0) {
|
|
401
408
|
const userMsg = msgs[lastUserIdx] as { content?: unknown };
|
|
402
409
|
const userText = extractText(userMsg.content);
|
|
403
|
-
if (userText) toStore.push({ role: "user", content: userText });
|
|
410
|
+
if (userText) toStore.push({ role: "user", content: stripMediaReferences(userText) });
|
|
404
411
|
}
|
|
405
412
|
|
|
406
413
|
// Collect ALL assistant messages after the last user message
|
|
@@ -413,7 +420,8 @@ const memoryRouterPlugin = {
|
|
|
413
420
|
}
|
|
414
421
|
}
|
|
415
422
|
if (assistantParts.length > 0) {
|
|
416
|
-
|
|
423
|
+
// Strip media refs so image paths don't get stored and re-injected
|
|
424
|
+
toStore.push({ role: "assistant", content: stripMediaReferences(assistantParts.join("\n\n")) });
|
|
417
425
|
}
|
|
418
426
|
|
|
419
427
|
if (toStore.length === 0) return;
|