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

@@ -127,6 +127,7 @@ def _lean_parse_summary(structured: dict[str, Any] | None) -> dict[str, Any]:
if email.get('stored_body_text_length') is not None
else len(str(email.get('body_text') or ''))
),
'body_html_table_count': len(email.get('body_html_tables') or []),
}
out['email'] = lean_email
attachments = out.get('attachments')
@@ -145,6 +146,9 @@ def _lean_parse_summary(structured: dict[str, Any] | None) -> dict[str, Any]:
'text_length': item.get('text_length'),
'stored_text_length': item.get('stored_text_length'),
'warnings': list(item.get('warnings') or []),
'ready_for_extraction': bool(item.get('ready_for_extraction')),
'is_inline_resource': bool(item.get('is_inline_resource')),
'catalog_reason': item.get('catalog_reason'),
}
if item.get('asset_no'):
row['asset_no'] = item.get('asset_no')
@@ -192,6 +196,7 @@ def serialize_intake(
'intake_no': intake.intake_no,
'asset_no': asset.asset_no if asset else None,
'conversation_id': intake.conversation_id,
'upload_batch_id': intake.upload_batch_id,
'parse_status': intake.parse_status,
'parser_version': intake.parser_version,
'order_extraction_status': intake.order_extraction_status,
@@ -326,6 +331,7 @@ def create_shipping_notice_intake(
user_id: int,
asset_no: str,
conversation_id: str | None = None,
upload_batch_id: str | None = None,
) -> dict[str, Any]:
"""
基于已上传 FileAsset 创建接入记录并投递解析 Job。
@@ -339,7 +345,7 @@ def create_shipping_notice_intake(
"""
return _create_intake_for_asset(
user_id=user_id, asset_no=asset_no, purpose='shipping_notice',
conversation_id=conversation_id,
conversation_id=conversation_id, upload_batch_id=upload_batch_id,
)
@@ -352,12 +358,13 @@ def create_order_document_profile_sample_intake(*, user_id: int, asset_no: str)
"""
return _create_intake_for_asset(
user_id=user_id, asset_no=asset_no, purpose=ORDER_DOCUMENT_PROFILE_SAMPLE_PURPOSE,
conversation_id=None,
conversation_id=None, upload_batch_id=None,
)
def _create_intake_for_asset(
*, user_id: int, asset_no: str, purpose: str, conversation_id: str | None,
upload_batch_id: str | None,
) -> dict[str, Any]:
"""按受控 purpose 创建幂等 Intake;模板样本与业务发货通知共享基础设施但隔离用途。"""
asset = get_asset_for_user(asset_no, user_id)
@@ -368,6 +375,9 @@ def _create_intake_for_asset(
parser_version = _parser_version()
conv = str(conversation_id or '').strip() or None
provided_batch_id = str(upload_batch_id or '').strip()
# Workspace API 强制提供批次;服务层保留内部调用的隔离默认值。
batch_id = provided_batch_id or str(uuid.uuid4())
if purpose == ORDER_DOCUMENT_PROFILE_SAMPLE_PURPOSE:
extension = str(asset.extension or '').strip().lower()
if extension not in {'pdf', 'eml'}:
@@ -388,6 +398,7 @@ def _create_intake_for_asset(
asset_id=int(asset.id),
user_id=int(user_id),
conversation_id=conv,
upload_batch_id=batch_id or str(uuid.uuid4()),
purpose=purpose,
parse_status='created',
parser_version=parser_version,
@@ -408,6 +419,13 @@ def _create_intake_for_asset(
if intake is None:
raise
if purpose == 'shipping_notice' and provided_batch_id and intake.upload_batch_id != batch_id:
db.session.rollback()
raise ConflictError(
code='SHIPPING_NOTICE.UPLOAD_BATCH_MISMATCH',
message='Uploaded asset already belongs to another input batch',
)
# [STEP 2] 终态 / 已在飞 / 禁止复活
status_now = str(intake.parse_status or '')
if status_now in {'parsed', 'consumed', 'queued', 'parsing'}: