@nestim/koishi-plugin-qq-group-manager 1.4.6 → 1.4.8

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.
@@ -39,7 +39,7 @@ class ChatProvider {
39
39
  async chat(request) {
40
40
  if (!this.apiKey)
41
41
  return { ok: false, error: 'AI 未配置 apiKey' };
42
- if (!this.model)
42
+ if (!this.model && !String(request.model || '').trim())
43
43
  return { ok: false, error: 'AI 未配置 model' };
44
44
  const provider = String(this.config.aiProvider ?? 'openai-compatible');
45
45
  const requested = (request.images ?? []).filter((item) => /^data:image\//i.test(item) || /^https?:\/\//i.test(item));
@@ -77,6 +77,7 @@ class ChatProvider {
77
77
  }
78
78
  async callOpenAi(request, images, options = {}) {
79
79
  const base = String(this.config.aiBaseUrl || 'https://api.openai.com/v1').replace(/\/+$/, '');
80
+ const model = String(request.model || this.model).trim();
80
81
  const content = [{ type: 'text', text: request.user }];
81
82
  for (const url of images)
82
83
  content.push({ type: 'image_url', image_url: { url } });
@@ -92,7 +93,7 @@ class ChatProvider {
92
93
  'Content-Type': 'application/json',
93
94
  },
94
95
  body: JSON.stringify({
95
- model: this.model,
96
+ model,
96
97
  temperature: request.temperature ?? this.config.aiTemperature ?? 0.8,
97
98
  max_tokens: maxTokens,
98
99
  messages: [
@@ -143,7 +144,7 @@ class ChatProvider {
143
144
  error: `模型返回空内容(finish=${payload?.choices?.[0]?.finish_reason || 'unknown'})`,
144
145
  };
145
146
  }
146
- return { ok: true, text, status: response.status };
147
+ return { ok: true, text, status: response.status, usage: payload?.usage };
147
148
  }
148
149
  catch (error) {
149
150
  const aborted = error?.name === 'AbortError';
@@ -156,7 +157,8 @@ class ChatProvider {
156
157
  async callGemini(request, images) {
157
158
  const rawBase = String(this.config.aiBaseUrl || 'https://generativelanguage.googleapis.com/v1beta').replace(/\/+$/, '');
158
159
  const base = /\/v\d/i.test(rawBase) ? rawBase : `${rawBase}/v1beta`;
159
- const endpoint = `${base}/models/${encodeURIComponent(this.model)}:generateContent?key=${encodeURIComponent(this.apiKey)}`;
160
+ const model = String(request.model || this.model).trim();
161
+ const endpoint = `${base}/models/${encodeURIComponent(model)}:generateContent?key=${encodeURIComponent(this.apiKey)}`;
160
162
  const parts = [{ text: request.user }];
161
163
  for (const url of images) {
162
164
  const match = /^data:(image\/[^;]+);base64,(.*)$/i.exec(url);
@@ -193,7 +195,7 @@ class ChatProvider {
193
195
  .trim();
194
196
  if (!text)
195
197
  return { ok: false, status: response.status, error: 'Gemini 返回空内容' };
196
- return { ok: true, text, status: response.status };
198
+ return { ok: true, text, status: response.status, usage: payload?.usageMetadata };
197
199
  }
198
200
  catch (error) {
199
201
  const aborted = error?.name === 'AbortError';
package/lib/ai/state.d.ts CHANGED
@@ -39,6 +39,10 @@ export declare class GroupState {
39
39
  counter: number;
40
40
  lastReplyAt: number;
41
41
  lastAttemptAt: number;
42
+ /** 上次发「冷却中」提示的时间,用于避免 @ 刷屏时反复提示 */
43
+ lastCooldownNoticeAt: number;
44
+ /** 伪随机加成:随机未命中时累加,命中后归零 */
45
+ randomBoost: number;
42
46
  inFlight: boolean;
43
47
  followup: FollowupState | null;
44
48
  seen: Map<string, number>;
package/lib/ai/state.js CHANGED
@@ -15,6 +15,10 @@ class GroupState {
15
15
  counter = 0;
16
16
  lastReplyAt = 0;
17
17
  lastAttemptAt = 0;
18
+ /** 上次发「冷却中」提示的时间,用于避免 @ 刷屏时反复提示 */
19
+ lastCooldownNoticeAt = 0;
20
+ /** 伪随机加成:随机未命中时累加,命中后归零 */
21
+ randomBoost = 0;
18
22
  inFlight = false;
19
23
  followup = null;
20
24
  seen = new Map();
@@ -1,11 +1,12 @@
1
1
  /**
2
2
  * 触发放行判定(纯函数,便于单测)。
3
3
  *
4
- * 三道闸门保留,但语义收紧:
5
- * 1) 冷却:同一群两次"真正调用模型"之间至少间隔 aiMinReplyIntervalSeconds;
6
- * 2) 阈值:hybrid/threshold 下需累计够 aiMessageThreshold 条消息;
7
- * 3) 概率:random/hybrid 下每条消息掷一次骰。
8
- * 点名与"点名后跟随"直接放行(不占冷却)。
4
+ * 冷却的语义已经统一:**所有真正调用模型的行为**(含 @、点名后跟随)
5
+ * 都受同一个冷却约束,按「上一次调用模型的时刻」计算,而不是按
6
+ * 「上一次成功发出回复」——模型返回 <pass/>、被过滤器拦下、请求失败
7
+ * 都算用过一次,避免一直失败却一直重试。
8
+ *
9
+ * 被 @ 但仍在冷却里时返回 remainingMs,由引擎决定是否在群里提示还剩多久。
9
10
  */
10
11
  export interface TriggerInput {
11
12
  mode: 'threshold' | 'random' | 'hybrid';
@@ -15,18 +16,29 @@ export interface TriggerInput {
15
16
  now: number;
16
17
  lastAttemptAt: number;
17
18
  minIntervalMs: number;
18
- /** 上一次真正发出回复的时间(用于 @ 冷却) */
19
- lastReplyAt: number;
20
- /** 被 @ 后两次回复的最小间隔 */
21
- mentionCooldownMs: number;
19
+ /** 兼容字段:旧版按“上次回复”计算的 @ 冷却,已合并进 minIntervalMs */
20
+ lastReplyAt?: number;
21
+ mentionCooldownMs?: number;
22
22
  inFlight: boolean;
23
23
  mention: boolean;
24
24
  followup: boolean;
25
25
  rng: () => number;
26
+ /** 伪随机:随机未命中时把下一次概率往上抬,直到必定触发 */
27
+ pseudoRandom?: boolean;
28
+ /** 当前已累计的概率加成(0~1) */
29
+ randomBoost?: number;
30
+ /** 每次未命中增加多少(默认 0.01) */
31
+ pseudoRandomStep?: number;
26
32
  }
27
33
  export interface TriggerDecision {
28
34
  fire: boolean;
29
35
  forced: boolean;
30
36
  reason: string;
37
+ /** 冷却中时距离可以再次调用模型的剩余毫秒数 */
38
+ remainingMs?: number;
39
+ /** 本次判定后应保存的伪随机加成;未发生随机掷骰时为 undefined(保持不变) */
40
+ nextBoost?: number;
41
+ /** 本次实际使用的概率(基础值 + 加成),用于日志排查 */
42
+ effectiveProbability?: number;
31
43
  }
32
44
  export declare function decideTrigger(input: TriggerInput): TriggerDecision;
package/lib/ai/trigger.js CHANGED
@@ -2,29 +2,38 @@
2
2
  /**
3
3
  * 触发放行判定(纯函数,便于单测)。
4
4
  *
5
- * 三道闸门保留,但语义收紧:
6
- * 1) 冷却:同一群两次"真正调用模型"之间至少间隔 aiMinReplyIntervalSeconds;
7
- * 2) 阈值:hybrid/threshold 下需累计够 aiMessageThreshold 条消息;
8
- * 3) 概率:random/hybrid 下每条消息掷一次骰。
9
- * 点名与"点名后跟随"直接放行(不占冷却)。
5
+ * 冷却的语义已经统一:**所有真正调用模型的行为**(含 @、点名后跟随)
6
+ * 都受同一个冷却约束,按「上一次调用模型的时刻」计算,而不是按
7
+ * 「上一次成功发出回复」——模型返回 <pass/>、被过滤器拦下、请求失败
8
+ * 都算用过一次,避免一直失败却一直重试。
9
+ *
10
+ * 被 @ 但仍在冷却里时返回 remainingMs,由引擎决定是否在群里提示还剩多久。
10
11
  */
11
12
  Object.defineProperty(exports, "__esModule", { value: true });
12
13
  exports.decideTrigger = decideTrigger;
13
14
  function decideTrigger(input) {
14
15
  if (input.inFlight)
15
16
  return { fire: false, forced: false, reason: 'in-flight' };
16
- if (input.mention) {
17
- const cooldown = Math.max(0, Number(input.mentionCooldownMs) || 0);
18
- if (cooldown > 0 && input.now - (Number(input.lastReplyAt) || 0) < cooldown) {
19
- return { fire: false, forced: false, reason: 'mention-cooldown' };
17
+ // ---------- 1) 模型调用冷却:@ 也不能绕过 ----------
18
+ const cooldown = Math.max(0, Number(input.minIntervalMs) || 0);
19
+ const lastAttempt = Number(input.lastAttemptAt) || 0;
20
+ if (cooldown > 0 && lastAttempt > 0) {
21
+ const elapsed = input.now - lastAttempt;
22
+ if (elapsed < cooldown) {
23
+ return {
24
+ fire: false,
25
+ forced: false,
26
+ reason: input.mention ? 'cooldown-mention' : 'cooldown',
27
+ remainingMs: Math.max(0, cooldown - elapsed),
28
+ };
20
29
  }
21
- return { fire: true, forced: true, reason: 'direct-mention' };
22
30
  }
31
+ // ---------- 2) 点名与点名后跟随:越过阈值/概率,但不越过冷却 ----------
32
+ if (input.mention)
33
+ return { fire: true, forced: true, reason: 'direct-mention' };
23
34
  if (input.followup)
24
35
  return { fire: true, forced: true, reason: 'followup' };
25
- if (input.minIntervalMs > 0 && input.now - input.lastAttemptAt < input.minIntervalMs) {
26
- return { fire: false, forced: false, reason: 'cooldown' };
27
- }
36
+ // ---------- 3) 阈值 ----------
28
37
  const needThreshold = input.mode === 'threshold' || input.mode === 'hybrid';
29
38
  if (needThreshold && input.counter < Math.max(1, input.threshold)) {
30
39
  return {
@@ -33,14 +42,41 @@ function decideTrigger(input) {
33
42
  reason: `below-threshold(${input.counter}/${Math.max(1, input.threshold)})`,
34
43
  };
35
44
  }
45
+ // ---------- 4) 概率(支持伪随机:连续未命中会逐步抬高概率) ----------
36
46
  const needRandom = input.mode === 'random' || input.mode === 'hybrid';
37
47
  if (needRandom) {
38
- const probability = Math.max(0, Math.min(1, Number(input.probability) || 0));
39
- if (probability <= 0)
40
- return { fire: false, forced: false, reason: 'random-disabled' };
41
- if (input.rng() >= probability) {
42
- return { fire: false, forced: false, reason: `random-miss(${probability})` };
48
+ const base = Math.max(0, Math.min(1, Number(input.probability) || 0));
49
+ const boost = Math.max(0, Number(input.randomBoost) || 0);
50
+ const effective = Math.min(1, base + boost);
51
+ const round4 = (value) => Math.round(value * 10000) / 10000;
52
+ if (effective <= 0) {
53
+ return {
54
+ fire: false,
55
+ forced: false,
56
+ reason: 'random-disabled',
57
+ nextBoost: round4(boost),
58
+ effectiveProbability: 0,
59
+ };
60
+ }
61
+ // 加成到 1 时必定触发,不再消耗随机数
62
+ if (effective >= 1 || input.rng() < effective) {
63
+ return {
64
+ fire: true,
65
+ forced: false,
66
+ reason: `trigger(${input.mode})`,
67
+ nextBoost: 0,
68
+ effectiveProbability: round4(effective),
69
+ };
43
70
  }
71
+ const step = Math.max(0, Number(input.pseudoRandomStep) || 0);
72
+ const nextBoost = input.pseudoRandom ? Math.min(1, round4(boost + step)) : round4(boost);
73
+ return {
74
+ fire: false,
75
+ forced: false,
76
+ reason: `random-miss(${effective.toFixed(2)})`,
77
+ nextBoost,
78
+ effectiveProbability: round4(effective),
79
+ };
44
80
  }
45
81
  return { fire: true, forced: false, reason: `trigger(${input.mode})` };
46
82
  }
package/lib/index.d.ts CHANGED
@@ -25,6 +25,12 @@ export declare const Config: Schema<Schemastery.ObjectS<{
25
25
  groupRules: Schema<Schemastery.ObjectS<{
26
26
  guildId: Schema<string, string>;
27
27
  enableAiReply: Schema<boolean, boolean>;
28
+ aiMessageThreshold: Schema<number, number>;
29
+ aiRandomReplyProbability: Schema<number, number>;
30
+ aiPseudoRandom: Schema<boolean, boolean>;
31
+ aiPseudoRandomStep: Schema<number, number>;
32
+ aiMinReplyIntervalSeconds: Schema<number, number>;
33
+ aiCooldownNotice: Schema<boolean, boolean>;
28
34
  bannedWords: Schema<string[], string[]>;
29
35
  whitelistKeywords: Schema<string[], string[]>;
30
36
  strongKeywords: Schema<string[], string[]>;
@@ -44,6 +50,12 @@ export declare const Config: Schema<Schemastery.ObjectS<{
44
50
  }>[], Schemastery.ObjectT<{
45
51
  guildId: Schema<string, string>;
46
52
  enableAiReply: Schema<boolean, boolean>;
53
+ aiMessageThreshold: Schema<number, number>;
54
+ aiRandomReplyProbability: Schema<number, number>;
55
+ aiPseudoRandom: Schema<boolean, boolean>;
56
+ aiPseudoRandomStep: Schema<number, number>;
57
+ aiMinReplyIntervalSeconds: Schema<number, number>;
58
+ aiCooldownNotice: Schema<boolean, boolean>;
47
59
  bannedWords: Schema<string[], string[]>;
48
60
  whitelistKeywords: Schema<string[], string[]>;
49
61
  strongKeywords: Schema<string[], string[]>;
@@ -81,6 +93,11 @@ export declare const Config: Schema<Schemastery.ObjectS<{
81
93
  memoryLearnPushBack: Schema<boolean, boolean>;
82
94
  memoryLearnDuplicateThreshold: Schema<number, number>;
83
95
  memoryLearnDailyLimit: Schema<number, number>;
96
+ memoryLearnConsolidate: Schema<boolean, boolean>;
97
+ memoryLearnConsolidateEvery: Schema<number, number>;
98
+ memoryLearnMaxEntries: Schema<number, number>;
99
+ memoryLearnConsolidateMaxChars: Schema<number, number>;
100
+ memoryLearnModel: Schema<string, string>;
84
101
  }> | Schemastery.ObjectS<{
85
102
  enableBlacklist: Schema<boolean, boolean>;
86
103
  blacklistFileName: Schema<string, string>;
@@ -131,6 +148,9 @@ export declare const Config: Schema<Schemastery.ObjectS<{
131
148
  aiModel: Schema<string, string>;
132
149
  aiAgentName: Schema<string, string>;
133
150
  aiMentionCooldownSeconds: Schema<number, number>;
151
+ aiCooldownNotice: Schema<boolean, boolean>;
152
+ aiCooldownNoticeText: Schema<string, string>;
153
+ aiCooldownNoticeIntervalSeconds: Schema<number, number>;
134
154
  aiIdleTopicMinutes: Schema<number, number>;
135
155
  aiIdleTopicMinHour: Schema<number, number>;
136
156
  aiIdleTopicMaxHour: Schema<number, number>;
@@ -149,8 +169,12 @@ export declare const Config: Schema<Schemastery.ObjectS<{
149
169
  aiReplyMode: Schema<"threshold" | "random" | "hybrid", "threshold" | "random" | "hybrid">;
150
170
  aiMessageThreshold: Schema<number, number>;
151
171
  aiRandomReplyProbability: Schema<number, number>;
172
+ aiPseudoRandom: Schema<boolean, boolean>;
173
+ aiPseudoRandomStep: Schema<number, number>;
152
174
  aiMinReplyIntervalSeconds: Schema<number, number>;
153
175
  aiContextWindow: Schema<number, number>;
176
+ aiContextMaxChars: Schema<number, number>;
177
+ aiStyleMaxChars: Schema<number, number>;
154
178
  aiTemperature: Schema<number, number>;
155
179
  aiMaxOutputTokens: Schema<number, number>;
156
180
  aiMaxReplyChars: Schema<number, number>;
@@ -217,6 +241,12 @@ export declare const Config: Schema<Schemastery.ObjectS<{
217
241
  groupRules: Schemastery.ObjectT<{
218
242
  guildId: Schema<string, string>;
219
243
  enableAiReply: Schema<boolean, boolean>;
244
+ aiMessageThreshold: Schema<number, number>;
245
+ aiRandomReplyProbability: Schema<number, number>;
246
+ aiPseudoRandom: Schema<boolean, boolean>;
247
+ aiPseudoRandomStep: Schema<number, number>;
248
+ aiMinReplyIntervalSeconds: Schema<number, number>;
249
+ aiCooldownNotice: Schema<boolean, boolean>;
220
250
  bannedWords: Schema<string[], string[]>;
221
251
  whitelistKeywords: Schema<string[], string[]>;
222
252
  strongKeywords: Schema<string[], string[]>;
@@ -254,6 +284,11 @@ export declare const Config: Schema<Schemastery.ObjectS<{
254
284
  memoryLearnPushBack: boolean;
255
285
  memoryLearnDuplicateThreshold: number;
256
286
  memoryLearnDailyLimit: number;
287
+ memoryLearnConsolidate: boolean;
288
+ memoryLearnConsolidateEvery: number;
289
+ memoryLearnMaxEntries: number;
290
+ memoryLearnConsolidateMaxChars: number;
291
+ memoryLearnModel: string;
257
292
  } & {
258
293
  enableBlacklist: boolean;
259
294
  blacklistFileName: string;
@@ -295,6 +330,9 @@ export declare const Config: Schema<Schemastery.ObjectS<{
295
330
  aiModel: string;
296
331
  aiAgentName: string;
297
332
  aiMentionCooldownSeconds: number;
333
+ aiCooldownNotice: boolean;
334
+ aiCooldownNoticeText: string;
335
+ aiCooldownNoticeIntervalSeconds: number;
298
336
  aiIdleTopicMinutes: number;
299
337
  aiIdleTopicMinHour: number;
300
338
  aiIdleTopicMaxHour: number;
@@ -309,8 +347,12 @@ export declare const Config: Schema<Schemastery.ObjectS<{
309
347
  aiReplyMode: "threshold" | "random" | "hybrid";
310
348
  aiMessageThreshold: number;
311
349
  aiRandomReplyProbability: number;
350
+ aiPseudoRandom: boolean;
351
+ aiPseudoRandomStep: number;
312
352
  aiMinReplyIntervalSeconds: number;
313
353
  aiContextWindow: number;
354
+ aiContextMaxChars: number;
355
+ aiStyleMaxChars: number;
314
356
  aiTemperature: number;
315
357
  aiMaxOutputTokens: number;
316
358
  aiMaxReplyChars: number;
package/lib/index.js CHANGED
@@ -35,6 +35,12 @@ exports.Config = koishi_1.Schema.intersect([
35
35
  groupRules: koishi_1.Schema.array(koishi_1.Schema.object({
36
36
  guildId: koishi_1.Schema.string().required().description('群号。'),
37
37
  enableAiReply: koishi_1.Schema.boolean().description('该群是否启用 AI 回复(留空则跟随全局设置)。'),
38
+ aiMessageThreshold: koishi_1.Schema.natural().description('该群触发的消息数阈值(留空跟随全局 aiMessageThreshold)。'),
39
+ aiRandomReplyProbability: koishi_1.Schema.percent().description('该群随机触发概率(0~1,控制台按百分比显示;留空跟随全局)。'),
40
+ aiPseudoRandom: koishi_1.Schema.boolean().description('该群是否启用伪随机(连续未命中逐步提高概率;留空跟随全局)。'),
41
+ aiPseudoRandomStep: koishi_1.Schema.number().min(0).max(1).step(0.001).description('该群伪随机每次未命中增加的概率(留空跟随全局)。'),
42
+ aiMinReplyIntervalSeconds: koishi_1.Schema.natural().description('该群模型调用冷却(秒;留空跟随全局 aiMinReplyIntervalSeconds)。'),
43
+ aiCooldownNotice: koishi_1.Schema.boolean().description('该群被 @ 但处于冷却时是否提示还剩多久(留空跟随全局)。'),
38
44
  bannedWords: koishi_1.Schema.array(String).role('table').default([]).description('该群专属违禁词列表(同样支持“关键词|分值”与顺序模糊匹配)。'),
39
45
  whitelistKeywords: koishi_1.Schema.array(String).role('table').default([]).description('该群违禁词白名单:消息只要命中其中任意一个关键词,就整条跳过违禁词评分(用于校学生会招新等允许的宣传场景)。'),
40
46
  strongKeywords: koishi_1.Schema.array(String).role('table').description('该群强关键词(留空则跟随全局设置)。命中后无视白名单豁免,用于堵住「附一个白名单词即可绕过管控」的漏洞。'),
@@ -74,6 +80,11 @@ exports.Config = koishi_1.Schema.intersect([
74
80
  memoryLearnPushBack: koishi_1.Schema.boolean().default(true).description('归纳后把结果回推到原会话:私聊发私聊、群聊发对应群。'),
75
81
  memoryLearnDuplicateThreshold: koishi_1.Schema.number().min(0.3).max(0.95).step(0.05).default(0.55).description('与已有记忆相似度超过该值就跳过,避免同一件事反复记。'),
76
82
  memoryLearnDailyLimit: koishi_1.Schema.natural().min(1).max(200).default(30).description('每个作用域每天最多归纳几次,防止刷模型额度。'),
83
+ memoryLearnConsolidate: koishi_1.Schema.boolean().default(true).description('自动归纳压缩:每累计 N 条就合并成一条更短的记忆,避免记忆越堆越长、反复占用提示词。'),
84
+ memoryLearnConsolidateEvery: koishi_1.Schema.natural().min(2).max(20).default(5).description('每多少条自动记忆压缩一次(默认 5)。'),
85
+ memoryLearnMaxEntries: koishi_1.Schema.natural().min(1).max(100).default(15).description('自动归纳记忆的条数上限(不含手动 [memory] 保存的内容);超过后会强制压缩。'),
86
+ memoryLearnConsolidateMaxChars: koishi_1.Schema.natural().min(40).max(300).default(90).description('压缩后单条记忆的字数上限。'),
87
+ memoryLearnModel: koishi_1.Schema.string().default('').description('自动归纳/压缩使用的模型(留空沿用 aiModel)。可用更便宜的模型降低开销。'),
77
88
  }).description('记忆库'),
78
89
  koishi_1.Schema.object({
79
90
  enableBlacklist: koishi_1.Schema.boolean().default(true).description('全局黑名单系统开关。单个群未单独设置时跟随此值;单个群设置后以该群为准(全局关着也能为某群单独开启)。'),
@@ -122,7 +133,10 @@ exports.Config = koishi_1.Schema.intersect([
122
133
  aiBaseUrl: koishi_1.Schema.string().default('https://api.openai.com/v1').description('接口基础地址(OpenAI 兼容模式需以 /v1 结尾;Gemini 模式可留默认)。'),
123
134
  aiModel: koishi_1.Schema.string().default('gpt-4o-mini').description('模型名称,如 gpt-4o-mini / doubao-1.5-lite / gemini-2.0-flash。'),
124
135
  aiAgentName: koishi_1.Schema.string().default('bot').description('默认智能体自称(可在配置页修改)。'),
125
- aiMentionCooldownSeconds: koishi_1.Schema.natural().min(0).max(3600).default(5).description('被 @ 后两次回复的最小间隔(秒),防止连续 @ 刷屏。'),
136
+ aiMentionCooldownSeconds: koishi_1.Schema.natural().min(0).max(3600).default(5).description('(兼容字段)旧的 @ 冷却;现在所有模型调用统一走 aiMinReplyIntervalSeconds。'),
137
+ aiCooldownNotice: koishi_1.Schema.boolean().default(true).description('被 @ 但处于模型调用冷却时,是否在群里提示还剩多久(纯本地消息,不调用模型)。'),
138
+ aiCooldownNoticeText: koishi_1.Schema.string().default('还在冷却,{seconds} 秒后再叫我。').description('冷却提示文案,可用 {seconds} 与 {minutes} 占位。'),
139
+ aiCooldownNoticeIntervalSeconds: koishi_1.Schema.natural().min(0).max(600).default(20).description('同一群两次冷却提示的最小间隔(秒),防止连续 @ 刷屏;0 = 不限制。'),
126
140
  aiIdleTopicMinutes: koishi_1.Schema.natural().min(0).max(1440).default(120).description('群内无消息多少分钟后主动抛话题;0=关闭。'),
127
141
  aiIdleTopicMinHour: koishi_1.Schema.natural().min(0).max(23).default(9).description('主动话题允许的最早小时(0-23)。'),
128
142
  aiIdleTopicMaxHour: koishi_1.Schema.natural().min(0).max(24).default(23).description('主动话题允许的最晚小时(不含)。'),
@@ -141,8 +155,12 @@ exports.Config = koishi_1.Schema.intersect([
141
155
  ]).role('radio').default('hybrid').description('AI 触发策略:threshold 只看消息数、random 只看概率、hybrid 两者都要满足。@点名与点名后跟随会越过这些闸门。是否真正接话由模型在回复时用 <pass/> 自行决定。'),
142
156
  aiMessageThreshold: koishi_1.Schema.natural().default(16).description('阈值触发所需累计消息数。threshold / hybrid 模式下未达此数一律不触发;计数器在模型给出回复或主动放弃后清零。'),
143
157
  aiRandomReplyProbability: koishi_1.Schema.percent().default(0.08).description('随机触发概率(每条消息掷一次骰)。random / hybrid 模式下未掷中直接跳过,不会调用 AI 接口。填 0 等同于关闭随机触发。'),
158
+ aiPseudoRandom: koishi_1.Schema.boolean().default(true).description('伪随机:随机触发没命中时,下一次概率按步长累加(命中后归零),加到 1 时必定回复,避免真随机长期不触发。'),
159
+ aiPseudoRandomStep: koishi_1.Schema.number().min(0).max(1).step(0.001).default(0.01).description('伪随机每次未命中增加的概率(默认 0.01 = 1%)。只在真正掷骰且未命中时累加,冷却/阈值跳过不算。'),
144
160
  aiMinReplyIntervalSeconds: koishi_1.Schema.natural().default(45).description('同一群两次真正调用模型的最短间隔(秒)。'),
145
161
  aiContextWindow: koishi_1.Schema.natural().default(30).description('参与推理的最近消息条数(建议 20~40;太小会导致模型看不到前文)。'),
162
+ aiContextMaxChars: koishi_1.Schema.natural().min(0).max(20000).default(0).description('历史上下文的字数上限:超过后从最旧的消息开始丢(至少保留最近 4 条)。0 = 不限。想省 token 可设 2500~3500。'),
163
+ aiStyleMaxChars: koishi_1.Schema.natural().min(0).max(20000).default(0).description('外部插件注入的「说话风格」段每条最多保留多少字。0 = 不限。风格 skill 很长时可设 1200~1800 显著省 token。'),
146
164
  aiTemperature: koishi_1.Schema.number().min(0).max(2).step(0.1).default(0.8).description('生成温度(0~2)。群聊接话建议 0.7~0.9,过高会跑题、复述、发散。'),
147
165
  aiMaxOutputTokens: koishi_1.Schema.natural().default(400).description('AI 最大输出 token 数。群聊一句话不需要太大,过大会增加延迟。'),
148
166
  aiMaxReplyChars: koishi_1.Schema.natural().min(20).max(500).default(120).description('单条回复的最大字符数,超出会在句末截断。'),
package/lib/service.d.ts CHANGED
@@ -226,6 +226,11 @@ export class QQGroupManagerService extends koishi_1.Service<any, koishi_1.Contex
226
226
  kind: "group" | "private";
227
227
  id: string;
228
228
  } | null, label?: string): Promise<any>;
229
+ /**
230
+ * 自动归纳专用写入:追加一条新记忆,并可同时删掉若干旧条目。
231
+ * 用于「每 N 条压缩成 1 条」——remove 里的旧条目会被新条目替换。
232
+ */
233
+ commitAutoMemory(scope: any, payload: any): Promise<any>;
229
234
  searchMemory(keyword: any, limit: number, scope: any): Promise<string[]>;
230
235
  /** 按关键词删除记忆条目(含该关键词的整条记忆块)。返回 { ok, removed, message } */
231
236
  deleteMemoryByKeyword(keyword: any, scope: any): Promise<any>;
@@ -352,6 +357,8 @@ export class QQGroupManagerService extends koishi_1.Service<any, koishi_1.Contex
352
357
  resolveImage(ref: any, session: any): Promise<any>;
353
358
  /** AI 回复发送:按 aiQuoteReplyMode 决定是否引用触发消息,失败则退化为纯文本 */
354
359
  sendReply(session: any, text: any): Promise<void>;
360
+ /** 系统提示(例如「冷却中」),不引用原消息、不写入 AI 上下文 */
361
+ sendNotice(session: any, text: any): Promise<void>;
355
362
  extractTextForFilter(session: any): any;
356
363
  hasTextContent(session: any): boolean;
357
364
  hasImageOrFace(session: any): any;
package/lib/service.js CHANGED
@@ -887,6 +887,42 @@ class QQGroupManagerService extends koishi_1.Service {
887
887
  return block;
888
888
  });
889
889
  }
890
+ /**
891
+ * 自动归纳专用写入:追加一条新记忆,并可同时删掉若干旧条目。
892
+ * 用于「每 N 条压缩成 1 条」——remove 里的旧条目会被新条目替换。
893
+ */
894
+ async commitAutoMemory(scope, payload) {
895
+ const add = String(payload && payload.add || '').trim();
896
+ if (!add)
897
+ return null;
898
+ const remove = new Set((payload && payload.remove || [])
899
+ .map((item) => String(item || '').trim())
900
+ .filter(Boolean));
901
+ const label = String(payload && payload.label || '自动归纳');
902
+ return this.runMemoryWriteLocked(async () => {
903
+ const now = new Date();
904
+ const stamp = now.toLocaleString('zh-CN', { hour12: false });
905
+ const block = `## ${stamp} · ${label}\n${add}`;
906
+ const existing = (await this.readMemoryFile(scope)).trim();
907
+ const blocks = this.extractMemoryBlocks(existing);
908
+ const kept = [];
909
+ let insertAt = -1;
910
+ for (const item of blocks) {
911
+ if (remove.has(item)) {
912
+ if (insertAt < 0)
913
+ insertAt = kept.length;
914
+ continue;
915
+ }
916
+ kept.push(item);
917
+ }
918
+ if (insertAt < 0)
919
+ insertAt = kept.length;
920
+ kept.splice(insertAt, 0, block);
921
+ const next = kept.length ? `${kept.join('\n\n---\n\n')}\n` : `${block}\n`;
922
+ await this.writeMemoryFile(next, scope);
923
+ return block;
924
+ });
925
+ }
890
926
  async searchMemory(keyword, limit = 8, scope) {
891
927
  const blocks = this.extractMemoryBlocks(await this.readMemoryFile(scope));
892
928
  const kw = String(keyword || '').trim();
@@ -2173,6 +2209,12 @@ class QQGroupManagerService extends koishi_1.Service {
2173
2209
  }
2174
2210
  await session.send(koishi_1.h.text(text));
2175
2211
  }
2212
+ /** 系统提示(例如「冷却中」),不引用原消息、不写入 AI 上下文 */
2213
+ async sendNotice(session, text) {
2214
+ if (!text)
2215
+ return;
2216
+ await session.send(koishi_1.h.text(String(text)));
2217
+ }
2176
2218
  extractTextForFilter(session) {
2177
2219
  const raw = (session.content ?? '')
2178
2220
  .replace(/<[^>]+>/g, ' ')
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.4.6",
4
+ "version": "1.4.8",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [