koishi-plugin-chatluna 1.4.0-alpha.39 → 1.4.0-alpha.40
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/chains/chain.d.ts +1 -1
- package/lib/chains/index.cjs +14 -6
- package/lib/chains/index.mjs +14 -6
- package/lib/config.d.ts +1 -0
- package/lib/index.cjs +45 -53
- package/lib/index.mjs +45 -53
- package/lib/llm-core/agent/sub-agent/tool.d.ts +8 -8
- package/lib/llm-core/chat/helper.d.ts +2 -1
- package/lib/llm-core/prompt/type.d.ts +2 -0
- package/lib/middlewares/chat/message_delay.d.ts +1 -0
- package/lib/middlewares/chat/thinking_message_send.d.ts +2 -0
- package/lib/middlewares/conversation/request_conversation.d.ts +0 -1
- package/lib/preset.cjs +14 -0
- package/lib/preset.d.ts +1 -0
- package/lib/preset.mjs +14 -0
- package/lib/services/chat.cjs +24 -8
- package/lib/services/chat.mjs +24 -8
- package/lib/services/conversation_runtime.d.ts +1 -1
- package/package.json +1 -1
package/lib/chains/chain.d.ts
CHANGED
|
@@ -50,7 +50,7 @@ export declare class ChainMiddleware {
|
|
|
50
50
|
constructor(name: string, execute: ChainMiddlewareFunction, graph: ChatChainDependencyGraph);
|
|
51
51
|
before<T extends keyof ChainMiddlewareName>(name: T): this;
|
|
52
52
|
after<T extends keyof ChainMiddlewareName>(name: T): this;
|
|
53
|
-
run(session: Session, options: ChainMiddlewareContext): Promise<string |
|
|
53
|
+
run(session: Session, options: ChainMiddlewareContext): Promise<string | h[] | h[][] | ChainMiddlewareRunStatus>;
|
|
54
54
|
}
|
|
55
55
|
export interface ChainMiddlewareContext {
|
|
56
56
|
config: Config;
|
package/lib/chains/index.cjs
CHANGED
|
@@ -88,6 +88,7 @@ var ChatChain = class {
|
|
|
88
88
|
const timeoutObj = context.options.thinkingTimeoutObject;
|
|
89
89
|
clearTimeout(timeoutObj.timeout);
|
|
90
90
|
timeoutObj.autoRecallTimeout && clearTimeout(timeoutObj.autoRecallTimeout);
|
|
91
|
+
timeoutObj.setQueueCount(0);
|
|
91
92
|
timeoutObj.recallFunc && await timeoutObj.recallFunc();
|
|
92
93
|
timeoutObj.timeout = null;
|
|
93
94
|
context.options.thinkingTimeoutObject = void 0;
|
|
@@ -108,9 +109,12 @@ var ChatChain = class {
|
|
|
108
109
|
)
|
|
109
110
|
};
|
|
110
111
|
context.recallThinkingMessage = this._createRecallThinkingMessage(context);
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
112
|
+
try {
|
|
113
|
+
return await this._runMiddleware(session, context);
|
|
114
|
+
} finally {
|
|
115
|
+
await context.options.completeMessageTurn?.();
|
|
116
|
+
await context.recallThinkingMessage();
|
|
117
|
+
}
|
|
114
118
|
}
|
|
115
119
|
async receiveCommand(session, command, options = {}, ctx = this.ctx) {
|
|
116
120
|
return (await this.runCommand(session, command, options, ctx)).ok;
|
|
@@ -141,9 +145,13 @@ var ChatChain = class {
|
|
|
141
145
|
}
|
|
142
146
|
};
|
|
143
147
|
context.recallThinkingMessage = this._createRecallThinkingMessage(context);
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
148
|
+
try {
|
|
149
|
+
const ok = await this._runMiddleware(session, context);
|
|
150
|
+
return { ok, context };
|
|
151
|
+
} finally {
|
|
152
|
+
await context.options.completeMessageTurn?.();
|
|
153
|
+
await context.recallThinkingMessage();
|
|
154
|
+
}
|
|
147
155
|
}
|
|
148
156
|
middleware(name, middleware, ctx = this.ctx) {
|
|
149
157
|
const result = new ChainMiddleware(name, middleware, this._graph);
|
package/lib/chains/index.mjs
CHANGED
|
@@ -67,6 +67,7 @@ var ChatChain = class {
|
|
|
67
67
|
const timeoutObj = context.options.thinkingTimeoutObject;
|
|
68
68
|
clearTimeout(timeoutObj.timeout);
|
|
69
69
|
timeoutObj.autoRecallTimeout && clearTimeout(timeoutObj.autoRecallTimeout);
|
|
70
|
+
timeoutObj.setQueueCount(0);
|
|
70
71
|
timeoutObj.recallFunc && await timeoutObj.recallFunc();
|
|
71
72
|
timeoutObj.timeout = null;
|
|
72
73
|
context.options.thinkingTimeoutObject = void 0;
|
|
@@ -87,9 +88,12 @@ var ChatChain = class {
|
|
|
87
88
|
)
|
|
88
89
|
};
|
|
89
90
|
context.recallThinkingMessage = this._createRecallThinkingMessage(context);
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
try {
|
|
92
|
+
return await this._runMiddleware(session, context);
|
|
93
|
+
} finally {
|
|
94
|
+
await context.options.completeMessageTurn?.();
|
|
95
|
+
await context.recallThinkingMessage();
|
|
96
|
+
}
|
|
93
97
|
}
|
|
94
98
|
async receiveCommand(session, command, options = {}, ctx = this.ctx) {
|
|
95
99
|
return (await this.runCommand(session, command, options, ctx)).ok;
|
|
@@ -120,9 +124,13 @@ var ChatChain = class {
|
|
|
120
124
|
}
|
|
121
125
|
};
|
|
122
126
|
context.recallThinkingMessage = this._createRecallThinkingMessage(context);
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
127
|
+
try {
|
|
128
|
+
const ok = await this._runMiddleware(session, context);
|
|
129
|
+
return { ok, context };
|
|
130
|
+
} finally {
|
|
131
|
+
await context.options.completeMessageTurn?.();
|
|
132
|
+
await context.recallThinkingMessage();
|
|
133
|
+
}
|
|
126
134
|
}
|
|
127
135
|
middleware(name, middleware, ctx = this.ctx) {
|
|
128
136
|
const result = new ChainMiddleware(name, middleware, this._graph);
|
package/lib/config.d.ts
CHANGED
package/lib/index.cjs
CHANGED
|
@@ -34,14 +34,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
34
34
|
// src/locales/zh-CN.schema.yml
|
|
35
35
|
var require_zh_CN_schema = __commonJS({
|
|
36
36
|
"src/locales/zh-CN.schema.yml"(exports2, module2) {
|
|
37
|
-
module2.exports = { $inner: [{ $desc: "bot 配置", botNames: "设置 bot 的名称。(只有第一个名称是实际的 bot 名称,其他名称仅用于触发对话)", isNickname: "是否允许在开头匹配 bot 配置中的昵称来触发对话。", isNickNameWithContent: "是否允许在对话内容里任意匹配 bot 配置中的昵称来触发对话。" }, { $desc: "对话行为选项", allowPrivate: "是否允许在私聊中触发对话。", allowAtReply: "是否允许通过 @ bot 来触发对话。", allowQuoteReply: "是否允许通过引用 bot 的消息来触发对话。", privateChatWithoutCommand: "在私聊中是否允许无需命令直接与 bot 对话。", allowConversationTriggerPrefix: "是否允许使用会话标题前缀触发对话。注意:启用此选项可能会显著影响 ChatLuna 的性能,建议配合过滤器仅在特定群组中启用。", randomReplyFrequency: "设置随机回复的频率。", includeQuoteReply: "是否在向模型的请求内容中添加被引用的消息内容", attachForwardMsgIdToContext: "是否将合并转发聊天记录消息的 ID 附加到上下文中。启用后,检测到聊天记录会额外追加一条 [聊天记录] 消息。" }, { isForwardMsg: "是否以合并消息的形式发送 bot 的回复。", forwardMsgMinLength: "合并消息的最小应用长度。为 0 则总是应用。设置大于 0 时,只有发送的文本大于此长度才会转为合并消息。" }, { isReplyWithAt: "当 bot 回复时,是否引用原消息", replyQuoteThreshold: "引用原消息的最小响应时长。为 0 则总是应用。设置大于 0 时,只有响应耗时大于此时长才会引用原消息。" }, { $desc: "对话响应选项", sendThinkingMessage: "是否在请求处理过程中发送等待消息。", sendThinkingMessageTimeout: "设置在模型开始响应前,等待多少毫秒后发送等待消息。", thinkingMessage: "自定义等待消息的内容。", msgCooldown: "设置全局消息冷却时间(单位:秒),用于防止适配器被过于频繁地调用。", messageQueue: "设置是否启用消息队列。启用后当发送了多条消息,并且模型未响应初始消息时,会将将消息缓存合并成一条消息,并等待模型响应后再发送。", messageQueueDelay: "设置消息队列的延迟时间(单位:秒)。为 0 则不启用延迟。开启延迟后,会等待指定时间后才发送消息给模型,如果在此期间内存在未处理的消息,则将消息缓存合并成多条消息发送给模型。", agentTaskAutoWakeup: "后台代理任务完成后自动唤醒所在对话。关闭后回到手动 status 查询模式。", showThoughtMessage: "在使用插件模式或思考模型时,是否显示思考过程。" }, { $desc: "消息渲染选项", outputMode: { $desc: "选择消息回复的渲染输出模式。" }, splitMessage: { $desc: "设置消息分割发送方式。非流式和流式回复都会按此选项切割;语音和混合语音会在达到切割点时立即渲染发送。", $inner: ["不切割", "按标点切割", "按段落切割"] }, censor: "是否启用文本审核服务(需要安装 censor 服务)。", rawOnCensor: "是否在 Post Handler 被触发时,将原始消息发送给模型。", streamResponse: "是否启用流式响应。启用后,bot 会在生成回复的过程中就开始发送消息,而不是等待完全生成后再发送。注意:启用此选项会导致渲染输出模式选项失效,且不支持插件模式。" }, { $desc: "黑名单选项", blackList: { $desc: "设置黑名单列表。请谨慎使用,只对需要拉黑的用户或群启用。1 表示启用黑名单,0 表示不启用黑名单。默认值为 0。" } }, { $desc: "历史记录选项", infiniteContext: "启用「无限上下文」,当对话接近模型的上下文上限时自动压缩旧消息,保留关键话题和指令并丢弃无关内容。", infiniteContextThreshold: "设置无限上下文的触发阈值(百分比)。当对话历史的 token 数量达到模型上下文上限的该百分比时,将触发压缩。", autoArchive: "是否自动归档长期未使用的会话,而不是继续保留旧的房间状态。", autoArchiveTimeout: "设置自动归档未使用会话的时间阈值(单位:秒)。", autoPurgeArchive: "是否在归档会话超过保留时间后自动彻底删除。", autoPurgeArchiveTimeout: "设置归档会话被自动删除前的保留时间(单位:秒)。" }, { $desc: "模型选项", defaultEmbeddings: "设置默认使用的嵌入模型。", defaultVectorStore: "设置默认使用的向量数据库。" }, { $desc: "会话路由默认配置", defaultGroupRouteMode: { $desc: "设置群聊场景下默认的会话路由模式,决定群成员是共享同一路由还是各自拥有独立路由,也会影响预设分流。", $inner: ["群共享会话", "成员独立会话"] }, defaultChatMode: "设置默认的聊天模式。", defaultModel: "设置默认使用的聊天模型。", defaultPreset: "设置默认使用的聊天预设。" }, { $desc: "杂项", errorTemplate: "设置错误提示消息的模板(此设置在未来版本中可能会有变更)。", voiceSpeakId: "设置使用 vits 服务时的默认发音人 ID。", isLog: "是否启用调试模式。" }, { isProxy: { $desc: "是否启用代理。启用后,ChatLuna 全家桶插件的网络请求将使用此代理。", $inner: [true] }, proxyAddress: "网络请求的代理地址。填写后,ChatLuna 相关插件的网络服务将使用此代理地址。若为空,将尝试使用 Koishi 全局配置中的代理设置。" }] };
|
|
37
|
+
module2.exports = { $inner: [{ $desc: "bot 配置", botNames: "设置 bot 的名称。(只有第一个名称是实际的 bot 名称,其他名称仅用于触发对话)", isNickname: "是否允许在开头匹配 bot 配置中的昵称来触发对话。", isNickNameWithContent: "是否允许在对话内容里任意匹配 bot 配置中的昵称来触发对话。" }, { $desc: "对话行为选项", allowPrivate: "是否允许在私聊中触发对话。", allowAtReply: "是否允许通过 @ bot 来触发对话。", allowQuoteReply: "是否允许通过引用 bot 的消息来触发对话。", privateChatWithoutCommand: "在私聊中是否允许无需命令直接与 bot 对话。", allowConversationTriggerPrefix: "是否允许使用会话标题前缀触发对话。注意:启用此选项可能会显著影响 ChatLuna 的性能,建议配合过滤器仅在特定群组中启用。", randomReplyFrequency: "设置随机回复的频率。", includeQuoteReply: "是否在向模型的请求内容中添加被引用的消息内容", attachForwardMsgIdToContext: "是否将合并转发聊天记录消息的 ID 附加到上下文中。启用后,检测到聊天记录会额外追加一条 [聊天记录] 消息。" }, { isForwardMsg: "是否以合并消息的形式发送 bot 的回复。", forwardMsgMinLength: "合并消息的最小应用长度。为 0 则总是应用。设置大于 0 时,只有发送的文本大于此长度才会转为合并消息。" }, { isReplyWithAt: "当 bot 回复时,是否引用原消息", replyQuoteThreshold: "引用原消息的最小响应时长。为 0 则总是应用。设置大于 0 时,只有响应耗时大于此时长才会引用原消息。" }, { $desc: "对话响应选项", sendThinkingMessage: "是否在请求处理过程中发送等待消息。", sendThinkingMessageTimeout: "设置在模型开始响应前,等待多少毫秒后发送等待消息。", thinkingMessage: "自定义等待消息的内容。", msgCooldown: "设置全局消息冷却时间(单位:秒),用于防止适配器被过于频繁地调用。", messageQueue: "设置是否启用消息队列。启用后当发送了多条消息,并且模型未响应初始消息时,会将将消息缓存合并成一条消息,并等待模型响应后再发送。", messageQueueDelay: "设置消息队列的延迟时间(单位:秒)。为 0 则不启用延迟。开启延迟后,会等待指定时间后才发送消息给模型,如果在此期间内存在未处理的消息,则将消息缓存合并成多条消息发送给模型。", agentTaskAutoWakeup: "后台代理任务完成后自动唤醒所在对话。关闭后回到手动 status 查询模式。", showThoughtMessage: "在使用插件模式或思考模型时,是否显示思考过程。" }, { $desc: "消息渲染选项", outputMode: { $desc: "选择消息回复的渲染输出模式。" }, splitMessage: { $desc: "设置消息分割发送方式。非流式和流式回复都会按此选项切割;语音和混合语音会在达到切割点时立即渲染发送。", $inner: ["不切割", "按标点切割", "按段落切割"] }, censor: "是否启用文本审核服务(需要安装 censor 服务)。", rawOnCensor: "是否在 Post Handler 被触发时,将原始消息发送给模型。", streamResponse: "是否启用流式响应。启用后,bot 会在生成回复的过程中就开始发送消息,而不是等待完全生成后再发送。注意:启用此选项会导致渲染输出模式选项失效,且不支持插件模式。" }, { $desc: "黑名单选项", blackList: { $desc: "设置黑名单列表。请谨慎使用,只对需要拉黑的用户或群启用。1 表示启用黑名单,0 表示不启用黑名单。默认值为 0。" } }, { $desc: "历史记录选项", infiniteContext: "启用「无限上下文」,当对话接近模型的上下文上限时自动压缩旧消息,保留关键话题和指令并丢弃无关内容。", infiniteContextThreshold: "设置无限上下文的触发阈值(百分比)。当对话历史的 token 数量达到模型上下文上限的该百分比时,将触发压缩。", autoArchive: "是否自动归档长期未使用的会话,而不是继续保留旧的房间状态。", autoArchiveTimeout: "设置自动归档未使用会话的时间阈值(单位:秒)。", autoPurgeArchive: "是否在归档会话超过保留时间后自动彻底删除。", autoPurgeArchiveTimeout: "设置归档会话被自动删除前的保留时间(单位:秒)。" }, { $desc: "模型选项", defaultEmbeddings: "设置默认使用的嵌入模型。", defaultVectorStore: "设置默认使用的向量数据库。" }, { $desc: "会话路由默认配置", defaultGroupRouteMode: { $desc: "设置群聊场景下默认的会话路由模式,决定群成员是共享同一路由还是各自拥有独立路由,也会影响预设分流。", $inner: ["群共享会话", "成员独立会话"] }, defaultChatMode: "设置默认的聊天模式。", defaultModel: "设置默认使用的聊天模型。", defaultPreset: "设置默认使用的聊天预设。", enablePresetKeywordTrigger: "是否允许通过消息开头的预设关键词切换预设分流。" }, { $desc: "杂项", errorTemplate: "设置错误提示消息的模板(此设置在未来版本中可能会有变更)。", voiceSpeakId: "设置使用 vits 服务时的默认发音人 ID。", isLog: "是否启用调试模式。" }, { isProxy: { $desc: "是否启用代理。启用后,ChatLuna 全家桶插件的网络请求将使用此代理。", $inner: [true] }, proxyAddress: "网络请求的代理地址。填写后,ChatLuna 相关插件的网络服务将使用此代理地址。若为空,将尝试使用 Koishi 全局配置中的代理设置。" }] };
|
|
38
38
|
}
|
|
39
39
|
});
|
|
40
40
|
|
|
41
41
|
// src/locales/en-US.schema.yml
|
|
42
42
|
var require_en_US_schema = __commonJS({
|
|
43
43
|
"src/locales/en-US.schema.yml"(exports2, module2) {
|
|
44
|
-
module2.exports = { $inner: [{ $desc: "Bot Configuration", botNames: "Set the bot's name. (Only the first name is the actual bot name; other names are only used to trigger conversations.)", isNickname: "Allow matching bot nickname at the beginning of a message to trigger a conversation.", isNickNameWithContent: "Allow matching bot nickname anywhere in the message content to trigger a conversation." }, { $desc: "Conversation Behavior", allowPrivate: "Enable private chat conversations.", allowAtReply: "Enable @mention triggering.", allowQuoteReply: "Enable quote triggering.", privateChatWithoutCommand: "Enable direct conversation in private chats without commands.", allowConversationTriggerPrefix: "Enable conversation title prefix triggering. Note: May impact performance significantly. Recommended for use with filters in specific groups only.", randomReplyFrequency: "Set random reply frequency (0-100, where 0 means never and 100 means always).", includeQuoteReply: "Include quoted message content in requests sent to the model.", attachForwardMsgIdToContext: 'Attach forward message record IDs to context. When enabled, a "[聊天记录]" marker message will be appended if forward records are detected.' }, { isForwardMsg: "Send bot replies as forwarded messages.", forwardMsgMinLength: "Set minimum length of forwarded messages (characters)." }, { isReplyWithAt: "Quote the original message when the bot replies.", replyQuoteThreshold: "Minimum response time required to quote the original message. Set to 0 to always apply. When greater than 0, the original message will only be quoted if the response time exceeds this threshold." }, { $desc: "Response Options", sendThinkingMessage: "Send waiting message during processing.", sendThinkingMessageTimeout: "Set timeout (ms) for waiting message dispatch.", thinkingMessage: "Customize waiting message content.", msgCooldown: "Set global message cooldown (seconds) to limit adapter calls.", messageQueue: "Enable message queue. When enabled, if multiple messages are sent and the model has not responded to the initial message, the messages will be cached and merged into one message, and will be sent after waiting for the model response.", messageQueueDelay: "Set message queue delay time (seconds). Set to 0 to disable delay. When delay is enabled, the system will wait for the specified time before sending messages to the model. If there are unprocessed messages during this period, they will be cached and merged into multiple messages to send to the model.", agentTaskAutoWakeup: "Automatically wake up the conversation when a background agent task finishes. Disable to return to manual status checks.", showThoughtMessage: "Display thinking message in plugin mode or reasoner model." }, { $desc: "Message Rendering", outputMode: { $desc: "Select message reply rendering mode." }, splitMessage: { $desc: "Split outgoing messages. Applies to both streaming and non-streaming replies; voice and mixed-voice renderers send as soon as a split point is reached.", $inner: ["Do not split", "Split by punctuation", "Split by paragraph"] }, censor: "Enable text moderation (requires censor service).", rawOnCensor: "Whether to send the raw message to the model when the Post Handler is triggered.", streamResponse: "Enable stream response. Initiates message sending during reply generation. Note: Disables rendering output mode and incompatible with plugin mode." }, { $desc: "Blacklist Management", blackList: "Configure blacklist. Use cautiously to avoid unintended blocking. The number 1 indicates enabled blacklist. Set to zero value to unenable blacklist." }, { $desc: "History Management", infiniteContext: "Enable automatic Infinite Context compression when history nears the model limit. Preserves critical topics and instructions while discarding noise.", infiniteContextThreshold: "Set the threshold (percentage) for triggering Infinite Context compression. Compression will be triggered when the token count of conversation history reaches this percentage of the model's context limit.", autoArchive: "Enable automatic archiving of inactive conversations instead of keeping legacy room state alive.", autoArchiveTimeout: "Set inactivity threshold for conversation archiving in seconds.", autoPurgeArchive: "Enable automatic deletion of archived conversations after the purge timeout.", autoPurgeArchiveTimeout: "Set how long archived conversations are retained before automatic purge in seconds." }, { $desc: "Model Configuration", defaultEmbeddings: "Set default embedding model.", defaultVectorStore: "Set default vector database." }, { $desc: "Conversation Routing Defaults", defaultGroupRouteMode: { $desc: "Set the default conversation route mode for group chats. This controls whether group members share one conversation route or get personal routes, including preset-lane routes.", $inner: ["Shared group conversation", "Personal conversation per member"] }, defaultChatMode: "Set default chat mode.", defaultModel: "Set default chat model.", defaultPreset: "Set default chat preset." }, { $desc: "Miscellaneous", errorTemplate: "Set error prompt message template (subject to change).", voiceSpeakId: "Set default speaker ID for vits service.", isLog: "Enable debug mode." }, { isProxy: { $desc: "Enable proxy for ChatLuna family plugin network requests.", $inner: [true] }, proxyAddress: "Set proxy address for network requests. Falls back to Koishi global proxy settings if cleared." }] };
|
|
44
|
+
module2.exports = { $inner: [{ $desc: "Bot Configuration", botNames: "Set the bot's name. (Only the first name is the actual bot name; other names are only used to trigger conversations.)", isNickname: "Allow matching bot nickname at the beginning of a message to trigger a conversation.", isNickNameWithContent: "Allow matching bot nickname anywhere in the message content to trigger a conversation." }, { $desc: "Conversation Behavior", allowPrivate: "Enable private chat conversations.", allowAtReply: "Enable @mention triggering.", allowQuoteReply: "Enable quote triggering.", privateChatWithoutCommand: "Enable direct conversation in private chats without commands.", allowConversationTriggerPrefix: "Enable conversation title prefix triggering. Note: May impact performance significantly. Recommended for use with filters in specific groups only.", randomReplyFrequency: "Set random reply frequency (0-100, where 0 means never and 100 means always).", includeQuoteReply: "Include quoted message content in requests sent to the model.", attachForwardMsgIdToContext: 'Attach forward message record IDs to context. When enabled, a "[聊天记录]" marker message will be appended if forward records are detected.' }, { isForwardMsg: "Send bot replies as forwarded messages.", forwardMsgMinLength: "Set minimum length of forwarded messages (characters)." }, { isReplyWithAt: "Quote the original message when the bot replies.", replyQuoteThreshold: "Minimum response time required to quote the original message. Set to 0 to always apply. When greater than 0, the original message will only be quoted if the response time exceeds this threshold." }, { $desc: "Response Options", sendThinkingMessage: "Send waiting message during processing.", sendThinkingMessageTimeout: "Set timeout (ms) for waiting message dispatch.", thinkingMessage: "Customize waiting message content.", msgCooldown: "Set global message cooldown (seconds) to limit adapter calls.", messageQueue: "Enable message queue. When enabled, if multiple messages are sent and the model has not responded to the initial message, the messages will be cached and merged into one message, and will be sent after waiting for the model response.", messageQueueDelay: "Set message queue delay time (seconds). Set to 0 to disable delay. When delay is enabled, the system will wait for the specified time before sending messages to the model. If there are unprocessed messages during this period, they will be cached and merged into multiple messages to send to the model.", agentTaskAutoWakeup: "Automatically wake up the conversation when a background agent task finishes. Disable to return to manual status checks.", showThoughtMessage: "Display thinking message in plugin mode or reasoner model." }, { $desc: "Message Rendering", outputMode: { $desc: "Select message reply rendering mode." }, splitMessage: { $desc: "Split outgoing messages. Applies to both streaming and non-streaming replies; voice and mixed-voice renderers send as soon as a split point is reached.", $inner: ["Do not split", "Split by punctuation", "Split by paragraph"] }, censor: "Enable text moderation (requires censor service).", rawOnCensor: "Whether to send the raw message to the model when the Post Handler is triggered.", streamResponse: "Enable stream response. Initiates message sending during reply generation. Note: Disables rendering output mode and incompatible with plugin mode." }, { $desc: "Blacklist Management", blackList: "Configure blacklist. Use cautiously to avoid unintended blocking. The number 1 indicates enabled blacklist. Set to zero value to unenable blacklist." }, { $desc: "History Management", infiniteContext: "Enable automatic Infinite Context compression when history nears the model limit. Preserves critical topics and instructions while discarding noise.", infiniteContextThreshold: "Set the threshold (percentage) for triggering Infinite Context compression. Compression will be triggered when the token count of conversation history reaches this percentage of the model's context limit.", autoArchive: "Enable automatic archiving of inactive conversations instead of keeping legacy room state alive.", autoArchiveTimeout: "Set inactivity threshold for conversation archiving in seconds.", autoPurgeArchive: "Enable automatic deletion of archived conversations after the purge timeout.", autoPurgeArchiveTimeout: "Set how long archived conversations are retained before automatic purge in seconds." }, { $desc: "Model Configuration", defaultEmbeddings: "Set default embedding model.", defaultVectorStore: "Set default vector database." }, { $desc: "Conversation Routing Defaults", defaultGroupRouteMode: { $desc: "Set the default conversation route mode for group chats. This controls whether group members share one conversation route or get personal routes, including preset-lane routes.", $inner: ["Shared group conversation", "Personal conversation per member"] }, defaultChatMode: "Set default chat mode.", defaultModel: "Set default chat model.", defaultPreset: "Set default chat preset.", enablePresetKeywordTrigger: "Allow switching preset lanes via keywords at the start of a message." }, { $desc: "Miscellaneous", errorTemplate: "Set error prompt message template (subject to change).", voiceSpeakId: "Set default speaker ID for vits service.", isLog: "Enable debug mode." }, { isProxy: { $desc: "Enable proxy for ChatLuna family plugin network requests.", $inner: [true] }, proxyAddress: "Set proxy address for network requests. Falls back to Koishi global proxy settings if cleared." }] };
|
|
45
45
|
}
|
|
46
46
|
});
|
|
47
47
|
|
|
@@ -2935,9 +2935,7 @@ function apply12(ctx, config, chain) {
|
|
|
2935
2935
|
}
|
|
2936
2936
|
if (parsePresetLaneInput(
|
|
2937
2937
|
content,
|
|
2938
|
-
ctx.chatluna.preset.
|
|
2939
|
-
(entry) => entry.split(",").map((item) => item.trim())
|
|
2940
|
-
)
|
|
2938
|
+
ctx.chatluna.preset.getKeywordTriggerAliases().value
|
|
2941
2939
|
) != null) {
|
|
2942
2940
|
return 2 /* CONTINUE */;
|
|
2943
2941
|
}
|
|
@@ -3308,32 +3306,10 @@ function apply17(ctx, config, chain) {
|
|
|
3308
3306
|
tryStartHeadTurn(conversationId, queue);
|
|
3309
3307
|
return await statusPromise;
|
|
3310
3308
|
}).after("transform_chat_message").before("lifecycle-handle_command");
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
}
|
|
3316
|
-
const current = conversation.turns.shift();
|
|
3317
|
-
conversation.inFlight = false;
|
|
3318
|
-
if (current?.timeout) {
|
|
3319
|
-
current.timeout();
|
|
3320
|
-
}
|
|
3321
|
-
if (current?.starter) {
|
|
3322
|
-
current.starter.resolve(1 /* STOP */);
|
|
3323
|
-
current.starter = void 0;
|
|
3324
|
-
}
|
|
3325
|
-
if (conversation.turns.length === 0) {
|
|
3326
|
-
queues.delete(conversationId);
|
|
3327
|
-
return;
|
|
3328
|
-
}
|
|
3329
|
-
tryStartHeadTurn(conversationId, conversation);
|
|
3330
|
-
if (current) {
|
|
3331
|
-
logger9.debug(
|
|
3332
|
-
`Completing turn for ${conversationId}, remaining: ${conversation.turns.length}`
|
|
3333
|
-
);
|
|
3334
|
-
}
|
|
3335
|
-
}, "completeTurn");
|
|
3336
|
-
ctx.on("chatluna/after-chat", completeTurn);
|
|
3309
|
+
ctx.on(
|
|
3310
|
+
"chatluna/after-chat",
|
|
3311
|
+
(conversationId) => completeTurn(conversationId)
|
|
3312
|
+
);
|
|
3337
3313
|
ctx.on(
|
|
3338
3314
|
"chatluna/after-chat-error",
|
|
3339
3315
|
(_error, conversationId) => completeTurn(conversationId)
|
|
@@ -3382,6 +3358,32 @@ function apply17(ctx, config, chain) {
|
|
|
3382
3358
|
);
|
|
3383
3359
|
}
|
|
3384
3360
|
__name(apply17, "apply");
|
|
3361
|
+
async function completeTurn(conversationId, expected) {
|
|
3362
|
+
const conversation = queues.get(conversationId);
|
|
3363
|
+
if (!conversation || expected != null && conversation.turns[0] !== expected) {
|
|
3364
|
+
return;
|
|
3365
|
+
}
|
|
3366
|
+
const current = conversation.turns.shift();
|
|
3367
|
+
conversation.inFlight = false;
|
|
3368
|
+
if (current?.timeout) {
|
|
3369
|
+
current.timeout();
|
|
3370
|
+
}
|
|
3371
|
+
if (current?.starter) {
|
|
3372
|
+
current.starter.resolve(1 /* STOP */);
|
|
3373
|
+
current.starter = void 0;
|
|
3374
|
+
}
|
|
3375
|
+
if (conversation.turns.length === 0) {
|
|
3376
|
+
queues.delete(conversationId);
|
|
3377
|
+
return;
|
|
3378
|
+
}
|
|
3379
|
+
tryStartHeadTurn(conversationId, conversation);
|
|
3380
|
+
if (current) {
|
|
3381
|
+
logger9.debug(
|
|
3382
|
+
`Completing turn for ${conversationId}, remaining: ${conversation.turns.length}`
|
|
3383
|
+
);
|
|
3384
|
+
}
|
|
3385
|
+
}
|
|
3386
|
+
__name(completeTurn, "completeTurn");
|
|
3385
3387
|
function awaitTurnStart(turn, context) {
|
|
3386
3388
|
if (turn.starter) {
|
|
3387
3389
|
turn.starter.resolve(1 /* STOP */);
|
|
@@ -3447,6 +3449,7 @@ function startHeadTurn(conversationId, conversation, head) {
|
|
|
3447
3449
|
head.starter = void 0;
|
|
3448
3450
|
conversation.inFlight = true;
|
|
3449
3451
|
head.state = "processing";
|
|
3452
|
+
starter.context.options.completeMessageTurn = () => completeTurn(conversationId, head);
|
|
3450
3453
|
starter.context.options.inputMessage = mergeMessages(
|
|
3451
3454
|
head.messages.sort((a, b) => a.timestamp - b.timestamp).map((msg) => msg.message)
|
|
3452
3455
|
);
|
|
@@ -3552,9 +3555,7 @@ function apply18(ctx, config, chain) {
|
|
|
3552
3555
|
const text = import_koishi7.h.select(message, "text").join("");
|
|
3553
3556
|
const parsed = parsePresetLaneInput(
|
|
3554
3557
|
text,
|
|
3555
|
-
ctx.chatluna.preset.
|
|
3556
|
-
(entry) => entry.split(",").map((item) => item.trim())
|
|
3557
|
-
)
|
|
3558
|
+
ctx.chatluna.preset.getKeywordTriggerAliases().value
|
|
3558
3559
|
);
|
|
3559
3560
|
if (parsed?.preset != null) {
|
|
3560
3561
|
const preset = ctx.chatluna.preset.getPreset(
|
|
@@ -4395,6 +4396,7 @@ __name(apply22, "apply");
|
|
|
4395
4396
|
|
|
4396
4397
|
// src/middlewares/chat/thinking_message_send.ts
|
|
4397
4398
|
var import_logger3 = require("koishi-plugin-chatluna/utils/logger");
|
|
4399
|
+
var import_promise = require("koishi-plugin-chatluna/utils/promise");
|
|
4398
4400
|
var logger11;
|
|
4399
4401
|
function apply23(ctx, config, chain) {
|
|
4400
4402
|
logger11 = (0, import_logger3.createLogger)(ctx);
|
|
@@ -4402,13 +4404,14 @@ function apply23(ctx, config, chain) {
|
|
|
4402
4404
|
if (!config.sendThinkingMessage || context.command?.length > 0) {
|
|
4403
4405
|
return 0 /* SKIPPED */;
|
|
4404
4406
|
}
|
|
4405
|
-
const
|
|
4407
|
+
const queue = (0, import_promise.withResolver)();
|
|
4408
|
+
const thinkingTimeoutObject = {
|
|
4409
|
+
queueCount: queue.promise,
|
|
4410
|
+
setQueueCount: queue.resolve
|
|
4411
|
+
};
|
|
4406
4412
|
context.options.thinkingTimeoutObject = thinkingTimeoutObject;
|
|
4407
4413
|
thinkingTimeoutObject.timeout = setTimeout(async () => {
|
|
4408
|
-
const queueCount = await
|
|
4409
|
-
thinkingTimeoutObject,
|
|
4410
|
-
context.options
|
|
4411
|
-
);
|
|
4414
|
+
const queueCount = await thinkingTimeoutObject.queueCount;
|
|
4412
4415
|
if (thinkingTimeoutObject.timeout == null || queueCount < 1) {
|
|
4413
4416
|
return;
|
|
4414
4417
|
}
|
|
@@ -4441,18 +4444,6 @@ function apply23(ctx, config, chain) {
|
|
|
4441
4444
|
}).before("lifecycle-prepare");
|
|
4442
4445
|
}
|
|
4443
4446
|
__name(apply23, "apply");
|
|
4444
|
-
async function getQueueCount(obj, options) {
|
|
4445
|
-
await new Promise((resolve, reject) => {
|
|
4446
|
-
const timer = setInterval(() => {
|
|
4447
|
-
if (obj.timeout != null && options.queueCount != null) {
|
|
4448
|
-
clearInterval(timer);
|
|
4449
|
-
resolve(void 0);
|
|
4450
|
-
}
|
|
4451
|
-
});
|
|
4452
|
-
});
|
|
4453
|
-
return options.queueCount;
|
|
4454
|
-
}
|
|
4455
|
-
__name(getQueueCount, "getQueueCount");
|
|
4456
4447
|
|
|
4457
4448
|
// src/middlewares/conversation/request_conversation.ts
|
|
4458
4449
|
var import_error5 = require("koishi-plugin-chatluna/utils/error");
|
|
@@ -4582,7 +4573,7 @@ function createChatCallbacks(context, config, stream, captureOnly) {
|
|
|
4582
4573
|
await stream.write({ type: "content", chunk });
|
|
4583
4574
|
},
|
|
4584
4575
|
"llm-queue-waiting": /* @__PURE__ */ __name(async (count) => {
|
|
4585
|
-
context.options.
|
|
4576
|
+
context.options.thinkingTimeoutObject?.setQueueCount(count);
|
|
4586
4577
|
}, "llm-queue-waiting"),
|
|
4587
4578
|
"llm-usage": /* @__PURE__ */ __name(async (usage2) => {
|
|
4588
4579
|
if (context.options.invocation != null) {
|
|
@@ -6715,7 +6706,8 @@ var Config2 = import_koishi13.Schema.intersect([
|
|
|
6715
6706
|
]).default("shared"),
|
|
6716
6707
|
defaultChatMode: import_koishi13.Schema.dynamic("chat-mode").default("plugin"),
|
|
6717
6708
|
defaultModel: import_koishi13.Schema.dynamic("model").default("无"),
|
|
6718
|
-
defaultPreset: import_koishi13.Schema.dynamic("preset").default("sydney")
|
|
6709
|
+
defaultPreset: import_koishi13.Schema.dynamic("preset").default("sydney"),
|
|
6710
|
+
enablePresetKeywordTrigger: import_koishi13.Schema.boolean().default(true)
|
|
6719
6711
|
}),
|
|
6720
6712
|
import_koishi13.Schema.object({
|
|
6721
6713
|
voiceSpeakId: import_koishi13.Schema.number().default(0),
|
package/lib/index.mjs
CHANGED
|
@@ -8,14 +8,14 @@ var __commonJS = (cb, mod) => function __require() {
|
|
|
8
8
|
// src/locales/zh-CN.schema.yml
|
|
9
9
|
var require_zh_CN_schema = __commonJS({
|
|
10
10
|
"src/locales/zh-CN.schema.yml"(exports, module) {
|
|
11
|
-
module.exports = { $inner: [{ $desc: "bot 配置", botNames: "设置 bot 的名称。(只有第一个名称是实际的 bot 名称,其他名称仅用于触发对话)", isNickname: "是否允许在开头匹配 bot 配置中的昵称来触发对话。", isNickNameWithContent: "是否允许在对话内容里任意匹配 bot 配置中的昵称来触发对话。" }, { $desc: "对话行为选项", allowPrivate: "是否允许在私聊中触发对话。", allowAtReply: "是否允许通过 @ bot 来触发对话。", allowQuoteReply: "是否允许通过引用 bot 的消息来触发对话。", privateChatWithoutCommand: "在私聊中是否允许无需命令直接与 bot 对话。", allowConversationTriggerPrefix: "是否允许使用会话标题前缀触发对话。注意:启用此选项可能会显著影响 ChatLuna 的性能,建议配合过滤器仅在特定群组中启用。", randomReplyFrequency: "设置随机回复的频率。", includeQuoteReply: "是否在向模型的请求内容中添加被引用的消息内容", attachForwardMsgIdToContext: "是否将合并转发聊天记录消息的 ID 附加到上下文中。启用后,检测到聊天记录会额外追加一条 [聊天记录] 消息。" }, { isForwardMsg: "是否以合并消息的形式发送 bot 的回复。", forwardMsgMinLength: "合并消息的最小应用长度。为 0 则总是应用。设置大于 0 时,只有发送的文本大于此长度才会转为合并消息。" }, { isReplyWithAt: "当 bot 回复时,是否引用原消息", replyQuoteThreshold: "引用原消息的最小响应时长。为 0 则总是应用。设置大于 0 时,只有响应耗时大于此时长才会引用原消息。" }, { $desc: "对话响应选项", sendThinkingMessage: "是否在请求处理过程中发送等待消息。", sendThinkingMessageTimeout: "设置在模型开始响应前,等待多少毫秒后发送等待消息。", thinkingMessage: "自定义等待消息的内容。", msgCooldown: "设置全局消息冷却时间(单位:秒),用于防止适配器被过于频繁地调用。", messageQueue: "设置是否启用消息队列。启用后当发送了多条消息,并且模型未响应初始消息时,会将将消息缓存合并成一条消息,并等待模型响应后再发送。", messageQueueDelay: "设置消息队列的延迟时间(单位:秒)。为 0 则不启用延迟。开启延迟后,会等待指定时间后才发送消息给模型,如果在此期间内存在未处理的消息,则将消息缓存合并成多条消息发送给模型。", agentTaskAutoWakeup: "后台代理任务完成后自动唤醒所在对话。关闭后回到手动 status 查询模式。", showThoughtMessage: "在使用插件模式或思考模型时,是否显示思考过程。" }, { $desc: "消息渲染选项", outputMode: { $desc: "选择消息回复的渲染输出模式。" }, splitMessage: { $desc: "设置消息分割发送方式。非流式和流式回复都会按此选项切割;语音和混合语音会在达到切割点时立即渲染发送。", $inner: ["不切割", "按标点切割", "按段落切割"] }, censor: "是否启用文本审核服务(需要安装 censor 服务)。", rawOnCensor: "是否在 Post Handler 被触发时,将原始消息发送给模型。", streamResponse: "是否启用流式响应。启用后,bot 会在生成回复的过程中就开始发送消息,而不是等待完全生成后再发送。注意:启用此选项会导致渲染输出模式选项失效,且不支持插件模式。" }, { $desc: "黑名单选项", blackList: { $desc: "设置黑名单列表。请谨慎使用,只对需要拉黑的用户或群启用。1 表示启用黑名单,0 表示不启用黑名单。默认值为 0。" } }, { $desc: "历史记录选项", infiniteContext: "启用「无限上下文」,当对话接近模型的上下文上限时自动压缩旧消息,保留关键话题和指令并丢弃无关内容。", infiniteContextThreshold: "设置无限上下文的触发阈值(百分比)。当对话历史的 token 数量达到模型上下文上限的该百分比时,将触发压缩。", autoArchive: "是否自动归档长期未使用的会话,而不是继续保留旧的房间状态。", autoArchiveTimeout: "设置自动归档未使用会话的时间阈值(单位:秒)。", autoPurgeArchive: "是否在归档会话超过保留时间后自动彻底删除。", autoPurgeArchiveTimeout: "设置归档会话被自动删除前的保留时间(单位:秒)。" }, { $desc: "模型选项", defaultEmbeddings: "设置默认使用的嵌入模型。", defaultVectorStore: "设置默认使用的向量数据库。" }, { $desc: "会话路由默认配置", defaultGroupRouteMode: { $desc: "设置群聊场景下默认的会话路由模式,决定群成员是共享同一路由还是各自拥有独立路由,也会影响预设分流。", $inner: ["群共享会话", "成员独立会话"] }, defaultChatMode: "设置默认的聊天模式。", defaultModel: "设置默认使用的聊天模型。", defaultPreset: "设置默认使用的聊天预设。" }, { $desc: "杂项", errorTemplate: "设置错误提示消息的模板(此设置在未来版本中可能会有变更)。", voiceSpeakId: "设置使用 vits 服务时的默认发音人 ID。", isLog: "是否启用调试模式。" }, { isProxy: { $desc: "是否启用代理。启用后,ChatLuna 全家桶插件的网络请求将使用此代理。", $inner: [true] }, proxyAddress: "网络请求的代理地址。填写后,ChatLuna 相关插件的网络服务将使用此代理地址。若为空,将尝试使用 Koishi 全局配置中的代理设置。" }] };
|
|
11
|
+
module.exports = { $inner: [{ $desc: "bot 配置", botNames: "设置 bot 的名称。(只有第一个名称是实际的 bot 名称,其他名称仅用于触发对话)", isNickname: "是否允许在开头匹配 bot 配置中的昵称来触发对话。", isNickNameWithContent: "是否允许在对话内容里任意匹配 bot 配置中的昵称来触发对话。" }, { $desc: "对话行为选项", allowPrivate: "是否允许在私聊中触发对话。", allowAtReply: "是否允许通过 @ bot 来触发对话。", allowQuoteReply: "是否允许通过引用 bot 的消息来触发对话。", privateChatWithoutCommand: "在私聊中是否允许无需命令直接与 bot 对话。", allowConversationTriggerPrefix: "是否允许使用会话标题前缀触发对话。注意:启用此选项可能会显著影响 ChatLuna 的性能,建议配合过滤器仅在特定群组中启用。", randomReplyFrequency: "设置随机回复的频率。", includeQuoteReply: "是否在向模型的请求内容中添加被引用的消息内容", attachForwardMsgIdToContext: "是否将合并转发聊天记录消息的 ID 附加到上下文中。启用后,检测到聊天记录会额外追加一条 [聊天记录] 消息。" }, { isForwardMsg: "是否以合并消息的形式发送 bot 的回复。", forwardMsgMinLength: "合并消息的最小应用长度。为 0 则总是应用。设置大于 0 时,只有发送的文本大于此长度才会转为合并消息。" }, { isReplyWithAt: "当 bot 回复时,是否引用原消息", replyQuoteThreshold: "引用原消息的最小响应时长。为 0 则总是应用。设置大于 0 时,只有响应耗时大于此时长才会引用原消息。" }, { $desc: "对话响应选项", sendThinkingMessage: "是否在请求处理过程中发送等待消息。", sendThinkingMessageTimeout: "设置在模型开始响应前,等待多少毫秒后发送等待消息。", thinkingMessage: "自定义等待消息的内容。", msgCooldown: "设置全局消息冷却时间(单位:秒),用于防止适配器被过于频繁地调用。", messageQueue: "设置是否启用消息队列。启用后当发送了多条消息,并且模型未响应初始消息时,会将将消息缓存合并成一条消息,并等待模型响应后再发送。", messageQueueDelay: "设置消息队列的延迟时间(单位:秒)。为 0 则不启用延迟。开启延迟后,会等待指定时间后才发送消息给模型,如果在此期间内存在未处理的消息,则将消息缓存合并成多条消息发送给模型。", agentTaskAutoWakeup: "后台代理任务完成后自动唤醒所在对话。关闭后回到手动 status 查询模式。", showThoughtMessage: "在使用插件模式或思考模型时,是否显示思考过程。" }, { $desc: "消息渲染选项", outputMode: { $desc: "选择消息回复的渲染输出模式。" }, splitMessage: { $desc: "设置消息分割发送方式。非流式和流式回复都会按此选项切割;语音和混合语音会在达到切割点时立即渲染发送。", $inner: ["不切割", "按标点切割", "按段落切割"] }, censor: "是否启用文本审核服务(需要安装 censor 服务)。", rawOnCensor: "是否在 Post Handler 被触发时,将原始消息发送给模型。", streamResponse: "是否启用流式响应。启用后,bot 会在生成回复的过程中就开始发送消息,而不是等待完全生成后再发送。注意:启用此选项会导致渲染输出模式选项失效,且不支持插件模式。" }, { $desc: "黑名单选项", blackList: { $desc: "设置黑名单列表。请谨慎使用,只对需要拉黑的用户或群启用。1 表示启用黑名单,0 表示不启用黑名单。默认值为 0。" } }, { $desc: "历史记录选项", infiniteContext: "启用「无限上下文」,当对话接近模型的上下文上限时自动压缩旧消息,保留关键话题和指令并丢弃无关内容。", infiniteContextThreshold: "设置无限上下文的触发阈值(百分比)。当对话历史的 token 数量达到模型上下文上限的该百分比时,将触发压缩。", autoArchive: "是否自动归档长期未使用的会话,而不是继续保留旧的房间状态。", autoArchiveTimeout: "设置自动归档未使用会话的时间阈值(单位:秒)。", autoPurgeArchive: "是否在归档会话超过保留时间后自动彻底删除。", autoPurgeArchiveTimeout: "设置归档会话被自动删除前的保留时间(单位:秒)。" }, { $desc: "模型选项", defaultEmbeddings: "设置默认使用的嵌入模型。", defaultVectorStore: "设置默认使用的向量数据库。" }, { $desc: "会话路由默认配置", defaultGroupRouteMode: { $desc: "设置群聊场景下默认的会话路由模式,决定群成员是共享同一路由还是各自拥有独立路由,也会影响预设分流。", $inner: ["群共享会话", "成员独立会话"] }, defaultChatMode: "设置默认的聊天模式。", defaultModel: "设置默认使用的聊天模型。", defaultPreset: "设置默认使用的聊天预设。", enablePresetKeywordTrigger: "是否允许通过消息开头的预设关键词切换预设分流。" }, { $desc: "杂项", errorTemplate: "设置错误提示消息的模板(此设置在未来版本中可能会有变更)。", voiceSpeakId: "设置使用 vits 服务时的默认发音人 ID。", isLog: "是否启用调试模式。" }, { isProxy: { $desc: "是否启用代理。启用后,ChatLuna 全家桶插件的网络请求将使用此代理。", $inner: [true] }, proxyAddress: "网络请求的代理地址。填写后,ChatLuna 相关插件的网络服务将使用此代理地址。若为空,将尝试使用 Koishi 全局配置中的代理设置。" }] };
|
|
12
12
|
}
|
|
13
13
|
});
|
|
14
14
|
|
|
15
15
|
// src/locales/en-US.schema.yml
|
|
16
16
|
var require_en_US_schema = __commonJS({
|
|
17
17
|
"src/locales/en-US.schema.yml"(exports, module) {
|
|
18
|
-
module.exports = { $inner: [{ $desc: "Bot Configuration", botNames: "Set the bot's name. (Only the first name is the actual bot name; other names are only used to trigger conversations.)", isNickname: "Allow matching bot nickname at the beginning of a message to trigger a conversation.", isNickNameWithContent: "Allow matching bot nickname anywhere in the message content to trigger a conversation." }, { $desc: "Conversation Behavior", allowPrivate: "Enable private chat conversations.", allowAtReply: "Enable @mention triggering.", allowQuoteReply: "Enable quote triggering.", privateChatWithoutCommand: "Enable direct conversation in private chats without commands.", allowConversationTriggerPrefix: "Enable conversation title prefix triggering. Note: May impact performance significantly. Recommended for use with filters in specific groups only.", randomReplyFrequency: "Set random reply frequency (0-100, where 0 means never and 100 means always).", includeQuoteReply: "Include quoted message content in requests sent to the model.", attachForwardMsgIdToContext: 'Attach forward message record IDs to context. When enabled, a "[聊天记录]" marker message will be appended if forward records are detected.' }, { isForwardMsg: "Send bot replies as forwarded messages.", forwardMsgMinLength: "Set minimum length of forwarded messages (characters)." }, { isReplyWithAt: "Quote the original message when the bot replies.", replyQuoteThreshold: "Minimum response time required to quote the original message. Set to 0 to always apply. When greater than 0, the original message will only be quoted if the response time exceeds this threshold." }, { $desc: "Response Options", sendThinkingMessage: "Send waiting message during processing.", sendThinkingMessageTimeout: "Set timeout (ms) for waiting message dispatch.", thinkingMessage: "Customize waiting message content.", msgCooldown: "Set global message cooldown (seconds) to limit adapter calls.", messageQueue: "Enable message queue. When enabled, if multiple messages are sent and the model has not responded to the initial message, the messages will be cached and merged into one message, and will be sent after waiting for the model response.", messageQueueDelay: "Set message queue delay time (seconds). Set to 0 to disable delay. When delay is enabled, the system will wait for the specified time before sending messages to the model. If there are unprocessed messages during this period, they will be cached and merged into multiple messages to send to the model.", agentTaskAutoWakeup: "Automatically wake up the conversation when a background agent task finishes. Disable to return to manual status checks.", showThoughtMessage: "Display thinking message in plugin mode or reasoner model." }, { $desc: "Message Rendering", outputMode: { $desc: "Select message reply rendering mode." }, splitMessage: { $desc: "Split outgoing messages. Applies to both streaming and non-streaming replies; voice and mixed-voice renderers send as soon as a split point is reached.", $inner: ["Do not split", "Split by punctuation", "Split by paragraph"] }, censor: "Enable text moderation (requires censor service).", rawOnCensor: "Whether to send the raw message to the model when the Post Handler is triggered.", streamResponse: "Enable stream response. Initiates message sending during reply generation. Note: Disables rendering output mode and incompatible with plugin mode." }, { $desc: "Blacklist Management", blackList: "Configure blacklist. Use cautiously to avoid unintended blocking. The number 1 indicates enabled blacklist. Set to zero value to unenable blacklist." }, { $desc: "History Management", infiniteContext: "Enable automatic Infinite Context compression when history nears the model limit. Preserves critical topics and instructions while discarding noise.", infiniteContextThreshold: "Set the threshold (percentage) for triggering Infinite Context compression. Compression will be triggered when the token count of conversation history reaches this percentage of the model's context limit.", autoArchive: "Enable automatic archiving of inactive conversations instead of keeping legacy room state alive.", autoArchiveTimeout: "Set inactivity threshold for conversation archiving in seconds.", autoPurgeArchive: "Enable automatic deletion of archived conversations after the purge timeout.", autoPurgeArchiveTimeout: "Set how long archived conversations are retained before automatic purge in seconds." }, { $desc: "Model Configuration", defaultEmbeddings: "Set default embedding model.", defaultVectorStore: "Set default vector database." }, { $desc: "Conversation Routing Defaults", defaultGroupRouteMode: { $desc: "Set the default conversation route mode for group chats. This controls whether group members share one conversation route or get personal routes, including preset-lane routes.", $inner: ["Shared group conversation", "Personal conversation per member"] }, defaultChatMode: "Set default chat mode.", defaultModel: "Set default chat model.", defaultPreset: "Set default chat preset." }, { $desc: "Miscellaneous", errorTemplate: "Set error prompt message template (subject to change).", voiceSpeakId: "Set default speaker ID for vits service.", isLog: "Enable debug mode." }, { isProxy: { $desc: "Enable proxy for ChatLuna family plugin network requests.", $inner: [true] }, proxyAddress: "Set proxy address for network requests. Falls back to Koishi global proxy settings if cleared." }] };
|
|
18
|
+
module.exports = { $inner: [{ $desc: "Bot Configuration", botNames: "Set the bot's name. (Only the first name is the actual bot name; other names are only used to trigger conversations.)", isNickname: "Allow matching bot nickname at the beginning of a message to trigger a conversation.", isNickNameWithContent: "Allow matching bot nickname anywhere in the message content to trigger a conversation." }, { $desc: "Conversation Behavior", allowPrivate: "Enable private chat conversations.", allowAtReply: "Enable @mention triggering.", allowQuoteReply: "Enable quote triggering.", privateChatWithoutCommand: "Enable direct conversation in private chats without commands.", allowConversationTriggerPrefix: "Enable conversation title prefix triggering. Note: May impact performance significantly. Recommended for use with filters in specific groups only.", randomReplyFrequency: "Set random reply frequency (0-100, where 0 means never and 100 means always).", includeQuoteReply: "Include quoted message content in requests sent to the model.", attachForwardMsgIdToContext: 'Attach forward message record IDs to context. When enabled, a "[聊天记录]" marker message will be appended if forward records are detected.' }, { isForwardMsg: "Send bot replies as forwarded messages.", forwardMsgMinLength: "Set minimum length of forwarded messages (characters)." }, { isReplyWithAt: "Quote the original message when the bot replies.", replyQuoteThreshold: "Minimum response time required to quote the original message. Set to 0 to always apply. When greater than 0, the original message will only be quoted if the response time exceeds this threshold." }, { $desc: "Response Options", sendThinkingMessage: "Send waiting message during processing.", sendThinkingMessageTimeout: "Set timeout (ms) for waiting message dispatch.", thinkingMessage: "Customize waiting message content.", msgCooldown: "Set global message cooldown (seconds) to limit adapter calls.", messageQueue: "Enable message queue. When enabled, if multiple messages are sent and the model has not responded to the initial message, the messages will be cached and merged into one message, and will be sent after waiting for the model response.", messageQueueDelay: "Set message queue delay time (seconds). Set to 0 to disable delay. When delay is enabled, the system will wait for the specified time before sending messages to the model. If there are unprocessed messages during this period, they will be cached and merged into multiple messages to send to the model.", agentTaskAutoWakeup: "Automatically wake up the conversation when a background agent task finishes. Disable to return to manual status checks.", showThoughtMessage: "Display thinking message in plugin mode or reasoner model." }, { $desc: "Message Rendering", outputMode: { $desc: "Select message reply rendering mode." }, splitMessage: { $desc: "Split outgoing messages. Applies to both streaming and non-streaming replies; voice and mixed-voice renderers send as soon as a split point is reached.", $inner: ["Do not split", "Split by punctuation", "Split by paragraph"] }, censor: "Enable text moderation (requires censor service).", rawOnCensor: "Whether to send the raw message to the model when the Post Handler is triggered.", streamResponse: "Enable stream response. Initiates message sending during reply generation. Note: Disables rendering output mode and incompatible with plugin mode." }, { $desc: "Blacklist Management", blackList: "Configure blacklist. Use cautiously to avoid unintended blocking. The number 1 indicates enabled blacklist. Set to zero value to unenable blacklist." }, { $desc: "History Management", infiniteContext: "Enable automatic Infinite Context compression when history nears the model limit. Preserves critical topics and instructions while discarding noise.", infiniteContextThreshold: "Set the threshold (percentage) for triggering Infinite Context compression. Compression will be triggered when the token count of conversation history reaches this percentage of the model's context limit.", autoArchive: "Enable automatic archiving of inactive conversations instead of keeping legacy room state alive.", autoArchiveTimeout: "Set inactivity threshold for conversation archiving in seconds.", autoPurgeArchive: "Enable automatic deletion of archived conversations after the purge timeout.", autoPurgeArchiveTimeout: "Set how long archived conversations are retained before automatic purge in seconds." }, { $desc: "Model Configuration", defaultEmbeddings: "Set default embedding model.", defaultVectorStore: "Set default vector database." }, { $desc: "Conversation Routing Defaults", defaultGroupRouteMode: { $desc: "Set the default conversation route mode for group chats. This controls whether group members share one conversation route or get personal routes, including preset-lane routes.", $inner: ["Shared group conversation", "Personal conversation per member"] }, defaultChatMode: "Set default chat mode.", defaultModel: "Set default chat model.", defaultPreset: "Set default chat preset.", enablePresetKeywordTrigger: "Allow switching preset lanes via keywords at the start of a message." }, { $desc: "Miscellaneous", errorTemplate: "Set error prompt message template (subject to change).", voiceSpeakId: "Set default speaker ID for vits service.", isLog: "Enable debug mode." }, { isProxy: { $desc: "Enable proxy for ChatLuna family plugin network requests.", $inner: [true] }, proxyAddress: "Set proxy address for network requests. Falls back to Koishi global proxy settings if cleared." }] };
|
|
19
19
|
}
|
|
20
20
|
});
|
|
21
21
|
|
|
@@ -2942,9 +2942,7 @@ function apply12(ctx, config, chain) {
|
|
|
2942
2942
|
}
|
|
2943
2943
|
if (parsePresetLaneInput(
|
|
2944
2944
|
content,
|
|
2945
|
-
ctx.chatluna.preset.
|
|
2946
|
-
(entry) => entry.split(",").map((item) => item.trim())
|
|
2947
|
-
)
|
|
2945
|
+
ctx.chatluna.preset.getKeywordTriggerAliases().value
|
|
2948
2946
|
) != null) {
|
|
2949
2947
|
return 2 /* CONTINUE */;
|
|
2950
2948
|
}
|
|
@@ -3315,32 +3313,10 @@ function apply17(ctx, config, chain) {
|
|
|
3315
3313
|
tryStartHeadTurn(conversationId, queue);
|
|
3316
3314
|
return await statusPromise;
|
|
3317
3315
|
}).after("transform_chat_message").before("lifecycle-handle_command");
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
}
|
|
3323
|
-
const current = conversation.turns.shift();
|
|
3324
|
-
conversation.inFlight = false;
|
|
3325
|
-
if (current?.timeout) {
|
|
3326
|
-
current.timeout();
|
|
3327
|
-
}
|
|
3328
|
-
if (current?.starter) {
|
|
3329
|
-
current.starter.resolve(1 /* STOP */);
|
|
3330
|
-
current.starter = void 0;
|
|
3331
|
-
}
|
|
3332
|
-
if (conversation.turns.length === 0) {
|
|
3333
|
-
queues.delete(conversationId);
|
|
3334
|
-
return;
|
|
3335
|
-
}
|
|
3336
|
-
tryStartHeadTurn(conversationId, conversation);
|
|
3337
|
-
if (current) {
|
|
3338
|
-
logger9.debug(
|
|
3339
|
-
`Completing turn for ${conversationId}, remaining: ${conversation.turns.length}`
|
|
3340
|
-
);
|
|
3341
|
-
}
|
|
3342
|
-
}, "completeTurn");
|
|
3343
|
-
ctx.on("chatluna/after-chat", completeTurn);
|
|
3316
|
+
ctx.on(
|
|
3317
|
+
"chatluna/after-chat",
|
|
3318
|
+
(conversationId) => completeTurn(conversationId)
|
|
3319
|
+
);
|
|
3344
3320
|
ctx.on(
|
|
3345
3321
|
"chatluna/after-chat-error",
|
|
3346
3322
|
(_error, conversationId) => completeTurn(conversationId)
|
|
@@ -3389,6 +3365,32 @@ function apply17(ctx, config, chain) {
|
|
|
3389
3365
|
);
|
|
3390
3366
|
}
|
|
3391
3367
|
__name(apply17, "apply");
|
|
3368
|
+
async function completeTurn(conversationId, expected) {
|
|
3369
|
+
const conversation = queues.get(conversationId);
|
|
3370
|
+
if (!conversation || expected != null && conversation.turns[0] !== expected) {
|
|
3371
|
+
return;
|
|
3372
|
+
}
|
|
3373
|
+
const current = conversation.turns.shift();
|
|
3374
|
+
conversation.inFlight = false;
|
|
3375
|
+
if (current?.timeout) {
|
|
3376
|
+
current.timeout();
|
|
3377
|
+
}
|
|
3378
|
+
if (current?.starter) {
|
|
3379
|
+
current.starter.resolve(1 /* STOP */);
|
|
3380
|
+
current.starter = void 0;
|
|
3381
|
+
}
|
|
3382
|
+
if (conversation.turns.length === 0) {
|
|
3383
|
+
queues.delete(conversationId);
|
|
3384
|
+
return;
|
|
3385
|
+
}
|
|
3386
|
+
tryStartHeadTurn(conversationId, conversation);
|
|
3387
|
+
if (current) {
|
|
3388
|
+
logger9.debug(
|
|
3389
|
+
`Completing turn for ${conversationId}, remaining: ${conversation.turns.length}`
|
|
3390
|
+
);
|
|
3391
|
+
}
|
|
3392
|
+
}
|
|
3393
|
+
__name(completeTurn, "completeTurn");
|
|
3392
3394
|
function awaitTurnStart(turn, context) {
|
|
3393
3395
|
if (turn.starter) {
|
|
3394
3396
|
turn.starter.resolve(1 /* STOP */);
|
|
@@ -3454,6 +3456,7 @@ function startHeadTurn(conversationId, conversation, head) {
|
|
|
3454
3456
|
head.starter = void 0;
|
|
3455
3457
|
conversation.inFlight = true;
|
|
3456
3458
|
head.state = "processing";
|
|
3459
|
+
starter.context.options.completeMessageTurn = () => completeTurn(conversationId, head);
|
|
3457
3460
|
starter.context.options.inputMessage = mergeMessages(
|
|
3458
3461
|
head.messages.sort((a, b) => a.timestamp - b.timestamp).map((msg) => msg.message)
|
|
3459
3462
|
);
|
|
@@ -3569,9 +3572,7 @@ function apply18(ctx, config, chain) {
|
|
|
3569
3572
|
const text = h4.select(message, "text").join("");
|
|
3570
3573
|
const parsed = parsePresetLaneInput(
|
|
3571
3574
|
text,
|
|
3572
|
-
ctx.chatluna.preset.
|
|
3573
|
-
(entry) => entry.split(",").map((item) => item.trim())
|
|
3574
|
-
)
|
|
3575
|
+
ctx.chatluna.preset.getKeywordTriggerAliases().value
|
|
3575
3576
|
);
|
|
3576
3577
|
if (parsed?.preset != null) {
|
|
3577
3578
|
const preset = ctx.chatluna.preset.getPreset(
|
|
@@ -4415,6 +4416,7 @@ __name(apply22, "apply");
|
|
|
4415
4416
|
|
|
4416
4417
|
// src/middlewares/chat/thinking_message_send.ts
|
|
4417
4418
|
import { createLogger as createLogger3 } from "koishi-plugin-chatluna/utils/logger";
|
|
4419
|
+
import { withResolver } from "koishi-plugin-chatluna/utils/promise";
|
|
4418
4420
|
var logger11;
|
|
4419
4421
|
function apply23(ctx, config, chain) {
|
|
4420
4422
|
logger11 = createLogger3(ctx);
|
|
@@ -4422,13 +4424,14 @@ function apply23(ctx, config, chain) {
|
|
|
4422
4424
|
if (!config.sendThinkingMessage || context.command?.length > 0) {
|
|
4423
4425
|
return 0 /* SKIPPED */;
|
|
4424
4426
|
}
|
|
4425
|
-
const
|
|
4427
|
+
const queue = withResolver();
|
|
4428
|
+
const thinkingTimeoutObject = {
|
|
4429
|
+
queueCount: queue.promise,
|
|
4430
|
+
setQueueCount: queue.resolve
|
|
4431
|
+
};
|
|
4426
4432
|
context.options.thinkingTimeoutObject = thinkingTimeoutObject;
|
|
4427
4433
|
thinkingTimeoutObject.timeout = setTimeout(async () => {
|
|
4428
|
-
const queueCount = await
|
|
4429
|
-
thinkingTimeoutObject,
|
|
4430
|
-
context.options
|
|
4431
|
-
);
|
|
4434
|
+
const queueCount = await thinkingTimeoutObject.queueCount;
|
|
4432
4435
|
if (thinkingTimeoutObject.timeout == null || queueCount < 1) {
|
|
4433
4436
|
return;
|
|
4434
4437
|
}
|
|
@@ -4461,18 +4464,6 @@ function apply23(ctx, config, chain) {
|
|
|
4461
4464
|
}).before("lifecycle-prepare");
|
|
4462
4465
|
}
|
|
4463
4466
|
__name(apply23, "apply");
|
|
4464
|
-
async function getQueueCount(obj, options) {
|
|
4465
|
-
await new Promise((resolve, reject) => {
|
|
4466
|
-
const timer = setInterval(() => {
|
|
4467
|
-
if (obj.timeout != null && options.queueCount != null) {
|
|
4468
|
-
clearInterval(timer);
|
|
4469
|
-
resolve(void 0);
|
|
4470
|
-
}
|
|
4471
|
-
});
|
|
4472
|
-
});
|
|
4473
|
-
return options.queueCount;
|
|
4474
|
-
}
|
|
4475
|
-
__name(getQueueCount, "getQueueCount");
|
|
4476
4467
|
|
|
4477
4468
|
// src/middlewares/conversation/request_conversation.ts
|
|
4478
4469
|
import {
|
|
@@ -4613,7 +4604,7 @@ function createChatCallbacks(context, config, stream, captureOnly) {
|
|
|
4613
4604
|
await stream.write({ type: "content", chunk });
|
|
4614
4605
|
},
|
|
4615
4606
|
"llm-queue-waiting": /* @__PURE__ */ __name(async (count) => {
|
|
4616
|
-
context.options.
|
|
4607
|
+
context.options.thinkingTimeoutObject?.setQueueCount(count);
|
|
4617
4608
|
}, "llm-queue-waiting"),
|
|
4618
4609
|
"llm-usage": /* @__PURE__ */ __name(async (usage2) => {
|
|
4619
4610
|
if (context.options.invocation != null) {
|
|
@@ -6752,7 +6743,8 @@ var Config2 = Schema.intersect([
|
|
|
6752
6743
|
]).default("shared"),
|
|
6753
6744
|
defaultChatMode: Schema.dynamic("chat-mode").default("plugin"),
|
|
6754
6745
|
defaultModel: Schema.dynamic("model").default("无"),
|
|
6755
|
-
defaultPreset: Schema.dynamic("preset").default("sydney")
|
|
6746
|
+
defaultPreset: Schema.dynamic("preset").default("sydney"),
|
|
6747
|
+
enablePresetKeywordTrigger: Schema.boolean().default(true)
|
|
6756
6748
|
}),
|
|
6757
6749
|
Schema.object({
|
|
6758
6750
|
voiceSpeakId: Schema.number().default(0),
|
|
@@ -19,37 +19,37 @@ declare class AgentTaskTool extends StructuredTool {
|
|
|
19
19
|
background: z.ZodOptional<z.ZodBoolean>;
|
|
20
20
|
message: z.ZodOptional<z.ZodString>;
|
|
21
21
|
}, "strip", z.ZodTypeAny, {
|
|
22
|
-
message?: string;
|
|
23
22
|
id?: string;
|
|
23
|
+
message?: string;
|
|
24
|
+
action?: "status" | "stop" | "list" | "message" | "run" | "list_all";
|
|
24
25
|
prompt?: string;
|
|
25
|
-
action?: "message" | "list" | "run" | "status" | "stop" | "list_all";
|
|
26
26
|
agent?: string;
|
|
27
27
|
background?: boolean;
|
|
28
28
|
goal?: string;
|
|
29
29
|
reason?: string;
|
|
30
30
|
}, {
|
|
31
|
-
message?: string;
|
|
32
31
|
id?: string;
|
|
32
|
+
message?: string;
|
|
33
|
+
action?: "status" | "stop" | "list" | "message" | "run" | "list_all";
|
|
33
34
|
prompt?: string;
|
|
34
|
-
action?: "message" | "list" | "run" | "status" | "stop" | "list_all";
|
|
35
35
|
agent?: string;
|
|
36
36
|
background?: boolean;
|
|
37
37
|
goal?: string;
|
|
38
38
|
reason?: string;
|
|
39
39
|
}>, {
|
|
40
|
-
message?: string;
|
|
41
40
|
id?: string;
|
|
41
|
+
message?: string;
|
|
42
|
+
action?: "status" | "stop" | "list" | "message" | "run" | "list_all";
|
|
42
43
|
prompt?: string;
|
|
43
|
-
action?: "message" | "list" | "run" | "status" | "stop" | "list_all";
|
|
44
44
|
agent?: string;
|
|
45
45
|
background?: boolean;
|
|
46
46
|
goal?: string;
|
|
47
47
|
reason?: string;
|
|
48
48
|
}, {
|
|
49
|
-
message?: string;
|
|
50
49
|
id?: string;
|
|
50
|
+
message?: string;
|
|
51
|
+
action?: "status" | "stop" | "list" | "message" | "run" | "list_all";
|
|
51
52
|
prompt?: string;
|
|
52
|
-
action?: "message" | "list" | "run" | "status" | "stop" | "list_all";
|
|
53
53
|
agent?: string;
|
|
54
54
|
background?: boolean;
|
|
55
55
|
goal?: string;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Embeddings } from '@langchain/core/embeddings';
|
|
1
2
|
import { AIMessage } from '@langchain/core/messages';
|
|
2
3
|
import { ComputedRef } from '@vue/reactivity';
|
|
3
4
|
import { ChatLunaChatModel } from 'koishi-plugin-chatluna/llm-core/platform/model';
|
|
@@ -5,7 +6,7 @@ import { PlatformService } from 'koishi-plugin-chatluna/llm-core/platform/servic
|
|
|
5
6
|
import { ModelInfo } from 'koishi-plugin-chatluna/llm-core/platform/types';
|
|
6
7
|
import type { ChatLunaService } from '../../services/chat';
|
|
7
8
|
export declare function createDisplayResponse(responseMessage: AIMessage): AIMessage;
|
|
8
|
-
export declare function initEmbeddings(service: PlatformService, model: string | undefined): Promise<ComputedRef<
|
|
9
|
+
export declare function initEmbeddings(service: PlatformService, model: string | undefined): Promise<ComputedRef<Embeddings<number[]>>>;
|
|
9
10
|
export declare function initModel(chatluna: ChatLunaService, llmPlatform: string, llmModelName: string): Promise<[
|
|
10
11
|
ComputedRef<ChatLunaChatModel>,
|
|
11
12
|
ComputedRef<ModelInfo | undefined>
|
|
@@ -38,6 +38,7 @@ export interface RawPreset {
|
|
|
38
38
|
longMemoryNewQuestionPrompt?: string;
|
|
39
39
|
postHandler?: PostHandler;
|
|
40
40
|
reActInstruction?: string;
|
|
41
|
+
enableKeywordTrigger?: boolean;
|
|
41
42
|
};
|
|
42
43
|
}
|
|
43
44
|
export interface RoleBook {
|
|
@@ -79,6 +80,7 @@ export interface PresetTemplate {
|
|
|
79
80
|
longMemoryNewQuestionPrompt?: string;
|
|
80
81
|
postHandler?: PostHandler;
|
|
81
82
|
reActInstruction?: string;
|
|
83
|
+
enableKeywordTrigger?: boolean;
|
|
82
84
|
};
|
|
83
85
|
}
|
|
84
86
|
export interface KnowledgeConfig {
|
|
@@ -3,6 +3,8 @@ import { Config } from '../../config';
|
|
|
3
3
|
import { ChatChain } from '../../chains/chain';
|
|
4
4
|
export declare function apply(ctx: Context, config: Config, chain: ChatChain): void;
|
|
5
5
|
export interface ThinkingTimeoutObject {
|
|
6
|
+
queueCount: Promise<number>;
|
|
7
|
+
setQueueCount: (count: number) => void;
|
|
6
8
|
timeout?: NodeJS.Timeout;
|
|
7
9
|
recallFunc?: () => PromiseLike<void>;
|
|
8
10
|
autoRecallTimeout?: NodeJS.Timeout;
|
package/lib/preset.cjs
CHANGED
|
@@ -226,6 +226,20 @@ var PresetService = class {
|
|
|
226
226
|
return this._presets.value[0];
|
|
227
227
|
});
|
|
228
228
|
}
|
|
229
|
+
getKeywordTriggerAliases() {
|
|
230
|
+
return (0, import_reactivity.computed)(() => {
|
|
231
|
+
if (!this.config.enablePresetKeywordTrigger) {
|
|
232
|
+
return [];
|
|
233
|
+
}
|
|
234
|
+
return this._presets.value.filter(
|
|
235
|
+
(preset) => preset.config.enableKeywordTrigger !== false
|
|
236
|
+
).flatMap(
|
|
237
|
+
(preset) => preset.triggerKeyword.flatMap(
|
|
238
|
+
(keyword) => keyword.split(",").map((item) => item.trim()).filter((item) => item.length > 0)
|
|
239
|
+
)
|
|
240
|
+
);
|
|
241
|
+
});
|
|
242
|
+
}
|
|
229
243
|
getAllPreset(concatKeyword = true) {
|
|
230
244
|
return (0, import_reactivity.computed)(
|
|
231
245
|
() => this._presets.value.map(
|
package/lib/preset.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export declare class PresetService {
|
|
|
18
18
|
init(): Promise<void>;
|
|
19
19
|
getPreset(triggerKeyword: string, throwError?: boolean): ComputedRef<PresetTemplate>;
|
|
20
20
|
getDefaultPreset(): ComputedRef<PresetTemplate>;
|
|
21
|
+
getKeywordTriggerAliases(): ComputedRef<string[]>;
|
|
21
22
|
getAllPreset(concatKeyword?: boolean): ComputedRef<string[]>;
|
|
22
23
|
addPreset(preset: PresetTemplate): void;
|
|
23
24
|
private _updateSchema;
|
package/lib/preset.mjs
CHANGED
|
@@ -199,6 +199,20 @@ var PresetService = class {
|
|
|
199
199
|
return this._presets.value[0];
|
|
200
200
|
});
|
|
201
201
|
}
|
|
202
|
+
getKeywordTriggerAliases() {
|
|
203
|
+
return computed(() => {
|
|
204
|
+
if (!this.config.enablePresetKeywordTrigger) {
|
|
205
|
+
return [];
|
|
206
|
+
}
|
|
207
|
+
return this._presets.value.filter(
|
|
208
|
+
(preset) => preset.config.enableKeywordTrigger !== false
|
|
209
|
+
).flatMap(
|
|
210
|
+
(preset) => preset.triggerKeyword.flatMap(
|
|
211
|
+
(keyword) => keyword.split(",").map((item) => item.trim()).filter((item) => item.length > 0)
|
|
212
|
+
)
|
|
213
|
+
);
|
|
214
|
+
});
|
|
215
|
+
}
|
|
202
216
|
getAllPreset(concatKeyword = true) {
|
|
203
217
|
return computed(
|
|
204
218
|
() => this._presets.value.map(
|
package/lib/services/chat.cjs
CHANGED
|
@@ -255,6 +255,7 @@ var ChatChain = class {
|
|
|
255
255
|
const timeoutObj = context.options.thinkingTimeoutObject;
|
|
256
256
|
clearTimeout(timeoutObj.timeout);
|
|
257
257
|
timeoutObj.autoRecallTimeout && clearTimeout(timeoutObj.autoRecallTimeout);
|
|
258
|
+
timeoutObj.setQueueCount(0);
|
|
258
259
|
timeoutObj.recallFunc && await timeoutObj.recallFunc();
|
|
259
260
|
timeoutObj.timeout = null;
|
|
260
261
|
context.options.thinkingTimeoutObject = void 0;
|
|
@@ -275,9 +276,12 @@ var ChatChain = class {
|
|
|
275
276
|
)
|
|
276
277
|
};
|
|
277
278
|
context.recallThinkingMessage = this._createRecallThinkingMessage(context);
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
279
|
+
try {
|
|
280
|
+
return await this._runMiddleware(session, context);
|
|
281
|
+
} finally {
|
|
282
|
+
await context.options.completeMessageTurn?.();
|
|
283
|
+
await context.recallThinkingMessage();
|
|
284
|
+
}
|
|
281
285
|
}
|
|
282
286
|
async receiveCommand(session, command, options = {}, ctx = this.ctx) {
|
|
283
287
|
return (await this.runCommand(session, command, options, ctx)).ok;
|
|
@@ -308,9 +312,13 @@ var ChatChain = class {
|
|
|
308
312
|
}
|
|
309
313
|
};
|
|
310
314
|
context.recallThinkingMessage = this._createRecallThinkingMessage(context);
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
315
|
+
try {
|
|
316
|
+
const ok = await this._runMiddleware(session, context);
|
|
317
|
+
return { ok, context };
|
|
318
|
+
} finally {
|
|
319
|
+
await context.options.completeMessageTurn?.();
|
|
320
|
+
await context.recallThinkingMessage();
|
|
321
|
+
}
|
|
314
322
|
}
|
|
315
323
|
middleware(name, middleware, ctx = this.ctx) {
|
|
316
324
|
const result = new ChainMiddleware(name, middleware, this._graph);
|
|
@@ -3451,7 +3459,8 @@ var ConversationRuntime = class {
|
|
|
3451
3459
|
message,
|
|
3452
3460
|
options
|
|
3453
3461
|
),
|
|
3454
|
-
options.signal
|
|
3462
|
+
options.signal,
|
|
3463
|
+
options.event?.["llm-queue-waiting"]
|
|
3455
3464
|
);
|
|
3456
3465
|
}
|
|
3457
3466
|
async internalChat(config, session, conversation, message, options) {
|
|
@@ -3603,7 +3612,7 @@ ${reasoning}`
|
|
|
3603
3612
|
await this.conversationQueue.remove(conversation.id, requestId);
|
|
3604
3613
|
}
|
|
3605
3614
|
}
|
|
3606
|
-
async withConversationAndPlatformLock(conversation, callback, signal) {
|
|
3615
|
+
async withConversationAndPlatformLock(conversation, callback, signal, onQueueWaiting) {
|
|
3607
3616
|
const requestId = (0, import_crypto3.randomUUID)();
|
|
3608
3617
|
const modelRequestId = (0, import_crypto3.randomUUID)();
|
|
3609
3618
|
const platform = requirePlatform(conversation);
|
|
@@ -3624,6 +3633,13 @@ ${reasoning}`
|
|
|
3624
3633
|
this.conversationQueue.add(conversation.id, requestId),
|
|
3625
3634
|
this.modelQueue.add(platform, modelRequestId)
|
|
3626
3635
|
]);
|
|
3636
|
+
if (onQueueWaiting != null) {
|
|
3637
|
+
const sizes = await Promise.all([
|
|
3638
|
+
this.conversationQueue.getQueueLength(conversation.id),
|
|
3639
|
+
this.modelQueue.getQueueLength(platform)
|
|
3640
|
+
]);
|
|
3641
|
+
await onQueueWaiting(Math.max(...sizes));
|
|
3642
|
+
}
|
|
3627
3643
|
const waiting = Promise.all([
|
|
3628
3644
|
this.conversationQueue.wait(
|
|
3629
3645
|
conversation.id,
|
package/lib/services/chat.mjs
CHANGED
|
@@ -251,6 +251,7 @@ var ChatChain = class {
|
|
|
251
251
|
const timeoutObj = context.options.thinkingTimeoutObject;
|
|
252
252
|
clearTimeout(timeoutObj.timeout);
|
|
253
253
|
timeoutObj.autoRecallTimeout && clearTimeout(timeoutObj.autoRecallTimeout);
|
|
254
|
+
timeoutObj.setQueueCount(0);
|
|
254
255
|
timeoutObj.recallFunc && await timeoutObj.recallFunc();
|
|
255
256
|
timeoutObj.timeout = null;
|
|
256
257
|
context.options.thinkingTimeoutObject = void 0;
|
|
@@ -271,9 +272,12 @@ var ChatChain = class {
|
|
|
271
272
|
)
|
|
272
273
|
};
|
|
273
274
|
context.recallThinkingMessage = this._createRecallThinkingMessage(context);
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
275
|
+
try {
|
|
276
|
+
return await this._runMiddleware(session, context);
|
|
277
|
+
} finally {
|
|
278
|
+
await context.options.completeMessageTurn?.();
|
|
279
|
+
await context.recallThinkingMessage();
|
|
280
|
+
}
|
|
277
281
|
}
|
|
278
282
|
async receiveCommand(session, command, options = {}, ctx = this.ctx) {
|
|
279
283
|
return (await this.runCommand(session, command, options, ctx)).ok;
|
|
@@ -304,9 +308,13 @@ var ChatChain = class {
|
|
|
304
308
|
}
|
|
305
309
|
};
|
|
306
310
|
context.recallThinkingMessage = this._createRecallThinkingMessage(context);
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
311
|
+
try {
|
|
312
|
+
const ok = await this._runMiddleware(session, context);
|
|
313
|
+
return { ok, context };
|
|
314
|
+
} finally {
|
|
315
|
+
await context.options.completeMessageTurn?.();
|
|
316
|
+
await context.recallThinkingMessage();
|
|
317
|
+
}
|
|
310
318
|
}
|
|
311
319
|
middleware(name, middleware, ctx = this.ctx) {
|
|
312
320
|
const result = new ChainMiddleware(name, middleware, this._graph);
|
|
@@ -3485,7 +3493,8 @@ var ConversationRuntime = class {
|
|
|
3485
3493
|
message,
|
|
3486
3494
|
options
|
|
3487
3495
|
),
|
|
3488
|
-
options.signal
|
|
3496
|
+
options.signal,
|
|
3497
|
+
options.event?.["llm-queue-waiting"]
|
|
3489
3498
|
);
|
|
3490
3499
|
}
|
|
3491
3500
|
async internalChat(config, session, conversation, message, options) {
|
|
@@ -3637,7 +3646,7 @@ ${reasoning}`
|
|
|
3637
3646
|
await this.conversationQueue.remove(conversation.id, requestId);
|
|
3638
3647
|
}
|
|
3639
3648
|
}
|
|
3640
|
-
async withConversationAndPlatformLock(conversation, callback, signal) {
|
|
3649
|
+
async withConversationAndPlatformLock(conversation, callback, signal, onQueueWaiting) {
|
|
3641
3650
|
const requestId = randomUUID2();
|
|
3642
3651
|
const modelRequestId = randomUUID2();
|
|
3643
3652
|
const platform = requirePlatform(conversation);
|
|
@@ -3658,6 +3667,13 @@ ${reasoning}`
|
|
|
3658
3667
|
this.conversationQueue.add(conversation.id, requestId),
|
|
3659
3668
|
this.modelQueue.add(platform, modelRequestId)
|
|
3660
3669
|
]);
|
|
3670
|
+
if (onQueueWaiting != null) {
|
|
3671
|
+
const sizes = await Promise.all([
|
|
3672
|
+
this.conversationQueue.getQueueLength(conversation.id),
|
|
3673
|
+
this.modelQueue.getQueueLength(platform)
|
|
3674
|
+
]);
|
|
3675
|
+
await onQueueWaiting(Math.max(...sizes));
|
|
3676
|
+
}
|
|
3661
3677
|
const waiting = Promise.all([
|
|
3662
3678
|
this.conversationQueue.wait(
|
|
3663
3679
|
conversation.id,
|
|
@@ -36,7 +36,7 @@ export declare class ConversationRuntime {
|
|
|
36
36
|
getCachedConversations(): [string, RuntimeConversationEntry][];
|
|
37
37
|
withConversationLock<T>(conversationId: string, callback: () => Promise<T>): Promise<T>;
|
|
38
38
|
withConversationSync<T>(conversation: ConversationRecord, callback: () => Promise<T>): Promise<T>;
|
|
39
|
-
withConversationAndPlatformLock<T>(conversation: ConversationRecord, callback: (config: ClientConfig) => Promise<T>, signal?: AbortSignal): Promise<T>;
|
|
39
|
+
withConversationAndPlatformLock<T>(conversation: ConversationRecord, callback: (config: ClientConfig) => Promise<T>, signal?: AbortSignal, onQueueWaiting?: ChatEvents['llm-queue-waiting']): Promise<T>;
|
|
40
40
|
registerRequest(conversationId: string, requestId: string, chatMode: string, platform: string, abortController: AbortController, session?: Session): ActiveRequest;
|
|
41
41
|
completeRequest(conversationId: string, requestId: string): void;
|
|
42
42
|
stopRequest(requestId: string): boolean;
|