koishi-plugin-group-analysis-mx 1.7.7 → 1.7.9

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.
@@ -3,6 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LLMService = void 0;
4
4
  const koishi_1 = require("koishi");
5
5
  const js_yaml_1 = require("js-yaml");
6
+ const REPAIRABLE_QUOTED_FIELDS = new Set(['sender', 'name', 'username', 'user_id', 'userId', 'id', 'topic', 'title', 'mbti']);
7
+ function repairUnclosedQuotedFields(source) {
8
+ let changed = false;
9
+ const repaired = String(source).split(/\r?\n/).map((line) => {
10
+ const match = line.match(/^(\s*)([A-Za-z_][A-Za-z0-9_-]*)\s*:\s*("(?:\\.|[^"\\])*)\s*$/);
11
+ if (!match || !REPAIRABLE_QUOTED_FIELDS.has(match[2]))
12
+ return line;
13
+ changed = true;
14
+ return line + '"';
15
+ }).join('\n');
16
+ return changed ? repaired : null;
17
+ }
6
18
  class LLMService extends koishi_1.Service {
7
19
  config;
8
20
  constructor(ctx, config) {
@@ -44,7 +56,17 @@ class LLMService extends koishi_1.Service {
44
56
  }
45
57
  try {
46
58
  // json: true 容忍重复 key(LLM 偶尔会重复输出 sender 等字段),后者覆盖前者
47
- const data = (0, js_yaml_1.load)(yamlMatch[1], { json: true });
59
+ let data;
60
+ try {
61
+ data = (0, js_yaml_1.load)(yamlMatch[1], { json: true });
62
+ }
63
+ catch (parseError) {
64
+ const repairedYaml = repairUnclosedQuotedFields(yamlMatch[1]);
65
+ if (!repairedYaml)
66
+ throw parseError;
67
+ data = (0, js_yaml_1.load)(repairedYaml, { json: true });
68
+ this.ctx.logger.warn(`LLM ${taskName} YAML 的身份字段缺少结束引号,已自动修复后解析。`);
69
+ }
48
70
  if (Array.isArray(data)) {
49
71
  this.ctx.logger.info(`成功解析 ${data.length} 条数据。`);
50
72
  }
package/lib/utils.js CHANGED
@@ -28,6 +28,7 @@ exports.buildGroupAnalysisCacheKey = buildGroupAnalysisCacheKey;
28
28
  exports.buildMessagePersistenceKey = buildMessagePersistenceKey;
29
29
  exports.isNapCatBot = isNapCatBot;
30
30
  exports.isJunkMessage = isJunkMessage;
31
+ exports.isForwardedChatRecord = isForwardedChatRecord;
31
32
  exports.cleanContent = cleanContent;
32
33
  const koishi_1 = require("koishi");
33
34
  const skins_1 = require("./skins");
@@ -372,6 +373,28 @@ async function isNapCatBot(bot) {
372
373
  const name = versionInfo.data['app_name'].toLowerCase();
373
374
  return { isRunningNapCat: name.includes('napcat'), botAppName: name };
374
375
  }
376
+ /**
377
+ * 判断消息是否为 QQ“合并转发/聊天记录”卡片。
378
+ * 官方适配器没有解析 102 类型的聊天记录,只把卡片预览文字当成普通文本,
379
+ * 直接分析会把它当成转发者的发言,因此这里整体识别并跳过。
380
+ */
381
+ function isForwardedChatRecord(content) {
382
+ if (content === null || content === undefined)
383
+ return false;
384
+ const s = String(content).replace(/\s+/g, ' ').trim();
385
+ if (!s)
386
+ return false;
387
+ // 卡片底部固定文案,如“查看2条转发消息”
388
+ if (/查看\s*\d+\s*条(?:转发)?消息/.test(s))
389
+ return true;
390
+ // 卡片标题,如“群聊的聊天记录”
391
+ if (/^群聊的聊天记录(?:$|\s|[::])/.test(s))
392
+ return true;
393
+ // 部分版本只给占位标签
394
+ if (/^\[(?:聊天记录|合并转发)\]$/.test(s))
395
+ return true;
396
+ return false;
397
+ }
375
398
  /**
376
399
  * 判断消息是否为非聊天的垃圾内容(腾讯官方 bot 的 ROBOT1.0_ 签名、超长无空白 token 串等)。
377
400
  * 这类内容不应存入消息库,也不应参与分析。
@@ -382,6 +405,9 @@ function isJunkMessage(content) {
382
405
  const s = String(content).trim();
383
406
  if (!s)
384
407
  return false;
408
+ // 合并转发/聊天记录卡片
409
+ if (isForwardedChatRecord(s))
410
+ return true;
385
411
  // 腾讯 QQ 官方机器人消息签名(任意位置出现都过滤)
386
412
  if (/ROBOT1\.0_/.test(s))
387
413
  return true;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-group-analysis-mx",
3
3
  "description": "群聊分析插件 - 生成精美群聊统计报告,支持 AI 话题总结(独立版,不依赖 ChatLuna)",
4
- "version": "1.7.7",
4
+ "version": "1.7.9",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.mjs",
7
7
  "typings": "lib/index.d.ts",
@@ -62,3 +62,5 @@
62
62
 
63
63
 
64
64
 
65
+
66
+
@@ -442,8 +442,10 @@ body {
442
442
  }
443
443
 
444
444
  .masonry-grid {
445
- column-count: 2;
445
+ display: grid;
446
+ grid-template-columns: repeat(2, minmax(0, 1fr));
446
447
  column-gap: 25px;
448
+ align-items: start;
447
449
  }
448
450
 
449
451
  .user-card {
@@ -793,7 +795,7 @@ body {
793
795
  }
794
796
 
795
797
  .masonry-grid {
796
- column-count: 1;
798
+ grid-template-columns: minmax(0, 1fr);
797
799
  }
798
800
 
799
801
  .stamp {