552 lines
27 KiB
TypeScript
552 lines
27 KiB
TypeScript
import { createApp, defineComponent, h, ref } from 'vue'
|
|
import { NButton, NConfigProvider, NGlobalStyle, NMessageProvider, dateZhCN, zhCN } from 'naive-ui'
|
|
import ActionMessageProvider from '../../src/components/ui/ActionMessageProvider.vue'
|
|
import { useTheme } from '../../src/composables/useTheme'
|
|
import ShotDerivedReview from '../../src/features/storyboard/components/ShotDerivedReview.vue'
|
|
import MotionRevisionEditor from '../../src/features/storyboard/components/MotionRevisionEditor.vue'
|
|
import ProjectSettingsDialog from '../../src/features/generation-config/components/ProjectSettingsDialog.vue'
|
|
import KeyframeDialog from '../../src/features/production/components/KeyframeDialog.vue'
|
|
import KeyframeCard from '../../src/features/production/components/KeyframeCard.vue'
|
|
import type { MotionPlan, MotionRevisionHistory, MotionRevision } from '../../src/features/storyboard/motion-revision'
|
|
import type { ImageBoundedAuthorizationInput } from '../../src/features/image-authorization/types'
|
|
import { jointReviewFixture } from '../fixtures/joint-review'
|
|
import { additionalImageFixture } from '../fixtures/image-additional'
|
|
import { imagePreviewFixture } from '../fixtures/image-preview'
|
|
import { billingCatalog, billingProfile } from '../fixtures/billing'
|
|
import { keyframeFixture } from '../../src/features/production/testing/fixtures'
|
|
import '../../src/styles/styles.css'
|
|
import '../../src/styles/admin.css'
|
|
|
|
/** 只存在内存的独立项目,不接触真实资产或批准。 */
|
|
const projectId = 'v8-ten-isolated',
|
|
joint = jointReviewFixture(projectId),
|
|
shotId = joint.shot.shotId
|
|
/** 原未知账本保留,无自动新增或核清。 */
|
|
const images = additionalImageFixture(projectId)
|
|
images.requests[0]!.inputFingerprint = 'e'.repeat(64)
|
|
images.additionalAuthorizations = []
|
|
/** 草案初始与正式内容一致,只允许用户主动变更构图。 */
|
|
joint.saved.draft = structuredClone(joint.formal)
|
|
/** 图片使用本地内嵌占位,不访问任何图片模型。 */
|
|
const mockImage = 'http://localhost:4312/tests/browser/candidate.svg'
|
|
/** 两个已有图片及一个明确生成失败记录;免费计划不在资产列表中。 */
|
|
const assets = [
|
|
keyframeFixture({ id: 'old-failed', shotId, isPrimary: true, imageUrl: mockImage, provider: 'openai-image' }),
|
|
keyframeFixture({ id: 'quality-unknown', shotId, isPrimary: false, imageUrl: mockImage, provider: 'openai-image' }),
|
|
keyframeFixture({
|
|
id: 'generation-failed',
|
|
shotId,
|
|
isPrimary: false,
|
|
status: 'failed',
|
|
imageUrl: null,
|
|
error: '隔离生成失败,原费用保留'
|
|
})
|
|
]
|
|
/** 有限许可、摄影及模型动作分别计数,刷新页面不会触发生成。 */
|
|
const writes = ref(0),
|
|
generations = ref(0),
|
|
vision = ref(0),
|
|
reviewVersion = ref(0)
|
|
/** 免费能力409开关与正式来源版本。 */
|
|
let capacityBlocked = false,
|
|
adopted = false,
|
|
generated = false
|
|
/** 原失败动作原文,不因人工保存而改成通过。 */
|
|
const motionPlan: MotionPlan = {
|
|
beats: [
|
|
{
|
|
startSecond: 0,
|
|
endSecond: 4,
|
|
action: '人物保持起点站姿后缓慢前行',
|
|
cameraMotion: '保持静止',
|
|
physicalContinuity: '双脚支撑连续,保持正式空间',
|
|
subjectRefs: ['@CH0001'],
|
|
closingState: '人物保持站立',
|
|
performedActionIds: ['original-action']
|
|
}
|
|
],
|
|
globalMotionConstraints: ['保留正式身份与场景'],
|
|
interactions: []
|
|
}
|
|
/** 空原始指针合法,服务端保存时创建失败根与人工子版本。 */
|
|
const history: MotionRevisionHistory = { shotId, originalRevisionId: null, activeRevisionId: null, revisions: [] }
|
|
/** 当前正式人工规划仅声明视频末态未验证。 */
|
|
const continuity = {
|
|
previousShotId: 'previous-shot',
|
|
sameScene: true,
|
|
previousClosingState: null,
|
|
subjects: [],
|
|
reviewIssues: [],
|
|
sceneTransition: {
|
|
previousShotId: 'previous-shot',
|
|
subjectRef: '@SC0001',
|
|
subjectFormId: 'original-scene-form',
|
|
basis: 'confirmed_plan' as const,
|
|
fingerprint: 'a'.repeat(64),
|
|
requestFingerprint: 'b'.repeat(64),
|
|
verifiedVideoEndState: false as const
|
|
}
|
|
}
|
|
/**
|
|
* 正式响应包装,永远不回退到网络。
|
|
* @param data 隔离投影
|
|
* @returns Mock响应
|
|
*/
|
|
function ok(data: unknown) {
|
|
return Response.json({ data })
|
|
}
|
|
/**
|
|
* 全量拦截真实组件的请求,未知路由直接403;不连接模型或正式项目。
|
|
* @param input 原路径
|
|
* @param init 请求参数
|
|
* @returns 隔离正式契约响应
|
|
*/
|
|
window.fetch = async (input, init) => {
|
|
const path = String(input),
|
|
method = init?.method ?? 'GET',
|
|
body = init?.body ? JSON.parse(String(init.body)) : undefined
|
|
if (['POST', 'PUT'].includes(method)) writes.value++
|
|
if (path === `/api/projects/${projectId}`) return ok({ id: projectId, episodes: [{ episode: 1 }] })
|
|
if (path.includes('/workflow-executions/latest')) return ok(null)
|
|
if (path.endsWith('/generation-models')) return ok(billingCatalog)
|
|
if (path.endsWith('/creative-profile'))
|
|
return ok({
|
|
...billingProfile,
|
|
projectId,
|
|
aspectRatio: '16:9',
|
|
imageOptions: { size: '1536x1024', quality: 'auto', count: 1 }
|
|
})
|
|
if (path.endsWith('/resolve'))
|
|
return ok({
|
|
provider: 'openai-image',
|
|
model: 'gpt-image-2.5-flare',
|
|
options: { size: '1536x1024', quality: 'auto', count: 1 }
|
|
})
|
|
if (path.endsWith('/image-providers/capabilities'))
|
|
return ok([
|
|
{
|
|
provider: 'openai-image',
|
|
active: true,
|
|
capabilities: { references: { supported: true, maxReferenceImages: 16 } }
|
|
}
|
|
])
|
|
if (path.includes('/keyframe-provider-capability'))
|
|
return capacityBlocked
|
|
? Response.json(
|
|
{
|
|
code: 'IMAGE_REFERENCE_CAPACITY_EXCEEDED',
|
|
message: '当前必需参考17张,OpenAI限制16张;不能丢弃必需参考。'
|
|
},
|
|
{ status: 409 }
|
|
)
|
|
: ok({
|
|
provider: 'openai-image',
|
|
valid: true,
|
|
referenceCount: 2,
|
|
plannedReferenceCount: 2,
|
|
omittedReferenceCount: 0,
|
|
maxReferenceImages: 16
|
|
})
|
|
if (path.includes('/storyboard-quality-confirmation'))
|
|
return ok({
|
|
current: { ...joint.approval.approval, valid: true, confirmation: joint.approval.record },
|
|
quality: joint.approval.quality
|
|
})
|
|
if (path.includes('/keyframe-review-draft')) {
|
|
if (method === 'PUT') {
|
|
joint.saved.draft = body.draft
|
|
joint.saved.revision++
|
|
joint.saved.providerInput = body.providerInput
|
|
joint.saved.status = 'current'
|
|
}
|
|
return ok(joint.saved)
|
|
}
|
|
if (path.includes('/storyboard-directions?')) return ok(joint.directions)
|
|
if (path.includes('/storyboard-visual-states?')) return ok(joint.visuals)
|
|
if (path.includes('/keyframe-spec'))
|
|
return ok({ ...joint.keyframe, formalSourceFingerprint: (adopted ? 'f' : 'c').repeat(64) })
|
|
if (path.includes('/generation-spec')) return ok({ projectId, shotId, subjects: [], continuity })
|
|
if (path.endsWith('/storyboard-derived-reviews/confirm')) {
|
|
adopted = true
|
|
joint.saved.status = 'stale'
|
|
joint.directions.beats[0]!.shots[0]!.direction = {
|
|
...body.shots[0].draft.direction,
|
|
rawJson: JSON.stringify({
|
|
cameraRevisionHistory: [
|
|
{ reviewer: body.reviewer, before: joint.formal.direction, after: body.shots[0].draft.direction }
|
|
]
|
|
})
|
|
}
|
|
reviewVersion.value++
|
|
return ok({ projectId, shots: [{ shotId, directionId: 'd', visualStateId: 'v' }] })
|
|
}
|
|
if (path.includes('/keyframe/preview')) {
|
|
if (capacityBlocked)
|
|
return Response.json(
|
|
{ code: 'IMAGE_REFERENCE_CAPACITY_EXCEEDED', message: '当前必需参考17张,OpenAI限制16张。' },
|
|
{ status: 409 }
|
|
)
|
|
const preview = {
|
|
...imagePreviewFixture(),
|
|
provider: 'openai-image',
|
|
model: 'gpt-image-2.5-flare',
|
|
shotId,
|
|
continuity
|
|
}
|
|
return ok(
|
|
body.draft
|
|
? {
|
|
...preview,
|
|
draftFingerprint: 'd'.repeat(64),
|
|
currentDerivedFingerprint: 'c'.repeat(64),
|
|
adjacentDerivedVersions: [{ shotId: 'previous-shot', derivedFingerprint: 'a'.repeat(64) }],
|
|
productionReady: false,
|
|
productionGate: { ready: false, reason: '仅检查草案' },
|
|
sceneSources: []
|
|
}
|
|
: preview
|
|
)
|
|
}
|
|
if (path.endsWith('/image-authorizations/preview'))
|
|
return ok({
|
|
provider: 'openai-image',
|
|
model: 'gpt-image-2.5-flare',
|
|
context: {
|
|
projectId,
|
|
scope: 'keyframe',
|
|
targetId: body.targetId,
|
|
sourceFingerprint: (adopted ? 'f' : 'c').repeat(64)
|
|
},
|
|
planFingerprint: 'b'.repeat(64),
|
|
authorization: images
|
|
})
|
|
if (path.endsWith('/image-authorizations')) {
|
|
if (method === 'POST') {
|
|
if (body.mode !== 'bounded') return Response.json({ message: '本隔离场景仅登记bounded' }, { status: 403 })
|
|
const existing = images.additionalAuthorizations!.find(
|
|
row => row.input.idempotencyKey === body.idempotencyKey
|
|
)
|
|
if (existing) return ok({ authorizationId: existing.id, status: existing.status })
|
|
const permit = {
|
|
id: 'bounded-' + images.additionalAuthorizations!.length,
|
|
status: 'approved',
|
|
input: { ...(body as ImageBoundedAuthorizationInput), parentInputFingerprint: 'a'.repeat(64) },
|
|
usedRequests: 0,
|
|
remainingRequests: body.maxRequests,
|
|
targets: body.targets.map((target: ImageBoundedAuthorizationInput['targets'][number]) => ({
|
|
...target,
|
|
usedRequests: 0
|
|
}))
|
|
}
|
|
images.additionalAuthorizations!.push(permit)
|
|
return ok({ authorizationId: permit.id, status: permit.status })
|
|
}
|
|
return ok(images)
|
|
}
|
|
if (path.endsWith('/revoke')) {
|
|
const permit = images.additionalAuthorizations!.find(row => row.id === path.split('/').at(-2))
|
|
if (permit) permit.status = 'revoked'
|
|
return ok({ authorizationId: permit?.id, status: 'revoked' })
|
|
}
|
|
if (/\/keyframe(?:\?|$)/.test(path) && method === 'POST') {
|
|
const permit = images.additionalAuthorizations!.find(row => row.id === body.additionalAuthorizationId)
|
|
if (!permit || permit.status !== 'approved' || permit.remainingRequests < 1)
|
|
return Response.json({ message: '许可已失效或用尽' }, { status: 409 })
|
|
if (!generated) {
|
|
generated = true
|
|
generations.value++
|
|
permit.usedRequests++
|
|
permit.remainingRequests--
|
|
permit.targets![0]!.usedRequests++
|
|
const grant = images.authorizations[0]!
|
|
grant.usedRequests++
|
|
grant.remainingRequests--
|
|
grant.accountedMicros += grant.input.perRequestMicros
|
|
grant.remainingMicros -= grant.input.perRequestMicros
|
|
images.requests.push({
|
|
...structuredClone(images.requests[0]!),
|
|
id: 'new-completed',
|
|
status: 'completed',
|
|
input: { ...images.requests[0]!.input, targetId: shotId, additionalAuthorizationId: permit.id },
|
|
output: { usageCostMicros: 1, actualBilledMicros: null, result: { image: 'mock-result' } }
|
|
})
|
|
}
|
|
return ok({ id: 'new-completed', shotId, status: 'completed' })
|
|
}
|
|
if (path.endsWith('/keyframes')) return ok(assets)
|
|
if (path.includes('/quality-review'))
|
|
return ok({
|
|
shotId,
|
|
keyframeId: path.split('/keyframes/')[1]?.split('/')[0],
|
|
qualityDecision: path.includes('/old-failed/') ? 'failed' : 'unknown',
|
|
effectiveQualityStatus: path.includes('/old-failed/') ? 'stale' : 'unknown',
|
|
validationTaskId: null,
|
|
historicalGazePreview: [],
|
|
manualReview: null,
|
|
manualReviewAvailable: false
|
|
})
|
|
if (path.includes('/validations')) return ok([])
|
|
if (path.endsWith('/motion-plan/preview'))
|
|
return ok({
|
|
shotId,
|
|
durationSeconds: 4,
|
|
motionPlanAvailable: false,
|
|
beats: [],
|
|
globalMotionConstraints: [],
|
|
issues: [],
|
|
actionDensityIssues: [],
|
|
actionReviewSuggestions: [],
|
|
savedActionDensityIssues: null,
|
|
willCallModel: false,
|
|
willModifyAssets: false
|
|
})
|
|
if (path.endsWith('/video-prompt/preview'))
|
|
return ok({
|
|
shotId,
|
|
projectId,
|
|
latestTask: { taskId: 'original-failed-task', executionId: 'original-failed-workflow' }
|
|
})
|
|
if (path.includes('/video-prompt/executions/'))
|
|
return ok({
|
|
taskId: 'original-failed-task',
|
|
executionId: 'original-failed-workflow',
|
|
shotId,
|
|
plan: { projectId },
|
|
current: true,
|
|
status: 'failed',
|
|
qualityFailure: { phase: 'motion_plan', issues: ['原动作起点不匹配'] },
|
|
observations: { motion_plan: motionPlan },
|
|
steps: [
|
|
{
|
|
name: 'motion_plan',
|
|
status: 'completed',
|
|
providerRequestId: 'mock-provider-receipt',
|
|
usage: { inputTokens: 100 }
|
|
}
|
|
]
|
|
})
|
|
if (path.endsWith('/revisions/preview'))
|
|
return ok({
|
|
shotId,
|
|
valid: true,
|
|
motionPlanFingerprint: 'f'.repeat(64),
|
|
schemaIssues: [],
|
|
timelineIssues: [],
|
|
actionDensityIssues: [],
|
|
formalIssues: [],
|
|
requiresStartStateValidation: true,
|
|
canActivate: false,
|
|
willCallModel: false,
|
|
willModifyAssets: false,
|
|
startStateStatus: 'required_unknown',
|
|
sourceFingerprint: 'c'.repeat(64),
|
|
previewFingerprint: 'd'.repeat(64),
|
|
source: {
|
|
projectId,
|
|
activeRevisionId: history.activeRevisionId,
|
|
primaryKeyframeId: assets[0]!.id,
|
|
facts: {}
|
|
},
|
|
startStatePlan: {
|
|
version: 1,
|
|
primaryKeyframeId: assets[0]!.id,
|
|
expectedRevisionId: history.activeRevisionId,
|
|
motionPlanFingerprint: 'f'.repeat(64),
|
|
fingerprint: 'a'.repeat(64),
|
|
sourceFingerprint: 'c'.repeat(64),
|
|
status: 'ready',
|
|
executionAvailable: true,
|
|
proposedMaximumProviderRequests: 1,
|
|
additionalProviderRequests: 1,
|
|
feeEstimate: { currency: 'USD', amount: null, reason: '实际费用未知' }
|
|
}
|
|
})
|
|
if (path.endsWith('/motion-plan/revisions')) {
|
|
if (method === 'POST') {
|
|
const root: MotionRevision = {
|
|
revisionId: 'failed-root',
|
|
shotId,
|
|
source: 'failed_candidate',
|
|
parentRevisionId: null,
|
|
reason: '原质量失败',
|
|
candidateOrigin: {
|
|
taskId: 'original-failed-task',
|
|
workflowExecutionId: 'original-failed-workflow',
|
|
authorizationId: 'original-grant',
|
|
sourceFingerprint: 'c'.repeat(64),
|
|
evidenceFingerprint: 'e'.repeat(64),
|
|
receiptFingerprint: 'b'.repeat(64),
|
|
originalBusinessStatus: 'failed'
|
|
},
|
|
motionPlan,
|
|
durationSeconds: 4,
|
|
fingerprint: 'e'.repeat(64),
|
|
createdAt: new Date().toISOString(),
|
|
isActive: false
|
|
}
|
|
const manual: MotionRevision = {
|
|
...root,
|
|
revisionId: 'manual-child',
|
|
source: 'manual',
|
|
parentRevisionId: root.revisionId,
|
|
reason: body.reason,
|
|
candidateOrigin: null,
|
|
motionPlan: body.motionPlan,
|
|
fingerprint: 'f'.repeat(64)
|
|
}
|
|
history.revisions = [root, manual]
|
|
return ok(manual)
|
|
}
|
|
return ok(history)
|
|
}
|
|
if (path.endsWith('/start-state-validation/start')) {
|
|
vision.value++
|
|
return Response.json({ message: '此浏览器场景只验收保存,不执行Vision' }, { status: 403 })
|
|
}
|
|
return Response.json({ message: '未声明接口,禁止连接真实服务。' }, { status: 403 })
|
|
}
|
|
/** 复用原设置/摄影/首帧/动作编辑器,仅为测试提供外部打开按钮。 */
|
|
const Preview = defineComponent({
|
|
setup() {
|
|
const theme = useTheme(),
|
|
settings = ref(false),
|
|
keyframe = ref(false),
|
|
motion = ref(false)
|
|
return () =>
|
|
h(
|
|
NConfigProvider,
|
|
{ theme: theme.theme.value, themeOverrides: theme.overrides.value, locale: zhCN, dateLocale: dateZhCN },
|
|
{
|
|
default: () =>
|
|
h(
|
|
NMessageProvider,
|
|
{},
|
|
{
|
|
default: () =>
|
|
h(
|
|
ActionMessageProvider,
|
|
{},
|
|
{
|
|
default: () => [
|
|
h(NGlobalStyle),
|
|
h('main', { style: 'height:100dvh;overflow:auto;padding:24px' }, [
|
|
h('h1', {}, 'V8-10 隔离验收'),
|
|
h(
|
|
'p',
|
|
{ style: 'margin:16px 0' },
|
|
'全部接口已拦截,真实模型请求0次。免费计划不计为图片候选。'
|
|
),
|
|
h(
|
|
'div',
|
|
{ class: 'workspace-action-group', style: 'margin:16px 0' },
|
|
[
|
|
h(
|
|
NButton,
|
|
{ onClick: () => (settings.value = true) },
|
|
() => '图片授权管理'
|
|
),
|
|
h(
|
|
NButton,
|
|
{ onClick: () => (keyframe.value = true) },
|
|
() => '首帧生成'
|
|
),
|
|
h(
|
|
NButton,
|
|
{ onClick: () => (motion.value = true) },
|
|
() => '人工动作修订'
|
|
),
|
|
h(
|
|
NButton,
|
|
{ onClick: () => (capacityBlocked = !capacityBlocked) },
|
|
() => '切换容量409'
|
|
),
|
|
h(
|
|
NButton,
|
|
{
|
|
onClick: () => {
|
|
const row =
|
|
images.additionalAuthorizations!.at(-1)
|
|
if (row?.input.mode === 'bounded')
|
|
row.input.expiresAt = '2000-01-01T00:00:00Z'
|
|
}
|
|
},
|
|
() => '模拟许可过期'
|
|
)
|
|
]
|
|
),
|
|
h(ShotDerivedReview, {
|
|
projectId,
|
|
episodeNo: 1,
|
|
shot: joint.shot,
|
|
shots: joint.shots,
|
|
disabled: false
|
|
}),
|
|
h(
|
|
'p',
|
|
{ role: 'status', style: 'margin:16px 0' },
|
|
`模拟写入 ${writes.value} · 图片生成 ${generations.value} · Vision ${vision.value} · 正式采用 ${history.activeRevisionId ?? '无'}`
|
|
),
|
|
h(
|
|
'div',
|
|
{
|
|
style: 'display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,280px),1fr));gap:16px'
|
|
},
|
|
assets.map(item =>
|
|
h(KeyframeCard, {
|
|
key: item.id,
|
|
item,
|
|
projectId,
|
|
shotId,
|
|
shotNo: 1,
|
|
stale: false,
|
|
blocked: true,
|
|
validationPassed: false,
|
|
confirming: false,
|
|
readonly: true,
|
|
reviewRevision: reviewVersion.value
|
|
})
|
|
)
|
|
)
|
|
]),
|
|
h(ProjectSettingsDialog, {
|
|
projectId,
|
|
disabled: false,
|
|
initialTab: 'image-authorization',
|
|
open: settings.value,
|
|
'onUpdate:open': value => (settings.value = value)
|
|
}),
|
|
h(KeyframeDialog, {
|
|
projectId,
|
|
shotId,
|
|
shotTitle: '隔离镜头',
|
|
disabled: false,
|
|
additionalAllowed: true,
|
|
open: keyframe.value,
|
|
'onUpdate:open': value => (keyframe.value = value),
|
|
reuseExisting: async () => generated,
|
|
submitGeneration: async input => ({
|
|
accepted: (
|
|
await fetch(
|
|
`/api/storyboard-shots/${shotId}/keyframe?projectId=${projectId}`,
|
|
{ method: 'POST', body: JSON.stringify(input) }
|
|
)
|
|
).ok
|
|
})
|
|
}),
|
|
h(MotionRevisionEditor, {
|
|
projectId,
|
|
shotId,
|
|
open: motion.value,
|
|
'onUpdate:open': value => (motion.value = value)
|
|
})
|
|
]
|
|
}
|
|
)
|
|
}
|
|
)
|
|
}
|
|
)
|
|
}
|
|
})
|
|
createApp(Preview).mount('#app')
|