读取单次运行目录内的 manifest.json。 成功时返回 reportId 以及元数据字典;读取或解析失败会记录错误 并返回 (None, None),以便上层提前终止流程。 参数: run_dir: 包含 manifest.json 的章节输出目录 返回: tuple[str | None, dict | None]: (report_id, metadata)
(run_dir: Path)
| 53 | |
| 54 | |
| 55 | def load_manifest(run_dir: Path): |
| 56 | """ |
| 57 | 读取单次运行目录内的 manifest.json。 |
| 58 | |
| 59 | 成功时返回 reportId 以及元数据字典;读取或解析失败会记录错误 |
| 60 | 并返回 (None, None),以便上层提前终止流程。 |
| 61 | |
| 62 | 参数: |
| 63 | run_dir: 包含 manifest.json 的章节输出目录 |
| 64 | |
| 65 | 返回: |
| 66 | tuple[str | None, dict | None]: (report_id, metadata) |
| 67 | """ |
| 68 | manifest_path = run_dir / "manifest.json" |
| 69 | try: |
| 70 | with manifest_path.open("r", encoding="utf-8") as f: |
| 71 | manifest = json.load(f) |
| 72 | report_id = manifest.get("reportId") or run_dir.name |
| 73 | metadata = manifest.get("metadata") or {} |
| 74 | logger.info(f"报告ID: {report_id}") |
| 75 | if manifest.get("createdAt"): |
| 76 | logger.info(f"创建时间: {manifest['createdAt']}") |
| 77 | return report_id, metadata |
| 78 | except Exception as exc: |
| 79 | logger.error(f"读取manifest失败: {exc}") |
| 80 | return None, None |
| 81 | |
| 82 | |
| 83 | def load_chapters(run_dir: Path): |