feat(chat): 优化发货相关消息处理逻辑
- 在列出聊天消息时,过滤掉类型为'shipping-parse-review'的消息 - 移除不再使用的shippingConversationTaskIdCache - 更新发货决策处理逻辑,简化保存消息的参数 - 添加发货动作按钮刷新时的任务定位优先级逻辑 - 移除解析复核消息的展示逻辑,统一处理到轻量工作台 - 增加单元测试,验证发货动作按钮刷新时的任务定位优先级
This commit is contained in:
1 parent
9f5493185d
commit
6a0a51313f
18 files changed
+1230
-199
No files matched your search
@@ -28,7 +28,10 @@ const isShippingActionListContextLine = (line: string) =>
|
||||
/(?:请选择操作|选择操作|操作选项|下方按钮|按钮继续操作|以下.*方式|任一方式|库存上传|提供当前库存|提供.*库存数据)/.test(line);
|
||||
|
||||
const isShippingActionChoiceLine = (line: string) =>
|
||||
/(?:选择库存文件|上传库存|粘贴库存|重试\s*RPA|修改映射|确认字段|继续处理|查看卡点|返回修订|重新匹配|重试当前步骤|切换为当前任务)/i.test(line);
|
||||
/(?:选择库存文件|上传库存|粘贴库存|重试\s*RPA|修改映射|确认字段|继续处理|查看卡点|返回修订|重新匹配|重试当前步骤|切换为当前任务|确认|驳回|重新解析)/i.test(line);
|
||||
|
||||
const isPlainActionMenuLine = (line: string) =>
|
||||
/^\s*(?:[-*]\s*)?(?:\*\*)?(?:确认|驳回|重新解析|更正映射|重新匹配|继续处理|重试当前步骤|选择库存文件|上传库存|粘贴库存)(?:\*\*)?\s*(?:[-—-::]|$)/.test(line);
|
||||
|
||||
/**
|
||||
* 移除 Agent 正文里重复描述按钮的 1/2/3 编号动作列表。
|
||||
@@ -95,6 +98,39 @@ export function stripShippingRedundantNumberedActionList(text: string): string {
|
||||
.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除 Agent 正文中手写的操作菜单段落。
|
||||
*
|
||||
* 核心逻辑:结构化按钮已经由系统渲染,正文里再写“请使用下方按钮/确认/驳回/重新解析”
|
||||
* 会形成两套入口。只删除明确处在按钮/操作上下文附近的菜单行,避免误删普通业务说明。
|
||||
*/
|
||||
export function stripShippingPlainActionMenu(text: string): string {
|
||||
const lines = String(text || '').split('\n');
|
||||
const remove = new Set<number>();
|
||||
|
||||
lines.forEach((line, index) => {
|
||||
if (!isPlainActionMenuLine(line)) return;
|
||||
const nearby = lines.slice(Math.max(0, index - 4), Math.min(lines.length, index + 4));
|
||||
const hasContext = nearby.some((item) => isShippingActionListContextLine(item) || /(?:按钮|确认操作|进行确认操作|操作$)/.test(item));
|
||||
if (!hasContext) return;
|
||||
remove.add(index);
|
||||
for (let before = index - 1; before >= 0 && before >= index - 4; before -= 1) {
|
||||
const prev = lines[before] || '';
|
||||
if (!prev.trim() || isShippingActionListContextLine(prev) || /(?:按钮|确认操作|进行确认操作|操作$)/.test(prev)) {
|
||||
remove.add(before);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
return lines
|
||||
.filter((_, index) => !remove.has(index))
|
||||
.join('\n')
|
||||
.replace(/\n{3,}/g, '\n\n')
|
||||
.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据后端 action_buttons 移除 Agent 正文中重复生成的编号操作列表。
|
||||
*
|
||||
@@ -213,7 +249,7 @@ export function sanitizeShippingConversationText(text: string, enabled: boolean)
|
||||
result = result.replace(quoted, '');
|
||||
result = result.replace(new RegExp(`\`${token}\``, 'gi'), '');
|
||||
}
|
||||
return stripShippingRedundantNumberedActionList(result.replace(/\n{3,}/g, '\n\n').trim());
|
||||
return stripShippingPlainActionMenu(stripShippingRedundantNumberedActionList(result.replace(/\n{3,}/g, '\n\n').trim()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user