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:
1 parent
eb0466245b
commit
4cd987eef6
45 files changed
+2748
-1406
No files matched your search
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* features/chat/shipping/shippingText.test.ts
|
||||
* 用途:锁定货代发货 Agent 消息净化规则,避免按钮动作列表和工程语言重新泄漏到用户界面。
|
||||
* 依赖:Vitest、shippingText 纯函数。
|
||||
* 逻辑:输入典型 Agent 回复,断言冗余 1/2/3 操作列表被移除,同时普通业务编号列表不受影响。
|
||||
*/
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { sanitizeShippingConversationText } from './shippingText';
|
||||
|
||||
describe('shippingText', () => {
|
||||
it('removes numbered action lists that duplicate structured shipping buttons', () => {
|
||||
// 关键断言:按钮已经结构化展示时,正文里的 1/2/3 操作清单不能再露给业务用户。
|
||||
const result = sanitizeShippingConversationText(
|
||||
[
|
||||
'⏳ 当前卡点 — 待上传库存',
|
||||
'',
|
||||
'目前任务已进入库存上传环节,您需要提供当前库存数据。请使用下方按钮选择以下任一方式:',
|
||||
'',
|
||||
'1. 📁 选择库存文件 — 在本对话中上传库存 Excel 文件',
|
||||
'2. 🔄 重试 RPA — 让系统重新尝试从 RPA 导出库存快照',
|
||||
'3. 📋 粘贴库存 — 直接粘贴库存小表内容',
|
||||
'',
|
||||
'请使用下方按钮继续操作。',
|
||||
].join('\n'),
|
||||
true,
|
||||
);
|
||||
|
||||
expect(result).toContain('当前卡点');
|
||||
expect(result).not.toContain('1.');
|
||||
expect(result).not.toContain('选择库存文件');
|
||||
expect(result).not.toContain('重试 RPA');
|
||||
expect(result).not.toContain('粘贴库存');
|
||||
expect(result).not.toContain('下方按钮');
|
||||
});
|
||||
|
||||
it('keeps normal numbered business lists', () => {
|
||||
// 关键断言:正常订单/业务明细仍可用编号展示,不能被动作列表规则误删。
|
||||
const result = sanitizeShippingConversationText(
|
||||
[
|
||||
'本次识别到 2 行订单:',
|
||||
'1. SKU A001,数量 10',
|
||||
'2. SKU B002,数量 5',
|
||||
].join('\n'),
|
||||
true,
|
||||
);
|
||||
|
||||
expect(result).toContain('1. SKU A001');
|
||||
expect(result).toContain('2. SKU B002');
|
||||
});
|
||||
});
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -34,6 +34,7 @@ export interface ShippingUploadHandlerContext {
|
||||
shippingInventorySchemaPreviewCache: Ref<Record<string, unknown>>;
|
||||
getActiveShippingTaskId: () => string;
|
||||
sendShippingMenuMessage: (message: string) => Promise<void>;
|
||||
pushShippingLocalUserMessage: (text: string) => Promise<void>;
|
||||
pushShippingLocalAssistantMessage: (text: string) => Promise<void>;
|
||||
refreshShippingActions: () => Promise<void>;
|
||||
msg: { warning: (text: string) => void };
|
||||
@@ -72,6 +73,7 @@ export function createShippingUploadHandlers(ctx: ShippingUploadHandlerContext)
|
||||
|
||||
const uploadInventoryForTask = async (taskId: string, file: File) => {
|
||||
ctx.resolvedShippingTaskId.value = taskId;
|
||||
await ctx.pushShippingLocalUserMessage(ctx.t('chat.shippingNoticeInventoryUploadStarted', { fileName: file.name }));
|
||||
const result = await uploadWorkspaceShippingInventory(taskId, file);
|
||||
const batchNo = String(
|
||||
((result as unknown as { data?: { batch_no?: string } }).data?.batch_no)
|
||||
|
||||
Reference in new issue
Block a user