@mcviseron/dsh-qq-bridge 0.3.0 → 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.
Files changed (3) hide show
  1. package/bot/main.py +91 -21
  2. package/lib/client.js +34 -15
  3. 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
- MENU_COMMANDS = {"/菜单", "/指令", "/面板", "/menu", "/commands", "菜单", "指令"}
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
- COMMAND_PANEL_ROWS = [
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 COMMAND_PANEL_ROWS:
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
- return "\n".join(
3900
- [
3901
- f"我是 {self.config.botname}:DeepSeek Harness 的 QQ 入口。",
3902
- "· /状态 看授权、/窗口 列窗口、/截图 <关键字> 截图发你",
3903
- "· 连续发几条会合并成一条再处理;发图我能看图",
3904
- "· 群里 @ 我才干活,其它时候像群友一样听着、偶尔插一句",
3905
- "· /新会话(/重置)清空上下文;群里 /绑定 把自己绑成群主",
3906
- "· /会话 看绑定,/切会话 <id> 换会话,/切回 回到原会话",
3907
- "· /花费 看本会话 token 用量(/花费 全部 看最近所有会话)",
3908
- "· /菜单 弹出按钮面板,常用指令一点就走",
3909
- "· /消息池 看最近 10 分钟收发(/池),/撤回 [n|#序号] 撤我发的或指定那条",
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
@@ -70,6 +70,9 @@ window.__ModuleLoader__.load({
70
70
  cardKey: { color: "var(--dsw-alias-label-tertiary)" },
71
71
  cardValue: { color: "var(--dsw-alias-label-secondary)", fontVariantNumeric: "tabular-nums" },
72
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)" },
73
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" },
74
77
  inputWide: { width: 260, textAlign: "left" },
75
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" },
@@ -171,13 +174,16 @@ window.__ModuleLoader__.load({
171
174
  ["judge_force_per_hour","每小时最多几次降档补开口",0,5],
172
175
  ]
173
176
 
177
+ // 凭据放最前面:装机器人、改 AppID 都在第一屏
178
+ const CREDENTIALS = [
179
+ ["appid", "APPID(开放平台的机器人 AppID)"],
180
+ ["appsecret", "APPSECRET(留空=不变;打码值不会被写入)"],
181
+ ]
182
+
174
183
  const TEXTS = [
175
184
  ["group_allowlist","群白名单(openid,逗号分隔)"],
176
185
  ["c2c_allowlist","私聊白名单(同上)"], ["bot_aliases","群内别名(逗号分隔)"],
177
- ["appid","APPID(留空=用 config.json)"],
178
- ["appsecret","APPSECRET(留空=不变,需重启)"],
179
186
  ["auto_group_root","自动分组根目录(如 D:\\dsh-qqbot-temp)"],
180
- ,
181
187
  ]
182
188
 
183
189
  function QQBridgePage() {
@@ -814,14 +820,15 @@ window.__ModuleLoader__.load({
814
820
  h("style", { key: "qq-scroll-css" }, SCROLLBAR_CSS),
815
821
  h("div", { style: T.inner },
816
822
  tabBar,
817
- h("div", { style: T.actions },
818
- h("span", { style: T.badge }, dot(!!bot.running), "进程 · " + (bot.running ? "运行中" : "已停止")),
819
- h("span", { style: T.badge }, dot(!!bot.online), "在线 · " + (bot.online ? "是" : "否")),
820
- h("span", { style: T.badge }, dot(state.bridge === "ready"), "桥接 · " + (state.bridge || "?")),
821
- bot.pid ? h("span", { style: T.hint }, "pid " + bot.pid) : null),
822
- message ? h("div", { style: T.hint }, message) : null,
823
- h("div", { style: T.actions },
824
- h("button", { style: Object.assign({}, T.btn, T.btnPrimary), disabled: busy, onClick: function () { manage("start") } }, "启动"),
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") } }, "启动"),
825
832
  h("button", { style: T.btn, disabled: busy, onClick: function () { manage("restart") } }, "重启"),
826
833
  h("button", { style: T.btn, disabled: busy, onClick: function () { manage("stop") } }, "关闭(不拉起)"),
827
834
  h("button", { style: T.btn, onClick: function () { window.open("https://q.qq.com/qqbot/", "_blank", "noopener") } }, "QQ 开放平台"),
@@ -836,7 +843,18 @@ window.__ModuleLoader__.load({
836
843
  setMessage("打不开:" + target)
837
844
  }
838
845
  },
839
- }, "打开分组文件夹")),
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
+ }),
840
858
  h("div", { style: T.sectionTitle }, "机器人环境(把 Python / SDK / 机器人代码一次配好)"),
841
859
  h("div", { style: T.card },
842
860
  h("div", { style: T.cardRow },
@@ -893,7 +911,7 @@ window.__ModuleLoader__.load({
893
911
  value: value("group_mode"),
894
912
  disabled: busy,
895
913
  onChange: function (next) { setValue("group_mode", next) },
896
- }), h("div", { style: T.sectionTitle }, "过滤与凭据"),
914
+ }), h("div", { style: T.sectionTitle }, "过滤与目录"),
897
915
  TEXTS.map(function (item) {
898
916
  return h(Row, { key: item[0], title: item[1] },
899
917
  h("input", {
@@ -903,9 +921,10 @@ window.__ModuleLoader__.load({
903
921
  onChange: function (event) { setValue(item[0], event.target.value) },
904
922
  }))
905
923
  }),
906
- h("div", { style: T.actions },
924
+ h("div", { style: T.stickyBottom },
907
925
  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() } }, "重新读取")),
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 + " 项未保存)")),
909
928
  h("div", { style: T.sectionTitle }, "运行日志(最近 200 行)"),
910
929
  h("div", { style: T.actions },
911
930
  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.0",
3
+ "version": "0.3.1",
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",