@memtensor/memos-local-openclaw-plugin 1.0.2 → 1.0.4-beta.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/README.md +38 -21
- package/dist/client/connector.d.ts +26 -0
- package/dist/client/connector.d.ts.map +1 -0
- package/dist/client/connector.js +127 -0
- package/dist/client/connector.js.map +1 -0
- package/dist/client/hub.d.ts +61 -0
- package/dist/client/hub.d.ts.map +1 -0
- package/dist/client/hub.js +148 -0
- package/dist/client/hub.js.map +1 -0
- package/dist/client/skill-sync.d.ts +29 -0
- package/dist/client/skill-sync.d.ts.map +1 -0
- package/dist/client/skill-sync.js +216 -0
- package/dist/client/skill-sync.js.map +1 -0
- package/dist/config.d.ts +2 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +70 -3
- package/dist/config.js.map +1 -1
- package/dist/embedding/index.d.ts +4 -2
- package/dist/embedding/index.d.ts.map +1 -1
- package/dist/embedding/index.js +21 -4
- package/dist/embedding/index.js.map +1 -1
- package/dist/hub/auth.d.ts +19 -0
- package/dist/hub/auth.d.ts.map +1 -0
- package/dist/hub/auth.js +70 -0
- package/dist/hub/auth.js.map +1 -0
- package/dist/hub/server.d.ts +41 -0
- package/dist/hub/server.d.ts.map +1 -0
- package/dist/hub/server.js +742 -0
- package/dist/hub/server.js.map +1 -0
- package/dist/hub/user-manager.d.ts +28 -0
- package/dist/hub/user-manager.d.ts.map +1 -0
- package/dist/hub/user-manager.js +112 -0
- package/dist/hub/user-manager.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/ingest/providers/index.d.ts +10 -2
- package/dist/ingest/providers/index.d.ts.map +1 -1
- package/dist/ingest/providers/index.js +242 -8
- package/dist/ingest/providers/index.js.map +1 -1
- package/dist/ingest/providers/openai.d.ts +1 -0
- package/dist/ingest/providers/openai.d.ts.map +1 -1
- package/dist/ingest/providers/openai.js +1 -0
- package/dist/ingest/providers/openai.js.map +1 -1
- package/dist/ingest/task-processor.js +1 -1
- package/dist/ingest/task-processor.js.map +1 -1
- package/dist/openclaw-api.d.ts +53 -0
- package/dist/openclaw-api.d.ts.map +1 -0
- package/dist/openclaw-api.js +189 -0
- package/dist/openclaw-api.js.map +1 -0
- package/dist/recall/engine.js +2 -2
- package/dist/recall/engine.js.map +1 -1
- package/dist/shared/llm-call.d.ts +4 -1
- package/dist/shared/llm-call.d.ts.map +1 -1
- package/dist/shared/llm-call.js +15 -0
- package/dist/shared/llm-call.js.map +1 -1
- package/dist/sharing/types.contract.d.ts +2 -0
- package/dist/sharing/types.contract.d.ts.map +1 -0
- package/dist/sharing/types.contract.js +3 -0
- package/dist/sharing/types.contract.js.map +1 -0
- package/dist/sharing/types.d.ts +80 -0
- package/dist/sharing/types.d.ts.map +1 -0
- package/dist/sharing/types.js +3 -0
- package/dist/sharing/types.js.map +1 -0
- package/dist/skill/evaluator.d.ts.map +1 -1
- package/dist/skill/evaluator.js +2 -2
- package/dist/skill/evaluator.js.map +1 -1
- package/dist/skill/generator.d.ts.map +1 -1
- package/dist/skill/generator.js +4 -4
- package/dist/skill/generator.js.map +1 -1
- package/dist/skill/upgrader.js +1 -1
- package/dist/skill/upgrader.js.map +1 -1
- package/dist/skill/validator.js +1 -1
- package/dist/skill/validator.js.map +1 -1
- package/dist/storage/sqlite.d.ts +294 -0
- package/dist/storage/sqlite.d.ts.map +1 -1
- package/dist/storage/sqlite.js +902 -8
- package/dist/storage/sqlite.js.map +1 -1
- package/dist/tools/index.d.ts +1 -0
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +3 -1
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/memory-search.d.ts +3 -2
- package/dist/tools/memory-search.d.ts.map +1 -1
- package/dist/tools/memory-search.js +48 -7
- package/dist/tools/memory-search.js.map +1 -1
- package/dist/tools/network-memory-detail.d.ts +4 -0
- package/dist/tools/network-memory-detail.d.ts.map +1 -0
- package/dist/tools/network-memory-detail.js +34 -0
- package/dist/tools/network-memory-detail.js.map +1 -0
- package/dist/types.d.ts +47 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/update-check.d.ts.map +1 -1
- package/dist/update-check.js +0 -1
- package/dist/update-check.js.map +1 -1
- package/dist/viewer/html.d.ts.map +1 -1
- package/dist/viewer/html.js +2396 -289
- package/dist/viewer/html.js.map +1 -1
- package/dist/viewer/server.d.ts +43 -0
- package/dist/viewer/server.d.ts.map +1 -1
- package/dist/viewer/server.js +1180 -33
- package/dist/viewer/server.js.map +1 -1
- package/index.ts +445 -25
- package/openclaw.plugin.json +2 -1
- package/package.json +2 -1
- package/scripts/postinstall.cjs +282 -45
- package/skill/memos-memory-guide/SKILL.md +26 -2
- package/src/client/connector.ts +124 -0
- package/src/client/hub.ts +189 -0
- package/src/client/skill-sync.ts +202 -0
- package/src/config.ts +92 -3
- package/src/embedding/index.ts +25 -3
- package/src/hub/auth.ts +78 -0
- package/src/hub/server.ts +734 -0
- package/src/hub/user-manager.ts +126 -0
- package/src/index.ts +7 -4
- package/src/ingest/providers/index.ts +279 -8
- package/src/ingest/providers/openai.ts +1 -1
- package/src/ingest/task-processor.ts +1 -1
- package/src/openclaw-api.ts +287 -0
- package/src/recall/engine.ts +2 -2
- package/src/shared/llm-call.ts +19 -1
- package/src/sharing/types.contract.ts +40 -0
- package/src/sharing/types.ts +102 -0
- package/src/skill/evaluator.ts +3 -2
- package/src/skill/generator.ts +6 -4
- package/src/skill/upgrader.ts +1 -1
- package/src/skill/validator.ts +1 -1
- package/src/storage/sqlite.ts +1167 -7
- package/src/tools/index.ts +1 -0
- package/src/tools/memory-search.ts +57 -8
- package/src/tools/network-memory-detail.ts +34 -0
- package/src/types.ts +48 -2
- package/src/update-check.ts +0 -1
- package/src/viewer/html.ts +2396 -289
- package/src/viewer/server.ts +1087 -34
package/scripts/postinstall.cjs
CHANGED
|
@@ -380,58 +380,30 @@ function sqliteBindingsExist() {
|
|
|
380
380
|
|
|
381
381
|
if (sqliteBindingsExist()) {
|
|
382
382
|
ok("better-sqlite3 is ready.");
|
|
383
|
-
console.log(`
|
|
384
|
-
${GREEN}${BOLD} ┌──────────────────────────────────────────────────┐
|
|
385
|
-
│ ✔ Setup complete! │
|
|
386
|
-
│ │
|
|
387
|
-
│ Restart gateway: │
|
|
388
|
-
│ ${CYAN}openclaw gateway stop && openclaw gateway start${GREEN} │
|
|
389
|
-
└──────────────────────────────────────────────────┘${RESET}
|
|
390
|
-
`);
|
|
391
|
-
process.exit(0);
|
|
392
383
|
} else {
|
|
393
384
|
warn("better-sqlite3 native bindings not found in plugin dir.");
|
|
394
385
|
log(`Searched in: ${DIM}${sqliteModulePath}/build/${RESET}`);
|
|
395
386
|
log("Running: npm rebuild better-sqlite3 (may take 30-60s)...");
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
const startMs = Date.now();
|
|
399
|
-
|
|
400
|
-
const result = spawnSync("npm", ["rebuild", "better-sqlite3"], {
|
|
401
|
-
cwd: pluginDir,
|
|
402
|
-
stdio: "pipe",
|
|
403
|
-
shell: true,
|
|
404
|
-
timeout: 180_000,
|
|
405
|
-
});
|
|
406
387
|
|
|
407
|
-
const
|
|
408
|
-
const
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
388
|
+
const startMs = Date.now();
|
|
389
|
+
const result = spawnSync("npm", ["rebuild", "better-sqlite3"], {
|
|
390
|
+
cwd: pluginDir,
|
|
391
|
+
stdio: "pipe",
|
|
392
|
+
shell: true,
|
|
393
|
+
timeout: 180_000,
|
|
394
|
+
});
|
|
395
|
+
const elapsed = ((Date.now() - startMs) / 1000).toFixed(1);
|
|
396
|
+
const stdout = (result.stdout || "").toString().trim();
|
|
397
|
+
const stderr = (result.stderr || "").toString().trim();
|
|
398
|
+
if (stdout) log(`rebuild output: ${DIM}${stdout.slice(0, 500)}${RESET}`);
|
|
399
|
+
if (stderr) warn(`rebuild stderr: ${DIM}${stderr.slice(0, 500)}${RESET}`);
|
|
413
400
|
|
|
414
|
-
if (result.status === 0) {
|
|
415
|
-
if (sqliteBindingsExist()) {
|
|
401
|
+
if (result.status === 0 && sqliteBindingsExist()) {
|
|
416
402
|
ok(`better-sqlite3 rebuilt successfully (${elapsed}s).`);
|
|
417
|
-
console.log(`
|
|
418
|
-
${GREEN}${BOLD} ┌──────────────────────────────────────────────────┐
|
|
419
|
-
│ ✔ Setup complete! │
|
|
420
|
-
│ │
|
|
421
|
-
│ Restart gateway: │
|
|
422
|
-
│ ${CYAN}openclaw gateway stop && openclaw gateway start${GREEN} │
|
|
423
|
-
└──────────────────────────────────────────────────┘${RESET}
|
|
424
|
-
`);
|
|
425
|
-
process.exit(0);
|
|
426
403
|
} else {
|
|
427
|
-
fail(`Rebuild
|
|
428
|
-
fail(`Looked in: ${sqliteModulePath}/build/`);
|
|
429
|
-
|
|
430
|
-
} else {
|
|
431
|
-
fail(`Rebuild failed with exit code ${result.status} (${elapsed}s).`);
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
console.log(`
|
|
404
|
+
if (result.status !== 0) fail(`Rebuild failed with exit code ${result.status} (${elapsed}s).`);
|
|
405
|
+
else { fail(`Rebuild completed but bindings still missing (${elapsed}s).`); fail(`Looked in: ${sqliteModulePath}/build/`); }
|
|
406
|
+
console.log(`
|
|
435
407
|
${YELLOW}${BOLD} ╔══════════════════════════════════════════════════════════════╗
|
|
436
408
|
║ ✖ better-sqlite3 native module build failed ║
|
|
437
409
|
╠══════════════════════════════════════════════════════════════╣${RESET}
|
|
@@ -452,5 +424,270 @@ ${YELLOW} ║${RESET} ${GREEN}openclaw gateway stop && openclaw gateway start$
|
|
|
452
424
|
${YELLOW} ║${RESET} ${YELLOW}║${RESET}
|
|
453
425
|
${YELLOW}${BOLD} ╚══════════════════════════════════════════════════════════════╝${RESET}
|
|
454
426
|
`);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/* ═══════════════════════════════════════════════════════════
|
|
431
|
+
* Phase 3: Interactive LAN Sharing Setup
|
|
432
|
+
* ═══════════════════════════════════════════════════════════ */
|
|
433
|
+
|
|
434
|
+
const rlMod = require("readline");
|
|
435
|
+
const os = require("os");
|
|
436
|
+
const crypto = require("crypto");
|
|
437
|
+
|
|
438
|
+
function getLocalIPs() {
|
|
439
|
+
const nets = os.networkInterfaces();
|
|
440
|
+
const results = [];
|
|
441
|
+
for (const name of Object.keys(nets)) {
|
|
442
|
+
for (const net of nets[name]) {
|
|
443
|
+
if (net.family === "IPv4" && !net.internal) {
|
|
444
|
+
results.push({ name, address: net.address });
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
return results;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
function generateTeamToken() {
|
|
452
|
+
return crypto.randomBytes(18).toString("base64url");
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
function createPrompt() {
|
|
456
|
+
const rl = rlMod.createInterface({ input: process.stdin, output: process.stdout });
|
|
457
|
+
return {
|
|
458
|
+
ask(q) { return new Promise((resolve) => rl.question(q, (a) => resolve(a.trim()))); },
|
|
459
|
+
close() { rl.close(); },
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
async function setupSharingWizard() {
|
|
464
|
+
if (!process.stdin.isTTY) {
|
|
465
|
+
log("Non-interactive environment, skipping sharing setup wizard.");
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
if (process.env.MEMOS_SKIP_SETUP === "1") {
|
|
469
|
+
log("MEMOS_SKIP_SETUP=1, skipping sharing setup.");
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
const home = process.env.HOME || process.env.USERPROFILE || "";
|
|
474
|
+
const cfgPath = path.join(home, ".openclaw", "openclaw.json");
|
|
475
|
+
if (!fs.existsSync(cfgPath)) {
|
|
476
|
+
log("~/.openclaw/openclaw.json not found, skipping sharing setup.");
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
let cfg;
|
|
481
|
+
try {
|
|
482
|
+
cfg = JSON.parse(fs.readFileSync(cfgPath, "utf-8"));
|
|
483
|
+
} catch (e) {
|
|
484
|
+
warn(`Cannot parse openclaw.json: ${e.message}`);
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
const pluginEntry = cfg?.plugins?.entries?.["memos-local-openclaw-plugin"];
|
|
489
|
+
const existingSharing = pluginEntry?.config?.sharing;
|
|
490
|
+
|
|
491
|
+
if (existingSharing?.enabled) {
|
|
492
|
+
const roleLabel = existingSharing.role === "hub" ? "Hub (团队中心)" : "Client (团队成员)";
|
|
493
|
+
log(`已检测到共享配置: 角色 = ${BOLD}${roleLabel}${RESET}`);
|
|
494
|
+
const prompt = createPrompt();
|
|
495
|
+
const ans = await prompt.ask(` 是否重新配置?/ Reconfigure? (y/N) > `);
|
|
496
|
+
prompt.close();
|
|
497
|
+
if (ans.toLowerCase() !== "y") {
|
|
498
|
+
ok("保留现有共享配置。");
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
phase(3, "局域网共享设置 / LAN Sharing Setup");
|
|
504
|
+
|
|
505
|
+
const prompt = createPrompt();
|
|
506
|
+
|
|
507
|
+
const enableAns = await prompt.ask(` 是否启用局域网记忆共享?/ Enable LAN sharing? (y/N) > `);
|
|
508
|
+
if (enableAns.toLowerCase() !== "y") {
|
|
509
|
+
prompt.close();
|
|
510
|
+
log("未启用共享。你可以稍后在 openclaw.json 中手动配置。");
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
console.log(`
|
|
515
|
+
${BOLD}请选择你的角色 / Choose your role:${RESET}
|
|
516
|
+
${GREEN}1)${RESET} 创建团队 (Hub) — 成为团队管理员,其他人连接你
|
|
517
|
+
${GREEN}2)${RESET} 加入团队 (Client) — 连接到已有的 Hub
|
|
518
|
+
`);
|
|
519
|
+
|
|
520
|
+
const roleAns = await prompt.ask(` 请输入 1 或 2 / Enter 1 or 2 > `);
|
|
521
|
+
|
|
522
|
+
let sharingConfig;
|
|
523
|
+
|
|
524
|
+
if (roleAns === "1") {
|
|
525
|
+
console.log(`\n ${CYAN}${BOLD}── Hub 设置 / Hub Setup ──${RESET}\n`);
|
|
526
|
+
|
|
527
|
+
const teamName = (await prompt.ask(` 团队名称 / Team name (默认: My Team) > `)) || "My Team";
|
|
528
|
+
const portStr = (await prompt.ask(` Hub 端口 / Hub port (默认: 18800) > `)) || "18800";
|
|
529
|
+
const port = parseInt(portStr, 10) || 18800;
|
|
530
|
+
const teamToken = generateTeamToken();
|
|
531
|
+
|
|
532
|
+
sharingConfig = {
|
|
533
|
+
enabled: true,
|
|
534
|
+
role: "hub",
|
|
535
|
+
hub: { port, teamName, teamToken },
|
|
536
|
+
};
|
|
537
|
+
|
|
538
|
+
const localIPs = getLocalIPs();
|
|
539
|
+
const displayIP = localIPs.length > 0 ? localIPs[0].address : "<your-ip>";
|
|
540
|
+
|
|
541
|
+
console.log(`
|
|
542
|
+
${GREEN}${BOLD} ┌────────────────────────────────────────────────────────────┐
|
|
543
|
+
│ ✔ Hub 配置完成!/ Hub configured! │
|
|
544
|
+
│ │
|
|
545
|
+
│ 请将以下信息分享给团队成员: │
|
|
546
|
+
│ Share this info with your team: │
|
|
547
|
+
│ │
|
|
548
|
+
│ ${CYAN}Hub 地址 / Address : ${displayIP}:${port}${GREEN}
|
|
549
|
+
│ ${CYAN}Team Token : ${teamToken}${GREEN}
|
|
550
|
+
│ │
|
|
551
|
+
│ 团队成员安装插件时选择 "加入团队" 并输入以上信息。 │
|
|
552
|
+
└────────────────────────────────────────────────────────────┘${RESET}
|
|
553
|
+
`);
|
|
554
|
+
|
|
555
|
+
if (localIPs.length > 1) {
|
|
556
|
+
log("检测到多个网络接口 / Multiple network interfaces:");
|
|
557
|
+
for (const ip of localIPs) {
|
|
558
|
+
log(` ${ip.name}: ${BOLD}${ip.address}:${port}${RESET}`);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
} else if (roleAns === "2") {
|
|
563
|
+
console.log(`\n ${CYAN}${BOLD}── 加入团队 / Join Team ──${RESET}\n`);
|
|
564
|
+
|
|
565
|
+
const hubAddress = await prompt.ask(` Hub 地址 / Hub address (如 192.168.1.100:18800) > `);
|
|
566
|
+
if (!hubAddress) {
|
|
567
|
+
prompt.close();
|
|
568
|
+
warn("Hub 地址不能为空,跳过配置。");
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
const teamToken = await prompt.ask(` Team Token (由 Hub 创建者提供 / from Hub creator) > `);
|
|
573
|
+
if (!teamToken) {
|
|
574
|
+
prompt.close();
|
|
575
|
+
warn("Team Token 不能为空,跳过配置。");
|
|
576
|
+
return;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
const username = (await prompt.ask(` 你的用户名 / Your username (默认: ${os.userInfo().username}) > `)) || os.userInfo().username;
|
|
455
580
|
|
|
456
|
-
|
|
581
|
+
const hubUrl = /^https?:\/\//i.test(hubAddress.trim()) ? hubAddress.trim() : `http://${hubAddress.trim()}`;
|
|
582
|
+
log(`正在加入团队 / Joining team at: ${BOLD}${hubUrl}${RESET} ...`);
|
|
583
|
+
|
|
584
|
+
let userToken = "";
|
|
585
|
+
let joinOk = false;
|
|
586
|
+
|
|
587
|
+
try {
|
|
588
|
+
const http = require("http");
|
|
589
|
+
const https = require("https");
|
|
590
|
+
const joinResult = await new Promise((resolve, reject) => {
|
|
591
|
+
const postData = JSON.stringify({ teamToken, username, deviceName: os.hostname() });
|
|
592
|
+
const url = new URL(`${hubUrl}/api/v1/hub/join`);
|
|
593
|
+
const mod = url.protocol === "https:" ? https : http;
|
|
594
|
+
const reqObj = mod.request({
|
|
595
|
+
hostname: url.hostname, port: url.port, path: url.pathname,
|
|
596
|
+
method: "POST",
|
|
597
|
+
headers: { "Content-Type": "application/json", "Content-Length": Buffer.byteLength(postData) },
|
|
598
|
+
timeout: 8000,
|
|
599
|
+
}, (resp) => {
|
|
600
|
+
let data = "";
|
|
601
|
+
resp.on("data", (c) => { data += c; });
|
|
602
|
+
resp.on("end", () => {
|
|
603
|
+
try { resolve({ status: resp.statusCode, body: JSON.parse(data) }); }
|
|
604
|
+
catch { resolve({ status: resp.statusCode, body: data }); }
|
|
605
|
+
});
|
|
606
|
+
});
|
|
607
|
+
reqObj.on("error", reject);
|
|
608
|
+
reqObj.on("timeout", () => { reqObj.destroy(); reject(new Error("timeout")); });
|
|
609
|
+
reqObj.write(postData);
|
|
610
|
+
reqObj.end();
|
|
611
|
+
});
|
|
612
|
+
|
|
613
|
+
if (joinResult.status === 200 && joinResult.body.userToken) {
|
|
614
|
+
userToken = joinResult.body.userToken;
|
|
615
|
+
joinOk = true;
|
|
616
|
+
ok(`加入成功!/ Joined successfully! 用户: ${BOLD}${username}${RESET}`);
|
|
617
|
+
} else if (joinResult.status === 403) {
|
|
618
|
+
prompt.close();
|
|
619
|
+
fail("Team Token 无效 / Invalid Team Token");
|
|
620
|
+
return;
|
|
621
|
+
} else {
|
|
622
|
+
warn(`Hub 返回 / Hub responded: ${joinResult.status} ${JSON.stringify(joinResult.body)}`);
|
|
623
|
+
log("配置将被保存,gateway 启动时会用 Team Token 自动重试加入。");
|
|
624
|
+
}
|
|
625
|
+
} catch (e) {
|
|
626
|
+
warn(`无法连接 Hub / Cannot reach Hub: ${e.message}`);
|
|
627
|
+
log("配置将被保存,gateway 启动时会用 Team Token 自动重试加入。");
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
sharingConfig = {
|
|
631
|
+
enabled: true,
|
|
632
|
+
role: "client",
|
|
633
|
+
client: { hubAddress, teamToken },
|
|
634
|
+
};
|
|
635
|
+
if (userToken) sharingConfig.client.userToken = userToken;
|
|
636
|
+
|
|
637
|
+
const statusMsg = joinOk
|
|
638
|
+
? `已加入团队,重启 gateway 即生效`
|
|
639
|
+
: `Hub 暂不可达,gateway 启动时会自动加入`;
|
|
640
|
+
console.log(`
|
|
641
|
+
${GREEN}${BOLD} ┌────────────────────────────────────────────────────────────┐
|
|
642
|
+
│ ✔ Client 配置完成!/ Client configured! │
|
|
643
|
+
│ ${CYAN}Hub: ${hubAddress}${GREEN}
|
|
644
|
+
│ ${CYAN}${statusMsg}${GREEN}
|
|
645
|
+
└────────────────────────────────────────────────────────────┘${RESET}
|
|
646
|
+
`);
|
|
647
|
+
|
|
648
|
+
} else {
|
|
649
|
+
prompt.close();
|
|
650
|
+
warn(`无效选择 "${roleAns}",跳过配置。你可以稍后在 openclaw.json 中手动配置。`);
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
prompt.close();
|
|
655
|
+
|
|
656
|
+
try {
|
|
657
|
+
if (!cfg.plugins) cfg.plugins = {};
|
|
658
|
+
if (!cfg.plugins.entries) cfg.plugins.entries = {};
|
|
659
|
+
if (!cfg.plugins.entries["memos-local-openclaw-plugin"]) {
|
|
660
|
+
cfg.plugins.entries["memos-local-openclaw-plugin"] = { enabled: true };
|
|
661
|
+
}
|
|
662
|
+
const entry = cfg.plugins.entries["memos-local-openclaw-plugin"];
|
|
663
|
+
if (!entry.config) entry.config = {};
|
|
664
|
+
entry.config.sharing = sharingConfig;
|
|
665
|
+
|
|
666
|
+
const backup = cfgPath + ".bak-" + Date.now();
|
|
667
|
+
fs.copyFileSync(cfgPath, backup);
|
|
668
|
+
fs.writeFileSync(cfgPath, JSON.stringify(cfg, null, 2) + "\n", "utf-8");
|
|
669
|
+
ok(`配置已写入 / Config saved: ${DIM}~/.openclaw/openclaw.json${RESET}`);
|
|
670
|
+
log(`备份 / Backup: ${DIM}${backup}${RESET}`);
|
|
671
|
+
} catch (e) {
|
|
672
|
+
fail(`写入配置失败 / Config write failed: ${e.message}`);
|
|
673
|
+
warn("请手动编辑 ~/.openclaw/openclaw.json 添加 sharing 配置。");
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
(async () => {
|
|
678
|
+
try {
|
|
679
|
+
await setupSharingWizard();
|
|
680
|
+
} catch (e) {
|
|
681
|
+
warn(`Setup wizard error: ${e.message}`);
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
console.log(`
|
|
685
|
+
${GREEN}${BOLD} ┌──────────────────────────────────────────────────┐
|
|
686
|
+
│ ✔ Setup complete! │
|
|
687
|
+
│ │
|
|
688
|
+
│ Restart gateway: │
|
|
689
|
+
│ ${CYAN}openclaw gateway stop && openclaw gateway start${GREEN} │
|
|
690
|
+
└──────────────────────────────────────────────────┘${RESET}
|
|
691
|
+
`);
|
|
692
|
+
process.exit(0);
|
|
693
|
+
})();
|
|
@@ -5,13 +5,13 @@ description: "Use the MemOS Local memory system to search and use the user's pas
|
|
|
5
5
|
|
|
6
6
|
# MemOS Local Memory — Agent Guide
|
|
7
7
|
|
|
8
|
-
This skill describes how to use the MemOS memory tools so you can reliably search and use the user's long-term conversation history,
|
|
8
|
+
This skill describes how to use the MemOS memory tools so you can reliably search and use the user's long-term conversation history, query Hub-shared team data, share tasks, and discover or pull reusable skills.
|
|
9
9
|
|
|
10
10
|
## How memory is provided each turn
|
|
11
11
|
|
|
12
12
|
- **Automatic recall (hook):** At the start of each turn, the system runs a memory search using the user's current message and injects relevant past memories into your context. You do not need to call any tool for that.
|
|
13
13
|
- **When that is not enough:** If the user's message is very long, vague, or the automatic search returns **no memories**, you should **generate your own short, focused query** and call `memory_search` yourself.
|
|
14
|
-
- **Memory isolation:** Each agent can only see its own
|
|
14
|
+
- **Memory isolation:** Each agent can only see its own local private memories and local `public` memories. Hub-shared data only appears when you search with `scope="group"` or `scope="all"`.
|
|
15
15
|
|
|
16
16
|
## Tools — what they do and when to call
|
|
17
17
|
|
|
@@ -89,6 +89,30 @@ This skill describes how to use the MemOS memory tools so you can reliably searc
|
|
|
89
89
|
- **Parameters:**
|
|
90
90
|
- `skillId` (string, **required**) — The skill ID to unpublish.
|
|
91
91
|
|
|
92
|
+
### network_memory_detail
|
|
93
|
+
|
|
94
|
+
- **What it does:** Fetches the full content behind a Hub search hit.
|
|
95
|
+
- **When to call:** A `memory_search` result came from the Hub and you need the full shared memory content.
|
|
96
|
+
- **Parameters:** `remoteHitId`.
|
|
97
|
+
|
|
98
|
+
### task_share / task_unshare
|
|
99
|
+
|
|
100
|
+
- **What they do:** Share a local task to the Hub, or remove it later.
|
|
101
|
+
- **When to call:** A task is valuable to your group or to the whole team and should be discoverable via shared search.
|
|
102
|
+
- **Parameters:** `taskId`, plus sharing visibility/scope when required.
|
|
103
|
+
|
|
104
|
+
### network_skill_pull
|
|
105
|
+
|
|
106
|
+
- **What it does:** Pulls a Hub-shared skill bundle down into local storage.
|
|
107
|
+
- **When to call:** `skill_search` found a useful Hub skill and you want to use it locally or offline.
|
|
108
|
+
- **Parameters:** `skillId`.
|
|
109
|
+
|
|
110
|
+
### network_team_info
|
|
111
|
+
|
|
112
|
+
- **What it does:** Returns current Hub connection information, user, role, and groups.
|
|
113
|
+
- **When to call:** You need to confirm whether team sharing is configured or which groups the current client belongs to.
|
|
114
|
+
- **Parameters:** none.
|
|
115
|
+
|
|
92
116
|
### memory_timeline
|
|
93
117
|
|
|
94
118
|
- **What it does:** Expand context around a memory search hit. Pass the `chunkId` from a search result to read the surrounding conversation messages.
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { Logger, MemosLocalConfig } from "../types";
|
|
2
|
+
import type { GroupInfo, UserRole, UserStatus } from "../sharing/types";
|
|
3
|
+
import type { SqliteStore } from "../storage/sqlite";
|
|
4
|
+
import { hubRequestJson, normalizeHubUrl } from "./hub";
|
|
5
|
+
|
|
6
|
+
export interface HubSessionInfo {
|
|
7
|
+
hubUrl: string;
|
|
8
|
+
userId: string;
|
|
9
|
+
username: string;
|
|
10
|
+
userToken: string;
|
|
11
|
+
role: UserRole;
|
|
12
|
+
connectedAt: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface HubStatusInfo {
|
|
16
|
+
connected: boolean;
|
|
17
|
+
hubUrl?: string;
|
|
18
|
+
user: null | {
|
|
19
|
+
id: string;
|
|
20
|
+
username: string;
|
|
21
|
+
role: UserRole;
|
|
22
|
+
status: UserStatus | string;
|
|
23
|
+
groups: GroupInfo[];
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export async function connectToHub(store: SqliteStore, config: MemosLocalConfig, log?: Logger): Promise<HubSessionInfo> {
|
|
28
|
+
const hubAddress = config.sharing?.client?.hubAddress ?? "";
|
|
29
|
+
let userToken = config.sharing?.client?.userToken ?? "";
|
|
30
|
+
|
|
31
|
+
if (!userToken) {
|
|
32
|
+
const persisted = store.getClientHubConnection();
|
|
33
|
+
if (persisted?.userToken) userToken = persisted.userToken;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (!userToken && config.sharing?.client?.teamToken) {
|
|
37
|
+
if (!log) throw new Error("hub client connection is not configured (no userToken, has teamToken but no logger for auto-join)");
|
|
38
|
+
return autoJoinHub(store, config, log);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (!hubAddress || !userToken) {
|
|
42
|
+
throw new Error("hub client connection is not configured");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const hubUrl = normalizeHubUrl(hubAddress);
|
|
46
|
+
const me = await hubRequestJson(hubUrl, userToken, "/api/v1/hub/me", { method: "GET" }) as any;
|
|
47
|
+
store.setClientHubConnection({
|
|
48
|
+
hubUrl,
|
|
49
|
+
userId: String(me.id),
|
|
50
|
+
username: String(me.username ?? ""),
|
|
51
|
+
userToken,
|
|
52
|
+
role: String(me.role ?? "member") as UserRole,
|
|
53
|
+
connectedAt: Date.now(),
|
|
54
|
+
});
|
|
55
|
+
return store.getClientHubConnection()!;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export async function getHubStatus(store: SqliteStore, config: MemosLocalConfig): Promise<HubStatusInfo> {
|
|
59
|
+
const conn = store.getClientHubConnection();
|
|
60
|
+
const hubAddress = conn?.hubUrl || config.sharing?.client?.hubAddress || "";
|
|
61
|
+
const userToken = conn?.userToken || config.sharing?.client?.userToken || "";
|
|
62
|
+
if (!hubAddress || !userToken) {
|
|
63
|
+
return { connected: false, user: null };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
const me = await hubRequestJson(normalizeHubUrl(hubAddress), userToken, "/api/v1/hub/me", { method: "GET" }) as any;
|
|
68
|
+
return {
|
|
69
|
+
connected: true,
|
|
70
|
+
hubUrl: normalizeHubUrl(hubAddress),
|
|
71
|
+
user: {
|
|
72
|
+
id: String(me.id),
|
|
73
|
+
username: String(me.username ?? ""),
|
|
74
|
+
role: String(me.role ?? "member") as UserRole,
|
|
75
|
+
status: String(me.status ?? "active"),
|
|
76
|
+
groups: Array.isArray(me.groups)
|
|
77
|
+
? me.groups.map((group: any) => ({
|
|
78
|
+
id: String(group.id),
|
|
79
|
+
name: String(group.name),
|
|
80
|
+
description: typeof group.description === "string" ? group.description : undefined,
|
|
81
|
+
}))
|
|
82
|
+
: [],
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
} catch {
|
|
86
|
+
return { connected: false, user: null };
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export async function autoJoinHub(
|
|
91
|
+
store: SqliteStore,
|
|
92
|
+
config: MemosLocalConfig,
|
|
93
|
+
log: Logger,
|
|
94
|
+
): Promise<HubSessionInfo> {
|
|
95
|
+
const hubAddress = config.sharing?.client?.hubAddress ?? "";
|
|
96
|
+
const teamToken = config.sharing?.client?.teamToken ?? "";
|
|
97
|
+
if (!hubAddress || !teamToken) {
|
|
98
|
+
throw new Error("hubAddress and teamToken are required for auto-join");
|
|
99
|
+
}
|
|
100
|
+
const hubUrl = normalizeHubUrl(hubAddress);
|
|
101
|
+
const hostname = typeof globalThis.process !== "undefined" ? (await import("os")).hostname() : "unknown";
|
|
102
|
+
const username = typeof globalThis.process !== "undefined" ? (await import("os")).userInfo().username : "user";
|
|
103
|
+
|
|
104
|
+
log.info(`Joining Hub at ${hubUrl} as "${username}"...`);
|
|
105
|
+
const result = await hubRequestJson(hubUrl, "", "/api/v1/hub/join", {
|
|
106
|
+
method: "POST",
|
|
107
|
+
body: JSON.stringify({ teamToken, username, deviceName: hostname }),
|
|
108
|
+
}) as any;
|
|
109
|
+
|
|
110
|
+
if (!result.userToken) {
|
|
111
|
+
throw new Error(`Hub join failed: ${JSON.stringify(result)}`);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
log.info(`Joined Hub successfully! userId=${result.userId}`);
|
|
115
|
+
store.setClientHubConnection({
|
|
116
|
+
hubUrl,
|
|
117
|
+
userId: String(result.userId),
|
|
118
|
+
username,
|
|
119
|
+
userToken: result.userToken,
|
|
120
|
+
role: "member",
|
|
121
|
+
connectedAt: Date.now(),
|
|
122
|
+
});
|
|
123
|
+
return store.getClientHubConnection()!;
|
|
124
|
+
}
|