koishi-plugin-chatluna 1.4.2 → 1.4.4
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/index.cjs +187 -229
- package/lib/index.mjs +44 -89
- package/lib/llm-core/agent/sub-agent/tool.d.ts +8 -8
- package/lib/llm-core/chat/helper.d.ts +1 -2
- package/lib/render/stream.d.ts +0 -1
- package/lib/services/chat.cjs +33 -75
- package/lib/services/chat.mjs +33 -75
- package/lib/services/message_transform.d.ts +0 -1
- package/lib/utils/koishi.cjs +0 -33
- package/lib/utils/koishi.d.ts +0 -3
- package/lib/utils/koishi.mjs +0 -30
- package/package.json +1 -1
package/lib/index.cjs
CHANGED
|
@@ -78,9 +78,9 @@ __export(index_exports, {
|
|
|
78
78
|
usage: () => usage
|
|
79
79
|
});
|
|
80
80
|
module.exports = __toCommonJS(index_exports);
|
|
81
|
-
var
|
|
81
|
+
var import_koishi26 = require("koishi");
|
|
82
82
|
var import_chat2 = require("koishi-plugin-chatluna/services/chat");
|
|
83
|
-
var
|
|
83
|
+
var import_koishi27 = require("koishi-plugin-chatluna/utils/koishi");
|
|
84
84
|
var import_logger7 = require("koishi-plugin-chatluna/utils/logger");
|
|
85
85
|
var request = __toESM(require("koishi-plugin-chatluna/utils/request"), 1);
|
|
86
86
|
|
|
@@ -3258,10 +3258,11 @@ function apply15(ctx, config, chain) {
|
|
|
3258
3258
|
__name(apply15, "apply");
|
|
3259
3259
|
|
|
3260
3260
|
// src/middlewares/chat/cooldown_time.ts
|
|
3261
|
-
var
|
|
3261
|
+
var lastChatTimes = /* @__PURE__ */ new Map();
|
|
3262
3262
|
function apply16(ctx, config, chain) {
|
|
3263
3263
|
chain.middleware("cooldown_time", async (session, context) => {
|
|
3264
3264
|
const currentChatTime = Date.now();
|
|
3265
|
+
const lastChatTime = lastChatTimes.get(session.channelId) ?? 0;
|
|
3265
3266
|
if (currentChatTime - lastChatTime < config.msgCooldown * 1e3) {
|
|
3266
3267
|
const waitTime = (config.msgCooldown * 1e3 - (currentChatTime - lastChatTime)) / 1e3;
|
|
3267
3268
|
context.message = session.text(
|
|
@@ -3270,9 +3271,9 @@ function apply16(ctx, config, chain) {
|
|
|
3270
3271
|
);
|
|
3271
3272
|
return 1 /* STOP */;
|
|
3272
3273
|
}
|
|
3273
|
-
|
|
3274
|
+
lastChatTimes.set(session.channelId, currentChatTime);
|
|
3274
3275
|
return 2 /* CONTINUE */;
|
|
3275
|
-
}).after("allow_reply");
|
|
3276
|
+
}).after("allow_reply").after("message_delay");
|
|
3276
3277
|
}
|
|
3277
3278
|
__name(apply16, "apply");
|
|
3278
3279
|
|
|
@@ -3315,7 +3316,7 @@ function apply17(ctx, config, chain) {
|
|
|
3315
3316
|
queues.set(conversationId, queue);
|
|
3316
3317
|
const tailTurn = queue.turns[queue.turns.length - 1];
|
|
3317
3318
|
let turn;
|
|
3318
|
-
if (tailTurn && tailTurn.state !== "processing"
|
|
3319
|
+
if (tailTurn && tailTurn.state !== "processing") {
|
|
3319
3320
|
turn = tailTurn;
|
|
3320
3321
|
logger9.debug(
|
|
3321
3322
|
`Joining turn for ${conversationId}, messageId: ${messageId}, user: ${userName}, total: ${turn.messages.length + 1}`
|
|
@@ -3324,7 +3325,6 @@ function apply17(ctx, config, chain) {
|
|
|
3324
3325
|
const state = queue.turns.length === 0 && config.messageQueueDelay > 0 ? "collecting" : "waiting";
|
|
3325
3326
|
turn = {
|
|
3326
3327
|
messages: [],
|
|
3327
|
-
userName,
|
|
3328
3328
|
state
|
|
3329
3329
|
};
|
|
3330
3330
|
queue.turns.push(turn);
|
|
@@ -3501,11 +3501,18 @@ function mergeMessages(messages) {
|
|
|
3501
3501
|
if (messages.length === 1) return messages[0];
|
|
3502
3502
|
const base = messages[0];
|
|
3503
3503
|
const mergedContent = [];
|
|
3504
|
+
const multiUser = messages.some((msg) => msg.name !== base.name);
|
|
3504
3505
|
for (const msg of messages) {
|
|
3505
3506
|
const content = msg.content;
|
|
3506
3507
|
if (mergedContent.length > 0) {
|
|
3507
3508
|
mergedContent.push({ type: "text", text: "\n" });
|
|
3508
3509
|
}
|
|
3510
|
+
if (multiUser) {
|
|
3511
|
+
mergedContent.push({
|
|
3512
|
+
type: "text",
|
|
3513
|
+
text: `${msg.name ?? "unknown"}: `
|
|
3514
|
+
});
|
|
3515
|
+
}
|
|
3509
3516
|
if (typeof content === "string") {
|
|
3510
3517
|
mergedContent.push({ type: "text", text: content });
|
|
3511
3518
|
} else if (Array.isArray(content)) {
|
|
@@ -3542,7 +3549,6 @@ __name(createPendingMessage, "createPendingMessage");
|
|
|
3542
3549
|
var import_koishi8 = require("koishi");
|
|
3543
3550
|
var import_string6 = require("koishi-plugin-chatluna/utils/string");
|
|
3544
3551
|
var import_types5 = require("koishi-plugin-chatluna/llm-core/platform/types");
|
|
3545
|
-
var import_koishi9 = require("koishi-plugin-chatluna/utils/koishi");
|
|
3546
3552
|
var import_count_tokens3 = require("koishi-plugin-chatluna/llm-core/utils/count_tokens");
|
|
3547
3553
|
var import_base64 = require("koishi-plugin-chatluna/utils/base64");
|
|
3548
3554
|
|
|
@@ -3583,7 +3589,6 @@ var SUPPORTED_AUDIO_MIME_TYPES = /* @__PURE__ */ new Set([
|
|
|
3583
3589
|
"audio/aiff"
|
|
3584
3590
|
]);
|
|
3585
3591
|
function apply18(ctx, config, chain) {
|
|
3586
|
-
const forwardHistory = /* @__PURE__ */ new WeakMap();
|
|
3587
3592
|
const fileSizes = /* @__PURE__ */ new WeakMap();
|
|
3588
3593
|
const handledAudio = /* @__PURE__ */ new WeakSet();
|
|
3589
3594
|
chain.middleware("read_chat_message", async (session, context) => {
|
|
@@ -3648,7 +3653,7 @@ function apply18(ctx, config, chain) {
|
|
|
3648
3653
|
if (message == null || resolved == null) {
|
|
3649
3654
|
return 2 /* CONTINUE */;
|
|
3650
3655
|
}
|
|
3651
|
-
const
|
|
3656
|
+
const msg = await ctx.chatluna.messageTransformer.transform(
|
|
3652
3657
|
session,
|
|
3653
3658
|
message,
|
|
3654
3659
|
ctx.chatluna.conversation.pickModel(
|
|
@@ -3666,23 +3671,10 @@ function apply18(ctx, config, chain) {
|
|
|
3666
3671
|
includeQuoteReply: config.includeQuoteReply
|
|
3667
3672
|
}
|
|
3668
3673
|
);
|
|
3669
|
-
if (
|
|
3670
|
-
const state = forwardHistory.get(transformedMessage);
|
|
3671
|
-
if (state?.hasForwardHistory) {
|
|
3672
|
-
if (state.ids.length > 0) {
|
|
3673
|
-
transformedMessage.additional_kwargs ??= {};
|
|
3674
|
-
transformedMessage.additional_kwargs.forwardMessageIds = state.ids;
|
|
3675
|
-
}
|
|
3676
|
-
addMessageContent(
|
|
3677
|
-
transformedMessage,
|
|
3678
|
-
state.ids.length > 0 ? state.ids.map((id) => `<forward id="${id}"/>`).join("") : "<forward/>"
|
|
3679
|
-
);
|
|
3680
|
-
}
|
|
3681
|
-
}
|
|
3682
|
-
if (transformedMessage.content.length < 1 && (0, import_string6.getMessageContent)(transformedMessage.content).trim().length < 1) {
|
|
3674
|
+
if (msg.content.length < 1 && (0, import_string6.getMessageContent)(msg.content).trim().length < 1) {
|
|
3683
3675
|
return 1 /* STOP */;
|
|
3684
3676
|
}
|
|
3685
|
-
context.options.inputMessage =
|
|
3677
|
+
context.options.inputMessage = msg;
|
|
3686
3678
|
return 2 /* CONTINUE */;
|
|
3687
3679
|
}).after("resolve_conversation").before("message_delay");
|
|
3688
3680
|
ctx.chatluna.messageTransformer.before(async (session, elements) => {
|
|
@@ -3709,17 +3701,17 @@ function apply18(ctx, config, chain) {
|
|
|
3709
3701
|
);
|
|
3710
3702
|
ctx.chatluna.messageTransformer.intercept(
|
|
3711
3703
|
"forward",
|
|
3712
|
-
async (session,
|
|
3713
|
-
if (
|
|
3714
|
-
trackForwardId(forwardHistory, element, message);
|
|
3704
|
+
async (session, el, msg) => {
|
|
3705
|
+
if (config.attachForwardMsgIdToContext) addForward(msg, el);
|
|
3715
3706
|
}
|
|
3716
3707
|
);
|
|
3717
3708
|
ctx.chatluna.messageTransformer.intercept(
|
|
3718
3709
|
"message",
|
|
3719
|
-
async (session,
|
|
3720
|
-
if (
|
|
3721
|
-
|
|
3722
|
-
|
|
3710
|
+
async (session, el, msg) => {
|
|
3711
|
+
if (config.attachForwardMsgIdToContext && ["true", "1"].includes(String(el.attrs.forward))) {
|
|
3712
|
+
addForward(msg, el);
|
|
3713
|
+
}
|
|
3714
|
+
return false;
|
|
3723
3715
|
}
|
|
3724
3716
|
);
|
|
3725
3717
|
ctx.chatluna.messageTransformer.intercept(
|
|
@@ -4113,25 +4105,25 @@ function modelSupportsElement(ctx, model, type) {
|
|
|
4113
4105
|
);
|
|
4114
4106
|
}
|
|
4115
4107
|
__name(modelSupportsElement, "modelSupportsElement");
|
|
4108
|
+
function addForward(message, element) {
|
|
4109
|
+
const id = element.attrs.id?.toString();
|
|
4110
|
+
if (!id) {
|
|
4111
|
+
addMessageContent(message, "<forward/>");
|
|
4112
|
+
return;
|
|
4113
|
+
}
|
|
4114
|
+
message.additional_kwargs ??= {};
|
|
4115
|
+
const ids = message.additional_kwargs.forwardMessageIds ??= [];
|
|
4116
|
+
if (ids.includes(id)) return;
|
|
4117
|
+
ids.push(id);
|
|
4118
|
+
addMessageContent(message, (0, import_koishi8.h)("forward", { id }).toString());
|
|
4119
|
+
}
|
|
4120
|
+
__name(addForward, "addForward");
|
|
4116
4121
|
function setElementUrl(element, url) {
|
|
4117
4122
|
element.attrs["imageUrl"] = url;
|
|
4118
4123
|
element.attrs["src"] = url;
|
|
4119
4124
|
element.attrs["url"] = url;
|
|
4120
4125
|
}
|
|
4121
4126
|
__name(setElementUrl, "setElementUrl");
|
|
4122
|
-
function trackForwardId(history, element, message) {
|
|
4123
|
-
const state = history.get(message) ?? {
|
|
4124
|
-
ids: [],
|
|
4125
|
-
hasForwardHistory: false
|
|
4126
|
-
};
|
|
4127
|
-
history.set(message, state);
|
|
4128
|
-
state.hasForwardHistory = true;
|
|
4129
|
-
const id = (0, import_koishi9.pickForwardMessageId)(element);
|
|
4130
|
-
if (id && !state.ids.includes(id)) {
|
|
4131
|
-
state.ids.push(id);
|
|
4132
|
-
}
|
|
4133
|
-
}
|
|
4134
|
-
__name(trackForwardId, "trackForwardId");
|
|
4135
4127
|
function appendQQAttachments(session, elements) {
|
|
4136
4128
|
if (session.platform !== "qq") {
|
|
4137
4129
|
return;
|
|
@@ -4216,7 +4208,7 @@ __name(renderMessage, "renderMessage");
|
|
|
4216
4208
|
|
|
4217
4209
|
// src/middlewares/chat/rollback_chat.ts
|
|
4218
4210
|
var import_string7 = require("koishi-plugin-chatluna/utils/string");
|
|
4219
|
-
var
|
|
4211
|
+
var import_koishi9 = require("koishi-plugin-chatluna/utils/koishi");
|
|
4220
4212
|
var MAX_ROLLBACK_HOPS = 1e3;
|
|
4221
4213
|
function apply20(ctx, config, chain) {
|
|
4222
4214
|
chain.middleware("rollback_chat", async (session, context) => {
|
|
@@ -4288,7 +4280,7 @@ async function rollbackConversation(ctx, config, session, context, conversation,
|
|
|
4288
4280
|
msg: session.text(".conversation_not_exist")
|
|
4289
4281
|
};
|
|
4290
4282
|
}
|
|
4291
|
-
if (resolved.constraint.manageMode === "admin" && !await (0,
|
|
4283
|
+
if (resolved.constraint.manageMode === "admin" && !await (0, import_koishi9.checkAdmin)(session)) {
|
|
4292
4284
|
return {
|
|
4293
4285
|
status: 1 /* STOP */,
|
|
4294
4286
|
msg: session.text(".conversation_not_exist")
|
|
@@ -4354,7 +4346,7 @@ async function rollbackConversation(ctx, config, session, context, conversation,
|
|
|
4354
4346
|
const humanContent = await decodeMessageContent(humanMessage);
|
|
4355
4347
|
inputMessage = await ctx.chatluna.messageTransformer.transform(
|
|
4356
4348
|
session,
|
|
4357
|
-
(0,
|
|
4349
|
+
(0, import_koishi9.transformMessageContentToElements)(humanContent),
|
|
4358
4350
|
ctx.chatluna.conversation.pickModel(resolved.constraint, current) ?? current.model,
|
|
4359
4351
|
{
|
|
4360
4352
|
content: "",
|
|
@@ -4386,7 +4378,7 @@ async function rollbackConversation(ctx, config, session, context, conversation,
|
|
|
4386
4378
|
__name(rollbackConversation, "rollbackConversation");
|
|
4387
4379
|
|
|
4388
4380
|
// src/middlewares/chat/stop_chat.ts
|
|
4389
|
-
var
|
|
4381
|
+
var import_koishi10 = require("koishi-plugin-chatluna/utils/koishi");
|
|
4390
4382
|
function apply21(ctx, config, chain) {
|
|
4391
4383
|
chain.middleware("stop_chat", async (session, context) => {
|
|
4392
4384
|
const { command: command2 } = context;
|
|
@@ -4408,7 +4400,7 @@ function apply21(ctx, config, chain) {
|
|
|
4408
4400
|
context.message = session.text(".no_active_chat");
|
|
4409
4401
|
return 1 /* STOP */;
|
|
4410
4402
|
}
|
|
4411
|
-
if (resolved.constraint.manageMode === "admin" && !await (0,
|
|
4403
|
+
if (resolved.constraint.manageMode === "admin" && !await (0, import_koishi10.checkAdmin)(session)) {
|
|
4412
4404
|
context.message = session.text(".stop_failed");
|
|
4413
4405
|
return 1 /* STOP */;
|
|
4414
4406
|
}
|
|
@@ -5588,10 +5580,10 @@ function apply39(ctx, config, chain) {
|
|
|
5588
5580
|
__name(apply39, "apply");
|
|
5589
5581
|
|
|
5590
5582
|
// src/middlewares/system/conversation_manage.ts
|
|
5591
|
-
var
|
|
5583
|
+
var import_koishi11 = require("koishi");
|
|
5592
5584
|
var import_error8 = require("koishi-plugin-chatluna/utils/error");
|
|
5593
5585
|
var import_pagination7 = require("koishi-plugin-chatluna/utils/pagination");
|
|
5594
|
-
var
|
|
5586
|
+
var import_koishi12 = require("koishi-plugin-chatluna/utils/koishi");
|
|
5595
5587
|
var import_promises6 = __toESM(require("fs/promises"), 1);
|
|
5596
5588
|
function apply40(ctx, config, chain) {
|
|
5597
5589
|
function middleware2(name2, fn) {
|
|
@@ -5614,7 +5606,7 @@ function apply40(ctx, config, chain) {
|
|
|
5614
5606
|
);
|
|
5615
5607
|
return 1 /* STOP */;
|
|
5616
5608
|
}
|
|
5617
|
-
if (resolved.constraint.manageMode === "admin" && resolved.constraint.routeMode !== "personal" && !await (0,
|
|
5609
|
+
if (resolved.constraint.manageMode === "admin" && resolved.constraint.routeMode !== "personal" && !await (0, import_koishi12.checkAdmin)(session)) {
|
|
5618
5610
|
context.message = session.text(
|
|
5619
5611
|
"chatluna.conversation.messages.admin_required",
|
|
5620
5612
|
[import_error8.ChatLunaErrorCode.CONVERSATION_ADMIN_REQUIRED]
|
|
@@ -5957,7 +5949,7 @@ function apply40(ctx, config, chain) {
|
|
|
5957
5949
|
try {
|
|
5958
5950
|
const buffer = await import_promises6.default.readFile(result.path);
|
|
5959
5951
|
await session.send(
|
|
5960
|
-
|
|
5952
|
+
import_koishi11.h.file(buffer, "application/markdown", {
|
|
5961
5953
|
title: result.conversation.title + ".md"
|
|
5962
5954
|
})
|
|
5963
5955
|
);
|
|
@@ -6719,106 +6711,106 @@ async function unbindConversation(ctx, conversationId) {
|
|
|
6719
6711
|
__name(unbindConversation, "unbindConversation");
|
|
6720
6712
|
|
|
6721
6713
|
// src/config.ts
|
|
6722
|
-
var
|
|
6723
|
-
var Config2 =
|
|
6724
|
-
|
|
6725
|
-
botNames:
|
|
6726
|
-
isNickname:
|
|
6727
|
-
isNickNameWithContent:
|
|
6714
|
+
var import_koishi13 = require("koishi");
|
|
6715
|
+
var Config2 = import_koishi13.Schema.intersect([
|
|
6716
|
+
import_koishi13.Schema.object({
|
|
6717
|
+
botNames: import_koishi13.Schema.array(import_koishi13.Schema.string()).default(["香草"]),
|
|
6718
|
+
isNickname: import_koishi13.Schema.boolean().default(true),
|
|
6719
|
+
isNickNameWithContent: import_koishi13.Schema.boolean().default(false)
|
|
6728
6720
|
}),
|
|
6729
|
-
|
|
6730
|
-
allowPrivate:
|
|
6731
|
-
allowAtReply:
|
|
6732
|
-
allowQuoteReply:
|
|
6733
|
-
privateChatWithoutCommand:
|
|
6734
|
-
includeQuoteReply:
|
|
6735
|
-
randomReplyFrequency:
|
|
6736
|
-
attachForwardMsgIdToContext:
|
|
6737
|
-
autoUpdateConversationModel:
|
|
6721
|
+
import_koishi13.Schema.object({
|
|
6722
|
+
allowPrivate: import_koishi13.Schema.boolean().default(true),
|
|
6723
|
+
allowAtReply: import_koishi13.Schema.boolean().default(true),
|
|
6724
|
+
allowQuoteReply: import_koishi13.Schema.boolean().default(false),
|
|
6725
|
+
privateChatWithoutCommand: import_koishi13.Schema.boolean().default(true),
|
|
6726
|
+
includeQuoteReply: import_koishi13.Schema.boolean().default(true),
|
|
6727
|
+
randomReplyFrequency: import_koishi13.Schema.percent().min(0).max(1).step(0.01).default(0).computed(),
|
|
6728
|
+
attachForwardMsgIdToContext: import_koishi13.Schema.boolean().default(false),
|
|
6729
|
+
autoUpdateConversationModel: import_koishi13.Schema.boolean().default(false)
|
|
6738
6730
|
}),
|
|
6739
|
-
|
|
6740
|
-
|
|
6741
|
-
isForwardMsg:
|
|
6731
|
+
import_koishi13.Schema.intersect([
|
|
6732
|
+
import_koishi13.Schema.object({
|
|
6733
|
+
isForwardMsg: import_koishi13.Schema.boolean().default(false)
|
|
6742
6734
|
}),
|
|
6743
|
-
|
|
6744
|
-
|
|
6745
|
-
isForwardMsg:
|
|
6746
|
-
forwardMsgMinLength:
|
|
6735
|
+
import_koishi13.Schema.union([
|
|
6736
|
+
import_koishi13.Schema.object({
|
|
6737
|
+
isForwardMsg: import_koishi13.Schema.const(true).required(),
|
|
6738
|
+
forwardMsgMinLength: import_koishi13.Schema.number().min(0).max(400).step(1).default(0)
|
|
6747
6739
|
}),
|
|
6748
|
-
|
|
6740
|
+
import_koishi13.Schema.object({})
|
|
6749
6741
|
])
|
|
6750
6742
|
]),
|
|
6751
|
-
|
|
6752
|
-
|
|
6753
|
-
isReplyWithAt:
|
|
6743
|
+
import_koishi13.Schema.intersect([
|
|
6744
|
+
import_koishi13.Schema.object({
|
|
6745
|
+
isReplyWithAt: import_koishi13.Schema.boolean().default(false)
|
|
6754
6746
|
}),
|
|
6755
|
-
|
|
6756
|
-
|
|
6757
|
-
isReplyWithAt:
|
|
6758
|
-
replyQuoteThreshold:
|
|
6747
|
+
import_koishi13.Schema.union([
|
|
6748
|
+
import_koishi13.Schema.object({
|
|
6749
|
+
isReplyWithAt: import_koishi13.Schema.const(true).required(),
|
|
6750
|
+
replyQuoteThreshold: import_koishi13.Schema.number().min(0).max(600).step(1).default(0)
|
|
6759
6751
|
}),
|
|
6760
|
-
|
|
6752
|
+
import_koishi13.Schema.object({})
|
|
6761
6753
|
])
|
|
6762
6754
|
]),
|
|
6763
|
-
|
|
6764
|
-
sendThinkingMessage:
|
|
6765
|
-
sendThinkingMessageTimeout:
|
|
6766
|
-
msgCooldown:
|
|
6767
|
-
messageQueue:
|
|
6768
|
-
messageQueueDelay:
|
|
6769
|
-
agentTaskAutoWakeup:
|
|
6770
|
-
showThoughtMessage:
|
|
6755
|
+
import_koishi13.Schema.object({
|
|
6756
|
+
sendThinkingMessage: import_koishi13.Schema.boolean().default(true),
|
|
6757
|
+
sendThinkingMessageTimeout: import_koishi13.Schema.number().default(15e3),
|
|
6758
|
+
msgCooldown: import_koishi13.Schema.number().min(0).max(3600).step(1).default(0),
|
|
6759
|
+
messageQueue: import_koishi13.Schema.boolean().default(true),
|
|
6760
|
+
messageQueueDelay: import_koishi13.Schema.number().min(0).max(60 * 30).default(0),
|
|
6761
|
+
agentTaskAutoWakeup: import_koishi13.Schema.boolean().default(true),
|
|
6762
|
+
showThoughtMessage: import_koishi13.Schema.boolean().default(false)
|
|
6771
6763
|
}),
|
|
6772
|
-
|
|
6773
|
-
outputMode:
|
|
6774
|
-
splitMessage:
|
|
6775
|
-
|
|
6776
|
-
|
|
6777
|
-
|
|
6764
|
+
import_koishi13.Schema.object({
|
|
6765
|
+
outputMode: import_koishi13.Schema.dynamic("output-mode").default("text"),
|
|
6766
|
+
splitMessage: import_koishi13.Schema.union([
|
|
6767
|
+
import_koishi13.Schema.const("none"),
|
|
6768
|
+
import_koishi13.Schema.const("punctuation"),
|
|
6769
|
+
import_koishi13.Schema.const("paragraph")
|
|
6778
6770
|
]).default("none"),
|
|
6779
|
-
censor:
|
|
6780
|
-
rawOnCensor:
|
|
6781
|
-
streamResponse:
|
|
6771
|
+
censor: import_koishi13.Schema.boolean().default(false),
|
|
6772
|
+
rawOnCensor: import_koishi13.Schema.boolean().default(false),
|
|
6773
|
+
streamResponse: import_koishi13.Schema.boolean().default(false)
|
|
6782
6774
|
}),
|
|
6783
|
-
|
|
6784
|
-
blackList:
|
|
6775
|
+
import_koishi13.Schema.object({
|
|
6776
|
+
blackList: import_koishi13.Schema.number().min(0).max(1).step(1).default(0).computed().default(0)
|
|
6785
6777
|
}),
|
|
6786
|
-
|
|
6787
|
-
infiniteContext:
|
|
6788
|
-
infiniteContextThreshold:
|
|
6789
|
-
autoArchive:
|
|
6790
|
-
autoArchiveTimeout:
|
|
6791
|
-
autoPurgeArchive:
|
|
6792
|
-
autoPurgeArchiveTimeout:
|
|
6778
|
+
import_koishi13.Schema.object({
|
|
6779
|
+
infiniteContext: import_koishi13.Schema.boolean().default(true),
|
|
6780
|
+
infiniteContextThreshold: import_koishi13.Schema.percent().min(0.5).max(0.95).step(0.01).default(0.85),
|
|
6781
|
+
autoArchive: import_koishi13.Schema.boolean().default(false),
|
|
6782
|
+
autoArchiveTimeout: import_koishi13.Schema.number().default(import_koishi13.Time.day * 10 / import_koishi13.Time.second).min(import_koishi13.Time.hour / import_koishi13.Time.second),
|
|
6783
|
+
autoPurgeArchive: import_koishi13.Schema.boolean().default(false),
|
|
6784
|
+
autoPurgeArchiveTimeout: import_koishi13.Schema.number().default(import_koishi13.Time.day * 30 / import_koishi13.Time.second).min(import_koishi13.Time.hour / import_koishi13.Time.second)
|
|
6793
6785
|
}),
|
|
6794
|
-
|
|
6795
|
-
defaultEmbeddings:
|
|
6796
|
-
defaultVectorStore:
|
|
6786
|
+
import_koishi13.Schema.object({
|
|
6787
|
+
defaultEmbeddings: import_koishi13.Schema.dynamic("embeddings").default("无"),
|
|
6788
|
+
defaultVectorStore: import_koishi13.Schema.dynamic("vector-store").default("无")
|
|
6797
6789
|
}),
|
|
6798
|
-
|
|
6799
|
-
defaultGroupRouteMode:
|
|
6800
|
-
|
|
6801
|
-
|
|
6790
|
+
import_koishi13.Schema.object({
|
|
6791
|
+
defaultGroupRouteMode: import_koishi13.Schema.union([
|
|
6792
|
+
import_koishi13.Schema.const("shared"),
|
|
6793
|
+
import_koishi13.Schema.const("personal")
|
|
6802
6794
|
]).default("shared"),
|
|
6803
|
-
defaultChatMode:
|
|
6804
|
-
defaultModel:
|
|
6805
|
-
defaultPreset:
|
|
6806
|
-
enablePresetKeywordTrigger:
|
|
6795
|
+
defaultChatMode: import_koishi13.Schema.dynamic("chat-mode").default("plugin"),
|
|
6796
|
+
defaultModel: import_koishi13.Schema.dynamic("model").default("无"),
|
|
6797
|
+
defaultPreset: import_koishi13.Schema.dynamic("preset").default("sydney"),
|
|
6798
|
+
enablePresetKeywordTrigger: import_koishi13.Schema.boolean().default(true)
|
|
6807
6799
|
}),
|
|
6808
|
-
|
|
6809
|
-
voiceSpeakId:
|
|
6810
|
-
isLog:
|
|
6800
|
+
import_koishi13.Schema.object({
|
|
6801
|
+
voiceSpeakId: import_koishi13.Schema.number().default(0),
|
|
6802
|
+
isLog: import_koishi13.Schema.boolean().default(false)
|
|
6811
6803
|
}),
|
|
6812
|
-
|
|
6813
|
-
|
|
6814
|
-
isProxy:
|
|
6804
|
+
import_koishi13.Schema.intersect([
|
|
6805
|
+
import_koishi13.Schema.object({
|
|
6806
|
+
isProxy: import_koishi13.Schema.boolean().default(false)
|
|
6815
6807
|
}),
|
|
6816
|
-
|
|
6817
|
-
|
|
6818
|
-
isProxy:
|
|
6819
|
-
proxyAddress:
|
|
6808
|
+
import_koishi13.Schema.union([
|
|
6809
|
+
import_koishi13.Schema.object({
|
|
6810
|
+
isProxy: import_koishi13.Schema.const(true).required(),
|
|
6811
|
+
proxyAddress: import_koishi13.Schema.string().default("http://127.0.0.1:7897")
|
|
6820
6812
|
}),
|
|
6821
|
-
|
|
6813
|
+
import_koishi13.Schema.object({})
|
|
6822
6814
|
])
|
|
6823
6815
|
])
|
|
6824
6816
|
]).i18n({
|
|
@@ -6827,23 +6819,23 @@ var Config2 = import_koishi14.Schema.intersect([
|
|
|
6827
6819
|
});
|
|
6828
6820
|
|
|
6829
6821
|
// src/render/index.ts
|
|
6830
|
-
var
|
|
6822
|
+
var import_koishi25 = require("koishi");
|
|
6831
6823
|
var import_error9 = require("koishi-plugin-chatluna/utils/error");
|
|
6832
6824
|
|
|
6833
6825
|
// src/render/koishi-element.ts
|
|
6834
|
-
var
|
|
6826
|
+
var import_koishi17 = require("koishi");
|
|
6835
6827
|
var import_koishi_plugin_chatluna9 = require("koishi-plugin-chatluna");
|
|
6836
6828
|
var import_string11 = require("koishi-plugin-chatluna/utils/string");
|
|
6837
|
-
var
|
|
6829
|
+
var import_koishi18 = require("koishi-plugin-chatluna/utils/koishi");
|
|
6838
6830
|
|
|
6839
6831
|
// src/render/base.ts
|
|
6840
|
-
var
|
|
6832
|
+
var import_koishi16 = require("koishi");
|
|
6841
6833
|
var import_string10 = require("koishi-plugin-chatluna/utils/string");
|
|
6842
6834
|
|
|
6843
6835
|
// src/render/split.ts
|
|
6844
|
-
var
|
|
6836
|
+
var import_koishi14 = require("koishi");
|
|
6845
6837
|
var import_string9 = require("koishi-plugin-chatluna/utils/string");
|
|
6846
|
-
var
|
|
6838
|
+
var import_koishi15 = require("koishi-plugin-chatluna/utils/koishi");
|
|
6847
6839
|
|
|
6848
6840
|
// src/render/sentence.ts
|
|
6849
6841
|
var import_grapheme = require("unicode-segmenter/grapheme");
|
|
@@ -7123,16 +7115,16 @@ var MessageElementSplitter = class {
|
|
|
7123
7115
|
writeText(text) {
|
|
7124
7116
|
if (!text) return [];
|
|
7125
7117
|
this.buf += text;
|
|
7126
|
-
const result = (0,
|
|
7118
|
+
const result = (0, import_koishi15.parseElements)(this.buf, true);
|
|
7127
7119
|
this.buf = result.rest;
|
|
7128
7120
|
return result.elements;
|
|
7129
7121
|
}
|
|
7130
7122
|
flush() {
|
|
7131
7123
|
if (!this.buf.trim()) return [];
|
|
7132
7124
|
try {
|
|
7133
|
-
return (0,
|
|
7125
|
+
return (0, import_koishi15.parseElements)(this.buf);
|
|
7134
7126
|
} catch {
|
|
7135
|
-
return [
|
|
7127
|
+
return [import_koishi14.h.text(this.buf)];
|
|
7136
7128
|
} finally {
|
|
7137
7129
|
this.buf = "";
|
|
7138
7130
|
}
|
|
@@ -7227,7 +7219,7 @@ var BufferedRenderStreamSession = class {
|
|
|
7227
7219
|
const elements = await this.renderText(part);
|
|
7228
7220
|
result.push(
|
|
7229
7221
|
...this.options.split && this.options.split !== "none" ? elements.map(
|
|
7230
|
-
(el) => el.type === "message" ? el : (0,
|
|
7222
|
+
(el) => el.type === "message" ? el : (0, import_koishi16.h)("message", el)
|
|
7231
7223
|
) : elements
|
|
7232
7224
|
);
|
|
7233
7225
|
}
|
|
@@ -7245,7 +7237,7 @@ var KoishiElementRenderer = class extends Renderer {
|
|
|
7245
7237
|
transformed = transformAndEscape(transformed);
|
|
7246
7238
|
if (options.split && options.split !== "none") {
|
|
7247
7239
|
transformed = transformed.map(
|
|
7248
|
-
(element) => element.type === "message" ? element : (0,
|
|
7240
|
+
(element) => element.type === "message" ? element : (0, import_koishi17.h)("message", element)
|
|
7249
7241
|
);
|
|
7250
7242
|
}
|
|
7251
7243
|
return {
|
|
@@ -7262,7 +7254,7 @@ var KoishiElementRenderer = class extends Renderer {
|
|
|
7262
7254
|
createStreamSession(options, plan) {
|
|
7263
7255
|
return new KoishiElementStreamSession(options, plan);
|
|
7264
7256
|
}
|
|
7265
|
-
schema =
|
|
7257
|
+
schema = import_koishi17.Schema.const("koishi-element").i18n({
|
|
7266
7258
|
"zh-CN": "将回复作为 koishi 消息元素进行渲染",
|
|
7267
7259
|
"en-US": "Render as koishi message element template"
|
|
7268
7260
|
});
|
|
@@ -7286,12 +7278,12 @@ var KoishiElementStreamSession = class {
|
|
|
7286
7278
|
if (!text) return null;
|
|
7287
7279
|
if (this.plan.mode === "edit") {
|
|
7288
7280
|
this.text += text;
|
|
7289
|
-
return transformAndEscape([
|
|
7281
|
+
return transformAndEscape([import_koishi17.h.text(this.text + "●")]);
|
|
7290
7282
|
}
|
|
7291
7283
|
let elements = this.splitter.writeText(text);
|
|
7292
7284
|
if (this.options.split && this.options.split !== "none") {
|
|
7293
7285
|
elements = elements.map(
|
|
7294
|
-
(el) => el.type === "message" ? el : (0,
|
|
7286
|
+
(el) => el.type === "message" ? el : (0, import_koishi17.h)("message", el)
|
|
7295
7287
|
);
|
|
7296
7288
|
}
|
|
7297
7289
|
return elements.length > 0 ? elements : null;
|
|
@@ -7299,12 +7291,12 @@ var KoishiElementStreamSession = class {
|
|
|
7299
7291
|
flush() {
|
|
7300
7292
|
if (this.plan.mode === "buffer") return null;
|
|
7301
7293
|
if (this.plan.mode === "edit" && this.text.trim()) {
|
|
7302
|
-
return transformAndEscape([
|
|
7294
|
+
return transformAndEscape([import_koishi17.h.text(this.text)]);
|
|
7303
7295
|
}
|
|
7304
7296
|
let elements = this.splitter.flush();
|
|
7305
7297
|
if (this.options.split && this.options.split !== "none") {
|
|
7306
7298
|
elements = elements.map(
|
|
7307
|
-
(el) => el.type === "message" ? el : (0,
|
|
7299
|
+
(el) => el.type === "message" ? el : (0, import_koishi17.h)("message", el)
|
|
7308
7300
|
);
|
|
7309
7301
|
}
|
|
7310
7302
|
return elements.length > 0 ? elements : null;
|
|
@@ -7323,24 +7315,24 @@ function transformAndEscape(source) {
|
|
|
7323
7315
|
return element;
|
|
7324
7316
|
}
|
|
7325
7317
|
try {
|
|
7326
|
-
return (0,
|
|
7318
|
+
return (0, import_koishi18.parseElements)(element.attrs["content"]);
|
|
7327
7319
|
} catch (e) {
|
|
7328
7320
|
import_koishi_plugin_chatluna9.logger.error(e);
|
|
7329
|
-
return [
|
|
7321
|
+
return [import_koishi17.h.text(element.attrs["content"])];
|
|
7330
7322
|
}
|
|
7331
7323
|
});
|
|
7332
7324
|
}
|
|
7333
7325
|
__name(transformAndEscape, "transformAndEscape");
|
|
7334
7326
|
|
|
7335
7327
|
// src/render/mixed-voice.ts
|
|
7336
|
-
var
|
|
7328
|
+
var import_koishi21 = require("koishi");
|
|
7337
7329
|
var import_koishi_plugin_chatluna10 = require("koishi-plugin-chatluna");
|
|
7338
7330
|
var import_string13 = require("koishi-plugin-chatluna/utils/string");
|
|
7339
7331
|
|
|
7340
7332
|
// src/render/text.ts
|
|
7341
|
-
var
|
|
7333
|
+
var import_koishi19 = require("koishi");
|
|
7342
7334
|
var import_string12 = require("koishi-plugin-chatluna/utils/string");
|
|
7343
|
-
var
|
|
7335
|
+
var import_koishi20 = require("koishi-plugin-chatluna/utils/koishi");
|
|
7344
7336
|
var TextRenderer = class extends Renderer {
|
|
7345
7337
|
static {
|
|
7346
7338
|
__name(this, "TextRenderer");
|
|
@@ -7349,8 +7341,8 @@ var TextRenderer = class extends Renderer {
|
|
|
7349
7341
|
if (options.session != null && options.session.platform === "qq" && options.session.isDirect) {
|
|
7350
7342
|
return {
|
|
7351
7343
|
element: [
|
|
7352
|
-
|
|
7353
|
-
...
|
|
7344
|
+
import_koishi19.h.text((0, import_string12.getMessageContent)(message.content)),
|
|
7345
|
+
...import_koishi19.h.parse("<markdown-qq></markdown-qq>")
|
|
7354
7346
|
]
|
|
7355
7347
|
};
|
|
7356
7348
|
}
|
|
@@ -7363,16 +7355,16 @@ var TextRenderer = class extends Renderer {
|
|
|
7363
7355
|
const element = transformed.shift();
|
|
7364
7356
|
const content = element.attrs["content"];
|
|
7365
7357
|
if (content) {
|
|
7366
|
-
transformed.unshift(
|
|
7358
|
+
transformed.unshift(import_koishi19.h.text(content));
|
|
7367
7359
|
} else {
|
|
7368
7360
|
transformed.unshift(...element.children);
|
|
7369
7361
|
}
|
|
7370
7362
|
}
|
|
7371
7363
|
if (options.split && options.split !== "none") {
|
|
7372
7364
|
transformed = transformed.flatMap((element) => {
|
|
7373
|
-
if (element.type !== "text") return (0,
|
|
7365
|
+
if (element.type !== "text") return (0, import_koishi19.h)("message", element);
|
|
7374
7366
|
return splitText2(element.attrs["content"], options.split).map(
|
|
7375
|
-
(text) => (0,
|
|
7367
|
+
(text) => (0, import_koishi19.h)("message", import_koishi19.h.text(text))
|
|
7376
7368
|
);
|
|
7377
7369
|
});
|
|
7378
7370
|
}
|
|
@@ -7390,7 +7382,7 @@ var TextRenderer = class extends Renderer {
|
|
|
7390
7382
|
createStreamSession(options, plan) {
|
|
7391
7383
|
return new TextStreamSession(options, plan);
|
|
7392
7384
|
}
|
|
7393
|
-
schema =
|
|
7385
|
+
schema = import_koishi19.Schema.const("text").i18n({
|
|
7394
7386
|
"zh-CN": "将回复作为 markdown 进行渲染",
|
|
7395
7387
|
"en-US": "Render as markdown"
|
|
7396
7388
|
});
|
|
@@ -7411,7 +7403,7 @@ var TextStreamSession = class extends BufferedRenderStreamSession {
|
|
|
7411
7403
|
const element = transformed.shift();
|
|
7412
7404
|
const content = element.attrs["content"];
|
|
7413
7405
|
if (content) {
|
|
7414
|
-
transformed.unshift(
|
|
7406
|
+
transformed.unshift(import_koishi19.h.text(content));
|
|
7415
7407
|
} else {
|
|
7416
7408
|
transformed.unshift(...element.children);
|
|
7417
7409
|
}
|
|
@@ -7422,7 +7414,7 @@ var TextStreamSession = class extends BufferedRenderStreamSession {
|
|
|
7422
7414
|
function transformAndEscape2(source, platform = "sandbox") {
|
|
7423
7415
|
return source.flatMap((element) => {
|
|
7424
7416
|
if (element.type === "text") {
|
|
7425
|
-
return (0,
|
|
7417
|
+
return (0, import_koishi20.transformToMarkdown)(element.attrs["content"], platform);
|
|
7426
7418
|
}
|
|
7427
7419
|
return element;
|
|
7428
7420
|
});
|
|
@@ -7466,7 +7458,7 @@ var MixedVoiceRenderer = class extends Renderer {
|
|
|
7466
7458
|
async renderText(messages, options) {
|
|
7467
7459
|
let transformed = transformAndEscape2(messages);
|
|
7468
7460
|
if (options.split && options.split !== "none") {
|
|
7469
|
-
transformed = transformed.map((element) => (0,
|
|
7461
|
+
transformed = transformed.map((element) => (0, import_koishi21.h)("message", element));
|
|
7470
7462
|
}
|
|
7471
7463
|
return {
|
|
7472
7464
|
element: transformed
|
|
@@ -7500,7 +7492,7 @@ var MixedVoiceRenderer = class extends Renderer {
|
|
|
7500
7492
|
)
|
|
7501
7493
|
);
|
|
7502
7494
|
}
|
|
7503
|
-
schema =
|
|
7495
|
+
schema = import_koishi21.Schema.const("mixed-voice").i18n({
|
|
7504
7496
|
"zh-CN": "同时输出语音和文本",
|
|
7505
7497
|
"en-US": "Output both voice and text"
|
|
7506
7498
|
});
|
|
@@ -7520,7 +7512,7 @@ var MixedVoiceStreamSession = class extends BufferedRenderStreamSession {
|
|
|
7520
7512
|
(0, import_string13.transformMessageContentToElements)(text)
|
|
7521
7513
|
);
|
|
7522
7514
|
if (this.options.split && this.options.split !== "none") {
|
|
7523
|
-
result.push(...elements.map((el) => (0,
|
|
7515
|
+
result.push(...elements.map((el) => (0, import_koishi21.h)("message", el)));
|
|
7524
7516
|
} else {
|
|
7525
7517
|
result.push(...elements);
|
|
7526
7518
|
}
|
|
@@ -7530,7 +7522,7 @@ var MixedVoiceStreamSession = class extends BufferedRenderStreamSession {
|
|
|
7530
7522
|
};
|
|
7531
7523
|
|
|
7532
7524
|
// src/render/pure-text.ts
|
|
7533
|
-
var
|
|
7525
|
+
var import_koishi22 = require("koishi");
|
|
7534
7526
|
var import_koishi_plugin_markdown = require("koishi-plugin-markdown");
|
|
7535
7527
|
var import_string14 = require("koishi-plugin-chatluna/utils/string");
|
|
7536
7528
|
var import_he = __toESM(require("he"), 1);
|
|
@@ -7621,10 +7613,10 @@ var PureTextRenderer = class extends Renderer {
|
|
|
7621
7613
|
if (options.split && options.split !== "none") {
|
|
7622
7614
|
return {
|
|
7623
7615
|
element: transformed.flatMap((element) => {
|
|
7624
|
-
if (element.type !== "text") return (0,
|
|
7616
|
+
if (element.type !== "text") return (0, import_koishi22.h)("message", element);
|
|
7625
7617
|
const content = element.attrs["content"];
|
|
7626
7618
|
return splitText2(content, options.split).map(
|
|
7627
|
-
(text) => (0,
|
|
7619
|
+
(text) => (0, import_koishi22.h)("message", import_koishi22.h.text(stripMarkdown(text)))
|
|
7628
7620
|
);
|
|
7629
7621
|
})
|
|
7630
7622
|
};
|
|
@@ -7632,7 +7624,7 @@ var PureTextRenderer = class extends Renderer {
|
|
|
7632
7624
|
return {
|
|
7633
7625
|
element: transformed.map((element) => {
|
|
7634
7626
|
if (element.type !== "text") return element;
|
|
7635
|
-
return
|
|
7627
|
+
return import_koishi22.h.text(stripMarkdown(element.attrs["content"]));
|
|
7636
7628
|
})
|
|
7637
7629
|
};
|
|
7638
7630
|
}
|
|
@@ -7646,7 +7638,7 @@ var PureTextRenderer = class extends Renderer {
|
|
|
7646
7638
|
createStreamSession(options, plan) {
|
|
7647
7639
|
return new PureTextStreamSession(options, plan);
|
|
7648
7640
|
}
|
|
7649
|
-
schema =
|
|
7641
|
+
schema = import_koishi22.Schema.const("pure-text").i18n({
|
|
7650
7642
|
"zh-CN": "将回复渲染为纯文本(去除 markdown 格式)",
|
|
7651
7643
|
"en-US": "Render as pure text (remove markdown format)"
|
|
7652
7644
|
});
|
|
@@ -7659,7 +7651,7 @@ var PureTextStreamSession = class extends BufferedRenderStreamSession {
|
|
|
7659
7651
|
super(options, plan);
|
|
7660
7652
|
}
|
|
7661
7653
|
renderText(text) {
|
|
7662
|
-
return [
|
|
7654
|
+
return [import_koishi22.h.text(stripMarkdown(text))];
|
|
7663
7655
|
}
|
|
7664
7656
|
};
|
|
7665
7657
|
function stripMarkdown(source) {
|
|
@@ -7668,7 +7660,7 @@ function stripMarkdown(source) {
|
|
|
7668
7660
|
__name(stripMarkdown, "stripMarkdown");
|
|
7669
7661
|
|
|
7670
7662
|
// src/render/raw.ts
|
|
7671
|
-
var
|
|
7663
|
+
var import_koishi23 = require("koishi");
|
|
7672
7664
|
var import_string15 = require("koishi-plugin-chatluna/utils/string");
|
|
7673
7665
|
var RawRenderer = class extends Renderer {
|
|
7674
7666
|
static {
|
|
@@ -7677,7 +7669,7 @@ var RawRenderer = class extends Renderer {
|
|
|
7677
7669
|
async render(message, options) {
|
|
7678
7670
|
if (typeof message.content === "string") {
|
|
7679
7671
|
return {
|
|
7680
|
-
element:
|
|
7672
|
+
element: import_koishi23.h.text(message.content)
|
|
7681
7673
|
};
|
|
7682
7674
|
}
|
|
7683
7675
|
return {
|
|
@@ -7694,7 +7686,7 @@ var RawRenderer = class extends Renderer {
|
|
|
7694
7686
|
createStreamSession(options, plan) {
|
|
7695
7687
|
return new RawStreamSession(options, plan);
|
|
7696
7688
|
}
|
|
7697
|
-
schema =
|
|
7689
|
+
schema = import_koishi23.Schema.const("raw").i18n({
|
|
7698
7690
|
"zh-CN": "原始输出",
|
|
7699
7691
|
"en-US": "Raw text"
|
|
7700
7692
|
});
|
|
@@ -7707,7 +7699,7 @@ var RawStreamSession = class extends BufferedRenderStreamSession {
|
|
|
7707
7699
|
super(options, plan);
|
|
7708
7700
|
}
|
|
7709
7701
|
renderText(text) {
|
|
7710
|
-
return [
|
|
7702
|
+
return [import_koishi23.h.text(text)];
|
|
7711
7703
|
}
|
|
7712
7704
|
};
|
|
7713
7705
|
|
|
@@ -7750,7 +7742,6 @@ var ReplyStream = class {
|
|
|
7750
7742
|
sentAdditional = false;
|
|
7751
7743
|
closed = false;
|
|
7752
7744
|
moderated;
|
|
7753
|
-
pending = [];
|
|
7754
7745
|
renderMessage;
|
|
7755
7746
|
renderAdditional;
|
|
7756
7747
|
async write(frame) {
|
|
@@ -7767,10 +7758,6 @@ var ReplyStream = class {
|
|
|
7767
7758
|
return;
|
|
7768
7759
|
}
|
|
7769
7760
|
if (frame.type === "mark" && frame.instant) {
|
|
7770
|
-
if (this.moderated) {
|
|
7771
|
-
this.pending.push({ content: frame.content ?? frame.name });
|
|
7772
|
-
return;
|
|
7773
|
-
}
|
|
7774
7761
|
await this.sendMessage(
|
|
7775
7762
|
{ content: frame.content ?? frame.name },
|
|
7776
7763
|
"split"
|
|
@@ -7791,26 +7778,10 @@ var ReplyStream = class {
|
|
|
7791
7778
|
if (frame != null) {
|
|
7792
7779
|
await this.write(frame);
|
|
7793
7780
|
}
|
|
7794
|
-
if (
|
|
7795
|
-
if (
|
|
7796
|
-
return;
|
|
7797
|
-
}
|
|
7798
|
-
if (this.closed) {
|
|
7799
|
-
if (frame?.type === "done") {
|
|
7800
|
-
if (this.mode === "edit") {
|
|
7801
|
-
await this.sendMessage(frame.message, "edit");
|
|
7802
|
-
} else if (this.mode === "buffer" || this.firstChunk) {
|
|
7803
|
-
await this.sendMessage(frame.message, "split");
|
|
7804
|
-
}
|
|
7805
|
-
}
|
|
7806
|
-
return await this.finish();
|
|
7807
|
-
}
|
|
7781
|
+
if (frame?.type !== "done" && frame?.type !== "error") return;
|
|
7782
|
+
if (this.closed) return;
|
|
7808
7783
|
this.closed = true;
|
|
7809
7784
|
await this.context.recallThinkingMessage?.();
|
|
7810
|
-
for (const message of this.pending) {
|
|
7811
|
-
await this.sendMessage(message, "split");
|
|
7812
|
-
}
|
|
7813
|
-
this.pending = [];
|
|
7814
7785
|
if (this.mode === "buffer") {
|
|
7815
7786
|
if (this.finalMessage != null) {
|
|
7816
7787
|
await this.sendMessage(this.finalMessage, "split");
|
|
@@ -7865,7 +7836,7 @@ var ReplyStream = class {
|
|
|
7865
7836
|
await this.context.send([elements]);
|
|
7866
7837
|
}
|
|
7867
7838
|
async censor(message) {
|
|
7868
|
-
if (!this.moderated) return message;
|
|
7839
|
+
if (!this.moderated || this.ctx.censor == null) return message;
|
|
7869
7840
|
return await censorMessage(
|
|
7870
7841
|
this.ctx,
|
|
7871
7842
|
message,
|
|
@@ -7921,7 +7892,7 @@ var ReplyQueue = class {
|
|
|
7921
7892
|
};
|
|
7922
7893
|
|
|
7923
7894
|
// src/render/voice.ts
|
|
7924
|
-
var
|
|
7895
|
+
var import_koishi24 = require("koishi");
|
|
7925
7896
|
var import_koishi_plugin_chatluna11 = require("koishi-plugin-chatluna");
|
|
7926
7897
|
var import_string16 = require("koishi-plugin-chatluna/utils/string");
|
|
7927
7898
|
var VoiceRenderer = class extends Renderer {
|
|
@@ -7941,7 +7912,7 @@ var VoiceRenderer = class extends Renderer {
|
|
|
7941
7912
|
return {
|
|
7942
7913
|
element: await Promise.all(
|
|
7943
7914
|
splitMessages.map(
|
|
7944
|
-
async (text) => (0,
|
|
7915
|
+
async (text) => (0, import_koishi24.h)("message", await this._renderToVoice(text, options))
|
|
7945
7916
|
)
|
|
7946
7917
|
)
|
|
7947
7918
|
};
|
|
@@ -7976,7 +7947,7 @@ var VoiceRenderer = class extends Renderer {
|
|
|
7976
7947
|
)
|
|
7977
7948
|
);
|
|
7978
7949
|
}
|
|
7979
|
-
schema =
|
|
7950
|
+
schema = import_koishi24.Schema.const("voice").i18n({
|
|
7980
7951
|
"zh-CN": "将回复渲染为语音",
|
|
7981
7952
|
"en-US": "Render as voice"
|
|
7982
7953
|
});
|
|
@@ -7992,7 +7963,7 @@ var VoiceStreamSession = class extends BufferedRenderStreamSession {
|
|
|
7992
7963
|
}
|
|
7993
7964
|
async renderText(text) {
|
|
7994
7965
|
return [
|
|
7995
|
-
this.options.split && this.options.split !== "none" ? (0,
|
|
7966
|
+
this.options.split && this.options.split !== "none" ? (0, import_koishi24.h)("message", await this.render(text)) : await this.render(text)
|
|
7996
7967
|
];
|
|
7997
7968
|
}
|
|
7998
7969
|
};
|
|
@@ -8030,24 +8001,12 @@ var DefaultRenderer = class {
|
|
|
8030
8001
|
renderers = {};
|
|
8031
8002
|
async render(message, options = this.defaultOptions) {
|
|
8032
8003
|
try {
|
|
8033
|
-
const result = [];
|
|
8034
8004
|
options = Object.assign({}, this.defaultOptions, options);
|
|
8035
|
-
const
|
|
8036
|
-
|
|
8037
|
-
|
|
8038
|
-
|
|
8039
|
-
|
|
8040
|
-
result.push({
|
|
8041
|
-
element: (0, import_koishi26.h)(
|
|
8042
|
-
"message",
|
|
8043
|
-
{ forward: true },
|
|
8044
|
-
Array.isArray(elements) ? elements : [elements]
|
|
8045
|
-
)
|
|
8046
|
-
});
|
|
8047
|
-
}
|
|
8048
|
-
}
|
|
8049
|
-
result.push(await currentRenderer.render(message, options));
|
|
8050
|
-
return result;
|
|
8005
|
+
const result = await this.renderAdditionalMessages(message, options);
|
|
8006
|
+
return [
|
|
8007
|
+
...result.map((element) => ({ element })),
|
|
8008
|
+
await this.getRenderer(options.type).render(message, options)
|
|
8009
|
+
];
|
|
8051
8010
|
} catch (e) {
|
|
8052
8011
|
throw new import_error9.ChatLunaError(import_error9.ChatLunaErrorCode.RENDER_ERROR, e);
|
|
8053
8012
|
}
|
|
@@ -8078,12 +8037,11 @@ var DefaultRenderer = class {
|
|
|
8078
8037
|
const rawRenderer = this.getRenderer("raw");
|
|
8079
8038
|
const result = [];
|
|
8080
8039
|
for (const msg of message.additionalReplyMessages) {
|
|
8081
|
-
const elements = await rawRenderer.render(msg, options).then((r) => r.element);
|
|
8082
8040
|
result.push([
|
|
8083
|
-
(0,
|
|
8041
|
+
(0, import_koishi25.h)(
|
|
8084
8042
|
"message",
|
|
8085
8043
|
{ forward: true },
|
|
8086
|
-
|
|
8044
|
+
(await rawRenderer.render(msg, options)).element
|
|
8087
8045
|
)
|
|
8088
8046
|
]);
|
|
8089
8047
|
}
|
|
@@ -8107,7 +8065,7 @@ var DefaultRenderer = class {
|
|
|
8107
8065
|
}
|
|
8108
8066
|
this.ctx.schema.set(
|
|
8109
8067
|
"output-mode",
|
|
8110
|
-
|
|
8068
|
+
import_koishi25.Schema.union(this._getAllRendererScheme())
|
|
8111
8069
|
);
|
|
8112
8070
|
}
|
|
8113
8071
|
_getAllRendererScheme() {
|
|
@@ -8167,7 +8125,7 @@ function setupEntryPoint(ctx, config, disposables) {
|
|
|
8167
8125
|
setupMiddleware(ctx2);
|
|
8168
8126
|
});
|
|
8169
8127
|
}, "entryPointPlugin");
|
|
8170
|
-
const entryPointDisposable = (0,
|
|
8128
|
+
const entryPointDisposable = (0, import_koishi27.forkScopeToDisposable)(
|
|
8171
8129
|
ctx.plugin(
|
|
8172
8130
|
{
|
|
8173
8131
|
apply: entryPointPlugin,
|
|
@@ -8218,7 +8176,7 @@ function setupMiddleware(ctx) {
|
|
|
8218
8176
|
__name(setupMiddleware, "setupMiddleware");
|
|
8219
8177
|
function setupLogger(config) {
|
|
8220
8178
|
if (config.isLog) {
|
|
8221
|
-
(0, import_logger7.setLoggerLevel)(
|
|
8179
|
+
(0, import_logger7.setLoggerLevel)(import_koishi26.Logger.DEBUG);
|
|
8222
8180
|
}
|
|
8223
8181
|
}
|
|
8224
8182
|
__name(setupLogger, "setupLogger");
|
|
@@ -8238,7 +8196,7 @@ function setupProxy(ctx, config) {
|
|
|
8238
8196
|
}
|
|
8239
8197
|
__name(setupProxy, "setupProxy");
|
|
8240
8198
|
function setupServices(ctx, config, disposables) {
|
|
8241
|
-
disposables.push((0,
|
|
8199
|
+
disposables.push((0, import_koishi27.forkScopeToDisposable)(ctx.plugin(import_chat2.ChatLunaService, config)));
|
|
8242
8200
|
}
|
|
8243
8201
|
__name(setupServices, "setupServices");
|
|
8244
8202
|
function setupPermissions(ctx, disposables) {
|
|
@@ -8309,7 +8267,7 @@ async function setupAutoArchive(ctx, config) {
|
|
|
8309
8267
|
await execute();
|
|
8310
8268
|
ctx.setInterval(async () => {
|
|
8311
8269
|
await execute();
|
|
8312
|
-
},
|
|
8270
|
+
}, import_koishi26.Time.minute * 5);
|
|
8313
8271
|
}
|
|
8314
8272
|
__name(setupAutoArchive, "setupAutoArchive");
|
|
8315
8273
|
async function setupAutoPurgeArchive(ctx, config) {
|
|
@@ -8372,7 +8330,7 @@ async function setupAutoPurgeArchive(ctx, config) {
|
|
|
8372
8330
|
await execute();
|
|
8373
8331
|
ctx.setInterval(async () => {
|
|
8374
8332
|
await execute();
|
|
8375
|
-
},
|
|
8333
|
+
}, import_koishi26.Time.minute * 10);
|
|
8376
8334
|
}
|
|
8377
8335
|
__name(setupAutoPurgeArchive, "setupAutoPurgeArchive");
|
|
8378
8336
|
async function dedupeConstraintNames(ctx) {
|