koishi-plugin-chatluna 1.1.3 → 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/chains/chain.d.ts +1 -1
- package/lib/index.cjs +144 -147
- package/lib/index.mjs +48 -51
- package/lib/llm-core/agent/index.cjs +3 -2
- package/lib/llm-core/agent/index.mjs +3 -2
- package/lib/llm-core/agent/react/index.d.ts +2 -1
- package/lib/llm-core/prompt/type.d.ts +2 -0
- package/lib/middlewares/allow_reply.d.ts +3 -0
- package/package.json +1 -1
package/lib/chains/chain.d.ts
CHANGED
|
@@ -43,7 +43,7 @@ export declare class ChainMiddleware {
|
|
|
43
43
|
constructor(name: string, execute: ChainMiddlewareFunction, graph: ChatChainDependencyGraph);
|
|
44
44
|
before<T extends keyof ChainMiddlewareName>(name: T): this;
|
|
45
45
|
after<T extends keyof ChainMiddlewareName>(name: T): this;
|
|
46
|
-
run(session: Session, options: ChainMiddlewareContext): Promise<string | h[] | h[][]
|
|
46
|
+
run(session: Session, options: ChainMiddlewareContext): Promise<string | h[] | ChainMiddlewareRunStatus | h[][]>;
|
|
47
47
|
}
|
|
48
48
|
export interface ChainMiddlewareContext {
|
|
49
49
|
config: Config;
|
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",
|
|
@@ -898,7 +902,7 @@ async function command(ctx, config) {
|
|
|
898
902
|
__name(command, "command");
|
|
899
903
|
|
|
900
904
|
// src/llm-core/chat/default.ts
|
|
901
|
-
var
|
|
905
|
+
var import_koishi3 = require("koishi");
|
|
902
906
|
var import_koishi_plugin_chatluna = require("koishi-plugin-chatluna");
|
|
903
907
|
var import_types = require("koishi-plugin-chatluna/llm-core/platform/types");
|
|
904
908
|
|
|
@@ -1045,7 +1049,10 @@ var ChatLunaPluginChain = class _ChatLunaPluginChain extends import_base2.ChatLu
|
|
|
1045
1049
|
agent: await (0, import_agent.createReactAgent)({
|
|
1046
1050
|
llm,
|
|
1047
1051
|
tools,
|
|
1048
|
-
prompt: this.prompt
|
|
1052
|
+
prompt: this.prompt,
|
|
1053
|
+
instructions: await this.preset().then((preset) => {
|
|
1054
|
+
return preset.config.reActInstruction;
|
|
1055
|
+
})
|
|
1049
1056
|
}),
|
|
1050
1057
|
tools,
|
|
1051
1058
|
memory: void 0,
|
|
@@ -1268,17 +1275,17 @@ async function defaultFactory(ctx, service) {
|
|
|
1268
1275
|
}
|
|
1269
1276
|
__name(defaultFactory, "defaultFactory");
|
|
1270
1277
|
function updateModels(ctx, service) {
|
|
1271
|
-
ctx.schema.set("model",
|
|
1278
|
+
ctx.schema.set("model", import_koishi3.Schema.union(getModelNames(service)));
|
|
1272
1279
|
}
|
|
1273
1280
|
__name(updateModels, "updateModels");
|
|
1274
1281
|
function updateChatChains(ctx, service) {
|
|
1275
|
-
ctx.schema.set("chat-mode",
|
|
1282
|
+
ctx.schema.set("chat-mode", import_koishi3.Schema.union(getChatChainNames(service)));
|
|
1276
1283
|
}
|
|
1277
1284
|
__name(updateChatChains, "updateChatChains");
|
|
1278
1285
|
function updateEmbeddings(ctx, service) {
|
|
1279
1286
|
ctx.schema.set(
|
|
1280
1287
|
"embeddings",
|
|
1281
|
-
|
|
1288
|
+
import_koishi3.Schema.union(getModelNames(service, import_types.ModelType.embeddings))
|
|
1282
1289
|
);
|
|
1283
1290
|
}
|
|
1284
1291
|
__name(updateEmbeddings, "updateEmbeddings");
|
|
@@ -1288,13 +1295,13 @@ function getVectorStoreRetrieverNames(service) {
|
|
|
1288
1295
|
__name(getVectorStoreRetrieverNames, "getVectorStoreRetrieverNames");
|
|
1289
1296
|
function updateVectorStores(ctx, service) {
|
|
1290
1297
|
const rawVectorStoreNames = getVectorStoreRetrieverNames(service);
|
|
1291
|
-
const vectorStoreRetrieverNames = rawVectorStoreNames.concat("无").map((name2) =>
|
|
1298
|
+
const vectorStoreRetrieverNames = rawVectorStoreNames.concat("无").map((name2) => import_koishi3.Schema.const(name2));
|
|
1292
1299
|
if (rawVectorStoreNames.length === 0) {
|
|
1293
|
-
ctx.schema.set("long-memory",
|
|
1300
|
+
ctx.schema.set("long-memory", import_koishi3.Schema.boolean().disabled());
|
|
1294
1301
|
} else {
|
|
1295
|
-
ctx.schema.set("long-memory",
|
|
1302
|
+
ctx.schema.set("long-memory", import_koishi3.Schema.boolean());
|
|
1296
1303
|
}
|
|
1297
|
-
ctx.schema.set("vector-store",
|
|
1304
|
+
ctx.schema.set("vector-store", import_koishi3.Schema.union(vectorStoreRetrieverNames));
|
|
1298
1305
|
}
|
|
1299
1306
|
__name(updateVectorStores, "updateVectorStores");
|
|
1300
1307
|
function getTools(service, filter) {
|
|
@@ -1303,12 +1310,12 @@ function getTools(service, filter) {
|
|
|
1303
1310
|
}
|
|
1304
1311
|
__name(getTools, "getTools");
|
|
1305
1312
|
function getChatChainNames(service) {
|
|
1306
|
-
return service.getChatChains().map((info) =>
|
|
1313
|
+
return service.getChatChains().map((info) => import_koishi3.Schema.const(info.name).i18n(info.description));
|
|
1307
1314
|
}
|
|
1308
1315
|
__name(getChatChainNames, "getChatChainNames");
|
|
1309
1316
|
function getModelNames(service, type = import_types.ModelType.llm) {
|
|
1310
1317
|
const models = service.getAllModels(type).concat("无");
|
|
1311
|
-
return models.map((model) =>
|
|
1318
|
+
return models.map((model) => import_koishi3.Schema.const(model).description(model));
|
|
1312
1319
|
}
|
|
1313
1320
|
__name(getModelNames, "getModelNames");
|
|
1314
1321
|
|
|
@@ -1506,7 +1513,7 @@ __name(apply9, "apply");
|
|
|
1506
1513
|
|
|
1507
1514
|
// src/chains/chain.ts
|
|
1508
1515
|
var import_events = require("events");
|
|
1509
|
-
var
|
|
1516
|
+
var import_koishi4 = require("koishi");
|
|
1510
1517
|
var import_error3 = require("koishi-plugin-chatluna/utils/error");
|
|
1511
1518
|
var import_logger = require("koishi-plugin-chatluna/utils/logger");
|
|
1512
1519
|
|
|
@@ -1564,7 +1571,7 @@ __name(apply11, "apply");
|
|
|
1564
1571
|
|
|
1565
1572
|
// src/chains/rooms.ts
|
|
1566
1573
|
var import_crypto = require("crypto");
|
|
1567
|
-
var
|
|
1574
|
+
var import_koishi5 = require("koishi");
|
|
1568
1575
|
var import_types2 = require("koishi-plugin-chatluna/llm-core/platform/types");
|
|
1569
1576
|
var import_count_tokens = require("koishi-plugin-chatluna/llm-core/utils/count_tokens");
|
|
1570
1577
|
var import_error4 = require("koishi-plugin-chatluna/utils/error");
|
|
@@ -1748,7 +1755,7 @@ async function getTemplateConversationRoom(ctx, config) {
|
|
|
1748
1755
|
}
|
|
1749
1756
|
__name(getTemplateConversationRoom, "getTemplateConversationRoom");
|
|
1750
1757
|
async function getConversationRoomCount(ctx) {
|
|
1751
|
-
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));
|
|
1752
1759
|
return count;
|
|
1753
1760
|
}
|
|
1754
1761
|
__name(getConversationRoomCount, "getConversationRoomCount");
|
|
@@ -2078,9 +2085,12 @@ function apply12(ctx, config, chain) {
|
|
|
2078
2085
|
__name(apply12, "apply");
|
|
2079
2086
|
|
|
2080
2087
|
// src/middlewares/allow_reply.ts
|
|
2088
|
+
var import_koishi6 = require("koishi");
|
|
2081
2089
|
function apply13(ctx, config, chain) {
|
|
2082
2090
|
chain.middleware("allow_reply", async (session, context) => {
|
|
2083
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("");
|
|
2084
2094
|
if (session.isDirect && config.allowPrivate && (context.command != null || config.privateChatWithoutCommand)) {
|
|
2085
2095
|
return await checkReplyPermission();
|
|
2086
2096
|
}
|
|
@@ -2100,21 +2110,17 @@ function apply13(ctx, config, chain) {
|
|
|
2100
2110
|
if (config.allowQuoteReply && session.quote?.user?.id === botId) {
|
|
2101
2111
|
return await checkReplyPermission();
|
|
2102
2112
|
}
|
|
2103
|
-
if (config.botNames.some(
|
|
2104
|
-
(name2) => session.content.startsWith(name2)
|
|
2105
|
-
) && config.isNickname || config.isNickNameWithContent && config.botNames.some(
|
|
2106
|
-
(name2) => session.content.includes(name2)
|
|
2107
|
-
)) {
|
|
2113
|
+
if (config.botNames.some((name2) => content.startsWith(name2)) && config.isNickname || config.isNickNameWithContent && config.botNames.some((name2) => content.includes(name2))) {
|
|
2108
2114
|
return await checkReplyPermission();
|
|
2109
2115
|
}
|
|
2110
2116
|
if (Math.random() < await session.resolve(config.randomReplyFrequency)) {
|
|
2111
2117
|
return await checkReplyPermission();
|
|
2112
2118
|
}
|
|
2113
|
-
if (config.allowChatWithRoomName) {
|
|
2114
|
-
return await checkReplyPermission();
|
|
2115
|
-
}
|
|
2116
2119
|
if (context.command != null) {
|
|
2117
|
-
return
|
|
2120
|
+
return 2 /* CONTINUE */;
|
|
2121
|
+
}
|
|
2122
|
+
if (config.allowChatWithRoomName) {
|
|
2123
|
+
return 2 /* CONTINUE */;
|
|
2118
2124
|
}
|
|
2119
2125
|
return 1 /* STOP */;
|
|
2120
2126
|
async function checkReplyPermission() {
|
|
@@ -2122,7 +2128,9 @@ function apply13(ctx, config, chain) {
|
|
|
2122
2128
|
"chatluna/before-check-sender",
|
|
2123
2129
|
session
|
|
2124
2130
|
);
|
|
2125
|
-
|
|
2131
|
+
const status = notReply ? 1 /* STOP */ : 2 /* CONTINUE */;
|
|
2132
|
+
context.options.reply_status = status === 2 /* CONTINUE */;
|
|
2133
|
+
return status;
|
|
2126
2134
|
}
|
|
2127
2135
|
__name(checkReplyPermission, "checkReplyPermission");
|
|
2128
2136
|
}).after("lifecycle-check");
|
|
@@ -2168,7 +2176,7 @@ var import_count_tokens2 = require("koishi-plugin-chatluna/llm-core/utils/count_
|
|
|
2168
2176
|
var import_error5 = require("koishi-plugin-chatluna/utils/error");
|
|
2169
2177
|
|
|
2170
2178
|
// src/cache.ts
|
|
2171
|
-
var
|
|
2179
|
+
var import_koishi7 = require("koishi");
|
|
2172
2180
|
var Cache = class {
|
|
2173
2181
|
constructor(ctx, config, tableName) {
|
|
2174
2182
|
this.config = config;
|
|
@@ -2222,7 +2230,7 @@ var DatabaseCache = class {
|
|
|
2222
2230
|
);
|
|
2223
2231
|
ctx.setInterval(async () => {
|
|
2224
2232
|
await ctx.database.remove("cache", { expire: { $lt: /* @__PURE__ */ new Date() } });
|
|
2225
|
-
}, 10 *
|
|
2233
|
+
}, 10 * import_koishi7.Time.minute);
|
|
2226
2234
|
}
|
|
2227
2235
|
static {
|
|
2228
2236
|
__name(this, "DatabaseCache");
|
|
@@ -3840,13 +3848,13 @@ function apply40(ctx, config, chain) {
|
|
|
3840
3848
|
__name(apply40, "apply");
|
|
3841
3849
|
|
|
3842
3850
|
// src/middlewares/read_chat_message.ts
|
|
3843
|
-
var
|
|
3851
|
+
var import_koishi8 = require("koishi");
|
|
3844
3852
|
function apply41(ctx, config, chain) {
|
|
3845
3853
|
chain.middleware("read_chat_message", async (session, context) => {
|
|
3846
3854
|
let message = context.command != null ? context.message : session.elements;
|
|
3847
3855
|
message = message;
|
|
3848
3856
|
if (typeof message === "string") {
|
|
3849
|
-
message = [
|
|
3857
|
+
message = [import_koishi8.h.text(message)];
|
|
3850
3858
|
}
|
|
3851
3859
|
const transformedMessage = await ctx.chatluna.messageTransformer.transform(
|
|
3852
3860
|
session,
|
|
@@ -3960,7 +3968,7 @@ async function renderMessage(ctx, message, options) {
|
|
|
3960
3968
|
__name(renderMessage, "renderMessage");
|
|
3961
3969
|
|
|
3962
3970
|
// src/middlewares/request_model.ts
|
|
3963
|
-
var
|
|
3971
|
+
var import_koishi10 = require("koishi");
|
|
3964
3972
|
var import_prompt3 = require("koishi-plugin-chatluna/llm-core/prompt");
|
|
3965
3973
|
var import_count_tokens3 = require("koishi-plugin-chatluna/llm-core/utils/count_tokens");
|
|
3966
3974
|
var import_error6 = require("koishi-plugin-chatluna/utils/error");
|
|
@@ -3969,7 +3977,7 @@ var import_chains = require("koishi-plugin-chatluna/chains");
|
|
|
3969
3977
|
var import_string = require("koishi-plugin-chatluna/utils/string");
|
|
3970
3978
|
|
|
3971
3979
|
// src/utils/buffer_text.ts
|
|
3972
|
-
var
|
|
3980
|
+
var import_koishi9 = require("koishi");
|
|
3973
3981
|
var import_lock2 = require("koishi-plugin-chatluna/utils/lock");
|
|
3974
3982
|
var BufferText = class {
|
|
3975
3983
|
constructor(sleepTime = 3, prefix, postfix) {
|
|
@@ -3999,7 +4007,7 @@ var BufferText = class {
|
|
|
3999
4007
|
while (this.queue.length > 0 || !this.isEnd) {
|
|
4000
4008
|
const text = await this.processChar();
|
|
4001
4009
|
if (text == null) {
|
|
4002
|
-
await (0,
|
|
4010
|
+
await (0, import_koishi9.sleep)(this.sleepTime);
|
|
4003
4011
|
continue;
|
|
4004
4012
|
}
|
|
4005
4013
|
this.rawText += text;
|
|
@@ -4014,7 +4022,7 @@ var BufferText = class {
|
|
|
4014
4022
|
const text = this.queue.shift();
|
|
4015
4023
|
unlock();
|
|
4016
4024
|
if (!this.isEnd) {
|
|
4017
|
-
await (0,
|
|
4025
|
+
await (0, import_koishi9.sleep)(this.sleepTime);
|
|
4018
4026
|
}
|
|
4019
4027
|
return text;
|
|
4020
4028
|
}
|
|
@@ -4261,7 +4269,7 @@ async function handleEditMessage(context, session, config, bufferText, sendMessa
|
|
|
4261
4269
|
while (!isFinished) {
|
|
4262
4270
|
const firstQueue = queue.shift();
|
|
4263
4271
|
if (firstQueue == null) {
|
|
4264
|
-
await (0,
|
|
4272
|
+
await (0, import_koishi10.sleep)(2);
|
|
4265
4273
|
continue;
|
|
4266
4274
|
}
|
|
4267
4275
|
await editMessage(firstQueue);
|
|
@@ -4397,7 +4405,7 @@ function apply44(ctx, config, chain) {
|
|
|
4397
4405
|
__name(apply44, "apply");
|
|
4398
4406
|
|
|
4399
4407
|
// src/middlewares/resolve_room.ts
|
|
4400
|
-
var
|
|
4408
|
+
var import_koishi11 = require("koishi");
|
|
4401
4409
|
var import_uuid2 = require("uuid");
|
|
4402
4410
|
var import_logger6 = require("koishi-plugin-chatluna/utils/logger");
|
|
4403
4411
|
var logger8;
|
|
@@ -4410,21 +4418,10 @@ function apply45(ctx, config, chain) {
|
|
|
4410
4418
|
context.options?.room_resolve?.name
|
|
4411
4419
|
);
|
|
4412
4420
|
if (config.allowChatWithRoomName) {
|
|
4413
|
-
const needContinue =
|
|
4414
|
-
|
|
4415
|
-
|
|
4416
|
-
|
|
4417
|
-
config.botNames.some(
|
|
4418
|
-
(name2) => session.content.startsWith(name2)
|
|
4419
|
-
) && config.isNickname || config.isNickNameWithContent && config.botNames.some(
|
|
4420
|
-
(name2) => session.content.includes(name2)
|
|
4421
|
-
) ? true : (
|
|
4422
|
-
// 命令
|
|
4423
|
-
context.command != null
|
|
4424
|
-
)
|
|
4425
|
-
)
|
|
4426
|
-
);
|
|
4427
|
-
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(" ");
|
|
4428
4425
|
let matchedRoom;
|
|
4429
4426
|
if (splitContent.length > 1) {
|
|
4430
4427
|
matchedRoom = await queryJoinedConversationRoom(
|
|
@@ -4440,7 +4437,7 @@ function apply45(ctx, config, chain) {
|
|
|
4440
4437
|
joinRoom = matchedRoom;
|
|
4441
4438
|
context.options.inputMessage = await ctx.chatluna.messageTransformer.transform(
|
|
4442
4439
|
session,
|
|
4443
|
-
[
|
|
4440
|
+
[import_koishi11.h.text(splitContent.concat(" "))]
|
|
4444
4441
|
);
|
|
4445
4442
|
}
|
|
4446
4443
|
}
|
|
@@ -4582,7 +4579,7 @@ function apply46(ctx, config, chain) {
|
|
|
4582
4579
|
__name(apply46, "apply");
|
|
4583
4580
|
|
|
4584
4581
|
// src/middlewares/rollback_chat.ts
|
|
4585
|
-
var
|
|
4582
|
+
var import_koishi12 = require("koishi");
|
|
4586
4583
|
function apply47(ctx, config, chain) {
|
|
4587
4584
|
chain.middleware("rollback_chat", async (session, context) => {
|
|
4588
4585
|
const { command: command2 } = context;
|
|
@@ -4642,7 +4639,7 @@ function apply47(ctx, config, chain) {
|
|
|
4642
4639
|
]);
|
|
4643
4640
|
if ((context.options.message?.length ?? 0) < 1) {
|
|
4644
4641
|
context.options.inputMessage = await ctx.chatluna.messageTransformer.transform(session, [
|
|
4645
|
-
|
|
4642
|
+
import_koishi12.h.text(humanMessage.text)
|
|
4646
4643
|
]);
|
|
4647
4644
|
}
|
|
4648
4645
|
await ctx.database.remove("chathub_message", {
|
|
@@ -5907,84 +5904,84 @@ __name(middleware, "middleware");
|
|
|
5907
5904
|
var import_chains2 = require("koishi-plugin-chatluna/chains");
|
|
5908
5905
|
|
|
5909
5906
|
// src/config.ts
|
|
5910
|
-
var
|
|
5911
|
-
var Config2 =
|
|
5912
|
-
|
|
5913
|
-
botNames:
|
|
5914
|
-
isNickname:
|
|
5915
|
-
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)
|
|
5916
5913
|
}),
|
|
5917
|
-
|
|
5918
|
-
allowPrivate:
|
|
5919
|
-
allowAtReply:
|
|
5920
|
-
allowQuoteReply:
|
|
5921
|
-
isReplyWithAt:
|
|
5922
|
-
isForwardMsg:
|
|
5923
|
-
privateChatWithoutCommand:
|
|
5924
|
-
allowChatWithRoomName:
|
|
5925
|
-
includeQuoteReply:
|
|
5926
|
-
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()
|
|
5927
5924
|
}),
|
|
5928
|
-
|
|
5929
|
-
sendThinkingMessage:
|
|
5930
|
-
sendThinkingMessageTimeout:
|
|
5931
|
-
msgCooldown:
|
|
5932
|
-
messageDelay:
|
|
5933
|
-
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)
|
|
5934
5931
|
}),
|
|
5935
|
-
|
|
5936
|
-
outputMode:
|
|
5937
|
-
splitMessage:
|
|
5938
|
-
censor:
|
|
5939
|
-
rawOnCensor:
|
|
5940
|
-
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)
|
|
5941
5938
|
}),
|
|
5942
|
-
|
|
5943
|
-
blackList:
|
|
5939
|
+
import_koishi13.Schema.object({
|
|
5940
|
+
blackList: import_koishi13.Schema.boolean().computed().default(false)
|
|
5944
5941
|
}),
|
|
5945
|
-
|
|
5946
|
-
messageCount:
|
|
5947
|
-
autoDelete:
|
|
5948
|
-
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)
|
|
5949
5946
|
}),
|
|
5950
|
-
|
|
5951
|
-
defaultEmbeddings:
|
|
5952
|
-
defaultVectorStore:
|
|
5947
|
+
import_koishi13.Schema.object({
|
|
5948
|
+
defaultEmbeddings: import_koishi13.Schema.dynamic("embeddings").default("无"),
|
|
5949
|
+
defaultVectorStore: import_koishi13.Schema.dynamic("vector-store").default("无")
|
|
5953
5950
|
}),
|
|
5954
|
-
|
|
5955
|
-
autoCreateRoomFromUser:
|
|
5956
|
-
defaultChatMode:
|
|
5957
|
-
defaultModel:
|
|
5958
|
-
defaultPreset:
|
|
5959
|
-
autoUpdateRoomMode:
|
|
5960
|
-
|
|
5961
|
-
|
|
5962
|
-
|
|
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")
|
|
5963
5960
|
]).default("manual")
|
|
5964
5961
|
}),
|
|
5965
|
-
|
|
5966
|
-
authSystem:
|
|
5967
|
-
isProxy:
|
|
5968
|
-
voiceSpeakId:
|
|
5969
|
-
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)
|
|
5970
5967
|
}),
|
|
5971
|
-
|
|
5972
|
-
|
|
5973
|
-
isProxy:
|
|
5974
|
-
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("")
|
|
5975
5972
|
}),
|
|
5976
|
-
|
|
5973
|
+
import_koishi13.Schema.object({})
|
|
5977
5974
|
]),
|
|
5978
|
-
|
|
5979
|
-
|
|
5980
|
-
authSystem:
|
|
5981
|
-
authUserDefaultGroup:
|
|
5982
|
-
|
|
5983
|
-
|
|
5984
|
-
|
|
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")
|
|
5985
5982
|
]).computed().default([0, 1, "guest"])
|
|
5986
5983
|
}),
|
|
5987
|
-
|
|
5984
|
+
import_koishi13.Schema.object({})
|
|
5988
5985
|
])
|
|
5989
5986
|
]).i18n({
|
|
5990
5987
|
"zh-CN": require_zh_CN_schema(),
|
|
@@ -5992,7 +5989,7 @@ var Config2 = import_koishi11.Schema.intersect([
|
|
|
5992
5989
|
});
|
|
5993
5990
|
|
|
5994
5991
|
// src/render.ts
|
|
5995
|
-
var
|
|
5992
|
+
var import_koishi19 = require("koishi");
|
|
5996
5993
|
var import_error7 = require("koishi-plugin-chatluna/utils/error");
|
|
5997
5994
|
|
|
5998
5995
|
// src/renders/default.ts
|
|
@@ -6007,7 +6004,7 @@ var Renderer = class {
|
|
|
6007
6004
|
|
|
6008
6005
|
// src/renders/text.ts
|
|
6009
6006
|
var import_koishi_plugin_markdown = require("koishi-plugin-markdown");
|
|
6010
|
-
var
|
|
6007
|
+
var import_koishi14 = require("koishi");
|
|
6011
6008
|
var import_he = __toESM(require("he"), 1);
|
|
6012
6009
|
var TextRenderer = class extends Renderer {
|
|
6013
6010
|
static {
|
|
@@ -6017,14 +6014,14 @@ var TextRenderer = class extends Renderer {
|
|
|
6017
6014
|
let transformed = transformAndEscape(message.content);
|
|
6018
6015
|
if (options.split) {
|
|
6019
6016
|
transformed = transformed.map((element) => {
|
|
6020
|
-
return (0,
|
|
6017
|
+
return (0, import_koishi14.h)("message", element);
|
|
6021
6018
|
});
|
|
6022
6019
|
}
|
|
6023
6020
|
if (transformed[0]?.type === "p") {
|
|
6024
6021
|
const pElement = transformed.shift();
|
|
6025
6022
|
const pElementContent = pElement.attrs["content"];
|
|
6026
6023
|
if (pElementContent) {
|
|
6027
|
-
transformed.unshift(
|
|
6024
|
+
transformed.unshift(import_koishi14.h.text(pElementContent));
|
|
6028
6025
|
} else {
|
|
6029
6026
|
transformed.unshift(...pElement.children);
|
|
6030
6027
|
}
|
|
@@ -6033,7 +6030,7 @@ var TextRenderer = class extends Renderer {
|
|
|
6033
6030
|
element: transformed
|
|
6034
6031
|
};
|
|
6035
6032
|
}
|
|
6036
|
-
schema =
|
|
6033
|
+
schema = import_koishi14.Schema.const("text").i18n({
|
|
6037
6034
|
"zh-CN": "将回复作为 markdown 进行渲染",
|
|
6038
6035
|
"en-US": "Render as markdown"
|
|
6039
6036
|
});
|
|
@@ -6057,7 +6054,7 @@ __name(transformAndEscape, "transformAndEscape");
|
|
|
6057
6054
|
// src/renders/voice.ts
|
|
6058
6055
|
var import_marked = require("marked");
|
|
6059
6056
|
var import_koishi_plugin_chatluna3 = require("koishi-plugin-chatluna");
|
|
6060
|
-
var
|
|
6057
|
+
var import_koishi15 = require("koishi");
|
|
6061
6058
|
var VoiceRenderer = class extends Renderer {
|
|
6062
6059
|
static {
|
|
6063
6060
|
__name(this, "VoiceRenderer");
|
|
@@ -6069,7 +6066,7 @@ var VoiceRenderer = class extends Renderer {
|
|
|
6069
6066
|
return {
|
|
6070
6067
|
element: await Promise.all(
|
|
6071
6068
|
splitMessages.map(async (text) => {
|
|
6072
|
-
return (0,
|
|
6069
|
+
return (0, import_koishi15.h)(
|
|
6073
6070
|
"message",
|
|
6074
6071
|
await this._renderToVoice(text, options)
|
|
6075
6072
|
);
|
|
@@ -6105,7 +6102,7 @@ var VoiceRenderer = class extends Renderer {
|
|
|
6105
6102
|
)
|
|
6106
6103
|
);
|
|
6107
6104
|
}
|
|
6108
|
-
schema =
|
|
6105
|
+
schema = import_koishi15.Schema.const("voice").i18n({
|
|
6109
6106
|
"zh-CN": "将回复渲染为语音",
|
|
6110
6107
|
"en-US": "Render as voice"
|
|
6111
6108
|
});
|
|
@@ -6124,24 +6121,24 @@ function renderTokens(tokens) {
|
|
|
6124
6121
|
__name(renderTokens, "renderTokens");
|
|
6125
6122
|
|
|
6126
6123
|
// src/renders/raw.ts
|
|
6127
|
-
var
|
|
6124
|
+
var import_koishi16 = require("koishi");
|
|
6128
6125
|
var RawRenderer = class extends Renderer {
|
|
6129
6126
|
static {
|
|
6130
6127
|
__name(this, "RawRenderer");
|
|
6131
6128
|
}
|
|
6132
6129
|
async render(message, options) {
|
|
6133
6130
|
return {
|
|
6134
|
-
element:
|
|
6131
|
+
element: import_koishi16.h.text(message.content)
|
|
6135
6132
|
};
|
|
6136
6133
|
}
|
|
6137
|
-
schema =
|
|
6134
|
+
schema = import_koishi16.Schema.const("raw").i18n({
|
|
6138
6135
|
"zh-CN": "原始输出",
|
|
6139
6136
|
"en-US": "Raw text"
|
|
6140
6137
|
});
|
|
6141
6138
|
};
|
|
6142
6139
|
|
|
6143
6140
|
// src/renders/koishi-element.ts
|
|
6144
|
-
var
|
|
6141
|
+
var import_koishi17 = require("koishi");
|
|
6145
6142
|
var import_he2 = __toESM(require("he"), 1);
|
|
6146
6143
|
var import_koishi_plugin_chatluna4 = require("koishi-plugin-chatluna");
|
|
6147
6144
|
var KoishiElementRenderer = class extends Renderer {
|
|
@@ -6152,14 +6149,14 @@ var KoishiElementRenderer = class extends Renderer {
|
|
|
6152
6149
|
let transformed = transformAndEscape2(message.content);
|
|
6153
6150
|
if (options.split) {
|
|
6154
6151
|
transformed = transformed.map((element) => {
|
|
6155
|
-
return (0,
|
|
6152
|
+
return (0, import_koishi17.h)("message", element);
|
|
6156
6153
|
});
|
|
6157
6154
|
}
|
|
6158
6155
|
return {
|
|
6159
6156
|
element: transformed
|
|
6160
6157
|
};
|
|
6161
6158
|
}
|
|
6162
|
-
schema =
|
|
6159
|
+
schema = import_koishi17.Schema.const("koishi-element").i18n({
|
|
6163
6160
|
"zh-CN": "将回复作为 koishi 消息元素进行渲染",
|
|
6164
6161
|
"en-US": "Render as koishi message element template"
|
|
6165
6162
|
});
|
|
@@ -6176,10 +6173,10 @@ function unescape2(element) {
|
|
|
6176
6173
|
__name(unescape2, "unescape");
|
|
6177
6174
|
function transformAndEscape2(source) {
|
|
6178
6175
|
try {
|
|
6179
|
-
return
|
|
6176
|
+
return import_koishi17.h.parse(source).map(unescape2);
|
|
6180
6177
|
} catch (e) {
|
|
6181
6178
|
import_koishi_plugin_chatluna4.logger.error(e);
|
|
6182
|
-
return [
|
|
6179
|
+
return [import_koishi17.h.text(source)];
|
|
6183
6180
|
}
|
|
6184
6181
|
}
|
|
6185
6182
|
__name(transformAndEscape2, "transformAndEscape");
|
|
@@ -6187,7 +6184,7 @@ __name(transformAndEscape2, "transformAndEscape");
|
|
|
6187
6184
|
// src/renders/mixed-voice.ts
|
|
6188
6185
|
var import_marked2 = require("marked");
|
|
6189
6186
|
var import_koishi_plugin_chatluna5 = require("koishi-plugin-chatluna");
|
|
6190
|
-
var
|
|
6187
|
+
var import_koishi18 = require("koishi");
|
|
6191
6188
|
var MixedVoiceRenderer = class extends Renderer {
|
|
6192
6189
|
static {
|
|
6193
6190
|
__name(this, "MixedVoiceRenderer");
|
|
@@ -6214,7 +6211,7 @@ var MixedVoiceRenderer = class extends Renderer {
|
|
|
6214
6211
|
let transformed = transformAndEscape(message.content);
|
|
6215
6212
|
if (options.split) {
|
|
6216
6213
|
transformed = transformed.map((element) => {
|
|
6217
|
-
return (0,
|
|
6214
|
+
return (0, import_koishi18.h)("message", element);
|
|
6218
6215
|
});
|
|
6219
6216
|
}
|
|
6220
6217
|
return {
|
|
@@ -6248,7 +6245,7 @@ var MixedVoiceRenderer = class extends Renderer {
|
|
|
6248
6245
|
)
|
|
6249
6246
|
);
|
|
6250
6247
|
}
|
|
6251
|
-
schema =
|
|
6248
|
+
schema = import_koishi18.Schema.const("mixed-voice").i18n({
|
|
6252
6249
|
"zh-CN": "同时输出语音和文本",
|
|
6253
6250
|
"en-US": "Output both voice and text"
|
|
6254
6251
|
});
|
|
@@ -6303,7 +6300,7 @@ var DefaultRenderer = class {
|
|
|
6303
6300
|
for (const additionalMessage of message.additionalReplyMessages) {
|
|
6304
6301
|
const elements = await rawRenderer.render(additionalMessage, options).then((r) => r.element);
|
|
6305
6302
|
result2.push({
|
|
6306
|
-
element: (0,
|
|
6303
|
+
element: (0, import_koishi19.h)(
|
|
6307
6304
|
"message",
|
|
6308
6305
|
{ forward: true },
|
|
6309
6306
|
Array.isArray(elements) ? elements : [elements]
|
|
@@ -6335,7 +6332,7 @@ var DefaultRenderer = class {
|
|
|
6335
6332
|
}
|
|
6336
6333
|
this.ctx.schema.set(
|
|
6337
6334
|
"output-mode",
|
|
6338
|
-
|
|
6335
|
+
import_koishi19.Schema.union(this._getAllRendererScheme())
|
|
6339
6336
|
);
|
|
6340
6337
|
}
|
|
6341
6338
|
_getAllRendererScheme() {
|
|
@@ -6392,7 +6389,7 @@ async function setupEntryPoint(ctx, config, disposables) {
|
|
|
6392
6389
|
});
|
|
6393
6390
|
setupMiddleware(ctx2);
|
|
6394
6391
|
}, "entryPointPlugin");
|
|
6395
|
-
const entryPointDisposable = (0,
|
|
6392
|
+
const entryPointDisposable = (0, import_koishi21.forkScopeToDisposable)(
|
|
6396
6393
|
ctx.plugin(
|
|
6397
6394
|
{
|
|
6398
6395
|
apply: entryPointPlugin,
|
|
@@ -6439,7 +6436,7 @@ function setupMiddleware(ctx) {
|
|
|
6439
6436
|
__name(setupMiddleware, "setupMiddleware");
|
|
6440
6437
|
function setupLogger(config) {
|
|
6441
6438
|
if (config.isLog) {
|
|
6442
|
-
(0, import_logger9.setLoggerLevel)(
|
|
6439
|
+
(0, import_logger9.setLoggerLevel)(import_koishi20.Logger.DEBUG);
|
|
6443
6440
|
}
|
|
6444
6441
|
}
|
|
6445
6442
|
__name(setupLogger, "setupLogger");
|
|
@@ -6464,8 +6461,8 @@ function setupProxy(ctx, config) {
|
|
|
6464
6461
|
__name(setupProxy, "setupProxy");
|
|
6465
6462
|
async function setupServices(ctx, config, disposables) {
|
|
6466
6463
|
disposables.push(
|
|
6467
|
-
(0,
|
|
6468
|
-
(0,
|
|
6464
|
+
(0, import_koishi21.forkScopeToDisposable)(ctx.plugin(import_chat2.ChatLunaService, config)),
|
|
6465
|
+
(0, import_koishi21.forkScopeToDisposable)(ctx.plugin(ChatLunaAuthService, config))
|
|
6469
6466
|
);
|
|
6470
6467
|
}
|
|
6471
6468
|
__name(setupServices, "setupServices");
|
|
@@ -6525,7 +6522,7 @@ async function setupAutoDelete(ctx, config) {
|
|
|
6525
6522
|
await execute();
|
|
6526
6523
|
ctx.setInterval(async () => {
|
|
6527
6524
|
await execute();
|
|
6528
|
-
},
|
|
6525
|
+
}, import_koishi20.Time.minute * 5);
|
|
6529
6526
|
}
|
|
6530
6527
|
__name(setupAutoDelete, "setupAutoDelete");
|
|
6531
6528
|
// Annotate the CommonJS export names for ESM import in node:
|
package/lib/index.mjs
CHANGED
|
@@ -487,6 +487,7 @@ function apply(ctx, config, chain) {
|
|
|
487
487
|
__name(apply, "apply");
|
|
488
488
|
|
|
489
489
|
// src/commands/chat.ts
|
|
490
|
+
import { h } from "koishi";
|
|
490
491
|
function apply2(ctx, config, chain) {
|
|
491
492
|
ctx.command("chatluna", {
|
|
492
493
|
authority: 1
|
|
@@ -501,8 +502,9 @@ function apply2(ctx, config, chain) {
|
|
|
501
502
|
)) {
|
|
502
503
|
return session.text(".invalid-render-type");
|
|
503
504
|
}
|
|
505
|
+
const elements = h.parse(message);
|
|
504
506
|
await chain.receiveCommand(session, "", {
|
|
505
|
-
message,
|
|
507
|
+
message: elements,
|
|
506
508
|
room_resolve: {
|
|
507
509
|
name: options.room
|
|
508
510
|
},
|
|
@@ -514,8 +516,9 @@ function apply2(ctx, config, chain) {
|
|
|
514
516
|
});
|
|
515
517
|
});
|
|
516
518
|
ctx.command("chatluna.chat.rollback [message:text]").option("room", "-r <room:string>").option("i", "-i <i: string>").action(async ({ options, session }, message) => {
|
|
519
|
+
const elements = h.parse(message);
|
|
517
520
|
await chain.receiveCommand(session, "rollback", {
|
|
518
|
-
message,
|
|
521
|
+
message: elements,
|
|
519
522
|
room_resolve: {
|
|
520
523
|
name: options.room
|
|
521
524
|
},
|
|
@@ -535,8 +538,9 @@ function apply2(ctx, config, chain) {
|
|
|
535
538
|
});
|
|
536
539
|
});
|
|
537
540
|
ctx.command("chatluna.chat.voice <message:text>").option("room", "-r <room:string>").option("speaker", "-s <speakerId:number>", { authority: 1 }).action(async ({ options, session }, message) => {
|
|
541
|
+
const elements = h.parse(message);
|
|
538
542
|
await chain.receiveCommand(session, "", {
|
|
539
|
-
message,
|
|
543
|
+
message: elements,
|
|
540
544
|
renderOptions: {
|
|
541
545
|
split: config.splitMessage,
|
|
542
546
|
type: "voice",
|
|
@@ -1029,7 +1033,10 @@ var ChatLunaPluginChain = class _ChatLunaPluginChain extends ChatLunaLLMChainWra
|
|
|
1029
1033
|
agent: await createReactAgent({
|
|
1030
1034
|
llm,
|
|
1031
1035
|
tools,
|
|
1032
|
-
prompt: this.prompt
|
|
1036
|
+
prompt: this.prompt,
|
|
1037
|
+
instructions: await this.preset().then((preset) => {
|
|
1038
|
+
return preset.config.reActInstruction;
|
|
1039
|
+
})
|
|
1033
1040
|
}),
|
|
1034
1041
|
tools,
|
|
1035
1042
|
memory: void 0,
|
|
@@ -1490,7 +1497,7 @@ __name(apply9, "apply");
|
|
|
1490
1497
|
|
|
1491
1498
|
// src/chains/chain.ts
|
|
1492
1499
|
import { EventEmitter } from "events";
|
|
1493
|
-
import { h } from "koishi";
|
|
1500
|
+
import { h as h2 } from "koishi";
|
|
1494
1501
|
import {
|
|
1495
1502
|
ChatLunaError as ChatLunaError3,
|
|
1496
1503
|
ChatLunaErrorCode as ChatLunaErrorCode3,
|
|
@@ -2069,9 +2076,12 @@ function apply12(ctx, config, chain) {
|
|
|
2069
2076
|
__name(apply12, "apply");
|
|
2070
2077
|
|
|
2071
2078
|
// src/middlewares/allow_reply.ts
|
|
2079
|
+
import { h as h3 } from "koishi";
|
|
2072
2080
|
function apply13(ctx, config, chain) {
|
|
2073
2081
|
chain.middleware("allow_reply", async (session, context) => {
|
|
2074
2082
|
if (ctx.bots[session.uid]) return 1 /* STOP */;
|
|
2083
|
+
context.options.reply_status = false;
|
|
2084
|
+
const content = h3.select(session.elements, "text").join("");
|
|
2075
2085
|
if (session.isDirect && config.allowPrivate && (context.command != null || config.privateChatWithoutCommand)) {
|
|
2076
2086
|
return await checkReplyPermission();
|
|
2077
2087
|
}
|
|
@@ -2091,21 +2101,17 @@ function apply13(ctx, config, chain) {
|
|
|
2091
2101
|
if (config.allowQuoteReply && session.quote?.user?.id === botId) {
|
|
2092
2102
|
return await checkReplyPermission();
|
|
2093
2103
|
}
|
|
2094
|
-
if (config.botNames.some(
|
|
2095
|
-
(name2) => session.content.startsWith(name2)
|
|
2096
|
-
) && config.isNickname || config.isNickNameWithContent && config.botNames.some(
|
|
2097
|
-
(name2) => session.content.includes(name2)
|
|
2098
|
-
)) {
|
|
2104
|
+
if (config.botNames.some((name2) => content.startsWith(name2)) && config.isNickname || config.isNickNameWithContent && config.botNames.some((name2) => content.includes(name2))) {
|
|
2099
2105
|
return await checkReplyPermission();
|
|
2100
2106
|
}
|
|
2101
2107
|
if (Math.random() < await session.resolve(config.randomReplyFrequency)) {
|
|
2102
2108
|
return await checkReplyPermission();
|
|
2103
2109
|
}
|
|
2104
|
-
if (config.allowChatWithRoomName) {
|
|
2105
|
-
return await checkReplyPermission();
|
|
2106
|
-
}
|
|
2107
2110
|
if (context.command != null) {
|
|
2108
|
-
return
|
|
2111
|
+
return 2 /* CONTINUE */;
|
|
2112
|
+
}
|
|
2113
|
+
if (config.allowChatWithRoomName) {
|
|
2114
|
+
return 2 /* CONTINUE */;
|
|
2109
2115
|
}
|
|
2110
2116
|
return 1 /* STOP */;
|
|
2111
2117
|
async function checkReplyPermission() {
|
|
@@ -2113,7 +2119,9 @@ function apply13(ctx, config, chain) {
|
|
|
2113
2119
|
"chatluna/before-check-sender",
|
|
2114
2120
|
session
|
|
2115
2121
|
);
|
|
2116
|
-
|
|
2122
|
+
const status = notReply ? 1 /* STOP */ : 2 /* CONTINUE */;
|
|
2123
|
+
context.options.reply_status = status === 2 /* CONTINUE */;
|
|
2124
|
+
return status;
|
|
2117
2125
|
}
|
|
2118
2126
|
__name(checkReplyPermission, "checkReplyPermission");
|
|
2119
2127
|
}).after("lifecycle-check");
|
|
@@ -3834,13 +3842,13 @@ function apply40(ctx, config, chain) {
|
|
|
3834
3842
|
__name(apply40, "apply");
|
|
3835
3843
|
|
|
3836
3844
|
// src/middlewares/read_chat_message.ts
|
|
3837
|
-
import { h as
|
|
3845
|
+
import { h as h4 } from "koishi";
|
|
3838
3846
|
function apply41(ctx, config, chain) {
|
|
3839
3847
|
chain.middleware("read_chat_message", async (session, context) => {
|
|
3840
3848
|
let message = context.command != null ? context.message : session.elements;
|
|
3841
3849
|
message = message;
|
|
3842
3850
|
if (typeof message === "string") {
|
|
3843
|
-
message = [
|
|
3851
|
+
message = [h4.text(message)];
|
|
3844
3852
|
}
|
|
3845
3853
|
const transformedMessage = await ctx.chatluna.messageTransformer.transform(
|
|
3846
3854
|
session,
|
|
@@ -4403,7 +4411,7 @@ function apply44(ctx, config, chain) {
|
|
|
4403
4411
|
__name(apply44, "apply");
|
|
4404
4412
|
|
|
4405
4413
|
// src/middlewares/resolve_room.ts
|
|
4406
|
-
import { h as
|
|
4414
|
+
import { h as h5 } from "koishi";
|
|
4407
4415
|
import { v4 as uuidv42 } from "uuid";
|
|
4408
4416
|
import { createLogger as createLogger6 } from "koishi-plugin-chatluna/utils/logger";
|
|
4409
4417
|
var logger8;
|
|
@@ -4416,21 +4424,10 @@ function apply45(ctx, config, chain) {
|
|
|
4416
4424
|
context.options?.room_resolve?.name
|
|
4417
4425
|
);
|
|
4418
4426
|
if (config.allowChatWithRoomName) {
|
|
4419
|
-
const needContinue =
|
|
4420
|
-
|
|
4421
|
-
|
|
4422
|
-
|
|
4423
|
-
config.botNames.some(
|
|
4424
|
-
(name2) => session.content.startsWith(name2)
|
|
4425
|
-
) && config.isNickname || config.isNickNameWithContent && config.botNames.some(
|
|
4426
|
-
(name2) => session.content.includes(name2)
|
|
4427
|
-
) ? true : (
|
|
4428
|
-
// 命令
|
|
4429
|
-
context.command != null
|
|
4430
|
-
)
|
|
4431
|
-
)
|
|
4432
|
-
);
|
|
4433
|
-
const splitContent = context.message.split(" ");
|
|
4427
|
+
const needContinue = context.command == null;
|
|
4428
|
+
const rawMessageContent = context.message;
|
|
4429
|
+
const messageContent = typeof rawMessageContent === "string" ? rawMessageContent : h5.select(rawMessageContent, "text").join("");
|
|
4430
|
+
const splitContent = messageContent.split(" ");
|
|
4434
4431
|
let matchedRoom;
|
|
4435
4432
|
if (splitContent.length > 1) {
|
|
4436
4433
|
matchedRoom = await queryJoinedConversationRoom(
|
|
@@ -4446,7 +4443,7 @@ function apply45(ctx, config, chain) {
|
|
|
4446
4443
|
joinRoom = matchedRoom;
|
|
4447
4444
|
context.options.inputMessage = await ctx.chatluna.messageTransformer.transform(
|
|
4448
4445
|
session,
|
|
4449
|
-
[
|
|
4446
|
+
[h5.text(splitContent.concat(" "))]
|
|
4450
4447
|
);
|
|
4451
4448
|
}
|
|
4452
4449
|
}
|
|
@@ -4588,7 +4585,7 @@ function apply46(ctx, config, chain) {
|
|
|
4588
4585
|
__name(apply46, "apply");
|
|
4589
4586
|
|
|
4590
4587
|
// src/middlewares/rollback_chat.ts
|
|
4591
|
-
import { h as
|
|
4588
|
+
import { h as h6 } from "koishi";
|
|
4592
4589
|
function apply47(ctx, config, chain) {
|
|
4593
4590
|
chain.middleware("rollback_chat", async (session, context) => {
|
|
4594
4591
|
const { command: command2 } = context;
|
|
@@ -4648,7 +4645,7 @@ function apply47(ctx, config, chain) {
|
|
|
4648
4645
|
]);
|
|
4649
4646
|
if ((context.options.message?.length ?? 0) < 1) {
|
|
4650
4647
|
context.options.inputMessage = await ctx.chatluna.messageTransformer.transform(session, [
|
|
4651
|
-
|
|
4648
|
+
h6.text(humanMessage.text)
|
|
4652
4649
|
]);
|
|
4653
4650
|
}
|
|
4654
4651
|
await ctx.database.remove("chathub_message", {
|
|
@@ -5998,7 +5995,7 @@ var Config2 = Schema2.intersect([
|
|
|
5998
5995
|
});
|
|
5999
5996
|
|
|
6000
5997
|
// src/render.ts
|
|
6001
|
-
import { h as
|
|
5998
|
+
import { h as h12, Schema as Schema8 } from "koishi";
|
|
6002
5999
|
import {
|
|
6003
6000
|
ChatLunaError as ChatLunaError7,
|
|
6004
6001
|
ChatLunaErrorCode as ChatLunaErrorCode7
|
|
@@ -6016,7 +6013,7 @@ var Renderer = class {
|
|
|
6016
6013
|
|
|
6017
6014
|
// src/renders/text.ts
|
|
6018
6015
|
import { transform } from "koishi-plugin-markdown";
|
|
6019
|
-
import { h as
|
|
6016
|
+
import { h as h7, Schema as Schema3 } from "koishi";
|
|
6020
6017
|
import he from "he";
|
|
6021
6018
|
var TextRenderer = class extends Renderer {
|
|
6022
6019
|
static {
|
|
@@ -6026,14 +6023,14 @@ var TextRenderer = class extends Renderer {
|
|
|
6026
6023
|
let transformed = transformAndEscape(message.content);
|
|
6027
6024
|
if (options.split) {
|
|
6028
6025
|
transformed = transformed.map((element) => {
|
|
6029
|
-
return
|
|
6026
|
+
return h7("message", element);
|
|
6030
6027
|
});
|
|
6031
6028
|
}
|
|
6032
6029
|
if (transformed[0]?.type === "p") {
|
|
6033
6030
|
const pElement = transformed.shift();
|
|
6034
6031
|
const pElementContent = pElement.attrs["content"];
|
|
6035
6032
|
if (pElementContent) {
|
|
6036
|
-
transformed.unshift(
|
|
6033
|
+
transformed.unshift(h7.text(pElementContent));
|
|
6037
6034
|
} else {
|
|
6038
6035
|
transformed.unshift(...pElement.children);
|
|
6039
6036
|
}
|
|
@@ -6066,7 +6063,7 @@ __name(transformAndEscape, "transformAndEscape");
|
|
|
6066
6063
|
// src/renders/voice.ts
|
|
6067
6064
|
import { marked } from "marked";
|
|
6068
6065
|
import { logger as logger11 } from "koishi-plugin-chatluna";
|
|
6069
|
-
import { h as
|
|
6066
|
+
import { h as h8, Schema as Schema4 } from "koishi";
|
|
6070
6067
|
var VoiceRenderer = class extends Renderer {
|
|
6071
6068
|
static {
|
|
6072
6069
|
__name(this, "VoiceRenderer");
|
|
@@ -6078,7 +6075,7 @@ var VoiceRenderer = class extends Renderer {
|
|
|
6078
6075
|
return {
|
|
6079
6076
|
element: await Promise.all(
|
|
6080
6077
|
splitMessages.map(async (text) => {
|
|
6081
|
-
return
|
|
6078
|
+
return h8(
|
|
6082
6079
|
"message",
|
|
6083
6080
|
await this._renderToVoice(text, options)
|
|
6084
6081
|
);
|
|
@@ -6133,14 +6130,14 @@ function renderTokens(tokens) {
|
|
|
6133
6130
|
__name(renderTokens, "renderTokens");
|
|
6134
6131
|
|
|
6135
6132
|
// src/renders/raw.ts
|
|
6136
|
-
import { h as
|
|
6133
|
+
import { h as h9, Schema as Schema5 } from "koishi";
|
|
6137
6134
|
var RawRenderer = class extends Renderer {
|
|
6138
6135
|
static {
|
|
6139
6136
|
__name(this, "RawRenderer");
|
|
6140
6137
|
}
|
|
6141
6138
|
async render(message, options) {
|
|
6142
6139
|
return {
|
|
6143
|
-
element:
|
|
6140
|
+
element: h9.text(message.content)
|
|
6144
6141
|
};
|
|
6145
6142
|
}
|
|
6146
6143
|
schema = Schema5.const("raw").i18n({
|
|
@@ -6150,7 +6147,7 @@ var RawRenderer = class extends Renderer {
|
|
|
6150
6147
|
};
|
|
6151
6148
|
|
|
6152
6149
|
// src/renders/koishi-element.ts
|
|
6153
|
-
import { h as
|
|
6150
|
+
import { h as h10, Schema as Schema6 } from "koishi";
|
|
6154
6151
|
import he2 from "he";
|
|
6155
6152
|
import { logger as logger12 } from "koishi-plugin-chatluna";
|
|
6156
6153
|
var KoishiElementRenderer = class extends Renderer {
|
|
@@ -6161,7 +6158,7 @@ var KoishiElementRenderer = class extends Renderer {
|
|
|
6161
6158
|
let transformed = transformAndEscape2(message.content);
|
|
6162
6159
|
if (options.split) {
|
|
6163
6160
|
transformed = transformed.map((element) => {
|
|
6164
|
-
return
|
|
6161
|
+
return h10("message", element);
|
|
6165
6162
|
});
|
|
6166
6163
|
}
|
|
6167
6164
|
return {
|
|
@@ -6185,10 +6182,10 @@ function unescape2(element) {
|
|
|
6185
6182
|
__name(unescape2, "unescape");
|
|
6186
6183
|
function transformAndEscape2(source) {
|
|
6187
6184
|
try {
|
|
6188
|
-
return
|
|
6185
|
+
return h10.parse(source).map(unescape2);
|
|
6189
6186
|
} catch (e) {
|
|
6190
6187
|
logger12.error(e);
|
|
6191
|
-
return [
|
|
6188
|
+
return [h10.text(source)];
|
|
6192
6189
|
}
|
|
6193
6190
|
}
|
|
6194
6191
|
__name(transformAndEscape2, "transformAndEscape");
|
|
@@ -6196,7 +6193,7 @@ __name(transformAndEscape2, "transformAndEscape");
|
|
|
6196
6193
|
// src/renders/mixed-voice.ts
|
|
6197
6194
|
import { marked as marked2 } from "marked";
|
|
6198
6195
|
import { logger as logger13 } from "koishi-plugin-chatluna";
|
|
6199
|
-
import { h as
|
|
6196
|
+
import { h as h11, Schema as Schema7 } from "koishi";
|
|
6200
6197
|
var MixedVoiceRenderer = class extends Renderer {
|
|
6201
6198
|
static {
|
|
6202
6199
|
__name(this, "MixedVoiceRenderer");
|
|
@@ -6223,7 +6220,7 @@ var MixedVoiceRenderer = class extends Renderer {
|
|
|
6223
6220
|
let transformed = transformAndEscape(message.content);
|
|
6224
6221
|
if (options.split) {
|
|
6225
6222
|
transformed = transformed.map((element) => {
|
|
6226
|
-
return
|
|
6223
|
+
return h11("message", element);
|
|
6227
6224
|
});
|
|
6228
6225
|
}
|
|
6229
6226
|
return {
|
|
@@ -6312,7 +6309,7 @@ var DefaultRenderer = class {
|
|
|
6312
6309
|
for (const additionalMessage of message.additionalReplyMessages) {
|
|
6313
6310
|
const elements = await rawRenderer.render(additionalMessage, options).then((r) => r.element);
|
|
6314
6311
|
result2.push({
|
|
6315
|
-
element:
|
|
6312
|
+
element: h12(
|
|
6316
6313
|
"message",
|
|
6317
6314
|
{ forward: true },
|
|
6318
6315
|
Array.isArray(elements) ? elements : [elements]
|
|
@@ -1344,11 +1344,12 @@ async function createReactAgent({
|
|
|
1344
1344
|
llm,
|
|
1345
1345
|
tools,
|
|
1346
1346
|
prompt,
|
|
1347
|
-
streamRunnable
|
|
1347
|
+
streamRunnable,
|
|
1348
|
+
instructions
|
|
1348
1349
|
}) {
|
|
1349
1350
|
const toolNames = tools.map((tool) => tool.name);
|
|
1350
1351
|
const instructionsFormat = import_prompts2.PromptTemplate.fromTemplate(
|
|
1351
|
-
FORMAT_INSTRUCTIONS
|
|
1352
|
+
instructions ?? FORMAT_INSTRUCTIONS
|
|
1352
1353
|
).format({
|
|
1353
1354
|
tool_descriptions: renderTextDescriptionAndArgs(tools),
|
|
1354
1355
|
tool_names: toolNames.join(", ")
|
|
@@ -1334,11 +1334,12 @@ async function createReactAgent({
|
|
|
1334
1334
|
llm,
|
|
1335
1335
|
tools,
|
|
1336
1336
|
prompt,
|
|
1337
|
-
streamRunnable
|
|
1337
|
+
streamRunnable,
|
|
1338
|
+
instructions
|
|
1338
1339
|
}) {
|
|
1339
1340
|
const toolNames = tools.map((tool) => tool.name);
|
|
1340
1341
|
const instructionsFormat = PromptTemplate.fromTemplate(
|
|
1341
|
-
FORMAT_INSTRUCTIONS
|
|
1342
|
+
instructions ?? FORMAT_INSTRUCTIONS
|
|
1342
1343
|
).format({
|
|
1343
1344
|
tool_descriptions: renderTextDescriptionAndArgs(tools),
|
|
1344
1345
|
tool_names: toolNames.join(", ")
|
|
@@ -21,6 +21,7 @@ export type CreateReactAgentParams = {
|
|
|
21
21
|
* allowing streaming of intermediate steps. Defaults to true.
|
|
22
22
|
*/
|
|
23
23
|
streamRunnable?: boolean;
|
|
24
|
+
instructions?: string;
|
|
24
25
|
};
|
|
25
26
|
/**
|
|
26
27
|
* Create an agent that uses ReAct prompting.
|
|
@@ -65,7 +66,7 @@ export type CreateReactAgentParams = {
|
|
|
65
66
|
* });
|
|
66
67
|
* ```
|
|
67
68
|
*/
|
|
68
|
-
export declare function createReactAgent({ llm, tools, prompt, streamRunnable }: CreateReactAgentParams): Promise<AgentRunnableSequence<{
|
|
69
|
+
export declare function createReactAgent({ llm, tools, prompt, streamRunnable, instructions }: CreateReactAgentParams): Promise<AgentRunnableSequence<{
|
|
69
70
|
steps: AgentStep[];
|
|
70
71
|
}, import("@langchain/core/agents").AgentAction | import("@langchain/core/agents").AgentFinish>>;
|
|
71
72
|
/**
|
|
@@ -37,6 +37,7 @@ export interface RawPreset {
|
|
|
37
37
|
longMemoryExtractPrompt?: string;
|
|
38
38
|
longMemoryNewQuestionPrompt?: string;
|
|
39
39
|
postHandler?: PostHandler;
|
|
40
|
+
reActInstruction?: string;
|
|
40
41
|
};
|
|
41
42
|
}
|
|
42
43
|
export interface RoleBook {
|
|
@@ -77,6 +78,7 @@ export interface PresetTemplate {
|
|
|
77
78
|
longMemoryExtractPrompt?: string;
|
|
78
79
|
longMemoryNewQuestionPrompt?: string;
|
|
79
80
|
postHandler?: PostHandler;
|
|
81
|
+
reActInstruction?: string;
|
|
80
82
|
};
|
|
81
83
|
}
|
|
82
84
|
export interface KnowledgeConfig {
|