457 lines
24 KiB
TypeScript
457 lines
24 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 ProjectSettingsDialog from '../../src/features/generation-config/components/ProjectSettingsDialog.vue'
|
|
import KeyframeDialog from '../../src/features/production/components/KeyframeDialog.vue'
|
|
import { jointReviewFixture } from '../fixtures/joint-review'
|
|
import { imageAuditFixture } from '../fixtures/image-billing-audit'
|
|
import { additionalImageFixture } from '../fixtures/image-additional'
|
|
import { imagePreviewFixture } from '../fixtures/image-preview'
|
|
import { billingCatalog, billingProfile } from '../fixtures/billing'
|
|
import type {
|
|
ImageBillingEvidenceInput,
|
|
ImageBillingReviewInput
|
|
} from '../../src/features/image-authorization/billing-audit.types'
|
|
import type { ImageAdditionalAuthorizationInput } from '../../src/features/image-authorization/types'
|
|
import '../../src/styles/styles.css'
|
|
import '../../src/styles/admin.css'
|
|
|
|
/** 隔离数据只存在本页面,未知接口403,无任何正式项目或模型连接。 */
|
|
const joint = jointReviewFixture('mock-joint-project')
|
|
/** 可选环境验收仅修改内存草案;完整源集正文保留原始换行。 */
|
|
const environmentMode = new URLSearchParams(location.search).has('environment')
|
|
/** 模拟正式项目详情公开的本集身份和全文,不使用摘要。 */
|
|
const environmentEpisode = {
|
|
id: 'mock-source-episode',
|
|
projectId: 'mock-joint-project',
|
|
episode: 1,
|
|
title: '当前源集',
|
|
content: '第一行\r\n午后,维修间透入日光。\n天气未指定。'
|
|
}
|
|
if (environmentMode) {
|
|
joint.saved.draft.visualState.environment = {
|
|
timeOfDay: '午后',
|
|
weather: '',
|
|
atmosphere: '自然日光',
|
|
transientState: ''
|
|
}
|
|
}
|
|
/** 原unknown与账单始终保留的隔离费用账本。 */
|
|
const images = additionalImageFixture()
|
|
images.additionalAuthorizations = []
|
|
/** 原图片审计身份与费用父请求一致,所有原件必须由测试操作者填写。 */
|
|
const audit = imageAuditFixture('billing-project', 'original-image-request')
|
|
audit.identity.candidateId = 'original-image'
|
|
audit.reservedMicros = images.requests[0]!.input.reservedMicros
|
|
/** 只统计模拟同步操作,不是真实模型调用。 */
|
|
const writes = ref(0)
|
|
/** 隔离模型请求计数,已成功后同计划不再增加。 */
|
|
const mockGenerations = ref(0)
|
|
/** 精确保存当前页面发出的请求,帮助验收无隐式生成。 */
|
|
const calls: Array<{ path: string; method: string; body: unknown }> = []
|
|
/** 模拟并发仅作用于下一次正式联合采用,不改变预检。 */
|
|
let neighborConflict = false
|
|
/** 下一次采用时模拟本集正文版本变化,预检仍可通过。 */
|
|
let environmentConflict = false
|
|
/** 模拟审计409后保留表单。 */
|
|
let auditConflict = false
|
|
/** 只读结果是否已有完整同计划候选。 */
|
|
let hasImage = false
|
|
/**
|
|
* 返回隔离的正式接口响应形状。
|
|
* @param data 当前模拟数据
|
|
* @returns 不连接网络的响应
|
|
*/
|
|
function ok(data: unknown) {
|
|
return new Response(JSON.stringify({ data }), { headers: { 'Content-Type': 'application/json' } })
|
|
}
|
|
/**
|
|
* 全请求隔离处理,任何未声明路由都拒绝,不回退真实fetch。
|
|
* @param input 原请求地址
|
|
* @param init 原请求参数
|
|
* @returns 正式接口形状的Mock响应
|
|
*/
|
|
window.fetch = async (input, init) => {
|
|
const path = String(input),
|
|
method = init?.method ?? 'GET',
|
|
body = init?.body ? JSON.parse(String(init.body)) : undefined
|
|
calls.push({ path, method, body })
|
|
if (method === 'POST' || method === 'PUT') writes.value++
|
|
if (path === '/api/projects/mock-joint-project')
|
|
return ok({ id: 'mock-joint-project', episodes: [environmentEpisode] })
|
|
if (path.endsWith('/generation-models')) return ok(billingCatalog)
|
|
if (path.endsWith('/creative-profile')) return ok(billingProfile)
|
|
if (path.endsWith('/resolve')) return ok({ provider: 'openai-image', model: 'gpt-image-2.5-flare', options: {} })
|
|
if (path.includes('/keyframe-review-draft')) {
|
|
if (method === 'PUT') {
|
|
if (body.expectedRevision !== joint.saved.revision)
|
|
return new Response(JSON.stringify({ message: '草案版本已变化' }), { status: 409 })
|
|
joint.saved.draft = body.draft
|
|
joint.saved.providerInput = body.providerInput ?? null
|
|
joint.saved.expectedCurrentFormalSourceFingerprint = body.expectedCurrentFormalSourceFingerprint
|
|
joint.saved.revision++
|
|
joint.saved.status = 'current'
|
|
}
|
|
return ok(joint.saved)
|
|
}
|
|
if (path.endsWith('/storyboard-quality-confirmation'))
|
|
return ok({ ...joint.approval.approval, valid: true, confirmation: joint.approval.record })
|
|
if (path.endsWith('/storyboard-quality-confirmation/preflight'))
|
|
return ok({
|
|
current: { ...joint.approval.approval, valid: true, confirmation: joint.approval.record },
|
|
quality: joint.approval.quality
|
|
})
|
|
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)
|
|
if (path.includes('/generation-spec'))
|
|
return ok({ shotId: joint.shot.shotId, projectId: 'mock-joint-project', subjects: [] })
|
|
if (path.endsWith('/storyboard-derived-reviews/confirm')) {
|
|
if (body.shots[0]?.jointRevision) {
|
|
if (!body.preview && environmentConflict) {
|
|
environmentConflict = false
|
|
environmentEpisode.content += '\n另一位编辑已更新源正文。'
|
|
}
|
|
if (body.shots[0].jointRevision.changes.some((row: { target: string }) => row.target === 'environment')) {
|
|
const source = body.shots[0].jointRevision.environmentSource
|
|
const digest = await crypto.subtle.digest(
|
|
'SHA-256',
|
|
new TextEncoder().encode(environmentEpisode.content)
|
|
)
|
|
const fingerprint = Array.from(new Uint8Array(digest), byte => byte.toString(16).padStart(2, '0')).join(
|
|
''
|
|
)
|
|
if (
|
|
!source ||
|
|
source.episodeId !== environmentEpisode.id ||
|
|
source.expectedContentFingerprint !== fingerprint ||
|
|
!environmentEpisode.content.includes(source.quote)
|
|
)
|
|
return new Response(
|
|
JSON.stringify({
|
|
message: 'JOINT_REVISION_ENVIRONMENT_SOURCE_STALE: 本集原文已变化,请重新核对。'
|
|
}),
|
|
{ status: 409 }
|
|
)
|
|
}
|
|
if (!body.preview && neighborConflict) {
|
|
neighborConflict = false
|
|
return new Response(
|
|
JSON.stringify({ message: 'JOINT_REVISION_NEIGHBOR_STALE: 相邻镜头已经更新,请重新读取。' }),
|
|
{ status: 409 }
|
|
)
|
|
}
|
|
if (!body.preview) {
|
|
const draft = body.shots[0].draft
|
|
joint.saved.status = 'stale'
|
|
joint.directions.beats[0]!.shots[0]!.direction = {
|
|
...draft.direction,
|
|
rawJson: JSON.stringify({
|
|
jointRevisionHistory: [
|
|
{
|
|
originalDirection: joint.shot.direction,
|
|
changes: body.shots[0].jointRevision.changes,
|
|
environmentSource: body.shots[0].jointRevision.environmentSource,
|
|
reviewer: body.reviewer
|
|
}
|
|
]
|
|
})
|
|
}
|
|
joint.visuals.beats[0]!.shots[0]!.visualState = {
|
|
timeOfDay: draft.visualState.environment.timeOfDay,
|
|
weather: draft.visualState.environment.weather,
|
|
atmosphere: draft.visualState.environment.atmosphere,
|
|
environmentTransientState: draft.visualState.environment.transientState,
|
|
continuityNote: draft.visualState.continuityNote,
|
|
subjects: draft.visualState.subjects.map((subject: Record<string, string>) => ({
|
|
...subject,
|
|
subjectId: 'mock-subject',
|
|
subjectFormId: subject.formId
|
|
}))
|
|
}
|
|
}
|
|
return ok({
|
|
projectId: 'mock-joint-project',
|
|
preview: body.preview,
|
|
changed: !body.preview,
|
|
reused: false,
|
|
requestFingerprint: 'f'.repeat(64),
|
|
shots: [{ shotId: joint.shot.shotId, directionId: 'mock-direction', visualStateId: 'mock-visual' }]
|
|
})
|
|
}
|
|
return ok({ shots: [{ shotId: joint.shot.shotId }] })
|
|
}
|
|
if (path.includes('/keyframe/preview')) {
|
|
const image = {
|
|
...imagePreviewFixture(),
|
|
provider: body.provider ?? 'openai-image',
|
|
model: 'gpt-image-2.5-flare',
|
|
shotId: path.includes('/audit-shot/') ? 'audit-shot' : joint.shot.shotId
|
|
}
|
|
return body.draft
|
|
? ok({
|
|
...image,
|
|
draftFingerprint: 'a'.repeat(64),
|
|
productionReady: false,
|
|
productionGate: { ready: false, reason: '隔离项目尚未完整生产' },
|
|
currentDerivedFingerprint: 'c'.repeat(64),
|
|
adjacentDerivedVersions: [{ shotId: 'shot-db-1-2', derivedFingerprint: 'd'.repeat(64) }],
|
|
sceneSources: []
|
|
})
|
|
: ok(image)
|
|
}
|
|
if (path.endsWith('/image-authorizations/preview'))
|
|
return ok({
|
|
provider: 'openai-image',
|
|
model: 'gpt-image-2.5-flare',
|
|
context: {
|
|
projectId: 'billing-project',
|
|
targetId: 'audit-shot',
|
|
scope: 'keyframe',
|
|
sourceFingerprint: 'c'.repeat(64)
|
|
},
|
|
planFingerprint: 'b'.repeat(64),
|
|
authorization: images
|
|
})
|
|
if (path.endsWith('/image-authorizations') && method === 'GET') return ok(images)
|
|
if (path.endsWith('/image-authorizations') && method === 'POST') {
|
|
if (body.mode === 'additional') {
|
|
const previous = images.additionalAuthorizations!.find(
|
|
row => row.input.idempotencyKey === body.idempotencyKey
|
|
)
|
|
if (previous) return ok({ authorizationId: previous.id, status: previous.status })
|
|
const approvalInput = body as ImageAdditionalAuthorizationInput
|
|
const permit = {
|
|
id: `mock-permit-${images.additionalAuthorizations!.length + 1}`,
|
|
status: 'approved',
|
|
input: { ...approvalInput, parentInputFingerprint: 'd'.repeat(64) },
|
|
usedRequests: 0,
|
|
remainingRequests: approvalInput.maxRequests
|
|
}
|
|
images.additionalAuthorizations!.push(permit)
|
|
return ok({ authorizationId: permit.id, status: permit.status, parentAuthorizationId: 'grant' })
|
|
}
|
|
return ok({ authorizationId: 'mock-standing', status: 'approved' })
|
|
}
|
|
if (path.endsWith('/revoke')) {
|
|
const id = path.split('/').at(-2)!,
|
|
row =
|
|
images.authorizations.find(item => item.id === id) ??
|
|
images.additionalAuthorizations!.find(item => item.id === id)
|
|
if (row) row.status = 'revoked'
|
|
return ok({ authorizationId: id, status: 'revoked' })
|
|
}
|
|
if (path.endsWith('/audit')) return ok(audit)
|
|
if (path.endsWith('/audit/evidence')) {
|
|
const previous = audit.history.evidence.find(row => JSON.stringify(row.body) === JSON.stringify(body))
|
|
const row = previous ?? {
|
|
id: `mock-evidence-${audit.history.evidence.length + 1}`,
|
|
requestId: audit.requestId,
|
|
taskFingerprint: audit.taskFingerprint,
|
|
body: body as ImageBillingEvidenceInput,
|
|
digest: '1'.repeat(64)
|
|
}
|
|
if (!previous) audit.history.evidence.push(row)
|
|
audit.evidenceSetFingerprint = '2'.repeat(64)
|
|
audit.released = false
|
|
audit.billingBlocked = true
|
|
audit.status = 'unreviewed'
|
|
return ok({ ...audit, evidenceId: row.id, reused: !!previous })
|
|
}
|
|
if (path.endsWith('/audit/reviews')) {
|
|
if (auditConflict) {
|
|
auditConflict = false
|
|
audit.reviewFingerprint = '3'.repeat(64)
|
|
return new Response(
|
|
JSON.stringify({
|
|
code: 'IMAGE_BILLING_AUDIT_REVIEW_CONFLICT',
|
|
message: '另一项隔离复核已先完成,请重新核对。'
|
|
}),
|
|
{ status: 409 }
|
|
)
|
|
}
|
|
const review = body as ImageBillingReviewInput
|
|
audit.history.reviews.push({
|
|
id: `mock-review-${audit.history.reviews.length + 1}`,
|
|
requestId: audit.requestId,
|
|
taskFingerprint: audit.taskFingerprint,
|
|
body: review,
|
|
digest: '4'.repeat(64),
|
|
revision: audit.history.reviews.length + 1
|
|
})
|
|
audit.released = review.decision === 'release_future_charges'
|
|
audit.status = audit.released ? 'released' : 'blocked'
|
|
audit.billingBlocked = !audit.released
|
|
audit.reviewedAmountMicros = audit.released ? 1 : null
|
|
images.billingBlocked = audit.billingBlocked
|
|
images.blockingRequestIds = audit.billingBlocked ? ['original-image-request'] : []
|
|
images.requests[0]!.billingAudit = {
|
|
status: audit.status,
|
|
released: audit.released,
|
|
reviewId: audit.released ? 'mock-review' : null,
|
|
reviewedAmountMicros: audit.reviewedAmountMicros
|
|
}
|
|
return ok({ ...audit, reused: false })
|
|
}
|
|
if (/\/audit-shot\/keyframe(?:\?|$)/.test(path)) {
|
|
if (!hasImage) {
|
|
const permit = images.additionalAuthorizations!.find(row => row.id === body.additionalAuthorizationId)
|
|
if (
|
|
!permit ||
|
|
permit.status !== 'approved' ||
|
|
!permit.remainingRequests ||
|
|
body.provider !== 'openai-image'
|
|
)
|
|
return new Response(
|
|
JSON.stringify({
|
|
code: 'IMAGE_ADDITIONAL_AUTHORIZATION_INVALID',
|
|
message: '缺少当前精确计划人工许可'
|
|
}),
|
|
{ status: 409 }
|
|
)
|
|
permit.usedRequests++
|
|
permit.remainingRequests--
|
|
mockGenerations.value++
|
|
hasImage = true
|
|
const grant = images.authorizations.find(row => row.id === images.requests[0]!.input.authorizationId)
|
|
if (grant) {
|
|
grant.usedRequests++
|
|
grant.remainingRequests = Math.max(0, grant.remainingRequests - 1)
|
|
grant.accountedMicros += images.requests[0]!.input.reservedMicros
|
|
grant.remainingMicros = Math.max(0, grant.input.budgetMicros - grant.accountedMicros)
|
|
}
|
|
images.requests.push({
|
|
...structuredClone(images.requests[0]!),
|
|
id: 'mock-image-completed',
|
|
status: 'completed',
|
|
input: { ...images.requests[0]!.input, additionalAuthorizationId: permit.id },
|
|
output: { usageCostMicros: 1, actualBilledMicros: null, result: { image: 'mock-existing-result' } }
|
|
})
|
|
}
|
|
return ok({
|
|
id: 'mock-existing-candidate',
|
|
shotId: 'audit-shot',
|
|
status: 'completed',
|
|
recoveryRequired: false,
|
|
providerInputFingerprint: 'a'.repeat(64)
|
|
})
|
|
}
|
|
return new Response(JSON.stringify({ message: '隔离页面拒绝未声明接口;不会连接正式服务。' }), { status: 403 })
|
|
}
|
|
/** 原组件与原全屏抽屉组成的本地验收页,不进入正式构建入口。 */
|
|
const Preview = defineComponent({
|
|
setup() {
|
|
const theme = useTheme(),
|
|
settings = ref(false),
|
|
keyframe = 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',
|
|
{ style: 'font-size:22px;margin-bottom:12px' },
|
|
'联合摄影与图片费用 · Mock隔离验收'
|
|
),
|
|
h(
|
|
'p',
|
|
{ style: 'margin-bottom:20px' },
|
|
'全部接口已拦截,测试材料仅保存在内存,不连接正式项目或真实模型。'
|
|
),
|
|
h(
|
|
'div',
|
|
{
|
|
style: 'display:flex;flex-wrap:wrap;gap:12px;margin-bottom:20px'
|
|
},
|
|
[
|
|
h(
|
|
NButton,
|
|
{ onClick: () => (settings.value = true) },
|
|
() => '项目图片授权与原请求'
|
|
),
|
|
h(
|
|
NButton,
|
|
{ onClick: () => (keyframe.value = true) },
|
|
() => '原首帧生成入口'
|
|
),
|
|
h(
|
|
NButton,
|
|
{ onClick: () => (neighborConflict = true) },
|
|
() => '模拟采用时邻镜变化'
|
|
),
|
|
h(
|
|
NButton,
|
|
{ onClick: () => (auditConflict = true) },
|
|
() => '模拟一次费用复核冲突'
|
|
),
|
|
h(
|
|
NButton,
|
|
{ onClick: () => (environmentConflict = true) },
|
|
() => '模拟采用时原文变化'
|
|
)
|
|
]
|
|
),
|
|
h(ShotDerivedReview, {
|
|
projectId: 'mock-joint-project',
|
|
episodeNo: 1,
|
|
shot: joint.shot,
|
|
shots: joint.shots,
|
|
disabled: false
|
|
}),
|
|
h(
|
|
'p',
|
|
{ role: 'status', style: 'margin-top:20px' },
|
|
`模拟同步操作 ${writes.value} 次 · 模拟图片请求 ${mockGenerations.value} 次 · 真实模型请求 0 次`
|
|
)
|
|
]),
|
|
h(ProjectSettingsDialog, {
|
|
projectId: 'billing-project',
|
|
disabled: false,
|
|
initialTab: 'image-authorization',
|
|
open: settings.value,
|
|
'onUpdate:open': value => (settings.value = value)
|
|
}),
|
|
h(KeyframeDialog, {
|
|
projectId: 'billing-project',
|
|
shotId: 'audit-shot',
|
|
shotTitle: '仅供Mock的原镜头',
|
|
disabled: true,
|
|
additionalAllowed: true,
|
|
open: keyframe.value,
|
|
'onUpdate:open': value => (keyframe.value = value),
|
|
reuseExisting: async () => hasImage,
|
|
submitGeneration: async input => {
|
|
const result = await fetch(
|
|
'/api/storyboard-shots/audit-shot/keyframe?projectId=billing-project',
|
|
{ method: 'POST', body: JSON.stringify(input) }
|
|
)
|
|
return { accepted: result.ok }
|
|
}
|
|
})
|
|
]
|
|
}
|
|
)
|
|
}
|
|
)
|
|
}
|
|
)
|
|
}
|
|
})
|
|
createApp(Preview).mount('#app')
|