refactor(chat/shipping): 重构发货通知模块为统一UI State驱动模式

- 重构发货通知的状态与动作获取逻辑:移除从聊天文本解析HXOPS_SHIPPING_ACTIONS注释的旧逻辑,改为统一从后端shipping_ui_state获取任务状态、动作按钮与工作流步骤
- 新增SSE实时推送shipping_ui_state事件,支持前端即时更新聊天气泡与工作台的状态与按钮
- 优化路由与登录流程:调整根路径重定向逻辑,退出登录时跳转到登录页;移除chat路由不必要的props传参;将原路由守卫中的根路径判断迁移到路由配置中
- 完善库存RPA与本地导入流程:新增本地库存文件托管接口,优化RPA回调的文件落盘与任务关联逻辑
- 新增多组单元测试覆盖焦点切换、决策处理、SSE同步等核心场景
- 修复多语言显示逻辑,使用te方法判断翻译key是否存在,避免缺失翻译时的渲染异常
- 新增reparse_inventory菜单动作,支持静默重新解析库存且不追加额外聊天消息
- 重构工作流步骤渲染函数,优先使用后端返回的步骤数据, fallback到本地推导的旧逻辑
- 清理后端旧的chat-actions API接口,将相关逻辑迁移到统一的ui_state接口中
This commit is contained in:
hugo committed 2026-07-02 01:55:19 +08:00
commit 9c036c825b
39 files changed
+3114 -456

No files matched your search

@@ -1,11 +1,11 @@
/**
* features/chat/shipping/shippingText.ts
* 用途:发货聊天消息文本净化与 HTML 动作指令解析(纯函数,无 Vue 依赖)。
* 用途:发货聊天消息文本净化(纯函数,无 Vue 依赖)。
* 依赖:constants/shippingNoticeActions、types/shipping.types。
* 逻辑:ChatView 渲染前 sanitize;shippingMenu 解析 <!-- HXOPS_SHIPPING_ACTIONS --> 注释块。
* 逻辑:ChatView 渲染前 sanitize;动作按钮统一来自后端 shipping_ui_state。
*/
import { SHIPPING_INTERNAL_STATUS_TOKENS, SHIPPING_KNOWN_ACTION_ID_SET } from '@/constants/shippingNoticeActions';
import type { ShippingActionButton, ShippingActionVariant } from '../types/shipping.types';
import { SHIPPING_INTERNAL_STATUS_TOKENS } from '@/constants/shippingNoticeActions';
import type { ShippingActionButton } from '../types/shipping.types';
/**
* 文本归一化用于判断 Agent 正文编号项是否重复描述了结构化按钮。
@@ -249,49 +249,16 @@ export function sanitizeShippingConversationText(text: string, enabled: boolean)
result = result.replace(quoted, '');
result = result.replace(new RegExp(`\`${token}\``, 'gi'), '');
}
return stripShippingPlainActionMenu(stripShippingRedundantNumberedActionList(result.replace(/\n{3,}/g, '\n\n').trim()));
return stripShippingPlainActionMenu(stripShippingRedundantNumberedActionList(stripShippingActionsDirectiveComment(result).replace(/\n{3,}/g, '\n\n').trim()));
}
/**
* 解析消息中的 HXOPS_SHIPPING_ACTIONS HTML 注释,提取 action_buttons 并返回净化后文本。
* 移除历史 HXOPS_SHIPPING_ACTIONS HTML 注释。
*
* 按钮已经切换为后端状态机 shipping_ui_state,正文注释只作为脏文本清理,不再产生 action_buttons。
*/
export function extractShippingActionsDirective(rawText: string): {
cleanedText: string;
buttons: ShippingActionButton[];
} {
const text = String(rawText || '');
const re = /<!--\s*HXOPS_SHIPPING_ACTIONS\s*:\s*([\s\S]*?)\s*-->/gi;
const buttons: ShippingActionButton[] = [];
for (;;) {
const m = re.exec(text);
if (!m) break;
const body = String(m[1] || '').trim();
if (!body) continue;
try {
const parsed = JSON.parse(body);
if (Array.isArray(parsed)) {
for (const item of parsed) {
if (!item || typeof item !== 'object') continue;
const id = String((item as Record<string, unknown>).id || '').trim();
const label = String((item as Record<string, unknown>).label || '').trim();
const message = String((item as Record<string, unknown>).message || '').trim();
const variantRaw = String((item as Record<string, unknown>).variant || '').trim();
const variant: ShippingActionVariant | undefined = (variantRaw === 'primary' || variantRaw === 'secondary' || variantRaw === 'danger')
? (variantRaw as ShippingActionVariant)
: undefined;
if (!id || !label || !message) continue;
if (!SHIPPING_KNOWN_ACTION_ID_SET.has(id)) {
console.warn(`[shipping] unknown action id in HXOPS_SHIPPING_ACTIONS: ${id}`);
}
buttons.push({ id, label, message, variant });
}
}
} catch {
// ignore malformed directive
}
}
const cleaned = text.replace(re, '').trim();
return { cleanedText: cleaned, buttons };
export function stripShippingActionsDirectiveComment(rawText: string): string {
return String(rawText || '').replace(/<!--\s*HXOPS_SHIPPING_ACTIONS\s*:\s*[\s\S]*?\s*-->/gi, '').trim();
}
/**