feat: 对齐后端能力并补齐形态提示词与生产诊断

This commit is contained in:
GouJ committed 2026-09-02 18:21:20 +08:00
1 parent 7d8074f90e
commit f71d2bf0a4
30 files changed
+1707 -66

No files matched your search

@@ -0,0 +1,155 @@
import { computed, onScopeDispose, ref, watch } from 'vue'
import { projectsApi } from '../projects/api'
import { useProjectContext } from '../projects/context'
import { subjectImagesApi } from '../subject-images/api'
import { hasRunningImages, isPrimaryIdentityStale, primaryImage } from '../subject-images/model'
import { getOperation, runOperation } from '../workflows/operations'
import { workflowCheckpoints } from '../workflows/selectors'
import { errorMessage } from '../../lib/http'
import { productionApi } from './api'
import { getProductionSession } from './model'
/** 高级串联入口只能消费已验图的主资产,不替用户跳过选角、设计和首帧环节。 */
export async function checkPipeline(projectId: string) {
const [project, checkpoints, forms, keyframes, prompts, videos] = await Promise.all([
projectsApi.detail(projectId),
projectsApi.checkpoints(projectId),
subjectImagesApi.listForms(projectId),
productionApi.keyframeReadiness(projectId, true),
productionApi.promptReadiness(projectId, true),
productionApi.videoReadiness(projectId, false)
])
if (project.id !== projectId || forms.some(form => form.subject.projectId !== projectId))
throw new Error('预检返回了其他项目的数据,请重新读取。')
const issues: string[] = []
const shotIds = new Set(keyframes.items.map(item => item.shotId))
if (
shotIds.size !== keyframes.total ||
[prompts, videos].some(
data =>
new Set(data.items.map(item => item.shotId)).size !== shotIds.size ||
data.items.some(item => !shotIds.has(item.shotId))
)
)
issues.push('各阶段镜头列表不一致,可能正在重新拆解,请刷新后重试。')
if (project.status !== 'completed') issues.push('剧本尚未完成,请先完成剧本创作。')
if (
project.tasks.some(task => ['pending', 'queued', 'running', 'generating'].includes(task.status)) ||
[...new Set(checkpoints.map(item => item.workflowName))].some(
name => workflowCheckpoints(checkpoints, name).at(-1)?.state.workflowExecution?.status === 'running'
)
)
issues.push('项目仍有后台任务或工作流进行中。')
if (!forms.length) issues.push('尚无正式形态,请先完成拆解。')
if (forms.some(form => hasRunningImages(form.images))) issues.push('形态图片仍在生成中。')
if (forms.some(form => !primaryImage(form.images)?.imageUrl || isPrimaryIdentityStale(form)))
issues.push('请先补齐并确认所有形态主图,更新过期母版引用,再生成首帧。')
if (
!keyframes.total ||
keyframes.items.length !== keyframes.total ||
keyframes.items.some(
item =>
!item.primaryKeyframeId || item.primaryKeyframeStale || item.issues.length || item.status === 'blocked'
)
)
issues.push('请先为全部镜头完成设计、身份检查和有效主首帧;串联流程不会生成首帧。')
if (
prompts.total !== keyframes.total ||
prompts.items.length !== prompts.total ||
prompts.items.some(item => item.issues.length || item.status === 'blocked')
)
issues.push('视频提示词的生成规格或参考图不完整,请到分镜页修复。')
if (
videos.total !== keyframes.total ||
videos.items.length !== videos.total ||
videos.items.some(item => item.issues.some(issue => issue.code !== 'missing_prompt'))
)
issues.push('视频前置检查未通过,请检查参考图和主首帧。')
if (videos.inProgress || videos.items.some(item => item.status === 'in_progress' || item.activeVideoId))
issues.push('存在活动视频任务,请等待结束后再操作。')
return { projectId, issues, shotCount: keyframes.total, checkedAt: new Date().toISOString() }
}
/** 预检不付费;确认后再次预检并锁住本浏览器项目,长请求不自动重发。 */
export function useAdvancedProduction() {
const context = useProjectContext()
const id = computed(() => context.project.value?.id ?? '')
const operation = computed(() => getOperation(id.value))
const session = computed(() => getProductionSession(id.value))
const checking = ref(false)
const error = ref('')
const check = ref<Awaited<ReturnType<typeof checkPipeline>> | null>(null)
const blocked = computed(
() =>
!id.value ||
operation.value.pending ||
!!context.error.value ||
context.project.value?.status !== 'completed'
)
let version = 0
let disposed = false
onScopeDispose(() => {
disposed = true
version++
})
watch(id, () => {
version++
check.value = null
error.value = ''
checking.value = false
})
async function preflight() {
if (blocked.value || checking.value) return
const current = ++version
const projectId = id.value
checking.value = true
check.value = null
error.value = ''
try {
const result = await checkPipeline(projectId)
if (current === version && id.value === projectId) check.value = result
} catch (cause) {
if (current === version) error.value = errorMessage(cause)
} finally {
if (current === version) checking.value = false
}
}
async function start() {
if (
blocked.value ||
checking.value ||
!check.value ||
check.value.projectId !== id.value ||
check.value.issues.length
)
return
const projectId = id.value
const target = getProductionSession(projectId)
let submitted = false
await runOperation(projectId, '高级串联生产', async () => {
const result = await checkPipeline(projectId)
if (
disposed ||
id.value !== projectId ||
context.project.value?.status !== 'completed' ||
context.error.value
)
return
check.value = result
if (result.issues.length) throw new Error('提交前预检发现条件变化,未启动生产。请处理下方问题。')
target.pipelineReceipt = null
submitted = true
const receipt = await productionApi.startPipeline(projectId)
if (!receipt || receipt.projectId !== projectId)
throw new Error('回执项目不匹配,请读取资产状态核对,不要直接重试。')
target.pipelineReceipt = receipt
})
if (!disposed && id.value === projectId) {
if (submitted) check.value = null
await context.refresh()
}
}
return { id, operation, session, checking, error, check, blocked, preflight, start }
}