diff --git a/README.md b/README.md
index 1d6b3cb..88475c5 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# Short Drama Agent Front
-短剧 Agent 的前端工作台。支持剧本创作、拆解、视觉风格、主体身份、形态图片与分镜设计,使用真实后端 API,不包含演示数据或浏览器端模型调用。
+短剧 Agent 的前端工作台。支持剧本创作、拆解、视觉风格、角色选角、主体形态、分镜设计、镜头首帧与视频生产,使用真实后端 API,不包含演示数据或浏览器端模型调用。
## 启动
@@ -32,14 +32,16 @@ API_PROXY_TARGET=http://localhost:3412
| 拆解结果 | 主体、别名、视觉形态、Episode → Beat → Shot、主体绑定、抽取任务状态、校验问题、JSON 导出 |
| 拆解恢复 | 失败抽取重试、缺失剧集镜头补齐、分镜引用与 Form 绑定修复 |
| 视觉风格 | AI 生成、人工编辑、分类 Prompt、JSON 硬约束、锁定;风格参考图地址登记、启停和删除 |
-| 主体身份 | 按正式主体归并形态,单个/批量生成身份文本,人工编辑及锁定,部分失败诊断 |
-| 身份母版 | Seedream 生图、四种参考视角、指定身份参考图、母版候选与切换、实际 Prompt 和来源追溯 |
+| 主体身份 | 正式主体目录、单个/批量身份文本、人工编辑与锁定;无形态 Character 也可先完成身份 |
+| 角色选角 | 选角就绪检查、角色身份专用批量生成、Seedream 候选小批量生成、确认演员并原子锁定 Identity |
+| 身份母版 | 普通身份图与辅助视角、实际 Prompt 和来源追溯;Character 母版通过确认选角确定 |
| 分镜检查 | 按剧集、Beat、正式 Shot ID 浏览;导演设计、环境与主体即时状态;单集覆盖率与 JSON 导出 |
| 分镜生成 | Direction / VisualState 单集生成、项目批量补齐、覆盖重生成;并发和自动修复次数;部分失败诊断 |
| 镜头工具 | 主体参考图与缺失原因、确定性 GenerationSpec 查询与导出、单镜头/批量视频提示词 |
| 形态图片 | 正式形态图库、主图/候选图预览、图片历史与失败记录、Seedream 单图/批量生图、切换主参考图 |
+| 镜头生产 | Prompt/首帧/视频就绪诊断、Seedream 首帧候选、Seedance 任务、成片播放、主资产切换与失败重试 |
-尚未实现:手工编辑剧本或分镜设计(后端暂无对应写接口)、实际视频生成、用户登录。模型输出按纯文本显示,避免执行不可信 HTML。参考图只接受 HTTP(S) 或后端 `/storage/` 路径。
+尚未实现:手工编辑剧本或分镜设计(后端暂无对应写接口)、用户登录。模型输出按纯文本显示,避免执行不可信 HTML。图片和视频只接受 HTTP(S) 或后端 `/storage/` 路径。
## 技术与规范
@@ -72,6 +74,7 @@ Oxfmt 不负责代码质量,Oxlint 不负责 Vue 的完整类型推导;Vue S
| `src/features/subject-images` | 正式形态图库、图片生成参数、历史图片、主图选择与批量回执 |
| `src/features/visual-style` | 项目视觉风格 API、类型、编辑器、锁定和风格参考图管理 |
| `src/features/subject-identity` | 稳定身份 API、正式主体目录、文本编辑、生图配置、身份图库和母版切换 |
+| `src/features/production` | 视频提示词、镜头首帧、视频任务、就绪诊断、资产候选与批量回执 |
| `src/features/workflows` | checkpoint 选择、执行记录、长请求互斥与操作确认 |
| `src/components/ui` | 跨业务使用的 Reka UI 封装与公共展示组件 |
| `src/composables` | 具备取消和竞态保护的轮询 |
@@ -83,7 +86,7 @@ Oxfmt 不负责代码质量,Oxlint 不负责 Vue 的完整类型推导;Vue S
## 接口基线
对齐后端 `qianlanse/short-drama-agent` 的 `dev`:
-`059e59709359dccd08b08cb35c6aff95c5e03f2b`(2026-08-28),包含 VisualStyle、SubjectIdentity、身份母版、人物/场景形态自动引用母版及道具稳定特征提取。本轮只修改前端,请确保后端依照其开发流程同步了新 Prisma 结构并重启服务。
+`c50d3f536fbca40ea07d36e00bace7bb886fabfa`(2026-08-31),包含 Character Casting、身份/形态双参考首帧、首帧与视频生产就绪检查。本轮只修改前端,请确保后端依照其开发流程同步 Prisma migration 并重启服务。
| HTTP | 路径(以 /api 为前缀) | 用途 |
| --- | --- | --- |
@@ -120,8 +123,22 @@ Oxfmt 不负责代码质量,Oxlint 不负责 Vue 的完整类型推导;Vue S
| GET / PUT | `/subjects/:subjectId/identity` | 查询/人工编辑稳定身份;使用正式 Subject ID |
| POST | `/subjects/:subjectId/identity/generate` | AI 生成身份文本,需要项目视觉风格 |
| POST | `/projects/:id/subject-identities/generate` | 项目批量身份文本;`force`、`concurrency`,已锁定始终跳过 |
+| POST | `/projects/:id/character-identities/generate` | 只批量生成 Character Identity 文本 |
+| GET | `/projects/:id/character-casting/readiness` | 角色身份、候选、Anchor 与锁定状态汇总 |
+| POST | `/projects/:id/character-casting/candidates/generate` | 为缺少 Anchor 的角色小批量生成停用候选 |
| GET / POST | `/subjects/:subjectId/identity/images` | 查询带 `isAnchor` 的身份图片/Seedream 生图 |
+| POST | `/subjects/:subjectId/identity/casting-candidates` | 单角色生成 primary 选角候选,不自动成为 Anchor |
| PUT | `/subjects/:subjectId/identity/images/:imageId/anchor` | 将成功的 primary 候选设为身份母版 |
+| PUT | `/subjects/:subjectId/identity/images/:imageId/casting` | 确认 Character 选角:切换 Anchor 并锁定 Identity |
+| GET | `/projects/:id/video-prompts/readiness` | 项目视频提示词前置条件检查 |
+| GET / POST | `/projects/:id/keyframes/readiness`、`/keyframes/generate` | 首帧就绪检查与批量 Seedream 生图 |
+| GET / POST | `/storyboard-shots/:shotId/keyframes`、`/keyframe` | 单镜头首帧历史与生图 |
+| PUT | `/storyboard-shots/:shotId/keyframes/:keyframeId/primary` | 切换主首帧 |
+| GET / POST | `/projects/:id/videos/readiness`、`/videos/generate` | 视频前置检查与批量 Seedance 任务 |
+| GET | `/projects/:id/videos/status` | 项目最近视频任务状态 |
+| POST | `/projects/:id/videos/retry-failed` | 重试最近失败的视频任务 |
+| GET / POST | `/storyboard-shots/:shotId/videos` | 单镜头视频历史与任务创建 |
+| PUT | `/storyboard-shots/:shotId/videos/:videoId/primary` | 切换主视频 |
API 层也提供 `state` 与 `breakdown/latest` 方法。页面通过共享 checkpoint 查询取得阶段状态,避免重复拉取同样内容。
@@ -147,7 +164,7 @@ API 层也提供 `state` 与 `breakdown/latest` 方法。页面通过共享 chec
7. 上游重生成**不会自动使下游旧数据失效**。覆盖 Direction 后请重生成 VisualState,修改设计/状态/参考图后按需覆盖 Prompt。覆盖率只说明字段已保存,不能证明下游与新版本一致。
8. 每 6 秒查询当前剧集的两类正式结果;这不是全项目实时进度。后端没有独立 Storyboard running / executionId 查询。回执只保留当前浏览器会话,切换页面不丢失,刷新浏览器会丢失。
9. 参考图和 GenerationSpec 按需 GET,切换镜头或设计变化时取消旧查询。GenerationSpec 需要有效的 Direction、VisualState 和形态关联,不生成图片或视频。
-10. 后端当前的 Video Prompt 仍使用镜头描述和参考图,**尚未消费 GenerationSpec**。没有独立 GET Prompt 接口,“读取/生成提示词”仍是 POST;不存在 Prompt 时会调用模型,因此必须确认。`force: false` 复用已有正文;批量响应只有计数和失败列表,不能凭计数构造 Prompt 正文。`generated` 是后端处理成功数,可能包含已存在但状态不为 `prompt_ready` 的复用项。
+10. Video Prompt、Keyframe 与 Video 都有项目级 readiness。页面只向 `ready` 镜头批量提交;`force` 会重写 Prompt 或新增首帧/视频候选,但不会静默替换主首帧和主视频。视频任务创建成功不代表成片完成,最终状态以后端轮询和持久化资产为准。
### 形态图片约定
@@ -163,20 +180,21 @@ API 层也提供 `state` 与 `breakdown/latest` 方法。页面通过共享 chec
### 视觉风格、身份与形态的衔接
-建议操作顺序:**剧本创作 → 剧本拆解 → 视觉风格 → 主体身份 → 形态图片 → 分镜设计**。视觉风格也可以在拆解前准备;这不是前端强制启动的整条生产流程。
+建议操作顺序:**剧本创作 → 剧本拆解 → 视觉风格 → 角色身份与选角 → 形态图片 → 分镜设计 → 镜头生产**。视觉风格也可以在拆解前准备;页面不会自动重生成已存在的下游资产。
| 层级 | 职责 | 本次可操作内容 |
| --- | --- | --- |
| VisualStyle | 项目整体美术与视觉语言 | 整体/人物/场景/道具 Prompt、JSON 字符串数组硬约束、锁定、风格图片记录 |
| SubjectIdentity | 同一主体跨形态不变的特征 | 稳定身份描述、身份 Prompt、锁定、单个及批量 AI 文本生成 |
-| Identity Image | 固定主体身份,人物主要固定脸部与体型 | primary、front、three-quarter、full-body 四类生图、身份锚定来源、母版选择 |
+| Character Casting | 确认具体演员身份 | 候选图、人工选择 Anchor、Identity 原子锁定、项目就绪检查 |
+| Identity Image | 固定主体身份或补充辅助视角 | Scene / Prop 母版及 Character front、three-quarter、full-body 辅助图 |
| SubjectForm Image | 某个具体造型或状态的图片 | 原有单图/批量生图与主图选择;人物/场景图自动引用当前身份母版 |
-1. 风格与身份的 `isLocked` 只禁止 AI 自动覆盖文本。已锁定记录仍可人工编辑并保存;身份生图和母版切换也不受文字锁定限制。需要 AI 重生成时,先取消锁定并保存。
+1. 风格锁定仍用于阻止 AI 覆盖。Character 的 `isLocked` 同时是正式选角前置条件:必须具有 Identity、已确认的 primary Anchor 并锁定,Keyframe 才会就绪;确认选角接口会原子完成后两项。
2. 身份 AI 生成需要已创建 VisualStyle;身份图生成还需要已保存的非空 `generationPrompt`。不存在身份时不调用会报错的图片 GET。404 或网络失败不会被当作“尚未创建”。
-3. 后端暂无全项目主体/身份的 GET。前端从正式 `subject-forms` 目录按 `subjectId` 去重,选中主体后按需读取身份和专用图库;无形态主体暂不在目录展示。批量仍由后端处理项目全部主体,可能多于目录可见数,不受当前筛选影响。未使用 checkpoint 或 `DramaCharacter.id` 拼造 Subject ID。
-4. 身份文本批量回执显示 `total`、`targetCount`、`generated`、`skipped`、`skippedLocked`、`failed` 和逐主体失败原因。它不代表图片已生成,也不是实时任务进度。后端没有批量身份生图接口,前端不自行循环触发有费用的图片请求。
-5. 身份图片的 `isAnchor` 来自专用 GET。`enabled: true` 的正面、侧面或全身图不是母版;只有成功且有地址的 `primary` 图可经 PUT 设为母版。第一张 primary 图自动启用;已有母版后,新 primary 图作为停用候选保留,不静默替换。辅助视图不能直接选为母版,但可以作为新 primary 图的参考来源。
+3. 前端以正式 `subject-forms` 目录为基础,并合并 Character Casting readiness,因此尚无形态的角色也可先完成 Identity 和选角。Scene / Prop 若还没有 Form,仍不会凭 checkpoint 伪造正式 Subject ID。
+4. 身份文本批量分为 Character 专用入口和全部主体高级入口。选角候选批量只处理 `missing_anchor`,受本批上限控制;`candidate_pending` 必须人工确认,不会由批量任务静默决定演员。
+5. 身份图片的 `isAnchor` 来自专用 GET。Character primary 通过 Casting Candidate 接口生成且默认停用;点击确认演员后才成为 Anchor 并锁定 Identity。辅助视图不能直接成为母版。Scene / Prop 保留普通母版切换接口。
6. 身份生图不传 `referenceImageId` 时,由后端自动选择当前母版;无母版时按文本生成。指定时只能选择当前身份已完成的图片;候选图即使停用也可作为显式参考。后端没有“有母版但忽略它”的参数。尺寸成对留空或提供正整数。自定义 Prompt 会替换后端编译的完整文本,建议保留默认。
7. 目前**人物与场景形态生图**会自动注入当前身份母版,分别固定人物身份和空间骨架;道具暂不自动引用。没有身份或母版时,原形态生图流程仍可使用。已有母版但缺少 Provider 可访问远程地址时,后端会报错;本地 `/storage/` 能显示并不证明原始 Provider URL 仍可访问。前端显示后端错误,不自动重试消耗额度。
8. 修改风格、身份文本或母版,不会自动使旧图失效或重生成。已有形态主图仍会被分镜使用;需要保持新身份时,主动生成候选图并设为形态主图,再刷新分镜参考图,按需覆盖视频提示词。图库详情展示当次 `identityAnchorImageId` 或 `referenceImageId`;旧记录没有该字段时明确显示未知,不推断它使用了当前母版。
@@ -237,13 +255,14 @@ server {
5. 在可控测试项目中触发故障,确认 retry / resume-shots / resume-storyboard 各自对应正确失败阶段。
6. 进入分镜设计,确认正式镜头 ID 与 Beat 对应;先生成单集 Direction,再生成 VisualState,检查覆盖率和主体状态。
7. 用小型测试项目验证批量补齐、跳过完整集、失败诊断和明确覆盖;确认关闭覆盖后不会重生成完整设计。
-8. 给主体形态准备参考图,读取镜头参考图和 GenerationSpec;确认 Prompt 无正文时经确认生成、有正文且不覆盖时复用。不提交实际视频任务。
+8. 给主体形态准备参考图,读取镜头参考图和 GenerationSpec;在镜头生产页核对 Prompt、首帧和视频三类 readiness。
9. 打开“形态图片”,检查已有主图自动显示;单个形态新增候选图,查看历史、失败原因和实际 Prompt,再设为主图。
10. 在小型测试项目中验证批量补齐与“已有主图也新增候选图”;回到分镜刷新参考图,确认使用新选择的主图。
11. 进入“视觉风格”,保存或生成风格,检查分类 Prompt 和硬约束;锁定后 AI 入口禁用,人工编辑仍可保存。登记一张已有风格图,检查启停和移除确认。
-12. 进入“主体身份”,检查同一主体的多形态归并。生成/保存身份文本并锁定,再生成第一张 primary 图;生成第二张后,确认旧母版未被替换。
-13. 为同一主体选择参考来源并生成 front / three-quarter / full-body 图;确认辅助图不能直接设为母版。将第二张 primary 候选设为母版后,检查旧母版停用且保留。
+12. 进入“主体身份”,先补齐 Character Identity,再小批量生成选角候选。确认候选不会自动成为 Anchor,人工确认演员后 Identity 同时锁定且 readiness 变为 ready。
+13. 为已确认演员生成 front / three-quarter / full-body 辅助图;确认辅助图不能直接设为母版。角色需要更多演员候选时使用单角色候选入口。
14. 对人物和场景形态分别新增图片,在图片详情检查当次母版 ID;旧主图应保持不变,手动切换后再刷新分镜参考图。道具不应显示自动继承母版已生效。
+15. 在镜头生产页生成单镜头首帧,确认规格同时列出 `identity-anchor` 与 `form-primary`。切换主首帧后再创建 Seedance 任务,等待完成后播放并选择主视频。
本轮新增测试覆盖风格 JSON/锁定/图片 DELETE、身份归并/前置条件/尺寸/显式参考图/母版切换、部分失败、旧响应、草稿保护与费用确认。模型调用均使用模拟 API。当前执行环境未能通过浏览器访问本地开发服务,**未完成浏览器视觉验收及真实模型联调**,请按上述步骤在本地验收。
diff --git a/src/features/production/ProductionPage.vue b/src/features/production/ProductionPage.vue
index 45a4e77..6cecd27 100644
--- a/src/features/production/ProductionPage.vue
+++ b/src/features/production/ProductionPage.vue
@@ -75,6 +75,12 @@ const videoRunning = computed(
(query.data.value?.videoStatus.queued ?? 0) +
(query.data.value?.videoStatus.running ?? 0)
)
+const identityBlocked = computed(
+ () =>
+ (query.data.value?.keyframes.missingIdentity ?? 0) +
+ (query.data.value?.keyframes.missingIdentityAnchor ?? 0) +
+ (query.data.value?.keyframes.identityUnlocked ?? 0)
+)
/** 父页查询包含整个项目的就绪统计,单镜头变更后立即刷新。 */
function refreshProject() {
@@ -149,6 +155,11 @@ function refreshProject() {
当前有 {{ videoRunning }} 个视频任务等待或生成中。后端正在轮询 Provider;同一镜头不会重复提交活动任务。
+
+ 当前有 {{ identityBlocked }} 项角色身份前置问题。Character 必须生成
+ Identity、确认演员母版并锁定后,首帧才能就绪。
+ 前往角色选角 →
+
+ 身份缺失 {{ query.data.value?.keyframes.missingIdentity ?? 0 }} · 母版缺失
+ {{ query.data.value?.keyframes.missingIdentityAnchor ?? 0 }} · 未锁定
+ {{ query.data.value?.keyframes.identityUnlocked ?? 0 }}
+
首帧 Prompt · {{ keyframeSpec.references.length }} 张参考图
{{ keyframeSpec.prompt }}
+
+ -
+ {{ reference.subjectRef }} ·
+ {{ reference.role === 'identity-anchor' ? '演员身份母版' : '形态主图' }} ·
+
{{ reference.imageId }}
+
+
视频 Prompt · {{ videoSpec.durationSeconds }}s
diff --git a/src/features/production/model.ts b/src/features/production/model.ts
index 584ade4..16d34b7 100644
--- a/src/features/production/model.ts
+++ b/src/features/production/model.ts
@@ -43,6 +43,9 @@ export function issueLabel(code: ProductionIssueCode): string {
invalid_generation_spec: '生成规格不完整',
missing_visual_style: '缺少视觉风格',
missing_reference: '缺少主体参考图',
+ missing_identity: '缺少角色身份',
+ missing_identity_anchor: '缺少演员母版',
+ identity_unlocked: '演员身份未锁定',
missing_prompt: '缺少视频提示词',
missing_keyframe: '缺少主首帧'
}
diff --git a/src/features/production/production.test.ts b/src/features/production/production.test.ts
index 01b848f..e697c55 100644
--- a/src/features/production/production.test.ts
+++ b/src/features/production/production.test.ts
@@ -51,6 +51,8 @@ describe('镜头生产数据契约', () => {
it('就绪问题和异步任务状态提供中文标签', () => {
expect(issueLabel('missing_keyframe')).toBe('缺少主首帧')
expect(issueLabel('invalid_generation_spec')).toBe('生成规格不完整')
+ expect(issueLabel('missing_identity_anchor')).toBe('缺少演员母版')
+ expect(issueLabel('identity_unlocked')).toBe('演员身份未锁定')
expect(productionStatusLabel('in_progress')).toBe('任务进行中')
expect(productionStatusLabel('unknown')).toBe('unknown')
})
diff --git a/src/features/production/types.ts b/src/features/production/types.ts
index e06c5a9..b1e6e52 100644
--- a/src/features/production/types.ts
+++ b/src/features/production/types.ts
@@ -6,6 +6,9 @@ export type ProductionIssueCode =
| 'invalid_generation_spec'
| 'missing_visual_style'
| 'missing_reference'
+ | 'missing_identity'
+ | 'missing_identity_anchor'
+ | 'identity_unlocked'
| 'missing_prompt'
| 'missing_keyframe'
@@ -37,12 +40,17 @@ export interface PromptReadiness {
/** 镜头首帧就绪检查的逐镜结果。 */
export interface KeyframeReadinessItem extends PromptReadinessItem {
+ episodeNo: number
+ beatNo: number
primaryKeyframeId?: string | null
}
/** 镜头首帧项目级就绪汇总。 */
export interface KeyframeReadiness extends PromptReadiness {
missingVisualStyle: number
+ missingIdentity: number
+ missingIdentityAnchor: number
+ identityUnlocked: number
items: KeyframeReadinessItem[]
}
@@ -111,7 +119,8 @@ export interface KeyframeReference {
subjectId: string
subjectRef: string
module: string
- subjectFormId: string
+ role: 'identity-anchor' | 'form-primary'
+ subjectFormId?: string
imageId: string
imageUrl: string
providerImageUrl?: string
@@ -129,9 +138,16 @@ export interface KeyframeSpec {
}
/** 视频生成规格中的主体参考图。 */
-export interface VideoReference extends KeyframeReference {
+export interface VideoReference {
+ subjectId: string
+ subjectRef: string
subjectName: string
+ module: string
+ subjectFormId: string
subjectFormName: string
+ imageId: string
+ imageUrl: string
+ providerImageUrl?: string
}
/** 后端实际提交 Seedance 前编译的完整视频生成规格。 */
diff --git a/src/features/storyboard/components/ShotTools.vue b/src/features/storyboard/components/ShotTools.vue
index ba22d67..0bf249a 100644
--- a/src/features/storyboard/components/ShotTools.vue
+++ b/src/features/storyboard/components/ShotTools.vue
@@ -174,8 +174,8 @@ function exportResult(kind: 'spec' | 'prompt') {
- 后端合并主体、形态、摄影设计与即时状态,编译为 GenerationSpec,不调用模型。需要本镜头已有 Direction 和
- VisualState。
+ 后端合并主体稳定身份、具体形态、摄影设计与即时状态,编译为 GenerationSpec,不调用模型。需要本镜头已有
+ Direction 和 VisualState。
{{ errors.spec }}
视频提示词
- 已有提示词直接读取,没有则调用模型生成。当前后端仍使用镜头描述和参考图生成 Prompt,尚未接入上方
- GenerationSpec;此操作不会生成视频。
+ 已有提示词可直接复用,没有则依据 GenerationSpec 与参考图调用模型生成。此处只处理
+ Prompt;首帧和实际视频任务请到“镜头生产”。
import { computed, ref, watch } from 'vue'
import { useRoute } from 'vue-router'
-import { AssetImage, EmptyState } from '../../components/ui'
+import { UserCheck } from '@lucide/vue'
+import { AssetImage, EmptyState, StatusBadge } from '../../components/ui'
import { downloadText } from '../../lib/format'
import ConfirmAction from '../workflows/ConfirmAction.vue'
-import { currentAnchor } from './model'
+import { castingStatusLabel, currentAnchor } from './model'
import { useSubjectIdentity } from './useSubjectIdentity'
import IdentityEditor from './components/IdentityEditor.vue'
import IdentityGallery from './components/IdentityGallery.vue'
import IdentityImageDialog from './components/IdentityImageDialog.vue'
+import CastingCandidateDialog from './components/CastingCandidateDialog.vue'
/** 主体身份工作区按正式主体聚合,不把同一主体的多个 Form 当成不同身份。 */
const route = useRoute()
@@ -19,32 +21,46 @@ const {
subject,
subjects,
catalog,
+ castingQuery,
styleQuery,
detail,
identity,
images,
+ castingItem,
session,
concurrency,
+ candidateLimit,
force,
editorRevision,
dirty,
blocked,
+ castingBlocked,
detailBlocked,
hasStyle,
canGenerateText,
canGenerateImage,
+ canGenerateCandidate,
batchValid,
+ candidateLimitValid,
save,
generate,
generateProject,
+ generateCastingCandidates,
generateImage,
- setAnchor
+ generateCastingCandidate,
+ setAnchor,
+ confirmCasting
} = useSubjectIdentity()
const search = ref('')
const module = ref('all')
const imageOpen = ref(false)
+const castingOpen = ref(false)
const pendingSelection = ref('')
const anchor = computed(() => currentAnchor(images.value))
+const casting = computed(() => {
+ const value = castingQuery.data.value
+ return value && Array.isArray(value.items) ? value : null
+})
const filtered = computed(() =>
subjects.value.filter(
item =>
@@ -66,6 +82,7 @@ watch(
)
watch(selectedId, () => {
imageOpen.value = false
+ castingOpen.value = false
pendingSelection.value = ''
})
@@ -87,6 +104,17 @@ function discardAndSelect() {
function exportReceipt() {
downloadText('subject-identities-receipt.json', JSON.stringify(session.value.receipt, null, 2), 'application/json')
}
+
+/** 目录刷新同时读取正式形态和 Character Casting,避免无形态角色状态滞后。 */
+function refreshDirectory() {
+ void Promise.all([catalog.refresh(), castingQuery.refresh()])
+}
+
+/** Character 使用确认选角事务;Scene / Prop 保留普通母版切换。 */
+function chooseAnchor(imageId: string) {
+ if (subject.value?.module === 'character') void confirmCasting(imageId)
+ else void setAnchor(imageId)
+}
@@ -101,10 +129,16 @@ function exportReceipt() {
>
- 人物与场景形态图在有身份母版时自动引用,分别保持人物身份与空间结构;没有母版仍可按原逻辑生图。道具暂不自动引用。旧图不会因母版切换而自动更新。
+ Character 现在需要依次完成身份文本、选角候选、确认演员并锁定
+ Identity,之后首帧才能就绪。场景和道具仍使用普通身份母版流程;旧形态图、首帧与视频不会因母版切换自动更新。
-
- {{ catalog.error.value || styleQuery.error.value }} 当前操作已暂停,请刷新核对后端。
+
+ {{ catalog.error.value || styleQuery.error.value || castingQuery.error.value }}
+ 当前相关操作已暂停,请刷新核对后端。
先创建项目视觉风格,才能 AI 生成身份或身份图片。设置视觉风格 →
-
- 项目批量生成身份文本
-
-
@@ -238,11 +374,19 @@ function exportReceipt() {
description="调用文本模型生成稳定身份描述和提示词。旧图片不会自动重生成;已锁定身份需先解锁并保存。"
@confirm="generate"
/>
+ 生成选角候选
- 生成身份参考图
+ {{ subject.module === 'character' ? '生成辅助身份图' : '生成身份参考图' }}
请先保存身份修改,再使用 AI 或生成图片。
@@ -264,9 +408,13 @@ function exportReceipt() {
当前身份母版
{{
- subject.module === 'prop'
- ? '道具形态生图暂不自动引用此母版。'
- : '后续人物/场景形态图会继承此图的身份或空间结构。'
+ subject.module === 'character'
+ ? identity?.isLocked
+ ? '演员身份已确认并锁定,可用于形态图与镜头首帧。'
+ : '已有演员母版但 Identity 尚未锁定,镜头首帧仍会被阻塞。'
+ : subject.module === 'prop'
+ ? '道具形态生图暂不自动引用此母版。'
+ : '后续场景形态图会继承此图的空间结构。'
}}
@@ -275,8 +423,10 @@ function exportReceipt() {
:key="selectedId"
:images="images"
:subject-name="subject.name"
- :disabled="detailBlocked"
- @anchor="setAnchor"
+ :module="subject.module"
+ :identity-locked="!!identity?.isLocked"
+ :disabled="detailBlocked || (subject.module === 'character' && !!castingQuery.error.value)"
+ @anchor="chooseAnchor"
/>
@@ -286,6 +436,9 @@ function exportReceipt() {
>{{ form.name }}{{ form.isDefault ? ' · 默认' : '' }}
+
+ 此角色尚无正式形态,但可以先完成 Identity 与选角。
+
+
diff --git a/src/features/subject-identity/api.ts b/src/features/subject-identity/api.ts
index 0da3a18..0d76b0c 100644
--- a/src/features/subject-identity/api.ts
+++ b/src/features/subject-identity/api.ts
@@ -1,5 +1,10 @@
import { request } from '../../lib/http'
import type {
+ CastingBatchResult,
+ CharacterCastingReadiness,
+ ConfirmCastingResult,
+ GenerateCastingCandidateInput,
+ GenerateCastingCandidatesInput,
GenerateIdentityImageInput,
IdentityBatchResult,
IdentityImage,
@@ -30,6 +35,27 @@ export const subjectIdentityApi = {
body: input,
timeoutMs: 0
}),
+ generateCharacters: (projectId: string, input: { force: boolean; concurrency: number }) =>
+ request(`/projects/${encodeURIComponent(projectId)}/character-identities/generate`, {
+ method: 'POST',
+ body: input,
+ timeoutMs: 0
+ }),
+ castingReadiness: (projectId: string, signal?: AbortSignal) =>
+ request(`/projects/${encodeURIComponent(projectId)}/character-casting/readiness`, {
+ signal
+ }),
+ generateCastingCandidate: (subjectId: string, input: GenerateCastingCandidateInput) =>
+ request(`${identityPath(subjectId)}/casting-candidates`, {
+ method: 'POST',
+ body: input,
+ timeoutMs: 0
+ }),
+ generateCastingCandidates: (projectId: string, input: GenerateCastingCandidatesInput) =>
+ request(
+ `/projects/${encodeURIComponent(projectId)}/character-casting/candidates/generate`,
+ { method: 'POST', body: input, timeoutMs: 0 }
+ ),
listImages: (subjectId: string, signal?: AbortSignal) =>
request(`${identityPath(subjectId)}/images`, { signal }),
generateImage: (subjectId: string, input: GenerateIdentityImageInput) =>
@@ -37,5 +63,9 @@ export const subjectIdentityApi = {
setAnchor: (subjectId: string, imageId: string) =>
request(`${identityPath(subjectId)}/images/${encodeURIComponent(imageId)}/anchor`, {
method: 'PUT'
+ }),
+ confirmCasting: (subjectId: string, imageId: string) =>
+ request(`${identityPath(subjectId)}/images/${encodeURIComponent(imageId)}/casting`, {
+ method: 'PUT'
})
}
diff --git a/src/features/subject-identity/components/CastingCandidateDialog.vue b/src/features/subject-identity/components/CastingCandidateDialog.vue
new file mode 100644
index 0000000..2028a6f
--- /dev/null
+++ b/src/features/subject-identity/components/CastingCandidateDialog.vue
@@ -0,0 +1,84 @@
+
+
+
+
+
+
+
diff --git a/src/features/subject-identity/components/IdentityEditor.vue b/src/features/subject-identity/components/IdentityEditor.vue
index 0716863..126fb89 100644
--- a/src/features/subject-identity/components/IdentityEditor.vue
+++ b/src/features/subject-identity/components/IdentityEditor.vue
@@ -61,12 +61,11 @@ function save() {
这里保存身份事实;背景、视角和参考图约束由后端另行编译,不是最终整段生图 Prompt。
确认并锁定身份文本。锁定后仍可人工保存、生成图片及切换母版。{{
+ module === 'character'
+ ? '确认并锁定演员身份。Character 必须同时具有身份母版并锁定 Identity,首帧才能进入就绪状态。'
+ : '确认并锁定身份文本。锁定后仍可人工保存、生成图片及切换母版。'
+ }}
{{
diff --git a/src/features/subject-identity/components/IdentityGallery.vue b/src/features/subject-identity/components/IdentityGallery.vue
index 0bf980f..d3df53b 100644
--- a/src/features/subject-identity/components/IdentityGallery.vue
+++ b/src/features/subject-identity/components/IdentityGallery.vue
@@ -7,7 +7,13 @@ import { canBeAnchor, currentAnchor, identityViewLabels, readImageProvenance } f
import type { IdentityImage } from '../types'
/** 身份图库区分权威母版、primary 候选和辅助视图,保留后端原始状态。 */
-const props = defineProps<{ images: IdentityImage[]; subjectName: string; disabled: boolean }>()
+const props = defineProps<{
+ images: IdentityImage[]
+ subjectName: string
+ module: string
+ identityLocked: boolean
+ disabled: boolean
+}>()
const emit = defineEmits<{ anchor: [imageId: string] }>()
const selectedId = ref('')
const confirming = ref(false)
@@ -15,8 +21,13 @@ const anchor = computed(() => currentAnchor(props.images))
const selected = computed(
() => props.images.find(image => image.id === selectedId.value) ?? anchor.value ?? props.images[0]
)
+const character = computed(() => props.module === 'character')
const canSelect = computed(
- () => !props.disabled && !!selected.value && canBeAnchor(selected.value) && !selected.value.isAnchor
+ () =>
+ !props.disabled &&
+ !!selected.value &&
+ canBeAnchor(selected.value) &&
+ (!selected.value.isAnchor || (character.value && !props.identityLocked))
)
const imageUrl = computed(() => referenceImageUrl(selected.value?.imageUrl ?? ''))
watch(
@@ -76,12 +87,12 @@ function chooseAnchor() {
{{ selected.error }}
- 设为身份母版{{ selected.provider }} · {{ selected.model }} · {{ formatDate(selected.createdAt) }}
@@ -91,12 +102,15 @@ function chooseAnchor() {
- 确认切换身份母版?旧 primary
- 母版将停用并保留。后续人物/场景形态生图会引用新母版,道具暂不自动引用。此操作不调用模型。
+ {{
+ character
+ ? '确认选择这张图片作为正式演员?后端会在同一事务中切换身份母版并锁定 Identity,完成后首帧才具备稳定人物身份。'
+ : '确认切换身份母版?旧 primary 母版将停用并保留。后续场景形态生图会引用新母版。此操作不调用模型。'
+ }}
- 确认切换身份母版取消
diff --git a/src/features/subject-identity/components/IdentityImageDialog.vue b/src/features/subject-identity/components/IdentityImageDialog.vue
index 63968b6..f5dd2ca 100644
--- a/src/features/subject-identity/components/IdentityImageDialog.vue
+++ b/src/features/subject-identity/components/IdentityImageDialog.vue
@@ -6,7 +6,13 @@ import { currentAnchor, identityViewLabels } from '../model'
import type { GenerateIdentityImageInput, IdentityImage, IdentityViewType } from '../types'
/** 身份图生成配置;默认自动引用母版,不提供后端不存在的“忽略母版”开关。 */
-const props = defineProps<{ subjectId: string; subjectName: string; images: IdentityImage[]; disabled: boolean }>()
+const props = defineProps<{
+ subjectId: string
+ subjectName: string
+ module?: string
+ images: IdentityImage[]
+ disabled: boolean
+}>()
const open = defineModel
('open', { default: false })
const emit = defineEmits<{ generate: [input: GenerateIdentityImageInput] }>()
const viewType = ref('primary')
@@ -16,6 +22,9 @@ const width = ref('')
const height = ref('')
const acknowledged = ref(false)
const anchor = computed(() => currentAnchor(props.images))
+const allowedViews = computed(() =>
+ Object.entries(identityViewLabels).filter(([value]) => props.module !== 'character' || value !== 'primary')
+)
const references = computed(() => props.images.filter(image => image.status === 'completed' && image.imageUrl))
const valid = computed(
() =>
@@ -25,13 +34,14 @@ const valid = computed(
watch(
() => [open.value, props.subjectId],
() => {
- viewType.value = 'primary'
+ viewType.value = props.module === 'character' ? 'front' : 'primary'
referenceImageId.value = ''
prompt.value = ''
width.value = ''
height.value = ''
acknowledged.value = false
- }
+ },
+ { immediate: true }
)
/** 提交显式的 Seedream 参数;省略空参考 ID 以保留后端自动选择逻辑。 */
@@ -58,7 +68,7 @@ function submit() {
参考视角 {
wrapper?.unmount()
wrapper = undefined
document.body.innerHTML = ''
+ vi.unstubAllGlobals()
})
/** 从真实 Reka Portal 内获取确认按钮。 */
@@ -48,6 +58,29 @@ describe('身份图与母版契约', () => {
})
})
+ it('选角就绪结果可以补入尚无形态的角色目录', () => {
+ const rows = mergeCastingSubjects(
+ groupIdentitySubjects([formFixture()]),
+ [
+ {
+ subjectId: 'character-without-form',
+ subjectRef: '@CH0002',
+ subjectName: '陆川',
+ status: 'missing_identity',
+ isLocked: false
+ }
+ ],
+ 'project-1'
+ )
+ expect(rows).toHaveLength(2)
+ expect(rows.find(item => item.id === 'character-without-form')).toMatchObject({
+ projectId: 'project-1',
+ module: 'character',
+ forms: []
+ })
+ expect(castingStatusLabel('candidate_pending')).toBe('等待确认演员')
+ })
+
it('辅助视角传递明确参考图、成对尺寸和本次 Prompt,不传形态生图字段', async () => {
wrapper = mount(IdentityImageDialog, {
attachTo: document.body,
@@ -107,18 +140,97 @@ describe('身份图与母版契约', () => {
expect(document.querySelector('#identity-image-cost')!.checked).toBe(false)
})
+ it('Character 普通身份图入口只提供辅助视角,primary 必须走选角候选接口', async () => {
+ wrapper = mount(IdentityImageDialog, {
+ attachTo: document.body,
+ props: {
+ open: true,
+ subjectId: 's1',
+ subjectName: '林夏',
+ module: 'character',
+ images: [identityImageFixture()],
+ disabled: false
+ }
+ })
+ await flushPromises()
+ const options = [...document.querySelectorAll('#identity-view option')]
+ expect(options.map(item => item.value)).toEqual(['front', 'three-quarter', 'full-body'])
+ expect(document.querySelector('#identity-view')!.value).toBe('front')
+ })
+
it('辅助图不能切换母版,提示词按纯文本展示', async () => {
wrapper = mount(IdentityGallery, {
attachTo: document.body,
props: {
subjectName: '林夏',
+ module: 'character',
+ identityLocked: false,
disabled: false,
images: [identityImageFixture({ viewType: 'front', isAnchor: false })]
}
})
- expect(button('设为身份母版').disabled).toBe(true)
+ expect(button('确认选角并锁定').disabled).toBe(true)
expect(wrapper.text()).toContain('')
expect(wrapper.find('script').exists()).toBe(false)
expect(wrapper.emitted('anchor')).toBeUndefined()
})
+
+ it('角色已有母版但未锁定时仍可确认选角,确认文案不冒充普通母版切换', async () => {
+ wrapper = mount(IdentityGallery, {
+ attachTo: document.body,
+ props: {
+ subjectName: '林夏',
+ module: 'character',
+ identityLocked: false,
+ disabled: false,
+ images: [identityImageFixture({ isAnchor: true })]
+ }
+ })
+ button('确认选角并锁定').click()
+ await flushPromises()
+ expect(document.body.textContent).toContain('同一事务中切换身份母版并锁定 Identity')
+ button('确认演员选择').click()
+ expect(wrapper.emitted('anchor')).toEqual([['identity-image-1']])
+ })
+
+ it('选角候选固定发送 Seedream,不携带普通身份图视角字段', async () => {
+ wrapper = mount(CastingCandidateDialog, {
+ attachTo: document.body,
+ props: { open: true, subjectId: 'subject-1', subjectName: '林夏', disabled: false }
+ })
+ await flushPromises()
+ document.querySelector('#casting-candidate-cost')!.click()
+ await flushPromises()
+ button('确认生成候选').click()
+ expect(wrapper.emitted('generate')).toEqual([[{ provider: 'seedream' }]])
+ })
+
+ it('角色选角接口区分批量身份、候选生图与确认事务', async () => {
+ const fetcher = vi.fn().mockImplementation(
+ async () =>
+ new Response(
+ JSON.stringify({
+ data: {
+ total: 0,
+ targetCount: 0,
+ generated: 0,
+ skipped: 0,
+ skippedLocked: 0,
+ failed: 0,
+ failures: []
+ }
+ })
+ )
+ )
+ vi.stubGlobal('fetch', fetcher)
+ await subjectIdentityApi.generateCharacters('project/1', { force: false, concurrency: 2 })
+ await subjectIdentityApi.generateCastingCandidate('subject/1', { provider: 'seedream' })
+ await subjectIdentityApi.confirmCasting('subject/1', 'image/1')
+ expect(fetcher.mock.calls.map(([url]) => url)).toEqual([
+ '/api/projects/project%2F1/character-identities/generate',
+ '/api/subjects/subject%2F1/identity/casting-candidates',
+ '/api/subjects/subject%2F1/identity/images/image%2F1/casting'
+ ])
+ expect(fetcher.mock.calls.map(([, init]) => init?.method)).toEqual(['POST', 'POST', 'PUT'])
+ })
})
diff --git a/src/features/subject-identity/model.ts b/src/features/subject-identity/model.ts
index f39eb6b..47a05b3 100644
--- a/src/features/subject-identity/model.ts
+++ b/src/features/subject-identity/model.ts
@@ -1,6 +1,12 @@
import { reactive } from 'vue'
import type { SubjectFormAsset } from '../subject-images/types'
-import type { IdentityBatchResult, IdentityImage, IdentitySubject } from './types'
+import type {
+ CharacterCastingItem,
+ CharacterCastingStatus,
+ IdentityImage,
+ IdentityReceipt,
+ IdentitySubject
+} from './types'
/** 视角名称保持与后端四种固定值对应。 */
export const identityViewLabels = {
@@ -22,6 +28,40 @@ export function groupIdentitySubjects(forms: SubjectFormAsset[]): IdentitySubjec
return [...subjects.values()]
}
+/** 将选角就绪接口中的无形态 Character 补入主体目录,确保选角早于 Form 生图也可操作。 */
+export function mergeCastingSubjects(
+ subjects: IdentitySubject[],
+ casting: CharacterCastingItem[],
+ projectId: string
+): IdentitySubject[] {
+ const rows = new Map(subjects.map(subject => [subject.id, subject]))
+ for (const item of casting) {
+ if (!rows.has(item.subjectId)) {
+ rows.set(item.subjectId, {
+ id: item.subjectId,
+ projectId,
+ ref: item.subjectRef,
+ name: item.subjectName,
+ module: 'character',
+ forms: []
+ })
+ }
+ }
+ return [...rows.values()].toSorted((a, b) => a.ref.localeCompare(b.ref))
+}
+
+/** 角色选角状态中文标签。 */
+export function castingStatusLabel(status: CharacterCastingStatus): string {
+ const labels: Record = {
+ missing_identity: '缺少身份文本',
+ missing_anchor: '缺少候选图',
+ candidate_pending: '等待确认演员',
+ unlocked: '演员尚未锁定',
+ ready: '选角已完成'
+ }
+ return labels[status]
+}
+
/** 只有成功且有图片的 primary 候选可成为母版;停用候选也允许重新启用。 */
export function canBeAnchor(image: IdentityImage): boolean {
return image.viewType === 'primary' && image.status === 'completed' && !!image.imageUrl
@@ -52,9 +92,9 @@ export function readImageProvenance(rawJson?: string | null): {
}
/** 批量回执按项目保存在当前会话,切页不丢失,刷新浏览器后不伪造恢复。 */
-const sessions = reactive>({})
+const sessions = reactive>({})
-/** 取得指定项目的身份文本批量回执。 */
+/** 取得指定项目的身份文本或选角候选批量回执。 */
export function getIdentitySession(projectId: string) {
return (sessions[projectId] ??= { receipt: null })
}
diff --git a/src/features/subject-identity/types.ts b/src/features/subject-identity/types.ts
index 3b2a7ce..54ab446 100644
--- a/src/features/subject-identity/types.ts
+++ b/src/features/subject-identity/types.ts
@@ -36,12 +36,12 @@ export interface SubjectIdentity {
updatedAt: string
}
-/** 从正式形态目录归并主体,不使用 checkpoint 的候选 ID。 */
+/** 从正式形态与 Character Casting 归并主体,不使用 checkpoint 的候选 ID。 */
export type IdentitySubject = SubjectFormAsset['subject'] & {
forms: SubjectFormAsset[]
}
-/** 人工保存身份;锁定只保护 AI 文本重生成,不限制人工保存或生图。 */
+/** 人工保存身份;Character 锁定同时是确认演员后的首帧前置条件。 */
export type SaveIdentityInput = Partial>
/** 单张身份生图;空 referenceImageId 应省略,由后端自动引用当前母版。 */
@@ -54,6 +54,14 @@ export interface GenerateIdentityImageInput {
height?: number
}
+/** Character 选角候选固定生成 primary,且不会自动成为 Anchor。 */
+export interface GenerateCastingCandidateInput {
+ provider: 'seedream'
+ prompt?: string
+ width?: number
+ height?: number
+}
+
/** 身份文本批量生成回执,不代表已生成参考图。 */
export interface IdentityBatchResult {
total: number
@@ -64,3 +72,80 @@ export interface IdentityBatchResult {
failed: number
failures: { subjectId: string; subjectRef: string; error: string }[]
}
+
+/** Character 的正式选角阶段状态。 */
+export type CharacterCastingStatus = 'missing_identity' | 'missing_anchor' | 'candidate_pending' | 'unlocked' | 'ready'
+
+/** 就绪接口返回的轻量候选图。 */
+export interface CastingCandidateImage {
+ id: string
+ imageUrl: string
+ createdAt: string
+}
+
+/** 单个 Character 的选角就绪记录。 */
+export interface CharacterCastingItem {
+ subjectId: string
+ subjectRef: string
+ subjectName: string
+ status: CharacterCastingStatus
+ identityId?: string
+ anchorImageId?: string
+ anchorImageUrl?: string
+ candidateImages?: CastingCandidateImage[]
+ isLocked: boolean
+}
+
+/** 项目角色选角汇总;locked 与 ready 语义不同,锁定但无 Anchor 仍不可生产首帧。 */
+export interface CharacterCastingReadiness {
+ total: number
+ ready: number
+ missingIdentity: number
+ missingAnchor: number
+ candidatePending: number
+ unlocked: number
+ locked: number
+ items: CharacterCastingItem[]
+}
+
+/** 小批量生成选角候选的配置。 */
+export interface GenerateCastingCandidatesInput {
+ provider: 'seedream'
+ limit: number
+ concurrency: number
+ width?: number
+ height?: number
+}
+
+/** 选角候选批量结果中的逐主体记录。 */
+export interface CastingCandidateResult {
+ subjectId: string
+ subjectRef: string
+ subjectName: string
+ success: boolean
+ imageId?: string
+ imageUrl?: string | null
+ error?: string
+}
+
+/** 小批量选角候选生图回执。 */
+export interface CastingBatchResult {
+ totalCharacters: number
+ missingAnchor: number
+ targetCount: number
+ generated: number
+ failed: number
+ failures: { subjectId: string; subjectRef: string; subjectName: string; error: string }[]
+ results: CastingCandidateResult[]
+}
+
+/** 确认选角会在同一事务中切换 Anchor 并锁定 Identity。 */
+export interface ConfirmCastingResult {
+ identity: Omit
+ anchor: IdentityImage
+}
+
+/** 主体身份页的批量操作回执。 */
+export type IdentityReceipt =
+ | { kind: 'identities'; title: string; result: IdentityBatchResult }
+ | { kind: 'casting'; title: string; result: CastingBatchResult }
diff --git a/src/features/subject-identity/useSubjectIdentity.ts b/src/features/subject-identity/useSubjectIdentity.ts
index 7b67ac9..d7388cd 100644
--- a/src/features/subject-identity/useSubjectIdentity.ts
+++ b/src/features/subject-identity/useSubjectIdentity.ts
@@ -6,8 +6,14 @@ import { hasRunningImages } from '../subject-images/model'
import { runOperation } from '../workflows/operations'
import { useProjectMutationGuard } from '../workflows/useProjectMutationGuard'
import { subjectIdentityApi } from './api'
-import { canBeAnchor, getIdentitySession, groupIdentitySubjects } from './model'
-import type { GenerateIdentityImageInput, IdentityImage, SaveIdentityInput, SubjectIdentity } from './types'
+import { canBeAnchor, getIdentitySession, groupIdentitySubjects, mergeCastingSubjects } from './model'
+import type {
+ GenerateCastingCandidateInput,
+ GenerateIdentityImageInput,
+ IdentityImage,
+ SaveIdentityInput,
+ SubjectIdentity
+} from './types'
/** 单主体保存响应必须与提交时固定的正式 ID 一致。 */
function assertIdentity(value: SubjectIdentity, id: string) {
@@ -22,6 +28,7 @@ export function useSubjectIdentity() {
const editorRevision = ref(0)
const dirty = ref(false)
const concurrency = ref(3)
+ const candidateLimit = ref(3)
const force = ref(false)
const catalog = usePolling(projectId, async (id, signal) => {
const forms = await subjectImagesApi.listForms(id, signal)
@@ -38,7 +45,13 @@ export function useSubjectIdentity() {
if (style && style.projectId !== id) throw new Error('视觉风格与当前项目不匹配。')
return { style }
})
- const subjects = computed(() => catalog.data.value?.subjects ?? [])
+ const castingQuery = usePolling(projectId, async (id, signal) => {
+ const readiness = await subjectIdentityApi.castingReadiness(id, signal)
+ return readiness
+ })
+ 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 = usePolling(selectionKey, async (id, signal) => {
@@ -52,6 +65,9 @@ export function useSubjectIdentity() {
})
const identity = computed(() => detail.data.value?.identity ?? null)
const images = computed(() => detail.data.value?.images ?? [])
+ const castingItem = computed(() =>
+ castingQuery.data.value?.items?.find(item => item.subjectId === subject.value?.id)
+ )
const session = computed(() => getIdentitySession(projectId.value))
const blocked = computed(
() =>
@@ -77,7 +93,18 @@ export function useSubjectIdentity() {
const canGenerateImage = computed(
() => !detailBlocked.value && hasStyle.value && !!identity.value?.generationPrompt?.trim() && !dirty.value
)
+ const canGenerateCandidate = computed(
+ () =>
+ canGenerateImage.value &&
+ subject.value?.module === 'character' &&
+ !!castingQuery.data.value &&
+ !castingQuery.error.value
+ )
const batchValid = computed(() => Number.isSafeInteger(concurrency.value) && concurrency.value > 0)
+ const candidateLimitValid = computed(() => Number.isSafeInteger(candidateLimit.value) && candidateLimit.value > 0)
+ const castingBlocked = computed(
+ () => blocked.value || !!castingQuery.error.value || !castingQuery.data.value || dirty.value
+ )
watch(subjects, rows => {
if (!rows.some(item => item.id === selectedId.value)) selectedId.value = rows[0]?.id ?? ''
@@ -102,7 +129,7 @@ export function useSubjectIdentity() {
dirty.value = false
}
})
- if (ok) await detail.refresh()
+ if (ok) await Promise.all([detail.refresh(), castingQuery.refresh()])
}
/** 人工保存可修改已锁定身份;锁定只阻止自动重生成。 */
@@ -118,16 +145,51 @@ export function useSubjectIdentity() {
}
/** 批量仅生成身份文本,已锁定项由后端跳过,回执保留部分失败。 */
- async function generateProject() {
+ async function generateProject(charactersOnly = false) {
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 }
target.receipt = null
- await runOperation(id, '批量生成主体身份文本', async () => {
- target.receipt = await subjectIdentityApi.generateProject(id, input)
+ const title = charactersOnly ? '批量生成角色身份文本' : '批量生成全部主体身份文本'
+ await runOperation(id, title, async () => {
+ target.receipt = {
+ kind: 'identities',
+ title,
+ result: charactersOnly
+ ? await subjectIdentityApi.generateCharacters(id, input)
+ : await subjectIdentityApi.generateProject(id, input)
+ }
})
- await detail.refresh()
+ await Promise.all([detail.refresh(), castingQuery.refresh()])
+ }
+
+ /** 小批量只为 missing_anchor 的 Character 生成候选,不自动选择演员。 */
+ async function generateCastingCandidates() {
+ if (
+ castingBlocked.value ||
+ !hasStyle.value ||
+ !batchValid.value ||
+ !candidateLimitValid.value ||
+ !castingQuery.data.value?.missingAnchor
+ )
+ return
+ const id = projectId.value
+ const target = getIdentitySession(id)
+ const title = '批量生成角色选角候选'
+ target.receipt = null
+ await runOperation(id, title, async () => {
+ target.receipt = {
+ kind: 'casting',
+ title,
+ result: await subjectIdentityApi.generateCastingCandidates(id, {
+ provider: 'seedream',
+ limit: candidateLimit.value,
+ concurrency: concurrency.value
+ })
+ }
+ })
+ await Promise.all([detail.refresh(), castingQuery.refresh()])
}
/** 生图不修改文字锁定;即使有自定义 Prompt,也需已有身份 Prompt 与项目风格。 */
@@ -150,6 +212,19 @@ export function useSubjectIdentity() {
await detail.refresh()
}
+ /** 单角色候选图固定为 primary,生成成功后仍需人工确认选角。 */
+ async function generateCastingCandidate(input: GenerateCastingCandidateInput) {
+ if (!canGenerateCandidate.value || !subject.value || !identity.value) return
+ const id = subject.value.id
+ const identityId = identity.value.id
+ await runOperation(projectId.value, `生成 ${subject.value.name} 选角候选`, async () => {
+ const image = await subjectIdentityApi.generateCastingCandidate(id, input)
+ if (!image || image.identityId !== identityId || image.status !== 'completed' || !image.imageUrl)
+ throw new Error(image?.error || '后端未返回已完成的选角候选,请刷新核对。')
+ })
+ await Promise.all([detail.refresh(), castingQuery.refresh()])
+ }
+
/** 候选切换母版只允许成功的 primary 图,不能将辅助视角直接升级为母版。 */
async function setAnchor(imageId: string) {
const image = images.value.find(item => item.id === imageId)
@@ -170,6 +245,34 @@ export function useSubjectIdentity() {
await detail.refresh()
}
+ /** Character 确认选角必须原子切换 Anchor 并锁定 Identity。 */
+ async function confirmCasting(imageId: string) {
+ const image = images.value.find(item => item.id === imageId)
+ if (
+ detailBlocked.value ||
+ subject.value?.module !== 'character' ||
+ !!castingQuery.error.value ||
+ !identity.value ||
+ !image ||
+ !canBeAnchor(image)
+ )
+ return
+ const subjectId = subject.value.id
+ const identityId = identity.value.id
+ await runOperation(projectId.value, `确认 ${subject.value.name} 角色选角`, async () => {
+ const result = await subjectIdentityApi.confirmCasting(subjectId, imageId)
+ if (
+ !result ||
+ result.identity.id !== identityId ||
+ !result.identity.isLocked ||
+ result.anchor.id !== imageId ||
+ !result.anchor.enabled
+ )
+ throw new Error('接口未确认演员母版与身份锁定,请刷新核对。')
+ })
+ await Promise.all([detail.refresh(), castingQuery.refresh()])
+ }
+
return {
projectId,
operation,
@@ -177,25 +280,34 @@ export function useSubjectIdentity() {
subject,
subjects,
catalog,
+ castingQuery,
styleQuery,
detail,
identity,
images,
+ castingItem,
session,
concurrency,
+ candidateLimit,
force,
editorRevision,
dirty,
blocked,
+ castingBlocked,
detailBlocked,
hasStyle,
canGenerateText,
canGenerateImage,
+ canGenerateCandidate,
batchValid,
+ candidateLimitValid,
save,
generate,
generateProject,
+ generateCastingCandidates,
generateImage,
- setAnchor
+ generateCastingCandidate,
+ setAnchor,
+ confirmCasting
}
}
diff --git a/src/features/workflows/pages.test.ts b/src/features/workflows/pages.test.ts
index 90b161f..12860bb 100644
--- a/src/features/workflows/pages.test.ts
+++ b/src/features/workflows/pages.test.ts
@@ -337,7 +337,7 @@ describe('视觉风格与主体身份工作区', () => {
expect(wrapper!.text()).toContain('2 个形态')
expect(fetcher.mock.calls.some(([url]) => String(url).endsWith('/subjects/subject-db-1/identity'))).toBe(true)
expect(fetcher.mock.calls.some(([url]) => String(url).endsWith('/identity/images'))).toBe(false)
- expect(button('生成身份参考图').disabled).toBe(true)
+ expect(button('生成选角候选').disabled).toBe(true)
expect(button('AI 生成身份').disabled).toBe(false)
})
@@ -353,7 +353,7 @@ describe('视觉风格与主体身份工作区', () => {
await mountAssets('identity')
expect(button('AI 重新生成身份').disabled).toBe(true)
expect(button('保存主体身份').disabled).toBe(false)
- button('生成身份参考图').click()
+ button('生成辅助身份图').click()
await flushPromises()
expect(button('确认生成身份图').disabled).toBe(true)
document.querySelector('#identity-image-cost')!.click()
@@ -362,7 +362,7 @@ describe('视觉风格与主体身份工作区', () => {
await flushPromises()
const post = fetcher.mock.calls.find(([, init]) => init?.method === 'POST')!
expect(post[0]).toBe('/api/subjects/subject-db-1/identity/images')
- expect(JSON.parse(post[1]!.body as string)).toEqual({ provider: 'seedream', viewType: 'primary' })
+ expect(JSON.parse(post[1]!.body as string)).toEqual({ provider: 'seedream', viewType: 'front' })
})
it('无项目风格时禁止生成身份和图片,但仍可人工保存身份', async () => {
@@ -377,7 +377,7 @@ describe('视觉风格与主体身份工作区', () => {
)
await mountAssets('identity')
expect(button('AI 重新生成身份').disabled).toBe(true)
- expect(button('生成身份参考图').disabled).toBe(true)
+ expect(button('生成选角候选').disabled).toBe(true)
expect(button('保存主体身份').disabled).toBe(false)
})
@@ -399,19 +399,21 @@ describe('视觉风格与主体身份工作区', () => {
})
vi.stubGlobal('fetch', fetcher)
await mountAssets('identity')
- await confirmGeneration('补齐项目身份文本')
+ await confirmGeneration('补齐全部主体身份文本')
const post = fetcher.mock.calls.find(([, init]) => init?.method === 'POST')!
expect(post[0]).toBe('/api/projects/page-test-project/subject-identities/generate')
expect(JSON.parse(post[1]!.body as string)).toEqual({ force: false, concurrency: 3 })
- expect(wrapper!.text()).toContain('部分主体生成失败')
+ expect(wrapper!.text()).toContain('本次存在部分失败')
expect(wrapper!.text()).toContain('含锁定 1')
expect(wrapper!.text()).toContain('文本模型超时')
})
it('身份候选母版切换需确认,只发送正确 Subject ID 的 anchor PUT', async () => {
let selected = false
+ const form = formFixture()
+ form.subject.module = 'scene'
const fetcher = vi.fn().mockImplementation(async (url, init) => {
- if (String(url).endsWith('/subject-forms')) return jsonResponse([formFixture()])
+ if (String(url).endsWith('/subject-forms')) return jsonResponse([form])
if (String(url).endsWith('/visual-style')) return jsonResponse(styleFixture())
if (init?.method === 'PUT') {
selected = true
@@ -434,6 +436,63 @@ describe('视觉风格与主体身份工作区', () => {
expect(wrapper!.text()).toContain('当前身份母版')
})
+ it('Character 确认选角原子切换 Anchor 并锁定 Identity,不调用普通母版接口', async () => {
+ let locked = false
+ let selected = false
+ const candidate = identityImageFixture({ id: 'casting-1', enabled: false, isAnchor: false })
+ const fetcher = vi.fn().mockImplementation(async (url, init) => {
+ const path = String(url)
+ if (path.endsWith('/subject-forms')) return jsonResponse([formFixture()])
+ if (path.endsWith('/visual-style')) return jsonResponse(styleFixture())
+ if (path.endsWith('/character-casting/readiness'))
+ return jsonResponse({
+ total: 1,
+ ready: locked ? 1 : 0,
+ missingIdentity: 0,
+ missingAnchor: 0,
+ candidatePending: locked ? 0 : 1,
+ unlocked: 0,
+ locked: locked ? 1 : 0,
+ items: [
+ {
+ subjectId: 'subject-db-1',
+ subjectRef: '@CH0001',
+ subjectName: '林知夏',
+ status: locked ? 'ready' : 'candidate_pending',
+ identityId: 'identity-db-1',
+ candidateImages: locked ? undefined : [{ id: 'casting-1', imageUrl: candidate.imageUrl }],
+ anchorImageId: locked ? 'casting-1' : undefined,
+ anchorImageUrl: locked ? candidate.imageUrl : undefined,
+ isLocked: locked
+ }
+ ]
+ })
+ if (path.endsWith('/identity/images'))
+ return jsonResponse([{ ...candidate, enabled: selected, isAnchor: selected }])
+ if (init?.method === 'PUT' && path.endsWith('/casting')) {
+ locked = true
+ selected = true
+ return jsonResponse({
+ identity: { ...identityFixture({ isLocked: true }), images: undefined },
+ anchor: { ...candidate, enabled: true }
+ })
+ }
+ return jsonResponse(identityFixture({ isLocked: locked }))
+ })
+ vi.stubGlobal('fetch', fetcher)
+ await mountAssets('identity')
+ expect(wrapper!.text()).toContain('等待确认演员')
+ button('确认选角并锁定').click()
+ await flushPromises()
+ button('确认演员选择').click()
+ await flushPromises()
+ const put = fetcher.mock.calls.find(([, init]) => init?.method === 'PUT')!
+ expect(put[0]).toBe('/api/subjects/subject-db-1/identity/images/casting-1/casting')
+ expect(fetcher.mock.calls.some(([url]) => String(url).endsWith('/anchor'))).toBe(false)
+ expect(wrapper!.text()).toContain('选角状态:选角已完成')
+ expect(wrapper!.text()).toContain('演员身份已确认并锁定')
+ })
+
it('切换主体会取消旧查询,迟到的身份结果不覆盖当前主体', async () => {
let finish!: (value: Response) => void
const form = formFixture()
@@ -485,7 +544,7 @@ describe('视觉风格与主体身份工作区', () => {
provided.data.value!.project = { ...fixture, status: 'generating' }
await flushPromises()
expect(button('保存主体身份').disabled).toBe(true)
- expect(button('生成身份参考图').disabled).toBe(true)
+ expect(button('生成选角候选').disabled).toBe(true)
})
})
diff --git a/src/styles.css b/src/styles.css
index bf29141..280bdb1 100644
--- a/src/styles.css
+++ b/src/styles.css
@@ -88,6 +88,47 @@
background: #f1e8df;
color: var(--color-accent);
}
+ .casting-stats {
+ display: grid;
+ grid-template-columns: repeat(5, minmax(0, 1fr));
+ gap: 10px;
+ }
+ .casting-stats div {
+ padding: 10px 12px;
+ border-radius: 4px;
+ background: #f7f8f4;
+ }
+ .casting-stats dt {
+ color: var(--color-muted);
+ font-size: 10px;
+ }
+ .casting-stats dd {
+ margin-top: 5px;
+ font-family: ui-monospace, monospace;
+ font-size: 13px;
+ }
+ .casting-list {
+ display: grid;
+ grid-template-columns: repeat(3, minmax(0, 1fr));
+ gap: 8px;
+ }
+ .casting-item {
+ display: flex;
+ min-width: 0;
+ align-items: center;
+ justify-content: space-between;
+ gap: 12px;
+ padding: 11px 12px;
+ border: 1px solid var(--color-line);
+ border-radius: 5px;
+ background: #fafbf7;
+ text-align: left;
+ }
+ .casting-item:hover,
+ .casting-item.selected {
+ border-color: #c9d0be;
+ background: #eef1e7;
+ }
@media (max-width: 900px) {
.identity-workspace {
grid-template-columns: minmax(0, 1fr);
@@ -95,6 +136,12 @@
.identity-subject-list {
max-height: 220px;
}
+ .casting-stats {
+ grid-template-columns: repeat(2, minmax(0, 1fr));
+ }
+ .casting-list {
+ grid-template-columns: 1fr;
+ }
}
.app-shell {
display: grid;
@@ -446,9 +493,15 @@
color: #557b50;
}
.status-badge[data-status='blocked'],
- .status-badge[data-status='cancelled'] {
+ .status-badge[data-status='cancelled'],
+ .status-badge[data-status='missing_identity'],
+ .status-badge[data-status='missing_anchor'] {
color: #8b6f64;
}
+ .status-badge[data-status='candidate_pending'],
+ .status-badge[data-status='unlocked'] {
+ color: #aa8137;
+ }
.production-controls {
display: grid;