koishi-plugin-chatluna-toolbox 0.0.15 → 0.0.16

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 (2) hide show
  1. package/lib/index.js +55 -40
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -589,13 +589,12 @@ var DEFAULT_XML_REFERENCE_PROMPT = `## \u52A8\u4F5C\u6307\u4EE4
589
589
  - id: user_id
590
590
  - duration: \u7981\u8A00\u65F6\u957F\uFF0C\u5355\u4F4D\u79D2\uFF0C\u4F20 0 \u8868\u793A\u89E3\u9664\u7981\u8A00
591
591
  - \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
592
+ - \u4F60\u5728\u672C\u7FA4\u4E3A\u7BA1\u7406\u5458\u65F6\u7528\u4E8E\u7981\u8A00\u6216\u89E3\u9664\u7981\u8A00\u6307\u5B9A\u7FA4\u6210\u5458
594
593
  4. \u64A4\u56DE\u6D88\u606F: <delete message_id=""/>
595
594
  - message_id: \u6D88\u606F ID
596
595
  - \u9002\u7528\u573A\u666F:
597
- - \u4F60\u5728\u672C\u7FA4\u4E3A\u7BA1\u7406\u5458
598
- - \u7528\u4E8E\u64A4\u56DE\u6307\u5B9A\u6D88\u606F
596
+ - \u64A4\u56DE\u81EA\u5DF1\u53D1\u7684\u6D88\u606F
597
+ - \u4F60\u5728\u672C\u7FA4\u4E3A\u7BA1\u7406\u5458\u65F6\u64A4\u56DE\u5176\u4ED6\u7528\u6237\u53D1\u9001\u7684\u6D88\u606F
599
598
 
600
599
  \u683C\u5F0F\u793A\u4F8B:
601
600
  \`\`\`xml
@@ -760,6 +759,7 @@ function createLogger(ctx, config) {
760
759
 
761
760
  // src/features/native-tools/tools/delete-msg.ts
762
761
  var import_zod = require("zod");
762
+ var import_tools = require("@langchain/core/tools");
763
763
 
764
764
  // src/features/native-tools/onebot-api.ts
765
765
  function ensureOneBotSession(session) {
@@ -789,19 +789,33 @@ function getSession(runnable) {
789
789
  }
790
790
 
791
791
  // src/features/native-tools/tools/delete-msg.ts
792
+ function assertOneBotSuccess(result) {
793
+ const response = result;
794
+ if (!response || typeof response !== "object") return;
795
+ const status = String(response.status || "").toLowerCase();
796
+ const failed = status === "failed" || !!status && status !== "ok" || typeof response.retcode === "number" && response.retcode !== 0;
797
+ if (!failed) return;
798
+ const reason = response.wording || response.message || response.status;
799
+ const retcode = typeof response.retcode === "number" ? ` (retcode: ${response.retcode})` : "";
800
+ throw new Error(`${reason || "OneBot returned failed"}${retcode}`);
801
+ }
792
802
  async function sendDeleteMessage(params) {
793
- const { session, messageId, log } = params;
803
+ const { session, message_id, log } = params;
794
804
  try {
795
805
  if (!session) return "No session context available.";
796
- const messageIdRaw = messageId.trim();
797
- if (!messageIdRaw) return "messageId is required.";
806
+ const messageIdRaw = message_id.trim();
807
+ if (!messageIdRaw) return "message_id is required.";
798
808
  const numericId = /^\d+$/.test(messageIdRaw) ? Number(messageIdRaw) : messageIdRaw;
799
809
  if (session.platform === "onebot") {
800
810
  const { error, internal } = ensureOneBotSession(session);
801
811
  if (error) return error;
802
- await callOneBotAPI(internal, "delete_msg", { message_id: numericId }, [
803
- "deleteMsg"
804
- ]);
812
+ const result = await callOneBotAPI(
813
+ internal,
814
+ "delete_msg",
815
+ { message_id: numericId },
816
+ ["deleteMsg"]
817
+ );
818
+ assertOneBotSuccess(result);
805
819
  const success = `Message deleted by ID ${messageIdRaw}.`;
806
820
  log?.("info", success);
807
821
  return success;
@@ -823,18 +837,18 @@ async function sendDeleteMessage(params) {
823
837
  }
824
838
  function createDeleteMessageTool(deps) {
825
839
  const { toolName, description, log } = deps;
826
- const tool = {
827
- name: toolName || "delete_msg",
828
- description: description || DEFAULT_DELETE_MESSAGE_TOOL_DESCRIPTION,
829
- schema: import_zod.z.object({
830
- messageId: import_zod.z.string().min(1, "messageId is required").describe("Specific message ID to delete.")
831
- }),
840
+ return new class extends import_tools.StructuredTool {
841
+ name = toolName || "delete_msg";
842
+ description = description || DEFAULT_DELETE_MESSAGE_TOOL_DESCRIPTION;
843
+ schema = import_zod.z.object({
844
+ message_id: import_zod.z.string().min(1, "message_id is required").describe("Specific message ID to delete.")
845
+ }).strict();
832
846
  async _call(input, _manager, runnable) {
833
847
  try {
834
848
  const session = getSession(runnable);
835
849
  return await sendDeleteMessage({
836
850
  session,
837
- messageId: input.messageId,
851
+ message_id: input.message_id,
838
852
  log
839
853
  });
840
854
  } catch (error) {
@@ -842,13 +856,12 @@ function createDeleteMessageTool(deps) {
842
856
  return `delete_msg failed: ${error.message}`;
843
857
  }
844
858
  }
845
- };
846
- return tool;
859
+ }();
847
860
  }
848
861
 
849
862
  // src/features/native-tools/tools/poke.ts
850
863
  var import_zod2 = require("zod");
851
- var import_tools = require("@langchain/core/tools");
864
+ var import_tools2 = require("@langchain/core/tools");
852
865
  async function sendPoke(params) {
853
866
  try {
854
867
  const { session, userId, groupId, log, protocol } = params;
@@ -858,11 +871,11 @@ async function sendPoke(params) {
858
871
  session: validatedSession
859
872
  } = ensureOneBotSession(session);
860
873
  if (error) return error;
861
- const resolvedGroupId = groupId?.trim() || validatedSession?.guildId || validatedSession?.channelId || validatedSession?.roomId;
874
+ const resolvedGroupId = groupId?.trim() || validatedSession?.guildId || validatedSession?.roomId;
862
875
  const payload = { user_id: userId };
863
876
  if (resolvedGroupId) payload.group_id = resolvedGroupId;
877
+ const action = payload.group_id ? "group_poke" : "friend_poke";
864
878
  if (protocol === "llbot") {
865
- const action = payload.group_id ? "group_poke" : "friend_poke";
866
879
  if (typeof internal._request === "function") {
867
880
  await internal._request(action, payload);
868
881
  } else if (typeof internal[action] === "function") {
@@ -871,7 +884,9 @@ async function sendPoke(params) {
871
884
  throw new Error(`\u5F53\u524D\u9002\u914D\u5668\u672A\u5B9E\u73B0 ${action} API\u3002`);
872
885
  }
873
886
  } else if (typeof internal._request === "function") {
874
- await internal._request("send_poke", payload);
887
+ await internal._request(action, payload);
888
+ } else if (typeof internal[action] === "function") {
889
+ await internal[action](payload);
875
890
  } else if (typeof internal.sendPoke === "function") {
876
891
  await internal.sendPoke(
877
892
  payload.group_id,
@@ -893,7 +908,7 @@ async function sendPoke(params) {
893
908
  }
894
909
  function createPokeTool(deps) {
895
910
  const { toolName, description, log, protocol } = deps;
896
- return new class extends import_tools.StructuredTool {
911
+ return new class extends import_tools2.StructuredTool {
897
912
  name = toolName || "poke_user";
898
913
  description = description || DEFAULT_POKE_TOOL_DESCRIPTION;
899
914
  schema = import_zod2.z.object({
@@ -915,7 +930,7 @@ function createPokeTool(deps) {
915
930
 
916
931
  // src/features/native-tools/tools/set-group-ban.ts
917
932
  var import_zod3 = require("zod");
918
- var import_tools2 = require("@langchain/core/tools");
933
+ var import_tools3 = require("@langchain/core/tools");
919
934
  function resolveGroupId(session, groupId) {
920
935
  return groupId?.trim() || (session.guildId || "").trim() || (session.channelId || "").trim() || (session.roomId || "").trim();
921
936
  }
@@ -965,7 +980,7 @@ async function sendGroupBan(params) {
965
980
  }
966
981
  function createSetGroupBanTool(deps) {
967
982
  const { toolName, description, protocol, log } = deps;
968
- return new class extends import_tools2.StructuredTool {
983
+ return new class extends import_tools3.StructuredTool {
969
984
  name = toolName || "set_group_ban";
970
985
  description = description || DEFAULT_SET_GROUP_BAN_TOOL_DESCRIPTION;
971
986
  schema = import_zod3.z.object({
@@ -989,7 +1004,7 @@ function createSetGroupBanTool(deps) {
989
1004
 
990
1005
  // src/features/native-tools/tools/set-group-card.ts
991
1006
  var import_zod4 = require("zod");
992
- var import_tools3 = require("@langchain/core/tools");
1007
+ var import_tools4 = require("@langchain/core/tools");
993
1008
  async function sendSetGroupCard(params) {
994
1009
  try {
995
1010
  const { session, userId, card, groupId, log } = params;
@@ -1020,7 +1035,7 @@ async function sendSetGroupCard(params) {
1020
1035
  }
1021
1036
  function createSetGroupCardTool(deps) {
1022
1037
  const { toolName, description, log } = deps;
1023
- return new class extends import_tools3.StructuredTool {
1038
+ return new class extends import_tools4.StructuredTool {
1024
1039
  name = toolName || "set_group_card";
1025
1040
  description = description || DEFAULT_SET_GROUP_CARD_TOOL_DESCRIPTION;
1026
1041
  schema = import_zod4.z.object({
@@ -1042,7 +1057,7 @@ function createSetGroupCardTool(deps) {
1042
1057
 
1043
1058
  // src/features/native-tools/tools/set-group-special-title.ts
1044
1059
  var import_zod5 = require("zod");
1045
- var import_tools4 = require("@langchain/core/tools");
1060
+ var import_tools5 = require("@langchain/core/tools");
1046
1061
  function resolveGroupId2(session, groupId) {
1047
1062
  return groupId?.trim() || (session.guildId || "").trim() || (session.channelId || "").trim() || (session.roomId || "").trim();
1048
1063
  }
@@ -1082,7 +1097,7 @@ async function sendSetGroupSpecialTitle(params) {
1082
1097
  }
1083
1098
  function createSetGroupSpecialTitleTool(deps) {
1084
1099
  const { toolName, description, protocol, log } = deps;
1085
- return new class extends import_tools4.StructuredTool {
1100
+ return new class extends import_tools5.StructuredTool {
1086
1101
  name = toolName || "set_group_special_title";
1087
1102
  description = description || DEFAULT_SET_GROUP_SPECIAL_TITLE_TOOL_DESCRIPTION;
1088
1103
  schema = import_zod5.z.object({
@@ -1106,7 +1121,7 @@ function createSetGroupSpecialTitleTool(deps) {
1106
1121
 
1107
1122
  // src/features/native-tools/tools/set-msg-emoji.ts
1108
1123
  var import_zod6 = require("zod");
1109
- var import_tools5 = require("@langchain/core/tools");
1124
+ var import_tools6 = require("@langchain/core/tools");
1110
1125
  async function sendMsgEmoji(params) {
1111
1126
  try {
1112
1127
  const { session, messageId, emojiId, log, protocol } = params;
@@ -1137,7 +1152,7 @@ async function sendMsgEmoji(params) {
1137
1152
  }
1138
1153
  function createSetMsgEmojiTool(deps) {
1139
1154
  const { toolName, description, log, protocol } = deps;
1140
- return new class extends import_tools5.StructuredTool {
1155
+ return new class extends import_tools6.StructuredTool {
1141
1156
  name = toolName || "set_msg_emoji";
1142
1157
  description = description || DEFAULT_SET_MSG_EMOJI_TOOL_DESCRIPTION;
1143
1158
  schema = import_zod6.z.object({
@@ -1159,7 +1174,7 @@ function createSetMsgEmojiTool(deps) {
1159
1174
 
1160
1175
  // src/features/native-tools/tools/profile.ts
1161
1176
  var import_zod7 = require("zod");
1162
- var import_tools6 = require("@langchain/core/tools");
1177
+ var import_tools7 = require("@langchain/core/tools");
1163
1178
  var genders = {
1164
1179
  unknown: "0",
1165
1180
  male: "1",
@@ -1186,7 +1201,7 @@ async function sendSetProfile(params) {
1186
1201
  }
1187
1202
  function createSetProfileTool(deps) {
1188
1203
  const { toolName, description, log, protocol } = deps;
1189
- return new class extends import_tools6.StructuredTool {
1204
+ return new class extends import_tools7.StructuredTool {
1190
1205
  name = toolName || "set_self_profile";
1191
1206
  description = description || DEFAULT_SET_SELF_PROFILE_TOOL_DESCRIPTION;
1192
1207
  schema = import_zod7.z.object({
@@ -1209,7 +1224,7 @@ function createSetProfileTool(deps) {
1209
1224
 
1210
1225
  // src/features/native-tools/tools/set-qq-avatar.ts
1211
1226
  var import_zod8 = require("zod");
1212
- var import_tools7 = require("@langchain/core/tools");
1227
+ var import_tools8 = require("@langchain/core/tools");
1213
1228
  function isHttpUrl(value) {
1214
1229
  return /^https?:\/\//i.test(value);
1215
1230
  }
@@ -1237,7 +1252,7 @@ async function fetchImageAsOneBotFile(ctx, imageUrl) {
1237
1252
  throw new Error(`\u65E0\u6CD5\u8BFB\u53D6\u5934\u50CF\u56FE\u7247\uFF1A${error.message}`);
1238
1253
  }
1239
1254
  }
1240
- function assertOneBotSuccess(result) {
1255
+ function assertOneBotSuccess2(result) {
1241
1256
  const response = result;
1242
1257
  if (!response || typeof response !== "object") return;
1243
1258
  const failed = response.status === "failed" || typeof response.retcode === "number" && response.retcode !== 0;
@@ -1257,7 +1272,7 @@ async function sendSetQQAvatar(params) {
1257
1272
  const result = await callOneBotAPI(internal, "set_qq_avatar", { file }, [
1258
1273
  "setQQAvatar"
1259
1274
  ]);
1260
- assertOneBotSuccess(result);
1275
+ assertOneBotSuccess2(result);
1261
1276
  const message = "QQ \u5934\u50CF\u5DF2\u66F4\u65B0\u3002";
1262
1277
  log?.("info", message);
1263
1278
  return message;
@@ -1268,7 +1283,7 @@ async function sendSetQQAvatar(params) {
1268
1283
  }
1269
1284
  function createSetQQAvatarTool(deps) {
1270
1285
  const { ctx, toolName, description, log } = deps;
1271
- return new class extends import_tools7.StructuredTool {
1286
+ return new class extends import_tools8.StructuredTool {
1272
1287
  name = toolName || "set_qq_avatar";
1273
1288
  description = description || DEFAULT_SET_QQ_AVATAR_TOOL_DESCRIPTION;
1274
1289
  schema = import_zod8.z.object({
@@ -1687,7 +1702,7 @@ function registerCharacterReplyTools(deps) {
1687
1702
  if (typeof action.message_id !== "string") continue;
1688
1703
  await sendDeleteMessage({
1689
1704
  session,
1690
- messageId: action.message_id,
1705
+ message_id: action.message_id,
1691
1706
  log
1692
1707
  });
1693
1708
  }
@@ -1787,7 +1802,7 @@ function createXmlProcessor(deps) {
1787
1802
  if (messageIds.length > 0) handled = true;
1788
1803
  for (const messageId of messageIds) {
1789
1804
  try {
1790
- await runDelete({ session, messageId, log });
1805
+ await runDelete({ session, message_id: messageId, log });
1791
1806
  } catch (error) {
1792
1807
  log?.("warn", "XML \u89E6\u53D1\u64A4\u56DE\u5931\u8D25", error);
1793
1808
  }
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.15",
4
+ "version": "0.0.16",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
7
7
  "files": [