mr-memory 2.9.11 → 2.9.13
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 +21 -3
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -15,10 +15,27 @@ 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 and OpenClaw media instruction text so
|
|
19
|
+
* old screenshots/photos/audio don't get stored and re-injected forever. */
|
|
20
|
+
const MEDIA_ATTACHED_RE = /\[media attached[^\]]*\]/gi;
|
|
21
|
+
const MEDIA_TAGS_RE = /<media:(?:audio|image|video|document)>/gi;
|
|
22
|
+
const MEDIA_INSTRUCTION_RE = /To send an image back,[\s\S]*?Keep caption in the text body\./gi;
|
|
23
|
+
const MEDIA_INBOUND_PATH_RE = /\/Users\/[^\s]*\/media\/inbound\/[^\s)\]"]*/gi;
|
|
24
|
+
const IMAGE_DATA_RE = /\[image data removed[^\]]*\]/gi;
|
|
25
|
+
function stripMediaReferences(text: string): string {
|
|
26
|
+
return text
|
|
27
|
+
.replace(MEDIA_INSTRUCTION_RE, "")
|
|
28
|
+
.replace(MEDIA_ATTACHED_RE, "[media reference removed]")
|
|
29
|
+
.replace(MEDIA_TAGS_RE, "")
|
|
30
|
+
.replace(MEDIA_INBOUND_PATH_RE, "[media reference removed]")
|
|
31
|
+
.replace(IMAGE_DATA_RE, "")
|
|
32
|
+
.replace(/\n{3,}/g, "\n\n");
|
|
33
|
+
}
|
|
34
|
+
|
|
18
35
|
/** Wrap raw memory context in XML tags with a strong instruction */
|
|
19
36
|
/** Wrap API response in extraction markers so we can strip it next turn. */
|
|
20
37
|
function wrapForInjection(context: string): string {
|
|
21
|
-
return `<mr-memory>\n${context}\n</mr-memory>`;
|
|
38
|
+
return `<mr-memory>\n${stripMediaReferences(context)}\n</mr-memory>`;
|
|
22
39
|
}
|
|
23
40
|
|
|
24
41
|
/** Strip previous memory injections from message text to prevent stacking.
|
|
@@ -400,7 +417,7 @@ const memoryRouterPlugin = {
|
|
|
400
417
|
if (lastUserIdx >= 0) {
|
|
401
418
|
const userMsg = msgs[lastUserIdx] as { content?: unknown };
|
|
402
419
|
const userText = extractText(userMsg.content);
|
|
403
|
-
if (userText) toStore.push({ role: "user", content: userText });
|
|
420
|
+
if (userText) toStore.push({ role: "user", content: stripMediaReferences(userText) });
|
|
404
421
|
}
|
|
405
422
|
|
|
406
423
|
// Collect ALL assistant messages after the last user message
|
|
@@ -413,7 +430,8 @@ const memoryRouterPlugin = {
|
|
|
413
430
|
}
|
|
414
431
|
}
|
|
415
432
|
if (assistantParts.length > 0) {
|
|
416
|
-
|
|
433
|
+
// Strip media refs so image paths don't get stored and re-injected
|
|
434
|
+
toStore.push({ role: "assistant", content: stripMediaReferences(assistantParts.join("\n\n")) });
|
|
417
435
|
}
|
|
418
436
|
|
|
419
437
|
if (toStore.length === 0) return;
|