diff --git a/docs/api-contract-sync.md b/docs/api-contract-sync.md
index fbad3c9..3e1de90 100644
--- a/docs/api-contract-sync.md
+++ b/docs/api-contract-sync.md
@@ -89,3 +89,16 @@
验证不启动真实生图、视频或视觉校验。当前浏览器无法访问本地 localhost 服务,浏览器视觉验收与真实后端联调仍待在可访问的开发环境完成。
本轮校验:`pnpm check`(49 个文件、393 项测试)、`pnpm build` 和差异检查通过。新增回归覆盖切镜迟到响应、历史审计缺失、编辑预览失效、主图身份变化及后台候选编辑句柄。测试输出仍有已有 localhost:3000 连接拒绝日志;不据此宣称真实后端或付费模型联调完成。
+
+
+## 2026-10-14 动作修订与候选权限同步
+
+依据同级后端当前未提交 dev 的 `docs/api/public/motion-plan-revisions.md` 及正式路由、服务返回;不依赖旧建议文档推断契约。
+
+- 视频 DTO 和质量链共用八个版本与权限字段。候选独立控制校验、修复与设主;过期终态优先于历史通过,两个空版本 ID 不自行判为过期。主视频优先显示 readiness 的具体原因。运行任务的过期计数与逐镜终态读取 metadata,完成后读取 result。
+- 分镜动作面板和生产动作弹窗共用完整修订编辑器。编辑、免费预检查、保存、确认模型费用、启动视觉任务、读取任务、激活均为独立步骤;阶段、整体约束、主体引用和收尾等字段完整传递。
+- 保存显式提交父版本(首次可为 null);校验提交当前主首帧 ID 和当前生效指针,使用服务端视觉模型,不传请求级模型选择参数;激活提交真实视觉任务 ID 和预期生效指针。
+- 激活资格要求任务完成、通过且未失效,并核对镜头、修订、内容指纹、主首帧 ID 与图片地址、生效指针。修改草稿、保存新修订、主首帧或生效指针变化后撤销旧资格和费用确认。刷新后可恢复同镜头持久化任务;关闭弹窗或切换标签不重复启动任务。
+- 激活后刷新版本、动作预览、视频资产、质量记录和项目 readiness,提示重新生成视频提示词,不自动发起生成。同步 409 保留顶层 code 与独立 details,撤销候选会话资格并刷新权限;后台 failed 任务独立展示 error 和 result.issues。
+
+浏览器验收使用本地 Chrome 和 localhost。真实后端读取及免费预检查不调用模型;保存、收费视觉校验、激活、版本冲突、首帧换图和草稿修改的流程使用隔离模拟场景验证,不写入业务数据或触发真实付费任务。
diff --git a/docs/backend-motion-contract-followup.md b/docs/backend-motion-contract-followup.md
new file mode 100644
index 0000000..65a1f0b
--- /dev/null
+++ b/docs/backend-motion-contract-followup.md
@@ -0,0 +1,66 @@
+# 动作规划版本与视频质量接口补充建议归档
+
+2026-10-14 更新:后三项已由后端实现。以下保留 2026-10-13 的建议清单;实际接口以同级后端的 `docs/api/public/motion-plan-revisions.md` 为准,前端已按实际契约接入。
+
+前端需要识别视频候选所使用的动作版本、展示当前生效动作规划,并完成安全的人工修订流程。以下内容供后端实施与接口评审使用;标记为“建议新增”的路径和字段尚未开放,最终命名由后端确认。所有路径均以 `/api` 为前缀,成功响应沿用 `{ data: ... }`。
+
+## 视频质量状态与候选版本字段
+
+现有 `GET /storyboard-shots/:shotId/videos/quality-status`(含 `?detail=true`)没有读取持久化的 `qualityTerminalStatus=stale_motion_plan`。旧版本候选停止处理后,查询仍可能返回 `validating` 或 `repairing`。项目任务聚合结果已经提供 `staleMotionPlan` 和 `settled[shotId].status`,但不能替代逐候选状态。
+
+建议在质量查询的每个 `chain` 项补充以下字段,并在视频列表、主视频和刷新接口使用的 `VideoAssetDto` 中提供同一份候选版本摘要,使普通候选也可判断是否过期。
+
+| 建议字段 | 类型 | 用途 |
+| --- | --- | --- |
+| `motionPlanRevisionId` | `string \| null` | 此视频生成时绑定的动作修订 ID;历史 AI 快照为 `null` |
+| `currentMotionPlanRevisionId` | `string \| null` | 此镜头当前生效的人工动作修订 ID |
+| `motionPlanStale` | `boolean` | 后端根据绑定与当前版本判断,前端不解析内部快照 |
+| `qualityTerminalStatus` | `string \| null` | 暴露已持久化的质量终态,至少支持 `stale_motion_plan`;其余终态以实际持久化能力为准 |
+| `staleReason` | `string \| null` | 可直接展示的过期原因 |
+| `canValidate`、`canRepair`、`canSetPrimary` | `boolean` | 后端依据版本、资产完成状态和质量证据计算的操作权限 |
+
+顶层 `status` 增加 `stale_motion_plan`;最新候选已终止时优先返回此状态,不继续显示校验或修复中。保留历史 `validationPassed` 和问题证据,同时明确历史通过不能证明版本仍有效。逐候选字段必须覆盖整条链,不能只判断最新视频或当前主视频。
+
+版本字段与终态保持各自含义:即使后来切回同一版本,曾因过期而终止的任务也不能隐式恢复。历史视频的绑定版本与当前版本均为 `null` 时,保持既有兼容规则,不一律判为过期。不要新增 `ShotVideo.status` 的 Provider 状态值来代替质量终态,也不要公开完整 `rawJson`。
+
+建议在现有 readiness 的镜头项增加 `primaryVideoStaleReasons: string[]`,为空数组表示没有原因。前端即可展示首帧、参考图、模型输入变体或动作版本变化的具体原因;当前仅有 `primaryVideoStale` 布尔值,只能展示概括说明。
+
+## 人工动作规划的查询与修订接口
+
+现有 `POST /storyboard-shots/:shotId/motion-plan/revisions/preview` 请求为 `{ motionPlan }`,时长从正式镜头读取。返回结构问题、时间轴与动作密度预警及内容指纹;`requiresStartStateValidation=true`、`canActivate=false`。结构合法不代表可直接激活。当前尚无公开的修订保存、历史查询与激活接口。
+
+现有 `GET /storyboard-shots/:shotId/motion-plan/preview` 仍读取 `rawJson.motionPlan`。建议改为优先解析当前生效修订,沿用既有时间轴字段,同时增加 `source: 'ai_original' | 'manual'`、`activeRevisionId: string | null`、`motionPlanFingerprint: string | null`。仅在没有人工生效版本时读取历史 AI 快照;版本记录损坏或归属错误应明确报错,不静默回退。
+
+| 建议新增接口 | 请求 | 返回核心字段 |
+| --- | --- | --- |
+| `GET /storyboard-shots/:shotId/motion-plan/revisions` | 无请求体 | `shotId`、`originalRevisionId`、`activeRevisionId`、`revisions`;未初始化的版本 ID 可为 `null` |
+| `POST /storyboard-shots/:shotId/motion-plan/revisions` | `motionPlan`、`parentRevisionId`、`reason` | 新建修订;保存不激活,由服务端确定 `source=manual`、镜头时长和指纹 |
+| `POST /storyboard-shots/:shotId/motion-plan/revisions/:revisionId/start-state-validation/start` | 目标主首帧 ID及预期生效版本 ID | `executionId`、`status`;复用持久化任务查询,明确此操作调用模型,供前端确认费用 |
+| `PUT /storyboard-shots/:shotId/motion-plan/revisions/:revisionId/active` | `expectedRevisionId: string | null`、有效的起点校验任务 ID | `shotId`、`activeRevisionId`、`motionPlanFingerprint`、`changed`、`videoPromptStale` |
+
+修订记录建议包含 `revisionId`、`shotId`、`source`、`parentRevisionId`、`reason`、`motionPlan`、`durationSeconds`、`fingerprint`、`createdAt`、`isActive`。`motionPlan` 沿用 `MotionPlanOutputSchema` 的完整 `beats` 和 `globalMotionConstraints`,不另造简化编辑结构。
+
+起点校验任务路径为建议方案,后端也可采用同等能力的现有任务接口。必须明确返回校验结论及其绑定的 `revisionId`、指纹、主首帧 ID,且激活前检查这些输入仍有效。预检查不调用模型;正式视觉校验的费用、模型参数和结果查询契约需要一并确认。现实性等其他激活门禁应由后端定义,不能由前端用预检查的 `valid` 推断。
+
+保存、校验与激活均检查镜头和版本归属。激活在事务内执行版本并发检查,使旧视频提示词失效,并保留原始 AI 快照与所有历史候选。并发冲突建议返回 HTTP 409 及可识别错误码,附当前生效版本 ID,前端刷新后由用户重新确认。
+
+## 手动设为主视频的版本检查
+
+现有 `PUT /storyboard-shots/:shotId/videos/:videoId/primary` 经 `videoAssetService.setPrimary` 调用旧的 `shotVideoRepository.setPrimary`,尚未复用自动晋升的版本检查。仅禁用前端按钮不能防止页面打开后版本变化。
+
+建议此接口在同一事务内重新读取镜头当前动作版本、候选绑定版本、持久化质量证据及终止事实,确认候选已完成、属于该镜头且允许晋升后再切换主视频。过期候选或已停止的质量候选必须拒绝;失败时不修改现有主视频。
+
+请求可增加 `expectedMotionPlanRevisionId: string | null`,用于发现用户确认期间的版本变化;无论客户端是否提交,服务端都必须比较候选绑定版本和镜头当前版本。成功响应沿用视频 DTO,并包含上文的版本摘要。
+
+建议错误返回 HTTP 409,提供可识别的 `code`(例如 `MOTION_PLAN_STALE`)、`message`、`shotId`、`videoId`、`motionPlanRevisionId`、`currentMotionPlanRevisionId`。错误包装沿用项目约定;前端据此撤销本次会话的通过资格、关闭切换确认并刷新资产。
+
+## 联调验收
+
+- 候选生成期间切换动作版本后,质量任务停止;任务汇总与逐候选状态一致,刷新页面后仍显示版本过期。
+- 同一镜头包含新旧版本候选时,各候选独立显示版本与操作权限,历史通过不会使旧候选可晋升。
+- 手动设主与动作版本切换并发时,旧候选不能替换当前主视频;拒绝请求不改变主视频。
+- 动作预览、提示词生成、视频生成和校验使用同一生效版本,原始 AI 规划始终可追溯。
+- 修订保存、起点校验与激活独立;结构合法但未经有效视觉校验的修订不能激活。
+- 无人工修订的历史镜头正常读取和生产;旧任务缺少 `staleMotionPlan` 时前端按零展示。
+
+实现核对入口:后端 `video-quality-status.service.ts`、`video-quality-execution.service.ts`、`motion-plan-detail-preview.service.ts`、`motion-plan-revision-preview.service.ts`、`motion-plan-revision.repository.ts`、`video-asset.service.ts`、`shot-video.repository.ts` 和 `storyboard.routes.ts`、`video.routes.ts`。
diff --git a/src/components/ui/WorkspaceRefreshButton.vue b/src/components/ui/WorkspaceRefreshButton.vue
new file mode 100644
index 0000000..c22646c
--- /dev/null
+++ b/src/components/ui/WorkspaceRefreshButton.vue
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+ {{ label }}
+
+
diff --git a/src/components/ui/WorkspaceSectionHeading.vue b/src/components/ui/WorkspaceSectionHeading.vue
new file mode 100644
index 0000000..ce96497
--- /dev/null
+++ b/src/components/ui/WorkspaceSectionHeading.vue
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+ {{ description }}
+
+
+
+
+
diff --git a/src/components/ui/index.ts b/src/components/ui/index.ts
index ff71ff4..23b7ba1 100644
--- a/src/components/ui/index.ts
+++ b/src/components/ui/index.ts
@@ -9,3 +9,5 @@ export { default as AssetOpenLink } from './AssetOpenLink.vue'
export { default as RevealImage } from './RevealImage.vue'
export { default as DirectoryItem } from './DirectoryItem.vue'
export { default as WorkspaceTools } from './WorkspaceTools.vue'
+export { default as WorkspaceSectionHeading } from './WorkspaceSectionHeading.vue'
+export { default as WorkspaceRefreshButton } from './WorkspaceRefreshButton.vue'
diff --git a/src/features/production/ProductionPage.vue b/src/features/production/ProductionPage.vue
index bb4f78b..39a5452 100644
--- a/src/features/production/ProductionPage.vue
+++ b/src/features/production/ProductionPage.vue
@@ -15,6 +15,7 @@ import { EmptyState, StatusBadge } from '../../components/ui'
import BeatShotDirectory from '../storyboard/components/BeatShotDirectory.vue'
import ConfirmAction from '../workflows/ConfirmAction.vue'
import { productionStatusLabel } from './model'
+import { videoInputStaleReason } from './production-messages'
import { useProduction } from './useProduction'
import ProductionReceipt from './components/ProductionReceipt.vue'
import ShotProductionAssets from './components/ShotProductionAssets.vue'
@@ -65,6 +66,8 @@ const {
promptExecution,
videoExecution
} = useProduction()
+/** 关闭动作弹窗或切换镜头时继续观察视觉任务,避免遗留未知活动锁。 */
+useWorkflowExecution(id, 'motion-plan-start-state-validation')
/** 当前镜头资产组件引用,标题菜单仅操作此镜头的只读检查弹窗。 */
const shotAssetsRef = ref | null>(null)
/** 标题状态只描述最近视频任务,不能表示质量通过或当前主视频仍可用。 */
@@ -387,7 +390,9 @@ const videoRules = { videoLimit: integerRule('本批镜头上限'), videoRepairA
当前有
{{ staleVideos }}
- 个主视频已过期。它们使用的主首帧或主体参考图已经变化;非覆盖模式批量生成时会只重建这些过期主视频。
+ 个主视频已过期。{{
+ videoInputStaleReason
+ }};非覆盖模式批量生成会按最新输入重建过期主视频。
- 主视频已过期 {{ staleVideos }} · 会按当前主首帧与参考资产重新生成
+ 主视频已过期 {{ staleVideos }} ·
+ 会按当前主首帧、参考资产与动作规划重新生成
- 主视频已过期:当前主首帧或主体参考图与生成该视频时不一致。旧视频仍保留,但需要重新生成后才能作为当前有效成片。
+ 主视频已过期:{{
+ videoItem.primaryVideoStaleReasons?.join(';') || videoInputStaleReason
+ }}。旧视频仍保留,但需要重新生成后才能作为当前有效成片。
request(`/storyboard-shot-videos/${encodeURIComponent(videoId)}/status`, { signal }),
- setPrimaryVideo: (shotId: string, videoId: string) =>
+ /**
+ * 按候选后端权限切换主视频,并携带已读取的生效版本作并发检查。
+ * @param shotId 镜头 ID
+ * @param videoId 候选 ID
+ * @param expectedMotionPlanRevisionId 已查询的当前动作版本
+ * @returns 后端确认后的主视频
+ */
+ setPrimaryVideo: (shotId: string, videoId: string, expectedMotionPlanRevisionId?: string | null) =>
request(`${shotPath(shotId)}/videos/${encodeURIComponent(videoId)}/primary`, {
- method: 'PUT'
+ method: 'PUT',
+ body: expectedMotionPlanRevisionId === undefined ? {} : { expectedMotionPlanRevisionId }
})
}
diff --git a/src/features/production/components/QualityDialog.vue b/src/features/production/components/QualityDialog.vue
index a1a7d77..ebbe4c8 100644
--- a/src/features/production/components/QualityDialog.vue
+++ b/src/features/production/components/QualityDialog.vue
@@ -1,4 +1,5 @@
@@ -75,10 +76,24 @@ const canSelect = computed(
{{ item.isPrimary ? '主视频' : '候选视频' }}
- 需更新
+ 需更新
{{ item.durationSeconds || durationSeconds || '—' }}s
+ {{ item.staleReason }}
+
+ 生成动作版本 {{ item.motionPlanRevisionId ?? 'AI 原始' }} · 当前
+ {{ item.currentMotionPlanRevisionId ?? 'AI 原始' }}
+
{{ previousValidation ? '此前画面检查通过' : '此前画面检查未通过' }}
@@ -87,9 +102,23 @@ const canSelect = computed(
{{ item.provider }} · {{ item.model }} · {{ formatDate(item.createdAt) }}
-
+
质量检查
+ 创建修复候选
查看质量记录
设为主视频
diff --git a/src/features/production/components/VideoQualityDiagnostics.vue b/src/features/production/components/VideoQualityDiagnostics.vue
index e56c90b..446488f 100644
--- a/src/features/production/components/VideoQualityDiagnostics.vue
+++ b/src/features/production/components/VideoQualityDiagnostics.vue
@@ -7,6 +7,7 @@ import { useQuery } from '../../../composables/useQuery'
import { formatDate } from '../../../lib/format'
import { videoDiagnosticsApi } from '../diagnostics-api'
import { videoQualityStatusLabel } from '../model'
+import { videoInputStaleReason } from '../production-messages'
import type { VideoQualityRollbackTarget } from '../diagnostics.types'
/** 视频诊断绑定正式镜头与用户选中的视频,随弹窗挂载直接读取。 */
@@ -15,8 +16,10 @@ const props = defineProps<{
shotId: string
/** 用户选中的视频 ID。 */
videoId: string
- /** 当前视频是否因首帧或参考图变化而需要更新。 */
+ /** 当前视频是否因首帧、参考图或动作规划版本等输入变化而需要更新。 */
stale: boolean
+ /** 当前资产公开的过期原因,普通候选也可能不在自动链中。 */
+ staleReason?: string | null
}>()
/** 查询目标包含镜头和视频,切换目标后取消旧请求。 */
const key = computed(() => (props.shotId && props.videoId ? JSON.stringify([props.shotId, props.videoId]) : ''))
@@ -37,6 +40,15 @@ const query = useQuery(key, async (value, signal) => {
const detail = computed(() => query.data.value?.detail)
/** 当前视频的独立记录,不能使用其它候选或流程整体结果兜底。 */
const currentRecord = computed(() => detail.value?.chain.find(item => item.videoId === props.videoId))
+/** 当前候选的终态优先于保留的历史通过证据。 */
+const currentStale = computed(
+ () =>
+ props.stale ||
+ !!currentRecord.value?.motionPlanStale ||
+ currentRecord.value?.qualityTerminalStatus === 'stale_motion_plan'
+)
+/** 仅展示当前候选的具体原因,不能套用最新候选的原因。 */
+const reason = computed(() => currentRecord.value?.staleReason || props.staleReason || videoInputStaleReason)
/** 当前视频优先展示,其它候选明确标识为相关记录。 */
const orderedChain = computed(() => {
const chain = detail.value?.chain ?? []
@@ -69,8 +81,8 @@ function rollbackLabel(target: VideoQualityRollbackTarget) {
-
- 此视频需要更新:首帧或参考图已变化。此前画面检查结果仅供参考,请重新生成视频。
+
+ 此视频需要更新:{{ reason }}。此前画面检查结果仅供参考,请重新生成视频。
{{
query.error.value
@@ -79,11 +91,13 @@ function rollbackLabel(target: VideoQualityRollbackTarget) {
{{
- currentRecord.validationPassed === true
- ? '当前视频此前画面检查通过'
- : currentRecord.validationPassed === false
- ? '当前视频此前画面检查未通过'
- : '当前视频尚未完成画面检查'
+ currentStale
+ ? '当前候选版本已过期,质量流程已停止;历史画面检查仅供参考'
+ : currentRecord.validationPassed === true
+ ? '当前视频此前画面检查通过'
+ : currentRecord.validationPassed === false
+ ? '当前视频此前画面检查未通过'
+ : '当前视频尚未完成画面检查'
}}
此视频暂无自动质量流程记录。
@@ -91,10 +105,17 @@ function rollbackLabel(target: VideoQualityRollbackTarget) {
本镜头共 {{ detail.chain.length }} 条视频记录;当前视频优先显示,其它候选单独标识。
+
+ 生成动作版本 {{ currentRecord.motionPlanRevisionId ?? 'AI 原始' }} · 当前
+ {{ currentRecord.currentMotionPlanRevisionId ?? 'AI 原始' }}
+
当前视频修复 {{ currentRecord.repairAttempt }} / {{ currentRecord.maxRepairAttempts ?? '未设置' }}
-
+
当前镜头正在执行:{{ videoQualityStatusLabel(detail.status) }}
当前镜头尚无质量链记录。
@@ -106,15 +127,18 @@ function rollbackLabel(target: VideoQualityRollbackTarget) {
{{ item.providerStatus }} ·
{{
- item.validationPassed === true
- ? '校验通过'
- : item.validationPassed === false
- ? '校验未通过'
- : '尚未校验'
+ item.motionPlanStale || item.qualityTerminalStatus === 'stale_motion_plan'
+ ? '动作版本过期,质量流程已停止'
+ : item.validationPassed === true
+ ? '历史校验通过'
+ : item.validationPassed === false
+ ? '校验未通过'
+ : '尚未校验'
}}
{{ formatDate(item.updatedAt) }}
+ {{ item.staleReason }}
- = {}): ShotKeyframe
}
}
-/** 视频测试记录,默认是已完成的主视频。 */
+/**
+ * 视频测试记录沿用后端权限摘要,默认已完成主视频。
+ * @param patch 覆盖字段
+ * @returns 测试视频公开 DTO
+ */
export function videoFixture(patch: Partial = {}): ShotVideo {
return {
+ motionPlanRevisionId: null,
+ currentMotionPlanRevisionId: null,
+ motionPlanStale: false,
+ qualityTerminalStatus: null,
+ staleReason: null,
+ canValidate: true,
+ canRepair: false,
+ canSetPrimary: false,
id: 'video-1',
shotId: 'shot-1',
provider: 'seedance',
diff --git a/src/features/production/types.ts b/src/features/production/types.ts
index 9bac28c..9105471 100644
--- a/src/features/production/types.ts
+++ b/src/features/production/types.ts
@@ -78,8 +78,10 @@ export interface VideoReadinessItem {
issues: ProductionIssue[]
primaryVideoId?: string | null
activeVideoId?: string | null
- /** 当前主视频已基于旧主首帧或旧主体参考图生成。 */
+ /** 当前主视频的首帧、参考资产或动作规划版本已变化。 */
primaryVideoStale?: boolean
+ /** 后端给出的当前主视频过期原因。 */
+ primaryVideoStaleReasons?: string[]
providerInputRecovery?: ProviderInputRecoveryStatus | null
}
@@ -150,8 +152,28 @@ export interface ShotKeyframe {
updatedAt: string
}
+/** 视频候选独立的动作版本、终态及后端操作权限。 */
+export interface VideoPermissions {
+ /** 生成时绑定的人工动作版本。 */
+ motionPlanRevisionId: string | null
+ /** 当前镜头生效的人工动作版本。 */
+ currentMotionPlanRevisionId: string | null
+ /** 是否已因动作版本变化而过期。 */
+ motionPlanStale: boolean
+ /** 已持久化的质量终态,切回旧版本也不撤销。 */
+ qualityTerminalStatus: string | null
+ /** 后端提供的过期原因。 */
+ staleReason: string | null
+ /** 是否允许视觉校验。 */
+ canValidate: boolean
+ /** 是否允许创建修复候选。 */
+ canRepair: boolean
+ /** 是否允许设为主视频。 */
+ canSetPrimary: boolean
+}
+
/** 视频生成记录;完成后地址指向后端持久化的视频资产。 */
-export interface ShotVideo {
+export interface ShotVideo extends VideoPermissions {
id: string
shotId: string
provider: string
@@ -400,14 +422,14 @@ export interface ProjectVideoStatus {
/** 单镜头严格质量链的持久化状态;读取不会重新调用模型。 */
export interface ShotVideoQualityStatus {
shotId: string
- status: 'not_started' | 'generating' | 'validating' | 'repairing' | 'passed' | 'exhausted'
+ status: 'not_started' | 'generating' | 'validating' | 'repairing' | 'passed' | 'exhausted' | 'stale_motion_plan'
primaryVideoId: string | null
latestVideoId: string | null
repairAttempt: number
maxRepairAttempts: number | null
validationPassed: boolean | null
issues: unknown[]
- chain: {
+ chain: (VideoPermissions & {
videoId: string
providerStatus: ShotVideo['status']
isPrimary: boolean
@@ -416,7 +438,7 @@ export interface ShotVideoQualityStatus {
validationPassed: boolean | null
createdAt: string
updatedAt: string
- }[]
+ })[]
}
/** 失败视频批量重试回执。 */
diff --git a/src/features/production/useQuality.ts b/src/features/production/useQuality.ts
index 9b05dd2..e2412e9 100644
--- a/src/features/production/useQuality.ts
+++ b/src/features/production/useQuality.ts
@@ -1,3 +1,4 @@
+import { videoOperationAllowed } from './video-permissions'
import { computed, onScopeDispose, watch } from 'vue'
import { useWorkflowExecution } from '../workflows/execution'
import { isQualityBatchResult } from './quality'
@@ -8,11 +9,12 @@ import { productionApi } from './api'
import { qualityApi } from './quality-api'
import {
isVisualValidation,
+ clearVideoQualification,
+ clearVideoConflict,
qualityKey,
qualitySession,
qualityTargets,
- validQualityInput,
- sessionVideoValidation
+ validQualityInput
} from './quality'
import type { QualityAction, QualityInput, QualityReceipt, QualityTarget, RepairAttempt } from './quality.types'
@@ -212,17 +214,20 @@ export function useQuality(
video.durationSeconds <= 0
)
throw new Error('视频未完成、缺少视频地址或有效时长,不能执行抽样校验。')
+ if (video.motionPlanStale || video.qualityTerminalStatus === 'stale_motion_plan')
+ clearVideoQualification(projectId, target.shotId, target.assetId)
+ if (!videoOperationAllowed(video, action === 'repair' ? 'repair' : 'validate'))
+ throw new Error(video.staleReason || '后端当前不允许此候选执行所选质量操作,请刷新权限。')
if (action === 'repair') {
- if (sessionVideoValidation(projectId, target.shotId, target.assetId)?.passed !== false)
- throw new Error('请先完成视频质量校验;只有未通过的视频才能创建修复候选。')
if (videos.some(item => ['pending', 'queued', 'running'].includes(item.status)))
throw new Error('此镜头仍有活动视频任务,请结束后再修复。')
if (!stillCurrent()) throw new Error('已离开原操作目标,未提交质量任务。')
- const result = await qualityApi.repairVideo(
- target.shotId,
- target.assetId,
- input.maxRepairAttempts
- )
+ const result = await qualityApi
+ .repairVideo(target.shotId, target.assetId, input.maxRepairAttempts)
+ .catch(cause => {
+ clearVideoConflict(cause, projectId, target.shotId, target.assetId)
+ throw cause
+ })
if (
!result ||
result.shotId !== target.shotId ||
@@ -239,11 +244,12 @@ export function useQuality(
receipt = { kind: 'video-repair', result }
} else {
if (!stillCurrent()) throw new Error('已离开原操作目标,未提交质量任务。')
- const result = await qualityApi.validateVideo(
- target.shotId,
- target.assetId,
- input.allowedTexts ?? []
- )
+ const result = await qualityApi
+ .validateVideo(target.shotId, target.assetId, input.allowedTexts ?? [])
+ .catch(cause => {
+ clearVideoConflict(cause, projectId, target.shotId, target.assetId)
+ throw cause
+ })
if (
!isVisualValidation(result) ||
result.shotId !== target.shotId ||
diff --git a/src/features/production/video-permissions.ts b/src/features/production/video-permissions.ts
new file mode 100644
index 0000000..cfb41cf
--- /dev/null
+++ b/src/features/production/video-permissions.ts
@@ -0,0 +1,18 @@
+import type { VideoPermissions } from './types'
+
+/**
+ * 过期终态优先于历史通过和权限标记;缺失权限默认禁用,版本为空不自行判过期。
+ * @param video 当前候选公开摘要
+ * @param action 所选视频操作
+ * @returns 后端是否明确允许此候选执行操作
+ */
+export function videoOperationAllowed(
+ video: Partial | null | undefined,
+ action: 'validate' | 'repair' | 'primary'
+) {
+ if (!video || video.motionPlanStale || video.qualityTerminalStatus === 'stale_motion_plan') return false
+ return (
+ (action === 'validate' ? video.canValidate : action === 'repair' ? video.canRepair : video.canSetPrimary) ===
+ true
+ )
+}
diff --git a/src/features/storyboard/StoryboardPage.vue b/src/features/storyboard/StoryboardPage.vue
index 5a2270a..3138614 100644
--- a/src/features/storyboard/StoryboardPage.vue
+++ b/src/features/storyboard/StoryboardPage.vue
@@ -27,6 +27,7 @@ import BeatShotDirectory from './components/BeatShotDirectory.vue'
import SubjectCoverageAudit from './components/SubjectCoverageAudit.vue'
import type { SubjectCoverageIssue } from './coverage.types'
import WorkflowExecutionPanel from '../workflows/WorkflowExecutionPanel.vue'
+import { useWorkflowExecution } from '../workflows/execution'
import { useStoryboard } from './useStoryboard'
import { storyboardApi, type StoryboardDurationAudit } from './api'
@@ -74,6 +75,8 @@ const {
executions,
run
} = useStoryboard()
+/** 切换详情标签后仍观察起点视觉任务,重新进入项目时恢复真实终态。 */
+useWorkflowExecution(id, 'motion-plan-start-state-validation')
const productionReady = computed(() => directionComplete.value && visualStateComplete.value)
/** 分镜时长审计为只读预警,接口失败不能影响分镜设计。 */
const durationAudit = ref(null)
@@ -552,11 +555,18 @@ const rules = { concurrency: integerRule('批量并发'), maxRepairAttempts: int
>设计与状态参考图与提示词动作与视线
-
+
+
-import { computed } from 'vue'
+import { computed, ref } from 'vue'
import { NButton, NTag, NSpin } from 'naive-ui'
import { useQuery } from '../../../composables/useQuery'
+import { WorkspaceSectionHeading, WorkspaceRefreshButton } from '../../../components/ui'
import IssueHint from '../../../components/ui/IssueHint.vue'
import { motionApi } from '../motion-api'
+import MotionRevisionEditor from './MotionRevisionEditor.vue'
/** 单镜头动作计划嵌入当前位置,切换镜头时取消旧读取。 */
-const props = defineProps<{ shotId: string; revision?: string }>()
+const props = defineProps<{
+ /** 正式镜头。 */
+ shotId: string
+ /** 所属项目,旧只读引用可以缺省。 */
+ projectId?: string
+ /** 外层更新标记。 */
+ revision?: string
+ /** 是否阻止修改。 */
+ disabled?: boolean
+}>()
+/** 激活后通知外层刷新资产与就绪检查。 */
+const emit = defineEmits<{ changed: [] }>()
+/** 人工编辑只在用户明确打开后挂载。 */
+const editing = ref(false)
+/** 生效后刷新真实时间轴,不用草稿覆盖预览。 */
+async function changed() {
+ await query.refresh()
+ emit('changed')
+}
/** 生成提示词后修改 revision,重新读取后端保存的动作时间轴。 */
const key = computed(() => JSON.stringify([props.shotId, props.revision ?? '']))
const query = useQuery(key, async (value, signal) => {
@@ -34,10 +54,25 @@ const savedWarnings = computed(() =>
-
+
+
+
+
+ 编辑动作修订
+
+
+
+ {{
+ query.data.value.source === 'manual' ? '人工生效版本' : 'AI 原始规划'
+ }}
+ {{ query.data.value.durationSeconds }} 秒 · {{ query.data.value.beats.length }} 个阶段
+ 需人工复核
+
+
+
+
-
-
- {{ query.data.value.durationSeconds }} 秒 · {{ query.data.value.beats.length }} 个阶段
- 需人工复核
-
-
+
尚无已保存动作计划,生成视频提示词后可在此查看。
@@ -96,13 +126,23 @@ const savedWarnings = computed(() =>
+
+
diff --git a/src/features/storyboard/components/ShotDesign.vue b/src/features/storyboard/components/ShotDesign.vue
index 5ad05eb..2bf0a74 100644
--- a/src/features/storyboard/components/ShotDesign.vue
+++ b/src/features/storyboard/components/ShotDesign.vue
@@ -1,4 +1,5 @@
-
+
- 导演摄影设计
+
+
+ >
此镜头尚无已保存的导演设计。
+ 此镜头尚无已保存的导演设计。
-
- 画面状态
+
+
+
+ >
- 时间
- {{ shot.visualState.timeOfDay || '未指定' }}
- 天气
@@ -78,7 +81,7 @@ defineProps<{ shot: DesignedShot }>()
- 此镜头还没有画面状态,请先完成镜头设计。
+ 此镜头还没有画面状态,请先完成镜头设计。
diff --git a/src/features/storyboard/components/ShotTools.vue b/src/features/storyboard/components/ShotTools.vue
index cd1688c..bc499e6 100644
--- a/src/features/storyboard/components/ShotTools.vue
+++ b/src/features/storyboard/components/ShotTools.vue
@@ -3,9 +3,9 @@ import FeedbackMessage from '../../../components/ui/FeedbackMessage.vue'
import { NScrollbar, NButton, NCheckbox } from 'naive-ui'
import { computed, onScopeDispose, ref, watch } from 'vue'
-import { Download, ExternalLink, RefreshCw } from '@lucide/vue'
+import { Download, ExternalLink } from '@lucide/vue'
import IssueHint from '../../../components/ui/IssueHint.vue'
-import { AssetImage } from '../../../components/ui'
+import { AssetImage, WorkspaceSectionHeading, WorkspaceRefreshButton } from '../../../components/ui'
import { storyboardApi } from '../api'
import { getStoryboardSession, referenceImageUrl } from '../model'
import type { DesignedShot, ShotReferences } from '../types'
@@ -130,17 +130,22 @@ function exportResult(kind: 'spec' | 'prompt') {
-
+
-
-
主体参考图
- 刷新参考图
-
-
- 自动读取镜头当前绑定形态的主参考图,不生成新图。切换镜头会同步刷新,参考图缺失会影响后续生成。
-
+
+
+
+
+
+
@@ -182,20 +187,21 @@ function exportResult(kind: 'spec' | 'prompt') {
-
-
-
镜头生成规格
- {{ busy.spec ? '编译中…' : '读取生成规格' }}
-
-
- 后端合并主体稳定身份、具体形态、摄影设计与即时状态,编译为 GenerationSpec,不调用模型。需要本镜头已有
- Direction 和 VisualState。
-
+
+
+
+
+ {{ busy.spec ? '编译中…' : '读取生成规格' }}
+
+
@@ -208,12 +214,12 @@ function exportResult(kind: 'spec' | 'prompt') {
-
- 视频提示词
-
- 已有提示词可直接复用,没有则依据 GenerationSpec 与参考图调用模型生成。此处只处理
- Prompt;首帧和实际视频任务请到“镜头生产”。
-
+
+
+
-
-
视线目标
- 刷新绑定
-
-
- 明确“朝向目标方向”或“注视具体目标”,保存后重新核对相关提示词和首帧。
-
+
+
+
+
+
+
diff --git a/src/features/storyboard/motion-api.ts b/src/features/storyboard/motion-api.ts
index 738cbab..ede70d5 100644
--- a/src/features/storyboard/motion-api.ts
+++ b/src/features/storyboard/motion-api.ts
@@ -1,8 +1,84 @@
+import type { MotionPlan, MotionRevision, MotionRevisionHistory, MotionRevisionPreview } from './motion-revision'
+import type { WorkflowExecutionStart } from '../workflows/execution.types'
import { request } from '../../lib/http'
import type { MotionPlanAudit, MotionPlanPreview } from './motion.types'
-/** 动作时间轴入口只读,不生成提示词,也不改变镜头时长。 */
+/** 动作查询与修订入口;只有明确启动视觉校验会调用模型。 */
export const motionApi = {
+ /**
+ * 查询真实修订历史。
+ * @param shotId 镜头 ID
+ * @param signal 取消信号
+ * @returns 版本历史与生效指针
+ */
+ revisions: (shotId: string, signal?: AbortSignal) =>
+ request(`/storyboard-shots/${encodeURIComponent(shotId)}/motion-plan/revisions`, {
+ signal
+ }),
+ /**
+ * 免费检查完整草稿,不激活版本。
+ * @param shotId 镜头 ID
+ * @param motionPlan 完整规划
+ * @returns 结构检查与预警
+ */
+ previewRevision: (shotId: string, motionPlan: MotionPlan) =>
+ request(
+ `/storyboard-shots/${encodeURIComponent(shotId)}/motion-plan/revisions/preview`,
+ { method: 'POST', body: { motionPlan } }
+ ),
+ /**
+ * 保存不可变修订,不调用模型。
+ * @param shotId 镜头 ID
+ * @param input 完整规划、父版本与原因
+ * @returns 未生效修订
+ */
+ saveRevision: (
+ shotId: string,
+ input: { motionPlan: MotionPlan; parentRevisionId: string | null; reason: string | null }
+ ) =>
+ request(`/storyboard-shots/${encodeURIComponent(shotId)}/motion-plan/revisions`, {
+ method: 'POST',
+ body: input
+ }),
+ /**
+ * 明确确认费用后启动服务端视觉模型,不接收请求级模型配置。
+ * @param shotId 镜头 ID
+ * @param revisionId 校验版本
+ * @param input 当前主首帧及当前生效指针
+ * @returns 持久化任务句柄
+ */
+ validateRevision: (
+ shotId: string,
+ revisionId: string,
+ input: { primaryKeyframeId: string; expectedRevisionId: string | null }
+ ) =>
+ request(
+ `/storyboard-shots/${encodeURIComponent(shotId)}/motion-plan/revisions/${encodeURIComponent(revisionId)}/start-state-validation/start`,
+ { method: 'POST', body: input }
+ ),
+ /**
+ * 使用当前有效视觉证据激活已保存版本。
+ * @param shotId 镜头 ID
+ * @param revisionId 目标版本
+ * @param input 当前指针与校验任务 ID
+ * @returns 生效状态及提示词失效标记
+ */
+ activateRevision: (
+ shotId: string,
+ revisionId: string,
+ input: { expectedRevisionId: string | null; validationExecutionId: string }
+ ) =>
+ request<{
+ shotId: string
+ activeRevisionId: string
+ motionPlanFingerprint: string
+ changed: boolean
+ videoPromptStale: boolean
+ }>(
+ `/storyboard-shots/${encodeURIComponent(shotId)}/motion-plan/revisions/${encodeURIComponent(revisionId)}/active`,
+ { method: 'PUT', body: input }
+ ),
+
/**
* 读取单镜头已保存的动作计划和实时复核建议。
* @param shotId 正式镜头 ID
diff --git a/src/features/storyboard/motion-revision.ts b/src/features/storyboard/motion-revision.ts
new file mode 100644
index 0000000..a9c8bb7
--- /dev/null
+++ b/src/features/storyboard/motion-revision.ts
@@ -0,0 +1,148 @@
+import type { MotionBeat, MotionIssue } from './motion.types'
+import type { ShotKeyframe } from '../production/types'
+import type { WorkflowExecution } from '../workflows/execution.types'
+
+/** 可编辑的完整动作规划,与后端 schema 一致。 */
+export interface MotionPlan {
+ /** 一至五个动作阶段。 */
+ beats: MotionBeat[]
+ /** 一至八条整体运动约束。 */
+ globalMotionConstraints: string[]
+}
+/** 不可变动作修订,生效状态由后端返回。 */
+export interface MotionRevision {
+ /** 修订 ID。 */
+ revisionId: string
+ /** 所属镜头。 */
+ shotId: string
+ /** 修订来源。 */
+ source: 'ai_original' | 'manual'
+ /** 实际父版本。 */
+ parentRevisionId: string | null
+ /** 修改原因。 */
+ reason: string | null
+ /** 完整规划快照。 */
+ motionPlan: MotionPlan
+ /** 镜头时长。 */
+ durationSeconds: number
+ /** 服务端内容指纹。 */
+ fingerprint: string
+ /** ISO 创建时间。 */
+ createdAt: string
+ /** 是否生效。 */
+ isActive: boolean
+}
+/** 空历史与空生效指针均为合法状态。 */
+export interface MotionRevisionHistory {
+ /** 镜头 ID。 */
+ shotId: string
+ /** 原始封存版本。 */
+ originalRevisionId: string | null
+ /** 当前生效版本。 */
+ activeRevisionId: string | null
+ /** 所有版本。 */
+ revisions: MotionRevision[]
+}
+/** 免费预检查不授予激活权限。 */
+export interface MotionRevisionPreview {
+ /** 镜头 ID。 */
+ shotId: string
+ /** 仅结构合法。 */
+ valid: boolean
+ /** 通过结构检查后的指纹。 */
+ motionPlanFingerprint: string | null
+ /** 结构错误位置与原因。 */
+ schemaIssues: { path: string; message: string }[]
+ /** 时间预警。 */
+ timelineIssues: MotionIssue[]
+ /** 密度预警。 */
+ actionDensityIssues: MotionIssue[]
+ /** 必须进一步视觉校验。 */
+ requiresStartStateValidation: true
+ /** 预检查不能激活。 */
+ canActivate: false
+ /** 不调用模型。 */
+ willCallModel: false
+ /** 不修改资产。 */
+ willModifyAssets: false
+}
+/** 起点视觉校验的实际问题结构。 */
+export interface MotionValidationIssue {
+ /** 起点冲突种类。 */
+ type: 'state_replay' | 'keyframe_conflict' | 'subject_spawn_risk'
+ /** 警告或错误。 */
+ severity: 'warning' | 'error'
+ /** 问题说明。 */
+ description: string
+ /** 涉及主体。 */
+ subjectRef?: string
+}
+/** 任务完成后的视觉证据;完成不代表通过。 */
+export interface MotionValidationResult {
+ /** 镜头 ID。 */
+ shotId: string
+ /** 被校验版本。 */
+ revisionId: string
+ /** 被校验内容指纹。 */
+ fingerprint: string
+ /** 主首帧 ID。 */
+ primaryKeyframeId: string
+ /** 主首帧图片地址。 */
+ primaryKeyframeImageUrl: string
+ /** 校验启动时的生效指针。 */
+ expectedRevisionId: string | null
+ /** 后端最终通过标记。 */
+ passed: boolean
+ /** 是否失效。 */
+ stale: boolean
+ /** 汇总问题。 */
+ issues: MotionValidationIssue[]
+ /** 汇总说明。 */
+ summary: string
+ /** 模型校验结论。 */
+ validation: {
+ /** 是否通过视觉检查。 */
+ passed: boolean
+ /** 是否重演首帧状态。 */
+ stateReplayDetected: boolean
+ /** 模型问题。 */
+ issues: MotionValidationIssue[]
+ /** 模型说明。 */
+ summary: string
+ }
+}
+/**
+ * 只接受完整且仍绑定当前修订、主首帧和生效版本的已通过证据。
+ * @param execution 持久化任务
+ * @param revision 已保存修订
+ * @param primary 当前主首帧
+ * @param activeRevisionId 当前生效版本
+ * @returns 是否允许请求激活
+ */
+export function motionEvidenceCurrent(
+ execution: WorkflowExecution | null,
+ revision: MotionRevision | null,
+ primary: ShotKeyframe | null,
+ activeRevisionId: string | null
+): boolean {
+ const result = execution?.result
+ const validation = result?.validation as MotionValidationResult['validation'] | undefined
+ return !!(
+ execution?.status === 'completed' &&
+ execution.workflowName === 'motion-plan-start-state-validation' &&
+ revision &&
+ primary?.imageUrl &&
+ primary.status === 'completed' &&
+ primary.isPrimary &&
+ primary.source !== 'provider_variant' &&
+ result?.passed === true &&
+ result.stale === false &&
+ validation?.passed === true &&
+ result.shotId === revision.shotId &&
+ result.revisionId === revision.revisionId &&
+ result.fingerprint === revision.fingerprint &&
+ result.primaryKeyframeId === primary.id &&
+ result.primaryKeyframeImageUrl === primary.imageUrl &&
+ result.expectedRevisionId === activeRevisionId
+ )
+}
diff --git a/src/features/storyboard/motion.types.ts b/src/features/storyboard/motion.types.ts
index 1e2dabe..f9daaea 100644
--- a/src/features/storyboard/motion.types.ts
+++ b/src/features/storyboard/motion.types.ts
@@ -19,6 +19,12 @@ export interface MotionBeat {
/** 单镜头动作时间轴详情,实时审计与历史生成记录分别保存。 */
export interface MotionPlanPreview {
+ /** 当前生效规划来源。 */
+ source?: 'ai_original' | 'manual' | null
+ /** 当前生效修订,历史镜头可为空。 */
+ activeRevisionId?: string | null
+ /** 生效规划内容指纹。 */
+ motionPlanFingerprint?: string | null
shotId: string
episodeNo: number
beatNo: number
diff --git a/src/features/storyboard/useMotionRevision.ts b/src/features/storyboard/useMotionRevision.ts
new file mode 100644
index 0000000..225cb0d
--- /dev/null
+++ b/src/features/storyboard/useMotionRevision.ts
@@ -0,0 +1,352 @@
+import { computed, ref, watch, onScopeDispose, type Ref } from 'vue'
+import { usePolling } from '../../composables/usePolling'
+import { motionApi } from './motion-api'
+import { productionApi } from '../production/api'
+import { useWorkflowExecution } from '../workflows/execution'
+import { getOperation, runOperation } from '../workflows/operations'
+import { ApiError, errorMessage } from '../../lib/http'
+import { motionEvidenceCurrent, type MotionPlan, type MotionRevisionPreview } from './motion-revision'
+
+/**
+ * 管理一个镜头的完整草稿、免费预检、保存和付费视觉任务;切镜后丢弃迟到 UI 更新。
+ * @param props 当前镜头与项目
+ * @param open 编辑面板可见状态
+ * @param changed 激活成功后通知外层刷新资产和就绪状态
+ * @returns 表单状态与明确操作入口
+ */
+export function useMotionRevision(
+ props: { projectId: string; shotId: string; disabled?: boolean },
+ open: Ref,
+ changed: () => void
+) {
+ /** 任务观察按项目隔离,真实状态来自持久化接口。 */
+ const project = computed(() => props.projectId)
+ const execution = useWorkflowExecution(project, 'motion-plan-start-state-validation')
+ /** 原目标身份同时用于废弃迟到响应。 */
+ const identity = computed(() => JSON.stringify([props.projectId, props.shotId]))
+ /** 面板关闭后不发起普通查询;活动任务仍由任务观察器恢复。 */
+ const key = computed(() => (open.value ? identity.value : ''))
+ /** 查询期间显示已有后端数据,但出错时禁用所有写入。 */
+ const context = usePolling(
+ key,
+ async (value, signal) => {
+ if (!value) return null
+ const [, shotId] = JSON.parse(value) as [string, string]
+ const [history, preview, keyframes] = await Promise.all([
+ motionApi.revisions(shotId, signal),
+ motionApi.preview(shotId, signal),
+ productionApi.listKeyframes(shotId, signal)
+ ])
+ if (
+ history.shotId !== shotId ||
+ preview.shotId !== shotId ||
+ keyframes.some(item => item.shotId !== shotId)
+ )
+ throw new Error('动作修订或首帧与当前镜头不匹配。')
+ return {
+ history,
+ preview,
+ primary:
+ keyframes.find(
+ item => item.isPrimary && item.status === 'completed' && item.source !== 'provider_variant'
+ ) ?? null
+ }
+ },
+ computed(() => (open.value ? 5000 : false))
+ )
+ /** 当前选择的已保存版本;空值表示从历史 AI 预览开始。 */
+ const selectedId = ref('')
+ /** 全字段动作草稿,不允许自动生成占位阶段。 */
+ const draft = ref({ beats: [], globalMotionConstraints: [] })
+ /** 人工修改原因。 */
+ const reason = ref('')
+ /** 只保留当前草稿的免费预检查。 */
+ const preview = ref(null)
+ /** 明确确认视觉模型费用。 */
+ const acknowledged = ref(false)
+ /** 草稿或输入变化后不再认可旧视觉证据。 */
+ const invalidated = ref(false)
+ /** 本次请求错误独立于只读查询。 */
+ const error = ref('')
+ /** 激活成功的提示词更新说明。 */
+ const notice = ref('')
+ /** 拷贝历史时不误判为用户修改。 */
+ let copying = false
+ /** 卸载后不更新当前界面。 */
+ let disposed = false
+ onScopeDispose(() => {
+ disposed = true
+ })
+ /** 当前后端保存版本,不以草稿代替不可变修订。 */
+ const revision = computed(
+ () => context.data.value?.history.revisions.find(item => item.revisionId === selectedId.value) ?? null
+ )
+ /** 草稿与所选修订内容保持一致才可校验或激活。 */
+ const saved = computed(
+ () => !!revision.value && JSON.stringify(draft.value) === JSON.stringify(revision.value.motionPlan)
+ )
+ /** 项目已有请求或后台任务时禁止重复发起。 */
+ const pending = computed(() => getOperation(props.projectId).pending)
+ /** 自动核对输入期间允许继续填写草稿,不让定时查询打断输入焦点。 */
+ const formBlocked = computed(
+ () => !!props.disabled || pending.value || !!context.error.value || !context.data.value
+ )
+ /** 后端查询缺失或失败时不使用旧数据提交。 */
+ const blocked = computed(
+ () => !!props.disabled || pending.value || context.loading.value || !!context.error.value || !context.data.value
+ )
+ /** 当前任务只展示本镜头记录,其他镜头任务不充当证据。 */
+ const record = computed(() => {
+ const item = execution.query.data.value
+ return item?.metadata?.shotId === props.shotId || item?.result?.shotId === props.shotId ? item : null
+ })
+ /** 完成、通过、未失效且所有绑定匹配才开放激活。 */
+ const evidenceValid = computed(
+ () =>
+ saved.value &&
+ !invalidated.value &&
+ motionEvidenceCurrent(
+ record.value,
+ revision.value,
+ context.data.value?.primary ?? null,
+ context.data.value?.history.activeRevisionId ?? null
+ )
+ )
+ /** 查询与请求进行中临时禁用提交,不把有效证据误显示为失效。 */
+ const canActivate = computed(() => !blocked.value && evidenceValid.value)
+ /** 当前版本和主首帧输入变化也撤销费用确认及旧证据。 */
+ const binding = computed(() =>
+ JSON.stringify([
+ context.data.value?.history.activeRevisionId ?? null,
+ context.data.value?.primary?.id ?? null,
+ context.data.value?.primary?.imageUrl ?? null
+ ])
+ )
+ watch(binding, (_value, old) => {
+ if (old && old !== '[null,null,null]') invalidated.value = true
+ acknowledged.value = false
+ })
+ watch(
+ draft,
+ () => {
+ preview.value = null
+ acknowledged.value = false
+ if (!copying) invalidated.value = true
+ },
+ { deep: true, flush: 'sync' }
+ )
+ watch([identity, open], () => {
+ selectedId.value = ''
+ draft.value = { beats: [], globalMotionConstraints: [] }
+ preview.value = null
+ reason.value = ''
+ error.value = ''
+ notice.value = ''
+ acknowledged.value = false
+ })
+ /**
+ * 复制所选版本或真实 AI 规划;改变来源后须重新取得视觉证据。
+ * @param id 所选版本 ID,空值使用预览
+ * @param initial 首次恢复允许核对已持久化任务
+ */
+ function select(id: string, initial = false) {
+ const value = context.data.value
+ if (!value) return
+ const source =
+ value.history.revisions.find(item => item.revisionId === id)?.motionPlan ??
+ (id ? null : { beats: value.preview.beats, globalMotionConstraints: value.preview.globalMotionConstraints })
+ if (!source) return
+ copying = true
+ selectedId.value = id
+ draft.value = JSON.parse(JSON.stringify(source)) as MotionPlan
+ copying = false
+ preview.value = null
+ reason.value = ''
+ acknowledged.value = false
+ invalidated.value = !initial
+ notice.value = ''
+ }
+ watch(
+ () => context.data.value,
+ value => {
+ if (value && !selectedId.value && draft.value.beats.length === 0)
+ select(
+ value.history.activeRevisionId ??
+ value.history.originalRevisionId ??
+ value.history.revisions.at(-1)?.revisionId ??
+ '',
+ true
+ )
+ }
+ )
+ /** 刷新或重开时恢复同镜头的真实任务版本;用户修改后不恢复旧资格。 */
+ watch([() => context.data.value, record], ([value, task]) => {
+ const id = task?.metadata?.revisionId
+ if (
+ value &&
+ typeof id === 'string' &&
+ !invalidated.value &&
+ !preview.value &&
+ value.history.revisions.some(item => item.revisionId === id) &&
+ selectedId.value !== id &&
+ (saved.value || draft.value.beats.length === 0)
+ )
+ select(id, true)
+ })
+ /**
+ * 发起一次明确操作;冲突后刷新绑定,成功也校验响应目标。
+ * @param label 操作说明
+ * @param action 固定原镜头操作
+ */
+ async function perform(label: string, action: () => Promise) {
+ if (blocked.value) return
+ const target = identity.value
+ error.value = ''
+ notice.value = ''
+ await runOperation(props.projectId, label, async () => {
+ try {
+ await action()
+ } catch (cause) {
+ if (!disposed && identity.value === target) {
+ error.value = errorMessage(cause)
+ if (cause instanceof ApiError && cause.status === 409) {
+ invalidated.value = true
+ acknowledged.value = false
+ await context.refresh()
+ changed()
+ }
+ }
+ throw cause
+ }
+ })
+ }
+ /** 免费检查本次完整草稿;编辑或切镜后丢弃迟到回执。 */
+ async function precheck() {
+ const shotId = props.shotId
+ const plan = JSON.parse(JSON.stringify(draft.value)) as MotionPlan
+ const signature = JSON.stringify(plan)
+ await perform('免费检查动作修订', async () => {
+ const result = await motionApi.previewRevision(shotId, plan)
+ if (!disposed && props.shotId === shotId && signature === JSON.stringify(draft.value)) {
+ if (result.shotId !== shotId) throw new Error('预检查回执与镜头不匹配。')
+ preview.value = result
+ }
+ })
+ }
+ /** 保存必须先获得当前草稿的结构通过结果,不激活或调用模型。 */
+ async function save() {
+ if (preview.value?.valid !== true) return
+ const target = identity.value
+ const shotId = props.shotId
+ const plan = JSON.parse(JSON.stringify(draft.value)) as MotionPlan
+ const parentRevisionId = selectedId.value || null
+ await perform('保存动作修订', async () => {
+ const result = await motionApi.saveRevision(shotId, {
+ motionPlan: plan,
+ parentRevisionId,
+ reason: reason.value.trim() || null
+ })
+ if (result.shotId !== shotId || result.source !== 'manual' || result.isActive || !result.revisionId)
+ throw new Error('保存回执不是当前镜头的未生效人工版本。')
+ if (disposed || identity.value !== target) return
+ await context.refresh()
+ select(result.revisionId)
+ notice.value = '修订已保存,尚未生效;请确认模型费用后校验。'
+ })
+ }
+ /** 用户确认费用后重新读取首帧与生效指针,再启动视觉模型。 */
+ async function validate() {
+ if (!acknowledged.value || !saved.value || !revision.value || !context.data.value?.primary) return
+ const target = identity.value
+ const selected = revision.value
+ const originalProjectId = props.projectId
+ const expectedBinding = binding.value
+ acknowledged.value = false
+ await perform('校验动作修订起点', async () => {
+ await context.refresh()
+ if (
+ disposed ||
+ identity.value !== target ||
+ context.error.value ||
+ expectedBinding !== binding.value ||
+ !saved.value
+ )
+ throw new Error('主首帧或生效版本已变化,请刷新并重新确认费用。')
+ const primary = context.data.value?.primary
+ if (!primary?.imageUrl) throw new Error('尚无有效主首帧,不能启动视觉校验。')
+ const result = await motionApi.validateRevision(selected.shotId, selected.revisionId, {
+ primaryKeyframeId: primary.id,
+ expectedRevisionId: context.data.value!.history.activeRevisionId
+ })
+ if (!result.executionId || result.willCallModel !== true)
+ throw new Error('未返回有效视觉校验任务,请刷新,勿重复提交。')
+ if (!disposed && identity.value === target) invalidated.value = false
+ await execution.track(result.executionId, originalProjectId)
+ })
+ }
+ /** 激活前再次刷新并核对全部证据,成功后通知两个工作区同步。 */
+ async function activate() {
+ if (!canActivate.value || !revision.value || !record.value) return
+ const target = identity.value
+ const selected = revision.value
+ const taskId = record.value.id
+ await perform('激活动作修订', async () => {
+ await context.refresh()
+ if (
+ disposed ||
+ identity.value !== target ||
+ context.error.value ||
+ !saved.value ||
+ invalidated.value ||
+ !motionEvidenceCurrent(
+ record.value,
+ selected,
+ context.data.value?.primary ?? null,
+ context.data.value?.history.activeRevisionId ?? null
+ )
+ )
+ throw new Error('视觉证据已失效,请重新校验当前修订。')
+ const result = await motionApi.activateRevision(props.shotId, selected.revisionId, {
+ expectedRevisionId: context.data.value!.history.activeRevisionId,
+ validationExecutionId: taskId
+ })
+ if (
+ result.shotId !== selected.shotId ||
+ result.activeRevisionId !== selected.revisionId ||
+ result.motionPlanFingerprint !== selected.fingerprint
+ )
+ throw new Error('激活回执与目标版本不匹配,请刷新核对。')
+ if (disposed || identity.value !== target) return
+ await context.refresh()
+ changed()
+ notice.value = result.videoPromptStale
+ ? '修订已生效。请重新生成视频提示词;旧视频候选仍保留,未自动提交生成任务。'
+ : '此版本已生效。'
+ })
+ }
+ return {
+ context,
+ selectedId,
+ draft,
+ reason,
+ preview,
+ acknowledged,
+ error,
+ notice,
+ revision,
+ saved,
+ pending,
+ blocked,
+ formBlocked,
+ record,
+ execution,
+ canActivate,
+ evidenceValid,
+ invalidated,
+ select,
+ precheck,
+ save,
+ validate,
+ activate
+ }
+}
diff --git a/src/features/workflows/WorkflowExecutionPanel.vue b/src/features/workflows/WorkflowExecutionPanel.vue
index 8b33d1c..232b2e2 100644
--- a/src/features/workflows/WorkflowExecutionPanel.vue
+++ b/src/features/workflows/WorkflowExecutionPanel.vue
@@ -32,13 +32,46 @@ const statusLabel = computed(() => {
const labels = { pending: '等待开始', running: '执行中', completed: '已完成', failed: '失败' }
return props.execution ? labels[props.execution.status] : ''
})
-const statusType = computed(() =>
- props.execution?.status === 'completed' ? 'success' : props.execution?.status === 'failed' ? 'error' : 'warning'
-)
const finished = computed(() => ['completed', 'failed'].includes(props.execution?.status ?? ''))
/** 是否为剧本创作任务,避免使用镜头素材的提示文案。 */
const scriptCreation = computed(() => props.execution?.workflowName === 'create-drama')
+/** 视频质量任务使用后端聚合后的候选终态统计。 */
const videoQuality = computed(() => props.execution?.workflowName === 'video-quality')
+/** 旧任务没有版本过期计数时按零展示,仅接受后端非负整数计数。 */
+const staleMotionPlanCount = computed(() => {
+ const count =
+ props.execution?.status === 'completed'
+ ? result.value.staleMotionPlan
+ : props.execution?.metadata?.staleMotionPlan
+ return typeof count === 'number' && Number.isSafeInteger(count) && count >= 0 ? count : 0
+})
+/** 视频流程结束但含过期候选时使用警告标签,不显示全成功的绿色状态。 */
+const statusType = computed(() =>
+ props.execution?.status === 'completed'
+ ? videoQuality.value && staleMotionPlanCount.value > 0
+ ? 'warning'
+ : 'success'
+ : props.execution?.status === 'failed'
+ ? 'error'
+ : 'warning'
+)
+/** 逐镜终态从运行 metadata 或完成 result 读取,不根据历史通过猜测状态。 */
+const settledItems = computed(() => {
+ const settled = props.execution?.status === 'completed' ? result.value.settled : props.execution?.metadata?.settled
+ if (!settled || typeof settled !== 'object' || Array.isArray(settled)) return []
+ return Object.entries(settled).flatMap(([shotId, item]) => {
+ if (
+ !item ||
+ typeof item !== 'object' ||
+ !('status' in item) ||
+ !('videoId' in item) ||
+ typeof item.status !== 'string' ||
+ typeof item.videoId !== 'string'
+ )
+ return []
+ return [{ shotId, status: item.status, videoId: item.videoId }]
+ })
+})
/** 首帧质量后台任务使用独立的通过与修复失败统计,不套用普通生图字段。 */
const keyframeQuality = computed(() => props.execution?.workflowName === 'keyframe-quality')
/** 首帧编辑复用质量工作流,最终回执不属于批量质量统计。 */
@@ -156,10 +189,12 @@ function isInputMode(value: unknown, inputMode: string): boolean {
: result.validationSkipped === true
? 'info'
: 'warning'
- : keyframeQuality &&
- (!keyframeCounts || keyframeCounts.repairFailed + keyframeCounts.failed > 0)
+ : videoQuality && staleMotionPlanCount > 0
? 'warning'
- : 'success'
+ : keyframeQuality &&
+ (!keyframeCounts || keyframeCounts.repairFailed + keyframeCounts.failed > 0)
+ ? 'warning'
+ : 'success'
"
:show-icon="false"
class="mt-3"
@@ -174,7 +209,12 @@ function isInputMode(value: unknown, inputMode: string): boolean {
目标 {{ result.targetCount ?? execution.total }} · 通过 {{ result.passed ?? 0 }} · 修复耗尽
{{ result.exhausted ?? 0 }} · 模型失败 {{ result.providerFailed ?? 0 }} · 提交失败
- {{ result.submissionFailed ?? 0 }}
+ {{ result.submissionFailed ?? 0 }} · 动作版本过期 {{ staleMotionPlanCount }}
+
+
+
+ {{ staleMotionPlanCount }}
+ 个镜头的候选因动作规划版本变化已停止质量流程。请先更新视频提示词,再按当前动作规划重新生成视频。
输入规划:首帧模式 {{ inputPlanCounts.firstFrame }} · 全模态参考
@@ -215,8 +255,27 @@ function isInputMode(value: unknown, inputMode: string): boolean {
任务详情
任务编号 · {{ execution.id }}
+
+
+ -
+ 查看镜头
+ · {{ executionStageLabel(item.status) }} · 视频 {{ item.videoId }}
+
+
+
+
+ 动作版本过期 {{ staleMotionPlanCount }} · 这些候选已停止质量流程,其余镜头继续处理。
+
{{ error }}。任务可能仍在运行,请先重新读取状态;不要直接重复提交。
重试读取
diff --git a/src/features/workflows/execution.ts b/src/features/workflows/execution.ts
index ad60162..a34973c 100644
--- a/src/features/workflows/execution.ts
+++ b/src/features/workflows/execution.ts
@@ -76,6 +76,7 @@ export function executionStageLabel(stage: string | null) {
provider_failed: '模型生成失败',
submission_failed: '任务提交失败',
completed: '执行完成',
+ stale_motion_plan: '动作版本过期,质量流程已停止',
failed: '执行失败'
}
return labels[stage] ?? stage
@@ -193,9 +194,24 @@ export function useWorkflowExecution(projectId: Ref, workflowName: strin
)
return
}
- const failures = ['failed', 'repairFailed', 'exhausted', 'providerFailed', 'submissionFailed'].some(
- field => typeof result[field] === 'number' && Number(result[field]) > 0
- )
+ if (record.workflowName === 'motion-plan-start-state-validation') {
+ const passed = result.passed === true && result.stale === false
+ message[passed ? 'info' : 'warning'](
+ passed
+ ? '动作起点视觉校验通过,请核对证据后手动激活。'
+ : '动作起点校验未通过或证据已失效,请查看任务结果。',
+ { duration: 6000, closable: true }
+ )
+ return
+ }
+ const failures = [
+ 'staleMotionPlan',
+ 'failed',
+ 'repairFailed',
+ 'exhausted',
+ 'providerFailed',
+ 'submissionFailed'
+ ].some(field => typeof result[field] === 'number' && Number(result[field]) > 0)
message[failures ? 'warning' : 'info'](
failures
? '本轮任务已结束,部分结果未通过或执行失败,请查看任务记录。'
diff --git a/src/lib/http.ts b/src/lib/http.ts
index 9eb0bdc..9d59dc1 100644
--- a/src/lib/http.ts
+++ b/src/lib/http.ts
@@ -3,7 +3,9 @@ export class ApiError extends Error {
constructor(
message: string,
public readonly status: number,
- public readonly details?: unknown
+ public readonly details?: unknown,
+ /** 同步接口的顶层业务错误码;普通 400 或网络错误可缺省。 */
+ public readonly code?: string
) {
super(message)
this.name = 'ApiError'
@@ -23,7 +25,12 @@ function isRecord(value: unknown): value is Record {
return typeof value === 'object' && value !== null && !Array.isArray(value)
}
-/** 兼容普通 {data} 响应,以及 POST /projects 的顶层 202 响应。 */
+/**
+ * 解析公开响应及顶层同步错误码,不自动重试写入。
+ * @param path 不含统一 API 前缀的正式路径
+ * @param options 方法、请求体及取消信号
+ * @returns 解包后的公开响应
+ */
export async function request(path: string, options: RequestOptions = {}): Promise {
const base = (import.meta.env.VITE_API_BASE_URL || '/api').replace(/\/$/, '')
const multipart = typeof FormData !== 'undefined' && options.body instanceof FormData
@@ -58,7 +65,8 @@ export async function request(path: string, options: RequestOptions = {}): Pr
throw new ApiError(
message,
response.status,
- isRecord(data) ? (data.details ?? data.issues ?? data.error) : data
+ isRecord(data) ? (data.details ?? data.issues ?? data.error) : data,
+ isRecord(data) && typeof data.code === 'string' ? data.code : undefined
)
}
return (isRecord(data) && 'data' in data ? data.data : data) as T
diff --git a/src/styles/admin.css b/src/styles/admin.css
index ea7419f..c5ec58e 100644
--- a/src/styles/admin.css
+++ b/src/styles/admin.css
@@ -193,6 +193,10 @@ body {
.workspace-section-stack > * {
margin-block: 0 !important;
}
+/* 独立详情模块采用两倍全局间距,避免 gap 与模块顶部留白叠加。 */
+.workspace-section-stack.workspace-section-stack-spacious {
+ gap: calc(var(--app-content-gap) * 2);
+}
.workspace-panel {
padding: 20px;
background: var(--app-subtle);
diff --git a/tests/features/production/public-assets.test.ts b/tests/features/production/public-assets.test.ts
index e25df55..0cd34be 100644
--- a/tests/features/production/public-assets.test.ts
+++ b/tests/features/production/public-assets.test.ts
@@ -62,7 +62,7 @@ const record = (workflowName: string, day: number, status: 'running' | 'complete
})
describe('精简公开资产回归', () => {
- it('无内部字段的视频可播放,未知质量不得直接晋升;真实校验结果按项目隔离', async () => {
+ it('无内部字段的视频可播放,晋升使用后端权限,会话通过不能授权', async () => {
const projectId = 'public-video-contract'
const video = videoFixture({ isPrimary: false })
expect(video).not.toHaveProperty('rawJson')
@@ -104,7 +104,7 @@ describe('精简公开资产回归', () => {
await flushPromises()
expect(
[...document.querySelectorAll('button')].some(button => button.textContent?.trim() === '设为主视频')
- ).toBe(true)
+ ).toBe(false)
expect(sessionVideoValidation('other-project', shot.shotId, video.id)).toBeNull()
session.videoValidation = { ...validation, passed: false }
await flushPromises()
diff --git a/tests/features/production/quality.test.ts b/tests/features/production/quality.test.ts
index d849986..98f878d 100644
--- a/tests/features/production/quality.test.ts
+++ b/tests/features/production/quality.test.ts
@@ -1,3 +1,4 @@
+import { ApiError } from '@/lib/http'
import { defineComponent, reactive, ref } from 'vue'
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
import { afterEach, describe, expect, it, vi } from 'vitest'
@@ -542,11 +543,27 @@ describe('质量面板渐进展示', () => {
})
describe('视频修复候选与复检晋升', () => {
- it('只允许校验未通过的视频创建一个候选,不自动再次校验', async () => {
+ it('视频修复遇到同步版本冲突后撤销本会话旧资格并刷新', async () => {
+ const data = setup({ kind: 'video', shotId: 'shot-1', assetId: 'video-1', title: '视频' })
+ data.video.canRepair = true
+ data.validation.passed = false
+ await data.service.run('validate', input())
+ expect(sessionVideoValidation(data.projectId, 'shot-1', 'video-1')?.passed).toBe(false)
+ vi.spyOn(qualityApi, 'repairVideo').mockRejectedValueOnce(
+ new ApiError('动作版本已过期', 409, { currentMotionPlanRevisionId: 'r2' }, 'MOTION_PLAN_STALE')
+ )
+ await data.service.run('repair', input({ maxRepairAttempts: 2 }))
+ expect(sessionVideoValidation(data.projectId, 'shot-1', 'video-1')).toBeNull()
+ expect(data.service.session.value.error).toContain('动作版本已过期')
+ expect(qualityApi.repairVideo).toHaveBeenCalledTimes(1)
+ })
+
+ it('只允许后端授予修复权限的视频创建候选,不自动再次校验', async () => {
const data = setup({ kind: 'video', shotId: 'shot-1', assetId: 'video-1', title: '视频' })
await data.service.run('repair', input({ maxRepairAttempts: 2 }))
expect(data.posts()).toHaveLength(0)
data.validation.passed = false
+ data.video.canRepair = true
await data.service.run('validate', input())
data.fetcher.mockClear()
await data.service.run('repair', input({ maxRepairAttempts: 2 }))
@@ -562,6 +579,7 @@ describe('视频修复候选与复检晋升', () => {
it('修复不接受零次上限,后端次数限制错误原样保留且不重试', async () => {
const data = setup({ kind: 'video', shotId: 'shot-1', assetId: 'video-1', title: '视频' })
data.validation.passed = false
+ data.video.canRepair = true
await data.service.run('validate', input())
data.fetcher.mockClear()
await data.service.run('repair', input({ maxRepairAttempts: 0 }))
diff --git a/tests/features/production/video-permissions.test.ts b/tests/features/production/video-permissions.test.ts
new file mode 100644
index 0000000..7f105e4
--- /dev/null
+++ b/tests/features/production/video-permissions.test.ts
@@ -0,0 +1,22 @@
+import { describe, expect, it } from 'vitest'
+import { videoOperationAllowed } from '@/features/production/video-permissions'
+import { videoFixture } from '@/features/production/testing/fixtures'
+
+describe('视频候选操作权限', () => {
+ it('每个候选独立使用后端权限,两个空版本不自行视为过期', () => {
+ const first = videoFixture({ canValidate: false, canRepair: true, canSetPrimary: false })
+ const second = videoFixture({ canValidate: true, canRepair: false, canSetPrimary: true })
+ expect(videoOperationAllowed(first, 'validate')).toBe(false)
+ expect(videoOperationAllowed(first, 'repair')).toBe(true)
+ expect(videoOperationAllowed(second, 'repair')).toBe(false)
+ expect(videoOperationAllowed(second, 'primary')).toBe(true)
+ })
+ it.each(['validate', 'repair', 'primary'] as const)('过期或已终止候选不能执行 %s,即使曾经通过', action => {
+ const permissions = { canValidate: true, canRepair: true, canSetPrimary: true }
+ expect(videoOperationAllowed(videoFixture({ ...permissions, motionPlanStale: true }), action)).toBe(false)
+ expect(
+ videoOperationAllowed(videoFixture({ ...permissions, qualityTerminalStatus: 'stale_motion_plan' }), action)
+ ).toBe(false)
+ })
+ it('缺失权限不能当作允许操作', () => expect(videoOperationAllowed({}, 'validate')).toBe(false))
+})
diff --git a/tests/features/production/video-quality-record.test.ts b/tests/features/production/video-quality-record.test.ts
index cfb5bb0..0c76c5d 100644
--- a/tests/features/production/video-quality-record.test.ts
+++ b/tests/features/production/video-quality-record.test.ts
@@ -15,6 +15,14 @@ const qualityStatus: ShotVideoQualityStatus = {
chain: [
{
videoId: 'video-failed',
+ motionPlanRevisionId: null,
+ currentMotionPlanRevisionId: null,
+ motionPlanStale: false,
+ qualityTerminalStatus: null,
+ staleReason: null,
+ canValidate: true,
+ canRepair: false,
+ canSetPrimary: false,
providerStatus: 'completed',
isPrimary: false,
repairAttempt: 0,
@@ -25,6 +33,14 @@ const qualityStatus: ShotVideoQualityStatus = {
},
{
videoId: 'video-passed',
+ motionPlanRevisionId: null,
+ currentMotionPlanRevisionId: null,
+ motionPlanStale: false,
+ qualityTerminalStatus: null,
+ staleReason: null,
+ canValidate: true,
+ canRepair: false,
+ canSetPrimary: false,
providerStatus: 'completed',
isPrimary: true,
repairAttempt: 1,
diff --git a/tests/features/storyboard/motion-revision.test.ts b/tests/features/storyboard/motion-revision.test.ts
new file mode 100644
index 0000000..46a1b12
--- /dev/null
+++ b/tests/features/storyboard/motion-revision.test.ts
@@ -0,0 +1,115 @@
+import { describe, expect, it, vi, afterEach } from 'vitest'
+import { motionEvidenceCurrent, type MotionRevision } from '@/features/storyboard/motion-revision'
+import { motionApi } from '@/features/storyboard/motion-api'
+import { keyframeFixture } from '@/features/production/testing/fixtures'
+import type { WorkflowExecution } from '@/features/workflows/execution.types'
+
+/** 完整的不可变修订,供证据绑定验证。 */
+const revision: MotionRevision = {
+ revisionId: 'r1',
+ shotId: 'shot-1',
+ source: 'manual',
+ parentRevisionId: null,
+ reason: '调整动作',
+ fingerprint: 'fp1',
+ createdAt: '2026-10-14T00:00:00Z',
+ isActive: false,
+ durationSeconds: 4,
+ motionPlan: {
+ beats: [
+ {
+ startSecond: 0,
+ endSecond: 4,
+ action: '人物缓慢行走',
+ cameraMotion: '保持静止',
+ physicalContinuity: '动作连贯自然',
+ subjectRefs: ['@CH0001'],
+ closingState: '停在画面中央'
+ }
+ ],
+ globalMotionConstraints: ['保持动作连续']
+ }
+}
+/** 真正完成并通过的后台证据,指针为空表示历史 AI 生效状态。 */
+const primary = keyframeFixture()
+const execution: WorkflowExecution = {
+ id: 'e1',
+ projectId: 'p1',
+ workflowName: 'motion-plan-start-state-validation',
+ status: 'completed',
+ stage: 'completed',
+ current: 1,
+ total: 1,
+ currentResourceId: null,
+ metadata: { shotId: 'shot-1' },
+ error: null,
+ startedAt: null,
+ completedAt: null,
+ createdAt: '',
+ updatedAt: '',
+ result: {
+ shotId: 'shot-1',
+ revisionId: 'r1',
+ fingerprint: 'fp1',
+ primaryKeyframeId: primary.id,
+ primaryKeyframeImageUrl: primary.imageUrl,
+ expectedRevisionId: null,
+ passed: true,
+ stale: false,
+ validation: { passed: true }
+ }
+}
+
+afterEach(() => vi.unstubAllGlobals())
+describe('动作修订激活证据', () => {
+ it('仅接受完成且通过的对应修订与首帧', () =>
+ expect(motionEvidenceCurrent(execution, revision, primary, null)).toBe(true))
+ it.each([
+ { passed: false },
+ { stale: true },
+ { revisionId: 'r2' },
+ { fingerprint: 'other' },
+ { shotId: 'shot-2' },
+ { validation: { passed: false } }
+ ])('拒绝失败、失效或不属于当前目标的证据 %j', patch => {
+ expect(
+ motionEvidenceCurrent({ ...execution, result: { ...execution.result, ...patch } }, revision, primary, null)
+ ).toBe(false)
+ })
+ it('任务结束不等于通过,活动任务也不能激活', () => {
+ expect(motionEvidenceCurrent({ ...execution, status: 'running' }, revision, primary, null)).toBe(false)
+ expect(motionEvidenceCurrent({ ...execution, status: 'failed' }, revision, primary, null)).toBe(false)
+ })
+ it('同 ID 首帧换图和生效指针变化都撤销证据', () => {
+ expect(motionEvidenceCurrent(execution, revision, { ...primary, imageUrl: '/new.png' }, null)).toBe(false)
+ expect(motionEvidenceCurrent(execution, revision, primary, 'r2')).toBe(false)
+ })
+ it('保存显式发送空父版本,视觉校验发送当前生效指针,激活发送真实任务 ID', async () => {
+ const fetcher = vi.fn().mockImplementation(async () => new Response('{"data":{}}'))
+ vi.stubGlobal('fetch', fetcher)
+ await motionApi.previewRevision('s/1', revision.motionPlan)
+ await motionApi.saveRevision('s/1', { motionPlan: revision.motionPlan, parentRevisionId: null, reason: null })
+ await motionApi.validateRevision('s/1', 'r/1', { primaryKeyframeId: primary.id, expectedRevisionId: null })
+ await motionApi.activateRevision('s/1', 'r/1', { expectedRevisionId: null, validationExecutionId: 'e1' })
+ const calls = fetcher.mock.calls
+ expect(calls.map(([url]) => url)).toEqual([
+ '/api/storyboard-shots/s%2F1/motion-plan/revisions/preview',
+ '/api/storyboard-shots/s%2F1/motion-plan/revisions',
+ '/api/storyboard-shots/s%2F1/motion-plan/revisions/r%2F1/start-state-validation/start',
+ '/api/storyboard-shots/s%2F1/motion-plan/revisions/r%2F1/active'
+ ])
+ expect(JSON.parse(String(calls[1]?.[1]?.body))).toEqual({
+ motionPlan: revision.motionPlan,
+ parentRevisionId: null,
+ reason: null
+ })
+ expect(JSON.parse(String(calls[2]?.[1]?.body))).toEqual({
+ primaryKeyframeId: primary.id,
+ expectedRevisionId: null
+ })
+ expect(JSON.parse(String(calls[3]?.[1]?.body))).toEqual({
+ expectedRevisionId: null,
+ validationExecutionId: 'e1'
+ })
+ })
+})
diff --git a/tests/lib/http.test.ts b/tests/lib/http.test.ts
index b30f1b1..a8f6046 100644
--- a/tests/lib/http.test.ts
+++ b/tests/lib/http.test.ts
@@ -254,3 +254,24 @@ describe('后端 API 契约', () => {
}
})
})
+
+/** 同步版本冲突保留顶层错误码,资源与版本 ID 只位于 details。 */
+it('保留版本冲突的顶层 code 与独立 details', async () => {
+ const details = { shotId: 's1', currentActiveRevisionId: 'r2' }
+ vi.stubGlobal(
+ 'fetch',
+ vi
+ .fn()
+ .mockResolvedValue(
+ new Response(
+ JSON.stringify({ code: 'MOTION_PLAN_REVISION_CONFLICT', message: '生效版本变化', details }),
+ { status: 409 }
+ )
+ )
+ )
+ await expect(request('/test')).rejects.toMatchObject({
+ status: 409,
+ code: 'MOTION_PLAN_REVISION_CONFLICT',
+ details
+ })
+})