@nestim/koishi-plugin-qq-group-manager 1.2.3 → 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,16 @@
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
+
5
15
  ## 1.2.3
6
16
 
7
17
  ### 修复
@@ -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
@@ -422,7 +422,7 @@ class AiEngine {
422
422
  if (this.debugPrompt) {
423
423
  this.host.logger.info(`[ai-debug] system=${prompt.system}\n[ai-debug] user=${prompt.user}`);
424
424
  }
425
- const images = await this.collectImages(session, record);
425
+ const images = await this.collectImages(session, record, state);
426
426
  const result = await this.provider.chat({
427
427
  system: prompt.system,
428
428
  user: prompt.user,
@@ -498,15 +498,34 @@ class AiEngine {
498
498
  state.inFlight = false;
499
499
  }
500
500
  }
501
- 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) {
502
519
  if (this.config.aiEnableImageRecognition === false)
503
520
  return [];
504
521
  const maxCount = Math.max(0, Number(this.config.aiImageMaxCount ?? 2));
505
522
  if (!maxCount)
506
523
  return [];
507
524
  const own = record.images.length ? record.images : this.host.extractImages(session);
525
+ // 用户常见的“先发图,再单独 @ 一句”:当前消息没有图,回看同一用户最近 2 分钟内的图
526
+ const fallback = own.length ? [] : this.recentImageRecords(state, record);
508
527
  const quoted = record.quote ? this.host.extractImages(session?.quote) : [];
509
- const items = (0, vision_1.pickImages)(own, quoted, maxCount);
528
+ const items = (0, vision_1.pickImages)([...own, ...fallback], quoted, maxCount);
510
529
  if (!items.length)
511
530
  return [];
512
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.3",
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
@@ -454,7 +454,7 @@ export class AiEngine {
454
454
  this.host.logger.info(`[ai-debug] system=${prompt.system}\n[ai-debug] user=${prompt.user}`);
455
455
  }
456
456
 
457
- const images = await this.collectImages(session, record);
457
+ const images = await this.collectImages(session, record, state);
458
458
  const result = await this.provider.chat({
459
459
  system: prompt.system,
460
460
  user: prompt.user,
@@ -535,14 +535,35 @@ export class AiEngine {
535
535
  }
536
536
  }
537
537
 
538
- 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[]> {
539
558
  if (this.config.aiEnableImageRecognition === false) return [];
540
559
  const maxCount = Math.max(0, Number(this.config.aiImageMaxCount ?? 2));
541
560
  if (!maxCount) return [];
542
561
 
543
562
  const own = record.images.length ? record.images : this.host.extractImages(session);
563
+ // 用户常见的“先发图,再单独 @ 一句”:当前消息没有图,回看同一用户最近 2 分钟内的图
564
+ const fallback = own.length ? [] : this.recentImageRecords(state, record);
544
565
  const quoted = record.quote ? this.host.extractImages(session?.quote) : [];
545
- const items = pickImages(own, quoted, maxCount);
566
+ const items = pickImages([...own, ...fallback], quoted, maxCount);
546
567
  if (!items.length) return [];
547
568
 
548
569
  return resolveImages(