refactor(agent, shipping): 简化代理模型并完善订单抽取业务

- 移除 Agent 的 exposure_mode 与 internal_executor 相关逻辑,清理关联的过滤、序列化代码
- 删除废弃的 AgentRuntimeBinding 模型及其依赖
- 新增订单抽取上传批次、请求快照等数据库迁移与业务逻辑
- 修复附件完整性检测、订单抽取状态映射问题
- 更新多语言错误文案与前端单元测试配置
- 清理平台配置中不再使用的暴露模式配置
This commit is contained in:
hugo committed 2026-07-28 20:25:48 +08:00
1 parent 1f3ecb87b7
commit 61ac6403c4
159 files changed
+12883 -5099

No files matched your search

@@ -40,8 +40,8 @@ const ACTIVE_ORDER_EXTRACTION = new Set(['extracting']);
/**
* 判断服务端 Intake 是否应恢复到输入栏。
* AI 触发时机:无;页面刷新或重新打开会话时调用。
* 已解析文件已作为用户消息附件固化在对话气泡中,不能再次显示在输入栏;但存在待审核
* Candidate 的部分完成 Intake 必须恢复,否则用户无法补充字段并继续建单。
* 上传快览与发送授权已拆分:未发送但已快览成功的附件,刷新后也必须恢复到输入栏;
* 已进入订单抽取终态的附件仅保留在消息气泡中,避免把旧批次误带回当前输入框。
* @param parseStatus - 服务端返回的预解析状态。
* @param orderExtractionStatus - 服务端返回的订单抽取状态。
* @param candidateCount - 当前仍可审核的订单 Candidate 数量。
@@ -51,13 +51,17 @@ export function shouldRestoreShippingNoticeIntake(
parseStatus: string | null | undefined,
orderExtractionStatus?: string | null,
candidateCount = 0,
layoutStatus?: ShippingNoticePendingAttachment['layoutStatus'],
parseSummary?: ShippingNoticePendingAttachment['parseSummary'],
): boolean {
const status = String(parseStatus || '').trim().toLowerCase();
const extractionStatus = String(orderExtractionStatus || '').trim().toLowerCase();
return ACTIVE_PARSE.has(status)
|| status === 'parse_failed'
|| layoutStatus === 'processing'
|| (
status === 'parsed'
&& (!extractionStatus || extractionStatus === 'not_started')
&& !isShippingNoticeAttachmentParseIncomplete(parseSummary)
)
|| extractionStatus === 'failed'
|| (extractionStatus === 'partially_completed' && candidateCount > 0);
}
@@ -67,8 +71,7 @@ export function shouldPollShippingNoticeIntake(
item: Pick<ShippingNoticePendingAttachment, 'parseStatus' | 'orderExtractionStatus' | 'layoutStatus'>,
): boolean {
return !TERMINAL_PARSE.has(item.parseStatus)
|| ACTIVE_ORDER_EXTRACTION.has(String(item.orderExtractionStatus || '').trim().toLowerCase())
|| item.layoutStatus === 'processing';
|| ACTIVE_ORDER_EXTRACTION.has(String(item.orderExtractionStatus || '').trim().toLowerCase());
}
/** 判断附件是否仍可作为新一轮完整订单抽取的输入。 */
@@ -79,7 +82,6 @@ export function isOrderExtractionEligibleIntake(
return item.parseStatus === 'parsed'
&& Boolean(item.intakeNo)
&& (extractionStatus === 'not_started' || extractionStatus === 'failed')
&& item.layoutStatus !== 'processing'
&& !isShippingNoticeAttachmentParseIncomplete(item.parseSummary);
}
@@ -222,7 +224,7 @@ export function mapServerCandidate(remote: ShippingNoticeCandidateResponse): Shi
};
}
function createPendingAttachment(file: File): ShippingNoticePendingAttachment {
function createPendingAttachment(file: File, uploadBatchId: string): ShippingNoticePendingAttachment {
return {
id: `${Date.now()}_${Math.random().toString(36).slice(2, 8)}`,
kind: 'shipping_notice',
@@ -233,6 +235,7 @@ function createPendingAttachment(file: File): ShippingNoticePendingAttachment {
uploadProgress: 0,
originalFilename: file.name,
fileSize: file.size,
uploadBatchId,
};
}
@@ -246,6 +249,8 @@ export interface UseShippingNoticeIntakesOptions {
export function useShippingNoticeIntakes(options: UseShippingNoticeIntakesOptions) {
const pollTimer = ref<ReturnType<typeof setTimeout> | null>(null);
const pollRound = ref(0);
// 新文件选择显式推进当前批次;恢复历史卡片不能覆盖它。
const currentUploadBatchId = ref<string | null>(null);
const noticeAttachments = computed(() =>
options.attachments.value.filter(
@@ -253,20 +258,26 @@ export function useShippingNoticeIntakes(options: UseShippingNoticeIntakesOption
),
);
const currentBatchAttachments = computed(() => {
const batchId = currentUploadBatchId.value;
return batchId
? noticeAttachments.value.filter((item) => item.uploadBatchId === batchId)
: noticeAttachments.value;
});
const hasBlockingUploadOrParse = computed(() =>
noticeAttachments.value.some((item) =>
currentBatchAttachments.value.some((item) =>
item.uploadStatus === 'uploading'
|| item.uploadStatus === 'waiting'
|| ACTIVE_PARSE.has(item.parseStatus)
|| item.parseStatus === 'queued'
|| item.parseStatus === 'parsing'
|| item.layoutStatus === 'processing'
|| ACTIVE_ORDER_EXTRACTION.has(String(item.orderExtractionStatus || '').trim().toLowerCase()),
),
);
const hasParseFailures = computed(() =>
noticeAttachments.value.some(
currentBatchAttachments.value.some(
(item) =>
item.parseStatus === 'failed'
|| isShippingNoticeAttachmentParseIncomplete(item.parseSummary),
@@ -274,8 +285,8 @@ export function useShippingNoticeIntakes(options: UseShippingNoticeIntakesOption
);
const allParsedReady = computed(() =>
noticeAttachments.value.length > 0
&& noticeAttachments.value.every(
currentBatchAttachments.value.length > 0
&& currentBatchAttachments.value.every(
(item) =>
item.parseStatus === 'parsed'
&& !isShippingNoticeAttachmentParseIncomplete(item.parseSummary),
@@ -283,7 +294,7 @@ export function useShippingNoticeIntakes(options: UseShippingNoticeIntakesOption
);
const hasBlockingDuplicates = computed(() =>
noticeAttachments.value.some(
currentBatchAttachments.value.some(
(item) => (item.candidates?.length
? item.candidates.some((candidate) =>
candidate.selected && candidate.duplicate?.blocking && !candidate.duplicateResolution?.action,
@@ -293,7 +304,7 @@ export function useShippingNoticeIntakes(options: UseShippingNoticeIntakesOption
);
const hasCandidateReviewIssues = computed(() =>
noticeAttachments.value.some((item) =>
currentBatchAttachments.value.some((item) =>
(item.candidates || []).some((candidate) =>
candidate.selected && candidate.validationStatus !== 'ready',
),
@@ -305,7 +316,7 @@ export function useShippingNoticeIntakes(options: UseShippingNoticeIntakesOption
&& !hasBlockingDuplicates.value
&& !hasCandidateReviewIssues.value
&& !hasParseFailures.value
&& noticeAttachments.value.some((item) => (item.candidates || []).some((candidate) => candidate.selected)),
&& currentBatchAttachments.value.some((item) => (item.candidates || []).some((candidate) => candidate.selected)),
);
const stopPolling = () => {
@@ -386,9 +397,11 @@ export function useShippingNoticeIntakes(options: UseShippingNoticeIntakesOption
const intake = await createShippingNoticeIntake(
asset.asset_no,
options.conversationId.value,
attachment.uploadBatchId,
);
patchAttachment(attachment.id, {
intakeNo: intake.intake_no,
uploadBatchId: intake.upload_batch_id || attachment.uploadBatchId,
parseStatus: mapServerParseStatus(intake.parse_status),
orderExtractionStatus: intake.order_extraction_status || undefined,
parseSummary: (intake.parse_summary || undefined) as ShippingNoticeParseSummary | undefined,
@@ -412,8 +425,12 @@ export function useShippingNoticeIntakes(options: UseShippingNoticeIntakesOption
};
const enqueueNoticeFiles = async (files: File[]) => {
// 同一次选择共享一个持久化批次;后续发送只会自动取这个最新批次。
const uploadBatchId = globalThis.crypto?.randomUUID?.()
|| `${Date.now()}-${Math.random().toString(36).slice(2, 12)}`;
currentUploadBatchId.value = uploadBatchId;
for (const file of files) {
const attachment = createPendingAttachment(file);
const attachment = createPendingAttachment(file, uploadBatchId);
options.attachments.value = [...options.attachments.value, attachment];
await processSingleFile(attachment);
}
@@ -452,10 +469,14 @@ export function useShippingNoticeIntakes(options: UseShippingNoticeIntakesOption
schedulePoll();
};
const getParsedIntakeNos = () =>
noticeAttachments.value
.filter(isOrderExtractionEligibleIntake)
const getParsedIntakeNos = () => {
const eligible = noticeAttachments.value.filter(isOrderExtractionEligibleIntake);
const currentBatchId = currentUploadBatchId.value
|| [...noticeAttachments.value].reverse().find((item) => item.uploadBatchId)?.uploadBatchId;
return eligible
.filter((item) => item.uploadBatchId === currentBatchId)
.map((item) => String(item.intakeNo));
};
/** 点击发送后立即展示订单识别阶段,并启动 Intake 状态轮询。 */
const markOrderExtractionStarted = (intakeNos: string[]) => {
@@ -497,7 +518,7 @@ export function useShippingNoticeIntakes(options: UseShippingNoticeIntakesOption
item.parse_status,
item.order_extraction_status,
item.candidates?.length || 0,
item.layout_status,
(item.parse_summary || undefined) as ShippingNoticeParseSummary | undefined,
))
.map((item) => ({
id: `restored_${item.intake_no}`,
@@ -505,6 +526,7 @@ export function useShippingNoticeIntakes(options: UseShippingNoticeIntakesOption
type: 'document' as const,
assetNo: item.asset_no || undefined,
intakeNo: item.intake_no,
uploadBatchId: item.upload_batch_id || undefined,
uploadStatus: 'uploaded' as const,
parseStatus: mapServerParseStatus(item.parse_status),
orderExtractionStatus: item.order_extraction_status || undefined,