| 200 | normalized.push_back(' '); |
| 201 | in_space = false; |
| 202 | } |
| 203 | normalized.push_back(static_cast<char>(ch)); |
| 204 | } |
| 205 | return normalized; |
| 206 | } |
| 207 | |
| 208 | std::string read_batch_text_payload(const std::filesystem::path & path) { |
| 209 | const auto ext = lowercase_extension(path); |
| 210 | if (ext == ".txt" || ext == ".md") { |
| 211 | return normalize_text_as_paragraph(read_text_file(path)); |
| 212 | } |
| 213 | if (ext == ".json") { |
| 214 | const auto root = engine::io::json::parse_file(path); |
| 215 | if (root.is_string()) { |
| 216 | return normalize_text_as_paragraph(root.as_string()); |
| 217 | } |
| 218 | if (root.is_object()) { |
| 219 | if (const auto * input = root.find("input"); input != nullptr && input->is_string()) { |
| 220 | return normalize_text_as_paragraph(input->as_string()); |
| 221 | } |
| 222 | if (const auto * text = root.find("text"); text != nullptr && text->is_string()) { |
| 223 | return normalize_text_as_paragraph(text->as_string()); |
| 224 | } |
| 225 | } |
| 226 | throw std::runtime_error("workflow batch JSON text file requires a string root, input, or text: " + path.string()); |
no test coverage detected