feat: 接入持久化工作流执行状态
This commit is contained in:
1 parent
7d2900c705
commit
3caea26924
14 files changed
+532
-44
No files matched your search
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user