feat: 接入持久化工作流执行状态
This commit is contained in:
1 parent
7d2900c705
commit
3caea26924
14 files changed
+532
-44
No files matched your search
@@ -32,6 +32,7 @@ import QualityDialog from './components/QualityDialog.vue'
|
||||
import DetailDisclosure from '../../components/ui/DetailDisclosure.vue'
|
||||
import CreativeProfileSettings from '../generation-config/components/CreativeProfileSettings.vue'
|
||||
import EpisodeAssemblyPanel from './components/EpisodeAssemblyPanel.vue'
|
||||
import WorkflowExecutionPanel from '../workflows/WorkflowExecutionPanel.vue'
|
||||
const qualityOpen = ref(false)
|
||||
|
||||
/** 镜头生产页将项目批处理与单镜头资产管理放在同一条可核验链路中。 */
|
||||
@@ -55,13 +56,17 @@ const {
|
||||
keyframeLimit,
|
||||
keyframeWidth,
|
||||
keyframeHeight,
|
||||
promptLimit,
|
||||
videoLimit,
|
||||
videoRepairAttempts,
|
||||
keyframeValid,
|
||||
promptValid,
|
||||
videoQualityValid,
|
||||
batchValid,
|
||||
blocked,
|
||||
run
|
||||
run,
|
||||
promptExecution,
|
||||
videoExecution
|
||||
} = useProduction()
|
||||
const route = inject(routeLocationKey, undefined)
|
||||
/** 从素材页返回时恢复到指定剧集与正式镜头,不按重复的 Shot 编号定位。 */
|
||||
@@ -84,6 +89,19 @@ const openRequestedKeyframe = computed(
|
||||
() => queryText(route?.query.action) === 'keyframe' && queryText(route?.query.shotId) === shot.value?.shotId
|
||||
)
|
||||
const staleVideos = computed(() => query.data.value?.videos.stalePrimaryVideo ?? 0)
|
||||
const episodePromptReadiness = computed(() => {
|
||||
const source = query.data.value?.prompts
|
||||
if (!source) return undefined
|
||||
const items = source.items.filter(item => item.episodeNo === episodeNo.value)
|
||||
return {
|
||||
...source,
|
||||
items,
|
||||
total: items.length,
|
||||
ready: items.filter(item => item.status === 'ready').length,
|
||||
skipped: items.filter(item => item.status === 'skipped').length,
|
||||
blocked: items.filter(item => item.status === 'blocked').length
|
||||
}
|
||||
})
|
||||
const stages = computed(() => {
|
||||
const data = query.data.value
|
||||
return [
|
||||
@@ -93,8 +111,8 @@ const stages = computed(() => {
|
||||
title: '视频提示词',
|
||||
description: '校验 GenerationSpec 与主体参考图后,由模型生成视频运动描述。',
|
||||
icon: MessageSquareText,
|
||||
data: data?.prompts,
|
||||
done: data?.prompts.skipped ?? 0,
|
||||
data: episodePromptReadiness.value,
|
||||
done: episodePromptReadiness.value?.skipped ?? 0,
|
||||
action: force.value ? '重生成全部提示词' : '补齐视频提示词'
|
||||
},
|
||||
{
|
||||
@@ -190,12 +208,14 @@ const keyframeModel = computed(() => ({
|
||||
keyframeWidth: keyframeWidth.value,
|
||||
keyframeHeight: keyframeHeight.value
|
||||
}))
|
||||
const promptModel = computed(() => ({ promptLimit: promptLimit.value }))
|
||||
const dimensionRules = sizeRules(() => ({ width: keyframeWidth.value, height: keyframeHeight.value }))
|
||||
const keyframeRules = {
|
||||
keyframeLimit: integerRule('本批上限', 1, true),
|
||||
keyframeWidth: dimensionRules.width,
|
||||
keyframeHeight: dimensionRules.height
|
||||
}
|
||||
const promptRules = { promptLimit: integerRule('本批镜头上限') }
|
||||
const videoModel = computed(() => ({ videoLimit: videoLimit.value, videoRepairAttempts: videoRepairAttempts.value }))
|
||||
const videoRules = { videoLimit: integerRule('本批镜头上限'), videoRepairAttempts: integerRule('每镜最多自动修复') }
|
||||
</script>
|
||||
@@ -340,6 +360,24 @@ const videoRules = { videoLimit: integerRule('本批镜头上限'), videoRepairA
|
||||
个主视频已过期。它们使用的主首帧或主体参考图已经变化;非覆盖模式批量生成时会只重建这些过期主视频。
|
||||
</NAlert>
|
||||
<ProductionReceipt v-if="session.receipt" :receipt="session.receipt" />
|
||||
<WorkflowExecutionPanel
|
||||
v-if="promptExecution.executionId.value"
|
||||
title="视频提示词后台任务"
|
||||
:execution="promptExecution.query.data.value"
|
||||
:loading="promptExecution.query.loading.value"
|
||||
:error="promptExecution.query.error.value"
|
||||
@refresh="promptExecution.query.refresh"
|
||||
@dismiss="promptExecution.dismiss"
|
||||
/>
|
||||
<WorkflowExecutionPanel
|
||||
v-if="videoExecution.executionId.value"
|
||||
title="视频质量后台任务"
|
||||
:execution="videoExecution.query.data.value"
|
||||
:loading="videoExecution.query.loading.value"
|
||||
:error="videoExecution.query.error.value"
|
||||
@refresh="videoExecution.query.refresh"
|
||||
@dismiss="videoExecution.dismiss"
|
||||
/>
|
||||
<div v-if="query.data.value" class="production-pipeline mt-5">
|
||||
<article
|
||||
v-for="stage in stages"
|
||||
@@ -430,6 +468,7 @@ const videoRules = { videoLimit: integerRule('本批镜头上限'), videoRepairA
|
||||
:disabled="
|
||||
blocked ||
|
||||
!batchValid ||
|
||||
(stage.key === 'prompts' && !promptValid) ||
|
||||
(stage.key === 'keyframes' && !keyframeValid) ||
|
||||
(stage.key === 'videos' && !videoQualityValid) ||
|
||||
!(stage.data?.ready ?? 0)
|
||||
@@ -442,11 +481,28 @@ const videoRules = { videoLimit: integerRule('本批镜头上限'), videoRepairA
|
||||
: `只为至多 ${videoLimit || '—'} 个就绪镜头启动严格质量流水线。任务创建后由后端自动校验,最多修复 ${videoRepairAttempts || '—'} 次,通过后才晋升主视频。`
|
||||
: stage.key === 'keyframes'
|
||||
? `处理缺失或过期主首帧。过期首帧成功后自动接替旧主图(覆盖模式也如此),其余已有主图只新增候选。本批上限:${keyframeLimit || '不限制'};尺寸:${keyframeWidth && keyframeHeight ? `${keyframeWidth} × ${keyframeHeight}` : '后端默认'}。`
|
||||
: '只处理通过视频提示词就绪检查的镜头;覆盖模式会重写已有提示词。'
|
||||
: `只处理第 ${episodeNo} 集中通过就绪检查的镜头,本批最多 ${promptLimit || '—'} 镜;覆盖模式会重写已有提示词。`
|
||||
"
|
||||
:primary="stage.key === 'videos'"
|
||||
@confirm="run(stage.key)"
|
||||
/>
|
||||
<AppForm
|
||||
v-if="stage.key === 'prompts'"
|
||||
:model="promptModel"
|
||||
:rules="promptRules"
|
||||
:disabled="operation.pending"
|
||||
validate-on-change
|
||||
class="mt-4 grid gap-3"
|
||||
>
|
||||
<NFormItem path="promptLimit" label="本批镜头上限"
|
||||
><NInputNumber
|
||||
v-model:value="promptLimit"
|
||||
:min="1"
|
||||
:precision="0"
|
||||
:disabled="operation.pending"
|
||||
:input-props="{ 'aria-label': '视频提示词本批镜头上限' }"
|
||||
/></NFormItem>
|
||||
</AppForm>
|
||||
<AppForm
|
||||
v-if="stage.key === 'keyframes'"
|
||||
:model="keyframeModel"
|
||||
|
||||
@@ -17,6 +17,7 @@ import type {
|
||||
RetryVideosResult,
|
||||
ShotKeyframe,
|
||||
ShotVideo,
|
||||
ShotVideoQualityStatus,
|
||||
ShotVideoQualityResult,
|
||||
VideoQualityBatchResult,
|
||||
VideoQualityConfig,
|
||||
@@ -25,6 +26,7 @@ import type {
|
||||
ProjectAssemblyReadiness,
|
||||
EpisodeAssemblyResult
|
||||
} from './types'
|
||||
import type { WorkflowExecutionStart } from '../workflows/execution.types'
|
||||
|
||||
/** 项目路径统一编码,避免业务组件手工拼接 ID。 */
|
||||
function projectPath(id: string) {
|
||||
@@ -78,6 +80,12 @@ export const productionApi = {
|
||||
body: input,
|
||||
timeoutMs: 0
|
||||
}),
|
||||
/** 后台生成视频提示词;刷新页面后可凭 executionId 继续观察。 */
|
||||
startPromptExecution: (projectId: string, input: StoryboardBatchInput) =>
|
||||
request<WorkflowExecutionStart>(`${projectPath(projectId)}/video-prompts/generate/start`, {
|
||||
method: 'POST',
|
||||
body: input
|
||||
}),
|
||||
keyframeReadiness: (projectId: string, force: boolean, signal?: AbortSignal) =>
|
||||
request<KeyframeReadiness>(`${projectPath(projectId)}/keyframes/readiness?force=${force}`, { signal }),
|
||||
generateKeyframes: (projectId: string, input: GenerateKeyframesInput) =>
|
||||
@@ -95,8 +103,17 @@ export const productionApi = {
|
||||
body: input,
|
||||
timeoutMs: 0
|
||||
}),
|
||||
/** 后台启动项目级视频质量任务;后续状态通过 WorkflowExecution 查询。 */
|
||||
startQualityVideoExecution: (projectId: string, input: GenerateQualityVideosInput) =>
|
||||
request<WorkflowExecutionStart>(`${projectPath(projectId)}/videos/generate-quality/start`, {
|
||||
method: 'POST',
|
||||
body: input
|
||||
}),
|
||||
projectVideoStatus: (projectId: string, signal?: AbortSignal) =>
|
||||
request<ProjectVideoStatus>(`${projectPath(projectId)}/videos/status`, { signal }),
|
||||
/** 读取单镜头已持久化的质量链状态,不触发新的视觉校验。 */
|
||||
videoQualityStatus: (shotId: string, signal?: AbortSignal) =>
|
||||
request<ShotVideoQualityStatus>(`${shotPath(shotId)}/videos/quality-status`, { signal }),
|
||||
retryVideos: (projectId: string, concurrency: number) =>
|
||||
request<RetryVideosResult>(`${projectPath(projectId)}/videos/retry-failed`, {
|
||||
method: 'POST',
|
||||
|
||||
@@ -13,7 +13,14 @@ import { storyboardApi } from '../../storyboard/api'
|
||||
import ConfirmAction from '../../workflows/ConfirmAction.vue'
|
||||
import { getOperation, runOperation } from '../../workflows/operations'
|
||||
import { productionApi } from '../api'
|
||||
import { isActiveVideo, issueLabel, primaryKeyframe, primaryVideo, productionStatusLabel } from '../model'
|
||||
import {
|
||||
isActiveVideo,
|
||||
issueLabel,
|
||||
primaryKeyframe,
|
||||
primaryVideo,
|
||||
productionStatusLabel,
|
||||
videoQualityStatusLabel
|
||||
} from '../model'
|
||||
import type {
|
||||
GenerateKeyframeInput,
|
||||
KeyframeReadinessItem,
|
||||
@@ -47,18 +54,24 @@ const key = computed(() => props.shot.shotId)
|
||||
const query = usePolling(
|
||||
key,
|
||||
async (shotId, signal) => {
|
||||
const [keyframes, videos] = await Promise.all([
|
||||
const [keyframes, videos, qualityState] = await Promise.all([
|
||||
productionApi.listKeyframes(shotId, signal),
|
||||
productionApi.listVideos(shotId, signal)
|
||||
productionApi.listVideos(shotId, signal),
|
||||
productionApi
|
||||
.videoQualityStatus(shotId, signal)
|
||||
.then(data => ({ data, error: '' }))
|
||||
.catch(cause => ({ data: null, error: errorMessage(cause) }))
|
||||
])
|
||||
if (keyframes.some(item => item.shotId !== shotId) || videos.some(item => item.shotId !== shotId))
|
||||
throw new Error('资产记录与当前镜头不匹配,请刷新后重试。')
|
||||
return { keyframes, videos }
|
||||
const qualityStatus = qualityState.data?.shotId === shotId ? qualityState.data : null
|
||||
return { keyframes, videos, qualityStatus, qualityStatusError: qualityState.error }
|
||||
},
|
||||
false
|
||||
)
|
||||
const keyframes = computed(() => query.data.value?.keyframes ?? [])
|
||||
const videos = computed(() => query.data.value?.videos ?? [])
|
||||
const videoQualityStatus = computed(() => query.data.value?.qualityStatus ?? null)
|
||||
const currentKeyframe = computed(() => primaryKeyframe(keyframes.value))
|
||||
const currentVideo = computed(() => primaryVideo(videos.value))
|
||||
const activeVideo = computed(() => videos.value.find(isActiveVideo))
|
||||
@@ -358,6 +371,9 @@ async function inspectSpecs() {
|
||||
>
|
||||
当前主首帧在本次质量检查中未通过,已阻止继续生成视频。请从候选中选择质量通过的图片。
|
||||
</NAlert>
|
||||
<NAlert v-if="query.data.value?.qualityStatusError" type="warning" :show-icon="false" class="mt-3 text-xs">
|
||||
视频质量链状态暂时无法读取;视频资产仍可查看。请稍后刷新。
|
||||
</NAlert>
|
||||
<div class="production-stage-actions">
|
||||
<NButton v-if="keyframeCandidates.length" @click="candidatesOpen = true">
|
||||
管理候选({{ keyframeCandidates.length }})
|
||||
@@ -389,6 +405,26 @@ async function inspectSpecs() {
|
||||
{{ issueLabel(issue.code) }}:{{ issue.reason }}
|
||||
</li>
|
||||
</ul>
|
||||
<NAlert
|
||||
v-if="videoQualityStatus && videoQualityStatus.status !== 'not_started'"
|
||||
:type="
|
||||
videoQualityStatus.status === 'passed'
|
||||
? 'success'
|
||||
: videoQualityStatus.status === 'exhausted'
|
||||
? 'error'
|
||||
: 'info'
|
||||
"
|
||||
:show-icon="false"
|
||||
class="mt-3 text-xs"
|
||||
>
|
||||
{{ videoQualityStatusLabel(videoQualityStatus.status) }}
|
||||
<template v-if="videoQualityStatus.maxRepairAttempts !== null">
|
||||
· 修复 {{ videoQualityStatus.repairAttempt }} / {{ videoQualityStatus.maxRepairAttempts }}
|
||||
</template>
|
||||
<template v-if="videoQualityStatus.status === 'exhausted'">
|
||||
。请检查候选视频和校验结果,调整提示词或参考资产后再重新生成。
|
||||
</template>
|
||||
</NAlert>
|
||||
<div v-if="videos.length" class="mt-4 space-y-3">
|
||||
<article v-for="item in videos" :key="item.id" class="video-record">
|
||||
<video
|
||||
@@ -464,7 +500,7 @@ async function inspectSpecs() {
|
||||
</div>
|
||||
<p v-else class="mt-4 text-xs text-muted">尚无视频任务记录。</p>
|
||||
<p v-if="videos.some(item => !item.isPrimary)" class="mt-3 text-xs text-muted">
|
||||
候选视频的历史质量结果未公开;手动设为主视频前需在本会话完成视觉校验。自动质量任务的晋升结果以刷新后的主视频标记为准。
|
||||
质量链状态来自后端持久化记录;手动晋升候选仍需在当前页面完成一次视觉校验。自动质量任务通过后会直接更新主视频。
|
||||
</p>
|
||||
<div class="production-stage-actions">
|
||||
<ConfirmAction
|
||||
|
||||
@@ -74,3 +74,16 @@ export function productionStatusLabel(status: string): string {
|
||||
}
|
||||
return labels[status] ?? status
|
||||
}
|
||||
|
||||
/** 视频质量链状态标签与后端状态机保持一致。 */
|
||||
export function videoQualityStatusLabel(status: string): string {
|
||||
const labels: Record<string, string> = {
|
||||
not_started: '尚未开始质量流程',
|
||||
generating: '正在生成候选视频',
|
||||
validating: '正在执行质量校验',
|
||||
repairing: '正在自动修复',
|
||||
passed: '质量校验通过',
|
||||
exhausted: '自动修复次数已用完'
|
||||
}
|
||||
return labels[status] ?? status
|
||||
}
|
||||
@@ -25,6 +25,7 @@ export interface ProductionIssue {
|
||||
/** 视频提示词就绪检查的逐镜结果。 */
|
||||
export interface PromptReadinessItem {
|
||||
shotId: string
|
||||
episodeNo: number
|
||||
shotNo: number
|
||||
status: Exclude<ProductionReadinessStatus, 'in_progress'>
|
||||
stalePrompt?: boolean
|
||||
@@ -328,6 +329,28 @@ export interface ProjectVideoStatus {
|
||||
items: ProjectVideoStatusItem[]
|
||||
}
|
||||
|
||||
/** 单镜头严格质量链的持久化状态;读取不会重新调用模型。 */
|
||||
export interface ShotVideoQualityStatus {
|
||||
shotId: string
|
||||
status: 'not_started' | 'generating' | 'validating' | 'repairing' | 'passed' | 'exhausted'
|
||||
primaryVideoId: string | null
|
||||
latestVideoId: string | null
|
||||
repairAttempt: number
|
||||
maxRepairAttempts: number | null
|
||||
validationPassed: boolean | null
|
||||
issues: unknown[]
|
||||
chain: {
|
||||
videoId: string
|
||||
providerStatus: ShotVideo['status']
|
||||
isPrimary: boolean
|
||||
repairAttempt: number
|
||||
maxRepairAttempts: number | null
|
||||
validationPassed: boolean | null
|
||||
createdAt: string
|
||||
updatedAt: string
|
||||
}[]
|
||||
}
|
||||
|
||||
/** 失败视频批量重试回执。 */
|
||||
export interface RetryVideosResult {
|
||||
totalFailed: number
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { computed, ref } from 'vue'
|
||||
import { useQuery } from '../../composables/useQuery'
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { usePolling } from '../../composables/usePolling'
|
||||
import { useProjectContext } from '../projects/context'
|
||||
import { mergeDesignedShots } from '../storyboard/model'
|
||||
import { storyboardApi } from '../storyboard/api'
|
||||
import { breakdownSnapshot } from '../workflows/selectors'
|
||||
import { getOperation, runOperation } from '../workflows/operations'
|
||||
import { useWorkflowExecution } from '../workflows/execution'
|
||||
import { productionApi } from './api'
|
||||
import { getProductionSession, validOptionalSize } from './model'
|
||||
|
||||
@@ -22,6 +23,7 @@ export function useProduction() {
|
||||
const keyframeLimit = ref<number | ''>('')
|
||||
const keyframeWidth = ref<number | ''>('')
|
||||
const keyframeHeight = ref<number | ''>('')
|
||||
const promptLimit = ref<number | null>(1)
|
||||
const videoLimit = ref<number | null>(1)
|
||||
const videoRepairAttempts = ref<number | null>(2)
|
||||
const snapshot = computed(() => breakdownSnapshot(context.checkpoints.value))
|
||||
@@ -45,20 +47,24 @@ export function useProduction() {
|
||||
)
|
||||
const queryKey = computed(() => JSON.stringify([id.value, episodeNo.value, force.value]))
|
||||
/** 生产页已有刷新按钮,就绪状态改为手动更新。 */
|
||||
const query = useQuery(queryKey, async (key, signal) => {
|
||||
const [projectId, number, overwrite] = JSON.parse(key) as [string, number, boolean]
|
||||
if (!projectId || !number) return null
|
||||
const [directions, prompts, keyframes, videos, videoStatus] = await Promise.all([
|
||||
storyboardApi.directions(projectId, number, signal),
|
||||
productionApi.promptReadiness(projectId, overwrite, signal),
|
||||
productionApi.keyframeReadiness(projectId, overwrite, signal),
|
||||
productionApi.videoReadiness(projectId, overwrite, signal),
|
||||
productionApi.projectVideoStatus(projectId, signal)
|
||||
])
|
||||
if (directions.projectId !== projectId || directions.episodeNo !== number)
|
||||
throw new Error('镜头生产查询返回了不匹配的项目或剧集,请刷新后重试。')
|
||||
return { directions, prompts, keyframes, videos, videoStatus }
|
||||
})
|
||||
const query = usePolling(
|
||||
queryKey,
|
||||
async (key, signal) => {
|
||||
const [projectId, number, overwrite] = JSON.parse(key) as [string, number, boolean]
|
||||
if (!projectId || !number) return null
|
||||
const [directions, prompts, keyframes, videos, videoStatus] = await Promise.all([
|
||||
storyboardApi.directions(projectId, number, signal),
|
||||
productionApi.promptReadiness(projectId, overwrite, signal),
|
||||
productionApi.keyframeReadiness(projectId, overwrite, signal),
|
||||
productionApi.videoReadiness(projectId, overwrite, signal),
|
||||
productionApi.projectVideoStatus(projectId, signal)
|
||||
])
|
||||
if (directions.projectId !== projectId || directions.episodeNo !== number)
|
||||
throw new Error('镜头生产查询返回了不匹配的项目或剧集,请刷新后重试。')
|
||||
return { directions, prompts, keyframes, videos, videoStatus }
|
||||
},
|
||||
false
|
||||
)
|
||||
const source = computed(() => sourceEpisodes.value.find(item => item.episodeNo === episodeNo.value))
|
||||
const shots = computed(() => mergeDesignedShots(query.data.value?.directions ?? null, null, source.value))
|
||||
const shot = computed(() => shots.value.find(item => item.shotId === selectedShot.value) ?? shots.value[0])
|
||||
@@ -72,7 +78,10 @@ export function useProduction() {
|
||||
)
|
||||
const operation = computed(() => getOperation(id.value))
|
||||
const session = computed(() => getProductionSession(id.value))
|
||||
const promptExecution = useWorkflowExecution(id, 'video-prompt')
|
||||
const videoExecution = useWorkflowExecution(id, 'video-quality')
|
||||
const batchValid = computed(() => Number.isSafeInteger(concurrency.value) && concurrency.value > 0)
|
||||
const promptValid = computed(() => Number.isSafeInteger(promptLimit.value) && (promptLimit.value ?? 0) > 0)
|
||||
const keyframeValid = computed(
|
||||
() =>
|
||||
(keyframeLimit.value === '' || (Number.isSafeInteger(keyframeLimit.value) && keyframeLimit.value > 0)) &&
|
||||
@@ -89,17 +98,34 @@ export function useProduction() {
|
||||
const blocked = computed(
|
||||
() =>
|
||||
operation.value.pending ||
|
||||
promptExecution.active.value ||
|
||||
videoExecution.active.value ||
|
||||
!!context.error.value ||
|
||||
!!query.error.value ||
|
||||
!query.data.value ||
|
||||
context.project.value?.status !== 'completed'
|
||||
)
|
||||
|
||||
/** 批量操作只向就绪镜头提交;最终资产状态由显式刷新确认。 */
|
||||
/** 后台质量任务收口后重新读取资产;失败也要保留已经成功的镜头状态。 */
|
||||
watch(
|
||||
() => videoExecution.query.data.value?.status,
|
||||
(status, previous) => {
|
||||
if ((status === 'completed' || status === 'failed') && status !== previous) void query.refresh()
|
||||
}
|
||||
)
|
||||
watch(
|
||||
() => promptExecution.query.data.value?.status,
|
||||
(status, previous) => {
|
||||
if ((status === 'completed' || status === 'failed') && status !== previous) void query.refresh()
|
||||
}
|
||||
)
|
||||
|
||||
/** 批量操作只向就绪镜头提交;最终资产状态由轮询查询确认。 */
|
||||
async function run(command: ProductionCommand) {
|
||||
if (
|
||||
blocked.value ||
|
||||
!batchValid.value ||
|
||||
(command === 'prompts' && !promptValid.value) ||
|
||||
(command === 'keyframes' && !keyframeValid.value) ||
|
||||
(command === 'videos' && !videoQualityValid.value)
|
||||
)
|
||||
@@ -126,11 +152,12 @@ export function useProduction() {
|
||||
}
|
||||
await runOperation(projectId, labels[command], async () => {
|
||||
if (command === 'prompts') {
|
||||
target.receipt = {
|
||||
kind: 'prompts',
|
||||
title: labels[command],
|
||||
result: await productionApi.generatePrompts(projectId, input)
|
||||
}
|
||||
const started = await productionApi.startPromptExecution(projectId, {
|
||||
...input,
|
||||
episodeNo: episodeNo.value,
|
||||
limit: promptLimit.value ?? undefined
|
||||
})
|
||||
await promptExecution.track(started.executionId)
|
||||
} else if (command === 'keyframes') {
|
||||
target.receipt = {
|
||||
kind: 'keyframes',
|
||||
@@ -146,15 +173,12 @@ export function useProduction() {
|
||||
})
|
||||
}
|
||||
} else if (command === 'videos') {
|
||||
target.receipt = {
|
||||
kind: 'videos',
|
||||
title: labels[command],
|
||||
result: await productionApi.generateQualityVideos(projectId, {
|
||||
...input,
|
||||
limit: videoLimit.value ?? undefined,
|
||||
maxRepairAttempts: videoRepairAttempts.value ?? 0
|
||||
})
|
||||
}
|
||||
const started = await productionApi.startQualityVideoExecution(projectId, {
|
||||
...input,
|
||||
limit: videoLimit.value ?? undefined,
|
||||
maxRepairAttempts: videoRepairAttempts.value ?? 0
|
||||
})
|
||||
await videoExecution.track(started.executionId)
|
||||
} else {
|
||||
target.receipt = {
|
||||
kind: 'retry',
|
||||
@@ -186,12 +210,16 @@ export function useProduction() {
|
||||
keyframeLimit,
|
||||
keyframeWidth,
|
||||
keyframeHeight,
|
||||
promptLimit,
|
||||
videoLimit,
|
||||
videoRepairAttempts,
|
||||
keyframeValid,
|
||||
promptValid,
|
||||
videoQualityValid,
|
||||
batchValid,
|
||||
blocked,
|
||||
run
|
||||
run,
|
||||
promptExecution,
|
||||
videoExecution
|
||||
}
|
||||
}
|
||||
@@ -95,6 +95,10 @@ export interface StoryboardBatchResult {
|
||||
export interface StoryboardBatchInput {
|
||||
concurrency: number
|
||||
force: boolean
|
||||
/** 可选试跑剧集范围。 */
|
||||
episodeNo?: number
|
||||
/** 可选本批实际处理上限。 */
|
||||
limit?: number
|
||||
}
|
||||
|
||||
/** 即时状态生成增加有限次的模型自动修复。 */
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { NAlert, NButton, NProgress, NTag } from 'naive-ui'
|
||||
import { RefreshCw, X } from '@lucide/vue'
|
||||
import { formatDate } from '../../lib/format'
|
||||
import { executionPercentage, executionStageLabel } from './execution'
|
||||
import type { WorkflowExecution } from './execution.types'
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{ title?: string; execution: WorkflowExecution | null; loading: boolean; error: string }>(),
|
||||
{ title: '后台任务' }
|
||||
)
|
||||
const emit = defineEmits<{ refresh: []; dismiss: [] }>()
|
||||
const percentage = computed(() => executionPercentage(props.execution?.current ?? 0, props.execution?.total ?? 0))
|
||||
const result = computed(() => props.execution?.result ?? {})
|
||||
const statusLabel = computed(() => {
|
||||
const labels = { pending: '等待开始', running: '执行中', completed: '已完成', failed: '失败' }
|
||||
return props.execution ? labels[props.execution.status] : ''
|
||||
})
|
||||
const statusType = computed(() =>
|
||||
props.execution?.status === 'completed' ? 'success' : props.execution?.status === 'failed' ? 'error' : 'warning'
|
||||
)
|
||||
const finished = computed(() => ['completed', 'failed'].includes(props.execution?.status ?? ''))
|
||||
const videoQuality = computed(() => props.execution?.workflowName === 'video-quality')
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section v-if="execution || error" class="panel mt-4 p-5" :aria-label="title">
|
||||
<div class="flex flex-wrap items-start justify-between gap-3">
|
||||
<div>
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<h3 class="text-sm font-semibold">{{ title }}</h3>
|
||||
<NTag v-if="execution" size="small" :type="statusType" :bordered="false">{{ statusLabel }}</NTag>
|
||||
</div>
|
||||
<p v-if="execution" class="mt-2 text-xs text-muted">
|
||||
{{ executionStageLabel(execution.stage) }} · 更新于 {{ formatDate(execution.updatedAt) }}
|
||||
</p>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<NButton
|
||||
class="icon-button"
|
||||
quaternary
|
||||
:loading="loading"
|
||||
aria-label="刷新后台任务状态"
|
||||
title="刷新后台任务状态"
|
||||
@click="emit('refresh')"
|
||||
><RefreshCw :size="15" /></NButton
|
||||
><NButton
|
||||
v-if="finished || error"
|
||||
class="icon-button"
|
||||
quaternary
|
||||
aria-label="隐藏后台任务记录"
|
||||
title="隐藏后台任务记录"
|
||||
@click="emit('dismiss')"
|
||||
><X :size="15" /></NButton
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<template v-if="execution">
|
||||
<NProgress
|
||||
v-if="execution.total > 0"
|
||||
type="line"
|
||||
:percentage="percentage"
|
||||
:height="5"
|
||||
:show-indicator="false"
|
||||
class="mt-4"
|
||||
/>
|
||||
<p class="mt-3 text-xs">
|
||||
<template v-if="execution.total > 0">已处理 {{ execution.current }} / {{ execution.total }}</template>
|
||||
<template v-else>后端正在确定本次任务范围</template>
|
||||
<template v-if="execution.currentResourceId">
|
||||
· 当前镜头 <code>{{ execution.currentResourceId }}</code></template
|
||||
>
|
||||
</p>
|
||||
<NAlert v-if="execution.status === 'running'" type="info" :show-icon="false" class="mt-3">
|
||||
{{
|
||||
videoQuality
|
||||
? '后端会继续生成、校验并按需修复。'
|
||||
: '后端会继续处理剩余镜头并保存已完成的提示词。'
|
||||
}}可以离开或刷新页面,返回后会继续显示本次任务进度,请勿重复提交。
|
||||
</NAlert>
|
||||
<NAlert v-else-if="execution.status === 'completed'" type="success" :show-icon="false" class="mt-3">
|
||||
<p>本轮任务已结束,页面正在重新读取镜头资产状态。</p>
|
||||
<p v-if="videoQuality" class="mt-2 text-xs">
|
||||
目标 {{ result.targetCount ?? execution.total }} · 通过 {{ result.passed ?? 0 }} · 修复耗尽
|
||||
{{ result.exhausted ?? 0 }} · 模型失败 {{ result.providerFailed ?? 0 }} · 提交失败
|
||||
{{ result.submissionFailed ?? 0 }}
|
||||
</p>
|
||||
<p v-else class="mt-2 text-xs">
|
||||
共 {{ result.total ?? execution.total }} · 生成 {{ result.generated ?? execution.current }} · 跳过
|
||||
{{ result.skipped ?? 0 }} · 阻塞 {{ result.blocked ?? 0 }} · 失败 {{ result.failed ?? 0 }}
|
||||
</p>
|
||||
</NAlert>
|
||||
<NAlert v-else-if="execution.status === 'failed'" type="error" :show-icon="false" class="mt-3">
|
||||
<p>{{ execution.error || '后台任务执行失败。' }}</p>
|
||||
<p class="mt-2 text-xs">
|
||||
请先刷新下方视频状态,确认已成功的镜头;处理报错原因后,只对仍处于“可执行”的镜头重新提交。
|
||||
</p>
|
||||
</NAlert>
|
||||
<p class="mt-3 break-all font-mono text-[10px] text-muted">执行 ID · {{ execution.id }}</p>
|
||||
</template>
|
||||
<NAlert v-if="error" type="error" :show-icon="false" class="mt-3">
|
||||
{{ error }}。任务可能仍在后端运行,请先点击刷新;不要直接重复提交。
|
||||
</NAlert>
|
||||
</section>
|
||||
</template>
|
||||
@@ -0,0 +1,8 @@
|
||||
import { request } from '../../lib/http'
|
||||
import type { WorkflowExecution } from './execution.types'
|
||||
|
||||
/** WorkflowExecution 查询接口;数据库状态是任务进度的权威来源。 */
|
||||
export const workflowExecutionApi = {
|
||||
get: (executionId: string, signal?: AbortSignal) =>
|
||||
request<WorkflowExecution>(`/workflow-executions/${encodeURIComponent(executionId)}`, { signal })
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
import { computed, ref, watch, type Ref } from 'vue'
|
||||
import { usePolling } from '../../composables/usePolling'
|
||||
import { workflowExecutionApi } from './execution-api'
|
||||
|
||||
const storagePrefix = 'short-drama:workflow-execution'
|
||||
|
||||
/** 任务阶段短标签;未知后端阶段保留原值,避免静默隐藏新能力。 */
|
||||
export function executionStageLabel(stage: string | null) {
|
||||
if (!stage) return '等待后端开始'
|
||||
const labels: Record<string, string> = {
|
||||
video_prompt: '生成视频提示词',
|
||||
submitting: '提交视频候选',
|
||||
generating: '生成视频',
|
||||
validating: '质量校验',
|
||||
repairing: '自动修复',
|
||||
passed: '校验通过',
|
||||
exhausted: '修复次数已用完',
|
||||
provider_failed: '模型生成失败',
|
||||
submission_failed: '任务提交失败',
|
||||
completed: '执行完成',
|
||||
failed: '执行失败'
|
||||
}
|
||||
return labels[stage] ?? stage
|
||||
}
|
||||
|
||||
/** 有总量时按真实计数展示进度;未知总量保持不确定进度。 */
|
||||
export function executionPercentage(current: number, total: number) {
|
||||
return total > 0 ? Math.min(100, Math.max(0, Math.round((current / total) * 100))) : 0
|
||||
}
|
||||
|
||||
function storageKey(projectId: string, workflowName: string) {
|
||||
return `${storagePrefix}:${projectId}:${workflowName}`
|
||||
}
|
||||
|
||||
function savedExecutionId(projectId: string, workflowName: string) {
|
||||
if (!projectId || typeof localStorage === 'undefined') return ''
|
||||
return localStorage.getItem(storageKey(projectId, workflowName)) ?? ''
|
||||
}
|
||||
|
||||
/** 跟踪一个项目最近的持久化任务;刷新页面后从本地句柄恢复,状态仍从后端读取。 */
|
||||
export function useWorkflowExecution(projectId: Ref<string>, workflowName: string) {
|
||||
const executionId = ref('')
|
||||
const terminal = ref(false)
|
||||
watch(
|
||||
projectId,
|
||||
value => {
|
||||
executionId.value = savedExecutionId(value, workflowName)
|
||||
terminal.value = false
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
const key = computed(() => executionId.value)
|
||||
const query = usePolling(
|
||||
key,
|
||||
(id, signal) => (id ? workflowExecutionApi.get(id, signal) : Promise.resolve(null)),
|
||||
computed(() => (executionId.value && !terminal.value ? 1_500 : false))
|
||||
)
|
||||
watch(
|
||||
() => query.data.value?.status,
|
||||
status => {
|
||||
terminal.value = status === 'completed' || status === 'failed'
|
||||
}
|
||||
)
|
||||
const active = computed(
|
||||
() =>
|
||||
!!executionId.value &&
|
||||
(!query.data.value || ['pending', 'running'].includes(query.data.value.status))
|
||||
)
|
||||
|
||||
/** 保存后端返回的真实 executionId,随后立即读取一次权威状态。 */
|
||||
async function track(id: string) {
|
||||
if (!id || !projectId.value) return
|
||||
if (typeof localStorage !== 'undefined') localStorage.setItem(storageKey(projectId.value, workflowName), id)
|
||||
terminal.value = false
|
||||
executionId.value = id
|
||||
await query.refresh()
|
||||
}
|
||||
|
||||
/** 只隐藏当前观察记录,不取消后端任务。 */
|
||||
function dismiss() {
|
||||
if (projectId.value && typeof localStorage !== 'undefined')
|
||||
localStorage.removeItem(storageKey(projectId.value, workflowName))
|
||||
executionId.value = ''
|
||||
terminal.value = false
|
||||
}
|
||||
|
||||
return { executionId, query, active, track, dismiss }
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/** 后端持久化长任务状态;字段以 WorkflowExecution 查询接口为准。 */
|
||||
export type WorkflowExecutionStatus = 'pending' | 'running' | 'completed' | 'failed'
|
||||
|
||||
/** 可持久化、可在刷新页面后继续观察的工作流执行记录。 */
|
||||
export interface WorkflowExecution {
|
||||
id: string
|
||||
projectId: string
|
||||
workflowName: string
|
||||
status: WorkflowExecutionStatus
|
||||
stage: string | null
|
||||
current: number
|
||||
total: number
|
||||
currentResourceId: string | null
|
||||
metadata: Record<string, unknown> | null
|
||||
result: Record<string, unknown> | null
|
||||
error: string | null
|
||||
startedAt: string | null
|
||||
completedAt: string | null
|
||||
createdAt: string
|
||||
updatedAt: string
|
||||
}
|
||||
|
||||
/** 后台任务启动接口只返回观察句柄,不把它误认为最终生产结果。 */
|
||||
export interface WorkflowExecutionStart {
|
||||
executionId: string
|
||||
status: 'pending' | 'running'
|
||||
total?: number
|
||||
}
|
||||
@@ -332,7 +332,13 @@ describe('首帧批量参数', () => {
|
||||
await service.run('keyframes')
|
||||
expect(posts()).toHaveLength(1)
|
||||
await service.run('prompts')
|
||||
expect(JSON.parse(String(posts()[1]?.[1]?.body))).toEqual({ concurrency: 2, force: false })
|
||||
expect(posts()[1]?.[0]).toBe('/api/projects/capability-test/video-prompts/generate/start')
|
||||
expect(JSON.parse(String(posts()[1]?.[1]?.body))).toEqual({
|
||||
concurrency: 2,
|
||||
force: false,
|
||||
episodeNo: 1,
|
||||
limit: 1
|
||||
})
|
||||
service.keyframeLimit.value = ''
|
||||
service.keyframeWidth.value = ''
|
||||
service.keyframeHeight.value = ''
|
||||
|
||||
@@ -128,14 +128,14 @@ describe('镜头生产数据契约', () => {
|
||||
})
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
await productionApi.videoReadiness('project/1', true)
|
||||
await productionApi.generateQualityVideos('project/1', {
|
||||
await productionApi.startQualityVideoExecution('project/1', {
|
||||
concurrency: 3,
|
||||
force: true,
|
||||
limit: 2,
|
||||
maxRepairAttempts: 2
|
||||
})
|
||||
expect(fetcher.mock.calls[0]?.[0]).toBe('/api/projects/project%2F1/videos/readiness?force=true')
|
||||
expect(fetcher.mock.calls[1]?.[0]).toBe('/api/projects/project%2F1/videos/generate-quality')
|
||||
expect(fetcher.mock.calls[1]?.[0]).toBe('/api/projects/project%2F1/videos/generate-quality/start')
|
||||
expect(JSON.parse(String(fetcher.mock.calls[1]?.[1]?.body))).toEqual({
|
||||
concurrency: 3,
|
||||
force: true,
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
import { flushPromises, mount } from '@vue/test-utils'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { effectScope, ref } from 'vue'
|
||||
import WorkflowExecutionPanel from '@/features/workflows/WorkflowExecutionPanel.vue'
|
||||
import { executionPercentage, executionStageLabel, useWorkflowExecution } from '@/features/workflows/execution'
|
||||
import type { WorkflowExecution } from '@/features/workflows/execution.types'
|
||||
|
||||
const execution = (overrides: Partial<WorkflowExecution> = {}): WorkflowExecution => ({
|
||||
id: 'execution-1',
|
||||
projectId: 'project-1',
|
||||
workflowName: 'video-quality',
|
||||
status: 'running',
|
||||
stage: 'validating',
|
||||
current: 1,
|
||||
total: 2,
|
||||
currentResourceId: 'shot-1',
|
||||
metadata: null,
|
||||
result: null,
|
||||
error: null,
|
||||
startedAt: '2026-09-23T00:00:00Z',
|
||||
completedAt: null,
|
||||
createdAt: '2026-09-23T00:00:00Z',
|
||||
updatedAt: '2026-09-23T00:01:00Z',
|
||||
...overrides
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
localStorage.clear()
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
describe('WorkflowExecution 前端契约', () => {
|
||||
it('保留未知阶段并限制真实进度范围', () => {
|
||||
expect(executionStageLabel('repairing')).toBe('自动修复')
|
||||
expect(executionStageLabel('new_backend_stage')).toBe('new_backend_stage')
|
||||
expect(executionPercentage(1, 2)).toBe(50)
|
||||
expect(executionPercentage(4, 2)).toBe(100)
|
||||
expect(executionPercentage(1, 0)).toBe(0)
|
||||
})
|
||||
|
||||
it('刷新页面后使用保存的 executionId 读取后端权威状态', async () => {
|
||||
localStorage.setItem('short-drama:workflow-execution:project-1:video-quality', 'execution-1')
|
||||
const fetcher = vi.fn<typeof fetch>().mockResolvedValue(
|
||||
new Response(JSON.stringify({ data: execution() }))
|
||||
)
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
const scope = effectScope()
|
||||
const tracker = scope.run(() => useWorkflowExecution(ref('project-1'), 'video-quality'))!
|
||||
await flushPromises()
|
||||
expect(fetcher.mock.calls[0]?.[0]).toBe('/api/workflow-executions/execution-1')
|
||||
expect(tracker.query.data.value?.stage).toBe('validating')
|
||||
tracker.dismiss()
|
||||
expect(localStorage.getItem('short-drama:workflow-execution:project-1:video-quality')).toBeNull()
|
||||
scope.stop()
|
||||
})
|
||||
|
||||
it('完成面板展示质量汇总和下一步状态', () => {
|
||||
const wrapper = mount(WorkflowExecutionPanel, {
|
||||
props: {
|
||||
execution: execution({
|
||||
status: 'completed',
|
||||
stage: 'completed',
|
||||
current: 2,
|
||||
result: { targetCount: 2, passed: 1, exhausted: 1, providerFailed: 0, submissionFailed: 0 }
|
||||
}),
|
||||
loading: false,
|
||||
error: ''
|
||||
}
|
||||
})
|
||||
expect(wrapper.text()).toContain('本轮任务已结束')
|
||||
expect(wrapper.text()).toContain('通过 1')
|
||||
expect(wrapper.text()).toContain('修复耗尽 1')
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user