koishi-plugin-chatluna-character 0.0.47 → 0.0.48
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 +98 -147
- package/lib/index.d.ts +148 -44
- package/lib/index.mjs +79 -135
- package/package.json +20 -11
- package/resources/presets/default.yml +44 -15
- package/lib/plugin.d.ts +0 -3
- package/lib/plugins/chat.d.ts +0 -3
- package/lib/plugins/commands.d.ts +0 -3
- package/lib/plugins/config.d.ts +0 -3
- package/lib/plugins/filter.d.ts +0 -5
- package/lib/plugins/interception.d.ts +0 -3
- package/lib/preset.d.ts +0 -17
- package/lib/service/message.d.ts +0 -38
- package/lib/service/sticker.d.ts +0 -10
- package/lib/types.d.ts +0 -37
package/lib/index.cjs
CHANGED
|
@@ -5,15 +5,6 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
5
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
-
var __glob = (map) => (path4) => {
|
|
9
|
-
var fn = map[path4];
|
|
10
|
-
if (fn)
|
|
11
|
-
return fn();
|
|
12
|
-
throw new Error("Module not found in bundle: " + path4);
|
|
13
|
-
};
|
|
14
|
-
var __esm = (fn, res) => function __init() {
|
|
15
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
16
|
-
};
|
|
17
8
|
var __export = (target, all) => {
|
|
18
9
|
for (var name2 in all)
|
|
19
10
|
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
@@ -36,11 +27,22 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
36
27
|
));
|
|
37
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
38
29
|
|
|
39
|
-
// src/
|
|
40
|
-
var
|
|
41
|
-
__export(
|
|
42
|
-
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
Config: () => Config,
|
|
34
|
+
apply: () => apply6,
|
|
35
|
+
inject: () => inject,
|
|
36
|
+
inject2: () => inject2,
|
|
37
|
+
name: () => name
|
|
43
38
|
});
|
|
39
|
+
module.exports = __toCommonJS(src_exports);
|
|
40
|
+
var import_koishi6 = require("koishi");
|
|
41
|
+
|
|
42
|
+
// src/plugins/chat.ts
|
|
43
|
+
var import_messages = require("@langchain/core/messages");
|
|
44
|
+
var import_koishi = require("koishi");
|
|
45
|
+
var import_count_tokens = require("koishi-plugin-chatluna/llm-core/utils/count_tokens");
|
|
44
46
|
async function apply(ctx, config) {
|
|
45
47
|
const service = ctx.chatluna_character;
|
|
46
48
|
const preset = service.preset;
|
|
@@ -108,7 +110,8 @@ async function apply(ctx, config) {
|
|
|
108
110
|
await currentPreset.input.format({
|
|
109
111
|
history_new: recentMessage,
|
|
110
112
|
history_last: lastMessage,
|
|
111
|
-
time: (/* @__PURE__ */ new Date()).toLocaleString()
|
|
113
|
+
time: (/* @__PURE__ */ new Date()).toLocaleString(),
|
|
114
|
+
status: temp.status ?? currentPreset.status ?? ""
|
|
112
115
|
})
|
|
113
116
|
);
|
|
114
117
|
const completionMessages = await formatCompletionMessages(
|
|
@@ -150,11 +153,10 @@ async function apply(ctx, config) {
|
|
|
150
153
|
return;
|
|
151
154
|
}
|
|
152
155
|
temp.completionMessages.push(humanMessage, responseMessage);
|
|
153
|
-
if (temp.completionMessages.length >
|
|
154
|
-
|
|
155
|
-
temp.completionMessages.shift();
|
|
156
|
-
}
|
|
156
|
+
if (temp.completionMessages.length > 2) {
|
|
157
|
+
temp.completionMessages.length = 0;
|
|
157
158
|
}
|
|
159
|
+
temp.status = parsedResponse.status;
|
|
158
160
|
const random = new import_koishi.Random();
|
|
159
161
|
for (const elements of parsedResponse.elements) {
|
|
160
162
|
const text = elements.map((element) => element.attrs.content ?? "").join("");
|
|
@@ -165,9 +167,14 @@ async function apply(ctx, config) {
|
|
|
165
167
|
if (config.splitVoice !== true && parsedResponse.messageType === "voice") {
|
|
166
168
|
maxTime = parsedResponse.rawMessage.length * copyOfConfig.typingTime + 100;
|
|
167
169
|
await (0, import_koishi.sleep)(random.int(maxTime / 4, maxTime / 2));
|
|
168
|
-
|
|
169
|
-
await
|
|
170
|
-
|
|
170
|
+
try {
|
|
171
|
+
await session.send(
|
|
172
|
+
await ctx.vits.say({ input: parsedResponse.rawMessage })
|
|
173
|
+
);
|
|
174
|
+
} catch (e) {
|
|
175
|
+
logger.error(e);
|
|
176
|
+
await session.send(elements);
|
|
177
|
+
}
|
|
171
178
|
break;
|
|
172
179
|
}
|
|
173
180
|
try {
|
|
@@ -201,16 +208,20 @@ async function apply(ctx, config) {
|
|
|
201
208
|
await service.broadcastOnBot(session, parsedResponse.elements.flat());
|
|
202
209
|
});
|
|
203
210
|
}
|
|
211
|
+
__name(apply, "apply");
|
|
204
212
|
function isEmoticonStatement(text) {
|
|
205
213
|
const regex = /^[\p{P}\p{S}\p{Z}\p{M}\p{N}\p{L}\s]*\p{So}[\p{P}\p{S}\p{Z}\p{M}\p{N}\p{L}\s]*$/u;
|
|
206
214
|
return regex.test(text);
|
|
207
215
|
}
|
|
216
|
+
__name(isEmoticonStatement, "isEmoticonStatement");
|
|
208
217
|
function parseResponse(response, useAt = true) {
|
|
209
218
|
let rawMessage;
|
|
210
219
|
let parsedMessage = "";
|
|
211
220
|
let messageType = "text";
|
|
221
|
+
let status = "";
|
|
212
222
|
try {
|
|
213
223
|
rawMessage = response.match(/<message>\s*(.*?)\s*<\/message>/)?.[1];
|
|
224
|
+
status = response.match(/<status>(.*?)<\/status>/)?.[1];
|
|
214
225
|
if (rawMessage == null) {
|
|
215
226
|
logger.debug("failed to parse response: " + response);
|
|
216
227
|
rawMessage = response.substring(
|
|
@@ -273,9 +284,11 @@ function parseResponse(response, useAt = true) {
|
|
|
273
284
|
return {
|
|
274
285
|
elements: resultElements,
|
|
275
286
|
rawMessage: parsedMessage,
|
|
287
|
+
status,
|
|
276
288
|
messageType
|
|
277
289
|
};
|
|
278
290
|
}
|
|
291
|
+
__name(parseResponse, "parseResponse");
|
|
279
292
|
function splitSentence(text) {
|
|
280
293
|
const result = [];
|
|
281
294
|
const lines = text.split("\n").filter((line) => line.trim().length > 0).join(" ");
|
|
@@ -352,6 +365,7 @@ function splitSentence(text) {
|
|
|
352
365
|
}
|
|
353
366
|
return result.filter((item) => punctuations.indexOf(item) === -1);
|
|
354
367
|
}
|
|
368
|
+
__name(splitSentence, "splitSentence");
|
|
355
369
|
function matchAt(str) {
|
|
356
370
|
const atRegex = /([((]).*-(\d+)-<at>([))])/g;
|
|
357
371
|
return [...str.matchAll(atRegex)].map((item) => {
|
|
@@ -362,6 +376,7 @@ function matchAt(str) {
|
|
|
362
376
|
};
|
|
363
377
|
});
|
|
364
378
|
}
|
|
379
|
+
__name(matchAt, "matchAt");
|
|
365
380
|
async function formatCompletionMessages(messages, humanMessage, config, model) {
|
|
366
381
|
const maxTokens = config.maxTokens - 600;
|
|
367
382
|
const systemMessage = messages.shift();
|
|
@@ -385,6 +400,7 @@ async function formatCompletionMessages(messages, humanMessage, config, model) {
|
|
|
385
400
|
result.unshift(systemMessage);
|
|
386
401
|
return result;
|
|
387
402
|
}
|
|
403
|
+
__name(formatCompletionMessages, "formatCompletionMessages");
|
|
388
404
|
async function formatMessage(messages, config, model, systemPrompt, historyPrompt) {
|
|
389
405
|
const maxTokens = config.maxTokens - 300;
|
|
390
406
|
let currentTokens = 0;
|
|
@@ -413,28 +429,11 @@ async function formatMessage(messages, config, model, systemPrompt, historyPromp
|
|
|
413
429
|
}
|
|
414
430
|
return [calculatedMessages, lastMessage];
|
|
415
431
|
}
|
|
416
|
-
|
|
417
|
-
var
|
|
418
|
-
"src/plugins/chat.ts"() {
|
|
419
|
-
import_messages = require("@langchain/core/messages");
|
|
420
|
-
import_koishi = require("koishi");
|
|
421
|
-
import_count_tokens = require("koishi-plugin-chatluna/llm-core/utils/count_tokens");
|
|
422
|
-
__name(apply, "apply");
|
|
423
|
-
__name(isEmoticonStatement, "isEmoticonStatement");
|
|
424
|
-
__name(parseResponse, "parseResponse");
|
|
425
|
-
__name(splitSentence, "splitSentence");
|
|
426
|
-
__name(matchAt, "matchAt");
|
|
427
|
-
__name(formatCompletionMessages, "formatCompletionMessages");
|
|
428
|
-
__name(formatMessage, "formatMessage");
|
|
429
|
-
}
|
|
430
|
-
});
|
|
432
|
+
__name(formatMessage, "formatMessage");
|
|
433
|
+
var logger;
|
|
431
434
|
|
|
432
435
|
// src/plugins/filter.ts
|
|
433
|
-
var
|
|
434
|
-
__export(filter_exports, {
|
|
435
|
-
apply: () => apply2,
|
|
436
|
-
groupInfos: () => groupInfos
|
|
437
|
-
});
|
|
436
|
+
var groupInfos = {};
|
|
438
437
|
async function apply2(ctx, config) {
|
|
439
438
|
const maxMessages = config.messageInterval;
|
|
440
439
|
const service = ctx.chatluna_character;
|
|
@@ -517,19 +516,9 @@ async function apply2(ctx, config) {
|
|
|
517
516
|
return false;
|
|
518
517
|
});
|
|
519
518
|
}
|
|
520
|
-
|
|
521
|
-
var init_filter = __esm({
|
|
522
|
-
"src/plugins/filter.ts"() {
|
|
523
|
-
groupInfos = {};
|
|
524
|
-
__name(apply2, "apply");
|
|
525
|
-
}
|
|
526
|
-
});
|
|
519
|
+
__name(apply2, "apply");
|
|
527
520
|
|
|
528
521
|
// src/plugins/commands.ts
|
|
529
|
-
var commands_exports = {};
|
|
530
|
-
__export(commands_exports, {
|
|
531
|
-
apply: () => apply3
|
|
532
|
-
});
|
|
533
522
|
function apply3(ctx, config) {
|
|
534
523
|
ctx.command("chatluna.character", "角色扮演相关命令");
|
|
535
524
|
ctx.command(
|
|
@@ -553,18 +542,11 @@ function apply3(ctx, config) {
|
|
|
553
542
|
return `已清除群组 ${groupId} 的聊天记录`;
|
|
554
543
|
});
|
|
555
544
|
}
|
|
556
|
-
|
|
557
|
-
"src/plugins/commands.ts"() {
|
|
558
|
-
init_filter();
|
|
559
|
-
__name(apply3, "apply");
|
|
560
|
-
}
|
|
561
|
-
});
|
|
545
|
+
__name(apply3, "apply");
|
|
562
546
|
|
|
563
547
|
// src/plugins/config.ts
|
|
564
|
-
var
|
|
565
|
-
|
|
566
|
-
apply: () => apply4
|
|
567
|
-
});
|
|
548
|
+
var import_koishi2 = require("koishi");
|
|
549
|
+
var import_types = require("koishi-plugin-chatluna/llm-core/platform/types");
|
|
568
550
|
async function apply4(ctx, config) {
|
|
569
551
|
ctx.on("chatluna/model-added", async (service) => {
|
|
570
552
|
ctx.schema.set("model", import_koishi2.Schema.union(await getModelNames(service)));
|
|
@@ -577,24 +559,13 @@ async function apply4(ctx, config) {
|
|
|
577
559
|
import_koishi2.Schema.union(await getModelNames(ctx.chatluna.platform))
|
|
578
560
|
);
|
|
579
561
|
}
|
|
562
|
+
__name(apply4, "apply");
|
|
580
563
|
async function getModelNames(service) {
|
|
581
564
|
return service.getAllModels(import_types.ModelType.llm).map((m) => import_koishi2.Schema.const(m));
|
|
582
565
|
}
|
|
583
|
-
|
|
584
|
-
var init_config = __esm({
|
|
585
|
-
"src/plugins/config.ts"() {
|
|
586
|
-
import_koishi2 = require("koishi");
|
|
587
|
-
import_types = require("koishi-plugin-chatluna/llm-core/platform/types");
|
|
588
|
-
__name(apply4, "apply");
|
|
589
|
-
__name(getModelNames, "getModelNames");
|
|
590
|
-
}
|
|
591
|
-
});
|
|
566
|
+
__name(getModelNames, "getModelNames");
|
|
592
567
|
|
|
593
568
|
// src/plugins/interception.ts
|
|
594
|
-
var interception_exports = {};
|
|
595
|
-
__export(interception_exports, {
|
|
596
|
-
apply: () => apply5
|
|
597
|
-
});
|
|
598
569
|
function apply5(ctx, config) {
|
|
599
570
|
ctx.on("chatluna/before-check-sender", async (session) => {
|
|
600
571
|
const guildId = session.guildId;
|
|
@@ -622,63 +593,34 @@ function apply5(ctx, config) {
|
|
|
622
593
|
return config.disableChatLuna;
|
|
623
594
|
});
|
|
624
595
|
}
|
|
625
|
-
|
|
626
|
-
"src/plugins/interception.ts"() {
|
|
627
|
-
__name(apply5, "apply");
|
|
628
|
-
}
|
|
629
|
-
});
|
|
630
|
-
|
|
631
|
-
// src/index.ts
|
|
632
|
-
var src_exports = {};
|
|
633
|
-
__export(src_exports, {
|
|
634
|
-
Config: () => Config,
|
|
635
|
-
apply: () => apply6,
|
|
636
|
-
inject: () => inject,
|
|
637
|
-
name: () => name
|
|
638
|
-
});
|
|
639
|
-
module.exports = __toCommonJS(src_exports);
|
|
640
|
-
var import_koishi6 = require("koishi");
|
|
641
|
-
|
|
642
|
-
// src/plugin.ts
|
|
643
|
-
var import_promises = __toESM(require("fs/promises"));
|
|
644
|
-
var import_path = __toESM(require("path"));
|
|
645
|
-
|
|
646
|
-
// import("./plugins/**/*.ts") in src/plugin.ts
|
|
647
|
-
var globImport_plugins_ts = __glob({
|
|
648
|
-
"./plugins/chat.ts": () => Promise.resolve().then(() => (init_chat(), chat_exports)),
|
|
649
|
-
"./plugins/commands.ts": () => Promise.resolve().then(() => (init_commands(), commands_exports)),
|
|
650
|
-
"./plugins/config.ts": () => Promise.resolve().then(() => (init_config(), config_exports)),
|
|
651
|
-
"./plugins/filter.ts": () => Promise.resolve().then(() => (init_filter(), filter_exports)),
|
|
652
|
-
"./plugins/interception.ts": () => Promise.resolve().then(() => (init_interception(), interception_exports))
|
|
653
|
-
});
|
|
596
|
+
__name(apply5, "apply");
|
|
654
597
|
|
|
655
598
|
// src/plugin.ts
|
|
656
|
-
async function plugins(ctx,
|
|
657
|
-
const
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
if (command.apply) {
|
|
664
|
-
await command.apply(ctx, config);
|
|
665
|
-
}
|
|
599
|
+
async function plugins(ctx, parent) {
|
|
600
|
+
const middlewares = (
|
|
601
|
+
// middleware start
|
|
602
|
+
[apply, apply3, apply4, apply2, apply5]
|
|
603
|
+
);
|
|
604
|
+
for (const middleware of middlewares) {
|
|
605
|
+
await middleware(ctx, parent);
|
|
666
606
|
}
|
|
667
607
|
}
|
|
668
608
|
__name(plugins, "plugins");
|
|
669
609
|
|
|
670
610
|
// src/service/message.ts
|
|
671
|
-
var import_events = __toESM(require("events"));
|
|
611
|
+
var import_events = __toESM(require("events"), 1);
|
|
672
612
|
var import_koishi5 = require("koishi");
|
|
673
613
|
var import_logger = require("koishi-plugin-chatluna/utils/logger");
|
|
674
614
|
|
|
675
615
|
// src/preset.ts
|
|
676
616
|
var import_prompts = require("@langchain/core/prompts");
|
|
677
|
-
var
|
|
617
|
+
var import_promises = __toESM(require("fs/promises"), 1);
|
|
678
618
|
var import_js_yaml = require("js-yaml");
|
|
679
619
|
var import_koishi3 = require("koishi");
|
|
680
620
|
var import_error = require("koishi-plugin-chatluna/utils/error");
|
|
681
|
-
var
|
|
621
|
+
var import_path = __toESM(require("path"), 1);
|
|
622
|
+
var import_url = require("url");
|
|
623
|
+
var import_meta = {};
|
|
682
624
|
var Preset = class {
|
|
683
625
|
constructor(ctx) {
|
|
684
626
|
this.ctx = ctx;
|
|
@@ -690,19 +632,19 @@ var Preset = class {
|
|
|
690
632
|
async loadAllPreset() {
|
|
691
633
|
await this._checkPresetDir();
|
|
692
634
|
const presetDir = this.resolvePresetDir();
|
|
693
|
-
const files = await
|
|
635
|
+
const files = await import_promises.default.readdir(presetDir);
|
|
694
636
|
this._presets.length = 0;
|
|
695
637
|
for (const file of files) {
|
|
696
|
-
const extension =
|
|
638
|
+
const extension = import_path.default.extname(file);
|
|
697
639
|
if (extension !== ".yml") {
|
|
698
640
|
continue;
|
|
699
641
|
}
|
|
700
|
-
const rawText = await
|
|
701
|
-
|
|
642
|
+
const rawText = await import_promises.default.readFile(
|
|
643
|
+
import_path.default.join(presetDir, file),
|
|
702
644
|
"utf-8"
|
|
703
645
|
);
|
|
704
646
|
const preset = loadPreset(rawText);
|
|
705
|
-
preset.path =
|
|
647
|
+
preset.path = import_path.default.join(presetDir, file);
|
|
706
648
|
this._presets.push(preset);
|
|
707
649
|
}
|
|
708
650
|
this.ctx.schema.set(
|
|
@@ -753,15 +695,15 @@ var Preset = class {
|
|
|
753
695
|
await this._copyDefaultPresets();
|
|
754
696
|
}
|
|
755
697
|
resolvePresetDir() {
|
|
756
|
-
return
|
|
698
|
+
return import_path.default.resolve(this.ctx.baseDir, "data/chathub/character/presets");
|
|
757
699
|
}
|
|
758
700
|
async _checkPresetDir() {
|
|
759
|
-
const presetDir =
|
|
701
|
+
const presetDir = import_path.default.join(this.resolvePresetDir());
|
|
760
702
|
try {
|
|
761
|
-
await
|
|
703
|
+
await import_promises.default.access(presetDir);
|
|
762
704
|
} catch (err) {
|
|
763
705
|
if (err.code === "ENOENT") {
|
|
764
|
-
await
|
|
706
|
+
await import_promises.default.mkdir(presetDir, { recursive: true });
|
|
765
707
|
await this._copyDefaultPresets();
|
|
766
708
|
} else {
|
|
767
709
|
throw err;
|
|
@@ -769,18 +711,19 @@ var Preset = class {
|
|
|
769
711
|
}
|
|
770
712
|
}
|
|
771
713
|
async _copyDefaultPresets() {
|
|
772
|
-
const currentPresetDir =
|
|
773
|
-
const
|
|
774
|
-
const
|
|
714
|
+
const currentPresetDir = import_path.default.join(this.resolvePresetDir());
|
|
715
|
+
const dirname = __dirname?.length > 0 ? __dirname : (0, import_url.fileURLToPath)(import_meta.url);
|
|
716
|
+
const defaultPresetDir = import_path.default.join(dirname, "../resources/presets");
|
|
717
|
+
const files = await import_promises.default.readdir(defaultPresetDir);
|
|
775
718
|
for (const file of files) {
|
|
776
|
-
const filePath =
|
|
777
|
-
const fileStat = await
|
|
719
|
+
const filePath = import_path.default.join(defaultPresetDir, file);
|
|
720
|
+
const fileStat = await import_promises.default.stat(filePath);
|
|
778
721
|
if (fileStat.isFile()) {
|
|
779
|
-
await
|
|
722
|
+
await import_promises.default.mkdir(currentPresetDir, { recursive: true });
|
|
780
723
|
this.ctx.chatluna_character.logger.debug(
|
|
781
724
|
`copy preset file ${filePath} to ${currentPresetDir}`
|
|
782
725
|
);
|
|
783
|
-
await
|
|
726
|
+
await import_promises.default.copyFile(filePath, import_path.default.join(currentPresetDir, file));
|
|
784
727
|
}
|
|
785
728
|
}
|
|
786
729
|
}
|
|
@@ -799,8 +742,10 @@ __name(loadPreset, "loadPreset");
|
|
|
799
742
|
|
|
800
743
|
// src/service/sticker.ts
|
|
801
744
|
var import_koishi4 = require("koishi");
|
|
802
|
-
var
|
|
803
|
-
var
|
|
745
|
+
var import_path2 = __toESM(require("path"), 1);
|
|
746
|
+
var import_promises2 = __toESM(require("fs/promises"), 1);
|
|
747
|
+
var import_url2 = require("url");
|
|
748
|
+
var import_meta2 = {};
|
|
804
749
|
var StickerService = class {
|
|
805
750
|
constructor(_ctx, _config) {
|
|
806
751
|
this._ctx = _ctx;
|
|
@@ -811,24 +756,25 @@ var StickerService = class {
|
|
|
811
756
|
}
|
|
812
757
|
_stickers;
|
|
813
758
|
async init() {
|
|
814
|
-
const sickerDir =
|
|
759
|
+
const sickerDir = import_path2.default.resolve(
|
|
815
760
|
this._ctx.baseDir,
|
|
816
761
|
"data/chathub/character/sticker"
|
|
817
762
|
);
|
|
818
763
|
try {
|
|
819
|
-
await
|
|
764
|
+
await import_promises2.default.access(sickerDir);
|
|
820
765
|
} catch (error) {
|
|
821
|
-
await
|
|
822
|
-
|
|
823
|
-
|
|
766
|
+
await import_promises2.default.mkdir(sickerDir, { recursive: true });
|
|
767
|
+
const dirname = __dirname?.length > 0 ? __dirname : (0, import_url2.fileURLToPath)(import_meta2.url);
|
|
768
|
+
await import_promises2.default.cp(
|
|
769
|
+
import_path2.default.resolve(dirname, "../resources/sticker"),
|
|
824
770
|
sickerDir,
|
|
825
771
|
{
|
|
826
772
|
recursive: true
|
|
827
773
|
}
|
|
828
774
|
);
|
|
829
775
|
}
|
|
830
|
-
const files = await
|
|
831
|
-
this._stickers = files.map((file) =>
|
|
776
|
+
const files = await import_promises2.default.readdir(sickerDir);
|
|
777
|
+
this._stickers = files.map((file) => import_path2.default.resolve(sickerDir, file));
|
|
832
778
|
}
|
|
833
779
|
async randomStick() {
|
|
834
780
|
const random = Math.random();
|
|
@@ -843,11 +789,11 @@ var StickerService = class {
|
|
|
843
789
|
this._ctx.root.chatluna_character.logger.debug(
|
|
844
790
|
`send sticker: ${sticker}`
|
|
845
791
|
);
|
|
846
|
-
return import_koishi4.h.image(await (0,
|
|
792
|
+
return import_koishi4.h.image(await (0, import_promises2.readFile)(sticker), `image/${getFileType(sticker)}`);
|
|
847
793
|
}
|
|
848
794
|
};
|
|
849
|
-
function getFileType(
|
|
850
|
-
const type =
|
|
795
|
+
function getFileType(path3) {
|
|
796
|
+
const type = path3.split(".").pop().toLocaleLowerCase();
|
|
851
797
|
if (type === "jpg") {
|
|
852
798
|
return "jpeg";
|
|
853
799
|
}
|
|
@@ -1000,7 +946,7 @@ var MessageCollector = class extends import_koishi5.Service {
|
|
|
1000
946
|
}
|
|
1001
947
|
const message = {
|
|
1002
948
|
content,
|
|
1003
|
-
name: session.author.name,
|
|
949
|
+
name: session.author.nick ?? session.author.name,
|
|
1004
950
|
id: session.author.id,
|
|
1005
951
|
quote: session.quote ? {
|
|
1006
952
|
content: mapElementToString(
|
|
@@ -1069,7 +1015,7 @@ function apply6(ctx, config) {
|
|
|
1069
1015
|
await ctx2.chatluna_character.preset.loadAllPreset();
|
|
1070
1016
|
await plugins(ctx2, config2);
|
|
1071
1017
|
},
|
|
1072
|
-
inject: Object.assign({},
|
|
1018
|
+
inject: Object.assign({}, inject2, {
|
|
1073
1019
|
chatluna_character: {
|
|
1074
1020
|
required: true
|
|
1075
1021
|
}
|
|
@@ -1101,6 +1047,10 @@ function apply6(ctx, config) {
|
|
|
1101
1047
|
}
|
|
1102
1048
|
__name(apply6, "apply");
|
|
1103
1049
|
var inject = {
|
|
1050
|
+
required: ["chatluna", "cache"],
|
|
1051
|
+
optional: ["chatluna_character", "vits"]
|
|
1052
|
+
};
|
|
1053
|
+
var inject2 = {
|
|
1104
1054
|
chatluna: {
|
|
1105
1055
|
required: true
|
|
1106
1056
|
},
|
|
@@ -1175,5 +1125,6 @@ var name = "chatluna-character";
|
|
|
1175
1125
|
Config,
|
|
1176
1126
|
apply,
|
|
1177
1127
|
inject,
|
|
1128
|
+
inject2,
|
|
1178
1129
|
name
|
|
1179
1130
|
});
|
package/lib/index.d.ts
CHANGED
|
@@ -1,44 +1,148 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
export
|
|
44
|
-
export
|
|
1
|
+
import { BaseMessage } from '@langchain/core/messages';
|
|
2
|
+
import { PromptTemplate } from '@langchain/core/prompts';
|
|
3
|
+
import { Context, h, Logger, Service, Session, Schema } from 'koishi';
|
|
4
|
+
import { ChatLunaPlugin } from 'koishi-plugin-chatluna/services/chat';
|
|
5
|
+
export interface Message {
|
|
6
|
+
content: string;
|
|
7
|
+
name: string;
|
|
8
|
+
id: string;
|
|
9
|
+
quote?: Message;
|
|
10
|
+
}
|
|
11
|
+
export interface GroupTemp {
|
|
12
|
+
completionMessages: BaseMessage[];
|
|
13
|
+
status?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface GuildConfig {
|
|
16
|
+
preset: string;
|
|
17
|
+
messageInterval: number;
|
|
18
|
+
maxTokens: number;
|
|
19
|
+
isNickname: boolean;
|
|
20
|
+
isForceMute: boolean;
|
|
21
|
+
sendStickerProbability: number;
|
|
22
|
+
coolDownTime: number;
|
|
23
|
+
splitVoice: boolean;
|
|
24
|
+
isAt: boolean;
|
|
25
|
+
typingTime: number;
|
|
26
|
+
messageProbability: number;
|
|
27
|
+
muteTime: number;
|
|
28
|
+
}
|
|
29
|
+
export interface PresetTemplate {
|
|
30
|
+
name: string;
|
|
31
|
+
status?: string;
|
|
32
|
+
nick_name: string[];
|
|
33
|
+
input: PromptTemplate;
|
|
34
|
+
system: PromptTemplate;
|
|
35
|
+
mute_keyword?: string[];
|
|
36
|
+
path?: string;
|
|
37
|
+
}
|
|
38
|
+
export interface GroupInfo {
|
|
39
|
+
messageCount: number;
|
|
40
|
+
messageSendProbability: number;
|
|
41
|
+
}
|
|
42
|
+
export function apply(ctx: Context, config: Config): Promise<void>;
|
|
43
|
+
export const groupInfos: Record<string, GroupInfo>;
|
|
44
|
+
export function apply(ctx: Context, config: Config): Promise<void>;
|
|
45
|
+
export function apply(ctx: Context, config: Config): void;
|
|
46
|
+
export function apply(ctx: Context, config: Config): Promise<void>;
|
|
47
|
+
export function apply(ctx: Context, config: Config): void;
|
|
48
|
+
export function plugins(ctx: Context, parent: Config): Promise<void>;
|
|
49
|
+
export class Preset {
|
|
50
|
+
private readonly ctx;
|
|
51
|
+
private readonly _presets;
|
|
52
|
+
constructor(ctx: Context);
|
|
53
|
+
loadAllPreset(): Promise<void>;
|
|
54
|
+
getPreset(triggerKeyword: string, loadForDisk?: boolean, throwError?: boolean): Promise<PresetTemplate>;
|
|
55
|
+
getPresetForCache(triggerKeyword: string, throwError?: boolean): PresetTemplate;
|
|
56
|
+
getDefaultPreset(): Promise<PresetTemplate>;
|
|
57
|
+
getAllPreset(): Promise<string[]>;
|
|
58
|
+
resetDefaultPreset(): Promise<void>;
|
|
59
|
+
resolvePresetDir(): string;
|
|
60
|
+
private _checkPresetDir;
|
|
61
|
+
private _copyDefaultPresets;
|
|
62
|
+
}
|
|
63
|
+
export function loadPreset(text: string): PresetTemplate;
|
|
64
|
+
export class StickerService {
|
|
65
|
+
private _ctx;
|
|
66
|
+
private _config;
|
|
67
|
+
private _stickers;
|
|
68
|
+
constructor(_ctx: Context, _config: Config);
|
|
69
|
+
init(): Promise<void>;
|
|
70
|
+
randomStick(): Promise<h>;
|
|
71
|
+
}
|
|
72
|
+
export class MessageCollector extends Service {
|
|
73
|
+
readonly ctx: Context;
|
|
74
|
+
_config: Config;
|
|
75
|
+
private _messages;
|
|
76
|
+
private _eventEmitter;
|
|
77
|
+
private _filters;
|
|
78
|
+
private _groupLocks;
|
|
79
|
+
private _groupTemp;
|
|
80
|
+
stickerService: StickerService;
|
|
81
|
+
preset: Preset;
|
|
82
|
+
logger: Logger;
|
|
83
|
+
constructor(ctx: Context, _config: Config);
|
|
84
|
+
addFilter(filter: MessageCollectorFilter): void;
|
|
85
|
+
mute(session: Session, time: number): void;
|
|
86
|
+
collect(func: (session: Session, messages: Message[]) => Promise<void>): void;
|
|
87
|
+
getMessages(groupId: string): Message[];
|
|
88
|
+
isMute(session: Session): boolean;
|
|
89
|
+
updateTemp(session: Session, temp: GroupTemp): Promise<void>;
|
|
90
|
+
getTemp(session: Session): Promise<GroupTemp>;
|
|
91
|
+
private _getGroupLocks;
|
|
92
|
+
private _lock;
|
|
93
|
+
private _unlock;
|
|
94
|
+
clear(groupId?: string): void;
|
|
95
|
+
broadcastOnBot(session: Session, elements: h[]): Promise<void>;
|
|
96
|
+
broadcast(session: Session): Promise<boolean>;
|
|
97
|
+
}
|
|
98
|
+
type MessageCollectorFilter = (session: Session, message: Message) => boolean;
|
|
99
|
+
declare module 'koishi' {
|
|
100
|
+
interface Context {
|
|
101
|
+
chatluna_character: MessageCollector;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
export function apply(ctx: Context, config: Config): void;
|
|
105
|
+
export const inject: {
|
|
106
|
+
required: string[];
|
|
107
|
+
optional: string[];
|
|
108
|
+
};
|
|
109
|
+
export const inject2: {
|
|
110
|
+
chatluna: {
|
|
111
|
+
required: boolean;
|
|
112
|
+
};
|
|
113
|
+
cache: {
|
|
114
|
+
required: boolean;
|
|
115
|
+
};
|
|
116
|
+
chatluna_character: {
|
|
117
|
+
required: boolean;
|
|
118
|
+
};
|
|
119
|
+
vits: {
|
|
120
|
+
required: boolean;
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
export interface Config extends ChatLunaPlugin.Config {
|
|
124
|
+
model: string;
|
|
125
|
+
maxMessages: number;
|
|
126
|
+
messageInterval: number;
|
|
127
|
+
messageProbability: number;
|
|
128
|
+
maxTokens: number;
|
|
129
|
+
applyGroup: string[];
|
|
130
|
+
modelOverride: {
|
|
131
|
+
groupId: string;
|
|
132
|
+
model: string;
|
|
133
|
+
}[];
|
|
134
|
+
configs: Record<string, GuildConfig>;
|
|
135
|
+
defaultPreset: string;
|
|
136
|
+
isNickname: boolean;
|
|
137
|
+
isForceMute: boolean;
|
|
138
|
+
sendStickerProbability: number;
|
|
139
|
+
coolDownTime: number;
|
|
140
|
+
typingTime: number;
|
|
141
|
+
muteTime: number;
|
|
142
|
+
disableChatLuna: boolean;
|
|
143
|
+
whiteListDisableChatLuna: string[];
|
|
144
|
+
splitVoice: boolean;
|
|
145
|
+
isAt: boolean;
|
|
146
|
+
}
|
|
147
|
+
export const Config: Schema<Config>;
|
|
148
|
+
export const name = "chatluna-character";
|