checkpoint: complete recoverable V2 pre-separation baseline
Complete the selective V2 checkpoint with its minimal AgentBus, object-storage, replay persistence, and validated-workbench shared dependency closure.
This commit is contained in:
1 parent
7330ac853b
commit
694c4317a3
627 files changed
+130467
-885
No files matched your search
@@ -0,0 +1,108 @@
|
||||
import type { AgentBusEmlReplayRun, AgentBusReplayTrace } from '@/types/agentBusEmlReplay'
|
||||
|
||||
export type AgentBusReplayPresentationMode = 'REAL_AGENT_FLOW' | 'LEGACY_COMPATIBLE_FLOW'
|
||||
export type AgentBusReplayPresentationState = 'PREVIEW' | 'PROCESSING' | 'SUCCESS' | 'FAILURE' | 'ENDED'
|
||||
export type AgentBusReplayPresentationTone = 'info' | 'warning' | 'success' | 'danger'
|
||||
|
||||
export interface AgentBusReplayPresentation {
|
||||
mode: AgentBusReplayPresentationMode
|
||||
modeLabel: string
|
||||
statusLabel: string
|
||||
state: AgentBusReplayPresentationState
|
||||
tone: AgentBusReplayPresentationTone
|
||||
isProcessing: boolean
|
||||
legacyNotice: string | null
|
||||
}
|
||||
|
||||
const REAL_AGENT_POLICY = 'REQUIRE_REAL_L3_L5'
|
||||
const PREVIEW_STATUSES = new Set(['CREATED', 'PREVIEW_READY'])
|
||||
const PROCESSING_STATUSES = new Set(['EXECUTING', 'PROCESSING'])
|
||||
const SUCCESS_STATUSES = new Set([
|
||||
'SUCCEEDED',
|
||||
'SUCCESS',
|
||||
'VALIDATED',
|
||||
'AWAITING_CONFIRMATION',
|
||||
'PARTIALLY_CONFIRMED',
|
||||
'CONFIRMED',
|
||||
])
|
||||
const FAILURE_STATUSES = new Set(['FAILED', 'REJECTED', 'EXPIRED'])
|
||||
|
||||
export function getAgentBusReplayPresentation(
|
||||
replay: AgentBusEmlReplayRun,
|
||||
trace: AgentBusReplayTrace | null = null,
|
||||
): AgentBusReplayPresentation {
|
||||
const mode: AgentBusReplayPresentationMode = isRealAgentFlow(replay, trace)
|
||||
? 'REAL_AGENT_FLOW'
|
||||
: 'LEGACY_COMPATIBLE_FLOW'
|
||||
|
||||
if (PREVIEW_STATUSES.has(normalize(replay.status)) && !replay.processor_result) {
|
||||
return presentation(mode, 'PREVIEW', mode === 'REAL_AGENT_FLOW' ? '等待执行' : '兼容流程待执行')
|
||||
}
|
||||
|
||||
const replayStatus = normalize(replay.status)
|
||||
const downstreamStatus = normalize(replay.processor_result?.downstream?.status)
|
||||
const traceStatus = normalize(trace?.booking_run_status)
|
||||
const observedStatuses = [traceStatus, downstreamStatus, replayStatus]
|
||||
const hasFailure = observedStatuses.some((status) => FAILURE_STATUSES.has(status))
|
||||
|| Boolean(trace?.stages.some((stage) => stage.status === 'FAILED'))
|
||||
const hasSuccess = observedStatuses.some((status) => SUCCESS_STATUSES.has(status))
|
||||
const downstreamPending = replay.processor_result?.downstream?.asynchronous === true
|
||||
&& !SUCCESS_STATUSES.has(downstreamStatus)
|
||||
&& !FAILURE_STATUSES.has(downstreamStatus)
|
||||
|
||||
if (trace?.terminal === false || PROCESSING_STATUSES.has(replayStatus) || downstreamPending) {
|
||||
return presentation(mode, 'PROCESSING', mode === 'REAL_AGENT_FLOW' ? '全流程处理中' : '兼容流程处理中')
|
||||
}
|
||||
|
||||
if (mode === 'LEGACY_COMPATIBLE_FLOW') {
|
||||
return presentation(mode, 'ENDED', '兼容流程已结束')
|
||||
}
|
||||
|
||||
const hasTerminalEvidence = trace?.terminal === true
|
||||
|| hasFailure
|
||||
|| SUCCESS_STATUSES.has(traceStatus)
|
||||
|| SUCCESS_STATUSES.has(downstreamStatus)
|
||||
|
||||
if (!hasTerminalEvidence) {
|
||||
return presentation(mode, 'PROCESSING', '全流程处理中')
|
||||
}
|
||||
if (hasFailure || !hasSuccess) {
|
||||
return presentation(mode, 'FAILURE', '全流程失败')
|
||||
}
|
||||
return presentation(mode, 'SUCCESS', '全流程成功')
|
||||
}
|
||||
|
||||
function isRealAgentFlow(
|
||||
replay: AgentBusEmlReplayRun,
|
||||
trace: AgentBusReplayTrace | null,
|
||||
): boolean {
|
||||
if (replay.execution_policy === REAL_AGENT_POLICY) return true
|
||||
const replayDownstream = replay.processor_result?.downstream
|
||||
const replayHasRealRun = normalize(replayDownstream?.mode) === 'BOOKING_DECISION_V2'
|
||||
&& Boolean(replayDownstream?.processing_run_id)
|
||||
const traceHasRealRun = normalize(trace?.downstream_mode) === 'BOOKING_DECISION_V2'
|
||||
&& Boolean(trace?.processing_run_id)
|
||||
return replayHasRealRun || traceHasRealRun
|
||||
}
|
||||
|
||||
function presentation(
|
||||
mode: AgentBusReplayPresentationMode,
|
||||
state: AgentBusReplayPresentationState,
|
||||
statusLabel: string,
|
||||
): AgentBusReplayPresentation {
|
||||
return {
|
||||
mode,
|
||||
modeLabel: mode === 'REAL_AGENT_FLOW' ? '真实 Agent 全流程' : '旧兼容流程',
|
||||
statusLabel,
|
||||
state,
|
||||
tone: state === 'SUCCESS' ? 'success' : state === 'FAILURE' ? 'danger' : state === 'PROCESSING' ? 'warning' : 'info',
|
||||
isProcessing: state === 'PROCESSING',
|
||||
legacyNotice: mode === 'LEGACY_COMPATIBLE_FLOW'
|
||||
? '旧兼容流程不会运行 Parsing Agent 和 Booking Agent。'
|
||||
: null,
|
||||
}
|
||||
}
|
||||
|
||||
function normalize(value: string | null | undefined): string {
|
||||
return value?.trim().toUpperCase() ?? ''
|
||||
}
|
||||
Reference in new issue
Block a user