@nestim/koishi-plugin-qq-group-manager 1.4.8 → 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 CHANGED
@@ -2,6 +2,37 @@
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
+
5
36
  ## 1.4.8
6
37
 
7
38
  ### 新功能
@@ -12,7 +12,7 @@
12
12
  * - 允许模型用 <pass/> 主动放弃,放弃也重置计数,避免每条消息都空转调用。
13
13
  */
14
14
  import { AiState, ChatRecord } from './state';
15
- import { ChatProvider, ChatResult } from './provider';
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,8 +772,6 @@ 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,
@@ -826,14 +828,6 @@ class AiEngine {
826
828
  webSearch,
827
829
  webSearchEnabled: this.config.aiWebSearchEnabled !== false,
828
830
  };
829
- if (allowPass && this.config.aiReplyDecision === 'two-stage') {
830
- const judge = await this.judge(promptInput);
831
- if (!judge) {
832
- state.counter = 0;
833
- this.log('ai-pass', { by: 'judge', latencyMs: this.now() - startedAt }, session);
834
- return;
835
- }
836
- }
837
831
  const prompt = (0, prompt_1.buildReplyPrompt)(promptInput);
838
832
  if (this.debugPrompt) {
839
833
  this.host.logger.info(`[ai-debug] system=${prompt.system}\n[ai-debug] user=${prompt.user}`);
@@ -855,6 +849,11 @@ class AiEngine {
855
849
  }, session);
856
850
  return;
857
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
+ }
858
857
  const raw = String(result.text || '').trim();
859
858
  if (!raw || PASS_RE.test(raw)) {
860
859
  state.counter = 0;
@@ -905,7 +904,6 @@ class AiEngine {
905
904
  return;
906
905
  }
907
906
  await this.host.sendReply(session, finalText);
908
- state.lastReplyAt = this.now();
909
907
  state.counter = 0;
910
908
  this.recordSelf(session, finalText);
911
909
  if (mention)
@@ -1125,29 +1123,6 @@ class AiEngine {
1125
1123
  return [];
1126
1124
  return (0, vision_1.resolveImages)(items, (ref) => this.host.resolveImage(ref, session), { maxCount, budgetMs: Number(this.config.aiImageBudgetMs ?? 6000) });
1127
1125
  }
1128
- async judge(input) {
1129
- const prompt = (0, prompt_1.buildJudgePrompt)(input);
1130
- const result = await this.provider.chat({
1131
- system: prompt.system,
1132
- user: prompt.user,
1133
- temperature: 0.1,
1134
- maxTokens: 256,
1135
- });
1136
- if (!result.ok || !result.text)
1137
- return false;
1138
- const match = result.text.match(/\{[\s\S]*\}/);
1139
- if (!match)
1140
- return false;
1141
- try {
1142
- const parsed = JSON.parse(match[0]);
1143
- const score = Number(parsed?.score) || 0;
1144
- const min = Number(this.config.aiInterestMinScore ?? 60);
1145
- return !!parsed?.reply && score >= min;
1146
- }
1147
- catch {
1148
- return false;
1149
- }
1150
- }
1151
1126
  platformAllowed(platform) {
1152
1127
  const list = Array.isArray(this.config.platformFilter) ? this.config.platformFilter : ['onebot'];
1153
1128
  return list.includes(platform);
@@ -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
- }
@@ -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;
@@ -144,7 +144,13 @@ class ChatProvider {
144
144
  error: `模型返回空内容(finish=${payload?.choices?.[0]?.finish_reason || 'unknown'})`,
145
145
  };
146
146
  }
