perplexity-user-mcp 0.8.42 → 0.8.44

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 (132) hide show
  1. package/dist/attachments.d.ts +10 -20
  2. package/dist/browser-window.d.ts +1 -0
  3. package/dist/cf-warmup.d.ts +32 -0
  4. package/dist/checks/browser.d.ts +12 -100
  5. package/dist/checks/config.d.ts +25 -91
  6. package/dist/checks/ide.d.ts +31 -89
  7. package/dist/checks/mcp.d.ts +12 -61
  8. package/dist/checks/native-deps.d.ts +46 -131
  9. package/dist/checks/network.d.ts +13 -71
  10. package/dist/checks/probe.d.ts +20 -92
  11. package/dist/checks/profiles.d.ts +13 -99
  12. package/dist/checks/profiles.mjs +35 -0
  13. package/dist/checks/runtime.d.ts +24 -89
  14. package/dist/checks/vault.d.ts +13 -142
  15. package/dist/checks/vault.mjs +6 -11
  16. package/dist/{chunk-T6ARJK2P.mjs → chunk-2B5OQUXR.mjs} +6 -6
  17. package/dist/{chunk-2FPGJKCA.mjs → chunk-2EE7MNP2.mjs} +2 -2
  18. package/dist/{chunk-Z4OLYVB2.mjs → chunk-2OVLCZHU.mjs} +1 -1
  19. package/dist/{chunk-WDIW33DA.mjs → chunk-3LUO5ATM.mjs} +1 -1
  20. package/dist/{chunk-B65IJQZJ.mjs → chunk-6E6XTHTG.mjs} +1 -1
  21. package/dist/{chunk-S677V2JU.mjs → chunk-C5I7KXHK.mjs} +32 -2
  22. package/dist/{chunk-TDXETAQT.mjs → chunk-DKEJZ4FI.mjs} +1 -1
  23. package/dist/{chunk-U7QPUNRH.mjs → chunk-DXR6EEZH.mjs} +26 -7
  24. package/dist/{chunk-HJIXH6CL.mjs → chunk-E3GRJXXJ.mjs} +2 -0
  25. package/dist/{chunk-RK4EBZJ3.mjs → chunk-E75J42W5.mjs} +11 -8
  26. package/dist/{chunk-452DK6OS.mjs → chunk-FNHYUE22.mjs} +2 -2
  27. package/dist/{chunk-D254EFYB.mjs → chunk-GBI2U336.mjs} +1 -1
  28. package/dist/chunk-GPUGKWXH.mjs +17 -0
  29. package/dist/{chunk-HNSPNCFH.mjs → chunk-KSNV3ZVY.mjs} +1 -1
  30. package/dist/{chunk-XTRJSV72.mjs → chunk-LGH5BSUY.mjs} +1 -1
  31. package/dist/{chunk-KJFX2ZXR.mjs → chunk-NMKNEEZB.mjs} +1 -1
  32. package/dist/{chunk-FKQ3HP4Q.mjs → chunk-TIWHN4IW.mjs} +1 -1
  33. package/dist/{chunk-V4U3JM4R.mjs → chunk-TSLRTZYR.mjs} +1 -1
  34. package/dist/{chunk-DQQISMYN.mjs → chunk-V4LHDNWJ.mjs} +2 -2
  35. package/dist/{chunk-C3HPFFTD.mjs → chunk-WHVJ724K.mjs} +84 -44
  36. package/dist/cli.d.ts +14 -1317
  37. package/dist/cli.mjs +14 -21
  38. package/dist/client.d.ts +27 -24
  39. package/dist/client.mjs +6 -6
  40. package/dist/cloud-sync.d.ts +65 -42
  41. package/dist/cloud-sync.mjs +8 -8
  42. package/dist/config.d.ts +35 -39
  43. package/dist/config.mjs +3 -3
  44. package/dist/cookie-jar.d.ts +77 -0
  45. package/dist/daemon/attach.d.ts +5 -12
  46. package/dist/daemon/attach.mjs +17 -17
  47. package/dist/daemon/audit.d.ts +5 -7
  48. package/dist/daemon/audit.mjs +2 -2
  49. package/dist/daemon/client-http.d.ts +10 -16
  50. package/dist/daemon/client-http.mjs +17 -17
  51. package/dist/daemon/index.d.ts +17 -14
  52. package/dist/daemon/index.mjs +18 -18
  53. package/dist/daemon/install-tunnel.d.ts +8 -34
  54. package/dist/daemon/install-tunnel.mjs +2 -2
  55. package/dist/daemon/launcher.d.ts +24 -29
  56. package/dist/daemon/launcher.mjs +16 -16
  57. package/dist/daemon/local-tokens.d.ts +23 -0
  58. package/dist/daemon/lockfile.d.ts +10 -12
  59. package/dist/daemon/lockfile.mjs +2 -2
  60. package/dist/daemon/oauth-consent-cache.d.ts +86 -0
  61. package/dist/daemon/oauth-provider.d.ts +132 -0
  62. package/dist/daemon/public-pages.d.ts +9 -0
  63. package/dist/daemon/security.d.ts +52 -0
  64. package/dist/daemon/server.d.ts +12 -83
  65. package/dist/daemon/server.mjs +11 -11
  66. package/dist/daemon/token.d.ts +7 -9
  67. package/dist/daemon/token.mjs +2 -2
  68. package/dist/daemon/tunnel-providers/cloudflared-named-setup.d.ts +140 -0
  69. package/dist/daemon/tunnel-providers/cloudflared-named.d.ts +45 -0
  70. package/dist/daemon/tunnel-providers/cloudflared-quick.d.ts +8 -0
  71. package/dist/daemon/tunnel-providers/index.d.ts +16 -327
  72. package/dist/daemon/tunnel-providers/index.mjs +3 -3
  73. package/dist/daemon/tunnel-providers/ngrok-config.d.ts +18 -0
  74. package/dist/daemon/tunnel-providers/ngrok.d.ts +68 -0
  75. package/dist/daemon/tunnel-providers/types.d.ts +56 -0
  76. package/dist/daemon/tunnel.d.ts +5 -7
  77. package/dist/debug-tracer.d.ts +2 -0
  78. package/dist/doctor-report.d.ts +17 -22
  79. package/dist/doctor.d.ts +12 -44
  80. package/dist/doctor.mjs +2 -2
  81. package/dist/export.d.ts +11 -18
  82. package/dist/export.mjs +4 -4
  83. package/dist/format.d.ts +52 -0
  84. package/dist/fs-utils.d.ts +8 -0
  85. package/dist/health-check.d.ts +1 -108
  86. package/dist/health-check.mjs +3 -3
  87. package/dist/history-store.d.ts +29 -65
  88. package/dist/history-store.mjs +2 -2
  89. package/dist/impit-login-runner.d.ts +1 -469
  90. package/dist/impit-login-runner.mjs +4 -4
  91. package/dist/index.d.ts +25 -149
  92. package/dist/index.mjs +22 -20
  93. package/dist/is-main-module.d.ts +9 -0
  94. package/dist/login-runner.d.ts +1 -333
  95. package/dist/login-runner.mjs +13 -13
  96. package/dist/login.d.ts +5 -0
  97. package/dist/logout.d.ts +2 -28
  98. package/dist/logout.mjs +3 -2
  99. package/dist/manual-login-runner.d.ts +1 -150
  100. package/dist/manual-login-runner.mjs +11 -11
  101. package/dist/{native-deps-IE4B55EL.mjs → native-deps-FCSYDL4W.mjs} +4 -4
  102. package/dist/native-deps.d.ts +36 -0
  103. package/dist/package-version.d.ts +1 -0
  104. package/dist/profiles.d.ts +41 -41
  105. package/dist/profiles.mjs +1 -1
  106. package/dist/prompts.d.ts +2 -0
  107. package/dist/redact.d.ts +14 -142
  108. package/dist/refresh.d.ts +11 -16
  109. package/dist/refresh.mjs +4 -4
  110. package/dist/reinit-watcher.d.ts +15 -24
  111. package/dist/reinit-watcher.mjs +2 -2
  112. package/dist/resources.d.ts +5 -0
  113. package/dist/safe-write.d.ts +16 -0
  114. package/dist/session-metadata.d.ts +45 -0
  115. package/dist/tool-config.d.ts +10 -0
  116. package/dist/tools.d.ts +23 -0
  117. package/dist/tty-prompt.d.ts +18 -34
  118. package/dist/vault.d.ts +114 -34
  119. package/dist/vault.mjs +6 -4
  120. package/dist/viewer-detect.d.ts +2 -4
  121. package/dist/viewers.d.ts +13 -18
  122. package/dist/viewers.mjs +1 -1
  123. package/package.json +2 -2
  124. package/dist/cloud-sync.d-Cqt6y18U.d.ts +0 -42
  125. package/dist/doctor.d-CXmUqOXX.d.ts +0 -43
  126. package/dist/history-store.d-BzjBF2m3.d.ts +0 -65
  127. package/dist/native-deps-BNThFHxa.d.ts +0 -175
  128. package/dist/profiles.d-DqS1oZWr.d.ts +0 -41
  129. package/dist/session-metadata-B9aV_n5g.d.ts +0 -148
  130. package/dist/vault.d-BSJWDLhp.d.ts +0 -37
  131. package/dist/viewer-detect.d-HWGnyFAA.d.ts +0 -4
  132. package/dist/viewers.d-BGCK6sw6.d.ts +0 -10
@@ -2,22 +2,22 @@ import {
2
2
  appendAuditEntry,
3
3
  getAuditLogPath,
4
4
  readAuditTail
5
- } from "./chunk-V4U3JM4R.mjs";
5
+ } from "./chunk-TSLRTZYR.mjs";
6
6
  import {
7
7
  ensureToken,
8
8
  getTokenPath,
9
9
  rotateToken
10
- } from "./chunk-TDXETAQT.mjs";
10
+ } from "./chunk-DKEJZ4FI.mjs";
11
11
  import {
12
12
  hydrateCloudHistoryEntry,
13
13
  syncCloudHistory
14
- } from "./chunk-2FPGJKCA.mjs";
14
+ } from "./chunk-2EE7MNP2.mjs";
15
15
  import {
16
16
  PerplexityClient,
17
17
  exportThreadViaImpit,
18
18
  readCachedAccountInfoFromDisk,
19
19
  retrieveThreadViaImpit
20
- } from "./chunk-C3HPFFTD.mjs";
20
+ } from "./chunk-WHVJ724K.mjs";
21
21
  import {
22
22
  append,
23
23
  findPendingByThread,
@@ -26,13 +26,13 @@ import {
26
26
  getHistoryDir,
27
27
  list,
28
28
  update
29
- } from "./chunk-B65IJQZJ.mjs";
29
+ } from "./chunk-6E6XTHTG.mjs";
30
30
  import {
31
31
  safeAtomicWriteFileSync
32
32
  } from "./chunk-MTDFKNXX.mjs";
