feat(shipping-notice): 落地 XFA 拆分、版面签名、统一进度与处理域履约
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
3a9fbac2fc
commit
d2b3d74def
571 files changed
+78064
-24681
No files matched your search
@@ -629,6 +629,8 @@ export function useChatPage() {
|
||||
activeShippingTaskDetail: shipping.activeShippingTaskDetail,
|
||||
getActiveOrderExtractionRunNo: shipping.getActiveOrderExtractionRunNo,
|
||||
workflowRefreshTrigger: shipping.workflowRefreshTrigger,
|
||||
focusedConversationTaskNo: shipping.focusedConversationTaskNo,
|
||||
setFocusedConversationTaskNo: shipping.setFocusedConversationTaskNo,
|
||||
shippingInventorySelectionActive: shipping.shippingInventorySelectionActive,
|
||||
shippingInventorySelectionTaskId: shipping.shippingInventorySelectionTaskId,
|
||||
switchShippingBatch: shipping.switchShippingBatch,
|
||||
|
||||
@@ -13,6 +13,7 @@ const { deleteAllChatSessions, deleteChatSession, listChatSessions } = vi.hoiste
|
||||
deleteChatSession: vi.fn(),
|
||||
listChatSessions: vi.fn(),
|
||||
}));
|
||||
const listWorkspaceShippingOrderExtractionRuns = vi.hoisted(() => vi.fn());
|
||||
|
||||
const {
|
||||
getSessionHistory,
|
||||
@@ -29,6 +30,7 @@ vi.mock('../api/chat.api', () => ({
|
||||
deleteChatSession,
|
||||
listChatSessions,
|
||||
}));
|
||||
vi.mock('../api/shipping.api', () => ({ listWorkspaceShippingOrderExtractionRuns }));
|
||||
|
||||
vi.mock('../stores/chat.store', () => ({
|
||||
useChatStore: () => ({
|
||||
@@ -43,6 +45,7 @@ describe('useChatSessions', () => {
|
||||
deleteAllChatSessions.mockReset();
|
||||
deleteChatSession.mockReset();
|
||||
listChatSessions.mockReset();
|
||||
listWorkspaceShippingOrderExtractionRuns.mockReset();
|
||||
getSessionHistory.mockReset();
|
||||
setSessionHistory.mockReset();
|
||||
patchSessionHistory.mockReset();
|
||||
@@ -91,4 +94,41 @@ describe('useChatSessions', () => {
|
||||
expect(runs.value).toEqual([]);
|
||||
expect(startNewChat).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('rebuilds order-review query from the selected conversation', async () => {
|
||||
const replace = vi.fn();
|
||||
listWorkspaceShippingOrderExtractionRuns.mockResolvedValue({
|
||||
items: [{ run_no: 'RUN-NEW', status: 'review_required' }],
|
||||
});
|
||||
const sessions = useChatSessions({
|
||||
deps: {
|
||||
t: (key: string) => key,
|
||||
router: { replace },
|
||||
route: {
|
||||
path: '/chat/7',
|
||||
query: {
|
||||
conversation_id: 'conv-old', mode: 'order-review', run_no: 'RUN-OLD',
|
||||
case_no: 'CASE-OLD', document_id: '91', focus: 'evidence',
|
||||
},
|
||||
},
|
||||
} as never,
|
||||
currentAgentId: computed(() => 7),
|
||||
conversationId: ref('conv-old'),
|
||||
activeRunId: ref(null),
|
||||
runs: ref([]),
|
||||
activateRun: vi.fn(),
|
||||
loadConversation: vi.fn(async () => {}),
|
||||
isSidebarOpen: ref(true),
|
||||
onConfirmDelete: vi.fn(),
|
||||
startNewChat: vi.fn(),
|
||||
});
|
||||
|
||||
await sessions.handleHistorySelect({ id: 2, conversation_id: 'conv-new' } as never);
|
||||
|
||||
expect(listWorkspaceShippingOrderExtractionRuns).toHaveBeenCalledWith('conv-new', 20);
|
||||
expect(replace).toHaveBeenCalledWith({
|
||||
path: '/chat/7',
|
||||
query: { conversation_id: 'conv-new', mode: 'order-review', run_no: 'RUN-NEW' },
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
deleteChatSession,
|
||||
listChatSessions,
|
||||
} from '../api/chat.api';
|
||||
import { listWorkspaceShippingOrderExtractionRuns } from '../api/shipping.api';
|
||||
import type { ChatRun, ChatSessionItem, DisplayHistoryItem } from '../types/chat.types';
|
||||
import type { ChatDeps } from './chat.deps';
|
||||
import { useChatStore } from '../stores/chat.store';
|
||||
@@ -133,6 +134,22 @@ export function useChatSessions(options: UseChatSessionsOptions) {
|
||||
return;
|
||||
}
|
||||
|
||||
const isOrderReview = route.query.mode === 'order-review';
|
||||
if (isOrderReview) {
|
||||
// 复核工作台的 Run/Case/文档上下文属于旧会话,切换时必须整体重建,不能只替换 conversation_id。
|
||||
const restored = await listWorkspaceShippingOrderExtractionRuns(item.conversation_id, 20);
|
||||
const nextRun = (restored.items || []).find((candidate) =>
|
||||
['review_required', 'partially_completed'].includes(String(candidate.status || '')),
|
||||
);
|
||||
const nextQuery: Record<string, string> = { conversation_id: item.conversation_id };
|
||||
if (nextRun?.run_no) {
|
||||
nextQuery.mode = 'order-review';
|
||||
nextQuery.run_no = String(nextRun.run_no);
|
||||
}
|
||||
await router.replace({ path: route.path, query: nextQuery });
|
||||
return;
|
||||
}
|
||||
|
||||
const nextQuery: Record<string, string | string[]> = { ...route.query, conversation_id: item.conversation_id };
|
||||
delete nextQuery.task_id;
|
||||
delete nextQuery.preset;
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
/**
|
||||
* features/chat/composables/useChatShipping.ts
|
||||
* 用途:发货通知聊天编排入口,组合 shipping/* 子模块并对 ChatView 暴露统一交互能力。
|
||||
* 依赖:shipping.api、shipping/ 下各 handler 工厂、chat.deps、chat.types、Vue refs/computed/watch。
|
||||
* 依赖:shipping.api(任务/客户等)、shipping/ 下各 handler 工厂、chat.deps、chat.types、Vue refs/computed/watch。
|
||||
* 逻辑:上游由 ChatView/ChatPage 调用本 composable;本文件维护会话任务摘要 + ui_state 同步,
|
||||
* 不再管理批次抽屉/焦点条/聊天履约写按钮(履约写改由任务处理工作台承接)。
|
||||
* 以及 focusedConversationTaskNo(提交追加优先级 / 侧栏焦点);
|
||||
* co8:shipping_batches 工作台轮询已下线,进度改由 shipping-processing projection 承接;
|
||||
* 保留 resolvedShippingBatchNo / shippingBatchSummary 等 ref 供调用方兼容,不再发起批次网络请求。
|
||||
*/
|
||||
|
||||
import {
|
||||
@@ -38,18 +40,18 @@ import {
|
||||
import { isShippingSpreadsheetFile } from '../shipping/shippingUploadPrompt';
|
||||
import { extractExt } from '../constants/shipping';
|
||||
import {
|
||||
getWorkspaceShippingConversationBatches,
|
||||
getWorkspaceShippingBatch,
|
||||
getWorkspaceShippingTask,
|
||||
listWorkspaceShippingCustomerOptions,
|
||||
confirmWorkspaceShippingCustomer,
|
||||
type ShippingBatchUiState,
|
||||
type ShippingBatchSummary,
|
||||
type ShippingConversationWorkspace,
|
||||
type ShippingTaskDetail,
|
||||
type ShippingTaskSummary,
|
||||
} from '@/features/chat/api/shipping.api';
|
||||
import type { ShippingCustomerOption } from '../types/shipping.api.types';
|
||||
import type {
|
||||
ShippingBatchSummary,
|
||||
ShippingBatchUiState,
|
||||
ShippingCustomerOption,
|
||||
} from '../types/shipping.api.types';
|
||||
import { buildShippingQueryShortageTurn } from '../shipping/shippingTurnActions';
|
||||
import {
|
||||
hasShortageLines,
|
||||
@@ -346,6 +348,12 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 同步批次摘要占位(co8 已下线批次详情 API)。
|
||||
*
|
||||
* 核心逻辑:batchNo 为空时清空摘要;否则仅回填本地 batch_no 与已有 task 焦点,不发起网络请求。
|
||||
* @param batchNo - 目标批次号
|
||||
*/
|
||||
const syncShippingBatchSummary = async (batchNo: string) => {
|
||||
const normalized = String(batchNo || '').trim();
|
||||
if (!normalized) {
|
||||
@@ -353,52 +361,32 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
shippingBatchTasks.value = [];
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const detail = await getWorkspaceShippingBatch(normalized);
|
||||
applyShippingBatchDetail(detail, normalized);
|
||||
} catch {
|
||||
// ignore summary refresh failure in chat flow
|
||||
resolvedShippingBatchNo.value = normalized;
|
||||
if (!activeShippingBatchNo.value) {
|
||||
activeShippingBatchNo.value = normalized;
|
||||
}
|
||||
shippingBatchSummary.value = {
|
||||
id: 0,
|
||||
batch_no: normalized,
|
||||
conversation_id: conversationId.value,
|
||||
current_focus_task_no: resolvedShippingTaskId.value || null,
|
||||
process_summary: null,
|
||||
};
|
||||
};
|
||||
|
||||
const applyConversationWorkspaceFocus = (
|
||||
workspace: ShippingConversationWorkspace,
|
||||
options?: { preferLatest?: boolean },
|
||||
) => {
|
||||
const batches = Array.isArray(workspace.batches) ? workspace.batches : [];
|
||||
if (!batches.length) return;
|
||||
const queryBatchNo = String(shippingBatchNoFromQuery.value || '').trim();
|
||||
const currentBatchNo = String(activeShippingBatchNo.value || resolvedShippingBatchNo.value || queryBatchNo || '').trim();
|
||||
const selectedBatch = selectShippingConversationBatch(
|
||||
batches,
|
||||
currentBatchNo,
|
||||
queryBatchNo,
|
||||
Boolean(options?.preferLatest),
|
||||
);
|
||||
if (!selectedBatch) return;
|
||||
if (options?.preferLatest) {
|
||||
activeShippingBatchNo.value = selectedBatch.batch_no;
|
||||
}
|
||||
applyShippingBatchDetail(selectedBatch, selectedBatch.batch_no);
|
||||
};
|
||||
|
||||
/**
|
||||
* 同步会话批次工作台(co8 已下线 conversation batches API)。
|
||||
*
|
||||
* 核心逻辑:保留调用签名供抽取 Run / 终态刷新链路兼容;始终清空 workspace 并返回 false,不发起网络。
|
||||
* @param _options - 历史参数,保留兼容
|
||||
* @returns 恒为 false
|
||||
*/
|
||||
const syncShippingConversationWorkspace = async (
|
||||
options?: { preferLatest?: boolean },
|
||||
_options?: { preferLatest?: boolean },
|
||||
): Promise<boolean> => {
|
||||
const localConversationId = String(conversationId.value || '').trim();
|
||||
if (!localConversationId || !isShippingNoticeAgent.value) {
|
||||
shippingConversationWorkspace.value = null;
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
const workspace = await getWorkspaceShippingConversationBatches(localConversationId);
|
||||
shippingConversationWorkspace.value = workspace;
|
||||
applyConversationWorkspaceFocus(workspace, options);
|
||||
return true;
|
||||
} catch {
|
||||
shippingConversationWorkspace.value = null;
|
||||
return false;
|
||||
}
|
||||
void _options;
|
||||
shippingConversationWorkspace.value = null;
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -469,13 +457,8 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
recovered = true;
|
||||
}
|
||||
if (!snapshot && batchNo) {
|
||||
try {
|
||||
const detail = await getWorkspaceShippingBatch(batchNo);
|
||||
applyShippingBatchDetail(detail, batchNo);
|
||||
recovered = true;
|
||||
} catch {
|
||||
// ignore and continue with task-first recovery
|
||||
}
|
||||
await syncShippingBatchSummary(batchNo);
|
||||
recovered = true;
|
||||
}
|
||||
if (taskNo) {
|
||||
await syncActiveShippingTaskDetail(taskNo);
|
||||
@@ -486,13 +469,8 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
activeShippingBatchNo.value = detailBatchNo;
|
||||
}
|
||||
if (!snapshot && batchNo && String(shippingBatchSummary.value?.batch_no || '').trim() !== batchNo) {
|
||||
try {
|
||||
const detail = await getWorkspaceShippingBatch(batchNo);
|
||||
applyShippingBatchDetail(detail, batchNo);
|
||||
recovered = true;
|
||||
} catch {
|
||||
// ignore and keep task-only recovery
|
||||
}
|
||||
await syncShippingBatchSummary(batchNo);
|
||||
recovered = true;
|
||||
}
|
||||
recovered = recovered || Boolean(activeShippingTaskDetail.value);
|
||||
}
|
||||
@@ -504,33 +482,17 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
);
|
||||
|
||||
/**
|
||||
* 切换会话上传摘要中的活动批次(只读同步,无焦点条/抽屉写操作)。
|
||||
* 切换会话上传摘要中的活动批次(co8 已下线,保留签名兼容)。
|
||||
*
|
||||
* 核心逻辑:批次工作台 API 已移除,调用时仅提示用户改由右侧 processing 工作台操作。
|
||||
* @param batchNo - 目标批次号
|
||||
* @returns 是否切换成功
|
||||
* @returns 恒为 false
|
||||
*/
|
||||
const switchShippingBatch = async (batchNo: string) => {
|
||||
const normalizedBatchNo = String(batchNo || '').trim();
|
||||
if (!normalizedBatchNo) return false;
|
||||
activeShippingBatchNo.value = normalizedBatchNo;
|
||||
resolvedShippingBatchNo.value = normalizedBatchNo;
|
||||
const workspaceBatch = shippingConversationWorkspace.value?.batches.find((item) => item.batch_no === normalizedBatchNo);
|
||||
if (workspaceBatch) {
|
||||
applyShippingBatchDetail(workspaceBatch, normalizedBatchNo);
|
||||
} else {
|
||||
await syncShippingBatchSummary(normalizedBatchNo);
|
||||
}
|
||||
const nextFocusState = resolveShippingBatchFocusState(
|
||||
shippingBatchSummary.value,
|
||||
shippingBatchTasks.value,
|
||||
'',
|
||||
);
|
||||
const nextTaskNo = nextFocusState.taskNo;
|
||||
if (nextTaskNo) {
|
||||
resolvedShippingTaskId.value = nextTaskNo;
|
||||
await syncActiveShippingTaskDetail(nextTaskNo);
|
||||
}
|
||||
await refreshShippingActions();
|
||||
return true;
|
||||
msg.warning(t('chat.shippingNoticeUi.batchSwitchRemoved'));
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -540,6 +502,9 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
* 避免会话摘要和待上传库存文件残留到下一次新会话。
|
||||
*/
|
||||
const resetShippingConversationState = () => {
|
||||
// 新对话不会触发 onConversationIdChanging;必须在此清掉旧 Run,
|
||||
// 否则右侧面板仍会将其作为当前会话的展示条件。
|
||||
shippingOrderExtractionRuns.clearActiveRun();
|
||||
shippingAutoFlowRequested.value = false;
|
||||
pendingShippingUploadTaskId.value = '';
|
||||
pendingShippingNoticeTaskId.value = '';
|
||||
@@ -796,6 +761,11 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
const bumpWorkflowRefresh = () => {
|
||||
workflowRefreshTrigger.value += 1;
|
||||
};
|
||||
/** 侧栏/提交共用的当前聚焦用户可见任务(OT-…)。 */
|
||||
const focusedConversationTaskNo = ref<string | null>(null);
|
||||
const setFocusedConversationTaskNo = (taskNo: string | null) => {
|
||||
focusedConversationTaskNo.value = String(taskNo || '').trim() || null;
|
||||
};
|
||||
const shippingOrderExtractionRuns = useShippingOrderExtractionRuns({
|
||||
messages,
|
||||
conversationId,
|
||||
@@ -818,6 +788,8 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
},
|
||||
onRetryError: (message) => msg.error(message),
|
||||
onWorkflowRefresh: bumpWorkflowRefresh,
|
||||
getFocusedUserTaskNo: () => focusedConversationTaskNo.value,
|
||||
setFocusedUserTaskNo: setFocusedConversationTaskNo,
|
||||
t,
|
||||
});
|
||||
|
||||
@@ -1024,6 +996,8 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
getParsedIntakeNos: shippingIntakes.getParsedIntakeNos,
|
||||
getSelectedCandidateNos: shippingIntakes.getSelectedCandidateNos,
|
||||
clearConsumedNoticeAttachments: shippingIntakes.clearConsumedAttachments,
|
||||
enqueueNoticeFiles: shippingIntakes.enqueueNoticeFiles,
|
||||
startOrderExtractionRun: (...args) => shippingOrderExtractionRuns.startRun(...args),
|
||||
sendTemporaryInventoryMessage: async (assetNo, fileName) => sendMessage(
|
||||
`我已上传库存文件:${fileName},请先检查文件结构并说明下一步。`,
|
||||
currentAgentId.value,
|
||||
@@ -1147,6 +1121,7 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
onNoticeBatchConversationChanging(nextId, prevId);
|
||||
shippingIntakes.stopPolling();
|
||||
if (nextId && nextId !== prevId) {
|
||||
focusedConversationTaskNo.value = null;
|
||||
void shippingIntakes.restoreForConversation(nextId);
|
||||
void shippingOrderExtractionRuns.restoreForConversation(nextId);
|
||||
} else {
|
||||
@@ -1163,33 +1138,17 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
};
|
||||
|
||||
/**
|
||||
* 重试当前聚焦批次中可恢复的失败/排队任务(供页面级确认弹窗调用;Chat 本身不再挂批次抽屉按钮)。
|
||||
* @returns 成功时返回 started/skipped;失败或跳过时返回 null
|
||||
* 重试当前聚焦批次中可恢复的失败/排队任务(co8 已下线,保留签名兼容)。
|
||||
*
|
||||
* 核心逻辑:批次重试 API 已移除,调用时提示用户改由 processing 工作台或任务动作重试。
|
||||
* @returns 恒为 null
|
||||
*/
|
||||
const retryCurrentShippingBatchPendingTasks = async (): Promise<{
|
||||
started: number;
|
||||
skipped: number;
|
||||
} | null> => {
|
||||
const batchNo = getActiveShippingBatchNo();
|
||||
if (!batchNo) return null;
|
||||
if (isShippingActionBusy.value) {
|
||||
msg.warning(t('chat.shippingNoticeUi.actionBusyHint'));
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
const { retryWorkspaceShippingBatchPending } = await import('@/features/chat/api/shipping.api');
|
||||
const result = await retryWorkspaceShippingBatchPending(batchNo);
|
||||
await syncShippingConversationWorkspace();
|
||||
await syncShippingBatchSummary(batchNo);
|
||||
await refreshShippingActions();
|
||||
return {
|
||||
started: Number(result.started ?? 0),
|
||||
skipped: Number(result.skipped ?? 0),
|
||||
};
|
||||
} catch (error) {
|
||||
msg.error(error instanceof Error ? error.message : t('chat.shippingNoticeUi.retryFailed'));
|
||||
return null;
|
||||
}
|
||||
msg.warning(t('chat.shippingNoticeUi.batchRetryRemoved'));
|
||||
return null;
|
||||
};
|
||||
|
||||
const handleShippingLocalFilesSelected = (event: Event): boolean => {
|
||||
@@ -1247,8 +1206,8 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
/**
|
||||
* 启停发货会话状态短轮询。
|
||||
*
|
||||
* 核心逻辑:聊天流当前没有 shipping 专属 SSE;因此在存在任务/批次上下文时每 3 秒补拉一次,
|
||||
* 让右侧会话摘要与通知态 ui_state 能在后端异步状态变化后自动更新。
|
||||
* 核心逻辑:co8 后不再轮询 shipping_batches;仅在存在任务上下文时每 3 秒补拉任务详情与动作按钮,
|
||||
* 批次/处理进度改由 shipping-processing projection 承接。
|
||||
*/
|
||||
const restartShippingStatusPolling = () => {
|
||||
if (shippingStatusPollTimer) {
|
||||
@@ -1256,22 +1215,16 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
shippingStatusPollTimer = null;
|
||||
}
|
||||
if (!isShippingNoticeAgent.value) return;
|
||||
const batchNo = getActiveShippingBatchNo();
|
||||
const taskId = getActiveBatchTaskId();
|
||||
if (!batchNo && !taskId) return;
|
||||
const taskId = getActiveBatchTaskId() || getActiveShippingTaskId();
|
||||
if (!taskId) return;
|
||||
|
||||
shippingStatusPollTimer = setInterval(() => {
|
||||
if (!isShippingNoticeAgent.value) return;
|
||||
const nextBatchNo = getActiveShippingBatchNo();
|
||||
const nextTaskId = getActiveBatchTaskId();
|
||||
if (!nextBatchNo && !nextTaskId) return;
|
||||
const nextTaskId = getActiveBatchTaskId() || getActiveShippingTaskId();
|
||||
if (!nextTaskId) return;
|
||||
void (async () => {
|
||||
await syncShippingConversationWorkspace();
|
||||
if (nextBatchNo) await syncShippingBatchSummary(nextBatchNo);
|
||||
if (nextTaskId) {
|
||||
await syncActiveShippingTaskDetail(nextTaskId);
|
||||
await syncConversationMessagesIfNeeded(nextTaskId);
|
||||
}
|
||||
await syncActiveShippingTaskDetail(nextTaskId);
|
||||
await syncConversationMessagesIfNeeded(nextTaskId);
|
||||
await refreshShippingActions();
|
||||
if (!hasRunningShippingBatchTasks() && !isShippingActionBusy.value && shippingStatusPollTimer) {
|
||||
clearInterval(shippingStatusPollTimer);
|
||||
@@ -1395,6 +1348,8 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
reparseOrderExtractionRun: shippingOrderExtractionRuns.reparseRun,
|
||||
getActiveOrderExtractionRunNo: shippingOrderExtractionRuns.getActiveRunNo,
|
||||
workflowRefreshTrigger,
|
||||
focusedConversationTaskNo,
|
||||
setFocusedConversationTaskNo,
|
||||
shippingNoticeAllReadyForConfirmation: shippingIntakes.allReadyForConfirmation,
|
||||
setShippingCandidateSelected,
|
||||
resolveShippingCandidateDuplicate,
|
||||
@@ -1404,6 +1359,7 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
showShippingCustomerDialog,
|
||||
shippingCustomerOptions,
|
||||
shippingCustomerLoading,
|
||||
openShippingCustomerDialog,
|
||||
searchShippingCustomers,
|
||||
confirmShippingCustomer,
|
||||
closeShippingCustomerDialog: () => {
|
||||
|
||||
Reference in new issue
Block a user