@nestim/koishi-plugin-qq-group-manager 1.2.2 → 1.2.4

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 CHANGED
@@ -2,6 +2,25 @@
2
2
 
3
3
  本文件记录所有值得注意的变更。版本号遵循 [语义化版本](https://semver.org/lang/zh-CN/)。
4
4
 
5
+ ## 1.2.4
6
+
7
+ ### 修复
8
+
9
+ - **识图:先发图、再单独 @ 机器人时图片丢失**。`collectImages` 原本只看当前消息和引用消息,
10
+ 当前消息只有文字时 `images=0`,机器人会回“图没刷出来”。
11
+ 现在当前消息没有图时,会回看最近 2 分钟内**同一用户**最近 1–2 条消息里的图
12
+ (仍受 `aiImageMaxCount` 限制);不回看其他用户的图,也不回看超过 2 分钟的图。
13
+ - 删除 1.2.3 诊断期临时加的 `[ai-image]` 日志。
14
+
15
+ ## 1.2.3
16
+
17
+ ### 修复
18
+
19
+ - **续聊(followup)触发过宽**:用户换话题后,像“操不会说话了”这种短句仍会被当成
20
+ “接着上一轮说”,导致机器人追着自己的旧话题自说自话。
21
+ 现在必须满足“与上一轮有话题交集”或“明确追问词(展开/细说/然后/为什么…)”才续聊,
22
+ 否则直接清掉待续状态,按新消息重新判断。
23
+
5
24
  ## 1.2.2
6
25
 
7
26
  ### 修复
@@ -67,6 +67,7 @@ export declare class AiEngine {
67
67
  private getFollowup;
68
68
  private loadMemories;
69
69
  handle(session: any): Promise<void>;
70
+ private recentImageRecords;
70
71
  private collectImages;
71
72
  private judge;
72
73
  private platformAllowed;
package/lib/ai/engine.js CHANGED
@@ -264,9 +264,12 @@ class AiEngine {
264
264
  return false;
265
265
  if (/[??]/.test(text))
266
266
  return true;
267
- if (/(继续|然后|那|所以|为什么|怎么|如何|帮我|还能|可以吗|行吗|对不对|是不是)/.test(text))
267
+ if (/(继续|然后|那|所以|为什么|怎么|如何|帮我|还能|可以吗|行吗|对不对|是不是|展开|多说|细说|具体|举个例子|还有呢|后来呢|说说|讲讲)/.test(text))
268
268
  return true;
269
- return text.length >= 6;
269
+ // 没有话题交集、也不是明确的追问 → 不追着说,避免用户换话题后机器人自说自话
270
+ if (overlap > 0 && ratio >= 0.18)
271
+ return true;
272
+ return false;
270
273
  }
271
274
  startFollowup(state, record) {
272
275
  if (this.config.aiEnableFollowupAfterMention === false)
@@ -354,6 +357,9 @@ class AiEngine {
354
357
  const mention = this.isMention(session, record);
355
358
  const followupState = mention ? null : this.getFollowup(state, record, session);
356
359
  const followup = !!followupState && this.shouldContinueFollowup(record, followupState);
360
+ // 用户换了话题/说的和上一轮无关时,丢掉待续话题,避免机器人追着自己上一句说
361
+ if (followupState && !followup)
362
+ state.followup = null;
357
363
  const threshold = Math.max(1, Number(this.config.aiMessageThreshold ?? 15));
358
364
  const decision = (0, trigger_1.decideTrigger)({
359
365
  mode: (this.config.aiReplyMode || 'hybrid'),
@@ -416,7 +422,7 @@ class AiEngine {
416
422
  if (this.debugPrompt) {
417
423
  this.host.logger.info(`[ai-debug] system=${prompt.system}\n[ai-debug] user=${prompt.user}`);
418
424
  }
419
- const images = await this.collectImages(session, record);
425
+ const images = await this.collectImages(session, record, state);
420
426
  const result = await this.provider.chat({
421
427
  system: prompt.system,
422
428
  user: prompt.user,
@@ -492,15 +498,34 @@ class AiEngine {
492
498
  state.inFlight = false;
493
499
  }
494
500
  }
495
- async collectImages(session, record) {
501
+ recentImageRecords(state, record, maxAgeMs = 120000) {
502
+ const cutoff = Number(record.at) - maxAgeMs;
503
+ const candidates = state.records
504
+ .filter((item) => (!item.self
505
+ && item.id !== record.id
506
+ && item.userId === record.userId
507
+ && item.images.length > 0
508
+ && Number(item.at) >= cutoff))
509
+ .slice(-4)
510
+ .reverse();
511
+ const out = [];
512
+ for (const item of candidates) {
513
+ for (const image of item.images)
514
+ out.push(image);
515
+ }
516
+ return out;
517
+ }
518
+ async collectImages(session, record, state) {
496
519
  if (this.config.aiEnableImageRecognition === false)
497
520
  return [];
498
521
  const maxCount = Math.max(0, Number(this.config.aiImageMaxCount ?? 2));
499
522
  if (!maxCount)
500
523
  return [];
501
524
  const own = record.images.length ? record.images : this.host.extractImages(session);
525
+ // 用户常见的“先发图,再单独 @ 一句”:当前消息没有图,回看同一用户最近 2 分钟内的图
526
+ const fallback = own.length ? [] : this.recentImageRecords(state, record);
502
527
  const quoted = record.quote ? this.host.extractImages(session?.quote) : [];
503
- const items = (0, vision_1.pickImages)(own, quoted, maxCount);
528
+ const items = (0, vision_1.pickImages)([...own, ...fallback], quoted, maxCount);
504
529
  if (!items.length)
505
530
  return [];
506
531
  return (0, vision_1.resolveImages)(items, (ref) => this.host.resolveImage(ref, session), { maxCount, budgetMs: Number(this.config.aiImageBudgetMs ?? 6000) });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nestim/koishi-plugin-qq-group-manager",
3
3
  "description": "Koishi QQ群管理插件(OneBot/LLOneBot):群管命令、权限校验、图片菜单、状态卡片、复读、AI群聊回复、记忆库、识图与自动管控(禁言/踢人)。",
4
- "version": "1.2.2",
4
+ "version": "1.2.4",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
package/src/ai/engine.ts CHANGED
@@ -297,8 +297,10 @@ export class AiEngine {
297
297
  if (text.length >= 8 && ratio <= 0.12 && /[??]/.test(text)) return false;
298
298
 
299
299
  if (/[??]/.test(text)) return true;
300
- if (/(继续|然后|那|所以|为什么|怎么|如何|帮我|还能|可以吗|行吗|对不对|是不是)/.test(text)) return true;
301
- return text.length >= 6;
300
+ if (/(继续|然后|那|所以|为什么|怎么|如何|帮我|还能|可以吗|行吗|对不对|是不是|展开|多说|细说|具体|举个例子|还有呢|后来呢|说说|讲讲)/.test(text)) return true;
301
+ // 没有话题交集、也不是明确的追问 → 不追着说,避免用户换话题后机器人自说自话
302
+ if (overlap > 0 && ratio >= 0.18) return true;
303
+ return false;
302
304
  }
303
305
 
304
306
  private startFollowup(state: GroupState, record: ChatRecord): void {
@@ -382,6 +384,8 @@ export class AiEngine {
382
384
  const mention = this.isMention(session, record);
383
385
  const followupState = mention ? null : this.getFollowup(state, record, session);
384
386
  const followup = !!followupState && this.shouldContinueFollowup(record, followupState);
387
+ // 用户换了话题/说的和上一轮无关时,丢掉待续话题,避免机器人追着自己上一句说
388
+ if (followupState && !followup) state.followup = null;
385
389
 
386
390
  const threshold = Math.max(1, Number(this.config.aiMessageThreshold ?? 15));
387
391
  const decision = decideTrigger({
@@ -450,7 +454,7 @@ export class AiEngine {
450
454
  this.host.logger.info(`[ai-debug] system=${prompt.system}\n[ai-debug] user=${prompt.user}`);
451
455
  }
452
456
 
453
- const images = await this.collectImages(session, record);
457
+ const images = await this.collectImages(session, record, state);
454
458
  const result = await this.provider.chat({
455
459
  system: prompt.system,
456
460
  user: prompt.user,
@@ -531,14 +535,35 @@ export class AiEngine {
531
535
  }
532
536
  }
533
537
 
534
- private async collectImages(session: any, record: ChatRecord): Promise<string[]> {
538
+ private recentImageRecords(state: GroupState, record: ChatRecord, maxAgeMs = 120000): RenderedImage[] {
539
+ const cutoff = Number(record.at) - maxAgeMs;
540
+ const candidates = state.records
541
+ .filter((item) => (
542
+ !item.self
543
+ && item.id !== record.id
544
+ && item.userId === record.userId
545
+ && item.images.length > 0
546
+ && Number(item.at) >= cutoff
547
+ ))
548
+ .slice(-4)
549
+ .reverse();
550
+ const out: RenderedImage[] = [];
551
+ for (const item of candidates) {
552
+ for (const image of item.images) out.push(image);
553
+ }
554
+ return out;
555
+ }
556
+
557
+ private async collectImages(session: any, record: ChatRecord, state: GroupState): Promise<string[]> {
535
558
  if (this.config.aiEnableImageRecognition === false) return [];
536
559
  const maxCount = Math.max(0, Number(this.config.aiImageMaxCount ?? 2));
537
560
  if (!maxCount) return [];
538
561
 
539
562
  const own = record.images.length ? record.images : this.host.extractImages(session);
563
+ // 用户常见的“先发图,再单独 @ 一句”:当前消息没有图,回看同一用户最近 2 分钟内的图
564
+ const fallback = own.length ? [] : this.recentImageRecords(state, record);
540
565
  const quoted = record.quote ? this.host.extractImages(session?.quote) : [];
541
- const items = pickImages(own, quoted, maxCount);
566
+ const items = pickImages([...own, ...fallback], quoted, maxCount);
542
567
  if (!items.length) return [];
543
568
 
544
569
  return resolveImages(