feat(short-drama-agent-front): 同步拆解候选审核与安全提交

This commit is contained in:
GJ committed 2026-10-17 20:18:20 +08:00
1 parent cc27d463e0
commit 190333d4f9
26 files changed
+1495 -249

No files matched your search

+112 -55
View File
@@ -4,7 +4,7 @@ import { NFormItem } from 'naive-ui'
import { integerRule, fieldRule } from '../../lib/form-rules'
import WorkspacePage from '../../components/ui/WorkspacePage.vue'
import WorkspaceExportButton from '../../components/ui/WorkspaceExportButton.vue'
import { NScrollbar, NButton, NCheckbox, NInputNumber, NTab, NTable, NTabs } from 'naive-ui'
import { NScrollbar, NButton, NCheckbox, NCollapse, NCollapseItem, NInputNumber, NTab, NTable, NTabs } from 'naive-ui'
import { computed, h, nextTick, onScopeDispose, ref, watch } from 'vue'
import { useActionMessage } from '../../components/ui/useActionMessage'
import { CircleAlert, Layers, LoaderCircle, Settings2 } from '@lucide/vue'
@@ -23,6 +23,8 @@ import StoryboardDiagnosis from './components/StoryboardDiagnosis.vue'
import BreakdownCandidatePanel from './components/BreakdownCandidatePanel.vue'
import StoryboardQualityRepair from './components/StoryboardQualityRepair.vue'
import BreakdownIssuesDialog from './components/BreakdownIssuesDialog.vue'
import CandidateRepairs from './components/CandidateRepairs.vue'
import { useBreakdownQuality } from './useBreakdownQuality'
import type { DiagnosisLocation } from './diagnosis'
import { errorMessage } from '../../lib/http'
import { downloadText } from '../../lib/format'
@@ -68,15 +70,25 @@ watch(
},
{ immediate: true }
)
const snapshot = computed(() => breakdownSnapshot(checkpoints.value))
const result = computed(() => snapshot.value?.breakdownResult ?? snapshot.value)
/** 当前项目用于候选审核及所有版本化写操作。 */
const projectId = computed(() => project.value?.id ?? '')
/** 候选、正式和历史来源及质量状态统一选择。 */
const qualityObservation = useBreakdownQuality(projectId, checkpoints)
/** 当前质量结论不使用历史嵌套错误,也不作为正式提交许可。 */
const quality = qualityObservation.quality
/** 仅结果展示可回看历史,历史质量不进入当前审核。 */
const snapshot = computed(() => qualityObservation.source.value.state ?? breakdownSnapshot(checkpoints.value))
/** 当前同版本归一化成果,顶层修复优先。 */
const result = computed(() => snapshot.value)
const subjects = computed(() => result.value?.subjectCandidates ?? [])
const forms = computed(() => result.value?.subjectForms ?? [])
const plans = computed(() => result.value?.storyboardPlans ?? [])
const shots = computed(() => result.value?.storyboardEpisodeShots ?? [])
const summary = computed(() => snapshot.value?.taskSummary)
const validation = computed(() => result.value?.storyboardShotValidation ?? snapshot.value?.storyboardShotValidation)
const projectId = computed(() => project.value?.id ?? '')
/** 候选审核读取完成前不展示旧错误。 */
const validation = computed(() => quality.value.structureValid === null ? undefined : { valid: quality.value.structureValid, issues: quality.value.structuralIssues })
/** 数据来源在桌面和移动端正文均明确显示,候选数量不冒充正式资产。 */
const sourceLabel = computed(() => ({ candidate: '拆解候选 · 尚未提交正式结果', formal: '正式拆解结果', history: '历史结果 · 仅供回看', empty: '' })[quality.value.source])
const operation = computed(() => getOperation(projectId.value))
/** 分镜阅读和诊断入口共用当前剧集,不维护独立的诊断集号输入。 */
const selectedEpisodeNo = ref<number>()
@@ -101,7 +113,7 @@ const diagnosisPanel = ref<InstanceType<typeof StoryboardDiagnosis> | null>(null
* @param location 当前分镜坐标
*/
function openShotDiagnosis(location: DiagnosisLocation) {
if (breakdownBusy.value || backgroundExecution.discovering.value) return
if (quality.value.source !== 'formal' || breakdownBusy.value || backgroundExecution.discovering.value) return
diagnosisPanel.value?.open(location)
}
/**
@@ -124,7 +136,19 @@ const execution = computed(() => {
startedAt: record.startedAt ?? record.createdAt,
completedAt: record.completedAt ?? undefined
}
: snapshot.value?.workflowExecution
: latestCheckpoint.value?.state.workflowExecution
})
/** 修复或提交之后的历史失败不污染新版本;活动任务仍使用真实状态。 */
const currentWorkflowError = computed(() => {
if (execution.value?.status !== 'failed') return ''
const latest = latestCheckpoint.value
const failedAt = Date.parse(execution.value.completedAt ?? '')
const checkpointAt = Date.parse(latest?.createdAt ?? '')
// 优先比较真实终态时间,修复元数据不能屏蔽随后启动的新任务失败。
if (Number.isFinite(failedAt) && Number.isFinite(checkpointAt))
return checkpointAt > failedAt ? '' : execution.value.errorMessage || ''
if (!backgroundExecution.query.data.value && latest?.metadata?.sourceCheckpointId) return ''
return execution.value.errorMessage || ''
})
/** 拆解运行状态同时控制状态栏、诊断入口及所有恢复写操作。 */
const breakdownBusy = computed(
@@ -180,6 +204,11 @@ async function locateIssue(issue: ShotValidation['issues'][number]) {
})
}
const taskStopped = computed(() => execution.value?.status === 'failed' || execution.value?.status === 'completed')
/** 后续候选修订已替代旧任务结果时,只在明确的历史记录中展示回执。 */
const executionHistorical = computed(() => {
const record = backgroundExecution.query.data.value
return !!record && !!latestCheckpoint.value && !!record.completedAt && Date.parse(latestCheckpoint.value.createdAt) > Date.parse(record.completedAt)
})
/** 后台拆解结束后自动刷新项目、Checkpoint 与正式主体/分镜数据。 */
watch(
() => backgroundExecution.query.data.value?.status,
@@ -189,26 +218,44 @@ watch(
}
)
/** 结构校验通过后仍可能存在服务端明确标记的质量待审剧集。 */
const pendingQuality = computed(() => !!latestCheckpoint.value?.state.storyboardPendingQualityEpisodeNos?.length)
const pendingQuality = computed(() => quality.value.actionStatus === 'blocked')
/** 只在已有拆解结果且任务中断或校验待处理时提供阶段恢复。 */
const showRecovery = computed(
() =>
records.value.length > 0 &&
(execution.value?.status !== 'completed' || validation.value?.valid === false || pendingQuality.value)
!quality.value.needsRefresh &&
(!!currentWorkflowError.value || validation.value?.valid === false || pendingQuality.value)
)
/** 问题入口兼顾执行异常、结构错误、质量待审和已停止的恢复任务。 */
const hasBreakdownIssues = computed(() =>
Boolean(
execution.value?.errorMessage ||
validation.value?.valid === false ||
pendingQuality.value ||
currentWorkflowError.value ||
quality.value.problems.length ||
quality.value.error ||
(showRecovery.value && taskStopped.value)
)
)
/** 问题按钮按真实问题类型展示,不把质量待审或执行异常误称为结构校验失败。 */
const issueEntryLabel = computed(() =>
validation.value?.valid === false ? '分镜校验未通过' : pendingQuality.value ? '分镜质量待修订' : '拆解问题待处理'
quality.value.error ? '候选审核待刷新' : validation.value?.valid === false ? '分镜校验未通过' : pendingQuality.value ? '分镜质量待修订' : '拆解问题待处理'
)
/** 当前状态颜色只取当前质量和活动任务,不继承历史执行失败。 */
const qualityStatus = computed(() => breakdownBusy.value ? 'running' : quality.value.loading ? 'pending' : quality.value.needsRefresh ? 'unknown' : currentWorkflowError.value ? 'failed' : quality.value.problems.length ? 'blocked' : quality.value.structureValid === true ? quality.value.isCandidate ? 'candidate_pending' : 'completed' : 'unknown')
/** 当前生命周期与审核文案集中展示。 */
const qualityLabel = computed(() => {
if (breakdownBusy.value) return '拆解进行中'
if (backgroundExecution.discovering.value) return '正在读取任务状态'
if (quality.value.loading) return '正在审核候选'
if (quality.value.needsRefresh) return '候选审核待确认'
if (validation.value?.valid === false) return '分镜校验未通过'
if (pendingQuality.value) return '分镜质量待修订'
if (currentWorkflowError.value) return '工作流失败'
if (quality.value.committed) return '已提交正式结果'
if (quality.value.isCandidate && quality.value.canRequestCommitPreview) return '候选审核通过 · 待安全预检查'
if (quality.value.source === 'history') return '历史结果 · 当前质量待确认'
if (quality.value.isCandidate) return '候选审核待处理'
return quality.value.structureValid === true ? '正式分镜校验通过' : '执行状态待确认'
})
/** 所有问题修改和恢复共用活动锁及后台状态读取限制,查看问题不受影响。 */
const issueActionsDisabled = computed(
() =>
@@ -218,6 +265,7 @@ const issueActionsDisabled = computed(
breakdownBusy.value ||
backgroundExecution.discovering.value ||
!!backgroundExecution.discoveryError.value
|| quality.value.loading || !!quality.value.error
)
const configValid = computed(
() => Number.isSafeInteger(groupSize.value) && groupSize.value > 0 && modules.value.length > 0
@@ -235,25 +283,30 @@ const actionMessage = useActionMessage()
/** 问题内容变化才通知,轮询取得相同快照时不会重复弹出。 */
const issueSignature = computed(() =>
JSON.stringify({
error: execution.value?.errorMessage || '',
issues: validation.value?.valid === false ? validation.value.issues : []
projectId: projectId.value,
checkpointId: quality.value.checkpointId,
error: currentWorkflowError.value,
problems: quality.value.problems
})
)
/** 首次读取或问题变化时只显示一条汇总,保留可操作的详情入口。 */
/** 当前会话同一版本的相同问题只通知一次,重审或切集不重复弹出。 */
const notifiedIssues = new Set<string>()
watch(
issueSignature,
() => {
const executionError = execution.value?.errorMessage
const invalid = validation.value?.valid === false
if (breakdownBusy.value || backgroundExecution.discovering.value) return
if (!executionError && !invalid) return
const executionError = currentWorkflowError.value
const invalid = quality.value.issueCount > 0
if (quality.value.needsRefresh || quality.value.loading || breakdownBusy.value || backgroundExecution.discovering.value) return
if ((!executionError && !invalid) || notifiedIssues.has(issueSignature.value)) return
notifiedIssues.add(issueSignature.value)
actionMessage?.warning(
() =>
h('div', { class: 'flex flex-wrap items-center gap-3' }, [
h(
'span',
invalid
? `分镜校验未通过,共 ${validation.value?.issues.length ?? 0} 项问题。`
? `当前${quality.value.isCandidate ? '候选' : '正式分镜'}待处理:结构 ${quality.value.structuralCount} 项,动作 ${quality.value.actionBlocks.length} 镜${quality.value.pendingEpisodeNos.length ? `,待审 ${quality.value.pendingEpisodeNos.length} 集` : ''}。`
: '拆解任务未完成,请查看错误详情。'
),
h(
@@ -365,7 +418,9 @@ async function run(action: BreakdownAction) {
/** 刷新候选和正式阶段状态,不重放候选生成请求。 */
async function refreshCandidate() {
await Promise.all([refresh(), refreshStageReadiness()])
const key = qualityObservation.key.value
await Promise.all([refresh(), refreshStageReadiness(), backgroundExecution.query.refresh()])
if (key === qualityObservation.key.value) await qualityObservation.refresh()
}
/** 导出当前拆解结果;阶段性数据也明确标记为 snapshot。 */
@@ -397,31 +452,7 @@ const rules = {
>抽取 {{ summary.completed }} / {{ summary.total }} · 失败 {{ summary.failed }}</span
>
<span>主体 {{ subjects.length }} · 分镜剧集 {{ shots.length }} / {{ plans.length }}</span>
<StatusBadge
:status="
breakdownBusy
? 'running'
: validation?.valid === false
? 'blocked'
: execution?.status || 'unknown'
"
:label="
breakdownBusy
? '拆解进行中'
: backgroundExecution.discovering.value
? '正在读取任务状态'
: validation?.valid === false
? '分镜校验未通过'
: execution?.status === 'completed'
? latestCheckpoint?.state.candidateOnly &&
!latestCheckpoint.state.storyboardPersisted
? '候选生成已完成'
: '工作流已完成'
: execution?.status === 'failed'
? '工作流失败'
: '执行状态待确认'
"
/>
<StatusBadge :status="qualityStatus" :label="qualityLabel" />
<span v-if="breakdownBusy" class="flex items-center gap-2" role="status"
><LoaderCircle :size="13" class="animate-spin" />最近阶段:{{ runningStage }}</span
>
@@ -588,14 +619,18 @@ const rules = {
</section>
<BreakdownCandidatePanel
:project-id="projectId"
:state="latestCheckpoint?.state"
:state="qualityObservation.source.value.state || undefined"
:quality="quality"
:checkpoint-id="latestCheckpoint?.checkpointId"
:disabled="!!error || operation.pending || backgroundExecution.active.value"
:disabled="issueActionsDisabled"
@refresh="refreshCandidate"
/>
<!-- 以下是明确标记的历史执行回执,旧任务结论不表示当前候选质量 -->
<component :is="executionHistorical ? NCollapse : 'div'" v-if="backgroundExecution.executionId.value" :class="{ 'breakdown-execution-history': executionHistorical }">
<component :is="executionHistorical ? NCollapseItem : 'div'" :name="executionHistorical ? 'history' : undefined" :title="executionHistorical ? '历史拆解执行记录(不代表当前质量)' : undefined">
<WorkflowExecutionPanel
v-if="backgroundExecution.executionId.value"
title="剧本拆解任务"
:title="executionHistorical ? '历史拆解任务' : '剧本拆解任务'"
class="breakdown-execution-panel"
:show-status-hint="false"
:execution="backgroundExecution.query.data.value"
@@ -604,6 +639,8 @@ const rules = {
@refresh="backgroundExecution.query.refresh"
@dismiss="backgroundExecution.dismiss"
/>
</component>
</component>
</WorkspaceTools>
</div>
</div>
@@ -615,7 +652,9 @@ const rules = {
/>
</NScrollbar>
<template v-else>
<section class="breakdown-results-section">
<section class="breakdown-results-section" :data-breakdown-source="quality.source">
<!-- 以下是候选与正式数据来源提示,手机也不隐藏,防止把候选镜头当作正式资产 -->
<p v-if="sourceLabel" class="text-xs text-muted" role="status">{{ sourceLabel }}<span v-if="quality.loading"> · 正在读取当前质量审核…</span></p>
<div class="result-toolbar tabs-toolbar">
<NTabs v-model:value="tab" class="workspace-tabs" type="line" size="small" aria-label="拆解结果"
><!-- 以下是仅显示分类名称的拆解标签模块,主体数量保留在搜索统计中 -->
@@ -670,7 +709,7 @@ const rules = {
<template v-for="option in moduleOptions" :key="option.value"
><div v-if="tab === option.value" class="breakdown-result-pad">
<SubjectList
:project-id="project?.id"
:project-id="quality.source === 'formal' ? project?.id : undefined"
:subjects="subjects.filter(item => item.module === option.value)"
:forms="forms"
/></div
@@ -681,13 +720,13 @@ const rules = {
v-model:episode-no="selectedEpisodeNo"
:plans="plans"
:episodes="shots"
:diagnosis-disabled="breakdownBusy || backgroundExecution.discovering.value"
:diagnosis-disabled="quality.source !== 'formal' || breakdownBusy || backgroundExecution.discovering.value"
@diagnose="openShotDiagnosis"
>
<!-- 以下是跟随当前剧集的一行诊断摘要,诊断弹窗独立于列表滚动 -->
<template #diagnosis>
<StoryboardDiagnosis
v-if="!breakdownBusy && !backgroundExecution.discovering.value"
v-if="quality.source === 'formal' && !breakdownBusy && !backgroundExecution.discovering.value"
ref="diagnosisPanel"
:project-id="projectId"
:episode-no="currentEpisodeNo"
@@ -759,9 +798,11 @@ const rules = {
<BreakdownIssuesDialog
v-model:open="issuesOpen"
:issues="storyboardIssues"
:workflow-error="execution?.errorMessage"
:quality="quality"
:workflow-error="currentWorkflowError"
:locatable="!breakdownBusy && !!shots.length"
@locate="locateIssue"
@refresh="refreshCandidate"
>
<!-- 以下是只属于问题处理的人工修订与阶段恢复,不混入拆解启动配置 -->
<template #repair>
@@ -775,8 +816,17 @@ const rules = {
>
任务状态或结果尚未确认,请先重新读取状态与结果。
</p>
<CandidateRepairs
v-if="issuesOpen && quality.isCandidate && snapshot"
:project-id="projectId"
:checkpoint-id="latestCheckpoint?.checkpointId || ''"
:state="snapshot"
:review="qualityObservation.review.value"
:disabled="issueActionsDisabled"
@refresh="refreshCandidate"
/>
<StoryboardQualityRepair
v-if="issuesOpen && snapshot"
v-else-if="issuesOpen && snapshot && !quality.isCandidate"
:project-id="projectId"
:checkpoint="latestCheckpoint"
:disabled="issueActionsDisabled"
@@ -816,6 +866,13 @@ const rules = {
</template>
<style>
/* 历史折叠只保留一层内容留白,避免 Naive 内容间距叠加任务卡片的 mt-4。 */
.breakdown-execution-history.n-collapse .n-collapse-item .n-collapse-item__content-wrapper .n-collapse-item__content-inner {
padding-top: 8px;
}
.breakdown-execution-history .breakdown-execution-panel {
margin-top: 0;
}
/* 键盘聚焦仍有清晰提示,并与问题入口的红色语义保持一致。 */
.breakdown-workspace-page .breakdown-issues-trigger.n-button:focus-visible {
outline-color: var(--app-danger);