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,56 @@
1
+ /**
2
+ * tools/zoom.js — `video_zoom` 的 execute。
3
+ *
4
+ * 两件事这里必须自己做(不能交给 boardOptions):
5
+ * 1. `cellId` → 该格的绝对时间区间。查不到就**明确报错并指路**,不悄悄退回一个猜的窗口。
6
+ * 2. 链接模式下先设法拿到高清直链 —— storyboard 那次 `-J` 通常已经记下了,
7
+ * 这里多半是内存命中;实在没有才真的再解析一次(2.4 s)。
8
+ */
9
+
10
+ import { boardOptions } from '../storyboard/board.js';
11
+ import { lookupCell } from '../storyboard/cells.js';
12
+ import { resolveInput } from '../storyboard/fetch.js';
13
+ import { isHttpUrl } from '../storyboard/url.js';
14
+ import { resolveDirectUrl } from '../storyboard/direct-url.js';
15
+ import { runStoryboard } from '../storyboard/pipeline.js';
16
+ import { formatForDetail } from '../storyboard/format.js';
17
+ import { validateZoomArgs } from '../storyboard/tool-spec.js';
18
+ import { attachSheetImages } from './shared.js';
19
+
20
+ export async function execute(ctx, args) {
21
+ const problems = validateZoomArgs(args);
22
+ if (problems.length > 0) throw new Error(`invalid arguments: ${problems.join('; ')}`);
23
+
24
+ // cellId → 该格的绝对时间区间(上一次分镜落下的表)。
25
+ let from = args.from;
26
+ let to = args.to;
27
+ if (args.cellId !== undefined && args.cellId !== null) {
28
+ const hit = await lookupCell(args.input, args.cellId);
29
+ if (!hit) {
30
+ throw new Error(`no cell map recorded for this input (cellId ${args.cellId}). ` +
31
+ 'Run video_storyboard on it first, or pass from/to.');
32
+ }
33
+ from = hit.from;
34
+ to = hit.to;
35
+ }
36
+ // zoom 的参数只在一处定义(src/board.js)。这里先拿它的 fetchOptions 去解析直链,
37
+ // 免得"扫描清晰度/zoom 清晰度"在解析和取帧两处出现两个值。
38
+ const opts = boardOptions({ ...args, from, to }, { kind: 'zoom' });
39
+ const fetchOptions = opts.fetchOptions;
40
+ let frameSource = null;
41
+ if (isHttpUrl(args.input)) {
42
+ try {
43
+ const resolved = await resolveInput(args.input, fetchOptions);
44
+ frameSource = resolved.frameSource
45
+ ?? await resolveDirectUrl(args.input, { ...fetchOptions, height: fetchOptions.zoomHeight });
46
+ } catch {
47
+ /* 直链拿不到就退回本地低清:糊一点,但整次调用不该失败 */
48
+ }
49
+ }
50
+ const result = await runStoryboard({ ...opts, frameSource });
51
+ return {
52
+ images: await attachSheetImages(ctx, result),
53
+ text: formatForDetail(result, { detail: args.detail ?? 'med' }),
54
+ };
55
+ }
56
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ckz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,6 @@
1
+ # Inserts the dsh-world row enabled: with no config it serves the standard preset as a world named
2
+ # "default" in the system time zone. Override the row by id in a profile to name the companion, pick
3
+ # another preset or turn on the life line (see README).
4
+ - insert:
5
+ - id: dsh-world
6
+ name: dsh-world
@@ -0,0 +1,6 @@
1
+ import { type ContentBlock } from '@deepseek-ai/dsh-llm';
2
+ import { type SessionEvent } from '@deepseek-ai/dsh-session';
3
+ import type { ArchiveScope, ConversationRecord } from './types.ts';
4
+ export declare const conversationRecordId: (worldId: string, sessionId: string, messageId: string) => string;
5
+ export declare function visibleText(content: readonly ContentBlock[]): string;
6
+ export declare function extractConversationRecords(event: SessionEvent, scope: ArchiveScope): ConversationRecord[];
@@ -0,0 +1,49 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { lastAssistantStreamChunk } from '@deepseek-ai/dsh-llm';
3
+ import { isAppendSurfaceEvent } from '@deepseek-ai/dsh-session';
4
+ import { identityPrefix, speakerIdentity } from "./ecosystem/shared/identity.js";
5
+ import { replyMessages, replyText } from "./ecosystem/wechat/messages.js";
6
+ export const conversationRecordId = (worldId, sessionId, messageId) => createHash('sha256').update(JSON.stringify([worldId, sessionId, messageId])).digest('hex');
7
+ export function visibleText(content) {
8
+ return content.flatMap(block => {
9
+ if (block.type === 'text')
10
+ return [block.text];
11
+ if (block.type === 'image' || block.type === 'file')
12
+ return [JSON.stringify({ type: block.type, attachment: block.attachment })];
13
+ return [];
14
+ }).join('\n');
15
+ }
16
+ export function extractConversationRecords(event, scope) {
17
+ const { header } = scope;
18
+ if ((!scope.archiveScope && header.agentPreset !== scope.agentPreset) || header.origin === 'subagent' || (header.delegationDepth ?? 0) > 0 || event.seq < scope.inheritedEventCount)
19
+ return [];
20
+ if (event.type !== 'user/message' && event.type !== 'assistant/message')
21
+ return [];
22
+ if (!isAppendSurfaceEvent(event))
23
+ return [];
24
+ const message = event.type === 'user/message' ? event.data : event.data.message;
25
+ const outgoing = event.type === 'user/message' && event.data.source.kind === 'dsh-world-wechat-outgoing' ? event.data.source : undefined;
26
+ if (event.type === 'user/message' && message.source.kind !== 'user' && !outgoing)
27
+ return [];
28
+ const identity = event.type === 'user/message' && 'identity' in message.source ? speakerIdentity(message.source.identity) : undefined;
29
+ const sentMessages = outgoing ? replyMessages(outgoing.messages) : undefined;
30
+ if (outgoing && (identity?.channel !== 'wechat' || identity.speakerId !== `wechat:${identity.accountId}`))
31
+ throw new Error('Invalid WeChat outgoing identity');
32
+ const visible = visibleText(message.content);
33
+ const prefix = identity ? identityPrefix(identity) : '';
34
+ const content = outgoing ? `微信待发送给 ${identity.conversationId}(已生成,发送尚未确认):\n${replyText(sentMessages)}` : prefix && visible.startsWith(prefix) ? visible.slice(prefix.length) : visible;
35
+ if (!content)
36
+ return [];
37
+ const turn = event.type === 'assistant/message' ? event.data.turn : scope.turn;
38
+ if (!Number.isSafeInteger(turn) || turn < 1)
39
+ throw new Error(`dsh-world: no host turn for ${header.id}/${event.seq}`);
40
+ return [{
41
+ schemaVersion: 1, worldId: scope.worldId,
42
+ recordId: conversationRecordId(scope.worldId, header.id, message.id),
43
+ sourceSessionId: header.id, sourceMessageId: message.id, sourceSeq: event.seq,
44
+ turnId: `${header.id}:${turn}`, role: event.type === 'user/message' && !outgoing ? 'user' : 'assistant',
45
+ occurredAt: new Date(event.time).toISOString(), content, ...identity,
46
+ ...(sentMessages ? { wechatDelivery: { status: 'pending', confirmed: 0, total: sentMessages.length } } : {}),
47
+ status: event.type === 'assistant/message' && (event.data.interrupted || lastAssistantStreamChunk(event.data.stream, 'finish')?.reason.kind === 'max-tokens') ? 'interrupted' : 'complete',
48
+ }];
49
+ }
@@ -0,0 +1,8 @@
1
+ import type { Context } from '@deepseek-ai/cordis';
2
+ export type MemoryArchiveScope = 'home' | 'workspace';
3
+ export declare const validArchiveScope: (value: unknown) => value is MemoryArchiveScope;
4
+ /** Workspace membership comes from the host, never a preset or a display name. */
5
+ export declare function createArchiveSelection(ctx: Context, scope: MemoryArchiveScope, isHome: (id: string) => boolean, roomDir: string, qq?: {
6
+ readonly scope?: string;
7
+ readonly sessionsFile?: string;
8
+ }): (id: string) => boolean;
@@ -0,0 +1,20 @@
1
+ import { existsSync, realpathSync } from 'node:fs';
2
+ import { inQqScope } from "./qqScope.js";
3
+ export const validArchiveScope = (value) => value === 'home' || value === 'workspace';
4
+ /** Workspace membership comes from the host, never a preset or a display name. */
5
+ export function createArchiveSelection(ctx, scope, isHome, roomDir, qq = {}) {
6
+ return id => {
7
+ // The QQ binding owns the memory: only the conversations it bound read and write this world.
8
+ if (qq.scope === 'qq')
9
+ return inQqScope(id, qq.sessionsFile);
10
+ if (scope === 'home')
11
+ return isHome(id);
12
+ const registry = ctx.get('workspaceRegistry');
13
+ if (!registry)
14
+ throw new Error('工作区归档需要宿主工作区服务');
15
+ const workspaces = registry.list();
16
+ const room = workspaces.find(workspace => workspace.sessionIds.some(isHome))
17
+ ?? workspaces.find(workspace => workspace.path === (existsSync(roomDir) ? realpathSync(roomDir) : roomDir));
18
+ return room?.sessionIds.includes(id) ?? false;
19
+ };
20
+ }
@@ -0,0 +1,124 @@
1
+ import type { Context } from '@deepseek-ai/cordis';
2
+ import z from '@deepseek-ai/schemastery';
3
+ import { CompactionEngine, type CompactionAgentContext, type CompactionResult, type CompactionTrigger, type ManualCompactAgentContext } from '@deepseek-ai/dsh-compaction';
4
+ import type { CommandId } from '@deepseek-ai/dsh-commands/brand';
5
+ import { type Message } from '@deepseek-ai/dsh-llm';
6
+ import { type SessionSeq } from '@deepseek-ai/dsh-session';
7
+ import { type RegionAgent, type SummaryResult } from './compactionRegion.ts';
8
+ import './hostContract.ts';
9
+ interface SummaryAudit {
10
+ policyVersion: 2;
11
+ provider: string;
12
+ model: string;
13
+ maxTokens: number;
14
+ instruction: string;
15
+ timeContext: string;
16
+ replayedMessageIds: string[];
17
+ }
18
+ declare module '@deepseek-ai/dsh-session/types' {
19
+ interface PluginRecordMap {
20
+ 'plugin:dsh-world/compaction-request': SummaryAudit;
21
+ }
22
+ }
23
+ interface Policy {
24
+ thresholdRatio: number;
25
+ headroomTokens: number;
26
+ summarizationProvider: string;
27
+ summarizationModel: string;
28
+ maxTokens: number;
29
+ maxOverflowRetries: number;
30
+ }
31
+ export interface ToolFreeCompactionConfig extends Partial<Policy> {
32
+ timeZone?: string;
33
+ auto?: boolean;
34
+ modelPolicies?: (Partial<Policy> & {
35
+ provider: string;
36
+ model: string;
37
+ })[];
38
+ }
39
+ /**
40
+ * The compacted span exactly as the conversation request sent it, minus every
41
+ * tool call and tool result, so the summary request shares the longest possible
42
+ * provider-cached prefix. Assistant text split around a removed call is rejoined.
43
+ */
44
+ export declare function toolFreeMessages(messages: readonly Message[]): Message[];
45
+ /**
46
+ * Replacement for `@deepseek-ai/dsh-compaction-basic`: drops every tool call,
47
+ * tool result, tool schema and reasoning block from the compacted span, then
48
+ * replaces the whole conversation with one summary paragraph.
49
+ */
50
+ export default class ToolFreeCompaction extends CompactionEngine {
51
+ static inject: string[];
52
+ static Config: z<Schemastery.ObjectS<NoInfer<{
53
+ timeZone: z<string, string, "plain">;
54
+ auto: z<boolean, boolean, "plain">;
55
+ thresholdRatio: z<number, number, "plain">;
56
+ headroomTokens: z<number, number, "plain">;
57
+ summarizationProvider: z<string, string, "plain">;
58
+ summarizationModel: z<string, string, "plain">;
59
+ maxTokens: z<number, number, "plain">;
60
+ maxOverflowRetries: z<number, number, "plain">;
61
+ modelPolicies: z<({
62
+ provider?: string | null | undefined;
63
+ model?: string | null | undefined;
64
+ thresholdRatio?: number | null | undefined;
65
+ headroomTokens?: number | null | undefined;
66
+ summarizationProvider?: string | null | undefined;
67
+ summarizationModel?: string | null | undefined;
68
+ maxTokens?: number | null | undefined;
69
+ maxOverflowRetries?: number | null | undefined;
70
+ } & import("@deepseek-ai/cosmokit").Dict)[], Schemastery.ObjectT<NoInfer<{
71
+ provider: z<string, string, "defined">;
72
+ model: z<string, string, "defined">;
73
+ thresholdRatio: z<number, number, "plain">;
74
+ headroomTokens: z<number, number, "plain">;
75
+ summarizationProvider: z<string, string, "plain">;
76
+ summarizationModel: z<string, string, "plain">;
77
+ maxTokens: z<number, number, "plain">;
78
+ maxOverflowRetries: z<number, number, "plain">;
79
+ }>>[], "plain">;
80
+ }>>, Schemastery.ObjectT<NoInfer<{
81
+ timeZone: z<string, string, "plain">;
82
+ auto: z<boolean, boolean, "plain">;
83
+ thresholdRatio: z<number, number, "plain">;
84
+ headroomTokens: z<number, number, "plain">;
85
+ summarizationProvider: z<string, string, "plain">;
86
+ summarizationModel: z<string, string, "plain">;
87
+ maxTokens: z<number, number, "plain">;
88
+ maxOverflowRetries: z<number, number, "plain">;
89
+ modelPolicies: z<({
90
+ provider?: string | null | undefined;
91
+ model?: string | null | undefined;
92
+ thresholdRatio?: number | null | undefined;
93
+ headroomTokens?: number | null | undefined;
94
+ summarizationProvider?: string | null | undefined;
95
+ summarizationModel?: string | null | undefined;
96
+ maxTokens?: number | null | undefined;
97
+ maxOverflowRetries?: number | null | undefined;
98
+ } & import("@deepseek-ai/cosmokit").Dict)[], Schemastery.ObjectT<NoInfer<{
99
+ provider: z<string, string, "defined">;
100
+ model: z<string, string, "defined">;
101
+ thresholdRatio: z<number, number, "plain">;
102
+ headroomTokens: z<number, number, "plain">;
103
+ summarizationProvider: z<string, string, "plain">;
104
+ summarizationModel: z<string, string, "plain">;
105
+ maxTokens: z<number, number, "plain">;
106
+ maxOverflowRetries: z<number, number, "plain">;
107
+ }>>[], "plain">;
108
+ }>>, "plain">;
109
+ private readonly policy;
110
+ private readonly overrides;
111
+ private readonly timeZone;
112
+ private readonly warnedTargets;
113
+ private readonly overflowRetries;
114
+ private readonly overflowAgents;
115
+ constructor(ctx: Context, config?: ToolFreeCompactionConfig);
116
+ private policyFor;
117
+ private registerAutomaticCompaction;
118
+ compactIfNeeded(agent: CompactionAgentContext, trigger: CompactionTrigger, signal: AbortSignal): Promise<CompactionResult | null>;
119
+ compactRegion(start: SessionSeq, end: SessionSeq, agent: CompactionAgentContext, signal?: AbortSignal): Promise<CompactionResult>;
120
+ compactNow(agent: ManualCompactAgentContext, signal: AbortSignal, sourceCommandId?: CommandId): Promise<CompactionResult | null>;
121
+ private dependencies;
122
+ protected summarize(messages: Message[], agent: RegionAgent, signal?: AbortSignal): Promise<SummaryResult>;
123
+ }
124
+ export {};
@@ -0,0 +1,273 @@
1
+ import z from '@deepseek-ai/schemastery';
2
+ import { CompactionEngine, ManualCompactionError, isCompactCheckpointSource } from '@deepseek-ai/dsh-compaction';
3
+ import { BlockAssembler, CONTEXT_WINDOW_EXCEEDED_CODE, LlmError, createUserMessage } from '@deepseek-ai/dsh-llm';
4
+ import { appendPluginRecord } from '@deepseek-ai/dsh-session';
5
+ import { visibleText } from "./archive.js";
6
+ import { assertNoActiveCompaction, compactSurfaceRegion, selectWholeRange } from "./compactionRegion.js";
7
+ import { formatTimeContext } from "./timeContext.js";
8
+ import "./hostContract.js";
9
+ const summaryInstruction = [
10
+ '现在暂停对话,改为执行上下文压缩:把上面这段会话中双方的交流整理成一段精炼的中文摘要,供你之后接着对话使用。',
11
+ '保留用户的意图、情绪与关系进展、明确要求、重要事实、已作决定、未完成事项和最近进展;最后一条用户发言尽量按原意完整保留。以“以下是此前交流的摘要”开头的消息是更早的摘要,请与新内容合并为同一段。',
12
+ '以【我的时间】(较早的是【你的时间】)开头的消息是你自己定的闹钟和留给自己的话,不是用户说的话;把它们当作你自己的安排来记,不要算作用户发言。',
13
+ '开头写着“这是我们最近的聊天记录”(较早的写着“最近的聊天记忆”或“最近的相处记忆”)的记忆资料、系统提示里的世界提示词(含「我是谁」)和“Time sampled”开头的时间块会在压缩后重新提供,不要写进摘要。工具调用过程已从会话中删除,不要提及工具。',
14
+ '保留准确的姓名、日期、数字和标识,分清每件事是谁说的、谁做的。不要标题、列表或分段,不要开头语,不要补写原文没有的事实,不要调用任何工具,直接输出摘要正文。',
15
+ ].join('\n');
16
+ // The model tends to echo the checkpoint lead it saw on earlier summaries; the frame adds it once.
17
+ const leadEcho = /^以下是此前交流的摘要[^::]{0,40}[::]\s*/;
18
+ const checkpointLead = '以下是此前交流的摘要,工具调用过程已省略;请把它当作已知背景,直接接着当前对话继续:';
19
+ // Re-injected after every successful compaction by the memory runtime; replayed only as cacheable prefix.
20
+ const injectedSources = new Set(['time-context', 'dsh-world-history']);
21
+ /**
22
+ * The compacted span exactly as the conversation request sent it, minus every
23
+ * tool call and tool result, so the summary request shares the longest possible
24
+ * provider-cached prefix. Assistant text split around a removed call is rejoined.
25
+ */
26
+ export function toolFreeMessages(messages) {
27
+ const kept = [];
28
+ for (const message of messages) {
29
+ if (message.role === 'tool')
30
+ continue;
31
+ if (message.role !== 'assistant') {
32
+ kept.push(message);
33
+ continue;
34
+ }
35
+ const content = message.content.filter(block => block.type !== 'tool-call');
36
+ // A step that only reasoned before calling a tool has nothing left to say.
37
+ if (!content.some(block => block.type !== 'reasoning'))
38
+ continue;
39
+ const previous = kept.at(-1);
40
+ if (previous?.role === 'assistant')
41
+ kept[kept.length - 1] = { ...previous, content: [...previous.content, ...content] };
42
+ else
43
+ kept.push(content.length === message.content.length ? message : { ...message, content });
44
+ }
45
+ return kept;
46
+ }
47
+ function hasConversation(messages) {
48
+ return messages.some(message => (message.role === 'user' || message.role === 'assistant') && !injectedSources.has(message.source.kind) && !(message.role === 'user' && isCompactCheckpointSource(message.source)) && visibleText(message.content).trim());
49
+ }
50
+ function routedTarget(session) {
51
+ const config = session.requestHeader()?.config;
52
+ return config?.provider && config.model ? { provider: config.provider, model: config.model } : undefined;
53
+ }
54
+ function resolvePolicy(config) {
55
+ return {
56
+ thresholdRatio: config.thresholdRatio ?? 0.9, headroomTokens: config.headroomTokens ?? 65536,
57
+ summarizationProvider: config.summarizationProvider ?? '', summarizationModel: config.summarizationModel ?? '',
58
+ maxTokens: config.maxTokens ?? config.headroomTokens ?? 65536, maxOverflowRetries: config.maxOverflowRetries ?? 1,
59
+ };
60
+ }
61
+ /** Pressure failures specific to one routed model; warned once per target. */
62
+ class TargetConfigError extends Error {
63
+ targetKey;
64
+ constructor(targetKey, message) { super(message); this.targetKey = targetKey; }
65
+ }
66
+ /**
67
+ * Replacement for `@deepseek-ai/dsh-compaction-basic`: drops every tool call,
68
+ * tool result, tool schema and reasoning block from the compacted span, then
69
+ * replaces the whole conversation with one summary paragraph.
70
+ */
71
+ export default class ToolFreeCompaction extends CompactionEngine {
72
+ static inject = ['llm', 'tokenMeter', 'sessions'];
73
+ static Config = z.object({
74
+ timeZone: z.string(), auto: z.boolean(),
75
+ thresholdRatio: z.number(), headroomTokens: z.natural(), summarizationProvider: z.string(), summarizationModel: z.string(),
76
+ maxTokens: z.natural(), maxOverflowRetries: z.natural(),
77
+ modelPolicies: z.array(z.object({ provider: z.string().required(), model: z.string().required(), thresholdRatio: z.number(), headroomTokens: z.natural(), summarizationProvider: z.string(), summarizationModel: z.string(), maxTokens: z.natural(), maxOverflowRetries: z.natural() })),
78
+ });
79
+ policy;
80
+ overrides;
81
+ timeZone;
82
+ warnedTargets = new Set();
83
+ overflowRetries = new WeakMap();
84
+ overflowAgents = new WeakMap();
85
+ constructor(ctx, config = {}) {
86
+ super(ctx);
87
+ const source = Object.fromEntries(Object.entries(config).filter(([, value]) => value !== undefined));
88
+ this.timeZone = source.timeZone ?? Intl.DateTimeFormat().resolvedOptions().timeZone;
89
+ this.policy = resolvePolicy(source);
90
+ this.overrides = (source.modelPolicies ?? []).map(override => {
91
+ const entry = Object.fromEntries(Object.entries(override).filter(([, value]) => value !== undefined));
92
+ const merged = { ...this.policy, ...entry };
93
+ if (entry.maxTokens === undefined && entry.headroomTokens !== undefined && source.maxTokens === undefined)
94
+ merged.maxTokens = entry.headroomTokens;
95
+ return { ...resolvePolicy(merged), provider: entry.provider, model: entry.model };
96
+ });
97
+ if (source.auto ?? true)
98
+ this.registerAutomaticCompaction();
99
+ }
100
+ policyFor(target) {
101
+ return (target && this.overrides.find(policy => policy.provider === target.provider && policy.model === target.model)) || this.policy;
102
+ }
103
+ registerAutomaticCompaction() {
104
+ const { ctx } = this;
105
+ const log = (result, trigger) => ctx.logger.info(`compaction (${trigger}): replaced ${result.shadowedSeqs.length} surface nodes with one tool-free summary (~${result.shadowedTokenCount} tokens)`);
106
+ ctx.on('agent/pre-step', async ({ agent, signal }, next) => {
107
+ if (!signal.aborted)
108
+ try {
109
+ const result = await this.compactIfNeeded(agent, 'pressure', signal);
110
+ if (result)
111
+ log(result, 'step pressure');
112
+ }
113
+ catch (error) {
114
+ if (error instanceof TargetConfigError) {
115
+ if (this.warnedTargets.has(error.targetKey))
116
+ return next();
117
+ this.warnedTargets.add(error.targetKey);
118
+ }
119
+ ctx.logger.warn(`step compaction failed: ${error instanceof Error ? error.message : String(error)}; continuing the turn`);
120
+ }
121
+ return next();
122
+ });
123
+ ctx.on('agent/status', ({ agent, status }) => { if (status === 'idle')
124
+ this.overflowRetries.delete(agent); });
125
+ ctx.on('session/event', (session, event) => {
126
+ if (event.type !== 'assistant/message')
127
+ return;
128
+ const agent = this.overflowAgents.get(session);
129
+ if (agent)
130
+ this.overflowRetries.delete(agent);
131
+ });
132
+ ctx.on('agent/request-error', async ({ agent, failure, signal }, next) => {
133
+ if (failure.code !== CONTEXT_WINDOW_EXCEEDED_CODE || signal.aborted)
134
+ return next();
135
+ this.overflowAgents.set(agent.session, agent);
136
+ const target = routedTarget(agent.session);
137
+ if (!target)
138
+ return next();
139
+ const retries = this.overflowRetries.get(agent) ?? 0;
140
+ if (retries >= this.policyFor(target).maxOverflowRetries)
141
+ return next();
142
+ const generation = agent.session.surface.replaceGeneration;
143
+ let result;
144
+ try {
145
+ result = await this.compactIfNeeded(agent, 'context-overflow', signal);
146
+ }
147
+ catch (error) {
148
+ const message = error instanceof Error ? error.message : String(error);
149
+ if (!signal.aborted && agent.session.surface.replaceGeneration > generation) {
150
+ ctx.logger.warn(`context-overflow compaction failed after durable surface progress: ${message}; retrying from the replacement surface`);
151
+ this.overflowRetries.set(agent, retries + 1);
152
+ return { kind: 'retry' };
153
+ }
154
+ ctx.logger.warn(`context-overflow compaction failed: ${message}; ${signal.aborted ? 'cancellation prevents retry' : 'preserving the original request error'}`);
155
+ return next();
156
+ }
157
+ if (signal.aborted || agent.session.surface.replaceGeneration <= generation)
158
+ return next();
159
+ if (result)
160
+ log(result, 'context overflow recovery');
161
+ this.overflowRetries.set(agent, retries + 1);
162
+ return { kind: 'retry' };
163
+ });
164
+ }
165
+ async compactIfNeeded(agent, trigger, signal) {
166
+ const target = routedTarget(agent.session);
167
+ if (!target)
168
+ return null;
169
+ const meter = this.ctx.tokenMeter;
170
+ if (trigger === 'context-overflow') {
171
+ const range = selectWholeRange(agent.session, meter.measure(agent.session));
172
+ return range && this.compactRegion(range.start, range.end, agent, signal);
173
+ }
174
+ const policy = this.policyFor(target);
175
+ const info = await this.ctx.llm.resolveModelInfo(target.provider, target.model, signal);
176
+ assertNoActiveCompaction(agent.session, 'automatic pressure compaction');
177
+ const key = `${target.provider}/${target.model}`;
178
+ if (!info.context)
179
+ throw new TargetConfigError(key, `dsh-world/compaction: no context capacity for ${key}; configure contextWindow on that adapter model`);
180
+ const { contextWindow } = info.context;
181
+ const reserved = agent.session.requestHeader()?.config.maxTokens ?? info.defaultMaxTokens ?? 0;
182
+ const pressureBudget = contextWindow - reserved - policy.headroomTokens;
183
+ if (pressureBudget <= 0)
184
+ throw new TargetConfigError(key, `dsh-world/compaction: ${key} reserves ${reserved} completion and ${policy.headroomTokens} headroom tokens of its ${contextWindow}-token window, leaving no pressure budget`);
185
+ const threshold = Math.floor(Math.min(contextWindow * policy.thresholdRatio, pressureBudget));
186
+ if (meter.measure(agent.session).totalTokens < threshold)
187
+ return null;
188
+ const range = selectWholeRange(agent.session, meter.measure(agent.session));
189
+ if (!range)
190
+ return null;
191
+ const result = await this.compactRegion(range.start, range.end, agent, signal);
192
+ const after = meter.measure(agent.session).totalTokens;
193
+ if (after >= threshold)
194
+ throw new Error(`compaction still above threshold after summarizing the whole conversation (${after} estimated tokens >= threshold ${threshold})`);
195
+ return result;
196
+ }
197
+ compactRegion(start, end, agent, signal) {
198
+ return compactSurfaceRegion(this.dependencies(), agent, start, end, { owner: 'current-turn', stability: 'whole-surface' }, signal);
199
+ }
200
+ compactNow(agent, signal, sourceCommandId) {
201
+ signal.throwIfAborted();
202
+ try {
203
+ return agent.runMaintenance(async (agentSignal) => {
204
+ const operationSignal = AbortSignal.any([agentSignal, signal]);
205
+ try {
206
+ operationSignal.throwIfAborted();
207
+ const range = selectWholeRange(agent.session, this.ctx.tokenMeter.measure(agent.session));
208
+ if (!range)
209
+ return null;
210
+ return await compactSurfaceRegion(this.dependencies(), agent, range.start, range.end, {
211
+ owner: null, stability: 'selected-span', ...(sourceCommandId === undefined ? {} : { sourceCommandId }),
212
+ flush: async () => { await this.ctx.sessions.flush(agent.session); },
213
+ }, operationSignal);
214
+ }
215
+ catch (error) {
216
+ if (agentSignal.aborted && operationSignal.reason === agentSignal.reason)
217
+ throw new ManualCompactionError('cancelled', 'manual compaction was cancelled', { cause: error });
218
+ operationSignal.throwIfAborted();
219
+ throw error;
220
+ }
221
+ });
222
+ }
223
+ catch (error) {
224
+ throw new ManualCompactionError('busy', 'manual compaction requires an idle agent with no waking queued work', { cause: error });
225
+ }
226
+ }
227
+ dependencies() {
228
+ return {
229
+ meter: this.ctx.tokenMeter,
230
+ summarize: (messages, agent, signal) => this.summarize(messages, agent, signal),
231
+ frame: summary => [{ type: 'text', text: `${checkpointLead}${summary.map(block => block.type === 'text' ? block.text : '').join('')}` }],
232
+ recover: (error, agent, sourceEventSeqs, signal) => this.ctx.waterfall('compaction/summary-error', { session: agent.session, sourceEventSeqs, error, ...(signal === undefined ? {} : { signal }) }, () => false),
233
+ };
234
+ }
235
+ async summarize(messages, agent, signal) {
236
+ signal?.throwIfAborted();
237
+ const routed = routedTarget(agent.session) ?? (agent.options.provider && agent.options.model ? { provider: agent.options.provider, model: agent.options.model } : undefined);
238
+ const policy = this.policyFor(routed);
239
+ const provider = policy.summarizationProvider || routed?.provider;
240
+ const model = policy.summarizationModel || routed?.model;
241
+ const { maxTokens } = policy;
242
+ if (!provider || !model)
243
+ throw new Error('dsh-world: no provider/model configured for compaction');
244
+ const replayed = toolFreeMessages(messages);
245
+ if (!hasConversation(replayed))
246
+ throw new Error('dsh-world: no visible conversation remains to summarize');
247
+ const { session } = agent;
248
+ const head = session.surface.nodes[0] === undefined ? undefined : session.eventAt(session.surface.nodes[0]);
249
+ const system = head?.type === 'system/message' ? session.deriveEventMessage(head) : null;
250
+ const header = session.requestHeader();
251
+ const timeContext = formatTimeContext(new Date(), this.timeZone);
252
+ appendPluginRecord(session, 'plugin:dsh-world/compaction-request', { policyVersion: 2, provider, model, maxTokens, instruction: summaryInstruction, timeContext, replayedMessageIds: replayed.map(message => message.id) });
253
+ await this.ctx.sessions.flush(session);
254
+ const request = [
255
+ ...(system ? [system] : []), ...replayed,
256
+ createUserMessage({ source: { kind: 'dsh-world-summary-input' }, content: [{ type: 'text', text: `${summaryInstruction}\n\n${timeContext}` }] }),
257
+ ];
258
+ const assembler = new BlockAssembler();
259
+ for await (const chunk of this.ctx.llm.stream({ provider, model, maxTokens, messages: request, ...(header?.tools === undefined ? {} : { tools: [...header.tools] }), toolHistory: session.toolHistory(), sessionId: session.id, purpose: 'compaction', ...(signal === undefined ? {} : { signal }) }))
260
+ assembler.push(chunk);
261
+ signal?.throwIfAborted();
262
+ const finish = assembler.finish;
263
+ if (finish.kind === 'error' || finish.kind === 'aborted')
264
+ throw new LlmError(finish.failure.message, finish.failure.code, finish.failure);
265
+ if (finish.kind !== 'stop')
266
+ throw new Error(`dsh-world: compaction summary truncated or invalid (${finish.kind})`);
267
+ const rawOutput = assembler.blocks();
268
+ const text = rawOutput.flatMap(block => block.type === 'text' ? [block.text.trim()] : []).join(' ').replace(/\s*\r?\n\s*/g, ' ').trim().replace(leadEcho, '').trim();
269
+ if (!text)
270
+ throw new Error('dsh-world: summarizer returned no paragraph');
271
+ return { summary: [{ type: 'text', text }], rawOutput, provider, model, maxTokens, ...(assembler.usage ? { usage: assembler.usage } : {}) };
272
+ }
273
+ }
@@ -0,0 +1,42 @@
1
+ import { type CompactionResult } from '@deepseek-ai/dsh-compaction';
2
+ import type { CommandId } from '@deepseek-ai/dsh-commands/brand';
3
+ import { type ContentBlock, type Message, type TokenUsage } from '@deepseek-ai/dsh-llm';
4
+ import { SessionSeq, type Session } from '@deepseek-ai/dsh-session';
5
+ import type { TokenMeasurement } from '@deepseek-ai/dsh-token-meter';
6
+ export interface SummaryResult {
7
+ summary: ContentBlock[];
8
+ rawOutput: ContentBlock[];
9
+ provider: string;
10
+ model: string;
11
+ maxTokens: number;
12
+ usage?: TokenUsage;
13
+ }
14
+ export interface RegionAgent {
15
+ session: Session;
16
+ options: {
17
+ provider?: string;
18
+ model?: string;
19
+ };
20
+ }
21
+ export interface RegionDependencies {
22
+ meter: {
23
+ measure(session: Session): TokenMeasurement;
24
+ estimateMessage(message: Message): number;
25
+ };
26
+ summarize(messages: Message[], agent: RegionAgent, signal?: AbortSignal): Promise<SummaryResult>;
27
+ frame(summary: ContentBlock[]): ContentBlock[];
28
+ recover(error: unknown, agent: RegionAgent, seqs: readonly SessionSeq[], signal?: AbortSignal): boolean;
29
+ }
30
+ export interface RegionOptions {
31
+ owner: 'current-turn' | null;
32
+ stability: 'whole-surface' | 'selected-span';
33
+ sourceCommandId?: CommandId;
34
+ flush?: () => Promise<void>;
35
+ }
36
+ /** Everything after the system head through the newest cut that splits no tool call from its result. */
37
+ export declare function selectWholeRange(session: Session, measurement: TokenMeasurement): {
38
+ start: SessionSeq;
39
+ end: SessionSeq;
40
+ } | null;
41
+ export declare function compactSurfaceRegion(deps: RegionDependencies, agent: RegionAgent, start: SessionSeq, end: SessionSeq, options: RegionOptions, signal?: AbortSignal): Promise<CompactionResult>;
42
+ export declare function assertNoActiveCompaction(session: Session, stage: string): void;