@nestim/koishi-plugin-qq-group-manager 1.4.6 → 1.4.7
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 +47 -0
- package/lib/ai/engine.d.ts +40 -1
- package/lib/ai/engine.js +203 -20
- package/lib/ai/learn.d.ts +19 -0
- package/lib/ai/learn.js +50 -1
- package/lib/ai/provider.d.ts +4 -0
- package/lib/ai/provider.js +7 -5
- package/lib/ai/state.d.ts +2 -0
- package/lib/ai/state.js +2 -0
- package/lib/ai/trigger.d.ts +11 -9
- package/lib/ai/trigger.js +23 -13
- package/lib/index.d.ts +32 -0
- package/lib/index.js +15 -1
- package/lib/service.d.ts +7 -0
- package/lib/service.js +42 -0
- package/package.json +1 -1
- package/src/ai/engine.ts +236 -25
- package/src/ai/learn.ts +56 -0
- package/src/ai/provider.ts +11 -5
- package/src/ai/state.ts +2 -0
- package/src/ai/trigger.ts +28 -18
- package/src/index.ts +16 -2
- package/src/service.js +42 -0
package/lib/ai/trigger.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 触发放行判定(纯函数,便于单测)。
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* 冷却的语义已经统一:**所有真正调用模型的行为**(含 @、点名后跟随)
|
|
5
|
+
* 都受同一个冷却约束,按「上一次调用模型的时刻」计算,而不是按
|
|
6
|
+
* 「上一次成功发出回复」——模型返回 <pass/>、被过滤器拦下、请求失败
|
|
7
|
+
* 都算用过一次,避免一直失败却一直重试。
|
|
8
|
+
*
|
|
9
|
+
* 被 @ 但仍在冷却里时返回 remainingMs,由引擎决定是否在群里提示还剩多久。
|
|
9
10
|
*/
|
|
10
11
|
export interface TriggerInput {
|
|
11
12
|
mode: 'threshold' | 'random' | 'hybrid';
|
|
@@ -15,10 +16,9 @@ export interface TriggerInput {
|
|
|
15
16
|
now: number;
|
|
16
17
|
lastAttemptAt: number;
|
|
17
18
|
minIntervalMs: number;
|
|
18
|
-
/**
|
|
19
|
-
lastReplyAt
|
|
20
|
-
|
|
21
|
-
mentionCooldownMs: number;
|
|
19
|
+
/** 兼容字段:旧版按“上次回复”计算的 @ 冷却,已合并进 minIntervalMs */
|
|
20
|
+
lastReplyAt?: number;
|
|
21
|
+
mentionCooldownMs?: number;
|
|
22
22
|
inFlight: boolean;
|
|
23
23
|
mention: boolean;
|
|
24
24
|
followup: boolean;
|
|
@@ -28,5 +28,7 @@ export interface TriggerDecision {
|
|
|
28
28
|
fire: boolean;
|
|
29
29
|
forced: boolean;
|
|
30
30
|
reason: string;
|
|
31
|
+
/** 冷却中时距离可以再次调用模型的剩余毫秒数 */
|
|
32
|
+
remainingMs?: number;
|
|
31
33
|
}
|
|
32
34
|
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
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
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,6 +42,7 @@ 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
48
|
const probability = Math.max(0, Math.min(1, Number(input.probability) || 0));
|
package/lib/index.d.ts
CHANGED
|
@@ -25,6 +25,10 @@ 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
|
+
aiMinReplyIntervalSeconds: Schema<number, number>;
|
|
31
|
+
aiCooldownNotice: Schema<boolean, boolean>;
|
|
28
32
|
bannedWords: Schema<string[], string[]>;
|
|
29
33
|
whitelistKeywords: Schema<string[], string[]>;
|
|
30
34
|
strongKeywords: Schema<string[], string[]>;
|
|
@@ -44,6 +48,10 @@ export declare const Config: Schema<Schemastery.ObjectS<{
|
|
|
44
48
|
}>[], Schemastery.ObjectT<{
|
|
45
49
|
guildId: Schema<string, string>;
|
|
46
50
|
enableAiReply: Schema<boolean, boolean>;
|
|
51
|
+
aiMessageThreshold: Schema<number, number>;
|
|
52
|
+
aiRandomReplyProbability: Schema<number, number>;
|
|
53
|
+
aiMinReplyIntervalSeconds: Schema<number, number>;
|
|
54
|
+
aiCooldownNotice: Schema<boolean, boolean>;
|
|
47
55
|
bannedWords: Schema<string[], string[]>;
|
|
48
56
|
whitelistKeywords: Schema<string[], string[]>;
|
|
49
57
|
strongKeywords: Schema<string[], string[]>;
|
|
@@ -81,6 +89,11 @@ export declare const Config: Schema<Schemastery.ObjectS<{
|
|
|
81
89
|
memoryLearnPushBack: Schema<boolean, boolean>;
|
|
82
90
|
memoryLearnDuplicateThreshold: Schema<number, number>;
|
|
83
91
|
memoryLearnDailyLimit: Schema<number, number>;
|
|
92
|
+
memoryLearnConsolidate: Schema<boolean, boolean>;
|
|
93
|
+
memoryLearnConsolidateEvery: Schema<number, number>;
|
|
94
|
+
memoryLearnMaxEntries: Schema<number, number>;
|
|
95
|
+
memoryLearnConsolidateMaxChars: Schema<number, number>;
|
|
96
|
+
memoryLearnModel: Schema<string, string>;
|
|
84
97
|
}> | Schemastery.ObjectS<{
|
|
85
98
|
enableBlacklist: Schema<boolean, boolean>;
|
|
86
99
|
blacklistFileName: Schema<string, string>;
|
|
@@ -131,6 +144,9 @@ export declare const Config: Schema<Schemastery.ObjectS<{
|
|
|
131
144
|
aiModel: Schema<string, string>;
|
|
132
145
|
aiAgentName: Schema<string, string>;
|
|
133
146
|
aiMentionCooldownSeconds: Schema<number, number>;
|
|
147
|
+
aiCooldownNotice: Schema<boolean, boolean>;
|
|
148
|
+
aiCooldownNoticeText: Schema<string, string>;
|
|
149
|
+
aiCooldownNoticeIntervalSeconds: Schema<number, number>;
|
|
134
150
|
aiIdleTopicMinutes: Schema<number, number>;
|
|
135
151
|
aiIdleTopicMinHour: Schema<number, number>;
|
|
136
152
|
aiIdleTopicMaxHour: Schema<number, number>;
|
|
@@ -151,6 +167,8 @@ export declare const Config: Schema<Schemastery.ObjectS<{
|
|
|
151
167
|
aiRandomReplyProbability: Schema<number, number>;
|
|
152
168
|
aiMinReplyIntervalSeconds: Schema<number, number>;
|
|
153
169
|
aiContextWindow: Schema<number, number>;
|
|
170
|
+
aiContextMaxChars: Schema<number, number>;
|
|
171
|
+
aiStyleMaxChars: Schema<number, number>;
|
|
154
172
|
aiTemperature: Schema<number, number>;
|
|
155
173
|
aiMaxOutputTokens: Schema<number, number>;
|
|
156
174
|
aiMaxReplyChars: Schema<number, number>;
|
|
@@ -217,6 +235,10 @@ export declare const Config: Schema<Schemastery.ObjectS<{
|
|
|
217
235
|
groupRules: Schemastery.ObjectT<{
|
|
218
236
|
guildId: Schema<string, string>;
|
|
219
237
|
enableAiReply: Schema<boolean, boolean>;
|
|
238
|
+
aiMessageThreshold: Schema<number, number>;
|
|
239
|
+
aiRandomReplyProbability: Schema<number, number>;
|
|
240
|
+
aiMinReplyIntervalSeconds: Schema<number, number>;
|
|
241
|
+
aiCooldownNotice: Schema<boolean, boolean>;
|
|
220
242
|
bannedWords: Schema<string[], string[]>;
|
|
221
243
|
whitelistKeywords: Schema<string[], string[]>;
|
|
222
244
|
strongKeywords: Schema<string[], string[]>;
|
|
@@ -254,6 +276,11 @@ export declare const Config: Schema<Schemastery.ObjectS<{
|
|
|
254
276
|
memoryLearnPushBack: boolean;
|
|
255
277
|
memoryLearnDuplicateThreshold: number;
|
|
256
278
|
memoryLearnDailyLimit: number;
|
|
279
|
+
memoryLearnConsolidate: boolean;
|
|
280
|
+
memoryLearnConsolidateEvery: number;
|
|
281
|
+
memoryLearnMaxEntries: number;
|
|
282
|
+
memoryLearnConsolidateMaxChars: number;
|
|
283
|
+
memoryLearnModel: string;
|
|
257
284
|
} & {
|
|
258
285
|
enableBlacklist: boolean;
|
|
259
286
|
blacklistFileName: string;
|
|
@@ -295,6 +322,9 @@ export declare const Config: Schema<Schemastery.ObjectS<{
|
|
|
295
322
|
aiModel: string;
|
|
296
323
|
aiAgentName: string;
|
|
297
324
|
aiMentionCooldownSeconds: number;
|
|
325
|
+
aiCooldownNotice: boolean;
|
|
326
|
+
aiCooldownNoticeText: string;
|
|
327
|
+
aiCooldownNoticeIntervalSeconds: number;
|
|
298
328
|
aiIdleTopicMinutes: number;
|
|
299
329
|
aiIdleTopicMinHour: number;
|
|
300
330
|
aiIdleTopicMaxHour: number;
|
|
@@ -311,6 +341,8 @@ export declare const Config: Schema<Schemastery.ObjectS<{
|
|
|
311
341
|
aiRandomReplyProbability: number;
|
|
312
342
|
aiMinReplyIntervalSeconds: number;
|
|
313
343
|
aiContextWindow: number;
|
|
344
|
+
aiContextMaxChars: number;
|
|
345
|
+
aiStyleMaxChars: number;
|
|
314
346
|
aiTemperature: number;
|
|
315
347
|
aiMaxOutputTokens: number;
|
|
316
348
|
aiMaxReplyChars: number;
|
package/lib/index.js
CHANGED
|
@@ -35,6 +35,10 @@ 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
|
+
aiMinReplyIntervalSeconds: koishi_1.Schema.natural().description('该群模型调用冷却(秒;留空跟随全局 aiMinReplyIntervalSeconds)。'),
|
|
41
|
+
aiCooldownNotice: koishi_1.Schema.boolean().description('该群被 @ 但处于冷却时是否提示还剩多久(留空跟随全局)。'),
|
|
38
42
|
bannedWords: koishi_1.Schema.array(String).role('table').default([]).description('该群专属违禁词列表(同样支持“关键词|分值”与顺序模糊匹配)。'),
|
|
39
43
|
whitelistKeywords: koishi_1.Schema.array(String).role('table').default([]).description('该群违禁词白名单:消息只要命中其中任意一个关键词,就整条跳过违禁词评分(用于校学生会招新等允许的宣传场景)。'),
|
|
40
44
|
strongKeywords: koishi_1.Schema.array(String).role('table').description('该群强关键词(留空则跟随全局设置)。命中后无视白名单豁免,用于堵住「附一个白名单词即可绕过管控」的漏洞。'),
|
|
@@ -74,6 +78,11 @@ exports.Config = koishi_1.Schema.intersect([
|
|
|
74
78
|
memoryLearnPushBack: koishi_1.Schema.boolean().default(true).description('归纳后把结果回推到原会话:私聊发私聊、群聊发对应群。'),
|
|
75
79
|
memoryLearnDuplicateThreshold: koishi_1.Schema.number().min(0.3).max(0.95).step(0.05).default(0.55).description('与已有记忆相似度超过该值就跳过,避免同一件事反复记。'),
|
|
76
80
|
memoryLearnDailyLimit: koishi_1.Schema.natural().min(1).max(200).default(30).description('每个作用域每天最多归纳几次,防止刷模型额度。'),
|
|
81
|
+
memoryLearnConsolidate: koishi_1.Schema.boolean().default(true).description('自动归纳压缩:每累计 N 条就合并成一条更短的记忆,避免记忆越堆越长、反复占用提示词。'),
|
|
82
|
+
memoryLearnConsolidateEvery: koishi_1.Schema.natural().min(2).max(20).default(5).description('每多少条自动记忆压缩一次(默认 5)。'),
|
|
83
|
+
memoryLearnMaxEntries: koishi_1.Schema.natural().min(1).max(100).default(15).description('自动归纳记忆的条数上限(不含手动 [memory] 保存的内容);超过后会强制压缩。'),
|
|
84
|
+
memoryLearnConsolidateMaxChars: koishi_1.Schema.natural().min(40).max(300).default(90).description('压缩后单条记忆的字数上限。'),
|
|
85
|
+
memoryLearnModel: koishi_1.Schema.string().default('').description('自动归纳/压缩使用的模型(留空沿用 aiModel)。可用更便宜的模型降低开销。'),
|
|
77
86
|
}).description('记忆库'),
|
|
78
87
|
koishi_1.Schema.object({
|
|
79
88
|
enableBlacklist: koishi_1.Schema.boolean().default(true).description('全局黑名单系统开关。单个群未单独设置时跟随此值;单个群设置后以该群为准(全局关着也能为某群单独开启)。'),
|
|
@@ -122,7 +131,10 @@ exports.Config = koishi_1.Schema.intersect([
|
|
|
122
131
|
aiBaseUrl: koishi_1.Schema.string().default('https://api.openai.com/v1').description('接口基础地址(OpenAI 兼容模式需以 /v1 结尾;Gemini 模式可留默认)。'),
|
|
123
132
|
aiModel: koishi_1.Schema.string().default('gpt-4o-mini').description('模型名称,如 gpt-4o-mini / doubao-1.5-lite / gemini-2.0-flash。'),
|
|
124
133
|
aiAgentName: koishi_1.Schema.string().default('bot').description('默认智能体自称(可在配置页修改)。'),
|
|
125
|
-
aiMentionCooldownSeconds: koishi_1.Schema.natural().min(0).max(3600).default(5).description('
|
|
134
|
+
aiMentionCooldownSeconds: koishi_1.Schema.natural().min(0).max(3600).default(5).description('(兼容字段)旧的 @ 冷却;现在所有模型调用统一走 aiMinReplyIntervalSeconds。'),
|
|
135
|
+
aiCooldownNotice: koishi_1.Schema.boolean().default(true).description('被 @ 但处于模型调用冷却时,是否在群里提示还剩多久(纯本地消息,不调用模型)。'),
|
|
136
|
+
aiCooldownNoticeText: koishi_1.Schema.string().default('还在冷却,{seconds} 秒后再叫我。').description('冷却提示文案,可用 {seconds} 与 {minutes} 占位。'),
|
|
137
|
+
aiCooldownNoticeIntervalSeconds: koishi_1.Schema.natural().min(0).max(600).default(20).description('同一群两次冷却提示的最小间隔(秒),防止连续 @ 刷屏;0 = 不限制。'),
|
|
126
138
|
aiIdleTopicMinutes: koishi_1.Schema.natural().min(0).max(1440).default(120).description('群内无消息多少分钟后主动抛话题;0=关闭。'),
|
|
127
139
|
aiIdleTopicMinHour: koishi_1.Schema.natural().min(0).max(23).default(9).description('主动话题允许的最早小时(0-23)。'),
|
|
128
140
|
aiIdleTopicMaxHour: koishi_1.Schema.natural().min(0).max(24).default(23).description('主动话题允许的最晚小时(不含)。'),
|
|
@@ -143,6 +155,8 @@ exports.Config = koishi_1.Schema.intersect([
|
|
|
143
155
|
aiRandomReplyProbability: koishi_1.Schema.percent().default(0.08).description('随机触发概率(每条消息掷一次骰)。random / hybrid 模式下未掷中直接跳过,不会调用 AI 接口。填 0 等同于关闭随机触发。'),
|
|
144
156
|
aiMinReplyIntervalSeconds: koishi_1.Schema.natural().default(45).description('同一群两次真正调用模型的最短间隔(秒)。'),
|
|
145
157
|
aiContextWindow: koishi_1.Schema.natural().default(30).description('参与推理的最近消息条数(建议 20~40;太小会导致模型看不到前文)。'),
|
|
158
|
+
aiContextMaxChars: koishi_1.Schema.natural().min(0).max(20000).default(0).description('历史上下文的字数上限:超过后从最旧的消息开始丢(至少保留最近 4 条)。0 = 不限。想省 token 可设 2500~3500。'),
|
|
159
|
+
aiStyleMaxChars: koishi_1.Schema.natural().min(0).max(20000).default(0).description('外部插件注入的「说话风格」段每条最多保留多少字。0 = 不限。风格 skill 很长时可设 1200~1800 显著省 token。'),
|
|
146
160
|
aiTemperature: koishi_1.Schema.number().min(0).max(2).step(0.1).default(0.8).description('生成温度(0~2)。群聊接话建议 0.7~0.9,过高会跑题、复述、发散。'),
|
|
147
161
|
aiMaxOutputTokens: koishi_1.Schema.natural().default(400).description('AI 最大输出 token 数。群聊一句话不需要太大,过大会增加延迟。'),
|
|
148
162
|
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.
|
|
4
|
+
"version": "1.4.7",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"files": [
|