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.
- package/lib/llm-core/agent/openai/index.d.ts +1 -1
- package/lib/llm-core/agent/openai/output_parser.d.ts +1 -1
- package/lib/llm-core/agent/react/index.d.ts +1 -1
- package/lib/llm-core/chat/app.cjs +3 -3
- package/lib/llm-core/chat/app.mjs +3 -3
- package/lib/services/chat.cjs +9 -9
- package/lib/services/chat.mjs +9 -9
- package/lib/utils/logger.cjs +30 -14
- package/lib/utils/logger.mjs +30 -14
- package/package.json +1 -1
|
@@ -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 |
|
|
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<
|
|
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").
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
882
|
+
threshold: this.ctx.chatluna.currentConfig.infiniteContextThreshold
|
|
883
883
|
});
|
|
884
884
|
}
|
|
885
885
|
return this._infiniteContextManager;
|
package/lib/services/chat.cjs
CHANGED
|
@@ -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,
|
|
1175
|
+
constructor(ctx, currentConfig) {
|
|
1176
1176
|
super(ctx, "chatluna");
|
|
1177
1177
|
this.ctx = ctx;
|
|
1178
|
-
this.
|
|
1179
|
-
this._chain = new ChatChain(ctx,
|
|
1180
|
-
this._keysCache = new Cache(this.ctx,
|
|
1181
|
-
this._preset = new import_preset.PresetService(ctx,
|
|
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(
|
|
1184
|
-
this._renderer = new import_koishi_plugin_chatluna3.DefaultRenderer(ctx,
|
|
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.
|
|
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.
|
|
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],
|
package/lib/services/chat.mjs
CHANGED
|
@@ -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,
|
|
1200
|
+
constructor(ctx, currentConfig) {
|
|
1201
1201
|
super(ctx, "chatluna");
|
|
1202
1202
|
this.ctx = ctx;
|
|
1203
|
-
this.
|
|
1204
|
-
this._chain = new ChatChain(ctx,
|
|
1205
|
-
this._keysCache = new Cache(this.ctx,
|
|
1206
|
-
this._preset = new PresetService(ctx,
|
|
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(
|
|
1209
|
-
this._renderer = new DefaultRenderer(ctx,
|
|
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.
|
|
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.
|
|
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],
|
package/lib/utils/logger.cjs
CHANGED
|
@@ -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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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:
|
package/lib/utils/logger.mjs
CHANGED
|
@@ -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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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 {
|