feat(shipping-notice): 落地字段资产治理与唯一 Schema,自动建单随版本冻结
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
b7307fc573
commit
3a1dbf7ce5
144 files changed
+15167
-4480
No files matched your search
@@ -1,15 +1,14 @@
|
||||
/**
|
||||
* features/chat/shipping/useChatShippingRefresh.ts
|
||||
* 用途:刷新聊天区发货通知 UI State,把后端状态机 action_buttons 同步到消息气泡。
|
||||
* 用途:刷新聊天区发货通知 UI State,同步后端 summary/checkpoint 到消息,供通知展示。
|
||||
* 依赖:shipping.api、shippingTaskId、shippingNoticeActions 常量、chat.types。
|
||||
* 逻辑:由 useChatShipping 调用本文件;本文件只读取后端 /ui-state,不再从会话标题猜任务号或从 Dify 正文解析按钮。
|
||||
* 逻辑:由 useChatShipping 调用本文件;只读取后端 /ui-state 并净化正文中的动作菜单文案,不再把 action_buttons 映射为消息按钮。
|
||||
*/
|
||||
import { getWorkspaceShippingTaskUiState } from '@/features/chat/api/shipping.api';
|
||||
import { SHIPPING_TERMINAL_CHECKPOINTS } from '@/constants/shippingNoticeActions';
|
||||
import { findLatestShippingTaskId } from './shippingTaskId';
|
||||
import { stripShippingActionListByButtons, stripShippingPlainActionMenu } from './shippingText';
|
||||
import type { ChatMessage } from '../types/chat.types';
|
||||
import type { ShippingActionButton } from '../types/shipping.types';
|
||||
import type { ShippingTaskUiState } from '../types/shipping.api.types';
|
||||
import type { ComputedRef, Ref } from 'vue';
|
||||
|
||||
@@ -27,7 +26,7 @@ export interface ShippingRefreshContext {
|
||||
* 解析当前聊天页最可靠的发货任务编号。
|
||||
*
|
||||
* 核心逻辑:优先使用批次当前焦点任务,其次才回退到消息内嵌任务号、已解析状态和路由参数;
|
||||
* 禁止再按 conversation 标题“猜”一票,避免多票会话把动作按钮挂错任务。
|
||||
* 禁止再按 conversation 标题“猜”一票,避免多票会话把状态挂错任务。
|
||||
* @param params - 当前聊天页中可用的任务定位线索
|
||||
* @returns 可信的任务编号;无法明确定位时返回空字符串
|
||||
*/
|
||||
@@ -57,11 +56,12 @@ export function assistantMessageHasLaterUserReply(msgs: Array<{ role?: string }>
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建发货通知动作按钮刷新器。
|
||||
* 创建发货通知 UI State 刷新器。
|
||||
*
|
||||
* 核心逻辑:按 taskId 拉取后端 ui_state/action_buttons,并在终态 checkpoint 清空旧按钮。
|
||||
* 核心逻辑:按 taskId 拉取后端 ui_state,写回 `shipping_ui_state` 供摘要/通知展示,
|
||||
* 并清空消息上的 `shipping_actions`(Chat 不再渲染履约写按钮)。
|
||||
* @param ctx - 发货通知聊天上下文
|
||||
* @returns 动作刷新函数
|
||||
* @returns 状态刷新函数
|
||||
*/
|
||||
export function createShippingActionsRefresher(ctx: ShippingRefreshContext) {
|
||||
let shippingActionsRequestSeq = 0;
|
||||
@@ -128,43 +128,33 @@ export function createShippingActionsRefresher(ctx: ShippingRefreshContext) {
|
||||
return;
|
||||
}
|
||||
msgs.forEach((rawMsg, index) => {
|
||||
const chatMsg = rawMsg as ChatMessage & {
|
||||
shipping_actions_used?: boolean;
|
||||
shipping_actions?: ShippingActionButton[];
|
||||
};
|
||||
if (chatMsg.role !== 'assistant' || chatMsg.shipping_actions_used) {
|
||||
const chatMsg = rawMsg as ChatMessage;
|
||||
if (chatMsg.role !== 'assistant') {
|
||||
return;
|
||||
}
|
||||
if (chatMsg.type && !['text', undefined].includes(chatMsg.type)) {
|
||||
chatMsg.shipping_actions = undefined;
|
||||
// Chat 只保留通知态:始终清空履约按钮,仅同步最新 ui_state summary。
|
||||
chatMsg.shipping_actions = undefined;
|
||||
if (chatMsg.type && !['text', undefined, 'shipping-match-result'].includes(chatMsg.type)) {
|
||||
return;
|
||||
}
|
||||
if (assistantMessageHasLaterUserReply(msgs, index) && index !== targetAssistantIndex) {
|
||||
chatMsg.shipping_actions = undefined;
|
||||
return;
|
||||
}
|
||||
let buttons: ShippingActionButton[] = [];
|
||||
let cleanedText = stripShippingPlainActionMenu(String(chatMsg.content || ''));
|
||||
if (index === targetAssistantIndex) {
|
||||
if (apiState?.action_buttons?.length) {
|
||||
buttons = apiState.action_buttons;
|
||||
chatMsg.shipping_ui_state = apiState;
|
||||
} else if (!apiResolved && chatMsg.shipping_ui_state?.action_buttons?.length) {
|
||||
buttons = chatMsg.shipping_ui_state.action_buttons;
|
||||
if (index === targetAssistantIndex && apiState) {
|
||||
chatMsg.shipping_ui_state = apiState;
|
||||
if (apiState.action_buttons?.length) {
|
||||
cleanedText = stripShippingActionListByButtons(cleanedText, apiState.action_buttons);
|
||||
}
|
||||
if (buttons.length) {
|
||||
cleanedText = stripShippingActionListByButtons(cleanedText, buttons);
|
||||
}
|
||||
} else {
|
||||
cleanedText = stripShippingPlainActionMenu(String(chatMsg.content || ''));
|
||||
} else if (!apiResolved && chatMsg.shipping_ui_state?.action_buttons?.length) {
|
||||
cleanedText = stripShippingActionListByButtons(
|
||||
cleanedText,
|
||||
chatMsg.shipping_ui_state.action_buttons,
|
||||
);
|
||||
}
|
||||
if (cleanedText !== String(chatMsg.content || '').trim()) {
|
||||
chatMsg.content = cleanedText;
|
||||
}
|
||||
if (chatMsg.type === 'shipping-match-result' && chatMsg.payload && typeof chatMsg.payload === 'object') {
|
||||
(chatMsg.payload as { action_buttons?: ShippingActionButton[] }).action_buttons = buttons;
|
||||
(chatMsg.payload as { action_buttons?: unknown[] }).action_buttons = [];
|
||||
}
|
||||
chatMsg.shipping_actions = buttons.length ? buttons : undefined;
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user