fix: always strip old functionCall/functionResponse from LS history
The function call stripping was only happening when no custom tools were present. But even with custom tools injected, the LS history contains functionCall/functionResponse parts for LS-internal tools that we stripped, causing MALFORMED_FUNCTION_CALL. Now always strip regardless of custom tools presence.
This commit is contained in:
@@ -206,8 +206,13 @@ pub fn modify_request(body: &[u8], tool_ctx: Option<&ToolContext>) -> Option<Vec
|
|||||||
changes.push("remove toolConfig (no tools)".to_string());
|
changes.push("remove toolConfig (no tools)".to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Also strip functionCall/functionResponse from conversation history
|
// ── 3b. ALWAYS strip old functionCall/functionResponse from history ───
|
||||||
|
// Even when custom tools are injected, the LS history contains function
|
||||||
|
// call parts for LS-internal tools we stripped. Google rejects these as
|
||||||
|
// MALFORMED_FUNCTION_CALL because the referenced tools don't exist.
|
||||||
|
if STRIP_ALL_TOOLS {
|
||||||
if let Some(contents) = json
|
if let Some(contents) = json
|
||||||
.pointer_mut("/request/contents")
|
.pointer_mut("/request/contents")
|
||||||
.and_then(|v| v.as_array_mut())
|
.and_then(|v| v.as_array_mut())
|
||||||
|
|||||||
@@ -726,6 +726,12 @@ async fn handle_http_over_tls(
|
|||||||
}
|
}
|
||||||
headers_parsed = true;
|
headers_parsed = true;
|
||||||
|
|
||||||
|
// Log error response bodies for debugging
|
||||||
|
if resp.code.unwrap_or(0) >= 400 {
|
||||||
|
let body_preview = String::from_utf8_lossy(&header_buf[hdr_end..]);
|
||||||
|
warn!(domain, status = resp.code.unwrap_or(0), body = %body_preview, "MITM: upstream error response");
|
||||||
|
}
|
||||||
|
|
||||||
// Save body for usage parsing
|
// Save body for usage parsing
|
||||||
response_body_buf.extend_from_slice(&header_buf[hdr_end..]);
|
response_body_buf.extend_from_slice(&header_buf[hdr_end..]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user