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

+105 -47
View File
@@ -1,10 +1,18 @@
import { computed, ref } from 'vue'
import { useWorkflowExecution } from '../workflows/execution'
import type { StoryboardBatchResult, PromptBatchResult, StoryboardShotRegenerationResult } from './types'
import { computed, ref, watch } from 'vue'
import { useQuery } from '../../composables/useQuery'
import { useProjectContext } from '../projects/context'
import { breakdownSnapshot } from '../workflows/selectors'
import { getOperation, runOperation } from '../workflows/operations'
import { storyboardApi } from './api'
import { getStoryboardSession, mergeDesignedShots, storyboardPrerequisites } from './model'
import {
currentEpisodeSource,
getStoryboardSession,
invalidateEpisodeSource,
mergeDesignedShots,
storyboardPrerequisites
} from './model'
/** 分镜页只提供正式主流程命令,不暴露后端测试路由。 */
export type StoryboardCommand = 'shots-current' | 'direction-all' | 'visual-all' | 'prompts'
@@ -12,16 +20,25 @@ export type StoryboardCommand = 'shots-current' | 'direction-all' | 'visual-all'
/** 分镜查询、依赖判断与操作入口;不修改后端 graph。 */
export function useStoryboard() {
const context = useProjectContext()
/** 当前工作区的响应式状态或派生业务条件。 */
const id = computed(() => context.project.value?.id ?? '')
/** 当前工作区的响应式状态或派生业务条件。 */
const selectedEpisode = ref<number>()
/** 当前工作区的响应式状态或派生业务条件。 */
const selectedShot = ref('')
/** 当前工作区的响应式状态或派生业务条件。 */
const concurrency = ref(2)
/** 当前工作区的响应式状态或派生业务条件。 */
const maxRepairAttempts = ref(2)
/** 当前工作区的响应式状态或派生业务条件。 */
const force = ref(false)
/** 当前工作区的响应式状态或派生业务条件。 */
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) {
@@ -31,12 +48,14 @@ export function useStoryboard() {
.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]))
/** 分镜页仅在进入、切换剧集或显式刷新时读取。 */
const query = useQuery(queryKey, async (key, signal) => {
@@ -57,21 +76,33 @@ export function useStoryboard() {
return { directions, visualStates }
})
const data = query.data
/** 当前工作区的响应式状态或派生业务条件。 */
const session = computed(() => getStoryboardSession(id.value))
/** 单集重生成返回的是最新镜头正文,优先于不会随局部覆盖更新的历史 Breakdown 快照。 */
const source = computed(
() =>
session.value.regeneratedEpisodes[episodeNo.value] ??
const source = computed(() =>
currentEpisodeSource(
id.value,
episodeNo.value,
sourceEpisodes.value.find(item => item.episodeNo === episodeNo.value)
)
)
/** 重生成接口未返回新正文时,明确标记辅助剧情信息不可用。 */
const episodeSourceUnavailable = computed(() => !!session.value.invalidatedEpisodeSources[episodeNo.value])
/** 当前工作区的响应式状态或派生业务条件。 */
const shots = computed(() =>
mergeDesignedShots(data.value?.directions ?? null, data.value?.visualStates ?? null, source.value)
)
/** 当前工作区的响应式状态或派生业务条件。 */
const shot = computed(() => shots.value.find(item => item.shotId === selectedShot.value) ?? shots.value[0])
/** 当前工作区的响应式状态或派生业务条件。 */
const prerequisites = computed(() => storyboardPrerequisites(context.checkpoints.value, episodeNo.value))
/** 当前工作区的响应式状态或派生业务条件。 */
const operation = computed(() => getOperation(id.value))
/** 当前工作区的响应式状态或派生业务条件。 */
const batchValid = computed(() => Number.isSafeInteger(concurrency.value) && concurrency.value > 0)
/** 当前工作区的响应式状态或派生业务条件。 */
const repairsValid = computed(() => Number.isSafeInteger(maxRepairAttempts.value) && maxRepairAttempts.value >= 0)
/** 当前工作区的响应式状态或派生业务条件。 */
const blocked = computed(
() =>
operation.value.pending ||
@@ -81,18 +112,21 @@ export function useStoryboard() {
context.project.value?.status !== 'completed' ||
prerequisites.value.breakdownRunning
)
/** 当前工作区的响应式状态或派生业务条件。 */
const directionComplete = computed(
() =>
!!data.value?.directions.shotCount &&
data.value.directions.directionCount === data.value.directions.shotCount &&
data.value.directions.coverage === 1
)
/** 当前工作区的响应式状态或派生业务条件。 */
const visualStateComplete = computed(
() =>
!!data.value?.visualStates.shotCount &&
data.value.visualStates.visualStateCount === data.value.visualStates.shotCount &&
data.value.visualStates.coverage === 1
)
/** 当前工作区的响应式状态或派生业务条件。 */
const hasCurrentEpisodeShots = computed(
() => Math.max(data.value?.directions.shotCount ?? 0, data.value?.visualStates.shotCount ?? 0) > 0
)
@@ -103,6 +137,54 @@ export function useStoryboard() {
prompts: !blocked.value && shots.value.length > 0 && batchValid.value
}))
/** 正式后台任务观察器;重生成使用后端 breakdown 名称并通过 metadata 区分。 */
const executions = [
{ title: '单集镜头重生成', observer: useWorkflowExecution(id, 'breakdown') },
{ title: '项目导演设计', observer: useWorkflowExecution(id, 'storyboard-direction') },
{ title: '项目即时状态', observer: useWorkflowExecution(id, 'storyboard-visual-state') },
{ title: '项目视频提示词', observer: useWorkflowExecution(id, 'video-prompt') }
]
/** 真实终态结果才发布回执;刷新恢复也按后端 metadata 归属。 */
for (const [index, entry] of executions.entries()) {
watch(
() => entry.observer.query.data.value,
record => {
if (!record || record.projectId !== id.value || !['completed', 'failed'].includes(record.status)) return
const target = getStoryboardSession(record.projectId)
if (index === 0 && record.metadata?.action !== 'regenerate-storyboard-episode') return
if (record.status === 'completed' && record.result) {
if (index === 0) {
const result = record.result as unknown as StoryboardShotRegenerationResult
const number = record.metadata?.episodeNo
if (
typeof number !== 'number' ||
result.episodeNo !== number ||
!result.storyboardShotValidation ||
!result.storyboardShotSummary
)
return
target.receipt = { kind: 'shots', title: `第 ${number} 集镜头`, result }
if (result.storyboardShotValidation.valid) {
delete target.regeneratedEpisodes[number]
invalidateEpisodeSource(record.projectId, number)
target.prompts = {}
if (episodeNo.value === number) selectedShot.value = ''
}
} else if (index === 3) {
const result = record.result as unknown as PromptBatchResult
if (typeof result.failed !== 'number') return
target.receipt = { kind: 'prompts', title: entry.title, result }
} else {
const result = record.result as unknown as StoryboardBatchResult
if (result.projectId !== record.projectId || !Array.isArray(result.episodes)) return
target.receipt = { kind: 'batch', title: entry.title, result }
}
}
void Promise.all([query.refresh(), context.refresh(), context.refreshStageReadiness()])
}
)
}
/** 捕获提交时的目标与配置,切换剧集不改变正在运行的请求或回执。 */
async function run(command: StoryboardCommand) {
if (!allowed.value[command]) return
@@ -119,48 +201,22 @@ export function useStoryboard() {
}
target.receipt = null
await runOperation(projectId, `生成${titles[command]}`, async () => {
switch (command) {
case 'shots-current': {
const result = await storyboardApi.regenerateEpisodeShots(projectId, targetEpisode)
if (result.projectId !== projectId || result.episodeNo !== targetEpisode) {
throw new Error('镜头重生成返回了不匹配的项目或剧集,请刷新后重试。')
}
target.receipt = { kind: 'shots', title: titles[command], result }
if (!result.storyboardShotValidation.valid) {
throw new Error('本集镜头校验未通过,后端未覆盖正式 Storyboard。')
}
target.regeneratedEpisodes[targetEpisode] = result.episodeShot
// 新镜头会获得新的数据库 ID,废弃所有按旧 Shot ID 缓存的提示词。
target.prompts = {}
if (episodeNo.value === targetEpisode) selectedShot.value = ''
break
}
case 'direction-all':
target.receipt = {
kind: 'batch',
title: titles[command],
result: await storyboardApi.generateDirections(projectId, batch)
}
break
case 'visual-all':
target.receipt = {
kind: 'batch',
title: titles[command],
result: await storyboardApi.generateVisualStates(projectId, {
...batch,
maxRepairAttempts: repairs
})
}
break
case 'prompts':
// 断网时也可能已部分覆盖,先清空缓存,避免继续展示可能失效的正文。
target.prompts = {}
target.receipt = {
kind: 'prompts',
title: titles[command],
result: await storyboardApi.generatePrompts(projectId, batch)
}
break
if (command === 'shots-current') {
const started = await storyboardApi.regenerateEpisodeShots(projectId, targetEpisode)
await executions[0]!.observer.track(started.executionId, projectId)
} else if (command === 'direction-all') {
const started = await storyboardApi.generateDirections(projectId, batch)
await executions[1]!.observer.track(started.executionId, projectId)
} else if (command === 'visual-all') {
const started = await storyboardApi.generateVisualStates(projectId, {
...batch,
maxRepairAttempts: repairs
})
await executions[2]!.observer.track(started.executionId, projectId)
} else {
target.prompts = {}
const started = await storyboardApi.generatePrompts(projectId, batch)
await executions[3]!.observer.track(started.executionId, projectId)
}
})
await Promise.all([query.refresh(), context.refreshStageReadiness()])
@@ -177,6 +233,7 @@ export function useStoryboard() {
query,
data,
source,
episodeSourceUnavailable,
prerequisites,
session,
operation,
@@ -190,6 +247,7 @@ export function useStoryboard() {
directionComplete,
visualStateComplete,
hasCurrentEpisodeShots,
executions,
run
}
}