feat(chat): 完善附件预览与订单提取交互
- 优化聊天附件上传、预览及 PDF.js 加载 - 完善订单文档画布与审核预览体验 - 优化订单提取运行状态及发送流程 - 增强会话附件接口与相关测试覆盖 - 更新 Nginx 配置、技术文档及四语言文案
This commit is contained in:
1 parent
104afa3844
commit
9d2fa522fa
29 files changed
+584
-140
No files matched your search
@@ -4,6 +4,7 @@
|
||||
* 依赖:lucide 图标、附件完整性判断工具。
|
||||
* 逻辑:附件卡片位于文本框上方;订单审核结果随对应聊天消息展示,输入区只保留附件处理状态。
|
||||
* 同时支持采购合同双文件输入控件:底部左区放附件/合同等工具,右区语音与发送并排;采购合同审查用专用上传按钮,不展示通用回形针附件入口。
|
||||
* 货代订单抽取提交中(isOrderExtractionSubmitting)时发送钮展示 Loader,免责声明区提示提交中。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
||||
@@ -58,6 +59,8 @@ const props = defineProps<{
|
||||
isVoiceRecording: boolean;
|
||||
isVoiceTranscribing: boolean;
|
||||
isUploadingAttachments: boolean;
|
||||
/** 货代订单抽取统一提交进行中;为 true 时发送钮 Loader 且禁用。 */
|
||||
isOrderExtractionSubmitting?: boolean;
|
||||
canSendMessage: boolean;
|
||||
isShippingNoticeAgent: boolean;
|
||||
isProcurementContractAgent?: boolean;
|
||||
@@ -843,7 +846,7 @@ watch(
|
||||
</button>
|
||||
|
||||
<button
|
||||
v-if="isThinking && !isUploadingAttachments"
|
||||
v-if="isThinking && !isUploadingAttachments && !isOrderExtractionSubmitting"
|
||||
type="button"
|
||||
class="flex h-10 w-10 items-center justify-center rounded-full border border-rose-300 bg-rose-50 text-rose-600 shadow-sm transition-all duration-200 hover:scale-105 hover:bg-rose-100 active:scale-95"
|
||||
:title="$t('chat.stopGenerating')"
|
||||
@@ -862,14 +865,15 @@ watch(
|
||||
: 'border-brand-500 bg-brand-500 text-white shadow-[0_0_0_4px_rgba(59,130,246,0.18)] hover:scale-105 hover:bg-brand-600 hover:shadow-[0_0_0_6px_rgba(59,130,246,0.24)] active:scale-95'"
|
||||
@click="emit('send')"
|
||||
>
|
||||
<Loader2 v-if="isUploadingAttachments" class="h-4 w-4 animate-spin" />
|
||||
<Loader2 v-if="isUploadingAttachments || isOrderExtractionSubmitting" class="h-4 w-4 animate-spin" />
|
||||
<Send v-else class="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-3 text-center text-[11px] text-muted">
|
||||
<span v-if="isThinking">{{ $t('chat.thinking') }}</span>
|
||||
<span v-if="isOrderExtractionSubmitting">{{ $t('chat.shippingNoticeSubmitting') }}</span>
|
||||
<span v-else-if="isThinking">{{ $t('chat.thinking') }}</span>
|
||||
<span v-else>{{ $t('chat.disclaimer') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -607,6 +607,8 @@ watch(() => page.currentAgentId, () => {
|
||||
|
||||
:is-uploading-attachments="page.isUploadingAttachments"
|
||||
|
||||
:is-order-extraction-submitting="page.isOrderExtractionSubmitting"
|
||||
|
||||
:can-send-message="page.canSendMessage"
|
||||
|
||||
:is-shipping-notice-agent="page.isShippingNoticeAgent"
|
||||
|
||||
@@ -9,33 +9,13 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { loadPdfJs } from '@/shared/utils/pdfjs';
|
||||
import type { ShippingOrderReviewEvidence } from '../../types/shipping.api.types';
|
||||
import { normalizedTopLeftBBoxToViewportRect } from './pdfHighlightCoords';
|
||||
|
||||
/** 有合法 bbox 时四种质量都绘制;颜色只提示可信度,不隐藏取值位置。 */
|
||||
const DRAWABLE_QUALITIES = new Set(['verified', 'candidate', 'unavailable', 'invalid']);
|
||||
|
||||
type PdfJsModule = typeof import('pdfjs-dist');
|
||||
|
||||
let pdfjsLoader: Promise<PdfJsModule> | null = null;
|
||||
|
||||
/**
|
||||
* 动态加载 pdfjs 与 worker;同页复用单例 Promise。
|
||||
*/
|
||||
async function loadPdfJs(): Promise<PdfJsModule> {
|
||||
if (!pdfjsLoader) {
|
||||
pdfjsLoader = (async () => {
|
||||
const [pdfjs, workerMod] = await Promise.all([
|
||||
import('pdfjs-dist'),
|
||||
import('pdfjs-dist/build/pdf.worker.min.mjs?url'),
|
||||
]);
|
||||
pdfjs.GlobalWorkerOptions.workerSrc = workerMod.default;
|
||||
return pdfjs;
|
||||
})();
|
||||
}
|
||||
return pdfjsLoader;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
src: string;
|
||||
evidence?: ShippingOrderReviewEvidence | null;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* 依赖:useChat* composables、shipping(含 openShippingCustomerDialog)、chat.api。
|
||||
* 逻辑:ChatView provide(CHAT_PAGE_KEY);子树经 inject 打开客户确认等叠层。
|
||||
* 兼容:同时编排采购合同审查与货代客户确认能力。
|
||||
* 货代发送禁用态经 hasBlockingNoticeIntake / isOrderExtractionSubmitting 注入 createChatPageSendApi。
|
||||
*/
|
||||
import { computed, markRaw, nextTick, ref, watch } from 'vue';
|
||||
import { storeToRefs } from 'pinia';
|
||||
@@ -446,6 +447,8 @@ export function useChatPage() {
|
||||
tryHandleProcurementContractSend: procurement.tryHandleProcurementContractSend,
|
||||
refreshToolRunProgressAfterSend: toolRun.refreshToolRunProgressAfterSend,
|
||||
prepareToolRunProgressBeforeSend: toolRun.prepareToolRunProgressBeforeSend,
|
||||
hasBlockingNoticeIntake: shipping.hasBlockingNoticeIntake,
|
||||
isOrderExtractionSubmitting: shipping.isOrderExtractionSubmitting,
|
||||
msg,
|
||||
t,
|
||||
copiedIndex,
|
||||
@@ -593,6 +596,7 @@ export function useChatPage() {
|
||||
messageBubbleHandlers: markdown.messageBubbleHandlers,
|
||||
shouldRenderMessage: markdown.shouldRenderMessage,
|
||||
canSendMessage: sendApi.canSendMessage,
|
||||
isOrderExtractionSubmitting: shipping.isOrderExtractionSubmitting,
|
||||
handleSend: sendApi.handleSend,
|
||||
stopActiveGeneration,
|
||||
pushLocalAssistantMessage,
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* 逻辑:上游由 ChatView/ChatPage 调用本 composable;本文件维护会话任务摘要 + ui_state 同步,
|
||||
* 以及 focusedConversationTaskNo(提交追加优先级 / 侧栏焦点)。会话恢复唯一使用 task_no;
|
||||
* 批次进度由 shipping-processing projection 承接,不维护已下线 shipping_batches 的本地快照。
|
||||
* 对外暴露 isOrderExtractionSubmitting / hasBlockingNoticeIntake,供发送禁用与输入区 loading。
|
||||
*/
|
||||
|
||||
import {
|
||||
@@ -979,6 +980,8 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
cancelOrderExtractionUnit: shippingOrderExtractionRuns.cancelUnit,
|
||||
reparseOrderExtractionRun: shippingOrderExtractionRuns.reparseRun,
|
||||
getActiveOrderExtractionRunNo: shippingOrderExtractionRuns.getActiveRunNo,
|
||||
isOrderExtractionSubmitting: shippingOrderExtractionRuns.isOrderExtractionSubmitting,
|
||||
hasBlockingNoticeIntake: () => shippingIntakes.hasBlockingUploadOrParse.value,
|
||||
workflowRefreshTrigger,
|
||||
bumpWorkflowRefresh,
|
||||
focusedConversationTaskNo,
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
* features/chat/page/useChatPageSend.spec.ts
|
||||
* 用途:验证普通聊天发送时附件失败保留、消息成功后清空的恢复语义。
|
||||
* 依赖:Vitest、Vue 响应式 API、useChatPageSend。
|
||||
* 逻辑:构造最小发送上下文,分别模拟上传失败、SSE 发送失败与发送成功。
|
||||
* 逻辑:构造最小发送上下文,分别模拟上传失败、SSE 发送失败与发送成功;
|
||||
* 另覆盖货代 blocking / submitting 对 canSendMessage 的早禁用。
|
||||
*/
|
||||
import { computed, ref } from 'vue';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
@@ -119,3 +120,32 @@ describe('createChatPageSendApi attachment lifecycle', () => {
|
||||
expect(ctx.clearAttachments).toHaveBeenCalledOnce();
|
||||
});
|
||||
});
|
||||
|
||||
describe('createChatPageSendApi canSendMessage shipping gates', () => {
|
||||
it('disables send when hasBlockingNoticeIntake returns true', () => {
|
||||
const ctx = createContext({
|
||||
hasBlockingNoticeIntake: () => true,
|
||||
});
|
||||
|
||||
// 解析/上传未完成时必须早禁用,避免点发送后空等。
|
||||
expect(createChatPageSendApi(ctx).canSendMessage.value).toBe(false);
|
||||
});
|
||||
|
||||
it('disables send while isOrderExtractionSubmitting is true', () => {
|
||||
const ctx = createContext({
|
||||
isOrderExtractionSubmitting: ref(true),
|
||||
});
|
||||
|
||||
// 统一提交进行中禁止重复点击。
|
||||
expect(createChatPageSendApi(ctx).canSendMessage.value).toBe(false);
|
||||
});
|
||||
|
||||
it('allows send when neither blocking nor submitting', () => {
|
||||
const ctx = createContext({
|
||||
hasBlockingNoticeIntake: () => false,
|
||||
isOrderExtractionSubmitting: ref(false),
|
||||
});
|
||||
|
||||
expect(createChatPageSendApi(ctx).canSendMessage.value).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -4,6 +4,7 @@
|
||||
* 依赖:统一 BusinessError、剪贴板工具、Chat 消息与附件参数类型。
|
||||
* 逻辑:附件上传成功后调用 Dify SSE;仅在消息发送成功后清空附件,失败时保留供重试。
|
||||
* 兼容:依次处理货代附件、采购合同、请假与货代文本前置拦截。
|
||||
* 货代路径另受 hasBlockingNoticeIntake / isOrderExtractionSubmitting 约束 canSendMessage。
|
||||
*/
|
||||
import { computed } from 'vue';
|
||||
import { BusinessError } from '@/shared/api/client';
|
||||
@@ -83,10 +84,26 @@ export interface ChatPageSendContext {
|
||||
copiedIndex: Ref<number | null>;
|
||||
getChatContext?: () => { task_id?: string; shipping_temporary_inventory_asset_no?: string; shipping_temporary_inventory_session_no?: string; display_query?: string };
|
||||
onAssistantMessageFinished?: (message: ChatMessage, runMessages: ChatMessage[]) => void | Promise<void>;
|
||||
/** 货代 Intake 仍在上传/解析时返回 true,用于早禁用发送。 */
|
||||
hasBlockingNoticeIntake?: () => boolean;
|
||||
/** 订单抽取统一提交进行中;为 true 时禁用发送并展示 Loader。 */
|
||||
isOrderExtractionSubmitting?: Ref<boolean>;
|
||||
}
|
||||
|
||||
/**
|
||||
* 组装聊天页发送 API:canSendMessage / handleSend / 复制 / 重新生成。
|
||||
* 核心逻辑:货代 blocking/submitting 优先禁用;附件失败保留、成功后清空。
|
||||
* @param ctx - 页面发送所需的响应式状态与业务钩子。
|
||||
* @returns 发送相关计算属性与方法。
|
||||
*/
|
||||
export function createChatPageSendApi(ctx: ChatPageSendContext) {
|
||||
/**
|
||||
* 是否允许点击发送。
|
||||
* 核心逻辑:上传中、订单抽取提交中、或 Intake 阻塞解析时一律 false;其余沿用输入/附件/thinking 规则。
|
||||
*/
|
||||
const canSendMessage = computed(() => {
|
||||
if (ctx.isOrderExtractionSubmitting?.value) return false;
|
||||
if (ctx.hasBlockingNoticeIntake?.()) return false;
|
||||
const allowSendWhileThinking = canContinueSendWhileThinking(ctx.messages.value);
|
||||
if (ctx.isUploadingAttachments.value) return false;
|
||||
if (ctx.input.value.trim()) return !ctx.isThinking.value || allowSendWhileThinking;
|
||||
@@ -99,11 +116,19 @@ export function createChatPageSendApi(ctx: ChatPageSendContext) {
|
||||
return false;
|
||||
});
|
||||
|
||||
/**
|
||||
* 处理发送:依次尝试货代附件自动流、采购合同、请假、货代文本,否则走通用 SSE。
|
||||
* @param textOrEvent - 可选字符串覆盖输入框内容,或来自 UI 事件。
|
||||
*/
|
||||
const handleSend = async (textOrEvent?: string | Event) => {
|
||||
const content = (typeof textOrEvent === 'string' ? textOrEvent : null) || ctx.input.value;
|
||||
const trimmed = content.trim();
|
||||
const hasAttachments = ctx.attachmentPolicy.value.anyEnabled && ctx.attachments.value.length > 0;
|
||||
const allowSendWhileThinking = canContinueSendWhileThinking(ctx.messages.value);
|
||||
// [STEP 0] 提交中禁止重复触发(含 Enter);Intake 阻塞仍交给货代 handler 提示,不在此静默吞掉。
|
||||
if (ctx.isOrderExtractionSubmitting?.value) {
|
||||
return;
|
||||
}
|
||||
if (await ctx.tryHandleShippingAttachmentAutoFlow(textOrEvent, content, trimmed)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -250,6 +250,31 @@ describe('useChatShippingSendHandler', () => {
|
||||
expect(ctx.msg.warning).toHaveBeenCalledWith('run create failed');
|
||||
});
|
||||
|
||||
it('blocks order extraction when notice attachments exceed chat snapshot limit', async () => {
|
||||
const many = Array.from({ length: 201 }, (_, i) => ({
|
||||
id: `notice-${i}`,
|
||||
kind: 'shipping_notice' as const,
|
||||
type: 'document' as const,
|
||||
uploadStatus: 'uploaded' as const,
|
||||
parseStatus: 'parsed' as const,
|
||||
uploadProgress: 100,
|
||||
originalFilename: `orders-${i}.eml`,
|
||||
fileSize: 100,
|
||||
intakeNo: `SNI-${i}`,
|
||||
}));
|
||||
const startOrderExtractionRun = vi.fn(async () => true);
|
||||
const ctx = createContext({
|
||||
attachments: ref(many),
|
||||
getParsedIntakeNos: () => many.map((item) => item.intakeNo),
|
||||
startOrderExtractionRun,
|
||||
});
|
||||
const { tryHandleShippingAttachmentAutoFlow } = createShippingSendHandlers(ctx);
|
||||
const handled = await tryHandleShippingAttachmentAutoFlow(undefined, '', '');
|
||||
expect(handled).toBe(true);
|
||||
expect(startOrderExtractionRun).not.toHaveBeenCalled();
|
||||
expect(ctx.msg.warning).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('warns and consumes send when user tries batch task switching (co8 batch API retired)', async () => {
|
||||
const ctx = createContext({
|
||||
});
|
||||
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
import { resolveShippingDecisionFromText, resolveShippingNumericChoice } from './shippingMenu';
|
||||
import { isShippingSpreadsheetFile, isTemporaryInventoryDeclaration } from './shippingUploadPrompt';
|
||||
import { extractExt } from '../constants/shipping';
|
||||
import { createChatMessageAttachmentSnapshots } from '../utils/attachmentCard.utils';
|
||||
import { CHAT_USER_ATTACHMENT_LIMIT, createChatMessageAttachmentSnapshots } from '../utils/attachmentCard.utils';
|
||||
import type { SendMessageLifecycleHooks } from '../composables/useChat';
|
||||
import type { ChatMessageSendResult, StartChatTurnOptions } from '../types/chat-turn.types';
|
||||
import type { ChatMessage, ChatSessionItem } from '../types/chat.types';
|
||||
@@ -101,6 +101,15 @@ export function createShippingSendHandlers(ctx: ShippingSendHandlerContext) {
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* 拦截发货通知附件自动流程(订单抽取、本地表格/邮件入队)。
|
||||
*
|
||||
* 核心逻辑:已解析 Intake 走 startOrderExtractionRun;快照数超 CHAT_USER_ATTACHMENT_LIMIT 时 warning 并消费发送。
|
||||
* @param textOrEvent - 发送触发源(按钮或文本)
|
||||
* @param _content - 原始输入(保留供后续分支)
|
||||
* @param trimmed - 去空白后的用户正文
|
||||
* @returns 已消费本次发送时为 true
|
||||
*/
|
||||
const tryHandleShippingAttachmentAutoFlow = async (
|
||||
textOrEvent: string | Event | undefined,
|
||||
_content: string,
|
||||
@@ -132,6 +141,10 @@ export function createShippingSendHandlers(ctx: ShippingSendHandlerContext) {
|
||||
&& submittedIntakes.has(item.intakeNo.trim().toUpperCase()),
|
||||
),
|
||||
);
|
||||
if (userAttachments.length > CHAT_USER_ATTACHMENT_LIMIT) {
|
||||
ctx.msg.warning(ctx.t('chat.attachmentsUi.limitReached', { limit: CHAT_USER_ATTACHMENT_LIMIT }));
|
||||
return true;
|
||||
}
|
||||
// 空备注不伪造用户正文;订单抽取动作由结构化 Run 提交承载,用户消息只保留附件快照。
|
||||
const query = trimmed;
|
||||
ctx.shippingAutoFlowRequested.value = false;
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
* features/chat/shipping/useShippingOrderExtractionRuns.spec.ts
|
||||
* 用途:验证订单抽取 Run 的状态映射、单状态卡消息持久化与轮询生命周期。
|
||||
* 依赖:Vitest、Vue refs、shipping.api mock、useShippingOrderExtractionRuns。
|
||||
* 逻辑:覆盖新建/追加提交不生成重复反馈气泡、状态契约、无变化轮询及恢复隔离。
|
||||
* 逻辑:覆盖新建/追加提交不生成重复反馈气泡、状态契约、无变化轮询及恢复隔离;
|
||||
* 另覆盖 startRun 期间 isOrderExtractionSubmitting 的 true→false(含失败 finally)。
|
||||
*/
|
||||
import { computed, ref } from 'vue';
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
@@ -136,6 +137,52 @@ describe('useShippingOrderExtractionRuns lifecycle', () => {
|
||||
harness.runs.stopPolling();
|
||||
});
|
||||
|
||||
it('sets isOrderExtractionSubmitting true during startRun and false after success', async () => {
|
||||
const submissionGate = deferred<{
|
||||
decision: string;
|
||||
user_task_no: string;
|
||||
run_no: string;
|
||||
created_new: boolean;
|
||||
operation_id: string;
|
||||
}>();
|
||||
api.createSubmission.mockReturnValue(submissionGate.promise);
|
||||
api.getRun.mockResolvedValue(run({
|
||||
run_no: 'SNER-SUBMIT',
|
||||
conversation_id: 'conv-submit',
|
||||
user_task_no: 'OT-SUBMIT',
|
||||
}));
|
||||
const harness = createHarness();
|
||||
|
||||
const pending = harness.runs.startRun('提交中', ['SNI-1'], [], 'batch-submit');
|
||||
// 断言:请求尚未返回时必须处于提交中,驱动发送钮 loading。
|
||||
expect(harness.runs.isOrderExtractionSubmitting.value).toBe(true);
|
||||
|
||||
submissionGate.resolve({
|
||||
decision: 'created',
|
||||
user_task_no: 'OT-SUBMIT',
|
||||
run_no: 'SNER-SUBMIT',
|
||||
created_new: true,
|
||||
operation_id: 'op-submit',
|
||||
});
|
||||
await pending;
|
||||
|
||||
// 断言:成功结束后清除 submitting;用户气泡仅在成功路径出现。
|
||||
expect(harness.runs.isOrderExtractionSubmitting.value).toBe(false);
|
||||
expect(harness.messages.value.some((item) => item.role === 'user')).toBe(true);
|
||||
harness.runs.stopPolling();
|
||||
});
|
||||
|
||||
it('clears isOrderExtractionSubmitting in finally when startRun fails', async () => {
|
||||
api.createSubmission.mockRejectedValue(new Error('submit failed'));
|
||||
const harness = createHarness();
|
||||
|
||||
await expect(harness.runs.startRun('失败', ['SNI-1'], [])).rejects.toThrow('submit failed');
|
||||
|
||||
// 断言:失败路径不得残留 submitting,且不得插入用户气泡。
|
||||
expect(harness.runs.isOrderExtractionSubmitting.value).toBe(false);
|
||||
expect(harness.messages.value).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('keeps the submitted Run card independent from sibling Runs in the same upload batch', async () => {
|
||||
const first = Object.assign(run({
|
||||
run_no: 'SNER-BATCH-1',
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
* 持久化去重签名必须包含 handling_items / primary_notice,避免处理说明变化后历史会话仍读到旧卡。
|
||||
* 会话恢复锚定 submission primary(client_submission_id)或已有进度卡,禁止 sibling Run 再写第二张卡。
|
||||
*/
|
||||
import { getCurrentInstance, onBeforeUnmount, type ComputedRef, type Ref } from 'vue';
|
||||
import { getCurrentInstance, onBeforeUnmount, ref, type ComputedRef, type Ref } from 'vue';
|
||||
import {
|
||||
cancelWorkspaceShippingOrderExtractionDocument,
|
||||
cancelWorkspaceShippingOrderExtractionRun,
|
||||
@@ -221,6 +221,8 @@ export function useShippingOrderExtractionRuns(options: UseShippingOrderExtracti
|
||||
/** 输入区短生命周期上下文;切会话时轮换,同会话多次发送可命中追加优先级第 1 档。 */
|
||||
let composerContextId = createComposerContextId();
|
||||
let composerBoundConversationId = String(options.conversationId.value || '').trim();
|
||||
/** 统一提交进行中:驱动发送钮 loading,并禁止重复点击;成功后才 push 用户气泡。 */
|
||||
const isOrderExtractionSubmitting = ref(false);
|
||||
|
||||
/**
|
||||
* 确保 composer_context_id 绑定当前会话;会话变化时轮换。
|
||||
@@ -462,6 +464,7 @@ export function useShippingOrderExtractionRuns(options: UseShippingOrderExtracti
|
||||
|
||||
/**
|
||||
* 启动订单抽取统一提交:后端裁决 append/create,并只持久化用户操作与唯一 Run 状态卡。
|
||||
* 核心逻辑:进入时置 submitting,API 成功后再 push 用户气泡与进度卡;finally 清 submitting(含失败)。
|
||||
* @param query - 用户本次备注;为空时用户消息仅展示附件,不伪造默认正文。
|
||||
* @param intakeNos - 本次冻结的 Intake 编号。
|
||||
* @param attachments - 用户消息中的安全附件快照。
|
||||
@@ -475,57 +478,62 @@ export function useShippingOrderExtractionRuns(options: UseShippingOrderExtracti
|
||||
uploadBatchId?: string,
|
||||
): Promise<boolean> => {
|
||||
stopPolling();
|
||||
const submissionId = createShippingSubmissionId();
|
||||
const composerContext = ensureComposerContext();
|
||||
const focusedUserTaskNo = String(options.getFocusedUserTaskNo?.() || '').trim() || null;
|
||||
const submission = await createWorkspaceOrderExtractionSubmission({
|
||||
agent_id: options.currentAgentId.value,
|
||||
conversation_id: options.conversationId.value || '',
|
||||
intake_nos: intakeNos,
|
||||
submission_id: submissionId,
|
||||
upload_batch_id: uploadBatchId || undefined,
|
||||
composer_context_id: composerContext,
|
||||
focused_user_task_no: focusedUserTaskNo,
|
||||
});
|
||||
// 统一提交只返回决策摘要;再拉 Run 投影供状态卡与轮询。
|
||||
const submittedRun = await getWorkspaceShippingOrderExtractionRun(submission.run_no);
|
||||
const run = await loadDisplayRun(submittedRun);
|
||||
if (!options.conversationId.value) {
|
||||
options.conversationId.value = run.conversation_id;
|
||||
composerBoundConversationId = run.conversation_id;
|
||||
isOrderExtractionSubmitting.value = true;
|
||||
try {
|
||||
const submissionId = createShippingSubmissionId();
|
||||
const composerContext = ensureComposerContext();
|
||||
const focusedUserTaskNo = String(options.getFocusedUserTaskNo?.() || '').trim() || null;
|
||||
const submission = await createWorkspaceOrderExtractionSubmission({
|
||||
agent_id: options.currentAgentId.value,
|
||||
conversation_id: options.conversationId.value || '',
|
||||
intake_nos: intakeNos,
|
||||
submission_id: submissionId,
|
||||
upload_batch_id: uploadBatchId || undefined,
|
||||
composer_context_id: composerContext,
|
||||
focused_user_task_no: focusedUserTaskNo,
|
||||
});
|
||||
// 统一提交只返回决策摘要;再拉 Run 投影供状态卡与轮询。
|
||||
const submittedRun = await getWorkspaceShippingOrderExtractionRun(submission.run_no);
|
||||
const run = await loadDisplayRun(submittedRun);
|
||||
if (!options.conversationId.value) {
|
||||
options.conversationId.value = run.conversation_id;
|
||||
composerBoundConversationId = run.conversation_id;
|
||||
}
|
||||
|
||||
const userMessage: ChatMessage = {
|
||||
role: 'user',
|
||||
type: 'text',
|
||||
content: query,
|
||||
attachments,
|
||||
local_id: options.newLocalMessageId('shipping-order-extraction-user'),
|
||||
local_only: true,
|
||||
payload: {
|
||||
formId: `shipping-order-extraction-user:${run.run_no}`,
|
||||
order_extraction_run_no: run.run_no,
|
||||
user_task_no: submission.user_task_no,
|
||||
submission_decision: submission.decision,
|
||||
},
|
||||
};
|
||||
options.messages.value.push(userMessage);
|
||||
await options.saveLocalMessageToBackend(userMessage, query || undefined);
|
||||
|
||||
// 新建任务自动聚焦;追加则保持/回写当前 OT。
|
||||
options.setFocusedUserTaskNo?.(submission.user_task_no || null);
|
||||
|
||||
await upsertRunMessage(run);
|
||||
await acknowledgeTerminalRunWhenVisible(run);
|
||||
await options.onConversationResolved(run.conversation_id);
|
||||
options.onWorkflowRefresh?.();
|
||||
if (ACTIVE_RUN_STATUSES.has(run.status)) {
|
||||
beginPolling(submittedRun.run_no, 1000);
|
||||
} else {
|
||||
const reviewAttachments = await refreshTerminalFacts(run);
|
||||
await upsertRunMessage(run, reviewAttachments);
|
||||
}
|
||||
return true;
|
||||
} finally {
|
||||
isOrderExtractionSubmitting.value = false;
|
||||
}
|
||||
|
||||
const userMessage: ChatMessage = {
|
||||
role: 'user',
|
||||
type: 'text',
|
||||
content: query,
|
||||
attachments,
|
||||
local_id: options.newLocalMessageId('shipping-order-extraction-user'),
|
||||
local_only: true,
|
||||
payload: {
|
||||
formId: `shipping-order-extraction-user:${run.run_no}`,
|
||||
order_extraction_run_no: run.run_no,
|
||||
user_task_no: submission.user_task_no,
|
||||
submission_decision: submission.decision,
|
||||
},
|
||||
};
|
||||
options.messages.value.push(userMessage);
|
||||
await options.saveLocalMessageToBackend(userMessage, query || undefined);
|
||||
|
||||
// 新建任务自动聚焦;追加则保持/回写当前 OT。
|
||||
options.setFocusedUserTaskNo?.(submission.user_task_no || null);
|
||||
|
||||
await upsertRunMessage(run);
|
||||
await acknowledgeTerminalRunWhenVisible(run);
|
||||
await options.onConversationResolved(run.conversation_id);
|
||||
options.onWorkflowRefresh?.();
|
||||
if (ACTIVE_RUN_STATUSES.has(run.status)) {
|
||||
beginPolling(submittedRun.run_no, 1000);
|
||||
} else {
|
||||
const reviewAttachments = await refreshTerminalFacts(run);
|
||||
await upsertRunMessage(run, reviewAttachments);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
/** 复用原 Run 的冻结附件重新识别,并恢复同一状态卡的轮询。 */
|
||||
@@ -803,5 +811,6 @@ export function useShippingOrderExtractionRuns(options: UseShippingOrderExtracti
|
||||
clearActiveRun,
|
||||
updateCandidateReviewSnapshot,
|
||||
getActiveRunNo: () => activeRunNo,
|
||||
isOrderExtractionSubmitting,
|
||||
};
|
||||
}
|
||||
@@ -8,6 +8,9 @@ import type { ChatMessageAttachment } from '../types/chat.types';
|
||||
import type { AttachmentUiStatus, PendingAttachment } from '../types/shipping.types';
|
||||
import { isShippingNoticeAttachmentParseIncomplete } from '../shipping/shippingNoticeAttachmentIntegrity';
|
||||
|
||||
/** 与后端 CHAT_USER_ATTACHMENT_LIMIT 对齐;超过则发送前拦截,禁止静默截断。 */
|
||||
export const CHAT_USER_ATTACHMENT_LIMIT = 200;
|
||||
|
||||
export interface AttachmentCardStatus {
|
||||
state: AttachmentUiStatus;
|
||||
labelKey: string;
|
||||
|
||||
Reference in new issue
Block a user