koishi-plugin-chatluna 1.3.13 → 1.3.14

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.
@@ -22,4 +22,4 @@ export type CreateOpenAIAgentParams = {
22
22
  };
23
23
  export declare function createOpenAIAgent({ llm, tools, prompt }: CreateOpenAIAgentParams): RunnableSequence<{
24
24
  steps: AgentStep[];
25
- }, AgentAction | AgentFinish | AgentAction[]>;
25
+ }, AgentAction | AgentAction[] | AgentFinish>;
@@ -12,7 +12,7 @@ export declare class OpenAIFunctionsAgentOutputParser extends AgentActionOutputP
12
12
  lc_namespace: string[];
13
13
  static lc_name(): string;
14
14
  parse(text: string): Promise<AgentAction | AgentFinish>;
15
- parseResult(generations: ChatGeneration[]): Promise<FunctionsAgentAction | AgentFinish>;
15
+ parseResult(generations: ChatGeneration[]): Promise<AgentFinish | FunctionsAgentAction>;
16
16
  /**
17
17
  * Parses the output message into a FunctionsAgentAction or AgentFinish
18
18
  * object.
@@ -72,7 +72,7 @@ export type CreateReactAgentParams = {
72
72
  */
73
73
  export declare function createReactAgent({ llm, tools, prompt, streamRunnable, instructions }: CreateReactAgentParams): AgentRunnableSequence<{
74
74
  steps: AgentStep[];
75
- }, import("koishi-plugin-chatluna/llm-core/agent").AgentFinish | import("koishi-plugin-chatluna/llm-core/agent").AgentAction[]>;
75
+ }, import("koishi-plugin-chatluna/llm-core/agent").AgentAction[] | import("koishi-plugin-chatluna/llm-core/agent").AgentFinish>;
76
76
  /**
77
77
  * Construct the scratchpad that lets the agent continue its thought process.
78
78
  * @param intermediateSteps
@@ -584,7 +584,7 @@ var ChatInterface = class {
584
584
  }
585
585
  async processChat(arg, wrapper) {
586
586
  try {
587
- if (this.ctx.chatluna.config.infiniteContext) {
587
+ if (this.ctx.chatluna.currentConfig.infiniteContext) {
588
588
  const manager = this._ensureInfiniteContextManager();
589
589
  await manager?.compressIfNeeded(wrapper);
590
590
  }
@@ -615,7 +615,7 @@ var ChatInterface = class {
615
615
  if (messageContent.trim().length > 0) {
616
616
  await this.chatHistory.addMessage(arg.message);
617
617
  let saveMessage = responseMessage;
618
- if (!this.ctx.chatluna.config.rawOnCensor) {
618
+ if (!this.ctx.chatluna.currentConfig.rawOnCensor) {
619
619
  saveMessage = displayResponse;
620
620
  }
621
621
  if (Array.isArray(response.parallelIntermediateSteps) && response.parallelIntermediateSteps.length > 0) {
@@ -885,7 +885,7 @@ var ChatInterface = class {
885
885
  chatHistory: this._chatHistory,
886
886
  conversationId: this._input.conversationId,
887
887
  preset: this._input.preset,
888
- threshold: this.ctx.chatluna.config.infiniteContextThreshold
888
+ threshold: this.ctx.chatluna.currentConfig.infiniteContextThreshold
889
889
  });
890
890
  }
891
891
  return this._infiniteContextManager;
@@ -578,7 +578,7 @@ var ChatInterface = class {
578
578
  }
579
579
  async processChat(arg, wrapper) {
580
580
  try {
581
- if (this.ctx.chatluna.config.infiniteContext) {
581
+ if (this.ctx.chatluna.currentConfig.infiniteContext) {
582
582
  const manager = this._ensureInfiniteContextManager();
583
583
  await manager?.compressIfNeeded(wrapper);
584
584
  }
@@ -609,7 +609,7 @@ var ChatInterface = class {
609
609
  if (messageContent.trim().length > 0) {
610
610
  await this.chatHistory.addMessage(arg.message);
611
611
  let saveMessage = responseMessage;
612
- if (!this.ctx.chatluna.config.rawOnCensor) {
612
+ if (!this.ctx.chatluna.currentConfig.rawOnCensor) {
613
613
  saveMessage = displayResponse;
614
614
  }
615
615
  if (Array.isArray(response.parallelIntermediateSteps) && response.parallelIntermediateSteps.length > 0) {
@@ -879,7 +879,7 @@ var ChatInterface = class {
879
879
  chatHistory: this._chatHistory,
880
880
  conversationId: this._input.conversationId,
881
881
  preset: this._input.preset,
882
- threshold: this.ctx.chatluna.config.infiniteContextThreshold
882
+ threshold: this.ctx.chatluna.currentConfig.infiniteContextThreshold
883
883
  });
884
884
  }
885
885
  return this._infiniteContextManager;
@@ -1172,16 +1172,16 @@ __reExport(types_exports, require("@chatluna/shared-prompt-renderer"));
1172
1172
  // src/services/chat.ts
1173
1173
  __reExport(chat_exports, types_exports, module.exports);
1174
1174
  var ChatLunaService = class extends import_koishi4.Service {
1175
- constructor(ctx, config) {
1175
+ constructor(ctx, currentConfig) {
1176
1176
  super(ctx, "chatluna");
1177
1177
  this.ctx = ctx;
1178
- this.config = config;
1179
- this._chain = new ChatChain(ctx, config);
1180
- this._keysCache = new Cache(this.ctx, config, "chatluna/keys");
1181
- this._preset = new import_preset.PresetService(ctx, config);
1178
+ this.currentConfig = currentConfig;
1179
+ this._chain = new ChatChain(ctx, currentConfig);
1180
+ this._keysCache = new Cache(this.ctx, currentConfig, "chatluna/keys");
1181
+ this._preset = new import_preset.PresetService(ctx, currentConfig);
1182
1182
  this._platformService = new import_service.PlatformService(ctx);
1183
- this._messageTransformer = new MessageTransformer(config);
1184
- this._renderer = new import_koishi_plugin_chatluna3.DefaultRenderer(ctx, config);
1183
+ this._messageTransformer = new MessageTransformer(currentConfig);
1184
+ this._renderer = new import_koishi_plugin_chatluna3.DefaultRenderer(ctx, currentConfig);
1185
1185
  this._promptRenderer = new ChatLunaPromptRenderService();
1186
1186
  this._createTempDir();
1187
1187
  this._defineDatabase();
@@ -1823,7 +1823,7 @@ var ChatInterfaceWrapper = class {
1823
1823
  const reasoningContent = aiMessage.additional_kwargs?.reasoning_content;
1824
1824
  const reasoningTime = aiMessage.additional_kwargs?.reasoning_time;
1825
1825
  const additionalReplyMessages = [];
1826
- if (reasoningContent != null && reasoningContent.length > 0 && this._service.config.showThoughtMessage) {
1826
+ if (reasoningContent != null && reasoningContent.length > 0 && this._service.currentConfig.showThoughtMessage) {
1827
1827
  additionalReplyMessages.push({
1828
1828
  content: `Thought for ${reasoningTime / 1e3} seconds:
1829
1829
 
@@ -1968,7 +1968,7 @@ ${reasoningContent}`
1968
1968
  this._platformToConversations.delete(platform);
1969
1969
  }
1970
1970
  async _createChatInterface(room) {
1971
- const config = this._service.config;
1971
+ const config = this._service.currentConfig;
1972
1972
  const chatInterface = new import_app.ChatInterface(this._service.ctx.root, {
1973
1973
  chatMode: room.chatMode,
1974
1974
  botName: config.botNames[0],
@@ -1197,16 +1197,16 @@ import * as shared_prompt_renderer_star from "@chatluna/shared-prompt-renderer";
1197
1197
  // src/services/chat.ts
1198
1198
  __reExport(chat_exports, types_exports);
1199
1199
  var ChatLunaService = class extends Service {
1200
- constructor(ctx, config) {
1200
+ constructor(ctx, currentConfig) {
1201
1201
  super(ctx, "chatluna");
1202
1202
  this.ctx = ctx;
1203
- this.config = config;
1204
- this._chain = new ChatChain(ctx, config);
1205
- this._keysCache = new Cache(this.ctx, config, "chatluna/keys");
1206
- this._preset = new PresetService(ctx, config);
1203
+ this.currentConfig = currentConfig;
1204
+ this._chain = new ChatChain(ctx, currentConfig);
1205
+ this._keysCache = new Cache(this.ctx, currentConfig, "chatluna/keys");
1206
+ this._preset = new PresetService(ctx, currentConfig);
1207
1207
  this._platformService = new PlatformService(ctx);
1208
- this._messageTransformer = new MessageTransformer(config);
1209
- this._renderer = new DefaultRenderer(ctx, config);
1208
+ this._messageTransformer = new MessageTransformer(currentConfig);
1209
+ this._renderer = new DefaultRenderer(ctx, currentConfig);
1210
1210
  this._promptRenderer = new ChatLunaPromptRenderService();
1211
1211
  this._createTempDir();
1212
1212
  this._defineDatabase();
@@ -1848,7 +1848,7 @@ var ChatInterfaceWrapper = class {
1848
1848
  const reasoningContent = aiMessage.additional_kwargs?.reasoning_content;
1849
1849
  const reasoningTime = aiMessage.additional_kwargs?.reasoning_time;
1850
1850
  const additionalReplyMessages = [];
1851
- if (reasoningContent != null && reasoningContent.length > 0 && this._service.config.showThoughtMessage) {
1851
+ if (reasoningContent != null && reasoningContent.length > 0 && this._service.currentConfig.showThoughtMessage) {
1852
1852
  additionalReplyMessages.push({
1853
1853
  content: `Thought for ${reasoningTime / 1e3} seconds:
1854
1854
 
@@ -1993,7 +1993,7 @@ ${reasoningContent}`
1993
1993
  this._platformToConversations.delete(platform);
1994
1994
  }
1995
1995
  async _createChatInterface(room) {
1996
- const config = this._service.config;
1996
+ const config = this._service.currentConfig;
1997
1997
  const chatInterface = new ChatInterface(this._service.ctx.root, {
1998
1998
  chatMode: room.chatMode,
1999
1999
  botName: config.botNames[0],
@@ -68,21 +68,37 @@ async function trackLogToLocal(tag, output, logger) {
68
68
  if (!import_fs.default.existsSync(logDir)) {
69
69
  import_fs.default.mkdirSync(logDir, { recursive: true });
70
70
  }
71
- await import_fs.default.promises.writeFile(logFile, output);
72
- logger.info(`[${tag}] A local log file has been created at ${logFile}`);
73
- const sevenDaysAgo = Date.now() - 7 * 24 * 60 * 60 * 1e3;
74
- const files = await import_fs.default.promises.readdir(logDir);
75
- for (const file of files) {
76
- if (!file.startsWith("chatluna-log-") || !file.endsWith(".log")) {
77
- continue;
71
+ const writeAndCleanup = /* @__PURE__ */ __name(async () => {
72
+ await import_fs.default.promises.writeFile(logFile, output);
73
+ logger.info(`[${tag}] A local log file has been created at ${logFile}`);
74
+ const sevenDaysAgo = Date.now() - 7 * 24 * 60 * 60 * 1e3;
75
+ const files = await import_fs.default.promises.readdir(logDir);
76
+ let deletedCount = 0;
77
+ for (const file of files) {
78
+ if (!file.startsWith("chatluna-log-") || !file.endsWith(".log")) {
79
+ continue;
80
+ }
81
+ const filePath = `${logDir}/${file}`;
82
+ let stats;
83
+ try {
84
+ stats = await import_fs.default.promises.stat(filePath);
85
+ } catch {
86
+ continue;
87
+ }
88
+ if (stats.mtimeMs < sevenDaysAgo) {
89
+ try {
90
+ await import_fs.default.promises.unlink(filePath);
91
+ deletedCount += 1;
92
+ } catch {
93
+ }
94
+ await new Promise((resolve) => setTimeout(resolve, 0));
95
+ }
78
96
  }
79
- const filePath = `${logDir}/${file}`;
80
- const stats = await import_fs.default.promises.stat(filePath);
81
- if (stats.mtimeMs < sevenDaysAgo) {
82
- await import_fs.default.promises.unlink(filePath);
83
- logger.debug(`[${tag}] Deleted old log file: ${filePath}`);
84
- }
85
- }
97
+ logger.debug(`[${tag}] Deleted ${deletedCount} old log file(s).`);
98
+ }, "writeAndCleanup");
99
+ setTimeout(() => {
100
+ writeAndCleanup().catch(() => void 0);
101
+ }, 0);
86
102
  }
