feat(short-drama-agent-front): 接入草案、首帧证据与审核继续
This commit is contained in:
1 parent
751106985e
commit
d0264c08ce
23 files changed
+990
-170
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import { keyframeScope } from './keyframe-scope'
|
||||
import { request } from '../../lib/http'
|
||||
import type { PromptBatchResult, StoryboardBatchInput } from '../storyboard/types'
|
||||
import type {
|
||||
@@ -156,8 +157,8 @@ export const productionApi = {
|
||||
}),
|
||||
listKeyframes: (shotId: string, signal?: AbortSignal) =>
|
||||
request<ShotKeyframe[]>(`${shotPath(shotId)}/keyframes`, { signal }),
|
||||
keyframeSpec: (shotId: string, signal?: AbortSignal) =>
|
||||
request<KeyframeSpec>(`${shotPath(shotId)}/keyframe-spec`, { signal }),
|
||||
keyframeSpec: (shotId: string, signal?: AbortSignal, projectId?: string) =>
|
||||
request<KeyframeSpec>(keyframeScope(`${shotPath(shotId)}/keyframe-spec`, projectId), { signal }),
|
||||
/** 按本次请求选择的图片模型与参数预览最终输入,不创建首帧任务。 */
|
||||
previewKeyframe: (
|
||||
shotId: string,
|
||||
|
||||
@@ -16,6 +16,8 @@ import type { ShotKeyframe } from '../types'
|
||||
/** 首帧卡片统一主图标识、质量结论和晋升限制。 */
|
||||
const props = defineProps<{
|
||||
item: ShotKeyframe
|
||||
/** 正式项目归属,用于查询候选审核。 */
|
||||
projectId?: string
|
||||
shotId: string
|
||||
/** 审核后递增以刷新持久化质量状态。 */
|
||||
reviewRevision?: number
|
||||
@@ -42,9 +44,13 @@ const emit = defineEmits<{
|
||||
}>()
|
||||
/** 每张可见候选可独立找回自己的审核任务。 */
|
||||
const visionKey = computed(() =>
|
||||
props.item.status === 'completed' ? JSON.stringify([props.shotId, props.item.id]) : ''
|
||||
props.item.status === 'completed'
|
||||
? JSON.stringify(
|
||||
props.projectId ? [props.shotId, props.item.id, props.projectId] : [props.shotId, props.item.id]
|
||||
)
|
||||
: ''
|
||||
)
|
||||
const vision = useKeyframeVision(visionKey)
|
||||
const vision = useKeyframeVision(visionKey, false)
|
||||
watch(
|
||||
() => vision.state.value.active,
|
||||
(active, previous) => {
|
||||
|
||||
@@ -20,7 +20,7 @@ import { errorMessage } from '../../../lib/http'
|
||||
import { productionApi } from '../api'
|
||||
import { directionLabel } from '../../storyboard/model'
|
||||
import type { ShotDirection, ShotVisualState } from '../../storyboard/types'
|
||||
import type { GenerateKeyframeInput, KeyframeGenerationPreview } from '../types'
|
||||
import type { GenerateKeyframeInput } from '../types'
|
||||
|
||||
/** 单镜头首帧表单;所有新图先生成候选,通过质量检查后再人工晋升。 */
|
||||
const props = defineProps<{
|
||||
@@ -38,8 +38,6 @@ const props = defineProps<{
|
||||
/** 仅发送已经确认的当前快照。 */
|
||||
submitGeneration: (input: GenerateKeyframeInput) => Promise<ImageGenerationSubmission>
|
||||
}>()
|
||||
/** 只读提供当次正式预览,候选必须匹配输入指纹才能展示。 */
|
||||
const emit = defineEmits<{ previewed: [preview: KeyframeGenerationPreview] }>()
|
||||
/** 当前候选生成窗口。 */
|
||||
const open = defineModel<boolean>('open', { default: false })
|
||||
/** 生成参数表单,用于复用字段校验。 */
|
||||
@@ -86,7 +84,6 @@ const {
|
||||
const shotId = props.shotId
|
||||
const result = await productionApi.previewKeyframe(shotId, input, signal)
|
||||
if (result?.shotId !== shotId) throw new Error('预览结果与当前镜头不匹配。')
|
||||
if (!signal.aborted && shotId === props.shotId) emit('previewed', result)
|
||||
return result
|
||||
},
|
||||
generate: input => props.submitGeneration({ ...input, setPrimary: false })
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue'
|
||||
import { NButton, NCollapse, NCollapseItem } from 'naive-ui'
|
||||
import { useQuery } from '../../../composables/useQuery'
|
||||
import ImageGenerationPreview from '../../subject-images/components/ImageGenerationPreview.vue'
|
||||
import { historicalReferenceUrl, loadKeyframeInput } from '../keyframe-input'
|
||||
import type { ImageGenerationPreview as ImagePreview } from '../../subject-images/generation-preview'
|
||||
|
||||
/** 只在展开后读取所选候选的实际生成输入。 */
|
||||
const props = defineProps<{
|
||||
/** 当前项目。 */ projectId: string
|
||||
/** 当前镜头。 */ shotId: string
|
||||
/** 当前候选。 */ keyframeId: string
|
||||
}>()
|
||||
/** 生成证据默认收起。 */
|
||||
const expanded = ref<string[]>([])
|
||||
/** 包含完整归属,切换候选即取消前一个请求。 */
|
||||
const key = computed(() =>
|
||||
expanded.value.includes('generation') ? JSON.stringify([props.projectId, props.shotId, props.keyframeId]) : ''
|
||||
)
|
||||
/** 从保存快照读取;不调用免费预览重建历史。 */
|
||||
const query = useQuery(key, async (value, signal) => {
|
||||
if (!value) return null
|
||||
const [projectId, shotId, keyframeId] = JSON.parse(value) as [string, string, string]
|
||||
const result = await loadKeyframeInput(projectId, shotId, keyframeId, signal)
|
||||
if (result.shotId !== shotId || result.keyframeId !== keyframeId) throw new Error('生成记录与当前候选不一致。')
|
||||
return result
|
||||
})
|
||||
/** 只有完整历史证据才能进入现有图片预览组件。 */
|
||||
const snapshot = computed(() =>
|
||||
query.data.value?.inputSnapshotStatus === 'recorded' ? query.data.value.providerInputSnapshot : null
|
||||
)
|
||||
/** 使用正式原件地址和真实模型参数展示历史快照。 */
|
||||
const display = computed<ImagePreview | null>(() => {
|
||||
const input = snapshot.value
|
||||
if (!input) return null
|
||||
return {
|
||||
provider: input.provider,
|
||||
model: input.model ?? '模型未记录',
|
||||
providerPrompt: input.providerPrompt,
|
||||
previewFingerprint: input.fingerprint,
|
||||
generationConfig: { options: input.generationOptions, width: input.width, height: input.height },
|
||||
providerInputSnapshot: input,
|
||||
referenceImages: input.references.map(
|
||||
reference => historicalReferenceUrl(reference, props.projectId, props.shotId, props.keyframeId) ?? ''
|
||||
)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<!-- 以下是当前候选生成输入的按需详情 -->
|
||||
<NCollapse v-model:expanded-names="expanded" class="mb-4">
|
||||
<NCollapseItem name="generation" title="当次参考图和画面描述">
|
||||
<p v-if="query.loading.value" role="status" class="text-xs text-muted">正在读取生成记录…</p>
|
||||
<NButton
|
||||
v-if="query.error.value || query.data.value"
|
||||
size="small"
|
||||
:disabled="query.loading.value"
|
||||
class="mb-3"
|
||||
@click="query.refresh"
|
||||
>刷新生成记录</NButton
|
||||
>
|
||||
<template v-if="display && snapshot">
|
||||
<p class="text-xs text-muted">
|
||||
快照版本 {{ snapshot.version
|
||||
}}<template v-if="snapshot.width && snapshot.height">
|
||||
· {{ snapshot.width }} × {{ snapshot.height }}</template
|
||||
>
|
||||
</p>
|
||||
<ImageGenerationPreview
|
||||
:preview="display"
|
||||
:historical-references="snapshot.references"
|
||||
:loading="false"
|
||||
error=""
|
||||
stale-notice=""
|
||||
display-only
|
||||
/>
|
||||
</template>
|
||||
<p v-else-if="query.data.value" class="text-xs text-muted">
|
||||
{{
|
||||
query.data.value.inputSnapshotStatus === 'not-recorded'
|
||||
? '这张首帧没有保存当次生成输入。'
|
||||
: '这张首帧的生成证据已损坏,无法读取。'
|
||||
}}
|
||||
</p>
|
||||
</NCollapseItem>
|
||||
</NCollapse>
|
||||
</template>
|
||||
@@ -26,6 +26,8 @@ const props = defineProps<{
|
||||
disabled?: boolean
|
||||
/** 在独立弹窗内直接展示内容,并隐藏内部标题、说明与操作栏。 */
|
||||
initialOpen?: boolean
|
||||
/** 已有审核弹窗的观察器,可共享同一订阅。 */
|
||||
observation?: ReturnType<typeof useKeyframeVision>
|
||||
}>()
|
||||
/** 通知候选重新读取当前质量状态。 */
|
||||
const emit = defineEmits<{ reviewed: [] }>()
|
||||
@@ -38,8 +40,14 @@ const key = computed(() =>
|
||||
: ''
|
||||
)
|
||||
/** 独立打开历史后恢复后台观察。 */
|
||||
const visionKey = computed(() => (key.value ? JSON.stringify([props.shotId, props.keyframeId]) : ''))
|
||||
const { history: query, execution, state, uncertain } = useKeyframeVision(visionKey)
|
||||
const visionKey = computed(() =>
|
||||
key.value
|
||||
? JSON.stringify(
|
||||
props.projectId ? [props.shotId, props.keyframeId, props.projectId] : [props.shotId, props.keyframeId]
|
||||
)
|
||||
: ''
|
||||
)
|
||||
const { history: query, execution, state, uncertain } = props.observation ?? useKeyframeVision(visionKey)
|
||||
/** 后台结束时同步刷新人工复核与候选状态。 */
|
||||
watch(
|
||||
() => state.value.active,
|
||||
@@ -234,7 +242,7 @@ const records = computed(() =>
|
||||
role="status"
|
||||
class="text-sm text-muted"
|
||||
>
|
||||
审核结果或费用待核查,请勿重复提交。
|
||||
{{ userFacingText(state.unknown?.recoveryReason, '审核结果或费用待核查,请勿重复提交。') }}
|
||||
</p>
|
||||
<p v-else-if="state.active" role="status" class="text-sm text-muted">
|
||||
审核{{ execution.data.value?.status === 'pending' ? '等待开始' : '在后台进行' }},关闭页面后仍会保存记录。
|
||||
@@ -254,9 +262,19 @@ const records = computed(() =>
|
||||
: '未取得完整视觉结论'
|
||||
}}
|
||||
</p>
|
||||
<p v-if="record.allowedTexts !== undefined" class="text-muted">
|
||||
原文字授权:{{
|
||||
record.allowedTexts === null
|
||||
? '无记录'
|
||||
: record.allowedTexts.length
|
||||
? record.allowedTexts.join('、')
|
||||
: '无额外授权文字'
|
||||
}}
|
||||
</p>
|
||||
<p v-if="record.recoveryReason" class="text-muted">{{ userFacingText(record.recoveryReason) }}</p>
|
||||
<p v-if="record.error" class="text-danger">{{ userFacingText(record.error) }}</p>
|
||||
<template v-if="record.validation">
|
||||
<p>{{ record.validation.summary }}</p>
|
||||
<p>合并结论:{{ userFacingText(record.validation.summary) }}</p>
|
||||
<p v-for="(issue, index) in record.validation.issues" :key="index" class="text-danger">
|
||||
{{ userFacingText(issue.description) }}
|
||||
</p>
|
||||
@@ -278,6 +296,15 @@ const records = computed(() =>
|
||||
{{ usageLabels[unit] }}词元:{{ count }}
|
||||
</div>
|
||||
</dl>
|
||||
<ul v-if="step.issues?.length" class="mt-2 space-y-1 text-xs">
|
||||
<li v-for="(issue, index) in step.issues" :key="index" class="text-danger">
|
||||
{{ issue.subjectRef ? issue.subjectRef + ' · ' : ''
|
||||
}}{{ userFacingText(issue.description) }}
|
||||
</li>
|
||||
</ul>
|
||||
<p v-else class="mt-2 text-xs text-muted">
|
||||
{{ step.issues ? '本步骤未发现结构化问题。' : '尚无此步骤的结构化问题记录。' }}
|
||||
</p>
|
||||
<p v-if="step.error" class="mt-2 text-danger">{{ userFacingText(step.error) }}</p>
|
||||
</NCollapseItem>
|
||||
</NCollapse>
|
||||
|
||||
@@ -54,14 +54,18 @@ const { key, session, operation, execution, blocked, run } = useQuality(
|
||||
)
|
||||
/** 打开首帧质量弹窗时读取正式审核状态。 */
|
||||
const visionKey = computed(() =>
|
||||
open.value && props.target?.kind === 'keyframe' ? JSON.stringify([props.target.shotId, props.target.assetId]) : ''
|
||||
open.value && props.target?.kind === 'keyframe'
|
||||
? JSON.stringify([props.target.shotId, props.target.assetId, props.projectId])
|
||||
: ''
|
||||
)
|
||||
const vision = useKeyframeVision(visionKey)
|
||||
/** 有原参数时继续;没有原参数时保留只读核查。 */
|
||||
const visionBlocked = computed(() => !!visionKey.value && vision.blocked.value)
|
||||
/** 质量弹窗重新读取所选候选自身的权限,不以会话历史代替后端事实。 */
|
||||
const videoKey = computed(() =>
|
||||
open.value && props.target?.kind === 'video' ? JSON.stringify([props.target.shotId, props.target.assetId]) : ''
|
||||
open.value && props.target?.kind === 'video'
|
||||
? JSON.stringify([props.target.shotId, props.target.assetId, props.projectId])
|
||||
: ''
|
||||
)
|
||||
/** 按正式镜头和候选 ID 查询公开权限。 */
|
||||
const videoQuery = useQuery(videoKey, async (value, signal) => {
|
||||
@@ -143,7 +147,7 @@ const input = computed<QualityInput>(() => ({
|
||||
maxRepairAttempts: action.value === 'validate' ? 0 : (attempts.value ?? -1),
|
||||
force: force.value,
|
||||
episodeNo: props.target?.kind === 'batch' ? props.target.episodeNo : 1,
|
||||
allowedTexts: vision.resumeTexts.value ?? allowedTextLines(texts.value),
|
||||
allowedTexts: allowedTextLines(texts.value),
|
||||
...(action.value === 'validate' || width.value === null ? {} : { width: width.value }),
|
||||
...(action.value === 'validate' || height.value === null ? {} : { height: height.value })
|
||||
}))
|
||||
@@ -243,11 +247,21 @@ async function submit() {
|
||||
blocked.value ||
|
||||
visionBlocked.value ||
|
||||
!repairAvailable.value ||
|
||||
(!!vision.resumeTexts.value && action.value !== 'validate')
|
||||
!!vision.state.value.resumable
|
||||
)
|
||||
return
|
||||
acknowledged.value = false
|
||||
await run(action.value, input.value)
|
||||
if (visionKey.value) void vision.history.refresh()
|
||||
}
|
||||
|
||||
/** 只用已确认的原任务身份继续;不会退回普通审核。 */
|
||||
async function submitResume() {
|
||||
const resume = vision.resume.value
|
||||
if (!resume || !acknowledged.value || blocked.value || visionBlocked.value || action.value !== 'validate') return
|
||||
acknowledged.value = false
|
||||
await run('validate', input.value, resume)
|
||||
if (visionKey.value) void vision.history.refresh()
|
||||
}
|
||||
/** 质量面板的formModel状态,随目标更新。 */
|
||||
const formModel = computed(() => ({
|
||||
@@ -374,9 +388,9 @@ const optionsExpanded = ref<string[]>(['options'])
|
||||
</div>
|
||||
<NFormItem class="mt-4 block" path="texts" label="额外允许的画面文字(一行一项,可留空)"
|
||||
><NInput
|
||||
:value="vision.resumeTexts.value?.join('\n') ?? texts"
|
||||
:value="texts"
|
||||
@update:value="texts = $event"
|
||||
:disabled="pending || !!vision.resumeTexts.value"
|
||||
:disabled="pending || !!vision.state.value.resumable"
|
||||
type="textarea"
|
||||
:autosize="{ minRows: 2, maxRows: 5 }"
|
||||
:input-props="{ 'aria-label': '额外允许的画面文字' }"
|
||||
@@ -444,8 +458,8 @@ const optionsExpanded = ref<string[]>(['options'])
|
||||
@refresh="execution.query.refresh"
|
||||
@dismiss="execution.dismiss"
|
||||
/>
|
||||
<p v-if="vision.state.value.resumable && !vision.resumeTexts.value" class="mt-3 text-xs text-muted">
|
||||
此窗口没有原审核参数,暂不能安全继续。
|
||||
<p v-if="vision.state.value.resumable && !vision.resume.value" class="mt-3 text-xs text-muted">
|
||||
原审核缺少可核对的请求版本,暂不能安全继续。
|
||||
</p>
|
||||
<KeyframeValidationHistory
|
||||
v-if="open && target?.kind === 'keyframe'"
|
||||
@@ -453,6 +467,7 @@ const optionsExpanded = ref<string[]>(['options'])
|
||||
:shot-id="target.shotId"
|
||||
:key="target.assetId"
|
||||
:keyframe-id="target.assetId"
|
||||
:observation="vision"
|
||||
:disabled="disabled || pending"
|
||||
initial-open
|
||||
@reviewed="emit('changed')"
|
||||
@@ -479,17 +494,22 @@ const optionsExpanded = ref<string[]>(['options'])
|
||||
<div class="quality-dialog-actions">
|
||||
<NButton @click="open = false">关闭</NButton>
|
||||
<NButton
|
||||
v-if="vision.state.value.resumable"
|
||||
type="primary"
|
||||
:loading="pending"
|
||||
:disabled="
|
||||
blocked ||
|
||||
visionBlocked ||
|
||||
!acknowledged ||
|
||||
!repairAvailable ||
|
||||
(!!vision.resumeTexts.value && action !== 'validate')
|
||||
blocked || visionBlocked || !acknowledged || !vision.resume.value || action !== 'validate'
|
||||
"
|
||||
@click="submitResume"
|
||||
>继续原审核</NButton
|
||||
>
|
||||
<NButton
|
||||
v-else
|
||||
type="primary"
|
||||
:loading="pending"
|
||||
:disabled="blocked || visionBlocked || !acknowledged || !repairAvailable"
|
||||
@click="formRef?.validate(submit)"
|
||||
>{{ vision.resumeTexts.value && action === 'validate' ? '继续原审核' : label }}</NButton
|
||||
>{{ label }}</NButton
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -28,7 +28,6 @@ import type {
|
||||
GenerateKeyframeInput,
|
||||
KeyframeReadinessItem,
|
||||
KeyframeSpec,
|
||||
KeyframeGenerationPreview,
|
||||
PromptReadinessItem,
|
||||
VideoGenerationSpec,
|
||||
VideoReadinessItem
|
||||
@@ -48,7 +47,7 @@ import KeyframeValidationHistory from './KeyframeValidationHistory.vue'
|
||||
import { AppDialog } from '../../../components/ui'
|
||||
import ModelCapabilities from './ModelCapabilities.vue'
|
||||
import type { QualityTarget } from '../quality.types'
|
||||
import ImageGenerationPreview from '../../subject-images/components/ImageGenerationPreview.vue'
|
||||
import KeyframeInputDetails from './KeyframeInputDetails.vue'
|
||||
import { visionState } from '../keyframe-vision'
|
||||
import { clearVideoConflict, clearVideoQualification, sessionKeyframePassed, sessionVideoValidation } from '../quality'
|
||||
import { useProjectGenerationRevision } from '../../generation-config/context'
|
||||
@@ -348,19 +347,6 @@ function openShotKeyframeQuality() {
|
||||
}
|
||||
/** 当前查看历史的候选 ID;历史记录在独立弹窗内按候选隔离。 */
|
||||
const historyKeyframeId = ref('')
|
||||
/** 当前会话保留最近一次真实正式预览,只用于相同候选输入的证据展示。 */
|
||||
const latestKeyframePreview = ref<KeyframeGenerationPreview | null>(null)
|
||||
/** 历史候选的实际输入只有指纹完全一致时才能显示。 */
|
||||
const historyInput = computed(() => {
|
||||
const preview = latestKeyframePreview.value
|
||||
const item = keyframes.value.find(candidate => candidate.id === historyKeyframeId.value)
|
||||
return preview &&
|
||||
item &&
|
||||
item.shotId === preview.shotId &&
|
||||
preview.previewFingerprint === item.providerInputFingerprint
|
||||
? preview
|
||||
: null
|
||||
})
|
||||
/** 历史候选画幅或来源失效时保留浏览、禁止人工采用。 */
|
||||
const historyBlocked = computed(() => {
|
||||
const item = keyframes.value.find(candidate => candidate.id === historyKeyframeId.value)
|
||||
@@ -587,7 +573,7 @@ async function setPrimaryKeyframe() {
|
||||
// 晋升前重新读取持久化质量结论,刷新页面后也认可真实历史通过。
|
||||
const [review, history] = await Promise.all([
|
||||
qualityApi.keyframeQualityReview(shotId, keyframeId),
|
||||
qualityApi.keyframeHistory(shotId, keyframeId)
|
||||
qualityApi.keyframeHistory(shotId, keyframeId, undefined, props.projectId)
|
||||
])
|
||||
const vision = visionState(history)
|
||||
if (vision.active || vision.unknown || vision.resumable) throw new Error('审核尚未结算,暂不能设为主首帧。')
|
||||
@@ -760,6 +746,7 @@ defineExpose({ inspectSpecs, inspecting })
|
||||
<!-- 以下是主首帧卡片模块,校验历史通过卡片入口在弹窗内查看 -->
|
||||
<div v-if="currentKeyframe" class="keyframe-grid mt-4">
|
||||
<KeyframeCard
|
||||
:project-id="projectId"
|
||||
:shot-id="shot.shotId"
|
||||
:review-revision="reviewRevision"
|
||||
:item="currentKeyframe"
|
||||
@@ -1093,6 +1080,7 @@ defineExpose({ inspectSpecs, inspecting })
|
||||
<div v-if="keyframeCandidates.length" class="asset-candidate-grid mt-4">
|
||||
<div v-for="item in keyframeCandidates" :key="item.id" class="min-w-0">
|
||||
<KeyframeCard
|
||||
:project-id="projectId"
|
||||
:shot-id="shot.shotId"
|
||||
:review-revision="reviewRevision"
|
||||
:item="item"
|
||||
@@ -1170,22 +1158,14 @@ defineExpose({ inspectSpecs, inspecting })
|
||||
description="核对当前候选的生成输入、视觉审核与人工复核。"
|
||||
wide
|
||||
>
|
||||
<!-- 以下是同指纹的实际输入,历史无法取得时如实说明 -->
|
||||
<NCollapse v-if="historyOpen" class="mb-4">
|
||||
<NCollapseItem name="generation" title="当次参考图和画面描述">
|
||||
<ImageGenerationPreview
|
||||
v-if="historyInput"
|
||||
:preview="historyInput"
|
||||
:loading="false"
|
||||
error=""
|
||||
stale-notice=""
|
||||
display-only
|
||||
/>
|
||||
<p v-else class="text-xs text-muted">
|
||||
当前无法读取这张图的原始生成输入。可查看候选原图和已有审核记录。
|
||||
</p>
|
||||
</NCollapseItem>
|
||||
</NCollapse>
|
||||
<!-- 以下是按需读取的候选生成证据 -->
|
||||
<KeyframeInputDetails
|
||||
v-if="historyOpen && historyKeyframeId"
|
||||
:key="historyKeyframeId"
|
||||
:project-id="projectId"
|
||||
:shot-id="shot.shotId"
|
||||
:keyframe-id="historyKeyframeId"
|
||||
/>
|
||||
<KeyframeValidationHistory
|
||||
v-if="historyOpen && historyKeyframeId"
|
||||
:key="historyKeyframeId"
|
||||
@@ -1208,7 +1188,6 @@ defineExpose({ inspectSpecs, inspecting })
|
||||
:disabled="!canGenerateKeyframe"
|
||||
:previous-candidate-ids="keyframes.map(item => item.id)"
|
||||
:submit-generation="generateKeyframe"
|
||||
@previewed="latestKeyframePreview = $event"
|
||||
/>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
import { request } from '../../lib/http'
|
||||
import type { ProviderImageInputSnapshot } from '../subject-images/generation-preview'
|
||||
import { keyframeScope } from './keyframe-scope'
|
||||
|
||||
/** 历史实际参考图保留顺序和证据,独立报告原件可用性。 */
|
||||
export type HistoricalKeyframeReference = ProviderImageInputSnapshot['references'][number] & {
|
||||
/** 当次实际文件字节指纹。 */ sha256: string
|
||||
/** 当次解码像素指纹。 */ pixelFingerprint: string
|
||||
/** 图像类型。 */ mimeType: string
|
||||
/** 文件大小。 */ byteLength: number
|
||||
/** 像素宽度。 */ width: number
|
||||
/** 像素高度。 */ height: number
|
||||
/** 服务端原件核验结果。 */
|
||||
availability: 'available' | 'unavailable' | 'changed'
|
||||
/** 经过同一候选校验的相对 API 地址。 */
|
||||
imageUrl: string | null
|
||||
}
|
||||
|
||||
/** 候选的历史输入证据,缺失时不重新编译。 */
|
||||
export interface HistoricalKeyframeInput {
|
||||
/** 所属镜头。 */ shotId: string
|
||||
/** 所属候选。 */ keyframeId: string
|
||||
/** 已保存输入的完整性。 */ inputSnapshotStatus: 'recorded' | 'not-recorded' | 'invalid'
|
||||
/** 当次输入版本。 */ providerInputFingerprint: string | null
|
||||
/** 实际模型输入。 */
|
||||
providerInputSnapshot:
|
||||
| (Omit<ProviderImageInputSnapshot, 'references'> & {
|
||||
/** 当次图片模型服务。 */ provider: string
|
||||
/** 当次具体模型。 */ model: string | null
|
||||
/** 当次完整提示词。 */ providerPrompt: string
|
||||
/** 快照格式。 */ version: number
|
||||
/** 旧参数中记录的宽度。 */ width?: number
|
||||
/** 旧参数中记录的高度。 */ height?: number
|
||||
/** 实际参考图顺序。 */ references: HistoricalKeyframeReference[]
|
||||
})
|
||||
| null
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造候选独立的正式证据路径。
|
||||
* @param shotId 正式镜头
|
||||
* @param keyframeId 候选
|
||||
* @returns 不含 API 前缀的路径
|
||||
*/
|
||||
function inputPath(shotId: string, keyframeId: string) {
|
||||
return `/storyboard-shots/${encodeURIComponent(shotId)}/keyframes/${encodeURIComponent(keyframeId)}/generation-input`
|
||||
}
|
||||
|
||||
/**
|
||||
* 只读加载指定候选的历史输入。
|
||||
* @param projectId 当前项目
|
||||
* @param shotId 正式镜头
|
||||
* @param keyframeId 候选
|
||||
* @param signal 取消已离开候选的请求
|
||||
* @returns 该候选的历史证据
|
||||
*/
|
||||
export function loadKeyframeInput(projectId: string, shotId: string, keyframeId: string, signal?: AbortSignal) {
|
||||
return request<HistoricalKeyframeInput>(keyframeScope(inputPath(shotId, keyframeId), projectId), { signal })
|
||||
}
|
||||
|
||||
/**
|
||||
* 只允许访问同项目同候选的正式参考原件,保留服务返回的范围参数。
|
||||
* @param reference 当前参考图
|
||||
* @param projectId 当前项目
|
||||
* @param shotId 正式镜头
|
||||
* @param keyframeId 候选
|
||||
* @returns 可安全浏览的绝对地址,或空
|
||||
*/
|
||||
export function historicalReferenceUrl(
|
||||
reference: HistoricalKeyframeReference,
|
||||
projectId: string,
|
||||
shotId: string,
|
||||
keyframeId: string
|
||||
) {
|
||||
if (reference.availability !== 'available' || !reference.imageUrl?.startsWith('/api/')) return null
|
||||
try {
|
||||
const api = new URL(import.meta.env.VITE_API_BASE_URL || '/api', window.location.origin)
|
||||
const url = new URL(reference.imageUrl, api.origin)
|
||||
const expected = '/api' + inputPath(shotId, keyframeId) + '/references/' + reference.imageNumber
|
||||
return url.pathname === expected && url.searchParams.get('projectId') === projectId ? url.href : null
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* 为镜头级正式接口附带项目归属;已有查询参数也保留。
|
||||
* @param path 不含统一 API 前缀的路径
|
||||
* @param projectId 当前项目
|
||||
* @returns 附带项目范围的路径
|
||||
*/
|
||||
export function keyframeScope(path: string, projectId?: string) {
|
||||
return projectId ? path + (path.includes('?') ? '&' : '?') + new URLSearchParams({ projectId }) : path
|
||||
}
|
||||
@@ -1,15 +1,14 @@
|
||||
import { computed, onScopeDispose, ref, watch, type Ref } from 'vue'
|
||||
import { useQuery } from '../../composables/useQuery'
|
||||
import { ApiError } from '../../lib/http'
|
||||
import type { WorkflowExecution } from '../workflows/execution.types'
|
||||
import { workflowExecutionApi } from '../workflows/execution-api'
|
||||
import { qualityApi } from './quality-api'
|
||||
import { isVisualValidation } from './quality'
|
||||
import type { KeyframeValidationHistoryItem } from './quality.types'
|
||||
import type { KeyframeValidationHistoryItem, ResumeKeyframeValidation } from './quality.types'
|
||||
|
||||
/** 当前候选的最近一次客户端提交,用于断线后只读恢复。 */
|
||||
interface Submission {
|
||||
/** 本次确认的文字授权。 */
|
||||
texts: string[]
|
||||
/** 请求前已存在的最近记录。 */
|
||||
before: string | null
|
||||
/** 同一任务继续时,原执行编号用于识别新一轮。 */
|
||||
@@ -18,9 +17,7 @@ interface Submission {
|
||||
taskId?: string
|
||||
/** 服务确认的执行编号。 */
|
||||
executionId?: string
|
||||
/** 任务属于其他提交,当前文字不能用于继续。 */
|
||||
external?: boolean
|
||||
/** 已明确结算,仅保留原参数供显式继续。 */
|
||||
/** 已明确结算,可解除断线保护。 */
|
||||
settled?: boolean
|
||||
}
|
||||
|
||||
@@ -66,8 +63,12 @@ function saveSubmission(key: string, value?: Submission) {
|
||||
*/
|
||||
export function visionState(records: KeyframeValidationHistoryItem[]) {
|
||||
const active = records.find(item => item.status === 'pending' || item.status === 'running')
|
||||
const unknown = records.find(item => item.status === 'failed' && visionOutput(item).recoveryRequired !== false)
|
||||
const resumable = records.find(item => item.status === 'failed' && visionOutput(item).resumeAvailable === true)
|
||||
const unknown = records.find(
|
||||
item => item.recoveryRequired ?? (item.status === 'failed' && visionOutput(item).recoveryRequired !== false)
|
||||
)
|
||||
const resumable = records.find(
|
||||
item => item.status === 'failed' && (item.resumeAvailable ?? visionOutput(item).resumeAvailable) === true
|
||||
)
|
||||
return { active, unknown, resumable }
|
||||
}
|
||||
|
||||
@@ -88,22 +89,27 @@ function visionOutput(record: KeyframeValidationHistoryItem): Record<string, unk
|
||||
/**
|
||||
* 按候选发现后台任务,轮询仅查询历史和正式执行记录。
|
||||
* @param key 镜头和候选 ID 的 JSON 查询键
|
||||
* @param observeExecution 是否订阅执行事件(候选卡片只读历史)
|
||||
* @returns 观察状态和一次性提交凭据操作
|
||||
*/
|
||||
export function useKeyframeVision(key: Ref<string>) {
|
||||
export function useKeyframeVision(key: Ref<string>, observeExecution = true) {
|
||||
/** 当前候选的客户端凭据。 */
|
||||
const submission = computed(() => readSubmission(key.value))
|
||||
/** 公开审核记录是刷新恢复的正式来源。 */
|
||||
const history = useQuery(key, (value, signal) => {
|
||||
if (!value) return Promise.resolve([])
|
||||
const [shotId, keyframeId] = JSON.parse(value) as [string, string]
|
||||
return qualityApi.keyframeHistory(shotId, keyframeId, signal)
|
||||
const [shotId, keyframeId, projectId] = JSON.parse(value) as [string, string, string?]
|
||||
return qualityApi.keyframeHistory(shotId, keyframeId, signal, projectId)
|
||||
})
|
||||
/** 当前活跃、未结或可继续的记录。 */
|
||||
const state = computed(() => visionState(history.data.value ?? []))
|
||||
/** 旧版活跃记录没有执行编号,仍只能观察和核查。 */
|
||||
const executionKey = computed(
|
||||
() => state.value.active?.executionId ?? (submission.value?.settled ? '' : submission.value?.executionId) ?? ''
|
||||
const executionKey = computed(() =>
|
||||
observeExecution
|
||||
? (state.value.active?.executionId ??
|
||||
(submission.value?.settled ? '' : submission.value?.executionId) ??
|
||||
'')
|
||||
: ''
|
||||
)
|
||||
/** 只读取执行状态,不展示工作流内部原始结果。 */
|
||||
const execution = useQuery(executionKey, (id, signal) =>
|
||||
@@ -111,25 +117,59 @@ export function useKeyframeVision(key: Ref<string>) {
|
||||
)
|
||||
/** 未明确结算的断线状态禁止再次写入。 */
|
||||
const uncertain = computed(() => !!submission.value && !submission.value.settled && !state.value.active)
|
||||
/** 只有本次会话确知原文字授权时才能安全继续。 */
|
||||
const resumeTexts = computed(() => {
|
||||
const saved = submission.value
|
||||
return saved?.settled && !saved.external && saved.taskId && saved.taskId === state.value.resumable?.id
|
||||
? saved.texts
|
||||
/** 继续完全依赖同一条正式历史的任务和指纹。 */
|
||||
const resume = computed<ResumeKeyframeValidation | null>(() => {
|
||||
const task = state.value.resumable
|
||||
return task?.requestFingerprint && /^[a-f0-9]{64}$/.test(task.requestFingerprint)
|
||||
? { resumeValidationTaskId: task.id, expectedRequestFingerprint: task.requestFingerprint }
|
||||
: null
|
||||
})
|
||||
/** 初次读取或失败时不允许盲目启动,轮询期间不清空旧状态。 */
|
||||
/** 初次读取或失败时不允许盲目启动,轮询期间保留旧状态。 */
|
||||
const blocked = computed(
|
||||
() =>
|
||||
!history.data.value ||
|
||||
!!history.error.value ||
|
||||
!!state.value.active ||
|
||||
!!state.value.unknown ||
|
||||
uncertain.value ||
|
||||
(!!state.value.resumable && !resumeTexts.value)
|
||||
uncertain.value
|
||||
)
|
||||
/** SSE 断开时回到只读轮询。 */
|
||||
let live = false
|
||||
watch(
|
||||
executionKey,
|
||||
(id, _, onCleanup) => {
|
||||
live = false
|
||||
if (!id || typeof EventSource === 'undefined') return
|
||||
const source = new EventSource(workflowExecutionApi.executionEventsUrl(id))
|
||||
onCleanup(() => {
|
||||
source.close()
|
||||
live = false
|
||||
})
|
||||
source.addEventListener('message', event => {
|
||||
if (id !== executionKey.value) return
|
||||
try {
|
||||
const payload = JSON.parse(event.data) as
|
||||
| WorkflowExecution
|
||||
| { done: true; result?: WorkflowExecution }
|
||||
const record = 'done' in payload ? payload.result : payload
|
||||
if (!record || record.id !== id) return
|
||||
live = true
|
||||
execution.data.value = record
|
||||
if (!history.loading.value) void history.refresh()
|
||||
if (record.status === 'completed' || record.status === 'failed') source.close()
|
||||
} catch {
|
||||
live = false
|
||||
}
|
||||
})
|
||||
source.addEventListener('error', () => {
|
||||
live = false
|
||||
})
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
watch([history.data, submission], ([records, saved]) => {
|
||||
watch(history.data, records => {
|
||||
const saved = submission.value
|
||||
if (!records || !saved || saved.settled) return
|
||||
const latest = records[0]
|
||||
const found = saved.taskId
|
||||
@@ -145,48 +185,51 @@ export function useKeyframeVision(key: Ref<string>) {
|
||||
const timer = setInterval(() => {
|
||||
if (key.value && (state.value.active || uncertain.value)) {
|
||||
if (!history.loading.value) void history.refresh()
|
||||
if (executionKey.value && !execution.loading.value) void execution.refresh()
|
||||
if (executionKey.value && !live && !execution.loading.value) void execution.refresh()
|
||||
}
|
||||
}, 2500)
|
||||
onScopeDispose(() => clearInterval(timer))
|
||||
return { history, state, execution, uncertain, blocked, resumeTexts }
|
||||
return { history, state, execution, uncertain, blocked, resume }
|
||||
}
|
||||
|
||||
/**
|
||||
* 只提交一次审核;冲突和断线回到只读观察。
|
||||
* @param shotId 正式镜头
|
||||
* @param assetId 当前候选
|
||||
* @param texts 已明确确认的文字授权
|
||||
* @param input 已明确确认的新文字,或原任务继续凭据
|
||||
* @param records 提交前读取的审核历史
|
||||
* @param projectId 当前正式项目
|
||||
* @returns 已复用的质量结论,或后台受理时返回空
|
||||
*/
|
||||
export async function submitKeyframeVision(
|
||||
shotId: string,
|
||||
assetId: string,
|
||||
texts: string[],
|
||||
records: KeyframeValidationHistoryItem[]
|
||||
input: string[] | ResumeKeyframeValidation,
|
||||
records: KeyframeValidationHistoryItem[],
|
||||
projectId?: string
|
||||
) {
|
||||
const key = JSON.stringify([shotId, assetId])
|
||||
const key = JSON.stringify(projectId ? [shotId, assetId, projectId] : [shotId, assetId])
|
||||
const previous = readSubmission(key)
|
||||
const current = visionState(records)
|
||||
if (current.active || current.unknown || (previous && !previous.settled))
|
||||
throw new Error('已有审核或费用待核查,请查看审核记录。')
|
||||
if (
|
||||
current.resumable &&
|
||||
(!previous ||
|
||||
previous.external ||
|
||||
previous.taskId !== current.resumable.id ||
|
||||
JSON.stringify(texts) !== JSON.stringify(previous.texts))
|
||||
)
|
||||
throw new Error('继续审核需要原审核参数,请核对原操作记录。')
|
||||
if (Array.isArray(input)) {
|
||||
if (current.resumable) throw new Error('有可继续的审核,请通过继续原审核操作处理。')
|
||||
} else if (
|
||||
!current.resumable ||
|
||||
current.resumable.id !== input.resumeValidationTaskId ||
|
||||
current.resumable.requestFingerprint !== input.expectedRequestFingerprint ||
|
||||
!/^[a-f0-9]{64}$/.test(input.expectedRequestFingerprint)
|
||||
) {
|
||||
throw new Error('原审核参数或任务状态已变化,请刷新记录。')
|
||||
}
|
||||
const pending: Submission = {
|
||||
texts: [...texts],
|
||||
before: records[0]?.id ?? null,
|
||||
beforeExecutionId: records[0]?.executionId
|
||||
}
|
||||
saveSubmission(key, pending)
|
||||
try {
|
||||
const result = await qualityApi.validateKeyframe(shotId, assetId, texts)
|
||||
const result = await qualityApi.validateKeyframe(shotId, assetId, input, projectId)
|
||||
if (result.shotId !== shotId || result.keyframeId !== assetId || !result.validationTaskId)
|
||||
throw new Error('审核回执与当前候选不一致,请刷新审核记录。')
|
||||
if ('executionId' in result && result.status === 'pending' && result.executionId) {
|
||||
@@ -206,13 +249,13 @@ export async function submitKeyframeVision(
|
||||
saveSubmission(key, {
|
||||
...pending,
|
||||
taskId: details?.taskId,
|
||||
executionId: details?.executionId,
|
||||
external: true
|
||||
executionId: details?.executionId
|
||||
})
|
||||
return null
|
||||
}
|
||||
if (code === 'KEYFRAME_VALIDATION_RECOVERY_REQUIRED') {
|
||||
saveSubmission(key, { ...pending, taskId: details?.taskId, external: true })
|
||||
// 在一次新的历史读取确认结算或可继续前,保持写入阻断。
|
||||
saveSubmission(key, { ...pending, taskId: details?.taskId })
|
||||
throw new Error('原审核结果或费用待核查,请查看审核记录。', { cause })
|
||||
}
|
||||
saveSubmission(key, previous)
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { keyframeScope } from './keyframe-scope'
|
||||
import { request } from '../../lib/http'
|
||||
import type {
|
||||
ImageProviderCapability,
|
||||
KeyframeRepair,
|
||||
KeyframeValidation,
|
||||
KeyframeValidationAccepted,
|
||||
ResumeKeyframeValidation,
|
||||
KeyframeQualityStart,
|
||||
KeyframeValidationHistoryItem,
|
||||
QualityInput,
|
||||
@@ -57,10 +59,18 @@ export const qualityApi = {
|
||||
{ signal }
|
||||
),
|
||||
/** 显式请求一次审核,返回后台受理或既有质量结果。 */
|
||||
validateKeyframe: (shotId: string, assetId: string, allowedTexts: string[]) =>
|
||||
validateKeyframe: (
|
||||
shotId: string,
|
||||
assetId: string,
|
||||
input: string[] | ResumeKeyframeValidation,
|
||||
projectId?: string
|
||||
) =>
|
||||
request<KeyframeValidation | KeyframeValidationAccepted>(
|
||||
`/storyboard-shots/${encodeURIComponent(shotId)}/keyframes/${encodeURIComponent(assetId)}/validate`,
|
||||
{ method: 'POST', body: { allowedTexts } }
|
||||
keyframeScope(
|
||||
`/storyboard-shots/${encodeURIComponent(shotId)}/keyframes/${encodeURIComponent(assetId)}/validate`,
|
||||
projectId
|
||||
),
|
||||
{ method: 'POST', body: Array.isArray(input) ? { allowedTexts: input } : input }
|
||||
),
|
||||
repair: (
|
||||
shotId: string,
|
||||
@@ -124,9 +134,12 @@ export const qualityApi = {
|
||||
`/storyboard-shots/${encodeURIComponent(shotId)}/keyframes/${encodeURIComponent(keyframeId)}/quality-review/reject`,
|
||||
{ method: 'POST', body }
|
||||
),
|
||||
keyframeHistory: (shotId: string, keyframeId: string, signal?: AbortSignal) =>
|
||||
keyframeHistory: (shotId: string, keyframeId: string, signal?: AbortSignal, projectId?: string) =>
|
||||
request<KeyframeValidationHistoryItem[]>(
|
||||
`/storyboard-shots/${encodeURIComponent(shotId)}/keyframes/${encodeURIComponent(keyframeId)}/validations`,
|
||||
keyframeScope(
|
||||
`/storyboard-shots/${encodeURIComponent(shotId)}/keyframes/${encodeURIComponent(keyframeId)}/validations`,
|
||||
projectId
|
||||
),
|
||||
{ signal }
|
||||
),
|
||||
/**
|
||||
|
||||
@@ -219,6 +219,20 @@ export interface KeyframeValidationAccepted {
|
||||
status: 'pending'
|
||||
}
|
||||
|
||||
/** 通过正式任务身份继续,不能同时发送新的文字授权。 */
|
||||
export interface ResumeKeyframeValidation {
|
||||
/** 原审核任务编号。 */ resumeValidationTaskId: string
|
||||
/** 同一任务保存的请求版本。 */ expectedRequestFingerprint: string
|
||||
}
|
||||
|
||||
/** 单一步骤已解析并公开的问题。 */
|
||||
export interface KeyframeStepIssue {
|
||||
/** 问题分类。 */ code: string
|
||||
/** 对用户可读的问题。 */ description: string
|
||||
/** 有证据时的严重程度。 */ severity?: string
|
||||
/** 对应主体。 */ subjectRef?: string
|
||||
}
|
||||
|
||||
/** 审核历史中公开的步骤证据。 */
|
||||
export interface KeyframeValidationStep {
|
||||
/** 审核范围。 */
|
||||
@@ -235,6 +249,8 @@ export interface KeyframeValidationStep {
|
||||
finishedAt?: string
|
||||
/** 可取得的词元计量。 */
|
||||
usage?: Partial<Record<'inputTokens' | 'outputTokens' | 'totalTokens' | 'reasoningTokens', number>>
|
||||
/** 未产出为 null,已完成且无问题为 []。 */
|
||||
issues?: KeyframeStepIssue[] | null
|
||||
/** 公开错误说明。 */
|
||||
error?: string
|
||||
}
|
||||
@@ -247,6 +263,16 @@ export interface KeyframeValidationHistoryItem {
|
||||
status: string
|
||||
/** 数据库保存的 JSON 输出 */
|
||||
output: string | Record<string, unknown> | null
|
||||
/** 原审核的文字授权,空数组与未记录分开。 */
|
||||
allowedTexts?: string[] | null
|
||||
/** 继续时需要的请求指纹。 */
|
||||
requestFingerprint?: string | null
|
||||
/** 服务端判定是否需要核查。 */
|
||||
recoveryRequired?: boolean
|
||||
/** 服务端明确允许继续。 */
|
||||
resumeAvailable?: boolean
|
||||
/** 服务端核查原因。 */
|
||||
recoveryReason?: string | null
|
||||
/** 新版工作流执行编号。 */
|
||||
executionId?: string
|
||||
/** 公开步骤进度。 */
|
||||
|
||||
@@ -18,7 +18,14 @@ import {
|
||||
qualityTargets,
|
||||
validQualityInput
|
||||
} from './quality'
|
||||
import type { QualityAction, QualityInput, QualityReceipt, QualityTarget, RepairAttempt } from './quality.types'
|
||||
import type {
|
||||
QualityAction,
|
||||
QualityInput,
|
||||
QualityReceipt,
|
||||
QualityTarget,
|
||||
RepairAttempt,
|
||||
ResumeKeyframeValidation
|
||||
} from './quality.types'
|
||||
|
||||
/** 校验有限修复回执的每轮结论,避免结构缺失时误报成功。 */
|
||||
function validAttempts(attempts: RepairAttempt[]) {
|
||||
@@ -106,11 +113,13 @@ export function useQuality(
|
||||
* 确认之后重读状态并只提交一次,固定原目标与费用范围。
|
||||
* @param action 已确认的质量操作
|
||||
* @param input 已确认的参数
|
||||
* @param resume 显式继续的原任务身份,可省略
|
||||
* @returns 操作结束通知,后台生成由持久化任务继续跟踪
|
||||
*/
|
||||
async function run(action: QualityAction, input: QualityInput) {
|
||||
async function run(action: QualityAction, input: QualityInput, resume?: ResumeKeyframeValidation) {
|
||||
if (blocked.value || !visible() || !props.target || !validQualityInput(input)) return
|
||||
const target = { ...props.target }
|
||||
if (resume && (target.kind !== 'keyframe' || action !== 'validate')) return
|
||||
if (
|
||||
(target.kind === 'batch') !== (action === 'batch') ||
|
||||
(target.kind === 'video' && action === 'repair' && input.maxRepairAttempts <= 0)
|
||||
@@ -210,7 +219,7 @@ export function useQuality(
|
||||
if (target.kind === 'keyframe' && action === 'validate') {
|
||||
const [images, history] = await Promise.all([
|
||||
productionApi.listKeyframes(target.shotId),
|
||||
qualityApi.keyframeHistory(target.shotId, target.assetId)
|
||||
qualityApi.keyframeHistory(target.shotId, target.assetId, undefined, projectId)
|
||||
])
|
||||
const image = images.find(item => item.id === target.assetId && item.shotId === target.shotId)
|
||||
if (
|
||||
@@ -225,8 +234,9 @@ export function useQuality(
|
||||
const result = await submitKeyframeVision(
|
||||
target.shotId,
|
||||
target.assetId,
|
||||
input.allowedTexts ?? [],
|
||||
history
|
||||
resume ?? input.allowedTexts ?? [],
|
||||
history,
|
||||
projectId
|
||||
)
|
||||
if (result) receiptTarget.receipt = { kind: 'keyframe', result }
|
||||
return
|
||||
@@ -331,7 +341,15 @@ export function useQuality(
|
||||
}
|
||||
}
|
||||
receiptTarget.receipt = receipt
|
||||
}
|
||||
},
|
||||
target.kind === 'keyframe' && action === 'validate'
|
||||
? () => ({
|
||||
type: 'info',
|
||||
content: receiptTarget.receipt
|
||||
? '已读取已有审核结论。'
|
||||
: '审核任务已受理或正在执行,可查看后台进度。'
|
||||
})
|
||||
: undefined
|
||||
)
|
||||
if (!ok) receiptTarget.error = getOperation(projectId).error
|
||||
// 已提交请求即使切换页面也归原会话;只刷新仍在查看的原项目。
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { keyframeScope } from '../production/keyframe-scope'
|
||||
import type { WorkflowExecutionStart } from '../workflows/execution.types'
|
||||
import { request } from '../../lib/http'
|
||||
import type {
|
||||
@@ -83,8 +84,8 @@ export const storyboardApi = {
|
||||
timeoutMs: 0
|
||||
}),
|
||||
references: (id: string, signal?: AbortSignal) => request<ShotReferences>(`${shotPath(id)}/references`, { signal }),
|
||||
generationSpec: (id: string, signal?: AbortSignal) =>
|
||||
request<ShotGenerationSpec>(`${shotPath(id)}/generation-spec`, { signal }),
|
||||
generationSpec: (id: string, signal?: AbortSignal, projectId?: string) =>
|
||||
request<ShotGenerationSpec>(keyframeScope(`${shotPath(id)}/generation-spec`, projectId), { signal }),
|
||||
/** 只读获取已保存的视频提示词,不要求首帧已就绪。 */
|
||||
videoPrompt: (id: string, signal?: AbortSignal) =>
|
||||
request<ShotPromptResult>(`${shotPath(id)}/video-prompt`, { signal }),
|
||||
|
||||
@@ -5,6 +5,7 @@ import { AppDrawer, WorkspaceSectionHeading } from '../../../components/ui'
|
||||
import { useActionMessage } from '../../../components/ui/useActionMessage'
|
||||
import { useQuery } from '../../../composables/useQuery'
|
||||
import { ApiError, errorMessage } from '../../../lib/http'
|
||||
import { formatDate } from '../../../lib/format'
|
||||
import { userFacingText } from '../../../lib/user-facing-text'
|
||||
import { productionApi } from '../../production/api'
|
||||
import KeyframePreviewChecks from '../../production/components/KeyframePreviewChecks.vue'
|
||||
@@ -17,7 +18,12 @@ import type { GenerationOptions } from '../../generation-config/types'
|
||||
import { storyboardApi } from '../api'
|
||||
import { derivedReviewApi } from '../derived-review-api'
|
||||
import { draftFromFormal } from '../derived-review'
|
||||
import type { DerivedReviewSelection, ShotDraftPreview, ShotReviewDraft } from '../derived-review.types'
|
||||
import type {
|
||||
DerivedReviewSelection,
|
||||
DraftProviderInput,
|
||||
ShotDraftPreview,
|
||||
ShotReviewDraft
|
||||
} from '../derived-review.types'
|
||||
import { directionLabel } from '../model'
|
||||
import type { DesignedShot } from '../types'
|
||||
|
||||
@@ -56,7 +62,31 @@ const saving = ref(false)
|
||||
/** 当前消息层。 */
|
||||
const message = useActionMessage()
|
||||
/** 关闭或切换镜头后撤销旧读取。 */
|
||||
const key = computed(() => (open.value ? props.shot.shotId : ''))
|
||||
const key = computed(() => (open.value ? JSON.stringify([props.projectId, props.shot.shotId]) : ''))
|
||||
/** 服务端草案单独读取,不阻塞外部草案的免费预览。 */
|
||||
const savedDraft = useQuery(key, async (value, signal) => {
|
||||
if (!value) return null
|
||||
const [projectId, shotId] = JSON.parse(value) as [string, string]
|
||||
const result = await derivedReviewApi.draft(projectId, shotId, signal)
|
||||
if (result && result.shotId !== shotId) throw new Error('已保存草案与当前镜头不一致。')
|
||||
return result
|
||||
})
|
||||
/** 区分已保存原稿与当前表单内容。 */
|
||||
const useSaved = ref(false)
|
||||
/** 保存冲突后必须由用户重新读取,不自动覆盖。 */
|
||||
const draftConflict = ref(false)
|
||||
/** 草案保存使用独立的短请求状态。 */
|
||||
const savingDraft = ref(false)
|
||||
/** 用户主动修改模型后不再使用保存时的参数。 */
|
||||
const providerEdited = ref(false)
|
||||
/** 编辑保存的原稿时,保留其模型参数和显式尺寸。 */
|
||||
const editingSavedInput = ref<DraftProviderInput | null>()
|
||||
/** 当前可查看的原稿,保留过期草案的全部内容。 */
|
||||
const savedDraftText = computed(() =>
|
||||
savedDraft.data.value ? JSON.stringify(savedDraft.data.value.draft, null, 2) : ''
|
||||
)
|
||||
/** 原稿与编辑状态的来源分离,重读草案不替换用户输入。 */
|
||||
const draftLoaded = ref(false)
|
||||
/** 已有正式设计时仅允许受控修改。 */
|
||||
const formal = computed(() => !!props.shot.direction && !!props.shot.visualState)
|
||||
/** 读取服务端正式审核状态和版本。 */
|
||||
@@ -64,11 +94,12 @@ const preflight = useQuery(key, (id, signal) =>
|
||||
id ? preparationApi.qualityPreflight(props.projectId, signal) : Promise.resolve(null)
|
||||
)
|
||||
/** 受控修改前重新读取镜头规格、实际参考与新鲜摄影记录。 */
|
||||
const formalQuery = useQuery(key, async (id, signal) => {
|
||||
if (!id || !formal.value) return null
|
||||
const formalQuery = useQuery(key, async (value, signal) => {
|
||||
if (!value || !formal.value) return null
|
||||
const [projectId, id] = JSON.parse(value) as [string, string]
|
||||
const [keyframe, generation, directions, visuals] = await Promise.all([
|
||||
productionApi.keyframeSpec(id, signal),
|
||||
storyboardApi.generationSpec(id, signal),
|
||||
productionApi.keyframeSpec(id, signal, projectId),
|
||||
storyboardApi.generationSpec(id, signal, projectId),
|
||||
storyboardApi.directions(props.projectId, props.episodeNo, signal),
|
||||
storyboardApi.visualStates(props.projectId, props.episodeNo, signal)
|
||||
])
|
||||
@@ -137,6 +168,8 @@ onScopeDispose(clearPreview)
|
||||
watch(
|
||||
[
|
||||
key,
|
||||
useSaved,
|
||||
providerEdited,
|
||||
mode,
|
||||
composition,
|
||||
cameraPosition,
|
||||
@@ -151,32 +184,119 @@ watch(
|
||||
{ flush: 'sync' }
|
||||
)
|
||||
watch(key, () => {
|
||||
useSaved.value = false
|
||||
draftConflict.value = false
|
||||
providerEdited.value = false
|
||||
draftLoaded.value = false
|
||||
editingSavedInput.value = undefined
|
||||
mode.value = 'camera'
|
||||
selectedScene.value = null
|
||||
imported.value = ''
|
||||
reviewer.value = ''
|
||||
})
|
||||
watch(
|
||||
savedDraft.updatedAt,
|
||||
updatedAt => {
|
||||
if (!key.value || !updatedAt || draftLoaded.value) return
|
||||
const value = savedDraft.data.value
|
||||
if (
|
||||
value &&
|
||||
!imported.value.trim() &&
|
||||
!providerEdited.value &&
|
||||
(!composition.value || composition.value === formalQuery.data.value?.shot.direction?.composition) &&
|
||||
(!cameraPosition.value || cameraPosition.value === formalQuery.data.value?.shot.direction?.cameraPosition)
|
||||
)
|
||||
useSaved.value = true
|
||||
draftLoaded.value = true
|
||||
},
|
||||
{ flush: 'post' }
|
||||
)
|
||||
|
||||
/** 用最新修订作为下一次显式保存的基准,保留现有表单。 */
|
||||
async function reloadSavedDraft() {
|
||||
clearPreview()
|
||||
await savedDraft.refresh()
|
||||
if (!savedDraft.error.value) draftConflict.value = false
|
||||
}
|
||||
|
||||
/** 从原稿返回当前正式来源编辑,已有表单不被覆盖。 */
|
||||
function editCurrentDraft() {
|
||||
const saved = savedDraft.data.value
|
||||
useSaved.value = false
|
||||
providerEdited.value = false
|
||||
editingSavedInput.value = saved?.providerInput
|
||||
if (saved?.providerInput?.provider) provider.value = saved.providerInput.provider
|
||||
if (saved?.providerInput?.generationOptions) {
|
||||
options.value = Object.fromEntries(
|
||||
Object.entries(saved.providerInput.generationOptions).filter(
|
||||
(entry): entry is [string, string | number | boolean] =>
|
||||
['string', 'number', 'boolean'].includes(typeof entry[1])
|
||||
)
|
||||
)
|
||||
}
|
||||
if (!saved) return
|
||||
if (saved.status === 'stale') {
|
||||
void preflight.refresh()
|
||||
void formalQuery.refresh()
|
||||
return
|
||||
}
|
||||
if (!formal.value) {
|
||||
imported.value = savedDraftText.value
|
||||
return
|
||||
}
|
||||
if (saved.draft.sceneStateCarryForward) {
|
||||
mode.value = 'scene'
|
||||
selectedScene.value = saved.draft.sceneStateCarryForward.subjectRef
|
||||
} else {
|
||||
mode.value = 'camera'
|
||||
composition.value = saved.draft.direction.composition
|
||||
cameraPosition.value = saved.draft.direction.cameraPosition
|
||||
}
|
||||
}
|
||||
|
||||
/** 显式复制已保存原稿,包含过期稿件。 */
|
||||
async function copySavedDraft() {
|
||||
try {
|
||||
await navigator.clipboard.writeText(savedDraftText.value)
|
||||
message?.success('已复制草案原稿')
|
||||
} catch (cause) {
|
||||
message?.error(errorMessage(cause))
|
||||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
savedDraft.data,
|
||||
() => {
|
||||
if (useSaved.value) clearPreview()
|
||||
},
|
||||
{ flush: 'sync' }
|
||||
)
|
||||
watch(formalQuery.data, value => {
|
||||
composition.value = value?.shot.direction?.composition ?? ''
|
||||
cameraPosition.value = value?.shot.direction?.cameraPosition ?? ''
|
||||
})
|
||||
watch(configuration.data, value => {
|
||||
const model = value?.catalog.images.find(item => item.enabled && item.provider === value.profile.imageProvider)
|
||||
if (providerEdited.value || editingSavedInput.value !== undefined) return
|
||||
provider.value = model?.provider ?? ''
|
||||
options.value = value?.profile.imageOptions ?? {}
|
||||
})
|
||||
/** 是否具备提交免费预览的实际输入。 */
|
||||
const canPreview = computed(
|
||||
() =>
|
||||
!!provider.value &&
|
||||
!!preflight.data.value?.current.evidence.shotFingerprint &&
|
||||
!preflight.error.value &&
|
||||
!configuration.error.value &&
|
||||
(formal.value
|
||||
? !!formalQuery.data.value &&
|
||||
!formalQuery.error.value &&
|
||||
(mode.value === 'scene' ? !!scene.value : !!composition.value.trim() && !!cameraPosition.value.trim())
|
||||
: !!imported.value.trim())
|
||||
(useSaved.value
|
||||
? savedDraft.data.value?.status === 'current' && !savedDraft.error.value
|
||||
: (!!provider.value || (!providerEdited.value && editingSavedInput.value !== undefined)) &&
|
||||
!configuration.error.value &&
|
||||
(formal.value
|
||||
? !!formalQuery.data.value &&
|
||||
!formalQuery.error.value &&
|
||||
(mode.value === 'scene'
|
||||
? !!scene.value
|
||||
: !!composition.value.trim() && !!cameraPosition.value.trim())
|
||||
: !!imported.value.trim()))
|
||||
)
|
||||
/** 展示已预览输入,草案指纹只用于只读公共组件。 */
|
||||
const previewDisplay = computed(() =>
|
||||
@@ -194,6 +314,12 @@ const previewDisplay = computed(() =>
|
||||
*/
|
||||
function buildDraft(): ShotReviewDraft {
|
||||
const fingerprint = preflight.data.value!.current.evidence.shotFingerprint
|
||||
if (useSaved.value) {
|
||||
const original = savedDraft.data.value
|
||||
if (!original || original.status !== 'current' || original.draft.expectedShotFingerprint !== fingerprint)
|
||||
throw new Error('草案来源已变化,请刷新正式分镜并重新核对。')
|
||||
return JSON.parse(JSON.stringify(original.draft)) as ShotReviewDraft
|
||||
}
|
||||
if (!formal.value) {
|
||||
let draft: ShotReviewDraft
|
||||
try {
|
||||
@@ -233,6 +359,68 @@ function buildDraft(): ShotReviewDraft {
|
||||
return draft
|
||||
}
|
||||
|
||||
/**
|
||||
* 固定本次预览或保存的参数,保留原稿中未指定的模型字段。
|
||||
* @returns 真实模型参数和受控修订来源
|
||||
*/
|
||||
function draftParameters() {
|
||||
const original = useSaved.value ? savedDraft.data.value : null
|
||||
const storedInput = original ? original.providerInput : !providerEdited.value ? editingSavedInput.value : undefined
|
||||
const providerInput: DraftProviderInput | undefined =
|
||||
storedInput === undefined
|
||||
? { provider: provider.value, generationOptions: { ...options.value } }
|
||||
: storedInput
|
||||
? (JSON.parse(JSON.stringify(storedInput)) as DraftProviderInput)
|
||||
: undefined
|
||||
const expectedCurrentFormalSourceFingerprint = original
|
||||
? (original.expectedCurrentFormalSourceFingerprint ?? undefined)
|
||||
: formalQuery.data.value?.keyframe.formalSourceFingerprint
|
||||
return { providerInput, expectedCurrentFormalSourceFingerprint }
|
||||
}
|
||||
|
||||
/** 保存是显式整份替换,不触发免费预览或采用。 */
|
||||
async function saveDraft() {
|
||||
if (
|
||||
!canPreview.value ||
|
||||
props.disabled ||
|
||||
savingDraft.value ||
|
||||
saving.value ||
|
||||
savedDraft.loading.value ||
|
||||
!savedDraft.updatedAt.value ||
|
||||
savedDraft.error.value ||
|
||||
draftConflict.value
|
||||
)
|
||||
return
|
||||
const target = key.value
|
||||
clearPreview()
|
||||
savingDraft.value = true
|
||||
try {
|
||||
const result = await derivedReviewApi.saveDraft(props.projectId, props.shot.shotId, {
|
||||
expectedRevision: savedDraft.data.value?.revision ?? null,
|
||||
draft: buildDraft(),
|
||||
...draftParameters()
|
||||
})
|
||||
if (target !== key.value) return
|
||||
if (result.shotId !== props.shot.shotId) throw new Error('保存回执与当前镜头不一致。')
|
||||
savedDraft.data.value = result
|
||||
message?.success('已保存待审草案')
|
||||
} catch (cause) {
|
||||
if (target !== key.value) return
|
||||
if (cause instanceof ApiError && cause.status === 409) {
|
||||
draftConflict.value = true
|
||||
const details = cause.details as { code?: string; currentRevision?: number | null } | null
|
||||
const revisionConflict =
|
||||
(details?.code ?? cause.code ?? cause.message.split(':')[0]) ===
|
||||
'KEYFRAME_REVIEW_DRAFT_REVISION_CONFLICT'
|
||||
message?.warning(
|
||||
revisionConflict ? '草案已被更新。当前输入已保留,请重新读取后核对。' : errorMessage(cause)
|
||||
)
|
||||
} else message?.error(errorMessage(cause))
|
||||
} finally {
|
||||
savingDraft.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 免费编译并冻结本次输入,只有同一快照可正式采用。 */
|
||||
async function loadPreview() {
|
||||
if (!canPreview.value || previewing.value || saving.value) return
|
||||
@@ -243,9 +431,14 @@ async function loadPreview() {
|
||||
try {
|
||||
const draft = buildDraft()
|
||||
const shotId = props.shot.shotId
|
||||
const parameters = { provider: provider.value, generationOptions: { ...options.value } }
|
||||
const expectedCurrentFormalSourceFingerprint = formalQuery.data.value?.keyframe.formalSourceFingerprint
|
||||
const preview = await derivedReviewApi.preview(shotId, draft, parameters, controller.signal)
|
||||
const { providerInput: parameters, expectedCurrentFormalSourceFingerprint } = draftParameters()
|
||||
const preview = await derivedReviewApi.preview(
|
||||
shotId,
|
||||
draft,
|
||||
parameters ?? {},
|
||||
controller.signal,
|
||||
props.projectId
|
||||
)
|
||||
if (controller.signal.aborted) return
|
||||
if (preview.shotId !== shotId || !preview.draftFingerprint || preview.productionReady !== false)
|
||||
throw new Error('没有收到本镜头的有效草案预览。')
|
||||
@@ -312,7 +505,7 @@ async function adopt() {
|
||||
<NButton class="workspace-action-button" @click="open = true">摄影草案与审核</NButton>
|
||||
<AppDrawer
|
||||
v-model:open="open"
|
||||
:busy="saving"
|
||||
:busy="saving || savingDraft"
|
||||
title="摄影草案与审核"
|
||||
:description="`第 ${episodeNo} 集 · 镜头 ${shot.beatNo}.${shot.shotNo} · ${shot.title}`"
|
||||
>
|
||||
@@ -344,8 +537,58 @@ async function adopt() {
|
||||
<p v-else-if="preflight.loading.value" role="status" class="text-sm text-muted">正在读取正式审核状态…</p>
|
||||
<NButton v-if="preflight.error.value" @click="preflight.refresh">重新读取审核状态</NButton>
|
||||
|
||||
<!-- 以下是服务端待审草案、版本和保留的原稿 -->
|
||||
<section class="space-y-3 text-sm">
|
||||
<WorkspaceSectionHeading title="已保存草案" />
|
||||
<p v-if="savedDraft.loading.value" role="status" class="text-muted">正在读取草案…</p>
|
||||
<template v-if="savedDraft.data.value">
|
||||
<p>
|
||||
{{ savedDraft.data.value.status === 'stale' ? '草案来源已变化' : '有已保存的待审草案' }} · 第
|
||||
{{ savedDraft.data.value.revision }} 版 · {{ formatDate(savedDraft.data.value.updatedAt) }}
|
||||
</p>
|
||||
<p v-if="savedDraft.data.value.status === 'stale'" class="text-muted">
|
||||
{{ userFacingText(savedDraft.data.value.staleReason, '请刷新正式来源并重新核对。') }}
|
||||
</p>
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<NButton
|
||||
v-if="!useSaved"
|
||||
size="small"
|
||||
:disabled="saving || savingDraft"
|
||||
@click="useSaved = true"
|
||||
>查看已保存草案</NButton
|
||||
>
|
||||
<NButton v-else size="small" :disabled="saving || savingDraft" @click="editCurrentDraft">{{
|
||||
formal ? '基于当前来源重新编辑' : '导入已复核草案'
|
||||
}}</NButton>
|
||||
<NButton size="small" @click="copySavedDraft">复制原稿</NButton>
|
||||
</div>
|
||||
<NCollapse v-if="useSaved">
|
||||
<NCollapseItem name="saved-draft" title="查看保存的摄影、状态与原参数">
|
||||
<p>构图:{{ savedDraft.data.value.draft.direction.composition }}</p>
|
||||
<p>摄影机位置:{{ savedDraft.data.value.draft.direction.cameraPosition }}</p>
|
||||
<pre class="mt-2 whitespace-pre-wrap wrap-anywhere text-xs">{{ savedDraftText }}</pre>
|
||||
<pre
|
||||
v-if="savedDraft.data.value.providerInput"
|
||||
class="mt-2 whitespace-pre-wrap wrap-anywhere text-xs"
|
||||
>{{ JSON.stringify(savedDraft.data.value.providerInput, null, 2) }}</pre>
|
||||
</NCollapseItem>
|
||||
</NCollapse>
|
||||
</template>
|
||||
<p v-else-if="!savedDraft.loading.value && !savedDraft.error.value" class="text-muted">
|
||||
此镜头还没有已保存的待审草案。
|
||||
</p>
|
||||
<p v-if="draftConflict" class="text-muted">当前输入已保留。请重新读取保存记录,核对后再保存。</p>
|
||||
<NButton
|
||||
v-if="draftConflict || savedDraft.error.value"
|
||||
size="small"
|
||||
:loading="savedDraft.loading.value"
|
||||
@click="reloadSavedDraft"
|
||||
>重新读取草案</NButton
|
||||
>
|
||||
</section>
|
||||
|
||||
<!-- 以下是受控摄影修订与场景沿用 -->
|
||||
<section v-if="formal" class="space-y-3 text-sm">
|
||||
<section v-if="formal && !useSaved" class="space-y-3 text-sm">
|
||||
<WorkspaceSectionHeading
|
||||
title="待审修改"
|
||||
description="可单独修订构图与机位,或填写所选场景的空缺即时状态。"
|
||||
@@ -407,7 +650,7 @@ async function adopt() {
|
||||
</template>
|
||||
</template>
|
||||
</section>
|
||||
<section v-else class="space-y-3">
|
||||
<section v-else-if="!useSaved" class="space-y-3">
|
||||
<WorkspaceSectionHeading
|
||||
title="导入待审摄影草案"
|
||||
description="粘贴为当前分镜版本准备的草案,再免费核对实际输入。"
|
||||
@@ -423,19 +666,34 @@ async function adopt() {
|
||||
</section>
|
||||
|
||||
<!-- 以下是沿用项目模型目录的预览参数 -->
|
||||
<section v-if="configuration.data.value" class="space-y-4">
|
||||
<section v-if="configuration.data.value && !useSaved" class="space-y-4">
|
||||
<WorkspaceSectionHeading title="预览模型" />
|
||||
<GenerationModelControls
|
||||
type="image"
|
||||
:catalog="configuration.data.value.catalog"
|
||||
:aspect-ratio="configuration.data.value.profile.aspectRatio"
|
||||
v-model:provider="provider"
|
||||
v-model:options="options"
|
||||
:provider="provider"
|
||||
:options="options"
|
||||
@update:provider="
|
||||
value => {
|
||||
providerEdited = true
|
||||
provider = value
|
||||
}
|
||||
"
|
||||
@update:options="
|
||||
value => {
|
||||
providerEdited = true
|
||||
options = value
|
||||
}
|
||||
"
|
||||
:disabled="saving"
|
||||
/>
|
||||
</section>
|
||||
<NButton v-if="configuration.error.value" @click="configuration.refresh">重新读取模型配置</NButton>
|
||||
<NButton :loading="previewing" :disabled="!canPreview || saving || previewing" @click="loadPreview"
|
||||
<NButton
|
||||
:loading="previewing"
|
||||
:disabled="!canPreview || saving || savingDraft || previewing"
|
||||
@click="loadPreview"
|
||||
>免费预览摄影草案</NButton
|
||||
>
|
||||
|
||||
@@ -532,7 +790,22 @@ async function adopt() {
|
||||
</section>
|
||||
</div>
|
||||
<template #footer>
|
||||
<NButton :disabled="saving" @click="open = false">关闭</NButton>
|
||||
<NButton :disabled="saving || savingDraft" @click="open = false">关闭</NButton>
|
||||
<NButton
|
||||
v-if="!useSaved"
|
||||
:loading="savingDraft"
|
||||
:disabled="
|
||||
disabled ||
|
||||
!canPreview ||
|
||||
saving ||
|
||||
savedDraft.loading.value ||
|
||||
!savedDraft.updatedAt.value ||
|
||||
!!savedDraft.error.value ||
|
||||
draftConflict
|
||||
"
|
||||
@click="saveDraft"
|
||||
>保存草案</NButton
|
||||
>
|
||||
<NButton
|
||||
v-if="reviewed"
|
||||
type="primary"
|
||||
|
||||
@@ -1,27 +1,53 @@
|
||||
import { keyframeScope } from '../production/keyframe-scope'
|
||||
import { request } from '../../lib/http'
|
||||
import type {
|
||||
DerivedReviewSelection,
|
||||
DraftProviderInput,
|
||||
ShotDraftPreview,
|
||||
ShotReviewDraft
|
||||
ShotReviewDraft,
|
||||
SavedKeyframeDraft,
|
||||
SaveKeyframeDraft
|
||||
} from './derived-review.types'
|
||||
|
||||
/** 已审摄影草案的正式读写入口。 */
|
||||
export const derivedReviewApi = {
|
||||
/** 读取指定镜头已保存的原稿,无草案时返回空。 */
|
||||
draft: (projectId: string, shotId: string, signal?: AbortSignal) =>
|
||||
request<SavedKeyframeDraft | null>(
|
||||
keyframeScope(`/storyboard-shots/${encodeURIComponent(shotId)}/keyframe-review-draft`, projectId),
|
||||
{ signal }
|
||||
),
|
||||
/** 显式保存完整原稿,服务端按修订号防止覆盖。 */
|
||||
saveDraft: (projectId: string, shotId: string, body: SaveKeyframeDraft) =>
|
||||
request<SavedKeyframeDraft>(
|
||||
keyframeScope(`/storyboard-shots/${encodeURIComponent(shotId)}/keyframe-review-draft`, projectId),
|
||||
{ method: 'PUT', body }
|
||||
),
|
||||
|
||||
/**
|
||||
* 免费编译草案,不保存、不调用模型。
|
||||
* @param shotId 当前正式镜头
|
||||
* @param draft 待审草案
|
||||
* @param provider 选定的模型参数
|
||||
* @param signal 取消过期查询
|
||||
* @param projectId 当前正式项目
|
||||
* @returns 对应草案指纹及实际模型输入
|
||||
*/
|
||||
preview: (shotId: string, draft: ShotReviewDraft, provider: DraftProviderInput, signal?: AbortSignal) =>
|
||||
request<ShotDraftPreview>(`/storyboard-shots/${encodeURIComponent(shotId)}/keyframe/preview`, {
|
||||
method: 'POST',
|
||||
body: { ...provider, draft },
|
||||
signal
|
||||
}),
|
||||
preview: (
|
||||
shotId: string,
|
||||
draft: ShotReviewDraft,
|
||||
provider: DraftProviderInput,
|
||||
signal?: AbortSignal,
|
||||
projectId?: string
|
||||
) =>
|
||||
request<ShotDraftPreview>(
|
||||
keyframeScope(`/storyboard-shots/${encodeURIComponent(shotId)}/keyframe/preview`, projectId),
|
||||
{
|
||||
method: 'POST',
|
||||
body: { ...provider, draft },
|
||||
signal
|
||||
}
|
||||
),
|
||||
/**
|
||||
* 用户明确采用已经预览的镜头草案。
|
||||
* @param projectId 正式项目
|
||||
|
||||
@@ -44,7 +44,10 @@ export interface ShotReviewDraft {
|
||||
}
|
||||
|
||||
/** 原样传给免费预览和人工采用的可选模型参数。 */
|
||||
export type DraftProviderInput = Pick<GenerateKeyframeInput, 'provider' | 'generationOptions' | 'width' | 'height'>
|
||||
export type DraftProviderInput = Pick<GenerateKeyframeInput, 'provider' | 'width' | 'height'> & {
|
||||
/** 原预览使用的模型参数,可保留服务端公开的 JSON 值。 */
|
||||
generationOptions?: Record<string, unknown>
|
||||
}
|
||||
|
||||
/** 草案只有草案指纹,不能提交正式生图。 */
|
||||
export interface ShotDraftPreview extends Omit<KeyframeGenerationPreview, 'previewFingerprint'> {
|
||||
@@ -62,3 +65,23 @@ export interface DerivedReviewSelection extends DraftProviderInput {
|
||||
/** 对应的免费预览指纹。 */ expectedDraftFingerprint: string
|
||||
/** 控制正式修订时必须携带的旧来源。 */ expectedCurrentFormalSourceFingerprint?: string
|
||||
}
|
||||
|
||||
/** 独立保存的待审草案,不代表已预览或已采用。 */
|
||||
export interface SavedKeyframeDraft {
|
||||
/** 所属正式镜头。 */ shotId: string
|
||||
/** 防止并发覆盖的草案修订。 */ revision: number
|
||||
/** 保存时间。 */ updatedAt: string
|
||||
/** 来源是否仍可核对。 */ status: 'current' | 'stale'
|
||||
/** 旧来源不能采用的原因。 */ staleReason: string | null
|
||||
/** 保存的完整原稿。 */ draft: ShotReviewDraft
|
||||
/** 原模型参数。 */ providerInput: DraftProviderInput | null
|
||||
/** 受控修订绑定的正式来源。 */ expectedCurrentFormalSourceFingerprint: string | null
|
||||
}
|
||||
|
||||
/** 显式替换草案时提交的版本和完整内容。 */
|
||||
export interface SaveKeyframeDraft {
|
||||
/** 首次保存为 null,否则使用已读修订。 */ expectedRevision: number | null
|
||||
/** 需保存的完整草案。 */ draft: ShotReviewDraft
|
||||
/** 本次原模型参数。 */ providerInput?: DraftProviderInput
|
||||
/** 受控修订绑定的正式来源。 */ expectedCurrentFormalSourceFingerprint?: string
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { NButton, NCollapse, NCollapseItem, NTag } from 'naive-ui'
|
||||
import { Eye } from '@lucide/vue'
|
||||
import type { HistoricalKeyframeReference } from '../../production/keyframe-input'
|
||||
import RevealImage from '../../../components/ui/RevealImage.vue'
|
||||
import { referenceImageUrl } from '../../../lib/assets'
|
||||
import { userFacingText } from '../../../lib/user-facing-text'
|
||||
@@ -19,6 +20,8 @@ const props = defineProps<{
|
||||
loading: boolean
|
||||
/** 只显示已取得的实际输入。 */
|
||||
displayOnly?: boolean
|
||||
/** 历史预览按顺序展示当次像素证据。 */
|
||||
historicalReferences?: HistoricalKeyframeReference[]
|
||||
/** 当前不能读取预览。 */
|
||||
disabled?: boolean
|
||||
/** 读取或提交错误。 */
|
||||
@@ -28,6 +31,14 @@ const props = defineProps<{
|
||||
}>()
|
||||
/** 预览由当前表单按真实参数读取。 */
|
||||
const emit = defineEmits<{ load: [] }>()
|
||||
/** 详情读取之后取图仍可能失败,保留当次证据。 */
|
||||
const unavailable = ref<number[]>([])
|
||||
watch(
|
||||
() => props.preview,
|
||||
() => {
|
||||
unavailable.value = []
|
||||
}
|
||||
)
|
||||
/** 参考职责统一中文展示,不展示内部图片编号。 */
|
||||
const roles: Record<string, string> = {
|
||||
'identity-anchor': '主体外观母版',
|
||||
@@ -52,11 +63,13 @@ const references = computed(() => {
|
||||
const snapshot = preview.providerInputSnapshot?.references.find(item => item.imageNumber === index + 1)
|
||||
const plan = selected?.[index]
|
||||
return {
|
||||
order: index + 1,
|
||||
order: props.historicalReferences?.[index]?.imageNumber ?? index + 1,
|
||||
evidence: props.historicalReferences?.[index],
|
||||
src: /^data:image\/(png|jpeg|webp|gif|avif);base64,[a-z\d+/=]+$/i.test(image)
|
||||
? image
|
||||
: referenceImageUrl(image),
|
||||
bindings:
|
||||
props.historicalReferences?.[index]?.bindings ??
|
||||
snapshot?.bindings ??
|
||||
reference?.bindings ??
|
||||
plan?.bindings ??
|
||||
@@ -110,15 +123,28 @@ const omitted = computed(
|
||||
<li v-for="item in references" :key="item.order" class="min-w-0">
|
||||
<div class="asset-image max-w-sm">
|
||||
<RevealImage
|
||||
v-if="item.src"
|
||||
v-if="item.src && !unavailable.includes(item.order)"
|
||||
:src="item.src"
|
||||
:alt="`参考图 ${item.order}`"
|
||||
object-fit="contain"
|
||||
preview
|
||||
@error="unavailable.push(item.order)"
|
||||
/>
|
||||
<span v-else class="text-muted">图片无法预览</span>
|
||||
<span v-else class="p-3 text-muted">{{
|
||||
item.evidence?.availability === 'changed'
|
||||
? '原件字节已变化'
|
||||
: item.evidence
|
||||
? '原件不可用,可刷新详情'
|
||||
: '图片无法预览'
|
||||
}}</span>
|
||||
</div>
|
||||
<p class="mt-1 font-medium">图 {{ item.order }}</p>
|
||||
<p v-if="item.evidence" class="wrap-anywhere text-muted">
|
||||
{{ item.evidence.width }} × {{ item.evidence.height }} · {{ item.evidence.mimeType }} ·
|
||||
{{ item.evidence.byteLength }} 字节 <br />文件指纹:{{ item.evidence.sha256 }}<br />像素指纹:{{
|
||||
item.evidence.pixelFingerprint
|
||||
}}
|
||||
</p>
|
||||
<p v-for="(binding, index) in item.bindings" :key="index" class="wrap-anywhere text-muted">
|
||||
{{ roles[binding.role] ?? '图片参考'
|
||||
}}<template v-if="binding.subjectRef"> · {{ binding.subjectRef }}</template>
|
||||
@@ -135,6 +161,12 @@ const omitted = computed(
|
||||
<NCollapse :default-expanded-names="['prompt']">
|
||||
<NCollapseItem name="prompt" title="本次实际使用的画面描述">
|
||||
<p class="whitespace-pre-wrap wrap-anywhere">{{ preview.providerPrompt }}</p>
|
||||
<p
|
||||
v-if="preview.providerInputSnapshot?.negativePrompt"
|
||||
class="mt-3 whitespace-pre-wrap wrap-anywhere"
|
||||
>
|
||||
负向提示词:{{ preview.providerInputSnapshot.negativePrompt }}
|
||||
</p>
|
||||
</NCollapseItem>
|
||||
<NCollapseItem v-if="omitted?.length" name="omitted" title="未进入模型的参考图">
|
||||
<ul class="space-y-2">
|
||||
|
||||
@@ -23,6 +23,13 @@ export const workflowExecutionApi = {
|
||||
*/
|
||||
eventsUrl: (projectId: string, workflowName: string) =>
|
||||
`${(import.meta.env.VITE_API_BASE_URL || '/api').replace(/\/$/, '')}/projects/${encodeURIComponent(projectId)}/workflow-executions/events?${new URLSearchParams({ workflowName })}`,
|
||||
/**
|
||||
* 订阅单个已确认执行,不发现或提交其他任务。
|
||||
* @param executionId 正式执行编号
|
||||
* @returns 服务端单执行事件地址
|
||||
*/
|
||||
executionEventsUrl: (executionId: string) =>
|
||||
`${(import.meta.env.VITE_API_BASE_URL || '/api').replace(/\/$/, '')}/workflow-executions/${encodeURIComponent(executionId)}/events`,
|
||||
get: (executionId: string, signal?: AbortSignal) =>
|
||||
request<WorkflowExecution>(`/workflow-executions/${encodeURIComponent(executionId)}`, { signal })
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
import { flushPromises, mount } from '@vue/test-utils'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import KeyframeInputDetails from '@/features/production/components/KeyframeInputDetails.vue'
|
||||
import { historicalReferenceUrl, type HistoricalKeyframeReference } from '@/features/production/keyframe-input'
|
||||
|
||||
/** 两种职责对应同一张实际参考图。 */
|
||||
const reference: HistoricalKeyframeReference = {
|
||||
imageNumber: 1,
|
||||
sha256: 'a'.repeat(64),
|
||||
pixelFingerprint: 'b'.repeat(64),
|
||||
mimeType: 'image/png',
|
||||
width: 512,
|
||||
height: 512,
|
||||
byteLength: 100,
|
||||
bindings: [
|
||||
{ role: 'identity-anchor', subjectRef: '@CH01' },
|
||||
{ role: 'form-primary', subjectRef: '@CH02' }
|
||||
],
|
||||
availability: 'available',
|
||||
imageUrl: '/api/storyboard-shots/shot/keyframes/one/generation-input/references/1?projectId=project'
|
||||
}
|
||||
|
||||
describe('历史首帧输入', () => {
|
||||
it('只解析归属当前候选的正式原件地址', () => {
|
||||
expect(historicalReferenceUrl(reference, 'project', 'shot', 'one')).toContain('?projectId=project')
|
||||
expect(historicalReferenceUrl(reference, 'project', 'shot', 'two')).toBeNull()
|
||||
expect(historicalReferenceUrl(reference, 'wrong', 'shot', 'one')).toBeNull()
|
||||
expect(historicalReferenceUrl({ ...reference, availability: 'changed' }, 'project', 'shot', 'one')).toBeNull()
|
||||
})
|
||||
|
||||
it('展开才读取历史,切换候选不混用输入和参考', async () => {
|
||||
const fetcher = vi.fn<typeof fetch>().mockImplementation(async path => {
|
||||
const keyframeId = String(path).includes('/one/') ? 'one' : 'two'
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
data: {
|
||||
shotId: 'shot',
|
||||
keyframeId,
|
||||
inputSnapshotStatus: 'recorded',
|
||||
providerInputFingerprint: 'fingerprint',
|
||||
providerInputSnapshot: {
|
||||
provider: 'seedream',
|
||||
model: 'test',
|
||||
providerPrompt: '当次描述 ' + keyframeId,
|
||||
fingerprint: 'fingerprint',
|
||||
sourceFingerprint: 'source',
|
||||
generationOptions: { size: '2048x2048' },
|
||||
version: 1,
|
||||
references: [
|
||||
{
|
||||
...reference,
|
||||
imageUrl: null,
|
||||
availability: keyframeId === 'one' ? 'changed' : 'unavailable'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
})
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
const wrapper = mount(KeyframeInputDetails, {
|
||||
props: { projectId: 'project', shotId: 'shot', keyframeId: 'one' }
|
||||
})
|
||||
try {
|
||||
expect(fetcher).not.toHaveBeenCalled()
|
||||
await wrapper.get('.n-collapse-item__header-main').trigger('click')
|
||||
await flushPromises()
|
||||
expect(wrapper.text()).toContain('当次描述 one')
|
||||
expect(wrapper.text()).toContain('原件字节已变化')
|
||||
expect(wrapper.text()).toContain('@CH01')
|
||||
expect(wrapper.text()).toContain('@CH02')
|
||||
expect(wrapper.find('img').exists()).toBe(false)
|
||||
await wrapper.setProps({ keyframeId: 'two' })
|
||||
await flushPromises()
|
||||
expect(wrapper.text()).toContain('当次描述 two')
|
||||
expect(wrapper.text()).not.toContain('当次描述 one')
|
||||
expect(wrapper.text()).toContain('原件不可用')
|
||||
expect(fetcher.mock.calls.map(([url]) => url)).toEqual([
|
||||
'/api/storyboard-shots/shot/keyframes/one/generation-input?projectId=project',
|
||||
'/api/storyboard-shots/shot/keyframes/two/generation-input?projectId=project'
|
||||
])
|
||||
} finally {
|
||||
wrapper.unmount()
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -114,40 +114,45 @@ describe('正式首帧 Vision 的费用与恢复边界', () => {
|
||||
expect(fetcher.mock.calls.filter(([, options]) => options?.method === 'POST')).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('有正式可继续结论时使用原文字显式提交,保留已完成步骤', async () => {
|
||||
let accepted = 0
|
||||
const saved = history('failed', { recoveryRequired: false, resumeAvailable: true })
|
||||
it('新会话从正式历史恢复任务,只显式发送任务和指纹', async () => {
|
||||
const fingerprint = 'f'.repeat(64)
|
||||
const saved = {
|
||||
...history('failed'),
|
||||
allowedTexts: ['旧门牌'],
|
||||
requestFingerprint: fingerprint,
|
||||
recoveryRequired: false,
|
||||
resumeAvailable: true
|
||||
}
|
||||
const fetcher = vi.fn<typeof fetch>().mockImplementation(async (_url, options) => {
|
||||
if (options?.method === 'POST') {
|
||||
accepted++
|
||||
if (options?.method === 'POST')
|
||||
return response(
|
||||
{
|
||||
shotId,
|
||||
keyframeId: assetId,
|
||||
validationTaskId: taskId,
|
||||
executionId: accepted === 1 ? executionId : 'resume-execution',
|
||||
executionId: 'resume-execution',
|
||||
status: 'pending'
|
||||
},
|
||||
202
|
||||
)
|
||||
}
|
||||
return response([saved])
|
||||
})
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
await submitKeyframeVision(shotId, assetId, ['旧门牌'], [])
|
||||
const vision = observe()
|
||||
await flushPromises()
|
||||
expect(vision.resumeTexts.value).toEqual(['旧门牌'])
|
||||
const resume = { resumeValidationTaskId: taskId, expectedRequestFingerprint: fingerprint }
|
||||
expect(vision.resume.value).toEqual(resume)
|
||||
expect(vision.state.value.resumable?.steps?.map(item => item.status)).toEqual(['completed', 'received'])
|
||||
await expect(submitKeyframeVision(shotId, assetId, ['新门牌'], [saved])).rejects.toThrow('原审核参数')
|
||||
expect(accepted).toBe(1)
|
||||
await submitKeyframeVision(shotId, assetId, ['旧门牌'], [saved])
|
||||
expect(accepted).toBe(2)
|
||||
expect(
|
||||
fetcher.mock.calls
|
||||
.filter(([, options]) => options?.method === 'POST')
|
||||
.map(([, options]) => JSON.parse(String(options?.body)))
|
||||
).toEqual([{ allowedTexts: ['旧门牌'] }, { allowedTexts: ['旧门牌'] }])
|
||||
await expect(submitKeyframeVision(shotId, assetId, ['新门牌'], [saved])).rejects.toThrow('继续原审核')
|
||||
await expect(
|
||||
submitKeyframeVision(shotId, assetId, { ...resume, expectedRequestFingerprint: 'a'.repeat(64) }, [saved])
|
||||
).rejects.toThrow('任务状态已变化')
|
||||
expect(fetcher.mock.calls.filter(([, options]) => options?.method === 'POST')).toHaveLength(0)
|
||||
await submitKeyframeVision(shotId, assetId, resume, [saved], 'project/1')
|
||||
const writes = fetcher.mock.calls.filter(([, options]) => options?.method === 'POST')
|
||||
expect(writes).toHaveLength(1)
|
||||
expect(String(writes[0]?.[0])).toContain('?projectId=project%2F1')
|
||||
expect(JSON.parse(String(writes[0]?.[1]?.body))).toEqual(resume)
|
||||
})
|
||||
|
||||
it('409 活动审核只观察原编号,不能把当前表单参数当作原参数', async () => {
|
||||
@@ -168,7 +173,7 @@ describe('正式首帧 Vision 的费用与恢复边界', () => {
|
||||
const vision = observe()
|
||||
await flushPromises()
|
||||
expect(vision.execution.data.value?.id).toBe(executionId)
|
||||
expect(vision.resumeTexts.value).toBeNull()
|
||||
expect(vision.resume.value).toBeNull()
|
||||
expect(vision.blocked.value).toBe(true)
|
||||
})
|
||||
})
|
||||
@@ -114,7 +114,7 @@ function server() {
|
||||
const executionState = { status: 'completed' as 'running' | 'completed' | 'failed' }
|
||||
let batchMetadata: QualityInput | null = null
|
||||
const fetcher = vi.fn<typeof fetch>().mockImplementation(async (url, options) => {
|
||||
const path = String(url)
|
||||
const path = String(url).split('?')[0]!
|
||||
let data: unknown
|
||||
if (options?.method === 'POST') {
|
||||
if (path.endsWith('/generate-quality')) {
|
||||
@@ -235,7 +235,9 @@ describe('视觉质量契约与付费边界', () => {
|
||||
expect(data.fetcher).not.toHaveBeenCalled()
|
||||
await data.service.run('validate', input({ allowedTexts: ['记忆当铺'] }))
|
||||
expect(data.posts()).toHaveLength(1)
|
||||
expect(data.posts()[0]?.[0]).toBe('/api/storyboard-shots/shot-1/keyframes/keyframe-1/validate')
|
||||
expect(data.posts()[0]?.[0]).toBe(
|
||||
'/api/storyboard-shots/shot-1/keyframes/keyframe-1/validate?projectId=' + data.projectId
|
||||
)
|
||||
expect(JSON.parse(String(data.posts()[0]?.[1]?.body))).toEqual({ allowedTexts: ['记忆当铺'] })
|
||||
expect(data.service.session.value.receipt).toMatchObject({ kind: 'keyframe', result: { passed: true } })
|
||||
})
|
||||
|
||||
@@ -142,3 +142,55 @@ describe('摄影草案与规格复用的正式契约', () => {
|
||||
expect(JSON.parse(String(mock.mock.calls[0]![1]?.body))).toEqual({ reuseOnly: true })
|
||||
})
|
||||
})
|
||||
|
||||
/** 草案 API 的隔离保存记录,只模拟正式修订规则。 */
|
||||
describe('待审摄影草案的保存与回读', () => {
|
||||
it('按项目和镜头区分草案;首次保存、回读和 409 不触发预览', async () => {
|
||||
const rows = new Map<string, { revision: number; draft: unknown }>()
|
||||
const fetcher = vi.fn<typeof fetch>().mockImplementation(async (path, options) => {
|
||||
const url = new URL(String(path), 'http://localhost')
|
||||
const key = url.pathname
|
||||
const previous = rows.get(key)
|
||||
if (options?.method !== 'PUT') return new Response(JSON.stringify({ data: previous ?? null }))
|
||||
const body = JSON.parse(String(options.body)) as { expectedRevision: number | null; draft: unknown }
|
||||
if (body.expectedRevision !== (previous?.revision ?? null))
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
message: '草案修订已变化',
|
||||
details: {
|
||||
code: 'KEYFRAME_REVIEW_DRAFT_REVISION_CONFLICT',
|
||||
currentRevision: previous?.revision ?? null
|
||||
}
|
||||
}),
|
||||
{ status: 409 }
|
||||
)
|
||||
const data = { revision: (previous?.revision ?? 0) + 1, draft: body.draft }
|
||||
rows.set(key, data)
|
||||
return new Response(JSON.stringify({ data }))
|
||||
})
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
const first = draftFromFormal(shot, keyframe, 'b'.repeat(64))
|
||||
const second = { ...first, direction: { ...first.direction, composition: '另一镜构图' } }
|
||||
expect(await derivedReviewApi.draft('p/1', 'one')).toBeNull()
|
||||
await derivedReviewApi.saveDraft('p/1', 'one', { expectedRevision: null, draft: first })
|
||||
await derivedReviewApi.saveDraft('p/1', 'two', { expectedRevision: null, draft: second })
|
||||
expect((await derivedReviewApi.draft('p/1', 'one'))?.draft.direction.composition).toBe(
|
||||
first.direction.composition
|
||||
)
|
||||
expect((await derivedReviewApi.draft('p/1', 'two'))?.draft.direction.composition).toBe('另一镜构图')
|
||||
await expect(
|
||||
derivedReviewApi.saveDraft('p/1', 'one', { expectedRevision: null, draft: second })
|
||||
).rejects.toMatchObject({
|
||||
status: 409,
|
||||
details: { currentRevision: 1 }
|
||||
})
|
||||
expect(fetcher.mock.calls.map(([url]) => String(url))).toEqual([
|
||||
'/api/storyboard-shots/one/keyframe-review-draft?projectId=p%2F1',
|
||||
'/api/storyboard-shots/one/keyframe-review-draft?projectId=p%2F1',
|
||||
'/api/storyboard-shots/two/keyframe-review-draft?projectId=p%2F1',
|
||||
'/api/storyboard-shots/one/keyframe-review-draft?projectId=p%2F1',
|
||||
'/api/storyboard-shots/two/keyframe-review-draft?projectId=p%2F1',
|
||||
'/api/storyboard-shots/one/keyframe-review-draft?projectId=p%2F1'
|
||||
])
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user