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,103 @@
|
|
|
1
|
+
"""OCR 桥:给 Node 侧调用,负责"找字幕带 + 只识别"。
|
|
2
|
+
|
|
3
|
+
为什么要单独一个 Python 脚本:OCR 生态(rapidocr / PaddleOCR)都在 Python 侧,
|
|
4
|
+
而插件是 Node。走一次 subprocess 换 JSON,比在 Node 里重造一套中文 OCR 现实得多。
|
|
5
|
+
|
|
6
|
+
两个模式:
|
|
7
|
+
detect 全图检测 2–3 帧,找出"字幕带"(宽、居中、置信度够的文字行的 y 区间)
|
|
8
|
+
read 已知字幕带,只跑识别(不做检测)—— 实测 3108 ms/帧 → 261 ms/帧
|
|
9
|
+
|
|
10
|
+
输出一律是 JSON,失败也返回 {"ok": false, "error": ...},不抛栈给 Node。
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import json
|
|
14
|
+
import sys
|
|
15
|
+
|
|
16
|
+
# 同 watch_smtc.py:Windows 默认 cp936,中文会变乱码
|
|
17
|
+
try:
|
|
18
|
+
sys.stdout.reconfigure(encoding="utf-8")
|
|
19
|
+
except Exception: # noqa: BLE001
|
|
20
|
+
pass
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _fail(msg):
|
|
24
|
+
print(json.dumps({"ok": False, "error": str(msg)}, ensure_ascii=False))
|
|
25
|
+
sys.exit(0)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _engine():
|
|
29
|
+
try:
|
|
30
|
+
from rapidocr_onnxruntime import RapidOCR
|
|
31
|
+
except Exception as e: # noqa: BLE001
|
|
32
|
+
_fail(f"rapidocr_onnxruntime not installed: {e}")
|
|
33
|
+
return RapidOCR
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def detect(paths):
|
|
37
|
+
RapidOCR = _engine()
|
|
38
|
+
ocr = RapidOCR()
|
|
39
|
+
from PIL import Image
|
|
40
|
+
|
|
41
|
+
boxes = []
|
|
42
|
+
width = height = None
|
|
43
|
+
for p in paths:
|
|
44
|
+
im = Image.open(p)
|
|
45
|
+
width, height = im.size
|
|
46
|
+
res, _ = ocr(p)
|
|
47
|
+
for item in res or []:
|
|
48
|
+
box, txt, conf = item[0], str(item[1]), float(item[2])
|
|
49
|
+
xs = [float(pt[0]) for pt in box]
|
|
50
|
+
ys = [float(pt[1]) for pt in box]
|
|
51
|
+
w = max(xs) - min(xs)
|
|
52
|
+
# 字幕的特征:宽(占画面 35% 以上)、居中、置信度不太低
|
|
53
|
+
if w / width < 0.35 or conf < 0.55:
|
|
54
|
+
continue
|
|
55
|
+
boxes.append({"y0": min(ys), "y1": max(ys), "w": w, "text": txt, "conf": round(conf, 3)})
|
|
56
|
+
|
|
57
|
+
if boxes:
|
|
58
|
+
y0 = min(b["y0"] for b in boxes)
|
|
59
|
+
y1 = max(b["y1"] for b in boxes)
|
|
60
|
+
pad = (y1 - y0) * 0.6 + 8
|
|
61
|
+
band = [max(0.0, (y0 - pad) / height), min(1.0, (y1 + pad) / height)]
|
|
62
|
+
else:
|
|
63
|
+
# 没找到也不失败:给中下区域兜底,让调用方决定要不要信
|
|
64
|
+
band = [0.42, 0.68]
|
|
65
|
+
|
|
66
|
+
print(json.dumps({
|
|
67
|
+
"ok": True,
|
|
68
|
+
"size": [width, height],
|
|
69
|
+
"band": [round(band[0], 4), round(band[1], 4)],
|
|
70
|
+
"boxes": boxes[:12],
|
|
71
|
+
"detected": bool(boxes),
|
|
72
|
+
}, ensure_ascii=False))
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def read(paths):
|
|
76
|
+
RapidOCR = _engine()
|
|
77
|
+
ocr = RapidOCR(use_det=False, use_cls=False, use_rec=True)
|
|
78
|
+
|
|
79
|
+
out = []
|
|
80
|
+
for p in paths:
|
|
81
|
+
try:
|
|
82
|
+
res, _ = ocr(p)
|
|
83
|
+
texts = [str(x[1]) for x in (res or [])]
|
|
84
|
+
confs = [float(x[2]) for x in (res or [])]
|
|
85
|
+
out.append({
|
|
86
|
+
"text": " ".join(texts).strip(),
|
|
87
|
+
"conf": round(sum(confs) / len(confs), 3) if confs else 0.0,
|
|
88
|
+
})
|
|
89
|
+
except Exception as e: # noqa: BLE001
|
|
90
|
+
out.append({"text": "", "conf": 0.0, "error": str(e)[:120]})
|
|
91
|
+
print(json.dumps({"ok": True, "items": out}, ensure_ascii=False))
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
if __name__ == "__main__":
|
|
95
|
+
if len(sys.argv) < 3:
|
|
96
|
+
_fail("usage: ocr_bridge.py detect|read <image> [<image> ...]")
|
|
97
|
+
mode, imgs = sys.argv[1], sys.argv[2:]
|
|
98
|
+
if mode == "detect":
|
|
99
|
+
detect(imgs)
|
|
100
|
+
elif mode == "read":
|
|
101
|
+
read(imgs)
|
|
102
|
+
else:
|
|
103
|
+
_fail(f"unknown mode: {mode}")
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* asr-lifecycle.js — 让本地 ASR 服务"用完就走"。
|
|
3
|
+
*
|
|
4
|
+
* 背景(2026-10-28,三次死机):本地 ASR 服务常驻要吃约 6.8 GB 提交额度。
|
|
5
|
+
* 这台 16 GB 的机器上,它和 Premiere / 大项目同时存在就会把提交上限撞穿,
|
|
6
|
+
* 表现为 dwm 崩 0xc00001ad、桌面黑屏、整机卡死。
|
|
7
|
+
*
|
|
8
|
+
* 插件**不会**自己去拉起别人的服务 —— 除非用户在 `~/.dsh/asr.json` 里显式写了 `manage.start`。
|
|
9
|
+
* 一旦写了,就按下面的契约办:
|
|
10
|
+
*
|
|
11
|
+
* 1. 转录前:端点活着 → 什么都不做(owned=false,不碰别人的进程)
|
|
12
|
+
* 2. 端点死了 → 跑 manage.start,等它 ready(最多 waitMs)
|
|
13
|
+
* 3. 本次运行结束 → 只有"是我们拉起来的"才安排停止;到点前又有请求就取消停止
|
|
14
|
+
*
|
|
15
|
+
* 关键设计:**只杀自己拉起来的那个**。别人(另一个插件、你自己开的窗口)启动的实例,
|
|
16
|
+
* 我们无权杀 —— 杀了会把正在用它的任务打断。
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { spawn } from 'node:child_process';
|
|
20
|
+
import { existsSync } from 'node:fs';
|
|
21
|
+
import { dirname, join } from 'node:path';
|
|
22
|
+
|
|
23
|
+
const SHELL_EXE = 'cmd.exe';
|
|
24
|
+
|
|
25
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* `start` 写成 `.py` 时补上解释器。
|
|
29
|
+
*
|
|
30
|
+
* 真实事故:`"start": "D:/asr-local/server-sherpa.py"` —— Windows 上直接 spawn 一个 .py 什么也不会发生,
|
|
31
|
+
* 于是每次转写都是 ECONNREFUSED,看起来像"自启没成功"。这里按 <脚本目录>/.venv 找解释器,找不到用 PATH 里的。
|
|
32
|
+
*/
|
|
33
|
+
function resolveScriptStart(start) {
|
|
34
|
+
if (typeof start !== 'string' || !/\.py$/i.test(start)) return start;
|
|
35
|
+
const dir = dirname(start);
|
|
36
|
+
const candidates = process.platform === 'win32'
|
|
37
|
+
? [join(dir, '.venv', 'Scripts', 'python.exe')]
|
|
38
|
+
: [join(dir, '.venv', 'bin', 'python')];
|
|
39
|
+
for (const py of candidates) {
|
|
40
|
+
if (existsSync(py)) return [py, start];
|
|
41
|
+
}
|
|
42
|
+
return [process.platform === 'win32' ? 'python' : 'python3', start];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** 从 asr.json 的配置里取出生命周期设置(没有就返回 null,表示不托管) */
|
|
46
|
+
export function lifecycleConfig(config = {}) {
|
|
47
|
+
const m = config?.manage;
|
|
48
|
+
if (!m || typeof m !== 'object' || !m.start) return null;
|
|
49
|
+
// start 可以是字符串(.cmd/.exe)或数组([exe, ...args])。
|
|
50
|
+
// **数组更干净**:Windows 上起 .cmd 会闪一个控制台窗口,而且批处理对行尾/编码很敏感
|
|
51
|
+
// (LF 行尾会让 cmd.exe 把注释片段当命令执行 —— 实测弹出一屏 "'wo' 不是内部或外部命令")。
|
|
52
|
+
const raw = Array.isArray(m.start) ? m.start.map(String) : String(m.start);
|
|
53
|
+
const start = resolveScriptStart(raw);
|
|
54
|
+
return {
|
|
55
|
+
start,
|
|
56
|
+
stop: m.stop ? String(m.stop) : null,
|
|
57
|
+
waitMs: Number.isFinite(m.waitMs) ? m.waitMs : 120_000,
|
|
58
|
+
// 默认 10 分钟:冷启动要 30 秒,2 分钟就关等于每次都要重付这 30 秒。
|
|
59
|
+
// 语义是"最后一次运行结束后 10 分钟没有新运行就关"。
|
|
60
|
+
idleMs: Number.isFinite(m.idleMs) ? m.idleMs : 600_000,
|
|
61
|
+
healthPath: typeof m.healthPath === 'string' ? m.healthPath : '/health',
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** 端点是否已经在应答(/health 不通就退到 /v1/models,兼容不支持 /health 的服务) */
|
|
66
|
+
export async function probeEndpoint(baseUrl, { fetchImpl = fetch, timeoutMs = 1500, healthPath = '/health' } = {}) {
|
|
67
|
+
const root = String(baseUrl ?? '').replace(/\/v1\/?$/, '').replace(/\/$/, '');
|
|
68
|
+
if (!root) return false;
|
|
69
|
+
for (const path of [healthPath, '/v1/models']) {
|
|
70
|
+
try {
|
|
71
|
+
const ctrl = new AbortController();
|
|
72
|
+
const timer = setTimeout(() => ctrl.abort(), timeoutMs);
|
|
73
|
+
const res = await fetchImpl(`${root}${path}`, { signal: ctrl.signal });
|
|
74
|
+
clearTimeout(timer);
|
|
75
|
+
if (res.ok) return true;
|
|
76
|
+
} catch {
|
|
77
|
+
/* 换下一个探测点 */
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* 让服务自己退出(POST /shutdown)。比按 pid 杀可靠得多 ——
|
|
85
|
+
* Windows 上 start 出来的壳进程会先退出,真正的 pid 谁也拿不到。
|
|
86
|
+
* 服务若不支持这个端点(返回 404),调用方再退回按端口杀。
|
|
87
|
+
*/
|
|
88
|
+
export async function stopViaHttp(baseUrl, { fetchImpl = fetch, timeoutMs = 3000 } = {}) {
|
|
89
|
+
const root = String(baseUrl ?? '').replace(/\/v1\/?$/, '').replace(/\/$/, '');
|
|
90
|
+
if (!root) return false;
|
|
91
|
+
try {
|
|
92
|
+
const ctrl = new AbortController();
|
|
93
|
+
const timer = setTimeout(() => ctrl.abort(), timeoutMs);
|
|
94
|
+
const res = await fetchImpl(`${root}/shutdown`, { method: 'POST', signal: ctrl.signal });
|
|
95
|
+
clearTimeout(timer);
|
|
96
|
+
return res.ok;
|
|
97
|
+
} catch {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** 从 baseUrl 里抠出端口(默认 80/443) */
|
|
103
|
+
export function portOf(baseUrl) {
|
|
104
|
+
try {
|
|
105
|
+
const u = new URL(String(baseUrl).replace(/\/v1\/?$/, ''));
|
|
106
|
+
return Number(u.port) || (u.protocol === 'https:' ? 443 : 80);
|
|
107
|
+
} catch {
|
|
108
|
+
return 8000;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* 找出监听这个端口的进程号。
|
|
114
|
+
*
|
|
115
|
+
* 为什么需要:Windows 上 `start /b script.cmd` 会**立刻退出**,我们手上那个 pid 是壳的,
|
|
116
|
+
* 壳一退就没了句柄 —— 而真正吃内存的 python 还在。只能按端口反查。
|
|
117
|
+
*/
|
|
118
|
+
export async function findPidByPort(port, { execImpl } = {}) {
|
|
119
|
+
const run = execImpl ?? (await import('node:child_process')).execFile;
|
|
120
|
+
const cmdline = process.platform === 'win32'
|
|
121
|
+
? ['netstat', ['-ano', '-p', 'tcp']]
|
|
122
|
+
: ['lsof', ['-nP', `-iTCP:${port}`, '-sTCP:LISTEN', '-t']];
|
|
123
|
+
return await new Promise((resolve) => {
|
|
124
|
+
run(cmdline[0], cmdline[1], { timeout: 4000 }, (err, stdout) => {
|
|
125
|
+
if (err || !stdout) return resolve(null);
|
|
126
|
+
if (process.platform === 'win32') {
|
|
127
|
+
const line = stdout.split(/\r?\n/).find((l) => new RegExp(`[:.]${port}\\s.*LISTENING`, 'i').test(l));
|
|
128
|
+
const m = line && line.trim().match(/(\d+)\s*$/);
|
|
129
|
+
resolve(m ? Number(m[1]) : null);
|
|
130
|
+
} else {
|
|
131
|
+
resolve(Number(stdout.trim().split(/\s+/)[0]) || null);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/* 只保留一个"待停止"的定时器:连续几次调用应该共用一个实例,而不是起了又杀 */
|
|
138
|
+
let pendingStop = null;
|
|
139
|
+
let ownedChild = null;
|
|
140
|
+
|
|
141
|
+
/** 取消即将发生的停止(同一会话里连续调用时,不该把服务杀了重开) */
|
|
142
|
+
export function keepAlive() {
|
|
143
|
+
if (pendingStop) {
|
|
144
|
+
clearTimeout(pendingStop);
|
|
145
|
+
pendingStop = null;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* 确保 ASR 可用。返回 { owned, started }:
|
|
151
|
+
* - owned=true 表示**这个进程是我们拉起来的**,运行结束可以停
|
|
152
|
+
* - owned=false 表示它本来就在跑,不碰
|
|
153
|
+
*/
|
|
154
|
+
export async function ensureAsr({
|
|
155
|
+
// spawnImpl 以前没有默认值:任何不传它的调用都会在启动时抛 "spawnImpl is not a function",
|
|
156
|
+
// 而这个错误只会在"本地服务没起来、需要拉一次"的时候出现 —— 平时测不到。
|
|
157
|
+
baseUrl, config, env = process.env, spawnImpl = spawn, fetchImpl = fetch, log = () => {},
|
|
158
|
+
} = {}) {
|
|
159
|
+
const life = lifecycleConfig(config);
|
|
160
|
+
const alive = await probeEndpoint(baseUrl, { fetchImpl, healthPath: life?.healthPath });
|
|
161
|
+
if (alive) {
|
|
162
|
+
keepAlive();
|
|
163
|
+
return { owned: false, started: false };
|
|
164
|
+
}
|
|
165
|
+
if (!life) return { owned: false, started: false, reason: 'no manage.start configured' };
|
|
166
|
+
|
|
167
|
+
log(`starting local ASR: ${Array.isArray(life.start) ? life.start.join(' ') : life.start}`);
|
|
168
|
+
let child;
|
|
169
|
+
if (Array.isArray(life.start)) {
|
|
170
|
+
// 直接起 exe:windowsHide 才会真的不建控制台窗口,也不受批处理编码影响
|
|
171
|
+
// **不要 detached**:Windows 上 `detached: true` 会创建新的控制台窗口,
|
|
172
|
+
// 即使同时给了 windowsHide —— 实际表现就是"每拉起一次 ASR 就弹一个黑框挡住画面"。
|
|
173
|
+
// 不 detached 时子进程挂在 DSH 进程下,同样能跨工具调用存活(服务本来就是长期进程),
|
|
174
|
+
// 停止仍走 /shutdown 或 taskkill /T。
|
|
175
|
+
child = spawnImpl(life.start[0], life.start.slice(1), {
|
|
176
|
+
detached: false, stdio: 'ignore', windowsHide: true, env,
|
|
177
|
+
});
|
|
178
|
+
} else {
|
|
179
|
+
const isBatch = /\.(cmd|bat)$/i.test(life.start);
|
|
180
|
+
child = process.platform === 'win32' && isBatch
|
|
181
|
+
? spawnImpl(SHELL_EXE, ['/c', 'start', '', '/b', life.start], {
|
|
182
|
+
detached: false, stdio: 'ignore', windowsHide: true, env,
|
|
183
|
+
})
|
|
184
|
+
: spawnImpl(life.start, [], {
|
|
185
|
+
shell: true, detached: false, stdio: 'ignore', windowsHide: true, env,
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
child.unref?.();
|
|
189
|
+
ownedChild = child;
|
|
190
|
+
|
|
191
|
+
const deadline = Date.now() + life.waitMs;
|
|
192
|
+
while (Date.now() < deadline) {
|
|
193
|
+
await sleep(1000);
|
|
194
|
+
if (await probeEndpoint(baseUrl, { fetchImpl, healthPath: life.healthPath })) {
|
|
195
|
+
log('local ASR is ready');
|
|
196
|
+
keepAlive();
|
|
197
|
+
// 壳进程可能已经退了,按端口找出真正在听的那个
|
|
198
|
+
const real = await findPidByPort(portOf(baseUrl ?? ''));
|
|
199
|
+
if (real) ownedChild = { pid: real };
|
|
200
|
+
return { owned: true, started: true, pid: real ?? child.pid };
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return { owned: true, started: true, pid: child.pid, timedOut: true };
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* 运行结束后安排停止。只有 owned 的实例才会被停。
|
|
208
|
+
* 到点前如果又来了请求(keepAlive),这次停止会被取消。
|
|
209
|
+
*/
|
|
210
|
+
export function scheduleStop({ owned, config, killImpl, baseUrl, minIdleMs } = {}) {
|
|
211
|
+
if (!owned) return false;
|
|
212
|
+
const life = lifecycleConfig(config);
|
|
213
|
+
if (!life) return false;
|
|
214
|
+
// 陪看这类"持续调用"的场景要临时放宽空闲窗口:否则每段之间服务就被关了,
|
|
215
|
+
// 下一段又要冷启动(实测 5 s,用户感知为"每次都要等")。
|
|
216
|
+
if (Number.isFinite(minIdleMs) && minIdleMs > life.idleMs) life.idleMs = minIdleMs;
|
|
217
|
+
keepAlive();
|
|
218
|
+
const pid = ownedChild?.pid;
|
|
219
|
+
pendingStop = setTimeout(() => {
|
|
220
|
+
pendingStop = null;
|
|
221
|
+
try {
|
|
222
|
+
if (killImpl) killImpl(pid, life);
|
|
223
|
+
else if (baseUrl && life.quietShutdown !== false) {
|
|
224
|
+
// 首选:请它自己退出(服务端 /shutdown);不支持时再按端口杀
|
|
225
|
+
stopViaHttp(baseUrl).then((ok) => {
|
|
226
|
+
if (ok || !pid) return;
|
|
227
|
+
if (process.platform === 'win32') {
|
|
228
|
+
import('node:child_process')
|
|
229
|
+
.then(({ execFile }) => execFile('taskkill', ['/PID', String(pid), '/T', '/F'], () => {}))
|
|
230
|
+
.catch(() => {});
|
|
231
|
+
} else { try { process.kill(pid, 'SIGTERM'); } catch { /* 已退出 */ } }
|
|
232
|
+
}).catch(() => {});
|
|
233
|
+
} else if (pid) {
|
|
234
|
+
if (process.platform === 'win32') {
|
|
235
|
+
// 连子树一起杀;start /b 起的 python 不在我们的句柄里,只能靠 /T
|
|
236
|
+
import('node:child_process')
|
|
237
|
+
.then(({ execFile }) => execFile('taskkill', ['/PID', String(pid), '/T', '/F'], () => {}))
|
|
238
|
+
.catch(() => {});
|
|
239
|
+
} else {
|
|
240
|
+
try { process.kill(pid, 'SIGTERM'); } catch { /* 已退出 */ }
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
} catch {
|
|
244
|
+
/* 已经不在了 */
|
|
245
|
+
}
|
|
246
|
+
ownedChild = null;
|
|
247
|
+
}, life.idleMs);
|
|
248
|
+
pendingStop.unref?.();
|
|
249
|
+
return true;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/** 测试用:清掉内部状态 */
|
|
253
|
+
export function __resetLifecycle() {
|
|
254
|
+
keepAlive();
|
|
255
|
+
ownedChild = null;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** 当前是否有"我们拉起的"实例还活着(用于运行开始时决定要不要续命) */
|
|
259
|
+
export function isOwned() {
|
|
260
|
+
return Boolean(ownedChild?.pid);
|
|
261
|
+
}
|
|
262
|
+
|