@nestim/koishi-plugin-qq-group-manager 1.1.0 → 1.1.1

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/index.js CHANGED
@@ -125,12 +125,12 @@ exports.Config = koishi_1.Schema.intersect([
125
125
  prompt: koishi_1.Schema.string().role('textarea').default('').description('该人格系统提示词(留空则使用默认提示词)。'),
126
126
  })).role('table').default([]).description('可保存多个人格配置,按 aiActivePersona 切换。'),
127
127
  aiReplyMode: koishi_1.Schema.union([
128
- koishi_1.Schema.const('threshold').description('达到消息阈值后回复'),
129
- koishi_1.Schema.const('random').description('按概率随机回复'),
130
- koishi_1.Schema.const('hybrid').description('阈值与随机同时生效'),
131
- ]).role('radio').default('hybrid').description('AI 触发策略。'),
132
- aiMessageThreshold: koishi_1.Schema.natural().default(16).description('阈值触发所需累计消息数。'),
133
- aiRandomReplyProbability: koishi_1.Schema.percent().default(0.08).description('随机触发概率(每条消息判定一次)。'),
128
+ koishi_1.Schema.const('threshold').description('只看消息数:累计达到阈值才触发(不看概率)'),
129
+ koishi_1.Schema.const('random').description('只看概率:每条消息掷一次骰(不看消息数)'),
130
+ koishi_1.Schema.const('hybrid').description('两者都要满足:先累计到阈值,再按概率掷中'),
131
+ ]).role('radio').default('hybrid').description('AI 触发策略。三道闸门依序为:①消息阈值 ②随机概率 ③兴趣评分,任一不过都不回复;@点名与点名后跟随可越过全部三道。'),
132
+ aiMessageThreshold: koishi_1.Schema.natural().default(16).description('阈值触发所需累计消息数。threshold / hybrid 模式下未达此数一律不触发;计数器在成功回复后清零,需重新累计。'),
133
+ aiRandomReplyProbability: koishi_1.Schema.percent().default(0.08).description('随机触发概率(每条消息掷一次骰)。random / hybrid 模式下未掷中直接跳过,不会调用 AI 接口。填 0 等同于关闭随机触发。'),
134
134
  aiMinReplyIntervalSeconds: koishi_1.Schema.natural().default(45).description('同一群两次 AI 回复的最短间隔(秒)。'),
135
135
  aiContextWindow: koishi_1.Schema.natural().default(24).description('参与推理的最近消息条数。'),
136
136
  aiTemperature: koishi_1.Schema.number().min(0).max(2).step(0.1).default(0.8).description('生成温度(0~2)。'),
@@ -146,7 +146,7 @@ exports.Config = koishi_1.Schema.intersect([
146
146
  aiOwnerUserId: koishi_1.Schema.string().default('').description('主人平台用户 ID(如 QQ 号,用于记忆主人身份)。'),
147
147
  aiHomePlatform: koishi_1.Schema.string().default('onebot').description('兼容字段:主页平台标识(建议改用 aiOwnerPlatform)。'),
148
148
  aiHomeUserId: koishi_1.Schema.string().default('').description('兼容字段:主页平台用户 ID(建议改用 aiOwnerUserId)。'),
149
- aiInterestMinScore: koishi_1.Schema.number().min(0).max(100).step(1).default(82).description('AI 兴趣触发最低分(非点名场景,分值越高越不容易回复)。'),
149
+ aiInterestMinScore: koishi_1.Schema.number().min(0).max(100).step(1).default(82).description('AI 兴趣触发最低分(最后一道闸门):非点名场景下,无论由阈值还是概率触发,都要再过一次兴趣评分,达到此分才真正回复。分值越高越不容易回复。'),
150
150
  aiInterestContextWindow: koishi_1.Schema.number().min(4).max(16).step(1).default(8).description('非阈值兴趣判定使用的上下文窗口条数。'),
151
151
  }).description('AI 回复'),
