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
@@ -10,6 +10,9 @@ import { useProjectContext } from '../projects/context'
|
||||
import { subjectIdentityApi } from './api'
|
||||
import { canBeAnchor, getIdentitySession, groupIdentitySubjects, mergeCastingSubjects } from './model'
|
||||
import type {
|
||||
IdentityValidationResult,
|
||||
StableAnchorQualityInput,
|
||||
StableAnchorQualityResult,
|
||||
GenerateCastingCandidateInput,
|
||||
GenerateIdentityImageInput,
|
||||
IdentityImage,
|
||||
@@ -82,7 +85,9 @@ export function useSubjectIdentity() {
|
||||
)
|
||||
const subject = computed(() => subjects.value.find(item => item.id === selectedId.value))
|
||||
const selectionKey = computed(() => subject.value?.id ?? '')
|
||||
const detailRef = {} as { current?: ReturnType<typeof usePolling<{ identity: SubjectIdentity | null; images: IdentityImage[] }>> }
|
||||
const detailRef = {} as {
|
||||
current?: ReturnType<typeof usePolling<{ identity: SubjectIdentity | null; images: IdentityImage[] }>>
|
||||
}
|
||||
const detailPollInterval = computed(() =>
|
||||
detailRef.current?.data.value?.images.some(image => image.status === 'pending' || image.status === 'generating')
|
||||
? 4000
|
||||
@@ -163,6 +168,72 @@ export function useSubjectIdentity() {
|
||||
editorRevision.value++
|
||||
})
|
||||
|
||||
/** 校验结果以正式主体 ID 保存,切换主体不会串回执。 */
|
||||
const validationResults = ref<Record<string, IdentityValidationResult>>({})
|
||||
/** 质量闭环结果以正式主体 ID 保存。 */
|
||||
const qualityResults = ref<Record<string, StableAnchorQualityResult>>({})
|
||||
/** 当前主体的指定图片校验结果。 */
|
||||
const validationResult = computed(() => validationResults.value[selectedId.value] ?? null)
|
||||
/** 当前主体的质量闭环回执。 */
|
||||
const qualityResult = computed(() => qualityResults.value[selectedId.value] ?? null)
|
||||
/**
|
||||
* 校验当前主体的正式图片,费用确认由图库负责。
|
||||
* @param imageId 指定正式身份图片 ID
|
||||
*/
|
||||
async function validateImage(imageId: string) {
|
||||
const image = images.value.find(item => item.id === imageId)
|
||||
if (detailBlocked.value || !subject.value || image?.status !== 'completed' || !image.imageUrl) return
|
||||
const id = subject.value.id
|
||||
const project = projectId.value
|
||||
delete validationResults.value[id]
|
||||
await runOperation(project, '校验身份参考图质量', async () => {
|
||||
const result = await subjectIdentityApi.validateImage(id, imageId)
|
||||
if (result.subjectId !== id || result.imageId !== imageId) throw new Error('身份校验回执与提交目标不匹配')
|
||||
validationResults.value[id] = result
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 为场景或道具执行有限预算质量闭环,仅按真实回执确认锁定。
|
||||
* @param input 模型、参数和修复次数
|
||||
*/
|
||||
async function generateStableAnchorQuality(input: StableAnchorQualityInput) {
|
||||
if (
|
||||
!canGenerateImage.value ||
|
||||
!subject.value ||
|
||||
!identity.value ||
|
||||
!['scene', 'prop'].includes(subject.value.module)
|
||||
)
|
||||
return
|
||||
if (!Number.isInteger(input.maxRepairAttempts) || input.maxRepairAttempts < 0 || input.maxRepairAttempts > 3)
|
||||
return
|
||||
const id = subject.value.id
|
||||
const identityId = identity.value.id
|
||||
const project = projectId.value
|
||||
delete qualityResults.value[id]
|
||||
await runOperation(project, '生成稳定身份母版并校验质量', async () => {
|
||||
const result = await subjectIdentityApi.generateStableAnchorQuality(id, input)
|
||||
if (
|
||||
result.passed &&
|
||||
(!result.confirmed ||
|
||||
result.confirmed.subjectId !== id ||
|
||||
result.confirmed.identityId !== identityId ||
|
||||
!result.confirmed.isLocked ||
|
||||
!result.confirmed.anchor.isAnchor ||
|
||||
result.confirmed.anchor.id !== result.imageId)
|
||||
)
|
||||
throw new Error('质量生成的母版与锁定回执未确认,请刷新核对')
|
||||
qualityResults.value[id] = result
|
||||
})
|
||||
if (projectId.value === project) {
|
||||
await Promise.all([
|
||||
catalog.refresh(),
|
||||
castingQuery.refresh(),
|
||||
projectContext.refreshStageReadiness(),
|
||||
...(selectedId.value === id ? [detail.refresh()] : [])
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
/** 长请求跨主体切换后只更新原项目的操作回执,不用旧响应覆盖新主体。 */
|
||||
async function writeIdentity(label: string, action: (id: string) => Promise<SubjectIdentity>) {
|
||||
if (detailBlocked.value || !subject.value) return
|
||||
@@ -447,6 +518,10 @@ export function useSubjectIdentity() {
|
||||
generateCastingCandidate,
|
||||
setAnchor,
|
||||
confirmStableAnchor,
|
||||
confirmCasting
|
||||
confirmCasting,
|
||||
validateImage,
|
||||
generateStableAnchorQuality,
|
||||
validationResult,
|
||||
qualityResult
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user