- 移除 Agent 的 exposure_mode 与 internal_executor 相关逻辑,清理关联的过滤、序列化代码 - 删除废弃的 AgentRuntimeBinding 模型及其依赖 - 新增订单抽取上传批次、请求快照等数据库迁移与业务逻辑 - 修复附件完整性检测、订单抽取状态映射问题 - 更新多语言错误文案与前端单元测试配置 - 清理平台配置中不再使用的暴露模式配置
65 lines
2.4 KiB
TypeScript
65 lines
2.4 KiB
TypeScript
/**
|
||
* features/chat/shipping/shippingNoticeAttachmentIntegrity.ts
|
||
* 用途:发货通知附件完整性门禁契约(阻断 warning 前缀与 incomplete 判定)。
|
||
* 依赖:shipping.types(ParseSummary 形状)。
|
||
* 逻辑:与后端 attachment_integrity.BLOCKING_WARNING_PREFIXES /
|
||
* is_attachment_parse_incomplete 保持一致;契约测试校验两端前缀集合。
|
||
*/
|
||
|
||
import type { ShippingNoticeParseSummary } from '../types/shipping.types';
|
||
|
||
/** 阻断 warning 前缀;须与 backend BLOCKING_WARNING_PREFIXES 完全一致(顺序可不同)。 */
|
||
export const BLOCKING_WARNING_PREFIXES = [
|
||
'eml_nesting_depth_exceeded:',
|
||
'eml_attachment_limit_exceeded:',
|
||
'eml_total_attachment_size_exceeded:',
|
||
'eml_nested_message_unreadable',
|
||
'eml_attachment_text_budget_exhausted:',
|
||
'eml_attachment_text_truncated:',
|
||
'notice_text_truncated:',
|
||
] as const;
|
||
|
||
const INCOMPLETE_ATTACHMENT_STATUSES = new Set(['failed', 'empty', 'skipped']);
|
||
|
||
/**
|
||
* 判定单条 warning 是否为完整性阻断项。
|
||
*/
|
||
export function isBlockingWarning(text: string): boolean {
|
||
const normalized = String(text || '');
|
||
return BLOCKING_WARNING_PREFIXES.some((prefix) => normalized.startsWith(prefix));
|
||
}
|
||
|
||
/**
|
||
* 判定 EML 等 intake 是否存在未完整解析的附件(含超深/超限/截断警告)。
|
||
* 核心逻辑:阻断警告、登记数少于发现数、或 failed/empty/skipped 均视为不完整;
|
||
* duplicate 仅为去重,不阻断建单。
|
||
*/
|
||
export function isShippingNoticeAttachmentParseIncomplete(
|
||
summary?: ShippingNoticeParseSummary | null,
|
||
): boolean {
|
||
if (!summary) return false;
|
||
const previewStatus = String(summary.preview_status || '').trim().toLowerCase();
|
||
if (summary.technical_failure) {
|
||
return true;
|
||
}
|
||
if (previewStatus === 'technical_failed' || previewStatus === 'directory_incomplete') {
|
||
return true;
|
||
}
|
||
if (summary.attachment_directory_complete === false || summary.ready_for_extraction === false) {
|
||
return true;
|
||
}
|
||
const warnings = summary.warnings || [];
|
||
if (warnings.some((item) => isBlockingWarning(String(item || '')))) {
|
||
return true;
|
||
}
|
||
const rows = summary.attachments || [];
|
||
const total = Number(summary.attachment_count || 0);
|
||
if (total > rows.length) return true;
|
||
return rows.some((item) => {
|
||
if (INCOMPLETE_ATTACHMENT_STATUSES.has(String(item.parse_status || ''))) {
|
||
return true;
|
||
}
|
||
return (item.warnings || []).some((w) => isBlockingWarning(String(w || '')));
|
||
});
|
||
}
|