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,21 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
import { isPeak, stepCost } from '../src/life/pricing.ts';
|
|
4
|
+
|
|
5
|
+
test('peak hours are Beijing weekday 9-12 and 14-18; weekends and statutory holidays are off-peak all day', () => {
|
|
6
|
+
assert.equal(isPeak(new Date('2026-10-23T02:00:00Z')), true, 'Friday 10:00 Beijing');
|
|
7
|
+
assert.equal(isPeak(new Date('2026-10-23T04:30:00Z')), false, 'Friday 12:30 Beijing');
|
|
8
|
+
assert.equal(isPeak(new Date('2026-10-23T07:00:00Z')), true, 'Friday 15:00 Beijing');
|
|
9
|
+
assert.equal(isPeak(new Date('2026-10-23T10:00:00Z')), false, 'Friday 18:00 Beijing');
|
|
10
|
+
assert.equal(isPeak(new Date('2026-10-24T02:00:00Z')), false, 'Saturday');
|
|
11
|
+
assert.equal(isPeak(new Date('2026-10-05T02:00:00Z')), false, 'National Day holiday, a Monday');
|
|
12
|
+
});
|
|
13
|
+
test('a step costs its cache hits, other input and output at the model\'s price; unknown models are priced as Flash', () => {
|
|
14
|
+
const usage = { inputTokens: 1_000_000, outputTokens: 1_000_000, cacheReadTokens: 1_000_000 };
|
|
15
|
+
const offPeak = new Date('2026-10-24T02:00:00Z'); const peak = new Date('2026-10-23T02:00:00Z');
|
|
16
|
+
assert.equal(stepCost(usage, 'deepseek-flash', offPeak), 0.02 + 1 + 4);
|
|
17
|
+
assert.equal(stepCost(usage, 'deepseek-flash', peak), 0.04 + 2 + 8);
|
|
18
|
+
assert.equal(stepCost(usage, 'deepseek-v4-pro', offPeak), 0.15 + 4.5 + 13.5);
|
|
19
|
+
assert.equal(stepCost(usage, 'some-other-model', offPeak), 0.02 + 1 + 4);
|
|
20
|
+
assert.equal(stepCost({ inputTokens: 0, outputTokens: 0 }, 'deepseek-flash', peak), 0);
|
|
21
|
+
});
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
import { Readable } from 'node:stream';
|
|
4
|
+
import { QQ_PREFIX, WRITE_HEADER, qqRoute } from '../src/ecosystem/qq/route.ts';
|
|
5
|
+
import type { QqBridge } from '../src/ecosystem/qq/bridge.ts';
|
|
6
|
+
|
|
7
|
+
function request(method: string, path: string, options: { body?: unknown; headers?: Record<string, string> } = {}) {
|
|
8
|
+
const text = options.body === undefined ? '' : JSON.stringify(options.body);
|
|
9
|
+
const stream = Readable.from(text ? [Buffer.from(text)] : []);
|
|
10
|
+
return Object.assign(stream, { method, url: QQ_PREFIX + path, headers: { host: '127.0.0.1:1707', ...options.headers } }) as never;
|
|
11
|
+
}
|
|
12
|
+
async function call(route: ReturnType<typeof qqRoute>, req: never) {
|
|
13
|
+
let status = 0;
|
|
14
|
+
let body = '';
|
|
15
|
+
const res = { writeHead: (code: number) => { status = code; }, end: (text: string) => { body = text; }, setHeader: () => {}, getHeader: () => undefined, headersSent: false } as never;
|
|
16
|
+
await route.handler(req, res);
|
|
17
|
+
return { status, body: body ? JSON.parse(body) : undefined };
|
|
18
|
+
}
|
|
19
|
+
function stub(overrides: Partial<QqBridge> = {}): QqBridge {
|
|
20
|
+
const base: QqBridge = {
|
|
21
|
+
status: async () => ({ running: true, port: 3100, dir: 'D:/qq-bridge', dsh: true, sessions: [], faults: [], intent: { desired: 'running', at: 0, by: 'test' } }),
|
|
22
|
+
start: async () => ({ started: true }),
|
|
23
|
+
stop: async () => ({ stopped: true }),
|
|
24
|
+
halt: async () => ({ stopped: true }),
|
|
25
|
+
intent: () => ({ desired: 'running', at: 0, by: 'test' }),
|
|
26
|
+
bind: async (key, sessionId) => ({ started: true, key, sessionId }),
|
|
27
|
+
unbind: async key => ({ started: true, key }),
|
|
28
|
+
ensureRunning: async () => ({ started: true }),
|
|
29
|
+
syncEndpoint: async () => ({ changed: false }),
|
|
30
|
+
proactive: async () => ({ enabled: false, dryRun: true, running: false }),
|
|
31
|
+
setProactive: async patch => ({ ok: true, config: patch }),
|
|
32
|
+
faults: () => [],
|
|
33
|
+
};
|
|
34
|
+
return { ...base, ...overrides };
|
|
35
|
+
}
|
|
36
|
+
const route = (bridge: QqBridge) => qqRoute(bridge);
|
|
37
|
+
|
|
38
|
+
test('QQ 状态是 GET,五扇门都是一个前缀下面', async () => {
|
|
39
|
+
const answered = await call(route(stub()), request('GET', '/'));
|
|
40
|
+
assert.equal(answered.status, 200);
|
|
41
|
+
assert.equal(answered.body.running, true);
|
|
42
|
+
const shaped = qqRoute(stub());
|
|
43
|
+
assert.deepEqual({ kind: shaped.kind, path: shaped.path }, { kind: 'prefix', path: '/dsh-world/qq' });
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('写操作必须带 x-dsh-world 头,跨站来的连读都不给', async () => {
|
|
47
|
+
assert.equal((await call(route(stub()), request('POST', '/start'))).status, 400);
|
|
48
|
+
assert.equal((await call(route(stub()), request('POST', '/start', { headers: { [WRITE_HEADER]: '1', 'sec-fetch-site': 'cross-site' } }))).status, 403);
|
|
49
|
+
const ok = await call(route(stub()), request('POST', '/start', { headers: { [WRITE_HEADER]: '1' } }));
|
|
50
|
+
assert.equal(ok.status, 200);
|
|
51
|
+
assert.equal(ok.body.started, true);
|
|
52
|
+
// 认不出来的路径是 404,不是把请求交给 console。
|
|
53
|
+
assert.equal((await call(route(stub()), request('POST', '/nope', { headers: { [WRITE_HEADER]: '1' } }))).status, 404);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('停桥和真停是两扇门:/stop 会重启,/halt 不会', async () => {
|
|
57
|
+
const seen: string[] = [];
|
|
58
|
+
const bridge = stub({
|
|
59
|
+
stop: async () => { seen.push('stop'); return { stopped: true }; },
|
|
60
|
+
halt: async () => { seen.push('halt'); return { stopped: true }; },
|
|
61
|
+
});
|
|
62
|
+
const headers = { [WRITE_HEADER]: '1' };
|
|
63
|
+
assert.equal((await call(route(bridge), request('POST', '/halt', { headers }))).status, 200);
|
|
64
|
+
assert.equal((await call(route(bridge), request('POST', '/stop', { headers }))).status, 200);
|
|
65
|
+
assert.deepEqual(seen, ['halt', 'stop']);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('绑定只接受 group:数字 和 private:数字,缺会话 id 直接拒', async () => {
|
|
69
|
+
const seen: string[] = [];
|
|
70
|
+
const bridge = stub({ bind: async (key, sessionId) => { seen.push(`${key}=${sessionId}`); return { started: false, key, sessionId }; } });
|
|
71
|
+
const headers = { [WRITE_HEADER]: '1' };
|
|
72
|
+
assert.equal((await call(route(bridge), request('POST', '/bind', { headers, body: { key: 'group:681528723' } }))).status, 400);
|
|
73
|
+
assert.equal((await call(route(bridge), request('POST', '/bind', { headers, body: { key: 'someone', sessionId: 'session-1' } }))).status, 400);
|
|
74
|
+
const ok = await call(route(bridge), request('POST', '/bind', { headers, body: { key: 'group:681528723', sessionId: 'session-1' } }));
|
|
75
|
+
assert.equal(ok.status, 200);
|
|
76
|
+
assert.deepEqual(seen, ['group:681528723=session-1']);
|
|
77
|
+
});
|
|
78
|
+
test('主动联系的两个开关走 POST,只认布尔,多余字段不给桥', async () => {
|
|
79
|
+
const seen: Array<Record<string, unknown>> = [];
|
|
80
|
+
const bridge = stub({ setProactive: async patch => { seen.push(patch); return { ok: true, config: patch }; } });
|
|
81
|
+
const headers = { [WRITE_HEADER]: '1' };
|
|
82
|
+
// 一个布尔都没给,就没得改
|
|
83
|
+
assert.equal((await call(route(bridge), request('POST', '/proactive', { headers, body: {} }))).status, 400);
|
|
84
|
+
assert.equal((await call(route(bridge), request('POST', '/proactive', { headers, body: { enabled: 'yes' } }))).status, 400);
|
|
85
|
+
// 只带一个就只改那一个;policy 这种不是开关的东西不转发
|
|
86
|
+
assert.equal((await call(route(bridge), request('POST', '/proactive', { headers, body: { enabled: true } }))).status, 200);
|
|
87
|
+
assert.equal((await call(route(bridge), request('POST', '/proactive', { headers, body: { dryRun: false, policy: { maxPerDay: 99 } } }))).status, 200);
|
|
88
|
+
assert.deepEqual(seen, [{ enabled: true }, { dryRun: false }]);
|
|
89
|
+
});
|
|
90
|
+
test('两个控制台的地址是读接口:一个来自桥的令牌文件,一个要用面板密码现换', async () => {
|
|
91
|
+
const doors = {
|
|
92
|
+
qq: () => ({ url: 'http://127.0.0.1:3100/?token=tok' }),
|
|
93
|
+
snowluma: async () => ({ needs: 'password' as const, url: 'http://127.0.0.1:5099' }),
|
|
94
|
+
remember: async () => ({ url: 'http://127.0.0.1:5099/?token=abc' }),
|
|
95
|
+
open: async () => ({ opened: true as const }),
|
|
96
|
+
};
|
|
97
|
+
const withDoors = await call(qqRoute(stub(), [], doors), request('GET', '/console'));
|
|
98
|
+
assert.equal(withDoors.status, 200);
|
|
99
|
+
assert.deepEqual(withDoors.body.qq, { url: 'http://127.0.0.1:3100/?token=tok' });
|
|
100
|
+
assert.deepEqual(withDoors.body.snowluma, { needs: 'password', url: 'http://127.0.0.1:5099' });
|
|
101
|
+
// 没接门的时候是老样子:说没有,不是 500。
|
|
102
|
+
assert.equal((await call(route(stub()), request('GET', '/console'))).status, 404);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('面板密码只走 POST,还得带 x-dsh-world 头;密码要是空的就别往磁盘上写', async () => {
|
|
106
|
+
const seen: string[] = [];
|
|
107
|
+
const doors = {
|
|
108
|
+
qq: () => ({ url: 'http://127.0.0.1:3100/?token=tok' }),
|
|
109
|
+
snowluma: async () => ({ needs: 'password' as const }),
|
|
110
|
+
remember: async (username: string, password: string) => { seen.push(`${username || 'admin'}:${password}`); return { url: 'http://127.0.0.1:5099/?token=abc' }; },
|
|
111
|
+
open: async () => ({ opened: true as const }),
|
|
112
|
+
};
|
|
113
|
+
const route_ = qqRoute(stub(), [], doors);
|
|
114
|
+
const headers = { [WRITE_HEADER]: '1' };
|
|
115
|
+
assert.equal((await call(route_, request('POST', '/panel-password', { body: { password: 'x' } }))).status, 400);
|
|
116
|
+
assert.equal((await call(route_, request('POST', '/panel-password', { headers, body: { password: '' } }))).status, 400);
|
|
117
|
+
const ok = await call(route_, request('POST', '/panel-password', { headers, body: { username: '', password: 'hunter2' } }));
|
|
118
|
+
assert.equal(ok.status, 200);
|
|
119
|
+
assert.deepEqual(ok.body.snowluma, { url: 'http://127.0.0.1:5099/?token=abc' });
|
|
120
|
+
assert.deepEqual(seen, ['admin:hunter2']);
|
|
121
|
+
});
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import { syncBridgeSessionMode } from '../src/ecosystem/qq/bridge.ts';
|
|
7
|
+
|
|
8
|
+
function makeBridge(config: unknown): string {
|
|
9
|
+
const dir = mkdtempSync(join(tmpdir(), 'dsh-world-qq-mode-'));
|
|
10
|
+
if (config !== undefined) writeFileSync(join(dir, 'config.json'), JSON.stringify(config, null, 2), 'utf8');
|
|
11
|
+
return dir;
|
|
12
|
+
}
|
|
13
|
+
function readConfig(dir: string): any {
|
|
14
|
+
return JSON.parse(readFileSync(join(dir, 'config.json'), 'utf8'));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
test('会话绑定:空值就一个字都不动桥的配置', () => {
|
|
18
|
+
const dir = makeBridge({ dsh: { baseUrl: 'http://127.0.0.1:6934' }, socialV2: { enabled: true } });
|
|
19
|
+
try {
|
|
20
|
+
const before = readFileSync(join(dir, 'config.json'), 'utf8');
|
|
21
|
+
const result = syncBridgeSessionMode(dir, '');
|
|
22
|
+
assert.equal(result.changed, false);
|
|
23
|
+
assert.equal(result.reason, 'no-mode');
|
|
24
|
+
assert.equal(readFileSync(join(dir, 'config.json'), 'utf8'), before);
|
|
25
|
+
} finally {
|
|
26
|
+
rmSync(dir, { recursive: true, force: true });
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('会话绑定:owner 写进去,别的键一个都不丢', () => {
|
|
31
|
+
const dir = makeBridge({ dsh: { baseUrl: 'http://127.0.0.1:6934' }, allow: { groups: ['456'] } });
|
|
32
|
+
try {
|
|
33
|
+
const result = syncBridgeSessionMode(dir, 'owner');
|
|
34
|
+
assert.equal(result.changed, true);
|
|
35
|
+
assert.equal(result.mode, 'owner');
|
|
36
|
+
assert.equal(result.before, '');
|
|
37
|
+
const config = readConfig(dir);
|
|
38
|
+
assert.equal(config.socialV2.bindHomeSession, 'owner');
|
|
39
|
+
assert.equal(config.dsh.baseUrl, 'http://127.0.0.1:6934');
|
|
40
|
+
assert.deepEqual(config.allow.groups, ['456']);
|
|
41
|
+
} finally {
|
|
42
|
+
rmSync(dir, { recursive: true, force: true });
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('会话绑定:同一个值不重复写盘', () => {
|
|
47
|
+
const dir = makeBridge({ socialV2: { bindHomeSession: 'owner' } });
|
|
48
|
+
try {
|
|
49
|
+
const stamp = readFileSync(join(dir, 'config.json'));
|
|
50
|
+
const result = syncBridgeSessionMode(dir, 'owner');
|
|
51
|
+
assert.equal(result.changed, false);
|
|
52
|
+
assert.equal(result.before, 'owner');
|
|
53
|
+
assert.deepEqual(readFileSync(join(dir, 'config.json')), stamp);
|
|
54
|
+
} finally {
|
|
55
|
+
rmSync(dir, { recursive: true, force: true });
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('会话绑定:owner 改 all 会覆盖,并交出旧值', () => {
|
|
60
|
+
const dir = makeBridge({ socialV2: { bindHomeSession: 'owner', enabled: true } });
|
|
61
|
+
try {
|
|
62
|
+
const result = syncBridgeSessionMode(dir, 'all');
|
|
63
|
+
assert.equal(result.changed, true);
|
|
64
|
+
assert.equal(result.before, 'owner');
|
|
65
|
+
const config = readConfig(dir);
|
|
66
|
+
assert.equal(config.socialV2.bindHomeSession, 'all');
|
|
67
|
+
assert.equal(config.socialV2.enabled, true);
|
|
68
|
+
} finally {
|
|
69
|
+
rmSync(dir, { recursive: true, force: true });
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('会话绑定:none 是把键删掉,不是写成空串', () => {
|
|
74
|
+
const dir = makeBridge({ socialV2: { bindHomeSession: 'owner', enabled: true } });
|
|
75
|
+
try {
|
|
76
|
+
const result = syncBridgeSessionMode(dir, 'none');
|
|
77
|
+
assert.equal(result.changed, true);
|
|
78
|
+
assert.equal(result.before, 'owner');
|
|
79
|
+
const config = readConfig(dir);
|
|
80
|
+
assert.equal('bindHomeSession' in config.socialV2, false);
|
|
81
|
+
assert.equal(config.socialV2.enabled, true);
|
|
82
|
+
assert.equal(syncBridgeSessionMode(dir, 'none').changed, false);
|
|
83
|
+
} finally {
|
|
84
|
+
rmSync(dir, { recursive: true, force: true });
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test('会话绑定:没有 config.json 时讲清原因,不抛', () => {
|
|
89
|
+
const dir = makeBridge(undefined);
|
|
90
|
+
try {
|
|
91
|
+
const result = syncBridgeSessionMode(dir, 'owner');
|
|
92
|
+
assert.equal(result.changed, false);
|
|
93
|
+
assert.match(String(result.reason), /config\.json 读不到/);
|
|
94
|
+
} finally {
|
|
95
|
+
rmSync(dir, { recursive: true, force: true });
|
|
96
|
+
}
|
|
97
|
+
});
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
import { createQqSupervisor } from '../src/ecosystem/qq/supervisor.ts';
|
|
4
|
+
import type { QqBridge } from '../src/ecosystem/qq/bridge.ts';
|
|
5
|
+
|
|
6
|
+
/** 一个只回答 start/intent 的假桥:这两个就是 supervisor 用到的全部能力。 */
|
|
7
|
+
function fakeBridge(options: {
|
|
8
|
+
desired?: 'running' | 'stopped';
|
|
9
|
+
started?: boolean;
|
|
10
|
+
startThrows?: boolean;
|
|
11
|
+
} = {}): { bridge: Pick<QqBridge, 'start' | 'halt' | 'intent'>; starts: () => number } {
|
|
12
|
+
let starts = 0;
|
|
13
|
+
return {
|
|
14
|
+
starts: () => starts,
|
|
15
|
+
bridge: {
|
|
16
|
+
intent: () => ({ desired: options.desired ?? 'running', at: 0, by: 'test' }),
|
|
17
|
+
async start() {
|
|
18
|
+
starts += 1;
|
|
19
|
+
if (options.startThrows) throw new Error('spawn 失败了');
|
|
20
|
+
return { started: options.started ?? true };
|
|
21
|
+
},
|
|
22
|
+
async halt() { return { stopped: true }; },
|
|
23
|
+
} as Pick<QqBridge, 'start' | 'halt' | 'intent'>,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** 临时替换全局 fetch:所有用例都不该真的连 3100(那可能是台在跑的桥)。 */
|
|
28
|
+
async function withFetch(
|
|
29
|
+
impl: () => Promise<Response> | Response,
|
|
30
|
+
run: () => Promise<void>,
|
|
31
|
+
): Promise<void> {
|
|
32
|
+
const original = globalThis.fetch;
|
|
33
|
+
globalThis.fetch = (async () => impl()) as typeof fetch;
|
|
34
|
+
try { await run(); } finally { globalThis.fetch = original; }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const okBody = (extra: Record<string, unknown> = {}): Response =>
|
|
38
|
+
new Response(JSON.stringify({ ok: true, dshReady: true, ...extra }), { status: 200 });
|
|
39
|
+
const fail503 = (): Response => new Response('{}', { status: 503 });
|
|
40
|
+
|
|
41
|
+
function supervisor(bridge: Pick<QqBridge, 'start' | 'halt' | 'intent'>, options: Record<string, unknown> = {}) {
|
|
42
|
+
return createQqSupervisor({
|
|
43
|
+
dir: 'Z:/no/such/bridge', // readConsoleToken 会读不到;mock 的 fetch 不看 token
|
|
44
|
+
bridge,
|
|
45
|
+
intervalMs: 5,
|
|
46
|
+
probeTimeoutMs: 200,
|
|
47
|
+
backoffBaseMs: 1,
|
|
48
|
+
random: () => 0.5, // 固定抖动,退避值可预测
|
|
49
|
+
...options,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
test('探到 200 且 dshReady → healthy', async () => {
|
|
54
|
+
const fake = fakeBridge();
|
|
55
|
+
const s = supervisor(fake.bridge);
|
|
56
|
+
await withFetch(okBody, async () => {
|
|
57
|
+
const snap = await s.probeOnce();
|
|
58
|
+
assert.equal(snap.state, 'healthy');
|
|
59
|
+
assert.equal(snap.dshReady, true);
|
|
60
|
+
assert.equal(snap.consecutiveFailures, 0);
|
|
61
|
+
assert.equal(snap.backoffMs, 0, '没在退避就别报时长,界面上「退避 5 秒」会误导人');
|
|
62
|
+
assert.equal(snap.lastError, undefined);
|
|
63
|
+
});
|
|
64
|
+
assert.equal(fake.starts(), 0);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('桥在线但 dshReady=false → degraded,且不重启桥', async () => {
|
|
68
|
+
// 这类故障是 baseUrl 过期(DSH 换了端口),重启桥只会白折腾一趟。
|
|
69
|
+
const fake = fakeBridge();
|
|
70
|
+
const s = supervisor(fake.bridge);
|
|
71
|
+
await withFetch(() => okBody({ dshReady: false }), async () => {
|
|
72
|
+
const snap = await s.probeOnce();
|
|
73
|
+
assert.equal(snap.state, 'degraded');
|
|
74
|
+
assert.equal(snap.dshReady, false);
|
|
75
|
+
assert.match(String(snap.lastError), /syncEndpoint/);
|
|
76
|
+
});
|
|
77
|
+
assert.equal(fake.starts(), 0, 'dshReady=false 不该触发重启');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('失败 1、2 次只报状态,第 3 次才拉起', async () => {
|
|
81
|
+
const fake = fakeBridge();
|
|
82
|
+
const s = supervisor(fake.bridge);
|
|
83
|
+
await withFetch(fail503, async () => {
|
|
84
|
+
assert.equal((await s.probeOnce()).state, 'degraded');
|
|
85
|
+
assert.equal(fake.starts(), 0);
|
|
86
|
+
assert.equal((await s.probeOnce()).consecutiveFailures, 2);
|
|
87
|
+
assert.equal(fake.starts(), 0, '两次还没到阈值');
|
|
88
|
+
const third = await s.probeOnce();
|
|
89
|
+
assert.equal(fake.starts(), 1, '第三次应该尝试拉起');
|
|
90
|
+
assert.equal(third.state, 'healthy');
|
|
91
|
+
assert.equal(third.restartsInWindow, 1);
|
|
92
|
+
assert.equal(third.consecutiveFailures, 0, '拉起成功后计数清零');
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test('用户主动停止(desired=stopped)时巡检不拉起', async () => {
|
|
97
|
+
const fake = fakeBridge({ desired: 'stopped' });
|
|
98
|
+
const s = supervisor(fake.bridge);
|
|
99
|
+
await withFetch(fail503, async () => {
|
|
100
|
+
const first = await s.probeOnce();
|
|
101
|
+
assert.equal(first.state, 'stopped', '第一次探测就该报 stopped,不该先跳 degraded');
|
|
102
|
+
assert.equal(first.consecutiveFailures, 0, '主动停止不算故障,不累计失败次数');
|
|
103
|
+
for (let i = 0; i < 4; i += 1) await s.probeOnce();
|
|
104
|
+
assert.equal(fake.starts(), 0, '停止是人的决定,巡检不该把手伸回去');
|
|
105
|
+
assert.equal(s.snapshot().state, 'stopped');
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test('拉起失败会退避,且退避时长随失败次数增长', async () => {
|
|
110
|
+
const fake = fakeBridge({ started: false });
|
|
111
|
+
const s = supervisor(fake.bridge);
|
|
112
|
+
await withFetch(fail503, async () => {
|
|
113
|
+
for (let i = 0; i < 3; i += 1) await s.probeOnce();
|
|
114
|
+
const first = s.snapshot();
|
|
115
|
+
assert.equal(fake.starts(), 1);
|
|
116
|
+
assert.equal(first.state, 'degraded', '退避等待结束后应该回到 degraded,而不是卡在 recovering');
|
|
117
|
+
assert.equal(first.backoffMs, 1, '第 1 次恢复失败:base(1) × 2^0 × 抖动(1.0)');
|
|
118
|
+
// 再累积 3 次失败,退避翻倍。
|
|
119
|
+
for (let i = 0; i < 3; i += 1) await s.probeOnce();
|
|
120
|
+
assert.equal(fake.starts(), 2);
|
|
121
|
+
assert.equal(s.snapshot().backoffMs, 2, '第 2 次恢复失败:base(1) × 2^1 × 抖动(1.0)');
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test('10 分钟窗口内拉起次数超上限就停在 failed,不再动手', async () => {
|
|
126
|
+
// start 报成功但桥立刻又挂:这是「拉了也没用」的形态,必须停下来。
|
|
127
|
+
const fake = fakeBridge({ started: true });
|
|
128
|
+
const s = supervisor(fake.bridge, { maxRestartsPerWindow: 2 });
|
|
129
|
+
await withFetch(fail503, async () => {
|
|
130
|
+
for (let i = 0; i < 9; i += 1) await s.probeOnce();
|
|
131
|
+
const snap = s.snapshot();
|
|
132
|
+
assert.equal(fake.starts(), 2, '上限 2 次之后不该再拉');
|
|
133
|
+
assert.equal(snap.state, 'failed');
|
|
134
|
+
assert.match(String(snap.lastError), /已自动拉起 2 次/);
|
|
135
|
+
assert.equal(snap.restartsInWindow, 2);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test('start 抛异常不会把巡检打死', async () => {
|
|
140
|
+
const fake = fakeBridge({ startThrows: true });
|
|
141
|
+
const s = supervisor(fake.bridge);
|
|
142
|
+
await withFetch(fail503, async () => {
|
|
143
|
+
for (let i = 0; i < 3; i += 1) await s.probeOnce();
|
|
144
|
+
const snap = s.snapshot();
|
|
145
|
+
assert.equal(fake.starts(), 1);
|
|
146
|
+
assert.match(String(snap.lastError), /spawn 失败了/);
|
|
147
|
+
assert.equal(snap.state, 'degraded');
|
|
148
|
+
});
|
|
149
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
4
|
+
import { createSourceArchive, isCorruptSessionLog } from '../src/sourceArchive.ts';
|
|
5
|
+
import type { ArchiveStore } from '../src/store.ts';
|
|
6
|
+
|
|
7
|
+
class SessionPersistenceNotFoundError extends Error { override name = 'SessionPersistenceNotFoundError'; }
|
|
8
|
+
const config = { worldId: 'fish', agentPreset: 'companion', timeZone: 'UTC' } as never;
|
|
9
|
+
|
|
10
|
+
/** Two archived sessions, "a" first; `open` decides how each one fares. */
|
|
11
|
+
function fixture(open: (id: string) => Promise<unknown>, stored: (id: string) => boolean = () => true) {
|
|
12
|
+
const opened: string[] = []; const forgotten: string[] = []; const warned: string[] = []; const errored: unknown[] = [];
|
|
13
|
+
let served = false;
|
|
14
|
+
const store = {
|
|
15
|
+
sourcePage: (after: string) => { if (after || served) return []; served = true; return ['a', 'b']; },
|
|
16
|
+
progress: () => ({ nextSeq: 0, turn: 0 }),
|
|
17
|
+
commitRecords: async () => {},
|
|
18
|
+
forgetProgress: (id: string) => { forgotten.push(id); },
|
|
19
|
+
} as unknown as ArchiveStore;
|
|
20
|
+
const ctx = {
|
|
21
|
+
sessions: { get: () => undefined, flush: async () => {} },
|
|
22
|
+
sessionPersistence: { list: async () => [], stat: async (id: string) => (stored(id) ? {} : undefined), open: async (id: string) => { opened.push(id); return open(id); } },
|
|
23
|
+
logger: { warn: (message: string) => warned.push(message), error: (error: unknown) => errored.push(error) },
|
|
24
|
+
} as unknown as Context;
|
|
25
|
+
return { archive: createSourceArchive(ctx, config, store), opened, forgotten, warned, errored };
|
|
26
|
+
}
|
|
27
|
+
const emptyLog = { header: {}, inheritedEventCount: 0, read: async () => ({ events: [] }), close: async () => {} };
|
|
28
|
+
|
|
29
|
+
test('a session whose log vanished is skipped with a warning and does not count as a failure', async () => {
|
|
30
|
+
const { archive, warned, forgotten } = fixture(async id => { if (id === 'a') throw new SessionPersistenceNotFoundError('a'); return emptyLog; });
|
|
31
|
+
await archive.catchUp();
|
|
32
|
+
await archive.flush();
|
|
33
|
+
assert.deepEqual(forgotten, ['a']);
|
|
34
|
+
assert.equal(warned.length, 1); assert.match(warned[0], /session a is no longer stored/);
|
|
35
|
+
});
|
|
36
|
+
test('one session failing does not stop catch-up of the next, and flush still reports it', async () => {
|
|
37
|
+
const { archive, opened } = fixture(async id => { if (id === 'a') throw new Error('disk error'); return emptyLog; });
|
|
38
|
+
await archive.catchUp();
|
|
39
|
+
assert.deepEqual(opened, ['a', 'b']);
|
|
40
|
+
await assert.rejects(archive.flush(), /unresolved failures/);
|
|
41
|
+
});
|
|
42
|
+
test('catch-up forgets the resume point of a session the host no longer has, and reads the others', async () => {
|
|
43
|
+
const { archive, opened, forgotten } = fixture(async () => emptyLog, id => id !== 'a');
|
|
44
|
+
await archive.catchUp();
|
|
45
|
+
await archive.flush();
|
|
46
|
+
assert.deepEqual(forgotten, ['a']);
|
|
47
|
+
assert.deepEqual(opened, ['b']);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('读不动的会话日志只丢那一份,不拖垮整个插件', () => {
|
|
51
|
+
// 这几种都是宿主的原文:坏在哪都无所谓,要紧的是认出它。
|
|
52
|
+
assert.equal(isCorruptSessionLog(new Error('stored log is corrupt: unexpected end of file')), true);
|
|
53
|
+
assert.equal(isCorruptSessionLog(Object.assign(new Error('boom'), { name: 'SessionFormatError' })), true);
|
|
54
|
+
assert.equal(isCorruptSessionLog(new Error('system/message does not match an open turn and step')), true);
|
|
55
|
+
// 别的错误照旧往外抛,不能被这道网兜住。
|
|
56
|
+
assert.equal(isCorruptSessionLog(new Error('EACCES: permission denied')), false);
|
|
57
|
+
assert.equal(isCorruptSessionLog(undefined), false);
|
|
58
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
import { mkdtemp, readFile, rm, appendFile, writeFile, mkdir, truncate } from 'node:fs/promises';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { tmpdir } from 'node:os';
|
|
6
|
+
import { spawn } from 'node:child_process';
|
|
7
|
+
import { createArchiveStore } from '../src/store.ts';
|
|
8
|
+
import { record } from './fixtures.ts';
|
|
9
|
+
|
|
10
|
+
async function setup(t: test.TestContext) {
|
|
11
|
+
const root = await mkdtemp(join(tmpdir(), 'dsh-world-'));
|
|
12
|
+
const stores: ReturnType<typeof createArchiveStore>[] = [];
|
|
13
|
+
const open = () => { const store = createArchiveStore({ root, worldId: 'fish', timeZone: 'Asia/Seoul', agentPreset: 'companion' }); stores.push(store); return store; };
|
|
14
|
+
t.after(async () => { for (const s of stores) s.close(); await rm(root, { recursive: true, force: true }); });
|
|
15
|
+
return { root, open, path: (date: string) => join(root, 'worlds/fish/conversations', `${date}.jsonl`) };
|
|
16
|
+
}
|
|
17
|
+
test('midnight files preserve actual timestamps, turn identity and replay uniqueness', async t => {
|
|
18
|
+
const s = await setup(t); const store = s.open();
|
|
19
|
+
const records = [record('a', { occurredAt: '2026-10-23T14:59:59.000Z', turnId: 'same' }), record('b', { occurredAt: '2026-10-23T15:00:00.000Z', turnId: 'same' })];
|
|
20
|
+
await store.commitRecords(records); await store.commitRecords(records);
|
|
21
|
+
for (const [day, r] of [['2026-10-23', records[0]], ['2026-10-24', records[1]]] as const) assert.deepEqual((await readFile(s.path(day), 'utf8')).trim().split('\n').map(line => JSON.parse(line)), [r]);
|
|
22
|
+
});
|
|
23
|
+
test('stable pagination excludes later appends including backdated records', async t => {
|
|
24
|
+
const s = await setup(t); const store = s.open();
|
|
25
|
+
await store.commitRecords(['a', 'b', 'c', 'd'].map(id => record(id)));
|
|
26
|
+
const first = await store.readPage({ worldId: 'fish', limit: 2 });
|
|
27
|
+
assert.deepEqual(first.records.map(r => r.recordId), ['d', 'c']);
|
|
28
|
+
await store.commitRecords([record('e'), record('aa')]);
|
|
29
|
+
const second = await store.readPage({ worldId: 'fish', before: first.nextCursor, limit: 2 });
|
|
30
|
+
assert.deepEqual(second.records.map(r => r.recordId), ['b', 'a']);
|
|
31
|
+
assert.equal(second.nextCursor, undefined);
|
|
32
|
+
});
|
|
33
|
+
test('failed export reports error and recovers canonical records plus source progress on reopen', async t => {
|
|
34
|
+
const s = await setup(t); const store = s.open();
|
|
35
|
+
await mkdir(s.path('2026-10-23'));
|
|
36
|
+
await assert.rejects(store.commitRecords([record('a')], { sessionId: 'a', nextSeq: 4, turn: 1 }), /archive write failed/);
|
|
37
|
+
await rm(s.path('2026-10-23'), { recursive: true });
|
|
38
|
+
store.close(); const resumed = s.open();
|
|
39
|
+
assert.equal(resumed.progress('a').nextSeq, 4);
|
|
40
|
+
assert.deepEqual((await resumed.readPage({ worldId: 'fish', limit: 10 })).records.map(r => r.recordId), ['a']);
|
|
41
|
+
});
|
|
42
|
+
test('crash after file write before progress and partial tail recover without duplication', async t => {
|
|
43
|
+
const s = await setup(t); const store = s.open();
|
|
44
|
+
await mkdir(s.path('2026-10-23'));
|
|
45
|
+
await assert.rejects(store.commitRecords([record('a'), record('b')]), /archive write failed/);
|
|
46
|
+
await rm(s.path('2026-10-23'), { recursive: true });
|
|
47
|
+
await writeFile(s.path('2026-10-23'), JSON.stringify(record('a')) + '\n' + JSON.stringify(record('b')).slice(0, 30));
|
|
48
|
+
store.close(); const resumed = s.open();
|
|
49
|
+
await resumed.readPage({ worldId: 'fish', limit: 10 });
|
|
50
|
+
assert.equal((await readFile(s.path('2026-10-23'), 'utf8')).trim().split('\n').length, 2);
|
|
51
|
+
});
|
|
52
|
+
test('a shortened export is rebuilt from the database on the next write to that day', async t => {
|
|
53
|
+
const s = await setup(t); const store = s.open();
|
|
54
|
+
await store.commitRecords([record('a'), record('b')]);
|
|
55
|
+
await truncate(s.path('2026-10-23'), 0);
|
|
56
|
+
await store.commitRecords([record('c')]);
|
|
57
|
+
assert.deepEqual((await readFile(s.path('2026-10-23'), 'utf8')).trim().split('\n').map(line => JSON.parse(line).recordId), ['a', 'b', 'c']);
|
|
58
|
+
});
|
|
59
|
+
test('separate processes can write the same world day safely', async t => {
|
|
60
|
+
const s = await setup(t); s.open();
|
|
61
|
+
const run = (prefix: string) => new Promise<void>((resolve, reject) => {
|
|
62
|
+
const child = spawn(process.execPath, ['--experimental-strip-types', '--disable-warning=ExperimentalWarning', 'tests/storeWriter.ts', s.root, prefix], { cwd: process.cwd(), stdio: ['ignore', 'pipe', 'pipe'] });
|
|
63
|
+
let error = ''; child.stderr.on('data', data => error += data); child.on('error', reject); child.on('exit', code => code === 0 ? resolve() : reject(new Error(error)));
|
|
64
|
+
});
|
|
65
|
+
await Promise.all([run('left'), run('right')]);
|
|
66
|
+
const rows = (await readFile(s.path('2026-10-23'), 'utf8')).trim().split('\n').map(line => JSON.parse(line));
|
|
67
|
+
assert.equal(rows.length, 40); assert.equal(new Set(rows.map(r => r.recordId)).size, 40);
|
|
68
|
+
});
|
|
69
|
+
test('a worldId that would leave the worlds directory is refused; the same world reopens under another time zone', async t => {
|
|
70
|
+
const s = await setup(t); await s.open().commitRecords([record('a')]);
|
|
71
|
+
assert.throws(() => createArchiveStore({ root: s.root, worldId: '../other', timeZone: 'UTC', agentPreset: 'companion' }), /worldId/);
|
|
72
|
+
const moved = createArchiveStore({ root: s.root, worldId: 'fish', timeZone: 'UTC', agentPreset: 'companion' });
|
|
73
|
+
try { assert.deepEqual((await moved.readPage({ worldId: 'fish', limit: 10 })).records.map(r => r.recordId), ['a']); } finally { moved.close(); }
|
|
74
|
+
});
|
|
75
|
+
test('stats count records and distinct source sessions', async t => {
|
|
76
|
+
const root = await mkdtemp(join(tmpdir(), 'dsh-world-stats-'));
|
|
77
|
+
const store = createArchiveStore({ root, worldId: 'fish', agentPreset: 'companion', timeZone: 'UTC' });
|
|
78
|
+
t.after(() => store.close());
|
|
79
|
+
t.after(() => rm(root, { recursive: true, force: true }));
|
|
80
|
+
await store.commitRecords([record('a1', { sourceSessionId: 's1' }), record('a2', { sourceSessionId: 's1' }), record('a3', { sourceSessionId: 's2' })]);
|
|
81
|
+
assert.deepEqual(store.stats(), { records: 3, sessions: 2 });
|
|
82
|
+
});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { createArchiveStore } from '../src/store.ts';
|
|
2
|
+
import { record } from './fixtures.ts';
|
|
3
|
+
const store = createArchiveStore({ root: process.argv[2], worldId: 'fish', timeZone: 'Asia/Seoul', agentPreset: 'companion' });
|
|
4
|
+
try { for (let i = 0; i < 20; i++) await store.commitRecords([record(`${process.argv[3]}${i}`)]); }
|
|
5
|
+
finally { store.close(); }
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
import { formatTimeContext } from '../src/timeContext.ts';
|
|
4
|
+
|
|
5
|
+
test('request time is exactly two lines in the configured zone', () => {
|
|
6
|
+
assert.equal(formatTimeContext(new Date('2026-10-23T12:30:00Z'), 'Asia/Seoul'), '当前时间:2026-10-23T21:30:00+09:00\n时区:Asia/Seoul');
|
|
7
|
+
});
|
|
8
|
+
test('UTC, fractional offsets and daylight saving follow the named zone', () => {
|
|
9
|
+
for (const [input, zone, expected] of [
|
|
10
|
+
['2026-10-23T12:30:00Z', 'UTC', '2026-10-23T12:30:00+00:00'],
|
|
11
|
+
['2026-10-23T12:30:00Z', 'Asia/Kathmandu', '2026-10-23T18:15:00+05:45'],
|
|
12
|
+
['2026-01-23T12:30:00Z', 'America/New_York', '2026-01-23T07:30:00-05:00'],
|
|
13
|
+
['2026-07-23T12:30:00Z', 'America/New_York', '2026-07-23T08:30:00-04:00'],
|
|
14
|
+
]) assert.equal(formatTimeContext(new Date(input), zone), `当前时间:${expected}\n时区:${zone}`);
|
|
15
|
+
});
|