dsh-qqbot-muu 0.1.15 → 0.1.21
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/CHANGELOG.md +168 -85
- package/client/qqbot-settings.js +13401 -12024
- package/config/modules.json +212 -0
- package/dist/channel-tools.js +21 -10
- package/dist/config.d.ts +14 -0
- package/dist/config.js +573 -449
- package/dist/features/contextless-store.js +247 -247
- package/dist/features/contextless-trim.js +455 -34
- package/dist/features/four-source.js +338 -336
- package/dist/features/group-join-request.js +289 -287
- package/dist/features/local-models.js +1494 -0
- package/dist/features/rotate-summarizer.js +438 -0
- package/dist/features/scenario-detect.js +321 -0
- package/dist/features/scheduler.js +8 -1
- package/dist/features/session-rotate.js +499 -0
- package/dist/features/session-title.js +199 -0
- package/dist/features/style-layer.js +501 -0
- package/dist/features/thinking-log.js +71 -69
- package/dist/gateway/bootstrap.js +1704 -1388
- package/dist/gateway/data-root.js +77 -3
- package/dist/gateway/middleware-setup.js +6 -3
- package/dist/index.js +4 -2
- package/dist/model/settings-reader.js +193 -102
- package/dist/session/session-manager.js +1730 -1587
- package/dist/shared/paths.js +128 -0
- package/dist/shared/settings-io.js +79 -0
- package/dist/transport/inbound.js +20 -1
- package/dist/transport/outbound.js +56 -4
- package/docs/RELEASE_CHECKLIST.md +24 -2
- package/dshqqbot/.qqbot-extensions/hooks/interview-panel.mjs +41 -1
- package/dshqqbot/.qqbot-extensions/inbound/00-vision.mjs +111 -0
- package/dshqqbot/.qqbot-extensions/inbound/aa-memory-recall.mjs +802 -689
- package/dshqqbot/.qqbot-extensions/inbound/ac-image-see.mjs +1 -1
- package/dshqqbot/.qqbot-extensions/inbound/az-feedback.mjs +113 -115
- package/dshqqbot/.qqbot-extensions/inbound/local-answer.mjs +689 -568
- package/dshqqbot/.qqbot-extensions/lib/.pet-form.json +1 -1
- package/dshqqbot/.qqbot-extensions/lib/draw-core.mjs +238 -7
- package/dshqqbot/.qqbot-extensions/lib/local-llm.mjs +455 -394
- package/dshqqbot/.qqbot-extensions/lib/memory-agent.mjs +930 -928
- package/dshqqbot/.qqbot-extensions/lib/memory-core.mjs +537 -537
- package/dshqqbot/.qqbot-extensions/lib/memory-db.mjs +2476 -2245
- package/dshqqbot/.qqbot-extensions/lib/memory-hippo.mjs +18 -0
- package/dshqqbot/.qqbot-extensions/lib/memory.mjs +191 -186
- package/dshqqbot/.qqbot-extensions/lib/plugin-dir.mjs +14 -4
- package/dshqqbot/.qqbot-extensions/lib/scope-util.mjs +84 -0
- package/dshqqbot/.qqbot-extensions/lib/vision.mjs +1 -1
- package/dshqqbot/.qqbot-extensions/outbound/aa-sanitize.mjs +158 -154
- package/dshqqbot/.qqbot-extensions/outbound/ac-media-fix.mjs +5 -1
- package/dshqqbot/.qqbot-extensions/outbound/memory-agent.mjs +121 -130
- package/dshqqbot/.qqbot-extensions/outbound/split-reply.mjs +18 -2
- package/dshqqbot/.qqbot-extensions/outbound/turn-memory.mjs +92 -101
- package/dshqqbot/.qqbot-extensions/tools/draw.mjs +22 -1
- package/dshqqbot/.qqbot-extensions/tools/memory.mjs +178 -120
- package/dshqqbot/.qqbot-extensions/tools/pet_card.mjs +3 -2
- package/dshqqbot/.qqbot-extensions/tools/storyboard.mjs +3 -1
- package/dshqqbot/.qqbot-extensions/vendor/abogus/test-abogus.mjs +128 -126
- package/package.json +119 -111
- package/scripts/__pycache__/fan-mode.cpython-311.pyc +0 -0
- package/scripts/__pycache__/memory-audit.cpython-311.pyc +0 -0
- package/scripts/__pycache__/qq-ip-sync.cpython-311.pyc +0 -0
- package/scripts/__pycache__/qq-whitelist.cpython-311.pyc +0 -0
- package/scripts/_add_maintenance_cfg.py +20 -0
- package/scripts/_bench_keeplease.sh +10 -0
- package/scripts/_dbg_purge.py +15 -0
- package/scripts/_elev.sh +6 -0
- package/scripts/_fix_all_admin.cmd +16 -0
- package/scripts/_livecheck-image.mjs +33 -0
- package/scripts/_livecheck-llm.mjs +34 -0
- package/scripts/_livecheck-tts.mjs +37 -0
- package/scripts/_patch_curve.py +88 -0
- package/scripts/_patch_fan_thermal.py +24 -0
- package/scripts/_tag_tmp.py +13 -0
- package/scripts/adb-broker-client.mjs +87 -0
- package/scripts/adb-broker.mjs +205 -0
- package/scripts/ai-mode.cmd +6 -0
- package/scripts/ai-mode.py +387 -0
- package/scripts/ai-toolkit.py +607 -0
- package/scripts/apply-fan-gpu45.py +51 -0
- package/scripts/bench-fans.py +515 -0
- package/scripts/bench-load-direct.py +63 -0
- package/scripts/boot-tasks-hidden.vbs +20 -0
- package/scripts/boot-tasks.cmd +277 -0
- package/scripts/chat-archive/__pycache__/build-sft-v4.cpython-311.pyc +0 -0
- package/scripts/chat-archive/__pycache__/build-sft.cpython-311.pyc +0 -0
- package/scripts/chat-archive/build-sft-v4.py +566 -0
- package/scripts/chat-archive/build-sft.py +390 -0
- package/scripts/chat-archive/eval-sft.py +155 -0
- package/scripts/chat-archive/extract-memory.py +143 -0
- package/scripts/chat-archive/inventory.py +182 -0
- package/scripts/chat-archive/merge-sft.py +114 -0
- package/scripts/chat-archive/qce-pull.py +217 -0
- package/scripts/chat-archive/qqheader.py +110 -0
- package/scripts/chat-archive/qqkey2.py +113 -0
- package/scripts/chat-archive/qqprobe.py +153 -0
- package/scripts/chat-archive/screen-collect.py +163 -0
- package/scripts/chat-archive/sqlcipher_probe.py +444 -0
- package/scripts/comfy_gen.py +209 -0
- package/scripts/compose-video.py +168 -0
- package/scripts/dl_models.py +45 -0
- package/scripts/draw-now.cmd +18 -0
- package/scripts/dsh-instance-guard.mjs +20 -2
- package/scripts/elev-extra.cmd +25 -0
- package/scripts/episode.py +529 -0
- package/scripts/fan-curve.py +218 -0
- package/scripts/fan-guard.cmd +8 -0
- package/scripts/fan-mode.py +380 -0
- package/scripts/fan_manual_safe.py +33 -0
- package/scripts/fan_restore_manual.py +46 -0
- package/scripts/fc_curves.py +359 -0
- package/scripts/fix-fan-and-timers.cmd +39 -0
- package/scripts/fix_admin_all.py +94 -0
- package/scripts/flows.mjs +224 -0
- package/scripts/gateway.cmd +126 -0
- package/scripts/gen-image.py +420 -0
- package/scripts/gen-video.py +186 -0
- package/scripts/git-askpass.cmd +2 -2
- package/scripts/gpu-mode.py +195 -0
- package/scripts/hw-profile.py +175 -0
- package/scripts/install-schedule.cmd +37 -0
- package/scripts/install-watch.cmd +29 -0
- package/scripts/matte-cutout.py +106 -0
- package/scripts/media-enhance.py +402 -0
- package/scripts/memory-audit.py +581 -0
- package/scripts/migrate-scope.mjs +140 -139
- package/scripts/model-registry.py +519 -0
- package/scripts/openid-audit.mjs +219 -0
- package/scripts/pull-gguf.py +127 -0
- package/scripts/purge-standby.py +151 -0
- package/scripts/qq-connect-login.py +133 -0
- package/scripts/qq-ip-sync-hidden.vbs +5 -0
- package/scripts/qq-ip-sync.py +300 -0
- package/scripts/qq-login-once.cmd +20 -0
- package/scripts/qq-login-qr.py +72 -0
- package/scripts/qq-whitelist-fix.cmd +27 -0
- package/scripts/qq-whitelist-login.cmd +26 -0
- package/scripts/qq-whitelist.cmd +12 -0
- package/scripts/qq-whitelist.py +1452 -0
- package/scripts/quality-compare.py +134 -0
- package/scripts/release-all.mjs +636 -430
- package/scripts/release-check.mjs +244 -226
- package/scripts/resume-coder.cmd +38 -0
- package/scripts/secure-room/index.html +334 -0
- package/scripts/secure-room/server.py +582 -0
- package/scripts/security-check.mjs +164 -0
- package/scripts/selftest-local-llm.mjs +20 -0
- package/scripts/selftest-local-models.mjs +754 -0
- package/scripts/selftest-rotate-style.mjs +308 -0
- package/scripts/shutdown-s5-optional.cmd +21 -0
- package/scripts/sleep-2325.cmd +75 -0
- package/scripts/start-comfyui.cmd +5 -0
- package/scripts/start-strata.cmd +17 -0
- package/scripts/start-strata.vbs +11 -0
- package/scripts/start-watch-hidden.vbs +3 -0
- package/scripts/stickers/auto-tag.mjs +161 -0
- package/scripts/storage.mjs +236 -0
- package/scripts/sync-plugin-copies.mjs +98 -23
- package/scripts/tests/test-qq-whitelist.py +192 -0
- package/scripts/train/__pycache__/train-lora.cpython-311.pyc +0 -0
- package/scripts/train/gguf-quantize.py +92 -0
- package/scripts/train/gguf-to-hf.py +112 -0
- package/scripts/train/merge-lora.py +51 -0
- package/scripts/train/probe-mirrors.sh +12 -0
- package/scripts/train/probe-mirrors2.sh +20 -0
- package/scripts/train/setup-wsl.sh +23 -0
- package/scripts/train/setup-wsl2.sh +25 -0
- package/scripts/train/setup-wsl3.sh +22 -0
- package/scripts/train/setup-wsl4.sh +22 -0
- package/scripts/train/train-lora.py +319 -0
- package/scripts/vram-free.py +104 -0
- package/scripts/wechat-full-pull.mjs +1 -1
- package/settings-host.js +1047 -12
|
@@ -9,15 +9,18 @@
|
|
|
9
9
|
*
|
|
10
10
|
* 迁移: 首次启动时, 若 cwd 下存在旧数据目录而数据根下还没有, 自动整目录搬移(rename, 同盘瞬时完成), 不覆盖已有目标。
|
|
11
11
|
*/
|
|
12
|
-
import { accessSync, constants, existsSync, mkdirSync, renameSync } from 'node:fs';
|
|
12
|
+
import { accessSync, constants, existsSync, mkdirSync, readFileSync, renameSync, statSync } from 'node:fs';
|
|
13
13
|
import { homedir } from 'node:os';
|
|
14
14
|
import { join, resolve } from 'node:path';
|
|
15
|
+
import { fileURLToPath } from 'node:url';
|
|
15
16
|
import { absCwdOf } from '../util/abs-path.js';
|
|
16
17
|
/** 旧版数据直接落在 agent cwd 的清单(与数据根对应的相对布局; 目录+散文件) */
|
|
17
18
|
export const DATA_SUBDIRS = ['表情包', '.qqbot', '.qqbot-extensions', 'schedule-state.json', 'botplay-events.json'];
|
|
18
19
|
/** 未配置 dataRoot 时的默认数据子目录名(通用设计: 让工作目录保持干净) */
|
|
19
20
|
export const DEFAULT_DATA_SUBDIR = 'dshqqbot';
|
|
20
21
|
const _writableCache = new Map();
|
|
22
|
+
/** cwdRoot → 最终数据根(回退决策缓存,见 dataRootOf) */
|
|
23
|
+
const _fallbackCache = new Map();
|
|
21
24
|
/**
|
|
22
25
|
* 0.1.14:数据根落点兜底。
|
|
23
26
|
* 用户反馈「装上就报路径错误」的根因之一:插件从只读目录/系统目录启动时,
|
|
@@ -47,6 +50,56 @@ function pickWritableRoot(preferred) {
|
|
|
47
50
|
_writableCache.set(preferred, chosen);
|
|
48
51
|
return chosen;
|
|
49
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* 2026-12-01 DSH 0.14 升级兼容:profile 从 web 换成 desktop 后,agent cwd 变成了
|
|
55
|
+
* `…/harness/profiles/desktop`,于是 `{cwd}/dshqqbot` 指向一个**全新的空数据根** ——
|
|
56
|
+
* 记忆库、人设、表情包、扩展配置全部"消失"(表现:QQBot 功能缺失、不认人)。
|
|
57
|
+
*
|
|
58
|
+
* 这里做一次**保守**的自动回退:只有在
|
|
59
|
+
* ① 没显式配 dataRoot;
|
|
60
|
+
* ② 当前 cwd 数据根没有"真实数据";
|
|
61
|
+
* ③ 插件包旁边(或 config/repo-root.json 指向的仓库)确实有一份真实数据
|
|
62
|
+
* 三条同时成立时才切换,并打一行 warn。用户显式配了 dataRoot 就永远以配置为准。
|
|
63
|
+
*/
|
|
64
|
+
function hasRealData(root) {
|
|
65
|
+
try {
|
|
66
|
+
const db = join(root, '.qqbot', 'memory.db');
|
|
67
|
+
if (statSync(db).size > 200 * 1024)
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
catch { /* 还没建库 */ }
|
|
71
|
+
// 老用户即使没记忆,也一定有台账/群表/表情包其中之一
|
|
72
|
+
for (const rel of ['.qqbot/known-chats.jsonl', '.qqbot/groups.json', '表情包']) {
|
|
73
|
+
try {
|
|
74
|
+
if (existsSync(join(root, rel)))
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
catch { /* ignore */ }
|
|
78
|
+
}
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
let _repoHint;
|
|
82
|
+
function repoRootHint() {
|
|
83
|
+
if (_repoHint !== undefined)
|
|
84
|
+
return _repoHint;
|
|
85
|
+
_repoHint = '';
|
|
86
|
+
let pkgRoot = '';
|
|
87
|
+
try {
|
|
88
|
+
pkgRoot = fileURLToPath(new URL('../..', import.meta.url));
|
|
89
|
+
}
|
|
90
|
+
catch { /* ignore */ }
|
|
91
|
+
if (!pkgRoot)
|
|
92
|
+
return _repoHint;
|
|
93
|
+
// 安装副本里同步脚本写的"真实仓库根"指针优先
|
|
94
|
+
try {
|
|
95
|
+
const j = JSON.parse(readFileSync(join(pkgRoot, 'config', 'repo-root.json'), 'utf8'));
|
|
96
|
+
if (j && j.root && existsSync(String(j.root))) { _repoHint = String(j.root); return _repoHint; }
|
|
97
|
+
}
|
|
98
|
+
catch { /* 没有指针 */ }
|
|
99
|
+
if (hasRealData(join(pkgRoot, 'dshqqbot')))
|
|
100
|
+
_repoHint = pkgRoot;
|
|
101
|
+
return _repoHint;
|
|
102
|
+
}
|
|
50
103
|
/**
|
|
51
104
|
* 插件数据根: config.dataRoot(绝对化) > `{cwd}/dshqqbot` > 进程 cwd。
|
|
52
105
|
*
|
|
@@ -56,12 +109,33 @@ function pickWritableRoot(preferred) {
|
|
|
56
109
|
* 想保留"数据就在工作目录"的老行为, 显式配 `dataRoot: <cwd>` 即可。
|
|
57
110
|
*/
|
|
58
111
|
export function dataRootOf(config) {
|
|
59
|
-
const r = config.dataRoot ? resolve(config.dataRoot) : '';
|
|
112
|
+
const r = config && config.dataRoot ? resolve(config.dataRoot) : '';
|
|
60
113
|
if (r)
|
|
61
114
|
return r;
|
|
62
115
|
// ⚠️ cwd 必须绝对化:安卓/设置页可能给出 "storage\emulated\0\大肥鱼" 这种相对路径,
|
|
63
116
|
// 直接 join 会被解析到 process.cwd() 下,凭空多出一套幽灵数据根(issue #18)。
|
|
64
|
-
|
|
117
|
+
const cwdRoot = join(absCwdOf(config && config.cwd) || process.cwd(), DEFAULT_DATA_SUBDIR);
|
|
118
|
+
// 2026-12-01:回退决策要缓存 —— 这个函数每条消息都会调,而 hasRealData 是 3 次 statSync;
|
|
119
|
+
// 不缓存还会把「自动改用仓库数据根」的 warn 每轮刷一遍。
|
|
120
|
+
const cached = _fallbackCache.get(cwdRoot);
|
|
121
|
+
if (cached)
|
|
122
|
+
return cached;
|
|
123
|
+
try {
|
|
124
|
+
const repo = repoRootHint();
|
|
125
|
+
if (repo) {
|
|
126
|
+
const repoData = join(repo, 'dshqqbot');
|
|
127
|
+
if (resolve(repoData) !== resolve(cwdRoot) && hasRealData(repoData) && !hasRealData(cwdRoot)) {
|
|
128
|
+
console.warn(`[data-root] 当前数据根 ${cwdRoot} 是空的,自动改用仓库数据根 ${repoData}(DSH 升级换 profile 后常见;显式配 dataRoot 可覆盖)`);
|
|
129
|
+
const chosen = pickWritableRoot(repoData);
|
|
130
|
+
_fallbackCache.set(cwdRoot, chosen);
|
|
131
|
+
return chosen;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
catch { /* 探测失败按老逻辑 */ }
|
|
136
|
+
const chosen = pickWritableRoot(cwdRoot);
|
|
137
|
+
_fallbackCache.set(cwdRoot, chosen);
|
|
138
|
+
return chosen;
|
|
65
139
|
}
|
|
66
140
|
/** 图库/台账/活性计数等通用数据目录: config.sticker.dataDir 覆盖 > {dataRoot}/表情包 */
|
|
67
141
|
export function stickerDirOf(config) {
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
/** 从盘上直接读 autoRecall(settings 热更不落到闭包 config 时的兜底,2026-10-20)
|
|
1
|
+
/** 从盘上直接读 autoRecall(settings 热更不落到闭包 config 时的兜底,2026-10-20)
|
|
2
|
+
* 2026-12-01:DSH 0.14 把设置目录从 ~/.dsh 挪到 %APPDATA%/dsh-desktop/harness,
|
|
3
|
+
* 这里改走 findSettingsFile()(新→旧目录自动找,profile 不再写死 web)。 */
|
|
2
4
|
function readAutoRecallFromDiskMw(cfg) {
|
|
3
5
|
try {
|
|
4
6
|
const c = cfg;
|
|
5
|
-
const prof = process.env.DSH_PROFILE || 'web';
|
|
6
7
|
const ns = String(c?.settingsNs || c?.ns || 'im-qqbot-2');
|
|
7
|
-
const f =
|
|
8
|
+
const f = findSettingsFile(ns);
|
|
9
|
+
if (!f) return undefined;
|
|
8
10
|
const j = JSON.parse(readFileSync(f, 'utf8'));
|
|
9
11
|
return j?.groupAdmin?.autoRecall;
|
|
10
12
|
}
|
|
@@ -15,6 +17,7 @@ function readAutoRecallFromDiskMw(cfg) {
|
|
|
15
17
|
import { readFileSync } from 'node:fs';
|
|
16
18
|
import { homedir } from 'node:os';
|
|
17
19
|
import { join } from 'node:path';
|
|
20
|
+
import { findSettingsFile } from '../shared/settings-io.js';
|
|
18
21
|
import { errorHandler, messageFilter, accessPolicy, mentionGate, contentSanitizer, slashCommand, concurrencyGuard, typingIndicator, quoteRef, envelopeFormatter, } from '@tencent-connect/qqbot-nodejs';
|
|
19
22
|
import { dataRootOf, stickerDirOf } from './data-root.js';
|
|
20
23
|
import { accessScopeOf, careEmptyHint } from './access-care.js';
|
package/dist/index.js
CHANGED
|
@@ -13,6 +13,8 @@ import { bootstrapGateway } from './gateway/index.js';
|
|
|
13
13
|
import { takePendingMemoText } from './features/people-memo.js';
|
|
14
14
|
import { getProfileDir, resolveEnv, resolveProfileName } from './shared/index.js';
|
|
15
15
|
import { describeNsConflict, nsPathsOf, scanNsOwners } from './features/ns-guard.js';
|
|
16
|
+
// 2026-12-01:设置目录解析(DSH 0.14 desktop 用 %APPDATA%/dsh-desktop/harness,不是 ~/.dsh)
|
|
17
|
+
import { settingsHome } from './shared/settings-io.js';
|
|
16
18
|
void getProfileDir;
|
|
17
19
|
import { runQrSetup, persistCredentialsToProfile } from './setup.js';
|
|
18
20
|
// 2026-09-24 关闭"启动自动扫码"后,这些符号保留给设置页路径使用;此处显式引用避免 TS 未使用报错。
|
|
@@ -136,7 +138,7 @@ export async function apply(ctx, config) {
|
|
|
136
138
|
// 环境(DSH 走 `ctx.get('profileContext').name`,DSH_PROFILE 只在每次 shell/工具调用时临时注入),
|
|
137
139
|
// 于是这里永远拿到空 → 永远落 `_default/`,"web 与 desktop 各写各的"形同虚设。
|
|
138
140
|
// 改用 `resolveProfileName()`(环境变量 → 代码位置 → 宿主扫描兜底,细节见 src/shared/utils.ts)。
|
|
139
|
-
const nsPaths = nsPathsOf(
|
|
141
|
+
const nsPaths = nsPathsOf(settingsHome(), String(ns), resolveProfileName());
|
|
140
142
|
const ownSettingsFile = nsPaths.file;
|
|
141
143
|
const readOwnSettings = () => {
|
|
142
144
|
try {
|
|
@@ -188,7 +190,7 @@ export async function apply(ctx, config) {
|
|
|
188
190
|
// 一起被换掉(实测:web 的配置被 desktop 覆盖、QQ 连接被顶掉后收不到消息)。
|
|
189
191
|
// 这里只做**只读探测 + 告警**:不改任何 profile 文件、也不阻断启动。
|
|
190
192
|
try {
|
|
191
|
-
const nsHome =
|
|
193
|
+
const nsHome = settingsHome();
|
|
192
194
|
const myProfile = resolveProfileName();
|
|
193
195
|
const owners = scanNsOwners(nsHome, ns);
|
|
194
196
|
const others = owners.filter((p) => p !== myProfile);
|
|
@@ -1,103 +1,194 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SettingsReader — settings.yaml 只读解析
|
|
3
|
-
*
|
|
4
|
-
* 从 ~/.dsh/settings.yaml 中读取模型配置信息。
|
|
5
|
-
* 只读,不修改 settings.yaml。
|
|
6
|
-
*/
|
|
7
|
-
import { readFileSync, existsSync } from 'node:fs';
|
|
8
|
-
import { resolve } from 'node:path';
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
1
|
+
/**
|
|
2
|
+
* SettingsReader — settings.yaml 只读解析
|
|
3
|
+
*
|
|
4
|
+
* 从 ~/.dsh/settings.yaml 中读取模型配置信息。
|
|
5
|
+
* 只读,不修改 settings.yaml。
|
|
6
|
+
*/
|
|
7
|
+
import { readFileSync, existsSync, statSync } from 'node:fs';
|
|
8
|
+
import { resolve } from 'node:path';
|
|
9
|
+
import yaml from 'js-yaml';
|
|
10
|
+
import { dshHomeCandidates } from '../shared/paths.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 读 settings.yaml,并兼容 DSH 内核的「改名 + 搬家」行为。
|
|
14
|
+
*
|
|
15
|
+
* 2026-12-04(别的用户反馈的 bug):DSH 内核每次启动会把 settings.yaml 改名成
|
|
16
|
+
* settings.yaml.imported 再写一份新的;只认 settings.yaml 的插件就读不到
|
|
17
|
+
* im-qqbot.groupAdmin,owner/群管权限整体失效。
|
|
18
|
+
* 另一处变化:DSH 0.14 起设置根从 ~/.dsh 搬到 %APPDATA%/dsh-desktop/harness,
|
|
19
|
+
* 只认 ~/.dsh 的读法在新版上同样读不到。
|
|
20
|
+
*
|
|
21
|
+
* 现在的做法:把所有候选目录(paths.js dshHomeCandidates + DSH_CONFIG_DIR)里的
|
|
22
|
+
* settings.yaml / settings.yaml.imported / settings.imported / settings.yml 全收进来,
|
|
23
|
+
* 按文件修改时间从新到旧合并(新的优先,旧的只补缺的键)。
|
|
24
|
+
* 改名不改 mtime,所以「刚写的新 settings.yaml」自然排在「被改名的旧 .imported」前面。
|
|
25
|
+
*/
|
|
26
|
+
export function settingsDir() {
|
|
27
|
+
// 目录本身也可能被宿主改:DSH_HOME / DSH_CONFIG_DIR 优先,其次 ~/.dsh。
|
|
28
|
+
const env = process.env;
|
|
29
|
+
const dir = String(env.DSH_HOME || env.DSH_CONFIG_DIR || '').trim();
|
|
30
|
+
if (dir)
|
|
31
|
+
return dir;
|
|
32
|
+
const cands = dshHomeCandidates();
|
|
33
|
+
for (const c of cands) {
|
|
34
|
+
try {
|
|
35
|
+
if (existsSync(c))
|
|
36
|
+
return c;
|
|
37
|
+
}
|
|
38
|
+
catch { /* ignore */ }
|
|
39
|
+
}
|
|
40
|
+
return cands[0] || resolve('.');
|
|
41
|
+
}
|
|
42
|
+
/** 所有候选目录(按新→旧),显式指定的环境变量排最前 */
|
|
43
|
+
function settingsDirs() {
|
|
44
|
+
const out = [];
|
|
45
|
+
const push = (p) => {
|
|
46
|
+
const v = String(p || '').trim();
|
|
47
|
+
if (v && !out.includes(v))
|
|
48
|
+
out.push(v);
|
|
49
|
+
};
|
|
50
|
+
push(process.env.DSH_CONFIG_DIR);
|
|
51
|
+
push(process.env.DSH_HOME);
|
|
52
|
+
for (const c of dshHomeCandidates())
|
|
53
|
+
push(c);
|
|
54
|
+
push(settingsDir());
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
const SETTINGS_NAMES = ['settings.yaml', 'settings.yaml.imported', 'settings.imported', 'settings.yml'];
|
|
58
|
+
/** 收集现存候选文件,按 mtime 新→旧 */
|
|
59
|
+
function settingsFiles() {
|
|
60
|
+
const list = [];
|
|
61
|
+
const seen = new Set();
|
|
62
|
+
for (const dir of settingsDirs()) {
|
|
63
|
+
for (const name of SETTINGS_NAMES) {
|
|
64
|
+
const f = resolve(dir, name);
|
|
65
|
+
if (seen.has(f))
|
|
66
|
+
continue;
|
|
67
|
+
seen.add(f);
|
|
68
|
+
try {
|
|
69
|
+
if (!existsSync(f))
|
|
70
|
+
continue;
|
|
71
|
+
list.push({ f, mtime: statSync(f).mtimeMs || 0 });
|
|
72
|
+
}
|
|
73
|
+
catch { /* 没权限 → 跳过 */ }
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
list.sort((a, b) => b.mtime - a.mtime);
|
|
77
|
+
return list.map((x) => x.f);
|
|
78
|
+
}
|
|
79
|
+
function readSettingsMerged() {
|
|
80
|
+
const files = settingsFiles();
|
|
81
|
+
let merged = null;
|
|
82
|
+
let found = false;
|
|
83
|
+
for (const f of files) {
|
|
84
|
+
try {
|
|
85
|
+
const j = yaml.load(readFileSync(f, 'utf8'));
|
|
86
|
+
if (!j || typeof j !== 'object')
|
|
87
|
+
continue;
|
|
88
|
+
found = true;
|
|
89
|
+
merged = merged ? mergeFill(merged, j) : j;
|
|
90
|
+
}
|
|
91
|
+
catch { /* 单个文件坏了不影响其它候选 */ }
|
|
92
|
+
}
|
|
93
|
+
return found ? merged : null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** 深合并:a 已有的键优先,b 只补 a 缺的(所以 settings.yaml 优先于 .imported) */
|
|
97
|
+
function mergeFill(a, b) {
|
|
98
|
+
if (!a || typeof a !== 'object' || !b || typeof b !== 'object' || Array.isArray(a) || Array.isArray(b))
|
|
99
|
+
return a;
|
|
100
|
+
for (const [k, v] of Object.entries(b)) {
|
|
101
|
+
if (a[k] === undefined)
|
|
102
|
+
a[k] = v;
|
|
103
|
+
else if (a[k] && typeof a[k] === 'object' && v && typeof v === 'object')
|
|
104
|
+
mergeFill(a[k], v);
|
|
105
|
+
}
|
|
106
|
+
return a;
|
|
107
|
+
}
|
|
108
|
+
export class SettingsReader {
|
|
109
|
+
/** settings.yaml 缓存 */
|
|
110
|
+
settingsCache;
|
|
111
|
+
/**
|
|
112
|
+
* 从 settings.yaml 的 agent-default-model 字段读取默认模型路由
|
|
113
|
+
*/
|
|
114
|
+
readDefaultRoute() {
|
|
115
|
+
const settings = this.loadSettings();
|
|
116
|
+
if (!settings)
|
|
117
|
+
return undefined;
|
|
118
|
+
const defaultModel = settings['agent-default-model'];
|
|
119
|
+
if (defaultModel?.provider && defaultModel?.model) {
|
|
120
|
+
return { provider: defaultModel.provider, model: defaultModel.model };
|
|
121
|
+
}
|
|
122
|
+
return undefined;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* 列出 settings.yaml 中配置的所有模型
|
|
126
|
+
*/
|
|
127
|
+
readModels() {
|
|
128
|
+
const settings = this.loadSettings();
|
|
129
|
+
if (!settings)
|
|
130
|
+
return [];
|
|
131
|
+
const models = [];
|
|
132
|
+
const llmPiAi = settings['llm-pi-ai'];
|
|
133
|
+
if (llmPiAi?.providers) {
|
|
134
|
+
for (const [providerName, providerConfig] of Object.entries(llmPiAi.providers)) {
|
|
135
|
+
if (Array.isArray(providerConfig?.models)) {
|
|
136
|
+
for (const m of providerConfig.models) {
|
|
137
|
+
if (m.id) {
|
|
138
|
+
models.push({ provider: providerName, id: m.id, name: m.name || undefined });
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return models;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* 列出 settings.yaml 中配置的 provider 名称
|
|
148
|
+
*/
|
|
149
|
+
readProviders() {
|
|
150
|
+
const settings = this.loadSettings();
|
|
151
|
+
const llmPiAi = settings?.['llm-pi-ai'];
|
|
152
|
+
return llmPiAi?.providers ? Object.keys(llmPiAi.providers) : [];
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* 从 settings.yaml 的 <ns> 段读取 groupAdmin 配置。
|
|
156
|
+
* 解决"QQBot 构造时 intents 一次性读取"的时序坑: settings 服务的 Web 可视化配置
|
|
157
|
+
* (写 settings.yaml)是异步注入, 晚于 gateway 构造 → 启动期读文件才能在构造前拿到值。
|
|
158
|
+
* 返回 undefined = settings.yaml 无该 ns 或 ns 无 groupAdmin。
|
|
159
|
+
*/
|
|
160
|
+
readGroupAdmin(ns) {
|
|
161
|
+
const settings = this.loadSettings();
|
|
162
|
+
if (!settings)
|
|
163
|
+
return undefined;
|
|
164
|
+
const nsBlock = settings[ns];
|
|
165
|
+
const ga = nsBlock?.groupAdmin;
|
|
166
|
+
return ga && typeof ga === 'object' ? ga : undefined;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* 从 settings.yaml 的 <ns> 段读取群守则 groupPrompt(热更新用)。
|
|
170
|
+
* fresh=true 时绕过缓存现读磁盘(每次 system prompt 渲染调用, 使 Web 改完即时生效);
|
|
171
|
+
* 返回 undefined = 无该 ns / 无 groupPrompt / 空串。
|
|
172
|
+
*/
|
|
173
|
+
readGroupPrompt(ns, fresh = false) {
|
|
174
|
+
const settings = this.loadSettings(fresh);
|
|
175
|
+
if (!settings)
|
|
176
|
+
return undefined;
|
|
177
|
+
const nsBlock = settings[ns];
|
|
178
|
+
const gp = nsBlock?.groupPrompt;
|
|
179
|
+
return typeof gp === 'string' && gp.trim() ? gp.trim() : undefined;
|
|
180
|
+
}
|
|
181
|
+
loadSettings(fresh = false) {
|
|
182
|
+
if (!fresh && this.settingsCache !== undefined)
|
|
183
|
+
return this.settingsCache;
|
|
184
|
+
try {
|
|
185
|
+
this.settingsCache = readSettingsMerged();
|
|
186
|
+
return this.settingsCache;
|
|
187
|
+
}
|
|
188
|
+
catch {
|
|
189
|
+
this.settingsCache = null;
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
103
194
|
//# sourceMappingURL=settings-reader.js.map
|