dsh-plugin-console-oh 0.0.0-stage → 0.6.2
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 +86 -2
- package/cordis.patch.yml +16 -0
- package/lib/client.js +451 -0
- package/lib/index.js +1414 -0
- package/lib/server.mjs +718 -0
- package/lib/tunnel.mjs +238 -0
- package/lib/vendor/README.md +11 -0
- package/lib/vendor/dijkstrajs/LICENSE.md +19 -0
- package/lib/vendor/dijkstrajs/index.js +165 -0
- package/lib/vendor/dijkstrajs/package.json +5 -0
- package/lib/vendor/qrcode/LICENSE +10 -0
- package/lib/vendor/qrcode/core/alignment-pattern.js +83 -0
- package/lib/vendor/qrcode/core/alphanumeric-data.js +59 -0
- package/lib/vendor/qrcode/core/bit-buffer.js +37 -0
- package/lib/vendor/qrcode/core/bit-matrix.js +65 -0
- package/lib/vendor/qrcode/core/byte-data.js +30 -0
- package/lib/vendor/qrcode/core/error-correction-code.js +135 -0
- package/lib/vendor/qrcode/core/error-correction-level.js +50 -0
- package/lib/vendor/qrcode/core/finder-pattern.js +22 -0
- package/lib/vendor/qrcode/core/format-info.js +29 -0
- package/lib/vendor/qrcode/core/galois-field.js +69 -0
- package/lib/vendor/qrcode/core/kanji-data.js +54 -0
- package/lib/vendor/qrcode/core/mask-pattern.js +234 -0
- package/lib/vendor/qrcode/core/mode.js +167 -0
- package/lib/vendor/qrcode/core/numeric-data.js +43 -0
- package/lib/vendor/qrcode/core/polynomial.js +62 -0
- package/lib/vendor/qrcode/core/qrcode.js +495 -0
- package/lib/vendor/qrcode/core/reed-solomon-encoder.js +56 -0
- package/lib/vendor/qrcode/core/regex.js +31 -0
- package/lib/vendor/qrcode/core/segments.js +330 -0
- package/lib/vendor/qrcode/core/utils.js +63 -0
- package/lib/vendor/qrcode/core/version-check.js +9 -0
- package/lib/vendor/qrcode/core/version.js +163 -0
- package/lib/vendor/qrcode/index.js +20 -0
- package/lib/vendor/qrcode/package.json +5 -0
- package/lib/vendor/qrcode/renderer/svg-tag.js +81 -0
- package/lib/vendor/qrcode/renderer/utils.js +99 -0
- package/package.json +64 -4
package/README.md
CHANGED
|
@@ -1,3 +1,87 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-plugin-console-oh · DSH 控制台(电脑侧插件)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
DSH 里的控制台面板:出 6 位配对码、起局域网服务、按需拉 cloudflared 隧道,
|
|
4
|
+
配套 **HarmonyOS NEXT 手机 App「DSH 控制台」**,随时随地查看会话、读对话、发消息、停生成。
|
|
5
|
+
|
|
6
|
+
## 功能
|
|
7
|
+
|
|
8
|
+
- **会话管理**:列会话、新建、归档/恢复/删除(走 DSH 原生回收站)、批量操作、重命名
|
|
9
|
+
- **对话**:完整回合流(含思考过程)、生成中插话、图片随消息发送、模式切换、模型目录
|
|
10
|
+
- **配对**:6 位配对码(15 分钟一次一换)/ 二维码一次性票据;「我的电脑」信任直连——设备密钥签名,token 失效免扫码重连
|
|
11
|
+
- **面板**:节点信息、双通道配对码(局域网/公网)、隧道开关与地址复制、异地配对开关、设备列表(含信任标记)
|
|
12
|
+
|
|
13
|
+
## 安装(桌面端)
|
|
14
|
+
|
|
15
|
+
**方式一 · 添加插件对话框**(推荐):DSH 插件页 → 添加插件 → 输入包名 `dsh-plugin-console-oh` → 安装 → 完全退出 DSH(含托盘)重启。
|
|
16
|
+
|
|
17
|
+
**方式二 · 命令行**(官方网页版 `dsh web`,或社区插件中心标准命令):
|
|
18
|
+
|
|
19
|
+
```powershell
|
|
20
|
+
dsh plugin --profile web add dsh-plugin-console-oh
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
**方式二(桌面 profile)**:桌面 profile 由应用独占管理,请在应用内「插件 → 添加插件」输入包名安装;或手动:
|
|
24
|
+
|
|
25
|
+
```powershell
|
|
26
|
+
cd ~/.dsh/profiles/desktop
|
|
27
|
+
pnpm add dsh-plugin-console-oh
|
|
28
|
+
# 再把 dsh-plugin-console-oh 加入 package.json 的 dsh.profile.bundles 数组,重启 DSH
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
**方式三 · 本地开发(改代码即时生效)**:
|
|
32
|
+
|
|
33
|
+
```powershell
|
|
34
|
+
dsh plugin --profile desktop add link:D:\path\to\dsh-console-oh\plugin
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
装完在 **设置 → DSH 控制台** 打开面板。
|
|
38
|
+
|
|
39
|
+
## 手机端
|
|
40
|
+
|
|
41
|
+
HarmonyOS NEXT 应用「DSH 控制台」:扫面板二维码或输 6 位配对码完成首次配对;
|
|
42
|
+
之后 token 过期/失效时,配对页点「我的电脑」即可用设备密钥签名免扫码重连。
|
|
43
|
+
|
|
44
|
+
## 文件
|
|
45
|
+
|
|
46
|
+
| 文件 | 作用 |
|
|
47
|
+
| --- | --- |
|
|
48
|
+
| `lib/index.js` | 宿主半边:sessionController → 手机窄接口,注册面板路由 |
|
|
49
|
+
| `lib/server.mjs` | HTTP 服务:配对、信任直连、鉴权、会话、指令 |
|
|
50
|
+
| `lib/tunnel.mjs` | cloudflared 下载与生命周期 |
|
|
51
|
+
| `lib/client.js` | 面板 UI(`window.__ModuleLoader__` 格式,无构建步骤) |
|
|
52
|
+
| `test/selftest.mjs` | 服务层自测 |
|
|
53
|
+
| `test/host-test.mjs` | 宿主半边自测 |
|
|
54
|
+
|
|
55
|
+
## 安全
|
|
56
|
+
|
|
57
|
+
- 默认只监听 `127.0.0.1`,公网走隧道;同 WiFi 直连要在面板手动打开「局域网访问」(那一段是明文 HTTP)
|
|
58
|
+
- 配对码一次性、15 分钟;同一来源错 10 次锁 15 分钟(按真实来源分桶)
|
|
59
|
+
- 访问码 192 bit,state.json 只存 sha256,恒定时间比较,30 天过期,面板可单台撤销
|
|
60
|
+
- 信任直连:手机端生成 ECC P-256 密钥对,电脑端只存公钥哈希;签名带 ±60s 时间窗与防重放缓存;踢掉设备即吊销信任;新设备首次公网连接必须先完成扫码验证
|
|
61
|
+
- 支持只读模式:手机只能读会话、停止生成,发不出消息
|
|
62
|
+
- 公网来源的 6 位码配对必须显式打开「异地配对」;二维码票据不受限(只出现在电脑屏幕上)
|
|
63
|
+
- 手机只能:列会话、读轮次、发消息、停止、新建、改名。没有文件读写、不接受客户端指定工作目录
|
|
64
|
+
- 落地页与 /health 不含主机名/内网 IP/端口;不返回 CORS 头;不接受 ?token=
|
|
65
|
+
- 面板路由只接受回环 Host,非回环一律 403
|
|
66
|
+
- cloudflared 下载后校验 Authenticode 签名(Cloudflare, Inc.),不符即删除并拒绝启动
|
|
67
|
+
|
|
68
|
+
## 跨平台
|
|
69
|
+
|
|
70
|
+
- 服务本体是纯 Node.js,跟随 DSH 桌面端运行(Windows / macOS / Linux)
|
|
71
|
+
- cloudflared 按平台自动下载:Windows amd64(ARM64 Windows 走系统 x64 模拟,官方无原生包)、macOS Intel/Apple Silicon(tgz 自动解包)、Linux amd64/arm64(便携裸二进制)
|
|
72
|
+
- 供应链校验:Windows 验 Authenticode、macOS 验 codesign(签名者必须 Cloudflare, Inc.),不符即删除拒绝启动;**Linux 无统一签名机制,走镜像下载时无本地校验**,介意者可在配置里指定 cloudflaredPath 用自备二进制
|
|
73
|
+
- 真机验证状态:Windows x64 全量验证;macOS / Linux 为代码级验证(test/matrix.mjs 平台矩阵 12 项)+ 待真机回归
|
|
74
|
+
- 鸿蒙电脑:插件本身纯 Node 可随宿主运行,但官方无 cloudflared 鸿蒙资产——局域网模式可用,隧道待宿主生态支持
|
|
75
|
+
|
|
76
|
+
## 开发
|
|
77
|
+
|
|
78
|
+
```powershell
|
|
79
|
+
node test/selftest.mjs # 服务层自测
|
|
80
|
+
node test/host-test.mjs # 宿主半边自测
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
`@deepseek-ai/*` peer 依赖均标 optional,独立开发/发布不需要私有仓库访问权。
|
|
84
|
+
|
|
85
|
+
## License
|
|
86
|
+
|
|
87
|
+
MIT
|
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# DSH 控制台 · 电脑侧插件
|
|
2
|
+
#
|
|
3
|
+
# 装法:DSH 侧栏 → 插件 → 添加插件 → 粘贴本目录的绝对路径
|
|
4
|
+
# 或命令行:dsh plugin --profile desktop add link:<本目录绝对路径>
|
|
5
|
+
#
|
|
6
|
+
# 配置(一般不用改)写在 profile 的 cordis.patch.yml 里,按 id 定向覆盖:
|
|
7
|
+
# - id: dsh-console-oh
|
|
8
|
+
# config:
|
|
9
|
+
# port: 8909 # 局域网服务端口
|
|
10
|
+
# name: "我的电脑" # App 上显示的节点名
|
|
11
|
+
# tunnel: false # 启动时是否自动拉 cloudflared 隧道
|
|
12
|
+
#
|
|
13
|
+
# 注意:loader 行只放在本文件里,不要在 profile 的 cordis.patch.yml 里重复 insert。
|
|
14
|
+
- insert:
|
|
15
|
+
- id: dsh-console-oh
|
|
16
|
+
name: './lib/index.js'
|
package/lib/client.js
ADDED
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
// 必须与 package.json 的 name 完全一致:rc.5 内核按包名建表,
|
|
3
|
+
// 收到的注册 id 不等于包名会被判为「loaded without registering」直接丢弃
|
|
4
|
+
id: "dsh-plugin-console-oh",
|
|
5
|
+
factory: (require) => {
|
|
6
|
+
var module = { exports: {} }
|
|
7
|
+
var exports = module.exports
|
|
8
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" })
|
|
9
|
+
|
|
10
|
+
const react = require("react")
|
|
11
|
+
const { useState, useEffect, useCallback } = react
|
|
12
|
+
const h = react.createElement
|
|
13
|
+
|
|
14
|
+
const inject = ["slots", "locale"]
|
|
15
|
+
|
|
16
|
+
const STATE = "/api/dsh-console-oh/state"
|
|
17
|
+
const NEWCODE = "/api/dsh-console-oh/newcode"
|
|
18
|
+
const TOGGLE = "/api/dsh-console-oh/toggle"
|
|
19
|
+
const TUNNEL = "/api/dsh-console-oh/tunnel"
|
|
20
|
+
const QR = "/api/dsh-console-oh/qr"
|
|
21
|
+
const SESSIONS = "/api/dsh-console-oh/sessions"
|
|
22
|
+
const TURNS = "/api/dsh-console-oh/turns"
|
|
23
|
+
const SEND = "/api/dsh-console-oh/send"
|
|
24
|
+
|
|
25
|
+
const CSS = `
|
|
26
|
+
.dco-wrap{display:flex;flex-direction:column;gap:12px;font-size:13px;line-height:1.6}
|
|
27
|
+
.dco-card{border:1px solid rgba(128,128,128,.22);border-radius:16px;padding:14px 14px 12px;background:rgba(128,128,128,.04)}
|
|
28
|
+
.dco-row{display:flex;align-items:center;justify-content:space-between;gap:10px}
|
|
29
|
+
.dco-h{font-size:12px;letter-spacing:.08em;text-transform:uppercase;opacity:.55;margin-bottom:6px}
|
|
30
|
+
.dco-name{font-size:15px;font-weight:600}
|
|
31
|
+
.dco-dot{display:inline-block;width:6px;height:6px;border-radius:50%;margin-right:6px;vertical-align:1px}
|
|
32
|
+
.dco-code{font:600 34px/1.2 ui-monospace,SFMono-Regular,Consolas,monospace;letter-spacing:.22em;padding:10px 0 4px}
|
|
33
|
+
.dco-sub{opacity:.6;font-size:12px}
|
|
34
|
+
.dco-btn{border:1px solid rgba(128,128,128,.3);background:transparent;color:inherit;border-radius:10px;
|
|
35
|
+
font-size:12px;padding:6px 12px;cursor:pointer;white-space:nowrap}
|
|
36
|
+
.dco-btn:hover{background:rgba(128,128,128,.12)}
|
|
37
|
+
.dco-btn[disabled]{opacity:.4;cursor:default}
|
|
38
|
+
.dco-btn.primary{background:rgba(76,141,255,.16);border-color:rgba(76,141,255,.5);color:#8ab4ff}
|
|
39
|
+
.dco-btn.danger{color:#f2635f;border-color:rgba(242,99,95,.35)}
|
|
40
|
+
.dco-mono{font:12px/1.5 ui-monospace,Consolas,monospace;word-break:break-all;opacity:.85}
|
|
41
|
+
.dco-tag{font-size:11px;padding:2px 8px;border-radius:999px;border:1px solid rgba(128,128,128,.3)}
|
|
42
|
+
.dco-tag.on{border-color:rgba(62,207,142,.55);color:#3ecf8e}
|
|
43
|
+
.dco-tag.off{opacity:.6}
|
|
44
|
+
.dco-tag.bad{border-color:rgba(242,99,95,.55);color:#f2635f}
|
|
45
|
+
.dco-list{display:flex;flex-direction:column;gap:6px;margin-top:6px}
|
|
46
|
+
.dco-dev{display:flex;justify-content:space-between;align-items:center;gap:8px;font-size:12px}
|
|
47
|
+
.dco-switch{width:38px;height:22px;border-radius:999px;border:1px solid rgba(128,128,128,.35);
|
|
48
|
+
background:transparent;position:relative;cursor:pointer;flex:0 0 auto}
|
|
49
|
+
.dco-switch i{position:absolute;top:2px;left:2px;width:16px;height:16px;border-radius:50%;
|
|
50
|
+
background:rgba(128,128,128,.6);transition:transform .16s ease,background .16s ease}
|
|
51
|
+
.dco-switch.on{border-color:rgba(76,141,255,.6);background:rgba(76,141,255,.18)}
|
|
52
|
+
.dco-switch.on i{transform:translateX(16px);background:#4c8dff}
|
|
53
|
+
.dco-note{opacity:.5;font-size:11.5px;line-height:1.6}
|
|
54
|
+
.dco-qr{display:flex;gap:14px;align-items:flex-start;margin-top:8px}
|
|
55
|
+
.dco-qrimg{width:126px;height:126px;flex:0 0 auto;border-radius:12px;background:#fff;padding:5px;display:block}
|
|
56
|
+
.dco-qrside{display:flex;flex-direction:column;gap:6px;min-width:0}
|
|
57
|
+
.dco-warnbox{margin-top:6px;padding:7px 9px;border-radius:9px;background:rgba(232,177,76,.12);border:1px solid rgba(232,177,76,.35);color:#e8b14c;font-size:11.5px;line-height:1.5}
|
|
58
|
+
.dco-qrfallback{width:126px;flex:0 0 auto;border-radius:12px;border:1px dashed rgba(128,128,128,.4);padding:10px;display:flex;flex-direction:column;gap:6px;justify-content:center}
|
|
59
|
+
.dco-hist{display:flex;flex-direction:column;gap:8px;margin-top:8px}
|
|
60
|
+
.dco-hrow{display:flex;align-items:center;gap:8px;padding:8px 10px;border-radius:10px;cursor:pointer;
|
|
61
|
+
border:1px solid rgba(128,128,128,.16);background:rgba(128,128,128,.05)}
|
|
62
|
+
.dco-hrow:hover{background:rgba(128,128,128,.12)}
|
|
63
|
+
.dco-htitle{flex:1;min-width:0;font-size:12.5px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
64
|
+
.dco-hbody{max-height:260px;overflow:auto;display:flex;flex-direction:column;gap:10px;
|
|
65
|
+
padding:10px;border-radius:10px;border:1px solid rgba(128,128,128,.16);background:rgba(0,0,0,.12)}
|
|
66
|
+
.dco-turn{display:flex;flex-direction:column;gap:4px}
|
|
67
|
+
.dco-tu{align-self:flex-end;max-width:86%;padding:6px 9px;border-radius:10px;background:rgba(76,141,255,.16);font-size:12.5px;white-space:pre-wrap}
|
|
68
|
+
.dco-ta{font-size:12.5px;white-space:pre-wrap;opacity:.92}
|
|
69
|
+
.dco-send{display:flex;gap:8px;margin-top:8px}
|
|
70
|
+
.dco-input{flex:1;min-height:34px;max-height:90px;resize:vertical;border-radius:10px;padding:7px 10px;
|
|
71
|
+
border:1px solid rgba(128,128,128,.3);background:transparent;color:inherit;font:inherit;font-size:12.5px}
|
|
72
|
+
.dco-swrow{display:flex;align-items:flex-start;justify-content:space-between;gap:12px;padding:9px 0}
|
|
73
|
+
.dco-swrow+.dco-swrow{border-top:1px solid rgba(128,128,128,.14)}
|
|
74
|
+
`
|
|
75
|
+
|
|
76
|
+
function useCss(id, text) {
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
try {
|
|
79
|
+
if (typeof document === "undefined" || !document.head) return
|
|
80
|
+
if (document.getElementById(id)) return
|
|
81
|
+
const el = document.createElement("style")
|
|
82
|
+
el.id = id
|
|
83
|
+
el.textContent = text
|
|
84
|
+
document.head.appendChild(el)
|
|
85
|
+
} catch (_) { }
|
|
86
|
+
}, [])
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function call(path, method, body) {
|
|
90
|
+
return fetch(path, {
|
|
91
|
+
method: method || "GET",
|
|
92
|
+
credentials: "same-origin",
|
|
93
|
+
cache: "no-store",
|
|
94
|
+
headers: body ? { "content-type": "application/json" } : undefined,
|
|
95
|
+
body: body ? JSON.stringify(body) : undefined
|
|
96
|
+
}).then((r) => r.json())
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function fmtLeft(exp) {
|
|
100
|
+
if (!exp) return ""
|
|
101
|
+
const left = Math.max(0, Math.floor((exp - Date.now()) / 1000))
|
|
102
|
+
const m = String(Math.floor(left / 60)).padStart(2, "0")
|
|
103
|
+
const s = String(left % 60).padStart(2, "0")
|
|
104
|
+
return m + ":" + s
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function day(ms) {
|
|
108
|
+
if (!ms) return "—"
|
|
109
|
+
const d = new Date(ms)
|
|
110
|
+
return (d.getMonth() + 1) + "-" + d.getDate()
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function Card(props) {
|
|
114
|
+
return h("div", { className: "dco-card" }, props.children)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function Switch(props) {
|
|
118
|
+
return h("button", {
|
|
119
|
+
className: "dco-switch" + (props.on ? " on" : ""),
|
|
120
|
+
onClick: props.onClick,
|
|
121
|
+
"aria-pressed": props.on ? "true" : "false"
|
|
122
|
+
}, h("i", null))
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function Panel() {
|
|
126
|
+
useCss("dco-css", CSS)
|
|
127
|
+
const [st, setSt] = useState(null)
|
|
128
|
+
const [err, setErr] = useState("")
|
|
129
|
+
const [busy, setBusy] = useState("")
|
|
130
|
+
const [tick, setTick] = useState(0)
|
|
131
|
+
const [qrKey, setQrKey] = useState(0)
|
|
132
|
+
const [qrErr, setQrErr] = useState(false)
|
|
133
|
+
const [hist, setHist] = useState(null)
|
|
134
|
+
const [openId, setOpenId] = useState("")
|
|
135
|
+
const [detail, setDetail] = useState(null)
|
|
136
|
+
const [draft, setDraft] = useState("")
|
|
137
|
+
const [sending, setSending] = useState(false)
|
|
138
|
+
|
|
139
|
+
const load = useCallback(() => {
|
|
140
|
+
call(STATE).then((j) => {
|
|
141
|
+
if (j && j.ok) { setSt(j); setErr("") } else setErr((j && j.error) || "读不到状态")
|
|
142
|
+
}).catch((e) => setErr(String(e && e.message || e)))
|
|
143
|
+
}, [])
|
|
144
|
+
|
|
145
|
+
useEffect(() => {
|
|
146
|
+
load()
|
|
147
|
+
loadHist()
|
|
148
|
+
const iv = setInterval(load, 3000)
|
|
149
|
+
const tv = setInterval(() => setTick((n) => n + 1), 1000)
|
|
150
|
+
return () => { clearInterval(iv); clearInterval(tv) }
|
|
151
|
+
}, [load])
|
|
152
|
+
|
|
153
|
+
const act = (name, path, body) => {
|
|
154
|
+
setBusy(name)
|
|
155
|
+
call(path, "POST", body || {})
|
|
156
|
+
.then((j) => { if (j && j.ok) setSt(j); else setErr((j && j.error) || "操作失败") })
|
|
157
|
+
.catch((e) => setErr(String(e && e.message || e)))
|
|
158
|
+
.then(() => setBusy(""))
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const loadHist = () => {
|
|
162
|
+
call(SESSIONS).then((j) => { if (j && j.ok) setHist(j.sessions || []) }).catch(() => { })
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const openSession = (id) => {
|
|
166
|
+
setOpenId(id)
|
|
167
|
+
setDetail(null)
|
|
168
|
+
call(TURNS + "?id=" + encodeURIComponent(id))
|
|
169
|
+
.then((j) => setDetail(j && j.ok ? j : { turns: [], error: (j && j.error) || "" }))
|
|
170
|
+
.catch(() => setDetail({ turns: [], error: "读不到会话" }))
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const sendHere = () => {
|
|
174
|
+
const text = String(draft || "").trim()
|
|
175
|
+
if (text === "" || sending) return
|
|
176
|
+
setSending(true)
|
|
177
|
+
call(SEND, "POST", { sessionId: openId, text })
|
|
178
|
+
.then((j) => {
|
|
179
|
+
if (j && j.ok) { setDraft(""); openSession(openId) }
|
|
180
|
+
else setErr((j && j.error) || "发送失败")
|
|
181
|
+
})
|
|
182
|
+
.catch((e) => setErr(String(e && e.message || e)))
|
|
183
|
+
.then(() => setSending(false))
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const copy = (text) => {
|
|
187
|
+
try { navigator.clipboard.writeText(text) } catch (_) { }
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (!st) {
|
|
191
|
+
return h("div", { className: "dco-wrap" }, h(Card, null, h("div", { className: "dco-sub" }, err || "正在读取…")))
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const tun = st.tunnel || { state: "idle", url: "", error: "" }
|
|
195
|
+
const tunnelUp = !!(tun.state === "up" && tun.url)
|
|
196
|
+
const lanNamed = Array.isArray(st.lanNamed) && st.lanNamed.length ? st.lanNamed : []
|
|
197
|
+
const qrSrc = QR + "?_=" + qrKey + "-" + String(st.publicUrl || "").slice(-6)
|
|
198
|
+
const noAddr = !tunnelUp && !st.lanAccess
|
|
199
|
+
|
|
200
|
+
return h("div", { className: "dco-wrap" },
|
|
201
|
+
|
|
202
|
+
// 抬头
|
|
203
|
+
h(Card, null,
|
|
204
|
+
h("div", { className: "dco-row" },
|
|
205
|
+
h("div", null,
|
|
206
|
+
h("div", { className: "dco-name" }, st.name),
|
|
207
|
+
h("div", { className: "dco-sub" }, "DSH 控制台 · v" + st.version + " · 端口 " + st.port)
|
|
208
|
+
),
|
|
209
|
+
h("div", { className: "dco-row" },
|
|
210
|
+
h("span", { className: "dco-tag on" }, "服务在线"),
|
|
211
|
+
h("span", { className: "dco-tag " + (tunnelUp ? "on" : "off") }, tunnelUp ? "公网已通" : "公网未开")
|
|
212
|
+
)
|
|
213
|
+
),
|
|
214
|
+
st.lanAccess
|
|
215
|
+
? h("div", { className: "dco-list" },
|
|
216
|
+
lanNamed.map((x) => h("div", { key: x.ip, className: "dco-mono" }, (x.iface ? x.iface + " · " : "") + "http://" + x.ip + ":" + st.port)))
|
|
217
|
+
: h("div", { className: "dco-sub", style: { marginTop: 6 } },
|
|
218
|
+
h("span", { className: "dco-mono" }, "127.0.0.1:" + st.port + " · 只监听本机"),
|
|
219
|
+
" 局域网已关闭,手机走隧道即可")
|
|
220
|
+
),
|
|
221
|
+
|
|
222
|
+
// 扫码配对
|
|
223
|
+
h(Card, null,
|
|
224
|
+
h("div", { className: "dco-row" },
|
|
225
|
+
h("div", { className: "dco-h" }, "扫码配对"),
|
|
226
|
+
h("button", {
|
|
227
|
+
className: "dco-btn primary",
|
|
228
|
+
onClick: () => { setQrErr(false); setQrKey((n) => n + 1) }
|
|
229
|
+
}, "换一张")
|
|
230
|
+
),
|
|
231
|
+
h("div", { className: "dco-qr" },
|
|
232
|
+
qrErr || noAddr
|
|
233
|
+
? h("div", { className: "dco-qrfallback" },
|
|
234
|
+
h("div", { className: "dco-name", style: { fontSize: 13 } }, noAddr ? "还没有可用地址" : "二维码没出来"),
|
|
235
|
+
h("div", { className: "dco-note" }, noAddr ? "先开通下面「公网访问」,再点「换一张」" : "宿主侧还是旧代码 —— 完全退出 DSH 再启动一次"))
|
|
236
|
+
: h("img", {
|
|
237
|
+
className: "dco-qrimg", src: qrSrc, alt: "配对二维码",
|
|
238
|
+
onError: () => setQrErr(true),
|
|
239
|
+
onLoad: () => setQrErr(false)
|
|
240
|
+
}),
|
|
241
|
+
h("div", { className: "dco-qrside" },
|
|
242
|
+
h("div", { className: "dco-name", style: { fontSize: 13 } }, "手机 App → 扫一扫"),
|
|
243
|
+
h("div", { className: "dco-mono" }, st.publicUrl || "—"),
|
|
244
|
+
h("div", { className: "dco-sub" }, "2 分钟过期、扫一次即作废;别截图外传,换地址后点「换一张」。"),
|
|
245
|
+
tunnelUp ? null : h("div", { className: "dco-warnbox" }, "当前不是公网地址,手机用流量连不上。先开通下面的「公网访问」。")
|
|
246
|
+
)
|
|
247
|
+
)
|
|
248
|
+
),
|
|
249
|
+
|
|
250
|
+
// 配对码:公网 / 局域网各一个,互不复用
|
|
251
|
+
h(Card, null,
|
|
252
|
+
h("div", { className: "dco-row" },
|
|
253
|
+
h("div", { className: "dco-h" }, "6 位配对码"),
|
|
254
|
+
h("div", { className: "dco-sub" }, "两入口各自独立")
|
|
255
|
+
),
|
|
256
|
+
(() => {
|
|
257
|
+
const codes = st.codes || {}
|
|
258
|
+
const block = (title, scope) => {
|
|
259
|
+
const rec = codes[scope] || {}
|
|
260
|
+
return h("div", { style: { marginTop: 12 } },
|
|
261
|
+
h("div", { className: "dco-row" },
|
|
262
|
+
h("div", { className: "dco-sub" }, title),
|
|
263
|
+
h("button", {
|
|
264
|
+
className: "dco-btn",
|
|
265
|
+
disabled: busy === ("code-" + scope),
|
|
266
|
+
onClick: () => act("code-" + scope, NEWCODE, { scope })
|
|
267
|
+
}, "换一个")
|
|
268
|
+
),
|
|
269
|
+
h("div", { className: "dco-code" }, rec.code || "— — — — — —"),
|
|
270
|
+
h("div", { className: "dco-sub" },
|
|
271
|
+
rec.expiresAt ? "剩余 " + fmtLeft(rec.expiresAt) + ",用掉即作废" : "点「换一个」生成新码")
|
|
272
|
+
)
|
|
273
|
+
}
|
|
274
|
+
return h("div", null, block("公网(走隧道)", "wan"), block("局域网(同一 Wi-Fi)", "lan"))
|
|
275
|
+
})()
|
|
276
|
+
),
|
|
277
|
+
|
|
278
|
+
// 公网隧道
|
|
279
|
+
h(Card, null,
|
|
280
|
+
h("div", { className: "dco-row" },
|
|
281
|
+
h("div", { className: "dco-h" }, "公网访问 · cloudflared"),
|
|
282
|
+
h("button", {
|
|
283
|
+
className: tunnelUp ? "dco-btn" : "dco-btn primary",
|
|
284
|
+
disabled: busy === "tunnel" || tun.state === "downloading" || tun.state === "starting",
|
|
285
|
+
onClick: () => act("tunnel", TUNNEL, { action: tunnelUp ? "stop" : "start" })
|
|
286
|
+
}, tunnelUp ? "停止" : tun.state === "downloading" ? "下载中…" : tun.state === "starting" ? "启动中…" : "开通")
|
|
287
|
+
),
|
|
288
|
+
tunnelUp
|
|
289
|
+
? h("div", null,
|
|
290
|
+
h("div", { className: "dco-mono", style: { marginTop: 6 } }, tun.url),
|
|
291
|
+
h("div", { className: "dco-row", style: { marginTop: 8 } },
|
|
292
|
+
h("button", { className: "dco-btn", onClick: () => copy(tun.url) }, "复制地址"),
|
|
293
|
+
h("button", { className: "dco-btn", onClick: load }, "刷新")
|
|
294
|
+
),
|
|
295
|
+
h("div", { className: "dco-note", style: { marginTop: 8 } }, "下次 DSH 启动会自动拉起隧道;不想这样就点「停止」。")
|
|
296
|
+
)
|
|
297
|
+
: h("div", { className: "dco-sub", style: { marginTop: 4 } },
|
|
298
|
+
tun.error ? "失败:" + tun.error : "手机不在同一 WiFi 时用它把服务暴露到公网,地址每次启动都会变。")
|
|
299
|
+
),
|
|
300
|
+
|
|
301
|
+
// 访问控制
|
|
302
|
+
h(Card, null,
|
|
303
|
+
h("div", { className: "dco-h" }, "访问控制"),
|
|
304
|
+
|
|
305
|
+
h("div", { className: "dco-swrow" },
|
|
306
|
+
h("div", null,
|
|
307
|
+
h("div", { style: { fontSize: 13 } }, "局域网访问"),
|
|
308
|
+
h("div", { className: "dco-sub" }, st.lanAccess ? "同 WiFi 的手机能直连(这一段是明文 HTTP)" : "只监听 127.0.0.1,流量只走隧道")
|
|
309
|
+
),
|
|
310
|
+
h(Switch, { on: !!st.lanAccess, onClick: () => act("lan", TOGGLE, { lanAccess: !st.lanAccess }) })
|
|
311
|
+
),
|
|
312
|
+
|
|
313
|
+
h("div", { className: "dco-swrow" },
|
|
314
|
+
h("div", null,
|
|
315
|
+
h("div", { style: { fontSize: 13 } }, "只读模式"),
|
|
316
|
+
h("div", { className: "dco-sub" }, st.readOnly ? "手机只能看会话、停止生成,发不出消息" : "手机可以发消息(等于能驱动这台电脑上的 agent)")
|
|
317
|
+
),
|
|
318
|
+
h(Switch, { on: !!st.readOnly, onClick: () => act("ro", TOGGLE, { readOnly: !st.readOnly }) })
|
|
319
|
+
),
|
|
320
|
+
|
|
321
|
+
h("div", { className: "dco-swrow" },
|
|
322
|
+
h("div", null,
|
|
323
|
+
h("div", { style: { fontSize: 13 } }, "异地配对"),
|
|
324
|
+
h("div", { className: "dco-sub" }, st.remotePair ? "公网来源也能用 6 位码配对" : "只允许二维码/局域网配对")
|
|
325
|
+
),
|
|
326
|
+
h(Switch, { on: !!st.remotePair, onClick: () => act("rp", TOGGLE, { remotePair: !st.remotePair }) })
|
|
327
|
+
),
|
|
328
|
+
|
|
329
|
+
h("div", { className: "dco-note", style: { marginTop: 8 } },
|
|
330
|
+
"异地配对打开期间,任何拿到公网地址的人都能试 6 位码(连续输错 5 次会锁 15 分钟)。配完就关。")
|
|
331
|
+
),
|
|
332
|
+
|
|
333
|
+
// 会话记录:列表 → 详情 → 继续对话
|
|
334
|
+
h(Card, null,
|
|
335
|
+
h("div", { className: "dco-row" },
|
|
336
|
+
h("div", { className: "dco-h" }, "会话记录"),
|
|
337
|
+
h("div", { className: "dco-row" },
|
|
338
|
+
openId !== "" ? h("button", {
|
|
339
|
+
className: "dco-btn",
|
|
340
|
+
onClick: () => { setOpenId(""); setDetail(null) }
|
|
341
|
+
}, "‹ 列表") : null,
|
|
342
|
+
h("button", { className: "dco-btn", onClick: loadHist }, "刷新")
|
|
343
|
+
)
|
|
344
|
+
),
|
|
345
|
+
openId === ""
|
|
346
|
+
? (hist === null
|
|
347
|
+
? h("div", { className: "dco-sub" }, "点「刷新」载入历史会话")
|
|
348
|
+
: (hist.length === 0
|
|
349
|
+
? h("div", { className: "dco-sub" }, "还没有会话")
|
|
350
|
+
: h("div", { className: "dco-hist" }, hist.slice(0, 12).map((it) =>
|
|
351
|
+
h("div", {
|
|
352
|
+
key: it.id,
|
|
353
|
+
className: "dco-hrow",
|
|
354
|
+
onClick: () => openSession(it.id)
|
|
355
|
+
},
|
|
356
|
+
h("span", { className: "dco-htitle" }, it.title || "未命名会话"),
|
|
357
|
+
it.running ? h("span", { className: "dco-tag on" }, "运行中") : null,
|
|
358
|
+
it.archived ? h("span", { className: "dco-tag off" }, "已归档") : null
|
|
359
|
+
)))))
|
|
360
|
+
: h("div", null,
|
|
361
|
+
h("div", { className: "dco-sub", style: { margin: "6px 0" } },
|
|
362
|
+
detail === null ? "读取中…" : (detail.title || "会话")),
|
|
363
|
+
h("div", { className: "dco-hbody" },
|
|
364
|
+
detail === null
|
|
365
|
+
? h("div", { className: "dco-sub" }, "读取中…")
|
|
366
|
+
: (detail.error
|
|
367
|
+
? h("div", { className: "dco-note", style: { color: "#f2635f" } }, detail.error)
|
|
368
|
+
: (detail.turns || []).slice(-12).map((t, i) =>
|
|
369
|
+
h("div", { key: i, className: "dco-turn" },
|
|
370
|
+
t.prompt ? h("div", { className: "dco-tu" }, t.prompt) : null,
|
|
371
|
+
t.response ? h("div", { className: "dco-ta" }, t.response) : null
|
|
372
|
+
)))),
|
|
373
|
+
h("div", { className: "dco-send" },
|
|
374
|
+
h("textarea", {
|
|
375
|
+
className: "dco-input",
|
|
376
|
+
placeholder: st.readOnly ? "只读模式下不能发消息" : "继续这个会话…",
|
|
377
|
+
value: draft,
|
|
378
|
+
onChange: (e) => setDraft(e.target.value)
|
|
379
|
+
}),
|
|
380
|
+
h("button", {
|
|
381
|
+
className: "dco-btn primary",
|
|
382
|
+
disabled: sending || st.readOnly,
|
|
383
|
+
onClick: sendHere
|
|
384
|
+
}, sending ? "发送中…" : "发送")
|
|
385
|
+
)
|
|
386
|
+
)
|
|
387
|
+
),
|
|
388
|
+
|
|
389
|
+
// 设备
|
|
390
|
+
h(Card, null,
|
|
391
|
+
h("div", { className: "dco-row" },
|
|
392
|
+
h("div", { className: "dco-h" }, "已配对设备"),
|
|
393
|
+
h("span", { className: "dco-tag " + (st.devices && st.devices.length ? "on" : "off") }, String((st.devices || []).length))
|
|
394
|
+
),
|
|
395
|
+
(st.devices && st.devices.length)
|
|
396
|
+
? h("div", { className: "dco-list" }, st.devices.map((d) =>
|
|
397
|
+
h("div", { key: d.id, className: "dco-dev" },
|
|
398
|
+
h("div", { style: { minWidth: 0 } },
|
|
399
|
+
h("div", null, d.label || "手机"),
|
|
400
|
+
h("div", { className: "dco-sub" }, "配对于 " + day(d.at) + " · 有效至 " + day(d.exp))
|
|
401
|
+
),
|
|
402
|
+
h("button", {
|
|
403
|
+
className: "dco-btn danger",
|
|
404
|
+
disabled: busy === "revoke",
|
|
405
|
+
onClick: () => act("revoke", TOGGLE, { deviceId: d.id })
|
|
406
|
+
}, "断开")
|
|
407
|
+
)))
|
|
408
|
+
: h("div", { className: "dco-sub" }, "还没有手机连过。"),
|
|
409
|
+
h("div", { className: "dco-note", style: { marginTop: 8 } },
|
|
410
|
+
"访问码只以 sha256 存在本机,30 天过期;手机丢了就在这里断开那一台。")
|
|
411
|
+
),
|
|
412
|
+
|
|
413
|
+
err ? h("div", { className: "dco-note", style: { color: "#f2635f" } }, err) : null
|
|
414
|
+
)
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
// rc.5 起内核按 generator 迭代 slot 注册(对照 dsh-vision-router 的写法),
|
|
418
|
+
// 旧式普通回调会被静默跳过——设置页就不出现「DSH 控制台」入口。
|
|
419
|
+
function PanelIcon() {
|
|
420
|
+
return h('div', {
|
|
421
|
+
style: {
|
|
422
|
+
width: '20px', height: '20px', display: 'flex', alignItems: 'center',
|
|
423
|
+
justifyContent: 'center', font: '700 11px ui-monospace, Consolas, monospace',
|
|
424
|
+
letterSpacing: '-1px'
|
|
425
|
+
}
|
|
426
|
+
}, '>_')
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
function apply(ctx) {
|
|
430
|
+
const slots = ctx.slots || (typeof ctx.get === "function" ? ctx.get("slots") : undefined)
|
|
431
|
+
if (!slots || typeof slots.inject !== "function") return
|
|
432
|
+
slots.inject("settings.section", function* () {
|
|
433
|
+
yield slots.register({
|
|
434
|
+
name: "settings.section",
|
|
435
|
+
id: "dsh-plugin-console-oh",
|
|
436
|
+
order: 36,
|
|
437
|
+
label: () => "DSH 控制台",
|
|
438
|
+
inject: () => ({})
|
|
439
|
+
}, Panel)
|
|
440
|
+
})
|
|
441
|
+
// 侧栏导航图标(旧宿主没有这个 slot,不渲染也无副作用)
|
|
442
|
+
slots.inject("settings.section.icon", function* () {
|
|
443
|
+
yield slots.register({ name: "settings.section.icon", id: "dsh-plugin-console-oh" }, PanelIcon)
|
|
444
|
+
})
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
exports.apply = apply
|
|
448
|
+
exports.inject = inject
|
|
449
|
+
return module.exports
|
|
450
|
+
}
|
|
451
|
+
})
|