feat(queue): 添加旧知识库任务入队兼容入口

- 增加 enqueue_kb_job 和 enqueue_clean_job 函数以支持旧 KB 清洗任务入队
- 在 enqueue 函数中处理 KB_CLEAN 和 KB_DIFY_SYNC 类型的任务
- 引入 ValidationError 以处理 job_id 缺失的情况

feat(shipping_notice): 更新库存 RPA 工作流逻辑
- 修改 ensure_inventory_via_rpa 函数以支持手动重试逻辑
- 优化库存导出触发和状态更新的消息提示

fix(i18n): 更新任务未找到的提示信息
- 修改中文和英文提示,明确用户操作要求

feat(shipping_notice): 增强任务解析逻辑
- 添加缺失 Reservation ID 的检查,阻止任务进入确认阶段
- 更新 get_task_status 函数以处理多票会话的任务解析
This commit is contained in:
hugo committed 2026-06-30 21:00:25 +08:00
1 parent eb0466245b
commit 4cd987eef6
45 files changed
+2748 -1406

No files matched your search

@@ -24,6 +24,77 @@ const isActionListContextLine = (line: string) =>
const isActionListTailLine = (line: string) =>
/(?:选择哪|希望.*(?:处理|执行|操作)|要.*哪一项|点击.*按钮)/.test(line);
const isShippingActionListContextLine = (line: string) =>
/(?:请选择操作|选择操作|操作选项|下方按钮|按钮继续操作|以下.*方式|任一方式|库存上传|提供当前库存|提供.*库存数据)/.test(line);
const isShippingActionChoiceLine = (line: string) =>
/(?:选择库存文件|上传库存|粘贴库存|重试\s*RPA|修改映射|确认字段|继续处理|查看卡点|返回修订|重新匹配|重试当前步骤|切换为当前任务)/i.test(line);
/**
* 移除 Agent 正文里重复描述按钮的 1/2/3 编号动作列表。
*
* 这些动作已经由结构化按钮承载,正文再展示会显得像提示词/后端兜底泄漏。
* 为避免误删订单行,只在“按钮/库存/操作方式”上下文中,且编号行命中动作词时移除。
*/
export function stripShippingRedundantNumberedActionList(text: string): string {
const lines = String(text || '').split('\n');
const remove = new Set<number>();
for (let index = 0; index < lines.length; index += 1) {
if (!isNumberedActionLine(lines[index] || '')) continue;
const block: number[] = [];
let cursor = index;
while (cursor < lines.length && isNumberedActionLine(lines[cursor] || '')) {
block.push(cursor);
cursor += 1;
}
const actionLineCount = block.filter((lineIndex) => isShippingActionChoiceLine(lines[lineIndex] || '')).length;
if (block.length < 2 || actionLineCount === 0) {
index = cursor - 1;
continue;
}
const nearbyStart = Math.max(0, index - 3);
const nearbyEnd = Math.min(lines.length - 1, cursor + 2);
const hasActionContext = lines
.slice(nearbyStart, nearbyEnd + 1)
.some((line) => isShippingActionListContextLine(line));
if (!hasActionContext) {
index = cursor - 1;
continue;
}
block.forEach((lineIndex) => remove.add(lineIndex));
for (let before = index - 1; before >= nearbyStart; before -= 1) {
const line = lines[before] || '';
if (!line.trim() || isShippingActionListContextLine(line)) {
remove.add(before);
continue;
}
break;
}
for (let after = cursor; after <= nearbyEnd; after += 1) {
const line = lines[after] || '';
if (!line.trim() || isShippingActionListContextLine(line)) {
remove.add(after);
continue;
}
break;
}
index = cursor - 1;
}
return lines
.filter((_, index) => !remove.has(index))
.join('\n')
.replace(/\n{3,}/g, '\n\n')
.trim();
}
/**
* 根据后端 action_buttons 移除 Agent 正文中重复生成的编号操作列表。
*
@@ -80,11 +151,11 @@ export function stripShippingActionListByButtons(
}
}
return lines
return stripShippingRedundantNumberedActionList(lines
.filter((_, index) => !remove.has(index))
.join('\n')
.replace(/\n{3,}/g, '\n\n')
.trim();
.trim());
}
/**
@@ -93,6 +164,18 @@ export function stripShippingActionListByButtons(
export function sanitizeShippingConversationText(text: string, enabled: boolean): string {
if (!enabled) return text;
let result = String(text || '')
.replace(
/已回到列映射步骤。?请根据\s*schema_preview\s*提供新的\s*map_json\s*[,,]\s*再调用\s*(?:应用库存字段映射|apply_inventory_mapping)[^。.\n]*[。.]?/gi,
'已回到库存字段确认步骤。请检查系统识别的库存列名,确认无误后继续;如有问题请修改映射。',
)
.replace(
/请根据\s*schema_preview\s*提供新的\s*map_json\s*[,,]\s*再调用\s*(?:应用库存字段映射|apply_inventory_mapping)[^。.\n]*[。.]?/gi,
'请检查系统识别的库存列名,确认无误后继续;如有问题请修改映射。',
)
.replace(
/根据\s*data\.schema_preview\.headers\s*与\s*sample_rows\s*推断\s*JSON[^。.\n]*再调用\s*(?:应用库存字段映射|apply_inventory_mapping)[^。.\n]*[。.]?/gi,
'请根据库存表头和样例行确认字段对应关系。',
)
.replace(/通过\s*(?:Hxops|HXOPS|hxops)\s*聊天区上传/gi, '在当前对话中上传')
.replace(/在\s*(?:Hxops|HXOPS|hxops)\s*聊天区上传/gi, '在当前对话中上传')
.replace(/(?:Hxops|HXOPS|hxops)\s*聊天区/gi, '当前对话')
@@ -112,6 +195,10 @@ export function sanitizeShippingConversationText(text: string, enabled: boolean)
.replace(/\bupload_to_freight\b/gi, '上传货代系统')
.replace(/\bapply_inventory_mapping\b/gi, '应用库存字段映射')
.replace(/\bget_inventory_schema_preview\b/gi, '读取库存表头预览')
.replace(/\bschema_preview(?:\.headers)?\b/gi, '库存表头预览')
.replace(/\bdata\.库存表头预览\b/gi, '库存表头预览')
.replace(/\bmap_json\b/gi, '字段映射')
.replace(/\bsample_rows\b/gi, '样例行')
.replace(/\bretry_rpa\b/gi, '重试库存抓取')
.replace(/\bretry_upload\b/gi, '重试上传货代')
.replace(/\bstructured\b/gi, '结构化内容')
@@ -126,7 +213,7 @@ export function sanitizeShippingConversationText(text: string, enabled: boolean)
result = result.replace(quoted, '');
result = result.replace(new RegExp(`\`${token}\``, 'gi'), '');
}
return result.replace(/\n{3,}/g, '\n\n').trim();
return stripShippingRedundantNumberedActionList(result.replace(/\n{3,}/g, '\n\n').trim());
}
/**