147
- return { ok: true, text, status: response.status, usage: payload?.usage };
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 { ok: true, text, status: response.status, usage: payload?.usageMetadata };
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,7 +37,6 @@ 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;
package/lib/ai/state.js CHANGED
@@ -13,7 +13,6 @@ class GroupState {
13
13
  records = [];
14
14
  /** 自上次"完整考虑"(真正调用了模型)以来累计的消息数 */
15
15
  counter = 0;
16
- lastReplyAt = 0;
17
16
  lastAttemptAt = 0;
18
17
  /** 上次发「冷却中」提示的时间,用于避免 @ 刷屏时反复提示 */
19
18
  lastCooldownNoticeAt = 0;
@@ -16,9 +16,6 @@ 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;
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[]>;
@@ -147,7 +146,6 @@ export declare const Config: Schema<Schemastery.ObjectS<{
147
146
  aiBaseUrl: Schema<string, string>;
148
147
  aiModel: Schema<string, string>;
149
148
  aiAgentName: Schema<string, string>;
150
- aiMentionCooldownSeconds: Schema<number, number>;
151
149
  aiCooldownNotice: Schema<boolean, boolean>;
152
150
  aiCooldownNoticeText: Schema<string, string>;
153
151
  aiCooldownNoticeIntervalSeconds: Schema<number, number>;
@@ -182,7 +180,6 @@ export declare const Config: Schema<Schemastery.ObjectS<{
182
180
  aiQuoteReplyProbability: Schema<number, number>;
183
181
  aiReadForwardMessage: Schema<boolean, boolean>;
184
182
  aiForwardMaxNodes: Schema<number, number>;
185
- aiReplyDecision: Schema<"two-stage" | "single", "two-stage" | "single">;
186
183
  aiEnableImageRecognition: Schema<boolean, boolean>;
187
184
  aiImageMaxCount: Schema<number, number>;
188
185
  aiImageBudgetMs: Schema<number, number>;
@@ -194,19 +191,10 @@ export declare const Config: Schema<Schemastery.ObjectS<{
194
191
  aiWebSearchCacheMinutes: Schema<number, number>;
195
192
  aiRequestTimeoutSeconds: Schema<number, number>;
196
193
  aiDebugPrompt: Schema<boolean, boolean>;
197
- aiIgnoreCommandMessage: Schema<boolean, boolean>;
198
194
  aiEnableDirectMentionTrigger: Schema<boolean, boolean>;
199
195
  aiEnableFollowupAfterMention: Schema<boolean, boolean>;
200
196
  aiFollowupWindowSeconds: Schema<number, number>;
201
197
  aiFollowupMaxTurns: Schema<number, number>;
202
- aiOwnerPlatform: Schema<string, string>;
203
- aiOwnerUserId: Schema<string, string>;
204
- aiHomePlatform: Schema<string, string>;
205
- aiHomeUserId: Schema<string, string>;
206
- aiInterestMinScore: Schema<number, number>;
207
- aiInterestContextWindow: Schema<number, number>;
208
- aiInterestModel: Schema<string, string>;
209
- aiInterestMaxTokens: Schema<number, number>;
210
198
  }> | Schemastery.ObjectS<{
211
199
  allowedUserIds: Schema<string[], string[]>;
212
200
  allowGroupOwner: Schema<boolean, boolean>;
@@ -228,7 +216,6 @@ export declare const Config: Schema<Schemastery.ObjectS<{
228
216
  cmdCustom: string;
229
217
  cmdVersion: string;
230
218
  platformFilter: string[];
231
- responseStyle: "plain" | "meow";
232
219
  dryRun: boolean;
233
220
  } & import("koishi").Dict & {
234
221
  bannedWords: string[];
@@ -329,7 +316,6 @@ export declare const Config: Schema<Schemastery.ObjectS<{
329
316
  aiBaseUrl: string;
330
317
  aiModel: string;
331
318
  aiAgentName: string;
332
- aiMentionCooldownSeconds: number;
333
319
  aiCooldownNotice: boolean;
334
320
  aiCooldownNoticeText: string;
335
321
  aiCooldownNoticeIntervalSeconds: number;
@@ -360,7 +346,6 @@ export declare const Config: Schema<Schemastery.ObjectS<{
360
346
  aiQuoteReplyProbability: number;
361
347
  aiReadForwardMessage: boolean;
362
348
  aiForwardMaxNodes: number;
363
- aiReplyDecision: "two-stage" | "single";
364
349
  aiEnableImageRecognition: boolean;
365
350
  aiImageMaxCount: number;
366
351
  aiImageBudgetMs: number;
@@ -372,19 +357,10 @@ export declare const Config: Schema<Schemastery.ObjectS<{
372
357
  aiWebSearchCacheMinutes: number;
373
358
  aiRequestTimeoutSeconds: number;
374
359
  aiDebugPrompt: boolean;
375
- aiIgnoreCommandMessage: boolean;
376
360
  aiEnableDirectMentionTrigger: boolean;
377
361
  aiEnableFollowupAfterMention: boolean;
378
362
  aiFollowupWindowSeconds: number;
379
363
  aiFollowupMaxTurns: number;
380
- aiOwnerPlatform: string;
381
- aiOwnerUserId: string;
382
- aiHomePlatform: string;
383
- aiHomeUserId: string;
384
- aiInterestMinScore: number;
385
- aiInterestContextWindow: number;
386
- aiInterestModel: string;
387
- aiInterestMaxTokens: number;
388
364
  } & {
389
365
  allowedUserIds: string[];
390
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({
@@ -133,7 +129,6 @@ exports.Config = koishi_1.Schema.intersect([
133
129
  aiBaseUrl: koishi_1.Schema.string().default('https://api.openai.com/v1').description('接口基础地址(OpenAI 兼容模式需以 /v1 结尾;Gemini 模式可留默认)。'),
134
130
  aiModel: koishi_1.Schema.string().default('gpt-4o-mini').description('模型名称,如 gpt-4o-mini / doubao-1.5-lite / gemini-2.0-flash。'),
135
131
  aiAgentName: koishi_1.Schema.string().default('bot').description('默认智能体自称(可在配置页修改)。'),
136
- aiMentionCooldownSeconds: koishi_1.Schema.natural().min(0).max(3600).default(5).description('(兼容字段)旧的 @ 冷却;现在所有模型调用统一走 aiMinReplyIntervalSeconds。'),
137
132
  aiCooldownNotice: koishi_1.Schema.boolean().default(true).description('被 @ 但处于模型调用冷却时,是否在群里提示还剩多久(纯本地消息,不调用模型)。'),
138
133
  aiCooldownNoticeText: koishi_1.Schema.string().default('还在冷却,{seconds} 秒后再叫我。').description('冷却提示文案,可用 {seconds} 与 {minutes} 占位。'),
139
134
  aiCooldownNoticeIntervalSeconds: koishi_1.Schema.natural().min(0).max(600).default(20).description('同一群两次冷却提示的最小间隔(秒),防止连续 @ 刷屏;0 = 不限制。'),
@@ -162,7 +157,7 @@ exports.Config = koishi_1.Schema.intersect([
162
157
  aiContextMaxChars: koishi_1.Schema.natural().min(0).max(20000).default(0).description('历史上下文的字数上限:超过后从最旧的消息开始丢(至少保留最近 4 条)。0 = 不限。想省 token 可设 2500~3500。'),
163
158
  aiStyleMaxChars: koishi_1.Schema.natural().min(0).max(20000).default(0).description('外部插件注入的「说话风格」段每条最多保留多少字。0 = 不限。风格 skill 很长时可设 1200~1800 显著省 token。'),
164
159
  aiTemperature: koishi_1.Schema.number().min(0).max(2).step(0.1).default(0.8).description('生成温度(0~2)。群聊接话建议 0.7~0.9,过高会跑题、复述、发散。'),
165
- aiMaxOutputTokens: koishi_1.Schema.natural().default(400).description('AI 最大输出 token 数。群聊一句话不需要太大,过大会增加延迟。'),
160
+ aiMaxOutputTokens: koishi_1.Schema.natural().min(100).max(131072).default(1500).description('思考 + 回答的总 token 上限(API 的 max_tokens,不是只限制正文)。思考模式开启时思维链也计入这里:设得太小,预算会被思考吃掉、正文被截断;设得太大则单次成本上限更高。群聊接话建议 1000~2000。'),
166
161
  aiMaxReplyChars: koishi_1.Schema.natural().min(20).max(500).default(120).description('单条回复的最大字符数,超出会在句末截断。'),
167
162
  aiQuoteReplyMode: koishi_1.Schema.union([
168
163
  koishi_1.Schema.const('random').description('随机决定'),
@@ -172,10 +167,6 @@ exports.Config = koishi_1.Schema.intersect([
172
167
  aiQuoteReplyProbability: koishi_1.Schema.number().min(0).max(1).step(0.05).default(0.5).hidden().description('引用概率(仅 random 模式生效)。'),
173
168
  aiReadForwardMessage: koishi_1.Schema.boolean().default(true).description('读取合并转发聊天记录的内容,作为上下文的一部分。'),
174
169
  aiForwardMaxNodes: koishi_1.Schema.natural().min(1).max(50).default(20).description('单条合并转发最多读取多少条子消息。'),
175
- aiReplyDecision: koishi_1.Schema.union([
176
- koishi_1.Schema.const('single').description('一次调用:模型直接输出回复,或用 <pass/> 放弃(推荐)'),
177
- koishi_1.Schema.const('two-stage').description('两次调用:先判定是否值得回复,再生成正文'),
178
- ]).role('radio').default('single').description('接话决策方式。single 更快、决策与正文一致;two-stage 更省生成成本但多一次延迟。'),
179
170
  aiEnableImageRecognition: koishi_1.Schema.boolean().default(true).description('是否启用图片识别(支持时将图片一并发送给模型;不支持的模型会自动降级为纯文本)。'),
180
171
  aiImageMaxCount: koishi_1.Schema.natural().default(2).description('每次最多发送给模型的图片数量。'),
181
172
  aiImageBudgetMs: koishi_1.Schema.natural().min(500).max(20000).default(6000).description('图片下载/转换的总时间预算(毫秒)。超时直接跳过图片,避免拖慢回复。'),
@@ -191,19 +182,10 @@ exports.Config = koishi_1.Schema.intersect([
191
182
  aiWebSearchCacheMinutes: koishi_1.Schema.natural().min(0).max(1440).default(10).description('相同 query 的结果缓存分钟数;0=不缓存。'),
192
183
  aiRequestTimeoutSeconds: koishi_1.Schema.natural().min(5).max(120).default(20).description('单次模型请求超时(秒)。'),
193
184
  aiDebugPrompt: koishi_1.Schema.boolean().default(false).description('调试:把最终系统提示词与用户提示词写入日志(排查"答非所问"时打开,平时关闭)。'),
194
- aiIgnoreCommandMessage: koishi_1.Schema.boolean().default(true).description('忽略看起来像命令的消息,避免干扰正常指令执行。'),
195
185
  aiEnableDirectMentionTrigger: koishi_1.Schema.boolean().default(true).description('消息命中智能体名字时是否忽略阈值直接触发回复。'),
196
186
  aiEnableFollowupAfterMention: koishi_1.Schema.boolean().default(true).description('点名触发后,是否跟随该用户一段时间继续对话。'),
197
187
  aiFollowupWindowSeconds: koishi_1.Schema.natural().default(120).description('点名后跟随该用户的持续时间(秒)。'),
198
188
  aiFollowupMaxTurns: koishi_1.Schema.natural().default(3).description('一次点名会话最多继续回复轮数。'),
199
- aiOwnerPlatform: koishi_1.Schema.string().default('onebot').description('主人平台标识(用于识别主人用户,如 onebot)。'),
200
- aiOwnerUserId: koishi_1.Schema.string().default('').description('主人平台用户 ID(如 QQ 号,用于记忆主人身份)。'),
201
- aiHomePlatform: koishi_1.Schema.string().default('onebot').description('兼容字段:主页平台标识(建议改用 aiOwnerPlatform)。'),
202
- aiHomeUserId: koishi_1.Schema.string().default('').description('兼容字段:主页平台用户 ID(建议改用 aiOwnerUserId)。'),
203
- aiInterestMinScore: koishi_1.Schema.number().min(0).max(100).step(1).default(82).description('(仅 aiReplyDecision=two-stage 时生效)判定为值得回复的最低分。'),
204
- aiInterestContextWindow: koishi_1.Schema.number().min(4).max(16).step(1).default(8).description('(仅 two-stage 生效)判定使用的上下文窗口条数。'),
205
- aiInterestModel: koishi_1.Schema.string().default('').description('(仅 two-stage 生效)判定专用模型(留空沿用 aiModel)。'),
206
- aiInterestMaxTokens: koishi_1.Schema.natural().min(256).max(16384).default(2048).description('(仅 two-stage 生效)判定的最大输出 token。'),
207
189
  }).description('AI 回复'),
208
190
  koishi_1.Schema.object({
209
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
- return this.config.responseStyle === 'meow' ? `喵~ ${text}` : text;
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.8",
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 { buildJudgePrompt, buildReplyPrompt, buildUserPrompt, PASS_TOKEN } from './prompt';
28
- import { ChatProvider, ChatResult } from './provider';
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,8 +848,6 @@ 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,
@@ -906,15 +907,6 @@ export class AiEngine {
906
907
  webSearchEnabled: this.config.aiWebSearchEnabled !== false,
907
908
  };
908
909
 
909
- if (allowPass && this.config.aiReplyDecision === 'two-stage') {
910
- const judge = await this.judge(promptInput);
911
- if (!judge) {
912
- state.counter = 0;
913
- this.log('ai-pass', { by: 'judge', latencyMs: this.now() - startedAt }, session);
914
- return;
915
- }
916
- }
917
-
918
910
  const prompt = buildReplyPrompt(promptInput);
919
911
  if (this.debugPrompt) {
920
912
  this.host.logger.info(`[ai-debug] system=${prompt.system}\n[ai-debug] user=${prompt.user}`);
@@ -939,6 +931,14 @@ export class AiEngine {
939
931
  return;
940
932
  }
941
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
+
942
942
  const raw = String(result.text || '').trim();
943
943
  if (!raw || PASS_RE.test(raw)) {
944
944
  state.counter = 0;
@@ -993,7 +993,6 @@ export class AiEngine {
993
993
  }
994
994
 
995
995
  await this.host.sendReply(session, finalText);
996
- state.lastReplyAt = this.now();
997
996
  state.counter = 0;
998
997
  this.recordSelf(session, finalText);
999
998
 
@@ -1210,27 +1209,6 @@ export class AiEngine {
1210
1209
  );
1211
1210
  }
1212
1211
 
1213
- private async judge(input: any): Promise<boolean> {
1214
- const prompt = buildJudgePrompt(input);
1215
- const result: ChatResult = await this.provider.chat({
1216
- system: prompt.system,
1217
- user: prompt.user,
1218
- temperature: 0.1,
1219
- maxTokens: 256,
1220
- });
1221
- if (!result.ok || !result.text) return false;
1222
- const match = result.text.match(/\{[\s\S]*\}/);
1223
- if (!match) return false;
1224
- try {
1225
- const parsed = JSON.parse(match[0]);
1226
- const score = Number(parsed?.score) || 0;
1227
- const min = Number(this.config.aiInterestMinScore ?? 60);
1228
- return !!parsed?.reply && score >= min;
1229
- } catch {
1230
- return false;
1231
- }
1232
- }
1233
-
1234
1212
  private platformAllowed(platform: string): boolean {
1235
1213
  const list = Array.isArray(this.config.platformFilter) ? this.config.platformFilter : ['onebot'];
1236
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
- }
@@ -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 { ok: true, text, status: response.status, usage: payload?.usage };
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 { ok: true, text, status: response.status, usage: payload?.usageMetadata };
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,7 +41,6 @@ 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;
package/src/ai/trigger.ts CHANGED
@@ -17,9 +17,6 @@ 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;
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({
@@ -130,7 +126,6 @@ export const Config = Schema.intersect([
130
126
  aiBaseUrl: Schema.string().default('https://api.openai.com/v1').description('接口基础地址(OpenAI 兼容模式需以 /v1 结尾;Gemini 模式可留默认)。'),
131
127
  aiModel: Schema.string().default('gpt-4o-mini').description('模型名称,如 gpt-4o-mini / doubao-1.5-lite / gemini-2.0-flash。'),
132
128
  aiAgentName: Schema.string().default('bot').description('默认智能体自称(可在配置页修改)。'),
133
- aiMentionCooldownSeconds: Schema.natural().min(0).max(3600).default(5).description('(兼容字段)旧的 @ 冷却;现在所有模型调用统一走 aiMinReplyIntervalSeconds。'),
134
129
  aiCooldownNotice: Schema.boolean().default(true).description('被 @ 但处于模型调用冷却时,是否在群里提示还剩多久(纯本地消息,不调用模型)。'),
135
130
  aiCooldownNoticeText: Schema.string().default('还在冷却,{seconds} 秒后再叫我。').description('冷却提示文案,可用 {seconds} 与 {minutes} 占位。'),
136
131
  aiCooldownNoticeIntervalSeconds: Schema.natural().min(0).max(600).default(20).description('同一群两次冷却提示的最小间隔(秒),防止连续 @ 刷屏;0 = 不限制。'),
@@ -159,7 +154,7 @@ export const Config = Schema.intersect([
159
154
  aiContextMaxChars: Schema.natural().min(0).max(20000).default(0).description('历史上下文的字数上限:超过后从最旧的消息开始丢(至少保留最近 4 条)。0 = 不限。想省 token 可设 2500~3500。'),
160
155
  aiStyleMaxChars: Schema.natural().min(0).max(20000).default(0).description('外部插件注入的「说话风格」段每条最多保留多少字。0 = 不限。风格 skill 很长时可设 1200~1800 显著省 token。'),
161
156
  aiTemperature: Schema.number().min(0).max(2).step(0.1).default(0.8).description('生成温度(0~2)。群聊接话建议 0.7~0.9,过高会跑题、复述、发散。'),
162
- aiMaxOutputTokens: Schema.natural().default(400).description('AI 最大输出 token 数。群聊一句话不需要太大,过大会增加延迟。'),
157
+ aiMaxOutputTokens: Schema.natural().min(100).max(131072).default(1500).description('思考 + 回答的总 token 上限(API 的 max_tokens,不是只限制正文)。思考模式开启时思维链也计入这里:设得太小,预算会被思考吃掉、正文被截断;设得太大则单次成本上限更高。群聊接话建议 1000~2000。'),
163
158
  aiMaxReplyChars: Schema.natural().min(20).max(500).default(120).description('单条回复的最大字符数,超出会在句末截断。'),
164
159
  aiQuoteReplyMode: Schema.union([
165
160
  Schema.const('random').description('随机决定'),
@@ -169,10 +164,6 @@ export const Config = Schema.intersect([
169
164
  aiQuoteReplyProbability: Schema.number().min(0).max(1).step(0.05).default(0.5).hidden().description('引用概率(仅 random 模式生效)。'),
170
165
  aiReadForwardMessage: Schema.boolean().default(true).description('读取合并转发聊天记录的内容,作为上下文的一部分。'),
171
166
  aiForwardMaxNodes: Schema.natural().min(1).max(50).default(20).description('单条合并转发最多读取多少条子消息。'),
172
- aiReplyDecision: Schema.union([
173
- Schema.const('single').description('一次调用:模型直接输出回复,或用 <pass/> 放弃(推荐)'),
174
- Schema.const('two-stage').description('两次调用:先判定是否值得回复,再生成正文'),
175
- ]).role('radio').default('single').description('接话决策方式。single 更快、决策与正文一致;two-stage 更省生成成本但多一次延迟。'),
176
167
  aiEnableImageRecognition: Schema.boolean().default(true).description('是否启用图片识别(支持时将图片一并发送给模型;不支持的模型会自动降级为纯文本)。'),
177
168
  aiImageMaxCount: Schema.natural().default(2).description('每次最多发送给模型的图片数量。'),
178
169
  aiImageBudgetMs: Schema.natural().min(500).max(20000).default(6000).description('图片下载/转换的总时间预算(毫秒)。超时直接跳过图片,避免拖慢回复。'),
@@ -188,19 +179,10 @@ export const Config = Schema.intersect([
188
179
  aiWebSearchCacheMinutes: Schema.natural().min(0).max(1440).default(10).description('相同 query 的结果缓存分钟数;0=不缓存。'),
189
180
  aiRequestTimeoutSeconds: Schema.natural().min(5).max(120).default(20).description('单次模型请求超时(秒)。'),
190
181
  aiDebugPrompt: Schema.boolean().default(false).description('调试:把最终系统提示词与用户提示词写入日志(排查"答非所问"时打开,平时关闭)。'),
191
- aiIgnoreCommandMessage: Schema.boolean().default(true).description('忽略看起来像命令的消息,避免干扰正常指令执行。'),
192
182
  aiEnableDirectMentionTrigger: Schema.boolean().default(true).description('消息命中智能体名字时是否忽略阈值直接触发回复。'),
193
183
  aiEnableFollowupAfterMention: Schema.boolean().default(true).description('点名触发后,是否跟随该用户一段时间继续对话。'),
194
184
  aiFollowupWindowSeconds: Schema.natural().default(120).description('点名后跟随该用户的持续时间(秒)。'),
195
185
  aiFollowupMaxTurns: Schema.natural().default(3).description('一次点名会话最多继续回复轮数。'),
196
- aiOwnerPlatform: Schema.string().default('onebot').description('主人平台标识(用于识别主人用户,如 onebot)。'),
197
- aiOwnerUserId: Schema.string().default('').description('主人平台用户 ID(如 QQ 号,用于记忆主人身份)。'),
198
- aiHomePlatform: Schema.string().default('onebot').description('兼容字段:主页平台标识(建议改用 aiOwnerPlatform)。'),
199
- aiHomeUserId: Schema.string().default('').description('兼容字段:主页平台用户 ID(建议改用 aiOwnerUserId)。'),
200
- aiInterestMinScore: Schema.number().min(0).max(100).step(1).default(82).description('(仅 aiReplyDecision=two-stage 时生效)判定为值得回复的最低分。'),
201
- aiInterestContextWindow: Schema.number().min(4).max(16).step(1).default(8).description('(仅 two-stage 生效)判定使用的上下文窗口条数。'),
202
- aiInterestModel: Schema.string().default('').description('(仅 two-stage 生效)判定专用模型(留空沿用 aiModel)。'),
203
- aiInterestMaxTokens: Schema.natural().min(256).max(16384).default(2048).description('(仅 two-stage 生效)判定的最大输出 token。'),
204
186
  }).description('AI 回复'),
205
187
  Schema.object({
206
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
- return this.config.responseStyle === 'meow' ? `喵~ ${text}` : text;
605
+ // 旧的「Meow 风格」已移除:想要喵味请在 qqgm-chat-style 里加一个风格 skill。
606
+ return text;
606
607
  }
607
608
  getMessageText(session) {
608
609
  const raw = session?.content ?? '';