feat(short-drama-agent-front): 接入图片持续授权与视频费用审计
This commit is contained in:
1 parent
3915566994
commit
1e9ef33d1d
39 files changed
+3442
-51
No files matched your search
@@ -0,0 +1,86 @@
|
||||
# OpenAI 图片持续授权与视频外部费用审计前端交付
|
||||
|
||||
2026-11-13。前端根目录 `dev`,基线 `3915566`。后端契约核对 `dev@3cbff50e749cde36212053800757b8eafb729a3c` 的两份公开 API、两份前端 Prompt、正式路由、Schema 与服务。
|
||||
|
||||
1. 文件与职责
|
||||
|
||||
新增 18 个文件,修改 21 个文件,删除 0 个文件。所有改动均在前端仓库。
|
||||
|
||||
| 状态 | 文件 | 职责 |
|
||||
| --- | --- | --- |
|
||||
| 新增 | [src/features/image-authorization/ImageAuthorizationSettings.vue](../../src/features/image-authorization/ImageAuthorizationSettings.vue) | 有限授权创建、余额、原请求、未知费用和撤销表单 |
|
||||
| 新增 | [src/features/image-authorization/api.ts](../../src/features/image-authorization/api.ts) | 四个正式图片授权接口及既有请求封装 |
|
||||
| 新增 | [src/features/image-authorization/model.ts](../../src/features/image-authorization/model.ts) | 美元精确换算、范围匹配、免费复用及具体阻断原因 |
|
||||
| 新增 | [src/features/image-authorization/types.ts](../../src/features/image-authorization/types.ts) | 授权、原图片请求和免费精确计划的正式类型 |
|
||||
| 新增 | [src/features/production/components/VideoAuditPanel.vue](../../src/features/production/components/VideoAuditPanel.vue) | 原任务只读身份、外部原件、独立复核和完整审计历史 |
|
||||
| 新增 | [src/features/production/useVideoAudit.ts](../../src/features/production/useVideoAudit.ts) | 原任务发现、归属检查、版本冲突和独立同步提交 |
|
||||
| 新增 | [src/features/production/video-audit-api.ts](../../src/features/production/video-audit-api.ts) | 三个正式审计接口与已有历史预检、原任务 GET |
|
||||
| 新增 | [src/features/production/video-audit.ts](../../src/features/production/video-audit.ts) | 原件及复核门禁校验,区分供应方、SDK 与本地身份 |
|
||||
| 新增 | [src/features/production/video-audit.types.ts](../../src/features/production/video-audit.types.ts) | 原身份、原件、复核版本和历史事件类型 |
|
||||
| 新增 | [src/lib/billing-errors.ts](../../src/lib/billing-errors.ts) | 图片错误类型与审计冲突的中文展示映射 |
|
||||
| 新增 | [tests/browser/billing.html](../../tests/browser/billing.html) | 本地 Chrome 隔离验收入口 |
|
||||
| 新增 | [tests/browser/billing.ts](../../tests/browser/billing.ts) | 复用真实组件、主题与全量请求拦截的浏览器场景 |
|
||||
| 新增 | [tests/features/image-authorization/authorization.test.ts](../../tests/features/image-authorization/authorization.test.ts) | 范围、额度、免费复用、供应方切换、未知及原预览提交回归 |
|
||||
| 新增 | [tests/features/image-authorization/defaults.test.ts](../../tests/features/image-authorization/defaults.test.ts) | 推荐与既有选择优先级、主体覆盖、目标切换及迟到响应回归 |
|
||||
| 新增 | [tests/features/image-authorization/settings.test.ts](../../tests/features/image-authorization/settings.test.ts) | 无预填批准、微美元转换、幂等重试和撤销回归 |
|
||||
| 新增 | [tests/features/production/video-audit.test.ts](../../tests/features/production/video-audit.test.ts) | 独立登记、复核、并发冲突、证据不足及费用与质量分离回归 |
|
||||
| 新增 | [tests/fixtures/billing.ts](../../tests/fixtures/billing.ts) | 无真实账户和收费的图片、视频费用夹具 |
|
||||
| 新增 | [docs/audits/image-authorization-video-audit-2026-11-13.md](../../docs/audits/image-authorization-video-audit-2026-11-13.md) | 本轮逐文件职责、接口、验收、边界和 Git 状态交接 |
|
||||
| 修改 | [src/features/generation-config/api.ts](../../src/features/generation-config/api.ts) | 配置解析增加取消信号,沿用服务端覆盖优先级 |
|
||||
| 修改 | [src/features/generation-config/components/ProjectSettingsDialog.vue](../../src/features/generation-config/components/ProjectSettingsDialog.vue) | 原项目全屏配置中增加图片授权标签和固定底栏操作 |
|
||||
| 修改 | [src/features/generation-config/context.ts](../../src/features/generation-config/context.ts) | 共享图片授权入口和配置修订,兼容独立作用域 |
|
||||
| 修改 | [src/features/generation-config/image-defaults.ts](../../src/features/generation-config/image-defaults.ts) | 后端推荐仅用于未填写配置,解析主体覆盖并保护手动选择与迟到响应 |
|
||||
| 修改 | [src/features/production/components/KeyframeDialog.vue](../../src/features/production/components/KeyframeDialog.vue) | 原首帧预览接入授权资格,保留镜头覆盖与候选门禁 |
|
||||
| 修改 | [src/features/production/components/ShotProductionAssets.vue](../../src/features/production/components/ShotProductionAssets.vue) | 视频详情复用全屏抽屉,分开质量与费用审计并刷新原资源 |
|
||||
| 修改 | [src/features/production/components/VideoCard.vue](../../src/features/production/components/VideoCard.vue) | 主视频和候选卡片增加费用审计入口 |
|
||||
| 修改 | [src/features/spatial-layouts/components/MasterGenerationForm.vue](../../src/features/spatial-layouts/components/MasterGenerationForm.vue) | 原布局生成表单展示授权状态和独立费用确认资格 |
|
||||
| 修改 | [src/features/spatial-layouts/components/SceneMasterManager.vue](../../src/features/spatial-layouts/components/SceneMasterManager.vue) | 布局授权范围内省略逐次图片收费确认,独立视觉审核保留原确认 |
|
||||
| 修改 | [src/features/spatial-layouts/useMasterGeneration.ts](../../src/features/spatial-layouts/useMasterGeneration.ts) | 原母版免费预检接入布局范围授权、未知费用阻断和修订失效 |
|
||||
| 修改 | [src/features/subject-identity/components/IdentityImageDialog.vue](../../src/features/subject-identity/components/IdentityImageDialog.vue) | 原身份图入口接入范围授权、原预览和主体覆盖配置 |
|
||||
| 修改 | [src/features/subject-images/components/GenerateImageDialog.vue](../../src/features/subject-images/components/GenerateImageDialog.vue) | 原形态入口接入范围授权,同主体切换形态仍重新读取配置 |
|
||||
| 修改 | [src/features/subject-images/generation-preview.ts](../../src/features/subject-images/generation-preview.ts) | 共用原预览、费用资格、精确免费复用和防重复提交 |
|
||||
| 修改 | [src/lib/http.ts](../../src/lib/http.ts) | 费用错误展示为业务中文,保留原始错误码及细节 |
|
||||
| 修改 | [tests/features/production/production.test.ts](../../tests/features/production/production.test.ts) | 首帧旧回归补充正式配置解析响应 |
|
||||
| 修改 | [tests/features/production/public-assets.test.ts](../../tests/features/production/public-assets.test.ts) | 下载恢复旧回归补充镜头覆盖解析响应 |
|
||||
| 修改 | [tests/features/subject-identity/identity.test.ts](../../tests/features/subject-identity/identity.test.ts) | 身份图片旧回归补充主体配置解析响应 |
|
||||
| 修改 | [tests/features/subject-images/images.test.ts](../../tests/features/subject-images/images.test.ts) | 形态图片旧回归补充主体配置解析响应 |
|
||||
| 修改 | [tests/features/subject-images/prompts.test.ts](../../tests/features/subject-images/prompts.test.ts) | 提示词旧回归补充主体配置解析响应 |
|
||||
|
||||
| 修改 | [tests/components/ui/form.test.ts](../../tests/components/ui/form.test.ts) | 公共图片表单回归补充正式主体配置解析 Mock |
|
||||
| 修改 | [tests/features/workflows/pages.test.ts](../../tests/features/workflows/pages.test.ts) | 工作台端到端组件回归补充正式模型解析 Mock |
|
||||
|
||||
2. API 对接
|
||||
|
||||
- 图片授权完整接入 GET 列表、POST 免费计划、POST 登记、POST 撤销。请求使用现有 `/api` 代理和 `{ data }` 解包。USD 编辑值精确换为整数微美元,空白、非正数及超过 6 位小数均拒绝提交。
|
||||
- 原身份图、形态图、首帧及布局母版继续使用原预览与生成接口。图片预览指纹与费用计划指纹分别保存和使用,正式生成保留 `setPrimary=false` 或原布局版本及 `confirmPaidGeneration=true`。
|
||||
- 视频完整接入 GET audit、POST evidence、POST reviews。已有免费质检预检、原任务 GET 和项目最新执行记录负责任务发现与回读,没有新增收费、恢复或事件流接口。
|
||||
- 正式后端只读核对两项均为 HTTP 200。项目图片授权及原图片请求均为空。原视频任务仍为 failed、billingBlocked=true,三个原步骤均 unreviewed,无外部证据和人工复核。
|
||||
|
||||
3. UI 与状态
|
||||
|
||||
- 授权在原项目配置抽屉独立管理。预算、单次预留、次数、有效期、批准人和接受浮动计费均由用户填写。展示累计准入预算、已记账及未结预留、余额、次数、到期、原请求和具体阻断原因。公开用量价与实际账单分别显示,未知不显示零。
|
||||
- 单次预留不构成供应方账单硬上限,创建前明确说明。有效范围内用户主动生图省略逐图收费批准,其它供应方重新预览并独立确认。原 Creative Profile、主体和镜头覆盖及手动选择保留。
|
||||
- 视频详情的质量和费用分开。原 Task、Workflow、本地请求、供应方请求与 SDK 回执分别显示。登记后不自动复核,核清后只刷新原审计、原任务、质量和列表及免费预检。旧视频过期、failed、needs_review 和晋升门禁沿原状态。
|
||||
- 外部原件只保存引用和 SHA256。表单不生成供应方请求号,不用本地 UUID 或观测编号代替。未知金额保持 null,原件缺失、模糊关联、未知费用及原 SDK 事实冲突时禁用核清。
|
||||
- 409 后刷新服务端版本、保留表单和原件选择、取消当前确认,等待人工重新核对,不自动重提。写入就地加载并使用 NMessage,正文独立滚动,底栏固定,窄屏单列,图标按钮复用正方形公共样式。
|
||||
|
||||
4. 验证结果
|
||||
|
||||
- Git 复核补齐公共表单与工作台页面两处旧配置解析 Mock,69 项定向复验通过。本次正常提交钩子将再次执行完整 pnpm check 和 Commitlint,结果以提交日志为准。
|
||||
- 48 个相关 Vitest 文件、358 项用例通过。补充原请求阻断摘要断言后,图片授权 13 项再次通过。旧测试的配置解析 Mock 已按正式新增读取补齐。
|
||||
- pnpm 启动时尝试拉取包管理器版本失败,本轮改用 node_modules/.bin 下已安装的 vue-tsc、vite、vitest、oxlint、eslint 和 oxfmt 完成等价范围检查。
|
||||
- Vue TypeScript 检查、Vite 生产构建通过。改动范围 Oxlint、Vue ESLint、Oxfmt 检查和 git diff --check 通过。
|
||||
- 本地 Chrome 使用 localhost 隔离页,全部 fetch 均由本页 Mock 拦截。授权与图片入口 10 项、视频审计 10 项核心交互断言通过,覆盖创建、撤销、到期、预算不足、未知阻断、免费复用、供应方重新确认、双击防重复、证据登记、重复登记、独立复核、并发冲突、核清不改质量、新证据使旧复核失效。
|
||||
- Chrome 实际检查桌面和 400×706、500×883 窄屏。字段标签与控件间距为 8px,无水平溢出,长内容滚动前后底栏位置一致,取消保留可见键盘焦点。删除原件图标最终为 34×34。
|
||||
- Chrome 刷新隔离页后请求记录为空,没有自动重发生成、授权或审计写入。
|
||||
- Chrome 原控制连接超时,实际浏览器验证使用本机 Chrome AppleScript 与 DOM 事件完成。未使用 Playwright。
|
||||
|
||||
5. 契约边界与未执行项
|
||||
|
||||
- 真实收费图片、视频、独立视觉审核、修复及主资产变更均未执行。正式历史任务没有登记模拟材料或提交人工核清。原视频仍需真实供应方执行与账单材料才能处置。
|
||||
- 后端普通精确授权预览只开放 identity/form/keyframe 的普通输入。自定义提示词、身份辅助视角和布局高级输入继续使用原预览及持续范围授权;精确免费复用提示仅在正式授权预览能够覆盖该输入时显示。
|
||||
- 已过期候选准备新质检会被原预检拒绝,前端保留最新原任务发现,并提供按原任务编号只读查询。历史身份始终使用服务端原版本。
|
||||
|
||||
6. Git 状态
|
||||
|
||||
开发轮结束时未提交或推送。本 Git 轮用户已明确授权复核后提交并推送到 dev,实际提交和远端同步以 Git 记录为准。全程使用前端根目录 dev,未创建工作树,未修改后端代码。
|
||||
@@ -29,6 +29,14 @@ export const generationConfigApi = {
|
||||
request<CreativeProfile | null>(`${projectPath(projectId)}/creative-profile`, { signal }),
|
||||
saveProfile: (projectId: string, input: CreativeProfileInput) =>
|
||||
request<CreativeProfile>(`${projectPath(projectId)}/creative-profile`, { method: 'PUT', body: input }),
|
||||
/**
|
||||
* 解析实际项目及目标覆盖配置,显式选择时沿原优先级处理。
|
||||
* @param projectId 当前项目
|
||||
* @param mediaType 图片或视频
|
||||
* @param input 显式参数与正式目标
|
||||
* @param signal 取消旧表单读取
|
||||
* @returns 最终供应方、型号及参数
|
||||
*/
|
||||
resolve: (
|
||||
projectId: string,
|
||||
mediaType: GenerationMediaType,
|
||||
@@ -37,11 +45,13 @@ export const generationConfigApi = {
|
||||
model?: string
|
||||
options?: Record<string, unknown>
|
||||
target?: { targetType: GenerationOverrideTargetType; targetId: string }
|
||||
}
|
||||
},
|
||||
signal?: AbortSignal
|
||||
) =>
|
||||
request<ResolvedGenerationConfig>(`${projectPath(projectId)}/generation-config/${mediaType}/resolve`, {
|
||||
method: 'POST',
|
||||
body: input
|
||||
body: input,
|
||||
signal
|
||||
}),
|
||||
override: (
|
||||
projectId: string,
|
||||
|
||||
@@ -4,6 +4,7 @@ import { NButton, NTabs, NTabPane } from 'naive-ui'
|
||||
import { AppDrawer } from '../../../components/ui'
|
||||
import type { CreativeProfileInput } from '../types'
|
||||
import CreativeProfileSettings from './CreativeProfileSettings.vue'
|
||||
import ImageAuthorizationSettings from '../../image-authorization/ImageAuthorizationSettings.vue'
|
||||
import QualityPolicySettings from './QualityPolicySettings.vue'
|
||||
import type { ProjectSettingsTab } from '../context'
|
||||
|
||||
@@ -37,8 +38,16 @@ watch([open, () => props.initialTab, () => props.projectId], ([shown]) => {
|
||||
})
|
||||
/** 质量策略表单实例。 */
|
||||
const qualityForm = ref<InstanceType<typeof QualityPolicySettings> | null>(null)
|
||||
/** 图片授权表单复用抽屉底栏。 */
|
||||
const authorizationForm = ref<InstanceType<typeof ImageAuthorizationSettings> | null>(null)
|
||||
/** 当前标签的独立保存入口,避免跨接口混合保存。 */
|
||||
const activeForm = computed(() => (tab.value === 'quality' ? qualityForm.value : form.value))
|
||||
const activeForm = computed(() =>
|
||||
tab.value === 'image-authorization'
|
||||
? authorizationForm.value
|
||||
: tab.value === 'quality'
|
||||
? qualityForm.value
|
||||
: form.value
|
||||
)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -68,12 +77,26 @@ const activeForm = computed(() => (tab.value === 'quality' ? qualityForm.value :
|
||||
@saved="emit('qualitySaved')"
|
||||
/>
|
||||
</NTabPane>
|
||||
<NTabPane name="image-authorization" tab="OpenAI 图片授权" :disabled="saving" display-directive="show:lazy">
|
||||
<ImageAuthorizationSettings
|
||||
v-if="open"
|
||||
ref="authorizationForm"
|
||||
:key="props.projectId"
|
||||
:project-id="props.projectId"
|
||||
:disabled="props.disabled"
|
||||
@busy="saving = $event"
|
||||
/>
|
||||
</NTabPane>
|
||||
</NTabs>
|
||||
<!-- 以下是固定底栏取消与保存配置模块 -->
|
||||
<template #footer>
|
||||
<NButton :disabled="saving" @click="open = false">取消</NButton>
|
||||
<NButton type="primary" :loading="saving" :disabled="!activeForm?.canSave" @click="activeForm?.save()">{{
|
||||
tab === 'quality' ? '保存质量规则' : '保存配置'
|
||||
tab === 'image-authorization'
|
||||
? authorizationForm?.submitLabel
|
||||
: tab === 'quality'
|
||||
? '保存质量规则'
|
||||
: '保存配置'
|
||||
}}</NButton>
|
||||
</template>
|
||||
</AppDrawer>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { inject, ref, type InjectionKey, type Ref } from 'vue'
|
||||
import { hasInjectionContext, inject, ref, type InjectionKey, type Ref } from 'vue'
|
||||
|
||||
/** 项目配置沿用同一个抽屉,可直接定位生成配置或质量规则。 */
|
||||
export type ProjectSettingsTab = 'generation' | 'quality'
|
||||
export type ProjectSettingsTab = 'generation' | 'quality' | 'image-authorization'
|
||||
|
||||
/** 项目内共享的配置修订号,成功保存后通知已挂载的生成表单重新读取。 */
|
||||
export const projectGenerationRevisionKey: InjectionKey<Ref<number>> = Symbol('project-generation-revision')
|
||||
@@ -13,5 +13,5 @@ export const projectSettingsOpenKey: InjectionKey<(tab?: ProjectSettingsTab) =>
|
||||
* @returns 当前项目的响应式配置修订号
|
||||
*/
|
||||
export function useProjectGenerationRevision() {
|
||||
return inject(projectGenerationRevisionKey, undefined) ?? ref(0)
|
||||
return (hasInjectionContext() ? inject(projectGenerationRevisionKey, undefined) : undefined) ?? ref(0)
|
||||
}
|
||||
@@ -1,3 +1,6 @@
|
||||
import { ref, watch, type Ref } from 'vue'
|
||||
import { errorMessage } from '../../lib/http'
|
||||
import { generationConfigApi } from './api'
|
||||
import type { CreativeProfile, GenerationModelCatalog, GenerationOptions } from './types'
|
||||
|
||||
/**
|
||||
@@ -15,7 +18,10 @@ export function imageGenerationDefaults(
|
||||
} {
|
||||
const selected =
|
||||
catalog.images.find(item => item.provider === profile.imageProvider && item.enabled) ??
|
||||
catalog.images.find(item => item.enabled)
|
||||
(!profile.imageProvider
|
||||
? (catalog.images.find(item => item.provider === catalog.defaults.imageProvider && item.enabled) ??
|
||||
catalog.images.find(item => item.isDefault && item.enabled))
|
||||
: undefined)
|
||||
const options: GenerationOptions = {
|
||||
...selected?.defaults,
|
||||
...(selected?.provider === profile.imageProvider ? profile.imageOptions : {})
|
||||
@@ -25,3 +31,59 @@ export function imageGenerationDefaults(
|
||||
options.size = selected?.defaults.size ?? size.options[0]?.value ?? ''
|
||||
return { provider: selected?.provider ?? '', options }
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开原图片表单时读取项目与主体覆盖配置,迟到结果不覆盖用户选择。
|
||||
* @param open 当前生成表单开关
|
||||
* @param profile 原项目配置
|
||||
* @param targetId 正式主体编号,形态沿所属主体的覆盖配置
|
||||
* @param selectionKey 表单目标变化时重新读取默认配置
|
||||
* @returns 可编辑模型、参数及读取状态
|
||||
*/
|
||||
export function useAssetImageDefaults(
|
||||
open: Ref<boolean>,
|
||||
profile: () => CreativeProfile,
|
||||
targetId: () => string,
|
||||
selectionKey: () => string = targetId
|
||||
) {
|
||||
/** 本次显式供应方,解析完成前不提供生成资格。 */
|
||||
const provider = ref('')
|
||||
/** 服务端按项目及主体覆盖解析的参数。 */
|
||||
const generationOptions = ref<GenerationOptions>({})
|
||||
/** 原配置只读加载。 */
|
||||
const configLoading = ref(false)
|
||||
/** 配置读取失败,不回退其它供应方。 */
|
||||
const configError = ref('')
|
||||
watch(
|
||||
[open, () => profile().projectId, targetId, selectionKey],
|
||||
async ([shown], _, onCleanup) => {
|
||||
provider.value = ''
|
||||
generationOptions.value = {}
|
||||
configError.value = ''
|
||||
configLoading.value = false
|
||||
if (!shown || !targetId()) return
|
||||
const controller = new AbortController()
|
||||
onCleanup(() => controller.abort())
|
||||
configLoading.value = true
|
||||
try {
|
||||
const resolved = await generationConfigApi.resolve(
|
||||
profile().projectId,
|
||||
'image',
|
||||
{ target: { targetType: 'asset', targetId: targetId() } },
|
||||
controller.signal
|
||||
)
|
||||
if (controller.signal.aborted) return
|
||||
if (!resolved.provider || !resolved.model || !resolved.options)
|
||||
throw new Error('当前主体模型配置不完整,请重新读取。')
|
||||
provider.value = resolved.provider
|
||||
generationOptions.value = { ...resolved.options }
|
||||
} catch (cause) {
|
||||
if (!controller.signal.aborted) configError.value = errorMessage(cause)
|
||||
} finally {
|
||||
if (!controller.signal.aborted) configLoading.value = false
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
return { provider, generationOptions, configLoading, configError }
|
||||
}
|
||||
@@ -0,0 +1,350 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onScopeDispose, ref, watch } from 'vue'
|
||||
import { NButton, NCheckbox, NDatePicker, NInput, NInputNumber, NSelect, NCollapse, NCollapseItem } from 'naive-ui'
|
||||
import { useQuery } from '../../composables/useQuery'
|
||||
import { errorMessage } from '../../lib/http'
|
||||
import { useActionMessage, showActionFeedback } from '../../components/ui/useActionMessage'
|
||||
import WorkspaceSectionHeading from '../../components/ui/WorkspaceSectionHeading.vue'
|
||||
import RawDataDetails from '../../components/ui/RawDataDetails.vue'
|
||||
import { generationConfigApi } from '../generation-config/api'
|
||||
import { useProjectGenerationRevision } from '../generation-config/context'
|
||||
import { imageAuthorizationApi } from './api'
|
||||
import { formatMicros, imageRequestBlockReason, imageScopeLabels, usdToMicros } from './model'
|
||||
import type { ImageAuthorizationScope } from './types'
|
||||
|
||||
/** 原项目生成设置中的独立授权表单。 */
|
||||
const props = defineProps<{
|
||||
/** 正式项目。 */ projectId: string
|
||||
/** 上游活动锁。 */ disabled: boolean
|
||||
}>()
|
||||
/** 将写入状态交给公共抽屉。 */
|
||||
const emit = defineEmits<{ busy: [value: boolean] }>()
|
||||
/** 离开项目后不再回填提交结果。 */
|
||||
let disposed = false
|
||||
onScopeDispose(() => {
|
||||
disposed = true
|
||||
})
|
||||
/** 原项目查询身份,切换取消旧读取。 */
|
||||
const key = computed(() => props.projectId)
|
||||
/** 授权及原请求直接回读服务端。 */
|
||||
const query = useQuery(key, (id, signal) => imageAuthorizationApi.list(id, signal))
|
||||
/** 授权型号来自真实目录。 */
|
||||
const catalog = useQuery(key, (_, signal) => generationConfigApi.catalog(signal))
|
||||
/** 当前用户明确填写的授权草稿,金额、次数及时间均不预填。 */
|
||||
const draft = ref({
|
||||
models: [] as string[],
|
||||
scopes: [] as ImageAuthorizationScope[],
|
||||
targets: '',
|
||||
budget: '',
|
||||
reserve: '',
|
||||
count: null as number | null,
|
||||
expires: null as number | null,
|
||||
approvedBy: '',
|
||||
note: '',
|
||||
accepted: false
|
||||
})
|
||||
/** 原批准撤销目标。 */
|
||||
const revokeId = ref('')
|
||||
/** 实际撤销操作者及理由。 */
|
||||
const revocation = ref({ revokedBy: '', reason: '' })
|
||||
/** 同步写入的就地加载。 */
|
||||
const saving = ref(false)
|
||||
/** 同草稿失败后仍使用原幂等键,不能自动另开授权。 */
|
||||
const idempotencyKey = ref(crypto.randomUUID())
|
||||
/** 只在主动提交时显示校验消息。 */
|
||||
const validation = ref('')
|
||||
/** 正式配置变更通知,使其它已打开的预览失效。 */
|
||||
const revision = useProjectGenerationRevision()
|
||||
/** 操作消息沿用全局 NMessage。 */
|
||||
const message = useActionMessage()
|
||||
/** 仅列出真正可用的 OpenAI 型号。 */
|
||||
const modelOptions = computed(
|
||||
() =>
|
||||
catalog.data.value?.images
|
||||
.filter(item => item.provider === 'openai-image' && item.enabled && item.model)
|
||||
.map(item => ({ label: item.modelLabel || item.model!, value: item.model! })) ?? []
|
||||
)
|
||||
/** 所有范围名称与真实枚举共用。 */
|
||||
const scopeOptions = Object.entries(imageScopeLabels).map(([value, label]) => ({ label, value }))
|
||||
/** 撤销与创建各有独立提交名称。 */
|
||||
const submitLabel = computed(() => (revokeId.value ? '确认撤销授权' : '登记有限持续授权'))
|
||||
/** 读取失败时保守禁止写入,空表单允许主动校验。 */
|
||||
const canSave = computed(
|
||||
() =>
|
||||
!props.disabled &&
|
||||
!saving.value &&
|
||||
!!query.data.value &&
|
||||
!query.loading.value &&
|
||||
!query.error.value &&
|
||||
(revokeId.value !== '' || !!modelOptions.value.length)
|
||||
)
|
||||
watch(saving, value => emit('busy', value), { flush: 'sync' })
|
||||
watch(
|
||||
[draft, revocation],
|
||||
() => {
|
||||
validation.value = ''
|
||||
},
|
||||
{ deep: true }
|
||||
)
|
||||
|
||||
/** 校验后同步登记或撤销,不触发图片生成。 */
|
||||
async function save() {
|
||||
if (!canSave.value) return
|
||||
const project = props.projectId
|
||||
if (revokeId.value) {
|
||||
if (!revocation.value.revokedBy.trim() || !revocation.value.reason.trim()) {
|
||||
validation.value = '请填写撤销操作者和原因。'
|
||||
return
|
||||
}
|
||||
} else {
|
||||
const value = draft.value
|
||||
const budget = usdToMicros(value.budget),
|
||||
reserve = usdToMicros(value.reserve)
|
||||
if (
|
||||
!budget ||
|
||||
!reserve ||
|
||||
reserve > budget ||
|
||||
!Number.isInteger(value.count) ||
|
||||
!value.count ||
|
||||
value.count < 1 ||
|
||||
value.count > 10000 ||
|
||||
!value.expires ||
|
||||
value.expires <= Date.now() ||
|
||||
!value.models.length ||
|
||||
!value.scopes.length ||
|
||||
!value.approvedBy.trim() ||
|
||||
!value.note.trim() ||
|
||||
!value.accepted
|
||||
) {
|
||||
validation.value =
|
||||
'请完整填写型号、范围、正数预算、单次预留、1~10000 次、未来到期时间及批准材料,并接受浮动计费。单次预留不能超过预算,金额最多 6 位小数。'
|
||||
return
|
||||
}
|
||||
}
|
||||
saving.value = true
|
||||
try {
|
||||
if (revokeId.value) {
|
||||
await imageAuthorizationApi.revoke(project, revokeId.value, {
|
||||
revokedBy: revocation.value.revokedBy.trim(),
|
||||
reason: revocation.value.reason.trim()
|
||||
})
|
||||
if (disposed || project !== props.projectId) return
|
||||
revokeId.value = ''
|
||||
revocation.value = { revokedBy: '', reason: '' }
|
||||
showActionFeedback(message, '已撤销未来领取,原请求和历史费用保留。', 'success')
|
||||
} else {
|
||||
const value = draft.value
|
||||
await imageAuthorizationApi.create(project, {
|
||||
idempotencyKey: idempotencyKey.value,
|
||||
mode: 'standing',
|
||||
provider: 'openai-image',
|
||||
currency: 'USD',
|
||||
models: [...value.models],
|
||||
scopes: [...value.scopes],
|
||||
...(value.targets.trim()
|
||||
? { targetIds: [...new Set(value.targets.split(/[\s,,]+/).filter(Boolean))] }
|
||||
: {}),
|
||||
budgetMicros: usdToMicros(value.budget)!,
|
||||
perRequestMicros: usdToMicros(value.reserve)!,
|
||||
maxRequests: value.count!,
|
||||
expiresAt: new Date(value.expires!).toISOString(),
|
||||
acknowledgeVariableBilling: true,
|
||||
approvedBy: value.approvedBy.trim(),
|
||||
approvalNote: value.note.trim()
|
||||
})
|
||||
if (disposed || project !== props.projectId) return
|
||||
idempotencyKey.value = crypto.randomUUID()
|
||||
draft.value = {
|
||||
models: [],
|
||||
scopes: [],
|
||||
targets: '',
|
||||
budget: '',
|
||||
reserve: '',
|
||||
count: null,
|
||||
expires: null,
|
||||
approvedBy: '',
|
||||
note: '',
|
||||
accepted: false
|
||||
}
|
||||
showActionFeedback(message, '有限持续授权已登记。', 'success')
|
||||
}
|
||||
revision.value++
|
||||
await query.refresh()
|
||||
} catch (cause) {
|
||||
if (disposed || project !== props.projectId) return
|
||||
showActionFeedback(message, errorMessage(cause), 'error')
|
||||
await query.refresh()
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
/** 公共固定底栏调用当前操作。 */
|
||||
defineExpose({ save, canSave, submitLabel })
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<!-- 以下是授权余额、原请求与有限批准模块 -->
|
||||
<div class="workspace-section-stack">
|
||||
<WorkspaceSectionHeading
|
||||
title="OpenAI 图片授权"
|
||||
description="授权仅覆盖明确选择的图片范围。其他图片供应方需单独确认;视频、独立视觉审核、修复及主资产确认继续单独操作。"
|
||||
/>
|
||||
<NButton class="self-start" :loading="query.loading.value" :disabled="saving" @click="query.refresh"
|
||||
>刷新授权与请求</NButton
|
||||
>
|
||||
<p v-if="query.loading.value && !query.data.value" role="status">正在读取授权…</p>
|
||||
<p v-if="query.error.value" role="alert" class="text-sm text-muted">{{ query.error.value }}</p>
|
||||
<p v-if="query.data.value?.billingBlocked" class="surface-inset p-4 text-sm" role="status">
|
||||
原请求在途、缺少回执或用量,或用量价超过预留,已停止后续 OpenAI 收费。新增授权无法绕过,请核对下方原请求。
|
||||
</p>
|
||||
<p v-if="query.data.value && !query.data.value.authorizations.length" class="text-sm text-muted">
|
||||
暂无图片授权。
|
||||
</p>
|
||||
<article
|
||||
v-for="item in query.data.value?.authorizations ?? []"
|
||||
:key="item.id"
|
||||
class="surface-inset p-4 space-y-3 min-w-0"
|
||||
>
|
||||
<p class="font-semibold">
|
||||
{{ item.status === 'revoked' ? '已撤销' : item.expired ? '已到期' : '已批准' }} ·
|
||||
{{ item.input.models.join('、') }}
|
||||
</p>
|
||||
<p class="text-sm">
|
||||
累计预算 {{ formatMicros(item.input.budgetMicros) }} · 已记账及未结预留
|
||||
{{ formatMicros(item.accountedMicros) }} · 剩余 {{ formatMicros(item.remainingMicros) }}
|
||||
</p>
|
||||
<p class="text-sm">
|
||||
已请求 {{ item.usedRequests }} / {{ item.input.maxRequests }} 次 · 剩余 {{ item.remainingRequests }} 次
|
||||
· 单次预留 {{ formatMicros(item.input.perRequestMicros) }}
|
||||
</p>
|
||||
<p class="text-sm">
|
||||
{{ item.input.scopes.map(scope => imageScopeLabels[scope]).join('、') }} · 有效期至
|
||||
{{ new Date(item.input.expiresAt).toLocaleString('zh-CN', { hour12: false }) }}
|
||||
</p>
|
||||
<p v-if="item.billingBlocked" class="text-sm">此授权存在未核清费用。</p>
|
||||
<RawDataDetails :value="item.input" title="批准范围与材料" />
|
||||
<NButton v-if="item.status !== 'revoked'" :disabled="saving || disabled" @click="revokeId = item.id"
|
||||
>撤销此授权</NButton
|
||||
>
|
||||
</article>
|
||||
<!-- 以下是保留全部状态的原生成请求及费用模块 -->
|
||||
<NCollapse v-if="query.data.value?.requests.length">
|
||||
<NCollapseItem name="requests" title="原生成请求与费用状态">
|
||||
<article
|
||||
v-for="item in query.data.value.requests"
|
||||
:key="item.id"
|
||||
class="mb-4 surface-inset p-4 space-y-2 min-w-0"
|
||||
>
|
||||
<p class="text-sm font-semibold">
|
||||
{{
|
||||
item.status === 'completed'
|
||||
? '图片回执完整,质量另行审核'
|
||||
: item.status === 'running'
|
||||
? '已领取发送资格,禁止重发'
|
||||
: '结果或费用未知,禁止重试'
|
||||
}}
|
||||
</p>
|
||||
<p class="wrap-anywhere text-xs">
|
||||
{{ item.id }} · {{ imageScopeLabels[item.input.scope] }} · {{ item.input.targetId }}
|
||||
</p>
|
||||
<p class="text-sm">
|
||||
原预留 {{ formatMicros(item.input.reservedMicros) }} · 公开用量价
|
||||
{{ formatMicros(item.output?.usageCostMicros) }} ·
|
||||
{{
|
||||
item.output?.actualBilledMicros == null
|
||||
? '账单未核实'
|
||||
: `实际账单 ${formatMicros(item.output.actualBilledMicros)}`
|
||||
}}
|
||||
</p>
|
||||
<p v-if="query.data.value.blockingRequestIds.includes(item.id)" class="text-sm">
|
||||
{{ imageRequestBlockReason(item) }} 完整同计划回执仍可免费复用。
|
||||
</p>
|
||||
<RawDataDetails :value="item" title="原请求、来源及回执详情" />
|
||||
</article>
|
||||
</NCollapseItem>
|
||||
</NCollapse>
|
||||
<!-- 以下是独立撤销表单,底栏明确提交 -->
|
||||
<section v-if="revokeId" class="workspace-section-stack">
|
||||
<WorkspaceSectionHeading
|
||||
title="撤销未来领取"
|
||||
description="已领取请求可能已经发送。撤销不会取消、退款或删除原请求。"
|
||||
/>
|
||||
<p class="wrap-anywhere text-xs">{{ revokeId }}</p>
|
||||
<label class="workspace-form-field"
|
||||
><span>撤销操作者</span
|
||||
><NInput v-model:value="revocation.revokedBy" :maxlength="200" :disabled="saving"
|
||||
/></label>
|
||||
<label class="workspace-form-field"
|
||||
><span>撤销原因</span
|
||||
><NInput v-model:value="revocation.reason" type="textarea" :maxlength="2000" :disabled="saving"
|
||||
/></label>
|
||||
<NButton :disabled="saving" @click="revokeId = ''">返回创建授权</NButton>
|
||||
</section>
|
||||
<!-- 以下是用户明确填写的有限持续授权,不预填金额、次数及日期 -->
|
||||
<section v-else class="workspace-section-stack">
|
||||
<WorkspaceSectionHeading
|
||||
title="创建有限持续授权"
|
||||
description="单次预留金额不是供应方实际账单的硬上限。按实际 Token 浮动计费,实际费用可能超过预留。超预留、缺回执或用量时将停止后续收费。"
|
||||
/>
|
||||
<div class="grid grid-cols-1 gap-(--app-field-gap) sm:grid-cols-2">
|
||||
<div class="workspace-form-field">
|
||||
<span>授权型号</span
|
||||
><NSelect
|
||||
aria-label="授权型号"
|
||||
v-model:value="draft.models"
|
||||
multiple
|
||||
:options="modelOptions"
|
||||
:disabled="saving"
|
||||
placeholder="选择明确批准的型号"
|
||||
/>
|
||||
</div>
|
||||
<div class="workspace-form-field">
|
||||
<span>授权范围</span
|
||||
><NSelect
|
||||
aria-label="授权范围"
|
||||
v-model:value="draft.scopes"
|
||||
multiple
|
||||
:options="scopeOptions"
|
||||
:disabled="saving"
|
||||
placeholder="选择图片范围"
|
||||
/>
|
||||
</div>
|
||||
<label class="workspace-form-field"
|
||||
><span>累计预算(USD)</span
|
||||
><NInput v-model:value="draft.budget" :disabled="saving" placeholder="填写累计准入预算"
|
||||
/></label>
|
||||
<label class="workspace-form-field"
|
||||
><span>单次预留(USD)</span
|
||||
><NInput v-model:value="draft.reserve" :disabled="saving" placeholder="填写每次发送前的预留"
|
||||
/></label>
|
||||
<label class="workspace-form-field"
|
||||
><span>累计请求次数</span
|
||||
><NInputNumber v-model:value="draft.count" :min="1" :max="10000" :precision="0" :disabled="saving"
|
||||
/></label>
|
||||
<label class="workspace-form-field"
|
||||
><span>到期时间</span
|
||||
><NDatePicker v-model:value="draft.expires" type="datetime" clearable :disabled="saving"
|
||||
/></label>
|
||||
</div>
|
||||
<label class="workspace-form-field"
|
||||
><span>目标编号限制(可选)</span
|
||||
><NInput
|
||||
v-model:value="draft.targets"
|
||||
type="textarea"
|
||||
:disabled="saving"
|
||||
placeholder="留空覆盖所选范围;填写正式主体、形态、镜头或布局编号,以逗号或换行分隔"
|
||||
/></label>
|
||||
<label class="workspace-form-field"
|
||||
><span>批准人</span><NInput v-model:value="draft.approvedBy" :maxlength="200" :disabled="saving"
|
||||
/></label>
|
||||
<label class="workspace-form-field"
|
||||
><span>批准说明</span
|
||||
><NInput v-model:value="draft.note" type="textarea" :maxlength="2000" :disabled="saving"
|
||||
/></label>
|
||||
<NCheckbox v-model:checked="draft.accepted" :disabled="saving"
|
||||
>我接受按 Token 浮动计费,单次实际账单可能超过预留;有效范围内后续图片不再逐张确认收费。</NCheckbox
|
||||
>
|
||||
</section>
|
||||
<p v-if="validation" role="alert" class="text-sm">{{ validation }}</p>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,56 @@
|
||||
import { request } from '../../lib/http'
|
||||
import type {
|
||||
ImageAuthorizationInput,
|
||||
ImageAuthorizationList,
|
||||
ImageAuthorizationPreview,
|
||||
ImageAuthorizationPreviewInput
|
||||
} from './types'
|
||||
|
||||
/**
|
||||
* 构造原项目授权地址。
|
||||
* @param projectId 正式项目
|
||||
* @returns 授权资源路径
|
||||
*/
|
||||
function root(projectId: string) {
|
||||
return `/projects/${encodeURIComponent(projectId)}/image-authorizations`
|
||||
}
|
||||
|
||||
/** 图片授权同步接口,不创建生成任务或新的事件流。 */
|
||||
export const imageAuthorizationApi = {
|
||||
/**
|
||||
* 读取余额、原请求及未知阻断。
|
||||
* @param projectId 正式项目
|
||||
* @param signal 取消旧项目读取
|
||||
* @returns 原授权投影
|
||||
*/
|
||||
list: (projectId: string, signal?: AbortSignal) => request<ImageAuthorizationList>(root(projectId), { signal }),
|
||||
/**
|
||||
* 免费编译精确费用计划,不替换原图片预览。
|
||||
* @param projectId 正式项目
|
||||
* @param input 原编译参数
|
||||
* @param signal 取消旧读取
|
||||
* @returns 精确计划及余额
|
||||
*/
|
||||
preview: (projectId: string, input: ImageAuthorizationPreviewInput, signal?: AbortSignal) =>
|
||||
request<ImageAuthorizationPreview>(root(projectId) + '/preview', { method: 'POST', body: input, signal }),
|
||||
/**
|
||||
* 登记用户明确填写的有限授权。
|
||||
* @param projectId 正式项目
|
||||
* @param input 本次不可变批准
|
||||
* @returns 原授权标识及状态
|
||||
*/
|
||||
create: (projectId: string, input: ImageAuthorizationInput) =>
|
||||
request<{ authorizationId: string; status: string }>(root(projectId), { method: 'POST', body: input }),
|
||||
/**
|
||||
* 撤销未来领取并保留原件。
|
||||
* @param projectId 正式项目
|
||||
* @param authorizationId 原批准
|
||||
* @param input 操作者和原因
|
||||
* @returns 撤销凭据
|
||||
*/
|
||||
revoke: (projectId: string, authorizationId: string, input: { revokedBy: string; reason: string }) =>
|
||||
request<{ authorizationId: string; status: 'revoked' }>(
|
||||
`${root(projectId)}/${encodeURIComponent(authorizationId)}/revoke`,
|
||||
{ method: 'POST', body: input }
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
import { billingErrorText } from '../../lib/billing-errors'
|
||||
import type { ImageAuthorizationList, ImageAuthorizationScope, ImageChargeRequest } from './types'
|
||||
|
||||
/** 所有范围共用中文名称,原枚举提交不变。 */
|
||||
export const imageScopeLabels: Record<ImageAuthorizationScope, string> = {
|
||||
identity: '主体身份图片',
|
||||
form: '形态图片',
|
||||
keyframe: '镜头首帧',
|
||||
layout: '布局母版',
|
||||
keyframe_evidence: '首帧证据图片'
|
||||
}
|
||||
|
||||
/**
|
||||
* 以十进制字符串精确换算微美元,拒绝超精度及非正金额。
|
||||
* @param value 用户填写的美元
|
||||
* @returns 整数微美元,无效时为 null
|
||||
*/
|
||||
export function usdToMicros(value: string): number | null {
|
||||
if (!/^\d+(\.\d{1,6})?$/.test(value.trim())) return null
|
||||
const [whole = '', fraction = ''] = value.trim().split('.')
|
||||
const micros = Number(whole) * 1_000_000 + Number(fraction.padEnd(6, '0'))
|
||||
return Number.isSafeInteger(micros) && micros > 0 && micros <= 1_000_000_000_000 ? micros : null
|
||||
}
|
||||
|
||||
/**
|
||||
* 未知金额保持未知,公开用量价与实际账单分别标注。
|
||||
* @param value 微美元或未知
|
||||
* @returns 美元显示值
|
||||
*/
|
||||
export function formatMicros(value: number | null | undefined): string {
|
||||
return value === null || value === undefined
|
||||
? '未知'
|
||||
: `USD ${(value / 1_000_000).toFixed(6).replace(/0+$/, '').replace(/\.$/, '')}`
|
||||
}
|
||||
|
||||
/**
|
||||
* 按当前精确范围查询准入资格,最终领取仍由服务端事务裁决。
|
||||
* @param list 当前项目投影
|
||||
* @param scope 实际生成范围
|
||||
* @param targetId 实际目标
|
||||
* @param model 实际预览型号
|
||||
* @param planFingerprint 免费计划返回的指纹,仅普通计划可提供
|
||||
* @returns 可复用、已授权或阻断说明
|
||||
*/
|
||||
export function imageChargeEligibility(
|
||||
list: ImageAuthorizationList,
|
||||
scope: ImageAuthorizationScope,
|
||||
targetId: string,
|
||||
model: string,
|
||||
planFingerprint?: string
|
||||
) {
|
||||
const reusable = list.requests.find(
|
||||
row =>
|
||||
!!planFingerprint &&
|
||||
row.input.planFingerprint === planFingerprint &&
|
||||
row.input.scope === scope &&
|
||||
row.input.targetId === targetId &&
|
||||
row.input.model === model &&
|
||||
row.status === 'completed' &&
|
||||
row.output?.result
|
||||
)
|
||||
if (reusable)
|
||||
return {
|
||||
allowed: true,
|
||||
reusable: true,
|
||||
message: '同计划完整回执可免费复用,不新增请求次数;图片质量仍按原审核结果。'
|
||||
}
|
||||
if (list.billingBlocked)
|
||||
return {
|
||||
allowed: false,
|
||||
reusable: false,
|
||||
message: '原图片请求在途或费用未核清,已停止新增收费。请在项目生成设置查看原请求。'
|
||||
}
|
||||
const matching = list.authorizations.filter(
|
||||
row =>
|
||||
row.status === 'approved' &&
|
||||
!row.expired &&
|
||||
Date.parse(row.input.expiresAt) > Date.now() &&
|
||||
row.input.models.includes(model) &&
|
||||
row.input.scopes.includes(scope) &&
|
||||
(!row.input.targetIds || row.input.targetIds.includes(targetId)) &&
|
||||
(row.input.mode === 'standing' || row.input.planFingerprint === planFingerprint)
|
||||
)
|
||||
const grant = matching.find(
|
||||
row => !row.billingBlocked && row.remainingRequests > 0 && row.remainingMicros >= row.input.perRequestMicros
|
||||
)
|
||||
return grant
|
||||
? {
|
||||
allowed: true,
|
||||
reusable: false,
|
||||
message: `本次使用已批准的 OpenAI 图片授权,剩余 ${formatMicros(grant.remainingMicros)},可请求 ${grant.remainingRequests} 次。最终额度以提交时核验为准。`
|
||||
}
|
||||
: {
|
||||
allowed: false,
|
||||
reusable: false,
|
||||
message: matching.length
|
||||
? '授权剩余预算不足整次预留,或请求次数已用尽。请核对项目生成设置。'
|
||||
: '缺少当前模型和范围的有效授权,或授权已到期、撤销。请先在项目生成设置登记。'
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从原状态和回执给出具体费用阻断原因,未知费用不推断为零。
|
||||
* @param request 原始图片请求
|
||||
* @returns 当前需要核对的业务原因
|
||||
*/
|
||||
export function imageRequestBlockReason(request: ImageChargeRequest): string {
|
||||
if (request.status === 'running') return '原请求已领取发送资格,结果与费用尚未确认,禁止重发。'
|
||||
if (request.status !== 'completed') {
|
||||
return (
|
||||
billingErrorText('OPENAI_IMAGE_PROVIDER_ERROR', request.output?.error) ?? '原请求结果或费用未知,禁止重试。'
|
||||
)
|
||||
}
|
||||
const usageCost = request.output?.usageCostMicros
|
||||
if (usageCost === null || usageCost === undefined) return '已收到图片,但缺少可核验的用量,后续收费暂停。'
|
||||
if (usageCost > request.input.reservedMicros) return '公开用量价超过单次预留,后续收费暂停。'
|
||||
return ''
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/** 图片持续授权的业务范围。 */
|
||||
export type ImageAuthorizationScope = 'identity' | 'form' | 'keyframe' | 'layout' | 'keyframe_evidence'
|
||||
|
||||
/** 用户明确批准的有限持续授权。 */
|
||||
export interface ImageAuthorizationInput {
|
||||
/** 本次批准的幂等标识。 */ idempotencyKey: string
|
||||
/** 批准方式。 */ mode: 'standing' | 'single'
|
||||
/** 固定供应方。 */ provider: 'openai-image'
|
||||
/** 明确批准的型号。 */ models: string[]
|
||||
/** 明确批准的范围。 */ scopes: ImageAuthorizationScope[]
|
||||
/** 可选的目标限制。 */ targetIds?: string[]
|
||||
/** 固定美元币种。 */ currency: 'USD'
|
||||
/** 累计预算微美元。 */ budgetMicros: number
|
||||
/** 单次预留微美元。 */ perRequestMicros: number
|
||||
/** 累计次数上限。 */ maxRequests: number
|
||||
/** 到期时间。 */ expiresAt: string
|
||||
/** 单次授权绑定的精确计划。 */ planFingerprint?: string
|
||||
/** 明确接受浮动计费。 */ acknowledgeVariableBilling: true
|
||||
/** 实际批准人。 */ approvedBy: string
|
||||
/** 批准说明。 */ approvalNote: string
|
||||
}
|
||||
|
||||
/** 原始图片请求与费用回执。 */
|
||||
export interface ImageChargeRequest {
|
||||
/** 原请求标识。 */ id: string
|
||||
/** 原执行状态。 */ status: string
|
||||
/** 不可变原输入。 */ input: {
|
||||
/** 原项目。 */ projectId: string
|
||||
/** 原范围。 */ scope: ImageAuthorizationScope
|
||||
/** 原目标。 */ targetId: string
|
||||
/** 原候选。 */ candidateId: string
|
||||
/** 原授权。 */ authorizationId: string
|
||||
/** 原供应方。 */ provider: string
|
||||
/** 原型号。 */ model: string
|
||||
/** 原来源摘要。 */ sourceFingerprint: string
|
||||
/** 原精确计划摘要。 */ planFingerprint: string
|
||||
/** 原预留微美元。 */ reservedMicros: number
|
||||
/** 完整实际请求,可能含图片数据。 */ request: unknown
|
||||
}
|
||||
/** 原回执或未知费用。 */ output: {
|
||||
/** 原回执公开用量价。 */ usageCostMicros: number | null
|
||||
/** 实际账单尚未核验。 */ actualBilledMicros: number | null
|
||||
/** 完整回执。 */ result?: unknown
|
||||
/** 原结构化错误。 */ error?: unknown
|
||||
} | null
|
||||
}
|
||||
|
||||
/** 项目授权余额与原请求。 */
|
||||
export interface ImageAuthorizationList {
|
||||
/** 服务端计算的授权投影。 */ authorizations: Array<{
|
||||
/** 原批准记录。 */ id: string
|
||||
/** 原批准状态。 */ status: string
|
||||
/** 原批准内容。 */ input: ImageAuthorizationInput
|
||||
/** 实时到期状态。 */ expired: boolean
|
||||
/** 累计发送次数。 */ usedRequests: number
|
||||
/** 剩余发送次数。 */ remainingRequests: number
|
||||
/** 用量价及未结预留合计。 */ accountedMicros: number
|
||||
/** 剩余准入预算。 */ remainingMicros: number
|
||||
/** 此授权有未结费用。 */ billingBlocked: boolean
|
||||
}>
|
||||
/** 原请求记录。 */ requests: ImageChargeRequest[]
|
||||
/** 项目后续收费阻断。 */ billingBlocked: boolean
|
||||
/** 阻断请求编号。 */ blockingRequestIds: string[]
|
||||
}
|
||||
|
||||
/** 免费授权计划仅接受普通正式编译参数。 */
|
||||
export interface ImageAuthorizationPreviewInput {
|
||||
/** 普通图片范围。 */ scope: 'identity' | 'form' | 'keyframe'
|
||||
/** 正式目标。 */ targetId: string
|
||||
/** 显式供应方。 */ providerName?: string
|
||||
/** 正式模型参数。 */ generationOptions?: Record<string, unknown>
|
||||
/** 可选宽度。 */ width?: number
|
||||
/** 可选高度。 */ height?: number
|
||||
}
|
||||
|
||||
/** 服务端编译的免费精确授权计划。 */
|
||||
export interface ImageAuthorizationPreview {
|
||||
/** 原供应方。 */ provider: string
|
||||
/** 实际型号。 */ model: string
|
||||
/** 原目标及来源。 */ context: {
|
||||
/** 原项目。 */ projectId: string
|
||||
/** 原业务范围。 */ scope: ImageAuthorizationScope
|
||||
/** 原目标。 */ targetId: string
|
||||
/** 原来源。 */ sourceFingerprint: string
|
||||
}
|
||||
/** 精确费用计划,与图片预览指纹用途不同。 */ planFingerprint: string
|
||||
/** 实际请求,禁止输出浏览器日志。 */ request: unknown
|
||||
/** 币种。 */ currency: 'USD'
|
||||
/** 按用量记账。 */ billingBasis: 'provider_usage'
|
||||
/** 不承诺实际账单硬上限。 */ hardProviderCostCap: false
|
||||
/** 当前授权与费用状态。 */ authorization: ImageAuthorizationList
|
||||
}
|
||||
@@ -51,10 +51,15 @@ const directionSummary = computed(() =>
|
||||
.join(' · ')
|
||||
: ''
|
||||
)
|
||||
/** 本次目录与模型参数仅用于首帧。 */
|
||||
const generationCatalog = ref<GenerationModelCatalog | null>(null)
|
||||
/** 模型读取错误。 */
|
||||
const generationCatalogError = ref('')
|
||||
/** 实际项目及镜头配置解析后的模型。 */
|
||||
const imageProvider = ref('')
|
||||
/** 本次明确参数。 */
|
||||
const imageGenerationOptions = ref<GenerationOptions>({})
|
||||
/** 项目画幅。 */
|
||||
const projectAspectRatio = ref<CreativeProfileAspectRatio>('9:16')
|
||||
/** 预览和生成复用当前请求字段,生成时再附加版本及候选标记。 */
|
||||
const generationInput = computed(() => ({
|
||||
@@ -65,6 +70,8 @@ const generationInput = computed(() => ({
|
||||
const {
|
||||
preview,
|
||||
acknowledged,
|
||||
requiresCostConfirmation,
|
||||
chargeNotice,
|
||||
loading,
|
||||
submitting,
|
||||
error,
|
||||
@@ -75,6 +82,12 @@ const {
|
||||
submit: submitPreview
|
||||
} = useImageGenerationPreview({
|
||||
open,
|
||||
chargeContext: () => ({
|
||||
projectId: props.projectId,
|
||||
scope: 'keyframe',
|
||||
targetId: props.shotId,
|
||||
exactPreview: true
|
||||
}),
|
||||
recoveryTarget: () => (props.shotId ? 'keyframe:' + props.shotId : ''),
|
||||
previousCandidateIds: () => props.previousCandidateIds,
|
||||
target: () => JSON.stringify([props.shotId, props.direction, props.visualState]),
|
||||
@@ -106,16 +119,26 @@ watch(
|
||||
generationCatalogError.value = ''
|
||||
imageProvider.value = ''
|
||||
try {
|
||||
const [catalog, profile] = await Promise.all([
|
||||
const [catalog, profile, resolved] = await Promise.all([
|
||||
generationConfigApi.catalog(controller.signal),
|
||||
generationConfigApi.profile(projectId, controller.signal)
|
||||
generationConfigApi.profile(projectId, controller.signal),
|
||||
generationConfigApi.resolve(
|
||||
projectId,
|
||||
'image',
|
||||
{
|
||||
target: { targetType: 'shot', targetId: props.shotId }
|
||||
},
|
||||
controller.signal
|
||||
)
|
||||
])
|
||||
if (controller.signal.aborted) return
|
||||
if (!resolved.provider || !resolved.model || !resolved.options)
|
||||
throw new Error('当前镜头模型配置不完整,请重新读取。')
|
||||
generationCatalog.value = catalog
|
||||
projectAspectRatio.value = profile?.aspectRatio ?? '9:16'
|
||||
imageProvider.value = profile?.imageProvider || catalog.defaults.imageProvider
|
||||
imageProvider.value = resolved.provider
|
||||
const selected = catalog.images.find(item => item.provider === imageProvider.value)
|
||||
imageGenerationOptions.value = { ...selected?.defaults, ...profile?.imageOptions }
|
||||
imageGenerationOptions.value = { ...selected?.defaults, ...resolved.options }
|
||||
} catch (cause) {
|
||||
if (!controller.signal.aborted) generationCatalogError.value = errorMessage(cause)
|
||||
}
|
||||
@@ -209,7 +232,9 @@ watch(
|
||||
/>
|
||||
<!-- 以下是正式画幅、尺寸及连续性诊断 -->
|
||||
<KeyframePreviewChecks v-if="preview" :preview="preview" class="mt-3" />
|
||||
<p v-if="chargeNotice" class="text-sm text-muted" role="status">{{ chargeNotice }}</p>
|
||||
<NCheckbox
|
||||
v-if="requiresCostConfirmation"
|
||||
id="confirm-keyframe-cost"
|
||||
v-model:checked="acknowledged"
|
||||
:disabled="!preview || preview.specConsistencySummary?.blocking || submitting || !!recoveryNotice"
|
||||
|
||||
@@ -8,7 +8,7 @@ import ContextNotice from '../../../components/ui/ContextNotice.vue'
|
||||
import IssueHint from '../../../components/ui/IssueHint.vue'
|
||||
import { useActionMessage } from '../../../components/ui/useActionMessage'
|
||||
import ProviderInputInspector from './ProviderInputInspector.vue'
|
||||
import { NButton, NCheckbox, NCollapse, NCollapseItem, NSelect, NTag } from 'naive-ui'
|
||||
import { NButton, NCheckbox, NCollapse, NCollapseItem, NSelect, NTag, NTabs, NTabPane } from 'naive-ui'
|
||||
import { computed, onScopeDispose, ref, watch } from 'vue'
|
||||
import { ImagePlus, RefreshCw } from '@lucide/vue'
|
||||
import { AssetImage } from '../../../components/ui'
|
||||
@@ -43,9 +43,10 @@ import KeyframeCard from './KeyframeCard.vue'
|
||||
import VideoCard from './VideoCard.vue'
|
||||
import ProductionStageStatus from './ProductionStageStatus.vue'
|
||||
import QualityDialog from './QualityDialog.vue'
|
||||
import VideoAuditPanel from './VideoAuditPanel.vue'
|
||||
import VideoQualityDiagnostics from './VideoQualityDiagnostics.vue'
|
||||
import KeyframeValidationHistory from './KeyframeValidationHistory.vue'
|
||||
import { AppDialog } from '../../../components/ui'
|
||||
import { AppDialog, AppDrawer } from '../../../components/ui'
|
||||
import ModelCapabilities from './ModelCapabilities.vue'
|
||||
import type { QualityTarget } from '../quality.types'
|
||||
import KeyframeInputDetails from './KeyframeInputDetails.vue'
|
||||
@@ -253,6 +254,12 @@ const candidatesOpen = ref(false)
|
||||
const videoCandidatesOpen = ref(false)
|
||||
/** 仅点击视频卡片入口后显示已有质量记录。 */
|
||||
const videoHistoryOpen = ref(false)
|
||||
/** 费用审计和原质量共用视频详情,独立标签与固定底栏。 */
|
||||
const videoHistoryTab = ref('quality')
|
||||
/** 费用事务提交期间锁住关闭及切换。 */
|
||||
const videoAuditBusy = ref(false)
|
||||
/** 固定底栏调用当前原任务表单。 */
|
||||
const videoAuditForm = ref<InstanceType<typeof VideoAuditPanel> | null>(null)
|
||||
/** 当前查看记录的视频 ID,按资产隔离主视频和候选。 */
|
||||
const videoHistoryId = ref('')
|
||||
/** 历史弹窗按用户选择的候选独立判断过期,不套用主视频结论。 */
|
||||
@@ -331,9 +338,11 @@ function openQuality(kind: 'keyframe' | 'video', assetId: string, repair = false
|
||||
/**
|
||||
* 从主视频或候选卡片打开只读记录,关闭候选弹窗以避免弹窗叠加。
|
||||
* @param videoId 当前选中视频 ID
|
||||
* @param tab 本次打开的记录分类
|
||||
*/
|
||||
function openVideoHistory(videoId: string) {
|
||||
function openVideoHistory(videoId: string, tab: 'quality' | 'audit' = 'quality') {
|
||||
videoCandidatesOpen.value = false
|
||||
videoHistoryTab.value = tab
|
||||
videoHistoryId.value = videoId
|
||||
videoHistoryOpen.value = true
|
||||
}
|
||||
@@ -868,6 +877,7 @@ defineExpose({ inspectSpecs, inspecting })
|
||||
@quality="openQuality('video', currentVideo.id)"
|
||||
@repair="openQuality('video', currentVideo.id, true)"
|
||||
@history="openVideoHistory(currentVideo.id)"
|
||||
@audit="openVideoHistory(currentVideo.id, 'audit')"
|
||||
/>
|
||||
</div>
|
||||
<p v-else class="mt-4 text-xs text-muted">
|
||||
@@ -1156,6 +1166,7 @@ defineExpose({ inspectSpecs, inspecting })
|
||||
@quality="openQuality('video', item.id)"
|
||||
@repair="openQuality('video', item.id, true)"
|
||||
@history="openVideoHistory(item.id)"
|
||||
@audit="openVideoHistory(item.id, 'audit')"
|
||||
@select="confirmingVideo = item.id"
|
||||
@confirm="setPrimaryVideo"
|
||||
@cancel="confirmingVideo = ''"
|
||||
@@ -1164,16 +1175,44 @@ defineExpose({ inspectSpecs, inspecting })
|
||||
<p v-else class="text-xs text-muted">暂无其它视频候选。</p>
|
||||
</AppDialog>
|
||||
<!-- 以下是指定视频质量记录弹窗模块,打开后直接展示结果与修改建议 -->
|
||||
<AppDialog v-model:open="videoHistoryOpen" title="视频质量记录" description="免费查看视频检查记录。" wide>
|
||||
<VideoQualityDiagnostics
|
||||
v-if="videoHistoryOpen && videoHistoryId"
|
||||
:key="`${shot.shotId}:${videoHistoryId}`"
|
||||
:shot-id="shot.shotId"
|
||||
:video-id="videoHistoryId"
|
||||
:stale="videoHistoryStale"
|
||||
:stale-reason="videoHistoryId === currentVideo?.id ? videoStaleReason : videoHistoryAsset?.staleReason"
|
||||
/>
|
||||
</AppDialog>
|
||||
<AppDrawer v-model:open="videoHistoryOpen" title="视频记录" :busy="videoAuditBusy">
|
||||
<NTabs v-if="videoHistoryOpen && videoHistoryId" v-model:value="videoHistoryTab" type="line">
|
||||
<NTabPane name="quality" tab="视频质量" :disabled="videoAuditBusy" display-directive="show:lazy">
|
||||
<VideoQualityDiagnostics
|
||||
:key="`${shot.shotId}:${videoHistoryId}:${reviewRevision}`"
|
||||
:shot-id="shot.shotId"
|
||||
:video-id="videoHistoryId"
|
||||
:stale="videoHistoryStale"
|
||||
:stale-reason="
|
||||
videoHistoryId === currentVideo?.id ? videoStaleReason : videoHistoryAsset?.staleReason
|
||||
"
|
||||
/>
|
||||
</NTabPane>
|
||||
<NTabPane name="audit" tab="费用审计" :disabled="videoAuditBusy" display-directive="show:lazy">
|
||||
<VideoAuditPanel
|
||||
ref="videoAuditForm"
|
||||
:key="`${shot.shotId}:${videoHistoryId}`"
|
||||
:project-id="projectId"
|
||||
:shot-id="shot.shotId"
|
||||
:video-id="videoHistoryId"
|
||||
:disabled="disabled"
|
||||
@busy="videoAuditBusy = $event"
|
||||
@changed="refreshAfterReview"
|
||||
/>
|
||||
</NTabPane>
|
||||
</NTabs>
|
||||
<template #footer>
|
||||
<NButton :disabled="videoAuditBusy" @click="videoHistoryOpen = false">关闭</NButton>
|
||||
<NButton
|
||||
v-if="videoHistoryTab === 'audit' && videoAuditForm"
|
||||
type="primary"
|
||||
:disabled="!videoAuditForm.canSubmit"
|
||||
:loading="videoAuditBusy"
|
||||
@click="videoAuditForm.submit()"
|
||||
>{{ videoAuditForm.submitLabel }}</NButton
|
||||
>
|
||||
</template>
|
||||
</AppDrawer>
|
||||
<AppDialog v-model:open="historyOpen" title="首帧记录" :busy="historyAuthorizationPending" wide>
|
||||
<div v-if="historyOpen && historyKeyframeId" :key="historyKeyframeId" class="workspace-section-stack">
|
||||
<!-- 以下是按需读取的候选生成证据 -->
|
||||
|
||||
@@ -0,0 +1,447 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, watch } from 'vue'
|
||||
import { NButton, NCheckbox, NCollapse, NCollapseItem, NInput, NInputNumber, NSelect } from 'naive-ui'
|
||||
import { Trash2 } from '@lucide/vue'
|
||||
import RawDataDetails from '../../../components/ui/RawDataDetails.vue'
|
||||
import WorkspaceActionTooltip from '../../../components/ui/WorkspaceActionTooltip.vue'
|
||||
import WorkspaceSectionHeading from '../../../components/ui/WorkspaceSectionHeading.vue'
|
||||
import { formatDate } from '../../../lib/format'
|
||||
import { useVideoAudit } from '../useVideoAudit'
|
||||
import {
|
||||
auditArtifactLabels,
|
||||
auditFindingLabels,
|
||||
auditOutcomeLabels,
|
||||
auditStatusLabels,
|
||||
auditRequestStatusLabels,
|
||||
auditStepLabels
|
||||
} from '../video-audit'
|
||||
|
||||
/** 在原视频详情中处理原质检任务费用,不修改质量。 */
|
||||
const props = defineProps<{
|
||||
/** 原项目。 */ projectId: string
|
||||
/** 原镜头。 */ shotId: string
|
||||
/** 原候选。 */ videoId: string
|
||||
/** 活动写入锁。 */ disabled?: boolean
|
||||
}>()
|
||||
/** 原数据写入后刷新当前视频列表与质量。 */
|
||||
const emit = defineEmits<{ changed: []; busy: [value: boolean] }>()
|
||||
/** 整个表单复用既有请求与取消机制。 */
|
||||
const form = useVideoAudit(props, () => emit('changed'))
|
||||
/** 当前原审计,费用与质量各自显示。 */
|
||||
const audit = computed(() => form.query.data.value?.audit)
|
||||
/** 原任务质量和费用保持原输出。 */
|
||||
const original = computed(() => form.query.data.value?.original)
|
||||
/** 真实步骤选项。 */
|
||||
const stepOptions = computed(
|
||||
() =>
|
||||
audit.value?.steps.map(step => ({ label: auditStepLabels[step.name] ?? '原请求阶段', value: step.name })) ?? []
|
||||
)
|
||||
/** 证据包选项只来自当前步骤服务端记录。 */
|
||||
const evidenceOptions = computed(
|
||||
() =>
|
||||
form.step.value?.evidence.map(row => ({
|
||||
label: `${row.body.operator} · ${formatDate(row.createdAt)} · ${row.id}`,
|
||||
value: row.id
|
||||
})) ?? []
|
||||
)
|
||||
/** 下拉选项保留实际枚举值。 */
|
||||
const artifactKinds = Object.entries(auditArtifactLabels).map(([value, label]) => ({ value, label }))
|
||||
/** 执行结果选项。 */
|
||||
const outcomeOptions = Object.entries(auditOutcomeLabels).map(([value, label]) => ({ value, label }))
|
||||
/** 费用结果选项。 */
|
||||
const findingOptions = Object.entries(auditFindingLabels).map(([value, label]) => ({ value, label }))
|
||||
watch(form.saving, value => emit('busy', value), { flush: 'sync' })
|
||||
/** 主操作由原抽屉固定 footer 提供。 */
|
||||
defineExpose({ canSubmit: form.canSubmit, saving: form.saving, submit: form.submit, submitLabel: form.submitLabel })
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<!-- 以下是正式原任务发现与手动只读查询模块 -->
|
||||
<div class="workspace-section-stack min-w-0">
|
||||
<WorkspaceSectionHeading
|
||||
title="视频费用审计"
|
||||
description="登记原件后仍需独立人工复核。费用核清仅影响未来收费门禁,视频质量、版本与主视频资格继续按原记录核对。"
|
||||
/>
|
||||
<p v-if="form.discovery.loading.value" role="status" class="text-sm">正在读取原质检任务…</p>
|
||||
<p v-if="form.discovery.data.value?.notice" class="text-sm text-muted">
|
||||
{{ form.discovery.data.value.notice }}
|
||||
</p>
|
||||
<div v-if="form.discovery.data.value?.rows.length" class="workspace-form-field">
|
||||
<span>原质检历史任务</span
|
||||
><NSelect
|
||||
aria-label="原质检历史任务"
|
||||
v-model:value="form.taskId.value"
|
||||
:disabled="form.saving.value"
|
||||
:options="
|
||||
form.discovery.data.value.rows.map(row => ({
|
||||
label: `${row.taskStatus === 'failed' ? '原执行失败' : row.taskStatus === 'completed' ? '原执行完成' : '原执行状态待核对'} · ${row.taskId}`,
|
||||
value: row.taskId
|
||||
}))
|
||||
"
|
||||
/>
|
||||
</div>
|
||||
<div class="flex items-end gap-3">
|
||||
<label class="workspace-form-field min-w-0 flex-1"
|
||||
><span>按原任务编号查询</span
|
||||
><NInput
|
||||
v-model:value="form.taskInput.value"
|
||||
:disabled="form.saving.value"
|
||||
placeholder="填写历史质检任务编号,不能填写供应方请求号"
|
||||
@keyup.enter="form.lookup"
|
||||
/></label>
|
||||
<NButton :disabled="form.saving.value || !form.taskInput.value.trim()" @click="form.lookup">读取</NButton>
|
||||
</div>
|
||||
<NButton
|
||||
class="self-start"
|
||||
v-if="form.taskId.value"
|
||||
:loading="form.query.loading.value"
|
||||
:disabled="form.saving.value"
|
||||
@click="form.refresh"
|
||||
>刷新原任务与审计</NButton
|
||||
>
|
||||
<p v-if="form.query.error.value" role="alert" class="text-sm">{{ form.query.error.value }}</p>
|
||||
<p v-if="form.query.loading.value && !audit" role="status" class="text-sm">正在读取费用审计…</p>
|
||||
<template v-if="audit && original">
|
||||
<!-- 以下是费用及原质量互相独立的摘要模块 -->
|
||||
<section class="surface-inset p-4 space-y-3 min-w-0">
|
||||
<p class="font-semibold">{{ audit.billingBlocked ? '当前任务费用仍阻断' : '当前任务无费用阻断' }}</p>
|
||||
<p class="text-sm">
|
||||
原执行
|
||||
{{
|
||||
audit.originalTaskStatus === 'failed'
|
||||
? '失败'
|
||||
: audit.originalTaskStatus === 'completed'
|
||||
? '完成'
|
||||
: '尚未结束'
|
||||
}}
|
||||
· 原执行记录
|
||||
{{
|
||||
audit.originalWorkflowStatus === 'failed'
|
||||
? '失败'
|
||||
: audit.originalWorkflowStatus === 'completed'
|
||||
? '完成'
|
||||
: '尚未结束'
|
||||
}}
|
||||
· {{ original.needsReview ? '原质量待审' : '质量以原视频检查记录为准' }}
|
||||
</p>
|
||||
<p class="text-sm">
|
||||
{{ original.current ? '原版本仍适用' : '原版本已过期或不可确认,费用审计仍绑定原请求' }}
|
||||
</p>
|
||||
<p class="text-xs wrap-anywhere">
|
||||
原任务 {{ audit.taskId }} · 原执行记录 {{ audit.workflowExecutionId }}
|
||||
</p>
|
||||
<RawDataDetails
|
||||
:value="{
|
||||
billing: original.output.billing,
|
||||
steps: original.output.steps,
|
||||
result: original.output.result,
|
||||
needsReview: original.needsReview,
|
||||
current: original.current,
|
||||
staleReason: original.staleReason
|
||||
}"
|
||||
title="原始费用状态与质量观察"
|
||||
/>
|
||||
</section>
|
||||
<div class="workspace-form-field">
|
||||
<span>原请求阶段</span
|
||||
><NSelect
|
||||
aria-label="原请求阶段"
|
||||
v-model:value="form.stepName.value"
|
||||
:options="stepOptions"
|
||||
:disabled="form.saving.value"
|
||||
/>
|
||||
</div>
|
||||
<p v-if="!audit.steps.length" class="text-sm">此任务暂无完整的原请求标记,无法登记审计。</p>
|
||||
<template v-if="form.step.value">
|
||||
<section class="space-y-2 text-sm min-w-0">
|
||||
<p class="font-semibold">{{ auditStatusLabels[form.step.value.status] }}</p>
|
||||
<p class="wrap-anywhere">
|
||||
原请求状态 {{ auditRequestStatusLabels[form.step.value.requestStatus] ?? '原状态待核对' }} ·
|
||||
{{ form.step.value.identity.provider }} /
|
||||
{{ form.step.value.identity.model }}
|
||||
</p>
|
||||
<p class="wrap-anywhere">
|
||||
原供应方请求号 {{ form.step.value.originalProviderRequestId ?? '未知' }}
|
||||
</p>
|
||||
<p class="wrap-anywhere">
|
||||
原 SDK 回执号 {{ form.step.value.originalSdkReceiptId ?? '未知' }} ·
|
||||
{{ form.step.value.hasOriginalReceipt ? '已有原 SDK 完成回执' : '暂无原 SDK 回执' }}
|
||||
</p>
|
||||
<RawDataDetails
|
||||
:value="{
|
||||
identity: form.step.value.identity,
|
||||
taskFingerprint: audit.taskFingerprint,
|
||||
evidenceSetFingerprint: form.step.value.evidenceSetFingerprint,
|
||||
reviewFingerprint: form.step.value.reviewFingerprint
|
||||
}"
|
||||
title="原请求身份、来源与并发版本(只读)"
|
||||
/>
|
||||
</section>
|
||||
<div class="workspace-form-field">
|
||||
<span>本次操作</span
|
||||
><NSelect
|
||||
aria-label="本次操作"
|
||||
v-model:value="form.action.value"
|
||||
:disabled="form.saving.value"
|
||||
:options="[
|
||||
{ label: '登记外部证据', value: 'evidence' },
|
||||
{ label: '独立人工复核', value: 'review' }
|
||||
]"
|
||||
/>
|
||||
</div>
|
||||
<!-- 以下是外部原件登记表单,默认未知,原件引用不执行 URL -->
|
||||
<section v-if="form.action.value === 'evidence'" class="workspace-section-stack">
|
||||
<p class="text-sm text-muted">
|
||||
请保存原件并填写非敏感定位说明。真实供应方请求号与本地请求、LangSmith
|
||||
编号分别记录,不能互相代用。
|
||||
</p>
|
||||
<label class="workspace-form-field"
|
||||
><span>登记人</span
|
||||
><NInput v-model:value="form.operator.value" :maxlength="120" :disabled="form.saving.value"
|
||||
/></label>
|
||||
<div class="grid grid-cols-1 gap-(--app-field-gap) sm:grid-cols-2">
|
||||
<div class="workspace-form-field">
|
||||
<span>与原请求的关联</span
|
||||
><NSelect
|
||||
aria-label="与原请求的关联"
|
||||
v-model:value="form.correlation.value"
|
||||
:disabled="form.saving.value"
|
||||
:options="[
|
||||
{ label: '尚未核实', value: 'unverified' },
|
||||
{ label: '关联有歧义', value: 'ambiguous' },
|
||||
{ label: '已唯一关联', value: 'unique' }
|
||||
]"
|
||||
/>
|
||||
</div>
|
||||
<label class="workspace-form-field"
|
||||
><span>真实供应方请求号(未知留空)</span
|
||||
><NInput
|
||||
v-model:value="form.providerRequestId.value"
|
||||
:maxlength="200"
|
||||
:disabled="form.saving.value"
|
||||
/></label>
|
||||
</div>
|
||||
<article
|
||||
v-for="(item, index) in form.artifacts.value"
|
||||
:key="index"
|
||||
class="surface-inset p-4 workspace-section-stack min-w-0"
|
||||
>
|
||||
<div class="flex items-center justify-between gap-3">
|
||||
<h3 class="font-semibold">原件 {{ index + 1 }}</h3>
|
||||
<WorkspaceActionTooltip label="删除原件"
|
||||
><NButton
|
||||
class="workspace-action-button icon-button"
|
||||
:disabled="form.saving.value"
|
||||
aria-label="删除原件"
|
||||
@click="form.removeArtifact(index)"
|
||||
><Trash2 :size="16" /></NButton
|
||||
></WorkspaceActionTooltip>
|
||||
</div>
|
||||
<div class="grid grid-cols-1 gap-(--app-field-gap) sm:grid-cols-2">
|
||||
<label class="workspace-form-field"
|
||||
><span>包内引用键</span
|
||||
><NInput v-model:value="item.id" :maxlength="120" :disabled="form.saving.value"
|
||||
/></label>
|
||||
<div class="workspace-form-field">
|
||||
<span>原件来源</span
|
||||
><NSelect
|
||||
aria-label="原件来源"
|
||||
v-model:value="item.kind"
|
||||
:options="artifactKinds"
|
||||
:disabled="form.saving.value"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<label class="workspace-form-field"
|
||||
><span>原件记录编号</span
|
||||
><NInput v-model:value="item.recordId" :maxlength="200" :disabled="form.saving.value"
|
||||
/></label>
|
||||
<label class="workspace-form-field"
|
||||
><span>原件 SHA256</span
|
||||
><NInput v-model:value="item.sha256" :maxlength="64" :disabled="form.saving.value"
|
||||
/></label>
|
||||
<label class="workspace-form-field"
|
||||
><span>非敏感原件定位说明</span
|
||||
><NInput
|
||||
v-model:value="item.reference"
|
||||
type="textarea"
|
||||
:maxlength="1000"
|
||||
:disabled="form.saving.value"
|
||||
/></label>
|
||||
</article>
|
||||
<NButton
|
||||
:disabled="form.saving.value || form.artifacts.value.length >= 20"
|
||||
@click="form.addArtifact"
|
||||
>添加原件</NButton
|
||||
>
|
||||
<div class="grid grid-cols-1 gap-(--app-field-gap) sm:grid-cols-2">
|
||||
<div class="workspace-form-field">
|
||||
<span>供应方执行结果</span
|
||||
><NSelect
|
||||
aria-label="供应方执行结果"
|
||||
v-model:value="form.outcome.value"
|
||||
:options="outcomeOptions"
|
||||
:disabled="form.saving.value"
|
||||
/>
|
||||
</div>
|
||||
<div class="workspace-form-field">
|
||||
<span>执行依据原件</span
|
||||
><NSelect
|
||||
aria-label="执行依据原件"
|
||||
v-model:value="form.executionIds.value"
|
||||
multiple
|
||||
:options="form.artifactOptions.value"
|
||||
:disabled="form.saving.value"
|
||||
/>
|
||||
</div>
|
||||
<div class="workspace-form-field">
|
||||
<span>原始费用结论</span
|
||||
><NSelect
|
||||
aria-label="原始费用结论"
|
||||
v-model:value="form.finding.value"
|
||||
:options="findingOptions"
|
||||
:disabled="form.saving.value"
|
||||
/>
|
||||
</div>
|
||||
<div class="workspace-form-field">
|
||||
<span>费用依据原件</span
|
||||
><NSelect
|
||||
aria-label="费用依据原件"
|
||||
v-model:value="form.billingIds.value"
|
||||
multiple
|
||||
:options="form.artifactOptions.value"
|
||||
:disabled="form.saving.value"
|
||||
/>
|
||||
</div>
|
||||
<label class="workspace-form-field"
|
||||
><span>实际金额({{ audit.currency }},未知留空)</span
|
||||
><NInputNumber
|
||||
v-model:value="form.amount.value"
|
||||
:min="0"
|
||||
clearable
|
||||
:disabled="form.saving.value"
|
||||
/></label>
|
||||
</div>
|
||||
</section>
|
||||
<!-- 以下是独立人工复核表单,资料不足时保留阻断 -->
|
||||
<section v-else class="workspace-section-stack">
|
||||
<div class="workspace-form-field">
|
||||
<span>选择已登记证据包</span
|
||||
><NSelect
|
||||
aria-label="选择已登记证据包"
|
||||
v-model:value="form.evidenceId.value"
|
||||
:options="evidenceOptions"
|
||||
:disabled="form.saving.value"
|
||||
/>
|
||||
</div>
|
||||
<template v-if="form.selectedEvidence.value">
|
||||
<p class="text-sm">
|
||||
{{ auditOutcomeLabels[form.selectedEvidence.value.body.evidence.execution.outcome] }} ·
|
||||
{{ auditFindingLabels[form.selectedEvidence.value.body.evidence.billing.finding] }} ·
|
||||
{{
|
||||
form.selectedEvidence.value.body.evidence.billing.amount === null
|
||||
? '金额未知'
|
||||
: `${form.selectedEvidence.value.body.evidence.billing.currency} ${form.selectedEvidence.value.body.evidence.billing.amount}`
|
||||
}}
|
||||
·
|
||||
{{
|
||||
form.selectedEvidence.value.body.evidence.correlation === 'unique'
|
||||
? '声明已唯一关联'
|
||||
: '唯一关联尚未确认'
|
||||
}}
|
||||
</p>
|
||||
<RawDataDetails
|
||||
:value="form.selectedEvidence.value.body.evidence"
|
||||
title="核对选中原件、原始身份与实际金额"
|
||||
/>
|
||||
</template>
|
||||
<div class="workspace-form-field">
|
||||
<span>费用处置</span
|
||||
><NSelect
|
||||
aria-label="费用处置"
|
||||
v-model:value="form.decision.value"
|
||||
:disabled="form.saving.value"
|
||||
:options="[
|
||||
{ label: '保留费用阻断', value: 'keep_blocked' },
|
||||
{
|
||||
label: '确认核清费用',
|
||||
value: 'release_future_charges',
|
||||
disabled: !!form.releaseIssues.value.length
|
||||
}
|
||||
]"
|
||||
/>
|
||||
</div>
|
||||
<ul v-if="form.releaseIssues.value.length" class="text-sm text-muted space-y-1">
|
||||
<li v-for="issue in form.releaseIssues.value" :key="issue">{{ issue }}</li>
|
||||
</ul>
|
||||
<label class="workspace-form-field"
|
||||
><span>复核人</span
|
||||
><NInput v-model:value="form.reviewer.value" :maxlength="120" :disabled="form.saving.value"
|
||||
/></label>
|
||||
<label class="workspace-form-field"
|
||||
><span>复核说明</span
|
||||
><NInput
|
||||
v-model:value="form.reason.value"
|
||||
type="textarea"
|
||||
:maxlength="2000"
|
||||
:disabled="form.saving.value"
|
||||
/></label>
|
||||
<label class="workspace-form-field"
|
||||
><span>人工确认材料 SHA256</span
|
||||
><NInput
|
||||
v-model:value="form.confirmationSha256.value"
|
||||
:maxlength="64"
|
||||
:disabled="form.saving.value"
|
||||
/></label>
|
||||
</section>
|
||||
<NCheckbox
|
||||
v-model:checked="form.confirmed.value"
|
||||
:disabled="form.saving.value || form.query.loading.value || !!form.query.error.value"
|
||||
>我已核对当前版本及原始材料,确认提交本次{{
|
||||
form.action.value === 'evidence' ? '登记声明' : '人工费用复核'
|
||||
}}。</NCheckbox
|
||||
>
|
||||
<p v-if="form.validation.value" role="alert" class="text-sm">{{ form.validation.value }}</p>
|
||||
</template>
|
||||
<!-- 以下是跨版本审计历史,单调复核序号与原版本都保留 -->
|
||||
<NCollapse
|
||||
><NCollapseItem name="history" title="完整审计历史">
|
||||
<p
|
||||
v-if="!audit.history.evidence.length && !audit.history.reviews.length"
|
||||
class="text-sm text-muted"
|
||||
>
|
||||
暂无外部证据或人工复核。
|
||||
</p>
|
||||
<article
|
||||
v-for="item in audit.history.evidence"
|
||||
:key="item.id"
|
||||
class="mb-4 surface-inset p-4 space-y-2 min-w-0"
|
||||
>
|
||||
<p class="font-semibold text-sm">
|
||||
证据登记 · {{ item.body.operator }} · {{ formatDate(item.createdAt) }} ·
|
||||
{{ item.taskFingerprint === audit.taskFingerprint ? '当前原任务版本' : '历史原任务版本' }}
|
||||
</p>
|
||||
<p class="text-sm">
|
||||
{{ auditStepLabels[item.stepName] ?? '原阶段' }} ·
|
||||
{{ auditOutcomeLabels[item.body.evidence.execution.outcome] }} ·
|
||||
{{ auditFindingLabels[item.body.evidence.billing.finding] }}
|
||||
</p>
|
||||
<RawDataDetails :value="item" title="原件与登记详情" />
|
||||
</article>
|
||||
<article
|
||||
v-for="item in [...audit.history.reviews].sort((a, b) => (b.revision ?? 0) - (a.revision ?? 0))"
|
||||
:key="item.id"
|
||||
class="mb-4 surface-inset p-4 space-y-2 min-w-0"
|
||||
>
|
||||
<p class="font-semibold text-sm">
|
||||
人工复核 {{ item.revision }} · {{ item.body.reviewer }} ·
|
||||
{{ item.body.decision === 'keep_blocked' ? '保留阻断' : '核清未来费用' }} ·
|
||||
{{ item.taskFingerprint === audit.taskFingerprint ? '当前原任务版本' : '历史原任务版本' }}
|
||||
</p>
|
||||
<p class="text-sm whitespace-pre-wrap wrap-anywhere">{{ item.body.reason }}</p>
|
||||
<RawDataDetails :value="item" title="原人工复核版本与材料" />
|
||||
</article> </NCollapseItem
|
||||
></NCollapse>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
@@ -4,6 +4,7 @@ import FeedbackMessage from '../../../components/ui/FeedbackMessage.vue'
|
||||
|
||||
import ContextNotice from '../../../components/ui/ContextNotice.vue'
|
||||
|
||||
import { ReceiptText } from '@lucide/vue'
|
||||
import { computed } from 'vue'
|
||||
import { NButton, NTag } from 'naive-ui'
|
||||
import { AssetOpenLink, StatusBadge } from '../../../components/ui'
|
||||
@@ -32,7 +33,7 @@ const props = defineProps<{
|
||||
confirming: boolean
|
||||
}>()
|
||||
/** 交由父面板执行检查与切换,卡片不直接调用生成接口。 */
|
||||
const emit = defineEmits<{ quality: []; repair: []; history: []; select: []; confirm: []; cancel: [] }>()
|
||||
const emit = defineEmits<{ quality: []; repair: []; history: []; audit: []; select: []; confirm: []; cancel: [] }>()
|
||||
/** 播放和外链共用经过协议与资源路径校验的地址。 */
|
||||
const videoUrl = computed(() => (props.item.videoUrl ? mediaAssetUrl(props.item.videoUrl) : null))
|
||||
/** 优先显示本次会话的检查结果,否则显示此视频已有的记录。 */
|
||||
@@ -120,6 +121,9 @@ const canSelect = computed(
|
||||
>创建修复候选</NButton
|
||||
>
|
||||
<NButton text size="small" @click="emit('history')">查看质量记录</NButton>
|
||||
<NButton class="workspace-action-button" size="small" @click="emit('audit')"
|
||||
><template #icon><ReceiptText :size="16" /></template>费用审计</NButton
|
||||
>
|
||||
<NButton v-if="canSelect" :disabled="blocked" text size="small" @click="emit('select')">
|
||||
设为主视频
|
||||
</NButton>
|
||||
|
||||
@@ -0,0 +1,381 @@
|
||||
import { computed, onScopeDispose, ref, watch } from 'vue'
|
||||
import { useQuery } from '../../composables/useQuery'
|
||||
import { ApiError, errorMessage } from '../../lib/http'
|
||||
import { useActionMessage, showActionFeedback } from '../../components/ui/useActionMessage'
|
||||
import { workflowExecutionApi } from '../workflows/execution-api'
|
||||
import { videoAuditApi } from './video-audit-api'
|
||||
import { auditEvidenceIssues, auditReleaseIssues } from './video-audit'
|
||||
import type { VideoAuditArtifact, VideoAuditEvidence, VideoExecutionSummary } from './video-audit.types'
|
||||
|
||||
/**
|
||||
* 管理原任务发现、独立登记及人工复核,不执行任何收费或质量动作。
|
||||
* @param props 当前原候选及项目
|
||||
* @param changed 写入完成后通知刷新原视频质量与列表
|
||||
* @returns 原资源、表单与固定底栏操作
|
||||
*/
|
||||
export function useVideoAudit(
|
||||
props: { projectId: string; shotId: string; videoId: string; disabled?: boolean },
|
||||
changed: () => void
|
||||
) {
|
||||
/** 页面离开后不再回填原操作结果。 */
|
||||
let disposed = false
|
||||
onScopeDispose(() => {
|
||||
disposed = true
|
||||
})
|
||||
/** 当前候选隔离查询。 */
|
||||
const context = computed(() => JSON.stringify([props.projectId, props.shotId, props.videoId]))
|
||||
/** 正式发现历史,当前版本无法准备新质检时仍可读取最新原任务。 */
|
||||
const discovery = useQuery(context, async (_, signal) => {
|
||||
const [preview, latest] = await Promise.allSettled([
|
||||
videoAuditApi.history(props.shotId, props.videoId, signal),
|
||||
workflowExecutionApi.latest(props.projectId, 'video-validation', signal)
|
||||
])
|
||||
const rows: VideoExecutionSummary[] =
|
||||
preview.status === 'fulfilled' ? preview.value.history.filter(item => item.videoId === props.videoId) : []
|
||||
const execution = latest.status === 'fulfilled' ? latest.value : null
|
||||
if (
|
||||
execution?.metadata?.shotId === props.shotId &&
|
||||
execution.metadata.videoId === props.videoId &&
|
||||
typeof execution.metadata.taskId === 'string' &&
|
||||
!rows.some(row => row.taskId === execution.metadata!.taskId)
|
||||
)
|
||||
rows.push({
|
||||
taskId: execution.metadata.taskId,
|
||||
executionId: execution.id,
|
||||
videoId: props.videoId,
|
||||
taskStatus: execution.status,
|
||||
needsReview: false
|
||||
})
|
||||
return {
|
||||
rows,
|
||||
notice:
|
||||
preview.status === 'rejected'
|
||||
? '当前视频无法准备新的质检计划。可读取已发现的原任务,或使用原任务编号查询历史费用。'
|
||||
: ''
|
||||
}
|
||||
})
|
||||
/** 人工从原历史记录取得的任务号,不是供应方编号。 */
|
||||
const taskId = ref('')
|
||||
/** 供输入后明确查询,不逐字发起请求。 */
|
||||
const taskInput = ref('')
|
||||
/** 审计资源绑定原项目、镜头、候选及任务。 */
|
||||
const key = computed(() =>
|
||||
taskId.value ? JSON.stringify([props.projectId, props.shotId, props.videoId, taskId.value]) : ''
|
||||
)
|
||||
/** 真实原任务及当前证据同时回读并核对归属。 */
|
||||
const query = useQuery(key, async (value, signal) => {
|
||||
if (!value) return null
|
||||
const [project, shot, video, task] = JSON.parse(value) as string[]
|
||||
const [audit, original] = await Promise.all([
|
||||
videoAuditApi.get(shot!, task!, signal),
|
||||
videoAuditApi.task(shot!, task!, signal)
|
||||
])
|
||||
if (
|
||||
audit.projectId !== project ||
|
||||
audit.shotId !== shot ||
|
||||
audit.taskId !== task ||
|
||||
original.taskId !== task ||
|
||||
original.executionId !== audit.workflowExecutionId ||
|
||||
original.plan.projectId !== project ||
|
||||
original.plan.shotId !== shot ||
|
||||
original.plan.videoId !== video ||
|
||||
original.plan.purpose !== 'video_validation' ||
|
||||
audit.steps.some(
|
||||
step =>
|
||||
step.identity.taskId !== task ||
|
||||
step.identity.videoId !== video ||
|
||||
step.identity.workflowExecutionId !== audit.workflowExecutionId
|
||||
)
|
||||
)
|
||||
throw new Error('原任务归属与当前视频不匹配,请核对历史任务编号。')
|
||||
return { audit, original }
|
||||
})
|
||||
/** 当前选择的真实原请求阶段。 */
|
||||
const stepName = ref('')
|
||||
/** 登记和人工复核始终为两个独立操作。 */
|
||||
const action = ref<'evidence' | 'review'>('evidence')
|
||||
/** 实际登记人。 */
|
||||
const operator = ref('')
|
||||
/** 人工取得的真实供应方请求编号,绝不回填本地编号。 */
|
||||
const providerRequestId = ref('')
|
||||
/** 默认未核实关联。 */
|
||||
const correlation = ref<VideoAuditEvidence['correlation']>('unverified')
|
||||
/** 原件表单,空白原件不是实际证据。 */
|
||||
const artifacts = ref<VideoAuditArtifact[]>([])
|
||||
/** 默认执行事实未知。 */
|
||||
const outcome = ref<VideoAuditEvidence['execution']['outcome']>('unknown')
|
||||
/** 默认收费事实未知。 */
|
||||
const finding = ref<VideoAuditEvidence['billing']['finding']>('unknown')
|
||||
/** 未知金额不推断零。 */
|
||||
const amount = ref<number | null>(null)
|
||||
/** 人工选择的执行原件引用。 */
|
||||
const executionIds = ref<string[]>([])
|
||||
/** 人工选择的账单原件引用。 */
|
||||
const billingIds = ref<string[]>([])
|
||||
/** 已登记证据的选择。 */
|
||||
const evidenceId = ref('')
|
||||
/** 实际复核人。 */
|
||||
const reviewer = ref('')
|
||||
/** 实际复核说明。 */
|
||||
const reason = ref('')
|
||||
/** 原确认材料摘要,不由浏览器生成替代。 */
|
||||
const confirmationSha256 = ref('')
|
||||
/** 默认保留费用阻断,核清须主动切换。 */
|
||||
const decision = ref<'keep_blocked' | 'release_future_charges'>('keep_blocked')
|
||||
/** 提交前核对当前版本,刷新或冲突后取消确认。 */
|
||||
const confirmed = ref(false)
|
||||
/** 当前同步写入,阻止切换和重复操作。 */
|
||||
const saving = ref(false)
|
||||
/** 主动提交后的表单问题。 */
|
||||
const validation = ref('')
|
||||
/** 原步骤不使用当前新镜头的身份。 */
|
||||
const step = computed(() => query.data.value?.audit.steps.find(item => item.name === stepName.value))
|
||||
/** 人工选择的已登记原件包。 */
|
||||
const selectedEvidence = computed(() => step.value?.evidence.find(item => item.id === evidenceId.value))
|
||||
/** 原件引用选项共用实际包内键。 */
|
||||
const artifactOptions = computed(() =>
|
||||
artifacts.value
|
||||
.filter(item => item.id.trim())
|
||||
.map(item => ({ label: `${item.id} · ${item.recordId || '未填记录编号'}`, value: item.id }))
|
||||
)
|
||||
/** 已登记证据才有核清资格,默认未知保持阻断。 */
|
||||
const releaseIssues = computed(() =>
|
||||
step.value && query.data.value
|
||||
? auditReleaseIssues(selectedEvidence.value?.body.evidence, step.value, query.data.value.audit)
|
||||
: ['请读取原任务。']
|
||||
)
|
||||
/** 底栏名称明确区分登记与处置。 */
|
||||
const submitLabel = computed(() =>
|
||||
action.value === 'evidence'
|
||||
? '登记外部证据'
|
||||
: decision.value === 'keep_blocked'
|
||||
? '确认保留阻断'
|
||||
: '确认核清费用'
|
||||
)
|
||||
/** 资源完整且用户核对当前版本后才提供写操作。 */
|
||||
const canSubmit = computed(
|
||||
() =>
|
||||
!!step.value &&
|
||||
!saving.value &&
|
||||
!props.disabled &&
|
||||
!query.loading.value &&
|
||||
!query.error.value &&
|
||||
confirmed.value &&
|
||||
(action.value !== 'review' || decision.value !== 'release_future_charges' || !releaseIssues.value.length)
|
||||
)
|
||||
/** 消息反馈使用全局 NMessage。 */
|
||||
const message = useActionMessage()
|
||||
watch(
|
||||
context,
|
||||
() => {
|
||||
taskId.value = ''
|
||||
taskInput.value = ''
|
||||
},
|
||||
{ flush: 'sync' }
|
||||
)
|
||||
watch(
|
||||
key,
|
||||
() => {
|
||||
stepName.value = ''
|
||||
},
|
||||
{ flush: 'sync' }
|
||||
)
|
||||
watch(
|
||||
() => discovery.data.value?.rows,
|
||||
rows => {
|
||||
if (!taskId.value && rows?.length) taskId.value = rows[0]!.taskId
|
||||
}
|
||||
)
|
||||
watch(
|
||||
stepName,
|
||||
() => {
|
||||
operator.value = ''
|
||||
providerRequestId.value = ''
|
||||
correlation.value = 'unverified'
|
||||
artifacts.value = []
|
||||
outcome.value = 'unknown'
|
||||
finding.value = 'unknown'
|
||||
amount.value = null
|
||||
executionIds.value = []
|
||||
billingIds.value = []
|
||||
evidenceId.value = ''
|
||||
decision.value = 'keep_blocked'
|
||||
reviewer.value = ''
|
||||
reason.value = ''
|
||||
confirmationSha256.value = ''
|
||||
confirmed.value = false
|
||||
},
|
||||
{ flush: 'sync' }
|
||||
)
|
||||
watch(
|
||||
() => query.data.value,
|
||||
data => {
|
||||
confirmed.value = false
|
||||
if (data && !data.audit.steps.some(item => item.name === stepName.value))
|
||||
stepName.value = data.audit.steps[0]?.name ?? ''
|
||||
}
|
||||
)
|
||||
watch(
|
||||
[
|
||||
stepName,
|
||||
action,
|
||||
evidenceId,
|
||||
decision,
|
||||
operator,
|
||||
providerRequestId,
|
||||
correlation,
|
||||
artifacts,
|
||||
outcome,
|
||||
finding,
|
||||
amount,
|
||||
executionIds,
|
||||
billingIds,
|
||||
reviewer,
|
||||
reason,
|
||||
confirmationSha256
|
||||
],
|
||||
() => {
|
||||
validation.value = ''
|
||||
confirmed.value = false
|
||||
},
|
||||
{ deep: true }
|
||||
)
|
||||
|
||||
/** 显式查询用户输入的原任务,不写入供应方身份。 */
|
||||
function lookup() {
|
||||
if (!saving.value && taskInput.value.trim()) taskId.value = taskInput.value.trim()
|
||||
}
|
||||
/** 添加空白原件,只有实际填写材料后才能登记。 */
|
||||
function addArtifact() {
|
||||
if (artifacts.value.length < 20)
|
||||
artifacts.value.push({ id: '', kind: 'provider-execution', recordId: '', sha256: '', reference: '' })
|
||||
}
|
||||
/**
|
||||
* 删除原件并同步清除对应引用。
|
||||
* @param index 表单原件顺序
|
||||
*/
|
||||
function removeArtifact(index: number) {
|
||||
const id = artifacts.value[index]?.id
|
||||
artifacts.value.splice(index, 1)
|
||||
executionIds.value = executionIds.value.filter(value => value !== id)
|
||||
billingIds.value = billingIds.value.filter(value => value !== id)
|
||||
}
|
||||
/** 只读刷新原审计和任务,取消旧的提交确认。 */
|
||||
async function refresh() {
|
||||
confirmed.value = false
|
||||
await query.refresh()
|
||||
}
|
||||
/** 独立登记或人工复核,所有冲突刷新后等待人工重新核查。 */
|
||||
async function submit() {
|
||||
if (!canSubmit.value || !step.value || !query.data.value) return
|
||||
const { audit } = query.data.value
|
||||
const originalStep = step.value
|
||||
const target = key.value
|
||||
const evidence: VideoAuditEvidence = {
|
||||
identity: { ...originalStep.identity },
|
||||
correlation: correlation.value,
|
||||
providerRequestId: providerRequestId.value.trim() || null,
|
||||
artifacts: artifacts.value.map(item => ({ ...item })),
|
||||
execution: { outcome: outcome.value, evidenceIds: [...executionIds.value] },
|
||||
billing: {
|
||||
finding: finding.value,
|
||||
amount: amount.value,
|
||||
currency: audit.currency,
|
||||
evidenceIds: [...billingIds.value]
|
||||
}
|
||||
}
|
||||
const issues =
|
||||
action.value === 'evidence'
|
||||
? [...auditEvidenceIssues(evidence), ...(!operator.value.trim() ? ['请填写登记人。'] : [])]
|
||||
: [
|
||||
...(!selectedEvidence.value ? ['请选择已登记证据包。'] : []),
|
||||
...(!reviewer.value.trim() ||
|
||||
reason.value.trim().length < 4 ||
|
||||
!/^[a-f0-9]{64}$/.test(confirmationSha256.value)
|
||||
? ['请填写复核人、至少 4 字说明及真实确认材料 SHA256。']
|
||||
: [])
|
||||
]
|
||||
if (issues.length) {
|
||||
validation.value = issues.join(' ')
|
||||
return
|
||||
}
|
||||
saving.value = true
|
||||
confirmed.value = false
|
||||
try {
|
||||
if (action.value === 'evidence') {
|
||||
await videoAuditApi.register(props.shotId, audit.taskId, {
|
||||
expectedTaskFingerprint: audit.taskFingerprint,
|
||||
stepName: originalStep.name,
|
||||
operator: operator.value.trim(),
|
||||
evidence
|
||||
})
|
||||
if (disposed || target !== key.value) return
|
||||
showActionFeedback(message, '证据已登记,等待人工核查。', 'info')
|
||||
} else {
|
||||
const result = await videoAuditApi.review(props.shotId, audit.taskId, {
|
||||
stepName: originalStep.name,
|
||||
evidenceId: evidenceId.value,
|
||||
expectedTaskFingerprint: audit.taskFingerprint,
|
||||
expectedEvidenceSetFingerprint: originalStep.evidenceSetFingerprint,
|
||||
expectedReviewFingerprint: originalStep.reviewFingerprint,
|
||||
decision: decision.value,
|
||||
reviewer: reviewer.value.trim(),
|
||||
reason: reason.value.trim(),
|
||||
confirmationSha256: confirmationSha256.value
|
||||
})
|
||||
if (disposed || target !== key.value) return
|
||||
showActionFeedback(
|
||||
message,
|
||||
result.billingBlocked
|
||||
? '复核已记录,当前任务仍有费用阻断。'
|
||||
: '费用已核清,旧视频质量与版本继续按原记录核对。',
|
||||
'info'
|
||||
)
|
||||
}
|
||||
await Promise.all([refresh(), discovery.refresh()])
|
||||
if (!disposed && target === key.value) changed()
|
||||
} catch (cause) {
|
||||
if (disposed || target !== key.value) return
|
||||
showActionFeedback(message, errorMessage(cause), 'error')
|
||||
if (cause instanceof ApiError && cause.status === 409) await refresh()
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
return {
|
||||
discovery,
|
||||
query,
|
||||
taskId,
|
||||
taskInput,
|
||||
lookup,
|
||||
stepName,
|
||||
step,
|
||||
action,
|
||||
operator,
|
||||
providerRequestId,
|
||||
correlation,
|
||||
artifacts,
|
||||
outcome,
|
||||
finding,
|
||||
amount,
|
||||
executionIds,
|
||||
billingIds,
|
||||
evidenceId,
|
||||
reviewer,
|
||||
reason,
|
||||
confirmationSha256,
|
||||
decision,
|
||||
confirmed,
|
||||
saving,
|
||||
validation,
|
||||
selectedEvidence,
|
||||
artifactOptions,
|
||||
releaseIssues,
|
||||
submitLabel,
|
||||
canSubmit,
|
||||
addArtifact,
|
||||
removeArtifact,
|
||||
refresh,
|
||||
submit
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
import { request } from '../../lib/http'
|
||||
import type {
|
||||
RegisterVideoAudit,
|
||||
ReviewVideoAudit,
|
||||
VideoAuditView,
|
||||
VideoExecutionDetail,
|
||||
VideoExecutionSummary
|
||||
} from './video-audit.types'
|
||||
|
||||
/**
|
||||
* 原任务路径不使用当前新版镜头替代身份。
|
||||
* @param shotId 原镜头
|
||||
* @param taskId 原任务
|
||||
* @returns 正式执行路径
|
||||
*/
|
||||
function root(shotId: string, taskId: string) {
|
||||
return `/storyboard-shots/${encodeURIComponent(shotId)}/video-executions/${encodeURIComponent(taskId)}`
|
||||
}
|
||||
/** 当前视频免费计划的原历史任务。 */
|
||||
interface VideoAuditDiscovery {
|
||||
/** 当前候选历史。 */ history: VideoExecutionSummary[]
|
||||
/** 本镜头仍阻断费用的原任务。 */ blockingTasks: VideoExecutionSummary[]
|
||||
}
|
||||
/** 费用审计同步事务,不调用模型或恢复旧任务。 */
|
||||
export const videoAuditApi = {
|
||||
/**
|
||||
* 免费发现候选原质检任务,过期候选可按原任务编号直接查询。
|
||||
* @param shotId 原镜头
|
||||
* @param videoId 原候选
|
||||
* @param signal 取消旧候选请求
|
||||
* @returns 服务端原任务摘要
|
||||
*/
|
||||
history: (shotId: string, videoId: string, signal?: AbortSignal) =>
|
||||
request<VideoAuditDiscovery>(
|
||||
`/storyboard-shots/${encodeURIComponent(shotId)}/videos/${encodeURIComponent(videoId)}/validation/preview`,
|
||||
{ method: 'POST', body: {}, signal }
|
||||
),
|
||||
/**
|
||||
* 读取原任务质量、费用和版本状态。
|
||||
* @param shotId 原镜头
|
||||
* @param taskId 原任务
|
||||
* @param signal 取消旧读取
|
||||
* @returns 原任务详情
|
||||
*/
|
||||
task: (shotId: string, taskId: string, signal?: AbortSignal) =>
|
||||
request<VideoExecutionDetail>(root(shotId, taskId), { signal }),
|
||||
/**
|
||||
* 读取当前完整证据集合及并发版本。
|
||||
* @param shotId 原镜头
|
||||
* @param taskId 原任务
|
||||
* @param signal 取消旧读取
|
||||
* @returns 费用审计资源
|
||||
*/
|
||||
get: (shotId: string, taskId: string, signal?: AbortSignal) =>
|
||||
request<VideoAuditView>(root(shotId, taskId) + '/audit', { signal }),
|
||||
/**
|
||||
* 幂等登记外部原件引用,登记本身不核清费用。
|
||||
* @param shotId 原镜头
|
||||
* @param taskId 原任务
|
||||
* @param body 用户提供的真实材料与版本
|
||||
* @returns 同步登记结果
|
||||
*/
|
||||
register: (shotId: string, taskId: string, body: RegisterVideoAudit) =>
|
||||
request<{ evidenceId: string; reused: boolean; billingBlocked: boolean }>(
|
||||
root(shotId, taskId) + '/audit/evidence',
|
||||
{ method: 'POST', body }
|
||||
),
|
||||
/**
|
||||
* 独立人工复核当前完整证据,不启动质量操作。
|
||||
* @param shotId 原镜头
|
||||
* @param taskId 原任务
|
||||
* @param body 用户核验材料及三个服务端版本
|
||||
* @returns 当前费用状态
|
||||
*/
|
||||
review: (shotId: string, taskId: string, body: ReviewVideoAudit) =>
|
||||
request<{ reviewId: string; status: string; reused: boolean; billingBlocked: boolean }>(
|
||||
root(shotId, taskId) + '/audit/reviews',
|
||||
{ method: 'POST', body }
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
import type { VideoAuditEvidence, VideoAuditStep, VideoAuditView } from './video-audit.types'
|
||||
|
||||
/** 原件来源使用中文选项,提交保留原枚举。 */
|
||||
export const auditArtifactLabels = {
|
||||
'provider-execution': '供应方执行原件',
|
||||
'provider-billing': '供应方账单原件',
|
||||
'provider-support': '供应方官方支持材料',
|
||||
langsmith: 'LangSmith 观测记录',
|
||||
'client-log': '客户端日志'
|
||||
}
|
||||
/** 原执行结论不替代质量结论。 */
|
||||
export const auditOutcomeLabels = {
|
||||
'not-received': '供应方未接收',
|
||||
succeeded: '供应方执行完成',
|
||||
failed: '供应方执行失败',
|
||||
unknown: '执行结果未知'
|
||||
}
|
||||
/** 原收费结论不以零 Token 推断。 */
|
||||
export const auditFindingLabels = { charged: '已收费', 'no-charge': '未收费', unknown: '费用未知' }
|
||||
/** 费用审计状态中文。 */
|
||||
export const auditStatusLabels = { unreviewed: '等待人工核查', blocked: '保留费用阻断', released: '此步骤费用已核清' }
|
||||
/** 原请求步骤名称。 */
|
||||
export const auditStepLabels: Record<string, string> = {
|
||||
visualResult: '画面检查',
|
||||
propLocator: '道具定位',
|
||||
motionResult: '运动检查',
|
||||
spatialInteractionResult: '空间互动检查',
|
||||
physicalStructureResult: '物理结构检查',
|
||||
physicalJointResult: '连接关系检查'
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交前检查真实材料及引用格式,未知事实允许登记。
|
||||
* @param evidence 用户填写的证据包
|
||||
* @returns 校验问题
|
||||
*/
|
||||
export function auditEvidenceIssues(evidence: VideoAuditEvidence): string[] {
|
||||
const issues: string[] = []
|
||||
const ids = evidence.artifacts.map(item => item.id)
|
||||
if (!ids.length || ids.length > 20 || new Set(ids).size !== ids.length)
|
||||
issues.push('请提供 1~20 项原件,引用键不能重复。')
|
||||
if (
|
||||
evidence.artifacts.some(
|
||||
item =>
|
||||
!item.id.trim() ||
|
||||
item.id.length > 120 ||
|
||||
!item.recordId.trim() ||
|
||||
item.recordId.length > 200 ||
|
||||
!/^[a-f0-9]{64}$/.test(item.sha256) ||
|
||||
!item.reference.trim() ||
|
||||
item.reference.length > 1000
|
||||
)
|
||||
)
|
||||
issues.push('请填写每项原件的引用键、记录编号、64 位小写 SHA256 及定位说明。')
|
||||
if ([...evidence.execution.evidenceIds, ...evidence.billing.evidenceIds].some(id => !ids.includes(id)))
|
||||
issues.push('执行或费用引用的原件已不存在,请重新选择。')
|
||||
if (evidence.billing.amount !== null && (!Number.isFinite(evidence.billing.amount) || evidence.billing.amount < 0))
|
||||
issues.push('实际金额需为非负数,未知请留空。')
|
||||
if (
|
||||
evidence.providerRequestId &&
|
||||
([
|
||||
evidence.identity.requestId,
|
||||
evidence.identity.taskId,
|
||||
evidence.identity.workflowExecutionId,
|
||||
evidence.identity.videoId
|
||||
].includes(evidence.providerRequestId) ||
|
||||
evidence.artifacts.some(item => item.kind === 'langsmith' && item.recordId === evidence.providerRequestId))
|
||||
)
|
||||
issues.push('本地任务、请求或 LangSmith 编号不能作为供应方请求号。')
|
||||
return issues
|
||||
}
|
||||
/**
|
||||
* 资料不完整时禁用核清,最终真实性与唯一认领仍由人工及服务端核验。
|
||||
* @param evidence 已登记证据
|
||||
* @param step 原请求及 SDK 事实
|
||||
* @param view 原任务版本与币种
|
||||
* @returns 不可确认核清的原因
|
||||
*/
|
||||
export function auditReleaseIssues(
|
||||
evidence: VideoAuditEvidence | undefined,
|
||||
step: VideoAuditStep,
|
||||
view: VideoAuditView
|
||||
): string[] {
|
||||
if (!evidence) return ['请先选择已经登记的证据包。']
|
||||
const issues = auditEvidenceIssues(evidence)
|
||||
const execution = evidence.artifacts.filter(item => evidence.execution.evidenceIds.includes(item.id))
|
||||
const billing = evidence.artifacts.filter(item => evidence.billing.evidenceIds.includes(item.id))
|
||||
if (evidence.correlation !== 'unique') issues.push('原件尚未唯一关联原请求。')
|
||||
if (
|
||||
evidence.execution.outcome === 'unknown' ||
|
||||
evidence.billing.finding === 'unknown' ||
|
||||
evidence.billing.amount === null
|
||||
)
|
||||
issues.push('执行终态或实际费用仍未知。')
|
||||
if (evidence.billing.currency !== view.currency) issues.push('币种与原批准不符。')
|
||||
if (evidence.billing.finding === 'no-charge' && evidence.billing.amount !== 0)
|
||||
issues.push('未收费必须有明确的零金额依据。')
|
||||
if (
|
||||
!execution.some(item => ['provider-execution', 'provider-support'].includes(item.kind)) ||
|
||||
!billing.some(item => ['provider-billing', 'provider-support'].includes(item.kind))
|
||||
)
|
||||
issues.push('执行与计费分别需要供应方原件,观测记录不能替代。')
|
||||
if (evidence.execution.outcome === 'not-received') {
|
||||
if (evidence.billing.finding !== 'no-charge' || !execution.some(item => item.kind === 'provider-support'))
|
||||
issues.push('未接收需要官方支持原件及未收费说明。')
|
||||
} else if (!evidence.providerRequestId) issues.push('请核对真实供应方请求号。')
|
||||
if (step.hasOriginalReceipt && evidence.execution.outcome !== 'succeeded')
|
||||
issues.push('原 SDK 回执已证明执行完成,外部声明与原事实冲突。')
|
||||
if (step.originalProviderRequestId && step.originalProviderRequestId !== evidence.providerRequestId)
|
||||
issues.push('供应方编号与原回执不一致。')
|
||||
if (
|
||||
['pending', 'running'].includes(view.originalTaskStatus) ||
|
||||
['pending', 'running'].includes(view.originalWorkflowStatus)
|
||||
)
|
||||
issues.push('原任务和执行记录尚未结束。')
|
||||
if (
|
||||
Object.entries(step.identity).some(
|
||||
([key, value]) => evidence.identity[key as keyof typeof evidence.identity] !== value
|
||||
)
|
||||
)
|
||||
issues.push('证据身份与原请求不一致。')
|
||||
return issues
|
||||
}
|
||||
|
||||
/** 原请求的费用状态名称,不推断费用为零。 */
|
||||
export const auditRequestStatusLabels: Record<string, string> = {
|
||||
pending: '尚未发送',
|
||||
running: '请求执行中',
|
||||
sending: '正在发送',
|
||||
received: '已取得回执',
|
||||
completed: '原步骤完成',
|
||||
failed: '原步骤失败',
|
||||
unknown: '结果或费用未知',
|
||||
unresolved: '结果或费用待核实'
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
/** 历史费用审计状态。 */
|
||||
export type VideoAuditStatus = 'unreviewed' | 'blocked' | 'released'
|
||||
/** 原历史请求身份,提交时原样复制。 */
|
||||
export interface VideoAuditIdentity {
|
||||
/** 原任务。 */ taskId: string
|
||||
/** 原执行记录。 */ workflowExecutionId: string
|
||||
/** 本地请求编号。 */ requestId: string
|
||||
/** 原请求指纹。 */ requestFingerprint: string
|
||||
/** 原计划指纹。 */ planFingerprint: string
|
||||
/** 原来源指纹。 */ sourceFingerprint: string
|
||||
/** 原视频。 */ videoId: string
|
||||
/** 原供应方。 */ provider: string
|
||||
/** 原型号。 */ model: string
|
||||
}
|
||||
/** 外部原件定位,引用始终按纯文本显示。 */
|
||||
export interface VideoAuditArtifact {
|
||||
/** 包内引用键。 */ id: string
|
||||
/** 原件来源声明。 */ kind:
|
||||
| 'provider-execution'
|
||||
| 'provider-billing'
|
||||
| 'provider-support'
|
||||
| 'langsmith'
|
||||
| 'client-log'
|
||||
/** 原件记录编号。 */ recordId: string
|
||||
/** 人工取得的原件摘要。 */ sha256: string
|
||||
/** 非敏感定位说明。 */ reference: string
|
||||
}
|
||||
/** 待人工核验的外部事实。 */
|
||||
export interface VideoAuditEvidence {
|
||||
/** 原请求身份。 */ identity: VideoAuditIdentity
|
||||
/** 唯一关联程度。 */ correlation: 'unique' | 'ambiguous' | 'unverified'
|
||||
/** 真实供应方请求号。 */ providerRequestId: string | null
|
||||
/** 外部原件。 */ artifacts: VideoAuditArtifact[]
|
||||
/** 原供应方执行结果,与质量独立。 */ execution: {
|
||||
/** 执行事实。 */ outcome: 'not-received' | 'succeeded' | 'failed' | 'unknown'
|
||||
/** 所引原件。 */ evidenceIds: string[]
|
||||
}
|
||||
/** 实际账单事实。 */ billing: {
|
||||
/** 是否收费。 */ finding: 'charged' | 'no-charge' | 'unknown'
|
||||
/** 实际金额,未知保留 null。 */ amount: number | null
|
||||
/** 原批准币种。 */ currency: string
|
||||
/** 所引原件。 */ evidenceIds: string[]
|
||||
}
|
||||
}
|
||||
/** 外部证据登记。 */
|
||||
export interface RegisterVideoAudit {
|
||||
/** 原任务版本。 */ expectedTaskFingerprint: string
|
||||
/** 原步骤。 */ stepName: string
|
||||
/** 实际登记人。 */ operator: string
|
||||
/** 外部材料与事实声明。 */ evidence: VideoAuditEvidence
|
||||
}
|
||||
/** 独立人工复核。 */
|
||||
export interface ReviewVideoAudit {
|
||||
/** 原步骤。 */ stepName: string
|
||||
/** 已登记证据。 */ evidenceId: string
|
||||
/** 原任务版本。 */ expectedTaskFingerprint: string
|
||||
/** 完整证据集合版本。 */ expectedEvidenceSetFingerprint: string
|
||||
/** 复核并发版本。 */ expectedReviewFingerprint: string
|
||||
/** 仅影响未来收费。 */ decision: 'keep_blocked' | 'release_future_charges'
|
||||
/** 实际复核人。 */ reviewer: string
|
||||
/** 复核原因。 */ reason: string
|
||||
/** 实际确认材料摘要。 */ confirmationSha256: string
|
||||
}
|
||||
/** 原不可变审计事件。 */
|
||||
export interface VideoAuditEvent<T> {
|
||||
/** 原事件编号。 */ id: string
|
||||
/** 原任务版本。 */ taskFingerprint: string
|
||||
/** 原步骤。 */ stepName: string
|
||||
/** 事件时间。 */ createdAt: string
|
||||
/** 原事件正文。 */ body: T
|
||||
/** 原事件摘要。 */ digest: string
|
||||
/** 人工复核单调序号。 */ revision?: number
|
||||
}
|
||||
/** 原步骤审计视图。 */
|
||||
export interface VideoAuditStep {
|
||||
/** 步骤名。 */ name: string
|
||||
/** 原请求状态。 */ requestStatus: string
|
||||
/** 原供应方请求号,与 SDK 编号分开。 */ originalProviderRequestId: string | null
|
||||
/** 原 SDK 回执号。 */ originalSdkReceiptId: string | null
|
||||
/** 原 SDK 已存在完成回执。 */ hasOriginalReceipt: boolean
|
||||
/** 原请求精确身份。 */ identity: VideoAuditIdentity
|
||||
/** 当前集合版本。 */ evidenceSetFingerprint: string
|
||||
/** 当前复核版本。 */ reviewFingerprint: string
|
||||
/** 当前费用状态。 */ status: VideoAuditStatus
|
||||
/** 有效核清。 */ released: boolean
|
||||
/** 当前有效复核编号。 */ reviewId: string | null
|
||||
/** 当前版本证据。 */ evidence: VideoAuditEvent<RegisterVideoAudit>[]
|
||||
/** 当前版本复核。 */ reviews: VideoAuditEvent<ReviewVideoAudit>[]
|
||||
}
|
||||
/** 原任务完整费用审计资源。 */
|
||||
export interface VideoAuditView {
|
||||
/** 原项目。 */ projectId: string
|
||||
/** 原镜头。 */ shotId: string
|
||||
/** 原任务。 */ taskId: string
|
||||
/** 原执行记录。 */ workflowExecutionId: string
|
||||
/** 原批准币种。 */ currency: string
|
||||
/** 原任务版本。 */ taskFingerprint: string
|
||||
/** 原执行状态。 */ originalTaskStatus: string
|
||||
/** 原执行记录状态。 */ originalWorkflowStatus: string
|
||||
/** 当前整体费用阻断。 */ billingBlocked: boolean
|
||||
/** 有真实原请求的步骤。 */ steps: VideoAuditStep[]
|
||||
/** 全部版本历史。 */ history: {
|
||||
/** 全部外部证据。 */ evidence: VideoAuditEvent<RegisterVideoAudit>[]
|
||||
/** 全部人工复核。 */ reviews: VideoAuditEvent<ReviewVideoAudit>[]
|
||||
}
|
||||
}
|
||||
/** 受控任务只读概要,不从费用结果重写质量。 */
|
||||
export interface VideoExecutionSummary {
|
||||
/** 原任务。 */ taskId: string
|
||||
/** 原任务状态。 */ taskStatus: string
|
||||
/** 原执行记录。 */ executionId: string
|
||||
/** 原视频。 */ videoId: string | null
|
||||
/** 原待审标记。 */ needsReview: boolean
|
||||
/** 当前费用阻断,旧摘要可缺省。 */ billingBlocked?: boolean
|
||||
}
|
||||
/** 原受控任务详情,完整质量及费用存于原输出中。 */
|
||||
export interface VideoExecutionDetail extends VideoExecutionSummary {
|
||||
/** 原执行记录状态。 */ workflowStatus: string
|
||||
/** 原版本是否当前。 */ current: boolean
|
||||
/** 版本说明。 */ staleReason: string | null
|
||||
/** 原冻结计划。 */ plan: {
|
||||
/** 原用途。 */ purpose: string
|
||||
/** 原项目。 */ projectId: string
|
||||
/** 原镜头。 */ shotId: string
|
||||
/** 原视频。 */ videoId: string | null
|
||||
/** 原计划指纹。 */ fingerprint: string
|
||||
}
|
||||
/** 原状态、步骤、费用及质量观察保持不变。 */ output: Record<string, unknown>
|
||||
}
|
||||
@@ -28,6 +28,7 @@ defineExpose({
|
||||
canSubmit: form.canSubmit,
|
||||
submitting: form.submitting,
|
||||
acknowledged: form.acknowledged,
|
||||
requiresCostConfirmation: form.requiresCostConfirmation,
|
||||
submit: form.submit
|
||||
})
|
||||
/** 选项明确区分旧版确认图和当前草稿,用户自定义名称不翻译。 */
|
||||
@@ -139,6 +140,7 @@ const options = computed(() =>
|
||||
></NCollapse
|
||||
>
|
||||
</section>
|
||||
<p v-if="form.chargeNotice.value" class="text-sm text-muted" role="status">{{ form.chargeNotice.value }}</p>
|
||||
<p v-if="form.recoveryNotice.value" class="text-sm text-muted" role="status">
|
||||
{{ form.recoveryNotice.value }}只读刷新任务记录,不要再次生图。
|
||||
</p>
|
||||
|
||||
@@ -323,7 +323,7 @@ function reviewed() {
|
||||
<template #footer>
|
||||
<div class="flex w-full flex-wrap items-center justify-end gap-3">
|
||||
<NCheckbox
|
||||
v-if="tab === 'generate' && generationRef"
|
||||
v-if="tab === 'generate' && generationRef?.requiresCostConfirmation"
|
||||
v-model:checked="generationRef.acknowledged"
|
||||
:disabled="busy || blocked"
|
||||
class="mr-auto"
|
||||
|
||||
@@ -2,10 +2,13 @@ import { computed, onScopeDispose, ref, shallowRef, watch } from 'vue'
|
||||
import { useQuery } from '../../composables/useQuery'
|
||||
import { ApiError, errorMessage } from '../../lib/http'
|
||||
import { useActionMessage, showActionFeedback } from '../../components/ui/useActionMessage'
|
||||
import { useProjectGenerationRevision } from '../generation-config/context'
|
||||
import { generationConfigApi } from '../generation-config/api'
|
||||
import type { GenerationOptions } from '../generation-config/types'
|
||||
import { getOperation, runOperation } from '../workflows/operations'
|
||||
import { imageRequestNotice, runGuardedImageRequest } from '../subject-images/image-request-guard'
|
||||
import { imageAuthorizationApi } from '../image-authorization/api'
|
||||
import { imageChargeEligibility } from '../image-authorization/model'
|
||||
import { spatialMasterApi } from './api'
|
||||
import { canUseMasterReference, toMasterPreview } from './model'
|
||||
import type { MasterGenerationReceipt, MasterPreview, SceneMaster, SpatialLayout } from './types'
|
||||
@@ -87,16 +90,25 @@ export function useMasterGeneration(
|
||||
(!revisionMode.value ||
|
||||
(!!referenceId.value && !!instruction.value.trim() && instruction.value.trim().length <= 2000))
|
||||
)
|
||||
/** 当前项目授权或生成配置修订。 */
|
||||
const generationRevision = useProjectGenerationRevision()
|
||||
/** 只有本次参数和原件状态完全相同时才保留预览。 */
|
||||
const identity = computed(() =>
|
||||
JSON.stringify([
|
||||
context.value,
|
||||
generationRevision.value,
|
||||
input.value,
|
||||
props.masters.map(item => [item.id, item.status, item.updatedAt, item.imageUrl, item.spatialLayoutVersion])
|
||||
])
|
||||
)
|
||||
/** 只在内存保存本次免费预检,不持久化 Base64。 */
|
||||
const preview = shallowRef<MasterPreview | null>(null)
|
||||
/** 当前预览使用已批准的布局范围,不扩展独立视觉审核授权。 */
|
||||
const charge = shallowRef<{ allowed: boolean; message: string } | null>(null)
|
||||
/** OpenAI 持续授权内无需逐次收费确认。 */
|
||||
const requiresCostConfirmation = computed(() => preview.value?.provider !== 'openai-image')
|
||||
/** 布局生成的当前授权或费用阻断说明。 */
|
||||
const chargeNotice = computed(() => charge.value?.message ?? '')
|
||||
/** 独立确认一次生成费用和范围。 */
|
||||
const acknowledged = ref(false)
|
||||
/** 免费预览加载不锁关闭。 */
|
||||
@@ -110,7 +122,7 @@ export function useMasterGeneration(
|
||||
() =>
|
||||
valid.value &&
|
||||
!!preview.value &&
|
||||
acknowledged.value &&
|
||||
(requiresCostConfirmation.value ? acknowledged.value : charge.value?.allowed === true) &&
|
||||
!loading.value &&
|
||||
!submitting.value &&
|
||||
!props.disabled &&
|
||||
@@ -132,6 +144,7 @@ export function useMasterGeneration(
|
||||
revision++
|
||||
controller?.abort()
|
||||
preview.value = null
|
||||
charge.value = null
|
||||
acknowledged.value = false
|
||||
loading.value = false
|
||||
}
|
||||
@@ -204,6 +217,11 @@ export function useMasterGeneration(
|
||||
result.references.some(item => !item.providerInputResolved)
|
||||
)
|
||||
throw new Error('母版预检与当前输入不一致,请重新核对。')
|
||||
if (result.provider === 'openai-image') {
|
||||
const list = await imageAuthorizationApi.list(projectId, controller.signal)
|
||||
if (disposed || target !== identity.value || current !== revision) return
|
||||
charge.value = imageChargeEligibility(list, 'layout', layoutId, result.model)
|
||||
}
|
||||
preview.value = toMasterPreview(result)
|
||||
} catch (cause) {
|
||||
if (!disposed && target === identity.value && current === revision)
|
||||
@@ -260,6 +278,7 @@ export function useMasterGeneration(
|
||||
throw new Error('生成回执不完整,请先读取任务记录,勿再次生图。')
|
||||
if (!disposed && target === identity.value && requestRevision === revision) {
|
||||
preview.value = null
|
||||
charge.value = null
|
||||
changed(receipt)
|
||||
}
|
||||
return receipt
|
||||
@@ -285,6 +304,7 @@ export function useMasterGeneration(
|
||||
const operation = getOperation(projectId)
|
||||
showActionFeedback(message, operation.error, 'error')
|
||||
preview.value = null
|
||||
charge.value = null
|
||||
if (
|
||||
operation.cause instanceof ApiError &&
|
||||
operation.cause.status === 409 &&
|
||||
@@ -305,6 +325,8 @@ export function useMasterGeneration(
|
||||
selectedReference,
|
||||
valid,
|
||||
preview,
|
||||
requiresCostConfirmation,
|
||||
chargeNotice,
|
||||
acknowledged,
|
||||
loading,
|
||||
submitting,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { imageGenerationDefaults } from '../../generation-config/image-defaults'
|
||||
import { useAssetImageDefaults } from '../../generation-config/image-defaults'
|
||||
import ImageGenerationPreview from '../../subject-images/components/ImageGenerationPreview.vue'
|
||||
import { useImageGenerationPreview, type ImageGenerationSubmission } from '../../subject-images/generation-preview'
|
||||
import ContextNotice from '../../../components/ui/ContextNotice.vue'
|
||||
@@ -11,7 +11,7 @@ import { NButton, NCheckbox, NInput, NSelect } from 'naive-ui'
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { AppDrawer, FieldLabel } from '../../../components/ui'
|
||||
import GenerationModelControls from '../../generation-config/components/GenerationModelControls.vue'
|
||||
import type { CreativeProfile, GenerationModelCatalog, GenerationOptions } from '../../generation-config/types'
|
||||
import type { CreativeProfile, GenerationModelCatalog } from '../../generation-config/types'
|
||||
import { subjectIdentityApi } from '../api'
|
||||
import { currentAnchor, identityViewLabels } from '../model'
|
||||
import type { GenerateIdentityImageInput, IdentityImage, IdentityViewType } from '../types'
|
||||
@@ -47,10 +47,12 @@ const viewType = ref<IdentityViewType>('primary')
|
||||
const referenceImageId = ref('')
|
||||
/** prompt 的当前界面状态与输入绑定。 */
|
||||
const prompt = ref('')
|
||||
/** provider 的当前界面状态与输入绑定。 */
|
||||
const provider = ref('')
|
||||
/** 当前模型参数。 */
|
||||
const generationOptions = ref<GenerationOptions>({})
|
||||
/** 模型初值按项目与主体覆盖解析,用户后续手动选择独立保留。 */
|
||||
const { provider, generationOptions, configLoading, configError } = useAssetImageDefaults(
|
||||
open,
|
||||
() => props.profile,
|
||||
() => props.subjectId
|
||||
)
|
||||
/** anchor 的当前界面状态与输入绑定。 */
|
||||
const anchor = computed(() => currentAnchor(props.images))
|
||||
/** allowedViews 的当前界面状态与输入绑定。 */
|
||||
@@ -79,9 +81,6 @@ watch(
|
||||
: 'primary'
|
||||
referenceImageId.value = ''
|
||||
prompt.value = ''
|
||||
const defaults = imageGenerationDefaults(props.catalog, props.profile)
|
||||
provider.value = defaults.provider
|
||||
generationOptions.value = defaults.options
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
@@ -106,6 +105,8 @@ const generationInput = computed<GenerateIdentityImageInput>(() => ({
|
||||
const {
|
||||
preview,
|
||||
acknowledged,
|
||||
requiresCostConfirmation,
|
||||
chargeNotice,
|
||||
loading: previewLoading,
|
||||
submitting,
|
||||
error: previewError,
|
||||
@@ -116,6 +117,12 @@ const {
|
||||
submit
|
||||
} = useImageGenerationPreview({
|
||||
open,
|
||||
chargeContext: () => ({
|
||||
projectId: props.profile.projectId,
|
||||
scope: 'identity',
|
||||
targetId: props.subjectId,
|
||||
exactPreview: viewType.value === 'primary' && !prompt.value.trim() && !referenceImageId.value
|
||||
}),
|
||||
recoveryTarget: () => (props.subjectId ? 'identity:' + props.subjectId : ''),
|
||||
target: () =>
|
||||
JSON.stringify([props.subjectId, props.images.filter(image => image.status === 'completed'), props.profile]),
|
||||
@@ -154,6 +161,7 @@ const rules = {
|
||||
<ContextNotice type="info" :show-icon="false" class="text-xs">
|
||||
每次生成一张候选图,可能收费。审核通过后需手动设为母版。
|
||||
</ContextNotice>
|
||||
<p v-if="configError" class="text-sm" role="alert">{{ configError }}</p>
|
||||
<!-- 以下是多视角与已有身份图选择模块,单一选项不显示选择器 -->
|
||||
<NFormItem
|
||||
v-if="allowedViews.length > 1"
|
||||
@@ -215,7 +223,7 @@ const rules = {
|
||||
:provider="provider"
|
||||
:options="compatibleOptions"
|
||||
:aspect-ratio="profile.aspectRatio"
|
||||
:disabled="disabled || submitting"
|
||||
:disabled="disabled || submitting || configLoading"
|
||||
@update:provider="provider = $event"
|
||||
@update:options="generationOptions = $event"
|
||||
/>
|
||||
@@ -228,7 +236,9 @@ const rules = {
|
||||
:stale-notice="staleNotice || recoveryNotice"
|
||||
@load="loadPreview"
|
||||
/>
|
||||
<p v-if="chargeNotice" class="text-sm text-muted" role="status">{{ chargeNotice }}</p>
|
||||
<NCheckbox
|
||||
v-if="requiresCostConfirmation"
|
||||
id="identity-image-cost"
|
||||
v-model:checked="acknowledged"
|
||||
:disabled="!preview || submitting"
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
<script setup lang="ts">
|
||||
import { imageGenerationDefaults } from '../../generation-config/image-defaults'
|
||||
import { useAssetImageDefaults } from '../../generation-config/image-defaults'
|
||||
import { NButton, NCheckbox, NCollapse, NCollapseItem, NFormItem, NInput } from 'naive-ui'
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { AppDrawer } from '../../../components/ui'
|
||||
import AppForm from '../../../components/ui/AppForm.vue'
|
||||
import ContextNotice from '../../../components/ui/ContextNotice.vue'
|
||||
import GenerationModelControls from '../../generation-config/components/GenerationModelControls.vue'
|
||||
import type { CreativeProfile, GenerationModelCatalog, GenerationOptions } from '../../generation-config/types'
|
||||
import type { CreativeProfile, GenerationModelCatalog } from '../../generation-config/types'
|
||||
import { subjectImagesApi } from '../api'
|
||||
import { useImageGenerationPreview, type ImageGenerationSubmission } from '../generation-preview'
|
||||
import type { GenerateFormImageInput, SubjectFormAsset } from '../types'
|
||||
@@ -29,10 +29,13 @@ const props = defineProps<{
|
||||
const open = defineModel<boolean>('open', { default: false })
|
||||
/** 仅本次使用的完整描述。 */
|
||||
const prompt = ref('')
|
||||
/** 当前图片供应方。 */
|
||||
const provider = ref('')
|
||||
/** 当前模型动态参数。 */
|
||||
const generationOptions = ref<GenerationOptions>({})
|
||||
/** 模型初值按项目与主体覆盖解析,用户后续手动选择独立保留。 */
|
||||
const { provider, generationOptions, configLoading, configError } = useAssetImageDefaults(
|
||||
open,
|
||||
() => props.profile,
|
||||
() => props.form?.subject.id ?? '',
|
||||
() => props.form?.id ?? ''
|
||||
)
|
||||
/** 预览与生成共用同一份输入。 */
|
||||
const generationInput = computed<GenerateFormImageInput>(() => ({
|
||||
...(prompt.value.trim() ? { prompt: prompt.value.trim() } : {}),
|
||||
@@ -46,6 +49,8 @@ const formModel = computed(() => ({ prompt: prompt.value }))
|
||||
const {
|
||||
preview,
|
||||
acknowledged,
|
||||
requiresCostConfirmation,
|
||||
chargeNotice,
|
||||
loading,
|
||||
submitting,
|
||||
error,
|
||||
@@ -56,6 +61,12 @@ const {
|
||||
submit
|
||||
} = useImageGenerationPreview({
|
||||
open,
|
||||
chargeContext: () => ({
|
||||
projectId: props.profile.projectId,
|
||||
scope: 'form',
|
||||
targetId: props.form!.id,
|
||||
exactPreview: !prompt.value.trim()
|
||||
}),
|
||||
recoveryTarget: () => (props.form ? 'form:' + props.form.id : ''),
|
||||
target: () =>
|
||||
JSON.stringify([props.form?.id, props.form?.generationPrompt, props.form?.subject.identity, props.profile]),
|
||||
@@ -75,9 +86,6 @@ watch(
|
||||
() => [open.value, props.form?.id],
|
||||
() => {
|
||||
prompt.value = ''
|
||||
const defaults = imageGenerationDefaults(props.catalog, props.profile)
|
||||
provider.value = defaults.provider
|
||||
generationOptions.value = defaults.options
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
@@ -121,10 +129,11 @@ watch(
|
||||
:provider="provider"
|
||||
:options="generationOptions"
|
||||
:aspect-ratio="profile.aspectRatio"
|
||||
:disabled="disabled || submitting"
|
||||
:disabled="disabled || submitting || configLoading"
|
||||
@update:provider="provider = $event"
|
||||
@update:options="generationOptions = $event"
|
||||
/>
|
||||
<p v-if="configError" class="text-sm" role="alert">{{ configError }}</p>
|
||||
<!-- 以下是与当前参数绑定的只读预览及费用确认模块 -->
|
||||
<ImageGenerationPreview
|
||||
:preview="preview"
|
||||
@@ -134,7 +143,9 @@ watch(
|
||||
:stale-notice="staleNotice || recoveryNotice"
|
||||
@load="loadPreview"
|
||||
/>
|
||||
<p v-if="chargeNotice" class="text-sm text-muted" role="status">{{ chargeNotice }}</p>
|
||||
<NCheckbox
|
||||
v-if="requiresCostConfirmation"
|
||||
id="confirm-image-cost"
|
||||
v-model:checked="acknowledged"
|
||||
:disabled="!preview || submitting || !!recoveryNotice"
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import { computed, onBeforeUnmount, ref, shallowRef, watch, type Ref } from 'vue'
|
||||
import { imageAuthorizationApi } from '../image-authorization/api'
|
||||
import { imageChargeEligibility } from '../image-authorization/model'
|
||||
import type { ImageAuthorizationScope } from '../image-authorization/types'
|
||||
import { useProjectGenerationRevision } from '../generation-config/context'
|
||||
import { ApiError, errorMessage } from '../../lib/http'
|
||||
import { imageRequestNotice, runGuardedImageRequest } from './image-request-guard'
|
||||
|
||||
@@ -90,6 +94,13 @@ interface PreviewOptions<Input extends object, Preview extends ImageGenerationPr
|
||||
recoveryTarget?: () => string
|
||||
/** 首帧提交前已有候选,供恢复时区分历史记录。 */
|
||||
previousCandidateIds?: () => readonly string[] | undefined
|
||||
/** 当前图片授权归属,仅普通计划允许使用授权预览核对免费复用。 */
|
||||
chargeContext?: () => {
|
||||
/** 所属正式项目。 */ projectId: string
|
||||
/** 正式生成范围。 */ scope: ImageAuthorizationScope
|
||||
/** 当前正式目标。 */ targetId: string
|
||||
/** 免费路由是否完整覆盖当前输入。 */ exactPreview: boolean
|
||||
}
|
||||
/** 当前完整生成参数。 */
|
||||
input: () => Input
|
||||
/** 当前是否允许提交。 */
|
||||
@@ -120,8 +131,20 @@ export function useImageGenerationPreview<Input extends object, Preview extends
|
||||
const error = ref('')
|
||||
/** 过期说明在新预览返回后仍保留,提醒再次确认。 */
|
||||
const staleNotice = ref('')
|
||||
/** 当前预览的 OpenAI 准入结论,未知时不允许收费。 */
|
||||
const charge = shallowRef<{ allowed: boolean; reusable: boolean; message: string } | null>(null)
|
||||
/** 授权保存或撤销使打开的预览失效。 */
|
||||
const authorizationRevision = useProjectGenerationRevision()
|
||||
/** 有效授权内无需逐张收费确认,其它供应方仍独立确认。 */
|
||||
const requiresCostConfirmation = computed(
|
||||
() => preview.value?.provider !== 'openai-image' || !options.chargeContext
|
||||
)
|
||||
/** 授权与未知费用显示在当前生成入口。 */
|
||||
const chargeNotice = computed(() => charge.value?.message ?? '')
|
||||
/** 输入快照同时绑定界面目标和显隐周期。 */
|
||||
const key = computed(() => JSON.stringify([options.open.value, options.target(), options.input()]))
|
||||
const key = computed(() =>
|
||||
JSON.stringify([options.open.value, options.target(), options.input(), authorizationRevision.value])
|
||||
)
|
||||
/** 请求序号防止相同参数的旧响应回填。 */
|
||||
let revision = 0
|
||||
/** 预览请求取消句柄;生成提交不取消或重试。 */
|
||||
@@ -139,7 +162,7 @@ export function useImageGenerationPreview<Input extends object, Preview extends
|
||||
!loading.value &&
|
||||
!recoveryNotice.value &&
|
||||
!!preview.value &&
|
||||
acknowledged.value
|
||||
(requiresCostConfirmation.value ? acknowledged.value : charge.value?.allowed === true)
|
||||
)
|
||||
|
||||
/** 参数或目标变化立即废弃预览和确认。 */
|
||||
@@ -151,6 +174,7 @@ export function useImageGenerationPreview<Input extends object, Preview extends
|
||||
loading.value = false
|
||||
error.value = ''
|
||||
staleNotice.value = ''
|
||||
charge.value = null
|
||||
}
|
||||
watch(key, invalidate, { flush: 'sync' })
|
||||
onBeforeUnmount(invalidate)
|
||||
@@ -185,6 +209,45 @@ export function useImageGenerationPreview<Input extends object, Preview extends
|
||||
result.providerInputSnapshot.references.length !== result.referenceImages.length)
|
||||
)
|
||||
throw new Error('生成预览不完整,请刷新预览后再确认。')
|
||||
const context = options.chargeContext?.()
|
||||
if (result.provider === 'openai-image' && context) {
|
||||
const values = input as Record<string, unknown>
|
||||
let list, planFingerprint: string | undefined
|
||||
if (context.exactPreview && ['identity', 'form', 'keyframe'].includes(context.scope)) {
|
||||
const plan = await imageAuthorizationApi.preview(
|
||||
context.projectId,
|
||||
{
|
||||
scope: context.scope as 'identity' | 'form' | 'keyframe',
|
||||
targetId: context.targetId,
|
||||
providerName: result.provider,
|
||||
generationOptions: values.generationOptions as Record<string, unknown> | undefined,
|
||||
...(typeof values.width === 'number' ? { width: values.width } : {}),
|
||||
...(typeof values.height === 'number' ? { height: values.height } : {})
|
||||
},
|
||||
abort.signal
|
||||
)
|
||||
if (
|
||||
plan.context.projectId !== context.projectId ||
|
||||
plan.context.targetId !== context.targetId ||
|
||||
plan.context.scope !== context.scope ||
|
||||
plan.provider !== result.provider ||
|
||||
(result.providerInputSnapshot &&
|
||||
plan.context.sourceFingerprint !== result.providerInputSnapshot.sourceFingerprint) ||
|
||||
plan.model !== result.model
|
||||
)
|
||||
throw new Error('授权计划与当前预览不匹配,请重新读取。')
|
||||
list = plan.authorization
|
||||
planFingerprint = plan.planFingerprint
|
||||
} else list = await imageAuthorizationApi.list(context.projectId, abort.signal)
|
||||
if (current !== revision || abort.signal.aborted) return
|
||||
charge.value = imageChargeEligibility(
|
||||
list,
|
||||
context.scope,
|
||||
context.targetId,
|
||||
result.model,
|
||||
planFingerprint
|
||||
)
|
||||
}
|
||||
preview.value = result
|
||||
} catch (cause) {
|
||||
if (current === revision && !abort.signal.aborted) error.value = errorMessage(cause)
|
||||
@@ -231,6 +294,7 @@ export function useImageGenerationPreview<Input extends object, Preview extends
|
||||
return
|
||||
}
|
||||
acknowledged.value = false
|
||||
charge.value = null
|
||||
if (
|
||||
result.cause instanceof ApiError &&
|
||||
result.cause.status === 409 &&
|
||||
@@ -247,6 +311,8 @@ export function useImageGenerationPreview<Input extends object, Preview extends
|
||||
}
|
||||
return {
|
||||
preview,
|
||||
requiresCostConfirmation,
|
||||
chargeNotice,
|
||||
acknowledged,
|
||||
loading,
|
||||
submitting,
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/** 用户可操作的图片授权及视频费用审计错误,保留原码用于业务判断。 */
|
||||
const messages: Record<string, string> = {
|
||||
IMAGE_AUTHORIZATION_REQUIRED: '当前模型或范围没有有效图片授权,授权可能已到期或撤销。请核对项目生成设置。',
|
||||
IMAGE_AUTHORIZATION_EXPIRED: '到期时间已过,请重新填写未来时间。',
|
||||
IMAGE_AUTHORIZATION_BUDGET_EXCEEDED: '图片授权剩余预算不足整次预留,或请求次数已用尽。',
|
||||
IMAGE_AUTHORIZATION_CONFLICT: '本次批准与原授权内容冲突。请核对原记录,保留原批准凭据。',
|
||||
IMAGE_AUTHORIZATION_SCOPE_MISMATCH: '授权目标与当前项目或范围不匹配,请核对所选目标。',
|
||||
IMAGE_AUTHORIZATION_MODEL_UNAVAILABLE: 'OpenAI 图片型号当前不可用或与授权不匹配,请核对型号配置。',
|
||||
IMAGE_REQUEST_UNRESOLVED: '原图片请求在途或费用未核清,已禁止新增收费与重试。请先查看原请求。',
|
||||
IMAGE_PROVIDER_AUTHORIZATION_REQUIRED: '此图片供应方需要单独确认,不能使用 OpenAI 授权。',
|
||||
IMAGE_PROVIDER_CONFIRMATION_REQUIRED: '备用图片供应方需要单独确认。请主动选择供应方,重新预览并确认本次费用。',
|
||||
VIDEO_AUDIT_NOT_ELIGIBLE: '此任务不支持费用审计,仅支持原受控视频质检任务。',
|
||||
VIDEO_AUDIT_CONFLICT: '原任务、执行记录或费用批准发生冲突,请刷新后核对原件。',
|
||||
VIDEO_AUDIT_STALE: '原任务或证据集合已变化。已刷新,请重新核对资料和版本后主动提交。',
|
||||
VIDEO_AUDIT_REVIEW_CONFLICT: '另一项人工复核已先完成。已刷新,请重新核对后主动提交。',
|
||||
VIDEO_AUDIT_BINDING_INCOMPLETE: '原请求记录不完整,暂时无法关联审计,请核对原始材料。',
|
||||
VIDEO_AUDIT_IDENTITY_MISMATCH: '证据与原请求身份不一致,或供应方请求已归属另一任务,请核对原件。',
|
||||
VIDEO_AUDIT_RELEASE_REJECTED: '尚未满足费用核清条件,请核对执行原件、账单和唯一关联。',
|
||||
VIDEO_AUDIT_EVIDENCE_INVALID: '原审计记录或摘要无法确认,费用继续阻断,请核对原件。'
|
||||
}
|
||||
/** OpenAI 失败类型分别展示,限流不表示余额耗尽。 */
|
||||
const failureMessages: Record<string, string> = {
|
||||
billing_quota_exceeded: 'OpenAI 返回计费配额不足,请核对原供应方错误及账户配额。',
|
||||
rate_limited: 'OpenAI 请求被限流,请先核对原请求结果和费用。',
|
||||
unsupported_request: 'OpenAI 不支持本次模型或参数,请核对原请求。',
|
||||
network_error: '图片请求连接中断,结果和费用待核对,禁止自动重发。',
|
||||
timeout_unknown: '图片请求超时,结果和费用未知,禁止重试。',
|
||||
receipt_unknown: '图片回执无法确认,费用未知,禁止重试。',
|
||||
provider_error: '图片供应方返回错误,请核对原请求和费用。'
|
||||
}
|
||||
/**
|
||||
* 将费用业务码和原失败类型转换成中文,不改写原始数据。
|
||||
* @param code 原业务码
|
||||
* @param details 原结构化原因
|
||||
* @returns 可操作说明或空值
|
||||
*/
|
||||
export function billingErrorText(code: string | undefined, details: unknown): string | undefined {
|
||||
const record = details && typeof details === 'object' ? (details as Record<string, unknown>) : {}
|
||||
const actualCode = code ?? (typeof record.code === 'string' ? record.code : undefined)
|
||||
if (actualCode && messages[actualCode]) return messages[actualCode]
|
||||
if (actualCode?.startsWith('OPENAI_IMAGE_'))
|
||||
return failureMessages[String(record.failureType)] ?? '图片请求结果或费用尚未核实,请查看原请求,禁止自动重发。'
|
||||
return undefined
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import { billingErrorText } from './billing-errors'
|
||||
import { businessErrorMessages, configurationErrorText, userFacingText } from './user-facing-text'
|
||||
|
||||
/** HTTP 错误携带状态码与后端细节,供页面区别空数据、校验错误与网络故障。 */
|
||||
@@ -118,6 +119,8 @@ export async function optionalResource<T>(promise: Promise<T>): Promise<T | null
|
||||
export function errorMessage(error: unknown): string {
|
||||
const fallback = '操作失败,请刷新后重试。'
|
||||
if (error instanceof ApiError) {
|
||||
const billingMessage = billingErrorText(error.code, error.details)
|
||||
if (billingMessage) return [billingMessage, ...businessErrorMessages(error.details)].join(';')
|
||||
const configurationMessage =
|
||||
configurationErrorText(error.code) ??
|
||||
configurationErrorText(isRecord(error.details) ? error.details.code : undefined)
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>图片授权与视频费用审计 · 隔离验收</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="./billing.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,335 @@
|
||||
import { createApp, defineComponent, h, ref } from 'vue'
|
||||
import { NButton, NConfigProvider, NMessageProvider, NGlobalStyle, zhCN, dateZhCN } from 'naive-ui'
|
||||
import { useTheme } from '../../src/composables/useTheme'
|
||||
import AppDrawer from '../../src/components/ui/AppDrawer.vue'
|
||||
import ActionMessageProvider from '../../src/components/ui/ActionMessageProvider.vue'
|
||||
import ProjectSettingsDialog from '../../src/features/generation-config/components/ProjectSettingsDialog.vue'
|
||||
import KeyframeDialog from '../../src/features/production/components/KeyframeDialog.vue'
|
||||
import VideoAuditPanel from '../../src/features/production/components/VideoAuditPanel.vue'
|
||||
import { billingCatalog, billingProfile, imageAuthorizationsFixture, videoAuditFixture } from '../fixtures/billing'
|
||||
import type { ImageAuthorizationInput, ImageChargeRequest } from '../../src/features/image-authorization/types'
|
||||
import type { RegisterVideoAudit, ReviewVideoAudit } from '../../src/features/production/video-audit.types'
|
||||
import '../../src/styles/styles.css'
|
||||
import '../../src/styles/admin.css'
|
||||
|
||||
/** 浏览器隔离页面的唯一请求记录,不连接真实服务。 */
|
||||
const calls: Array<{ path: string; method: string; body: unknown }> = []
|
||||
/** 每次场景切换都使用新的模拟项目投影。 */
|
||||
let images = imageAuthorizationsFixture()
|
||||
/** 模拟原历史任务,费用处置从不改变原质量。 */
|
||||
let video = videoAuditFixture()
|
||||
/** 仅用于明确制造一次审计并发冲突。 */
|
||||
let conflictNext = false
|
||||
/** 场景重挂,刷新行为只执行读取。 */
|
||||
const revision = ref(0)
|
||||
/** 可从 Chrome 只读核对真实组件发出的请求。 */
|
||||
Object.assign(window, {
|
||||
billingTest: {
|
||||
calls,
|
||||
get images() {
|
||||
return images
|
||||
},
|
||||
get video() {
|
||||
return video
|
||||
},
|
||||
get conflictNext() {
|
||||
return conflictNext
|
||||
},
|
||||
set conflictNext(value: boolean) {
|
||||
conflictNext = value
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
/** 通过 DOM 只读导出隔离请求计数,便于浏览器检查。 */
|
||||
document.addEventListener('billing-probe', () => {
|
||||
document.documentElement.dataset.billingProbe = JSON.stringify({ calls, images, video, conflictNext })
|
||||
})
|
||||
|
||||
/**
|
||||
* 全量拦截当前隔离页的请求,未知接口直接拒绝,无任何真实付费或业务写入。
|
||||
* @param input 请求路径
|
||||
* @param init 原请求参数
|
||||
* @returns 隔离正式结构响应
|
||||
*/
|
||||
window.fetch = async (input, init) => {
|
||||
const path = String(input),
|
||||
method = init?.method ?? 'GET'
|
||||
const body = init?.body ? JSON.parse(String(init.body)) : undefined
|
||||
calls.push({ path, method, body })
|
||||
let data: unknown
|
||||
if (path.endsWith('/generation-models')) data = billingCatalog
|
||||
else if (path.endsWith('/creative-profile')) data = billingProfile
|
||||
else if (path.endsWith('/resolve')) data = { provider: 'openai-image', model: 'gpt-image-2.5-flare', options: {} }
|
||||
else if (path.includes('/workflow-executions/latest')) data = null
|
||||
else if (path.endsWith('/validation/preview'))
|
||||
data = { history: [video.original], blockingTasks: video.audit.billingBlocked ? [video.original] : [] }
|
||||
else if (path.endsWith('/keyframe/preview'))
|
||||
data = {
|
||||
shotId: 'audit-shot',
|
||||
provider: body.provider,
|
||||
model: body.provider === 'openai-image' ? 'gpt-image-2.5-flare' : 'qwen-image-3.0-pro',
|
||||
providerPrompt: '仅供隔离验收的画面描述',
|
||||
previewFingerprint: 'a'.repeat(64),
|
||||
referenceImages: [],
|
||||
generationConfig: { options: {} }
|
||||
}
|
||||
else if (path.endsWith('/keyframe')) data = { id: 'mock-keyframe', shotId: 'audit-shot', status: 'completed' }
|
||||
else if (path.endsWith('/image-authorizations/preview'))
|
||||
data = {
|
||||
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),
|
||||
request: {},
|
||||
currency: 'USD',
|
||||
billingBasis: 'provider_usage',
|
||||
hardProviderCostCap: false,
|
||||
authorization: images
|
||||
}
|
||||
else if (path.endsWith('/image-authorizations') && method === 'GET') data = images
|
||||
else if (path.endsWith('/image-authorizations') && method === 'POST') {
|
||||
const previous = images.authorizations.find(item => item.input.idempotencyKey === body.idempotencyKey)
|
||||
if (previous) data = { authorizationId: previous.id, status: previous.status }
|
||||
else {
|
||||
const id = `mock-grant-${images.authorizations.length}`
|
||||
images.authorizations.push({
|
||||
id,
|
||||
status: 'approved',
|
||||
input: body as ImageAuthorizationInput,
|
||||
expired: false,
|
||||
usedRequests: 0,
|
||||
remainingRequests: body.maxRequests,
|
||||
accountedMicros: 0,
|
||||
remainingMicros: body.budgetMicros,
|
||||
billingBlocked: false
|
||||
})
|
||||
data = { authorizationId: id, status: 'approved' }
|
||||
}
|
||||
} else if (path.endsWith('/revoke')) {
|
||||
const id = path.split('/').at(-2)!
|
||||
images.authorizations.find(item => item.id === id)!.status = 'revoked'
|
||||
data = { authorizationId: id, status: 'revoked' }
|
||||
} else if (path.endsWith('/audit')) data = video.audit
|
||||
else if (path.endsWith('/audit-task')) data = video.original
|
||||
else if (path.endsWith('/audit/evidence')) {
|
||||
const value = body as RegisterVideoAudit
|
||||
const step = video.audit.steps[0]!
|
||||
const previous = step.evidence.find(row => JSON.stringify(row.body) === JSON.stringify(value))
|
||||
const event = previous ?? {
|
||||
id: `mock-evidence-${step.evidence.length}`,
|
||||
createdAt: new Date().toISOString(),
|
||||
taskFingerprint: video.audit.taskFingerprint,
|
||||
stepName: step.name,
|
||||
digest: '1'.repeat(64),
|
||||
body: value
|
||||
}
|
||||
if (!previous) {
|
||||
step.evidence.push(event)
|
||||
video.audit.history.evidence.push(event)
|
||||
step.evidenceSetFingerprint = String(step.evidence.length + 1).repeat(64)
|
||||
step.status = 'unreviewed'
|
||||
video.audit.billingBlocked = true
|
||||
}
|
||||
data = { evidenceId: event.id, reused: !!previous, billingBlocked: true }
|
||||
} else if (path.endsWith('/audit/reviews')) {
|
||||
if (conflictNext) {
|
||||
conflictNext = false
|
||||
video.audit.steps[0]!.reviewFingerprint = '8'.repeat(64)
|
||||
return new Response(JSON.stringify({ code: 'VIDEO_AUDIT_REVIEW_CONFLICT', message: '另一复核先完成' }), {
|
||||
status: 409
|
||||
})
|
||||
}
|
||||
const value = body as ReviewVideoAudit,
|
||||
step = video.audit.steps[0]!
|
||||
const released = value.decision === 'release_future_charges'
|
||||
const event = {
|
||||
id: `mock-review-${step.reviews.length}`,
|
||||
createdAt: new Date().toISOString(),
|
||||
taskFingerprint: video.audit.taskFingerprint,
|
||||
stepName: step.name,
|
||||
digest: '3'.repeat(64),
|
||||
revision: step.reviews.length + 1,
|
||||
body: value
|
||||
}
|
||||
step.reviews.push(event)
|
||||
video.audit.history.reviews.push(event)
|
||||
step.status = released ? 'released' : 'blocked'
|
||||
video.audit.billingBlocked = !released
|
||||
step.reviewFingerprint = '7'.repeat(64)
|
||||
data = { reviewId: event.id, status: step.status, billingBlocked: video.audit.billingBlocked, reused: false }
|
||||
} else return new Response(JSON.stringify({ message: '隔离页拒绝未声明请求' }), { status: 403 })
|
||||
return new Response(JSON.stringify({ data }), { headers: { 'Content-Type': 'application/json' } })
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换隔离数据,所有金额均为测试值,与正式批准无关。
|
||||
* @param kind 本次测试场景
|
||||
*/
|
||||
function scenario(kind: string) {
|
||||
images = imageAuthorizationsFixture()
|
||||
video = videoAuditFixture()
|
||||
const grant = images.authorizations[0]!
|
||||
if (kind === 'expired') {
|
||||
grant.expired = true
|
||||
grant.input.expiresAt = '2000-01-01T00:00:00Z'
|
||||
}
|
||||
if (kind === 'insufficient') grant.remainingMicros = 1
|
||||
if (kind === 'unknown' || kind === 'reusable') {
|
||||
images.billingBlocked = true
|
||||
images.blockingRequestIds = ['original-image-request']
|
||||
const request: ImageChargeRequest = {
|
||||
id: 'original-image-request',
|
||||
status: kind === 'reusable' ? 'completed' : 'unknown',
|
||||
input: {
|
||||
projectId: 'billing-project',
|
||||
authorizationId: grant.id,
|
||||
candidateId: 'original-image',
|
||||
targetId: 'audit-shot',
|
||||
scope: 'keyframe',
|
||||
provider: 'openai-image',
|
||||
model: 'gpt-image-2.5-flare',
|
||||
planFingerprint: 'b'.repeat(64),
|
||||
sourceFingerprint: 'c'.repeat(64),
|
||||
reservedMicros: 500_000,
|
||||
request: { prompt: '隔离原请求' }
|
||||
},
|
||||
output: {
|
||||
usageCostMicros: null,
|
||||
actualBilledMicros: null,
|
||||
...(kind === 'reusable'
|
||||
? { result: { image: 'mock-image' } }
|
||||
: { error: { failureType: 'timeout_unknown' } })
|
||||
}
|
||||
}
|
||||
images.requests.push(request)
|
||||
}
|
||||
revision.value++
|
||||
}
|
||||
/** 使用正式抽屉和表单验收布局,顶栏仅为隔离测试控制。 */
|
||||
const Preview = defineComponent({
|
||||
setup() {
|
||||
/** 正式项目配置抽屉。 */
|
||||
const settingsOpen = ref(false)
|
||||
/** 原首帧生成弹窗。 */
|
||||
const keyframeOpen = ref(false)
|
||||
/** 费用审计使用正式固定底栏。 */
|
||||
const auditOpen = ref(false)
|
||||
/** 真实审计表单公开的底栏入口。 */
|
||||
const auditForm = ref<InstanceType<typeof VideoAuditPanel> | null>(null)
|
||||
return () =>
|
||||
h('main', { style: 'padding:24px;height:100dvh;overflow:auto' }, [
|
||||
h('h1', { style: 'font-size:24px;margin-bottom:16px' }, '图片授权与视频费用审计 · Mock 隔离验收'),
|
||||
h('p', { style: 'margin-bottom:16px' }, '所有请求均拦截在当前页面,不连接真实模型或正式任务。'),
|
||||
h('div', { style: 'display:flex;flex-wrap:wrap;gap:12px;margin-bottom:24px' }, [
|
||||
h(NButton, { onClick: () => (settingsOpen.value = true) }, () => '项目图片授权'),
|
||||
h(NButton, { onClick: () => (keyframeOpen.value = true) }, () => '原首帧生成入口'),
|
||||
h(NButton, { onClick: () => (auditOpen.value = true) }, () => '视频费用审计'),
|
||||
...Object.entries({
|
||||
active: '有效授权',
|
||||
expired: '授权到期',
|
||||
insufficient: '额度不足',
|
||||
unknown: '未知费用',
|
||||
reusable: '同计划免费复用'
|
||||
}).map(([value, label]) => h(NButton, { onClick: () => scenario(value) }, () => label)),
|
||||
h(
|
||||
NButton,
|
||||
{
|
||||
onClick: () => {
|
||||
conflictNext = true
|
||||
}
|
||||
},
|
||||
() => '下一次复核冲突'
|
||||
)
|
||||
]),
|
||||
h(ProjectSettingsDialog, {
|
||||
key: 'settings' + revision.value,
|
||||
projectId: 'billing-project',
|
||||
disabled: false,
|
||||
initialTab: 'image-authorization',
|
||||
open: settingsOpen.value,
|
||||
'onUpdate:open': value => (settingsOpen.value = value)
|
||||
}),
|
||||
h(KeyframeDialog, {
|
||||
key: 'keyframe' + revision.value,
|
||||
shotId: 'audit-shot',
|
||||
projectId: 'billing-project',
|
||||
shotTitle: '隔离首帧',
|
||||
disabled: false,
|
||||
open: keyframeOpen.value,
|
||||
'onUpdate:open': value => (keyframeOpen.value = value),
|
||||
submitGeneration: async input => {
|
||||
await fetch('/api/storyboard-shots/audit-shot/keyframe', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(input)
|
||||
})
|
||||
return { accepted: true }
|
||||
}
|
||||
}),
|
||||
h(
|
||||
AppDrawer,
|
||||
{
|
||||
key: 'audit' + revision.value,
|
||||
open: auditOpen.value,
|
||||
title: '视频费用审计',
|
||||
busy: auditForm.value?.saving,
|
||||
'onUpdate:open': value => (auditOpen.value = value)
|
||||
},
|
||||
{
|
||||
default: () =>
|
||||
auditOpen.value
|
||||
? h(VideoAuditPanel, {
|
||||
ref: auditForm,
|
||||
projectId: 'billing-project',
|
||||
shotId: 'audit-shot',
|
||||
videoId: 'audit-video'
|
||||
})
|
||||
: null,
|
||||
footer: () => [
|
||||
h(
|
||||
NButton,
|
||||
{ disabled: auditForm.value?.saving, onClick: () => (auditOpen.value = false) },
|
||||
() => '关闭'
|
||||
),
|
||||
h(
|
||||
NButton,
|
||||
{
|
||||
type: 'primary',
|
||||
disabled: !auditForm.value?.canSubmit,
|
||||
loading: auditForm.value?.saving,
|
||||
onClick: () => auditForm.value?.submit()
|
||||
},
|
||||
() => auditForm.value?.submitLabel ?? '登记外部证据'
|
||||
)
|
||||
]
|
||||
}
|
||||
)
|
||||
])
|
||||
}
|
||||
})
|
||||
createApp({
|
||||
setup() {
|
||||
/** 隔离页复用正式主题、中文控件与状态色。 */
|
||||
const theme = useTheme()
|
||||
return () =>
|
||||
h(
|
||||
NConfigProvider,
|
||||
{ theme: theme.theme.value, themeOverrides: theme.overrides.value, locale: zhCN, dateLocale: dateZhCN },
|
||||
{
|
||||
default: () => [
|
||||
h(NGlobalStyle),
|
||||
h(
|
||||
NMessageProvider,
|
||||
{},
|
||||
{ default: () => h(ActionMessageProvider, {}, { default: () => h(Preview) }) }
|
||||
)
|
||||
]
|
||||
}
|
||||
)
|
||||
}
|
||||
}).mount('#app')
|
||||
@@ -1,3 +1,4 @@
|
||||
import { generationConfigApi } from '@/features/generation-config/api'
|
||||
import { imageCatalog, generationProfile } from '../../fixtures/generation'
|
||||
import { routerLinkStubs } from '../../fixtures/router'
|
||||
import { defineComponent, h, reactive } from 'vue'
|
||||
@@ -110,6 +111,12 @@ describe('统一的 Naive UI 表单校验', () => {
|
||||
})
|
||||
|
||||
it('图片尺寸采用目录必填枚举,切换目标清空提示词和费用确认', async () => {
|
||||
/** 原图片表单先解析主体覆盖,测试仅提供正式只读配置。 */
|
||||
vi.spyOn(generationConfigApi, 'resolve').mockResolvedValue({
|
||||
provider: creativeProfile.imageProvider,
|
||||
model: creativeProfile.imageModel,
|
||||
options: { ...creativeProfile.imageOptions }
|
||||
})
|
||||
wrapper = mount(GenerateImageDialog, {
|
||||
attachTo: document.body,
|
||||
props: {
|
||||
|
||||
@@ -0,0 +1,211 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { defineComponent, ref } from 'vue'
|
||||
import { mount, flushPromises, type VueWrapper } from '@vue/test-utils'
|
||||
import {
|
||||
usdToMicros,
|
||||
formatMicros,
|
||||
imageChargeEligibility,
|
||||
imageRequestBlockReason
|
||||
} from '@/features/image-authorization/model'
|
||||
import { imageAuthorizationApi } from '@/features/image-authorization/api'
|
||||
import { useImageGenerationPreview, type ImageGenerationSubmission } from '@/features/subject-images/generation-preview'
|
||||
import { ApiError, errorMessage } from '@/lib/http'
|
||||
import { imageAuthorizationsFixture } from '../../fixtures/billing'
|
||||
import { imagePreviewFixture } from '../../fixtures/image-preview'
|
||||
|
||||
/** 每个用例清理表单、费用标记及替身。 */
|
||||
let wrapper: VueWrapper | undefined
|
||||
afterEach(() => {
|
||||
wrapper?.unmount()
|
||||
sessionStorage.clear()
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
/**
|
||||
* 挂载真实共用生成逻辑,只模拟正式读写接口。
|
||||
* @returns 真实表单、用户选择与无费用生成替身
|
||||
*/
|
||||
function setup() {
|
||||
const open = ref(true),
|
||||
provider = ref('openai-image'),
|
||||
project = ref('billing-project')
|
||||
const list = imageAuthorizationsFixture()
|
||||
vi.spyOn(imageAuthorizationApi, 'list').mockResolvedValue(list)
|
||||
const authorizationPreview = vi.spyOn(imageAuthorizationApi, 'preview').mockImplementation(async () => ({
|
||||
provider: provider.value,
|
||||
model: 'gpt-image-2.5-flare',
|
||||
context: {
|
||||
projectId: project.value,
|
||||
scope: 'keyframe',
|
||||
targetId: 'shot',
|
||||
sourceFingerprint: 'c'.repeat(64)
|
||||
},
|
||||
planFingerprint: 'b'.repeat(64),
|
||||
request: {},
|
||||
currency: 'USD',
|
||||
billingBasis: 'provider_usage',
|
||||
hardProviderCostCap: false,
|
||||
authorization: list
|
||||
}))
|
||||
const generate = vi.fn<() => Promise<ImageGenerationSubmission>>(async () => ({ accepted: true }))
|
||||
const load = vi.fn<() => Promise<ReturnType<typeof imagePreviewFixture>>>(async () => ({
|
||||
...imagePreviewFixture(),
|
||||
provider: provider.value,
|
||||
model: 'gpt-image-2.5-flare'
|
||||
}))
|
||||
let flow!: ReturnType<typeof useImageGenerationPreview>
|
||||
wrapper = mount(
|
||||
defineComponent({
|
||||
setup() {
|
||||
flow = useImageGenerationPreview({
|
||||
open,
|
||||
target: () => project.value + ':shot',
|
||||
recoveryTarget: () => 'keyframe:shot',
|
||||
chargeContext: () => ({
|
||||
projectId: project.value,
|
||||
targetId: 'shot',
|
||||
scope: 'keyframe',
|
||||
exactPreview: true
|
||||
}),
|
||||
input: () => ({ provider: provider.value, generationOptions: {} }),
|
||||
disabled: () => false,
|
||||
load,
|
||||
generate
|
||||
})
|
||||
return () => null
|
||||
}
|
||||
})
|
||||
)
|
||||
return { flow, provider, project, list, generate, load, authorizationPreview }
|
||||
}
|
||||
|
||||
describe('OpenAI 图片有限授权及收费门禁', () => {
|
||||
it('美元精确转换,未知金额不显示零,拒绝过多小数与非法金额', () => {
|
||||
expect(usdToMicros('0.123456')).toBe(123456)
|
||||
expect(usdToMicros('5')).toBe(5_000_000)
|
||||
for (const value of ['', '0', '-1', '1e2', '0.0000001', 'Infinity']) expect(usdToMicros(value)).toBeNull()
|
||||
expect(formatMicros(null)).toBe('未知')
|
||||
expect(formatMicros(0)).toBe('USD 0')
|
||||
})
|
||||
it.each(['expired', 'revoked', 'budget', 'requests', 'scope', 'model', 'target'] as const)(
|
||||
'%s 不授予新收费资格',
|
||||
kind => {
|
||||
const list = imageAuthorizationsFixture(),
|
||||
row = list.authorizations[0]!
|
||||
if (kind === 'expired') {
|
||||
row.expired = true
|
||||
row.input.expiresAt = '2000-01-01T00:00:00Z'
|
||||
}
|
||||
if (kind === 'revoked') row.status = 'revoked'
|
||||
if (kind === 'budget') row.remainingMicros = row.input.perRequestMicros - 1
|
||||
if (kind === 'requests') row.remainingRequests = 0
|
||||
if (kind === 'scope') row.input.scopes = ['identity']
|
||||
if (kind === 'model') row.input.models = ['other']
|
||||
if (kind === 'target') row.input.targetIds = ['other']
|
||||
expect(imageChargeEligibility(list, 'keyframe', 'shot', 'gpt-image-2.5-flare').allowed).toBe(false)
|
||||
}
|
||||
)
|
||||
it('有效持续授权无需逐图批准,仍要求原图片预览并防止双击', async () => {
|
||||
const { flow, generate } = setup()
|
||||
expect(flow.canSubmit.value).toBe(false)
|
||||
await flow.loadPreview()
|
||||
expect(flow.requiresCostConfirmation.value).toBe(false)
|
||||
expect(flow.acknowledged.value).toBe(false)
|
||||
expect(flow.canSubmit.value).toBe(true)
|
||||
await Promise.all([flow.submit(), flow.submit()])
|
||||
expect(generate).toHaveBeenCalledExactlyOnceWith({
|
||||
provider: 'openai-image',
|
||||
generationOptions: {},
|
||||
expectedPreviewFingerprint: 'a'.repeat(64)
|
||||
})
|
||||
})
|
||||
it('切换供应方立即撤销原预览,重新预览后必须独立确认', async () => {
|
||||
const { flow, provider, generate } = setup()
|
||||
await flow.loadPreview()
|
||||
provider.value = 'qwen-image'
|
||||
expect(flow.preview.value).toBeNull()
|
||||
await flow.loadPreview()
|
||||
expect(flow.requiresCostConfirmation.value).toBe(true)
|
||||
await flow.submit()
|
||||
expect(generate).not.toHaveBeenCalled()
|
||||
flow.acknowledged.value = true
|
||||
await flow.submit()
|
||||
expect(generate).toHaveBeenCalledOnce()
|
||||
})
|
||||
it('未知费用禁止重试;完整同计划在撤销、到期及项目阻断后仍可免费复用', async () => {
|
||||
const { flow, list, generate } = setup()
|
||||
list.billingBlocked = true
|
||||
await flow.loadPreview()
|
||||
await flow.submit()
|
||||
expect(generate).not.toHaveBeenCalled()
|
||||
const grant = list.authorizations[0]!
|
||||
grant.expired = true
|
||||
grant.status = 'revoked'
|
||||
list.requests.push({
|
||||
id: 'old-request',
|
||||
status: 'completed',
|
||||
input: {
|
||||
projectId: 'billing-project',
|
||||
scope: 'keyframe',
|
||||
targetId: 'shot',
|
||||
candidateId: 'old-candidate',
|
||||
authorizationId: 'grant',
|
||||
provider: 'openai-image',
|
||||
model: 'gpt-image-2.5-flare',
|
||||
sourceFingerprint: 'c'.repeat(64),
|
||||
planFingerprint: 'b'.repeat(64),
|
||||
reservedMicros: 500_000,
|
||||
request: {}
|
||||
},
|
||||
output: { usageCostMicros: null, actualBilledMicros: null, result: { image: 'mock' } }
|
||||
})
|
||||
await flow.loadPreview()
|
||||
expect(flow.chargeNotice.value).toContain('免费复用')
|
||||
await flow.submit()
|
||||
expect(generate).toHaveBeenCalledOnce()
|
||||
expect(list.authorizations[0]!.usedRequests).toBe(0)
|
||||
const original = list.requests[0]!
|
||||
expect(imageRequestBlockReason(original)).toContain('缺少可核验的用量')
|
||||
original.output!.usageCostMicros = original.input.reservedMicros + 1
|
||||
expect(imageRequestBlockReason(original)).toContain('超过单次预留')
|
||||
original.status = 'running'
|
||||
expect(imageRequestBlockReason(original)).toContain('禁止重发')
|
||||
original.status = 'unknown'
|
||||
original.output!.error = { failureType: 'rate_limited' }
|
||||
expect(imageRequestBlockReason(original)).toContain('限流')
|
||||
})
|
||||
it('并发额度拒绝后需重新读取授权,刷新及重新挂载均不重复生成', async () => {
|
||||
const { flow, list, generate, project } = setup()
|
||||
generate.mockResolvedValueOnce({
|
||||
accepted: false,
|
||||
cause: new ApiError('额度不足', 409, undefined, 'IMAGE_AUTHORIZATION_BUDGET_EXCEEDED')
|
||||
} as { accepted: boolean })
|
||||
await flow.loadPreview()
|
||||
await flow.submit()
|
||||
expect(flow.canSubmit.value).toBe(false)
|
||||
list.authorizations[0]!.remainingMicros = 0
|
||||
await flow.loadPreview()
|
||||
await flow.submit()
|
||||
project.value = 'other-project'
|
||||
await flushPromises()
|
||||
expect(flow.preview.value).toBeNull()
|
||||
expect(generate).toHaveBeenCalledOnce()
|
||||
})
|
||||
it('错误区分计费配额与限流、未知回执及供应方切换', () => {
|
||||
expect(
|
||||
errorMessage(new ApiError('429', 502, { failureType: 'rate_limited' }, 'OPENAI_IMAGE_PROVIDER_ERROR'))
|
||||
).toContain('限流')
|
||||
expect(
|
||||
errorMessage(
|
||||
new ApiError('429', 502, { failureType: 'billing_quota_exceeded' }, 'OPENAI_IMAGE_PROVIDER_ERROR')
|
||||
)
|
||||
).toContain('计费配额')
|
||||
expect(
|
||||
errorMessage(
|
||||
new ApiError('unknown', 502, { failureType: 'receipt_unknown' }, 'OPENAI_IMAGE_RECEIPT_INVALID')
|
||||
)
|
||||
).toContain('禁止重试')
|
||||
expect(errorMessage(new ApiError('switch', 409, undefined, 'IMAGE_PROVIDER_CONFIRMATION_REQUIRED'))).toContain(
|
||||
'主动选择'
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,76 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { mount, flushPromises, type VueWrapper } from '@vue/test-utils'
|
||||
import { defineComponent, ref } from 'vue'
|
||||
import { imageGenerationDefaults, useAssetImageDefaults } from '@/features/generation-config/image-defaults'
|
||||
import { generationConfigApi } from '@/features/generation-config/api'
|
||||
import { billingCatalog, billingProfile } from '../../fixtures/billing'
|
||||
import { generationProfile } from '../../fixtures/generation'
|
||||
|
||||
/** 原配置及覆盖在独立组件生命周期中核对。 */
|
||||
let wrapper: VueWrapper | undefined
|
||||
afterEach(() => {
|
||||
wrapper?.unmount()
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
describe('OpenAI 推荐与既有配置的优先级', () => {
|
||||
it('空配置采用后端推荐,现有 Qwen 选择保留,失效选择不自动跨供应方', () => {
|
||||
expect(
|
||||
imageGenerationDefaults(billingCatalog, { ...billingProfile, imageProvider: '', imageOptions: {} }).provider
|
||||
).toBe('openai-image')
|
||||
expect(imageGenerationDefaults(billingCatalog, generationProfile('p')).provider).toBe('qwen-image')
|
||||
expect(
|
||||
imageGenerationDefaults(billingCatalog, { ...billingProfile, imageProvider: 'disabled-provider' }).provider
|
||||
).toBe('')
|
||||
})
|
||||
it('以主体覆盖解析初值,手动选择保留,同主体切换形态重新读取,切项目拒绝旧回填', async () => {
|
||||
const project = ref('p'),
|
||||
form = ref('form-a'),
|
||||
open = ref(true)
|
||||
const resolve = vi
|
||||
.spyOn(generationConfigApi, 'resolve')
|
||||
.mockResolvedValue({ provider: 'qwen-image', model: 'qwen-image-3.0-pro', options: { size: '2048*2048' } })
|
||||
let state!: ReturnType<typeof useAssetImageDefaults>
|
||||
wrapper = mount(
|
||||
defineComponent({
|
||||
setup() {
|
||||
state = useAssetImageDefaults(
|
||||
open,
|
||||
() => ({ ...billingProfile, projectId: project.value }),
|
||||
() => 'subject',
|
||||
() => form.value
|
||||
)
|
||||
return () => null
|
||||
}
|
||||
})
|
||||
)
|
||||
await flushPromises()
|
||||
expect(resolve).toHaveBeenCalledWith(
|
||||
'p',
|
||||
'image',
|
||||
{ target: { targetType: 'asset', targetId: 'subject' } },
|
||||
expect.any(AbortSignal)
|
||||
)
|
||||
expect(state.provider.value).toBe('qwen-image')
|
||||
state.provider.value = 'manual-provider'
|
||||
await flushPromises()
|
||||
expect(state.provider.value).toBe('manual-provider')
|
||||
form.value = 'form-b'
|
||||
await flushPromises()
|
||||
expect(state.provider.value).toBe('qwen-image')
|
||||
expect(resolve).toHaveBeenCalledTimes(2)
|
||||
let finish!: (value: Awaited<ReturnType<typeof generationConfigApi.resolve>>) => void
|
||||
resolve.mockImplementationOnce(
|
||||
() =>
|
||||
new Promise(accept => {
|
||||
finish = accept
|
||||
})
|
||||
)
|
||||
project.value = 'old-project'
|
||||
await flushPromises()
|
||||
project.value = 'new-project'
|
||||
await flushPromises()
|
||||
finish({ provider: 'old-provider', model: 'old-model', options: {} })
|
||||
await flushPromises()
|
||||
expect(state.provider.value).toBe('qwen-image')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,115 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import { NCheckbox, NDatePicker, NInput, NInputNumber, NSelect } from 'naive-ui'
|
||||
import ImageAuthorizationSettings from '@/features/image-authorization/ImageAuthorizationSettings.vue'
|
||||
import { imageAuthorizationApi } from '@/features/image-authorization/api'
|
||||
import { generationConfigApi } from '@/features/generation-config/api'
|
||||
import { ApiError } from '@/lib/http'
|
||||
import { billingCatalog, imageAuthorizationsFixture } from '../../fixtures/billing'
|
||||
|
||||
/** 保持真实 Naive 表单生命周期独立。 */
|
||||
let wrapper: VueWrapper<InstanceType<typeof ImageAuthorizationSettings>> | undefined
|
||||
afterEach(() => {
|
||||
wrapper?.unmount()
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
/**
|
||||
* 创建隔离授权设置,捕获正式登记与撤销输入。
|
||||
* @returns 请求替身及原数据
|
||||
*/
|
||||
async function setup() {
|
||||
const list = imageAuthorizationsFixture()
|
||||
vi.spyOn(generationConfigApi, 'catalog').mockResolvedValue(billingCatalog)
|
||||
vi.spyOn(imageAuthorizationApi, 'list').mockResolvedValue(list)
|
||||
const create = vi
|
||||
.spyOn(imageAuthorizationApi, 'create')
|
||||
.mockResolvedValue({ authorizationId: 'created', status: 'approved' })
|
||||
const revoke = vi.spyOn(imageAuthorizationApi, 'revoke').mockImplementation(async () => {
|
||||
list.authorizations[0]!.status = 'revoked'
|
||||
return { authorizationId: 'grant', status: 'revoked' }
|
||||
})
|
||||
wrapper = mount(ImageAuthorizationSettings, { props: { projectId: 'billing-project', disabled: false } })
|
||||
await flushPromises()
|
||||
return { list, create, revoke }
|
||||
}
|
||||
/** 完整填写用户实际批准的金额、次数、时间与范围。 */
|
||||
async function fill() {
|
||||
const selects = wrapper!.findAllComponents(NSelect)
|
||||
selects[0]!.vm.$emit('update:value', ['gpt-image-2.5-flare'])
|
||||
selects[1]!.vm.$emit('update:value', ['keyframe'])
|
||||
for (const [label, value] of [
|
||||
['累计预算', '1.123456'],
|
||||
['单次预留', '0.123456'],
|
||||
['目标编号', 'shot-1,shot-2'],
|
||||
['批准人', '隔离批准人'],
|
||||
['批准说明', '仅隔离测试']
|
||||
] as const)
|
||||
wrapper!
|
||||
.findAll('label.workspace-form-field')
|
||||
.find(item => item.text().startsWith(label))!
|
||||
.findComponent(NInput)
|
||||
.vm.$emit('update:value', value)
|
||||
wrapper!.findComponent(NInputNumber).vm.$emit('update:value', 3)
|
||||
wrapper!.findComponent(NDatePicker).vm.$emit('update:value', Date.UTC(2099, 0, 1))
|
||||
wrapper!.findComponent(NCheckbox).vm.$emit('update:checked', true)
|
||||
await flushPromises()
|
||||
}
|
||||
|
||||
describe('项目生成设置中的 OpenAI 授权管理', () => {
|
||||
it('打开时金额、次数、日期、批准均为空,不能自动登记', async () => {
|
||||
const { create } = await setup()
|
||||
expect(
|
||||
wrapper!
|
||||
.findAllComponents(NInput)
|
||||
.slice(0, 2)
|
||||
.map(item => item.props('value'))
|
||||
).toEqual(['', ''])
|
||||
expect(wrapper!.findComponent(NInputNumber).props('value')).toBeNull()
|
||||
expect(wrapper!.findComponent(NDatePicker).props('value')).toBeNull()
|
||||
expect(wrapper!.findComponent(NCheckbox).props('checked')).toBe(false)
|
||||
await wrapper!.vm.save()
|
||||
expect(create).not.toHaveBeenCalled()
|
||||
expect(wrapper!.text()).toContain('请完整填写')
|
||||
})
|
||||
it('金额转换为整数微美元且超时后使用原幂等键,不自动重提', async () => {
|
||||
const { create } = await setup()
|
||||
create.mockRejectedValueOnce(new ApiError('网络未知', 0))
|
||||
await fill()
|
||||
await wrapper!.vm.save()
|
||||
expect(create).toHaveBeenCalledOnce()
|
||||
expect(wrapper!.findAllComponents(NInput)[0]!.props('value')).toBe('1.123456')
|
||||
await wrapper!.vm.save()
|
||||
expect(create).toHaveBeenCalledTimes(2)
|
||||
expect(create.mock.calls[0]![1]).toEqual(create.mock.calls[1]![1])
|
||||
expect(create.mock.calls[0]![1]).toMatchObject({
|
||||
mode: 'standing',
|
||||
budgetMicros: 1123456,
|
||||
perRequestMicros: 123456,
|
||||
maxRequests: 3,
|
||||
targetIds: ['shot-1', 'shot-2'],
|
||||
acknowledgeVariableBilling: true,
|
||||
currency: 'USD'
|
||||
})
|
||||
})
|
||||
it('撤销需要明确操作者和原因,保留原授权与历史请求', async () => {
|
||||
const { list, create, revoke } = await setup()
|
||||
await wrapper!
|
||||
.findAll('button')
|
||||
.find(item => item.text() === '撤销此授权')!
|
||||
.trigger('click')
|
||||
await wrapper!.vm.save()
|
||||
expect(revoke).not.toHaveBeenCalled()
|
||||
const inputs = wrapper!.findAllComponents(NInput)
|
||||
inputs[0]!.vm.$emit('update:value', '隔离撤销人')
|
||||
inputs[1]!.vm.$emit('update:value', '停止后续领取')
|
||||
await flushPromises()
|
||||
await wrapper!.vm.save()
|
||||
expect(revoke).toHaveBeenCalledExactlyOnceWith('billing-project', 'grant', {
|
||||
revokedBy: '隔离撤销人',
|
||||
reason: '停止后续领取'
|
||||
})
|
||||
expect(list.authorizations).toHaveLength(1)
|
||||
expect(list.authorizations[0]!.status).toBe('revoked')
|
||||
expect(create).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
@@ -203,6 +203,14 @@ describe('镜头生产数据契约', () => {
|
||||
const fetcher = vi.fn<typeof fetch>().mockImplementation(async url => {
|
||||
const path = String(url)
|
||||
if (path === '/api/generation-models') return new Response(JSON.stringify({ data: imageCatalog }))
|
||||
if (path.endsWith('/generation-config/image/resolve'))
|
||||
return Response.json({
|
||||
data: {
|
||||
provider: 'qwen-image',
|
||||
model: 'qwen-image-3.0-pro',
|
||||
options: generationProfile('project-1').imageOptions
|
||||
}
|
||||
})
|
||||
if (path === '/api/projects/project-1/creative-profile')
|
||||
return new Response(JSON.stringify({ data: generationProfile('project-1') }))
|
||||
const shotId = path.match(/storyboard-shots\/([^/]+)/)?.[1]
|
||||
@@ -285,6 +293,8 @@ describe('镜头生产数据契约', () => {
|
||||
}
|
||||
})
|
||||
)
|
||||
if (path.endsWith('/generation-config/image/resolve'))
|
||||
return Response.json({ data: { provider: 'seedream', model: 'image-model', options: {} } })
|
||||
if (path.includes('/creative-profile')) return new Response(JSON.stringify({ data: null }))
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
|
||||
@@ -206,6 +206,14 @@ describe('精简公开资产回归', () => {
|
||||
const path = String(url)
|
||||
if (path.endsWith('/generation-models')) return Response.json({ data: imageCatalog })
|
||||
if (path.endsWith('/creative-profile')) return Response.json({ data: generationProfile(projectId) })
|
||||
if (path.endsWith('/generation-config/image/resolve'))
|
||||
return Response.json({
|
||||
data: {
|
||||
provider: 'qwen-image',
|
||||
model: 'qwen-image-3.0-pro',
|
||||
options: generationProfile(projectId).imageOptions
|
||||
}
|
||||
})
|
||||
if (path.endsWith('/keyframes')) return Response.json({ data: rows })
|
||||
if (path.endsWith('/keyframe/preview'))
|
||||
return Response.json({
|
||||
|
||||
@@ -0,0 +1,219 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { defineComponent } from 'vue'
|
||||
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import { ApiError } from '@/lib/http'
|
||||
import { useVideoAudit } from '@/features/production/useVideoAudit'
|
||||
import { videoAuditApi } from '@/features/production/video-audit-api'
|
||||
import { auditEvidenceIssues, auditReleaseIssues } from '@/features/production/video-audit'
|
||||
import { workflowExecutionApi } from '@/features/workflows/execution-api'
|
||||
import { videoAuditFixture, videoEvidenceFixture } from '../../fixtures/billing'
|
||||
|
||||
/** 每次释放实际组合逻辑与请求替身。 */
|
||||
let wrapper: VueWrapper | undefined
|
||||
afterEach(() => {
|
||||
wrapper?.unmount()
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
/**
|
||||
* 挂载原视频审计逻辑,仅模拟同步 HTTP 边界。
|
||||
* @returns 原证据、表单、接口及刷新通知
|
||||
*/
|
||||
async function setup() {
|
||||
const { audit, original } = videoAuditFixture()
|
||||
const history = vi
|
||||
.spyOn(videoAuditApi, 'history')
|
||||
.mockResolvedValue({ history: [original], blockingTasks: [original] })
|
||||
vi.spyOn(workflowExecutionApi, 'latest').mockResolvedValue(null)
|
||||
const get = vi.spyOn(videoAuditApi, 'get').mockImplementation(async () => structuredClone(audit))
|
||||
const task = vi.spyOn(videoAuditApi, 'task').mockImplementation(async () => structuredClone(original))
|
||||
const register = vi
|
||||
.spyOn(videoAuditApi, 'register')
|
||||
.mockResolvedValue({ evidenceId: 'event', billingBlocked: true, reused: false })
|
||||
const review = vi
|
||||
.spyOn(videoAuditApi, 'review')
|
||||
.mockResolvedValue({ reviewId: 'review', status: 'released', billingBlocked: false, reused: false })
|
||||
const changed = vi.fn<() => void>()
|
||||
let form!: ReturnType<typeof useVideoAudit>
|
||||
wrapper = mount(
|
||||
defineComponent({
|
||||
setup() {
|
||||
form = useVideoAudit(
|
||||
{ projectId: audit.projectId, shotId: audit.shotId, videoId: original.videoId! },
|
||||
changed
|
||||
)
|
||||
return () => null
|
||||
}
|
||||
})
|
||||
)
|
||||
await flushPromises()
|
||||
return { audit, original, form, get, task, register, review, changed, history }
|
||||
}
|
||||
/**
|
||||
* 填写隔离材料,未知仍可登记,不能据此自动核清。
|
||||
* @param form 原表单
|
||||
*/
|
||||
async function fillEvidence(form: ReturnType<typeof useVideoAudit>) {
|
||||
const evidence = videoEvidenceFixture()
|
||||
form.operator.value = '隔离登记人'
|
||||
form.providerRequestId.value = evidence.providerRequestId!
|
||||
form.correlation.value = evidence.correlation
|
||||
form.artifacts.value = evidence.artifacts
|
||||
form.outcome.value = evidence.execution.outcome
|
||||
form.finding.value = evidence.billing.finding
|
||||
form.amount.value = evidence.billing.amount
|
||||
form.executionIds.value = evidence.execution.evidenceIds
|
||||
form.billingIds.value = evidence.billing.evidenceIds
|
||||
await flushPromises()
|
||||
form.confirmed.value = true
|
||||
}
|
||||
|
||||
describe('视频外部费用审计独立登记与人工复核', () => {
|
||||
it('登记原身份、原任务版本、未知金额,不解除或修改旧质量', async () => {
|
||||
const { audit, original, form, register, review, changed } = await setup()
|
||||
const before = structuredClone(original)
|
||||
await fillEvidence(form)
|
||||
form.amount.value = null
|
||||
form.finding.value = 'unknown'
|
||||
await flushPromises()
|
||||
form.confirmed.value = true
|
||||
await Promise.all([form.submit(), form.submit()])
|
||||
expect(register).toHaveBeenCalledOnce()
|
||||
expect(register.mock.calls[0]![2]).toMatchObject({
|
||||
expectedTaskFingerprint: audit.taskFingerprint,
|
||||
evidence: {
|
||||
identity: audit.steps[0]!.identity,
|
||||
billing: { amount: null, finding: 'unknown', currency: 'USD' }
|
||||
}
|
||||
})
|
||||
expect(review).not.toHaveBeenCalled()
|
||||
expect(original).toEqual(before)
|
||||
expect(changed).toHaveBeenCalledOnce()
|
||||
expect(form.confirmed.value).toBe(false)
|
||||
})
|
||||
it.each(['VIDEO_AUDIT_STALE', 'VIDEO_AUDIT_REVIEW_CONFLICT', 'VIDEO_AUDIT_IDENTITY_MISMATCH'])(
|
||||
'409 %s 刷新版本并保留表单,不自动重新提交',
|
||||
async code => {
|
||||
const { form, register, get, audit, changed } = await setup()
|
||||
await fillEvidence(form)
|
||||
register.mockImplementationOnce(async () => {
|
||||
audit.steps[0]!.reviewFingerprint = '9'.repeat(64)
|
||||
throw new ApiError('版本已变化', 409, undefined, code)
|
||||
})
|
||||
await form.submit()
|
||||
expect(get).toHaveBeenCalledTimes(2)
|
||||
expect(form.operator.value).toBe('隔离登记人')
|
||||
expect(form.providerRequestId.value).toBe('mock-provider-request')
|
||||
expect(form.artifacts.value).toHaveLength(2)
|
||||
expect(form.confirmed.value).toBe(false)
|
||||
await form.submit()
|
||||
expect(register).toHaveBeenCalledOnce()
|
||||
expect(changed).not.toHaveBeenCalled()
|
||||
}
|
||||
)
|
||||
it('核清只提交三个服务端版本并刷新原资源,费用成功不改变过期/待审质量', async () => {
|
||||
const { audit, original, form, review, register, get, task, changed } = await setup()
|
||||
const step = audit.steps[0]!
|
||||
step.evidence.push({
|
||||
id: 'evidence',
|
||||
taskFingerprint: audit.taskFingerprint,
|
||||
stepName: step.name,
|
||||
createdAt: '2026-11-13T00:00:00Z',
|
||||
digest: '1'.repeat(64),
|
||||
body: {
|
||||
operator: '隔离登记人',
|
||||
stepName: step.name,
|
||||
expectedTaskFingerprint: audit.taskFingerprint,
|
||||
evidence: videoEvidenceFixture()
|
||||
}
|
||||
})
|
||||
await form.refresh()
|
||||
form.action.value = 'review'
|
||||
form.evidenceId.value = 'evidence'
|
||||
form.reviewer.value = '隔离复核人'
|
||||
form.reason.value = '核对隔离原件'
|
||||
form.confirmationSha256.value = '3'.repeat(64)
|
||||
await flushPromises()
|
||||
expect(form.releaseIssues.value).toEqual([])
|
||||
form.decision.value = 'release_future_charges'
|
||||
await flushPromises()
|
||||
form.confirmed.value = true
|
||||
const before = structuredClone(original)
|
||||
review.mockImplementationOnce(async () => {
|
||||
audit.billingBlocked = false
|
||||
step.status = 'released'
|
||||
return { reviewId: 'review', status: 'released', billingBlocked: false, reused: false }
|
||||
})
|
||||
await form.submit()
|
||||
expect(review).toHaveBeenCalledExactlyOnceWith(
|
||||
audit.shotId,
|
||||
audit.taskId,
|
||||
expect.objectContaining({
|
||||
expectedTaskFingerprint: audit.taskFingerprint,
|
||||
expectedEvidenceSetFingerprint: step.evidenceSetFingerprint,
|
||||
expectedReviewFingerprint: step.reviewFingerprint,
|
||||
decision: 'release_future_charges'
|
||||
})
|
||||
)
|
||||
expect(register).not.toHaveBeenCalled()
|
||||
expect(original).toEqual(before)
|
||||
expect(form.query.data.value!.original.current).toBe(false)
|
||||
expect(form.query.data.value!.original.needsReview).toBe(true)
|
||||
expect(form.query.data.value!.audit.billingBlocked).toBe(false)
|
||||
expect(get.mock.calls.length).toBeGreaterThan(1)
|
||||
expect(task.mock.calls.length).toBeGreaterThan(1)
|
||||
expect(changed).toHaveBeenCalledOnce()
|
||||
})
|
||||
it('真实原件缺失、歧义、未知费用、币种、原 SDK 事实与本地编号均禁止核清', () => {
|
||||
const { audit } = videoAuditFixture(),
|
||||
step = audit.steps[0]!
|
||||
for (const kind of [
|
||||
'missing',
|
||||
'ambiguous',
|
||||
'unknown',
|
||||
'currency',
|
||||
'sdk',
|
||||
'local',
|
||||
'observability',
|
||||
'not-received'
|
||||
] as const) {
|
||||
const evidence = videoEvidenceFixture(),
|
||||
currentStep = structuredClone(step)
|
||||
if (kind === 'missing') evidence.artifacts = []
|
||||
if (kind === 'ambiguous') evidence.correlation = 'ambiguous'
|
||||
if (kind === 'unknown') evidence.billing.amount = null
|
||||
if (kind === 'currency') evidence.billing.currency = 'CNY'
|
||||
if (kind === 'sdk') currentStep.hasOriginalReceipt = true
|
||||
if (kind === 'local') evidence.providerRequestId = evidence.identity.requestId
|
||||
if (kind === 'observability') evidence.artifacts.forEach(item => (item.kind = 'langsmith'))
|
||||
if (kind === 'not-received') evidence.execution.outcome = 'not-received'
|
||||
expect(auditReleaseIssues(evidence, currentStep, audit).length).toBeGreaterThan(0)
|
||||
}
|
||||
})
|
||||
it('校验重复/缺失原件引用,允许未知声明但不会推断零费用', () => {
|
||||
const evidence = videoEvidenceFixture()
|
||||
evidence.artifacts[1]!.id = 'execution'
|
||||
expect(auditEvidenceIssues(evidence).length).toBeGreaterThan(0)
|
||||
const unknown = videoEvidenceFixture()
|
||||
unknown.correlation = 'unverified'
|
||||
unknown.execution.outcome = 'unknown'
|
||||
unknown.billing.finding = 'unknown'
|
||||
unknown.billing.amount = null
|
||||
expect(auditEvidenceIssues(unknown)).toEqual([])
|
||||
expect(auditReleaseIssues(unknown, videoAuditFixture().audit.steps[0]!, videoAuditFixture().audit)).not.toEqual(
|
||||
[]
|
||||
)
|
||||
})
|
||||
it('原候选过期预检失败后仍允许按原任务号回读,归属错误禁止写入', async () => {
|
||||
const { form, history, get, register, review } = await setup()
|
||||
history.mockRejectedValueOnce(new ApiError('旧候选已过期', 409))
|
||||
await form.discovery.refresh()
|
||||
expect(form.discovery.data.value!.notice).toContain('原任务编号')
|
||||
get.mockImplementationOnce(async () => ({ ...videoAuditFixture().audit, projectId: 'other' }))
|
||||
await form.refresh()
|
||||
form.confirmed.value = true
|
||||
await form.submit()
|
||||
expect(register).not.toHaveBeenCalled()
|
||||
expect(review).not.toHaveBeenCalled()
|
||||
expect(form.query.error.value).toContain('归属')
|
||||
})
|
||||
})
|
||||
@@ -1,3 +1,4 @@
|
||||
import { generationConfigApi } from '@/features/generation-config/api'
|
||||
import { approvedCharacter, imagePreviewFixture } from '../../fixtures/image-preview'
|
||||
import { imageCatalog, generationProfile } from '../../fixtures/generation'
|
||||
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
@@ -20,6 +21,14 @@ import { identityImageFixture } from '@/features/subject-identity/testing/fixtur
|
||||
import { formFixture } from '@/features/subject-images/testing/fixtures'
|
||||
import { selectControl } from '@/testing/naive'
|
||||
|
||||
/** 模型初值通过正式解析接口读取,保留项目已保存参数。 */
|
||||
beforeEach(() => {
|
||||
vi.spyOn(generationConfigApi, 'resolve').mockResolvedValue({
|
||||
provider: creativeProfile.imageProvider,
|
||||
model: creativeProfile.imageModel,
|
||||
options: { ...creativeProfile.imageOptions }
|
||||
})
|
||||
})
|
||||
/** 生成提交由测试替身接收,绝不调用真实模型。 */
|
||||
const submitGeneration = vi.fn<() => Promise<{ accepted: boolean }>>(async () => ({ accepted: true }))
|
||||
let wrapper: VueWrapper | undefined
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { generationConfigApi } from '@/features/generation-config/api'
|
||||
import { validationPreviewResponse } from '../../fixtures/image-preview'
|
||||
import { imagePreviewFixture } from '../../fixtures/image-preview'
|
||||
import { imageCatalog, generationProfile } from '../../fixtures/generation'
|
||||
@@ -13,6 +14,14 @@ import { expandSections } from '@/testing/naive'
|
||||
|
||||
/** 当前测试使用真实目录契约构造项目模型配置。 */
|
||||
const creativeProfile = generationProfile('gallery-test')
|
||||
/** 模型初值通过正式解析接口读取,保留项目已保存参数。 */
|
||||
beforeEach(() => {
|
||||
vi.spyOn(generationConfigApi, 'resolve').mockResolvedValue({
|
||||
provider: creativeProfile.imageProvider,
|
||||
model: creativeProfile.imageModel,
|
||||
options: { ...creativeProfile.imageOptions }
|
||||
})
|
||||
})
|
||||
/** 生成提交由测试替身接收,绝不调用真实模型。 */
|
||||
const submitGeneration = vi.fn<() => Promise<{ accepted: boolean }>>(async () => ({ accepted: true }))
|
||||
let wrapper: VueWrapper | undefined
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { generationConfigApi } from '@/features/generation-config/api'
|
||||
import { imageCatalog, generationProfile } from '../../fixtures/generation'
|
||||
import { defineComponent } from 'vue'
|
||||
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { projectContextKey } from '@/features/projects/context'
|
||||
import { testProjectContext } from '@/testing/project-context'
|
||||
import { getOperation } from '@/features/workflows/operations'
|
||||
@@ -13,6 +14,14 @@ import GenerateImageDialog from '@/features/subject-images/components/GenerateIm
|
||||
|
||||
/** 当前测试使用真实目录契约构造项目模型配置。 */
|
||||
const creativeProfile = generationProfile('gallery-test')
|
||||
/** 模型初值通过正式解析接口读取,保留项目已保存参数。 */
|
||||
beforeEach(() => {
|
||||
vi.spyOn(generationConfigApi, 'resolve').mockResolvedValue({
|
||||
provider: creativeProfile.imageProvider,
|
||||
model: creativeProfile.imageModel,
|
||||
options: { ...creativeProfile.imageOptions }
|
||||
})
|
||||
})
|
||||
/** 生成提交由测试替身接收,绝不调用真实模型。 */
|
||||
const submitGeneration = vi.fn<() => Promise<{ accepted: boolean }>>(async () => ({ accepted: true }))
|
||||
let wrapper: VueWrapper | undefined
|
||||
|
||||
@@ -119,6 +119,15 @@ function stubFetch(fetcher: Mock<typeof fetch>) {
|
||||
}
|
||||
if (path.endsWith('/generation-models')) return jsonResponse(imageCatalog)
|
||||
if (path.endsWith('/creative-profile')) return jsonResponse(generationProfile(fixture.id))
|
||||
/** 主体与首帧表单使用原配置解析接口,不创建图片候选。 */
|
||||
if (path.endsWith('/generation-config/image/resolve')) {
|
||||
const profile = generationProfile(fixture.id)
|
||||
return jsonResponse({
|
||||
provider: profile.imageProvider,
|
||||
model: profile.imageModel,
|
||||
options: profile.imageOptions
|
||||
})
|
||||
}
|
||||
if (path.endsWith('/duration-budget'))
|
||||
return jsonResponse({
|
||||
projectId: fixture.id,
|
||||
|
||||
Vendored
+167
@@ -0,0 +1,167 @@
|
||||
import type { ImageAuthorizationList } from '../../src/features/image-authorization/types'
|
||||
import type {
|
||||
VideoAuditEvidence,
|
||||
VideoAuditView,
|
||||
VideoExecutionDetail
|
||||
} from '../../src/features/production/video-audit.types'
|
||||
import { imageCatalog, generationProfile } from './generation'
|
||||
|
||||
/** 统一隔离模型目录,保留其它供应方用于切换确认。 */
|
||||
export const billingCatalog = {
|
||||
...imageCatalog,
|
||||
defaults: { ...imageCatalog.defaults, imageProvider: 'openai-image' },
|
||||
images: [
|
||||
...imageCatalog.images.map(item => ({ ...item, isDefault: false })),
|
||||
{
|
||||
...imageCatalog.images[0]!,
|
||||
provider: 'openai-image',
|
||||
providerLabel: 'OpenAI',
|
||||
model: 'gpt-image-2.5-flare',
|
||||
modelLabel: 'GPT Image',
|
||||
isDefault: true
|
||||
}
|
||||
]
|
||||
}
|
||||
/** 隔离项目保留明确的 OpenAI 配置。 */
|
||||
export const billingProfile = {
|
||||
...generationProfile('billing-project'),
|
||||
imageProvider: 'openai-image',
|
||||
imageModel: 'gpt-image-2.5-flare'
|
||||
}
|
||||
/**
|
||||
* 创建每个用例独立的授权与余额。
|
||||
* @returns 不连接真实账户的正式投影
|
||||
*/
|
||||
export function imageAuthorizationsFixture(): ImageAuthorizationList {
|
||||
return {
|
||||
authorizations: [
|
||||
{
|
||||
id: 'grant',
|
||||
status: 'approved',
|
||||
expired: false,
|
||||
usedRequests: 0,
|
||||
remainingRequests: 10,
|
||||
accountedMicros: 0,
|
||||
remainingMicros: 5_000_000,
|
||||
billingBlocked: false,
|
||||
input: {
|
||||
idempotencyKey: 'fixture',
|
||||
mode: 'standing',
|
||||
provider: 'openai-image',
|
||||
models: ['gpt-image-2.5-flare'],
|
||||
scopes: ['identity', 'form', 'keyframe', 'layout'],
|
||||
currency: 'USD',
|
||||
budgetMicros: 5_000_000,
|
||||
perRequestMicros: 500_000,
|
||||
maxRequests: 10,
|
||||
expiresAt: '2099-01-01T00:00:00Z',
|
||||
acknowledgeVariableBilling: true,
|
||||
approvedBy: '隔离批准人',
|
||||
approvalNote: '仅供 Mock 测试'
|
||||
}
|
||||
}
|
||||
],
|
||||
requests: [],
|
||||
billingBlocked: false,
|
||||
blockingRequestIds: []
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 构造跨版本原质检任务与原审计,默认完全未知。
|
||||
* @returns 隔离审计和原任务
|
||||
*/
|
||||
export function videoAuditFixture() {
|
||||
const identity = {
|
||||
taskId: 'audit-task',
|
||||
workflowExecutionId: 'audit-workflow',
|
||||
requestId: 'local-request',
|
||||
requestFingerprint: 'a'.repeat(64),
|
||||
planFingerprint: 'b'.repeat(64),
|
||||
sourceFingerprint: 'c'.repeat(64),
|
||||
videoId: 'audit-video',
|
||||
provider: 'vision-provider',
|
||||
model: 'vision-model'
|
||||
}
|
||||
const audit: VideoAuditView = {
|
||||
projectId: 'billing-project',
|
||||
shotId: 'audit-shot',
|
||||
taskId: identity.taskId,
|
||||
workflowExecutionId: identity.workflowExecutionId,
|
||||
currency: 'USD',
|
||||
taskFingerprint: 'd'.repeat(64),
|
||||
originalTaskStatus: 'failed',
|
||||
originalWorkflowStatus: 'failed',
|
||||
billingBlocked: true,
|
||||
steps: [
|
||||
{
|
||||
name: 'spatialInteractionResult',
|
||||
requestStatus: 'unresolved',
|
||||
identity,
|
||||
originalProviderRequestId: null,
|
||||
originalSdkReceiptId: null,
|
||||
hasOriginalReceipt: false,
|
||||
evidenceSetFingerprint: 'e'.repeat(64),
|
||||
reviewFingerprint: 'f'.repeat(64),
|
||||
status: 'unreviewed',
|
||||
released: false,
|
||||
reviewId: null,
|
||||
evidence: [],
|
||||
reviews: []
|
||||
}
|
||||
],
|
||||
history: { evidence: [], reviews: [] }
|
||||
}
|
||||
const original: VideoExecutionDetail = {
|
||||
taskId: identity.taskId,
|
||||
taskStatus: 'failed',
|
||||
executionId: identity.workflowExecutionId,
|
||||
videoId: identity.videoId,
|
||||
needsReview: true,
|
||||
billingBlocked: true,
|
||||
workflowStatus: 'failed',
|
||||
current: false,
|
||||
staleReason: '动作规划已变化',
|
||||
plan: {
|
||||
purpose: 'video_validation',
|
||||
projectId: audit.projectId,
|
||||
shotId: audit.shotId,
|
||||
videoId: identity.videoId,
|
||||
fingerprint: identity.planFingerprint
|
||||
},
|
||||
output: {
|
||||
billing: { actualAmount: null, reason: '原费用未知' },
|
||||
result: { passed: false, qualityDecision: 'needs_review' },
|
||||
steps: [{ name: 'spatialInteractionResult', status: 'unresolved' }]
|
||||
}
|
||||
}
|
||||
return { audit, original }
|
||||
}
|
||||
/**
|
||||
* 构造仅供隔离测试的完整材料声明,绝不提交正式历史任务。
|
||||
* @returns 可供人工核验交互测试的证据包
|
||||
*/
|
||||
export function videoEvidenceFixture(): VideoAuditEvidence {
|
||||
return {
|
||||
identity: videoAuditFixture().audit.steps[0]!.identity,
|
||||
correlation: 'unique',
|
||||
providerRequestId: 'mock-provider-request',
|
||||
artifacts: [
|
||||
{
|
||||
id: 'execution',
|
||||
kind: 'provider-execution',
|
||||
recordId: 'mock-execution',
|
||||
sha256: '1'.repeat(64),
|
||||
reference: '隔离执行原件'
|
||||
},
|
||||
{
|
||||
id: 'bill',
|
||||
kind: 'provider-billing',
|
||||
recordId: 'mock-bill',
|
||||
sha256: '2'.repeat(64),
|
||||
reference: '隔离账单原件'
|
||||
}
|
||||
],
|
||||
execution: { outcome: 'failed', evidenceIds: ['execution'] },
|
||||
billing: { finding: 'charged', amount: 0.12, currency: 'USD', evidenceIds: ['bill'] }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user