33
33
  import {
34
34
  getConfigDir
35
- } from "./chunk-HJIXH6CL.mjs";
35
+ } from "./chunk-E3GRJXXJ.mjs";
36
36
 
37
37
  // src/daemon/server.ts
38
38
  import { createServer } from "http";
@@ -2,11 +2,11 @@ import {
2
2
  PerplexityClient,
3
3
  getCloudThreadViaImpit,
4
4
  listCloudThreadsViaImpit
5
- } from "./chunk-C3HPFFTD.mjs";
5
+ } from "./chunk-WHVJ724K.mjs";
6
6
  import {
7
7
  hydrateCloudEntry,
8
8
  upsertFromCloud
9
- } from "./chunk-B65IJQZJ.mjs";
9
+ } from "./chunk-6E6XTHTG.mjs";
10
10
 
11
11
  // src/cloud-sync.js
12
12
  var DEFAULT_PAGE_SIZE = 1e3;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  ensureDaemon
3
- } from "./chunk-RK4EBZJ3.mjs";
3
+ } from "./chunk-E75J42W5.mjs";
4
4
 
5
5
  // src/daemon/attach.ts
6
6
  import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  getConfigDir,
3
3
  getProfilePaths
4
- } from "./chunk-HJIXH6CL.mjs";
4
+ } from "./chunk-E3GRJXXJ.mjs";
5
5
 
6
6
  // src/reinit-watcher.js
7
7
  import { existsSync, mkdirSync, watch } from "fs";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  getActiveName,
3
3
  getProfilePaths
