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,210 @@
1
+ // Surface transaction adapted from @deepseek-ai/dsh-compaction-basic@0.2.1-rc.2 (MIT, Copyright (c) 2026 DeepSeek).
2
+ // Kept local so the stock package is used unmodified; selection here always runs to the newest balanced cut.
3
+ import { randomUUID } from 'node:crypto';
4
+ import { isDeepStrictEqual } from 'node:util';
5
+ import { CompactionId, ManualCompactionError, compactCheckpointSource, toolPairingBalancedAfter, toolPairingBalancedBefore } from '@deepseek-ai/dsh-compaction';
6
+ import { createUserMessage, errorChain } from '@deepseek-ai/dsh-llm';
7
+ import { SessionSeq } from '@deepseek-ai/dsh-session';
8
+ function eventAt(session, seq) {
9
+ const event = session.eventAt(seq);
10
+ if (event === undefined)
11
+ throw new Error(`compaction: session seq ${seq} has no event`);
12
+ return event;
13
+ }
14
+ class SurfaceChangedError extends Error {
15
+ }
16
+ /** Everything after the system head through the newest cut that splits no tool call from its result. */
17
+ export function selectWholeRange(session, measurement) {
18
+ const nodes = session.surface.nodes;
19
+ if (!nodes.length)
20
+ return null;
21
+ if (nodes.length !== measurement.nodes.length || nodes.some((seq, index) => seq !== measurement.nodes[index]?.seq))
22
+ throw new Error('compaction: token-meter surface does not match the current session surface');
23
+ const firstIdx = eventAt(session, nodes[0]).type === 'system/message' ? 1 : 0;
24
+ let endIdx = nodes.length - 1;
25
+ while (endIdx >= firstIdx && !toolPairingBalancedAfter(session, nodes[endIdx]))
26
+ endIdx -= 1;
27
+ return endIdx < firstIdx ? null : { start: nodes[firstIdx], end: nodes[endIdx] };
28
+ }
29
+ export async function compactSurfaceRegion(deps, agent, start, end, options, signal) {
30
+ const { session } = agent;
31
+ if (options.owner === null)
32
+ signal?.throwIfAborted();
33
+ const selection = validateSurfaceRegion(session, start, end);
34
+ const entry = inspectEntryState(session);
35
+ assertInactive(entry, 'compaction');
36
+ if (options.owner === null && entry.openTurn !== null)
37
+ throw new ManualCompactionError('busy', 'manual compaction: the session already has an open turn');
38
+ if (options.owner !== null && entry.openTurn === null)
39
+ throw new Error('compactRegion: no open turn — automatic compaction events must be enclosed in a turn');
40
+ const lifecycle = { compactionId: CompactionId(randomUUID()), ...(options.sourceCommandId === undefined ? {} : { sourceCommandId: options.sourceCommandId }), turn: options.owner === null ? null : entry.openTurn };
41
+ const startEvent = session.append('compaction/start', lifecycle);
42
+ const assertStable = options.stability === 'whole-surface' ? assertWholeSurfaceUnchanged : assertSelectedSpanStable;
43
+ let failure;
44
+ let flushFailure;
45
+ let result;
46
+ let closed = false;
47
+ let closing = false;
48
+ let stage = 'summary';
49
+ try {
50
+ const summarized = await summarize(deps, prepare(deps, session, selection), agent, lifecycle.compactionId, options.sourceCommandId, assertStable, signal);
51
+ if (options.owner === null)
52
+ signal?.throwIfAborted();
53
+ assertStable(deps, session, summarized);
54
+ stage = 'commit';
55
+ const pending = commitBody(session, startEvent.seq, lifecycle, summarized);
56
+ closing = true;
57
+ const endEvent = session.append('compaction/end', lifecycle);
58
+ closed = true;
59
+ result = { ...pending, endSeq: endEvent.seq };
60
+ }
61
+ catch (error) {
62
+ failure = { error, stage: closing ? 'commit' : stage };
63
+ if (!closing) {
64
+ closing = true;
65
+ try {
66
+ session.append('compaction/end', { ...lifecycle, error: errorChain(error) });
67
+ closed = true;
68
+ }
69
+ catch (closeError) {
70
+ failure = { error: closeError, stage: 'commit' };
71
+ }
72
+ }
73
+ }
74
+ if (closed && options.flush)
75
+ try {
76
+ await options.flush();
77
+ }
78
+ catch (error) {
79
+ flushFailure = error;
80
+ }
81
+ if (options.owner === null)
82
+ signal?.throwIfAborted();
83
+ if (failure) {
84
+ if (options.owner !== null)
85
+ throw failure.error;
86
+ if (failure.stage === 'commit')
87
+ throw new ManualCompactionError('commit', 'manual compaction did not commit cleanly', { cause: failure.error });
88
+ if (failure.error instanceof SurfaceChangedError)
89
+ throw new ManualCompactionError('changed', 'the compacted history changed during manual compaction', { cause: failure.error });
90
+ throw new ManualCompactionError('summary', 'manual compaction could not produce a smaller summary', { cause: failure.error });
91
+ }
92
+ if (flushFailure !== undefined)
93
+ throw new ManualCompactionError('persistence', 'manual compaction durability checkpoint failed', { cause: flushFailure });
94
+ return result;
95
+ }
96
+ export function assertNoActiveCompaction(session, stage) { assertInactive(inspectEntryState(session), stage); }
97
+ function assertInactive(entry, stage) {
98
+ if (entry.unmatchedStart === undefined || (entry.latestEndSeedSeq !== undefined && entry.latestEndSeedSeq > entry.unmatchedStart))
99
+ return;
100
+ throw new ManualCompactionError('busy', `${stage}: compaction already in progress; the session compaction lock is already active`);
101
+ }
102
+ function validateSurfaceRegion(session, start, end) {
103
+ const nodes = session.surface.nodes;
104
+ const startIdx = nodes.indexOf(start);
105
+ const endIdx = nodes.indexOf(end);
106
+ if (startIdx === -1)
107
+ throw new Error(`compactRegion: start seq ${start} not found in surface`);
108
+ if (endIdx === -1)
109
+ throw new Error(`compactRegion: end seq ${end} not found in surface`);
110
+ if (startIdx > endIdx)
111
+ throw new Error(`compactRegion: start seq ${start} is after end seq ${end} on the surface`);
112
+ if (!toolPairingBalancedBefore(session, nodes[startIdx]))
113
+ throw new Error(`compactRegion: start seq ${start} would split a tool-call/result pair`);
114
+ if (!toolPairingBalancedAfter(session, nodes[endIdx]))
115
+ throw new Error(`compactRegion: end seq ${end} would split a tool-call/result pair, or the step is still open`);
116
+ return { start, end, startIdx, endIdx, shadowedSeqs: nodes.slice(startIdx, endIdx + 1) };
117
+ }
118
+ function prepare(deps, session, selection) {
119
+ const measurement = deps.meter.measure(session);
120
+ const selectedNodes = measurement.nodes.slice(selection.startIdx, selection.endIdx + 1);
121
+ if (selectedNodes.length !== selection.shadowedSeqs.length || selectedNodes.some((node, index) => node.seq !== selection.shadowedSeqs[index]))
122
+ throw new SurfaceChangedError('compaction: selected surface changed before summarization began');
123
+ return {
124
+ ...selection, measurement, selectedNodes,
125
+ shadowedTokenCount: selectedNodes.reduce((total, node) => total + node.heuristicTokens, 0),
126
+ shadowedRouteTokenCount: selectedNodes.reduce((total, node) => total + node.tokens, 0),
127
+ messages: selection.shadowedSeqs.map(seq => session.deriveEventMessage(eventAt(session, seq))).filter((message) => message !== null),
128
+ };
129
+ }
130
+ async function summarize(deps, prepared, agent, compactionId, sourceCommandId, assertStable, signal) {
131
+ let summary;
132
+ for (;;) {
133
+ signal?.throwIfAborted();
134
+ try {
135
+ summary = await deps.summarize(prepared.messages, agent, signal);
136
+ break;
137
+ }
138
+ catch (error) {
139
+ if (signal?.aborted)
140
+ throw error;
141
+ assertStable(deps, agent.session, prepared);
142
+ if (!deps.recover(error, agent, prepared.shadowedSeqs, signal))
143
+ throw error;
144
+ prepared = prepare(deps, agent.session, validateSurfaceRegion(agent.session, prepared.start, prepared.end));
145
+ }
146
+ }
147
+ const checkpointMessage = createUserMessage({ content: deps.frame(summary.summary), source: compactCheckpointSource(compactionId, sourceCommandId) });
148
+ const framed = deps.meter.estimateMessage(checkpointMessage);
149
+ if (framed >= prepared.shadowedRouteTokenCount)
150
+ throw new Error(`summary is not smaller than the shadowed content (${framed} estimated framed tokens >= ${prepared.shadowedRouteTokenCount})`);
151
+ return { ...prepared, ...summary, checkpointMessage };
152
+ }
153
+ function assertWholeSurfaceUnchanged(deps, session, prepared) {
154
+ if (!isDeepStrictEqual(deps.meter.measure(session).nodes, prepared.measurement.nodes))
155
+ throw new SurfaceChangedError('compaction: session surface changed during summarization');
156
+ }
157
+ function assertSelectedSpanStable(deps, session, prepared) {
158
+ let current;
159
+ try {
160
+ current = validateSurfaceRegion(session, prepared.start, prepared.end);
161
+ }
162
+ catch (error) {
163
+ throw new SurfaceChangedError('compaction: the selected span is no longer a valid replacement target', { cause: error });
164
+ }
165
+ if (!isDeepStrictEqual([...current.shadowedSeqs], [...prepared.shadowedSeqs]))
166
+ throw new SurfaceChangedError('compaction: the selected span changed during summarization');
167
+ if (!isDeepStrictEqual(deps.meter.measure(session).nodes.slice(current.startIdx, current.endIdx + 1), prepared.selectedNodes))
168
+ throw new SurfaceChangedError('compaction: the selected span was rewritten during summarization');
169
+ }
170
+ function commitBody(session, startSeq, lifecycle, summarized) {
171
+ const { start, end, shadowedSeqs, shadowedTokenCount, summary, rawOutput, provider, model, maxTokens, usage, checkpointMessage } = summarized;
172
+ const { compactionId, sourceCommandId } = lifecycle;
173
+ const command = sourceCommandId === undefined ? {} : { sourceCommandId };
174
+ const summaryEvent = session.append('compaction/summary', {
175
+ compactionId, ...command, summary, rawOutput, shadowedRange: { start, end }, shadowedSeqs: [...shadowedSeqs], shadowedTokenCount, provider, model, maxTokens, ...(usage === undefined ? {} : { usage }),
176
+ });
177
+ session.append('user/message', checkpointMessage, { surfaceOp: { op: 'replace', startSeq: start, endSeq: end }, sourceEventSeqs: [startSeq, summaryEvent.seq, ...shadowedSeqs] });
178
+ return { compactionId, ...command, startSeq, summarySeq: summaryEvent.seq, summary, shadowedRange: { start, end }, shadowedSeqs: [...shadowedSeqs], shadowedTokenCount };
179
+ }
180
+ function inspectEntryState(session) {
181
+ let openTurn = null;
182
+ let turnKnown = false;
183
+ let unmatchedStart;
184
+ let lockKnown = false;
185
+ let latestEndSeedSeq;
186
+ for (let seq = session.seq - 1; seq >= 0; seq -= 1) {
187
+ const event = eventAt(session, SessionSeq(seq));
188
+ if (latestEndSeedSeq === undefined && event.type === 'session/end-seed')
189
+ latestEndSeedSeq = event.seq;
190
+ if (!lockKnown) {
191
+ if (event.type === 'compaction/start') {
192
+ unmatchedStart = event.seq;
193
+ lockKnown = true;
194
+ }
195
+ else if (event.type === 'compaction/end')
196
+ lockKnown = true;
197
+ }
198
+ if (!turnKnown) {
199
+ if (event.type === 'turn/start') {
200
+ openTurn = event.data.turn;
201
+ turnKnown = true;
202
+ }
203
+ else if (event.type === 'turn/end')
204
+ turnKnown = true;
205
+ }
206
+ if (turnKnown && lockKnown && latestEndSeedSeq !== undefined)
207
+ break;
208
+ }
209
+ return { openTurn, unmatchedStart, latestEndSeedSeq };
210
+ }
@@ -0,0 +1,57 @@
1
+ import type { IncomingMessage, ServerResponse } from 'node:http';
2
+ import { type JsonResult } from '../http.ts';
3
+ import { type Persona } from '../persona.ts';
4
+ import { type MemoryArchiveScope } from '../archiveSelection.ts';
5
+ export declare const CONSOLE_PREFIX = "/dsh-world";
6
+ /** A write must carry this header; a page on another site cannot add it without a CORS preflight, which is never answered. */
7
+ export declare const WRITE_HEADER = "x-dsh-world";
8
+ export interface ConsoleSources {
9
+ snapshot(): Promise<unknown>;
10
+ activity(day: string, outsideOnly: boolean): unknown;
11
+ diary(date: string): string | undefined;
12
+ }
13
+ /** What the console can change: whether her world runs, and her persona and world prompt. */
14
+ export interface ConsoleActions {
15
+ start(): Promise<void>;
16
+ stop(): Promise<void>;
17
+ prompts(): {
18
+ persona: Persona;
19
+ worldPrompt: {
20
+ text: string;
21
+ custom: boolean;
22
+ };
23
+ };
24
+ savePersona(persona: Partial<Persona>): void;
25
+ /** An empty text goes back to the shipped template. */
26
+ saveWorldPrompt(text: string): void;
27
+ /** CNY a day for her home; undefined removes the limit. */
28
+ setDailyBudget(yuan: number | undefined): void;
29
+ /** Turns in her memory block; undefined goes back to the default. */
30
+ setMemoryTurns(turns: number | undefined): void;
31
+ setArchiveScope(scope: MemoryArchiveScope): boolean;
32
+ /** A field left out stays as it is; null goes back to its default. */
33
+ /** Turns the WeChat and QQ modules on or off now (their tools and routes come and go with the switch). Returns why it cannot, or nothing. */
34
+ setModules(modules: {
35
+ wechat?: boolean;
36
+ qq?: boolean;
37
+ }): Promise<string | undefined>;
38
+ /** Restarts the adapter the plugin manages; false when it does not manage one. */
39
+ restartWechatAdapter(): Promise<boolean>;
40
+ setWechatSettings(settings: {
41
+ context?: number | null;
42
+ bufferSeconds?: number | null;
43
+ }): void;
44
+ }
45
+ export interface ConsoleRequest {
46
+ method: string;
47
+ url: string;
48
+ write: boolean;
49
+ body?: Record<string, unknown> | undefined;
50
+ }
51
+ /** Reads are open to the console page; writes need POST, the write header and a JSON body. */
52
+ export declare function handleConsole(sources: ConsoleSources, actions: ConsoleActions, request: ConsoleRequest): Promise<JsonResult>;
53
+ export declare function consoleRoute(sources: ConsoleSources, actions: ConsoleActions, allowedHosts?: readonly string[]): {
54
+ kind: "prefix";
55
+ path: string;
56
+ handler: (req: IncomingMessage, res: ServerResponse) => Promise<void>;
57
+ };
@@ -0,0 +1,129 @@
1
+ import { jsonObject, knownHost, readBody, sendJson } from "../http.js";
2
+ import { PERSONA_LAYERS } from "../persona.js";
3
+ import { validTurns, validWechatBuffer, validWechatContext, MAX_WECHAT_BUFFER_SECONDS, MAX_WECHAT_CONTEXT } from "../worldSwitch.js";
4
+ import { validArchiveScope } from "../archiveSelection.js";
5
+ export const CONSOLE_PREFIX = '/dsh-world';
6
+ /** A write must carry this header; a page on another site cannot add it without a CORS preflight, which is never answered. */
7
+ export const WRITE_HEADER = 'x-dsh-world';
8
+ const MAX_BODY_BYTES = 64 * 1024;
9
+ const ok = (body = { ok: true }) => ({ status: 200, body });
10
+ const bad = (error) => ({ status: 400, body: { error } });
11
+ function persona(body) {
12
+ if (!body)
13
+ return undefined;
14
+ const entries = Object.entries(body);
15
+ if (!entries.every(([key, value]) => PERSONA_LAYERS.includes(key) && typeof value === 'string'))
16
+ return undefined;
17
+ return Object.fromEntries(entries);
18
+ }
19
+ async function write(actions, path, body) {
20
+ switch (path) {
21
+ case '/console/start':
22
+ await actions.start();
23
+ return ok();
24
+ case '/console/stop':
25
+ await actions.stop();
26
+ return ok();
27
+ case '/console/persona': {
28
+ const layers = persona(body);
29
+ if (!layers)
30
+ return bad('persona layers must be strings');
31
+ actions.savePersona(layers);
32
+ return ok();
33
+ }
34
+ case '/console/budget': {
35
+ const daily = body?.daily;
36
+ if (daily !== null && (typeof daily !== 'number' || !Number.isFinite(daily) || daily < 0))
37
+ return bad('daily must be a non-negative number or null');
38
+ actions.setDailyBudget(daily === null ? undefined : daily);
39
+ return ok();
40
+ }
41
+ case '/console/memory': {
42
+ const turns = body?.turns;
43
+ if (turns !== null && !validTurns(turns))
44
+ return bad('turns must be a whole number of at least 1, or null');
45
+ actions.setMemoryTurns(turns === null ? undefined : turns);
46
+ return ok();
47
+ }
48
+ case '/console/wechat': {
49
+ const context = body?.contextMessages, bufferSeconds = body?.bufferSeconds;
50
+ if (context !== undefined && context !== null && !validWechatContext(context))
51
+ return bad(`contextMessages must be a whole number from 1 to ${MAX_WECHAT_CONTEXT}, or null`);
52
+ if (bufferSeconds !== undefined && bufferSeconds !== null && !validWechatBuffer(bufferSeconds))
53
+ return bad(`bufferSeconds must be a number from 0 to ${MAX_WECHAT_BUFFER_SECONDS}, or null`);
54
+ if (context === undefined && bufferSeconds === undefined)
55
+ return bad('nothing to change');
56
+ actions.setWechatSettings({ ...(context === undefined ? {} : { context }), ...(bufferSeconds === undefined ? {} : { bufferSeconds }) });
57
+ return ok();
58
+ }
59
+ case '/console/modules': {
60
+ const wechat = body?.wechat, qq = body?.qq;
61
+ if ((wechat !== undefined && typeof wechat !== 'boolean') || (qq !== undefined && typeof qq !== 'boolean'))
62
+ return bad('wechat 和 qq 必须是 true 或 false');
63
+ if (wechat === undefined && qq === undefined)
64
+ return bad('nothing to change');
65
+ const refused = await actions.setModules({ ...(wechat === undefined ? {} : { wechat }), ...(qq === undefined ? {} : { qq }) });
66
+ return refused ? bad(refused) : ok();
67
+ }
68
+ case '/console/wechat-adapter': return await actions.restartWechatAdapter() ? ok() : bad('适配器不是由插件管理的,请在配置里写 wechatAdapter');
69
+ case '/console/archive-scope': {
70
+ if (!validArchiveScope(body?.scope))
71
+ return bad('scope must be home or workspace');
72
+ return ok({ ok: true, restartRequired: actions.setArchiveScope(body.scope) });
73
+ }
74
+ case '/console/world-prompt': {
75
+ if (typeof body?.text !== 'string')
76
+ return bad('text must be a string');
77
+ actions.saveWorldPrompt(body.text);
78
+ return ok();
79
+ }
80
+ default: return { status: 404, body: { error: 'not found' } };
81
+ }
82
+ }
83
+ /** Reads are open to the console page; writes need POST, the write header and a JSON body. */
84
+ export async function handleConsole(sources, actions, request) {
85
+ const url = new URL(request.url, 'http://localhost');
86
+ if (url.pathname !== CONSOLE_PREFIX && !url.pathname.startsWith(CONSOLE_PREFIX + '/'))
87
+ return { status: 404, body: { error: 'not found' } };
88
+ const path = url.pathname.slice(CONSOLE_PREFIX.length);
89
+ if (request.method === 'POST') {
90
+ if (!request.write)
91
+ return { status: 403, body: { error: 'forbidden' } };
92
+ return write(actions, path, request.body);
93
+ }
94
+ if (request.method !== 'GET')
95
+ return { status: 405, body: { error: 'method not allowed' }, headers: { allow: 'GET, POST' } };
96
+ switch (path) {
97
+ case '/console/snapshot': return ok(await sources.snapshot());
98
+ case '/console/activity': return ok(sources.activity(url.searchParams.get('day') ?? '', url.searchParams.get('outside') === '1'));
99
+ case '/console/diary': {
100
+ const date = url.searchParams.get('date') ?? '';
101
+ const text = sources.diary(date);
102
+ return text === undefined ? { status: 404, body: { error: 'no diary for this date' } } : ok({ date, text });
103
+ }
104
+ case '/console/prompts': return ok(actions.prompts());
105
+ default: return { status: 404, body: { error: 'not found' } };
106
+ }
107
+ }
108
+ export function consoleRoute(sources, actions, allowedHosts = []) {
109
+ return {
110
+ kind: 'prefix', path: CONSOLE_PREFIX,
111
+ handler: async (req, res) => {
112
+ let result;
113
+ try {
114
+ if (req.headers['sec-fetch-site'] === 'cross-site' || !knownHost(req.headers.host, allowedHosts))
115
+ result = { status: 403, body: { error: 'cross-site requests are not allowed' } };
116
+ else {
117
+ const method = req.method ?? 'GET';
118
+ const write = method === 'POST' && req.headers[WRITE_HEADER] === '1' && String(req.headers['content-type'] ?? '').startsWith('application/json');
119
+ const body = write ? jsonObject(await readBody(req, MAX_BODY_BYTES)) : undefined;
120
+ result = write && body === undefined ? bad('a JSON object body is required') : await handleConsole(sources, actions, { method, url: req.url ?? '/', write, body });
121
+ }
122
+ }
123
+ catch {
124
+ result = { status: 500, body: { error: 'internal error' } };
125
+ }
126
+ sendJson(res, result);
127
+ },
128
+ };
129
+ }
@@ -0,0 +1,39 @@
1
+ import type { Context } from '@deepseek-ai/cordis';
2
+ import type { LifeStore } from '../life/lifeStore.ts';
3
+ import type { LifeRuntime } from '../life/runtime.ts';
4
+ import type { ArchiveStore } from '../store.ts';
5
+ import type { WorldConfig } from '../types.ts';
6
+ import type { WorldNames } from '../worldPrompt.ts';
7
+ import type { MemoryArchiveScope } from '../archiveSelection.ts';
8
+ import type { ConsoleSources } from './routes.ts';
9
+ export declare function estimateTokens(text: string): number;
10
+ export interface SnapshotDeps {
11
+ ctx: Context;
12
+ config: WorldConfig;
13
+ archive: ArchiveStore;
14
+ names(): WorldNames;
15
+ /** Absent when the life line could not be set up. */
16
+ lifeStore?: LifeStore;
17
+ /** The running life line; undefined while her world is stopped. */
18
+ life(): LifeRuntime | undefined;
19
+ diaryDir: string;
20
+ running(): boolean;
21
+ /** CNY a day for her home; undefined is no limit. */
22
+ dailyBudget(): number | undefined;
23
+ /** Turns her memory block carries. */
24
+ memoryTurns(): number;
25
+ selectedArchiveScope?(): MemoryArchiveScope;
26
+ /** The WeChat module's state; undefined while it is off or her world is stopped. */
27
+ wechat?(): unknown;
28
+ includesSession?(id: string): boolean;
29
+ /** Faults outside the life line: the memory line, the bridge, the QQ bridge, starting and stopping. */
30
+ faults(): string[];
31
+ /** Which modules the config allows, whether their console switch is on, and whether they are running now. */
32
+ modules?(): unknown;
33
+ /** The QQ bridge, when the module is on; absent leaves that card out of the console. */
34
+ qq?: () => Promise<unknown>;
35
+ }
36
+ /** Read-only views for the console; repeated polling within a few seconds reuses one snapshot until `invalidate`. */
37
+ export declare function consoleSources(deps: SnapshotDeps): ConsoleSources & {
38
+ invalidate(): void;
39
+ };
@@ -0,0 +1,51 @@
1
+ import { SessionId } from '@deepseek-ai/dsh-session';
2
+ import { createHistory, renderHistory } from "../history.js";
3
+ import { createDiaryReader } from "../life/diary.js";
4
+ const SNAPSHOT_TTL_MS = 5000;
5
+ export function estimateTokens(text) {
6
+ const cjk = (text.match(/[㐀-鿿豈-﫿 -〿＀-￯]/g) ?? []).length;
7
+ return Math.round(cjk * 0.6 + (text.length - cjk) / 3.5);
8
+ }
9
+ /** Read-only views for the console; repeated polling within a few seconds reuses one snapshot until `invalidate`. */
10
+ export function consoleSources(deps) {
11
+ const { config, archive, lifeStore } = deps;
12
+ const history = createHistory(archive);
13
+ const diary = createDiaryReader(deps.diaryDir);
14
+ let cached;
15
+ async function compute() {
16
+ const life = deps.life()?.snapshot();
17
+ const home = life?.homeSessionId ? deps.ctx.agents.get(SessionId(life.homeSessionId)) : undefined;
18
+ const window = deps.memoryTurns();
19
+ const turns = await history.loadRecentTurns(config.worldId, window, deps.includesSession);
20
+ const archiveScope = config.archiveScope ?? 'workspace';
21
+ const selectedArchiveScope = deps.selectedArchiveScope?.() ?? archiveScope;
22
+ // Never let a dead bridge take the whole console down with it: a broken QQ module shows as "not running".
23
+ const qq = deps.qq ? await deps.qq().catch(() => null) : null;
24
+ return {
25
+ worldId: config.worldId, timeZone: config.timeZone, now: new Date().toISOString(), running: deps.running(), name: deps.names().companion,
26
+ budget: { daily: deps.dailyBudget() ?? null, today: life?.spend ?? null },
27
+ life: life ? { homeSessionId: life.homeSessionId, status: home ? home.status : 'cold', alarm: life.alarm, review: life.review, recentWakes: lifeStore?.wakes().slice(-5).reverse() ?? [] } : null,
28
+ health: [...(life?.faults ?? []), ...deps.faults()],
29
+ memory: { turns: turns.length, windowTurns: window, archiveScope, selectedArchiveScope, restartRequired: archiveScope !== selectedArchiveScope, approxTokens: estimateTokens(renderHistory(turns, config.timeZone, deps.names(), archiveScope === 'home')), oldest: turns.at(-1)?.messages[0]?.occurredAt, ...archive.stats() },
30
+ wechat: deps.wechat?.() ?? null,
31
+ compactions: lifeStore?.compactions().slice(-5).reverse() ?? [],
32
+ diaryDates: diary.dates(), activityDays: lifeStore?.activityDays() ?? [],
33
+ qq: deps.qq ? qq : null,
34
+ modules: deps.modules?.() ?? null,
35
+ };
36
+ }
37
+ return {
38
+ snapshot() {
39
+ if (cached && Date.now() - cached.at < SNAPSHOT_TTL_MS)
40
+ return cached.value;
41
+ const entry = { at: Date.now(), value: compute() };
42
+ cached = entry;
43
+ entry.value.catch(() => { if (cached === entry)
44
+ cached = undefined; });
45
+ return entry.value;
46
+ },
47
+ invalidate() { cached = undefined; },
48
+ activity: (day, outsideOnly) => lifeStore?.activity(day).filter(record => !outsideOnly || record.outside).reverse() ?? [],
49
+ diary: date => diary.read(date),
50
+ };
51
+ }
@@ -0,0 +1,36 @@
1
+ import type { Context } from '@deepseek-ai/cordis';
2
+ import type { Agent } from '@deepseek-ai/dsh-agent';
3
+ import { type LifeTimers } from '../../life/alarmTimer.ts';
4
+ import { type Outlet } from '../shared/outlets.ts';
5
+ export declare const REPLY_TIMEOUT_MS: number;
6
+ /** The words could not be handed to her home; the route answers 503. */
7
+ export declare class HomeUnavailable extends Error {
8
+ }
9
+ export interface BridgeDeps {
10
+ ctx: Context;
11
+ /** The current home, resolving or rebuilding it (the life line's own). */
12
+ home(): Promise<Agent>;
13
+ /** Where her replies and the busy notice go; each takes the kinds it lists. */
14
+ outlets: readonly Outlet[];
15
+ origin(): string;
16
+ /** `<world>/bridge.json`, where a local app finds the bridge. */
17
+ file: string;
18
+ timers?: LifeTimers;
19
+ clock?: () => Date;
20
+ /** Her name, in the busy notice and the console's faults; TA when unnamed. */
21
+ name?: string;
22
+ }
23
+ /**
24
+ * A local app's way into her home: its words arrive as her partner's own (source `user`), and the first
25
+ * visible text she says after they are admitted goes to the outlets. Only the latest words are tracked.
26
+ */
27
+ export declare function createBridge(deps: BridgeDeps): {
28
+ start: () => void;
29
+ stop: () => void;
30
+ say: (text: string) => Promise<{
31
+ id: string;
32
+ }>;
33
+ checkToken: (value: string | undefined) => boolean;
34
+ faults: () => string[];
35
+ };
36
+ export type Bridge = ReturnType<typeof createBridge>;
@@ -0,0 +1,140 @@
1
+ import { randomBytes, timingSafeEqual } from 'node:crypto';
2
+ import { readFileSync, rmSync } from 'node:fs';
3
+ import { createUserMessage } from '@deepseek-ai/dsh-llm';
4
+ import { durableWrite } from "../../life/lifeStore.js";
5
+ import { errorText, Faults } from "../../faults.js";
6
+ import { realTimers } from "../../life/alarmTimer.js";
7
+ import { busyText, pushOf } from "../shared/outlets.js";
8
+ export const REPLY_TIMEOUT_MS = 3 * 60_000;
9
+ /** The words could not be handed to her home; the route answers 503. */
10
+ export class HomeUnavailable extends Error {
11
+ }
12
+ const labels = (name) => ({ reply: `${name}的回复`, busy: `「${name}在忙」`, reach: `${name}找你的话` });
13
+ /**
14
+ * A local app's way into her home: its words arrive as her partner's own (source `user`), and the first
15
+ * visible text she says after they are admitted goes to the outlets. Only the latest words are tracked.
16
+ */
17
+ export function createBridge(deps) {
18
+ const { ctx } = deps;
19
+ const name = deps.name ?? 'TA';
20
+ const clock = deps.clock ?? (() => new Date());
21
+ const timers = deps.timers ?? realTimers;
22
+ const faults = new Faults();
23
+ const disposers = [];
24
+ const token = randomBytes(32).toString('hex');
25
+ let tracked;
26
+ let stopped = false;
27
+ function send(push) {
28
+ for (const outlet of deps.outlets) {
29
+ if (!outlet.kinds.includes(push.kind))
30
+ continue;
31
+ const key = `push:${outlet.name}`;
32
+ void outlet.send(push).then(() => faults.clear(key), error => {
33
+ if (stopped)
34
+ return;
35
+ faults.set(key, `${outlet.name}没收到${labels(name)[push.kind]}:${errorText(error)}`);
36
+ ctx.logger.warn(`dsh-world: the push to ${outlet.name} failed:`, error);
37
+ });
38
+ }
39
+ }
40
+ function untrack() {
41
+ if (tracked?.timer !== undefined)
42
+ timers.clear(tracked.timer);
43
+ tracked = undefined;
44
+ }
45
+ function track(id, sessionId) {
46
+ untrack();
47
+ const entry = { id, sessionId, admitted: false };
48
+ // The reply stays tracked after "busy": it is still pushed when it comes.
49
+ entry.timer = timers.set(() => { entry.timer = undefined; if (tracked === entry && !stopped)
50
+ send({ text: busyText(name), kind: 'busy', name }); }, REPLY_TIMEOUT_MS);
51
+ tracked = entry;
52
+ }
53
+ function start() {
54
+ disposers.push(ctx.on('session/event', (session, event) => {
55
+ if (!tracked || session.id !== tracked.sessionId)
56
+ return;
57
+ if (event.type === 'user/message' && event.data.id === tracked.id) {
58
+ tracked.admitted = true;
59
+ return;
60
+ }
61
+ if (event.type !== 'assistant/message' || !tracked.admitted)
62
+ return;
63
+ const visible = event.data.message.content.flatMap(block => block.type === 'text' ? [block.text] : []).join('\n');
64
+ const reply = pushOf(visible, 'reply', name, safeOrigin());
65
+ if (!reply.text && !reply.images)
66
+ return;
67
+ untrack();
68
+ send(reply);
69
+ }));
70
+ try {
71
+ durableWrite(deps.file, JSON.stringify({ origin: deps.origin(), token, pid: process.pid, startedAt: clock().toISOString(), name }, null, 2));
72
+ faults.clear('file');
73
+ }
74
+ catch (error) {
75
+ faults.set('file', `bridge.json 没能写入,外面的程序找不到家:${errorText(error)}`);
76
+ ctx.logger.error(error);
77
+ }
78
+ }
79
+ function safeOrigin() { try {
80
+ return deps.origin();
81
+ }
82
+ catch {
83
+ return undefined;
84
+ } }
85
+ function stop() {
86
+ if (stopped)
87
+ return;
88
+ stopped = true;
89
+ untrack();
90
+ for (const dispose of disposers.splice(0).reverse())
91
+ dispose();
92
+ // A newer start (a reload) may already have written its own token; that file is not ours to remove.
93
+ try {
94
+ if (JSON.parse(readFileSync(deps.file, 'utf8')).token === token)
95
+ rmSync(deps.file, { force: true });
96
+ }
97
+ catch { /* gone or unreadable */ }
98
+ }
99
+ function checkToken(value) {
100
+ if (typeof value !== 'string')
101
+ return false;
102
+ const given = Buffer.from(value);
103
+ const expected = Buffer.from(token);
104
+ return given.length === expected.length && timingSafeEqual(given, expected);
105
+ }
106
+ async function say(text) {
107
+ if (stopped)
108
+ throw new HomeUnavailable('the bridge is stopped');
109
+ let agent;
110
+ try {
111
+ agent = await deps.home();
112
+ }
113
+ catch (error) {
114
+ faults.set('home', `从外面送来的话没进家:${errorText(error)}`);
115
+ ctx.logger.error(error);
116
+ throw new HomeUnavailable(errorText(error), { cause: error });
117
+ }
118
+ if (stopped)
119
+ throw new HomeUnavailable('the bridge is stopped');
120
+ const words = createUserMessage({ source: { kind: 'user' }, content: [{ type: 'text', text }] });
121
+ // Tracked first: steering can admit the words before it returns.
122
+ track(words.id, agent.id);
123
+ try {
124
+ // Like her partner typing in the home: into the running turn at its next step, or a new turn.
125
+ if (agent.status === 'running')
126
+ agent.steer(words);
127
+ else
128
+ agent.followup(words);
129
+ }
130
+ catch (error) {
131
+ untrack();
132
+ faults.set('home', `从外面送来的话没进家:${errorText(error)}`);
133
+ ctx.logger.error(error);
134
+ throw new HomeUnavailable(errorText(error), { cause: error });
135
+ }
136
+ faults.clear('home');
137
+ return { id: words.id };
138
+ }
139
+ return { start, stop, say, checkToken, faults: () => faults.list() };
140
+ }