@memtensor/memos-local-openclaw-plugin 1.0.4-beta.10 → 1.0.4-beta.12

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 (72) hide show
  1. package/dist/client/connector.d.ts +5 -0
  2. package/dist/client/connector.d.ts.map +1 -1
  3. package/dist/client/connector.js +38 -8
  4. package/dist/client/connector.js.map +1 -1
  5. package/dist/hub/server.d.ts +1 -0
  6. package/dist/hub/server.d.ts.map +1 -1
  7. package/dist/hub/server.js +143 -32
  8. package/dist/hub/server.js.map +1 -1
  9. package/dist/hub/user-manager.d.ts +9 -0
  10. package/dist/hub/user-manager.d.ts.map +1 -1
  11. package/dist/hub/user-manager.js +26 -2
  12. package/dist/hub/user-manager.js.map +1 -1
  13. package/dist/ingest/chunker.d.ts +2 -1
  14. package/dist/ingest/chunker.d.ts.map +1 -1
  15. package/dist/ingest/chunker.js +14 -10
  16. package/dist/ingest/chunker.js.map +1 -1
  17. package/dist/recall/engine.d.ts.map +1 -1
  18. package/dist/recall/engine.js +7 -2
  19. package/dist/recall/engine.js.map +1 -1
  20. package/dist/sharing/types.d.ts +1 -1
  21. package/dist/sharing/types.d.ts.map +1 -1
  22. package/dist/skill/evolver.d.ts +2 -0
  23. package/dist/skill/evolver.d.ts.map +1 -1
  24. package/dist/skill/evolver.js +56 -5
  25. package/dist/skill/evolver.js.map +1 -1
  26. package/dist/skill/generator.d.ts +2 -0
  27. package/dist/skill/generator.d.ts.map +1 -1
  28. package/dist/skill/generator.js +45 -3
  29. package/dist/skill/generator.js.map +1 -1
  30. package/dist/skill/installer.d.ts +26 -0
  31. package/dist/skill/installer.d.ts.map +1 -1
  32. package/dist/skill/installer.js +80 -4
  33. package/dist/skill/installer.js.map +1 -1
  34. package/dist/skill/upgrader.d.ts +2 -0
  35. package/dist/skill/upgrader.d.ts.map +1 -1
  36. package/dist/skill/upgrader.js +139 -1
  37. package/dist/skill/upgrader.js.map +1 -1
  38. package/dist/skill/validator.d.ts +3 -0
  39. package/dist/skill/validator.d.ts.map +1 -1
  40. package/dist/skill/validator.js +75 -0
  41. package/dist/skill/validator.js.map +1 -1
  42. package/dist/storage/sqlite.d.ts +28 -0
  43. package/dist/storage/sqlite.d.ts.map +1 -1
  44. package/dist/storage/sqlite.js +155 -16
  45. package/dist/storage/sqlite.js.map +1 -1
  46. package/dist/types.d.ts +10 -0
  47. package/dist/types.d.ts.map +1 -1
  48. package/dist/types.js +4 -0
  49. package/dist/types.js.map +1 -1
  50. package/dist/viewer/html.d.ts.map +1 -1
  51. package/dist/viewer/html.js +64 -24
  52. package/dist/viewer/html.js.map +1 -1
  53. package/dist/viewer/server.d.ts.map +1 -1
  54. package/dist/viewer/server.js +39 -20
  55. package/dist/viewer/server.js.map +1 -1
  56. package/index.ts +338 -33
  57. package/package.json +1 -1
  58. package/src/client/connector.ts +43 -8
  59. package/src/hub/server.ts +142 -31
  60. package/src/hub/user-manager.ts +42 -6
  61. package/src/ingest/chunker.ts +19 -13
  62. package/src/recall/engine.ts +7 -2
  63. package/src/sharing/types.ts +1 -1
  64. package/src/skill/evolver.ts +58 -6
  65. package/src/skill/generator.ts +44 -5
  66. package/src/skill/installer.ts +107 -4
  67. package/src/skill/upgrader.ts +139 -1
  68. package/src/skill/validator.ts +79 -0
  69. package/src/storage/sqlite.ts +174 -16
  70. package/src/types.ts +11 -0
  71. package/src/viewer/html.ts +64 -24
  72. package/src/viewer/server.ts +39 -20
@@ -1232,7 +1232,7 @@ export class ViewerServer {
1232
1232
  body: JSON.stringify({ memory: { sourceChunkId: refreshedChunk.id, role: refreshedChunk.role, content: refreshedChunk.content, summary: refreshedChunk.summary, kind: refreshedChunk.kind, groupId: null, visibility: "public" } }),
1233
1233
  });
1234
1234
  if (!isLocalShared) this.store.markMemorySharedLocally(chunkId);
