dsh-chat-comprehension 0.2.0 → 0.3.1

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 +41 -9
  4. package/lib/engines.mjs +136 -0
  5. package/lib/index.js +54 -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 +3293 -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,106 @@
1
+ /**
2
+ * media-store.js — 「下载到哪、占多大、什么时候删」。
3
+ *
4
+ * 从 fetch.js 拆出来的。落盘那份低清全片是"后面随便跳"的入场费(见 fetch.js 头部的实测),
5
+ * 于是它就成了一份需要**自己管自己**的缓存:有容量上限、有 LRU 淘汰、有磁盘余量检查。
6
+ * 这些和"怎么把 URL 变成本地文件"是两件事,出错时查的地方也不同。
7
+ */
8
+
9
+ import { createHash } from 'node:crypto';
10
+ import { access, readdir, rm, stat } from 'node:fs/promises';
11
+ import { constants } from 'node:fs';
12
+ import { tmpdir } from 'node:os';
13
+ import { join } from 'node:path';
14
+
15
+ /** 文件在不在、可不可读。**一行一个坑**:裸 access() 抛异常,用 try 包住才是判断而不是报错。 */
16
+ export async function fileExists(path) {
17
+ try {
18
+ await access(path, constants.R_OK);
19
+ return true;
20
+ } catch {
21
+ return false;
22
+ }
23
+ }
24
+
25
+ export const MEDIA_ENV = 'DSH_VIDEO_MEDIA_DIR';
26
+ export const MEDIA_MAX_MB_ENV = 'DSH_VIDEO_MEDIA_MAX_MB';
27
+ export const DEFAULT_MEDIA_MAX_MB = 300;
28
+
29
+ /* ------------------------------------------------------------------ 媒体缓存 */
30
+
31
+ export function mediaDir(env = process.env) {
32
+ return env[MEDIA_ENV] || join(tmpdir(), 'dsh-video-storyboard', 'media');
33
+ }
34
+
35
+ export function mediaMaxBytes(env = process.env) {
36
+ const mb = Number(env[MEDIA_MAX_MB_ENV]);
37
+ return (Number.isFinite(mb) && mb > 0 ? mb : DEFAULT_MEDIA_MAX_MB) * 1024 * 1024;
38
+ }
39
+
40
+ /** 缓存键:归一化链接 + 落盘清晰度。**路径必须稳定**,否则下游的 sha1(路径+窗口) 会全部失效。 */
41
+ export function mediaKey(normalizedUrl, height) {
42
+ return createHash('sha1').update(`${normalizedUrl}|${height}`).digest('hex').slice(0, 20);
43
+ }
44
+
45
+ async function dirSize(dir) {
46
+ let total = 0;
47
+ let newest = 0;
48
+ let entries = [];
49
+ try {
50
+ entries = await readdir(dir, { withFileTypes: true });
51
+ } catch {
52
+ return { total: 0, newest: 0 };
53
+ }
54
+ for (const entry of entries) {
55
+ const path = join(dir, entry.name);
56
+ try {
57
+ const st = await stat(path);
58
+ total += st.size;
59
+ newest = Math.max(newest, st.mtimeMs);
60
+ } catch { /* 忽略 */ }
61
+ }
62
+ return { total, newest };
63
+ }
64
+
65
+ /**
66
+ * 超限就**按 mtime 从旧到新**删整个 `<key>/` 目录。
67
+ * 单个目录一起删,不留半个视频——否则下次会命中一个没有 video.mp4 的空壳。
68
+ */
69
+ export async function pruneMedia({ dir = mediaDir(), maxBytes = mediaMaxBytes() } = {}) {
70
+ let entries = [];
71
+ try {
72
+ entries = await readdir(dir, { withFileTypes: true });
73
+ } catch {
74
+ return { removed: 0, bytes: 0 };
75
+ }
76
+ const dirs = [];
77
+ for (const entry of entries) {
78
+ if (!entry.isDirectory()) continue;
79
+ const path = join(dir, entry.name);
80
+ const { total, newest } = await dirSize(path);
81
+ if (total > 0) dirs.push({ path, size: total, at: newest });
82
+ }
83
+ dirs.sort((a, b) => a.at - b.at);
84
+ let total = dirs.reduce((n, d) => n + d.size, 0);
85
+ let removed = 0;
86
+ for (const d of dirs) {
87
+ if (total <= maxBytes) break;
88
+ try {
89
+ await rm(d.path, { recursive: true, force: true });
90
+ total -= d.size;
91
+ removed += 1;
92
+ } catch { /* 忽略 */ }
93
+ }
94
+ return { removed, bytes: total };
95
+ }
96
+
97
+ /** 磁盘剩余空间(字节)。拿不到就返回 null,由调用方决定是否放行。 */
98
+ export async function freeBytes() {
99
+ try {
100
+ const { statfs } = await import('node:fs/promises');
101
+ const s = await statfs(tmpdir());
102
+ return Number(s.bavail) * Number(s.bsize);
103
+ } catch {
104
+ return null;
105
+ }
106
+ }
@@ -0,0 +1,94 @@
1
+ /**
2
+ * memory.js — "这个文件我看过,看到哪了"
3
+ *
4
+ * 缓存(cache.js)按 (路径, 大小, mtime, 窗口, 阈值) 存扫描与 ASR 结果,回答的是
5
+ * **"这一段的账算过没有"**。它回答不了"这部片子我是不是看过、看了哪一段"——
6
+ * 换个窗口、隔一天、换一个对话,全部重来,于是 agent 会把同一部片子重新描述一遍。
7
+ *
8
+ * 这里记的是最轻的一层事实:哪个文件、哪一段、多少格、多少刀、什么时候。
9
+ * **不存模型输出**(那是调用方的职责),只存能证明"看过"的机械指标——
10
+ * 也正因如此,它不会把上一次的结论当成事实带进新对话。
11
+ */
12
+
13
+ import { appendFile, readFile, writeFile } from 'node:fs/promises';
14
+ import { join } from 'node:path';
15
+
16
+ import { cacheDir } from './cache.js';
17
+
18
+ const FILE = 'seen.jsonl';
19
+ const MAX_LINES = 400;
20
+
21
+ const norm = (p) => String(p ?? '').replace(/\\/g, '/').toLowerCase();
22
+
23
+ export function memoryPath(env = process.env) {
24
+ return join(cacheDir(env), FILE);
25
+ }
26
+
27
+ /**
28
+ * 记一笔。失败就算了——记忆是锦上添花,不该让主流程挂掉。
29
+ *
30
+ * @param {{path?:string, duration?:number}} info probe 的结果
31
+ * @param {{from:number, to:number, cells:number, cuts:number}} look 这一次看了什么
32
+ */
33
+ export async function remember(info, look, { env = process.env, at = Date.now() } = {}) {
34
+ if (!info?.path) return;
35
+ const rec = {
36
+ path: norm(info.path),
37
+ duration: +(info.duration ?? 0).toFixed(2),
38
+ from: +Number(look.from ?? 0).toFixed(2),
39
+ to: +Number(look.to ?? info.duration ?? 0).toFixed(2),
40
+ cells: look.cells ?? 0,
41
+ cuts: look.cuts ?? 0,
42
+ at,
43
+ };
44
+ try {
45
+ await appendFile(memoryPath(env), `${JSON.stringify(rec)}\n`, 'utf8');
46
+ await prune(env);
47
+ } catch { /* 磁盘满 / 没权限:静默 */ }
48
+ }
49
+
50
+ /** 读到这个文件的所有历史记录(按时间倒序)。 */
51
+ export async function recall(info, { env = process.env } = {}) {
52
+ if (!info?.path) return { entries: [], lastAt: null, windows: 0 };
53
+ try {
54
+ const raw = await readFile(memoryPath(env), 'utf8');
55
+ const key = norm(info.path);
56
+ const entries = raw.split('\n').filter(Boolean)
57
+ .map((l) => { try { return JSON.parse(l); } catch { return null; } })
58
+ .filter((r) => r && r.path === key)
59
+ .sort((a, b) => b.at - a.at);
60
+ return {
61
+ entries,
62
+ lastAt: entries[0]?.at ?? null,
63
+ windows: new Set(entries.map((e) => `${e.from}-${e.to}`)).size,
64
+ };
65
+ } catch {
66
+ return { entries: [], lastAt: null, windows: 0 };
67
+ }
68
+ }
69
+
70
+ /** 只保留最近 MAX_LINES 条,避免无限长。 */
71
+ async function prune(env) {
72
+ try {
73
+ const raw = await readFile(memoryPath(env), 'utf8');
74
+ const lines = raw.split('\n').filter(Boolean);
75
+ if (lines.length <= MAX_LINES) return;
76
+ await writeFile(memoryPath(env), `${lines.slice(-MAX_LINES).join('\n')}\n`, 'utf8');
77
+ } catch { /* 忽略 */ }
78
+ }
79
+
80
+ /**
81
+ * 给清单用的一句话:"看过 2 段,上次 2026-10-27 23:10"。
82
+ * 只在**确实看过**时返回,否则 null —— 没看过就不该占字符。
83
+ */
84
+ export async function describeMemory(info, { env = process.env } = {}) {
85
+ const m = await recall(info, { env });
86
+ if (!m.windows) return null;
87
+ const d = new Date(m.lastAt);
88
+ const pad = (n) => String(n).padStart(2, '0');
89
+ const when = `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ` +
90
+ `${pad(d.getHours())}:${pad(d.getMinutes())}`;
91
+ const ranges = [...new Set(m.entries.map((e) => `${e.from}-${e.to}s`))].slice(0, 4).join(', ');
92
+ return `${m.windows} window(s) analysed before (${ranges}), last on ${when}. ` +
93
+ 'If you already described this file, cite that instead of describing it again.';
94
+ }
@@ -0,0 +1,107 @@
1
+ /**
2
+ * ocr-subs.js — 用画面硬字幕**校正 ASR 文本**(只在 detail=high 时开)。
3
+ *
4
+ * 从 pipeline.js 拆出来的。它是唯一一条"读像素来改文字"的路径,
5
+ * 失败方式(没装 rapidocr / 检测不到字幕带 / 相似度不够)和转写本身完全不同,
6
+ * 混在编排里既难查也难单独关。
7
+ *
8
+ * 硬约束:三条都成立才替换(置信度够 / 长度差不多 / 相似度在 0.2–0.9)。
9
+ * 剩下的一律保留 ASR 原文 —— 宁可留一个已知的错字,也不要引入一个来源不明的句子。
10
+ */
11
+
12
+ import { mkdtemp, rm } from 'node:fs/promises';
13
+ import { tmpdir } from 'node:os';
14
+ import { join } from 'node:path';
15
+ import { execFile } from 'node:child_process';
16
+ import { promisify } from 'node:util';
17
+
18
+ import { detectSubtitleBand, OCR_MAX_ITEMS, ocrPython, readBand, shouldReplace } from './ocr.js';
19
+
20
+ const runFile = promisify(execFile);
21
+
22
+ /**
23
+ * 用画面硬字幕校正 ASR。流程刻意分两步,因为检测是最贵的一环:
24
+ * ① 抽 2–3 张**原分辨率**帧做一次全图检测,定出字幕带 (≈3 s)
25
+ * ② 对若干条台词,只裁那一条带子做识别(不做检测) (≈0.26 s/条)
26
+ *
27
+ * 只有三条都成立才替换(见 shouldReplace):OCR 置信度够、长度差不多、相似度落在 0.2–0.9。
28
+ * 剩下的情况一律保留 ASR 原文 —— 宁可留一个已知的错字,也不要引入一个来源不明的句子。
29
+ */
30
+ export async function correctByOnScreenSubs({
31
+ input, winStart, winDur, ffmpegPath, segments, remoteFrame, sourceCopyHeight = null,
32
+ }) {
33
+ // 直链是另一套取帧路径(带 header),第一版不做 —— 明确说"跳过",而不是悄悄不生效
34
+ if (remoteFrame?.uri) return { status: 'skipped', reason: 'remote-frame-source' };
35
+ const python = await ocrPython();
36
+ if (!python) return { status: 'skipped', reason: 'no-python-with-rapidocr' };
37
+
38
+ const dir = await mkdtemp(join(tmpdir(), 'dsh-ocr-'));
39
+ try {
40
+ const grab = async (at, outName, crop) => {
41
+ const out = join(dir, outName);
42
+ const args = ['-hide_banner', '-v', 'error', '-y', '-ss', String(Math.max(0, at)), '-i', input,
43
+ '-frames:v', '1', '-q:v', '2'];
44
+ if (crop) args.push('-vf', crop);
45
+ args.push(out);
46
+ await runFile(ffmpegPath, args);
47
+ return out;
48
+ };
49
+
50
+ // ① 定字幕带:取窗口内均匀分布的 3 个时刻
51
+ const probes = await Promise.all([0.2, 0.5, 0.8].map((r, i) => grab(
52
+ winStart + winDur * r, `probe${i}.jpg`, null,
53
+ )));
54
+ const band = await detectSubtitleBand({ python, frames: probes });
55
+ if (!band) return { status: 'failed', reason: 'detect-failed' };
56
+
57
+ const [y0, y1] = band.band;
58
+ const crop = `crop=iw:ih*${(y1 - y0).toFixed(4)}:0:ih*${y0.toFixed(4)},scale=1280:-1`;
59
+
60
+ // ② 均匀抽样若干条台词(不取全部,成本与收益不成正比)
61
+ const picks = [];
62
+ const n = Math.min(OCR_MAX_ITEMS, segments.length);
63
+ const step = segments.length / n;
64
+ for (let i = 0; i < n; i += 1) picks.push(Math.floor(i * step));
65
+
66
+ const images = [];
67
+ for (const [k, idx] of picks.entries()) {
68
+ const seg = segments[idx];
69
+ const mid = winStart + (seg.from + seg.to) / 2;
70
+ images.push(await grab(mid, `band${k}.jpg`, crop));
71
+ }
72
+ const items = await readBand({ python, images });
73
+ if (!items) return { status: 'failed', reason: 'read-failed' };
74
+
75
+ const out = segments.map((x) => ({ ...x }));
76
+ const changes = [];
77
+ for (const [k, idx] of picks.entries()) {
78
+ const seg = segments[idx];
79
+ const ocrText = (items[k]?.text ?? '').replace(/\s+/g, '');
80
+ const verdict = shouldReplace({ asr: seg.text, ocr: ocrText, conf: items[k]?.conf ?? 0 });
81
+ if (process.env.DSH_OCR_DEBUG) {
82
+ console.error('[ocr]', seg.from.toFixed(1), JSON.stringify(seg.text), '| ocr:', JSON.stringify(ocrText),
83
+ '| conf', items[k]?.conf, '|', verdict.reason, verdict.cover ?? '');
84
+ }
85
+ if (verdict.replace) {
86
+ const fixedText = verdict.text ?? ocrText;
87
+ changes.push({ from: seg.from, was: seg.text, now: fixedText, cover: verdict.cover });
88
+ out[idx] = { ...seg, text: fixedText };
89
+ }
90
+ }
91
+ return {
92
+ status: 'applied',
93
+ fixed: changes.length,
94
+ checked: picks.length,
95
+ band: { y0: +y0.toFixed(3), y1: +y1.toFixed(3), detected: band.detected },
96
+ // URL 模式下跑的是下载的扫描副本:字幕本身就糊,校正的可信度低于本地高清文件。
97
+ // 这个事实必须传到清单,否则读起来像"原片台词已核对"。
98
+ ...(sourceCopyHeight
99
+ ? { basedOn: 'low-res-copy', copyHeight: sourceCopyHeight }
100
+ : { basedOn: 'source' }),
101
+ changes: changes.slice(0, 5),
102
+ segments: out,
103
+ };
104
+ } finally {
105
+ await rm(dir, { recursive: true, force: true }).catch(() => {});
106
+ }
107
+ }
@@ -0,0 +1,167 @@
1
+ /**
2
+ * ocr.js — 用画面上的硬字幕校正语音转写。
3
+ *
4
+ * 为什么需要:ASR 会听错专有名词(实测「像差」→「相差」、「也要忘记吗」→「他也忘记」),
5
+ * 而画面里烧进去的字幕是**确定的文本**。两者对不上时,画面更可信。
6
+ *
7
+ * 为什么不是"让模型自己看图":模型看到的格子是 331×184,实测同一句字幕在那一档会掉字
8
+ * ("也要忘记吗" → "也要记"),而且它只看得到 9–20 帧,覆盖不了全片。OCR 是在原分辨率上做的。
9
+ *
10
+ * 为什么走 Python:中文 OCR 的现成实现(rapidocr)在 Python 侧。用一次 subprocess 换 JSON,
11
+ * 比在 Node 里重造一套现实得多。**没装就跳过**,不报错、不影响出图。
12
+ */
13
+
14
+ import { execFile } from 'node:child_process';
15
+ import { dirname, join } from 'node:path';
16
+ import { fileURLToPath } from 'node:url';
17
+
18
+ import { findPython } from './python.js';
19
+
20
+ const HERE = dirname(fileURLToPath(import.meta.url));
21
+
22
+ /** 单次最多校正多少条 —— 每条要解一次 ffmpeg、跑一次 OCR,太多就不划算了 */
23
+ export const OCR_MAX_ITEMS = 16;
24
+
25
+ /**
26
+ * 找一台能 `import rapidocr_onnxruntime` 的 python。
27
+ *
28
+ * 早期版本在这里硬编码了开发机的 `.venv` 路径 —— 跟着包发出去,别人的机器上永远找不到,
29
+ * 于是"OCR 校正"对所有人都是静默跳过。现在统一走 python.js 的候选链 + 实际 import 验证。
30
+ */
31
+ export async function ocrPython({ config = {}, env = process.env } = {}) {
32
+ return findPython('rapidocr_onnxruntime', { config, env });
33
+ }
34
+
35
+ function runBridge({ python, mode, images, timeoutMs = 120_000 }) {
36
+ const bridge = join(HERE, 'ocr_bridge.py');
37
+ return new Promise((resolve) => {
38
+ execFile(python, [bridge, mode, ...images], {
39
+ timeout: timeoutMs,
40
+ maxBuffer: 8 * 1024 * 1024,
41
+ windowsHide: true,
42
+ env: { ...process.env, PYTHONIOENCODING: 'utf-8', PYTHONUTF8: '1' },
43
+ },
44
+ (err, stdout) => {
45
+ if (err) return resolve(null);
46
+ try {
47
+ const parsed = JSON.parse(String(stdout ?? '').trim() || '{}');
48
+ resolve(parsed?.ok ? parsed : null);
49
+ } catch {
50
+ resolve(null);
51
+ }
52
+ });
53
+ });
54
+ }
55
+
56
+ /** 用 2–3 帧全图检测,找出字幕带(y 的归一化区间)。检测是最贵的一步,只跑这一次。 */
57
+ export async function detectSubtitleBand({ python, frames }) {
58
+ if (!python || !frames?.length) return null;
59
+ const res = await runBridge({ python, mode: 'detect', images: frames.slice(0, 3) });
60
+ if (!res?.band) return null;
61
+ return { band: res.band, detected: Boolean(res.detected), boxes: res.boxes ?? [] };
62
+ }
63
+
64
+ /** 已知字幕带后只做识别(比全图检测快约 12 倍) */
65
+ export async function readBand({ python, images }) {
66
+ if (!python || !images?.length) return null;
67
+ const res = await runBridge({ python, mode: 'read', images });
68
+ return res?.items ?? null;
69
+ }
70
+
71
+ /**
72
+ * 文本相似度:用「公共子序列长度 / 较长者长度」做粗判。
73
+ * 不用编辑距离的绝对值 —— 两句 20 字的台词差 2 个字和两句 8 字的台词差 2 个字,含义完全不同。
74
+ */
75
+ export function similarity(a, b) {
76
+ const s1 = String(a ?? '').replace(/[\s,。、!?;:""''()()]/g, '');
77
+ const s2 = String(b ?? '').replace(/[\s,。、!?;""''()()]/g, '');
78
+ if (!s1 && !s2) return 1;
79
+ if (!s1 || !s2) return 0;
80
+ const m = s1.length;
81
+ const n = s2.length;
82
+ let prev = new Array(n + 1).fill(0);
83
+ for (let i = 1; i <= m; i += 1) {
84
+ const cur = new Array(n + 1).fill(0);
85
+ for (let j = 1; j <= n; j += 1) {
86
+ cur[j] = s1[i - 1] === s2[j - 1] ? prev[j - 1] + 1 : Math.max(prev[j], cur[j - 1]);
87
+ }
88
+ prev = cur;
89
+ }
90
+ return prev[n] / Math.max(m, n);
91
+ }
92
+
93
+ /**
94
+ * 决定"要不要用 OCR 文本替换 ASR 文本"。
95
+ *
96
+ * 规则刻意保守:只有**三条同时成立**才替换,否则保留 ASR 并记一笔"存疑"。
97
+ * 1. OCR 置信度 ≥ 0.65(低置信的 OCR 比 ASR 还不可信;代码是 0.65,注释以前写成 0.75)
98
+ * 2. 两边长度差不超过 30%(差太多说明截到别的字幕了)
99
+ * 3. 相似度在 0.2–0.9 之间
100
+ * —— <0.2:完全是两句话,可能帧没对上;>0.9:本来就一致,没必要动
101
+ */
102
+ export function shouldReplace({ asr, ocr, conf }) {
103
+ const clean = (x) => String(x ?? '').replace(/[\s,。、!?;:""''()()…—]/g, '');
104
+ const A = clean(asr);
105
+ const B = clean(ocr);
106
+ if (B.length < 2) return { replace: false, reason: 'empty-ocr' };
107
+ if (!(conf >= 0.65)) return { replace: false, reason: 'low-conf' };
108
+ if (A.length === 0) return { replace: true, reason: 'asr-empty', text: String(ocr).trim() };
109
+
110
+ // 一条字幕带里常常同时留着上下两句(上一句还没消失),所以先把 OCR 切成分句,
111
+ // 再挑"和这句 ASR 最吻合的那一块"——拿整条去比长度,永远会被判成"长度差太多"。
112
+ const pieces = String(ocr).split(/[,。、!?;,;!?\n]/).map((x) => clean(x)).filter((x) => x.length >= 2);
113
+ const candidates = pieces.length > 0 ? pieces : [B];
114
+ let best = { cover: 0, piece: B, raw: String(ocr).trim() };
115
+ for (let i = 0; i < candidates.length; i += 1) {
116
+ const cover = lcsLength(A, candidates[i]) / A.length;
117
+ if (cover > best.cover) best = { cover, piece: candidates[i], raw: candidates[i] };
118
+ }
119
+ const cover = best.cover;
120
+
121
+ // 长度差(对"最吻合那块"而言):差太多说明截到的是别的字幕
122
+ if (Math.abs(A.length - best.piece.length) / Math.max(A.length, best.piece.length) > 0.5) {
123
+ return { replace: false, reason: 'length-gap', cover: +cover.toFixed(2) };
124
+ }
125
+ // 判据是**覆盖度**:ASR 的典型错误是漏字/换字,OCR 常常是完整那句。
126
+ // 问"ASR 里有多少字按顺序出现在 OCR 里",而不是两边各占多少。
127
+ if (cover < 0.6) return { replace: false, reason: 'unrelated', cover: +cover.toFixed(2) };
128
+ if (cover > 0.98) return { replace: false, reason: 'agree' };
129
+ // 多出来的字如果明显多于这句台词,说明带子把相邻那句也截进来了 —— 按匹配区间剪掉两头
130
+ const match = lcsMatch(A, best.piece);
131
+ // 剪到匹配区间,两侧各放宽 1 个字:ASR 常常漏掉句尾的语气词(吗/了/啊),
132
+ // 但再宽就会把相邻那句的头一个字带进来。
133
+ const text = best.piece.length - A.length > 2
134
+ ? best.piece.slice(Math.max(0, match.lo - 1), Math.min(best.piece.length, match.hi + 2))
135
+ : best.raw;
136
+ return { replace: true, reason: 'ocr-covers-asr', cover: +cover.toFixed(2), text };
137
+ }
138
+
139
+ /** 最长公共子序列长度(按字符) */
140
+ function lcsLength(a, b) {
141
+ return lcsMatch(a, b).length;
142
+ }
143
+
144
+ /**
145
+ * 最长公共子序列 + 它在 b 里覆盖的区间。
146
+ * 区间用来把"顺带截进来的上一句/下一句"剪掉:字幕带上常常同时有两条字幕。
147
+ */
148
+ function lcsMatch(a, b) {
149
+ const m = a.length;
150
+ const n = b.length;
151
+ const dp = Array.from({ length: m + 1 }, () => new Array(n + 1).fill(0));
152
+ for (let i = 1; i <= m; i += 1) {
153
+ for (let j = 1; j <= n; j += 1) {
154
+ dp[i][j] = a[i - 1] === b[j - 1] ? dp[i - 1][j - 1] + 1 : Math.max(dp[i - 1][j], dp[i][j - 1]);
155
+ }
156
+ }
157
+ let i = m; let j = n; let lo = Infinity; let hi = -1;
158
+ while (i > 0 && j > 0) {
159
+ if (a[i - 1] === b[j - 1]) {
160
+ lo = Math.min(lo, j - 1);
161
+ hi = Math.max(hi, j - 1);
162
+ i -= 1; j -= 1;
163
+ } else if (dp[i - 1][j] >= dp[i][j - 1]) i -= 1;
164
+ else j -= 1;
165
+ }
166
+ return { length: dp[m][n], lo: hi >= 0 ? lo : 0, hi: hi >= 0 ? hi : n - 1 };
167
+ }