memory-gateway-sync 0.2.0 → 0.3.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.ts +16 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "memory-gateway-sync",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Memory 双写插件:fs.watch 感知变化后同步到外部 Gateway",
5
5
  "type": "module",
6
6
  "openclaw": {
package/src/index.ts CHANGED
@@ -16,6 +16,7 @@ interface IngestPayload {
16
16
  path: string;
17
17
  content: string;
18
18
  agentId: string;
19
+ userId: string | null;
19
20
  workspaceDir: string;
20
21
  eventType: string;
21
22
  syncedAt: string;
@@ -41,6 +42,7 @@ export default definePluginEntry({
41
42
  const gatewayToken = cfg.gatewayToken;
42
43
  const debounceMs = cfg.debounceMs ?? 1500;
43
44
  const defaultAgentId = cfg.agentId ?? "default";
45
+ const ownerClawUserId = process.env.owner_claw_user_id ?? null;
44
46
 
45
47
  if (!gatewayUrl || !gatewayToken) {
46
48
  api.logger.warn(
@@ -115,10 +117,24 @@ export default definePluginEntry({
115
117
  }
116
118
 
117
119
  const relativePath = path.relative(ws.dir, absPath);
120
+
121
+ // 根据路径解析 userId
122
+ // MEMORY.md / memory/owner/* → 环境变量 owner_claw_user_id
123
+ // memory/peers/{peerId}/* → 路径中的 peerId
124
+ // 其他 → null
125
+ let userId: string | null = null;
126
+ const parts = relativePath.replace(/\\/g, "/").split("/");
127
+ if (relativePath === "MEMORY.md" || parts[0] === "memory" && parts[1] === "owner") {
128
+ userId = ownerClawUserId;
129
+ } else if (parts[0] === "memory" && parts[1] === "peers" && parts.length >= 3) {
130
+ userId = parts[2];
131
+ }
132
+
118
133
  const payload: IngestPayload = {
119
134
  path: relativePath,
120
135
  content,
121
136
  agentId: ws.agentId,
137
+ userId,
122
138
  workspaceDir: ws.dir,
123
139
  eventType,
124
140
  syncedAt: new Date().toISOString(),