1235
- if (hubClient.userId) {
1235
+ if (hubClient.userId && this.ctx?.config?.sharing?.role === "hub") {
1236
1236
  const existing = this.store.getHubMemoryBySource(hubClient.userId, chunkId);
1237
1237
  this.store.upsertHubMemory({
1238
1238
  id: (response as any)?.memoryId ?? existing?.id ?? crypto.randomUUID(),
@@ -1780,7 +1780,8 @@ export class ViewerServer {
1780
1780
  localIPs.push("127.0.0.1", "localhost", "0.0.0.0");
1781
1781
  try {
1782
1782
  const u = new URL(hubUrl);
1783
- if (localIPs.includes(u.hostname)) {
1783
+ const targetPort = u.port || (u.protocol === "https:" ? "443" : "80");
1784
+ if (localIPs.includes(u.hostname) && targetPort === String(this.port)) {
1784
1785
  return this.jsonResponse(res, { ok: false, error: "cannot_join_self" });
1785
1786
  }
1786
1787
  } catch {}
@@ -1788,10 +1789,13 @@ export class ViewerServer {
1788
1789
  const nickname = sharing.client?.nickname;
1789
1790
  const username = nickname || os.userInfo().username || "user";
1790
1791
  const hostname = os.hostname() || "unknown";
1792
+ const persisted = this.store.getClientHubConnection();
1793
+ const existingIdentityKey = persisted?.identityKey || "";
1791
1794
  const result = await hubRequestJson(hubUrl, "", "/api/v1/hub/join", {
1792
1795
  method: "POST",
1793
- body: JSON.stringify({ teamToken, username, deviceName: hostname, reapply: true }),
1796
+ body: JSON.stringify({ teamToken, username, deviceName: hostname, reapply: true, identityKey: existingIdentityKey }),
1794
1797
  }) as any;
1798
+ const returnedIdentityKey = String(result.identityKey || existingIdentityKey || "");
1795
1799
  this.store.setClientHubConnection({
1796
1800
  hubUrl,
1797
1801
  userId: String(result.userId || ""),
@@ -1799,6 +1803,8 @@ export class ViewerServer {
1799
1803
  userToken: result.userToken || "",
1800
1804
  role: "member",
1801
1805
  connectedAt: Date.now(),
1806
+ identityKey: returnedIdentityKey,
1807
+ lastKnownStatus: result.status || "",
1802
1808
  });
1803
1809
  this.jsonResponse(res, { ok: true, status: result.status || "pending" });
1804
1810
  } catch (err) {
@@ -2074,14 +2080,13 @@ export class ViewerServer {
2074
2080
  },
2075
2081
  }),
2076
2082
  });
2077
- const hubUserId = hubClient.userId;
2078
- if (hubUserId) {
2083
+ if (hubClient.userId && this.ctx?.config?.sharing?.role === "hub") {
2079
2084
  const now = Date.now();
2080
- const existing = this.store.getHubMemoryBySource(hubUserId, chunk.id);
2085
+ const existing = this.store.getHubMemoryBySource(hubClient.userId, chunk.id);
2081
2086
  this.store.upsertHubMemory({
2082
2087
  id: (response as any)?.memoryId ?? existing?.id ?? crypto.randomUUID(),
2083
2088
  sourceChunkId: chunk.id,
2084
- sourceUserId: hubUserId,
2089
+ sourceUserId: hubClient.userId,
2085
2090
  role: chunk.role,
2086
2091
  content: chunk.content,
2087
2092
  summary: chunk.summary ?? "",
@@ -2592,7 +2597,8 @@ export class ViewerServer {
2592
2597
  localIPs.push("127.0.0.1", "localhost", "0.0.0.0");
2593
2598
  try {
2594
2599
  const u = new URL(addr.startsWith("http") ? addr : `http://${addr}`);
2595
- if (localIPs.includes(u.hostname)) {
2600
+ const targetPort = u.port || (u.protocol === "https:" ? "443" : "80");
2601
+ if (localIPs.includes(u.hostname) && targetPort === String(this.port)) {
2596
2602
  res.writeHead(400, { "Content-Type": "application/json" });
2597
2603
  res.end(JSON.stringify({ error: "cannot_join_self" }));
2598
2604
  return;
@@ -2618,17 +2624,22 @@ export class ViewerServer {
2618
2624
  const isClient = newEnabled && newRole === "client";
2619
2625
  if (wasClient && !isClient) {
2620
2626
  this.notifyHubLeave();
2621
- this.store.clearClientHubConnection();
2622
- this.log.info("Cleared client hub connection (sharing disabled or role changed)");
2627
+ const oldConn = this.store.getClientHubConnection();
2628
+ if (oldConn) {
2629
+ this.store.setClientHubConnection({ ...oldConn, userToken: "", lastKnownStatus: "left" });
2630
+ }
2631
+ this.log.info("Client hub connection token cleared (sharing disabled or role changed), identity preserved");
2623
2632
  }
2624
2633
 
2625
- // Detect switching to a different Hub while still in client mode
2626
2634
  if (wasClient && isClient) {
2627
2635
  const newClientAddr = String((merged.client as Record<string, unknown>)?.hubAddress || "");
2628
2636
  if (newClientAddr && oldClientHubAddress && normalizeHubUrl(newClientAddr) !== normalizeHubUrl(oldClientHubAddress)) {
2629
2637
  this.notifyHubLeave();
2630
- this.store.clearClientHubConnection();
2631
- this.log.info("Cleared client hub connection (switched to different Hub)");
2638
+ const oldConn = this.store.getClientHubConnection();
2639
+ if (oldConn) {
2640
+ this.store.setClientHubConnection({ ...oldConn, hubUrl: normalizeHubUrl(newClientAddr), userToken: "", lastKnownStatus: "hub_changed" });
2641
+ }
2642
+ this.log.info("Client hub connection token cleared (switched to different Hub), identity preserved");
2632
2643
  }
2633
2644
  }
2634
2645
 
@@ -2645,9 +2656,11 @@ export class ViewerServer {
2645
2656
  this.log.info("Plugin config updated via Viewer");
2646
2657
  this.stopHubHeartbeat();
2647
2658
 
2648
- // When switching to client mode, immediately send join request
2659
+ // When switching to client mode or re-enabling sharing as client, send join request
2649
2660
  const finalSharing = config.sharing as Record<string, unknown> | undefined;
2650
- if (finalSharing?.role === "client" && oldSharingRole !== "client") {
2661
+ const nowClient = Boolean(finalSharing?.enabled) && finalSharing?.role === "client";
2662
+ const previouslyClient = oldSharingEnabled && oldSharingRole === "client";
2663
+ if (nowClient && !previouslyClient) {
2651
2664
  this.autoJoinOnSave(finalSharing).catch(e => this.log.warn(`Auto-join on save failed: ${e}`));
2652
2665
  }
2653
2666
 
@@ -2670,10 +2683,13 @@ export class ViewerServer {
2670
2683
  const nickname = String(clientCfg?.nickname || "");
2671
2684
  const username = nickname || os.userInfo().username || "user";
2672
2685
  const hostname = os.hostname() || "unknown";
2686
+ const persisted = this.store.getClientHubConnection();
2687
+ const existingIdentityKey = persisted?.identityKey || "";
2673
2688
  const result = await hubRequestJson(hubUrl, "", "/api/v1/hub/join", {
2674
2689
  method: "POST",
2675
- body: JSON.stringify({ teamToken, username, deviceName: hostname }),
2690
+ body: JSON.stringify({ teamToken, username, deviceName: hostname, identityKey: existingIdentityKey }),
2676
2691
  }) as any;
2692
+ const returnedIdentityKey = String(result.identityKey || existingIdentityKey || "");
2677
2693
  this.store.setClientHubConnection({
2678
2694
  hubUrl,
2679
2695
  userId: String(result.userId || ""),
@@ -2681,6 +2697,8 @@ export class ViewerServer {
2681
2697
  userToken: result.userToken || "",
2682
2698
  role: "member",
2683
2699
  connectedAt: Date.now(),
2700
+ identityKey: returnedIdentityKey,
2701
+ lastKnownStatus: result.status || "",
2684
2702
  });
2685
2703
  this.log.info(`Auto-join on save: status=${result.status}, userId=${result.userId}`);
2686
2704
  if (result.userToken) {
@@ -2768,10 +2786,10 @@ export class ViewerServer {
2768
2786
  this.log.warn(`Failed to update hub-auth.json: ${e}`);
2769
2787
  }
2770
2788
  } else {
2771
- const persisted = this.store.getClientHubConnection();
2772
- if (persisted) {
2789
+ const persistedConn = this.store.getClientHubConnection();
2790
+ if (persistedConn) {
2773
2791
  this.store.setClientHubConnection({
2774
- ...persisted,
2792
+ ...persistedConn,
2775
2793
  username: result.username,
2776
2794
  userToken: result.userToken,
2777
2795
  });
@@ -2798,7 +2816,8 @@ export class ViewerServer {
2798
2816
  const localIPs = this.getLocalIPs();
2799
2817
  localIPs.push("127.0.0.1", "localhost", "0.0.0.0");
2800
2818
  const parsed = new URL(hubUrl.startsWith("http") ? hubUrl : `http://${hubUrl}`);
2801
- if (localIPs.includes(parsed.hostname)) {
2819
+ const targetPort = parsed.port || (parsed.protocol === "https:" ? "443" : "80");
2820
+ if (localIPs.includes(parsed.hostname) && targetPort === String(this.port)) {
2802
2821
  this.jsonResponse(res, { ok: false, error: "cannot_join_self" });
2803
2822
  return;
2804
2823
  }