4
- } from "./chunk-HJIXH6CL.mjs";
4
+ } from "./chunk-E3GRJXXJ.mjs";
5
5
 
6
6
  // src/history-store.js
7
7
  import { randomUUID } from "crypto";
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-MTDFKNXX.mjs";
4
4
  import {
5
5
  getProfilePaths
6
- } from "./chunk-HJIXH6CL.mjs";
6
+ } from "./chunk-E3GRJXXJ.mjs";
7
7
 
8
8
  // src/vault.js
9
9
  import { createCipheriv, createDecipheriv, randomBytes, hkdfSync, scrypt as nodeScrypt } from "crypto";
@@ -32,6 +32,7 @@ var V3_HEADER_FIXED_PREAMBLE = 4 + 1 + 1 + 1;
32
32
  var scryptAsync = promisify(nodeScrypt);
33
33
  var _kdfParamsOverride = null;
34
34
  var _kdfTestModeActive = false;
35
+ var _keytarModuleCache = null;
35
36
  function __setKdfParamsForTest(params) {
36
37
  if (!params || typeof params.logN !== "number" || typeof params.r !== "number" || typeof params.p !== "number") {
37
38
  throw new Error("__setKdfParamsForTest requires {logN, r, p} numbers.");
@@ -197,17 +198,30 @@ var KEYTAR_SERVICE = "perplexity-user-mcp";
197
198
  var KEYTAR_ACCOUNT = "vault-master-key";
198
199
  var _keyCache = null;
199
200
  var _unsealMaterialCache = null;
201
+ function isKeychainDisabled() {
202
+ return process.env.PERPLEXITY_DISABLE_KEYCHAIN === "1";
203
+ }
200
204
  function __resetKeyCache() {
201
205
  _keyCache = null;
202
206
  _unsealMaterialCache = null;
203
207
  _kdfParamsOverride = null;
204
208
  _kdfTestModeActive = false;
209
+ _keytarModuleCache = null;
205
210
  }
206
211
  async function tryKeytar() {
212
+ if (isKeychainDisabled()) return null;
213
+ if (_keytarModuleCache !== null) return _keytarModuleCache;
207
214
  try {
208
215
  const mod = await import("keytar");
209
- return mod.default ?? mod;
216
+ const keytar = mod.default ?? mod;
217
+ if (!keytar || typeof keytar.getPassword !== "function") {
218
+ _keytarModuleCache = false;
219
+ return null;
220
+ }
221
+ _keytarModuleCache = keytar;
222
+ return keytar;
210
223
  } catch {
224
+ _keytarModuleCache = false;
211
225
  return null;
212
226
  }
213
227
  }
@@ -228,6 +242,21 @@ async function keyFromKeychain() {
228
242
  return null;
229
243
  }
230
244
  }
245
+ async function probeKeychainState() {
246
+ if (isKeychainDisabled()) {
247
+ return { available: false, hasKey: false };
248
+ }
249
+ const keytar = await tryKeytar();
250
+ if (!keytar || typeof keytar.getPassword !== "function") {
251
+ return { available: false, hasKey: false };
252
+ }
253
+ try {
254
+ const hex = await keytar.getPassword(KEYTAR_SERVICE, KEYTAR_ACCOUNT);
255
+ return { available: true, hasKey: !!hex };
256
+ } catch {
257
+ return { available: true, hasKey: false };
258
+ }
259
+ }
231
260
  function isStdioServerMode() {
232
261
  return process.env.PERPLEXITY_MCP_STDIO === "1" || process.stdin && process.stdin.isTTY === false;
233
262
  }
@@ -383,6 +412,7 @@ export {
383
412
  encryptBlob,
384
413
  decryptBlob,
385
414
  __resetKeyCache,
415
+ probeKeychainState,
386
416
  getUnsealMaterial,
387
417
  getAllUnsealMaterials,
388
418
  getMasterKey,
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-MTDFKNXX.mjs";
4
4
  import {
5
5
  getConfigDir
6
- } from "./chunk-HJIXH6CL.mjs";
6
+ } from "./chunk-E3GRJXXJ.mjs";
7
7
 
8
8
  // src/daemon/token.ts
9
9
  import { randomBytes } from "crypto";
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  Vault
3
- } from "./chunk-S677V2JU.mjs";
3
+ } from "./chunk-C5I7KXHK.mjs";
4
4
  import {
5
5
  getActiveName,
6
6
  getProfilePaths
7
- } from "./chunk-HJIXH6CL.mjs";
7
+ } from "./chunk-E3GRJXXJ.mjs";
8
8
 
