2026-10-13 23:44:11 +08:00
|
|
|
"""审查运行的共享上下文。"""
|
|
|
|
|
|
|
|
|
|
from dataclasses import dataclass
|
|
|
|
|
|
2026-10-16 23:07:23 +08:00
|
|
|
from . import config, evidence_model
|
2026-10-13 23:44:11 +08:00
|
|
|
from .cad_tools import CadTools
|
|
|
|
|
from .checklist import load_checklist
|
|
|
|
|
from .llm_client import LlmClient
|
|
|
|
|
from .mcp_client import McpClient
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
|
class ReviewContext:
|
2026-10-16 23:07:23 +08:00
|
|
|
"""一次审查运行的共享上下文。
|
|
|
|
|
|
|
|
|
|
`connect_cad=False`(离线模式)时 `client` / `tools` 均为 `None`——供 PDF / 图片
|
|
|
|
|
等**纯离线源**使用:这些源没有 CAD 可连,全链路(取证 / 审查 / 批注)都必须
|
|
|
|
|
先判 `ctx.tools is None` 再决定是否走 CAD 工具。`source` 记录本次运行的来源类型,
|
|
|
|
|
供规划阶段分发(CAD 走 `detect_drawing_frames`,文件源自带图框)。
|
|
|
|
|
|
|
|
|
|
`source_path` 为文件源(PDF / 图片)的磁盘路径;`source_reader` 是 `sources`
|
|
|
|
|
打开的读取器(缓存,避免每页重复打开 PDF)。
|
|
|
|
|
"""
|
|
|
|
|
|
2026-10-13 23:44:11 +08:00
|
|
|
client: McpClient
|
|
|
|
|
tools: CadTools
|
|
|
|
|
llm: LlmClient
|
|
|
|
|
checklist: dict
|
2026-10-16 23:07:23 +08:00
|
|
|
source: str = evidence_model.SOURCE_CAD
|
|
|
|
|
source_path: str = None
|
|
|
|
|
source_reader: object = None
|
2026-10-13 23:44:11 +08:00
|
|
|
max_frames: int = 0
|
|
|
|
|
frame_limit: int = 200
|
|
|
|
|
max_iters: int = 4
|
|
|
|
|
annotate: bool = False
|
|
|
|
|
dry_run: bool = False
|
|
|
|
|
|
|
|
|
|
@classmethod
|
2026-10-16 23:07:23 +08:00
|
|
|
def create(cls, *, need_llm=True, connect_cad=True, source=None, source_path=None,
|
|
|
|
|
**overrides):
|
|
|
|
|
client = McpClient() if connect_cad else None
|
|
|
|
|
# CadTools.__init__ 会立刻 list_tools() 去连 127.0.0.1:8080;离线模式必须跳过。
|
|
|
|
|
tools = CadTools(client) if connect_cad else None
|
2026-10-13 23:44:11 +08:00
|
|
|
llm = LlmClient() if need_llm else None
|
|
|
|
|
checklist = load_checklist()
|
|
|
|
|
params = dict(
|
|
|
|
|
client=client,
|
|
|
|
|
tools=tools,
|
|
|
|
|
llm=llm,
|
|
|
|
|
checklist=checklist,
|
2026-10-16 23:07:23 +08:00
|
|
|
source=source or evidence_model.SOURCE_CAD,
|
|
|
|
|
source_path=source_path,
|
2026-10-13 23:44:11 +08:00
|
|
|
max_frames=config.MAX_FRAMES,
|
|
|
|
|
frame_limit=config.FRAME_ENTITY_LIMIT,
|
|
|
|
|
max_iters=config.REVIEW_MAX_ITERS,
|
|
|
|
|
)
|
|
|
|
|
params.update(overrides)
|
|
|
|
|
return cls(**params)
|