MCPcopy Create free account
hub / github.com/thesysdev/openui / loadOrCreateState

Function loadOrCreateState

packages/openui-cli/src/lib/telemetry.ts:22–40  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

20type Stored = { distinctId: string; firstRunNoticeShown?: boolean };
21
22function loadOrCreateState() {
23 const file = path.join(configDir(), "telemetry.json");
24 try {
25 const raw = JSON.parse(fs.readFileSync(file, "utf8")) as Stored;
26 return {
27 distinctId: raw.distinctId,
28 isFirstRun: !raw.firstRunNoticeShown,
29 persist: () => writeState(file, { ...raw, firstRunNoticeShown: true }),
30 };
31 } catch {
32 /* missing/corrupt → create */
33 }
34 const fresh: Stored = { distinctId: crypto.randomUUID(), firstRunNoticeShown: false };
35 return {
36 distinctId: fresh.distinctId,
37 isFirstRun: true,
38 persist: () => writeState(file, { ...fresh, firstRunNoticeShown: true }),
39 };
40}
41function writeState(file: string, s: Stored) {
42 try {
43 fs.mkdirSync(path.dirname(file), { recursive: true });

Callers 1

initMethod · 0.85

Calls 3

configDirFunction · 0.85
writeStateFunction · 0.85
parseMethod · 0.65

Tested by

no test coverage detected