koishi-plugin-satori-ai 1.2.9 → 1.2.10

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/lib/database.d.ts CHANGED
@@ -11,6 +11,7 @@ export declare function updateFavorability(ctx: Context, user: User, adjustment:
11
11
  export declare function updateUserLevel(ctx: Context, user: User, level: number): Promise<void>;
12
12
  export declare function updateUserUsage(ctx: Context, user: User, adjustment?: number): Promise<number | void>;
13
13
  export declare function updateUserItems(ctx: Context, user: User): Promise<void>;
14
+ export declare function updateUserP(ctx: Context, user: User, adjustment: number): Promise<void>;
14
15
  export declare function getUser(ctx: Context, userId: string): Promise<User | null>;
15
16
  export declare function ensureUserExists(ctx: Context, userId: string, username: string): Promise<User>;
16
17
  export declare function extendDatabase(ctx: Context): void;
package/lib/index.d.ts CHANGED
@@ -27,6 +27,7 @@ export declare class SAT extends Sat {
27
27
  private generateResponse;
28
28
  private buildMessages;
29
29
  private buildSystemPrompt;
30
+ private getThinkingPrompt;
30
31
  private formatResponse;
31
32
  private clearSession;
32
33
  private addCommonSense;
package/lib/index.js CHANGED
@@ -52,6 +52,106 @@ var import_koishi2 = require("koishi");
52
52
 
53
53
  // src/utils.ts
54
54
  var import_koishi = require("koishi");
55
+
56
+ // src/database.ts
57
+ async function isTargetIdNotExists(ctx, userId) {
58
+ const users = await ctx.database.get("p_system", { userid: userId });
59
+ return users.length === 0;
60
+ }
61
+ __name(isTargetIdNotExists, "isTargetIdNotExists");
62
+ async function createUser(ctx, user) {
63
+ await ctx.database.create("p_system", {
64
+ userid: user.userid || "",
65
+ usersname: user.usersname || "",
66
+ p: user.p || 0,
67
+ favorability: user.favorability || 0,
68
+ userlevel: user.userlevel || 0,
69
+ usage: user.usage || 0,
70
+ lastChatTime: user.lastChatTime || (/* @__PURE__ */ new Date()).getDate(),
71
+ items: user.items || {}
72
+ });
73
+ }
74
+ __name(createUser, "createUser");
75
+ async function updateFavorability(ctx, user, adjustment) {
76
+ if (!user)
77
+ return;
78
+ let newValue;
79
+ if (typeof adjustment === "number")
80
+ newValue = user.favorability + adjustment;
81
+ else
82
+ newValue = user.favorability;
83
+ await ctx.database.set("p_system", { userid: user.userid }, { favorability: newValue });
84
+ }
85
+ __name(updateFavorability, "updateFavorability");
86
+ async function updateUserLevel(ctx, user, level) {
87
+ if (!user)
88
+ return;
89
+ level = level < 5 ? level : 4;
90
+ await ctx.database.set("p_system", { userid: user.userid }, { userlevel: level });
91
+ }
92
+ __name(updateUserLevel, "updateUserLevel");
93
+ async function updateUserUsage(ctx, user, adjustment = 1) {
94
+ if (!user)
95
+ return;
96
+ if (user.lastChatTime && (/* @__PURE__ */ new Date()).getDate() !== user.lastChatTime)
97
+ user.usage = 0;
98
+ await ctx.database.set("p_system", { userid: user.userid }, { usage: user.usage + adjustment });
99
+ await ctx.database.set("p_system", { userid: user.userid }, { lastChatTime: (/* @__PURE__ */ new Date()).getDate() });
100
+ return user.usage + adjustment;
101
+ }
102
+ __name(updateUserUsage, "updateUserUsage");
103
+ async function updateUserItems(ctx, user) {
104
+ if (!user)
105
+ return;
106
+ await ctx.database.set("p_system", { userid: user.userid }, { items: user.items });
107
+ }
108
+ __name(updateUserItems, "updateUserItems");
109
+ async function updateUserP(ctx, user, adjustment) {
110
+ if (!user)
111
+ return;
112
+ if (user.p + adjustment < 0)
113
+ adjustment = -user.p;
114
+ await ctx.database.set("p_system", { userid: user.userid }, { p: user.p + adjustment });
115
+ }
116
+ __name(updateUserP, "updateUserP");
117
+ async function getUser(ctx, userId) {
118
+ const users = await ctx.database.get("p_system", { userid: userId });
119
+ return users[0] || null;
120
+ }
121
+ __name(getUser, "getUser");
122
+ async function ensureUserExists(ctx, userId, username) {
123
+ const notExists = await isTargetIdNotExists(ctx, userId);
124
+ if (notExists) {
125
+ await createUser(ctx, {
126
+ userid: userId,
127
+ usersname: username,
128
+ p: 0,
129
+ favorability: 0,
130
+ userlevel: 0,
131
+ usage: 0,
132
+ lastChatTime: (/* @__PURE__ */ new Date()).getDate(),
133
+ items: {}
134
+ });
135
+ }
136
+ return getUser(ctx, userId);
137
+ }
138
+ __name(ensureUserExists, "ensureUserExists");
139
+ function extendDatabase(ctx) {
140
+ ctx.model.extend("p_system", {
141
+ id: "unsigned",
142
+ userid: "string",
143
+ usersname: "string",
144
+ p: "integer",
145
+ favorability: "integer",
146
+ userlevel: "integer",
147
+ usage: "integer",
148
+ lastChatTime: "integer",
149
+ items: "object"
150
+ }, { autoInc: true });
151
+ }
152
+ __name(extendDatabase, "extendDatabase");
153
+
154
+ // src/utils.ts
55
155
  var fs = __toESM(require("fs"));
56
156
  var path = __toESM(require("path"));
57
157
  var logger = new import_koishi.Logger("satori-utils");
@@ -169,6 +269,14 @@ function addOutputCensor(session, word, baseURL) {
169
269
  session.send(`添加"${word}"成功`);
170
270
  }
171
271
  __name(addOutputCensor, "addOutputCensor");
272
+ async function updateUserPWithTicket(ctx, user, adjustment) {
273
+ if (!user)
274
+ return;
275
+ if (user?.items?.["地灵殿通行证"]?.description && user.items["地灵殿通行证"].description === "on") {
276
+ await updateUserP(ctx, user, adjustment);
277
+ }
278
+ }
279
+ __name(updateUserPWithTicket, "updateUserPWithTicket");
172
280
 
173
281
  // src/api.ts
174
282
  var logger2 = new import_koishi2.Logger("satori-api");
@@ -191,14 +299,20 @@ var APIClient = class {
191
299
  let modle;
192
300
  let baseURL;
193
301
  if (enableUserKey) {
194
- const key = user.items["地灵殿通行证"].metadata?.key;
195
- keys = [key];
196
- modle = user.items["地灵殿通行证"].metadata?.model;
197
- baseURL = user.items["地灵殿通行证"].metadata?.baseURL;
302
+ const ticket = user.items["地灵殿通行证"].metadata;
303
+ keys = [ticket?.key];
304
+ modle = ticket?.model;
305
+ baseURL = ticket?.baseURL;
306
+ const not_reasoner_model = ticket?.not_reasoner_model;
307
+ const length = ticket?.use_not_reasoner_LLM_length;
308
+ if (not_reasoner_model && length && messages[messages.length - 1].content.length <= length)
309
+ modle = not_reasoner_model;
198
310
  } else {
199
- keys = this.config.keys;
200
- modle = this.config.appointModel;
201
- baseURL = this.config.baseURL;
311
+ const config = this.config;
312
+ const useNotReasoner = messages[messages.length - 1].content.length <= config.use_not_reasoner_LLM_length;
313
+ keys = useNotReasoner ? config.not_reasoner_LLM_key : config.keys;
314
+ modle = useNotReasoner ? config.not_reasoner_LLM : config.appointModel;
315
+ baseURL = useNotReasoner ? config.not_reasoner_LLM_URL : config.baseURL;
202
316
  }
203
317
  const payload = this.createPayload(messages, modle);
204
318
  for (let i = 0; i < keys.length; i++) {
@@ -276,7 +390,6 @@ var APIClient = class {
276
390
  return {
277
391
  model,
278
392
  messages,
279
- max_tokens: this.config.content_max_tokens,
280
393
  temperature: this.config.temperature,
281
394
  top_p: 1,
282
395
  frequency_penalty: this.config.frequency_penalty,
@@ -300,19 +413,13 @@ var APIClient = class {
300
413
  try {
301
414
  const response = await this.ctx.http.post(url, payload, { headers, timeout: 36e5 });
302
415
  content = response.choices[0].message.content;
303
- const reasoning_content = response.choices[0].message.reasoning_content;
416
+ const reasoning_content = response.choices[0].message.reasoning_content || "无";
304
417
  if (this.config.reasoning_content)
305
- logger2.info(`思维链: ${reasoning_content || "无"}`);
418
+ logger2.info(`思维链: ${reasoning_content}`);
306
419
  if (!content && reasoning_content) {
307
420
  logger2.warn("返回内容为空,但存在推理内容");
308
421
  content = response.choices[0].message.reasoning_content;
309
422
  }
310
- if (content.length > this.config.content_max_length) {
311
- logger2.warn(`返回内容超过最大长度(${content.length} > ${this.config.content_max_length})`);
312
- if (i >= 2)
313
- return { content: "返回内容超过最大长度", error: true };
314
- continue;
315
- }
316
423
  const responseMsg = { role: "assistant", content };
317
424
  if (payload.messages.some((msg) => msg === responseMsg) && content.length > 5) {
318
425
  const lastMsg = payload.messages[payload.messages.length - 1];
@@ -388,98 +495,6 @@ var APIClient = class {
388
495
  var import_koishi3 = require("koishi");
389
496
  var fs2 = __toESM(require("fs"));
390
497
  var path2 = __toESM(require("path"));
391
-
392
- // src/database.ts
393
- async function isTargetIdNotExists(ctx, userId) {
394
- const users = await ctx.database.get("p_system", { userid: userId });
395
- return users.length === 0;
396
- }
397
- __name(isTargetIdNotExists, "isTargetIdNotExists");
398
- async function createUser(ctx, user) {
399
- await ctx.database.create("p_system", {
400
- userid: user.userid || "",
401
- usersname: user.usersname || "",
402
- p: user.p || 0,
403
- favorability: user.favorability || 0,
404
- userlevel: user.userlevel || 0,
405
- usage: user.usage || 0,
406
- lastChatTime: user.lastChatTime || (/* @__PURE__ */ new Date()).getDate(),
407
- items: user.items || {}
408
- });
409
- }
410
- __name(createUser, "createUser");
411
- async function updateFavorability(ctx, user, adjustment) {
412
- if (!user)
413
- return;
414
- let newValue;
415
- if (typeof adjustment === "number")
416
- newValue = user.favorability + adjustment;
417
- else
418
- newValue = user.favorability;
419
- await ctx.database.set("p_system", { userid: user.userid }, { favorability: newValue });
420
- }
421
- __name(updateFavorability, "updateFavorability");
422
- async function updateUserLevel(ctx, user, level) {
423
- if (!user)
424
- return;
425
- level = level < 5 ? level : 4;
426
- await ctx.database.set("p_system", { userid: user.userid }, { userlevel: level });
427
- }
428
- __name(updateUserLevel, "updateUserLevel");
429
- async function updateUserUsage(ctx, user, adjustment = 1) {
430
- if (!user)
431
- return;
432
- if (user.lastChatTime && (/* @__PURE__ */ new Date()).getDate() !== user.lastChatTime)
433
- user.usage = 0;
434
- await ctx.database.set("p_system", { userid: user.userid }, { usage: user.usage + adjustment });
435
- await ctx.database.set("p_system", { userid: user.userid }, { lastChatTime: (/* @__PURE__ */ new Date()).getDate() });
436
- return user.usage + adjustment;
437
- }
438
- __name(updateUserUsage, "updateUserUsage");
439
- async function updateUserItems(ctx, user) {
440
- if (!user)
441
- return;
442
- await ctx.database.set("p_system", { userid: user.userid }, { items: user.items });
443
- }
444
- __name(updateUserItems, "updateUserItems");
445
- async function getUser(ctx, userId) {
446
- const users = await ctx.database.get("p_system", { userid: userId });
447
- return users[0] || null;
448
- }
449
- __name(getUser, "getUser");
450
- async function ensureUserExists(ctx, userId, username) {
451
- const notExists = await isTargetIdNotExists(ctx, userId);
452
- if (notExists) {
453
- await createUser(ctx, {
454
- userid: userId,
455
- usersname: username,
456
- p: 0,
457
- favorability: 0,
458
- userlevel: 0,
459
- usage: 0,
460
- lastChatTime: (/* @__PURE__ */ new Date()).getDate(),
461
- items: {}
462
- });
463
- }
464
- return getUser(ctx, userId);
465
- }
466
- __name(ensureUserExists, "ensureUserExists");
467
- function extendDatabase(ctx) {
468
- ctx.model.extend("p_system", {
469
- id: "unsigned",
470
- userid: "string",
471
- usersname: "string",
472
- p: "integer",
473
- favorability: "integer",
474
- userlevel: "integer",
475
- usage: "integer",
476
- lastChatTime: "integer",
477
- items: "object"
478
- }, { autoInc: true });
479
- }
480
- __name(extendDatabase, "extendDatabase");
481
-
482
- // src/memory.ts
483
498
  var logger3 = new import_koishi3.Logger("satori-memory");
484
499
  var MemoryManager = class {
485
500
  constructor(ctx, config) {
@@ -1031,27 +1046,34 @@ var Sat = class extends import_koishi5.Service {
1031
1046
  ((Sat2) => {
1032
1047
  Sat2.Config = import_koishi5.Schema.intersect([
1033
1048
  import_koishi5.Schema.object({
1034
- baseURL: import_koishi5.Schema.string().default("https://api.deepseek.com").description("请求地址"),
1049
+ baseURL: import_koishi5.Schema.string().default("https://api.deepseek.com").description("深度思考模型请求地址"),
1035
1050
  key: import_koishi5.Schema.union([
1036
1051
  import_koishi5.Schema.array(String).role("secret"),
1037
1052
  import_koishi5.Schema.transform(String, (value) => [value])
1038
- ]).default([]).role("secret").description("api_key"),
1039
- appointModel: import_koishi5.Schema.string().default("deepseek-reasoner").description("主模型"),
1053
+ ]).default([]).role("secret").description("深度思考模型api_key"),
1054
+ appointModel: import_koishi5.Schema.string().default("deepseek-reasoner").description("深度思考模型"),
1055
+ not_reasoner_LLM_URL: import_koishi5.Schema.string().default("https://api.deepseek.com").description("非深度思考模型请求地址"),
1056
+ not_reasoner_LLM: import_koishi5.Schema.string().default("deepseek-chat").description("非深度思考模型(用于节省成本"),
1057
+ not_reasoner_LLM_key: import_koishi5.Schema.union([
1058
+ import_koishi5.Schema.array(String).role("secret"),
1059
+ import_koishi5.Schema.transform(String, (value) => [value])
1060
+ ]).default([]).role("secret").description("非深度思考模型api_key"),
1061
+ use_not_reasoner_LLM_length: import_koishi5.Schema.number().default(8).description("触发使用非深度思考模型的字数(输入少于此字数时),如果你希望始终使用非深度思考模型进行对话,请将此值设置成一个较大的值"),
1062
+ enable_reasoner_like: import_koishi5.Schema.boolean().default(true).description("是否启用非深度思考模型模仿思维链(可以在节省成本的同时提高效果)"),
1040
1063
  auxiliary_LLM_URL: import_koishi5.Schema.string().default("https://api.deepseek.com").description("辅助模型请求地址"),
1041
1064
  auxiliary_LLM: import_koishi5.Schema.string().default("deepseek-chat").description("辅助模型(用于好感度调整等功能,如不需要可不填,建议使用低成本模型"),
1042
1065
  auxiliary_LLM_key: import_koishi5.Schema.union([
1043
1066
  import_koishi5.Schema.array(String).role("secret"),
1044
1067
  import_koishi5.Schema.transform(String, (value) => [value])
1045
1068
  ]).default([]).role("secret").description("辅助模型api_key"),
1046
- prompt: import_koishi5.Schema.string().role("textarea").description("人格设定")
1069
+ prompt: import_koishi5.Schema.string().role("textarea").description("人格设定"),
1070
+ reasoner_prompt: import_koishi5.Schema.string().role("textarea").description("思考提示词(对于深度思考模型和非深度思考模型模仿思维链时生效)").default("你在思考时应当逐步分析以下内容:1.当前对话的禁止事项;2.是否与群聊中其他人的发言有关联;3.是否与当前用户之前说的话有关联;4.对话的具体要求;5.用户的意图如何;6.最终的发言的主要内容。")
1047
1071
  }).description("基础设置"),
1048
1072
  import_koishi5.Schema.object({
1049
1073
  alias: import_koishi5.Schema.array(String).default(["ai"]).description("触发命令;别名"),
1050
1074
  authority: import_koishi5.Schema.number().role("slider").min(0).max(5).step(1).description("允许使用的最低权限").default(1),
1051
- no_system_prompt: import_koishi5.Schema.boolean().default(false).description("是否将系统提示的system替换为user(用于具有思维链的模型或一些特殊的api格式,例如硅基流动)"),
1075
+ no_system_prompt: import_koishi5.Schema.boolean().default(false).description("是否将系统提示的system替换为user(用于具有思维链的模型)"),
1052
1076
  max_tokens: import_koishi5.Schema.number().description("最大请求长度(字符数)").default(100),
1053
- content_max_tokens: import_koishi5.Schema.number().description("最大回答长度(思维链+输出token)").default(4096),
1054
- content_max_length: import_koishi5.Schema.number().description("最大回答长度(仅输出,字符数)").default(100),
1055
1077
  message_max_length: import_koishi5.Schema.number().description("最大频道上下文长度(条数)").default(10),
1056
1078
  temperature: import_koishi5.Schema.number().role("slider").min(0).max(2).step(0.01).default(0.5).description("温度"),
1057
1079
  frequency_penalty: import_koishi5.Schema.number().default(0).description("频率惩罚"),
@@ -1328,11 +1350,13 @@ var SAT = class extends Sat {
1328
1350
  baseURL: this.config.baseURL,
1329
1351
  keys: this.config.key,
1330
1352
  appointModel: this.config.appointModel,
1353
+ not_reasoner_LLM_URL: this.config.not_reasoner_LLM_URL,
1354
+ not_reasoner_LLM: this.config.not_reasoner_LLM,
1355
+ not_reasoner_LLM_key: this.config.not_reasoner_LLM_key,
1356
+ use_not_reasoner_LLM_length: this.config.use_not_reasoner_LLM_length,
1331
1357
  auxiliary_LLM_URL: this.config.auxiliary_LLM_URL,
1332
1358
  auxiliary_LLM: this.config.auxiliary_LLM,
1333
1359
  auxiliary_LLM_key: this.config.auxiliary_LLM_key,
1334
- content_max_tokens: this.config.content_max_tokens,
1335
- content_max_length: this.config.content_max_length,
1336
1360
  maxRetryTimes: this.config.maxRetryTimes,
1337
1361
  retry_delay_time: this.config.retry_delay_time,
1338
1362
  temperature: this.config.temperature,
@@ -1441,6 +1465,8 @@ var SAT = class extends Sat {
1441
1465
  const response = await this.generateResponse(session, processedPrompt);
1442
1466
  const auxiliaryResult = await this.handleAuxiliaryDialogue(session, processedPrompt, response);
1443
1467
  await this.memoryManager.updateMemories(session, processedPrompt, this.getMemoryConfig(), response);
1468
+ if (!response.error)
1469
+ await updateUserPWithTicket(this.ctx, user, 10);
1444
1470
  if (user.usage == this.config.portrait_usage - 1)
1445
1471
  this.portraitManager.generatePortrait(session, user, this.apiClient);
1446
1472
  return await this.formatResponse(session, response.content, auxiliaryResult);
@@ -1572,6 +1598,8 @@ var SAT = class extends Sat {
1572
1598
  logger6.info(`Satori AI:${response.content}`);
1573
1599
  if (this.config.reasoner_filter)
1574
1600
  response.content = filterResponse(response.content, this.config.reasoner_filter_word.split("-"));
1601
+ if (response.error)
1602
+ updateUserUsage(this.ctx, user, -1);
1575
1603
  return response;
1576
1604
  }
1577
1605
  // 构建消息
@@ -1603,28 +1631,40 @@ ${payload}`);
1603
1631
  const channelDialogue = await this.memoryManager.getChannelDialogue(session);
1604
1632
  const userMemory = await this.memoryManager.searchMemories(session, prompt);
1605
1633
  const user = await getUser(this.ctx, session.userId);
1606
- if (user?.items?.["觉的衣柜"]?.count) {
1607
- const clothes = user?.items?.["觉的衣柜"]?.metadata?.clothes;
1608
- if (clothes)
1609
- systemPrompt += `
1610
- 你当前的穿着(根据穿着进行对应的行为):${clothes}
1611
- `;
1612
- }
1634
+ systemPrompt += this.getThinkingPrompt(user, prompt);
1613
1635
  systemPrompt += commonSense;
1614
1636
  systemPrompt += channelDialogue;
1615
1637
  systemPrompt += userMemory;
1616
1638
  systemPrompt += this.portraitManager.getUserPortrait(session);
1617
- const nickName = user.items["情侣合照"]?.metadata?.userNickName;
1618
1639
  systemPrompt += `用户的名字是:${session.username}, id是:${session.userId}`;
1640
+ const nickName = user.items["情侣合照"]?.metadata?.userNickName;
1619
1641
  if (nickName)
1620
1642
  systemPrompt += `, 昵称是:${nickName},称呼用户时请优先使用昵称`;
1621
- if (this.config.enable_favorability) {
1643
+ if (this.config.enable_favorability)
1622
1644
  systemPrompt += generateLevelPrompt(getFavorabilityLevel(user, this.getFavorabilityConfig()), this.getFavorabilityConfig(), user);
1623
- }
1624
1645
  if (this.config.no_system_prompt)
1625
1646
  systemPrompt += "如果你明白以上内容,请回复“已明确对话要求”";
1626
1647
  return systemPrompt;
1627
1648
  }
1649
+ // 思考提示
1650
+ getThinkingPrompt(user, prompt) {
1651
+ const reasonerPrompt = this.config.reasoner_prompt;
1652
+ const promptForNoReasoner = `请你在最终回复前先输出思考内容,所有思考内容使用<think>和</think>包裹输出,而后在最后输出正式的回复内容。${reasonerPrompt}
1653
+ `;
1654
+ const promptForReasoner = `你需要将所有思考内容使用<think>和</think>包裹输出在思维链中,注意不要在最终的输出内包含思考内容。${reasonerPrompt}
1655
+ `;
1656
+ const hasTicket = user?.items?.["地灵殿通行证"]?.description && user.items["地灵殿通行证"].description === "on";
1657
+ const maxLength = hasTicket ? user?.items?.["地灵殿通行证"]?.metadata?.use_not_reasoner_LLM_length : this.config.use_not_reasoner_LLM_length;
1658
+ const useNoReasoner = prompt.length <= maxLength;
1659
+ if (!this.config.enable_reasoner_like && useNoReasoner)
1660
+ return "";
1661
+ const reasonerText = `
1662
+ 以下是你的【思考要求】:{
1663
+ ${useNoReasoner ? promptForNoReasoner : promptForReasoner}
1664
+ }
1665
+ `;
1666
+ return reasonerText;
1667
+ }
1628
1668
  // 处理回复
1629
1669
  async formatResponse(session, response, auxiliaryResult) {
1630
1670
  const user = await getUser(this.ctx, session.userId);
package/lib/types.d.ts CHANGED
@@ -87,11 +87,13 @@ export interface APIConfig {
87
87
  baseURL: string;
88
88
  keys: string[];
89
89
  appointModel: string;
90
+ not_reasoner_LLM_URL: string;
91
+ not_reasoner_LLM: string;
92
+ not_reasoner_LLM_key: string[];
93
+ use_not_reasoner_LLM_length: number;
90
94
  auxiliary_LLM_URL: string;
91
95
  auxiliary_LLM: string;
92
96
  auxiliary_LLM_key: string[];
93
- content_max_tokens: number;
94
- content_max_length: number;
95
97
  temperature: number;
96
98
  frequency_penalty: number;
97
99
  presence_penalty: number;
@@ -143,14 +145,17 @@ export declare namespace Sat {
143
145
  baseURL: string;
144
146
  key: string[];
145
147
  appointModel: string;
148
+ not_reasoner_LLM_URL: string;
149
+ not_reasoner_LLM: string;
150
+ not_reasoner_LLM_key: string[];
151
+ use_not_reasoner_LLM_length: number;
146
152
  auxiliary_LLM_URL: string;
147
153
  auxiliary_LLM: string;
148
154
  auxiliary_LLM_key: string[];
149
155
  prompt: string;
156
+ reasoner_prompt: string;
150
157
  no_system_prompt: boolean;
151
158
  max_tokens: number;
152
- content_max_tokens: number;
153
- content_max_length: number;
154
159
  message_max_length: number;
155
160
  remember_min_length: number;
156
161
  temperature: number;
@@ -172,6 +177,7 @@ export declare namespace Sat {
172
177
  common_topN: number;
173
178
  dailogues_topN: number;
174
179
  enable_fixed_dialogues: boolean;
180
+ enable_reasoner_like: boolean;
175
181
  max_usage: number[];
176
182
  private: boolean;
177
183
  nick_name: boolean;
package/lib/utils.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { Session } from 'koishi';
1
+ import { Context, Session } from 'koishi';
2
+ import { User } from './types';
2
3
  export declare function escapeRegExp(str: string): string;
3
4
  export declare function parseTimeToMinutes(timeStr: string): number;
4
5
  export declare function parseTime(timestamp: number): number;
@@ -24,3 +25,4 @@ export declare function processPrompt(prompt: string): string;
24
25
  */
25
26
  export declare function filterResponse(prompt: string, words: string[]): string;
26
27
  export declare function addOutputCensor(session: Session, word: string, baseURL: string): void;
28
+ export declare function updateUserPWithTicket(ctx: Context, user: User, adjustment: number): Promise<void>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-satori-ai",
3
3
  "description": "基于 Satori 适配器的智能对话插件,具备用户画像、长期记忆、常识管理和好感度系统",
4
- "version": "1.2.9",
4
+ "version": "1.2.10",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "types": "lib/index.d.ts",
package/wasm/gobang.cpp CHANGED
@@ -460,8 +460,7 @@ int wholeScore(int player, const Game &game) {
460
460
  if (temp.score == 0)
461
461
  continue;
462
462
  if (temp.score == player) {
463
- if (player == BLACK)
464
- Score += singleScore(temp, player, game); // 己方落子的单点分相加
463
+ Score += singleScore(temp, player, game); // 己方落子的单点分相加
465
464
  } else
466
465
  Score -= singleScore(temp, 3 - player, game); // 对方落子的单点分相加
467
466
  }
@@ -475,11 +474,10 @@ int inspireSearch(coordinate *scoreBoard, int player, Game &game) {
475
474
  for (int j = 0; j < BOARD_SIZE; j++) {
476
475
  if (game.MAP.board[i][j] == 0) {
477
476
  coordinate temp = {i, j, 0};
478
- if (hasNeighbor(temp, 2, game)) {
477
+ if (hasNeighbor(temp, 3, game)) {
479
478
  scoreBoard[length] = temp;
480
479
  scoreBoard[length].score = singleScore(temp, 3 - player, game);
481
- if (player == BLACK)
482
- scoreBoard[length].score += singleScore(temp, player, game);
480
+ scoreBoard[length].score += singleScore(temp, player, game);
483
481
  length++;
484
482
  }
485
483
  }
package/wasm/gobang.js CHANGED
@@ -1,21 +1,21 @@
1
- var Module = (() => {
2
- var _scriptName = typeof document != 'undefined' ? document.currentScript?.src : undefined;
3
- if (typeof __filename != 'undefined') _scriptName = _scriptName || __filename;
4
- return (
5
- async function(moduleArg = {}) {
6
- var moduleRtn;
7
-
8
- var Module=moduleArg;var readyPromiseResolve,readyPromiseReject;var readyPromise=new Promise((resolve,reject)=>{readyPromiseResolve=resolve;readyPromiseReject=reject});var ENVIRONMENT_IS_NODE=true;if(ENVIRONMENT_IS_NODE){}var moduleOverrides={...Module};var arguments_=[];var thisProgram="./this.program";var quit_=(status,toThrow)=>{throw toThrow};var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var readAsync,readBinary;if(ENVIRONMENT_IS_NODE){var fs=require("fs");var nodePath=require("path");scriptDirectory=__dirname+"/";readBinary=filename=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename);return ret};readAsync=async(filename,binary=true)=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename,binary?undefined:"utf8");return ret};if(!Module["thisProgram"]&&process.argv.length>1){thisProgram=process.argv[1].replace(/\\/g,"/")}arguments_=process.argv.slice(2);quit_=(status,toThrow)=>{process.exitCode=status;throw toThrow}}else{}var out=Module["print"]||console.log.bind(console);var err=Module["printErr"]||console.error.bind(console);Object.assign(Module,moduleOverrides);moduleOverrides=null;if(Module["arguments"])arguments_=Module["arguments"];if(Module["thisProgram"])thisProgram=Module["thisProgram"];var wasmBinary=Module["wasmBinary"];var wasmMemory;var ABORT=false;var HEAP8,HEAPU8,HEAP16,HEAPU16,HEAP32,HEAPU32,HEAPF32,HEAP64,HEAPU64,HEAPF64;var runtimeInitialized=false;var isFileURI=filename=>filename.startsWith("file://");function updateMemoryViews(){var b=wasmMemory.buffer;Module["HEAP8"]=HEAP8=new Int8Array(b);Module["HEAP16"]=HEAP16=new Int16Array(b);Module["HEAPU8"]=HEAPU8=new Uint8Array(b);Module["HEAPU16"]=HEAPU16=new Uint16Array(b);Module["HEAP32"]=HEAP32=new Int32Array(b);Module["HEAPU32"]=HEAPU32=new Uint32Array(b);Module["HEAPF32"]=HEAPF32=new Float32Array(b);Module["HEAPF64"]=HEAPF64=new Float64Array(b);Module["HEAP64"]=HEAP64=new BigInt64Array(b);Module["HEAPU64"]=HEAPU64=new BigUint64Array(b)}function preRun(){if(Module["preRun"]){if(typeof Module["preRun"]=="function")Module["preRun"]=[Module["preRun"]];while(Module["preRun"].length){addOnPreRun(Module["preRun"].shift())}}callRuntimeCallbacks(onPreRuns)}function initRuntime(){runtimeInitialized=true;wasmExports["c"]()}function postRun(){if(Module["postRun"]){if(typeof Module["postRun"]=="function")Module["postRun"]=[Module["postRun"]];while(Module["postRun"].length){addOnPostRun(Module["postRun"].shift())}}callRuntimeCallbacks(onPostRuns)}var runDependencies=0;var dependenciesFulfilled=null;function addRunDependency(id){runDependencies++;Module["monitorRunDependencies"]?.(runDependencies)}function removeRunDependency(id){runDependencies--;Module["monitorRunDependencies"]?.(runDependencies);if(runDependencies==0){if(dependenciesFulfilled){var callback=dependenciesFulfilled;dependenciesFulfilled=null;callback()}}}function abort(what){Module["onAbort"]?.(what);what="Aborted("+what+")";err(what);ABORT=true;what+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(what);readyPromiseReject(e);throw e}var wasmBinaryFile;function findWasmBinary(){return locateFile("gobang.wasm")}function getBinarySync(file){if(file==wasmBinaryFile&&wasmBinary){return new Uint8Array(wasmBinary)}if(readBinary){return readBinary(file)}throw"both async and sync fetching of the wasm failed"}async function getWasmBinary(binaryFile){if(!wasmBinary){try{var response=await readAsync(binaryFile);return new Uint8Array(response)}catch{}}return getBinarySync(binaryFile)}async function instantiateArrayBuffer(binaryFile,imports){try{var binary=await getWasmBinary(binaryFile);var instance=await WebAssembly.instantiate(binary,imports);return instance}catch(reason){err(`failed to asynchronously prepare wasm: ${reason}`);abort(reason)}}async function instantiateAsync(binary,binaryFile,imports){if(!binary&&typeof WebAssembly.instantiateStreaming=="function"&&!ENVIRONMENT_IS_NODE){try{var response=fetch(binaryFile,{credentials:"same-origin"});var instantiationResult=await WebAssembly.instantiateStreaming(response,imports);return instantiationResult}catch(reason){err(`wasm streaming compile failed: ${reason}`);err("falling back to ArrayBuffer instantiation")}}return instantiateArrayBuffer(binaryFile,imports)}function getWasmImports(){return{a:wasmImports}}async function createWasm(){function receiveInstance(instance,module){wasmExports=instance.exports;wasmMemory=wasmExports["b"];updateMemoryViews();removeRunDependency("wasm-instantiate");return wasmExports}addRunDependency("wasm-instantiate");function receiveInstantiationResult(result){return receiveInstance(result["instance"])}var info=getWasmImports();if(Module["instantiateWasm"]){return new Promise((resolve,reject)=>{Module["instantiateWasm"](info,(mod,inst)=>{receiveInstance(mod,inst);resolve(mod.exports)})})}wasmBinaryFile??=findWasmBinary();try{var result=await instantiateAsync(wasmBinary,wasmBinaryFile,info);var exports=receiveInstantiationResult(result);return exports}catch(e){readyPromiseReject(e);return Promise.reject(e)}}class ExitStatus{name="ExitStatus";constructor(status){this.message=`Program terminated with exit(${status})`;this.status=status}}var callRuntimeCallbacks=callbacks=>{while(callbacks.length>0){callbacks.shift()(Module)}};var onPostRuns=[];var addOnPostRun=cb=>onPostRuns.unshift(cb);var onPreRuns=[];var addOnPreRun=cb=>onPreRuns.unshift(cb);var noExitRuntime=Module["noExitRuntime"]||true;var abortOnCannotGrowMemory=requestedSize=>{abort("OOM")};var _emscripten_resize_heap=requestedSize=>{var oldSize=HEAPU8.length;requestedSize>>>=0;abortOnCannotGrowMemory(requestedSize)};var wasmImports={a:_emscripten_resize_heap};var wasmExports=await createWasm();var ___wasm_call_ctors=wasmExports["c"];var _decideMove=Module["_decideMove"]=wasmExports["d"];var _malloc=Module["_malloc"]=wasmExports["f"];var _free=Module["_free"]=wasmExports["g"];function run(){if(runDependencies>0){dependenciesFulfilled=run;return}preRun();if(runDependencies>0){dependenciesFulfilled=run;return}function doRun(){Module["calledRun"]=true;if(ABORT)return;initRuntime();readyPromiseResolve(Module);Module["onRuntimeInitialized"]?.();postRun()}if(Module["setStatus"]){Module["setStatus"]("Running...");setTimeout(()=>{setTimeout(()=>Module["setStatus"](""),1);doRun()},1)}else{doRun()}}if(Module["preInit"]){if(typeof Module["preInit"]=="function")Module["preInit"]=[Module["preInit"]];while(Module["preInit"].length>0){Module["preInit"].pop()()}}run();moduleRtn=readyPromise;
9
-
10
-
11
- return moduleRtn;
12
- }
13
- );
14
- })();
15
- if (typeof exports === 'object' && typeof module === 'object') {
16
- module.exports = Module;
17
- // This default export looks redundant, but it allows TS to import this
18
- // commonjs style module.
19
- module.exports.default = Module;
20
- } else if (typeof define === 'function' && define['amd'])
21
- define([], () => Module);
1
+ var Module = (() => {
2
+ var _scriptName = typeof document != 'undefined' ? document.currentScript?.src : undefined;
3
+ if (typeof __filename != 'undefined') _scriptName = _scriptName || __filename;
4
+ return (
5
+ async function(moduleArg = {}) {
6
+ var moduleRtn;
7
+
8
+ var Module=moduleArg;var readyPromiseResolve,readyPromiseReject;var readyPromise=new Promise((resolve,reject)=>{readyPromiseResolve=resolve;readyPromiseReject=reject});var ENVIRONMENT_IS_NODE=true;if(ENVIRONMENT_IS_NODE){}var moduleOverrides={...Module};var arguments_=[];var thisProgram="./this.program";var quit_=(status,toThrow)=>{throw toThrow};var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var readAsync,readBinary;if(ENVIRONMENT_IS_NODE){var fs=require("fs");var nodePath=require("path");scriptDirectory=__dirname+"/";readBinary=filename=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename);return ret};readAsync=async(filename,binary=true)=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename,binary?undefined:"utf8");return ret};if(!Module["thisProgram"]&&process.argv.length>1){thisProgram=process.argv[1].replace(/\\/g,"/")}arguments_=process.argv.slice(2);quit_=(status,toThrow)=>{process.exitCode=status;throw toThrow}}else{}var out=Module["print"]||console.log.bind(console);var err=Module["printErr"]||console.error.bind(console);Object.assign(Module,moduleOverrides);moduleOverrides=null;if(Module["arguments"])arguments_=Module["arguments"];if(Module["thisProgram"])thisProgram=Module["thisProgram"];var wasmBinary=Module["wasmBinary"];var wasmMemory;var ABORT=false;var HEAP8,HEAPU8,HEAP16,HEAPU16,HEAP32,HEAPU32,HEAPF32,HEAP64,HEAPU64,HEAPF64;var runtimeInitialized=false;var isFileURI=filename=>filename.startsWith("file://");function updateMemoryViews(){var b=wasmMemory.buffer;Module["HEAP8"]=HEAP8=new Int8Array(b);Module["HEAP16"]=HEAP16=new Int16Array(b);Module["HEAPU8"]=HEAPU8=new Uint8Array(b);Module["HEAPU16"]=HEAPU16=new Uint16Array(b);Module["HEAP32"]=HEAP32=new Int32Array(b);Module["HEAPU32"]=HEAPU32=new Uint32Array(b);Module["HEAPF32"]=HEAPF32=new Float32Array(b);Module["HEAPF64"]=HEAPF64=new Float64Array(b);Module["HEAP64"]=HEAP64=new BigInt64Array(b);Module["HEAPU64"]=HEAPU64=new BigUint64Array(b)}function preRun(){if(Module["preRun"]){if(typeof Module["preRun"]=="function")Module["preRun"]=[Module["preRun"]];while(Module["preRun"].length){addOnPreRun(Module["preRun"].shift())}}callRuntimeCallbacks(onPreRuns)}function initRuntime(){runtimeInitialized=true;wasmExports["c"]()}function postRun(){if(Module["postRun"]){if(typeof Module["postRun"]=="function")Module["postRun"]=[Module["postRun"]];while(Module["postRun"].length){addOnPostRun(Module["postRun"].shift())}}callRuntimeCallbacks(onPostRuns)}var runDependencies=0;var dependenciesFulfilled=null;function addRunDependency(id){runDependencies++;Module["monitorRunDependencies"]?.(runDependencies)}function removeRunDependency(id){runDependencies--;Module["monitorRunDependencies"]?.(runDependencies);if(runDependencies==0){if(dependenciesFulfilled){var callback=dependenciesFulfilled;dependenciesFulfilled=null;callback()}}}function abort(what){Module["onAbort"]?.(what);what="Aborted("+what+")";err(what);ABORT=true;what+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(what);readyPromiseReject(e);throw e}var wasmBinaryFile;function findWasmBinary(){return locateFile("gobang.wasm")}function getBinarySync(file){if(file==wasmBinaryFile&&wasmBinary){return new Uint8Array(wasmBinary)}if(readBinary){return readBinary(file)}throw"both async and sync fetching of the wasm failed"}async function getWasmBinary(binaryFile){if(!wasmBinary){try{var response=await readAsync(binaryFile);return new Uint8Array(response)}catch{}}return getBinarySync(binaryFile)}async function instantiateArrayBuffer(binaryFile,imports){try{var binary=await getWasmBinary(binaryFile);var instance=await WebAssembly.instantiate(binary,imports);return instance}catch(reason){err(`failed to asynchronously prepare wasm: ${reason}`);abort(reason)}}async function instantiateAsync(binary,binaryFile,imports){if(!binary&&typeof WebAssembly.instantiateStreaming=="function"&&!ENVIRONMENT_IS_NODE){try{var response=fetch(binaryFile,{credentials:"same-origin"});var instantiationResult=await WebAssembly.instantiateStreaming(response,imports);return instantiationResult}catch(reason){err(`wasm streaming compile failed: ${reason}`);err("falling back to ArrayBuffer instantiation")}}return instantiateArrayBuffer(binaryFile,imports)}function getWasmImports(){return{a:wasmImports}}async function createWasm(){function receiveInstance(instance,module){wasmExports=instance.exports;wasmMemory=wasmExports["b"];updateMemoryViews();removeRunDependency("wasm-instantiate");return wasmExports}addRunDependency("wasm-instantiate");function receiveInstantiationResult(result){return receiveInstance(result["instance"])}var info=getWasmImports();if(Module["instantiateWasm"]){return new Promise((resolve,reject)=>{Module["instantiateWasm"](info,(mod,inst)=>{receiveInstance(mod,inst);resolve(mod.exports)})})}wasmBinaryFile??=findWasmBinary();try{var result=await instantiateAsync(wasmBinary,wasmBinaryFile,info);var exports=receiveInstantiationResult(result);return exports}catch(e){readyPromiseReject(e);return Promise.reject(e)}}class ExitStatus{name="ExitStatus";constructor(status){this.message=`Program terminated with exit(${status})`;this.status=status}}var callRuntimeCallbacks=callbacks=>{while(callbacks.length>0){callbacks.shift()(Module)}};var onPostRuns=[];var addOnPostRun=cb=>onPostRuns.unshift(cb);var onPreRuns=[];var addOnPreRun=cb=>onPreRuns.unshift(cb);var noExitRuntime=Module["noExitRuntime"]||true;var abortOnCannotGrowMemory=requestedSize=>{abort("OOM")};var _emscripten_resize_heap=requestedSize=>{var oldSize=HEAPU8.length;requestedSize>>>=0;abortOnCannotGrowMemory(requestedSize)};var wasmImports={a:_emscripten_resize_heap};var wasmExports=await createWasm();var ___wasm_call_ctors=wasmExports["c"];var _decideMove=Module["_decideMove"]=wasmExports["d"];var _malloc=Module["_malloc"]=wasmExports["f"];var _free=Module["_free"]=wasmExports["g"];function run(){if(runDependencies>0){dependenciesFulfilled=run;return}preRun();if(runDependencies>0){dependenciesFulfilled=run;return}function doRun(){Module["calledRun"]=true;if(ABORT)return;initRuntime();readyPromiseResolve(Module);Module["onRuntimeInitialized"]?.();postRun()}if(Module["setStatus"]){Module["setStatus"]("Running...");setTimeout(()=>{setTimeout(()=>Module["setStatus"](""),1);doRun()},1)}else{doRun()}}if(Module["preInit"]){if(typeof Module["preInit"]=="function")Module["preInit"]=[Module["preInit"]];while(Module["preInit"].length>0){Module["preInit"].pop()()}}run();moduleRtn=readyPromise;
9
+
10
+
11
+ return moduleRtn;
12
+ }
13
+ );
14
+ })();
15
+ if (typeof exports === 'object' && typeof module === 'object') {
16
+ module.exports = Module;
17
+ // This default export looks redundant, but it allows TS to import this
18
+ // commonjs style module.
19
+ module.exports.default = Module;
20
+ } else if (typeof define === 'function' && define['amd'])
21
+ define([], () => Module);
package/wasm/gobang.wasm CHANGED
Binary file