!11 feat(shipping-notice): 实现滚动履约功能,优化发货通知流程与代码清理
Merge pull request !11 from 曹惠鹏/hugo-shipping-notice
This commit is contained in:
402 files changed
+23045
-20484
No files matched your search
@@ -37,21 +37,15 @@ describe('useChat user attachment snapshots', () => {
|
||||
});
|
||||
});
|
||||
|
||||
const buildBatchUiStateEvent = (
|
||||
const buildTaskUiStateEvent = (
|
||||
taskNo: string,
|
||||
batchNo: string,
|
||||
actionId: string,
|
||||
checkpoint = 'ready_export',
|
||||
) => ({
|
||||
event: 'shipping_ui_state',
|
||||
batch_no: batchNo,
|
||||
batch_ui_state: {
|
||||
batch_no: batchNo,
|
||||
current_focus_task_no: taskNo,
|
||||
tasks: [],
|
||||
focus_task_ui_state: {
|
||||
task_no: taskNo,
|
||||
ui_state: {
|
||||
task_no: taskNo,
|
||||
batch_no: batchNo,
|
||||
checkpoint,
|
||||
match_status: 'matched',
|
||||
review_status: null,
|
||||
@@ -73,7 +67,6 @@ const buildBatchUiStateEvent = (
|
||||
},
|
||||
],
|
||||
updated_at: '2026-07-01T10:00:00+08:00',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -81,38 +74,38 @@ describe('useChat shipping_ui_state SSE', () => {
|
||||
it('hydrates ui_state for notifications and never attaches chat fulfillment actions', () => {
|
||||
const message: ChatMessage = {
|
||||
role: 'assistant',
|
||||
content: '当前正在处理批次任务',
|
||||
content: '当前正在处理任务',
|
||||
type: 'shipping-match-result',
|
||||
payload: { action_buttons: [{ id: 'legacy' }] },
|
||||
};
|
||||
|
||||
const batchEvent = buildBatchUiStateEvent('SN-UNIT-001', 'SB-UNIT-001', 'generate_excel');
|
||||
const taskEvent = buildTaskUiStateEvent('SN-UNIT-001', 'generate_excel');
|
||||
|
||||
applyShippingUiStateToMessage(message, batchEvent);
|
||||
applyShippingUiStateToMessage(message, taskEvent);
|
||||
|
||||
expect(message.shipping_ui_state?.task_no).toBe('SN-UNIT-001');
|
||||
expect(message.shipping_actions).toBeUndefined();
|
||||
expect((message.payload as { action_buttons?: unknown[] }).action_buttons).toBeUndefined();
|
||||
expect((message.payload as { shipping_batch_ui_state?: { batch_no?: string } }).shipping_batch_ui_state?.batch_no).toBe('SB-UNIT-001');
|
||||
expect((message.payload as { shipping_ui_state?: { task_no?: string } }).shipping_ui_state?.task_no).toBe('SN-UNIT-001');
|
||||
});
|
||||
|
||||
it('updates ui_state when batch focus task changes without remounting action buttons', () => {
|
||||
it('updates ui_state when task changes without remounting action buttons', () => {
|
||||
const message: ChatMessage = {
|
||||
role: 'assistant',
|
||||
content: '请继续处理当前批次',
|
||||
content: '请继续处理当前任务',
|
||||
payload: { action_buttons: [] },
|
||||
};
|
||||
|
||||
applyShippingUiStateToMessage(message, buildBatchUiStateEvent('SN-FOCUS-A', 'SB-FOCUS-001', 'generate_excel'));
|
||||
applyShippingUiStateToMessage(message, buildTaskUiStateEvent('SN-FOCUS-A', 'generate_excel'));
|
||||
|
||||
expect(message.shipping_ui_state?.task_no).toBe('SN-FOCUS-A');
|
||||
expect(message.shipping_actions).toBeUndefined();
|
||||
|
||||
applyShippingUiStateToMessage(message, buildBatchUiStateEvent('SN-FOCUS-B', 'SB-FOCUS-001', 'retry_upload'));
|
||||
applyShippingUiStateToMessage(message, buildTaskUiStateEvent('SN-FOCUS-B', 'retry_upload'));
|
||||
|
||||
expect(message.shipping_ui_state?.task_no).toBe('SN-FOCUS-B');
|
||||
expect(message.shipping_actions).toBeUndefined();
|
||||
expect((message.payload as { shipping_batch_ui_state?: { current_focus_task_no?: string } }).shipping_batch_ui_state?.current_focus_task_no)
|
||||
expect((message.payload as { shipping_ui_state?: { task_no?: string } }).shipping_ui_state?.task_no)
|
||||
.toBe('SN-FOCUS-B');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -15,7 +15,7 @@ import type {
|
||||
RetrieverResource,
|
||||
ShippingOrderExtractionState,
|
||||
} from '../types/chat.types';
|
||||
import type { ShippingBatchUiState, ShippingTaskUiState } from '../types/shipping.api.types';
|
||||
import type { ShippingTaskUiState } from '../types/shipping.api.types';
|
||||
import type { ChatMessageSendResult } from '../types/chat-turn.types';
|
||||
import { createStartChatTurn } from './useChatTurn';
|
||||
|
||||
@@ -112,29 +112,19 @@ const addAttributionParts = (msg: ChatMessage, value: unknown) => {
|
||||
/**
|
||||
* 解析发货通知 SSE 事件中的统一 UI State 载荷。
|
||||
*
|
||||
* 核心逻辑:优先读取单票 `ui_state`,批次事件则下钻 `batch_ui_state.focus_task_ui_state`;
|
||||
* 同时保留批次态原文,供会话上传摘要与后续同步逻辑继续消费。
|
||||
* 核心逻辑:只读取正式任务 `ui_state`;已删除的 shipping_batches 不再参与事件恢复。
|
||||
* @param data - SSE 事件 JSON
|
||||
* @returns 提炼后的单票 UI State 与原始批次 UI State
|
||||
* @returns 提炼后的单票 UI State
|
||||
*/
|
||||
export const resolveShippingUiStatePayload = (data: Record<string, unknown>): {
|
||||
uiState?: ShippingTaskUiState;
|
||||
batchUiState?: ShippingBatchUiState;
|
||||
} => {
|
||||
const rawUiState = data.ui_state;
|
||||
const uiState = rawUiState && typeof rawUiState === 'object'
|
||||
? rawUiState as ShippingTaskUiState
|
||||
: undefined;
|
||||
const rawBatchUiState = data.batch_ui_state;
|
||||
const batchUiState = rawBatchUiState && typeof rawBatchUiState === 'object'
|
||||
? rawBatchUiState as ShippingBatchUiState
|
||||
: undefined;
|
||||
const focusTaskUiState = batchUiState?.focus_task_ui_state && typeof batchUiState.focus_task_ui_state === 'object'
|
||||
? batchUiState.focus_task_ui_state
|
||||
: undefined;
|
||||
return {
|
||||
uiState: uiState || focusTaskUiState,
|
||||
batchUiState,
|
||||
uiState,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -145,7 +135,7 @@ export const resolveShippingUiStatePayload = (data: Record<string, unknown>): {
|
||||
* 不再把 action_buttons 挂到聊天消息(履约写操作改由任务处理工作台承接)。
|
||||
*/
|
||||
export const applyShippingUiStateToMessage = (msg: ChatMessage, data: Record<string, unknown>) => {
|
||||
const { uiState, batchUiState } = resolveShippingUiStatePayload(data);
|
||||
const { uiState } = resolveShippingUiStatePayload(data);
|
||||
if (!uiState) return;
|
||||
|
||||
msg.shipping_ui_state = uiState;
|
||||
@@ -156,7 +146,6 @@ export const applyShippingUiStateToMessage = (msg: ChatMessage, data: Record<str
|
||||
msg.payload = {
|
||||
...(msg.payload && typeof msg.payload === 'object' ? msg.payload as Record<string, unknown> : {}),
|
||||
shipping_ui_state: uiState,
|
||||
...(batchUiState ? { shipping_batch_ui_state: batchUiState } : {}),
|
||||
};
|
||||
};
|
||||
|
||||
@@ -602,7 +591,7 @@ export function useChat() {
|
||||
| { type: 'image' | 'document' | 'audio' | 'video' | 'custom'; transfer_method: 'local_file'; upload_file_id: string }
|
||||
| { type: 'image' | 'document' | 'audio' | 'video' | 'custom'; transfer_method: 'remote_url'; url: string }
|
||||
>,
|
||||
context?: { task_id?: string; batch_no?: string; shipping_temporary_inventory_asset_no?: string; shipping_temporary_inventory_session_no?: string; display_query?: string },
|
||||
context?: { task_id?: string; shipping_temporary_inventory_asset_no?: string; shipping_temporary_inventory_session_no?: string; display_query?: string },
|
||||
hooks?: SendMessageLifecycleHooks,
|
||||
): Promise<ChatMessageSendResult> => {
|
||||
const displayQuery = String(
|
||||
@@ -669,7 +658,6 @@ export function useChat() {
|
||||
kb_type: kbType,
|
||||
files: files && files.length > 0 ? files : undefined,
|
||||
task_id: context?.task_id || undefined,
|
||||
batch_no: context?.batch_no || undefined,
|
||||
shipping_temporary_inventory_asset_no: context?.shipping_temporary_inventory_asset_no || undefined,
|
||||
shipping_temporary_inventory_session_no: context?.shipping_temporary_inventory_session_no || undefined,
|
||||
display_query: context && Object.prototype.hasOwnProperty.call(context, 'display_query')
|
||||
|
||||
@@ -35,7 +35,6 @@ import { useChatStore } from '../stores/chat.store';
|
||||
import { useTrainingWorkspace } from './useTrainingWorkspace';
|
||||
import { matchesTrainingAgent } from '../training/trainingWorkspace.utils';
|
||||
import { hasActiveRunningChatRun } from '../shipping/shippingActionBusy';
|
||||
import { clearPendingNoticeBatchRetry } from '../shipping/useChatShippingUploadHandler';
|
||||
import {
|
||||
createChatPageConversationApi,
|
||||
createChatPageLocalMessageApi,
|
||||
@@ -195,7 +194,7 @@ export function useChatPage() {
|
||||
}, { immediate: true });
|
||||
|
||||
const dialogs = useChatPageDialogs(messages);
|
||||
const { openDeleteConfirmDialog, openRetryFailedConfirm, showShippingToast } = dialogs;
|
||||
const { openDeleteConfirmDialog } = dialogs;
|
||||
|
||||
let loadConversation: (id: string, options?: { force?: boolean }) => Promise<void>;
|
||||
let startNewChat: () => void;
|
||||
@@ -330,35 +329,6 @@ export function useChatPage() {
|
||||
|| procurement.allowsSendWithAttachmentsOnly.value,
|
||||
);
|
||||
|
||||
/**
|
||||
* 打开批次失败重试确认弹窗(会话摘要场景的兜底入口)。
|
||||
*/
|
||||
const openRetryFailedConfirmDialog = () => {
|
||||
openRetryFailedConfirm(() => confirmRetryFailedTasks());
|
||||
};
|
||||
|
||||
/**
|
||||
* 确认后执行批次失败任务重试,并以非阻塞 toast 反馈结果。
|
||||
* 核心逻辑:调用 useChatShipping.retryCurrentShippingBatchPendingTasks,成功后刷新已内置;仅补 toast。
|
||||
*/
|
||||
const retryingShippingPendingTasks = ref(false);
|
||||
const confirmRetryFailedTasks = async () => {
|
||||
if (retryingShippingPendingTasks.value) return;
|
||||
retryingShippingPendingTasks.value = true;
|
||||
try {
|
||||
const result = await shipping.retryCurrentShippingBatchPendingTasks();
|
||||
if (!result) return;
|
||||
showShippingToast(
|
||||
t('chat.shippingNoticeUi.retryFailedStarted', {
|
||||
started: result.started,
|
||||
skipped: result.skipped,
|
||||
}),
|
||||
);
|
||||
} finally {
|
||||
retryingShippingPendingTasks.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const conversationApi = createChatPageConversationApi({
|
||||
deps,
|
||||
route,
|
||||
@@ -370,13 +340,11 @@ export function useChatPage() {
|
||||
isThinking,
|
||||
loadConversationState,
|
||||
createNewChatView,
|
||||
clearPendingNoticeBatchRetry,
|
||||
onConversationIdChanging: shipping.onConversationIdChanging,
|
||||
onConversationLoadedEmpty: shipping.onConversationLoadedEmpty,
|
||||
onConversationLoadFailed: shipping.onConversationLoadFailed,
|
||||
isShippingNoticeAgent: shipping.isShippingNoticeAgent,
|
||||
shippingTaskIdFromQuery: shipping.shippingTaskIdFromQuery,
|
||||
shippingBatchNoFromQuery: shipping.shippingBatchNoFromQuery,
|
||||
clearHistory,
|
||||
clearAttachments: attachmentApi.clearAttachments,
|
||||
input,
|
||||
@@ -498,7 +466,6 @@ export function useChatPage() {
|
||||
currentAgentId,
|
||||
presetQuestion,
|
||||
shippingTaskIdFromQuery: shipping.shippingTaskIdFromQuery,
|
||||
shippingBatchNoFromQuery: shipping.shippingBatchNoFromQuery,
|
||||
isShippingNoticeAgent: shipping.isShippingNoticeAgent,
|
||||
resetChatStateForAgentChange,
|
||||
cancelVoiceInput: voice.cancelVoiceInput,
|
||||
@@ -639,11 +606,6 @@ export function useChatPage() {
|
||||
deleteConfirmMessage: dialogs.deleteConfirmMessage,
|
||||
closeDeleteConfirmDialog: dialogs.closeDeleteConfirmDialog,
|
||||
handleDeleteConfirm: dialogs.handleDeleteConfirm,
|
||||
showRetryFailedConfirmDialog: dialogs.showRetryFailedConfirmDialog,
|
||||
closeRetryFailedConfirm: dialogs.closeRetryFailedConfirm,
|
||||
handleRetryFailedConfirm: dialogs.handleRetryFailedConfirm,
|
||||
openRetryFailedConfirm: openRetryFailedConfirmDialog,
|
||||
retryingShippingPendingTasks,
|
||||
shippingToastMessage: dialogs.shippingToastMessage,
|
||||
clearShippingToast: dialogs.clearShippingToast,
|
||||
showChatRating,
|
||||
@@ -655,10 +617,6 @@ export function useChatPage() {
|
||||
clearProcurementOriginalContract: procurement.clearOriginalContract,
|
||||
showShippingProgressWorkspace: shipping.showShippingProgressWorkspace,
|
||||
clearShippingFocus: shipping.clearShippingFocus,
|
||||
shippingBatchSummary: shipping.shippingBatchSummary,
|
||||
shippingConversationWorkspace: shipping.shippingConversationWorkspace,
|
||||
activeShippingBatchNo: shipping.activeShippingBatchNo,
|
||||
shippingBatchTasks: shipping.shippingBatchTasks,
|
||||
activeShippingTaskDetail: shipping.activeShippingTaskDetail,
|
||||
getActiveOrderExtractionRunNo: shipping.getActiveOrderExtractionRunNo,
|
||||
workflowRefreshTrigger: shipping.workflowRefreshTrigger,
|
||||
@@ -667,8 +625,6 @@ export function useChatPage() {
|
||||
setFocusedConversationTaskNo: shipping.setFocusedConversationTaskNo,
|
||||
shippingInventorySelectionActive: shipping.shippingInventorySelectionActive,
|
||||
shippingInventorySelectionTaskId: shipping.shippingInventorySelectionTaskId,
|
||||
switchShippingBatch: shipping.switchShippingBatch,
|
||||
retryCurrentShippingBatchPendingTasks: shipping.retryCurrentShippingBatchPendingTasks,
|
||||
queryShippingShortageDetails: shipping.queryShippingShortageDetails,
|
||||
selectShippingInventoryUploadTask: shipping.selectShippingInventoryUploadTask,
|
||||
cancelShippingInventoryTaskSelection: shipping.cancelShippingInventoryTaskSelection,
|
||||
|
||||
@@ -13,7 +13,6 @@ export interface UseChatRouteSyncOptions {
|
||||
currentAgentId: ComputedRef<number>;
|
||||
presetQuestion: ComputedRef<string>;
|
||||
shippingTaskIdFromQuery: ComputedRef<string | null>;
|
||||
shippingBatchNoFromQuery?: ComputedRef<string | null>;
|
||||
isShippingNoticeAgent: ComputedRef<boolean>;
|
||||
resetChatStateForAgentChange: () => void;
|
||||
cancelVoiceInput: () => void;
|
||||
@@ -39,7 +38,6 @@ export function useChatRouteSync(options: UseChatRouteSyncOptions) {
|
||||
currentAgentId,
|
||||
presetQuestion,
|
||||
shippingTaskIdFromQuery,
|
||||
shippingBatchNoFromQuery,
|
||||
resetChatStateForAgentChange,
|
||||
cancelVoiceInput,
|
||||
syncCurrentUserProfile,
|
||||
@@ -103,7 +101,7 @@ export function useChatRouteSync(options: UseChatRouteSyncOptions) {
|
||||
loadConversation(convId, { force: true }),
|
||||
]);
|
||||
if (syncToken !== routeSyncToken) return;
|
||||
} else if (shippingTaskIdFromQuery.value || shippingBatchNoFromQuery?.value) {
|
||||
} else if (shippingTaskIdFromQuery.value) {
|
||||
await historyPromise;
|
||||
if (syncToken !== routeSyncToken) return;
|
||||
await resumeShippingTaskFromQuery();
|
||||
@@ -129,17 +127,16 @@ export function useChatRouteSync(options: UseChatRouteSyncOptions) {
|
||||
});
|
||||
|
||||
watch(
|
||||
() => [route.params.agentId, route.query.conversation_id, route.query.preset, route.query.task_id, route.query.batch_no],
|
||||
() => [route.params.agentId, route.query.conversation_id, route.query.preset, route.query.task_id],
|
||||
async (
|
||||
[nextAgentId, nextConversationId, nextPreset, nextTaskId, nextBatchNo],
|
||||
[prevAgentId, prevConversationId, prevPreset, prevTaskId, prevBatchNo],
|
||||
[nextAgentId, nextConversationId, nextPreset, nextTaskId],
|
||||
[prevAgentId, prevConversationId, prevPreset, prevTaskId],
|
||||
) => {
|
||||
if (
|
||||
nextAgentId === prevAgentId
|
||||
&& nextConversationId === prevConversationId
|
||||
&& nextPreset === prevPreset
|
||||
&& nextTaskId === prevTaskId
|
||||
&& nextBatchNo === prevBatchNo
|
||||
) {
|
||||
return;
|
||||
}
|
||||
@@ -148,7 +145,6 @@ export function useChatRouteSync(options: UseChatRouteSyncOptions) {
|
||||
nextAgentId === prevAgentId
|
||||
&& nextPreset === prevPreset
|
||||
&& nextTaskId === prevTaskId
|
||||
&& nextBatchNo === prevBatchNo
|
||||
&& nextConversationId !== prevConversationId
|
||||
) {
|
||||
if (typeof nextConversationId === 'string' && nextConversationId) {
|
||||
|
||||
@@ -1,150 +1,36 @@
|
||||
/**
|
||||
* features/chat/composables/useChatShipping.spec.ts
|
||||
* 用途:验证发货批次切换后的默认焦点解析,避免右侧工作台沿用旧批次的 focused task。
|
||||
* 用途:验证聊天恢复只使用单票任务锚点。
|
||||
* 依赖:vitest、useChatShipping 纯函数导出。
|
||||
* 逻辑:覆盖 current focus、process summary 回退、首票回退与无任务时清空焦点原因四种路径。
|
||||
* 逻辑:历史回放只接受 task_no / shipping_ui_state,不恢复已下线批次快照。
|
||||
*/
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
resolveLatestShippingMessageRecoveryPayload,
|
||||
resolveLatestShippingBatchSnapshot,
|
||||
resolveShippingBatchFocusState,
|
||||
selectShippingConversationBatch,
|
||||
} from './useChatShipping';
|
||||
|
||||
describe('useChatShipping batch focus sync', () => {
|
||||
it('prefers batch current focus task and keeps default reason', () => {
|
||||
expect(resolveShippingBatchFocusState(
|
||||
{
|
||||
current_focus_task_no: 'SN-BATCH-B2',
|
||||
process_summary: { current_task_no: 'SN-BATCH-B1' },
|
||||
},
|
||||
[{ task_no: 'SN-BATCH-B0' }],
|
||||
'当前聚焦任务',
|
||||
)).toEqual({
|
||||
taskNo: 'SN-BATCH-B2',
|
||||
focusReason: '当前聚焦任务',
|
||||
});
|
||||
});
|
||||
|
||||
it('falls back to process summary and first task when current focus is absent', () => {
|
||||
expect(resolveShippingBatchFocusState(
|
||||
{
|
||||
current_focus_task_no: '',
|
||||
process_summary: { current_task_no: 'SN-BATCH-C1' },
|
||||
},
|
||||
[{ task_no: 'SN-BATCH-C0' }],
|
||||
'当前聚焦任务',
|
||||
)).toEqual({
|
||||
taskNo: 'SN-BATCH-C1',
|
||||
focusReason: '当前聚焦任务',
|
||||
});
|
||||
|
||||
expect(resolveShippingBatchFocusState(
|
||||
{
|
||||
current_focus_task_no: '',
|
||||
process_summary: { current_task_no: '' },
|
||||
},
|
||||
[{ task_no: 'SN-BATCH-D0' }],
|
||||
'当前聚焦任务',
|
||||
)).toEqual({
|
||||
taskNo: 'SN-BATCH-D0',
|
||||
focusReason: '当前聚焦任务',
|
||||
});
|
||||
});
|
||||
|
||||
it('clears focus state when the new batch has no resolvable task', () => {
|
||||
expect(resolveShippingBatchFocusState(
|
||||
{
|
||||
current_focus_task_no: '',
|
||||
process_summary: { current_task_no: '' },
|
||||
},
|
||||
[],
|
||||
'当前聚焦任务',
|
||||
)).toEqual({
|
||||
taskNo: '',
|
||||
focusReason: '',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('useChatShipping conversation workspace selection', () => {
|
||||
const batches = [
|
||||
{ batch_no: 'SB-OLD', focus_task: { task_no: 'SN-OLD' } },
|
||||
{ batch_no: 'SB-NEW', focus_task: { task_no: 'SN-NEW' } },
|
||||
];
|
||||
|
||||
it('keeps the active batch during a normal refresh', () => {
|
||||
expect(selectShippingConversationBatch(batches, 'SB-OLD', '', false)?.batch_no).toBe('SB-OLD');
|
||||
});
|
||||
|
||||
it('selects the latest batch after an order extraction turn', () => {
|
||||
expect(selectShippingConversationBatch(batches, 'SB-OLD', '', true)?.batch_no).toBe('SB-NEW');
|
||||
});
|
||||
});
|
||||
|
||||
describe('useChatShipping persisted batch snapshot', () => {
|
||||
it('restores the latest valid batch snapshot from assistant message payloads', () => {
|
||||
const snapshot = resolveLatestShippingBatchSnapshot([
|
||||
{
|
||||
role: 'assistant',
|
||||
content: '旧结果',
|
||||
payload: { shipping_batch_ui_state: { batch_no: 'SB-OLD', tasks: [] } },
|
||||
},
|
||||
{
|
||||
role: 'assistant',
|
||||
content: '无效结果',
|
||||
payload: { shipping_batch_ui_state: { batch_no: 'SB-INVALID' } },
|
||||
},
|
||||
{
|
||||
role: 'assistant',
|
||||
content: '已打开已有任务',
|
||||
payload: {
|
||||
shipping_batch_ui_state: {
|
||||
batch_no: 'SB-EXISTING',
|
||||
current_focus_task_no: 'SN-EXISTING',
|
||||
tasks: [{ task_no: 'SN-EXISTING', source_type: 'email', review_status: 'parse_review' }],
|
||||
},
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
expect(snapshot?.batch_no).toBe('SB-EXISTING');
|
||||
expect(snapshot?.current_focus_task_no).toBe('SN-EXISTING');
|
||||
});
|
||||
|
||||
it('ignores malformed snapshots', () => {
|
||||
expect(resolveLatestShippingBatchSnapshot([
|
||||
{ role: 'assistant', content: '', payload: { shipping_batch_ui_state: { batch_no: 'SB-NO-TASKS' } } },
|
||||
{ role: 'user', content: '继续' },
|
||||
])).toBeNull();
|
||||
});
|
||||
});
|
||||
import { resolveLatestShippingMessageRecoveryPayload } from './useChatShipping';
|
||||
|
||||
describe('useChatShipping message recovery payload', () => {
|
||||
it('falls back to task anchor when batch snapshot is absent', () => {
|
||||
it('recovers a task anchor and read-only UI state', () => {
|
||||
const payload = resolveLatestShippingMessageRecoveryPayload([
|
||||
{
|
||||
role: 'assistant',
|
||||
content: '已打开已有任务',
|
||||
payload: {
|
||||
task_no: 'SN-OPEN-EXISTING',
|
||||
batch_no: 'SB-OPEN-EXISTING',
|
||||
shipping_ui_state: {
|
||||
task_no: 'SN-OPEN-EXISTING',
|
||||
batch_no: 'SB-OPEN-EXISTING',
|
||||
inventory_lines_json: [{ reservation_id: 'R-1' }],
|
||||
steps: [],
|
||||
summary: {},
|
||||
action_buttons: [],
|
||||
},
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
expect(payload?.task_no).toBe('SN-OPEN-EXISTING');
|
||||
expect(payload?.batch_no).toBe('SB-OPEN-EXISTING');
|
||||
expect(payload?.shipping_ui_state?.task_no).toBe('SN-OPEN-EXISTING');
|
||||
expect(payload?.shipping_batch_ui_state).toBeUndefined();
|
||||
});
|
||||
|
||||
it('ignores a legacy batch-only payload', () => {
|
||||
expect(resolveLatestShippingMessageRecoveryPayload([
|
||||
{ role: 'assistant', content: '', payload: { shipping_batch_ui_state: { tasks: [] } } },
|
||||
])).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -3,9 +3,8 @@
|
||||
* 用途:发货通知聊天编排入口,组合 shipping/* 子模块并对 ChatView 暴露统一交互能力。
|
||||
* 依赖: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 供调用方兼容,不再发起批次网络请求。
|
||||
* 以及 focusedConversationTaskNo(提交追加优先级 / 侧栏焦点)。会话恢复唯一使用 task_no;
|
||||
* 批次进度由 shipping-processing projection 承接,不维护已下线 shipping_batches 的本地快照。
|
||||
*/
|
||||
|
||||
import {
|
||||
@@ -31,7 +30,6 @@ import {
|
||||
createShippingSendHandlers,
|
||||
createShippingUploadHandlers,
|
||||
useShippingOrderExtractionRuns,
|
||||
onNoticeBatchConversationChanging,
|
||||
findLatestShippingTaskId,
|
||||
getShippingMatchResultPayload,
|
||||
getShippingParseReviewPayload,
|
||||
@@ -43,13 +41,9 @@ import {
|
||||
getWorkspaceShippingTask,
|
||||
listWorkspaceShippingCustomerOptions,
|
||||
confirmWorkspaceShippingCustomer,
|
||||
type ShippingConversationWorkspace,
|
||||
type ShippingTaskDetail,
|
||||
type ShippingTaskSummary,
|
||||
} from '@/features/chat/api/shipping.api';
|
||||
import type {
|
||||
ShippingBatchSummary,
|
||||
ShippingBatchUiState,
|
||||
ShippingCustomerOption,
|
||||
} from '../types/shipping.api.types';
|
||||
import { buildShippingQueryShortageTurn } from '../shipping/shippingTurnActions';
|
||||
@@ -91,7 +85,7 @@ export interface UseChatShippingOptions {
|
||||
agentId: number,
|
||||
kb: string,
|
||||
files: ChatUploadFileSpec[],
|
||||
context?: { task_id?: string; batch_no?: string; shipping_temporary_inventory_asset_no?: string; shipping_temporary_inventory_session_no?: string; display_query?: string },
|
||||
context?: { task_id?: string; shipping_temporary_inventory_asset_no?: string; shipping_temporary_inventory_session_no?: string; display_query?: string },
|
||||
hooks?: SendMessageLifecycleHooks,
|
||||
) => Promise<ChatMessageSendResult>;
|
||||
startChatTurn: (options: import('../types/chat-turn.types').StartChatTurnOptions) => Promise<boolean>;
|
||||
@@ -100,78 +94,9 @@ export interface UseChatShippingOptions {
|
||||
createNewChatView: () => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析批次切换后的默认焦点状态。
|
||||
* 核心逻辑:优先取状态机记录的 current focus,其次回退到 process summary 当前任务,再回退到任务列表首票;只有拿到 task_no 才回填默认聚焦原因。
|
||||
* @param batchSummary - 当前批次摘要
|
||||
* @param batchTasks - 当前批次任务列表
|
||||
* @param defaultReason - 批次切换后写入输入栏提示的默认焦点原因
|
||||
* @returns 供步骤条、按钮与右侧工作台共用的 focus 状态;取不到 task 时返回空焦点
|
||||
*/
|
||||
export const resolveShippingBatchFocusState = (
|
||||
batchSummary: {
|
||||
current_focus_task_no?: string | null;
|
||||
process_summary?: { current_task_no?: string | null } | null;
|
||||
} | null | undefined,
|
||||
batchTasks: Array<{ task_no?: string | null }> | null | undefined,
|
||||
defaultReason: string,
|
||||
) => {
|
||||
const taskNo = String(
|
||||
batchSummary?.current_focus_task_no
|
||||
|| batchSummary?.process_summary?.current_task_no
|
||||
|| batchTasks?.[0]?.task_no
|
||||
|| '',
|
||||
).trim();
|
||||
return {
|
||||
taskNo,
|
||||
focusReason: taskNo ? defaultReason : '',
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* 从会话工作台选择本轮应展示的批次。
|
||||
* 核心逻辑:订单抽取完成后选服务端按创建时间升序返回的最后一个批次;普通续办优先保留当前批次。
|
||||
*/
|
||||
export const selectShippingConversationBatch = <T extends { batch_no: string; focus_task?: unknown }>(
|
||||
batches: T[],
|
||||
currentBatchNo: string,
|
||||
queryBatchNo: string,
|
||||
preferLatest = false,
|
||||
): T | undefined => (
|
||||
(preferLatest ? batches[batches.length - 1] : undefined)
|
||||
|| batches.find((item) => item.batch_no === currentBatchNo)
|
||||
|| (queryBatchNo ? batches.find((item) => item.batch_no === queryBatchNo) : undefined)
|
||||
|| batches.find((item) => Boolean(item.focus_task))
|
||||
|| batches[0]
|
||||
);
|
||||
|
||||
/**
|
||||
* 从消息列表解析最近一次权威批次快照。
|
||||
* 核心逻辑:只接受包含批次号和任务数组的 `shipping_batch_ui_state`,供实时终态与历史会话共用。
|
||||
* @param sourceMessages - 当前会话消息
|
||||
* @returns 最近的合法批次快照;不存在时返回 null
|
||||
*/
|
||||
export const resolveLatestShippingBatchSnapshot = (
|
||||
sourceMessages: ChatMessage[],
|
||||
): ShippingBatchUiState | null => {
|
||||
for (let index = sourceMessages.length - 1; index >= 0; index -= 1) {
|
||||
const message = sourceMessages[index];
|
||||
const payload = message?.payload && typeof message.payload === 'object'
|
||||
? message.payload as Record<string, unknown>
|
||||
: null;
|
||||
const rawSnapshot = payload?.shipping_batch_ui_state;
|
||||
if (!rawSnapshot || typeof rawSnapshot !== 'object') continue;
|
||||
const snapshot = rawSnapshot as ShippingBatchUiState;
|
||||
if (String(snapshot.batch_no || '').trim() && Array.isArray(snapshot.tasks)) {
|
||||
return snapshot;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
/**
|
||||
* 从单条助手消息中提取工作台恢复锚点。
|
||||
* 核心逻辑:优先识别合法 `shipping_batch_ui_state`,其次回退到 `task_no / batch_no / shipping_ui_state`;
|
||||
* 核心逻辑:只接受 `task_no / shipping_ui_state`;
|
||||
* 供实时终态、历史回放与刷新恢复共用。
|
||||
*/
|
||||
export const resolveShippingMessageRecoveryPayload = (
|
||||
@@ -181,34 +106,18 @@ export const resolveShippingMessageRecoveryPayload = (
|
||||
? message.payload as ShippingMessageRecoveryPayload
|
||||
: null;
|
||||
if (!payload) return null;
|
||||
const batchSnapshot = payload.shipping_batch_ui_state;
|
||||
const hasBatchSnapshot = Boolean(
|
||||
batchSnapshot
|
||||
&& String(batchSnapshot.batch_no || '').trim()
|
||||
&& Array.isArray(batchSnapshot.tasks),
|
||||
);
|
||||
const taskNo = String(
|
||||
payload.task_no
|
||||
|| payload.shipping_ui_state?.task_no
|
||||
|| batchSnapshot?.current_focus_task_no
|
||||
|| batchSnapshot?.focus_task?.task_no
|
||||
|| batchSnapshot?.tasks?.[0]?.task_no
|
||||
|| '',
|
||||
).trim();
|
||||
const batchNo = String(
|
||||
payload.batch_no
|
||||
|| payload.shipping_ui_state?.batch_no
|
||||
|| batchSnapshot?.batch_no
|
||||
|| '',
|
||||
).trim();
|
||||
const hasTaskUiState = Boolean(payload.shipping_ui_state && typeof payload.shipping_ui_state === 'object');
|
||||
if (!hasBatchSnapshot && !taskNo && !batchNo && !hasTaskUiState) {
|
||||
if (!taskNo && !hasTaskUiState) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
...payload,
|
||||
...(taskNo ? { task_no: taskNo } : {}),
|
||||
...(batchNo ? { batch_no: batchNo } : {}),
|
||||
};
|
||||
};
|
||||
|
||||
@@ -288,160 +197,34 @@ 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() : '';
|
||||
});
|
||||
const shippingBatchNoFromQuery = computed(() => {
|
||||
const value = route.query.batch_no;
|
||||
return typeof value === 'string' ? value.trim() : '';
|
||||
});
|
||||
const resolvedShippingTaskId = ref('');
|
||||
const resolvedShippingBatchNo = ref('');
|
||||
const activeShippingBatchNo = ref('');
|
||||
const shippingConversationWorkspace = ref<ShippingConversationWorkspace | null>(null);
|
||||
const shippingBatchSummary = ref<ShippingBatchSummary | null>(null);
|
||||
const shippingBatchTasks = ref<ShippingTaskSummary[]>([]);
|
||||
const activeShippingTaskDetail = ref<ShippingTaskDetail | null>(null);
|
||||
const autoResumedShippingTasks = ref<Record<string, boolean>>({});
|
||||
const lastConversationSyncKey = ref('');
|
||||
let shippingStatusPollTimer: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
const applyShippingBatchDetail = (
|
||||
detail: ShippingBatchUiState,
|
||||
fallbackBatchNo: string,
|
||||
) => {
|
||||
const normalizedBatchNo = detail.batch_no || fallbackBatchNo;
|
||||
resolvedShippingBatchNo.value = normalizedBatchNo;
|
||||
if (!activeShippingBatchNo.value || activeShippingBatchNo.value === fallbackBatchNo) {
|
||||
activeShippingBatchNo.value = normalizedBatchNo;
|
||||
}
|
||||
shippingBatchTasks.value = Array.isArray(detail.tasks) ? detail.tasks : [];
|
||||
shippingBatchSummary.value = {
|
||||
id: detail.id,
|
||||
batch_no: detail.batch_no,
|
||||
conversation_id: detail.conversation_id,
|
||||
current_focus_task_no: detail.focus_task?.task_no || detail.current_focus_task_no || null,
|
||||
file_count: detail.file_count,
|
||||
process_summary: detail.process_summary || null,
|
||||
created_at: detail.created_at,
|
||||
updated_at: detail.updated_at,
|
||||
};
|
||||
const preferredTaskNo = String(
|
||||
detail.focus_task?.task_no
|
||||
|| detail.process_summary?.current_task_no
|
||||
|| detail.current_focus_task_no
|
||||
|| '',
|
||||
).trim();
|
||||
if (preferredTaskNo) {
|
||||
resolvedShippingTaskId.value = preferredTaskNo;
|
||||
}
|
||||
if (detail.focus_task && detail.focus_task_ui_state) {
|
||||
activeShippingTaskDetail.value = {
|
||||
...(activeShippingTaskDetail.value || {}),
|
||||
...detail.focus_task,
|
||||
lines: activeShippingTaskDetail.value?.lines || [],
|
||||
events: activeShippingTaskDetail.value?.events || [],
|
||||
ui_state: detail.focus_task_ui_state,
|
||||
} as ShippingTaskDetail;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 同步批次摘要占位(co8 已下线批次详情 API)。
|
||||
* 按任务锚点恢复聊天工作台。
|
||||
*
|
||||
* 核心逻辑:batchNo 为空时清空摘要;否则仅回填本地 batch_no 与已有 task 焦点,不发起网络请求。
|
||||
* @param batchNo - 目标批次号
|
||||
*/
|
||||
const syncShippingBatchSummary = async (batchNo: string) => {
|
||||
const normalized = String(batchNo || '').trim();
|
||||
if (!normalized) {
|
||||
shippingBatchSummary.value = null;
|
||||
shippingBatchTasks.value = [];
|
||||
return;
|
||||
}
|
||||
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,
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* 同步会话批次工作台(co8 已下线 conversation batches API)。
|
||||
*
|
||||
* 核心逻辑:保留调用签名供抽取 Run / 终态刷新链路兼容;始终清空 workspace 并返回 false,不发起网络。
|
||||
* @param _options - 历史参数,保留兼容
|
||||
* @returns 恒为 false
|
||||
*/
|
||||
const syncShippingConversationWorkspace = async (
|
||||
_options?: { preferLatest?: boolean },
|
||||
): Promise<boolean> => {
|
||||
void _options;
|
||||
shippingConversationWorkspace.value = null;
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* 从本轮 SSE 助手消息恢复权威批次快照。
|
||||
*
|
||||
* 核心逻辑:订单识别可能打开属于旧会话的已有任务,此时按当前会话补拉工作台会返回空批次;
|
||||
* 优先应用 `shipping_ui_state` 事件随消息持久化的 `shipping_batch_ui_state`,再由接口刷新后续状态。
|
||||
* @param message - 当前流式回答完成后的助手消息
|
||||
* @returns 是否找到并应用了合法批次快照
|
||||
*/
|
||||
const applyResolvedShippingBatchSnapshot = (snapshot: ShippingBatchUiState | null): boolean => {
|
||||
if (!snapshot) return false;
|
||||
const batchNo = String(snapshot.batch_no || '').trim();
|
||||
applyShippingBatchDetail(snapshot, batchNo);
|
||||
return true;
|
||||
};
|
||||
|
||||
const applyShippingBatchSnapshot = (message: ChatMessage): boolean => (
|
||||
applyResolvedShippingBatchSnapshot(resolveLatestShippingBatchSnapshot([message]))
|
||||
);
|
||||
|
||||
/**
|
||||
* 按“批次快照 -> 任务/批次锚点 -> 会话工作台”顺序恢复聊天工作台。
|
||||
*
|
||||
* 核心逻辑:`open_existing` 可能只携带 `task_no / shipping_ui_state`;此时先恢复任务锚点并补拉任务详情,
|
||||
* 再尝试按任务所属批次加载批次详情,最后才回退到当前会话工作台。
|
||||
* 核心逻辑:`open_existing` 携带 `task_no / shipping_ui_state`;恢复任务锚点后补拉任务详情。
|
||||
* @param payload - 从消息中解析出的恢复载荷
|
||||
* @returns 是否至少恢复出一层任务或批次上下文
|
||||
* @returns 是否恢复出任务上下文
|
||||
*/
|
||||
const applyResolvedShippingMessageRecovery = async (
|
||||
payload: ShippingMessageRecoveryPayload | null,
|
||||
): Promise<boolean> => {
|
||||
if (!payload) return false;
|
||||
let recovered = false;
|
||||
const snapshot = payload.shipping_batch_ui_state ?? null;
|
||||
if (applyResolvedShippingBatchSnapshot(snapshot)) {
|
||||
recovered = true;
|
||||
}
|
||||
|
||||
const taskNo = String(
|
||||
payload.task_no
|
||||
|| payload.shipping_ui_state?.task_no
|
||||
|| '',
|
||||
).trim().toUpperCase();
|
||||
let batchNo = String(
|
||||
payload.batch_no
|
||||
|| payload.shipping_ui_state?.batch_no
|
||||
|| snapshot?.batch_no
|
||||
|| '',
|
||||
).trim();
|
||||
|
||||
if (batchNo) {
|
||||
resolvedShippingBatchNo.value = batchNo;
|
||||
activeShippingBatchNo.value = batchNo;
|
||||
}
|
||||
if (taskNo) {
|
||||
resolvedShippingTaskId.value = taskNo;
|
||||
}
|
||||
@@ -449,52 +232,23 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
activeShippingTaskDetail.value = {
|
||||
...(activeShippingTaskDetail.value || {}),
|
||||
task_no: taskNo,
|
||||
batch_no: batchNo || payload.shipping_ui_state.batch_no || null,
|
||||
lines: activeShippingTaskDetail.value?.lines || [],
|
||||
events: activeShippingTaskDetail.value?.events || [],
|
||||
ui_state: payload.shipping_ui_state,
|
||||
} as ShippingTaskDetail;
|
||||
recovered = true;
|
||||
}
|
||||
if (!snapshot && batchNo) {
|
||||
await syncShippingBatchSummary(batchNo);
|
||||
recovered = true;
|
||||
}
|
||||
if (taskNo) {
|
||||
await syncActiveShippingTaskDetail(taskNo);
|
||||
const detailBatchNo = String(activeShippingTaskDetail.value?.batch_no || '').trim();
|
||||
if (detailBatchNo) {
|
||||
batchNo = detailBatchNo;
|
||||
resolvedShippingBatchNo.value = detailBatchNo;
|
||||
activeShippingBatchNo.value = detailBatchNo;
|
||||
}
|
||||
if (!snapshot && batchNo && String(shippingBatchSummary.value?.batch_no || '').trim() !== batchNo) {
|
||||
await syncShippingBatchSummary(batchNo);
|
||||
recovered = true;
|
||||
}
|
||||
recovered = recovered || Boolean(activeShippingTaskDetail.value);
|
||||
}
|
||||
return recovered || Boolean(batchNo);
|
||||
return recovered;
|
||||
};
|
||||
|
||||
const applyShippingMessageRecovery = async (message: ChatMessage): Promise<boolean> => (
|
||||
applyResolvedShippingMessageRecovery(resolveShippingMessageRecoveryPayload(message))
|
||||
);
|
||||
|
||||
/**
|
||||
* 切换会话上传摘要中的活动批次(co8 已下线,保留签名兼容)。
|
||||
*
|
||||
* 核心逻辑:批次工作台 API 已移除,调用时仅提示用户改由右侧 processing 工作台操作。
|
||||
* @param batchNo - 目标批次号
|
||||
* @returns 恒为 false
|
||||
*/
|
||||
const switchShippingBatch = async (batchNo: string) => {
|
||||
const normalizedBatchNo = String(batchNo || '').trim();
|
||||
if (!normalizedBatchNo) return false;
|
||||
msg.warning(t('chat.shippingNoticeUi.batchSwitchRemoved'));
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* 清空当前聊天页绑定的发货任务上下文。
|
||||
*
|
||||
@@ -512,11 +266,6 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
shippingInventorySelectionActive.value = false;
|
||||
shippingInventorySelectionTaskId.value = '';
|
||||
resolvedShippingTaskId.value = '';
|
||||
resolvedShippingBatchNo.value = '';
|
||||
activeShippingBatchNo.value = '';
|
||||
shippingConversationWorkspace.value = null;
|
||||
shippingBatchSummary.value = null;
|
||||
shippingBatchTasks.value = [];
|
||||
activeShippingTaskDetail.value = null;
|
||||
lastConversationSyncKey.value = '';
|
||||
};
|
||||
@@ -527,16 +276,8 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
|| shippingTaskIdFromQuery.value
|
||||
|| '';
|
||||
|
||||
const getActiveShippingBatchNo = () =>
|
||||
activeShippingBatchNo.value
|
||||
|| resolvedShippingBatchNo.value
|
||||
|| shippingBatchNoFromQuery.value
|
||||
|| String(shippingBatchSummary.value?.batch_no || '').trim()
|
||||
|| '';
|
||||
|
||||
const getCurrentShippingChatContext = () => ({
|
||||
task_id: getActiveBatchTaskId() || getActiveShippingTaskId(),
|
||||
batch_no: getActiveShippingBatchNo(),
|
||||
task_id: getActiveShippingTaskId(),
|
||||
});
|
||||
|
||||
const getCurrentShippingChatContextWithDisplay = (displayQuery: string) => ({
|
||||
@@ -544,23 +285,10 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
display_query: displayQuery,
|
||||
});
|
||||
|
||||
const getActiveBatchTaskId = () => String(
|
||||
shippingBatchSummary.value?.current_focus_task_no
|
||||
|| shippingBatchSummary.value?.process_summary?.current_task_no
|
||||
|| shippingBatchTasks.value[0]?.task_no
|
||||
|| resolvedShippingTaskId.value
|
||||
|| '',
|
||||
).trim();
|
||||
|
||||
const hasRunningShippingBatchTasks = () =>
|
||||
shippingBatchTasks.value.some(
|
||||
(task) => String(task.ui_state?.stage?.code || '').trim() !== 'upload_complete',
|
||||
);
|
||||
|
||||
/**
|
||||
* 同步当前焦点任务详情,并在仅恢复 `task_no` 的场景下补齐 `batch_no` 上下文。
|
||||
* 同步当前焦点任务详情。
|
||||
*
|
||||
* 核心逻辑:先拉取任务详情,再把详情里的批次号回填到聊天状态,确保会话恢复后仍能继续按批次模式加载 2 票/多票摘要。
|
||||
* 核心逻辑:仅拉取任务详情;批次进度由独立 processing projection 提供。
|
||||
* @param taskId - 可选任务编号;未传时回退到当前激活任务
|
||||
*/
|
||||
const syncActiveShippingTaskDetail = async (taskId?: string) => {
|
||||
@@ -571,16 +299,7 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
}
|
||||
try {
|
||||
const detail = await getWorkspaceShippingTask(normalized);
|
||||
const detailBatchNo = String(detail.batch_no || '').trim();
|
||||
const activeBatchNo = String(activeShippingBatchNo.value || '').trim();
|
||||
if (activeBatchNo && detailBatchNo && detailBatchNo !== activeBatchNo) {
|
||||
return;
|
||||
}
|
||||
activeShippingTaskDetail.value = detail;
|
||||
if (detailBatchNo && resolvedShippingBatchNo.value !== detailBatchNo) {
|
||||
resolvedShippingBatchNo.value = detailBatchNo;
|
||||
activeShippingBatchNo.value = activeShippingBatchNo.value || detailBatchNo;
|
||||
}
|
||||
} catch {
|
||||
activeShippingTaskDetail.value = null;
|
||||
}
|
||||
@@ -637,7 +356,7 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
isThinking,
|
||||
resolvedShippingTaskId,
|
||||
shippingTaskIdFromQuery,
|
||||
getActiveBatchTaskId,
|
||||
getActiveShippingTaskId,
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -649,10 +368,6 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
const finalizeShippingAssistantMessage = async () => {
|
||||
if (!isShippingNoticeAgent.value) return;
|
||||
await shippingIntakes.refreshStatuses();
|
||||
if (!(await syncShippingConversationWorkspace())) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 300));
|
||||
await syncShippingConversationWorkspace();
|
||||
}
|
||||
shippingIntakes.clearConsumedAttachments();
|
||||
await refreshShippingActions();
|
||||
};
|
||||
@@ -666,15 +381,10 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
const resolveShippingTaskForShortageQuery = async (taskNo?: string) => {
|
||||
const normalizedTaskNo = String(
|
||||
taskNo
|
||||
|| getActiveBatchTaskId()
|
||||
|| getActiveShippingTaskId()
|
||||
|| '',
|
||||
).trim().toUpperCase();
|
||||
if (!normalizedTaskNo) return null;
|
||||
const summaryTask = shippingBatchTasks.value.find(
|
||||
(item) => String(item.task_no || '').trim().toUpperCase() === normalizedTaskNo,
|
||||
);
|
||||
if (summaryTask && hasShortageLines(summaryTask)) return summaryTask;
|
||||
const detail = activeShippingTaskDetail.value;
|
||||
if (String(detail?.task_no || '').trim().toUpperCase() === normalizedTaskNo && hasShortageLines(detail)) {
|
||||
return detail;
|
||||
@@ -682,7 +392,7 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
try {
|
||||
return await getWorkspaceShippingTask(normalizedTaskNo);
|
||||
} catch {
|
||||
return summaryTask || null;
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -772,7 +482,6 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
refreshNoticeIntakeStatuses: shippingIntakes.refreshStatuses,
|
||||
getOrderExtractionReview: shippingIntakes.getOrderExtractionReview,
|
||||
clearConsumedNoticeAttachments: shippingIntakes.clearConsumedAttachments,
|
||||
syncShippingConversationWorkspace,
|
||||
refreshShippingActions,
|
||||
loadHistory,
|
||||
onConversationResolved: async (resolvedConversationId) => {
|
||||
@@ -962,6 +671,7 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
const {
|
||||
handleShippingAutoUploadFile,
|
||||
handleShippingAutoUploadNoticeBatch,
|
||||
openShippingInventoryPicker,
|
||||
openShippingNoticePicker,
|
||||
selectShippingInventoryUploadTask,
|
||||
cancelShippingInventoryTaskSelection,
|
||||
@@ -981,9 +691,6 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
pendingShippingNoticeTaskId,
|
||||
pendingShippingInventoryFile,
|
||||
resolvedShippingTaskId,
|
||||
resolvedShippingBatchNo,
|
||||
shippingBatchSummary,
|
||||
shippingBatchTasks,
|
||||
shippingInventorySelectionActive,
|
||||
shippingInventorySelectionTaskId,
|
||||
getActiveShippingTaskId,
|
||||
@@ -1013,6 +720,7 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
getActiveShippingTaskId,
|
||||
messages,
|
||||
sendShippingMenuMessage,
|
||||
openShippingInventoryPicker,
|
||||
openShippingNoticePicker,
|
||||
openShippingCustomerDialog,
|
||||
executeShippingDecision,
|
||||
@@ -1033,7 +741,6 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
attachments,
|
||||
shippingAutoFlowRequested,
|
||||
resolvedShippingTaskId,
|
||||
getActiveShippingBatchNo,
|
||||
currentAgentId,
|
||||
selectedKb,
|
||||
attachmentPolicy,
|
||||
@@ -1060,8 +767,6 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
getParsedIntakeNos: shippingIntakes.getParsedIntakeNos,
|
||||
startOrderExtractionRun: shippingOrderExtractionRuns.startRun,
|
||||
applyShippingMessageRecovery,
|
||||
applyShippingBatchSnapshot,
|
||||
syncShippingConversationWorkspace,
|
||||
refreshShippingActions,
|
||||
shippingSuggestedPrompt,
|
||||
isShippingShortageQueryIntent,
|
||||
@@ -1072,19 +777,11 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
|
||||
// ── 路由 / 会话生命周期 ───────────────────────────────────
|
||||
/**
|
||||
* 根据路由中的 `task_id/batch_no` 恢复发货任务上下文。
|
||||
* 核心逻辑:优先同步显式传入的批次摘要;若仍缺少会话,则直接基于 `task_id` 发起一次继续任务请求,
|
||||
* 禁止再按历史标题模糊猜测旧会话,避免多批次/多票场景跳进错误会话。
|
||||
* 根据路由中的 `task_id` 恢复发货任务上下文。
|
||||
* 核心逻辑:直接基于明确 task_id 发起一次继续任务请求,禁止按历史标题模糊猜测会话。
|
||||
* @returns Promise<void>
|
||||
*/
|
||||
const resumeShippingTaskFromQuery = async () => {
|
||||
const batchNo = shippingBatchNoFromQuery.value;
|
||||
if (batchNo && isShippingNoticeAgent.value) {
|
||||
await syncShippingBatchSummary(batchNo);
|
||||
if (!shippingTaskIdFromQuery.value && resolvedShippingTaskId.value) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
const taskId = shippingTaskIdFromQuery.value;
|
||||
if (!taskId || !isShippingNoticeAgent.value) return;
|
||||
if (route.query.conversation_id) return;
|
||||
@@ -1103,7 +800,6 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
};
|
||||
|
||||
const onConversationIdChanging = (nextId: string, prevId: string | null | undefined) => {
|
||||
onNoticeBatchConversationChanging(nextId, prevId);
|
||||
shippingIntakes.stopPolling();
|
||||
if (nextId && nextId !== prevId) {
|
||||
focusedConversationTaskNo.value = null;
|
||||
@@ -1114,28 +810,9 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
}
|
||||
if (prevId !== nextId) {
|
||||
resolvedShippingTaskId.value = '';
|
||||
if (!shippingBatchNoFromQuery.value) {
|
||||
resolvedShippingBatchNo.value = '';
|
||||
shippingBatchSummary.value = null;
|
||||
shippingBatchTasks.value = [];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 重试当前聚焦批次中可恢复的失败/排队任务(co8 已下线,保留签名兼容)。
|
||||
*
|
||||
* 核心逻辑:批次重试 API 已移除,调用时提示用户改由 processing 工作台或任务动作重试。
|
||||
* @returns 恒为 null
|
||||
*/
|
||||
const retryCurrentShippingBatchPendingTasks = async (): Promise<{
|
||||
started: number;
|
||||
skipped: number;
|
||||
} | null> => {
|
||||
msg.warning(t('chat.shippingNoticeUi.batchRetryRemoved'));
|
||||
return null;
|
||||
};
|
||||
|
||||
const handleShippingLocalFilesSelected = (event: Event): boolean => {
|
||||
if (!isShippingNoticeAgent.value) return false;
|
||||
const inputEl = event.target as HTMLInputElement | null;
|
||||
@@ -1167,7 +844,6 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
const onConversationLoadedEmpty = async () => {
|
||||
if (!isShippingNoticeAgent.value || !shippingTaskIdFromQuery.value || isShippingActionBusy.value) return;
|
||||
const nextQuery: Record<string, string> = { task_id: shippingTaskIdFromQuery.value };
|
||||
if (shippingBatchNoFromQuery.value) nextQuery.batch_no = shippingBatchNoFromQuery.value;
|
||||
await router.replace({ path: route.path, query: nextQuery });
|
||||
};
|
||||
|
||||
@@ -1175,7 +851,6 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
if (!isShippingNoticeAgent.value || !shippingTaskIdFromQuery.value || isShippingActionBusy.value) return;
|
||||
createNewChatView();
|
||||
const nextQuery: Record<string, string> = { task_id: shippingTaskIdFromQuery.value };
|
||||
if (shippingBatchNoFromQuery.value) nextQuery.batch_no = shippingBatchNoFromQuery.value;
|
||||
void router.replace({ path: route.path, query: nextQuery });
|
||||
const displayText = t('chat.shippingNoticeUi.retrySingleTaskMessage', { taskId: shippingTaskIdFromQuery.value });
|
||||
await sendMessage(
|
||||
@@ -1200,18 +875,18 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
shippingStatusPollTimer = null;
|
||||
}
|
||||
if (!isShippingNoticeAgent.value) return;
|
||||
const taskId = getActiveBatchTaskId() || getActiveShippingTaskId();
|
||||
const taskId = getActiveShippingTaskId();
|
||||
if (!taskId) return;
|
||||
|
||||
shippingStatusPollTimer = setInterval(() => {
|
||||
if (!isShippingNoticeAgent.value) return;
|
||||
const nextTaskId = getActiveBatchTaskId() || getActiveShippingTaskId();
|
||||
const nextTaskId = getActiveShippingTaskId();
|
||||
if (!nextTaskId) return;
|
||||
void (async () => {
|
||||
await syncActiveShippingTaskDetail(nextTaskId);
|
||||
await syncConversationMessagesIfNeeded(nextTaskId);
|
||||
await refreshShippingActions();
|
||||
if (!hasRunningShippingBatchTasks() && !isShippingActionBusy.value && shippingStatusPollTimer) {
|
||||
if (!isShippingActionBusy.value && shippingStatusPollTimer) {
|
||||
clearInterval(shippingStatusPollTimer);
|
||||
shippingStatusPollTimer = null;
|
||||
}
|
||||
@@ -1232,15 +907,11 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
});
|
||||
const shippingRecoveryWatchKey = computed(() => {
|
||||
const recovery = resolveLatestShippingMessageRecoveryPayload(messages.value);
|
||||
const snapshot = recovery?.shipping_batch_ui_state;
|
||||
const uiState = recovery?.shipping_ui_state;
|
||||
return [
|
||||
String(conversationId.value || ''),
|
||||
String(recovery?.batch_no || snapshot?.batch_no || uiState?.batch_no || ''),
|
||||
String(recovery?.task_no || snapshot?.current_focus_task_no || uiState?.task_no || ''),
|
||||
String(snapshot?.updated_at || ''),
|
||||
String(recovery?.task_no || uiState?.task_no || ''),
|
||||
String(uiState?.updated_at || ''),
|
||||
String(snapshot?.tasks.length || 0),
|
||||
].join('|');
|
||||
});
|
||||
watch([shippingRecoveryWatchKey, isShippingNoticeAgent], () => {
|
||||
@@ -1249,7 +920,7 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
}, { immediate: true });
|
||||
watch([shippingActionsWatchKey, isThinking, isShippingNoticeAgent, () => currentAgent.value?.name], () => {
|
||||
void refreshShippingActions().then(async () => {
|
||||
const taskId = getActiveBatchTaskId() || getActiveShippingTaskId();
|
||||
const taskId = getActiveShippingTaskId();
|
||||
await Promise.all([
|
||||
syncShippingParseReviewCard(taskId),
|
||||
syncActiveShippingTaskDetail(taskId),
|
||||
@@ -1257,19 +928,8 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
await syncConversationMessagesIfNeeded(taskId);
|
||||
});
|
||||
});
|
||||
watch([activeShippingBatchNo, shippingBatchNoFromQuery, resolvedShippingBatchNo], ([activeBatchNo, queryBatchNo, batchNo]) => {
|
||||
const nextBatchNo = String(activeBatchNo || queryBatchNo || batchNo || '').trim();
|
||||
if (!nextBatchNo) {
|
||||
shippingBatchSummary.value = null;
|
||||
return;
|
||||
}
|
||||
void syncShippingBatchSummary(nextBatchNo);
|
||||
}, { immediate: true });
|
||||
watch([conversationId, isShippingNoticeAgent], () => {
|
||||
void syncShippingConversationWorkspace();
|
||||
}, { immediate: true });
|
||||
watch(
|
||||
[isShippingNoticeAgent, conversationId, resolvedShippingBatchNo, shippingBatchNoFromQuery, resolvedShippingTaskId, shippingTaskIdFromQuery, isThinking],
|
||||
[isShippingNoticeAgent, conversationId, resolvedShippingTaskId, shippingTaskIdFromQuery, isThinking],
|
||||
() => {
|
||||
restartShippingStatusPolling();
|
||||
},
|
||||
@@ -1294,18 +954,9 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
shippingInventorySelectionTaskId,
|
||||
allowsSendWithAttachmentsOnly,
|
||||
shippingTaskIdFromQuery,
|
||||
shippingBatchNoFromQuery,
|
||||
resolvedShippingBatchNo,
|
||||
activeShippingBatchNo,
|
||||
shippingConversationWorkspace,
|
||||
shippingBatchSummary,
|
||||
shippingBatchTasks,
|
||||
isShippingActionBusy,
|
||||
activeShippingTaskDetail,
|
||||
getCurrentShippingChatContext,
|
||||
getActiveShippingBatchNo,
|
||||
switchShippingBatch,
|
||||
retryCurrentShippingBatchPendingTasks,
|
||||
queryShippingShortageDetails,
|
||||
resetShippingConversationState,
|
||||
resumeShippingTaskFromQuery,
|
||||
|
||||
Reference in new issue
Block a user