feat: 同步最新生图与身份能力

This commit is contained in:
GouJ committed 2026-09-22 19:56:12 +08:00
1 parent 65e8f9c3ba
commit be06caaa9f
18 files changed
+583 -69

No files matched your search

@@ -64,6 +64,7 @@ const {
save,
generate,
generateProject,
generateStableAnchors,
generateCastingCandidates,
generateImage,
generateCastingCandidate,
@@ -72,6 +73,7 @@ const {
} = useSubjectIdentity()
const search = ref('')
const module = ref('all')
const identityBatchModule = ref<'all' | 'character' | 'scene' | 'prop'>('all')
const imageOpen = ref(false)
const castingOpen = ref(false)
const pendingSelection = ref('')
@@ -301,6 +303,7 @@ const rules = { concurrency: integerRule('并发数'), candidateLimit: integerRu
blocked ||
!hasStyle ||
!batchValid ||
!candidateLimitValid ||
dirty ||
!casting.total
"
@@ -343,6 +346,46 @@ const rules = { concurrency: integerRule('并发数'), candidateLimit: integerRu
/></NButton>
</div>
</section>
<section class="panel mb-5 p-5" aria-label="场景与道具身份母版">
<div class="flex flex-wrap items-start justify-between gap-4">
<div>
<h3 class="text-sm font-semibold">场景与道具稳定母版</h3>
<p class="mt-2 text-xs leading-6 text-muted">
为已有身份提示词但缺少有效母版的场景或道具小批量生图。成功后后端会自动设为
Anchor 并锁定 Identity。
</p>
</div>
<div class="flex flex-wrap gap-3">
<ConfirmAction
label="生成场景母版"
:disabled="
blocked ||
!hasStyle ||
!batchValid ||
!candidateLimitValid ||
dirty ||
!subjects.length
"
acknowledgement
:description="`最多处理 ${candidateLimit} 个场景,生成成功后自动设为身份母版并锁定。可能产生图片模型费用。`"
@confirm="generateStableAnchors('scene')"
/>
<ConfirmAction
label="生成道具母版"
:disabled="
blocked ||
!hasStyle ||
!batchValid ||
dirty ||
!subjects.length
"
acknowledgement
:description="`最多处理 ${candidateLimit} 个道具,生成成功后自动设为身份母版并锁定。可能产生图片模型费用。`"
@confirm="generateStableAnchors('prop')"
/>
</div>
</div>
</section>
<NCollapse class="panel mb-5 p-5" :default-expanded-names="['details']"
><NCollapseItem name="details"
><template #header>高级:全部主体身份文本</template>
@@ -350,6 +393,16 @@ const rules = { concurrency: integerRule('并发数'), candidateLimit: integerRu
同时处理 Character、Scene 和
Prop;角色选角建议优先使用上方专用入口。已锁定身份始终跳过。
</p>
<NSelect
v-model:value="identityBatchModule"
class="mt-4 w-48"
aria-label="身份文本批处理范围"
:options="[
{ label: String('全部类型'), value: 'all' },
{ label: String('仅人物'), value: 'character' },
{ label: String('仅场景'), value: 'scene' },
{ label: String('仅道具'), value: 'prop' }
]" />
<ConfirmAction
class="mt-4"
:label="force ? '重生成全部未锁定身份' : '补齐全部主体身份文本'"
@@ -358,7 +411,17 @@ const rules = { concurrency: integerRule('并发数'), candidateLimit: integerRu
"
acknowledgement
description="生成全项目主体身份描述与提示词,不生成图片。覆盖不会自动更新旧身份图、形态图、首帧或视频。"
@confirm="generateProject(false)" /></NCollapseItem
@confirm="
identityBatchModule === 'character'
? generateProject(true)
: generateProject(
false,
identityBatchModule === 'scene' ||
identityBatchModule === 'prop'
? identityBatchModule
: undefined
)
" /></NCollapseItem
></NCollapse>
<section
v-if="session.receipt"
@@ -382,13 +445,25 @@ const rules = { concurrency: integerRule('并发数'), candidateLimit: integerRu
{{ session.receipt.result.skippedLocked }})· 失败
{{ session.receipt.result.failed }}
</p>
<p v-else class="mt-3 text-xs text-muted">
<p
v-else-if="session.receipt.kind === 'casting'"
class="mt-3 text-xs text-muted"
>
共 {{ session.receipt.result.totalCharacters }} 个角色 · 缺候选
{{ session.receipt.result.missingAnchor }} · 本批目标
{{ session.receipt.result.targetCount }} · 已生成
{{ session.receipt.result.generated }} · 失败
{{ session.receipt.result.failed }}
</p>
<p v-else class="mt-3 text-xs text-muted">
共 {{ session.receipt.result.total }} 个{{
session.receipt.result.module === 'scene' ? '场景' : '道具'
}}
· 符合条件 {{ session.receipt.result.eligibleCount }} · 本批目标
{{ session.receipt.result.targetCount }} · 已生成并锁定
{{ session.receipt.result.generated }} · 失败
{{ session.receipt.result.failed }}
</p>
<NAlert
v-if="session.receipt.result.failed"
role="alert"
+12 -1
View File
@@ -8,7 +8,9 @@ import type {
GenerateIdentityImageInput,
IdentityBatchResult,
IdentityImage,
IdentityModule,
SaveIdentityInput,
StableAnchorBatchResult,
SubjectIdentity
} from './types'
@@ -29,7 +31,7 @@ export const subjectIdentityApi = {
body: { force },
timeoutMs: 0
}),
generateProject: (projectId: string, input: { force: boolean; concurrency: number }) =>
generateProject: (projectId: string, input: { force: boolean; concurrency: number; module?: IdentityModule }) =>
request<IdentityBatchResult>(`/projects/${encodeURIComponent(projectId)}/subject-identities/generate`, {
method: 'POST',
body: input,
@@ -56,6 +58,15 @@ export const subjectIdentityApi = {
`/projects/${encodeURIComponent(projectId)}/character-casting/candidates/generate`,
{ method: 'POST', body: input, timeoutMs: 0 }
),
/** 为场景或道具生成稳定身份母版,并由后端原子设为 Anchor、锁定 Identity。 */
generateStableAnchors: (
projectId: string,
input: { module: 'scene' | 'prop'; limit: number; concurrency: number }
) =>
request<StableAnchorBatchResult>(
`/projects/${encodeURIComponent(projectId)}/subject-identities/anchors/generate`,
{ method: 'POST', body: input, timeoutMs: 0 }
),
listImages: (subjectId: string, signal?: AbortSignal) =>
request<IdentityImage[]>(`${identityPath(subjectId)}/images`, { signal }),
generateImage: (subjectId: string, input: GenerateIdentityImageInput) =>
+23
View File
@@ -67,6 +67,28 @@ export interface IdentityBatchResult {
failures: { subjectId: string; subjectRef: string; error: string }[]
}
export type IdentityModule = 'character' | 'scene' | 'prop'
export interface StableAnchorBatchResult {
module: 'scene' | 'prop'
total: number
eligibleCount: number
targetCount: number
generated: number
failed: number
failures: { subjectId: string; subjectRef: string; subjectName: string; error: string }[]
results: Array<{
subjectId: string
subjectRef: string
subjectName: string
success: boolean
imageId?: string
imageUrl?: string | null
identityLocked?: boolean
error?: string
}>
}
/** Character 的正式选角阶段状态。 */
export type CharacterCastingStatus = 'missing_identity' | 'missing_anchor' | 'candidate_pending' | 'unlocked' | 'ready'
@@ -144,3 +166,4 @@ export interface ConfirmCastingResult {
export type IdentityReceipt =
| { kind: 'identities'; title: string; result: IdentityBatchResult }
| { kind: 'casting'; title: string; result: CastingBatchResult }
| { kind: 'stable-anchors'; title: string; result: StableAnchorBatchResult }
@@ -1,5 +1,5 @@
import { computed, ref, watch } from 'vue'
import { useQuery } from '../../composables/useQuery'
import { usePolling } from '../../composables/usePolling'
import { visualStyleApi } from '../visual-style'
import { subjectImagesApi } from '../subject-images/api'
import { hasRunningImages } from '../subject-images/model'
@@ -30,42 +30,58 @@ export function useSubjectIdentity() {
const candidateLimit = ref(3)
const force = ref(false)
/** 目录与身份已有刷新按钮,查询只在进入、切换和手动刷新时读取。 */
const catalog = useQuery(projectId, async (id, signal) => {
const forms = await subjectImagesApi.listForms(id, signal)
if (
forms.some(
form => form.subject.projectId !== id || form.images.some(image => image.subjectFormId !== form.id)
const catalog = usePolling(
projectId,
async (id, signal) => {
const forms = await subjectImagesApi.listForms(id, signal)
if (
forms.some(
form => form.subject.projectId !== id || form.images.some(image => image.subjectFormId !== form.id)
)
)
)
throw new Error('主体目录与当前项目不匹配,请刷新后重试。')
return {
subjects: groupIdentitySubjects(forms),
running: forms.some(form => hasRunningImages(form.images))
}
})
const styleQuery = useQuery(projectId, async (id, signal) => {
const style = await visualStyleApi.get(id, signal)
if (style && style.projectId !== id) throw new Error('视觉风格与当前项目不匹配。')
return { style }
})
const castingQuery = useQuery(projectId, async (id, signal) => {
const readiness = await subjectIdentityApi.castingReadiness(id, signal)
return readiness
})
throw new Error('主体目录与当前项目不匹配,请刷新后重试。')
return {
subjects: groupIdentitySubjects(forms),
running: forms.some(form => hasRunningImages(form.images))
}
},
false
)
const styleQuery = usePolling(
projectId,
async (id, signal) => {
const style = await visualStyleApi.get(id, signal)
if (style && style.projectId !== id) throw new Error('视觉风格与当前项目不匹配。')
return { style }
},
false
)
const castingQuery = usePolling(
projectId,
async (id, signal) => {
const readiness = await subjectIdentityApi.castingReadiness(id, signal)
return readiness
},
false
)
const subjects = computed(() =>
mergeCastingSubjects(catalog.data.value?.subjects ?? [], castingQuery.data.value?.items ?? [], projectId.value)
)
const subject = computed(() => subjects.value.find(item => item.id === selectedId.value))
const selectionKey = computed(() => subject.value?.id ?? '')
const detail = useQuery(selectionKey, async (id, signal) => {
if (!id) return null
const identity = await subjectIdentityApi.get(id, signal)
if (!identity) return { identity: null, images: [] as IdentityImage[] }
assertIdentity(identity, id)
const images = await subjectIdentityApi.listImages(id, signal)
if (images.some(image => image.identityId !== identity.id)) throw new Error('身份图片与当前主体不匹配。')
return { identity, images }
})
const detail = usePolling(
selectionKey,
async (id, signal) => {
if (!id) return null
const identity = await subjectIdentityApi.get(id, signal)
if (!identity) return { identity: null, images: [] as IdentityImage[] }
assertIdentity(identity, id)
const images = await subjectIdentityApi.listImages(id, signal)
if (images.some(image => image.identityId !== identity.id)) throw new Error('身份图片与当前主体不匹配。')
return { identity, images }
},
false
)
const identity = computed(() => detail.data.value?.identity ?? null)
const images = computed(() => detail.data.value?.images ?? [])
const castingItem = computed(() =>
@@ -148,13 +164,17 @@ export function useSubjectIdentity() {
}
/** 批量仅生成身份文本,已锁定项由后端跳过,回执保留部分失败。 */
async function generateProject(charactersOnly = false) {
async function generateProject(charactersOnly = false, module?: 'scene' | 'prop') {
if (blocked.value || !hasStyle.value || !batchValid.value || dirty.value || !subjects.value.length) return
const id = projectId.value
const target = getIdentitySession(id)
const input = { concurrency: concurrency.value, force: force.value }
const input = { concurrency: concurrency.value, force: force.value, ...(module ? { module } : {}) }
target.receipt = null
const title = charactersOnly ? '批量生成角色身份文本' : '批量生成全部主体身份文本'
const title = charactersOnly
? '批量生成角色身份文本'
: module
? `批量生成${module === 'scene' ? '场景' : '道具'}身份文本`
: '批量生成全部主体身份文本'
await runOperation(id, title, async () => {
target.receipt = {
kind: 'identities',
@@ -167,6 +187,27 @@ export function useSubjectIdentity() {
await Promise.all([detail.refresh(), castingQuery.refresh()])
}
/** 场景/道具身份母版由后端独立生成、设为 Anchor 并锁定,保留逐主体失败回执。 */
async function generateStableAnchors(module: 'scene' | 'prop') {
if (blocked.value || !hasStyle.value || !batchValid.value || !candidateLimitValid.value || dirty.value) return
const id = projectId.value
const target = getIdentitySession(id)
const title = `批量生成${module === 'scene' ? '场景' : '道具'}身份母版`
target.receipt = null
await runOperation(id, title, async () => {
target.receipt = {
kind: 'stable-anchors',
title,
result: await subjectIdentityApi.generateStableAnchors(id, {
module,
limit: candidateLimit.value,
concurrency: concurrency.value
})
}
})
await Promise.all([catalog.refresh(), detail.refresh()])
}
/** 小批量只为 missing_anchor 的 Character 生成候选,不自动选择演员。 */
async function generateCastingCandidates() {
if (
@@ -309,6 +350,7 @@ export function useSubjectIdentity() {
save,
generate,
generateProject,
generateStableAnchors,
generateCastingCandidates,
generateImage,
generateCastingCandidate,