fix(windsurf): 修复 native 工具流式回程

This commit is contained in:
Entropy.Xu
2026-05-21 02:55:05 +08:00
parent 4112a8b2ea
commit 6b04a0a3a6
2 changed files with 82 additions and 9 deletions

View File

@@ -2157,6 +2157,11 @@ fn decode_body_for_storage(body_base64: Option<&str>) -> Option<Value> {
let bytes = base64::engine::general_purpose::STANDARD
.decode(body_base64)
.ok()?;
if let Some(error_body) =
aether_ai_formats::api::extract_provider_private_stream_error_body(None, &bytes)
{
return Some(error_body);
}
if let Ok(json_body) = serde_json::from_slice::<Value>(&bytes) {
return Some(json_body);
}
@@ -3014,7 +3019,7 @@ mod tests {
build_stream_terminal_usage_event, build_streaming_usage_record,
build_sync_terminal_usage_event, build_sync_terminal_usage_payload_seed,
build_sync_terminal_usage_seed, build_terminal_usage_context_seed,
build_terminal_usage_event_from_seed, build_usage_event_data_seed,
build_terminal_usage_event_from_seed, build_usage_event_data_seed, decode_body_for_storage,
extract_token_counts_from_json, extract_token_counts_from_value, headers_to_json,
mask_header_value, mask_sensitive_body_fields, mask_sensitive_headers_in_json_value,
parse_sse_body_for_storage, resolve_error_message, trim_owned_non_empty_string,
@@ -5403,6 +5408,27 @@ mod tests {
);
}
#[test]
fn decode_body_for_storage_extracts_connect_json_error_frames() {
let payload = br#"{"error":{"code":"resource_exhausted","message":"quota exhausted"}}"#;
let mut framed = Vec::new();
framed.push(2);
framed.extend_from_slice(&(payload.len() as u32).to_be_bytes());
framed.extend_from_slice(payload);
let body_base64 = base64::engine::general_purpose::STANDARD.encode(framed);
assert_eq!(
decode_body_for_storage(Some(body_base64.as_str())),
Some(json!({
"error": {
"code": "resource_exhausted",
"message": "quota exhausted",
"type": "resource_exhausted"
}
}))
);
}
#[test]
fn parse_sse_body_for_storage_handles_crlf_and_cr_line_endings() {
let sse_body = concat!(