feat(short-drama-agent-front): 接入独立来源复核闭环
This commit is contained in:
1 parent
7e149a10c0
commit
13efe5b786
9 files changed
+1312
-1
No files matched your search
@@ -0,0 +1,34 @@
|
||||
# B04-12 旧主图独立新来源复核
|
||||
|
||||
## 接入范围
|
||||
|
||||
依据后端 dev 的 b04-12-primary-source-review-frontend-prompt.md、公开 shot-keyframe-source-review.md、正式 Router、SourceVisionApprovalSchema 和 service 实现。仅修改前端,未调用真实 Provider。
|
||||
|
||||
首帧卡片中的“按当前来源人工复核”适用于已完成 Primary,即使原来源过期仍可免费预检。复用 AppDrawer 固定底栏、内容滚动、NMessage、现有项目范围 WorkflowExecution/SSE 和正式分页执行历史。
|
||||
|
||||
- 原图、原件 SHA、原始 Provider 输入、旧 Vision、sourceChanges 与当前参考分开显示;新参考保留全部 bindings,不冒充原生成输入。
|
||||
- 每张物理参考逐项填写身份、结构、空间、动作、连续性;初始全部 unknown,不推断门轴,不将开关门当固定结构变化。
|
||||
- 人工保存绑定 expectedFingerprint、真实审核人、理由和全部观察;保存后回读原记录,原 status、原观察与当前 reviewStatus/current 分开。
|
||||
- 只有当前且 passed 的人工记录才读取免费机器计划;原图和计划的所有指纹、模型、全部步骤可审阅。
|
||||
- 费用批准独立登记。真实批准人、操作人、批准材料 SHA、CNY 范围均由用户填写;maxRequests 严格等于步骤数。更改范围撤销旧授权。
|
||||
- 执行必须再次明确确认,携带本次 authorizationId;恢复只携带正式历史提供的原 task ID 和 request fingerprint。未知费用不提供恢复。
|
||||
- 202 复用已有观察器;200 复用完整结果(含失败)。并发和断线沿用同候选提交保护,不自动重试、换模型或生图。
|
||||
- sourceReviewId 标识独立审核,按原 validationTaskId 展开完整执行历史;旧 Vision 的通过不显示为新来源通过。原 Primary 不被修改,仍需独立三镜/Production 验收。
|
||||
- 关闭、项目/镜头/候选切换取消免费查询,拒绝旧结果;人工回读先比对当前主图预检指纹,避免引用其他主图记录。
|
||||
|
||||
## 浏览器验收
|
||||
|
||||
自动化检查通过:105 个测试文件、782 项测试;lint、格式检查、类型检查和生产构建通过。新增 8 项来源审核测试,覆盖默认未知、明确批准、参数变更、范围切换、并发、断线保护、失败复用及真实组件的只读打开行为。
|
||||
|
||||
复用 localhost:4312 已有 Chrome 项目标签,真实操作全部为只读:
|
||||
|
||||
- 2.1 人工记录显示人工来源观察通过;免费机器计划显示 qwen3.8-max、general/physical 两步。批准人、批准材料和金额无默认值,没有发起授权或 Vision。
|
||||
- 2.2 保留原 insufficient_evidence,展示 needs_review,机器计划入口禁用。
|
||||
- 原图与本次参考分区、逐图初始未知、旧 Vision 不冒充新来源、桌面和 375×667 内容滚动/固定底栏已核对。
|
||||
- 未提交人工观察、未签发真实费用批准、未执行模型、未改原 Primary 或旧 Vision。
|
||||
|
||||
## 已知契约边界
|
||||
|
||||
- 当前没有按首帧列出人工来源记录的接口,已有人工记录需输入真实 reviewId 回读;新机器任务的 sourceReviewId 可从正式审核历史追溯。不使用本机历史缓存补齐列表。
|
||||
- 人工记录 GET 未返回 shotId/keyframeId,页面用当前主图免费预检与原 expectedFingerprint 交叉核对,不匹配的原记录仅供追溯。
|
||||
- 当前计划不提供报价,金额及批准摘要必须来自真实人工批准,不自动估价或生成批准材料。
|
||||
@@ -4,7 +4,8 @@ import ContextNotice from '../../../components/ui/ContextNotice.vue'
|
||||
import IssueHint from '../../../components/ui/IssueHint.vue'
|
||||
import { productionMessage } from '../production-messages'
|
||||
import { useKeyframeVision } from '../keyframe-vision'
|
||||
import { computed, watch } from 'vue'
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import SourceReviewDrawer from './SourceReviewDrawer.vue'
|
||||
import { useQuery } from '../../../composables/useQuery'
|
||||
import { qualityApi } from '../quality-api'
|
||||
import { NButton, NTag } from 'naive-ui'
|
||||
@@ -31,6 +32,15 @@ const props = defineProps<{
|
||||
validationPassed: boolean | null
|
||||
confirming: boolean
|
||||
}>()
|
||||
/** 用户显式打开来源复核,不能自动调用模型。 */
|
||||
const sourceReviewOpen = ref(false)
|
||||
watch(
|
||||
() => JSON.stringify([props.projectId, props.shotId, props.item.id]),
|
||||
() => {
|
||||
sourceReviewOpen.value = false
|
||||
},
|
||||
{ flush: 'sync' }
|
||||
)
|
||||
/** 用户显式触发候选审核、确认或免费恢复。 */
|
||||
const emit = defineEmits<{
|
||||
recover: []
|
||||
@@ -181,6 +191,13 @@ const canSelect = computed(
|
||||
</p>
|
||||
<IssueHint v-if="item.error" :messages="[productionMessage(item.error)]" type="error" />
|
||||
<!-- 以下是来源记录与独立的免费恢复入口 -->
|
||||
<NButton
|
||||
v-if="item.isPrimary && item.status === 'completed' && projectId"
|
||||
class="workspace-action-button mt-2"
|
||||
size="small"
|
||||
@click="sourceReviewOpen = true"
|
||||
>按当前来源人工复核</NButton
|
||||
>
|
||||
<p v-if="item.inputSnapshotStatus" class="mt-2 text-xs text-muted">
|
||||
{{
|
||||
{ recorded: '已保存生成输入', 'not-recorded': '历史生成输入未记录', invalid: '生成输入证据已失效' }[
|
||||
@@ -244,4 +261,11 @@ const canSelect = computed(
|
||||
</ContextNotice>
|
||||
</div>
|
||||
</article>
|
||||
<SourceReviewDrawer
|
||||
v-if="projectId && sourceReviewOpen"
|
||||
v-model:open="sourceReviewOpen"
|
||||
:project-id="projectId"
|
||||
:shot-id="shotId"
|
||||
:keyframe-id="item.id"
|
||||
/>
|
||||
</template>
|
||||
@@ -445,6 +445,9 @@ const records = computed(() =>
|
||||
</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>
|
||||
<p v-if="record.sourceReviewId" class="wrap-anywhere text-sm">
|
||||
独立新来源审核 · 人工记录 {{ record.sourceReviewId }}(与旧 Vision 分开存证)
|
||||
</p>
|
||||
<template v-if="record.validation">
|
||||
<p>合并结论:{{ userFacingText(record.validation.summary) }}</p>
|
||||
<p v-for="(issue, index) in record.validation.issues" :key="index" class="text-danger">
|
||||
|
||||
@@ -0,0 +1,378 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { NButton, NCheckbox, NCollapse, NCollapseItem, NInput, NInputNumber, NSelect } from 'naive-ui'
|
||||
import AppDrawer from '../../../components/ui/AppDrawer.vue'
|
||||
import { AssetImage } from '../../../components/ui'
|
||||
import WorkspaceSectionHeading from '../../../components/ui/WorkspaceSectionHeading.vue'
|
||||
import { validationStepNames } from '../validation-execution-labels'
|
||||
import { isVisualValidation, keyframeValidationPassed } from '../quality'
|
||||
import { userFacingText } from '../../../lib/user-facing-text'
|
||||
import { sourceFindingLabels } from '../source-review'
|
||||
import { useSourceReview } from '../useSourceReview'
|
||||
import KeyframeExecutionStatus from './KeyframeExecutionStatus.vue'
|
||||
import KeyframeExecutionHistory from './KeyframeExecutionHistory.vue'
|
||||
/** 仅供唯一完成主图的来源复核入口。 */
|
||||
const props = defineProps<{
|
||||
/** 项目。 */ projectId: string
|
||||
/** 镜头。 */ shotId: string
|
||||
/** 原主图。 */ keyframeId: string
|
||||
}>()
|
||||
/** 全屏开关,关闭取消免费查询。 */
|
||||
const open = defineModel<boolean>('open', { default: false })
|
||||
/** 三段范围与打开状态共用取消身份。 */
|
||||
const key = computed(() => (open.value ? JSON.stringify([props.shotId, props.keyframeId, props.projectId]) : ''))
|
||||
/** 人工、批准和执行分别操作。 */
|
||||
const form = useSourceReview(key)
|
||||
/** 仅写入时锁关闭。 */
|
||||
const busy = computed(() => ['save', 'authorize', 'execute'].includes(form.pending.value))
|
||||
/** 用户明确选择,打开时不预填通过。 */
|
||||
const findingOptions = [
|
||||
{ label: '未知/无法看清', value: 'unknown' },
|
||||
{ label: '通过', value: 'passed' },
|
||||
{ label: '不通过', value: 'failed' }
|
||||
]
|
||||
/** 当前人工记录或新机器任务,供正式执行历史展开。 */
|
||||
const task = computed(() => form.vision.history.data.value?.find(item => item.sourceReviewId === form.reviewId.value))
|
||||
/** 已知原任务才允许明确继续,未知费用不显示恢复按钮。 */
|
||||
const canResume = computed(
|
||||
() =>
|
||||
!!form.vision.resume.value &&
|
||||
!form.vision.state.value.unknown &&
|
||||
task.value?.id === form.vision.resume.value.resumeValidationTaskId
|
||||
)
|
||||
/** 完整回执和实际质量分别表达,失败也复用原结果。 */
|
||||
const resultLabel = computed(() =>
|
||||
isVisualValidation(form.result.value)
|
||||
? keyframeValidationPassed(form.result.value)
|
||||
? '独立机器审核通过,仍需三镜连续性验收'
|
||||
: '执行完成,质量未通过或待复核;保留原结果,不自动重发'
|
||||
: form.result.value
|
||||
? '已受理,正在观察正式执行'
|
||||
: ''
|
||||
)
|
||||
/** 当前观察状态的中文摘要。 */
|
||||
const statusLabels: Record<string, string> = {
|
||||
passed: '人工来源观察通过',
|
||||
failed: '人工来源观察未通过',
|
||||
needs_review: '待复核,存在未知观察',
|
||||
insufficient_evidence: '证据不足',
|
||||
stale: '来源已失效'
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<!-- 以下是保留原主图的独立来源观察,不晋升或覆盖旧审核 -->
|
||||
<AppDrawer
|
||||
v-model:open="open"
|
||||
title="按当前来源人工复核"
|
||||
description="人工观察、机器审核与跨镜验收分别进行;不会生图或替换主首帧。"
|
||||
:busy="busy"
|
||||
>
|
||||
<div class="space-y-(--app-content-gap)">
|
||||
<div class="flex flex-wrap gap-3">
|
||||
<NButton
|
||||
:loading="form.pending.value === 'preview'"
|
||||
:disabled="!!form.pending.value"
|
||||
@click="form.loadPreview"
|
||||
>免费预检当前来源</NButton
|
||||
>
|
||||
<NInput
|
||||
v-model:value="form.reviewId.value"
|
||||
:disabled="!!form.pending.value"
|
||||
placeholder="输入已有人工来源记录编号以回读"
|
||||
aria-label="人工来源记录编号"
|
||||
class="sm:max-w-md"
|
||||
/>
|
||||
<NButton
|
||||
:loading="form.pending.value === 'read'"
|
||||
:disabled="!!form.pending.value || !form.reviewId.value.trim()"
|
||||
@click="form.readRecord"
|
||||
>回读人工记录</NButton
|
||||
>
|
||||
</div>
|
||||
<template v-if="form.preview.value">
|
||||
<WorkspaceSectionHeading title="保留的原主首帧" description="以下生成输入及旧审核均为历史记录。" />
|
||||
<AssetImage
|
||||
class="max-w-sm aspect-square"
|
||||
:src="form.preview.value.imageUrl"
|
||||
alt="保留的原主首帧"
|
||||
object-fit="contain"
|
||||
preview
|
||||
/>
|
||||
<p class="wrap-anywhere text-xs text-muted">原件 SHA:{{ form.preview.value.originalPixels.sha256 }}</p>
|
||||
<NCollapse
|
||||
><NCollapseItem title="历史生成输入、旧审核与来源变化" name="original">
|
||||
<pre class="whitespace-pre-wrap wrap-anywhere text-xs">{{
|
||||
JSON.stringify(
|
||||
{
|
||||
originalProviderInput: form.preview.value.originalProviderInput,
|
||||
historicalVision: form.preview.value.historicalVision,
|
||||
sourceChanges: form.preview.value.sourceChanges
|
||||
},
|
||||
null,
|
||||
2
|
||||
)
|
||||
}}</pre>
|
||||
</NCollapseItem></NCollapse
|
||||
>
|
||||
<WorkspaceSectionHeading
|
||||
title="本次新参考与逐图观察"
|
||||
description="新参考仅是本次比较依据,不是原图的生成输入。门轴等固定结构看不清时选未知;开关门不等于固定结构改变。"
|
||||
/>
|
||||
<div class="grid items-start gap-(--app-content-gap) lg:grid-cols-2">
|
||||
<section
|
||||
v-for="(observation, index) in form.observations.value"
|
||||
:key="observation.imageNumber"
|
||||
class="min-w-0 space-y-3"
|
||||
>
|
||||
<h3 class="font-medium">比较参考 {{ observation.imageNumber }}</h3>
|
||||
<AssetImage
|
||||
class="max-w-sm aspect-square"
|
||||
:src="
|
||||
form.preview.value.references.find(r => r.imageNumber === observation.imageNumber)
|
||||
?.imageUrl
|
||||
"
|
||||
:alt="'本次比较参考 ' + observation.imageNumber"
|
||||
object-fit="contain"
|
||||
preview
|
||||
/>
|
||||
<p
|
||||
v-for="(binding, b) in form.preview.value.currentReferenceInput.references.find(
|
||||
r => r.imageNumber === observation.imageNumber
|
||||
)?.bindings"
|
||||
:key="b"
|
||||
class="wrap-anywhere text-sm"
|
||||
>
|
||||
{{ binding.subjectRef }} · {{ userFacingText(binding.role) }} {{ binding.viewDescription }}
|
||||
{{ binding.spatialLayoutVersion }}
|
||||
</p>
|
||||
<label
|
||||
v-for="(label, field) in sourceFindingLabels"
|
||||
:key="field"
|
||||
class="block space-y-1 text-sm"
|
||||
>
|
||||
<span>{{ label }}</span
|
||||
><NSelect
|
||||
v-model:value="observation.finding[field]"
|
||||
:options="findingOptions"
|
||||
:disabled="!!form.pending.value"
|
||||
:aria-label="'参考 ' + (index + 1) + ' ' + label"
|
||||
/>
|
||||
</label>
|
||||
<NInput
|
||||
v-model:value="observation.note"
|
||||
type="textarea"
|
||||
:maxlength="2000"
|
||||
:disabled="!!form.pending.value"
|
||||
placeholder="逐图填写可见事实;看不清的安装点明确记录未知"
|
||||
:input-props="{ 'aria-label': '参考 ' + (index + 1) + ' 观察说明' }"
|
||||
/>
|
||||
</section>
|
||||
</div>
|
||||
<NInput
|
||||
v-model:value="form.reviewer.value"
|
||||
:maxlength="120"
|
||||
:disabled="!!form.pending.value"
|
||||
placeholder="真实审核人"
|
||||
aria-label="来源审核人"
|
||||
/>
|
||||
<NInput
|
||||
v-model:value="form.reason.value"
|
||||
type="textarea"
|
||||
:maxlength="4000"
|
||||
:disabled="!!form.pending.value"
|
||||
placeholder="本次人工来源复核理由"
|
||||
aria-label="来源审核理由"
|
||||
/>
|
||||
</template>
|
||||
<!-- 以下是原观察与当前性,保存通过不变更机器或生产徽标 -->
|
||||
<section v-if="form.record.value" class="space-y-3">
|
||||
<WorkspaceSectionHeading
|
||||
title="人工来源记录"
|
||||
description="仍需独立质量及三镜连续性验收;人工通过不代表机器通过或生产准入。"
|
||||
/>
|
||||
<p>
|
||||
{{ statusLabels[form.record.value.reviewStatus] || '结论待核对' }} ·
|
||||
{{ form.record.value.current ? '来源当前' : '当前已失效' }}
|
||||
</p>
|
||||
<p v-if="!form.targetMatched.value" class="text-sm text-muted">
|
||||
原记录与当前主图比较计划不一致,仅可追溯,不能批准执行。
|
||||
</p>
|
||||
<p class="text-sm">
|
||||
原结论:{{
|
||||
statusLabels[form.record.value.originalResult.status] || form.record.value.originalResult.status
|
||||
}}
|
||||
</p>
|
||||
<p v-if="form.record.value.invalidation" class="text-sm text-muted">
|
||||
{{ userFacingText(form.record.value.invalidation) }}
|
||||
</p>
|
||||
<NCollapse
|
||||
><NCollapseItem title="原始人工观察" name="observations">
|
||||
<pre class="whitespace-pre-wrap wrap-anywhere text-xs">{{
|
||||
JSON.stringify(form.record.value.review, null, 2)
|
||||
}}</pre>
|
||||
</NCollapseItem></NCollapse
|
||||
>
|
||||
<NButton
|
||||
:loading="form.pending.value === 'plan'"
|
||||
:disabled="
|
||||
!!form.pending.value ||
|
||||
!form.targetMatched.value ||
|
||||
!form.record.value.current ||
|
||||
form.record.value.reviewStatus !== 'passed'
|
||||
"
|
||||
@click="form.loadPlan"
|
||||
>免费查看独立机器审核计划</NButton
|
||||
>
|
||||
</section>
|
||||
<!-- 以下是精确计划与真实人工费用批准,不虚构摘要或报价 -->
|
||||
<section v-if="form.plan.value" class="space-y-3">
|
||||
<WorkspaceSectionHeading
|
||||
title="独立新来源机器审核计划"
|
||||
description="逐项核对原主图、摘要、参考、模型及全部步骤;登记批准不会执行审核。"
|
||||
/>
|
||||
<p>
|
||||
模型:{{ form.plan.value.model }} · 步骤:{{
|
||||
form.plan.value.steps.map(step => validationStepNames[step]).join(' → ')
|
||||
}}
|
||||
· 最多请求 {{ form.plan.value.steps.length }} 次
|
||||
</p>
|
||||
<NCollapse
|
||||
><NCollapseItem title="完整计划及指纹" name="plan">
|
||||
<pre class="whitespace-pre-wrap wrap-anywhere text-xs">{{
|
||||
JSON.stringify(form.plan.value, null, 2)
|
||||
}}</pre>
|
||||
</NCollapseItem></NCollapse
|
||||
>
|
||||
<NInput
|
||||
v-model:value="form.approvedBy.value"
|
||||
:disabled="!!form.pending.value"
|
||||
placeholder="真实批准人"
|
||||
aria-label="费用批准人"
|
||||
/>
|
||||
<NInput
|
||||
v-model:value="form.operator.value"
|
||||
:disabled="!!form.pending.value"
|
||||
placeholder="真实操作人"
|
||||
aria-label="费用操作人"
|
||||
/>
|
||||
<NInput
|
||||
v-model:value="form.approvalSha256.value"
|
||||
:disabled="!!form.pending.value"
|
||||
placeholder="真实批准材料 SHA256(64 位)"
|
||||
aria-label="批准材料摘要"
|
||||
/>
|
||||
<label class="block text-sm"
|
||||
>批准估算下限(CNY)<NInputNumber
|
||||
v-model:value="form.estimatedMin.value"
|
||||
:disabled="!!form.pending.value"
|
||||
:min="0"
|
||||
placeholder="按真实批准填写"
|
||||
aria-label="批准费用下限"
|
||||
/></label>
|
||||
<label class="block text-sm"
|
||||
>批准估算上限(CNY)<NInputNumber
|
||||
v-model:value="form.estimatedMax.value"
|
||||
:disabled="!!form.pending.value"
|
||||
:min="0"
|
||||
placeholder="按真实批准填写"
|
||||
aria-label="批准费用上限"
|
||||
/></label>
|
||||
<NCheckbox v-model:checked="form.approved.value" :disabled="!!form.pending.value"
|
||||
>明确批准上述完整计划和费用范围</NCheckbox
|
||||
>
|
||||
<p v-if="form.authorizationId.value" class="wrap-anywhere text-sm">
|
||||
本次授权编号:{{ form.authorizationId.value }}
|
||||
</p>
|
||||
<NCheckbox
|
||||
v-if="form.authorizationId.value"
|
||||
v-model:checked="form.executeApproved.value"
|
||||
:disabled="!!form.pending.value"
|
||||
>明确执行本次独立审核,可能产生上述费用</NCheckbox
|
||||
>
|
||||
</section>
|
||||
<!-- 以下是既有项目作用域执行观察和服务端分页历史 -->
|
||||
<p v-if="form.vision.state.value.unknown || form.vision.uncertain.value" class="text-sm text-muted">
|
||||
结果或费用待核查,仅可只读刷新,不自动重发。
|
||||
</p>
|
||||
<KeyframeExecutionStatus
|
||||
v-if="
|
||||
form.vision.execution.data.value &&
|
||||
form.vision.history.data.value?.some(
|
||||
r => r.sourceReviewId && r.executionId === form.vision.execution.data.value?.id
|
||||
)
|
||||
"
|
||||
:execution="form.vision.execution.data.value"
|
||||
:loading="form.vision.execution.loading.value"
|
||||
@refresh="form.vision.execution.refresh"
|
||||
/>
|
||||
<section
|
||||
v-for="record in form.vision.history.data.value?.filter(r => r.sourceReviewId)"
|
||||
:key="record.id"
|
||||
class="space-y-2"
|
||||
>
|
||||
<p class="wrap-anywhere text-sm">
|
||||
独立新来源审核 · 人工记录 {{ record.sourceReviewId }} · 原任务 {{ record.id }} ·
|
||||
{{ userFacingText(record.status) }}
|
||||
</p>
|
||||
<KeyframeExecutionHistory
|
||||
:project-id="projectId"
|
||||
:shot-id="shotId"
|
||||
:keyframe-id="keyframeId"
|
||||
:validation-task-id="record.id"
|
||||
/>
|
||||
</section>
|
||||
<p v-if="resultLabel" class="text-sm" role="status">{{ resultLabel }}</p>
|
||||
<NCollapse v-if="form.result.value"
|
||||
><NCollapseItem title="本次完整回执(完成不等于通过)" name="receipt">
|
||||
<pre class="whitespace-pre-wrap wrap-anywhere text-xs">{{
|
||||
JSON.stringify(form.result.value, null, 2)
|
||||
}}</pre>
|
||||
</NCollapseItem></NCollapse
|
||||
>
|
||||
<NButton :loading="form.vision.history.loading.value" @click="form.vision.history.refresh"
|
||||
>只读刷新审核历史</NButton
|
||||
>
|
||||
</div>
|
||||
<template #footer>
|
||||
<NButton :disabled="busy" @click="open = false">关闭</NButton>
|
||||
<NButton
|
||||
v-if="form.preview.value"
|
||||
type="primary"
|
||||
:disabled="!!form.pending.value"
|
||||
:loading="form.pending.value === 'save'"
|
||||
@click="form.save"
|
||||
>保存人工观察(免费)</NButton
|
||||
>
|
||||
<NButton
|
||||
v-if="form.plan.value"
|
||||
type="primary"
|
||||
:disabled="!!form.pending.value || !form.approved.value"
|
||||
:loading="form.pending.value === 'authorize'"
|
||||
@click="form.authorize"
|
||||
>登记本次费用批准</NButton
|
||||
>
|
||||
<NButton
|
||||
v-if="form.authorizationId.value"
|
||||
type="primary"
|
||||
:disabled="
|
||||
!!form.pending.value ||
|
||||
!form.executeApproved.value ||
|
||||
!form.vision.history.data.value ||
|
||||
!!form.vision.history.error.value ||
|
||||
!!form.vision.state.value.active ||
|
||||
!!form.vision.state.value.unknown ||
|
||||
form.vision.uncertain.value
|
||||
"
|
||||
:loading="form.pending.value === 'execute'"
|
||||
@click="form.execute(false)"
|
||||
>明确执行独立审核</NButton
|
||||
>
|
||||
<NButton
|
||||
v-if="canResume && form.authorizationId.value"
|
||||
:disabled="!!form.pending.value || !form.executeApproved.value"
|
||||
@click="form.execute(true)"
|
||||
>明确继续原审核</NButton
|
||||
>
|
||||
</template>
|
||||
</AppDrawer>
|
||||
</template>
|
||||
@@ -366,3 +366,41 @@ export async function submitKeyframeVision(
|
||||
throw cause
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 新来源审核复用同候选的断线保护与执行观察,绝不调用普通 validate。
|
||||
* @param key 候选完整范围
|
||||
* @param records 正式历史
|
||||
* @param send 用户明确执行的请求
|
||||
* @returns 完整复用结果或后台受理回执
|
||||
*/
|
||||
export async function submitSourceVision(
|
||||
key: string,
|
||||
records: KeyframeValidationHistoryItem[],
|
||||
send: () => Promise<
|
||||
import('./quality.types').KeyframeValidation | import('./quality.types').KeyframeValidationAccepted
|
||||
>
|
||||
) {
|
||||
const previous = readSubmission(key)
|
||||
const state = visionState(records)
|
||||
if (state.active || state.unknown || (previous && !previous.settled))
|
||||
throw new Error('已有审核或费用待核查,请只读刷新历史。')
|
||||
const pending: Submission = { before: records[0]?.id ?? null }
|
||||
saveSubmission(key, pending)
|
||||
try {
|
||||
const result = await send()
|
||||
const [shotId, keyframeId] = JSON.parse(key) as string[]
|
||||
if (!result || result.shotId !== shotId || result.keyframeId !== keyframeId || !result.validationTaskId)
|
||||
throw new Error('审核回执不完整,请只读刷新历史。')
|
||||
if ('executionId' in result && result.status === 'pending' && result.executionId) {
|
||||
saveSubmission(key, { ...pending, taskId: result.validationTaskId, executionId: result.executionId })
|
||||
} else if ('passed' in result && isVisualValidation(result)) {
|
||||
saveSubmission(key, { ...pending, taskId: result.validationTaskId, settled: true })
|
||||
} else throw new Error('审核回执不完整,请核查原请求费用。')
|
||||
return result
|
||||
} catch (cause) {
|
||||
// 明确的参数或范围拒绝无自动重试;其余断线保持未结保护。
|
||||
if (cause instanceof ApiError && [400, 404, 409].includes(cause.status)) saveSubmission(key)
|
||||
throw cause
|
||||
}
|
||||
}
|
||||
@@ -274,6 +274,8 @@ export interface KeyframeValidationStep {
|
||||
|
||||
/** 已保存的只读首帧校验任务记录。 */
|
||||
export interface KeyframeValidationHistoryItem {
|
||||
/** 独立新来源人工记录,普通旧 Vision 保留独立。 */ sourceReviewId?: string
|
||||
/** 审核证据类型。 */ evidenceKind?: string
|
||||
/** 校验任务编号 */
|
||||
id: string
|
||||
/** 任务状态,保留后端原值 */
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
import { request } from '../../lib/http'
|
||||
import type { ProviderImageInputSnapshot } from '../subject-images/generation-preview'
|
||||
import type { KeyframeValidation, KeyframeValidationAccepted } from './quality.types'
|
||||
/** 人工观察结果,未知不可默认通过。 */
|
||||
export type SourceFinding = 'passed' | 'failed' | 'unknown'
|
||||
/** 五类独立观察。 */
|
||||
export const sourceFindingLabels = {
|
||||
identity: '身份',
|
||||
structure: '固定结构',
|
||||
spatial: '空间',
|
||||
action: '动作',
|
||||
continuity: '连续性'
|
||||
} as const
|
||||
/** 逐图人工观察。 */
|
||||
export interface SourceObservation {
|
||||
/** 物理参考编号。 */ imageNumber: number
|
||||
/** 全部观察项。 */ finding: Record<keyof typeof sourceFindingLabels, SourceFinding>
|
||||
/** 可见事实。 */ note: string
|
||||
}
|
||||
/** 人工保存输入。 */
|
||||
export interface SourceReviewInput {
|
||||
/** 预检指纹。 */ expectedFingerprint: string
|
||||
/** 审核人。 */ reviewer: string
|
||||
/** 理由。 */ reason: string
|
||||
/** 全部物理参考。 */ observations: SourceObservation[]
|
||||
}
|
||||
/** 公开输入,不将当前参考冒充原始输入。 */
|
||||
export type SourcePublicInput = ProviderImageInputSnapshot & {
|
||||
/** 服务。 */ provider: string
|
||||
/** 模型。 */ model: string | null
|
||||
/** 原完整描述。 */ providerPrompt: string
|
||||
}
|
||||
/**
|
||||
* 免费比较计划。
|
||||
* @param p 项目编号
|
||||
* @param s 镜头编号
|
||||
* @param k 原主图编号
|
||||
* @param signal 取消信号
|
||||
* @returns 正式接口回执
|
||||
*/
|
||||
export interface SourceReviewPreview {
|
||||
/** 项目。 */ projectId: string
|
||||
/** 镜头。 */ shotId: string
|
||||
/** 原主图。 */ keyframeId: string
|
||||
/** 原图。 */ imageUrl: string
|
||||
/** 预检指纹。 */ fingerprint: string
|
||||
/** 原件证据。 */ originalPixels: { /** 原件摘要。 */ sha256: string }
|
||||
/** 原输入指纹。 */ originalInputFingerprint: string
|
||||
/** 原始生成输入。 */ originalProviderInput: SourcePublicInput
|
||||
/** 来源变化。 */ sourceChanges: Record<string, unknown>
|
||||
/** 旧审核。 */ historicalVision: Array<{ /** 任务。 */ id: string; /** 状态。 */ status: string }>
|
||||
/** 当前参考原件。 */ references: Array<{
|
||||
/** 序号。 */ imageNumber: number
|
||||
/** 地址。 */ imageUrl: string
|
||||
/** 编号。 */ imageId: string
|
||||
}>
|
||||
/** 当前全部参考职责。 */ currentReferenceInput: SourcePublicInput
|
||||
}
|
||||
/** 原人工记录及当前性。 */
|
||||
export interface SourceReviewRecord {
|
||||
/** 记录。 */ reviewId: string
|
||||
/** 当前有效。 */ current: boolean
|
||||
/** 失效原因。 */ invalidation: string | null
|
||||
/** 原观察。 */ review: SourceReviewInput
|
||||
/** 原结论。 */ originalResult: { /** 状态。 */ status: string; /** 证据类型。 */ evidenceKind: string }
|
||||
/** 当前结论。 */ reviewStatus: string
|
||||
}
|
||||
/** 精确机器计划,原样批准。 */
|
||||
export interface SourceVisionPlan {
|
||||
/** 人工记录。 */ reviewId: string
|
||||
/** 观察指纹。 */ reviewFingerprint: string
|
||||
/** 原输入。 */ originalInputFingerprint: string
|
||||
/** 当前参考。 */ referenceInputFingerprint: string
|
||||
/** 来源。 */ sourceFingerprint: string
|
||||
/** 请求。 */ requestFingerprint: string
|
||||
/** 原件摘要。 */ imageSha256: string
|
||||
/** 模型。 */ model: string
|
||||
/** 路由。 */ routeFingerprint: string
|
||||
/** 全部步骤。 */ steps: Array<'general' | 'physical' | 'gaze'>
|
||||
}
|
||||
/** 明确批准的费用材料,不推测报价。 */
|
||||
export interface SourceVisionApproval {
|
||||
/** 原计划。 */ plan: SourceVisionPlan
|
||||
/** 批准人。 */ approvedBy: string
|
||||
/** 操作人。 */ operator: string
|
||||
/** 真实批准材料摘要。 */ approvalSha256: string
|
||||
/** 费用范围。 */ feeScope: {
|
||||
/** 币种。 */ currency: 'CNY'
|
||||
/** 最低估算。 */ estimatedMin: number
|
||||
/** 最高估算。 */ estimatedMax: number
|
||||
/** 请求数。 */ maxRequests: number
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 人工记录路径。
|
||||
* @param p 项目
|
||||
* @param r 记录
|
||||
* @returns 正式路径
|
||||
*/
|
||||
function recordPath(p: string, r: string) {
|
||||
return '/projects/' + encodeURIComponent(p) + '/storyboard-keyframes/source-reviews/' + encodeURIComponent(r)
|
||||
}
|
||||
/**
|
||||
* 原主图路径。
|
||||
* @param p 项目
|
||||
* @param s 镜头
|
||||
* @param k 原主图
|
||||
* @returns 正式路径
|
||||
*/
|
||||
function targetPath(p: string, s: string, k: string) {
|
||||
return (
|
||||
'/projects/' +
|
||||
encodeURIComponent(p) +
|
||||
'/storyboard-shots/' +
|
||||
encodeURIComponent(s) +
|
||||
'/keyframes/' +
|
||||
encodeURIComponent(k)
|
||||
)
|
||||
}
|
||||
/** 正式来源复核 API;所有写入只由用户操作调用。 */
|
||||
export const sourceReviewApi = {
|
||||
/**
|
||||
* 免费比较计划。
|
||||
* @param p 项目编号
|
||||
* @param s 镜头编号
|
||||
* @param k 原主图编号
|
||||
* @param signal 取消信号
|
||||
* @returns 正式接口回执
|
||||
*/
|
||||
preview: (p: string, s: string, k: string, signal?: AbortSignal) =>
|
||||
request<SourceReviewPreview>(targetPath(p, s, k) + '/source-review/preview', { signal, timeoutMs: 0 }),
|
||||
/**
|
||||
* 保存人工观察。
|
||||
* @param p 项目编号
|
||||
* @param s 镜头编号
|
||||
* @param k 原主图编号
|
||||
* @param body 本次全部人工观察
|
||||
* @returns 正式接口回执
|
||||
*/
|
||||
save: (p: string, s: string, k: string, body: SourceReviewInput) =>
|
||||
request<{ reviewId: string }>(targetPath(p, s, k) + '/source-reviews', { method: 'POST', body, timeoutMs: 0 }),
|
||||
/**
|
||||
* 回读原记录。
|
||||
* @param p 项目编号
|
||||
* @param r 人工记录编号
|
||||
* @param signal 取消信号
|
||||
* @returns 正式接口回执
|
||||
*/
|
||||
get: (p: string, r: string, signal?: AbortSignal) =>
|
||||
request<SourceReviewRecord>(recordPath(p, r), { signal, timeoutMs: 0 }),
|
||||
/**
|
||||
* 免费机器计划。
|
||||
* @param p 项目编号
|
||||
* @param r 人工记录编号
|
||||
* @param signal 取消信号
|
||||
* @returns 正式接口回执
|
||||
*/
|
||||
plan: (p: string, r: string, signal?: AbortSignal) =>
|
||||
request<SourceVisionPlan>(recordPath(p, r) + '/vision/preview', { signal, timeoutMs: 0 }),
|
||||
/**
|
||||
* 登记批准,不执行模型。
|
||||
* @param p 项目编号
|
||||
* @param r 人工记录编号
|
||||
* @param body 明确批准的完整计划及费用
|
||||
* @returns 正式接口回执
|
||||
*/
|
||||
authorize: (p: string, r: string, body: SourceVisionApproval) =>
|
||||
request<{ authorizationId: string; plan: SourceVisionPlan }>(recordPath(p, r) + '/vision/authorizations', {
|
||||
method: 'POST',
|
||||
body,
|
||||
timeoutMs: 0
|
||||
}),
|
||||
/**
|
||||
* 单次执行或显式继续。
|
||||
* @param p 项目编号
|
||||
* @param r 人工记录编号
|
||||
* @param body 本次授权及明确恢复证据
|
||||
* @returns 正式接口回执
|
||||
*/
|
||||
execute: (
|
||||
p: string,
|
||||
r: string,
|
||||
body: {
|
||||
authorizationId: string
|
||||
resume?: { resumeValidationTaskId: string; expectedRequestFingerprint: string }
|
||||
}
|
||||
) =>
|
||||
request<KeyframeValidation | KeyframeValidationAccepted>(recordPath(p, r) + '/vision', {
|
||||
method: 'POST',
|
||||
body,
|
||||
timeoutMs: 0
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,363 @@
|
||||
import { computed, ref, shallowRef, watch, onScopeDispose, type Ref } from 'vue'
|
||||
import {
|
||||
sourceReviewApi,
|
||||
type SourceReviewPreview,
|
||||
type SourceReviewRecord,
|
||||
type SourceVisionPlan,
|
||||
type SourceObservation,
|
||||
type SourceVisionApproval
|
||||
} from './source-review'
|
||||
import { useKeyframeVision, submitSourceVision } from './keyframe-vision'
|
||||
import { useActionMessage, showActionFeedback } from '../../components/ui/useActionMessage'
|
||||
import { errorMessage } from '../../lib/http'
|
||||
import { runOperation, getOperation } from '../workflows/operations'
|
||||
|
||||
/**
|
||||
* 原 Primary 的独立来源观察及明确批准闭环。
|
||||
* @param key 打开时的完整候选身份
|
||||
* @returns 只读证据、人工输入和显式操作
|
||||
*/
|
||||
export function useSourceReview(key: Ref<string>) {
|
||||
/** 正式候选观察复用已有 SSE/GET。 */
|
||||
const vision = useKeyframeVision(key)
|
||||
/** 免费比较输入。 */
|
||||
const preview = shallowRef<SourceReviewPreview | null>(null)
|
||||
/** 原人工记录。 */
|
||||
const record = shallowRef<SourceReviewRecord | null>(null)
|
||||
/** 原记录确实属于当前主图和本次输入。 */
|
||||
const targetMatched = ref(false)
|
||||
/** 免费机器计划。 */
|
||||
const plan = shallowRef<SourceVisionPlan | null>(null)
|
||||
/** 用户指定历史记录,不通过缓存推断。 */
|
||||
const reviewId = ref('')
|
||||
/** 真实审核人。 */
|
||||
const reviewer = ref('')
|
||||
/** 审核理由。 */
|
||||
const reason = ref('')
|
||||
/** 逐图默认未知。 */
|
||||
const observations = ref<SourceObservation[]>([])
|
||||
/** 正式授权只在本次页面内保留。 */
|
||||
const authorizationId = ref('')
|
||||
/** 批准人。 */
|
||||
const approvedBy = ref('')
|
||||
/** 操作人。 */
|
||||
const operator = ref('')
|
||||
/** 用户提供的真实批准材料 SHA。 */
|
||||
const approvalSha256 = ref('')
|
||||
/** 真实批准金额下限,打开不预填。 */
|
||||
const estimatedMin = ref<number | null>(null)
|
||||
/** 真实批准金额上限。 */
|
||||
const estimatedMax = ref<number | null>(null)
|
||||
/** 明确批准整份计划和费用。 */
|
||||
const approved = ref(false)
|
||||
/** 每次执行另行勾选,不因签发自动执行。 */
|
||||
const executeApproved = ref(false)
|
||||
/** 当前操作,不让并发点击创建多份任务。 */
|
||||
const pending = ref('')
|
||||
/** 最近完整结果,仅供展示,不改机器徽标。 */
|
||||
const result = shallowRef<unknown>(null)
|
||||
/** 当前费用材料身份。 */
|
||||
const approvalKey = computed(() =>
|
||||
JSON.stringify([
|
||||
plan.value,
|
||||
approvedBy.value,
|
||||
operator.value,
|
||||
approvalSha256.value,
|
||||
estimatedMin.value,
|
||||
estimatedMax.value
|
||||
])
|
||||
)
|
||||
/** 反馈使用现有消息层。 */
|
||||
const message = useActionMessage()
|
||||
/** 请求代次与取消器。 */
|
||||
let epoch = 0
|
||||
let controller: AbortController | undefined
|
||||
/** 关闭和切换忽略旧结果。 */
|
||||
function reset() {
|
||||
epoch++
|
||||
controller?.abort()
|
||||
preview.value = null
|
||||
record.value = null
|
||||
targetMatched.value = false
|
||||
plan.value = null
|
||||
reviewId.value = ''
|
||||
reviewer.value = ''
|
||||
reason.value = ''
|
||||
observations.value = []
|
||||
authorizationId.value = ''
|
||||
approved.value = false
|
||||
executeApproved.value = false
|
||||
pending.value = ''
|
||||
result.value = null
|
||||
approvedBy.value = ''
|
||||
operator.value = ''
|
||||
approvalSha256.value = ''
|
||||
estimatedMin.value = null
|
||||
estimatedMax.value = null
|
||||
}
|
||||
watch(key, reset, { flush: 'sync' })
|
||||
watch(
|
||||
approvalKey,
|
||||
() => {
|
||||
authorizationId.value = ''
|
||||
approved.value = false
|
||||
executeApproved.value = false
|
||||
},
|
||||
{ flush: 'sync' }
|
||||
)
|
||||
watch(
|
||||
reviewId,
|
||||
() => {
|
||||
targetMatched.value = false
|
||||
record.value = null
|
||||
plan.value = null
|
||||
authorizationId.value = ''
|
||||
result.value = null
|
||||
},
|
||||
{ flush: 'sync' }
|
||||
)
|
||||
onScopeDispose(reset)
|
||||
/**
|
||||
* 同一范围操作和反馈,不自动重试。
|
||||
* @param name 操作名
|
||||
* @param work 实际操作
|
||||
* @returns 操作结束
|
||||
*/
|
||||
async function run(
|
||||
name: string,
|
||||
work: (scope: string[], signal: AbortSignal, valid: () => boolean) => Promise<void>
|
||||
) {
|
||||
if (pending.value || !key.value) return
|
||||
const target = key.value,
|
||||
cycle = epoch,
|
||||
rid = reviewId.value
|
||||
controller?.abort()
|
||||
controller = new AbortController()
|
||||
pending.value = name
|
||||
const valid = () => target === key.value && cycle === epoch && (name === 'preview' || rid === reviewId.value)
|
||||
try {
|
||||
await work(JSON.parse(target) as string[], controller.signal, valid)
|
||||
} catch (cause) {
|
||||
if (valid()) showActionFeedback(message, errorMessage(cause), 'error')
|
||||
} finally {
|
||||
if (target === key.value && cycle === epoch) pending.value = ''
|
||||
}
|
||||
}
|
||||
/** 免费预检;只有用户操作才编译参考。 */
|
||||
async function loadPreview() {
|
||||
await run('preview', async ([s, k, p], signal, valid) => {
|
||||
preview.value = null
|
||||
plan.value = null
|
||||
record.value = null
|
||||
targetMatched.value = false
|
||||
authorizationId.value = ''
|
||||
const data = await sourceReviewApi.preview(p!, s!, k!, signal)
|
||||
if (!valid()) return
|
||||
if (data.projectId !== p || data.shotId !== s || data.keyframeId !== k)
|
||||
throw new Error('比较计划不属于当前首帧。')
|
||||
reviewId.value = ''
|
||||
preview.value = data
|
||||
record.value = null
|
||||
plan.value = null
|
||||
observations.value = data.currentReferenceInput.references.map(reference => ({
|
||||
imageNumber: reference.imageNumber,
|
||||
finding: {
|
||||
identity: 'unknown',
|
||||
structure: 'unknown',
|
||||
spatial: 'unknown',
|
||||
action: 'unknown',
|
||||
continuity: 'unknown'
|
||||
},
|
||||
note: ''
|
||||
}))
|
||||
})
|
||||
}
|
||||
/** 免费回读原人工记录;原结论保持不变。 */
|
||||
async function readRecord() {
|
||||
await run('read', async ([, , p], signal, valid) => {
|
||||
const data = await sourceReviewApi.get(p!, reviewId.value.trim(), signal)
|
||||
if (!valid()) return
|
||||
const [s, k] = JSON.parse(key.value) as string[]
|
||||
record.value = data
|
||||
preview.value = null
|
||||
observations.value = []
|
||||
targetMatched.value = false
|
||||
const comparison = await sourceReviewApi.preview(p!, s!, k!, signal)
|
||||
if (valid()) {
|
||||
record.value = data
|
||||
preview.value = comparison
|
||||
observations.value = comparison.currentReferenceInput.references.map(reference => ({
|
||||
imageNumber: reference.imageNumber,
|
||||
finding: {
|
||||
identity: 'unknown',
|
||||
structure: 'unknown',
|
||||
spatial: 'unknown',
|
||||
action: 'unknown',
|
||||
continuity: 'unknown'
|
||||
},
|
||||
note: ''
|
||||
}))
|
||||
targetMatched.value =
|
||||
comparison.projectId === p &&
|
||||
comparison.shotId === s &&
|
||||
comparison.keyframeId === k &&
|
||||
comparison.fingerprint === data.review.expectedFingerprint
|
||||
plan.value = null
|
||||
authorizationId.value = ''
|
||||
}
|
||||
})
|
||||
}
|
||||
/** 保存全部人工观察,既有生产徽标不会据此变更。 */
|
||||
async function save() {
|
||||
if (
|
||||
!preview.value ||
|
||||
!observations.value.length ||
|
||||
!reviewer.value.trim() ||
|
||||
!reason.value.trim() ||
|
||||
observations.value.some(o => !o.note.trim())
|
||||
) {
|
||||
showActionFeedback(message, '请填写审核人、理由及每张参考的观察说明。', 'error')
|
||||
return
|
||||
}
|
||||
await run('save', async ([s, k, p], _, valid) => {
|
||||
const savedEpoch = epoch
|
||||
const data = await sourceReviewApi.save(p!, s!, k!, {
|
||||
expectedFingerprint: preview.value!.fingerprint,
|
||||
reviewer: reviewer.value.trim(),
|
||||
reason: reason.value.trim(),
|
||||
observations: structuredClone(observations.value.map(o => ({ ...o, finding: { ...o.finding } })))
|
||||
})
|
||||
if (valid()) {
|
||||
reviewId.value = data.reviewId
|
||||
const next = await sourceReviewApi.get(p!, data.reviewId)
|
||||
if (
|
||||
savedEpoch === epoch &&
|
||||
key.value === JSON.stringify([s, k, p]) &&
|
||||
reviewId.value === data.reviewId &&
|
||||
!controller?.signal.aborted
|
||||
) {
|
||||
record.value = next
|
||||
targetMatched.value = true
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
/** 仅有效且全部通过的原观察才请求免费机器计划。 */
|
||||
async function loadPlan() {
|
||||
if (!targetMatched.value || !record.value?.current || record.value.reviewStatus !== 'passed') return
|
||||
await run('plan', async ([, , p], signal, valid) => {
|
||||
plan.value = null
|
||||
authorizationId.value = ''
|
||||
const data = await sourceReviewApi.plan(p!, reviewId.value, signal)
|
||||
if (valid()) {
|
||||
if (data.reviewId !== reviewId.value) throw new Error('计划归属不符。')
|
||||
plan.value = data
|
||||
}
|
||||
})
|
||||
}
|
||||
/** 明确登记批准,不自动执行。 */
|
||||
async function authorize() {
|
||||
if (
|
||||
!plan.value ||
|
||||
!approved.value ||
|
||||
!approvedBy.value.trim() ||
|
||||
!operator.value.trim() ||
|
||||
!/^[a-f0-9]{64}$/.test(approvalSha256.value) ||
|
||||
estimatedMin.value === null ||
|
||||
estimatedMax.value === null ||
|
||||
estimatedMin.value < 0 ||
|
||||
estimatedMax.value <= 0 ||
|
||||
estimatedMin.value > estimatedMax.value
|
||||
) {
|
||||
showActionFeedback(message, '请填写真实批准材料及有效费用范围,并批准本次完整计划。', 'error')
|
||||
return
|
||||
}
|
||||
const input: SourceVisionApproval = {
|
||||
plan: plan.value,
|
||||
approvedBy: approvedBy.value.trim(),
|
||||
operator: operator.value.trim(),
|
||||
approvalSha256: approvalSha256.value,
|
||||
feeScope: {
|
||||
currency: 'CNY',
|
||||
estimatedMin: estimatedMin.value,
|
||||
estimatedMax: estimatedMax.value,
|
||||
maxRequests: plan.value.steps.length
|
||||
}
|
||||
}
|
||||
await run('authorize', async ([, , p], _, valid) => {
|
||||
authorizationId.value = ''
|
||||
executeApproved.value = false
|
||||
const data = await sourceReviewApi.authorize(p!, reviewId.value, input)
|
||||
if (valid()) {
|
||||
if (JSON.stringify(data.plan) !== JSON.stringify(input.plan))
|
||||
throw new Error('批准范围已变化,请重新预检。')
|
||||
authorizationId.value = data.authorizationId
|
||||
executeApproved.value = false
|
||||
}
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 用户单独执行,继续仅来自原任务证据;费用未知禁止恢复。
|
||||
* @param resume 是否显式继续原任务
|
||||
*/
|
||||
async function execute(resume = false) {
|
||||
if (
|
||||
!vision.history.data.value ||
|
||||
!!vision.history.error.value ||
|
||||
!authorizationId.value ||
|
||||
!executeApproved.value ||
|
||||
!plan.value ||
|
||||
!record.value?.current ||
|
||||
vision.state.value.active ||
|
||||
vision.state.value.unknown ||
|
||||
vision.uncertain.value
|
||||
)
|
||||
return
|
||||
const original = vision.resume.value
|
||||
const task = vision.history.data.value?.find(t => t.id === original?.resumeValidationTaskId)
|
||||
if (resume && (!original || task?.sourceReviewId !== reviewId.value)) return
|
||||
const rid = reviewId.value,
|
||||
id = authorizationId.value,
|
||||
target = key.value
|
||||
executeApproved.value = false
|
||||
await run('execute', async ([, , p], _, valid) => {
|
||||
const ok = await runOperation(p!, '独立新来源机器审核', async () => {
|
||||
const data = await submitSourceVision(target, vision.history.data.value ?? [], () =>
|
||||
sourceReviewApi.execute(p!, rid, { authorizationId: id, ...(resume ? { resume: original! } : {}) })
|
||||
)
|
||||
if (valid()) result.value = data
|
||||
})
|
||||
if (valid()) {
|
||||
if (!ok) showActionFeedback(message, getOperation(p!).error, 'error')
|
||||
void vision.history.refresh()
|
||||
}
|
||||
})
|
||||
}
|
||||
return {
|
||||
targetMatched,
|
||||
vision,
|
||||
preview,
|
||||
record,
|
||||
plan,
|
||||
reviewId,
|
||||
reviewer,
|
||||
reason,
|
||||
observations,
|
||||
authorizationId,
|
||||
approvedBy,
|
||||
operator,
|
||||
approvalSha256,
|
||||
estimatedMin,
|
||||
estimatedMax,
|
||||
approved,
|
||||
executeApproved,
|
||||
pending,
|
||||
result,
|
||||
loadPreview,
|
||||
readRecord,
|
||||
save,
|
||||
loadPlan,
|
||||
authorize,
|
||||
execute
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,276 @@
|
||||
import { effectScope, ref } from 'vue'
|
||||
import { flushPromises } from '@vue/test-utils'
|
||||
import { afterEach, expect, it, vi } from 'vitest'
|
||||
import { useSourceReview } from '@/features/production/useSourceReview'
|
||||
import { sourceReviewApi, type SourceReviewPreview, type SourceVisionPlan } from '@/features/production/source-review'
|
||||
/** 全部请求仅使用隔离数据,不连接 Provider。 */
|
||||
const hash = 'a'.repeat(64)
|
||||
/** 原输入和当前参考完整公开证据。 */
|
||||
const input = {
|
||||
fingerprint: hash,
|
||||
sourceFingerprint: hash,
|
||||
provider: 'mock',
|
||||
model: 'mock',
|
||||
providerPrompt: '历史描述',
|
||||
generationOptions: {},
|
||||
references: [
|
||||
{
|
||||
imageNumber: 1,
|
||||
bindings: [
|
||||
{ role: 'layout-master', subjectRef: '@SC1' },
|
||||
{ role: 'scene-form', subjectRef: '@SC2' }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
/** 可复用隔离预检。 */
|
||||
export const sourcePreview: SourceReviewPreview = {
|
||||
projectId: 'p',
|
||||
shotId: 's',
|
||||
keyframeId: 'k',
|
||||
imageUrl: '',
|
||||
fingerprint: hash,
|
||||
originalPixels: { sha256: hash },
|
||||
originalInputFingerprint: hash,
|
||||
originalProviderInput: input,
|
||||
sourceChanges: {},
|
||||
historicalVision: [],
|
||||
references: [{ imageNumber: 1, imageId: 'i', imageUrl: '' }],
|
||||
currentReferenceInput: input
|
||||
}
|
||||
/** 精确机器计划。 */
|
||||
export const sourcePlan: SourceVisionPlan = {
|
||||
reviewId: 'r',
|
||||
reviewFingerprint: hash,
|
||||
originalInputFingerprint: hash,
|
||||
referenceInputFingerprint: hash,
|
||||
sourceFingerprint: hash,
|
||||
requestFingerprint: hash,
|
||||
imageSha256: hash,
|
||||
model: 'mock',
|
||||
routeFingerprint: hash,
|
||||
steps: ['general', 'physical']
|
||||
}
|
||||
/** 每次隔离作用域。 */
|
||||
let scope = effectScope()
|
||||
afterEach(() => {
|
||||
scope.stop()
|
||||
scope = effectScope()
|
||||
sessionStorage.clear()
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
/**
|
||||
* 创建只处理正式路径的 Mock。
|
||||
* @param status 人工原状态
|
||||
* @returns 请求记录
|
||||
*/
|
||||
export function sourceMock(status = 'passed') {
|
||||
const calls: Array<{ url: string; body: Record<string, unknown> | null }> = []
|
||||
const record = {
|
||||
reviewId: 'r',
|
||||
current: true,
|
||||
invalidation: null,
|
||||
review: {
|
||||
expectedFingerprint: hash,
|
||||
reviewer: '审核人',
|
||||
reason: '理由',
|
||||
observations: [
|
||||
{
|
||||
imageNumber: 1,
|
||||
finding: {
|
||||
identity: 'passed',
|
||||
structure: 'passed',
|
||||
spatial: 'passed',
|
||||
action: 'passed',
|
||||
continuity: 'passed'
|
||||
},
|
||||
note: '可见'
|
||||
}
|
||||
]
|
||||
},
|
||||
originalResult: { status, evidenceKind: 'manual-source-observation' },
|
||||
reviewStatus: status === 'insufficient_evidence' ? 'needs_review' : status
|
||||
}
|
||||
const fetcher = vi.fn<typeof fetch>(async (url, init) => {
|
||||
const path = String(url)
|
||||
const body = init?.body ? JSON.parse(String(init.body)) : null
|
||||
calls.push({ url: path, body })
|
||||
let data: unknown
|
||||
if (path.includes('/source-review/preview')) data = sourcePreview
|
||||
else if (path.endsWith('/source-reviews')) data = { reviewId: 'r' }
|
||||
else if (path.endsWith('/vision/preview')) data = sourcePlan
|
||||
else if (path.endsWith('/vision/authorizations')) data = { authorizationId: 'auth', plan: sourcePlan }
|
||||
else if (path.endsWith('/source-reviews/r')) data = record
|
||||
else if (path.includes('/validations')) data = []
|
||||
else return new Response(JSON.stringify({ error: { message: '未模拟请求' } }), { status: 404 })
|
||||
return new Response(JSON.stringify({ data }))
|
||||
})
|
||||
return { calls, fetcher, record }
|
||||
}
|
||||
/** 默认未知且逐图保存,人工通过不自动批准或执行。 */
|
||||
it('默认未知,逐图包含全部职责;原人工状态不覆盖', async () => {
|
||||
const mock = sourceMock('insufficient_evidence')
|
||||
vi.stubGlobal('fetch', mock.fetcher)
|
||||
const form = scope.run(() => useSourceReview(ref(JSON.stringify(['s', 'k', 'p']))))!
|
||||
await flushPromises()
|
||||
await form.loadPreview()
|
||||
expect(Object.values(form.observations.value[0]!.finding)).toEqual(Array(5).fill('unknown'))
|
||||
expect(form.preview.value?.currentReferenceInput.references[0]?.bindings).toHaveLength(2)
|
||||
form.reviewer.value = '审核人'
|
||||
form.reason.value = '理由'
|
||||
form.observations.value[0]!.note = '门轴看不清'
|
||||
await form.save()
|
||||
expect(form.record.value?.reviewStatus).toBe('needs_review')
|
||||
expect(form.record.value?.originalResult.status).toBe('insufficient_evidence')
|
||||
await form.loadPlan()
|
||||
expect(mock.calls.filter(c => c.url.endsWith('/vision/preview'))).toHaveLength(0)
|
||||
expect(mock.calls.filter(c => c.url.endsWith('/vision') || c.url.endsWith('/authorizations'))).toHaveLength(0)
|
||||
})
|
||||
/** 批准与执行分步;变更费用撤销原授权。 */
|
||||
it('真实费用材料独立批准,变更范围撤销授权,不自动收费', async () => {
|
||||
const mock = sourceMock()
|
||||
vi.stubGlobal('fetch', mock.fetcher)
|
||||
const form = scope.run(() => useSourceReview(ref(JSON.stringify(['s', 'k', 'p']))))!
|
||||
await flushPromises()
|
||||
form.reviewId.value = 'r'
|
||||
await form.readRecord()
|
||||
await form.loadPlan()
|
||||
form.approvedBy.value = '批准人'
|
||||
form.operator.value = '操作人'
|
||||
form.approvalSha256.value = hash
|
||||
form.estimatedMin.value = 1
|
||||
form.estimatedMax.value = 2
|
||||
form.approved.value = true
|
||||
await form.authorize()
|
||||
expect(form.authorizationId.value).toBe('auth')
|
||||
const body = mock.calls.find(c => c.url.endsWith('/authorizations'))!.body!
|
||||
expect(body.feeScope).toEqual({ currency: 'CNY', estimatedMin: 1, estimatedMax: 2, maxRequests: 2 })
|
||||
expect(mock.calls.some(c => c.url.endsWith('/vision'))).toBe(false)
|
||||
form.estimatedMax.value = 3
|
||||
expect(form.authorizationId.value).toBe('')
|
||||
})
|
||||
/** 项目切换后不接收旧预检。 */
|
||||
it('旧项目迟到响应被忽略', async () => {
|
||||
const mock = sourceMock()
|
||||
let finish!: (value: Response) => void
|
||||
vi.stubGlobal(
|
||||
'fetch',
|
||||
vi.fn<typeof fetch>((url, init) =>
|
||||
String(url).includes('/source-review/preview')
|
||||
? new Promise(resolve => {
|
||||
finish = resolve
|
||||
})
|
||||
: mock.fetcher(url, init)
|
||||
)
|
||||
)
|
||||
const key = ref(JSON.stringify(['s', 'k', 'p']))
|
||||
const form = scope.run(() => useSourceReview(key))!
|
||||
await flushPromises()
|
||||
const pending = form.loadPreview()
|
||||
key.value = JSON.stringify(['s2', 'k2', 'p2'])
|
||||
finish(new Response(JSON.stringify({ data: sourcePreview })))
|
||||
await pending
|
||||
expect(form.preview.value).toBeNull()
|
||||
})
|
||||
/** 执行请求仅携带本次授权和明确原任务指纹。 */
|
||||
it('执行和恢复使用正式路径,不能混入模型或文字参数', async () => {
|
||||
const fetcher = vi.fn<typeof fetch>(async () => new Response(JSON.stringify({ data: {} })))
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
await sourceReviewApi.execute('p/a', 'r/b', {
|
||||
authorizationId: 'auth',
|
||||
resume: { resumeValidationTaskId: 'task', expectedRequestFingerprint: hash }
|
||||
})
|
||||
expect(String(fetcher.mock.calls[0]![0])).toBe(
|
||||
'/api/projects/p%2Fa/storyboard-keyframes/source-reviews/r%2Fb/vision'
|
||||
)
|
||||
expect(JSON.parse(String(fetcher.mock.calls[0]![1]?.body))).toEqual({
|
||||
authorizationId: 'auth',
|
||||
resume: { resumeValidationTaskId: 'task', expectedRequestFingerprint: hash }
|
||||
})
|
||||
})
|
||||
|
||||
/** 并发点击仅一次送出,断线费用未知不重发。 */
|
||||
it('并发和未知费用保持同一候选提交保护', async () => {
|
||||
const { submitSourceVision } = await import('@/features/production/keyframe-vision')
|
||||
const key = JSON.stringify(['source-s', 'source-k', 'source-p'])
|
||||
let fail!: (cause: Error) => void
|
||||
const send = vi.fn<() => Promise<never>>(
|
||||
() =>
|
||||
new Promise((_, reject) => {
|
||||
fail = reject
|
||||
})
|
||||
)
|
||||
const first = submitSourceVision(key, [], send)
|
||||
await expect(submitSourceVision(key, [], send)).rejects.toThrow('费用待核查')
|
||||
fail(new Error('断线'))
|
||||
await expect(first).rejects.toThrow('断线')
|
||||
await expect(submitSourceVision(key, [], send)).rejects.toThrow('费用待核查')
|
||||
expect(send).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
/** 别的主图记录只能追溯,不可签发计划。 */
|
||||
it('记录与主图指纹不同不会取得机器计划', async () => {
|
||||
const mock = sourceMock()
|
||||
mock.record.review.expectedFingerprint = 'b'.repeat(64)
|
||||
vi.stubGlobal('fetch', mock.fetcher)
|
||||
const form = scope.run(() => useSourceReview(ref(JSON.stringify(['s', 'k', 'p']))))!
|
||||
await flushPromises()
|
||||
form.reviewId.value = 'r'
|
||||
await form.readRecord()
|
||||
await form.loadPlan()
|
||||
expect(form.record.value?.originalResult.status).toBe('passed')
|
||||
expect(form.targetMatched.value).toBe(false)
|
||||
expect(form.plan.value).toBeNull()
|
||||
expect(mock.calls.some(c => c.url.endsWith('/vision/preview'))).toBe(false)
|
||||
})
|
||||
|
||||
/** 完成的失败结论也是完整结果,返回后不自动再提交。 */
|
||||
it('200 失败结论保持原失败且结算提交观察', async () => {
|
||||
const { submitSourceVision } = await import('@/features/production/keyframe-vision')
|
||||
const failed = {
|
||||
shotId: 's',
|
||||
keyframeId: 'k',
|
||||
validationTaskId: 'task',
|
||||
imageUrl: '',
|
||||
isPrimary: true,
|
||||
passed: false,
|
||||
summary: '结构未通过',
|
||||
subjectCountConsistent: true,
|
||||
subjects: [],
|
||||
issues: [],
|
||||
unauthorizedText: { detected: false, texts: [] },
|
||||
qualityDecision: 'failed' as const
|
||||
}
|
||||
const send = vi.fn<() => Promise<typeof failed>>(async () => failed)
|
||||
const result = await submitSourceVision(JSON.stringify(['s', 'k', 'p']), [], send)
|
||||
expect(result).toEqual(failed)
|
||||
expect(result).toHaveProperty('passed', false)
|
||||
expect(send).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
/** 实际组件不自动预检、批准或执行,观察控件初始未知。 */
|
||||
it('抽屉使用真实表单,打开只读历史,免费预检逐项展示全部参考', async () => {
|
||||
const { mount } = await import('@vue/test-utils')
|
||||
const Drawer = (await import('@/features/production/components/SourceReviewDrawer.vue')).default
|
||||
const mock = sourceMock()
|
||||
vi.stubGlobal('fetch', mock.fetcher)
|
||||
const wrapper = mount(Drawer, {
|
||||
props: { open: true, projectId: 'p', shotId: 's', keyframeId: 'k' },
|
||||
global: { stubs: { AppDrawer: { template: '<div><slot/><slot name="footer"/></div>' }, AssetImage: true } }
|
||||
})
|
||||
try {
|
||||
await flushPromises()
|
||||
expect(mock.calls.every(c => c.body === null)).toBe(true)
|
||||
await wrapper
|
||||
.findAll('button')
|
||||
.find(b => b.text() === '免费预检当前来源')!
|
||||
.trigger('click')
|
||||
await flushPromises()
|
||||
expect(wrapper.text()).toContain('未知/无法看清')
|
||||
expect(wrapper.text()).toContain('本次新参考与逐图观察')
|
||||
expect(wrapper.text()).toContain('@SC1')
|
||||
expect(wrapper.text()).toContain('@SC2')
|
||||
expect(wrapper.text()).not.toContain('登记本次费用批准')
|
||||
} finally {
|
||||
wrapper.unmount()
|
||||
}
|
||||
})
|
||||
Reference in new issue
Block a user