dsh-plugin-mesh 0.5.5 → 0.5.6

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/lib/index.js CHANGED
@@ -64,23 +64,37 @@ import {
64
64
  import { TsnetNode, channelKey, channelSignature } from "./tsnet/manager.js";
65
65
  import { resolveTailnetChannels } from "./tsnet/channels.js";
66
66
  import { tailnetFetch, tailnetOrigin } from "./tsnet/bridge.js";
67
+ import { createWebProxy } from "./web-proxy.js";
68
+ import { createSecretReader } from "./desktop-auth.js";
69
+ import { createSshManager } from "./ssh-host.js";
70
+ import { acceptUpgrade } from "./ws-mini.js";
71
+ import {
72
+ createDesktopWebForwarder,
73
+ createDesktopWebUpgrade,
74
+ DESKTOP_WEB_PREFIX,
75
+ DESKTOP_WEB_STREAM_PATH,
76
+ } from "./desktop-web.js";
67
77
 
68
78
  export const name = "dsh-plugin-mesh";
69
79
  export const inject = ["tools", "webServer"];
70
80
 
71
- const VERSION = "0.5.5";
81
+ const VERSION = "0.5.6";
72
82
  // 诊断用:进程启动时间、入口真实路径、**磁盘上** package.json 的版本。
73
83
  // 这三样放一起才能回答"现在跑的到底是哪份代码" —— 只看 state.json 或重启日志
74
84
  // 都答不了(真踩过:磁盘升到 0.5.1,进程还在 0.5.0,界面显示 0.5.0)。
75
85
  const PROCESS_STARTED_AT = Date.now() - Math.round(process.uptime() * 1000);
76
86
  const ENTRY_INFO = entryInfo(import.meta.url);
77
87
  const DISK_VERSION = readPackageVersion(import.meta.url);
88
+ /** 一次性取文件用的 nonce:进程每次启动都换,写进日志给运维/agent 取。 */
89
+ const FILE_TRANSFER_NONCE = randomBytes(9).toString("base64url");
78
90
  const RULE_ID = "mesh-inbound";
79
91
  const RULE_KIND = "mesh";
80
92
  const MAX_BODY = 256 * 1024;
81
93
  const MAX_HISTORY = 200;
82
94
  /** 默认固定端口:内网里"扫这个端口 + ping 一下"就能建立连接,无需任何配置。 */
83
95
  export const MESH_DEFAULT_PORT = 45917;
96
+ /** 对端 DSH Web 的部署默认端口(回环代理拿不到对端自报地址时按它拼)。 */
97
+ const WEB_PANEL_DEFAULT_PORT = 3080;
84
98
 
85
99
  /**
86
100
  * 互联网自组网(tailnet)通道:通道 id → 节点句柄。
@@ -154,6 +168,12 @@ export const Config = z.object({
154
168
  * 同机跑多个实例时会被占用,此时自动退回随机端口(仍能用组播互相发现)。
155
169
  */
156
170
  port: z.natural().default(MESH_DEFAULT_PORT),
171
+ /**
172
+ * 本机另一个 DSH 引擎(通常是桌面 App)的 Web 端口:0 = 关闭这条前缀代理。
173
+ * 开了之后 `<本机>:<port>/mesh/web/...` 会转发到 127.0.0.1:<desktopWebPort>,
174
+ * 并自带签名 cookie —— 供手机在应用内查看"有历史会话的那个引擎"。
175
+ */
176
+ desktopWebPort: z.natural().max(65535).default(0),
157
177
  announceIntervalMs: z.natural().default(5000),
158
178
  /** 超过这么久没心跳、也没 ping 通,算离线 */
159
179
  peerTtlMs: z.natural().default(20000),
@@ -1189,6 +1209,7 @@ function applyUnsafe(ctx, config) {
1189
1209
  await syncRuntime({ reason: "启动" });
1190
1210
  log(
1191
1211
  `已启动 machine=${identity.name}(来源 ${identity.source})` +
1212
+ ` 文件搬运 nonce=${FILE_TRANSFER_NONCE}` +
1192
1213
  ` 地址=${preferredAddress()}:${discovery.port || "?"} 实例=${instanceId} ` +
1193
1214
  `配对要求=${config.requirePairing ? "开" : "关"} ` +
1194
1215
  `开关=${describeMeshSwitch(switchDesired)}`,
@@ -2320,9 +2341,70 @@ function startPeerServer(ctx, { config, discovery, inbound, outbound, log, warn,
2320
2341
 
2321
2342
  if (!authed(req)) return send(res, 403, { ok: false, error: "未配对:两台机器的配对码不一致(本机开启了 requirePairing)" });
2322
2343
 
2344
+ // 一次性文件搬运:给对端取本机插件包里的文件(同版本部署用)。
2345
+ // 只认启动时生成的 nonce,且路径必须落在插件包目录内 —— 不是通用文件服务。
2346
+ if (path === "/mesh/v1/file" && req.method === "GET") {
2347
+ const nonce = url.searchParams.get("k") ?? "";
2348
+ // 两个都认:进程内的随机 nonce,或本机的 mesh 密钥(可从 state.json 读到,
2349
+ // 方便"人在旁边"时一次搬运;两者都不用改配置)。
2350
+ if (!safeEqual(nonce, FILE_TRANSFER_NONCE) && !safeEqual(nonce, currentSecret())) {
2351
+ return send(res, 403, { ok: false, error: "nonce 不对" });
2352
+ }
2353
+ const wanted = url.searchParams.get("path") ?? "";
2354
+ const packageRoot = resolve(ENTRY_INFO.path, "..", "..");
2355
+ const absolute = resolve(wanted);
2356
+ if (!absolute.startsWith(`${packageRoot}/`)) {
2357
+ return send(res, 400, { ok: false, error: "路径超出插件包目录" });
2358
+ }
2359
+ try {
2360
+ const body = readFileSync(absolute);
2361
+ res.writeHead(200, {
2362
+ "content-type": "application/octet-stream",
2363
+ "content-length": String(body.length),
2364
+ });
2365
+ res.end(body);
2366
+ return;
2367
+ } catch (err) {
2368
+ return send(res, 404, { ok: false, error: String(err?.message ?? err) });
2369
+ }
2370
+ }
2371
+
2323
2372
  // 诊断:进程版本 vs 磁盘版本。**必须在对端鉴权之后** —— 里面有本机路径。
2324
2373
  if (path === "/mesh/v1/diagnostics") return send(res, 200, diagnostics());
2325
2374
 
2375
+ // 本机 DSH Web GUI 的入口地址(带启动 token)。
2376
+ //
2377
+ // 只在这里按需发放,**绝不**放进 discovery 广播:那条是明文组播,
2378
+ // 谁加入组播谁就能读到 token,等于把本机的 RCE 交给整个网段。
2379
+ // 走这条路径时要过 authed(),也就是跟着配对开关一起受保护。
2380
+ //
2381
+ // token 是进程级的、随重启轮换;浏览器第一次带 token 打开后会拿到
2382
+ // 一枚 30 天、绑定 authority 的签名 cookie,之后不带 token 也能开。
2383
+ if (path === "/mesh/v1/web-url" && req.method === "GET") {
2384
+ try {
2385
+ const connection = ctx.get("connection");
2386
+ const port = ctx.get("webServer")?.port;
2387
+ const bind = ctx.get("webServer")?.host ?? "";
2388
+ if (!connection || typeof connection.authenticatedUrl !== "function" || !port) {
2389
+ return send(res, 200, { ok: false, supported: false, error: "本端没有可用的 Web GUI(不是 web profile)" });
2390
+ }
2391
+ const lanHost = preferredAddress();
2392
+ // 只绑了回环时如实说:地址虽然给得出来,但局域网里连不通。
2393
+ const lanReachable = bind === "0.0.0.0" && !!lanHost;
2394
+ const host = lanReachable ? lanHost : "127.0.0.1";
2395
+ return send(res, 200, {
2396
+ ok: true,
2397
+ supported: true,
2398
+ url: connection.authenticatedUrl(`http://${host}:${port}/`),
2399
+ bind,
2400
+ lanReachable,
2401
+ port,
2402
+ });
2403
+ } catch (err) {
2404
+ return send(res, 200, { ok: false, supported: false, error: String(err?.message ?? err) });
2405
+ }
2406
+ }
2407
+
2326
2408
  if (path === "/mesh/v1/peers") return send(res, 200, { ok: true, peers: discovery.peers() });
2327
2409
 
2328
2410
  if (path === "/mesh/v1/tasks" && req.method === "GET") {
@@ -3497,5 +3579,326 @@ function registerUiRoutes(ctx, { discovery, config, identity, inbound, outbound,
3497
3579
  }
3498
3580
  });
3499
3581
 
3500
- log("UI 接口已挂载: /mesh/api/state|refresh|secret|send|probe");
3582
+ post("/mesh/api/web-url", async (req, res) => {
3583
+ const body = await readJson(req);
3584
+ const found = findPeer(String(body?.peer ?? "").trim());
3585
+ if (found.error) return send(res, 404, { ok: false, error: found.error });
3586
+ const target = found.peer;
3587
+ try {
3588
+ const r = await peerFetch(target, "/mesh/v1/web-url", {
3589
+ headers: { "X-Dsh-Mesh-Token": currentSecret() },
3590
+ timeoutMs: 5000,
3591
+ });
3592
+ const rb = await r.json().catch(() => ({}));
3593
+ // 400/404 = 对端是老版本插件,没有这条路由。如实区分"不支持"和"取不到"。
3594
+ if (!r.ok || rb?.ok !== true || typeof rb?.url !== "string") {
3595
+ return send(res, 200, {
3596
+ ok: false,
3597
+ supported: rb?.supported === true,
3598
+ error: rb?.error || `对端 HTTP ${r.status}`,
3599
+ });
3600
+ }
3601
+ return send(res, 200, {
3602
+ ok: true,
3603
+ url: rb.url,
3604
+ bind: rb.bind ?? "",
3605
+ lanReachable: rb.lanReachable === true,
3606
+ port: rb.port ?? 0,
3607
+ });
3608
+ } catch (err) {
3609
+ return send(res, 200, { ok: false, supported: false, error: String(err?.message ?? err) });
3610
+ }
3611
+ });
3612
+
3613
+ // ── 对端 DSH Web 的应用内面板(回环反代 + 服务端认证)─────────────────
3614
+ //
3615
+ // 为什么不直接把对端地址塞进 iframe:对端会话 cookie 是 SameSite=Strict,
3616
+ // 跨站 iframe 里不发送,token 又随对端重启轮换 —— 页面会永远停在 401。
3617
+ // 所以认证搬到服务端:代理用 token 换一次 cookie,之后每个请求自己带;
3618
+ // 浏览器只跟本机 127.0.0.1 的这个端口说话。
3619
+ const webPanels = new Map(); // 机器名 -> { proxy, remote }
3620
+
3621
+ // 对端会话 cookie 落盘:token 每次重启都会轮换,而 cookie 是 30 天、由对端
3622
+ // 持久密钥签名的 —— 存住它就等于以后不必再问 token(到期或换密钥再补一次)。
3623
+ const panelStatePath = () => join(stateDir(), "web-panels.json");
3624
+ const readPanelCookies = () => {
3625
+ try {
3626
+ const value = JSON.parse(readFileSync(panelStatePath(), "utf8"));
3627
+ return value && typeof value === "object" && !Array.isArray(value) ? value : {};
3628
+ } catch {
3629
+ return {};
3630
+ }
3631
+ };
3632
+ const writePanelCookie = (origin, cookie) => {
3633
+ try {
3634
+ const all = readPanelCookies();
3635
+ all[origin] = cookie;
3636
+ mkdirSync(stateDir(), { recursive: true });
3637
+ writeFileSync(panelStatePath(), JSON.stringify(all, null, 2));
3638
+ } catch (err) {
3639
+ warn(`保存对端 cookie 失败:${err?.message ?? err}`);
3640
+ }
3641
+ };
3642
+
3643
+ const closeWebPanels = async () => {
3644
+ const entries = [...webPanels.values()];
3645
+ webPanels.clear();
3646
+ for (const entry of entries) {
3647
+ try {
3648
+ await entry.proxy.close();
3649
+ } catch (err) {
3650
+ warn(`关闭 Web 面板代理失败:${err?.message ?? err}`);
3651
+ }
3652
+ }
3653
+ };
3654
+ ctx.effect(() => () => {
3655
+ void closeWebPanels();
3656
+ });
3657
+
3658
+ /** 取对端的 Web 地址与启动 token;老版本对端只能退回按约定拼地址。 */
3659
+ /**
3660
+ * 取对端的 Web 地址与启动 token。
3661
+ * @param target - 对端名片
3662
+ * @param tokenOverride - 调用方手工给的 token(对端插件还没升级时的逃生口)
3663
+ */
3664
+ async function resolveWebTarget(target, tokenOverride = "") {
3665
+ // 优先:对端开了 desktopWebPort 时,会有一条 /mesh/web/ 前缀转发到它自己的
3666
+ // 另一个引擎(桌面 App 那个,有历史会话)。有就直接用它,认证在对端完成。
3667
+ // 端点可能有多个(局域网 + tailnet),且顺序会变 —— 逐个试,别只认第一个。
3668
+ for (const ep of orderedEndpoints(target)) {
3669
+ if (!ep?.host) continue;
3670
+ const base = `http://${ep.host}:${WEB_PANEL_DEFAULT_PORT}`;
3671
+ try {
3672
+ const probe = await fetch(`${base}${DESKTOP_WEB_PREFIX}/__probe`, { signal: AbortSignal.timeout(2000) });
3673
+ const body = await probe.json().catch(() => ({}));
3674
+ if (probe.ok && body?.ok === true) {
3675
+ return {
3676
+ remoteBase: `${base}/`,
3677
+ pathPrefix: DESKTOP_WEB_PREFIX,
3678
+ passthrough: true,
3679
+ lanReachable: true,
3680
+ note: `转发到对端 ${body.target}`,
3681
+ };
3682
+ }
3683
+ } catch {
3684
+ /* 这条端点不通,试下一条 */
3685
+ }
3686
+ }
3687
+
3688
+ let remoteBase = "";
3689
+ let token = tokenOverride;
3690
+ let lanReachable;
3691
+ let note = "";
3692
+ try {
3693
+ const r = await peerFetch(target, "/mesh/v1/web-url", {
3694
+ headers: { "X-Dsh-Mesh-Token": currentSecret() },
3695
+ timeoutMs: 5000,
3696
+ });
3697
+ const rb = await r.json().catch(() => ({}));
3698
+ if (rb?.ok === true && typeof rb.url === "string") {
3699
+ const parsed = new URL(rb.url);
3700
+ token = parsed.searchParams.get("token") || token;
3701
+ // token 只用来换 cookie,别留在浏览器的地址栏里。
3702
+ parsed.searchParams.delete("token");
3703
+ remoteBase = parsed.href;
3704
+ lanReachable = rb.lanReachable === true;
3705
+ } else {
3706
+ note = rb?.error ? String(rb.error) : `对端 HTTP ${r.status}`;
3707
+ }
3708
+ } catch (err) {
3709
+ note = String(err?.message ?? err);
3710
+ }
3711
+ if (!remoteBase) {
3712
+ const ep = orderedEndpoints(target)[0];
3713
+ if (!ep?.host) return { error: note || "对端没有上报地址" };
3714
+ remoteBase = `http://${ep.host}:${WEB_PANEL_DEFAULT_PORT}/`;
3715
+ }
3716
+ if (!token) note = note || "对端没有给出 token(对端插件需升级到带 /mesh/v1/web-url 的版本)";
3717
+ return { remoteBase, token, lanReachable, note };
3718
+ }
3719
+
3720
+ post("/mesh/api/web-panel", async (req, res) => {
3721
+ const body = await readJson(req);
3722
+ const found = findPeer(String(body?.peer ?? "").trim());
3723
+ if (found.error) return send(res, 404, { ok: false, error: found.error });
3724
+ const target = found.peer;
3725
+ const machine = target.machine || String(body?.peer ?? "");
3726
+
3727
+ const resolved = await resolveWebTarget(
3728
+ target,
3729
+ typeof body?.token === "string" ? body.token.trim() : "",
3730
+ );
3731
+ if (resolved.error) return send(res, 400, { ok: false, error: resolved.error });
3732
+
3733
+ const signature = `${resolved.remoteBase}|${resolved.pathPrefix || ""}|${resolved.passthrough ? "p" : "c"}`;
3734
+ try {
3735
+ const existing = webPanels.get(machine);
3736
+ if (existing && existing.signature === signature) {
3737
+ return send(res, 200, {
3738
+ ok: true,
3739
+ url: existing.proxy.url,
3740
+ remote: existing.proxy.remote,
3741
+ hasSession: existing.proxy.hasSession(),
3742
+ note: resolved.note,
3743
+ lanReachable: resolved.lanReachable,
3744
+ });
3745
+ }
3746
+ if (existing) {
3747
+ webPanels.delete(machine);
3748
+ await existing.proxy.close();
3749
+ }
3750
+ const proxy = await createWebProxy({
3751
+ remoteBase: resolved.remoteBase,
3752
+ token: resolved.token,
3753
+ nonce: randomBytes(18).toString("base64url"),
3754
+ initialCookie: readPanelCookies()[resolved.remoteBase] || "",
3755
+ onCookie: (cookie) => writePanelCookie(resolved.remoteBase, cookie),
3756
+ pathPrefix: resolved.pathPrefix || "",
3757
+ passthrough: resolved.passthrough === true,
3758
+ log,
3759
+ warn,
3760
+ });
3761
+ webPanels.set(machine, { proxy, remote: resolved.remoteBase, signature });
3762
+ return send(res, 200, {
3763
+ ok: true,
3764
+ url: proxy.url,
3765
+ remote: proxy.remote,
3766
+ hasSession: proxy.hasSession(),
3767
+ note: resolved.note,
3768
+ lanReachable: resolved.lanReachable,
3769
+ });
3770
+ } catch (err) {
3771
+ return send(res, 502, { ok: false, error: String(err?.message ?? err) });
3772
+ }
3773
+ });
3774
+
3775
+ post("/mesh/api/web-panel/close", async (req, res) => {
3776
+ const body = await readJson(req);
3777
+ const machine = String(body?.peer ?? "").trim();
3778
+ const entry = webPanels.get(machine);
3779
+ if (entry) {
3780
+ webPanels.delete(machine);
3781
+ try {
3782
+ await entry.proxy.close();
3783
+ } catch (err) {
3784
+ warn(`关闭 Web 面板代理失败:${err?.message ?? err}`);
3785
+ }
3786
+ }
3787
+ return send(res, 200, { ok: true });
3788
+ });
3789
+
3790
+ // ── 「本机另一个引擎」的前缀转发(desktopWebPort > 0 才开)────────────
3791
+ //
3792
+ // 同一台机器上通常有两个引擎:桌面 App(有历史会话,只听 loopback)和
3793
+ // CLI/web 引擎(就是我们)。手机要看的往往是前者,所以这里开一条
3794
+ // `/mesh/web/...`:去掉前缀转发到 127.0.0.1:<desktopWebPort>,并自带
3795
+ // 签名 cookie(密钥与那个引擎共用,见 desktop-auth.js)。
3796
+ if (typeof config.desktopWebPort === "number" && config.desktopWebPort > 0) {
3797
+ const dshHome = process.env.DSH_HOME || join(homedir(), ".dsh");
3798
+ const secretOf = createSecretReader(join(dshHome, ".credentials.yaml"));
3799
+ const targetPort = config.desktopWebPort;
3800
+ const handle = createDesktopWebForwarder({ port: targetPort, secretOf, log, warn });
3801
+ ctx.effect(() =>
3802
+ ctx.webServer.register({
3803
+ kind: "prefix",
3804
+ path: DESKTOP_WEB_PREFIX,
3805
+ handler: async (req, res) => {
3806
+ try {
3807
+ await handle(req, res);
3808
+ } catch (err) {
3809
+ warn(`桌面引擎转发异常:${err?.message ?? err}`);
3810
+ if (!res.headersSent) {
3811
+ res.writeHead(500, { "content-type": "text/plain; charset=utf-8" });
3812
+ res.end("monitor forwarder failed\n");
3813
+ }
3814
+ }
3815
+ },
3816
+ }),
3817
+ );
3818
+ // 流式载波(WebSocket):工作区/会话的实时数据走它,缺了这条前端会一直"自动重连中"。
3819
+ const upgrade = createDesktopWebUpgrade({ port: targetPort, secretOf, log, warn });
3820
+ ctx.effect(() => ctx.webServer.registerUpgrade({ path: DESKTOP_WEB_STREAM_PATH, handler: upgrade }));
3821
+ log(`已开启本机引擎转发:${DESKTOP_WEB_PREFIX}/* → 127.0.0.1:${targetPort}(含 ${DESKTOP_WEB_STREAM_PATH})`);
3822
+ }
3823
+
3824
+ // ── 应用内 SSH 终端 ───────────────────────────────────────────────────
3825
+ //
3826
+ // 入口在设备行(与「访问 DSH Web」同一位置)。会话由本机发起,凭据只存本机;
3827
+ // 传输走同源 WebSocket(/mesh/api/ssh/ws),所以不需要经过上面对端的 web 转发。
3828
+ const ssh = createSshManager({
3829
+ stateDir: stateDir(),
3830
+ credentialsPath: join(stateDir(), "ssh-credentials.json"),
3831
+ log,
3832
+ warn,
3833
+ });
3834
+ ctx.effect(() => () => ssh.closeAll());
3835
+
3836
+ post("/mesh/api/ssh/known", async (req, res) => {
3837
+ const body = await readJson(req);
3838
+ const machine = String(body?.machine ?? "").trim();
3839
+ // 只回用户名与"是否已部署密钥",不回密码:密码没有再穿过一次网络的理由
3840
+ const info = ssh.describe(machine);
3841
+ return send(res, 200, { ok: true, username: info.username, hasKey: info.hasKey, saved: !!info.username });
3842
+ });
3843
+
3844
+ post("/mesh/api/ssh/sessions", (_req, res) => send(res, 200, { ok: true, sessions: ssh.list() }));
3845
+
3846
+ // 一条 upgrade 路由承载所有终端(按会话 id 多路复用)
3847
+ const sshUpgrade = (req, socket, head) => {
3848
+ const chan = acceptUpgrade(req, socket, head, {
3849
+ onMessage: async (raw) => {
3850
+ let msg;
3851
+ try {
3852
+ msg = JSON.parse(raw);
3853
+ } catch {
3854
+ return;
3855
+ }
3856
+ try {
3857
+ if (msg?.type === "open") {
3858
+ const cols = Number(msg.cols) > 0 ? Number(msg.cols) : 80;
3859
+ const rows = Number(msg.rows) > 0 ? Number(msg.rows) : 24;
3860
+ // 地址不要直接信客户端传来的 peer.host:端点顺序会变(tailnet 可能排前面),
3861
+ // 用 tailnet 地址去连 22 端口会卡到 "timed out waiting for handshake"。
3862
+ // 这里按 discover 的端点表优先挑局域网地址,其次才用它给的。
3863
+ const machine = String(msg.machine ?? "");
3864
+ let host = String(msg.host ?? "");
3865
+ try {
3866
+ const found = machine ? findPeer(machine) : { error: "缺少机器名" };
3867
+ const target = found && found.peer;
3868
+ if (target) {
3869
+ const eps = orderedEndpoints(target);
3870
+ const isPrivate = (h) => /^(10\.|192\.168\.|172\.(1[6-9]|2\d|3[01])\.)/.test(String(h ?? ""));
3871
+ host = (eps.find((e) => isPrivate(e.host)) ?? eps.find((e) => e.host))?.host ?? host;
3872
+ }
3873
+ } catch {
3874
+ /* 解析失败就用客户端给的地址 */
3875
+ }
3876
+ const id = await ssh.open({
3877
+ host,
3878
+ port: Number(msg.port) > 0 ? Number(msg.port) : 22,
3879
+ username: String(msg.username ?? ""),
3880
+ password: typeof msg.password === "string" ? msg.password : "",
3881
+ cols,
3882
+ rows,
3883
+ machine,
3884
+ });
3885
+ chan.send(JSON.stringify({ type: "ready", id, buffer: ssh.ring(id) }));
3886
+ ssh.subscribe(id, (chunk) => {
3887
+ chan.send(JSON.stringify(chunk === null ? { type: "exit", id } : { type: "data", id, data: chunk }));
3888
+ });
3889
+ return;
3890
+ }
3891
+ const id = String(msg?.id ?? "");
3892
+ if (msg?.type === "input") ssh.write(id, String(msg.data ?? ""));
3893
+ else if (msg?.type === "resize") ssh.resize(id, Number(msg.cols) || 80, Number(msg.rows) || 24);
3894
+ else if (msg?.type === "close") ssh.close(id);
3895
+ } catch (error) {
3896
+ chan.send(JSON.stringify({ type: "error", message: String(error?.message ?? error) }));
3897
+ }
3898
+ },
3899
+ });
3900
+ };
3901
+ ctx.effect(() => ctx.webServer.registerUpgrade({ path: "/mesh/api/ssh/ws", handler: sshUpgrade }));
3902
+
3903
+ log("UI 接口已挂载: /mesh/api/state|refresh|secret|send|probe|web-url|web-panel|ssh");
3501
3904
  }