| 456 | # --------------------------------------------------------------------------- |
| 457 | |
| 458 | def _resolve_prompt(cfg: dict[str, Any], key: str, *, required: bool) -> str | None: |
| 459 | inline = cfg.get(key) |
| 460 | file_key = f"{key}_file" |
| 461 | file_path = cfg.get(file_key) |
| 462 | if inline is not None and file_path is not None: |
| 463 | raise ValueError(f"Provide only one of {key!r} or {file_key!r}, not both.") |
| 464 | if file_path is not None: |
| 465 | return Path(file_path).read_text(encoding="utf-8") |
| 466 | if inline is not None: |
| 467 | return inline |
| 468 | if required: |
| 469 | raise ValueError(f"Missing required prompt: {key} (or {file_key}).") |
| 470 | return None |
| 471 | |
| 472 | |
| 473 | def _load_config(config_arg: str) -> dict[str, Any]: |