@mcviseron/dsh-qq-bridge 0.2.1 → 0.3.1
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 +8 -0
- package/bot/.env.example +32 -0
- package/bot/bridge.py +339 -0
- package/bot/check_await.py +31 -0
- package/bot/main.py +4405 -0
- package/bot/panel.py +471 -0
- package/bot/probe_group.py +24 -0
- package/bot/requirements.txt +6 -0
- package/bot/run-bot.bat +23 -0
- package/bot/runtime_config.py +185 -0
- package/bot/stop-bot.bat +11 -0
- package/bot/test_bystander.py +48 -0
- package/bot/test_commands.py +149 -0
- package/bot/test_group_alias.py +149 -0
- package/bot/test_group_routing.py +241 -0
- package/bot/test_plan_b.py +153 -0
- package/bot/test_queue_drain.py +114 -0
- package/bot/test_quote.py +240 -0
- package/bot/test_stream_strict.py +84 -0
- package/bot/test_streaming.py +141 -0
- package/bot/test_turnid.py +80 -0
- package/bot/usage.mjs +175 -0
- package/lib/client.js +668 -17
- package/lib/index.js +205 -21
- package/lib/install.js +324 -0
- package/lib/server.js +17 -5
- package/package.json +5 -1
package/lib/client.js
CHANGED
|
@@ -12,6 +12,8 @@ window.__ModuleLoader__.load({
|
|
|
12
12
|
const React = require("react")
|
|
13
13
|
const h = React.createElement
|
|
14
14
|
const PANEL = "http://127.0.0.1:39062"
|
|
15
|
+
// 安装器在宿主插件里(Node 侧),不在机器人面板
|
|
16
|
+
const BRIDGE = "http://127.0.0.1:39061"
|
|
15
17
|
|
|
16
18
|
const T = {
|
|
17
19
|
page: { width: "100%", height: "100%", minHeight: 0, overflow: "auto", boxSizing: "border-box", padding: "24px clamp(16px,4vw,48px) 32px", color: "var(--dsw-alias-label-primary)", fontFamily: "var(--dsw-font-family, inherit)" },
|
|
@@ -30,9 +32,50 @@ window.__ModuleLoader__.load({
|
|
|
30
32
|
labelBox: { display: "grid", gap: 2, minWidth: 0 },
|
|
31
33
|
title: { fontSize: 13, color: "var(--dsw-alias-label-primary)" },
|
|
32
34
|
hint: { fontSize: 12, color: "var(--dsw-alias-label-tertiary)" },
|
|
35
|
+
tabs: { display: "flex", gap: 8, marginBottom: 4 },
|
|
36
|
+
tab: { padding: "6px 14px", borderRadius: 999, border: "1px solid var(--dsw-alias-border-l2)", background: "transparent", color: "var(--dsw-alias-label-secondary)", fontSize: 13, cursor: "pointer" },
|
|
37
|
+
tabActive: { background: "var(--dsw-alias-label-primary)", borderColor: "var(--dsw-alias-label-primary)", color: "var(--dsw-alias-bg-layer-3)" },
|
|
38
|
+
grid: { display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(220px, 1fr))", gap: 12 },
|
|
39
|
+
kpiRow: { display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(150px, 1fr))", gap: 12 },
|
|
40
|
+
kpi: { display: "grid", gap: 4, padding: "14px 16px", borderRadius: 12, border: "1px solid var(--dsw-alias-border-l2)", background: "var(--dsw-alias-bg-layer-1, rgba(255,255,255,0.04))" },
|
|
41
|
+
kpiLabel: { fontSize: 12, color: "var(--dsw-alias-label-tertiary)" },
|
|
42
|
+
kpiValue: { fontSize: 26, fontWeight: 650, letterSpacing: "-0.02em", color: "var(--dsw-alias-label-primary)", fontVariantNumeric: "tabular-nums" },
|
|
43
|
+
cardHead: { display: "flex", alignItems: "center", justifyContent: "space-between", gap: 10, marginBottom: 6 },
|
|
44
|
+
legend: { display: "flex", gap: 10, flexWrap: "wrap" },
|
|
45
|
+
legendItem: { display: "inline-flex", alignItems: "center", gap: 5, fontSize: 11, color: "var(--dsw-alias-label-tertiary)" },
|
|
46
|
+
legendDot: { width: 8, height: 8, borderRadius: 999, display: "inline-block" },
|
|
47
|
+
ringBox: { display: "grid", justifyItems: "center", gap: 4 },
|
|
48
|
+
ringLabel: { fontSize: 13, fontWeight: 600, color: "var(--dsw-alias-label-primary)" },
|
|
49
|
+
barRow: { display: "grid", gridTemplateColumns: "minmax(64px,auto) 1fr 34px", alignItems: "center", gap: 8, fontSize: 12, whiteSpace: "nowrap" },
|
|
50
|
+
barLabel: { color: "var(--dsw-alias-label-tertiary)" },
|
|
51
|
+
barTrack: { height: 8, borderRadius: 999, background: "var(--dsw-alias-border-l2, rgba(255,255,255,0.12))", overflow: "hidden" },
|
|
52
|
+
barFill: { height: "100%", borderRadius: 999 },
|
|
53
|
+
barValue: { textAlign: "right", color: "var(--dsw-alias-label-secondary)", fontVariantNumeric: "tabular-nums" },
|
|
54
|
+
eventRow: { display: "grid", gridTemplateColumns: "42px 62px 1fr", gap: 8, fontSize: 12, lineHeight: 1.5 },
|
|
55
|
+
eventTime: { color: "var(--dsw-alias-label-tertiary)", fontVariantNumeric: "tabular-nums" },
|
|
56
|
+
eventKind: { color: "var(--dsw-alias-state-business-primary, #2f6bff)" },
|
|
57
|
+
eventText: { color: "var(--dsw-alias-label-secondary)", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" },
|
|
58
|
+
footNote: { fontSize: 11, color: "var(--dsw-alias-label-tertiary)" },
|
|
59
|
+
memberRow: { display: "grid", gridTemplateColumns: "24px 1fr auto", alignItems: "center", gap: 8, fontSize: 12 },
|
|
60
|
+
memberAvatar: { width: 24, height: 24, borderRadius: 999, objectFit: "cover", display: "inline-block" },
|
|
61
|
+
memberName: { color: "var(--dsw-alias-label-secondary)", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" },
|
|
62
|
+
memberTail: { color: "var(--dsw-alias-label-tertiary)", fontVariantNumeric: "tabular-nums" },
|
|
63
|
+
memberList: { maxHeight: 172, overflowY: "scroll", display: "flex", flexDirection: "column", gap: 6, paddingRight: 4 },
|
|
64
|
+
eventList: { maxHeight: 200, overflowY: "scroll", display: "flex", flexDirection: "column", gap: 4, paddingRight: 4 },
|
|
65
|
+
chipRow: { display: "flex", flexWrap: "wrap", gap: 6 },
|
|
66
|
+
chip: { padding: "2px 8px", borderRadius: 999, border: "1px solid var(--dsw-alias-border-l2)", fontSize: 11, color: "var(--dsw-alias-label-secondary)" },
|
|
67
|
+
card: { display: "grid", gap: 8, padding: "14px 16px", borderRadius: 12, border: "1px solid var(--dsw-alias-border-l2)", background: "var(--dsw-alias-bg-layer-1, rgba(255,255,255,0.04))" },
|
|
68
|
+
cardTitle: { fontSize: 13, fontWeight: 600, color: "var(--dsw-alias-label-primary)" },
|
|
69
|
+
cardRow: { display: "flex", justifyContent: "space-between", gap: 10, fontSize: 12 },
|
|
70
|
+
cardKey: { color: "var(--dsw-alias-label-tertiary)" },
|
|
71
|
+
cardValue: { color: "var(--dsw-alias-label-secondary)", fontVariantNumeric: "tabular-nums" },
|
|
33
72
|
sectionTitle: { fontSize: 12, letterSpacing: "0.04em", color: "var(--dsw-alias-label-tertiary)", margin: "10px 0 2px" },
|
|
73
|
+
// 顶/底悬浮栏:状态与操作、保存按钮常驻,不用滑到最底下
|
|
74
|
+
stickyTop: { position: "sticky", top: 0, zIndex: 6, display: "grid", gap: 10, padding: "10px 0 12px", marginTop: -10, background: "linear-gradient(to bottom, rgba(22,24,30,0.97), rgba(22,24,30,0.88))", backdropFilter: "blur(12px)", WebkitBackdropFilter: "blur(12px)", borderBottom: "1px solid var(--dsw-alias-border-l2)" },
|
|
75
|
+
stickyBottom: { position: "sticky", bottom: 0, zIndex: 6, display: "flex", gap: 8, flexWrap: "wrap", alignItems: "center", padding: "10px 0", background: "linear-gradient(to top, rgba(22,24,30,0.97), rgba(22,24,30,0.88))", backdropFilter: "blur(12px)", WebkitBackdropFilter: "blur(12px)", borderTop: "1px solid var(--dsw-alias-border-l2)" },
|
|
34
76
|
input: { width: 132, padding: "5px 8px", border: "1px solid var(--dsw-alias-border-l2)", borderRadius: 6, background: "var(--dsw-alias-bg-layer-3)", color: "var(--dsw-alias-label-primary)", font: "inherit", textAlign: "right" },
|
|
35
77
|
inputWide: { width: 260, textAlign: "left" },
|
|
78
|
+
textarea: { width: "100%", minHeight: 120, padding: "8px 10px", border: "1px solid var(--dsw-alias-border-l2)", borderRadius: 6, background: "var(--dsw-alias-bg-layer-3)", color: "var(--dsw-alias-label-primary)", font: "inherit", lineHeight: 1.6, resize: "vertical", boxSizing: "border-box", textAlign: "left" },
|
|
36
79
|
btn: { padding: "6px 14px", border: "1px solid var(--dsw-alias-border-l2)", borderRadius: 6, background: "transparent", color: "var(--dsw-alias-label-primary)", font: "inherit", cursor: "pointer" },
|
|
37
80
|
btnPrimary: { background: "var(--dsw-alias-label-primary)", borderColor: "var(--dsw-alias-label-primary)", color: "var(--dsw-alias-bg-layer-3)" },
|
|
38
81
|
actions: { display: "flex", gap: 8, flexWrap: "wrap", alignItems: "center" },
|
|
@@ -87,9 +130,13 @@ window.__ModuleLoader__.load({
|
|
|
87
130
|
capture_enabled: ["允许截屏", "/截图、/窗口 是否可用"],
|
|
88
131
|
auto_group: ["自动分组(每个会话独立工作区)", "关闭则所有会话共用同一个工作目录"],
|
|
89
132
|
approval_inline_redraw: ["审批按钮就地重绘为“已允许”", "关闭后退回旧行为:额外发一条结论文字 + “已处理”卡片"],
|
|
133
|
+
kick_confirm: ["踢人二次审批", "开启后踢人前先在你的私聊弹一张确认卡片,点了才执行"],
|
|
134
|
+
interject_hook_only: ["插话只要命中钩子才判断", "开启后只有被点名/带问号/提到别名/长时间冷场才花一次判断;关闭则每攒够几条就判一次"],
|
|
135
|
+
judge_score_output: ["判断用打分制", "让模型先给 0~3 分的开口意愿,再按阈值决定发不发"],
|
|
136
|
+
persona_enabled: ["启用人设", "只在新会话的第一条消息里发一次;会话已有历史就不再重复"],
|
|
90
137
|
}
|
|
91
138
|
|
|
92
|
-
const SWITCHES = ["enabled","c2c_enabled","group_enabled","group_full_mode","group_at_only","md_auto","stream_enabled","ack_enabled","quote_enabled","capture_enabled","auto_group","approval_inline_redraw"]
|
|
139
|
+
const SWITCHES = ["enabled","c2c_enabled","group_enabled","group_full_mode","group_at_only","md_auto","stream_enabled","ack_enabled","quote_enabled","capture_enabled","auto_group","approval_inline_redraw","kick_confirm","interject_hook_only","judge_score_output","persona_enabled"]
|
|
93
140
|
.map(function (key) { return [key, LABELS[key][0], LABELS[key][1]] })
|
|
94
141
|
|
|
95
142
|
// 静默时段:开始/结束时间 + 最右侧开关,并实时显示"当前是否静默、下次切换"
|
|
@@ -120,15 +167,23 @@ window.__ModuleLoader__.load({
|
|
|
120
167
|
["image_max_mb","图片上限(MB)",1,20], ["rate_limit_per_hour","每会话每小时上限(0=不限)",0,240],
|
|
121
168
|
["stream_interval_ms","流式节流(毫秒)",50,2000], ["quote_context_chars","引用原文上限(字)",50,2000],
|
|
122
169
|
["pool_ttl_s","消息池保留(秒)",60,86400], ["pool_max","消息池上限(条)",10,1000],
|
|
170
|
+
["metrics_keep_days","仪表盘数据保留(天)",1,365], ["interject_cold_s","冷场判定(秒,超过则有钩子)",60,7200],
|
|
171
|
+
["send_file_timeout_s","发文件超时(秒)",10,300], ["stream_retry_s","流式降级后暂停(秒)",10,3600],
|
|
172
|
+
["judge_join_threshold","开口阈值(0~3,越大越安静)",0,3],
|
|
173
|
+
["judge_silent_streak","连续沉默几次后自动降一档",0,20],
|
|
174
|
+
["judge_force_per_hour","每小时最多几次降档补开口",0,5],
|
|
175
|
+
]
|
|
176
|
+
|
|
177
|
+
// 凭据放最前面:装机器人、改 AppID 都在第一屏
|
|
178
|
+
const CREDENTIALS = [
|
|
179
|
+
["appid", "APPID(开放平台的机器人 AppID)"],
|
|
180
|
+
["appsecret", "APPSECRET(留空=不变;打码值不会被写入)"],
|
|
123
181
|
]
|
|
124
182
|
|
|
125
183
|
const TEXTS = [
|
|
126
184
|
["group_allowlist","群白名单(openid,逗号分隔)"],
|
|
127
185
|
["c2c_allowlist","私聊白名单(同上)"], ["bot_aliases","群内别名(逗号分隔)"],
|
|
128
|
-
["appid","APPID(留空=用 config.json)"],
|
|
129
|
-
["appsecret","APPSECRET(留空=不变,需重启)"],
|
|
130
186
|
["auto_group_root","自动分组根目录(如 D:\\dsh-qqbot-temp)"],
|
|
131
|
-
,
|
|
132
187
|
]
|
|
133
188
|
|
|
134
189
|
function QQBridgePage() {
|
|
@@ -139,6 +194,17 @@ window.__ModuleLoader__.load({
|
|
|
139
194
|
const [logs, setLogs] = React.useState([])
|
|
140
195
|
const [paused, setPaused] = React.useState(false)
|
|
141
196
|
const [follow, setFollow] = React.useState(true)
|
|
197
|
+
const [tab, setTab] = React.useState("settings")
|
|
198
|
+
const [dash, setDash] = React.useState(null)
|
|
199
|
+
const [dashRange, setDashRange] = React.useState("hour")
|
|
200
|
+
const [install, setInstall] = React.useState(null)
|
|
201
|
+
const [installNote, setInstallNote] = React.useState("")
|
|
202
|
+
const [stickers, setStickers] = React.useState([])
|
|
203
|
+
const [stickerNote, setStickerNote] = React.useState("")
|
|
204
|
+
const [stickerDir, setStickerDir] = React.useState("")
|
|
205
|
+
const [renameFile, setRenameFile] = React.useState("")
|
|
206
|
+
const [renameValue, setRenameValue] = React.useState("")
|
|
207
|
+
const [deleteFile, setDeleteFile] = React.useState("")
|
|
142
208
|
const logRef = React.useRef(null)
|
|
143
209
|
React.useEffect(function () {
|
|
144
210
|
const node = logRef.current
|
|
@@ -155,6 +221,58 @@ window.__ModuleLoader__.load({
|
|
|
155
221
|
}, [call])
|
|
156
222
|
|
|
157
223
|
React.useEffect(function () { load() }, [load])
|
|
224
|
+
|
|
225
|
+
// 装环境的状态轮询必须和其它 hook 一样在提前 return 之前声明,否则 hook 数量会变
|
|
226
|
+
const installCall = async function (body) {
|
|
227
|
+
const response = await fetch(BRIDGE + "/install", {
|
|
228
|
+
method: "POST",
|
|
229
|
+
headers: { "content-type": "application/json", "x-qqbridge-install": "1" },
|
|
230
|
+
body: JSON.stringify(body || {}),
|
|
231
|
+
})
|
|
232
|
+
return await response.json()
|
|
233
|
+
}
|
|
234
|
+
// 挂载时读一次;running 翻成 true 后持续轮询(首次挂载 running=false,旧写法会直接停掉不再更新)
|
|
235
|
+
const installRunning = install !== null && install.running === true
|
|
236
|
+
React.useEffect(function () {
|
|
237
|
+
let stop = false
|
|
238
|
+
const tick = async function () {
|
|
239
|
+
try {
|
|
240
|
+
const state = await installCall({ action: "status" })
|
|
241
|
+
if (stop) return
|
|
242
|
+
setInstall(state)
|
|
243
|
+
if (state.running === true) setTimeout(tick, 1000)
|
|
244
|
+
} catch (error) {
|
|
245
|
+
if (!stop) setInstallNote("连不上宿主插件(39061),确认插件已加载")
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
void tick()
|
|
249
|
+
return function () { stop = true }
|
|
250
|
+
}, [installRunning])
|
|
251
|
+
React.useEffect(function () {
|
|
252
|
+
if (tab !== "stickers") return undefined
|
|
253
|
+
let stop = false
|
|
254
|
+
call("/api/stickers").then(function (data) {
|
|
255
|
+
if (stop) return
|
|
256
|
+
setStickers(Array.isArray(data.stickers) ? data.stickers : [])
|
|
257
|
+
setStickerDir(String(data.dir || ""))
|
|
258
|
+
}).catch(function () { if (!stop) setStickerNote("表情包目录不可达") })
|
|
259
|
+
return function () { stop = true }
|
|
260
|
+
}, [tab, call])
|
|
261
|
+
React.useEffect(function () {
|
|
262
|
+
if (tab !== "dashboard") return undefined
|
|
263
|
+
let stop = false
|
|
264
|
+
const tick = async function () {
|
|
265
|
+
try {
|
|
266
|
+
const data = await call("/api/dashboard?range=" + dashRange)
|
|
267
|
+
if (!stop) setDash(data)
|
|
268
|
+
} catch (error) {
|
|
269
|
+
if (!stop) setDash({ offline: true })
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
tick()
|
|
273
|
+
const timer = setInterval(tick, 5000)
|
|
274
|
+
return function () { stop = true; clearInterval(timer) }
|
|
275
|
+
}, [tab, call, dashRange])
|
|
158
276
|
React.useEffect(function () {
|
|
159
277
|
const timer = setInterval(load, 8000)
|
|
160
278
|
return function () { clearInterval(timer) }
|
|
@@ -176,7 +294,8 @@ window.__ModuleLoader__.load({
|
|
|
176
294
|
}, [call, paused])
|
|
177
295
|
|
|
178
296
|
if (state !== null && state.offline) {
|
|
179
|
-
return h("div", { style: T.page },
|
|
297
|
+
return h("div", { style: T.page },
|
|
298
|
+
h("div", { style: T.inner },
|
|
180
299
|
h("div", { style: T.title }, "机器人的设置服务没有运行"),
|
|
181
300
|
h("div", { style: T.hint }, "用 bot\\run-bot.bat 启动一次(或 python -u main.py --supervise),再点重试。"),
|
|
182
301
|
h("div", { style: T.actions }, h("button", { style: T.btn, onClick: load }, "重试"))))
|
|
@@ -199,26 +318,517 @@ window.__ModuleLoader__.load({
|
|
|
199
318
|
catch (error) { setMessage("保存失败") }
|
|
200
319
|
setBusy(false)
|
|
201
320
|
}
|
|
321
|
+
// 装环境:POST 给宿主插件的 /install,再轮询进度
|
|
322
|
+
const startInstall = async function () {
|
|
323
|
+
setInstallNote("")
|
|
324
|
+
try {
|
|
325
|
+
// 面板回传的 AppSecret 是打码值(pHjC****N6),别把它当真的传下去
|
|
326
|
+
const rawSecret = String(value("appsecret") === undefined ? "" : value("appsecret"))
|
|
327
|
+
const started = await installCall({
|
|
328
|
+
action: "start",
|
|
329
|
+
appid: value("appid"),
|
|
330
|
+
appsecret: rawSecret.indexOf("****") >= 0 ? "" : rawSecret,
|
|
331
|
+
autoGroupRoot: value("auto_group_root"),
|
|
332
|
+
})
|
|
333
|
+
if (started.ok !== true) { setInstallNote("启动安装失败:" + (started.error || "未知错误")); return }
|
|
334
|
+
setInstall(started.state || null)
|
|
335
|
+
} catch (error) {
|
|
336
|
+
setInstallNote("连不上宿主插件(39061),确认插件已加载")
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
202
340
|
const manage = async function (action) {
|
|
203
341
|
setBusy(true)
|
|
204
342
|
try { const result = await call("/api/manage", { method: "POST", body: JSON.stringify({ action: action }) }); setMessage(result.message || action); await load() }
|
|
205
343
|
catch (error) { setMessage("操作失败") }
|
|
206
344
|
setBusy(false)
|
|
207
345
|
}
|
|
346
|
+
|
|
347
|
+
const SCROLLBAR_CSS = [
|
|
348
|
+
'[data-qq-scroll]::-webkit-scrollbar{width:9px;height:9px}',
|
|
349
|
+
'[data-qq-scroll]::-webkit-scrollbar-track{background:rgba(0,0,0,0.04);border-radius:999px}',
|
|
350
|
+
'[data-qq-scroll]::-webkit-scrollbar-thumb{background:rgba(120,130,145,0.55);border-radius:999px;border:2px solid transparent;background-clip:padding-box}',
|
|
351
|
+
'[data-qq-scroll]::-webkit-scrollbar-thumb:hover{background:rgba(120,130,145,0.8);background-clip:padding-box}',
|
|
352
|
+
].join('')
|
|
353
|
+
|
|
354
|
+
function bucketPlan(range) {
|
|
355
|
+
const now = Math.floor(Date.now() / 1000)
|
|
356
|
+
if (range === "today") {
|
|
357
|
+
const midnight = new Date(now * 1000)
|
|
358
|
+
midnight.setHours(0, 0, 0, 0)
|
|
359
|
+
const start = Math.floor(midnight.getTime() / 1000)
|
|
360
|
+
return { start: start, step: 60, count: Math.min(1440, Math.ceil((now - start) / 60) + 1) }
|
|
361
|
+
}
|
|
362
|
+
if (range === "7d") {
|
|
363
|
+
const step = 30 * 60
|
|
364
|
+
const start = Math.floor((now - 7 * 86400) / step) * step
|
|
365
|
+
return { start: start, step: step, count: Math.ceil((now - start) / step) + 1 }
|
|
366
|
+
}
|
|
367
|
+
const start = Math.floor((now - 60 * 60) / 60) * 60
|
|
368
|
+
return { start: start, step: 60, count: 60 }
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function buildSeries(raw, keys, range) {
|
|
372
|
+
const plan = bucketPlan(range)
|
|
373
|
+
const byTime = new Map()
|
|
374
|
+
;(raw || []).forEach(function (row) {
|
|
375
|
+
const bucket = Math.floor(Number(row.t) / plan.step) * plan.step
|
|
376
|
+
const cell = byTime.get(bucket) || {}
|
|
377
|
+
keys.forEach(function (key) { cell[key] = (cell[key] || 0) + Number(row[key] || 0) })
|
|
378
|
+
byTime.set(bucket, cell)
|
|
379
|
+
})
|
|
380
|
+
return Array.from({ length: plan.count }, function (_, index) {
|
|
381
|
+
const t = plan.start + index * plan.step
|
|
382
|
+
const cell = byTime.get(t) || {}
|
|
383
|
+
const point = { t: t }
|
|
384
|
+
keys.forEach(function (key) { point[key] = Number(cell[key] || 0) })
|
|
385
|
+
return point
|
|
386
|
+
})
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
function chartTick(tSec, spanSec) {
|
|
390
|
+
const d = new Date(Number(tSec) * 1000)
|
|
391
|
+
const pad = function (n) { return ("0" + n).slice(-2) }
|
|
392
|
+
if (spanSec > 86400) return (d.getMonth() + 1) + "-" + pad(d.getDate()) + " " + pad(d.getHours()) + "h"
|
|
393
|
+
return pad(d.getHours()) + ":" + pad(d.getMinutes())
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
function areaChart(rawPoints, keys, colors) {
|
|
397
|
+
// 7 天区间会产生上万条分钟点:抽稀到 ≤1000 条,形状不变,重绘不卡
|
|
398
|
+
let points = rawPoints
|
|
399
|
+
if (points.length > 1000) {
|
|
400
|
+
const stride = Math.ceil(points.length / 1000)
|
|
401
|
+
points = points.filter(function (_point, index) { return index % stride === 0 || index === points.length - 1 })
|
|
402
|
+
}
|
|
403
|
+
const width = 560
|
|
404
|
+
const height = 150
|
|
405
|
+
const left = 30
|
|
406
|
+
const right = 8
|
|
407
|
+
const top = 8
|
|
408
|
+
const bottom = 20
|
|
409
|
+
const plotW = width - left - right
|
|
410
|
+
const plotH = height - top - bottom
|
|
411
|
+
let max = 1
|
|
412
|
+
points.forEach(function (point) {
|
|
413
|
+
keys.forEach(function (key) { if (point[key] > max) max = point[key] })
|
|
414
|
+
})
|
|
415
|
+
const nice = Math.max(1, Math.ceil(max / 2) * 2)
|
|
416
|
+
const stamp = function (point) { return Number(point.t) || 0 }
|
|
417
|
+
let tMin = points.length ? Math.min.apply(null, points.map(stamp)) : 0
|
|
418
|
+
let tMax = points.length ? Math.max.apply(null, points.map(stamp)) : 60
|
|
419
|
+
if (tMax - tMin < 60) tMax = tMin + 60
|
|
420
|
+
const xAt = function (point) { return left + ((stamp(point) - tMin) / (tMax - tMin)) * plotW }
|
|
421
|
+
const yAt = function (value) { return top + plotH - ((Number(value) || 0) / nice) * plotH }
|
|
422
|
+
const children = [
|
|
423
|
+
h("rect", { key: "bg", x: 0, y: 0, width: width, height: height, fill: "transparent" }),
|
|
424
|
+
]
|
|
425
|
+
;[nice, Math.round(nice / 2), 0].forEach(function (value, index) {
|
|
426
|
+
const y = yAt(value)
|
|
427
|
+
children.push(h("line", {
|
|
428
|
+
key: "gy" + index, x1: left, y1: y, x2: left + plotW, y2: y,
|
|
429
|
+
stroke: "var(--dsw-alias-border-l2, #e3e6ea)", strokeWidth: 0.5,
|
|
430
|
+
}))
|
|
431
|
+
children.push(h("text", {
|
|
432
|
+
key: "gyt" + index, x: left - 5, y: y + 3, textAnchor: "end", fontSize: 9,
|
|
433
|
+
fill: "var(--dsw-alias-label-tertiary, #8b929c)",
|
|
434
|
+
}, String(value)))
|
|
435
|
+
})
|
|
436
|
+
const spanSec = tMax - tMin
|
|
437
|
+
for (let i = 0; i <= 4; i += 1) {
|
|
438
|
+
const x = left + (plotW / 4) * i
|
|
439
|
+
const tickTime = tMin + (spanSec / 4) * i
|
|
440
|
+
children.push(h("line", {
|
|
441
|
+
key: "gx" + i, x1: x, y1: top + plotH, x2: x, y2: top + plotH + 3,
|
|
442
|
+
stroke: "var(--dsw-alias-border-l3, #cfd4da)", strokeWidth: 0.5,
|
|
443
|
+
}))
|
|
444
|
+
children.push(h("text", {
|
|
445
|
+
key: "gxt" + i, x: x, y: height - 6,
|
|
446
|
+
textAnchor: i === 0 ? "start" : (i === 4 ? "end" : "middle"), fontSize: 9,
|
|
447
|
+
fill: "var(--dsw-alias-label-tertiary, #8b929c)",
|
|
448
|
+
}, chartTick(tickTime, spanSec)))
|
|
449
|
+
}
|
|
450
|
+
keys.forEach(function (key) {
|
|
451
|
+
const coords = points.map(function (point) {
|
|
452
|
+
return [xAt(point).toFixed(1), yAt(point[key]).toFixed(1)]
|
|
453
|
+
})
|
|
454
|
+
if (!coords.length) return
|
|
455
|
+
if (coords.length === 1) {
|
|
456
|
+
children.push(h("circle", { key: "p" + key, cx: coords[0][0], cy: coords[0][1], r: 2.5, fill: colors[key] }))
|
|
457
|
+
return
|
|
458
|
+
}
|
|
459
|
+
const d = coords.map(function (pair, index) {
|
|
460
|
+
return (index === 0 ? "M" : "L") + pair[0] + " " + pair[1]
|
|
461
|
+
}).join(" ")
|
|
462
|
+
const baseline = (top + plotH).toFixed(1)
|
|
463
|
+
children.push(h("path", {
|
|
464
|
+
key: "a" + key,
|
|
465
|
+
d: d + " L" + coords[coords.length - 1][0] + " " + baseline + " L" + coords[0][0] + " " + baseline + " Z",
|
|
466
|
+
fill: colors[key], opacity: 0.14,
|
|
467
|
+
}))
|
|
468
|
+
children.push(h("path", {
|
|
469
|
+
key: "l" + key, d: d, fill: "none", stroke: colors[key], strokeWidth: 2,
|
|
470
|
+
strokeLinejoin: "round", strokeLinecap: "round",
|
|
471
|
+
}))
|
|
472
|
+
})
|
|
473
|
+
return h("svg", { viewBox: "0 0 " + width + " " + height, style: { width: "100%", height: 150, display: "block" } }, children)
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
function ring(ratio, label, detail, color) {
|
|
477
|
+
const value = Math.max(0, Math.min(1, Number(ratio) || 0))
|
|
478
|
+
const radius = 26
|
|
479
|
+
const circumference = 2 * Math.PI * radius
|
|
480
|
+
const filled = circumference * value
|
|
481
|
+
return h("div", { style: T.ringBox },
|
|
482
|
+
h("svg", { viewBox: "0 0 72 72", style: { width: 72, height: 72 } },
|
|
483
|
+
h("circle", { cx: 36, cy: 36, r: radius, fill: "none", stroke: "var(--dsw-alias-border-l2, rgba(255,255,255,0.16))", strokeWidth: 7 }),
|
|
484
|
+
h("circle", {
|
|
485
|
+
cx: 36, cy: 36, r: radius, fill: "none", stroke: color, strokeWidth: 7, strokeLinecap: "round",
|
|
486
|
+
strokeDasharray: filled.toFixed(1) + " " + circumference.toFixed(1),
|
|
487
|
+
transform: "rotate(-90 36 36)",
|
|
488
|
+
}),
|
|
489
|
+
h("text", { x: 36, y: 41, textAnchor: "middle", fontSize: 15, fill: "var(--dsw-alias-label-primary)", fontWeight: 600 }, Math.round(value * 100) + "%")),
|
|
490
|
+
h("div", { style: T.ringLabel }, label),
|
|
491
|
+
h("div", { style: T.hint }, detail))
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
function kpi(label, value, sub) {
|
|
495
|
+
return h("div", { style: T.kpi },
|
|
496
|
+
h("div", { style: T.kpiLabel }, label),
|
|
497
|
+
h("div", { style: T.kpiValue }, value),
|
|
498
|
+
sub ? h("div", { style: T.hint }, sub) : null)
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
function barRow(label, value, max, color) {
|
|
502
|
+
const width = max > 0 ? Math.round((value / max) * 100) : 0
|
|
503
|
+
return h("div", { key: label, style: T.barRow },
|
|
504
|
+
h("span", { style: T.barLabel }, label),
|
|
505
|
+
h("div", { style: T.barTrack },
|
|
506
|
+
h("div", { style: Object.assign({}, T.barFill, { width: width + "%", background: color }) })),
|
|
507
|
+
h("span", { style: T.barValue }, String(value)))
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
function chartCard(title, legend, body) {
|
|
511
|
+
return h("div", { style: T.card },
|
|
512
|
+
h("div", { style: T.cardHead },
|
|
513
|
+
h("span", { style: T.cardTitle }, title),
|
|
514
|
+
h("span", { style: T.legend }, (legend || []).map(function (item) {
|
|
515
|
+
return h("span", { key: item.label, style: T.legendItem },
|
|
516
|
+
h("span", { style: Object.assign({}, T.legendDot, { background: item.color }) }),
|
|
517
|
+
item.label)
|
|
518
|
+
}))),
|
|
519
|
+
body)
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
const reloadStickers = async function () {
|
|
523
|
+
try {
|
|
524
|
+
const data = await call("/api/stickers")
|
|
525
|
+
setStickers(Array.isArray(data.stickers) ? data.stickers : [])
|
|
526
|
+
setStickerDir(String(data.dir || ""))
|
|
527
|
+
} catch (error) { setStickerNote("表情包目录不可达") }
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
const uploadSticker = function (event) {
|
|
531
|
+
const file = event.target.files && event.target.files[0]
|
|
532
|
+
if (!file) return
|
|
533
|
+
if (file.size > 4 * 1024 * 1024) { setStickerNote("图片超过 4MB"); return }
|
|
534
|
+
const reader = new FileReader()
|
|
535
|
+
reader.onload = async function () {
|
|
536
|
+
const name = String(file.name || "sticker").replace(/\.[^.]+$/, "")
|
|
537
|
+
try {
|
|
538
|
+
const result = await call("/api/stickers", { method: "POST", body: JSON.stringify({ action: "upload", name: name, data: String(reader.result) }) })
|
|
539
|
+
setStickerNote(result.ok ? "已上传:" + name : "上传失败:" + (result.error || ""))
|
|
540
|
+
await reloadStickers()
|
|
541
|
+
} catch (error) { setStickerNote("上传失败") }
|
|
542
|
+
}
|
|
543
|
+
reader.readAsDataURL(file)
|
|
544
|
+
event.target.value = ""
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
const stickerAction = async function (action, name, extra) {
|
|
548
|
+
try {
|
|
549
|
+
const result = await call("/api/stickers", { method: "POST", body: JSON.stringify(Object.assign({ action: action, name: name }, extra || {})) })
|
|
550
|
+
setStickerNote(result.ok ? (action === "delete" ? "已删除:" + name : "已改名") : "操作失败:" + (result.error || ""))
|
|
551
|
+
await reloadStickers()
|
|
552
|
+
} catch (error) { setStickerNote("操作失败") }
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
function stickersView() {
|
|
556
|
+
return h("div", { style: { display: "grid", gap: 14 } },
|
|
557
|
+
h("div", { style: T.actions },
|
|
558
|
+
h("label", { style: Object.assign({}, T.btn, T.btnPrimary, { cursor: "pointer" }) },
|
|
559
|
+
"上传表情包",
|
|
560
|
+
h("input", { type: "file", accept: "image/*", style: { display: "none" }, onChange: uploadSticker })),
|
|
561
|
+
h("button", { style: T.btn, onClick: reloadStickers }, "刷新"),
|
|
562
|
+
h("span", { style: T.hint }, stickers.length + " 个 · " + (stickerDir || "assets/stickers"))),
|
|
563
|
+
stickerNote ? h("div", { style: T.hint }, stickerNote) : null,
|
|
564
|
+
h("div", { style: T.grid },
|
|
565
|
+
...(stickers.length === 0
|
|
566
|
+
? [h("div", { style: T.card }, h("div", { style: T.hint }, "还没有表情包,点「上传表情包」加一个"))]
|
|
567
|
+
: stickers.map(function (item) {
|
|
568
|
+
return h("div", { key: item.file, style: Object.assign({}, T.card, { justifyItems: "center" }) },
|
|
569
|
+
h("img", {
|
|
570
|
+
src: PANEL + "/api/stickers?file=" + encodeURIComponent(item.file),
|
|
571
|
+
alt: item.name,
|
|
572
|
+
style: { width: "100%", maxHeight: 120, objectFit: "contain", borderRadius: 8 },
|
|
573
|
+
}),
|
|
574
|
+
renameFile === item.file
|
|
575
|
+
? h("div", { style: { display: "grid", gap: 6, width: "100%" } },
|
|
576
|
+
h("input", {
|
|
577
|
+
style: Object.assign({}, T.input, { width: "100%", textAlign: "center" }),
|
|
578
|
+
value: renameValue,
|
|
579
|
+
autoFocus: true,
|
|
580
|
+
onChange: function (event) { setRenameValue(event.target.value) },
|
|
581
|
+
onKeyDown: function (event) {
|
|
582
|
+
if (event.key === "Enter" && renameValue.trim() && renameValue.trim() !== item.name) {
|
|
583
|
+
stickerAction("rename", item.name, { to: renameValue.trim() })
|
|
584
|
+
setRenameFile("")
|
|
585
|
+
}
|
|
586
|
+
if (event.key === "Escape") setRenameFile("")
|
|
587
|
+
},
|
|
588
|
+
}),
|
|
589
|
+
h("div", { style: T.actions },
|
|
590
|
+
h("button", {
|
|
591
|
+
style: Object.assign({}, T.btn, T.btnPrimary),
|
|
592
|
+
onClick: function () {
|
|
593
|
+
const next = renameValue.trim()
|
|
594
|
+
if (!next || next === item.name) { setRenameFile(""); return }
|
|
595
|
+
stickerAction("rename", item.name, { to: next })
|
|
596
|
+
setRenameFile("")
|
|
597
|
+
},
|
|
598
|
+
}, "保存"),
|
|
599
|
+
h("button", { style: T.btn, onClick: function () { setRenameFile("") } }, "取消")))
|
|
600
|
+
: h("div", { style: T.cardTitle }, item.name),
|
|
601
|
+
h("div", { style: T.hint }, Math.round(item.bytes / 1024) + " KB"),
|
|
602
|
+
h("div", { style: T.actions },
|
|
603
|
+
h("button", {
|
|
604
|
+
style: T.btn,
|
|
605
|
+
onClick: function () {
|
|
606
|
+
const syntax = "[[sticker: " + item.name + "]]"
|
|
607
|
+
try { navigator.clipboard.writeText(syntax) ; setStickerNote("已复制 " + syntax) } catch (error) { setStickerNote(syntax) }
|
|
608
|
+
},
|
|
609
|
+
}, "复制语法"),
|
|
610
|
+
h("button", {
|
|
611
|
+
style: T.btn,
|
|
612
|
+
onClick: function () {
|
|
613
|
+
setRenameFile(item.file)
|
|
614
|
+
setRenameValue(item.name)
|
|
615
|
+
setStickerNote("")
|
|
616
|
+
},
|
|
617
|
+
}, "改名"),
|
|
618
|
+
h("button", {
|
|
619
|
+
style: deleteFile === item.file ? Object.assign({}, T.btn, { color: "#ef4444", borderColor: "#ef4444" }) : T.btn,
|
|
620
|
+
onClick: function () {
|
|
621
|
+
if (deleteFile === item.file) {
|
|
622
|
+
setDeleteFile("")
|
|
623
|
+
stickerAction("delete", item.name)
|
|
624
|
+
} else {
|
|
625
|
+
setDeleteFile(item.file)
|
|
626
|
+
setStickerNote("再点一次「确认删除」移除 " + item.name)
|
|
627
|
+
}
|
|
628
|
+
},
|
|
629
|
+
}, deleteFile === item.file ? "确认删除" : "删除"))
|
|
630
|
+
)
|
|
631
|
+
}))),
|
|
632
|
+
h("div", { style: T.hint }, "模型在回复里写 " + "[[sticker: 名字]]" + " 就会发出对应的图;名字就是文件名去掉扩展名。"))
|
|
633
|
+
}
|
|
634
|
+
function dashboardView() {
|
|
635
|
+
if (!dash) return h("div", { style: T.card }, h("div", { style: T.hint }, "正在读取…"))
|
|
636
|
+
if (dash.offline) return h("div", { style: T.card }, h("div", { style: T.hint }, "面板不可达(守护进程没在跑)"))
|
|
637
|
+
const c = dash.counters || {}
|
|
638
|
+
const botInfo = dash.bot || {}
|
|
639
|
+
const queues = dash.queues || {}
|
|
640
|
+
const logs = dash.logs || {}
|
|
641
|
+
const uptime = Number(dash.uptime_s || 0)
|
|
642
|
+
const human = uptime > 0 ? Math.floor(uptime / 3600) + "h " + Math.floor((uptime % 3600) / 60) + "m" : "—"
|
|
643
|
+
const points = buildSeries(dash.series, ["c2c_msgs", "group_msgs", "judge_spoke", "streams"], dashRange)
|
|
644
|
+
const sumKey = function (key) {
|
|
645
|
+
return (points || []).reduce(function (acc, point) { return acc + Number(point[key] || 0) }, 0)
|
|
646
|
+
}
|
|
647
|
+
const rangeC2c = sumKey("c2c_msgs")
|
|
648
|
+
const rangeGroup = sumKey("group_msgs")
|
|
649
|
+
const rangeSpoke = sumKey("judge_spoke")
|
|
650
|
+
const rangeStreams = sumKey("streams")
|
|
651
|
+
const totalMsgs = (c.c2c_msgs || 0) + (c.group_msgs || 0)
|
|
652
|
+
const judged = c.judge_calls || 0
|
|
653
|
+
const spoke = c.judge_spoke || 0
|
|
654
|
+
const speakRate = judged > 0 ? spoke / judged : 0
|
|
655
|
+
const streamed = c.streams || 0
|
|
656
|
+
const fallbacks = c.stream_fallbacks || 0
|
|
657
|
+
const streamOk = streamed > 0 ? 1 - fallbacks / streamed : 1
|
|
658
|
+
const runtime = dash.runtime || {}
|
|
659
|
+
const actions = [
|
|
660
|
+
["图片文件", c.files_image || 0, "var(--dsw-alias-state-business-primary, #2f6bff)"],
|
|
661
|
+
["文档文件", c.files_doc || 0, "#0ea5e9"],
|
|
662
|
+
["审批通过", c.approvals_allow || 0, "#22c55e"],
|
|
663
|
+
["审批拒绝", c.approvals_deny || 0, "#ef4444"],
|
|
664
|
+
["提问回答", c.questions_answered || 0, "#8b5cf6"],
|
|
665
|
+
["提问超时", c.question_timeouts || 0, "#f97316"],
|
|
666
|
+
["禁言", c.mutes || 0, "#f59e0b"],
|
|
667
|
+
["解禁", c.unmutes || 0, "#14b8a6"],
|
|
668
|
+
["踢人", c.kicks || 0, "#dc2626"],
|
|
669
|
+
]
|
|
670
|
+
const actionMax = actions.reduce(function (acc, item) { return Math.max(acc, item[1]) }, 1)
|
|
671
|
+
const logText = Object.keys(logs).map(function (name) { return name.replace(".log", "") + " " + Math.round(logs[name] / 1024) + "KB" }).join(" · ") || "—"
|
|
672
|
+
return h("div", { style: { display: "grid", gap: 14 } },
|
|
673
|
+
h("div", { style: T.kpiRow },
|
|
674
|
+
kpi("运行时长", human, (botInfo.online ? "在线" : "离线") + " · pid " + (botInfo.pid || "—")),
|
|
675
|
+
kpi("消息(本区间)", rangeC2c + rangeGroup, "私聊 " + rangeC2c + " · 群 " + rangeGroup),
|
|
676
|
+
kpi("开口(本区间)", rangeSpoke, "累计 " + spoke + " 次 · 判断 " + judged),
|
|
677
|
+
kpi("流式(本区间)", rangeStreams, "累计 " + streamed + " 次 · 降级 " + fallbacks)),
|
|
678
|
+
h("div", { style: T.kpiRow },
|
|
679
|
+
kpi("累计消息", totalMsgs, "自首次运行起,重启不清零"),
|
|
680
|
+
kpi("累计开口", spoke, "共判断 " + judged + " 次"),
|
|
681
|
+
kpi("省下的调用", c.hook_skips || 0, "钩子预筛直接跳过"),
|
|
682
|
+
kpi("内存/错误", (dash.memory_mb ? dash.memory_mb + " MB" : "—") + " / " + (dash.errors || 0), "工作集 / 日志 ERROR 数")),
|
|
683
|
+
h("div", { style: T.actions },
|
|
684
|
+
[["hour", "近 60 分钟"], ["today", "今天"], ["7d", "近 7 天"]].map(function (item) {
|
|
685
|
+
return h("button", {
|
|
686
|
+
key: item[0],
|
|
687
|
+
style: dashRange === item[0] ? Object.assign({}, T.tab, T.tabActive) : T.tab,
|
|
688
|
+
onClick: function () { setDashRange(item[0]) },
|
|
689
|
+
}, item[1])
|
|
690
|
+
}),
|
|
691
|
+
h("span", { style: T.hint }, dashRange === "hour" ? "近 60 分钟,按分钟聚合" : "读取 state/metrics/*.jsonl,停机也留档")), chartCard(dashRange === "hour" ? "近 60 分钟活动" : dashRange === "today" ? "今天每分钟活动" : "近 7 天每 30 分钟活动", [
|
|
692
|
+
{ label: "私聊", color: "#2f6bff" },
|
|
693
|
+
{ label: "群聊", color: "#22c55e" },
|
|
694
|
+
{ label: "开口", color: "#f59e0b" },
|
|
695
|
+
{ label: "流式", color: "#a855f7" },
|
|
696
|
+
], areaChart(points, ["c2c_msgs", "group_msgs", "judge_spoke", "streams"], {
|
|
697
|
+
c2c_msgs: "#2f6bff", group_msgs: "#22c55e", judge_spoke: "#f59e0b", streams: "#a855f7",
|
|
698
|
+
})),
|
|
699
|
+
h("div", { style: T.kpiRow },
|
|
700
|
+
h("div", { style: T.card }, ring(speakRate, "开口率", spoke + " / " + judged + " 次判断", "#f59e0b")),
|
|
701
|
+
h("div", { style: T.card }, ring(streamed > 0 ? streamOk : 0, streamed > 0 ? "流式成功率" : "流式(暂无数据)", streamed + " 次 · 降级 " + fallbacks, "#a855f7")),
|
|
702
|
+
h("div", { style: Object.assign({}, T.card, { gridColumn: "span 2" }) },
|
|
703
|
+
h("div", { style: T.cardTitle }, "动作分布"),
|
|
704
|
+
...actions.map(function (item) { return barRow(item[0], item[1], actionMax, item[2]) }))),
|
|
705
|
+
h("div", { style: T.kpiRow },
|
|
706
|
+
kpi("队列残留", (queues.questions || 0) + (queues.admin || 0), "提问 " + (queues.questions || 0) + " · 管理 " + (queues.admin || 0)),
|
|
707
|
+
kpi("成员索引", dash.members || 0, "本群发过言的成员"),
|
|
708
|
+
kpi("日志体积", Math.round(Object.keys(logs).reduce(function (acc, k) { return acc + logs[k] }, 0) / 1024) + " KB", logText)),
|
|
709
|
+
h("div", { style: T.kpiRow },
|
|
710
|
+
kpi("内存占用", (dash.memory_mb ? dash.memory_mb + " MB" : "—"), "bot 进程工作集"),
|
|
711
|
+
kpi("日志错误", dash.errors || 0, "最近 300KB 内 [ERROR] 行"),
|
|
712
|
+
kpi("待处理", (runtime.inflight || 0) + (runtime.queued || 0) + (runtime.chatter || 0),
|
|
713
|
+
"在跑 " + (runtime.inflight || 0) + " · 排队 " + (runtime.queued || 0) + " · 待判 " + (runtime.chatter || 0)),
|
|
714
|
+
kpi("群图片/引用", (c.group_images || 0) + " / " + (c.quotes || 0), "含附件的群消息与引用次数")),
|
|
715
|
+
h("div", { style: T.kpiRow },
|
|
716
|
+
h("div", { style: T.card },
|
|
717
|
+
h("div", { style: T.cardTitle }, "最近事件"),
|
|
718
|
+
h("div", { style: T.eventList, "data-qq-scroll": "1" },
|
|
719
|
+
...(dash.events && dash.events.length
|
|
720
|
+
? dash.events.map(function (item, index) {
|
|
721
|
+
const when = new Date(Number(item.at) * 1000)
|
|
722
|
+
const hhmm = ("0" + when.getHours()).slice(-2) + ":" + ("0" + when.getMinutes()).slice(-2)
|
|
723
|
+
return h("div", { key: "ev" + index, style: T.eventRow },
|
|
724
|
+
h("span", { style: T.eventTime }, hhmm),
|
|
725
|
+
h("span", { style: T.eventKind }, String(item.kind || "")),
|
|
726
|
+
h("span", { style: T.eventText }, String(item.text || "")))
|
|
727
|
+
})
|
|
728
|
+
: [h("div", { style: T.hint }, "还没有事件")]))),
|
|
729
|
+
h("div", { style: T.card },
|
|
730
|
+
h("div", { style: T.cardTitle }, "群资料"),
|
|
731
|
+
...(dash.groups_detail && dash.groups_detail.length
|
|
732
|
+
? dash.groups_detail.flatMap(function (group) {
|
|
733
|
+
const rows = [
|
|
734
|
+
h("div", { key: group.openid + "-name", style: T.cardRow },
|
|
735
|
+
h("span", { style: T.cardKey }, "群名"),
|
|
736
|
+
h("span", { style: T.cardValue }, group.name || "—")),
|
|
737
|
+
h("div", { key: group.openid + "-members", style: T.cardRow },
|
|
738
|
+
h("span", { style: T.cardKey }, "成员数"),
|
|
739
|
+
h("span", { style: T.cardValue }, String(group.members || 0))),
|
|
740
|
+
]
|
|
741
|
+
if (group.memo) {
|
|
742
|
+
rows.push(h("div", { key: group.openid + "-memo", style: T.hint }, group.memo))
|
|
743
|
+
}
|
|
744
|
+
if (group.class || (group.tags || []).length) {
|
|
745
|
+
rows.push(h("div", { key: group.openid + "-tags", style: T.chipRow },
|
|
746
|
+
...[group.class].concat(group.tags || []).filter(Boolean).map(function (tag) {
|
|
747
|
+
return h("span", { key: group.openid + tag, style: T.chip }, tag)
|
|
748
|
+
})))
|
|
749
|
+
}
|
|
750
|
+
return rows
|
|
751
|
+
})
|
|
752
|
+
: [h("div", { style: T.hint }, "还没取到群资料(机器人收到群消息后会自动缓存)")])),
|
|
753
|
+
h("div", { style: T.card },
|
|
754
|
+
h("div", { style: T.cardTitle }, "群成员 · " + Object.keys(dash.members_detail || {}).reduce(function (sum, key) { return sum + ((dash.members_detail[key] || []).length) }, 0)),
|
|
755
|
+
...Object.keys(dash.members_detail || {}).length
|
|
756
|
+
? Object.keys(dash.members_detail || {}).flatMap(function (key) {
|
|
757
|
+
const groupName = (dash.group_names || {})[key.replace("group:", "")] || ""
|
|
758
|
+
const list = dash.members_detail[key] || []
|
|
759
|
+
const rows = [h("div", { key: key, style: T.footNote }, groupName ? groupName + " · " + key.replace("group:", "").slice(-8) : key.replace("group:", "").slice(-8))]
|
|
760
|
+
rows.push(h("div", { key: key + "-list", style: T.memberList, "data-qq-scroll": "1" },
|
|
761
|
+
...(list.length
|
|
762
|
+
? list.map(function (item) {
|
|
763
|
+
return h("div", { key: key + item.tail, style: T.memberRow },
|
|
764
|
+
item.avatar
|
|
765
|
+
? h("img", { src: item.avatar, alt: item.tail, style: T.memberAvatar })
|
|
766
|
+
: h("span", { style: Object.assign({}, T.memberAvatar, { background: "var(--dsw-alias-border-l2)" }) }),
|
|
767
|
+
h("span", { style: T.memberName }, item.name || item.tail),
|
|
768
|
+
h("span", { style: T.memberTail }, item.name ? item.tail : ""))
|
|
769
|
+
})
|
|
770
|
+
: [h("div", { key: key + "-empty", style: T.hint }, "暂无")])))
|
|
771
|
+
if (list.length > 5) {
|
|
772
|
+
rows.push(h("div", { key: key + "-more", style: T.footNote }, "共 " + list.length + " 人 · 上下滚动查看全部"))
|
|
773
|
+
}
|
|
774
|
+
return rows
|
|
775
|
+
})
|
|
776
|
+
: [h("div", { style: T.hint }, "暂无")])),
|
|
777
|
+
h("div", { style: T.card },
|
|
778
|
+
h("div", { style: T.cardTitle }, "历史留档(state/metrics)"),
|
|
779
|
+
...(dash.history && dash.history.length
|
|
780
|
+
? dash.history.slice(-7).reverse().map(function (item) {
|
|
781
|
+
return h("div", { key: item.day, style: T.cardRow },
|
|
782
|
+
h("span", { style: T.cardKey }, item.day),
|
|
783
|
+
h("span", { style: T.cardValue }, item.minutes + " 分钟 · " + item.total + " 次事件"))
|
|
784
|
+
})
|
|
785
|
+
: [h("div", { style: T.hint }, "还没有归档文件(每分钟结束后自动写一行 JSONL)")])),
|
|
786
|
+
h("div", { style: T.footNote }, "计数与曲线跨重启保留(读 state/metrics),只有运行时长按本次启动计算。"))
|
|
787
|
+
}
|
|
208
788
|
const dot = function (ok) {
|
|
209
789
|
return h("span", { style: Object.assign({}, T.dot, { background: ok === true ? "var(--dsw-alias-state-success-primary, #35c759)" : ok === false ? "var(--dsw-alias-label-error, #e5534b)" : "var(--dsw-alias-label-tertiary, #888)" }) })
|
|
210
790
|
}
|
|
211
791
|
|
|
792
|
+
const tabBar = h("div", { style: T.tabs },
|
|
793
|
+
h("button", { style: tab === "settings" ? Object.assign({}, T.tab, T.tabActive) : T.tab, onClick: function () { setTab("settings") } }, "设置"),
|
|
794
|
+
h("button", { style: tab === "dashboard" ? Object.assign({}, T.tab, T.tabActive) : T.tab, onClick: function () { setTab("dashboard") } }, "数据仪表盘"),
|
|
795
|
+
h("button", { style: tab === "stickers" ? Object.assign({}, T.tab, T.tabActive) : T.tab, onClick: function () { setTab("stickers") } }, "表情包"))
|
|
796
|
+
|
|
797
|
+
// 人设:一个大输入框一份,群聊与私聊分开
|
|
798
|
+
const personaBox = function (key, title, hint) {
|
|
799
|
+
return h("div", { key: key, style: T.card },
|
|
800
|
+
h("div", { style: T.cardHead },
|
|
801
|
+
h("span", { style: T.cardTitle }, title),
|
|
802
|
+
h("span", { style: T.hint }, hint)),
|
|
803
|
+
h("textarea", {
|
|
804
|
+
style: T.textarea,
|
|
805
|
+
rows: 8,
|
|
806
|
+
placeholder: "写这里,例如:你是一条叫「蓝色大肥鱼」的群宠,话短、带口癖「喵」,不主动聊政治和带节奏。",
|
|
807
|
+
value: value(key) === undefined ? "" : value(key),
|
|
808
|
+
onChange: function (event) { setValue(key, event.target.value) },
|
|
809
|
+
}))
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
if (tab === "dashboard") {
|
|
813
|
+
return h("div", { style: T.page }, h("style", { key: "qq-scroll-css" }, SCROLLBAR_CSS), h("div", { style: T.inner }, tabBar, dashboardView()))
|
|
814
|
+
}
|
|
815
|
+
if (tab === "stickers") {
|
|
816
|
+
return h("div", { style: T.page }, h("style", { key: "qq-scroll-css" }, SCROLLBAR_CSS), h("div", { style: T.inner }, tabBar, stickersView()))
|
|
817
|
+
}
|
|
818
|
+
|
|
212
819
|
return h("div", { style: T.page },
|
|
820
|
+
h("style", { key: "qq-scroll-css" }, SCROLLBAR_CSS),
|
|
213
821
|
h("div", { style: T.inner },
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
h("
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
h("
|
|
822
|
+
tabBar,
|
|
823
|
+
h("div", { style: T.stickyTop },
|
|
824
|
+
h("div", { style: T.actions },
|
|
825
|
+
h("span", { style: T.badge }, dot(!!bot.running), "进程 · " + (bot.running ? "运行中" : "已停止")),
|
|
826
|
+
h("span", { style: T.badge }, dot(!!bot.online), "在线 · " + (bot.online ? "是" : "否")),
|
|
827
|
+
h("span", { style: T.badge }, dot(state.bridge === "ready"), "桥接 · " + (state.bridge || "?")),
|
|
828
|
+
bot.pid ? h("span", { style: T.hint }, "pid " + bot.pid) : null),
|
|
829
|
+
message ? h("div", { style: T.hint }, message) : null,
|
|
830
|
+
h("div", { style: T.actions },
|
|
831
|
+
h("button", { style: Object.assign({}, T.btn, T.btnPrimary), disabled: busy, onClick: function () { manage("start") } }, "启动"),
|
|
222
832
|
h("button", { style: T.btn, disabled: busy, onClick: function () { manage("restart") } }, "重启"),
|
|
223
833
|
h("button", { style: T.btn, disabled: busy, onClick: function () { manage("stop") } }, "关闭(不拉起)"),
|
|
224
834
|
h("button", { style: T.btn, onClick: function () { window.open("https://q.qq.com/qqbot/", "_blank", "noopener") } }, "QQ 开放平台"),
|
|
@@ -233,12 +843,52 @@ window.__ModuleLoader__.load({
|
|
|
233
843
|
setMessage("打不开:" + target)
|
|
234
844
|
}
|
|
235
845
|
},
|
|
236
|
-
|
|
846
|
+
}, "打开分组文件夹"))),
|
|
847
|
+
h("div", { style: T.sectionTitle }, "凭据"),
|
|
848
|
+
CREDENTIALS.map(function (item) {
|
|
849
|
+
return h(Row, { key: item[0], title: item[1] },
|
|
850
|
+
h("input", {
|
|
851
|
+
type: item[0].indexOf("secret") >= 0 ? "password" : "text",
|
|
852
|
+
placeholder: item[0].indexOf("secret") >= 0 ? "不改" : "留空=用 config.json",
|
|
853
|
+
style: Object.assign({}, T.input, T.inputWide),
|
|
854
|
+
value: value(item[0]) === undefined ? "" : value(item[0]),
|
|
855
|
+
onChange: function (event) { setValue(item[0], event.target.value) },
|
|
856
|
+
}))
|
|
857
|
+
}),
|
|
858
|
+
h("div", { style: T.sectionTitle }, "机器人环境(把 Python / SDK / 机器人代码一次配好)"),
|
|
859
|
+
h("div", { style: T.card },
|
|
860
|
+
h("div", { style: T.cardRow },
|
|
861
|
+
h("span", { style: T.cardKey }, "状态"),
|
|
862
|
+
h("span", { style: T.cardValue },
|
|
863
|
+
install === null ? "读取中…"
|
|
864
|
+
: install.running ? "正在配置…"
|
|
865
|
+
: (install.done && install.succeeded) ? "配置完成"
|
|
866
|
+
: install.installed ? "已配置" : "未用一键安装(按插件里的 pythonPath 启动)")),
|
|
867
|
+
install && install.installed
|
|
868
|
+
? h("div", { style: T.hint }, "目录 " + install.installed.botDir + " · Python " + (install.installed.pythonVersion || "?"))
|
|
869
|
+
: h("div", { style: T.hint }, "点按钮:找系统 Python(3.10+)→ 建 venv → pip 装 aiohttp / Pillow / viseron-qqbotpy → 复制机器人代码 → 写配置 → 拉起守护进程"),
|
|
870
|
+
install && install.running && Array.isArray(install.steps)
|
|
871
|
+
? h("div", { style: T.hint }, "第 " + (install.step + 1) + "/" + install.steps.length + " 步:" + install.steps[install.step])
|
|
872
|
+
: null,
|
|
873
|
+
install && install.error ? h("div", { style: T.hint }, "失败:" + install.error) : null,
|
|
874
|
+
installNote ? h("div", { style: T.hint }, installNote) : null,
|
|
875
|
+
h("div", { style: T.actions },
|
|
876
|
+
h("button", {
|
|
877
|
+
style: Object.assign({}, T.btn, T.btnPrimary),
|
|
878
|
+
disabled: busy || (install !== null && install.running === true),
|
|
879
|
+
onClick: function () { void startInstall() },
|
|
880
|
+
}, install && install.running ? "正在配置…" : "下载 / 配置机器人")),
|
|
881
|
+
install && Array.isArray(install.lines) && install.lines.length
|
|
882
|
+
? h("pre", { style: T.log }, install.lines.slice(-60).join("\n"))
|
|
883
|
+
: null),
|
|
237
884
|
h("div", { style: T.sectionTitle }, "开关"),
|
|
238
885
|
SWITCHES.map(function (item) {
|
|
239
886
|
return h(Row, { key: item[0], title: item[1], hint: item[2] },
|
|
240
887
|
h(Switch, { checked: !!value(item[0]), label: item[1], disabled: busy, onChange: function (next) { setValue(item[0], next) } }))
|
|
241
888
|
}),
|
|
889
|
+
h("div", { style: T.sectionTitle }, "人设(只在新会话的第一条消息里发一次)"),
|
|
890
|
+
personaBox("persona_group", "群聊人设", "群聊里带的人设;留空=不启用"),
|
|
891
|
+
personaBox("persona_c2c", "私聊人设", "单聊里带的人设;留空=不启用"),
|
|
242
892
|
h("div", { style: T.sectionTitle }, "群聊节奏与发送"),
|
|
243
893
|
h(QuietRow, {
|
|
244
894
|
key: "quiet-hours",
|
|
@@ -261,7 +911,7 @@ window.__ModuleLoader__.load({
|
|
|
261
911
|
value: value("group_mode"),
|
|
262
912
|
disabled: busy,
|
|
263
913
|
onChange: function (next) { setValue("group_mode", next) },
|
|
264
|
-
}), h("div", { style: T.sectionTitle }, "
|
|
914
|
+
}), h("div", { style: T.sectionTitle }, "过滤与目录"),
|
|
265
915
|
TEXTS.map(function (item) {
|
|
266
916
|
return h(Row, { key: item[0], title: item[1] },
|
|
267
917
|
h("input", {
|
|
@@ -271,9 +921,10 @@ window.__ModuleLoader__.load({
|
|
|
271
921
|
onChange: function (event) { setValue(item[0], event.target.value) },
|
|
272
922
|
}))
|
|
273
923
|
}),
|
|
274
|
-
h("div", { style: T.
|
|
924
|
+
h("div", { style: T.stickyBottom },
|
|
275
925
|
h("button", { style: Object.assign({}, T.btn, T.btnPrimary), disabled: busy, onClick: save }, "保存设置"),
|
|
276
|
-
h("button", { style: T.btn, disabled: busy, onClick: function () { setDraft({}); load() } }, "重新读取")
|
|
926
|
+
h("button", { style: T.btn, disabled: busy, onClick: function () { setDraft({}); load() } }, "重新读取"),
|
|
927
|
+
h("span", { style: T.hint }, Object.keys(draft).length === 0 ? "(没有改动)" : "(有 " + Object.keys(draft).length + " 项未保存)")),
|
|
277
928
|
h("div", { style: T.sectionTitle }, "运行日志(最近 200 行)"),
|
|
278
929
|
h("div", { style: T.actions },
|
|
279
930
|
h("button", { style: T.btn, onClick: function () { setPaused(!paused) } }, paused ? "继续刷新" : "暂停刷新"),
|