fix: serialize non-string text_result in pure ref path

text_result can be a JSON object/number/boolean, not just a string.
Serialize non-string values to text instead of dropping them.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
jh-block
2026-03-10 17:44:54 +01:00
parent 3a8fdd63c3
commit 02159bc40e
@@ -318,10 +318,13 @@ impl CodeExecutionClient {
.output
.as_ref()
.and_then(|v| v.get("text_result"))
.and_then(|v| v.as_str())
.filter(|s| !s.is_empty())
.unwrap_or("Tool returned rich content.");
let mut contents = vec![Content::text(text_fallback)];
.and_then(|v| match v {
Value::String(s) if !s.is_empty() => Some(s.clone()),
Value::Null | Value::String(_) => None,
other => Some(other.to_string()),
})
.unwrap_or_else(|| "Tool returned rich content.".to_string());
let mut contents = vec![Content::text(&text_fallback)];
contents.extend(rich_contents);
Ok(contents)
} else {