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
@@ -6,16 +6,26 @@ import { hasRunningImages } from '../subject-images/model'
|
||||
import { getOperation, runOperation } from '../workflows/operations'
|
||||
import { useWorkflowExecution } from '../workflows/execution'
|
||||
import { hasRunningWorkflow } from '../workflows/selectors'
|
||||
import { errorMessage } from '../../lib/http'
|
||||
import { ApiError, errorMessage } from '../../lib/http'
|
||||
import { generationConfigApi } from '../generation-config/api'
|
||||
import { productionApi } from './api'
|
||||
import { getProductionSession } from './model'
|
||||
import type { ProductionStartInput, ProductionStage } from './types'
|
||||
|
||||
/** 使用后端计划区分可自动补齐和人工阻塞,保留项目归属及活动任务检查。 */
|
||||
export async function checkPipeline(projectId: string) {
|
||||
/**
|
||||
* 使用后端计划区分可自动补齐和人工阻塞,保留项目归属及活动任务检查。
|
||||
* @param projectId 当前项目 ID
|
||||
* @param scope 已选择的生产范围
|
||||
* @returns 无消耗计划、实际状态与同源请求参数
|
||||
*/
|
||||
export async function checkPipeline(projectId: string, scope: ProductionStartInput = {}) {
|
||||
const profile = await generationConfigApi.profile(projectId)
|
||||
const providers = profile
|
||||
? { imageProvider: profile.imageProvider, videoProvider: profile.videoProvider }
|
||||
? {
|
||||
imageProvider: profile.imageProvider,
|
||||
videoProvider: profile.videoProvider,
|
||||
imageGenerationOptions: { ...profile.imageOptions }
|
||||
}
|
||||
: undefined
|
||||
const [project, checkpoints, forms, plan, status] = await Promise.all([
|
||||
projectsApi.detail(projectId),
|
||||
@@ -32,6 +42,8 @@ export async function checkPipeline(projectId: string) {
|
||||
)
|
||||
throw new Error('预检返回了其他项目的数据,请重新读取。')
|
||||
const issues: string[] = []
|
||||
if (plan.entryReadiness && !plan.entryReadiness.ready)
|
||||
issues.push(plan.entryReadiness.reason || '项目尚未满足生产入口条件。')
|
||||
if (!profile) issues.push('尚未配置项目画布与生成模型,请先在批量生产工具中保存配置。')
|
||||
const shotIds = new Set(plan.details.keyframes.map(item => item.shotId))
|
||||
if (
|
||||
@@ -68,23 +80,56 @@ export async function checkPipeline(projectId: string) {
|
||||
status,
|
||||
profile,
|
||||
shotCount: plan.keyframes.total,
|
||||
input: { ...scope, ...providers } as ProductionStartInput,
|
||||
checkedAt: new Date().toISOString()
|
||||
}
|
||||
}
|
||||
|
||||
/** 预检不付费;确认后再次预检并锁住本浏览器项目,长请求不自动重发。 */
|
||||
/**
|
||||
* 预检不付费;确认后再次预检并锁住本浏览器项目,长请求不自动重发。
|
||||
* @returns 生产范围、预检状态及一次性提交操作
|
||||
*/
|
||||
export function useAdvancedProduction() {
|
||||
const context = useProjectContext()
|
||||
/** 当前项目 ID。 */
|
||||
const id = computed(() => context.project.value?.id ?? '')
|
||||
/** 项目级操作锁。 */
|
||||
const operation = computed(() => getOperation(id.value))
|
||||
/** 项目生产回执。 */
|
||||
const session = computed(() => getProductionSession(id.value))
|
||||
const execution = useWorkflowExecution(id, 'production')
|
||||
/** 正在读取预检。 */
|
||||
const checking = ref(false)
|
||||
/** 预检错误或已有任务说明。 */
|
||||
const error = ref('')
|
||||
/** 默认使用无视频测试模式,只有用户明确切换后才允许提交高费用视频任务。 */
|
||||
const safeMode = ref(true)
|
||||
/** 本轮有限首帧数量,保留原安全模式字段。 */
|
||||
const testKeyframeLimit = ref<number | null>(1)
|
||||
/** 恢复起点;留空从默认入口开始。 */
|
||||
const startFrom = ref<ProductionStage | null>(null)
|
||||
/** 显式结束阶段;安全模式下为空时默认在视频提示词后停止。 */
|
||||
const stopAfter = ref<ProductionStage | null>(null)
|
||||
/** 本轮稳定身份母版上限。 */
|
||||
const stableIdentityAnchorLimit = ref<number | null>(1)
|
||||
/** 本轮主体图片上限。 */
|
||||
const subjectImageLimit = ref<number | null>(1)
|
||||
/** 本轮视频提示词上限。 */
|
||||
const videoPromptLimit = ref<number | null>(1)
|
||||
/** 可供界面和确认描述共用的生产范围。 */
|
||||
const scope = computed<ProductionStartInput>(() => ({
|
||||
...(startFrom.value ? { startFrom: startFrom.value } : {}),
|
||||
...(stopAfter.value || safeMode.value ? { stopAfter: stopAfter.value ?? 'videoPrompts' } : {}),
|
||||
stableIdentityAnchorLimit: stableIdentityAnchorLimit.value ?? 0,
|
||||
subjectImageLimit: subjectImageLimit.value ?? 0,
|
||||
keyframeLimit: testKeyframeLimit.value ?? 0,
|
||||
videoPromptLimit: videoPromptLimit.value ?? 0
|
||||
}))
|
||||
/** 阶段顺序与后端正整数约束。 */
|
||||
const scopeError = computed(() => validateProductionScope(scope.value))
|
||||
/** 已读取的预检与其不可变请求快照。 */
|
||||
const check = ref<Awaited<ReturnType<typeof checkPipeline>> | null>(null)
|
||||
/** 当前项目不可提交条件。 */
|
||||
const blocked = computed(
|
||||
() =>
|
||||
!id.value ||
|
||||
@@ -106,15 +151,27 @@ export function useAdvancedProduction() {
|
||||
checking.value = false
|
||||
})
|
||||
|
||||
watch(
|
||||
[scope, safeMode],
|
||||
() => {
|
||||
version++
|
||||
check.value = null
|
||||
checking.value = false
|
||||
error.value = ''
|
||||
},
|
||||
{ deep: true, flush: 'sync' }
|
||||
)
|
||||
|
||||
/** 只读取无消耗计划,保存此次范围与模型参数。 */
|
||||
async function preflight() {
|
||||
if (blocked.value || checking.value) return
|
||||
if (blocked.value || checking.value || scopeError.value) return
|
||||
const current = ++version
|
||||
const projectId = id.value
|
||||
checking.value = true
|
||||
check.value = null
|
||||
error.value = ''
|
||||
try {
|
||||
const result = await checkPipeline(projectId)
|
||||
const result = await checkPipeline(projectId, scope.value)
|
||||
if (current === version && id.value === projectId) check.value = result
|
||||
} catch (cause) {
|
||||
if (current === version) error.value = errorMessage(cause)
|
||||
@@ -123,9 +180,11 @@ export function useAdvancedProduction() {
|
||||
}
|
||||
}
|
||||
|
||||
/** 确认后校验参数快照并提交一次;冲突时观察现有任务。 */
|
||||
async function start() {
|
||||
if (
|
||||
blocked.value ||
|
||||
!!scopeError.value ||
|
||||
checking.value ||
|
||||
!check.value ||
|
||||
check.value.projectId !== id.value ||
|
||||
@@ -134,36 +193,49 @@ export function useAdvancedProduction() {
|
||||
return
|
||||
const projectId = id.value
|
||||
const target = getProductionSession(projectId)
|
||||
const confirmedInput = JSON.stringify(check.value.input)
|
||||
const confirmedVersion = version
|
||||
let submitted = false
|
||||
await runOperation(projectId, '高级串联生产', async () => {
|
||||
const result = await checkPipeline(projectId)
|
||||
const result = await checkPipeline(projectId, scope.value)
|
||||
if (
|
||||
confirmedVersion !== version ||
|
||||
disposed ||
|
||||
id.value !== projectId ||
|
||||
context.project.value?.status !== 'completed' ||
|
||||
context.error.value
|
||||
)
|
||||
return
|
||||
if (JSON.stringify(result.input) !== confirmedInput) {
|
||||
check.value = null
|
||||
throw new Error('项目模型或图片参数已变化,请重新预检并确认费用。')
|
||||
}
|
||||
check.value = result
|
||||
if (result.issues.length) throw new Error('提交前预检发现条件变化,未启动生产。请处理下方问题。')
|
||||
target.pipelineReceipt = null
|
||||
submitted = true
|
||||
const started = await productionApi.startPipeline(projectId, {
|
||||
...(result.profile
|
||||
? {
|
||||
imageProvider: result.profile.imageProvider,
|
||||
videoProvider: result.profile.videoProvider
|
||||
}
|
||||
: {}),
|
||||
...(safeMode.value
|
||||
? {
|
||||
stopAfter: 'videoPrompts' as const,
|
||||
...(testKeyframeLimit.value ? { keyframeLimit: testKeyframeLimit.value } : {})
|
||||
}
|
||||
: {})
|
||||
})
|
||||
let started
|
||||
try {
|
||||
started = await productionApi.startPipeline(projectId, result.input)
|
||||
} catch (cause) {
|
||||
if (
|
||||
cause instanceof ApiError &&
|
||||
cause.status === 409 &&
|
||||
cause.details &&
|
||||
typeof cause.details === 'object' &&
|
||||
'executionId' in cause.details &&
|
||||
typeof cause.details.executionId === 'string' &&
|
||||
cause.details.executionId
|
||||
) {
|
||||
if (!disposed && id.value === projectId)
|
||||
error.value = '已有任务:已附着当前生产后台任务,请等待其结束。'
|
||||
await execution.track(cause.details.executionId, projectId)
|
||||
return
|
||||
}
|
||||
throw cause
|
||||
}
|
||||
if (!started.executionId) throw new Error('后端未返回 Production executionId,请勿重复提交。')
|
||||
await execution.track(started.executionId)
|
||||
await execution.track(started.executionId, projectId)
|
||||
})
|
||||
if (!disposed && id.value === projectId) {
|
||||
if (submitted) check.value = null
|
||||
@@ -194,17 +266,48 @@ export function useAdvancedProduction() {
|
||||
blocked,
|
||||
safeMode,
|
||||
testKeyframeLimit,
|
||||
startFrom,
|
||||
stopAfter,
|
||||
stableIdentityAnchorLimit,
|
||||
subjectImageLimit,
|
||||
videoPromptLimit,
|
||||
scope,
|
||||
scopeError,
|
||||
preflight,
|
||||
start
|
||||
}
|
||||
}
|
||||
|
||||
/** WorkflowExecution.result 只在完成后转成串联生产回执,运行中绝不伪造完成状态。 */
|
||||
function targetPipelineReceipt(
|
||||
projectId: string,
|
||||
result: object,
|
||||
session: ReturnType<typeof getProductionSession>
|
||||
) {
|
||||
/**
|
||||
* 完成任务结果只在项目归属正确时保存为回执。
|
||||
* @param projectId 当前项目 ID
|
||||
* @param result 后端真实完成结果
|
||||
* @param session 当前项目回执容器
|
||||
*/
|
||||
function targetPipelineReceipt(projectId: string, result: object, session: ReturnType<typeof getProductionSession>) {
|
||||
if (!projectId || !('projectId' in result) || result.projectId !== projectId) return
|
||||
session.pipelineReceipt = result as import('./types').ProductionPipelineResult
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证后端阶段枚举、顺序和本轮生成上限。
|
||||
* @param input 本轮启动范围
|
||||
* @returns 可直接展示的阻断原因;空字符串表示有效
|
||||
*/
|
||||
export function validateProductionScope(input: ProductionStartInput): string {
|
||||
const stages: ProductionStage[] = ['subjectImages', 'keyframes', 'videoPrompts']
|
||||
if (
|
||||
(input.startFrom && !stages.includes(input.startFrom)) ||
|
||||
(input.stopAfter && !stages.includes(input.stopAfter))
|
||||
)
|
||||
return '请选择有效的生产阶段。'
|
||||
if (input.startFrom && input.stopAfter && stages.indexOf(input.startFrom) > stages.indexOf(input.stopAfter))
|
||||
return '结束阶段不能早于起始阶段。'
|
||||
if (
|
||||
[input.stableIdentityAnchorLimit, input.subjectImageLimit, input.keyframeLimit, input.videoPromptLimit].some(
|
||||
value => value !== undefined && (!Number.isInteger(value) || value <= 0)
|
||||
)
|
||||
)
|
||||
return '所有生成上限必须是大于 0 的整数。'
|
||||
return ''
|
||||
}
|
||||
Reference in new issue
Block a user