dsh-hiss-plugins 1.3.1 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -14
- package/cordis.patch.yml +7 -0
- package/lib/client.js +629 -7
- package/lib/lan-access/gateway.js +348 -0
- package/lib/lan-access/index.js +298 -0
- package/lib/lan-access/qr.js +442 -0
- package/lib/project-mcp/actions.js +60 -0
- package/lib/project-mcp/config.js +119 -1
- package/lib/project-mcp/index.js +429 -23
- package/lib/project-mcp/state.js +154 -0
- package/lib/project-mcp/view.js +109 -0
- package/locale/en.json +47 -3
- package/locale/zh.json +47 -3
- package/package.json +8 -4
package/lib/client.js
CHANGED
|
@@ -36,6 +36,7 @@ window.__ModuleLoader__.load({
|
|
|
36
36
|
{ key: "ponytail", moduleName: `${PACKAGE_ID}/ponytail`, description: "featurePonytailDescription" },
|
|
37
37
|
{ key: "init", moduleName: `${PACKAGE_ID}/init`, description: "featureInitDescription" },
|
|
38
38
|
{ key: "fix", moduleName: `${PACKAGE_ID}/fix`, description: "featureFixDescription" },
|
|
39
|
+
{ key: "lan-access", moduleName: `${PACKAGE_ID}/lan-access`, description: "featureLanAccessDescription" },
|
|
39
40
|
];
|
|
40
41
|
/** The same features keyed by the name a card shows. */
|
|
41
42
|
const FEATURE_BY_KEY = new Map(FEATURES.map((feature) => [feature.key, feature]));
|
|
@@ -52,6 +53,29 @@ window.__ModuleLoader__.load({
|
|
|
52
53
|
const NOTICE_STYLE = { margin: 0, color: "var(--dsw-alias-label-secondary, var(--dsw-alias-label-tertiary))", fontSize: "13px", lineHeight: "20px" };
|
|
53
54
|
const REASON_STYLE = { color: "var(--dsw-alias-label-tertiary)", fontSize: "12px", lineHeight: "18px", maxWidth: "220px" };
|
|
54
55
|
const BUTTON_STYLE = { border: "0.5px solid var(--dsw-alias-border-l3)", borderRadius: "6px", color: "var(--dsw-alias-label-primary)", font: "inherit", cursor: "pointer", background: "none", padding: "4px 10px" };
|
|
56
|
+
/** Sidebar-foot action: icon in the rail, icon + label in a wide column. */
|
|
57
|
+
const LAN_BUTTON_STYLE = { display: "inline-flex", alignItems: "center", justifyContent: "center", gap: "8px", height: "32px", padding: "0 8px", border: "none", borderRadius: "8px", background: "transparent", color: "var(--dsw-alias-label-secondary, var(--dsw-alias-label-tertiary))", font: "inherit", fontSize: "13px", cursor: "pointer", whiteSpace: "nowrap" };
|
|
58
|
+
const LAN_RAIL_STYLE = { width: "32px", padding: "0" };
|
|
59
|
+
/** Frame-wide click-catcher for the phone-link popup. */
|
|
60
|
+
const LAN_OVERLAY_STYLE = { position: "fixed", inset: "0", zIndex: 2147483000, display: "flex", alignItems: "center", justifyContent: "center", background: "rgba(0, 0, 0, 0.45)", pointerEvents: "auto" };
|
|
61
|
+
const LAN_DIALOG_STYLE = { width: "380px", maxWidth: "calc(100vw - 32px)", maxHeight: "calc(100vh - 48px)", overflow: "auto", display: "flex", flexDirection: "column", gap: "12px", padding: "16px", borderRadius: "12px", background: "var(--dsw-alias-bg-primary, #fff)", color: "var(--dsw-alias-label-primary)", boxShadow: "0 18px 48px rgba(0, 0, 0, 0.28)" };
|
|
62
|
+
const LAN_HEADER_STYLE = { display: "flex", alignItems: "center", justifyContent: "space-between", gap: "12px" };
|
|
63
|
+
const LAN_HINT_STYLE = { margin: 0, color: "var(--dsw-alias-label-tertiary)", fontSize: "13px", lineHeight: "20px" };
|
|
64
|
+
const LAN_FRAME_STYLE = { width: "100%", height: "360px", border: "none", borderRadius: "8px", background: "#fff", display: "block" };
|
|
65
|
+
/** The MCP dialog: same shell as the phone popup, one column of servers inside. */
|
|
66
|
+
const MCP_DIALOG_STYLE = { width: "880px", maxWidth: "calc(100vw - 32px)", maxHeight: "calc(100vh - 48px)", overflow: "auto", display: "flex", flexDirection: "column", gap: "14px", padding: "16px", borderRadius: "12px", background: "var(--dsw-alias-bg-primary, #fff)", color: "var(--dsw-alias-label-primary)", boxShadow: "0 18px 48px rgba(0, 0, 0, 0.28)" };
|
|
67
|
+
/** Two columns: global on the left, the workspace on the right. */
|
|
68
|
+
const MCP_COLUMNS_STYLE = { display: "flex", gap: "16px", alignItems: "flex-start" };
|
|
69
|
+
const MCP_COLUMN_STYLE = { display: "flex", flexDirection: "column", gap: "8px", flex: "1 1 0", minWidth: 0 };
|
|
70
|
+
const MCP_ACTIONS_STYLE = { display: "inline-flex", gap: "8px" };
|
|
71
|
+
const MCP_SECTION_STYLE = { display: "flex", flexDirection: "column", gap: "6px" };
|
|
72
|
+
const MCP_SERVER_STYLE = { display: "flex", flexDirection: "column", gap: "4px", padding: "8px 10px", border: "0.5px solid var(--dsw-alias-settings-card-stroke, var(--dsw-alias-border-l3))", borderRadius: "10px" };
|
|
73
|
+
const MCP_SERVER_HEADER = { display: "flex", alignItems: "center", gap: "10px" };
|
|
74
|
+
const MCP_TOOL_STYLE = { display: "flex", alignItems: "center", gap: "8px", fontSize: "13px", lineHeight: "20px" };
|
|
75
|
+
const MCP_TOOL_NAME_STYLE = { fontFamily: "ui-monospace, SFMono-Regular, Menlo, monospace", fontSize: "12px", color: "var(--dsw-alias-label-secondary, var(--dsw-alias-label-tertiary))" };
|
|
76
|
+
const MCP_FIELD_STYLE = { display: "flex", flexDirection: "column", gap: "2px" };
|
|
77
|
+
const MCP_INPUT_STYLE = { font: "inherit", fontSize: "13px", padding: "4px 6px", borderRadius: "6px", border: "0.5px solid var(--dsw-alias-border-l3)", background: "transparent", color: "var(--dsw-alias-label-primary)" };
|
|
78
|
+
const MCP_FORM_STYLE = { display: "flex", flexDirection: "column", gap: "8px", paddingTop: "8px", borderTop: "0.5px solid var(--dsw-alias-border-l3)" };
|
|
55
79
|
|
|
56
80
|
/**
|
|
57
81
|
* Copy for the management tab; the `locale/*.json` files carry the same entries, where the
|
|
@@ -79,6 +103,50 @@ window.__ModuleLoader__.load({
|
|
|
79
103
|
featurePonytailDescription: "ponytail 采纳提示与 /ponytail 等级切换",
|
|
80
104
|
featureInitDescription: "生成或更新项目 AGENTS.md(/init)",
|
|
81
105
|
featureFixDescription: "先查根因并报告,确认后再修复(/fix)",
|
|
106
|
+
featureLanAccessDescription: "让手机在同一局域网打开本 GUI(/lan 给出带 token 的地址)",
|
|
107
|
+
lanButton: "手机连接",
|
|
108
|
+
lanButtonAria: "用手机通过局域网连接:打开二维码",
|
|
109
|
+
lanTitle: "手机扫码连接",
|
|
110
|
+
lanClose: "关闭",
|
|
111
|
+
lanLoading: "正在开启局域网访问…",
|
|
112
|
+
lanHint: "手机与电脑连同一个网络,用相机扫码打开;打开一次后 30 天内免 token。",
|
|
113
|
+
lanRestart: "已开启局域网访问,但需要重启 DSH 后二维码才可用。",
|
|
114
|
+
lanFailed: "无法开启局域网访问:{error}",
|
|
115
|
+
lanNotInstalled: "这个 profile 里没有 lan-access 行。",
|
|
116
|
+
lanReadOnly: "无法在这个页面启用 lan-access 行({reason})。",
|
|
117
|
+
lanFrameFailed: "二维码页没有响应;请先打开 /lan-access 检查原因。",
|
|
118
|
+
mcpTitle: "MCP 服务器",
|
|
119
|
+
mcpClose: "关闭",
|
|
120
|
+
mcpLoading: "正在读取 MCP 状态…",
|
|
121
|
+
mcpFailed: "操作失败:{error}",
|
|
122
|
+
mcpGlobal: "全局 MCP",
|
|
123
|
+
mcpLocal: "当前工作区 MCP",
|
|
124
|
+
mcpNoGlobal: "没有全局 MCP 服务器。",
|
|
125
|
+
mcpNoLocal: "这个工作区没有 .mcp.json 服务器。",
|
|
126
|
+
mcpNoTools: "没有工具(未连接,或服务器没有工具)。",
|
|
127
|
+
mcpConnected: "已连接",
|
|
128
|
+
mcpNotConnected: "未连接",
|
|
129
|
+
mcpToolToggle: "开关 {name}",
|
|
130
|
+
mcpServerToggle: "开关服务器 {name}",
|
|
131
|
+
mcpPromote: "注册到全局",
|
|
132
|
+
mcpAddTitle: "新增 MCP 服务器",
|
|
133
|
+
mcpAddName: "名称",
|
|
134
|
+
mcpAddScope: "作用域",
|
|
135
|
+
mcpAddGlobal: "全局(所有会话)",
|
|
136
|
+
mcpAddWorkspace: "当前工作区",
|
|
137
|
+
mcpAddType: "类型",
|
|
138
|
+
mcpAddStdio: "stdio(启动命令)",
|
|
139
|
+
mcpAddHttp: "http(URL)",
|
|
140
|
+
mcpAddCommand: "命令",
|
|
141
|
+
mcpAddArgs: "参数(空格分隔)",
|
|
142
|
+
mcpAddUrl: "URL",
|
|
143
|
+
mcpAddSubmit: "添加",
|
|
144
|
+
mcpRefresh: "刷新",
|
|
145
|
+
mcpAdd: "添加 MCP",
|
|
146
|
+
mcpExpand: "{count} 个工具",
|
|
147
|
+
mcpCollapse: "收起",
|
|
148
|
+
mcpExpandAria: "展开 {name} 的工具",
|
|
149
|
+
mcpCollapseAria: "收起 {name} 的工具",
|
|
82
150
|
};
|
|
83
151
|
/** English dictionary checked against the Chinese key set. */
|
|
84
152
|
const en = {
|
|
@@ -102,6 +170,50 @@ window.__ModuleLoader__.load({
|
|
|
102
170
|
featurePonytailDescription: "ponytail adoption hint and /ponytail level switching",
|
|
103
171
|
featureInitDescription: "generates or updates the project's AGENTS.md (/init)",
|
|
104
172
|
featureFixDescription: "diagnoses the root cause and waits for confirmation before fixing (/fix)",
|
|
173
|
+
featureLanAccessDescription: "opens this GUI from a phone on the same network (/lan prints the tokenized URL)",
|
|
174
|
+
lanButton: "Phone link",
|
|
175
|
+
lanButtonAria: "Connect a phone over the LAN: show the QR code",
|
|
176
|
+
lanTitle: "Scan to connect a phone",
|
|
177
|
+
lanClose: "Close",
|
|
178
|
+
lanLoading: "Enabling LAN access…",
|
|
179
|
+
lanHint: "Keep the phone on the same network and scan with the camera; after one open the token is not needed for 30 days.",
|
|
180
|
+
lanRestart: "LAN access is enabled, but DSH must restart before the QR code is available.",
|
|
181
|
+
lanFailed: "Could not enable LAN access: {error}",
|
|
182
|
+
lanNotInstalled: "This profile has no lan-access row.",
|
|
183
|
+
lanReadOnly: "The lan-access row cannot be enabled from here ({reason}).",
|
|
184
|
+
lanFrameFailed: "The QR page did not answer; open /lan-access to see why.",
|
|
185
|
+
mcpTitle: "MCP servers",
|
|
186
|
+
mcpClose: "Close",
|
|
187
|
+
mcpLoading: "Reading MCP state…",
|
|
188
|
+
mcpFailed: "The operation failed: {error}",
|
|
189
|
+
mcpGlobal: "Global MCP",
|
|
190
|
+
mcpLocal: "Workspace MCP",
|
|
191
|
+
mcpNoGlobal: "No global MCP servers.",
|
|
192
|
+
mcpNoLocal: "This workspace declares no .mcp.json servers.",
|
|
193
|
+
mcpNoTools: "No tools (not connected, or the server exposes none).",
|
|
194
|
+
mcpConnected: "Connected",
|
|
195
|
+
mcpNotConnected: "Not connected",
|
|
196
|
+
mcpToolToggle: "Toggle {name}",
|
|
197
|
+
mcpServerToggle: "Toggle server {name}",
|
|
198
|
+
mcpPromote: "Register globally",
|
|
199
|
+
mcpAddTitle: "Add an MCP server",
|
|
200
|
+
mcpAddName: "Name",
|
|
201
|
+
mcpAddScope: "Scope",
|
|
202
|
+
mcpAddGlobal: "Global (every session)",
|
|
203
|
+
mcpAddWorkspace: "This workspace",
|
|
204
|
+
mcpAddType: "Type",
|
|
205
|
+
mcpAddStdio: "stdio (a command)",
|
|
206
|
+
mcpAddHttp: "http (a URL)",
|
|
207
|
+
mcpAddCommand: "Command",
|
|
208
|
+
mcpAddArgs: "Arguments (space separated)",
|
|
209
|
+
mcpAddUrl: "URL",
|
|
210
|
+
mcpAddSubmit: "Add",
|
|
211
|
+
mcpRefresh: "Refresh",
|
|
212
|
+
mcpAdd: "Add MCP",
|
|
213
|
+
mcpExpand: "{count} tools",
|
|
214
|
+
mcpCollapse: "Collapse",
|
|
215
|
+
mcpExpandAria: "Expand the tools of {name}",
|
|
216
|
+
mcpCollapseAria: "Collapse the tools of {name}",
|
|
105
217
|
};
|
|
106
218
|
|
|
107
219
|
/** Read one thrown value as text. */
|
|
@@ -324,14 +436,432 @@ window.__ModuleLoader__.load({
|
|
|
324
436
|
});
|
|
325
437
|
}
|
|
326
438
|
|
|
327
|
-
/** Host command whose run this browser half projects into the chat view. */
|
|
328
|
-
const MCP_COMMAND = "mcp";
|
|
329
439
|
/**
|
|
330
|
-
*
|
|
440
|
+
* Values apply() hands the two slot components. They live at module scope because the
|
|
441
|
+
* sidebar action and the overlay host are separate slot occupants with no shared props.
|
|
442
|
+
*/
|
|
443
|
+
const lanUi = {
|
|
444
|
+
store: null,
|
|
445
|
+
t: (key) => key,
|
|
446
|
+
ensureEnabled: async () => "enabled",
|
|
447
|
+
probe: async () => ({ ok: false, message: "" }),
|
|
448
|
+
};
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* Popup state shared by the sidebar action and its overlay host: the two live in
|
|
452
|
+
* different slots, so neither can own React state for the other.
|
|
453
|
+
* @returns a tiny external store.
|
|
454
|
+
*/
|
|
455
|
+
function createPopupStore() {
|
|
456
|
+
let open = false;
|
|
457
|
+
const listeners = new Set();
|
|
458
|
+
return {
|
|
459
|
+
get: () => open,
|
|
460
|
+
set(value) {
|
|
461
|
+
const next = value === true;
|
|
462
|
+
if (next === open) return;
|
|
463
|
+
open = next;
|
|
464
|
+
for (const listener of [...listeners]) listener();
|
|
465
|
+
},
|
|
466
|
+
listen(listener) {
|
|
467
|
+
listeners.add(listener);
|
|
468
|
+
return () => {
|
|
469
|
+
listeners.delete(listener);
|
|
470
|
+
};
|
|
471
|
+
},
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* Subscribe a component to the popup store.
|
|
477
|
+
* @param store - the shared store.
|
|
478
|
+
* @returns whether the popup is open.
|
|
479
|
+
*/
|
|
480
|
+
function usePopupOpen(store) {
|
|
481
|
+
const [open, setOpen] = React.useState(store.get());
|
|
482
|
+
React.useEffect(() => store.listen(() => setOpen(store.get())), []);
|
|
483
|
+
return open;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/** A phone outline for the sidebar action. */
|
|
487
|
+
function PhoneIcon() {
|
|
488
|
+
return jsx("svg", {
|
|
489
|
+
width: 16,
|
|
490
|
+
height: 16,
|
|
491
|
+
viewBox: "0 0 24 24",
|
|
492
|
+
fill: "none",
|
|
493
|
+
stroke: "currentColor",
|
|
494
|
+
strokeWidth: 1.8,
|
|
495
|
+
strokeLinecap: "round",
|
|
496
|
+
strokeLinejoin: "round",
|
|
497
|
+
"aria-hidden": "true",
|
|
498
|
+
children: [
|
|
499
|
+
jsx("rect", { x: 6, y: 2, width: 12, height: 20, rx: 3, key: "body" }),
|
|
500
|
+
jsx("path", { d: "M11 18h2", key: "home" }),
|
|
501
|
+
],
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* The sidebar-foot action that opens the phone-link popup.
|
|
507
|
+
* @param props - `store`, the bound `t`, and the owner's column width state.
|
|
508
|
+
*/
|
|
509
|
+
function LanAccessButton({ wide }) {
|
|
510
|
+
const { store, t } = lanUi;
|
|
511
|
+
const open = usePopupOpen(store);
|
|
512
|
+
return jsx("button", {
|
|
513
|
+
type: "button",
|
|
514
|
+
title: t("lanButton"),
|
|
515
|
+
"aria-label": t("lanButtonAria"),
|
|
516
|
+
"aria-expanded": open,
|
|
517
|
+
style: wide ? LAN_BUTTON_STYLE : { ...LAN_BUTTON_STYLE, ...LAN_RAIL_STYLE },
|
|
518
|
+
onClick: () => store.set(true),
|
|
519
|
+
children: [
|
|
520
|
+
jsx(PhoneIcon, { key: "icon" }),
|
|
521
|
+
wide ? jsx("span", {
|
|
522
|
+
key: "label",
|
|
523
|
+
children: t("lanButton")
|
|
524
|
+
}) : null
|
|
525
|
+
]
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* The frame-wide popup: enabling the row, waiting for the page, and showing the QR.
|
|
531
|
+
* @param props - `store`, the bound `t`, `ensureEnabled`, and `probe`.
|
|
532
|
+
*/
|
|
533
|
+
function LanAccessPopup() {
|
|
534
|
+
const { store, t, ensureEnabled, probe } = lanUi;
|
|
535
|
+
const open = usePopupOpen(store);
|
|
536
|
+
const [state, setState] = React.useState({ status: "idle" });
|
|
537
|
+
const [frameHeight, setFrameHeight] = React.useState(360);
|
|
538
|
+
React.useEffect(() => {
|
|
539
|
+
if (!open) return undefined;
|
|
540
|
+
let current = true;
|
|
541
|
+
setState({ status: "loading" });
|
|
542
|
+
Promise.resolve().then(ensureEnabled).then((outcome) => {
|
|
543
|
+
if (!current) return undefined;
|
|
544
|
+
if (outcome === "restart-required") {
|
|
545
|
+
setState({ status: "restart" });
|
|
546
|
+
return undefined;
|
|
547
|
+
}
|
|
548
|
+
return probe().then((answer) => {
|
|
549
|
+
if (!current) return;
|
|
550
|
+
setState(answer.ok ? { status: "ready", src: answer.url } : { status: "error", message: answer.message });
|
|
551
|
+
});
|
|
552
|
+
}).catch((error) => {
|
|
553
|
+
if (current) setState({ status: "error", message: messageOf(error) });
|
|
554
|
+
});
|
|
555
|
+
return () => {
|
|
556
|
+
current = false;
|
|
557
|
+
};
|
|
558
|
+
}, [open, ensureEnabled, probe]);
|
|
559
|
+
React.useEffect(() => {
|
|
560
|
+
if (!open) return undefined;
|
|
561
|
+
const onKey = (event) => {
|
|
562
|
+
if (event.key === "Escape") store.set(false);
|
|
563
|
+
};
|
|
564
|
+
globalThis.window?.addEventListener?.("keydown", onKey);
|
|
565
|
+
return () => globalThis.window?.removeEventListener?.("keydown", onKey);
|
|
566
|
+
}, [open, store]);
|
|
567
|
+
if (!open) return null;
|
|
568
|
+
return jsx("div", {
|
|
569
|
+
role: "presentation",
|
|
570
|
+
style: LAN_OVERLAY_STYLE,
|
|
571
|
+
onClick: () => store.set(false),
|
|
572
|
+
children: jsxs("div", {
|
|
573
|
+
role: "dialog",
|
|
574
|
+
"aria-modal": "true",
|
|
575
|
+
"aria-label": t("lanTitle"),
|
|
576
|
+
style: LAN_DIALOG_STYLE,
|
|
577
|
+
onClick: (event) => event.stopPropagation(),
|
|
578
|
+
children: [
|
|
579
|
+
jsxs("div", {
|
|
580
|
+
style: LAN_HEADER_STYLE,
|
|
581
|
+
children: [jsx("strong", { children: t("lanTitle") }), jsx("button", {
|
|
582
|
+
type: "button",
|
|
583
|
+
style: BUTTON_STYLE,
|
|
584
|
+
onClick: () => store.set(false),
|
|
585
|
+
children: t("lanClose")
|
|
586
|
+
})]
|
|
587
|
+
}),
|
|
588
|
+
state.status === "loading" ? jsx("p", { role: "status", style: LAN_HINT_STYLE, children: t("lanLoading") }) : null,
|
|
589
|
+
state.status === "restart" ? jsx("p", { role: "alert", style: LAN_HINT_STYLE, children: t("lanRestart") }) : null,
|
|
590
|
+
state.status === "error" ? jsx("p", { role: "alert", style: LAN_HINT_STYLE, children: t("lanFailed", { error: state.message }) }) : null,
|
|
591
|
+
state.status === "ready" ? jsx("iframe", {
|
|
592
|
+
title: t("lanTitle"),
|
|
593
|
+
src: state.src,
|
|
594
|
+
style: { ...LAN_FRAME_STYLE, height: `${String(frameHeight)}px` },
|
|
595
|
+
onLoad: (event) => {
|
|
596
|
+
// Same origin, so the document height is readable: the frame is cut
|
|
597
|
+
// to its content and the dialog never grows a second scrollbar.
|
|
598
|
+
try {
|
|
599
|
+
const measured = event?.currentTarget?.contentDocument?.documentElement?.scrollHeight;
|
|
600
|
+
if (typeof measured === "number" && measured > 0) setFrameHeight(Math.max(240, Math.min(measured + 2, 560)));
|
|
601
|
+
} catch {
|
|
602
|
+
// A cross-origin document keeps the default height.
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
}) : null,
|
|
606
|
+
jsx("p", { style: LAN_HINT_STYLE, children: t("lanHint") })
|
|
607
|
+
]
|
|
608
|
+
})
|
|
609
|
+
});
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
/** Values the `/mcp` dialog needs from apply(): its store, the bound lookup and the host call. */
|
|
613
|
+
const mcpUi = {
|
|
614
|
+
store: null,
|
|
615
|
+
t: (key) => key,
|
|
616
|
+
post: async () => ({}),
|
|
617
|
+
};
|
|
618
|
+
|
|
619
|
+
/**
|
|
620
|
+
* Dialog state shared by the decorator that opens it and the overlay that draws it.
|
|
621
|
+
* @returns a tiny external store holding the open dialog's session.
|
|
622
|
+
*/
|
|
623
|
+
function createDialogStore() {
|
|
624
|
+
let current = { open: false, sessionId: "" };
|
|
625
|
+
const listeners = new Set();
|
|
626
|
+
const set = (next) => {
|
|
627
|
+
if (next.open === current.open && next.sessionId === current.sessionId) return;
|
|
628
|
+
current = next;
|
|
629
|
+
for (const listener of [...listeners]) listener();
|
|
630
|
+
};
|
|
631
|
+
return {
|
|
632
|
+
get: () => current,
|
|
633
|
+
open(sessionId) {
|
|
634
|
+
set({ open: true, sessionId });
|
|
635
|
+
},
|
|
636
|
+
close() {
|
|
637
|
+
set({ open: false, sessionId: current.sessionId });
|
|
638
|
+
},
|
|
639
|
+
listen(listener) {
|
|
640
|
+
listeners.add(listener);
|
|
641
|
+
return () => {
|
|
642
|
+
listeners.delete(listener);
|
|
643
|
+
};
|
|
644
|
+
},
|
|
645
|
+
};
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
/** Subscribe a component to the dialog store. */
|
|
649
|
+
function useDialog(store) {
|
|
650
|
+
const [dialog, setDialog] = React.useState(store.get());
|
|
651
|
+
React.useEffect(() => store.listen(() => setDialog(store.get())), []);
|
|
652
|
+
return dialog;
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
/** The empty add-server form. */
|
|
656
|
+
function emptyForm() {
|
|
657
|
+
return { name: "", scope: "workspace", type: "stdio", command: "", args: "", url: "" };
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
/** One master switch, so both columns read the same. */
|
|
661
|
+
function switchControl(checked, label, onChange) {
|
|
662
|
+
return jsx("label", { style: SWITCH_STYLE, children: jsx("input", {
|
|
663
|
+
type: "checkbox",
|
|
664
|
+
checked,
|
|
665
|
+
"aria-label": label,
|
|
666
|
+
onChange: (event) => onChange(event.currentTarget.checked),
|
|
667
|
+
}) });
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
/**
|
|
671
|
+
* One server card: master switch, connection line, the expand toggle, and — when
|
|
672
|
+
* open — its tools. Collapsed is the default: a real MCP server exposes a dozen.
|
|
673
|
+
* @param server - one entry of the dialog view.
|
|
674
|
+
* @param side - "global" or "local".
|
|
675
|
+
* @param view - the dialog's bound lookups and actions.
|
|
676
|
+
* @returns the card element.
|
|
677
|
+
*/
|
|
678
|
+
function serverBlock(server, side, view) {
|
|
679
|
+
const { t, expanded, onExpand, onTool, onServer, onGlobalServer, onPromote } = view;
|
|
680
|
+
const key = `${side}:${server.name}`;
|
|
681
|
+
const open = expanded[key] === true;
|
|
682
|
+
const header = [jsx("strong", { key: "name", children: server.name })];
|
|
683
|
+
if (side === "local") {
|
|
684
|
+
header.push(switchControl(server.enabled, t("mcpServerToggle", { name: server.name }), (value) => onServer(server.name, value)));
|
|
685
|
+
header.push(jsx("button", {
|
|
686
|
+
key: "promote",
|
|
687
|
+
type: "button",
|
|
688
|
+
style: BUTTON_STYLE,
|
|
689
|
+
onClick: () => onPromote(server.name),
|
|
690
|
+
children: t("mcpPromote"),
|
|
691
|
+
}));
|
|
692
|
+
} else if (server.managed) {
|
|
693
|
+
header.push(switchControl(server.enabled, t("mcpServerToggle", { name: server.name }), (value) => onGlobalServer(server.name, value)));
|
|
694
|
+
}
|
|
695
|
+
header.push(jsx("span", { key: "status", style: DESCRIPTION_STYLE, children: server.tools.length === 0 ? t("mcpNotConnected") : t("mcpConnected") }));
|
|
696
|
+
header.push(jsx("button", {
|
|
697
|
+
key: "expand",
|
|
698
|
+
type: "button",
|
|
699
|
+
style: BUTTON_STYLE,
|
|
700
|
+
"aria-label": open ? t("mcpCollapseAria", { name: server.name }) : t("mcpExpandAria", { name: server.name }),
|
|
701
|
+
onClick: () => onExpand(key),
|
|
702
|
+
children: open ? t("mcpCollapse") : t("mcpExpand", { count: server.tools.length }),
|
|
703
|
+
}));
|
|
704
|
+
const tools = open && server.tools.length > 0
|
|
705
|
+
? [jsx("ul", { key: "tools", style: LIST_STYLE, children: server.tools.map((tool) => jsxs("li", {
|
|
706
|
+
style: MCP_TOOL_STYLE,
|
|
707
|
+
children: [
|
|
708
|
+
side === "global" ? jsx("input", {
|
|
709
|
+
type: "checkbox",
|
|
710
|
+
checked: tool.enabled,
|
|
711
|
+
"aria-label": t("mcpToolToggle", { name: tool.name }),
|
|
712
|
+
onChange: (event) => onTool(tool.name, event.currentTarget.checked),
|
|
713
|
+
}) : null,
|
|
714
|
+
jsx("code", { style: MCP_TOOL_NAME_STYLE, children: tool.name }),
|
|
715
|
+
],
|
|
716
|
+
}, tool.name)) })]
|
|
717
|
+
: [];
|
|
718
|
+
return jsxs("li", { style: MCP_SERVER_STYLE, children: [jsx("div", { style: MCP_SERVER_HEADER, children: header }), ...tools] }, server.name);
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
/** The `/mcp` dialog: two columns, collapsed servers, and the add form behind a button. */
|
|
722
|
+
function McpDialog() {
|
|
723
|
+
const { store, t, post } = mcpUi;
|
|
724
|
+
const dialog = useDialog(store);
|
|
725
|
+
const [state, setState] = React.useState({ kind: "idle" });
|
|
726
|
+
const [notice, setNotice] = React.useState(null);
|
|
727
|
+
const [expanded, setExpanded] = React.useState({});
|
|
728
|
+
const [formOpen, setFormOpen] = React.useState(false);
|
|
729
|
+
const [form, setForm] = React.useState(emptyForm());
|
|
730
|
+
React.useEffect(() => {
|
|
731
|
+
if (!dialog.open) return undefined;
|
|
732
|
+
let current = true;
|
|
733
|
+
setState({ kind: "loading" });
|
|
734
|
+
Promise.resolve().then(() => post({ action: "status", sessionId: dialog.sessionId })).then((value) => {
|
|
735
|
+
if (current) setState({ kind: "ready", view: value });
|
|
736
|
+
}, (error) => {
|
|
737
|
+
if (current) setState({ kind: "error", message: messageOf(error) });
|
|
738
|
+
});
|
|
739
|
+
return () => {
|
|
740
|
+
current = false;
|
|
741
|
+
};
|
|
742
|
+
}, [dialog.open, dialog.sessionId]);
|
|
743
|
+
React.useEffect(() => {
|
|
744
|
+
if (!dialog.open) return undefined;
|
|
745
|
+
const onKey = (event) => {
|
|
746
|
+
if (event.key === "Escape") store.close();
|
|
747
|
+
};
|
|
748
|
+
globalThis.window?.addEventListener?.("keydown", onKey);
|
|
749
|
+
return () => globalThis.window?.removeEventListener?.("keydown", onKey);
|
|
750
|
+
}, [dialog.open, store]);
|
|
751
|
+
if (!dialog.open) return null;
|
|
752
|
+
/** Run one request and re-render from the answer; resolves to whether it worked. */
|
|
753
|
+
const run = (body) => {
|
|
754
|
+
setNotice(null);
|
|
755
|
+
return Promise.resolve().then(() => post({ ...body, sessionId: dialog.sessionId })).then((value) => {
|
|
756
|
+
setState({ kind: "ready", view: value });
|
|
757
|
+
return true;
|
|
758
|
+
}, (error) => {
|
|
759
|
+
setNotice(messageOf(error));
|
|
760
|
+
return false;
|
|
761
|
+
});
|
|
762
|
+
};
|
|
763
|
+
const handlers = {
|
|
764
|
+
t,
|
|
765
|
+
expanded,
|
|
766
|
+
onExpand: (key) => setExpanded((old) => ({ ...old, [key]: old[key] !== true })),
|
|
767
|
+
onTool: (tool, enabled) => run({ action: "set-tool", tool, enabled }),
|
|
768
|
+
onServer: (server, enabled) => run({ action: "set-server", server, enabled }),
|
|
769
|
+
onGlobalServer: (server, enabled) => run({ action: "set-global-server", server, enabled }),
|
|
770
|
+
onPromote: (server) => run({ action: "promote", server }),
|
|
771
|
+
};
|
|
772
|
+
const field = (label, key, placeholder) => jsxs("label", { style: MCP_FIELD_STYLE, children: [
|
|
773
|
+
jsx("span", { style: DESCRIPTION_STYLE, children: label }),
|
|
774
|
+
jsx("input", {
|
|
775
|
+
type: "text",
|
|
776
|
+
value: form[key],
|
|
777
|
+
placeholder,
|
|
778
|
+
style: MCP_INPUT_STYLE,
|
|
779
|
+
onChange: (event) => {
|
|
780
|
+
const value = event.currentTarget.value;
|
|
781
|
+
setForm((old) => ({ ...old, [key]: value }));
|
|
782
|
+
},
|
|
783
|
+
}),
|
|
784
|
+
] });
|
|
785
|
+
const view = state.kind === "ready" ? state.view : undefined;
|
|
786
|
+
const submit = () => {
|
|
787
|
+
run({
|
|
788
|
+
action: "add-server",
|
|
789
|
+
server: { name: form.name, scope: form.scope, type: form.type, command: form.command, args: form.args, url: form.url },
|
|
790
|
+
}).then((accepted) => {
|
|
791
|
+
if (accepted) {
|
|
792
|
+
setForm(emptyForm());
|
|
793
|
+
setFormOpen(false);
|
|
794
|
+
}
|
|
795
|
+
});
|
|
796
|
+
};
|
|
797
|
+
const column = (side, title, empty, entries) => jsxs("section", { style: MCP_COLUMN_STYLE, children: [
|
|
798
|
+
jsx("strong", { children: title }),
|
|
799
|
+
entries.length === 0 ? jsx("p", { style: DESCRIPTION_STYLE, children: empty }) : jsx("ul", { style: LIST_STYLE, children: entries.map((server) => serverBlock(server, side, handlers)) }),
|
|
800
|
+
] });
|
|
801
|
+
return jsx("div", {
|
|
802
|
+
role: "presentation",
|
|
803
|
+
style: LAN_OVERLAY_STYLE,
|
|
804
|
+
onClick: () => store.close(),
|
|
805
|
+
children: jsxs("div", {
|
|
806
|
+
role: "dialog",
|
|
807
|
+
"aria-modal": "true",
|
|
808
|
+
"aria-label": t("mcpTitle"),
|
|
809
|
+
style: MCP_DIALOG_STYLE,
|
|
810
|
+
onClick: (event) => event.stopPropagation(),
|
|
811
|
+
children: [
|
|
812
|
+
jsxs("div", { style: LAN_HEADER_STYLE, children: [
|
|
813
|
+
jsx("strong", { children: t("mcpTitle") }),
|
|
814
|
+
jsxs("span", { style: MCP_ACTIONS_STYLE, children: [
|
|
815
|
+
jsx("button", { type: "button", style: BUTTON_STYLE, "aria-label": t("mcpRefresh"), onClick: () => run({ action: "status" }), children: t("mcpRefresh") }),
|
|
816
|
+
jsx("button", { type: "button", style: BUTTON_STYLE, onClick: () => store.close(), children: t("mcpClose") }),
|
|
817
|
+
] }),
|
|
818
|
+
] }),
|
|
819
|
+
state.kind === "loading" ? jsx("p", { role: "status", style: DESCRIPTION_STYLE, children: t("mcpLoading") }) : null,
|
|
820
|
+
state.kind === "error" ? jsx("p", { role: "alert", style: DESCRIPTION_STYLE, children: t("mcpFailed", { error: state.message }) }) : null,
|
|
821
|
+
view !== undefined && view.workspaceError !== undefined ? jsx("p", { role: "alert", style: DESCRIPTION_STYLE, children: t("mcpFailed", { error: view.workspaceError }) }) : null,
|
|
822
|
+
view === undefined ? null : jsxs("div", { style: MCP_COLUMNS_STYLE, children: [
|
|
823
|
+
column("global", t("mcpGlobal"), t("mcpNoGlobal"), view.global),
|
|
824
|
+
jsxs("section", { style: MCP_COLUMN_STYLE, children: [
|
|
825
|
+
jsx("strong", { children: t("mcpLocal") }),
|
|
826
|
+
view.local.length === 0 ? jsx("p", { style: DESCRIPTION_STYLE, children: t("mcpNoLocal") }) : jsx("ul", { style: LIST_STYLE, children: view.local.map((server) => serverBlock(server, "local", handlers)) }),
|
|
827
|
+
jsx("button", { type: "button", style: BUTTON_STYLE, "aria-label": t("mcpAdd"), onClick: () => setFormOpen((old) => !old), children: t("mcpAdd") }),
|
|
828
|
+
formOpen ? jsxs("div", { style: MCP_FORM_STYLE, children: [
|
|
829
|
+
field(t("mcpAddName"), "name", "my-server"),
|
|
830
|
+
jsxs("label", { style: MCP_FIELD_STYLE, children: [
|
|
831
|
+
jsx("span", { style: DESCRIPTION_STYLE, children: t("mcpAddScope") }),
|
|
832
|
+
jsxs("select", { value: form.scope, style: MCP_INPUT_STYLE, onChange: (event) => { const value = event.currentTarget.value; setForm((old) => ({ ...old, scope: value })); }, children: [
|
|
833
|
+
jsx("option", { value: "workspace", children: t("mcpAddWorkspace") }),
|
|
834
|
+
jsx("option", { value: "global", children: t("mcpAddGlobal") }),
|
|
835
|
+
] }),
|
|
836
|
+
] }),
|
|
837
|
+
jsxs("label", { style: MCP_FIELD_STYLE, children: [
|
|
838
|
+
jsx("span", { style: DESCRIPTION_STYLE, children: t("mcpAddType") }),
|
|
839
|
+
jsxs("select", { value: form.type, style: MCP_INPUT_STYLE, onChange: (event) => { const value = event.currentTarget.value; setForm((old) => ({ ...old, type: value })); }, children: [
|
|
840
|
+
jsx("option", { value: "stdio", children: t("mcpAddStdio") }),
|
|
841
|
+
jsx("option", { value: "http", children: t("mcpAddHttp") }),
|
|
842
|
+
] }),
|
|
843
|
+
] }),
|
|
844
|
+
form.type === "http" ? field(t("mcpAddUrl"), "url", "https://example.com/mcp") : null,
|
|
845
|
+
form.type === "http" ? null : field(t("mcpAddCommand"), "command", "npx"),
|
|
846
|
+
form.type === "http" ? null : field(t("mcpAddArgs"), "args", "-y @modelcontextprotocol/server-filesystem ."),
|
|
847
|
+
jsx("button", { type: "button", style: BUTTON_STYLE, onClick: submit, children: t("mcpAddSubmit") }),
|
|
848
|
+
] }) : null,
|
|
849
|
+
] }),
|
|
850
|
+
] }),
|
|
851
|
+
notice === null ? null : jsx("p", { role: "alert", style: DESCRIPTION_STYLE, children: t("mcpFailed", { error: notice }) }),
|
|
852
|
+
],
|
|
853
|
+
}),
|
|
854
|
+
});
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
/** Host commands whose run this browser half projects into the chat view. */
|
|
858
|
+
const PROJECTED_COMMANDS = new Set(["mcp", "lan"]);
|
|
859
|
+
/**
|
|
860
|
+
* Chat node kind of the `/mcp` and `/lan` projection.
|
|
331
861
|
*
|
|
332
862
|
* DSH hides the whole transcript while a session has no turn (the chat view counts only
|
|
333
863
|
* non-command nodes as activity, and only a turn clears the session's blank flag), so in a
|
|
334
|
-
* never-messaged session the
|
|
864
|
+
* never-messaged session the report — logged as `command/run` + `command/done` — would
|
|
335
865
|
* stay invisible until the first message starts a turn. Registering this non-command node is
|
|
336
866
|
* how DSH's own `ui-goal` keeps `/goal` visible; the report itself stays in the generic
|
|
337
867
|
* command card, which is why the renderer below draws nothing.
|
|
@@ -339,14 +869,14 @@ window.__ModuleLoader__.load({
|
|
|
339
869
|
const MCP_NODE_KIND = "hiss-mcp-command";
|
|
340
870
|
|
|
341
871
|
/**
|
|
342
|
-
* Project one `/mcp` run as an empty chat node.
|
|
872
|
+
* Project one `/mcp` or `/lan` run as an empty chat node.
|
|
343
873
|
* Only `command/run` is claimed: `command/done` still renders through the generic command card,
|
|
344
874
|
* and every other command is untouched.
|
|
345
875
|
*/
|
|
346
876
|
const mcpCommandDefinition = {
|
|
347
877
|
kind: MCP_NODE_KIND,
|
|
348
878
|
target: "chat",
|
|
349
|
-
match: (event) => event.type === "command/run" && event.data.name
|
|
879
|
+
match: (event) => event.type === "command/run" && PROJECTED_COMMANDS.has(event.data.name)
|
|
350
880
|
? { id: String(event.data.commandId), role: "start" }
|
|
351
881
|
: null,
|
|
352
882
|
start: (_context, match) => ({ seq: match.event.seq, commandId: match.event.data.commandId }),
|
|
@@ -414,6 +944,37 @@ window.__ModuleLoader__.load({
|
|
|
414
944
|
if (result.application === "failed") throw refusalError(t, result.error?.code, result.error?.diagnostic);
|
|
415
945
|
return result.application;
|
|
416
946
|
};
|
|
947
|
+
lanUi.store = createPopupStore();
|
|
948
|
+
/**
|
|
949
|
+
* Turn the lan-access row on so the popup has something to show.
|
|
950
|
+
* @returns "enabled" when the listener is being mounted now, "restart-required" when only a restart lands it.
|
|
951
|
+
*/
|
|
952
|
+
const ensureLanEnabled = async () => {
|
|
953
|
+
const rows = await list();
|
|
954
|
+
const row = rows.find((candidate) => candidate.key === "lan-access");
|
|
955
|
+
if (row === undefined) throw new Error(t("lanNotInstalled"));
|
|
956
|
+
if (row.enabled) return "enabled";
|
|
957
|
+
if (!row.toggleable) throw new Error(t("lanReadOnly", { reason: row.reason ?? "unknown" }));
|
|
958
|
+
return (await setEnabled(row.entryId, true)) === "restart-required" ? "restart-required" : "enabled";
|
|
959
|
+
};
|
|
960
|
+
/**
|
|
961
|
+
* Wait for the host's QR page: a just-enabled row registers its route asynchronously.
|
|
962
|
+
* @returns whether the page answers, and the frame URL.
|
|
963
|
+
*/
|
|
964
|
+
const probeLanPage = async () => {
|
|
965
|
+
const url = "/lan-access?embed=1";
|
|
966
|
+
for (let attempt = 0; attempt < 12; attempt += 1) {
|
|
967
|
+
try {
|
|
968
|
+
const response = await fetch(url, { method: "HEAD", cache: "no-store" });
|
|
969
|
+
if (response.ok) return { ok: true, url };
|
|
970
|
+
if (response.status === 401 || response.status === 403) break;
|
|
971
|
+
} catch {
|
|
972
|
+
// The route does not exist yet (404) or the browser is briefly offline.
|
|
973
|
+
}
|
|
974
|
+
await new Promise((resolve) => setTimeout(resolve, 250));
|
|
975
|
+
}
|
|
976
|
+
return { ok: false, message: t("lanFrameFailed", { url: "/lan-access" }) };
|
|
977
|
+
};
|
|
417
978
|
ctx.slots.inject("plugins.tab", () => ctx.slots.register({
|
|
418
979
|
name: "plugins.tab",
|
|
419
980
|
id: "dsh-hiss-plugins",
|
|
@@ -427,10 +988,71 @@ window.__ModuleLoader__.load({
|
|
|
427
988
|
features: FEATURES.map((feature) => feature.key)
|
|
428
989
|
})
|
|
429
990
|
}, HissPluginsTab));
|
|
991
|
+
lanUi.t = t;
|
|
992
|
+
lanUi.ensureEnabled = ensureLanEnabled;
|
|
993
|
+
lanUi.probe = probeLanPage;
|
|
994
|
+
mcpUi.store = createDialogStore();
|
|
995
|
+
mcpUi.t = t;
|
|
996
|
+
/**
|
|
997
|
+
* Call the host's dialog route: same origin, one JSON answer, failures as text.
|
|
998
|
+
* @param body - the request without its session id.
|
|
999
|
+
* @returns the answer's `value`.
|
|
1000
|
+
*/
|
|
1001
|
+
mcpUi.post = async (body) => {
|
|
1002
|
+
const response = await fetch("/hiss-mcp/action", {
|
|
1003
|
+
method: "POST",
|
|
1004
|
+
headers: { "content-type": "application/json" },
|
|
1005
|
+
body: JSON.stringify(body),
|
|
1006
|
+
});
|
|
1007
|
+
let answer = null;
|
|
1008
|
+
try {
|
|
1009
|
+
answer = await response.json();
|
|
1010
|
+
} catch {
|
|
1011
|
+
answer = null;
|
|
1012
|
+
}
|
|
1013
|
+
if (answer !== null && answer.ok === false) throw new Error(answer.error?.message ?? "the host refused the request");
|
|
1014
|
+
if (!response.ok) throw new Error(answer?.error?.message ?? `HTTP ${String(response.status)}`);
|
|
1015
|
+
return answer?.value;
|
|
1016
|
+
};
|
|
1017
|
+
// The dialog replaces the chat text report a bare /mcp used to log; an argued
|
|
1018
|
+
// /mcp still reaches the host command, which answers with its usage line.
|
|
1019
|
+
// Optional: a host without the command surface keeps the tab and the phone popup.
|
|
1020
|
+
if (typeof ctx.inject === "function") ctx.inject(["commandUi"], (uiCtx) => uiCtx.commandUi.decorate({
|
|
1021
|
+
name: "mcp",
|
|
1022
|
+
available: () => true,
|
|
1023
|
+
ui: {
|
|
1024
|
+
kind: "action",
|
|
1025
|
+
run: (session) => {
|
|
1026
|
+
mcpUi.store.open(session.sessionId);
|
|
1027
|
+
},
|
|
1028
|
+
},
|
|
1029
|
+
}));
|
|
1030
|
+
ctx.slots.inject("sidebar.footer.action", () => ctx.slots.register({
|
|
1031
|
+
name: "sidebar.footer.action",
|
|
1032
|
+
id: "lan-access",
|
|
1033
|
+
order: 10,
|
|
1034
|
+
locale: NS,
|
|
1035
|
+
label: () => t("lanButton"),
|
|
1036
|
+
}, LanAccessButton));
|
|
1037
|
+
ctx.slots.inject("shell.overlay", () => {
|
|
1038
|
+
const popup = ctx.slots.register({
|
|
1039
|
+
name: "shell.overlay",
|
|
1040
|
+
id: "lan-access.popup",
|
|
1041
|
+
order: 900,
|
|
1042
|
+
locale: NS,
|
|
1043
|
+
}, LanAccessPopup);
|
|
1044
|
+
ctx.slots.register({
|
|
1045
|
+
name: "shell.overlay",
|
|
1046
|
+
id: "mcp.dialog",
|
|
1047
|
+
order: 901,
|
|
1048
|
+
locale: NS,
|
|
1049
|
+
}, McpDialog);
|
|
1050
|
+
return popup;
|
|
1051
|
+
});
|
|
430
1052
|
}
|
|
431
1053
|
|
|
432
1054
|
exports.apply = apply;
|
|
433
1055
|
exports.inject = inject;
|
|
434
1056
|
return module.exports;
|
|
435
1057
|
},
|
|
436
|
-
});
|
|
1058
|
+
});
|