dsh-plugin-mesh 0.5.4 → 0.5.5
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/AGENTS.md +4 -2
- package/README.md +37 -1
- package/client/client.js +364 -3
- package/lib/_selftest-reply-route.mjs +80 -2
- package/lib/_selftest-switch.mjs +142 -0
- package/lib/_selftest-tsnet.mjs +86 -1
- package/lib/_selftest-workbench.mjs +236 -0
- package/lib/index.js +618 -108
- package/lib/switch.js +110 -0
- package/lib/tsnet/manager.js +129 -3
- package/llms.txt +40 -1
- package/package.json +5 -4
- package/scripts/check-tarball.mjs +1 -0
package/AGENTS.md
CHANGED
|
@@ -100,6 +100,7 @@ lib/identity.js persistent UUID + OS machine fingerprint (claim only)
|
|
|
100
100
|
lib/conversation.js conversation key + reply target (both sides compute independently)
|
|
101
101
|
lib/capabilities.js runtime/GPU/capability collection, sanitising, staleness
|
|
102
102
|
lib/prompt.js task prompt text generation (pure, unit-tested)
|
|
103
|
+
lib/switch.js one-click shutdown resolver (pure, unit-tested): state.json `shutdown`
|
|
103
104
|
lib/tsnet/ sidecar download/verify, per-channel process manager, tailnet HTTP bridge,
|
|
104
105
|
channel-list resolution (channels.js, pure and unit-tested)
|
|
105
106
|
client/client.js renderer: sidebar icon + Mesh panel, hand-written bundle
|
|
@@ -117,10 +118,11 @@ inject the prompt → the peer's agent replies by calling `mesh_run`.
|
|
|
117
118
|
|
|
118
119
|
| Suite | Command | Covers |
|
|
119
120
|
|---|---|---|
|
|
120
|
-
| Core / tsnet | `npm run selftest` | discovery, multi-channel endpoints, channel resolution, conversation keys (
|
|
121
|
+
| Core / tsnet | `npm run selftest` | discovery, multi-channel endpoints, channel resolution, conversation keys, stall detection (76) |
|
|
121
122
|
| Capabilities | `npm run selftest:caps` | sanitising, GPU parsing, retry-on-timeout, claim rules (72) |
|
|
122
|
-
| Client render | `npm run selftest:client` | bundle loads, `apply()` registers slots, component output (
|
|
123
|
+
| Client render | `npm run selftest:client` | bundle loads, `apply()` registers slots, component output, kill-switch rows + overview bar (60) |
|
|
123
124
|
| Prompt | `npm run selftest:prompt` | reply target must be a machine name, not `machine/user` (10) |
|
|
125
|
+
| Kill switch | `npm run selftest:switch` | shutdown merge rules: `off` defaults to true, `all` closes both scopes, strict booleans only (15) |
|
|
124
126
|
|
|
125
127
|
`lib/_selftest-newsession.mjs` is a manual end-to-end check that needs a dev host
|
|
126
128
|
running; it is deliberately not part of `npm test` because it creates real agent
|
package/README.md
CHANGED
|
@@ -638,7 +638,7 @@ New-NetFirewallRule -DisplayName "DSH Mesh (multicast)" -Direction Inbound -Prot
|
|
|
638
638
|
- **任务记录**:收到 / 派出的任务
|
|
639
639
|
- **配对码**(折叠,默认不需要)
|
|
640
640
|
|
|
641
|
-
agent
|
|
641
|
+
agent 多出五个工具:
|
|
642
642
|
|
|
643
643
|
| 工具 | 作用 |
|
|
644
644
|
|---|---|
|
|
@@ -646,11 +646,47 @@ agent 多出四个工具:
|
|
|
646
646
|
| `mesh_scan` | 主动扫本网段,找还没发现的机器 |
|
|
647
647
|
| `mesh_run` | 把任务派给某台机器的 agent(异步) |
|
|
648
648
|
| `mesh_tasks` | 查看收到/派出的任务记录 |
|
|
649
|
+
| `mesh_switch` | 一键关闭 / 打开 mesh(全部 / 局域网 / 互联网) |
|
|
649
650
|
|
|
650
651
|
所以你可以直接说:
|
|
651
652
|
|
|
652
653
|
> 「看看局域网里有哪些机器,然后让 B 把 web 服务重新部署一下,跑完告诉我。」
|
|
653
654
|
|
|
655
|
+
### 一键关闭(kill switch)
|
|
656
|
+
|
|
657
|
+
三个范围,两处入口:**主页概览卡**上的一排胶囊(`一键关闭 · 全部 / 局域网 / 互联网`,
|
|
658
|
+
不展开、不跳页,状态直接写在上面),以及 **连接 → 一键关闭** 的详细区块(带监听地址、
|
|
659
|
+
组播状态与偏差说明)。agent 用 `mesh_switch` 调用:
|
|
660
|
+
|
|
661
|
+
| 范围 | 关掉之后会发生什么 |
|
|
662
|
+
|---|---|
|
|
663
|
+
| **全部 Mesh** | 局域网与互联网一起关:不广播、不扫网段、不接受任务、tailnet sidecar 全停 |
|
|
664
|
+
| **局域网 Mesh** | 停发组播、停止扫描与 ping;对端端口从 `0.0.0.0` 收回 `127.0.0.1`。互联网通道(如果有)继续可用 |
|
|
665
|
+
| **互联网 Mesh** | 停掉全部 tailnet sidecar;通道与授权码保留,再打开即恢复,不用重新登录 |
|
|
666
|
+
|
|
667
|
+
几个刻意的取舍:
|
|
668
|
+
|
|
669
|
+
- **关闭立即生效,且跨重启保持。** 状态写在本机 `state.json` 的 `shutdown` 字段,
|
|
670
|
+
不是插件配置 —— 重启 DSH 后不会自己悄悄恢复。改配置文件那个 `enabled: false`
|
|
671
|
+
是另一回事:它在加载期就把整个插件摘掉,**连面板都没有了**,也就不可能从界面打开。
|
|
672
|
+
- **面板始终可用。** 一键关闭只停三条对外路径,`/mesh/api/*` 照常工作,
|
|
673
|
+
否则就成了"一键把自己锁在外面"。
|
|
674
|
+
- **局域网关了但互联网还开着时,对端端口只绑回环。** tailnet 的入站是 sidecar
|
|
675
|
+
反代到 `127.0.0.1` 的,所以这条路径不受影响;而局域网里的机器连端口都连不上。
|
|
676
|
+
- **说得到就要做得到。** 如果重绑回环失败(端口被占等),界面会显示一行偏差说明,
|
|
677
|
+
不会只显示"已关闭"就完事。
|
|
678
|
+
|
|
679
|
+
> 关闭后,"发现 0 台机器"是**正常现象**,不是故障。顶部横幅会一直提示当前是
|
|
680
|
+
> 哪一条被关了。同类误判在这个项目里出现过:把"没有答"当成"没有"。
|
|
681
|
+
|
|
682
|
+
#### 互联网一直显示"正在启动"怎么办
|
|
683
|
+
|
|
684
|
+
不会了。启动超过 75 秒还没拿到 tailnet 地址、也没有授权链接时,状态会变成
|
|
685
|
+
**启动受阻**,并把 sidecar 自己报的登录错误和一句可执行提示一起显示出来,
|
|
686
|
+
旁边的按钮变成「重试连接」。最常见的原因是本机代理:sidecar 走的是裸
|
|
687
|
+
TCP/UDP,只放行 HTTP 客户端的代理设置对它无效(实测诊断里是
|
|
688
|
+
`register request: … context deadline exceeded`)。
|
|
689
|
+
|
|
654
690
|
---
|
|
655
691
|
|
|
656
692
|
|
package/client/client.js
CHANGED
|
@@ -1248,6 +1248,43 @@ window.__ModuleLoader__.load({
|
|
|
1248
1248
|
.mesh-actions-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
|
|
1249
1249
|
.mesh-divider { height: 1px; background: var(--mesh-line); margin: 14px 0; }
|
|
1250
1250
|
|
|
1251
|
+
/* ── 一键关闭(kill switch)── */
|
|
1252
|
+
.mesh-switch-list {
|
|
1253
|
+
display: flex; flex-direction: column; gap: 8px; margin-top: 12px;
|
|
1254
|
+
}
|
|
1255
|
+
.mesh-switch-row {
|
|
1256
|
+
display: flex; align-items: flex-start; gap: 12px;
|
|
1257
|
+
padding: 12px 14px;
|
|
1258
|
+
border: 1px solid var(--mesh-line); border-radius: 11px;
|
|
1259
|
+
background: var(--mesh-surface);
|
|
1260
|
+
transition: border-color var(--mesh-dur-fast) ease, background var(--mesh-dur-fast) ease;
|
|
1261
|
+
}
|
|
1262
|
+
/* 关闭中的一行用左侧警示条标出来:列表里三行很像,必须一眼看出哪条关了 */
|
|
1263
|
+
.mesh-switch-row.is-off { border-left: 2px solid var(--mesh-warn); }
|
|
1264
|
+
.mesh-switch-row-icon {
|
|
1265
|
+
flex: 0 0 auto; width: 26px; height: 26px; border-radius: 8px;
|
|
1266
|
+
display: grid; place-items: center;
|
|
1267
|
+
color: var(--mesh-accent);
|
|
1268
|
+
background: color-mix(in srgb, var(--mesh-accent) 8%, transparent);
|
|
1269
|
+
}
|
|
1270
|
+
.mesh-switch-row.is-off .mesh-switch-row-icon { color: var(--mesh-warn); background: color-mix(in srgb, var(--mesh-warn) 10%, transparent); }
|
|
1271
|
+
.mesh-switch-row-main { flex: 1; min-width: 0; }
|
|
1272
|
+
.mesh-switch-row-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
|
|
1273
|
+
.mesh-switch-row-title { font-size: 12.5px; font-weight: 600; }
|
|
1274
|
+
.mesh-switch-row-desc { margin-top: 3px; font-size: 11px; line-height: 1.6; color: var(--mesh-muted); }
|
|
1275
|
+
.mesh-switch-row-meta {
|
|
1276
|
+
margin-top: 5px;
|
|
1277
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
1278
|
+
font-size: 10px; color: var(--mesh-muted);
|
|
1279
|
+
word-break: break-word;
|
|
1280
|
+
}
|
|
1281
|
+
.mesh-switch-row-action { flex: 0 0 auto; align-self: center; }
|
|
1282
|
+
@media (max-width: 560px) {
|
|
1283
|
+
.mesh-switch-row { flex-wrap: wrap; }
|
|
1284
|
+
.mesh-switch-row-action { width: 100%; }
|
|
1285
|
+
.mesh-switch-row-action .mesh-btn { width: 100%; }
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1251
1288
|
/* ── 主页(卡片工作台) ── */
|
|
1252
1289
|
.mesh-home { flex: 1; min-height: 0; overflow-y: auto; }
|
|
1253
1290
|
.mesh-home-inner { max-width: 1040px; margin: 0 auto; padding: 26px 30px 60px; }
|
|
@@ -1303,6 +1340,35 @@ window.__ModuleLoader__.load({
|
|
|
1303
1340
|
.mesh-hero-stat { display: flex; flex-direction: column; gap: 2px; min-width: 54px; }
|
|
1304
1341
|
.mesh-hero-stat-value { font-size: 17px; font-weight: 600; line-height: 1.2; font-variant-numeric: tabular-nums; }
|
|
1305
1342
|
.mesh-hero-stat-label { font-size: 10px; color: var(--mesh-muted); }
|
|
1343
|
+
|
|
1344
|
+
/* ── 概览卡上的一键关闭快捷条 ── */
|
|
1345
|
+
.mesh-home-switch {
|
|
1346
|
+
display: flex; align-items: center; flex-wrap: wrap; gap: 6px;
|
|
1347
|
+
margin-top: 14px; padding-top: 11px;
|
|
1348
|
+
border-top: 1px dashed var(--mesh-line);
|
|
1349
|
+
}
|
|
1350
|
+
.mesh-home-switch-label {
|
|
1351
|
+
font-size: 10px; color: var(--mesh-muted); letter-spacing: .02em;
|
|
1352
|
+
margin-right: 2px;
|
|
1353
|
+
}
|
|
1354
|
+
.mesh-home-switch-pill {
|
|
1355
|
+
display: inline-flex; align-items: center; gap: 5px;
|
|
1356
|
+
padding: 3px 9px;
|
|
1357
|
+
border: 1px solid var(--mesh-line); border-radius: 999px;
|
|
1358
|
+
background: var(--mesh-surface-2); color: var(--mesh-fg);
|
|
1359
|
+
font-size: 11px; line-height: 1.5; cursor: pointer;
|
|
1360
|
+
transition: border-color var(--mesh-dur-fast) ease, background var(--mesh-dur-fast) ease,
|
|
1361
|
+
transform var(--mesh-dur-press) var(--mesh-ease-out);
|
|
1362
|
+
}
|
|
1363
|
+
.mesh-home-switch-pill:hover { border-color: var(--mesh-accent); }
|
|
1364
|
+
.mesh-home-switch-pill:active { transform: scale(0.97); }
|
|
1365
|
+
.mesh-home-switch-pill:disabled { cursor: progress; opacity: .7; }
|
|
1366
|
+
.mesh-home-switch-pill.is-off { border-color: var(--mesh-warn); }
|
|
1367
|
+
.mesh-home-switch-pill.is-off .mesh-home-switch-name { color: var(--mesh-warn); }
|
|
1368
|
+
.mesh-home-switch-pill.is-stalled { border-color: var(--mesh-warn); }
|
|
1369
|
+
.mesh-home-switch-name { font-weight: 600; }
|
|
1370
|
+
.mesh-home-switch-state { color: var(--mesh-muted); font-variant-numeric: tabular-nums; }
|
|
1371
|
+
.mesh-home.is-dense .mesh-home-switch { margin-top: 9px; padding-top: 8px; gap: 4px; }
|
|
1306
1372
|
.mesh-mini-row { display: flex; align-items: center; gap: 8px; padding: 5px 0; border-top: 1px solid var(--mesh-line); font-size: 11.5px; min-width: 0; }
|
|
1307
1373
|
.mesh-mini-row:first-child { border-top: 0; padding-top: 0; }
|
|
1308
1374
|
.mesh-mini-name { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
@@ -2266,6 +2332,11 @@ window.__ModuleLoader__.load({
|
|
|
2266
2332
|
h("path", { key: "b", d: "M8.5 16a5 5 0 0 1 7 0" }),
|
|
2267
2333
|
h("path", { key: "c", d: "M12 19h.01" }),
|
|
2268
2334
|
];
|
|
2335
|
+
case "power":
|
|
2336
|
+
return [
|
|
2337
|
+
h("path", { key: "a", d: "M12 3v9" }),
|
|
2338
|
+
h("path", { key: "b", d: "M6.3 6.8a8 8 0 1 0 11.4 0" }),
|
|
2339
|
+
];
|
|
2269
2340
|
case "key":
|
|
2270
2341
|
return [
|
|
2271
2342
|
h("circle", { key: "a", cx: 8, cy: 15, r: 4 }),
|
|
@@ -3966,6 +4037,158 @@ window.__ModuleLoader__.load({
|
|
|
3966
4037
|
|
|
3967
4038
|
// ─────────────────────── 连接 / 设置 ───────────────────────
|
|
3968
4039
|
|
|
4040
|
+
/**
|
|
4041
|
+
* 一键关闭(kill switch)。
|
|
4042
|
+
*
|
|
4043
|
+
* 三个范围与宿主 lib/switch.js 一致:all / lan / internet。
|
|
4044
|
+
* 刻意**不做二次确认**:这个功能最需要的时刻是"我怀疑有人能连上我",
|
|
4045
|
+
* 那一刻要的是快;误点的代价只是再点一次打开(配置、会话都不丢)。
|
|
4046
|
+
* 牙口留给别处:按钮文案写清楚会发生什么,关闭后顶部横幅常驻提示。
|
|
4047
|
+
*/
|
|
4048
|
+
const MESH_SWITCH_ROWS = [
|
|
4049
|
+
{
|
|
4050
|
+
scope: "all",
|
|
4051
|
+
title: "全部 Mesh",
|
|
4052
|
+
icon: "power",
|
|
4053
|
+
desc: "局域网 + 互联网一起关。关掉后这台机器不再被任何设备发现,也不再接受任务。",
|
|
4054
|
+
},
|
|
4055
|
+
{
|
|
4056
|
+
scope: "lan",
|
|
4057
|
+
title: "局域网 Mesh",
|
|
4058
|
+
icon: "wifi",
|
|
4059
|
+
desc: "停发组播、停止扫描与 ping,对端端口从局域网收回(只绑本机回环)。",
|
|
4060
|
+
},
|
|
4061
|
+
{
|
|
4062
|
+
scope: "internet",
|
|
4063
|
+
title: "互联网 Mesh",
|
|
4064
|
+
icon: "tailscale",
|
|
4065
|
+
desc: "停掉全部 tailnet sidecar。通道与授权码保留,打开即恢复,不用重新登录。",
|
|
4066
|
+
},
|
|
4067
|
+
];
|
|
4068
|
+
|
|
4069
|
+
function SwitchRow({ row, off, badge, meta, note, busy, onToggle }) {
|
|
4070
|
+
return h(
|
|
4071
|
+
"div",
|
|
4072
|
+
{ className: cls("mesh-switch-row", off && "is-off"), "data-mesh-switch": row.scope },
|
|
4073
|
+
h("span", { className: "mesh-switch-row-icon" }, h(Icon, { name: row.icon, size: 15 })),
|
|
4074
|
+
h(
|
|
4075
|
+
"div",
|
|
4076
|
+
{ className: "mesh-switch-row-main" },
|
|
4077
|
+
h(
|
|
4078
|
+
"div",
|
|
4079
|
+
{ className: "mesh-switch-row-top" },
|
|
4080
|
+
h("span", { className: "mesh-switch-row-title" }, row.title),
|
|
4081
|
+
h(Badge, { kind: off ? "warn" : "ok" }, badge),
|
|
4082
|
+
),
|
|
4083
|
+
h("div", { className: "mesh-switch-row-desc" }, row.desc),
|
|
4084
|
+
meta ? h("div", { className: "mesh-switch-row-meta" }, meta) : null,
|
|
4085
|
+
note ? h("div", { className: "mesh-note is-warn", style: { marginTop: 8 } }, h(Icon, { name: "alert", size: 13 }), h("span", null, note)) : null,
|
|
4086
|
+
),
|
|
4087
|
+
h(
|
|
4088
|
+
"div",
|
|
4089
|
+
{ className: "mesh-switch-row-action" },
|
|
4090
|
+
h(
|
|
4091
|
+
Button,
|
|
4092
|
+
{
|
|
4093
|
+
variant: off ? "secondary" : "danger",
|
|
4094
|
+
size: "sm",
|
|
4095
|
+
icon: off ? "check" : "power",
|
|
4096
|
+
loading: busy,
|
|
4097
|
+
onClick: () => onToggle(row.scope, !off),
|
|
4098
|
+
},
|
|
4099
|
+
off ? "打开" : `一键关闭${row.scope === "all" ? " Mesh" : ""}`,
|
|
4100
|
+
),
|
|
4101
|
+
),
|
|
4102
|
+
);
|
|
4103
|
+
}
|
|
4104
|
+
|
|
4105
|
+
function SwitchBody({ sw, push, reload }) {
|
|
4106
|
+
const st = sw || {};
|
|
4107
|
+
const lan = st.lan || {};
|
|
4108
|
+
const net = st.internet || {};
|
|
4109
|
+
const [busy, setBusy] = react.useState("");
|
|
4110
|
+
const [error, setError] = react.useState("");
|
|
4111
|
+
|
|
4112
|
+
const apply = async (scope, off) => {
|
|
4113
|
+
setBusy(scope);
|
|
4114
|
+
setError("");
|
|
4115
|
+
try {
|
|
4116
|
+
const r = await api("/switch", { scope, off });
|
|
4117
|
+
if (r && r.ok) {
|
|
4118
|
+
const label = scope === "all" ? "Mesh" : scope === "lan" ? "局域网 Mesh" : "互联网 Mesh";
|
|
4119
|
+
push(
|
|
4120
|
+
"success",
|
|
4121
|
+
`${label}已${off ? "关闭" : "打开"}${r.changed === false ? "(本来就是这个状态)" : ""}`,
|
|
4122
|
+
// 误点一键关闭时,"撤销"要在一处就能点回来,而不是去翻三个开关
|
|
4123
|
+
{ label: "撤销", onClick: () => apply(scope, !off) },
|
|
4124
|
+
);
|
|
4125
|
+
await reload();
|
|
4126
|
+
} else {
|
|
4127
|
+
setError(apiErr(r));
|
|
4128
|
+
}
|
|
4129
|
+
} catch (e) {
|
|
4130
|
+
setError(String((e && e.message) || e));
|
|
4131
|
+
} finally {
|
|
4132
|
+
setBusy("");
|
|
4133
|
+
}
|
|
4134
|
+
};
|
|
4135
|
+
|
|
4136
|
+
const LAN_META = () =>
|
|
4137
|
+
lan.off
|
|
4138
|
+
? `对端端口${lan.port ? ` ${lan.bind || "回环"}:${lan.port}` : "已停"} · 组播已停`
|
|
4139
|
+
: `监听 ${lan.bind || "—"}:${lan.port || "—"} · 组播 ${lan.multicast ? "开" : "关"}`;
|
|
4140
|
+
const NET_META = () =>
|
|
4141
|
+
`运行中 ${net.running || 0} / 已启用 ${net.configured || 0} 条通道` + (net.off ? " · sidecar 已停" : "");
|
|
4142
|
+
|
|
4143
|
+
// 「全部」这一行不能复用单条的 active:两条都开着才叫全部开启,
|
|
4144
|
+
// 只关了一条要显示「部分关闭」而不是含糊的「开启」。
|
|
4145
|
+
const partial = !st.all && (!!lan.off || !!net.off);
|
|
4146
|
+
const values = {
|
|
4147
|
+
all: {
|
|
4148
|
+
off: !!st.all,
|
|
4149
|
+
badge: st.all ? "已关闭" : partial ? "部分关闭" : "全部开启",
|
|
4150
|
+
meta: `${lan.off ? "局域网已关" : "局域网开着"} · ${net.off ? "互联网已关" : "互联网开着"}`,
|
|
4151
|
+
},
|
|
4152
|
+
lan: { off: !!lan.off, badge: lan.off ? "已关闭" : lan.active ? "运行中" : "开启(未监听)", meta: LAN_META(), note: lan.note || "" },
|
|
4153
|
+
internet: {
|
|
4154
|
+
off: !!net.off,
|
|
4155
|
+
badge: net.off ? "已关闭" : net.active ? "运行中" : net.stalled ? "启动受阻" : "开启(未连接)",
|
|
4156
|
+
meta: NET_META(),
|
|
4157
|
+
note: net.note || "",
|
|
4158
|
+
},
|
|
4159
|
+
};
|
|
4160
|
+
|
|
4161
|
+
return h(
|
|
4162
|
+
"div",
|
|
4163
|
+
null,
|
|
4164
|
+
h(
|
|
4165
|
+
"p",
|
|
4166
|
+
{ className: "mesh-p", style: { marginBottom: 4 } },
|
|
4167
|
+
"关闭立即生效,并写入本机状态 —— 重启 DSH 后仍保持关闭,直到在这里打开。面板本身始终可用。",
|
|
4168
|
+
),
|
|
4169
|
+
error ? h("div", { className: "mesh-note is-err", style: { marginTop: 10 } }, h(Icon, { name: "alert", size: 13 }), h("span", null, error)) : null,
|
|
4170
|
+
h(
|
|
4171
|
+
"div",
|
|
4172
|
+
{ className: "mesh-switch-list" },
|
|
4173
|
+
MESH_SWITCH_ROWS.map((row) =>
|
|
4174
|
+
h(SwitchRow, {
|
|
4175
|
+
key: row.scope,
|
|
4176
|
+
row,
|
|
4177
|
+
off: values[row.scope].off,
|
|
4178
|
+
badge: values[row.scope].badge,
|
|
4179
|
+
meta: values[row.scope].meta,
|
|
4180
|
+
note: values[row.scope].note,
|
|
4181
|
+
busy: busy === row.scope,
|
|
4182
|
+
onToggle: apply,
|
|
4183
|
+
}),
|
|
4184
|
+
),
|
|
4185
|
+
),
|
|
4186
|
+
st.by
|
|
4187
|
+
? h("p", { className: "mesh-hint", style: { marginTop: 10 } }, `最近一次操作:${st.at ? new Date(st.at).toLocaleString() : "—"}(${st.by === "tool" ? "agent 调用" : st.by === "ui" ? "界面" : st.by})`)
|
|
4188
|
+
: null,
|
|
4189
|
+
);
|
|
4190
|
+
}
|
|
4191
|
+
|
|
3969
4192
|
function SettingsSection({ id, icon, title, subtitle, status, open, onToggle, children }) {
|
|
3970
4193
|
return h(
|
|
3971
4194
|
"section",
|
|
@@ -4222,18 +4445,23 @@ window.__ModuleLoader__.load({
|
|
|
4222
4445
|
/** 单条通道的阶段 → 文案/颜色。 */
|
|
4223
4446
|
function channelPhase(ch) {
|
|
4224
4447
|
const p = ch && ch.node && ch.node.phase ? ch.node.phase : ch && ch.enabled ? "idle" : "off";
|
|
4448
|
+
// 卡在控制面上时 phase 仍然会是 starting —— 光看 phase 会一直显示「正在启动」。
|
|
4449
|
+
// node.stalled 是宿主按时间+证据给的结论,优先级更高(真机反馈 2026-10-29)。
|
|
4450
|
+
const stalled = !!(ch && ch.node && ch.node.stalled);
|
|
4225
4451
|
const map = {
|
|
4226
4452
|
off: ["未启用", "idle"],
|
|
4227
4453
|
idle: ["未连接", "idle"],
|
|
4228
4454
|
starting: ["正在启动", "warn"],
|
|
4229
4455
|
downloading: ["正在下载组件", "warn"],
|
|
4230
4456
|
"needs-login": ["需要授权", "warn"],
|
|
4457
|
+
stalled: ["启动受阻", "err"],
|
|
4231
4458
|
running: ["已连接", "ok"],
|
|
4232
4459
|
exited: ["已停止", "idle"],
|
|
4233
4460
|
error: ["出错", "err"],
|
|
4234
4461
|
};
|
|
4235
|
-
const
|
|
4236
|
-
|
|
4462
|
+
const key = stalled && p !== "running" ? "stalled" : p;
|
|
4463
|
+
const m = map[key] || [p, "idle"];
|
|
4464
|
+
return { phase: key, label: m[0], kind: m[1] };
|
|
4237
4465
|
}
|
|
4238
4466
|
|
|
4239
4467
|
/**
|
|
@@ -4264,6 +4492,7 @@ window.__ModuleLoader__.load({
|
|
|
4264
4492
|
if (running > 0) phase = "running";
|
|
4265
4493
|
else if (phases.includes("needs-login")) phase = "needs-login";
|
|
4266
4494
|
else if (phases.includes("downloading")) phase = "downloading";
|
|
4495
|
+
else if (phases.includes("stalled")) phase = "stalled";
|
|
4267
4496
|
else if (phases.includes("starting")) phase = "starting";
|
|
4268
4497
|
else if (phases.includes("error")) phase = "error";
|
|
4269
4498
|
else if (phases.includes("exited")) phase = "exited";
|
|
@@ -4275,6 +4504,7 @@ window.__ModuleLoader__.load({
|
|
|
4275
4504
|
starting: ["正在启动", "warn"],
|
|
4276
4505
|
downloading: ["正在下载组件", "warn"],
|
|
4277
4506
|
"needs-login": ["需要授权", "warn"],
|
|
4507
|
+
stalled: ["启动受阻", "err"],
|
|
4278
4508
|
running: ["已连接", "ok"],
|
|
4279
4509
|
exited: ["已停止", "idle"],
|
|
4280
4510
|
error: ["出错", "err"],
|
|
@@ -4488,7 +4718,7 @@ window.__ModuleLoader__.load({
|
|
|
4488
4718
|
disabled: isBusy && busy !== `/tsnet/start:${ch.id}`,
|
|
4489
4719
|
onClick: () => run("/tsnet/start", { id: ch.id }, `通道「${ch.label || ch.id}」已启动`),
|
|
4490
4720
|
},
|
|
4491
|
-
"连接",
|
|
4721
|
+
cp.phase === "stalled" ? "重试连接" : "连接",
|
|
4492
4722
|
),
|
|
4493
4723
|
),
|
|
4494
4724
|
node && node.authUrl
|
|
@@ -4502,6 +4732,19 @@ window.__ModuleLoader__.load({
|
|
|
4502
4732
|
),
|
|
4503
4733
|
)
|
|
4504
4734
|
: null,
|
|
4735
|
+
node && node.stalled
|
|
4736
|
+
? h(
|
|
4737
|
+
"div",
|
|
4738
|
+
{ className: "mesh-note is-err" },
|
|
4739
|
+
h(Icon, { name: "alert", size: 13 }),
|
|
4740
|
+
h(
|
|
4741
|
+
"span",
|
|
4742
|
+
null,
|
|
4743
|
+
`启动受阻:${node.stalledReason || "控制面一直没有回应"}`,
|
|
4744
|
+
node.stalledHint ? h("div", { className: "mesh-hint", style: { marginTop: 4 } }, node.stalledHint) : null,
|
|
4745
|
+
),
|
|
4746
|
+
)
|
|
4747
|
+
: null,
|
|
4505
4748
|
node && node.error
|
|
4506
4749
|
? h(
|
|
4507
4750
|
"div",
|
|
@@ -4680,8 +4923,20 @@ window.__ModuleLoader__.load({
|
|
|
4680
4923
|
const self = (state && state.self) || {};
|
|
4681
4924
|
const cfg = (state && state.config) || {};
|
|
4682
4925
|
const tsnet = state && state.tsnet;
|
|
4926
|
+
const sw = state && state.switch;
|
|
4683
4927
|
const phase = tsnetPhase(tsnet);
|
|
4684
4928
|
const toggle = (id) => onOpen(open === id ? null : id);
|
|
4929
|
+
// 关闭状态的摘要要能一眼看出"哪一条被关了",而不是只说"有东西关了"
|
|
4930
|
+
const swOff = Boolean(sw && (sw.lan.off || sw.internet.off));
|
|
4931
|
+
const swSubtitle = !sw
|
|
4932
|
+
? "本机 mesh 开关"
|
|
4933
|
+
: sw.all
|
|
4934
|
+
? "全部已关闭 · 不广播、不监听、不接受任务"
|
|
4935
|
+
: sw.lan.off
|
|
4936
|
+
? "局域网已关闭 · 互联网仍可用"
|
|
4937
|
+
: sw.internet.off
|
|
4938
|
+
? "互联网已关闭 · 局域网仍可用"
|
|
4939
|
+
: "全部开启 · 局域网 + 互联网";
|
|
4685
4940
|
|
|
4686
4941
|
return h(
|
|
4687
4942
|
"div",
|
|
@@ -4695,6 +4950,21 @@ window.__ModuleLoader__.load({
|
|
|
4695
4950
|
// tab 已经叫「连接」了,标题再写一遍是重复;这里只留一句说明。
|
|
4696
4951
|
h("p", null, "本机身份、配对码与跨网络互联。改动立即生效,不需要重启。"),
|
|
4697
4952
|
),
|
|
4953
|
+
sw
|
|
4954
|
+
? h(
|
|
4955
|
+
SettingsSection,
|
|
4956
|
+
{
|
|
4957
|
+
id: "switch",
|
|
4958
|
+
icon: "power",
|
|
4959
|
+
title: "一键关闭",
|
|
4960
|
+
subtitle: swSubtitle,
|
|
4961
|
+
status: h(Badge, { kind: swOff ? "warn" : "ok" }, sw.all ? "全部关闭" : swOff ? "部分关闭" : "全部开启"),
|
|
4962
|
+
open: open === "switch",
|
|
4963
|
+
onToggle: () => toggle("switch"),
|
|
4964
|
+
},
|
|
4965
|
+
h(SwitchBody, { sw, push, reload }),
|
|
4966
|
+
)
|
|
4967
|
+
: null,
|
|
4698
4968
|
h(
|
|
4699
4969
|
SettingsSection,
|
|
4700
4970
|
{
|
|
@@ -4773,6 +5043,69 @@ window.__ModuleLoader__.load({
|
|
|
4773
5043
|
);
|
|
4774
5044
|
}
|
|
4775
5045
|
|
|
5046
|
+
/**
|
|
5047
|
+
* 概览卡上的「一键关闭」快捷条。
|
|
5048
|
+
*
|
|
5049
|
+
* 为什么放主页概览:用户想关 mesh 的时候通常就在主页,不在设置页 ——
|
|
5050
|
+
* 要的是"一眼看见状态、一下点掉",而不是先找到连接页再展开折叠。
|
|
5051
|
+
* 设置页里那份保留:那里有端口/组播/受阻原因等细节。
|
|
5052
|
+
*
|
|
5053
|
+
* 三个胶囊都**没有二次确认**:这是紧急动作,误点的成本只是再点一次。
|
|
5054
|
+
*/
|
|
5055
|
+
function HomeSwitchBar({ sw, push, reload }) {
|
|
5056
|
+
const [busy, setBusy] = react.useState("");
|
|
5057
|
+
if (!sw) return null; // 老宿主没有这个能力:不占位、也不显示一个点了没用的按钮
|
|
5058
|
+
const lan = sw.lan || {};
|
|
5059
|
+
const net = sw.internet || {};
|
|
5060
|
+
const rows = [
|
|
5061
|
+
{ scope: "all", label: "全部", off: !!sw.all },
|
|
5062
|
+
{ scope: "lan", label: "局域网", off: !!lan.off },
|
|
5063
|
+
{ scope: "internet", label: "互联网", off: !!net.off, stalled: !net.off && !!net.stalled },
|
|
5064
|
+
];
|
|
5065
|
+
const toggle = async (scope, off) => {
|
|
5066
|
+
setBusy(scope);
|
|
5067
|
+
try {
|
|
5068
|
+
const r = await api("/switch", { scope, off });
|
|
5069
|
+
if (r && r.ok) {
|
|
5070
|
+
const name = scope === "all" ? "Mesh" : scope === "lan" ? "局域网 Mesh" : "互联网 Mesh";
|
|
5071
|
+
push("success", `${name}已${off ? "关闭" : "打开"}`, {
|
|
5072
|
+
label: "撤销",
|
|
5073
|
+
onClick: () => toggle(scope, !off),
|
|
5074
|
+
});
|
|
5075
|
+
await reload();
|
|
5076
|
+
} else {
|
|
5077
|
+
push("error", apiErr(r));
|
|
5078
|
+
}
|
|
5079
|
+
} catch (e) {
|
|
5080
|
+
push("error", String((e && e.message) || e));
|
|
5081
|
+
} finally {
|
|
5082
|
+
setBusy("");
|
|
5083
|
+
}
|
|
5084
|
+
};
|
|
5085
|
+
return h(
|
|
5086
|
+
"div",
|
|
5087
|
+
{ className: "mesh-home-switch", "data-mesh-home-switch": "1" },
|
|
5088
|
+
h("span", { className: "mesh-home-switch-label" }, "一键关闭"),
|
|
5089
|
+
rows.map((r) => {
|
|
5090
|
+
const stateText = r.off ? "已关" : r.stalled ? "受阻" : "开";
|
|
5091
|
+
return h(
|
|
5092
|
+
"button",
|
|
5093
|
+
{
|
|
5094
|
+
key: r.scope,
|
|
5095
|
+
type: "button",
|
|
5096
|
+
className: cls("mesh-home-switch-pill", r.off && "is-off", r.stalled && "is-stalled", busy === r.scope && "is-busy"),
|
|
5097
|
+
disabled: !!busy,
|
|
5098
|
+
title: `${r.off ? "打开" : "关闭"}${r.scope === "all" ? " Mesh(局域网 + 互联网)" : r.scope === "lan" ? "局域网 Mesh" : "互联网 Mesh"}`,
|
|
5099
|
+
onClick: () => toggle(r.scope, !r.off),
|
|
5100
|
+
},
|
|
5101
|
+
h(Dot, { kind: r.off ? "idle" : r.stalled ? "warn" : "ok" }),
|
|
5102
|
+
h("span", { className: "mesh-home-switch-name" }, r.label),
|
|
5103
|
+
h("span", { className: "mesh-home-switch-state" }, busy === r.scope ? "…" : stateText),
|
|
5104
|
+
);
|
|
5105
|
+
}),
|
|
5106
|
+
);
|
|
5107
|
+
}
|
|
5108
|
+
|
|
4776
5109
|
function HomeCard({ card, subtitle, status, editing, index, count, onMove, onHide, children, footer }) {
|
|
4777
5110
|
return h(
|
|
4778
5111
|
"article",
|
|
@@ -5579,6 +5912,8 @@ window.__ModuleLoader__.load({
|
|
|
5579
5912
|
firstRun,
|
|
5580
5913
|
hostDown,
|
|
5581
5914
|
onDispatched,
|
|
5915
|
+
push,
|
|
5916
|
+
reload,
|
|
5582
5917
|
}) {
|
|
5583
5918
|
const [editing, setEditing] = react.useState(false);
|
|
5584
5919
|
const [drag, setDrag] = react.useState({ draggingId: null, dropId: null, resizingId: null });
|
|
@@ -5852,6 +6187,7 @@ window.__ModuleLoader__.load({
|
|
|
5852
6187
|
h(HomeStat, { label: "跨网络", value: tsnet ? phase.label : "未启用" }),
|
|
5853
6188
|
h(HomeStat, { label: "更新", value: ago(lastOk, now) }),
|
|
5854
6189
|
),
|
|
6190
|
+
h(HomeSwitchBar, { sw: state && state.switch, push, reload }),
|
|
5855
6191
|
),
|
|
5856
6192
|
footer: h(
|
|
5857
6193
|
react.Fragment,
|
|
@@ -6256,6 +6592,7 @@ window.__ModuleLoader__.load({
|
|
|
6256
6592
|
const self = state && state.self ? state.self : null;
|
|
6257
6593
|
const peers = state && Array.isArray(state.peers) ? state.peers : [];
|
|
6258
6594
|
const online = peers.filter((p) => p && p.online).length;
|
|
6595
|
+
const sw = state && state.switch ? state.switch : null;
|
|
6259
6596
|
const tasks = react.useMemo(() => taskList(state), [state]);
|
|
6260
6597
|
const sortedPeers = react.useMemo(
|
|
6261
6598
|
() =>
|
|
@@ -6654,6 +6991,25 @@ window.__ModuleLoader__.load({
|
|
|
6654
6991
|
action: { label: "重试", onClick: reload },
|
|
6655
6992
|
})
|
|
6656
6993
|
: null,
|
|
6994
|
+
sw && (sw.lan.off || sw.internet.off)
|
|
6995
|
+
? h(Banner, {
|
|
6996
|
+
kind: "warn",
|
|
6997
|
+
title: sw.all
|
|
6998
|
+
? "Mesh 已全部关闭"
|
|
6999
|
+
: sw.lan.off
|
|
7000
|
+
? "局域网 Mesh 已关闭"
|
|
7001
|
+
: "互联网 Mesh 已关闭",
|
|
7002
|
+
// 关掉之后"没有设备"是正常的,不是故障 —— 这一句把两者区分开
|
|
7003
|
+
detail: `${sw.summary || ""} · 关闭期间不广播、不接受任务;重启后仍保持`.trim(),
|
|
7004
|
+
action: {
|
|
7005
|
+
label: "去打开",
|
|
7006
|
+
onClick: () => {
|
|
7007
|
+
setView("connect");
|
|
7008
|
+
setSettingsOpen("switch");
|
|
7009
|
+
},
|
|
7010
|
+
},
|
|
7011
|
+
})
|
|
7012
|
+
: null,
|
|
6657
7013
|
state.duplicateNames && state.duplicateNames.length
|
|
6658
7014
|
? h(Banner, {
|
|
6659
7015
|
kind: "warn",
|
|
@@ -6698,6 +7054,8 @@ window.__ModuleLoader__.load({
|
|
|
6698
7054
|
firstRun: firstRunNode,
|
|
6699
7055
|
hostDown,
|
|
6700
7056
|
onDispatched: (peer, r) => notifyDispatched((peer && peer.machine) || "", r),
|
|
7057
|
+
push,
|
|
7058
|
+
reload,
|
|
6701
7059
|
})
|
|
6702
7060
|
: view === "devices"
|
|
6703
7061
|
? h(DeviceView, {
|
|
@@ -6857,6 +7215,9 @@ window.__ModuleLoader__.load({
|
|
|
6857
7215
|
sendToAgent,
|
|
6858
7216
|
PairingBody,
|
|
6859
7217
|
TsnetBody,
|
|
7218
|
+
SwitchBody,
|
|
7219
|
+
SwitchRow,
|
|
7220
|
+
HomeSwitchBar,
|
|
6860
7221
|
};
|
|
6861
7222
|
return module.exports;
|
|
6862
7223
|
},
|