联网搜索响应超限的诊断带上实际收到的字节数
- WebSearchError::ResponseTooLarge 原来只记 max_bytes,用户只看到「超过上限 524288 bytes」,不知道实际多大 - 两个构造点都已拿到真实大小:content_length() 与 bytes.len() + chunk.len(),变体加 got_bytes 并写进文案 - 判定与两个构造点位置不变,仅补上实际值 验证: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:
@@ -3452,11 +3452,12 @@ async fn bridge_web_search_at(
|
||||
status: response.status().as_u16(),
|
||||
});
|
||||
}
|
||||
if response
|
||||
if let Some(length) = response
|
||||
.content_length()
|
||||
.is_some_and(|length| length > DIRECT_TOOL_BRIDGE_MAX_SEARCH_RESPONSE_BYTES as u64)
|
||||
.filter(|length| *length > DIRECT_TOOL_BRIDGE_MAX_SEARCH_RESPONSE_BYTES as u64)
|
||||
{
|
||||
return Err(WebSearchError::ResponseTooLarge {
|
||||
got_bytes: usize::try_from(length).unwrap_or(usize::MAX),
|
||||
max_bytes: DIRECT_TOOL_BRIDGE_MAX_SEARCH_RESPONSE_BYTES,
|
||||
});
|
||||
}
|
||||
@@ -3470,8 +3471,10 @@ async fn bridge_web_search_at(
|
||||
cause: error.to_string(),
|
||||
})?
|
||||
{
|
||||
if bytes.len() + chunk.len() > DIRECT_TOOL_BRIDGE_MAX_SEARCH_RESPONSE_BYTES {
|
||||
let received_bytes = bytes.len() + chunk.len();
|
||||
if received_bytes > DIRECT_TOOL_BRIDGE_MAX_SEARCH_RESPONSE_BYTES {
|
||||
return Err(WebSearchError::ResponseTooLarge {
|
||||
got_bytes: received_bytes,
|
||||
max_bytes: DIRECT_TOOL_BRIDGE_MAX_SEARCH_RESPONSE_BYTES,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ pub(crate) enum WebSearchError {
|
||||
ClientUnavailable { cause: String },
|
||||
RequestFailed { cause: String },
|
||||
HttpStatusNotSuccess { status: u16 },
|
||||
ResponseTooLarge { max_bytes: usize },
|
||||
ResponseTooLarge { got_bytes: usize, max_bytes: usize },
|
||||
ResponseReadFailed { cause: String },
|
||||
NoPublicResults,
|
||||
}
|
||||
@@ -62,8 +62,13 @@ impl ToolFailure for WebSearchError {
|
||||
Self::HttpStatusNotSuccess { status } => {
|
||||
format!("联网搜索失败:AGC 受控搜索返回 HTTP {status}。")
|
||||
}
|
||||
Self::ResponseTooLarge { max_bytes } => {
|
||||
format!("联网搜索失败:AGC 受控搜索响应超过大小上限 {max_bytes} bytes。")
|
||||
Self::ResponseTooLarge {
|
||||
got_bytes,
|
||||
max_bytes,
|
||||
} => {
|
||||
format!(
|
||||
"联网搜索失败:AGC 受控搜索响应有 {got_bytes} bytes,超过大小上限 {max_bytes} bytes。"
|
||||
)
|
||||
}
|
||||
Self::ResponseReadFailed { cause } => {
|
||||
format!("联网搜索失败:读取 AGC 受控搜索响应失败:{cause}")
|
||||
|
||||
Reference in New Issue
Block a user