feat(short-drama-agent-front): 补齐后端生产与质量功能

This commit is contained in:
GJ committed 2026-10-08 18:28:35 +08:00
1 parent 967c4ebea1
commit 470b52e26d
52 files changed
+3754 -1075

No files matched your search

+95 -25
View File
@@ -1,4 +1,6 @@
import { computed, onScopeDispose } from 'vue'
import { computed, onScopeDispose, watch } from 'vue'
import { useWorkflowExecution } from '../workflows/execution'
import { isQualityBatchResult } from './quality'
import { projectsApi } from '../projects/api'
import { hasRunningWorkflow } from '../workflows/selectors'
import { getOperation, runOperation } from '../workflows/operations'
@@ -26,22 +28,82 @@ function validAttempts(attempts: RepairAttempt[]) {
)
}
/** 统一质量操作:只读预检 → 显式付费请求 → 按原目标保存回执,不自动重试。 */
/**
* 只读预检后显式启动质量操作,按原目标保存回执与后台状态。
* @param props 当前项目、目标和阻断状态
* @param visible 弹窗是否仍可见
* @param changed 原项目资产刷新通知
* @param started 后台启动编号通知
* @returns 质量会话、任务状态与执行入口
*/
export function useQuality(
props: { projectId: string; target: QualityTarget | null; disabled: boolean },
visible: () => boolean,
changed: () => void
changed: () => void,
started: (executionId: string) => void = () => {}
) {
/** 原项目与目标共同隔离结果。 */
const key = computed(() => qualityKey(props.projectId, props.target))
/** 当前目标的会话回执。 */
const session = computed(() => qualitySession(key.value))
/** 当前项目的短操作锁。 */
const operation = computed(() => getOperation(props.projectId))
const blocked = computed(() => props.disabled || operation.value.pending || !props.target || !props.projectId)
/** 按项目恢复后台句柄,关闭弹窗仍继续观察。 */
const execution = useWorkflowExecution(
computed(() => props.projectId),
'keyframe-quality'
)
/** 已结束任务只写入其原始范围的回执。 */
const handled = new Set<string>()
/** 后台任务阻止重复启动。 */
const blocked = computed(
() => props.disabled || operation.value.pending || execution.active.value || !props.target || !props.projectId
)
/** 完成后由 metadata 恢复原目标;当前目标变化不改变任务归属。 */
watch(
() => execution.query.data.value,
record => {
if (
!record ||
record.projectId !== props.projectId ||
record.workflowName !== 'keyframe-quality' ||
!['completed', 'failed'].includes(record.status) ||
handled.has(record.id)
)
return
handled.add(record.id)
const metadata = record.metadata
const episodeNo = metadata?.episodeNo
if (typeof episodeNo !== 'number') return
const target: QualityTarget = {
kind: 'batch',
episodeNo,
title: '',
...(typeof metadata?.shotId === 'string' ? { shotId: metadata.shotId } : {})
}
const original = qualitySession(qualityKey(record.projectId, target))
if (record.status === 'failed') original.error = record.error || '首帧质量后台任务失败,请核对已完成资产。'
else if (
isQualityBatchResult(record.result) &&
record.result.results.every(item => !target.shotId || item.shotId === target.shotId) &&
(typeof metadata?.limit !== 'number' || record.result.targetCount <= metadata.limit)
)
original.receipt = { kind: 'batch', result: record.result }
else original.error = '后台最终回执不完整或范围不匹配,请核对资产,不要重复生成。'
changed()
}
)
let disposed = false
onScopeDispose(() => {
disposed = true
})
/** 确认之后重新读取后端状态;打开弹窗和查看结果不会调用此函数。 */
/**
* 确认之后重读状态并只提交一次,固定原目标与费用范围。
* @param action 已确认的质量操作
* @param input 已确认的参数
* @returns 操作结束通知,后台生成由持久化任务继续跟踪
*/
async function run(action: QualityAction, input: QualityInput) {
if (blocked.value || !visible() || !props.target || !validQualityInput(input)) return
const target = { ...props.target }
@@ -50,10 +112,20 @@ export function useQuality(
(target.kind === 'video' && action === 'repair' && input.maxRepairAttempts <= 0)
)
return
if (target.kind === 'batch' && input.episodeNo !== target.episodeNo) return
if (
target.kind === 'batch' &&
(input.episodeNo !== target.episodeNo ||
input.shotId !== target.shotId ||
(target.shotId && input.limit !== 1))
)
return
const projectId = props.projectId
// 固定本次确认的参数,预检期间的表单变化不能扩大已确认的生成范围。
input = { ...input, allowedTexts: input.allowedTexts?.slice() }
input = {
...input,
allowedTexts: input.allowedTexts?.slice(),
generationOptions: input.generationOptions ? { ...input.generationOptions } : undefined
}
const originalKey = key.value
const receiptTarget = qualitySession(originalKey)
receiptTarget.receipt = null
@@ -90,11 +162,13 @@ export function useQuality(
if (!targets.length)
throw new Error(
readiness.stalePrimaryKeyframe > 0
? '当前集没有可更新的过期首帧;后端优先处理全项目过期项,请切换剧集。'
? '当前范围没有可执行的首帧质量镜头,请刷新就绪状态。'
: '当前集没有符合条件的镜头;请补齐设计与参考图,或明确选择重做有效首帧。'
)
// 逐镜只读检查已选的小批量;任何模型能力不足都不启动本批付费流水线。
const capabilities = await Promise.all(targets.map(item => qualityApi.capability(item.shotId)))
const capabilities = await Promise.all(
targets.map(item => qualityApi.capability(item.shotId, undefined, input.provider))
)
const invalid = capabilities.find(item => item.valid !== true)
if (invalid) throw new Error(invalid.message || '当前图片模型不支持所需参考图。')
const assets = await Promise.all(targets.map(item => productionApi.listKeyframes(item.shotId)))
@@ -112,22 +186,18 @@ export function useQuality(
const result = await qualityApi.generate(projectId, input)
if (
!result ||
!Array.isArray(result.results) ||
![result.targetCount, result.passed, result.repairFailed, result.failed, result.selected].every(
value => Number.isSafeInteger(value) && value >= 0
) ||
result.targetCount > input.limit ||
result.results.length !== result.targetCount ||
result.passed + result.repairFailed + result.failed !== result.targetCount ||
result.results.some(
item =>
!readiness.items.some(
shot => shot.shotId === item.shotId && shot.episodeNo === input.episodeNo
) || typeof item.success !== 'boolean'
)
result.projectId !== projectId ||
typeof result.executionId !== 'string' ||
!result.executionId ||
result.status !== 'running' ||
!Number.isSafeInteger(result.total) ||
result.total < 0 ||
result.total > input.limit
)
throw new Error('质量流水线回执不完整,请先核对资产,不要重复提交。')
receipt = { kind: 'batch', result }
throw new Error('后台启动回执不完整,请刷新状态,不要重复提交。')
await execution.track(result.executionId, projectId)
if (!disposed && props.projectId === projectId) started(result.executionId)
return
} else {
if (!readiness.items.some(item => item.shotId === target.shotId))
throw new Error('指定镜头不属于当前项目,未提交质量任务。')
@@ -245,5 +315,5 @@ export function useQuality(
// 已提交请求即使切换页面也归原会话;只刷新仍在查看的原项目。
if (!disposed && props.projectId === projectId) changed()
}
return { key, session, operation, blocked, run }
return { key, session, operation, execution, blocked, run }
}