9
9
  // src/config.ts
10
10
  import { existsSync } from "fs";
@@ -192,16 +192,35 @@ async function getSavedCookies() {
192
192
  }
193
193
  return cookies;
194
194
  }
195
- const raw = await _vault.get(activeName(), "cookies").catch((err) => {
195
+ const profile = activeName();
196
+ let unsealFailed = false;
197
+ const raw = await _vault.get(profile, "cookies").catch((err) => {
198
+ unsealFailed = true;
196
199
  const msg = err instanceof Error ? err.message : String(err);
197
- console.error(`[vault] getSavedCookies failed for profile ${activeName()}: ${msg}`);
200
+ console.error(`[vault] getSavedCookies failed for profile '${profile}': ${msg}`);
198
201
  return null;
199
202
  });
200
- if (!raw) return [];
203
+ if (!raw) {
204
+ if (!unsealFailed) {
205
+ const paths = getProfilePaths(profile);
206
+ if (!existsSync(paths.vault)) {
207
+ console.error(`[vault] getSavedCookies: no vault.enc for profile '${profile}' \u2014 run login first`);
208
+ } else {
209
+ console.error(`[vault] getSavedCookies: vault.enc exists for profile '${profile}' but 'cookies' key is absent`);
210
+ }
211
+ }
212
+ return [];
213
+ }
201
214
  try {
202
215
  const parsed = JSON.parse(raw);
203
- return Array.isArray(parsed) ? parsed : [];
204
- } catch {
216
+ if (!Array.isArray(parsed)) {
217
+ console.error(`[vault] getSavedCookies: 'cookies' value for profile '${profile}' is not an array (${typeof parsed})`);
218
+ return [];
219
+ }
220
+ return parsed;
221
+ } catch (err) {
222
+ const msg = err instanceof Error ? err.message : String(err);
223
+ console.error(`[vault] getSavedCookies: JSON parse failed for profile '${profile}': ${msg}`);
205
224
  return [];
206
225
  }
207
226
  }
@@ -17,7 +17,9 @@ function getProfilePaths(name) {
17
17
  vault: join(dir, "vault.enc"),
18
18
  vaultPlain: join(dir, "vault.json"),
19
19
  browserData: join(dir, "browser-data"),
20
+ loginBrowserData: join(dir, "login-browser-data"),
20
21
  modelsCache: join(dir, "models-cache.json"),
22
+ daemonStatus: join(dir, "daemon-status.json"),
21
23
  history: join(dir, "history"),
22
24
  attachments: join(dir, "attachments"),
23
25
  researches: join(dir, "researches"),
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  getTunnelProvider,
3
3
  readTunnelSettings
4
- } from "./chunk-XTRJSV72.mjs";
4
+ } from "./chunk-LGH5BSUY.mjs";
5
5
  import {
6
6
  acquire,
7
7
  getLockfilePath,
@@ -9,27 +9,27 @@ import {
9
9
  read,
10
10
  release,
11
11
  replace
12
- } from "./chunk-KJFX2ZXR.mjs";
12
+ } from "./chunk-NMKNEEZB.mjs";
13
13
  import {
14
14
  getPackageVersion,
15
15
  startDaemonServer
16
- } from "./chunk-T6ARJK2P.mjs";
16
+ } from "./chunk-2B5OQUXR.mjs";
17
17
  import {
18
18
  ensureToken,
19
19
  getTokenPath,
20
20
  readToken
21
- } from "./chunk-TDXETAQT.mjs";
21
+ } from "./chunk-DKEJZ4FI.mjs";
22
22
  import {
23
23
  watchActiveProfile,
24
24
  watchReinit
25
- } from "./chunk-WDIW33DA.mjs";
25
+ } from "./chunk-3LUO5ATM.mjs";
26
26
  import {
27
27
  PerplexityClient
28
- } from "./chunk-C3HPFFTD.mjs";
28
+ } from "./chunk-WHVJ724K.mjs";
29
29
  import {
30
30
  getActiveName,
31
31
  getConfigDir
32
- } from "./chunk-HJIXH6CL.mjs";
32
+ } from "./chunk-E3GRJXXJ.mjs";
33
33
 
