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
@@ -2,8 +2,8 @@
|
||||
* features/chat/composables/useChatShipping.ts
|
||||
* 用途:发货通知聊天编排入口,组合 shipping/* 子模块并对 ChatView 暴露统一交互能力。
|
||||
* 依赖:shipping.api、shipping/ 下各 handler 工厂、chat.deps、chat.types、Vue refs/computed/watch。
|
||||
* 逻辑:上游由 ChatView/ChatPage 调用本 composable;本文件再把任务状态、动作刷新、文件上传、决策与发送拦截分发给 shipping 子模块。
|
||||
* 批次「重试所有失败」成功后不弹居中 msg.success,由页面级 toast 展示 started/skipped。
|
||||
* 逻辑:上游由 ChatView/ChatPage 调用本 composable;本文件维护会话任务摘要 + ui_state 同步,
|
||||
* 不再管理批次抽屉/焦点条/聊天履约写按钮(履约写改由任务处理工作台承接)。
|
||||
*/
|
||||
|
||||
import {
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
type Ref,
|
||||
} from 'vue';
|
||||
import { useAuthStore } from '@/features/auth/stores/auth.store';
|
||||
import { agentUsesWorkspaceStepperProgress, isShippingNoticeAgent as resolveShippingNoticeAgent } from '@/shared/utils/agent-registry.utils';
|
||||
import { isShippingNoticeAgent as resolveShippingNoticeAgent } from '@/shared/utils/agent-registry.utils';
|
||||
import type { AgentRegistryFields } from '@/shared/utils/agent-registry.utils';
|
||||
import { hasActiveRunningChatRun } from '../shipping/shippingActionBusy';
|
||||
|
||||
@@ -34,9 +34,7 @@ import {
|
||||
getShippingMatchResultPayload,
|
||||
getShippingParseReviewPayload,
|
||||
sanitizeShippingConversationText,
|
||||
shippingActionButtonClass,
|
||||
} from '../shipping';
|
||||
import { reportShippingDebugEvent } from '../shipping/shippingDebugReporter';
|
||||
import { isShippingSpreadsheetFile } from '../shipping/shippingUploadPrompt';
|
||||
import { extractExt } from '../constants/shipping';
|
||||
import {
|
||||
@@ -45,7 +43,6 @@ import {
|
||||
getWorkspaceShippingTask,
|
||||
listWorkspaceShippingCustomerOptions,
|
||||
confirmWorkspaceShippingCustomer,
|
||||
switchWorkspaceShippingBatchFocusTask,
|
||||
type ShippingBatchUiState,
|
||||
type ShippingBatchSummary,
|
||||
type ShippingConversationWorkspace,
|
||||
@@ -62,7 +59,7 @@ import {
|
||||
import type { ChatMessage, ChatRun, ChatSessionItem, ShippingMessageRecoveryPayload } from '../types/chat.types';
|
||||
import type { SendMessageLifecycleHooks } from './useChat';
|
||||
import type { ChatMessageSendResult } from '../types/chat-turn.types';
|
||||
import type { ChatUploadFileSpec, PendingAttachment, ShippingActionButton } from '../types/shipping.types';
|
||||
import type { ChatUploadFileSpec, PendingAttachment } from '../types/shipping.types';
|
||||
import type { ChatDeps } from './chat.deps';
|
||||
import { listChatMessages } from '../api/chat.api';
|
||||
|
||||
@@ -269,7 +266,6 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
|
||||
// ── 功能开关与 UI refs ────────────────────────────────────
|
||||
const isShippingNoticeAgent = computed(() => resolveShippingNoticeAgent(currentAgent.value));
|
||||
const showShippingProgressWorkspace = computed(() => agentUsesWorkspaceStepperProgress(currentAgent.value));
|
||||
const isShippingActionBusy = computed(() => {
|
||||
if (shippingActionBusy.value) return true;
|
||||
return hasActiveRunningChatRun(isThinking.value, activeRunId.value, runs.value);
|
||||
@@ -290,7 +286,7 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
return sanitizeShippingConversationText(stripReasoningPrelude(text), isShippingNoticeAgent.value);
|
||||
};
|
||||
|
||||
// ── 任务编号状态 ──────────────────────────────────────────
|
||||
// ── 任务编号状态(会话摘要同步,无抽屉/焦点条) ──────────────
|
||||
const shippingTaskIdFromQuery = computed(() => {
|
||||
const value = route.query.task_id;
|
||||
return typeof value === 'string' ? value.trim() : '';
|
||||
@@ -302,23 +298,14 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
const resolvedShippingTaskId = ref('');
|
||||
const resolvedShippingBatchNo = ref('');
|
||||
const activeShippingBatchNo = ref('');
|
||||
const focusedShippingTaskNo = ref('');
|
||||
const shippingConversationWorkspace = ref<ShippingConversationWorkspace | null>(null);
|
||||
const shippingBatchSummary = ref<ShippingBatchSummary | null>(null);
|
||||
const shippingBatchTasks = ref<ShippingTaskSummary[]>([]);
|
||||
const shippingWorkspaceOpen = ref(false);
|
||||
const retryingShippingPendingTasks = ref(false);
|
||||
const activeShippingTaskDetail = ref<ShippingTaskDetail | null>(null);
|
||||
const shippingFocusReason = ref('');
|
||||
const autoResumedShippingTasks = ref<Record<string, boolean>>({});
|
||||
const lastConversationSyncKey = ref('');
|
||||
let shippingStatusPollTimer: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
// #region debug-point B:shipping-retry-chain
|
||||
const reportRetryRpaDebug = (hypothesisId: string, msg: string, data: Record<string, unknown>) =>
|
||||
reportShippingDebugEvent('useChatShipping.ts', hypothesisId, msg, data);
|
||||
// #endregion
|
||||
|
||||
const applyShippingBatchDetail = (
|
||||
detail: ShippingBatchUiState,
|
||||
fallbackBatchNo: string,
|
||||
@@ -469,10 +456,6 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
}
|
||||
if (taskNo) {
|
||||
resolvedShippingTaskId.value = taskNo;
|
||||
focusedShippingTaskNo.value = taskNo;
|
||||
if (!shippingFocusReason.value) {
|
||||
shippingFocusReason.value = t('chat.shippingNoticeUi.currentFocusDefaultReason');
|
||||
}
|
||||
}
|
||||
if (payload.shipping_ui_state && taskNo) {
|
||||
activeShippingTaskDetail.value = {
|
||||
@@ -520,56 +503,11 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
applyResolvedShippingMessageRecovery(resolveShippingMessageRecoveryPayload(message))
|
||||
);
|
||||
|
||||
const switchShippingFocusTask = async (taskNo: string) => {
|
||||
const batchNo = getActiveShippingBatchNo();
|
||||
const normalizedTaskNo = String(taskNo || '').trim().toUpperCase();
|
||||
// #region debug-point C:switch-focus-entry
|
||||
void reportRetryRpaDebug('C', 'switchShippingFocusTask entry', {
|
||||
batchNo,
|
||||
normalizedTaskNo,
|
||||
activeBatchNo: activeShippingBatchNo.value,
|
||||
resolvedBatchNo: resolvedShippingBatchNo.value,
|
||||
routeBatchNo: shippingBatchNoFromQuery.value,
|
||||
});
|
||||
// #endregion
|
||||
if (!batchNo || !normalizedTaskNo) {
|
||||
// #region debug-point C:switch-focus-guard
|
||||
void reportRetryRpaDebug('C', 'switchShippingFocusTask guard returned false', {
|
||||
batchNo,
|
||||
normalizedTaskNo,
|
||||
});
|
||||
// #endregion
|
||||
return false;
|
||||
}
|
||||
await switchWorkspaceShippingBatchFocusTask(batchNo, normalizedTaskNo);
|
||||
resolvedShippingTaskId.value = normalizedTaskNo;
|
||||
focusedShippingTaskNo.value = normalizedTaskNo;
|
||||
shippingFocusReason.value = t('chat.shippingNoticeUi.currentFocusDefaultReason');
|
||||
if (shippingBatchSummary.value) {
|
||||
shippingBatchSummary.value = {
|
||||
...shippingBatchSummary.value,
|
||||
current_focus_task_no: normalizedTaskNo,
|
||||
};
|
||||
}
|
||||
await syncShippingBatchSummary(batchNo);
|
||||
await syncShippingConversationWorkspace();
|
||||
await syncActiveShippingTaskDetail(normalizedTaskNo);
|
||||
await refreshShippingActions();
|
||||
// #region debug-point C:switch-focus-success
|
||||
void reportRetryRpaDebug('C', 'switchShippingFocusTask success', {
|
||||
batchNo,
|
||||
normalizedTaskNo,
|
||||
resolvedTaskId: resolvedShippingTaskId.value,
|
||||
});
|
||||
// #endregion
|
||||
return true;
|
||||
};
|
||||
|
||||
const clearShippingFocus = () => {
|
||||
focusedShippingTaskNo.value = '';
|
||||
shippingFocusReason.value = '';
|
||||
};
|
||||
|
||||
/**
|
||||
* 切换会话上传摘要中的活动批次(只读同步,无焦点条/抽屉写操作)。
|
||||
* @param batchNo - 目标批次号
|
||||
* @returns 是否切换成功
|
||||
*/
|
||||
const switchShippingBatch = async (batchNo: string) => {
|
||||
const normalizedBatchNo = String(batchNo || '').trim();
|
||||
if (!normalizedBatchNo) return false;
|
||||
@@ -584,11 +522,9 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
const nextFocusState = resolveShippingBatchFocusState(
|
||||
shippingBatchSummary.value,
|
||||
shippingBatchTasks.value,
|
||||
t('chat.shippingNoticeUi.currentFocusDefaultReason'),
|
||||
'',
|
||||
);
|
||||
const nextTaskNo = nextFocusState.taskNo;
|
||||
focusedShippingTaskNo.value = nextFocusState.taskNo;
|
||||
shippingFocusReason.value = nextFocusState.focusReason;
|
||||
if (nextTaskNo) {
|
||||
resolvedShippingTaskId.value = nextTaskNo;
|
||||
await syncActiveShippingTaskDetail(nextTaskNo);
|
||||
@@ -601,7 +537,7 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
* 清空当前聊天页绑定的发货任务上下文。
|
||||
*
|
||||
* 核心逻辑:在新建对话、切换 Agent 或离开发货任务场景时,主动清掉批次/任务/上传缓存,
|
||||
* 避免顶部 Stepper、列表展开态和待上传库存文件残留到下一次新会话。
|
||||
* 避免会话摘要和待上传库存文件残留到下一次新会话。
|
||||
*/
|
||||
const resetShippingConversationState = () => {
|
||||
shippingAutoFlowRequested.value = false;
|
||||
@@ -613,13 +549,9 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
resolvedShippingTaskId.value = '';
|
||||
resolvedShippingBatchNo.value = '';
|
||||
activeShippingBatchNo.value = '';
|
||||
focusedShippingTaskNo.value = '';
|
||||
shippingFocusReason.value = '';
|
||||
shippingConversationWorkspace.value = null;
|
||||
shippingBatchSummary.value = null;
|
||||
shippingBatchTasks.value = [];
|
||||
shippingWorkspaceOpen.value = false;
|
||||
retryingShippingPendingTasks.value = false;
|
||||
activeShippingTaskDetail.value = null;
|
||||
lastConversationSyncKey.value = '';
|
||||
};
|
||||
@@ -651,7 +583,6 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
shippingBatchSummary.value?.current_focus_task_no
|
||||
|| shippingBatchSummary.value?.process_summary?.current_task_no
|
||||
|| shippingBatchTasks.value[0]?.task_no
|
||||
|| focusedShippingTaskNo.value
|
||||
|| resolvedShippingTaskId.value
|
||||
|| '',
|
||||
).trim();
|
||||
@@ -770,7 +701,6 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
const resolveShippingTaskForShortageQuery = async (taskNo?: string) => {
|
||||
const normalizedTaskNo = String(
|
||||
taskNo
|
||||
|| focusedShippingTaskNo.value
|
||||
|| getActiveBatchTaskId()
|
||||
|| getActiveShippingTaskId()
|
||||
|| '',
|
||||
@@ -1211,10 +1141,11 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
const onConversationIdChanging = (nextId: string, prevId: string | null | undefined) => {
|
||||
onNoticeBatchConversationChanging(nextId, prevId);
|
||||
shippingIntakes.stopPolling();
|
||||
shippingOrderExtractionRuns.stopPolling();
|
||||
if (nextId && nextId !== prevId) {
|
||||
void shippingIntakes.restoreForConversation(nextId);
|
||||
void shippingOrderExtractionRuns.restoreForConversation(nextId);
|
||||
} else {
|
||||
shippingOrderExtractionRuns.clearActiveRun();
|
||||
}
|
||||
if (prevId !== nextId) {
|
||||
resolvedShippingTaskId.value = '';
|
||||
@@ -1226,38 +1157,8 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
}
|
||||
};
|
||||
|
||||
const WORKSPACE_DIRECT_PICKER_ACTION_IDS = new Set(['upload_inventory_file', 'replace_notice_file']);
|
||||
|
||||
/**
|
||||
* 从右侧批次工作台触发指定任务的后端状态机动作。
|
||||
*
|
||||
* 核心逻辑:普通动作先把 batch focus 切到目标 task,再复用聊天气泡的统一 action.id 分发器;
|
||||
* 文件选择类动作必须先同步打开 picker,再异步切焦点,避免浏览器丢失用户点击手势。
|
||||
* @param taskNo - 被点击按钮所属的任务编号
|
||||
* @param action - 后端 `ui_state.action_buttons` 返回的动作按钮
|
||||
* @returns 是否成功进入统一动作处理链
|
||||
*/
|
||||
const handleShippingWorkspaceAction = async (taskNo: string, action: ShippingActionButton) => {
|
||||
const normalizedTaskNo = String(taskNo || '').trim().toUpperCase();
|
||||
if (!normalizedTaskNo || !action?.id || !isShippingNoticeAgent.value) return false;
|
||||
if (isShippingActionBusy.value) {
|
||||
msg.warning(t('chat.shippingNoticeUi.actionBusyHint'));
|
||||
return false;
|
||||
}
|
||||
if (WORKSPACE_DIRECT_PICKER_ACTION_IDS.has(String(action.id || ''))) {
|
||||
await handleShippingMenuAction(action, undefined, { taskId: normalizedTaskNo });
|
||||
void switchShippingFocusTask(normalizedTaskNo);
|
||||
return true;
|
||||
}
|
||||
const switched = await switchShippingFocusTask(normalizedTaskNo);
|
||||
if (!switched) return false;
|
||||
await handleShippingMenuAction(action, undefined, { taskId: normalizedTaskNo });
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* 重试当前聚焦批次中可恢复的失败/排队任务。
|
||||
* 核心逻辑:调 workspace retry-pending → 刷新会话工作台/批次摘要/动作;成功反馈交给页面级非阻塞 toast,避免居中成功弹窗。
|
||||
* 重试当前聚焦批次中可恢复的失败/排队任务(供页面级确认弹窗调用;Chat 本身不再挂批次抽屉按钮)。
|
||||
* @returns 成功时返回 started/skipped;失败或跳过时返回 null
|
||||
*/
|
||||
const retryCurrentShippingBatchPendingTasks = async (): Promise<{
|
||||
@@ -1265,12 +1166,11 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
skipped: number;
|
||||
} | null> => {
|
||||
const batchNo = getActiveShippingBatchNo();
|
||||
if (!batchNo || retryingShippingPendingTasks.value) return null;
|
||||
if (!batchNo) return null;
|
||||
if (isShippingActionBusy.value) {
|
||||
msg.warning(t('chat.shippingNoticeUi.actionBusyHint'));
|
||||
return null;
|
||||
}
|
||||
retryingShippingPendingTasks.value = true;
|
||||
try {
|
||||
const { retryWorkspaceShippingBatchPending } = await import('@/features/chat/api/shipping.api');
|
||||
const result = await retryWorkspaceShippingBatchPending(batchNo);
|
||||
@@ -1284,8 +1184,6 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
} catch (error) {
|
||||
msg.error(error instanceof Error ? error.message : t('chat.shippingNoticeUi.retryFailed'));
|
||||
return null;
|
||||
} finally {
|
||||
retryingShippingPendingTasks.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1342,10 +1240,10 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
};
|
||||
|
||||
/**
|
||||
* 启停发货批次状态短轮询。
|
||||
* 启停发货会话状态短轮询。
|
||||
*
|
||||
* 核心逻辑:聊天流当前没有 shipping 专属 SSE;因此在存在任务/批次上下文时每 3 秒补拉一次,
|
||||
* 让顶部 Stepper、批次统计和动作按钮能在后端异步状态变化后自动更新。
|
||||
* 让右侧会话摘要与通知态 ui_state 能在后端异步状态变化后自动更新。
|
||||
*/
|
||||
const restartShippingStatusPolling = () => {
|
||||
if (shippingStatusPollTimer) {
|
||||
@@ -1444,7 +1342,6 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
return {
|
||||
shippingBindSend,
|
||||
isShippingNoticeAgent,
|
||||
showShippingProgressWorkspace,
|
||||
prepareMarkdownDisplayText,
|
||||
shippingAutoFlowRequested,
|
||||
shippingInventoryPickerRef,
|
||||
@@ -1457,21 +1354,14 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
shippingBatchNoFromQuery,
|
||||
resolvedShippingBatchNo,
|
||||
activeShippingBatchNo,
|
||||
focusedShippingTaskNo,
|
||||
shippingFocusReason,
|
||||
shippingConversationWorkspace,
|
||||
shippingBatchSummary,
|
||||
shippingBatchTasks,
|
||||
shippingWorkspaceOpen,
|
||||
isShippingActionBusy,
|
||||
retryingShippingPendingTasks,
|
||||
activeShippingTaskDetail,
|
||||
getCurrentShippingChatContext,
|
||||
getActiveShippingBatchNo,
|
||||
switchShippingBatch,
|
||||
switchShippingFocusTask,
|
||||
clearShippingFocus,
|
||||
handleShippingWorkspaceAction,
|
||||
retryCurrentShippingBatchPendingTasks,
|
||||
queryShippingShortageDetails,
|
||||
resetShippingConversationState,
|
||||
@@ -1487,7 +1377,6 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
finalizeShippingAssistantMessage,
|
||||
selectShippingInventoryUploadTask,
|
||||
cancelShippingInventoryTaskSelection,
|
||||
shippingActionButtonClass,
|
||||
shippingSuggestedPrompt,
|
||||
useShippingSuggestedPrompt,
|
||||
enqueueShippingNoticeFiles: shippingIntakes.enqueueNoticeFiles,
|
||||
@@ -1496,6 +1385,7 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
retryShippingNoticeAttachment: shippingIntakes.retryNoticeAttachment,
|
||||
retryOrderExtractionRun: shippingOrderExtractionRuns.retryRun,
|
||||
reparseOrderExtractionRun: shippingOrderExtractionRuns.reparseRun,
|
||||
getActiveOrderExtractionRunNo: shippingOrderExtractionRuns.getActiveRunNo,
|
||||
shippingNoticeAllReadyForConfirmation: shippingIntakes.allReadyForConfirmation,
|
||||
setShippingCandidateSelected,
|
||||
resolveShippingCandidateDuplicate,
|
||||
|
||||
Reference in new issue
Block a user