@nestim/koishi-plugin-qq-group-manager 1.2.1 → 1.2.3

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,8 +2,30 @@
2
2
 
3
3
  本文件记录所有值得注意的变更。版本号遵循 [语义化版本](https://semver.org/lang/zh-CN/)。
4
4
 
5
+ ## 1.2.3
6
+
7
+ ### 修复
8
+
9
+ - **续聊(followup)触发过宽**:用户换话题后,像“操不会说话了”这种短句仍会被当成
10
+ “接着上一轮说”,导致机器人追着自己的旧话题自说自话。
11
+ 现在必须满足“与上一轮有话题交集”或“明确追问词(展开/细说/然后/为什么…)”才续聊,
12
+ 否则直接清掉待续状态,按新消息重新判断。
13
+
14
+ ## 1.2.2
15
+
16
+ ### 修复
17
+
18
+ - **1.2.1 的 `aiHooks` 对兄弟插件不可达**:Koishi 的 `Service` 注册在插件 fork 作用域,
19
+ 外部插件 `inject: ['nestimQqGroupManager']` 拿不到,导致风格插件静默不生效。
20
+ 现在额外把扩展点挂到 root 的 `qqgmAiHooks`,外部插件 `inject: ['qqgmAiHooks']` 即可;
21
+ `ctx.nestimQqGroupManager.aiHooks` 仍保留,供同进程直接访问。
22
+ - 配套的 `koishi-plugin-qqgm-chat-style` 改为注入 `qqgmAiHooks`。
23
+
5
24
  ## 1.2.1
6
25
 
26
+ > **本版新增外部插件接口 `aiHooks`。** 第三方 Koishi 插件可以给 AI 追加“说话风格”提示词,
27
+ > 并在发送前过滤/丢弃输出,不需要改主插件,也不需要发新版本。
28
+
7
29
  ### 新增
8
30
 
9
31
  - **AI 扩展点 `aiHooks`(接口版本 1)**:外部 Koishi 插件可以在不改主插件代码的前提下
@@ -16,6 +38,25 @@
16
38
  - 配套本地插件(不发布 npm):`koishi-plugin-qqgm-chat-style`,用于加载
17
39
  `.skill/SKILL.md`(仅接受聊天风格类),并做限字数、限行数、删禁词等输出规范。
18
40
 
41
+ ### 外部接口示例
42
+
43
+ ```ts
44
+ export const inject = ['nestimQqGroupManager']
45
+
46
+ export function apply(ctx) {
47
+ const hooks = ctx.nestimQqGroupManager.aiHooks
48
+ if (!hooks) return
49
+
50
+ const off1 = hooks.registerPromptSection(() => '说话短一点,别用“首先/其次”这类词')
51
+ const off2 = hooks.registerOutputFilter((text) => text.replace(/首先/g, ''))
52
+
53
+ ctx.on('dispose', () => {
54
+ off1()
55
+ off2()
56
+ })
57
+ }
58
+ ```
59
+
19
60
  ### 说明
20
61
 
21
62
  - 无配置变更,旧版本行为不变;不安装风格插件时 `aiHooks` 只是空注册表。
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'),
package/lib/service.js CHANGED
@@ -185,6 +185,21 @@ class QQGroupManagerService extends koishi_1.Service {
185
185
  this.config = config;
186
186
  this._logger = ctx.logger('nestim-qq-group-manager');
187
187
  this.ai = new AiEngine(this);
188
+ // Koishi 的 Service 注册在插件 fork 作用域,兄弟插件的 inject 拿不到;
189
+ // 额外把扩展点挂到 root,外部插件 inject 'qqgmAiHooks' 即可。
190
+ try {
191
+ ctx.root.set('qqgmAiHooks', this.ai.hooks);
192
+ ctx.on('dispose', () => {
193
+ try {
194
+ if (ctx.root.get('qqgmAiHooks') === this.ai.hooks)
195
+ ctx.root.set('qqgmAiHooks', undefined);
196
+ }
197
+ catch { /* ignore */ }
198
+ });
199
+ }
200
+ catch (error) {
201
+ this._logger.warn(`[aiHooks] 暴露到 root 失败: ${String(error)}`);
202
+ }
188
203
  this._logger.info(`[qqgm] v${PLUGIN_VERSION} 已加载 | ai=single-call+pass | ctx=${this.config.aiContextWindow || 30}`);
189
204
  ctx.on('message', (session) => this.handleGroupModeration(session));
190
205
  ctx.on('guild-member-request', (session) => this.handleGuildMemberRequest(session));
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.1",
4
+ "version": "1.2.3",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
package/readme.md CHANGED
@@ -131,8 +131,37 @@ npm i @nestim/koishi-plugin-qq-group-manager
131
131
  - **调试**:`aiDebugPrompt` 打开后会把最终提示词写进日志,便于排查"到底看到了什么"。
132
132
  - **扩展点**:`ctx.nestimQqGroupManager.aiHooks`(接口版本 1)。外部插件可
133
133
  `registerPromptSection()` 追加风格段、`registerOutputFilter()` 过滤或丢弃输出;
134
- 钩子异常会被隔离,不影响正常回复。配套的本地风格插件 `koishi-plugin-qqgm-chat-style`
135
- 不随本包发布,按需单独部署。
134
+ 钩子异常会被隔离,不影响正常回复。跨插件使用时请注入 root 上的 `qqgmAiHooks`。
135
+ 配套的本地风格插件 `koishi-plugin-qqgm-chat-style` 不随本包发布,按需单独部署。
136
+
137
+ ## 外部插件接口(1.2.2+)
138
+
139
+ 主插件暴露一个很小的扩展点,第三方插件可以给 AI 追加“说话风格”,或在发送前过滤输出,
140
+ 不需要修改主插件源码:
141
+
142
+ ```ts
143
+ export const inject = ['qqgmAiHooks']
144
+
145
+ export function apply(ctx) {
146
+ const hooks = ctx.qqgmAiHooks
147
+ if (!hooks) return
148
+
149
+ // 追加到 system prompt 的【说话风格】段
150
+ const off1 = hooks.registerPromptSection(() => '说话短一点,别用“首先/其次”这类词')
151
+
152
+ // 发送前过滤;返回 null 表示这条不发(按 pass 处理)
153
+ const off2 = hooks.registerOutputFilter((text) => text.replace(/首先/g, ''))
154
+
155
+ ctx.on('dispose', () => {
156
+ off1()
157
+ off2()
158
+ })
159
+ }
160
+ ```
161
+
162
+ - 风格段插在基础规则之后、`<pass/>` 规则之前,并声明“与系统规则冲突时以系统规则为准”。
163
+ - 过滤器按注册顺序执行,异常会被隔离;过滤后的文本才会写回上下文。
164
+ - `hooks.version` 目前为 `1`,外部插件应先检查版本。
136
165
 
137
166
 
138
167
  ## 数据文件
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({
package/src/service.js CHANGED
@@ -186,6 +186,21 @@ class QQGroupManagerService extends koishi_1.Service {
186
186
  this.config = config;
187
187
  this._logger = ctx.logger('nestim-qq-group-manager');
188
188
  this.ai = new AiEngine(this);
189
+ // Koishi 的 Service 注册在插件 fork 作用域,兄弟插件的 inject 拿不到;
190
+ // 额外把扩展点挂到 root,外部插件 inject 'qqgmAiHooks' 即可。
191
+ try {
192
+ ctx.root.set('qqgmAiHooks', this.ai.hooks);
193
+ ctx.on('dispose', () => {
194
+ try {
195
+ if (ctx.root.get('qqgmAiHooks') === this.ai.hooks)
196
+ ctx.root.set('qqgmAiHooks', undefined);
197
+ }
198
+ catch { /* ignore */ }
199
+ });
200
+ }
201
+ catch (error) {
202
+ this._logger.warn(`[aiHooks] 暴露到 root 失败: ${String(error)}`);
203
+ }
189
204
  this._logger.info(`[qqgm] v${PLUGIN_VERSION} 已加载 | ai=single-call+pass | ctx=${this.config.aiContextWindow || 30}`);
190
205
  ctx.on('message', (session) => this.handleGroupModeration(session));
191
206
  ctx.on('guild-member-request', (session) => this.handleGuildMemberRequest(session));