34
34
  // src/daemon/launcher.ts
35
35
  import { spawn } from "child_process";
@@ -671,11 +671,14 @@ async function spawnDetachedDaemon(options) {
671
671
  if (options.tunnel) {
672
672
  args.push("--tunnel");
673
673
  }
674
+ const env = { ...process.env };
675
+ delete env.PERPLEXITY_HEADLESS_ONLY;
676
+ delete env.PERPLEXITY_NO_DAEMON;
674
677
  const child = spawn(process.execPath, args, {
675
678
  detached: true,
676
679
  stdio: "ignore",
677
680
  env: {
678
- ...process.env,
681
+ ...env,
679
682
  PERPLEXITY_CONFIG_DIR: options.configDir
680
683
  }
681
684
  });
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  ensureDaemon
3
- } from "./chunk-RK4EBZJ3.mjs";
3
+ } from "./chunk-E75J42W5.mjs";
4
4
  import {
5
5
  getPackageVersion
6
- } from "./chunk-T6ARJK2P.mjs";
6
+ } from "./chunk-2B5OQUXR.mjs";
7
7
 
8
8
  // src/daemon/client-http.ts
9
9
  import { randomUUID } from "crypto";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  PERPLEXITY_URL
3
- } from "./chunk-U7QPUNRH.mjs";
3
+ } from "./chunk-DXR6EEZH.mjs";
4
4
 
5
5
  // src/export.js
6
6
  import { Buffer } from "buffer";
@@ -0,0 +1,17 @@
1
+ // src/is-main-module.js
2
+ import { realpathSync } from "fs";
3
+ import { fileURLToPath, pathToFileURL } from "url";
4
+ function isMainModule(metaUrl) {
5
+ if (!process.argv[1]) return false;
6
+ try {
7
+ const moduleReal = realpathSync(fileURLToPath(metaUrl));
8
+ const argvReal = realpathSync(process.argv[1]);
9
+ return moduleReal === argvReal;
10
+ } catch {
11
+ return metaUrl === pathToFileURL(process.argv[1]).href;
12
+ }
13
+ }
14
+
15
+ export {
16
+ isMainModule
17
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getConfigDir
3
- } from "./chunk-HJIXH6CL.mjs";
3
+ } from "./chunk-E3GRJXXJ.mjs";
4
4
  import {
5
5
  __glob
6
6
  } from "./chunk-4UEJOM6W.mjs";
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-6YMQVLFX.mjs";
4
4
  import {
5
5
  getTunnelBinaryPath
6
- } from "./chunk-FKQ3HP4Q.mjs";
6
+ } from "./chunk-TIWHN4IW.mjs";
7
7
  import {
8
8
  safeAtomicWriteFileSync
9
9
  } from "./chunk-MTDFKNXX.mjs";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getConfigDir
3
- } from "./chunk-HJIXH6CL.mjs";
3
+ } from "./chunk-E3GRJXXJ.mjs";
4
4
 
5
5
  // src/daemon/lockfile.ts
6
6
  import { closeSync, existsSync, mkdirSync, openSync, readFileSync, renameSync, rmSync, writeFileSync } from "fs";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getConfigDir
3
- } from "./chunk-HJIXH6CL.mjs";
3
+ } from "./chunk-E3GRJXXJ.mjs";
4
4
 
5
5
  // src/daemon/install-tunnel.ts
6
6
  import { createHash } from "crypto";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getConfigDir
3
- } from "./chunk-HJIXH6CL.mjs";
3
+ } from "./chunk-E3GRJXXJ.mjs";
4
4
 
5
5
  // src/daemon/audit.ts
6
6
  import { appendFileSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, statSync } from "fs";
@@ -9,12 +9,12 @@ import {
9
9
  getOrCreateContext,
10
10
  getSavedCookies,
11
11
  resolveBrowserExecutable
12
- } from "./chunk-U7QPUNRH.mjs";
12
+ } from "./chunk-DXR6EEZH.mjs";
13
13
  import {
14
14
  getActiveName,
15
15
  getConfigDir,
16
16
  getProfilePaths
17
- } from "./chunk-HJIXH6CL.mjs";
17
+ } from "./chunk-E3GRJXXJ.mjs";
18
18
 
