chore(shipping-notice): 统一货代发货生命周期阶段命名并优化全链路业务逻辑
This commit is contained in:
1 parent
5ef8329bd8
commit
4ec4e57005
183 files changed
+14653
-3936
No files matched your search
@@ -17,6 +17,7 @@ import type {
|
||||
ConversationProcessingUserTask,
|
||||
ShippingProcessingBlockingReason,
|
||||
ShippingProcessingFacts,
|
||||
ShippingProcessingLifecycleEntry,
|
||||
ShippingProcessingPrimaryAction,
|
||||
ShippingProcessingProjection,
|
||||
ShippingWorkflowItem,
|
||||
@@ -98,6 +99,17 @@ export function buildTaskSemanticKey(
|
||||
uploadState: child.facts?.uploadState ?? null,
|
||||
filename: child.sourceSummary?.filename ?? null,
|
||||
reason: child.blockingReason?.code ?? child.sourceSummary?.failureReasonCode ?? null,
|
||||
// EML 父卡会缓存其叶子对象。子文件的入口与按钮同样是后端裁决,
|
||||
// 必须进入父卡语义签名;否则父卡引用被复用时会残留已撤销的入口。
|
||||
primaryAction: child.uiState
|
||||
? (child.uiState.primary_action?.code ?? null)
|
||||
: (child.primaryAction?.code ?? null),
|
||||
lifecycleEntries: child.uiState?.lifecycleEntries?.map((entry) => ({
|
||||
code: entry.code,
|
||||
state: entry.state,
|
||||
targetSurface: entry.targetSurface,
|
||||
disabledReasonKey: entry.disabledReasonKey ?? null,
|
||||
})) ?? [],
|
||||
}));
|
||||
return JSON.stringify({
|
||||
taskNo: task.user_task_no,
|
||||
@@ -114,6 +126,13 @@ export function buildTaskSemanticKey(
|
||||
: ((task as ConversationProcessingUserTask & { primaryAction?: { code?: string } | null }).primaryAction?.code
|
||||
?? task.primary_action
|
||||
?? null),
|
||||
// 生命周期入口由后端独立裁决;入口被撤销/禁用时必须替换缓存对象,不能保留旧按钮。
|
||||
lifecycleEntries: task.uiState?.lifecycleEntries?.map((entry) => ({
|
||||
code: entry.code,
|
||||
state: entry.state,
|
||||
targetSurface: entry.targetSurface,
|
||||
disabledReasonKey: entry.disabledReasonKey ?? null,
|
||||
})) ?? [],
|
||||
currentGate: (task as ConversationProcessingUserTask & {
|
||||
current_gate?: { blockingReasonCode?: string; nextActionCode?: string };
|
||||
blockingReason?: { code?: string } | null;
|
||||
@@ -911,8 +930,9 @@ export function mergeConversationProcessingFocusMetadata(
|
||||
|
||||
/**
|
||||
* 从统一 shipping-processing 响应解析 ConversationProcessingProjection。
|
||||
* 核心逻辑:work_items 非空时始终由 order_task 工作项合成任务列表;禁止优先 embedded
|
||||
* (兄弟 OT 仅出现在 work_items,embedded 可能缺 sibling)。
|
||||
* 核心逻辑:新版 embedded.status_groups 是后端已完成“当前文件代表项 → EML 容器”
|
||||
* 裁决的唯一列表读源,存在时绝不能再从 work_items 重建;否则旧 Run 会重新进入
|
||||
* 文件清单。旧接口未返回 status_groups 时,才从 work_items 合成兼容任务列表。
|
||||
* 语义稳定化:对比 previousProjection 的签名,复用未变的任务对象引用。
|
||||
*
|
||||
* @param workItems - unified.work_items
|
||||
@@ -927,11 +947,13 @@ export function resolveConversationProcessingFromUnified(
|
||||
stabilizer?: { hasSeenOrderTaskBefore?(conversationId?: string | null): boolean; markSeen?(conversationId?: string | null): void; reset?(conversationId?: string | null): void; conversationId?: string | null },
|
||||
): ConversationProcessingProjection | null {
|
||||
const items = Array.isArray(workItems) ? workItems : [];
|
||||
// [AUTHORITY] 新版接口已经由后端完成「状态 → EML → 业务文件」聚合。
|
||||
// 会话卡与批次中心必须直接使用该结果;前端从 work_items 重建只保留给旧响应兼容。
|
||||
// [AUTHORITY] conversation_processing.status_groups 与 four_stage_nodes / ui_state
|
||||
// 同属后端一次裁决。即使顶层 work_items 非空,也不得前端二次聚合或用旧快照覆盖。
|
||||
if (embedded && typeof embedded === 'object' && embedded.status_groups) {
|
||||
return normalizeConversationProcessingProjection(embedded);
|
||||
}
|
||||
// [AUTHORITY] 新版接口已经由后端完成「状态 → EML → 业务文件」聚合。
|
||||
// 会话卡与批次中心必须直接使用该结果;前端从 work_items 重建只保留给旧响应兼容。
|
||||
// [TRANSITION] 只有统一投影里明确存在 order_task,才认为 OT 维度已经成形。
|
||||
// 仅 order_intake 存在时视为过渡阶段:
|
||||
// - 如果此会话/全局在此之前已见到过 order_task(2s 窗口内),
|
||||
@@ -981,13 +1003,49 @@ export function normalizeConversationProcessingProjection(
|
||||
blockingReason?: ShippingProcessingBlockingReason | null;
|
||||
primaryAction?: ShippingProcessingPrimaryAction | null;
|
||||
secondaryActions?: Array<{ code: string; enabled: boolean }>;
|
||||
lifecycle_stage?: ConversationProcessingUserTask['uiState'] extends { lifecycleStage?: infer S } ? S : never;
|
||||
lifecycle_entries?: Array<Record<string, unknown>>;
|
||||
};
|
||||
const normalizeAction = (action: ShippingProcessingPrimaryAction | null | undefined) => {
|
||||
const normalizeAction = (
|
||||
action: ShippingProcessingPrimaryAction | null | undefined,
|
||||
): ShippingProcessingPrimaryAction | null => {
|
||||
if (!action || typeof action !== 'object') return null;
|
||||
const rawAction = action as ShippingProcessingPrimaryAction & { i18n_key?: string | null };
|
||||
const rawAction = action as ShippingProcessingPrimaryAction & {
|
||||
i18n_key?: string | null;
|
||||
execution_mode?: string | null;
|
||||
target_surface?: string | null;
|
||||
target_lifecycle_stage?: string | null;
|
||||
};
|
||||
return {
|
||||
...rawAction,
|
||||
i18nKey: rawAction.i18nKey ?? rawAction.i18n_key ?? null,
|
||||
// embedded conversation_processing 与 work_items 同为后端 snake_case DTO;
|
||||
// 跳转目标必须在 API 边界完整规范化,否则已授权的主按钮会点击无响应。
|
||||
executionMode: (
|
||||
rawAction.executionMode === 'navigate' || rawAction.executionMode === 'execute'
|
||||
? rawAction.executionMode
|
||||
: (rawAction.execution_mode === 'navigate' || rawAction.execution_mode === 'execute'
|
||||
? rawAction.execution_mode
|
||||
: undefined)
|
||||
),
|
||||
targetSurface: (
|
||||
rawAction.targetSurface === 'order_lifecycle_workbench'
|
||||
? rawAction.targetSurface
|
||||
: (rawAction.target_surface === 'order_lifecycle_workbench'
|
||||
? rawAction.target_surface
|
||||
: null)
|
||||
),
|
||||
targetLifecycleStage: (
|
||||
['intake_parse', 'order_review', 'fulfillment_prep', 'upload_complete'].includes(
|
||||
String(rawAction.targetLifecycleStage),
|
||||
)
|
||||
? rawAction.targetLifecycleStage
|
||||
: (['intake_parse', 'order_review', 'fulfillment_prep', 'upload_complete'].includes(
|
||||
String(rawAction.target_lifecycle_stage),
|
||||
)
|
||||
? rawAction.target_lifecycle_stage
|
||||
: null)
|
||||
) as ShippingProcessingPrimaryAction['targetLifecycleStage'],
|
||||
};
|
||||
};
|
||||
const normalizeReason = (reason: ShippingProcessingBlockingReason | null | undefined) => {
|
||||
@@ -1002,7 +1060,29 @@ export function normalizeConversationProcessingProjection(
|
||||
...state,
|
||||
blocking_reason: normalizeReason(state.blocking_reason ?? state.blockingReason),
|
||||
primary_action: normalizeAction(state.primary_action ?? state.primaryAction),
|
||||
secondary_actions: state.secondary_actions ?? state.secondaryActions ?? [],
|
||||
// 次动作与主动作同属后端 ui_state 授权契约。若仅透传原始 snake_case,
|
||||
// 文件行点击会看不到导航目标并错误落入旧兼容分支。
|
||||
secondary_actions: (state.secondary_actions ?? state.secondaryActions ?? [])
|
||||
.map((action) => {
|
||||
const normalized = normalizeAction(action);
|
||||
return normalized && 'code' in action && 'enabled' in action
|
||||
? { ...normalized, code: String(action.code), enabled: action.enabled !== false }
|
||||
: null;
|
||||
})
|
||||
.filter((action): action is ShippingProcessingPrimaryAction & { code: string; enabled: boolean } => Boolean(action)),
|
||||
lifecycleStage: state.lifecycleStage ?? state.lifecycle_stage,
|
||||
lifecycleEntries: Array.isArray(state.lifecycleEntries)
|
||||
? state.lifecycleEntries.filter((entry) => Boolean(entry?.code && entry?.state && entry?.targetSurface))
|
||||
: (Array.isArray(state.lifecycle_entries)
|
||||
? state.lifecycle_entries.map((entry) => {
|
||||
const rawEntry = entry as { code?: unknown; state?: unknown; target_surface?: unknown; targetSurface?: unknown };
|
||||
return {
|
||||
code: String(rawEntry.code || '') as ShippingProcessingLifecycleEntry['code'],
|
||||
state: String(rawEntry.state || '') as ShippingProcessingLifecycleEntry['state'],
|
||||
targetSurface: String(rawEntry.targetSurface ?? rawEntry.target_surface ?? '') as ShippingProcessingLifecycleEntry['targetSurface'],
|
||||
};
|
||||
}).filter((entry) => Boolean(entry.code && entry.state && entry.targetSurface))
|
||||
: []),
|
||||
};
|
||||
};
|
||||
const normalizeTask = (task: ConversationProcessingUserTask): ConversationProcessingUserTask => {
|
||||
@@ -1114,6 +1194,7 @@ export function normalizeConversationProcessingProjection(
|
||||
history,
|
||||
status_groups: normalizedGroups || projection.status_groups,
|
||||
four_stage_nodes: projection.four_stage_nodes || [],
|
||||
unclassified_summary: projection.unclassified_summary || { count: 0 },
|
||||
ui_state: projection.ui_state || undefined,
|
||||
output_artifacts: projection.output_artifacts || [],
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user