feat(shipping-notice): 添加识别定义和规则集管理功能,支持客户和站点的可配置识别规则
This commit is contained in:
1 parent
88408490d7
commit
34d489a2d1
167 files changed
+10365
-7978
No files matched your search
@@ -174,6 +174,13 @@ const SHIPPING_ORDER_EXTRACTION_STATUSES = new Set<ShippingOrderExtractionStatus
|
||||
'failed',
|
||||
]);
|
||||
|
||||
const STREAM_ERROR_FALLBACK_SUFFIXES = [
|
||||
'请求失败,请稍后重试。',
|
||||
'請求失敗,請稍後重試。',
|
||||
'The request failed. Please try again.',
|
||||
'คำขอล้มเหลว โปรดลองใหม่อีกครั้ง',
|
||||
];
|
||||
|
||||
/**
|
||||
* 将未知 SSE payload 规范为订单识别状态。
|
||||
* 核心逻辑:只接受固定状态枚举;计数字段统一约束为非负整数,避免异常上游值破坏卡片布局。
|
||||
@@ -219,6 +226,12 @@ export const applyShippingOrderExtractionStateToMessage = (
|
||||
if (!state) return;
|
||||
if (msg.shipping_order_extraction_state?.terminal && !state.terminal) return;
|
||||
msg.shipping_order_extraction_state = state;
|
||||
if (msg.stream_error && (state.status === 'completed' || state.status === 'partially_completed')) {
|
||||
// 已持久化的订单事实优先于连接层通用断流提示,避免业务成功仍向用户误报失败。
|
||||
const fallbackSuffix = STREAM_ERROR_FALLBACK_SUFFIXES.find((suffix) => msg.content.endsWith(suffix));
|
||||
if (fallbackSuffix) msg.content = msg.content.slice(0, -fallbackSuffix.length).trimEnd();
|
||||
msg.stream_error = false;
|
||||
}
|
||||
msg.payload = {
|
||||
...(msg.payload && typeof msg.payload === 'object' ? msg.payload as Record<string, unknown> : {}),
|
||||
shipping_order_extraction_state: state,
|
||||
|
||||
Reference in new issue
Block a user