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,30 @@
1
+ const FLASH = { hit: [0.02, 0.04], miss: [1, 2], out: [4, 8] };
2
+ const PRO = { hit: [0.15, 0.3], miss: [4.5, 9], out: [13.5, 27] };
3
+ /** Matched as substrings of the model id; anything else is priced as Flash. */
4
+ const PRICES = [['deepseek-v4-pro', PRO], ['deepseek-flash', FLASH], ['deepseek-v4-flash', FLASH]];
5
+ /** Beijing weekday hours priced as peak; weekends and the statutory holidays below are off-peak all day. */
6
+ const PEAK_HOURS = [[9, 12], [14, 18]];
7
+ /** Days off by the State Council's 2026 schedule; the working weekends are off-peak as weekends anyway. Add each new year's. */
8
+ const HOLIDAYS = new Set([
9
+ '2026-01-01', '2026-01-02', '2026-01-03',
10
+ '2026-02-15', '2026-02-16', '2026-02-17', '2026-02-18', '2026-02-19', '2026-02-20', '2026-02-21', '2026-02-22', '2026-02-23',
11
+ '2026-04-04', '2026-04-05', '2026-04-06',
12
+ '2026-05-01', '2026-05-02', '2026-05-03', '2026-05-04', '2026-05-05',
13
+ '2026-06-19', '2026-06-20', '2026-06-21',
14
+ '2026-09-25', '2026-09-26', '2026-09-27',
15
+ '2026-10-01', '2026-10-02', '2026-10-03', '2026-10-04', '2026-10-05', '2026-10-06', '2026-10-07',
16
+ ]);
17
+ export function isPeak(at) {
18
+ const beijing = new Date(at.getTime() + 8 * 3_600_000);
19
+ const day = beijing.getUTCDay();
20
+ if (day === 0 || day === 6 || HOLIDAYS.has(beijing.toISOString().slice(0, 10)))
21
+ return false;
22
+ const hour = beijing.getUTCHours();
23
+ return PEAK_HOURS.some(([from, to]) => hour >= from && hour < to);
24
+ }
25
+ /** What one model step cost in CNY. DeepSeek reports cache hits apart from the other input; reasoning is part of the output. */
26
+ export function stepCost(usage, model, at) {
27
+ const price = PRICES.find(([id]) => model.toLowerCase().includes(id))?.[1] ?? FLASH;
28
+ const peak = isPeak(at) ? 1 : 0;
29
+ return ((usage.cacheReadTokens ?? 0) * price.hit[peak] + usage.inputTokens * price.miss[peak] + usage.outputTokens * price.out[peak]) / 1e6;
30
+ }
@@ -0,0 +1,52 @@
1
+ import type { Context } from '@deepseek-ai/cordis';
2
+ import type { Agent } from '@deepseek-ai/dsh-agent';
3
+ import '../hostContract.ts';
4
+ import type { WorldConfig } from '../types.ts';
5
+ import { type LifeTimers } from './alarmTimer.ts';
6
+ import type { LifeHost } from './host.ts';
7
+ import type { LifeStore } from './lifeStore.ts';
8
+ import type { Notifier } from './notify.ts';
9
+ import type { Alarm, LifeOptions, Review } from './types.ts';
10
+ export interface LifeDeps {
11
+ ctx: Context;
12
+ config: WorldConfig;
13
+ options: LifeOptions;
14
+ store: LifeStore;
15
+ host: LifeHost;
16
+ notifier: Notifier;
17
+ clock?: () => Date;
18
+ timers?: LifeTimers;
19
+ /** CNY her home may spend a day; undefined or absent is no limit. */
20
+ dailyBudget?: () => number | undefined;
21
+ }
22
+ /**
23
+ * Her life line: one pending alarm, kept in life.json and delivered into her home with `agent.steer`, the
24
+ * tools she sets it with, the home itself, a new home's greeting and the evening look back. The parts live in
25
+ * their own modules; this wires them.
26
+ */
27
+ export declare function createLifeRuntime(deps: LifeDeps): {
28
+ start: (options?: {
29
+ resumed?: boolean;
30
+ }) => Promise<void>;
31
+ stop: () => void;
32
+ planNext: (input: {
33
+ at?: string;
34
+ after_minutes?: number;
35
+ }, note: string) => string;
36
+ checkAlarm: () => string;
37
+ cancelAlarm: () => string;
38
+ deliver: () => Promise<void>;
39
+ snapshot: () => {
40
+ homeSessionId: string | undefined;
41
+ alarm: Alarm | undefined;
42
+ review: Review | undefined;
43
+ spend: import("./types.ts").Spend | undefined;
44
+ faults: string[];
45
+ };
46
+ /** Resolves once no alarm delivery is in flight (its durability flush can outlast the turn it starts). */
47
+ settled: () => Promise<void>;
48
+ home: () => Promise<Agent>;
49
+ /** Whether this session is her home now; the world prompt gives the home its world line. */
50
+ isHome: (sessionId: string) => boolean;
51
+ };
52
+ export type LifeRuntime = ReturnType<typeof createLifeRuntime>;
@@ -0,0 +1,376 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { createUserMessage } from '@deepseek-ai/dsh-llm';
4
+ import "../hostContract.js";
5
+ import { errorText, Faults } from "../faults.js";
6
+ import { keepSelfCopy } from "../self.js";
7
+ import { formatLocalTime } from "../timeContext.js";
8
+ import { belongsToWorld } from "../sourceArchive.js";
9
+ import { homeTitle, roomTitle, worldNames } from "../worldPrompt.js";
10
+ import { budgetText, cancelReply, greetingText, checkReply, earlyStopText, nextLocalTime, nextReview, planReply, resolveAlarmTime, reviewText, wakeText } from "./alarm.js";
11
+ import { summarizeSince } from "./activity.js";
12
+ import { createAlarmTimer, realTimers } from "./alarmTimer.js";
13
+ import { createEarlyStopWatch } from "./earlyStop.js";
14
+ import { createHome } from "./home.js";
15
+ import { createJournal } from "./journal.js";
16
+ import { stepCost } from "./pricing.js";
17
+ import { exampleTime, readAlarmMessages } from "./messages.js";
18
+ import { createToolRegistry } from "./toolRegistry.js";
19
+ import { alarmDescriptions, lifeTools } from "./tools.js";
20
+ const withValue = (key, value) => (value === undefined ? {} : { [key]: value });
21
+ /**
22
+ * Her life line: one pending alarm, kept in life.json and delivered into her home with `agent.steer`, the
23
+ * tools she sets it with, the home itself, a new home's greeting and the evening look back. The parts live in
24
+ * their own modules; this wires them.
25
+ */
26
+ export function createLifeRuntime(deps) {
27
+ const { ctx, config, options, store, host } = deps;
28
+ const { timeZone } = options;
29
+ const names = worldNames(config);
30
+ const clock = deps.clock ?? (() => new Date());
31
+ const faults = new Faults();
32
+ const disposers = [];
33
+ const state = store.read();
34
+ let stopped = false;
35
+ let delivery;
36
+ /** Bookkeeping after the fact: a failure is a fault, never a broken turn. */
37
+ function record(work) {
38
+ try {
39
+ work();
40
+ faults.clear('state');
41
+ }
42
+ catch (error) {
43
+ faults.set('state', `生活状态没能保存:${errorText(error)}`);
44
+ ctx.logger.error(error);
45
+ }
46
+ }
47
+ /** Her alarm wording, read when it is used; an unreadable template is a fault and the shipped one is used. */
48
+ function alarmMessages() {
49
+ const messages = readAlarmMessages(options.alarmFile);
50
+ if (messages.error)
51
+ faults.set('alarm-template', messages.error);
52
+ else
53
+ faults.clear('alarm-template');
54
+ return messages;
55
+ }
56
+ const templateValues = () => ({ name: names.companion, partner: names.partner, homeTitle: homeTitle(names), timeZone, fallbackWakeTime: options.fallbackWakeTime, example: exampleTime(timeZone) });
57
+ /**
58
+ * What she actually did between setting this alarm and hearing it, in one line.
59
+ *
60
+ * Read from the activity log rather than from her own account of the time, so the alarm can contradict
61
+ * her note: "歇着" plus forty tool calls is a different sentence from "歇着" plus none. Both days the
62
+ * alarm could straddle are read, because a plan set at 23:50 and heard at 00:30 has its work split.
63
+ */
64
+ const didSince = (alarm, now) => {
65
+ const dayOf = (at) => formatLocalTime(new Date(at), timeZone).slice(0, 10);
66
+ const days = [...new Set([dayOf(alarm.setAt), dayOf(now)])];
67
+ const records = days.flatMap(each => store.activity(each)).sort((a, b) => Date.parse(a.time) - Date.parse(b.time));
68
+ return summarizeSince(records, alarm.setAt, now);
69
+ };
70
+ const say = (agent, text) => {
71
+ agent.steer(createUserMessage({ source: { kind: 'dsh-world-life' }, content: [{ type: 'text', text }] }));
72
+ return ctx.sessions.flush(agent.session);
73
+ };
74
+ function nextJob() {
75
+ const { greeting, review, alarm } = state;
76
+ if (greeting)
77
+ return { kind: 'greeting', at: greeting.at, greeting };
78
+ if (review && (!alarm || Date.parse(review.at) <= Date.parse(alarm.at)))
79
+ return { kind: 'review', at: review.at, review };
80
+ return alarm && { kind: 'alarm', at: alarm.at, alarm };
81
+ }
82
+ const timer = createAlarmTimer({ clock, timers: deps.timers ?? realTimers, dueAlarm: () => nextJob()?.at, fire: () => void deliver() });
83
+ const morning = (now) => ({ at: nextLocalTime(now, options.fallbackWakeTime, timeZone).toISOString(), note: '', setAt: now.toISOString(), source: 'fallback' });
84
+ /** A new alarm replaces a failing one, so its backoff and fault go with it. Saved or not, it is armed. */
85
+ function setAlarm(alarm) {
86
+ if (stopped)
87
+ return;
88
+ state.alarm = alarm;
89
+ faults.clear('delivery', 'alarm');
90
+ try {
91
+ store.write(state);
92
+ }
93
+ catch (error) {
94
+ faults.set('alarm', `闹钟没能保存:${errorText(error)}`);
95
+ throw error;
96
+ }
97
+ finally {
98
+ timer.reset();
99
+ }
100
+ }
101
+ /** Nothing pending means resting until the next morning. Unsaved, it still rings while the app keeps running. */
102
+ function fallbackAlarm() {
103
+ if (state.alarm || state.greeting || stopped)
104
+ return;
105
+ try {
106
+ setAlarm(morning(clock()));
107
+ }
108
+ catch (error) {
109
+ faults.set('alarm', `断线保护闹钟没能保存:${errorText(error)}`);
110
+ ctx.logger.error(error);
111
+ }
112
+ }
113
+ function planNext(input, note) {
114
+ if (stopped)
115
+ throw new Error('生活线已停止');
116
+ const now = clock();
117
+ const at = resolveAlarmTime(input, now, timeZone);
118
+ const replaced = state.alarm;
119
+ setAlarm({ at: at.toISOString(), note: note.trim(), setAt: now.toISOString(), source: 'plan' });
120
+ return planReply(at, replaced, timeZone);
121
+ }
122
+ const checkAlarm = () => checkReply(state.alarm, clock(), timeZone);
123
+ /** Back to the morning fallback, exactly as if she had set nothing. */
124
+ function cancelAlarm() {
125
+ if (stopped)
126
+ throw new Error('生活线已停止');
127
+ const cancelled = state.alarm;
128
+ if (cancelled?.source === 'plan')
129
+ setAlarm(morning(clock()));
130
+ else
131
+ fallbackAlarm();
132
+ return cancelReply(cancelled, state.alarm, timeZone);
133
+ }
134
+ // Delivery: one at a time; a failure backs off, and a newer alarm keeps its own time.
135
+ function deliver() {
136
+ const job = nextJob();
137
+ if (stopped || !job)
138
+ return delivery ?? Promise.resolve();
139
+ return delivery ??= (job.kind === 'alarm' ? send(job.alarm) : job.kind === 'review' ? lookBack(job.review) : greet(job.greeting)).finally(() => { delivery = undefined; });
140
+ }
141
+ const wake = (source, scheduledAt, now) => ({ scheduledAt, deliveredAt: now.toISOString(), source, lateMs: Math.max(0, now.getTime() - Date.parse(scheduledAt)) });
142
+ /**
143
+ * A message of the plugin's own, taken off the schedule while it is sent and put back if it fails: it backs
144
+ * off like an alarm, and its turn is never asked about as an early stop.
145
+ */
146
+ async function sayOwn(what, source, scheduledAt, take, putBack, text) {
147
+ let now = clock();
148
+ try {
149
+ const agent = await home.open();
150
+ if (stopped)
151
+ return;
152
+ take();
153
+ now = clock();
154
+ earlyStop.startsOwnTurn();
155
+ await say(agent, text(now));
156
+ }
157
+ catch (error) {
158
+ ctx.logger.error(error);
159
+ if (stopped)
160
+ return;
161
+ earlyStop.ownTurnFailed();
162
+ putBack();
163
+ faults.set('delivery', `${what}没送到,${timer.failed()} 分钟后重试:${errorText(error)}`);
164
+ return;
165
+ }
166
+ if (stopped)
167
+ return;
168
+ faults.clear('delivery', 'home');
169
+ record(() => { store.write(state); store.appendWake(wake(source, scheduledAt, now)); });
170
+ timer.reset();
171
+ }
172
+ /**
173
+ * A new home's first words, so it has a turn (the host lists no session without one) and she knows she moved;
174
+ * or the word that her world has started again.
175
+ */
176
+ const greet = (greeting) => sayOwn(greeting.kind === 'arrival' ? '新家的第一句话' : '重新开始的那句话', greeting.kind === 'arrival' ? 'first' : 'return', greeting.at, () => { delete state.greeting; }, () => { state.greeting ??= greeting; }, () => greetingText(greeting.kind, timeZone, options.fallbackWakeTime, alarmMessages(), templateValues()));
177
+ /** The evening look back on her day; her 我是谁 is kept as it was, so she can rewrite it freely. */
178
+ function lookBack(review) {
179
+ let snapshot;
180
+ const take = () => {
181
+ try {
182
+ snapshot = keepSelfCopy(options.selfFile, review.day);
183
+ faults.clear('snapshot');
184
+ }
185
+ catch (error) {
186
+ faults.set('snapshot', `我是谁没能留底:${errorText(error)}`);
187
+ ctx.logger.error(error);
188
+ }
189
+ state.review = nextReview(clock(), timeZone);
190
+ };
191
+ const existing = (dir) => { const file = join(options.worldDir, dir, `${review.day}.jsonl`); return existsSync(file) ? file : undefined; };
192
+ return sayOwn('每日回顾', 'review', review.at, take, () => { state.review = review; }, now => reviewText(review, now, {
193
+ ...withValue('conversations', existing('conversations')), ...withValue('activity', existing('activity')), ...withValue('snapshot', snapshot),
194
+ diaryDir: options.diaryDir, selfFile: options.selfFile,
195
+ }, timeZone, options.fallbackWakeTime, alarmMessages(), templateValues()));
196
+ }
197
+ async function send(alarm) {
198
+ let now = clock();
199
+ try {
200
+ // Resolve (or rebuild) the home first: a rebuilt home must still see this alarm as pending.
201
+ const agent = await home.open();
202
+ if (stopped)
203
+ return;
204
+ if (state.alarm !== alarm) {
205
+ timer.arm();
206
+ return;
207
+ }
208
+ // Cleared before steering, so a turn that ends quickly already sees "no alarm" and gets the fallback.
209
+ delete state.alarm;
210
+ now = clock();
211
+ await say(agent, wakeText(alarm, now, timeZone, options.fallbackWakeTime, alarmMessages(), { ...templateValues(), did: alarm.source === 'fallback' ? '' : didSince(alarm, now) }));
212
+ }
213
+ catch (error) {
214
+ ctx.logger.error(error);
215
+ if (stopped)
216
+ return;
217
+ if (state.alarm && state.alarm !== alarm) {
218
+ faults.set('delivery', `闹钟送达失败:${errorText(error)}`);
219
+ timer.arm();
220
+ return;
221
+ }
222
+ state.alarm = alarm;
223
+ faults.set('delivery', `闹钟送达失败,${timer.failed()} 分钟后重试:${errorText(error)}`);
224
+ return;
225
+ }
226
+ if (stopped)
227
+ return;
228
+ // Steered and durable: the alarm is delivered. Recording it may fail, but it is never sent again.
229
+ faults.clear('delivery', 'home');
230
+ record(() => {
231
+ store.write(state);
232
+ store.appendWake({ scheduledAt: alarm.at, deliveredAt: now.toISOString(), source: alarm.source, lateMs: Math.max(0, now.getTime() - Date.parse(alarm.at)) });
233
+ });
234
+ timer.reset();
235
+ }
236
+ // Stopping early: asked once per alarm whether she is done.
237
+ const earlyStop = createEarlyStopWatch();
238
+ function askIfDoneEarly(completed) {
239
+ const now = clock();
240
+ const alarm = state.alarm;
241
+ if (!earlyStop.turnEnded(completed, alarm, now) || stopped)
242
+ return;
243
+ alarm.nudged = true;
244
+ record(() => store.write(state));
245
+ earlyStop.startsOwnTurn();
246
+ const text = earlyStopText(alarm, now, timeZone, alarmMessages(), templateValues());
247
+ void home.open().then(agent => stopped ? undefined : say(agent, text)).catch(error => { earlyStop.ownTurnFailed(); ctx.logger.error(error); });
248
+ }
249
+ // What her home spends: each model step priced as it lands; past the daily budget she is told once that day.
250
+ function spent(usage, model) {
251
+ const now = clock();
252
+ const day = formatLocalTime(now, timeZone).slice(0, 10);
253
+ const spend = state.spend?.day === day ? state.spend : (state.spend = { day, yuan: 0 });
254
+ spend.yuan += stepCost(usage, model, now);
255
+ const budget = deps.dailyBudget?.();
256
+ const remind = budget !== undefined && spend.yuan >= budget && !spend.reminded;
257
+ if (remind)
258
+ spend.reminded = true;
259
+ record(() => store.write(state));
260
+ if (!remind)
261
+ return;
262
+ const text = budgetText(spend.yuan, budget, alarmMessages(), templateValues());
263
+ void home.open().then(agent => {
264
+ if (stopped)
265
+ return;
266
+ // Into the running turn at its next step, or a turn of its own that is not asked about.
267
+ if (agent.status !== 'running')
268
+ earlyStop.startsOwnTurn();
269
+ return say(agent, text);
270
+ }).catch(error => { earlyStop.ownTurnFailed(); ctx.logger.error(error); });
271
+ }
272
+ // Her tools and her home.
273
+ const notifier = {
274
+ ...(deps.notifier.toast ? { toast: (title, body) => faults.track('toast', '系统通知没送到', () => deps.notifier.toast(title, body)) } : {}),
275
+ outlets: deps.notifier.outlets.map(outlet => ({ ...outlet, send: push => faults.track(`outlet:${outlet.name}`, `${outlet.name}没送到`, () => outlet.send(push)) })),
276
+ };
277
+ const tools = createToolRegistry({
278
+ faults, logger: ctx.logger,
279
+ isHome: agent => agent.id === state.homeSessionId,
280
+ tools: () => lifeTools({ planNext, checkAlarm, cancelAlarm, notifier, names, origin: () => { try {
281
+ return host.origin();
282
+ }
283
+ catch {
284
+ return undefined;
285
+ } }, descriptions: alarmDescriptions(alarmMessages(), templateValues()) }),
286
+ });
287
+ const attach = (agent) => { if (!stopped && belongsToWorld(agent.session, config))
288
+ tools.attach(agent); };
289
+ const home = createHome({
290
+ host, roomDir: options.roomDir, agentPreset: config.agentPreset, title: homeTitle(names), roomTitle: roomTitle(names), faults, logger: ctx.logger,
291
+ current: () => state.homeSessionId,
292
+ // A new home greets her at once (the pending alarm moves in too and rings at its own time).
293
+ moveIn(sessionId) {
294
+ state.homeSessionId = sessionId;
295
+ state.greeting = { at: clock().toISOString(), kind: 'arrival' };
296
+ tools.releaseOldHomes();
297
+ store.write(state);
298
+ },
299
+ opened: attach,
300
+ stopped: () => stopped,
301
+ });
302
+ const journal = createJournal({ store, faults, roomDir: options.roomDir, logger: ctx.logger });
303
+ /** `resumed`: started again from the console; unless an alarm of her own is pending, she is told she is back. */
304
+ async function start(options = {}) {
305
+ disposers.push(ctx.on('agent/created', ({ agent }) => { attach(agent); return undefined; }), ctx.on('agent/disposed', ({ agent }) => tools.forget(agent)), ctx.on('agent/inbox/inserted', ({ agent, message: inserted }) => {
306
+ // Her partner's words reach her at the next step, like being called while busy.
307
+ if (agent.id !== state.homeSessionId || inserted.source.kind !== 'user' || agent.status !== 'running')
308
+ return;
309
+ if (!agent.inbox.nextTurn.some(queued => queued.id === inserted.id))
310
+ return;
311
+ agent.inbox.remove(inserted.id);
312
+ agent.steer(inserted);
313
+ }), ctx.on('session/event', (session, event) => {
314
+ if (!belongsToWorld(session, config))
315
+ return;
316
+ journal.world(session, event);
317
+ if (session.id !== state.homeSessionId)
318
+ return;
319
+ journal.home(session, event);
320
+ if (event.type === 'assistant/message' && event.data.usage)
321
+ spent(event.data.usage, event.data.message.source.model);
322
+ if (event.type === 'user/message' && event.data.source.kind === 'user')
323
+ earlyStop.partnerSpoke();
324
+ if (event.type !== 'turn/end')
325
+ return;
326
+ home.turnEnded(session.id);
327
+ fallbackAlarm();
328
+ // A stopped or failed turn is not her deciding she is done.
329
+ askIfDoneEarly(event.data.reason.kind === 'completed');
330
+ }));
331
+ for (const agent of ctx.agents.list())
332
+ attach(agent);
333
+ if (!state.review) {
334
+ state.review = nextReview(clock(), timeZone);
335
+ record(() => store.write(state));
336
+ }
337
+ try {
338
+ const agent = await home.open();
339
+ faults.clear('home');
340
+ // The morning fallback is the plugin's, not a plan of hers: starting again wakes her rather than leaving her asleep till then.
341
+ if (options.resumed && !state.greeting && state.alarm?.source !== 'plan') {
342
+ state.greeting = { at: clock().toISOString(), kind: 'return' };
343
+ record(() => store.write(state));
344
+ }
345
+ // A restart with nothing scheduled and no turn to end would otherwise never wake her again.
346
+ if (agent.status !== 'running')
347
+ fallbackAlarm();
348
+ }
349
+ catch (error) {
350
+ if (!stopped) {
351
+ faults.set('home', `家打不开:${errorText(error)}`);
352
+ ctx.logger.error(error);
353
+ }
354
+ }
355
+ timer.arm();
356
+ }
357
+ function stop() {
358
+ if (stopped)
359
+ return;
360
+ stopped = true;
361
+ timer.stop();
362
+ for (const dispose of disposers.splice(0).reverse())
363
+ dispose();
364
+ tools.clear();
365
+ }
366
+ return {
367
+ start, stop, planNext, checkAlarm, cancelAlarm, deliver,
368
+ snapshot: () => ({ homeSessionId: state.homeSessionId, alarm: state.alarm, review: state.review, spend: state.spend, faults: faults.list() }),
369
+ /** Resolves once no alarm delivery is in flight (its durability flush can outlast the turn it starts). */
370
+ settled: async () => { while (delivery)
371
+ await delivery; },
372
+ home: () => home.open(),
373
+ /** Whether this session is her home now; the world prompt gives the home its world line. */
374
+ isHome: (sessionId) => !stopped && sessionId === state.homeSessionId,
375
+ };
376
+ }
@@ -0,0 +1,22 @@
1
+ import type { Agent } from '@deepseek-ai/dsh-agent';
2
+ import { type Faults } from '../faults.ts';
3
+ import type { lifeTools } from './tools.ts';
4
+ /**
5
+ * The alarm tools are held by every world session (she can set her alarm anywhere; it rings at home);
6
+ * reach_out only by the current home. A registration that fails (a name clash) is a fault and never breaks
7
+ * agent creation; it registers all of a group or none.
8
+ */
9
+ export declare function createToolRegistry(deps: {
10
+ faults: Faults;
11
+ logger: {
12
+ error(...args: unknown[]): void;
13
+ };
14
+ tools: () => ReturnType<typeof lifeTools>;
15
+ isHome(agent: Agent): boolean;
16
+ }): {
17
+ attach(agent: Agent): void;
18
+ forget(agent: Agent): void;
19
+ /** A rebuilt home takes reach_out from the old one. */
20
+ releaseOldHomes(): void;
21
+ clear(): void;
22
+ };
@@ -0,0 +1,64 @@
1
+ import { errorText } from "../faults.js";
2
+ const ALARM_TOOLS = ['plan_next', 'check_alarm', 'cancel_alarm'];
3
+ const HOME_TOOLS = ['reach_out'];
4
+ /** Disposes in reverse; a disposer whose agent scope is already gone may throw and is skipped. */
5
+ function undo(list) {
6
+ for (const dispose of list.splice(0).reverse()) {
7
+ try {
8
+ dispose();
9
+ }
10
+ catch { /* scope already disposed */ }
11
+ }
12
+ }
13
+ /**
14
+ * The alarm tools are held by every world session (she can set her alarm anywhere; it rings at home);
15
+ * reach_out only by the current home. A registration that fails (a name clash) is a fault and never breaks
16
+ * agent creation; it registers all of a group or none.
17
+ */
18
+ export function createToolRegistry(deps) {
19
+ const alarm = new Map();
20
+ const home = new Map();
21
+ function register(agent, tools, names) {
22
+ const done = [];
23
+ try {
24
+ for (const tool of tools)
25
+ if (names.includes(tool.name))
26
+ done.push(agent.ctx.tools.register(tool));
27
+ }
28
+ catch (error) {
29
+ undo(done);
30
+ throw error;
31
+ }
32
+ return done;
33
+ }
34
+ return {
35
+ attach(agent) {
36
+ const needsAlarm = !alarm.get(agent)?.length, needsHome = deps.isHome(agent) && !home.get(agent)?.length;
37
+ if (!needsAlarm && !needsHome)
38
+ return;
39
+ try {
40
+ const tools = deps.tools();
41
+ if (needsAlarm)
42
+ alarm.set(agent, register(agent, tools, ALARM_TOOLS));
43
+ if (needsHome)
44
+ home.set(agent, register(agent, tools, HOME_TOOLS));
45
+ deps.faults.clear(`attach:${agent.id}`);
46
+ }
47
+ catch (error) {
48
+ deps.faults.set(`attach:${agent.id}`, `工具挂载失败:${errorText(error)}`);
49
+ deps.logger.error(error);
50
+ }
51
+ },
52
+ forget(agent) { alarm.delete(agent); home.delete(agent); deps.faults.clear(`attach:${agent.id}`); },
53
+ /** A rebuilt home takes reach_out from the old one. */
54
+ releaseOldHomes() { for (const [agent, list] of home)
55
+ if (!deps.isHome(agent))
56
+ undo(list); },
57
+ clear() {
58
+ for (const list of [...home.values(), ...alarm.values()])
59
+ undo(list);
60
+ home.clear();
61
+ alarm.clear();
62
+ },
63
+ };
64
+ }
@@ -0,0 +1,24 @@
1
+ import type { Notifier } from './notify.ts';
2
+ import type { WorldNames } from '../worldPrompt.ts';
3
+ export interface AlarmDescriptions {
4
+ plan: string;
5
+ check: string;
6
+ cancel: string;
7
+ }
8
+ export interface LifeToolHost {
9
+ planNext(input: {
10
+ at?: string;
11
+ after_minutes?: number;
12
+ }, note: string): string;
13
+ /** With both, check_alarm and cancel_alarm are offered too. */
14
+ checkAlarm?(): string;
15
+ cancelAlarm?(): string;
16
+ notifier: Notifier;
17
+ names?: WorldNames;
18
+ /** The DSH origin, for sticker URLs in her words. */
19
+ origin?(): string | undefined;
20
+ /** From the alarm template; the shipped wording otherwise. */
21
+ descriptions?: AlarmDescriptions;
22
+ }
23
+ export declare function alarmDescriptions(messages?: import("./messages.ts").AlarmMessages, values?: Record<string, string>): AlarmDescriptions;
24
+ export declare function lifeTools(host: LifeToolHost): readonly [import("@deepseek-ai/dsh-tools").ToolDefinition, import("@deepseek-ai/dsh-tools").ToolDefinition] | readonly [import("@deepseek-ai/dsh-tools").ToolDefinition, import("@deepseek-ai/dsh-tools").ToolDefinition, import("@deepseek-ai/dsh-tools").ToolDefinition, import("@deepseek-ai/dsh-tools").ToolDefinition];
@@ -0,0 +1,47 @@
1
+ import { defineTool } from '@deepseek-ai/dsh-tools';
2
+ import { exampleTime, fillMessage, readAlarmMessages } from "./messages.js";
3
+ import { pushOf } from "../ecosystem/shared/outlets.js";
4
+ export function alarmDescriptions(messages = readAlarmMessages(undefined), values = { example: exampleTime('UTC'), fallbackWakeTime: '09:00' }) {
5
+ return { plan: fillMessage(messages, 'plan_next 说明', values), check: fillMessage(messages, 'check_alarm 说明', values), cancel: fillMessage(messages, 'cancel_alarm 说明', values) };
6
+ }
7
+ const text = { schema: { type: 'string' }, render: (_args, value) => [{ type: 'text', text: value }] };
8
+ export function lifeTools(host) {
9
+ const { companion, partner } = host.names ?? { companion: 'TA', partner: '伙伴' };
10
+ const descriptions = host.descriptions ?? alarmDescriptions();
11
+ const planNext = defineTool({
12
+ name: 'plan_next',
13
+ description: descriptions.plan,
14
+ parameters: { at: { type: 'string' }, after_minutes: { type: 'number' }, note: { type: 'string', required: true } },
15
+ output: text,
16
+ execute: async ({ at, after_minutes, note }) => host.planNext({ ...(at === undefined ? {} : { at }), ...(after_minutes === undefined ? {} : { after_minutes }) }, note),
17
+ });
18
+ const { toast, outlets } = host.notifier;
19
+ const reaching = outlets.filter(outlet => outlet.kinds.includes('reach'));
20
+ const channelNames = [...(toast ? ['系统通知'] : []), ...reaching.map(outlet => outlet.name)];
21
+ const reachOut = defineTool({
22
+ name: 'reach_out',
23
+ description: `想找${partner}时用:先在家里正常把话说出来,再用它把这句话送到${partner}面前(${channelNames.length ? channelNames.join(' + ') : '现在还没有配置任何通道'})。image 可选,是一个表情的名字,接收的一方认得才会显示。找${partner}时说一两句就好,细节留在家里,${partner}来了自己会看。`,
24
+ parameters: { text: { type: 'string', required: true }, image: { type: 'string' } },
25
+ output: text,
26
+ execute: async ({ text: message, image }) => {
27
+ if (!channelNames.length)
28
+ throw new Error('现在还没有配置任何通道,话留在家里了。');
29
+ const push = pushOf(message, 'reach', companion, host.origin?.(), image);
30
+ const channels = [
31
+ ...(toast ? [['系统通知', '已发出', toast.call(host.notifier, companion, message)]] : []),
32
+ ...reaching.map(outlet => [outlet.name, '已送到', outlet.send(push)]),
33
+ ];
34
+ const results = await Promise.allSettled(channels.map(([, , sent]) => sent));
35
+ const summary = `${results.map((result, index) => { const [name, done] = channels[index]; return result.status === 'fulfilled' ? `${name}${done}` : `${name}没送到:${result.reason instanceof Error ? result.reason.message : String(result.reason)}`; }).join(';')}。`;
36
+ if (results.every(result => result.status === 'rejected'))
37
+ throw new Error(summary);
38
+ return summary;
39
+ },
40
+ });
41
+ const { checkAlarm, cancelAlarm } = host;
42
+ if (!checkAlarm || !cancelAlarm)
43
+ return [planNext, reachOut];
44
+ const check = defineTool({ name: 'check_alarm', description: descriptions.check, parameters: {}, output: text, execute: async () => checkAlarm.call(host) });
45
+ const cancel = defineTool({ name: 'cancel_alarm', description: descriptions.cancel, parameters: {}, output: text, execute: async () => cancelAlarm.call(host) });
46
+ return [planNext, reachOut, check, cancel];
47
+ }