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,86 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
import { mkdtempSync, rmSync } from 'node:fs';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import { Context } from '@deepseek-ai/cordis';
|
|
7
|
+
import { createWorldSwitch } from '../src/worldSwitch.ts';
|
|
8
|
+
import { createArchiveSelection } from '../src/archiveSelection.ts';
|
|
9
|
+
import { createArchiveStore } from '../src/store.ts';
|
|
10
|
+
import { createHistory } from '../src/history.ts';
|
|
11
|
+
import { record } from './fixtures.ts';
|
|
12
|
+
import { SessionId } from '@deepseek-ai/dsh-session';
|
|
13
|
+
import { createUserMessage, type GenerateOptions } from '@deepseek-ai/dsh-llm';
|
|
14
|
+
import { hostFixture, textResponse } from './hostFixture.ts';
|
|
15
|
+
import { createWorldRuntime } from '../src/runtime.ts';
|
|
16
|
+
|
|
17
|
+
test('saving archive scope requires restart and preserves the active scope until then', t => {
|
|
18
|
+
const dir = mkdtempSync(join(tmpdir(), 'dw-scope-')); t.after(() => rmSync(dir, { recursive: true, force: true }));
|
|
19
|
+
const settings = createWorldSwitch(dir, 'home');
|
|
20
|
+
assert.equal(settings.archiveScope(), 'home');
|
|
21
|
+
settings.setArchiveScope('workspace');
|
|
22
|
+
assert.equal(settings.archiveScope(), 'home');
|
|
23
|
+
assert.equal(settings.selectedArchiveScope(), 'workspace');
|
|
24
|
+
assert.equal(settings.restartRequired(), true);
|
|
25
|
+
const restarted = createWorldSwitch(dir, 'home');
|
|
26
|
+
assert.equal(restarted.archiveScope(), 'workspace');
|
|
27
|
+
assert.equal(restarted.restartRequired(), false);
|
|
28
|
+
settings.setArchiveScope('home');
|
|
29
|
+
assert.equal(settings.restartRequired(), false);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('workspace scope uses the workspace owning home, includes groups and ignores presets', () => {
|
|
33
|
+
const ctx = new Context();
|
|
34
|
+
ctx.provide('workspaceRegistry', { list: () => [
|
|
35
|
+
{ path: 'room', sessionIds: ['home', 'family', 'another-preset'] },
|
|
36
|
+
{ path: 'other', sessionIds: ['unrelated'] },
|
|
37
|
+
] });
|
|
38
|
+
const includes = createArchiveSelection(ctx, 'workspace', id => id === 'home', 'room');
|
|
39
|
+
for (const id of ['home', 'family', 'another-preset']) assert.equal(includes(id), true);
|
|
40
|
+
assert.equal(includes('unrelated'), false);
|
|
41
|
+
const onlyHome = createArchiveSelection(ctx, 'home', id => id === 'home', 'room');
|
|
42
|
+
assert.equal(onlyHome('home'), true); assert.equal(onlyHome('family'), false);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('narrowing memory filters old broader archive records without deleting them', async t => {
|
|
46
|
+
const root = mkdtempSync(join(tmpdir(), 'dw-history-scope-'));
|
|
47
|
+
const store = createArchiveStore({ root, worldId: 'fish', agentPreset: 'test', timeZone: 'UTC' });
|
|
48
|
+
t.after(() => { store.close(); rmSync(root, { recursive: true, force: true }); });
|
|
49
|
+
await store.commitRecords([
|
|
50
|
+
record('home', { sourceSessionId: 'home', turnId: 'home:1', occurredAt: '2026-10-25T01:00:00Z' }),
|
|
51
|
+
record('group', { sourceSessionId: 'family', turnId: 'family:1', occurredAt: '2026-10-26T01:00:00Z' }),
|
|
52
|
+
]);
|
|
53
|
+
const turns = await createHistory(store).loadRecentTurns('fish', 200, id => id === 'home');
|
|
54
|
+
assert.deepEqual(turns.map(turn => turn.turnId), ['home:1']);
|
|
55
|
+
assert.equal(store.stats().records, 2);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('restart discovers cold workspace sessions and replaces an older broad memory block', async t => {
|
|
59
|
+
const requests: GenerateOptions[] = [];
|
|
60
|
+
const { ctx, root, cleanup } = await hostFixture(t, request => { requests.push(request); return textResponse('ok'); });
|
|
61
|
+
const config = { worldId: 'fish', agentPreset: 'companion', timeZone: 'UTC', archiveScope: 'workspace' as const };
|
|
62
|
+
const store = createArchiveStore({ ...config, root }); cleanup.push(() => store.close());
|
|
63
|
+
const included = new Set(['home', 'family', 'different']);
|
|
64
|
+
const agents = [];
|
|
65
|
+
const user = (text: string) => createUserMessage({ source: { kind: 'user' }, content: [{ type: 'text', text }] });
|
|
66
|
+
for (const id of ['home', 'family', 'different', 'foreign']) {
|
|
67
|
+
const { agent } = await ctx.agents.create({ sessionId: SessionId(id), meta: { agentPreset: id === 'different' ? 'other' : 'companion' }, agentOptions: { provider: 'test', model: 'test' } });
|
|
68
|
+
agent.followup(user(id + '-original')); await agent.whenIdle(); await ctx.sessions.flush(agent.session); agents.push(agent);
|
|
69
|
+
}
|
|
70
|
+
const source = { prompt: { names: { companion: '鱼', partner: '我' } }, isHome: (id: string) => id === 'home', archiveSession: (id: string) => included.has(id) };
|
|
71
|
+
const broad = createWorldRuntime(ctx, config, store, source); await broad.start();
|
|
72
|
+
const archived = (await store.readPage({ worldId: 'fish', limit: 100 })).records.map(row => row.content);
|
|
73
|
+
for (const text of ['home-original', 'family-original', 'different-original']) assert.ok(archived.includes(text), text);
|
|
74
|
+
assert.ok(!archived.includes('foreign-original'));
|
|
75
|
+
const home = agents[0]; home.followup(user('first home request')); await home.whenIdle(); await broad.flush();
|
|
76
|
+
assert.match(JSON.stringify(requests.at(-1)?.messages.filter(message => message.source?.kind === 'dsh-world-history')), /family-original/);
|
|
77
|
+
await broad.stop();
|
|
78
|
+
const narrow = createWorldRuntime(ctx, { ...config, archiveScope: 'home' }, store, { ...source, archiveSession: source.isHome });
|
|
79
|
+
cleanup.push(() => narrow.stop()); await narrow.start();
|
|
80
|
+
home.followup(user('after restart')); await home.whenIdle();
|
|
81
|
+
await narrow.flush();
|
|
82
|
+
const blocks = requests.at(-1)!.messages.filter(message => message.source?.kind === 'dsh-world-history');
|
|
83
|
+
assert.ok(blocks.length <= 1);
|
|
84
|
+
assert.doesNotMatch(JSON.stringify(blocks), /family-original|different-original|foreign-original/);
|
|
85
|
+
assert.ok((await store.readPage({ worldId: 'fish', limit: 100 })).records.some(row => row.content === 'family-original'), 'old archive retained');
|
|
86
|
+
});
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
import { existsSync } from 'node:fs';
|
|
4
|
+
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import { Readable } from 'node:stream';
|
|
7
|
+
import { createUserMessage, ToolCallId, type GenerateOptions, type StreamChunk } from '@deepseek-ai/dsh-llm';
|
|
8
|
+
import { SessionId } from '@deepseek-ai/dsh-session';
|
|
9
|
+
import { defineTool } from '@deepseek-ai/dsh-tools';
|
|
10
|
+
import { hostFixture, textResponse } from './hostFixture.ts';
|
|
11
|
+
import { createBridge, HomeUnavailable, REPLY_TIMEOUT_MS, type Bridge } from '../src/ecosystem/bridge/bridge.ts';
|
|
12
|
+
import { BRIDGE_PATH, bridgeRoute } from '../src/ecosystem/bridge/route.ts';
|
|
13
|
+
import type { Push } from '../src/ecosystem/shared/outlets.ts';
|
|
14
|
+
|
|
15
|
+
const tick = () => new Promise(resolve => setImmediate(resolve));
|
|
16
|
+
const userMessage = (text: string) => createUserMessage({ source: { kind: 'user' }, content: [{ type: 'text', text }] });
|
|
17
|
+
const userTexts = (request: GenerateOptions) => request.messages.filter(m => m.role === 'user' && m.source?.kind === 'user').map(m => m.content.filter(b => b.type === 'text').map(b => b.text).join(''));
|
|
18
|
+
function fakeTimers(clock: { now: Date }) {
|
|
19
|
+
let pending: { fn: () => void; at: number }[] = [];
|
|
20
|
+
return {
|
|
21
|
+
set(fn: () => void, ms: number) { const entry = { fn, at: clock.now.getTime() + ms }; pending.push(entry); return entry; },
|
|
22
|
+
clear(handle: unknown) { pending = pending.filter(entry => entry !== handle); },
|
|
23
|
+
advance(ms: number) { clock.now = new Date(clock.now.getTime() + ms); const due = pending.filter(entry => entry.at <= clock.now.getTime()); pending = pending.filter(entry => !due.includes(entry)); for (const entry of due) entry.fn(); },
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
async function* textThenTool(text: string, name: string, id = `${name}-call`): AsyncIterable<StreamChunk> {
|
|
27
|
+
yield { type: 'block-start', index: 0, blockType: 'text' };
|
|
28
|
+
yield { type: 'text-delta', index: 0, text };
|
|
29
|
+
yield { type: 'block-end', index: 0, block: { type: 'text', text } };
|
|
30
|
+
const block = { type: 'tool-call' as const, id: ToolCallId(id), name, arguments: '{}' };
|
|
31
|
+
yield { type: 'block-start', index: 1, blockType: 'tool-call' };
|
|
32
|
+
yield { type: 'tool-call-delta', index: 1, id: block.id, name, argumentsDelta: '{}' };
|
|
33
|
+
yield { type: 'block-end', index: 1, block };
|
|
34
|
+
yield { type: 'finish', reason: { kind: 'tool-calls' } };
|
|
35
|
+
}
|
|
36
|
+
async function* toolOnly(name: string, id = `${name}-call`): AsyncIterable<StreamChunk> {
|
|
37
|
+
const block = { type: 'tool-call' as const, id: ToolCallId(id), name, arguments: '{}' };
|
|
38
|
+
yield { type: 'block-start', index: 0, blockType: 'tool-call' };
|
|
39
|
+
yield { type: 'tool-call-delta', index: 0, id: block.id, name, argumentsDelta: '{}' };
|
|
40
|
+
yield { type: 'block-end', index: 0, block };
|
|
41
|
+
yield { type: 'finish', reason: { kind: 'tool-calls' } };
|
|
42
|
+
}
|
|
43
|
+
const testTool = (name: string, execute: () => Promise<string>) => defineTool({ name, description: 'test', parameters: {}, output: { schema: { type: 'string' }, render: (_args, value) => [{ type: 'text', text: value }] }, execute });
|
|
44
|
+
|
|
45
|
+
async function setup(t: test.TestContext, model: (request: GenerateOptions, index: number) => AsyncIterable<StreamChunk>) {
|
|
46
|
+
const requests: GenerateOptions[] = [];
|
|
47
|
+
const { ctx, root, cleanup, errors } = await hostFixture(t, request => { requests.push(request); return model(request, requests.length - 1); });
|
|
48
|
+
const home = (await ctx.agents.create({ sessionId: SessionId('home'), meta: { agentPreset: 'companion' }, agentOptions: { provider: 'test', model: 'test' } })).agent;
|
|
49
|
+
const clock = { now: new Date('2026-10-23T03:00:00.000Z') }; const timers = fakeTimers(clock);
|
|
50
|
+
const pushes: Omit<Push, 'name'>[] = []; const names: string[] = []; const reachOnly: Push[] = []; const control = { pushFails: false, homeFails: undefined as string | undefined };
|
|
51
|
+
const file = join(root, 'world', 'bridge.json'); await mkdir(join(root, 'world'), { recursive: true });
|
|
52
|
+
const make = (bridgeFile = file) => createBridge({
|
|
53
|
+
ctx, file: bridgeFile, origin: () => 'http://127.0.0.1:5173', timers, clock: () => clock.now,
|
|
54
|
+
home: async () => { if (control.homeFails) throw new Error(control.homeFails); return home; },
|
|
55
|
+
outlets: [
|
|
56
|
+
{ name: '桌面桌宠', kinds: ['reply', 'busy', 'reach'], send: async ({ name, ...push }) => { names.push(name); pushes.push(push); if (control.pushFails) throw new Error('connect ECONNREFUSED'); } },
|
|
57
|
+
{ name: '只要 reach', kinds: ['reach'], send: async push => { reachOnly.push(push); } },
|
|
58
|
+
],
|
|
59
|
+
});
|
|
60
|
+
const bridge = make(); bridge.start(); cleanup.push(() => bridge.stop());
|
|
61
|
+
/** A home turn held inside a tool until `release()`. */
|
|
62
|
+
let release!: () => void; const gate = new Promise<void>(resolve => { release = resolve; });
|
|
63
|
+
let entered!: () => void; const playing = new Promise<void>(resolve => { entered = resolve; });
|
|
64
|
+
ctx.tools.register(testTool('play_game', async () => { entered(); await gate; return 'played'; }));
|
|
65
|
+
ctx.tools.register(testTool('look', async () => 'a puzzle'));
|
|
66
|
+
const busy = async () => { home.followup(userMessage('先玩会儿')); await playing; assert.equal(home.status, 'running'); };
|
|
67
|
+
const idle = async () => { await home.whenIdle(); await tick(); await tick(); };
|
|
68
|
+
return { ctx, root, home, bridge, make, file, pushes, names, reachOnly, control, requests, errors, timers, release, busy, idle };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
test('her partner\'s words reach an idle home as a followup from the user, and her reply goes to the pet', async t => {
|
|
72
|
+
const s = await setup(t, () => textResponse('\n**在的**,刚醒'));
|
|
73
|
+
const { id } = await s.bridge.say('在吗');
|
|
74
|
+
await s.idle();
|
|
75
|
+
assert.equal(s.requests.length, 1);
|
|
76
|
+
const sent = s.requests[0]!.messages.find(m => m.source?.kind === 'user')!;
|
|
77
|
+
assert.equal(sent.id, id); assert.deepEqual(userTexts(s.requests[0]!), ['在吗']);
|
|
78
|
+
assert.deepEqual(s.pushes, [{ text: '在的,刚醒', kind: 'reply', images: ['http://127.0.0.1:5173/m/a?size=150'] }]);
|
|
79
|
+
assert.deepEqual(s.names, ['TA'], 'an unnamed companion is TA'); assert.deepEqual(s.reachOnly, [], 'an outlet that takes only reach gets no reply');
|
|
80
|
+
assert.deepEqual(s.errors, []);
|
|
81
|
+
});
|
|
82
|
+
test('while she is busy the words are steered into the running turn, and the reply is her first visible text after them', async t => {
|
|
83
|
+
const s = await setup(t, (_request, index) => index === 0 ? textThenTool('我去玩游戏了', 'play_game') : index === 1 ? toolOnly('look') : index === 2 ? textResponse('在玩消消乐') : textResponse('不该出现'));
|
|
84
|
+
await s.busy();
|
|
85
|
+
await s.bridge.say('在玩什么');
|
|
86
|
+
s.release(); await s.idle();
|
|
87
|
+
assert.equal(s.requests.length, 3, 'the words entered the same turn at the next step');
|
|
88
|
+
assert.deepEqual(userTexts(s.requests[1]!), ['先玩会儿', '在玩什么']);
|
|
89
|
+
assert.deepEqual(s.pushes, [{ text: '在玩消消乐', kind: 'reply' }]);
|
|
90
|
+
});
|
|
91
|
+
test('a sentence she was already saying when the words arrived is not taken as the reply', async t => {
|
|
92
|
+
let release!: () => void; const gate = new Promise<void>(resolve => { release = resolve; });
|
|
93
|
+
let entered!: () => void; const speaking = new Promise<void>(resolve => { entered = resolve; });
|
|
94
|
+
const s = await setup(t, (_request, index) => index === 0 ? (async function* () { entered(); await gate; yield* textResponse('我在自言自语'); })() : textResponse('听到你了'));
|
|
95
|
+
s.home.followup(userMessage('先说会儿')); await speaking;
|
|
96
|
+
await s.bridge.say('喂');
|
|
97
|
+
release(); await s.idle();
|
|
98
|
+
assert.equal(s.requests.length, 2); assert.deepEqual(userTexts(s.requests[1]!), ['先说会儿', '喂']);
|
|
99
|
+
assert.deepEqual(s.pushes, [{ text: '听到你了', kind: 'reply' }]);
|
|
100
|
+
});
|
|
101
|
+
test('only the reply after the latest of several messages is pushed', async t => {
|
|
102
|
+
const s = await setup(t, (_request, index) => index === 0 ? toolOnly('play_game') : textResponse('两句都听到了'));
|
|
103
|
+
await s.busy();
|
|
104
|
+
await s.bridge.say('第一句'); await s.bridge.say('第二句');
|
|
105
|
+
s.release(); await s.idle();
|
|
106
|
+
assert.deepEqual(userTexts(s.requests[1]!), ['先玩会儿', '第一句', '第二句']);
|
|
107
|
+
assert.deepEqual(s.pushes, [{ text: '两句都听到了', kind: 'reply' }]);
|
|
108
|
+
s.timers.advance(REPLY_TIMEOUT_MS); await tick();
|
|
109
|
+
assert.equal(s.pushes.length, 1, 'no busy after the reply');
|
|
110
|
+
});
|
|
111
|
+
test('no reply within three minutes pushes busy, and the later reply is still pushed', async t => {
|
|
112
|
+
const s = await setup(t, (_request, index) => index === 0 ? toolOnly('play_game') : textResponse('忙完啦'));
|
|
113
|
+
await s.busy();
|
|
114
|
+
await s.bridge.say('在吗');
|
|
115
|
+
s.timers.advance(REPLY_TIMEOUT_MS - 1); await tick();
|
|
116
|
+
assert.equal(s.pushes.length, 0);
|
|
117
|
+
s.timers.advance(1); await tick();
|
|
118
|
+
assert.deepEqual([...s.pushes], [{ text: 'TA在忙,忙完会在家里回你', kind: 'busy' }]);
|
|
119
|
+
s.release(); await s.idle();
|
|
120
|
+
assert.deepEqual([...s.pushes], [{ text: 'TA在忙,忙完会在家里回你', kind: 'busy' }, { text: '忙完啦', kind: 'reply' }]);
|
|
121
|
+
});
|
|
122
|
+
test('a failed push is a fault until the next push works', async t => {
|
|
123
|
+
const s = await setup(t, () => textResponse('嗯'));
|
|
124
|
+
s.control.pushFails = true;
|
|
125
|
+
await s.bridge.say('在吗'); await s.idle();
|
|
126
|
+
assert.deepEqual(s.bridge.faults(), ['桌面桌宠没收到TA的回复:connect ECONNREFUSED']);
|
|
127
|
+
s.control.pushFails = false;
|
|
128
|
+
await s.bridge.say('再试'); await s.idle();
|
|
129
|
+
assert.deepEqual(s.bridge.faults(), []); assert.equal(s.pushes.length, 2);
|
|
130
|
+
});
|
|
131
|
+
test('a home that cannot be opened rejects the words and is a fault', async t => {
|
|
132
|
+
const s = await setup(t, () => textResponse('嗯'));
|
|
133
|
+
s.control.homeFails = 'resolve failed';
|
|
134
|
+
await assert.rejects(s.bridge.say('在吗'), HomeUnavailable);
|
|
135
|
+
assert.deepEqual(s.bridge.faults(), ['从外面送来的话没进家:resolve failed']);
|
|
136
|
+
assert.equal(s.requests.length, 0);
|
|
137
|
+
s.control.homeFails = undefined;
|
|
138
|
+
await s.bridge.say('在吗'); await s.idle();
|
|
139
|
+
assert.deepEqual(s.bridge.faults(), []);
|
|
140
|
+
});
|
|
141
|
+
test('bridge.json carries the origin, a fresh token, the pid and the start time, and is removed on stop', async t => {
|
|
142
|
+
const s = await setup(t, () => textResponse('嗯'));
|
|
143
|
+
const written = JSON.parse(await readFile(s.file, 'utf8'));
|
|
144
|
+
assert.deepEqual(Object.keys(written).sort(), ['name', 'origin', 'pid', 'startedAt', 'token']); assert.equal(written.name, 'TA');
|
|
145
|
+
assert.equal(written.origin, 'http://127.0.0.1:5173'); assert.equal(written.pid, process.pid);
|
|
146
|
+
assert.equal(written.startedAt, '2026-10-23T03:00:00.000Z'); assert.match(written.token, /^[0-9a-f]{64}$/);
|
|
147
|
+
assert.ok(s.bridge.checkToken(written.token)); assert.ok(!s.bridge.checkToken(written.token.slice(1))); assert.ok(!s.bridge.checkToken(undefined));
|
|
148
|
+
const other = s.make(join(s.root, 'other.json')); other.start();
|
|
149
|
+
assert.notEqual(JSON.parse(await readFile(join(s.root, 'other.json'), 'utf8')).token, written.token);
|
|
150
|
+
other.stop(); assert.ok(!existsSync(join(s.root, 'other.json')));
|
|
151
|
+
s.bridge.stop(); assert.ok(!existsSync(s.file));
|
|
152
|
+
await assert.rejects(s.bridge.say('在吗'), HomeUnavailable);
|
|
153
|
+
});
|
|
154
|
+
test('stop leaves a bridge.json that a newer start wrote', async t => {
|
|
155
|
+
const s = await setup(t, () => textResponse('嗯'));
|
|
156
|
+
await writeFile(s.file, JSON.stringify({ origin: 'x', token: 'newer', pid: 1, startedAt: 'x' }));
|
|
157
|
+
s.bridge.stop();
|
|
158
|
+
assert.equal(JSON.parse(await readFile(s.file, 'utf8')).token, 'newer');
|
|
159
|
+
});
|
|
160
|
+
test('a bridge.json that cannot be written is a fault', async t => {
|
|
161
|
+
const s = await setup(t, () => textResponse('嗯'));
|
|
162
|
+
await writeFile(join(s.root, 'not-a-dir'), '');
|
|
163
|
+
const broken = s.make(join(s.root, 'not-a-dir', 'bridge.json')); broken.start(); t.after(() => broken.stop());
|
|
164
|
+
assert.equal(broken.faults().length, 1); assert.match(broken.faults()[0]!, /^bridge\.json 没能写入,外面的程序找不到家:/);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
function fakeBridge(say: (text: string) => Promise<{ id: string }> = async () => ({ id: 'm1' })): Bridge & { said: string[] } {
|
|
168
|
+
const said: string[] = [];
|
|
169
|
+
return { said, checkToken: token => token === 'secret', say: async text => { said.push(text); return say(text); }, start() {}, stop() {}, faults: () => [] } as Bridge & { said: string[] };
|
|
170
|
+
}
|
|
171
|
+
async function call(bridge: Bridge | undefined, request: { method?: string; url?: string; headers?: Record<string, string>; body?: string }) {
|
|
172
|
+
const req = Object.assign(Readable.from(request.body === undefined ? [] : [Buffer.from(request.body)]), { method: request.method ?? 'POST', url: request.url ?? BRIDGE_PATH, headers: { host: '127.0.0.1:3080', ...request.headers } });
|
|
173
|
+
let status = 0; let headers: Record<string, string> = {}; let body = '';
|
|
174
|
+
await bridgeRoute(() => bridge).handler(req as never, { writeHead: (code: number, extra: Record<string, string>) => { status = code; headers = extra; }, end: (text: string) => { body = text; } } as never);
|
|
175
|
+
return { status, headers, body: JSON.parse(body) };
|
|
176
|
+
}
|
|
177
|
+
const ok = { 'x-dsh-world-token': 'secret', 'content-type': 'application/json' };
|
|
178
|
+
|
|
179
|
+
test('the say route accepts trimmed text with the right token and answers 202 without waiting', async () => {
|
|
180
|
+
const bridge = fakeBridge();
|
|
181
|
+
const route = bridgeRoute(() => bridge);
|
|
182
|
+
assert.deepEqual({ kind: route.kind, path: route.path }, { kind: 'exact', path: '/dsh-world/bridge/say' });
|
|
183
|
+
assert.deepEqual(await call(bridge, { headers: ok, body: JSON.stringify({ text: ' 在吗 ' }) }), { status: 202, headers: { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' }, body: { accepted: true, id: 'm1' } });
|
|
184
|
+
assert.deepEqual(bridge.said, ['在吗']);
|
|
185
|
+
assert.equal((await call(bridge, { headers: ok, body: JSON.stringify({ text: '鲸'.repeat(2000) }) })).status, 202);
|
|
186
|
+
});
|
|
187
|
+
test('the say route refuses a bad token, cross-site requests, other methods and bad bodies without saying anything', async () => {
|
|
188
|
+
const bridge = fakeBridge();
|
|
189
|
+
const body = JSON.stringify({ text: '在吗' });
|
|
190
|
+
assert.deepEqual(await call(bridge, { body }), { status: 403, headers: { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' }, body: { error: 'forbidden' } });
|
|
191
|
+
assert.equal((await call(bridge, { headers: { 'x-dsh-world-token': 'wrong' }, body })).status, 403);
|
|
192
|
+
assert.equal((await call(bridge, { headers: { ...ok, 'sec-fetch-site': 'cross-site' }, body })).status, 403);
|
|
193
|
+
assert.equal((await call(bridge, { headers: { ...ok, host: 'evil.example:3080' }, body })).status, 403, 'a rebound name');
|
|
194
|
+
const get = await call(bridge, { method: 'GET', headers: ok });
|
|
195
|
+
assert.equal(get.status, 405); assert.equal(get.headers.allow, 'POST');
|
|
196
|
+
for (const bad of ['{ torn', '[]', JSON.stringify({ text: 3 }), JSON.stringify({ text: ' ' }), JSON.stringify({ text: '鲸'.repeat(2001) }), JSON.stringify({ text: 'x'.repeat(70_000) })]) {
|
|
197
|
+
assert.deepEqual((await call(bridge, { headers: ok, body: bad })).status, 400, bad.slice(0, 20));
|
|
198
|
+
}
|
|
199
|
+
assert.deepEqual(bridge.said, []);
|
|
200
|
+
});
|
|
201
|
+
test('the say route answers 503 while her world is stopped (no bridge)', async () => {
|
|
202
|
+
assert.deepEqual((await call(undefined, { headers: ok, body: JSON.stringify({ text: '在吗' }) })).body, { error: 'home unavailable' });
|
|
203
|
+
assert.equal((await call(undefined, { headers: { ...ok, 'sec-fetch-site': 'cross-site' }, body: '{}' })).status, 403);
|
|
204
|
+
});
|
|
205
|
+
test('the say route answers 503 when the home is unavailable and never echoes internals', async () => {
|
|
206
|
+
const unavailable = fakeBridge(async () => { throw new HomeUnavailable('session C:\\secret broke'); });
|
|
207
|
+
assert.deepEqual((await call(unavailable, { headers: ok, body: JSON.stringify({ text: '在吗' }) })).body, { error: 'home unavailable' });
|
|
208
|
+
assert.equal((await call(unavailable, { headers: ok, body: JSON.stringify({ text: '在吗' }) })).status, 503);
|
|
209
|
+
const broken = fakeBridge(async () => { throw new Error('C:\\secret'); });
|
|
210
|
+
assert.deepEqual(await call(broken, { headers: ok, body: JSON.stringify({ text: '在吗' }) }), { status: 500, headers: { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' }, body: { error: 'internal error' } });
|
|
211
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
import { SessionId } from '@deepseek-ai/dsh-session';
|
|
4
|
+
import { createChannelSessions } from '../src/ecosystem/shared/sessions.ts';
|
|
5
|
+
import { conversationKey, speakerIdentity } from '../src/ecosystem/shared/identity.ts';
|
|
6
|
+
import { createArchiveStore } from '../src/store.ts';
|
|
7
|
+
import { hostFixture, textResponse } from './hostFixture.ts';
|
|
8
|
+
import type { LifeHost } from '../src/life/host.ts';
|
|
9
|
+
import { createWorldRuntime } from '../src/runtime.ts';
|
|
10
|
+
import { createWechatHome } from '../src/ecosystem/wechat/home.ts';
|
|
11
|
+
import { record } from './fixtures.ts';
|
|
12
|
+
import type { GenerateOptions } from '@deepseek-ai/dsh-llm';
|
|
13
|
+
|
|
14
|
+
const identity = { channel: 'wechat', accountId: 'bot', conversationType: 'group' as const, conversationId: 'family@chatroom', conversationName: '幸福一家人', speakerId: 'wechat:owner' };
|
|
15
|
+
|
|
16
|
+
test('message provenance is retained and cannot change the conversation routing identity', () => {
|
|
17
|
+
const supplied = { ...identity, platformMessageId: 'm.db:42', mentionIds: ['wechat:bot'] };
|
|
18
|
+
assert.deepEqual(speakerIdentity(supplied), supplied);
|
|
19
|
+
assert.equal(conversationKey(supplied), conversationKey(identity));
|
|
20
|
+
for (const mentionIds of [['qq:bot'], [42], ['wechat:'], Array(65).fill('wechat:bot')]) assert.throws(() => speakerIdentity({ ...identity, mentionIds }));
|
|
21
|
+
assert.throws(() => speakerIdentity({ ...identity, platformMessageId: '\n' }));
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('route keys distinguish platforms, accounts and conversation kinds while ignoring display names', () => {
|
|
25
|
+
assert.equal(conversationKey(identity), conversationKey({ ...identity, conversationName: '改名', speakerId: 'wechat:mom' }));
|
|
26
|
+
assert.notEqual(conversationKey(identity), conversationKey({ ...identity, channel: 'qq', speakerId: 'qq:owner' }));
|
|
27
|
+
assert.notEqual(conversationKey(identity), conversationKey({ ...identity, accountId: 'another' }));
|
|
28
|
+
assert.notEqual(conversationKey(identity), conversationKey({ ...identity, conversationType: 'private' }));
|
|
29
|
+
assert.equal(speakerIdentity(identity).conversationType, 'group');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('each group gets one durable session in the existing workspace without granting extra permissions', async t => {
|
|
33
|
+
const { ctx, root, cleanup } = await hostFixture(t, () => textResponse('ok'));
|
|
34
|
+
const store = createArchiveStore({ root, worldId: 'test', agentPreset: 'test', timeZone: 'UTC' }); cleanup.push(() => store.close());
|
|
35
|
+
let created = 0;
|
|
36
|
+
const archived = new Set<string>();
|
|
37
|
+
const titles: string[] = [];
|
|
38
|
+
const host: LifeHost = {
|
|
39
|
+
workspace: async () => ({ id: 'room', sessionIds: [], attachSession: async () => {} }),
|
|
40
|
+
createSession: async (cwd, preset, workspace) => {
|
|
41
|
+
assert.equal(cwd, root); assert.equal(preset, 'test'); assert.equal(workspace, 'room');
|
|
42
|
+
const id = SessionId('group-' + ++created);
|
|
43
|
+
await ctx.agents.create({ sessionId: id, meta: { agentPreset: preset }, agentOptions: { provider: 'test', model: 'test' } }); return id;
|
|
44
|
+
},
|
|
45
|
+
resolveAgent: async id => ctx.agents.get(SessionId(id)), isArchived: id => archived.has(id),
|
|
46
|
+
setFullAccess: () => { throw new Error('group permissions must not change'); },
|
|
47
|
+
rename: async (_id, title) => { titles.push(title); }, origin: () => 'http://127.0.0.1',
|
|
48
|
+
};
|
|
49
|
+
const deps = { ctx, host, store, roomDir: root, roomTitle: '鲸鲸的房间', agentPreset: 'test' };
|
|
50
|
+
const router = createChannelSessions(deps); cleanup.push(router.stop);
|
|
51
|
+
const [a, b] = await Promise.all([router.open(identity), router.open(identity)]);
|
|
52
|
+
assert.equal(a.id, b.id); assert.equal(created, 1);
|
|
53
|
+
const reopened = createChannelSessions(deps); cleanup.push(reopened.stop);
|
|
54
|
+
assert.equal((await reopened.open(identity)).id, a.id);
|
|
55
|
+
assert.equal(created, 1); assert.match(titles[0], /微信.*幸福一家人/);
|
|
56
|
+
archived.add(a.id);
|
|
57
|
+
assert.notEqual((await reopened.open(identity)).id, a.id);
|
|
58
|
+
assert.equal(created, 2);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('groups receive the existing home memory while their own messages stay out of that archive', async t => {
|
|
62
|
+
const requests: GenerateOptions[] = [];
|
|
63
|
+
const { ctx, root, cleanup } = await hostFixture(t, request => { requests.push(request); return textResponse('群内专属答复'); });
|
|
64
|
+
const config = { root, worldId: 'test', agentPreset: 'test', timeZone: 'UTC', archiveScope: 'home' as const };
|
|
65
|
+
const store = createArchiveStore(config); cleanup.push(() => store.close());
|
|
66
|
+
await store.commitRecords([record('seed', { worldId: 'test', sourceSessionId: 'home', content: '家的已有记忆' })]);
|
|
67
|
+
const isHome = (id: string) => id === 'home';
|
|
68
|
+
const world = createWorldRuntime(ctx, config, store, { prompt: { names: { companion: '鲸鲸', partner: '伙伴' } }, isHome });
|
|
69
|
+
await world.start(); cleanup.push(() => world.stop());
|
|
70
|
+
const agent = (await ctx.agents.create({ sessionId: SessionId('group'), meta: { agentPreset: 'test' }, agentOptions: { provider: 'test', model: 'test' } })).agent;
|
|
71
|
+
const channel = createWechatHome({ ctx, home: async () => agent }); cleanup.push(channel.stop);
|
|
72
|
+
await channel.ask('只属于群的提问', identity);
|
|
73
|
+
await world.flush();
|
|
74
|
+
assert.match(JSON.stringify(requests[0].messages), /家的已有记忆/);
|
|
75
|
+
const archived = (await store.readPage({ worldId: 'test', limit: 10 })).records;
|
|
76
|
+
assert.equal(archived.length, 1);
|
|
77
|
+
assert.doesNotMatch(JSON.stringify(archived), /群内专属答复|只属于群的提问/);
|
|
78
|
+
assert.match(JSON.stringify(agent.session.deriveMessages()), /群内专属答复/);
|
|
79
|
+
});
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 两帧之间 hook 顺序不能变。
|
|
3
|
+
*
|
|
4
|
+
* 浏览器半侧的几个组件都没有 ErrorBoundary:只要有一个组件在某一帧多调用或少调用
|
|
5
|
+
* 一个 useState,React 就会抛 "Rendered more hooks than during the previous render",
|
|
6
|
+
* 整棵树被卸载 —— 用户看到的是全白的界面,控制台之外什么线索都没有。
|
|
7
|
+
*
|
|
8
|
+
* 这个测试用两个假 React 框架把每个组件各渲两遍(先空数据、再有数据),比对 hook 序列。
|
|
9
|
+
* 曾经踩过一次:开关的 useState 写在 early return 后面,数据一到就白屏。
|
|
10
|
+
*/
|
|
11
|
+
import assert from 'node:assert/strict';
|
|
12
|
+
import { readFileSync } from 'node:fs';
|
|
13
|
+
import { dirname, join } from 'node:path';
|
|
14
|
+
import test from 'node:test';
|
|
15
|
+
import { fileURLToPath } from 'node:url';
|
|
16
|
+
import vm from 'node:vm';
|
|
17
|
+
|
|
18
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
19
|
+
const source = readFileSync(join(here, '..', 'client', 'index.js'), 'utf8');
|
|
20
|
+
|
|
21
|
+
/** 假 React:只记 hook 调用顺序,值从 values 里按位取,取不到就用初始值。 */
|
|
22
|
+
function runtime(values: readonly unknown[]): { run(name: string): { hooks: string[]; tree: unknown } } {
|
|
23
|
+
const hooks: string[] = [];
|
|
24
|
+
let at = 0;
|
|
25
|
+
const react = {
|
|
26
|
+
createElement: (type: unknown, props: unknown, ...children: unknown[]) => ({ type, props, children }),
|
|
27
|
+
useState: (init: unknown) => {
|
|
28
|
+
const index = at++;
|
|
29
|
+
hooks.push('useState');
|
|
30
|
+
return [index < values.length ? values[index] : init, () => {}];
|
|
31
|
+
},
|
|
32
|
+
useEffect: () => { hooks.push('useEffect') },
|
|
33
|
+
useRef: () => { hooks.push('useRef'); return { current: null } },
|
|
34
|
+
useMemo: (fn: () => unknown) => { hooks.push('useMemo'); return fn() },
|
|
35
|
+
Fragment: 'fragment',
|
|
36
|
+
};
|
|
37
|
+
const loaded: Array<{ factory: (require: (name: string) => unknown) => any }> = [];
|
|
38
|
+
vm.runInNewContext(source, {
|
|
39
|
+
window: { __ModuleLoader__: { load: (opts: never) => { loaded.push(opts) } } },
|
|
40
|
+
document: { visibilityState: 'visible' },
|
|
41
|
+
fetch: () => Promise.resolve({ ok: true, json: () => Promise.resolve({}) }),
|
|
42
|
+
console,
|
|
43
|
+
});
|
|
44
|
+
assert.equal(loaded.length, 1, '客户端应该只注册一次模块');
|
|
45
|
+
const exports = loaded[0].factory((name: string) => {
|
|
46
|
+
if (name === 'react') return react;
|
|
47
|
+
throw new Error(`组件不该依赖 ${name}`);
|
|
48
|
+
});
|
|
49
|
+
return {
|
|
50
|
+
run(name: string) {
|
|
51
|
+
at = 0;
|
|
52
|
+
hooks.length = 0;
|
|
53
|
+
const component = exports.__test[name];
|
|
54
|
+
assert.equal(typeof component, 'function', `${name} 应该在 __test 里`);
|
|
55
|
+
const tree = component({ ...filled, snapshot: filled, snap: filled });
|
|
56
|
+
return { hooks: [...hooks], tree };
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** 一份「什么都有一点」的假数据,让组件走「有数据」那条分支。 */
|
|
62
|
+
const filled = {
|
|
63
|
+
life: { today: '2026-10-26', days: [{ day: '2026-10-26', rows: [] }], memory: {}, quota: { daily: 20, used: 3 } },
|
|
64
|
+
persona: { persona: '她', rules: [] },
|
|
65
|
+
prompt: { prompt: '世界提示词' },
|
|
66
|
+
sessions: [{ sessionId: 'session-1', title: '和主人说话' }],
|
|
67
|
+
enabled: true,
|
|
68
|
+
dryRun: true,
|
|
69
|
+
running: true,
|
|
70
|
+
timeZone: 'Asia/Shanghai',
|
|
71
|
+
policy: { maxCallsPerDay: 60, maxPerDay: 3 },
|
|
72
|
+
today: { dayKey: '2026-10-26', calls: 2, messages: 1, sent: 1, suppressed: 0, pending: 0 },
|
|
73
|
+
usage: { calls: 2, sampled: 2, avgInputTokens: 1200, avgOutputTokens: 30 },
|
|
74
|
+
usageSeries: [{ dayKey: '2026-10-26', calls: 2, sampled: 2, avgInputTokens: 1200, avgOutputTokens: 30, messages: 1 }],
|
|
75
|
+
reports: [{ decision: 'send', blocked: [], text: '在吗' }],
|
|
76
|
+
days: [{ key: '2026-10-26', date: '2026-10-26', summary: '今天', rows: [] }],
|
|
77
|
+
diary: '',
|
|
78
|
+
records: [],
|
|
79
|
+
memory: { rounds: 3 },
|
|
80
|
+
health: [],
|
|
81
|
+
stats: {},
|
|
82
|
+
alarm: null,
|
|
83
|
+
dates: ['2026-10-26'],
|
|
84
|
+
modules: { wechat: { available: true, enabled: true, running: true }, qq: { available: true, enabled: true, running: true } },
|
|
85
|
+
wechat: { accountId: 'wxid_bot', chats: 2, pending: 0, uncertain: 0, lastContactAt: '2026-10-26T10:00:00.000Z', account: 'online', contextMessages: 8, bufferSeconds: 3, adapter: { running: true, pid: 1, restarts: 0, lastExit: null, error: null, needsHuman: false } },
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const components = ['Activity', 'Diary', 'Qq', 'Panel', 'View', 'Overview', 'PersonaEditor', 'PromptEditor', 'Proactive', 'Modules', 'Wechat'] as const;
|
|
89
|
+
|
|
90
|
+
for (const name of components) {
|
|
91
|
+
test(`${name} 在两帧之间不会换 hook 顺序`, () => {
|
|
92
|
+
// 第一帧:什么都还没读到(第一个 useState 给 null,其余用组件自己的初始值)
|
|
93
|
+
const empty = runtime([null]).run(name);
|
|
94
|
+
// 第二帧:数据到了(第一个 useState 给满的假数据,其余仍是初始值)
|
|
95
|
+
const full = runtime([filled]).run(name);
|
|
96
|
+
assert.deepEqual(
|
|
97
|
+
full.hooks,
|
|
98
|
+
empty.hooks,
|
|
99
|
+
`${name} 第一帧调了 ${empty.hooks.join('→')},数据到了以后变成 ${full.hooks.join('→')};` +
|
|
100
|
+
'React 会因此卸载整棵树,界面直接变白',
|
|
101
|
+
);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
import { Context } from '@deepseek-ai/cordis';
|
|
4
|
+
import { createUserMessage, ToolCallId, type GenerateOptions } from '@deepseek-ai/dsh-llm';
|
|
5
|
+
import { SessionId } from '@deepseek-ai/dsh-session';
|
|
6
|
+
import { defineTool } from '@deepseek-ai/dsh-tools';
|
|
7
|
+
import TokenMeter from '@deepseek-ai/dsh-token-meter';
|
|
8
|
+
import { hostFixture, textResponse } from './hostFixture.ts';
|
|
9
|
+
import ToolFreeCompaction, { toolFreeMessages } from '../src/compaction.ts';
|
|
10
|
+
|
|
11
|
+
test('compaction replays the conversation prefix minus tool calls and results, then commits one paragraph with no tool tail', async t => {
|
|
12
|
+
const summaries: GenerateOptions[] = []; const conversation: GenerateOptions[] = []; let conversationCalls = 0;
|
|
13
|
+
const { ctx, errors } = await hostFixture(t, async function* (request) {
|
|
14
|
+
if (request.purpose === 'compaction') { summaries.push(request); yield* textResponse('第一段\n\n第二段'); return; }
|
|
15
|
+
conversation.push(request);
|
|
16
|
+
if (++conversationCalls === 1) {
|
|
17
|
+
yield { type: 'block-end', index: 0, block: { type: 'text', text: 'before tool visible text' } };
|
|
18
|
+
const block = { type: 'tool-call' as const, id: ToolCallId('private-call'), name: 'work', arguments: '{"value":"PRIVATE_TOOL_ARGUMENT"}' };
|
|
19
|
+
yield { type: 'block-start', index: 1, blockType: 'tool-call' };
|
|
20
|
+
yield { type: 'tool-call-delta', index: 1, id: block.id, name: 'work', argumentsDelta: block.arguments };
|
|
21
|
+
yield { type: 'block-end', index: 1, block };
|
|
22
|
+
yield { type: 'finish', reason: { kind: 'tool-calls' } }; return;
|
|
23
|
+
}
|
|
24
|
+
yield* textResponse('after tool visible text');
|
|
25
|
+
});
|
|
26
|
+
ctx.tools.register(defineTool({ name: 'work', description: 'PRIVATE_TOOL_SCHEMA', parameters: { value: { type: 'string', required: true } }, output: { schema: { type: 'string' }, render: (_args, result) => [{ type: 'text', text: result }] }, execute: async () => 'PRIVATE_TOOL_RESULT' }));
|
|
27
|
+
await ctx.plugin(TokenMeter).await();
|
|
28
|
+
await ctx.plugin(ToolFreeCompaction, { auto: false, timeZone: 'Asia/Seoul', headroomTokens: 0, maxTokens: 128 }).await();
|
|
29
|
+
const handle = await ctx.agents.create({ sessionId: SessionId('tool-free'), meta: { agentPreset: 'companion' }, agentOptions: { provider: 'test', model: 'test' } });
|
|
30
|
+
handle.agent.followup(createUserMessage({ source: { kind: 'user' }, content: [{ type: 'text', text: 'real user request ' + 'context detail '.repeat(200) }] })); await handle.agent.whenIdle();
|
|
31
|
+
assert.equal(errors.length, 0); assert.equal(conversationCalls, 2);
|
|
32
|
+
const result = await ctx.compaction.compactNow(handle.agent, new AbortController().signal);
|
|
33
|
+
assert.ok(result); assert.equal(summaries.length, 1);
|
|
34
|
+
const request = summaries[0];
|
|
35
|
+
assert.ok(!request.messages.some(message => message.role === 'tool' || message.content.some(block => block.type === 'tool-call')));
|
|
36
|
+
const text = JSON.stringify(request.messages);
|
|
37
|
+
for (const removed of ['PRIVATE_TOOL_ARGUMENT', 'PRIVATE_TOOL_RESULT']) assert.ok(!text.includes(removed));
|
|
38
|
+
for (const kept of ['real user request', 'before tool visible text', 'after tool visible text']) assert.ok(text.includes(kept), kept);
|
|
39
|
+
// Same prefix as the last conversation request up to the first removed tool call, so the provider cache applies.
|
|
40
|
+
const last = conversation.at(-1)!.messages;
|
|
41
|
+
const firstTool = last.findIndex(message => message.role === 'tool' || message.content.some(block => block.type === 'tool-call'));
|
|
42
|
+
assert.ok(firstTool > 0); assert.deepEqual(request.messages.slice(0, firstTool), last.slice(0, firstTool));
|
|
43
|
+
assert.deepEqual(request.tools, conversation.at(-1)!.tools);
|
|
44
|
+
assert.equal(request.messages.filter(message => message.role === 'assistant').length, 1, 'text around a removed call is rejoined');
|
|
45
|
+
assert.deepEqual(result.summary, [{ type: 'text', text: '第一段 第二段' }]);
|
|
46
|
+
assert.match(JSON.stringify(request.messages.at(-1)), /执行上下文压缩.*当前时间:.*时区:Asia\/Seoul/);
|
|
47
|
+
const context = handle.agent.session.deriveMessages();
|
|
48
|
+
assert.ok(!context.some(message => message.role === 'tool' || message.content.some(block => block.type === 'tool-call')));
|
|
49
|
+
assert.equal(context.filter(message => message.role !== 'system').length, 1);
|
|
50
|
+
assert.ok(handle.agent.session.snapshotEvents().some(event => event.type === 'tool/result'));
|
|
51
|
+
assert.ok(handle.agent.session.snapshotEvents().some(event => event.type === 'plugin:dsh-world/compaction-request' as never));
|
|
52
|
+
});
|
|
53
|
+
test('failed or truncated summaries leave the original model context intact', async t => {
|
|
54
|
+
const { ctx } = await hostFixture(t, async function* (request) {
|
|
55
|
+
if (request.purpose === 'compaction') { yield { type: 'block-end', index: 0, block: { type: 'text', text: 'incomplete summary' } }; yield { type: 'finish', reason: { kind: 'max-tokens' } }; return; }
|
|
56
|
+
yield* textResponse('complete original response');
|
|
57
|
+
});
|
|
58
|
+
await ctx.plugin(TokenMeter).await();
|
|
59
|
+
await ctx.plugin(ToolFreeCompaction, { auto: false, timeZone: 'UTC', headroomTokens: 0, maxTokens: 128 }).await();
|
|
60
|
+
const handle = await ctx.agents.create({ sessionId: SessionId('failed-summary'), meta: { agentPreset: 'companion' }, agentOptions: { provider: 'test', model: 'test' } });
|
|
61
|
+
handle.agent.followup(createUserMessage({ source: { kind: 'user' }, content: [{ type: 'text', text: 'original user input' }] })); await handle.agent.whenIdle();
|
|
62
|
+
const before = handle.agent.session.deriveMessages();
|
|
63
|
+
await assert.rejects(ctx.compaction.compactNow(handle.agent, new AbortController().signal), error => error instanceof Error && String(error.cause).includes('truncated'));
|
|
64
|
+
assert.deepEqual(handle.agent.session.deriveMessages(), before);
|
|
65
|
+
});
|
|
66
|
+
test('automatic compaction immediately after a tool result removes the entire paired tail', async t => {
|
|
67
|
+
let conversationCalls = 0; const resumed: GenerateOptions[] = [];
|
|
68
|
+
const { ctx, errors } = await hostFixture(t, async function* (request) {
|
|
69
|
+
if (request.purpose === 'compaction') { yield* textResponse('已记住用户要求,继续完成任务。'); return; }
|
|
70
|
+
if (++conversationCalls === 1) {
|
|
71
|
+
const block = { type: 'tool-call' as const, id: ToolCallId('tail-call'), name: 'work', arguments: '{}' };
|
|
72
|
+
yield { type: 'block-start', index: 0, blockType: 'tool-call' };
|
|
73
|
+
yield { type: 'tool-call-delta', index: 0, id: block.id, name: block.name, argumentsDelta: '{}' };
|
|
74
|
+
yield { type: 'block-end', index: 0, block };
|
|
75
|
+
yield { type: 'finish', reason: { kind: 'tool-calls' } }; return;
|
|
76
|
+
}
|
|
77
|
+
resumed.push(request); yield* textResponse('done');
|
|
78
|
+
});
|
|
79
|
+
ctx.tools.register(defineTool({ name: 'work', description: 'test', parameters: {}, output: { schema: { type: 'string' }, render: (_args, value) => [{ type: 'text', text: value }] }, execute: async () => 'TAIL_TOOL_RESULT' }));
|
|
80
|
+
await ctx.plugin(TokenMeter).await();
|
|
81
|
+
await ctx.plugin(ToolFreeCompaction, { auto: true, timeZone: 'UTC', headroomTokens: 0, thresholdRatio: 0.0002, maxTokens: 128 }).await();
|
|
82
|
+
const handle = await ctx.agents.create({ sessionId: SessionId('tool-tail'), meta: { agentPreset: 'companion' }, agentOptions: { provider: 'test', model: 'test' } });
|
|
83
|
+
handle.agent.followup(createUserMessage({ source: { kind: 'user' }, content: [{ type: 'text', text: 'user facts '.repeat(300) }] })); await handle.agent.whenIdle();
|
|
84
|
+
assert.equal(errors.length, 0, errors.map(error => String((error as { error: Error }).error)).join('\n'));
|
|
85
|
+
assert.equal(resumed.length, 1);
|
|
86
|
+
assert.ok(!resumed[0].messages.some(message => message.role === 'tool' || message.content.some(block => block.type === 'tool-call')));
|
|
87
|
+
});
|
|
88
|
+
test('a later compaction replays the earlier paragraph for merging instead of the shadowed original', async t => {
|
|
89
|
+
const summaries: GenerateOptions[] = [];
|
|
90
|
+
const { ctx } = await hostFixture(t, async function* (request) {
|
|
91
|
+
if (request.purpose === 'compaction') { summaries.push(request); yield* textResponse(`摘要${summaries.length}`); return; }
|
|
92
|
+
yield* textResponse('reply ' + 'detail '.repeat(100));
|
|
93
|
+
});
|
|
94
|
+
await ctx.plugin(TokenMeter).await();
|
|
95
|
+
await ctx.plugin(ToolFreeCompaction, { auto: false, timeZone: 'UTC', headroomTokens: 0, maxTokens: 128 }).await();
|
|
96
|
+
const handle = await ctx.agents.create({ sessionId: SessionId('merge'), meta: { agentPreset: 'companion' }, agentOptions: { provider: 'test', model: 'test' } });
|
|
97
|
+
for (const text of ['first input', 'second input']) {
|
|
98
|
+
handle.agent.followup(createUserMessage({ source: { kind: 'user' }, content: [{ type: 'text', text: text + ' context '.repeat(100) }] })); await handle.agent.whenIdle();
|
|
99
|
+
assert.ok(await ctx.compaction.compactNow(handle.agent, new AbortController().signal));
|
|
100
|
+
}
|
|
101
|
+
const replayed = JSON.stringify(summaries[1].messages);
|
|
102
|
+
assert.ok(summaries[1].messages.some(message => message.source?.kind === 'compact-checkpoint' && JSON.stringify(message.content).includes('摘要1')));
|
|
103
|
+
assert.ok(replayed.includes('second input') && !replayed.includes('first input'));
|
|
104
|
+
const context = handle.agent.session.deriveMessages().filter(message => message.role !== 'system');
|
|
105
|
+
assert.equal(context.length, 1); assert.match(JSON.stringify(context[0].content), /摘要2/);
|
|
106
|
+
});
|
|
107
|
+
test('reasoning-only steps left by a removed tool call are dropped, and an echoed summary lead is not doubled', async t => {
|
|
108
|
+
const call = { type: 'tool-call' as const, id: ToolCallId('c'), name: 'send_sticker', arguments: '{}' };
|
|
109
|
+
const user = (text: string) => createUserMessage({ source: { kind: 'user' }, content: [{ type: 'text', text }] });
|
|
110
|
+
const step = (text: string) => ({ id: text, role: 'assistant', source: { kind: 'model' }, content: [{ type: 'reasoning', text }, call] }) as never;
|
|
111
|
+
const result = { id: 'r', role: 'tool', toolCallId: call.id, source: { kind: 'tool' }, content: [{ type: 'text', text: 'sent' }] } as never;
|
|
112
|
+
assert.deepEqual(toolFreeMessages([user('hello'), step('pick a sticker'), result, user('again'), step('another'), result]).map(message => message.role), ['user', 'user']);
|
|
113
|
+
const { ctx } = await hostFixture(t, async function* (request) {
|
|
114
|
+
if (request.purpose === 'compaction') { yield* textResponse('以下是此前交流的摘要:用户打了招呼。'); return; }
|
|
115
|
+
yield* textResponse('reply ' + 'detail '.repeat(100));
|
|
116
|
+
});
|
|
117
|
+
await ctx.plugin(TokenMeter).await();
|
|
118
|
+
await ctx.plugin(ToolFreeCompaction, { auto: false, timeZone: 'UTC', headroomTokens: 0, maxTokens: 128 }).await();
|
|
119
|
+
const handle = await ctx.agents.create({ sessionId: SessionId('lead'), meta: { agentPreset: 'companion' }, agentOptions: { provider: 'test', model: 'test' } });
|
|
120
|
+
handle.agent.followup(user('hi ' + 'context '.repeat(100))); await handle.agent.whenIdle();
|
|
121
|
+
const compacted = await ctx.compaction.compactNow(handle.agent, new AbortController().signal);
|
|
122
|
+
assert.deepEqual(compacted?.summary, [{ type: 'text', text: '用户打了招呼。' }]);
|
|
123
|
+
const checkpoint = JSON.stringify(handle.agent.session.deriveMessages().at(-1)!.content);
|
|
124
|
+
assert.equal(checkpoint.split('以下是此前交流的摘要').length - 1, 1);
|
|
125
|
+
});
|
|
126
|
+
test('her own alarm messages stay in the summarized input and the instruction says they are hers, not the user\'s', async t => {
|
|
127
|
+
const summaries: GenerateOptions[] = [];
|
|
128
|
+
const { ctx } = await hostFixture(t, async function* (request) {
|
|
129
|
+
if (request.purpose === 'compaction') { summaries.push(request); yield* textResponse('她起床了。'); return; }
|
|
130
|
+
yield* textResponse('reply ' + 'detail '.repeat(100));
|
|
131
|
+
});
|
|
132
|
+
await ctx.plugin(TokenMeter).await();
|
|
133
|
+
await ctx.plugin(ToolFreeCompaction, { auto: false, timeZone: 'UTC', headroomTokens: 0, maxTokens: 128 }).await();
|
|
134
|
+
const handle = await ctx.agents.create({ sessionId: SessionId('home'), meta: { agentPreset: 'companion' }, agentOptions: { provider: 'test', model: 'test' } });
|
|
135
|
+
handle.agent.followup(createUserMessage({ source: { kind: 'dsh-world-life' }, content: [{ type: 'text', text: '【我的时间】闹钟响了。ALARM_NOTE ' + 'context '.repeat(100) }] })); await handle.agent.whenIdle();
|
|
136
|
+
assert.ok(await ctx.compaction.compactNow(handle.agent, new AbortController().signal));
|
|
137
|
+
const input = summaries[0].messages;
|
|
138
|
+
assert.ok(input.some(message => message.source?.kind === 'dsh-world-life' && JSON.stringify(message.content).includes('ALARM_NOTE')));
|
|
139
|
+
const instruction = JSON.stringify(input.find(message => message.source?.kind === 'dsh-world-summary-input')!.content);
|
|
140
|
+
assert.ok(instruction.includes('以【我的时间】(较早的是【你的时间】)开头的消息是你自己定的闹钟和留给自己的话,不是用户说的话;把它们当作你自己的安排来记,不要算作用户发言。'));
|
|
141
|
+
});
|