dsh-dock 0.23.1 → 0.25.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 +50 -40
- package/client.js +2552 -472
- package/features/animation/host.js +3 -2
- package/features/balance/host.js +3 -3
- package/features/dshtools/host.js +319 -0
- package/features/dshtools/view.jsx +403 -0
- package/features/git/host.js +884 -0
- package/features/git/rpc.js +156 -0
- package/features/git/view.jsx +1946 -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 +38 -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 +8 -2
- package/package.json +5 -6
- package/src/client.jsx +21 -2
- package/src/host-core.js +52 -13
- 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
|
@@ -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] || ''
|
package/features/notify/view.jsx
CHANGED
|
@@ -442,37 +442,33 @@ function endReasonSpeech(reason) {
|
|
|
442
442
|
return "完成了";
|
|
443
443
|
}
|
|
444
444
|
/** 结束播报文案(success 由调用方按 isSuccessReason 给)。kind: complete|error
|
|
445
|
-
*
|
|
446
|
-
*
|
|
447
|
-
*
|
|
445
|
+
* 统一口径(用户 2026-11-07 要求):**先说「主任务/子任务」,再说事件(完成了/停止了),
|
|
446
|
+
* 任务名接在后面**,例如「主任务完成了「标题」」「子任务停止了「标题」」。
|
|
447
|
+
* 子任务结束(主任务可能还在跑)必须报「子任务」而不是「主任务」——否则听着像整个任务结束。*/
|
|
448
448
|
export function endBroadcastText(success, record, task, cfg) {
|
|
449
449
|
const mode = voiceTone(cfg);
|
|
450
450
|
const reason = (record && record.endReason) || "";
|
|
451
451
|
const title = (record && record.title) || (task && task.title) || "";
|
|
452
452
|
const sub = !!((record && record.isSubtask) || (task && task.isSubtask));
|
|
453
|
+
const role = sub ? "子任务" : "主任务";
|
|
453
454
|
const parentTitle = (record && record.parentTitle) || (task && task.parentTitle) || "";
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
return success ? "任务完成" : "任务停止了";
|
|
458
|
-
}
|
|
455
|
+
// 先说角色 + 事件,再跟任务名
|
|
456
|
+
const head = role + (success ? "完成了" : "停止了") + (title ? "「" + truncate(title, 30) + "」" : "");
|
|
457
|
+
if (mode === "brief") return head;
|
|
459
458
|
if (mode === "medium") {
|
|
460
|
-
//
|
|
461
|
-
|
|
462
|
-
const who = sub
|
|
463
|
-
? (parentTitle ? "主任务「" + truncate(parentTitle, 20) + "」的" : "") + (title ? "子任务「" + truncate(title, 30) + "」" : "子任务")
|
|
464
|
-
: (title ? "任务「" + truncate(title, 30) + "」" : "任务");
|
|
465
|
-
const parts = [success ? who + "完成了" : who + "停止了"];
|
|
459
|
+
// 适中口径:角色+结果+任务名 +(停止原因)+(子任务点名主任务)+ 耗时;不念回合/Token
|
|
460
|
+
const parts = [head];
|
|
466
461
|
if (!success) parts.push(",原因:" + endReasonSpeech(reason));
|
|
462
|
+
if (sub && parentTitle) parts.push("(主任务「" + truncate(parentTitle, 20) + "」)");
|
|
467
463
|
const dur = (record && record.duration) || 0;
|
|
468
464
|
if (dur > 0) parts.push(",耗时" + fmtDur(dur));
|
|
469
465
|
parts.push("。");
|
|
470
466
|
return parts.join("");
|
|
471
467
|
}
|
|
472
|
-
|
|
468
|
+
// 详细:角色+结果+任务名 → 主任务(子任务时)→ 原因/耗时 → 统计 → 摘要
|
|
469
|
+
const parts = [head + "。"];
|
|
473
470
|
if (sub && parentTitle) parts.push("主任务:" + truncate(parentTitle, 30) + "。");
|
|
474
|
-
if (
|
|
475
|
-
parts.push(success ? "已完成。" : "结束,原因:" + endReasonSpeech(reason) + "。");
|
|
471
|
+
if (!success) parts.push("原因:" + endReasonSpeech(reason) + "。");
|
|
476
472
|
const dur = (record && record.duration) || 0;
|
|
477
473
|
if (dur > 0) parts.push("耗时" + fmtDur(dur) + "。");
|
|
478
474
|
const turns = (record && record.turns) || (task && task.turns) || 0;
|
|
@@ -486,63 +482,59 @@ export function endBroadcastText(success, record, task, cfg) {
|
|
|
486
482
|
}
|
|
487
483
|
return parts.join("");
|
|
488
484
|
}
|
|
489
|
-
/**
|
|
485
|
+
/** 需授权播报文案。统一口径:先说「主任务/子任务」,再说「需要授权」,任务名接在后面。 */
|
|
490
486
|
export function confirmBroadcastText(task, approval, cfg) {
|
|
491
487
|
const mode = voiceTone(cfg);
|
|
492
|
-
|
|
488
|
+
const role = task && task.isSubtask ? "子任务" : "主任务";
|
|
489
|
+
const title = (task && task.title) || "";
|
|
490
|
+
const head = role + "需要授权" + (title ? "「" + truncate(title, 30) + "」" : "");
|
|
493
491
|
const tool = (approval && approval.toolName) || "工具";
|
|
494
492
|
const scene = toolLabel(tool);
|
|
495
|
-
if (mode === "
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
return who + "需要授权,正在等你批准" + (scene || "工具 " + tool) + "。";
|
|
499
|
-
}
|
|
500
|
-
const parts = [];
|
|
501
|
-
if (task && task.title) parts.push("任务:" + truncate(task.title, 30) + "。");
|
|
493
|
+
if (mode === "brief") return head;
|
|
494
|
+
if (mode === "medium") return head + ",正在等你批准" + (scene || "工具 " + tool) + "。";
|
|
495
|
+
const parts = [head + "。"];
|
|
502
496
|
parts.push("正在等待你批准" + (scene ? "执行" + scene : "") + ",工具是" + tool + ",请回到会话处理。");
|
|
503
497
|
return parts.join("");
|
|
504
498
|
}
|
|
505
499
|
/**
|
|
506
500
|
* 需回答播报文案(ask_user_question 挂起,等人选答案)。
|
|
507
|
-
*
|
|
508
|
-
* 简洁口径只说「任务需要回答」;适中点名任务与问题;详细再补"共几问"与回到会话的叮嘱。
|
|
501
|
+
* 与「需授权」是两件事。统一口径:先说「主任务/子任务」,再说「需要你回答」,任务名/问题接后面。
|
|
509
502
|
*/
|
|
510
503
|
export function questionBroadcastText(task, question, cfg) {
|
|
511
504
|
const mode = voiceTone(cfg);
|
|
512
|
-
|
|
513
|
-
const
|
|
514
|
-
const head = (
|
|
505
|
+
const role = task && task.isSubtask ? "子任务" : "主任务";
|
|
506
|
+
const title = (task && task.title) || "";
|
|
507
|
+
const head = role + "需要你回答" + (title ? "「" + truncate(title, 30) + "」" : "");
|
|
508
|
+
const qhead = (question && question.header) || "";
|
|
515
509
|
const body = (question && question.question) || "";
|
|
516
510
|
const what = body ? truncate(body.replace(/[#*_`>\[\]()!]/g, ""), 40) : "";
|
|
511
|
+
if (mode === "brief") return head;
|
|
517
512
|
if (mode === "medium") {
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
return who + "在等你回答" + tail + "。";
|
|
513
|
+
const tail = what ? ":" + what : (qhead ? ":" + qhead : "");
|
|
514
|
+
return head + tail + "。";
|
|
521
515
|
}
|
|
522
|
-
const parts = [];
|
|
523
|
-
|
|
524
|
-
parts.push(what ? "正在等你回答问题:" + what + "。" : "正在等你回答问题。");
|
|
516
|
+
const parts = [head + "。"];
|
|
517
|
+
parts.push(what ? "问题:" + what + "。" : (qhead ? "问题:" + qhead + "。" : "正在等你回答问题。"));
|
|
525
518
|
const count = (question && question.count) || 0;
|
|
526
519
|
if (count > 1) parts.push("共 " + count + " 个问题。");
|
|
527
520
|
parts.push("请回到会话选择答案。");
|
|
528
521
|
return parts.join("");
|
|
529
522
|
}
|
|
530
523
|
/**
|
|
531
|
-
*
|
|
532
|
-
*
|
|
533
|
-
* 用户实测:主任务进行中突然播「任务卡住了」,屏幕上却看不到卡住的东西),
|
|
534
|
-
* 所以简洁口径也带「主/子 + 标题」,详细口径再补停滞时长与最后动作。
|
|
524
|
+
* 卡住播报文案:统一口径(用户 2026-11-07 要求)**先说「主任务/子任务」,再说「卡住了」,
|
|
525
|
+
* 任务名接在后面**,详细再补停滞时长与最后动作。例:「主任务卡住了「标题」」。
|
|
535
526
|
* 归属字段来自宿主追踪快照(task-track 的 isSubtask/lastToolName)。
|
|
536
527
|
*/
|
|
537
528
|
export function stuckBroadcastText(task, cfg) {
|
|
538
529
|
const mode = voiceTone(cfg);
|
|
539
|
-
const
|
|
540
|
-
|
|
541
|
-
|
|
530
|
+
const role = task && task.isSubtask ? "子任务" : "主任务";
|
|
531
|
+
const title = (task && task.title) || "";
|
|
532
|
+
const head = role + "卡住了" + (title ? "「" + truncate(title, 30) + "」" : "");
|
|
533
|
+
if (mode === "brief") return head;
|
|
542
534
|
if (mode === "medium") {
|
|
543
|
-
return
|
|
535
|
+
return head + ",已经" + fmtDur(Math.max(0, (cfg && cfg.stuckMs) || STUCK_MS)) + "没有任何动静。";
|
|
544
536
|
}
|
|
545
|
-
const parts = [
|
|
537
|
+
const parts = [head + "。"];
|
|
546
538
|
parts.push("编程阶段已经" + fmtDur(Math.max(0, (cfg && cfg.stuckMs) || STUCK_MS)) + "没有任何动静,");
|
|
547
539
|
const tool = (task && task.lastToolName) || "";
|
|
548
540
|
const scene = tool ? toolLabel(tool) : "";
|
|
@@ -206,8 +206,8 @@ export const feature = {
|
|
|
206
206
|
setup(ctx) {
|
|
207
207
|
const webServer = ctx.get('webServer')
|
|
208
208
|
if (webServer === undefined) throw new Error('webServer 服务不可用,无法提供模型提供商路由')
|
|
209
|
-
const handler = async (req, res) => {
|
|
210
|
-
if (rejectUntrustedRequest(ctx, req, res)) return
|
|
209
|
+
const handler = async (req, res, peer) => {
|
|
210
|
+
if (rejectUntrustedRequest(ctx, req, res, peer)) return
|
|
211
211
|
try {
|
|
212
212
|
if (req.method === 'GET') {
|
|
213
213
|
const payload = readModelDirectory(ctx)
|
|
@@ -230,6 +230,6 @@ export const feature = {
|
|
|
230
230
|
sendJson(res, status, { ok: false, error: e instanceof Error ? e.message : String(e) })
|
|
231
231
|
}
|
|
232
232
|
}
|
|
233
|
-
return webServer.register({ kind: 'exact', path: '/dsh-dock/providerconfig', handler })
|
|
233
|
+
return webServer.register({ kind: 'exact', auth: 'required', path: '/dsh-dock/providerconfig', handler })
|
|
234
234
|
},
|
|
235
235
|
}
|
|
@@ -35,9 +35,10 @@ export const feature = {
|
|
|
35
35
|
disposers.push(ctx.inject(['webServer'], (wsCtx) => {
|
|
36
36
|
wsCtx.effect(() => wsCtx.webServer.register({
|
|
37
37
|
kind: 'prefix',
|
|
38
|
+
auth: 'required',
|
|
38
39
|
path: '/dsh-dock/runstate',
|
|
39
|
-
async handler(req, res) {
|
|
40
|
-
if (rejectUntrustedRequest(ctx, req, res)) return
|
|
40
|
+
async handler(req, res, peer) {
|
|
41
|
+
if (rejectUntrustedRequest(ctx, req, res, peer)) return
|
|
41
42
|
try {
|
|
42
43
|
const url = new URL(req.url || '/', 'http://dsh.internal')
|
|
43
44
|
const method = url.pathname.replace(/^\/dsh-dock\/runstate\/?/, '').split('/')[0] || ''
|
|
@@ -1035,9 +1035,10 @@ export const feature = {
|
|
|
1035
1035
|
disposers.push(ctx.inject(['webServer'], (wsCtx) => {
|
|
1036
1036
|
wsCtx.effect(() => wsCtx.webServer.register({
|
|
1037
1037
|
kind: 'prefix',
|
|
1038
|
+
auth: 'required',
|
|
1038
1039
|
path: '/dsh-dock/tokenlog',
|
|
1039
|
-
async handler(req, res) {
|
|
1040
|
-
if (rejectUntrustedRequest(ctx, req, res)) return
|
|
1040
|
+
async handler(req, res, peer) {
|
|
1041
|
+
if (rejectUntrustedRequest(ctx, req, res, peer)) return
|
|
1041
1042
|
try {
|
|
1042
1043
|
const url = new URL(req.url || '/', 'http://dsh.internal')
|
|
1043
1044
|
const method = url.pathname.replace(/^\/dsh-dock\/tokenlog\/?/, '').split('/')[0] || ''
|
package/features/tts/host.js
CHANGED
|
@@ -119,9 +119,10 @@ export const feature = {
|
|
|
119
119
|
disposers.push(ctx.inject(['webServer'], (wsCtx) => {
|
|
120
120
|
wsCtx.effect(() => wsCtx.webServer.register({
|
|
121
121
|
kind: 'prefix',
|
|
122
|
+
auth: 'required',
|
|
122
123
|
path: '/dsh-dock/tts',
|
|
123
|
-
async handler(req, res) {
|
|
124
|
-
if (rejectUntrustedRequest(ctx, req, res)) return
|
|
124
|
+
async handler(req, res, peer) {
|
|
125
|
+
if (rejectUntrustedRequest(ctx, req, res, peer)) return
|
|
125
126
|
try {
|
|
126
127
|
const url = new URL(req.url || '/', 'http://dsh.internal')
|
|
127
128
|
const method = url.pathname.replace(/^\/dsh-dock\/tts\/?/, '').split('/')[0] || ''
|
package/index.js
CHANGED
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
// - modelconfig 模型能力:模型目录的输入模态与思考强度(写回官方配置)
|
|
20
20
|
// - providerconfig 模型管理:Provider 增删改 + API Key + 拉取上游模型列表
|
|
21
21
|
// - mobile-relay 远程访问:账号密码登录的远程入口(网关 + 账号 + 浏览模式目录选择器)
|
|
22
|
+
// - git Git 管理:仓库提交记录查询(默认当前会话目录,可含子目录仓库)
|
|
22
23
|
import { DockConfig, sendJson, readBody, rejectUntrustedRequest, migrateNotifyConfig, migrateModelsFeatureId, migrateImportedFeatures, migrateImportedSections, bindDockConfig, readDockRoot, mutateDockSection } from './src/host-core.js'
|
|
23
24
|
import { injectWelcomeAck } from './src/welcome-ack.js'
|
|
24
25
|
import { feature as fModels } from './features/modelconfig/host.js'
|
|
@@ -32,6 +33,8 @@ import { feature as fRunState } from './features/runstate/host.js'
|
|
|
32
33
|
import { feature as fTts } from './features/tts/host.js'
|
|
33
34
|
import { feature as fMobileRelay } from './features/mobile-relay/host.js'
|
|
34
35
|
import { feature as fMcpConfig } from './features/mcpconfig/host.js'
|
|
36
|
+
import { feature as fDshTools } from './features/dshtools/host.js'
|
|
37
|
+
import { feature as fGit } from './features/git/host.js'
|
|
35
38
|
|
|
36
39
|
export const name = 'dsh-dock'
|
|
37
40
|
|
|
@@ -76,6 +79,8 @@ export function apply(ctx, config) {
|
|
|
76
79
|
fTts,
|
|
77
80
|
fMobileRelay,
|
|
78
81
|
fMcpConfig,
|
|
82
|
+
fDshTools,
|
|
83
|
+
fGit,
|
|
79
84
|
]
|
|
80
85
|
|
|
81
86
|
// 绑定 Config 镜像(替代已移除的 settings.get);volatile 字段热更时重绑。
|
|
@@ -197,9 +202,10 @@ export function apply(ctx, config) {
|
|
|
197
202
|
if (webServer) {
|
|
198
203
|
webServer.register({
|
|
199
204
|
kind: 'exact',
|
|
205
|
+
auth: 'required',
|
|
200
206
|
path: '/dsh-dock/features',
|
|
201
|
-
handler: async (req, res) => {
|
|
202
|
-
if (rejectUntrustedRequest(ctx, req, res)) return
|
|
207
|
+
handler: async (req, res, peer) => {
|
|
208
|
+
if (rejectUntrustedRequest(ctx, req, res, peer)) return
|
|
203
209
|
try {
|
|
204
210
|
if (req.method === 'POST') {
|
|
205
211
|
const body = await readBody(req)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-dock",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "DeepSeek Harness 功能坞插件(dsh-dock):模块化功能中枢——每个功能一个 features/ 模块(可单独提取成包发布,又可经 dockBridge 装回面板)。含用量记录(LLM 调用记账/费用统计,支持各模型自定义单价、多段分时价与周末/节假日谷价)、模型能力、图片理解代理、模型余额、任务动画(19 种运行动画 + 桌面伙伴 3D 场景)、任务通知(完成/异常/需确认通知、提示音、语音播报可选音色、系统通知、钉钉/飞书推送)、运行状态(进行中任务与最近完成一览)、语音朗读(浏览器 TTS 读回复:回合下方喇叭按钮 +
|
|
3
|
+
"version": "0.25.0",
|
|
4
|
+
"description": "DeepSeek Harness 功能坞插件(dsh-dock):模块化功能中枢——每个功能一个 features/ 模块(可单独提取成包发布,又可经 dockBridge 装回面板)。含用量记录(LLM 调用记账/费用统计,支持各模型自定义单价、多段分时价与周末/节假日谷价)、模型能力、图片理解代理、模型余额、任务动画(19 种运行动画 + 桌面伙伴 3D 场景)、任务通知(完成/异常/需确认通知、提示音、语音播报可选音色、系统通知、钉钉/飞书推送)、运行状态(进行中任务与最近完成一览)、语音朗读(浏览器 TTS 读回复:回合下方喇叭按钮 + 自动朗读)、DSH功能(给 DSH 自带界面补能力:文件右键大文件流式下载、右侧抽屉 Git 仓库操作面板)、Git 管理(提交历史表格与逐行差异、子仓库多选、时间段与提交人筛选、暂存/提交/推送);侧栏入口 + 可拖拽弹窗(最大化/最小化/缩放)。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"files": [
|
|
@@ -9,8 +9,7 @@
|
|
|
9
9
|
"client.js",
|
|
10
10
|
"src/",
|
|
11
11
|
"features/",
|
|
12
|
-
"cordis.patch.yml"
|
|
13
|
-
"screenshots"
|
|
12
|
+
"cordis.patch.yml"
|
|
14
13
|
],
|
|
15
14
|
"exports": {
|
|
16
15
|
".": "./index.js",
|
|
@@ -42,8 +41,8 @@
|
|
|
42
41
|
"license": "MIT",
|
|
43
42
|
"scripts": {
|
|
44
43
|
"build:client": "node scripts/build-client.mjs",
|
|
45
|
-
"test:client": "node scripts/test-client-views.mjs",
|
|
46
|
-
"test:host": "node scripts/test-task-host.mjs && node scripts/test-mcpconfig-host.mjs && node scripts/test-tokenlog-host.mjs && node scripts/test-balance-host.mjs && node scripts/test-route-trust-host.mjs && node scripts/test-tts-host.mjs && node scripts/test-legacy-import.mjs && node scripts/test-mobile-relay-host.mjs && node scripts/test-mobile-relay.mjs && node scripts/test-welcome-ack.mjs",
|
|
44
|
+
"test:client": "node scripts/test-client-views.mjs && node scripts/test-dshtools-client.mjs",
|
|
45
|
+
"test:host": "node scripts/test-task-host.mjs && node scripts/test-mcpconfig-host.mjs && node scripts/test-tokenlog-host.mjs && node scripts/test-balance-host.mjs && node scripts/test-route-trust-host.mjs && node scripts/test-tts-host.mjs && node scripts/test-legacy-import.mjs && node scripts/test-mobile-relay-host.mjs && node scripts/test-mobile-relay.mjs && node scripts/test-welcome-ack.mjs && node scripts/test-dshtools-host.mjs && node scripts/test-git-host.mjs",
|
|
47
46
|
"dev:client": "node scripts/watch-client.mjs",
|
|
48
47
|
"dev:link": "node scripts/dev-link-deps.mjs"
|
|
49
48
|
},
|
package/src/client.jsx
CHANGED
|
@@ -29,12 +29,14 @@ import { feature as fTts } from "../features/tts/view.jsx";
|
|
|
29
29
|
import { feature as fGames } from "../features/games/view.jsx";
|
|
30
30
|
import { feature as fMobileRelay } from "../features/mobile-relay/view.jsx";
|
|
31
31
|
import { feature as fMcpConfig } from "../features/mcpconfig/view.js";
|
|
32
|
+
import { feature as fDshTools, installClient as installDshTools } from "../features/dshtools/view.jsx";
|
|
33
|
+
import { installClient as installGit, css as GIT_CSS, DirBrowser as GitDirBrowser, GitView as GitPanelView } from "../features/git/view.jsx";
|
|
32
34
|
|
|
33
35
|
const name = "dsh-dock";
|
|
34
|
-
const DOCK_VERSION = "0.
|
|
36
|
+
const DOCK_VERSION = "0.25.0";
|
|
35
37
|
|
|
36
38
|
// ---- 内置功能注册表:新功能 = features/<id>/ 加模块 + 这里 import 一行 ----
|
|
37
|
-
const BUILTIN_FEATURES = [fTokenlog, fModelconfig, fProviderConfig, fMcpConfig, fBalance, fAnimation, fNotify, fRunState, fTts, fGames, fMobileRelay];
|
|
39
|
+
const BUILTIN_FEATURES = [fTokenlog, fModelconfig, fProviderConfig, fMcpConfig, fBalance, fAnimation, fNotify, fRunState, fTts, fGames, fMobileRelay, fDshTools];
|
|
38
40
|
// 规划占位(路线图):接入后移除并建 features/<id>/ 模块
|
|
39
41
|
const PLANNED_FEATURES = [];
|
|
40
42
|
const PLANNED_NOTES = {};
|
|
@@ -269,6 +271,9 @@ function cancelInitialCssSchedule() {
|
|
|
269
271
|
function fullDockCss() {
|
|
270
272
|
const parts = [SHELL_CSS];
|
|
271
273
|
for (const f of BUILTIN_FEATURES) if (f.css) parts.push(f.css);
|
|
274
|
+
// Git 面板不再是功能坞里的功能项(改成 DSH功能 的开关 + 抽屉页签),
|
|
275
|
+
// 但样式仍并入这同一个 <style data-plugin="dsh-dock">:单独注入会被别的插件 claim 走。
|
|
276
|
+
if (GIT_CSS) parts.push(GIT_CSS);
|
|
272
277
|
for (const f of externalDefs) if (f.css) parts.push(f.css);
|
|
273
278
|
return parts.join("\n");
|
|
274
279
|
}
|
|
@@ -784,7 +789,21 @@ export function apply(ctx) {
|
|
|
784
789
|
slots.inject("conversation.chat.turnTail", () => slots.register(
|
|
785
790
|
{ name: "conversation.chat.turnTail", id: "dsh-dock-turn-tail", order: 40, label: "功能坞" },
|
|
786
791
|
(owner) => react.createElement(FeatureTurnTail, owner)));
|
|
792
|
+
// 【DSH功能】的全局接线(右键菜单等):模块自带延迟注入,功能开关在菜单解析时判断
|
|
793
|
+
installDshTools(ctx);
|
|
794
|
+
installGit(ctx);
|
|
787
795
|
}
|
|
788
796
|
|
|
789
797
|
export const inject = ["timer"];
|
|
790
798
|
export { dockBridge };
|
|
799
|
+
// 测试探针:目录浏览器单独导出,便于用例直接渲染校验(不参与运行逻辑)
|
|
800
|
+
export { GitDirBrowser as DirBrowser };
|
|
801
|
+
export { GitPanelView as GitView };
|
|
802
|
+
// 测试探针:会话目录读取函数(验证按 sessionId 取值,而非全局当前会话)
|
|
803
|
+
export { currentSessionDir as readSessionDir } from "../features/git/rpc.js";
|
|
804
|
+
// 测试探针:时间格式化(验证列表里的绝对时间精确到秒)
|
|
805
|
+
export { fmtDateTime } from "../features/git/rpc.js";
|
|
806
|
+
// 测试探针:提交表格的列定义与列宽计算(验证「列可勾选」)
|
|
807
|
+
export { COMMIT_COLUMNS, DEFAULT_VISIBLE_COLUMNS, columnsTemplate, toggleRepoSelection } from "../features/git/view.jsx";
|
|
808
|
+
// 测试探针:拖动分隔条(验证上下拖动确实改变高度比例)
|
|
809
|
+
export { DragSplitter as GitDragSplitter, clampPercent, splitterStep, dragToPercent } from "../features/git/view.jsx";
|
package/src/host-core.js
CHANGED
|
@@ -184,6 +184,16 @@ export const DockConfig = z.object({
|
|
|
184
184
|
/** 自动朗读时只读回复的前 N 句(0 = 不限)。眼睛不舒服想听结论的人通常只要前几句。 */
|
|
185
185
|
maxSentences: z.number().default(0),
|
|
186
186
|
}).default({}).volatile(),
|
|
187
|
+
// 【DSH功能】模块:给 DSH 自带界面补充能力,按「分组 × 勾选项」组织。
|
|
188
|
+
// 分组/键名以 features/dshtools/host.js 的 DSH_TOOL_GROUPS 为准;这里只声明可持久化的段,
|
|
189
|
+
// 新增能力时在清单里加一项即可(旧设置里没有的键按清单 default 兜底)。
|
|
190
|
+
dshtools: z.object({
|
|
191
|
+
/** 文件右键菜单的补充项。 */
|
|
192
|
+
fileContextMenu: z.object({
|
|
193
|
+
/** 大文件下载(流式):文件超过 32 MiB 时右键多出「下载(大文件)」。 */
|
|
194
|
+
streamingDownload: z.boolean().default(true),
|
|
195
|
+
}).default({}),
|
|
196
|
+
}).default({}).volatile(),
|
|
187
197
|
})
|
|
188
198
|
|
|
189
199
|
// ── 本地配置镜像(替代已移除的 settings.get) ─────────────────────────────
|
|
@@ -523,31 +533,60 @@ export function sendJson(res, status, value) {
|
|
|
523
533
|
let warnedNoTrustSurface = false
|
|
524
534
|
|
|
525
535
|
/**
|
|
526
|
-
* 浏览器信任栅栏:**每个自行注册的 `webServer`
|
|
536
|
+
* 浏览器信任栅栏:**每个自行注册的 `webServer` 路由都必须先调它**(并把 handler 的
|
|
537
|
+
* 第三个参数 `peer` 传进来)。
|
|
538
|
+
*
|
|
539
|
+
* 为什么必须:`webServer` 的命名路由由载体直接派发给 handler。DSH 0.2.2-rc.2 之前载体
|
|
540
|
+
* 「不拥有认证或 Origin 策略」,`/api` 的 Host/Origin 校验与会话认证由 Connection 在它
|
|
541
|
+
* 自己的 FetchHandler 上做,**管不到插件注册的命名路由**——不检查的插件路由就是一扇对
|
|
542
|
+
* 任何能连到端口的人都敞开的门,dsh-access 这类门禁插件也拦不到。
|
|
543
|
+
*
|
|
544
|
+
* 0.2.2-rc.2 起准入换了地方(见 dsh 的
|
|
545
|
+
* `docs/upgrade-guide/v0.2.2-rc.2/connection-page-peer/guide.zh.md`):Connection 上的
|
|
546
|
+
* `requestRejection`、`authenticatedUrl` 等被删除;`webServer.register` 的路由项新增
|
|
547
|
+
* `auth: 'anonymous' | 'required' | 'deny'`(**默认 required**),由载体在派发前完成
|
|
548
|
+
* Host/Origin 校验与认证,并把准入得到的 Peer 作为 handler 的第三个参数交下来。
|
|
527
549
|
*
|
|
528
|
-
*
|
|
529
|
-
* `
|
|
530
|
-
*
|
|
531
|
-
*
|
|
532
|
-
*
|
|
533
|
-
*
|
|
550
|
+
* 本函数因此同时兼容两代宿主,判断顺序很关键:
|
|
551
|
+
* 1. handler 收到了 `peer` —— 载体已经放行,直接返回 false。**绝不再调一次
|
|
552
|
+
* `connection.admit`**:那会重新认证出一个新 Peer,白耗一份凭据与生命周期。
|
|
553
|
+
* 2. 没有 `peer` 但宿主提供 `requestRejection` —— 老宿主(命名路由不鉴权),照旧自己问
|
|
554
|
+
* 它,值即 401(Host 可信但无会话)或 403(Host/Origin 栅栏拒绝),与官方
|
|
555
|
+
* `dsh-host-open-in-app`、`dsh-experimental-inspector` 当年的写法一致。
|
|
556
|
+
* 3. 两者都没有 —— fail-closed 按 401 拒绝。dsh-dock 的路由本来就是 web 专用的,
|
|
557
|
+
* 宁可面板报错,也不能给身份不明的请求开门。
|
|
534
558
|
*
|
|
535
|
-
*
|
|
536
|
-
*
|
|
537
|
-
* 403(Host/Origin 栅栏拒绝)。Connection 不可用时按 fail-closed 处理——dsh-dock 的
|
|
538
|
-
* 路由本身就是 web 专用的。
|
|
559
|
+
* 走第 1 条的前提是每个注册点都**显式**写 `auth: 'required'`:不写也落在默认值上,但
|
|
560
|
+
* 显式声明才挡得住将来默认值变化。`scripts/test-route-trust-host.mjs` 静态检查这一点。
|
|
539
561
|
*
|
|
562
|
+
* @param ctx 插件上下文
|
|
563
|
+
* @param req 原始 HTTP 请求
|
|
564
|
+
* @param res 待写响应
|
|
565
|
+
* @param peer 新宿主准入后交给 handler 的 Peer;老宿主与测试桩为 undefined
|
|
540
566
|
* @returns {boolean} true = 已拒绝并写完响应,调用方必须立即 return。
|
|
541
567
|
*/
|
|
542
|
-
export function rejectUntrustedRequest(ctx, req, res) {
|
|
568
|
+
export function rejectUntrustedRequest(ctx, req, res, peer) {
|
|
569
|
+
// ① 新宿主:载体已完成准入,拿到 peer 就是放行过的请求。
|
|
570
|
+
if (peer !== undefined && peer !== null) return false
|
|
571
|
+
|
|
543
572
|
const connection = ctx && typeof ctx.get === 'function' ? ctx.get('connection') : null
|
|
544
573
|
const requestRejection = connection && typeof connection.requestRejection === 'function'
|
|
545
574
|
? connection.requestRejection.bind(connection)
|
|
546
575
|
: null
|
|
547
576
|
if (requestRejection === null) {
|
|
577
|
+
// ③-a 新宿主 + 本路由没声明 auth: 'required'(例如 anonymous):载体不会给它 peer。
|
|
578
|
+
if (connection && typeof connection.admit === 'function') {
|
|
579
|
+
if (!warnedNoTrustSurface) {
|
|
580
|
+
warnedNoTrustSurface = true
|
|
581
|
+
console.warn("[dsh-dock] 宿主已提供准入但本路由未拿到 peer:检查 webServer.register 是否显式声明 auth: 'required'")
|
|
582
|
+
}
|
|
583
|
+
sendJson(res, 401, { ok: false, error: { code: 'untrusted', message: "路由未声明 auth: 'required',未通过宿主准入,已拒绝请求" } })
|
|
584
|
+
return true
|
|
585
|
+
}
|
|
586
|
+
// ③-b 既没有载体的 peer,也没有老宿主的栅栏面:fail-closed。
|
|
548
587
|
if (!warnedNoTrustSurface) {
|
|
549
588
|
warnedNoTrustSurface = true
|
|
550
|
-
console.warn('[dsh-dock] connection
|
|
589
|
+
console.warn('[dsh-dock] 宿主未提供路由准入(既无 peer 也无 connection.requestRejection):/dsh-dock 路由一律按未受信请求拒绝(401)')
|
|
551
590
|
}
|
|
552
591
|
sendJson(res, 401, { ok: false, error: { code: 'untrusted', message: '浏览器信任栅栏不可用,已拒绝请求' } })
|
|
553
592
|
return true
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|