适配 M002 V3 前端任务流与同卡复核

This commit is contained in:
andy
2026-07-12 00:33:15 +08:00
parent fd027f124c
commit 155db63028
17 changed files with 1593 additions and 85 deletions

View File

@@ -1,5 +1,16 @@
type ReservationTranslator = (key: string, fallback?: string) => string
export interface ReservationTaskRouteLike {
task_type?: string | null
system_task_type?: string | null
task_card_type?: string | null
task_subtype?: string | null
result_type?: string | null
ai_task_type?: string | null
route_code?: string | null
system_process_category?: string | null
}
export function formatReservationTaskCard(
t: ReservationTranslator,
taskType: string | null | undefined,
@@ -26,6 +37,116 @@ export function isReservationSourceMessageOnlyTask(...codes: Array<string | null
return codes.some((code) => normalizeStableCode(code) === 'SOURCE_MESSAGE_ONLY')
}
export function isReservationSourceMessageNotificationTask(input: ReservationTaskRouteLike | null | undefined): boolean {
if (!input) {
return false
}
const subtype = normalizeStableCode(input.task_subtype)
const routeCode = normalizeStableCode(input.route_code)
if (
normalizeStableCode(input.result_type) === 'SOURCE_MESSAGE_REVIEW_NOTIFICATION' ||
normalizeStableCode(input.system_process_category) === 'SOURCE_MESSAGE_NOTIFICATION' ||
isReservationSourceMessageOnlyTask(input.task_type, input.system_task_type, input.task_card_type)
) {
return true
}
const hasSourceMessageRouteCode = ['S10', 'S99', 'S000', 'S999'].includes(subtype) ||
['S10', 'S99', 'S000', 'S999'].includes(routeCode)
const hasSourceMessageTaskContext = [
input.task_type,
input.system_task_type,
input.task_card_type,
input.ai_task_type,
].some((code) =>
['SOURCE_MESSAGE_ONLY', 'MESSAGE_NOTIFICATION', 'INFORMATIONAL_MESSAGE'].includes(normalizeStableCode(code)),
)
return hasSourceMessageRouteCode && hasSourceMessageTaskContext
}
export function isReservationAdapterContractErrorTask(input: ReservationTaskRouteLike | null | undefined): boolean {
return (
normalizeStableCode(input?.result_type) === 'ADAPTER_CONTRACT_ERROR' ||
normalizeStableCode(input?.system_process_category) === 'ADAPTER_CONTRACT_ERROR'
)
}
export function isReservationUnhandledIntentTask(input: ReservationTaskRouteLike | null | undefined): boolean {
return (
normalizeStableCode(input?.result_type) === 'UNHANDLED_CURRENT_INTENT' ||
normalizeStableCode(input?.system_process_category) === 'UNHANDLED_CURRENT_INTENT'
)
}
export function isReservationReadonlyDiagnosticTask(input: ReservationTaskRouteLike | null | undefined): boolean {
return (
isReservationSourceMessageNotificationTask(input) ||
isReservationAdapterContractErrorTask(input) ||
isReservationUnhandledIntentTask(input)
)
}
export function isReservationTypeKnownManualReviewTask(input: ReservationTaskRouteLike | null | undefined): boolean {
if (normalizeStableCode(input?.result_type) !== 'MANUAL_REVIEW') {
return false
}
const systemTaskType = normalizeStableCode(input?.system_task_type)
const cardType = normalizeStableCode(input?.task_card_type)
return !['MANUAL_REVIEW', 'FALLBACK', 'FALLBACK_REVIEW'].includes(systemTaskType) &&
!['MANUAL_REVIEW', 'FALLBACK', 'FALLBACK_REVIEW'].includes(cardType)
}
export function isReservationFallbackManualReviewTask(input: ReservationTaskRouteLike | null | undefined): boolean {
const codes = [
input?.system_task_type,
input?.task_card_type,
input?.task_type,
input?.ai_task_type,
input?.task_subtype,
]
return codes.some((code) => ['MANUAL_REVIEW', 'FALLBACK', 'FALLBACK_REVIEW'].includes(normalizeStableCode(code)))
}
export function formatReservationTaskRouteSummary(
t: ReservationTranslator,
input: ReservationTaskRouteLike,
fallbackLabel?: string | null,
): string {
if (isReservationSourceMessageNotificationTask(input)) {
return `${t('cardType.SOURCE_MESSAGE_ONLY')} / ${formatReservationRouteCode(t, input.route_code ?? input.task_subtype)}`
}
if (isReservationAdapterContractErrorTask(input)) {
return t('resultType.ADAPTER_CONTRACT_ERROR')
}
if (isReservationUnhandledIntentTask(input)) {
return t('resultType.UNHANDLED_CURRENT_INTENT')
}
return formatReservationTaskTypeSummary(
t,
input.task_type ?? input.system_task_type ?? input.task_card_type,
input.task_subtype,
) || fallbackLabel || t('common.unknownTaskType')
}
export function formatReservationResultType(t: ReservationTranslator, resultType: string | null | undefined): string {
return translateStableCode(t, 'resultType', resultType, 'common.unknownTaskType')
}
export function formatReservationSystemProcessCategory(
t: ReservationTranslator,
category: string | null | undefined,
): string {
return translateStableCode(t, 'systemProcessCategory', category, 'common.unknownTaskType')
}
export function formatReservationRouteCode(t: ReservationTranslator, routeCode: string | null | undefined): string {
const normalizedCode = normalizeStableCode(routeCode)
if (['S10', 'S99', 'S000', 'S999'].includes(normalizedCode)) {
return translateStableCode(t, 'taskSubtype', routeCode, 'common.unknownTaskSubtype')
}
return routeCode || t('common.unknownTaskSubtype')
}
export function formatReservationReadonlyReason(
t: ReservationTranslator,
reasonCode: string | null | undefined,
@@ -77,7 +198,7 @@ function translateStableCode(
return t(`${namespace}.${normalizedCode}`, fallbackLabel || t(fallbackKey))
}
function normalizeStableCode(code: string | null | undefined): string {
export function normalizeStableCode(code: string | null | undefined): string {
if (!code) {
return ''
}