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.
- package/NOTICE.md +20 -0
- package/README.md +20 -9
- package/client.js +30 -9
- package/lib/engines.mjs +136 -0
- package/lib/index.js +37 -4
- package/lib/qqbot-0.5.3-patches.json +75 -70
- package/lib/qqbot-patch.mjs +12 -7
- package/lib/video.mjs +11 -2
- package/package.json +7 -23
- package/vendor/dsh-agent-md/LICENSE +21 -0
- package/vendor/dsh-agent-md/cordis.patch.yml +8 -0
- package/vendor/dsh-agent-md/lib/index.js +775 -0
- package/vendor/dsh-agent-md/lib/persona.js +634 -0
- package/vendor/dsh-agent-md/lib/qq.js +527 -0
- package/vendor/dsh-agent-md/package.json +50 -0
- package/vendor/dsh-bili-scroll/LICENSE +21 -0
- package/vendor/dsh-bili-scroll/NOTICE.md +18 -0
- package/vendor/dsh-bili-scroll/cordis.patch.yml +20 -0
- package/vendor/dsh-bili-scroll/index.js +3278 -0
- package/vendor/dsh-bili-scroll/lib/asr.py +141 -0
- package/vendor/dsh-bili-scroll/lib/diagnose.mjs +95 -0
- package/vendor/dsh-bili-scroll/lib/dm.mjs +110 -0
- package/vendor/dsh-bili-scroll/lib/favops.py +90 -0
- package/vendor/dsh-bili-scroll/lib/hostdeps.mjs +148 -0
- package/vendor/dsh-bili-scroll/lib/login.mjs +141 -0
- package/vendor/dsh-bili-scroll/lib/mcp.mjs +144 -0
- package/vendor/dsh-bili-scroll/lib/state.mjs +236 -0
- package/vendor/dsh-bili-scroll/lib/uid.mjs +61 -0
- package/vendor/dsh-bili-scroll/lib/uvfetch.mjs +217 -0
- package/vendor/dsh-bili-scroll/lib/verify.mjs +184 -0
- package/vendor/dsh-bili-scroll/package.json +84 -0
- package/vendor/dsh-bili-scroll/profile-template/bili-duty/cordis.patch.yml +116 -0
- package/vendor/dsh-bili-scroll/profile-template/bili-duty/cordis.yml +4 -0
- package/vendor/dsh-bili-scroll/profile-template/bili-duty/package.json +13 -0
- package/vendor/dsh-bili-scroll/prompts/duty.md +296 -0
- package/vendor/dsh-bili-scroll/vendor/bilibili-mcp/LICENSE +21 -0
- package/vendor/dsh-bili-scroll/vendor/bilibili-mcp/README.md +176 -0
- package/vendor/dsh-bili-scroll/vendor/bilibili-mcp/mcp_server.py +2015 -0
- package/vendor/dsh-bili-scroll/vendor/bilibili-mcp/requirements.txt +10 -0
- package/vendor/dsh-meme/.dsh/skills/dsh-meme-maintenance/SKILL.md +50 -0
- package/vendor/dsh-meme/LICENSE +21 -0
- package/vendor/dsh-meme/anim.js +588 -0
- package/vendor/dsh-meme/cordis.patch.yml +13 -0
- package/vendor/dsh-meme/icon.jpg +0 -0
- package/vendor/dsh-meme/index.js +2616 -0
- package/vendor/dsh-meme/locale/en.json +6 -0
- package/vendor/dsh-meme/locale/zh.json +6 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/index.db +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/manifest.json +13 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/angry/shengqi.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/baka/xianqi.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/color/huachi.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/confused/jiazai.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/confused/wenhao.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/cpu/jiaban.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/daily/ganfan.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/fool/buyao.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/givemoney/yaoqian.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/happy/deyi.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/happy/ok.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/happy/piaole.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/like/bixin.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/meow/maozhua.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/morning/zaoshanghao.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/sad/qiurao.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/sad/yun.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/see/zhenjing.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/shy/haixiu.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/shy/toukan.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/sigh/wuyu.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/sleep/shuijiao.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/surprised/xia.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/work/tangping.jpg +0 -0
- package/vendor/dsh-meme/memes.js +998 -0
- package/vendor/dsh-meme/package.json +67 -0
- package/vendor/dsh-meme/panel.html +210 -0
- package/vendor/dsh-video-storyboard/LICENSE +21 -0
- package/vendor/dsh-video-storyboard/NOTICE +12 -0
- package/vendor/dsh-video-storyboard/bin/_args.mjs +16 -0
- package/vendor/dsh-video-storyboard/bin/asr-check.mjs +85 -0
- package/vendor/dsh-video-storyboard/bin/scan-stats.mjs +43 -0
- package/vendor/dsh-video-storyboard/bin/scan-video.mjs +38 -0
- package/vendor/dsh-video-storyboard/bin/storyboard.mjs +195 -0
- package/vendor/dsh-video-storyboard/cordis.patch.yml +3 -0
- package/vendor/dsh-video-storyboard/dsh.plugin.json +12 -0
- package/vendor/dsh-video-storyboard/package.json +88 -0
- package/vendor/dsh-video-storyboard/scripts/check-syntax.mjs +56 -0
- package/vendor/dsh-video-storyboard/scripts/install-dev.mjs +104 -0
- package/vendor/dsh-video-storyboard/src/flicker.js +104 -0
- package/vendor/dsh-video-storyboard/src/index.js +82 -0
- package/vendor/dsh-video-storyboard/src/ocr_bridge.py +103 -0
- package/vendor/dsh-video-storyboard/src/storyboard/asr-lifecycle.js +262 -0
- package/vendor/dsh-video-storyboard/src/storyboard/asr.js +488 -0
- package/vendor/dsh-video-storyboard/src/storyboard/audio.js +168 -0
- package/vendor/dsh-video-storyboard/src/storyboard/binaries.js +69 -0
- package/vendor/dsh-video-storyboard/src/storyboard/board.js +121 -0
- package/vendor/dsh-video-storyboard/src/storyboard/browser-time.js +504 -0
- package/vendor/dsh-video-storyboard/src/storyboard/cache.js +143 -0
- package/vendor/dsh-video-storyboard/src/storyboard/cells.js +70 -0
- package/vendor/dsh-video-storyboard/src/storyboard/density.js +545 -0
- package/vendor/dsh-video-storyboard/src/storyboard/direct-url.js +130 -0
- package/vendor/dsh-video-storyboard/src/storyboard/fetch.js +373 -0
- package/vendor/dsh-video-storyboard/src/storyboard/flash.js +180 -0
- package/vendor/dsh-video-storyboard/src/storyboard/format.js +573 -0
- package/vendor/dsh-video-storyboard/src/storyboard/frames.js +212 -0
- package/vendor/dsh-video-storyboard/src/storyboard/index.js +32 -0
- package/vendor/dsh-video-storyboard/src/storyboard/injection.js +76 -0
- package/vendor/dsh-video-storyboard/src/storyboard/layout-order.js +176 -0
- package/vendor/dsh-video-storyboard/src/storyboard/locate.js +113 -0
- package/vendor/dsh-video-storyboard/src/storyboard/media-store.js +106 -0
- package/vendor/dsh-video-storyboard/src/storyboard/memory.js +94 -0
- package/vendor/dsh-video-storyboard/src/storyboard/ocr-subs.js +107 -0
- package/vendor/dsh-video-storyboard/src/storyboard/ocr.js +167 -0
- package/vendor/dsh-video-storyboard/src/storyboard/pipeline.js +853 -0
- package/vendor/dsh-video-storyboard/src/storyboard/plan.js +400 -0
- package/vendor/dsh-video-storyboard/src/storyboard/probe.js +132 -0
- package/vendor/dsh-video-storyboard/src/storyboard/provenance.js +44 -0
- package/vendor/dsh-video-storyboard/src/storyboard/python.js +84 -0
- package/vendor/dsh-video-storyboard/src/storyboard/register.js +32 -0
- package/vendor/dsh-video-storyboard/src/storyboard/scan.js +486 -0
- package/vendor/dsh-video-storyboard/src/storyboard/segments.js +117 -0
- package/vendor/dsh-video-storyboard/src/storyboard/sheet.js +507 -0
- package/vendor/dsh-video-storyboard/src/storyboard/storage.js +93 -0
- package/vendor/dsh-video-storyboard/src/storyboard/subtitles.js +181 -0
- package/vendor/dsh-video-storyboard/src/storyboard/tool-spec.js +544 -0
- package/vendor/dsh-video-storyboard/src/storyboard/transcript-file.js +146 -0
- package/vendor/dsh-video-storyboard/src/storyboard/url.js +69 -0
- package/vendor/dsh-video-storyboard/src/storyboard/ytdlp.js +289 -0
- package/vendor/dsh-video-storyboard/src/tool-spec.js +17 -0
- package/vendor/dsh-video-storyboard/src/tools/locate.js +39 -0
- package/vendor/dsh-video-storyboard/src/tools/probe.js +23 -0
- package/vendor/dsh-video-storyboard/src/tools/shared.js +39 -0
- package/vendor/dsh-video-storyboard/src/tools/storyboard.js +20 -0
- package/vendor/dsh-video-storyboard/src/tools/zoom.js +56 -0
- package/vendor/dsh-world/LICENSE +21 -0
- package/vendor/dsh-world/assets/qq-card.png +0 -0
- package/vendor/dsh-world/cordis.patch.yml +6 -0
- package/vendor/dsh-world/lib/archive.d.ts +6 -0
- package/vendor/dsh-world/lib/archive.js +49 -0
- package/vendor/dsh-world/lib/archiveSelection.d.ts +8 -0
- package/vendor/dsh-world/lib/archiveSelection.js +20 -0
- package/vendor/dsh-world/lib/compaction.d.ts +124 -0
- package/vendor/dsh-world/lib/compaction.js +273 -0
- package/vendor/dsh-world/lib/compactionRegion.d.ts +42 -0
- package/vendor/dsh-world/lib/compactionRegion.js +210 -0
- package/vendor/dsh-world/lib/console/routes.d.ts +57 -0
- package/vendor/dsh-world/lib/console/routes.js +129 -0
- package/vendor/dsh-world/lib/console/snapshot.d.ts +39 -0
- package/vendor/dsh-world/lib/console/snapshot.js +51 -0
- package/vendor/dsh-world/lib/ecosystem/bridge/bridge.d.ts +36 -0
- package/vendor/dsh-world/lib/ecosystem/bridge/bridge.js +140 -0
- package/vendor/dsh-world/lib/ecosystem/bridge/route.d.ts +9 -0
- package/vendor/dsh-world/lib/ecosystem/bridge/route.js +46 -0
- package/vendor/dsh-world/lib/ecosystem/qq/bridge.d.ts +123 -0
- package/vendor/dsh-world/lib/ecosystem/qq/bridge.js +380 -0
- package/vendor/dsh-world/lib/ecosystem/qq/panel.d.ts +75 -0
- package/vendor/dsh-world/lib/ecosystem/qq/panel.js +187 -0
- package/vendor/dsh-world/lib/ecosystem/qq/route.d.ts +32 -0
- package/vendor/dsh-world/lib/ecosystem/qq/route.js +134 -0
- package/vendor/dsh-world/lib/ecosystem/qq/supervisor.d.ts +57 -0
- package/vendor/dsh-world/lib/ecosystem/qq/supervisor.js +188 -0
- package/vendor/dsh-world/lib/ecosystem/shared/context.d.ts +14 -0
- package/vendor/dsh-world/lib/ecosystem/shared/context.js +42 -0
- package/vendor/dsh-world/lib/ecosystem/shared/identity.d.ts +15 -0
- package/vendor/dsh-world/lib/ecosystem/shared/identity.js +36 -0
- package/vendor/dsh-world/lib/ecosystem/shared/outlets.d.ts +43 -0
- package/vendor/dsh-world/lib/ecosystem/shared/outlets.js +70 -0
- package/vendor/dsh-world/lib/ecosystem/shared/sessions.d.ts +16 -0
- package/vendor/dsh-world/lib/ecosystem/shared/sessions.js +52 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/archive.d.ts +24 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/archive.js +62 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/home.d.ts +21 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/home.js +111 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/images.d.ts +5 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/images.js +43 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/index.d.ts +41 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/index.js +166 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/messages.d.ts +24 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/messages.js +35 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/sending.d.ts +30 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/sending.js +216 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/supervisor.d.ts +39 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/supervisor.js +138 -0
- package/vendor/dsh-world/lib/faults.d.ts +10 -0
- package/vendor/dsh-world/lib/faults.js +13 -0
- package/vendor/dsh-world/lib/history.d.ts +16 -0
- package/vendor/dsh-world/lib/history.js +80 -0
- package/vendor/dsh-world/lib/hostContract.d.ts +19 -0
- package/vendor/dsh-world/lib/hostContract.js +1 -0
- package/vendor/dsh-world/lib/http.d.ts +18 -0
- package/vendor/dsh-world/lib/http.js +39 -0
- package/vendor/dsh-world/lib/index.d.ts +108 -0
- package/vendor/dsh-world/lib/index.js +356 -0
- package/vendor/dsh-world/lib/life/activity.d.ts +14 -0
- package/vendor/dsh-world/lib/life/activity.js +58 -0
- package/vendor/dsh-world/lib/life/alarm.d.ts +39 -0
- package/vendor/dsh-world/lib/life/alarm.js +132 -0
- package/vendor/dsh-world/lib/life/alarmTimer.d.ts +22 -0
- package/vendor/dsh-world/lib/life/alarmTimer.js +49 -0
- package/vendor/dsh-world/lib/life/diary.d.ts +4 -0
- package/vendor/dsh-world/lib/life/diary.js +9 -0
- package/vendor/dsh-world/lib/life/earlyStop.d.ts +19 -0
- package/vendor/dsh-world/lib/life/earlyStop.js +25 -0
- package/vendor/dsh-world/lib/life/home.d.ts +34 -0
- package/vendor/dsh-world/lib/life/home.js +91 -0
- package/vendor/dsh-world/lib/life/host.d.ts +22 -0
- package/vendor/dsh-world/lib/life/host.js +24 -0
- package/vendor/dsh-world/lib/life/journal.d.ts +20 -0
- package/vendor/dsh-world/lib/life/journal.js +59 -0
- package/vendor/dsh-world/lib/life/lifeStore.d.ts +16 -0
- package/vendor/dsh-world/lib/life/lifeStore.js +105 -0
- package/vendor/dsh-world/lib/life/messages.d.ts +17 -0
- package/vendor/dsh-world/lib/life/messages.js +53 -0
- package/vendor/dsh-world/lib/life/notify.d.ts +15 -0
- package/vendor/dsh-world/lib/life/notify.js +40 -0
- package/vendor/dsh-world/lib/life/pricing.d.ts +4 -0
- package/vendor/dsh-world/lib/life/pricing.js +30 -0
- package/vendor/dsh-world/lib/life/runtime.d.ts +52 -0
- package/vendor/dsh-world/lib/life/runtime.js +376 -0
- package/vendor/dsh-world/lib/life/toolRegistry.d.ts +22 -0
- package/vendor/dsh-world/lib/life/toolRegistry.js +64 -0
- package/vendor/dsh-world/lib/life/tools.d.ts +24 -0
- package/vendor/dsh-world/lib/life/tools.js +47 -0
- package/vendor/dsh-world/lib/life/types.d.ts +67 -0
- package/vendor/dsh-world/lib/life/types.js +1 -0
- package/vendor/dsh-world/lib/persona.d.ts +10 -0
- package/vendor/dsh-world/lib/persona.js +29 -0
- package/vendor/dsh-world/lib/promptSection.d.ts +30 -0
- package/vendor/dsh-world/lib/promptSection.js +81 -0
- package/vendor/dsh-world/lib/qqScope.d.ts +11 -0
- package/vendor/dsh-world/lib/qqScope.js +39 -0
- package/vendor/dsh-world/lib/runtime.d.ts +23 -0
- package/vendor/dsh-world/lib/runtime.js +206 -0
- package/vendor/dsh-world/lib/self.d.ts +10 -0
- package/vendor/dsh-world/lib/self.js +36 -0
- package/vendor/dsh-world/lib/sourceArchive.d.ts +28 -0
- package/vendor/dsh-world/lib/sourceArchive.js +156 -0
- package/vendor/dsh-world/lib/store.d.ts +30 -0
- package/vendor/dsh-world/lib/store.js +191 -0
- package/vendor/dsh-world/lib/timeContext.d.ts +3 -0
- package/vendor/dsh-world/lib/timeContext.js +13 -0
- package/vendor/dsh-world/lib/types.d.ts +118 -0
- package/vendor/dsh-world/lib/types.js +1 -0
- package/vendor/dsh-world/lib/worldPrompt.d.ts +47 -0
- package/vendor/dsh-world/lib/worldPrompt.js +49 -0
- package/vendor/dsh-world/lib/worldSwitch.d.ts +44 -0
- package/vendor/dsh-world/lib/worldSwitch.js +78 -0
- package/vendor/dsh-world/package-lock.json +1088 -0
- package/vendor/dsh-world/package.json +88 -0
- package/vendor/dsh-world/scripts/enable-tool-free-compaction.ps1 +33 -0
- package/vendor/dsh-world/src/archive.ts +45 -0
- package/vendor/dsh-world/src/archiveSelection.ts +27 -0
- package/vendor/dsh-world/src/compaction.ts +260 -0
- package/vendor/dsh-world/src/compactionRegion.ts +172 -0
- package/vendor/dsh-world/src/console/routes.ts +125 -0
- package/vendor/dsh-world/src/console/snapshot.ts +84 -0
- package/vendor/dsh-world/src/ecosystem/README.md +14 -0
- package/vendor/dsh-world/src/ecosystem/bridge/bridge.ts +121 -0
- package/vendor/dsh-world/src/ecosystem/bridge/route.ts +35 -0
- package/vendor/dsh-world/src/ecosystem/qq/bridge.ts +456 -0
- package/vendor/dsh-world/src/ecosystem/qq/panel.ts +178 -0
- package/vendor/dsh-world/src/ecosystem/qq/route.ts +130 -0
- package/vendor/dsh-world/src/ecosystem/qq/supervisor.ts +262 -0
- package/vendor/dsh-world/src/ecosystem/shared/context.ts +38 -0
- package/vendor/dsh-world/src/ecosystem/shared/identity.ts +42 -0
- package/vendor/dsh-world/src/ecosystem/shared/outlets.ts +75 -0
- package/vendor/dsh-world/src/ecosystem/shared/sessions.ts +47 -0
- package/vendor/dsh-world/src/ecosystem/wechat/archive.ts +66 -0
- package/vendor/dsh-world/src/ecosystem/wechat/home.ts +94 -0
- package/vendor/dsh-world/src/ecosystem/wechat/images.ts +38 -0
- package/vendor/dsh-world/src/ecosystem/wechat/index.ts +101 -0
- package/vendor/dsh-world/src/ecosystem/wechat/messages.ts +43 -0
- package/vendor/dsh-world/src/ecosystem/wechat/sending.ts +177 -0
- package/vendor/dsh-world/src/ecosystem/wechat/supervisor.ts +116 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/README.md +117 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/adapter.py +572 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/binding.py +52 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/engine/LICENSE +43 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/engine/NOTICE.md +10 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/engine/bridge.cpp +229 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/engine/build.ps1 +19 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/engine/profile.json +28 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/groups.py +42 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/incoming.py +157 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/native.py +168 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/outgoing.py +95 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/requirements.txt +1 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/sender.py +157 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/snapshot.py +32 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/stickers.py +60 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/wechat.ps1 +75 -0
- package/vendor/dsh-world/src/faults.ts +12 -0
- package/vendor/dsh-world/src/history.ts +77 -0
- package/vendor/dsh-world/src/hostContract.ts +9 -0
- package/vendor/dsh-world/src/http.ts +34 -0
- package/vendor/dsh-world/src/index.ts +286 -0
- package/vendor/dsh-world/src/life/activity.ts +48 -0
- package/vendor/dsh-world/src/life/alarm.ts +119 -0
- package/vendor/dsh-world/src/life/alarmTimer.ts +45 -0
- package/vendor/dsh-world/src/life/diary.ts +10 -0
- package/vendor/dsh-world/src/life/earlyStop.ts +27 -0
- package/vendor/dsh-world/src/life/home.ts +85 -0
- package/vendor/dsh-world/src/life/host.ts +50 -0
- package/vendor/dsh-world/src/life/journal.ts +44 -0
- package/vendor/dsh-world/src/life/lifeStore.ts +70 -0
- package/vendor/dsh-world/src/life/messages.ts +44 -0
- package/vendor/dsh-world/src/life/notify.ts +47 -0
- package/vendor/dsh-world/src/life/pricing.ts +37 -0
- package/vendor/dsh-world/src/life/runtime.ts +318 -0
- package/vendor/dsh-world/src/life/toolRegistry.ts +48 -0
- package/vendor/dsh-world/src/life/tools.ts +61 -0
- package/vendor/dsh-world/src/life/types.ts +19 -0
- package/vendor/dsh-world/src/persona.ts +26 -0
- package/vendor/dsh-world/src/promptSection.ts +71 -0
- package/vendor/dsh-world/src/qqScope.ts +51 -0
- package/vendor/dsh-world/src/runtime.ts +172 -0
- package/vendor/dsh-world/src/self.ts +32 -0
- package/vendor/dsh-world/src/sourceArchive.ts +132 -0
- package/vendor/dsh-world/src/store.ts +170 -0
- package/vendor/dsh-world/src/timeContext.ts +13 -0
- package/vendor/dsh-world/src/types.ts +112 -0
- package/vendor/dsh-world/src/worldPrompt.ts +64 -0
- package/vendor/dsh-world/src/worldSwitch.ts +82 -0
- package/vendor/dsh-world/templates/alarm.md +49 -0
- package/vendor/dsh-world/templates/world-prompt.md +7 -0
- package/vendor/dsh-world/tests/archive.test.ts +57 -0
- package/vendor/dsh-world/tests/archiveScope.test.ts +86 -0
- package/vendor/dsh-world/tests/bridge.test.ts +211 -0
- package/vendor/dsh-world/tests/channelSessions.test.ts +79 -0
- package/vendor/dsh-world/tests/clientHooks.test.ts +103 -0
- package/vendor/dsh-world/tests/compaction.test.ts +141 -0
- package/vendor/dsh-world/tests/console.test.ts +202 -0
- package/vendor/dsh-world/tests/consoleClient.test.ts +101 -0
- package/vendor/dsh-world/tests/enableCompaction.test.ts +19 -0
- package/vendor/dsh-world/tests/fixtures.ts +6 -0
- package/vendor/dsh-world/tests/history.test.ts +100 -0
- package/vendor/dsh-world/tests/hostFixture.ts +46 -0
- package/vendor/dsh-world/tests/lifeActivity.test.ts +70 -0
- package/vendor/dsh-world/tests/lifeAlarm.test.ts +87 -0
- package/vendor/dsh-world/tests/lifeDiary.test.ts +33 -0
- package/vendor/dsh-world/tests/lifeMessages.test.ts +61 -0
- package/vendor/dsh-world/tests/lifeNotify.test.ts +46 -0
- package/vendor/dsh-world/tests/lifeParts.test.ts +45 -0
- package/vendor/dsh-world/tests/lifeRuntime.test.ts +660 -0
- package/vendor/dsh-world/tests/lifeStore.test.ts +90 -0
- package/vendor/dsh-world/tests/lifeTools.test.ts +53 -0
- package/vendor/dsh-world/tests/outlets.test.ts +85 -0
- package/vendor/dsh-world/tests/panel.test.ts +85 -0
- package/vendor/dsh-world/tests/plugin.test.ts +614 -0
- package/vendor/dsh-world/tests/pricing.test.ts +21 -0
- package/vendor/dsh-world/tests/qq.test.ts +121 -0
- package/vendor/dsh-world/tests/qqSessionMode.test.ts +97 -0
- package/vendor/dsh-world/tests/qqSupervisor.test.ts +149 -0
- package/vendor/dsh-world/tests/sourceArchive.test.ts +58 -0
- package/vendor/dsh-world/tests/store.test.ts +82 -0
- package/vendor/dsh-world/tests/storeWriter.ts +5 -0
- package/vendor/dsh-world/tests/timeContext.test.ts +15 -0
- package/vendor/dsh-world/tests/wechat.test.ts +254 -0
- package/vendor/dsh-world/tests/wechatImages.test.ts +130 -0
- package/vendor/dsh-world/tests/wechatSending.test.ts +142 -0
- package/vendor/dsh-world/tests/wechatSupervisor.test.ts +91 -0
- package/vendor/dsh-world/tests/worldPrompt.test.ts +201 -0
- package/vendor/dsh-world/tsconfig.build.json +5 -0
- package/vendor/dsh-world/tsconfig.json +8 -0
|
@@ -0,0 +1,504 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* browser-time.js — 直接从浏览器里读 `video.currentTime`,毫秒级准。
|
|
3
|
+
*
|
|
4
|
+
* 为什么需要:Windows 的 SMTC 只在**事件时**刷新(起播/暂停/拖动/切集),
|
|
5
|
+
* 连续播放期间能几分钟不动。实测两次刷新隔过 143 s、216 s —— 那段时间里
|
|
6
|
+
* "用户看到第几秒"只能靠墙钟外推,暂停/缓冲一插进来就错。
|
|
7
|
+
*
|
|
8
|
+
* 浏览器里那个 `<video>` 元素的 `currentTime` 是**真的**,只要浏览器开了调试端口:
|
|
9
|
+
*
|
|
10
|
+
* msedge.exe --remote-debugging-port=9222
|
|
11
|
+
*
|
|
12
|
+
* 然后走 CDP(Chrome DevTools Protocol):
|
|
13
|
+
* GET http://127.0.0.1:9222/json → 找到页面目标
|
|
14
|
+
* WS Runtime.evaluate → 读 currentTime / paused / duration / location.href
|
|
15
|
+
*
|
|
16
|
+
* 顺带的好处:**拿得到当前网页地址**,源解析不用再靠标题猜。
|
|
17
|
+
*
|
|
18
|
+
* 没有调试端口就返回 null,调用方退回 SMTC。不报错、不打扰。
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
// 默认 9333 而不是 9222:9222 是 Chrome DevTools 的惯例端口,容易被别的 Electron 应用占掉
|
|
22
|
+
// (实测这台机器上 WorkBuddy 自己就占着 9222,盲连会读到它的界面)。
|
|
23
|
+
const DEFAULT_PORT = 9333;
|
|
24
|
+
|
|
25
|
+
import { spawn } from 'node:child_process';
|
|
26
|
+
import { execFileSync } from 'node:child_process';
|
|
27
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
28
|
+
import { homedir } from 'node:os';
|
|
29
|
+
import { join } from 'node:path';
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 从 `~/.dsh/video.json` 读端口配置。
|
|
33
|
+
*
|
|
34
|
+
* 为什么要文件而不是只认环境变量:DSH 桌面版的宿主进程 env 由启动器决定,
|
|
35
|
+
* 用户 `setx` 之后插件仍然读不到(这个坑今天已经踩过一次)。文件不依赖 env 传播。
|
|
36
|
+
*
|
|
37
|
+
* { "browserPort": 9333 }
|
|
38
|
+
*/
|
|
39
|
+
/** `~/.dsh/video.json` 里的 launchBrowser(默认关:不要替用户随便开程序) */
|
|
40
|
+
export function configuredLaunch(env = process.env) {
|
|
41
|
+
const home = env.DSH_HOME || join(env.USERPROFILE || env.HOME || homedir(), '.dsh');
|
|
42
|
+
try {
|
|
43
|
+
const cfg = JSON.parse(readFileSync(join(home, 'video.json'), 'utf8'));
|
|
44
|
+
return cfg?.launchBrowser === true;
|
|
45
|
+
} catch {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function configuredPort(env = process.env) {
|
|
51
|
+
const home = env.DSH_HOME || join(env.USERPROFILE || env.HOME || homedir(), '.dsh');
|
|
52
|
+
try {
|
|
53
|
+
const cfg = JSON.parse(readFileSync(join(home, 'video.json'), 'utf8'));
|
|
54
|
+
const n = Number(cfg?.browserPort);
|
|
55
|
+
if (Number.isFinite(n) && n > 0) return n;
|
|
56
|
+
if (cfg?.browserPort === false || cfg?.browser === false) return null;
|
|
57
|
+
} catch { /* 没有配置文件就是没开 */ }
|
|
58
|
+
const fromEnv = Number(env.DSH_BROWSER_DEBUG_PORT);
|
|
59
|
+
return Number.isFinite(fromEnv) && fromEnv > 0 ? fromEnv : null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 这个地址像不像"某个视频的页面"?
|
|
64
|
+
*
|
|
65
|
+
* 为什么需要:B 站**首页**上就挂着自动播放的推荐视频,`document.querySelector('video')` 也有值。
|
|
66
|
+
* 但 `https://www.bilibili.com/` 不是任何一条视频,拿去喂 yt-dlp 只会得到
|
|
67
|
+
* "this site is not supported"。判定要卡在地址上,而不是"页面上有没有 <video>"。
|
|
68
|
+
*/
|
|
69
|
+
export function looksLikeVideoUrl(url) {
|
|
70
|
+
if (typeof url !== 'string' || !url) return false;
|
|
71
|
+
if (url.startsWith('file://')) return true;
|
|
72
|
+
if (/^https?:\/\//i.test(url)) {
|
|
73
|
+
if (/bilibili\.com\/video\/(BV|av)/i.test(url)) return true;
|
|
74
|
+
if (/bilibili\.com\/bangumi\/play\//i.test(url)) return true;
|
|
75
|
+
if (/youtube\.com\/watch|youtu\.be\//i.test(url)) return true;
|
|
76
|
+
if (/\.(mp4|m3u8|webm|mkv)(\?|$)/i.test(url)) return true;
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* `file:///D:/a%20b.mp4` → `D:/a b.mp4`
|
|
83
|
+
* 本地视频用浏览器打开时,页面地址就是这个视频的路径 —— 正好当 input 用,不必再问用户。
|
|
84
|
+
*/
|
|
85
|
+
export function fileUrlToPath(url) {
|
|
86
|
+
if (typeof url !== 'string' || !url.startsWith('file://')) return null;
|
|
87
|
+
try {
|
|
88
|
+
const p = new URL(url).pathname;
|
|
89
|
+
const decoded = decodeURIComponent(p);
|
|
90
|
+
// Windows: /D:/x → D:/x
|
|
91
|
+
return /^\/[a-z]:/i.test(decoded) ? decoded.slice(1) : decoded;
|
|
92
|
+
} catch {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** 列出调试端口暴露的页面目标 */
|
|
98
|
+
export async function listTargets({ port = DEFAULT_PORT, timeoutMs = 1200 } = {}) {
|
|
99
|
+
const ac = new AbortController();
|
|
100
|
+
const timer = setTimeout(() => ac.abort(), timeoutMs);
|
|
101
|
+
try {
|
|
102
|
+
const res = await fetch(`http://127.0.0.1:${port}/json/list`, { signal: ac.signal });
|
|
103
|
+
if (!res.ok) return null;
|
|
104
|
+
const list = await res.json();
|
|
105
|
+
return Array.isArray(list) ? list : null;
|
|
106
|
+
} catch {
|
|
107
|
+
return null;
|
|
108
|
+
} finally {
|
|
109
|
+
clearTimeout(timer);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** 挑一个"正在放视频"的页面:优先 bilibili,其次任何带 video 的页面 */
|
|
114
|
+
export function pickVideoTarget(targets) {
|
|
115
|
+
const pages = (targets ?? []).filter((t) => t.type === 'page' && t.webSocketDebuggerUrl);
|
|
116
|
+
if (pages.length === 0) return null;
|
|
117
|
+
const scored = pages.map((t) => {
|
|
118
|
+
let n = 0;
|
|
119
|
+
if (/bilibili\.com/i.test(t.url ?? '')) n += 3;
|
|
120
|
+
if (/\/video\//i.test(t.url ?? '')) n += 2;
|
|
121
|
+
if (/\.(mp4|mkv|webm|m3u8)/i.test(t.url ?? '')) n += 2;
|
|
122
|
+
return { t, n };
|
|
123
|
+
}).sort((a, b) => b.n - a.n);
|
|
124
|
+
return scored[0].n > 0 ? scored[0].t : pages[0];
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** 在某个页面里求值一次(一条 CDP 往返,约 10–30 ms) */
|
|
128
|
+
export function evaluate(wsUrl, expression, { timeoutMs = 1500 } = {}) {
|
|
129
|
+
return new Promise((resolve) => {
|
|
130
|
+
let ws;
|
|
131
|
+
let done = false;
|
|
132
|
+
const finish = (v) => {
|
|
133
|
+
if (done) return;
|
|
134
|
+
done = true;
|
|
135
|
+
try { ws?.close(); } catch { /* 已关 */ }
|
|
136
|
+
resolve(v);
|
|
137
|
+
};
|
|
138
|
+
const timer = setTimeout(() => finish(null), timeoutMs);
|
|
139
|
+
try {
|
|
140
|
+
ws = new WebSocket(wsUrl);
|
|
141
|
+
} catch {
|
|
142
|
+
clearTimeout(timer);
|
|
143
|
+
return resolve(null);
|
|
144
|
+
}
|
|
145
|
+
ws.onopen = () => {
|
|
146
|
+
ws.send(JSON.stringify({
|
|
147
|
+
id: 1,
|
|
148
|
+
method: 'Runtime.evaluate',
|
|
149
|
+
params: { expression, returnByValue: true, awaitPromise: false },
|
|
150
|
+
}));
|
|
151
|
+
};
|
|
152
|
+
ws.onmessage = (ev) => {
|
|
153
|
+
try {
|
|
154
|
+
const msg = JSON.parse(String(ev.data));
|
|
155
|
+
if (msg.id !== 1) return;
|
|
156
|
+
clearTimeout(timer);
|
|
157
|
+
finish(msg.result?.result?.value ?? null);
|
|
158
|
+
} catch {
|
|
159
|
+
clearTimeout(timer);
|
|
160
|
+
finish(null);
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
ws.onerror = () => { clearTimeout(timer); finish(null); };
|
|
164
|
+
ws.onclose = () => { clearTimeout(timer); finish(null); };
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const SNAPSHOT_EXPR = `(() => {
|
|
169
|
+
const v = document.querySelector('video');
|
|
170
|
+
if (!v) return null;
|
|
171
|
+
return {
|
|
172
|
+
pos: v.currentTime,
|
|
173
|
+
dur: Number.isFinite(v.duration) ? v.duration : null,
|
|
174
|
+
paused: v.paused,
|
|
175
|
+
ended: v.ended,
|
|
176
|
+
readyState: v.readyState,
|
|
177
|
+
url: location.href,
|
|
178
|
+
title: document.title,
|
|
179
|
+
};
|
|
180
|
+
})()`;
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* 读浏览器里的真实播放位置。
|
|
184
|
+
* @returns {Promise<null | {pos:number, dur:number|null, paused:boolean, url:string, title:string, port:number}>}
|
|
185
|
+
*/
|
|
186
|
+
export async function readBrowserPosition({ port = DEFAULT_PORT, timeoutMs = 1500, maxPages = 8 } = {}) {
|
|
187
|
+
const targets = await listTargets({ port, timeoutMs });
|
|
188
|
+
if (!targets) return null;
|
|
189
|
+
const pages = targets.filter((t) => t.type === 'page' && t.webSocketDebuggerUrl)
|
|
190
|
+
// **跳过 Electron 宿主自己的页面**:WorkBuddy / VSCode 这类应用也会开调试端口,
|
|
191
|
+
// 页面里还有 <video>(实测 WorkBuddy 的 9222 上就有一个 5 秒的 video)。
|
|
192
|
+
// 不排除的话会读到宿主自己的界面元素,而不是用户在看的那支片子。
|
|
193
|
+
.filter((t) => {
|
|
194
|
+
const u = t.url ?? '';
|
|
195
|
+
return !u.includes('app.asar') && !u.startsWith('devtools:') && !u.includes('vscode');
|
|
196
|
+
});
|
|
197
|
+
if (pages.length === 0) return null;
|
|
198
|
+
|
|
199
|
+
// **挨个问 "你这儿有 video 吗"**,而不是靠 URL 猜。
|
|
200
|
+
// 实测踩过:同一台浏览器开着 7 个页面,靠 URL 打分选中了没有视频的那个,
|
|
201
|
+
// 于是永远读到 -1 —— 而 B 站页面好好的。URL 只能用来排序,不能用来判断。
|
|
202
|
+
const ordered = [
|
|
203
|
+
...pages.filter((t) => /bilibili\.com|\/video\//i.test(t.url ?? '')),
|
|
204
|
+
...pages.filter((t) => !/bilibili\.com|\/video\//i.test(t.url ?? '')),
|
|
205
|
+
].slice(0, maxPages);
|
|
206
|
+
|
|
207
|
+
let best = null;
|
|
208
|
+
for (const t of ordered) {
|
|
209
|
+
const snap = await evaluate(t.webSocketDebuggerUrl, SNAPSHOT_EXPR, { timeoutMs });
|
|
210
|
+
if (!snap || typeof snap.pos !== 'number') continue;
|
|
211
|
+
const cand = { ...snap, port };
|
|
212
|
+
// 正在播的优先;暂停的也能用,但排在后面
|
|
213
|
+
if (!snap.paused && !snap.ended) { best = cand; break; }
|
|
214
|
+
if (!best) best = cand;
|
|
215
|
+
}
|
|
216
|
+
if (!best) return null;
|
|
217
|
+
|
|
218
|
+
/*
|
|
219
|
+
* **`paused` 会误报**,这是实测出来的:用户坚称在播,接口一路回 `paused`,
|
|
220
|
+
* 而且 66 秒挂钟时间里 currentTime 只走了 8.6 秒(慢 3 倍多),之后又突然跳到 01:24。
|
|
221
|
+
* 单看 `v.paused` 会把"其实在播"判成"暂停",上层就反复让用户"按一下播放"——观感极差。
|
|
222
|
+
*
|
|
223
|
+
* 所以这里三路互证:
|
|
224
|
+
* ① `v.paused` 为 false → 一定在播
|
|
225
|
+
* ② currentTime 相对上次读数确实前进了 → 即使 paused 说是暂停,也判在播
|
|
226
|
+
* ③ 两次读数完全没动 → 记成 stale,让上层能区分"真暂停"和"读不到"
|
|
227
|
+
*/
|
|
228
|
+
const now = Date.now();
|
|
229
|
+
const prev = lastSnapByPort.get(port);
|
|
230
|
+
let playing = !best.paused && !best.ended;
|
|
231
|
+
let staleMs = 0;
|
|
232
|
+
if (prev && prev.url === best.url) {
|
|
233
|
+
const dt = (now - prev.t) / 1000;
|
|
234
|
+
const dp = best.pos - prev.pos;
|
|
235
|
+
if (!playing && dt >= 0.8 && dt <= 15 && dp > 0.15 * dt) playing = true;
|
|
236
|
+
if (dp === 0) staleMs = now - prev.t;
|
|
237
|
+
}
|
|
238
|
+
lastSnapByPort.set(port, { t: now, pos: best.pos, url: best.url });
|
|
239
|
+
|
|
240
|
+
return {
|
|
241
|
+
...best,
|
|
242
|
+
// 覆盖掉 DOM 那个会误报的 paused;原始值留档,排查时能对照
|
|
243
|
+
paused: !playing,
|
|
244
|
+
rawPaused: best.paused,
|
|
245
|
+
playing,
|
|
246
|
+
staleMs,
|
|
247
|
+
confidence: playing ? 'playing' : (staleMs > 5000 ? 'stale' : 'paused'),
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** 每个端口最近一次读数:用来判断 currentTime 有没有真的在走 */
|
|
252
|
+
const lastSnapByPort = new Map();
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* 「浏览器到底在不在」—— 一次调用同时回答三件事:端口开没开 / 有没有标签页挂着 <video> /
|
|
256
|
+
* 视频在播还是暂停。
|
|
257
|
+
*
|
|
258
|
+
* ## 为什么必须有这个函数
|
|
259
|
+
*
|
|
260
|
+
* `readBrowserPosition()` 读不到时返回 `null`,而调用方一律写成
|
|
261
|
+
* `.catch(() => null)`(watch-run 里有 7 处)。于是**"浏览器没开"和"浏览器开着但没视频"
|
|
262
|
+
* 在上层看起来一模一样**——都是"没有位置"。模型只能拿"有没有位置"去倒推"浏览器在不在",
|
|
263
|
+
* 而这两件事根本不是一回事:SMTC 那条路是系统级的,VLC、电影和电视、另一个没开调试端口的
|
|
264
|
+
* Edge 窗口都能给它一个位置。结果就是"有位置" ≠ "你在看的那只浏览器开着",
|
|
265
|
+
* 模型对着空气写台词,还以为一切正常。
|
|
266
|
+
*
|
|
267
|
+
* 这里把状态说死,不给上层猜的空间:
|
|
268
|
+
* unconfigured 没配调试端口(只可能走 SMTC)
|
|
269
|
+
* closed 端口不通 → 浏览器没开 / 没带调试参数启动
|
|
270
|
+
* no-video 端口通、标签页也有,但没有一个页面挂着 <video>
|
|
271
|
+
* watching 读到了具体进度(带 url / title / playing / pos)
|
|
272
|
+
* error 探测本身抛了,连"开没开"都不知道
|
|
273
|
+
*
|
|
274
|
+
* @returns {Promise<{state:'unconfigured'|'closed'|'no-video'|'watching'|'error', port:number|null,
|
|
275
|
+
* url?:string, title?:string, pos?:number, dur?:number|null, paused?:boolean, playing?:boolean,
|
|
276
|
+
* pages?:number, urls?:string[]}>}
|
|
277
|
+
*/
|
|
278
|
+
export async function probeBrowser({ port = DEFAULT_PORT, timeoutMs = 1200 } = {}) {
|
|
279
|
+
if (!port) return { state: 'unconfigured', port: null };
|
|
280
|
+
const targets = await listTargets({ port, timeoutMs });
|
|
281
|
+
if (!targets) return { state: 'closed', port };
|
|
282
|
+
const pages = targets.filter((t) => t.type === 'page' && t.webSocketDebuggerUrl);
|
|
283
|
+
let snap = null;
|
|
284
|
+
try {
|
|
285
|
+
snap = await readBrowserPosition({ port, timeoutMs, maxPages: 6 });
|
|
286
|
+
} catch {
|
|
287
|
+
return { state: 'error', port, pages: pages.length };
|
|
288
|
+
}
|
|
289
|
+
if (!snap) {
|
|
290
|
+
return {
|
|
291
|
+
state: 'no-video',
|
|
292
|
+
port,
|
|
293
|
+
pages: pages.length,
|
|
294
|
+
urls: pages.slice(0, 3).map((t) => String(t.url ?? '').slice(0, 100)),
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
return {
|
|
298
|
+
state: 'watching',
|
|
299
|
+
port,
|
|
300
|
+
pages: pages.length,
|
|
301
|
+
url: snap.url,
|
|
302
|
+
title: snap.title,
|
|
303
|
+
pos: snap.pos,
|
|
304
|
+
dur: snap.dur ?? null,
|
|
305
|
+
paused: snap.paused,
|
|
306
|
+
playing: snap.playing === true,
|
|
307
|
+
confidence: snap.confidence,
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* 由**插件自己**把浏览器拉起来。
|
|
313
|
+
*
|
|
314
|
+
* 为什么不能靠外部脚本代劳:我这边的工具进程跑在一个 Job Object 里,
|
|
315
|
+
* 它派生出去的子进程(哪怕 detached + unref)会随这个 job 一起被回收——
|
|
316
|
+
* 实测两次:窗口开起来、7 秒后读得到、再 10 秒整个浏览器连同用户自己的 Edge 一起没了。
|
|
317
|
+
* 而插件是跑在 DSH 里的长期进程,它 spawn 出去的浏览器才活得下来。
|
|
318
|
+
*
|
|
319
|
+
* 所以:想在"打开视频时自动就有端口",只能是插件来起。
|
|
320
|
+
*/
|
|
321
|
+
export function launchBrowser({
|
|
322
|
+
port = DEFAULT_PORT, url = '', profileDir = null, exe = null, taskScheduler = true,
|
|
323
|
+
} = {}) {
|
|
324
|
+
// 不能只认 x86 那条:只装了 Chrome 的机器上,自动起浏览器这条路会直接死
|
|
325
|
+
const EDGE_CANDIDATES = [
|
|
326
|
+
'C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe',
|
|
327
|
+
'C:/Program Files/Microsoft/Edge/Application/msedge.exe',
|
|
328
|
+
'C:/Program Files/Google/Chrome/Application/chrome.exe',
|
|
329
|
+
'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe',
|
|
330
|
+
];
|
|
331
|
+
const edge = exe
|
|
332
|
+
?? EDGE_CANDIDATES.find((q) => { try { return existsSync(q); } catch { return false; } })
|
|
333
|
+
?? EDGE_CANDIDATES[0];
|
|
334
|
+
const profile = profileDir ?? join(homedir(), '.dsh', 'edge-watch');
|
|
335
|
+
if (!existsSync(edge)) return { ok: false, reason: 'edge-not-found' };
|
|
336
|
+
mkdirSync(profile, { recursive: true });
|
|
337
|
+
// **清掉上次的会话**:用独立 profile 冷启动时,Edge 会自动恢复上次开的标签页,
|
|
338
|
+
// 于是旧视频页 + 陪看页每启动一次就多一份,标签栏越积越乱。
|
|
339
|
+
// 这里清的是 session 文件,不影响登录态(Cookie / Local Storage 都在别处)。
|
|
340
|
+
for (const sub of ['Sessions', join('Default', 'Sessions')]) {
|
|
341
|
+
try { rmSync(join(profile, sub), { recursive: true, force: true }); } catch { /* 删不掉就算了 */ }
|
|
342
|
+
}
|
|
343
|
+
const args = [
|
|
344
|
+
`--remote-debugging-port=${port}`,
|
|
345
|
+
`--user-data-dir=${profile}`,
|
|
346
|
+
'--no-first-run',
|
|
347
|
+
'--no-default-browser-check',
|
|
348
|
+
'--no-restore-last-session',
|
|
349
|
+
...(url ? [url] : []),
|
|
350
|
+
];
|
|
351
|
+
|
|
352
|
+
// **Windows 上走计划任务**:普通 spawn 出去的进程会留在调用者的 Job Object 里,
|
|
353
|
+
// 调用方一退出就被回收(实测:窗口开起来、3 秒后整个浏览器消失)。
|
|
354
|
+
// 计划任务由 Task Scheduler 服务启动,不在那个 job 里,才能真正活下来。
|
|
355
|
+
if (process.platform === 'win32' && taskScheduler !== false) {
|
|
356
|
+
// 任务名**不带端口**。以前是 `DSH-Edge-Watch-${port}`,端口一改就多一个任务 ——
|
|
357
|
+
// 机器上实测已经积了两个(DSH-Edge-Watch / DSH-Edge-Watch-9333),每个都是独立定义,
|
|
358
|
+
// 用户根本不知道该删哪个。名字固定,端口写进参数里。
|
|
359
|
+
const task = 'DSH-Edge-Watch';
|
|
360
|
+
|
|
361
|
+
// 顺手清掉历史上按端口命名的那些变体,别再长新的
|
|
362
|
+
try {
|
|
363
|
+
execFileSync('powershell', ['-NoProfile', '-NonInteractive', '-Command',
|
|
364
|
+
"$ErrorActionPreference='SilentlyContinue'; "
|
|
365
|
+
+ "Get-ScheduledTask -TaskName 'DSH-Edge-Watch-*' | Unregister-ScheduledTask -Confirm:$false"],
|
|
366
|
+
{ stdio: 'ignore', windowsHide: true, timeout: 15_000 });
|
|
367
|
+
} catch { /* 清不掉也不影响启动 */ }
|
|
368
|
+
const quoted = args.map((a) => (a.includes(' ') ? `"${a}"` : a)).join(' ');
|
|
369
|
+
const q = (s) => `'${String(s).replace(/'/g, "''")}'`;
|
|
370
|
+
|
|
371
|
+
// **顺序:PowerShell cmdlet 在前,schtasks.exe 在后。别调回去。**
|
|
372
|
+
// 为什么:schtasks.exe 在不少机器的"程序黑名单"里(安全策略直接拦,报 PROGRAM BLOCKED
|
|
373
|
+
// ... schtasks.exe),失败后只能退回 spawn —— 而 spawn 在 Job 对象里活不过几秒。
|
|
374
|
+
// 旧顺序(先 schtasks)的实测后果:**每次启动,用户的浏览器都会被关一次**。
|
|
375
|
+
//
|
|
376
|
+
// 还有一条:任务**已存在就只 Start,不要 Register**。
|
|
377
|
+
// Register-ScheduledTask -Force 会重写任务定义,正在跑的那个实例会被一起终止 ——
|
|
378
|
+
// 表现就是"用户看着看着,浏览器被关了"。只有任务不存在时才创建。
|
|
379
|
+
try {
|
|
380
|
+
execFileSync('powershell', ['-NoProfile', '-NonInteractive', '-Command',
|
|
381
|
+
`$ErrorActionPreference='Stop'; Start-ScheduledTask -TaskName ${q(task)}`],
|
|
382
|
+
{ stdio: 'ignore', windowsHide: true, timeout: 20_000 });
|
|
383
|
+
return { ok: true, via: 'scheduled-task', task, port, profile };
|
|
384
|
+
} catch { /* 任务不存在 → 下面创建 */ }
|
|
385
|
+
|
|
386
|
+
try {
|
|
387
|
+
execFileSync('powershell', ['-NoProfile', '-NonInteractive', '-Command', [
|
|
388
|
+
`$a = New-ScheduledTaskAction -Execute ${q(edge)} -Argument ${q(quoted)}`,
|
|
389
|
+
'$s = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit ([TimeSpan]::Zero)',
|
|
390
|
+
`Register-ScheduledTask -TaskName ${q(task)} -Action $a -Settings $s -Force | Out-Null`,
|
|
391
|
+
`Start-ScheduledTask -TaskName ${q(task)}`,
|
|
392
|
+
].join('; ')], { stdio: 'ignore', windowsHide: true, timeout: 20_000 });
|
|
393
|
+
return { ok: true, via: 'scheduled-task-new', task, port, profile };
|
|
394
|
+
} catch { /* 没有 PowerShell / 没有注册任务的权限,往下走 */ }
|
|
395
|
+
|
|
396
|
+
// 没有 PowerShell 的机器才用 schtasks.exe(本机它在黑名单里,永远失败)
|
|
397
|
+
try {
|
|
398
|
+
execFileSync('schtasks', ['/create', '/tn', task, '/tr', `"${edge}" ${quoted}`,
|
|
399
|
+
'/sc', 'once', '/st', '23:59', '/f'], { stdio: 'ignore', windowsHide: true, timeout: 15_000 });
|
|
400
|
+
execFileSync('schtasks', ['/run', '/tn', task], { stdio: 'ignore', windowsHide: true, timeout: 15_000 });
|
|
401
|
+
return { ok: true, via: 'schtasks', task, port, profile };
|
|
402
|
+
} catch { /* 没权限就往下走 */ }
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// 最后兜底:spawn。**它多半活不过调用方退出**(Job Object 会回收整棵子进程树),
|
|
406
|
+
// 只适合"起完立刻读一次"的场景。看到 via:'spawn' 就知道浏览器随时会消失。
|
|
407
|
+
try {
|
|
408
|
+
const child = spawn(edge, args, { detached: true, stdio: 'ignore' });
|
|
409
|
+
child.unref();
|
|
410
|
+
return { ok: true, via: 'spawn', pid: child.pid, port, profile };
|
|
411
|
+
} catch (e) {
|
|
412
|
+
return { ok: false, reason: String(e?.message ?? e).slice(0, 120) };
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/** 等端口起来(最多等 timeoutMs),返回是否起来了 */
|
|
417
|
+
export async function waitForPort(port, { timeoutMs = 8000, stepMs = 400 } = {}) {
|
|
418
|
+
const until = Date.now() + timeoutMs;
|
|
419
|
+
while (Date.now() < until) {
|
|
420
|
+
// eslint-disable-next-line no-await-in-loop
|
|
421
|
+
if ((await listTargets({ port, timeoutMs: 600 })) !== null) return true;
|
|
422
|
+
// eslint-disable-next-line no-await-in-loop
|
|
423
|
+
await new Promise((r) => setTimeout(r, stepMs));
|
|
424
|
+
}
|
|
425
|
+
return false;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/** 调试端口开没开(用于给用户一句明确的提示,而不是让功能悄悄退化) */
|
|
429
|
+
export async function hasDebugPort({ port = DEFAULT_PORT } = {}) {
|
|
430
|
+
return (await listTargets({ port })) !== null;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* 从浏览器里直接读 cookie,转成 Netscape 格式给 yt-dlp 用。
|
|
435
|
+
*
|
|
436
|
+
* 为什么比"手动导出"好:用户要做的只有一件事——**在带端口的那个窗口里登录一次**。
|
|
437
|
+
* 之后插件自己去要 cookie,不需要他找扩展、找文件、找路径。
|
|
438
|
+
*
|
|
439
|
+
* 走的是 CDP 的浏览器级端点(/json/version → Storage.getCookies),能拿到全部 cookie,
|
|
440
|
+
* 不受当前页面域限制。
|
|
441
|
+
*/
|
|
442
|
+
export async function readBrowserCookies({ port = DEFAULT_PORT, timeoutMs = 4000 } = {}) {
|
|
443
|
+
let wsUrl;
|
|
444
|
+
try {
|
|
445
|
+
const ac = new AbortController();
|
|
446
|
+
const timer = setTimeout(() => ac.abort(), timeoutMs);
|
|
447
|
+
const res = await fetch(`http://127.0.0.1:${port}/json/version`, { signal: ac.signal });
|
|
448
|
+
clearTimeout(timer);
|
|
449
|
+
if (!res.ok) return null;
|
|
450
|
+
const v = await res.json();
|
|
451
|
+
wsUrl = v?.webSocketDebuggerUrl;
|
|
452
|
+
} catch {
|
|
453
|
+
return null;
|
|
454
|
+
}
|
|
455
|
+
if (!wsUrl) return null;
|
|
456
|
+
|
|
457
|
+
const cookies = await new Promise((resolve) => {
|
|
458
|
+
let ws;
|
|
459
|
+
let done = false;
|
|
460
|
+
const finish = (v) => { if (done) return; done = true; try { ws?.close(); } catch { /* 已关 */ } resolve(v); };
|
|
461
|
+
const timer = setTimeout(() => finish(null), timeoutMs);
|
|
462
|
+
try { ws = new WebSocket(wsUrl); } catch { clearTimeout(timer); return resolve(null); }
|
|
463
|
+
ws.onopen = () => ws.send(JSON.stringify({ id: 1, method: 'Storage.getCookies' }));
|
|
464
|
+
ws.onmessage = (ev) => {
|
|
465
|
+
try {
|
|
466
|
+
const msg = JSON.parse(String(ev.data));
|
|
467
|
+
if (msg.id !== 1) return;
|
|
468
|
+
clearTimeout(timer);
|
|
469
|
+
finish(msg.result?.cookies ?? null);
|
|
470
|
+
} catch { clearTimeout(timer); finish(null); }
|
|
471
|
+
};
|
|
472
|
+
ws.onerror = () => { clearTimeout(timer); finish(null); };
|
|
473
|
+
ws.onclose = () => { clearTimeout(timer); finish(null); };
|
|
474
|
+
});
|
|
475
|
+
return Array.isArray(cookies) ? cookies : null;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
/** cookie 数组 → Netscape cookies.txt 文本(yt-dlp 认这个格式) */
|
|
479
|
+
export function cookiesToNetscape(cookies) {
|
|
480
|
+
const lines = ['# Netscape HTTP Cookie File', '# generated from the debug-port browser', ''];
|
|
481
|
+
for (const c of cookies ?? []) {
|
|
482
|
+
if (!c?.name || !c?.domain) continue;
|
|
483
|
+
const domain = c.domain.startsWith('.') ? c.domain : c.domain;
|
|
484
|
+
const includeSub = c.domain.startsWith('.') ? 'TRUE' : 'FALSE';
|
|
485
|
+
const expires = Number.isFinite(c.expires) && c.expires > 0 ? Math.floor(c.expires) : 0;
|
|
486
|
+
const secure = c.secure ? 'TRUE' : 'FALSE';
|
|
487
|
+
lines.push([domain, includeSub, c.path ?? '/', secure, expires, c.name, c.value ?? ''].join('\t'));
|
|
488
|
+
}
|
|
489
|
+
return `${lines.join('\n')}\n`;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
/** 把浏览器 cookie 落盘,返回文件路径(失败返回 null) */
|
|
493
|
+
export async function writeBrowserCookiesFile({ port = DEFAULT_PORT, dir = null } = {}) {
|
|
494
|
+
const cookies = await readBrowserCookies({ port });
|
|
495
|
+
if (!cookies || cookies.length === 0) return null;
|
|
496
|
+
const target = dir ?? join(homedir(), '.dsh', 'bili-cookies-from-browser.txt');
|
|
497
|
+
try {
|
|
498
|
+
mkdirSync(join(target, '..'), { recursive: true });
|
|
499
|
+
writeFileSync(target, cookiesToNetscape(cookies), 'utf8');
|
|
500
|
+
return target;
|
|
501
|
+
} catch {
|
|
502
|
+
return null;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cache.js — 扫描结果缓存。
|
|
3
|
+
*
|
|
4
|
+
* 缓存什么:切点、阈值、分数摘要。这三样只跟"(文件, 窗口, 阈值策略)"有关,
|
|
5
|
+
* 与格数/取帧方式无关,所以 storyboard 和 zoom 能共用同一份。
|
|
6
|
+
*
|
|
7
|
+
* **不缓存**响度序列:2 小时片子有 7 万个点,JSON 会涨到几百 KB;而音频解码比
|
|
8
|
+
* 视频解码便宜得多,重算更划算。
|
|
9
|
+
*
|
|
10
|
+
* 目录可用 DSH_VIDEO_CACHE_DIR 指定(C 盘紧张时指到别的盘)。
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { createHash } from 'node:crypto';
|
|
14
|
+
import { mkdir, readFile, readdir, stat, unlink, writeFile } from 'node:fs/promises';
|
|
15
|
+
import { homedir, tmpdir } from 'node:os';
|
|
16
|
+
import { join } from 'node:path';
|
|
17
|
+
|
|
18
|
+
// 缓存版本:**切点判定逻辑一变就要加 1** —— 版本进了 key,旧条目自动失效,不需要用户手清。
|
|
19
|
+
// 1 → 2:0.4.3 改了极静素材的相对基线判定(spikeCuts)、平铺格与 suppressClose 的用法,
|
|
20
|
+
// 旧缓存里的 cuts 与现在的算法不是一回事,留着会让"改了却看不出变化"。
|
|
21
|
+
// 2 → 3:扫描结果里新增了逐帧指纹(Uint8Array),而这里是 JSON.stringify —— 一旦被写进
|
|
22
|
+
// 条目就是几十 MB 的 {"0":12,…} 且类型全丢。现在指纹已改为不进缓存,升版本把可能写坏的条目作废。
|
|
23
|
+
// 3 → 4:扫描结果里新增了 darkRuns(黑场段)。旧条目没有这一项,命中后黑场会并回内容格,
|
|
24
|
+
// 同一支片子第一次跑和第二次跑出图不一样 —— 升版本让旧条目重扫一次。
|
|
25
|
+
export const CACHE_VERSION = 4;
|
|
26
|
+
/** 单独用(没有统一预算时)的默认上限;正常路径走 storage.js 的 300MB 总预算。 */
|
|
27
|
+
export const MAX_CACHE_BYTES = 50 * 1024 * 1024;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 这些文件不是"缓存":删了就丢状态(台词队列、看过哪、cell 映射、延迟标定)。
|
|
31
|
+
* 以前 pruneCache 会把所有 *.json 按 mtime 删,理论上包括 watch.json —— 台词会凭空消失。
|
|
32
|
+
*/
|
|
33
|
+
export const PROTECTED_FILES = Object.freeze([
|
|
34
|
+
'watch.json', 'seen.jsonl', 'latency.json', 'cells.json',
|
|
35
|
+
]);
|
|
36
|
+
|
|
37
|
+
export function cacheDir(env = process.env) {
|
|
38
|
+
if (env.DSH_VIDEO_CACHE_DIR) return env.DSH_VIDEO_CACHE_DIR;
|
|
39
|
+
if (process.platform === 'win32' && env.LOCALAPPDATA) {
|
|
40
|
+
return join(env.LOCALAPPDATA, 'dsh-video-storyboard', 'cache');
|
|
41
|
+
}
|
|
42
|
+
return join(env.XDG_CACHE_HOME || join(homedir(), '.cache'), 'dsh-video-storyboard');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* 缓存键:路径 + 大小 + mtime + 窗口 + 阈值模式。
|
|
47
|
+
* 不用文件内容 hash —— 2GB 的文件读一遍比重新扫描还慢。
|
|
48
|
+
*/
|
|
49
|
+
export async function cacheKey({ input, start, end, threshold }) {
|
|
50
|
+
let size = 0;
|
|
51
|
+
let mtime = 0;
|
|
52
|
+
try {
|
|
53
|
+
const st = await stat(input);
|
|
54
|
+
size = st.size;
|
|
55
|
+
mtime = Math.round(st.mtimeMs);
|
|
56
|
+
} catch {
|
|
57
|
+
return null; // 文件不可读就不缓存
|
|
58
|
+
}
|
|
59
|
+
const raw = [CACHE_VERSION, input, size, mtime, start ?? 0, end ?? 'eof', String(threshold)].join('|');
|
|
60
|
+
return createHash('sha1').update(raw).digest('hex').slice(0, 20);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export async function readCache(key, { dir = cacheDir() } = {}) {
|
|
64
|
+
if (!key) return null;
|
|
65
|
+
try {
|
|
66
|
+
const payload = JSON.parse(await readFile(join(dir, `${key}.json`), 'utf8'));
|
|
67
|
+
return payload?.v === CACHE_VERSION ? payload : null;
|
|
68
|
+
} catch {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export async function writeCache(key, value, { dir = cacheDir() } = {}) {
|
|
74
|
+
if (!key) return null;
|
|
75
|
+
try {
|
|
76
|
+
await mkdir(dir, { recursive: true });
|
|
77
|
+
const path = join(dir, `${key}.json`);
|
|
78
|
+
await writeFile(path, JSON.stringify({ v: CACHE_VERSION, at: Date.now(), ...value }), 'utf8');
|
|
79
|
+
return path;
|
|
80
|
+
} catch {
|
|
81
|
+
return null; // 缓存失败不能影响主流程
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** 当前 JSON 缓存占用(不含受保护的状态文件) */
|
|
86
|
+
export async function cacheBytes({ dir = cacheDir() } = {}) {
|
|
87
|
+
let entries = [];
|
|
88
|
+
try { entries = await readdir(dir); } catch { return 0; }
|
|
89
|
+
let total = 0;
|
|
90
|
+
for (const name of entries) {
|
|
91
|
+
if (!name.endsWith('.json') || PROTECTED_FILES.includes(name)) continue;
|
|
92
|
+
try { total += (await stat(join(dir, name))).size; } catch { /* 忽略 */ }
|
|
93
|
+
}
|
|
94
|
+
return total;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** 超过上限就按最久未用的删(简单 LRU) */
|
|
98
|
+
export async function pruneCache({ dir = cacheDir(), maxBytes = MAX_CACHE_BYTES } = {}) {
|
|
99
|
+
let entries;
|
|
100
|
+
try {
|
|
101
|
+
entries = await readdir(dir);
|
|
102
|
+
} catch {
|
|
103
|
+
return { removed: 0, bytes: 0 };
|
|
104
|
+
}
|
|
105
|
+
const files = [];
|
|
106
|
+
for (const name of entries) {
|
|
107
|
+
if (!name.endsWith('.json')) continue;
|
|
108
|
+
if (PROTECTED_FILES.includes(name)) continue;
|
|
109
|
+
try {
|
|
110
|
+
const st = await stat(join(dir, name));
|
|
111
|
+
files.push({ path: join(dir, name), size: st.size, at: st.mtimeMs });
|
|
112
|
+
} catch { /* 忽略 */ }
|
|
113
|
+
}
|
|
114
|
+
files.sort((a, b) => a.at - b.at);
|
|
115
|
+
let total = files.reduce((n, f) => n + f.size, 0);
|
|
116
|
+
let removed = 0;
|
|
117
|
+
for (const f of files) {
|
|
118
|
+
if (total <= maxBytes) break;
|
|
119
|
+
try {
|
|
120
|
+
await unlink(f.path);
|
|
121
|
+
total -= f.size;
|
|
122
|
+
removed += 1;
|
|
123
|
+
} catch { /* 忽略 */ }
|
|
124
|
+
}
|
|
125
|
+
return { removed, bytes: total };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* 包一层:命中就读,未命中就执行并写回。fails-open —— 缓存坏掉最多是"慢一点",
|
|
130
|
+
* 绝不能让分镜失败。
|
|
131
|
+
*
|
|
132
|
+
* producer 返回 null/undefined 时**原样返回**,不包成 `{cached:false}`:`{...null}` 出来的是
|
|
133
|
+
* 一个 **truthy 的空壳对象**,调用方写 `if (result)` 就会把自己骗过去 —— ASR 一条都没跑,
|
|
134
|
+
* 清单却写 "ASR ran and found no speech"(真实的假消息)。这类"什么都没做"的结果也不写缓存。
|
|
135
|
+
*/
|
|
136
|
+
export async function withCache(key, producer, opts = {}) {
|
|
137
|
+
const hit = await readCache(key, opts);
|
|
138
|
+
if (hit?.value) return { ...hit.value, cached: true };
|
|
139
|
+
const value = await producer();
|
|
140
|
+
if (value === null || value === undefined) return value;
|
|
141
|
+
await writeCache(key, { value }, opts);
|
|
142
|
+
return { ...value, cached: false };
|
|
143
|
+
}
|