@nestim/koishi-plugin-qq-group-manager 1.4.9 → 1.4.11

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/src/ai/learn.ts CHANGED
@@ -82,6 +82,22 @@ export class LearnStore {
82
82
  return out;
83
83
  }
84
84
 
85
+ /** 持久化用:遍历所有待归纳桶 */
86
+ entries(): Array<{ kind: string; scopeId: string; bucket: LearnBucket }> {
87
+ const out: Array<{ kind: string; scopeId: string; bucket: LearnBucket }> = [];
88
+ for (const [k, bucket] of this.map) {
89
+ if (!bucket.size) continue;
90
+ const idx = k.indexOf(':');
91
+ out.push({ kind: k.slice(0, idx), scopeId: k.slice(idx + 1), bucket });
92
+ }
93
+ return out;
94
+ }
95
+
96
+ /** 持久化用:恢复一个待归纳桶 */
97
+ set(kind: string, scopeId: string, bucket: LearnBucket): void {
98
+ this.map.set(this.key(kind, scopeId), bucket);
99
+ }
100
+
85
101
  clear(): void {
86
102
  this.map.clear();
87
103
  }
package/src/ai/runtime.ts CHANGED
@@ -50,6 +50,15 @@ export class AiRuntimeFacade {
50
50
  }
51
51
  return this.current.ai.chat(request);
52
52
  }
53
+
54
+ /** 把一条消息里的图片解析成 data URL(私聊插件复用主插件的视觉链路) */
55
+ images(session: any): Promise<string[]> {
56
+ if (!this.current || !this.current.ai
57
+ || typeof this.current.ai.resolveSessionImages !== 'function') {
58
+ return Promise.resolve([]);
59
+ }
60
+ return this.current.ai.resolveSessionImages(session);
61
+ }
53
62
  }
54
63
 
55
64
  export function getAiRuntimeFacade(): AiRuntimeFacade {
package/src/ai/state.ts CHANGED
@@ -93,6 +93,16 @@ export class AiState {
93
93
  return this.groups.get(key);
94
94
  }
95
95
 
96
+ /** 持久化用:遍历所有会话状态 */
97
+ entries(): Array<[string, GroupState]> {
98
+ return [...this.groups.entries()];
99
+ }
100
+
101
+ /** 持久化用:恢复一个会话状态 */
102
+ set(key: string, state: GroupState): void {
103
+ this.groups.set(key, state);
104
+ }
105
+
96
106
  clear(): void {
97
107
  this.groups.clear();
98
108
  }
package/src/index.ts CHANGED
@@ -151,6 +151,7 @@ export const Config = Schema.intersect([
151
151
  aiPseudoRandomStep: Schema.number().min(0).max(1).step(0.001).default(0.01).description('伪随机每次未命中增加的概率(默认 0.01 = 1%)。只在真正掷骰且未命中时累加,冷却/阈值跳过不算。'),
152
152
  aiMinReplyIntervalSeconds: Schema.natural().default(45).description('同一群两次真正调用模型的最短间隔(秒)。'),
153
153
  aiContextWindow: Schema.natural().default(30).description('参与推理的最近消息条数(建议 20~40;太小会导致模型看不到前文)。'),
154
+ persistAiState: Schema.boolean().default(true).description('重启插件后恢复最近上下文、未归纳的消息桶、计数与冷却(保存到 data/qqgm-ai-state.json,只存文本、不存图片)。关闭则每次重启都从头开始。'),
154
155
  aiContextMaxChars: Schema.natural().min(0).max(20000).default(0).description('历史上下文的字数上限:超过后从最旧的消息开始丢(至少保留最近 4 条)。0 = 不限。想省 token 可设 2500~3500。'),
155
156
  aiStyleMaxChars: Schema.natural().min(0).max(20000).default(0).description('外部插件注入的「说话风格」段每条最多保留多少字。0 = 不限。风格 skill 很长时可设 1200~1800 显著省 token。'),
156
157
  aiTemperature: Schema.number().min(0).max(2).step(0.1).default(0.8).description('生成温度(0~2)。群聊接话建议 0.7~0.9,过高会跑题、复述、发散。'),
@@ -175,7 +176,7 @@ export const Config = Schema.intersect([
175
176
  ]).role('radio').default('auto').description('联网搜索触发方式。'),
176
177
  aiWebSearchMaxResults: Schema.natural().min(1).max(10).default(5).description('每次联网搜索取几条结果。'),
177
178
  aiWebSearchTimeoutMs: Schema.natural().min(500).max(15000).default(4000).description('搜索请求超时(毫秒)。'),
178
- aiWebSearchMaxPerHour: Schema.natural().min(0).max(100).default(10).description('每个群每小时最多搜索次数;0=不限。'),
179
+ aiWebSearchMaxPerHour: Schema.natural().min(0).max(100).default(10).description('每个群每小时最多搜索次数;0=不限。命中缓存不占次数。'),
179
180
  aiWebSearchCacheMinutes: Schema.natural().min(0).max(1440).default(10).description('相同 query 的结果缓存分钟数;0=不缓存。'),
180
181
  aiRequestTimeoutSeconds: Schema.natural().min(5).max(120).default(20).description('单次模型请求超时(秒)。'),
181
182
  aiDebugPrompt: Schema.boolean().default(false).description('调试:把最终系统提示词与用户提示词写入日志(排查"答非所问"时打开,平时关闭)。'),