feat(shipping, admin, workspace, docs): 迭代货代模块、补充文档并处理合并冲突问题

This commit is contained in:
hugo committed 2026-08-12 09:27:33 +08:00
1 parent 4587b56900
commit 3c0e08377c
94 files changed
+29222 -1218

No files matched your search

@@ -521,7 +521,10 @@ export function useChat() {
* 说明:
* - Dify Chatflow 失败时常以 `workflow_finished + data.status=failed` 返回,HTTP 仍是 200;
* - 若这里只按“终态成功”处理,页面会出现“没有任何响应”;
* - 因此需要优先从 top-level / nested data / error 对象里抽取失败文案。
* - 因此需要优先从 top-level / nested data / error 对象里抽取失败文案;
* - 上下文过长与缺省失败文案走 chat.streamError.contextTooLong / workflowFailed。
* @param data - SSE 事件 JSON
* @returns 用户可读错误;非失败终态返回空串
*/
const extractWorkflowFailureMessage = (data: Record<string, unknown>) => {
if (String(data.event || '') !== 'workflow_finished') return '';
@@ -543,11 +546,11 @@ export function useChat() {
const normalized = formatStreamError(candidate).trim();
if (!normalized || normalized === 'Unknown error') continue;
if (/maximum context length|input_tokens/i.test(normalized)) {
return '当前会话上下文过长,模型无法继续回答。请新建对话后重新查询该资产编号。';
return t('chat.streamError.contextTooLong');
}
return normalized;
}
return '工作流执行失败,请稍后重试';
return t('chat.streamError.workflowFailed');
};
const streamErrorLabels = (): StreamErrorLabels => ({
@@ -9,6 +9,7 @@ import { uploadChatFile } from '../api/chat.api';
import { createChatMessageAttachmentSnapshots } from '../utils/attachmentCard.utils';
import type { PendingAttachment } from '../types/shipping.types';
import type { ChatDeps } from './chat.deps';
import { isProcurementContractAgent as resolveProcurementContractAgent } from '@/shared/utils/agent-registry.utils';
type ChatUploadFileType = 'image' | 'document' | 'audio' | 'video' | 'custom';
@@ -26,6 +27,8 @@ const DIFY_SUPPORTED_EXTS: Record<Exclude<ChatUploadFileType, 'custom'>, Set<str
video: new Set(['mp4', 'mov', 'mpeg', 'webm']),
};
const PROCUREMENT_CONTRACT_EXTS = new Set(['pdf', 'doc', 'docx', 'txt', 'md', 'markdown']);
const extractExt = (value: string) => {
const text = (value || '').trim().toLowerCase();
const withoutQuery = (text.split('?')[0] || '').split('#')[0] || '';
@@ -79,9 +82,11 @@ export function useChatAttachments(options: UseChatAttachmentsOptions) {
return (currentAgent.value?.dify_parameters?.system_parameters as any) || {};
});
const isProcurementContractAgent = computed(() => resolveProcurementContractAgent(currentAgent.value));
const attachmentPolicy = computed(() => {
const fileUploadAllowed = currentAgent.value?.capabilities?.file_upload;
if (fileUploadAllowed === false) {
if (fileUploadAllowed === false && !isProcurementContractAgent.value) {
return {
anyEnabled: false,
enabled: {
@@ -175,6 +180,10 @@ export function useChatAttachments(options: UseChatAttachmentsOptions) {
}
}
if (isProcurementContractAgent.value) {
enabled.document = { local: true, remote: false, limit: 1 };
}
const mergedLimits = {
...(difySystemParameters.value || {}),
...(raw?.fileUploadConfig || {}),
@@ -192,6 +201,7 @@ export function useChatAttachments(options: UseChatAttachmentsOptions) {
const canLocal = Object.values(enabled).some((v) => v.local);
const canRemote = Object.values(enabled).some((v) => v.remote);
const totalLimit = (() => {
if (isProcurementContractAgent.value) return 1;
const v1 = raw?.fileUploadConfig?.file_upload_limit;
if (Number.isFinite(Number(v1))) return Number(v1);
const v2 = raw?.number_limits;
@@ -200,6 +210,7 @@ export function useChatAttachments(options: UseChatAttachmentsOptions) {
})();
const effectiveAllowedExts: Set<string> | null = (() => {
if (isProcurementContractAgent.value) return new Set(PROCUREMENT_CONTRACT_EXTS);
if (!allowedExts) return null;
const filtered = new Set<string>();
for (const ext of allowedExts) {
@@ -265,12 +276,12 @@ export function useChatAttachments(options: UseChatAttachmentsOptions) {
const files = Array.from(fileList);
for (const f of files) {
if (attachmentPolicy.value.totalLimit && attachments.value.length >= attachmentPolicy.value.totalLimit) {
msg.warning(t('chat.attachment.totalLimit', { limit: attachmentPolicy.value.totalLimit }));
msg.warning(t('chat.attachmentsUi.limitReached', { limit: attachmentPolicy.value.totalLimit }));
break;
}
const ext = extractExt(f.name || '');
if (attachmentPolicy.value.allowedExts && (!ext || !attachmentPolicy.value.allowedExts.has(ext))) {
msg.warning(t('chat.attachment.unsupportedFile', { name: f.name }));
msg.warning(t('chat.attachmentsUi.unsupportedType', { name: f.name }));
continue;
}
let type = inferFileTypeFromFile(f);
@@ -278,23 +289,23 @@ export function useChatAttachments(options: UseChatAttachmentsOptions) {
if (attachmentPolicy.value.enabled.custom.local && !isKnownDifyExt(ext)) {
type = 'custom';
} else {
msg.warning(t('chat.attachment.unsupportedFile', { name: f.name }));
msg.warning(t('chat.attachmentsUi.unsupportedType', { name: f.name }));
continue;
}
}
const caps = attachmentPolicy.value.enabled[type];
if (!caps?.local) {
msg.warning(t('chat.attachment.localTypeDisabled', { type }));
msg.warning(t('chat.attachmentsUi.typeNotAllowed', { type }));
continue;
}
const limit = attachmentPolicy.value.sizeLimitMb[type];
if (limit && f.size > limit * 1024 * 1024) {
msg.warning(t('chat.attachment.fileTooLarge', { limit, name: f.name }));
msg.warning(t('chat.attachmentsUi.tooLarge', { limit, name: f.name }));
continue;
}
const countSameType = attachments.value.filter((a) => a.type === type).length;
if (caps.limit && countSameType >= caps.limit) {
msg.warning(t('chat.attachment.typeLimit', { limit: caps.limit }));
msg.warning(t('chat.attachmentsUi.typeLimitReached', { limit: caps.limit }));
continue;
}
attachments.value.push({
@@ -314,20 +325,20 @@ export function useChatAttachments(options: UseChatAttachmentsOptions) {
if (!raw) return;
const url = raw.startsWith('//') ? `${window.location.protocol}${raw}` : raw;
if (!/^https?:\/\//i.test(url)) {
msg.warning(t('chat.attachment.httpOnly'));
msg.warning(t('chat.attachmentsUi.httpOnly'));
return;
}
if (!attachmentPolicy.value.canRemote) {
msg.warning(t('chat.attachment.remoteDisabled'));
msg.warning(t('chat.attachmentsUi.urlNotSupported'));
return;
}
if (attachmentPolicy.value.totalLimit && attachments.value.length >= attachmentPolicy.value.totalLimit) {
msg.warning(t('chat.attachment.totalLimit', { limit: attachmentPolicy.value.totalLimit }));
msg.warning(t('chat.attachmentsUi.limitReached', { limit: attachmentPolicy.value.totalLimit }));
return;
}
const ext = extractExt(url);
if (attachmentPolicy.value.allowedExts && (!ext || !attachmentPolicy.value.allowedExts.has(ext))) {
msg.warning(t('chat.attachment.unsupportedRemote'));
msg.warning(t('chat.attachmentsUi.unsupportedUrlType'));
return;
}
let type = inferFileTypeFromUrl(url);
@@ -335,18 +346,18 @@ export function useChatAttachments(options: UseChatAttachmentsOptions) {
if (attachmentPolicy.value.enabled.custom.remote && !isKnownDifyExt(ext)) {
type = 'custom';
} else {
msg.warning(t('chat.attachment.unsupportedRemote'));
msg.warning(t('chat.attachmentsUi.unsupportedUrlType'));
return;
}
}
const caps = attachmentPolicy.value.enabled[type];
if (!caps?.remote) {
msg.warning(t('chat.attachment.remoteTypeDisabled', { type }));
msg.warning(t('chat.attachmentsUi.urlTypeNotAllowed', { type }));
return;
}
const countSameType = attachments.value.filter((a) => a.type === type).length;
if (caps.limit && countSameType >= caps.limit) {
msg.warning(t('chat.attachment.typeLimit', { limit: caps.limit }));
msg.warning(t('chat.attachmentsUi.typeLimitReached', { limit: caps.limit }));
return;
}
attachments.value.push({ id: `${Date.now()}_${Math.random()}`, kind: 'remote', url, type });
@@ -3,6 +3,7 @@
* 用途:对话页主编排;组合 SSE、Agent、附件、请假/出货、路由同步与 page/* 子模块。
* 依赖:useChat* composables、shipping(含 openShippingCustomerDialog)、chat.api。
* 逻辑:ChatView provide(CHAT_PAGE_KEY);子树经 inject 打开客户确认等叠层。
* 兼容:同时编排采购合同审查与货代客户确认能力。
*/
import { computed, markRaw, nextTick, ref, watch } from 'vue';
import { storeToRefs } from 'pinia';
@@ -26,6 +27,7 @@ import { useChatRouteSync } from './useChatRouteSync';
import { useChatScroll } from './useChatScroll';
import { useChatSessions } from './useChatSessions';
import { useChatShipping } from './useChatShipping';
import { useProcurementContractChat } from './useProcurementContractChat';
import { useChatSourceFiles } from './useChatSourceFiles';
import { useChatAssetHistory } from './useChatAssetHistory';
import { useChatAssetImage } from './useChatAssetImage';
@@ -241,6 +243,8 @@ export function useChatPage() {
const { newLocalMessageId, saveLocalMessageToBackend } = createChatPageLocalMessageApi({
conversationId,
currentAgentId,
route,
router,
});
const pushLocalAssistantMessage = async (content: string) => {
@@ -305,6 +309,27 @@ export function useChatPage() {
});
resetShippingConversationState = shipping.resetShippingConversationState;
const procurement = useProcurementContractChat({
currentAgent: agent.currentAgent,
currentAgentId,
attachments: attachmentApi.attachments,
messages,
isThinking,
isUploadingAttachments: attachmentApi.isUploadingAttachments,
input,
clearAttachments: attachmentApi.clearAttachments,
saveLocalMessageToBackend: async (msg, userQuery) => { await saveLocalMessageToBackend(msg, userQuery); },
loadHistory,
msg,
t,
});
const allowsSendWithAttachmentsOnly = computed(
() =>
shipping.allowsSendWithAttachmentsOnly.value
|| procurement.allowsSendWithAttachmentsOnly.value,
);
/**
* 打开批次失败重试确认弹窗(会话摘要场景的兜底入口)。
*/
@@ -417,7 +442,7 @@ export function useChatPage() {
isUploadingAttachments: attachmentApi.isUploadingAttachments,
attachmentPolicy: attachmentApi.attachmentPolicy,
attachments: attachmentApi.attachments,
allowsSendWithAttachmentsOnly: shipping.allowsSendWithAttachmentsOnly,
allowsSendWithAttachmentsOnly,
buildFileSpecsForSend: attachmentApi.buildFileSpecsForSend,
createMessageAttachmentSnapshots: attachmentApi.createMessageAttachmentSnapshots,
clearAttachments: attachmentApi.clearAttachments,
@@ -450,6 +475,7 @@ export function useChatPage() {
tryHandleShippingAttachmentAutoFlow: shipping.tryHandleShippingAttachmentAutoFlow,
tryHandleLeaveSend: leave.tryHandleLeaveSend,
tryHandleShippingSend: shipping.tryHandleShippingSend,
tryHandleProcurementContractSend: procurement.tryHandleProcurementContractSend,
refreshToolRunProgressAfterSend: toolRun.refreshToolRunProgressAfterSend,
prepareToolRunProgressBeforeSend: toolRun.prepareToolRunProgressBeforeSend,
msg,
@@ -622,6 +648,13 @@ export function useChatPage() {
clearShippingToast: dialogs.clearShippingToast,
showChatRating,
isShippingNoticeAgent: shipping.isShippingNoticeAgent,
isProcurementContractAgent: procurement.isProcurementContractAgent,
procurementReviewMode: procurement.reviewMode,
procurementOriginalContractName: procurement.originalContractName,
handleProcurementOriginalContractSelected: procurement.handleOriginalContractSelected,
clearProcurementOriginalContract: procurement.clearOriginalContract,
showShippingProgressWorkspace: shipping.showShippingProgressWorkspace,
clearShippingFocus: shipping.clearShippingFocus,
shippingBatchSummary: shipping.shippingBatchSummary,
shippingConversationWorkspace: shipping.shippingConversationWorkspace,
activeShippingBatchNo: shipping.activeShippingBatchNo,
@@ -629,6 +662,7 @@ export function useChatPage() {
activeShippingTaskDetail: shipping.activeShippingTaskDetail,
getActiveOrderExtractionRunNo: shipping.getActiveOrderExtractionRunNo,
workflowRefreshTrigger: shipping.workflowRefreshTrigger,
bumpWorkflowRefresh: shipping.bumpWorkflowRefresh,
focusedConversationTaskNo: shipping.focusedConversationTaskNo,
setFocusedConversationTaskNo: shipping.setFocusedConversationTaskNo,
shippingInventorySelectionActive: shipping.shippingInventorySelectionActive,
@@ -730,10 +730,10 @@ export function useChatShipping(options: UseChatShippingOptions) {
getActiveShippingTaskId,
getActiveShippingBatchNo: () => resolvedShippingBatchNo.value || shippingBatchNoFromQuery.value || '',
loadHistory,
refreshShippingActions,
startChatTurn,
msg,
t,
refreshShippingActions,
startChatTurn,
msg,
t,
});
const {
@@ -752,10 +752,10 @@ export function useChatShipping(options: UseChatShippingOptions) {
});
const shippingIntakes = useShippingNoticeIntakes({
attachments,
conversationId,
msg,
t,
attachments,
conversationId,
msg,
t,
});
const workflowRefreshTrigger = ref(0);
const bumpWorkflowRefresh = () => {
@@ -763,6 +763,11 @@ export function useChatShipping(options: UseChatShippingOptions) {
};
/** 侧栏/提交共用的当前聚焦用户可见任务(OT-…)。 */
const focusedConversationTaskNo = ref<string | null>(null);
const showShippingProgressWorkspace = ref(false);
const clearShippingFocus = () => {
focusedConversationTaskNo.value = null;
void router.replace({ path: route.path, query: { ...route.query, focus_task_no: undefined, focus_notice: undefined } });
};
const setFocusedConversationTaskNo = (taskNo: string | null) => {
focusedConversationTaskNo.value = String(taskNo || '').trim() || null;
};
@@ -786,11 +791,11 @@ export function useChatShipping(options: UseChatShippingOptions) {
query: { ...route.query, conversation_id: resolvedConversationId },
});
},
onRetryError: (message) => msg.error(message),
onWorkflowRefresh: bumpWorkflowRefresh,
getFocusedUserTaskNo: () => focusedConversationTaskNo.value,
setFocusedUserTaskNo: setFocusedConversationTaskNo,
t,
onRetryError: (message) => msg.error(message),
onWorkflowRefresh: bumpWorkflowRefresh,
getFocusedUserTaskNo: () => focusedConversationTaskNo.value,
setFocusedUserTaskNo: setFocusedConversationTaskNo,
t,
});
const showShippingDuplicateDialog = ref(false);
@@ -964,7 +969,7 @@ export function useChatShipping(options: UseChatShippingOptions) {
const {
handleShippingAutoUploadFile,
handleShippingAutoUploadNoticeBatch,
handleShippingAutoUploadNoticeBatch,
openShippingInventoryPicker,
openShippingNoticePicker,
selectShippingInventoryUploadTask,
@@ -998,7 +1003,7 @@ export function useChatShipping(options: UseChatShippingOptions) {
clearConsumedNoticeAttachments: shippingIntakes.clearConsumedAttachments,
enqueueNoticeFiles: shippingIntakes.enqueueNoticeFiles,
startOrderExtractionRun: (...args) => shippingOrderExtractionRuns.startRun(...args),
sendTemporaryInventoryMessage: async (assetNo, fileName) => sendMessage(
sendTemporaryInventoryMessage: async (assetNo, fileName) => sendMessage(
`我已上传库存文件:${fileName},请先检查文件结构并说明下一步。`,
currentAgentId.value,
selectedKb.value,
@@ -1007,9 +1012,9 @@ export function useChatShipping(options: UseChatShippingOptions) {
shipping_temporary_inventory_asset_no: assetNo,
display_query: `上传库存文件:${fileName}`,
},
),
msg,
t,
),
msg,
t,
});
// 快览完成后补充可见的用户请求;用户已输入备注时绝不覆盖。
@@ -1031,9 +1036,9 @@ export function useChatShipping(options: UseChatShippingOptions) {
executeShippingDecision,
executeShippingManualUpload,
refreshShippingActions,
startChatTurn,
msg,
t,
startChatTurn,
msg,
t,
});
const { tryHandleShippingSend, tryHandleShippingAttachmentAutoFlow } = createShippingSendHandlers({
@@ -1071,18 +1076,18 @@ export function useChatShipping(options: UseChatShippingOptions) {
hasBlockingNoticeDuplicates: () => shippingIntakes.hasBlockingDuplicates.value,
hasCandidateReviewIssues: () => shippingIntakes.hasCandidateReviewIssues.value,
hasSelectedNoticeCandidates: () => shippingIntakes.getSelectedCandidateNos().length > 0,
openShippingDuplicateDialog,
openShippingDuplicateDialog,
getParsedIntakeNos: shippingIntakes.getParsedIntakeNos,
startOrderExtractionRun: shippingOrderExtractionRuns.startRun,
applyShippingMessageRecovery,
applyShippingBatchSnapshot,
syncShippingConversationWorkspace,
refreshShippingActions,
shippingSuggestedPrompt,
isShippingShortageQueryIntent,
queryShippingShortageDetails,
msg,
t,
syncShippingConversationWorkspace,
refreshShippingActions,
shippingSuggestedPrompt,
isShippingShortageQueryIntent,
queryShippingShortageDetails,
msg,
t,
});
// ── 路由 / 会话生命周期 ───────────────────────────────────
@@ -1348,8 +1353,11 @@ export function useChatShipping(options: UseChatShippingOptions) {
reparseOrderExtractionRun: shippingOrderExtractionRuns.reparseRun,
getActiveOrderExtractionRunNo: shippingOrderExtractionRuns.getActiveRunNo,
workflowRefreshTrigger,
bumpWorkflowRefresh,
focusedConversationTaskNo,
setFocusedConversationTaskNo,
clearShippingFocus,
showShippingProgressWorkspace,
shippingNoticeAllReadyForConfirmation: shippingIntakes.allReadyForConfirmation,
setShippingCandidateSelected,
resolveShippingCandidateDuplicate,