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
@@ -1,23 +1,37 @@
|
||||
/**
|
||||
* features/shipping-progress/actionPresentation.ts
|
||||
* 用途:从统一投影解析四页面共用的 ActionPresentation(主/次/溢出)。
|
||||
* 依赖:ShippingProcessingProjection、SHIPPING_PROCESSING_ACTION_INTENTS、types。
|
||||
* 用途:从统一投影 / 会话 OT 任务解析四页面共用的 ActionPresentation(主/次/溢出)。
|
||||
* 依赖:ShippingProcessingProjection、ConversationProcessingUserTask、workbenchActionRegistry、types。
|
||||
* 逻辑:优先级 Gate.nextActionCode → availableActions → 终态查看 → none;
|
||||
* 自动处理中(processing/automating)主按钮为空;review 面隐藏 open_order_review。
|
||||
* cancel_* 与 view_details 永不作主 CTA;无业务入口时 focus_task 兜底并映射「查看进度」;
|
||||
* 自动处理中(processing/automating)主按钮为空;review 面经注册表 fail-closed 过滤。
|
||||
*/
|
||||
|
||||
import type {
|
||||
ConversationProcessingUserTask,
|
||||
ShippingProcessingActionIntent,
|
||||
ShippingProcessingProjection,
|
||||
} from '@/features/chat/types/shipping.api.types';
|
||||
import type { ActionPresentation, ActionPresentationItem, ActionPresentationSurface } from './types';
|
||||
import type { WorkbenchPanelAvailability } from './workbenchActionRegistry';
|
||||
import {
|
||||
lookupWorkbenchAction,
|
||||
shouldRenderWorkbenchAction,
|
||||
warnUnregisteredWorkbenchAction,
|
||||
} from './workbenchActionRegistry';
|
||||
|
||||
/** 可映射为统一意图的原始动作码(gate / available_actions)。 */
|
||||
const ACTION_CODE_TO_INTENT: Record<string, ShippingProcessingActionIntent> = {
|
||||
open_order_review: 'open_order_review',
|
||||
open_review: 'open_order_review',
|
||||
open_order_processing: 'open_order_review',
|
||||
enter_manual_review: 'open_order_review',
|
||||
edit_formal_task: 'edit_formal_task',
|
||||
freeze_order: 'edit_formal_task',
|
||||
open_profile_review: 'open_profile_review',
|
||||
confirm_customer: 'confirm_customer',
|
||||
resolve_field_conflicts: 'resolve_field_conflicts',
|
||||
adjudicate_duplicate: 'adjudicate_duplicate',
|
||||
open_inventory_source_review: 'open_inventory_source_review',
|
||||
confirm_inventory_source: 'open_inventory_source_review',
|
||||
retry_resolve_inventory_source: 'open_inventory_source_review',
|
||||
@@ -29,6 +43,9 @@ const ACTION_CODE_TO_INTENT: Record<string, ShippingProcessingActionIntent> = {
|
||||
retry: 'retry',
|
||||
retry_parse: 'retry',
|
||||
retry_failed_documents: 'retry',
|
||||
retry_failed_attachments: 'retry',
|
||||
retry_upload: 'retry',
|
||||
retry_freight_upload_rpa: 'retry',
|
||||
refresh: 'refresh',
|
||||
regenerate_excel: 'regenerate_excel',
|
||||
generate_excel: 'regenerate_excel',
|
||||
@@ -40,13 +57,21 @@ const ACTION_CODE_TO_INTENT: Record<string, ShippingProcessingActionIntent> = {
|
||||
open_fulfillment: 'view_result',
|
||||
view_result: 'view_result',
|
||||
view_details: 'view_result',
|
||||
focus_task: 'view_result',
|
||||
view_record: 'view_record',
|
||||
/** 取消类动作映射为 view_record,以便进入 presentation(再由 NEVER_PRIMARY 降为次要)。 */
|
||||
cancel_task: 'view_record',
|
||||
cancel_run: 'view_record',
|
||||
};
|
||||
|
||||
const AUTOMATING_STATUSES = new Set(['processing', 'automating', 'queued']);
|
||||
/** 永不升为主 CTA 的动作码(仍可作次要/溢出)。 */
|
||||
const NEVER_PRIMARY_CODES = new Set(['cancel_task', 'cancel_run', 'view_details']);
|
||||
|
||||
/**
|
||||
* 将原始动作码映射为统一意图;未知码返回 null。
|
||||
*
|
||||
* @param code - Gate / available_actions 原始码
|
||||
*/
|
||||
export function mapActionCodeToIntent(code: string | null | undefined): ShippingProcessingActionIntent | null {
|
||||
const normalized = String(code || '').trim().toLowerCase();
|
||||
@@ -56,6 +81,7 @@ export function mapActionCodeToIntent(code: string | null | undefined): Shipping
|
||||
|
||||
/**
|
||||
* 构建单个动作项。
|
||||
* 核心逻辑:默认 labelKey=action.{intent};chat/right 面改写订单处理 / 重试解析 / 查看进度。
|
||||
*/
|
||||
function toItem(
|
||||
code: string,
|
||||
@@ -63,11 +89,18 @@ function toItem(
|
||||
surface?: ActionPresentationSurface,
|
||||
): ActionPresentationItem {
|
||||
let labelKey = `chat.shippingProcessing.action.${intent}`;
|
||||
if (
|
||||
intent === 'open_order_review'
|
||||
&& (surface === 'chat' || surface === 'right')
|
||||
) {
|
||||
const normalized = String(code || '').trim().toLowerCase();
|
||||
const chatOrRight = surface === 'chat' || surface === 'right';
|
||||
if (intent === 'open_order_review' && chatOrRight) {
|
||||
labelKey = 'chat.shippingProcessing.action.open_order_processing';
|
||||
} else if (intent === 'retry' && chatOrRight) {
|
||||
labelKey = 'chat.shippingProcessing.action.retry_parse';
|
||||
} else if (normalized === 'focus_task' && chatOrRight) {
|
||||
labelKey = 'chat.shippingProcessing.action.view_progress';
|
||||
} else if (normalized === 'cancel_task' || normalized === 'cancel_run') {
|
||||
labelKey = 'chat.shippingProcessing.cancelEntireTaskSingle';
|
||||
} else if (normalized === 'view_details') {
|
||||
labelKey = 'chat.shippingProcessing.viewTaskDetails';
|
||||
}
|
||||
return {
|
||||
intent,
|
||||
@@ -76,6 +109,39 @@ function toItem(
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 将动作列表拆成主/次/溢出;cancel 与 view_details 永不作 primary。
|
||||
*/
|
||||
function partitionActionItems(items: ActionPresentationItem[]): ActionPresentation {
|
||||
if (!items.length) {
|
||||
return { primary: null, secondary: null, overflow: [] };
|
||||
}
|
||||
const primaryPool = items.filter(
|
||||
(item) => !NEVER_PRIMARY_CODES.has(String(item.actionCode || '').trim().toLowerCase()),
|
||||
);
|
||||
const demoted = items.filter(
|
||||
(item) => NEVER_PRIMARY_CODES.has(String(item.actionCode || '').trim().toLowerCase()),
|
||||
);
|
||||
const primary = primaryPool[0] || null;
|
||||
const rest = [
|
||||
...primaryPool.slice(1),
|
||||
...demoted,
|
||||
];
|
||||
return {
|
||||
primary,
|
||||
secondary: rest[0] || null,
|
||||
overflow: rest.slice(1),
|
||||
};
|
||||
}
|
||||
|
||||
export interface ResolveProcessingActionPresentationOptions {
|
||||
surface?: ActionPresentationSurface;
|
||||
/** 订单处理工作台写权限;仅 surface=review 时生效。 */
|
||||
actionsExecutable?: boolean;
|
||||
/** 面板可用性(review 面 requiresPanel 守卫)。 */
|
||||
panels?: WorkbenchPanelAvailability | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析统一动作投影。
|
||||
*
|
||||
@@ -84,16 +150,22 @@ function toItem(
|
||||
* 2. currentGate.nextActionCode 优先;
|
||||
* 3. availableActions 依次填主/次/溢出;
|
||||
* 4. completed/failed/cancelled → view_result / view_record 兜底;
|
||||
* 5. surface=review 时过滤 open_order_review(已在复核页)。
|
||||
* 5. surface=review 时经注册表 fail-closed(未知隐藏 + 告警;隐藏 refresh/自跳转);
|
||||
* 6. cancel / view_details 强制降为次要或溢出。
|
||||
*
|
||||
* @param projection - 统一处理投影
|
||||
* @param options - surface / actionsExecutable / panels
|
||||
*/
|
||||
export function resolveProcessingActionPresentation(
|
||||
projection: ShippingProcessingProjection | null | undefined,
|
||||
options?: { surface?: ActionPresentationSurface },
|
||||
options?: ResolveProcessingActionPresentationOptions,
|
||||
): ActionPresentation {
|
||||
const empty: ActionPresentation = { primary: null, secondary: null, overflow: [] };
|
||||
if (!projection) return empty;
|
||||
|
||||
const surface = options?.surface;
|
||||
const actionsExecutable = options?.actionsExecutable !== false;
|
||||
const panels = options?.panels ?? null;
|
||||
const status = String(projection.status || '').trim().toLowerCase();
|
||||
if (AUTOMATING_STATUSES.has(status) && !projection.currentGate?.nextActionCode) {
|
||||
return empty;
|
||||
@@ -107,10 +179,36 @@ export function resolveProcessingActionPresentation(
|
||||
if (!code) return;
|
||||
const key = code.toLowerCase();
|
||||
if (seen.has(key)) return;
|
||||
const intent = mapActionCodeToIntent(code);
|
||||
if (!intent || intent === 'none') return;
|
||||
if (surface === 'review' && intent === 'open_order_review') return;
|
||||
seen.add(key);
|
||||
const intent = mapActionCodeToIntent(code);
|
||||
if (!intent || intent === 'none') {
|
||||
// [fail-closed] 未知动作不渲染原始码,仅告警。
|
||||
warnUnregisteredWorkbenchAction({
|
||||
actionCode: code,
|
||||
surface: surface || 'workbench',
|
||||
workItemType: projection.workItemType,
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (surface === 'review') {
|
||||
const entry = lookupWorkbenchAction(code) || lookupWorkbenchAction(intent);
|
||||
if (!entry) {
|
||||
warnUnregisteredWorkbenchAction({
|
||||
actionCode: code,
|
||||
surface: 'review',
|
||||
workItemType: projection.workItemType,
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (!shouldRenderWorkbenchAction(entry, {
|
||||
actionsExecutable,
|
||||
surface: 'review',
|
||||
panels,
|
||||
actionCode: code,
|
||||
})) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
items.push(toItem(code, intent, surface));
|
||||
};
|
||||
|
||||
@@ -127,9 +225,50 @@ export function resolveProcessingActionPresentation(
|
||||
return empty;
|
||||
}
|
||||
|
||||
return {
|
||||
primary: items[0] || null,
|
||||
secondary: items[1] || null,
|
||||
overflow: items.slice(2),
|
||||
return partitionActionItems(items);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从会话 OT 任务投影解析 ActionPresentation(无 workItem 时的统一适配器)。
|
||||
* 核心逻辑:primary_action 优先;available_actions 补充;无正式入口时 focus_task→查看进度;
|
||||
* cancel/view_details 永不作主 CTA。
|
||||
* @param task - 会话用户可见任务
|
||||
* @param options.surface - 展示面(默认 right)
|
||||
*/
|
||||
export function resolveConversationTaskActionPresentation(
|
||||
task: ConversationProcessingUserTask | null | undefined,
|
||||
options?: { surface?: ActionPresentationSurface },
|
||||
): ActionPresentation {
|
||||
const empty: ActionPresentation = { primary: null, secondary: null, overflow: [] };
|
||||
if (!task) return empty;
|
||||
|
||||
const surface = options?.surface || 'right';
|
||||
const items: ActionPresentationItem[] = [];
|
||||
const seen = new Set<string>();
|
||||
|
||||
const pushCode = (raw: string | null | undefined) => {
|
||||
const code = String(raw || '').trim();
|
||||
if (!code) return;
|
||||
const key = code.toLowerCase();
|
||||
if (seen.has(key)) return;
|
||||
const intent = mapActionCodeToIntent(code);
|
||||
if (!intent || intent === 'none') return;
|
||||
seen.add(key);
|
||||
items.push(toItem(code, intent, surface));
|
||||
};
|
||||
|
||||
pushCode(task.primary_action);
|
||||
for (const action of task.available_actions || []) {
|
||||
pushCode(action);
|
||||
}
|
||||
|
||||
// 无正式业务入口时,默认提供查看进度(focus_task)。
|
||||
const hasPrimaryCandidate = items.some(
|
||||
(item) => !NEVER_PRIMARY_CODES.has(String(item.actionCode || '').trim().toLowerCase()),
|
||||
);
|
||||
if (!hasPrimaryCandidate) {
|
||||
pushCode('focus_task');
|
||||
}
|
||||
|
||||
return partitionActionItems(items);
|
||||
}
|
||||
Reference in new issue
Block a user