feat(short-drama-agent-front): 接入空间母版恢复与修订
This commit is contained in:
1 parent
c808a58a3f
commit
7e149a10c0
18 files changed
+2732
-12
No files matched your search
Vendored
+349
@@ -0,0 +1,349 @@
|
||||
import type {
|
||||
MasterRecoveryImpact,
|
||||
MasterReview,
|
||||
SceneMaster,
|
||||
SpatialLayout,
|
||||
MasterJob
|
||||
} from '@/features/spatial-layouts/types'
|
||||
import type { GenerationModelCatalog, CreativeProfile } from '@/features/generation-config/types'
|
||||
|
||||
/** 隔离当前几何版本,不引用真实项目。 */
|
||||
export const masterVersion = 'a'.repeat(64)
|
||||
/** 正式布局的跨题材夹具。 */
|
||||
export const spatialLayoutFixture: SpatialLayout = {
|
||||
id: 'layout',
|
||||
projectId: 'p',
|
||||
name: '星港中枢共享空间',
|
||||
version: masterVersion,
|
||||
sceneSubjectIds: ['scene']
|
||||
}
|
||||
/**
|
||||
* 构造正式草稿/确认母版,图片仅为隔离地址。
|
||||
* @param patch 当前测试差异
|
||||
* @returns 母版资产
|
||||
*/
|
||||
export function sceneMasterFixture(patch: Partial<SceneMaster> = {}): SceneMaster {
|
||||
return {
|
||||
id: 'draft',
|
||||
projectId: 'p',
|
||||
spatialLayoutId: 'layout',
|
||||
spatialLayoutVersion: masterVersion,
|
||||
imageUrl: '/storage/mock-master.png',
|
||||
status: 'draft',
|
||||
subjectFormId: null,
|
||||
viewDescription: null,
|
||||
evidence: null,
|
||||
confirmedBy: null,
|
||||
confirmedAt: null,
|
||||
visionReviewedAt: null,
|
||||
createdAt: '2026-11-07T00:00:00Z',
|
||||
updatedAt: '2026-11-07T00:00:00Z',
|
||||
...patch
|
||||
}
|
||||
}
|
||||
/** 隔离项目已保存的模型配置。 */
|
||||
export const masterProfile: CreativeProfile = {
|
||||
projectId: 'p',
|
||||
aspectRatio: '1:1',
|
||||
imageProvider: 'mock',
|
||||
imageModel: 'mock-model',
|
||||
imageOptions: { size: '2048x2048' },
|
||||
videoProvider: 'mock-video',
|
||||
videoModel: 'mock-video',
|
||||
videoOptions: {}
|
||||
}
|
||||
/** 使用正式目录结构,仅暴露一个测试模型。 */
|
||||
export const masterCatalog: GenerationModelCatalog = {
|
||||
defaults: { imageProvider: 'mock', videoProvider: 'mock-video' },
|
||||
images: [
|
||||
{
|
||||
type: 'image',
|
||||
provider: 'mock',
|
||||
providerLabel: '隔离图片模型',
|
||||
model: 'mock-model',
|
||||
modelLabel: '测试模型',
|
||||
supported: true,
|
||||
enabled: true,
|
||||
isDefault: true,
|
||||
capabilities: {},
|
||||
generationOptions: [],
|
||||
defaults: { size: '2048x2048' },
|
||||
projectConstraints: []
|
||||
}
|
||||
],
|
||||
videos: []
|
||||
}
|
||||
/**
|
||||
* 独立人工与机器证据,确认不改变机器结论。
|
||||
* @param master 指定母版
|
||||
* @param visionPassed 本次正式机器证据
|
||||
* @returns 正式审核材料
|
||||
*/
|
||||
export function masterReviewFixture(master: SceneMaster, visionPassed = false): MasterReview {
|
||||
const current = master.spatialLayoutVersion === masterVersion
|
||||
return {
|
||||
masterId: master.id,
|
||||
imageUrl: master.imageUrl,
|
||||
layoutId: 'layout',
|
||||
layoutVersion: masterVersion,
|
||||
currentVersion: current,
|
||||
status: master.status,
|
||||
reviewStatus: master.status === 'confirmed' && current ? 'human_passed' : 'needs_review',
|
||||
automatedVisionPassed: visionPassed,
|
||||
automatedVisionReview: visionPassed ? { summary: '隔离机器审核通过' } : null,
|
||||
sceneSubjectIds: ['scene'],
|
||||
subjectFormId: null,
|
||||
viewDescription: null,
|
||||
checklist: [
|
||||
{
|
||||
index: 1,
|
||||
kind: 'structural-connection',
|
||||
subjectId: 'scene',
|
||||
referenceSubjectId: null,
|
||||
requirement: '观察面内固定连接位置正确',
|
||||
acceptance: '连接处可见',
|
||||
result: 'needs_review'
|
||||
}
|
||||
],
|
||||
canConfirm: current && master.status === 'draft',
|
||||
humanReviewEvidence:
|
||||
master.status === 'confirmed' && current
|
||||
? {
|
||||
summary: master.evidence || '人工证据',
|
||||
compositionReviews: [{ index: 1, result: 'passed', evidence: '连接可见' }]
|
||||
}
|
||||
: null,
|
||||
note: '人工与AI证据独立'
|
||||
}
|
||||
}
|
||||
/** 真实影响结构:原件有效但来源过期,不能认定损坏或自动重生。 */
|
||||
export const masterImpactFixture: MasterRecoveryImpact = {
|
||||
projectId: 'p',
|
||||
layoutId: 'layout',
|
||||
layoutVersion: masterVersion,
|
||||
currentMaster: null,
|
||||
summary: {
|
||||
affectedShots: 8,
|
||||
primaryShots: 1,
|
||||
shotsWithVision: 1,
|
||||
shotsWithoutAssets: 7,
|
||||
candidateCount: 1,
|
||||
primaryRevalidationShots: 1
|
||||
},
|
||||
generationAllowed: false,
|
||||
limitation: '不改变主图',
|
||||
assets: [
|
||||
{
|
||||
subjectId: 'scene',
|
||||
ref: '@SC001',
|
||||
name: '星港中枢',
|
||||
anchors: [{ id: 'anchor', imageUrl: '/storage/anchor.png', fileStatus: 'readable', action: 'revalidate' }],
|
||||
forms: [
|
||||
{
|
||||
id: 'form',
|
||||
name: '基础形态',
|
||||
primaryImages: [
|
||||
{
|
||||
id: 'form-image',
|
||||
imageUrl: '/storage/form.png',
|
||||
fileStatus: 'readable',
|
||||
currentness: { current: false, reason: '母版来源已变化' }
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
shots: [
|
||||
{
|
||||
shotId: 'shot',
|
||||
episodeNo: 1,
|
||||
beatNo: 1,
|
||||
shotNo: 1,
|
||||
title: '星港相遇',
|
||||
primaryCount: 1,
|
||||
visionTaskCount: 1,
|
||||
primary: null,
|
||||
candidates: [
|
||||
{
|
||||
id: 'primary',
|
||||
isPrimary: true,
|
||||
status: 'completed',
|
||||
imageUrl: '/storage/primary.png',
|
||||
width: 2048,
|
||||
height: 2048,
|
||||
imageIntegrity: 'matches_review',
|
||||
sourceStatus: 'layout_version_changed',
|
||||
sourceReason: '布局版本已变化',
|
||||
action: 'revalidate',
|
||||
providerInputFingerprint: 'f'.repeat(64),
|
||||
referenceEvidence: [],
|
||||
latestVision: {
|
||||
id: 'old-vision',
|
||||
status: 'completed',
|
||||
passed: true,
|
||||
qualityDecision: 'passed',
|
||||
evidenceComplete: true,
|
||||
historical: true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
/**
|
||||
* 所有正式路由均隔离模拟;未匹配请求返回 404,不连接真实服务。
|
||||
* @returns Mock 请求、调用记录及可调整状态
|
||||
*/
|
||||
export function createMasterMock() {
|
||||
const calls: Array<{ url: string; method: string; body: Record<string, unknown> }> = []
|
||||
const state = {
|
||||
masters: [
|
||||
sceneMasterFixture(),
|
||||
sceneMasterFixture({ id: 'old', status: 'confirmed', spatialLayoutVersion: 'b'.repeat(64) })
|
||||
],
|
||||
jobs: [] as MasterJob[],
|
||||
visionPassed: false,
|
||||
visionMasterId: '',
|
||||
generationConflict: false,
|
||||
afterPaidConflict: false,
|
||||
generationErrorStatus: 409 as 400 | 409
|
||||
}
|
||||
/**
|
||||
* 隔离正式路由,不调用 Provider。
|
||||
* @param input 请求地址
|
||||
* @param init HTTP 参数
|
||||
* @returns Mock 响应
|
||||
*/
|
||||
const fetcher: typeof fetch = async (input, init) => {
|
||||
const url = new URL(String(input), 'http://localhost')
|
||||
const path = url.pathname
|
||||
const method = init?.method || 'GET'
|
||||
const body = JSON.parse(String(init?.body || '{}')) as Record<string, unknown>
|
||||
calls.push({ url: String(input), method, body })
|
||||
let data: unknown
|
||||
if (path === '/api/generation-models') data = masterCatalog
|
||||
else if (path.endsWith('/creative-profile')) data = { ...masterProfile, projectId: path.split('/')[3] }
|
||||
else if (path.endsWith('/shared-spatial-layouts')) data = [spatialLayoutFixture]
|
||||
else if (path.endsWith('/generation-jobs')) data = state.jobs
|
||||
else if (path.endsWith('/recovery-impact'))
|
||||
data = {
|
||||
...masterImpactFixture,
|
||||
currentMaster:
|
||||
state.masters.find(
|
||||
item => item.status === 'confirmed' && item.spatialLayoutVersion === masterVersion
|
||||
) ?? null
|
||||
}
|
||||
else if (path.endsWith('/confirmed'))
|
||||
data =
|
||||
state.masters.find(
|
||||
item => item.status === 'confirmed' && item.spatialLayoutVersion === masterVersion
|
||||
) ?? null
|
||||
else if (path.endsWith('/generation-preflight'))
|
||||
data = {
|
||||
layoutId: 'layout',
|
||||
layoutVersion: body.expectedVersion,
|
||||
provider: body.providerName,
|
||||
model: 'mock-model',
|
||||
generationOptions: body.generationOptions,
|
||||
prompt: '本次仅修订活动方向,保留星港结构。',
|
||||
references: body.referenceMasterId
|
||||
? [
|
||||
{
|
||||
imageId: body.referenceMasterId,
|
||||
imageUrl: '/storage/mock-master.png',
|
||||
providerImageUrl: 'data:image/png;base64,AA==',
|
||||
providerInputResolved: true,
|
||||
role: 'layout-master',
|
||||
sourceLayoutVersion: state.masters.find(item => item.id === body.referenceMasterId)
|
||||
?.spatialLayoutVersion,
|
||||
sha256: 'd'.repeat(64),
|
||||
pixelFingerprint: 'e'.repeat(64),
|
||||
width: 800,
|
||||
height: 800,
|
||||
sourceMasterStatus: state.masters.find(item => item.id === body.referenceMasterId)?.status
|
||||
}
|
||||
]
|
||||
: [],
|
||||
referenceCount: body.referenceMasterId ? 1 : 0,
|
||||
verifiedSceneCount: 2,
|
||||
maxReferenceImages: 10,
|
||||
referenceMasterId: body.referenceMasterId ?? null,
|
||||
revisionInstruction: body.revisionInstruction ?? null,
|
||||
previewFingerprint: 'f'.repeat(64),
|
||||
generationAllowed: false,
|
||||
reason: '免费预检'
|
||||
}
|
||||
else if (path.endsWith('/generate')) {
|
||||
if (state.afterPaidConflict)
|
||||
state.jobs.push({
|
||||
id: 'interrupted-job',
|
||||
projectId: 'p',
|
||||
spatialLayoutId: 'layout',
|
||||
spatialLayoutVersion: masterVersion,
|
||||
status: 'interrupted',
|
||||
referenceSnapshot: [],
|
||||
provider: 'mock',
|
||||
model: 'mock-model',
|
||||
prompt: '已提交的原输入',
|
||||
generationOptions: {},
|
||||
imageUrl: null,
|
||||
errorMessage: '保存失败',
|
||||
createdAt: '2026-11-07',
|
||||
updatedAt: '2026-11-07'
|
||||
})
|
||||
if (state.generationConflict || state.afterPaidConflict)
|
||||
return new Response(JSON.stringify({ message: '空间布局版本已变化,请重新预检' }), {
|
||||
status: state.generationErrorStatus
|
||||
})
|
||||
state.masters.unshift(sceneMasterFixture({ id: 'generated' }))
|
||||
state.jobs.push({
|
||||
id: 'job',
|
||||
projectId: 'p',
|
||||
spatialLayoutId: 'layout',
|
||||
spatialLayoutVersion: masterVersion,
|
||||
status: 'completed',
|
||||
referenceSnapshot: [],
|
||||
provider: 'mock',
|
||||
model: 'mock-model',
|
||||
prompt: '本次仅修订活动方向,保留星港结构。',
|
||||
generationOptions: masterProfile.imageOptions,
|
||||
imageUrl: '/storage/mock-master.png',
|
||||
errorMessage: null,
|
||||
createdAt: '2026-11-07',
|
||||
updatedAt: '2026-11-07'
|
||||
})
|
||||
data = { jobId: 'job', masterId: 'generated', imageUrl: '/storage/mock-master.png', status: 'completed' }
|
||||
} else if (path.endsWith('/review'))
|
||||
data = masterReviewFixture(
|
||||
state.masters.find(item => item.id === path.split('/').at(-2))!,
|
||||
state.visionPassed && state.visionMasterId === path.split('/').at(-2)
|
||||
)
|
||||
else if (path.endsWith('/validate')) {
|
||||
state.visionPassed = true
|
||||
state.visionMasterId = path.split('/').at(-2)!
|
||||
data = {
|
||||
masterId: path.split('/').at(-2),
|
||||
layoutId: 'layout',
|
||||
layoutVersion: masterVersion,
|
||||
currentVersion: true,
|
||||
persisted: true,
|
||||
automatedVisionPassed: true,
|
||||
reviewStatus: 'passed',
|
||||
summary: '隔离视觉审核通过'
|
||||
}
|
||||
} else if (path.endsWith('/confirm')) {
|
||||
const master = state.masters.find(item => item.id === path.split('/').at(-2))!
|
||||
Object.assign(master, {
|
||||
status: 'confirmed',
|
||||
evidence: body.evidence,
|
||||
confirmedBy: body.confirmedBy,
|
||||
confirmedAt: '2026-11-07T01:00:00Z'
|
||||
})
|
||||
data = master
|
||||
} else if (path.endsWith('/masters')) data = state.masters
|
||||
else return new Response(JSON.stringify({ message: '隔离测试未匹配请求' }), { status: 404 })
|
||||
return new Response(JSON.stringify({ data }))
|
||||
}
|
||||
return { calls, state, fetcher }
|
||||
}
|
||||
Reference in new issue
Block a user