koishi-plugin-chatluna-toolbox 0.0.1

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.
Files changed (3) hide show
  1. package/README.md +70 -0
  2. package/lib/index.js +1480 -0
  3. package/package.json +54 -0
package/lib/index.js ADDED
@@ -0,0 +1,1480 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name2 in all)
8
+ __defProp(target, name2, { get: all[name2], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ Config: () => ConfigSchema,
24
+ ConfigSchema: () => ConfigSchema,
25
+ DEFAULT_MEMBER_INFO_ITEMS: () => DEFAULT_MEMBER_INFO_ITEMS,
26
+ NativeToolsSchema: () => NativeToolsSchema,
27
+ RAW_INTERCEPTOR_TAG: () => RAW_INTERCEPTOR_TAG,
28
+ VariablesSchema: () => VariablesSchema,
29
+ XmlToolsSchema: () => XmlToolsSchema,
30
+ apply: () => apply,
31
+ callOneBotAPI: () => callOneBotAPI,
32
+ createBotInfoProvider: () => createBotInfoProvider,
33
+ createDeleteMessageTool: () => createDeleteMessageTool,
34
+ createGroupInfoProvider: () => createGroupInfoProvider,
35
+ createLogger: () => createLogger,
36
+ createPokeTool: () => createPokeTool,
37
+ createRandomProvider: () => createRandomProvider,
38
+ createSetGroupCardTool: () => createSetGroupCardTool,
39
+ createSetMsgEmojiTool: () => createSetMsgEmojiTool,
40
+ createSetProfileTool: () => createSetProfileTool,
41
+ createUserInfoProvider: () => createUserInfoProvider,
42
+ createXmlInterceptor: () => createXmlInterceptor,
43
+ ensureOneBotSession: () => ensureOneBotSession,
44
+ getSession: () => getSession,
45
+ inject: () => inject,
46
+ name: () => name,
47
+ parseXmlActions: () => parseXmlActions,
48
+ registerNativeTools: () => registerNativeTools,
49
+ registerVariables: () => registerVariables,
50
+ registerXmlTools: () => registerXmlTools,
51
+ resolveOneBotProtocol: () => resolveOneBotProtocol,
52
+ sendDeleteMessage: () => sendDeleteMessage,
53
+ sendMsgEmoji: () => sendMsgEmoji,
54
+ sendPoke: () => sendPoke
55
+ });
56
+ module.exports = __toCommonJS(index_exports);
57
+
58
+ // src/schema/index.ts
59
+ var import_koishi4 = require("koishi");
60
+
61
+ // src/schema/native-tools.ts
62
+ var import_koishi = require("koishi");
63
+ var NativeToolsSchema = import_koishi.Schema.object({
64
+ enableNapCatProtocol: import_koishi.Schema.boolean().default(true).description("\u542F\u7528 NapCat OneBot \u534F\u8BAE\uFF08\u4E0E LLBot \u4E8C\u9009\u4E00\uFF09"),
65
+ enableLlbotProtocol: import_koishi.Schema.boolean().default(false).description("\u542F\u7528 LLBot OneBot \u534F\u8BAE\uFF08\u4E0E NapCat \u4E8C\u9009\u4E00\uFF09"),
66
+ enablePokeTool: import_koishi.Schema.boolean().default(false).description("\u6CE8\u518C ChatLuna \u5DE5\u5177\uFF1A\u6233\u4E00\u6233\uFF08\u5EFA\u8BAE\u4E0E XML\u5DE5\u5177 \u4E8C\u9009\u4E00\uFF09"),
67
+ pokeToolName: import_koishi.Schema.string().default("poke_user").description("ChatLuna \u5DE5\u5177\u540D\u79F0\uFF1A\u6233\u4E00\u6233"),
68
+ enableSetSelfProfileTool: import_koishi.Schema.boolean().default(false).description("\u6CE8\u518C ChatLuna \u5DE5\u5177\uFF1A\u4FEE\u6539\u81EA\u8EAB\u8D26\u6237\u4FE1\u606F"),
69
+ setSelfProfileToolName: import_koishi.Schema.string().default("set_self_profile").description("ChatLuna \u5DE5\u5177\u540D\u79F0\uFF1A\u4FEE\u6539\u81EA\u8EAB\u8D26\u6237\u4FE1\u606F\uFF08\u652F\u6301\u6635\u79F0/\u7B7E\u540D/\u6027\u522B\uFF09"),
70
+ enableSetGroupCardTool: import_koishi.Schema.boolean().default(false).description("\u6CE8\u518C ChatLuna \u5DE5\u5177\uFF1A\u4FEE\u6539\u7FA4\u6210\u5458\u6635\u79F0"),
71
+ setGroupCardToolName: import_koishi.Schema.string().default("set_group_card").description("ChatLuna \u5DE5\u5177\u540D\u79F0\uFF1A\u4FEE\u6539\u7FA4\u6210\u5458\u6635\u79F0"),
72
+ enableSetMsgEmojiTool: import_koishi.Schema.boolean().default(false).description("\u6CE8\u518C ChatLuna \u5DE5\u5177\uFF1A\u7ED9\u6D88\u606F\u6DFB\u52A0\u8868\u60C5\uFF08\u9700 chatluna-character \u5F00\u542F enableMessageId\uFF0C\u5EFA\u8BAE\u4E0E XML\u5DE5\u5177 \u4E8C\u9009\u4E00\uFF09"),
73
+ setMsgEmojiToolName: import_koishi.Schema.string().default("set_msg_emoji").description("ChatLuna \u5DE5\u5177\u540D\u79F0\uFF1A\u7ED9\u6D88\u606F\u6DFB\u52A0\u8868\u60C5"),
74
+ enableDeleteMessageTool: import_koishi.Schema.boolean().default(false).description("\u6CE8\u518C ChatLuna \u5DE5\u5177\uFF1A\u64A4\u56DE\u6D88\u606F\uFF08\u9700 chatluna-character \u5F00\u542F enableMessageId\uFF0C\u5EFA\u8BAE\u4E0E XML\u5DE5\u5177 \u4E8C\u9009\u4E00\uFF09"),
75
+ deleteMessageToolName: import_koishi.Schema.string().default("delete_msg").description("ChatLuna \u5DE5\u5177\u540D\u79F0\uFF1A\u64A4\u56DE\u6D88\u606F")
76
+ }).description("\u539F\u751F\u5DE5\u5177");
77
+
78
+ // src/schema/xml-tools.ts
79
+ var import_koishi2 = require("koishi");
80
+ var DEFAULT_XML_REFERENCE_PROMPT = `## \u52A8\u4F5C\u6307\u4EE4
81
+ \u4F60\u53EF\u4EE5\u6839\u636E\u9700\u8981\u521B\u5EFA\u4E00\u4E2A\u72EC\u7ACB\u7684 <actions> \u5143\u7D20\u3002\u5B83\u7528\u4E8E\u6267\u884C\u975E\u8BED\u8A00\u7684\u7CFB\u7EDF\u6307\u4EE4\u3002\u5982\u679C\u4E0D\u9700\u8981\u6267\u884C\u4EFB\u4F55\u52A8\u4F5C\uFF0C\u8BF7\u7701\u7565\u6B64\u5143\u7D20\u3002
82
+ 1. \u6233\u4E00\u6233: <poke id=""/>
83
+ - id: user_id
84
+ - \u9002\u7528\u573A\u666F:
85
+ - \u5F53\u4F60\u60F3\u5F15\u8D77\u67D0\u4EBA\u7684\u6CE8\u610F\u65F6\u3002
86
+ - \u5F53\u5BF9\u65B9\u8BF4\u4E86\u8BA9\u4F60\u611F\u5230\u65E0\u8BED\u3001\u65E0\u89C6\u4F60\u3001\u6216\u8005\u4F60\u60F3\u901A\u8FC7\u80A2\u4F53\u4E92\u52A8\u8C03\u4F83\u5BF9\u65B9\u65F6\u3002
87
+ - \u4F5C\u4E3A\u4E00\u79CD\u4FCF\u76AE\u7684\u6253\u62DB\u547C\u65B9\u5F0F\u3002
88
+ 2. \u8868\u60C5\u56DE\u5E94: <emoji message_id="" emoji_id=""/>
89
+ - message_id: \u6D88\u606F ID
90
+ - emoji_id \u5BF9\u5E94\u8868:
91
+ - 424: \u8D5E\u540C (\u7EA2\u8272\u6309\u94AE)
92
+ - 10068: \u95EE\u53F7
93
+ - 265: \u9006\u5929 (\u5730\u94C1\u8001\u4EBA\u624B\u673A)
94
+ - 76: \u8D5E
95
+ - 66: \u7231\u5FC3
96
+ - \u9002\u7528\u573A\u666F:
97
+ - \u7528\u4E8E\u5BF9\u4E0A\u4E0B\u6587\u4E2D\u7684\u7279\u5B9A\u6D88\u606F\u8FDB\u884C\u8868\u60C5\u56DE\u5E94\u3002
98
+ 3. \u64A4\u56DE\u6D88\u606F: <delete message_id=""/>
99
+ - message_id: \u6D88\u606F ID
100
+ - \u9002\u7528\u573A\u666F:
101
+ - \u4F60\u5728\u672C\u7FA4\u4E3A\u7BA1\u7406\u5458
102
+ - \u7528\u4E8E\u64A4\u56DE\u6307\u5B9A\u6D88\u606F
103
+
104
+ \u683C\u5F0F\u793A\u4F8B:
105
+ \`\`\`xml
106
+ <actions>
107
+ <poke id="123456"/>
108
+ <emoji message_id="346234" emoji_id="66"/>
109
+ <delete message_id="435663"/>
110
+ </actions>
111
+ \`\`\``;
112
+ var XmlToolsSchema = import_koishi2.Schema.object({
113
+ enablePokeXmlTool: import_koishi2.Schema.boolean().default(false).description("\u542F\u7528 XML \u5F62\u5F0F\u7684\u6233\u4E00\u6233\u8C03\u7528"),
114
+ enableEmojiXmlTool: import_koishi2.Schema.boolean().default(false).description("\u542F\u7528 XML \u5F62\u5F0F\u7684\u6D88\u606F\u8868\u60C5\u8C03\u7528"),
115
+ enableDeleteXmlTool: import_koishi2.Schema.boolean().default(false).description("\u542F\u7528 XML \u5F62\u5F0F\u7684\u6D88\u606F\u64A4\u56DE\u8C03\u7528"),
116
+ referencePrompt: import_koishi2.Schema.string().role("textarea").default(DEFAULT_XML_REFERENCE_PROMPT).description("\u53C2\u8003\u63D0\u793A\u8BCD")
117
+ }).description("XML \u5DE5\u5177");
118
+
119
+ // src/schema/variables.ts
120
+ var import_koishi3 = require("koishi");
121
+
122
+ // src/constants/defaults.ts
123
+ var DEFAULT_MEMBER_INFO_ITEMS = [
124
+ "nickname",
125
+ "userId",
126
+ "role",
127
+ "level",
128
+ "title",
129
+ "gender",
130
+ "age",
131
+ "area",
132
+ "joinTime",
133
+ "lastSentTime"
134
+ ];
135
+ var RAW_INTERCEPTOR_TAG = "__chatlunaToolboxRawInterceptor";
136
+
137
+ // src/schema/variables.ts
138
+ var VariablesSchema = import_koishi3.Schema.object({
139
+ userInfo: import_koishi3.Schema.object({
140
+ variableName: import_koishi3.Schema.string().default("userInfo").description("\u53D8\u91CF\u540D\u79F0"),
141
+ items: import_koishi3.Schema.array(
142
+ import_koishi3.Schema.union([
143
+ import_koishi3.Schema.const("userId").description("\u7528\u6237 ID"),
144
+ import_koishi3.Schema.const("nickname").description("\u7FA4\u6635\u79F0"),
145
+ import_koishi3.Schema.const("role").description("\u7FA4\u5185\u8EAB\u4EFD"),
146
+ import_koishi3.Schema.const("level").description("\u7FA4\u7B49\u7EA7"),
147
+ import_koishi3.Schema.const("title").description("\u7FA4\u5934\u8854"),
148
+ import_koishi3.Schema.const("gender").description("\u6027\u522B"),
149
+ import_koishi3.Schema.const("age").description("\u5E74\u9F84"),
150
+ import_koishi3.Schema.const("area").description("\u5730\u533A"),
151
+ import_koishi3.Schema.const("joinTime").description("\u5165\u7FA4\u65F6\u95F4"),
152
+ import_koishi3.Schema.const("lastSentTime").description("\u6700\u540E\u53D1\u8A00\u65F6\u95F4")
153
+ ])
154
+ ).role("checkbox").default([...DEFAULT_MEMBER_INFO_ITEMS]).description("\u663E\u793A\u7684\u8BE6\u7EC6\u4FE1\u606F\u9879")
155
+ }).description("\u7528\u6237\u4FE1\u606F\u53D8\u91CF").collapse(),
156
+ botInfo: import_koishi3.Schema.object({
157
+ variableName: import_koishi3.Schema.string().default("botInfo").description("\u53D8\u91CF\u540D\u79F0"),
158
+ items: import_koishi3.Schema.array(
159
+ import_koishi3.Schema.union([
160
+ import_koishi3.Schema.const("userId").description("\u673A\u5668\u4EBA ID"),
161
+ import_koishi3.Schema.const("nickname").description("\u7FA4\u6635\u79F0"),
162
+ import_koishi3.Schema.const("role").description("\u7FA4\u5185\u8EAB\u4EFD"),
163
+ import_koishi3.Schema.const("level").description("\u7FA4\u7B49\u7EA7"),
164
+ import_koishi3.Schema.const("title").description("\u7FA4\u5934\u8854"),
165
+ import_koishi3.Schema.const("gender").description("\u6027\u522B"),
166
+ import_koishi3.Schema.const("age").description("\u5E74\u9F84"),
167
+ import_koishi3.Schema.const("area").description("\u5730\u533A"),
168
+ import_koishi3.Schema.const("joinTime").description("\u5165\u7FA4\u65F6\u95F4"),
169
+ import_koishi3.Schema.const("lastSentTime").description("\u6700\u540E\u53D1\u8A00\u65F6\u95F4")
170
+ ])
171
+ ).role("checkbox").default([...DEFAULT_MEMBER_INFO_ITEMS]).description("\u663E\u793A\u7684\u673A\u5668\u4EBA\u8BE6\u7EC6\u4FE1\u606F\u9879")
172
+ }).description("\u673A\u5668\u4EBA\u4FE1\u606F\u53D8\u91CF").collapse(),
173
+ groupInfo: import_koishi3.Schema.object({
174
+ variableName: import_koishi3.Schema.string().default("groupInfo").description("\u53D8\u91CF\u540D\u79F0"),
175
+ includeMemberCount: import_koishi3.Schema.boolean().default(true).description("\u662F\u5426\u5305\u542B\u6210\u5458\u6570\u91CF"),
176
+ includeCreateTime: import_koishi3.Schema.boolean().default(true).description("\u662F\u5426\u5305\u542B\u521B\u5EFA\u65F6\u95F4"),
177
+ includeOwnersAndAdmins: import_koishi3.Schema.boolean().default(true).description("\u662F\u5426\u5C55\u793A\u7FA4\u4E3B\u4E0E\u7BA1\u7406\u5458\u540D\u5355")
178
+ }).description("\u7FA4\u4FE1\u606F\u53D8\u91CF").collapse(),
179
+ random: import_koishi3.Schema.object({
180
+ variableName: import_koishi3.Schema.string().default("random").description("\u53D8\u91CF\u540D\u79F0"),
181
+ min: import_koishi3.Schema.number().default(0).description("\u9ED8\u8BA4\u968F\u673A\u6570\u4E0B\u9650"),
182
+ max: import_koishi3.Schema.number().default(100).description("\u9ED8\u8BA4\u968F\u673A\u6570\u4E0A\u9650")
183
+ }).description("\u968F\u673A\u6570\u53D8\u91CF").collapse()
184
+ }).default({
185
+ userInfo: { variableName: "userInfo", items: [...DEFAULT_MEMBER_INFO_ITEMS] },
186
+ botInfo: { variableName: "botInfo", items: [...DEFAULT_MEMBER_INFO_ITEMS] },
187
+ groupInfo: {
188
+ variableName: "groupInfo",
189
+ includeMemberCount: true,
190
+ includeCreateTime: true,
191
+ includeOwnersAndAdmins: true
192
+ },
193
+ random: { variableName: "random", min: 0, max: 100 }
194
+ }).description("\u5176\u4ED6\u53D8\u91CF");
195
+
196
+ // src/schema/index.ts
197
+ var OtherSettingsSchema = import_koishi4.Schema.object({
198
+ debugLogging: import_koishi4.Schema.boolean().default(false).description("\u8F93\u51FA\u8C03\u8BD5\u65E5\u5FD7")
199
+ }).description("\u5176\u4ED6\u8BBE\u7F6E");
200
+ var name = "chatluna-toolbox";
201
+ var inject = {
202
+ required: ["chatluna"],
203
+ optional: ["chatluna_character"]
204
+ };
205
+ var ConfigSchema = import_koishi4.Schema.intersect([
206
+ NativeToolsSchema,
207
+ XmlToolsSchema,
208
+ VariablesSchema,
209
+ OtherSettingsSchema
210
+ ]);
211
+
212
+ // src/helpers/logger.ts
213
+ function createLogger(ctx, config) {
214
+ const logger = ctx.logger("chatluna-toolbox");
215
+ return (level, message, meta) => {
216
+ if (level === "debug" && !config.debugLogging) return;
217
+ if (meta === void 0) {
218
+ logger[level](message);
219
+ return;
220
+ }
221
+ logger[level](message, meta);
222
+ };
223
+ }
224
+
225
+ // src/features/native-tools/tools/delete-msg.ts
226
+ var import_zod = require("zod");
227
+
228
+ // src/features/native-tools/onebot-api.ts
229
+ function ensureOneBotSession(session) {
230
+ if (!session) return { error: "\u7F3A\u5C11\u4F1A\u8BDD\u4E0A\u4E0B\u6587\uFF0C\u65E0\u6CD5\u6267\u884C OneBot \u5DE5\u5177\u3002" };
231
+ if (session.platform !== "onebot")
232
+ return { error: "\u8BE5\u5DE5\u5177\u4EC5\u652F\u6301 OneBot \u5E73\u53F0\u3002" };
233
+ if (!session.bot) return { error: "\u5F53\u524D\u4F1A\u8BDD\u7F3A\u5C11 bot \u5B9E\u4F8B\uFF0C\u65E0\u6CD5\u6267\u884C\u5DE5\u5177\u3002" };
234
+ const internal = session.bot.internal;
235
+ if (!internal) return { error: "Bot \u9002\u914D\u5668\u672A\u66B4\u9732 OneBot internal \u63A5\u53E3\u3002" };
236
+ return { session, internal };
237
+ }
238
+ async function callOneBotAPI(internal, action, params, fallbacks = []) {
239
+ if (typeof internal._request === "function") {
240
+ return internal._request(action, params);
241
+ }
242
+ for (const key of fallbacks) {
243
+ if (typeof internal[key] === "function") {
244
+ return internal[key](params);
245
+ }
246
+ }
247
+ throw new Error(`\u5F53\u524D OneBot \u9002\u914D\u5668\u4E0D\u652F\u6301 ${action} \u63A5\u53E3\u3002`);
248
+ }
249
+
250
+ // src/features/native-tools/session.ts
251
+ function getSession(runnable) {
252
+ return runnable?.configurable?.session || null;
253
+ }
254
+
255
+ // src/features/native-tools/tools/delete-msg.ts
256
+ async function sendDeleteMessage(params) {
257
+ const { session, messageId, log } = params;
258
+ try {
259
+ if (!session) return "No session context available.";
260
+ const messageIdRaw = messageId.trim();
261
+ if (!messageIdRaw) return "messageId is required.";
262
+ const numericId = /^\d+$/.test(messageIdRaw) ? Number(messageIdRaw) : messageIdRaw;
263
+ if (session.platform === "onebot") {
264
+ const { error, internal } = ensureOneBotSession(session);
265
+ if (error) return error;
266
+ await callOneBotAPI(internal, "delete_msg", { message_id: numericId }, [
267
+ "deleteMsg"
268
+ ]);
269
+ const success = `Message deleted by ID ${messageIdRaw}.`;
270
+ log?.("info", success);
271
+ return success;
272
+ }
273
+ const bot = session.bot;
274
+ if (typeof bot?.deleteMessage === "function") {
275
+ const channelId = session.channelId || session?.guildId || session?.roomId || session?.channel?.id || "";
276
+ if (!channelId) return "Cannot determine channel to delete message.";
277
+ await bot.deleteMessage(channelId, messageIdRaw);
278
+ const success = `Message deleted by ID ${messageIdRaw}.`;
279
+ log?.("info", success);
280
+ return success;
281
+ }
282
+ return "Delete message is not supported on this platform.";
283
+ } catch (error) {
284
+ log?.("warn", "delete_msg failed", error);
285
+ return `delete_msg failed: ${error.message}`;
286
+ }
287
+ }
288
+ function createDeleteMessageTool(deps) {
289
+ const { toolName, log } = deps;
290
+ const tool = {
291
+ name: toolName || "delete_msg",
292
+ description: "Deletes (recalls) a message by messageId only.",
293
+ schema: import_zod.z.object({
294
+ messageId: import_zod.z.string().min(1, "messageId is required").describe("Specific message ID to delete.")
295
+ }),
296
+ async _call(input, _manager, runnable) {
297
+ try {
298
+ const session = getSession(runnable);
299
+ return await sendDeleteMessage({
300
+ session,
301
+ messageId: input.messageId,
302
+ log
303
+ });
304
+ } catch (error) {
305
+ log?.("warn", "delete_msg failed", error);
306
+ return `delete_msg failed: ${error.message}`;
307
+ }
308
+ }
309
+ };
310
+ return tool;
311
+ }
312
+
313
+ // src/features/native-tools/tools/poke.ts
314
+ var import_zod2 = require("zod");
315
+ var import_tools = require("@langchain/core/tools");
316
+ async function sendPoke(params) {
317
+ try {
318
+ const { session, userId, groupId, log, protocol } = params;
319
+ const {
320
+ error,
321
+ internal,
322
+ session: validatedSession
323
+ } = ensureOneBotSession(session);
324
+ if (error) return error;
325
+ const resolvedGroupId = groupId?.trim() || validatedSession?.guildId || validatedSession?.channelId || validatedSession?.roomId;
326
+ const payload = { user_id: userId };
327
+ if (resolvedGroupId) payload.group_id = resolvedGroupId;
328
+ if (protocol === "llbot") {
329
+ const action = payload.group_id ? "group_poke" : "friend_poke";
330
+ if (typeof internal._request === "function") {
331
+ await internal._request(action, payload);
332
+ } else if (typeof internal[action] === "function") {
333
+ await internal[action](payload);
334
+ } else {
335
+ throw new Error(`\u5F53\u524D\u9002\u914D\u5668\u672A\u5B9E\u73B0 ${action} API\u3002`);
336
+ }
337
+ } else if (typeof internal._request === "function") {
338
+ await internal._request("send_poke", payload);
339
+ } else if (typeof internal.sendPoke === "function") {
340
+ await internal.sendPoke(
341
+ payload.group_id,
342
+ payload.user_id
343
+ );
344
+ } else if (typeof internal.pokeUser === "function") {
345
+ await internal.pokeUser(payload);
346
+ } else {
347
+ throw new Error("\u5F53\u524D\u9002\u914D\u5668\u672A\u5B9E\u73B0 send_poke API\u3002");
348
+ }
349
+ const location = payload.group_id ? `\u7FA4 ${payload.group_id}` : "\u79C1\u804A";
350
+ const message = `\u5DF2\u5728 ${location} \u6233\u4E86\u4E00\u4E0B ${payload.user_id}\u3002`;
351
+ log?.("info", message);
352
+ return message;
353
+ } catch (error) {
354
+ params.log?.("warn", "\u6233\u4E00\u6233\u5DE5\u5177\u6267\u884C\u5931\u8D25", error);
355
+ return `\u6233\u4E00\u6233\u5931\u8D25\uFF1A${error.message}`;
356
+ }
357
+ }
358
+ function createPokeTool(deps) {
359
+ const { toolName, log, protocol } = deps;
360
+ return new class extends import_tools.StructuredTool {
361
+ name = toolName || "poke_user";
362
+ description = "Poke (nudge) a specified user in a group or private conversation.";
363
+ schema = import_zod2.z.object({
364
+ userId: import_zod2.z.string().min(1, "userId is required").describe("The user ID to poke."),
365
+ groupId: import_zod2.z.string().optional().describe("Optional: specify a different group ID.")
366
+ });
367
+ async _call(input, _manager, runnable) {
368
+ const session = getSession(runnable);
369
+ return sendPoke({
370
+ session,
371
+ userId: input.userId,
372
+ groupId: input.groupId,
373
+ log,
374
+ protocol
375
+ });
376
+ }
377
+ }();
378
+ }
379
+
380
+ // src/features/native-tools/tools/set-group-card.ts
381
+ var import_zod3 = require("zod");
382
+ var import_tools2 = require("@langchain/core/tools");
383
+ function createSetGroupCardTool(deps) {
384
+ const { toolName, log } = deps;
385
+ return new class extends import_tools2.StructuredTool {
386
+ name = toolName || "set_group_card";
387
+ description = "Update a group member nickname (group card).";
388
+ schema = import_zod3.z.object({
389
+ groupId: import_zod3.z.string().optional().describe("Target group ID. Defaults to current session group."),
390
+ userId: import_zod3.z.string().min(1, "userId is required").describe("Target member user ID."),
391
+ card: import_zod3.z.string().min(1, "card is required").describe("New group card for the member.")
392
+ });
393
+ async _call(input, _manager, runnable) {
394
+ try {
395
+ const session = getSession(runnable);
396
+ if (!session) return "No session context available.";
397
+ const groupId = input.groupId?.trim() || (session.guildId ? String(session.guildId).trim() : "") || (session.channelId ? String(session.channelId).trim() : "");
398
+ if (!groupId)
399
+ return "Missing groupId. Provide groupId explicitly or run inside a group session.";
400
+ const userId = input.userId.trim();
401
+ const card = input.card.trim();
402
+ if (!userId) return "userId is required.";
403
+ if (!card) return "card is required.";
404
+ const { error, internal } = ensureOneBotSession(session);
405
+ if (error) return error;
406
+ await callOneBotAPI(
407
+ internal,
408
+ "set_group_card",
409
+ { group_id: groupId, user_id: userId, card },
410
+ ["setGroupCard"]
411
+ );
412
+ const message = `\u7FA4\u6635\u79F0\u5DF2\u66F4\u65B0\uFF1A${userId} -> ${card}`;
413
+ log?.("info", message);
414
+ return message;
415
+ } catch (error) {
416
+ log?.("warn", "set_group_card failed", error);
417
+ return `set_group_card failed: ${error.message}`;
418
+ }
419
+ }
420
+ }();
421
+ }
422
+
423
+ // src/features/native-tools/tools/set-msg-emoji.ts
424
+ var import_zod4 = require("zod");
425
+ var import_tools3 = require("@langchain/core/tools");
426
+ async function sendMsgEmoji(params) {
427
+ try {
428
+ const { session, messageId, emojiId, log, protocol } = params;
429
+ if (!session) return "No session context available.";
430
+ if (session.platform !== "onebot")
431
+ return "This tool only supports OneBot platform.";
432
+ if (protocol === "llbot" && !session.guildId && !session.channelId) {
433
+ return "\u5F53\u524D\u4F1A\u8BDD\u4E0D\u662F\u7FA4\u804A\uFF0CLLBot \u4E0D\u652F\u6301\u79C1\u804A\u8868\u60C5\u56DE\u5E94\u3002";
434
+ }
435
+ const messageIdRaw = messageId.trim();
436
+ const emojiIdRaw = emojiId.trim();
437
+ if (!messageIdRaw) return "message_id is required.";
438
+ if (!emojiIdRaw) return "emoji_id is required.";
439
+ const numericMessageId = /^\d+$/.test(messageIdRaw) ? Number(messageIdRaw) : messageIdRaw;
440
+ const { error, internal } = ensureOneBotSession(session);
441
+ if (error) return error;
442
+ await callOneBotAPI(
443
+ internal,
444
+ "set_msg_emoji_like",
445
+ { message_id: numericMessageId, emoji_id: emojiIdRaw },
446
+ ["setMsgEmojiLike"]
447
+ );
448
+ const success = `Emoji ${emojiIdRaw} sent to message ${messageIdRaw}.`;
449
+ log?.("info", success);
450
+ return success;
451
+ } catch (error) {
452
+ params.log?.("warn", "set_msg_emoji failed", error);
453
+ return `set_msg_emoji failed: ${error.message}`;
454
+ }
455
+ }
456
+ function createSetMsgEmojiTool(deps) {
457
+ const { toolName, log, protocol } = deps;
458
+ return new class extends import_tools3.StructuredTool {
459
+ name = toolName || "set_msg_emoji";
460
+ description = "React to a message with an emoji by messageId.";
461
+ schema = import_zod4.z.object({
462
+ messageId: import_zod4.z.string().min(1, "message_id is required").describe("Target message ID."),
463
+ emojiId: import_zod4.z.string().min(1, "emoji_id is required").describe("Emoji ID to send.")
464
+ });
465
+ async _call(input, _manager, runnable) {
466
+ const session = getSession(runnable);
467
+ return sendMsgEmoji({
468
+ session,
469
+ messageId: input.messageId,
470
+ emojiId: input.emojiId,
471
+ log,
472
+ protocol
473
+ });
474
+ }
475
+ }();
476
+ }
477
+
478
+ // src/features/native-tools/tools/profile.ts
479
+ var import_zod5 = require("zod");
480
+ var import_tools4 = require("@langchain/core/tools");
481
+ var genders = {
482
+ unknown: "0",
483
+ male: "1",
484
+ female: "2"
485
+ };
486
+ function createSetProfileTool(deps) {
487
+ const { toolName, log, protocol } = deps;
488
+ return new class extends import_tools4.StructuredTool {
489
+ name = toolName || "set_self_profile";
490
+ description = "Update the bot's own QQ profile (nickname, signature, gender).";
491
+ schema = import_zod5.z.object({
492
+ nickname: import_zod5.z.string().min(1, "nickname is required").describe("The new nickname for the bot."),
493
+ signature: import_zod5.z.string().optional().describe("Optional: the new personal signature."),
494
+ gender: import_zod5.z.enum(["unknown", "male", "female"]).optional().describe("Optional: the new gender.")
495
+ });
496
+ async _call(input, _manager, runnable) {
497
+ try {
498
+ const session = getSession(runnable);
499
+ const { error, internal } = ensureOneBotSession(session);
500
+ if (error) return error;
501
+ const payload = { nickname: input.nickname };
502
+ if (input.signature) payload.personal_note = input.signature;
503
+ if (input.gender && protocol !== "llbot")
504
+ payload.sex = genders[input.gender];
505
+ await callOneBotAPI(internal, "set_qq_profile", payload, [
506
+ "setQQProfile"
507
+ ]);
508
+ const message = "\u673A\u5668\u4EBA\u8D44\u6599\u5DF2\u66F4\u65B0\u3002";
509
+ log?.("info", message);
510
+ return message;
511
+ } catch (error) {
512
+ log?.("warn", "\u4FEE\u6539\u673A\u5668\u4EBA\u8D26\u6237\u4FE1\u606F\u5931\u8D25", error);
513
+ return `\u4FEE\u6539\u673A\u5668\u4EBA\u8D26\u6237\u4FE1\u606F\u5931\u8D25\uFF1A${error.message}`;
514
+ }
515
+ }
516
+ }();
517
+ }
518
+
519
+ // src/features/native-tools/register.ts
520
+ function resolveOneBotProtocol(config, log) {
521
+ if (config.enableNapCatProtocol && config.enableLlbotProtocol) {
522
+ log?.("warn", "NapCat \u4E0E LLBot \u534F\u8BAE\u540C\u65F6\u542F\u7528\uFF0C\u5C06\u4F18\u5148\u4F7F\u7528 LLBot\u3002");
523
+ return "llbot";
524
+ }
525
+ if (config.enableLlbotProtocol) return "llbot";
526
+ if (config.enableNapCatProtocol) return "napcat";
527
+ log?.("warn", "\u672A\u542F\u7528 OneBot \u534F\u8BAE\u9009\u9879\uFF0C\u9ED8\u8BA4\u4F7F\u7528 NapCat\u3002");
528
+ return "napcat";
529
+ }
530
+ function registerNativeTools(deps) {
531
+ const { ctx, config, plugin, protocol, log } = deps;
532
+ if (config.enablePokeTool) {
533
+ const toolName = String(config.pokeToolName || "poke_user").trim();
534
+ plugin.registerTool(toolName, {
535
+ selector: () => true,
536
+ authorization: (session) => session?.platform === "onebot",
537
+ createTool: () => createPokeTool({ ctx, toolName, log, protocol })
538
+ });
539
+ log?.("info", `\u6233\u4E00\u6233\u5DE5\u5177\u5DF2\u6CE8\u518C: ${toolName}`);
540
+ }
541
+ if (config.enableSetSelfProfileTool) {
542
+ const toolName = String(
543
+ config.setSelfProfileToolName || "set_self_profile"
544
+ ).trim();
545
+ plugin.registerTool(toolName, {
546
+ selector: () => true,
547
+ authorization: (session) => session?.platform === "onebot",
548
+ createTool: () => createSetProfileTool({ ctx, toolName, log, protocol })
549
+ });
550
+ log?.("info", `\u8BBE\u7F6E\u8D44\u6599\u5DE5\u5177\u5DF2\u6CE8\u518C: ${toolName}`);
551
+ }
552
+ if (config.enableSetGroupCardTool) {
553
+ const toolName = String(
554
+ config.setGroupCardToolName || "set_group_card"
555
+ ).trim();
556
+ plugin.registerTool(toolName, {
557
+ selector: () => true,
558
+ authorization: (session) => session?.platform === "onebot",
559
+ createTool: () => createSetGroupCardTool({ ctx, toolName, log })
560
+ });
561
+ log?.("info", `\u7FA4\u6635\u79F0\u5DE5\u5177\u5DF2\u6CE8\u518C: ${toolName}`);
562
+ }
563
+ if (config.enableSetMsgEmojiTool) {
564
+ const toolName = String(
565
+ config.setMsgEmojiToolName || "set_msg_emoji"
566
+ ).trim();
567
+ plugin.registerTool(toolName, {
568
+ selector: () => true,
569
+ authorization: (session) => session?.platform === "onebot",
570
+ createTool: () => createSetMsgEmojiTool({ toolName, log, protocol })
571
+ });
572
+ log?.("info", `\u6D88\u606F\u8868\u60C5\u5DE5\u5177\u5DF2\u6CE8\u518C: ${toolName}`);
573
+ }
574
+ if (config.enableDeleteMessageTool) {
575
+ const toolName = String(
576
+ config.deleteMessageToolName || "delete_msg"
577
+ ).trim();
578
+ plugin.registerTool(toolName, {
579
+ selector: () => true,
580
+ authorization: (session) => session?.platform === "onebot",
581
+ createTool: () => createDeleteMessageTool({ toolName, log })
582
+ });
583
+ log?.("info", `\u5220\u9664\u6D88\u606F\u5DE5\u5177\u5DF2\u6CE8\u518C: ${toolName}`);
584
+ }
585
+ }
586
+
587
+ // src/features/xml-tools/interceptor.ts
588
+ function createXmlInterceptor(deps) {
589
+ const { ctx, config, log, onResponse } = deps;
590
+ const sessionMap = /* @__PURE__ */ new Map();
591
+ let currentGuildId = null;
592
+ let lastSession = null;
593
+ const pendingSessions = [];
594
+ let monitorHandle = null;
595
+ let fastRetryHandle = null;
596
+ let startupHandle = null;
597
+ let activeService = null;
598
+ let activeLogger = null;
599
+ let originalDebug = null;
600
+ let collectorBound = false;
601
+ const restore = () => {
602
+ if (activeLogger && originalDebug) {
603
+ activeLogger.debug = originalDebug;
604
+ }
605
+ activeLogger = null;
606
+ originalDebug = null;
607
+ };
608
+ const isActive = () => {
609
+ const characterService = ctx.chatluna_character;
610
+ const debugFn = characterService?.logger?.debug;
611
+ return Boolean(debugFn?.[RAW_INTERCEPTOR_TAG]);
612
+ };
613
+ const resolveSession = () => {
614
+ while (pendingSessions.length > 100) pendingSessions.shift();
615
+ const now = Date.now();
616
+ while (pendingSessions.length > 0 && now - pendingSessions[0].timestamp > 12e3) {
617
+ pendingSessions.shift();
618
+ }
619
+ if (pendingSessions.length === 0) {
620
+ return (currentGuildId ? sessionMap.get(currentGuildId) : null) || lastSession || null;
621
+ }
622
+ const contextKeys = /* @__PURE__ */ new Set();
623
+ for (let i = 0; i < pendingSessions.length; i++) {
624
+ contextKeys.add(pendingSessions[i].key || "__null__");
625
+ }
626
+ let resolved = pendingSessions[pendingSessions.length - 1];
627
+ if (currentGuildId) {
628
+ for (let i = pendingSessions.length - 1; i >= 0; i--) {
629
+ if (pendingSessions[i].key === currentGuildId) {
630
+ resolved = pendingSessions[i];
631
+ break;
632
+ }
633
+ }
634
+ }
635
+ pendingSessions.length = 0;
636
+ if (contextKeys.size > 1 && config.debugLogging) {
637
+ log?.("warn", "\u68C0\u6D4B\u5230\u591A\u4E2A\u4F1A\u8BDD\u4E0A\u4E0B\u6587\uFF0C\u5DF2\u4F7F\u7528\u6700\u8FD1\u4F1A\u8BDD\u7EE7\u7EED\u6267\u884C XML", {
638
+ contextCount: contextKeys.size,
639
+ preferredGuildId: currentGuildId,
640
+ resolvedGuildId: resolved.key
641
+ });
642
+ }
643
+ return resolved.key ? sessionMap.get(resolved.key) || resolved.session : resolved.session;
644
+ };
645
+ const attach = () => {
646
+ const characterService = ctx.chatluna_character;
647
+ if (!characterService) return false;
648
+ if (activeService !== characterService) {
649
+ activeService = characterService;
650
+ collectorBound = false;
651
+ }
652
+ if (!collectorBound && typeof characterService.collect === "function") {
653
+ characterService.collect(async (session) => {
654
+ const guildId = session?.guildId || session?.channelId || session?.userId || null;
655
+ currentGuildId = guildId;
656
+ if (guildId) sessionMap.set(guildId, session);
657
+ lastSession = session;
658
+ pendingSessions.push({ key: guildId, session, timestamp: Date.now() });
659
+ });
660
+ collectorBound = true;
661
+ }
662
+ const loggerService = characterService.logger;
663
+ if (!loggerService || typeof loggerService.debug !== "function")
664
+ return false;
665
+ const tagged = loggerService.debug;
666
+ if (!tagged[RAW_INTERCEPTOR_TAG]) {
667
+ restore();
668
+ const raw = loggerService.debug.bind(loggerService);
669
+ const wrapped = (...args) => {
670
+ raw(...args);
671
+ const message = args[0];
672
+ if (typeof message !== "string" || !message.startsWith("model response: "))
673
+ return;
674
+ const response = message.substring("model response: ".length);
675
+ if (!response) return;
676
+ const session = resolveSession();
677
+ if (!session && config.debugLogging) {
678
+ log?.("warn", "\u62E6\u622A\u5230\u539F\u59CB\u8F93\u51FA\u4F46\u7F3A\u5C11\u4F1A\u8BDD\u4E0A\u4E0B\u6587\uFF0CXML \u5DE5\u5177\u4E0D\u4F1A\u6267\u884C", {
679
+ length: response.length
680
+ });
681
+ }
682
+ onResponse(response, session);
683
+ };
684
+ wrapped[RAW_INTERCEPTOR_TAG] = true;
685
+ loggerService.debug = wrapped;
686
+ activeLogger = loggerService;
687
+ originalDebug = raw;
688
+ }
689
+ return true;
690
+ };
691
+ const stopFastRetry = () => {
692
+ if (!fastRetryHandle) return;
693
+ fastRetryHandle();
694
+ fastRetryHandle = null;
695
+ };
696
+ const startFastRetry = () => {
697
+ if (fastRetryHandle) return;
698
+ fastRetryHandle = ctx.setInterval(() => {
699
+ if (isActive()) {
700
+ stopFastRetry();
701
+ return;
702
+ }
703
+ const ready = attach();
704
+ if (ready) {
705
+ log?.("info", "\u539F\u59CB\u8F93\u51FA\u62E6\u622A\u5DF2\u6062\u590D");
706
+ stopFastRetry();
707
+ }
708
+ }, 3e3);
709
+ };
710
+ const ensureActive = () => {
711
+ if (isActive()) {
712
+ stopFastRetry();
713
+ return;
714
+ }
715
+ const ready = attach();
716
+ if (!ready) {
717
+ startFastRetry();
718
+ }
719
+ };
720
+ const startMonitor = () => {
721
+ if (monitorHandle) return;
722
+ monitorHandle = ctx.setInterval(() => {
723
+ ensureActive();
724
+ }, 5e3);
725
+ };
726
+ const stopMonitor = () => {
727
+ if (!monitorHandle) return;
728
+ monitorHandle();
729
+ monitorHandle = null;
730
+ };
731
+ return {
732
+ start: () => {
733
+ const delay = 3e3;
734
+ if (startupHandle) return;
735
+ startupHandle = ctx.setTimeout(() => {
736
+ startupHandle = null;
737
+ const ready = attach();
738
+ if (ready) {
739
+ log?.("info", "\u5DF2\u542F\u7528\u539F\u59CB\u8F93\u51FA\u62E6\u622A\u6A21\u5F0F");
740
+ } else {
741
+ log?.("warn", "chatluna_character \u670D\u52A1\u4E0D\u53EF\u7528\uFF0C\u5C06\u6BCF3\u79D2\u91CD\u8BD5\u4E00\u6B21");
742
+ startFastRetry();
743
+ }
744
+ startMonitor();
745
+ }, delay);
746
+ },
747
+ stop: () => {
748
+ if (startupHandle) {
749
+ startupHandle();
750
+ startupHandle = null;
751
+ }
752
+ stopFastRetry();
753
+ stopMonitor();
754
+ restore();
755
+ sessionMap.clear();
756
+ pendingSessions.length = 0;
757
+ currentGuildId = null;
758
+ lastSession = null;
759
+ activeService = null;
760
+ }
761
+ };
762
+ }
763
+
764
+ // src/features/xml-tools/parser.ts
765
+ function unique(values) {
766
+ return Array.from(new Set(values.map((item) => item.trim()).filter(Boolean)));
767
+ }
768
+ function parseXmlActions(response) {
769
+ const pokeMatches = Array.from(response.matchAll(/<poke\s+id="([^"]+)"\s*\/>/gi));
770
+ const emojiMatches = Array.from(
771
+ response.matchAll(/<emoji\s+message_id="([^"]+)"\s+emoji_id="([^"]+)"\s*\/>/gi)
772
+ );
773
+ const deleteMatches = Array.from(response.matchAll(/<delete\s+message_id="([^"]+)"\s*\/?>/gi));
774
+ return {
775
+ pokeUserIds: unique(pokeMatches.map((match) => String(match[1] || ""))),
776
+ emojis: emojiMatches.map((match) => ({
777
+ messageId: String(match[1] || "").trim(),
778
+ emojiId: String(match[2] || "").trim()
779
+ })).filter((item) => item.messageId && item.emojiId),
780
+ deleteMessageIds: unique(deleteMatches.map((match) => String(match[1] || "")))
781
+ };
782
+ }
783
+
784
+ // src/features/xml-tools/register.ts
785
+ function registerXmlTools(deps) {
786
+ const { ctx, config, protocol, log } = deps;
787
+ const interceptor = createXmlInterceptor({
788
+ ctx,
789
+ config,
790
+ log,
791
+ onResponse: (response, session) => {
792
+ const actions = parseXmlActions(response);
793
+ if (config.enablePokeXmlTool && actions.pokeUserIds.length > 0) {
794
+ if (!session) {
795
+ log?.("warn", "\u68C0\u6D4B\u5230\u6233\u4E00\u6233\u6807\u8BB0\u4F46\u7F3A\u5C11\u4F1A\u8BDD\u4E0A\u4E0B\u6587");
796
+ } else {
797
+ for (const userId of actions.pokeUserIds) {
798
+ void sendPoke({ session, userId, protocol, log }).catch((error) => {
799
+ log?.("warn", "XML \u89E6\u53D1 poke \u5931\u8D25", error);
800
+ });
801
+ }
802
+ }
803
+ }
804
+ if (config.enableEmojiXmlTool && actions.emojis.length > 0) {
805
+ if (!session) {
806
+ log?.("warn", "\u68C0\u6D4B\u5230\u8868\u60C5\u6807\u8BB0\u4F46\u7F3A\u5C11\u4F1A\u8BDD\u4E0A\u4E0B\u6587");
807
+ } else {
808
+ for (const item of actions.emojis) {
809
+ void sendMsgEmoji({
810
+ session,
811
+ messageId: item.messageId,
812
+ emojiId: item.emojiId,
813
+ protocol,
814
+ log
815
+ }).catch((error) => {
816
+ log?.("warn", "XML \u89E6\u53D1\u8868\u60C5\u5931\u8D25", error);
817
+ });
818
+ }
819
+ }
820
+ }
821
+ if (config.enableDeleteXmlTool && actions.deleteMessageIds.length > 0) {
822
+ if (!session) {
823
+ log?.("warn", "\u68C0\u6D4B\u5230\u64A4\u56DE\u6807\u8BB0\u4F46\u7F3A\u5C11\u4F1A\u8BDD\u4E0A\u4E0B\u6587");
824
+ } else {
825
+ for (const messageId of actions.deleteMessageIds) {
826
+ void sendDeleteMessage({ session, messageId, log }).catch(
827
+ (error) => {
828
+ log?.("warn", "XML \u89E6\u53D1\u64A4\u56DE\u5931\u8D25", error);
829
+ }
830
+ );
831
+ }
832
+ }
833
+ }
834
+ }
835
+ });
836
+ return {
837
+ start: () => interceptor.start(),
838
+ stop: () => interceptor.stop()
839
+ };
840
+ }
841
+
842
+ // src/features/variables/providers/bot-info.ts
843
+ function pickFirst(...values) {
844
+ for (const value of values) {
845
+ if (value === null || value === void 0) continue;
846
+ const text = String(value).trim();
847
+ if (!text) continue;
848
+ return value;
849
+ }
850
+ return null;
851
+ }
852
+ function normalizeTimestamp(raw) {
853
+ if (raw === null || raw === void 0 || raw === "") return null;
854
+ const numeric = Number(raw);
855
+ if (!Number.isFinite(numeric)) return null;
856
+ return numeric < 1e11 ? numeric * 1e3 : numeric;
857
+ }
858
+ function formatDateOnly(value) {
859
+ if (!value) return "";
860
+ const date = new Date(value);
861
+ if (Number.isNaN(date.valueOf())) return "";
862
+ return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;
863
+ }
864
+ function formatDateTime(value) {
865
+ if (!value) return "";
866
+ const date = new Date(value);
867
+ if (Number.isNaN(date.valueOf())) return "";
868
+ return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")} ${String(date.getHours()).padStart(2, "0")}:${String(date.getMinutes()).padStart(2, "0")}`;
869
+ }
870
+ function translateGender(value) {
871
+ if (value == null) return "";
872
+ const text = String(value).trim().toLowerCase();
873
+ if (!text) return "";
874
+ if (["male", "man", "m", "1", "boy"].includes(text)) return "\u7537";
875
+ if (["female", "woman", "f", "2", "girl"].includes(text)) return "\u5973";
876
+ if (["\u672A\u77E5", "unknown", "0", "secret"].includes(text)) return "";
877
+ return String(value);
878
+ }
879
+ function normalizeRole(value) {
880
+ if (value == null) return "\u7FA4\u5458";
881
+ const raw = String(value).trim();
882
+ const text = raw.toLowerCase();
883
+ if (!text) return "\u7FA4\u5458";
884
+ if (["owner", "group_owner", "\u7FA4\u4E3B"].includes(text)) return "\u7FA4\u4E3B";
885
+ if (["admin", "administrator", "group_admin", "\u7BA1\u7406\u5458"].includes(text))
886
+ return "\u7BA1\u7406\u5458";
887
+ if (["member", "normal", "\u7FA4\u5458"].includes(text)) return "\u7FA4\u5458";
888
+ return raw;
889
+ }
890
+ async function fetchMember(session, userId) {
891
+ try {
892
+ const guildId = session.guildId || session?.event?.guild?.id;
893
+ if (!guildId) return null;
894
+ const bot = session.bot;
895
+ if (!bot) return null;
896
+ if (session.platform === "onebot") {
897
+ const internal = bot?.internal;
898
+ if (internal) {
899
+ if (typeof internal.getGroupMemberInfo === "function") {
900
+ const result = await internal.getGroupMemberInfo(Number(guildId), Number(userId), false);
901
+ if (result) return result;
902
+ }
903
+ if (typeof internal._request === "function") {
904
+ const result = await internal._request("get_group_member_info", {
905
+ group_id: Number(guildId),
906
+ user_id: Number(userId),
907
+ no_cache: false
908
+ });
909
+ if (result) return result;
910
+ }
911
+ }
912
+ }
913
+ if (typeof bot.getGuildMember === "function") {
914
+ return await bot.getGuildMember(guildId, userId);
915
+ }
916
+ return null;
917
+ } catch {
918
+ return null;
919
+ }
920
+ }
921
+ function renderBotInfo(session, member, items) {
922
+ const botId = String(
923
+ session.selfId || session.bot?.selfId || ""
924
+ ).trim();
925
+ const values = [];
926
+ for (const item of items) {
927
+ switch (item) {
928
+ case "nickname": {
929
+ const name2 = String(
930
+ pickFirst(
931
+ member?.card,
932
+ member?.remark,
933
+ member?.displayName,
934
+ member?.nick,
935
+ member?.nickname,
936
+ member?.name,
937
+ botId
938
+ ) || ""
939
+ ).trim();
940
+ if (name2) values.push(`name:${name2}`);
941
+ break;
942
+ }
943
+ case "userId":
944
+ if (botId) values.push(`id:${botId}`);
945
+ break;
946
+ case "role": {
947
+ const role = normalizeRole(
948
+ pickFirst(
949
+ member?.role,
950
+ member?.roleName,
951
+ member?.permission,
952
+ member?.identity
953
+ )
954
+ );
955
+ values.push(`\u7FA4\u5185\u8EAB\u4EFD:${role}`);
956
+ break;
957
+ }
958
+ case "level": {
959
+ const level = pickFirst(
960
+ member?.level,
961
+ member?.levelName,
962
+ member?.level_name,
963
+ member?.level_info?.current_level
964
+ );
965
+ if (level !== null) values.push(`\u7FA4\u7B49\u7EA7:${level}`);
966
+ break;
967
+ }
968
+ case "title": {
969
+ const title = pickFirst(
970
+ member?.title,
971
+ member?.specialTitle,
972
+ member?.special_title
973
+ );
974
+ if (title !== null) values.push(`\u5934\u8854:${title}`);
975
+ break;
976
+ }
977
+ case "gender": {
978
+ const gender = translateGender(member?.sex ?? member?.gender);
979
+ if (gender) values.push(`\u6027\u522B:${gender}`);
980
+ break;
981
+ }
982
+ case "age": {
983
+ const age = Number(member?.age);
984
+ if (Number.isFinite(age) && age > 0) values.push(`\u5E74\u9F84:${age}`);
985
+ break;
986
+ }
987
+ case "area": {
988
+ const area = pickFirst(member?.area, member?.region, member?.location);
989
+ if (area !== null) values.push(`\u5730\u533A:${area}`);
990
+ break;
991
+ }
992
+ case "joinTime": {
993
+ const joinTime = formatDateOnly(
994
+ normalizeTimestamp(
995
+ pickFirst(
996
+ member?.join_time,
997
+ member?.joined_at,
998
+ member?.joinTime,
999
+ member?.joinedAt
1000
+ )
1001
+ )
1002
+ );
1003
+ if (joinTime) values.push(`\u5165\u7FA4:${joinTime}`);
1004
+ break;
1005
+ }
1006
+ case "lastSentTime": {
1007
+ const lastSentTime = formatDateTime(
1008
+ normalizeTimestamp(
1009
+ pickFirst(
1010
+ member?.last_sent_time,
1011
+ member?.lastSentTime,
1012
+ member?.lastSpeakTimestamp
1013
+ )
1014
+ )
1015
+ );
1016
+ if (lastSentTime) values.push(`\u6D3B\u8DC3:${lastSentTime}`);
1017
+ break;
1018
+ }
1019
+ default:
1020
+ break;
1021
+ }
1022
+ }
1023
+ if (values.length === 0) return botId || "\u672A\u77E5\u673A\u5668\u4EBA";
1024
+ return values.join(", ");
1025
+ }
1026
+ function createBotInfoProvider(deps) {
1027
+ const { config } = deps;
1028
+ return async (_args, _variables, configurable) => {
1029
+ const session = configurable?.session;
1030
+ if (!session) return "\u672A\u77E5\u673A\u5668\u4EBA";
1031
+ const items = Array.isArray(config.botInfo?.items) && config.botInfo.items.length ? config.botInfo.items : ["nickname", "userId"];
1032
+ const botId = String(
1033
+ session.selfId || session.bot?.selfId || ""
1034
+ ).trim();
1035
+ if (!botId) return "\u672A\u77E5\u673A\u5668\u4EBA";
1036
+ const member = await fetchMember(session, botId);
1037
+ return renderBotInfo(session, member, items);
1038
+ };
1039
+ }
1040
+
1041
+ // src/features/variables/providers/group-info.ts
1042
+ async function fetchGroupInfo(session) {
1043
+ if (session.platform !== "onebot") return null;
1044
+ const bot = session.bot;
1045
+ const internal = bot?.internal;
1046
+ if (!internal) return null;
1047
+ const groupId = Number(session.guildId);
1048
+ if (!groupId || !Number.isFinite(groupId)) return null;
1049
+ try {
1050
+ if (typeof internal.getGroupInfo === "function") {
1051
+ return await internal.getGroupInfo(groupId, false);
1052
+ }
1053
+ if (typeof internal._request === "function") {
1054
+ return await internal._request("get_group_info", {
1055
+ group_id: groupId,
1056
+ no_cache: false
1057
+ });
1058
+ }
1059
+ } catch {
1060
+ return null;
1061
+ }
1062
+ return null;
1063
+ }
1064
+ async function fetchOwnersAndAdmins(session, log) {
1065
+ try {
1066
+ if (session.platform !== "onebot") return null;
1067
+ const guildId = session.guildId;
1068
+ if (!guildId) return null;
1069
+ const bot = session.bot;
1070
+ const internal = bot?.internal;
1071
+ let members = null;
1072
+ if (internal) {
1073
+ if (typeof internal.getGroupMemberList === "function") {
1074
+ members = await internal.getGroupMemberList(guildId);
1075
+ } else if (typeof internal._request === "function") {
1076
+ members = await internal._request("get_group_member_list", {
1077
+ group_id: Number(guildId)
1078
+ });
1079
+ }
1080
+ }
1081
+ if (!members && typeof bot.getGuildMemberList === "function") {
1082
+ const list = await bot.getGuildMemberList(guildId);
1083
+ members = list?.data || null;
1084
+ }
1085
+ if (!members || !Array.isArray(members) || members.length === 0) return null;
1086
+ const owners = [];
1087
+ const admins = [];
1088
+ for (const member of members) {
1089
+ const roleRaw = member.role || member.roleName || member.permission || member.identity || (Array.isArray(member.roles) ? member.roles[0] : "") || "";
1090
+ const role = String(roleRaw || "").toLowerCase();
1091
+ const userId = String(member.user_id || member.userId || member.id || member.qq || member.uid || "");
1092
+ const candidates = [member.card, member.remark, member.displayName, member.nick, member.nickname, member.name].map(
1093
+ (item) => item ? String(item).trim() : ""
1094
+ );
1095
+ const name2 = candidates.find((item) => item) || userId;
1096
+ const label = userId ? `${name2}(${userId})` : name2;
1097
+ if (role === "owner" || role === "master" || role === "leader") {
1098
+ owners.push(label);
1099
+ } else if (role === "admin" || role === "administrator" || role === "manager") {
1100
+ admins.push(label);
1101
+ }
1102
+ }
1103
+ return { owners, admins };
1104
+ } catch (error) {
1105
+ log?.("debug", "\u83B7\u53D6\u7FA4\u7BA1\u7406\u4FE1\u606F\u5931\u8D25", error);
1106
+ return null;
1107
+ }
1108
+ }
1109
+ function formatGroupInfo(group, options) {
1110
+ const { includeMemberCount, includeCreateTime } = options;
1111
+ const id = group.group_id ?? group.groupId ?? group.id ?? "\u672A\u77E5\u7FA4\u53F7";
1112
+ const name2 = group.group_name ?? group.groupName ?? group.name ?? "\u672A\u547D\u540D\u7FA4";
1113
+ const memberCount = group.member_count ?? group.memberCount ?? group.max_member_count;
1114
+ let createTime = "";
1115
+ if (includeCreateTime) {
1116
+ const raw = group.create_time ?? group.createTime;
1117
+ if (raw) {
1118
+ const timestamp = Number(raw);
1119
+ if (Number.isFinite(timestamp)) {
1120
+ const date = new Date(timestamp < 1e11 ? timestamp * 1e3 : timestamp);
1121
+ if (!Number.isNaN(date.valueOf())) {
1122
+ createTime = `\uFF0C\u521B\u5EFA\u65F6\u95F4\uFF1A${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;
1123
+ }
1124
+ }
1125
+ }
1126
+ }
1127
+ const members = includeMemberCount ? `\uFF0C\u4EBA\u6570: ${memberCount ?? "\u672A\u77E5"}` : "";
1128
+ return `\u7FA4\u53F7\uFF1A${id}\uFF0C\u7FA4\u540D\u79F0\uFF1A${name2}${members}${createTime}`;
1129
+ }
1130
+ function createGroupInfoProvider(deps) {
1131
+ const { config, log } = deps;
1132
+ return async (_args, _variables, configurable) => {
1133
+ const session = configurable?.session;
1134
+ if (!session) return "\u6682\u65E0\u7FA4\u4FE1\u606F\u3002";
1135
+ if (!session.guildId) return "";
1136
+ if (session.platform !== "onebot") return "\u5F53\u524D\u5E73\u53F0\u6682\u4E0D\u652F\u6301\u67E5\u8BE2\u7FA4\u4FE1\u606F\u3002";
1137
+ const groupInfoCfg = config.groupInfo || {
1138
+ includeMemberCount: true,
1139
+ includeCreateTime: true,
1140
+ includeOwnersAndAdmins: true
1141
+ };
1142
+ try {
1143
+ const groupInfo = await fetchGroupInfo(session);
1144
+ if (!groupInfo) return "\u672A\u80FD\u83B7\u53D6\u5F53\u524D\u7FA4\u4FE1\u606F\u3002";
1145
+ const baseText = formatGroupInfo(groupInfo, {
1146
+ includeMemberCount: groupInfoCfg.includeMemberCount !== false,
1147
+ includeCreateTime: groupInfoCfg.includeCreateTime !== false
1148
+ });
1149
+ if (groupInfoCfg.includeOwnersAndAdmins) {
1150
+ const roles = await fetchOwnersAndAdmins(session, log);
1151
+ if (roles) {
1152
+ const ownersText = roles.owners.length ? roles.owners.join("\u3001") : "\u65E0";
1153
+ const adminsText = roles.admins.length ? roles.admins.join("\u3001") : "\u65E0";
1154
+ return `${baseText}
1155
+ \u7FA4\u4E3B\uFF1A${ownersText}
1156
+ \u7BA1\u7406\u5458\uFF1A${adminsText}`;
1157
+ }
1158
+ }
1159
+ return baseText;
1160
+ } catch (error) {
1161
+ log?.("debug", "\u7FA4\u4FE1\u606F\u53D8\u91CF\u89E3\u6790\u5931\u8D25", error);
1162
+ return "\u83B7\u53D6\u7FA4\u4FE1\u606F\u5931\u8D25\u3002";
1163
+ }
1164
+ };
1165
+ }
1166
+
1167
+ // src/features/variables/providers/random.ts
1168
+ function createRandomProvider(deps) {
1169
+ const { config } = deps;
1170
+ return () => {
1171
+ const randomConfig = config.random || {
1172
+ min: 0,
1173
+ max: 100
1174
+ };
1175
+ const randomMin = randomConfig.min ?? 0;
1176
+ const randomMax = randomConfig.max ?? 100;
1177
+ return Math.floor(Math.random() * (randomMax - randomMin + 1)) + randomMin;
1178
+ };
1179
+ }
1180
+
1181
+ // src/features/variables/providers/user-info.ts
1182
+ function translateGender2(value) {
1183
+ if (value == null) return "";
1184
+ const text = String(value).trim().toLowerCase();
1185
+ if (!text) return "";
1186
+ if (["male", "man", "m", "1", "boy"].includes(text)) return "\u7537";
1187
+ if (["female", "woman", "f", "2", "girl"].includes(text)) return "\u5973";
1188
+ if (["\u672A\u77E5", "unknown", "0", "secret"].includes(text)) return "";
1189
+ return String(value);
1190
+ }
1191
+ function normalizeTimestamp2(raw) {
1192
+ if (raw === null || raw === void 0 || raw === "") return null;
1193
+ const numeric = Number(raw);
1194
+ if (!Number.isFinite(numeric)) return null;
1195
+ return numeric < 1e11 ? numeric * 1e3 : numeric;
1196
+ }
1197
+ function formatDateOnly2(value) {
1198
+ if (!value) return "";
1199
+ const date = new Date(value);
1200
+ if (Number.isNaN(date.valueOf())) return "";
1201
+ return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;
1202
+ }
1203
+ function formatDateTime2(value) {
1204
+ if (!value) return "";
1205
+ const date = new Date(value);
1206
+ if (Number.isNaN(date.valueOf())) return "";
1207
+ return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")} ${String(date.getHours()).padStart(2, "0")}:${String(date.getMinutes()).padStart(2, "0")}`;
1208
+ }
1209
+ function pickFirst2(...values) {
1210
+ for (const value of values) {
1211
+ if (value === null || value === void 0) continue;
1212
+ const text = String(value).trim();
1213
+ if (!text) continue;
1214
+ return value;
1215
+ }
1216
+ return null;
1217
+ }
1218
+ function normalizeRole2(value) {
1219
+ if (value == null) return "\u7FA4\u5458";
1220
+ const raw = String(value).trim();
1221
+ const text = raw.toLowerCase();
1222
+ if (!text) return "\u7FA4\u5458";
1223
+ if (["owner", "group_owner", "\u7FA4\u4E3B"].includes(text)) return "\u7FA4\u4E3B";
1224
+ if (["admin", "administrator", "group_admin", "\u7BA1\u7406\u5458"].includes(text))
1225
+ return "\u7BA1\u7406\u5458";
1226
+ if (["member", "normal", "\u7FA4\u5458"].includes(text)) return "\u7FA4\u5458";
1227
+ return raw;
1228
+ }
1229
+ async function fetchMember2(session, userId) {
1230
+ try {
1231
+ const guildId = session.guildId || session?.event?.guild?.id;
1232
+ if (!guildId) return null;
1233
+ const bot = session.bot;
1234
+ if (!bot) return null;
1235
+ if (session.platform === "onebot") {
1236
+ const internal = bot?.internal;
1237
+ if (internal) {
1238
+ if (typeof internal.getGroupMemberInfo === "function") {
1239
+ const result = await internal.getGroupMemberInfo(Number(guildId), Number(userId), false);
1240
+ if (result) return result;
1241
+ }
1242
+ if (typeof internal._request === "function") {
1243
+ const result = await internal._request("get_group_member_info", {
1244
+ group_id: Number(guildId),
1245
+ user_id: Number(userId),
1246
+ no_cache: false
1247
+ });
1248
+ if (result) return result;
1249
+ }
1250
+ }
1251
+ }
1252
+ if (typeof bot.getGuildMember === "function") {
1253
+ return await bot.getGuildMember(guildId, userId);
1254
+ }
1255
+ return null;
1256
+ } catch {
1257
+ return null;
1258
+ }
1259
+ }
1260
+ function renderUserInfo(session, member, items) {
1261
+ const userId = String(session.userId || "").trim();
1262
+ const values = [];
1263
+ for (const item of items) {
1264
+ switch (item) {
1265
+ case "nickname": {
1266
+ const name2 = String(
1267
+ pickFirst2(
1268
+ member?.card,
1269
+ member?.remark,
1270
+ member?.displayName,
1271
+ member?.nick,
1272
+ member?.nickname,
1273
+ member?.name,
1274
+ session.username,
1275
+ userId
1276
+ ) || ""
1277
+ ).trim();
1278
+ if (name2) values.push(`name:${name2}`);
1279
+ break;
1280
+ }
1281
+ case "userId":
1282
+ if (userId) values.push(`id:${userId}`);
1283
+ break;
1284
+ case "role": {
1285
+ const role = normalizeRole2(
1286
+ pickFirst2(
1287
+ member?.role,
1288
+ member?.roleName,
1289
+ member?.permission,
1290
+ member?.identity
1291
+ )
1292
+ );
1293
+ values.push(`\u7FA4\u5185\u8EAB\u4EFD:${role}`);
1294
+ break;
1295
+ }
1296
+ case "level": {
1297
+ const level = pickFirst2(
1298
+ member?.level,
1299
+ member?.levelName,
1300
+ member?.level_name,
1301
+ member?.level_info?.current_level
1302
+ );
1303
+ if (level !== null) values.push(`\u7FA4\u7B49\u7EA7:${level}`);
1304
+ break;
1305
+ }
1306
+ case "title": {
1307
+ const title = pickFirst2(
1308
+ member?.title,
1309
+ member?.specialTitle,
1310
+ member?.special_title
1311
+ );
1312
+ if (title !== null) values.push(`\u5934\u8854:${title}`);
1313
+ break;
1314
+ }
1315
+ case "gender": {
1316
+ const gender = translateGender2(member?.sex ?? member?.gender);
1317
+ if (gender) values.push(`\u6027\u522B:${gender}`);
1318
+ break;
1319
+ }
1320
+ case "age": {
1321
+ const age = Number(member?.age);
1322
+ if (Number.isFinite(age) && age > 0) values.push(`\u5E74\u9F84:${age}`);
1323
+ break;
1324
+ }
1325
+ case "area": {
1326
+ const area = pickFirst2(member?.area, member?.region, member?.location);
1327
+ if (area !== null) values.push(`\u5730\u533A:${area}`);
1328
+ break;
1329
+ }
1330
+ case "joinTime": {
1331
+ const joinTime = formatDateOnly2(
1332
+ normalizeTimestamp2(
1333
+ pickFirst2(
1334
+ member?.join_time,
1335
+ member?.joined_at,
1336
+ member?.joinTime,
1337
+ member?.joinedAt
1338
+ )
1339
+ )
1340
+ );
1341
+ if (joinTime) values.push(`\u5165\u7FA4:${joinTime}`);
1342
+ break;
1343
+ }
1344
+ case "lastSentTime": {
1345
+ const lastSentTime = formatDateTime2(
1346
+ normalizeTimestamp2(
1347
+ pickFirst2(
1348
+ member?.last_sent_time,
1349
+ member?.lastSentTime,
1350
+ member?.lastSpeakTimestamp
1351
+ )
1352
+ )
1353
+ );
1354
+ if (lastSentTime) values.push(`\u6D3B\u8DC3:${lastSentTime}`);
1355
+ break;
1356
+ }
1357
+ default:
1358
+ break;
1359
+ }
1360
+ }
1361
+ if (values.length === 0) return userId ? `id:${userId}` : "\u672A\u77E5\u7528\u6237";
1362
+ return values.join(", ");
1363
+ }
1364
+ function createUserInfoProvider(deps) {
1365
+ const { config } = deps;
1366
+ return async (_args, _variables, configurable) => {
1367
+ const session = configurable?.session;
1368
+ if (!session?.userId) return "\u672A\u77E5\u7528\u6237";
1369
+ const items = Array.isArray(config.userInfo?.items) && config.userInfo.items.length ? config.userInfo.items : ["nickname", "userId"];
1370
+ const member = await fetchMember2(session, session.userId);
1371
+ return renderUserInfo(session, member, items);
1372
+ };
1373
+ }
1374
+
1375
+ // src/features/variables/register.ts
1376
+ function registerVariables(deps) {
1377
+ const { ctx, config, log } = deps;
1378
+ const chatlunaService = ctx.chatluna;
1379
+ const promptRenderer = chatlunaService?.promptRenderer;
1380
+ if (!promptRenderer?.registerFunctionProvider) return;
1381
+ const userInfoProvider = createUserInfoProvider({ config });
1382
+ const userInfoName = String(
1383
+ config.userInfo?.variableName || "userInfo"
1384
+ ).trim();
1385
+ if (userInfoName) {
1386
+ promptRenderer.registerFunctionProvider(userInfoName, userInfoProvider);
1387
+ log?.("info", `\u7528\u6237\u4FE1\u606F\u53D8\u91CF\u5DF2\u6CE8\u518C: ${userInfoName}`);
1388
+ }
1389
+ const botInfoProvider = createBotInfoProvider({ config });
1390
+ const botInfoName = String(config.botInfo?.variableName || "botInfo").trim();
1391
+ if (botInfoName) {
1392
+ promptRenderer.registerFunctionProvider(botInfoName, botInfoProvider);
1393
+ log?.("info", `Bot\u4FE1\u606F\u53D8\u91CF\u5DF2\u6CE8\u518C: ${botInfoName}`);
1394
+ }
1395
+ const groupInfoProvider = createGroupInfoProvider({ config, log });
1396
+ const groupInfoName = String(
1397
+ config.groupInfo?.variableName || "groupInfo"
1398
+ ).trim();
1399
+ if (groupInfoName) {
1400
+ promptRenderer.registerFunctionProvider(groupInfoName, groupInfoProvider);
1401
+ log?.("info", `\u7FA4\u7EC4\u4FE1\u606F\u53D8\u91CF\u5DF2\u6CE8\u518C: ${groupInfoName}`);
1402
+ }
1403
+ const randomProvider = createRandomProvider({ config });
1404
+ const randomName = String(config.random?.variableName || "random").trim();
1405
+ if (randomName) {
1406
+ promptRenderer.registerFunctionProvider(randomName, randomProvider);
1407
+ log?.("info", `\u968F\u673A\u6570\u53D8\u91CF\u5DF2\u6CE8\u518C: ${randomName}`);
1408
+ }
1409
+ }
1410
+
1411
+ // src/plugin.ts
1412
+ function apply(ctx, config) {
1413
+ const chatlunaService = ctx.chatluna;
1414
+ const plugin = {
1415
+ registerTool: (name2, tool) => {
1416
+ chatlunaService?.platform?.registerTool?.(name2, tool);
1417
+ }
1418
+ };
1419
+ const log = createLogger(ctx, config);
1420
+ let xmlRuntime = null;
1421
+ const initializeServices = async () => {
1422
+ log("info", "toolbox \u521D\u59CB\u5316\u5F00\u59CB");
1423
+ registerVariables({ ctx, config, log });
1424
+ const protocol = resolveOneBotProtocol(config, log);
1425
+ registerNativeTools({ ctx, config, plugin, protocol, log });
1426
+ if (config.enablePokeXmlTool || config.enableEmojiXmlTool || config.enableDeleteXmlTool) {
1427
+ xmlRuntime = registerXmlTools({ ctx, config, protocol, log });
1428
+ xmlRuntime.start();
1429
+ log("info", "XML \u5DE5\u5177\u5DF2\u542F\u7528");
1430
+ }
1431
+ log("info", "toolbox \u521D\u59CB\u5316\u5B8C\u6210");
1432
+ };
1433
+ const dispose = () => {
1434
+ xmlRuntime?.stop();
1435
+ xmlRuntime = null;
1436
+ };
1437
+ ctx.on("dispose", dispose);
1438
+ if (ctx.root.lifecycle.isActive) {
1439
+ void initializeServices();
1440
+ } else {
1441
+ ctx.on("ready", () => {
1442
+ void initializeServices();
1443
+ });
1444
+ }
1445
+ }
1446
+ // Annotate the CommonJS export names for ESM import in node:
1447
+ 0 && (module.exports = {
1448
+ Config,
1449
+ ConfigSchema,
1450
+ DEFAULT_MEMBER_INFO_ITEMS,
1451
+ NativeToolsSchema,
1452
+ RAW_INTERCEPTOR_TAG,
1453
+ VariablesSchema,
1454
+ XmlToolsSchema,
1455
+ apply,
1456
+ callOneBotAPI,
1457
+ createBotInfoProvider,
1458
+ createDeleteMessageTool,
1459
+ createGroupInfoProvider,
1460
+ createLogger,
1461
+ createPokeTool,
1462
+ createRandomProvider,
1463
+ createSetGroupCardTool,
1464
+ createSetMsgEmojiTool,
1465
+ createSetProfileTool,
1466
+ createUserInfoProvider,
1467
+ createXmlInterceptor,
1468
+ ensureOneBotSession,
1469
+ getSession,
1470
+ inject,
1471
+ name,
1472
+ parseXmlActions,
1473
+ registerNativeTools,
1474
+ registerVariables,
1475
+ registerXmlTools,
1476
+ resolveOneBotProtocol,
1477
+ sendDeleteMessage,
1478
+ sendMsgEmoji,
1479
+ sendPoke
1480
+ });