mr-memory 3.7.2 → 3.7.3
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.js +40 -4
- package/index.ts +43 -4
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
*
|
|
8
8
|
* BYOK — provider API keys never touch MemoryRouter.
|
|
9
9
|
*/
|
|
10
|
-
import { readFile, lstat } from "node:fs/promises";
|
|
11
|
-
import { join, resolve, relative, isAbsolute, sep } from "node:path";
|
|
10
|
+
import { readFile, lstat, writeFile, copyFile, mkdir } from "node:fs/promises";
|
|
11
|
+
import { join, resolve, relative, isAbsolute, sep, dirname } from "node:path";
|
|
12
12
|
const DEFAULT_ENDPOINT = "https://api.memoryrouter.ai";
|
|
13
13
|
/** Strip media-attached references and OpenClaw media instruction text so
|
|
14
14
|
* old screenshots/photos/audio don't get stored and re-injected forever. */
|
|
@@ -267,13 +267,49 @@ const WORKSPACE_FILES = [
|
|
|
267
267
|
// ──────────────────────────────────────────────────────
|
|
268
268
|
// Helpers
|
|
269
269
|
// ──────────────────────────────────────────────────────
|
|
270
|
+
function openClawConfigPath() {
|
|
271
|
+
return process.env.OPENCLAW_CONFIG || join(os.homedir(), ".openclaw", "openclaw.json");
|
|
272
|
+
}
|
|
273
|
+
async function readOpenClawConfigFile() {
|
|
274
|
+
try {
|
|
275
|
+
return JSON.parse(await readFile(openClawConfigPath(), "utf8"));
|
|
276
|
+
}
|
|
277
|
+
catch (err) {
|
|
278
|
+
if (err?.code === "ENOENT")
|
|
279
|
+
return {};
|
|
280
|
+
throw err;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
async function writeOpenClawConfigFile(config) {
|
|
284
|
+
const configPath = openClawConfigPath();
|
|
285
|
+
await mkdir(dirname(configPath), { recursive: true });
|
|
286
|
+
try {
|
|
287
|
+
await copyFile(configPath, `${configPath}.bak`);
|
|
288
|
+
}
|
|
289
|
+
catch (err) {
|
|
290
|
+
if (err?.code !== "ENOENT")
|
|
291
|
+
throw err;
|
|
292
|
+
}
|
|
293
|
+
await writeFile(configPath, `${JSON.stringify(config, null, 2)}\n`, "utf8");
|
|
294
|
+
}
|
|
295
|
+
async function updateOpenClawPluginEntry(api, patch) {
|
|
296
|
+
const config = await readOpenClawConfigFile();
|
|
297
|
+
config.plugins ??= {};
|
|
298
|
+
config.plugins.entries ??= {};
|
|
299
|
+
config.plugins.entries[api.id] ??= {};
|
|
300
|
+
config.plugins.entries[api.id] = {
|
|
301
|
+
...config.plugins.entries[api.id],
|
|
302
|
+
...patch,
|
|
303
|
+
};
|
|
304
|
+
await writeOpenClawConfigFile(config);
|
|
305
|
+
}
|
|
270
306
|
async function setPluginConfig(api, config) {
|
|
271
307
|
const compat = api;
|
|
272
308
|
if (typeof compat.updatePluginConfig === "function") {
|
|
273
309
|
await compat.updatePluginConfig(config);
|
|
274
310
|
return;
|
|
275
311
|
}
|
|
276
|
-
|
|
312
|
+
await updateOpenClawPluginEntry(api, { config });
|
|
277
313
|
}
|
|
278
314
|
async function setPluginEnabled(api, enabled) {
|
|
279
315
|
const compat = api;
|
|
@@ -281,7 +317,7 @@ async function setPluginEnabled(api, enabled) {
|
|
|
281
317
|
await compat.updatePluginEnabled(enabled);
|
|
282
318
|
return;
|
|
283
319
|
}
|
|
284
|
-
|
|
320
|
+
await updateOpenClawPluginEntry(api, { enabled });
|
|
285
321
|
}
|
|
286
322
|
/**
|
|
287
323
|
* Read all workspace files and return as a single text blob for token counting.
|
package/index.ts
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
* BYOK — provider API keys never touch MemoryRouter.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import { readFile, readdir, stat, lstat } from "node:fs/promises";
|
|
12
|
-
import { join, resolve, relative, isAbsolute, sep } from "node:path";
|
|
11
|
+
import { readFile, readdir, stat, lstat, writeFile, copyFile, mkdir } from "node:fs/promises";
|
|
12
|
+
import { join, resolve, relative, isAbsolute, sep, dirname } from "node:path";
|
|
13
13
|
import path from "node:path";
|
|
14
14
|
import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
|
|
15
15
|
|
|
@@ -291,13 +291,52 @@ type CompatApi = OpenClawPluginApi & {
|
|
|
291
291
|
updatePluginEnabled?: (enabled: boolean) => Promise<void>;
|
|
292
292
|
};
|
|
293
293
|
|
|
294
|
+
type JsonObject = Record<string, any>;
|
|
295
|
+
|
|
296
|
+
function openClawConfigPath(): string {
|
|
297
|
+
return process.env.OPENCLAW_CONFIG || join(os.homedir(), ".openclaw", "openclaw.json");
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
async function readOpenClawConfigFile(): Promise<JsonObject> {
|
|
301
|
+
try {
|
|
302
|
+
return JSON.parse(await readFile(openClawConfigPath(), "utf8"));
|
|
303
|
+
} catch (err: any) {
|
|
304
|
+
if (err?.code === "ENOENT") return {};
|
|
305
|
+
throw err;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
async function writeOpenClawConfigFile(config: JsonObject): Promise<void> {
|
|
310
|
+
const configPath = openClawConfigPath();
|
|
311
|
+
await mkdir(dirname(configPath), { recursive: true });
|
|
312
|
+
try {
|
|
313
|
+
await copyFile(configPath, `${configPath}.bak`);
|
|
314
|
+
} catch (err: any) {
|
|
315
|
+
if (err?.code !== "ENOENT") throw err;
|
|
316
|
+
}
|
|
317
|
+
await writeFile(configPath, `${JSON.stringify(config, null, 2)}
|
|
318
|
+
`, "utf8");
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
async function updateOpenClawPluginEntry(api: OpenClawPluginApi, patch: JsonObject): Promise<void> {
|
|
322
|
+
const config = await readOpenClawConfigFile();
|
|
323
|
+
config.plugins ??= {};
|
|
324
|
+
config.plugins.entries ??= {};
|
|
325
|
+
config.plugins.entries[api.id] ??= {};
|
|
326
|
+
config.plugins.entries[api.id] = {
|
|
327
|
+
...config.plugins.entries[api.id],
|
|
328
|
+
...patch,
|
|
329
|
+
};
|
|
330
|
+
await writeOpenClawConfigFile(config);
|
|
331
|
+
}
|
|
332
|
+
|
|
294
333
|
async function setPluginConfig(api: OpenClawPluginApi, config: Record<string, unknown>): Promise<void> {
|
|
295
334
|
const compat = api as CompatApi;
|
|
296
335
|
if (typeof compat.updatePluginConfig === "function") {
|
|
297
336
|
await compat.updatePluginConfig(config);
|
|
298
337
|
return;
|
|
299
338
|
}
|
|
300
|
-
|
|
339
|
+
await updateOpenClawPluginEntry(api, { config });
|
|
301
340
|
}
|
|
302
341
|
|
|
303
342
|
async function setPluginEnabled(api: OpenClawPluginApi, enabled: boolean): Promise<void> {
|
|
@@ -306,7 +345,7 @@ async function setPluginEnabled(api: OpenClawPluginApi, enabled: boolean): Promi
|
|
|
306
345
|
await compat.updatePluginEnabled(enabled);
|
|
307
346
|
return;
|
|
308
347
|
}
|
|
309
|
-
|
|
348
|
+
await updateOpenClawPluginEntry(api, { enabled });
|
|
310
349
|
}
|
|
311
350
|
|
|
312
351
|
/**
|