MCPcopy Create free account
hub / github.com/MemTensor/MemOS / loadOrCreateAnonymousId

Method loadOrCreateAnonymousId

packages/memos-core/src/telemetry.ts:105–126  ·  view source on GitHub ↗
(stateDir: string)

Source from the content-addressed store, hash-verified

103 }
104
105 private loadOrCreateAnonymousId(stateDir: string): string {
106 const newDir = path.join(stateDir, "memos-local");
107 const oldDir = path.join(stateDir, "memos-lite");
108 const idFile = path.join(newDir, ".anonymous-id");
109 const oldIdFile = path.join(oldDir, ".anonymous-id");
110
111 try {
112 const existing = fs.readFileSync(idFile, "utf-8").trim();
113 if (existing.length > 10) return existing;
114 } catch {}
115 try {
116 const existing = fs.readFileSync(oldIdFile, "utf-8").trim();
117 if (existing.length > 10) return existing;
118 } catch {}
119
120 const newId = uuidv4();
121 try {
122 fs.mkdirSync(path.dirname(idFile), { recursive: true });
123 fs.writeFileSync(idFile, newId, "utf-8");
124 } catch {}
125 return newId;
126 }
127
128 private loadOrCreateSessionId(stateDir: string): string {
129 const filePath = path.join(stateDir, "memos-local", ".session");

Callers 1

constructorMethod · 0.95

Calls 1

joinMethod · 0.45

Tested by

no test coverage detected