dsh-dock 0.23.0 → 0.24.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 +33 -41
- package/client.js +610 -236
- package/features/animation/host.js +3 -2
- package/features/balance/host.js +3 -3
- package/features/dshtools/host.js +306 -0
- package/features/dshtools/view.jsx +403 -0
- package/features/mcpconfig/host.js +3 -3
- package/features/mcpconfig/view.js +8 -8
- package/features/mobile-relay/host.js +42 -9
- package/features/modelconfig/host.js +3 -3
- package/features/notify/host.js +3 -2
- package/features/notify/view.jsx +51 -46
- package/features/providerconfig/host.js +3 -3
- package/features/runstate/host.js +3 -2
- package/features/tokenlog/host.js +3 -2
- package/features/tts/host.js +3 -2
- package/index.js +5 -2
- package/package.json +5 -6
- package/src/client.jsx +5 -2
- package/src/host-core.js +52 -13
- package/src/task-track.js +16 -6
- package/screenshots/dock-animation.png +0 -0
- package/screenshots/dock-balance.png +0 -0
- package/screenshots/dock-games.png +0 -0
- package/screenshots/dock-home.png +0 -0
- package/screenshots/dock-modelconfig-provider-create.png +0 -0
- package/screenshots/dock-modelconfig-provider-edit.png +0 -0
- package/screenshots/dock-modelconfig-providers.png +0 -0
- package/screenshots/dock-modelconfig.png +0 -0
- package/screenshots/dock-notify.png +0 -0
- package/screenshots/dock-runstate.png +0 -0
- package/screenshots/dock-settings.png +0 -0
- package/screenshots/dock-tokenlog-charts-2.png +0 -0
- package/screenshots/dock-tokenlog-charts-3.png +0 -0
- package/screenshots/dock-tokenlog-charts.png +0 -0
- package/screenshots/dock-tokenlog.png +0 -0
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
// dsh-dock · 功能模块【DSH功能】· 客户端视图
|
|
2
|
+
//
|
|
3
|
+
// 给 DSH 自带界面补充能力的开关页:分组(例如「文件右键」)× 勾选项。
|
|
4
|
+
// 勾选状态存在宿主设置里(features/dshtools/host.js 的 /dsh-dock/dshtools),
|
|
5
|
+
// 跨浏览器/跨设备一致;面板页只负责渲染清单与提交单项切换。
|
|
6
|
+
//
|
|
7
|
+
// 新增能力不需要改这里:宿主清单里加一项,页面就多一个勾选框;
|
|
8
|
+
// 行为侧按分组/键名自行接线(见 installClient 里的「文件右键 → 大文件下载」示例)。
|
|
9
|
+
//
|
|
10
|
+
// 约束(与其它模块一致):
|
|
11
|
+
// 1. fetch 用文档相对路径 "dsh-dock/dshtools"(子路径反代 /ui/ 下自动带前缀);
|
|
12
|
+
// 2. 不引用宿主全局对象,测试可在 node:vm 里跑构建产物;
|
|
13
|
+
// 3. 宿主不支持该路由(旧版本)时页面给出提示,右键菜单也绝不出现新条目。
|
|
14
|
+
import react from "react";
|
|
15
|
+
import { stateOf } from "../../src/shared.js";
|
|
16
|
+
|
|
17
|
+
const ENDPOINT = "dsh-dock/dshtools";
|
|
18
|
+
/** 内置「下载」Remote 的整文件默认上限:超过它的文件才需要本功能的流式下载。 */
|
|
19
|
+
export const LARGE_FILE_BYTES = 32 * 1024 * 1024;
|
|
20
|
+
|
|
21
|
+
// ---------- 配置 Store(面板页与右键菜单共用;变更即通知) ----------
|
|
22
|
+
const store = {
|
|
23
|
+
/** 宿主 /dsh-dock/dshtools 是否已成功读过一次:没读过就绝不接管菜单。 */
|
|
24
|
+
ready: false,
|
|
25
|
+
error: "",
|
|
26
|
+
groups: [],
|
|
27
|
+
listeners: new Set(),
|
|
28
|
+
loading: null,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
function notify() {
|
|
32
|
+
for (const fn of store.listeners) {
|
|
33
|
+
try { fn(); } catch (e) { console.error("[dsh-dock] DSH功能订阅者出错:", e); }
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** 订阅配置变化;返回退订函数。 */
|
|
38
|
+
export function subscribe(fn) {
|
|
39
|
+
store.listeners.add(fn);
|
|
40
|
+
return () => { store.listeners.delete(fn); };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** 用宿主返回的清单覆盖本地状态;形状不对时保持原状并记错误。 */
|
|
44
|
+
function applyPayload(data) {
|
|
45
|
+
const groups = data && data.ok === true && Array.isArray(data.groups) ? data.groups : null;
|
|
46
|
+
if (!groups) {
|
|
47
|
+
store.error = (data && data.error) || "宿主返回的配置格式不正确";
|
|
48
|
+
notify();
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
store.groups = groups;
|
|
52
|
+
store.error = "";
|
|
53
|
+
store.ready = true;
|
|
54
|
+
notify();
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** 读一次配置(并发调用共用一个请求;失败后可重试)。 */
|
|
59
|
+
export function ensureLoaded() {
|
|
60
|
+
if (store.ready) return Promise.resolve(true);
|
|
61
|
+
if (store.loading) return store.loading;
|
|
62
|
+
if (typeof fetch !== "function") {
|
|
63
|
+
store.error = "当前环境不支持 fetch";
|
|
64
|
+
notify();
|
|
65
|
+
return Promise.resolve(false);
|
|
66
|
+
}
|
|
67
|
+
store.loading = fetch(ENDPOINT, { headers: { accept: "application/json" } })
|
|
68
|
+
.then(async (res) => {
|
|
69
|
+
if (!res.ok) throw new Error("HTTP " + res.status);
|
|
70
|
+
return res.json();
|
|
71
|
+
})
|
|
72
|
+
.then((data) => applyPayload(data))
|
|
73
|
+
.catch(() => {
|
|
74
|
+
// 宿主旧版本(无此路由)/未启用:页面提示,菜单不出现;下次打开可重试。
|
|
75
|
+
store.error = "宿主没有「DSH功能」接口:宿主进程可能是旧版本,或该功能在宿主侧未启用(重启 dsh web,或在功能坞里关掉再打开本功能)";
|
|
76
|
+
notify();
|
|
77
|
+
return false;
|
|
78
|
+
})
|
|
79
|
+
.finally(() => { store.loading = null; });
|
|
80
|
+
return store.loading;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** 某项当前勾选值;不存在返回 undefined。 */
|
|
84
|
+
export function valueOf(groupId, key) {
|
|
85
|
+
const group = store.groups.find((g) => g.id === groupId);
|
|
86
|
+
const item = group && Array.isArray(group.items) ? group.items.find((i) => i.key === key) : undefined;
|
|
87
|
+
return item ? item.value === true : undefined;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** 切换单项:提交宿主并同步本地(失败时抛错,由调用方展示)。 */
|
|
91
|
+
export async function setValue(groupId, key, value) {
|
|
92
|
+
const res = await fetch(ENDPOINT, {
|
|
93
|
+
method: "POST",
|
|
94
|
+
headers: { "content-type": "application/json" },
|
|
95
|
+
body: JSON.stringify({ group: groupId, key, value: value === true }),
|
|
96
|
+
});
|
|
97
|
+
const data = await res.json().catch(() => null);
|
|
98
|
+
if (!res.ok || !data || data.ok !== true) {
|
|
99
|
+
throw new Error((data && data.error) || ("HTTP " + res.status));
|
|
100
|
+
}
|
|
101
|
+
applyPayload(data);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// ---------- 「文件右键」接线:大文件流式下载 ----------
|
|
105
|
+
/** 从 DSH 的原始文件 URL(/api/file?path=…)里取绝对路径;不是该形态返回 undefined。 */
|
|
106
|
+
function filePathOf(url) {
|
|
107
|
+
if (typeof url !== "string" || url.length === 0) return undefined;
|
|
108
|
+
let parsed;
|
|
109
|
+
try {
|
|
110
|
+
parsed = new URL(url, document.baseURI);
|
|
111
|
+
} catch (e) {
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
if (typeof location !== "undefined" && parsed.origin !== location.origin) return undefined;
|
|
115
|
+
if (!/\/api\/file$/.test(parsed.pathname)) return undefined;
|
|
116
|
+
const path = parsed.searchParams.get("path");
|
|
117
|
+
return path && path.length > 0 ? path : undefined;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* 探测宿主下载路由是否可用(HEAD 204)。只有探测通过才接管 DSH 自带「下载」,
|
|
122
|
+
* 否则保持原行为——宿主旧版本 / 功能在宿主侧未启用时绝不改变现有下载。
|
|
123
|
+
*/
|
|
124
|
+
let routeReady = false;
|
|
125
|
+
let routeProbe = null;
|
|
126
|
+
function ensureRoute() {
|
|
127
|
+
if (routeReady) return Promise.resolve(true);
|
|
128
|
+
if (routeProbe) return routeProbe;
|
|
129
|
+
if (typeof fetch !== "function") return Promise.resolve(false);
|
|
130
|
+
routeProbe = fetch("dsh-dock/download?probe=1", { method: "HEAD", cache: "no-store" })
|
|
131
|
+
.then((res) => { routeReady = res.status === 204 || res.ok === true; return routeReady; })
|
|
132
|
+
.catch(() => false)
|
|
133
|
+
.finally(() => { routeProbe = null; });
|
|
134
|
+
return routeProbe;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** 当前是否接管 DSH 自带的「下载」:功能启用 + 勾选开启 + 宿主下载路由探测通过。 */
|
|
138
|
+
function shouldTakeover() {
|
|
139
|
+
const state = stateOf("dshtools");
|
|
140
|
+
if (!state || state.enabled !== true) return false;
|
|
141
|
+
if (valueOf("fileContextMenu", "streamingDownload") === false) return false;
|
|
142
|
+
if (!routeReady) { void ensureRoute(); return false; }
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* 接管 DSH 自带的「下载」:Web 端下载文件时不再走 workspaceFiles.readBytes 整文件读取
|
|
148
|
+
* (默认 32 MiB 上限,超了只弹「无法保存文件」),改为跳转本模块的流式下载路由。
|
|
149
|
+
* 只替换实例上的 save 方法,其余情况(Desktop、图片、非 /api/file 来源)原样回调。
|
|
150
|
+
* @param {object} actions ui-file-actions 提供的 fileActions 服务实例
|
|
151
|
+
*/
|
|
152
|
+
function installDownloadTakeover(actions) {
|
|
153
|
+
if (!actions || typeof actions.save !== "function" || actions.__dshDockStreamingDownload === true) return;
|
|
154
|
+
const original = actions.save;
|
|
155
|
+
const wrapped = async function (source, mode) {
|
|
156
|
+
if (mode === "download" && actions.canSaveAs !== true && shouldTakeover()) {
|
|
157
|
+
const path = filePathOf(source && source.url);
|
|
158
|
+
if (path !== undefined) {
|
|
159
|
+
try {
|
|
160
|
+
startDownload(path);
|
|
161
|
+
return { status: "requested" };
|
|
162
|
+
} catch (e) {
|
|
163
|
+
// 落回原下载路径(例如 document 不可用)
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return original.call(actions, source, mode);
|
|
168
|
+
};
|
|
169
|
+
wrapped.__original = original;
|
|
170
|
+
try {
|
|
171
|
+
actions.save = wrapped;
|
|
172
|
+
actions.__dshDockStreamingDownload = true;
|
|
173
|
+
} catch (e) {
|
|
174
|
+
// 服务对象只读:保持 DSH 原行为
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// ---------- 「文件右键」接线的第一步:大文件下载 ----------
|
|
179
|
+
/**
|
|
180
|
+
* 触发浏览器原生下载:URL 走文档相对路径(反代前缀由 base 带入),
|
|
181
|
+
* 响应带 Content-Disposition: attachment,所以只下载、不跳页。
|
|
182
|
+
* @param {string} absolutePath 文件绝对路径
|
|
183
|
+
*/
|
|
184
|
+
function startDownload(absolutePath) {
|
|
185
|
+
if (typeof document === "undefined" || !document.body) return;
|
|
186
|
+
const base = document.baseURI || (typeof location !== "undefined" ? location.href : "http://localhost/");
|
|
187
|
+
const url = new URL("dsh-dock/download?path=" + encodeURIComponent(absolutePath), base);
|
|
188
|
+
const anchor = document.createElement("a");
|
|
189
|
+
anchor.href = url.href;
|
|
190
|
+
anchor.download = "";
|
|
191
|
+
anchor.rel = "noopener";
|
|
192
|
+
document.body.append(anchor);
|
|
193
|
+
anchor.click();
|
|
194
|
+
anchor.remove();
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** 右键「文件」时按文件大小决定是否追加「下载(大文件)」。 */
|
|
198
|
+
async function resolveFileMenu(remote, target, signal) {
|
|
199
|
+
const state = stateOf("dshtools");
|
|
200
|
+
if (!state || state.enabled !== true) return [];
|
|
201
|
+
// 首屏配置没取到(宿主刚重启 / 请求失败)时补一次:本次不出现,下次右键就有。
|
|
202
|
+
if (!store.ready) { void ensureLoaded(); return []; }
|
|
203
|
+
if (valueOf("fileContextMenu", "streamingDownload") !== true) return [];
|
|
204
|
+
let result;
|
|
205
|
+
try {
|
|
206
|
+
result = await remote.workspaceFiles.stat(target.sessionId, target.path, signal);
|
|
207
|
+
} catch (e) {
|
|
208
|
+
return []; // 元数据不可用:不提供本项,菜单其余条目照常
|
|
209
|
+
}
|
|
210
|
+
if (!result || result.ok !== true || !result.value) return [];
|
|
211
|
+
const bytes = typeof result.value.bytes === "number" ? result.value.bytes : undefined;
|
|
212
|
+
// 小文件 DSH 自带的「下载」就能用,不重复占位;只有超过整文件上限才出现。
|
|
213
|
+
if (bytes === undefined || bytes <= LARGE_FILE_BYTES) return [];
|
|
214
|
+
const absolutePath = result.value.absolutePath;
|
|
215
|
+
if (typeof absolutePath !== "string" || absolutePath.length === 0) return [];
|
|
216
|
+
return [{
|
|
217
|
+
id: "download-large",
|
|
218
|
+
label: "下载(大文件)",
|
|
219
|
+
icon: { key: "dsh-dock.download" },
|
|
220
|
+
run: () => startDownload(absolutePath),
|
|
221
|
+
}];
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** 下载图标(contextMenu.icon 座位用;跟随菜单文字颜色)。 */
|
|
225
|
+
function DownloadIcon() {
|
|
226
|
+
return react.createElement("svg", {
|
|
227
|
+
width: 14, height: 14, viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true",
|
|
228
|
+
},
|
|
229
|
+
react.createElement("path", {
|
|
230
|
+
d: "M8 2.5v7.2m0 0 2.8-2.8M8 9.7 5.2 6.9M3 13h10",
|
|
231
|
+
stroke: "currentColor", strokeWidth: 1.4, strokeLinecap: "round", strokeLinejoin: "round",
|
|
232
|
+
}));
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** 取服务:优先属性访问(正常 ctx),再退回 get()(精简 ctx / 测试桩)。 */
|
|
236
|
+
function serviceOf(scope, name) {
|
|
237
|
+
if (!scope) return undefined;
|
|
238
|
+
const direct = scope[name];
|
|
239
|
+
if (direct !== undefined) return direct;
|
|
240
|
+
return typeof scope.get === "function" ? scope.get(name) : undefined;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* 在依赖服务就绪后执行;没有 ctx.inject(测试桩 / 极简 ctx)时直接尝试一次。
|
|
245
|
+
* @param {object} ctx Client context
|
|
246
|
+
* @param {string[]} names 依赖的服务名
|
|
247
|
+
* @param {(scope: object) => void} run 装配回调
|
|
248
|
+
*/
|
|
249
|
+
function onServices(ctx, names, run) {
|
|
250
|
+
if (typeof ctx.inject === "function") {
|
|
251
|
+
try {
|
|
252
|
+
ctx.inject(names, (scope) => run(scope));
|
|
253
|
+
return;
|
|
254
|
+
} catch (e) {
|
|
255
|
+
// 桩 ctx 的 inject 不可用时退回直接取服务
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
run(ctx);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* 客户端装配:注册右键菜单与图标。由 src/client.jsx 的 apply() 调一次。
|
|
263
|
+
* 依赖用 ctx.inject 延迟获取(功能坞可能先于 ui-file-actions / ui-context-menu 加载);
|
|
264
|
+
* 服务缺失(桌面端 / 测试桩)时静默跳过,面板页本身仍可用。
|
|
265
|
+
* @param {object} ctx Client context
|
|
266
|
+
*/
|
|
267
|
+
export function installClient(ctx) {
|
|
268
|
+
if (!ctx || typeof ctx !== "object") return;
|
|
269
|
+
ensureLoaded();
|
|
270
|
+
onServices(ctx, ["slots"], (scope) => {
|
|
271
|
+
const slots = serviceOf(scope, "slots");
|
|
272
|
+
if (!slots || typeof slots.inject !== "function" || typeof slots.register !== "function") return;
|
|
273
|
+
slots.inject("contextMenu.icon", function* () {
|
|
274
|
+
yield slots.register({ name: "contextMenu.icon", key: "dsh-dock.download" }, DownloadIcon);
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
onServices(ctx, ["contextMenus", "remote.workspaceFiles"], (scope) => {
|
|
278
|
+
const menus = serviceOf(scope, "contextMenus");
|
|
279
|
+
const remote = serviceOf(scope, "remote");
|
|
280
|
+
if (!menus || typeof menus.register !== "function") return;
|
|
281
|
+
if (!remote || !remote.workspaceFiles || typeof remote.workspaceFiles.stat !== "function") return;
|
|
282
|
+
const register = () => menus.register({
|
|
283
|
+
id: "dsh-dock.dshtools.file",
|
|
284
|
+
target: "file",
|
|
285
|
+
// 排在 DSH 自带 file-actions(order 200)之后:同菜单里我们的是补充项。
|
|
286
|
+
order: 210,
|
|
287
|
+
resolve: (target, signal) => resolveFileMenu(remote, target, signal),
|
|
288
|
+
});
|
|
289
|
+
if (typeof scope.effect === "function") scope.effect(register, "dsh-dock: DSH功能 · 文件右键");
|
|
290
|
+
else register();
|
|
291
|
+
});
|
|
292
|
+
// 关键:把 DSH 自带的「下载」也接到流式路由上——用户最常点的是那一条,
|
|
293
|
+
// 不能让他先点旧条目再看到「无法保存文件」。
|
|
294
|
+
ensureRoute();
|
|
295
|
+
onServices(ctx, ["fileActions"], (scope) => {
|
|
296
|
+
const actions = serviceOf(scope, "fileActions");
|
|
297
|
+
if (!actions) return;
|
|
298
|
+
installDownloadTakeover(actions);
|
|
299
|
+
if (typeof scope.effect === "function") {
|
|
300
|
+
scope.effect(() => () => {
|
|
301
|
+
if (actions.__dshDockStreamingDownload !== true) return;
|
|
302
|
+
const restore = actions.save && actions.save.__original;
|
|
303
|
+
if (typeof restore === "function") {
|
|
304
|
+
try { actions.save = restore; } catch (e) { /* 忽略 */ }
|
|
305
|
+
}
|
|
306
|
+
delete actions.__dshDockStreamingDownload;
|
|
307
|
+
}, "dsh-dock: DSH功能 · 下载接管");
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// ---------- 面板页 ----------
|
|
313
|
+
const CSS = [
|
|
314
|
+
".dkht{display:flex;flex-direction:column;gap:12px;}",
|
|
315
|
+
".dkht-intro{color:var(--dsw-alias-label-secondary);font-size:12px;line-height:1.7;border:1px dashed var(--dsw-alias-border-l1);border-radius:8px;padding:8px 10px;}",
|
|
316
|
+
".dkht-group{border:1px solid var(--dsw-alias-border-l1);border-radius:10px;padding:10px 12px;display:flex;flex-direction:column;gap:6px;background:var(--dsw-alias-bg-layer-1);}",
|
|
317
|
+
".dkht-group-head{display:flex;align-items:baseline;gap:8px;flex-wrap:wrap;}",
|
|
318
|
+
".dkht-group-name{font-weight:600;font-size:13px;}",
|
|
319
|
+
".dkht-group-desc{font-size:11px;color:var(--dsw-alias-label-tertiary);}",
|
|
320
|
+
".dkht-item{display:flex;gap:10px;align-items:flex-start;padding:8px 10px;border-radius:8px;cursor:pointer;border:1px solid transparent;transition:background .12s,border-color .12s;}",
|
|
321
|
+
".dkht-item:hover{background:var(--dsw-alias-interactive-bg-hover);}",
|
|
322
|
+
".dkht-item.on{border-color:color-mix(in srgb,var(--dk-accent) 35%,transparent);background:var(--dk-hover-tint);}",
|
|
323
|
+
".dkht-item.busy{opacity:.6;cursor:progress;}",
|
|
324
|
+
".dkht-check{width:15px;height:15px;margin:2px 0 0;accent-color:var(--dk-accent);flex:none;cursor:pointer;}",
|
|
325
|
+
".dkht-text{display:flex;flex-direction:column;gap:2px;min-width:0;}",
|
|
326
|
+
".dkht-name{font-size:12px;font-weight:600;}",
|
|
327
|
+
".dkht-desc{font-size:11px;line-height:1.6;color:var(--dsw-alias-label-secondary);}",
|
|
328
|
+
".dkht-error{color:var(--dsw-alias-state-error-primary);font-size:12px;line-height:1.6;}",
|
|
329
|
+
".dkht-empty{color:var(--dsw-alias-label-tertiary);font-size:12px;}",
|
|
330
|
+
".dkht-note{color:var(--dsw-alias-label-tertiary);font-size:11px;line-height:1.6;}",
|
|
331
|
+
].join("\n");
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* 面板页:按宿主清单渲染分组与勾选框。
|
|
335
|
+
* @param {{ctx?: object}} props 宿主插槽透传(本页不直接用)
|
|
336
|
+
*/
|
|
337
|
+
function DshToolsView(props) {
|
|
338
|
+
const [, force] = react.useReducer((n) => n + 1, 0);
|
|
339
|
+
const [busy, setBusy] = react.useState("");
|
|
340
|
+
const [error, setError] = react.useState("");
|
|
341
|
+
react.useEffect(() => {
|
|
342
|
+
const off = subscribe(() => force());
|
|
343
|
+
ensureLoaded().then(() => force());
|
|
344
|
+
return off;
|
|
345
|
+
}, []);
|
|
346
|
+
const toggle = async (group, item) => {
|
|
347
|
+
const id = group.id + "/" + item.key;
|
|
348
|
+
if (busy) return;
|
|
349
|
+
setBusy(id);
|
|
350
|
+
setError("");
|
|
351
|
+
try {
|
|
352
|
+
await setValue(group.id, item.key, item.value !== true);
|
|
353
|
+
} catch (e) {
|
|
354
|
+
setError(e && e.message ? e.message : String(e));
|
|
355
|
+
} finally {
|
|
356
|
+
setBusy("");
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
const groups = store.groups;
|
|
360
|
+
return react.createElement("div", { className: "dkht" },
|
|
361
|
+
react.createElement("div", { className: "dkht-intro" },
|
|
362
|
+
"这里给 DSH 自带界面补充能力,按分组逐项勾选;勾选状态保存在功能坞设置里,换浏览器也一致。",
|
|
363
|
+
"取消勾选即完全撤掉对应入口,不影响 DSH 原有功能。"),
|
|
364
|
+
error ? react.createElement("div", { className: "dkht-error" }, error) : null,
|
|
365
|
+
store.error ? react.createElement("div", { className: "dkht-error" }, store.error) : null,
|
|
366
|
+
!store.ready && !store.error
|
|
367
|
+
? react.createElement("div", { className: "dkht-empty" }, "正在读取配置…")
|
|
368
|
+
: null,
|
|
369
|
+
groups.map((group) => react.createElement("div", { className: "dkht-group", key: group.id },
|
|
370
|
+
react.createElement("div", { className: "dkht-group-head" },
|
|
371
|
+
react.createElement("span", { className: "dkht-group-name" }, group.name),
|
|
372
|
+
group.description ? react.createElement("span", { className: "dkht-group-desc" }, group.description) : null),
|
|
373
|
+
group.items.map((item) => {
|
|
374
|
+
const id = group.id + "/" + item.key;
|
|
375
|
+
return react.createElement("label", {
|
|
376
|
+
key: item.key,
|
|
377
|
+
className: "dkht-item" + (item.value === true ? " on" : "") + (busy === id ? " busy" : ""),
|
|
378
|
+
},
|
|
379
|
+
react.createElement("input", {
|
|
380
|
+
type: "checkbox",
|
|
381
|
+
className: "dkht-check",
|
|
382
|
+
checked: item.value === true,
|
|
383
|
+
disabled: busy !== "",
|
|
384
|
+
onChange: () => { void toggle(group, item); },
|
|
385
|
+
}),
|
|
386
|
+
react.createElement("span", { className: "dkht-text" },
|
|
387
|
+
react.createElement("span", { className: "dkht-name" }, item.name),
|
|
388
|
+
item.description ? react.createElement("span", { className: "dkht-desc" }, item.description) : null));
|
|
389
|
+
}))),
|
|
390
|
+
react.createElement("div", { className: "dkht-note" },
|
|
391
|
+
"后续新增的 DSH 增强能力会以新分组/新勾选项出现在这里,无需另外配置。"));
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
export const feature = {
|
|
395
|
+
id: "dshtools",
|
|
396
|
+
name: "DSH功能",
|
|
397
|
+
order: 170,
|
|
398
|
+
accent: "#8b5cf6",
|
|
399
|
+
description: "给 DSH 自带界面补充能力(文件右键等),按分组勾选启用",
|
|
400
|
+
defaultEnabled: true,
|
|
401
|
+
css: CSS,
|
|
402
|
+
View: DshToolsView,
|
|
403
|
+
};
|
|
@@ -355,8 +355,8 @@ export const feature = {
|
|
|
355
355
|
setup(ctx) {
|
|
356
356
|
const webServer = ctx.get('webServer')
|
|
357
357
|
if (webServer === undefined) throw new Error('webServer 服务不可用,无法提供 MCP 管理路由')
|
|
358
|
-
const handler = async (req, res) => {
|
|
359
|
-
if (rejectUntrustedRequest(ctx, req, res)) return
|
|
358
|
+
const handler = async (req, res, peer) => {
|
|
359
|
+
if (rejectUntrustedRequest(ctx, req, res, peer)) return
|
|
360
360
|
try {
|
|
361
361
|
if (req.method === 'GET') {
|
|
362
362
|
const path = patchPathOf(ctx)
|
|
@@ -397,6 +397,6 @@ export const feature = {
|
|
|
397
397
|
})
|
|
398
398
|
}
|
|
399
399
|
}
|
|
400
|
-
return webServer.register({ kind: 'exact', path: '/dsh-dock/mcpconfig', handler })
|
|
400
|
+
return webServer.register({ kind: 'exact', auth: 'required', path: '/dsh-dock/mcpconfig', handler })
|
|
401
401
|
},
|
|
402
402
|
}
|
|
@@ -255,7 +255,7 @@ function ServerForm(props) {
|
|
|
255
255
|
hint: "工具名前缀:模型看到的是 mcp__<serverName>__<tool>;须匹配 " + SERVER_NAME_RE,
|
|
256
256
|
}, input({
|
|
257
257
|
value: form.serverName,
|
|
258
|
-
placeholder: "
|
|
258
|
+
placeholder: "demo_ocr",
|
|
259
259
|
disabled: isEdit,
|
|
260
260
|
onChange: (e) => patch({ serverName: e.target.value }),
|
|
261
261
|
})),
|
|
@@ -287,7 +287,7 @@ function ServerForm(props) {
|
|
|
287
287
|
rows: 4,
|
|
288
288
|
spellCheck: false,
|
|
289
289
|
value: form.argsText,
|
|
290
|
-
placeholder: "/
|
|
290
|
+
placeholder: "/home/me/work/demo-service/mcp_ocr.py",
|
|
291
291
|
onChange: (e) => patch({ argsText: e.target.value }),
|
|
292
292
|
})),
|
|
293
293
|
Field({ label: "env(每行一个 KEY=VALUE)", hint: "环境变量会明文写进 profile 补丁层(文件 0600,仅本机可读);没有可留空" },
|
|
@@ -300,7 +300,7 @@ function ServerForm(props) {
|
|
|
300
300
|
onChange: (e) => patch({ envText: e.target.value }),
|
|
301
301
|
})),
|
|
302
302
|
Field({ label: "cwd(可选)" },
|
|
303
|
-
input({ value: form.cwd, placeholder: "/
|
|
303
|
+
input({ value: form.cwd, placeholder: "/home/me/work/demo-service", onChange: (e) => patch({ cwd: e.target.value }) }))),
|
|
304
304
|
react.createElement("details", { className: "dkmc-advanced" },
|
|
305
305
|
react.createElement("summary", { className: "dkmc-summary" }, "高级"),
|
|
306
306
|
react.createElement("div", { className: "dkmc-advanced-body" },
|
|
@@ -423,16 +423,16 @@ function McpConfigView() {
|
|
|
423
423
|
|
|
424
424
|
// 一键填入本机 Xiaomi-OCR 示例(已存在则只提示,不覆盖)
|
|
425
425
|
const fillXiaomiExample = () => {
|
|
426
|
-
if (drafts.some((d) => d.serverName === "
|
|
427
|
-
setMsg({ tone: "warn", text: "列表里已经有
|
|
426
|
+
if (drafts.some((d) => d.serverName === "demo_ocr")) {
|
|
427
|
+
setMsg({ tone: "warn", text: "列表里已经有 demo_ocr(可直接点该卡片的「编辑」查看/修改)" });
|
|
428
428
|
return;
|
|
429
429
|
}
|
|
430
430
|
setForm(Object.assign(emptyForm(), {
|
|
431
|
-
serverName: "
|
|
431
|
+
serverName: "demo_ocr",
|
|
432
432
|
transport: "stdio",
|
|
433
433
|
command: "/usr/bin/python3",
|
|
434
|
-
argsText: "/
|
|
435
|
-
cwd: "/
|
|
434
|
+
argsText: "/home/me/work/demo-service/mcp_ocr.py",
|
|
435
|
+
cwd: "/home/me/work/demo-service",
|
|
436
436
|
envText: "",
|
|
437
437
|
toolCallTimeoutMs: "300000",
|
|
438
438
|
failOnStartupError: false,
|
|
@@ -148,7 +148,7 @@ export const feature = {
|
|
|
148
148
|
id: 'mobile-relay',
|
|
149
149
|
name: '远程访问',
|
|
150
150
|
description: '账号密码登录的远程入口:局域网/虚拟网设备访问同一个 DSH,任务进度实时一致',
|
|
151
|
-
//
|
|
151
|
+
// 宿主半部必须随插件加载(网关路由/账号服务都在这里),远程部署
|
|
152
152
|
// 完全依赖它——保持默认开启。v0.9.6 起面板开关会同步到宿主:显式停用会连网关
|
|
153
153
|
// 一起关掉(并持久化,重启后仍停用),部署环境请勿在面板里关闭本功能。
|
|
154
154
|
defaultEnabled: true,
|
|
@@ -258,16 +258,36 @@ export const feature = {
|
|
|
258
258
|
return sameText(username, auth.username) && sameText(hashPassword(auth.salt, password), auth.passwordHash)
|
|
259
259
|
}
|
|
260
260
|
|
|
261
|
+
/** 宿主公告的带令牌入口地址(DSH ≥ 0.2.2-rc.2 的唯一令牌来源),由 entry-url 监听器填。 */
|
|
262
|
+
let upstreamEntryUrl = null
|
|
263
|
+
|
|
264
|
+
/** 把缓存的入口地址换成主实例端口上的令牌地址;没缓存/没令牌就返回 null。 */
|
|
265
|
+
function upstreamTokenUrl(mainPort) {
|
|
266
|
+
if (!upstreamEntryUrl) return null
|
|
267
|
+
try {
|
|
268
|
+
const token = new URL(upstreamEntryUrl).searchParams.get('token')
|
|
269
|
+
if (!token) return null
|
|
270
|
+
return `http://127.0.0.1:${mainPort}/?token=${encodeURIComponent(token)}`
|
|
271
|
+
} catch { return null }
|
|
272
|
+
}
|
|
273
|
+
|
|
261
274
|
// 上游会话自动兑换:dsh web 自身还有一层启动令牌认证(首次访问 /?token= 换
|
|
262
|
-
// 30 天会话 Cookie,绑定回环 authority
|
|
263
|
-
//
|
|
264
|
-
//
|
|
265
|
-
//
|
|
275
|
+
// 30 天会话 Cookie,绑定回环 authority)。网关与主实例同进程,直接取带令牌的地址,
|
|
276
|
+
// 服务端完成兑换并返回 Cookie 对,由网关在代理时自动附带——远程浏览器只需网关账号
|
|
277
|
+
// 登录,无需再手动访问令牌地址。带令牌地址有两个来源:
|
|
278
|
+
// - DSH ≤ 0.2.2-rc.1:connection.authenticatedUrl(baseUrl)(现已删除,留作兼容);
|
|
279
|
+
// - DSH ≥ 0.2.2-rc.2:令牌迁入 host-authentication-token 插件,它把带令牌的入口地址
|
|
280
|
+
// 贡献到 webserver/entry-url(见 dsh 的 docs/upgrade-guide/v0.2.2-rc.2/
|
|
281
|
+
// connection-page-peer/guide.zh.md)。这里缓存一份贡献值,兑换时换成主实例端口。
|
|
282
|
+
// 两条都拿不到(例如宿主没公告入口地址)时返回空,网关退回官方行为:远程浏览器自己
|
|
283
|
+
// 访问一次令牌地址。
|
|
266
284
|
async function mintUpstreamSession(mainPort) {
|
|
267
285
|
try {
|
|
268
286
|
const connection = ctx.get('connection')
|
|
269
|
-
|
|
270
|
-
|
|
287
|
+
const url = connection && typeof connection.authenticatedUrl === 'function'
|
|
288
|
+
? connection.authenticatedUrl(`http://127.0.0.1:${mainPort}`)
|
|
289
|
+
: upstreamTokenUrl(mainPort)
|
|
290
|
+
if (!url) return null
|
|
271
291
|
const res = await fetch(url, { redirect: 'manual' })
|
|
272
292
|
const cookies = typeof res.headers.getSetCookie === 'function' ? res.headers.getSetCookie() : [res.headers.get('set-cookie')].filter(Boolean)
|
|
273
293
|
for (const raw of cookies) {
|
|
@@ -384,11 +404,24 @@ export const feature = {
|
|
|
384
404
|
if (typeof wsCtx.webServer.tapIndex === 'function') {
|
|
385
405
|
disposers.push(wsCtx.effect(() => wsCtx.webServer.tapIndex(injectLanCompat)))
|
|
386
406
|
}
|
|
407
|
+
// 缓存宿主公告的带令牌入口地址:entries 是同步 emit、各监听器依次 push,
|
|
408
|
+
// 所以延一拍(微任务)再读,才能读到 token 插件贡献的那一条。
|
|
409
|
+
if (typeof wsCtx.on === 'function') {
|
|
410
|
+
disposers.push(wsCtx.effect(() => wsCtx.on('webserver/entry-url', (_baseUrl, entries) => {
|
|
411
|
+
queueMicrotask(() => {
|
|
412
|
+
for (const entry of entries || []) {
|
|
413
|
+
const raw = String((entry && entry.url) || '')
|
|
414
|
+
if (raw.includes('token=')) { upstreamEntryUrl = raw; return }
|
|
415
|
+
}
|
|
416
|
+
})
|
|
417
|
+
}, 'dsh-dock: mobile-relay upstream entry-url cache')))
|
|
418
|
+
}
|
|
387
419
|
wsCtx.effect(() => wsCtx.webServer.register({
|
|
388
420
|
kind: 'prefix',
|
|
421
|
+
auth: 'required',
|
|
389
422
|
path: '/dsh-dock/mobile-relay',
|
|
390
|
-
async handler(req, res) {
|
|
391
|
-
if (rejectUntrustedRequest(ctx, req, res)) return
|
|
423
|
+
async handler(req, res, peer) {
|
|
424
|
+
if (rejectUntrustedRequest(ctx, req, res, peer)) return
|
|
392
425
|
try {
|
|
393
426
|
const method = routeMethod(req)
|
|
394
427
|
const payload = await readBody(req)
|
|
@@ -119,8 +119,8 @@ export const feature = {
|
|
|
119
119
|
setup(ctx) {
|
|
120
120
|
const webServer = ctx.get('webServer')
|
|
121
121
|
if (webServer === undefined) throw new Error('webServer 服务不可用,无法提供模型设置路由')
|
|
122
|
-
const handler = async (req, res) => {
|
|
123
|
-
if (rejectUntrustedRequest(ctx, req, res)) return
|
|
122
|
+
const handler = async (req, res, peer) => {
|
|
123
|
+
if (rejectUntrustedRequest(ctx, req, res, peer)) return
|
|
124
124
|
try {
|
|
125
125
|
if (req.method === 'GET') {
|
|
126
126
|
const payload = readModelDirectory(ctx)
|
|
@@ -154,6 +154,6 @@ export const feature = {
|
|
|
154
154
|
sendJson(res, status, { ok: false, error: e instanceof Error ? e.message : String(e) })
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
|
-
return webServer.register({ kind: 'exact', path: '/dsh-dock/models', handler })
|
|
157
|
+
return webServer.register({ kind: 'exact', auth: 'required', path: '/dsh-dock/models', handler })
|
|
158
158
|
},
|
|
159
159
|
}
|
package/features/notify/host.js
CHANGED
|
@@ -289,9 +289,10 @@ export const feature = {
|
|
|
289
289
|
disposers.push(ctx.inject(['webServer'], (wsCtx) => {
|
|
290
290
|
wsCtx.effect(() => wsCtx.webServer.register({
|
|
291
291
|
kind: 'prefix',
|
|
292
|
+
auth: 'required',
|
|
292
293
|
path: '/dsh-dock/notify',
|
|
293
|
-
async handler(req, res) {
|
|
294
|
-
if (rejectUntrustedRequest(ctx, req, res)) return
|
|
294
|
+
async handler(req, res, peer) {
|
|
295
|
+
if (rejectUntrustedRequest(ctx, req, res, peer)) return
|
|
295
296
|
try {
|
|
296
297
|
const url = new URL(req.url || '/', 'http://dsh.internal')
|
|
297
298
|
const method = url.pathname.replace(/^\/dsh-dock\/notify\/?/, '').split('/')[0] || ''
|