fix(wechat): 微信深度思考改默认关——deep_think 列默认 0,旧库 DEFAULT 1 重建表把存量一键关回,读端缺行兜底同改

This commit is contained in:
2026-10-06 07:10:16 +08:00
parent 46867f8274
commit ccb0f803b3
3 changed files with 34 additions and 9 deletions
+29 -4
View File
@@ -145,8 +145,8 @@ function initDb(dbPath) {
bot_account_id TEXT, -- bot 上线后的微信账号标识(登录回调带回,展示用)
wx_to_user TEXT, -- 最近来话人 userId(deliver 回发对象;实际上只会是主人自己)
last_msg_id INTEGER NOT NULL DEFAULT 0, -- 投递游标:id ≤ 此值的 assistant 消息已送过微信
deep_think INTEGER NOT NULL DEFAULT 1, -- 微信端全局深度思考开关(/think;= H5 按钮的微信形态,
-- 随绑定不随会话;投递时替进消息 API 的 deepThink 字段)
deep_think INTEGER NOT NULL DEFAULT 0, -- 微信端全局深度思考开关(/think;= H5 按钮的微信形态,
-- 随绑定不随会话;投递时替进消息 API 的 deepThink 字段;默认关)
created_at INTEGER NOT NULL,
updated_at INTEGER NOT NULL
);
@@ -231,9 +231,34 @@ function initDb(dbPath) {
// 不得静默冲掉用户给会话起的名字;清空会话时随标题一并复位(旧名字已文不对题)。
if (!cols.some(c => c.name === 'title_locked')) db.exec("ALTER TABLE sessions ADD COLUMN title_locked INTEGER NOT NULL DEFAULT 0");
// 迁移:wechat_bindings 补 deep_think 列——微信端全局深度思考开关(routes/channel.js /think 读写,
// 投递时作为既有 deepThink 参数的取值来源);缺行/旧库默认 1=开(微信没按钮,默认按开走)。
// 投递时作为既有 deepThink 参数的取值来源);默认 0=关(与 H5 按钮初始态一致,/think on 手动开)。
// 旧库若曾按 DEFAULT 1 补过列(当时默认开,存量行都是默认值回填而非用户显式选择),
// SQLite 改不了列默认,重建表把默认关回 0 并一键关存量;重建后 dflt_value 不再为 1,天然幂等。
const bindCols = db.prepare('PRAGMA table_info(wechat_bindings)').all();
if (!bindCols.some(c => c.name === 'deep_think')) db.exec('ALTER TABLE wechat_bindings ADD COLUMN deep_think INTEGER NOT NULL DEFAULT 1');
if (!bindCols.some(c => c.name === 'deep_think')) {
db.exec('ALTER TABLE wechat_bindings ADD COLUMN deep_think INTEGER NOT NULL DEFAULT 0');
} else if (bindCols.some(c => c.name === 'deep_think' && String(c.dflt_value) === '1')) {
db.transaction(() => {
db.exec(`
CREATE TABLE wechat_bindings__v2 (
id TEXT PRIMARY KEY,
user TEXT NOT NULL,
status TEXT NOT NULL DEFAULT 'pending',
note TEXT,
bot_account_id TEXT,
wx_to_user TEXT,
last_msg_id INTEGER NOT NULL DEFAULT 0,
deep_think INTEGER NOT NULL DEFAULT 0,
created_at INTEGER NOT NULL,
updated_at INTEGER NOT NULL
);
INSERT INTO wechat_bindings__v2 (id, user, status, note, bot_account_id, wx_to_user, last_msg_id, deep_think, created_at, updated_at)
SELECT id, user, status, note, bot_account_id, wx_to_user, last_msg_id, 0, created_at, updated_at FROM wechat_bindings;
DROP TABLE wechat_bindings;
ALTER TABLE wechat_bindings__v2 RENAME TO wechat_bindings;
`);
})();
}
// 迁移:phase 语义重定义为 advising(顾问:澄清需求/规划)/ executing(执行)。
// 存量会话(旧值 planning/NULL)统一回填 executing——它们都有历史,行为与改造前一致、零打扰;
// 只有新建会话进 advising(createSession 显式写入)。幂等,每次启动一条廉价 UPDATE。
+3 -3
View File
@@ -213,7 +213,7 @@ function statusReply(db, s, channel) {
// 思考开关只对微信通道有意义(web 端用按钮,不读这列)
if (String(channel || '').startsWith('wx:')) {
const bt = db.prepare('SELECT deep_think FROM wechat_bindings WHERE id = ?').get(String(channel).slice(3));
if (bt) lines.push('- 深度思考:' + (bt.deep_think !== 0 ? '开' : '关'));
if (bt) lines.push('- 深度思考:' + (bt.deep_think ? '开' : '关'));
}
const t = db.prepare('SELECT cron_expr, next_run_at, last_run_at, last_status FROM scheduled_tasks WHERE session_id = ?').get(s.id);
lines.push(t
@@ -240,7 +240,7 @@ function handleSend(db, opts) {
// 只是没得点、改用 /think 拨);非 wx 通道照旧不传 opts,行为零变化。
if (!parsed || parsed.normal) {
const wx = String(channel).startsWith('wx:');
const deepThink = wx ? ((db.prepare('SELECT deep_think FROM wechat_bindings WHERE id = ?').get(channel.slice(3)) || {}).deep_think !== 0) : undefined;
const deepThink = wx ? !!((db.prepare('SELECT deep_think FROM wechat_bindings WHERE id = ?').get(channel.slice(3)) || {}).deep_think) : undefined;
let s = boundSession(db, user, channel);
let sent;
if (!s) {
@@ -337,7 +337,7 @@ function handleSend(db, opts) {
return { kind: 'command', reply: '未绑定微信,此开关不适用', session_id: s ? s.id : null };
}
if (v === null) {
return { kind: 'command', reply: '微信深度思考当前:' + (b.deep_think !== 0 ? '开' : '关') + '(/think on|off 切换)', session_id: s ? s.id : null };
return { kind: 'command', reply: '微信深度思考当前:' + (b.deep_think ? '开' : '关') + '(/think on|off 切换)', session_id: s ? s.id : null };
}
if (v !== b.deep_think) db.prepare('UPDATE wechat_bindings SET deep_think = ? WHERE id = ?').run(v, b.id);
log.info('task', tag + ' channel /think → ' + (v ? 'on' : 'off') + '(用户全局,binding ' + b.id + ')');