| 2053 | } |
| 2054 | |
| 2055 | fn parse_output_items(output: &[Value]) -> (Vec<ContentPart>, bool, Vec<Vec<LogprobEntry>>) { |
| 2056 | let mut parts = Vec::new(); |
| 2057 | let mut has_function_call = false; |
| 2058 | let mut logprobs = Vec::new(); |
| 2059 | |
| 2060 | for item in output { |
| 2061 | let Some(item_type) = item.get("type").and_then(Value::as_str) else { |
| 2062 | continue; |
| 2063 | }; |
| 2064 | match item_type { |
| 2065 | "reasoning" => { |
| 2066 | let id = item |
| 2067 | .get("id") |
| 2068 | .and_then(Value::as_str) |
| 2069 | .unwrap_or_default() |
| 2070 | .to_string(); |
| 2071 | let encrypted = item |
| 2072 | .get("encrypted_content") |
| 2073 | .and_then(Value::as_str) |
| 2074 | .map(ToString::to_string); |
| 2075 | let summary = item |
| 2076 | .get("summary") |
| 2077 | .and_then(Value::as_array) |
| 2078 | .map(|parts| { |
| 2079 | parts |
| 2080 | .iter() |
| 2081 | .filter_map(|p| p.get("text").and_then(Value::as_str)) |
| 2082 | .collect::<Vec<_>>() |
| 2083 | .join("\n") |
| 2084 | }) |
| 2085 | .unwrap_or_default(); |
| 2086 | |
| 2087 | let mut provider_options = HashMap::new(); |
| 2088 | if !id.is_empty() { |
| 2089 | provider_options.insert("itemId".to_string(), Value::String(id)); |
| 2090 | } |
| 2091 | if let Some(encrypted) = encrypted { |
| 2092 | provider_options |
| 2093 | .insert("encryptedContent".to_string(), Value::String(encrypted)); |
| 2094 | } |
| 2095 | |
| 2096 | parts.push(ContentPart { |
| 2097 | content_type: "reasoning".to_string(), |
| 2098 | text: Some(summary), |
| 2099 | provider_options: if provider_options.is_empty() { |
| 2100 | None |
| 2101 | } else { |
| 2102 | Some(provider_options) |
| 2103 | }, |
| 2104 | ..Default::default() |
| 2105 | }); |
| 2106 | } |
| 2107 | "message" => { |
| 2108 | for content in item |
| 2109 | .get("content") |
| 2110 | .and_then(Value::as_array) |
| 2111 | .cloned() |
| 2112 | .unwrap_or_default() |