feat(shipping-notice): 添加识别定义和规则集管理功能,支持客户和站点的可配置识别规则
This commit is contained in:
1 parent
88408490d7
commit
34d489a2d1
167 files changed
+10365
-7978
No files matched your search
@@ -190,6 +190,27 @@ describe('useChat shipping_order_extraction_state SSE', () => {
|
||||
expect(isAllowedAfterStreamTerminal('agent_message')).toBe(false);
|
||||
});
|
||||
|
||||
it('clears a generic stream failure after persisted partial completion', () => {
|
||||
const message: ChatMessage = {
|
||||
role: 'assistant',
|
||||
content: '请求失败,请稍后重试。',
|
||||
stream_error: true,
|
||||
};
|
||||
|
||||
applyShippingOrderExtractionStateToMessage(message, {
|
||||
status: 'partially_completed',
|
||||
phase: 'result_persisted',
|
||||
message: '仍有 1 个订单需要补充信息',
|
||||
pending_count: 1,
|
||||
terminal: true,
|
||||
});
|
||||
|
||||
// 关键断言:已保存的订单部分完成结果不得被通用 SSE 断流提示覆盖。
|
||||
expect(message.content).toBe('');
|
||||
expect(message.stream_error).toBe(false);
|
||||
expect(message.shipping_order_extraction_state?.status).toBe('partially_completed');
|
||||
});
|
||||
|
||||
it('hydrates persisted terminal state from ChatLog payload', () => {
|
||||
const message: ChatMessage = {
|
||||
role: 'assistant',
|
||||
|
||||
@@ -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