@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/src/index.ts
CHANGED
|
@@ -32,6 +32,10 @@ export const Config = Schema.intersect([
|
|
|
32
32
|
groupRules: Schema.array(Schema.object({
|
|
33
33
|
guildId: Schema.string().required().description('群号。'),
|
|
34
34
|
enableAiReply: Schema.boolean().description('该群是否启用 AI 回复(留空则跟随全局设置)。'),
|
|
35
|
+
aiMessageThreshold: Schema.natural().description('该群触发的消息数阈值(留空跟随全局 aiMessageThreshold)。'),
|
|
36
|
+
aiRandomReplyProbability: Schema.percent().description('该群随机触发概率(0~1,控制台按百分比显示;留空跟随全局)。'),
|
|
37
|
+
aiMinReplyIntervalSeconds: Schema.natural().description('该群模型调用冷却(秒;留空跟随全局 aiMinReplyIntervalSeconds)。'),
|
|
38
|
+
aiCooldownNotice: Schema.boolean().description('该群被 @ 但处于冷却时是否提示还剩多久(留空跟随全局)。'),
|
|
35
39
|
bannedWords: Schema.array(String).role('table').default([]).description('该群专属违禁词列表(同样支持“关键词|分值”与顺序模糊匹配)。'),
|
|
36
40
|
whitelistKeywords: Schema.array(String).role('table').default([]).description('该群违禁词白名单:消息只要命中其中任意一个关键词,就整条跳过违禁词评分(用于校学生会招新等允许的宣传场景)。'),
|
|
37
41
|
strongKeywords: Schema.array(String).role('table').description('该群强关键词(留空则跟随全局设置)。命中后无视白名单豁免,用于堵住「附一个白名单词即可绕过管控」的漏洞。'),
|
|
@@ -64,13 +68,18 @@ export const Config = Schema.intersect([
|
|
|
64
68
|
memoryPerScope: Schema.boolean().default(true).description('按私聊/群聊分开存储:群聊写 Memory_<群号>_群聊.md,私聊写 Memory_<QQ号>_私聊.md。关闭则所有会话共用单文件(旧行为)。'),
|
|
65
69
|
memoryInAi: Schema.boolean().default(true).description('AI 回复/识图时是否参考记忆库内容(只读当前会话对应的文件)。'),
|
|
66
70
|
memoryAutoLearn: Schema.boolean().default(false).description('自动归纳:上下文挤满后,把被挤出的消息交给外部学习插件总结成记忆。这里只负责抛出事件,实际归纳由 qqgm-memory-learn 完成。'),
|
|
67
|
-
memoryAutoLearnGroups: Schema.array(String).role('table').default([]).description('自动归纳生效的群号/QQ号白名单;留空表示全部生效。'),
|
|
71
|
+
memoryAutoLearnGroups: Schema.array(String).role('table').default([]).description('自动归纳生效的群号/QQ号白名单;留空表示全部生效。'),
|
|
68
72
|
memoryLearnIdleHours: Schema.natural().min(1).max(72).default(8).description('空闲兜底:距最后一条消息超过这么多小时且期间有新消息,就归纳一次。一直没新消息则不触发。'),
|
|
69
73
|
memoryLearnThresholdScale: Schema.number().min(1).max(10).step(0.5).default(1).description('归纳阈值 = aiContextWindow × 该倍数。填 1 表示攒满一个上下文窗口就归纳。'),
|
|
70
74
|
memoryLearnMaxChars: Schema.natural().min(40).max(300).default(150).description('单条自动记忆的字数上限。'),
|
|
71
75
|
memoryLearnPushBack: Schema.boolean().default(true).description('归纳后把结果回推到原会话:私聊发私聊、群聊发对应群。'),
|
|
72
76
|
memoryLearnDuplicateThreshold: Schema.number().min(0.3).max(0.95).step(0.05).default(0.55).description('与已有记忆相似度超过该值就跳过,避免同一件事反复记。'),
|
|
73
77
|
memoryLearnDailyLimit: Schema.natural().min(1).max(200).default(30).description('每个作用域每天最多归纳几次,防止刷模型额度。'),
|
|
78
|
+
memoryLearnConsolidate: Schema.boolean().default(true).description('自动归纳压缩:每累计 N 条就合并成一条更短的记忆,避免记忆越堆越长、反复占用提示词。'),
|
|
79
|
+
memoryLearnConsolidateEvery: Schema.natural().min(2).max(20).default(5).description('每多少条自动记忆压缩一次(默认 5)。'),
|
|
80
|
+
memoryLearnMaxEntries: Schema.natural().min(1).max(100).default(15).description('自动归纳记忆的条数上限(不含手动 [memory] 保存的内容);超过后会强制压缩。'),
|
|
81
|
+
memoryLearnConsolidateMaxChars: Schema.natural().min(40).max(300).default(90).description('压缩后单条记忆的字数上限。'),
|
|
82
|
+
memoryLearnModel: Schema.string().default('').description('自动归纳/压缩使用的模型(留空沿用 aiModel)。可用更便宜的模型降低开销。'),
|
|
74
83
|
}).description('记忆库'),
|
|
75
84
|
Schema.object({
|
|
76
85
|
enableBlacklist: Schema.boolean().default(true).description('全局黑名单系统开关。单个群未单独设置时跟随此值;单个群设置后以该群为准(全局关着也能为某群单独开启)。'),
|
|
@@ -119,7 +128,10 @@ export const Config = Schema.intersect([
|
|
|
119
128
|
aiBaseUrl: Schema.string().default('https://api.openai.com/v1').description('接口基础地址(OpenAI 兼容模式需以 /v1 结尾;Gemini 模式可留默认)。'),
|
|
120
129
|
aiModel: Schema.string().default('gpt-4o-mini').description('模型名称,如 gpt-4o-mini / doubao-1.5-lite / gemini-2.0-flash。'),
|
|
121
130
|
aiAgentName: Schema.string().default('bot').description('默认智能体自称(可在配置页修改)。'),
|
|
122
|
-
aiMentionCooldownSeconds: Schema.natural().min(0).max(3600).default(5).description('
|
|
131
|
+
aiMentionCooldownSeconds: Schema.natural().min(0).max(3600).default(5).description('(兼容字段)旧的 @ 冷却;现在所有模型调用统一走 aiMinReplyIntervalSeconds。'),
|
|
132
|
+
aiCooldownNotice: Schema.boolean().default(true).description('被 @ 但处于模型调用冷却时,是否在群里提示还剩多久(纯本地消息,不调用模型)。'),
|
|
133
|
+
aiCooldownNoticeText: Schema.string().default('还在冷却,{seconds} 秒后再叫我。').description('冷却提示文案,可用 {seconds} 与 {minutes} 占位。'),
|
|
134
|
+
aiCooldownNoticeIntervalSeconds: Schema.natural().min(0).max(600).default(20).description('同一群两次冷却提示的最小间隔(秒),防止连续 @ 刷屏;0 = 不限制。'),
|
|
123
135
|
aiIdleTopicMinutes: Schema.natural().min(0).max(1440).default(120).description('群内无消息多少分钟后主动抛话题;0=关闭。'),
|
|
124
136
|
aiIdleTopicMinHour: Schema.natural().min(0).max(23).default(9).description('主动话题允许的最早小时(0-23)。'),
|
|
125
137
|
aiIdleTopicMaxHour: Schema.natural().min(0).max(24).default(23).description('主动话题允许的最晚小时(不含)。'),
|
|
@@ -140,6 +152,8 @@ export const Config = Schema.intersect([
|
|
|
140
152
|
aiRandomReplyProbability: Schema.percent().default(0.08).description('随机触发概率(每条消息掷一次骰)。random / hybrid 模式下未掷中直接跳过,不会调用 AI 接口。填 0 等同于关闭随机触发。'),
|
|
141
153
|
aiMinReplyIntervalSeconds: Schema.natural().default(45).description('同一群两次真正调用模型的最短间隔(秒)。'),
|
|
142
154
|
aiContextWindow: Schema.natural().default(30).description('参与推理的最近消息条数(建议 20~40;太小会导致模型看不到前文)。'),
|
|
155
|
+
aiContextMaxChars: Schema.natural().min(0).max(20000).default(0).description('历史上下文的字数上限:超过后从最旧的消息开始丢(至少保留最近 4 条)。0 = 不限。想省 token 可设 2500~3500。'),
|
|
156
|
+
aiStyleMaxChars: Schema.natural().min(0).max(20000).default(0).description('外部插件注入的「说话风格」段每条最多保留多少字。0 = 不限。风格 skill 很长时可设 1200~1800 显著省 token。'),
|
|
143
157
|
aiTemperature: Schema.number().min(0).max(2).step(0.1).default(0.8).description('生成温度(0~2)。群聊接话建议 0.7~0.9,过高会跑题、复述、发散。'),
|
|
144
158
|
aiMaxOutputTokens: Schema.natural().default(400).description('AI 最大输出 token 数。群聊一句话不需要太大,过大会增加延迟。'),
|
|
145
159
|
aiMaxReplyChars: Schema.natural().min(20).max(500).default(120).description('单条回复的最大字符数,超出会在句末截断。'),
|
package/src/service.js
CHANGED
|
@@ -889,6 +889,42 @@ class QQGroupManagerService extends koishi_1.Service {
|
|
|
889
889
|
return block;
|
|
890
890
|
});
|
|
891
891
|
}
|
|
892
|
+
/**
|
|
893
|
+
* 自动归纳专用写入:追加一条新记忆,并可同时删掉若干旧条目。
|
|
894
|
+
* 用于「每 N 条压缩成 1 条」——remove 里的旧条目会被新条目替换。
|
|
895
|
+
*/
|
|
896
|
+
async commitAutoMemory(scope, payload) {
|
|
897
|
+
const add = String(payload && payload.add || '').trim();
|
|
898
|
+
if (!add)
|
|
899
|
+
return null;
|
|
900
|
+
const remove = new Set((payload && payload.remove || [])
|
|
901
|
+
.map((item) => String(item || '').trim())
|
|
902
|
+
.filter(Boolean));
|
|
903
|
+
const label = String(payload && payload.label || '自动归纳');
|
|
904
|
+
return this.runMemoryWriteLocked(async () => {
|
|
905
|
+
const now = new Date();
|
|
906
|
+
const stamp = now.toLocaleString('zh-CN', { hour12: false });
|
|
907
|
+
const block = `## ${stamp} · ${label}\n${add}`;
|
|
908
|
+
const existing = (await this.readMemoryFile(scope)).trim();
|
|
909
|
+
const blocks = this.extractMemoryBlocks(existing);
|
|
910
|
+
const kept = [];
|
|
911
|
+
let insertAt = -1;
|
|
912
|
+
for (const item of blocks) {
|
|
913
|
+
if (remove.has(item)) {
|
|
914
|
+
if (insertAt < 0)
|
|
915
|
+
insertAt = kept.length;
|
|
916
|
+
continue;
|
|
917
|
+
}
|
|
918
|
+
kept.push(item);
|
|
919
|
+
}
|
|
920
|
+
if (insertAt < 0)
|
|
921
|
+
insertAt = kept.length;
|
|
922
|
+
kept.splice(insertAt, 0, block);
|
|
923
|
+
const next = kept.length ? `${kept.join('\n\n---\n\n')}\n` : `${block}\n`;
|
|
924
|
+
await this.writeMemoryFile(next, scope);
|
|
925
|
+
return block;
|
|
926
|
+
});
|
|
927
|
+
}
|
|
892
928
|
async searchMemory(keyword, limit = 8, scope) {
|
|
893
929
|
const blocks = this.extractMemoryBlocks(await this.readMemoryFile(scope));
|
|
894
930
|
const kw = String(keyword || '').trim();
|
|
@@ -2174,6 +2210,12 @@ class QQGroupManagerService extends koishi_1.Service {
|
|
|
2174
2210
|
}
|
|
2175
2211
|
await session.send(koishi_1.h.text(text));
|
|
2176
2212
|
}
|
|
2213
|
+
/** 系统提示(例如「冷却中」),不引用原消息、不写入 AI 上下文 */
|
|
2214
|
+
async sendNotice(session, text) {
|
|
2215
|
+
if (!text)
|
|
2216
|
+
return;
|
|
2217
|
+
await session.send(koishi_1.h.text(String(text)));
|
|
2218
|
+
}
|
|
2177
2219
|
extractTextForFilter(session) {
|
|
2178
2220
|
const raw = (session.content ?? '')
|
|
2179
2221
|
.replace(/<[^>]+>/g, ' ')
|