fix(short-drama-agent-front): 完善素材准入与选角审核读取
This commit is contained in:
1 parent
75e86f7486
commit
3503926d62
13 files changed
+355
-42
No files matched your search
@@ -91,6 +91,8 @@ const {
|
||||
confirmStableAnchor,
|
||||
confirmCasting,
|
||||
validateImage,
|
||||
readSavedValidation,
|
||||
readingSavedReviewId,
|
||||
generateStableAnchorQuality,
|
||||
pendingImageOperation,
|
||||
validationResult
|
||||
@@ -994,6 +996,8 @@ function runNextAction() {
|
||||
"
|
||||
:pending-operation="pendingImageOperation"
|
||||
:validation-result="validationResult"
|
||||
:reading-saved-review-id="readingSavedReviewId"
|
||||
@read-review="readSavedValidation"
|
||||
:retry-disabled-reason="imageRetryDisabledReason"
|
||||
@validate="validateImage"
|
||||
@anchor="chooseAnchor"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { request } from '../../lib/http'
|
||||
import type {
|
||||
IdentityImagePreview,
|
||||
IdentityImageDetails,
|
||||
IdentityImageGenerationStart,
|
||||
IdentityValidationResult,
|
||||
StableAnchorQualityInput,
|
||||
@@ -74,6 +75,15 @@ export const subjectIdentityApi = {
|
||||
),
|
||||
listImages: (subjectId: string, signal?: AbortSignal) =>
|
||||
request<IdentityImage[]>(`${identityPath(subjectId)}/images`, { signal }),
|
||||
/**
|
||||
* 读取指定候选及已保存的审核记录。
|
||||
* @param subjectId 正式主体
|
||||
* @param imageId 当前候选
|
||||
* @param signal 取消过期查询
|
||||
* @returns 正式图片详情,不调用视觉模型
|
||||
*/
|
||||
imageDetails: (subjectId: string, imageId: string, signal?: AbortSignal) =>
|
||||
request<IdentityImageDetails>(`${identityPath(subjectId)}/images/${encodeURIComponent(imageId)}`, { signal }),
|
||||
generateImage: (subjectId: string, input: GenerateIdentityImageInput) =>
|
||||
request<IdentityImageGenerationStart>(`${identityPath(subjectId)}/images`, {
|
||||
method: 'POST',
|
||||
|
||||
@@ -24,6 +24,8 @@ const props = defineProps<{
|
||||
disabled: boolean
|
||||
/** 当前固定图片目标的确认或校验操作。 */
|
||||
pendingOperation?: IdentityImageOperation | null
|
||||
/** 当前正在读取历史审核的候选编号。 */
|
||||
readingSavedReviewId?: string
|
||||
/** 重新生成暂不可用的具体恢复步骤。 */
|
||||
retryDisabledReason?: string
|
||||
/** 本主体最近一次显式图片审核结果。 */
|
||||
@@ -35,6 +37,8 @@ const emit = defineEmits<{
|
||||
anchor: [imageId: string]
|
||||
/** 校验指定图片。 */
|
||||
validate: [imageId: string]
|
||||
/** 只读查看已保存的审核。 */
|
||||
readReview: [imageId: string]
|
||||
/** 打开失败图片对应类型的生成参数弹窗。 */
|
||||
regenerate: [imageId: string]
|
||||
}>()
|
||||
@@ -129,12 +133,14 @@ defineExpose({ openCandidates, closeCandidates })
|
||||
:identity-locked="identityLocked"
|
||||
:disabled="disabled"
|
||||
:pending-operation="pendingOperation"
|
||||
:reading-saved-review-id="readingSavedReviewId"
|
||||
:validation-result="validationResult"
|
||||
:retry-disabled-reason="retryDisabledReason"
|
||||
:active="true"
|
||||
:description="displayImage.isAnchor ? anchorDescription : undefined"
|
||||
@anchor="emit('anchor', $event)"
|
||||
@validate="emit('validate', $event)"
|
||||
@read-review="emit('readReview', $event)"
|
||||
@regenerate="regenerate"
|
||||
/>
|
||||
</div>
|
||||
@@ -171,11 +177,13 @@ defineExpose({ openCandidates, closeCandidates })
|
||||
:identity-locked="identityLocked"
|
||||
:disabled="disabled"
|
||||
:pending-operation="pendingOperation"
|
||||
:reading-saved-review-id="readingSavedReviewId"
|
||||
:validation-result="validationResult"
|
||||
:retry-disabled-reason="retryDisabledReason"
|
||||
:active="candidatesOpen"
|
||||
@anchor="emit('anchor', $event)"
|
||||
@validate="emit('validate', $event)"
|
||||
@read-review="emit('readReview', $event)"
|
||||
@regenerate="regenerate"
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -22,6 +22,8 @@ const props = defineProps<{
|
||||
disabled: boolean
|
||||
/** 当前固定目标的图片操作。 */
|
||||
pendingOperation?: IdentityImageOperation | null
|
||||
/** 当前正在读取历史审核的候选编号。 */
|
||||
readingSavedReviewId?: string
|
||||
/** 重新生成暂不可用的具体恢复步骤。 */
|
||||
retryDisabledReason?: string
|
||||
/** 当前母版的使用说明,候选卡片不展示。 */
|
||||
@@ -37,6 +39,8 @@ const emit = defineEmits<{
|
||||
anchor: [imageId: string]
|
||||
/** 校验指定图片。 */
|
||||
validate: [imageId: string]
|
||||
/** 只读查看已保存的审核。 */
|
||||
readReview: [imageId: string]
|
||||
/** 打开失败图片对应的生成参数弹窗。 */
|
||||
regenerate: [imageId: string]
|
||||
}>()
|
||||
@@ -235,6 +239,15 @@ function regenerate() {
|
||||
>
|
||||
{{ character ? '确认选角并锁定' : '设为身份母版' }}
|
||||
</NButton>
|
||||
<!-- 以下是角色候选的只读审核入口。 -->
|
||||
<NButton
|
||||
v-if="character && image.viewType === 'primary'"
|
||||
size="small"
|
||||
:loading="readingSavedReviewId === image.id"
|
||||
:disabled="readingSavedReviewId === image.id"
|
||||
@click="emit('readReview', image.id)"
|
||||
>查看已保存审核</NButton
|
||||
>
|
||||
<ConfirmAction
|
||||
:key="image.id"
|
||||
label="校验此身份图片"
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
import type { IdentityImage, IdentityImageDetails, IdentityValidationResult } from './types'
|
||||
|
||||
/**
|
||||
* 收敛未知元数据,避免访问错误类型的历史字段。
|
||||
* @param value 正式详情中的任意字段
|
||||
* @returns 可读取的记录
|
||||
*/
|
||||
function record(value: unknown): Record<string, unknown> {
|
||||
return value && typeof value === 'object' && !Array.isArray(value) ? (value as Record<string, unknown>) : {}
|
||||
}
|
||||
|
||||
/**
|
||||
* 只展示与当前候选、当次生成输入绑定的已保存审核。当前来源仍由正式确认接口复核。
|
||||
* @param detail 同一候选的只读详情
|
||||
* @param image 图库中当前候选
|
||||
* @param subjectId 当前正式主体
|
||||
* @returns 可展示的已保存审核结果
|
||||
*/
|
||||
export function savedIdentityValidation(
|
||||
detail: IdentityImageDetails,
|
||||
image: IdentityImage,
|
||||
subjectId: string
|
||||
): IdentityValidationResult {
|
||||
if (
|
||||
!detail ||
|
||||
detail.id !== image.id ||
|
||||
detail.identityId !== image.identityId ||
|
||||
detail.viewType !== 'primary' ||
|
||||
detail.status !== 'completed' ||
|
||||
detail.imageUrl !== image.imageUrl ||
|
||||
detail.updatedAt !== image.updatedAt
|
||||
)
|
||||
throw new Error('候选图片记录已变化,请刷新图库后重新查看审核。')
|
||||
|
||||
let metadata: Record<string, unknown>
|
||||
try {
|
||||
metadata = record(JSON.parse(detail.rawJson ?? '{}'))
|
||||
} catch {
|
||||
throw new Error('候选的审核记录无法读取。')
|
||||
}
|
||||
|
||||
const quality = record(metadata.qualityValidation)
|
||||
const validation = record(quality.validation)
|
||||
const fingerprint = record(metadata.providerInputSnapshot).fingerprint
|
||||
if (
|
||||
quality.imageId !== image.id ||
|
||||
validation.imageId !== image.id ||
|
||||
validation.subjectId !== subjectId ||
|
||||
validation.imageUrl !== image.imageUrl ||
|
||||
!quality.subjectFormId ||
|
||||
validation.subjectFormId !== quality.subjectFormId ||
|
||||
quality.sourceCurrent !== true ||
|
||||
!metadata.sourceFingerprint ||
|
||||
quality.generationSourceFingerprint !== metadata.sourceFingerprint ||
|
||||
typeof fingerprint !== 'string' ||
|
||||
!/^[a-f0-9]{64}$/i.test(fingerprint) ||
|
||||
metadata.providerInputFingerprint !== fingerprint ||
|
||||
quality.providerInputFingerprint !== fingerprint ||
|
||||
validation.providerInputFingerprint !== fingerprint ||
|
||||
typeof quality.passed !== 'boolean' ||
|
||||
typeof validation.passed !== 'boolean' ||
|
||||
typeof validation.summary !== 'string' ||
|
||||
!Array.isArray(validation.issues) ||
|
||||
(validation.characterCheckResults !== undefined && !Array.isArray(validation.characterCheckResults)) ||
|
||||
(validation.sourceVisualRequirementResults !== undefined &&
|
||||
!Array.isArray(validation.sourceVisualRequirementResults)) ||
|
||||
!Array.isArray(validation.sourceVisualRequirements) ||
|
||||
!validation.sourceVisualRequirements.every(item => Array.isArray(record(item).quantities))
|
||||
)
|
||||
throw new Error('此候选没有可核对的已保存审核,或审核与生成依据不一致。')
|
||||
|
||||
const rejected =
|
||||
['formConsistent', 'physicalStructureValid', 'spatialLayoutValid'].some(
|
||||
key => quality[key] !== undefined && quality[key] !== true
|
||||
) ||
|
||||
(Array.isArray(quality.issues) && quality.issues.some(issue => record(issue).severity === 'error'))
|
||||
return {
|
||||
...validation,
|
||||
passed: quality.passed && validation.passed && !rejected
|
||||
} as unknown as IdentityValidationResult
|
||||
}
|
||||
@@ -35,6 +35,15 @@ export interface IdentityImage {
|
||||
updatedAt: string
|
||||
}
|
||||
|
||||
/** 只读图片详情中核对候选和历史审核所需的字段。 */
|
||||
export interface IdentityImageDetails extends Pick<
|
||||
IdentityImage,
|
||||
'id' | 'identityId' | 'viewType' | 'status' | 'imageUrl' | 'updatedAt'
|
||||
> {
|
||||
/** 后端保存的生成与审核元数据,仅在数据层提取结构化证据。 */
|
||||
rawJson: string | null
|
||||
}
|
||||
|
||||
/** 普通身份生图接口的异步提交回执,图片记录位于 image 字段。 */
|
||||
export interface IdentityImageGenerationStart {
|
||||
/** 已持久化的后台任务编号。 */
|
||||
|
||||
@@ -2,6 +2,7 @@ import { ApiError } from '../../lib/http'
|
||||
import { imageValidationPassed } from '../subject-images/validation'
|
||||
import type { ImageGenerationSubmission } from '../subject-images/generation-preview'
|
||||
import { computed, ref, shallowRef, watch } from 'vue'
|
||||
import { useQuery } from '../../composables/useQuery'
|
||||
import { usePolling } from '../../composables/usePolling'
|
||||
import { visualStyleApi } from '../visual-style'
|
||||
import { useProjectGenerationRevision } from '../generation-config/context'
|
||||
@@ -12,6 +13,7 @@ import { batchResultNotice, getOperation, runOperation, type OperationNotice } f
|
||||
import { useProjectMutationGuard } from '../workflows/useProjectMutationGuard'
|
||||
import { useProjectContext } from '../projects/context'
|
||||
import { subjectIdentityApi } from './api'
|
||||
import { savedIdentityValidation } from './saved-validation'
|
||||
import { canBeAnchor, getIdentitySession, groupIdentitySubjects, mergeCastingSubjects } from './model'
|
||||
import type {
|
||||
IdentityImageOperation,
|
||||
@@ -214,16 +216,54 @@ export function useSubjectIdentity() {
|
||||
const validationSourceKey = computed(() =>
|
||||
JSON.stringify([projectId.value, selectedId.value, identity.value, images.value])
|
||||
)
|
||||
/** 仅在用户打开已保存审核时读取当前候选。 */
|
||||
const savedReviewImageId = ref('')
|
||||
/** 读取正式详情,并绑定当前候选与请求发出时的主体。 */
|
||||
const savedReview = useQuery(savedReviewImageId, async (imageId, signal) => {
|
||||
if (!imageId) return null
|
||||
const current = subject.value
|
||||
const image = images.value.find(item => item.id === imageId)
|
||||
if (current?.module !== 'character' || !image || !canBeAnchor(image)) return null
|
||||
const details = await subjectIdentityApi.imageDetails(current.id, imageId, signal)
|
||||
return savedIdentityValidation(details, image, current.id)
|
||||
})
|
||||
/** 单独标记读审核中的候选,不锁定抽屉关闭。 */
|
||||
const readingSavedReviewId = computed(() => (savedReview.loading.value ? savedReviewImageId.value : ''))
|
||||
|
||||
/**
|
||||
* 打开已保存的角色审核,不发起视觉校验。
|
||||
* @param imageId 用户选择的角色候选
|
||||
*/
|
||||
function readSavedValidation(imageId: string) {
|
||||
if (
|
||||
subject.value?.module !== 'character' ||
|
||||
!images.value.some(item => item.id === imageId && canBeAnchor(item))
|
||||
)
|
||||
return
|
||||
delete validationResults.value[selectedId.value]
|
||||
if (savedReviewImageId.value === imageId) void savedReview.refresh()
|
||||
else savedReviewImageId.value = imageId
|
||||
}
|
||||
|
||||
/** 来源变化或切换主体后清除旧审核展示,不能沿用历史通过。 */
|
||||
watch(
|
||||
validationSourceKey,
|
||||
() => {
|
||||
delete validationResults.value[selectedId.value]
|
||||
savedReviewImageId.value = ''
|
||||
},
|
||||
{ flush: 'sync' }
|
||||
)
|
||||
/** 当前主体的指定图片校验结果。 */
|
||||
const validationResult = computed(() => validationResults.value[selectedId.value] ?? null)
|
||||
const validationResult = computed(
|
||||
() =>
|
||||
validationResults.value[selectedId.value] ??
|
||||
(!savedReview.loading.value &&
|
||||
!savedReview.error.value &&
|
||||
savedReview.data.value?.imageId === savedReviewImageId.value
|
||||
? savedReview.data.value
|
||||
: null)
|
||||
)
|
||||
/** 当前主体的质量闭环回执。 */
|
||||
const qualityResult = computed(() => qualityResults.value[selectedId.value] ?? null)
|
||||
/** 固定图片请求目标,切换主体后不把旧请求的加载状态附在新图片上。 */
|
||||
@@ -284,6 +324,7 @@ export function useSubjectIdentity() {
|
||||
const name = subject.value.name
|
||||
const project = projectId.value
|
||||
const module = subject.value.module
|
||||
savedReviewImageId.value = ''
|
||||
delete validationResults.value[id]
|
||||
const sourceKey = validationSourceKey.value
|
||||
await runImageOperation(
|
||||
@@ -712,6 +753,7 @@ export function useSubjectIdentity() {
|
||||
{ type: 'success', content: `${name} 的角色选角已确认,身份已锁定。` }
|
||||
)
|
||||
if (!confirmed) {
|
||||
if (projectId.value === project && selectedId.value === subjectId) savedReviewImageId.value = ''
|
||||
delete validationResults.value[subjectId]
|
||||
await refreshImageConfirmation(project, subjectId)
|
||||
}
|
||||
@@ -762,6 +804,8 @@ export function useSubjectIdentity() {
|
||||
confirmStableAnchor,
|
||||
confirmCasting,
|
||||
validateImage,
|
||||
readSavedValidation,
|
||||
readingSavedReviewId,
|
||||
pendingImageOperation,
|
||||
generateStableAnchorQuality,
|
||||
validationResult,
|
||||
|
||||
Reference in new issue
Block a user