1. #353 mergeJsonMissing 补入缺失键后按模板顺序重排 2. #354 AI工具失败路径不再追加系统提示到回复+sanitizeReply拦截TOOL标记和系统提示泄露 3. #355 StackConfigManager clamp时打警告日志(不改模板值,代码适配)
This commit is contained in:
@@ -896,9 +896,12 @@ public class AIChatManager {
|
|||||||
}
|
}
|
||||||
if (toolResults == null) {
|
if (toolResults == null) {
|
||||||
plugin.getLogger().info("[AI聊天-Agent] 工具调用无结果,告知模型无法获取");
|
plugin.getLogger().info("[AI聊天-Agent] 工具调用无结果,告知模型无法获取");
|
||||||
reply = reply.replace("TOOL:" + call.type.name() + ":" + call.arg, "");
|
// ★ 第77批修复(#354):不再把系统提示直接追加到回复里。
|
||||||
// 追加说明让模型知道工具调用失败了,基于"不知道"回答
|
// 原逻辑 reply = reply + "\n(系统提示:...)" 会把内部提示词
|
||||||
reply = reply + "\n(系统提示:联网查询未获取到相关信息,请如实告知玩家你不知道。)";
|
// 原样发给玩家,暴露系统提示词。
|
||||||
|
// 改为:去掉 TOOL 标记后直接 break,让模型基于已有信息回答;
|
||||||
|
// 如果回复里还残留 TOOL 标记,sanitizeReply 会拦截。
|
||||||
|
reply = reply.replace("TOOL:" + call.type.name() + ":" + call.arg, "").trim();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1173,6 +1176,32 @@ public class AIChatManager {
|
|||||||
return fallbackDodge();
|
return fallbackDodge();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ★ 第77批修复(#354):TOOL 标记残留拦截
|
||||||
|
// 工具调用失败时模型可能仍输出 TOOL:SEARCH:关键词 标记,
|
||||||
|
// 或者第二轮请求的回复里残留 TOOL:FETCH: URL 标记
|
||||||
|
if (r.contains("TOOL:SEARCH:") || r.contains("TOOL:FETCH:")) {
|
||||||
|
plugin.getLogger().warning("[AI聊天] 输出守卫:回复含 TOOL 标记残留,拦截");
|
||||||
|
// 尝试去掉 TOOL 标记后放行(如果去掉后还有内容)
|
||||||
|
String cleaned = r.replaceAll("TOOL:(SEARCH|FETCH):[^\\s]*", "").trim();
|
||||||
|
if (!cleaned.isEmpty() && !cleaned.equals(r)) {
|
||||||
|
return cleaned;
|
||||||
|
}
|
||||||
|
return fallbackDodge();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ★ 第77批修复(#354):系统提示泄露拦截
|
||||||
|
// 工具失败路径可能把「(系统提示:...)」追加到回复里
|
||||||
|
if (r.contains("(系统提示") || r.contains("(系统提示")
|
||||||
|
|| r.contains("系统提示:联网查询")) {
|
||||||
|
plugin.getLogger().warning("[AI聊天] 输出守卫:回复含系统提示泄露,拦截");
|
||||||
|
// 尝试去掉系统提示部分后放行
|
||||||
|
String cleaned = r.replaceAll("[((]系统提示[::][^))]*[))]", "").trim();
|
||||||
|
if (!cleaned.isEmpty() && !cleaned.equals(r)) {
|
||||||
|
return cleaned;
|
||||||
|
}
|
||||||
|
return fallbackDodge();
|
||||||
|
}
|
||||||
|
|
||||||
// 3. 敏感话题关键词(与问题侧共用同一词表)
|
// 3. 敏感话题关键词(与问题侧共用同一词表)
|
||||||
String hit = matchOffTopic(r);
|
String hit = matchOffTopic(r);
|
||||||
if (hit != null) {
|
if (hit != null) {
|
||||||
|
|||||||
@@ -1653,6 +1653,9 @@ public class ConfigManager {
|
|||||||
if (!mergeJsonMissing(root, tplEl.getAsJsonObject(), "", added)) {
|
if (!mergeJsonMissing(root, tplEl.getAsJsonObject(), "", added)) {
|
||||||
return false; // 无缺失键,幂等
|
return false; // 无缺失键,幂等
|
||||||
}
|
}
|
||||||
|
// ★ 第77批修复(#353):缺失键插入后按模板顺序重排,
|
||||||
|
// 否则新键追加到末尾而非模板对应位置
|
||||||
|
reorderToTemplateOrder(root, tplEl.getAsJsonObject());
|
||||||
// ① 备份原文件 → .bak 并逐字节校验(失败=取消,原文件不动)
|
// ① 备份原文件 → .bak 并逐字节校验(失败=取消,原文件不动)
|
||||||
File bak = new File(file.getParentFile(), file.getName() + ".bak");
|
File bak = new File(file.getParentFile(), file.getName() + ".bak");
|
||||||
java.nio.file.Files.copy(file.toPath(), bak.toPath(),
|
java.nio.file.Files.copy(file.toPath(), bak.toPath(),
|
||||||
@@ -1697,6 +1700,47 @@ public class ConfigManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ★ 第77批修复(#353):按模板键顺序重排 target 的顶层键。
|
||||||
|
* <p>
|
||||||
|
* mergeJsonMissing 用 target.add() 插入缺失键,Gson JsonObject
|
||||||
|
* 底层是 LinkedHashMap,add() 把新键追加到末尾而非模板对应位置。
|
||||||
|
* 此方法在 mergeJsonMissing 之后调用,按模板顺序重建 JsonObject。
|
||||||
|
* <p>
|
||||||
|
* 只重排顶层键(不递归到子对象),因为子对象内部的键顺序不影响
|
||||||
|
* 功能——只有顶层键顺序影响用户阅读。
|
||||||
|
*
|
||||||
|
* @param target 已补入缺失键的对象(会被重建)
|
||||||
|
* @param tpl 模板对象(提供键顺序)
|
||||||
|
*/
|
||||||
|
private void reorderToTemplateOrder(com.google.gson.JsonObject target,
|
||||||
|
com.google.gson.JsonObject tpl) {
|
||||||
|
com.google.gson.JsonObject reordered = new com.google.gson.JsonObject();
|
||||||
|
// 先按模板顺序放入模板中存在的键
|
||||||
|
for (Map.Entry<String, com.google.gson.JsonElement> en : tpl.entrySet()) {
|
||||||
|
String k = en.getKey();
|
||||||
|
if (k.startsWith("#")) continue;
|
||||||
|
com.google.gson.JsonElement have = target.get(k);
|
||||||
|
if (have != null) {
|
||||||
|
reordered.add(k, have);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 再放入 target 中存在但模板中没有的键(用户自定义键保留)
|
||||||
|
for (Map.Entry<String, com.google.gson.JsonElement> en : target.entrySet()) {
|
||||||
|
String k = en.getKey();
|
||||||
|
if (!reordered.has(k)) {
|
||||||
|
reordered.add(k, en.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 清空原 target 并写入重排后的内容
|
||||||
|
for (String key : new java.util.ArrayList<>(target.keySet())) {
|
||||||
|
target.remove(key);
|
||||||
|
}
|
||||||
|
for (Map.Entry<String, com.google.gson.JsonElement> en : reordered.entrySet()) {
|
||||||
|
target.add(en.getKey(), en.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** 递归把模板里 target 缺失的键补进去(只插入不覆盖;# 说明键跳过) */
|
/** 递归把模板里 target 缺失的键补进去(只插入不覆盖;# 说明键跳过) */
|
||||||
private boolean mergeJsonMissing(com.google.gson.JsonObject target,
|
private boolean mergeJsonMissing(com.google.gson.JsonObject target,
|
||||||
com.google.gson.JsonObject tpl, String path, List<String> added) {
|
com.google.gson.JsonObject tpl, String path, List<String> added) {
|
||||||
|
|||||||
@@ -303,6 +303,11 @@ public class StackConfigManager implements Listener {
|
|||||||
*/
|
*/
|
||||||
private void resolveAndAdd(String key, int stackSize, Map<Material, Integer> out) {
|
private void resolveAndAdd(String key, int stackSize, Map<Material, Integer> out) {
|
||||||
// ★ 第70批:Paper 26.3 强制 maxStackSize ∈ [1,99],配置值 clamp
|
// ★ 第70批:Paper 26.3 强制 maxStackSize ∈ [1,99],配置值 clamp
|
||||||
|
// ★ 第77批-问题3:clamp 时打警告日志,让用户知道配置值被自动修正
|
||||||
|
if (stackSize < 1 || stackSize > 99) {
|
||||||
|
plugin.getLogger().warning("[物品堆叠] 配置项「" + key + "」值 " + stackSize
|
||||||
|
+ " 超出 Paper 26.x 限制 [1,99],已自动修正为 " + Math.max(1, Math.min(99, stackSize)));
|
||||||
|
}
|
||||||
stackSize = Math.max(1, Math.min(99, stackSize));
|
stackSize = Math.max(1, Math.min(99, stackSize));
|
||||||
// 1. 通配符 * (如 oak_* 或 *_wool)
|
// 1. 通配符 * (如 oak_* 或 *_wool)
|
||||||
if (key.contains("*")) {
|
if (key.contains("*")) {
|
||||||
|
|||||||
@@ -12,13 +12,15 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
<!-- 第77批说明:Paper 26.x 限制 maxStackSize ∈ [1,99],值超过99会被自动修正为99并在日志打警告。示范中的128/100是旧版写法,保留供参考。新配置请填 ≤99。 -->
|
||||||
|
|
||||||
| 物品名字 | 数量 |
|
| 物品名字 | 数量 |
|
||||||
| :---: |:---:|
|
| :---: |:---:|
|
||||||
| 示范-苹果 | 100个 |
|
| 示范-苹果 | 99个 |
|
||||||
| gold | 128 |
|
| gold | 99 |
|
||||||
## ----配置区域结束----
|
## ----配置区域结束----
|
||||||
|
|
||||||
### 物品堆叠食用说明
|
### 物品堆叠食用说明
|
||||||
|
|
||||||
- 在上方json围栏块/表格块内,按键值对修改。支持使用中文。通配符支持:`*`和中文词组`所有`。比如`oak_*`表示所有以oak开头的,比如橡木、橡木告示牌、橡木台阶等。`所有羊毛`表示所有以_wool结尾的羊毛。
|
- 在上方json围栏块/表格块内,按键值对修改。支持使用中文。通配符支持:`*`和中文词组`所有`。比如`oak_*`表示所有以oak开头的,比如橡木、橡木告示牌、橡木台阶等。`所有羊毛`表示所有以_wool结尾的羊毛。<br>
|
||||||
|
- MC最大上限是99,因此配置文件里,数量建议不要超过99(虽然插件会修正)
|
||||||
|
|||||||
Reference in New Issue
Block a user