feat(short-drama-agent-front): 补齐后端生产与质量功能
This commit is contained in:
1 parent
967c4ebea1
commit
470b52e26d
52 files changed
+3754
-1075
No files matched your search
@@ -1,7 +1,9 @@
|
||||
import type { KeyframeBatchResult } from './types'
|
||||
import type { PromptBatchResult } from '../storyboard/types'
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { usePolling } from '../../composables/usePolling'
|
||||
import { useProjectContext } from '../projects/context'
|
||||
import { mergeDesignedShots } from '../storyboard/model'
|
||||
import { currentEpisodeSource, getStoryboardSession, mergeDesignedShots } from '../storyboard/model'
|
||||
import { storyboardApi } from '../storyboard/api'
|
||||
import { breakdownSnapshot } from '../workflows/selectors'
|
||||
import { getOperation, runOperation } from '../workflows/operations'
|
||||
@@ -17,22 +19,37 @@ export type ProductionCommand = 'prompts' | 'keyframes' | 'videos' | 'retry-vide
|
||||
/** 镜头生产页的查询、筛选、就绪状态与批量操作。 */
|
||||
export function useProduction() {
|
||||
const context = useProjectContext()
|
||||
/** 当前工作区的响应式状态或派生业务条件。 */
|
||||
const id = computed(() => context.project.value?.id ?? '')
|
||||
/** 当前工作区的响应式状态或派生业务条件。 */
|
||||
const selectedEpisode = ref<number>()
|
||||
/** 当前工作区的响应式状态或派生业务条件。 */
|
||||
const selectedShot = ref('')
|
||||
/** 当前工作区的响应式状态或派生业务条件。 */
|
||||
const concurrency = ref(2)
|
||||
/** 当前工作区的响应式状态或派生业务条件。 */
|
||||
const force = ref(false)
|
||||
/** 当前工作区的响应式状态或派生业务条件。 */
|
||||
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 videoInputMode = ref<VideoInputMode | 'all'>('all')
|
||||
/** 当前工作区的响应式状态或派生业务条件。 */
|
||||
const snapshot = computed(() => breakdownSnapshot(context.checkpoints.value))
|
||||
/** 当前工作区的响应式状态或派生业务条件。 */
|
||||
const sourceEpisodes = computed(
|
||||
() => snapshot.value?.storyboardEpisodeShots ?? snapshot.value?.breakdownResult?.storyboardEpisodeShots ?? []
|
||||
)
|
||||
/** 当前工作区的响应式状态或派生业务条件。 */
|
||||
const episodeOptions = computed(() => {
|
||||
const entries = new Map(context.project.value?.episodes.map(episode => [episode.episode, episode.title]) ?? [])
|
||||
for (const episode of sourceEpisodes.value) {
|
||||
@@ -42,12 +59,14 @@ export function useProduction() {
|
||||
.map(([episodeNo, title]) => ({ episodeNo, title }))
|
||||
.toSorted((a, b) => a.episodeNo - b.episodeNo)
|
||||
})
|
||||
/** 当前工作区的响应式状态或派生业务条件。 */
|
||||
const episodeNo = computed(
|
||||
() =>
|
||||
episodeOptions.value.find(item => item.episodeNo === selectedEpisode.value)?.episodeNo ??
|
||||
episodeOptions.value[0]?.episodeNo ??
|
||||
0
|
||||
)
|
||||
/** 当前工作区的响应式状态或派生业务条件。 */
|
||||
const queryKey = computed(() => JSON.stringify([id.value, episodeNo.value, force.value]))
|
||||
/** 生产页已有刷新按钮,就绪状态改为手动更新。 */
|
||||
const query = usePolling(
|
||||
@@ -80,23 +99,48 @@ export function useProduction() {
|
||||
},
|
||||
false
|
||||
)
|
||||
const source = computed(() => sourceEpisodes.value.find(item => item.episodeNo === episodeNo.value))
|
||||
/** 当前工作区的响应式状态或派生业务条件。 */
|
||||
/** 重生成后不拿旧剧情快照补充新的正式镜头。 */
|
||||
const source = computed(() =>
|
||||
currentEpisodeSource(
|
||||
id.value,
|
||||
episodeNo.value,
|
||||
sourceEpisodes.value.find(item => item.episodeNo === episodeNo.value)
|
||||
)
|
||||
)
|
||||
/** 未取得重生成后的正文时,只展示正式镜头编号,不填充旧剧情或时长。 */
|
||||
const episodeSourceUnavailable = computed(
|
||||
() => !!getStoryboardSession(id.value).invalidatedEpisodeSources[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])
|
||||
/** 当前工作区的响应式状态或派生业务条件。 */
|
||||
const promptItem = computed(() => query.data.value?.prompts.items.find(item => item.shotId === shot.value?.shotId))
|
||||
/** 当前工作区的响应式状态或派生业务条件。 */
|
||||
const keyframeItem = computed(() =>
|
||||
query.data.value?.keyframes.items.find(item => item.shotId === shot.value?.shotId)
|
||||
)
|
||||
/** 当前工作区的响应式状态或派生业务条件。 */
|
||||
const videoItem = computed(() => query.data.value?.videos.items.find(item => item.shotId === shot.value?.shotId))
|
||||
/** 当前工作区的响应式状态或派生业务条件。 */
|
||||
const videoStatusItem = computed(() =>
|
||||
query.data.value?.videoStatus.items.find(item => item.shotId === shot.value?.shotId)
|
||||
)
|
||||
/** 当前工作区的响应式状态或派生业务条件。 */
|
||||
const operation = computed(() => getOperation(id.value))
|
||||
/** 当前工作区的响应式状态或派生业务条件。 */
|
||||
const session = computed(() => getProductionSession(id.value))
|
||||
/** 普通首帧后台观察器,刷新页面后恢复真实执行状态。 */
|
||||
const keyframeExecution = useWorkflowExecution(id, 'keyframe-generation')
|
||||
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)) &&
|
||||
@@ -110,6 +154,7 @@ export function useProduction() {
|
||||
Number.isSafeInteger(videoRepairAttempts.value) &&
|
||||
(videoRepairAttempts.value ?? 0) > 0
|
||||
)
|
||||
/** 当前工作区的响应式状态或派生业务条件。 */
|
||||
const blocked = computed(
|
||||
() =>
|
||||
operation.value.pending ||
|
||||
@@ -128,13 +173,39 @@ export function useProduction() {
|
||||
if ((status === 'completed' || status === 'failed') && status !== previous) void query.refresh()
|
||||
}
|
||||
)
|
||||
/** 观察后台状态变化并同步正式资产。 */
|
||||
watch(
|
||||
() => promptExecution.query.data.value?.status,
|
||||
(status, previous) => {
|
||||
const record = promptExecution.query.data.value
|
||||
if (status === 'completed' && record?.projectId === id.value && record.result) {
|
||||
const result = record.result as unknown as PromptBatchResult
|
||||
if (typeof result.total === 'number' && Array.isArray(result.failures)) {
|
||||
getProductionSession(record.projectId).receipt = {
|
||||
kind: 'prompts',
|
||||
title: '项目视频提示词',
|
||||
result
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((status === 'completed' || status === 'failed') && status !== previous) void query.refresh()
|
||||
}
|
||||
)
|
||||
|
||||
/** 普通首帧任务完成后才展示后端回执;失败仍刷新已经保存的资产。 */
|
||||
watch(
|
||||
() => keyframeExecution.query.data.value,
|
||||
record => {
|
||||
if (!record || record.projectId !== id.value || !['completed', 'failed'].includes(record.status)) return
|
||||
if (record.status === 'completed' && record.result) {
|
||||
const result = record.result as unknown as KeyframeBatchResult
|
||||
if (typeof result.total !== 'number' || !Array.isArray(result.failures)) return
|
||||
getProductionSession(record.projectId).receipt = { kind: 'keyframes', title: '项目首帧生成', result }
|
||||
}
|
||||
void query.refresh()
|
||||
}
|
||||
)
|
||||
|
||||
/** 批量操作只向就绪镜头提交;最终资产状态由轮询查询确认。 */
|
||||
async function run(command: ProductionCommand) {
|
||||
if (
|
||||
@@ -172,21 +243,18 @@ export function useProduction() {
|
||||
episodeNo: episodeNo.value,
|
||||
limit: promptLimit.value ?? undefined
|
||||
})
|
||||
await promptExecution.track(started.executionId)
|
||||
await promptExecution.track(started.executionId, projectId)
|
||||
} else if (command === 'keyframes') {
|
||||
target.receipt = {
|
||||
kind: 'keyframes',
|
||||
title: labels[command],
|
||||
result: await productionApi.generateKeyframes(projectId, {
|
||||
...input,
|
||||
// 有 stale 时由后端优先处理全部 stale;否则只补当前剧集,避免误跑整个项目。
|
||||
...(force.value || staleKeyframes > 0 ? {} : { episodeNo: episodeNo.value }),
|
||||
...(keyframeLimit.value === '' ? {} : { limit: keyframeLimit.value }),
|
||||
...(keyframeWidth.value === '' || keyframeHeight.value === ''
|
||||
? {}
|
||||
: { width: keyframeWidth.value, height: keyframeHeight.value })
|
||||
})
|
||||
}
|
||||
const started = await productionApi.generateKeyframes(projectId, {
|
||||
...input,
|
||||
// 有 stale 时由后端优先处理全部 stale;否则只补当前剧集,避免误跑整个项目。
|
||||
...(force.value || staleKeyframes > 0 ? {} : { episodeNo: episodeNo.value }),
|
||||
...(keyframeLimit.value === '' ? {} : { limit: keyframeLimit.value }),
|
||||
...(keyframeWidth.value === '' || keyframeHeight.value === ''
|
||||
? {}
|
||||
: { width: keyframeWidth.value, height: keyframeHeight.value })
|
||||
})
|
||||
await keyframeExecution.track(started.executionId, projectId)
|
||||
} else if (command === 'videos') {
|
||||
const started = await productionApi.startQualityVideoExecution(projectId, {
|
||||
...input,
|
||||
@@ -195,7 +263,7 @@ export function useProduction() {
|
||||
...(videoInputMode.value === 'all' ? {} : { inputMode: videoInputMode.value }),
|
||||
maxRepairAttempts: videoRepairAttempts.value ?? 0
|
||||
})
|
||||
await videoExecution.track(started.executionId)
|
||||
await videoExecution.track(started.executionId, projectId)
|
||||
} else {
|
||||
target.receipt = {
|
||||
kind: 'retry',
|
||||
@@ -220,6 +288,7 @@ export function useProduction() {
|
||||
videoItem,
|
||||
videoStatusItem,
|
||||
query,
|
||||
episodeSourceUnavailable,
|
||||
operation,
|
||||
session,
|
||||
concurrency,
|
||||
@@ -237,6 +306,7 @@ export function useProduction() {
|
||||
batchValid,
|
||||
blocked,
|
||||
run,
|
||||
keyframeExecution,
|
||||
promptExecution,
|
||||
videoExecution
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user