@zaofan/dsh-qqbot 1.13.25 → 1.13.28
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/client/qqbot-settings.js +9 -0
- package/dist/config.d.ts +27 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +5 -0
- package/dist/config.js.map +1 -1
- package/dist/features/image-path-surface.d.ts +38 -0
- package/dist/features/image-path-surface.d.ts.map +1 -0
- package/dist/features/image-path-surface.js +225 -0
- package/dist/features/image-path-surface.js.map +1 -0
- package/dist/features/qun-login.d.ts +21 -0
- package/dist/features/qun-login.d.ts.map +1 -1
- package/dist/features/qun-login.js +202 -59
- package/dist/features/qun-login.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +32 -1
- package/dist/index.js.map +1 -1
- package/dist/middleware/sticker-capture.d.ts +9 -0
- package/dist/middleware/sticker-capture.d.ts.map +1 -1
- package/dist/middleware/sticker-capture.js +56 -19
- package/dist/middleware/sticker-capture.js.map +1 -1
- package/dist/session/session-manager.d.ts.map +1 -1
- package/dist/session/session-manager.js +185 -13
- package/dist/session/session-manager.js.map +1 -1
- package/dist/transport/inbound.d.ts.map +1 -1
- package/dist/transport/inbound.js +29 -0
- package/dist/transport/inbound.js.map +1 -1
- package/docs/extension-contract.md +191 -2
- package/examples/ext-commands//346/214/211/351/222/256/346/265/213/350/257/225.mjs +321 -0
- package/examples/ext-tools/send_md3.mjs +406 -0
- package/package.json +4 -3
|
@@ -25,6 +25,10 @@ import { isContextlessActive, contextlessSmartOf, contextlessMemoMaxOf, contextl
|
|
|
25
25
|
import { contextlessSegmentOf, contextlessSegmentKeepOf, contextlessSegmentScoreMinOf } from '../features/contextless-store.js';
|
|
26
26
|
import { getSegmentScore } from '../features/segment-score.js';
|
|
27
27
|
import { offloadHistoryImages } from '../features/image-offload.js';
|
|
28
|
+
// ★ 2026-11-26:把已进上下文的 QQ 图片链接换成本地路径(surfaceOp replace,只动尾部)
|
|
29
|
+
import { replaceImagePathsInSurface } from '../features/image-path-surface.js';
|
|
30
|
+
// ★ 2026-11-26:pre-step 兜底把 QQ 图片 URL 换成本地路径(后台下载完的在回合开始那一刻生效)
|
|
31
|
+
import { lookupImagePath } from '../features/image-path-cache.js';
|
|
28
32
|
import { trimHistoryForContextless } from '../features/contextless-trim.js';
|
|
29
33
|
import { memoForInject, setMemoMaxItems } from '../features/context-memo.js';
|
|
30
34
|
import { traceContextless } from '../features/contextless-store.js';
|
|
@@ -517,6 +521,11 @@ export class SessionManager {
|
|
|
517
521
|
record.handle = created;
|
|
518
522
|
record.agentPreset = composed.agentPreset;
|
|
519
523
|
record.lastActivity = Date.now();
|
|
524
|
+
// ★★ 2026-11-25:/bot-new 换 agent 也不经 claimed/pre-step ⇒ 补一次 scoped 注册。
|
|
525
|
+
try {
|
|
526
|
+
this.syncScopedToolsOnClaim(created.agent);
|
|
527
|
+
}
|
|
528
|
+
catch { /* ignore */ }
|
|
520
529
|
void oldHandle.dispose().catch(() => { });
|
|
521
530
|
void attachSessionToWorkspaceWithRetry(this.ctx, this.config.cwd, childId, this.logger, {
|
|
522
531
|
// 这个 childId 已经被下一次 fork/new 取代的话,别再挂、更别反归档(会撤销别人的自动归档)
|
|
@@ -941,6 +950,13 @@ export class SessionManager {
|
|
|
941
950
|
agent: record.agent,
|
|
942
951
|
});
|
|
943
952
|
}
|
|
953
|
+
// ★★ 2026-11-25(/bot-new 之后 context_* 三件套消失、重启才好):mountChannelTools 只挂内置工具,
|
|
954
|
+
// 不碰 context_compact/drop/memo —— 那三个原先只在 agent/inbox/claimed 注册,
|
|
955
|
+
// 而"建会话"不是消息 claim ⇒ 事件不触发 ⇒ 工具永远不挂到重启。这里同点位补一次。
|
|
956
|
+
try {
|
|
957
|
+
this.syncScopedToolsOnClaim(record.agent);
|
|
958
|
+
}
|
|
959
|
+
catch { /* 失败不影响建会话 */ }
|
|
944
960
|
}
|
|
945
961
|
catch { /* 注册失败不影响建会话 */ }
|
|
946
962
|
return record;
|
|
@@ -1217,23 +1233,41 @@ export class SessionManager {
|
|
|
1217
1233
|
*/
|
|
1218
1234
|
syncScopedToolsOnClaim(agent) {
|
|
1219
1235
|
const a = agent;
|
|
1220
|
-
if (!a)
|
|
1236
|
+
if (!a) {
|
|
1237
|
+
traceContextless('[ctxtool-claim] skip: agent 为空');
|
|
1221
1238
|
return;
|
|
1239
|
+
}
|
|
1222
1240
|
// 只碰本实例的 agent(cwd 分流:别的 bot 实例的会话工具集不归我们管)
|
|
1223
|
-
|
|
1241
|
+
const cwdC0 = String(a.session?.header?.cwd ?? '');
|
|
1242
|
+
if (!this.nsForCwd(cwdC0)) {
|
|
1243
|
+
traceContextless('[ctxtool-claim] skip: cwd 不属本实例 cwd=' + cwdC0);
|
|
1224
1244
|
return;
|
|
1245
|
+
}
|
|
1225
1246
|
const rec = this.findByAgent(agent);
|
|
1226
|
-
|
|
1227
|
-
|
|
1247
|
+
// ★ CodeRabbit 2026-11-25(Major):**当前 agent 的 ctx 优先**。
|
|
1248
|
+
// forkCurrentSession 换了 record.agent / record.handle,但**没换 record.agentCtx** ——
|
|
1249
|
+
// 原来这段优先读 rec.agentCtx ⇒ 工具全注册到**已被替换的旧上下文**上,新 agent 看不到。
|
|
1250
|
+
// 顺序与同文件里其它几处(a.ctx 优先)保持一致;没有 ctx 的 agent 仍回退 rec.agentCtx。
|
|
1251
|
+
const ctxOfTool = a.ctx ?? rec?.agentCtx;
|
|
1252
|
+
if (!ctxOfTool) {
|
|
1253
|
+
traceContextless('[ctxtool-claim] skip: 拿不到 agentCtx/agent.ctx rec=' + String(Boolean(rec)));
|
|
1228
1254
|
return;
|
|
1255
|
+
}
|
|
1229
1256
|
let sk = String(rec?.sessionKey ?? '').trim();
|
|
1230
1257
|
if (!sk) {
|
|
1231
1258
|
const sid = String(a.session?.id ?? '');
|
|
1232
1259
|
if (sid)
|
|
1233
1260
|
sk = String(this.findBySessionId(sid)?.sessionKey ?? '');
|
|
1261
|
+
// ★ CodeRabbit 2026-11-25(Major):宿主**恢复**出来的 QQ 会话(resumeHostAgent 走
|
|
1262
|
+
// agents.resume,不写 this.sessions)在 findByAgent / findBySessionId 眼里都不存在
|
|
1263
|
+
// ⇒ 这里曾直接跳过注册。持久化的 sessionId→sessionKey 映射(model-prefs)是唯一兜底。
|
|
1264
|
+
if (!sk && sid)
|
|
1265
|
+
sk = String(this.modelResolver.findKeyBySessionId(sid) ?? '');
|
|
1234
1266
|
}
|
|
1235
|
-
if (!sk)
|
|
1236
|
-
|
|
1267
|
+
if (!sk) {
|
|
1268
|
+
traceContextless('[ctxtool-claim] skip: 拿不到 sessionKey rec=' + String(Boolean(rec)) + ' sid=' + String(a.session?.id ?? ''));
|
|
1269
|
+
return;
|
|
1270
|
+
} // 未知 = 不动
|
|
1237
1271
|
const smart = isContextlessActive(sk, this.config.contextlessMode)
|
|
1238
1272
|
&& contextlessSmartOf(sk, this.config.contextlessSmart);
|
|
1239
1273
|
syncChannelScopedTools(ctxOfTool, {
|
|
@@ -1248,7 +1282,10 @@ export class SessionManager {
|
|
|
1248
1282
|
* 每个实例在 patch 里配自己的 cwd + settingsNs, 即自动分流;
|
|
1249
1283
|
* 其他实例/项目(web、别的 cwd)的 agent 一律不注入, 避免群守则污染非本 bot 会话。 */
|
|
1250
1284
|
nsForCwd(cwd) {
|
|
1251
|
-
|
|
1285
|
+
// ★ CodeRabbit 2026-11-25:会话 header.cwd 是 absCwdOf() 写进去的,配置侧也必须用同一规则
|
|
1286
|
+
// —— 否则配置为相对路径(如 storage/emulated/0/bot)时两侧永远不相等,本实例的会话被误判成别人的,
|
|
1287
|
+
// 工具静默不注册。配置为绝对路径时 absCwdOf 原样返回,行为不变。
|
|
1288
|
+
const selfCwd = String(absCwdOf(this.config.cwd) ?? '').trim().replace(/[\/]+$/, '');
|
|
1252
1289
|
const ns = String(this.config.settingsNs ?? '').trim() || 'im-qqbot';
|
|
1253
1290
|
if (!selfCwd)
|
|
1254
1291
|
return ns; // 未配 cwd → 对本实例所有 agent 注入(保守)
|
|
@@ -1324,6 +1361,11 @@ export class SessionManager {
|
|
|
1324
1361
|
if (!tagC)
|
|
1325
1362
|
return;
|
|
1326
1363
|
applyExtToolVisibility(ag.ctx, tagC);
|
|
1364
|
+
// ★★ 2026-11-25:任何途径诞生的会话都该工具就绪 —— 这里也补一次 context_* 注册(幂等)。
|
|
1365
|
+
try {
|
|
1366
|
+
this.syncScopedToolsOnClaim(ag);
|
|
1367
|
+
}
|
|
1368
|
+
catch { /* ignore */ }
|
|
1327
1369
|
}
|
|
1328
1370
|
catch { /* 注册失败不影响建 agent */ }
|
|
1329
1371
|
});
|
|
@@ -1503,6 +1545,20 @@ export class SessionManager {
|
|
|
1503
1545
|
break;
|
|
1504
1546
|
}
|
|
1505
1547
|
}
|
|
1548
|
+
// ★★ 2026-11-25(CodeRabbit Major):**宿主恢复出来的会话**(resumeHostAgent 走 agents.resume,
|
|
1549
|
+
// 不写 this.sessions)在前两条反查里都查不到 ⇒ sk0 为空 ⇒ 下面 ctxKey0 退化成 '__global__'
|
|
1550
|
+
// ⇒ segOn0/ctxSmartOn 全 false ⇒ 1733 行的**固定窗口裁剪抢跑**(把本回合尾巴裁掉、
|
|
1551
|
+
// 写入 lastTrimmedTurn)⇒ 等 1819 行才通过持久映射恢复 sessionKey 时,
|
|
1552
|
+
// 1852 行的 trimHistoryForContextless 撞"同回合防重复"返回 false ⇒ pending 永远不执行。
|
|
1553
|
+
// 所以必须**在这里**(所有裁剪分派之前)就用持久映射兜底 —— 否则补消费端也改不了执行顺序。
|
|
1554
|
+
if (!sk0) {
|
|
1555
|
+
try {
|
|
1556
|
+
sk0 = String(this.modelResolver.findKeyBySessionId(sid0) ?? '');
|
|
1557
|
+
}
|
|
1558
|
+
catch { /* ignore */ }
|
|
1559
|
+
if (sk0)
|
|
1560
|
+
traceContextless('[ctxsmart] sk0 持久映射兜底: ' + sk0);
|
|
1561
|
+
}
|
|
1506
1562
|
skForTool = sk0; // 存到外层,供"上下文工具挂/卸"那块兜底用
|
|
1507
1563
|
}
|
|
1508
1564
|
try {
|
|
@@ -1521,7 +1577,9 @@ export class SessionManager {
|
|
|
1521
1577
|
// (isContextlessActive 在 globalEnabled===true 时直接返回 true)。
|
|
1522
1578
|
// ★ 提前算:会话级「智能判断」开关(固定 N 条 trim 要用它让位)
|
|
1523
1579
|
try {
|
|
1524
|
-
|
|
1580
|
+
// ★ 2026-11-25:优先用上面算好的 sk0(已含持久映射兜底),
|
|
1581
|
+
// 否则恢复的会话这里又退回 findByAgent ⇒ ctxSmartOn 仍为 false,固定窗口照样抢跑。
|
|
1582
|
+
const sk0b = this.findByAgent(agent)?.sessionKey || sk0;
|
|
1525
1583
|
if (sk0b) {
|
|
1526
1584
|
setMemoMaxItems(contextlessMemoMaxOf(sk0b) ?? this.config.contextMemoMaxItems ?? 20);
|
|
1527
1585
|
ctxSmartOn = isContextlessActive(sk0b, this.config.contextlessMode)
|
|
@@ -1540,7 +1598,30 @@ export class SessionManager {
|
|
|
1540
1598
|
segOn0 = isContextlessActive(ctxKey0, this.config.contextlessMode) && contextlessSegmentOf(sk0);
|
|
1541
1599
|
}
|
|
1542
1600
|
catch { /* ignore */ }
|
|
1543
|
-
|
|
1601
|
+
// ★★ 2026-11-25(主人实测 + 微积分指出):**智能判断与分段压缩同开时,AI 登记的
|
|
1602
|
+
// compact/drop 下一回合不生效**。原因是执行顺序:分段压缩先跑、把"上回合结束→本回合开始"
|
|
1603
|
+
// 那段压成占位节点;等下面消费 pending 时,那段里"消息数 <= keep+1"直接 return false,
|
|
1604
|
+
// 什么都删不掉 —— 但 pending 照样被 clear,工具回执还说"下一回合执行",等于骗人。
|
|
1605
|
+
// pending 是 AI 明确要求的全量操作,优先级高于"压本轮尾巴":有 pending 就跳过本轮分段压缩。
|
|
1606
|
+
let pendingAhead = null;
|
|
1607
|
+
try {
|
|
1608
|
+
const skP = String(sk0 || this.findByAgent(agent)?.sessionKey || "");
|
|
1609
|
+
const drP = this.resolveDataRootSmart();
|
|
1610
|
+
if (skP && drP)
|
|
1611
|
+
pendingAhead = readContextPending(drP, skP);
|
|
1612
|
+
if (pendingAhead)
|
|
1613
|
+
traceContextless("[ctxorder] 本轮有 pending(" + String(pendingAhead.mode) + ") → 跳过分段压缩,交给下面消费");
|
|
1614
|
+
}
|
|
1615
|
+
catch { /* ignore */ }
|
|
1616
|
+
// ★ 2026-11-25(CodeRabbit Major):跳过分段压缩的条件必须和"本轮**真的能消费** pending"一致。
|
|
1617
|
+
// 否则:上一回合登记了 compact、随后**关掉智能模式**但保留分段压缩 ⇒ pendingAhead 一直在,
|
|
1618
|
+
// 而下面的消费分支要求 ctxSmartOn 为真 ⇒ 既不执行也不清除 ⇒ **分段压缩被永久跳过**。
|
|
1619
|
+
// 正确口径:只有"有 pending **且** 智能模式开着(能消费)"才让位。
|
|
1620
|
+
const willConsumePending = !!pendingAhead && ctxSmartOn;
|
|
1621
|
+
if (pendingAhead && !ctxSmartOn) {
|
|
1622
|
+
traceContextless('[ctxorder] 有 pending 但智能模式已关 ⇒ 消费不了,照常跑分段压缩(pending 留着)');
|
|
1623
|
+
}
|
|
1624
|
+
if (segOn0 && !willConsumePending) {
|
|
1544
1625
|
// ── 分段压缩:只压「上回合结束 → 本回合开始」这一段,更早的前缀一个字都不动 ──
|
|
1545
1626
|
// 为什么这么做:dsh 每轮把整段上下文发出去,前缀不变才有缓存;只动尾巴才不会把缓存打掉。
|
|
1546
1627
|
try {
|
|
@@ -1669,6 +1750,19 @@ export class SessionManager {
|
|
|
1669
1750
|
catch (e) {
|
|
1670
1751
|
this.logger?.debug?.('[model-sync] 异常(已忽略): ' + (e instanceof Error ? e.message : String(e)));
|
|
1671
1752
|
}
|
|
1753
|
+
// ── 已进上下文的图片链接 → 本地路径(2026-11-26 主人要求,默认关)──
|
|
1754
|
+
// 图片是后台下载的,组装时可能还没下完,上下文里就留下了 QQ 临时长链接。
|
|
1755
|
+
// 这里用 surfaceOp replace 只改**尾部**(上一回合结束之后那几条),改完永久生效。
|
|
1756
|
+
try {
|
|
1757
|
+
if (this.config.imagePathSurface === true && (!Number.isFinite(currentStep) || currentStep <= 1)) {
|
|
1758
|
+
const n = await replaceImagePathsInSurface(agent, this.logger, Number.isFinite(currentTurn) ? currentTurn : undefined, { scope: 'tail' });
|
|
1759
|
+
if (n > 0)
|
|
1760
|
+
this.logger?.info?.(`[img-path-surface] 本轮改写 ${n} 个图片链接`);
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1763
|
+
catch (e) {
|
|
1764
|
+
this.logger?.debug?.('[img-path-surface] 异常(已忽略): ' + (e instanceof Error ? e.message : String(e)));
|
|
1765
|
+
}
|
|
1672
1766
|
// ── 历史图片不重发(2026-11-07 主人定)──
|
|
1673
1767
|
// 每轮第一步:把**本插件聚合出来**的图片在历史里换成文字占位,
|
|
1674
1768
|
// 只保留「本回合新来的那几张」。别的插件/功能塞的图一律不动。
|
|
@@ -1769,7 +1863,20 @@ export class SessionManager {
|
|
|
1769
1863
|
// 与上面的「固定 N 条 trim」互斥:智能模式开启时,固定窗口让位给 AI 自主决定。
|
|
1770
1864
|
try {
|
|
1771
1865
|
const recSmart = agent ? this.findByAgent(agent) : undefined;
|
|
1772
|
-
|
|
1866
|
+
let skSmart = recSmart?.sessionKey;
|
|
1867
|
+
// ★ CodeRabbit 2026-11-25(Major):**消费端要和注册端用同一个会话键**。
|
|
1868
|
+
// 宿主恢复出来的 QQ 会话没有 findByAgent 记录;注册端已经能用持久映射取到 key、
|
|
1869
|
+
// 把请求写进该 key 的 pending 文件,但原来这里仍只用 rec.sessionKey ⇒ 对这种会话
|
|
1870
|
+
// skSmart 恒空 ⇒ 下面的条件不成立 ⇒ **pending 永远不执行**(工具却回"下一回合执行")。
|
|
1871
|
+
// 有活跃记录时仍以记录为准;没有映射的会话保持现状。
|
|
1872
|
+
if (!skSmart) {
|
|
1873
|
+
try {
|
|
1874
|
+
const sidSmart = String(agent?.session?.id ?? '');
|
|
1875
|
+
if (sidSmart)
|
|
1876
|
+
skSmart = this.modelResolver.findKeyBySessionId(sidSmart) || undefined;
|
|
1877
|
+
}
|
|
1878
|
+
catch { /* ignore */ }
|
|
1879
|
+
}
|
|
1773
1880
|
try {
|
|
1774
1881
|
traceContextless('[ctxsmart-diag2] sk=' + String(skSmart) + ' on=' + String(ctxSmartOn));
|
|
1775
1882
|
}
|
|
@@ -1797,14 +1904,24 @@ export class SessionManager {
|
|
|
1797
1904
|
const req = readContextPending(dataRootSmart, skSmart);
|
|
1798
1905
|
if (req) {
|
|
1799
1906
|
const keep = req.mode === 'drop' ? 0 : (Number(req.keep) || 3);
|
|
1800
|
-
await trimHistoryForContextless(agent, keep, this.logger, (() => { try {
|
|
1907
|
+
const done = await trimHistoryForContextless(agent, keep, this.logger, (() => { try {
|
|
1801
1908
|
return this.ctx;
|
|
1802
1909
|
}
|
|
1803
1910
|
catch {
|
|
1804
1911
|
return undefined;
|
|
1805
1912
|
} })(), Number.isFinite(currentTurn) ? currentTurn : undefined);
|
|
1806
|
-
|
|
1807
|
-
|
|
1913
|
+
// ★★ 2026-11-25:trimHistoryForContextless **返回 false 表示"什么都没删"**
|
|
1914
|
+
// (节点数不足 / 消息数 <= keep+1 / 受保护节点挡在最前)。原来不看返回值就 clear,
|
|
1915
|
+
// AI 那边看到"已登记"、历史却没动,且请求被吞掉再也不重试。
|
|
1916
|
+
// 现在:没删成就**保留 pending**(下一回合还会再试),并把原因记进日志。
|
|
1917
|
+
if (done) {
|
|
1918
|
+
clearContextPending(dataRootSmart, skSmart);
|
|
1919
|
+
this.logger?.info?.('[contextless] 已执行 AI 登记的 ' + String(req.mode) + '(keep=' + keep + ', session=' + skSmart + ')');
|
|
1920
|
+
}
|
|
1921
|
+
else {
|
|
1922
|
+
this.logger?.warn?.('[contextless] AI 登记的 ' + String(req.mode) + ' 本轮没能生效(可删内容不足),保留 pending 下回合重试: session=' + skSmart);
|
|
1923
|
+
traceContextless('[ctxsmart] pending 未生效,保留: mode=' + String(req.mode) + ' keep=' + keep);
|
|
1924
|
+
}
|
|
1808
1925
|
}
|
|
1809
1926
|
}
|
|
1810
1927
|
}
|
|
@@ -2026,6 +2143,61 @@ export class SessionManager {
|
|
|
2026
2143
|
}
|
|
2027
2144
|
catch { /* ignore */ }
|
|
2028
2145
|
}
|
|
2146
|
+
// ★ 2026-11-26(主人方案):**pre-step 兜底** —— 把本步新消息里的 QQ 图片 URL 换成本地路径。
|
|
2147
|
+
// 为什么在这里:图片下载是后台 fire-and-forget(不阻塞入站),消息组装时可能还没下完;
|
|
2148
|
+
// 而 `dec.messages` 是「本步从收件箱取出的新消息」,正是**上下文已就位、回合正要开始**的那一刻。
|
|
2149
|
+
// 在这儿查 image-path-cache,下完几张就换几张,没下完的原样留着(回退 QQ 链接)。
|
|
2150
|
+
// ⚠️ 2026-11-26(审核 S8 更正):这段改写**会进 session** —— 宿主 agent-loop 的 step()
|
|
2151
|
+
// 会把 decision.messages 逐条 `session.append('user/message', …, {surfaceOp:'append'})`。
|
|
2152
|
+
// 所以是"一次性改写并落库",不是"只改副本"。副作用:本地路径日后若被图片回收删掉,
|
|
2153
|
+
// 原 QQ 链接已不可恢复 —— 这也是它虽不带开关、仍要尽量收窄范围的原因。
|
|
2154
|
+
try {
|
|
2155
|
+
let imgReplaced = 0;
|
|
2156
|
+
// 防御:只扫前 24 条(`dec.messages` 正常只有 1~3 条;真遇到大批量也不至于卡住热路径)
|
|
2157
|
+
const IMG_SCAN_MAX = 24;
|
|
2158
|
+
let scanLeft = IMG_SCAN_MAX;
|
|
2159
|
+
dec.messages = dec.messages.map((m) => {
|
|
2160
|
+
if (scanLeft-- <= 0)
|
|
2161
|
+
return m;
|
|
2162
|
+
const mm = m;
|
|
2163
|
+
if (!mm || mm.role !== 'user' || !Array.isArray(mm.content))
|
|
2164
|
+
return m;
|
|
2165
|
+
let msgChanged = false;
|
|
2166
|
+
const nc = mm.content.map((c) => {
|
|
2167
|
+
if (!c || c.type !== 'text' || typeof c.text !== 'string')
|
|
2168
|
+
return c;
|
|
2169
|
+
// 只碰含 QQ 图片下载链接的文本块,其他内容一律不动
|
|
2170
|
+
if (!/multimedia\.nt\.qq\.com\.cn|qq\.com\/download/i.test(c.text))
|
|
2171
|
+
return c;
|
|
2172
|
+
let blockChanged = false;
|
|
2173
|
+
// ⚠️ 字符类必须排除 `]`/`>`/中文标点:本仓库图片占位是 `[图片: <url>]`,
|
|
2174
|
+
// 用 `[^\s)]` 会把 `]` 与紧跟的正文一起吃掉(审核 M1)。
|
|
2175
|
+
// CodeRabbit PR #93:外层只判断「整段里有没有 QQ 图片域名」,但下面这个回调会对块里
|
|
2176
|
+
// **每个** https 链接调 lookupImagePath,而它的 stableKey 只看 fileid 前 40 字符
|
|
2177
|
+
// → 普通链接可能误命中缓存。所以回调内先校验主机,非 QQ 图片链接原样返回。
|
|
2178
|
+
const isQqImageUrl = (x) => /^https:\/\/(?:multimedia\.nt\.qq\.com\.cn|qq\.com)\/download/i.test(x);
|
|
2179
|
+
const replacedText = c.text.replace(/https:\/\/[^\s)\]}>"',。;!?、【】()《》]+/g, (u) => {
|
|
2180
|
+
if (!isQqImageUrl(u))
|
|
2181
|
+
return u;
|
|
2182
|
+
const local = lookupImagePath(u);
|
|
2183
|
+
if (!local)
|
|
2184
|
+
return u;
|
|
2185
|
+
imgReplaced++;
|
|
2186
|
+
blockChanged = true;
|
|
2187
|
+
return local;
|
|
2188
|
+
});
|
|
2189
|
+
if (!blockChanged)
|
|
2190
|
+
return c;
|
|
2191
|
+
msgChanged = true;
|
|
2192
|
+
return { ...c, text: replacedText };
|
|
2193
|
+
});
|
|
2194
|
+
return msgChanged ? { ...mm, content: nc } : m;
|
|
2195
|
+
});
|
|
2196
|
+
if (imgReplaced > 0) {
|
|
2197
|
+
this.logger?.debug?.(`[img-path] pre-step 替换 ${imgReplaced} 个图片 URL → 本地路径`);
|
|
2198
|
+
}
|
|
2199
|
+
}
|
|
2200
|
+
catch { /* 替换失败不影响本步 */ }
|
|
2029
2201
|
if (recMemo || isQqSessionByPrefs) {
|
|
2030
2202
|
const DIRECT_MARK = '【主人在 DSH 宿主界面直接发送】';
|
|
2031
2203
|
let marked = 0;
|