dsh-plugin-mesh 0.5.9 → 0.5.11
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/README.en.md +12 -0
- package/README.md +12 -0
- package/client/client.js +132 -28
- package/lib/_selftest-workbench.mjs +57 -23
- package/lib/discovery.js +45 -1
- package/lib/index.js +43 -11
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -123,4 +123,16 @@ The full key list with defaults is in [`llms.txt`](llms.txt#configuration).
|
|
|
123
123
|
| Issues | https://github.com/peng456/dsh-plugin-mesh/issues |
|
|
124
124
|
| Contact | geekstartup@163.com |
|
|
125
125
|
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## Sponsors
|
|
129
|
+
|
|
130
|
+
<a href="https://omdsh.dev/"><img src="https://omdsh.dev/assets/logo-orca.png" width="22" height="22" alt="Oh My DSH"></a> **[OMDSH](https://omdsh.dev/)** (Oh My DSH) · *Beyond the default.* · DeepSeek Harness developer community
|
|
131
|
+
|
|
132
|
+
Independent and unofficial; it sponsors the model tokens (compute) for this project. Website <https://omdsh.dev/>
|
|
133
|
+
|
|
134
|
+
Thanks, OMDSH. Sponsorship is support, not a purchase: everything here is free, and sponsorship unlocks no features.
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
126
138
|
MIT licensed. Not affiliated with DeepSeek.
|
package/README.md
CHANGED
|
@@ -137,4 +137,16 @@ npm test
|
|
|
137
137
|
|
|
138
138
|
有问题或想提需求:<https://github.com/peng456/dsh-plugin-mesh/issues> · 邮箱 `geekstartup@163.com`
|
|
139
139
|
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## 赞助方
|
|
143
|
+
|
|
144
|
+
<a href="https://omdsh.dev/"><img src="https://omdsh.dev/assets/logo-orca.png" width="22" height="22" alt="Oh My DSH"></a> **[OMDSH](https://omdsh.dev/)**(Oh My DSH)· *Beyond the default.* · DeepSeek Harness 开发者社区
|
|
145
|
+
|
|
146
|
+
独立、非官方,为本项目赞助模型 token(算力)。官网 <https://omdsh.dev/>
|
|
147
|
+
|
|
148
|
+
感谢 OMDSH 的支持。赞助是支持,不是购买——本项目全部功能免费,赞助不解锁任何能力。
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
140
152
|
MIT · 与 DeepSeek 官方无隶属关系
|
package/client/client.js
CHANGED
|
@@ -1694,6 +1694,36 @@ window.__ModuleLoader__.load({
|
|
|
1694
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
1695
|
.mesh-demo-note { margin-right: auto; font-size: 10.5px; color: var(--mesh-muted); align-self: center; }
|
|
1696
1696
|
|
|
1697
|
+
/* ── 安装确认弹窗:一次点击 → 一个说清楚要发生什么的弹窗 ── */
|
|
1698
|
+
.mesh-confirm-layer {
|
|
1699
|
+
position: fixed; inset: 0; z-index: 2147482700;
|
|
1700
|
+
display: flex; align-items: center; justify-content: center;
|
|
1701
|
+
padding: 22px; background: rgba(12, 14, 18, .46);
|
|
1702
|
+
animation: mesh-view-in 140ms ease both;
|
|
1703
|
+
}
|
|
1704
|
+
.mesh-confirm-card {
|
|
1705
|
+
width: min(430px, 100%);
|
|
1706
|
+
background: var(--mesh-surface); color: var(--mesh-fg);
|
|
1707
|
+
border: 1px solid var(--mesh-line); border-radius: 16px;
|
|
1708
|
+
box-shadow: 0 24px 70px rgba(0,0,0,.34);
|
|
1709
|
+
overflow: hidden; animation: mesh-detail-in 180ms var(--mesh-ease-out) both;
|
|
1710
|
+
}
|
|
1711
|
+
.mesh-confirm-head { display: flex; align-items: center; gap: 9px; padding: 16px 18px 6px; }
|
|
1712
|
+
.mesh-confirm-title { font-size: 14px; font-weight: 600; letter-spacing: -.01em; }
|
|
1713
|
+
.mesh-confirm-body { padding: 4px 18px 14px; font-size: 12px; line-height: 1.7; }
|
|
1714
|
+
.mesh-confirm-body p { margin: 0 0 8px; color: var(--mesh-muted); }
|
|
1715
|
+
.mesh-confirm-ver {
|
|
1716
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
1717
|
+
font-size: 12px; color: var(--mesh-fg);
|
|
1718
|
+
}
|
|
1719
|
+
.mesh-confirm-list { margin: 0 0 10px; padding-left: 18px; color: var(--mesh-muted); }
|
|
1720
|
+
.mesh-confirm-list li { margin: 2px 0; }
|
|
1721
|
+
.mesh-confirm-warn { color: var(--mesh-warn); font-size: 11.5px; margin: 0; }
|
|
1722
|
+
.mesh-confirm-foot {
|
|
1723
|
+
display: flex; gap: 8px; justify-content: flex-end;
|
|
1724
|
+
padding: 12px 18px 16px; border-top: 1px solid var(--mesh-line);
|
|
1725
|
+
}
|
|
1726
|
+
|
|
1697
1727
|
/* 主页底部的派发面板:视觉上跟卡片同级,但不参与拖动/隐藏。 */
|
|
1698
1728
|
.mesh-dispatch {
|
|
1699
1729
|
margin-top: 16px;
|
|
@@ -6818,7 +6848,6 @@ window.__ModuleLoader__.load({
|
|
|
6818
6848
|
const checking = phase === "checking";
|
|
6819
6849
|
const state = (install && install.state) || "idle";
|
|
6820
6850
|
const running = state === "running";
|
|
6821
|
-
const armed = state === "armed";
|
|
6822
6851
|
const installFailed = state === "failed";
|
|
6823
6852
|
const busy = checking || running;
|
|
6824
6853
|
const pending =
|
|
@@ -6894,12 +6923,10 @@ window.__ModuleLoader__.load({
|
|
|
6894
6923
|
disabled: running,
|
|
6895
6924
|
title: installFailed
|
|
6896
6925
|
? `上次安装失败:${String(install.error || "未知原因")};点一下重试`
|
|
6897
|
-
:
|
|
6898
|
-
|
|
6899
|
-
: `一键安装 v${report.latest}(先校验 sha512,可加载检查通过才替换)`,
|
|
6900
|
-
"aria-label": armed ? `确认安装 v${report.latest}` : `安装 v${report.latest}`,
|
|
6926
|
+
: `安装 v${report.latest}(先弹确认,再下载、校验、替换)`,
|
|
6927
|
+
"aria-label": `安装 v${report.latest}`,
|
|
6901
6928
|
},
|
|
6902
|
-
installFailed ? "安装失败" : running ? "安装中…" :
|
|
6929
|
+
installFailed ? "安装失败" : running ? "安装中…" : `新版本 v${report.latest}`,
|
|
6903
6930
|
)
|
|
6904
6931
|
: null,
|
|
6905
6932
|
failed && !canInstall
|
|
@@ -6919,14 +6946,88 @@ window.__ModuleLoader__.load({
|
|
|
6919
6946
|
);
|
|
6920
6947
|
}
|
|
6921
6948
|
|
|
6949
|
+
/**
|
|
6950
|
+
* 安装确认弹窗:一次点击就打开,把"要发生什么"说清楚再动手。
|
|
6951
|
+
*
|
|
6952
|
+
* 为什么不是"点两下":旧版把第一次点击做成静默确认态,按钮文案虽然变了,
|
|
6953
|
+
* 但没有别的提示,很多人点一下就以为装完了(真机反馈:点一次就重启,
|
|
6954
|
+
* 结果还是旧版本)。确认应该是一个看得见的弹窗,而不是一个容易错过的按钮状态。
|
|
6955
|
+
*/
|
|
6956
|
+
function InstallConfirm({ report, busy, onCancel, onConfirm }) {
|
|
6957
|
+
const to = report && report.latest ? String(report.latest) : "";
|
|
6958
|
+
const from = report ? String(report.current || report.diskVersion || "?") : "?";
|
|
6959
|
+
react.useEffect(() => {
|
|
6960
|
+
const onKey = (e) => {
|
|
6961
|
+
if (e.key === "Escape" && !busy) onCancel();
|
|
6962
|
+
};
|
|
6963
|
+
document.addEventListener("keydown", onKey);
|
|
6964
|
+
return () => document.removeEventListener("keydown", onKey);
|
|
6965
|
+
}, [busy, onCancel]);
|
|
6966
|
+
if (!report || report.hasUpdate !== true || !to) return null;
|
|
6967
|
+
return h(
|
|
6968
|
+
"div",
|
|
6969
|
+
{
|
|
6970
|
+
className: "mesh-confirm-layer",
|
|
6971
|
+
role: "dialog",
|
|
6972
|
+
"aria-modal": "true",
|
|
6973
|
+
"aria-label": `安装 v${to}`,
|
|
6974
|
+
onClick: (e) => {
|
|
6975
|
+
if (e.target === e.currentTarget && !busy) onCancel();
|
|
6976
|
+
},
|
|
6977
|
+
},
|
|
6978
|
+
h(
|
|
6979
|
+
"div",
|
|
6980
|
+
{ className: "mesh-confirm-card" },
|
|
6981
|
+
h(
|
|
6982
|
+
"div",
|
|
6983
|
+
{ className: "mesh-confirm-head" },
|
|
6984
|
+
h(Icon, { name: "arrowUp", size: 15 }),
|
|
6985
|
+
h("span", { className: "mesh-confirm-title" }, `安装 Mesh v${to}?`),
|
|
6986
|
+
),
|
|
6987
|
+
h(
|
|
6988
|
+
"div",
|
|
6989
|
+
{ className: "mesh-confirm-body" },
|
|
6990
|
+
h(
|
|
6991
|
+
"p",
|
|
6992
|
+
null,
|
|
6993
|
+
"当前 ",
|
|
6994
|
+
h("span", { className: "mesh-confirm-ver" }, `v${from}`),
|
|
6995
|
+
" → 目标 ",
|
|
6996
|
+
h("span", { className: "mesh-confirm-ver" }, `v${to}`),
|
|
6997
|
+
),
|
|
6998
|
+
h(
|
|
6999
|
+
"ul",
|
|
7000
|
+
{ className: "mesh-confirm-list" },
|
|
7001
|
+
h("li", null, "从 npm 下载,并校验 sha512"),
|
|
7002
|
+
h("li", null, "可加载检查通过后才替换文件;旧版本会备份,可回滚"),
|
|
7003
|
+
h("li", null, "装完在顶部点「重启生效」;只改界面时会提示重载即可"),
|
|
7004
|
+
),
|
|
7005
|
+
h("p", { className: "mesh-confirm-warn" }, "重启 DSH 会中断当前会话。"),
|
|
7006
|
+
),
|
|
7007
|
+
h(
|
|
7008
|
+
"div",
|
|
7009
|
+
{ className: "mesh-confirm-foot" },
|
|
7010
|
+
h(Button, { variant: "ghost", disabled: busy, onClick: onCancel }, "取消"),
|
|
7011
|
+
h(
|
|
7012
|
+
Button,
|
|
7013
|
+
{ variant: "primary", loading: busy, onClick: onConfirm },
|
|
7014
|
+
busy ? "安装中…" : `安装 v${to}`,
|
|
7015
|
+
),
|
|
7016
|
+
),
|
|
7017
|
+
),
|
|
7018
|
+
);
|
|
7019
|
+
}
|
|
7020
|
+
|
|
6922
7021
|
/**
|
|
6923
7022
|
* 检查更新的容器:进主页**静默**查一次(宿主机缓存 30 分钟),点一下强查。
|
|
6924
|
-
*
|
|
7023
|
+
* 点「新版本」→ 弹确认框 → 点「安装」才真的动手。
|
|
6925
7024
|
*/
|
|
6926
7025
|
function UpdateLink({ push }) {
|
|
6927
7026
|
const [phase, setPhase] = react.useState("idle");
|
|
6928
7027
|
const [report, setReport] = react.useState(null);
|
|
6929
7028
|
const [install, setInstall] = react.useState({ state: "idle", error: "" });
|
|
7029
|
+
// 安装确认弹窗:点「新版本」打开,点「安装」才真的开始
|
|
7030
|
+
const [confirmOpen, setConfirmOpen] = react.useState(false);
|
|
6930
7031
|
const alive = react.useRef(true);
|
|
6931
7032
|
const run = react.useCallback(
|
|
6932
7033
|
async (force, announce) => {
|
|
@@ -6970,19 +7071,9 @@ window.__ModuleLoader__.load({
|
|
|
6970
7071
|
alive.current = false;
|
|
6971
7072
|
};
|
|
6972
7073
|
}, [run]);
|
|
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
7074
|
const startInstall = react.useCallback(async () => {
|
|
6981
7075
|
if (!report || report.ok !== true || !report.latest) return;
|
|
6982
|
-
|
|
6983
|
-
setInstall({ state: "armed", error: "" });
|
|
6984
|
-
return;
|
|
6985
|
-
}
|
|
7076
|
+
setConfirmOpen(false);
|
|
6986
7077
|
setInstall({ state: "running", error: "" });
|
|
6987
7078
|
try {
|
|
6988
7079
|
const r = await api("/upgrade", { version: report.latest });
|
|
@@ -7008,7 +7099,7 @@ window.__ModuleLoader__.load({
|
|
|
7008
7099
|
setInstall({ state: "failed", error: String((e && e.message) || e) });
|
|
7009
7100
|
push("error", `安装失败:${String((e && e.message) || e)}`);
|
|
7010
7101
|
}
|
|
7011
|
-
}, [
|
|
7102
|
+
}, [push, report, run]);
|
|
7012
7103
|
|
|
7013
7104
|
const restart = react.useCallback(async () => {
|
|
7014
7105
|
try {
|
|
@@ -7040,15 +7131,27 @@ window.__ModuleLoader__.load({
|
|
|
7040
7131
|
}
|
|
7041
7132
|
}, [push]);
|
|
7042
7133
|
|
|
7043
|
-
return h(
|
|
7044
|
-
|
|
7045
|
-
|
|
7046
|
-
|
|
7047
|
-
|
|
7048
|
-
|
|
7049
|
-
|
|
7050
|
-
|
|
7051
|
-
|
|
7134
|
+
return h(
|
|
7135
|
+
react.Fragment,
|
|
7136
|
+
null,
|
|
7137
|
+
h(UpdateLinkView, {
|
|
7138
|
+
phase,
|
|
7139
|
+
report,
|
|
7140
|
+
install,
|
|
7141
|
+
onCheck: () => run(true, true),
|
|
7142
|
+
onInstall: () => setConfirmOpen(true),
|
|
7143
|
+
onRestart: restart,
|
|
7144
|
+
onReload: reload,
|
|
7145
|
+
}),
|
|
7146
|
+
confirmOpen
|
|
7147
|
+
? h(InstallConfirm, {
|
|
7148
|
+
report,
|
|
7149
|
+
busy: install.state === "running",
|
|
7150
|
+
onCancel: () => setConfirmOpen(false),
|
|
7151
|
+
onConfirm: startInstall,
|
|
7152
|
+
})
|
|
7153
|
+
: null,
|
|
7154
|
+
);
|
|
7052
7155
|
}
|
|
7053
7156
|
|
|
7054
7157
|
function HomeMetaLinks({ state, push }) {
|
|
@@ -8763,6 +8866,7 @@ window.__ModuleLoader__.load({
|
|
|
8763
8866
|
HomeMetaLinks,
|
|
8764
8867
|
UpdateLink,
|
|
8765
8868
|
UpdateLinkView,
|
|
8869
|
+
InstallConfirm,
|
|
8766
8870
|
FeedbackLink,
|
|
8767
8871
|
feedbackBody,
|
|
8768
8872
|
feedbackIssueUrl,
|
|
@@ -145,6 +145,7 @@ const {
|
|
|
145
145
|
HomeSwitchBar,
|
|
146
146
|
UpdateLink,
|
|
147
147
|
UpdateLinkView,
|
|
148
|
+
InstallConfirm,
|
|
148
149
|
FeedbackLink,
|
|
149
150
|
DemoOverlay,
|
|
150
151
|
ApprovalBar,
|
|
@@ -1157,30 +1158,63 @@ test("有更新:一行小字「新版本 v0.6.0」,不铺命令、不占卡
|
|
|
1157
1158
|
assert.ok(!txt.includes("curl"), "升级命令不再铺在页面上");
|
|
1158
1159
|
});
|
|
1159
1160
|
|
|
1160
|
-
test("
|
|
1161
|
-
let
|
|
1162
|
-
const
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
});
|
|
1177
|
-
return btn;
|
|
1178
|
-
};
|
|
1179
|
-
const armed = view({ state: "armed", error: "" });
|
|
1180
|
-
const btn = findInstallBtn(armed);
|
|
1181
|
-
assert.ok(btn, "确认态要有一个「确认安装 v0.6.0」按钮");
|
|
1161
|
+
test("一键安装:点「新版本」只打开确认弹窗,不会直接装", () => {
|
|
1162
|
+
let requested = 0;
|
|
1163
|
+
const el = UpdateLinkView({
|
|
1164
|
+
phase: "done",
|
|
1165
|
+
report: updateReport,
|
|
1166
|
+
install: { state: "idle", error: "" },
|
|
1167
|
+
onCheck: noop,
|
|
1168
|
+
onInstall: () => {
|
|
1169
|
+
requested += 1;
|
|
1170
|
+
},
|
|
1171
|
+
});
|
|
1172
|
+
let btn = null;
|
|
1173
|
+
walk(el, (n) => {
|
|
1174
|
+
if (n.type === "button" && textOf(n).join("").includes("新版本 v0.6.0")) btn = n;
|
|
1175
|
+
});
|
|
1176
|
+
assert.ok(btn, "缺少「新版本 v0.6.0」入口");
|
|
1182
1177
|
btn.props.onClick();
|
|
1183
|
-
assert.equal(
|
|
1178
|
+
assert.equal(requested, 1, "点击入口应当是打开确认,而不是直接安装");
|
|
1179
|
+
});
|
|
1180
|
+
|
|
1181
|
+
test("确认弹窗:说清版本、校验与重启代价,安装/取消各走各的", () => {
|
|
1182
|
+
let confirmed = 0;
|
|
1183
|
+
let cancelled = 0;
|
|
1184
|
+
const el = InstallConfirm({
|
|
1185
|
+
report: updateReport,
|
|
1186
|
+
busy: false,
|
|
1187
|
+
onCancel: () => {
|
|
1188
|
+
cancelled += 1;
|
|
1189
|
+
},
|
|
1190
|
+
onConfirm: () => {
|
|
1191
|
+
confirmed += 1;
|
|
1192
|
+
},
|
|
1193
|
+
});
|
|
1194
|
+
const txt = textOf(el).join(" ");
|
|
1195
|
+
assert.ok(txt.includes("安装 Mesh v0.6.0"), txt);
|
|
1196
|
+
assert.ok(txt.includes("v0.5.6") && txt.includes("v0.6.0"), txt);
|
|
1197
|
+
assert.ok(txt.includes("sha512"), "要说明会做完整性校验");
|
|
1198
|
+
assert.ok(txt.includes("备份"), "要说明旧版可回滚");
|
|
1199
|
+
assert.ok(txt.includes("重启"), "要提前说重启代价");
|
|
1200
|
+
let installBtn = null;
|
|
1201
|
+
let cancelBtn = null;
|
|
1202
|
+
walk(el, (n) => {
|
|
1203
|
+
const label = n.type === "button" ? textOf(n).join("") : "";
|
|
1204
|
+
if (label === "安装 v0.6.0") installBtn = n;
|
|
1205
|
+
if (label === "取消") cancelBtn = n;
|
|
1206
|
+
});
|
|
1207
|
+
assert.ok(installBtn && cancelBtn, "缺少安装或取消按钮");
|
|
1208
|
+
installBtn.props.onClick();
|
|
1209
|
+
cancelBtn.props.onClick();
|
|
1210
|
+
assert.equal(confirmed, 1);
|
|
1211
|
+
assert.equal(cancelled, 1);
|
|
1212
|
+
});
|
|
1213
|
+
|
|
1214
|
+
test("确认弹窗安装中:按钮显示「安装中…」,取消被禁用", () => {
|
|
1215
|
+
const el = InstallConfirm({ report: updateReport, busy: true, onCancel: noop, onConfirm: noop });
|
|
1216
|
+
const txt = textOf(el).join(" ");
|
|
1217
|
+
assert.ok(txt.includes("安装中…"), txt);
|
|
1184
1218
|
});
|
|
1185
1219
|
|
|
1186
1220
|
test("安装中 / 安装失败:状态写在字面上,失败不悄悄回到「有新版本」", () => {
|
package/lib/discovery.js
CHANGED
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
* 安全:发现是完全公开的(局域网内谁都能看见谁),这是有意设计 ——
|
|
14
14
|
* 先让你看见机器,再决定要不要和它配对。真正的操作要过 token。
|
|
15
15
|
*/
|
|
16
|
-
import dgram from "node:dgram";
|
|
17
16
|
import { EventEmitter } from "node:events";
|
|
18
17
|
import os from "node:os";
|
|
19
18
|
import { sanitizeCapabilities, isCapabilityStale, summarizeCapabilities, currentCapabilities } from "./capabilities.js";
|
|
@@ -205,6 +204,25 @@ export function peerOnline(peer, now = Date.now(), ttlMs = 20000) {
|
|
|
205
204
|
* "change" —— 对端列表有任何变化(新增/离线/恢复/信息更新)
|
|
206
205
|
* "diagnostic" —— 网络层问题(非致命),参数为字符串
|
|
207
206
|
*/
|
|
207
|
+
/**
|
|
208
|
+
* `node:dgram`, resolved on demand.
|
|
209
|
+
*
|
|
210
|
+
* Multicast announce/listen is this module's only consumer of datagram sockets.
|
|
211
|
+
* The sweep timer, the record table and everything active scan writes all work
|
|
212
|
+
* without it, so a host — or a browser page — that has no `dgram` loses passive
|
|
213
|
+
* discovery and nothing else. The specifier is assembled at runtime so a bundler
|
|
214
|
+
* cannot resolve it ahead of time: in a page it must fail at the call, not at the
|
|
215
|
+
* module loader, or the whole plugin never loads.
|
|
216
|
+
* @returns the module namespace.
|
|
217
|
+
*/
|
|
218
|
+
async function loadDgramModule() {
|
|
219
|
+
const specifier = "node:" + "dgram";
|
|
220
|
+
return await import(/* @vite-ignore */ specifier);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** The resolved `node:dgram`, once a host that has it asked for multicast. */
|
|
224
|
+
let dgram;
|
|
225
|
+
|
|
208
226
|
export class MeshDiscovery extends EventEmitter {
|
|
209
227
|
#id;
|
|
210
228
|
#port;
|
|
@@ -369,6 +387,32 @@ export class MeshDiscovery extends EventEmitter {
|
|
|
369
387
|
|
|
370
388
|
if (!multicast) return this;
|
|
371
389
|
|
|
390
|
+
// A page has no datagram sockets, and asking for the module would throw
|
|
391
|
+
// from the loader rather than from here. Say so once and keep the rest of
|
|
392
|
+
// discovery — the sweep, and every record active scan writes — running.
|
|
393
|
+
if (typeof window !== "undefined") {
|
|
394
|
+
this.emit("diagnostic", "multicast discovery is unavailable in a browser page; sweep and active scan still run");
|
|
395
|
+
return this;
|
|
396
|
+
}
|
|
397
|
+
if (dgram !== undefined) {
|
|
398
|
+
this.#startMulticast();
|
|
399
|
+
return this;
|
|
400
|
+
}
|
|
401
|
+
void (async () => {
|
|
402
|
+
try {
|
|
403
|
+
dgram = await loadDgramModule();
|
|
404
|
+
} catch (error) {
|
|
405
|
+
this.emit("diagnostic", `no datagram sockets on this host; passive discovery is off (${error?.message ?? error})`);
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
// Between the caller asking and the module arriving, stop() may have run.
|
|
409
|
+
if (this.#started && this.#multicast && this.#socket === null) this.#startMulticast();
|
|
410
|
+
})();
|
|
411
|
+
return this;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/** Bind the multicast socket and start announcing. */
|
|
415
|
+
#startMulticast() {
|
|
372
416
|
const socket = dgram.createSocket({ type: "udp4", reuseAddr: true });
|
|
373
417
|
this.#socket = socket;
|
|
374
418
|
|
package/lib/index.js
CHANGED
|
@@ -35,7 +35,18 @@ import {
|
|
|
35
35
|
import z from "@deepseek-ai/schemastery";
|
|
36
36
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
37
37
|
import { createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
38
|
-
|
|
38
|
+
/**
|
|
39
|
+
* A compile-time brand: the value it returns is the value it was given.
|
|
40
|
+
*
|
|
41
|
+
* It used to be imported from `@deepseek-ai/dsh-brand`, which is the right place
|
|
42
|
+
* for the *type*. At runtime it is an identity function, and not every dsh line
|
|
43
|
+
* ships it to every target — the browser build pins an older release whose
|
|
44
|
+
* module is empty — so importing it turns a type-level nicety into a hard
|
|
45
|
+
* dependency on a version this plugin does not otherwise care about.
|
|
46
|
+
* @param {string} value - the string.
|
|
47
|
+
* @returns the same string.
|
|
48
|
+
*/
|
|
49
|
+
const brandString = (value) => value;
|
|
39
50
|
import { MeshDiscovery, preferredAddress, lanIPv4Addresses, macForAddress, orderedEndpoints } from "./discovery.js";
|
|
40
51
|
import { candidateAddresses, scanForPeers } from "./scan.js";
|
|
41
52
|
import { machineFingerprint } from "./identity.js";
|
|
@@ -96,7 +107,6 @@ import { resolveTailnetChannels } from "./tsnet/channels.js";
|
|
|
96
107
|
import { tailnetFetch, tailnetOrigin } from "./tsnet/bridge.js";
|
|
97
108
|
import { createWebProxy } from "./web-proxy.js";
|
|
98
109
|
import { createSecretReader } from "./desktop-auth.js";
|
|
99
|
-
import { createSshManager } from "./ssh-host.js";
|
|
100
110
|
import { acceptUpgrade } from "./ws-mini.js";
|
|
101
111
|
import {
|
|
102
112
|
createDesktopWebForwarder,
|
|
@@ -108,7 +118,7 @@ import {
|
|
|
108
118
|
export const name = "dsh-plugin-mesh";
|
|
109
119
|
export const inject = ["tools", "webServer"];
|
|
110
120
|
|
|
111
|
-
const VERSION = "0.5.
|
|
121
|
+
const VERSION = "0.5.11";
|
|
112
122
|
// 诊断用:进程启动时间 + 入口真实路径。磁盘上的版本**不在这里缓存** ——
|
|
113
123
|
// 升级之后进程还跑旧代码,版本号必须现读磁盘才能立刻反映出来(真踩过:
|
|
114
124
|
// 磁盘升到 0.5.1,进程还在 0.5.0,界面显示 0.5.0)。
|
|
@@ -4478,26 +4488,48 @@ function registerUiRoutes(ctx, { discovery, config, identity, inbound, outbound,
|
|
|
4478
4488
|
//
|
|
4479
4489
|
// 入口在设备行(与「访问 DSH Web」同一位置)。会话由本机发起,凭据只存本机;
|
|
4480
4490
|
// 传输走同源 WebSocket(/mesh/api/ssh/ws),所以不需要经过上面对端的 web 转发。
|
|
4481
|
-
|
|
4482
|
-
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
|
|
4491
|
+
// The SSH terminal is the one part of this plugin that cannot exist in a
|
|
4492
|
+
// browser: it needs `crypto.generateKeyPairSync` and a raw socket. Ask for it
|
|
4493
|
+
// by a runtime-visible name so a page gets `undefined` here instead of a
|
|
4494
|
+
// module-loader failure that takes the whole plugin down with it.
|
|
4495
|
+
let ssh;
|
|
4496
|
+
{
|
|
4497
|
+
// Loaded on demand for the same reason the module no longer sits at the top
|
|
4498
|
+
// of this file: RSA key generation and raw sockets do not exist in a page,
|
|
4499
|
+
// and a static import would take the whole plugin down over a feature the
|
|
4500
|
+
// page cannot have anyway. Routes registered below check `ssh` when they
|
|
4501
|
+
// run, so settling a moment later is fine.
|
|
4502
|
+
const specifier = "./ssh-host.js";
|
|
4503
|
+
import(/* @vite-ignore */ specifier).then((module) => {
|
|
4504
|
+
ssh = module.createSshManager({
|
|
4505
|
+
stateDir: stateDir(),
|
|
4506
|
+
credentialsPath: join(stateDir(), "ssh-credentials.json"),
|
|
4507
|
+
log,
|
|
4508
|
+
warn,
|
|
4509
|
+
});
|
|
4510
|
+
ctx.effect(() => () => ssh?.closeAll());
|
|
4511
|
+
}).catch((error) => {
|
|
4512
|
+
warn(`SSH 终端不可用(${error?.message ?? error});其余 mesh 功能不受影响`);
|
|
4513
|
+
});
|
|
4514
|
+
}
|
|
4488
4515
|
|
|
4489
4516
|
post("/mesh/api/ssh/known", async (req, res) => {
|
|
4490
4517
|
const body = await readJson(req);
|
|
4491
4518
|
const machine = String(body?.machine ?? "").trim();
|
|
4492
4519
|
// 只回用户名与"是否已部署密钥",不回密码:密码没有再穿过一次网络的理由
|
|
4520
|
+
if (ssh === undefined) return send(res, 503, { ok: false, error: "SSH 终端在这个环境里不可用" });
|
|
4493
4521
|
const info = ssh.describe(machine);
|
|
4494
4522
|
return send(res, 200, { ok: true, username: info.username, hasKey: info.hasKey, saved: !!info.username });
|
|
4495
4523
|
});
|
|
4496
4524
|
|
|
4497
|
-
post("/mesh/api/ssh/sessions", (_req, res) => send(res, 200, { ok: true, sessions: ssh
|
|
4525
|
+
post("/mesh/api/ssh/sessions", (_req, res) => send(res, 200, { ok: true, sessions: ssh?.list() ?? [] }));
|
|
4498
4526
|
|
|
4499
4527
|
// 一条 upgrade 路由承载所有终端(按会话 id 多路复用)
|
|
4500
4528
|
const sshUpgrade = (req, socket, head) => {
|
|
4529
|
+
if (ssh === undefined) {
|
|
4530
|
+
try { socket.end("HTTP/1.1 503 Service Unavailable\r\nconnection: close\r\n\r\n"); } catch { /* 已断 */ }
|
|
4531
|
+
return;
|
|
4532
|
+
}
|
|
4501
4533
|
const chan = acceptUpgrade(req, socket, head, {
|
|
4502
4534
|
onMessage: async (raw) => {
|
|
4503
4535
|
let msg;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-mesh",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.11",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "把跑不完的活交给另一台电脑;跑完,结果回到你面前。两台装了 DSH 的电脑各装一次,自动互相发现,任务派过去由对端的 agent 执行,结果派回来。Hand a long task to another machine: your DSH instances find each other, the peer runs it, and the result comes back. No pairing codes, no IPs, no Tailscale client.",
|
|
6
6
|
"license": "MIT",
|