feat(short-drama-agent-front): 接入审核人工确认与延期验证
This commit is contained in:
1 parent
5836b90934
commit
c6ef595a8e
23 files changed
+3923
-67
No files matched your search
@@ -0,0 +1,248 @@
|
||||
import type {
|
||||
DramaReviewIssue,
|
||||
DramaReviewPreview,
|
||||
DramaReviewSnapshot,
|
||||
DramaRewritePreview,
|
||||
ManualReviewDraft,
|
||||
DeferredUncertaintyDraft,
|
||||
ReviewResolutionSuggestion,
|
||||
ManualReviewDecision
|
||||
} from './types'
|
||||
|
||||
/**
|
||||
* 读取当前预检绑定保存记录中的裁决,兼容人工处理尚未生成新 Review 的情况。
|
||||
* @param review 保存记录中的原始审核字段
|
||||
* @param reviewId 本次预检对应的正式审核编号
|
||||
* @returns 结构完整且属于本次审核的裁决,字段缺失时回退正式审核记录
|
||||
*/
|
||||
export function savedReviewDecisions(review: unknown, reviewId: string): ManualReviewDecision[] | null {
|
||||
if (!review || typeof review !== 'object' || !('manualUncertaintyDecisions' in review)) return null
|
||||
const decisions = review.manualUncertaintyDecisions
|
||||
if (!Array.isArray(decisions)) return null
|
||||
return decisions.filter(
|
||||
(item): item is ManualReviewDecision =>
|
||||
!!item &&
|
||||
typeof item === 'object' &&
|
||||
item.reviewId === reviewId &&
|
||||
Number.isSafeInteger(item.originalIndex) &&
|
||||
typeof item.description === 'string' &&
|
||||
['accepted', 'deferred', 'verified'].includes(item.disposition) &&
|
||||
(item.episode === undefined || (Number.isSafeInteger(item.episode) && item.episode > 0)) &&
|
||||
(item.verificationTarget === undefined || ['breakdown', 'storyboard'].includes(item.verificationTarget)) &&
|
||||
(item.verificationCriteria === undefined || typeof item.verificationCriteria === 'string')
|
||||
)
|
||||
}
|
||||
|
||||
/** 原始审核中的问题位置,不能用排序后的页面位置替代。 */
|
||||
export interface IndexedReviewIssue {
|
||||
/** 原始待确认数组索引。 */ originalIndex: number
|
||||
/** 真实问题内容。 */ issue: DramaReviewIssue
|
||||
}
|
||||
|
||||
/** 原始审核中的不确定项位置。 */
|
||||
export interface IndexedReviewUncertainty {
|
||||
/** 原始不确定项数组索引。 */ originalIndex: number
|
||||
/** 原始文字。 */ text: string
|
||||
}
|
||||
|
||||
/** 质量维度只翻译展示名称,提交仍使用原始枚举。 */
|
||||
export const reviewCategoryOptions = [
|
||||
{ label: '动作衔接', value: 'action_continuity' },
|
||||
{ label: '手部占用', value: 'hand_occupancy' },
|
||||
{ label: '姿态', value: 'pose' },
|
||||
{ label: '视线', value: 'gaze' },
|
||||
{ label: '道具交互', value: 'prop_interaction' },
|
||||
{ label: '时长', value: 'duration' },
|
||||
{ label: '主体一致性', value: 'subject_consistency' },
|
||||
{ label: '空间衔接', value: 'spatial_continuity' }
|
||||
]
|
||||
|
||||
/**
|
||||
* 沿用服务端识别当前待处理问题的字段,不把同集不同问题合并。
|
||||
* @param left 原始问题
|
||||
* @param right 当前问题
|
||||
* @returns 是否为同一原始条目
|
||||
*/
|
||||
function sameIssue(left: DramaReviewIssue, right: DramaReviewIssue) {
|
||||
return left.episode === right.episode && left.code === right.code && left.sourceQuote === right.sourceQuote
|
||||
}
|
||||
|
||||
/**
|
||||
* 展示当前剩余问题,始终保留原数组索引。
|
||||
* @param preview 当前预检
|
||||
* @returns 可按剧集展示的原始条目
|
||||
*/
|
||||
export function indexedPendingIssues(preview: DramaReviewPreview | null): IndexedReviewIssue[] {
|
||||
if (!preview) return []
|
||||
return preview.pendingQualityIssues
|
||||
.map((issue, originalIndex) => ({ issue, originalIndex }))
|
||||
.filter(
|
||||
row =>
|
||||
!preview.remainingPendingQualityIssues ||
|
||||
preview.remainingPendingQualityIssues.some(issue => sameIssue(row.issue, issue))
|
||||
)
|
||||
.toSorted((left, right) => left.issue.episode - right.issue.episode || left.originalIndex - right.originalIndex)
|
||||
}
|
||||
|
||||
/**
|
||||
* 原始索引独立于页面过滤,并与后端的文字匹配规则保持一致。
|
||||
* @param preview 当前预检
|
||||
* @returns 尚未裁决的不确定项
|
||||
*/
|
||||
export function indexedUncertainties(preview: DramaReviewPreview | null): IndexedReviewUncertainty[] {
|
||||
if (!preview) return []
|
||||
return preview.uncertainty
|
||||
.map((text, originalIndex) => ({ text, originalIndex }))
|
||||
.filter(row => !preview.remainingUncertainty || preview.remainingUncertainty.includes(row.text))
|
||||
}
|
||||
|
||||
/**
|
||||
* 只比较用户已核对的服务端来源,任何变更都要求重新选择。
|
||||
* @param previous 用户已核对的版本
|
||||
* @param current 提交前重新读取的版本
|
||||
* @returns 审核、保存记录与正文是否完全相同
|
||||
*/
|
||||
export function sameReviewSource(previous: DramaReviewPreview, current: DramaReviewPreview): boolean {
|
||||
return (
|
||||
previous.projectId === current.projectId &&
|
||||
previous.reviewId === current.reviewId &&
|
||||
previous.checkpointId === current.checkpointId &&
|
||||
JSON.stringify(previous.episodes) === JSON.stringify(current.episodes) &&
|
||||
JSON.stringify(previous.pendingQualityIssues) === JSON.stringify(current.pendingQualityIssues) &&
|
||||
JSON.stringify(previous.uncertainty) === JSON.stringify(current.uncertainty) &&
|
||||
JSON.stringify(previous.remainingPendingQualityIssues) ===
|
||||
JSON.stringify(current.remainingPendingQualityIssues) &&
|
||||
JSON.stringify(previous.remainingUncertainty) === JSON.stringify(current.remainingUncertainty) &&
|
||||
JSON.stringify(previous.resolutionSuggestions) === JSON.stringify(current.resolutionSuggestions)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 改写范围或来源变化后撤销旧费用确认。
|
||||
* @param previous 已展示的改写预检
|
||||
* @param current 提交前的新预检
|
||||
* @returns 是否仍是用户核对的同一范围
|
||||
*/
|
||||
export function sameRewriteScope(previous: DramaRewritePreview, current: DramaRewritePreview): boolean {
|
||||
return (
|
||||
previous.projectId === current.projectId &&
|
||||
previous.checkpointId === current.checkpointId &&
|
||||
previous.rewriteCharacters === current.rewriteCharacters &&
|
||||
previous.rewriteWorld === current.rewriteWorld &&
|
||||
previous.rewriteEpisodes === current.rewriteEpisodes &&
|
||||
JSON.stringify(previous.episodeNumbers.toSorted((a, b) => a - b)) ===
|
||||
JSON.stringify(current.episodeNumbers.toSorted((a, b) => a - b))
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 只有正式预检明确允许,且当前剩余数据完整时,才开放人工确认。
|
||||
* @param snapshot 已读取的审核及预检
|
||||
* @returns 不可提交的可读原因,空字符串表示可继续核对
|
||||
*/
|
||||
export function reviewBlockReason(snapshot: DramaReviewSnapshot | null): string {
|
||||
if (!snapshot?.latest) return '当前尚无审核记录。'
|
||||
if (snapshot.latest.passed) return '当前审核已通过,无需再次确认。'
|
||||
if (snapshot.previewError) return snapshot.previewError
|
||||
const preview = snapshot.preview
|
||||
if (!preview) return '尚未取得问题处理预检,请重新读取。'
|
||||
if (preview.hasActiveExecution) return '剧本任务仍在运行,请结束后再处理审核问题。'
|
||||
if (!preview.sourceValid || !preview.reviewSourceValid || preview.reviewId !== snapshot.latest.id)
|
||||
return '审核与当前剧本来源不一致,请刷新并核对保存记录。'
|
||||
if (
|
||||
!preview.ready ||
|
||||
preview.readOnly !== true ||
|
||||
!Array.isArray(preview.remainingPendingQualityIssues) ||
|
||||
!Array.isArray(preview.remainingUncertainty)
|
||||
)
|
||||
return '当前预检尚不允许确认,请刷新后核对。'
|
||||
return ''
|
||||
}
|
||||
|
||||
/**
|
||||
* 表单提交前检查必填项与逐字引用;最终事实仍由服务端核验。
|
||||
* @param draft 人工补充的草稿
|
||||
* @param episodes 当前预检返回的正式正文
|
||||
* @returns 可读字段问题,空字符串表示表单完整
|
||||
*/
|
||||
export function manualIssueError(draft: ManualReviewDraft, episodes: DramaReviewPreview['episodes']): string {
|
||||
const episode = episodes.find(item => item.episode === draft.episode)
|
||||
if (!episode) return '请选择当前正式剧集。'
|
||||
if (![draft.code, draft.sourceQuote, draft.message, draft.suggestion].every(value => value.trim()))
|
||||
return '请填写问题名称、原文片段、问题说明和修改建议。'
|
||||
if (!episode.content.includes(draft.sourceQuote.trim())) return '引用片段必须逐字出现在所选剧集原文中。'
|
||||
if (draft.subjectRef.trim() && !episode.content.includes(draft.subjectRef.trim()))
|
||||
return '所选角色必须出现在引用所属的剧集原文中。'
|
||||
return ''
|
||||
}
|
||||
|
||||
/**
|
||||
* 无效模型结构或无法核实的证据不能通过接受不确定项绕过。
|
||||
* @param text 原始不确定项
|
||||
* @returns 是否允许请求人工接受
|
||||
*/
|
||||
export function uncertaintyAcceptable(text: string): boolean {
|
||||
return !/引用原文或主体无法核实|模型返回不符合审核结构/.test(text)
|
||||
}
|
||||
|
||||
/**
|
||||
* 建议位置可能来自剩余项列表;按完整原文对应,提交仍使用原始审核索引。
|
||||
* @param preview 当前预检
|
||||
* @param originalIndex 原始不确定项索引
|
||||
* @returns 唯一对应的建议,无法对应时为空
|
||||
*/
|
||||
export function suggestionForUncertainty(
|
||||
preview: DramaReviewPreview | null,
|
||||
originalIndex: number
|
||||
): ReviewResolutionSuggestion | null {
|
||||
const text = preview?.uncertainty[originalIndex]
|
||||
if (
|
||||
!preview ||
|
||||
typeof text !== 'string' ||
|
||||
(preview.remainingUncertainty && !preview.remainingUncertainty.includes(text))
|
||||
)
|
||||
return null
|
||||
const matches = preview.resolutionSuggestions?.filter(item => item.description === text) ?? []
|
||||
return matches.length === 1 ? matches[0]! : null
|
||||
}
|
||||
|
||||
/**
|
||||
* 只有用户主动选择延期时创建草稿;低置信度或要求选集的建议不绑定默认集号。
|
||||
* @param index 原始不确定项索引
|
||||
* @param suggestion 当前原文对应的建议
|
||||
* @param episodes 正式剧集列表
|
||||
* @returns 尚未确认的延期表单
|
||||
*/
|
||||
export function newDeferredDraft(
|
||||
index: number,
|
||||
suggestion: ReviewResolutionSuggestion | null,
|
||||
episodes: DramaReviewPreview['episodes']
|
||||
): DeferredUncertaintyDraft {
|
||||
const episode =
|
||||
suggestion?.confidence === 'high' &&
|
||||
!suggestion.requiresEpisodeSelection &&
|
||||
episodes.some(item => item.episode === suggestion.episode)
|
||||
? suggestion.episode
|
||||
: null
|
||||
return {
|
||||
index,
|
||||
episode,
|
||||
verificationTarget: suggestion?.verificationTarget ?? null,
|
||||
verificationCriteria: suggestion?.verificationCriteria ?? ''
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验用户编辑后的延期要求,不限制为候选集,也不把建议当作已确认。
|
||||
* @param draft 当前延期草稿
|
||||
* @param episodes 当前正式剧集
|
||||
* @returns 需要用户修正的字段问题
|
||||
*/
|
||||
export function deferredDraftError(draft: DeferredUncertaintyDraft, episodes: DramaReviewPreview['episodes']): string {
|
||||
if (!Number.isSafeInteger(draft.episode) || !episodes.some(item => item.episode === draft.episode))
|
||||
return '请明确选择负责核验的正式剧集。'
|
||||
if (!['breakdown', 'storyboard'].includes(draft.verificationTarget ?? '')) return '请选择核验阶段。'
|
||||
if (!draft.verificationCriteria.trim()) return '请填写核验标准。'
|
||||
if (draft.verificationCriteria.trim().length > 2000) return '核验标准不能超过 2000 个字符。'
|
||||
return ''
|
||||
}
|
||||
Reference in new issue
Block a user