feat(shipping-notice): 添加识别定义和规则集管理功能,支持客户和站点的可配置识别规则

This commit is contained in:
hugo committed 2026-07-20 19:28:17 +08:00
1 parent 88408490d7
commit 34d489a2d1
167 files changed
+10365 -7978

No files matched your search

@@ -260,7 +260,7 @@ export function sanitizeShippingConversationText(text: string, enabled: boolean)
result = result
.replace(/\bcreate_task\b/gi, '新建任务')
.replace(/\bget_task_status\b/gi, '查询任务状态')
.replace(/\bparse_notice\b/gi, '解析发货通知')
.replace(/\bsubmit_order_extraction\b/gi, '提交订单抽取')
.replace(/\bsubmit_decision\b/gi, '提交处理结果')
.replace(/\bmatch_inventory\b/gi, '匹配库存')
.replace(/\bgenerate_excel\b/gi, '生成发货 Excel')
@@ -2,7 +2,7 @@
* features/chat/shipping/shippingUploadPrompt.ts
* 用途:通知上传后提示语构建、文件格式识别与临时库存声明判断。
* 依赖:无;useChatShippingUploadHandler 在上传成功后调用。
* 逻辑:按 checkpoint 生成不同 follow-up 提示;通知建批后触发 Dify LLM 解析续办。
* 逻辑:按 checkpoint 生成不同 follow-up 提示;通知建批后触发 Dify 完整动态订单抽取。
*/
import i18n from '@/i18n';
@@ -10,7 +10,7 @@ import i18n from '@/i18n';
* 根据上传 API 响应 checkpoint 生成发给 Agent 的 follow-up 提示语。
*/
/**
* 根据通知建批 API 响应生成发给 Dify 的 follow-up 提示语(触发画布 LLM 抽取 + parse_notice)。
* 根据通知建批 API 响应生成发给 Dify 的 follow-up 提示语(触发完整订单抽取链)。
*/
export function buildShippingNoticeUploadPrompt(
result: Record<string, unknown> | null | undefined,
@@ -43,13 +43,16 @@ describe('shipping notice order extraction state', () => {
expect(resolveShippingOrderExtractionStatus(undefined, 'not_started')).toBe('not_started');
});
it('restores only in-progress and retryable parsing attachments into the input area', () => {
it('restores in-progress, retryable, and pending-candidate attachments into the input area', () => {
expect(shouldRestoreShippingNoticeIntake('queued')).toBe(true);
expect(shouldRestoreShippingNoticeIntake('parsing')).toBe(true);
expect(shouldRestoreShippingNoticeIntake('parse_failed')).toBe(true);
expect(shouldRestoreShippingNoticeIntake('parsed', 'partially_completed', 2)).toBe(true);
// Parsed files are already persisted in the user message bubble.
// 已完成且没有待审核 Candidate 的文件仅保留在用户消息气泡中。
expect(shouldRestoreShippingNoticeIntake('parsed')).toBe(false);
expect(shouldRestoreShippingNoticeIntake('parsed', 'partially_completed', 0)).toBe(false);
expect(shouldRestoreShippingNoticeIntake('parsed', 'completed', 2)).toBe(false);
expect(shouldRestoreShippingNoticeIntake('consumed')).toBe(false);
});
});
@@ -37,13 +37,23 @@ const ACTIVE_ORDER_EXTRACTION = new Set(['extracting']);
/**
* 判断服务端 Intake 是否应恢复到输入栏。
* AI 触发时机:无;页面刷新或重新打开会话时调用。
* 已解析文件已作为用户消息附件固化在对话气泡中,不能再次显示在输入栏;仅恢复仍在处理中的文件和可手动重试的解析失败文件。
* @param parseStatus - 服务端返回的预解析状态
* 已解析文件已作为用户消息附件固化在对话气泡中,不能再次显示在输入栏;但存在待审核
* Candidate 的部分完成 Intake 必须恢复,否则用户无法补充字段并继续建单。
* @param parseStatus - 服务端返回的预解析状态。
* @param orderExtractionStatus - 服务端返回的订单抽取状态。
* @param candidateCount - 当前仍可审核的订单 Candidate 数量。
* @returns 是否恢复为待发送附件卡片
*/
export function shouldRestoreShippingNoticeIntake(parseStatus: string | null | undefined): boolean {
export function shouldRestoreShippingNoticeIntake(
parseStatus: string | null | undefined,
orderExtractionStatus?: string | null,
candidateCount = 0,
): boolean {
const status = String(parseStatus || '').trim().toLowerCase();
return ACTIVE_PARSE.has(status) || status === 'parse_failed';
const extractionStatus = String(orderExtractionStatus || '').trim().toLowerCase();
return ACTIVE_PARSE.has(status)
|| status === 'parse_failed'
|| (extractionStatus === 'partially_completed' && candidateCount > 0);
}
/** 判断 Intake 是否仍需轮询上传预处理或订单抽取状态。 */
@@ -437,7 +447,11 @@ export function useShippingNoticeIntakes(options: UseShippingNoticeIntakesOption
const restoreForConversation = async (conversationId?: string | null) => {
const { items } = await listActiveShippingNoticeIntakes(conversationId);
const restored: ShippingNoticePendingAttachment[] = items
.filter((item) => shouldRestoreShippingNoticeIntake(item.parse_status))
.filter((item) => shouldRestoreShippingNoticeIntake(
item.parse_status,
item.order_extraction_status,
item.candidates?.length || 0,
))
.map((item) => ({
id: `restored_${item.intake_no}`,
kind: 'shipping_notice' as const,