feat: restore source parity and harden agent runtime

This commit is contained in:
2026-06-22 11:17:26 +08:00
parent e33f08277b
commit 0793eb82d6
596 changed files with 168879 additions and 290 deletions
@@ -0,0 +1,43 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""预览/导出非功能性护栏(阶段 G"""
from __future__ import annotations
from typing import Any, Dict, List
# 与 dataset_bridge.fetch_all max_rows 对齐
DEFAULT_MAX_DATASET_ROWS = 50000
WARN_DATASET_ROWS = 10000
WARN_SNAPSHOT_CELL_COUNT = 200_000
def estimate_snapshot_cell_count(snapshot: Dict[str, Any]) -> int:
total = 0
for sheet in (snapshot.get("sheets") or {}).values():
if not isinstance(sheet, dict):
continue
for row in (sheet.get("cellData") or {}).values():
if isinstance(row, dict):
total += len(row)
return total
def collect_preview_warnings(
*,
datasets: Dict[str, List[Any]],
snapshot: Dict[str, Any],
max_rows: int = DEFAULT_MAX_DATASET_ROWS,
warn_rows: int = WARN_DATASET_ROWS,
) -> List[str]:
"""返回 warning 码列表,供前端 i18n 映射。"""
warnings: List[str] = []
for alias, rows in (datasets or {}).items():
count = len(rows) if isinstance(rows, list) else 0
if count >= max_rows:
warnings.append(f"dataset_row_limit:{alias}")
elif count >= warn_rows:
warnings.append(f"dataset_row_warn:{alias}")
cell_count = estimate_snapshot_cell_count(snapshot or {})
if cell_count >= WARN_SNAPSHOT_CELL_COUNT:
warnings.append("snapshot_large")
return warnings