mr-memory 2.7.0 → 2.9.0
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 +37 -11
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -42,6 +42,7 @@ type MemoryRouterConfig = {
|
|
|
42
42
|
endpoint?: string;
|
|
43
43
|
density?: "low" | "high" | "xhigh";
|
|
44
44
|
mode?: "relay" | "proxy";
|
|
45
|
+
logging?: boolean;
|
|
45
46
|
};
|
|
46
47
|
|
|
47
48
|
// ──────────────────────────────────────────────────────
|
|
@@ -149,6 +150,8 @@ const memoryRouterPlugin = {
|
|
|
149
150
|
const memoryKey = cfg?.key;
|
|
150
151
|
const density = cfg?.density || "high";
|
|
151
152
|
const mode = cfg?.mode || "relay";
|
|
153
|
+
const logging = cfg?.logging ?? false;
|
|
154
|
+
const log = (msg: string) => { if (logging) api.logger.info?.(msg); };
|
|
152
155
|
|
|
153
156
|
if (memoryKey) {
|
|
154
157
|
api.logger.info?.(`memoryrouter: active (key: ${memoryKey.slice(0, 6)}..., mode: ${mode})`);
|
|
@@ -171,7 +174,7 @@ const memoryRouterPlugin = {
|
|
|
171
174
|
// When PR #24122 merges, OpenClaw will use the returned prependContext.
|
|
172
175
|
// This gives forward compatibility — no plugin update needed.
|
|
173
176
|
api.on("llm_input", async (event, ctx) => {
|
|
174
|
-
|
|
177
|
+
log(`memoryrouter: llm_input fired (sessionKey=${ctx.sessionKey}, promptBuildFired=${promptBuildFiredThisRun})`);
|
|
175
178
|
// Skip the first call — before_prompt_build already handled it
|
|
176
179
|
// (before_prompt_build includes workspace+tools+skills for accurate billing)
|
|
177
180
|
if (promptBuildFiredThisRun) {
|
|
@@ -228,8 +231,8 @@ const memoryRouterPlugin = {
|
|
|
228
231
|
};
|
|
229
232
|
|
|
230
233
|
if (data.context) {
|
|
231
|
-
|
|
232
|
-
`memoryrouter: injected ${data.memories_found || 0} memories on tool iteration (${data.tokens_billed || 0} tokens
|
|
234
|
+
log(
|
|
235
|
+
`memoryrouter: injected ${data.memories_found || 0} memories on tool iteration (${data.tokens_billed || 0} tokens)`,
|
|
233
236
|
);
|
|
234
237
|
return { prependContext: wrapForInjection(data.context) };
|
|
235
238
|
}
|
|
@@ -241,7 +244,7 @@ const memoryRouterPlugin = {
|
|
|
241
244
|
// ── before_prompt_build: fires once per run (primary, includes full billing context)
|
|
242
245
|
api.on("before_prompt_build", async (event, ctx) => {
|
|
243
246
|
promptBuildFiredThisRun = true;
|
|
244
|
-
|
|
247
|
+
log(`memoryrouter: before_prompt_build fired (sessionKey=${ctx.sessionKey}, promptLen=${event.prompt?.length})`);
|
|
245
248
|
try {
|
|
246
249
|
const prompt = event.prompt;
|
|
247
250
|
|
|
@@ -318,7 +321,7 @@ const memoryRouterPlugin = {
|
|
|
318
321
|
});
|
|
319
322
|
|
|
320
323
|
if (!res.ok) {
|
|
321
|
-
|
|
324
|
+
log(`memoryrouter: prepare failed (${res.status})`);
|
|
322
325
|
return;
|
|
323
326
|
}
|
|
324
327
|
|
|
@@ -329,13 +332,13 @@ const memoryRouterPlugin = {
|
|
|
329
332
|
};
|
|
330
333
|
|
|
331
334
|
if (data.context) {
|
|
332
|
-
|
|
333
|
-
`memoryrouter: injected ${data.memories_found || 0} memories (${data.tokens_billed || 0} tokens
|
|
335
|
+
log(
|
|
336
|
+
`memoryrouter: injected ${data.memories_found || 0} memories (${data.tokens_billed || 0} tokens)`,
|
|
334
337
|
);
|
|
335
338
|
return { prependContext: wrapForInjection(data.context) };
|
|
336
339
|
}
|
|
337
340
|
} catch (err) {
|
|
338
|
-
|
|
341
|
+
log(
|
|
339
342
|
`memoryrouter: prepare error — ${err instanceof Error ? err.message : String(err)}`,
|
|
340
343
|
);
|
|
341
344
|
}
|
|
@@ -415,17 +418,17 @@ const memoryRouterPlugin = {
|
|
|
415
418
|
if (!res.ok) {
|
|
416
419
|
const details = await res.text().catch(() => "");
|
|
417
420
|
const suffix = details ? ` — ${details.slice(0, 200)}` : "";
|
|
418
|
-
|
|
421
|
+
log(`memoryrouter: ingest failed (${res.status})${suffix}`);
|
|
419
422
|
} else {
|
|
420
423
|
api.logger.debug?.(`memoryrouter: ingest accepted (${toStore.length} messages)`);
|
|
421
424
|
}
|
|
422
425
|
} catch (err) {
|
|
423
|
-
|
|
426
|
+
log(
|
|
424
427
|
`memoryrouter: ingest error — ${err instanceof Error ? err.message : String(err)}`,
|
|
425
428
|
);
|
|
426
429
|
}
|
|
427
430
|
} catch (err) {
|
|
428
|
-
|
|
431
|
+
log(
|
|
429
432
|
`memoryrouter: agent_end error — ${err instanceof Error ? err.message : String(err)}`,
|
|
430
433
|
);
|
|
431
434
|
}
|
|
@@ -499,6 +502,29 @@ const memoryRouterPlugin = {
|
|
|
499
502
|
});
|
|
500
503
|
}
|
|
501
504
|
|
|
505
|
+
// Logging toggle
|
|
506
|
+
mr.command("logging")
|
|
507
|
+
.description("Toggle debug logging on/off")
|
|
508
|
+
.action(async () => {
|
|
509
|
+
if (!memoryKey) {
|
|
510
|
+
console.error("Not configured. Run: openclaw mr <key>");
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
const newLogging = !logging;
|
|
514
|
+
try {
|
|
515
|
+
await setPluginConfig(api, {
|
|
516
|
+
key: memoryKey,
|
|
517
|
+
endpoint: cfg?.endpoint,
|
|
518
|
+
density,
|
|
519
|
+
mode,
|
|
520
|
+
logging: newLogging,
|
|
521
|
+
});
|
|
522
|
+
console.log(`✓ Logging ${newLogging ? "ON" : "OFF"} (restart gateway to apply)`);
|
|
523
|
+
} catch (err) {
|
|
524
|
+
console.error(`Failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
525
|
+
}
|
|
526
|
+
});
|
|
527
|
+
|
|
502
528
|
// Mode commands
|
|
503
529
|
for (const [modeName, modeDesc] of [
|
|
504
530
|
["relay", "Relay mode — hooks only, works on stock OpenClaw [default]"],
|