(raw_text: &str, errors: &[String])
| 1115 | } |
| 1116 | |
| 1117 | fn build_repair_message(raw_text: &str, errors: &[String]) -> String { |
| 1118 | // Truncate raw output in repair message to avoid blowing context |
| 1119 | let truncated_raw = if raw_text.len() > 2000 { |
| 1120 | format!( |
| 1121 | "{}...[truncated, {} bytes total]", |
| 1122 | truncate_utf8(raw_text, 2000), |
| 1123 | raw_text.len() |
| 1124 | ) |
| 1125 | } else { |
| 1126 | raw_text.to_string() |
| 1127 | }; |
| 1128 | format!( |
| 1129 | "Your previous output failed schema validation:\n\n{}\n\nValidation errors:\n{}\n\nPlease return ONLY a corrected JSON object that fixes these errors. No explanation, no markdown.", |
| 1130 | truncated_raw, |
| 1131 | errors.iter().map(|e| format!("- {}", e)).collect::<Vec<_>>().join("\n") |
| 1132 | ) |
| 1133 | } |
| 1134 | |
| 1135 | fn accumulate_usage(total: &mut TokenUsage, delta: &TokenUsage) { |
| 1136 | total.prompt_tokens += delta.prompt_tokens; |
no test coverage detected