diff --git a/apps/ai-game-creator-shell/src-tauri/src/agent/direct_tool_bridge.rs b/apps/ai-game-creator-shell/src-tauri/src/agent/direct_tool_bridge.rs index f44904bd4..bbf31cf21 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/agent/direct_tool_bridge.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/agent/direct_tool_bridge.rs @@ -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, }); } diff --git a/apps/ai-game-creator-shell/src-tauri/src/agent/tool/web_search/error.rs b/apps/ai-game-creator-shell/src-tauri/src/agent/tool/web_search/error.rs index 894e60c48..8296586e9 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/agent/tool/web_search/error.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/agent/tool/web_search/error.rs @@ -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}")