19
19
  // src/refresh.ts
20
20
  import { readFileSync, writeFileSync, existsSync, statSync, mkdirSync } from "fs";
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  impitFetchJson,
3
3
  isImpitAvailable
4
- } from "./chunk-DQQISMYN.mjs";
4
+ } from "./chunk-V4LHDNWJ.mjs";
5
5
  import {
6
6
  FORMAT_TO_CONTENT_TYPE,
7
7
  exportThread,
8
8
  resolveExportApiFormat
9
- } from "./chunk-D254EFYB.mjs";
9
+ } from "./chunk-GBI2U336.mjs";
10
10
  import {
11
11
  ASI_ACCESS_ENDPOINT,
12
12
  AUTH_SESSION_ENDPOINT,
@@ -18,15 +18,14 @@ import {
18
18
  SUPPORTED_BLOCK_USE_CASES,
19
19
  THREAD_ENDPOINT,
20
20
  findBrowser,
21
- getOrCreateContext,
22
21
  getSavedCookies,
23
22
  resolveBrowserExecutable
24
- } from "./chunk-U7QPUNRH.mjs";
23
+ } from "./chunk-DXR6EEZH.mjs";
25
24
  import {
26
25
  getActiveName,
27
26
  getConfigDir,
28
27
  getProfilePaths
29
- } from "./chunk-HJIXH6CL.mjs";
28
+ } from "./chunk-E3GRJXXJ.mjs";
30
29
 
31
30
  // src/client.ts
32
31
  import { randomUUID } from "crypto";
