@mrrisega/dsh-remote 0.3.9 → 0.4.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.
package/dsh-setup.mjs CHANGED
@@ -99,6 +99,19 @@ function deriveTunnelUrl(apiUrl) {
99
99
  return apiUrl.replace(/\/relay-api\/?$/, "").replace(/^https/, "wss");
100
100
  }
101
101
 
102
+ /**
103
+ * 模式归一化(SaaS 权威):清掉自建残留(local_key/假 tunnel_url),api_url 与
104
+ * tunnel_url 一律按云端权威地址重算。防止"切过自建后又登云端"时残留配置把
105
+ * bridge 带到错误服务器(此前手机永远看不到设备的根因之一)。
106
+ */
107
+ function applySaaSMode(cfg) {
108
+ delete cfg.local_key;
109
+ delete cfg.server; // 旧字段兜底
110
+ cfg.api_url = String(cfg.api_url || DEFAULT_API).replace(/\/+$/, "");
111
+ cfg.tunnel_url = deriveTunnelUrl(cfg.api_url);
112
+ return cfg;
113
+ }
114
+
102
115
  /** 归一化自建服务器地址:缺省补 wss://,去掉末尾 / */
103
116
  function normalizeTunnelUrl(raw) {
104
117
  let u = String(raw || "").trim().replace(/\/+$/, "");
@@ -239,9 +252,7 @@ function serveSettings() {
239
252
  return send(400, JSON.stringify({ ok: false, message: "SaaS 模式需要手机号与密码" }), "application/json");
240
253
  }
241
254
  cfg.phone = body.phone; cfg.password = body.password;
242
- delete cfg.local_key;
243
- cfg.api_url = body.api_url || cfg.api_url || DEFAULT_API;
244
- if (!cfg.tunnel_url) cfg.tunnel_url = deriveTunnelUrl(cfg.api_url);
255
+ applySaaSMode(cfg); // 清自建残留,api/tunnel 权威重算
245
256
  }
246
257
  // 自动获取服务端下发的 bridge_secret(device-login 共享密钥,一键安装开箱即用)
