dsh-chat-comprehension 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (364) hide show
  1. package/NOTICE.md +20 -0
  2. package/README.md +20 -9
  3. package/client.js +30 -9
  4. package/lib/engines.mjs +136 -0
  5. package/lib/index.js +37 -4
  6. package/lib/qqbot-0.5.3-patches.json +75 -70
  7. package/lib/qqbot-patch.mjs +12 -7
  8. package/lib/video.mjs +11 -2
  9. package/package.json +7 -23
  10. package/vendor/dsh-agent-md/LICENSE +21 -0
  11. package/vendor/dsh-agent-md/cordis.patch.yml +8 -0
  12. package/vendor/dsh-agent-md/lib/index.js +775 -0
  13. package/vendor/dsh-agent-md/lib/persona.js +634 -0
  14. package/vendor/dsh-agent-md/lib/qq.js +527 -0
  15. package/vendor/dsh-agent-md/package.json +50 -0
  16. package/vendor/dsh-bili-scroll/LICENSE +21 -0
  17. package/vendor/dsh-bili-scroll/NOTICE.md +18 -0
  18. package/vendor/dsh-bili-scroll/cordis.patch.yml +20 -0
  19. package/vendor/dsh-bili-scroll/index.js +3278 -0
  20. package/vendor/dsh-bili-scroll/lib/asr.py +141 -0
  21. package/vendor/dsh-bili-scroll/lib/diagnose.mjs +95 -0
  22. package/vendor/dsh-bili-scroll/lib/dm.mjs +110 -0
  23. package/vendor/dsh-bili-scroll/lib/favops.py +90 -0
  24. package/vendor/dsh-bili-scroll/lib/hostdeps.mjs +148 -0
  25. package/vendor/dsh-bili-scroll/lib/login.mjs +141 -0
  26. package/vendor/dsh-bili-scroll/lib/mcp.mjs +144 -0
  27. package/vendor/dsh-bili-scroll/lib/state.mjs +236 -0
  28. package/vendor/dsh-bili-scroll/lib/uid.mjs +61 -0
  29. package/vendor/dsh-bili-scroll/lib/uvfetch.mjs +217 -0
  30. package/vendor/dsh-bili-scroll/lib/verify.mjs +184 -0
  31. package/vendor/dsh-bili-scroll/package.json +84 -0
  32. package/vendor/dsh-bili-scroll/profile-template/bili-duty/cordis.patch.yml +116 -0
  33. package/vendor/dsh-bili-scroll/profile-template/bili-duty/cordis.yml +4 -0
  34. package/vendor/dsh-bili-scroll/profile-template/bili-duty/package.json +13 -0
  35. package/vendor/dsh-bili-scroll/prompts/duty.md +296 -0
  36. package/vendor/dsh-bili-scroll/vendor/bilibili-mcp/LICENSE +21 -0
  37. package/vendor/dsh-bili-scroll/vendor/bilibili-mcp/README.md +176 -0
  38. package/vendor/dsh-bili-scroll/vendor/bilibili-mcp/mcp_server.py +2015 -0
  39. package/vendor/dsh-bili-scroll/vendor/bilibili-mcp/requirements.txt +10 -0
  40. package/vendor/dsh-meme/.dsh/skills/dsh-meme-maintenance/SKILL.md +50 -0
  41. package/vendor/dsh-meme/LICENSE +21 -0
  42. package/vendor/dsh-meme/anim.js +588 -0
  43. package/vendor/dsh-meme/cordis.patch.yml +13 -0
  44. package/vendor/dsh-meme/icon.jpg +0 -0
  45. package/vendor/dsh-meme/index.js +2616 -0
  46. package/vendor/dsh-meme/locale/en.json +6 -0
  47. package/vendor/dsh-meme/locale/zh.json +6 -0
  48. package/vendor/dsh-meme/memes/dafeiyu-001/index.db +0 -0
  49. package/vendor/dsh-meme/memes/dafeiyu-001/manifest.json +13 -0
  50. package/vendor/dsh-meme/memes/dafeiyu-001/memes/angry/shengqi.jpg +0 -0
  51. package/vendor/dsh-meme/memes/dafeiyu-001/memes/baka/xianqi.jpg +0 -0
  52. package/vendor/dsh-meme/memes/dafeiyu-001/memes/color/huachi.jpg +0 -0
  53. package/vendor/dsh-meme/memes/dafeiyu-001/memes/confused/jiazai.jpg +0 -0
  54. package/vendor/dsh-meme/memes/dafeiyu-001/memes/confused/wenhao.jpg +0 -0
  55. package/vendor/dsh-meme/memes/dafeiyu-001/memes/cpu/jiaban.jpg +0 -0
  56. package/vendor/dsh-meme/memes/dafeiyu-001/memes/daily/ganfan.jpg +0 -0
  57. package/vendor/dsh-meme/memes/dafeiyu-001/memes/fool/buyao.jpg +0 -0
  58. package/vendor/dsh-meme/memes/dafeiyu-001/memes/givemoney/yaoqian.jpg +0 -0
  59. package/vendor/dsh-meme/memes/dafeiyu-001/memes/happy/deyi.jpg +0 -0
  60. package/vendor/dsh-meme/memes/dafeiyu-001/memes/happy/ok.jpg +0 -0
  61. package/vendor/dsh-meme/memes/dafeiyu-001/memes/happy/piaole.jpg +0 -0
  62. package/vendor/dsh-meme/memes/dafeiyu-001/memes/like/bixin.jpg +0 -0
  63. package/vendor/dsh-meme/memes/dafeiyu-001/memes/meow/maozhua.jpg +0 -0
  64. package/vendor/dsh-meme/memes/dafeiyu-001/memes/morning/zaoshanghao.jpg +0 -0
  65. package/vendor/dsh-meme/memes/dafeiyu-001/memes/sad/qiurao.jpg +0 -0
  66. package/vendor/dsh-meme/memes/dafeiyu-001/memes/sad/yun.jpg +0 -0
  67. package/vendor/dsh-meme/memes/dafeiyu-001/memes/see/zhenjing.jpg +0 -0
  68. package/vendor/dsh-meme/memes/dafeiyu-001/memes/shy/haixiu.jpg +0 -0
  69. package/vendor/dsh-meme/memes/dafeiyu-001/memes/shy/toukan.jpg +0 -0
  70. package/vendor/dsh-meme/memes/dafeiyu-001/memes/sigh/wuyu.jpg +0 -0
  71. package/vendor/dsh-meme/memes/dafeiyu-001/memes/sleep/shuijiao.jpg +0 -0
  72. package/vendor/dsh-meme/memes/dafeiyu-001/memes/surprised/xia.jpg +0 -0
  73. package/vendor/dsh-meme/memes/dafeiyu-001/memes/work/tangping.jpg +0 -0
  74. package/vendor/dsh-meme/memes.js +998 -0
  75. package/vendor/dsh-meme/package.json +67 -0
  76. package/vendor/dsh-meme/panel.html +210 -0
  77. package/vendor/dsh-video-storyboard/LICENSE +21 -0
  78. package/vendor/dsh-video-storyboard/NOTICE +12 -0
  79. package/vendor/dsh-video-storyboard/bin/_args.mjs +16 -0
  80. package/vendor/dsh-video-storyboard/bin/asr-check.mjs +85 -0
  81. package/vendor/dsh-video-storyboard/bin/scan-stats.mjs +43 -0
  82. package/vendor/dsh-video-storyboard/bin/scan-video.mjs +38 -0
  83. package/vendor/dsh-video-storyboard/bin/storyboard.mjs +195 -0
  84. package/vendor/dsh-video-storyboard/cordis.patch.yml +3 -0
  85. package/vendor/dsh-video-storyboard/dsh.plugin.json +12 -0
  86. package/vendor/dsh-video-storyboard/package.json +88 -0
  87. package/vendor/dsh-video-storyboard/scripts/check-syntax.mjs +56 -0
  88. package/vendor/dsh-video-storyboard/scripts/install-dev.mjs +104 -0
  89. package/vendor/dsh-video-storyboard/src/flicker.js +104 -0
  90. package/vendor/dsh-video-storyboard/src/index.js +82 -0
  91. package/vendor/dsh-video-storyboard/src/ocr_bridge.py +103 -0
  92. package/vendor/dsh-video-storyboard/src/storyboard/asr-lifecycle.js +262 -0
  93. package/vendor/dsh-video-storyboard/src/storyboard/asr.js +488 -0
  94. package/vendor/dsh-video-storyboard/src/storyboard/audio.js +168 -0
  95. package/vendor/dsh-video-storyboard/src/storyboard/binaries.js +69 -0
  96. package/vendor/dsh-video-storyboard/src/storyboard/board.js +121 -0
  97. package/vendor/dsh-video-storyboard/src/storyboard/browser-time.js +504 -0
  98. package/vendor/dsh-video-storyboard/src/storyboard/cache.js +143 -0
  99. package/vendor/dsh-video-storyboard/src/storyboard/cells.js +70 -0
  100. package/vendor/dsh-video-storyboard/src/storyboard/density.js +545 -0
  101. package/vendor/dsh-video-storyboard/src/storyboard/direct-url.js +130 -0
  102. package/vendor/dsh-video-storyboard/src/storyboard/fetch.js +373 -0
  103. package/vendor/dsh-video-storyboard/src/storyboard/flash.js +180 -0
  104. package/vendor/dsh-video-storyboard/src/storyboard/format.js +573 -0
  105. package/vendor/dsh-video-storyboard/src/storyboard/frames.js +212 -0
  106. package/vendor/dsh-video-storyboard/src/storyboard/index.js +32 -0
  107. package/vendor/dsh-video-storyboard/src/storyboard/injection.js +76 -0
  108. package/vendor/dsh-video-storyboard/src/storyboard/layout-order.js +176 -0
  109. package/vendor/dsh-video-storyboard/src/storyboard/locate.js +113 -0
  110. package/vendor/dsh-video-storyboard/src/storyboard/media-store.js +106 -0
  111. package/vendor/dsh-video-storyboard/src/storyboard/memory.js +94 -0
  112. package/vendor/dsh-video-storyboard/src/storyboard/ocr-subs.js +107 -0
  113. package/vendor/dsh-video-storyboard/src/storyboard/ocr.js +167 -0
  114. package/vendor/dsh-video-storyboard/src/storyboard/pipeline.js +853 -0
  115. package/vendor/dsh-video-storyboard/src/storyboard/plan.js +400 -0
  116. package/vendor/dsh-video-storyboard/src/storyboard/probe.js +132 -0
  117. package/vendor/dsh-video-storyboard/src/storyboard/provenance.js +44 -0
  118. package/vendor/dsh-video-storyboard/src/storyboard/python.js +84 -0
  119. package/vendor/dsh-video-storyboard/src/storyboard/register.js +32 -0
  120. package/vendor/dsh-video-storyboard/src/storyboard/scan.js +486 -0
  121. package/vendor/dsh-video-storyboard/src/storyboard/segments.js +117 -0
  122. package/vendor/dsh-video-storyboard/src/storyboard/sheet.js +507 -0
  123. package/vendor/dsh-video-storyboard/src/storyboard/storage.js +93 -0
  124. package/vendor/dsh-video-storyboard/src/storyboard/subtitles.js +181 -0
  125. package/vendor/dsh-video-storyboard/src/storyboard/tool-spec.js +544 -0
  126. package/vendor/dsh-video-storyboard/src/storyboard/transcript-file.js +146 -0
  127. package/vendor/dsh-video-storyboard/src/storyboard/url.js +69 -0
  128. package/vendor/dsh-video-storyboard/src/storyboard/ytdlp.js +289 -0
  129. package/vendor/dsh-video-storyboard/src/tool-spec.js +17 -0
  130. package/vendor/dsh-video-storyboard/src/tools/locate.js +39 -0
  131. package/vendor/dsh-video-storyboard/src/tools/probe.js +23 -0
  132. package/vendor/dsh-video-storyboard/src/tools/shared.js +39 -0
  133. package/vendor/dsh-video-storyboard/src/tools/storyboard.js +20 -0
  134. package/vendor/dsh-video-storyboard/src/tools/zoom.js +56 -0
  135. package/vendor/dsh-world/LICENSE +21 -0
  136. package/vendor/dsh-world/assets/qq-card.png +0 -0
  137. package/vendor/dsh-world/cordis.patch.yml +6 -0
  138. package/vendor/dsh-world/lib/archive.d.ts +6 -0
  139. package/vendor/dsh-world/lib/archive.js +49 -0
  140. package/vendor/dsh-world/lib/archiveSelection.d.ts +8 -0
  141. package/vendor/dsh-world/lib/archiveSelection.js +20 -0
  142. package/vendor/dsh-world/lib/compaction.d.ts +124 -0
  143. package/vendor/dsh-world/lib/compaction.js +273 -0
  144. package/vendor/dsh-world/lib/compactionRegion.d.ts +42 -0
  145. package/vendor/dsh-world/lib/compactionRegion.js +210 -0
  146. package/vendor/dsh-world/lib/console/routes.d.ts +57 -0
  147. package/vendor/dsh-world/lib/console/routes.js +129 -0
  148. package/vendor/dsh-world/lib/console/snapshot.d.ts +39 -0
  149. package/vendor/dsh-world/lib/console/snapshot.js +51 -0
  150. package/vendor/dsh-world/lib/ecosystem/bridge/bridge.d.ts +36 -0
  151. package/vendor/dsh-world/lib/ecosystem/bridge/bridge.js +140 -0
  152. package/vendor/dsh-world/lib/ecosystem/bridge/route.d.ts +9 -0
  153. package/vendor/dsh-world/lib/ecosystem/bridge/route.js +46 -0
  154. package/vendor/dsh-world/lib/ecosystem/qq/bridge.d.ts +123 -0
  155. package/vendor/dsh-world/lib/ecosystem/qq/bridge.js +380 -0
  156. package/vendor/dsh-world/lib/ecosystem/qq/panel.d.ts +75 -0
  157. package/vendor/dsh-world/lib/ecosystem/qq/panel.js +187 -0
  158. package/vendor/dsh-world/lib/ecosystem/qq/route.d.ts +32 -0
  159. package/vendor/dsh-world/lib/ecosystem/qq/route.js +134 -0
  160. package/vendor/dsh-world/lib/ecosystem/qq/supervisor.d.ts +57 -0
  161. package/vendor/dsh-world/lib/ecosystem/qq/supervisor.js +188 -0
  162. package/vendor/dsh-world/lib/ecosystem/shared/context.d.ts +14 -0
  163. package/vendor/dsh-world/lib/ecosystem/shared/context.js +42 -0
  164. package/vendor/dsh-world/lib/ecosystem/shared/identity.d.ts +15 -0
  165. package/vendor/dsh-world/lib/ecosystem/shared/identity.js +36 -0
  166. package/vendor/dsh-world/lib/ecosystem/shared/outlets.d.ts +43 -0
  167. package/vendor/dsh-world/lib/ecosystem/shared/outlets.js +70 -0
  168. package/vendor/dsh-world/lib/ecosystem/shared/sessions.d.ts +16 -0
  169. package/vendor/dsh-world/lib/ecosystem/shared/sessions.js +52 -0
  170. package/vendor/dsh-world/lib/ecosystem/wechat/archive.d.ts +24 -0
  171. package/vendor/dsh-world/lib/ecosystem/wechat/archive.js +62 -0
  172. package/vendor/dsh-world/lib/ecosystem/wechat/home.d.ts +21 -0
  173. package/vendor/dsh-world/lib/ecosystem/wechat/home.js +111 -0
  174. package/vendor/dsh-world/lib/ecosystem/wechat/images.d.ts +5 -0
  175. package/vendor/dsh-world/lib/ecosystem/wechat/images.js +43 -0
  176. package/vendor/dsh-world/lib/ecosystem/wechat/index.d.ts +41 -0
  177. package/vendor/dsh-world/lib/ecosystem/wechat/index.js +166 -0
  178. package/vendor/dsh-world/lib/ecosystem/wechat/messages.d.ts +24 -0
  179. package/vendor/dsh-world/lib/ecosystem/wechat/messages.js +35 -0
  180. package/vendor/dsh-world/lib/ecosystem/wechat/sending.d.ts +30 -0
  181. package/vendor/dsh-world/lib/ecosystem/wechat/sending.js +216 -0
  182. package/vendor/dsh-world/lib/ecosystem/wechat/supervisor.d.ts +39 -0
  183. package/vendor/dsh-world/lib/ecosystem/wechat/supervisor.js +138 -0
  184. package/vendor/dsh-world/lib/faults.d.ts +10 -0
  185. package/vendor/dsh-world/lib/faults.js +13 -0
  186. package/vendor/dsh-world/lib/history.d.ts +16 -0
  187. package/vendor/dsh-world/lib/history.js +80 -0
  188. package/vendor/dsh-world/lib/hostContract.d.ts +19 -0
  189. package/vendor/dsh-world/lib/hostContract.js +1 -0
  190. package/vendor/dsh-world/lib/http.d.ts +18 -0
  191. package/vendor/dsh-world/lib/http.js +39 -0
  192. package/vendor/dsh-world/lib/index.d.ts +108 -0
  193. package/vendor/dsh-world/lib/index.js +356 -0
  194. package/vendor/dsh-world/lib/life/activity.d.ts +14 -0
  195. package/vendor/dsh-world/lib/life/activity.js +58 -0
  196. package/vendor/dsh-world/lib/life/alarm.d.ts +39 -0
  197. package/vendor/dsh-world/lib/life/alarm.js +132 -0
  198. package/vendor/dsh-world/lib/life/alarmTimer.d.ts +22 -0
  199. package/vendor/dsh-world/lib/life/alarmTimer.js +49 -0
  200. package/vendor/dsh-world/lib/life/diary.d.ts +4 -0
  201. package/vendor/dsh-world/lib/life/diary.js +9 -0
  202. package/vendor/dsh-world/lib/life/earlyStop.d.ts +19 -0
  203. package/vendor/dsh-world/lib/life/earlyStop.js +25 -0
  204. package/vendor/dsh-world/lib/life/home.d.ts +34 -0
  205. package/vendor/dsh-world/lib/life/home.js +91 -0
  206. package/vendor/dsh-world/lib/life/host.d.ts +22 -0
  207. package/vendor/dsh-world/lib/life/host.js +24 -0
  208. package/vendor/dsh-world/lib/life/journal.d.ts +20 -0
  209. package/vendor/dsh-world/lib/life/journal.js +59 -0
  210. package/vendor/dsh-world/lib/life/lifeStore.d.ts +16 -0
  211. package/vendor/dsh-world/lib/life/lifeStore.js +105 -0
  212. package/vendor/dsh-world/lib/life/messages.d.ts +17 -0
  213. package/vendor/dsh-world/lib/life/messages.js +53 -0
  214. package/vendor/dsh-world/lib/life/notify.d.ts +15 -0
  215. package/vendor/dsh-world/lib/life/notify.js +40 -0
  216. package/vendor/dsh-world/lib/life/pricing.d.ts +4 -0
  217. package/vendor/dsh-world/lib/life/pricing.js +30 -0
  218. package/vendor/dsh-world/lib/life/runtime.d.ts +52 -0
  219. package/vendor/dsh-world/lib/life/runtime.js +376 -0
  220. package/vendor/dsh-world/lib/life/toolRegistry.d.ts +22 -0
  221. package/vendor/dsh-world/lib/life/toolRegistry.js +64 -0
  222. package/vendor/dsh-world/lib/life/tools.d.ts +24 -0
  223. package/vendor/dsh-world/lib/life/tools.js +47 -0
  224. package/vendor/dsh-world/lib/life/types.d.ts +67 -0
  225. package/vendor/dsh-world/lib/life/types.js +1 -0
  226. package/vendor/dsh-world/lib/persona.d.ts +10 -0
  227. package/vendor/dsh-world/lib/persona.js +29 -0
  228. package/vendor/dsh-world/lib/promptSection.d.ts +30 -0
  229. package/vendor/dsh-world/lib/promptSection.js +81 -0
  230. package/vendor/dsh-world/lib/qqScope.d.ts +11 -0
  231. package/vendor/dsh-world/lib/qqScope.js +39 -0
  232. package/vendor/dsh-world/lib/runtime.d.ts +23 -0
  233. package/vendor/dsh-world/lib/runtime.js +206 -0
  234. package/vendor/dsh-world/lib/self.d.ts +10 -0
  235. package/vendor/dsh-world/lib/self.js +36 -0
  236. package/vendor/dsh-world/lib/sourceArchive.d.ts +28 -0
  237. package/vendor/dsh-world/lib/sourceArchive.js +156 -0
  238. package/vendor/dsh-world/lib/store.d.ts +30 -0
  239. package/vendor/dsh-world/lib/store.js +191 -0
  240. package/vendor/dsh-world/lib/timeContext.d.ts +3 -0
  241. package/vendor/dsh-world/lib/timeContext.js +13 -0
  242. package/vendor/dsh-world/lib/types.d.ts +118 -0
  243. package/vendor/dsh-world/lib/types.js +1 -0
  244. package/vendor/dsh-world/lib/worldPrompt.d.ts +47 -0
  245. package/vendor/dsh-world/lib/worldPrompt.js +49 -0
  246. package/vendor/dsh-world/lib/worldSwitch.d.ts +44 -0
  247. package/vendor/dsh-world/lib/worldSwitch.js +78 -0
  248. package/vendor/dsh-world/package-lock.json +1088 -0
  249. package/vendor/dsh-world/package.json +88 -0
  250. package/vendor/dsh-world/scripts/enable-tool-free-compaction.ps1 +33 -0
  251. package/vendor/dsh-world/src/archive.ts +45 -0
  252. package/vendor/dsh-world/src/archiveSelection.ts +27 -0
  253. package/vendor/dsh-world/src/compaction.ts +260 -0
  254. package/vendor/dsh-world/src/compactionRegion.ts +172 -0
  255. package/vendor/dsh-world/src/console/routes.ts +125 -0
  256. package/vendor/dsh-world/src/console/snapshot.ts +84 -0
  257. package/vendor/dsh-world/src/ecosystem/README.md +14 -0
  258. package/vendor/dsh-world/src/ecosystem/bridge/bridge.ts +121 -0
  259. package/vendor/dsh-world/src/ecosystem/bridge/route.ts +35 -0
  260. package/vendor/dsh-world/src/ecosystem/qq/bridge.ts +456 -0
  261. package/vendor/dsh-world/src/ecosystem/qq/panel.ts +178 -0
  262. package/vendor/dsh-world/src/ecosystem/qq/route.ts +130 -0
  263. package/vendor/dsh-world/src/ecosystem/qq/supervisor.ts +262 -0
  264. package/vendor/dsh-world/src/ecosystem/shared/context.ts +38 -0
  265. package/vendor/dsh-world/src/ecosystem/shared/identity.ts +42 -0
  266. package/vendor/dsh-world/src/ecosystem/shared/outlets.ts +75 -0
  267. package/vendor/dsh-world/src/ecosystem/shared/sessions.ts +47 -0
  268. package/vendor/dsh-world/src/ecosystem/wechat/archive.ts +66 -0
  269. package/vendor/dsh-world/src/ecosystem/wechat/home.ts +94 -0
  270. package/vendor/dsh-world/src/ecosystem/wechat/images.ts +38 -0
  271. package/vendor/dsh-world/src/ecosystem/wechat/index.ts +101 -0
  272. package/vendor/dsh-world/src/ecosystem/wechat/messages.ts +43 -0
  273. package/vendor/dsh-world/src/ecosystem/wechat/sending.ts +177 -0
  274. package/vendor/dsh-world/src/ecosystem/wechat/supervisor.ts +116 -0
  275. package/vendor/dsh-world/src/ecosystem/wechat/windows/README.md +117 -0
  276. package/vendor/dsh-world/src/ecosystem/wechat/windows/adapter.py +572 -0
  277. package/vendor/dsh-world/src/ecosystem/wechat/windows/binding.py +52 -0
  278. package/vendor/dsh-world/src/ecosystem/wechat/windows/engine/LICENSE +43 -0
  279. package/vendor/dsh-world/src/ecosystem/wechat/windows/engine/NOTICE.md +10 -0
  280. package/vendor/dsh-world/src/ecosystem/wechat/windows/engine/bridge.cpp +229 -0
  281. package/vendor/dsh-world/src/ecosystem/wechat/windows/engine/build.ps1 +19 -0
  282. package/vendor/dsh-world/src/ecosystem/wechat/windows/engine/profile.json +28 -0
  283. package/vendor/dsh-world/src/ecosystem/wechat/windows/groups.py +42 -0
  284. package/vendor/dsh-world/src/ecosystem/wechat/windows/incoming.py +157 -0
  285. package/vendor/dsh-world/src/ecosystem/wechat/windows/native.py +168 -0
  286. package/vendor/dsh-world/src/ecosystem/wechat/windows/outgoing.py +95 -0
  287. package/vendor/dsh-world/src/ecosystem/wechat/windows/requirements.txt +1 -0
  288. package/vendor/dsh-world/src/ecosystem/wechat/windows/sender.py +157 -0
  289. package/vendor/dsh-world/src/ecosystem/wechat/windows/snapshot.py +32 -0
  290. package/vendor/dsh-world/src/ecosystem/wechat/windows/stickers.py +60 -0
  291. package/vendor/dsh-world/src/ecosystem/wechat/windows/wechat.ps1 +75 -0
  292. package/vendor/dsh-world/src/faults.ts +12 -0
  293. package/vendor/dsh-world/src/history.ts +77 -0
  294. package/vendor/dsh-world/src/hostContract.ts +9 -0
  295. package/vendor/dsh-world/src/http.ts +34 -0
  296. package/vendor/dsh-world/src/index.ts +286 -0
  297. package/vendor/dsh-world/src/life/activity.ts +48 -0
  298. package/vendor/dsh-world/src/life/alarm.ts +119 -0
  299. package/vendor/dsh-world/src/life/alarmTimer.ts +45 -0
  300. package/vendor/dsh-world/src/life/diary.ts +10 -0
  301. package/vendor/dsh-world/src/life/earlyStop.ts +27 -0
  302. package/vendor/dsh-world/src/life/home.ts +85 -0
  303. package/vendor/dsh-world/src/life/host.ts +50 -0
  304. package/vendor/dsh-world/src/life/journal.ts +44 -0
  305. package/vendor/dsh-world/src/life/lifeStore.ts +70 -0
  306. package/vendor/dsh-world/src/life/messages.ts +44 -0
  307. package/vendor/dsh-world/src/life/notify.ts +47 -0
  308. package/vendor/dsh-world/src/life/pricing.ts +37 -0
  309. package/vendor/dsh-world/src/life/runtime.ts +318 -0
  310. package/vendor/dsh-world/src/life/toolRegistry.ts +48 -0
  311. package/vendor/dsh-world/src/life/tools.ts +61 -0
  312. package/vendor/dsh-world/src/life/types.ts +19 -0
  313. package/vendor/dsh-world/src/persona.ts +26 -0
  314. package/vendor/dsh-world/src/promptSection.ts +71 -0
  315. package/vendor/dsh-world/src/qqScope.ts +51 -0
  316. package/vendor/dsh-world/src/runtime.ts +172 -0
  317. package/vendor/dsh-world/src/self.ts +32 -0
  318. package/vendor/dsh-world/src/sourceArchive.ts +132 -0
  319. package/vendor/dsh-world/src/store.ts +170 -0
  320. package/vendor/dsh-world/src/timeContext.ts +13 -0
  321. package/vendor/dsh-world/src/types.ts +112 -0
  322. package/vendor/dsh-world/src/worldPrompt.ts +64 -0
  323. package/vendor/dsh-world/src/worldSwitch.ts +82 -0
  324. package/vendor/dsh-world/templates/alarm.md +49 -0
  325. package/vendor/dsh-world/templates/world-prompt.md +7 -0
  326. package/vendor/dsh-world/tests/archive.test.ts +57 -0
  327. package/vendor/dsh-world/tests/archiveScope.test.ts +86 -0
  328. package/vendor/dsh-world/tests/bridge.test.ts +211 -0
  329. package/vendor/dsh-world/tests/channelSessions.test.ts +79 -0
  330. package/vendor/dsh-world/tests/clientHooks.test.ts +103 -0
  331. package/vendor/dsh-world/tests/compaction.test.ts +141 -0
  332. package/vendor/dsh-world/tests/console.test.ts +202 -0
  333. package/vendor/dsh-world/tests/consoleClient.test.ts +101 -0
  334. package/vendor/dsh-world/tests/enableCompaction.test.ts +19 -0
  335. package/vendor/dsh-world/tests/fixtures.ts +6 -0
  336. package/vendor/dsh-world/tests/history.test.ts +100 -0
  337. package/vendor/dsh-world/tests/hostFixture.ts +46 -0
  338. package/vendor/dsh-world/tests/lifeActivity.test.ts +70 -0
  339. package/vendor/dsh-world/tests/lifeAlarm.test.ts +87 -0
  340. package/vendor/dsh-world/tests/lifeDiary.test.ts +33 -0
  341. package/vendor/dsh-world/tests/lifeMessages.test.ts +61 -0
  342. package/vendor/dsh-world/tests/lifeNotify.test.ts +46 -0
  343. package/vendor/dsh-world/tests/lifeParts.test.ts +45 -0
  344. package/vendor/dsh-world/tests/lifeRuntime.test.ts +660 -0
  345. package/vendor/dsh-world/tests/lifeStore.test.ts +90 -0
  346. package/vendor/dsh-world/tests/lifeTools.test.ts +53 -0
  347. package/vendor/dsh-world/tests/outlets.test.ts +85 -0
  348. package/vendor/dsh-world/tests/panel.test.ts +85 -0
  349. package/vendor/dsh-world/tests/plugin.test.ts +614 -0
  350. package/vendor/dsh-world/tests/pricing.test.ts +21 -0
  351. package/vendor/dsh-world/tests/qq.test.ts +121 -0
  352. package/vendor/dsh-world/tests/qqSessionMode.test.ts +97 -0
  353. package/vendor/dsh-world/tests/qqSupervisor.test.ts +149 -0
  354. package/vendor/dsh-world/tests/sourceArchive.test.ts +58 -0
  355. package/vendor/dsh-world/tests/store.test.ts +82 -0
  356. package/vendor/dsh-world/tests/storeWriter.ts +5 -0
  357. package/vendor/dsh-world/tests/timeContext.test.ts +15 -0
  358. package/vendor/dsh-world/tests/wechat.test.ts +254 -0
  359. package/vendor/dsh-world/tests/wechatImages.test.ts +130 -0
  360. package/vendor/dsh-world/tests/wechatSending.test.ts +142 -0
  361. package/vendor/dsh-world/tests/wechatSupervisor.test.ts +91 -0
  362. package/vendor/dsh-world/tests/worldPrompt.test.ts +201 -0
  363. package/vendor/dsh-world/tsconfig.build.json +5 -0
  364. package/vendor/dsh-world/tsconfig.json +8 -0
