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,67 @@
|
|
|
1
|
+
export type AlarmSource = 'plan' | 'fallback';
|
|
2
|
+
/** `nudged`: she was already asked once, when a home turn stopped well before this alarm, whether she is done. */
|
|
3
|
+
export interface Alarm {
|
|
4
|
+
at: string;
|
|
5
|
+
note: string;
|
|
6
|
+
setAt: string;
|
|
7
|
+
source: AlarmSource;
|
|
8
|
+
nudged?: true;
|
|
9
|
+
}
|
|
10
|
+
/** The next look back on a day: when it is due, and the local day it looks back on. */
|
|
11
|
+
export interface Review {
|
|
12
|
+
at: string;
|
|
13
|
+
day: string;
|
|
14
|
+
}
|
|
15
|
+
/** A word the plugin owes her home: `arrival` when a new home was built, `return` when her world was started again. */
|
|
16
|
+
export interface Greeting {
|
|
17
|
+
at: string;
|
|
18
|
+
kind: 'arrival' | 'return';
|
|
19
|
+
}
|
|
20
|
+
/** What her home spent on the local `day`, in CNY, and whether she was told she went past her budget. */
|
|
21
|
+
export interface Spend {
|
|
22
|
+
day: string;
|
|
23
|
+
yuan: number;
|
|
24
|
+
reminded?: true;
|
|
25
|
+
}
|
|
26
|
+
export interface LifeState {
|
|
27
|
+
version: 1;
|
|
28
|
+
homeSessionId?: string;
|
|
29
|
+
alarm?: Alarm;
|
|
30
|
+
greeting?: Greeting;
|
|
31
|
+
review?: Review;
|
|
32
|
+
spend?: Spend;
|
|
33
|
+
}
|
|
34
|
+
/** `first` is a new home's first wake, `return` the word when her world starts again, `review` the daily look back. */
|
|
35
|
+
export interface WakeRecord {
|
|
36
|
+
scheduledAt: string;
|
|
37
|
+
deliveredAt: string;
|
|
38
|
+
source: AlarmSource | 'first' | 'return' | 'review';
|
|
39
|
+
lateMs: number;
|
|
40
|
+
}
|
|
41
|
+
export interface ActivityRecord {
|
|
42
|
+
time: string;
|
|
43
|
+
sessionId: string;
|
|
44
|
+
callId: string;
|
|
45
|
+
tool: string;
|
|
46
|
+
summary: string;
|
|
47
|
+
outside: boolean;
|
|
48
|
+
gapBefore?: true;
|
|
49
|
+
status?: 'ok' | 'error';
|
|
50
|
+
}
|
|
51
|
+
export interface CompactionRecord {
|
|
52
|
+
time: string;
|
|
53
|
+
sessionId: string;
|
|
54
|
+
ok: boolean;
|
|
55
|
+
shadowedTokens?: number;
|
|
56
|
+
error?: string;
|
|
57
|
+
}
|
|
58
|
+
export interface LifeOptions {
|
|
59
|
+
worldDir: string;
|
|
60
|
+
roomDir: string;
|
|
61
|
+
diaryDir: string;
|
|
62
|
+
selfFile: string;
|
|
63
|
+
fallbackWakeTime: string;
|
|
64
|
+
timeZone: string;
|
|
65
|
+
/** Her alarm wording; the shipped `templates/alarm.md` when absent or missing. */
|
|
66
|
+
alarmFile?: string;
|
|
67
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Her persona in layers, each a `## 名字` section of `<world>/persona.md`, filled in the world console. */
|
|
2
|
+
export declare const PERSONA_LAYERS: readonly ["名字", "她是谁", "性格", "说话方式", "愿景", "补充"];
|
|
3
|
+
export type PersonaLayer = typeof PERSONA_LAYERS[number];
|
|
4
|
+
export type Persona = Record<PersonaLayer, string>;
|
|
5
|
+
/** Missing or unreadable means not written yet: every layer empty. */
|
|
6
|
+
export declare function readPersona(file: string): Persona;
|
|
7
|
+
/** Only layers with text are kept; a persona with none removes the file. */
|
|
8
|
+
export declare function writePersona(file: string, persona: Partial<Persona>): void;
|
|
9
|
+
/** The persona as she reads it at the top of her system prompt, in her own voice; empty when nothing is written. */
|
|
10
|
+
export declare function renderPersona(persona: Persona): string;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { existsSync, readFileSync, rmSync } from 'node:fs';
|
|
2
|
+
import { durableWrite } from "./life/lifeStore.js";
|
|
3
|
+
import { parseSections } from "./life/messages.js";
|
|
4
|
+
/** Her persona in layers, each a `## 名字` section of `<world>/persona.md`, filled in the world console. */
|
|
5
|
+
export const PERSONA_LAYERS = ['名字', '她是谁', '性格', '说话方式', '愿景', '补充'];
|
|
6
|
+
/** Missing or unreadable means not written yet: every layer empty. */
|
|
7
|
+
export function readPersona(file) {
|
|
8
|
+
let sections = new Map();
|
|
9
|
+
try {
|
|
10
|
+
if (existsSync(file))
|
|
11
|
+
sections = parseSections(readFileSync(file, 'utf8'));
|
|
12
|
+
}
|
|
13
|
+
catch { /* treated as not written */ }
|
|
14
|
+
return Object.fromEntries(PERSONA_LAYERS.map(layer => [layer, sections.get(layer) ?? '']));
|
|
15
|
+
}
|
|
16
|
+
/** Only layers with text are kept; a persona with none removes the file. */
|
|
17
|
+
export function writePersona(file, persona) {
|
|
18
|
+
const kept = PERSONA_LAYERS.flatMap(layer => { const text = persona[layer]?.trim(); return text ? [`## ${layer}\n${text}`] : []; });
|
|
19
|
+
if (kept.length)
|
|
20
|
+
durableWrite(file, `${kept.join('\n\n')}\n`);
|
|
21
|
+
else
|
|
22
|
+
rmSync(file, { force: true });
|
|
23
|
+
}
|
|
24
|
+
/** The persona as she reads it at the top of her system prompt, in her own voice; empty when nothing is written. */
|
|
25
|
+
export function renderPersona(persona) {
|
|
26
|
+
const opening = [persona.名字 ? `我是${persona.名字}。` : '', persona.她是谁].filter(Boolean).join('');
|
|
27
|
+
const layers = ['性格', '说话方式', '愿景'].flatMap(layer => persona[layer] ? [`# ${layer}\n${persona[layer]}`] : []);
|
|
28
|
+
return [opening, ...layers, persona.补充].filter(Boolean).join('\n\n');
|
|
29
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Agent } from '@deepseek-ai/dsh-agent';
|
|
2
|
+
import type { Session } from '@deepseek-ai/dsh-session';
|
|
3
|
+
import { type Faults } from './faults.ts';
|
|
4
|
+
import type { WorldConfig } from './types.ts';
|
|
5
|
+
import { type WorldPrompt } from './worldPrompt.ts';
|
|
6
|
+
export interface WorldPromptSource {
|
|
7
|
+
prompt: WorldPrompt;
|
|
8
|
+
isHome(sessionId: string): boolean;
|
|
9
|
+
archiveSession?(sessionId: string): boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Her persona and the world prompt, sections of every world session's system prompt so she sees them on every
|
|
13
|
+
* request. They are read when the session opens and again after each successful compaction (the host assembles
|
|
14
|
+
* the system prompt before pre-step, so the refresh happens on compaction/end), never in between, so the prompt
|
|
15
|
+
* stays in the provider-cached prefix. Whether the session is her home is asked per request.
|
|
16
|
+
*
|
|
17
|
+
* Her persona takes the place of the host's: registered under the host persona's name for her agent, it shadows
|
|
18
|
+
* the deployment default. Where her preset already gave her agent a persona, that name is taken, so hers follows
|
|
19
|
+
* it under its own name and the console says so.
|
|
20
|
+
*/
|
|
21
|
+
export declare function createPromptSections(config: WorldConfig, world: WorldPromptSource, deps: {
|
|
22
|
+
faults: Faults;
|
|
23
|
+
logger: {
|
|
24
|
+
warn(...args: unknown[]): void;
|
|
25
|
+
};
|
|
26
|
+
}): {
|
|
27
|
+
add(agent: Agent): void;
|
|
28
|
+
refresh(session: Session): void;
|
|
29
|
+
clear(): void;
|
|
30
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { errorText } from "./faults.js";
|
|
2
|
+
import { readPersona, renderPersona } from "./persona.js";
|
|
3
|
+
import { renderSelf } from "./self.js";
|
|
4
|
+
import { belongsToWorld } from "./sourceArchive.js";
|
|
5
|
+
import { readTemplate, renderWorldPrompt } from "./worldPrompt.js";
|
|
6
|
+
/** The host's persona section; a preset may also register it for its own agents. */
|
|
7
|
+
const HOST_PERSONA = 'deployment:persona-prefix';
|
|
8
|
+
/**
|
|
9
|
+
* Her persona and the world prompt, sections of every world session's system prompt so she sees them on every
|
|
10
|
+
* request. They are read when the session opens and again after each successful compaction (the host assembles
|
|
11
|
+
* the system prompt before pre-step, so the refresh happens on compaction/end), never in between, so the prompt
|
|
12
|
+
* stays in the provider-cached prefix. Whether the session is her home is asked per request.
|
|
13
|
+
*
|
|
14
|
+
* Her persona takes the place of the host's: registered under the host persona's name for her agent, it shadows
|
|
15
|
+
* the deployment default. Where her preset already gave her agent a persona, that name is taken, so hers follows
|
|
16
|
+
* it under its own name and the console says so.
|
|
17
|
+
*/
|
|
18
|
+
export function createPromptSections(config, world, deps) {
|
|
19
|
+
const entries = new Map();
|
|
20
|
+
const agents = new WeakMap();
|
|
21
|
+
function read() {
|
|
22
|
+
const template = readTemplate(world.prompt.file);
|
|
23
|
+
if (template.error)
|
|
24
|
+
deps.logger.warn(`dsh-world: ${template.error}`);
|
|
25
|
+
return {
|
|
26
|
+
template: template.text,
|
|
27
|
+
...(config.selfFile ? { self: { file: config.selfFile, text: renderSelf(config.selfFile) } } : {}),
|
|
28
|
+
persona: world.prompt.persona ? renderPersona(readPersona(world.prompt.persona)) : '',
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/** Registers her persona when she has one and drops it when she has none. */
|
|
32
|
+
function placePersona(agent, entry) {
|
|
33
|
+
if (!entry.text.persona) {
|
|
34
|
+
entry.persona?.();
|
|
35
|
+
delete entry.persona;
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (entry.persona)
|
|
39
|
+
return;
|
|
40
|
+
const prompt = agent.ctx.systemPrompt;
|
|
41
|
+
const order = prompt.getSectionOrder('DEPLOYMENT_PERSONA_PREFIX') ?? 0;
|
|
42
|
+
const text = () => entry.text.persona;
|
|
43
|
+
try {
|
|
44
|
+
entry.persona = prompt.section({ name: HOST_PERSONA, order, interpolate: false, text });
|
|
45
|
+
deps.faults.clear('persona');
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
entry.persona = prompt.section({ name: 'dsh-world-persona', order: order + 1, interpolate: false, text });
|
|
49
|
+
deps.faults.set('persona', `她的预设自带人设,你写的人设排在它后面(${errorText(error)})`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
add(agent) {
|
|
54
|
+
if (entries.has(agent) || !belongsToWorld(agent.session, config))
|
|
55
|
+
return;
|
|
56
|
+
const text = read();
|
|
57
|
+
const entry = { text, world: agent.ctx.systemPrompt.section({ name: 'dsh-world', order: 50, interpolate: false, text: () => renderWorldPrompt(world.prompt, entry.text.template, entry.text.self, world.isHome(agent.id)) }) };
|
|
58
|
+
entries.set(agent, entry);
|
|
59
|
+
agents.set(agent.session, agent);
|
|
60
|
+
placePersona(agent, entry);
|
|
61
|
+
},
|
|
62
|
+
refresh(session) {
|
|
63
|
+
const agent = agents.get(session);
|
|
64
|
+
const entry = agent && entries.get(agent);
|
|
65
|
+
if (!agent || !entry)
|
|
66
|
+
return;
|
|
67
|
+
entry.text = read();
|
|
68
|
+
placePersona(agent, entry);
|
|
69
|
+
},
|
|
70
|
+
clear() {
|
|
71
|
+
for (const entry of entries.values())
|
|
72
|
+
for (const dispose of [entry.world, entry.persona]) {
|
|
73
|
+
try {
|
|
74
|
+
dispose?.();
|
|
75
|
+
}
|
|
76
|
+
catch { /* agent scope already gone */ }
|
|
77
|
+
}
|
|
78
|
+
entries.clear();
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Every conversation whose messages belong to this world's memory (current + the earlier QQ conversations). */
|
|
2
|
+
export declare function qqScopeSessions(file: string | undefined): ReadonlySet<string>;
|
|
3
|
+
/**
|
|
4
|
+
* The one conversation the QQ gateway is bound to right now. Only this session receives the memory block;
|
|
5
|
+
* the earlier conversations in `sessions` are archive sources, never injection targets.
|
|
6
|
+
*/
|
|
7
|
+
export declare function qqScopeCurrent(file: string | undefined): string;
|
|
8
|
+
/** Whether this session is one of the QQ-bound conversations (the current one and its predecessors). */
|
|
9
|
+
export declare function inQqScope(sessionId: string, file: string | undefined): boolean;
|
|
10
|
+
/** Whether this session is the conversation QQ currently speaks through. */
|
|
11
|
+
export declare function isQqCurrent(sessionId: string, file: string | undefined): boolean;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { readFileSync, statSync } from 'node:fs';
|
|
2
|
+
let cache = { file: '', mtime: -1, sessions: new Set(), current: '' };
|
|
3
|
+
function snapshot(file) {
|
|
4
|
+
if (!file)
|
|
5
|
+
return { file: '', mtime: -1, sessions: new Set(), current: '' };
|
|
6
|
+
try {
|
|
7
|
+
const info = statSync(file);
|
|
8
|
+
if (cache.file === file && cache.mtime === info.mtimeMs)
|
|
9
|
+
return cache;
|
|
10
|
+
const raw = JSON.parse(readFileSync(file, 'utf8'));
|
|
11
|
+
const sessions = new Set(Array.isArray(raw?.sessions) ? raw.sessions.filter((id) => typeof id === 'string' && id !== '') : []);
|
|
12
|
+
const current = typeof raw?.current === 'string' ? raw.current : '';
|
|
13
|
+
cache = { file, mtime: info.mtimeMs, sessions, current };
|
|
14
|
+
return cache;
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return { file, mtime: -1, sessions: new Set(), current: '' };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/** Every conversation whose messages belong to this world's memory (current + the earlier QQ conversations). */
|
|
21
|
+
export function qqScopeSessions(file) {
|
|
22
|
+
return snapshot(file).sessions;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The one conversation the QQ gateway is bound to right now. Only this session receives the memory block;
|
|
26
|
+
* the earlier conversations in `sessions` are archive sources, never injection targets.
|
|
27
|
+
*/
|
|
28
|
+
export function qqScopeCurrent(file) {
|
|
29
|
+
return snapshot(file).current;
|
|
30
|
+
}
|
|
31
|
+
/** Whether this session is one of the QQ-bound conversations (the current one and its predecessors). */
|
|
32
|
+
export function inQqScope(sessionId, file) {
|
|
33
|
+
return qqScopeSessions(file).has(String(sessionId));
|
|
34
|
+
}
|
|
35
|
+
/** Whether this session is the conversation QQ currently speaks through. */
|
|
36
|
+
export function isQqCurrent(sessionId, file) {
|
|
37
|
+
const current = qqScopeCurrent(file);
|
|
38
|
+
return current !== '' && current === String(sessionId);
|
|
39
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
2
|
+
import './hostContract.ts';
|
|
3
|
+
import { type WorldPromptSource } from './promptSection.ts';
|
|
4
|
+
import type { ArchiveStore } from './store.ts';
|
|
5
|
+
import type { WorldConfig } from './types.ts';
|
|
6
|
+
export type { WorldPromptSource } from './promptSection.ts';
|
|
7
|
+
/**
|
|
8
|
+
* The memory line: her conversations are archived as they happen, and every world session gets a memory
|
|
9
|
+
* block of the newest turns at its start and after each successful compaction, never in between, so it stays
|
|
10
|
+
* inside the provider-cached prefix. `home` archives the current home; `workspace` uses host membership. The memory block still
|
|
11
|
+
* goes to every world session. With a world prompt source, the world prompt joins every world session.
|
|
12
|
+
* `memoryTurns` is read each time a block is built (default 200).
|
|
13
|
+
*/
|
|
14
|
+
export declare function createWorldRuntime(ctx: Context, config: WorldConfig, store: ArchiveStore, world?: WorldPromptSource, memoryTurns?: () => number): {
|
|
15
|
+
start: (options?: {
|
|
16
|
+
fresh?: boolean;
|
|
17
|
+
}) => Promise<void>;
|
|
18
|
+
retryCatchUp: () => Promise<void>;
|
|
19
|
+
refreshScope: () => Promise<void>;
|
|
20
|
+
flush: () => Promise<void>;
|
|
21
|
+
stop: () => Promise<void>;
|
|
22
|
+
faults: () => string[];
|
|
23
|
+
};
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { dirname } from 'node:path';
|
|
3
|
+
import { createUserMessage, isAgentLoopRequest } from '@deepseek-ai/dsh-llm';
|
|
4
|
+
import "./hostContract.js";
|
|
5
|
+
import { Faults } from "./faults.js";
|
|
6
|
+
import { createHistory, excludePresentMessages, renderHistory } from "./history.js";
|
|
7
|
+
import { createPromptSections } from "./promptSection.js";
|
|
8
|
+
import { belongsToWorld, createSourceArchive } from "./sourceArchive.js";
|
|
9
|
+
import { worldNames } from "./worldPrompt.js";
|
|
10
|
+
import { DEFAULT_MEMORY_TURNS } from "./worldSwitch.js";
|
|
11
|
+
const memorySource = 'dsh-world-history';
|
|
12
|
+
/**
|
|
13
|
+
* The memory line: her conversations are archived as they happen, and every world session gets a memory
|
|
14
|
+
* block of the newest turns at its start and after each successful compaction, never in between, so it stays
|
|
15
|
+
* inside the provider-cached prefix. `home` archives the current home; `workspace` uses host membership. The memory block still
|
|
16
|
+
* goes to every world session. With a world prompt source, the world prompt joins every world session.
|
|
17
|
+
* `memoryTurns` is read each time a block is built (default 200).
|
|
18
|
+
*/
|
|
19
|
+
export function createWorldRuntime(ctx, config, store, world, memoryTurns = () => DEFAULT_MEMORY_TURNS) {
|
|
20
|
+
if (config.archiveScope === 'workspace' && !world?.archiveSession)
|
|
21
|
+
throw new Error('Workspace archive requires the host workspace selection');
|
|
22
|
+
const archivedByScope = world?.archiveSession ?? ((sessionId) => config.archiveScope !== 'home' || !!world?.isHome(sessionId));
|
|
23
|
+
/** False while some session's workspace was unknown (the host's workspace service was not up yet); `retryCatchUp` reads those later. */
|
|
24
|
+
let undecided = false;
|
|
25
|
+
/** Archiving never fails on unknown membership: the session waits, and what it said is read in order later. */
|
|
26
|
+
const archived = (sessionId) => { try {
|
|
27
|
+
return archivedByScope(sessionId);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
undecided = true;
|
|
31
|
+
return false;
|
|
32
|
+
} };
|
|
33
|
+
const archive = createSourceArchive(ctx, config, store, archived);
|
|
34
|
+
const history = createHistory(store);
|
|
35
|
+
const names = world?.prompt.names ?? worldNames(config);
|
|
36
|
+
const faults = new Faults();
|
|
37
|
+
const prompts = world && createPromptSections(config, world, { faults, logger: ctx.logger });
|
|
38
|
+
const memory = new WeakMap();
|
|
39
|
+
const attaching = new WeakMap();
|
|
40
|
+
const disposers = [];
|
|
41
|
+
let stopping;
|
|
42
|
+
/** Locate earlier memory blocks; every runtime start rebuilds from the active scope and real times. */
|
|
43
|
+
async function readMemoryState(session) {
|
|
44
|
+
const injected = new Map();
|
|
45
|
+
const surface = new Set(session.surface.nodes);
|
|
46
|
+
const handle = await ctx.sessionPersistence.open(session.id, 'read');
|
|
47
|
+
try {
|
|
48
|
+
for (let offset = 0;; offset += 128) {
|
|
49
|
+
const { events } = await handle.read(offset, 128);
|
|
50
|
+
if (!events.length)
|
|
51
|
+
break;
|
|
52
|
+
for (const event of events) {
|
|
53
|
+
const block = event.type === 'user/message' && event.data.source.kind === memorySource;
|
|
54
|
+
if (block && surface.has(event.seq))
|
|
55
|
+
injected.set(event.data.id, event.seq);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
finally {
|
|
60
|
+
await handle.close();
|
|
61
|
+
}
|
|
62
|
+
return { reload: true, injected };
|
|
63
|
+
}
|
|
64
|
+
async function attach(agent) {
|
|
65
|
+
const { session } = agent;
|
|
66
|
+
if (!belongsToWorld(session, config) || memory.has(session))
|
|
67
|
+
return;
|
|
68
|
+
const pending = attaching.get(session);
|
|
69
|
+
if (pending)
|
|
70
|
+
return pending;
|
|
71
|
+
const job = (async () => {
|
|
72
|
+
if (archived(session.id))
|
|
73
|
+
await store.commitRecords([], store.progress(session.id));
|
|
74
|
+
await archive.schedule(session.id);
|
|
75
|
+
memory.set(session, await readMemoryState(session));
|
|
76
|
+
})();
|
|
77
|
+
attaching.set(session, job);
|
|
78
|
+
try {
|
|
79
|
+
await job;
|
|
80
|
+
}
|
|
81
|
+
finally {
|
|
82
|
+
attaching.delete(session);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/** Retires the blocks still on the surface (they must be found, or the session would carry two) and builds a fresh one without the messages already present. */
|
|
86
|
+
async function freshBlock(session, state) {
|
|
87
|
+
const messages = session.deriveMessages();
|
|
88
|
+
const turns = await history.loadRecentTurns(config.worldId, memoryTurns(), archivedByScope);
|
|
89
|
+
const present = new Set(messages.filter(message => message.role === 'assistant' || message.source.kind === 'user').map(message => message.id));
|
|
90
|
+
const text = renderHistory(excludePresentMessages(turns, present), config.timeZone, names, config.archiveScope === 'home');
|
|
91
|
+
writeQqMirror(text);
|
|
92
|
+
const oldBlocks = messages.filter(message => message.source.kind === memorySource);
|
|
93
|
+
for (const [index, message] of oldBlocks.entries()) {
|
|
94
|
+
const seq = state.injected.get(message.id);
|
|
95
|
+
if (seq === undefined || !session.surface.nodes.includes(seq))
|
|
96
|
+
throw new Error('dsh-world: cannot locate retained injected context in the host surface');
|
|
97
|
+
const replacement = createUserMessage({ content: [{ type: 'text', text: index === 0 ? text : '' }], source: { kind: memorySource, form: 'recall' } });
|
|
98
|
+
session.append('user/message', replacement, { surfaceOp: { op: 'replace', startSeq: seq, endSeq: seq }, sourceEventSeqs: [seq] });
|
|
99
|
+
state.injected.delete(message.id);
|
|
100
|
+
}
|
|
101
|
+
if (oldBlocks.length)
|
|
102
|
+
return undefined;
|
|
103
|
+
return text ? createUserMessage({ content: [{ type: 'text', text }], source: { kind: memorySource, form: 'recall' } }) : undefined;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* A readable copy of the exact block the QQ conversation receives. Only the QQ-bound session builds a
|
|
107
|
+
* block, so only it writes this file; a failed mirror never disturbs the memory itself.
|
|
108
|
+
*/
|
|
109
|
+
function writeQqMirror(text) {
|
|
110
|
+
if (config.scope !== 'qq' || !config.qqMirrorFile || !text)
|
|
111
|
+
return;
|
|
112
|
+
try {
|
|
113
|
+
mkdirSync(dirname(config.qqMirrorFile), { recursive: true });
|
|
114
|
+
writeFileSync(config.qqMirrorFile, `<!-- dsh-world: QQ 绑定对话的近期记忆 · ${new Date().toISOString()} -->\n\n${text}\n`, 'utf8');
|
|
115
|
+
}
|
|
116
|
+
catch { /* the mirror is a convenience, never a dependency */ }
|
|
117
|
+
}
|
|
118
|
+
/** Reads what the first catch-up had to leave, once the host can say which sessions belong to her. */
|
|
119
|
+
async function retryCatchUp() {
|
|
120
|
+
if (!undecided)
|
|
121
|
+
return;
|
|
122
|
+
undecided = false;
|
|
123
|
+
await archive.catchUp();
|
|
124
|
+
}
|
|
125
|
+
/** `fresh`: her world was just started from the console, so what was said while it was stopped is not archived. */
|
|
126
|
+
async function start(options = {}) {
|
|
127
|
+
try {
|
|
128
|
+
disposers.push(ctx.on('session/event', (session, event) => {
|
|
129
|
+
if (session.header.origin === 'subagent' || (session.header.delegationDepth ?? 0) > 0 || (!config.archiveScope && !belongsToWorld(session, config)))
|
|
130
|
+
return;
|
|
131
|
+
const state = memory.get(session);
|
|
132
|
+
const compacted = event.type === 'compaction/end' && event.data.error === undefined;
|
|
133
|
+
if (state && event.type === 'user/message' && event.data.source.kind === memorySource)
|
|
134
|
+
state.injected.set(event.data.id, event.seq);
|
|
135
|
+
if (state && event.type === 'user/message' && event.data.id === state.pendingId) {
|
|
136
|
+
state.reload = false;
|
|
137
|
+
state.pendingId = undefined;
|
|
138
|
+
}
|
|
139
|
+
if (state && compacted)
|
|
140
|
+
state.reload = true;
|
|
141
|
+
if (compacted)
|
|
142
|
+
prompts?.refresh(session);
|
|
143
|
+
if (event.type === 'assistant/message' || event.type === 'turn/end' || event.type === 'turn/start' || event.type === 'compaction/end' || (event.type === 'user/message' && event.data.source.kind === 'user'))
|
|
144
|
+
void archive.schedule(session.id).catch(() => { });
|
|
145
|
+
}));
|
|
146
|
+
disposers.push(ctx.on('agent/created', async ({ agent }) => { prompts?.add(agent); await attach(agent); return undefined; }));
|
|
147
|
+
// Admitted ahead of the step's new input; the host's own admission order (contexts, time-context last) is kept.
|
|
148
|
+
disposers.push(ctx.on('agent/pre-step', async (payload, next) => {
|
|
149
|
+
const decision = await next();
|
|
150
|
+
const { agent, turn, step, signal } = payload;
|
|
151
|
+
// An empty first step ends the turn; any later step runs anyway, so adding to it is safe.
|
|
152
|
+
if (decision.kind !== 'enter' || (step === 1 && !decision.messages.length) || signal.aborted || !belongsToWorld(agent.session, config))
|
|
153
|
+
return decision;
|
|
154
|
+
await attach(agent);
|
|
155
|
+
await archive.schedule(agent.id);
|
|
156
|
+
signal.throwIfAborted();
|
|
157
|
+
const state = memory.get(agent.session);
|
|
158
|
+
if (!state.reload)
|
|
159
|
+
return decision;
|
|
160
|
+
const block = await freshBlock(agent.session, state);
|
|
161
|
+
if (!block) {
|
|
162
|
+
state.reload = false;
|
|
163
|
+
return decision;
|
|
164
|
+
}
|
|
165
|
+
state.pendingId = block.id;
|
|
166
|
+
return { ...decision, messages: [block, ...decision.messages] };
|
|
167
|
+
}));
|
|
168
|
+
disposers.push(ctx.on('llm/stream', async function* (request, next) {
|
|
169
|
+
const agent = isAgentLoopRequest(request) && request.sessionId ? ctx.agents.get(request.sessionId) : undefined;
|
|
170
|
+
const owned = agent && belongsToWorld(agent.session, config);
|
|
171
|
+
for await (const chunk of next()) {
|
|
172
|
+
if (owned && chunk.type === 'finish' && chunk.reason.kind === 'error' && chunk.reason.failure.code === 'CONTEXT_WINDOW_EXCEEDED')
|
|
173
|
+
yield {
|
|
174
|
+
...chunk, reason: { ...chunk.reason, failure: { ...chunk.reason.failure, message: `dsh-world: 模型总容量不足,完整近期记忆未被裁剪。${chunk.reason.failure.message}` } },
|
|
175
|
+
};
|
|
176
|
+
else
|
|
177
|
+
yield chunk;
|
|
178
|
+
}
|
|
179
|
+
}));
|
|
180
|
+
await archive.catchUp(options.fresh);
|
|
181
|
+
if (options.fresh)
|
|
182
|
+
for (const agent of ctx.agents.list())
|
|
183
|
+
if (belongsToWorld(agent.session, config))
|
|
184
|
+
await archive.skip(agent.id);
|
|
185
|
+
for (const agent of ctx.agents.list()) {
|
|
186
|
+
prompts?.add(agent);
|
|
187
|
+
await attach(agent);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
await stop();
|
|
192
|
+
throw error;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function stop() {
|
|
196
|
+
return stopping ??= (async () => {
|
|
197
|
+
prompts?.clear();
|
|
198
|
+
for (const dispose of disposers.splice(0).reverse())
|
|
199
|
+
dispose();
|
|
200
|
+
await archive.flush();
|
|
201
|
+
})();
|
|
202
|
+
}
|
|
203
|
+
/** Re-read the selected sessions after the QQ binding changes, so earlier conversations are archived before the next turn. */
|
|
204
|
+
const refreshScope = () => archive.catchUp();
|
|
205
|
+
return { start, retryCatchUp, refreshScope, flush: archive.flush, stop, faults: () => faults.list() };
|
|
206
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Characters of her self-description read per session; she is asked to keep it to what matters. */
|
|
2
|
+
export declare const SELF_CAP = 4000;
|
|
3
|
+
/**
|
|
4
|
+
* Her 我是谁 file as it goes into `{{self}}`: only what she wrote, tagged so her own headings do not read as
|
|
5
|
+
* sections of the world prompt. What the file is and that she may rewrite it is the template's to say.
|
|
6
|
+
* Empty when she has not written it. Never throws: an unreadable file becomes a short note.
|
|
7
|
+
*/
|
|
8
|
+
export declare function renderSelf(selfFile: string): string;
|
|
9
|
+
/** Keeps her 我是谁 as it is today beside it, in `<name>.history/<day><ext>`, so every change she makes can be seen and undone. Undefined when she has not written one. */
|
|
10
|
+
export declare function keepSelfCopy(selfFile: string, day: string): string | undefined;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { copyFileSync, existsSync, mkdirSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { basename, dirname, extname, join } from 'node:path';
|
|
3
|
+
/** Characters of her self-description read per session; she is asked to keep it to what matters. */
|
|
4
|
+
export const SELF_CAP = 4000;
|
|
5
|
+
/**
|
|
6
|
+
* Her 我是谁 file as it goes into `{{self}}`: only what she wrote, tagged so her own headings do not read as
|
|
7
|
+
* sections of the world prompt. What the file is and that she may rewrite it is the template's to say.
|
|
8
|
+
* Empty when she has not written it. Never throws: an unreadable file becomes a short note.
|
|
9
|
+
*/
|
|
10
|
+
export function renderSelf(selfFile) {
|
|
11
|
+
let text;
|
|
12
|
+
// trim() also drops a leading BOM.
|
|
13
|
+
try {
|
|
14
|
+
text = existsSync(selfFile) ? readFileSync(selfFile, 'utf8').trim() : '';
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
return `(这次没能读到我是谁.md:${error instanceof Error ? error.message : String(error)}。它还在,下次会再试。)`;
|
|
18
|
+
}
|
|
19
|
+
if (!text)
|
|
20
|
+
return '';
|
|
21
|
+
const chars = Array.from(text);
|
|
22
|
+
const capped = chars.length > SELF_CAP;
|
|
23
|
+
const body = `<我是谁.md>\n${capped ? chars.slice(0, SELF_CAP).join('') : text}\n</我是谁.md>`;
|
|
24
|
+
return capped ? `${body}\n(后面还有 ${chars.length - SELF_CAP} 字没读进来;挑最要紧的留下吧。)` : body;
|
|
25
|
+
}
|
|
26
|
+
/** Keeps her 我是谁 as it is today beside it, in `<name>.history/<day><ext>`, so every change she makes can be seen and undone. Undefined when she has not written one. */
|
|
27
|
+
export function keepSelfCopy(selfFile, day) {
|
|
28
|
+
if (!existsSync(selfFile))
|
|
29
|
+
return undefined;
|
|
30
|
+
const ext = extname(selfFile);
|
|
31
|
+
const dir = join(dirname(selfFile), `${basename(selfFile, ext)}.history`);
|
|
32
|
+
mkdirSync(dir, { recursive: true });
|
|
33
|
+
const copy = join(dir, `${day}${ext}`);
|
|
34
|
+
copyFileSync(selfFile, copy);
|
|
35
|
+
return copy;
|
|
36
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
2
|
+
import { type Session } from '@deepseek-ai/dsh-session';
|
|
3
|
+
import type { ArchiveStore } from './store.ts';
|
|
4
|
+
import type { WorldConfig } from './types.ts';
|
|
5
|
+
/**
|
|
6
|
+
* A session log the host itself cannot read (a compaction cut off mid-write, a half-flushed turn). It is not
|
|
7
|
+
* our bug and it never fixes itself, so retrying adds nothing — one broken conversation must not cost her the
|
|
8
|
+
* whole world: flushed and thrown, it fails the plugin's load and every session loses its memory block.
|
|
9
|
+
*/
|
|
10
|
+
export declare function isCorruptSessionLog(error: unknown): boolean;
|
|
11
|
+
export declare function belongsToWorld(session: Pick<Session, 'header'>, config: WorldConfig): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Copies her conversations from the host's session logs into the archive. Each session is replayed from where
|
|
14
|
+
* the archive left off; replays run one at a time, and a session already queued is not queued twice. Sessions
|
|
15
|
+
* outside `archived` are left alone.
|
|
16
|
+
*/
|
|
17
|
+
export declare function createSourceArchive(ctx: Context, config: WorldConfig, store: ArchiveStore, archived?: (sessionId: string) => boolean): {
|
|
18
|
+
schedule: (sessionId: string) => Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Every session the archive has seen, replayed again so nothing written while the plugin was not loaded is
|
|
21
|
+
* missed; with `skip`, what was said while her world was stopped is passed over instead.
|
|
22
|
+
*/
|
|
23
|
+
catchUp(skip?: boolean): Promise<void>;
|
|
24
|
+
/** Moves past everything a session holds now without keeping it (said while her world was stopped). */
|
|
25
|
+
skip: (sessionId: string) => Promise<void>;
|
|
26
|
+
/** Waits for every queued replay; rejects while any session still has an unresolved failure. */
|
|
27
|
+
flush(): Promise<void>;
|
|
28
|
+
};
|