247
258
  if (!cfg.bridge_secret && !cfg.local_key) {
@@ -328,7 +339,7 @@ async function runBridge() {
328
339
  // 每次循环重读配置:设置页登录/切换模式后无需重启守护即可生效
329
340
  cfg = loadConfig();
330
341
  const saas = Boolean((cfg.phone || cfg.email) && cfg.password);
331
- const local = Boolean(cfg.local_key);
342
+ let local = Boolean(cfg.local_key);
332
343
  if (!saas && !local) {
333
344
  if (!warnedNoLogin) {
334
345
  warnedNoLogin = true;
@@ -341,9 +352,13 @@ async function runBridge() {
341
352
  console.log("⚠️ 自建模式缺少服务器地址:请用 `dsh-remote setup --server wss://host:port --key <密钥>` 重新配置。");
342
353
  return;
343
354
  }
344
- if (saas && !cfg.tunnel_url) {
345
- cfg.tunnel_url = deriveTunnelUrl(cfg.api_url || DEFAULT_API);
355
+ if (saas) {
356
+ // SaaS 权威归一化:清掉任何自建残留,tunnel/api 始终指向云端地址
357
+ applySaaSMode(cfg);
358
+ local = false;
346
359
  saveConfig(cfg);
360
+ } else if (local && !cfg.tunnel_url) {
361
+ cfg.tunnel_url = deriveTunnelUrl(cfg.api_url || DEFAULT_API);
347
362
  }
348
363
  const apiUrl = saas ? (cfg.api_url || DEFAULT_API) : "";
349
364
 
@@ -458,7 +473,8 @@ async function setup(argv) {
458
473
  console.log(` 手机端: 打开 ${cfg.tunnel_url.replace(/^ws/, "https")}/app/ ,用访问密钥登录即可。`);
459
474
  } else {
460
475
  console.log(` 远程控制地址: ${pub.app_url || DEFAULT_APP_URL}`);
461
- console.log(` 下一步: 运行 \`dsh-remote settings\` 打开设置页,用手机号+密码登录(或注册)。`);
476
+ console.log(` 下一步(小白/无需任何命令): 打开 dsh web → 设置 → 「远程控制」→ 注册/登录手机号即可。`);
477
+ console.log(` 若你是从 DeepSeek App/插件市场 安装:请【完全退出并重开 App】(或刷新 profile),插件即生效。`);
462
478
  console.log(` 登录后 bridge 会自动启动,手机端即可看到本机。`);
463
479
  }
464
480
  if (svc.path) console.log(` 自启动服务: ${svc.path}`);
@@ -652,7 +668,8 @@ async function pluginCmd(argv) {
652
668
  : "✅ node_modules/dsh-remote-ui 已就绪");
653
669
 
654
670
  console.log(`✅ 插件安装完成。配置目录: ${CONFIG_DIR}`);
655
- console.log(" 重启 dsh web(或重开 profile)后,在「设置远程控制」查看面板。");
671
+ console.log(" 打开 dsh web 设置 「远程控制」,注册/登录手机号即可(无需任何命令)。");
672
+ console.log(" 若从 DeepSeek App/插件市场 安装:请完全退出并重开 App 让插件生效。");
656
673
  }
657
674
 
658
675
  // ---------- main ----------
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrrisega/dsh-remote",
3
- "version": "0.3.9",
3
+ "version": "0.4.0",
4
4
  "description": "手机远程控制 DeepSeek Harness · Remote control DeepSeek Harness (dsh web) from any phone browser — 100% 全功能 App 级体验:发消息、看工具执行、审批权限、改设置、管凭据,含特权操作,免内网穿透。一条命令安装 npx @mrrisega/dsh-remote。Mobile remote control for DSH, self-host or SaaS, no server needed on LAN.",
5
5
  "keywords": [
6
6
  "deepseek-harness",
@@ -106,6 +106,19 @@ function saveConfig(relayDir, cfg) {
106
106
  }
107
107
  }
108
108
 
109
+ /**
110
+ * SaaS 模式权威归一化(与 dsh-setup.mjs 同规则):
111
+ * 清除自建残留(local_key/假 tunnel_url),api_url 与 tunnel_url 一律按云端权威地址重算。
112
+ * 解决“切过自建(填了假地址)后,再登/重装云端账号仍连错服务器、手机看不到设备”的残留配置问题。
113
+ */
114
+ function applySaaSMode(cfg) {
115
+ delete cfg.local_key;
116
+ delete cfg.server;
117
+ cfg.api_url = String(cfg.api_url || DEFAULT_API).replace(/\/+$/, "");
118
+ cfg.tunnel_url = cfg.api_url.replace(/\/relay-api\/?$/, "").replace(/^https/, "wss");
119
+ return cfg;
120
+ }
121
+
109
122
  // ---------- bridge 服务状态 / 启停(launchctl,macOS) ----------
110
123
 
111
124
  function launchAgentPath() {
@@ -524,14 +537,8 @@ function registerRoutes(ctx, relayDir) {
524
537
  delete cfg.device_private_key;
525
538
  delete cfg.device_public_key;
526
539
  }
527
- // 切回 SaaS:仅当此前是自建模式(local_key)才清理本地隧道/API 地址;
528
- // 正常 SaaS 用户的 tunnel_url 是核心配置(wss://公网域名),绝不能删
529
- const wasLocal = Boolean(cfg.local_key);
530
- delete cfg.local_key;
531
- if (wasLocal) {
532
- if (cfg.tunnel_url) delete cfg.tunnel_url;
533
- if (cfg.api_url) delete cfg.api_url;
534
- }
540
+ // SaaS 权威归一化:清除自建残留(local_key/假 tunnel_url),api/tunnel 一律按云端重算
541
+ applySaaSMode(cfg);
535
542
  }
536
543
  saveConfig(relayDir, cfg);
537
544
  const bridgeRestart = startBridge(relayDir);