- 移除 Agent 的 exposure_mode 与 internal_executor 相关逻辑,清理关联的过滤、序列化代码 - 删除废弃的 AgentRuntimeBinding 模型及其依赖 - 新增订单抽取上传批次、请求快照等数据库迁移与业务逻辑 - 修复附件完整性检测、订单抽取状态映射问题 - 更新多语言错误文案与前端单元测试配置 - 清理平台配置中不再使用的暴露模式配置
303 lines
12 KiB
Vue
303 lines
12 KiB
Vue
<script setup lang="ts">
|
|
/**
|
|
* features/chat/components/shipping/ShippingOrderExtractionCard.vue
|
|
* 用途:渲染聊天中的订单抽取摘要卡,并在需要时打开 PDF 详情抽屉。
|
|
* 依赖:订单抽取 Run 状态卡 DTO、documents API、详情抽屉。
|
|
* 逻辑:卡片只显示 Run 汇总、当前活动和下一步动作;逐 PDF 结果与 Run 事实时间线延迟到抽屉内按需加载。
|
|
*/
|
|
import { computed, ref, watch } from 'vue';
|
|
import { useI18n } from 'vue-i18n';
|
|
import { CircleCheck, CircleX, LoaderCircle, TriangleAlert } from 'lucide-vue-next';
|
|
import {
|
|
listWorkspaceShippingOrderExtractionDocuments,
|
|
listWorkspaceShippingOrderExtractionProgressEvents,
|
|
} from '../../api/shipping.api';
|
|
import type { ShippingOrderExtractionState } from '../../types/chat.types';
|
|
import type {
|
|
ShippingOrderExtractionDocumentResult,
|
|
ShippingOrderExtractionProgressEvent,
|
|
} from '../../types/shipping.api.types';
|
|
import ShippingOrderExtractionDetailsDrawer from './ShippingOrderExtractionDetailsDrawer.vue';
|
|
|
|
const props = defineProps<{
|
|
state: ShippingOrderExtractionState;
|
|
runNo?: string;
|
|
hasReviewAttachments?: boolean;
|
|
}>();
|
|
|
|
const emit = defineEmits<{
|
|
retry: [];
|
|
enterManualReview: [];
|
|
}>();
|
|
|
|
const { t, te } = useI18n();
|
|
|
|
const detailsOpen = ref(false);
|
|
const documents = ref<ShippingOrderExtractionDocumentResult[]>([]);
|
|
const progressEvents = ref<ShippingOrderExtractionProgressEvent[]>([]);
|
|
const loadingDocuments = ref(false);
|
|
const documentsLoadFailed = ref(false);
|
|
const documentsLoadedForRun = ref('');
|
|
const loadingProgressEvents = ref(false);
|
|
const progressEventsLoadFailed = ref(false);
|
|
const progressEventsLoadedForRun = ref('');
|
|
|
|
watch(
|
|
() => props.runNo,
|
|
() => {
|
|
detailsOpen.value = false;
|
|
documents.value = [];
|
|
progressEvents.value = [];
|
|
loadingDocuments.value = false;
|
|
loadingProgressEvents.value = false;
|
|
documentsLoadFailed.value = false;
|
|
progressEventsLoadFailed.value = false;
|
|
documentsLoadedForRun.value = '';
|
|
progressEventsLoadedForRun.value = '';
|
|
},
|
|
);
|
|
|
|
const toneClass = computed(() => {
|
|
switch (props.state.status) {
|
|
case 'completed':
|
|
return 'border-emerald-200 bg-emerald-50/80 text-emerald-950 dark:border-emerald-800 dark:bg-emerald-950/35 dark:text-emerald-100';
|
|
case 'partially_completed':
|
|
case 'review_required':
|
|
return 'border-amber-200 bg-amber-50/80 text-amber-950 dark:border-amber-800 dark:bg-amber-950/35 dark:text-amber-100';
|
|
case 'failed':
|
|
case 'cancelled':
|
|
return 'border-rose-200 bg-rose-50/80 text-rose-900 dark:border-rose-800 dark:bg-rose-950/35 dark:text-rose-100';
|
|
default:
|
|
return 'border-sky-200 bg-sky-50/80 text-sky-900 dark:border-sky-800 dark:bg-sky-950/35 dark:text-sky-100';
|
|
}
|
|
});
|
|
|
|
const titleKey = computed(() => `chat.shippingOrderExtractionCardTitle.${props.state.status}`);
|
|
const activityKey = computed(() => {
|
|
const code = String(props.state.currentActivity?.eventCode || '').trim();
|
|
const key = `chat.shippingOrderExtractionActivity.${code}`;
|
|
return code && te(key) ? key : 'chat.shippingOrderExtractionActivity.generic_processing';
|
|
});
|
|
const completedLabel = computed(() => `${props.state.summary.completedDocuments} / ${props.state.summary.totalDocuments}`);
|
|
const selectionSummaryItems = computed(() => {
|
|
const selectionPlan = props.state.selectionPlan;
|
|
const unitSummary = props.state.unitSummary;
|
|
return [
|
|
selectionPlan?.selectedAttachmentCount
|
|
? t('chat.shippingOrderExtractionPlanSelected', { count: selectionPlan.selectedAttachmentCount })
|
|
: '',
|
|
selectionPlan?.pendingExpansionAttachmentCount
|
|
? t('chat.shippingOrderExtractionPlanPendingExpansion', { count: selectionPlan.pendingExpansionAttachmentCount })
|
|
: '',
|
|
selectionPlan?.skippedAttachmentCount
|
|
? t('chat.shippingOrderExtractionPlanSkipped', { count: selectionPlan.skippedAttachmentCount })
|
|
: '',
|
|
selectionPlan?.budgetLimitedAttachmentCount
|
|
? t('chat.shippingOrderExtractionPlanBudgetLimited', { count: selectionPlan.budgetLimitedAttachmentCount })
|
|
: '',
|
|
unitSummary?.retryingUnits
|
|
? t('chat.shippingOrderExtractionPlanRetrying', { count: unitSummary.retryingUnits })
|
|
: '',
|
|
unitSummary?.failedUnits
|
|
? t('chat.shippingOrderExtractionPlanTechnicalFailures', { count: unitSummary.failedUnits })
|
|
: '',
|
|
].filter(Boolean);
|
|
});
|
|
const selectionPlanHint = computed(() => {
|
|
const selectionPlan = props.state.selectionPlan;
|
|
if (!selectionPlan?.totalAttachmentCount) return '';
|
|
return t('chat.shippingOrderExtractionPlanSummary', {
|
|
total: selectionPlan.totalAttachmentCount,
|
|
groups: selectionPlan.groupCount || 0,
|
|
attachments: selectionPlan.maxInitialAttachments || 0,
|
|
concurrency: selectionPlan.maxInitialConcurrency || 0,
|
|
});
|
|
});
|
|
|
|
const translateReasonCodes = (codes: string[] | undefined): string[] => (
|
|
(codes || [])
|
|
.map((code) => {
|
|
const normalized = String(code || '').trim();
|
|
if (!normalized) return '';
|
|
const key = `chat.shippingOrderExtractionReason.${normalized}`;
|
|
return te(key) ? t(key) : normalized;
|
|
})
|
|
.filter(Boolean)
|
|
);
|
|
|
|
const reviewReasonSummary = computed(() => {
|
|
const labels = translateReasonCodes(props.state.unitSummary?.reviewRequiredReasonCodes);
|
|
return labels.length
|
|
? t('chat.shippingOrderExtractionReviewReasonCodes', { codes: labels.join(' / ') })
|
|
: '';
|
|
});
|
|
|
|
const expansionTriggerSummary = computed(() => {
|
|
const labels = translateReasonCodes(props.state.unitSummary?.expansionTriggerReasonCodes);
|
|
return labels.length
|
|
? t('chat.shippingOrderExtractionExpansionTriggerCodes', { codes: labels.join(' / ') })
|
|
: '';
|
|
});
|
|
|
|
const currentActivityContextSummary = computed(() => {
|
|
const parts: string[] = [];
|
|
const batch = Number(props.state.currentActivity?.selectionBatch || 0);
|
|
if (batch > 0) {
|
|
parts.push(t('chat.shippingOrderExtractionActivitySelectionBatch', { batch }));
|
|
}
|
|
const labels = translateReasonCodes(props.state.currentActivity?.reasonCodes);
|
|
if (labels.length) {
|
|
parts.push(t('chat.shippingOrderExtractionActivityReasonCodes', { codes: labels.join(' / ') }));
|
|
}
|
|
return parts.join(' · ');
|
|
});
|
|
|
|
const openDetails = async () => {
|
|
if (!props.runNo) return;
|
|
detailsOpen.value = true;
|
|
const tasks: Promise<void>[] = [];
|
|
if (documentsLoadedForRun.value !== props.runNo && !loadingDocuments.value) {
|
|
loadingDocuments.value = true;
|
|
documentsLoadFailed.value = false;
|
|
tasks.push(
|
|
listWorkspaceShippingOrderExtractionDocuments(props.runNo)
|
|
.then((response) => {
|
|
documents.value = response.items;
|
|
documentsLoadedForRun.value = props.runNo || '';
|
|
})
|
|
.catch(() => {
|
|
documentsLoadFailed.value = true;
|
|
})
|
|
.finally(() => {
|
|
loadingDocuments.value = false;
|
|
}),
|
|
);
|
|
}
|
|
if (progressEventsLoadedForRun.value !== props.runNo && !loadingProgressEvents.value) {
|
|
loadingProgressEvents.value = true;
|
|
progressEventsLoadFailed.value = false;
|
|
tasks.push(
|
|
listWorkspaceShippingOrderExtractionProgressEvents(props.runNo)
|
|
.then((response) => {
|
|
progressEvents.value = response.items;
|
|
progressEventsLoadedForRun.value = props.runNo || '';
|
|
})
|
|
.catch(() => {
|
|
progressEventsLoadFailed.value = true;
|
|
})
|
|
.finally(() => {
|
|
loadingProgressEvents.value = false;
|
|
}),
|
|
);
|
|
}
|
|
if (tasks.length) {
|
|
await Promise.all(tasks);
|
|
}
|
|
};
|
|
|
|
const handleActionClick = async (action: string) => {
|
|
switch (action) {
|
|
case 'view_details':
|
|
await openDetails();
|
|
return;
|
|
case 'enter_manual_review':
|
|
if (props.hasReviewAttachments) {
|
|
emit('enterManualReview');
|
|
} else {
|
|
await openDetails();
|
|
}
|
|
return;
|
|
case 'retry_failed_attachments':
|
|
emit('retry');
|
|
return;
|
|
default:
|
|
return;
|
|
}
|
|
};
|
|
</script>
|
|
|
|
<template>
|
|
<div class="mb-3 rounded-lg border px-3.5 py-3" :class="toneClass">
|
|
<div class="flex items-start gap-3">
|
|
<LoaderCircle
|
|
v-if="state.status === 'queued' || state.status === 'processing'"
|
|
class="mt-0.5 h-5 w-5 shrink-0 animate-spin"
|
|
/>
|
|
<CircleCheck v-else-if="state.status === 'completed'" class="mt-0.5 h-5 w-5 shrink-0" />
|
|
<TriangleAlert
|
|
v-else-if="state.status === 'partially_completed' || state.status === 'review_required'"
|
|
class="mt-0.5 h-5 w-5 shrink-0"
|
|
/>
|
|
<CircleX v-else class="mt-0.5 h-5 w-5 shrink-0" />
|
|
|
|
<div class="min-w-0 flex-1">
|
|
<div class="text-sm font-semibold">{{ t(titleKey) }}</div>
|
|
<div class="mt-2 flex flex-wrap gap-x-3 gap-y-1 text-xs opacity-90">
|
|
<span>{{ t('chat.shippingOrderExtractionSummary.total', { count: state.summary.totalDocuments }) }}</span>
|
|
<span>{{ t('chat.shippingOrderExtractionSummary.completedProgress', { value: completedLabel }) }}</span>
|
|
<span>{{ t('chat.shippingOrderExtractionSummary.candidates', { count: state.summary.candidateCount }) }}</span>
|
|
<span>{{ t('chat.shippingOrderExtractionSummary.reviewRequired', { count: state.summary.reviewRequiredDocuments }) }}</span>
|
|
<span v-if="state.summary.failedDocuments > 0">
|
|
{{ t('chat.shippingOrderExtractionSummary.failed', { count: state.summary.failedDocuments }) }}
|
|
</span>
|
|
</div>
|
|
<div v-if="state.currentActivity?.fileName" class="mt-2 text-xs font-medium opacity-90">
|
|
{{ t('chat.shippingOrderExtractionCurrentFile', { fileName: state.currentActivity.fileName || t('chat.shippingOrderExtractionUnknownDocument') }) }}
|
|
</div>
|
|
<div v-if="state.currentActivity" class="mt-1 text-xs opacity-80">
|
|
{{ t(activityKey) }}
|
|
</div>
|
|
<div v-if="currentActivityContextSummary" class="mt-1 text-xs opacity-80">
|
|
{{ currentActivityContextSummary }}
|
|
</div>
|
|
<div v-if="selectionPlanHint" class="mt-2 text-xs opacity-85">
|
|
{{ selectionPlanHint }}
|
|
</div>
|
|
<div v-if="reviewReasonSummary" class="mt-2 text-xs opacity-85">
|
|
{{ reviewReasonSummary }}
|
|
</div>
|
|
<div v-if="expansionTriggerSummary" class="mt-1 text-xs opacity-85">
|
|
{{ expansionTriggerSummary }}
|
|
</div>
|
|
<div v-if="selectionSummaryItems.length" class="mt-2 flex flex-wrap gap-2 text-[11px] font-medium opacity-90">
|
|
<span
|
|
v-for="item in selectionSummaryItems"
|
|
:key="item"
|
|
class="rounded-full bg-black/10 px-2 py-0.5 dark:bg-white/10"
|
|
>
|
|
{{ item }}
|
|
</span>
|
|
</div>
|
|
<div v-if="state.refreshFailed" class="mt-2 text-xs font-medium opacity-90">
|
|
{{ t('chat.shippingOrderExtractionRefreshFailed') }}
|
|
</div>
|
|
<div class="mt-3 flex flex-wrap gap-2">
|
|
<button
|
|
v-for="action in state.availableActions"
|
|
:key="action"
|
|
type="button"
|
|
class="inline-flex items-center rounded-md border border-current/20 px-2.5 py-1 text-xs font-medium hover:bg-black/5 dark:hover:bg-white/5"
|
|
@click="handleActionClick(action)"
|
|
>
|
|
{{ t(`chat.shippingOrderExtractionAction.${action}`) }}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<ShippingOrderExtractionDetailsDrawer
|
|
:open="detailsOpen"
|
|
:state="state"
|
|
:documents="documents"
|
|
:progress-events="progressEvents"
|
|
:loading="loadingDocuments"
|
|
:load-failed="documentsLoadFailed"
|
|
:progress-loading="loadingProgressEvents"
|
|
:progress-load-failed="progressEventsLoadFailed"
|
|
:has-review-attachments="hasReviewAttachments"
|
|
@close="detailsOpen = false"
|
|
@enter-manual-review="emit('enterManualReview')"
|
|
/>
|
|
</div>
|
|
</template>
|