feat(shipping-notice): 落地 XFA 拆分、版面签名、统一进度与处理域履约
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
3a9fbac2fc
commit
d2b3d74def
571 files changed
+78064
-24681
No files matched your search
@@ -1,17 +1,56 @@
|
||||
/**
|
||||
* features/chat/shipping/conversationProcessingProjection.ts
|
||||
* 用途:将现有 Workflow Items 投影为对话「本次处理中」统一对象行。
|
||||
* 依赖:shipping.api.types(ConversationProcessingObject / WorkflowNodeStatus)。
|
||||
* 逻辑:Timeline 复用本投影;Task 优先消费后端 node_status / progress_nodes;
|
||||
* 不伪造进度百分比。
|
||||
* 用途:将 OT / 统一 processing 投影为对话「本次处理中」对象、任务分组与文件行。
|
||||
* 依赖:shipping.api.types(ConversationProcessingObject / UserTask / WorkflowNodeStatus /
|
||||
* ShippingProcessingProjection、合成 ShippingWorkflowItem)。
|
||||
* 逻辑:Timeline 与 ShippingConversationProcessingCard 复用;文件明细由
|
||||
* mapUserTaskObjectsToFileRows(task.objects) 合成;禁止 Workflow fallback reconcile;
|
||||
* 可由统一 work_items(order_task)合成兼容分组。
|
||||
*/
|
||||
|
||||
import type {
|
||||
ConversationProcessingObject,
|
||||
ConversationProcessingProjection,
|
||||
ConversationProcessingSummary,
|
||||
ConversationProcessingTaskGroup,
|
||||
ConversationProcessingUserTask,
|
||||
ShippingProcessingProjection,
|
||||
ShippingWorkflowItem,
|
||||
WorkflowNodeStatus,
|
||||
} from '@/features/chat/types/shipping.api.types';
|
||||
|
||||
/** 需要人工处理的生命周期集合。 */
|
||||
const NEEDS_ACTION_LIFECYCLES = new Set([
|
||||
'pending_review',
|
||||
'manual_upload_pending',
|
||||
'failed',
|
||||
'reparse_failed',
|
||||
'upload_rpa_failed',
|
||||
]);
|
||||
|
||||
/** 处理中生命周期集合。 */
|
||||
const PROCESSING_LIFECYCLES = new Set([
|
||||
'queued',
|
||||
'layout_parsing',
|
||||
'extracting',
|
||||
'building_order',
|
||||
'inventory_matching',
|
||||
'generating_excel',
|
||||
'upload_rpa_pending',
|
||||
'upload_rpa_running',
|
||||
]);
|
||||
|
||||
/** 历史生命周期集合(已关闭/取消;completed 单独进「已完成」通知组)。 */
|
||||
const HISTORY_LIFECYCLES = new Set([
|
||||
'closed',
|
||||
'cancelled',
|
||||
]);
|
||||
|
||||
/** 识别完成、仍应在右侧展示的成功通知生命周期。 */
|
||||
const COMPLETED_LIFECYCLES = new Set([
|
||||
'completed',
|
||||
]);
|
||||
|
||||
/**
|
||||
* 将生命周期状态映射为 WorkflowNodeStatus(展示用,非进度百分比)。
|
||||
*/
|
||||
@@ -58,6 +97,59 @@ export function resolveItemDisplayStatus(item: ShippingWorkflowItem): string {
|
||||
return String(item.lifecycle_status || '').trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 OT 任务卡内 document objects 映射为侧栏文件行(合成 ShippingWorkflowItem 形态)。
|
||||
* 核心逻辑:仅消费 kind=document;item_no 优先 workflow_item_no / object_key;
|
||||
* available_actions / reparse_kind 可从 object 扩展字段透传(单测与后端可选投影)。
|
||||
*
|
||||
* @param task - 当前展开的用户可见任务
|
||||
* @returns 文件明细行;无文档对象时为空数组
|
||||
*/
|
||||
export function mapUserTaskObjectsToFileRows(
|
||||
task: ConversationProcessingUserTask | null | undefined,
|
||||
): ShippingWorkflowItem[] {
|
||||
if (!task) return [];
|
||||
const rows: ShippingWorkflowItem[] = [];
|
||||
for (const [index, object] of (task.objects || []).entries()) {
|
||||
if (object.kind !== 'document') continue;
|
||||
const documentId = Number(object.document_id || 0);
|
||||
const rootId = Number(object.root_document_id || documentId || 0);
|
||||
const status = String(object.status_label || task.status_label || 'queued').trim() || 'queued';
|
||||
const itemNo = String(
|
||||
object.workflow_item_no || object.object_key || `DOC-${documentId || index + 1}`,
|
||||
).trim();
|
||||
const extra = object as ConversationProcessingObject & {
|
||||
available_actions?: string[];
|
||||
reparse_kind?: string | null;
|
||||
lock_version?: number;
|
||||
};
|
||||
rows.push({
|
||||
item_no: itemNo,
|
||||
workflow_no: String(task.workflow_no || 'SNWF-OT').trim() || 'SNWF-OT',
|
||||
conversation_id: '',
|
||||
root_document_id: rootId,
|
||||
current_document_id: documentId || rootId,
|
||||
current_document_filename: object.filename || object.label || null,
|
||||
content_hash: object.content_hash || null,
|
||||
current_version_no: Number(object.current_version_no || 1) || 1,
|
||||
current_run_no: object.current_run_no || object.run_no || task.run_no || null,
|
||||
current_case_no: object.case_no || null,
|
||||
current_task_no: object.task_no || task.user_task_no || null,
|
||||
user_task_no: task.user_task_no,
|
||||
user_task_authoritative: task.user_task_authoritative,
|
||||
lifecycle_status: status,
|
||||
current_stage: status,
|
||||
display_lifecycle_status: status,
|
||||
lock_version: Number(extra.lock_version || 1) || 1,
|
||||
available_actions: Array.isArray(extra.available_actions)
|
||||
? extra.available_actions
|
||||
: (Array.isArray(task.available_actions) ? task.available_actions : undefined),
|
||||
reparse_kind: extra.reparse_kind ?? null,
|
||||
});
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 Workflow Items 聚合 Run / Candidate / Task / Process Gate 侧栏行。
|
||||
*
|
||||
@@ -188,3 +280,416 @@ export function projectConversationProcessingObjects(
|
||||
|
||||
return rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按生命周期/门禁将状态归入 needs_action | processing | completed | history。
|
||||
*/
|
||||
export function classifyConversationProcessingGroup(
|
||||
status: string | null | undefined,
|
||||
options?: { hasBlockingGate?: boolean; needsCustomerConfirm?: boolean },
|
||||
): ConversationProcessingTaskGroup {
|
||||
if (options?.hasBlockingGate || options?.needsCustomerConfirm) return 'needs_action';
|
||||
const normalized = String(status || '').trim();
|
||||
if (NEEDS_ACTION_LIFECYCLES.has(normalized)) return 'needs_action';
|
||||
if (COMPLETED_LIFECYCLES.has(normalized)) return 'completed';
|
||||
if (HISTORY_LIFECYCLES.has(normalized)) return 'history';
|
||||
if (PROCESSING_LIFECYCLES.has(normalized)) return 'processing';
|
||||
if (normalized === 'review_required' || normalized === 'partially_completed') {
|
||||
return 'needs_action';
|
||||
}
|
||||
if (normalized === 'failed' || normalized === 'cancelled') return 'needs_action';
|
||||
if (normalized === 'completed') return 'completed';
|
||||
if (normalized === 'processing' || normalized === 'queued') return 'processing';
|
||||
return 'processing';
|
||||
}
|
||||
|
||||
/**
|
||||
* 兜底任务身份键:稳定业务身份优先,文件名仅作最弱兜底。
|
||||
* 顺序:user_task_no → content_hash → root_document_id → filename → run/item。
|
||||
* 普通重传会换 root_document_id,故不得把 root 放在 content_hash 之前。
|
||||
*/
|
||||
function fallbackTaskIdentityKey(item: ShippingWorkflowItem): string {
|
||||
const userTaskNo = String(item.user_task_no || '').trim();
|
||||
if (userTaskNo) return `task:${userTaskNo}`;
|
||||
const contentHash = String(item.content_hash || '').trim().toLowerCase();
|
||||
if (contentHash) return `hash:${contentHash}`;
|
||||
const rootId = Number(item.root_document_id || 0);
|
||||
if (rootId > 0) return `root:${rootId}`;
|
||||
const filename = String(item.current_document_filename || '').trim().toLowerCase();
|
||||
if (filename) return `fn:${filename}`;
|
||||
const runNo = String(item.current_run_no || '').trim();
|
||||
if (runNo) return `run:${runNo}`;
|
||||
return `item:${String(item.item_no || '').trim()}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 降级路径:按稳定身份去重 Workflow Items 中的业务 PDF。
|
||||
* 顺序:content_hash → root_document_id → current_document_id;禁止仅按文件名去重。
|
||||
*/
|
||||
function dedupeFallbackDocuments(items: ShippingWorkflowItem[]): Array<{
|
||||
filename: string | null;
|
||||
content_hash: string | null;
|
||||
root_document_id: number;
|
||||
document_id: number;
|
||||
status_label: string;
|
||||
current_run_no: string | null;
|
||||
source_item: ShippingWorkflowItem;
|
||||
}> {
|
||||
const unique: Array<{
|
||||
filename: string | null;
|
||||
content_hash: string | null;
|
||||
root_document_id: number;
|
||||
document_id: number;
|
||||
status_label: string;
|
||||
current_run_no: string | null;
|
||||
source_item: ShippingWorkflowItem;
|
||||
recency: number;
|
||||
identity: string;
|
||||
}> = [];
|
||||
const seen = new Map<string, number>();
|
||||
for (const item of items || []) {
|
||||
const contentHash = String(item.content_hash || '').trim().toLowerCase();
|
||||
const rootId = Number(item.root_document_id || 0);
|
||||
const documentId = Number(item.current_document_id || 0);
|
||||
const identity = contentHash
|
||||
? `hash:${contentHash}`
|
||||
: rootId > 0
|
||||
? `root:${rootId}`
|
||||
: documentId > 0
|
||||
? `doc:${documentId}`
|
||||
: `item:${String(item.item_no || '').trim()}`;
|
||||
const filename = String(item.current_document_filename || '').trim() || null;
|
||||
const row = {
|
||||
filename,
|
||||
content_hash: contentHash || null,
|
||||
root_document_id: rootId,
|
||||
document_id: documentId,
|
||||
status_label: resolveItemDisplayStatus(item),
|
||||
current_run_no: String(item.current_run_no || '').trim() || null,
|
||||
source_item: item,
|
||||
recency: Date.parse(String(item.last_activity_at || item.updated_at || '').trim()) || 0,
|
||||
identity,
|
||||
};
|
||||
const existingIndex = seen.get(identity);
|
||||
if (existingIndex == null) {
|
||||
seen.set(identity, unique.length);
|
||||
unique.push(row);
|
||||
continue;
|
||||
}
|
||||
const existing = unique[existingIndex]!;
|
||||
if (row.recency > existing.recency
|
||||
|| (row.recency === existing.recency && documentId >= existing.document_id)) {
|
||||
unique[existingIndex] = row;
|
||||
}
|
||||
}
|
||||
return unique;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 Workflow Items 聚合为用户可见任务列表(后端 processing 未就绪时的前端兜底)。
|
||||
* 核心逻辑:先按稳定任务身份(user_task_no / hash…)归并全部 Item,再按 PDF 去重计
|
||||
* file_count;禁止先按 run_no 拆桶再丢弃同 OT 的另一份 PDF;单 PDF 才用文件名作 title。
|
||||
*/
|
||||
export function projectConversationProcessingTasks(
|
||||
items: ShippingWorkflowItem[],
|
||||
options?: {
|
||||
focusTaskNo?: string | null;
|
||||
focusRunNo?: string | null;
|
||||
focusUserTaskNo?: string | null;
|
||||
},
|
||||
): ConversationProcessingUserTask[] {
|
||||
const byIdentity = new Map<string, ShippingWorkflowItem[]>();
|
||||
for (const item of items || []) {
|
||||
const identity = fallbackTaskIdentityKey(item);
|
||||
if (!identity || identity === 'item:') continue;
|
||||
const bucket = byIdentity.get(identity) || [];
|
||||
bucket.push(item);
|
||||
byIdentity.set(identity, bucket);
|
||||
}
|
||||
|
||||
const focusUserTask = String(options?.focusUserTaskNo || '').trim();
|
||||
const focusRun = String(options?.focusRunNo || '').trim();
|
||||
const tasks: ConversationProcessingUserTask[] = [];
|
||||
|
||||
for (const [identity, groupItems] of byIdentity) {
|
||||
void identity;
|
||||
if (!groupItems.length) continue;
|
||||
// [STEP 1] 取最近活动 Item 作为任务级代表 Run;PDF 则跨 Run 独立选择最新版本。
|
||||
const sorted = [...groupItems].sort((a, b) => {
|
||||
const aAt = Date.parse(String(a.last_activity_at || a.updated_at || '').trim()) || 0;
|
||||
const bAt = Date.parse(String(b.last_activity_at || b.updated_at || '').trim()) || 0;
|
||||
if (bAt !== aAt) return bAt - aAt;
|
||||
return String(b.current_run_no || '').localeCompare(String(a.current_run_no || ''));
|
||||
});
|
||||
const primaryItem = sorted[0];
|
||||
if (!primaryItem) continue;
|
||||
const runNo = String(
|
||||
primaryItem.current_run_no || primaryItem.workflow_no || primaryItem.item_no || '',
|
||||
).trim();
|
||||
// [STEP 2] 同 OT 的旧 Run 仍可能承载未重识别 PDF,禁止整批过滤到代表 Run。
|
||||
const uniqueDocuments = dedupeFallbackDocuments(groupItems);
|
||||
const effectiveItems = uniqueDocuments.map((row) => row.source_item);
|
||||
// 任务级分组/操作只由最近代表 Item 决定;旧 Run 仅贡献未受影响的 PDF,不得反向污染状态。
|
||||
const statuses = [resolveItemDisplayStatus(primaryItem)];
|
||||
const hasGate = Boolean(primaryItem.process_gate?.current_blocking_gate);
|
||||
let group: ConversationProcessingTaskGroup = 'history';
|
||||
for (const status of statuses) {
|
||||
const g = classifyConversationProcessingGroup(status, { hasBlockingGate: hasGate });
|
||||
if (g === 'needs_action') {
|
||||
group = 'needs_action';
|
||||
break;
|
||||
}
|
||||
if (g === 'processing') {
|
||||
group = 'processing';
|
||||
continue;
|
||||
}
|
||||
if (g === 'completed' && group !== 'processing') {
|
||||
group = 'completed';
|
||||
}
|
||||
}
|
||||
const primaryStatus = statuses.find((s) => NEEDS_ACTION_LIFECYCLES.has(s))
|
||||
|| statuses.find((s) => PROCESSING_LIFECYCLES.has(s))
|
||||
|| statuses.find((s) => COMPLETED_LIFECYCLES.has(s))
|
||||
|| statuses[0]
|
||||
|| 'queued';
|
||||
// [UI-01] 必须原样输出后端真实 OT;仅缺省时才用本地兼容号,且不得用于写接口。
|
||||
const authoritativeTaskNo = String(
|
||||
effectiveItems.map((row) => row.user_task_no).find((value) => String(value || '').trim())
|
||||
|| groupItems.map((row) => row.user_task_no).find((value) => String(value || '').trim())
|
||||
|| '',
|
||||
).trim();
|
||||
const userTaskNo = authoritativeTaskNo || `OT-${runNo}`;
|
||||
const documentNames = uniqueDocuments
|
||||
.map((row) => String(row.filename || '').trim())
|
||||
.filter(Boolean);
|
||||
const isMulti = uniqueDocuments.length > 1;
|
||||
const title = isMulti
|
||||
? null
|
||||
: (documentNames[0] || String(primaryItem.current_document_filename || '').trim() || null);
|
||||
const activityRaw = String(primaryItem.last_activity_at || primaryItem.updated_at || '').trim();
|
||||
const documentObjects = uniqueDocuments.map((row) => ({
|
||||
kind: 'document' as const,
|
||||
object_key: row.document_id > 0
|
||||
? `DOC-${row.document_id}`
|
||||
: `DOC-${row.root_document_id || row.filename || 'unknown'}`,
|
||||
label: row.filename || `DOC-${row.document_id || row.root_document_id}`,
|
||||
status_label: row.status_label,
|
||||
document_id: row.document_id || null,
|
||||
root_document_id: row.root_document_id || null,
|
||||
filename: row.filename,
|
||||
content_hash: row.content_hash,
|
||||
run_no: row.current_run_no,
|
||||
current_run_no: row.current_run_no,
|
||||
user_task_no: userTaskNo,
|
||||
focused: false,
|
||||
}));
|
||||
tasks.push({
|
||||
user_task_no: userTaskNo,
|
||||
user_task_authoritative: Boolean(authoritativeTaskNo),
|
||||
title,
|
||||
display_kind: isMulti ? 'multi_document_task' : 'single_document_task',
|
||||
document_names: documentNames,
|
||||
group,
|
||||
status_label: primaryStatus,
|
||||
file_count: uniqueDocuments.length,
|
||||
run_no: runNo || null,
|
||||
workflow_no: String(primaryItem.workflow_no || '').trim() || null,
|
||||
can_append: false,
|
||||
append_block_reason: 'input_already_frozen',
|
||||
last_activity_at: activityRaw || null,
|
||||
focused: Boolean(
|
||||
(focusUserTask && focusUserTask === userTaskNo)
|
||||
|| (focusRun && focusRun === runNo),
|
||||
),
|
||||
objects: [
|
||||
...projectConversationProcessingObjects(effectiveItems, {
|
||||
focusTaskNo: options?.focusTaskNo,
|
||||
focusRunNo: runNo,
|
||||
}),
|
||||
...documentObjects,
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
return tasks;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将任务列表按分组装入 ConversationProcessingProjection。
|
||||
*/
|
||||
export function groupConversationProcessingTasks(
|
||||
tasks: ConversationProcessingUserTask[],
|
||||
options?: {
|
||||
focusedTaskNo?: string | null;
|
||||
recentTaskNo?: string | null;
|
||||
},
|
||||
): ConversationProcessingProjection {
|
||||
const needs_action = tasks.filter((t) => t.group === 'needs_action');
|
||||
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 totalFiles = active.reduce((sum, task) => sum + Number(task.file_count || 0), 0);
|
||||
const summary: ConversationProcessingSummary = {
|
||||
total_tasks: needs_action.length + processing.length + completed.length,
|
||||
total_files: totalFiles,
|
||||
processing: processing.length,
|
||||
needs_action: needs_action.length,
|
||||
completed: completed.length,
|
||||
history: history.length,
|
||||
};
|
||||
return {
|
||||
summary,
|
||||
focused_task_no: options?.focusedTaskNo || null,
|
||||
recent_task_no: options?.recentTaskNo || null,
|
||||
needs_action,
|
||||
processing,
|
||||
completed,
|
||||
history,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 用 Workflow 兜底投影补齐后端 processing 的多 PDF 标题/文件数。
|
||||
* 核心逻辑:同 user_task_no / run_no 时,若兜底 file_count 更大,采用兜底的
|
||||
* display_kind / title / document_names / objects(文档子对象)。
|
||||
*/
|
||||
/**
|
||||
* 将统一 ShippingProcessing status/gate 映射为会话任务分组。
|
||||
* 核心逻辑:waiting_review/blocked/failed → needs_action;completed → completed;
|
||||
* cancelled → history;其余 → processing。
|
||||
*/
|
||||
export function mapShippingProcessingStatusToTaskGroup(
|
||||
item: ShippingProcessingProjection,
|
||||
): ConversationProcessingTaskGroup {
|
||||
const status = String(item.status || '').trim().toLowerCase();
|
||||
const gateAction = String(item.currentGate?.nextActionCode || '').trim();
|
||||
if (
|
||||
status === 'waiting_review'
|
||||
|| status === 'blocked'
|
||||
|| status === 'failed'
|
||||
|| gateAction === 'open_order_review'
|
||||
|| gateAction === 'retry_parse'
|
||||
|| gateAction === 'retry_failed_documents'
|
||||
) {
|
||||
return 'needs_action';
|
||||
}
|
||||
if (status === 'completed') return 'completed';
|
||||
if (status === 'cancelled') return 'history';
|
||||
return 'processing';
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 embedded conversation_processing 的焦点元数据合并到 work_items 派生投影。
|
||||
* 核心逻辑:任务列表必须来自 work_items;仅 focused_task_no / recent_task_no 可取自 embedded。
|
||||
*
|
||||
* @param derived - 由 projectConversationProcessingFromWorkItems 生成的投影
|
||||
* @param embedded - API 内嵌 conversation_processing(可选)
|
||||
* @returns 合并后的投影;derived 为空时回退 embedded
|
||||
*/
|
||||
export function mergeConversationProcessingFocusMetadata(
|
||||
derived: ConversationProcessingProjection | null,
|
||||
embedded: ConversationProcessingProjection | null | undefined,
|
||||
): ConversationProcessingProjection | null {
|
||||
if (!derived) {
|
||||
return embedded && typeof embedded === 'object' ? embedded : null;
|
||||
}
|
||||
if (!embedded || typeof embedded !== 'object') return derived;
|
||||
return {
|
||||
...derived,
|
||||
focused_task_no: embedded.focused_task_no ?? derived.focused_task_no ?? null,
|
||||
recent_task_no: embedded.recent_task_no ?? derived.recent_task_no ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 从统一 shipping-processing 响应解析 ConversationProcessingProjection。
|
||||
* 核心逻辑:work_items 非空时始终由 order_task 工作项合成任务列表;禁止优先 embedded
|
||||
* (兄弟 OT 仅出现在 work_items,embedded 可能缺 sibling)。
|
||||
*
|
||||
* @param workItems - unified.work_items
|
||||
* @param embedded - unified.conversation_processing
|
||||
* @returns 会话处理投影;无可用数据时 null
|
||||
*/
|
||||
export function resolveConversationProcessingFromUnified(
|
||||
workItems: ShippingProcessingProjection[] | null | undefined,
|
||||
embedded: ConversationProcessingProjection | null | undefined,
|
||||
): ConversationProcessingProjection | null {
|
||||
const items = Array.isArray(workItems) ? workItems : [];
|
||||
if (items.length > 0) {
|
||||
return mergeConversationProcessingFocusMetadata(
|
||||
projectConversationProcessingFromWorkItems(items),
|
||||
embedded,
|
||||
);
|
||||
}
|
||||
if (embedded && typeof embedded === 'object') return embedded;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从统一 work_items 合成 ConversationProcessingProjection(仅 order_task)。
|
||||
*
|
||||
* 核心逻辑:order_task 工作项填充 needs_action/processing/completed;intake 不入组。
|
||||
*
|
||||
* @param workItems - 统一投影 work_items
|
||||
* @returns 兼容投影;无 order_task 时返回 null
|
||||
*/
|
||||
export function projectConversationProcessingFromWorkItems(
|
||||
workItems: ShippingProcessingProjection[] | null | undefined,
|
||||
): ConversationProcessingProjection | null {
|
||||
const items = Array.isArray(workItems) ? workItems : [];
|
||||
const orderTasks = items.filter((row) => row.workItemType === 'order_task');
|
||||
if (!orderTasks.length) return null;
|
||||
|
||||
const needs_action: ConversationProcessingUserTask[] = [];
|
||||
const processing: ConversationProcessingUserTask[] = [];
|
||||
const completed: ConversationProcessingUserTask[] = [];
|
||||
const history: ConversationProcessingUserTask[] = [];
|
||||
|
||||
for (const item of orderTasks) {
|
||||
const taskNo = String(item.workItemNo || item.rootOrderTaskNo || '').trim();
|
||||
if (!taskNo) continue;
|
||||
const group = mapShippingProcessingStatusToTaskGroup(item);
|
||||
const docCount = Number(item.sourceSummary?.documentCount || 0);
|
||||
const filename = String(item.sourceSummary?.filename || '').trim();
|
||||
const task: ConversationProcessingUserTask = {
|
||||
user_task_no: taskNo,
|
||||
user_task_authoritative: true,
|
||||
title: filename || null,
|
||||
display_kind: docCount > 1 ? 'multi_document_task' : 'single_document_task',
|
||||
document_names: filename ? [filename] : [],
|
||||
group,
|
||||
status_label: String(item.status || '') || null,
|
||||
file_count: docCount > 0 ? docCount : (filename ? 1 : 0),
|
||||
run_no: null,
|
||||
can_append: false,
|
||||
last_activity_at: item.lastActivityAt || null,
|
||||
available_actions: Array.isArray(item.availableActions) ? [...item.availableActions] : [],
|
||||
primary_action: item.currentGate?.nextActionCode || item.availableActions?.[0] || null,
|
||||
};
|
||||
if (group === 'needs_action') needs_action.push(task);
|
||||
else if (group === 'processing') processing.push(task);
|
||||
else if (group === 'completed') completed.push(task);
|
||||
else history.push(task);
|
||||
}
|
||||
|
||||
const active = [...needs_action, ...processing, ...completed];
|
||||
if (!active.length && !history.length) return null;
|
||||
const totalFiles = active.reduce((sum, task) => sum + Number(task.file_count || 0), 0);
|
||||
return {
|
||||
summary: {
|
||||
total_tasks: active.length,
|
||||
total_files: totalFiles,
|
||||
processing: processing.length,
|
||||
needs_action: needs_action.length,
|
||||
completed: completed.length,
|
||||
history: history.length,
|
||||
},
|
||||
focused_task_no: null,
|
||||
recent_task_no: null,
|
||||
needs_action,
|
||||
processing,
|
||||
completed,
|
||||
history,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user