koishi-plugin-chatluna 1.1.2 → 1.1.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/index.cjs +179 -180
- package/lib/index.mjs +83 -84
- package/lib/llm-core/agent/index.cjs +3 -2
- package/lib/llm-core/agent/index.mjs +3 -2
- package/lib/llm-core/agent/openai/index.d.ts +1 -1
- package/lib/llm-core/agent/react/index.d.ts +2 -1
- package/lib/llm-core/chain/prompt.cjs +7 -1
- package/lib/llm-core/chain/prompt.mjs +7 -1
- package/lib/llm-core/memory/message/database_history.d.ts +1 -0
- package/lib/llm-core/memory/message/index.cjs +10 -4
- package/lib/llm-core/memory/message/index.mjs +14 -4
- package/lib/llm-core/prompt/type.d.ts +2 -0
- package/lib/middlewares/allow_reply.d.ts +3 -0
- package/lib/services/chat.cjs +14 -2
- package/lib/services/chat.mjs +14 -2
- package/lib/utils/string.cjs +29 -0
- package/lib/utils/string.d.ts +6 -0
- package/lib/utils/string.mjs +26 -0
- package/package.json +1 -1
package/lib/index.cjs
CHANGED
|
@@ -72,9 +72,9 @@ __export(index_exports, {
|
|
|
72
72
|
usage: () => usage
|
|
73
73
|
});
|
|
74
74
|
module.exports = __toCommonJS(index_exports);
|
|
75
|
-
var
|
|
75
|
+
var import_koishi20 = require("koishi");
|
|
76
76
|
var import_chat2 = require("koishi-plugin-chatluna/services/chat");
|
|
77
|
-
var
|
|
77
|
+
var import_koishi21 = require("koishi-plugin-chatluna/utils/koishi");
|
|
78
78
|
var import_logger9 = require("koishi-plugin-chatluna/utils/logger");
|
|
79
79
|
var request = __toESM(require("koishi-plugin-chatluna/utils/request"), 1);
|
|
80
80
|
|
|
@@ -518,6 +518,7 @@ function apply(ctx, config, chain) {
|
|
|
518
518
|
__name(apply, "apply");
|
|
519
519
|
|
|
520
520
|
// src/commands/chat.ts
|
|
521
|
+
var import_koishi2 = require("koishi");
|
|
521
522
|
function apply2(ctx, config, chain) {
|
|
522
523
|
ctx.command("chatluna", {
|
|
523
524
|
authority: 1
|
|
@@ -532,8 +533,9 @@ function apply2(ctx, config, chain) {
|
|
|
532
533
|
)) {
|
|
533
534
|
return session.text(".invalid-render-type");
|
|
534
535
|
}
|
|
536
|
+
const elements = import_koishi2.h.parse(message);
|
|
535
537
|
await chain.receiveCommand(session, "", {
|
|
536
|
-
message,
|
|
538
|
+
message: elements,
|
|
537
539
|
room_resolve: {
|
|
538
540
|
name: options.room
|
|
539
541
|
},
|
|
@@ -545,8 +547,9 @@ function apply2(ctx, config, chain) {
|
|
|
545
547
|
});
|
|
546
548
|
});
|
|
547
549
|
ctx.command("chatluna.chat.rollback [message:text]").option("room", "-r <room:string>").option("i", "-i <i: string>").action(async ({ options, session }, message) => {
|
|
550
|
+
const elements = import_koishi2.h.parse(message);
|
|
548
551
|
await chain.receiveCommand(session, "rollback", {
|
|
549
|
-
message,
|
|
552
|
+
message: elements,
|
|
550
553
|
room_resolve: {
|
|
551
554
|
name: options.room
|
|
552
555
|
},
|
|
@@ -566,8 +569,9 @@ function apply2(ctx, config, chain) {
|
|
|
566
569
|
});
|
|
567
570
|
});
|
|
568
571
|
ctx.command("chatluna.chat.voice <message:text>").option("room", "-r <room:string>").option("speaker", "-s <speakerId:number>", { authority: 1 }).action(async ({ options, session }, message) => {
|
|
572
|
+
const elements = import_koishi2.h.parse(message);
|
|
569
573
|
await chain.receiveCommand(session, "", {
|
|
570
|
-
message,
|
|
574
|
+
message: elements,
|
|
571
575
|
renderOptions: {
|
|
572
576
|
split: config.splitMessage,
|
|
573
577
|
type: "voice",
|
|
@@ -594,42 +598,44 @@ __name(apply2, "apply");
|
|
|
594
598
|
|
|
595
599
|
// src/commands/memory.ts
|
|
596
600
|
function apply3(ctx, config, chain) {
|
|
597
|
-
ctx.
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
601
|
+
ctx.inject(["chatluna_long_memory"], (ctx2) => {
|
|
602
|
+
ctx2.command("chatluna.memory", { authority: 1 });
|
|
603
|
+
ctx2.command("chatluna.memory.search <query:string>").option("type", "-t <type:string>").option("limit", "-l <limit:number>").option("page", "-p <page:number>").option("view", "-v <view:string>").action(async ({ options, session }, query) => {
|
|
604
|
+
await chain.receiveCommand(session, "search_memory", {
|
|
605
|
+
type: options.type,
|
|
606
|
+
page: options.page ?? 1,
|
|
607
|
+
limit: options.limit ?? 6,
|
|
608
|
+
view: options.view,
|
|
609
|
+
query
|
|
610
|
+
});
|
|
605
611
|
});
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
+
ctx2.command("chatluna.memory.delete <...ids>").option("type", "-t <type:string>").option("view", "-v <view:string>").action(async ({ session, options }, ...ids) => {
|
|
613
|
+
await chain.receiveCommand(session, "delete_memory", {
|
|
614
|
+
ids,
|
|
615
|
+
type: options.type,
|
|
616
|
+
view: options.view
|
|
617
|
+
});
|
|
612
618
|
});
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
619
|
+
ctx2.command("chatluna.memory.clear").option("type", "-t <type:string>").option("view", "-v <view:string>").action(async ({ session, options }) => {
|
|
620
|
+
await chain.receiveCommand(session, "clear_memory", {
|
|
621
|
+
type: options.type,
|
|
622
|
+
view: options.view
|
|
623
|
+
});
|
|
618
624
|
});
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
+
ctx2.command("chatluna.memory.add <content:text>").option("type", "-t <type:string>").option("view", "-v <view:string>").action(async ({ session, options }, content) => {
|
|
626
|
+
await chain.receiveCommand(session, "add_memory", {
|
|
627
|
+
type: options.type,
|
|
628
|
+
view: options.view,
|
|
629
|
+
content
|
|
630
|
+
});
|
|
625
631
|
});
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
632
|
+
ctx2.command("chatluna.memory.edit <id:string>").option("type", "-t <type:string>").option("view", "-v <view:string>").action(async ({ session, options }, id, content) => {
|
|
633
|
+
await chain.receiveCommand(session, "edit_memory", {
|
|
634
|
+
memoryId: id,
|
|
635
|
+
content,
|
|
636
|
+
type: options.type,
|
|
637
|
+
view: options.view
|
|
638
|
+
});
|
|
633
639
|
});
|
|
634
640
|
});
|
|
635
641
|
}
|
|
@@ -896,7 +902,7 @@ async function command(ctx, config) {
|
|
|
896
902
|
__name(command, "command");
|
|
897
903
|
|
|
898
904
|
// src/llm-core/chat/default.ts
|
|
899
|
-
var
|
|
905
|
+
var import_koishi3 = require("koishi");
|
|
900
906
|
var import_koishi_plugin_chatluna = require("koishi-plugin-chatluna");
|
|
901
907
|
var import_types = require("koishi-plugin-chatluna/llm-core/platform/types");
|
|
902
908
|
|
|
@@ -1043,7 +1049,10 @@ var ChatLunaPluginChain = class _ChatLunaPluginChain extends import_base2.ChatLu
|
|
|
1043
1049
|
agent: await (0, import_agent.createReactAgent)({
|
|
1044
1050
|
llm,
|
|
1045
1051
|
tools,
|
|
1046
|
-
prompt: this.prompt
|
|
1052
|
+
prompt: this.prompt,
|
|
1053
|
+
instructions: await this.preset().then((preset) => {
|
|
1054
|
+
return preset.config.reActInstruction;
|
|
1055
|
+
})
|
|
1047
1056
|
}),
|
|
1048
1057
|
tools,
|
|
1049
1058
|
memory: void 0,
|
|
@@ -1266,17 +1275,17 @@ async function defaultFactory(ctx, service) {
|
|
|
1266
1275
|
}
|
|
1267
1276
|
__name(defaultFactory, "defaultFactory");
|
|
1268
1277
|
function updateModels(ctx, service) {
|
|
1269
|
-
ctx.schema.set("model",
|
|
1278
|
+
ctx.schema.set("model", import_koishi3.Schema.union(getModelNames(service)));
|
|
1270
1279
|
}
|
|
1271
1280
|
__name(updateModels, "updateModels");
|
|
1272
1281
|
function updateChatChains(ctx, service) {
|
|
1273
|
-
ctx.schema.set("chat-mode",
|
|
1282
|
+
ctx.schema.set("chat-mode", import_koishi3.Schema.union(getChatChainNames(service)));
|
|
1274
1283
|
}
|
|
1275
1284
|
__name(updateChatChains, "updateChatChains");
|
|
1276
1285
|
function updateEmbeddings(ctx, service) {
|
|
1277
1286
|
ctx.schema.set(
|
|
1278
1287
|
"embeddings",
|
|
1279
|
-
|
|
1288
|
+
import_koishi3.Schema.union(getModelNames(service, import_types.ModelType.embeddings))
|
|
1280
1289
|
);
|
|
1281
1290
|
}
|
|
1282
1291
|
__name(updateEmbeddings, "updateEmbeddings");
|
|
@@ -1286,13 +1295,13 @@ function getVectorStoreRetrieverNames(service) {
|
|
|
1286
1295
|
__name(getVectorStoreRetrieverNames, "getVectorStoreRetrieverNames");
|
|
1287
1296
|
function updateVectorStores(ctx, service) {
|
|
1288
1297
|
const rawVectorStoreNames = getVectorStoreRetrieverNames(service);
|
|
1289
|
-
const vectorStoreRetrieverNames = rawVectorStoreNames.concat("无").map((name2) =>
|
|
1298
|
+
const vectorStoreRetrieverNames = rawVectorStoreNames.concat("无").map((name2) => import_koishi3.Schema.const(name2));
|
|
1290
1299
|
if (rawVectorStoreNames.length === 0) {
|
|
1291
|
-
ctx.schema.set("long-memory",
|
|
1300
|
+
ctx.schema.set("long-memory", import_koishi3.Schema.boolean().disabled());
|
|
1292
1301
|
} else {
|
|
1293
|
-
ctx.schema.set("long-memory",
|
|
1302
|
+
ctx.schema.set("long-memory", import_koishi3.Schema.boolean());
|
|
1294
1303
|
}
|
|
1295
|
-
ctx.schema.set("vector-store",
|
|
1304
|
+
ctx.schema.set("vector-store", import_koishi3.Schema.union(vectorStoreRetrieverNames));
|
|
1296
1305
|
}
|
|
1297
1306
|
__name(updateVectorStores, "updateVectorStores");
|
|
1298
1307
|
function getTools(service, filter) {
|
|
@@ -1301,12 +1310,12 @@ function getTools(service, filter) {
|
|
|
1301
1310
|
}
|
|
1302
1311
|
__name(getTools, "getTools");
|
|
1303
1312
|
function getChatChainNames(service) {
|
|
1304
|
-
return service.getChatChains().map((info) =>
|
|
1313
|
+
return service.getChatChains().map((info) => import_koishi3.Schema.const(info.name).i18n(info.description));
|
|
1305
1314
|
}
|
|
1306
1315
|
__name(getChatChainNames, "getChatChainNames");
|
|
1307
1316
|
function getModelNames(service, type = import_types.ModelType.llm) {
|
|
1308
1317
|
const models = service.getAllModels(type).concat("无");
|
|
1309
|
-
return models.map((model) =>
|
|
1318
|
+
return models.map((model) => import_koishi3.Schema.const(model).description(model));
|
|
1310
1319
|
}
|
|
1311
1320
|
__name(getModelNames, "getModelNames");
|
|
1312
1321
|
|
|
@@ -1504,7 +1513,7 @@ __name(apply9, "apply");
|
|
|
1504
1513
|
|
|
1505
1514
|
// src/chains/chain.ts
|
|
1506
1515
|
var import_events = require("events");
|
|
1507
|
-
var
|
|
1516
|
+
var import_koishi4 = require("koishi");
|
|
1508
1517
|
var import_error3 = require("koishi-plugin-chatluna/utils/error");
|
|
1509
1518
|
var import_logger = require("koishi-plugin-chatluna/utils/logger");
|
|
1510
1519
|
|
|
@@ -1562,7 +1571,7 @@ __name(apply11, "apply");
|
|
|
1562
1571
|
|
|
1563
1572
|
// src/chains/rooms.ts
|
|
1564
1573
|
var import_crypto = require("crypto");
|
|
1565
|
-
var
|
|
1574
|
+
var import_koishi5 = require("koishi");
|
|
1566
1575
|
var import_types2 = require("koishi-plugin-chatluna/llm-core/platform/types");
|
|
1567
1576
|
var import_count_tokens = require("koishi-plugin-chatluna/llm-core/utils/count_tokens");
|
|
1568
1577
|
var import_error4 = require("koishi-plugin-chatluna/utils/error");
|
|
@@ -1746,7 +1755,7 @@ async function getTemplateConversationRoom(ctx, config) {
|
|
|
1746
1755
|
}
|
|
1747
1756
|
__name(getTemplateConversationRoom, "getTemplateConversationRoom");
|
|
1748
1757
|
async function getConversationRoomCount(ctx) {
|
|
1749
|
-
const count = await ctx.database.select("chathub_room").execute((row) =>
|
|
1758
|
+
const count = await ctx.database.select("chathub_room").execute((row) => import_koishi5.$.max(row.roomId));
|
|
1750
1759
|
return count;
|
|
1751
1760
|
}
|
|
1752
1761
|
__name(getConversationRoomCount, "getConversationRoomCount");
|
|
@@ -2076,9 +2085,12 @@ function apply12(ctx, config, chain) {
|
|
|
2076
2085
|
__name(apply12, "apply");
|
|
2077
2086
|
|
|
2078
2087
|
// src/middlewares/allow_reply.ts
|
|
2088
|
+
var import_koishi6 = require("koishi");
|
|
2079
2089
|
function apply13(ctx, config, chain) {
|
|
2080
2090
|
chain.middleware("allow_reply", async (session, context) => {
|
|
2081
2091
|
if (ctx.bots[session.uid]) return 1 /* STOP */;
|
|
2092
|
+
context.options.reply_status = false;
|
|
2093
|
+
const content = import_koishi6.h.select(session.elements, "text").join("");
|
|
2082
2094
|
if (session.isDirect && config.allowPrivate && (context.command != null || config.privateChatWithoutCommand)) {
|
|
2083
2095
|
return await checkReplyPermission();
|
|
2084
2096
|
}
|
|
@@ -2098,21 +2110,17 @@ function apply13(ctx, config, chain) {
|
|
|
2098
2110
|
if (config.allowQuoteReply && session.quote?.user?.id === botId) {
|
|
2099
2111
|
return await checkReplyPermission();
|
|
2100
2112
|
}
|
|
2101
|
-
if (config.botNames.some(
|
|
2102
|
-
(name2) => session.content.startsWith(name2)
|
|
2103
|
-
) && config.isNickname || config.isNickNameWithContent && config.botNames.some(
|
|
2104
|
-
(name2) => session.content.includes(name2)
|
|
2105
|
-
)) {
|
|
2113
|
+
if (config.botNames.some((name2) => content.startsWith(name2)) && config.isNickname || config.isNickNameWithContent && config.botNames.some((name2) => content.includes(name2))) {
|
|
2106
2114
|
return await checkReplyPermission();
|
|
2107
2115
|
}
|
|
2108
2116
|
if (Math.random() < await session.resolve(config.randomReplyFrequency)) {
|
|
2109
2117
|
return await checkReplyPermission();
|
|
2110
2118
|
}
|
|
2111
|
-
if (config.allowChatWithRoomName) {
|
|
2112
|
-
return await checkReplyPermission();
|
|
2113
|
-
}
|
|
2114
2119
|
if (context.command != null) {
|
|
2115
|
-
return
|
|
2120
|
+
return 2 /* CONTINUE */;
|
|
2121
|
+
}
|
|
2122
|
+
if (config.allowChatWithRoomName) {
|
|
2123
|
+
return 2 /* CONTINUE */;
|
|
2116
2124
|
}
|
|
2117
2125
|
return 1 /* STOP */;
|
|
2118
2126
|
async function checkReplyPermission() {
|
|
@@ -2120,7 +2128,9 @@ function apply13(ctx, config, chain) {
|
|
|
2120
2128
|
"chatluna/before-check-sender",
|
|
2121
2129
|
session
|
|
2122
2130
|
);
|
|
2123
|
-
|
|
2131
|
+
const status = notReply ? 1 /* STOP */ : 2 /* CONTINUE */;
|
|
2132
|
+
context.options.reply_status = status === 2 /* CONTINUE */;
|
|
2133
|
+
return status;
|
|
2124
2134
|
}
|
|
2125
2135
|
__name(checkReplyPermission, "checkReplyPermission");
|
|
2126
2136
|
}).after("lifecycle-check");
|
|
@@ -2166,7 +2176,7 @@ var import_count_tokens2 = require("koishi-plugin-chatluna/llm-core/utils/count_
|
|
|
2166
2176
|
var import_error5 = require("koishi-plugin-chatluna/utils/error");
|
|
2167
2177
|
|
|
2168
2178
|
// src/cache.ts
|
|
2169
|
-
var
|
|
2179
|
+
var import_koishi7 = require("koishi");
|
|
2170
2180
|
var Cache = class {
|
|
2171
2181
|
constructor(ctx, config, tableName) {
|
|
2172
2182
|
this.config = config;
|
|
@@ -2220,7 +2230,7 @@ var DatabaseCache = class {
|
|
|
2220
2230
|
);
|
|
2221
2231
|
ctx.setInterval(async () => {
|
|
2222
2232
|
await ctx.database.remove("cache", { expire: { $lt: /* @__PURE__ */ new Date() } });
|
|
2223
|
-
}, 10 *
|
|
2233
|
+
}, 10 * import_koishi7.Time.minute);
|
|
2224
2234
|
}
|
|
2225
2235
|
static {
|
|
2226
2236
|
__name(this, "DatabaseCache");
|
|
@@ -3838,13 +3848,13 @@ function apply40(ctx, config, chain) {
|
|
|
3838
3848
|
__name(apply40, "apply");
|
|
3839
3849
|
|
|
3840
3850
|
// src/middlewares/read_chat_message.ts
|
|
3841
|
-
var
|
|
3851
|
+
var import_koishi8 = require("koishi");
|
|
3842
3852
|
function apply41(ctx, config, chain) {
|
|
3843
3853
|
chain.middleware("read_chat_message", async (session, context) => {
|
|
3844
3854
|
let message = context.command != null ? context.message : session.elements;
|
|
3845
3855
|
message = message;
|
|
3846
3856
|
if (typeof message === "string") {
|
|
3847
|
-
message = [
|
|
3857
|
+
message = [import_koishi8.h.text(message)];
|
|
3848
3858
|
}
|
|
3849
3859
|
const transformedMessage = await ctx.chatluna.messageTransformer.transform(
|
|
3850
3860
|
session,
|
|
@@ -3958,7 +3968,7 @@ async function renderMessage(ctx, message, options) {
|
|
|
3958
3968
|
__name(renderMessage, "renderMessage");
|
|
3959
3969
|
|
|
3960
3970
|
// src/middlewares/request_model.ts
|
|
3961
|
-
var
|
|
3971
|
+
var import_koishi10 = require("koishi");
|
|
3962
3972
|
var import_prompt3 = require("koishi-plugin-chatluna/llm-core/prompt");
|
|
3963
3973
|
var import_count_tokens3 = require("koishi-plugin-chatluna/llm-core/utils/count_tokens");
|
|
3964
3974
|
var import_error6 = require("koishi-plugin-chatluna/utils/error");
|
|
@@ -3967,7 +3977,7 @@ var import_chains = require("koishi-plugin-chatluna/chains");
|
|
|
3967
3977
|
var import_string = require("koishi-plugin-chatluna/utils/string");
|
|
3968
3978
|
|
|
3969
3979
|
// src/utils/buffer_text.ts
|
|
3970
|
-
var
|
|
3980
|
+
var import_koishi9 = require("koishi");
|
|
3971
3981
|
var import_lock2 = require("koishi-plugin-chatluna/utils/lock");
|
|
3972
3982
|
var BufferText = class {
|
|
3973
3983
|
constructor(sleepTime = 3, prefix, postfix) {
|
|
@@ -3997,7 +4007,7 @@ var BufferText = class {
|
|
|
3997
4007
|
while (this.queue.length > 0 || !this.isEnd) {
|
|
3998
4008
|
const text = await this.processChar();
|
|
3999
4009
|
if (text == null) {
|
|
4000
|
-
await (0,
|
|
4010
|
+
await (0, import_koishi9.sleep)(this.sleepTime);
|
|
4001
4011
|
continue;
|
|
4002
4012
|
}
|
|
4003
4013
|
this.rawText += text;
|
|
@@ -4012,7 +4022,7 @@ var BufferText = class {
|
|
|
4012
4022
|
const text = this.queue.shift();
|
|
4013
4023
|
unlock();
|
|
4014
4024
|
if (!this.isEnd) {
|
|
4015
|
-
await (0,
|
|
4025
|
+
await (0, import_koishi9.sleep)(this.sleepTime);
|
|
4016
4026
|
}
|
|
4017
4027
|
return text;
|
|
4018
4028
|
}
|
|
@@ -4259,7 +4269,7 @@ async function handleEditMessage(context, session, config, bufferText, sendMessa
|
|
|
4259
4269
|
while (!isFinished) {
|
|
4260
4270
|
const firstQueue = queue.shift();
|
|
4261
4271
|
if (firstQueue == null) {
|
|
4262
|
-
await (0,
|
|
4272
|
+
await (0, import_koishi10.sleep)(2);
|
|
4263
4273
|
continue;
|
|
4264
4274
|
}
|
|
4265
4275
|
await editMessage(firstQueue);
|
|
@@ -4395,7 +4405,7 @@ function apply44(ctx, config, chain) {
|
|
|
4395
4405
|
__name(apply44, "apply");
|
|
4396
4406
|
|
|
4397
4407
|
// src/middlewares/resolve_room.ts
|
|
4398
|
-
var
|
|
4408
|
+
var import_koishi11 = require("koishi");
|
|
4399
4409
|
var import_uuid2 = require("uuid");
|
|
4400
4410
|
var import_logger6 = require("koishi-plugin-chatluna/utils/logger");
|
|
4401
4411
|
var logger8;
|
|
@@ -4408,21 +4418,10 @@ function apply45(ctx, config, chain) {
|
|
|
4408
4418
|
context.options?.room_resolve?.name
|
|
4409
4419
|
);
|
|
4410
4420
|
if (config.allowChatWithRoomName) {
|
|
4411
|
-
const needContinue =
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
|
|
4415
|
-
config.botNames.some(
|
|
4416
|
-
(name2) => session.content.startsWith(name2)
|
|
4417
|
-
) && config.isNickname || config.isNickNameWithContent && config.botNames.some(
|
|
4418
|
-
(name2) => session.content.includes(name2)
|
|
4419
|
-
) ? true : (
|
|
4420
|
-
// 命令
|
|
4421
|
-
context.command != null
|
|
4422
|
-
)
|
|
4423
|
-
)
|
|
4424
|
-
);
|
|
4425
|
-
const splitContent = context.message.split(" ");
|
|
4421
|
+
const needContinue = context.command == null;
|
|
4422
|
+
const rawMessageContent = context.message;
|
|
4423
|
+
const messageContent = typeof rawMessageContent === "string" ? rawMessageContent : import_koishi11.h.select(rawMessageContent, "text").join("");
|
|
4424
|
+
const splitContent = messageContent.split(" ");
|
|
4426
4425
|
let matchedRoom;
|
|
4427
4426
|
if (splitContent.length > 1) {
|
|
4428
4427
|
matchedRoom = await queryJoinedConversationRoom(
|
|
@@ -4438,7 +4437,7 @@ function apply45(ctx, config, chain) {
|
|
|
4438
4437
|
joinRoom = matchedRoom;
|
|
4439
4438
|
context.options.inputMessage = await ctx.chatluna.messageTransformer.transform(
|
|
4440
4439
|
session,
|
|
4441
|
-
[
|
|
4440
|
+
[import_koishi11.h.text(splitContent.concat(" "))]
|
|
4442
4441
|
);
|
|
4443
4442
|
}
|
|
4444
4443
|
}
|
|
@@ -4580,7 +4579,7 @@ function apply46(ctx, config, chain) {
|
|
|
4580
4579
|
__name(apply46, "apply");
|
|
4581
4580
|
|
|
4582
4581
|
// src/middlewares/rollback_chat.ts
|
|
4583
|
-
var
|
|
4582
|
+
var import_koishi12 = require("koishi");
|
|
4584
4583
|
function apply47(ctx, config, chain) {
|
|
4585
4584
|
chain.middleware("rollback_chat", async (session, context) => {
|
|
4586
4585
|
const { command: command2 } = context;
|
|
@@ -4640,7 +4639,7 @@ function apply47(ctx, config, chain) {
|
|
|
4640
4639
|
]);
|
|
4641
4640
|
if ((context.options.message?.length ?? 0) < 1) {
|
|
4642
4641
|
context.options.inputMessage = await ctx.chatluna.messageTransformer.transform(session, [
|
|
4643
|
-
|
|
4642
|
+
import_koishi12.h.text(humanMessage.text)
|
|
4644
4643
|
]);
|
|
4645
4644
|
}
|
|
4646
4645
|
await ctx.database.remove("chathub_message", {
|
|
@@ -5905,84 +5904,84 @@ __name(middleware, "middleware");
|
|
|
5905
5904
|
var import_chains2 = require("koishi-plugin-chatluna/chains");
|
|
5906
5905
|
|
|
5907
5906
|
// src/config.ts
|
|
5908
|
-
var
|
|
5909
|
-
var Config2 =
|
|
5910
|
-
|
|
5911
|
-
botNames:
|
|
5912
|
-
isNickname:
|
|
5913
|
-
isNickNameWithContent:
|
|
5907
|
+
var import_koishi13 = require("koishi");
|
|
5908
|
+
var Config2 = import_koishi13.Schema.intersect([
|
|
5909
|
+
import_koishi13.Schema.object({
|
|
5910
|
+
botNames: import_koishi13.Schema.array(import_koishi13.Schema.string()).default(["香草"]),
|
|
5911
|
+
isNickname: import_koishi13.Schema.boolean().default(true),
|
|
5912
|
+
isNickNameWithContent: import_koishi13.Schema.boolean().default(false)
|
|
5914
5913
|
}),
|
|
5915
|
-
|
|
5916
|
-
allowPrivate:
|
|
5917
|
-
allowAtReply:
|
|
5918
|
-
allowQuoteReply:
|
|
5919
|
-
isReplyWithAt:
|
|
5920
|
-
isForwardMsg:
|
|
5921
|
-
privateChatWithoutCommand:
|
|
5922
|
-
allowChatWithRoomName:
|
|
5923
|
-
includeQuoteReply:
|
|
5924
|
-
randomReplyFrequency:
|
|
5914
|
+
import_koishi13.Schema.object({
|
|
5915
|
+
allowPrivate: import_koishi13.Schema.boolean().default(true),
|
|
5916
|
+
allowAtReply: import_koishi13.Schema.boolean().default(true),
|
|
5917
|
+
allowQuoteReply: import_koishi13.Schema.boolean().default(false),
|
|
5918
|
+
isReplyWithAt: import_koishi13.Schema.boolean().default(false),
|
|
5919
|
+
isForwardMsg: import_koishi13.Schema.boolean().default(false),
|
|
5920
|
+
privateChatWithoutCommand: import_koishi13.Schema.boolean().default(true),
|
|
5921
|
+
allowChatWithRoomName: import_koishi13.Schema.boolean().default(false),
|
|
5922
|
+
includeQuoteReply: import_koishi13.Schema.boolean().default(true),
|
|
5923
|
+
randomReplyFrequency: import_koishi13.Schema.percent().min(0).max(1).step(0.01).default(0).computed()
|
|
5925
5924
|
}),
|
|
5926
|
-
|
|
5927
|
-
sendThinkingMessage:
|
|
5928
|
-
sendThinkingMessageTimeout:
|
|
5929
|
-
msgCooldown:
|
|
5930
|
-
messageDelay:
|
|
5931
|
-
showThoughtMessage:
|
|
5925
|
+
import_koishi13.Schema.object({
|
|
5926
|
+
sendThinkingMessage: import_koishi13.Schema.boolean().default(true),
|
|
5927
|
+
sendThinkingMessageTimeout: import_koishi13.Schema.number().default(15e3),
|
|
5928
|
+
msgCooldown: import_koishi13.Schema.number().min(0).max(3600).step(1).default(0),
|
|
5929
|
+
messageDelay: import_koishi13.Schema.number().min(0).max(60 * import_koishi13.Time.second).step(1).default(0),
|
|
5930
|
+
showThoughtMessage: import_koishi13.Schema.boolean().default(false)
|
|
5932
5931
|
}),
|
|
5933
|
-
|
|
5934
|
-
outputMode:
|
|
5935
|
-
splitMessage:
|
|
5936
|
-
censor:
|
|
5937
|
-
rawOnCensor:
|
|
5938
|
-
streamResponse:
|
|
5932
|
+
import_koishi13.Schema.object({
|
|
5933
|
+
outputMode: import_koishi13.Schema.dynamic("output-mode").default("text"),
|
|
5934
|
+
splitMessage: import_koishi13.Schema.boolean().default(false),
|
|
5935
|
+
censor: import_koishi13.Schema.boolean().default(false),
|
|
5936
|
+
rawOnCensor: import_koishi13.Schema.boolean().default(false),
|
|
5937
|
+
streamResponse: import_koishi13.Schema.boolean().default(false)
|
|
5939
5938
|
}),
|
|
5940
|
-
|
|
5941
|
-
blackList:
|
|
5939
|
+
import_koishi13.Schema.object({
|
|
5940
|
+
blackList: import_koishi13.Schema.boolean().computed().default(false)
|
|
5942
5941
|
}),
|
|
5943
|
-
|
|
5944
|
-
messageCount:
|
|
5945
|
-
autoDelete:
|
|
5946
|
-
autoDeleteTimeout:
|
|
5942
|
+
import_koishi13.Schema.object({
|
|
5943
|
+
messageCount: import_koishi13.Schema.number().role("slider").min(2).max(100).step(1).default(40),
|
|
5944
|
+
autoDelete: import_koishi13.Schema.boolean().default(false),
|
|
5945
|
+
autoDeleteTimeout: import_koishi13.Schema.number().default(import_koishi13.Time.day * 10 / import_koishi13.Time.second).min(import_koishi13.Time.hour / import_koishi13.Time.second)
|
|
5947
5946
|
}),
|
|
5948
|
-
|
|
5949
|
-
defaultEmbeddings:
|
|
5950
|
-
defaultVectorStore:
|
|
5947
|
+
import_koishi13.Schema.object({
|
|
5948
|
+
defaultEmbeddings: import_koishi13.Schema.dynamic("embeddings").default("无"),
|
|
5949
|
+
defaultVectorStore: import_koishi13.Schema.dynamic("vector-store").default("无")
|
|
5951
5950
|
}),
|
|
5952
|
-
|
|
5953
|
-
autoCreateRoomFromUser:
|
|
5954
|
-
defaultChatMode:
|
|
5955
|
-
defaultModel:
|
|
5956
|
-
defaultPreset:
|
|
5957
|
-
autoUpdateRoomMode:
|
|
5958
|
-
|
|
5959
|
-
|
|
5960
|
-
|
|
5951
|
+
import_koishi13.Schema.object({
|
|
5952
|
+
autoCreateRoomFromUser: import_koishi13.Schema.boolean().default(false),
|
|
5953
|
+
defaultChatMode: import_koishi13.Schema.dynamic("chat-mode").default("chat"),
|
|
5954
|
+
defaultModel: import_koishi13.Schema.dynamic("model").default("无"),
|
|
5955
|
+
defaultPreset: import_koishi13.Schema.dynamic("preset").default("chatgpt"),
|
|
5956
|
+
autoUpdateRoomMode: import_koishi13.Schema.union([
|
|
5957
|
+
import_koishi13.Schema.const("all"),
|
|
5958
|
+
import_koishi13.Schema.const("manual"),
|
|
5959
|
+
import_koishi13.Schema.const("disable")
|
|
5961
5960
|
]).default("manual")
|
|
5962
5961
|
}),
|
|
5963
|
-
|
|
5964
|
-
authSystem:
|
|
5965
|
-
isProxy:
|
|
5966
|
-
voiceSpeakId:
|
|
5967
|
-
isLog:
|
|
5962
|
+
import_koishi13.Schema.object({
|
|
5963
|
+
authSystem: import_koishi13.Schema.boolean().experimental().hidden().default(false),
|
|
5964
|
+
isProxy: import_koishi13.Schema.boolean().default(false),
|
|
5965
|
+
voiceSpeakId: import_koishi13.Schema.number().default(0),
|
|
5966
|
+
isLog: import_koishi13.Schema.boolean().default(false)
|
|
5968
5967
|
}),
|
|
5969
|
-
|
|
5970
|
-
|
|
5971
|
-
isProxy:
|
|
5972
|
-
proxyAddress:
|
|
5968
|
+
import_koishi13.Schema.union([
|
|
5969
|
+
import_koishi13.Schema.object({
|
|
5970
|
+
isProxy: import_koishi13.Schema.const(true).required(),
|
|
5971
|
+
proxyAddress: import_koishi13.Schema.string().default("")
|
|
5973
5972
|
}),
|
|
5974
|
-
|
|
5973
|
+
import_koishi13.Schema.object({})
|
|
5975
5974
|
]),
|
|
5976
|
-
|
|
5977
|
-
|
|
5978
|
-
authSystem:
|
|
5979
|
-
authUserDefaultGroup:
|
|
5980
|
-
|
|
5981
|
-
|
|
5982
|
-
|
|
5975
|
+
import_koishi13.Schema.union([
|
|
5976
|
+
import_koishi13.Schema.object({
|
|
5977
|
+
authSystem: import_koishi13.Schema.const(true).required(),
|
|
5978
|
+
authUserDefaultGroup: import_koishi13.Schema.tuple([
|
|
5979
|
+
import_koishi13.Schema.number().default(0),
|
|
5980
|
+
import_koishi13.Schema.number().default(1),
|
|
5981
|
+
import_koishi13.Schema.string().default("guest")
|
|
5983
5982
|
]).computed().default([0, 1, "guest"])
|
|
5984
5983
|
}),
|
|
5985
|
-
|
|
5984
|
+
import_koishi13.Schema.object({})
|
|
5986
5985
|
])
|
|
5987
5986
|
]).i18n({
|
|
5988
5987
|
"zh-CN": require_zh_CN_schema(),
|
|
@@ -5990,7 +5989,7 @@ var Config2 = import_koishi11.Schema.intersect([
|
|
|
5990
5989
|
});
|
|
5991
5990
|
|
|
5992
5991
|
// src/render.ts
|
|
5993
|
-
var
|
|
5992
|
+
var import_koishi19 = require("koishi");
|
|
5994
5993
|
var import_error7 = require("koishi-plugin-chatluna/utils/error");
|
|
5995
5994
|
|
|
5996
5995
|
// src/renders/default.ts
|
|
@@ -6005,7 +6004,7 @@ var Renderer = class {
|
|
|
6005
6004
|
|
|
6006
6005
|
// src/renders/text.ts
|
|
6007
6006
|
var import_koishi_plugin_markdown = require("koishi-plugin-markdown");
|
|
6008
|
-
var
|
|
6007
|
+
var import_koishi14 = require("koishi");
|
|
6009
6008
|
var import_he = __toESM(require("he"), 1);
|
|
6010
6009
|
var TextRenderer = class extends Renderer {
|
|
6011
6010
|
static {
|
|
@@ -6015,14 +6014,14 @@ var TextRenderer = class extends Renderer {
|
|
|
6015
6014
|
let transformed = transformAndEscape(message.content);
|
|
6016
6015
|
if (options.split) {
|
|
6017
6016
|
transformed = transformed.map((element) => {
|
|
6018
|
-
return (0,
|
|
6017
|
+
return (0, import_koishi14.h)("message", element);
|
|
6019
6018
|
});
|
|
6020
6019
|
}
|
|
6021
|
-
if (transformed[0]
|
|
6020
|
+
if (transformed[0]?.type === "p") {
|
|
6022
6021
|
const pElement = transformed.shift();
|
|
6023
6022
|
const pElementContent = pElement.attrs["content"];
|
|
6024
6023
|
if (pElementContent) {
|
|
6025
|
-
transformed.unshift(
|
|
6024
|
+
transformed.unshift(import_koishi14.h.text(pElementContent));
|
|
6026
6025
|
} else {
|
|
6027
6026
|
transformed.unshift(...pElement.children);
|
|
6028
6027
|
}
|
|
@@ -6031,7 +6030,7 @@ var TextRenderer = class extends Renderer {
|
|
|
6031
6030
|
element: transformed
|
|
6032
6031
|
};
|
|
6033
6032
|
}
|
|
6034
|
-
schema =
|
|
6033
|
+
schema = import_koishi14.Schema.const("text").i18n({
|
|
6035
6034
|
"zh-CN": "将回复作为 markdown 进行渲染",
|
|
6036
6035
|
"en-US": "Render as markdown"
|
|
6037
6036
|
});
|
|
@@ -6055,7 +6054,7 @@ __name(transformAndEscape, "transformAndEscape");
|
|
|
6055
6054
|
// src/renders/voice.ts
|
|
6056
6055
|
var import_marked = require("marked");
|
|
6057
6056
|
var import_koishi_plugin_chatluna3 = require("koishi-plugin-chatluna");
|
|
6058
|
-
var
|
|
6057
|
+
var import_koishi15 = require("koishi");
|
|
6059
6058
|
var VoiceRenderer = class extends Renderer {
|
|
6060
6059
|
static {
|
|
6061
6060
|
__name(this, "VoiceRenderer");
|
|
@@ -6067,7 +6066,7 @@ var VoiceRenderer = class extends Renderer {
|
|
|
6067
6066
|
return {
|
|
6068
6067
|
element: await Promise.all(
|
|
6069
6068
|
splitMessages.map(async (text) => {
|
|
6070
|
-
return (0,
|
|
6069
|
+
return (0, import_koishi15.h)(
|
|
6071
6070
|
"message",
|
|
6072
6071
|
await this._renderToVoice(text, options)
|
|
6073
6072
|
);
|
|
@@ -6103,7 +6102,7 @@ var VoiceRenderer = class extends Renderer {
|
|
|
6103
6102
|
)
|
|
6104
6103
|
);
|
|
6105
6104
|
}
|
|
6106
|
-
schema =
|
|
6105
|
+
schema = import_koishi15.Schema.const("voice").i18n({
|
|
6107
6106
|
"zh-CN": "将回复渲染为语音",
|
|
6108
6107
|
"en-US": "Render as voice"
|
|
6109
6108
|
});
|
|
@@ -6122,24 +6121,24 @@ function renderTokens(tokens) {
|
|
|
6122
6121
|
__name(renderTokens, "renderTokens");
|
|
6123
6122
|
|
|
6124
6123
|
// src/renders/raw.ts
|
|
6125
|
-
var
|
|
6124
|
+
var import_koishi16 = require("koishi");
|
|
6126
6125
|
var RawRenderer = class extends Renderer {
|
|
6127
6126
|
static {
|
|
6128
6127
|
__name(this, "RawRenderer");
|
|
6129
6128
|
}
|
|
6130
6129
|
async render(message, options) {
|
|
6131
6130
|
return {
|
|
6132
|
-
element:
|
|
6131
|
+
element: import_koishi16.h.text(message.content)
|
|
6133
6132
|
};
|
|
6134
6133
|
}
|
|
6135
|
-
schema =
|
|
6134
|
+
schema = import_koishi16.Schema.const("raw").i18n({
|
|
6136
6135
|
"zh-CN": "原始输出",
|
|
6137
6136
|
"en-US": "Raw text"
|
|
6138
6137
|
});
|
|
6139
6138
|
};
|
|
6140
6139
|
|
|
6141
6140
|
// src/renders/koishi-element.ts
|
|
6142
|
-
var
|
|
6141
|
+
var import_koishi17 = require("koishi");
|
|
6143
6142
|
var import_he2 = __toESM(require("he"), 1);
|
|
6144
6143
|
var import_koishi_plugin_chatluna4 = require("koishi-plugin-chatluna");
|
|
6145
6144
|
var KoishiElementRenderer = class extends Renderer {
|
|
@@ -6150,14 +6149,14 @@ var KoishiElementRenderer = class extends Renderer {
|
|
|
6150
6149
|
let transformed = transformAndEscape2(message.content);
|
|
6151
6150
|
if (options.split) {
|
|
6152
6151
|
transformed = transformed.map((element) => {
|
|
6153
|
-
return (0,
|
|
6152
|
+
return (0, import_koishi17.h)("message", element);
|
|
6154
6153
|
});
|
|
6155
6154
|
}
|
|
6156
6155
|
return {
|
|
6157
6156
|
element: transformed
|
|
6158
6157
|
};
|
|
6159
6158
|
}
|
|
6160
|
-
schema =
|
|
6159
|
+
schema = import_koishi17.Schema.const("koishi-element").i18n({
|
|
6161
6160
|
"zh-CN": "将回复作为 koishi 消息元素进行渲染",
|
|
6162
6161
|
"en-US": "Render as koishi message element template"
|
|
6163
6162
|
});
|
|
@@ -6174,10 +6173,10 @@ function unescape2(element) {
|
|
|
6174
6173
|
__name(unescape2, "unescape");
|
|
6175
6174
|
function transformAndEscape2(source) {
|
|
6176
6175
|
try {
|
|
6177
|
-
return
|
|
6176
|
+
return import_koishi17.h.parse(source).map(unescape2);
|
|
6178
6177
|
} catch (e) {
|
|
6179
6178
|
import_koishi_plugin_chatluna4.logger.error(e);
|
|
6180
|
-
return [
|
|
6179
|
+
return [import_koishi17.h.text(source)];
|
|
6181
6180
|
}
|
|
6182
6181
|
}
|
|
6183
6182
|
__name(transformAndEscape2, "transformAndEscape");
|
|
@@ -6185,7 +6184,7 @@ __name(transformAndEscape2, "transformAndEscape");
|
|
|
6185
6184
|
// src/renders/mixed-voice.ts
|
|
6186
6185
|
var import_marked2 = require("marked");
|
|
6187
6186
|
var import_koishi_plugin_chatluna5 = require("koishi-plugin-chatluna");
|
|
6188
|
-
var
|
|
6187
|
+
var import_koishi18 = require("koishi");
|
|
6189
6188
|
var MixedVoiceRenderer = class extends Renderer {
|
|
6190
6189
|
static {
|
|
6191
6190
|
__name(this, "MixedVoiceRenderer");
|
|
@@ -6212,7 +6211,7 @@ var MixedVoiceRenderer = class extends Renderer {
|
|
|
6212
6211
|
let transformed = transformAndEscape(message.content);
|
|
6213
6212
|
if (options.split) {
|
|
6214
6213
|
transformed = transformed.map((element) => {
|
|
6215
|
-
return (0,
|
|
6214
|
+
return (0, import_koishi18.h)("message", element);
|
|
6216
6215
|
});
|
|
6217
6216
|
}
|
|
6218
6217
|
return {
|
|
@@ -6246,7 +6245,7 @@ var MixedVoiceRenderer = class extends Renderer {
|
|
|
6246
6245
|
)
|
|
6247
6246
|
);
|
|
6248
6247
|
}
|
|
6249
|
-
schema =
|
|
6248
|
+
schema = import_koishi18.Schema.const("mixed-voice").i18n({
|
|
6250
6249
|
"zh-CN": "同时输出语音和文本",
|
|
6251
6250
|
"en-US": "Output both voice and text"
|
|
6252
6251
|
});
|
|
@@ -6301,7 +6300,7 @@ var DefaultRenderer = class {
|
|
|
6301
6300
|
for (const additionalMessage of message.additionalReplyMessages) {
|
|
6302
6301
|
const elements = await rawRenderer.render(additionalMessage, options).then((r) => r.element);
|
|
6303
6302
|
result2.push({
|
|
6304
|
-
element: (0,
|
|
6303
|
+
element: (0, import_koishi19.h)(
|
|
6305
6304
|
"message",
|
|
6306
6305
|
{ forward: true },
|
|
6307
6306
|
Array.isArray(elements) ? elements : [elements]
|
|
@@ -6333,7 +6332,7 @@ var DefaultRenderer = class {
|
|
|
6333
6332
|
}
|
|
6334
6333
|
this.ctx.schema.set(
|
|
6335
6334
|
"output-mode",
|
|
6336
|
-
|
|
6335
|
+
import_koishi19.Schema.union(this._getAllRendererScheme())
|
|
6337
6336
|
);
|
|
6338
6337
|
}
|
|
6339
6338
|
_getAllRendererScheme() {
|
|
@@ -6390,7 +6389,7 @@ async function setupEntryPoint(ctx, config, disposables) {
|
|
|
6390
6389
|
});
|
|
6391
6390
|
setupMiddleware(ctx2);
|
|
6392
6391
|
}, "entryPointPlugin");
|
|
6393
|
-
const entryPointDisposable = (0,
|
|
6392
|
+
const entryPointDisposable = (0, import_koishi21.forkScopeToDisposable)(
|
|
6394
6393
|
ctx.plugin(
|
|
6395
6394
|
{
|
|
6396
6395
|
apply: entryPointPlugin,
|
|
@@ -6437,7 +6436,7 @@ function setupMiddleware(ctx) {
|
|
|
6437
6436
|
__name(setupMiddleware, "setupMiddleware");
|
|
6438
6437
|
function setupLogger(config) {
|
|
6439
6438
|
if (config.isLog) {
|
|
6440
|
-
(0, import_logger9.setLoggerLevel)(
|
|
6439
|
+
(0, import_logger9.setLoggerLevel)(import_koishi20.Logger.DEBUG);
|
|
6441
6440
|
}
|
|
6442
6441
|
}
|
|
6443
6442
|
__name(setupLogger, "setupLogger");
|
|
@@ -6462,8 +6461,8 @@ function setupProxy(ctx, config) {
|
|
|
6462
6461
|
__name(setupProxy, "setupProxy");
|
|
6463
6462
|
async function setupServices(ctx, config, disposables) {
|
|
6464
6463
|
disposables.push(
|
|
6465
|
-
(0,
|
|
6466
|
-
(0,
|
|
6464
|
+
(0, import_koishi21.forkScopeToDisposable)(ctx.plugin(import_chat2.ChatLunaService, config)),
|
|
6465
|
+
(0, import_koishi21.forkScopeToDisposable)(ctx.plugin(ChatLunaAuthService, config))
|
|
6467
6466
|
);
|
|
6468
6467
|
}
|
|
6469
6468
|
__name(setupServices, "setupServices");
|
|
@@ -6523,7 +6522,7 @@ async function setupAutoDelete(ctx, config) {
|
|
|
6523
6522
|
await execute();
|
|
6524
6523
|
ctx.setInterval(async () => {
|
|
6525
6524
|
await execute();
|
|
6526
|
-
},
|
|
6525
|
+
}, import_koishi20.Time.minute * 5);
|
|
6527
6526
|
}
|
|
6528
6527
|
__name(setupAutoDelete, "setupAutoDelete");
|
|
6529
6528
|
// Annotate the CommonJS export names for ESM import in node:
|