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,356 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import z from '@deepseek-ai/schemastery';
|
|
4
|
+
import { resolveDshHome } from '@deepseek-ai/dsh-home-paths';
|
|
5
|
+
import { createBridge } from "./ecosystem/bridge/bridge.js";
|
|
6
|
+
import { bridgeRoute } from "./ecosystem/bridge/route.js";
|
|
7
|
+
import { consoleRoute } from "./console/routes.js";
|
|
8
|
+
import { consoleSources } from "./console/snapshot.js";
|
|
9
|
+
import { errorText, Faults } from "./faults.js";
|
|
10
|
+
import { hostLife } from "./life/host.js";
|
|
11
|
+
import { createLifeStore, durableWrite } from "./life/lifeStore.js";
|
|
12
|
+
import { toastSupported, windowsToast } from "./life/notify.js";
|
|
13
|
+
import { createLifeRuntime } from "./life/runtime.js";
|
|
14
|
+
import { createOutlet } from "./ecosystem/shared/outlets.js";
|
|
15
|
+
import { readPersona, writePersona } from "./persona.js";
|
|
16
|
+
import { createQqBridge, syncBridgeSessionMode } from "./ecosystem/qq/bridge.js";
|
|
17
|
+
import { createQqSupervisor } from "./ecosystem/qq/supervisor.js";
|
|
18
|
+
import { qqRoute } from "./ecosystem/qq/route.js";
|
|
19
|
+
import { createConsoleDoors } from "./ecosystem/qq/panel.js";
|
|
20
|
+
import { createWorldRuntime } from "./runtime.js";
|
|
21
|
+
import { createArchiveStore } from "./store.js";
|
|
22
|
+
import { DEFAULT_TEMPLATE_FILE, roomTitle, worldNames } from "./worldPrompt.js";
|
|
23
|
+
import { createWorldSwitch } from "./worldSwitch.js";
|
|
24
|
+
import { createWechatModule } from "./ecosystem/wechat/index.js";
|
|
25
|
+
import { createWechatRecorder } from "./ecosystem/wechat/archive.js";
|
|
26
|
+
import { createAdapterSupervisor } from "./ecosystem/wechat/supervisor.js";
|
|
27
|
+
import { createChannelSessions } from "./ecosystem/shared/sessions.js";
|
|
28
|
+
import { createArchiveSelection } from "./archiveSelection.js";
|
|
29
|
+
import { belongsToWorld } from "./sourceArchive.js";
|
|
30
|
+
export { createWorldRuntime } from "./runtime.js";
|
|
31
|
+
export const name = 'dsh-world';
|
|
32
|
+
export const inject = ['agents', 'sessions', 'sessionPersistence', 'llm'];
|
|
33
|
+
// One companion per profile is the usual case, so it works as installed: the standard preset, a world named
|
|
34
|
+
// default and the system time zone, with the life line on (it needs the desktop host's services and stays off without them).
|
|
35
|
+
const systemTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone || 'UTC';
|
|
36
|
+
export const Config = z.object({
|
|
37
|
+
worldId: z.string().default('default'), agentPreset: z.string().default('standard'), timeZone: z.string().default(systemTimeZone),
|
|
38
|
+
// `world` = upstream behavior (host preset); `qq` = only the conversations dsh-agent-md binds to the
|
|
39
|
+
// QQ gateway read and write this world's memory.
|
|
40
|
+
scope: z.union([z.const('world'), z.const('qq')]).default('world'),
|
|
41
|
+
qqSessionsFile: z.string().default(''),
|
|
42
|
+
qqMirrorFile: z.string().default(''),
|
|
43
|
+
companionName: z.string(), partnerName: z.string(),
|
|
44
|
+
archiveScope: z.union([z.const('home').description('仅家会话'), z.const('workspace').description('家所在工作区'), z.transform(z.const('world').hidden(), () => 'workspace').hidden()]).default('workspace').description('记忆归档范围,修改后重启生效'),
|
|
45
|
+
life: z.boolean().default(true), diaryDir: z.string(), fallbackWakeTime: z.string().pattern(/^([01]\d|2[0-3]):[0-5]\d$/).default('09:00'),
|
|
46
|
+
selfFile: z.string(), worldPromptFile: z.string(), alarmTemplateFile: z.string(), personaFile: z.string(),
|
|
47
|
+
// Where her words go outside DSH; no app is known by name (see README for the push body).
|
|
48
|
+
outlets: z.array(z.object({ name: z.string().required(), url: z.string(), urlFile: z.string(), path: z.string(), kinds: z.array(z.union([z.const('reply'), z.const('busy'), z.const('reach')])) })).default([]),
|
|
49
|
+
// A local app may hand her partner's words to her home through POST /dsh-world/bridge/say.
|
|
50
|
+
bridge: z.boolean().default(false),
|
|
51
|
+
wechat: z.boolean().default(false),
|
|
52
|
+
wechatAdapter: z.object({ python: z.string(), config: z.string() }).description('随微信模块启动和停止 Windows 适配器;写上即视为允许它发送消息'),
|
|
53
|
+
toast: z.boolean().default(true),
|
|
54
|
+
// The console and the bridge answer only this machine by name, plus these (a LAN address or domain behind a proxy).
|
|
55
|
+
allowedHosts: z.array(z.string()).default([]),
|
|
56
|
+
// QQ: her home is reachable from outside DSH through a separate `qq-bridge` process. Empty qqBridgeDir leaves
|
|
57
|
+
// this whole module off; the bridge is started by hand from the console unless qqBridgeAutoStart says otherwise.
|
|
58
|
+
qqBridgeDir: z.string().default(''), qqBridgePort: z.number().default(3100), qqBridgeNode: z.string(),
|
|
59
|
+
qqBridgeAutoStart: z.boolean().default(false),
|
|
60
|
+
// 谁和谁共用一个会话。空着就不碰桥的 config.json(尊重人自己填的);'owner' 让每个群各自一份会话、
|
|
61
|
+
// 只有主人私聊用她的家会话——这是装上之后最想要的那个,人在插件配置里说一次就够了。
|
|
62
|
+
qqBridgeBindHomeSession: z.union([z.const('owner').description('群各自独立,主人私聊用她的家会话'), z.const('all').description('所有入口都用她的家会话'), z.const('none').description('谁都不绑,每个入口各建一个'), z.const('')]).default(''),
|
|
63
|
+
});
|
|
64
|
+
/**
|
|
65
|
+
* Her world runs only after her partner presses start in the world console, and stops when they press stop:
|
|
66
|
+
* memory block, persona, world prompt, archive and life line come and go together. The switch is kept in
|
|
67
|
+
* `<world>/world.json`, so it outlasts a restart.
|
|
68
|
+
*/
|
|
69
|
+
export async function apply(ctx, config) {
|
|
70
|
+
const dshHome = resolveDshHome();
|
|
71
|
+
const worldDir = join(dshHome, 'worlds', config.worldId);
|
|
72
|
+
const store = createArchiveStore({ ...config, root: dshHome });
|
|
73
|
+
const power = createWorldSwitch(worldDir, config.archiveScope ?? 'workspace');
|
|
74
|
+
const qqSessionsFile = config.qqSessionsFile || join(dshHome, 'agents', 'qq-memory.json');
|
|
75
|
+
const qqMirrorFile = config.qqMirrorFile || join(dshHome, 'agents', 'qq-memory.md');
|
|
76
|
+
const memoryConfig = { ...config, archiveScope: power.archiveScope(), qqSessionsFile, qqMirrorFile };
|
|
77
|
+
const faults = new Faults();
|
|
78
|
+
// Her self-description lives in her room whether or not the life line runs; she writes it with her file tools.
|
|
79
|
+
const selfFile = config.selfFile || join(worldDir, 'room', '我是谁.md');
|
|
80
|
+
const personaFile = config.personaFile || join(worldDir, 'persona.md');
|
|
81
|
+
const worldPromptFile = config.worldPromptFile || join(worldDir, 'world-prompt.md');
|
|
82
|
+
// In QQ scope the persona lives in the 人格 page (dsh-agent-md). The shipped world prompt would add a
|
|
83
|
+
// second, conflicting identity ("digital life with full access"), so a fresh world starts with it empty.
|
|
84
|
+
if (config.scope === 'qq') {
|
|
85
|
+
try {
|
|
86
|
+
mkdirSync(dirname(worldPromptFile), { recursive: true });
|
|
87
|
+
if (!existsSync(worldPromptFile))
|
|
88
|
+
writeFileSync(worldPromptFile, '', 'utf8');
|
|
89
|
+
}
|
|
90
|
+
catch { /* the console can still edit it */ }
|
|
91
|
+
}
|
|
92
|
+
const options = { worldDir, roomDir: join(worldDir, 'room'), diaryDir: config.diaryDir || join(worldDir, 'diary'), selfFile, fallbackWakeTime: config.fallbackWakeTime, timeZone: config.timeZone, alarmFile: config.alarmTemplateFile || join(worldDir, 'alarm.md') };
|
|
93
|
+
/** The name in her persona comes first, then the configured one. */
|
|
94
|
+
const names = () => worldNames({ ...config, companionName: readPersona(personaFile).名字 || config.companionName });
|
|
95
|
+
const lifeStore = (() => {
|
|
96
|
+
if (!config.life)
|
|
97
|
+
return undefined;
|
|
98
|
+
try {
|
|
99
|
+
const current = createLifeStore(worldDir, config.timeZone);
|
|
100
|
+
current.read();
|
|
101
|
+
return current;
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
faults.set('life', `生活线没能启动:${errorText(error)}`);
|
|
105
|
+
ctx.logger.error(error);
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
})();
|
|
109
|
+
const storedHome = () => lifeStore?.read().homeSessionId;
|
|
110
|
+
let isHome = id => id === storedHome();
|
|
111
|
+
const includesSession = createArchiveSelection(ctx, power.archiveScope(), id => isHome(id), options.roomDir, {
|
|
112
|
+
scope: config.scope,
|
|
113
|
+
sessionsFile: qqSessionsFile,
|
|
114
|
+
});
|
|
115
|
+
let memory;
|
|
116
|
+
let stopLifeLine;
|
|
117
|
+
async function startMemory(fresh) {
|
|
118
|
+
if (memory)
|
|
119
|
+
return;
|
|
120
|
+
const prompt = { file: worldPromptFile, persona: personaFile, conversationsDir: join(worldDir, 'conversations'), names: names(), ...(config.life ? { life: options } : {}) };
|
|
121
|
+
memory = createWorldRuntime(ctx, { ...memoryConfig, selfFile }, store, { prompt, isHome: id => isHome(id), archiveSession: includesSession }, power.memoryTurns);
|
|
122
|
+
await memory.start({ fresh });
|
|
123
|
+
}
|
|
124
|
+
async function stopMemory() {
|
|
125
|
+
const running = memory;
|
|
126
|
+
memory = undefined;
|
|
127
|
+
await running?.stop();
|
|
128
|
+
}
|
|
129
|
+
ctx.effect(() => async () => {
|
|
130
|
+
if (scopeWatch)
|
|
131
|
+
clearInterval(scopeWatch);
|
|
132
|
+
try {
|
|
133
|
+
await stopLifeLine?.();
|
|
134
|
+
}
|
|
135
|
+
finally {
|
|
136
|
+
await stopMemory().finally(() => store.close());
|
|
137
|
+
}
|
|
138
|
+
}, 'dsh-world memory line');
|
|
139
|
+
if (power.running())
|
|
140
|
+
await startMemory(false);
|
|
141
|
+
// QQ scope follows a file dsh-agent-md writes on every bind. When it changes, replay the newly selected
|
|
142
|
+
// conversations (the current one and its predecessors) so the next turn already sees the earlier history.
|
|
143
|
+
let scopeWatch;
|
|
144
|
+
if (config.scope === 'qq') {
|
|
145
|
+
let lastMtime = -1;
|
|
146
|
+
const tick = () => {
|
|
147
|
+
let mtime = -1;
|
|
148
|
+
try {
|
|
149
|
+
mtime = statSync(qqSessionsFile).mtimeMs;
|
|
150
|
+
}
|
|
151
|
+
catch { /* not bound yet */ }
|
|
152
|
+
if (mtime === lastMtime)
|
|
153
|
+
return;
|
|
154
|
+
lastMtime = mtime;
|
|
155
|
+
void memory?.refreshScope().catch(error => ctx.logger.warn(error));
|
|
156
|
+
};
|
|
157
|
+
tick();
|
|
158
|
+
scopeWatch = setInterval(tick, 3000);
|
|
159
|
+
scopeWatch.unref?.();
|
|
160
|
+
}
|
|
161
|
+
// The host's workspace service may come up after this plugin; what the first catch-up could not place is read then.
|
|
162
|
+
ctx.inject(['workspaceRegistry'], injected => { void memory?.retryCatchUp().catch(error => injected.logger.error(error)); });
|
|
163
|
+
// The console and the life line need the desktop host.
|
|
164
|
+
ctx.inject(['sessionController', 'permissionPresets', 'webServer'], async (lifeCtx) => {
|
|
165
|
+
const webServer = lifeCtx.webServer;
|
|
166
|
+
const host = hostLife(lifeCtx);
|
|
167
|
+
// QQ: one more door into her home, managed here rather than by a launcher script. The endpoint is aligned
|
|
168
|
+
// on every start whether or not the bridge runs — DSH picks a new port each restart, and a stale baseUrl
|
|
169
|
+
// looks exactly like a dead bridge (a dead event stream, no error, for hours). The console switch starts
|
|
170
|
+
// and stops this management at any time; it does not stop a bridge that is already running.
|
|
171
|
+
let qq;
|
|
172
|
+
let qqSupervisor;
|
|
173
|
+
let unregisterQq;
|
|
174
|
+
function startQq() {
|
|
175
|
+
if (qq || !config.qqBridgeDir || !power.qqEnabled())
|
|
176
|
+
return;
|
|
177
|
+
const service = createQqBridge({ dir: config.qqBridgeDir, port: config.qqBridgePort, nodePath: config.qqBridgeNode || process.execPath, origin: () => host.origin(), logger: lifeCtx.logger });
|
|
178
|
+
qq = service;
|
|
179
|
+
// 会话绑定先写:桥是启动时才读 config.json 的,这条必须在 ensureRunning/syncEndpoint 之前。
|
|
180
|
+
syncBridgeSessionMode(config.qqBridgeDir, config.qqBridgeBindHomeSession, lifeCtx.logger);
|
|
181
|
+
// 两个控制台的门:qq-bridge 的令牌是文件,SnowLuma 的会话令牌得用面板密码现换。
|
|
182
|
+
const doors = createConsoleDoors({ worldDir, bridgeDir: config.qqBridgeDir, port: config.qqBridgePort });
|
|
183
|
+
unregisterQq = webServer.register(qqRoute(service, config.allowedHosts, doors));
|
|
184
|
+
void (config.qqBridgeAutoStart ? service.ensureRunning() : service.syncEndpoint()).catch(error => lifeCtx.logger.warn(error));
|
|
185
|
+
// QQ 巡检:桥是独立进程,崩了、被结束、连不上 DSH 都不会有人知道——上一版只有启动时那一次
|
|
186
|
+
// ensureRunning,之后再无人过问。2026-10-26 那条链路死了四个小时,就是这么来的。
|
|
187
|
+
// 这里只负责「什么时候该拉」,怎么拉仍然是 bridge.ts 的事。
|
|
188
|
+
qqSupervisor = createQqSupervisor({ dir: config.qqBridgeDir, port: config.qqBridgePort, bridge: service, logger: lifeCtx.logger });
|
|
189
|
+
qqSupervisor.start();
|
|
190
|
+
}
|
|
191
|
+
function stopQq() {
|
|
192
|
+
qqSupervisor?.stop();
|
|
193
|
+
qqSupervisor = undefined;
|
|
194
|
+
unregisterQq?.();
|
|
195
|
+
unregisterQq = undefined;
|
|
196
|
+
qq = undefined;
|
|
197
|
+
}
|
|
198
|
+
startQq();
|
|
199
|
+
lifeCtx.effect(() => () => stopQq(), 'dsh-world qq');
|
|
200
|
+
let life;
|
|
201
|
+
let bridge;
|
|
202
|
+
let wechat;
|
|
203
|
+
let adapter;
|
|
204
|
+
let channels;
|
|
205
|
+
let unregisterWechat;
|
|
206
|
+
let lifeStop;
|
|
207
|
+
let wechatClosing = Promise.resolve();
|
|
208
|
+
/** Starts the WeChat module (its tools, route and, when configured, the adapter) against the running life line. */
|
|
209
|
+
async function startWechat(current) {
|
|
210
|
+
if (wechat || !config.wechat)
|
|
211
|
+
return;
|
|
212
|
+
await wechatClosing;
|
|
213
|
+
const groupSessions = createChannelSessions({ ctx: lifeCtx, host, store, roomDir: options.roomDir, roomTitle: roomTitle(names()), agentPreset: config.agentPreset });
|
|
214
|
+
channels = groupSessions;
|
|
215
|
+
wechat = createWechatModule({ ctx: lifeCtx, worldId: config.worldId, acceptAgent: agent => belongsToWorld(agent.session, config), home: identity => identity.conversationType === 'group' ? groupSessions.open(identity) : current.home(), origin: () => host.origin(), file: join(worldDir, 'wechat.json'), incomingDir: join(worldDir, 'wechat-incoming'), allowedHosts: config.allowedHosts, settings: () => ({ contextMessages: power.wechatContext(), bufferSeconds: power.wechatBufferSeconds() }),
|
|
216
|
+
...createWechatRecorder(store, config.worldId, includesSession) });
|
|
217
|
+
wechat.start();
|
|
218
|
+
unregisterWechat = webServer.register(wechat.route);
|
|
219
|
+
if (config.wechatAdapter?.python && config.wechatAdapter.config) {
|
|
220
|
+
adapter = createAdapterSupervisor({ python: config.wechatAdapter.python, config: config.wechatAdapter.config, logFile: join(worldDir, 'wechat-adapter.log'), log: message => lifeCtx.logger.warn(message) });
|
|
221
|
+
adapter.start();
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
/** Takes the WeChat tools, route and adapter down; the adapter goes first because it exits when the module's connection file disappears. */
|
|
225
|
+
function stopWechat() {
|
|
226
|
+
unregisterWechat?.();
|
|
227
|
+
unregisterWechat = undefined;
|
|
228
|
+
const closingAdapter = adapter?.stop();
|
|
229
|
+
adapter = undefined;
|
|
230
|
+
const closing = Promise.all([closingAdapter, wechat?.stop()]).then(() => { });
|
|
231
|
+
wechat = undefined;
|
|
232
|
+
channels?.stop();
|
|
233
|
+
channels = undefined;
|
|
234
|
+
return wechatClosing = closing;
|
|
235
|
+
}
|
|
236
|
+
async function startLife(resumed) {
|
|
237
|
+
if (!lifeStore || life)
|
|
238
|
+
return;
|
|
239
|
+
try {
|
|
240
|
+
await lifeStop;
|
|
241
|
+
const outlets = config.outlets.map(outlet => createOutlet(outlet, () => host.origin()));
|
|
242
|
+
const notifier = { ...(config.toast && toastSupported() ? { toast: windowsToast() } : {}), outlets };
|
|
243
|
+
const current = createLifeRuntime({ ctx: lifeCtx, config: { ...config, companionName: names().companion }, options, store: lifeStore, host, notifier, dailyBudget: power.dailyBudget });
|
|
244
|
+
life = current;
|
|
245
|
+
isHome = current.isHome;
|
|
246
|
+
if (config.bridge) {
|
|
247
|
+
bridge = createBridge({ ctx: lifeCtx, home: () => current.home(), outlets, origin: () => host.origin(), file: join(worldDir, 'bridge.json'), name: names().companion });
|
|
248
|
+
bridge.start();
|
|
249
|
+
}
|
|
250
|
+
if (config.wechat && power.wechatEnabled())
|
|
251
|
+
await startWechat(current);
|
|
252
|
+
faults.clear('life');
|
|
253
|
+
await current.start({ resumed });
|
|
254
|
+
}
|
|
255
|
+
catch (error) {
|
|
256
|
+
// The console still opens and says why, instead of looking as if the life line were simply off.
|
|
257
|
+
await stopLife();
|
|
258
|
+
faults.set('life', `生活线没能启动:${errorText(error)}`);
|
|
259
|
+
lifeCtx.logger.error(error);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
function stopLife() {
|
|
263
|
+
isHome = id => id === storedHome();
|
|
264
|
+
bridge?.stop();
|
|
265
|
+
life?.stop();
|
|
266
|
+
const closingWechat = stopWechat();
|
|
267
|
+
bridge = undefined;
|
|
268
|
+
life = undefined;
|
|
269
|
+
return lifeStop = Promise.all([lifeStop, closingWechat]).then(() => { });
|
|
270
|
+
}
|
|
271
|
+
stopLifeLine = stopLife;
|
|
272
|
+
lifeCtx.effect(() => () => stopLife(), 'dsh-world life line');
|
|
273
|
+
// The host matches exact routes before the longest prefix, so this path never reaches the console.
|
|
274
|
+
if (config.bridge)
|
|
275
|
+
lifeCtx.effect(() => webServer.register(bridgeRoute(() => bridge, config.allowedHosts)), 'dsh-world bridge route');
|
|
276
|
+
// Her album lives in her room, so the console shows it whether or not the life line is running.
|
|
277
|
+
const sources = consoleSources({ ctx: lifeCtx, config: memoryConfig, archive: store, names, ...(lifeStore ? { lifeStore } : {}), life: () => life, diaryDir: options.diaryDir, running: power.running, dailyBudget: power.dailyBudget, memoryTurns: power.memoryTurns, selectedArchiveScope: power.selectedArchiveScope, wechat: () => wechat ? { ...wechat.status(), adapter: adapter?.status() ?? null } : undefined, includesSession, ...(config.qqBridgeDir ? { qq: async () => qq ? { ...(await qq.status()), ...(qqSupervisor ? { supervisor: qqSupervisor.snapshot() } : {}) } : null } : {}),
|
|
278
|
+
modules: () => ({ wechat: { available: config.wechat, enabled: power.wechatEnabled(), running: wechat !== undefined }, qq: { available: Boolean(config.qqBridgeDir), enabled: power.qqEnabled(), running: qq !== undefined } }), faults: () => [...faults.list(), ...(memory?.faults() ?? []), ...(bridge?.faults() ?? []), ...(qq?.faults() ?? [])] });
|
|
279
|
+
const actions = {
|
|
280
|
+
async start() {
|
|
281
|
+
if (power.running())
|
|
282
|
+
return;
|
|
283
|
+
power.set(true);
|
|
284
|
+
try {
|
|
285
|
+
await startMemory(true);
|
|
286
|
+
await startLife(true);
|
|
287
|
+
}
|
|
288
|
+
finally {
|
|
289
|
+
sources.invalidate();
|
|
290
|
+
}
|
|
291
|
+
},
|
|
292
|
+
async stop() {
|
|
293
|
+
if (!power.running())
|
|
294
|
+
return;
|
|
295
|
+
power.set(false);
|
|
296
|
+
await stopLife();
|
|
297
|
+
try {
|
|
298
|
+
await stopMemory();
|
|
299
|
+
}
|
|
300
|
+
finally {
|
|
301
|
+
sources.invalidate();
|
|
302
|
+
}
|
|
303
|
+
},
|
|
304
|
+
prompts: () => ({
|
|
305
|
+
persona: readPersona(personaFile),
|
|
306
|
+
worldPrompt: existsSync(worldPromptFile) ? { text: readFileSync(worldPromptFile, 'utf8'), custom: true } : { text: readFileSync(DEFAULT_TEMPLATE_FILE, 'utf8'), custom: false },
|
|
307
|
+
}),
|
|
308
|
+
savePersona: persona => { writePersona(personaFile, { ...readPersona(personaFile), ...persona }); sources.invalidate(); },
|
|
309
|
+
setDailyBudget: yuan => { power.setDailyBudget(yuan); sources.invalidate(); },
|
|
310
|
+
setMemoryTurns: turns => { power.setMemoryTurns(turns); sources.invalidate(); },
|
|
311
|
+
async setModules(patch) {
|
|
312
|
+
if (patch.wechat !== undefined && !config.wechat)
|
|
313
|
+
return '没有配置微信模块(配置里 wechat: true)';
|
|
314
|
+
if (patch.qq !== undefined && !config.qqBridgeDir)
|
|
315
|
+
return '没有配置 QQ 桥目录(配置里 qqBridgeDir)';
|
|
316
|
+
power.setModules(patch);
|
|
317
|
+
try {
|
|
318
|
+
if (patch.wechat === false)
|
|
319
|
+
await stopWechat();
|
|
320
|
+
if (patch.wechat === true && life)
|
|
321
|
+
await startWechat(life);
|
|
322
|
+
if (patch.qq === false)
|
|
323
|
+
stopQq();
|
|
324
|
+
if (patch.qq === true)
|
|
325
|
+
startQq();
|
|
326
|
+
}
|
|
327
|
+
catch (error) {
|
|
328
|
+
faults.set('wechat', `微信模块没能切换:${errorText(error)}`);
|
|
329
|
+
lifeCtx.logger.error(error);
|
|
330
|
+
return `切换失败:${errorText(error)}`;
|
|
331
|
+
}
|
|
332
|
+
finally {
|
|
333
|
+
sources.invalidate();
|
|
334
|
+
}
|
|
335
|
+
faults.clear('wechat');
|
|
336
|
+
return undefined;
|
|
337
|
+
},
|
|
338
|
+
restartWechatAdapter: async () => { if (!adapter)
|
|
339
|
+
return false; try {
|
|
340
|
+
await adapter.restart();
|
|
341
|
+
}
|
|
342
|
+
finally {
|
|
343
|
+
sources.invalidate();
|
|
344
|
+
} return true; },
|
|
345
|
+
setWechatSettings: next => { power.setWechat(next); sources.invalidate(); },
|
|
346
|
+
setArchiveScope: scope => { power.setArchiveScope(scope); sources.invalidate(); return power.restartRequired(); },
|
|
347
|
+
saveWorldPrompt: text => { if (text.trim())
|
|
348
|
+
durableWrite(worldPromptFile, text);
|
|
349
|
+
else
|
|
350
|
+
rmSync(worldPromptFile, { force: true }); },
|
|
351
|
+
};
|
|
352
|
+
lifeCtx.effect(() => webServer.register(consoleRoute(sources, actions, config.allowedHosts)), 'dsh-world console routes');
|
|
353
|
+
if (power.running())
|
|
354
|
+
await startLife(false);
|
|
355
|
+
});
|
|
356
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ActivityRecord } from './types.ts';
|
|
2
|
+
/** Shell commands cannot be reliably scoped, so they always count as outside the room. The path check is lexical: symlinks/junctions, `~` and `%VAR%` are not resolved. */
|
|
3
|
+
export declare function summarizeCall(tool: string, argumentsJson: string, roomDir: string): {
|
|
4
|
+
summary: string;
|
|
5
|
+
outside: boolean;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* What she actually did between `since` and `now`, in one line she can hold against the note she wrote.
|
|
9
|
+
*
|
|
10
|
+
* She asked for this (2026-10-26): an alarm that only repeats her own promise lets her believe she kept
|
|
11
|
+
* it. Counting her calls and naming the last thing she touched turns "歇着" into a claim that can fail.
|
|
12
|
+
* Empty string means "nothing to say" — the caller drops the sentence rather than print an empty one.
|
|
13
|
+
*/
|
|
14
|
+
export declare function summarizeSince(records: readonly ActivityRecord[], sinceIso: string, now: Date): string;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { isAbsolute, relative, resolve } from 'node:path';
|
|
2
|
+
const shells = new Set(['pwsh', 'bash', 'powershell', 'shell']);
|
|
3
|
+
const pathKeys = new Set(['path', 'file_path', 'filePath', 'paths', 'cwd', 'directory', 'dir', 'target', 'source', 'destination', 'root', 'folder']);
|
|
4
|
+
const clip = (text) => Array.from(text.replace(/\s+/g, ' ').trim()).slice(0, 160).join('');
|
|
5
|
+
/** Path strings under pathKeys at any depth, so nested operation arrays are covered. */
|
|
6
|
+
function collectPaths(value, keyed, out) {
|
|
7
|
+
if (typeof value === 'string') {
|
|
8
|
+
if (keyed)
|
|
9
|
+
out.push(value);
|
|
10
|
+
}
|
|
11
|
+
else if (Array.isArray(value))
|
|
12
|
+
for (const item of value)
|
|
13
|
+
collectPaths(item, keyed, out);
|
|
14
|
+
else if (value && typeof value === 'object')
|
|
15
|
+
for (const [key, item] of Object.entries(value))
|
|
16
|
+
collectPaths(item, keyed || pathKeys.has(key), out);
|
|
17
|
+
return out;
|
|
18
|
+
}
|
|
19
|
+
/** Shell commands cannot be reliably scoped, so they always count as outside the room. The path check is lexical: symlinks/junctions, `~` and `%VAR%` are not resolved. */
|
|
20
|
+
export function summarizeCall(tool, argumentsJson, roomDir) {
|
|
21
|
+
let parsed;
|
|
22
|
+
try {
|
|
23
|
+
parsed = JSON.parse(argumentsJson);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
parsed = undefined;
|
|
27
|
+
}
|
|
28
|
+
const args = parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : {};
|
|
29
|
+
if (shells.has(tool.toLowerCase()))
|
|
30
|
+
return { summary: clip(typeof args.command === 'string' ? args.command : argumentsJson), outside: true };
|
|
31
|
+
const paths = collectPaths(args, false, []);
|
|
32
|
+
const inside = (path) => { const rel = relative(roomDir, resolve(roomDir, path)); return rel === '' || (!/^\.\.(?:[\\/]|$)/.test(rel) && !isAbsolute(rel)); };
|
|
33
|
+
return { summary: clip(paths.length ? paths.join(', ') : argumentsJson), outside: paths.some(path => !inside(path)) };
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* What she actually did between `since` and `now`, in one line she can hold against the note she wrote.
|
|
37
|
+
*
|
|
38
|
+
* She asked for this (2026-10-26): an alarm that only repeats her own promise lets her believe she kept
|
|
39
|
+
* it. Counting her calls and naming the last thing she touched turns "歇着" into a claim that can fail.
|
|
40
|
+
* Empty string means "nothing to say" — the caller drops the sentence rather than print an empty one.
|
|
41
|
+
*/
|
|
42
|
+
export function summarizeSince(records, sinceIso, now) {
|
|
43
|
+
const from = Date.parse(sinceIso);
|
|
44
|
+
const until = now.getTime();
|
|
45
|
+
if (!Number.isFinite(from))
|
|
46
|
+
return '';
|
|
47
|
+
const mine = records.filter(record => {
|
|
48
|
+
const at = Date.parse(record.time);
|
|
49
|
+
return Number.isFinite(at) && at >= from && at <= until;
|
|
50
|
+
});
|
|
51
|
+
if (!mine.length)
|
|
52
|
+
return '这段时间我没动过手。';
|
|
53
|
+
const tools = [...new Set(mine.map(record => record.tool))];
|
|
54
|
+
const shown = tools.slice(0, 3).join('、') + (tools.length > 3 ? ` 等 ${tools.length} 种` : '');
|
|
55
|
+
const last = mine[mine.length - 1];
|
|
56
|
+
const touched = Array.from(last.summary).slice(0, 40).join('').trim();
|
|
57
|
+
return `这段时间我动了 ${mine.length} 次手(${shown})${touched ? `,最后一次是:${touched}` : ''}。`;
|
|
58
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Alarm, Review } from './types.ts';
|
|
2
|
+
import { type AlarmMessages } from './messages.ts';
|
|
3
|
+
/** Every evening at this local time she looks back on the day. */
|
|
4
|
+
export declare const REVIEW_TIME = "23:00";
|
|
5
|
+
export declare function resolveAlarmTime(input: {
|
|
6
|
+
at?: string;
|
|
7
|
+
after_minutes?: number;
|
|
8
|
+
}, now: Date, timeZone?: string): Date;
|
|
9
|
+
/** The first instant strictly after `now` whose local time in `timeZone` is hhmm:00; a time skipped by a DST gap lands on the first instant after the gap. */
|
|
10
|
+
export declare function nextLocalTime(now: Date, hhmm: string, timeZone: string): Date;
|
|
11
|
+
export declare function formatDuration(ms: number): string;
|
|
12
|
+
/**
|
|
13
|
+
* What she hears when an alarm rings. The wording comes from the alarm template (`extra` carries her
|
|
14
|
+
* names for templates that use them, plus `did` — one line about what she actually did since she set the
|
|
15
|
+
* alarm, so the promise and the record arrive together); the 【我的时间】 mark is always the plugin's own.
|
|
16
|
+
*/
|
|
17
|
+
export declare function wakeText(alarm: Alarm, now: Date, timeZone: string, fallbackWakeTime: string, messages?: AlarmMessages, extra?: Record<string, string>): string;
|
|
18
|
+
/** What a new home says the moment it is built, or her home when her world starts again. */
|
|
19
|
+
export declare function greetingText(kind: 'arrival' | 'return', timeZone: string, fallbackWakeTime: string, messages?: AlarmMessages, extra?: Record<string, string>): string;
|
|
20
|
+
/** The next evening look back after `now`, and the day it looks back on. */
|
|
21
|
+
export declare function nextReview(now: Date, timeZone: string): Review;
|
|
22
|
+
/** Where her day is written down; a file that does not exist is left out. */
|
|
23
|
+
export interface ReviewFiles {
|
|
24
|
+
conversations?: string;
|
|
25
|
+
activity?: string;
|
|
26
|
+
diaryDir: string;
|
|
27
|
+
selfFile: string;
|
|
28
|
+
snapshot?: string;
|
|
29
|
+
}
|
|
30
|
+
/** The evening look back: the day, where to read it, and her 我是谁 to rewrite if she has changed. */
|
|
31
|
+
export declare function reviewText(review: Review, now: Date, files: ReviewFiles, timeZone: string, fallbackWakeTime: string, messages?: AlarmMessages, extra?: Record<string, string>): string;
|
|
32
|
+
/** What she hears when a home turn stops well before the time she said she would keep at it. */
|
|
33
|
+
export declare function earlyStopText(alarm: Alarm, now: Date, timeZone: string, messages?: AlarmMessages, extra?: Record<string, string>): string;
|
|
34
|
+
/** plan_next's answer. Replacing her own plan says what it carried, while she can still copy it over; the plugin's own alarms are replaced silently. */
|
|
35
|
+
export declare function planReply(at: Date, replaced: Alarm | undefined, timeZone: string): string;
|
|
36
|
+
export declare function checkReply(alarm: Alarm | undefined, now: Date, timeZone: string): string;
|
|
37
|
+
export declare function cancelReply(cancelled: Alarm | undefined, next: Alarm | undefined, timeZone: string): string;
|
|
38
|
+
/** Told once a day, when her home has spent past the daily budget. */
|
|
39
|
+
export declare function budgetText(spent: number, budget: number, messages?: AlarmMessages, extra?: Record<string, string>): string;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { formatLocalTime } from "../timeContext.js";
|
|
2
|
+
import { ALARM_MARK, exampleTime, fillMessage, readAlarmMessages } from "./messages.js";
|
|
3
|
+
const MIN_ALARM_MS = 60_000;
|
|
4
|
+
const LATE_NOTICE_MS = 2 * 60_000;
|
|
5
|
+
/** Every evening at this local time she looks back on the day. */
|
|
6
|
+
export const REVIEW_TIME = '23:00';
|
|
7
|
+
export function resolveAlarmTime(input, now, timeZone = 'UTC') {
|
|
8
|
+
if ((input.at === undefined) === (input.after_minutes === undefined))
|
|
9
|
+
throw new Error('请只给 at 或 after_minutes 其中一个');
|
|
10
|
+
let target;
|
|
11
|
+
if (input.at !== undefined) {
|
|
12
|
+
if (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:\d{2})$/.test(input.at))
|
|
13
|
+
throw new Error(`at 需要 ISO 8601 格式并带时区,例如 ${exampleTime(timeZone)}`);
|
|
14
|
+
target = new Date(input.at);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
const minutes = input.after_minutes;
|
|
18
|
+
if (!Number.isFinite(minutes) || minutes <= 0)
|
|
19
|
+
throw new Error('after_minutes 必须是正数');
|
|
20
|
+
target = new Date(now.getTime() + minutes * 60_000);
|
|
21
|
+
}
|
|
22
|
+
if (!Number.isFinite(target.getTime()))
|
|
23
|
+
throw new Error(`无法识别的时间:${input.at ?? input.after_minutes}`);
|
|
24
|
+
if (target.getTime() - now.getTime() < MIN_ALARM_MS)
|
|
25
|
+
throw new Error('闹钟至少要定在 1 分钟之后');
|
|
26
|
+
return target;
|
|
27
|
+
}
|
|
28
|
+
const offsetMs = (at, timeZone) => {
|
|
29
|
+
const m = /([+-])(\d{2}):(\d{2})$/.exec(formatLocalTime(new Date(at), timeZone));
|
|
30
|
+
return (m[1] === '-' ? -1 : 1) * (Number(m[2]) * 60 + Number(m[3])) * 60_000;
|
|
31
|
+
};
|
|
32
|
+
/** The first instant strictly after `now` whose local time in `timeZone` is hhmm:00; a time skipped by a DST gap lands on the first instant after the gap. */
|
|
33
|
+
export function nextLocalTime(now, hhmm, timeZone) {
|
|
34
|
+
const [hour, minute] = hhmm.split(':').map(Number);
|
|
35
|
+
const today = formatLocalTime(now, timeZone);
|
|
36
|
+
const [y, mo, d] = [Number(today.slice(0, 4)), Number(today.slice(5, 7)), Number(today.slice(8, 10))];
|
|
37
|
+
for (let k = 0; k < 3; k++) {
|
|
38
|
+
const wall = Date.UTC(y, mo - 1, d + k, hour, minute);
|
|
39
|
+
const date = new Date(wall).toISOString().slice(0, 10);
|
|
40
|
+
const want = `${date}T${hhmm}:00`;
|
|
41
|
+
const around = [offsetMs(wall - 86_400_000, timeZone), offsetMs(wall + 86_400_000, timeZone)];
|
|
42
|
+
const hits = [...new Set(around)].map(offset => wall - offset).filter(at => formatLocalTime(new Date(at), timeZone).slice(0, 19) === want);
|
|
43
|
+
let at = hits.length ? Math.min(...hits.filter(h => h > now.getTime()), Infinity) : NaN;
|
|
44
|
+
if (!hits.length) {
|
|
45
|
+
// Skipped by a gap: the first instant from which the local clock reads at least the wanted time.
|
|
46
|
+
let [lo, hi] = [wall - Math.max(...around), wall - Math.min(...around)].sort((a, b) => a - b);
|
|
47
|
+
while (hi - lo > 1) {
|
|
48
|
+
const mid = Math.floor((lo + hi) / 2);
|
|
49
|
+
if (formatLocalTime(new Date(mid), timeZone).slice(0, 19) >= want)
|
|
50
|
+
hi = mid;
|
|
51
|
+
else
|
|
52
|
+
lo = mid;
|
|
53
|
+
}
|
|
54
|
+
at = hi;
|
|
55
|
+
}
|
|
56
|
+
if (at > now.getTime() && Number.isFinite(at))
|
|
57
|
+
return new Date(at);
|
|
58
|
+
}
|
|
59
|
+
throw new Error(`找不到 ${hhmm} 之后的下一个时间`);
|
|
60
|
+
}
|
|
61
|
+
export function formatDuration(ms) {
|
|
62
|
+
const minutes = Math.max(0, Math.round(ms / 60_000));
|
|
63
|
+
const days = Math.floor(minutes / 1440);
|
|
64
|
+
const hours = Math.floor((minutes % 1440) / 60);
|
|
65
|
+
const rest = minutes % 60;
|
|
66
|
+
const parts = [days ? `${days} 天` : '', hours ? `${hours} 小时` : '', rest || (!days && !hours) ? `${rest} 分` : ''];
|
|
67
|
+
return parts.filter(Boolean).join(' ');
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* What she hears when an alarm rings. The wording comes from the alarm template (`extra` carries her
|
|
71
|
+
* names for templates that use them, plus `did` — one line about what she actually did since she set the
|
|
72
|
+
* alarm, so the promise and the record arrive together); the 【我的时间】 mark is always the plugin's own.
|
|
73
|
+
*/
|
|
74
|
+
export function wakeText(alarm, now, timeZone, fallbackWakeTime, messages = readAlarmMessages(undefined), extra = {}) {
|
|
75
|
+
const base = { ...extra, timeZone, fallbackWakeTime };
|
|
76
|
+
const lateText = lateNotice(now.getTime() - Date.parse(alarm.at), messages, base);
|
|
77
|
+
const body = alarm.source === 'fallback' ? fillMessage(messages, '早上兜底', { ...base, late: lateText })
|
|
78
|
+
: fillMessage(messages, '闹钟响了', { ...base, time: formatLocalTime(new Date(alarm.at), timeZone), note: alarm.note, late: lateText }, { note: Boolean(alarm.note), did: Boolean(extra.did) });
|
|
79
|
+
return withTail(body, messages, base);
|
|
80
|
+
}
|
|
81
|
+
/** What a new home says the moment it is built, or her home when her world starts again. */
|
|
82
|
+
export function greetingText(kind, timeZone, fallbackWakeTime, messages = readAlarmMessages(undefined), extra = {}) {
|
|
83
|
+
const base = { ...extra, timeZone, fallbackWakeTime };
|
|
84
|
+
return withTail(fillMessage(messages, kind === 'arrival' ? '第一次到家' : '重新开始', base), messages, base);
|
|
85
|
+
}
|
|
86
|
+
/** The next evening look back after `now`, and the day it looks back on. */
|
|
87
|
+
export function nextReview(now, timeZone) {
|
|
88
|
+
const at = nextLocalTime(now, REVIEW_TIME, timeZone);
|
|
89
|
+
return { at: at.toISOString(), day: formatLocalTime(at, timeZone).slice(0, 10) };
|
|
90
|
+
}
|
|
91
|
+
/** The evening look back: the day, where to read it, and her 我是谁 to rewrite if she has changed. */
|
|
92
|
+
export function reviewText(review, now, files, timeZone, fallbackWakeTime, messages = readAlarmMessages(undefined), extra = {}) {
|
|
93
|
+
const base = { ...extra, timeZone, fallbackWakeTime };
|
|
94
|
+
const values = { ...base, date: review.day, diaryDir: files.diaryDir, selfFile: files.selfFile, conversations: files.conversations ?? '', activity: files.activity ?? '', snapshot: files.snapshot ?? '', late: lateNotice(now.getTime() - Date.parse(review.at), messages, base) };
|
|
95
|
+
return withTail(fillMessage(messages, '每日回顾', values, { conversations: Boolean(files.conversations), activity: Boolean(files.activity), snapshot: Boolean(files.snapshot) }), messages, base);
|
|
96
|
+
}
|
|
97
|
+
function lateNotice(late, messages, values) {
|
|
98
|
+
return late >= LATE_NOTICE_MS ? fillMessage(messages, '晚到说明', { ...values, lateBy: formatDuration(late) }) : '';
|
|
99
|
+
}
|
|
100
|
+
function withTail(body, messages, values) {
|
|
101
|
+
const tail = fillMessage(messages, '结尾提醒', values);
|
|
102
|
+
return `${ALARM_MARK}${body}${tail ? `\n${tail}` : ''}`;
|
|
103
|
+
}
|
|
104
|
+
/** What she hears when a home turn stops well before the time she said she would keep at it. */
|
|
105
|
+
export function earlyStopText(alarm, now, timeZone, messages = readAlarmMessages(undefined), extra = {}) {
|
|
106
|
+
const body = fillMessage(messages, '提前停下', { ...extra, timeZone, time: formatLocalTime(new Date(alarm.at), timeZone), now: formatLocalTime(now, timeZone), note: alarm.note }, { note: Boolean(alarm.note) });
|
|
107
|
+
return `${ALARM_MARK}${body}`;
|
|
108
|
+
}
|
|
109
|
+
const local = (at, timeZone) => formatLocalTime(new Date(at), timeZone);
|
|
110
|
+
/** plan_next's answer. Replacing her own plan says what it carried, while she can still copy it over; the plugin's own alarms are replaced silently. */
|
|
111
|
+
export function planReply(at, replaced, timeZone) {
|
|
112
|
+
const old = replaced?.source === 'plan' ? `(替换了原来做到 ${local(replaced.at, timeZone)} 的安排${replaced.note ? `:「${replaced.note}」。还想留着里面的事,就写进新的 note` : ''}。)` : '';
|
|
113
|
+
return `记下了,到 ${local(at, timeZone)} 提醒我。${old}`;
|
|
114
|
+
}
|
|
115
|
+
export function checkReply(alarm, now, timeZone) {
|
|
116
|
+
if (!alarm)
|
|
117
|
+
return '现在没有闹钟。';
|
|
118
|
+
const left = Date.parse(alarm.at) - now.getTime();
|
|
119
|
+
const when = `${local(alarm.at, timeZone)}(${left > 0 ? `还有 ${formatDuration(left)}` : '已经到点,正在叫我'})`;
|
|
120
|
+
if (alarm.source === 'plan')
|
|
121
|
+
return `我说好${alarm.note ? `做「${alarm.note}」` : ''}做到 ${when}。`;
|
|
122
|
+
return `我现在没有自己定的闹钟。下一次会在 ${when}按平常的时间叫我。`;
|
|
123
|
+
}
|
|
124
|
+
export function cancelReply(cancelled, next, timeZone) {
|
|
125
|
+
if (cancelled?.source !== 'plan')
|
|
126
|
+
return `现在没有我自己定的闹钟,不用取消。${next ? `下一次会在 ${local(next.at, timeZone)} 按平常的时间叫我。` : ''}`;
|
|
127
|
+
return `取消了做到 ${local(cancelled.at, timeZone)} 的安排${cancelled.note ? `:「${cancelled.note}」` : ''}。不另定的话,我就休息到 ${next ? local(next.at, timeZone) : '明早'}。`;
|
|
128
|
+
}
|
|
129
|
+
/** Told once a day, when her home has spent past the daily budget. */
|
|
130
|
+
export function budgetText(spent, budget, messages = readAlarmMessages(undefined), extra = {}) {
|
|
131
|
+
return `${ALARM_MARK}${fillMessage(messages, '额度用完', { ...extra, spent: spent.toFixed(2), budget: budget.toFixed(2) })}`;
|
|
132
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface LifeTimers {
|
|
2
|
+
set(fn: () => void, ms: number): unknown;
|
|
3
|
+
clear(handle: unknown): void;
|
|
4
|
+
}
|
|
5
|
+
export declare const realTimers: LifeTimers;
|
|
6
|
+
/**
|
|
7
|
+
* Waits for the pending alarm and calls `fire` once it is due, never before. A failed delivery backs off
|
|
8
|
+
* (1, 5, 15, 30, 60 minutes); a new alarm or a delivery that worked starts the backoff over.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createAlarmTimer(deps: {
|
|
11
|
+
clock: () => Date;
|
|
12
|
+
timers: LifeTimers;
|
|
13
|
+
dueAlarm: () => string | undefined;
|
|
14
|
+
fire: () => void;
|
|
15
|
+
}): {
|
|
16
|
+
arm: () => void;
|
|
17
|
+
/** Starts the backoff over (a new alarm, or one that was delivered) and re-arms. */
|
|
18
|
+
reset(): void;
|
|
19
|
+
/** A delivery failed: the next try waits out the backoff. Returns the wait in minutes. */
|
|
20
|
+
failed(): number;
|
|
21
|
+
stop(): void;
|
|
22
|
+
};
|