feat(shipping-notice): 收敛复核状态隔离、STP 重试幂等与 XFA 合成预览标注
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
84a881b554
commit
74270adc22
149 files changed
+20111
-3871
No files matched your search
@@ -0,0 +1,87 @@
|
||||
/**
|
||||
* features/chat/shipping/conversationProcessingDisplay.spec.ts
|
||||
* 用途:验收主文件回退与正式任务统计。
|
||||
* 依赖:Vitest、conversationProcessingDisplay。
|
||||
*/
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import type {
|
||||
ConversationProcessingObject,
|
||||
ConversationProcessingUserTask,
|
||||
} from '@/features/chat/types/shipping.api.types';
|
||||
import {
|
||||
getPrimaryDocumentName,
|
||||
resolveFormalTaskCount,
|
||||
resolveFormalTaskFileCount,
|
||||
} from './conversationProcessingDisplay';
|
||||
|
||||
/** 构造最小任务卡。 */
|
||||
function task(partial: Partial<ConversationProcessingUserTask>): ConversationProcessingUserTask {
|
||||
return {
|
||||
user_task_no: 'OT-1',
|
||||
group: 'needs_action',
|
||||
can_append: true,
|
||||
...partial,
|
||||
};
|
||||
}
|
||||
|
||||
/** 带可选 primary 标记的 document 行。 */
|
||||
function doc(
|
||||
filename: string,
|
||||
flags: { is_primary?: boolean; primary?: boolean; evidence_role?: string } = {},
|
||||
): ConversationProcessingObject & Record<string, unknown> {
|
||||
return {
|
||||
kind: 'document',
|
||||
object_key: `DOC-${filename}`,
|
||||
label: filename,
|
||||
filename,
|
||||
...flags,
|
||||
};
|
||||
}
|
||||
|
||||
describe('getPrimaryDocumentName', () => {
|
||||
it('prefers primary-marked document filename', () => {
|
||||
const name = getPrimaryDocumentName(task({
|
||||
document_names: ['first.pdf', 'second.pdf'],
|
||||
objects: [doc('first.pdf'), doc('second.pdf', { is_primary: true })],
|
||||
}));
|
||||
expect(name).toBe('second.pdf');
|
||||
});
|
||||
|
||||
it('falls back to document_names[0] without using root_document_id', () => {
|
||||
const name = getPrimaryDocumentName(task({
|
||||
document_names: ['alpha.pdf', 'beta.pdf'],
|
||||
objects: [{
|
||||
kind: 'document',
|
||||
object_key: 'DOC-9',
|
||||
label: 'DOC-9',
|
||||
root_document_id: 99,
|
||||
filename: null,
|
||||
}],
|
||||
}));
|
||||
expect(name).toBe('alpha.pdf');
|
||||
});
|
||||
|
||||
it('returns null when no filename is available', () => {
|
||||
expect(getPrimaryDocumentName(task({ document_names: [], objects: [] }))).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('resolveFormalTaskCount / resolveFormalTaskFileCount', () => {
|
||||
it('reads summary totals without collapsing files into tasks', () => {
|
||||
const projection = {
|
||||
summary: {
|
||||
total_tasks: 3,
|
||||
total_files: 6,
|
||||
processing: 1,
|
||||
needs_action: 2,
|
||||
history: 0,
|
||||
},
|
||||
needs_action: [],
|
||||
processing: [],
|
||||
completed: [],
|
||||
history: [],
|
||||
};
|
||||
expect(resolveFormalTaskCount(projection)).toBe(3);
|
||||
expect(resolveFormalTaskFileCount(projection)).toBe(6);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,92 @@
|
||||
/**
|
||||
* features/chat/shipping/conversationProcessingDisplay.ts
|
||||
* 用途:右侧栏/对话摘要的纯展示辅助(主文件名、正式任务统计)。
|
||||
* 依赖:ConversationProcessingProjection / UserTask / Object。
|
||||
* 逻辑:由 ShippingConversationProcessingCard、ShippingWorkflowTimeline 消费;
|
||||
* 不推导业务状态;主文件仅 UI 标签;禁止用 root_document_id 当文件名。
|
||||
*/
|
||||
|
||||
import type {
|
||||
ConversationProcessingObject,
|
||||
ConversationProcessingProjection,
|
||||
ConversationProcessingUserTask,
|
||||
} from '@/features/chat/types/shipping.api.types';
|
||||
|
||||
/**
|
||||
* 判断 object 是否带有可识别的 primary 标记。
|
||||
* 核心逻辑:兼容 is_primary / primary / evidence_role=primary_pdf;不用 root_document_id。
|
||||
* @param object - 任务 objects 行
|
||||
*/
|
||||
function objectHasPrimaryMark(object: ConversationProcessingObject & Record<string, unknown>): boolean {
|
||||
if (object.is_primary === true || object.primary === true) return true;
|
||||
const role = String(object.evidence_role || '').trim().toLowerCase();
|
||||
return role === 'primary_pdf' || role === 'primary';
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析任务「主文件」展示名。
|
||||
* 核心逻辑:优先 objects 中带 primary 标记的 document;否则 document_names[0];都没有返回 null。
|
||||
* @param task - 会话用户可见任务
|
||||
* @returns 主文件名;无则 null(调用方不渲染「主文件」行)
|
||||
*/
|
||||
export function getPrimaryDocumentName(
|
||||
task: ConversationProcessingUserTask | null | undefined,
|
||||
): string | null {
|
||||
if (!task) return null;
|
||||
const objects = Array.isArray(task.objects) ? task.objects : [];
|
||||
for (const raw of objects) {
|
||||
if (!raw || String(raw.kind || '').trim() !== 'document') continue;
|
||||
const row = raw as ConversationProcessingObject & Record<string, unknown>;
|
||||
if (!objectHasPrimaryMark(row)) continue;
|
||||
const name = String(row.filename || row.label || '').trim();
|
||||
if (name) return name;
|
||||
}
|
||||
const names = (Array.isArray(task.document_names) ? task.document_names : [])
|
||||
.map((name) => String(name || '').trim())
|
||||
.filter(Boolean);
|
||||
return names[0] || null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 汇总正式 OT 任务文件数(不含 order_intake)。
|
||||
* 核心逻辑:优先 summary.total_files;缺失时对 needs_action+processing+completed 的 file_count 求和。
|
||||
* @param projection - 会话 processing 投影
|
||||
*/
|
||||
export function resolveFormalTaskFileCount(
|
||||
projection: ConversationProcessingProjection | null | undefined,
|
||||
): number {
|
||||
if (!projection) return 0;
|
||||
const fromSummary = Number(projection.summary?.total_files);
|
||||
if (Number.isFinite(fromSummary) && fromSummary >= 0 && projection.summary?.total_files != null) {
|
||||
return fromSummary;
|
||||
}
|
||||
const tasks = [
|
||||
...(projection.needs_action || []),
|
||||
...(projection.processing || []),
|
||||
...(projection.completed || []),
|
||||
];
|
||||
return tasks.reduce((sum, task) => {
|
||||
const count = Number(task.file_count);
|
||||
return sum + (Number.isFinite(count) && count > 0 ? count : 0);
|
||||
}, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 汇总正式 OT 任务数(优先 summary.total_tasks;不含把 files 误当 tasks)。
|
||||
* @param projection - 会话 processing 投影
|
||||
*/
|
||||
export function resolveFormalTaskCount(
|
||||
projection: ConversationProcessingProjection | null | undefined,
|
||||
): number {
|
||||
if (!projection) return 0;
|
||||
const fromSummary = Number(projection.summary?.total_tasks);
|
||||
if (Number.isFinite(fromSummary) && fromSummary >= 0 && projection.summary?.total_tasks != null) {
|
||||
return fromSummary;
|
||||
}
|
||||
return (
|
||||
(projection.needs_action?.length || 0)
|
||||
+ (projection.processing?.length || 0)
|
||||
+ (projection.completed?.length || 0)
|
||||
+ (projection.history?.length || 0)
|
||||
);
|
||||
}
|
||||
@@ -134,14 +134,23 @@ describe('conversationProcessingProjection', () => {
|
||||
}),
|
||||
]);
|
||||
const projection = groupConversationProcessingTasks(tasks, { focusedTaskNo: 'OT-RUN-A' });
|
||||
// 右侧总数不含 history;completed 独立成组。
|
||||
// summary.total_* 含 history(正式 OT 全量);合成路径无截断。
|
||||
expect(projection.summary).toEqual({
|
||||
total_tasks: 4,
|
||||
total_files: 4,
|
||||
total_tasks: 5,
|
||||
total_files: 5,
|
||||
processing: 2,
|
||||
needs_action: 1,
|
||||
completed: 1,
|
||||
history: 1,
|
||||
returned: {
|
||||
needs_action: 1,
|
||||
processing: 2,
|
||||
completed: 1,
|
||||
history: 1,
|
||||
},
|
||||
truncated: { active: false, history: false },
|
||||
has_more_active: false,
|
||||
has_more_history: false,
|
||||
});
|
||||
expect(projection.needs_action[0]?.user_task_no).toBe('OT-RUN-A');
|
||||
expect(projection.processing.map((t) => t.user_task_no).sort()).toEqual([
|
||||
@@ -150,7 +159,7 @@ describe('conversationProcessingProjection', () => {
|
||||
]);
|
||||
expect(projection.completed?.[0]?.user_task_no).toBe('OT-RUN-DONE');
|
||||
expect(projection.history[0]?.user_task_no).toBe('OT-RUN-C');
|
||||
// [UI-02] 缺文件名时 title 为空,交给卡片回退「未命名 PDF」。
|
||||
// title 为空,卡片统一展示「订单识别任务」。
|
||||
const unnamed = projection.processing.find((t) => t.user_task_no === 'OT-RUN-NO-NAME');
|
||||
expect(unnamed?.title).toBeNull();
|
||||
});
|
||||
|
||||
@@ -516,6 +516,7 @@ export function projectConversationProcessingTasks(
|
||||
|
||||
/**
|
||||
* 将任务列表按分组装入 ConversationProcessingProjection。
|
||||
* 核心逻辑:summary.total_* 含 history;合成路径无截断,has_more=false。
|
||||
*/
|
||||
export function groupConversationProcessingTasks(
|
||||
tasks: ConversationProcessingUserTask[],
|
||||
@@ -528,14 +529,23 @@ export function groupConversationProcessingTasks(
|
||||
const processing = tasks.filter((t) => t.group === 'processing');
|
||||
const completed = tasks.filter((t) => t.group === 'completed');
|
||||
const history = tasks.filter((t) => t.group === 'history');
|
||||
const active = [...needs_action, ...processing, ...completed];
|
||||
const all = [...needs_action, ...processing, ...completed, ...history];
|
||||
const summary: ConversationProcessingSummary = {
|
||||
total_tasks: needs_action.length + processing.length + completed.length,
|
||||
total_files: active.reduce((sum, task) => sum + Number(task.file_count || 0), 0),
|
||||
total_tasks: all.length,
|
||||
total_files: all.reduce((sum, task) => sum + Number(task.file_count || 0), 0),
|
||||
processing: processing.length,
|
||||
needs_action: needs_action.length,
|
||||
completed: completed.length,
|
||||
history: history.length,
|
||||
returned: {
|
||||
needs_action: needs_action.length,
|
||||
processing: processing.length,
|
||||
completed: completed.length,
|
||||
history: history.length,
|
||||
},
|
||||
truncated: { active: false, history: false },
|
||||
has_more_active: false,
|
||||
has_more_history: false,
|
||||
};
|
||||
return {
|
||||
summary,
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
* features/chat/shipping/useShippingProcessingWorkItem.ts
|
||||
* 用途:按 work_item_type + work_item_no 轮询统一 ShippingProcessingProjection。
|
||||
* 依赖:shipping.api getWorkspaceShippingProcessingWorkItem、normalizeShippingProcessing。
|
||||
* 逻辑:复核台 / 任务中心双读接入;404 或权威 OT 缺失时保持 null,不打断旧进度 UI。
|
||||
* 依赖:shipping.api、normalizeShippingProcessing、mergeWorkbenchProcessingProjection。
|
||||
* 逻辑:复核台 / 任务中心双读;工作台可启用 monotonicProgressVersion;404 时保持 null。
|
||||
*/
|
||||
|
||||
import {
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
toValue,
|
||||
} from 'vue';
|
||||
import { BusinessError } from '@/shared/api/client';
|
||||
import { mergeWorkbenchProcessingProjection } from '@/features/shipping-progress/mergeProcessingProjection';
|
||||
import { getWorkspaceShippingProcessingWorkItem } from '../api/shipping.api';
|
||||
import type { ShippingProcessingProjection } from '../types/shipping.api.types';
|
||||
import { normalizeShippingProcessingProjection } from './normalizeShippingProcessing';
|
||||
@@ -33,7 +34,8 @@ export type ShippingProcessingWorkItemTypeArg = 'order_intake' | 'order_task';
|
||||
*
|
||||
* @param workItemType - order_intake | order_task
|
||||
* @param workItemNo - Intake 编号或 OT 编号(MaybeRef)
|
||||
* @param options.enabled - 是否启用;options.pollMs - 轮询间隔
|
||||
* @param options.enabled - 是否启用;options.pollMs - 轮询间隔;
|
||||
* options.monotonicProgressVersion - 仅工作台:旧 progress_version 不覆盖本地
|
||||
* @returns projection / loading / error / refresh / stop
|
||||
*/
|
||||
export function useShippingProcessingWorkItem(
|
||||
@@ -42,6 +44,8 @@ export function useShippingProcessingWorkItem(
|
||||
options: {
|
||||
enabled?: MaybeRefOrGetter<boolean>;
|
||||
pollMs?: number;
|
||||
/** 仅订单处理工作台开启;任务中心保持默认 false。 */
|
||||
monotonicProgressVersion?: boolean;
|
||||
} = {},
|
||||
): {
|
||||
projection: Ref<ShippingProcessingProjection | null>;
|
||||
@@ -57,6 +61,7 @@ export function useShippingProcessingWorkItem(
|
||||
let generation = 0;
|
||||
let stopped = false;
|
||||
const pollMs = options.pollMs ?? DEFAULT_POLL_MS;
|
||||
const monotonic = Boolean(options.monotonicProgressVersion);
|
||||
|
||||
/**
|
||||
* 清除轮询定时器。
|
||||
@@ -95,10 +100,14 @@ export function useShippingProcessingWorkItem(
|
||||
const raw = await getWorkspaceShippingProcessingWorkItem(workItemType, no);
|
||||
if (stopped || gen !== generation) return;
|
||||
const normalized = normalizeShippingProcessingProjection(raw);
|
||||
projection.value = normalized;
|
||||
// [STEP] 工作台单调合并:旧包丢弃;新包整包替换;同版本浅合并。任务中心不启用。
|
||||
projection.value = monotonic
|
||||
? mergeWorkbenchProcessingProjection(projection.value, normalized)
|
||||
: normalized;
|
||||
error.value = null;
|
||||
clearTimer();
|
||||
if (normalized && !TERMINAL_STATUSES.has(normalized.status) && !stopped) {
|
||||
const next = projection.value;
|
||||
if (next && !TERMINAL_STATUSES.has(next.status) && !stopped) {
|
||||
timer = window.setTimeout(() => {
|
||||
void refresh();
|
||||
}, pollMs);
|
||||
|
||||
Reference in new issue
Block a user