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,187 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import { spawn } from 'node:child_process';
3
+ import { join } from 'node:path';
4
+ import { durableWrite } from "../../life/lifeStore.js";
5
+ /**
6
+ * The two consoles her partner opens from the QQ card, both reached from this machine only.
7
+ *
8
+ * qq-bridge writes its console token into `<bridge>/state/console-token`, so that door needs nothing from him:
9
+ * read the file, put the token in the URL, done.
10
+ *
11
+ * SnowLuma's console is different. Its session token lives in the bridge process's memory (a fresh 64-hex
12
+ * string per login, dead on restart) and the only way to get one is `POST /api/login` with the panel password.
13
+ * So he types that password exactly once; it is kept in `<world>/panel.json` with mode 600 and used from then
14
+ * on to trade for a token behind his back. The page itself takes `?token=` and wipes it off the address bar.
15
+ */
16
+ export const PANEL_FILE = 'panel.json';
17
+ /** Its console answers on loopback; the port comes from SnowLuma's own runtime.json, never a constant here. */
18
+ const LOOPBACK = '127.0.0.1';
19
+ const LOGIN_TIMEOUT_MS = 8000;
20
+ const DEFAULT_USERNAME = 'admin';
21
+ /** Where SnowLuma's console listens, learned from its own config; undefined when it is not installed here. */
22
+ export function findSnowlumaConsole(homeDir) {
23
+ if (!homeDir)
24
+ return undefined;
25
+ const runtime = join(homeDir, 'config', 'runtime.json');
26
+ if (!existsSync(runtime))
27
+ return undefined;
28
+ let parsed;
29
+ try {
30
+ parsed = JSON.parse(readFileSync(runtime, 'utf8'));
31
+ }
32
+ catch {
33
+ return undefined;
34
+ }
35
+ const port = Number(parsed.webuiPort);
36
+ if (!Number.isInteger(port) || port <= 0)
37
+ return undefined;
38
+ const host = String(parsed.webuiHost ?? LOOPBACK);
39
+ // A console bound to every interface is still reached from here by name.
40
+ const named = host === '0.0.0.0' || host === '::' || host === '' ? LOOPBACK : host;
41
+ const scheme = parsed.webuiTls?.enabled === true ? 'https' : 'http';
42
+ return { base: `${scheme}://${named}:${port}`, username: undefined };
43
+ }
44
+ /** The panel password he typed once, kept beside her room rather than inside her world settings. */
45
+ export function createPanelSecrets(worldDir) {
46
+ const file = join(worldDir, PANEL_FILE);
47
+ let stored = {};
48
+ try {
49
+ if (existsSync(file))
50
+ stored = JSON.parse(readFileSync(file, 'utf8'));
51
+ }
52
+ catch {
53
+ stored = {};
54
+ }
55
+ const read = () => {
56
+ const password = stored.snowluma?.password;
57
+ if (typeof password !== 'string' || password === '')
58
+ return undefined;
59
+ return { username: stored.snowluma?.username?.trim() || DEFAULT_USERNAME, password };
60
+ };
61
+ return {
62
+ read,
63
+ remember(username, password) {
64
+ stored = { ...stored, snowluma: { username: username.trim() || DEFAULT_USERNAME, password } };
65
+ durableWrite(file, JSON.stringify(stored, null, 2));
66
+ },
67
+ forget() {
68
+ stored = {};
69
+ durableWrite(file, '{}');
70
+ },
71
+ };
72
+ }
73
+ /** Trades the panel password for a session token and hands back a URL that opens already logged in. */
74
+ export async function loginSnowluma(base, username, password, fetchImpl = fetch) {
75
+ const root = base.replace(/\/+$/, '');
76
+ let response;
77
+ try {
78
+ response = await fetchImpl(`${root}/api/login`, {
79
+ method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ username, password }),
80
+ signal: AbortSignal.timeout(LOGIN_TIMEOUT_MS),
81
+ });
82
+ }
83
+ catch (error) {
84
+ return { error: `连不上 SnowLuma 控制台(${root}):${error instanceof Error ? error.message : String(error)}` };
85
+ }
86
+ let body = {};
87
+ try {
88
+ body = (await response.json());
89
+ }
90
+ catch {
91
+ body = {};
92
+ }
93
+ if (response.status === 429)
94
+ return { error: '登录尝试太多,SnowLuma 让等一会儿再试' };
95
+ const token = typeof body.token === 'string' ? body.token : '';
96
+ if (!response.ok || body.success !== true || token === '') {
97
+ const message = typeof body.message === 'string' ? body.message : `登录失败(HTTP ${response.status})`;
98
+ return { error: message };
99
+ }
100
+ return { url: `${root}/?token=${encodeURIComponent(token)}` };
101
+ }
102
+ /** qq-bridge's console token is a file next to its state; the page takes it in the URL too. */
103
+ export function readBridgeToken(bridgeDir) {
104
+ const file = join(bridgeDir, 'state', 'console-token');
105
+ try {
106
+ return existsSync(file) ? readFileSync(file, 'utf8').trim() : '';
107
+ }
108
+ catch {
109
+ return '';
110
+ }
111
+ }
112
+ export function bridgeConsoleUrl(bridgeDir, port) {
113
+ const token = readBridgeToken(bridgeDir);
114
+ if (token === '')
115
+ return { error: 'qq-bridge 还没有控制台令牌(它没启动过?)' };
116
+ return { url: `http://${LOOPBACK}:${port}/?token=${encodeURIComponent(token)}` };
117
+ }
118
+ /**
119
+ * Both consoles send `X-Frame-Options: DENY` (SnowLuma also `frame-ancestors 'none'`), so no page of ours can
120
+ * hold them in a frame. Opening the desktop's own browser is the honest way in: it is where these consoles were
121
+ * meant to run, and the token rides in the URL so it lands already logged in.
122
+ */
123
+ export function openInBrowser(url, spawnImpl = spawn) {
124
+ try {
125
+ if (process.platform === 'win32') {
126
+ // The empty argument is the window title; without it `start` eats the first quoted word.
127
+ spawnImpl('cmd.exe', ['/c', 'start', '', url], { detached: true, stdio: 'ignore', windowsHide: true }).unref();
128
+ }
129
+ else {
130
+ spawnImpl(process.platform === 'darwin' ? 'open' : 'xdg-open', [url], { detached: true, stdio: 'ignore' }).unref();
131
+ }
132
+ return { opened: true };
133
+ }
134
+ catch (error) {
135
+ return { error: `打不开浏览器:${error instanceof Error ? error.message : String(error)}` };
136
+ }
137
+ }
138
+ /** Where SnowLuma itself lives, as the bridge already knows it (`snowluma.homeDir` in its config). */
139
+ export function readSnowlumaHome(bridgeDir) {
140
+ const file = join(bridgeDir, 'config.json');
141
+ try {
142
+ if (!existsSync(file))
143
+ return '';
144
+ const parsed = JSON.parse(readFileSync(file, 'utf8'));
145
+ const home = parsed.snowluma?.homeDir ?? parsed.dsh?.snowluma?.homeDir;
146
+ return typeof home === 'string' ? home : '';
147
+ }
148
+ catch {
149
+ return '';
150
+ }
151
+ }
152
+ export function createConsoleDoors(options) {
153
+ const secrets = createPanelSecrets(options.worldDir);
154
+ const home = options.snowlumaHome ?? readSnowlumaHome(options.bridgeDir);
155
+ async function snowluma() {
156
+ const console = findSnowlumaConsole(home);
157
+ if (!console)
158
+ return { error: '没找到 SnowLuma 的控制台配置(它在哪?)' };
159
+ const saved = secrets.read();
160
+ if (!saved)
161
+ return { needs: 'password', url: console.base, username: DEFAULT_USERNAME };
162
+ return loginSnowluma(console.base, saved.username, saved.password);
163
+ }
164
+ return {
165
+ qq: () => bridgeConsoleUrl(options.bridgeDir, options.port),
166
+ snowluma,
167
+ async remember(username, password) {
168
+ const console = findSnowlumaConsole(home);
169
+ if (!console)
170
+ return { error: '没找到 SnowLuma 的控制台配置(它在哪?)' };
171
+ const result = await loginSnowluma(console.base, username.trim() || DEFAULT_USERNAME, password);
172
+ // Only keep a password that works; a typo should not be remembered as the truth.
173
+ if ('url' in result)
174
+ secrets.remember(username, password);
175
+ return result;
176
+ },
177
+ async open(kind) {
178
+ const door = kind === 'qq' ? bridgeConsoleUrl(options.bridgeDir, options.port) : await snowluma();
179
+ // A door that still wants a password carries its base URL too; that is not something to open.
180
+ if ('needs' in door)
181
+ return { error: 'SnowLuma 还差一次面板密码' };
182
+ if ('error' in door)
183
+ return { error: door.error };
184
+ return openInBrowser(door.url);
185
+ },
186
+ };
187
+ }
@@ -0,0 +1,32 @@
1
+ import type { IncomingMessage, ServerResponse } from 'node:http';
2
+ import type { QqBridge } from './bridge.ts';
3
+ import type { ConsoleDoors } from './panel.ts';
4
+ /**
5
+ * The QQ module's few doors, on the same webServer as the console. The `/dsh-world/qq` prefix is never eaten
6
+ * by the console's `/dsh-world` prefix (the host matches the longer one first).
7
+ *
8
+ * Read: GET /dsh-world/qq is the bridge up, is it talking to DSH, which entries are bound
9
+ * GET /dsh-world/qq/proactive the proactive-chat numbers (calls, tokens, sent, suppressed)
10
+ * GET /dsh-world/qq/console the two consoles' addresses, tokens in hand: qq-bridge (its token is a
11
+ * file) and SnowLuma (a fresh session token traded for the panel password)
12
+ * Write: POST /dsh-world/qq/start bring it up if it is down
13
+ * POST /dsh-world/qq/stop ask it to exit gracefully (flushes state first)
14
+ * POST /dsh-world/qq/halt stop it and mean it: the bridge records intent=stopped and no handoff
15
+ * process is spawned, so the supervisor will not bring it back
16
+ * POST /dsh-world/qq/bind { key, sessionId } points a QQ entry at a session
17
+ * POST /dsh-world/qq/unbind { key }
18
+ * POST /dsh-world/qq/panel-password { username, password } remembers SnowLuma's panel password and
19
+ * trades it for a session token right away
20
+ * POST /dsh-world/qq/proactive { enabled?, dryRun? } flips the two switches; the bridge writes them into
21
+ * its own config.json and applies them on the spot, so nothing restarts
22
+ *
23
+ * Writes require the `x-dsh-world` header: a cross-site page cannot add it (that would trigger a preflight,
24
+ * and no preflight is answered here).
25
+ */
26
+ export declare const QQ_PREFIX = "/dsh-world/qq";
27
+ export declare const WRITE_HEADER = "x-dsh-world";
28
+ export declare function qqRoute(qq: QqBridge, allowedHosts?: readonly string[], doors?: ConsoleDoors): {
29
+ kind: "prefix";
30
+ path: string;
31
+ handler: (req: IncomingMessage, res: ServerResponse) => Promise<void>;
32
+ };
@@ -0,0 +1,134 @@
1
+ import { jsonObject, knownHost, readBody, sendJson } from "../../http.js";
2
+ /**
3
+ * The QQ module's few doors, on the same webServer as the console. The `/dsh-world/qq` prefix is never eaten
4
+ * by the console's `/dsh-world` prefix (the host matches the longer one first).
5
+ *
6
+ * Read: GET /dsh-world/qq is the bridge up, is it talking to DSH, which entries are bound
7
+ * GET /dsh-world/qq/proactive the proactive-chat numbers (calls, tokens, sent, suppressed)
8
+ * GET /dsh-world/qq/console the two consoles' addresses, tokens in hand: qq-bridge (its token is a
9
+ * file) and SnowLuma (a fresh session token traded for the panel password)
10
+ * Write: POST /dsh-world/qq/start bring it up if it is down
11
+ * POST /dsh-world/qq/stop ask it to exit gracefully (flushes state first)
12
+ * POST /dsh-world/qq/halt stop it and mean it: the bridge records intent=stopped and no handoff
13
+ * process is spawned, so the supervisor will not bring it back
14
+ * POST /dsh-world/qq/bind { key, sessionId } points a QQ entry at a session
15
+ * POST /dsh-world/qq/unbind { key }
16
+ * POST /dsh-world/qq/panel-password { username, password } remembers SnowLuma's panel password and
17
+ * trades it for a session token right away
18
+ * POST /dsh-world/qq/proactive { enabled?, dryRun? } flips the two switches; the bridge writes them into
19
+ * its own config.json and applies them on the spot, so nothing restarts
20
+ *
21
+ * Writes require the `x-dsh-world` header: a cross-site page cannot add it (that would trigger a preflight,
22
+ * and no preflight is answered here).
23
+ */
24
+ export const QQ_PREFIX = '/dsh-world/qq';
25
+ export const WRITE_HEADER = 'x-dsh-world';
26
+ const MAX_BODY_BYTES = 8 * 1024;
27
+ const ok = (body = { ok: true }) => ({ status: 200, body });
28
+ const bad = (error) => ({ status: 400, body: { error } });
29
+ function allowed(req, allowedHosts) {
30
+ if (req.headers['sec-fetch-site'] === 'cross-site')
31
+ return false;
32
+ return knownHost(req.headers.host, allowedHosts);
33
+ }
34
+ async function write(qq, doors, path, body) {
35
+ switch (path) {
36
+ case '/start': return ok(await qq.start());
37
+ case '/stop': return ok(await qq.stop());
38
+ case '/halt': return ok(await qq.halt());
39
+ case '/open': {
40
+ if (!doors)
41
+ return bad('控制台地址没有接上');
42
+ const kind = body?.kind === 'qq' ? 'qq' : body?.kind === 'snowluma' ? 'snowluma' : '';
43
+ if (kind === '')
44
+ return bad('kind 只能是 qq 或 snowluma');
45
+ return ok(await doors.open(kind));
46
+ }
47
+ case '/panel-password': {
48
+ if (!doors)
49
+ return bad('控制台地址没有接上');
50
+ const username = typeof body?.username === 'string' ? body.username.trim() : '';
51
+ const password = typeof body?.password === 'string' ? body.password : '';
52
+ if (password === '')
53
+ return bad('密码不能为空');
54
+ return ok({ snowluma: await doors.remember(username, password) });
55
+ }
56
+ case '/proactive': {
57
+ const patch = {};
58
+ if (typeof body?.enabled === 'boolean')
59
+ patch.enabled = body.enabled;
60
+ if (typeof body?.dryRun === 'boolean')
61
+ patch.dryRun = body.dryRun;
62
+ if (patch.enabled === undefined && patch.dryRun === undefined)
63
+ return bad('enabled 和 dryRun 至少要给一个布尔');
64
+ return ok(await qq.setProactive(patch));
65
+ }
66
+ case '/bind': {
67
+ const key = typeof body?.key === 'string' ? body.key.trim() : '';
68
+ const sessionId = typeof body?.sessionId === 'string' ? body.sessionId.trim() : '';
69
+ if (!key || !sessionId)
70
+ return bad('key 和 sessionId 都必须是非空字符串');
71
+ if (!/^(group|private):\d+$/.test(key))
72
+ return bad('key 形如 group:123 或 private:123');
73
+ return ok(await qq.bind(key, sessionId));
74
+ }
75
+ case '/unbind': {
76
+ const key = typeof body?.key === 'string' ? body.key.trim() : '';
77
+ if (!key)
78
+ return bad('key 必填');
79
+ return ok(await qq.unbind(key));
80
+ }
81
+ default: return undefined;
82
+ }
83
+ }
84
+ export function qqRoute(qq, allowedHosts = [], doors) {
85
+ return {
86
+ kind: 'prefix', path: QQ_PREFIX,
87
+ handler: async (req, res) => {
88
+ if (!allowed(req, allowedHosts)) {
89
+ sendJson(res, { status: 403, body: { error: 'forbidden' } });
90
+ return;
91
+ }
92
+ const url = new URL(req.url ?? QQ_PREFIX, 'http://localhost');
93
+ const path = url.pathname.slice(QQ_PREFIX.length) || '/';
94
+ try {
95
+ if (req.method === 'GET' && (path === '/' || path === '')) {
96
+ sendJson(res, ok(await qq.status()));
97
+ return;
98
+ }
99
+ if (req.method === 'GET' && path === '/proactive') {
100
+ const data = await qq.proactive();
101
+ if (!data) {
102
+ sendJson(res, { status: 503, body: { error: '桥没在跑,统计读不到' } });
103
+ return;
104
+ }
105
+ sendJson(res, ok(data));
106
+ return;
107
+ }
108
+ if (req.method === 'GET' && path === '/console') {
109
+ if (!doors) {
110
+ sendJson(res, { status: 404, body: { error: '控制台地址没有接上' } });
111
+ return;
112
+ }
113
+ const qqDoor = doors.qq();
114
+ sendJson(res, ok({ qq: qqDoor, snowluma: await doors.snowluma() }));
115
+ return;
116
+ }
117
+ if (req.method !== 'POST') {
118
+ sendJson(res, { status: 405, body: { error: 'method not allowed' }, headers: { allow: 'GET, POST' } });
119
+ return;
120
+ }
121
+ if (String(req.headers[WRITE_HEADER] ?? '') === '') {
122
+ sendJson(res, { status: 400, body: { error: `写操作必须带 ${WRITE_HEADER} 请求头` } });
123
+ return;
124
+ }
125
+ const body = jsonObject(await readBody(req, MAX_BODY_BYTES));
126
+ const result = await write(qq, doors, path, body);
127
+ sendJson(res, result ?? { status: 404, body: { error: 'not found' } });
128
+ }
129
+ catch (error) {
130
+ sendJson(res, { status: 500, body: { error: String(error instanceof Error ? error.message : error) } });
131
+ }
132
+ },
133
+ };
134
+ }
@@ -0,0 +1,57 @@
1
+ import type { QqBridge, QqLogger } from './bridge.ts';
2
+ /**
3
+ * QQ:看着那个外部进程,别让它悄悄死掉。
4
+ *
5
+ * 为什么需要一层巡检:桥是独立进程(`spawn` 出去的、detached),插件这边除了启动时的一次
6
+ * `ensureRunning()` 之外对它一无所知。它崩了、被任务管理器结束、DSH 换端口后它连不上——
7
+ * 三种情况在界面上长得一模一样:QQ 不说话了。2026-10-26 那次「链路死了四小时」就是这么来的。
8
+ *
9
+ * 这层只做三件事:探测、判断该不该拉、拉的时候别把自己拉爆。它不碰桥的业务逻辑,
10
+ * 也不接管桥的启停实现(那是 `bridge.ts` 的事)。
11
+ */
12
+ export type SupervisorState = 'stopped' | 'starting' | 'healthy' | 'degraded' | 'recovering' | 'failed';
13
+ export interface SupervisorSnapshot {
14
+ state: SupervisorState;
15
+ /** 连续探测失败次数;成功一次清零。 */
16
+ consecutiveFailures: number;
17
+ /** 最近 10 分钟内真正发起的自动拉起次数。 */
18
+ restartsInWindow: number;
19
+ /** 下次探测的间隔(恢复失败后会变长)。 */
20
+ backoffMs: number;
21
+ /** 桥在线且 `dshReady`——false 时桥在跑但连不上 DSH,那是端点问题,重启桥治不了。 */
22
+ dshReady?: boolean;
23
+ lastError?: string;
24
+ lastProbeAt?: number;
25
+ lastRestartAt?: number;
26
+ }
27
+ export interface SupervisorOptions {
28
+ /** qq-bridge 目录;`state/bridge.intent.json` 也从这里读。 */
29
+ dir: string;
30
+ port?: number;
31
+ /** 只用到 start / halt / intent 三个动作,方便测试塞假桥。 */
32
+ bridge: Pick<QqBridge, 'start' | 'halt' | 'intent'>;
33
+ logger?: QqLogger;
34
+ /** 探测间隔,默认 5s。 */
35
+ intervalMs?: number;
36
+ /** 单次探测超时,默认 1.5s。 */
37
+ probeTimeoutMs?: number;
38
+ /** 连续失败到几次才尝试恢复,默认 3。 */
39
+ failuresBeforeRestart?: number;
40
+ /** 10 分钟内最多自动拉起几次,默认 5。 */
41
+ maxRestartsPerWindow?: number;
42
+ /** 退避基数,默认 2s;第 n 次失败后等 base * 2^(n-1),上限 60s。 */
43
+ backoffBaseMs?: number;
44
+ /** 注入时钟与随机源,测试用。 */
45
+ now?: () => number;
46
+ random?: () => number;
47
+ }
48
+ export interface QqSupervisor {
49
+ /** 开始巡检。不会立刻拉起桥——「该不该跑」是调用方先决定的事。 */
50
+ start(): void;
51
+ /** 停止巡检。不影响桥本身。 */
52
+ stop(): void;
53
+ /** 立刻探一次,可用于控制台刷新或测试。 */
54
+ probeOnce(): Promise<SupervisorSnapshot>;
55
+ snapshot(): SupervisorSnapshot;
56
+ }
57
+ export declare function createQqSupervisor(options: SupervisorOptions): QqSupervisor;
@@ -0,0 +1,188 @@
1
+ import { readConsoleToken } from "./bridge.js";
2
+ const DEFAULT_INTERVAL_MS = 5000;
3
+ const DEFAULT_PROBE_TIMEOUT_MS = 1500;
4
+ const DEFAULT_FAILURES_BEFORE_RESTART = 3;
5
+ const DEFAULT_MAX_RESTARTS = 5;
6
+ const DEFAULT_BACKOFF_BASE_MS = 2000;
7
+ const MAX_BACKOFF_MS = 60000;
8
+ const RESTART_WINDOW_MS = 10 * 60 * 1000;
9
+ const sleep = (ms) => new Promise(resolve => { setTimeout(resolve, ms); });
10
+ const messageOf = (error) => error instanceof Error ? error.message : String(error);
11
+ export function createQqSupervisor(options) {
12
+ const { dir, bridge, logger, port = 3100, intervalMs = DEFAULT_INTERVAL_MS, probeTimeoutMs = DEFAULT_PROBE_TIMEOUT_MS, failuresBeforeRestart = DEFAULT_FAILURES_BEFORE_RESTART, maxRestartsPerWindow = DEFAULT_MAX_RESTARTS, backoffBaseMs = DEFAULT_BACKOFF_BASE_MS, now = () => Date.now(), random = () => Math.random(), } = options;
13
+ const base = `http://127.0.0.1:${port}`;
14
+ let state = 'stopped';
15
+ let consecutiveFailures = 0;
16
+ /** 本轮连续发起恢复的次数;成功或被探到桥好了就清零。退避按它算。 */
17
+ let recoverAttempts = 0;
18
+ let backoffMs = 0;
19
+ let restartsInWindow = 0;
20
+ let lastError;
21
+ let lastProbeAt;
22
+ let lastRestartAt;
23
+ let dshReady;
24
+ const restartTimes = [];
25
+ /** 单飞:探测和恢复共用这把锁,避免慢探测叠在恢复上。 */
26
+ let inFlight = false;
27
+ let timer;
28
+ function pruneWindow(at) {
29
+ const cutoff = at - RESTART_WINDOW_MS;
30
+ while (restartTimes.length > 0 && restartTimes[0] < cutoff)
31
+ restartTimes.shift();
32
+ restartsInWindow = restartTimes.length;
33
+ }
34
+ function nextBackoff() {
35
+ // 按「第几次发起恢复」算,不按「连续探测失败几次」算:
36
+ // 阈值是 3,用探测次数会让第一次恢复就先等 4 倍基数。
37
+ const raw = backoffBaseMs * 2 ** Math.min(Math.max(0, recoverAttempts - 1), 5);
38
+ // ±20% 抖动:几个实例同时恢复时不至于踩着同一个节奏互相抢锁。
39
+ const jitter = 0.8 + random() * 0.4;
40
+ return Math.min(MAX_BACKOFF_MS, Math.round(raw * jitter));
41
+ }
42
+ async function probe() {
43
+ const token = readConsoleToken(dir);
44
+ const url = `${base}/api/status${token ? `?token=${encodeURIComponent(token)}` : ''}`;
45
+ try {
46
+ const response = await fetch(url, { signal: AbortSignal.timeout(probeTimeoutMs) });
47
+ if (response.status !== 200)
48
+ return { ok: false, error: `status ${response.status}` };
49
+ const body = await response.json();
50
+ return { ok: true, body: body ?? {} };
51
+ }
52
+ catch (error) {
53
+ return { ok: false, error: messageOf(error) };
54
+ }
55
+ }
56
+ function intent() {
57
+ try {
58
+ return bridge.intent();
59
+ }
60
+ catch {
61
+ // 读意图失败按「想跑」处理:未知状态不该变成永久不启动。
62
+ return { desired: 'running', at: 0, by: '' };
63
+ }
64
+ }
65
+ async function attemptRecovery(at) {
66
+ const wanted = intent();
67
+ if (wanted.desired === 'stopped') {
68
+ // 用户主动停的:报状态就够了,别把手伸回去。
69
+ state = 'stopped';
70
+ logger?.info?.('[qq] 桥是用户主动停止的(desired=stopped),巡检不自动拉起');
71
+ return;
72
+ }
73
+ pruneWindow(at);
74
+ if (restartsInWindow >= maxRestartsPerWindow) {
75
+ state = 'failed';
76
+ lastError = `${RESTART_WINDOW_MS / 60000} 分钟内已自动拉起 ${restartsInWindow} 次,停止重试(修好再手动启动)`;
77
+ logger?.warn?.(`[qq] ${lastError}`);
78
+ return;
79
+ }
80
+ state = 'starting';
81
+ logger?.warn?.(`[qq] 桥连续 ${consecutiveFailures} 次探测失败,尝试拉起`);
82
+ try {
83
+ const result = await bridge.start();
84
+ if (result.started) {
85
+ restartTimes.push(now());
86
+ restartsInWindow = restartTimes.length;
87
+ lastRestartAt = now();
88
+ state = 'healthy';
89
+ consecutiveFailures = 0;
90
+ recoverAttempts = 0;
91
+ backoffMs = 0;
92
+ lastError = undefined;
93
+ logger?.info?.('[qq] 桥已拉起');
94
+ return;
95
+ }
96
+ lastError = `拉起没成功:${result.reason ?? '未知原因'}`;
97
+ }
98
+ catch (error) {
99
+ lastError = `拉起失败:${messageOf(error)}`;
100
+ }
101
+ // 失败:进入退避等待,期间不再尝试;等待结束才回到 degraded 让下一轮重新判定。
102
+ // 计数必须清零——否则「连续失败 3 次」这个闸门永远开着,退避等待一结束,
103
+ // 下一次探测就直接又拉一遍,退避等于没做。
104
+ state = 'recovering';
105
+ consecutiveFailures = 0;
106
+ recoverAttempts += 1;
107
+ backoffMs = nextBackoff();
108
+ logger?.warn?.(`[qq] ${lastError};${Math.round(backoffMs / 1000)}s 后再试`);
109
+ await sleep(backoffMs);
110
+ if (state === 'recovering')
111
+ state = 'degraded';
112
+ }
113
+ async function tick() {
114
+ if (inFlight)
115
+ return;
116
+ inFlight = true;
117
+ try {
118
+ const at = now();
119
+ lastProbeAt = at;
120
+ const result = await probe();
121
+ if (result.ok) {
122
+ consecutiveFailures = 0;
123
+ recoverAttempts = 0;
124
+ backoffMs = 0;
125
+ lastError = undefined;
126
+ dshReady = result.body.dshReady === true;
127
+ // 桥在跑但连不上 DSH:那是 baseUrl 过期,重启桥解决不了,交给 syncEndpoint。
128
+ // 这里只把它标成 degraded,让人在界面上看得出来。
129
+ state = dshReady ? 'healthy' : 'degraded';
130
+ if (!dshReady)
131
+ lastError = '桥在线,但 dshReady=false(多半是 DSH 换了端口,跑一次 syncEndpoint)';
132
+ return;
133
+ }
134
+ dshReady = undefined;
135
+ // 用户主动停的桥不在线是**预期状态**,不该算故障:否则界面上先跳十几秒的
136
+ // 「degraded / 连续失败 2 次」才变回 stopped,看着像巡检在犹豫要不要动手。
137
+ if (intent().desired === 'stopped') {
138
+ state = 'stopped';
139
+ consecutiveFailures = 0;
140
+ recoverAttempts = 0;
141
+ lastError = undefined;
142
+ return;
143
+ }
144
+ consecutiveFailures += 1;
145
+ lastError = result.error;
146
+ state = 'degraded';
147
+ if (consecutiveFailures >= failuresBeforeRestart)
148
+ await attemptRecovery(at);
149
+ }
150
+ finally {
151
+ inFlight = false;
152
+ }
153
+ }
154
+ return {
155
+ start() {
156
+ if (timer)
157
+ return;
158
+ // 先探一次,别让界面在头 5 秒里显示「未知」。
159
+ void tick();
160
+ timer = setInterval(() => { void tick(); }, intervalMs);
161
+ // 巡检不该成为进程退出的阻碍。
162
+ timer.unref?.();
163
+ },
164
+ stop() {
165
+ if (timer)
166
+ clearInterval(timer);
167
+ timer = undefined;
168
+ state = 'stopped';
169
+ },
170
+ async probeOnce() {
171
+ await tick();
172
+ return this.snapshot();
173
+ },
174
+ snapshot() {
175
+ pruneWindow(now());
176
+ return {
177
+ state,
178
+ consecutiveFailures,
179
+ restartsInWindow,
180
+ backoffMs,
181
+ ...(dshReady === undefined ? {} : { dshReady }),
182
+ ...(lastError ? { lastError } : {}),
183
+ ...(lastProbeAt === undefined ? {} : { lastProbeAt }),
184
+ ...(lastRestartAt === undefined ? {} : { lastRestartAt }),
185
+ };
186
+ },
187
+ };
188
+ }
@@ -0,0 +1,14 @@
1
+ import { type SpeakerIdentity } from './identity.ts';
2
+ export interface ChannelImage {
3
+ file: string;
4
+ quality: 'original' | 'cached' | 'thumbnail';
5
+ }
6
+ export interface ChannelContextMessage {
7
+ id: string;
8
+ occurredAt: string;
9
+ text: string;
10
+ identity: SpeakerIdentity;
11
+ image?: ChannelImage;
12
+ }
13
+ export declare function channelContext(value: unknown, current: SpeakerIdentity, limit?: number): ChannelContextMessage[];
14
+ export declare function channelMedia(value: unknown, current: SpeakerIdentity): ChannelContextMessage[];
@@ -0,0 +1,42 @@
1
+ import { conversationKey, speakerIdentity } from "./identity.js";
2
+ export function channelContext(value, current, limit = 8) {
3
+ if (value === undefined || (Array.isArray(value) && value.length === 0))
4
+ return [];
5
+ if (current.conversationType !== 'group')
6
+ throw new Error('Invalid group context');
7
+ return contextMessages(value, current, limit);
8
+ }
9
+ export function channelMedia(value, current) {
10
+ if (value === undefined || (Array.isArray(value) && value.length === 0))
11
+ return [];
12
+ if (current.conversationType !== 'private')
13
+ throw new Error('Invalid private media');
14
+ const messages = contextMessages(value, current, 2);
15
+ if (messages.some(message => message.identity.speakerId !== current.speakerId))
16
+ throw new Error('Media belongs to another speaker');
17
+ if (new Set(messages.map(message => message.id)).size !== messages.length)
18
+ throw new Error('Duplicate media message');
19
+ return messages;
20
+ }
21
+ function contextMessages(value, current, limit) {
22
+ if (!Array.isArray(value) || value.length > limit || Buffer.byteLength(JSON.stringify(value)) > 16 * 1024)
23
+ throw new Error('Invalid channel context');
24
+ let images = 0;
25
+ return value.map(item => {
26
+ if (!item || typeof item !== 'object' || typeof item.id !== 'string' || !item.id || item.id.length > 256 || /[\u0000-\u001f\u007f]/.test(item.id)
27
+ || typeof item.occurredAt !== 'string' || item.occurredAt.length > 40 || !Number.isFinite(Date.parse(item.occurredAt))
28
+ || typeof item.text !== 'string' || !item.text.trim() || [...item.text].length > 2000)
29
+ throw new Error('Invalid context message');
30
+ const identity = speakerIdentity(item.identity);
31
+ if (conversationKey(identity) !== conversationKey(current))
32
+ throw new Error('Context belongs to another conversation');
33
+ let image;
34
+ if (item.image !== undefined) {
35
+ if (!item.image || typeof item.image !== 'object' || typeof item.image.file !== 'string' || !/^[a-f0-9]{64}\.png$/.test(item.image.file)
36
+ || !['original', 'cached', 'thumbnail'].includes(item.image.quality) || ++images > 2)
37
+ throw new Error('Invalid group image');
38
+ image = { file: item.image.file, quality: item.image.quality };
39
+ }
40
+ return { id: item.id, occurredAt: item.occurredAt, text: item.text, identity, ...(image ? { image } : {}) };
41
+ });
42
+ }