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,400 @@
1
+ /**
2
+ * plan.js — 纯算术层。零 IO、零依赖、可单测。
3
+ *
4
+ * 所有"该切几格、发几张、画布多大、够不够清晰"的判断都在这里,
5
+ * 媒体层(ffmpeg)只负责执行,不参与决策。
6
+ *
7
+ * 关键常量来自实测:
8
+ * - DSH 单图像素预算 ≈ 640_000(与 dsh-llm-deepseek 的 imagePixelBudget 默认值一致)
9
+ * - 单图 token 封顶 384(14px patch + 3:1 降采样)
10
+ */
11
+
12
+ export const PIXEL_BUDGET = 640_000;
13
+ export const IMAGE_TOKEN_CAP = 384;
14
+ export const MIN_CELL_W = 240;
15
+ export const MIN_CELL_H = 135;
16
+ export const MAX_SHEETS = 99; // 不封顶:片长决定张数(每 5 分钟一张),token 随片长线性增长
17
+ export const DEFAULT_ASPECT = 16 / 9;
18
+
19
+ /** Content-classification thresholds. Kept in one place so the manifest can report them. */
20
+ export const PLAN_THRESHOLDS = Object.freeze({
21
+ musicLufs: -18,
22
+ musicSpeechRate: 1,
23
+ speechRateCut: 3,
24
+ });
25
+
26
+ /** 画布比例 = (cols / rows) × 源比例。方形宫格才会还原源比例。 */
27
+ export const canvasAspect = (cols, rows, aspect) => (cols / rows) * aspect;
28
+
29
+ /**
30
+ * 给定格数 n 与源比例,选一组 (cols, rows) 使画布比例最接近源比例。
31
+ * - 允许 cols*rows >= n(多余位置补灰格),所以非平方数也不会被硬塞成怪形状
32
+ * - 同分时略偏袒"更高"的画布:超宽画布被方形/16:9 编码器裁掉的部分更多
33
+ */
34
+ export function bestLayout(n, aspect = DEFAULT_ASPECT) {
35
+ if (!Number.isInteger(n) || n < 1) throw new RangeError(`n must be a positive integer, got ${n}`);
36
+ if (!(aspect > 0)) throw new RangeError(`aspect must be > 0, got ${aspect}`);
37
+ let best = null;
38
+ for (let cols = 1; cols <= n; cols++) {
39
+ const rows = Math.ceil(n / cols);
40
+ const canvas = canvasAspect(cols, rows, aspect);
41
+ let cost = Math.abs(Math.log(canvas / aspect));
42
+ if (canvas > aspect) cost += 0.12;
43
+ const padded = cols * rows - n;
44
+ const key = [Math.round((cost + 0.15 * padded) * 1e6) / 1e6, cols * rows];
45
+ if (best === null || key[0] < best.key[0] || (key[0] === best.key[0] && key[1] < best.key[1])) {
46
+ best = { key, cols, rows };
47
+ }
48
+ }
49
+ const { cols, rows } = best;
50
+ return { cols, rows, capacity: cols * rows, canvasAspect: canvasAspect(cols, rows, aspect) };
51
+ }
52
+
53
+ /**
54
+ * 把"想要 n 格"补到布局能盛下的整格数。
55
+ *
56
+ * 为什么:5 格会排成 2×3(容量 6),右下留一个空格。空格和画面占的是**同一张画布、
57
+ * 同样的 token** —— 空着等于白丢一帧,纯损失。所以只往上补,绝不往下砍。
58
+ *
59
+ * 5 → 6、7 → 9、10 → 12、14 → 16;4/6/9/12/16 本来就是整格,不动。
60
+ * 补出来的数自己是 cols×rows 的乘积,再算一次布局通常就稳定了(最多再一轮)。
61
+ *
62
+ * **它只解决"因为布局取整而空出来的格"**。如果 minGap / 素材太短导致取不到那么多帧,
63
+ * 那属于几何上给不出,仍然会补灰 —— 那是事实,不是取整。
64
+ */
65
+ export function fillLayout(n, aspect = DEFAULT_ASPECT) {
66
+ const requested = Math.max(1, Math.round(Number(n) || 0));
67
+ let cells = requested;
68
+ let layout = bestLayout(cells, aspect);
69
+ for (let i = 0; i < 3 && layout.capacity > cells; i += 1) {
70
+ cells = layout.capacity;
71
+ layout = bestLayout(cells, aspect);
72
+ }
73
+ return { ...layout, cells, requested };
74
+ }
75
+
76
+ /** coverage 档位 → 建议格数(n 由 bestLayout 决定具体行列)。显式指定时用它覆盖自动推荐。 */
77
+ export const COVERAGE = {
78
+ overview: 4,
79
+ balanced: 9,
80
+ detailed: 12,
81
+ timeline: 16,
82
+ };
83
+
84
+ /**
85
+ * 音乐驱动判据:**响度高 + 几乎不说话**。
86
+ * 实测基准:口播片最轻最吵(5.6 字/秒 @ −23 LUFS),音乐片最响最静(0.3 字/秒 @ −14.2 LUFS)。
87
+ * 两个信号反向,一起看比任何主观判断都准。
88
+ *
89
+ * 它**只表示"这片子的信息全在画面上"**,因此只该影响"取帧密不密"(摊开门槛 / 积分触发值),
90
+ * 不该影响格数 —— 格数走 rodt,由切点密度决定。
91
+ */
92
+ export function isMusicDriven({ meanLufs, speechRate = 0, thresholds } = {}) {
93
+ const T = { ...PLAN_THRESHOLDS, ...(thresholds ?? {}) };
94
+ return Number.isFinite(meanLufs) && meanLufs > T.musicLufs && speechRate < T.musicSpeechRate;
95
+ }
96
+
97
+ /**
98
+ * 从廉价元数据推导建议:多少格、几张。
99
+ *
100
+ * 依据实测(B站 5 分钟镜头密集素材,1920×1080):
101
+ * - 9 格(33s/格)大量重复的草地镜头;16 格(19s/格)才把产品、人物、采访都覆盖到
102
+ * - 所以格数不该按"时长÷固定值"硬算,而是按"每格看多少秒"反推,且不超过镜头数
103
+ * - 镜头密集(均镜头 <4s)时每格 15s,否则 40s
104
+ *
105
+ * 每格看多少秒由**画面变化 p90** 连续决定(40 - p90,夹 8~45),不再三档硬切:
106
+ * 实测 B-roll 类 p90=7.9、快剪 PV p90=26、静态单镜头 p90=2.2 都能落在合理档位。
107
+ *
108
+ * @param {{duration:number, cuts?:number, motion?:number, aspect?:number,
109
+ * hasSubtitle?:boolean, speechRate?:number, meanLufs?:number, thresholds?:object}} meta
110
+ * motion:scanSummary().p90,拿不到就退回按均镜头长估
111
+ * speechRate:台词字数/秒(有字幕或 ASR 时才有;没有就传 0)
112
+ * meanLufs:整片平均响度,用来判"音乐驱动"(只影响取帧,不影响格数)
113
+ */
114
+ export function suggest(meta) {
115
+ const { duration, cuts = 0, motion, speechRate = 0, hasSubtitle = false, meanLufs } = meta;
116
+ // 阈值可覆盖:不同母带的响度能差 9 LU(实测 −23 … −14),写死的常数换一批片源就会误判。
117
+ const T = { ...PLAN_THRESHOLDS, ...(meta.thresholds ?? {}) };
118
+ if (!(duration > 0)) throw new RangeError(`duration must be > 0, got ${duration}`);
119
+ const shots = Math.max(1, cuts + 1);
120
+ const avgShot = duration / shots;
121
+
122
+ if (shots <= 1) {
123
+ return pick('overview', 4, 1,
124
+ `单镜头 ${(duration / 60).toFixed(1)}min → 视觉切分无用;建议配合台词,或直接用 zoom 看某几秒`);
125
+ }
126
+ // "短就 4 格"只对**内容简单**的短片成立。这条规则原来只看时长,于是 90 秒 41 个镜头的
127
+ // 概念 PV 被一句"4 帧足够概览"打发了 —— 那是这支片子最需要细看的时候。
128
+ // 现在要求镜头数也少,才认为是"真的能一眼看全"。
129
+ if (duration <= 90 && shots <= 8) {
130
+ return pick('overview', 4, 1, `${duration.toFixed(0)}s、${shots} 个镜头 → 4 帧足够概览`);
131
+ }
132
+
133
+ // 每格多少秒,只看**画面变化 p90**。
134
+ // 曾经试过再叠加一个"剪辑密度(刀/秒)取更密者",想让快剪 PV 拿到更多格 ——
135
+ // 实测反而更差:概念 PV 会被推到 12 格,每格只剩 3~4 个镜头,摊开也覆盖不住,
136
+ // 一张图只能展示 36 个画面;而 9 格(每格 4~5 镜)配摊开能做到 41/41 全覆盖。
137
+ // **格数多 ≠ 看到的多**:格数是"把时间切成几段",摊开才是"每段看几张"。
138
+ // 每格秒数随画面变化 p90 **连续**下降,不再三档硬切。
139
+ // 旧的 `motion>=15?12:motion>=5?20:40` 在 13.2 和 17.1 之间划了一刀:
140
+ // 两支几乎同长的 PV,一个 4 格一个 9 格,纯属跨不跨这条线的运气。
141
+ // 经验式:p90 每高 1 分,每格少 1 秒,夹在 [8, 45] —— 画面越"忙",越该细看。
142
+ const perCell = typeof motion === 'number'
143
+ ? Math.max(8, Math.min(45, 40 - motion))
144
+ : (avgShot < 4 ? 15 : 40);
145
+ // 内容类型分流(判据见 isMusicDriven):只影响取帧密度,不影响下面算出的格数。
146
+ const musicDriven = isMusicDriven({ meanLufs, speechRate, thresholds: meta.thresholds });
147
+
148
+ // **总格数直接由「切点总数」决定 —— 这就是对整片密度做积分。**
149
+ //
150
+ // 切点总数 = ∫(局部密度)dt,是全片"热闹程度"的精确总量。
151
+ // 原来用 p90(全片第 90 百分位)当代理指标,它只反映"平时多热闹",
152
+ // 快慢混杂的片子会被平均掉:前 5 分钟狂切、后面 30 分钟长镜头,p90 只看到中间值。
153
+ //
154
+ // 现在:**每格装 TARGET_SHOTS 个镜头**,格数 = 镜头数 ÷ TARGET_SHOTS。
155
+ // 每格 12 个镜头 → 摊 3×3 或 4×4 刚好,也不至于一格塞十几个看不清。
156
+ const TARGET_SHOTS_PER_CELL = 8;
157
+ const MAX_PER_SHEET = 16;
158
+ // 单格最多覆盖多少秒。超过这个长度,一格里的"中点"就开始不像这一段的代表了
159
+ // (6 分钟的格子里,取哪一帧都是随便挑的)。
160
+ const MAX_CELL_SECONDS = 90;
161
+ // **宁可挤一挤,也不为几格多开一张图。** 一张图 384 token,
162
+ // 如果总格数只比单张容量多一点点(≤15%),塞进一张、少看两三格,比多一张划算。
163
+ const OVERFLOW_TOLERANCE = 0.15;
164
+ // 格数取两个口径里更大的那个:
165
+ // 按镜头数:每格 8 个镜头(快剪素材的节奏基准)
166
+ // 按时长: 单格不超过 90 秒(安静的长素材的覆盖基准,且不超过镜头数)
167
+ // 只用镜头数会漏掉一整类素材:66 分钟讲座只有 150 刀,算出来 19 格 ——
168
+ // 最后是 12 格看 66 分钟(每格 5.5 分钟)。实测就是这么翻的车。
169
+ // 也不按"每格 40 秒"算:那会把 15 分钟 61 镜的片子推到 24 格,
170
+ // 而它 8 格就够 —— 只在"单格长到没法看"时才介入。
171
+ const byShots = Math.round(shots / TARGET_SHOTS_PER_CELL);
172
+ const bySeconds = Math.min(Math.round(duration / MAX_CELL_SECONDS), shots);
173
+ let totalCells = Math.max(4, byShots, bySeconds);
174
+ if (!musicDriven && (hasSubtitle || speechRate > 0) && speechRate > T.speechRateCut) {
175
+ // 台词承担信息,图只做锚点 —— 但**不能锚到 90 秒才一张**:
176
+ // 降档之后再拿 bySeconds 兜一次底,否则 66 分钟讲座会被降成 24 格(每格 165 秒)。
177
+ totalCells = Math.max(4, Math.round(totalCells * 0.6), bySeconds);
178
+ }
179
+ const perSheetCap = MAX_PER_SHEET * (1 + OVERFLOW_TOLERANCE);
180
+ const sheets = Math.min(MAX_SHEETS, Math.max(1, Math.ceil(totalCells / perSheetCap)));
181
+ // 每张分到的格数:总格数摊到各张,再吸附成能整除的布局
182
+ let cells = snapCells(clamp(Math.ceil(totalCells / sheets), 4, MAX_PER_SHEET));
183
+
184
+ const label = cells <= 4 ? 'overview' : cells <= 9 ? 'balanced' : cells <= 12 ? 'detailed' : 'timeline';
185
+ // 说明里把两个信号都写出来,否则"为什么给这个格数"又变成猜的
186
+ const pace = typeof motion === 'number'
187
+ ? `画面变化 p90=${motion.toFixed(1)}(${perCell.toFixed(0)}s/格)`
188
+ : `均镜头 ${avgShot.toFixed(1)}s(${perCell.toFixed(0)}s/格)`;
189
+ return pick(label, cells, sheets,
190
+ `${duration.toFixed(0)}s、${shots} 个镜头、${pace} → ${cells} 格 × ${sheets} 张(≈${Math.round(duration / (cells * sheets))}s/格)` +
191
+ (musicDriven ? '·音乐驱动(取帧更密,格数不受影响)' : ''), musicDriven);
192
+ }
193
+
194
+ /** 吸附到"能整除成好布局"的格数,避免出现大量 padding(8→9 比 8+1 空格好) */
195
+ export const SNAP_CELLS = [4, 6, 9, 12, 16];
196
+ export function snapCells(n) {
197
+ let best = SNAP_CELLS[0];
198
+ for (const c of SNAP_CELLS) if (Math.abs(c - n) < Math.abs(best - n)) best = c;
199
+ return best;
200
+ }
201
+
202
+ const clamp = (v, lo, hi) => Math.max(lo, Math.min(hi, v));
203
+
204
+ /**
205
+ * @param {boolean} [musicDriven] 音乐驱动。**必须真的带出去**:
206
+ * 下游 pipeline 靠 `suggest().musicDriven` 决定"取帧门槛压不压低"。
207
+ * 这个参数曾经在调用处传了、在这里没接 → 返回值里永远是 undefined,
208
+ * 于是"音乐片取帧更密"这条规则写了一套却从没生效过。
209
+ */
210
+ function pick(label, cells, sheets, reason, musicDriven) {
211
+ return {
212
+ coverage: label, cells, sheets, reason,
213
+ ...(musicDriven ? { musicDriven: true } : {}),
214
+ };
215
+ }
216
+
217
+ /** 按数量均分(用于"已用 fitSegments 调好段数"的场景,保证每张图正好填满) */
218
+ export function groupByCount(segs, per, sheets = 1) {
219
+ const out = [];
220
+ for (let s = 0; s < sheets; s++) out.push(segs.slice(s * per, (s + 1) * per));
221
+ return out;
222
+ }
223
+
224
+ /**
225
+ * 把有序段列表切成 sheets 组,使每组覆盖时长尽量相等;切点只落在段边界(不劈镜头)。
226
+ * 注意:不保证每组段数相同,可能出现空格(padding)。如果你已经 fitSegments 到
227
+ * per×sheets,请用 groupByCount,那样不会浪费格位。
228
+ * @param {Array<[number, number]>} segs 有序、不重叠的 [t0, t1]
229
+ */
230
+ export function groupByDuration(segs, sheets) {
231
+ if (!Array.isArray(segs)) throw new TypeError('segs must be an array');
232
+ if (sheets <= 1) return [segs.slice()];
233
+ const total = segs.reduce((sum, [a, b]) => sum + (b - a), 0);
234
+ const target = total / sheets;
235
+ const groups = [];
236
+ let cur = [];
237
+ let acc = 0;
238
+ let left = sheets;
239
+ for (let i = 0; i < segs.length; i++) {
240
+ cur.push(segs[i]);
241
+ acc += segs[i][1] - segs[i][0];
242
+ const restSegs = segs.length - (i + 1);
243
+ if (left > 1 && acc >= target && restSegs >= left - 1) {
244
+ groups.push(cur);
245
+ cur = [];
246
+ acc = 0;
247
+ left -= 1;
248
+ }
249
+ }
250
+ if (cur.length > 0) groups.push(cur);
251
+ while (groups.length < sheets) groups.push([]);
252
+ return groups.slice(0, sheets);
253
+ }
254
+
255
+ /** 单格像素尺寸(按预算与布局推导)。 */
256
+ export function cellSize(cols, rows, aspect = DEFAULT_ASPECT, budget = PIXEL_BUDGET) {
257
+ const area = budget / (cols * rows);
258
+ const w = Math.round(Math.sqrt(area * aspect));
259
+ return { w, h: Math.round(w / aspect), area: Math.round(area) };
260
+ }
261
+
262
+ /**
263
+ * 生成一次完整的出图计划。
264
+ * 显式给 cells: [m,n] 时尊重调用方;只给 coverage 时由 bestLayout 决定行列。
265
+ */
266
+ export function planTotal(meta, opts = {}) {
267
+ const s = suggest(meta);
268
+ const aspect = meta.aspect ?? DEFAULT_ASPECT;
269
+ const coverage = opts.coverage ?? s.coverage;
270
+ const budgetImages = Math.min(MAX_SHEETS, opts.budgetImages ?? MAX_SHEETS);
271
+
272
+ let cols;
273
+ let rows;
274
+ if (Array.isArray(opts.cells) && opts.cells.length === 2) {
275
+ [cols, rows] = opts.cells.map(Number);
276
+ } else {
277
+ const n = opts.cells ?? (opts.coverage ? COVERAGE[opts.coverage] : s.cells);
278
+ ({ cols, rows } = bestLayout(Number(n), aspect));
279
+ }
280
+
281
+ let sheets = Math.max(1, opts.sheets ?? s.sheets);
282
+ const truncated = sheets > budgetImages;
283
+ if (truncated) sheets = budgetImages;
284
+
285
+ const cell = cellSize(cols, rows, aspect);
286
+ return {
287
+ cols,
288
+ rows,
289
+ capacity: cols * rows,
290
+ sheets,
291
+ coverage,
292
+ cell,
293
+ canvasAspect: canvasAspect(cols, rows, aspect),
294
+ images: sheets,
295
+ approxTokens: sheets * IMAGE_TOKEN_CAP,
296
+ truncated,
297
+ reason: s.reason,
298
+ };
299
+ }
300
+
301
+ /**
302
+ * 把长片切成 N 个窗口,供"分段看"用。**在扫描之前**就要能算,
303
+ * 所以格数只能按时长估(每格约 20s),是预估值,不是最终值。
304
+ *
305
+ * @param {number} duration 全片时长(秒)
306
+ * @param {number} step 每段最长多少秒
307
+ * @param {{cells?:number, maxWindows?:number}} opts
308
+ */
309
+ export function planWindows(duration, step = 300, {
310
+ cells, maxWindows = 12, boundaries = [], snapRatio = 0.2,
311
+ } = {}) {
312
+ if (!(duration > 0)) throw new RangeError(`duration must be > 0, got ${duration}`);
313
+ if (!(step > 0)) throw new RangeError(`step must be > 0, got ${step}`);
314
+ // 段数超上限时不是"砍掉尾巴",而是把每段拉长,保证覆盖全片
315
+ let span = step;
316
+ let total = Math.ceil(duration / span);
317
+ let stepAdjusted = false;
318
+ if (total > maxWindows) {
319
+ span = duration / maxWindows;
320
+ total = maxWindows;
321
+ stepAdjusted = true;
322
+ }
323
+ total = Math.max(1, total);
324
+ // 尾巴短于 30 秒就并进前一个窗口:92s 按 30s 切会剩一个 2.18s 的窗口,只够 1 格,
325
+ // 白白多花 384 token 换一张几乎没信息的图。用绝对阈值(而不是按比例),
326
+ // 这样 650s/300s 那种 50s 的尾巴不会被无谓地并掉。
327
+ if (total > 1) {
328
+ const tail = duration - (total - 1) * span;
329
+ if (tail < 30) total -= 1;
330
+ }
331
+ const windows = [];
332
+ for (let i = 0; i < total; i++) {
333
+ const from = +(i * span).toFixed(2);
334
+ // 最后一个窗口吸收剩下的全部(含被并掉的尾巴)
335
+ const to = i === total - 1 ? +duration.toFixed(2) : +Math.min(duration, from + span).toFixed(2);
336
+ const len = to - from;
337
+ const n = cells ?? snapCells(Math.max(4, Math.round(len / 20)));
338
+ const images = 1;
339
+ windows.push({
340
+ index: i + 1, from, to, duration: +len.toFixed(2),
341
+ cells: n, images, approxTokens: images * IMAGE_TOKEN_CAP,
342
+ });
343
+ }
344
+ // 窗口边界吸附到最近的剪辑点:按钟表切会把一句话劈成两半,
345
+ // 按内容切则每个窗口都是"几个完整镜头"。只吸附到 step×snapRatio 以内的点,
346
+ // 太远就不动(否则窗口长度会失控)。
347
+ let snapped = 0;
348
+ if (boundaries.length > 0 && windows.length > 1) {
349
+ const sorted = [...boundaries].filter((t) => t > 0 && t < duration).sort((a, b) => a - b);
350
+ const limit = span * snapRatio;
351
+ for (let i = 1; i < windows.length; i++) {
352
+ const target = windows[i].from;
353
+ let best = null;
354
+ let bestD = limit;
355
+ for (const t of sorted) {
356
+ const d = Math.abs(t - target);
357
+ if (d < bestD) { best = t; bestD = d; }
358
+ }
359
+ if (best === null) continue;
360
+ const prevFrom = windows[i - 1].from;
361
+ if (best - prevFrom < span * 0.3) continue; // 别把窗口压得太短
362
+ windows[i].from = +best.toFixed(2);
363
+ windows[i - 1].to = +best.toFixed(2);
364
+ windows[i].duration = +(windows[i].to - windows[i].from).toFixed(2);
365
+ windows[i - 1].duration = +(windows[i - 1].to - windows[i - 1].from).toFixed(2);
366
+ snapped += 1;
367
+ }
368
+ }
369
+
370
+ return {
371
+ total,
372
+ snapped,
373
+ step: +span.toFixed(2),
374
+ requestedStep: step,
375
+ stepAdjusted,
376
+ covered: +windows.reduce((sum, w) => sum + w.duration, 0).toFixed(2),
377
+ windows,
378
+ approxTokens: windows.reduce((sum, w) => sum + w.approxTokens, 0),
379
+ };
380
+ }
381
+
382
+ /** 护栏:不可商量的硬约束,写死在工具里,不靠模型自觉。 */
383
+ export function validatePlan(plan, aspect = DEFAULT_ASPECT) {
384
+ const errors = [];
385
+ const warnings = [];
386
+ const { cols, rows, sheets, cell } = plan;
387
+ if (cols < 1 || rows < 1) errors.push('cols/rows must be >= 1');
388
+ if (cell.w < MIN_CELL_W || cell.h < MIN_CELL_H) {
389
+ errors.push(`cell ${cell.w}x${cell.h} below minimum ${MIN_CELL_W}x${MIN_CELL_H}; reduce cells or add sheets`);
390
+ }
391
+ const ratio = plan.canvasAspect / aspect;
392
+ if (ratio > 1.5 || ratio < 0.6) {
393
+ errors.push(`canvas aspect ${plan.canvasAspect.toFixed(2)} deviates too far from source ${aspect.toFixed(2)}`);
394
+ } else if (ratio > 1.25 || ratio < 0.8) {
395
+ warnings.push(`canvas aspect ${plan.canvasAspect.toFixed(2)} is off source ${aspect.toFixed(2)}; ` +
396
+ `auto layout would pick a friendlier shape`);
397
+ }
398
+ if (sheets < 1 || sheets > MAX_SHEETS) errors.push(`sheets must be 1..${MAX_SHEETS}`);
399
+ return { ok: errors.length === 0, errors, warnings };
400
+ }
@@ -0,0 +1,132 @@
1
+ /**
2
+ * probe.js — ffprobe 封装 + 旋转归一。纯 IO 层,不做决策。
3
+ *
4
+ * 两个安静出错的坑(都有测试):
5
+ * 1. 手机竖拍常是"编码 1920×1080 + rotation 90",ffmpeg 解码会转正,ffprobe 报的是编码尺寸;
6
+ * 拿编码尺寸去算 scale 会把画面拉扁。
7
+ * 2. 末尾边界没有帧:时长的最后一帧在 duration - 1/fps 附近,-ss duration 抽不出东西。
8
+ */
9
+
10
+ import { execFile } from 'node:child_process';
11
+ import { promisify } from 'node:util';
12
+
13
+ import { DEFAULT_FFMPEG, DEFAULT_FFPROBE, describeMediaSearch } from './binaries.js';
14
+
15
+ const run = promisify(execFile);
16
+
17
+ export { DEFAULT_FFMPEG, DEFAULT_FFPROBE };
18
+
19
+ /** "25/1" | "30000/1001" → number | null */
20
+ export function parseRational(value) {
21
+ if (typeof value !== 'string' || value.trim() === '') return null;
22
+ const [num, den = '1'] = value.split('/');
23
+ const a = Number(num);
24
+ const b = Number(den);
25
+ if (!Number.isFinite(a) || !Number.isFinite(b) || b === 0) return null;
26
+ const v = a / b;
27
+ return Number.isFinite(v) && v > 0 ? v : null;
28
+ }
29
+
30
+ /**
31
+ * 像素宽高比(SAR):`4:3` / `1:1` / `0:1`。
32
+ * 0:1 或缺失表示"未声明",按方像素(1:1)处理。
33
+ */
34
+ export function parseSar(value) {
35
+ // ffprobe 的 sample_aspect_ratio 是 `4:3` 这种冒号写法(不是帧率的 `24/1` 斜杠写法)
36
+ if (typeof value !== 'string' || !value.includes(':')) return 1;
37
+ const [num, den = '1'] = value.split(':');
38
+ const a = Number(num);
39
+ const b = Number(den);
40
+ if (!Number.isFinite(a) || !Number.isFinite(b) || b === 0 || a <= 0) return 1;
41
+ return a / b;
42
+ }
43
+
44
+ /**
45
+ * 显示宽高比(DAR)= 编码宽 × SAR / 编码高;转 90° 后取倒数。
46
+ *
47
+ * 为什么不能用 width/height 直接算:非方形像素的素材(DVD 时代的 1440×1080 存成 4:3 SAR、
48
+ * 部分手机的变形录制)编码尺寸和**显示**尺寸不是一回事。用编码尺寸算比例,格子会被压扁/拉长,
49
+ * 而模型对"人脸比例不对"是敏感的。
50
+ */
51
+ export function displayAspect(codedW, codedH, sar, rotation = 0) {
52
+ if (!(codedW > 0) || !(codedH > 0)) return 16 / 9;
53
+ const dar = (codedW * (sar > 0 ? sar : 1)) / codedH;
54
+ return Math.abs(rotation) % 180 === 90 ? 1 / dar : dar;
55
+ }
56
+
57
+ /** 旋转角归一化到 (-180, 180] */
58
+ export function normalizeRotation(raw) {
59
+ const v = Number(raw);
60
+ if (!Number.isFinite(v)) return 0;
61
+ let a = v % 360;
62
+ if (a > 180) a -= 360;
63
+ if (a <= -180) a += 360;
64
+ return Math.round(a);
65
+ }
66
+
67
+ /** 旋转 90/270 时,观众看到的宽高与编码宽高互换 */
68
+ export function uprightSize(codedWidth, codedHeight, rotation) {
69
+ return Math.abs(rotation) % 180 === 90
70
+ ? { width: codedHeight, height: codedWidth }
71
+ : { width: codedWidth, height: codedHeight };
72
+ }
73
+
74
+ /** 末尾避让量:等分采样最后一帧若取 duration,会落在"不存在的帧"上 */
75
+ export const endEdge = (fps) => (fps > 0 ? 0.5 / fps : 0.02);
76
+
77
+ export async function probeVideo(input, { ffprobePath = DEFAULT_FFPROBE } = {}) {
78
+ let stdout;
79
+ try {
80
+ ({ stdout } = await run(
81
+ ffprobePath,
82
+ ['-v', 'error', '-print_format', 'json', '-show_format', '-show_streams', input],
83
+ { maxBuffer: 8 * 1024 * 1024 },
84
+ ));
85
+ } catch (error) {
86
+ if (error?.code === 'ENOENT') {
87
+ throw new Error(describeMediaSearch('ffprobe'));
88
+ }
89
+ throw error;
90
+ }
91
+ let parsed;
92
+ try {
93
+ parsed = JSON.parse(stdout);
94
+ } catch {
95
+ throw new Error(`ffprobe did not return JSON for "${input}"`);
96
+ }
97
+ const streams = Array.isArray(parsed?.streams) ? parsed.streams : [];
98
+ const video = streams.find((s) => s?.codec_type === 'video');
99
+ if (!video) throw new Error(`"${input}" has no video stream`);
100
+ const audio = streams.find((s) => s?.codec_type === 'audio');
101
+ const subtitle = streams.find((s) => s?.codec_type === 'subtitle');
102
+
103
+ const duration =
104
+ Number(parsed?.format?.duration) || Number(video?.duration) || 0;
105
+ const rotation = normalizeRotation(
106
+ video?.side_data_list?.find((d) => d?.rotation !== undefined)?.rotation ?? video?.tags?.rotate,
107
+ );
108
+ const coded = { width: Number(video.width) || 0, height: Number(video.height) || 0 };
109
+ const { width, height } = uprightSize(coded.width, coded.height, rotation);
110
+ // VFR 素材上 r_frame_rate 可能是 1000/1 之类的时间基噪声,avg_frame_rate 才是真实平均帧率。
111
+ // 我们的窗口扫描要用 fps 换算时长,帧率错 → 时长错 → 格边界错。
112
+ const rFps = parseRational(video.r_frame_rate);
113
+ const avgFps = parseRational(video.avg_frame_rate);
114
+ const fps = (rFps && rFps <= 240 ? rFps : null) ?? avgFps ?? 25;
115
+ const sar = parseSar(video.sample_aspect_ratio);
116
+
117
+ return {
118
+ duration,
119
+ width,
120
+ height,
121
+ coded,
122
+ rotation,
123
+ fps,
124
+ sar,
125
+ aspect: displayAspect(coded.width, coded.height, sar, rotation),
126
+ videoCodec: video.codec_name ?? 'unknown',
127
+ container: parsed?.format?.format_name ?? 'unknown',
128
+ hasAudio: Boolean(audio),
129
+ hasSubtitle: Boolean(subtitle),
130
+ audioCodec: audio?.codec_name ?? null,
131
+ };
132
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * provenance.js — best-effort source and tool provenance.
3
+ *
4
+ * Both helpers are deliberately failure-tolerant: provenance is metadata, not a
5
+ * reason to fail a render. The version is cached per binary path; hashing a large
6
+ * file is opt-in at the pipeline level because it costs a full read.
7
+ */
8
+ import { createHash } from 'node:crypto';
9
+ import { createReadStream } from 'node:fs';
10
+ import { execFile } from 'node:child_process';
11
+ import { promisify } from 'node:util';
12
+
13
+ const run = promisify(execFile);
14
+ const versionCache = new Map();
15
+
16
+ /** Full-file SHA-256 as lowercase hex. Rejects if the file cannot be read. */
17
+ export async function sha256File(path) {
18
+ const hash = createHash('sha256');
19
+ await new Promise((resolve, reject) => {
20
+ const stream = createReadStream(path);
21
+ stream.on('data', (chunk) => hash.update(chunk));
22
+ stream.on('error', reject);
23
+ stream.on('end', resolve);
24
+ });
25
+ return hash.digest('hex');
26
+ }
27
+
28
+ /** First token after "ffmpeg version", e.g. "6.1.1"; null when unavailable. */
29
+ export async function ffmpegVersion(ffmpegPath = 'ffmpeg') {
30
+ if (versionCache.has(ffmpegPath)) return versionCache.get(ffmpegPath);
31
+ let version = null;
32
+ try {
33
+ const { stdout } = await run(ffmpegPath, ['-version'], {
34
+ timeout: 5_000,
35
+ maxBuffer: 1024 * 1024,
36
+ });
37
+ const line = String(stdout).split(/\r?\n/).find((l) => l.startsWith('ffmpeg version '));
38
+ if (line) version = line.slice('ffmpeg version '.length).trim().split(/\s+/)[0] || null;
39
+ } catch {
40
+ version = null;
41
+ }
42
+ versionCache.set(ffmpegPath, version);
43
+ return version;
44
+ }
@@ -0,0 +1,84 @@
1
+ /**
2
+ * python.js — 找一台机器上的 Python(OCR 和读播放进度都要用它)。
3
+ *
4
+ * 为什么单独一个模块:这两件事都是"本地 Python 能力"(rapidocr / winrt),
5
+ * 之前各自在 windows 上硬编码了 `D:/asr-local/.venv/Scripts/python.exe` ——
6
+ * 那是开发机上的路径,**跟着包发出去会让别人的插件永远跳过这两项功能**。
7
+ *
8
+ * 顺序:显式配置 → 环境变量 → PATH 上的 python / python3。
9
+ * 找不到就返回 null,调用方据此说"跳过",不报错。
10
+ */
11
+
12
+ import { execFile } from 'node:child_process';
13
+ import { existsSync, readFileSync } from 'node:fs';
14
+ import { homedir } from 'node:os';
15
+ import { join } from 'node:path';
16
+
17
+ /** 从 ~/.dsh/asr.json 里挖出 ASR 用的那个 python(有就当作候选) */
18
+ function asrPython(env = process.env) {
19
+ const home = env.DSH_HOME || join(env.USERPROFILE || env.HOME || homedir(), '.dsh');
20
+ try {
21
+ const cfg = JSON.parse(readFileSync(join(home, 'asr.json'), 'utf8'));
22
+ const start = Array.isArray(cfg?.manage?.start) ? cfg.manage.start[0] : cfg?.manage?.start;
23
+ if (typeof start === 'string' && /python(\.exe)?$/i.test(start) && existsSync(start)) return start;
24
+ } catch { /* 没有配置就算了 */ }
25
+ return null;
26
+ }
27
+
28
+ /** @returns {string[]} 候选解释器,按优先级 */
29
+ export function pythonCandidates({ config = {}, env = process.env } = {}) {
30
+ const out = [];
31
+ const push = (v) => {
32
+ if (typeof v === 'string' && v.trim() && !out.includes(v.trim())) out.push(v.trim());
33
+ };
34
+ push(config?.ocr?.python); // 老配置项,保留兼容
35
+ push(config?.python);
36
+ push(env.DSH_PYTHON);
37
+ push(env.DSH_OCR_PYTHON);
38
+ push(env.DSH_WATCH_PYTHON);
39
+ // 用户已经为 ASR 配过一个 venv python —— 说明那台机器上"本地 Python 能力"装在这里的可能性最高。
40
+ // 复用它的好处:不需要再教用户多配一个环境变量。
41
+ push(asrPython(env));
42
+ // PATH 上的:Windows 通常叫 python,类 Unix 叫 python3
43
+ if (process.platform === 'win32') {
44
+ push('python');
45
+ push('py');
46
+ } else {
47
+ push('python3');
48
+ push('python');
49
+ }
50
+ return out;
51
+ }
52
+
53
+ /**
54
+ * 依次试候选解释器,返回第一个能跑通 `-c "import <module>"` 的。
55
+ * 结果进程内缓存:一次启动只会探一次。
56
+ */
57
+ const verified = new Map();
58
+
59
+ export function findPython(module, { config = {}, env = process.env, timeoutMs = 4000 } = {}) {
60
+ const key = String(module);
61
+ if (verified.has(key)) return Promise.resolve(verified.get(key));
62
+ const candidates = pythonCandidates({ config, env });
63
+ return new Promise((resolve) => {
64
+ let i = 0;
65
+ const tryNext = () => {
66
+ if (i >= candidates.length) {
67
+ verified.set(key, null);
68
+ return resolve(null);
69
+ }
70
+ const cmd = candidates[i++];
71
+ execFile(cmd, ['-c', `import ${module}`], { timeout: timeoutMs, windowsHide: true }, (err) => {
72
+ if (err) return tryNext();
73
+ verified.set(key, cmd);
74
+ return resolve(cmd);
75
+ });
76
+ };
77
+ tryNext();
78
+ });
79
+ }
80
+
81
+ /** 清掉探测缓存(测试用) */
82
+ export function __resetPythonCache() {
83
+ verified.clear();
84
+ }