feat: 接入分镜导演设计与即时视觉状态工作台
增加单集和批量生成、修复诊断、正式镜头检查、参考图、生成规格与视频提示词。 补齐接口契约、竞态保护和确认交互测试,保持现有两条工作流。
This commit is contained in:
1 parent
2ee6f049f6
commit
bae69c3c62
22 files changed
+2211
-11
No files matched your search
@@ -0,0 +1,182 @@
|
||||
import { computed, ref } from 'vue'
|
||||
import { usePolling } from '../../composables/usePolling'
|
||||
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'
|
||||
|
||||
/** 分镜页允许的生成命令,保持单集与批量参数边界。 */
|
||||
export type StoryboardCommand = 'direction-one' | 'direction-all' | 'visual-one' | 'visual-all' | 'prompts'
|
||||
|
||||
/** 分镜查询、依赖判断与操作入口;不修改后端 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) {
|
||||
if (!entries.has(episode.episodeNo)) entries.set(episode.episodeNo, episode.episodePlan.episodeTitle)
|
||||
}
|
||||
return [...entries]
|
||||
.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 = usePolling(queryKey, async (key, signal) => {
|
||||
const [projectId, number] = JSON.parse(key) as [string, number]
|
||||
if (!projectId || !number) return null
|
||||
const [directions, visualStates] = await Promise.all([
|
||||
storyboardApi.directions(projectId, number, signal),
|
||||
storyboardApi.visualStates(projectId, number, signal)
|
||||
])
|
||||
if (
|
||||
directions.projectId !== projectId ||
|
||||
visualStates.projectId !== projectId ||
|
||||
directions.episodeNo !== number ||
|
||||
visualStates.episodeNo !== number
|
||||
) {
|
||||
throw new Error('分镜查询返回了不匹配的项目或剧集,请刷新后重试。')
|
||||
}
|
||||
return { directions, visualStates }
|
||||
})
|
||||
const data = query.data
|
||||
const source = computed(() => sourceEpisodes.value.find(item => item.episodeNo === 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 session = computed(() => getStoryboardSession(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 ||
|
||||
!!context.error.value ||
|
||||
!!query.error.value ||
|
||||
!data.value ||
|
||||
context.project.value?.status === 'generating' ||
|
||||
prerequisites.value.breakdownRunning
|
||||
)
|
||||
const directionComplete = computed(
|
||||
() =>
|
||||
!!data.value?.directions.shotCount &&
|
||||
data.value.directions.directionCount === data.value.directions.shotCount &&
|
||||
data.value.directions.coverage === 1
|
||||
)
|
||||
const allowed = computed<Record<StoryboardCommand, boolean>>(() => ({
|
||||
'direction-one': !blocked.value && prerequisites.value.directionEpisode && !!data.value?.directions.shotCount,
|
||||
'direction-all': !blocked.value && prerequisites.value.directionProject && batchValid.value,
|
||||
'visual-one':
|
||||
!blocked.value && prerequisites.value.visualEpisode && directionComplete.value && repairsValid.value,
|
||||
'visual-all': !blocked.value && prerequisites.value.visualProject && batchValid.value && repairsValid.value,
|
||||
prompts: !blocked.value && shots.value.length > 0 && batchValid.value
|
||||
}))
|
||||
|
||||
/** 捕获提交时的目标与配置,切换剧集不改变正在运行的请求或回执。 */
|
||||
async function run(command: StoryboardCommand) {
|
||||
if (!allowed.value[command]) return
|
||||
const projectId = id.value
|
||||
const number = episodeNo.value
|
||||
const batch = { concurrency: concurrency.value, force: force.value }
|
||||
const repairs = maxRepairAttempts.value
|
||||
const target = getStoryboardSession(projectId)
|
||||
const titles: Record<StoryboardCommand, string> = {
|
||||
'direction-one': `第 ${number} 集导演设计`,
|
||||
'direction-all': '项目导演设计',
|
||||
'visual-one': `第 ${number} 集即时状态`,
|
||||
'visual-all': '项目即时状态',
|
||||
prompts: '项目视频提示词'
|
||||
}
|
||||
target.receipt = null
|
||||
await runOperation(projectId, `生成${titles[command]}`, async () => {
|
||||
switch (command) {
|
||||
case 'direction-one':
|
||||
target.receipt = {
|
||||
kind: 'direction',
|
||||
title: titles[command],
|
||||
episodeNo: number,
|
||||
result: await storyboardApi.generateDirection(projectId, number)
|
||||
}
|
||||
break
|
||||
case 'direction-all':
|
||||
target.receipt = {
|
||||
kind: 'batch',
|
||||
title: titles[command],
|
||||
result: await storyboardApi.generateDirections(projectId, batch)
|
||||
}
|
||||
break
|
||||
case 'visual-one':
|
||||
target.receipt = {
|
||||
kind: 'visual-state',
|
||||
title: titles[command],
|
||||
episodeNo: number,
|
||||
result: await storyboardApi.generateVisualState(projectId, number, repairs)
|
||||
}
|
||||
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
|
||||
}
|
||||
})
|
||||
await Promise.all([query.refresh(), context.refresh()])
|
||||
}
|
||||
|
||||
return {
|
||||
id,
|
||||
selectedEpisode,
|
||||
episodeNo,
|
||||
episodeOptions,
|
||||
selectedShot,
|
||||
shots,
|
||||
shot,
|
||||
query,
|
||||
data,
|
||||
source,
|
||||
prerequisites,
|
||||
session,
|
||||
operation,
|
||||
concurrency,
|
||||
maxRepairAttempts,
|
||||
force,
|
||||
allowed,
|
||||
batchValid,
|
||||
repairsValid,
|
||||
blocked,
|
||||
directionComplete,
|
||||
run
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user