@nestim/koishi-plugin-qq-group-manager 1.4.0 → 1.4.2
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 +42 -6
- package/lib/ai/engine.d.ts +21 -0
- package/lib/ai/engine.js +190 -35
- package/lib/ai/learn.d.ts +58 -0
- package/lib/ai/learn.js +200 -0
- package/lib/ai/provider.js +23 -10
- package/lib/core/bmp.d.ts +24 -0
- package/lib/core/bmp.js +224 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +6 -0
- package/lib/service.d.ts +6 -1
- package/lib/service.js +28 -3
- package/package.json +1 -1
- package/readme.md +37 -2
- package/src/ai/engine.ts +211 -44
- package/src/ai/learn.ts +208 -0
- package/src/ai/provider.ts +27 -9
- package/src/core/bmp.ts +225 -0
- package/src/index.ts +7 -1
- package/src/service.js +3774 -3749
package/lib/core/bmp.js
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* 内置 BMP → PNG 转码(纯 JS,零依赖)。
|
|
4
|
+
*
|
|
5
|
+
* 为什么需要:
|
|
6
|
+
* QQ 有时会把图片存成 BMP。DeepSeek 等视觉模型只接受 webp/png/jpeg/gif,
|
|
7
|
+
* 直接发 BMP 会 400。与其跳过这张图,不如转成 PNG 再发。
|
|
8
|
+
*
|
|
9
|
+
* 支持:
|
|
10
|
+
* - 1/4/8/16/24/32 位 BMP
|
|
11
|
+
* - BI_RGB(未压缩)、BI_BITFIELDS
|
|
12
|
+
* - 8 位调色板(含 RLE8 不处理,直接按索引读,够用)
|
|
13
|
+
*
|
|
14
|
+
* 不支持(遇到就返回 null,调用方回退到"跳过这张图"):
|
|
15
|
+
* - RLE 压缩
|
|
16
|
+
* - OS/2 v1 头
|
|
17
|
+
* - 带 alpha 的复杂变体(按 32 位 BGRA 直读,够常见场景用)
|
|
18
|
+
*/
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.isBmp = isBmp;
|
|
21
|
+
exports.bmpToPng = bmpToPng;
|
|
22
|
+
const PNG_SIG = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
|
23
|
+
/** 判断是不是 BMP */
|
|
24
|
+
function isBmp(buffer) {
|
|
25
|
+
return !!buffer && buffer.length > 26 && buffer[0] === 0x42 && buffer[1] === 0x4d;
|
|
26
|
+
}
|
|
27
|
+
/** CRC32(PNG chunk 需要) */
|
|
28
|
+
const CRC_TABLE = (() => {
|
|
29
|
+
const table = new Int32Array(256);
|
|
30
|
+
for (let n = 0; n < 256; n += 1) {
|
|
31
|
+
let c = n;
|
|
32
|
+
for (let k = 0; k < 8; k += 1) {
|
|
33
|
+
c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
|
|
34
|
+
}
|
|
35
|
+
table[n] = c;
|
|
36
|
+
}
|
|
37
|
+
return table;
|
|
38
|
+
})();
|
|
39
|
+
function crc32(buf) {
|
|
40
|
+
let c = 0xffffffff;
|
|
41
|
+
for (let i = 0; i < buf.length; i += 1) {
|
|
42
|
+
c = CRC_TABLE[(c ^ buf[i]) & 0xff] ^ (c >>> 8);
|
|
43
|
+
}
|
|
44
|
+
return (c ^ 0xffffffff) >>> 0;
|
|
45
|
+
}
|
|
46
|
+
/** 组装一个 PNG chunk */
|
|
47
|
+
function chunk(type, data) {
|
|
48
|
+
const len = Buffer.alloc(4);
|
|
49
|
+
len.writeUInt32BE(data.length, 0);
|
|
50
|
+
const typeBuf = Buffer.from(type, 'ascii');
|
|
51
|
+
const crcBuf = Buffer.alloc(4);
|
|
52
|
+
crcBuf.writeUInt32BE(crc32(Buffer.concat([typeBuf, data])), 0);
|
|
53
|
+
return Buffer.concat([len, typeBuf, data, crcBuf]);
|
|
54
|
+
}
|
|
55
|
+
/** 把 RGB(A) 像素编码成 PNG(真彩色 8 位) */
|
|
56
|
+
function encodePng(width, height, rgba) {
|
|
57
|
+
const stride = width * 4;
|
|
58
|
+
// 每行前置一个 filter byte(0 = None)
|
|
59
|
+
const raw = Buffer.alloc((stride + 1) * height);
|
|
60
|
+
for (let y = 0; y < height; y += 1) {
|
|
61
|
+
raw[y * (stride + 1)] = 0;
|
|
62
|
+
rgba.copy(raw, y * (stride + 1) + 1, y * stride, y * stride + stride);
|
|
63
|
+
}
|
|
64
|
+
const ihdr = Buffer.alloc(13);
|
|
65
|
+
ihdr.writeUInt32BE(width, 0);
|
|
66
|
+
ihdr.writeUInt32BE(height, 4);
|
|
67
|
+
ihdr[8] = 8; // bit depth
|
|
68
|
+
ihdr[9] = 6; // color type: RGBA
|
|
69
|
+
ihdr[10] = 0; // compression
|
|
70
|
+
ihdr[11] = 0; // filter
|
|
71
|
+
ihdr[12] = 0; // interlace
|
|
72
|
+
// zlib deflate(Node 自带)
|
|
73
|
+
const zlib = require('node:zlib');
|
|
74
|
+
const idat = zlib.deflateSync(raw, { level: 6 });
|
|
75
|
+
return Buffer.concat([
|
|
76
|
+
PNG_SIG,
|
|
77
|
+
chunk('IHDR', ihdr),
|
|
78
|
+
chunk('IDAT', idat),
|
|
79
|
+
chunk('IEND', Buffer.alloc(0)),
|
|
80
|
+
]);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* BMP → PNG buffer。
|
|
84
|
+
* @returns {Buffer|null} 成功返回 PNG,无法处理返回 null
|
|
85
|
+
*/
|
|
86
|
+
function bmpToPng(buffer) {
|
|
87
|
+
if (!isBmp(buffer))
|
|
88
|
+
return null;
|
|
89
|
+
try {
|
|
90
|
+
const dataOffset = buffer.readUInt32LE(10);
|
|
91
|
+
const headerSize = buffer.readUInt32LE(14);
|
|
92
|
+
let width;
|
|
93
|
+
let height;
|
|
94
|
+
let bitCount;
|
|
95
|
+
let compression;
|
|
96
|
+
let paletteOffset;
|
|
97
|
+
if (headerSize === 12) {
|
|
98
|
+
// OS/2 v1:不支持
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
// BITMAPINFOHEADER 及以后
|
|
102
|
+
width = buffer.readInt32LE(18);
|
|
103
|
+
height = buffer.readInt32LE(22);
|
|
104
|
+
bitCount = buffer.readUInt16LE(28);
|
|
105
|
+
compression = buffer.readUInt32LE(30);
|
|
106
|
+
paletteOffset = 14 + headerSize;
|
|
107
|
+
if (!width || !height)
|
|
108
|
+
return null;
|
|
109
|
+
if (compression === 1 || compression === 2)
|
|
110
|
+
return null; // RLE 不支持
|
|
111
|
+
const bottomUp = height > 0;
|
|
112
|
+
const h = Math.abs(height);
|
|
113
|
+
const w = Math.abs(width);
|
|
114
|
+
// 极端尺寸保护(避免爆内存)
|
|
115
|
+
if (w > 8192 || h > 8192 || w * h > 20_000_000)
|
|
116
|
+
return null;
|
|
117
|
+
// 调色板:8 位及以下
|
|
118
|
+
let palette = null;
|
|
119
|
+
if (bitCount <= 8) {
|
|
120
|
+
const count = bitCount === 8 ? 256 : 1 << bitCount;
|
|
121
|
+
palette = new Uint8Array(count * 4);
|
|
122
|
+
let base = paletteOffset;
|
|
123
|
+
// 若头里声明了颜色数,用它
|
|
124
|
+
const declared = headerSize >= 40 ? buffer.readUInt32LE(46) : 0;
|
|
125
|
+
const use = declared && declared <= count ? declared : count;
|
|
126
|
+
for (let i = 0; i < use; i += 1) {
|
|
127
|
+
const off = base + i * 4;
|
|
128
|
+
if (off + 3 >= buffer.length)
|
|
129
|
+
break;
|
|
130
|
+
palette[i * 4] = buffer[off + 2]; // R
|
|
131
|
+
palette[i * 4 + 1] = buffer[off + 1]; // G
|
|
132
|
+
palette[i * 4 + 2] = buffer[off]; // B
|
|
133
|
+
palette[i * 4 + 3] = 255;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const rowSize = Math.floor((bitCount * w + 31) / 32) * 4;
|
|
137
|
+
const rgba = Buffer.alloc(w * h * 4);
|
|
138
|
+
for (let y = 0; y < h; y += 1) {
|
|
139
|
+
// BMP 默认自下而上存储
|
|
140
|
+
const srcY = bottomUp ? h - 1 - y : y;
|
|
141
|
+
const rowStart = dataOffset + srcY * rowSize;
|
|
142
|
+
if (rowStart >= buffer.length)
|
|
143
|
+
break;
|
|
144
|
+
for (let x = 0; x < w; x += 1) {
|
|
145
|
+
const dst = (y * w + x) * 4;
|
|
146
|
+
let r = 0;
|
|
147
|
+
let g = 0;
|
|
148
|
+
let b = 0;
|
|
149
|
+
let a = 255;
|
|
150
|
+
if (bitCount === 24) {
|
|
151
|
+
const off = rowStart + x * 3;
|
|
152
|
+
if (off + 2 >= buffer.length)
|
|
153
|
+
continue;
|
|
154
|
+
b = buffer[off];
|
|
155
|
+
g = buffer[off + 1];
|
|
156
|
+
r = buffer[off + 2];
|
|
157
|
+
}
|
|
158
|
+
else if (bitCount === 32) {
|
|
159
|
+
const off = rowStart + x * 4;
|
|
160
|
+
if (off + 3 >= buffer.length)
|
|
161
|
+
continue;
|
|
162
|
+
b = buffer[off];
|
|
163
|
+
g = buffer[off + 1];
|
|
164
|
+
r = buffer[off + 2];
|
|
165
|
+
const alpha = buffer[off + 3];
|
|
166
|
+
a = alpha === 0 ? 255 : alpha; // 很多 BMP 的 alpha 位全 0,按不透明处理
|
|
167
|
+
}
|
|
168
|
+
else if (bitCount === 16) {
|
|
169
|
+
const off = rowStart + x * 2;
|
|
170
|
+
if (off + 1 >= buffer.length)
|
|
171
|
+
continue;
|
|
172
|
+
const v = buffer.readUInt16LE(off);
|
|
173
|
+
// 默认 5-5-5
|
|
174
|
+
r = ((v >> 10) & 0x1f) << 3;
|
|
175
|
+
g = ((v >> 5) & 0x1f) << 3;
|
|
176
|
+
b = (v & 0x1f) << 3;
|
|
177
|
+
}
|
|
178
|
+
else if (bitCount === 8) {
|
|
179
|
+
const off = rowStart + x;
|
|
180
|
+
if (off >= buffer.length)
|
|
181
|
+
continue;
|
|
182
|
+
const idx = buffer[off] * 4;
|
|
183
|
+
r = palette ? palette[idx] : buffer[off];
|
|
184
|
+
g = palette ? palette[idx + 1] : buffer[off];
|
|
185
|
+
b = palette ? palette[idx + 2] : buffer[off];
|
|
186
|
+
}
|
|
187
|
+
else if (bitCount === 4) {
|
|
188
|
+
const off = rowStart + (x >> 1);
|
|
189
|
+
if (off >= buffer.length)
|
|
190
|
+
continue;
|
|
191
|
+
const byte = buffer[off];
|
|
192
|
+
const idxVal = x % 2 === 0 ? (byte >> 4) & 0x0f : byte & 0x0f;
|
|
193
|
+
const idx = idxVal * 4;
|
|
194
|
+
r = palette ? palette[idx] : 0;
|
|
195
|
+
g = palette ? palette[idx + 1] : 0;
|
|
196
|
+
b = palette ? palette[idx + 2] : 0;
|
|
197
|
+
}
|
|
198
|
+
else if (bitCount === 1) {
|
|
199
|
+
const off = rowStart + (x >> 3);
|
|
200
|
+
if (off >= buffer.length)
|
|
201
|
+
continue;
|
|
202
|
+
const byte = buffer[off];
|
|
203
|
+
const bit = 7 - (x % 8);
|
|
204
|
+
const idxVal = (byte >> bit) & 1;
|
|
205
|
+
const idx = idxVal * 4;
|
|
206
|
+
r = palette ? palette[idx] : 0;
|
|
207
|
+
g = palette ? palette[idx + 1] : 0;
|
|
208
|
+
b = palette ? palette[idx + 2] : 0;
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
return null; // 未知位深
|
|
212
|
+
}
|
|
213
|
+
rgba[dst] = r;
|
|
214
|
+
rgba[dst + 1] = g;
|
|
215
|
+
rgba[dst + 2] = b;
|
|
216
|
+
rgba[dst + 3] = a;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return encodePng(w, h, rgba);
|
|
220
|
+
}
|
|
221
|
+
catch {
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -75,6 +75,12 @@ export declare const Config: Schema<Schemastery.ObjectS<{
|
|
|
75
75
|
memoryInAi: Schema<boolean, boolean>;
|
|
76
76
|
memoryAutoLearn: Schema<boolean, boolean>;
|
|
77
77
|
memoryAutoLearnGroups: Schema<string[], string[]>;
|
|
78
|
+
memoryLearnIdleHours: Schema<number, number>;
|
|
79
|
+
memoryLearnThresholdScale: Schema<number, number>;
|
|
80
|
+
memoryLearnMaxChars: Schema<number, number>;
|
|
81
|
+
memoryLearnPushBack: Schema<boolean, boolean>;
|
|
82
|
+
memoryLearnDuplicateThreshold: Schema<number, number>;
|
|
83
|
+
memoryLearnDailyLimit: Schema<number, number>;
|
|
78
84
|
}> | Schemastery.ObjectS<{
|
|
79
85
|
enableBlacklist: Schema<boolean, boolean>;
|
|
80
86
|
blacklistFileName: Schema<string, string>;
|
|
@@ -242,6 +248,12 @@ export declare const Config: Schema<Schemastery.ObjectS<{
|
|
|
242
248
|
memoryInAi: boolean;
|
|
243
249
|
memoryAutoLearn: boolean;
|
|
244
250
|
memoryAutoLearnGroups: string[];
|
|
251
|
+
memoryLearnIdleHours: number;
|
|
252
|
+
memoryLearnThresholdScale: number;
|
|
253
|
+
memoryLearnMaxChars: number;
|
|
254
|
+
memoryLearnPushBack: boolean;
|
|
255
|
+
memoryLearnDuplicateThreshold: number;
|
|
256
|
+
memoryLearnDailyLimit: number;
|
|
245
257
|
} & {
|
|
246
258
|
enableBlacklist: boolean;
|
|
247
259
|
blacklistFileName: string;
|
package/lib/index.js
CHANGED
|
@@ -68,6 +68,12 @@ exports.Config = koishi_1.Schema.intersect([
|
|
|
68
68
|
memoryInAi: koishi_1.Schema.boolean().default(true).description('AI 回复/识图时是否参考记忆库内容(只读当前会话对应的文件)。'),
|
|
69
69
|
memoryAutoLearn: koishi_1.Schema.boolean().default(false).description('自动归纳:上下文挤满后,把被挤出的消息交给外部学习插件总结成记忆。这里只负责抛出事件,实际归纳由 qqgm-memory-learn 完成。'),
|
|
70
70
|
memoryAutoLearnGroups: koishi_1.Schema.array(String).role('table').default([]).description('自动归纳生效的群号/QQ号白名单;留空表示全部生效。'),
|
|
71
|
+
memoryLearnIdleHours: koishi_1.Schema.natural().min(1).max(72).default(8).description('空闲兜底:距最后一条消息超过这么多小时且期间有新消息,就归纳一次。一直没新消息则不触发。'),
|
|
72
|
+
memoryLearnThresholdScale: koishi_1.Schema.number().min(1).max(10).step(0.5).default(1).description('归纳阈值 = aiContextWindow × 该倍数。填 1 表示攒满一个上下文窗口就归纳。'),
|
|
73
|
+
memoryLearnMaxChars: koishi_1.Schema.natural().min(40).max(300).default(150).description('单条自动记忆的字数上限。'),
|
|
74
|
+
memoryLearnPushBack: koishi_1.Schema.boolean().default(true).description('归纳后把结果回推到原会话:私聊发私聊、群聊发对应群。'),
|
|
75
|
+
memoryLearnDuplicateThreshold: koishi_1.Schema.number().min(0.3).max(0.95).step(0.05).default(0.55).description('与已有记忆相似度超过该值就跳过,避免同一件事反复记。'),
|
|
76
|
+
memoryLearnDailyLimit: koishi_1.Schema.natural().min(1).max(200).default(30).description('每个作用域每天最多归纳几次,防止刷模型额度。'),
|
|
71
77
|
}).description('记忆库'),
|
|
72
78
|
koishi_1.Schema.object({
|
|
73
79
|
enableBlacklist: koishi_1.Schema.boolean().default(true).description('全局黑名单系统开关。单个群未单独设置时跟随此值;单个群设置后以该群为准(全局关着也能为某群单独开启)。'),
|
package/lib/service.d.ts
CHANGED
|
@@ -236,6 +236,11 @@ export class QQGroupManagerService extends koishi_1.Service<any, koishi_1.Contex
|
|
|
236
236
|
isImageReference(value: any): boolean;
|
|
237
237
|
extractImageCandidates(session: any, maxCount?: number): any[];
|
|
238
238
|
detectImageMime(buffer: any, fallback?: string): string;
|
|
239
|
+
/**
|
|
240
|
+
* 把原始图片字节包成 data URL;BMP 会先转成 PNG。
|
|
241
|
+
* 视觉模型(DeepSeek 等)只认 webp/png/jpeg/gif,BMP 会被 400 拒掉。
|
|
242
|
+
*/
|
|
243
|
+
buildImageDataUrl(buffer: any): string;
|
|
239
244
|
resolveImageReferenceToDataUrl(ref: any, session: any): Promise<any>;
|
|
240
245
|
fetchImageAsDataUrl(url: any, extraHeaders?: {}): Promise<any>;
|
|
241
246
|
rememberImageDataUrl(url: any, dataUrl: any): void;
|
|
@@ -386,7 +391,7 @@ export class QQGroupManagerService extends koishi_1.Service<any, koishi_1.Contex
|
|
|
386
391
|
* 短关键词(2~4 字)极易被无关文本凑齐(如「领导说…红色包装袋」凑出「领红包」),
|
|
387
392
|
* 因此对短词要求更高的置信度;长词本身信息量足,门槛可放宽。
|
|
388
393
|
*/
|
|
389
|
-
minBannedWordConfidence(keywordLength: any): 1 | 0.
|
|
394
|
+
minBannedWordConfidence(keywordLength: any): 1 | 0.55 | 0.6 | 0.65 | 0.45;
|
|
390
395
|
subsequenceMatch(text: any, keyword: any): {
|
|
391
396
|
start: any;
|
|
392
397
|
end: any;
|
package/lib/service.js
CHANGED
|
@@ -543,6 +543,13 @@ class QQGroupManagerService extends koishi_1.Service {
|
|
|
543
543
|
clearTimeout(timer);
|
|
544
544
|
this._reminderTimers.clear();
|
|
545
545
|
this._idleTimers.clear();
|
|
546
|
+
try {
|
|
547
|
+
if (this.ai && typeof this.ai.dispose === 'function')
|
|
548
|
+
this.ai.dispose();
|
|
549
|
+
}
|
|
550
|
+
catch (error) {
|
|
551
|
+
this._logger.warn(`[dispose] AI 引擎清理失败: ${String(error)}`);
|
|
552
|
+
}
|
|
546
553
|
}
|
|
547
554
|
isPlatformAllowed(platform) {
|
|
548
555
|
if (!platform)
|
|
@@ -964,6 +971,24 @@ class QQGroupManagerService extends koishi_1.Service {
|
|
|
964
971
|
return 'image/bmp';
|
|
965
972
|
return fallback;
|
|
966
973
|
}
|
|
974
|
+
/**
|
|
975
|
+
* 把原始图片字节包成 data URL;BMP 会先转成 PNG。
|
|
976
|
+
* 视觉模型(DeepSeek 等)只认 webp/png/jpeg/gif,BMP 会被 400 拒掉。
|
|
977
|
+
*/
|
|
978
|
+
buildImageDataUrl(buffer) {
|
|
979
|
+
if (!buffer || !buffer.length)
|
|
980
|
+
return '';
|
|
981
|
+
if (bmp_1.isBmp(buffer)) {
|
|
982
|
+
const png = bmp_1.bmpToPng(buffer);
|
|
983
|
+
if (png && png.length) {
|
|
984
|
+
this._logger?.info?.(`[vision] BMP 已转为 PNG(${buffer.length} → ${png.length} 字节)`);
|
|
985
|
+
return `data:image/png;base64,${png.toString("base64")}`;
|
|
986
|
+
}
|
|
987
|
+
this._logger?.warn?.('[vision] BMP 转 PNG 失败,跳过这张图');
|
|
988
|
+
return '';
|
|
989
|
+
}
|
|
990
|
+
return `data:${this.detectImageMime(buffer)};base64,${buffer.toString("base64")}`;
|
|
991
|
+
}
|
|
967
992
|
async resolveImageReferenceToDataUrl(ref, session) {
|
|
968
993
|
const value = String(ref ?? '').trim();
|
|
969
994
|
if (!value)
|
|
@@ -981,7 +1006,7 @@ class QQGroupManagerService extends koishi_1.Service {
|
|
|
981
1006
|
const buffer = Buffer.from(raw, 'base64');
|
|
982
1007
|
if (!buffer.length)
|
|
983
1008
|
return '';
|
|
984
|
-
return
|
|
1009
|
+
return this.buildImageDataUrl(buffer);
|
|
985
1010
|
}
|
|
986
1011
|
if (/^https?:\/\//i.test(value)) {
|
|
987
1012
|
// OneBot 的 get_image 能把 file_id 换成可访问链接
|
|
@@ -1013,7 +1038,7 @@ class QQGroupManagerService extends koishi_1.Service {
|
|
|
1013
1038
|
try {
|
|
1014
1039
|
const buffer = await node_fs_1.default.promises.readFile(finalUrl);
|
|
1015
1040
|
if (buffer.length)
|
|
1016
|
-
return
|
|
1041
|
+
return this.buildImageDataUrl(buffer);
|
|
1017
1042
|
}
|
|
1018
1043
|
catch {
|
|
1019
1044
|
return '';
|
|
@@ -1024,7 +1049,7 @@ class QQGroupManagerService extends koishi_1.Service {
|
|
|
1024
1049
|
const localPath = value.replace(/^file:\/\//i, '');
|
|
1025
1050
|
const buffer = await node_fs_1.default.promises.readFile(localPath).catch(() => null);
|
|
1026
1051
|
if (buffer?.length)
|
|
1027
|
-
return
|
|
1052
|
+
return this.buildImageDataUrl(buffer);
|
|
1028
1053
|
}
|
|
1029
1054
|
return '';
|
|
1030
1055
|
}
|
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.2",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"files": [
|
package/readme.md
CHANGED
|
@@ -94,7 +94,13 @@ npm i @nestim/koishi-plugin-qq-group-manager
|
|
|
94
94
|
| `groupRules` | `[]` | 按群覆盖策略(违禁词、强关键词、白名单关键词、AI 开关、自动处罚阈值等) |
|
|
95
95
|
| `memoryFileName` | `Memory.md` | 记忆库基础文件名;分作用域时作为前缀 |
|
|
96
96
|
| `memoryPerScope` | `true` | 按私聊/群聊分开存:`Memory_<群号>_群聊.md` / `Memory_<QQ号>_私聊.md` |
|
|
97
|
-
| `memoryAutoLearn` | `false` |
|
|
97
|
+
| `memoryAutoLearn` | `false` | **AI 自动归纳记忆**(内建):上下文挤满后把消息总结成记忆并回推 |
|
|
98
|
+
| `memoryLearnIdleHours` | `8` | 空闲兜底小时数;期间没有新消息则不触发 |
|
|
99
|
+
| `memoryLearnThresholdScale` | `1` | 归纳阈值 = `aiContextWindow × 该值` |
|
|
100
|
+
| `memoryLearnMaxChars` | `150` | 单条自动记忆字数上限 |
|
|
101
|
+
| `memoryLearnPushBack` | `true` | 归纳后回推原会话(私聊发私聊、群聊发对应群) |
|
|
102
|
+
| `memoryLearnDuplicateThreshold` | `0.55` | 相似度超此值跳过,避免重复记 |
|
|
103
|
+
| `memoryLearnDailyLimit` | `30` | 每作用域每天最多归纳次数 |
|
|
98
104
|
| `blacklistFileName` | `banMember.md` | 黑名单文件名模板,实际为 `banMember_<群号>.md` |
|
|
99
105
|
| `pendingJoinFileName` | `JoinRequests.md` | 待审入群申请落盘文件名 |
|
|
100
106
|
| `enableJoinRequestReview` | `true` | 是否发起入群审核 |
|
|
@@ -162,10 +168,39 @@ npm i @nestim/koishi-plugin-qq-group-manager
|
|
|
162
168
|
| --- | --- | --- |
|
|
163
169
|
| `@nestim/koishi-plugin-qqgm-chat-style` | 聊天风格:一个主风格 + 多个按概率随机叠加的追加风格 | [npm](https://www.npmjs.com/package/@nestim/koishi-plugin-qqgm-chat-style) · [GitHub](https://github.com/Miseat/koishi-plugin-qqgm-chat-style) |
|
|
164
170
|
| `@nestim/koishi-plugin-qqgm-meme` | 表情包:AI 用 `[表情: 情绪]` 抽图,按概率补在文字后面 | [npm](https://www.npmjs.com/package/@nestim/koishi-plugin-qqgm-meme) · [GitHub](https://github.com/Miseat/koishi-plugin-qqgm-meme) |
|
|
165
|
-
| `@nestim/koishi-plugin-qqgm-
|
|
171
|
+
| `@nestim/koishi-plugin-qqgm-private` | 私聊:AI 自动回复 + 定时主动私发 | [npm](https://www.npmjs.com/package/@nestim/koishi-plugin-qqgm-private) · [GitHub](https://github.com/Miseat/koishi-plugin-qqgm-private) |
|
|
166
172
|
|
|
167
173
|
定时提醒(`[提醒] 明天 8 点 开会`)**内建在本插件里**,不需要额外安装。
|
|
168
174
|
|
|
175
|
+
## 记忆自动归纳(1.4.1+,内建)
|
|
176
|
+
|
|
177
|
+
不需要额外插件。开启 `memoryAutoLearn` 后:
|
|
178
|
+
|
|
179
|
+
```
|
|
180
|
+
上下文挤满(aiContextWindow 条)
|
|
181
|
+
↓ 最老的消息被挤出
|
|
182
|
+
累计到阈值(aiContextWindow × memoryLearnThresholdScale)
|
|
183
|
+
或空闲满 memoryLearnIdleHours(且期间有新消息)
|
|
184
|
+
↓
|
|
185
|
+
模型归纳成一条 ≤ memoryLearnMaxChars 的记忆
|
|
186
|
+
↓ 与已有记忆去重
|
|
187
|
+
写入 Memory_<群号>_群聊.md / Memory_<QQ号>_私聊.md
|
|
188
|
+
↓ 回推原会话
|
|
189
|
+
「刚记住了:……」
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
要点:
|
|
193
|
+
|
|
194
|
+
- **不会空转**:8 小时里一条新消息都没有,就不归纳。
|
|
195
|
+
- **不会串台**:私聊发私聊,群聊发对应群。
|
|
196
|
+
- **不会记废话**:提示词只允许人物关系、稳定偏好、群内黑话、反复出现的话题;
|
|
197
|
+
寒暄、一次性情绪、已结束的接梗、纯表情全部丢弃。
|
|
198
|
+
- **不会重复记**:写入前做相似度比对,超过 `memoryLearnDuplicateThreshold` 就跳过。
|
|
199
|
+
- **不会刷爆额度**:每作用域每天最多 `memoryLearnDailyLimit` 次。
|
|
200
|
+
- **系统备注与指令消息不参与归纳**(复读、命令结果等)。
|
|
201
|
+
|
|
202
|
+
自动写入了什么,可以直接在 Koishi 控制台「探索器」打开对应的 `Memory_*.md` 查看。
|
|
203
|
+
条目带的时间戳与来源标记能让你区分手动 `[memory]` 与 AI 自动归纳。
|
|
169
204
|
## 外部插件接口(1.2.2+)
|
|
170
205
|
|
|
171
206
|
主插件暴露一个很小的扩展点,第三方插件可以给 AI 追加“说话风格”,或在发送前过滤输出,
|