dsh-fish-soul 0.19.6 → 0.19.8
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/README.md +1 -1
- package/lib/behavior.js +23 -7
- package/lib/channels/douyin-pure.js +1 -1
- package/lib/channels/douyin.js +11 -3
- package/lib/db.js +1 -1
- package/lib/douyin-social.js +22 -2
- package/lib/gateway-session.js +70 -9
- package/lib/gateway.js +5 -3
- package/lib/index-tools.js +148 -47
- package/lib/index.js +218 -213
- package/lib/memory-label.js +1 -1
- package/lib/persona-templates.js +156 -166
- package/lib/routes.js +177 -3
- package/lib/slang.js +20 -4
- package/lib/social.js +24 -4
- package/lib/websearch.js +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
package/lib/behavior.js
CHANGED
|
@@ -598,6 +598,7 @@ export class DiaryWriter {
|
|
|
598
598
|
this.log = log ?? (() => {});
|
|
599
599
|
this.timer = null;
|
|
600
600
|
this.running = false;
|
|
601
|
+
this.shownTopics = new Set();
|
|
601
602
|
}
|
|
602
603
|
|
|
603
604
|
start(everyMs = 5 * 60_000) {
|
|
@@ -723,6 +724,7 @@ export class DiaryWriter {
|
|
|
723
724
|
const dropped = parsedTopics.length - topics.length;
|
|
724
725
|
if (dropped > 0) this.log('info', `[fish-soul] 日记有 ${dropped} 条想聊的对象认不出是谁,没存`);
|
|
725
726
|
setKv(this.db, 'diary.topics', { date, at: now, items: topics });
|
|
727
|
+
this.shownTopics.clear();
|
|
726
728
|
setKv(this.db, 'diary.last', date);
|
|
727
729
|
this.note?.('diary', { title: '日记', reason: '写了今天的日记', text: diary });
|
|
728
730
|
if (cfg.qzone && typeof this.qzone === 'function') {
|
|
@@ -737,10 +739,24 @@ export class DiaryWriter {
|
|
|
737
739
|
}
|
|
738
740
|
|
|
739
741
|
/** 昨晚(36 小时内)日记里想跟这个人聊的。 */
|
|
740
|
-
topicsFor(ownerId, now = this.clock.now()) {
|
|
742
|
+
topicsFor(ownerId, now = this.clock.now(), { skipShown = false } = {}) {
|
|
741
743
|
const t = getKv(this.db, 'diary.topics', null);
|
|
742
744
|
if (!t || !Array.isArray(t.items) || now - Number(t.at ?? 0) > 36 * 3600_000) return [];
|
|
743
|
-
|
|
745
|
+
const dateKey = String(t.date ?? t.at ?? '');
|
|
746
|
+
return t.items
|
|
747
|
+
.filter((x) => x.ownerId === ownerId)
|
|
748
|
+
.filter((x) => !skipShown || !this.shownTopics.has(`${dateKey}:${ownerId}:${x.topic}`))
|
|
749
|
+
.map((x) => x.topic);
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
/** 标记这个人今日想聊的日记话题已在对话开场带过,避免同一话题每轮重复占位。 */
|
|
753
|
+
markTopicsShown(ownerId, now = this.clock.now()) {
|
|
754
|
+
const t = getKv(this.db, 'diary.topics', null);
|
|
755
|
+
if (!t || !Array.isArray(t.items) || now - Number(t.at ?? 0) > 36 * 3600_000) return;
|
|
756
|
+
const dateKey = String(t.date ?? t.at ?? '');
|
|
757
|
+
for (const x of t.items) {
|
|
758
|
+
if (x.ownerId === ownerId) this.shownTopics.add(`${dateKey}:${ownerId}:${x.topic}`);
|
|
759
|
+
}
|
|
744
760
|
}
|
|
745
761
|
|
|
746
762
|
entries(n = 7) {
|
|
@@ -780,7 +796,7 @@ export function moodStyle(moods, p) {
|
|
|
780
796
|
return k && moods[k] ? `你${k === '犯懒' ? '懒洋洋' : k}的时候一般:${moods[k]}` : '';
|
|
781
797
|
}
|
|
782
798
|
|
|
783
|
-
export function behaviorLines({ db, getConfig, session, known, tone, now, diary, moods }) {
|
|
799
|
+
export function behaviorLines({ db, getConfig, session, known, tone, now, diary, moods, includeStatic = true, diaryTopics = null }) {
|
|
784
800
|
const out = [];
|
|
785
801
|
const cfg = behaviorConfig(getConfig().behavior);
|
|
786
802
|
const inGroup = session.channel === 'qq-group';
|
|
@@ -794,13 +810,13 @@ export function behaviorLines({ db, getConfig, session, known, tone, now, diary,
|
|
|
794
810
|
const own = moodStyle(moods, p);
|
|
795
811
|
if (p.hint) out.push(`[你现在的状态] ${p.hint}——体现在回复的快慢、长短和语气上,别直接说出来。${own ? `${own}。` : ''}${MOOD_STATE_GUARD}`);
|
|
796
812
|
}
|
|
797
|
-
// 去 AI
|
|
798
|
-
if (cfg.outFilter.enabled && session.channel !== 'dsh') {
|
|
813
|
+
// 去 AI 味:发出去以后再删只能删漏网的,先在提示里压一压(纯静态规则,外层可拆到 section 避免每轮通胀)
|
|
814
|
+
if (includeStatic && cfg.outFilter.enabled && session.channel !== 'dsh') {
|
|
799
815
|
out.push('[说话方式] 像平时打字聊天:简短、口语,可以省略主语、可以倒装,一次说一两件事;不滥用比喻、不讲大道理、不客套;' +
|
|
800
816
|
'别用括号或星号写动作神态(比如“(揉了揉眼睛)”),别用破折号、冒号、列点。');
|
|
801
817
|
}
|
|
802
|
-
if (!inGroup && known.length === 1 && diary) {
|
|
803
|
-
const topics = diary.topicsFor(known[0].ownerId, now);
|
|
818
|
+
if (!inGroup && known.length === 1 && (Array.isArray(diaryTopics) || diary)) {
|
|
819
|
+
const topics = Array.isArray(diaryTopics) ? diaryTopics : diary.topicsFor(known[0].ownerId, now);
|
|
804
820
|
if (topics.length > 0) out.push(`[昨晚日记里想跟 ${known[0].displayName} 聊的] ${topics.join(';')}(合适就自然地提,不合适就算了)`);
|
|
805
821
|
}
|
|
806
822
|
return out;
|
|
@@ -166,7 +166,7 @@ export function isGroupConversation(msgs, { name = '', groups = [] } = {}) {
|
|
|
166
166
|
if (m.fromMe !== true) {
|
|
167
167
|
// 🔴 只认 ID,**不认昵称**:DOM 路补的媒体消息没有 senderId、只有 senderName,
|
|
168
168
|
// 拿昵称当「一个人」会把「同一个人 + 他的昵称」数成两个 peer → 单聊被误判成群
|
|
169
|
-
//
|
|
169
|
+
// (真机见过:会话「某人」的游标被写成 group: true,从此走群聊路径读,永远读不到)。
|
|
170
170
|
const who = String(m.senderId || m.secUid || '');
|
|
171
171
|
if (who !== '') peers.add(who);
|
|
172
172
|
}
|
package/lib/channels/douyin.js
CHANGED
|
@@ -684,7 +684,8 @@ export class DouyinChannel {
|
|
|
684
684
|
let rows = [];
|
|
685
685
|
try { rows = this.db.prepare("SELECT key, value FROM kv WHERE key LIKE 'douyin.fails.douyin.conv.%'").all(); } catch { return 0; }
|
|
686
686
|
for (const row of rows) {
|
|
687
|
-
|
|
687
|
+
const failCount = Number(row.value);
|
|
688
|
+
if (!(failCount > 0)) continue;
|
|
688
689
|
const key = row.key.slice('douyin.fails.'.length);
|
|
689
690
|
let hasCursor = false;
|
|
690
691
|
let retryAt = 0;
|
|
@@ -693,6 +694,13 @@ export class DouyinChannel {
|
|
|
693
694
|
retryAt = Number(getKv(this.db, `douyin.retry.${key}`, 0) ?? 0) || 0;
|
|
694
695
|
} catch { hasCursor = true; }
|
|
695
696
|
const touched = Math.max(retryAt, this.lastReadAt(key));
|
|
697
|
+
// 🔴 「永远读不出来的死会话」不该算作「活着的失败」:
|
|
698
|
+
// 重试机制在 fails >= FAIL_HARD_AFTER 后就自己停了(needsVerify 的
|
|
699
|
+
// `fails < FAIL_HARD_AFTER` 上限),面板上还显示「N 个会话上次读取失败,
|
|
700
|
+
// 等待重试」是骗人 —— 它根本不会再重试了。
|
|
701
|
+
// 判据:失败次数已顶到上限 **且仍无游标**(从没读成功过)。
|
|
702
|
+
// kv 保留不删:排查「这个会话为什么没消息」时还查得到。
|
|
703
|
+
if (!hasCursor && failCount >= FAIL_HARD_AFTER) continue;
|
|
696
704
|
if (!hasCursor && touched > 0 && now - touched > ORPHAN_FAIL_TTL_MS) {
|
|
697
705
|
try {
|
|
698
706
|
this.db.prepare('DELETE FROM kv WHERE key IN (?, ?, ?)')
|
|
@@ -1127,7 +1135,7 @@ export class DouyinChannel {
|
|
|
1127
1135
|
const groups = this.groupNames();
|
|
1128
1136
|
// 当前会话 ID 是单聊形状(0:1:)时,旧游标里的 group 标记不算数。
|
|
1129
1137
|
// 那个标记是之前某轮误判写进去的,沿用下去会让单聊永远走群聊路径
|
|
1130
|
-
// (2026-11-11
|
|
1138
|
+
// (2026-11-11 真机:某人的 convId 是 0:1:...,游标却是 group:true,
|
|
1131
1139
|
// 私信被当成群消息入库)。
|
|
1132
1140
|
const singleNow = isSingleConversation(convId);
|
|
1133
1141
|
const group = singleNow ? false : (st?.group === true || isGroupConversation(msgs, { name, groups }));
|
|
@@ -1368,7 +1376,7 @@ export class DouyinChannel {
|
|
|
1368
1376
|
* 进别的会话,还把会话列表滚到那儿(抖音的会话列表是虚拟滚动的,
|
|
1369
1377
|
* 眼下只有几个会话在 DOM 里)。下一段再进目标会话就点不到了 ——
|
|
1370
1378
|
* enterChat 抛「找不到会话「X」」,整条回复被判「回复没发出去(发送失败)」
|
|
1371
|
-
* (真机 2026-11-12
|
|
1379
|
+
* (真机 2026-11-12:两个会话的发送窗口撞在一起)。
|
|
1372
1380
|
*
|
|
1373
1381
|
* 锁是 FIFO 的:轮询排在整条发送**之后**,发送中途就插不进来了。
|
|
1374
1382
|
* ⚠️ 这里不能再套一层 exclusive(自己抢自己的锁会死锁)。
|
package/lib/db.js
CHANGED
|
@@ -522,7 +522,7 @@ export function isMergedNameList(db, raw, excludeId = '') {
|
|
|
522
522
|
/**
|
|
523
523
|
* 清掉「把几个名字拼一起」的脏身份行。
|
|
524
524
|
*
|
|
525
|
-
* 历史上有过
|
|
525
|
+
* 历史上有过 `某某, 某人, 云` 这种值 —— 旧代码把一段对话里的**几个人**
|
|
526
526
|
* 拼成了一个身份,于是「和 A、B、C 寒暄」被记成了**一个人**的互动:好几个人的
|
|
527
527
|
* 往来记在一个人头上,就是「人物关系乱」本身。
|
|
528
528
|
*
|
package/lib/douyin-social.js
CHANGED
|
@@ -800,8 +800,28 @@ export function douyinSocialDriver(host, timing = {}) {
|
|
|
800
800
|
await br.send('Input.insertText', { text }, br.sessionId, tm.evalTimeoutMs);
|
|
801
801
|
await sleep(1000);
|
|
802
802
|
// 等图片传完("上传中"没了)
|
|
803
|
-
|
|
804
|
-
|
|
803
|
+
//
|
|
804
|
+
// 🔴 「读不回来」≠「读到空」(2026-11-27):原来写 `.catch(() => '')`,
|
|
805
|
+
// eval 超时/断连都返回空串 ⇒ `!/上传中/.test('')` 恒真 ⇒ 没读完页面就报上传成功。
|
|
806
|
+
// 页面被验证码 iframe 卡住时正好走这条路。现在把 eval 失败单独拿出来当「不知道」,
|
|
807
|
+
// 继续等;等到预算耗尽仍读不回来 ⇒ UPLOAD_UNKNOWN(不谎报成功)。
|
|
808
|
+
let readFailed = false;
|
|
809
|
+
const uploaded = await waitFor(async () => {
|
|
810
|
+
let body;
|
|
811
|
+
try {
|
|
812
|
+
body = await br.eval('document.body.innerText', { timeoutMs: tm.evalTimeoutMs });
|
|
813
|
+
} catch {
|
|
814
|
+
readFailed = true; // 读不回来:不知道传完没,继续等
|
|
815
|
+
return null;
|
|
816
|
+
}
|
|
817
|
+
readFailed = false;
|
|
818
|
+
return !/上传中|正在上传/.test(String(body ?? '')) ? true : null;
|
|
819
|
+
}, { tries: 30, budgetMs: tm.waitBudgetMs });
|
|
820
|
+
if (!uploaded) {
|
|
821
|
+
return readFailed
|
|
822
|
+
? { ok: false, code: 'UPLOAD_UNKNOWN', error: '页面读不回来(可能卡住或断连),没法确认图片传完没有' }
|
|
823
|
+
: { ok: false, code: 'UPLOAD_TIMEOUT', error: '图片一直在上传中,没等到上传完成' };
|
|
824
|
+
}
|
|
805
825
|
return { ok: true };
|
|
806
826
|
},
|
|
807
827
|
|
package/lib/gateway-session.js
CHANGED
|
@@ -133,6 +133,20 @@ export const sessionMethods = {
|
|
|
133
133
|
}
|
|
134
134
|
},
|
|
135
135
|
|
|
136
|
+
/** 按文件名排序的稳定表情包清单(用于放进上下文提示词,避免 >40 张每轮随机重排破坏前缀缓存)。 */
|
|
137
|
+
stableStickers(workspacePath, limit = 24) {
|
|
138
|
+
try {
|
|
139
|
+
const dir = join(workspacePath, '_stickers');
|
|
140
|
+
if (!existsSync(dir)) return [];
|
|
141
|
+
return readdirSync(dir)
|
|
142
|
+
.filter((f) => IMAGE_EXT.has(extname(f).toLowerCase()))
|
|
143
|
+
.sort()
|
|
144
|
+
.slice(0, limit);
|
|
145
|
+
} catch {
|
|
146
|
+
return [];
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
|
|
136
150
|
/** 当前嵌入模型 id(换模型后老的向量就不算数了,得重打)。 */
|
|
137
151
|
embeddingModel() {
|
|
138
152
|
try {
|
|
@@ -146,8 +160,9 @@ export const sessionMethods = {
|
|
|
146
160
|
* 没标签的照旧只给文件名 —— 老记录 / 主人手放的图都走这条降级路,不报错。
|
|
147
161
|
* @returns {Array<{file: string, tags: string[]}>}
|
|
148
162
|
*/
|
|
149
|
-
stickerManifest(workspacePath) {
|
|
150
|
-
const
|
|
163
|
+
stickerManifest(workspacePath, { deterministic = false, limit = 40 } = {}) {
|
|
164
|
+
const raw = deterministic ? this.stableStickers(workspacePath, limit) : this.listStickers(workspacePath);
|
|
165
|
+
const files = new Set(raw);
|
|
151
166
|
if (files.size === 0) return [];
|
|
152
167
|
const tagged = new Map();
|
|
153
168
|
try {
|
|
@@ -162,9 +177,10 @@ export const sessionMethods = {
|
|
|
162
177
|
* 发图清单(给模型看的):_stickers/ 里的表情包 + (images.sendAny 打开时)工作区里任意图片。
|
|
163
178
|
* 都是相对工作区根的路径,模型照着写  就能发出去。
|
|
164
179
|
*/
|
|
165
|
-
listImages(workspacePath) {
|
|
180
|
+
listImages(workspacePath, { deterministic = false, stickerLimit = 24 } = {}) {
|
|
166
181
|
const ws = String(workspacePath ?? '').trim();
|
|
167
|
-
const
|
|
182
|
+
const stickerFiles = deterministic ? this.stableStickers(ws, stickerLimit) : this.listStickers(ws);
|
|
183
|
+
const stickers = stickerFiles.map((f) => ({ rel: `_stickers/${f}`, mtimeMs: fileMtime(join(ws, '_stickers', f)) }));
|
|
168
184
|
const sendAny = this.getConfig?.()?.images?.sendAny === true;
|
|
169
185
|
if (!sendAny || ws === '') return stickers.map((x) => x.rel);
|
|
170
186
|
let extra = [];
|
|
@@ -228,9 +244,11 @@ export const sessionMethods = {
|
|
|
228
244
|
const provider = String(cfg.tools?.web?.provider ?? 'host') || 'host';
|
|
229
245
|
webTools = provider === 'host' ? [...WEB_TOOLS] : [OWN_WEB_TOOL];
|
|
230
246
|
}
|
|
231
|
-
const
|
|
247
|
+
const allowOpenMotion = isMaster && (cfg === null || (cfg.douyin?.enabled === true && cfg.douyin?.video?.enabled === true && (!cfg.douyin?.video?.provider || cfg.douyin.video.provider === 'openmotion')));
|
|
248
|
+
const omTools = allowOpenMotion
|
|
232
249
|
? [...new Set([...listNames(tools), ...listNames(agentCtx?.tools)].filter(isOpenMotionTool))]
|
|
233
250
|
: [];
|
|
251
|
+
const allowSoundRead = this.voiceGuardReady && cfg?.voice?.enabled === true && cfg?.voice?.saveIncoming === true && (channelId === undefined || platformOf(channelId) === 'qq');
|
|
234
252
|
const candidates = [
|
|
235
253
|
...QQ_SESSION_TOOLS,
|
|
236
254
|
...(allowMasterTools ? [RELAY_TOOL, ...SCHEDULED_TASK_TOOLS] : []),
|
|
@@ -238,7 +256,7 @@ export const sessionMethods = {
|
|
|
238
256
|
...(allowDouyinNote ? [DOUYIN_NOTE_TOOL] : []),
|
|
239
257
|
...(allowRelayFriend ? [RELAY_FRIEND_TOOL] : []),
|
|
240
258
|
...webTools,
|
|
241
|
-
...(
|
|
259
|
+
...(allowSoundRead ? ['sound_read'] : [])
|
|
242
260
|
];
|
|
243
261
|
const base = candidates.filter((n) =>
|
|
244
262
|
WEB_TOOLS.includes(n) || typeof tools?.get !== 'function' || has(tools, n) || has(agentCtx?.tools, n));
|
|
@@ -261,7 +279,7 @@ export const sessionMethods = {
|
|
|
261
279
|
} catch { /* 读不到就少给几个,不影响授权 */ }
|
|
262
280
|
}
|
|
263
281
|
const mine = new Set([...CHAT_TOOLS, ...WEB_TOOLS, OWN_WEB_TOOL, 'sound_read', 'run_code']);
|
|
264
|
-
return [...new Set(names.filter((n) => typeof n === 'string' && n !== '' && !mine.has(n) && !isOpenMotionTool(n)))];
|
|
282
|
+
return [...new Set(names.filter((n) => typeof n === 'string' && n !== '' && !mine.has(n) && !isOpenMotionTool(n) && !n.startsWith('mcp__')))];
|
|
265
283
|
},
|
|
266
284
|
|
|
267
285
|
/** 传话配置:熟人托她给另一个人带句话(默认关,白名单按平台 uid 精确匹配)。 */
|
|
@@ -302,7 +320,7 @@ export const sessionMethods = {
|
|
|
302
320
|
async setupAgent(agentCtx, channelId) {
|
|
303
321
|
// 人格卡 + 此刻状态只挂在这个 agent 的 scope 上,不注册全局段 —— 宿主自己的会话根本看不到(#41 架构方案)
|
|
304
322
|
try {
|
|
305
|
-
this.agentSections?.(agentCtx);
|
|
323
|
+
this.agentSections?.(agentCtx, channelId);
|
|
306
324
|
} catch (error) {
|
|
307
325
|
// 注不上不拦着建会话:宁可她少一张人格卡,也别整个聊天哑掉(人格卡是真身份,但比「不回」轻)
|
|
308
326
|
this.log('error', `[fish-soul] 人格注入挂不上:${String(error instanceof Error ? error.message : error)}`);
|
|
@@ -323,9 +341,11 @@ export const sessionMethods = {
|
|
|
323
341
|
const allow = this.allowedTools(agentCtx, channelId);
|
|
324
342
|
// #169 抖音:档位放开的只是「可见性」,真正放不放由 guard 每轮按身份当场判(见 lib/index.js)。
|
|
325
343
|
// 这里不判身份 —— 身份证据会变,restrict 是一次性的,判错就收不回来。guard 没装就不放宽。
|
|
326
|
-
|
|
344
|
+
const douyinVisible = platformOf(channelId) === 'douyin' && this.douyinHostVisible();
|
|
345
|
+
if (douyinVisible) {
|
|
327
346
|
for (const name of this.hostToolNames(agentCtx)) if (!allow.includes(name)) allow.push(name);
|
|
328
347
|
}
|
|
348
|
+
let finalAllow = allow;
|
|
329
349
|
if (typeof agentCtx?.tools?.restrict === 'function') {
|
|
330
350
|
try {
|
|
331
351
|
agentCtx.tools.restrict({ allow });
|
|
@@ -334,9 +354,48 @@ export const sessionMethods = {
|
|
|
334
354
|
if (trimmed.length === allow.length) throw error;
|
|
335
355
|
// 宿主要是不认没注册的工具名:去掉联网工具再收窄一次(收不窄就让建会话失败,宁可不回也不放开 shell)
|
|
336
356
|
this.log('warn', `[fish-soul] 收窄工具失败,去掉联网工具重试:${String(error instanceof Error ? error.message : error)}`);
|
|
357
|
+
finalAllow = trimmed;
|
|
337
358
|
agentCtx.tools.restrict({ allow: trimmed });
|
|
338
359
|
}
|
|
339
360
|
}
|
|
361
|
+
// 受限聊天会话(QQ / B站 / 抖音 memory 模式):过滤宿主全局注入的编码工具说明、MCP 提示段、AGENTS.md、time-context 和 skill-catalog
|
|
362
|
+
if (!douyinVisible && typeof agentCtx?.on === 'function') {
|
|
363
|
+
const allowSet = new Set(finalAllow);
|
|
364
|
+
const stripSections = new Set([
|
|
365
|
+
'harness:source', 'app:web-surface', 'plan:policy', 'team:policy',
|
|
366
|
+
'ui:deliverable-file-references', 'context:file-reference',
|
|
367
|
+
'mcp-resource-servers', 'deployment:persona-prefix', 'deployment:persona-suffix', 'tools:sdk'
|
|
368
|
+
]);
|
|
369
|
+
const stripPreStep = new Set(['agent-instructions', 'time-context', 'skill-catalog']);
|
|
370
|
+
try {
|
|
371
|
+
agentCtx.on('system-prompt/assemble', async (assembly, _context, next) => {
|
|
372
|
+
const result = await next();
|
|
373
|
+
if (!result || !Array.isArray(result.sections)) return result;
|
|
374
|
+
return {
|
|
375
|
+
...result,
|
|
376
|
+
sections: result.sections.filter((s) => {
|
|
377
|
+
const name = String(s?.name ?? '');
|
|
378
|
+
if (name === '' || name.startsWith('fish-soul')) return true;
|
|
379
|
+
if (name.startsWith('mcp:') || stripSections.has(name)) return false;
|
|
380
|
+
if (name.startsWith('tool:')) return allowSet.has(name.slice(5));
|
|
381
|
+
return true;
|
|
382
|
+
})
|
|
383
|
+
};
|
|
384
|
+
}, { prepend: true });
|
|
385
|
+
} catch (error) {
|
|
386
|
+
this.log('warn', `[fish-soul] system-prompt/assemble 过滤挂不上:${String(error instanceof Error ? error.message : error)}`);
|
|
387
|
+
}
|
|
388
|
+
try {
|
|
389
|
+
agentCtx.on('agent/pre-step', async (_payload, next) => {
|
|
390
|
+
const decision = await next();
|
|
391
|
+
if (!decision || decision.kind === 'reject' || !Array.isArray(decision.messages)) return decision;
|
|
392
|
+
const filtered = decision.messages.filter((m) => !stripPreStep.has(m?.source?.kind));
|
|
393
|
+
return filtered.length === decision.messages.length ? decision : { ...decision, messages: filtered };
|
|
394
|
+
}, { prepend: true });
|
|
395
|
+
} catch (error) {
|
|
396
|
+
this.log('warn', `[fish-soul] agent/pre-step 过滤挂不上:${String(error instanceof Error ? error.message : error)}`);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
340
399
|
},
|
|
341
400
|
|
|
342
401
|
/**
|
|
@@ -555,6 +614,7 @@ export const sessionMethods = {
|
|
|
555
614
|
...(agentOptions !== undefined ? { agentOptions } : {}),
|
|
556
615
|
setup: (agentCtx) => this.setupAgent(agentCtx, key)
|
|
557
616
|
});
|
|
617
|
+
this.onSectionsMounted?.(handle.agent?.id ?? row.session_id, key);
|
|
558
618
|
this.log('info', `[fish-soul] 已恢复会话 ${row.title || key}`);
|
|
559
619
|
this.diag?.add('session-resume', { sessionId: row.session_id, channelId: key });
|
|
560
620
|
const preflight = await this.shouldRotateBeforeModelSwitch(handle.agent, key);
|
|
@@ -635,6 +695,7 @@ export const sessionMethods = {
|
|
|
635
695
|
...(agentOptions !== undefined ? { agentOptions } : {}),
|
|
636
696
|
setup: (agentCtx) => this.setupAgent(agentCtx, chat.channelId)
|
|
637
697
|
});
|
|
698
|
+
this.onSectionsMounted?.(handle.agent?.id ?? sessionId, chat.channelId);
|
|
638
699
|
// 换新会话(resetSession)沿用旧标题:chatTitle 依赖人物库的当前状态,
|
|
639
700
|
// 对方改了昵称 / person 行被合并过,重算出来的题头就变了 —— 用户眼里是
|
|
640
701
|
// 「我只是换了个新会话,题头怎么变了」(2026-11-23 用户反馈)。
|
package/lib/gateway.js
CHANGED
|
@@ -103,14 +103,15 @@ export class ChatGateway extends gatewayMixins() {
|
|
|
103
103
|
* @param {any} [deps.voice]
|
|
104
104
|
* @param {any} [deps.stickers]
|
|
105
105
|
* @param {any} [deps.slang]
|
|
106
|
-
* @param {((agentCtx: object) => void)|null} [deps.agentSections] 给单个 agent 挂人格卡 / 瞬态块(index.js 传入 registerAgentSections)
|
|
106
|
+
* @param {((agentCtx: object, channelId?: string) => void)|null} [deps.agentSections] 给单个 agent 挂人格卡 / 瞬态块(index.js 传入 registerAgentSections)
|
|
107
|
+
* @param {((sessionId: string) => void)|null} [deps.onSectionsMounted] setupAgent 成功挂完段后通知外层标记已挂载
|
|
107
108
|
* @param {any} [deps.groupAdmin]
|
|
108
109
|
* @param {any} [deps.embedder]
|
|
109
110
|
* @param {any} [deps.embeddingCfg]
|
|
110
111
|
* @param {any} [deps.diag]
|
|
111
112
|
* @param {any} [deps.vision]
|
|
112
113
|
*/
|
|
113
|
-
constructor({ ctx, db, clock, getConfig, log, channel, bili = null, browser = null, douyin = null, douyinBrowser = null, canvasConvert = null, soul, voice = null, stickers = null, slang = null, agentSections = null, groupAdmin = null, embedder = null, embeddingCfg = null, diag = null, vision = null }) {
|
|
114
|
+
constructor({ ctx, db, clock, getConfig, log, channel, bili = null, browser = null, douyin = null, douyinBrowser = null, canvasConvert = null, soul, voice = null, stickers = null, slang = null, agentSections = null, onSectionsMounted = null, groupAdmin = null, embedder = null, embeddingCfg = null, diag = null, vision = null }) {
|
|
114
115
|
super();
|
|
115
116
|
this.ctx = ctx;
|
|
116
117
|
this.db = db;
|
|
@@ -153,8 +154,9 @@ export class ChatGateway extends gatewayMixins() {
|
|
|
153
154
|
this.vision = vision;
|
|
154
155
|
/** 群管理(入群申请):主人回"/鱼 同意/拒绝"时用它(可能没有) */
|
|
155
156
|
this.groupAdmin = groupAdmin;
|
|
156
|
-
/** 给单个 agent 挂人格卡 / 瞬态块:`(agentCtx) => void`(在 setup 里调,只对那个 agent 生效) */
|
|
157
|
+
/** 给单个 agent 挂人格卡 / 瞬态块:`(agentCtx, channelId) => void`(在 setup 里调,只对那个 agent 生效) */
|
|
157
158
|
this.agentSections = agentSections;
|
|
159
|
+
this.onSectionsMounted = onSectionsMounted;
|
|
158
160
|
this.diag = diag;
|
|
159
161
|
/**
|
|
160
162
|
* 抖音适配器(PR2):身份解析 / 配置归一 / 认人 / 会话标题。
|