feat(short-drama-agent-front): 接入正式审核执行历史

This commit is contained in:
GJ committed 2026-11-07 14:03:38 +08:00
1 parent 518b630a46
commit c808a58a3f
17 files changed
+1129 -175

No files matched your search

@@ -0,0 +1,191 @@
<script setup lang="ts">
import { computed, ref, watch } from 'vue'
import { NButton, NCollapse, NCollapseItem } from 'naive-ui'
import { formatDate } from '../../../lib/format'
import { useValidationExecutions } from '../useValidationExecutions'
import type { WorkflowExecution } from '../../workflows/execution.types'
import type { ValidationExecutionHistoryItem, ValidationStepName } from '../validation-executions.types'
import { validationStatusLabels, validationStepNames } from '../validation-execution-labels'
import KeyframeExecutionStatus from './KeyframeExecutionStatus.vue'
import KeyframeValidationSteps from './KeyframeValidationSteps.vue'
/** 单个审核任务的正式分页历史,关闭时中止请求,不使用本机历史缓存。 */
const props = defineProps<{
/** 当前项目,兼容没有项目参数的历史调用方。 */ projectId?: string
/** 正式镜头。 */ shotId: string
/** 当前候选。 */ keyframeId: string
/** 原审核任务,多个任务分别加载。 */ validationTaskId: string
/** 原轻量历史更新时仅作为刷新信号,不替代正式指针。 */ latestExecutionId?: string
/** 外部现有 GET/SSE 的观察结果,不创建额外订阅。 */ liveExecution?: WorkflowExecution | null
}>()
/** 统一使用 Naive 折叠组件,只有明确展开才读取。 */
const expanded = ref<string[]>([])
/** 查询身份固定全部资源,游标不跨资源复用。 */
const key = computed(() =>
expanded.value.includes('executions') && props.shotId && props.keyframeId && props.validationTaskId
? JSON.stringify([props.projectId, props.shotId, props.keyframeId, props.validationTaskId])
: ''
)
const query = useValidationExecutions(key)
/** 外部事件必须属于此任务及同一项目、镜头和候选。 */
const live = computed(() => {
const record = props.liveExecution
return record &&
(!props.projectId || record.projectId === props.projectId) &&
record.workflowName === 'shot-keyframe-validation' &&
record.metadata?.validationTaskId === props.validationTaskId &&
record.metadata?.shotId === props.shotId &&
record.metadata?.keyframeId === props.keyframeId
? record
: null
})
/** 同一终态或新执行信号只刷新一次,避免延迟同步时形成读取循环。 */
let refreshedSignal = ''
watch(
key,
() => {
refreshedSignal = ''
},
{ flush: 'sync' }
)
watch([() => props.latestExecutionId, live, query.loading], () => {
if (!key.value || !query.data.value || query.loading.value) return
const record = live.value
const known = query.items.value.find(item => item.execution.id === record?.id)?.execution
const changed =
query.data.value.integrity.currentExecution === 'valid' &&
props.latestExecutionId &&
props.latestExecutionId !== query.data.value.currentExecutionId
const terminal = record && ['completed', 'failed'].includes(record.status) && record.status !== known?.status
const signal = JSON.stringify([key.value, props.latestExecutionId, record?.id, record?.status, record?.updatedAt])
if ((changed || terminal) && refreshedSignal !== signal) {
refreshedSignal = signal
void query.refresh()
}
})
/**
* 只将更新的相同执行事件用于它自己的记录,不改写其他执行的结果或步骤。
* @param item 正式逐次记录
* @returns 此次执行的最新公开状态
*/
function displayExecution(item: ValidationExecutionHistoryItem) {
const record = live.value
const original = item.execution
return record?.id === original.id &&
!['completed', 'failed'].includes(original.status) &&
Date.parse(record.updatedAt) >= Date.parse(original.updatedAt)
? record
: original
}
/**
* 区分未记录范围与明确没有计划的新提交步骤。
* @param steps 服务保存的本次范围
* @returns 中文步骤或未记录说明
*/
function stepScope(steps: ValidationStepName[] | null) {
return steps === null ? '未记录' : steps.length ? steps.map(step => validationStepNames[step]).join('、') : '无'
}
/** 服务保存的模式只在展示层转为中文。 */
const modeLabels = {
initial: '首次审核',
resume: '继续原审核',
physical_retry: '仅补跑物理专项',
unknown: '执行范围未记录'
}
/** 正式逐次步骤的证据来源。 */
const evidenceLabels = {
execution_snapshot: '本次执行记录',
archived_audit: '已核对的历史审计',
not_recorded: '未记录本次步骤证据'
}
</script>
<template>
<!-- 以下是当前审核任务的执行记录按需读取模块 -->
<NCollapse v-model:expanded-names="expanded" class="mt-3">
<NCollapseItem name="executions" title="执行记录">
<section
class="space-y-3"
:aria-label="`审核任务 ${validationTaskId} 的执行记录`"
:aria-busy="query.loading.value"
>
<div class="flex flex-wrap items-center justify-between gap-3">
<p v-if="query.data.value" class="text-xs text-muted">
任务状态:{{ validationStatusLabels[query.data.value.taskStatus] ?? '待确认' }} · 已读取
{{ query.items.value.length }} 条,当前共 {{ query.data.value.total }} 条
</p>
<NButton
size="small"
:loading="query.loading.value && !query.loadingMore.value"
@click="query.refresh"
>刷新记录</NButton
>
</div>
<p v-if="query.error.value" class="text-sm text-muted" role="status">{{ query.error.value }}</p>
<p v-if="query.loading.value && !query.loadingMore.value" role="status" class="text-sm text-muted">
正在读取执行记录…
</p>
<template v-if="query.data.value">
<p v-if="query.data.value.integrity.currentExecution === 'unavailable'" class="text-sm text-muted">
当前执行关联需要核查,以下仅展示已保存的执行记录。
</p>
<p
v-else-if="query.data.value.integrity.currentExecution === 'not_recorded'"
class="text-sm text-muted"
>
原审核未记录当前执行关联。
</p>
<p v-else class="wrap-anywhere text-xs text-muted">
当前执行:{{ query.data.value.currentExecutionId
}}<span v-if="!query.items.value.some(item => item.isCurrent)">(尚未在已加载记录中)</span>
</p>
<p v-if="!query.items.value.length" class="text-sm text-muted">此审核任务暂无已保存的执行记录。</p>
</template>
<!-- 以下是逐次执行状态、质量与独立步骤证据,不以旧失败覆盖当前任务 -->
<article v-for="item in query.items.value" :key="item.execution.id" class="space-y-2 pt-2">
<p class="font-semibold text-sm">
{{ item.isCurrent ? '当前执行' : '历史执行' }} · {{ modeLabels[item.mode] }}
</p>
<KeyframeExecutionStatus
:execution="displayExecution(item)"
:title="item.isCurrent ? '当前执行状态' : '历史执行状态'"
:loading="false"
:refreshable="false"
/>
<p class="text-xs text-muted">
本次新提交步骤:{{ stepScope(item.scheduledSteps) }};复用已有步骤:{{
stepScope(item.reusedSteps)
}}
</p>
<p class="text-xs text-muted">{{ evidenceLabels[item.stepsEvidence] }}</p>
<KeyframeValidationSteps v-if="item.steps" :steps="item.steps" />
<!-- 以下是该执行自己的公开起止时间,不读取其他任务结果补齐 -->
<NCollapse
><NCollapseItem name="execution-details" title="执行详情"
><dl class="space-y-1 text-xs text-muted">
<div>创建:{{ formatDate(item.execution.createdAt) }}</div>
<div>
开始:{{
item.execution.startedAt ? formatDate(item.execution.startedAt) : '未记录'
}}
</div>
<div>
结束:{{
item.execution.completedAt ? formatDate(item.execution.completedAt) : '未记录'
}}
</div>
</dl></NCollapseItem
></NCollapse
>
</article>
<NButton
v-if="query.nextCursor.value"
:loading="query.loadingMore.value"
:disabled="query.loading.value && !query.loadingMore.value"
@click="query.loadMore"
>加载更多</NButton
>
</section>
</NCollapseItem>
</NCollapse>
</template>
@@ -8,10 +8,15 @@ import { userFacingText } from '../../../lib/user-facing-text'
import { formatDate } from '../../../lib/format'
/** 单次视觉审核执行状态,完成和质量通过分别表达。 */
const props = defineProps<{
/** 正式执行记录。 */ execution: WorkflowExecution
/** 只读刷新状态。 */ loading: boolean
}>()
const props = withDefaults(
defineProps<{
/** 正式执行记录。 */ execution: WorkflowExecution
/** 只读刷新状态。 */ loading: boolean
/** 历史记录与当前观察使用不同标题。 */ title?: string
/** 历史列表统一刷新,不对每行重复放置按钮。 */ refreshable?: boolean
}>(),
{ title: '当前审核执行', refreshable: true }
)
/** 仅触发只读刷新。 */
const emit = defineEmits<{ refresh: [] }>()
/** 只有明确质量通过且未标记恢复才使用成功语义。 */
@@ -26,26 +31,40 @@ const passed = computed(
const label = computed(() => {
if (passed.value) return '审核质量通过'
if (props.execution.status === 'failed') return '执行失败,质量未确认'
if (props.execution.status === 'completed')
return props.execution.result?.passed === false ? '执行完成,质量未通过' : '执行完成,质量待核对'
return props.execution.status === 'pending' ? '等待审核' : '审核进行中'
if (props.execution.status === 'completed') {
const quality = props.execution.result?.qualityDecision
const labels: Record<string, string> = {
failed: '质量未通过',
needs_review: '质量待复核',
stale: '审核来源已失效',
blocked: '质量受阻',
insufficient_evidence: '证据不足'
}
return `执行完成,${typeof quality === 'string' && labels[quality] ? labels[quality] : props.execution.result?.passed === false ? '质量未通过' : '质量待核对'}`
}
return props.execution.status === 'pending'
? '等待审核'
: props.execution.status === 'running'
? '审核进行中'
: '状态待确认'
})
</script>
<template>
<!-- 以下是正式执行与实际质量结论模块,不用满格绿色进度暗示通过 -->
<section class="mt-4 space-y-2 text-sm" role="status" :class="passed ? 'bg-(--app-success-soft) p-3' : ''">
<WorkspaceSectionHeading title="当前审核执行"
<WorkspaceSectionHeading :title="title"
><template #actions
><NButton :loading="loading" @click="emit('refresh')">刷新进度</NButton></template
><NButton v-if="refreshable" :loading="loading" @click="emit('refresh')">刷新进度</NButton></template
></WorkspaceSectionHeading
>
<p>{{ label }} · {{ executionStageLabel(execution.stage) }}</p>
<p v-if="execution.total > 0">已处理步骤:{{ execution.current }} / {{ execution.total }}</p>
<p v-if="execution.total > 0">审核计划进度:{{ execution.current }} / {{ execution.total }}</p>
<p v-else>尚无可确认的步骤进度。</p>
<p class="wrap-anywhere text-xs text-muted">
执行编号:{{ execution.id }} · {{ formatDate(execution.updatedAt) }}
</p>
<p v-if="typeof execution.result?.summary === 'string'">{{ userFacingText(execution.result.summary) }}</p>
<p v-if="execution.error">{{ userFacingText(execution.error) }}</p>
</section>
</template>
@@ -5,13 +5,15 @@ import FeedbackMessage from '../../../components/ui/FeedbackMessage.vue'
import ContextNotice from '../../../components/ui/ContextNotice.vue'
import { computed, ref, watch } from 'vue'
import { NButton, NCollapse, NCollapseItem, NInput } from 'naive-ui'
import { NButton, NInput } from 'naive-ui'
import { errorMessage } from '../../../lib/http'
import ReadonlyInspection from '../../../components/ui/ReadonlyInspection.vue'
import { useQuery } from '../../../composables/useQuery'
import { formatDate } from '../../../lib/format'
import { physicalRetryTarget, submitKeyframeVision, useKeyframeVision } from '../keyframe-vision'
import KeyframeExecutionStatus from './KeyframeExecutionStatus.vue'
import KeyframeExecutionHistory from './KeyframeExecutionHistory.vue'
import KeyframeValidationSteps from './KeyframeValidationSteps.vue'
import { validationStatusLabels as stepLabels } from '../validation-execution-labels'
import { useActionMessage, showActionFeedback } from '../../../components/ui/useActionMessage'
import { qualityApi } from '../quality-api'
import { parseKeyframeValidationOutput, keyframeValidationPassed } from '../quality'
@@ -54,7 +56,6 @@ const {
execution,
state,
uncertain,
observedExecutions,
submissionMode
} = props.observation ?? useKeyframeVision(visionKey)
/** 后台结束时同步刷新人工复核与候选状态。 */
@@ -67,19 +68,6 @@ watch(
}
}
)
/** 公开步骤状态的中文名称。 */
const stepLabels: Record<string, string> = {
pending: '等待',
running: '执行中',
received: '已收到回执',
completed: '完成',
failed: '失败',
needs_review: '需要人工核查'
}
/** 不显示内部模型名称作为审核步骤。 */
const stepNames = { general: '通用画面', physical: '物理关系', gaze: '视线' }
/** 仅显示公开词元计量。 */
const usageLabels = { inputTokens: '输入', outputTokens: '输出', totalTokens: '合计', reasoningTokens: '推理' }
/** 复核证据仅在展开历史时读取,不触发 Vision 或写入审核结论。 */
const reviewQuery = useQuery(key, (value, signal) => {
if (!value) return Promise.resolve(null)
@@ -296,7 +284,7 @@ const records = computed(() =>
:collapsible="!initialOpen"
:show-header="!initialOpen"
title="首帧校验历史"
:loading="query.loading.value"
:loading="query.loading.value && !query.data.value"
:error="query.error.value"
@refresh="
() => {
@@ -395,26 +383,9 @@ const records = computed(() =>
<section v-if="submissionMode === 'physical'" class="mt-3 space-y-2 text-sm" role="status">
<h3 class="font-semibold">仅补跑物理专项</h3>
<p>原通用检查已通过,原费用已记录;本次仅补跑一个物理步骤,不重复提交通用检查。</p>
<p>当前审核状态以以下正式执行及最新质量结论为准。</p>
<p>当前状态以审核结果及执行记录为准。</p>
</section>
<KeyframeExecutionStatus
v-if="execution.data.value"
:execution="execution.data.value"
:loading="execution.loading.value"
@refresh="execution.refresh"
/>
<p v-if="execution.error.value" class="mt-3 text-sm text-muted">{{ execution.error.value }}</p>
<NCollapse v-if="observedExecutions.length" class="mt-3">
<NCollapseItem name="executions" title="历史执行记录">
<p class="text-xs text-muted">
显示本机已观察到的执行;刷新会读取服务保存的最新执行。较早且未观察到的执行暂不可查询。
</p>
<p v-for="item in observedExecutions" :key="item.executionId" class="mt-2 wrap-anywhere text-xs">
审核任务:{{ item.taskId }} · 执行:{{ item.executionId
}}{{ item.status ? ` · 观察时状态:${stepLabels[item.status] ?? '待确认'}` : '' }}
</p>
</NCollapseItem>
</NCollapse>
<!-- 以下是当前审核任务和费用核查状态 -->
<p
v-if="state.unknown || uncertain || (state.active && !state.active.executionId)"
@@ -441,10 +412,7 @@ const records = computed(() =>
: '暂无结论'
}}
</p>
<p class="mt-2 wrap-anywhere text-xs text-muted">
审核任务:{{ record.id
}}<template v-if="record.executionId"> · 最新执行:{{ record.executionId }}</template>
</p>
<p class="mt-2 wrap-anywhere text-xs text-muted">审核任务:{{ record.id }}</p>
<section v-if="record.legacyTermination" class="mt-2 space-y-1 text-sm">
<p>历史审核已人工终止,原任务状态:{{ stepLabels[record.status] ?? '待确认' }};未标记通过。</p>
<p>人工终止时间:{{ formatDate(record.legacyTermination.terminatedAt) }}</p>
@@ -483,39 +451,16 @@ const records = computed(() =>
{{ userFacingText(issue.description) }}
</p>
</template>
<!-- 以下是公开步骤进度和计量,不展示模型回执 -->
<NCollapse v-if="record.steps?.length" class="mt-2">
<NCollapseItem
v-for="step in record.steps"
:key="step.name"
:name="step.name"
:title="`${stepNames[step.name]} · ${stepLabels[step.status]}`"
>
<NCollapse>
<NCollapseItem name="diagnostics" title="高级详情">
<dl class="grid gap-1 wrap-anywhere text-xs text-muted">
<div v-if="step.startedAt">开始:{{ formatDate(step.startedAt) }}</div>
<div v-if="step.finishedAt">完成:{{ formatDate(step.finishedAt) }}</div>
<div v-if="step.requestId">请求编号:{{ step.requestId }}</div>
<div v-if="step.providerRequestId">模型服务请求编号:{{ step.providerRequestId }}</div>
<div v-for="(count, unit) in step.usage" :key="unit">
{{ usageLabels[unit] }}词元:{{ count }}
</div>
</dl>
</NCollapseItem>
</NCollapse>
<ul v-if="step.issues?.length" class="mt-2 space-y-1 text-xs">
<li v-for="(issue, index) in step.issues" :key="index" class="text-danger">
{{ issue.subjectRef ? issue.subjectRef + ' · ' : ''
}}{{ userFacingText(issue.description) }}
</li>
</ul>
<p v-else class="mt-2 text-xs text-muted">
{{ step.issues ? '未发现问题。' : '暂无问题记录。' }}
</p>
<p v-if="step.error" class="mt-2 text-danger">{{ userFacingText(step.error) }}</p>
</NCollapseItem>
</NCollapse>
<!-- 以下是原任务的最新步骤摘要和按任务读取的正式执行历史 -->
<KeyframeValidationSteps v-if="record.steps?.length" :steps="record.steps" />
<KeyframeExecutionHistory
:project-id="projectId"
:shot-id="shotId"
:keyframe-id="keyframeId"
:validation-task-id="record.id"
:latest-execution-id="record.executionId"
:live-execution="execution.data.value"
/>
</article>
</ReadonlyInspection>
</template>
@@ -0,0 +1,91 @@
<script setup lang="ts">
import { NCollapse, NCollapseItem } from 'naive-ui'
import { formatDate } from '../../../lib/format'
import { userFacingText } from '../../../lib/user-facing-text'
import type { KeyframeValidationStep } from '../quality.types'
import type { ValidationExecutionStep } from '../validation-executions.types'
import {
validationQualityLabels,
validationStatusLabels,
validationStepNames,
validationUsageLabels
} from '../validation-execution-labels'
/** 原任务摘要与逐次执行共用公开步骤展示,复用用量不重复归入本次。 */
defineProps<{
/** 原有摘要没有逐次归属时,不从缺省值推断新调用。 */ steps: readonly (
| KeyframeValidationStep
| ValidationExecutionStep
)[]
}>()
/**
* 将执行状态与质量结论分开标示,保留复用语义。
* @param step 本条公开步骤
* @returns 可读标题
*/
function stepTitle(step: KeyframeValidationStep | ValidationExecutionStep) {
return (
`${validationStepNames[step.name]} · ${validationStatusLabels[step.status] ?? '状态待确认'}` +
('quality' in step
? ` · ${validationQualityLabels[step.quality]}${step.executionKind === 'reused' ? '(复用)' : ''}`
: '')
)
}
</script>
<template>
<!-- 以下是各步骤自己的结论、问题与计量模块 -->
<NCollapse v-if="steps.length" class="mt-3">
<NCollapseItem v-for="step in steps" :key="step.name" :name="step.name" :title="stepTitle(step)">
<template v-if="'executionKind' in step">
<p>
{{
step.executionKind === 'executed'
? '本次执行步骤'
: step.executionKind === 'reused'
? '复用已有步骤,不重复提交'
: '执行方式未记录'
}}
</p>
<p v-if="step.usageAttribution === 'reused'" class="text-muted">以下为原调用计量,不重复计入本次。</p>
<p v-else-if="step.usageAttribution === 'unknown'" class="text-muted">
计量归属未记录,不能推算本次费用。
</p>
</template>
<ul v-if="step.issues?.length" class="mt-2 space-y-1 text-xs">
<li v-for="(issue, index) in step.issues" :key="index">
{{ issue.subjectRef ? issue.subjectRef + ' · ' : '' }}{{ userFacingText(issue.description) }}
</li>
</ul>
<p v-else class="mt-2 text-xs text-muted">{{ step.issues ? '未记录问题。' : '未记录问题证据。' }}</p>
<p v-if="step.error" class="mt-2 text-sm">{{ userFacingText(step.error) }}</p>
<!-- 以下是必要的原始请求、时间和计量,默认收起 -->
<NCollapse class="mt-2"
><NCollapseItem name="diagnostics" title="高级详情">
<dl class="space-y-1 wrap-anywhere text-xs text-muted">
<div v-if="step.startedAt">开始:{{ formatDate(step.startedAt) }}</div>
<div v-if="step.finishedAt">完成:{{ formatDate(step.finishedAt) }}</div>
<div v-if="step.requestId">请求编号:{{ step.requestId }}</div>
<div v-if="step.providerRequestId">模型服务请求编号:{{ step.providerRequestId }}</div>
<div v-if="'sourceExecutionId' in step && step.sourceExecutionId">
复用来源执行:{{ step.sourceExecutionId }}
</div>
<div v-if="'usageAttribution' in step">
计量归属:{{
step.usageAttribution === 'this_execution'
? '本次新调用'
: step.usageAttribution === 'reused'
? '原调用复用'
: '未记录'
}}
</div>
<div v-for="(count, unit) in step.usage" :key="unit">
{{ validationUsageLabels[unit] }}词元:{{ count }}
</div>
<div v-if="!step.usage || !Object.keys(step.usage).length">未记录计量。</div>
</dl>
</NCollapseItem></NCollapse
>
</NCollapseItem>
</NCollapse>
</template>
+1 -37
View File
@@ -3,7 +3,6 @@ import { useQuery } from '../../composables/useQuery'
import { ApiError } from '../../lib/http'
import type { WorkflowExecution } from '../workflows/execution.types'
import { workflowExecutionApi } from '../workflows/execution-api'
import { rememberVisionExecutions, type ObservedVisionExecution } from './vision-execution-history'
import { qualityApi } from './quality-api'
import { isVisualValidation } from './quality'
import type { KeyframeValidationHistoryItem, ResumeKeyframeValidation, KeyframeVisionInput } from './quality.types'
@@ -225,11 +224,6 @@ export function useKeyframeVision(key: Ref<string>, observeExecution = true) {
)
watch(history.data, records => {
if (records && key.value)
rememberVisionExecutions(
key.value,
records.flatMap(item => (item.executionId ? [{ taskId: item.id, executionId: item.executionId }] : []))
)
const saved = submission.value
if (!records || !saved || saved.settled) return
const latest = records[0]
@@ -262,30 +256,6 @@ export function useKeyframeVision(key: Ref<string>, observeExecution = true) {
}
}, 2500)
onScopeDispose(() => clearInterval(timer))
/** 公开最新任务与本机已知的多次执行,读取不提交审核。 */
const observedExecutions = ref<ObservedVisionExecution[]>([])
watch(
[history.data, execution.data, key],
([records, current, target]) => {
observedExecutions.value = target
? rememberVisionExecutions(
target,
(records ?? []).flatMap(item =>
item.executionId
? [
{
taskId: item.id,
executionId: item.executionId,
...(current?.id === item.executionId ? { status: current.status } : {})
}
]
: []
)
)
: []
},
{ immediate: true }
)
/** 本机已提交且仍对应当前正式任务的授权范围。 */
const submissionMode = computed(() => {
const saved = submission.value
@@ -296,7 +266,7 @@ export function useKeyframeVision(key: Ref<string>, observeExecution = true) {
? saved.mode
: undefined
})
return { history, state, execution, uncertain, blocked, resume, observedExecutions, submissionMode }
return { history, state, execution, uncertain, blocked, resume, submissionMode }
}
/**
@@ -364,12 +334,6 @@ export async function submitKeyframeVision(
if (result.shotId !== shotId || result.keyframeId !== assetId || !result.validationTaskId)
throw new Error('审核回执与当前候选不一致,请刷新审核记录。')
if ('executionId' in result && result.status === 'pending' && result.executionId) {
rememberVisionExecutions(key, [
...records.flatMap(item =>
item.executionId ? [{ taskId: item.id, executionId: item.executionId }] : []
),
{ taskId: result.validationTaskId, executionId: result.executionId, status: 'pending' }
])
saveSubmission(key, { ...pending, taskId: result.validationTaskId, executionId: result.executionId })
return null
}
+24
View File
@@ -1,3 +1,4 @@
import type { ValidationExecutionHistory, ValidationExecutionQuery } from './validation-executions.types'
import { keyframeScope } from './keyframe-scope'
import { request } from '../../lib/http'
import type {
@@ -58,6 +59,29 @@ export const qualityApi = {
`/storyboard-shots/${encodeURIComponent(shotId)}/keyframe-provider-capability${provider ? `?provider=${encodeURIComponent(provider)}` : ''}`,
{ signal }
),
/**
* 按原审核任务读取正式执行历史,游标原样传递,不调用模型。
* @param shotId 正式镜头
* @param keyframeId 当前候选
* @param validationTaskId 原审核任务
* @param query 当前项目、分页大小与原始游标
* @param signal 取消旧范围读取
* @returns 本页执行及当前指针完整性
*/
keyframeExecutions: (
shotId: string,
keyframeId: string,
validationTaskId: string,
query: ValidationExecutionQuery = {},
signal?: AbortSignal
) => {
const params = new URLSearchParams()
if (query.projectId !== undefined) params.set('projectId', query.projectId)
if (query.limit !== undefined) params.set('limit', String(query.limit))
if (query.cursor !== undefined) params.set('cursor', query.cursor)
const path = `/storyboard-shots/${encodeURIComponent(shotId)}/keyframes/${encodeURIComponent(keyframeId)}/validations/${encodeURIComponent(validationTaskId)}/executions`
return request<ValidationExecutionHistory>(path + (params.size ? '?' + params : ''), { signal })
},
/**
* 显式请求一次审核,互斥提交新文字、原任务继续或独立授权。
* @param shotId 正式镜头编号
@@ -0,0 +1,166 @@
import { computed, onScopeDispose, ref, watch, type Ref } from 'vue'
import { ApiError, errorMessage } from '../../lib/http'
import { useFeedbackMessage } from '../../composables/useFeedbackMessage'
import { qualityApi } from './quality-api'
import type { ValidationExecutionHistory, ValidationExecutionHistoryItem } from './validation-executions.types'
/**
* 验证本页完整归属及当前指针,不能把排序第一条当成当前执行。
* @param page 正式接口的本页数据
* @param target 固定的项目、镜头、候选、审核任务
* @param cursor 本次请求的原始游标
*/
function assertPage(
page: ValidationExecutionHistory,
target: [string | undefined, string, string, string],
cursor?: string
) {
const [projectId, shotId, keyframeId, taskId] = target
if (
!page ||
!page.projectId ||
(projectId && page.projectId !== projectId) ||
page.shotId !== shotId ||
page.keyframeId !== keyframeId ||
page.validationTaskId !== taskId ||
!Number.isSafeInteger(page.total) ||
page.total < 0 ||
!Array.isArray(page.items) ||
page.items.length > 20 ||
!['valid', 'not_recorded', 'unavailable'].includes(page.integrity?.currentExecution) ||
(page.integrity.currentExecution === 'valid' ? !page.currentExecutionId : page.currentExecutionId !== null) ||
!(
page.nextCursor === null ||
(typeof page.nextCursor === 'string' && page.nextCursor.length > 0 && page.nextCursor !== cursor)
) ||
new Set(page.items.map(item => item.execution?.id)).size !== page.items.length ||
page.items.some(
item =>
!item.execution?.id ||
item.execution.projectId !== page.projectId ||
item.execution.workflowName !== 'shot-keyframe-validation' ||
item.execution.metadata?.validationTaskId !== taskId ||
item.execution.metadata?.shotId !== shotId ||
item.execution.metadata?.keyframeId !== keyframeId ||
item.isCurrent !== (item.execution.id === page.currentExecutionId)
)
) {
throw new Error('执行记录与当前审核范围不匹配,请刷新核对。')
}
}
/**
* 按任务按需读取正式分页,不读取或写入任何本机执行历史缓存。
* @param key 展开时的项目、镜头、候选、任务 JSON,收起时为空
* @returns 当前页信息、已加载记录及只读刷新入口
*/
export function useValidationExecutions(key: Ref<string>) {
/** 最新一页的正式任务状态、指针和游标。 */
const data = ref<ValidationExecutionHistory | null>(null)
/** 本次展开已加载的执行,刷新首屏时重新建立。 */
const records = ref<ValidationExecutionHistoryItem[]>([])
/** 当前请求状态,防止连续点击重复翻页。 */
const loading = ref(false)
/** 区分首屏与后续页,保留已加载内容的滚动位置。 */
const loadingMore = ref(false)
/** 只显示当前范围的可读错误。 */
const error = ref('')
useFeedbackMessage(error)
/** 下一页仅由正式游标决定,不以实时 total 计算。 */
const nextCursor = computed(() => data.value?.nextCursor ?? null)
/** 每页可返回更新后的当前指针,同步已加载旧页的标记。 */
const items = computed(() =>
records.value.map(item => ({ ...item, isCurrent: item.execution.id === data.value?.currentExecutionId }))
)
/** 请求代次覆盖取消失效的底层实现。 */
let generation = 0
/** 当前分页请求,切换或关闭时中止。 */
let controller: AbortController | undefined
/** 卸载后不更新状态或展示迟到错误。 */
let disposed = false
/** 取消旧页并清空旧范围,保留提交保护由原观察器负责。 */
function clear() {
generation++
controller?.abort()
data.value = null
records.value = []
error.value = ''
loading.value = false
loadingMore.value = false
}
/**
* 固定当前资源和游标读取一页,错误不启动审核或探测其他项目。
* @param cursor 正式下一页游标,省略时读取首屏
* @returns 本页读取结束
*/
async function read(cursor?: string) {
if (disposed || !key.value) return
const identity = key.value
const current = ++generation
controller?.abort()
controller = new AbortController()
const signal = controller.signal
loading.value = true
loadingMore.value = cursor !== undefined
error.value = ''
try {
const target = JSON.parse(identity) as [string | undefined, string, string, string]
const [projectId, shotId, keyframeId, taskId] = target
const page = await qualityApi.keyframeExecutions(
shotId,
keyframeId,
taskId,
{ ...(projectId ? { projectId } : {}), limit: 20, ...(cursor ? { cursor } : {}) },
signal
)
if (disposed || signal.aborted || current !== generation || identity !== key.value) return
assertPage(page, target, cursor)
const merged = new Map((cursor ? records.value : []).map(item => [item.execution.id, item]))
for (const item of page.items) merged.set(item.execution.id, item)
records.value = [...merged.values()]
data.value = page
} catch (cause) {
if (disposed || signal.aborted || current !== generation || identity !== key.value) return
error.value = errorMessage(cause)
if (cause instanceof ApiError && cause.status === 400 && data.value)
data.value = { ...data.value, nextCursor: null }
else if (!(cause instanceof ApiError) || [404, 409].includes(cause.status)) {
data.value = null
records.value = []
}
} finally {
if (!disposed && current === generation) {
loading.value = false
loadingMore.value = false
}
}
}
/**
* 刷新首屏并废弃旧游标,使新执行进入新的分页序列。
* @returns 首屏查询完成
*/
async function refresh() {
clear()
await read()
}
/**
* 明确点击后原样读取下一页,同一时刻只允许一个请求。
* @returns 下一页查询完成
*/
async function loadMore() {
if (!loading.value && nextCursor.value) await read(nextCursor.value)
}
watch(
key,
() => {
void refresh()
},
{ immediate: true, flush: 'sync' }
)
onScopeDispose(() => {
disposed = true
clear()
})
return { data, items, loading, loadingMore, error, nextCursor, refresh, loadMore }
}
@@ -0,0 +1,25 @@
/** 审核步骤共用中文名称,内部枚举不变。 */
export const validationStepNames = { general: '通用画面', physical: '物理关系', gaze: '视线' }
/** 执行和步骤的公开状态,仅完成不能推断质量通过。 */
export const validationStatusLabels: Record<string, string> = {
pending: '等待',
running: '执行中',
received: '已收到回执',
completed: '完成',
failed: '失败',
needs_review: '需要人工核查'
}
/** 已记录的质量结论。 */
export const validationQualityLabels = {
passed: '质量通过',
failed: '质量未通过',
needs_review: '质量待复核',
unknown: '质量未确认'
}
/** 原始计量单位,不显示缺失项或补零。 */
export const validationUsageLabels: Record<string, string> = {
inputTokens: '输入',
outputTokens: '输出',
totalTokens: '合计',
reasoningTokens: '推理'
}
@@ -0,0 +1,45 @@
import type { WorkflowExecution } from '../workflows/execution.types'
import type { KeyframeValidationStep, KeyframeStepIssue } from './quality.types'
/** 视觉审核的三个正式步骤名称。 */
export type ValidationStepName = KeyframeValidationStep['name']
/** 单次执行独立存证的公开步骤,不以完成状态推断通过。 */
export interface ValidationExecutionStep extends Omit<KeyframeValidationStep, 'issues' | 'error'> {
/** 已解析证据的真实质量结论。 */ quality: 'passed' | 'failed' | 'needs_review' | 'unknown'
/** 公开问题;没有解析结果时为空值。 */ issues: KeyframeStepIssue[] | null
/** 安全的失败原因。 */ error: string | null
/** 本次实际执行、复用或无法确认。 */ executionKind: 'executed' | 'reused' | 'unknown'
/** 有可靠证据时的复用来源执行。 */ sourceExecutionId: string | null
/** 用量归属,只有本次调用可计为新增计量。 */ usageAttribution: 'this_execution' | 'reused' | 'unknown'
}
/** 原审核任务的一次正式执行及其独立证据。 */
export interface ValidationExecutionHistoryItem {
/** 复用单执行接口的公开记录。 */ execution: WorkflowExecution
/** 依据原任务正式当前指针判断。 */ isCurrent: boolean
/** 已保存的本次执行模式。 */ mode: 'initial' | 'resume' | 'physical_retry' | 'unknown'
/** 本次需新提交的步骤,未记录时为 null。 */ scheduledSteps: ValidationStepName[] | null
/** 本次复用或解析已有回执的步骤,未记录时为 null。 */ reusedSteps: ValidationStepName[] | null
/** 本次自己的步骤,不使用任务当前 output 补齐。 */ steps: ValidationExecutionStep[] | null
/** 公开证据来源。 */ stepsEvidence: 'execution_snapshot' | 'archived_audit' | 'not_recorded'
}
/** 同一审核任务的正式分页结果。 */
export interface ValidationExecutionHistory {
/** 正式项目。 */ projectId: string
/** 正式镜头。 */ shotId: string
/** 镜头候选。 */ keyframeId: string
/** 原审核任务。 */ validationTaskId: string
/** 原任务状态,独立于执行和质量。 */ taskStatus: string
/** 经核对的当前执行,可以不在当前页。 */ currentExecutionId: string | null
/** 每次请求时的实时合法记录总数。 */ total: number
/** 当前页,按正式创建顺序倒序。 */ items: ValidationExecutionHistoryItem[]
/** 正式当前指针是否完整。 */ integrity: {
/** 有效、未保存或当前不可用。 */ currentExecution: 'valid' | 'not_recorded' | 'unavailable'
}
/** 原样传回的不透明游标,为 null 时停止。 */ nextCursor: string | null
}
/** 正式接口仅接受明确的项目、分页大小和原始游标。 */
export interface ValidationExecutionQuery {
/** 当前项目,历史调用允许省略。 */ projectId?: string
/** 一次读取的条数,默认 20。 */ limit?: number
/** 后端返回的下一页位置。 */ cursor?: string
}
@@ -1,45 +0,0 @@
/** 客户端曾实际观察到的执行,仅用于补充正式历史的最新执行编号。 */
export interface ObservedVisionExecution {
/** 原审核任务编号。 */ taskId: string
/** 已实际取得的执行编号。 */ executionId: string
/** 最近观察到的公开执行状态。 */ status?: string
}
/**
* 读取本机曾观察到的执行,不推断服务端未公开的历史。
* @param key 项目和候选范围
* @returns 已知执行记录
*/
export function readVisionExecutions(key: string): ObservedVisionExecution[] {
try {
const parsed: unknown = JSON.parse(localStorage.getItem('vision-executions:' + key) || '[]')
return Array.isArray(parsed)
? parsed.filter(item => item && typeof item.taskId === 'string' && typeof item.executionId === 'string')
: []
} catch {
return []
}
}
/**
* 合并真实编号,同一任务的新执行不会覆盖旧执行。
* @param key 项目和候选范围
* @param entries 正式响应或事件中取得的记录
* @returns 合并后的已知记录
*/
export function rememberVisionExecutions(key: string, entries: ObservedVisionExecution[]) {
const records = readVisionExecutions(key)
for (const item of entries) {
const existing = records.find(
record => record.executionId === item.executionId && record.taskId === item.taskId
)
if (existing) Object.assign(existing, item)
else records.push(item)
}
try {
localStorage.setItem('vision-executions:' + key, JSON.stringify(records))
} catch {
/* 存储不可用不影响正式查询。 */
}
return records
}
+4
View File
@@ -95,6 +95,10 @@ export function executionStageLabel(stage: string | null) {
submitting: '提交视频候选',
generating: '生成视频',
validating: '质量校验',
vision: '视觉审核',
general: '通用画面审核',
physical: '物理关系审核',
gaze: '视线审核',
repairing: '自动修复',
passed: '校验通过',
exhausted: '修复次数已用完',