pub fn parse_streaming_json(s: &str) -> ValueExpand description
Parse potentially incomplete JSON from streaming tool calls.
During streaming, tool call arguments arrive incrementally. This function attempts to parse the partial JSON, returning an empty object if parsing fails.
§Strategy
- Try parsing as complete JSON
- Try adding various closing brackets/braces
- Fall back to empty object
§Example
use alchemy_llm::utils::json_parse::parse_streaming_json;
use serde_json::json;
let partial = r#"{"name": "test", "value": 42"#;
let result = parse_streaming_json(partial);
assert_eq!(result, json!({"name": "test", "value": 42}));
// Complete JSON works too
let complete = r#"{"name": "test"}"#;
let result = parse_streaming_json(complete);
assert_eq!(result, json!({"name": "test"}));