@@ -0,0 +1,9 @@
1
+ import type { IncomingMessage, ServerResponse } from 'node:http';
2
+ import { type Bridge } from './bridge.ts';
3
+ export declare const BRIDGE_PATH = "/dsh-world/bridge/say";
4
+ /** The one outside route that changes something: a local app hands her partner's words to her home. */
5
+ export declare function bridgeRoute(bridge: () => Bridge | undefined, allowedHosts?: readonly string[]): {
6
+ kind: "exact";
7
+ path: string;
8
+ handler: (req: IncomingMessage, res: ServerResponse) => Promise<void>;
9
+ };
@@ -0,0 +1,46 @@
1
+ import { jsonObject, knownHost, readBody, sendJson } from "../../http.js";
2
+ import { HomeUnavailable } from "./bridge.js";
3
+ export const BRIDGE_PATH = '/dsh-world/bridge/say';
4
+ const MAX_BODY_BYTES = 32 * 1024;
5
+ const MAX_TEXT = 2000;
6
+ const bad = { status: 400, body: { error: 'bad request' } };
7
+ const unavailable = { status: 503, body: { error: 'home unavailable' } };
8
+ async function handleSay(bridge, req, allowedHosts) {
9
+ if (req.method !== 'POST')
10
+ return { status: 405, body: { error: 'method not allowed' }, headers: { allow: 'POST' } };
11
+ const token = req.headers['x-dsh-world-token'];
12
+ if (req.headers['sec-fetch-site'] === 'cross-site' || !knownHost(req.headers.host, allowedHosts))
13
+ return { status: 403, body: { error: 'forbidden' } };
14
+ // While her world is stopped there is no bridge and no token to check against.
15
+ if (!bridge)
16
+ return unavailable;
17
+ if (!bridge.checkToken(Array.isArray(token) ? undefined : token))
18
+ return { status: 403, body: { error: 'forbidden' } };
19
+ const body = jsonObject(await readBody(req, MAX_BODY_BYTES));
20
+ const text = typeof body?.text === 'string' ? body.text.trim() : '';
21
+ const length = [...text].length;
22
+ if (length < 1 || length > MAX_TEXT)
23
+ return bad;
24
+ try {
25
+ return { status: 202, body: { accepted: true, id: (await bridge.say(text)).id } };
26
+ }
27
+ catch (error) {
28
+ return error instanceof HomeUnavailable ? unavailable : { status: 500, body: { error: 'internal error' } };
29
+ }
30
+ }
31
+ /** The one outside route that changes something: a local app hands her partner's words to her home. */
32
+ export function bridgeRoute(bridge, allowedHosts = []) {
33
+ return {
34
+ kind: 'exact', path: BRIDGE_PATH,
35
+ handler: async (req, res) => {
36
+ let result;
37
+ try {
38
+ result = await handleSay(bridge(), req, allowedHosts);
39
+ }
40
+ catch {
41
+ result = { status: 500, body: { error: 'internal error' } };
42
+ }
43
+ sendJson(res, result);
44
+ },
45
+ };
46
+ }
@@ -0,0 +1,123 @@
1
+ /** The host logger, or nothing at all when the module runs without one. */
2
+ export interface QqLogger {
3
+ info?(message: string): void;
4
+ warn?(message: string): void;
5
+ }
6
+ export interface QqSessionEntry {
7
+ key: string;
8
+ sessionId: string;
9
+ owner: boolean;
10
+ }
11
+ /**
12
+ * 桥自己记下的运行意图。`stopped` 只可能来自一次显式的 `/api/stop`(或插件 halt),
13
+ * 意思是「人让它停的,别再自动拉」。巡检靠它区分「死了」和「关掉了」。
14
+ */
15
+ export interface QqIntent {
16
+ desired: 'running' | 'stopped';
17
+ at: number;
18
+ by: string;
19
+ }
20
+ /** What the console shows: is it up, is it talking to DSH, which entries are bound where. */
21
+ export interface QqStatus {
22
+ running: boolean;
23
+ port: number;
24
+ dir: string;
25
+ /** `reserved2` / `closed-agent` …; absent while the bridge is not answering. */
26
+ mode?: string | null;
27
+ /** DSH answers the bridge's own API calls — this is what goes false first when DSH moves to a new port. */
28
+ dsh?: boolean;
29
+ /** The QQ protocol side is online; when it drops, messages stop arriving. */
30
+ connected?: boolean;
31
+ accountOnline?: boolean;
32
+ lastPacketAgoMs?: number | null;
33
+ ownerQQ?: string | null;
34
+ allowGroups?: string[];
35
+ sessions: QqSessionEntry[];
36
+ faults: string[];
37
+ /** 上次是「想跑」还是「想停」。桥不在线时从 state 文件读,在线时取桥自报的值。 */
38
+ intent: QqIntent;
39
+ /** 巡检状态:由 index.ts 在 console 快照里填上,桥自己不认识它。 */
40
+ supervisor?: unknown;
41
+ }
42
+ export interface SyncResult {
43
+ changed: boolean;
44
+ reason?: string;
45
+ baseUrl?: string;
46
+ before?: string;
47
+ mode?: string;
48
+ }
49
+ /** 谁和谁共用一个会话:群各自一份,还是所有入口都用她的家会话,还是谁都不绑。 */
50
+ export type BindHomeSession = 'owner' | 'all' | 'none';
51
+ export interface StartResult {
52
+ started: boolean;
53
+ reason?: string;
54
+ }
55
+ export interface StopResult {
56
+ stopped: boolean;
57
+ reason?: string;
58
+ }
59
+ export interface BindResult extends StartResult {
60
+ key: string;
61
+ sessionId?: string;
62
+ }
63
+ export interface SyncEndpointResult extends SyncResult {
64
+ restarted?: boolean;
65
+ }
66
+ export interface QqBridgeOptions {
67
+ /** The qq-bridge checkout; nothing is guessed when this is empty, the module is simply off. */
68
+ dir: string;
69
+ /** The bridge's console port. */
70
+ port?: number;
71
+ /** Node to start the bridge with; the current process by default. */
72
+ nodePath?: string;
73
+ /** DSH's current origin, read fresh every time. */
74
+ origin?: () => string;
75
+ logger?: QqLogger;
76
+ }
77
+ export interface QqBridge {
78
+ status(): Promise<QqStatus>;
79
+ start(): Promise<StartResult>;
80
+ /** 重启式停止:桥会自己回来。给 bind/unbind/syncEndpoint 这类「中间改文件」的场景用。 */
81
+ stop(): Promise<StopResult>;
82
+ /** 真停:桥不会回来,并写下 desired=stopped 让巡检别拉起。 */
83
+ halt(): Promise<StopResult>;
84
+ /** 只读意图文件,不联网;巡检判「该不该拉」用这个。 */
85
+ intent(): QqIntent;
86
+ bind(key: string, sessionId: string): Promise<BindResult>;
87
+ unbind(key: string): Promise<BindResult>;
88
+ ensureRunning(): Promise<StartResult>;
89
+ syncEndpoint(): Promise<SyncEndpointResult>;
90
+ /** 主动聊天的统计:今天花了多少次、平均多少 token、成了几条、被规则拦下几条。读不到返回 undefined。 */
91
+ proactive(): Promise<any>;
92
+ setProactive(patch: {
93
+ enabled?: boolean;
94
+ dryRun?: boolean;
95
+ }): Promise<any>;
96
+ faults(): string[];
97
+ }
98
+ /** The bridge's console token: `config.json` first, else `state/console-token` (rewritten on every start). */
99
+ export declare function readConsoleToken(dir: string): string;
100
+ /**
101
+ * 读桥写下的运行意图。读不到一律当 `running`——未知状态不能变成「永久不启动」,
102
+ * 那是比「该停的又起来了」更难受的故障。
103
+ */
104
+ export declare function readIntent(dir: string): QqIntent;
105
+ /**
106
+ * Writes DSH's current origin back into the bridge's `config.json` (`dsh.baseUrl`).
107
+ *
108
+ * Why the plugin owns this: DSH picks a new port on every restart, the bridge's baseUrl is a fixed value, and
109
+ * nothing complains when it goes stale — `dshReady` just stays false and the event stream reconnects every 30s
110
+ * for zero frames. 2026-10-26 the link sat dead for four hours looking exactly like a crashed bridge.
111
+ */
112
+ export declare function syncBridgeBaseUrl(dir: string, origin: string, logger?: QqLogger): SyncResult;
113
+ /**
114
+ * 谁和谁共用一个会话,写进桥的 `socialV2.bindHomeSession`。
115
+ *
116
+ * 桥自己的默认是「谁都不绑」——装上之后每个群、每条私聊各建一个会话。那通常不是人想要的:主人私聊
117
+ * 应该是她记得的那个家会话,只有群才该各自独立。这个开关让人在插件配置里说一次,不用去翻桥的
118
+ * config.json。
119
+ *
120
+ * 空值表示不碰桥的配置(尊重人自己填的);`none` 表示把这个键删掉,回到桥的默认。
121
+ */
122
+ export declare function syncBridgeSessionMode(dir: string, mode: BindHomeSession | '', logger?: QqLogger): SyncResult;
123
+ export declare function createQqBridge(options: QqBridgeOptions): QqBridge;
@@ -0,0 +1,380 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { existsSync, readFileSync, writeFileSync } from 'node:fs';
3
+ import { join } from 'node:path';
4
+ /**
5
+ * QQ: the outside `qq-bridge` process, managed as one more pipe into her home.
6
+ *
7
+ * Why it belongs here rather than in a .bat: the bridge is a separate process, and before this it took a
8
+ * launcher by hand plus editing `state/sessions.json` by hand to point a QQ entry at a session. Inside the
9
+ * plugin those become a click in the world console, and they share one lifecycle with memory, diary and the
10
+ * life line. Nothing of the bridge's own logic is copied — this only probes, starts, stops, binds and reports.
11
+ */
12
+ const PROBE_TIMEOUT_MS = 2500;
13
+ const STOP_WAIT_MS = 8000;
14
+ const START_WAIT_MS = 15000;
15
+ const sleep = (ms) => new Promise(resolve => { setTimeout(resolve, ms); });
16
+ const messageOf = (error) => error instanceof Error ? error.message : String(error);
17
+ /** The bridge's console token: `config.json` first, else `state/console-token` (rewritten on every start). */
18
+ export function readConsoleToken(dir) {
19
+ try {
20
+ const config = JSON.parse(readFileSync(join(dir, 'config.json'), 'utf8'));
21
+ const fromConfig = typeof config?.consoleToken === 'string' ? config.consoleToken.trim() : '';
22
+ if (fromConfig)
23
+ return fromConfig;
24
+ }
25
+ catch {
26
+ // An unreadable config.json is not fatal: there is a second copy below.
27
+ }
28
+ try {
29
+ return readFileSync(join(dir, 'state', 'console-token'), 'utf8').trim();
30
+ }
31
+ catch {
32
+ return '';
33
+ }
34
+ }
35
+ /** PowerShell and Notepad both like to save JSON with a BOM; `JSON.parse` dies on its first character. */
36
+ function readJsonTolerant(file) {
37
+ const raw = readFileSync(file, 'utf8');
38
+ return JSON.parse(raw.charCodeAt(0) === 0xfeff ? raw.slice(1) : raw);
39
+ }
40
+ const INTENT_FILE = 'bridge.intent.json';
41
+ /**
42
+ * 读桥写下的运行意图。读不到一律当 `running`——未知状态不能变成「永久不启动」,
43
+ * 那是比「该停的又起来了」更难受的故障。
44
+ */
45
+ export function readIntent(dir) {
46
+ try {
47
+ const raw = readJsonTolerant(join(dir, 'state', INTENT_FILE));
48
+ return {
49
+ desired: raw?.desired === 'stopped' ? 'stopped' : 'running',
50
+ at: Number(raw?.at) || 0,
51
+ by: String(raw?.by ?? ''),
52
+ };
53
+ }
54
+ catch {
55
+ return { desired: 'running', at: 0, by: '' };
56
+ }
57
+ }
58
+ /**
59
+ * Writes DSH's current origin back into the bridge's `config.json` (`dsh.baseUrl`).
60
+ *
61
+ * Why the plugin owns this: DSH picks a new port on every restart, the bridge's baseUrl is a fixed value, and
62
+ * nothing complains when it goes stale — `dshReady` just stays false and the event stream reconnects every 30s
63
+ * for zero frames. 2026-10-26 the link sat dead for four hours looking exactly like a crashed bridge.
64
+ */
65
+ export function syncBridgeBaseUrl(dir, origin, logger) {
66
+ const url = typeof origin === 'string' ? origin.trim().replace(/\/+$/, '') : '';
67
+ if (!/^https?:\/\/[^/]/i.test(url))
68
+ return { changed: false, reason: 'no-origin' };
69
+ const file = join(dir, 'config.json');
70
+ let config;
71
+ try {
72
+ config = readJsonTolerant(file);
73
+ }
74
+ catch (error) {
75
+ return { changed: false, reason: `config.json 读不到:${messageOf(error)}` };
76
+ }
77
+ config.dsh = config.dsh ?? {};
78
+ const before = typeof config.dsh.baseUrl === 'string' ? config.dsh.baseUrl.trim() : '';
79
+ if (before === url)
80
+ return { changed: false, baseUrl: url };
81
+ config.dsh.baseUrl = url;
82
+ // Written without a BOM: the bridge reads it as utf-8-sig, other tools choke on the BOM.
83
+ writeFileSync(file, `${JSON.stringify(config, null, 2)}\n`, 'utf8');
84
+ logger?.info?.(`[qq] 桥的 DSH 端点已更新:${before || '(空)'} → ${url}`);
85
+ return { changed: true, baseUrl: url, before };
86
+ }
87
+ /**
88
+ * 谁和谁共用一个会话,写进桥的 `socialV2.bindHomeSession`。
89
+ *
90
+ * 桥自己的默认是「谁都不绑」——装上之后每个群、每条私聊各建一个会话。那通常不是人想要的:主人私聊
91
+ * 应该是她记得的那个家会话,只有群才该各自独立。这个开关让人在插件配置里说一次,不用去翻桥的
92
+ * config.json。
93
+ *
94
+ * 空值表示不碰桥的配置(尊重人自己填的);`none` 表示把这个键删掉,回到桥的默认。
95
+ */
96
+ export function syncBridgeSessionMode(dir, mode, logger) {
97
+ if (!mode)
98
+ return { changed: false, reason: 'no-mode' };
99
+ const file = join(dir, 'config.json');
100
+ let config;
101
+ try {
102
+ config = readJsonTolerant(file);
103
+ }
104
+ catch (error) {
105
+ return { changed: false, reason: `config.json 读不到:${messageOf(error)}` };
106
+ }
107
+ const socialV2 = (config.socialV2 = config.socialV2 ?? {});
108
+ const before = typeof socialV2.bindHomeSession === 'string' ? socialV2.bindHomeSession : '';
109
+ if (mode === 'none') {
110
+ if (!('bindHomeSession' in socialV2))
111
+ return { changed: false, mode, before };
112
+ delete socialV2.bindHomeSession;
113
+ writeFileSync(file, `${JSON.stringify(config, null, 2)}\n`, 'utf8');
114
+ logger?.info?.(`[qq] 桥的会话绑定已去掉(原来 ${before || '空'}):每个入口各用各的会话`);
115
+ return { changed: true, mode, before };
116
+ }
117
+ if (before === mode)
118
+ return { changed: false, mode, before };
119
+ socialV2.bindHomeSession = mode;
120
+ writeFileSync(file, `${JSON.stringify(config, null, 2)}\n`, 'utf8');
121
+ logger?.info?.(`[qq] 桥的会话绑定已设为 ${mode}(原来 ${before || '空'}):${mode === 'owner' ? '群各自独立,主人私聊用她的家会话' : '所有入口都用她的家会话'}`);
122
+ return { changed: true, mode, before };
123
+ }
124
+ async function call(base, path, init = {}) {
125
+ const response = await fetch(`${base}${path}`, { ...init, signal: AbortSignal.timeout(PROBE_TIMEOUT_MS) });
126
+ const text = await response.text();
127
+ let body;
128
+ try {
129
+ body = text ? JSON.parse(text) : undefined;
130
+ }
131
+ catch {
132
+ body = { raw: text.slice(0, 400) };
133
+ }
134
+ return { status: response.status, body };
135
+ }
136
+ export function createQqBridge(options) {
137
+ const { dir, logger, port = 3100, nodePath = process.execPath, origin = () => '' } = options;
138
+ const base = `http://127.0.0.1:${port}`;
139
+ const entry = join(dir, 'src', 'bridge.js');
140
+ const stateDir = join(dir, 'state');
141
+ const faults = new Map();
142
+ let child;
143
+ const note = (key, error) => {
144
+ faults.set(key, `${key}:${messageOf(error)}`);
145
+ logger?.warn?.(`[qq] ${key}: ${messageOf(error)}`);
146
+ };
147
+ const clear = (key) => { faults.delete(key); };
148
+ function ensureDir() {
149
+ if (!existsSync(entry))
150
+ throw new Error(`找不到桥的入口:${entry}`);
151
+ }
152
+ /** Whether the bridge is up: `/api/status` wants the console token too (401 without it), so it serves as the probe. */
153
+ async function ping() {
154
+ try {
155
+ const token = readConsoleToken(dir);
156
+ const { status, body } = await call(base, `/api/status${token ? `?token=${encodeURIComponent(token)}` : ''}`);
157
+ return status === 200 ? body ?? {} : undefined;
158
+ }
159
+ catch {
160
+ return undefined;
161
+ }
162
+ }
163
+ /**
164
+ * 主动聊天的统计。
165
+ *
166
+ * 只读:这个方法的唯一用途是给设置页画一张表,它不该能改开关(那要走 POST)。
167
+ * 桥没起来时返回 undefined —— 面板显示「未运行」,而不是报一个错。
168
+ */
169
+ async function proactive() {
170
+ try {
171
+ const token = readConsoleToken(dir);
172
+ const { status, body } = await call(base, `/api/socialV2/proactive${token ? `?token=${encodeURIComponent(token)}` : ''}`);
173
+ return status === 200 ? body ?? {} : undefined;
174
+ }
175
+ catch {
176
+ return undefined;
177
+ }
178
+ }
179
+ /**
180
+ * 改主动聊天的两个开关。
181
+ *
182
+ * 桥收到后会写进它自己的 config.json 并当场生效(引擎的 configure 是就地改),
183
+ * 所以不用重启桥。桥没起来就抛错,让上面那层回 503,而不是假装改成功。
184
+ */
185
+ async function setProactive(patch) {
186
+ const token = readConsoleToken(dir);
187
+ const { status, body } = await call(base, `/api/socialV2/proactive${token ? `?token=${encodeURIComponent(token)}` : ''}`, {
188
+ method: 'POST',
189
+ headers: { 'content-type': 'application/json' },
190
+ body: JSON.stringify(patch),
191
+ });
192
+ if (status !== 200)
193
+ throw new Error(String(body?.error ?? `桥没接受这次改动(HTTP ${status})`));
194
+ return body;
195
+ }
196
+ async function sessions() {
197
+ try {
198
+ const token = readConsoleToken(dir);
199
+ const { status, body } = await call(base, `/api/sessions${token ? `?token=${encodeURIComponent(token)}` : ''}`);
200
+ return status === 200 && Array.isArray(body?.sessions) ? body.sessions : [];
201
+ }
202
+ catch {
203
+ return [];
204
+ }
205
+ }
206
+ async function status() {
207
+ const alive = await ping();
208
+ const stored = readIntent(dir);
209
+ if (!alive)
210
+ return { running: false, port, dir, faults: [...faults.values()], sessions: [], intent: stored };
211
+ const list = await sessions();
212
+ const snowluma = (alive.snowluma ?? {});
213
+ return {
214
+ running: true,
215
+ port,
216
+ dir,
217
+ mode: typeof alive.mode === 'string' ? alive.mode : null,
218
+ dsh: alive.dshReady === true,
219
+ connected: snowluma.connected === true,
220
+ accountOnline: snowluma.accountOnline === true,
221
+ lastPacketAgoMs: snowluma.lastPacketAgoMs ?? null,
222
+ ownerQQ: alive.ownerQQ ?? null,
223
+ allowGroups: Array.isArray(alive.allowGroups) ? alive.allowGroups : [],
224
+ sessions: list.map((item) => ({ key: String(item?.key ?? ''), sessionId: String(item?.sessionId ?? ''), owner: item?.owner === true })),
225
+ faults: [...faults.values()],
226
+ // 桥在线时以它自报的为准:那是最新的(刚被 /api/stop 写过也不会漏),
227
+ // 拿不到就退回文件里的那份。
228
+ intent: alive?.intent?.desired === 'stopped' || alive?.intent?.desired === 'running'
229
+ ? { desired: alive.intent.desired, at: Number(alive.intent.at) || 0, by: String(alive.intent.by ?? '') }
230
+ : stored,
231
+ };
232
+ }
233
+ async function start() {
234
+ ensureDir();
235
+ // Line the endpoint up first: the bridge never notices DSH moved, and this is its only lifeline.
236
+ const synced = syncBridgeBaseUrl(dir, origin(), logger);
237
+ if (await ping()) {
238
+ if (!synced.changed)
239
+ return { started: false, reason: 'already-running' };
240
+ // It already read the old baseUrl into memory — writing the file is not enough, it has to be restarted.
241
+ await stop();
242
+ }
243
+ const proc = spawn(nodePath, ['src/bridge.js'], { cwd: dir, detached: true, stdio: 'ignore', windowsHide: true });
244
+ proc.unref();
245
+ child = proc;
246
+ const deadline = Date.now() + START_WAIT_MS;
247
+ while (Date.now() < deadline) {
248
+ await sleep(600);
249
+ if (await ping()) {
250
+ clear('start');
251
+ return { started: true };
252
+ }
253
+ }
254
+ note('start', new Error(`拉起后 ${START_WAIT_MS / 1000}s 内没连上控制台,去看 state/bridge.log`));
255
+ return { started: false, reason: 'not-ready' };
256
+ }
257
+ /**
258
+ * 重启式停止:打 `/api/restart`,桥先拉起接力子进程再退出,所以它几秒后**自己会回来**。
259
+ *
260
+ * 这个语义对 bind/unbind/syncEndpoint 是**对的**——它们紧接着就要 start(),中间那点空档正好
261
+ * 用来改 `sessions.json` / `config.json`。但它不能当「停止」按钮:用户点停止,桥又活了。
262
+ * 真要停请用 halt()。
263
+ */
264
+ async function stop() {
265
+ const token = readConsoleToken(dir);
266
+ if (!(await ping()))
267
+ return { stopped: false, reason: 'already-stopped' };
268
+ try {
269
+ await call(base, `/api/restart${token ? `?token=${encodeURIComponent(token)}` : ''}`, {
270
+ method: 'POST', headers: { 'content-type': 'application/json' }, body: '{}',
271
+ });
272
+ }
273
+ catch {
274
+ // It drops the connection on the way out; that error is expected.
275
+ }
276
+ const deadline = Date.now() + STOP_WAIT_MS;
277
+ while (Date.now() < deadline) {
278
+ await sleep(400);
279
+ if (!(await ping())) {
280
+ clear('stop');
281
+ return { stopped: true };
282
+ }
283
+ }
284
+ note('stop', new Error('请求重启后端口仍在响应,可能被别的守护进程又拉起来了'));
285
+ return { stopped: false, reason: 'still-alive' };
286
+ }
287
+ /**
288
+ * 真停:打 `/api/stop`,桥写下 `desired=stopped` 的意图、落盘、释放锁、退出,**不拉接力进程**。
289
+ *
290
+ * 意图文件是巡检的唯一判据:`desired=stopped` 时巡检只报状态不拉起。想让它再起来必须显式
291
+ * start()(桥启动成功时会把意图翻回 running)。
292
+ *
293
+ * 旧版桥没有 `/api/stop`(会 404),这时退回 `/api/restart` 并如实报 stop-failed——
294
+ * 宁可界面说「没停干净」,也不要假装停了然后它自己又回来。
295
+ */
296
+ async function halt() {
297
+ ensureDir();
298
+ const token = readConsoleToken(dir);
299
+ if (!(await ping()))
300
+ return { stopped: false, reason: 'already-stopped' };
301
+ let status = 0;
302
+ try {
303
+ const res = await call(base, `/api/stop${token ? `?token=${encodeURIComponent(token)}` : ''}`, {
304
+ method: 'POST', headers: { 'content-type': 'application/json' }, body: '{}',
305
+ });
306
+ status = res.status;
307
+ }
308
+ catch {
309
+ // 退出过程中会掐断连接,这个错误是预期内的。
310
+ }
311
+ const deadline = Date.now() + STOP_WAIT_MS;
312
+ while (Date.now() < deadline) {
313
+ await sleep(300);
314
+ if (!(await ping())) {
315
+ clear('stop');
316
+ return { stopped: true };
317
+ }
318
+ }
319
+ note('stop', new Error(status === 404
320
+ ? '桥没有 /api/stop(旧版本):这个桥只会重启不会停,请更新 qq-bridge'
321
+ : '请求停止后端口仍在响应:可能有别的守护进程把它拉起来了'));
322
+ return { stopped: false, reason: 'still-alive' };
323
+ }
324
+ /**
325
+ * Points a QQ entry (`group:123` / `private:123`) at a DSH session.
326
+ * The bridge must be stopped while the file is edited: it reads `sessions.json` into memory at startup and
327
+ * writes it back over anything changed while running — done by hand once, and that is exactly how it went.
328
+ */
329
+ async function bind(key, sessionId) {
330
+ const file = join(stateDir, 'sessions.json');
331
+ if (!existsSync(file))
332
+ throw new Error(`找不到 ${file}`);
333
+ await stop();
334
+ const raw = readJsonTolerant(file);
335
+ raw.sessions = raw.sessions ?? {};
336
+ raw.sessions[key] = sessionId;
337
+ writeFileSync(file, `${JSON.stringify(raw, null, 2)}\n`, 'utf8');
338
+ const started = await start();
339
+ return { key, sessionId, ...started };
340
+ }
341
+ async function unbind(key) {
342
+ const file = join(stateDir, 'sessions.json');
343
+ if (!existsSync(file))
344
+ throw new Error(`找不到 ${file}`);
345
+ await stop();
346
+ const raw = readJsonTolerant(file);
347
+ if (raw.sessions)
348
+ delete raw.sessions[key];
349
+ writeFileSync(file, `${JSON.stringify(raw, null, 2)}\n`, 'utf8');
350
+ const started = await start();
351
+ return { key, ...started };
352
+ }
353
+ /**
354
+ * Endpoint alignment: writes the current origin into the bridge's config.json, and if it is running (holding
355
+ * the old value in memory) restarts it once. With autoStart off only the first half happens — a bridge that
356
+ * is meant to be stopped is not started behind the user's back.
357
+ */
358
+ async function syncEndpoint() {
359
+ const synced = syncBridgeBaseUrl(dir, origin(), logger);
360
+ if (!synced.changed)
361
+ return synced;
362
+ if (!(await ping()))
363
+ return { ...synced, restarted: false };
364
+ const stopped = await stop();
365
+ if (!stopped.stopped)
366
+ return { ...synced, restarted: false, reason: 'stop-failed' };
367
+ const started = await start();
368
+ return { ...synced, restarted: started.started === true };
369
+ }
370
+ async function ensureRunning() {
371
+ try {
372
+ return await start();
373
+ }
374
+ catch (error) {
375
+ note('start', error);
376
+ return { started: false, reason: 'failed' };
377
+ }
378
+ }
379
+ return { status, start, stop, halt, intent: () => readIntent(dir), bind, unbind, ensureRunning, syncEndpoint, proactive, setProactive, faults: () => [...faults.values()] };
380
+ }
@@ -0,0 +1,75 @@
1
+ import { spawn } from 'node:child_process';
2
+ /**
3
+ * The two consoles her partner opens from the QQ card, both reached from this machine only.
4
+ *
5
+ * qq-bridge writes its console token into `<bridge>/state/console-token`, so that door needs nothing from him:
6
+ * read the file, put the token in the URL, done.
7
+ *
8
+ * SnowLuma's console is different. Its session token lives in the bridge process's memory (a fresh 64-hex
9
+ * string per login, dead on restart) and the only way to get one is `POST /api/login` with the panel password.
10
+ * So he types that password exactly once; it is kept in `<world>/panel.json` with mode 600 and used from then
11
+ * on to trade for a token behind his back. The page itself takes `?token=` and wipes it off the address bar.
12
+ */
13
+ export declare const PANEL_FILE = "panel.json";
14
+ export interface PanelUrl {
15
+ url: string;
16
+ }
17
+ export interface PanelNeeds {
18
+ needs: 'password';
19
+ url?: string;
20
+ username?: string;
21
+ }
22
+ export interface PanelError {
23
+ error: string;
24
+ }
25
+ export type PanelResult = PanelUrl | PanelNeeds | PanelError;
26
+ /** Where SnowLuma's console listens, learned from its own config; undefined when it is not installed here. */
27
+ export declare function findSnowlumaConsole(homeDir: string): {
28
+ base: string;
29
+ username?: string;
30
+ } | undefined;
31
+ /** The panel password he typed once, kept beside her room rather than inside her world settings. */
32
+ export declare function createPanelSecrets(worldDir: string): {
33
+ read: () => {
34
+ username: string;
35
+ password: string;
36
+ } | undefined;
37
+ remember(username: string, password: string): void;
38
+ forget(): void;
39
+ };
40
+ export type PanelSecrets = ReturnType<typeof createPanelSecrets>;
41
+ /** Trades the panel password for a session token and hands back a URL that opens already logged in. */
42
+ export declare function loginSnowluma(base: string, username: string, password: string, fetchImpl?: typeof fetch): Promise<PanelResult>;
43
+ /** qq-bridge's console token is a file next to its state; the page takes it in the URL too. */
44
+ export declare function readBridgeToken(bridgeDir: string): string;
45
+ export declare function bridgeConsoleUrl(bridgeDir: string, port: number): PanelResult;
46
+ /** The two doors the QQ card's buttons knock on. */
47
+ export interface ConsoleDoors {
48
+ qq(): PanelResult;
49
+ snowluma(): Promise<PanelResult>;
50
+ remember(username: string, password: string): Promise<PanelResult>;
51
+ /** Hand a console URL to the desktop's own browser; neither console allows being framed. */
52
+ open(kind: 'qq' | 'snowluma'): Promise<{
53
+ opened: true;
54
+ } | {
55
+ error: string;
56
+ }>;
57
+ }
58
+ /**
59
+ * Both consoles send `X-Frame-Options: DENY` (SnowLuma also `frame-ancestors 'none'`), so no page of ours can
60
+ * hold them in a frame. Opening the desktop's own browser is the honest way in: it is where these consoles were
61
+ * meant to run, and the token rides in the URL so it lands already logged in.
62
+ */
63
+ export declare function openInBrowser(url: string, spawnImpl?: typeof spawn): {
64
+ opened: true;
65
+ } | {
66
+ error: string;
67
+ };
68
+ /** Where SnowLuma itself lives, as the bridge already knows it (`snowluma.homeDir` in its config). */
69
+ export declare function readSnowlumaHome(bridgeDir: string): string;
70
+ export declare function createConsoleDoors(options: {
71
+ worldDir: string;
72
+ bridgeDir: string;
73
+ port: number;
74
+ snowlumaHome?: string;
75
+ }): ConsoleDoors;