mr-memory 2.9.9 → 2.9.11
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 +22 -12
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -15,17 +15,10 @@ 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
|
-
|
|
25
18
|
/** Wrap raw memory context in XML tags with a strong instruction */
|
|
26
19
|
/** Wrap API response in extraction markers so we can strip it next turn. */
|
|
27
20
|
function wrapForInjection(context: string): string {
|
|
28
|
-
return `<mr-memory>\n${
|
|
21
|
+
return `<mr-memory>\n${context}\n</mr-memory>`;
|
|
29
22
|
}
|
|
30
23
|
|
|
31
24
|
/** Strip previous memory injections from message text to prevent stacking.
|
|
@@ -229,7 +222,15 @@ const memoryRouterPlugin = {
|
|
|
229
222
|
}),
|
|
230
223
|
});
|
|
231
224
|
|
|
232
|
-
if (!res.ok)
|
|
225
|
+
if (!res.ok) {
|
|
226
|
+
const errBody = await res.json().catch(() => null) as any;
|
|
227
|
+
if (errBody?.error?.code === "payment_required") {
|
|
228
|
+
api.logger.warn?.(`⚠️ MemoryRouter: Out of credits. Memory is NOT being injected. Add credits at https://app.memoryrouter.ai/settings/billing`);
|
|
229
|
+
} else {
|
|
230
|
+
log(`memoryrouter: prepare failed (${res.status})`);
|
|
231
|
+
}
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
233
234
|
|
|
234
235
|
const data = (await res.json()) as {
|
|
235
236
|
context?: string;
|
|
@@ -330,7 +331,12 @@ const memoryRouterPlugin = {
|
|
|
330
331
|
});
|
|
331
332
|
|
|
332
333
|
if (!res.ok) {
|
|
333
|
-
|
|
334
|
+
const errBody = await res.json().catch(() => null) as any;
|
|
335
|
+
if (errBody?.error?.code === "payment_required") {
|
|
336
|
+
api.logger.warn?.(`⚠️ MemoryRouter: Out of credits. Memory is NOT being injected. Add credits at https://app.memoryrouter.ai/settings/billing`);
|
|
337
|
+
} else {
|
|
338
|
+
log(`memoryrouter: prepare failed (${res.status})`);
|
|
339
|
+
}
|
|
334
340
|
return;
|
|
335
341
|
}
|
|
336
342
|
|
|
@@ -428,8 +434,12 @@ const memoryRouterPlugin = {
|
|
|
428
434
|
});
|
|
429
435
|
if (!res.ok) {
|
|
430
436
|
const details = await res.text().catch(() => "");
|
|
431
|
-
|
|
432
|
-
|
|
437
|
+
if (details.includes("payment_required")) {
|
|
438
|
+
api.logger.warn?.(`⚠️ MemoryRouter: Out of credits. Conversations are NOT being stored. Add credits at https://app.memoryrouter.ai/settings/billing`);
|
|
439
|
+
} else {
|
|
440
|
+
const suffix = details ? ` — ${details.slice(0, 200)}` : "";
|
|
441
|
+
log(`memoryrouter: ingest failed (${res.status})${suffix}`);
|
|
442
|
+
}
|
|
433
443
|
} else {
|
|
434
444
|
api.logger.debug?.(`memoryrouter: ingest accepted (${toStore.length} messages)`);
|
|
435
445
|
}
|