联网搜索 maxResults 非整数的诊断上限改为随变体携带,不再写死 5

- WebSearchError::MaxResultsNotInteger 原文案把上限写死成「1 到 5」,同一份文件里 MaxResultsOutOfRange 却是从 DIRECT_TOOL_BRIDGE_MAX_SEARCH_RESULTS 取 {max};常量一改,两条诊断就会自相矛盾
- 变体加上 max: u64,构造点传 DIRECT_TOOL_BRIDGE_MAX_SEARCH_RESULTS as u64,文案改成「1 到 {max}」
- 只影响这一条诊断的取值来源,判定区间不变

验证:cargo test --bin genarrative-ai-game-creator-shell -- agent::direct_tool_bridge::tests::search_parser_accepts_only_bounded_public_https_results 通过
This commit is contained in:
2026-10-01 14:11:27 +08:00
parent b2d01ef8c1
commit 23a111985a
2 changed files with 4 additions and 3 deletions
@@ -3417,6 +3417,7 @@ pub(in crate::agent) fn web_search_input(
.as_u64()
.ok_or_else(|| WebSearchError::MaxResultsNotInteger {
got: value.to_string(),
max: DIRECT_TOOL_BRIDGE_MAX_SEARCH_RESULTS as u64,
})?,
};
if !(1..=DIRECT_TOOL_BRIDGE_MAX_SEARCH_RESULTS as u64).contains(&max_results) {
@@ -13,7 +13,7 @@ pub(crate) enum WebSearchError {
QueryEmpty,
QueryTooLong { got_chars: usize, max_chars: usize },
QueryHasControlCharacters,
MaxResultsNotInteger { got: String },
MaxResultsNotInteger { got: String, max: u64 },
MaxResultsOutOfRange { got: u64, max: u64 },
ClientUnavailable { cause: String },
RequestFailed { cause: String },
@@ -47,8 +47,8 @@ impl ToolFailure for WebSearchError {
max_chars,
} => format!("联网搜索失败:query 有 {got_chars} 个字符,超过上限 {max_chars}。"),
Self::QueryHasControlCharacters => "联网搜索失败:query 含有控制字符。".to_string(),
Self::MaxResultsNotInteger { got } => {
format!("联网搜索失败:maxResults 必须是 1 到 5 的整数,当前是「{got}」。")
Self::MaxResultsNotInteger { got, max } => {
format!("联网搜索失败:maxResults 必须是 1 到 {max} 的整数,当前是「{got}」。")
}
Self::MaxResultsOutOfRange { got, max } => {
format!("联网搜索失败:maxResults={got} 超出范围,必须在 1 到 {max} 之间。")