refactor(agent, shipping): 简化代理模型并完善订单抽取业务

- 移除 Agent 的 exposure_mode 与 internal_executor 相关逻辑,清理关联的过滤、序列化代码
- 删除废弃的 AgentRuntimeBinding 模型及其依赖
- 新增订单抽取上传批次、请求快照等数据库迁移与业务逻辑
- 修复附件完整性检测、订单抽取状态映射问题
- 更新多语言错误文案与前端单元测试配置
- 清理平台配置中不再使用的暴露模式配置
This commit is contained in:
hugo committed 2026-07-28 20:25:48 +08:00
1 parent 1f3ecb87b7
commit 61ac6403c4
159 files changed
+12883 -5099

No files matched your search

@@ -258,8 +258,26 @@ def reconstruct_coordinate_profile_rows(
for item in (exclusion_regions or []) if isinstance(item, dict)
]
if exclusions:
# Footer, signature and tax blocks are not candidate physical rows at all.
glyphs = [item for item in glyphs if not any(_inside_region(item[1].bbox, region) for region in exclusions)]
# Footer, signature and tax blocks are not candidate rows. Keep an explicit
# deletion marker from an exclusion region, however: it controls the prior
# detail row and must not be discarded before row reconstruction sees it.
deletion_marker_indices = {
glyph_index
for band in _group_visual_rows(glyphs)
if _DELETED_PATTERN.fullmatch(re.sub(
r'\s+', '', ''.join(glyph.text for _, glyph in sorted(band, key=lambda item: item[1].bbox.x0)),
))
and any(
any(_inside_region(glyph.bbox, region) for region in exclusions)
for glyph_index, glyph in band
)
for glyph_index, _glyph in band
}
glyphs = [
item for item in glyphs
if item[0] in deletion_marker_indices
or not any(_inside_region(item[1].bbox, region) for region in exclusions)
]
if not glyphs:
return []
@@ -11,7 +11,10 @@ from __future__ import annotations
from dataclasses import dataclass
from typing import Any
import cv2
try:
import cv2 # type: ignore
except ModuleNotFoundError:
cv2 = None
import numpy as np
from pydantic import BaseModel, ConfigDict, Field, model_validator
@@ -109,6 +112,8 @@ def reconstruct_opencv_table_geometry(
Returns:
ready 时包含所有 HTML 原始 cell 的页面 bbox;失败时仅包含问题码。
"""
if cv2 is None:
return _not_ready(grid, 'opencv_unavailable')
if min_consensus < 2 or len(configs) < min_consensus:
raise ValueError('OpenCV grid reconstruction requires at least two configurations')
image = _grayscale_page(page_image)
@@ -48,7 +48,8 @@ def match_frozen_coordinate_profiles(*, profiles: list[dict[str, Any]], layout:
pages = evidence.get('pages') if isinstance(evidence.get('pages'), dict) else {}
glyph_tables = evidence.get('tables') if isinstance(evidence.get('tables'), dict) else {}
page_glyphs = evidence.get('page_glyphs') if isinstance(evidence.get('page_glyphs'), dict) else {}
if not tables or not pages or not glyph_tables:
# v2 模板按页面坐标区域取证;表格检测只能辅助,不能成为续页区域的硬前提。
if not pages or (not glyph_tables and not page_glyphs):
return ProfileMatchResult(status='evidence_insufficient')
candidates: list[tuple[dict[str, Any], OrderCoordinateProfileV2, ProfileMatchCandidate]] = []
@@ -65,8 +66,6 @@ def match_frozen_coordinate_profiles(*, profiles: list[dict[str, Any]], layout:
except (TypeError, ValueError):
continue
reason_codes: list[str] = []
if len(tables) < len(profile.table_regions):
reason_codes.append('table_region_count_insufficient')
required = profile.document_match.required_anchors
required_hits = [_anchor_present(
anchor.model_dump(), tables=tables, glyph_tables=glyph_tables, page_glyphs=page_glyphs, pages=pages,
@@ -114,6 +113,8 @@ def _anchor_present(
if not expected or not all(candidates):
return False
page_numbers = sorted({str(item.get('page_no') or '') for item in tables if item.get('page_no')})
if not page_numbers:
page_numbers = sorted(str(page_no) for page_no in pages)
for page_no in page_numbers:
glyphs = page_glyphs.get(page_no)
# v1 frozen snapshots do not have page glyphs. Preserve historical matching