87
103
  __name(trackLogToLocal, "trackLogToLocal");
88
104
  // Annotate the CommonJS export names for ESM import in node:
@@ -34,21 +34,37 @@ async function trackLogToLocal(tag, output, logger) {
34
34
  if (!fs.existsSync(logDir)) {
35
35
  fs.mkdirSync(logDir, { recursive: true });
36
36
  }
37
- await fs.promises.writeFile(logFile, output);
38
- logger.info(`[${tag}] A local log file has been created at ${logFile}`);
39
- const sevenDaysAgo = Date.now() - 7 * 24 * 60 * 60 * 1e3;
40
- const files = await fs.promises.readdir(logDir);
41
- for (const file of files) {
42
- if (!file.startsWith("chatluna-log-") || !file.endsWith(".log")) {
43
- continue;
37
+ const writeAndCleanup = /* @__PURE__ */ __name(async () => {
38
+ await fs.promises.writeFile(logFile, output);
39
+ logger.info(`[${tag}] A local log file has been created at ${logFile}`);
40
+ const sevenDaysAgo = Date.now() - 7 * 24 * 60 * 60 * 1e3;
41
+ const files = await fs.promises.readdir(logDir);
42
+ let deletedCount = 0;
43
+ for (const file of files) {
44
+ if (!file.startsWith("chatluna-log-") || !file.endsWith(".log")) {
45
+ continue;
46
+ }
47
+ const filePath = `${logDir}/${file}`;
48
+ let stats;
49
+ try {
50
+ stats = await fs.promises.stat(filePath);
51
+ } catch {
52
+ continue;
53
+ }
54
+ if (stats.mtimeMs < sevenDaysAgo) {
55
+ try {
56
+ await fs.promises.unlink(filePath);
57
+ deletedCount += 1;
58
+ } catch {
59
+ }
60
+ await new Promise((resolve) => setTimeout(resolve, 0));
61
+ }
44
62
  }
45
- const filePath = `${logDir}/${file}`;
46
- const stats = await fs.promises.stat(filePath);
47
- if (stats.mtimeMs < sevenDaysAgo) {
48
- await fs.promises.unlink(filePath);
49
- logger.debug(`[${tag}] Deleted old log file: ${filePath}`);
50
- }
51
- }
63
+ logger.debug(`[${tag}] Deleted ${deletedCount} old log file(s).`);
64
+ }, "writeAndCleanup");
65
+ setTimeout(() => {
66
+ writeAndCleanup().catch(() => void 0);
67
+ }, 0);
52
68
  }
53
69
  __name(trackLogToLocal, "trackLogToLocal");
54
70
  export {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-chatluna",
3
3
  "description": "chatluna for koishi",
4
- "version": "1.3.13",
4
+ "version": "1.3.14",
5
5
  "main": "lib/index.cjs",
6
6
  "module": "lib/index.mjs",
7
7
  "typings": "lib/index.d.ts",