dsh-plugin-mesh 0.5.7 → 0.5.9
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 +9 -2
- package/README.en.md +28 -9
- package/README.md +77 -976
- package/client/client.js +628 -38
- package/cordis.patch.yml +10 -0
- package/lib/_selftest-approval.mjs +165 -0
- package/lib/_selftest-at-mention-host.mjs +377 -0
- package/lib/_selftest-at-mention.mjs +168 -0
- package/lib/_selftest-capabilities.mjs +11 -7
- package/lib/_selftest-prompt.mjs +7 -0
- package/lib/_selftest-reply-route.mjs +60 -1
- package/lib/_selftest-update.mjs +20 -3
- package/lib/_selftest-upgrade.mjs +623 -0
- package/lib/_selftest-workbench.mjs +163 -20
- package/lib/approval.js +152 -0
- package/lib/at-mention.js +109 -0
- package/lib/index.js +712 -99
- package/lib/prompt.js +5 -1
- package/lib/update.js +3 -0
- package/lib/upgrade.js +635 -0
- package/llms.txt +23 -3
- package/package.json +14 -10
- package/scripts/check-tdz.mjs +54 -9
package/client/client.js
CHANGED
|
@@ -1094,6 +1094,12 @@ window.__ModuleLoader__.load({
|
|
|
1094
1094
|
.mesh-chip.is-muted { background: transparent; border: 1px solid var(--mesh-line); color: var(--mesh-muted); }
|
|
1095
1095
|
.mesh-chip-label { color: var(--mesh-muted); }
|
|
1096
1096
|
.mesh-chip-mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 10.5px; }
|
|
1097
|
+
.mesh-chip-btn {
|
|
1098
|
+
cursor: pointer; border: 1px solid var(--mesh-line);
|
|
1099
|
+
background: transparent; color: var(--mesh-fg);
|
|
1100
|
+
transition: border-color 140ms ease, background 140ms ease;
|
|
1101
|
+
}
|
|
1102
|
+
.mesh-chip-btn:hover { border-color: var(--mesh-line-2); background: var(--mesh-surface-2); }
|
|
1097
1103
|
.mesh-specs { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 11px; color: var(--mesh-muted); }
|
|
1098
1104
|
.mesh-text-btn {
|
|
1099
1105
|
align-self: flex-start; border: 0; background: transparent;
|
|
@@ -1610,6 +1616,84 @@ window.__ModuleLoader__.load({
|
|
|
1610
1616
|
.mesh-home-empty p { margin: 0 0 12px; font-size: 12px; color: var(--mesh-muted); }
|
|
1611
1617
|
.mesh-home .mesh-firstrun { margin: 0 0 16px; }
|
|
1612
1618
|
|
|
1619
|
+
/* ── 演示(单机也能看见完整闭环) ── */
|
|
1620
|
+
.mesh-demo-layer {
|
|
1621
|
+
position: absolute; inset: 0; z-index: 50;
|
|
1622
|
+
display: flex; align-items: center; justify-content: center;
|
|
1623
|
+
padding: 22px;
|
|
1624
|
+
background: rgba(12, 14, 18, .46);
|
|
1625
|
+
animation: mesh-view-in 160ms ease both;
|
|
1626
|
+
}
|
|
1627
|
+
.mesh-demo-card {
|
|
1628
|
+
width: min(560px, 100%); max-height: min(88vh, 780px);
|
|
1629
|
+
display: flex; flex-direction: column;
|
|
1630
|
+
background: var(--mesh-surface);
|
|
1631
|
+
color: var(--mesh-fg);
|
|
1632
|
+
border: 1px solid var(--mesh-line);
|
|
1633
|
+
border-radius: 18px;
|
|
1634
|
+
box-shadow: 0 24px 80px rgba(0,0,0,.34);
|
|
1635
|
+
overflow: hidden;
|
|
1636
|
+
animation: mesh-detail-in 220ms var(--mesh-ease-out) both;
|
|
1637
|
+
}
|
|
1638
|
+
.mesh-demo-head {
|
|
1639
|
+
flex: 0 0 auto;
|
|
1640
|
+
display: flex; align-items: center; gap: 10px;
|
|
1641
|
+
padding: 15px 18px 12px;
|
|
1642
|
+
border-bottom: 1px solid var(--mesh-line);
|
|
1643
|
+
}
|
|
1644
|
+
.mesh-demo-eyebrow { font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--mesh-muted); }
|
|
1645
|
+
.mesh-demo-title { font-size: 14px; font-weight: 600; letter-spacing: -0.01em; }
|
|
1646
|
+
.mesh-demo-body { flex: 1; min-height: 0; overflow-y: auto; padding: 16px 18px 6px; display: flex; flex-direction: column; gap: 12px; }
|
|
1647
|
+
.mesh-demo-peer {
|
|
1648
|
+
display: flex; align-items: center; gap: 10px;
|
|
1649
|
+
padding: 10px 12px; border: 1px solid var(--mesh-line); border-radius: 12px;
|
|
1650
|
+
background: var(--mesh-bg);
|
|
1651
|
+
}
|
|
1652
|
+
.mesh-demo-peer-name { font-size: 13px; font-weight: 600; }
|
|
1653
|
+
.mesh-demo-peer-meta { margin-left: auto; font-size: 11px; color: var(--mesh-muted); }
|
|
1654
|
+
.mesh-demo-task {
|
|
1655
|
+
align-self: flex-end; max-width: 86%;
|
|
1656
|
+
padding: 9px 13px; border-radius: 14px 14px 4px 14px;
|
|
1657
|
+
background: var(--mesh-accent-soft, var(--mesh-surface));
|
|
1658
|
+
border: 1px solid var(--mesh-line);
|
|
1659
|
+
font-size: 12.5px; line-height: 1.6;
|
|
1660
|
+
}
|
|
1661
|
+
.mesh-demo-steps { display: flex; flex-direction: column; gap: 7px; padding: 2px 2px 0; }
|
|
1662
|
+
.mesh-demo-step { display: flex; align-items: center; gap: 9px; font-size: 12px; color: var(--mesh-muted); }
|
|
1663
|
+
.mesh-demo-step.is-active { color: var(--mesh-fg); font-weight: 550; }
|
|
1664
|
+
.mesh-demo-step.is-done { color: var(--mesh-fg); }
|
|
1665
|
+
.mesh-demo-step-dot {
|
|
1666
|
+
width: 16px; height: 16px; flex: 0 0 auto; border-radius: 50%;
|
|
1667
|
+
border: 1.5px solid var(--mesh-line-2);
|
|
1668
|
+
display: flex; align-items: center; justify-content: center;
|
|
1669
|
+
font-size: 9px; color: transparent;
|
|
1670
|
+
}
|
|
1671
|
+
.mesh-demo-step.is-active .mesh-demo-step-dot { border-color: var(--mesh-accent); }
|
|
1672
|
+
.mesh-demo-step.is-done .mesh-demo-step-dot { border-color: var(--mesh-accent); background: var(--mesh-accent); color: var(--mesh-bg); }
|
|
1673
|
+
.mesh-demo-spin { width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--mesh-accent); border-top-color: transparent; animation: mesh-spin .8s linear infinite; }
|
|
1674
|
+
.mesh-demo-result {
|
|
1675
|
+
border: 1px solid var(--mesh-line); border-radius: 13px;
|
|
1676
|
+
padding: 13px 14px; background: var(--mesh-bg);
|
|
1677
|
+
animation: mesh-detail-in 220ms ease both;
|
|
1678
|
+
}
|
|
1679
|
+
.mesh-demo-result-head { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; }
|
|
1680
|
+
.mesh-demo-result-title { font-size: 12.5px; font-weight: 600; }
|
|
1681
|
+
.mesh-demo-result-rows { display: flex; flex-direction: column; gap: 5px; }
|
|
1682
|
+
.mesh-demo-result-row { display: flex; gap: 10px; font-size: 11.5px; line-height: 1.5; }
|
|
1683
|
+
.mesh-demo-result-k { flex: 0 0 66px; color: var(--mesh-muted); }
|
|
1684
|
+
.mesh-demo-result-v { flex: 1; min-width: 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
|
|
1685
|
+
.mesh-demo-caption { font-size: 11px; line-height: 1.65; color: var(--mesh-muted); }
|
|
1686
|
+
.mesh-demo-code {
|
|
1687
|
+
display: flex; align-items: center; gap: 8px;
|
|
1688
|
+
padding: 9px 11px; border: 1px dashed var(--mesh-line-2); border-radius: 10px;
|
|
1689
|
+
font: 11.5px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
1690
|
+
background: var(--mesh-code-bg, var(--mesh-bg));
|
|
1691
|
+
overflow-wrap: anywhere;
|
|
1692
|
+
}
|
|
1693
|
+
.mesh-demo-code code { flex: 1; min-width: 0; }
|
|
1694
|
+
.mesh-demo-foot { flex: 0 0 auto; display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px 16px; border-top: 1px solid var(--mesh-line); flex-wrap: wrap; }
|
|
1695
|
+
.mesh-demo-note { margin-right: auto; font-size: 10.5px; color: var(--mesh-muted); align-self: center; }
|
|
1696
|
+
|
|
1613
1697
|
/* 主页底部的派发面板:视觉上跟卡片同级,但不参与拖动/隐藏。 */
|
|
1614
1698
|
.mesh-dispatch {
|
|
1615
1699
|
margin-top: 16px;
|
|
@@ -1725,6 +1809,8 @@ window.__ModuleLoader__.load({
|
|
|
1725
1809
|
.mesh-meta-link:disabled { cursor: default; opacity: .6; }
|
|
1726
1810
|
.mesh-meta-link.is-update { color: var(--mesh-accent); font-weight: 600; }
|
|
1727
1811
|
.mesh-meta-link.is-warn { color: var(--mesh-warn); }
|
|
1812
|
+
.mesh-meta-link.is-busy { opacity: .65; }
|
|
1813
|
+
.mesh-meta-pill { font-size: 11px; line-height: 1.5; color: var(--mesh-accent); font-weight: 600; white-space: nowrap; }
|
|
1728
1814
|
.mesh-card-link { color: var(--mesh-accent); text-decoration: none; }
|
|
1729
1815
|
.mesh-card-link:hover { text-decoration: underline; }
|
|
1730
1816
|
.mesh-focus .mesh-dot.is-ok::after,
|
|
@@ -2201,6 +2287,115 @@ window.__ModuleLoader__.load({
|
|
|
2201
2287
|
return now;
|
|
2202
2288
|
}
|
|
2203
2289
|
|
|
2290
|
+
// ─────────────────────── 聊天窗口 @ 设备 ───────────────────────
|
|
2291
|
+
//
|
|
2292
|
+
// composer 里打 @ 时,菜单把**在线的 mesh 机器**列出来。选中只插入
|
|
2293
|
+
// `@机器名 ` 这段文本;真正的派发在宿主侧:agent/pre-step 认出消息开头的
|
|
2294
|
+
// @机器名,把正文直接发给那台机器(见 lib/at-mention.js)。
|
|
2295
|
+
//
|
|
2296
|
+
// 候选数据来自和面板同一个 /mesh/api/state,但带 2.5 秒缓存 —— 补全是按键
|
|
2297
|
+
// 触发的,不能让每个字符都打一次接口(那还会顺带读盘)。
|
|
2298
|
+
|
|
2299
|
+
const AT_STATE_TTL_MS = 2500;
|
|
2300
|
+
const AT_SECTION = "Mesh 设备";
|
|
2301
|
+
let atPeersCache = { at: 0, rows: [] };
|
|
2302
|
+
|
|
2303
|
+
/** 读一次在线设备列表(带短缓存);失败沿用上一份缓存,不把错误抛给补全管线。 */
|
|
2304
|
+
async function loadOnlinePeers(signal) {
|
|
2305
|
+
if (atPeersCacheFresh()) return atPeersCache.rows;
|
|
2306
|
+
try {
|
|
2307
|
+
const r = await fetch(`${API}/state`, {
|
|
2308
|
+
headers: { accept: "application/json" },
|
|
2309
|
+
cache: "no-store",
|
|
2310
|
+
...(signal ? { signal } : {}),
|
|
2311
|
+
});
|
|
2312
|
+
const j = await r.json();
|
|
2313
|
+
const peers = j && Array.isArray(j.peers) ? j.peers : [];
|
|
2314
|
+
const rows = peers
|
|
2315
|
+
.filter((p) => p && p.online === true && String(p.machine || "").trim())
|
|
2316
|
+
.map((p) => ({
|
|
2317
|
+
machine: String(p.machine).trim(),
|
|
2318
|
+
address: peerAddress(p),
|
|
2319
|
+
system: osInfoLabel(p),
|
|
2320
|
+
user: String(p.user || "").trim(),
|
|
2321
|
+
}))
|
|
2322
|
+
.sort((a, b) => a.machine.localeCompare(b.machine));
|
|
2323
|
+
atPeersCache = { at: Date.now(), rows };
|
|
2324
|
+
return rows;
|
|
2325
|
+
} catch {
|
|
2326
|
+
// 网络/宿主不可用:沿用上一次的列表(可能为空)。候选失败必须静默,
|
|
2327
|
+
// 否则每敲一个字都弹一次错误。
|
|
2328
|
+
return atPeersCache.rows;
|
|
2329
|
+
}
|
|
2330
|
+
}
|
|
2331
|
+
|
|
2332
|
+
function resetAtPeersCache() {
|
|
2333
|
+
atPeersCache = { at: 0, rows: [] };
|
|
2334
|
+
}
|
|
2335
|
+
|
|
2336
|
+
/** 缓存是否还新鲜(空列表也要缓存:没有在线设备时别每敲一个字都打接口)。 */
|
|
2337
|
+
function atPeersCacheFresh() {
|
|
2338
|
+
return atPeersCache.at > 0 && Date.now() - atPeersCache.at < AT_STATE_TTL_MS;
|
|
2339
|
+
}
|
|
2340
|
+
|
|
2341
|
+
/**
|
|
2342
|
+
* 一个 `@` 源:在线设备 → 插入 `@名字 `。
|
|
2343
|
+
*
|
|
2344
|
+
* `showGroupTitle: false` + 每行带 section:菜单里显示的是我们自己的分组名,
|
|
2345
|
+
* 而不是触发管线按 source 名("mesh")反查出来的原始 key。
|
|
2346
|
+
*/
|
|
2347
|
+
function buildAtPeerSource() {
|
|
2348
|
+
return {
|
|
2349
|
+
trigger: "@",
|
|
2350
|
+
name: "mesh",
|
|
2351
|
+
showGroupTitle: false,
|
|
2352
|
+
async candidates(_session, { query, quoted, signal }) {
|
|
2353
|
+
// @"..." 是文件路径语法(见 @deepseek-ai/dsh-client-ui-reference),让给文件引用。
|
|
2354
|
+
if (quoted === true) return [];
|
|
2355
|
+
const rows = await loadOnlinePeers(signal);
|
|
2356
|
+
if (signal && signal.aborted) return [];
|
|
2357
|
+
const needle = String(query || "").trim().toLocaleLowerCase();
|
|
2358
|
+
return rows
|
|
2359
|
+
.filter(
|
|
2360
|
+
(row) =>
|
|
2361
|
+
needle === "" ||
|
|
2362
|
+
row.machine.toLocaleLowerCase().includes(needle) ||
|
|
2363
|
+
row.address.toLocaleLowerCase().includes(needle),
|
|
2364
|
+
)
|
|
2365
|
+
.map((row) => ({
|
|
2366
|
+
name: row.machine,
|
|
2367
|
+
description: [row.address, row.system, row.user ? `user=${row.user}` : ""].filter(Boolean).join(" · "),
|
|
2368
|
+
section: AT_SECTION,
|
|
2369
|
+
value: row.machine,
|
|
2370
|
+
}));
|
|
2371
|
+
},
|
|
2372
|
+
onPick({ candidate }) {
|
|
2373
|
+
const machine = String((candidate && candidate.value) || "").trim();
|
|
2374
|
+
if (!machine) return undefined;
|
|
2375
|
+
return { text: `@${machine} ` };
|
|
2376
|
+
},
|
|
2377
|
+
};
|
|
2378
|
+
}
|
|
2379
|
+
|
|
2380
|
+
/**
|
|
2381
|
+
* 注册 @ 源。宿主没有触发管线(老版本 DSH)时安静跳过 —— 不能因为多了
|
|
2382
|
+
* 一个可选增强,让整个 Mesh 面板起不来。
|
|
2383
|
+
*/
|
|
2384
|
+
function registerAtPeerSource(ctx) {
|
|
2385
|
+
if (!ctx || typeof ctx.inject !== "function") return;
|
|
2386
|
+
try {
|
|
2387
|
+
ctx.inject(["inputTriggers"], (scoped) => {
|
|
2388
|
+
const inputTriggers =
|
|
2389
|
+
(scoped && (scoped.inputTriggers || (scoped.get && scoped.get("inputTriggers")))) || null;
|
|
2390
|
+
if (!inputTriggers || typeof inputTriggers.registerSource !== "function") return;
|
|
2391
|
+
scoped.effect(() => inputTriggers.registerSource(buildAtPeerSource()), "mesh: @ 在线设备");
|
|
2392
|
+
});
|
|
2393
|
+
} catch (err) {
|
|
2394
|
+
// 触发管线是可选的:注册失败只记一条日志,不能让 Mesh 面板跟着挂掉。
|
|
2395
|
+
console.warn("mesh client: 聊天窗口 @ 设备注册失败(面板不受影响)", err);
|
|
2396
|
+
}
|
|
2397
|
+
}
|
|
2398
|
+
|
|
2204
2399
|
function prefersReducedMotion() {
|
|
2205
2400
|
try {
|
|
2206
2401
|
return typeof window !== "undefined" && window.matchMedia
|
|
@@ -2866,6 +3061,183 @@ window.__ModuleLoader__.load({
|
|
|
2866
3061
|
);
|
|
2867
3062
|
}
|
|
2868
3063
|
|
|
3064
|
+
/**
|
|
3065
|
+
* 陌生设备第一次派活的确认条。
|
|
3066
|
+
*
|
|
3067
|
+
* 默认会拦(判定在 lib/approval.js)。这里只负责把「谁、要干什么」摆清楚,
|
|
3068
|
+
* 给两个按钮;点完立刻调接口 —— 任务要么当场开始跑,要么被拒。
|
|
3069
|
+
*/
|
|
3070
|
+
function ApprovalBar({ items, busy, onDecide }) {
|
|
3071
|
+
const list = Array.isArray(items) ? items : [];
|
|
3072
|
+
const first = list[0];
|
|
3073
|
+
if (!first) return null;
|
|
3074
|
+
const name = first.fromMachine || String(first.from || "").split("/")[0] || "一台设备";
|
|
3075
|
+
const more = list.length > 1 ? `(还有 ${list.length - 1} 条待确认)` : "";
|
|
3076
|
+
const preview = String(first.task || "").replace(/\s+/g, " ").slice(0, 68);
|
|
3077
|
+
return h(
|
|
3078
|
+
"div",
|
|
3079
|
+
{ className: "mesh-banner is-warn", role: "status", "data-mesh-approval": first.id },
|
|
3080
|
+
h(Icon, { name: "alert", size: 14 }),
|
|
3081
|
+
h(
|
|
3082
|
+
"div",
|
|
3083
|
+
{ className: "mesh-banner-main" },
|
|
3084
|
+
h("span", { className: "mesh-banner-title" }, `「${name}」想派一个任务过来${more}`),
|
|
3085
|
+
h("span", { className: "mesh-banner-detail" }, `允许后这台设备以后不再问:${preview}`),
|
|
3086
|
+
),
|
|
3087
|
+
h(Button, { variant: "primary", size: "sm", loading: busy, onClick: () => onDecide(first.id, "allow") }, "允许"),
|
|
3088
|
+
h(Button, { variant: "ghost", size: "sm", disabled: busy, onClick: () => onDecide(first.id, "deny") }, "拒绝"),
|
|
3089
|
+
);
|
|
3090
|
+
}
|
|
3091
|
+
|
|
3092
|
+
/**
|
|
3093
|
+
* 「看演示」:没有第二台机器也能看见完整闭环。
|
|
3094
|
+
*
|
|
3095
|
+
* 这是唯一能让单机用户理解产品的东西。它**不连网络、不建会话、不花 token**,
|
|
3096
|
+
* 但结果里的数字是这台机器的真实数据(走 GET /mesh/api/demo),所以看起来
|
|
3097
|
+
* 不像编的。装好第二台之后,同一条链路会真的在那边跑。
|
|
3098
|
+
*/
|
|
3099
|
+
function DemoOverlay({ open, onClose }) {
|
|
3100
|
+
const [phase, setPhase] = react.useState("loading");
|
|
3101
|
+
const [data, setData] = react.useState(null);
|
|
3102
|
+
const [error, setError] = react.useState("");
|
|
3103
|
+
const [run, setRun] = react.useState(0);
|
|
3104
|
+
const [copied, setCopied] = react.useState(false);
|
|
3105
|
+
|
|
3106
|
+
react.useEffect(() => {
|
|
3107
|
+
if (!open) return undefined;
|
|
3108
|
+
let alive = true;
|
|
3109
|
+
const timers = [];
|
|
3110
|
+
setPhase("loading");
|
|
3111
|
+
setError("");
|
|
3112
|
+
setCopied(false);
|
|
3113
|
+
apiGet("/demo")
|
|
3114
|
+
.then((r) => {
|
|
3115
|
+
if (!alive) return;
|
|
3116
|
+
if (!r || !r.ok) {
|
|
3117
|
+
setError(apiErr(r));
|
|
3118
|
+
setPhase("error");
|
|
3119
|
+
return;
|
|
3120
|
+
}
|
|
3121
|
+
setData(r);
|
|
3122
|
+
setPhase("queued");
|
|
3123
|
+
timers.push(setTimeout(() => alive && setPhase("running"), 900));
|
|
3124
|
+
timers.push(setTimeout(() => alive && setPhase("done"), 3000));
|
|
3125
|
+
})
|
|
3126
|
+
.catch((e) => {
|
|
3127
|
+
if (!alive) return;
|
|
3128
|
+
setError(String((e && e.message) || e));
|
|
3129
|
+
setPhase("error");
|
|
3130
|
+
});
|
|
3131
|
+
return () => {
|
|
3132
|
+
alive = false;
|
|
3133
|
+
timers.forEach((t) => clearTimeout(t));
|
|
3134
|
+
};
|
|
3135
|
+
}, [open, run]);
|
|
3136
|
+
|
|
3137
|
+
if (!open) return null;
|
|
3138
|
+
|
|
3139
|
+
const stage = phase === "done" ? 2 : phase === "running" ? 1 : phase === "queued" ? 0 : -1;
|
|
3140
|
+
const stepClass = (i) => cls("mesh-demo-step", stage === i && "is-active", stage > i && "is-done");
|
|
3141
|
+
const dot = (i) => (stage === i ? h("span", { className: "mesh-demo-spin" }) : stage > i ? "✓" : "");
|
|
3142
|
+
const install = "dsh plugin add dsh-plugin-mesh";
|
|
3143
|
+
|
|
3144
|
+
return h(
|
|
3145
|
+
"div",
|
|
3146
|
+
{ className: "mesh-demo-layer", role: "dialog", "aria-modal": "true", "aria-label": "Mesh 演示", onClick: (e) => e.target === e.currentTarget && onClose() },
|
|
3147
|
+
h(
|
|
3148
|
+
"div",
|
|
3149
|
+
{ className: "mesh-demo-card" },
|
|
3150
|
+
h(
|
|
3151
|
+
"div",
|
|
3152
|
+
{ className: "mesh-demo-head" },
|
|
3153
|
+
h(Dot, { kind: "ok" }),
|
|
3154
|
+
h(
|
|
3155
|
+
"div",
|
|
3156
|
+
{ style: { flex: 1, minWidth: 0 } },
|
|
3157
|
+
h("div", { className: "mesh-demo-eyebrow" }, "演示 · 不连接其他机器"),
|
|
3158
|
+
h("div", { className: "mesh-demo-title" }, "一次跨机派发长什么样"),
|
|
3159
|
+
),
|
|
3160
|
+
h(IconButton, { icon: "close", label: "关闭演示", onClick: onClose }),
|
|
3161
|
+
),
|
|
3162
|
+
h(
|
|
3163
|
+
"div",
|
|
3164
|
+
{ className: "mesh-demo-body" },
|
|
3165
|
+
h(
|
|
3166
|
+
"div",
|
|
3167
|
+
{ className: "mesh-demo-peer" },
|
|
3168
|
+
h(Dot, { kind: "ok" }),
|
|
3169
|
+
h("span", { className: "mesh-demo-peer-name" }, "演示机 · Studio"),
|
|
3170
|
+
h("span", { className: "mesh-demo-peer-meta" }, "在线 · 示例"),
|
|
3171
|
+
),
|
|
3172
|
+
h("div", { className: "mesh-demo-task" }, "报一下你的系统和负载"),
|
|
3173
|
+
h(
|
|
3174
|
+
"div",
|
|
3175
|
+
{ className: "mesh-demo-steps" },
|
|
3176
|
+
h("div", { className: stage >= 0 ? "mesh-demo-step is-done" : "mesh-demo-step" }, h("span", { className: "mesh-demo-step-dot" }, stage >= 0 ? "✓" : ""), "已送达对端"),
|
|
3177
|
+
h("div", { className: stepClass(1) }, h("span", { className: "mesh-demo-step-dot" }, dot(1)), stage === 1 ? "对端正在跑" : "对端执行完毕"),
|
|
3178
|
+
h("div", { className: stepClass(2) }, h("span", { className: "mesh-demo-step-dot" }, dot(2)), "结果回到这里"),
|
|
3179
|
+
),
|
|
3180
|
+
phase === "error"
|
|
3181
|
+
? h("div", { className: "mesh-demo-caption" }, `取不到本机数据:${error}(演示依赖插件主机在线)`)
|
|
3182
|
+
: null,
|
|
3183
|
+
phase === "done" && data
|
|
3184
|
+
? h(
|
|
3185
|
+
"div",
|
|
3186
|
+
{ className: "mesh-demo-result" },
|
|
3187
|
+
h(
|
|
3188
|
+
"div",
|
|
3189
|
+
{ className: "mesh-demo-result-head" },
|
|
3190
|
+
h(Icon, { name: "check", size: 14 }),
|
|
3191
|
+
h("span", { className: "mesh-demo-result-title" }, "任务完成 · 结果卡"),
|
|
3192
|
+
),
|
|
3193
|
+
h(
|
|
3194
|
+
"div",
|
|
3195
|
+
{ className: "mesh-demo-result-rows" },
|
|
3196
|
+
h("div", { className: "mesh-demo-result-row" }, h("span", { className: "mesh-demo-result-k" }, "机器"), h("span", { className: "mesh-demo-result-v" }, `${data.hostname || data.machine} · ${osLabel(data.platform)} ${data.release}`)),
|
|
3197
|
+
h("div", { className: "mesh-demo-result-row" }, h("span", { className: "mesh-demo-result-k" }, "CPU"), h("span", { className: "mesh-demo-result-v" }, `${data.cpuModel || "未知型号"} · ${data.cpuCores} 核`)),
|
|
3198
|
+
h("div", { className: "mesh-demo-result-row" }, h("span", { className: "mesh-demo-result-k" }, "内存"), h("span", { className: "mesh-demo-result-v" }, `${data.memFreeGb} GB 可用 / ${data.memTotalGb} GB`)),
|
|
3199
|
+
h("div", { className: "mesh-demo-result-row" }, h("span", { className: "mesh-demo-result-k" }, "负载"), h("span", { className: "mesh-demo-result-v" }, `${data.load1}(1 分钟)· 已运行 ${data.uptimeHours} 小时`)),
|
|
3200
|
+
h("div", { className: "mesh-demo-result-row" }, h("span", { className: "mesh-demo-result-k" }, "运行时"), h("span", { className: "mesh-demo-result-v" }, (data.runtimes || []).map((r) => `${r.name} ${r.version}`).join(" · ") || "未探测到")),
|
|
3201
|
+
),
|
|
3202
|
+
)
|
|
3203
|
+
: null,
|
|
3204
|
+
phase === "done"
|
|
3205
|
+
? h(
|
|
3206
|
+
"div",
|
|
3207
|
+
null,
|
|
3208
|
+
h("p", { className: "mesh-demo-caption" }, "上面的数字来自这台机器本身 —— 演示只证明流程,不假装有第二台。装好第二台之后,同一句话会真的在那边跑,结果回到这里;合上笔记本也不影响。"),
|
|
3209
|
+
h(
|
|
3210
|
+
"div",
|
|
3211
|
+
{ className: "mesh-demo-code" },
|
|
3212
|
+
h("code", null, install),
|
|
3213
|
+
h(
|
|
3214
|
+
Button,
|
|
3215
|
+
{
|
|
3216
|
+
variant: "ghost",
|
|
3217
|
+
size: "sm",
|
|
3218
|
+
icon: copied ? "check" : "copy",
|
|
3219
|
+
onClick: async () => {
|
|
3220
|
+
const ok = await copyText(install);
|
|
3221
|
+
setCopied(ok);
|
|
3222
|
+
},
|
|
3223
|
+
},
|
|
3224
|
+
copied ? "已复制" : "复制",
|
|
3225
|
+
),
|
|
3226
|
+
),
|
|
3227
|
+
)
|
|
3228
|
+
: h("p", { className: "mesh-demo-caption" }, "派发出去之后这里会变成「在跑」,跑完自动变成结果卡 —— 你不用盯着。"),
|
|
3229
|
+
),
|
|
3230
|
+
h(
|
|
3231
|
+
"div",
|
|
3232
|
+
{ className: "mesh-demo-foot" },
|
|
3233
|
+
h("span", { className: "mesh-demo-note" }, "演示不会唤醒 agent,也不花 token。"),
|
|
3234
|
+
h(Button, { variant: "ghost", size: "sm", icon: "refresh", onClick: () => setRun((n) => n + 1) }, "再看一遍"),
|
|
3235
|
+
h(Button, { variant: "primary", size: "sm", onClick: onClose }, "知道了"),
|
|
3236
|
+
),
|
|
3237
|
+
),
|
|
3238
|
+
);
|
|
3239
|
+
}
|
|
3240
|
+
|
|
2869
3241
|
function LoadingView() {
|
|
2870
3242
|
return h("div", { className: "mesh-loading" }, h("span", { className: "mesh-spinner-lg" }), h("span", null, "正在读取 Mesh 状态…"));
|
|
2871
3243
|
}
|
|
@@ -3242,7 +3614,7 @@ window.__ModuleLoader__.load({
|
|
|
3242
3614
|
);
|
|
3243
3615
|
}
|
|
3244
3616
|
|
|
3245
|
-
function DeviceList({ selfPeer, peers, selectedId, onSelect, onWeb, onSsh, now, lastOk, onScan, scanning }) {
|
|
3617
|
+
function DeviceList({ selfPeer, peers, selectedId, onSelect, onWeb, onSsh, now, lastOk, onScan, scanning, onDemo }) {
|
|
3246
3618
|
return h(
|
|
3247
3619
|
"aside",
|
|
3248
3620
|
{ className: "mesh-list-pane" },
|
|
@@ -3269,7 +3641,17 @@ window.__ModuleLoader__.load({
|
|
|
3269
3641
|
h("div", { className: "mesh-list-heading" }, "其他设备"),
|
|
3270
3642
|
peers.length
|
|
3271
3643
|
? peers.map((p, i) => h(DeviceRow, { key: p.id, peer: p, active: selectedId === p.id, onSelect, onWeb, onSsh, now, index: i + 1 }))
|
|
3272
|
-
: h(
|
|
3644
|
+
: h(
|
|
3645
|
+
"div",
|
|
3646
|
+
{ className: "mesh-list-empty" },
|
|
3647
|
+
h("div", null, "还没有发现其他设备。"),
|
|
3648
|
+
h("div", { style: { marginTop: 8 } },
|
|
3649
|
+
onDemo
|
|
3650
|
+
? h(Button, { variant: "primary", size: "sm", icon: "arrowOut", onClick: onDemo }, "看 60 秒演示")
|
|
3651
|
+
: null,
|
|
3652
|
+
),
|
|
3653
|
+
h("div", { style: { marginTop: 6, fontSize: 10.5 } }, "或者在另一台电脑上装一次,它们会自己找到彼此。"),
|
|
3654
|
+
),
|
|
3273
3655
|
h(
|
|
3274
3656
|
"div",
|
|
3275
3657
|
{ className: "mesh-list-actions" },
|
|
@@ -3446,7 +3828,7 @@ window.__ModuleLoader__.load({
|
|
|
3446
3828
|
}
|
|
3447
3829
|
|
|
3448
3830
|
function DeviceView(props) {
|
|
3449
|
-
const { selfPeer, peers, selectedPeer, selectedId, onSelect, onWeb, onSsh, mobilePane, onBack, onCompose, onProbe, probe, hostDown, now, lastOk, onScan, scanning, firstRun, onRename, recentTasks, onOpenTask, onAllTasks } = props;
|
|
3831
|
+
const { selfPeer, peers, selectedPeer, selectedId, onSelect, onWeb, onSsh, mobilePane, onBack, onCompose, onProbe, probe, hostDown, now, lastOk, onScan, scanning, onDemo, firstRun, onRename, recentTasks, onOpenTask, onAllTasks } = props;
|
|
3450
3832
|
return h(
|
|
3451
3833
|
react.Fragment,
|
|
3452
3834
|
null,
|
|
@@ -3454,7 +3836,7 @@ window.__ModuleLoader__.load({
|
|
|
3454
3836
|
h(
|
|
3455
3837
|
"div",
|
|
3456
3838
|
{ className: "mesh-split", "data-pane": mobilePane },
|
|
3457
|
-
h(DeviceList, { selfPeer, peers, selectedId, onSelect, onWeb, onSsh, now, lastOk, onScan, scanning }),
|
|
3839
|
+
h(DeviceList, { selfPeer, peers, selectedId, onSelect, onWeb, onSsh, now, lastOk, onScan, scanning, onDemo }),
|
|
3458
3840
|
h(DeviceDetail, { peer: selectedPeer, isSelf: selectedId === "self", onCompose, onProbe, probe, hostDown, now, onBack, onRename, onScan, recentTasks, onOpenTask, onAllTasks }),
|
|
3459
3841
|
),
|
|
3460
3842
|
);
|
|
@@ -3568,6 +3950,27 @@ window.__ModuleLoader__.load({
|
|
|
3568
3950
|
h("strong", null, target.machine || "?"),
|
|
3569
3951
|
h("span", { style: { marginLeft: "auto" } }, online ? "对端会在自己的会话里执行" : "设备离线"),
|
|
3570
3952
|
),
|
|
3953
|
+
h(
|
|
3954
|
+
"div",
|
|
3955
|
+
{ className: "mesh-chips", style: { marginBottom: 8 } },
|
|
3956
|
+
[
|
|
3957
|
+
"在 Windows 那台编译,产物和报错都发我",
|
|
3958
|
+
"装到 Android 上启动一下,截图和日志发我",
|
|
3959
|
+
"在另一台装新版本插件,重启后确认版本",
|
|
3960
|
+
].map((preset) =>
|
|
3961
|
+
h(
|
|
3962
|
+
"button",
|
|
3963
|
+
{
|
|
3964
|
+
key: preset,
|
|
3965
|
+
type: "button",
|
|
3966
|
+
className: "mesh-chip mesh-chip-btn",
|
|
3967
|
+
onClick: () => setTask(preset),
|
|
3968
|
+
title: "填入这句话",
|
|
3969
|
+
},
|
|
3970
|
+
preset,
|
|
3971
|
+
),
|
|
3972
|
+
),
|
|
3973
|
+
),
|
|
3571
3974
|
h(
|
|
3572
3975
|
Field,
|
|
3573
3976
|
{ label: "要对方做什么?" },
|
|
@@ -3602,7 +4005,7 @@ window.__ModuleLoader__.load({
|
|
|
3602
4005
|
),
|
|
3603
4006
|
),
|
|
3604
4007
|
error ? h("div", { className: "mesh-sheet-error" }, error) : null,
|
|
3605
|
-
h("p", { className: "mesh-hint" }, "
|
|
4008
|
+
h("p", { className: "mesh-hint" }, "派发是异步的:这里成功只代表对端收了。它跑完会把结果派回来,出现在「任务」里。第一次派给陌生设备时,对方会先问你一次。⌘/Ctrl + Enter 发送。"),
|
|
3606
4009
|
),
|
|
3607
4010
|
h(
|
|
3608
4011
|
"div",
|
|
@@ -4326,6 +4729,10 @@ window.__ModuleLoader__.load({
|
|
|
4326
4729
|
dispatched: ["已派发", "ok"],
|
|
4327
4730
|
"queued-lost": ["排队丢失", "err"],
|
|
4328
4731
|
"dispatch-failed": ["派发失败", "err"],
|
|
4732
|
+
// 信任闸门:发出去的还在等对端点「允许」,收到的等本机点「允许」
|
|
4733
|
+
"awaiting-approval": ["等对端确认", "warn"],
|
|
4734
|
+
"needs-approval": ["待本机确认", "warn"],
|
|
4735
|
+
rejected: ["已拒绝", "err"],
|
|
4329
4736
|
};
|
|
4330
4737
|
|
|
4331
4738
|
function taskList(state) {
|
|
@@ -4351,7 +4758,13 @@ window.__ModuleLoader__.load({
|
|
|
4351
4758
|
at: tsOf(t.at),
|
|
4352
4759
|
text: String(t.task || ""),
|
|
4353
4760
|
thread: t.thread || "",
|
|
4354
|
-
status: t.ok
|
|
4761
|
+
status: t.ok
|
|
4762
|
+
? t.remoteStatus === "needs-approval"
|
|
4763
|
+
? "awaiting-approval"
|
|
4764
|
+
: "delivered"
|
|
4765
|
+
: t.status === 403
|
|
4766
|
+
? "pairing-mismatch"
|
|
4767
|
+
: "failed",
|
|
4355
4768
|
raw: t,
|
|
4356
4769
|
}));
|
|
4357
4770
|
return [...inbound, ...outbound].sort((a, b) => b.at - a.at);
|
|
@@ -5842,7 +6255,14 @@ window.__ModuleLoader__.load({
|
|
|
5842
6255
|
h("span", { className: "mesh-mini-meta" }, p.online ? `在线 · ${osLabel(p.os)}` : `${ago(p.lastSeen, now)}`),
|
|
5843
6256
|
),
|
|
5844
6257
|
)
|
|
5845
|
-
: h(
|
|
6258
|
+
: h(
|
|
6259
|
+
"div",
|
|
6260
|
+
null,
|
|
6261
|
+
h("p", { className: "mesh-card-text" }, "还没有发现其他设备。扫描本网段,或让对方也打开 Mesh。"),
|
|
6262
|
+
onDemo
|
|
6263
|
+
? h(Button, { variant: "secondary", size: "sm", icon: "arrowOut", onClick: onDemo }, "看演示:一次派发长什么样")
|
|
6264
|
+
: null,
|
|
6265
|
+
),
|
|
5846
6266
|
footer: h(Button, { variant: "ghost", size: "sm", icon: "device", onClick: onDevices }, "查看全部设备"),
|
|
5847
6267
|
});
|
|
5848
6268
|
}
|
|
@@ -6386,12 +6806,29 @@ window.__ModuleLoader__.load({
|
|
|
6386
6806
|
);
|
|
6387
6807
|
}
|
|
6388
6808
|
|
|
6389
|
-
/**
|
|
6390
|
-
|
|
6809
|
+
/**
|
|
6810
|
+
* 检查更新的展示层(纯 props):自测可以直接给各种现场,不用联网。
|
|
6811
|
+
*
|
|
6812
|
+
* 状态优先级(写在这里是为了让"该装 / 已装待重启 / 已装待重载"不会互相盖住):
|
|
6813
|
+
* pendingUpgrade(磁盘已是目标版)→ 只给「重启」或「重载界面」;
|
|
6814
|
+
* 否则 hasUpdate → 给「新版本 vX」,点第一下变确认、第二下才开始装;
|
|
6815
|
+
* 失败 → 明确写「安装失败」,点一下重试(绝不悄悄回到"有新版本")。
|
|
6816
|
+
*/
|
|
6817
|
+
function UpdateLinkView({ phase, report, install, onCheck, onInstall, onRestart, onReload }) {
|
|
6391
6818
|
const checking = phase === "checking";
|
|
6392
|
-
const
|
|
6819
|
+
const state = (install && install.state) || "idle";
|
|
6820
|
+
const running = state === "running";
|
|
6821
|
+
const armed = state === "armed";
|
|
6822
|
+
const installFailed = state === "failed";
|
|
6823
|
+
const busy = checking || running;
|
|
6824
|
+
const pending =
|
|
6825
|
+
report && report.ok === true && report.pendingUpgrade && (!report.latest || report.pendingUpgrade.version === report.latest)
|
|
6826
|
+
? report.pendingUpgrade
|
|
6827
|
+
: null;
|
|
6393
6828
|
const hasUpdate = !!report && report.ok === true && report.hasUpdate === true;
|
|
6829
|
+
const failed = !!report && report.ok !== true;
|
|
6394
6830
|
const incomparable = !!report && report.ok === true && report.comparable === false;
|
|
6831
|
+
const canInstall = hasUpdate && !pending && report.diskVersion !== report.latest;
|
|
6395
6832
|
const label = checking ? "检查中…" : "检查更新";
|
|
6396
6833
|
const title = failed
|
|
6397
6834
|
? `上次检查失败:${String(report.error || "未知原因")}(点一下重试)`
|
|
@@ -6407,29 +6844,65 @@ window.__ModuleLoader__.load({
|
|
|
6407
6844
|
"button",
|
|
6408
6845
|
{
|
|
6409
6846
|
type: "button",
|
|
6410
|
-
className: cls("mesh-meta-link",
|
|
6847
|
+
className: cls("mesh-meta-link", busy && "is-busy"),
|
|
6411
6848
|
onClick: onCheck,
|
|
6412
|
-
disabled:
|
|
6849
|
+
disabled: busy,
|
|
6413
6850
|
title,
|
|
6414
6851
|
"aria-label": "检查更新",
|
|
6415
|
-
"aria-busy":
|
|
6852
|
+
"aria-busy": busy || undefined,
|
|
6416
6853
|
},
|
|
6417
6854
|
label,
|
|
6418
6855
|
),
|
|
6419
|
-
|
|
6856
|
+
pending
|
|
6857
|
+
? h(
|
|
6858
|
+
"span",
|
|
6859
|
+
{ className: "mesh-meta-pill", title: pending.at ? `安装于 ${pending.at}` : undefined },
|
|
6860
|
+
`已安装 v${pending.version}`,
|
|
6861
|
+
)
|
|
6862
|
+
: null,
|
|
6863
|
+
pending && pending.restartRequired
|
|
6864
|
+
? h(
|
|
6865
|
+
"button",
|
|
6866
|
+
{
|
|
6867
|
+
type: "button",
|
|
6868
|
+
className: "mesh-meta-link is-update",
|
|
6869
|
+
onClick: onRestart,
|
|
6870
|
+
title: "重启 DSH 让新版本生效(会中断当前会话)",
|
|
6871
|
+
},
|
|
6872
|
+
"重启生效",
|
|
6873
|
+
)
|
|
6874
|
+
: null,
|
|
6875
|
+
pending && !pending.restartRequired
|
|
6420
6876
|
? h(
|
|
6421
6877
|
"button",
|
|
6422
6878
|
{
|
|
6423
6879
|
type: "button",
|
|
6424
6880
|
className: "mesh-meta-link is-update",
|
|
6425
|
-
onClick:
|
|
6426
|
-
title:
|
|
6427
|
-
|
|
6881
|
+
onClick: onReload,
|
|
6882
|
+
title: "这次只改了界面,重载界面即可生效",
|
|
6883
|
+
},
|
|
6884
|
+
"重载界面",
|
|
6885
|
+
)
|
|
6886
|
+
: null,
|
|
6887
|
+
!pending && canInstall
|
|
6888
|
+
? h(
|
|
6889
|
+
"button",
|
|
6890
|
+
{
|
|
6891
|
+
type: "button",
|
|
6892
|
+
className: cls("mesh-meta-link is-update", installFailed && "is-warn"),
|
|
6893
|
+
onClick: onInstall,
|
|
6894
|
+
disabled: running,
|
|
6895
|
+
title: installFailed
|
|
6896
|
+
? `上次安装失败:${String(install.error || "未知原因")};点一下重试`
|
|
6897
|
+
: armed
|
|
6898
|
+
? `再点一次开始安装 v${report.latest}(sha512 校验后替换,装完重启生效)`
|
|
6899
|
+
: `一键安装 v${report.latest}(先校验 sha512,可加载检查通过才替换)`,
|
|
6900
|
+
"aria-label": armed ? `确认安装 v${report.latest}` : `安装 v${report.latest}`,
|
|
6428
6901
|
},
|
|
6429
|
-
`新版本 v${report.latest}`,
|
|
6902
|
+
installFailed ? "安装失败" : running ? "安装中…" : armed ? `确认安装 v${report.latest}` : `新版本 v${report.latest}`,
|
|
6430
6903
|
)
|
|
6431
6904
|
: null,
|
|
6432
|
-
failed
|
|
6905
|
+
failed && !canInstall
|
|
6433
6906
|
? h(
|
|
6434
6907
|
"button",
|
|
6435
6908
|
{ type: "button", className: "mesh-meta-link is-warn", onClick: onCheck, title: report.error },
|
|
@@ -6448,23 +6921,13 @@ window.__ModuleLoader__.load({
|
|
|
6448
6921
|
|
|
6449
6922
|
/**
|
|
6450
6923
|
* 检查更新的容器:进主页**静默**查一次(宿主机缓存 30 分钟),点一下强查。
|
|
6451
|
-
*
|
|
6924
|
+
* 点「新版本」第一下只是确认(6 秒内不点第二下自动取消),第二下才真的装。
|
|
6452
6925
|
*/
|
|
6453
6926
|
function UpdateLink({ push }) {
|
|
6454
6927
|
const [phase, setPhase] = react.useState("idle");
|
|
6455
6928
|
const [report, setReport] = react.useState(null);
|
|
6929
|
+
const [install, setInstall] = react.useState({ state: "idle", error: "" });
|
|
6456
6930
|
const alive = react.useRef(true);
|
|
6457
|
-
const copyCommand = react.useCallback(
|
|
6458
|
-
async (text) => {
|
|
6459
|
-
if (!text) {
|
|
6460
|
-
push("error", "这次结果里没有升级命令,请先重新检查");
|
|
6461
|
-
return;
|
|
6462
|
-
}
|
|
6463
|
-
const ok = await copyText(text);
|
|
6464
|
-
push(ok ? "success" : "error", ok ? "升级命令已复制:装好后重启 DSH 生效" : "复制失败,请手动选择");
|
|
6465
|
-
},
|
|
6466
|
-
[push],
|
|
6467
|
-
);
|
|
6468
6931
|
const run = react.useCallback(
|
|
6469
6932
|
async (force, announce) => {
|
|
6470
6933
|
setPhase("checking");
|
|
@@ -6479,11 +6942,15 @@ window.__ModuleLoader__.load({
|
|
|
6479
6942
|
push("error", `没查到最新版本:${String(next.error || "未知原因")}`);
|
|
6480
6943
|
} else if (next.comparable === false) {
|
|
6481
6944
|
push("error", `版本号无法比较:v${next.current} vs v${next.latest},请到 Release 页面确认`);
|
|
6945
|
+
} else if (next.pendingUpgrade && (!next.latest || next.pendingUpgrade.version === next.latest)) {
|
|
6946
|
+
push(
|
|
6947
|
+
"success",
|
|
6948
|
+
next.pendingUpgrade.restartRequired
|
|
6949
|
+
? `已安装 v${next.pendingUpgrade.version},重启 DSH 后生效`
|
|
6950
|
+
: `已安装 v${next.pendingUpgrade.version},重载界面后生效`,
|
|
6951
|
+
);
|
|
6482
6952
|
} else if (next.hasUpdate) {
|
|
6483
|
-
push("success", `有新版本 v${next.latest}(当前 v${next.current}
|
|
6484
|
-
label: "复制升级命令",
|
|
6485
|
-
onClick: () => copyCommand(next.upgradeCommand),
|
|
6486
|
-
});
|
|
6953
|
+
push("success", `有新版本 v${next.latest}(当前 v${next.current}),点「新版本」一键安装`);
|
|
6487
6954
|
} else {
|
|
6488
6955
|
push("success", `已是最新(v${next.current})`);
|
|
6489
6956
|
}
|
|
@@ -6494,7 +6961,7 @@ window.__ModuleLoader__.load({
|
|
|
6494
6961
|
if (announce) push("error", `没查到最新版本:${String((e && e.message) || e)}`);
|
|
6495
6962
|
}
|
|
6496
6963
|
},
|
|
6497
|
-
[push
|
|
6964
|
+
[push],
|
|
6498
6965
|
);
|
|
6499
6966
|
react.useEffect(() => {
|
|
6500
6967
|
alive.current = true;
|
|
@@ -6503,7 +6970,85 @@ window.__ModuleLoader__.load({
|
|
|
6503
6970
|
alive.current = false;
|
|
6504
6971
|
};
|
|
6505
6972
|
}, [run]);
|
|
6506
|
-
|
|
6973
|
+
// 确认态 6 秒后自动取消:避免"上次点了一半"的按钮一直挂着。
|
|
6974
|
+
react.useEffect(() => {
|
|
6975
|
+
if (install.state !== "armed") return;
|
|
6976
|
+
const timer = setTimeout(() => setInstall({ state: "idle", error: "" }), 6000);
|
|
6977
|
+
return () => clearTimeout(timer);
|
|
6978
|
+
}, [install.state]);
|
|
6979
|
+
|
|
6980
|
+
const startInstall = react.useCallback(async () => {
|
|
6981
|
+
if (!report || report.ok !== true || !report.latest) return;
|
|
6982
|
+
if (install.state !== "armed") {
|
|
6983
|
+
setInstall({ state: "armed", error: "" });
|
|
6984
|
+
return;
|
|
6985
|
+
}
|
|
6986
|
+
setInstall({ state: "running", error: "" });
|
|
6987
|
+
try {
|
|
6988
|
+
const r = await api("/upgrade", { version: report.latest });
|
|
6989
|
+
if (!alive.current) return;
|
|
6990
|
+
if (!r || r.ok !== true) {
|
|
6991
|
+
setInstall({ state: "failed", error: apiErr(r) });
|
|
6992
|
+
push("error", `安装失败:${apiErr(r)}`);
|
|
6993
|
+
return;
|
|
6994
|
+
}
|
|
6995
|
+
setInstall({ state: "idle", error: "" });
|
|
6996
|
+
if (r.upToDate || r.installed === false) {
|
|
6997
|
+
push("success", `v${report.latest} 已经在磁盘上,不用重复安装`);
|
|
6998
|
+
} else if (r.restartRequired) {
|
|
6999
|
+
push("success", `已安装 v${r.version},重启 DSH 后生效(旧版已备份,可回滚)`);
|
|
7000
|
+
} else if (r.reloadRequired) {
|
|
7001
|
+
push("success", `已安装 v${r.version},点「重载界面」即可生效`);
|
|
7002
|
+
} else {
|
|
7003
|
+
push("success", `已安装 v${r.version}`);
|
|
7004
|
+
}
|
|
7005
|
+
await run(true, false);
|
|
7006
|
+
} catch (e) {
|
|
7007
|
+
if (!alive.current) return;
|
|
7008
|
+
setInstall({ state: "failed", error: String((e && e.message) || e) });
|
|
7009
|
+
push("error", `安装失败:${String((e && e.message) || e)}`);
|
|
7010
|
+
}
|
|
7011
|
+
}, [install.state, push, report, run]);
|
|
7012
|
+
|
|
7013
|
+
const restart = react.useCallback(async () => {
|
|
7014
|
+
try {
|
|
7015
|
+
const r = await api("/upgrade/restart", {});
|
|
7016
|
+
if (r && r.ok) push("success", "正在重启 DSH,窗口会自动回来…");
|
|
7017
|
+
else push("error", (r && r.error) || "当前宿主没有可用的重启入口,请手动重启 DSH");
|
|
7018
|
+
} catch (e) {
|
|
7019
|
+
push("error", String((e && e.message) || e));
|
|
7020
|
+
}
|
|
7021
|
+
}, [push]);
|
|
7022
|
+
|
|
7023
|
+
const reload = react.useCallback(async () => {
|
|
7024
|
+
// 先问宿主有没有内置重载入口(DSH Desktop 有:和「开发者选项 → 重新加载
|
|
7025
|
+
// 界面」同一个动作);没有才用页面自身 reload。两种都只重载渲染器,
|
|
7026
|
+
// 不重启宿主。
|
|
7027
|
+
try {
|
|
7028
|
+
const r = await api("/upgrade/reload", {});
|
|
7029
|
+
if (r && r.ok) {
|
|
7030
|
+
push("success", "正在重新加载界面…");
|
|
7031
|
+
return;
|
|
7032
|
+
}
|
|
7033
|
+
} catch {
|
|
7034
|
+
/* 落到页面自身重载 */
|
|
7035
|
+
}
|
|
7036
|
+
try {
|
|
7037
|
+
window.location.reload();
|
|
7038
|
+
} catch {
|
|
7039
|
+
push("error", "无法自动重载,请按 Cmd/Ctrl+R 手动重载界面");
|
|
7040
|
+
}
|
|
7041
|
+
}, [push]);
|
|
7042
|
+
|
|
7043
|
+
return h(UpdateLinkView, {
|
|
7044
|
+
phase,
|
|
7045
|
+
report,
|
|
7046
|
+
install,
|
|
7047
|
+
onCheck: () => run(true, true),
|
|
7048
|
+
onInstall: startInstall,
|
|
7049
|
+
onRestart: restart,
|
|
7050
|
+
onReload: reload,
|
|
7051
|
+
});
|
|
6507
7052
|
}
|
|
6508
7053
|
|
|
6509
7054
|
function HomeMetaLinks({ state, push }) {
|
|
@@ -6694,6 +7239,7 @@ window.__ModuleLoader__.load({
|
|
|
6694
7239
|
onSsh,
|
|
6695
7240
|
onScan,
|
|
6696
7241
|
scanning,
|
|
7242
|
+
onDemo,
|
|
6697
7243
|
firstRun,
|
|
6698
7244
|
hostDown,
|
|
6699
7245
|
onDispatched,
|
|
@@ -7427,6 +7973,10 @@ window.__ModuleLoader__.load({
|
|
|
7427
7973
|
const [transferDraft, setTransferDraft] = react.useState(null);
|
|
7428
7974
|
const [transferLogOpen, setTransferLogOpen] = react.useState(false);
|
|
7429
7975
|
const [transfers, setTransfers] = react.useState(() => loadTransfers());
|
|
7976
|
+
// 「看演示」:单机用户也能看见完整闭环(不连网络、不建会话)
|
|
7977
|
+
const [demoOpen, setDemoOpen] = react.useState(false);
|
|
7978
|
+
// 陌生设备首次派活的确认动作进行中
|
|
7979
|
+
const [approvalBusy, setApprovalBusy] = react.useState(false);
|
|
7430
7980
|
const sessionId = currentSessionId();
|
|
7431
7981
|
|
|
7432
7982
|
const self = state && state.self ? state.self : null;
|
|
@@ -7499,6 +8049,30 @@ window.__ModuleLoader__.load({
|
|
|
7499
8049
|
: null;
|
|
7500
8050
|
const hostDown = !!error;
|
|
7501
8051
|
|
|
8052
|
+
/**
|
|
8053
|
+
* 陌生设备第一次派活的确认。
|
|
8054
|
+
*
|
|
8055
|
+
* 允许 = 对端写进本机信任列表并立刻开始执行;拒绝 = 只标记,不执行。
|
|
8056
|
+
* 两种情况都刷新一次状态,让确认条和任务列表同时更新。
|
|
8057
|
+
*/
|
|
8058
|
+
const decideApproval = async (id, action) => {
|
|
8059
|
+
if (!id || approvalBusy) return;
|
|
8060
|
+
setApprovalBusy(true);
|
|
8061
|
+
try {
|
|
8062
|
+
const r = await api("/approval", { id, action });
|
|
8063
|
+
if (r && r.ok) {
|
|
8064
|
+
push("success", action === "allow" ? "已允许这台设备,任务开始执行" : "已拒绝这次派发");
|
|
8065
|
+
} else {
|
|
8066
|
+
push("error", apiErr(r));
|
|
8067
|
+
}
|
|
8068
|
+
await reload();
|
|
8069
|
+
} catch (e) {
|
|
8070
|
+
push("error", String((e && e.message) || e));
|
|
8071
|
+
} finally {
|
|
8072
|
+
setApprovalBusy(false);
|
|
8073
|
+
}
|
|
8074
|
+
};
|
|
8075
|
+
|
|
7502
8076
|
const saveName = async (raw) => {
|
|
7503
8077
|
const name = String(raw || "").trim();
|
|
7504
8078
|
if (!name) return false;
|
|
@@ -7718,7 +8292,11 @@ window.__ModuleLoader__.load({
|
|
|
7718
8292
|
* 设备页弹层和主页的派发面板共用它,免得两处提示文案慢慢走散。
|
|
7719
8293
|
*/
|
|
7720
8294
|
const notifyDispatched = (name, r) => {
|
|
7721
|
-
|
|
8295
|
+
// 202 = 对端收到了,但在等人点「允许」。不能把「送达」说成「开跑」。
|
|
8296
|
+
const pending = !!(r && r.pendingApproval);
|
|
8297
|
+
push(pending ? "info" : "success", pending
|
|
8298
|
+
? `已送达 ${name || "对端"},等它那边点一次「允许」`
|
|
8299
|
+
: `已派发给 ${name || "对端"}${r && r.id ? `(${r.id})` : ""}`, {
|
|
7722
8300
|
label: "查看任务",
|
|
7723
8301
|
onClick: () => {
|
|
7724
8302
|
setView("tasks");
|
|
@@ -7969,6 +8547,9 @@ window.__ModuleLoader__.load({
|
|
|
7969
8547
|
},
|
|
7970
8548
|
})
|
|
7971
8549
|
: null,
|
|
8550
|
+
state.approvals && state.approvals.length
|
|
8551
|
+
? h(ApprovalBar, { items: state.approvals, busy: approvalBusy, onDecide: decideApproval })
|
|
8552
|
+
: null,
|
|
7972
8553
|
h(
|
|
7973
8554
|
"main",
|
|
7974
8555
|
{ key: view, className: "mesh-view", role: "tabpanel", "aria-label": view === "home" ? "主页" : view === "devices" ? "设备" : view === "tasks" ? "任务" : "连接" },
|
|
@@ -7998,6 +8579,7 @@ window.__ModuleLoader__.load({
|
|
|
7998
8579
|
onSsh: (peer) => setSshPeer(peer),
|
|
7999
8580
|
onScan: doScan,
|
|
8000
8581
|
scanning,
|
|
8582
|
+
onDemo: () => setDemoOpen(true),
|
|
8001
8583
|
firstRun: firstRunNode,
|
|
8002
8584
|
hostDown,
|
|
8003
8585
|
onDispatched: (peer, r) => notifyDispatched((peer && peer.machine) || "", r),
|
|
@@ -8023,6 +8605,7 @@ window.__ModuleLoader__.load({
|
|
|
8023
8605
|
lastOk,
|
|
8024
8606
|
onScan: doScan,
|
|
8025
8607
|
scanning,
|
|
8608
|
+
onDemo: () => setDemoOpen(true),
|
|
8026
8609
|
recentTasks,
|
|
8027
8610
|
onOpenTask: openTask,
|
|
8028
8611
|
onAllTasks: openAllTasks,
|
|
@@ -8092,6 +8675,7 @@ window.__ModuleLoader__.load({
|
|
|
8092
8675
|
h(WebPanel, { panel: webPanel, onClose: closeWebPanel, onReload: reloadWebPanel }),
|
|
8093
8676
|
sshPeer ? h(SshPanel, { peer: sshPeer, onClose: () => setSshPeer(null) }) : null,
|
|
8094
8677
|
h(Toasts, { items: toasts, onClose: close }),
|
|
8678
|
+
h(DemoOverlay, { open: demoOpen, onClose: () => setDemoOpen(false) }),
|
|
8095
8679
|
);
|
|
8096
8680
|
}
|
|
8097
8681
|
|
|
@@ -8130,6 +8714,7 @@ window.__ModuleLoader__.load({
|
|
|
8130
8714
|
ctx.slots.inject("main", () =>
|
|
8131
8715
|
ctx.slots.register({ name: "main", key: PANEL_ID }, MeshApp),
|
|
8132
8716
|
);
|
|
8717
|
+
registerAtPeerSource(ctx);
|
|
8133
8718
|
ctx.logger?.info?.("mesh client: 已注册 Mesh 工作台");
|
|
8134
8719
|
}
|
|
8135
8720
|
|
|
@@ -8140,6 +8725,8 @@ window.__ModuleLoader__.load({
|
|
|
8140
8725
|
HomeView,
|
|
8141
8726
|
HomeBoard,
|
|
8142
8727
|
DispatchPanel,
|
|
8728
|
+
DemoOverlay,
|
|
8729
|
+
ApprovalBar,
|
|
8143
8730
|
DeviceList,
|
|
8144
8731
|
TasksView,
|
|
8145
8732
|
DeviceDetail,
|
|
@@ -8179,6 +8766,9 @@ window.__ModuleLoader__.load({
|
|
|
8179
8766
|
FeedbackLink,
|
|
8180
8767
|
feedbackBody,
|
|
8181
8768
|
feedbackIssueUrl,
|
|
8769
|
+
buildAtPeerSource,
|
|
8770
|
+
loadOnlinePeers,
|
|
8771
|
+
resetAtPeersCache,
|
|
8182
8772
|
};
|
|
8183
8773
|
return module.exports;
|
|
8184
8774
|
},
|