(pluginDir?: string)
| 20 | } |
| 21 | |
| 22 | function loadTelemetryCredentials(pluginDir?: string): { endpoint: string; pid: string; env: string } { |
| 23 | if (process.env.MEMOS_ARMS_ENDPOINT) { |
| 24 | return { |
| 25 | endpoint: process.env.MEMOS_ARMS_ENDPOINT, |
| 26 | pid: process.env.MEMOS_ARMS_PID ?? "", |
| 27 | env: process.env.MEMOS_ARMS_ENV ?? "prod", |
| 28 | }; |
| 29 | } |
| 30 | const bases = pluginDir ? [pluginDir, path.join(pluginDir, "src")] : []; |
| 31 | if (typeof __dirname === "string") bases.push(path.resolve(__dirname, ".."), __dirname); |
| 32 | const candidates = bases.map(b => path.join(b, "telemetry.credentials.json")); |
| 33 | for (const credPath of candidates) { |
| 34 | try { |
| 35 | const raw = fs.readFileSync(credPath, "utf-8"); |
| 36 | const creds = JSON.parse(raw); |
| 37 | if (creds.endpoint) return { endpoint: creds.endpoint, pid: creds.pid ?? "", env: creds.env ?? "prod" }; |
| 38 | } catch {} |
| 39 | } |
| 40 | return { endpoint: "", pid: "", env: "prod" }; |
| 41 | } |
| 42 | |
| 43 | const FLUSH_AT = 10; |
| 44 | const FLUSH_INTERVAL_MS = 30_000; |
no test coverage detected