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
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* paths.js — 全项目「根目录 / 外部依赖位置」的唯一来源(路径中心化)
|
|
3
|
+
*
|
|
4
|
+
* 为什么要有这个文件(2026-12-04):
|
|
5
|
+
* 在这之前,"包根"和"真仓库根"至少被推导了三遍 ——
|
|
6
|
+
* dist/config.js、dist/features/local-models.js、dist/gateway/bootstrap.js
|
|
7
|
+
* 各写一套,改一处漏两处;出图脚本、模型目录、产物目录就分别指着不同的根。
|
|
8
|
+
* 这里把它们收成一个叶子模块(只依赖 node 内置),谁需要就 import,别再自己算。
|
|
9
|
+
*
|
|
10
|
+
* 语义(三种安装形态都要成立):
|
|
11
|
+
* ① 源码直跑:PKG_ROOT = REPO_ROOT = 仓库根
|
|
12
|
+
* ② pnpm 装进 DSH profile:PKG_ROOT = node_modules/<pkg>,REPO_ROOT 由 config/repo-root.json 指回真仓库
|
|
13
|
+
* ③ 纯 npm 发布包:没有真仓库,REPO_ROOT 回落到 PKG_ROOT(包内自带 scripts/**)
|
|
14
|
+
*/
|
|
15
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
16
|
+
import { dirname, join, resolve } from 'node:path';
|
|
17
|
+
import { fileURLToPath } from 'node:url';
|
|
18
|
+
import { homedir } from 'node:os';
|
|
19
|
+
|
|
20
|
+
/** 包根。dist/shared → 上两级。 */
|
|
21
|
+
export const PKG_ROOT = (() => {
|
|
22
|
+
try {
|
|
23
|
+
return resolve(dirname(fileURLToPath(import.meta.url)), '..', '..');
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return process.cwd();
|
|
27
|
+
}
|
|
28
|
+
})();
|
|
29
|
+
|
|
30
|
+
/** 真仓库根:安装副本里 scripts/、.models/、.venv-draw/ 只在真仓库。 */
|
|
31
|
+
export const REPO_ROOT = (() => {
|
|
32
|
+
try {
|
|
33
|
+
const j = JSON.parse(readFileSync(join(PKG_ROOT, 'config', 'repo-root.json'), 'utf8'));
|
|
34
|
+
if (j && j.root && existsSync(String(j.root)))
|
|
35
|
+
return String(j.root);
|
|
36
|
+
}
|
|
37
|
+
catch { /* 没有指针就是源码直跑 / 纯发布包 */ }
|
|
38
|
+
// 环境变量兜底:容器/CI 里可以用 QQBOT_REPO_ROOT 指到挂载目录
|
|
39
|
+
const env = String(process.env.QQBOT_REPO_ROOT || '').trim();
|
|
40
|
+
if (env) {
|
|
41
|
+
try {
|
|
42
|
+
if (existsSync(env))
|
|
43
|
+
return env;
|
|
44
|
+
}
|
|
45
|
+
catch { /* ignore */ }
|
|
46
|
+
}
|
|
47
|
+
return PKG_ROOT;
|
|
48
|
+
})();
|
|
49
|
+
|
|
50
|
+
/** scripts/ 所在根:真仓库优先,其次包内(files 已包含 scripts/**)。 */
|
|
51
|
+
export const SCRIPTS_ROOT = (() => {
|
|
52
|
+
const cands = [String(process.env.QQBOT_REPO_ROOT || '').trim(), String(process.env.QQBOT_ROOT || '').trim(), REPO_ROOT, PKG_ROOT].filter(Boolean);
|
|
53
|
+
for (const c of cands) {
|
|
54
|
+
try {
|
|
55
|
+
if (existsSync(join(c, 'scripts')))
|
|
56
|
+
return c;
|
|
57
|
+
}
|
|
58
|
+
catch { /* ignore */ }
|
|
59
|
+
}
|
|
60
|
+
return REPO_ROOT;
|
|
61
|
+
})();
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* DSH 宿主的候选家目录(按新→旧)。
|
|
65
|
+
* 2026-12-04:DSH 0.14 把设置从 ~/.dsh 搬到 %APPDATA%/dsh-desktop/harness;
|
|
66
|
+
* 非 Windows 没有 %APPDATA%,之前会直接掉回 ~/.dsh 导致读不到设置。
|
|
67
|
+
* Go 版/自定义 harness 只要设 QQBOT_DSH_HOME 或 DSH_HOME 即可,不用改代码。
|
|
68
|
+
*/
|
|
69
|
+
export function dshHomeCandidates() {
|
|
70
|
+
const out = [];
|
|
71
|
+
const push = (p) => {
|
|
72
|
+
const v = String(p || '').trim();
|
|
73
|
+
if (v && !out.includes(v))
|
|
74
|
+
out.push(v);
|
|
75
|
+
};
|
|
76
|
+
push(process.env.QQBOT_DSH_HOME);
|
|
77
|
+
const appData = String(process.env.APPDATA || '').trim();
|
|
78
|
+
if (appData)
|
|
79
|
+
push(join(appData, 'dsh-desktop', 'harness'));
|
|
80
|
+
push(process.env.DSH_HOME);
|
|
81
|
+
const xdg = String(process.env.XDG_CONFIG_HOME || '').trim();
|
|
82
|
+
if (xdg)
|
|
83
|
+
push(join(xdg, 'dsh-desktop', 'harness'));
|
|
84
|
+
try { push(join(homedir(), '.config', 'dsh-desktop', 'harness')); } catch { /* ignore */ }
|
|
85
|
+
try { push(join(homedir(), '.dsh')); } catch { /* ignore */ }
|
|
86
|
+
return out;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** 第一个真实存在的 DSH 家目录(都不存在就交回仓库根,至少路径可拼) */
|
|
90
|
+
export function dshHome() {
|
|
91
|
+
for (const c of dshHomeCandidates()) {
|
|
92
|
+
try {
|
|
93
|
+
if (existsSync(c))
|
|
94
|
+
return c;
|
|
95
|
+
}
|
|
96
|
+
catch { /* ignore */ }
|
|
97
|
+
}
|
|
98
|
+
return PKG_ROOT;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** 统一产出根:任何形式产出的图/视频/音频/文本只落这里,不再各占一块。 */
|
|
102
|
+
export const OUT_ROOT = join(PKG_ROOT, 'out');
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Python 解释器候选(按顺序试,第一个存在的胜出)。
|
|
106
|
+
* 表里保留作者机器的 conda 路径只是"存在才用",别的用户机器上自动落到 python3 / python。
|
|
107
|
+
* 想指定自己的解释器:设环境变量 QQBOT_PYTHON。
|
|
108
|
+
*/
|
|
109
|
+
export function pythonCandidates(extra = []) {
|
|
110
|
+
const env = String(process.env.QQBOT_PYTHON || '').trim();
|
|
111
|
+
const list = [env, ...extra, 'E:/Anaconda/envs/ai25/python.exe', 'python3', 'python'].filter(Boolean);
|
|
112
|
+
return [...new Set(list)];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** 挑第一个存在的解释器(找不到就交回 python,让 spawn 报 ENOENT 而不是静默走错) */
|
|
116
|
+
export function pickPython(extra = []) {
|
|
117
|
+
for (const p of pythonCandidates(extra)) {
|
|
118
|
+
if (p === 'python' || p === 'python3')
|
|
119
|
+
continue;
|
|
120
|
+
try {
|
|
121
|
+
if (existsSync(p))
|
|
122
|
+
return p;
|
|
123
|
+
}
|
|
124
|
+
catch { /* ignore */ }
|
|
125
|
+
}
|
|
126
|
+
// Windows 上通常只有 python,Unix 上通常只有 python3
|
|
127
|
+
return process.platform === 'win32' ? 'python' : 'python3';
|
|
128
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* settings-io.js — 找到 dsh 的 qqbot 设置文件(2026-12-01)
|
|
3
|
+
*
|
|
4
|
+
* 背景:DSH Desktop 0.14 把 profile 从 `web` 换成 `desktop`,设置数据也从
|
|
5
|
+
* `~/.dsh/qqbot-settings/<profile>/<ns>.json`
|
|
6
|
+
* 搬到了
|
|
7
|
+
* `%APPDATA%/dsh-desktop/harness/qqbot-settings/<profile>/<ns>.json`
|
|
8
|
+
*
|
|
9
|
+
* 插件里还有几处写死 `~/.dsh/.../web` 的读法(autoRecall 热读、autoRecall 工具),
|
|
10
|
+
* 升级后全部读到"文件不存在"。这里统一解析:环境变量 > AppData harness > ~/.dsh。
|
|
11
|
+
*/
|
|
12
|
+
import { existsSync, readdirSync, statSync } from 'node:fs';
|
|
13
|
+
import { join } from 'node:path';
|
|
14
|
+
import { dshHome, dshHomeCandidates } from './paths.js';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* dsh home(能直接拼 `qqbot-settings/…` 的那一层)。
|
|
18
|
+
* DSH Desktop 0.14 的真实位置是 `%APPDATA%/dsh-desktop/harness`,而环境变量 DSH_HOME
|
|
19
|
+
* 只在 shell/工具调用时临时注入,插件进程里通常是空 —— 以前这里回落 ~/.dsh 就永远读不到设置。
|
|
20
|
+
*/
|
|
21
|
+
export function settingsHome() {
|
|
22
|
+
// 候选顺序统一由 shared/paths.js 给(含 QQBOT_DSH_HOME / APPDATA / DSH_HOME / XDG / ~/.dsh),
|
|
23
|
+
// 这里只多做一步:优先挑"真的有 qqbot-settings 子目录"的那一层。
|
|
24
|
+
for (const h of dshHomeCandidates()) {
|
|
25
|
+
try {
|
|
26
|
+
if (existsSync(join(h, 'qqbot-settings')))
|
|
27
|
+
return h;
|
|
28
|
+
}
|
|
29
|
+
catch { /* ignore */ }
|
|
30
|
+
}
|
|
31
|
+
return dshHome();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** 可能的 settings 根目录(按新→旧) */
|
|
35
|
+
export function settingsRoots() {
|
|
36
|
+
const out = dshHomeCandidates().map((h) => join(h, 'qqbot-settings'));
|
|
37
|
+
return out.filter((p) => { try { return existsSync(p); } catch { return false; } });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** 该目录下最新修改的 im-qqbot-*.json(同一 profile 里可能有多个命名空间) */
|
|
41
|
+
function newestNsFile(dir) {
|
|
42
|
+
try {
|
|
43
|
+
const cands = readdirSync(dir).filter((f) => /^im-qqbot-.*\.json$/.test(f));
|
|
44
|
+
if (!cands.length) return '';
|
|
45
|
+
cands.sort((a, b) => statSync(join(dir, b)).mtimeMs - statSync(join(dir, a)).mtimeMs);
|
|
46
|
+
return join(dir, String(cands[0]));
|
|
47
|
+
} catch { return ''; }
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 找设置文件:`ns` 精确命中优先;找不到再退到该 profile 下最新的 im-qqbot-*.json。
|
|
52
|
+
* @param {string} ns 例如 'im-qqbot' / 'im-qqbot-2'
|
|
53
|
+
* @returns {string} 绝对路径;找不到返回 ''
|
|
54
|
+
*/
|
|
55
|
+
export function findSettingsFile(ns) {
|
|
56
|
+
const name = String(ns || 'im-qqbot').replace(/\.json$/i, '');
|
|
57
|
+
const profEnv = String(process.env.DSH_PROFILE || '').trim();
|
|
58
|
+
for (const root of settingsRoots()) {
|
|
59
|
+
let profiles = [];
|
|
60
|
+
try { profiles = readdirSync(root).filter((p) => { try { return statSync(join(root, p)).isDirectory(); } catch { return false; } }); }
|
|
61
|
+
catch { continue; }
|
|
62
|
+
// 显式 DSH_PROFILE 优先,其余按“布局新→旧”:desktop 先于 web
|
|
63
|
+
profiles.sort((a, b) => {
|
|
64
|
+
const rank = (x) => (x === profEnv ? 0 : x === 'desktop' ? 1 : x === 'web' ? 2 : 3);
|
|
65
|
+
return rank(a) - rank(b);
|
|
66
|
+
});
|
|
67
|
+
for (const p of profiles) {
|
|
68
|
+
const dir = join(root, p);
|
|
69
|
+
const exact = join(dir, name + '.json');
|
|
70
|
+
if (existsSync(exact)) return exact;
|
|
71
|
+
}
|
|
72
|
+
// 没精确命中:取任意 profile 下最新的(老配置命名不稳定时兜底)
|
|
73
|
+
for (const p of profiles) {
|
|
74
|
+
const f = newestNsFile(join(root, p));
|
|
75
|
+
if (f) return f;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return '';
|
|
79
|
+
}
|
|
@@ -10,6 +10,7 @@ import { replaceBotMention, mentionsOthers } from '../shared/mention-clean.js';
|
|
|
10
10
|
import { resolveMentionNames } from '../features/chat-ledger.js';
|
|
11
11
|
import { MK, QUOTE_BEGIN_ALL, QUOTE_END_ALL, findFirstMarker, findLastMarker, escapeBlockMarkers, stripBlockMarkers } from './markers.js';
|
|
12
12
|
import { dataRootOf, stickerDirOf } from '../gateway/data-root.js';
|
|
13
|
+
import { takePendingIntro } from '../features/session-rotate.js';
|
|
13
14
|
import { registerMsgIndex } from './msg-index.js';
|
|
14
15
|
import { createValueScorer, appendScoreLog, OTHER_MENTION_PENALTY } from '../features/value-score.js';
|
|
15
16
|
import { getStickerStore, computeDHash } from '../features/sticker-store.js';
|
|
@@ -305,6 +306,24 @@ export async function handleInbound(rawMsg, manager, config, logger, state) {
|
|
|
305
306
|
// ⚠️ 2026-09-13 修(主人问"你看到了吗"): 图片预检提示是在**下面的评分段**才追加到 agentBody 的,
|
|
306
307
|
// 而这里 message 早就创建好了(用旧文本) → 提示改了变量却没进上下文。故 message 改为 let,
|
|
307
308
|
// 评分段若追加过提示会重建一次(见后面 `message = createUserMessage(...)`)。
|
|
309
|
+
// ── 提交 B:会话轮换后的「上一段要点」前置(默认关,sessionRotate=true 才会有内容)──
|
|
310
|
+
// 轮换是在 getOrCreate 里发生的,这里拿到的 record 已经是新档 → 首条消息带上前缀,
|
|
311
|
+
// 让新会话开局就知道上一段聊了什么、有哪些相关记忆。取走即清,绝不会重复注入。
|
|
312
|
+
if (config.sessionRotate === true) {
|
|
313
|
+
try {
|
|
314
|
+
const _intro = takePendingIntro({
|
|
315
|
+
dataRoot: dataRootOf(config),
|
|
316
|
+
sessionKey: manager.sessionKey(scope, peerId),
|
|
317
|
+
});
|
|
318
|
+
if (_intro) {
|
|
319
|
+
agentBody = _intro + '\n\n' + agentBody;
|
|
320
|
+
traceContextless('[rotate] 已给新会话首条消息加前缀: ' + _intro.length + ' 字');
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
catch (err) {
|
|
324
|
+
logger.debug(`[rotate] intro 注入失败(忽略): ${err instanceof Error ? err.message : String(err)}`);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
308
327
|
let content = [{ type: 'text', text: agentBody }];
|
|
309
328
|
let message = createUserMessage({
|
|
310
329
|
content,
|
|
@@ -367,7 +386,7 @@ export async function handleInbound(rawMsg, manager, config, logger, state) {
|
|
|
367
386
|
// 它**不伪造 @**:`mentioned` 仍如实为 false ⇒ 上下文里不会多出假的 (@you),
|
|
368
387
|
// 聚合加权/点名豁免这些读 mentioned 的地方照旧不受影响。
|
|
369
388
|
// 没有扩展调用 forceWake 时该值恒为 undefined ⇒ 下面三处判定与改动前**逐字一致**(零回归)。
|
|
370
|
-
const forced = mwState.qqInboundForceWake === true;
|
|
389
|
+
const forced = mwState.qqInboundForceWake === true || msg.forceWake === true;
|
|
371
390
|
// 这条消息 @ 的是**别人**(不是她)吗?—— 2026-09-15 主人修正的扣分依据(判据见 mentionsOthers 的注释)
|
|
372
391
|
const mentionedOthers = mentionsOthers(msg.mentions, mentioned);
|
|
373
392
|
try {
|
|
@@ -7,6 +7,8 @@ import { getLastSender } from '../features/attitude.js';
|
|
|
7
7
|
import { formatToolResult } from './tool-presenter.js';
|
|
8
8
|
import { disableStreamingWithExt } from '../features/runtime-tuning.js';
|
|
9
9
|
import { hasOutboundExtensions } from '../features/firstrun.js';
|
|
10
|
+
// 2026-11-25 任务 C:出站「去鱼味」后处理(削八股腔/客服腔/AI 腔,保护代码块与媒体标记)
|
|
11
|
+
import { softenOutbound } from '../features/style-layer.js';
|
|
10
12
|
/**
|
|
11
13
|
* `reply_gate` 的参数里是不是"判定静默"?
|
|
12
14
|
*
|
|
@@ -431,6 +433,12 @@ class OutboundRouter {
|
|
|
431
433
|
// 分句/卡片/转发/净化全会失效(而且流式失败回落时容易把同一段发两遍)。
|
|
432
434
|
if (disableStreamingWithExt() && hasOutboundExtensions(dataRootOf(this.config)))
|
|
433
435
|
return false;
|
|
436
|
+
// 2026-11-25 任务 C:开了「去鱼味」后处理就别流式 —— 流式是边生成边发,
|
|
437
|
+
// 后处理只能看到碎片,削腔会漏;而正文能完整过一遍 send() 才削得干净。
|
|
438
|
+
// 真想要流式的老用户可配 styleKeepStreaming: true 覆盖(代价是流式正文不削腔)。
|
|
439
|
+
if (this.config.styleLayerOn !== false && this.config.stylePostProcessOn !== false
|
|
440
|
+
&& this.config.styleKeepStreaming !== true)
|
|
441
|
+
return false;
|
|
434
442
|
return this.config.streaming
|
|
435
443
|
&& record.replyTarget.scope === 'c2c'
|
|
436
444
|
&& !!record.replyTarget.msgId;
|
|
@@ -569,14 +577,44 @@ class OutboundRouter {
|
|
|
569
577
|
// ① 本回合报"上下文超长/token 超限" → 立刻换新档(旧档保留),下一轮从干净上下文开始;
|
|
570
578
|
// ② 回合数超过阈值(默认 60,可用 QQBOT_SESSION_MAX_TURNS 调)→ 同样换新档,避免无限堆积。
|
|
571
579
|
// 人设与记忆不在会话档里(每轮由 persona / recall 重新注入),换档不丢性格和长期记忆。
|
|
572
|
-
|
|
580
|
+
// ── 2026-11-25 统一计数(任务 3)──────────────────────────────────────────
|
|
581
|
+
// `record.turns`(内存计数)**停用**:重启归零、换档不带摘要,是两套账打架的根源。
|
|
582
|
+
// 现在轮数只认 `.qqbot/session-turns/<key>.json`(session-rotate 的 bumpTurns 是唯一写入点)。
|
|
583
|
+
// 向后兼容:老进程内存里若已有 record.turns 而文件还是 0,把它搬进文件一次(迁移),随后清零。
|
|
584
|
+
const _turnsRoot = (() => {
|
|
585
|
+
try {
|
|
586
|
+
return dataRootOf(this.config);
|
|
587
|
+
}
|
|
588
|
+
catch {
|
|
589
|
+
return undefined;
|
|
590
|
+
}
|
|
591
|
+
})();
|
|
592
|
+
let _turnsNow = 0;
|
|
593
|
+
try {
|
|
594
|
+
const _st0 = loadTurns(_turnsRoot, record.sessionKey);
|
|
595
|
+
if ((Number(record.turns) || 0) > 0 && (Number(_st0.turns) || 0) === 0) {
|
|
596
|
+
_st0.turns = Number(record.turns) || 0;
|
|
597
|
+
saveTurns(_turnsRoot, record.sessionKey, _st0);
|
|
598
|
+
this.logger.info?.(`im-qqbot: 轮数迁移(旧内存值→session-turns) key=${record.sessionKey} turns=${_st0.turns}`);
|
|
599
|
+
}
|
|
600
|
+
const _bumped = bumpTurns({ dataRoot: _turnsRoot, sessionKey: record.sessionKey, sid: sessionId });
|
|
601
|
+
_turnsNow = _bumped.turns;
|
|
602
|
+
}
|
|
603
|
+
catch (turnErr) {
|
|
604
|
+
this.logger.debug?.(`im-qqbot: 轮数记账失败(忽略): ${turnErr instanceof Error ? turnErr.message : String(turnErr)}`);
|
|
605
|
+
}
|
|
606
|
+
record.turns = 0; // 旧通道停用:只留迁移用途,永不再自增(读轮数请用 loadTurns)
|
|
573
607
|
const _errText = failure === undefined ? '' : (String(failure.code ?? '') + ' ' + String(failure.message ?? '')).toLowerCase();
|
|
574
608
|
const _overflow = _errText !== '' && /context|too long|maximum|token limit|413|超长|超出/.test(_errText);
|
|
575
609
|
const _maxTurns = Number(process.env.QQBOT_SESSION_MAX_TURNS || 60) || 60;
|
|
576
|
-
|
|
610
|
+
// 2026-11-25 提交 B:新的「带摘要会话轮换」(sessionRotate) 开着时,按轮数的兜底让位
|
|
611
|
+
// (换档由 getOrCreate 的 maybeRotate 做,带摘要 + 空闲判断,避免同一回合连换两次档;
|
|
612
|
+
// overflow 兜底仍然保留)。关着时这里用**文件里的**轮数兜底。
|
|
613
|
+
const _turnLimit = this.config.sessionRotate !== true
|
|
614
|
+
&& this.config.sessionRotateByTurns !== false && _turnsNow >= _maxTurns;
|
|
577
615
|
if ((_overflow || _turnLimit) && typeof this.manager?.forceRotate === 'function') {
|
|
578
616
|
const _why = _overflow ? 'context-overflow' : 'turn-limit';
|
|
579
|
-
this.logger.warn?.(`im-qqbot: 换新档 key=${record.sessionKey} turns=${
|
|
617
|
+
this.logger.warn?.(`im-qqbot: 换新档 key=${record.sessionKey} turns=${_turnsNow} reason=${_why}`);
|
|
580
618
|
void Promise.resolve(this.manager.forceRotate(record.scope, record.peerId ?? record.targetId, _why)).catch((e) => this.logger.warn?.(`im-qqbot: 换档失败: ${e instanceof Error ? e.message : String(e)}`));
|
|
581
619
|
}
|
|
582
620
|
// 闸门静默导致的"取消"不是故障 —— 这个回合本来就不该出声(2026-09-14 主人要求)
|
|
@@ -599,7 +637,21 @@ class OutboundRouter {
|
|
|
599
637
|
mdTarget = { apiCall: ga.apiCall.bind(ga) };
|
|
600
638
|
}
|
|
601
639
|
catch { /* ignore */ }
|
|
602
|
-
|
|
640
|
+
// 2026-11-25 任务 C:「去鱼味」出站后处理(只削腔调;没命中词表时原样返回)
|
|
641
|
+
let body = text;
|
|
642
|
+
if (this.config.styleLayerOn !== false && this.config.stylePostProcessOn !== false) {
|
|
643
|
+
try {
|
|
644
|
+
body = softenOutbound(text, {
|
|
645
|
+
dataRoot: dataRootOf(this.config),
|
|
646
|
+
config: this.config,
|
|
647
|
+
logger: this.logger,
|
|
648
|
+
}).text;
|
|
649
|
+
}
|
|
650
|
+
catch (err) {
|
|
651
|
+
this.logger.debug?.('im-qqbot: style 后处理失败(用原文): ' + (err instanceof Error ? err.message : String(err)));
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
const outText = await rewriteLocalMarkdownImages(body, mdTarget);
|
|
603
655
|
// 2026-10-21: 改写后含 qqbot-media 图片引用 → 必须走 markdown 通道(msg_type=2),普通文本不渲染图片
|
|
604
656
|
if (outText.indexOf('qqbot-media://') >= 0) {
|
|
605
657
|
try {
|
|
@@ -30,6 +30,26 @@ npm run release # 一条龙:体检 → 提交 → 推 main → tag/Release
|
|
|
30
30
|
|
|
31
31
|
## 1. 一键闸门做了什么
|
|
32
32
|
|
|
33
|
+
> 2026-11-29 起所有「流程」收在 `scripts/flows.mjs`(`npm run flow -- list` 看全量):
|
|
34
|
+
>
|
|
35
|
+
> ```bash
|
|
36
|
+
> node scripts/flows.mjs doctor # 兼容性自检:注册表非空 / 仓库根有 .models / 模块 id 唯一 / 三份代码语法 / 安装副本注册表 / 产出目录 / 存储分区表
|
|
37
|
+
> node scripts/flows.mjs version patch # 版本号 + CHANGELOG 一起改(漏一处就是"版本没变但代码变了")
|
|
38
|
+
> node scripts/flows.mjs sync # = sync-plugin-copies(含 config/*.json 注册表 + 仓库根指针)
|
|
39
|
+
> node scripts/flows.mjs security # 安全 / 隐私审计(发布流程第 1 步,release-all 也会自动跑)
|
|
40
|
+
> node scripts/flows.mjs storage stats # 过程性文件占用(截图/OCR/转码/TTS 临时文件)
|
|
41
|
+
> node scripts/flows.mjs clean --dry-run # 按 TTL 清理过期过程文件(先演练,去掉 --dry-run 才真删)
|
|
42
|
+
> node scripts/flows.mjs pet --count 2 # 桌宠皮肤候选:img2img 保角色 → 纯色背景抠成透明
|
|
43
|
+
> ```
|
|
44
|
+
>
|
|
45
|
+
> **安全/隐私已进流程**:`scripts/security-check.mjs` 检查①源码明文凭证 ②git 是否跟踪凭证文件
|
|
46
|
+
> ③.gitignore 覆盖 ④命令注入面(shell 拼接) ⑤面板路由是否绕过同源闸门 ⑥临时目录是否登记在
|
|
47
|
+
> `config/storage.json`;报告写 `out/reports/security-<日期>.json`,`release-all` 第 1 步会跑,
|
|
48
|
+
> 任何 hard 失败直接拦住发版。
|
|
49
|
+
>
|
|
50
|
+
> **为什么要有 doctor**:模型面板"一个模型都没有"的真实原因是副本里的 `config/models.registry.json` 被一次空扫描写成 `models: []`,
|
|
51
|
+
> 而 `sync-plugin-copies` 当时没同步这一份。doctor 会把这两件事都点名,避免下次再靠猜。
|
|
52
|
+
|
|
33
53
|
`scripts/release-check.mjs`(`--strict` 为发布模式)会检查四类东西:
|
|
34
54
|
|
|
35
55
|
| 类别 | 检查内容 | 不通过会怎样 |
|
|
@@ -44,9 +64,11 @@ npm run release # 一条龙:体检 → 提交 → 推 main → tag/Release
|
|
|
44
64
|
## 2. 发布流程
|
|
45
65
|
|
|
46
66
|
```bash
|
|
47
|
-
# 0)
|
|
67
|
+
# 0) 改完代码;版本号与 CHANGELOG 用同一条命令改(2026-11-29 起)
|
|
68
|
+
node scripts/flows.mjs version patch # 自动 +1 并在 CHANGELOG 顶部插入本节模板
|
|
69
|
+
node scripts/flows.mjs doctor # 兼容性自检,全绿再往下
|
|
48
70
|
node scripts/release-check.mjs --strict # 或者 npm run release:check:strict
|
|
49
|
-
node scripts/sync-plugin-copies
|
|
71
|
+
node scripts/flows.mjs sync # = sync-plugin-copies(含 config/modules.json、models.registry.json)
|
|
50
72
|
|
|
51
73
|
# 1) 打包(可选,闸门里已经 dry-run 过一遍)
|
|
52
74
|
npm pack
|
|
@@ -459,8 +459,48 @@ function mount(ctx) {
|
|
|
459
459
|
registered = true;
|
|
460
460
|
|
|
461
461
|
const pagePath = PAGE_PATH;
|
|
462
|
+
// 模块闸(2026-11-28):面试官模式在 config/modules.json 里声明为「默认关」,
|
|
463
|
+
// 开关状态落在 {dataRoot}/.qqbot/modules.state.json(设置页 ⑬ 写的就是它)。
|
|
464
|
+
// 这里每次请求现读一次(几十字节,代价可忽略),关着就直接回 disabled,
|
|
465
|
+
// 不给"UI 藏了但 URL 还能进"的漏网机会。
|
|
466
|
+
const moduleStateCands = () => [
|
|
467
|
+
join(DATA_ROOT, '.qqbot', 'modules.state.json'),
|
|
468
|
+
join(FILE_ROOT, '.qqbot', 'modules.state.json'),
|
|
469
|
+
join(dirname(DATA_ROOT), '.qqbot', 'modules.state.json'),
|
|
470
|
+
];
|
|
471
|
+
function interviewEnabled() {
|
|
472
|
+
for (const p of moduleStateCands()) {
|
|
473
|
+
try {
|
|
474
|
+
if (!existsSync(p)) continue;
|
|
475
|
+
const j = JSON.parse(readFileSync(p, 'utf8'));
|
|
476
|
+
return !!(j && j.interview === true);
|
|
477
|
+
} catch { /* 换下一个候选 */ }
|
|
478
|
+
}
|
|
479
|
+
return false; // 没有任何状态文件 = 按注册表默认(关)
|
|
480
|
+
}
|
|
462
481
|
const reg = (path, handler) => {
|
|
463
|
-
try {
|
|
482
|
+
try {
|
|
483
|
+
ws.register({
|
|
484
|
+
kind: 'exact', path,
|
|
485
|
+
handler: (req, res) => {
|
|
486
|
+
if (!interviewEnabled()) {
|
|
487
|
+
if (String(path) === BASE) {
|
|
488
|
+
res.writeHead(200, { 'content-type': 'text/html; charset=utf-8', 'cache-control': 'no-store' });
|
|
489
|
+
res.end('<!doctype html><meta charset="utf-8"><title>面试官模式已关闭</title>'
|
|
490
|
+
+ '<body style="font:14px/1.7 -apple-system,\'Segoe UI\',sans-serif;padding:40px;color:#333">'
|
|
491
|
+
+ '<h2 style="margin:0 0 8px">🎓 面试官模式已关闭</h2>'
|
|
492
|
+
+ '<p>到设置页 → <b>⑬ 模块中心 → 工具 → 面试官模式</b> 打开即可;打开后刷新本页。</p>'
|
|
493
|
+
+ '<p style="color:#888;font-size:12px">本页不会读取任何面试记录;关闭状态下录音/转写/评分接口一律拒绝。</p></body>');
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
res.writeHead(503, { 'content-type': 'application/json; charset=utf-8' });
|
|
497
|
+
res.end(JSON.stringify({ ok: false, disabled: true, message: '面试官模式已关闭(设置页 ⑬ 模块中心可开)' }));
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
return handler(req, res);
|
|
501
|
+
},
|
|
502
|
+
});
|
|
503
|
+
}
|
|
464
504
|
catch (e) { logWarn('[interview] 注册路由失败', path, String((e && e.message) || e)); }
|
|
465
505
|
};
|
|
466
506
|
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 00-vision.mjs — 图片先"看"再答:本地视觉模型把图转成一句话,喂给后面的链路
|
|
3
|
+
*
|
|
4
|
+
* 为什么要有它(2026-12-02 主人反馈):
|
|
5
|
+
* 插件收到纯图片时,正文是空的,`local-answer` 只会记一条 `empty:media` 就交给云端;
|
|
6
|
+
* 而云端默认模型(deepseek-flash)**没有视觉**,于是"发了图它却答不上来/瞎猜"。
|
|
7
|
+
* 现在在最前面挂一跳:本地 qwen3-vl:8b 先看图,把描述以 `[看见]…[/看见]` 拼进 ctx.text,
|
|
8
|
+
* 后面的记忆召回、本地代答、云端上下文就都能"看见"这张图了。
|
|
9
|
+
*
|
|
10
|
+
* 只读、离线:图片只发到 127.0.0.1:11434,不写库、不落长期缓存(临时文件用完即删)。
|
|
11
|
+
* 配置:local-llm-config.json 里 `visionBridge: false` 可整关;`visionModel` 换模型。
|
|
12
|
+
*/
|
|
13
|
+
import { mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
14
|
+
import { join } from 'node:path';
|
|
15
|
+
import { createHash } from 'node:crypto';
|
|
16
|
+
import { dataRootOf, loadConfig } from '../lib/local-llm.mjs';
|
|
17
|
+
|
|
18
|
+
export const name = 'vision-bridge';
|
|
19
|
+
|
|
20
|
+
const OLLAMA = 'http://127.0.0.1:11434';
|
|
21
|
+
const DEFAULT_MODEL = 'qwen3-vl:8b';
|
|
22
|
+
const PROMPT = '用中文一句话说清这张图里有什么(人物/场景/文字要点),不超过 60 字,不要客套。';
|
|
23
|
+
|
|
24
|
+
function attachmentsOf(ctx) {
|
|
25
|
+
return Array.isArray(ctx?.message?.attachments) ? ctx.message.attachments : [];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function imageAtts(ctx) {
|
|
29
|
+
return attachmentsOf(ctx).filter((a) => /image/i.test(String(a?.contentType || a?.type || '')));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function tmpDir(root) {
|
|
33
|
+
const d = join(String(root || '.'), '.qqbot', 'vision-tmp');
|
|
34
|
+
try { mkdirSync(d, { recursive: true }); } catch { /* ignore */ }
|
|
35
|
+
return d;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** 取图片的 base64:优先本地路径,其次下载;失败返回空串 */
|
|
39
|
+
async function imageToB64(att, root) {
|
|
40
|
+
const p = att?.localPath || att?.path || att?.filePath;
|
|
41
|
+
if (p) {
|
|
42
|
+
try { return Buffer.from(readFileSync(p)).toString('base64'); } catch { /* 继续走下载 */ }
|
|
43
|
+
}
|
|
44
|
+
const url = att?.url || att?.fileUrl || att?.src;
|
|
45
|
+
if (!url || !/^https?:/i.test(String(url))) return '';
|
|
46
|
+
try {
|
|
47
|
+
const r = await fetch(url, { signal: AbortSignal.timeout(15000) });
|
|
48
|
+
if (!r.ok) return '';
|
|
49
|
+
const buf = Buffer.from(await r.arrayBuffer());
|
|
50
|
+
if (buf.length < 256) return '';
|
|
51
|
+
const f = join(tmpDir(root), createHash('sha1').update(buf).digest('hex').slice(0, 16) + '.img');
|
|
52
|
+
try { writeFileSync(f, buf); } catch { /* 落不了盘也能直接送 */ }
|
|
53
|
+
return buf.toString('base64');
|
|
54
|
+
} catch {
|
|
55
|
+
return '';
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function describe(b64, cfg) {
|
|
60
|
+
const model = String(cfg?.visionModel || DEFAULT_MODEL);
|
|
61
|
+
const body = {
|
|
62
|
+
model,
|
|
63
|
+
stream: false,
|
|
64
|
+
think: false,
|
|
65
|
+
messages: [{ role: 'user', content: PROMPT, images: [b64] }],
|
|
66
|
+
options: { temperature: 0.2, num_predict: 160 },
|
|
67
|
+
};
|
|
68
|
+
const r = await fetch(OLLAMA + '/api/chat', {
|
|
69
|
+
method: 'POST',
|
|
70
|
+
headers: { 'content-type': 'application/json' },
|
|
71
|
+
body: JSON.stringify(body),
|
|
72
|
+
signal: AbortSignal.timeout(Number(cfg?.visionTimeoutMs) || 45000),
|
|
73
|
+
});
|
|
74
|
+
if (!r.ok) return '';
|
|
75
|
+
const j = await r.json();
|
|
76
|
+
const text = String(j?.message?.content || j?.message?.thinking || '').trim();
|
|
77
|
+
return text.replace(/\s+/g, ' ').slice(0, 120);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export async function onInbound(ctx, next) {
|
|
81
|
+
try {
|
|
82
|
+
let cfg = loadConfig(dataRootOf({}));
|
|
83
|
+
cfg = loadConfig(dataRootOf(cfg));
|
|
84
|
+
if (cfg?.visionBridge === false) return next();
|
|
85
|
+
const imgs = imageAtts(ctx);
|
|
86
|
+
if (!imgs.length) return next();
|
|
87
|
+
const root = String(cfg?.dataRoot || dataRootOf(cfg));
|
|
88
|
+
const desc = [];
|
|
89
|
+
for (const a of imgs.slice(0, 2)) {
|
|
90
|
+
const b64 = await imageToB64(a, root);
|
|
91
|
+
if (!b64) continue;
|
|
92
|
+
const d = await describe(b64, cfg);
|
|
93
|
+
if (d) desc.push(d);
|
|
94
|
+
}
|
|
95
|
+
// 清掉临时文件(只留上下文里的描述)
|
|
96
|
+
try {
|
|
97
|
+
const d = tmpDir(root);
|
|
98
|
+
const fs = await import('node:fs');
|
|
99
|
+
for (const f of fs.readdirSync(d)) rmSync(join(d, f), { force: true });
|
|
100
|
+
} catch { /* ignore */ }
|
|
101
|
+
if (desc.length) {
|
|
102
|
+
const block = `[看见]${desc.join(';')}[/看见]`;
|
|
103
|
+
ctx.text = String(ctx.text || '') + '\n' + block;
|
|
104
|
+
try { (ctx.state || (ctx.state = {})).visionText = desc.join(';'); } catch { /* ignore */ }
|
|
105
|
+
ctx?.logger?.info?.('[vision] 已识图:' + desc.join(';'));
|
|
106
|
+
}
|
|
107
|
+
} catch (e) {
|
|
108
|
+
ctx?.logger?.debug?.('[vision] 跳过:' + (e instanceof Error ? e.message : String(e)));
|
|
109
|
+
}
|
|
110
|
+
return next();
|
|
111
|
+
}
|