@@ -558,47 +557,55 @@ var PerplexityClient = class _PerplexityClient {
558
557
  * Set env PERPLEXITY_HEADLESS_ONLY=1 to skip the headed phase (uses disk cache).
559
558
  */
560
559
  async init() {
561
- const activePaths = getActivePaths();
562
- if (!existsSync(activePaths.browserData)) {
563
- mkdirSync(activePaths.browserData, { recursive: true });
564
- }
565
- const browser = await resolveBrowserExecutable();
566
- console.error(`[perplexity-mcp] Using ${browser.source}: ${browser.path}`);
567
- const skipHeaded = process.env.PERPLEXITY_HEADLESS_ONLY === "1";
568
- if (!skipHeaded) {
569
- await this.headedBootstrap();
570
- } else {
571
- console.error("[perplexity-mcp] Skipping headed session (PERPLEXITY_HEADLESS_ONLY=1).");
572
- this.loadCachedAccountInfo();
573
- }
574
- console.error("[perplexity-mcp] Launching headless browser...");
575
- const launchOpts = buildLaunchOptions(true);
576
- this.browser = await chromium.launch({
577
- headless: launchOpts.headless,
578
- args: launchOpts.args,
579
- ...launchOpts.executablePath ? { executablePath: launchOpts.executablePath } : {},
580
- ...launchOpts.channel ? { channel: launchOpts.channel } : {},
581
- ignoreDefaultArgs: launchOpts.ignoreDefaultArgs
582
- });
583
- this.context = await getOrCreateContext(this.browser, {
584
- viewport: launchOpts.viewport,
585
- userAgent: launchOpts.userAgent
586
- });
587
- const saved = await getSavedCookies();
588
- if (saved.length > 0) {
589
- await this.context.addCookies(saved);
590
- console.error(`[perplexity-mcp] Injected ${saved.length} saved cookies into browser context.`);
591
- }
592
- this.page = await this.context.newPage();
560
+ const _initAt = Date.now();
593
561
  try {
594
- await this.page.goto(PERPLEXITY_URL, { waitUntil: "domcontentloaded", timeout: 3e4 });
595
- await this.page.waitForTimeout(2e3);
562
+ const activePaths = getActivePaths();
563
+ if (!existsSync(activePaths.browserData)) {
564
+ mkdirSync(activePaths.browserData, { recursive: true });
565
+ }
566
+ const browser = await resolveBrowserExecutable();
567
+ console.error(`[perplexity-mcp] Using ${browser.source}: ${browser.path}`);
568
+ const skipHeaded = process.env.PERPLEXITY_HEADLESS_ONLY === "1";
569
+ if (!skipHeaded) {
570
+ await this.headedBootstrap();
571
+ } else {
572
+ console.error("[perplexity-mcp] Skipping headed session (PERPLEXITY_HEADLESS_ONLY=1).");
573
+ this.loadCachedAccountInfo();
574
+ }
575
+ console.error("[perplexity-mcp] Launching headless persistent browser...");
576
+ const launchOpts = buildLaunchOptions(true);
577
+ this.context = await chromium.launchPersistentContext(
578
+ activePaths.browserData,
579
+ launchOpts
580
+ );
581
+ this.browser = this.context.browser();
582
+ const saved = await getSavedCookies();
583
+ if (saved.length > 0) {
584
+ const current = await this.context.cookies();
585
+ const currentNames = new Set(current.map((c) => c.name));
586
+ const toInject = saved.filter((c) => !currentNames.has(c.name));
587
+ if (toInject.length > 0) {
588
+ await this.context.addCookies(toInject);
589
+ console.error(`[perplexity-mcp] Injected ${toInject.length} missing cookies from vault.`);
590
+ } else {
591
+ console.error("[perplexity-mcp] All vault cookies already present on disk; skipping injection.");
592
+ }
593
+ }
594
+ this.page = await this.context.newPage();
595
+ try {
596
+ await this.page.goto(PERPLEXITY_URL, { waitUntil: "domcontentloaded", timeout: 3e4 });
597
+ await this.page.waitForTimeout(2e3);
598
+ } catch (err) {
599
+ console.error("[perplexity-mcp] Navigation warning:", err.message);
600
+ }
601
+ await this.checkAuth();
602
+ if (!this.accountInfo.modelsConfig) {
603
+ await this.loadAccountInfo();
604
+ }
605
+ this.writeDaemonStatus(_initAt, null);
596
606
  } catch (err) {
597
- console.error("[perplexity-mcp] Navigation warning:", err.message);
598
- }
599
- await this.checkAuth();
600
- if (!this.accountInfo.modelsConfig) {
601
- await this.loadAccountInfo();
607
+ this.writeDaemonStatus(_initAt, err instanceof Error ? err.message : String(err));
608
+ throw err;
602
609
  }
603
610
  }
604
611
  /**
@@ -1935,6 +1942,39 @@ View at: ${PERPLEXITY_URL}/search/${threadSlug}`,
1935
1942
  });
1936
1943
  this.browser = null;
1937
1944
  }
1945
+ this.authenticated = false;
1946
+ this.userId = null;
1947
+ this.writeDaemonStatus(Date.now(), null);
1948
+ }
1949
+ // ── Daemon status file ─────────────────────────────────────────────────────
1950
+ daemonTier() {
1951
+ if (!this.authenticated) return "Anonymous";
1952
+ if (this.accountInfo.isMax) return "Max";
1953
+ if (this.accountInfo.isPro) return "Pro";
1954
+ if (this.accountInfo.isEnterprise) return "Enterprise";
1955
+ return "Authenticated";
1956
+ }
1957
+ /**
1958
+ * Write daemon-status.json so the extension UI can show live auth state
1959
+ * instead of relying on the stale models-cache.json snapshot.
1960
+ * @param startedAt - Date.now() captured at the start of init/reinit
1961
+ * @param error - error message if init threw, null on success or shutdown
1962
+ */
1963
+ writeDaemonStatus(startedAt, error) {
1964
+ try {
1965
+ const paths = getActivePaths();
1966
+ const status = {
1967
+ authenticated: this.authenticated,
1968
+ tier: this.daemonTier(),
1969
+ userId: this.userId,
1970
+ pid: process.pid,
1971
+ lastInit: (/* @__PURE__ */ new Date()).toISOString(),
1972
+ initDurationMs: Date.now() - startedAt,
1973
+ error
1974
+ };
1975
+ writeFileSync(paths.daemonStatus, JSON.stringify(status, null, 2) + "\n");
1976
+ } catch {
1977
+ }
1938
1978
  }
1939
1979
  };
1940
1980