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,70 @@
1
+ /**
2
+ * cells.js — 记住上一次分镜里每一格对应的**绝对时间**,供 `video_zoom({ cellId })` 直接寻址。
3
+ *
4
+ * 为什么需要:清单里每格都有 `t_start/t_end`,但模型想细看某一格时得自己抄数字,
5
+ * 换窗口、改参数之后就抄错。cellId 让它"引用一次就闭环"。
6
+ *
7
+ * 存在哪:<cacheDir>/cells.json,只保留最近若干个文件,坏了就当没有(寻址失败可以退回 from/to)。
8
+ */
9
+ import { mkdir, readFile, writeFile } from 'node:fs/promises';
10
+ import { join } from 'node:path';
11
+
12
+ import { cacheDir } from './cache.js';
13
+
14
+ const FILE = 'cells.json';
15
+ const MAX_FILES = 12;
16
+
17
+ const norm = (p) => String(p ?? '').replace(/\\/g, '/').toLowerCase();
18
+
19
+ export function cellsPath(env = process.env) {
20
+ return join(cacheDir(env), FILE);
21
+ }
22
+
23
+ /**
24
+ * 记下这次分镜的格子表。
25
+ * @param {string|string[]} path 源文件路径;可以同时给 URL 和下载到本地的路径,让两边都能寻址
26
+ * @param {Array<{i:number, from:number, to:number}>} cells 绝对时间(秒)
27
+ *
28
+ * **为什么要支持数组**:远程视频的 `input` 是 URL,但下载后 `input` 会变成临时文件路径。
29
+ * `video_zoom({cellId})` 那边可能拿 URL 来查,也可能拿本地路径 —— 只存一个 key 就必然有一边查不到。
30
+ * 这个坑踩过:cell 表写进去了,用 URL 查三次全是 NOT FOUND。
31
+ */
32
+ export async function saveCells(path, cells, { env = process.env, at = Date.now() } = {}) {
33
+ const aliases = [...new Set((Array.isArray(path) ? path : [path]).map(norm).filter(Boolean))];
34
+ if (aliases.length === 0 || !Array.isArray(cells) || cells.length === 0) return;
35
+ const file = cellsPath(env);
36
+ let all = {};
37
+ try {
38
+ all = JSON.parse(await readFile(file, 'utf8')) ?? {};
39
+ } catch { /* 没有或坏了:重建 */ }
40
+
41
+ const record = {
42
+ at,
43
+ cells: cells.map((c) => ({ i: c.i, from: +c.from.toFixed(3), to: +c.to.toFixed(3) })),
44
+ };
45
+ for (const key of aliases) all[key] = record;
46
+ // 按时间保留最近 MAX_FILES 个文件
47
+ const keys = Object.keys(all).sort((a, b) => (all[b]?.at ?? 0) - (all[a]?.at ?? 0));
48
+ for (const k of keys.slice(MAX_FILES)) delete all[k];
49
+
50
+ try {
51
+ await mkdir(cacheDir(env), { recursive: true });
52
+ await writeFile(file, JSON.stringify(all), 'utf8');
53
+ } catch { /* 写不进去就算了,寻址会退回 from/to */ }
54
+ }
55
+
56
+ /**
57
+ * 查某个文件某一格的绝对时间区间。
58
+ * @returns {{from:number, to:number, i:number}|null}
59
+ */
60
+ export async function lookupCell(path, cellId, { env = process.env } = {}) {
61
+ if (!path || !Number.isFinite(Number(cellId))) return null;
62
+ try {
63
+ const all = JSON.parse(await readFile(cellsPath(env), 'utf8')) ?? {};
64
+ const rec = all[norm(path)];
65
+ const hit = rec?.cells?.find((c) => c.i === Number(cellId));
66
+ return hit ? { ...hit } : null;
67
+ } catch {
68
+ return null;
69
+ }
70
+ }
@@ -0,0 +1,545 @@
1
+ /**
2
+ * density.js — 按"画面密度"分配格位:快切区多给格,长镜头少给格。
3
+ *
4
+ * 为什么需要:`fitSegments` 会把短镜头**并进邻居**(为了避免 0.3s 的镜头独占一格),
5
+ * 结果是快切爆发区被压成 1 格、只留一张代表帧 —— 那一段里"发生了什么"就丢了。
6
+ * 而 16 格的总预算是固定的,所以正确做法不是"加格",而是**把格往密的地方挪**。
7
+ *
8
+ * 做法:给时间轴建一条密度曲线(普通处 1.0,快切爆发处 1+boost),
9
+ * 然后在"密度积分"上等分 —— 积分等分 = 每一格承载的"信息量"相同,
10
+ * 于是快切区自然分到更短的时段、更多的格。整段时间轴仍然被完整覆盖。
11
+ */
12
+
13
+ export const BIN = 0.1; // 密度采样粒度(秒)
14
+ export const RATE_WINDOW = 2.0; // 局部剪辑率的统计半窗(秒)
15
+ export const MAX_DENSITY = 2.5; // 密度上限:最快的区域最多拿到 2.5 倍格位(再高就会喧宾夺主)
16
+
17
+ /**
18
+ * 局部剪辑率:t 附近 ±window 秒内有多少个切点,换算成"每秒几刀"。
19
+ * 用二分查找,O(log n)/bin。
20
+ */
21
+ function localRate(sorted, t, window, duration) {
22
+ const lo = t - window;
23
+ const hi = t + window;
24
+ const count = upperBound(sorted, hi) - lowerBound(sorted, lo);
25
+ const span = Math.min(duration, hi) - Math.max(0, lo);
26
+ return span > 0 ? count / span : 0;
27
+ }
28
+
29
+ const lowerBound = (arr, v) => {
30
+ let lo = 0;
31
+ let hi = arr.length;
32
+ while (lo < hi) {
33
+ const mid = (lo + hi) >> 1;
34
+ if (arr[mid] < v) lo = mid + 1; else hi = mid;
35
+ }
36
+ return lo;
37
+ };
38
+ const upperBound = (arr, v) => {
39
+ let lo = 0;
40
+ let hi = arr.length;
41
+ while (lo < hi) {
42
+ const mid = (lo + hi) >> 1;
43
+ if (arr[mid] <= v) lo = mid + 1; else hi = mid;
44
+ }
45
+ return lo;
46
+ };
47
+
48
+ /**
49
+ * 密度曲线:density(t) = clamp(局部剪辑率 / 全片平均剪辑率, 1, MAX_DENSITY)
50
+ *
51
+ * 不用"固定 1.2s 算快切"那种硬阈值——一条 PV 的平均镜头本来就 2.2s,
52
+ * 硬阈值会一个爆发都认不出来。改成**和这条片子自己的平均节奏比**:
53
+ * 比平均快 3 倍的地方拿 3 倍格位,慢于平均的地方不额外给格。
54
+ */
55
+ export function densityCurve({
56
+ duration, cuts = [], bin = BIN, window = RATE_WINDOW, max = MAX_DENSITY, speech,
57
+ }) {
58
+ if (!(duration > 0)) throw new RangeError(`duration must be > 0, got ${duration}`);
59
+ const sorted = [...cuts].filter((c) => c > 0 && c < duration).sort((a, b) => a - b);
60
+ const bins = Math.max(1, Math.ceil(duration / bin));
61
+ const out = new Float64Array(bins);
62
+ if (sorted.length === 0) {
63
+ out.fill(1);
64
+ return { bins, density: out, meanRate: 0, peakRate: 0 };
65
+ }
66
+ const meanRate = sorted.length / duration;
67
+ // 两遍:先算逐 bin 的局部率,再做一次同宽度的箱型平滑。
68
+ // 不平滑的话,**均匀剪辑**的片子会在每个切点附近鼓一个包(窗口里多算了一刀),
69
+ // 实战里会认出一堆假"爆发"。
70
+ const half = Math.max(1, Math.round(window / bin));
71
+ const raw = new Float64Array(bins);
72
+ for (let i = 0; i < bins; i++) raw[i] = localRate(sorted, i * bin, window, duration);
73
+ const prefix = new Float64Array(bins + 1);
74
+ for (let i = 0; i < bins; i++) prefix[i + 1] = prefix[i] + raw[i];
75
+ let peakRate = 0;
76
+ for (let i = 0; i < bins; i++) {
77
+ const lo = Math.max(0, i - half);
78
+ const hi = Math.min(bins, i + half + 1);
79
+ const smooth = (prefix[hi] - prefix[lo]) / (hi - lo);
80
+ peakRate = Math.max(peakRate, smooth);
81
+ out[i] = Math.min(max, Math.max(1, meanRate > 0 ? smooth / meanRate : 1));
82
+ }
83
+
84
+ // 第三条信号:台词密度(每秒字数)。说话快的地方信息密,也该多给格。
85
+ // 只做温和放大(0.75–1.4),免得把画面信号压过去。
86
+ if (speech && speech.mean > 0) {
87
+ for (let i = 0; i < bins; i++) {
88
+ const ratio = speech.curve[Math.min(speech.bins - 1, i)] / speech.mean;
89
+ const factor = Math.min(1.4, Math.max(0.75, ratio));
90
+ out[i] = Math.min(max, Math.max(1, out[i] * factor));
91
+ }
92
+ }
93
+ return { bins, density: out, meanRate, peakRate };
94
+ }
95
+
96
+ /**
97
+ * 用**画面变化率本身**当密度,而不是用切点计数。
98
+ *
99
+ * 为什么:切点计数是"离散事件"——一处误报就在那里顶起一个密度尖峰;
100
+ * 而变化率是连续信号,一段时间都在动就是一段平台,分格自然平滑。
101
+ * 三个一镜到底的真实素材上量过,格长离散度从 0.53/0.52/0.26 降到 0.33/0.36/0.21。
102
+ *
103
+ * 更关键的是:**它不依赖切点检测准不准**。一镜到底的素材就算误报 3 个切点,
104
+ * 分格结果依然平滑 —— 因为 3 个孤立切点在半秒的箱型平滑里根本鼓不起来。
105
+ * 这也是"多一两帧误判无所谓"这句话在数学上的依据。
106
+ *
107
+ * @param {{duration:number, scores:Array<{t:number,score:number}>, bin?:number,
108
+ * window?:number, max?:number, offset?:number, speech?:object}} opts
109
+ * scores: 逐帧分数,t 用绝对秒;offset 是本窗口起点(转成相对时间用)
110
+ * @returns {{bins:number, density:Float64Array, meanScore:number}}
111
+ */
112
+ export function densityFromScore({
113
+ duration, scores, bin = BIN, window = 0.5, max = MAX_DENSITY, offset = 0, speech,
114
+ }) {
115
+ if (!(duration > 0)) throw new RangeError(`duration must be > 0, got ${duration}`);
116
+ const bins = Math.max(1, Math.ceil(duration / bin));
117
+
118
+ // 先算逐帧分数的 p95 当上限(winsorize)。
119
+ // 不截的话,单帧极端值会主导整段密度:实测 MAD 前 30 秒有一次黑场,score 78.9,
120
+ // 而同期真切只有 40 —— 那一帧把旁边的格子吸成 1.83 秒,格长离散度从 0.174 恶化到 0.276。
121
+ // 削到 p95 之后极端值只保留"很多帧都这么大"的那部分,符合"这段一直在变"才有资格拿格位。
122
+ const usable = (scores ?? []).filter((s) => s.t - offset >= 0 && s.t - offset < duration);
123
+ const sortedAll = usable.map((s) => s.score).sort((a, b) => a - b);
124
+ const scoreCap = sortedAll.length ? sortedAll[Math.floor(sortedAll.length * 0.95)] : Infinity;
125
+
126
+ const acc = new Float64Array(bins);
127
+ const cnt = new Uint32Array(bins);
128
+ for (const s of usable) {
129
+ const rel = s.t - offset;
130
+ const i = Math.min(bins - 1, Math.floor(rel / bin));
131
+ acc[i] += Math.min(s.score, scoreCap);
132
+ cnt[i] += 1;
133
+ }
134
+
135
+ const raw = new Float64Array(bins);
136
+ let filled = 0;
137
+ for (let i = 0; i < bins; i++) {
138
+ if (cnt[i]) { raw[i] = acc[i] / cnt[i]; filled += 1; }
139
+ }
140
+ if (filled === 0) return { bins, density: new Float64Array(bins).fill(1), meanScore: 0 };
141
+
142
+ // 箱型平滑:不平滑的话,一次切点会在它前后各鼓一个包,分格跟着抖
143
+ const half = Math.max(1, Math.round(window / bin));
144
+ const pre = new Float64Array(bins + 1);
145
+ for (let i = 0; i < bins; i++) pre[i + 1] = pre[i] + raw[i];
146
+ const smooth = new Float64Array(bins);
147
+ let mean = 0;
148
+ for (let i = 0; i < bins; i++) {
149
+ const lo = Math.max(0, i - half);
150
+ const hi = Math.min(bins, i + half + 1);
151
+ smooth[i] = (pre[hi] - pre[lo]) / (hi - lo);
152
+ mean += smooth[i];
153
+ }
154
+ mean /= bins;
155
+
156
+ // 归一化到"全片平均变化率 = 1",再夹到 [1, max]:
157
+ // 比平均安静的地方也至少拿 1 份(格子不会因为"没内容"被压没),
158
+ // 比平均剧烈的地方最多拿 max 倍(MAX_DENSITY 原本就有这层意思)。
159
+ const out = new Float64Array(bins);
160
+ for (let i = 0; i < bins; i++) {
161
+ out[i] = Math.min(max, Math.max(1, mean > 0 ? smooth[i] / mean : 1));
162
+ }
163
+
164
+ // 台词密度:说话快的地方信息密,温和放大(0.75–1.4),和 densityCurve 同一口径
165
+ if (speech && speech.mean > 0) {
166
+ for (let i = 0; i < bins; i++) {
167
+ const ratio = speech.curve[Math.min(speech.bins - 1, i)] / speech.mean;
168
+ const factor = Math.min(1.4, Math.max(0.75, ratio));
169
+ out[i] = Math.min(max, Math.max(1, out[i] * factor));
170
+ }
171
+ }
172
+ return { bins, density: out, meanScore: mean };
173
+ }
174
+
175
+ /**
176
+ * 找出"剪辑最密"的时段(只用于报告,不影响分配)。
177
+ */
178
+ export function findBursts(cuts, duration, { window = RATE_WINDOW, max = MAX_DENSITY } = {}) {
179
+ // densityCurve 只认数字;调用方有时传 {t},这里统一一次
180
+ const ts = cuts.map((c) => (typeof c === 'number' ? c : c.t));
181
+ const { density, bins, meanRate } = densityCurve({ duration, cuts: ts, window, max });
182
+ if (meanRate === 0) return [];
183
+ const bursts = [];
184
+ let start = -1;
185
+ for (let i = 0; i <= bins; i++) {
186
+ const hot = i < bins && density[i] > 1.5;
187
+ if (hot && start < 0) start = i;
188
+ if (!hot && start >= 0) {
189
+ const to = +Math.min(duration, i * BIN).toFixed(2);
190
+ const from = +(start * BIN).toFixed(2);
191
+ bursts.push({
192
+ from,
193
+ to,
194
+ density: +density[start].toFixed(2),
195
+ // 这一小段里切了几刀 —— 只有密度数字时,模型还得自己反推"到底几个镜头"
196
+ shots: ts.filter((t) => t >= from && t < to).length,
197
+ });
198
+ start = -1;
199
+ }
200
+ }
201
+ return bursts;
202
+ }
203
+
204
+ /**
205
+ * 把 [0, duration] 切成 cells 段,使每段承载的"密度积分"相等。
206
+ * 切点会尝试吸附到真实剪辑点,但**位移超过理想格长的 30% 就放弃吸附**——
207
+ * 否则吸附会把权重分配整个打乱(实测踩过:全片都被拉到剪辑点上,格长变得不均匀)。
208
+ *
209
+ * @returns {Array<{from:number,to:number,density:number,dur:number}>}
210
+ */
211
+ export function planCellRanges({
212
+ duration, cuts = [], cells, bin = BIN, window = RATE_WINDOW, max = MAX_DENSITY,
213
+ snap = 2.0, snapRatio = 0.3, minLen = 0.3, speech, audioEvents = [], scoreDensity,
214
+ } = {}) {
215
+ if (!(duration > 0)) throw new RangeError(`duration must be > 0, got ${duration}`);
216
+ if (!Number.isInteger(cells) || cells < 1) throw new RangeError(`cells must be a positive integer, got ${cells}`);
217
+
218
+ // 密度来源二选一:
219
+ // 默认走「切点计数」(densityCurve),保留了多年的行为;
220
+ // 传了 scoreDensity 就走「画面变化率」(densityFromScore)。
221
+ // 后者在三个一镜到底的真实素材上量过,格长离散度 0.53/0.52/0.26 → 0.33/0.36/0.21,
222
+ // 而且不依赖切点检得准不准 —— 误报 3 个切点也造不出密度尖峰。
223
+ const { density, bins } = scoreDensity
224
+ ? { density: Float64Array.from(scoreDensity.density), bins: scoreDensity.bins }
225
+ : densityCurve({ duration, cuts, bin, window, max, speech });
226
+
227
+ // 声音事件加权:突然变响/突然安静的地方,画面往往没变但事情发生了,
228
+ // 给它 ±1 秒的密度加成,让边界往那儿靠(权重保守,1.6 倍,避免盖过画面信号)。
229
+ for (const e of audioEvents) {
230
+ const center = Math.round(e.t / bin);
231
+ const half = Math.round(1.0 / bin);
232
+ for (let i = Math.max(0, center - half); i < Math.min(bins, center + half); i++) {
233
+ density[i] = Math.min(max, density[i] * 1.6);
234
+ }
235
+ }
236
+ const cum = new Float64Array(bins + 1);
237
+ for (let i = 0; i < bins; i++) cum[i + 1] = cum[i] + density[i] * bin;
238
+ const total = cum[bins] || duration;
239
+ const idealLen = duration / cells;
240
+
241
+ const candidates = [...cuts].filter((c) => c > 0 && c < duration).sort((a, b) => a - b);
242
+ const snapTo = (t, limit) => {
243
+ let best = t;
244
+ let bestD = Infinity;
245
+ for (const c of candidates) {
246
+ const d = Math.abs(c - t);
247
+ if (d < bestD) { best = c; bestD = d; }
248
+ }
249
+ return bestD <= Math.min(limit, snap) ? best : t;
250
+ };
251
+
252
+ const bounds = [0];
253
+ for (let j = 1; j < cells; j++) {
254
+ const target = (total * j) / cells;
255
+ let lo = 0;
256
+ let hi = bins;
257
+ while (lo < hi) {
258
+ const mid = (lo + hi) >> 1;
259
+ if (cum[mid] < target) lo = mid + 1; else hi = mid;
260
+ }
261
+ let t = Math.min(duration, Math.max(0, lo * bin));
262
+ t = snapTo(t, idealLen * snapRatio);
263
+ t = Math.max(t, bounds.at(-1) + minLen);
264
+ t = Math.min(t, duration - minLen * (cells - bounds.length));
265
+ if (t > bounds.at(-1)) bounds.push(t);
266
+ }
267
+ bounds.push(duration);
268
+
269
+ const ranges = [];
270
+ for (let i = 0; i < bounds.length - 1; i++) {
271
+ const from = bounds[i];
272
+ const to = bounds[i + 1];
273
+ const idx = Math.min(bins - 1, Math.floor(((from + to) / 2) / bin));
274
+ ranges.push({ from, to, density: +density[idx].toFixed(2), dur: to - from });
275
+ }
276
+ return ranges;
277
+ }
278
+
279
+ /**
280
+ * 按**镜头数**均分时间段,而不是按时间或密度积分。
281
+ *
282
+ * 为什么比"密度积分等分"更对:
283
+ * 密度积分保证每格承载相同的"变化量",但慢镜头的变化量低,
284
+ * 于是一段 3 分钟的慢戏可能只分到 1 格 —— 里面全是"几乎一样的画面",
285
+ * 而一段 20 秒的快剪分到 2 格。观众想看的恰恰是慢戏里的细节。
286
+ *
287
+ * 按镜头数均分则是:**每格装同样多的镜头**。
288
+ * 慢段:10 个镜头要 50 秒 → 这一段就占 50 秒
289
+ * 快段:10 个镜头只要 5 秒 → 这一段就占 5 秒
290
+ * 段长天然与镜头密度成反比,不需要再调参。
291
+ *
292
+ * 每段内部再由 chooseSubGrid 决定摊开几张:镜头多的段摊 3×3/4×4,
293
+ * 镜头少的段(1~2 个)整格一张 —— 慢镜头因此拿到"格内最大"的画面。
294
+ *
295
+ * @param {{cuts:number[], duration:number, cells:number}} opts
296
+ * @returns {Array<{from:number,to:number,dur:number,shots:number}>}
297
+ */
298
+ export function planByShotCount({ cuts = [], duration, cells } = {}) {
299
+ if (!(duration > 0)) throw new RangeError(`duration must be > 0, got ${duration}`);
300
+ if (!Number.isInteger(cells) || cells < 1) throw new RangeError(`cells must be a positive integer, got ${cells}`);
301
+
302
+ // 镜头边界:[0, ...切点..., duration]
303
+ const marks = [0, ...cuts.filter((c) => c > 0 && c < duration).sort((a, b) => a - b), duration];
304
+ const shots = marks.length - 1;
305
+ if (shots <= cells) {
306
+ // 镜头比格子还少:一个镜头一格,多出来的格子不硬塞(调用方按实际长度处理)
307
+ return marks.slice(0, -1).map((from, i) => ({
308
+ from, to: marks[i + 1], dur: marks[i + 1] - from, shots: 1,
309
+ density: +(1 / Math.max(0.1, marks[i + 1] - from)).toFixed(2),
310
+ }));
311
+ }
312
+
313
+ // 每格 targetShots 个镜头;除不尽的把余数摊到前面几格
314
+ const base = Math.floor(shots / cells);
315
+ const extra = shots % cells;
316
+ const out = [];
317
+ let k = 0;
318
+ for (let i = 0; i < cells; i++) {
319
+ const n = base + (i < extra ? 1 : 0);
320
+ if (n <= 0) continue;
321
+ const from = marks[k];
322
+ const to = marks[k + n];
323
+ out.push({ from, to, dur: to - from, shots: n, density: +(n / Math.max(0.1, to - from)).toFixed(2) });
324
+ k += n;
325
+ }
326
+ return out;
327
+ }
328
+
329
+ /**
330
+ * **rodt 函数** —— 每格长度 = 常数 ÷ 该处的切点密度。
331
+ *
332
+ * 密度 A(刀/秒)越大 → 每格长度 B 越短,B = K / A。这是最直觉的关系:
333
+ * 一分钟切 30 刀的地方,一格放 2 秒就够;一分钟才切 1 刀的地方,一格放 60 秒也不算长。
334
+ *
335
+ * 和 `planCellRanges` 的区别在这里:
336
+ * - `planCellRanges` 把密度夹到 [1, 2.5] 倍(MAX_DENSITY),且算的是**相对全片平均**的倍数。
337
+ * 结果最密的地方和最疏的地方最多只差 2.5 倍 —— 实测段长 8.5~21.1s,拉不开。
338
+ * - 这里用**绝对密度**、不做上限夹取(只兜一个下限防止除零),
339
+ * 所以快段和慢段能差十几倍,正好对应"快切要细、长镜头要粗"。
340
+ *
341
+ * 实现上用"累积密度等分":∫density·dt 每段相等 → 段长 L = C/density,天然就是 1/A。
342
+ * 不用逐点算 1/A 再累加(那反而会算成 L ∝ A,方向是反的)。
343
+ *
344
+ * @param {{cuts:number[], duration:number, cells:number,
345
+ * window?:number, minDensity?:number, snapTo?:number}} opts
346
+ * window 算局部密度的观察半径(秒)
347
+ * minDensity 密度下限(刀/秒),防止长时间无切点时除零
348
+ * snapTo 段长吸附粒度(秒):数据是离散的,掐到 0.5 秒的整数倍便于对齐
349
+ * @returns {Array<{from:number,to:number,dur:number,density:number,shots:number}>}
350
+ */
351
+ export function planByRodt({
352
+ cuts = [], duration, cells, window = 5, minDensity = 0.02, snapTo = 0.5, maxDensity = 20,
353
+ } = {}) {
354
+ if (!(duration > 0)) throw new RangeError(`duration must be > 0, got ${duration}`);
355
+ if (!Number.isInteger(cells) || cells < 1) throw new RangeError(`cells must be a positive integer, got ${cells}`);
356
+
357
+ const marks = cuts.filter((c) => c > 0 && c < duration).sort((a, b) => a - b);
358
+ const shots = marks.length + 1;
359
+ if (shots <= cells) {
360
+ const bounds = [0, ...marks, duration];
361
+ return bounds.slice(0, -1).map((from, i) => {
362
+ const to = bounds[i + 1];
363
+ return { from, to, dur: to - from, density: +(1 / Math.max(0.1, to - from)).toFixed(2), shots: 1 };
364
+ });
365
+ }
366
+
367
+ // 1) 累积密度:cum(t) = 从 0 到 t 一共"切了多少刀"
368
+ // 用累积而不是逐点密度,是为了让等分等价于 ∫density·dt 相等。
369
+ const cum = (t) => marks.filter((c) => c <= t).length;
370
+ // 2) 找 cells-1 个内点,让每段的"切点数"尽可能相等
371
+ // (切点数相等 = 密度积分相等 → 段长 ∝ 1/密度)
372
+ const targets = [];
373
+ for (let j = 1; j < cells; j++) targets.push((marks.length * j) / cells);
374
+
375
+ const bounds = [0];
376
+ for (const tgt of targets) {
377
+ // 3) 离散化:边界直接落在**切点**上。
378
+ // 切点本身就是离散的(0.01 秒精度),再吸附到 0.5 秒反而会把边界挪离切点,
379
+ // 导致一段里跨进半个镜头 —— 那正是"每格装多少镜头"失准的原因。
380
+ const idx = Math.min(marks.length - 1, Math.max(0, Math.round(tgt)));
381
+ let t = marks[idx] ?? duration;
382
+ t = Math.max(t, bounds.at(-1) + (snapTo > 0 ? snapTo : 0.01));
383
+ t = Math.min(t, duration - snapTo * (cells - bounds.length));
384
+ if (t > bounds.at(-1)) bounds.push(t);
385
+ }
386
+ bounds.push(duration);
387
+
388
+ return bounds.slice(0, -1).map((from, i) => {
389
+ const to = bounds[i + 1];
390
+ const n = cum(to) - cum(from) + 1;
391
+ return {
392
+ from, to, dur: +(to - from).toFixed(2),
393
+ density: +(n / Math.max(0.1, to - from)).toFixed(2),
394
+ shots: n,
395
+ };
396
+ });
397
+ }
398
+
399
+ /**
400
+ * **sheet 的边界直接由切点决定** —— 这是"按密度积分"最直接的写法。
401
+ *
402
+ * 思路:沿时间轴走,每累积 `shotsPerWindow` 个切点就划一张图。
403
+ * 因为密度高的地方攒够 N 个切点用的时间短,密度低的地方用得长,
404
+ * 所以每张覆盖的时长自动就是 B = K / A(A 是局部切点密度),不用再单独算。
405
+ *
406
+ * 边界不落在切点上,而是取**相邻两个切点的加权平均**:
407
+ * 直接切在切点上会把一个镜头劈成两半(前一张尾巴、后一张开头各半截),
408
+ * 取中间位置能保证每张都以完整镜头开始和结束。
409
+ *
410
+ * @param {{cuts:number[], duration:number, shotsPerWindow?:number}} opts
411
+ * @returns {Array<{from:number, to:number}>}
412
+ */
413
+ export function planSheetWindows({ cuts = [], duration, shotsPerWindow = 40 } = {}) {
414
+ if (!(duration > 0)) throw new RangeError(`duration must be > 0, got ${duration}`);
415
+ const marks = [...cuts].filter((c) => c > 0 && c < duration).sort((a, b) => a - b);
416
+ if (marks.length < shotsPerWindow) return [{ from: 0, to: duration }];
417
+
418
+ const windows = [];
419
+ let start = 0;
420
+ for (let i = shotsPerWindow - 1; i < marks.length; i += shotsPerWindow) {
421
+ const a = marks[i];
422
+ const b = marks[i + 1] ?? duration;
423
+ const mid = a + (b - a) * 0.5; // 加权平均,避开转场正中
424
+ if (mid <= start || mid >= duration) continue;
425
+ windows.push({ from: start, to: mid });
426
+ start = mid;
427
+ }
428
+ if (start < duration) windows.push({ from: start, to: duration });
429
+ return windows;
430
+ }
431
+
432
+ /**
433
+ * **按「累计画面帧数」切 sheet** —— 流程的最后一步。
434
+ *
435
+ * 为什么不能用"时间"或"格数"来切:
436
+ * - 按时间切:快剪段和长镜头段拿到一样长的图,前者塞不下、后者太空
437
+ * - 按格数切:一格不摊是 1 帧、摊 3×3 是 9 帧,格数一样但信息量差 9 倍
438
+ *
439
+ * 正确做法是先把画面**排好**(rodt 分格 + 每格决定摊几×几),
440
+ * 再沿时间累加每个格点贡献的帧数(k²),累到预算就切一张。
441
+ * 因为切的是**格点边界**,而格点边界本来就在切点上,所以两张之间天然衔接、不断裂:
442
+ * 上一张最后一个切点就是下一张的起点。
443
+ *
444
+ * @param {Array<{from:number,to:number,k?:number}>} cells 已排好的格点(时序)
445
+ * @param {{frameBudget?:number, maxCellsPerSheet?:number}} opts
446
+ * frameBudget 一张图累计多少帧就切(建议 64)
447
+ * maxCellsPerSheet 单张最多几个大格点(布局上限,默认 16)
448
+ * @returns {Array<Array>} 每个元素是一张 sheet 的格点数组
449
+ */
450
+ export function planSheetsByFrames(cells, { frameBudget = 64, maxCellsPerSheet = 16 } = {}) {
451
+ if (!Array.isArray(cells)) throw new TypeError('cells must be an array');
452
+ if (cells.length === 0) return [];
453
+ const framesOf = (c) => Math.max(1, (c.k ?? 1) ** 2);
454
+ const totalFrames = cells.reduce((n, c) => n + framesOf(c), 0);
455
+
456
+ // **先算要几张,再把帧数均摊。**
457
+ // 旧写法是"装满再切"(贪心),最后一张常常只剩一两格:实测 250 秒素材跑出
458
+ // 第 1 张 16 格、第 2 张 2 格 → 2 格按 bestLayout 排成 1×2(715×843 的竖长条),
459
+ // 两个格子各占 707×396,等于两张图只看了两个画面。
460
+ // 均摊之后每张的帧数接近,张数不变但形状正常。
461
+ const count = Math.max(
462
+ 1,
463
+ Math.ceil(totalFrames / Math.max(1, frameBudget)),
464
+ Math.ceil(cells.length / Math.max(1, maxCellsPerSheet)),
465
+ );
466
+ const target = totalFrames / count;
467
+
468
+ const sheets = [];
469
+ let cur = [];
470
+ let acc = 0;
471
+ const flush = () => { if (cur.length) { sheets.push(cur); cur = []; acc = 0; } };
472
+
473
+ for (let i = 0; i < cells.length; i++) {
474
+ const frames = framesOf(cells[i]);
475
+ const left = count - sheets.length; // 还差几张(含正在装的这张)
476
+ const rest = cells.length - i; // 还没装进去的格数(含当前这一格)
477
+ // 这一格塞进去会明显超过本张的目标,且剩下的格数还够后面每张至少分一格 → 切。
478
+ // 10% 的余量是给"一格 16 帧、目标是 12"这种整数边界留的,不然会切得太碎。
479
+ const over = acc + frames > target * 1.1;
480
+ if (cur.length > 0 && rest >= left && (over || cur.length >= maxCellsPerSheet)) flush();
481
+ cur.push(cells[i]);
482
+ acc += frames;
483
+ }
484
+ flush();
485
+ return sheets;
486
+ }
487
+
488
+ /**
489
+ * **积分采样点(假切点)** —— 沿时间累加画面变化率,累够阈值就记一个点、然后清零。
490
+ *
491
+ * 为什么放在"扫描之后"而不是"取帧的时候":取帧那一层只知道"这一格要几张",
492
+ * 而这里能拿到**全片的逐帧分数**。把触发点当成额外的切点交给下游,
493
+ * rodt 分格、二重细分、取帧全部原样复用 —— 不需要新的一套采样器。
494
+ *
495
+ * 阈值怎么定:`T = 全片平均每秒变化量 × equivSeconds`。
496
+ * 所以每个采样点代表"约 equivSeconds 秒的平均变化":
497
+ * - 长时间静止的段落永远累积不到 T → 一个点都不加 → 那一格还是一张整帧;
498
+ * - 摇镜/推拉/连续动作的地方会连续触发 → 那一段自然被切成几块、多取几张。
499
+ * **它是唯一真正自由的旋钮**:音频驱动(音乐片信息全在画面上)就是把 equivSeconds 调小。
500
+ *
501
+ * 两条必须的排除:
502
+ * 1. 真切点附近不补点 —— 真切点本身就是边界,再补一个是重复;
503
+ * 2. 两个点之间至少 minGap 秒 —— 一次爆发里的连续触发会挤成一堆。
504
+ *
505
+ * 注意:这些点**只用于"格内怎么取帧"**,不并进 `cuts`。清单里的"切点 N 个"必须是真切点,
506
+ * 否则模型会以为那些地方有硬切 —— 假切点描述的是"这里变化攒够了",不是"这里是一刀"。
507
+ *
508
+ * @param {{duration:number, series:Array<{t:number,score:number}>, cuts?:number[],
509
+ * start?:number, equivSeconds?:number, minGap?:number, skipNearCut?:number}} opts
510
+ * @returns {number[]} 采样时刻(绝对秒,升序)
511
+ */
512
+ export function integralMarks({
513
+ duration, series = [], cuts = [], start = 0,
514
+ equivSeconds = 6, minGap = 0.8, skipNearCut = 0.35,
515
+ } = {}) {
516
+ if (!(duration > 0)) throw new RangeError(`duration must be > 0, got ${duration}`);
517
+ const pts = (Array.isArray(series) ? series : [])
518
+ .filter((s) => Number.isFinite(s?.t) && s.t >= start && s.t < start + duration)
519
+ .sort((a, b) => a.t - b.t);
520
+ const real = [...cuts].filter((c) => Number.isFinite(c)).sort((a, b) => a - b);
521
+ // **真切点附近的分不参与累加**。那一帧的分数是"跨过这一刀"的差值(实测 40~100),
522
+ // 比一次摇镜高一两个数量级;混进来会把阈值抬到"只有连续动作狂甩才够",
523
+ // 于是这批切点密的地方一个采样点都加不出来。真切点本来就自带边界,不需要再补。
524
+ const clean = pts.filter((s) => !real.some((c) => Math.abs(c - s.t) < skipNearCut));
525
+ const total = clean.reduce((acc, s) => acc + Math.max(0, Number(s.score) || 0), 0);
526
+ if (!(total > 0)) return [];
527
+
528
+ // 全片平均每秒变化量 × equivSeconds。用全片均值当基准,换素材不用重新调参。
529
+ const T = (total / duration) * equivSeconds;
530
+ if (!(T > 0)) return [];
531
+
532
+ const out = [];
533
+ let acc = 0;
534
+ let last = -Infinity;
535
+ for (const p of clean) {
536
+ acc += Math.max(0, Number(p.score) || 0);
537
+ if (acc < T) continue;
538
+ acc = 0; // 触发即清零
539
+ if (p.t - last < minGap) continue;
540
+ if (real.some((c) => Math.abs(c - p.t) < skipNearCut)) continue;
541
+ out.push(+p.t.toFixed(3));
542
+ last = p.t;
543
+ }
544
+ return out;
545
+ }