koishi-plugin-group-analysis-mx 1.6.2 → 1.7.0

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/lib/config.js CHANGED
@@ -241,7 +241,7 @@ exports.Config = koishi_1.Schema.intersect([
241
241
  用户关注昵称:{nicknames}
242
242
  目标时间范围:{timeRange}
243
243
 
244
- 要求:生成内容时需优先围绕上述关键词、话题、昵称与时间范围。
244
+ 要求:生成内容时需优先围绕上述关键词、话题、昵称与时间范围。\n在 detail 中引用群友时,请使用 [user_id] 格式(从消息记录里的方括号 ID 取),例如 [123456],不要直接写昵称。
245
245
 
246
246
  群聊记录:
247
247
  {messages}
@@ -836,7 +836,7 @@ class AnalysisService extends koishi_1.Service {
836
836
  // LLM analyses in parallel
837
837
  const users = Object.values(userStats);
838
838
  const [topics, userTitles, goldenQuotes] = await Promise.all([
839
- this.ctx.group_analysis_llm.summarizeTopics(messagesText, context),
839
+ this.ctx.group_analysis_llm.summarizeTopics(idBasedMessagesText || messagesText, context),
840
840
  this.config.userTitleAnalysis
841
841
  ? this.ctx.group_analysis_llm.analyzeUserTitles(users, context)
842
842
  : Promise.resolve([]),
@@ -226,23 +226,52 @@ class RendererService extends koishi_1.Service {
226
226
  userTitles: await Promise.all((data.userTitles || []).map(inlineAvatar)),
227
227
  };
228
228
 
229
- // 话题昵称装饰:只给描述正文里的昵称加"头像 + 胶囊"小标签(参与者那一行不加)
229
+ // 话题昵称装饰:LLM 用 [user_id] 引用时渲染成"头像 + 昵称"胶囊(照原版做法),并兼容昵称匹配
230
+ const topicIdMap = new Map();
231
+ for (const u of (data.userStats || [])) {
232
+ if (u && u.userId && u.avatar && String(u.avatar).startsWith('data:'))
233
+ topicIdMap.set(String(u.userId), { name: u.nickname || u.rawName || '', avatar: u.avatar });
234
+ }
230
235
  const nameAvatar = new Map();
231
236
  for (const u of (data.userStats || [])) {
232
237
  if (u && u.avatar && String(u.avatar).startsWith('data:')) {
233
238
  for (const nm of [u.rawName, u.nickname]) {
234
- if (nm && String(nm).trim())
239
+ if (nm && String(nm).trim()) {
235
240
  nameAvatar.set(String(nm).trim(), u.avatar);
241
+ const nn = (0, utils_1.normalizeNickname)(nm);
242
+ if (nn) nameAvatar.set(nn, u.avatar);
243
+ }
236
244
  }
237
245
  }
238
246
  }
239
- // 昵称按长度降序,避免短名先替换把长名拆开
240
247
  const chipNames = [...nameAvatar.keys()].filter((n) => n && n.trim()).sort((x, y) => y.length - x.length);
241
- const chipOf = (name) => {
242
- const av = nameAvatar.get(name);
248
+ const capsuleOf = (name, av) => {
243
249
  const img = av ? '<img src="' + av + '" alt="" style="width:1.15em;height:1.15em;border-radius:50%;object-fit:cover;vertical-align:middle;display:inline-block;margin-right:3px">' : '';
244
250
  return '<span class="topic-user" style="display:inline-flex;align-items:center;background:rgba(0,0,0,.055);border-radius:999px;padding:1px 8px 1px 2px;font-size:.92em;line-height:1.7;vertical-align:middle;margin:0 1px">' + img + name + '</span>';
245
251
  };
252
+ data = {
253
+ ...data,
254
+ topics: (data.topics || []).map((t) => {
255
+ if (!t) return t;
256
+ let detail = String(t.detail || '');
257
+ // 1) [user_id] 引用 → 胶囊(确定性)
258
+ detail = detail.replace(/\[([0-9A-Za-z]{4,128})\]/g, (m, id) => {
259
+ const u = topicIdMap.get(id);
260
+ return u ? capsuleOf(u.name, u.avatar) : '群友';
261
+ });
262
+ // 2) 纯昵称兜底
263
+ const ph = [];
264
+ for (const n of chipNames) {
265
+ const text = n.trim();
266
+ if (!text || !detail.includes(text)) continue;
267
+ const tag = '\u0001' + ph.length + '\u0002';
268
+ detail = detail.split(text).join(tag);
269
+ ph.push(capsuleOf(text, nameAvatar.get(text)));
270
+ }
271
+ detail = detail.replace(/\u0001(\d+)\u0002/g, (m, i) => ph[+i] || '');
272
+ return { ...t, detail };
273
+ }),
274
+ };
246
275
  try { this.ctx.logger.info(`[chip] 映射昵称=${nameAvatar.size} 候选=${chipNames.length} 话题=${(data.topics || []).length} rawName示例=${JSON.stringify((data.userStats||[]).slice(0,2).map(u=>({n:u.nickname,r:u.rawName,a:String(u.avatar||'').slice(0,15)})))}`); } catch (e) {}
247
276
  const templatePath = this.getSkinPath('template_group.html');
248
277
  const randomId = Math.random().toString(36).substring(2, 15);
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.6.2",
4
+ "version": "1.7.0",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.mjs",
7
7
  "typings": "lib/index.d.ts",
@@ -55,3 +55,5 @@
55
55
 
56
56
 
57
57
 
58
+
59
+