fix:"规范音视频任务结果并按真实能力标识音频执行"
- 新增 AsyncTaskResponseNormalizer:解析 content/result/嵌套 data 回执与 {url} 对象,仅白名单媒体字段,裸字符串只接受 URL
- 视频/音频上游完成但无结果文件时标记 deliveryStatus=pending,结算一次、不重发不退款
- 目录与执行共用 AsyncMediaSupport.supportsSpeech;非 TTS 音频、专用渠道任务类型错配、非法语音参数在发送前拒绝
- 任务响应返回 taskType/completedAt,前端以持久任务类型优先,补音频 MIME、签名 URL 与未交付提示
- 新增 29 号 CPR 差距分析与优化方案文档,更新 24 号任务表 MED-01/02/03
验证:mvn -B -o clean verify 399 项通过(独立 PostgreSQL/Redis);前端构建与 27 项测试通过
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
ba5dbc195e
commit
2e53b1d9c8
15 files changed
+493
-83
No files matched your search
@@ -231,6 +231,7 @@ export interface ChatCompletionResult {
|
||||
export interface AsyncTaskResult {
|
||||
id: string
|
||||
model: string
|
||||
taskType?: AsyncMediaType
|
||||
provider?: string
|
||||
status: 'queued' | 'running' | 'reconciling' | 'succeeded' | 'failed' | 'cancelled'
|
||||
requiresReconciliation?: boolean
|
||||
|
||||
@@ -29,7 +29,7 @@ function base64DataUrl(value: unknown, mimeType: unknown, format: string): strin
|
||||
if (!/^[a-z0-9+/]+={0,2}$/i.test(payload) || payload.length % 4 === 1) return undefined
|
||||
const mime = typeof mimeType === 'string' && /^(image|video|audio|model)\/[a-z0-9.+-]+$/i.test(mimeType)
|
||||
? mimeType.toLowerCase()
|
||||
: ({ png: 'image/png', jpg: 'image/jpeg', jpeg: 'image/jpeg', webp: 'image/webp', gif: 'image/gif', mp4: 'video/mp4', webm: 'video/webm', mp3: 'audio/mpeg', wav: 'audio/wav', ogg: 'audio/ogg', glb: 'model/gltf-binary', gltf: 'model/gltf+json' } as Record<string, string>)[format]
|
||||
: ({ png: 'image/png', jpg: 'image/jpeg', jpeg: 'image/jpeg', webp: 'image/webp', gif: 'image/gif', mp4: 'video/mp4', webm: 'video/webm', mp3: 'audio/mpeg', wav: 'audio/wav', ogg: 'audio/ogg', opus: 'audio/ogg', aac: 'audio/aac', flac: 'audio/flac', m4a: 'audio/mp4', glb: 'model/gltf-binary', gltf: 'model/gltf+json' } as Record<string, string>)[format]
|
||||
return mime ? `data:${mime};base64,${payload}` : undefined
|
||||
}
|
||||
|
||||
@@ -47,22 +47,27 @@ export function mediaResult(result: Record<string, unknown> = {}, type = ''): Me
|
||||
const format = typeof result.format === 'string' ? result.format.toLowerCase() : ''
|
||||
const mime = typeof result.mimeType === 'string' ? result.mimeType.toLowerCase() : typeof result.mime_type === 'string' ? result.mime_type.toLowerCase() : ''
|
||||
const url = mediaValue(result.url, mime, format) || base64DataUrl(result.b64_json || result.base64 || result.data, mime, format)
|
||||
const suffix = url ? new URL(url).pathname.toLowerCase().split('.').pop() : ''
|
||||
const suffix = url && !url.startsWith('data:') ? new URL(url).pathname.toLowerCase().match(/\.([a-z0-9]+)$/)?.[1] || '' : ''
|
||||
const isImage = type === '图像' || type === 'image' || mime.startsWith('image/') || /^(png|jpe?g|webp|gif|avif)$/.test(format || suffix || '')
|
||||
const isVideo = type === '视频' || type === 'video' || mime.startsWith('video/') || /^(mp4|webm|mov)$/.test(format || suffix || '')
|
||||
const isAudio = type === '音频' || type === 'audio' || mime.startsWith('audio/') || /^(mp3|wav|ogg|m4a|flac|aac)$/.test(format || suffix || '')
|
||||
const isAudio = type === '音频' || type === 'audio' || mime.startsWith('audio/') || /^(mp3|wav|ogg|opus|m4a|flac|aac)$/.test(format || suffix || '')
|
||||
const isModel = type === '3D' || type === '3d' || /^(glb|gltf|obj|fbx|stl)$/.test(format || suffix || '')
|
||||
return {
|
||||
imageUrl: mediaValue(result.imageUrl, mime, format) || mediaValue(result.image_url, mime, format) || (isImage ? url : undefined),
|
||||
videoUrl: mediaValue(result.videoUrl, mime, format) || mediaValue(result.video_url, mime, format) || (isVideo ? url : undefined),
|
||||
audioUrl: mediaValue(result.audioUrl, mime, format) || mediaValue(result.audio_url, mime, format) || (isAudio ? url : undefined),
|
||||
modelUrl: mediaValue(result.modelUrl, mime, format) || (isModel ? url : undefined),
|
||||
previewUrl: mediaValue(result.previewUrl, mime, format),
|
||||
previewUrl: mediaValue(result.previewUrl, mime, format) || mediaValue(result.preview_url, mime, format) || mediaValue(result.last_frame_url, 'image/png', ''),
|
||||
resultUrl: url,
|
||||
resultFormat: format || suffix,
|
||||
}
|
||||
}
|
||||
|
||||
/** Persisted task kind wins over a missing/edited model catalog entry. */
|
||||
export function taskMediaType(taskType: unknown, fallback: string): string {
|
||||
return ({ video: '视频', audio: '音频', image: '图像', '3d': '3D' } as Record<string, string>)[typeof taskType === 'string' ? taskType.toLowerCase() : ''] || fallback
|
||||
}
|
||||
|
||||
export function mediaTypeLabel(type: string): string {
|
||||
return ({ text: '文本', image: '图片', image_url: '图片', video: '视频', audio: '音频', '3d': '3D', glb: 'GLB 模型', multimodal: '多模态' })[type.toLowerCase()] || type
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ import UiModal from '../components/UiModal.vue'
|
||||
import ModelGroupPermissions from '../components/ModelGroupPermissions.vue'
|
||||
import UsageHistory from '../components/UsageHistory.vue'
|
||||
import MediaResult from '../components/MediaResult.vue'
|
||||
import { generationLabel, mediaResult, mediaTypeLabel, safeMediaUrl } from '../services/media'
|
||||
import { generationLabel, mediaResult, mediaTypeLabel, safeMediaUrl, taskMediaType } from '../services/media'
|
||||
|
||||
defineProps<{ view: string; displayName?: string }>()
|
||||
const emit = defineEmits<{ navigate: [view: string]; notify: [message: string]; balance: [value: number | undefined] }>()
|
||||
@@ -494,10 +494,12 @@ function normalizeAssistantMedia(value: unknown) {
|
||||
}
|
||||
|
||||
function mapAsyncTask(task: AsyncTaskResult, model: ModelItem, taskPrompt?: string): TaskItem {
|
||||
const modelUrl = task.output?.modelUrl || task.result?.modelUrl
|
||||
const videoUrl = task.output?.videoUrl || task.result?.videoUrl
|
||||
const previewUrl = task.output?.previewUrl || task.result?.previewUrl
|
||||
const assets = mediaResult({ ...task.result, ...task.output }, model.type)
|
||||
const type = taskMediaType(task.taskType, model.type)
|
||||
const assets = mediaResult({ ...task.result, ...task.output }, type)
|
||||
const modelUrl = assets.modelUrl
|
||||
const videoUrl = assets.videoUrl
|
||||
const previewUrl = assets.previewUrl
|
||||
const deliveryPending = task.result?.deliveryStatus === 'pending'
|
||||
const imageUrl = assets.imageUrl
|
||||
const audioUrl = assets.audioUrl
|
||||
const resultUrl = assets.resultUrl
|
||||
@@ -513,13 +515,13 @@ function mapAsyncTask(task: AsyncTaskResult, model: ModelItem, taskPrompt?: stri
|
||||
const createdAt = task.createdAt || task.created_at
|
||||
return {
|
||||
id: task.id,
|
||||
name: model.type === '视频' || task.provider === 'seedance' ? '文字生成视频' : model.type === '图像' ? '生成图片' : model.type === '音频' ? '生成音频' : '生成 3D',
|
||||
name: type === '视频' || task.provider === 'seedance' ? '文字生成视频' : type === '图像' ? '生成图片' : type === '音频' ? '生成音频' : '生成 3D',
|
||||
model: model.name,
|
||||
status: statusMap[task.status],
|
||||
progress: task.status === 'succeeded' ? 100 : Math.round(task.progress || 0),
|
||||
createdAt: createdAt ? formatTaskTime(createdAt) : '刚刚',
|
||||
duration: task.completedAt ? '已完成' : task.status === 'reconciling' ? '等待核账' : '计算中',
|
||||
result: task.error?.message || (videoUrl ? '视频已生成' : imageUrl ? '图片已生成' : audioUrl ? '音频已生成' : modelUrl ? 'GLB 模型已生成' : resultUrl ? '文件已生成' : task.status === 'succeeded' ? '异步任务已完成' : task.status === 'running' ? `正在生成 · ${Math.round(task.progress || 0)}%` : '等待平台调度'),
|
||||
result: task.error?.message || (deliveryPending ? '上游生成完成,但结果文件尚未接入;请联系管理员获取,勿重复生成' : videoUrl ? '视频已生成' : imageUrl ? '图片已生成' : audioUrl ? '音频已生成' : modelUrl ? 'GLB 模型已生成' : resultUrl ? '文件已生成' : task.status === 'succeeded' ? '异步任务已完成' : task.status === 'running' ? `正在生成 · ${Math.round(task.progress || 0)}%` : '等待平台调度'),
|
||||
provider: task.provider,
|
||||
prompt: taskPrompt,
|
||||
modelUrl: modelUrl || assets.modelUrl,
|
||||
@@ -528,7 +530,7 @@ function mapAsyncTask(task: AsyncTaskResult, model: ModelItem, taskPrompt?: stri
|
||||
imageUrl,
|
||||
audioUrl,
|
||||
resultUrl,
|
||||
resultFormat: task.output?.format || task.result?.format,
|
||||
resultFormat: assets.resultFormat,
|
||||
creditsConsumed,
|
||||
remote: true,
|
||||
}
|
||||
@@ -563,7 +565,7 @@ async function pollTask(taskId: string, apiKey: string) {
|
||||
// Refresh financial state without encouraging another generation request.
|
||||
await refreshOverview()
|
||||
historyRevision.value++
|
||||
emit('notify', latest.status === 'reconciling' ? `${previous.name}结果尚未确认,额度仍冻结,请联系管理员核账,勿重复提交` : latest.status === 'succeeded' ? `${previous.name}完成,可以查看和保存结果` : `${previous.name}未能完成,请查看错误说明`)
|
||||
emit('notify', latest.status === 'reconciling' ? `${previous.name}结果尚未确认,额度仍冻结,请联系管理员核账,勿重复提交` : latest.result?.deliveryStatus === 'pending' ? '上游已完成,结果文件尚未接入,请联系管理员,勿重复生成' : latest.status === 'succeeded' ? `${previous.name}完成,可以查看和保存结果` : `${previous.name}未能完成,请查看错误说明`)
|
||||
}
|
||||
} catch (error) {
|
||||
taskPollers.delete(taskId)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { test } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { mediaResult, safeMediaUrl } from '../src/services/media.ts'
|
||||
import { mediaResult, safeMediaUrl, taskMediaType } from '../src/services/media.ts'
|
||||
|
||||
test('mediaResult keeps provider URLs in their declared media lane', () => {
|
||||
const result = mediaResult({ url: 'https://cdn.example.test/result.mp4', format: 'mp4' }, '视频')
|
||||
@@ -24,3 +24,20 @@ test('mediaResult supports provider base64 output and nested media objects', ()
|
||||
assert.match(nested.imageUrl, /^data:image\/png;base64,iVBORw0KGgo=$/)
|
||||
assert.equal(safeMediaUrl('data:text/html;base64,PGh0bWw+'), undefined)
|
||||
})
|
||||
|
||||
test('persisted task type wins over a missing or edited catalog entry', () => {
|
||||
assert.equal(taskMediaType('video', '3D'), '视频')
|
||||
assert.equal(taskMediaType('AUDIO', '3D'), '音频')
|
||||
assert.equal(taskMediaType(undefined, '图像'), '图像')
|
||||
const video = mediaResult({ url: 'https://cdn.example.test/v?sig=abc' }, taskMediaType('video', '3D'))
|
||||
assert.equal(video.videoUrl, 'https://cdn.example.test/v?sig=abc')
|
||||
assert.equal(video.modelUrl, undefined)
|
||||
})
|
||||
|
||||
test('audio base64 without a file suffix plays as audio', () => {
|
||||
const audio = mediaResult({ base64: 'ZmFrZQ==', format: 'opus' }, '音频')
|
||||
assert.equal(audio.audioUrl, 'data:audio/ogg;base64,ZmFrZQ==')
|
||||
assert.equal(audio.resultFormat, 'opus')
|
||||
const frame = mediaResult({ video_url: 'https://cdn.example.test/a.mp4', last_frame_url: 'https://cdn.example.test/a.png' }, '视频')
|
||||
assert.equal(frame.previewUrl, 'https://cdn.example.test/a.png')
|
||||
})
|
||||
Reference in new issue
Block a user