@mcviseron/dsh-qq-bridge 0.3.0 → 0.3.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/bot/main.py +91 -21
- package/lib/client.js +44 -18
- package/package.json +1 -1
package/bot/main.py
CHANGED
|
@@ -58,7 +58,8 @@ SESSION_COMMANDS = {"/会话", "/sessions", "会话", "/当前会话"}
|
|
|
58
58
|
SWITCH_COMMANDS = {"/切会话", "/切换", "/switch", "切会话"}
|
|
59
59
|
BACK_COMMANDS = {"/切回", "/返回", "/back", "切回"}
|
|
60
60
|
USAGE_COMMANDS = {"/花费", "/用量", "/token", "/usage", "/cost", "花费", "用量"}
|
|
61
|
-
|
|
61
|
+
# /指令 与 /commands 归 DSH 指令列表(下面 handle_extra_command 里那条分支),不再和菜单混用
|
|
62
|
+
MENU_COMMANDS = {"/菜单", "/面板", "/menu", "菜单"}
|
|
62
63
|
RECALL_COMMANDS = {"/撤回", "/recall", "撤回"}
|
|
63
64
|
POOL_COMMANDS = {"/消息池", "/池", "/pool", "消息池"}
|
|
64
65
|
URGENT_EVENTS = {"approval", "notice"}
|
|
@@ -286,17 +287,85 @@ def parse_decision(text: str) -> Tuple[Optional[str], Optional[str]]:
|
|
|
286
287
|
return None, None
|
|
287
288
|
|
|
288
289
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
290
|
+
# 命令的唯一来源:显示名 / 别名 / 说明 / 是否仅主人。
|
|
291
|
+
# 按钮键盘、QQ 指令面板(panels.json)和 /帮助 全部由它生成,避免三处各写一份走样。
|
|
292
|
+
COMMAND_SPECS: Tuple[Tuple[str, Tuple[str, ...], str, bool], ...] = (
|
|
293
|
+
("帮助", ("/帮助", "/help", "/dsh", "帮助", "help"), "用法与全部指令", False),
|
|
294
|
+
("菜单", ("/菜单", "/面板", "/menu", "菜单"), "消息内按钮面板", False),
|
|
295
|
+
("状态", ("/状态", "/status", "状态"), "授权、会话、桥接状态", True),
|
|
296
|
+
("会话", ("/会话", "/sessions", "/当前会话", "会话"), "当前绑定与可切会话", True),
|
|
297
|
+
("新会话", ("/新会话", "/reset", "/重置", "/清空", "新会话", "reset", "重置", "清空上下文"), "清空上下文重开", True),
|
|
298
|
+
("花费", ("/花费", "/用量", "/token", "/usage", "/cost", "花费", "用量"), "本会话 token 用量", True),
|
|
299
|
+
("花费 全部", ("/花费 全部",), "最近所有会话用量", True),
|
|
300
|
+
("切会话", ("/切会话", "/切换", "/switch", "切会话"), "切到指定 DSH 会话(/切会话 <session-id>)", True),
|
|
301
|
+
("切回", ("/切回", "/返回", "/back", "切回"), "回到原来的会话", True),
|
|
302
|
+
("截图", ("/截图", "/screenshot", "/shot", "截图"), "截本机窗口发给你", True),
|
|
303
|
+
("窗口", ("/窗口", "/windows", "窗口"), "列出可截图窗口", True),
|
|
304
|
+
("消息池", ("/消息池", "/池", "/pool", "消息池"), "最近 10 分钟收发", True),
|
|
305
|
+
("撤回", ("/撤回", "/recall", "撤回"), "撤回我发的或指定那条", False),
|
|
306
|
+
("链接", ("/链接", "/邀请", "/invite", "邀请链接"), "取 DSH 邀请链接", True),
|
|
307
|
+
("绑定", ("/绑定", "/绑定主人", "绑定主人"), "把自己绑成本会话主人", False),
|
|
308
|
+
("分组", ("/分组", "/workspace", "/ws"), "迁移到独立工作区", True),
|
|
309
|
+
("指令", ("/指令", "/commands"), "DSH 侧指令列表", False),
|
|
310
|
+
)
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
def command_panel_rows(per_row: int = 3) -> List[List[Tuple[str, str]]]:
|
|
314
|
+
"""按钮键盘的分行结果:每行 per_row 个(data=发出去的指令,label=按钮文字)。"""
|
|
315
|
+
items = [(name, alias) for name, aliases, _desc, _owner in COMMAND_SPECS for alias in (aliases[0],) if not name.startswith("花费 ")]
|
|
316
|
+
rows: List[List[Tuple[str, str]]] = []
|
|
317
|
+
for index in range(0, len(items), per_row):
|
|
318
|
+
rows.append([(data, label) for data, label in items[index:index + per_row]])
|
|
319
|
+
return rows
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
# QQ 指令面板一屏放不下太多:平台会回「超出数量限制」。按 COMMAND_SPECS 的先后取前 N 个,
|
|
323
|
+
# 剩下的照样能用(/帮助 里全在),只是不在面板上。
|
|
324
|
+
# 平台对「一个机器人名下的面板条目总数」有上限(实测 5+5 通过、7+3 触发「超出数量限制」)
|
|
325
|
+
PANEL_LIMIT_C2C = 5
|
|
326
|
+
PANEL_LIMIT_GROUP = 5
|
|
327
|
+
PANEL_MAX_ITEMS = PANEL_LIMIT_C2C + PANEL_LIMIT_GROUP
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
def build_panels_doc(limit: int = PANEL_LIMIT_C2C, group_limit: int = PANEL_LIMIT_GROUP) -> Dict[str, Any]:
|
|
331
|
+
"""QQ 指令面板:c2c 给全套(受平台条数上限约束),group 只放公开命令。"""
|
|
332
|
+
def items(include_owner: bool) -> List[Dict[str, str]]:
|
|
333
|
+
out = []
|
|
334
|
+
for name, _aliases, desc, owner_only in COMMAND_SPECS:
|
|
335
|
+
if owner_only and not include_owner:
|
|
336
|
+
continue
|
|
337
|
+
out.append({"type": "command", "name": name, "desc": desc})
|
|
338
|
+
if len(out) >= max(1, limit):
|
|
339
|
+
break
|
|
340
|
+
return out
|
|
341
|
+
|
|
342
|
+
return {
|
|
343
|
+
"c2c": {"target_type": "all", "remark": "DSH 指令面板", "items": items(True)[:limit]},
|
|
344
|
+
"group": {"target_type": "all", "remark": "DSH 群聊指令面板", "items": items(False)[:group_limit]},
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
def write_panels_doc(path: Optional[Path] = None) -> bool:
|
|
349
|
+
"""把命令表渲染成 panels.json;内容没变就不落盘(返回是否写过)。"""
|
|
350
|
+
target = path or (ROOT / "panels" / "panels.json")
|
|
351
|
+
text = json.dumps(build_panels_doc(), ensure_ascii=False, indent=2) + chr(10)
|
|
352
|
+
try:
|
|
353
|
+
if target.exists() and target.read_text(encoding="utf-8") == text:
|
|
354
|
+
return False
|
|
355
|
+
except OSError:
|
|
356
|
+
pass
|
|
357
|
+
try:
|
|
358
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
359
|
+
target.write_text(text, encoding="utf-8")
|
|
360
|
+
return True
|
|
361
|
+
except OSError:
|
|
362
|
+
return False
|
|
294
363
|
|
|
295
364
|
|
|
296
365
|
def command_keyboard() -> Dict[str, Any]:
|
|
297
366
|
"""Command panel: every button sends its command as a normal message."""
|
|
298
367
|
rows = []
|
|
299
|
-
for row in
|
|
368
|
+
for row in command_panel_rows():
|
|
300
369
|
buttons = []
|
|
301
370
|
for data, label in row:
|
|
302
371
|
buttons.append(
|
|
@@ -611,6 +680,9 @@ class DSHBot(Client):
|
|
|
611
680
|
self._bump("c2c_msgs", 0) # 初始化并落盘计数器,仪表盘开局就有数据
|
|
612
681
|
self._prune_metrics(time.time()) # 启动时清一次超过保留期的归档
|
|
613
682
|
await self._prefetch_group_profiles()
|
|
683
|
+
# 面板由命令表生成(有什么命令就有什么按钮),再推给 QQ
|
|
684
|
+
if write_panels_doc():
|
|
685
|
+
log.info("panels.json regenerated from the command table")
|
|
614
686
|
await self._sync_panels()
|
|
615
687
|
# 严格闭合:重启后先把上个进程遗留的流式会话关掉,再开始新回合
|
|
616
688
|
try:
|
|
@@ -627,6 +699,7 @@ class DSHBot(Client):
|
|
|
627
699
|
|
|
628
700
|
async def _sync_panels(self) -> None:
|
|
629
701
|
"""Push bot/panels/panels.json to the QQ instruction panel."""
|
|
702
|
+
write_panels_doc() # 命令表变了就先重写,避免推到旧面板
|
|
630
703
|
try:
|
|
631
704
|
store = await load_panels(self.api, root_dir=str(ROOT / "panels"))
|
|
632
705
|
await store.sync_from_config()
|
|
@@ -3896,20 +3969,17 @@ class DSHBot(Client):
|
|
|
3896
3969
|
self.group_state.pop(group_openid, None)
|
|
3897
3970
|
|
|
3898
3971
|
def help_text(self) -> str:
|
|
3899
|
-
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
|
|
3904
|
-
|
|
3905
|
-
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
"· 需要授权时审批发到主人单聊:点按钮或回「允许」/「拒绝」",
|
|
3911
|
-
]
|
|
3912
|
-
)
|
|
3972
|
+
"""按命令表生成,面板 / 键盘 / 帮助三处不会再各说一套。"""
|
|
3973
|
+
lines = [f"我是 {self.config.botname}:DeepSeek Harness 的 QQ 入口。"]
|
|
3974
|
+
for name, _aliases, desc, owner_only in COMMAND_SPECS:
|
|
3975
|
+
lines.append(f"· /{name} {desc}" + ("(主人)" if owner_only else ""))
|
|
3976
|
+
lines += [
|
|
3977
|
+
"——",
|
|
3978
|
+
"连续发几条会合并成一条再处理;发图我能看图。",
|
|
3979
|
+
"群里 @ 我才干活,其它时候像群友一样听着、偶尔插一句。",
|
|
3980
|
+
"需要授权时审批发到主人单聊:点按钮或回「允许」/「拒绝」。",
|
|
3981
|
+
]
|
|
3982
|
+
return "\n".join(lines)
|
|
3913
3983
|
|
|
3914
3984
|
|
|
3915
3985
|
# --------------------------------------------------------------------------- #
|
package/lib/client.js
CHANGED
|
@@ -23,7 +23,8 @@ window.__ModuleLoader__.load({
|
|
|
23
23
|
padding: "20px 22px", borderRadius: 16,
|
|
24
24
|
border: "1px solid var(--dsw-alias-border-l2, rgba(255,255,255,0.14))",
|
|
25
25
|
backgroundColor: "rgba(22, 24, 30, 0.62)",
|
|
26
|
-
|
|
26
|
+
// 94% 而不是 72%:卡片半透明太强时,滚动内容会从悬浮栏上下的内边距里透出来
|
|
27
|
+
background: "color-mix(in srgb, var(--dsw-alias-bg-base, #14161c) 94%, transparent)",
|
|
27
28
|
backdropFilter: "blur(18px) saturate(130%)",
|
|
28
29
|
WebkitBackdropFilter: "blur(18px) saturate(130%)",
|
|
29
30
|
boxShadow: "0 10px 30px rgba(0,0,0,0.24)",
|
|
@@ -70,6 +71,15 @@ window.__ModuleLoader__.load({
|
|
|
70
71
|
cardKey: { color: "var(--dsw-alias-label-tertiary)" },
|
|
71
72
|
cardValue: { color: "var(--dsw-alias-label-secondary)", fontVariantNumeric: "tabular-nums" },
|
|
72
73
|
sectionTitle: { fontSize: 12, letterSpacing: "0.04em", color: "var(--dsw-alias-label-tertiary)", margin: "10px 0 2px" },
|
|
74
|
+
// 顶/底悬浮栏:跟随主题的表面色(写死深色在浅色主题里就是一块黑板),圆角+描边看着像工具条
|
|
75
|
+
stickyBar: { position: "sticky", zIndex: 6, display: "grid", gap: 10, padding: "10px 12px", borderRadius: 12,
|
|
76
|
+
background: "color-mix(in srgb, var(--dsw-alias-bg-base, #ffffff) 96%, transparent)",
|
|
77
|
+
backdropFilter: "blur(14px) saturate(140%)", WebkitBackdropFilter: "blur(14px) saturate(140%)",
|
|
78
|
+
border: "1px solid var(--dsw-alias-border-l2, rgba(0,0,0,0.12))", boxShadow: "0 6px 18px rgba(0,0,0,0.10)" },
|
|
79
|
+
stickyTop: { top: 0 },
|
|
80
|
+
stickyBottom: { bottom: 0, display: "flex", gap: 8, flexWrap: "wrap", alignItems: "center" },
|
|
81
|
+
// 设置页去掉外层上下内边距,悬浮栏才能贴到视口边缘,不留一条会透出内容的缝
|
|
82
|
+
pageTight: { paddingTop: 0, paddingBottom: 0 },
|
|
73
83
|
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" },
|
|
74
84
|
inputWide: { width: 260, textAlign: "left" },
|
|
75
85
|
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" },
|
|
@@ -171,13 +181,16 @@ window.__ModuleLoader__.load({
|
|
|
171
181
|
["judge_force_per_hour","每小时最多几次降档补开口",0,5],
|
|
172
182
|
]
|
|
173
183
|
|
|
184
|
+
// 凭据放最前面:装机器人、改 AppID 都在第一屏
|
|
185
|
+
const CREDENTIALS = [
|
|
186
|
+
["appid", "APPID(开放平台的机器人 AppID)"],
|
|
187
|
+
["appsecret", "APPSECRET(留空=不变;打码值不会被写入)"],
|
|
188
|
+
]
|
|
189
|
+
|
|
174
190
|
const TEXTS = [
|
|
175
191
|
["group_allowlist","群白名单(openid,逗号分隔)"],
|
|
176
192
|
["c2c_allowlist","私聊白名单(同上)"], ["bot_aliases","群内别名(逗号分隔)"],
|
|
177
|
-
["appid","APPID(留空=用 config.json)"],
|
|
178
|
-
["appsecret","APPSECRET(留空=不变,需重启)"],
|
|
179
193
|
["auto_group_root","自动分组根目录(如 D:\\dsh-qqbot-temp)"],
|
|
180
|
-
,
|
|
181
194
|
]
|
|
182
195
|
|
|
183
196
|
function QQBridgePage() {
|
|
@@ -810,18 +823,19 @@ window.__ModuleLoader__.load({
|
|
|
810
823
|
return h("div", { style: T.page }, h("style", { key: "qq-scroll-css" }, SCROLLBAR_CSS), h("div", { style: T.inner }, tabBar, stickersView()))
|
|
811
824
|
}
|
|
812
825
|
|
|
813
|
-
return h("div", { style: T.page },
|
|
826
|
+
return h("div", { style: Object.assign({}, T.page, T.pageTight) },
|
|
814
827
|
h("style", { key: "qq-scroll-css" }, SCROLLBAR_CSS),
|
|
815
828
|
h("div", { style: T.inner },
|
|
816
|
-
tabBar,
|
|
817
|
-
h("div", { style: T.
|
|
818
|
-
h("
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
h("
|
|
829
|
+
h("div", { style: { paddingTop: 24 } }, tabBar),
|
|
830
|
+
h("div", { style: Object.assign({}, T.stickyBar, T.stickyTop) },
|
|
831
|
+
h("div", { style: T.actions },
|
|
832
|
+
h("span", { style: T.badge }, dot(!!bot.running), "进程 · " + (bot.running ? "运行中" : "已停止")),
|
|
833
|
+
h("span", { style: T.badge }, dot(!!bot.online), "在线 · " + (bot.online ? "是" : "否")),
|
|
834
|
+
h("span", { style: T.badge }, dot(state.bridge === "ready"), "桥接 · " + (state.bridge || "?")),
|
|
835
|
+
bot.pid ? h("span", { style: T.hint }, "pid " + bot.pid) : null),
|
|
836
|
+
message ? h("div", { style: T.hint }, message) : null,
|
|
837
|
+
h("div", { style: T.actions },
|
|
838
|
+
h("button", { style: Object.assign({}, T.btn, T.btnPrimary), disabled: busy, onClick: function () { manage("start") } }, "启动"),
|
|
825
839
|
h("button", { style: T.btn, disabled: busy, onClick: function () { manage("restart") } }, "重启"),
|
|
826
840
|
h("button", { style: T.btn, disabled: busy, onClick: function () { manage("stop") } }, "关闭(不拉起)"),
|
|
827
841
|
h("button", { style: T.btn, onClick: function () { window.open("https://q.qq.com/qqbot/", "_blank", "noopener") } }, "QQ 开放平台"),
|
|
@@ -836,7 +850,18 @@ window.__ModuleLoader__.load({
|
|
|
836
850
|
setMessage("打不开:" + target)
|
|
837
851
|
}
|
|
838
852
|
},
|
|
839
|
-
|
|
853
|
+
}, "打开分组文件夹"))),
|
|
854
|
+
h("div", { style: T.sectionTitle }, "凭据"),
|
|
855
|
+
CREDENTIALS.map(function (item) {
|
|
856
|
+
return h(Row, { key: item[0], title: item[1] },
|
|
857
|
+
h("input", {
|
|
858
|
+
type: item[0].indexOf("secret") >= 0 ? "password" : "text",
|
|
859
|
+
placeholder: item[0].indexOf("secret") >= 0 ? "不改" : "留空=用 config.json",
|
|
860
|
+
style: Object.assign({}, T.input, T.inputWide),
|
|
861
|
+
value: value(item[0]) === undefined ? "" : value(item[0]),
|
|
862
|
+
onChange: function (event) { setValue(item[0], event.target.value) },
|
|
863
|
+
}))
|
|
864
|
+
}),
|
|
840
865
|
h("div", { style: T.sectionTitle }, "机器人环境(把 Python / SDK / 机器人代码一次配好)"),
|
|
841
866
|
h("div", { style: T.card },
|
|
842
867
|
h("div", { style: T.cardRow },
|
|
@@ -893,7 +918,7 @@ window.__ModuleLoader__.load({
|
|
|
893
918
|
value: value("group_mode"),
|
|
894
919
|
disabled: busy,
|
|
895
920
|
onChange: function (next) { setValue("group_mode", next) },
|
|
896
|
-
}), h("div", { style: T.sectionTitle }, "
|
|
921
|
+
}), h("div", { style: T.sectionTitle }, "过滤与目录"),
|
|
897
922
|
TEXTS.map(function (item) {
|
|
898
923
|
return h(Row, { key: item[0], title: item[1] },
|
|
899
924
|
h("input", {
|
|
@@ -903,9 +928,10 @@ window.__ModuleLoader__.load({
|
|
|
903
928
|
onChange: function (event) { setValue(item[0], event.target.value) },
|
|
904
929
|
}))
|
|
905
930
|
}),
|
|
906
|
-
h("div", { style: T.
|
|
931
|
+
h("div", { style: Object.assign({}, T.stickyBar, T.stickyBottom, { marginBottom: 24 }) },
|
|
907
932
|
h("button", { style: Object.assign({}, T.btn, T.btnPrimary), disabled: busy, onClick: save }, "保存设置"),
|
|
908
|
-
h("button", { style: T.btn, disabled: busy, onClick: function () { setDraft({}); load() } }, "重新读取")
|
|
933
|
+
h("button", { style: T.btn, disabled: busy, onClick: function () { setDraft({}); load() } }, "重新读取"),
|
|
934
|
+
h("span", { style: T.hint }, Object.keys(draft).length === 0 ? "(没有改动)" : "(有 " + Object.keys(draft).length + " 项未保存)")),
|
|
909
935
|
h("div", { style: T.sectionTitle }, "运行日志(最近 200 行)"),
|
|
910
936
|
h("div", { style: T.actions },
|
|
911
937
|
h("button", { style: T.btn, onClick: function () { setPaused(!paused) } }, paused ? "继续刷新" : "暂停刷新"),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mcviseron/dsh-qq-bridge",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "DeepSeek Harness plugin: bridge QQ conversations (driven by an external viseron-botpy bot) to DSH sessions — injects user messages, captures assistant replies, streams C2C answers, and relays tool approvals to the bot owner.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|