| 267 | for (const auto & [key, value] : options.workflow_inputs) { |
| 268 | context.values[key] = value; |
| 269 | } |
| 270 | for (auto & [_, value] : context.values) { |
| 271 | value = expand_value(value, context); |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | void run_batch_inputs_step( |
| 276 | const engine::io::json::Value & step, |
| 277 | WorkflowContext & context) { |
| 278 | const std::string id = workflow_string(step, "id"); |
| 279 | if (workflow_has_field(step, "foreach")) { |
| 280 | throw std::runtime_error("batch_inputs cannot use foreach: " + id); |
| 281 | } |
| 282 | const bool has_audio_dir = workflow_has_field(step, "audio_dir"); |
| 283 | const bool has_text_dir = workflow_has_field(step, "text_dir"); |
| 284 | if ((has_audio_dir ? 1 : 0) + (has_text_dir ? 1 : 0) != 1) { |
| 285 | throw std::runtime_error("batch_inputs requires exactly one of audio_dir or text_dir: " + id); |
| 286 | } |
| 287 | |
| 288 | std::vector<std::filesystem::path> paths; |
| 289 | std::vector<std::unordered_map<std::string, std::string>> items; |
| 290 | if (has_audio_dir) { |
| 291 | const auto dir = resolve_workflow_path(workflow_string(step, "audio_dir"), context); |
| 292 | if (!std::filesystem::is_directory(dir)) { |
| 293 | throw std::runtime_error("batch_inputs audio_dir must be an existing directory: " + dir.string()); |
| 294 | } |
| 295 | for (const auto & entry : std::filesystem::directory_iterator(dir)) { |
| 296 | if (entry.is_regular_file() && is_wav_path(entry.path())) { |
| 297 | paths.push_back(entry.path()); |
| 298 | } |
| 299 | } |
| 300 | std::sort(paths.begin(), paths.end()); |
| 301 | if (paths.empty()) { |
| 302 | throw std::runtime_error("batch_inputs audio_dir contains no .wav files: " + dir.string()); |
| 303 | } |
| 304 | items.reserve(paths.size()); |
| 305 | for (const auto & path : paths) { |
| 306 | items.push_back({ |
| 307 | {"id", safe_workflow_id(path.stem().string())}, |
| 308 | {"audio_path", path.string()}, |
| 309 | }); |
| 310 | } |
| 311 | } else { |
| 312 | const auto dir = resolve_workflow_path(workflow_string(step, "text_dir"), context); |
| 313 | if (!std::filesystem::is_directory(dir)) { |
| 314 | throw std::runtime_error("batch_inputs text_dir must be an existing directory: " + dir.string()); |
| 315 | } |
| 316 | for (const auto & entry : std::filesystem::directory_iterator(dir)) { |
| 317 | if (entry.is_regular_file() && is_text_batch_path(entry.path())) { |
| 318 | paths.push_back(entry.path()); |
| 319 | } |
| 320 | } |
| 321 | std::sort(paths.begin(), paths.end()); |
| 322 | if (paths.empty()) { |
| 323 | throw std::runtime_error("batch_inputs text_dir contains no .txt, .md, or .json files: " + dir.string()); |
| 324 | } |
| 325 | items.reserve(paths.size()); |
| 326 | for (const auto & path : paths) { |
no test coverage detected