mr-memory 1.0.9 → 1.0.10

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.
Files changed (2) hide show
  1. package/index.ts +54 -35
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -9,46 +9,14 @@
9
9
  */
10
10
 
11
11
  import { spawn } from "node:child_process";
12
+ import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
12
13
 
13
14
  const DEFAULT_ENDPOINT = "https://api.memoryrouter.ai";
14
15
 
15
- /**
16
- * Minimal type surface for the OpenClaw plugin host API.
17
- * Defined locally so this plugin compiles standalone without an
18
- * `openclaw` dev-dependency — the real object is injected at runtime.
19
- */
20
- interface CliCommand {
21
- command(name: string): CliCommand;
22
- description(desc: string): CliCommand;
23
- argument(flags: string, desc?: string): CliCommand;
24
- option(flags: string, desc?: string): CliCommand;
25
- action(fn: (...args: never[]) => unknown): CliCommand;
26
- help(): void;
27
- }
28
-
29
- type OpenClawPluginApi = {
30
- id: string;
31
- config: Record<string, unknown> & {
32
- workspace?: string;
33
- agents?: { defaults?: { workspace?: string } };
34
- };
35
- pluginConfig: unknown;
36
- logger: { info?: (...args: unknown[]) => void };
37
- registerStreamFnWrapper: (
38
- wrapper: (
39
- next: (model: Record<string, unknown>, context: unknown, options?: Record<string, unknown>) => unknown,
40
- ) => (model: Record<string, unknown>, context: unknown, options?: Record<string, unknown>) => unknown,
41
- ) => void;
42
- registerCli: (
43
- setup: (ctx: { program: CliCommand }) => void,
44
- opts?: { commands?: string[] },
45
- ) => void;
46
- registerService: (svc: { id: string; start: () => void; stop: () => void }) => void;
47
- };
48
-
49
16
  type MemoryRouterConfig = {
50
17
  key: string;
51
18
  endpoint?: string;
19
+ density?: 'low' | 'high' | 'xhigh';
52
20
  };
53
21
 
54
22
  type CompatApi = OpenClawPluginApi & {
@@ -168,6 +136,7 @@ const memoryRouterPlugin = {
168
136
  const cfg = api.pluginConfig as MemoryRouterConfig | undefined;
169
137
  const endpoint = cfg?.endpoint?.replace(/\/v1\/?$/, "") || DEFAULT_ENDPOINT;
170
138
  const memoryKey = cfg?.key;
139
+ const density = cfg?.density || 'high';
171
140
 
172
141
  // ==================================================================
173
142
  // Core: Route LLM calls through MemoryRouter (only when key is set)
@@ -207,6 +176,7 @@ const memoryRouterPlugin = {
207
176
  ...options?.headers,
208
177
  "X-Memory-Key": memoryKey,
209
178
  "X-Memory-Store": toolIteration ? "false" : "true",
179
+ "X-Memory-Density": density,
210
180
  },
211
181
  };
212
182
 
@@ -273,6 +243,54 @@ const memoryRouterPlugin = {
273
243
  }
274
244
  });
275
245
 
246
+ // Density commands
247
+ mr.command("xhigh")
248
+ .description("Set memory density to xhigh (160 results, ~50k tokens)")
249
+ .action(async () => {
250
+ if (!memoryKey) {
251
+ console.error("MemoryRouter not configured. Run: openclaw mr <key>");
252
+ return;
253
+ }
254
+ try {
255
+ await setPluginConfig(api, { key: memoryKey, endpoint: cfg?.endpoint, density: 'xhigh' });
256
+ console.log("✓ Memory density set to xhigh (160 results, ~50k tokens)");
257
+ console.log(" Maximum context injection for deepest memory.");
258
+ } catch (err) {
259
+ console.error(`Failed to set density: ${err instanceof Error ? err.message : String(err)}`);
260
+ }
261
+ });
262
+
263
+ mr.command("high")
264
+ .description("Set memory density to high (80 results, ~24k tokens) [default]")
265
+ .action(async () => {
266
+ if (!memoryKey) {
267
+ console.error("MemoryRouter not configured. Run: openclaw mr <key>");
268
+ return;
269
+ }
270
+ try {
271
+ await setPluginConfig(api, { key: memoryKey, endpoint: cfg?.endpoint, density: 'high' });
272
+ console.log("✓ Memory density set to high (80 results, ~24k tokens)");
273
+ } catch (err) {
274
+ console.error(`Failed to set density: ${err instanceof Error ? err.message : String(err)}`);
275
+ }
276
+ });
277
+
278
+ mr.command("low")
279
+ .description("Set memory density to low (40 results, ~12k tokens)")
280
+ .action(async () => {
281
+ if (!memoryKey) {
282
+ console.error("MemoryRouter not configured. Run: openclaw mr <key>");
283
+ return;
284
+ }
285
+ try {
286
+ await setPluginConfig(api, { key: memoryKey, endpoint: cfg?.endpoint, density: 'low' });
287
+ console.log("✓ Memory density set to low (40 results, ~12k tokens)");
288
+ console.log(" Lighter context for faster responses or smaller models.");
289
+ } catch (err) {
290
+ console.error(`Failed to set density: ${err instanceof Error ? err.message : String(err)}`);
291
+ }
292
+ });
293
+
276
294
  mr.command("status")
277
295
  .description("Show MemoryRouter vault stats")
278
296
  .option("--json", "JSON output")
@@ -288,12 +306,13 @@ const memoryRouterPlugin = {
288
306
  const data = await res.json() as Record<string, unknown>;
289
307
 
290
308
  if (opts.json) {
291
- console.log(JSON.stringify({ enabled: true, key: memoryKey, stats: data }, null, 2));
309
+ console.log(JSON.stringify({ enabled: true, key: memoryKey, density, stats: data }, null, 2));
292
310
  } else {
293
311
  console.log("MemoryRouter Status");
294
312
  console.log("───────────────────────────");
295
313
  console.log(`Enabled: ✓ Yes`);
296
314
  console.log(`Key: ${memoryKey.slice(0, 6)}...${memoryKey.slice(-3)}`);
315
+ console.log(`Density: ${density} (openclaw mr xhigh|high|low)`);
297
316
  console.log(`Endpoint: ${endpoint}`);
298
317
  console.log("");
299
318
  console.log("Vault Stats:");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mr-memory",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "MemoryRouter persistent memory plugin for OpenClaw — your AI remembers every conversation",
5
5
  "type": "module",
6
6
  "files": [