152
152
  koishi_1.Schema.object({
package/lib/service.js CHANGED
@@ -750,12 +750,25 @@ class QQGroupManagerService extends koishi_1.Service {
750
750
  const mode = this.config.aiReplyMode;
751
751
  const messageCount = this.aiCounters.get(key) ?? 0;
752
752
  const threshold = Math.max(1, this.config.aiMessageThreshold || 1);
753
- const thresholdHit = (mode === 'threshold' || mode === 'hybrid') && messageCount >= threshold;
754
- if (thresholdHit)
755
- return { ok: true, reason: `threshold(${messageCount}/${threshold})` };
756
- if (mode === 'threshold')
757
- return { ok: false, reason: 'not-triggered' };
758
- return { ok: true, reason: 'interest-check' };
753
+ // 闸门一(消息阈值):threshold / hybrid 模式下,累计消息数未达阈值一律不触发。
754
+ // 计数器只在成功回复后清零(见 maybeReplyWithAi 末尾),因此回复后需重新累计。
755
+ const thresholdRequired = mode === 'threshold' || mode === 'hybrid';
756
+ if (thresholdRequired && messageCount < threshold)
757
+ return { ok: false, reason: `below-threshold(${messageCount}/${threshold})` };
758
+ // 闸门二(随机概率):random / hybrid 模式下对每条消息掷一次骰,未掷中直接返回,
759
+ // 不会触发后续的兴趣判定与生成请求。
760
+ const randomRequired = mode === 'random' || mode === 'hybrid';
761
+ if (randomRequired) {
762
+ const probability = Math.max(0, Math.min(1, Number(this.config.aiRandomReplyProbability ?? 0.08)));
763
+ if (probability <= 0)
764
+ return { ok: false, reason: 'random-disabled' };
765
+ if (Math.random() >= probability)
766
+ return { ok: false, reason: `random-miss(${probability})` };
767
+ return thresholdRequired
768
+ ? { ok: true, reason: `threshold(${messageCount}/${threshold})+random(${probability})` }
769
+ : { ok: true, reason: `random(${probability})` };
770
+ }
771
+ return { ok: true, reason: `threshold(${messageCount}/${threshold})` };
759
772
  }
760
773
  parseInterestDecision(raw) {
761
774
  const text = raw.trim();
@@ -2249,13 +2262,22 @@ class QQGroupManagerService extends koishi_1.Service {
2249
2262
  if (!trigger.ok)
2250
2263
  return;
2251
2264
  const topicHint = (this.aiTopicMemory.get(groupKey)?.text || '').replace(/\s+/g, ' ').trim().slice(0, 120);
2252
- if (trigger.reason === 'interest-check') {
2265
+ const thresholdMode = typeof trigger.reason === 'string' && trigger.reason.startsWith('threshold(');
2266
+ // 闸门三(兴趣评分):所有非点名触发的回复都先过兴趣判定,达标才继续生成。
2267
+ // 点名(direct-mention)与点名后跟随(followup)不受此限。
2268
+ if (!directMention && !followupForce && !relatedContextFollowup) {
2253
2269
  const interest = await this.shouldReplyByInterest({ groupKey, text: effectiveText, hasSticker, hasImage: focusImages.length > 0 });
2254
- this.logCommandResult('ai-interest', { ok: interest.ok, message: `score=${interest.score} threshold=${interest.threshold} reason=${interest.reason}` }, session, { ctxSize: interest.ctxSize, topicHint: interest.topicHint || topicHint || undefined });
2255
- if (!interest.ok)
2270
+ this.logCommandResult(thresholdMode ? 'ai-threshold-interest' : 'ai-interest', { ok: interest.ok, message: `score=${interest.score} threshold=${interest.threshold} reason=${interest.reason} trigger=${trigger.reason}` }, session, { ctxSize: interest.ctxSize, topicHint: interest.topicHint || topicHint || undefined });
2271
+ if (!interest.ok) {
2272
+ this.logCommandResult(thresholdMode ? 'ai-threshold-skip-by-interest' : 'ai-skip-by-interest', { ok: true, message: 'triggered but skipped by low interest' }, session, {
2273
+ score: interest.score,
2274
+ threshold: interest.threshold,
2275
+ reason: interest.reason,
2276
+ trigger: trigger.reason,
2277
+ });
2256
2278
  return;
2279
+ }
2257
2280
  }
2258
- const thresholdMode = typeof trigger.reason === 'string' && trigger.reason.startsWith('threshold(');
2259
2281
  const topicMemory = this.aiTopicMemory.get(groupKey);
2260
2282
  const topicTokens = topicMemory?.tokens ?? [];
2261
2283
  let selectedRecord;
@@ -2272,18 +2294,6 @@ class QQGroupManagerService extends koishi_1.Service {
2272
2294
  }
2273
2295
  }
2274
2296
  }
2275
- if (thresholdMode) {
2276
- const interest = await this.shouldReplyByInterest({ groupKey, text: effectiveText, hasSticker, hasImage: focusImages.length > 0 });
2277
- this.logCommandResult('ai-threshold-interest', { ok: interest.ok, message: `score=${interest.score} threshold=${interest.threshold} reason=${interest.reason}` }, session, { ctxSize: interest.ctxSize, topicHint: interest.topicHint || topicHint || undefined });
2278
- if (!interest.ok) {
2279
- this.logCommandResult('ai-threshold-skip-by-interest', { ok: true, message: 'threshold hit but skipped by low interest' }, session, {
2280
- score: interest.score,
2281
- threshold: interest.threshold,
2282
- reason: interest.reason,
2283
- });
2284
- return;
2285
- }
2286
- }
2287
2297
  this.aiInFlight.add(groupKey);
2288
2298
  const startedAt = Date.now();
2289
2299
  // 已确认要回复,此时才把图片下载/转换为 base64(模型需要可直接读取的图片数据)
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.1.0",
4
+ "version": "1.1.1",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
package/readme.md CHANGED
@@ -29,7 +29,7 @@ Koishi 控制台「探索器 Explorer」里查看和手改。
29
29
  | **黑名单** | 按群独立存储(`banMember_<群号>.md`);入群自动比对并踢出,可选踢人时自动记录 |
30
30
  | **入群审核** | 新申请推送到群内,管理员用 `approve` / `reject` 放行或拒绝;待审单落盘,**重启不丢** |
31
31
  | **记忆库** | `[memory]` 保存 / 列出 / 查询 / 删除,落盘 `Memory.md`;开启后 AI 回复会检索并引用相关记忆 |
32
- | **AI 群聊回复** | 阈值 / 随机 / 混合三种触发,多人格、点名直触发、点名后话题跟随、兴趣分判定、上下文窗口、温度与输出上限 |
32
+ | **AI 群聊回复** | 三道闸门逐层收敛:①消息阈值 ②随机概率 ③兴趣评分,任一不过都不回复、也不调用模型;`@点名` 可越过全部闸门。多人格、点名后话题跟随、上下文窗口、温度与输出上限 |
33
33
  | **AI 识图** | 图片下载转 data URL 后送入模型,兼容 CQ 码 / HTML `<img>` / 元素三种形态与表情包 |
34
34
  | **复读** | 连续相同消息达阈值复读,支持图片引用回查;复读事件会进入 AI 上下文 |
35
35
  | **娱乐** | 自我约束(口球)与违规禁言惩罚,可开关与调节参数 |
@@ -102,8 +102,13 @@ npm i @nestim/koishi-plugin-qq-group-manager
102
102
  ## AI 回复与识图
103
103
 
104
104
  - **接口**:`openai-compatible`(OpenAI 兼容 Chat Completions)与 `gemini`(原生 `generateContent`)两类。
105
- - **触发**:`threshold`(累计消息达阈值)、`random`(按概率)、`hybrid`(两者同时生效);
106
- 消息中命中智能体自称或直接 `@bot` 时忽略阈值直接触发。
105
+ - **触发**:三道闸门依序判定,任一不过都不回复,也不会产生模型调用:
106
+ 1. `aiMessageThreshold` 消息阈值(`threshold` / `hybrid`)——累计未达阈值不触发,计数器在成功回复后清零;
107
+ 2. `aiRandomReplyProbability` 随机概率(`random` / `hybrid`)——每条消息掷一次骰,未掷中直接跳过;
108
+ 3. `aiInterestMinScore` 兴趣评分——调模型给消息打分,达标才回复。
109
+
110
+ `hybrid` 表示**两者都需满足**(先够消息数,再掷中概率)。消息中命中智能体自称或直接 `@bot` 时,
111
+ 越过上述全部闸门直接触发。
107
112
  - **多人格**:`aiPersonas` 保存多套「自称 + 系统提示词」,用 `aiActivePersona` 切换。
108
113
  - **识图**:开启 `aiEnableImageRecognition` 后,图片会下载并转为 data URL 再送入模型,
109
114
  不依赖模型侧访问 QQ 图链;兼容 CQ 码、HTML `<img>`、消息元素与表情包。