feat(shipping-notice): 新增通用解析能力,优化性能并清理遗留废弃代码

This commit is contained in:
hugo committed 2026-08-23 00:27:18 +08:00
1 parent 935bf26fa6
commit 7cfd5d167e
230 files changed
+9337 -10989

No files matched your search

@@ -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,