feat(shipping-notice): 支持发货通知解析延后至 Dify 画布,优化任务创建流程
This commit is contained in:
1 parent
d46d61bfa1
commit
70e8f700ff
38 files changed
+3215
-714
No files matched your search
@@ -439,6 +439,7 @@ export type {
|
||||
ShippingBatchSummary,
|
||||
ShippingChatAction,
|
||||
ShippingChatActionsResponse,
|
||||
ShippingCurrentStepProgress,
|
||||
ShippingDecisionResponse,
|
||||
ShippingInventoryUploadResponse,
|
||||
ShippingMatchLineResult,
|
||||
|
||||
@@ -15,7 +15,7 @@ import ChatBrowserPanel from '@/features/chat/components/ChatBrowserPanel.vue';
|
||||
import ShippingWorkflowStepper from '@/features/chat/components/ShippingWorkflowStepper.vue';
|
||||
import { useChatPageContext } from '@/features/chat/composables/chat.context';
|
||||
import { buildShippingWorkflowSteps } from '@/features/chat/shipping';
|
||||
import type { ShippingTaskSummary } from '@/features/chat/types/shipping.api.types';
|
||||
import type { ShippingCurrentStepProgress, ShippingTaskSummary } from '@/features/chat/types/shipping.api.types';
|
||||
|
||||
const page = useChatPageContext();
|
||||
const { t } = useI18n();
|
||||
@@ -38,6 +38,12 @@ const statusMeta = (status?: string | null) => {
|
||||
const stepLabel = (step?: string | null) => {
|
||||
const map: Record<string, string> = {
|
||||
step1_notice_submit: t('chat.shippingNoticeUi.currentStep.noticeParse'),
|
||||
step2_parse_confirm: t('chat.shippingNoticeUi.currentStep.parseConfirm'),
|
||||
step3_inventory_prepare: t('chat.shippingNoticeUi.currentStep.inventoryPrepare'),
|
||||
step4_align_confirm: t('chat.shippingNoticeUi.currentStep.alignConfirm'),
|
||||
step5_match_inventory: t('chat.shippingNoticeUi.currentStep.inventoryMatch'),
|
||||
step6_generate_file: t('chat.shippingNoticeUi.currentStep.generateExcel'),
|
||||
step7_upload_freight: t('chat.shippingNoticeUi.currentStep.uploadFreight'),
|
||||
step2_inventory_prepare: t('chat.shippingNoticeUi.currentStep.inventoryPrepare'),
|
||||
step3_inventory_match: t('chat.shippingNoticeUi.currentStep.inventoryMatch'),
|
||||
step4_shortage_review: t('chat.shippingNoticeUi.currentStep.shortageHandle'),
|
||||
@@ -56,6 +62,12 @@ const currentShippingTask = computed<ShippingTaskSummary | null>(() => {
|
||||
|
||||
const currentShippingTaskSource = computed(() => currentShippingTask.value || page.activeShippingTaskDetail || null);
|
||||
const currentShippingSteps = computed(() => buildShippingWorkflowSteps(currentShippingTaskSource.value));
|
||||
const currentShippingStepProgress = computed<ShippingCurrentStepProgress | null>(() => {
|
||||
const payload = currentShippingTaskSource.value?.step_payload;
|
||||
if (!payload || typeof payload !== 'object') return null;
|
||||
const progress = (payload as Record<string, unknown>).current_step_progress;
|
||||
return progress && typeof progress === 'object' ? progress as ShippingCurrentStepProgress : null;
|
||||
});
|
||||
const currentShippingBatchProgress = computed(() => {
|
||||
const task = currentShippingTask.value;
|
||||
if (!task?.batch_index || !task?.batch_total) return '';
|
||||
@@ -67,9 +79,20 @@ const batchCompletedCount = computed(() =>
|
||||
const batchRunningCount = computed(() =>
|
||||
Number(page.shippingBatchSummary?.process_summary?.running || 0),
|
||||
);
|
||||
const batchPendingCount = computed(() =>
|
||||
Number(page.shippingBatchSummary?.process_summary?.pending || 0),
|
||||
);
|
||||
const batchFileCount = computed(() =>
|
||||
Number(page.shippingBatchSummary?.file_count || 0),
|
||||
);
|
||||
const batchCurrentIndex = computed(() =>
|
||||
Number(
|
||||
currentShippingTask.value?.batch_index
|
||||
|| page.activeShippingTaskDetail?.batch_index
|
||||
|| page.shippingBatchSummary?.process_summary?.current_index
|
||||
|| 0,
|
||||
),
|
||||
);
|
||||
const batchCompletionPercent = computed(() => {
|
||||
if (!batchFileCount.value) return 0;
|
||||
return Math.min(100, Math.max(0, Math.round((batchCompletedCount.value / batchFileCount.value) * 100)));
|
||||
@@ -175,6 +198,12 @@ const batchCompletionPercent = computed(() => {
|
||||
>
|
||||
{{ currentShippingBatchProgress }}
|
||||
</span>
|
||||
<span
|
||||
v-if="batchCurrentIndex"
|
||||
class="rounded-full bg-amber-50 px-2.5 py-1 text-xs font-medium text-amber-700"
|
||||
>
|
||||
{{ t('chat.shippingNoticeUi.batchCurrentIndex', { index: batchCurrentIndex, total: batchFileCount }) }}
|
||||
</span>
|
||||
</div>
|
||||
<div v-if="currentShippingTaskSource" class="flex flex-wrap items-center gap-2 text-xs text-secondary">
|
||||
<span class="truncate font-medium text-primary">
|
||||
@@ -194,6 +223,40 @@ const batchCompletionPercent = computed(() => {
|
||||
compact
|
||||
class="pt-2"
|
||||
/>
|
||||
<div
|
||||
v-if="currentShippingStepProgress"
|
||||
class="mt-3 rounded-2xl border border-default/80 bg-surface/80 px-3 py-3"
|
||||
>
|
||||
<div class="flex items-center justify-between gap-3 text-xs">
|
||||
<div class="font-medium text-primary">
|
||||
{{ currentShippingStepProgress.step_title || t('chat.shippingNoticeUi.stepDetail.title') }}
|
||||
</div>
|
||||
<div class="text-muted">
|
||||
{{ currentShippingStepProgress.progress_percent ?? 0 }}%
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-1 text-sm text-secondary">
|
||||
{{ currentShippingStepProgress.message || t('chat.shippingNoticeUi.processing') }}
|
||||
</div>
|
||||
<div
|
||||
v-if="currentShippingStepProgress.detail"
|
||||
class="mt-1 text-xs text-muted"
|
||||
>
|
||||
{{ currentShippingStepProgress.detail }}
|
||||
</div>
|
||||
<div
|
||||
v-if="currentShippingStepProgress.current && currentShippingStepProgress.total"
|
||||
class="mt-1 text-xs text-muted"
|
||||
>
|
||||
{{ t('chat.shippingNoticeUi.stepDetail.counter', { current: currentShippingStepProgress.current, total: currentShippingStepProgress.total }) }}
|
||||
</div>
|
||||
<div class="mt-2 h-2 overflow-hidden rounded-full bg-slate-200">
|
||||
<div
|
||||
class="h-full rounded-full bg-sky-500 transition-all"
|
||||
:style="{ width: `${currentShippingStepProgress.progress_percent ?? 0}%` }"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-wrap gap-2 pt-1 text-xs">
|
||||
<button
|
||||
v-if="page.shippingBatchSummary"
|
||||
@@ -221,7 +284,7 @@ const batchCompletionPercent = computed(() => {
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="page.shippingBatchSummary" class="grid grid-cols-3 gap-2 text-right text-xs">
|
||||
<div v-if="page.shippingBatchSummary" class="grid grid-cols-4 gap-2 text-right text-xs">
|
||||
<div class="rounded-2xl bg-surface px-3 py-2">
|
||||
<div class="text-muted">{{ t('chat.shippingNoticeUi.fileCount') }}</div>
|
||||
<div class="mt-1 text-sm font-semibold text-primary">{{ batchFileCount }}</div>
|
||||
@@ -234,6 +297,10 @@ const batchCompletionPercent = computed(() => {
|
||||
<div class="text-muted">{{ t('chat.shippingNoticeUi.completedCount') }}</div>
|
||||
<div class="mt-1 text-sm font-semibold text-primary">{{ batchCompletedCount }}</div>
|
||||
</div>
|
||||
<div class="rounded-2xl bg-surface px-3 py-2">
|
||||
<div class="text-muted">{{ t('chat.shippingNoticeUi.pendingCount') }}</div>
|
||||
<div class="mt-1 text-sm font-semibold text-primary">{{ batchPendingCount }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
|
||||
@@ -83,6 +83,10 @@ const applyEventMetadata = (msg: ChatMessage, data: Record<string, unknown>) =>
|
||||
if (Number.isInteger(data.chat_log_id)) {
|
||||
msg.chat_log_id = Number(data.chat_log_id);
|
||||
}
|
||||
const runId = Number(data.run_id);
|
||||
if (Number.isFinite(runId) && runId > 0) {
|
||||
msg.run_id = runId;
|
||||
}
|
||||
if (typeof data.type === 'string' && data.type.trim()) {
|
||||
msg.type = data.type as ChatMessage['type'];
|
||||
}
|
||||
@@ -177,6 +181,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 },
|
||||
) => {
|
||||
const runViewId = viewId.value;
|
||||
const runMessages = messages.value;
|
||||
@@ -195,17 +200,20 @@ export function useChat() {
|
||||
activeRunId.value = run.runId;
|
||||
|
||||
runMessages.push({ role: 'user', content: query });
|
||||
let botMsgIndex: number | null = null;
|
||||
let botMsgRef: ChatMessage | null = null;
|
||||
let hasAssistantContent = false;
|
||||
let hasTerminalEvent = false;
|
||||
const ensureBotMessage = () => {
|
||||
if (botMsgIndex === null) {
|
||||
botMsgIndex = runMessages.push({
|
||||
if (!botMsgRef) {
|
||||
botMsgRef = {
|
||||
role: 'assistant',
|
||||
content: '',
|
||||
retriever_resources: [],
|
||||
attribution_parts: [],
|
||||
}) - 1;
|
||||
};
|
||||
runMessages.push(botMsgRef);
|
||||
}
|
||||
return runMessages[botMsgIndex] || null;
|
||||
return botMsgRef;
|
||||
};
|
||||
|
||||
isThinking.value = true;
|
||||
@@ -220,6 +228,8 @@ export function useChat() {
|
||||
conversation_id: conversationId.value,
|
||||
kb_type: kbType,
|
||||
files: files && files.length > 0 ? files : undefined,
|
||||
task_id: context?.task_id || undefined,
|
||||
batch_no: context?.batch_no || undefined,
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -253,6 +263,16 @@ export function useChat() {
|
||||
if (!payload) continue;
|
||||
|
||||
try {
|
||||
const eventMatch = payload.match(/"event"\s*:\s*"([^"]+)"/);
|
||||
const fastEventName = eventMatch?.[1] || '';
|
||||
if (
|
||||
fastEventName === 'workflow_started'
|
||||
|| fastEventName === 'node_started'
|
||||
|| fastEventName === 'node_finished'
|
||||
|| fastEventName === 'chat_perf'
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
const data = JSON.parse(payload) as Record<string, unknown>;
|
||||
|
||||
if (data?.conversation_id) {
|
||||
@@ -267,40 +287,13 @@ export function useChat() {
|
||||
const botMsg = ensureBotMessage();
|
||||
if (!botMsg) continue;
|
||||
botMsg.content += normalizeStreamText(data.answer);
|
||||
hasAssistantContent = true;
|
||||
}
|
||||
if (botMsgIndex !== null) {
|
||||
const currentBotMsg = runMessages[botMsgIndex];
|
||||
if (currentBotMsg) applyEventMetadata(currentBotMsg, data);
|
||||
if (botMsgRef) {
|
||||
applyEventMetadata(botMsgRef, data);
|
||||
}
|
||||
} else if (eventName === 'chat_perf') {
|
||||
const perf = (data.perf || {}) as Record<string, unknown>;
|
||||
const nodes = Array.isArray(perf.nodes) ? perf.nodes : [];
|
||||
// eslint-disable-next-line no-console
|
||||
console.groupCollapsed(
|
||||
`[chat-perf] request=${String(perf.request_id || '')} total=${String(perf.total_ms ?? '')}ms ttft=${String(perf.ttft_ms ?? '')}ms`,
|
||||
);
|
||||
if (nodes.length > 0) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.table(
|
||||
nodes.map((node) => {
|
||||
const item = node as Record<string, unknown>;
|
||||
return {
|
||||
index: item.index,
|
||||
title: item.title,
|
||||
type: item.node_type,
|
||||
elapsed_ms: item.elapsed_ms,
|
||||
at_ms: item.at_ms,
|
||||
status: item.status,
|
||||
};
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(perf);
|
||||
}
|
||||
// eslint-disable-next-line no-console
|
||||
console.groupEnd();
|
||||
} else if (eventName === 'message_end' || eventName === 'workflow_finished') {
|
||||
hasTerminalEvent = true;
|
||||
const relay = (data.hxops_relay || {}) as Record<string, unknown>;
|
||||
if (relay.total_relay_ms != null) {
|
||||
// eslint-disable-next-line no-console
|
||||
@@ -310,30 +303,19 @@ export function useChat() {
|
||||
}
|
||||
run.status = 'done';
|
||||
if (messages.value === runMessages) isThinking.value = false;
|
||||
if (botMsgIndex !== null && Number.isInteger(data.chat_log_id)) {
|
||||
const currentBotMsg = runMessages[botMsgIndex];
|
||||
if (currentBotMsg) currentBotMsg.chat_log_id = Number(data.chat_log_id);
|
||||
}
|
||||
if (botMsgIndex !== null) {
|
||||
const runId = Number(data.run_id);
|
||||
if (Number.isFinite(runId) && runId > 0) {
|
||||
const currentBotMsg = runMessages[botMsgIndex];
|
||||
if (currentBotMsg) currentBotMsg.run_id = runId;
|
||||
}
|
||||
}
|
||||
if (typeof data.answer === 'string' && data.answer.length > 0) {
|
||||
const botMsg = ensureBotMessage();
|
||||
if (!botMsg) continue;
|
||||
const normalizedAnswer = normalizeStreamText(data.answer);
|
||||
hasAssistantContent = true;
|
||||
if (data.replace_answer) {
|
||||
botMsg.content = normalizedAnswer;
|
||||
} else {
|
||||
botMsg.content += normalizedAnswer;
|
||||
}
|
||||
}
|
||||
if (botMsgIndex !== null) {
|
||||
const currentBotMsg = runMessages[botMsgIndex];
|
||||
if (currentBotMsg) applyEventMetadata(currentBotMsg, data);
|
||||
if (botMsgRef) {
|
||||
applyEventMetadata(botMsgRef, data);
|
||||
}
|
||||
} else if (eventName === 'error') {
|
||||
const botMsg = ensureBotMessage();
|
||||
@@ -345,12 +327,16 @@ export function useChat() {
|
||||
const botMsg = ensureBotMessage();
|
||||
if (!botMsg) continue;
|
||||
botMsg.content += normalizeStreamText(data.answer);
|
||||
hasAssistantContent = true;
|
||||
}
|
||||
} catch {
|
||||
// ignore malformed SSE frames
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!hasTerminalEvent && hasAssistantContent && run.status === 'running') {
|
||||
run.status = 'done';
|
||||
}
|
||||
} catch (e: unknown) {
|
||||
run.status = 'error';
|
||||
const botMsg = ensureBotMessage();
|
||||
|
||||
@@ -284,6 +284,7 @@ export function useChatPage() {
|
||||
buildFileSpecsForSend: attachmentApi.buildFileSpecsForSend,
|
||||
clearAttachments: attachmentApi.clearAttachments,
|
||||
sendMessage,
|
||||
getChatContext: shipping.isShippingNoticeAgent ? shipping.getCurrentShippingChatContext : undefined,
|
||||
refreshHistoryAfterSend,
|
||||
tryHandleShippingAttachmentAutoFlow: shipping.tryHandleShippingAttachmentAutoFlow,
|
||||
tryHandleLeaveSend: leave.tryHandleLeaveSend,
|
||||
|
||||
@@ -210,6 +210,11 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
|| String(shippingBatchSummary.value?.batch_no || '').trim()
|
||||
|| '';
|
||||
|
||||
const getCurrentShippingChatContext = () => ({
|
||||
task_id: getActiveShippingTaskId(),
|
||||
batch_no: getActiveShippingBatchNo(),
|
||||
});
|
||||
|
||||
const syncActiveShippingTaskDetail = async (taskId?: string) => {
|
||||
const normalized = String(taskId || getActiveShippingTaskId() || '').trim().toUpperCase();
|
||||
if (!normalized) {
|
||||
@@ -483,6 +488,7 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
shippingBatchTasks,
|
||||
shippingBatchTasksExpanded,
|
||||
activeShippingTaskDetail,
|
||||
getCurrentShippingChatContext,
|
||||
getActiveShippingBatchNo,
|
||||
switchShippingFocusTask,
|
||||
resumeShippingTaskFromQuery,
|
||||
|
||||
@@ -25,6 +25,7 @@ export interface ChatPageSendContext {
|
||||
agentId: number,
|
||||
kb: string,
|
||||
files: ChatUploadFileSpec[],
|
||||
context?: { task_id?: string; batch_no?: string },
|
||||
) => Promise<void>;
|
||||
refreshHistoryAfterSend: () => Promise<void>;
|
||||
tryHandleShippingAttachmentAutoFlow: (
|
||||
@@ -43,6 +44,7 @@ export interface ChatPageSendContext {
|
||||
msg: { warning: (text: string) => void; info: (text: string) => void };
|
||||
t: (key: string) => string;
|
||||
copiedIndex: Ref<number | null>;
|
||||
getChatContext?: () => { task_id?: string; batch_no?: string };
|
||||
}
|
||||
|
||||
export function createChatPageSendApi(ctx: ChatPageSendContext) {
|
||||
@@ -90,7 +92,13 @@ export function createChatPageSendApi(ctx: ChatPageSendContext) {
|
||||
ctx.clearAttachments();
|
||||
|
||||
await ctx.prepareToolRunProgressBeforeSend();
|
||||
await ctx.sendMessage(content, ctx.currentAgentId.value, ctx.selectedKb.value, files);
|
||||
await ctx.sendMessage(
|
||||
content,
|
||||
ctx.currentAgentId.value,
|
||||
ctx.selectedKb.value,
|
||||
files,
|
||||
ctx.getChatContext?.(),
|
||||
);
|
||||
await ctx.refreshHistoryAfterSend();
|
||||
await ctx.refreshToolRunProgressAfterSend();
|
||||
};
|
||||
|
||||
@@ -29,13 +29,37 @@ export const SHIPPING_WORKFLOW_STEP_LABELS = [
|
||||
'chat.shippingNoticeUi.stepper.uploadFreight',
|
||||
] as const;
|
||||
|
||||
const CURRENT_STEP_INDEX_MAP: Record<string, number> = {
|
||||
step1_notice_submit: 0,
|
||||
step2_parse_confirm: 1,
|
||||
step3_inventory_prepare: 2,
|
||||
step2_inventory_prepare: 2,
|
||||
step4_align_confirm: 3,
|
||||
step5_match_inventory: 4,
|
||||
step3_inventory_match: 4,
|
||||
step4_shortage_review: 4,
|
||||
step6_generate_file: 5,
|
||||
step5_export_excel: 5,
|
||||
step7_upload_freight: 6,
|
||||
step6_upload_freight: 6,
|
||||
step7_finish: 6,
|
||||
};
|
||||
|
||||
function deriveCurrentIndex(task: ShippingTaskStepperSource | null | undefined): number {
|
||||
const currentStep = String(task?.current_step || '').trim();
|
||||
const processStatus = String(task?.process_status || '').trim();
|
||||
const reviewStatus = String(task?.review_status || '').trim();
|
||||
const pendingReason = String(task?.pending_human_reason || '').trim();
|
||||
const matchStatus = String(task?.match_status || '').trim();
|
||||
const hasExport = !!String(task?.export_file_name || '').trim();
|
||||
|
||||
if (currentStep) {
|
||||
const currentStepIndex = CURRENT_STEP_INDEX_MAP[currentStep];
|
||||
if (currentStepIndex !== undefined) {
|
||||
return currentStepIndex;
|
||||
}
|
||||
}
|
||||
|
||||
if (processStatus === 'uploaded' || processStatus === 'closed') return 6;
|
||||
if (processStatus === 'waiting_upload' || processStatus === 'upload_failed' || hasExport) return 5;
|
||||
if (processStatus === 'matched') return 4;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
* features/chat/shipping/shippingUploadPrompt.ts
|
||||
* 用途:库存上传后发给 Dify 的提示语构建与附件类型分类。
|
||||
* 用途:库存/通知上传后发给 Dify 的提示语构建与附件类型分类。
|
||||
* 依赖:无;useChatShippingUploadHandler 在上传成功后调用。
|
||||
* 逻辑:按 checkpoint 生成不同 follow-up 提示;classifyShippingUploadFile 区分库存/通知附件。
|
||||
* 逻辑:按 checkpoint 生成不同 follow-up 提示;通知建批后触发 Dify LLM 解析续办。
|
||||
*/
|
||||
/**
|
||||
* 根据上传 API 响应 checkpoint 生成发给 Agent 的 follow-up 提示语。
|
||||
@@ -29,6 +29,34 @@ export function buildShippingInventoryUploadPrompt(
|
||||
return `${prefix}。请继续处理库存导入,并告诉我下一步。`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据通知建批 API 响应生成发给 Dify 的 follow-up 提示语(触发画布 LLM 抽取 + parse_notice)。
|
||||
*/
|
||||
export function buildShippingNoticeUploadPrompt(
|
||||
result: Record<string, unknown> | null | undefined,
|
||||
options?: { fileCount?: number; fileName?: string },
|
||||
): string {
|
||||
const batchNo = String(
|
||||
(result?.batch_no as string | undefined)
|
||||
|| ((result?.data as { batch?: { batch_no?: string } } | undefined)?.batch?.batch_no)
|
||||
|| '',
|
||||
).trim();
|
||||
const taskId = String(
|
||||
((result?.data as { focus_task?: { task_no?: string } } | undefined)?.focus_task?.task_no)
|
||||
|| (result?.task_id as string | undefined)
|
||||
|| ((result?.data as { tasks?: Array<{ task_id?: string }> } | undefined)?.tasks?.[0]?.task_id)
|
||||
|| '',
|
||||
).trim();
|
||||
const fileCount = Number(options?.fileCount || 0);
|
||||
const fileLabel = options?.fileName
|
||||
? `《${options.fileName}》`
|
||||
: (fileCount > 1 ? `${fileCount} 份发货通知` : '发货通知');
|
||||
const parts = [`我已上传${fileLabel}`];
|
||||
if (batchNo) parts.push(`批次 ${batchNo}`);
|
||||
if (taskId) parts.push(`当前任务 ${taskId}`);
|
||||
return `${parts.join(',')}。请读取任务 raw_text,用 LLM 抽取结构化字段后调用 parse_notice(structured=...) 落库;若抽取失败可仅传 raw_text 走后端规则兜底,并展示解析结果供我确认。`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按扩展名判断附件是库存 Excel 还是发货通知文件。
|
||||
*/
|
||||
|
||||
@@ -60,10 +60,14 @@ export function createShippingParseReviewHandlers(ctx: ShippingParseReviewContex
|
||||
const removeParseReviewMessageForTask = (taskId: string) => {
|
||||
const normalized = String(taskId || '').trim().toUpperCase();
|
||||
if (!normalized) return;
|
||||
ctx.messages.value = ctx.messages.value.filter((msg) => {
|
||||
for (let i = ctx.messages.value.length - 1; i >= 0; i -= 1) {
|
||||
const msg = ctx.messages.value[i];
|
||||
if (!msg) continue;
|
||||
const payload = getShippingParseReviewPayload(msg);
|
||||
return payload?.taskId?.trim().toUpperCase() !== normalized;
|
||||
});
|
||||
if (payload?.taskId?.trim().toUpperCase() === normalized) {
|
||||
ctx.messages.value.splice(i, 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const upsertParseReviewMessage = async (payload: ShippingParseReviewPayload) => {
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
type ShippingTaskSummary,
|
||||
} from '@/features/chat/api/shipping.api';
|
||||
import { extractExt } from '../constants/shipping';
|
||||
import { buildShippingInventoryUploadPrompt, classifyShippingUploadFile } from './shippingUploadPrompt';
|
||||
import { buildShippingInventoryUploadPrompt, buildShippingNoticeUploadPrompt, classifyShippingUploadFile } from './shippingUploadPrompt';
|
||||
import type { PendingAttachment } from '../types/shipping.types';
|
||||
import type { Ref } from 'vue';
|
||||
|
||||
@@ -193,6 +193,9 @@ export function createShippingUploadHandlers(ctx: ShippingUploadHandlerContext)
|
||||
tail,
|
||||
].filter(Boolean).join('\n'),
|
||||
);
|
||||
await ctx.sendShippingMenuMessage(
|
||||
buildShippingNoticeUploadPrompt(result as unknown as Record<string, unknown>, { fileName: file.name }),
|
||||
);
|
||||
void ctx.refreshShippingActions();
|
||||
};
|
||||
|
||||
@@ -238,6 +241,9 @@ export function createShippingUploadHandlers(ctx: ShippingUploadHandlerContext)
|
||||
tail,
|
||||
].filter(Boolean).join('\n'),
|
||||
);
|
||||
await ctx.sendShippingMenuMessage(
|
||||
buildShippingNoticeUploadPrompt(result as unknown as Record<string, unknown>, { fileCount }),
|
||||
);
|
||||
void ctx.refreshShippingActions();
|
||||
};
|
||||
|
||||
|
||||
@@ -25,6 +25,9 @@ export interface ShippingTaskSummary {
|
||||
conversation_id?: string | null;
|
||||
export_file_name?: string | null;
|
||||
freight_ref_no?: string | null;
|
||||
step_payload?: Record<string, unknown> & {
|
||||
current_step_progress?: ShippingCurrentStepProgress;
|
||||
};
|
||||
created_at?: string | null;
|
||||
updated_at?: string | null;
|
||||
}
|
||||
@@ -35,6 +38,18 @@ export interface ShippingTaskEvent {
|
||||
created_at?: string | null;
|
||||
}
|
||||
|
||||
export interface ShippingCurrentStepProgress {
|
||||
step_key?: string;
|
||||
step_title?: string;
|
||||
status?: 'running' | 'completed' | 'needs_human' | 'pending' | string;
|
||||
message?: string;
|
||||
progress_percent?: number;
|
||||
current?: number;
|
||||
total?: number;
|
||||
detail?: string;
|
||||
extra?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export interface ShippingNoticeHeader {
|
||||
customer_name?: string | null;
|
||||
customer_code?: string | null;
|
||||
@@ -70,7 +85,6 @@ export interface ShippingTaskDetail extends ShippingTaskSummary {
|
||||
ship_to?: string | null;
|
||||
po_number?: string | null;
|
||||
required_date?: string | null;
|
||||
step_payload?: Record<string, unknown>;
|
||||
upload_receipt?: Record<string, unknown>;
|
||||
export_version?: number | null;
|
||||
idempotency_key?: string | null;
|
||||
@@ -104,7 +118,15 @@ export interface ShippingBatchSummary {
|
||||
conversation_id?: string | null;
|
||||
current_focus_task_no?: string | null;
|
||||
file_count?: number | null;
|
||||
process_summary?: Record<string, unknown> | null;
|
||||
process_summary?: Record<string, unknown> & {
|
||||
total?: number;
|
||||
completed?: number;
|
||||
failed?: number;
|
||||
running?: number;
|
||||
pending?: number;
|
||||
current_index?: number;
|
||||
current_task_no?: string | null;
|
||||
} | null;
|
||||
created_at?: string | null;
|
||||
updated_at?: string | null;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import {
|
||||
updateWorkspaceShippingNoticeLine,
|
||||
workspaceShippingExportUrl,
|
||||
type ShippingChatAction,
|
||||
type ShippingCurrentStepProgress,
|
||||
type ShippingNoticeHeader,
|
||||
type ShippingNoticeLine,
|
||||
type ShippingTaskDetail,
|
||||
@@ -90,6 +91,12 @@ const statusBadge = (status: string) => {
|
||||
};
|
||||
|
||||
const detailWorkflowSteps = computed(() => buildShippingWorkflowSteps(detail.value));
|
||||
const detailStepProgress = computed<ShippingCurrentStepProgress | null>(() => {
|
||||
const payload = detail.value?.step_payload;
|
||||
if (!payload || typeof payload !== 'object') return null;
|
||||
const progress = (payload as Record<string, unknown>).current_step_progress;
|
||||
return progress && typeof progress === 'object' ? progress as ShippingCurrentStepProgress : null;
|
||||
});
|
||||
|
||||
const loadCases = async () => {
|
||||
loading.value = true;
|
||||
@@ -413,6 +420,38 @@ onMounted(async () => {
|
||||
|
||||
<ShippingWorkflowStepper :steps="detailWorkflowSteps" />
|
||||
|
||||
<div
|
||||
v-if="detailStepProgress"
|
||||
class="rounded-2xl border border-default/80 bg-surface px-4 py-3"
|
||||
>
|
||||
<div class="flex items-center justify-between gap-3 text-xs">
|
||||
<div class="font-medium text-primary">
|
||||
{{ detailStepProgress.step_title || t('chat.shippingNoticeUi.stepDetail.title') }}
|
||||
</div>
|
||||
<div class="text-muted">
|
||||
{{ detailStepProgress.progress_percent ?? 0 }}%
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-1 text-sm text-secondary">
|
||||
{{ detailStepProgress.message || t('chat.shippingNoticeUi.processing') }}
|
||||
</div>
|
||||
<div v-if="detailStepProgress.detail" class="mt-1 text-xs text-muted">
|
||||
{{ detailStepProgress.detail }}
|
||||
</div>
|
||||
<div
|
||||
v-if="detailStepProgress.current && detailStepProgress.total"
|
||||
class="mt-1 text-xs text-muted"
|
||||
>
|
||||
{{ t('chat.shippingNoticeUi.stepDetail.counter', { current: detailStepProgress.current, total: detailStepProgress.total }) }}
|
||||
</div>
|
||||
<div class="mt-2 h-2 overflow-hidden rounded-full bg-slate-200">
|
||||
<div
|
||||
class="h-full rounded-full bg-sky-500 transition-all"
|
||||
:style="{ width: `${detailStepProgress.progress_percent ?? 0}%` }"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<dl class="grid gap-3 sm:grid-cols-2 text-sm">
|
||||
<div><dt class="text-muted">{{ $t('workspace.shippingNotice.fields.status') }}</dt><dd>{{ detail.process_status }}</dd></div>
|
||||
<div><dt class="text-muted">{{ $t('workspace.shippingNotice.fields.match') }}</dt><dd>{{ detail.match_status || '—' }}</dd></div>
|
||||
|
||||
@@ -79,6 +79,7 @@
|
||||
"taskTitle": "Shipping task",
|
||||
"currentTask": "Current task {taskId}",
|
||||
"batchProgress": "Item {index}/{total}",
|
||||
"batchCurrentIndex": "Currently processing item {index}/{total}",
|
||||
"currentNotice": "Current notice",
|
||||
"prevTask": "Previous",
|
||||
"nextTask": "Next",
|
||||
@@ -94,6 +95,7 @@
|
||||
"fileCount": "Files",
|
||||
"runningCount": "Running",
|
||||
"completedCount": "Completed",
|
||||
"pendingCount": "Pending",
|
||||
"batchProgressTitle": "Batch progress",
|
||||
"processing": "Processing",
|
||||
"status": {
|
||||
@@ -109,13 +111,19 @@
|
||||
},
|
||||
"currentStep": {
|
||||
"noticeParse": "Notice parsing",
|
||||
"parseConfirm": "Confirm parsing",
|
||||
"inventoryPrepare": "Inventory prep",
|
||||
"alignConfirm": "Confirm mapping",
|
||||
"inventoryMatch": "Inventory match",
|
||||
"shortageHandle": "Shortage handling",
|
||||
"generateExcel": "Generate Excel",
|
||||
"uploadFreight": "Upload to freight",
|
||||
"finishArchive": "Archive"
|
||||
},
|
||||
"stepDetail": {
|
||||
"title": "Step progress",
|
||||
"counter": "{current}/{total}"
|
||||
},
|
||||
"matchStatus": {
|
||||
"fulfillable": "Fully fulfillable",
|
||||
"partial": "Partially fulfillable",
|
||||
|
||||
@@ -79,6 +79,7 @@
|
||||
"taskTitle": "งานจัดส่ง",
|
||||
"currentTask": "งานปัจจุบัน {taskId}",
|
||||
"batchProgress": "รายการ {index}/{total}",
|
||||
"batchCurrentIndex": "กำลังประมวลผลรายการที่ {index}/{total}",
|
||||
"currentNotice": "ใบแจ้งปัจจุบัน",
|
||||
"prevTask": "ก่อนหน้า",
|
||||
"nextTask": "ถัดไป",
|
||||
@@ -94,6 +95,7 @@
|
||||
"fileCount": "จำนวนไฟล์",
|
||||
"runningCount": "กำลังดำเนินการ",
|
||||
"completedCount": "เสร็จแล้ว",
|
||||
"pendingCount": "รอดำเนินการ",
|
||||
"batchProgressTitle": "ความคืบหน้าของชุดงาน",
|
||||
"processing": "กำลังดำเนินการ",
|
||||
"status": {
|
||||
@@ -109,13 +111,19 @@
|
||||
},
|
||||
"currentStep": {
|
||||
"noticeParse": "แยกใบแจ้ง",
|
||||
"parseConfirm": "ยืนยันผลแยก",
|
||||
"inventoryPrepare": "เตรียมสต็อก",
|
||||
"alignConfirm": "ยืนยันการจับคู่คอลัมน์",
|
||||
"inventoryMatch": "จับคู่สต็อก",
|
||||
"shortageHandle": "จัดการส่วนขาด",
|
||||
"generateExcel": "สร้าง Excel",
|
||||
"uploadFreight": "อัปโหลดผู้ให้บริการขนส่ง",
|
||||
"finishArchive": "เก็บงาน"
|
||||
},
|
||||
"stepDetail": {
|
||||
"title": "ความคืบหน้าภายในขั้นตอน",
|
||||
"counter": "{current}/{total}"
|
||||
},
|
||||
"matchStatus": {
|
||||
"fulfillable": "จัดส่งได้ครบ",
|
||||
"partial": "จัดส่งได้บางส่วน",
|
||||
|
||||
@@ -79,6 +79,7 @@
|
||||
"taskTitle": "发货任务",
|
||||
"currentTask": "当前任务 {taskId}",
|
||||
"batchProgress": "第 {index}/{total} 票",
|
||||
"batchCurrentIndex": "当前处理第 {index}/{total} 票",
|
||||
"currentNotice": "当前通知",
|
||||
"prevTask": "上一票",
|
||||
"nextTask": "下一票",
|
||||
@@ -94,6 +95,7 @@
|
||||
"fileCount": "文件数",
|
||||
"runningCount": "处理中",
|
||||
"completedCount": "已完成",
|
||||
"pendingCount": "待处理",
|
||||
"batchProgressTitle": "批次进度",
|
||||
"processing": "处理中",
|
||||
"status": {
|
||||
@@ -109,13 +111,19 @@
|
||||
},
|
||||
"currentStep": {
|
||||
"noticeParse": "通知解析",
|
||||
"parseConfirm": "确认解析",
|
||||
"inventoryPrepare": "库存准备",
|
||||
"alignConfirm": "确认字段对齐",
|
||||
"inventoryMatch": "库存匹配",
|
||||
"shortageHandle": "缺口处理",
|
||||
"generateExcel": "生成 Excel",
|
||||
"uploadFreight": "上传货代",
|
||||
"finishArchive": "完成归档"
|
||||
},
|
||||
"stepDetail": {
|
||||
"title": "步骤内进度",
|
||||
"counter": "{current}/{total}"
|
||||
},
|
||||
"matchStatus": {
|
||||
"fulfillable": "可全部发货",
|
||||
"partial": "部分满足",
|
||||
|
||||
@@ -79,6 +79,7 @@
|
||||
"taskTitle": "發貨任務",
|
||||
"currentTask": "當前任務 {taskId}",
|
||||
"batchProgress": "第 {index}/{total} 票",
|
||||
"batchCurrentIndex": "當前處理第 {index}/{total} 票",
|
||||
"currentNotice": "當前通知",
|
||||
"prevTask": "上一票",
|
||||
"nextTask": "下一票",
|
||||
@@ -94,6 +95,7 @@
|
||||
"fileCount": "檔案數",
|
||||
"runningCount": "處理中",
|
||||
"completedCount": "已完成",
|
||||
"pendingCount": "待處理",
|
||||
"batchProgressTitle": "批次進度",
|
||||
"processing": "處理中",
|
||||
"status": {
|
||||
@@ -109,13 +111,19 @@
|
||||
},
|
||||
"currentStep": {
|
||||
"noticeParse": "通知解析",
|
||||
"parseConfirm": "確認解析",
|
||||
"inventoryPrepare": "庫存準備",
|
||||
"alignConfirm": "確認欄位對齊",
|
||||
"inventoryMatch": "庫存匹配",
|
||||
"shortageHandle": "缺口處理",
|
||||
"generateExcel": "生成 Excel",
|
||||
"uploadFreight": "上傳貨代",
|
||||
"finishArchive": "完成歸檔"
|
||||
},
|
||||
"stepDetail": {
|
||||
"title": "步驟內進度",
|
||||
"counter": "{current}/{total}"
|
||||
},
|
||||
"matchStatus": {
|
||||
"fulfillable": "可全部發貨",
|
||||
"partial": "部分滿足",
|
||||
|
||||
Reference in new issue
Block a user