@nestim/koishi-plugin-qq-group-manager 1.4.7 → 1.4.9
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 +56 -0
- package/lib/ai/engine.d.ts +2 -3
- package/lib/ai/engine.js +17 -34
- package/lib/ai/prompt.d.ts +0 -5
- package/lib/ai/prompt.js +0 -13
- package/lib/ai/provider.d.ts +2 -0
- package/lib/ai/provider.js +14 -2
- package/lib/ai/state.d.ts +2 -1
- package/lib/ai/state.js +2 -1
- package/lib/ai/trigger.d.ts +10 -3
- package/lib/ai/trigger.js +32 -6
- package/lib/index.d.ts +10 -24
- package/lib/index.js +5 -19
- package/lib/service.js +2 -1
- package/package.json +1 -1
- package/src/ai/engine.ts +20 -35
- package/src/ai/prompt.ts +0 -16
- package/src/ai/provider.ts +16 -2
- package/src/ai/state.ts +2 -1
- package/src/ai/trigger.ts +45 -8
- package/src/index.ts +5 -19
- package/src/service.js +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,62 @@
|
|
|
2
2
|
|
|
3
3
|
本文件记录所有值得注意的变更。版本号遵循 [语义化版本](https://semver.org/lang/zh-CN/)。
|
|
4
4
|
|
|
5
|
+
## 1.4.9
|
|
6
|
+
|
|
7
|
+
### 清理
|
|
8
|
+
|
|
9
|
+
- 删除一批无效或冗余配置项,配置页不再显示这些「意义不明」的开关:
|
|
10
|
+
|
|
11
|
+
- `aiReplyDecision`:`two-stage` 判定路径整体移除(判定提示词、判定函数一并删除),
|
|
12
|
+
现在固定为「一次调用 + `<pass/>` 放弃」;
|
|
13
|
+
- `aiInterestMinScore`、`aiInterestContextWindow`、`aiInterestModel`、`aiInterestMaxTokens`:
|
|
14
|
+
只服务于 two-stage,且后三个在代码里从未被读取;
|
|
15
|
+
- `aiMentionCooldownSeconds`:1.4.7 起模型调用冷却已统一,旧字段不再生效;
|
|
16
|
+
- `aiOwnerPlatform`、`aiOwnerUserId`、`aiHomePlatform`、`aiHomeUserId`、`aiIgnoreCommandMessage`:
|
|
17
|
+
代码里没有任何引用,属于历史遗留;
|
|
18
|
+
- `responseStyle`:只会给指令回复加「喵~ 」前缀,需要喵味请在 qqgm-chat-style
|
|
19
|
+
里加一个风格 skill(插件内已无引用,固定普通输出)。
|
|
20
|
+
|
|
21
|
+
旧配置里残留的这些键会被 Schema 忽略,不影响启动。
|
|
22
|
+
|
|
23
|
+
### 改进
|
|
24
|
+
|
|
25
|
+
- 模型调用日志补充思考 token:`tokens="in=…,out=…,cache=…,reasoning=…"`。
|
|
26
|
+
`out` 是 completion 总数(含思考),`reasoning` 是其中思维链的部分,
|
|
27
|
+
可直接看出每次调用在思考上花了多少。
|
|
28
|
+
|
|
29
|
+
- **明确 `aiMaxOutputTokens` 的语义:它是「思考 + 回答」的总上限(API 的 `max_tokens`),
|
|
30
|
+
不是只限制正文**。默认值从 400 调整为 1500(群聊接话建议 1000~2000):
|
|
31
|
+
设得太小,预算会被思维链吃掉、正文被截断;设得太大,单次成本上限更高。
|
|
32
|
+
|
|
33
|
+
- 当服务端返回 `finish_reason=length`(触达 `max_tokens`)时输出一条
|
|
34
|
+
`[ai-budget]` 告警,提示正文可能被截断,并给出当前上限。
|
|
35
|
+
|
|
36
|
+
## 1.4.8
|
|
37
|
+
|
|
38
|
+
### 新功能
|
|
39
|
+
|
|
40
|
+
- **伪随机触发**:随机 / 混合模式下,每次随机未命中都会把下一次的概率按步长累加,
|
|
41
|
+
加到 1 时必定回复,命中后归零。避免真随机运气差时连续很多条都不接话。
|
|
42
|
+
|
|
43
|
+
- `aiPseudoRandom`:总开关(默认开)
|
|
44
|
+
- `aiPseudoRandomStep`:每次未命中增加多少(默认 0.01 = 1%)
|
|
45
|
+
- `groupRules` 里也可以按群设置 `aiPseudoRandom` / `aiPseudoRandomStep`
|
|
46
|
+
(留空跟随全局,填 0 表示该群不涨概率)
|
|
47
|
+
|
|
48
|
+
细节:
|
|
49
|
+
|
|
50
|
+
- 只有「真正掷骰且未命中」才累加;冷却中、阈值不足、点名与点名后跟随都不算;
|
|
51
|
+
- 点名 / 跟随仍然直接回复,不消耗也不清零加成;
|
|
52
|
+
- 加成到 1 时不再掷骰,直接回复;
|
|
53
|
+
- 触发成功(随机命中)后加成归零;
|
|
54
|
+
- `[ai-trigger]` 日志新增 `prob=`(本次实际概率)与 `boost=`(当前加成),方便排查。
|
|
55
|
+
|
|
56
|
+
### 测试
|
|
57
|
+
|
|
58
|
+
- 新增 6 项:未命中累加 / 命中归零、加成到 1 必定触发且不掷骰、关闭后不累加、
|
|
59
|
+
概率为 0 但已有加成仍可累计、按群覆盖步长、按群关闭。
|
|
60
|
+
|
|
5
61
|
## 1.4.7
|
|
6
62
|
|
|
7
63
|
### 新功能
|
package/lib/ai/engine.d.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* - 允许模型用 <pass/> 主动放弃,放弃也重置计数,避免每条消息都空转调用。
|
|
13
13
|
*/
|
|
14
14
|
import { AiState, ChatRecord } from './state';
|
|
15
|
-
import { ChatProvider
|
|
15
|
+
import { ChatProvider } from './provider';
|
|
16
16
|
import { RenderedImage } from '../core/text';
|
|
17
17
|
import { AiHookRegistry } from './hooks';
|
|
18
18
|
export interface AiHost {
|
|
@@ -147,7 +147,7 @@ export declare class AiEngine {
|
|
|
147
147
|
private sendCooldownNotice;
|
|
148
148
|
handle(session: any): Promise<void>;
|
|
149
149
|
/** 供外部插件(如私聊插件)复用同一个模型 provider。 */
|
|
150
|
-
chat(request: any): Promise<ChatResult>;
|
|
150
|
+
chat(request: any): Promise<import("./provider").ChatResult>;
|
|
151
151
|
/** 群内长时间没人说话时,生成一条主动话题。 */
|
|
152
152
|
idleTopic(groupId: string): Promise<string>;
|
|
153
153
|
/** 需要时调用 DeepSeek Search API;失败/不支持/没结果都返回空串,继续普通回复。 */
|
|
@@ -158,7 +158,6 @@ export declare class AiEngine {
|
|
|
158
158
|
private readForwards;
|
|
159
159
|
private recentImageRecords;
|
|
160
160
|
private collectImages;
|
|
161
|
-
private judge;
|
|
162
161
|
private platformAllowed;
|
|
163
162
|
private log;
|
|
164
163
|
/** 供指令/调试使用 */
|
package/lib/ai/engine.js
CHANGED
|
@@ -51,6 +51,8 @@ function usageText(usage) {
|
|
|
51
51
|
const cacheHit = usage.prompt_cache_hit_tokens
|
|
52
52
|
?? usage.cached_tokens
|
|
53
53
|
?? usage.cache_read_input_tokens;
|
|
54
|
+
const reasoning = usage.completion_tokens_details?.reasoning_tokens
|
|
55
|
+
?? usage.reasoning_tokens;
|
|
54
56
|
const parts = [];
|
|
55
57
|
if (input != null)
|
|
56
58
|
parts.push(`in=${input}`);
|
|
@@ -58,6 +60,8 @@ function usageText(usage) {
|
|
|
58
60
|
parts.push(`out=${output}`);
|
|
59
61
|
if (cacheHit != null)
|
|
60
62
|
parts.push(`cache=${cacheHit}`);
|
|
63
|
+
if (reasoning != null)
|
|
64
|
+
parts.push(`reasoning=${reasoning}`);
|
|
61
65
|
return parts.join(',');
|
|
62
66
|
}
|
|
63
67
|
function clipReply(text, maxChars) {
|
|
@@ -768,13 +772,17 @@ class AiEngine {
|
|
|
768
772
|
now: this.now(),
|
|
769
773
|
lastAttemptAt: state.lastAttemptAt,
|
|
770
774
|
minIntervalMs: Math.max(0, Number(this.setting(session, 'aiMinReplyIntervalSeconds') ?? 45)) * 1000,
|
|
771
|
-
lastReplyAt: state.lastReplyAt || 0,
|
|
772
|
-
mentionCooldownMs: Math.max(0, Number(this.config.aiMentionCooldownSeconds ?? 5)) * 1000,
|
|
773
775
|
inFlight: state.inFlight,
|
|
774
776
|
mention,
|
|
775
777
|
followup,
|
|
776
778
|
rng: this.rng,
|
|
779
|
+
pseudoRandom: this.setting(session, 'aiPseudoRandom') !== false,
|
|
780
|
+
randomBoost: state.randomBoost,
|
|
781
|
+
pseudoRandomStep: Math.max(0, Number(this.setting(session, 'aiPseudoRandomStep') ?? 0.01)),
|
|
777
782
|
});
|
|
783
|
+
// 伪随机加成只由「随机掷骰」更新:冷却/阈值跳过时保持不变
|
|
784
|
+
if (typeof decision.nextBoost === 'number')
|
|
785
|
+
state.randomBoost = decision.nextBoost;
|
|
778
786
|
this.log('ai-trigger', {
|
|
779
787
|
fire: decision.fire,
|
|
780
788
|
reason: decision.reason,
|
|
@@ -782,6 +790,8 @@ class AiEngine {
|
|
|
782
790
|
threshold,
|
|
783
791
|
mention,
|
|
784
792
|
followup,
|
|
793
|
+
prob: decision.effectiveProbability,
|
|
794
|
+
boost: state.randomBoost,
|
|
785
795
|
ctx: state.records.length,
|
|
786
796
|
}, session);
|
|
787
797
|
if (!decision.fire) {
|
|
@@ -818,14 +828,6 @@ class AiEngine {
|
|
|
818
828
|
webSearch,
|
|
819
829
|
webSearchEnabled: this.config.aiWebSearchEnabled !== false,
|
|
820
830
|
};
|
|
821
|
-
if (allowPass && this.config.aiReplyDecision === 'two-stage') {
|
|
822
|
-
const judge = await this.judge(promptInput);
|
|
823
|
-
if (!judge) {
|
|
824
|
-
state.counter = 0;
|
|
825
|
-
this.log('ai-pass', { by: 'judge', latencyMs: this.now() - startedAt }, session);
|
|
826
|
-
return;
|
|
827
|
-
}
|
|
828
|
-
}
|
|
829
831
|
const prompt = (0, prompt_1.buildReplyPrompt)(promptInput);
|
|
830
832
|
if (this.debugPrompt) {
|
|
831
833
|
this.host.logger.info(`[ai-debug] system=${prompt.system}\n[ai-debug] user=${prompt.user}`);
|
|
@@ -847,6 +849,11 @@ class AiEngine {
|
|
|
847
849
|
}, session);
|
|
848
850
|
return;
|
|
849
851
|
}
|
|
852
|
+
if (result.finishReason === 'length') {
|
|
853
|
+
const cap = Number(this.config.aiMaxOutputTokens ?? 1500);
|
|
854
|
+
this.host.logger?.warn?.(`[ai-budget] 输出触达 max_tokens=${cap}(思考 + 回答总上限),正文可能被截断;`
|
|
855
|
+
+ `可在配置页调大 aiMaxOutputTokens | guild=${session.guildId ?? '?'}`);
|
|
856
|
+
}
|
|
850
857
|
const raw = String(result.text || '').trim();
|
|
851
858
|
if (!raw || PASS_RE.test(raw)) {
|
|
852
859
|
state.counter = 0;
|
|
@@ -897,7 +904,6 @@ class AiEngine {
|
|
|
897
904
|
return;
|
|
898
905
|
}
|
|
899
906
|
await this.host.sendReply(session, finalText);
|
|
900
|
-
state.lastReplyAt = this.now();
|
|
901
907
|
state.counter = 0;
|
|
902
908
|
this.recordSelf(session, finalText);
|
|
903
909
|
if (mention)
|
|
@@ -1117,29 +1123,6 @@ class AiEngine {
|
|
|
1117
1123
|
return [];
|
|
1118
1124
|
return (0, vision_1.resolveImages)(items, (ref) => this.host.resolveImage(ref, session), { maxCount, budgetMs: Number(this.config.aiImageBudgetMs ?? 6000) });
|
|
1119
1125
|
}
|
|
1120
|
-
async judge(input) {
|
|
1121
|
-
const prompt = (0, prompt_1.buildJudgePrompt)(input);
|
|
1122
|
-
const result = await this.provider.chat({
|
|
1123
|
-
system: prompt.system,
|
|
1124
|
-
user: prompt.user,
|
|
1125
|
-
temperature: 0.1,
|
|
1126
|
-
maxTokens: 256,
|
|
1127
|
-
});
|
|
1128
|
-
if (!result.ok || !result.text)
|
|
1129
|
-
return false;
|
|
1130
|
-
const match = result.text.match(/\{[\s\S]*\}/);
|
|
1131
|
-
if (!match)
|
|
1132
|
-
return false;
|
|
1133
|
-
try {
|
|
1134
|
-
const parsed = JSON.parse(match[0]);
|
|
1135
|
-
const score = Number(parsed?.score) || 0;
|
|
1136
|
-
const min = Number(this.config.aiInterestMinScore ?? 60);
|
|
1137
|
-
return !!parsed?.reply && score >= min;
|
|
1138
|
-
}
|
|
1139
|
-
catch {
|
|
1140
|
-
return false;
|
|
1141
|
-
}
|
|
1142
|
-
}
|
|
1143
1126
|
platformAllowed(platform) {
|
|
1144
1127
|
const list = Array.isArray(this.config.platformFilter) ? this.config.platformFilter : ['onebot'];
|
|
1145
1128
|
return list.includes(platform);
|
package/lib/ai/prompt.d.ts
CHANGED
|
@@ -35,8 +35,3 @@ export declare function buildReplyPrompt(input: PromptInput): {
|
|
|
35
35
|
system: string;
|
|
36
36
|
user: string;
|
|
37
37
|
};
|
|
38
|
-
/** 两段式模式下的判定提示词(只有显式配置 aiReplyDecision=two-stage 才会用) */
|
|
39
|
-
export declare function buildJudgePrompt(input: PromptInput): {
|
|
40
|
-
system: string;
|
|
41
|
-
user: string;
|
|
42
|
-
};
|
package/lib/ai/prompt.js
CHANGED
|
@@ -15,7 +15,6 @@ exports.renderRecordLine = renderRecordLine;
|
|
|
15
15
|
exports.buildSystemPrompt = buildSystemPrompt;
|
|
16
16
|
exports.buildUserPrompt = buildUserPrompt;
|
|
17
17
|
exports.buildReplyPrompt = buildReplyPrompt;
|
|
18
|
-
exports.buildJudgePrompt = buildJudgePrompt;
|
|
19
18
|
const names_1 = require("../core/names");
|
|
20
19
|
const text_1 = require("../core/text");
|
|
21
20
|
exports.PASS_TOKEN = '<pass/>';
|
|
@@ -146,15 +145,3 @@ function buildReplyPrompt(input) {
|
|
|
146
145
|
user: buildUserPrompt(input),
|
|
147
146
|
};
|
|
148
147
|
}
|
|
149
|
-
/** 两段式模式下的判定提示词(只有显式配置 aiReplyDecision=two-stage 才会用) */
|
|
150
|
-
function buildJudgePrompt(input) {
|
|
151
|
-
const system = [
|
|
152
|
-
'你是群聊回复开关判定器。',
|
|
153
|
-
`当前群里有一个机器人,自称「${input.selfName}」。`,
|
|
154
|
-
'判断机器人现在是否应该接话。',
|
|
155
|
-
'只输出 JSON:{"reply":true|false,"score":0-100,"reason":"一句话"}。不要输出任何其它文字。',
|
|
156
|
-
'标准:与机器人无关、别人正在对话、纯刷屏 → reply=false;被点名、被追问、有明显互动价值 → reply=true。',
|
|
157
|
-
].join('\n');
|
|
158
|
-
const user = buildUserPrompt({ ...input, allowPass: false }).replace(/现在只输出一条回复正文。$/, '现在只输出判定 JSON。');
|
|
159
|
-
return { system, user };
|
|
160
|
-
}
|
package/lib/ai/provider.d.ts
CHANGED
|
@@ -25,6 +25,8 @@ export interface ChatResult {
|
|
|
25
25
|
degradedToText?: boolean;
|
|
26
26
|
/** 服务端 token 用量(OpenAI: usage;Gemini: usageMetadata) */
|
|
27
27
|
usage?: any;
|
|
28
|
+
/** 停止原因:length 表示被 max_tokens / 上下文上限截断 */
|
|
29
|
+
finishReason?: string;
|
|
28
30
|
}
|
|
29
31
|
export interface ProviderConfig {
|
|
30
32
|
aiProvider?: string;
|
package/lib/ai/provider.js
CHANGED
|
@@ -144,7 +144,13 @@ class ChatProvider {
|
|
|
144
144
|
error: `模型返回空内容(finish=${payload?.choices?.[0]?.finish_reason || 'unknown'})`,
|
|
145
145
|
};
|
|
146
146
|
}
|
|
147
|
-
return {
|
|
147
|
+
return {
|
|
148
|
+
ok: true,
|
|
149
|
+
text,
|
|
150
|
+
status: response.status,
|
|
151
|
+
usage: payload?.usage,
|
|
152
|
+
finishReason: payload?.choices?.[0]?.finish_reason,
|
|
153
|
+
};
|
|
148
154
|
}
|
|
149
155
|
catch (error) {
|
|
150
156
|
const aborted = error?.name === 'AbortError';
|
|
@@ -195,7 +201,13 @@ class ChatProvider {
|
|
|
195
201
|
.trim();
|
|
196
202
|
if (!text)
|
|
197
203
|
return { ok: false, status: response.status, error: 'Gemini 返回空内容' };
|
|
198
|
-
return {
|
|
204
|
+
return {
|
|
205
|
+
ok: true,
|
|
206
|
+
text,
|
|
207
|
+
status: response.status,
|
|
208
|
+
usage: payload?.usageMetadata,
|
|
209
|
+
finishReason: payload?.candidates?.[0]?.finishReason,
|
|
210
|
+
};
|
|
199
211
|
}
|
|
200
212
|
catch (error) {
|
|
201
213
|
const aborted = error?.name === 'AbortError';
|
package/lib/ai/state.d.ts
CHANGED
|
@@ -37,10 +37,11 @@ export declare class GroupState {
|
|
|
37
37
|
records: ChatRecord[];
|
|
38
38
|
/** 自上次"完整考虑"(真正调用了模型)以来累计的消息数 */
|
|
39
39
|
counter: number;
|
|
40
|
-
lastReplyAt: number;
|
|
41
40
|
lastAttemptAt: number;
|
|
42
41
|
/** 上次发「冷却中」提示的时间,用于避免 @ 刷屏时反复提示 */
|
|
43
42
|
lastCooldownNoticeAt: number;
|
|
43
|
+
/** 伪随机加成:随机未命中时累加,命中后归零 */
|
|
44
|
+
randomBoost: number;
|
|
44
45
|
inFlight: boolean;
|
|
45
46
|
followup: FollowupState | null;
|
|
46
47
|
seen: Map<string, number>;
|
package/lib/ai/state.js
CHANGED
|
@@ -13,10 +13,11 @@ class GroupState {
|
|
|
13
13
|
records = [];
|
|
14
14
|
/** 自上次"完整考虑"(真正调用了模型)以来累计的消息数 */
|
|
15
15
|
counter = 0;
|
|
16
|
-
lastReplyAt = 0;
|
|
17
16
|
lastAttemptAt = 0;
|
|
18
17
|
/** 上次发「冷却中」提示的时间,用于避免 @ 刷屏时反复提示 */
|
|
19
18
|
lastCooldownNoticeAt = 0;
|
|
19
|
+
/** 伪随机加成:随机未命中时累加,命中后归零 */
|
|
20
|
+
randomBoost = 0;
|
|
20
21
|
inFlight = false;
|
|
21
22
|
followup = null;
|
|
22
23
|
seen = new Map();
|
package/lib/ai/trigger.d.ts
CHANGED
|
@@ -16,13 +16,16 @@ export interface TriggerInput {
|
|
|
16
16
|
now: number;
|
|
17
17
|
lastAttemptAt: number;
|
|
18
18
|
minIntervalMs: number;
|
|
19
|
-
/** 兼容字段:旧版按“上次回复”计算的 @ 冷却,已合并进 minIntervalMs */
|
|
20
|
-
lastReplyAt?: number;
|
|
21
|
-
mentionCooldownMs?: number;
|
|
22
19
|
inFlight: boolean;
|
|
23
20
|
mention: boolean;
|
|
24
21
|
followup: boolean;
|
|
25
22
|
rng: () => number;
|
|
23
|
+
/** 伪随机:随机未命中时把下一次概率往上抬,直到必定触发 */
|
|
24
|
+
pseudoRandom?: boolean;
|
|
25
|
+
/** 当前已累计的概率加成(0~1) */
|
|
26
|
+
randomBoost?: number;
|
|
27
|
+
/** 每次未命中增加多少(默认 0.01) */
|
|
28
|
+
pseudoRandomStep?: number;
|
|
26
29
|
}
|
|
27
30
|
export interface TriggerDecision {
|
|
28
31
|
fire: boolean;
|
|
@@ -30,5 +33,9 @@ export interface TriggerDecision {
|
|
|
30
33
|
reason: string;
|
|
31
34
|
/** 冷却中时距离可以再次调用模型的剩余毫秒数 */
|
|
32
35
|
remainingMs?: number;
|
|
36
|
+
/** 本次判定后应保存的伪随机加成;未发生随机掷骰时为 undefined(保持不变) */
|
|
37
|
+
nextBoost?: number;
|
|
38
|
+
/** 本次实际使用的概率(基础值 + 加成),用于日志排查 */
|
|
39
|
+
effectiveProbability?: number;
|
|
33
40
|
}
|
|
34
41
|
export declare function decideTrigger(input: TriggerInput): TriggerDecision;
|
package/lib/ai/trigger.js
CHANGED
|
@@ -42,15 +42,41 @@ function decideTrigger(input) {
|
|
|
42
42
|
reason: `below-threshold(${input.counter}/${Math.max(1, input.threshold)})`,
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
-
// ---------- 4)
|
|
45
|
+
// ---------- 4) 概率(支持伪随机:连续未命中会逐步抬高概率) ----------
|
|
46
46
|
const needRandom = input.mode === 'random' || input.mode === 'hybrid';
|
|
47
47
|
if (needRandom) {
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
+
};
|
|
53
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
|
+
};
|
|
54
80
|
}
|
|
55
81
|
return { fire: true, forced: false, reason: `trigger(${input.mode})` };
|
|
56
82
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -12,7 +12,6 @@ export declare const Config: Schema<Schemastery.ObjectS<{
|
|
|
12
12
|
cmdCustom: Schema<string, string>;
|
|
13
13
|
cmdVersion: Schema<string, string>;
|
|
14
14
|
platformFilter: Schema<string[], string[]>;
|
|
15
|
-
responseStyle: Schema<"plain" | "meow", "plain" | "meow">;
|
|
16
15
|
dryRun: Schema<boolean, boolean>;
|
|
17
16
|
}> | Schemastery.ObjectS<{
|
|
18
17
|
bannedWords: Schema<string[], string[]>;
|
|
@@ -27,6 +26,8 @@ export declare const Config: Schema<Schemastery.ObjectS<{
|
|
|
27
26
|
enableAiReply: Schema<boolean, boolean>;
|
|
28
27
|
aiMessageThreshold: Schema<number, number>;
|
|
29
28
|
aiRandomReplyProbability: Schema<number, number>;
|
|
29
|
+
aiPseudoRandom: Schema<boolean, boolean>;
|
|
30
|
+
aiPseudoRandomStep: Schema<number, number>;
|
|
30
31
|
aiMinReplyIntervalSeconds: Schema<number, number>;
|
|
31
32
|
aiCooldownNotice: Schema<boolean, boolean>;
|
|
32
33
|
bannedWords: Schema<string[], string[]>;
|
|
@@ -50,6 +51,8 @@ export declare const Config: Schema<Schemastery.ObjectS<{
|
|
|
50
51
|
enableAiReply: Schema<boolean, boolean>;
|
|
51
52
|
aiMessageThreshold: Schema<number, number>;
|
|
52
53
|
aiRandomReplyProbability: Schema<number, number>;
|
|
54
|
+
aiPseudoRandom: Schema<boolean, boolean>;
|
|
55
|
+
aiPseudoRandomStep: Schema<number, number>;
|
|
53
56
|
aiMinReplyIntervalSeconds: Schema<number, number>;
|
|
54
57
|
aiCooldownNotice: Schema<boolean, boolean>;
|
|
55
58
|
bannedWords: Schema<string[], string[]>;
|
|
@@ -143,7 +146,6 @@ export declare const Config: Schema<Schemastery.ObjectS<{
|
|
|
143
146
|
aiBaseUrl: Schema<string, string>;
|
|
144
147
|
aiModel: Schema<string, string>;
|
|
145
148
|
aiAgentName: Schema<string, string>;
|
|
146
|
-
aiMentionCooldownSeconds: Schema<number, number>;
|
|
147
149
|
aiCooldownNotice: Schema<boolean, boolean>;
|
|
148
150
|
aiCooldownNoticeText: Schema<string, string>;
|
|
149
151
|
aiCooldownNoticeIntervalSeconds: Schema<number, number>;
|
|
@@ -165,6 +167,8 @@ export declare const Config: Schema<Schemastery.ObjectS<{
|
|
|
165
167
|
aiReplyMode: Schema<"threshold" | "random" | "hybrid", "threshold" | "random" | "hybrid">;
|
|
166
168
|
aiMessageThreshold: Schema<number, number>;
|
|
167
169
|
aiRandomReplyProbability: Schema<number, number>;
|
|
170
|
+
aiPseudoRandom: Schema<boolean, boolean>;
|
|
171
|
+
aiPseudoRandomStep: Schema<number, number>;
|
|
168
172
|
aiMinReplyIntervalSeconds: Schema<number, number>;
|
|
169
173
|
aiContextWindow: Schema<number, number>;
|
|
170
174
|
aiContextMaxChars: Schema<number, number>;
|
|
@@ -176,7 +180,6 @@ export declare const Config: Schema<Schemastery.ObjectS<{
|
|
|
176
180
|
aiQuoteReplyProbability: Schema<number, number>;
|
|
177
181
|
aiReadForwardMessage: Schema<boolean, boolean>;
|
|
178
182
|
aiForwardMaxNodes: Schema<number, number>;
|
|
179
|
-
aiReplyDecision: Schema<"two-stage" | "single", "two-stage" | "single">;
|
|
180
183
|
aiEnableImageRecognition: Schema<boolean, boolean>;
|
|
181
184
|
aiImageMaxCount: Schema<number, number>;
|
|
182
185
|
aiImageBudgetMs: Schema<number, number>;
|
|
@@ -188,19 +191,10 @@ export declare const Config: Schema<Schemastery.ObjectS<{
|
|
|
188
191
|
aiWebSearchCacheMinutes: Schema<number, number>;
|
|
189
192
|
aiRequestTimeoutSeconds: Schema<number, number>;
|
|
190
193
|
aiDebugPrompt: Schema<boolean, boolean>;
|
|
191
|
-
aiIgnoreCommandMessage: Schema<boolean, boolean>;
|
|
192
194
|
aiEnableDirectMentionTrigger: Schema<boolean, boolean>;
|
|
193
195
|
aiEnableFollowupAfterMention: Schema<boolean, boolean>;
|
|
194
196
|
aiFollowupWindowSeconds: Schema<number, number>;
|
|
195
197
|
aiFollowupMaxTurns: Schema<number, number>;
|
|
196
|
-
aiOwnerPlatform: Schema<string, string>;
|
|
197
|
-
aiOwnerUserId: Schema<string, string>;
|
|
198
|
-
aiHomePlatform: Schema<string, string>;
|
|
199
|
-
aiHomeUserId: Schema<string, string>;
|
|
200
|
-
aiInterestMinScore: Schema<number, number>;
|
|
201
|
-
aiInterestContextWindow: Schema<number, number>;
|
|
202
|
-
aiInterestModel: Schema<string, string>;
|
|
203
|
-
aiInterestMaxTokens: Schema<number, number>;
|
|
204
198
|
}> | Schemastery.ObjectS<{
|
|
205
199
|
allowedUserIds: Schema<string[], string[]>;
|
|
206
200
|
allowGroupOwner: Schema<boolean, boolean>;
|
|
@@ -222,7 +216,6 @@ export declare const Config: Schema<Schemastery.ObjectS<{
|
|
|
222
216
|
cmdCustom: string;
|
|
223
217
|
cmdVersion: string;
|
|
224
218
|
platformFilter: string[];
|
|
225
|
-
responseStyle: "plain" | "meow";
|
|
226
219
|
dryRun: boolean;
|
|
227
220
|
} & import("koishi").Dict & {
|
|
228
221
|
bannedWords: string[];
|
|
@@ -237,6 +230,8 @@ export declare const Config: Schema<Schemastery.ObjectS<{
|
|
|
237
230
|
enableAiReply: Schema<boolean, boolean>;
|
|
238
231
|
aiMessageThreshold: Schema<number, number>;
|
|
239
232
|
aiRandomReplyProbability: Schema<number, number>;
|
|
233
|
+
aiPseudoRandom: Schema<boolean, boolean>;
|
|
234
|
+
aiPseudoRandomStep: Schema<number, number>;
|
|
240
235
|
aiMinReplyIntervalSeconds: Schema<number, number>;
|
|
241
236
|
aiCooldownNotice: Schema<boolean, boolean>;
|
|
242
237
|
bannedWords: Schema<string[], string[]>;
|
|
@@ -321,7 +316,6 @@ export declare const Config: Schema<Schemastery.ObjectS<{
|
|
|
321
316
|
aiBaseUrl: string;
|
|
322
317
|
aiModel: string;
|
|
323
318
|
aiAgentName: string;
|
|
324
|
-
aiMentionCooldownSeconds: number;
|
|
325
319
|
aiCooldownNotice: boolean;
|
|
326
320
|
aiCooldownNoticeText: string;
|
|
327
321
|
aiCooldownNoticeIntervalSeconds: number;
|
|
@@ -339,6 +333,8 @@ export declare const Config: Schema<Schemastery.ObjectS<{
|
|
|
339
333
|
aiReplyMode: "threshold" | "random" | "hybrid";
|
|
340
334
|
aiMessageThreshold: number;
|
|
341
335
|
aiRandomReplyProbability: number;
|
|
336
|
+
aiPseudoRandom: boolean;
|
|
337
|
+
aiPseudoRandomStep: number;
|
|
342
338
|
aiMinReplyIntervalSeconds: number;
|
|
343
339
|
aiContextWindow: number;
|
|
344
340
|
aiContextMaxChars: number;
|
|
@@ -350,7 +346,6 @@ export declare const Config: Schema<Schemastery.ObjectS<{
|
|
|
350
346
|
aiQuoteReplyProbability: number;
|
|
351
347
|
aiReadForwardMessage: boolean;
|
|
352
348
|
aiForwardMaxNodes: number;
|
|
353
|
-
aiReplyDecision: "two-stage" | "single";
|
|
354
349
|
aiEnableImageRecognition: boolean;
|
|
355
350
|
aiImageMaxCount: number;
|
|
356
351
|
aiImageBudgetMs: number;
|
|
@@ -362,19 +357,10 @@ export declare const Config: Schema<Schemastery.ObjectS<{
|
|
|
362
357
|
aiWebSearchCacheMinutes: number;
|
|
363
358
|
aiRequestTimeoutSeconds: number;
|
|
364
359
|
aiDebugPrompt: boolean;
|
|
365
|
-
aiIgnoreCommandMessage: boolean;
|
|
366
360
|
aiEnableDirectMentionTrigger: boolean;
|
|
367
361
|
aiEnableFollowupAfterMention: boolean;
|
|
368
362
|
aiFollowupWindowSeconds: number;
|
|
369
363
|
aiFollowupMaxTurns: number;
|
|
370
|
-
aiOwnerPlatform: string;
|
|
371
|
-
aiOwnerUserId: string;
|
|
372
|
-
aiHomePlatform: string;
|
|
373
|
-
aiHomeUserId: string;
|
|
374
|
-
aiInterestMinScore: number;
|
|
375
|
-
aiInterestContextWindow: number;
|
|
376
|
-
aiInterestModel: string;
|
|
377
|
-
aiInterestMaxTokens: number;
|
|
378
364
|
} & {
|
|
379
365
|
allowedUserIds: string[];
|
|
380
366
|
allowGroupOwner: boolean;
|
package/lib/index.js
CHANGED
|
@@ -18,10 +18,6 @@ exports.Config = koishi_1.Schema.intersect([
|
|
|
18
18
|
cmdCustom: koishi_1.Schema.string().default('[custom]').description('自定义指令集前缀,用法:[custom]。未配置自定义指令时提示「目前还没有指令」。'),
|
|
19
19
|
cmdVersion: koishi_1.Schema.string().default('[Version]').description('插件信息指令前缀,用法:[Version]。返回当前版本、作者、GitHub 与 npm 地址。'),
|
|
20
20
|
platformFilter: koishi_1.Schema.array(String).default(['onebot']).description('允许启用管理功能的平台列表。'),
|
|
21
|
-
responseStyle: koishi_1.Schema.union([
|
|
22
|
-
koishi_1.Schema.const('plain').description('普通输出'),
|
|
23
|
-
koishi_1.Schema.const('meow').description('Meow 风格输出'),
|
|
24
|
-
]).role('radio').default('plain').description('群聊中指令返回的文本风格。'),
|
|
25
21
|
dryRun: koishi_1.Schema.boolean().default(false).description('演练模式:仅输出计划动作,不执行群管理操作。'),
|
|
26
22
|
}).description('基础设置'),
|
|
27
23
|
koishi_1.Schema.object({
|
|
@@ -37,6 +33,8 @@ exports.Config = koishi_1.Schema.intersect([
|
|
|
37
33
|
enableAiReply: koishi_1.Schema.boolean().description('该群是否启用 AI 回复(留空则跟随全局设置)。'),
|
|
38
34
|
aiMessageThreshold: koishi_1.Schema.natural().description('该群触发的消息数阈值(留空跟随全局 aiMessageThreshold)。'),
|
|
39
35
|
aiRandomReplyProbability: koishi_1.Schema.percent().description('该群随机触发概率(0~1,控制台按百分比显示;留空跟随全局)。'),
|
|
36
|
+
aiPseudoRandom: koishi_1.Schema.boolean().description('该群是否启用伪随机(连续未命中逐步提高概率;留空跟随全局)。'),
|
|
37
|
+
aiPseudoRandomStep: koishi_1.Schema.number().min(0).max(1).step(0.001).description('该群伪随机每次未命中增加的概率(留空跟随全局)。'),
|
|
40
38
|
aiMinReplyIntervalSeconds: koishi_1.Schema.natural().description('该群模型调用冷却(秒;留空跟随全局 aiMinReplyIntervalSeconds)。'),
|
|
41
39
|
aiCooldownNotice: koishi_1.Schema.boolean().description('该群被 @ 但处于冷却时是否提示还剩多久(留空跟随全局)。'),
|
|
42
40
|
bannedWords: koishi_1.Schema.array(String).role('table').default([]).description('该群专属违禁词列表(同样支持“关键词|分值”与顺序模糊匹配)。'),
|
|
@@ -131,7 +129,6 @@ exports.Config = koishi_1.Schema.intersect([
|
|
|
131
129
|
aiBaseUrl: koishi_1.Schema.string().default('https://api.openai.com/v1').description('接口基础地址(OpenAI 兼容模式需以 /v1 结尾;Gemini 模式可留默认)。'),
|
|
132
130
|
aiModel: koishi_1.Schema.string().default('gpt-4o-mini').description('模型名称,如 gpt-4o-mini / doubao-1.5-lite / gemini-2.0-flash。'),
|
|
133
131
|
aiAgentName: koishi_1.Schema.string().default('bot').description('默认智能体自称(可在配置页修改)。'),
|
|
134
|
-
aiMentionCooldownSeconds: koishi_1.Schema.natural().min(0).max(3600).default(5).description('(兼容字段)旧的 @ 冷却;现在所有模型调用统一走 aiMinReplyIntervalSeconds。'),
|
|
135
132
|
aiCooldownNotice: koishi_1.Schema.boolean().default(true).description('被 @ 但处于模型调用冷却时,是否在群里提示还剩多久(纯本地消息,不调用模型)。'),
|
|
136
133
|
aiCooldownNoticeText: koishi_1.Schema.string().default('还在冷却,{seconds} 秒后再叫我。').description('冷却提示文案,可用 {seconds} 与 {minutes} 占位。'),
|
|
137
134
|
aiCooldownNoticeIntervalSeconds: koishi_1.Schema.natural().min(0).max(600).default(20).description('同一群两次冷却提示的最小间隔(秒),防止连续 @ 刷屏;0 = 不限制。'),
|
|
@@ -153,12 +150,14 @@ exports.Config = koishi_1.Schema.intersect([
|
|
|
153
150
|
]).role('radio').default('hybrid').description('AI 触发策略:threshold 只看消息数、random 只看概率、hybrid 两者都要满足。@点名与点名后跟随会越过这些闸门。是否真正接话由模型在回复时用 <pass/> 自行决定。'),
|
|
154
151
|
aiMessageThreshold: koishi_1.Schema.natural().default(16).description('阈值触发所需累计消息数。threshold / hybrid 模式下未达此数一律不触发;计数器在模型给出回复或主动放弃后清零。'),
|
|
155
152
|
aiRandomReplyProbability: koishi_1.Schema.percent().default(0.08).description('随机触发概率(每条消息掷一次骰)。random / hybrid 模式下未掷中直接跳过,不会调用 AI 接口。填 0 等同于关闭随机触发。'),
|
|
153
|
+
aiPseudoRandom: koishi_1.Schema.boolean().default(true).description('伪随机:随机触发没命中时,下一次概率按步长累加(命中后归零),加到 1 时必定回复,避免真随机长期不触发。'),
|
|
154
|
+
aiPseudoRandomStep: koishi_1.Schema.number().min(0).max(1).step(0.001).default(0.01).description('伪随机每次未命中增加的概率(默认 0.01 = 1%)。只在真正掷骰且未命中时累加,冷却/阈值跳过不算。'),
|
|
156
155
|
aiMinReplyIntervalSeconds: koishi_1.Schema.natural().default(45).description('同一群两次真正调用模型的最短间隔(秒)。'),
|
|
157
156
|
aiContextWindow: koishi_1.Schema.natural().default(30).description('参与推理的最近消息条数(建议 20~40;太小会导致模型看不到前文)。'),
|
|
158
157
|
aiContextMaxChars: koishi_1.Schema.natural().min(0).max(20000).default(0).description('历史上下文的字数上限:超过后从最旧的消息开始丢(至少保留最近 4 条)。0 = 不限。想省 token 可设 2500~3500。'),
|
|
159
158
|
aiStyleMaxChars: koishi_1.Schema.natural().min(0).max(20000).default(0).description('外部插件注入的「说话风格」段每条最多保留多少字。0 = 不限。风格 skill 很长时可设 1200~1800 显著省 token。'),
|
|
160
159
|
aiTemperature: koishi_1.Schema.number().min(0).max(2).step(0.1).default(0.8).description('生成温度(0~2)。群聊接话建议 0.7~0.9,过高会跑题、复述、发散。'),
|
|
161
|
-
aiMaxOutputTokens: koishi_1.Schema.natural().default(
|
|
160
|
+
aiMaxOutputTokens: koishi_1.Schema.natural().min(100).max(131072).default(1500).description('思考 + 回答的总 token 上限(API 的 max_tokens,不是只限制正文)。思考模式开启时思维链也计入这里:设得太小,预算会被思考吃掉、正文被截断;设得太大则单次成本上限更高。群聊接话建议 1000~2000。'),
|
|
162
161
|
aiMaxReplyChars: koishi_1.Schema.natural().min(20).max(500).default(120).description('单条回复的最大字符数,超出会在句末截断。'),
|
|
163
162
|
aiQuoteReplyMode: koishi_1.Schema.union([
|
|
164
163
|
koishi_1.Schema.const('random').description('随机决定'),
|
|
@@ -168,10 +167,6 @@ exports.Config = koishi_1.Schema.intersect([
|
|
|
168
167
|
aiQuoteReplyProbability: koishi_1.Schema.number().min(0).max(1).step(0.05).default(0.5).hidden().description('引用概率(仅 random 模式生效)。'),
|
|
169
168
|
aiReadForwardMessage: koishi_1.Schema.boolean().default(true).description('读取合并转发聊天记录的内容,作为上下文的一部分。'),
|
|
170
169
|
aiForwardMaxNodes: koishi_1.Schema.natural().min(1).max(50).default(20).description('单条合并转发最多读取多少条子消息。'),
|
|
171
|
-
aiReplyDecision: koishi_1.Schema.union([
|
|
172
|
-
koishi_1.Schema.const('single').description('一次调用:模型直接输出回复,或用 <pass/> 放弃(推荐)'),
|
|
173
|
-
koishi_1.Schema.const('two-stage').description('两次调用:先判定是否值得回复,再生成正文'),
|
|
174
|
-
]).role('radio').default('single').description('接话决策方式。single 更快、决策与正文一致;two-stage 更省生成成本但多一次延迟。'),
|
|
175
170
|
aiEnableImageRecognition: koishi_1.Schema.boolean().default(true).description('是否启用图片识别(支持时将图片一并发送给模型;不支持的模型会自动降级为纯文本)。'),
|
|
176
171
|
aiImageMaxCount: koishi_1.Schema.natural().default(2).description('每次最多发送给模型的图片数量。'),
|
|
177
172
|
aiImageBudgetMs: koishi_1.Schema.natural().min(500).max(20000).default(6000).description('图片下载/转换的总时间预算(毫秒)。超时直接跳过图片,避免拖慢回复。'),
|
|
@@ -187,19 +182,10 @@ exports.Config = koishi_1.Schema.intersect([
|
|
|
187
182
|
aiWebSearchCacheMinutes: koishi_1.Schema.natural().min(0).max(1440).default(10).description('相同 query 的结果缓存分钟数;0=不缓存。'),
|
|
188
183
|
aiRequestTimeoutSeconds: koishi_1.Schema.natural().min(5).max(120).default(20).description('单次模型请求超时(秒)。'),
|
|
189
184
|
aiDebugPrompt: koishi_1.Schema.boolean().default(false).description('调试:把最终系统提示词与用户提示词写入日志(排查"答非所问"时打开,平时关闭)。'),
|
|
190
|
-
aiIgnoreCommandMessage: koishi_1.Schema.boolean().default(true).description('忽略看起来像命令的消息,避免干扰正常指令执行。'),
|
|
191
185
|
aiEnableDirectMentionTrigger: koishi_1.Schema.boolean().default(true).description('消息命中智能体名字时是否忽略阈值直接触发回复。'),
|
|
192
186
|
aiEnableFollowupAfterMention: koishi_1.Schema.boolean().default(true).description('点名触发后,是否跟随该用户一段时间继续对话。'),
|
|
193
187
|
aiFollowupWindowSeconds: koishi_1.Schema.natural().default(120).description('点名后跟随该用户的持续时间(秒)。'),
|
|
194
188
|
aiFollowupMaxTurns: koishi_1.Schema.natural().default(3).description('一次点名会话最多继续回复轮数。'),
|
|
195
|
-
aiOwnerPlatform: koishi_1.Schema.string().default('onebot').description('主人平台标识(用于识别主人用户,如 onebot)。'),
|
|
196
|
-
aiOwnerUserId: koishi_1.Schema.string().default('').description('主人平台用户 ID(如 QQ 号,用于记忆主人身份)。'),
|
|
197
|
-
aiHomePlatform: koishi_1.Schema.string().default('onebot').description('兼容字段:主页平台标识(建议改用 aiOwnerPlatform)。'),
|
|
198
|
-
aiHomeUserId: koishi_1.Schema.string().default('').description('兼容字段:主页平台用户 ID(建议改用 aiOwnerUserId)。'),
|
|
199
|
-
aiInterestMinScore: koishi_1.Schema.number().min(0).max(100).step(1).default(82).description('(仅 aiReplyDecision=two-stage 时生效)判定为值得回复的最低分。'),
|
|
200
|
-
aiInterestContextWindow: koishi_1.Schema.number().min(4).max(16).step(1).default(8).description('(仅 two-stage 生效)判定使用的上下文窗口条数。'),
|
|
201
|
-
aiInterestModel: koishi_1.Schema.string().default('').description('(仅 two-stage 生效)判定专用模型(留空沿用 aiModel)。'),
|
|
202
|
-
aiInterestMaxTokens: koishi_1.Schema.natural().min(256).max(16384).default(2048).description('(仅 two-stage 生效)判定的最大输出 token。'),
|
|
203
189
|
}).description('AI 回复'),
|
|
204
190
|
koishi_1.Schema.object({
|
|
205
191
|
allowedUserIds: koishi_1.Schema.array(String).role('table').default([]).description('允许直接使用群管理命令的账号 ID 白名单。命中即通过,不再校验群内角色。'),
|
package/lib/service.js
CHANGED
|
@@ -599,7 +599,8 @@ class QQGroupManagerService extends koishi_1.Service {
|
|
|
599
599
|
return `platform=${session.platform ?? 'unknown'} user=${session.userId ?? 'unknown'} guild=${session.guildId ?? 'private'}`;
|
|
600
600
|
}
|
|
601
601
|
styleText(text) {
|
|
602
|
-
|
|
602
|
+
// 旧的「Meow 风格」已移除:想要喵味请在 qqgm-chat-style 里加一个风格 skill。
|
|
603
|
+
return text;
|
|
603
604
|
}
|
|
604
605
|
getMessageText(session) {
|
|
605
606
|
const raw = session?.content ?? '';
|
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.9",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"files": [
|
package/src/ai/engine.ts
CHANGED
|
@@ -24,8 +24,8 @@ import {
|
|
|
24
24
|
AUTO_MEMORY_LABEL,
|
|
25
25
|
} from './learn';
|
|
26
26
|
import { decideTrigger } from './trigger';
|
|
27
|
-
import {
|
|
28
|
-
import { ChatProvider
|
|
27
|
+
import { buildReplyPrompt, buildUserPrompt } from './prompt';
|
|
28
|
+
import { ChatProvider } from './provider';
|
|
29
29
|
import { pickImages, resolveImages } from './vision';
|
|
30
30
|
import { selectMemoryBlocks, splitMemoryBlocks, tokenizeForMatch } from './memory';
|
|
31
31
|
import { NameResolver, MemberIdentity } from '../core/names';
|
|
@@ -97,10 +97,13 @@ function usageText(usage: any): string {
|
|
|
97
97
|
const cacheHit = usage.prompt_cache_hit_tokens
|
|
98
98
|
?? usage.cached_tokens
|
|
99
99
|
?? usage.cache_read_input_tokens;
|
|
100
|
+
const reasoning = usage.completion_tokens_details?.reasoning_tokens
|
|
101
|
+
?? usage.reasoning_tokens;
|
|
100
102
|
const parts: string[] = [];
|
|
101
103
|
if (input != null) parts.push(`in=${input}`);
|
|
102
104
|
if (output != null) parts.push(`out=${output}`);
|
|
103
105
|
if (cacheHit != null) parts.push(`cache=${cacheHit}`);
|
|
106
|
+
if (reasoning != null) parts.push(`reasoning=${reasoning}`);
|
|
104
107
|
return parts.join(',');
|
|
105
108
|
}
|
|
106
109
|
|
|
@@ -845,13 +848,16 @@ export class AiEngine {
|
|
|
845
848
|
now: this.now(),
|
|
846
849
|
lastAttemptAt: state.lastAttemptAt,
|
|
847
850
|
minIntervalMs: Math.max(0, Number(this.setting(session, 'aiMinReplyIntervalSeconds') ?? 45)) * 1000,
|
|
848
|
-
lastReplyAt: state.lastReplyAt || 0,
|
|
849
|
-
mentionCooldownMs: Math.max(0, Number(this.config.aiMentionCooldownSeconds ?? 5)) * 1000,
|
|
850
851
|
inFlight: state.inFlight,
|
|
851
852
|
mention,
|
|
852
853
|
followup,
|
|
853
854
|
rng: this.rng,
|
|
855
|
+
pseudoRandom: this.setting(session, 'aiPseudoRandom') !== false,
|
|
856
|
+
randomBoost: state.randomBoost,
|
|
857
|
+
pseudoRandomStep: Math.max(0, Number(this.setting(session, 'aiPseudoRandomStep') ?? 0.01)),
|
|
854
858
|
});
|
|
859
|
+
// 伪随机加成只由「随机掷骰」更新:冷却/阈值跳过时保持不变
|
|
860
|
+
if (typeof decision.nextBoost === 'number') state.randomBoost = decision.nextBoost;
|
|
855
861
|
|
|
856
862
|
this.log('ai-trigger', {
|
|
857
863
|
fire: decision.fire,
|
|
@@ -860,6 +866,8 @@ export class AiEngine {
|
|
|
860
866
|
threshold,
|
|
861
867
|
mention,
|
|
862
868
|
followup,
|
|
869
|
+
prob: decision.effectiveProbability,
|
|
870
|
+
boost: state.randomBoost,
|
|
863
871
|
ctx: state.records.length,
|
|
864
872
|
}, session);
|
|
865
873
|
if (!decision.fire) {
|
|
@@ -899,15 +907,6 @@ export class AiEngine {
|
|
|
899
907
|
webSearchEnabled: this.config.aiWebSearchEnabled !== false,
|
|
900
908
|
};
|
|
901
909
|
|
|
902
|
-
if (allowPass && this.config.aiReplyDecision === 'two-stage') {
|
|
903
|
-
const judge = await this.judge(promptInput);
|
|
904
|
-
if (!judge) {
|
|
905
|
-
state.counter = 0;
|
|
906
|
-
this.log('ai-pass', { by: 'judge', latencyMs: this.now() - startedAt }, session);
|
|
907
|
-
return;
|
|
908
|
-
}
|
|
909
|
-
}
|
|
910
|
-
|
|
911
910
|
const prompt = buildReplyPrompt(promptInput);
|
|
912
911
|
if (this.debugPrompt) {
|
|
913
912
|
this.host.logger.info(`[ai-debug] system=${prompt.system}\n[ai-debug] user=${prompt.user}`);
|
|
@@ -932,6 +931,14 @@ export class AiEngine {
|
|
|
932
931
|
return;
|
|
933
932
|
}
|
|
934
933
|
|
|
934
|
+
if (result.finishReason === 'length') {
|
|
935
|
+
const cap = Number(this.config.aiMaxOutputTokens ?? 1500);
|
|
936
|
+
this.host.logger?.warn?.(
|
|
937
|
+
`[ai-budget] 输出触达 max_tokens=${cap}(思考 + 回答总上限),正文可能被截断;`
|
|
938
|
+
+ `可在配置页调大 aiMaxOutputTokens | guild=${session.guildId ?? '?'}`,
|
|
939
|
+
);
|
|
940
|
+
}
|
|
941
|
+
|
|
935
942
|
const raw = String(result.text || '').trim();
|
|
936
943
|
if (!raw || PASS_RE.test(raw)) {
|
|
937
944
|
state.counter = 0;
|
|
@@ -986,7 +993,6 @@ export class AiEngine {
|
|
|
986
993
|
}
|
|
987
994
|
|
|
988
995
|
await this.host.sendReply(session, finalText);
|
|
989
|
-
state.lastReplyAt = this.now();
|
|
990
996
|
state.counter = 0;
|
|
991
997
|
this.recordSelf(session, finalText);
|
|
992
998
|
|
|
@@ -1203,27 +1209,6 @@ export class AiEngine {
|
|
|
1203
1209
|
);
|
|
1204
1210
|
}
|
|
1205
1211
|
|
|
1206
|
-
private async judge(input: any): Promise<boolean> {
|
|
1207
|
-
const prompt = buildJudgePrompt(input);
|
|
1208
|
-
const result: ChatResult = await this.provider.chat({
|
|
1209
|
-
system: prompt.system,
|
|
1210
|
-
user: prompt.user,
|
|
1211
|
-
temperature: 0.1,
|
|
1212
|
-
maxTokens: 256,
|
|
1213
|
-
});
|
|
1214
|
-
if (!result.ok || !result.text) return false;
|
|
1215
|
-
const match = result.text.match(/\{[\s\S]*\}/);
|
|
1216
|
-
if (!match) return false;
|
|
1217
|
-
try {
|
|
1218
|
-
const parsed = JSON.parse(match[0]);
|
|
1219
|
-
const score = Number(parsed?.score) || 0;
|
|
1220
|
-
const min = Number(this.config.aiInterestMinScore ?? 60);
|
|
1221
|
-
return !!parsed?.reply && score >= min;
|
|
1222
|
-
} catch {
|
|
1223
|
-
return false;
|
|
1224
|
-
}
|
|
1225
|
-
}
|
|
1226
|
-
|
|
1227
1212
|
private platformAllowed(platform: string): boolean {
|
|
1228
1213
|
const list = Array.isArray(this.config.platformFilter) ? this.config.platformFilter : ['onebot'];
|
|
1229
1214
|
return list.includes(platform);
|
package/src/ai/prompt.ts
CHANGED
|
@@ -167,19 +167,3 @@ export function buildReplyPrompt(input: PromptInput): { system: string; user: st
|
|
|
167
167
|
user: buildUserPrompt(input),
|
|
168
168
|
};
|
|
169
169
|
}
|
|
170
|
-
|
|
171
|
-
/** 两段式模式下的判定提示词(只有显式配置 aiReplyDecision=two-stage 才会用) */
|
|
172
|
-
export function buildJudgePrompt(input: PromptInput): { system: string; user: string } {
|
|
173
|
-
const system = [
|
|
174
|
-
'你是群聊回复开关判定器。',
|
|
175
|
-
`当前群里有一个机器人,自称「${input.selfName}」。`,
|
|
176
|
-
'判断机器人现在是否应该接话。',
|
|
177
|
-
'只输出 JSON:{"reply":true|false,"score":0-100,"reason":"一句话"}。不要输出任何其它文字。',
|
|
178
|
-
'标准:与机器人无关、别人正在对话、纯刷屏 → reply=false;被点名、被追问、有明显互动价值 → reply=true。',
|
|
179
|
-
].join('\n');
|
|
180
|
-
const user = buildUserPrompt({ ...input, allowPass: false }).replace(
|
|
181
|
-
/现在只输出一条回复正文。$/,
|
|
182
|
-
'现在只输出判定 JSON。',
|
|
183
|
-
);
|
|
184
|
-
return { system, user };
|
|
185
|
-
}
|
package/src/ai/provider.ts
CHANGED
|
@@ -27,6 +27,8 @@ export interface ChatResult {
|
|
|
27
27
|
degradedToText?: boolean;
|
|
28
28
|
/** 服务端 token 用量(OpenAI: usage;Gemini: usageMetadata) */
|
|
29
29
|
usage?: any;
|
|
30
|
+
/** 停止原因:length 表示被 max_tokens / 上下文上限截断 */
|
|
31
|
+
finishReason?: string;
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
export interface ProviderConfig {
|
|
@@ -185,7 +187,13 @@ export class ChatProvider {
|
|
|
185
187
|
error: `模型返回空内容(finish=${payload?.choices?.[0]?.finish_reason || 'unknown'})`,
|
|
186
188
|
};
|
|
187
189
|
}
|
|
188
|
-
return {
|
|
190
|
+
return {
|
|
191
|
+
ok: true,
|
|
192
|
+
text,
|
|
193
|
+
status: response.status,
|
|
194
|
+
usage: payload?.usage,
|
|
195
|
+
finishReason: payload?.choices?.[0]?.finish_reason,
|
|
196
|
+
};
|
|
189
197
|
} catch (error: any) {
|
|
190
198
|
const aborted = error?.name === 'AbortError';
|
|
191
199
|
return { ok: false, error: aborted ? '请求超时' : `请求失败: ${String(error?.message || error)}` };
|
|
@@ -234,7 +242,13 @@ export class ChatProvider {
|
|
|
234
242
|
.join('')
|
|
235
243
|
.trim();
|
|
236
244
|
if (!text) return { ok: false, status: response.status, error: 'Gemini 返回空内容' };
|
|
237
|
-
return {
|
|
245
|
+
return {
|
|
246
|
+
ok: true,
|
|
247
|
+
text,
|
|
248
|
+
status: response.status,
|
|
249
|
+
usage: payload?.usageMetadata,
|
|
250
|
+
finishReason: payload?.candidates?.[0]?.finishReason,
|
|
251
|
+
};
|
|
238
252
|
} catch (error: any) {
|
|
239
253
|
const aborted = error?.name === 'AbortError';
|
|
240
254
|
return { ok: false, error: aborted ? '请求超时' : `请求失败: ${String(error?.message || error)}` };
|
package/src/ai/state.ts
CHANGED
|
@@ -41,10 +41,11 @@ export class GroupState {
|
|
|
41
41
|
records: ChatRecord[] = [];
|
|
42
42
|
/** 自上次"完整考虑"(真正调用了模型)以来累计的消息数 */
|
|
43
43
|
counter = 0;
|
|
44
|
-
lastReplyAt = 0;
|
|
45
44
|
lastAttemptAt = 0;
|
|
46
45
|
/** 上次发「冷却中」提示的时间,用于避免 @ 刷屏时反复提示 */
|
|
47
46
|
lastCooldownNoticeAt = 0;
|
|
47
|
+
/** 伪随机加成:随机未命中时累加,命中后归零 */
|
|
48
|
+
randomBoost = 0;
|
|
48
49
|
inFlight = false;
|
|
49
50
|
followup: FollowupState | null = null;
|
|
50
51
|
seen = new Map<string, number>();
|
package/src/ai/trigger.ts
CHANGED
|
@@ -17,13 +17,16 @@ export interface TriggerInput {
|
|
|
17
17
|
now: number;
|
|
18
18
|
lastAttemptAt: number;
|
|
19
19
|
minIntervalMs: number;
|
|
20
|
-
/** 兼容字段:旧版按“上次回复”计算的 @ 冷却,已合并进 minIntervalMs */
|
|
21
|
-
lastReplyAt?: number;
|
|
22
|
-
mentionCooldownMs?: number;
|
|
23
20
|
inFlight: boolean;
|
|
24
21
|
mention: boolean;
|
|
25
22
|
followup: boolean;
|
|
26
23
|
rng: () => number;
|
|
24
|
+
/** 伪随机:随机未命中时把下一次概率往上抬,直到必定触发 */
|
|
25
|
+
pseudoRandom?: boolean;
|
|
26
|
+
/** 当前已累计的概率加成(0~1) */
|
|
27
|
+
randomBoost?: number;
|
|
28
|
+
/** 每次未命中增加多少(默认 0.01) */
|
|
29
|
+
pseudoRandomStep?: number;
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
export interface TriggerDecision {
|
|
@@ -32,6 +35,10 @@ export interface TriggerDecision {
|
|
|
32
35
|
reason: string;
|
|
33
36
|
/** 冷却中时距离可以再次调用模型的剩余毫秒数 */
|
|
34
37
|
remainingMs?: number;
|
|
38
|
+
/** 本次判定后应保存的伪随机加成;未发生随机掷骰时为 undefined(保持不变) */
|
|
39
|
+
nextBoost?: number;
|
|
40
|
+
/** 本次实际使用的概率(基础值 + 加成),用于日志排查 */
|
|
41
|
+
effectiveProbability?: number;
|
|
35
42
|
}
|
|
36
43
|
|
|
37
44
|
export function decideTrigger(input: TriggerInput): TriggerDecision {
|
|
@@ -66,14 +73,44 @@ export function decideTrigger(input: TriggerInput): TriggerDecision {
|
|
|
66
73
|
};
|
|
67
74
|
}
|
|
68
75
|
|
|
69
|
-
// ---------- 4)
|
|
76
|
+
// ---------- 4) 概率(支持伪随机:连续未命中会逐步抬高概率) ----------
|
|
70
77
|
const needRandom = input.mode === 'random' || input.mode === 'hybrid';
|
|
71
78
|
if (needRandom) {
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
79
|
+
const base = Math.max(0, Math.min(1, Number(input.probability) || 0));
|
|
80
|
+
const boost = Math.max(0, Number(input.randomBoost) || 0);
|
|
81
|
+
const effective = Math.min(1, base + boost);
|
|
82
|
+
const round4 = (value: number) => Math.round(value * 10000) / 10000;
|
|
83
|
+
|
|
84
|
+
if (effective <= 0) {
|
|
85
|
+
return {
|
|
86
|
+
fire: false,
|
|
87
|
+
forced: false,
|
|
88
|
+
reason: 'random-disabled',
|
|
89
|
+
nextBoost: round4(boost),
|
|
90
|
+
effectiveProbability: 0,
|
|
91
|
+
};
|
|
76
92
|
}
|
|
93
|
+
|
|
94
|
+
// 加成到 1 时必定触发,不再消耗随机数
|
|
95
|
+
if (effective >= 1 || input.rng() < effective) {
|
|
96
|
+
return {
|
|
97
|
+
fire: true,
|
|
98
|
+
forced: false,
|
|
99
|
+
reason: `trigger(${input.mode})`,
|
|
100
|
+
nextBoost: 0,
|
|
101
|
+
effectiveProbability: round4(effective),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const step = Math.max(0, Number(input.pseudoRandomStep) || 0);
|
|
106
|
+
const nextBoost = input.pseudoRandom ? Math.min(1, round4(boost + step)) : round4(boost);
|
|
107
|
+
return {
|
|
108
|
+
fire: false,
|
|
109
|
+
forced: false,
|
|
110
|
+
reason: `random-miss(${effective.toFixed(2)})`,
|
|
111
|
+
nextBoost,
|
|
112
|
+
effectiveProbability: round4(effective),
|
|
113
|
+
};
|
|
77
114
|
}
|
|
78
115
|
|
|
79
116
|
return { fire: true, forced: false, reason: `trigger(${input.mode})` };
|
package/src/index.ts
CHANGED
|
@@ -15,10 +15,6 @@ export const Config = Schema.intersect([
|
|
|
15
15
|
cmdCustom: Schema.string().default('[custom]').description('自定义指令集前缀,用法:[custom]。未配置自定义指令时提示「目前还没有指令」。'),
|
|
16
16
|
cmdVersion: Schema.string().default('[Version]').description('插件信息指令前缀,用法:[Version]。返回当前版本、作者、GitHub 与 npm 地址。'),
|
|
17
17
|
platformFilter: Schema.array(String).default(['onebot']).description('允许启用管理功能的平台列表。'),
|
|
18
|
-
responseStyle: Schema.union([
|
|
19
|
-
Schema.const('plain').description('普通输出'),
|
|
20
|
-
Schema.const('meow').description('Meow 风格输出'),
|
|
21
|
-
]).role('radio').default('plain').description('群聊中指令返回的文本风格。'),
|
|
22
18
|
dryRun: Schema.boolean().default(false).description('演练模式:仅输出计划动作,不执行群管理操作。'),
|
|
23
19
|
}).description('基础设置'),
|
|
24
20
|
Schema.object({
|
|
@@ -34,6 +30,8 @@ export const Config = Schema.intersect([
|
|
|
34
30
|
enableAiReply: Schema.boolean().description('该群是否启用 AI 回复(留空则跟随全局设置)。'),
|
|
35
31
|
aiMessageThreshold: Schema.natural().description('该群触发的消息数阈值(留空跟随全局 aiMessageThreshold)。'),
|
|
36
32
|
aiRandomReplyProbability: Schema.percent().description('该群随机触发概率(0~1,控制台按百分比显示;留空跟随全局)。'),
|
|
33
|
+
aiPseudoRandom: Schema.boolean().description('该群是否启用伪随机(连续未命中逐步提高概率;留空跟随全局)。'),
|
|
34
|
+
aiPseudoRandomStep: Schema.number().min(0).max(1).step(0.001).description('该群伪随机每次未命中增加的概率(留空跟随全局)。'),
|
|
37
35
|
aiMinReplyIntervalSeconds: Schema.natural().description('该群模型调用冷却(秒;留空跟随全局 aiMinReplyIntervalSeconds)。'),
|
|
38
36
|
aiCooldownNotice: Schema.boolean().description('该群被 @ 但处于冷却时是否提示还剩多久(留空跟随全局)。'),
|
|
39
37
|
bannedWords: Schema.array(String).role('table').default([]).description('该群专属违禁词列表(同样支持“关键词|分值”与顺序模糊匹配)。'),
|
|
@@ -128,7 +126,6 @@ export const Config = Schema.intersect([
|
|
|
128
126
|
aiBaseUrl: Schema.string().default('https://api.openai.com/v1').description('接口基础地址(OpenAI 兼容模式需以 /v1 结尾;Gemini 模式可留默认)。'),
|
|
129
127
|
aiModel: Schema.string().default('gpt-4o-mini').description('模型名称,如 gpt-4o-mini / doubao-1.5-lite / gemini-2.0-flash。'),
|
|
130
128
|
aiAgentName: Schema.string().default('bot').description('默认智能体自称(可在配置页修改)。'),
|
|
131
|
-
aiMentionCooldownSeconds: Schema.natural().min(0).max(3600).default(5).description('(兼容字段)旧的 @ 冷却;现在所有模型调用统一走 aiMinReplyIntervalSeconds。'),
|
|
132
129
|
aiCooldownNotice: Schema.boolean().default(true).description('被 @ 但处于模型调用冷却时,是否在群里提示还剩多久(纯本地消息,不调用模型)。'),
|
|
133
130
|
aiCooldownNoticeText: Schema.string().default('还在冷却,{seconds} 秒后再叫我。').description('冷却提示文案,可用 {seconds} 与 {minutes} 占位。'),
|
|
134
131
|
aiCooldownNoticeIntervalSeconds: Schema.natural().min(0).max(600).default(20).description('同一群两次冷却提示的最小间隔(秒),防止连续 @ 刷屏;0 = 不限制。'),
|
|
@@ -150,12 +147,14 @@ export const Config = Schema.intersect([
|
|
|
150
147
|
]).role('radio').default('hybrid').description('AI 触发策略:threshold 只看消息数、random 只看概率、hybrid 两者都要满足。@点名与点名后跟随会越过这些闸门。是否真正接话由模型在回复时用 <pass/> 自行决定。'),
|
|
151
148
|
aiMessageThreshold: Schema.natural().default(16).description('阈值触发所需累计消息数。threshold / hybrid 模式下未达此数一律不触发;计数器在模型给出回复或主动放弃后清零。'),
|
|
152
149
|
aiRandomReplyProbability: Schema.percent().default(0.08).description('随机触发概率(每条消息掷一次骰)。random / hybrid 模式下未掷中直接跳过,不会调用 AI 接口。填 0 等同于关闭随机触发。'),
|
|
150
|
+
aiPseudoRandom: Schema.boolean().default(true).description('伪随机:随机触发没命中时,下一次概率按步长累加(命中后归零),加到 1 时必定回复,避免真随机长期不触发。'),
|
|
151
|
+
aiPseudoRandomStep: Schema.number().min(0).max(1).step(0.001).default(0.01).description('伪随机每次未命中增加的概率(默认 0.01 = 1%)。只在真正掷骰且未命中时累加,冷却/阈值跳过不算。'),
|
|
153
152
|
aiMinReplyIntervalSeconds: Schema.natural().default(45).description('同一群两次真正调用模型的最短间隔(秒)。'),
|
|
154
153
|
aiContextWindow: Schema.natural().default(30).description('参与推理的最近消息条数(建议 20~40;太小会导致模型看不到前文)。'),
|
|
155
154
|
aiContextMaxChars: Schema.natural().min(0).max(20000).default(0).description('历史上下文的字数上限:超过后从最旧的消息开始丢(至少保留最近 4 条)。0 = 不限。想省 token 可设 2500~3500。'),
|
|
156
155
|
aiStyleMaxChars: Schema.natural().min(0).max(20000).default(0).description('外部插件注入的「说话风格」段每条最多保留多少字。0 = 不限。风格 skill 很长时可设 1200~1800 显著省 token。'),
|
|
157
156
|
aiTemperature: Schema.number().min(0).max(2).step(0.1).default(0.8).description('生成温度(0~2)。群聊接话建议 0.7~0.9,过高会跑题、复述、发散。'),
|
|
158
|
-
aiMaxOutputTokens: Schema.natural().default(
|
|
157
|
+
aiMaxOutputTokens: Schema.natural().min(100).max(131072).default(1500).description('思考 + 回答的总 token 上限(API 的 max_tokens,不是只限制正文)。思考模式开启时思维链也计入这里:设得太小,预算会被思考吃掉、正文被截断;设得太大则单次成本上限更高。群聊接话建议 1000~2000。'),
|
|
159
158
|
aiMaxReplyChars: Schema.natural().min(20).max(500).default(120).description('单条回复的最大字符数,超出会在句末截断。'),
|
|
160
159
|
aiQuoteReplyMode: Schema.union([
|
|
161
160
|
Schema.const('random').description('随机决定'),
|
|
@@ -165,10 +164,6 @@ export const Config = Schema.intersect([
|
|
|
165
164
|
aiQuoteReplyProbability: Schema.number().min(0).max(1).step(0.05).default(0.5).hidden().description('引用概率(仅 random 模式生效)。'),
|
|
166
165
|
aiReadForwardMessage: Schema.boolean().default(true).description('读取合并转发聊天记录的内容,作为上下文的一部分。'),
|
|
167
166
|
aiForwardMaxNodes: Schema.natural().min(1).max(50).default(20).description('单条合并转发最多读取多少条子消息。'),
|
|
168
|
-
aiReplyDecision: Schema.union([
|
|
169
|
-
Schema.const('single').description('一次调用:模型直接输出回复,或用 <pass/> 放弃(推荐)'),
|
|
170
|
-
Schema.const('two-stage').description('两次调用:先判定是否值得回复,再生成正文'),
|
|
171
|
-
]).role('radio').default('single').description('接话决策方式。single 更快、决策与正文一致;two-stage 更省生成成本但多一次延迟。'),
|
|
172
167
|
aiEnableImageRecognition: Schema.boolean().default(true).description('是否启用图片识别(支持时将图片一并发送给模型;不支持的模型会自动降级为纯文本)。'),
|
|
173
168
|
aiImageMaxCount: Schema.natural().default(2).description('每次最多发送给模型的图片数量。'),
|
|
174
169
|
aiImageBudgetMs: Schema.natural().min(500).max(20000).default(6000).description('图片下载/转换的总时间预算(毫秒)。超时直接跳过图片,避免拖慢回复。'),
|
|
@@ -184,19 +179,10 @@ export const Config = Schema.intersect([
|
|
|
184
179
|
aiWebSearchCacheMinutes: Schema.natural().min(0).max(1440).default(10).description('相同 query 的结果缓存分钟数;0=不缓存。'),
|
|
185
180
|
aiRequestTimeoutSeconds: Schema.natural().min(5).max(120).default(20).description('单次模型请求超时(秒)。'),
|
|
186
181
|
aiDebugPrompt: Schema.boolean().default(false).description('调试:把最终系统提示词与用户提示词写入日志(排查"答非所问"时打开,平时关闭)。'),
|
|
187
|
-
aiIgnoreCommandMessage: Schema.boolean().default(true).description('忽略看起来像命令的消息,避免干扰正常指令执行。'),
|
|
188
182
|
aiEnableDirectMentionTrigger: Schema.boolean().default(true).description('消息命中智能体名字时是否忽略阈值直接触发回复。'),
|
|
189
183
|
aiEnableFollowupAfterMention: Schema.boolean().default(true).description('点名触发后,是否跟随该用户一段时间继续对话。'),
|
|
190
184
|
aiFollowupWindowSeconds: Schema.natural().default(120).description('点名后跟随该用户的持续时间(秒)。'),
|
|
191
185
|
aiFollowupMaxTurns: Schema.natural().default(3).description('一次点名会话最多继续回复轮数。'),
|
|
192
|
-
aiOwnerPlatform: Schema.string().default('onebot').description('主人平台标识(用于识别主人用户,如 onebot)。'),
|
|
193
|
-
aiOwnerUserId: Schema.string().default('').description('主人平台用户 ID(如 QQ 号,用于记忆主人身份)。'),
|
|
194
|
-
aiHomePlatform: Schema.string().default('onebot').description('兼容字段:主页平台标识(建议改用 aiOwnerPlatform)。'),
|
|
195
|
-
aiHomeUserId: Schema.string().default('').description('兼容字段:主页平台用户 ID(建议改用 aiOwnerUserId)。'),
|
|
196
|
-
aiInterestMinScore: Schema.number().min(0).max(100).step(1).default(82).description('(仅 aiReplyDecision=two-stage 时生效)判定为值得回复的最低分。'),
|
|
197
|
-
aiInterestContextWindow: Schema.number().min(4).max(16).step(1).default(8).description('(仅 two-stage 生效)判定使用的上下文窗口条数。'),
|
|
198
|
-
aiInterestModel: Schema.string().default('').description('(仅 two-stage 生效)判定专用模型(留空沿用 aiModel)。'),
|
|
199
|
-
aiInterestMaxTokens: Schema.natural().min(256).max(16384).default(2048).description('(仅 two-stage 生效)判定的最大输出 token。'),
|
|
200
186
|
}).description('AI 回复'),
|
|
201
187
|
Schema.object({
|
|
202
188
|
allowedUserIds: Schema.array(String).role('table').default([]).description('允许直接使用群管理命令的账号 ID 白名单。命中即通过,不再校验群内角色。'),
|
package/src/service.js
CHANGED
|
@@ -602,7 +602,8 @@ class QQGroupManagerService extends koishi_1.Service {
|
|
|
602
602
|
return `platform=${session.platform ?? 'unknown'} user=${session.userId ?? 'unknown'} guild=${session.guildId ?? 'private'}`;
|
|
603
603
|
}
|
|
604
604
|
styleText(text) {
|
|
605
|
-
|
|
605
|
+
// 旧的「Meow 风格」已移除:想要喵味请在 qqgm-chat-style 里加一个风格 skill。
|
|
606
|
+
return text;
|
|
606
607
|
}
|
|
607
608
|
getMessageText(session) {
|
|
608
609
|
const raw = session?.content ?? '';
|