diff --git a/src/main/java/Sdf1_login/AIChatManager.java b/src/main/java/Sdf1_login/AIChatManager.java index 69c26ae..2019c53 100644 --- a/src/main/java/Sdf1_login/AIChatManager.java +++ b/src/main/java/Sdf1_login/AIChatManager.java @@ -1205,7 +1205,9 @@ public class AIChatManager { int fetchIdx = reply.indexOf("TOOL:FETCH:"); if (fetchIdx >= 0) { String after = reply.substring(fetchIdx + "TOOL:FETCH:".length()).trim(); - // ★ 第77批:用空白字符截取参数(空格/换行/制表符) + // ★ 第80批:截取到 "→ 联网抓取" 或换行符为止(关键词可含空格) + int arrowIdx = after.indexOf("→ 联网抓取"); + if (arrowIdx >= 0) after = after.substring(0, arrowIdx).trim(); int ws = indexOfWhitespace(after); if (ws >= 0) after = after.substring(0, ws).trim(); after = after.replaceAll("[。,、!?.!?,)$\\]]$", "").trim(); @@ -1214,18 +1216,41 @@ public class AIChatManager { } } - // TOOL:SEARCH:关键词 + // TOOL:SEARCH:关键词 [→ 联网搜索] int idx = reply.indexOf("TOOL:SEARCH:"); if (idx >= 0) { String after = reply.substring(idx + "TOOL:SEARCH:".length()).trim(); - // ★ 第77批:用空白字符截取参数(空格/换行/制表符) - int ws = indexOfWhitespace(after); - if (ws >= 0) after = after.substring(0, ws).trim(); + // ★ 第80批:截取到 "→ 联网搜索" 或换行符为止(关键词可含空格) + int arrowIdx = after.indexOf("→ 联网搜索"); + if (arrowIdx >= 0) after = after.substring(0, arrowIdx).trim(); + // ★ 第80批:截取到换行符为止 + int nl = after.indexOf('\n'); + if (nl >= 0) after = after.substring(0, nl).trim(); after = after.replaceAll("[。,、!?.!?,)$", "").trim(); if (!after.isEmpty() && after.length() <= 100) { return new ToolCall(ToolCall.Type.SEARCH, after); } } + + // ★ 第80批:无 TOOL:SEARCH: 前缀,但有 "关键词 → 联网搜索" 格式 + // 例: "牛铃 音符盒 音色 放置方块 → 联网搜索" + int arrowIdx2 = reply.indexOf("→ 联网搜索"); + if (arrowIdx2 > 0) { + String before = reply.substring(0, arrowIdx2).trim(); + // 截取到换行符为止(关键词在同行) + int nl2 = before.indexOf('\n'); + if (nl2 >= 0) before = before.substring(0, nl2).trim(); + // 去掉可能残留的 "TOOL:SEARCH:" 前缀(如果模型混用格式) + if (before.startsWith("TOOL:SEARCH:")) { + before = before.substring("TOOL:SEARCH:".length()).trim(); + } + before = before.replaceAll("[。,、!?.!?,)$", "").trim(); + if (!before.isEmpty() && before.length() <= 100) { + plugin.getLogger().info("[AI聊天-Agent] 识别无前缀搜索标记: \"" + before + "\""); + return new ToolCall(ToolCall.Type.SEARCH, before); + } + } + return null; }