koishi-plugin-chatluna-toolbox 0.0.15 → 0.0.17
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/README.md +4 -4
- package/lib/index.js +77 -67
- package/package.json +14 -13
package/README.md
CHANGED
|
@@ -58,15 +58,15 @@ QQ 头像工具会把 HTTP/HTTPS 图片先转为 OneBot `base64://` 文件再提
|
|
|
58
58
|
### 4. 构建
|
|
59
59
|
|
|
60
60
|
```bash
|
|
61
|
-
|
|
61
|
+
yarn build
|
|
62
62
|
```
|
|
63
63
|
|
|
64
64
|
## 开发命令
|
|
65
65
|
|
|
66
66
|
```bash
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
yarn typecheck
|
|
68
|
+
yarn build
|
|
69
|
+
yarn test
|
|
70
70
|
```
|
|
71
71
|
|
|
72
72
|
## 仓库地址
|
package/lib/index.js
CHANGED
|
@@ -457,8 +457,10 @@ var import_koishi5 = require("koishi");
|
|
|
457
457
|
// src/schema/basic-settings.ts
|
|
458
458
|
var import_koishi = require("koishi");
|
|
459
459
|
var BasicSettingsSchema = import_koishi.Schema.object({
|
|
460
|
-
|
|
461
|
-
|
|
460
|
+
oneBotProtocol: import_koishi.Schema.union([
|
|
461
|
+
import_koishi.Schema.const("napcat").description("NapCat"),
|
|
462
|
+
import_koishi.Schema.const("llbot").description("LLBot")
|
|
463
|
+
]).default("napcat").description("\u9009\u62E9 OneBot \u534F\u8BAE")
|
|
462
464
|
}).description("\u57FA\u7840\u8BBE\u7F6E");
|
|
463
465
|
|
|
464
466
|
// src/schema/native-tools.ts
|
|
@@ -477,47 +479,47 @@ var DEFAULT_DELETE_MESSAGE_TOOL_DESCRIPTION = "\u6839\u636E\u6D88\u606F ID \u64A
|
|
|
477
479
|
// src/schema/native-tools.ts
|
|
478
480
|
var NativeToolsSchema = import_koishi2.Schema.object({
|
|
479
481
|
poke: import_koishi2.Schema.object({
|
|
480
|
-
enabled: import_koishi2.Schema.boolean().default(false).description(
|
|
482
|
+
enabled: import_koishi2.Schema.boolean().default(false).description(`\u6CE8\u518C ChatLuna \u539F\u751F\u5DE5\u5177\uFF1A\u6233\u4E00\u6233\uFF0C\u4E0E**XML \u6233\u4E00\u6233\u8C03\u7528**\u4E8C\u9009\u4E00`),
|
|
481
483
|
toolName: import_koishi2.Schema.string().default("poke_user").description("\u5DE5\u5177\u540D\u79F0"),
|
|
482
484
|
description: import_koishi2.Schema.string().default(DEFAULT_POKE_TOOL_DESCRIPTION).description("\u5DE5\u5177\u63CF\u8FF0")
|
|
483
485
|
}).description("\u6233\u4E00\u6233\u5DE5\u5177").collapse(),
|
|
484
486
|
setSelfProfile: import_koishi2.Schema.object({
|
|
485
487
|
enabled: import_koishi2.Schema.boolean().default(false).description(
|
|
486
|
-
|
|
488
|
+
`\u6CE8\u518C ChatLuna \u539F\u751F\u5DE5\u5177\uFF1A\u4FEE\u6539\u81EA\u8EAB\u8D26\u6237\u4FE1\u606F\uFF0C\u652F\u6301\u6635\u79F0 / \u7B7E\u540D / \u6027\u522B`
|
|
487
489
|
),
|
|
488
490
|
toolName: import_koishi2.Schema.string().default("set_self_profile").description("\u5DE5\u5177\u540D\u79F0"),
|
|
489
491
|
description: import_koishi2.Schema.string().default(DEFAULT_SET_SELF_PROFILE_TOOL_DESCRIPTION).description("\u5DE5\u5177\u63CF\u8FF0")
|
|
490
492
|
}).description("\u4FEE\u6539\u81EA\u8EAB\u8D26\u6237\u4FE1\u606F\u5DE5\u5177").collapse(),
|
|
491
493
|
setQQAvatar: import_koishi2.Schema.object({
|
|
492
|
-
enabled: import_koishi2.Schema.boolean().default(false).description("\u6CE8\u518C ChatLuna \u5DE5\u5177\uFF1A\u4FEE\u6539\u673A\u5668\u4EBA QQ \u5934\u50CF"),
|
|
494
|
+
enabled: import_koishi2.Schema.boolean().default(false).description("\u6CE8\u518C ChatLuna \u539F\u751F\u5DE5\u5177\uFF1A\u4FEE\u6539\u673A\u5668\u4EBA QQ \u5934\u50CF"),
|
|
493
495
|
toolName: import_koishi2.Schema.string().default("set_qq_avatar").description("\u5DE5\u5177\u540D\u79F0"),
|
|
494
496
|
description: import_koishi2.Schema.string().default(DEFAULT_SET_QQ_AVATAR_TOOL_DESCRIPTION).description("\u5DE5\u5177\u63CF\u8FF0")
|
|
495
497
|
}).description("\u4FEE\u6539 QQ \u5934\u50CF\u5DE5\u5177").collapse(),
|
|
496
498
|
setGroupCard: import_koishi2.Schema.object({
|
|
497
|
-
enabled: import_koishi2.Schema.boolean().default(false).description("\u6CE8\u518C ChatLuna \u5DE5\u5177\uFF1A\u4FEE\u6539\u7FA4\u6210\u5458\u6635\u79F0"),
|
|
499
|
+
enabled: import_koishi2.Schema.boolean().default(false).description("\u6CE8\u518C ChatLuna \u539F\u751F\u5DE5\u5177\uFF1A\u4FEE\u6539\u7FA4\u6210\u5458\u6635\u79F0"),
|
|
498
500
|
toolName: import_koishi2.Schema.string().default("set_group_card").description("\u5DE5\u5177\u540D\u79F0"),
|
|
499
501
|
description: import_koishi2.Schema.string().default(DEFAULT_SET_GROUP_CARD_TOOL_DESCRIPTION).description("\u5DE5\u5177\u63CF\u8FF0")
|
|
500
502
|
}).description("\u4FEE\u6539\u7FA4\u6210\u5458\u6635\u79F0\u5DE5\u5177").collapse(),
|
|
501
503
|
setGroupBan: import_koishi2.Schema.object({
|
|
502
|
-
enabled: import_koishi2.Schema.boolean().default(false).description("\u6CE8\u518C ChatLuna \u5DE5\u5177\uFF1A\u7981\u8A00\u7FA4\u6210\u5458"),
|
|
504
|
+
enabled: import_koishi2.Schema.boolean().default(false).description("\u6CE8\u518C ChatLuna \u539F\u751F\u5DE5\u5177\uFF1A\u7981\u8A00\u7FA4\u6210\u5458"),
|
|
503
505
|
toolName: import_koishi2.Schema.string().default("set_group_ban").description("\u5DE5\u5177\u540D\u79F0"),
|
|
504
506
|
description: import_koishi2.Schema.string().default(DEFAULT_SET_GROUP_BAN_TOOL_DESCRIPTION).description("\u5DE5\u5177\u63CF\u8FF0")
|
|
505
507
|
}).description("\u7981\u8A00\u5DE5\u5177").collapse(),
|
|
506
508
|
setGroupSpecialTitle: import_koishi2.Schema.object({
|
|
507
|
-
enabled: import_koishi2.Schema.boolean().default(false).description("\u6CE8\u518C ChatLuna \u5DE5\u5177\uFF1A\u4FEE\u6539\u7FA4\u6210\u5458\u4E13\u5C5E\u5934\u8854"),
|
|
509
|
+
enabled: import_koishi2.Schema.boolean().default(false).description("\u6CE8\u518C ChatLuna \u539F\u751F\u5DE5\u5177\uFF1A\u4FEE\u6539\u7FA4\u6210\u5458\u4E13\u5C5E\u5934\u8854"),
|
|
508
510
|
toolName: import_koishi2.Schema.string().default("set_group_special_title").description("\u5DE5\u5177\u540D\u79F0"),
|
|
509
511
|
description: import_koishi2.Schema.string().default(DEFAULT_SET_GROUP_SPECIAL_TITLE_TOOL_DESCRIPTION).description("\u5DE5\u5177\u63CF\u8FF0")
|
|
510
512
|
}).description("\u4FEE\u6539\u7FA4\u6210\u5458\u4E13\u5C5E\u5934\u8854\u5DE5\u5177").collapse(),
|
|
511
513
|
setMsgEmoji: import_koishi2.Schema.object({
|
|
512
514
|
enabled: import_koishi2.Schema.boolean().default(false).description(
|
|
513
|
-
|
|
515
|
+
`\u6CE8\u518C ChatLuna \u539F\u751F\u5DE5\u5177\uFF1A\u7ED9\u6D88\u606F\u6DFB\u52A0\u8868\u60C5\uFF0C\u9700\`chatluna-character\`\u5F00\u542F\`enableMessageId\`\uFF0C\u4E0E**XML \u8868\u60C5\u56DE\u5E94\u8C03\u7528**\u4E8C\u9009\u4E00\uFF0C\u70B9\u51FB\u67E5\u770B[\u8868\u60C5\u5BF9\u7167\u8868](https://bot.q.qq.com/wiki/develop/pythonsdk/model/emoji.html)`
|
|
514
516
|
),
|
|
515
517
|
toolName: import_koishi2.Schema.string().default("set_msg_emoji").description("\u5DE5\u5177\u540D\u79F0"),
|
|
516
518
|
description: import_koishi2.Schema.string().default(DEFAULT_SET_MSG_EMOJI_TOOL_DESCRIPTION).description("\u5DE5\u5177\u63CF\u8FF0")
|
|
517
519
|
}).description("\u6D88\u606F\u8868\u60C5\u5DE5\u5177").collapse(),
|
|
518
520
|
deleteMessage: import_koishi2.Schema.object({
|
|
519
521
|
enabled: import_koishi2.Schema.boolean().default(false).description(
|
|
520
|
-
|
|
522
|
+
`\u6CE8\u518C ChatLuna \u539F\u751F\u5DE5\u5177\uFF1A\u64A4\u56DE\u6D88\u606F\uFF0C\u9700\`chatluna-character\`\u5F00\u542F\`enableMessageId\`\uFF0C\u4E0E**XML \u6D88\u606F\u64A4\u56DE\u8C03\u7528**\u4E8C\u9009\u4E00`
|
|
521
523
|
),
|
|
522
524
|
toolName: import_koishi2.Schema.string().default("delete_msg").description("\u5DE5\u5177\u540D\u79F0"),
|
|
523
525
|
description: import_koishi2.Schema.string().default(DEFAULT_DELETE_MESSAGE_TOOL_DESCRIPTION).description("\u5DE5\u5177\u63CF\u8FF0")
|
|
@@ -589,13 +591,12 @@ var DEFAULT_XML_REFERENCE_PROMPT = `## \u52A8\u4F5C\u6307\u4EE4
|
|
|
589
591
|
- id: user_id
|
|
590
592
|
- duration: \u7981\u8A00\u65F6\u957F\uFF0C\u5355\u4F4D\u79D2\uFF0C\u4F20 0 \u8868\u793A\u89E3\u9664\u7981\u8A00
|
|
591
593
|
- \u9002\u7528\u573A\u666F:
|
|
592
|
-
- \u4F60\u5728\u672C\u7FA4\u4E3A\u7BA1\u7406\u5458
|
|
593
|
-
- \u7528\u4E8E\u7981\u8A00\u6216\u89E3\u9664\u7981\u8A00\u6307\u5B9A\u7FA4\u6210\u5458
|
|
594
|
+
- \u4F60\u5728\u672C\u7FA4\u4E3A\u7BA1\u7406\u5458\u65F6\u7528\u4E8E\u7981\u8A00\u6216\u89E3\u9664\u7981\u8A00\u6307\u5B9A\u7FA4\u6210\u5458
|
|
594
595
|
4. \u64A4\u56DE\u6D88\u606F: <delete message_id=""/>
|
|
595
596
|
- message_id: \u6D88\u606F ID
|
|
596
597
|
- \u9002\u7528\u573A\u666F:
|
|
597
|
-
- \
|
|
598
|
-
- \
|
|
598
|
+
- \u64A4\u56DE\u81EA\u5DF1\u53D1\u7684\u6D88\u606F
|
|
599
|
+
- \u4F60\u5728\u672C\u7FA4\u4E3A\u7BA1\u7406\u5458\u65F6\u64A4\u56DE\u5176\u4ED6\u7528\u6237\u53D1\u9001\u7684\u6D88\u606F
|
|
599
600
|
|
|
600
601
|
\u683C\u5F0F\u793A\u4F8B:
|
|
601
602
|
\`\`\`xml
|
|
@@ -607,18 +608,18 @@ var DEFAULT_XML_REFERENCE_PROMPT = `## \u52A8\u4F5C\u6307\u4EE4
|
|
|
607
608
|
</actions>
|
|
608
609
|
\`\`\``;
|
|
609
610
|
var XmlToolsSchema = import_koishi3.Schema.object({
|
|
610
|
-
injectXmlToolAsReplyTool: import_koishi3.Schema.boolean().default(false).description("\u5C06 XML \u5DE5\u5177\
|
|
611
|
-
enablePokeXmlTool: import_koishi3.Schema.boolean().default(false).description(
|
|
611
|
+
injectXmlToolAsReplyTool: import_koishi3.Schema.boolean().default(false).description("\u5C06 XML \u5DE5\u5177\u6CE8\u5165\u5B9E\u9A8C\u6027[\u5DE5\u5177\u8C03\u7528\u56DE\u590D](https://chatluna.chat/ecosystem/other/character.html#%E9%A2%84%E8%AE%BE)\u7684\u53C2\u6570\u4E2D"),
|
|
612
|
+
enablePokeXmlTool: import_koishi3.Schema.boolean().default(false).description(`\u542F\u7528 XML \u6233\u4E00\u6233\u8C03\u7528\uFF0C\u4E0E**\u6233\u4E00\u6233\u5DE5\u5177**\u4E8C\u9009\u4E00`),
|
|
612
613
|
enableEmojiXmlTool: import_koishi3.Schema.boolean().default(false).description(
|
|
613
|
-
|
|
614
|
+
`\u542F\u7528 XML \u6D88\u606F\u8868\u60C5\u8C03\u7528\uFF0C\u9700\`chatluna-character\`\u5F00\u542F\`enableMessageId\`\uFF0C\u4E0E**\u6D88\u606F\u8868\u60C5\u5DE5\u5177**\u4E8C\u9009\u4E00\uFF0C\u70B9\u51FB\u67E5\u770B[emoji_id \u5BF9\u7167\u8868](https://bot.q.qq.com/wiki/develop/pythonsdk/model/emoji.html)`
|
|
614
615
|
),
|
|
615
616
|
enableDeleteXmlTool: import_koishi3.Schema.boolean().default(false).description(
|
|
616
|
-
|
|
617
|
+
`\u542F\u7528 XML \u6D88\u606F\u64A4\u56DE\u8C03\u7528\uFF0C\u9700\`chatluna-character\`\u5F00\u542F\`enableMessageId\`\uFF0C\u4E0E**\u64A4\u56DE\u6D88\u606F\u5DE5\u5177**\u4E8C\u9009\u4E00`
|
|
617
618
|
),
|
|
618
619
|
enableBanXmlTool: import_koishi3.Schema.boolean().default(false).description(
|
|
619
|
-
|
|
620
|
+
`\u542F\u7528 XML \u7FA4\u6210\u5458\u7981\u8A00\u8C03\u7528\uFF0C\u4E0E**\u7981\u8A00\u5DE5\u5177**\u4E8C\u9009\u4E00`
|
|
620
621
|
),
|
|
621
|
-
referencePrompt: import_koishi3.Schema.string().role("textarea").default(DEFAULT_XML_REFERENCE_PROMPT).description("\u6A21\u578B\u56DE\u590D XML \u53C2\u8003\u63D0\u793A\u8BCD\
|
|
622
|
+
referencePrompt: import_koishi3.Schema.string().role("textarea").default(DEFAULT_XML_REFERENCE_PROMPT).description("\u6A21\u578B\u56DE\u590D XML \u53C2\u8003\u63D0\u793A\u8BCD\u3002\u81EA\u884C\u5199\u5165\u63D0\u793A\u8BCD\u4E2D\uFF0C\u4E0D\u4F1A\u81EA\u52A8\u6CE8\u5165\uFF1B\u82E5\u5F00\u542F\u201C\u5C06 XML \u5DE5\u5177\u6CE8\u5165\u5B9E\u9A8C\u6027[\u5DE5\u5177\u8C03\u7528\u56DE\u590D](https://chatluna.chat/ecosystem/other/character.html#%E9%A2%84%E8%AE%BE)\u7684\u53C2\u6570\u4E2D\u201D\uFF0C\u5219\u65E0\u9700\u589E\u52A0\u989D\u5916\u63D0\u793A\u8BCD")
|
|
622
623
|
}).description("XML \u5DE5\u5177");
|
|
623
624
|
|
|
624
625
|
// src/schema/variables.ts
|
|
@@ -663,7 +664,7 @@ var VariablesSchema = import_koishi4.Schema.object({
|
|
|
663
664
|
import_koishi4.Schema.const("joinTime").description("\u5165\u7FA4\u65F6\u95F4"),
|
|
664
665
|
import_koishi4.Schema.const("lastSentTime").description("\u6700\u540E\u53D1\u8A00\u65F6\u95F4")
|
|
665
666
|
])
|
|
666
|
-
).role("checkbox").default([...DEFAULT_MEMBER_INFO_ITEMS]).description("\u663E\u793A\u7684\u8BE6\u7EC6\u4FE1\u606F\u9879")
|
|
667
|
+
).role("checkbox").default([...DEFAULT_MEMBER_INFO_ITEMS]).description("\u9009\u62E9\u7528\u6237\u4FE1\u606F\u53D8\u91CF\u4E2D\u663E\u793A\u7684\u8BE6\u7EC6\u4FE1\u606F\u9879")
|
|
667
668
|
}).description("\u7528\u6237\u4FE1\u606F\u53D8\u91CF").collapse(),
|
|
668
669
|
botInfo: import_koishi4.Schema.object({
|
|
669
670
|
variableName: import_koishi4.Schema.string().default("botInfo").description("\u53D8\u91CF\u540D\u79F0"),
|
|
@@ -680,7 +681,7 @@ var VariablesSchema = import_koishi4.Schema.object({
|
|
|
680
681
|
import_koishi4.Schema.const("joinTime").description("\u5165\u7FA4\u65F6\u95F4"),
|
|
681
682
|
import_koishi4.Schema.const("lastSentTime").description("\u6700\u540E\u53D1\u8A00\u65F6\u95F4")
|
|
682
683
|
])
|
|
683
|
-
).role("checkbox").default([...DEFAULT_MEMBER_INFO_ITEMS]).description("\
|
|
684
|
+
).role("checkbox").default([...DEFAULT_MEMBER_INFO_ITEMS]).description("\u9009\u62E9\u673A\u5668\u4EBA\u4FE1\u606F\u53D8\u91CF\u4E2D\u663E\u793A\u7684\u8BE6\u7EC6\u4FE1\u606F\u9879")
|
|
684
685
|
}).description("\u673A\u5668\u4EBA\u4FE1\u606F\u53D8\u91CF").collapse(),
|
|
685
686
|
groupInfo: import_koishi4.Schema.object({
|
|
686
687
|
variableName: import_koishi4.Schema.string().default("groupInfo").description("\u53D8\u91CF\u540D\u79F0"),
|
|
@@ -693,7 +694,7 @@ var VariablesSchema = import_koishi4.Schema.object({
|
|
|
693
694
|
import_koishi4.Schema.const("ownerList").description("\u7FA4\u4E3B\u540D\u5355"),
|
|
694
695
|
import_koishi4.Schema.const("adminList").description("\u7BA1\u7406\u5458\u540D\u5355")
|
|
695
696
|
])
|
|
696
|
-
).role("checkbox").default([...DEFAULT_GROUP_INFO_ITEMS]).description("\u663E\u793A\u7684\u7FA4\u4FE1\u606F\u9879")
|
|
697
|
+
).role("checkbox").default([...DEFAULT_GROUP_INFO_ITEMS]).description("\u9009\u62E9\u7FA4\u4FE1\u606F\u53D8\u91CF\u4E2D\u663E\u793A\u7684\u7FA4\u4FE1\u606F\u9879")
|
|
697
698
|
}).description("\u7FA4\u4FE1\u606F\u53D8\u91CF").collapse(),
|
|
698
699
|
groupShutList: import_koishi4.Schema.object({
|
|
699
700
|
variableName: import_koishi4.Schema.string().default("groupShutList").description("\u53D8\u91CF\u540D\u79F0")
|
|
@@ -760,6 +761,7 @@ function createLogger(ctx, config) {
|
|
|
760
761
|
|
|
761
762
|
// src/features/native-tools/tools/delete-msg.ts
|
|
762
763
|
var import_zod = require("zod");
|
|
764
|
+
var import_tools = require("@langchain/core/tools");
|
|
763
765
|
|
|
764
766
|
// src/features/native-tools/onebot-api.ts
|
|
765
767
|
function ensureOneBotSession(session) {
|
|
@@ -789,19 +791,33 @@ function getSession(runnable) {
|
|
|
789
791
|
}
|
|
790
792
|
|
|
791
793
|
// src/features/native-tools/tools/delete-msg.ts
|
|
794
|
+
function assertOneBotSuccess(result) {
|
|
795
|
+
const response = result;
|
|
796
|
+
if (!response || typeof response !== "object") return;
|
|
797
|
+
const status = String(response.status || "").toLowerCase();
|
|
798
|
+
const failed = status === "failed" || !!status && status !== "ok" || typeof response.retcode === "number" && response.retcode !== 0;
|
|
799
|
+
if (!failed) return;
|
|
800
|
+
const reason = response.wording || response.message || response.status;
|
|
801
|
+
const retcode = typeof response.retcode === "number" ? ` (retcode: ${response.retcode})` : "";
|
|
802
|
+
throw new Error(`${reason || "OneBot returned failed"}${retcode}`);
|
|
803
|
+
}
|
|
792
804
|
async function sendDeleteMessage(params) {
|
|
793
|
-
const { session,
|
|
805
|
+
const { session, message_id, log } = params;
|
|
794
806
|
try {
|
|
795
807
|
if (!session) return "No session context available.";
|
|
796
|
-
const messageIdRaw =
|
|
797
|
-
if (!messageIdRaw) return "
|
|
808
|
+
const messageIdRaw = message_id.trim();
|
|
809
|
+
if (!messageIdRaw) return "message_id is required.";
|
|
798
810
|
const numericId = /^\d+$/.test(messageIdRaw) ? Number(messageIdRaw) : messageIdRaw;
|
|
799
811
|
if (session.platform === "onebot") {
|
|
800
812
|
const { error, internal } = ensureOneBotSession(session);
|
|
801
813
|
if (error) return error;
|
|
802
|
-
await callOneBotAPI(
|
|
803
|
-
|
|
804
|
-
|
|
814
|
+
const result = await callOneBotAPI(
|
|
815
|
+
internal,
|
|
816
|
+
"delete_msg",
|
|
817
|
+
{ message_id: numericId },
|
|
818
|
+
["deleteMsg"]
|
|
819
|
+
);
|
|
820
|
+
assertOneBotSuccess(result);
|
|
805
821
|
const success = `Message deleted by ID ${messageIdRaw}.`;
|
|
806
822
|
log?.("info", success);
|
|
807
823
|
return success;
|
|
@@ -823,18 +839,18 @@ async function sendDeleteMessage(params) {
|
|
|
823
839
|
}
|
|
824
840
|
function createDeleteMessageTool(deps) {
|
|
825
841
|
const { toolName, description, log } = deps;
|
|
826
|
-
|
|
827
|
-
name
|
|
828
|
-
description
|
|
829
|
-
schema
|
|
830
|
-
|
|
831
|
-
})
|
|
842
|
+
return new class extends import_tools.StructuredTool {
|
|
843
|
+
name = toolName || "delete_msg";
|
|
844
|
+
description = description || DEFAULT_DELETE_MESSAGE_TOOL_DESCRIPTION;
|
|
845
|
+
schema = import_zod.z.object({
|
|
846
|
+
message_id: import_zod.z.string().min(1, "message_id is required").describe("Specific message ID to delete.")
|
|
847
|
+
}).strict();
|
|
832
848
|
async _call(input, _manager, runnable) {
|
|
833
849
|
try {
|
|
834
850
|
const session = getSession(runnable);
|
|
835
851
|
return await sendDeleteMessage({
|
|
836
852
|
session,
|
|
837
|
-
|
|
853
|
+
message_id: input.message_id,
|
|
838
854
|
log
|
|
839
855
|
});
|
|
840
856
|
} catch (error) {
|
|
@@ -842,13 +858,12 @@ function createDeleteMessageTool(deps) {
|
|
|
842
858
|
return `delete_msg failed: ${error.message}`;
|
|
843
859
|
}
|
|
844
860
|
}
|
|
845
|
-
};
|
|
846
|
-
return tool;
|
|
861
|
+
}();
|
|
847
862
|
}
|
|
848
863
|
|
|
849
864
|
// src/features/native-tools/tools/poke.ts
|
|
850
865
|
var import_zod2 = require("zod");
|
|
851
|
-
var
|
|
866
|
+
var import_tools2 = require("@langchain/core/tools");
|
|
852
867
|
async function sendPoke(params) {
|
|
853
868
|
try {
|
|
854
869
|
const { session, userId, groupId, log, protocol } = params;
|
|
@@ -858,11 +873,11 @@ async function sendPoke(params) {
|
|
|
858
873
|
session: validatedSession
|
|
859
874
|
} = ensureOneBotSession(session);
|
|
860
875
|
if (error) return error;
|
|
861
|
-
const resolvedGroupId = groupId?.trim() || validatedSession?.guildId || validatedSession?.
|
|
876
|
+
const resolvedGroupId = groupId?.trim() || validatedSession?.guildId || validatedSession?.roomId;
|
|
862
877
|
const payload = { user_id: userId };
|
|
863
878
|
if (resolvedGroupId) payload.group_id = resolvedGroupId;
|
|
879
|
+
const action = payload.group_id ? "group_poke" : "friend_poke";
|
|
864
880
|
if (protocol === "llbot") {
|
|
865
|
-
const action = payload.group_id ? "group_poke" : "friend_poke";
|
|
866
881
|
if (typeof internal._request === "function") {
|
|
867
882
|
await internal._request(action, payload);
|
|
868
883
|
} else if (typeof internal[action] === "function") {
|
|
@@ -871,7 +886,9 @@ async function sendPoke(params) {
|
|
|
871
886
|
throw new Error(`\u5F53\u524D\u9002\u914D\u5668\u672A\u5B9E\u73B0 ${action} API\u3002`);
|
|
872
887
|
}
|
|
873
888
|
} else if (typeof internal._request === "function") {
|
|
874
|
-
await internal._request(
|
|
889
|
+
await internal._request(action, payload);
|
|
890
|
+
} else if (typeof internal[action] === "function") {
|
|
891
|
+
await internal[action](payload);
|
|
875
892
|
} else if (typeof internal.sendPoke === "function") {
|
|
876
893
|
await internal.sendPoke(
|
|
877
894
|
payload.group_id,
|
|
@@ -893,7 +910,7 @@ async function sendPoke(params) {
|
|
|
893
910
|
}
|
|
894
911
|
function createPokeTool(deps) {
|
|
895
912
|
const { toolName, description, log, protocol } = deps;
|
|
896
|
-
return new class extends
|
|
913
|
+
return new class extends import_tools2.StructuredTool {
|
|
897
914
|
name = toolName || "poke_user";
|
|
898
915
|
description = description || DEFAULT_POKE_TOOL_DESCRIPTION;
|
|
899
916
|
schema = import_zod2.z.object({
|
|
@@ -915,7 +932,7 @@ function createPokeTool(deps) {
|
|
|
915
932
|
|
|
916
933
|
// src/features/native-tools/tools/set-group-ban.ts
|
|
917
934
|
var import_zod3 = require("zod");
|
|
918
|
-
var
|
|
935
|
+
var import_tools3 = require("@langchain/core/tools");
|
|
919
936
|
function resolveGroupId(session, groupId) {
|
|
920
937
|
return groupId?.trim() || (session.guildId || "").trim() || (session.channelId || "").trim() || (session.roomId || "").trim();
|
|
921
938
|
}
|
|
@@ -965,7 +982,7 @@ async function sendGroupBan(params) {
|
|
|
965
982
|
}
|
|
966
983
|
function createSetGroupBanTool(deps) {
|
|
967
984
|
const { toolName, description, protocol, log } = deps;
|
|
968
|
-
return new class extends
|
|
985
|
+
return new class extends import_tools3.StructuredTool {
|
|
969
986
|
name = toolName || "set_group_ban";
|
|
970
987
|
description = description || DEFAULT_SET_GROUP_BAN_TOOL_DESCRIPTION;
|
|
971
988
|
schema = import_zod3.z.object({
|
|
@@ -989,7 +1006,7 @@ function createSetGroupBanTool(deps) {
|
|
|
989
1006
|
|
|
990
1007
|
// src/features/native-tools/tools/set-group-card.ts
|
|
991
1008
|
var import_zod4 = require("zod");
|
|
992
|
-
var
|
|
1009
|
+
var import_tools4 = require("@langchain/core/tools");
|
|
993
1010
|
async function sendSetGroupCard(params) {
|
|
994
1011
|
try {
|
|
995
1012
|
const { session, userId, card, groupId, log } = params;
|
|
@@ -1020,7 +1037,7 @@ async function sendSetGroupCard(params) {
|
|
|
1020
1037
|
}
|
|
1021
1038
|
function createSetGroupCardTool(deps) {
|
|
1022
1039
|
const { toolName, description, log } = deps;
|
|
1023
|
-
return new class extends
|
|
1040
|
+
return new class extends import_tools4.StructuredTool {
|
|
1024
1041
|
name = toolName || "set_group_card";
|
|
1025
1042
|
description = description || DEFAULT_SET_GROUP_CARD_TOOL_DESCRIPTION;
|
|
1026
1043
|
schema = import_zod4.z.object({
|
|
@@ -1042,7 +1059,7 @@ function createSetGroupCardTool(deps) {
|
|
|
1042
1059
|
|
|
1043
1060
|
// src/features/native-tools/tools/set-group-special-title.ts
|
|
1044
1061
|
var import_zod5 = require("zod");
|
|
1045
|
-
var
|
|
1062
|
+
var import_tools5 = require("@langchain/core/tools");
|
|
1046
1063
|
function resolveGroupId2(session, groupId) {
|
|
1047
1064
|
return groupId?.trim() || (session.guildId || "").trim() || (session.channelId || "").trim() || (session.roomId || "").trim();
|
|
1048
1065
|
}
|
|
@@ -1082,7 +1099,7 @@ async function sendSetGroupSpecialTitle(params) {
|
|
|
1082
1099
|
}
|
|
1083
1100
|
function createSetGroupSpecialTitleTool(deps) {
|
|
1084
1101
|
const { toolName, description, protocol, log } = deps;
|
|
1085
|
-
return new class extends
|
|
1102
|
+
return new class extends import_tools5.StructuredTool {
|
|
1086
1103
|
name = toolName || "set_group_special_title";
|
|
1087
1104
|
description = description || DEFAULT_SET_GROUP_SPECIAL_TITLE_TOOL_DESCRIPTION;
|
|
1088
1105
|
schema = import_zod5.z.object({
|
|
@@ -1106,7 +1123,7 @@ function createSetGroupSpecialTitleTool(deps) {
|
|
|
1106
1123
|
|
|
1107
1124
|
// src/features/native-tools/tools/set-msg-emoji.ts
|
|
1108
1125
|
var import_zod6 = require("zod");
|
|
1109
|
-
var
|
|
1126
|
+
var import_tools6 = require("@langchain/core/tools");
|
|
1110
1127
|
async function sendMsgEmoji(params) {
|
|
1111
1128
|
try {
|
|
1112
1129
|
const { session, messageId, emojiId, log, protocol } = params;
|
|
@@ -1137,7 +1154,7 @@ async function sendMsgEmoji(params) {
|
|
|
1137
1154
|
}
|
|
1138
1155
|
function createSetMsgEmojiTool(deps) {
|
|
1139
1156
|
const { toolName, description, log, protocol } = deps;
|
|
1140
|
-
return new class extends
|
|
1157
|
+
return new class extends import_tools6.StructuredTool {
|
|
1141
1158
|
name = toolName || "set_msg_emoji";
|
|
1142
1159
|
description = description || DEFAULT_SET_MSG_EMOJI_TOOL_DESCRIPTION;
|
|
1143
1160
|
schema = import_zod6.z.object({
|
|
@@ -1159,7 +1176,7 @@ function createSetMsgEmojiTool(deps) {
|
|
|
1159
1176
|
|
|
1160
1177
|
// src/features/native-tools/tools/profile.ts
|
|
1161
1178
|
var import_zod7 = require("zod");
|
|
1162
|
-
var
|
|
1179
|
+
var import_tools7 = require("@langchain/core/tools");
|
|
1163
1180
|
var genders = {
|
|
1164
1181
|
unknown: "0",
|
|
1165
1182
|
male: "1",
|
|
@@ -1186,7 +1203,7 @@ async function sendSetProfile(params) {
|
|
|
1186
1203
|
}
|
|
1187
1204
|
function createSetProfileTool(deps) {
|
|
1188
1205
|
const { toolName, description, log, protocol } = deps;
|
|
1189
|
-
return new class extends
|
|
1206
|
+
return new class extends import_tools7.StructuredTool {
|
|
1190
1207
|
name = toolName || "set_self_profile";
|
|
1191
1208
|
description = description || DEFAULT_SET_SELF_PROFILE_TOOL_DESCRIPTION;
|
|
1192
1209
|
schema = import_zod7.z.object({
|
|
@@ -1209,7 +1226,7 @@ function createSetProfileTool(deps) {
|
|
|
1209
1226
|
|
|
1210
1227
|
// src/features/native-tools/tools/set-qq-avatar.ts
|
|
1211
1228
|
var import_zod8 = require("zod");
|
|
1212
|
-
var
|
|
1229
|
+
var import_tools8 = require("@langchain/core/tools");
|
|
1213
1230
|
function isHttpUrl(value) {
|
|
1214
1231
|
return /^https?:\/\//i.test(value);
|
|
1215
1232
|
}
|
|
@@ -1237,7 +1254,7 @@ async function fetchImageAsOneBotFile(ctx, imageUrl) {
|
|
|
1237
1254
|
throw new Error(`\u65E0\u6CD5\u8BFB\u53D6\u5934\u50CF\u56FE\u7247\uFF1A${error.message}`);
|
|
1238
1255
|
}
|
|
1239
1256
|
}
|
|
1240
|
-
function
|
|
1257
|
+
function assertOneBotSuccess2(result) {
|
|
1241
1258
|
const response = result;
|
|
1242
1259
|
if (!response || typeof response !== "object") return;
|
|
1243
1260
|
const failed = response.status === "failed" || typeof response.retcode === "number" && response.retcode !== 0;
|
|
@@ -1257,7 +1274,7 @@ async function sendSetQQAvatar(params) {
|
|
|
1257
1274
|
const result = await callOneBotAPI(internal, "set_qq_avatar", { file }, [
|
|
1258
1275
|
"setQQAvatar"
|
|
1259
1276
|
]);
|
|
1260
|
-
|
|
1277
|
+
assertOneBotSuccess2(result);
|
|
1261
1278
|
const message = "QQ \u5934\u50CF\u5DF2\u66F4\u65B0\u3002";
|
|
1262
1279
|
log?.("info", message);
|
|
1263
1280
|
return message;
|
|
@@ -1268,7 +1285,7 @@ async function sendSetQQAvatar(params) {
|
|
|
1268
1285
|
}
|
|
1269
1286
|
function createSetQQAvatarTool(deps) {
|
|
1270
1287
|
const { ctx, toolName, description, log } = deps;
|
|
1271
|
-
return new class extends
|
|
1288
|
+
return new class extends import_tools8.StructuredTool {
|
|
1272
1289
|
name = toolName || "set_qq_avatar";
|
|
1273
1290
|
description = description || DEFAULT_SET_QQ_AVATAR_TOOL_DESCRIPTION;
|
|
1274
1291
|
schema = import_zod8.z.object({
|
|
@@ -1309,14 +1326,7 @@ function resolveToolDescription(value, fallback) {
|
|
|
1309
1326
|
return trimmedValue || fallback;
|
|
1310
1327
|
}
|
|
1311
1328
|
function resolveOneBotProtocol(config, log) {
|
|
1312
|
-
|
|
1313
|
-
log?.("warn", "NapCat \u4E0E LLBot \u534F\u8BAE\u540C\u65F6\u542F\u7528\uFF0C\u5C06\u4F18\u5148\u4F7F\u7528 LLBot\u3002");
|
|
1314
|
-
return "llbot";
|
|
1315
|
-
}
|
|
1316
|
-
if (config.enableLlbotProtocol) return "llbot";
|
|
1317
|
-
if (config.enableNapCatProtocol) return "napcat";
|
|
1318
|
-
log?.("warn", "\u672A\u542F\u7528 OneBot \u534F\u8BAE\u9009\u9879\uFF0C\u9ED8\u8BA4\u4F7F\u7528 NapCat\u3002");
|
|
1319
|
-
return "napcat";
|
|
1329
|
+
return config.oneBotProtocol;
|
|
1320
1330
|
}
|
|
1321
1331
|
function registerNativeTools(deps) {
|
|
1322
1332
|
const { ctx, config, plugin, protocol, log } = deps;
|
|
@@ -1687,7 +1697,7 @@ function registerCharacterReplyTools(deps) {
|
|
|
1687
1697
|
if (typeof action.message_id !== "string") continue;
|
|
1688
1698
|
await sendDeleteMessage({
|
|
1689
1699
|
session,
|
|
1690
|
-
|
|
1700
|
+
message_id: action.message_id,
|
|
1691
1701
|
log
|
|
1692
1702
|
});
|
|
1693
1703
|
}
|
|
@@ -1787,7 +1797,7 @@ function createXmlProcessor(deps) {
|
|
|
1787
1797
|
if (messageIds.length > 0) handled = true;
|
|
1788
1798
|
for (const messageId of messageIds) {
|
|
1789
1799
|
try {
|
|
1790
|
-
await runDelete({ session, messageId, log });
|
|
1800
|
+
await runDelete({ session, message_id: messageId, log });
|
|
1791
1801
|
} catch (error) {
|
|
1792
1802
|
log?.("warn", "XML \u89E6\u53D1\u64A4\u56DE\u5931\u8D25", error);
|
|
1793
1803
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-chatluna-toolbox",
|
|
3
3
|
"description": "为 ChatLuna 提供更多原生工具、XML 工具与变量,仅支持 onebot 平台。",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.17",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -15,6 +15,12 @@
|
|
|
15
15
|
"type": "git",
|
|
16
16
|
"url": "https://github.com/Sor85/AAAAACAT-chatluna-plugins.git"
|
|
17
17
|
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsup && vite build",
|
|
20
|
+
"watch": "tsup --watch",
|
|
21
|
+
"typecheck": "yarn workspace shared-chatluna-xmltools build && NODE_OPTIONS=--max-old-space-size=8192 tsc -p tsconfig.test.json",
|
|
22
|
+
"test": "vitest run"
|
|
23
|
+
},
|
|
18
24
|
"keywords": [
|
|
19
25
|
"chatbot",
|
|
20
26
|
"koishi",
|
|
@@ -22,16 +28,16 @@
|
|
|
22
28
|
"chatluna"
|
|
23
29
|
],
|
|
24
30
|
"peerDependencies": {
|
|
31
|
+
"@koishijs/plugin-console": "^5.30.0",
|
|
25
32
|
"koishi": "^4.18.7",
|
|
26
33
|
"koishi-plugin-chatluna": "*",
|
|
27
|
-
"koishi-plugin-chatluna-character": "*"
|
|
28
|
-
"@koishijs/plugin-console": "^5.30.0"
|
|
34
|
+
"koishi-plugin-chatluna-character": "*"
|
|
29
35
|
},
|
|
30
36
|
"peerDependenciesMeta": {
|
|
31
|
-
"
|
|
37
|
+
"@koishijs/plugin-console": {
|
|
32
38
|
"optional": true
|
|
33
39
|
},
|
|
34
|
-
"
|
|
40
|
+
"koishi-plugin-chatluna-character": {
|
|
35
41
|
"optional": true
|
|
36
42
|
}
|
|
37
43
|
},
|
|
@@ -44,17 +50,12 @@
|
|
|
44
50
|
"@types/node": "^22.10.1",
|
|
45
51
|
"@vitejs/plugin-vue": "^6.0.2",
|
|
46
52
|
"sass": "^1.77.0",
|
|
53
|
+
"shared-chatluna-xmltools": "0.0.1",
|
|
54
|
+
"shared-nav": "0.0.1",
|
|
47
55
|
"tsup": "^8.0.0",
|
|
48
56
|
"typescript": "^5.7.2",
|
|
49
57
|
"vite": "^6.0.0",
|
|
50
58
|
"vitest": "^3.2.4",
|
|
51
|
-
"
|
|
52
|
-
"shared-nav": "0.0.1"
|
|
53
|
-
},
|
|
54
|
-
"scripts": {
|
|
55
|
-
"build": "tsup && vite build",
|
|
56
|
-
"watch": "tsup --watch",
|
|
57
|
-
"typecheck": "NODE_OPTIONS=--max-old-space-size=8192 tsc -p tsconfig.test.json",
|
|
58
|
-
"test": "vitest run"
|
|
59
|
+
"vue": "^3.5.21"
|
|
59
60
|
}
|
|
60
61
|
}
|