From 9a946b29e639595c3d99fbc42667642a5c896931 Mon Sep 17 00:00:00 2001 From: WangLX <519407855@qq.com> Date: Mon, 28 Sep 2026 23:51:27 +0800 Subject: [PATCH] feat: improve media playground inputs and outputs --- prototype/package.json | 2 +- prototype/src/components/MediaResult.vue | 36 ++++++++ prototype/src/services/catalog.ts | 42 +++++---- prototype/src/services/media.ts | 46 +++++++++ prototype/src/types.ts | 7 ++ prototype/src/views/UserConsole.vue | 113 ++++++++++++++++++----- prototype/tests/media.test.mjs | 18 ++++ 7 files changed, 225 insertions(+), 39 deletions(-) create mode 100644 prototype/src/components/MediaResult.vue create mode 100644 prototype/src/services/media.ts create mode 100644 prototype/tests/media.test.mjs diff --git a/prototype/package.json b/prototype/package.json index ce63818..9b07f25 100644 --- a/prototype/package.json +++ b/prototype/package.json @@ -4,7 +4,7 @@ "version": "0.1.0", "type": "module", "scripts": { - "test": "node --experimental-strip-types --test tests/chat-stream.test.mjs tests/model-catalog.test.mjs tests/pricing.test.mjs", + "test": "node --experimental-strip-types --test tests/chat-stream.test.mjs tests/model-catalog.test.mjs tests/pricing.test.mjs tests/media.test.mjs", "dev": "vite", "build": "vue-tsc --noEmit && vite build", "preview": "vite preview" diff --git a/prototype/src/components/MediaResult.vue b/prototype/src/components/MediaResult.vue new file mode 100644 index 0000000..d3880b8 --- /dev/null +++ b/prototype/src/components/MediaResult.vue @@ -0,0 +1,36 @@ + + + + + diff --git a/prototype/src/services/catalog.ts b/prototype/src/services/catalog.ts index 5ed0c6e..9d36ec6 100644 --- a/prototype/src/services/catalog.ts +++ b/prototype/src/services/catalog.ts @@ -1,5 +1,6 @@ export type CatalogModelType = 'text' | 'code' | 'multimodal' | 'image' | 'audio' | 'video' | 'embedding' | '3d' export type CatalogCallMode = 'sync' | 'stream' | 'async' +export type AsyncMediaType = '3d' | 'video' | 'image' | 'audio' export interface CatalogProvider { id: string @@ -230,12 +231,21 @@ export interface AsyncTaskResult { updated_at?: string createdAt?: string completedAt?: string - result?: { format?: string; url?: string; modelUrl?: string; previewUrl?: string; videoUrl?: string; creditsConsumed?: number; [key: string]: unknown } - output?: { modelUrl?: string; previewUrl?: string; videoUrl?: string } + result?: { format?: string; url?: string; modelUrl?: string; previewUrl?: string; videoUrl?: string; imageUrl?: string; audioUrl?: string; mimeType?: string; creditsConsumed?: number; [key: string]: unknown } + output?: { modelUrl?: string; previewUrl?: string; videoUrl?: string; imageUrl?: string; audioUrl?: string; url?: string; format?: string; mimeType?: string } creditsConsumed?: number error?: { code?: number; message?: string } } +/** OpenAI-compatible multimodal content. Keep text-only calls byte-for-byte compatible. */ +function userMessage(prompt: string, mediaUrl?: string): string | Array> { + if (!mediaUrl) return prompt + return [ + { type: 'text', text: prompt }, + { type: 'image_url', image_url: { url: mediaUrl } }, + ] +} + export class CatalogApiError extends Error { constructor(readonly status: number, message: string, readonly code?: string) { super(message) @@ -327,27 +337,27 @@ class HttpCatalogClient { return response.blob() } - async chatCompletion(apiKey: string, input: { model: string; prompt: string; maxTokens?: number }) { + async chatCompletion(apiKey: string, input: { model: string; prompt: string; maxTokens?: number; mediaUrl?: string }) { return this.request('/v1/chat/completions', { method: 'POST', headers: { Authorization: `Bearer ${apiKey}`, 'X-Moyi-Source': 'playground', 'Idempotency-Key': crypto.randomUUID() }, - body: JSON.stringify({ model: input.model, messages: [{ role: 'user', content: input.prompt }], max_tokens: input.maxTokens || 4096 }), + body: JSON.stringify({ model: input.model, messages: [{ role: 'user', content: userMessage(input.prompt, input.mediaUrl) }], max_tokens: input.maxTokens || 4096 }), }) } - async playgroundChatCompletion(keyId: string, input: { model: string; prompt: string; maxTokens?: number }) { + async playgroundChatCompletion(keyId: string, input: { model: string; prompt: string; maxTokens?: number; mediaUrl?: string }) { return this.request(`/api/playground/keys/${encodeURIComponent(keyId)}/chat/completions`, { method: 'POST', headers: { 'X-Moyi-Source': 'playground', 'Idempotency-Key': crypto.randomUUID() }, - body: JSON.stringify({ model: input.model, messages: [{ role: 'user', content: input.prompt }], max_tokens: input.maxTokens || 4096 }), + body: JSON.stringify({ model: input.model, messages: [{ role: 'user', content: userMessage(input.prompt, input.mediaUrl) }], max_tokens: input.maxTokens || 4096 }), }) } - async streamChat(apiKey: string, input: { model: string; prompt: string; maxTokens: number }, onDelta: (content: string, reasoning: string) => void, signal: AbortSignal) { + async streamChat(apiKey: string, input: { model: string; prompt: string; maxTokens: number; mediaUrl?: string }, onDelta: (content: string, reasoning: string) => void, signal: AbortSignal) { const response = await fetch(`${this.baseUrl}/v1/chat/completions`, { method: 'POST', credentials: 'include', signal, headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${apiKey}`, 'X-Moyi-Source': 'playground', 'Idempotency-Key': crypto.randomUUID() }, - body: JSON.stringify({ model: input.model, messages: [{ role: 'user', content: input.prompt }], stream: true, max_tokens: input.maxTokens }), + body: JSON.stringify({ model: input.model, messages: [{ role: 'user', content: userMessage(input.prompt, input.mediaUrl) }], stream: true, max_tokens: input.maxTokens }), }) if (!response.ok) { const error = await response.json().catch(() => ({})) @@ -358,11 +368,11 @@ class HttpCatalogClient { await readChatStream(response.body, onDelta) } - async playgroundStreamChat(keyId: string, input: { model: string; prompt: string; maxTokens: number }, onDelta: (content: string, reasoning: string) => void, signal: AbortSignal) { + async playgroundStreamChat(keyId: string, input: { model: string; prompt: string; maxTokens: number; mediaUrl?: string }, onDelta: (content: string, reasoning: string) => void, signal: AbortSignal) { const response = await fetch(`${this.baseUrl}/api/playground/keys/${encodeURIComponent(keyId)}/chat/completions`, { method: 'POST', credentials: 'include', signal, headers: { 'Content-Type': 'application/json', 'X-Moyi-Source': 'playground', 'Idempotency-Key': crypto.randomUUID() }, - body: JSON.stringify({ model: input.model, messages: [{ role: 'user', content: input.prompt }], stream: true, max_tokens: input.maxTokens }), + body: JSON.stringify({ model: input.model, messages: [{ role: 'user', content: userMessage(input.prompt, input.mediaUrl) }], stream: true, max_tokens: input.maxTokens }), }) if (!response.ok) { const error = await response.json().catch(() => ({})) @@ -373,18 +383,18 @@ class HttpCatalogClient { await readChatStream(response.body, onDelta) } - async createMediaTask(apiKey: string, input: { model: string; prompt: string; mediaType: '3d' | 'video' }) { - const payload = await this.request<{ task: AsyncTaskResult }>(input.mediaType === 'video' ? '/v1/video/tasks' : '/v1/3d/tasks', { + async createMediaTask(apiKey: string, input: { model: string; prompt: string; mediaType: AsyncMediaType; mediaUrl?: string }) { + const payload = await this.request<{ task: AsyncTaskResult }>(`/v1/${input.mediaType}/tasks`, { method: 'POST', headers: { Authorization: `Bearer ${apiKey}`, 'X-Moyi-Source': 'playground' }, - body: JSON.stringify({ model: input.model, prompt: input.prompt }), + body: JSON.stringify({ model: input.model, prompt: input.prompt, ...(input.mediaUrl ? { media_url: input.mediaUrl } : {}) }), }) return payload.task } - async playgroundCreateMediaTask(keyId: string, input: { model: string; prompt: string; mediaType: '3d' | 'video' }) { - const payload = await this.request<{ task: AsyncTaskResult }>(`/api/playground/keys/${encodeURIComponent(keyId)}/${input.mediaType === 'video' ? 'video' : '3d'}/tasks`, { - method: 'POST', headers: { 'X-Moyi-Source': 'playground' }, body: JSON.stringify({ model: input.model, prompt: input.prompt }), + async playgroundCreateMediaTask(keyId: string, input: { model: string; prompt: string; mediaType: AsyncMediaType; mediaUrl?: string }) { + const payload = await this.request<{ task: AsyncTaskResult }>(`/api/playground/keys/${encodeURIComponent(keyId)}/${input.mediaType}/tasks`, { + method: 'POST', headers: { 'X-Moyi-Source': 'playground' }, body: JSON.stringify({ model: input.model, prompt: input.prompt, ...(input.mediaUrl ? { media_url: input.mediaUrl } : {}) }), }) return payload.task } diff --git a/prototype/src/services/media.ts b/prototype/src/services/media.ts new file mode 100644 index 0000000..836a911 --- /dev/null +++ b/prototype/src/services/media.ts @@ -0,0 +1,46 @@ +export interface MediaResult { + imageUrl?: string + videoUrl?: string + audioUrl?: string + modelUrl?: string + previewUrl?: string + resultUrl?: string + resultFormat?: string +} + +export function safeMediaUrl(value: unknown): string | undefined { + if (typeof value !== 'string' || !value.trim()) return undefined + try { + const url = new URL(value) + return url.protocol === 'https:' || url.protocol === 'http:' ? url.href : undefined + } catch { return undefined } +} + +/** Normalize generation assets without treating every provider's generic URL as a 3D model. */ +export function mediaResult(result: Record = {}, type = ''): MediaResult { + const format = typeof result.format === 'string' ? result.format.toLowerCase() : '' + const url = safeMediaUrl(result.url) + const mime = typeof result.mimeType === 'string' ? result.mimeType.toLowerCase() : '' + const suffix = url ? new URL(url).pathname.toLowerCase().split('.').pop() : '' + 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 isModel = type === '3D' || type === '3d' || /^(glb|gltf|obj|fbx|stl)$/.test(format || suffix || '') + return { + imageUrl: safeMediaUrl(result.imageUrl) || (isImage ? url : undefined), + videoUrl: safeMediaUrl(result.videoUrl) || (isVideo ? url : undefined), + audioUrl: safeMediaUrl(result.audioUrl) || (isAudio ? url : undefined), + modelUrl: safeMediaUrl(result.modelUrl) || (isModel ? url : undefined), + previewUrl: safeMediaUrl(result.previewUrl), + resultUrl: url, + resultFormat: format || suffix, + } +} + +export function mediaTypeLabel(type: string): string { + return ({ text: '文本', image: '图片', image_url: '图片', video: '视频', audio: '音频', '3d': '3D', glb: 'GLB 模型', multimodal: '多模态' })[type.toLowerCase()] || type +} + +export function generationLabel(type: string): string { + return ({ 视频: '生成视频', 图像: '生成图片', 音频: '生成音频', '3D': '生成 3D' })[type] || '提交任务' +} diff --git a/prototype/src/types.ts b/prototype/src/types.ts index 4285c1a..e6d1cec 100644 --- a/prototype/src/types.ts +++ b/prototype/src/types.ts @@ -29,6 +29,9 @@ export interface ModelItem { description: string latency: string specification: string + /** Declared media accepted and returned by this model route. */ + inputTypes?: string[] + outputTypes?: string[] availability: string accent: string icon: Component @@ -82,6 +85,10 @@ export interface TaskItem { modelUrl?: string videoUrl?: string previewUrl?: string + imageUrl?: string + audioUrl?: string + resultUrl?: string + resultFormat?: string creditsConsumed?: number remote?: boolean } diff --git a/prototype/src/views/UserConsole.vue b/prototype/src/views/UserConsole.vue index 365a3ef..f0642ff 100644 --- a/prototype/src/views/UserConsole.vue +++ b/prototype/src/views/UserConsole.vue @@ -37,7 +37,7 @@ import { Zap, } from 'lucide-vue-next' import type { ApiKeyItem, CallMode, ModelItem, ModelType, TaskItem, TaskStatus } from '../types' -import { catalogClient, platformApiBaseUrl, type AsyncTaskResult, type CatalogApiKey, type CatalogModel, type LogicalModel, type CatalogProject, type PlatformOverview, type UserUsageRecord } from '../services/catalog' +import { catalogClient, platformApiBaseUrl, type AsyncMediaType, type AsyncTaskResult, type CatalogApiKey, type CatalogModel, type LogicalModel, type CatalogProject, type PlatformOverview, type UserUsageRecord } from '../services/catalog' import { buildModelCatalog } from '../services/model-catalog' import { groupDiscountLabel as formatGroupDiscountLabel, modelStandardPriceLabel, platformPriceLabel } from '../services/pricing' import { usePagination } from '../composables/usePagination' @@ -47,6 +47,8 @@ import SlidePanel from '../components/SlidePanel.vue' 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' defineProps<{ view: string; displayName?: string }>() const emit = defineEmits<{ navigate: [view: string]; notify: [message: string]; balance: [value: number | undefined] }>() @@ -76,19 +78,21 @@ const playgroundModels = computed(() => [...new Map(catalogModels.value.map(grou const playgroundGroups = computed(() => catalogModels.value.filter(group => (group.logicalModelId || group.id) === (activeModel.value.logicalModelId || activeModel.value.id))) function selectPlaygroundGroup(id: string) { const group = catalogModels.value.find(item => item.id === id) - if (group) { activeModel.value = group; callMode.value = group.mode; response.value = ''; reasoningOutput.value = ''; finishReason.value = ''; activeTaskId.value = '' } + if (group) { activeModel.value = group; callMode.value = group.mode; response.value = ''; responseMedia.value = {}; responseError.value = ''; mediaUrl.value = ''; reasoningOutput.value = ''; finishReason.value = ''; activeTaskId.value = '' } } function selectPlaygroundModel(id: string) { const group = catalogModels.value.find(item => (item.logicalModelId || item.id) === id) if (group) selectPlaygroundGroup(group.id) } const prompt = ref('') +const mediaUrl = ref('') const running = ref(false) const maxOutputTokens = ref(4096) const reasoningOutput = ref('') const finishReason = ref('') let streamAbort: AbortController | undefined const response = ref('') +const responseMedia = ref>({}) const responseError = ref('') const keys = ref([]) const { page: keyPage, pageSize: keyPageSize, pagedItems: pagedKeys } = usePagination(keys) @@ -129,6 +133,27 @@ const selectedApiKeyId = ref('') const activeDebugKeys = computed(() => keys.value.filter((key) => key.status === '正常')) const selectedDebugKey = computed(() => activeDebugKeys.value.find((key) => String(key.id) === selectedApiKeyId.value)) const debugKeyCanInvoke = computed(() => !!selectedDebugKey.value?.modelIds.includes(activeModel.value.id)) +const activeMediaKind = computed(() => { + if (activeModel.value.type === '3D') return '3d' + if (activeModel.value.type === '视频') return 'video' + if (activeModel.value.type === '图像') return 'image' + if (activeModel.value.type === '音频') return 'audio' + return undefined +}) +const activeInputTypes = computed(() => activeModel.value.inputTypes || []) +const activeOutputTypes = computed(() => activeModel.value.outputTypes || []) +const activeAsyncSupported = computed(() => activeModel.value.mode !== '异步' || (!!activeMediaKind.value && activeModel.value.executionReady !== false)) +const supportsMediaInput = computed(() => activeInputTypes.value.some(input => /image|audio|video|url|media/i.test(input))) +const activeModelReady = computed(() => activeModel.value.pricingConfigured === true && activeModel.value.billingReady !== false && activeModel.value.executionReady !== false && activeAsyncSupported.value) +const submitLabel = computed(() => callMode.value === '异步' ? generationLabel(activeModel.value.type) : '开始调用') +const promptPlaceholder = computed(() => ({ + '文本': '描述你希望模型完成的任务', + '多模态': '描述你希望模型完成的任务,也可以附加媒体地址', + '视频': '例如:电影感产品展示视频,柔和运镜与自然光影', + '图像': '例如:一只坐在窗边的橘猫,温暖日光,水彩插画', + '音频': '请输入希望生成的语音文字或描述音频内容', + '3D': '例如:一个低面数的木质机械鸟,游戏资产风格', +} as Record)[activeModel.value.type] || '描述你希望模型完成的任务') const catalogConnected = ref(false) const overviewLoaded = ref(false) const overview = ref({ generatedAt: '', callsToday: 0, callsThisMonth: 0, asyncTasks: 0, tasks: { queued: 0, running: 0, succeeded: 0, failed: 0 }, series: [], ledger: [] }) @@ -293,6 +318,7 @@ function tryModel(model: GalleryModel) { callMode.value = group.mode selectedModel.value = null response.value = '' + responseMedia.value = {} reasoningOutput.value = '' finishReason.value = '' emit('navigate', 'playground') @@ -300,7 +326,7 @@ function tryModel(model: GalleryModel) { async function runModel() { if (!activeModel.value.id) return emit('notify', '当前没有可调用的模型,请先检查模型目录') - if (!prompt.value.trim()) return emit('notify', '请先输入调用内容') + if (!prompt.value.trim() && !mediaUrl.value.trim()) return emit('notify', '请先输入调用内容或媒体 URL') if (running.value) return if (callMode.value !== '异步' && (!Number.isInteger(maxOutputTokens.value) || maxOutputTokens.value < 1 || maxOutputTokens.value > 32768)) return emit('notify', '最大输出 Token 须为 1–32768 的整数') if (!catalogConnected.value) return emit('notify', 'Control Plane 未连接,无法提交真实调用') @@ -310,15 +336,19 @@ async function runModel() { return } if (!debugKeyCanInvoke.value) return emit('notify', '该 Key 尚未授权当前模型分组,请切换 Key 或修改模型权限') + if (callMode.value === '异步' && !activeAsyncSupported.value) return emit('notify', '当前媒体类型尚未配置异步执行器,暂时不能调用') + if (!activeModelReady.value) return emit('notify', '该分组尚未完成执行或计费配置,暂时不能调用') + if (mediaUrl.value.trim() && !safeMediaUrl(mediaUrl.value.trim())) return emit('notify', '请输入有效的 http 或 https 图片地址') running.value = true response.value = '' + responseMedia.value = {} responseError.value = '' reasoningOutput.value = '' finishReason.value = '' const selectedMode = callMode.value try { if (callMode.value === '异步') { - const task = await catalogClient.playgroundCreateMediaTask(apiKey, { model: activeModel.value.id, prompt: prompt.value, mediaType: activeModel.value.type === '视频' ? 'video' : '3d' }) + const task = await catalogClient.playgroundCreateMediaTask(apiKey, { model: activeModel.value.id, prompt: prompt.value, mediaUrl: mediaUrl.value.trim() || undefined, mediaType: activeMediaKind.value! }) const taskItem = mapAsyncTask(task, activeModel.value, prompt.value) tasks.value.unshift(taskItem) activeTaskId.value = task.id @@ -326,15 +356,16 @@ async function runModel() { scheduleTaskPoll(task.id, apiKey) } else if (selectedMode === '流式') { streamAbort = new AbortController() - await catalogClient.playgroundStreamChat(apiKey, { model: activeModel.value.id, prompt: prompt.value, maxTokens: maxOutputTokens.value }, (text, reasoning) => { response.value += text; reasoningOutput.value += reasoning }, streamAbort.signal) + await catalogClient.playgroundStreamChat(apiKey, { model: activeModel.value.id, prompt: prompt.value, mediaUrl: mediaUrl.value.trim() || undefined, maxTokens: maxOutputTokens.value }, (text, reasoning) => { response.value += text; reasoningOutput.value += reasoning }, streamAbort.signal) } else { - const result = await catalogClient.playgroundChatCompletion(apiKey, { model: activeModel.value.id, prompt: prompt.value, maxTokens: maxOutputTokens.value }) + const result = await catalogClient.playgroundChatCompletion(apiKey, { model: activeModel.value.id, prompt: prompt.value, mediaUrl: mediaUrl.value.trim() || undefined, maxTokens: maxOutputTokens.value }) const choice = result.choices[0] const message = choice?.message const reasoning = typeof message?.reasoning_content === 'string' ? message.reasoning_content : typeof message?.reasoning === 'string' ? message.reasoning : '' reasoningOutput.value = reasoning finishReason.value = typeof choice?.finish_reason === 'string' ? choice.finish_reason : '' const content = normalizeAssistantContent(message?.content) + responseMedia.value = normalizeAssistantMedia(message?.content) // Keep reasoning separate from the final answer. A small output budget // can legitimately end after reasoning; leave that choice to the user. response.value = content || (reasoning ? '模型仅返回了思考过程,未返回最终答案;可调整最大输出 Token 后重试。' : '模型未返回内容') @@ -361,10 +392,29 @@ function normalizeAssistantContent(value: unknown): string { }).join('') } +function normalizeAssistantMedia(value: unknown) { + if (!Array.isArray(value)) return {} + const media: Record = {} + const urlFrom = (entry: unknown) => typeof entry === 'string' ? entry : entry && typeof entry === 'object' && typeof (entry as { url?: unknown }).url === 'string' ? (entry as { url: string }).url : undefined + for (const part of value) { + if (!part || typeof part !== 'object') continue + const item = part as { type?: unknown; image_url?: unknown; video_url?: unknown; audio_url?: unknown; url?: unknown } + const url = urlFrom(item.url) + if (item.type === 'image_url') media.imageUrl = urlFrom(item.image_url) || url + if (item.type === 'video_url' || item.type === 'video') media.videoUrl = urlFrom(item.video_url) || url + if (item.type === 'audio_url' || item.type === 'audio') media.audioUrl = urlFrom(item.audio_url) || url + } + return mediaResult(media, activeModel.value.type) +} + function mapAsyncTask(task: AsyncTaskResult, model: ModelItem, taskPrompt?: string): TaskItem { - const modelUrl = task.output?.modelUrl || task.result?.modelUrl || (task.provider ? task.result?.url : undefined) + 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 imageUrl = assets.imageUrl + const audioUrl = assets.audioUrl + const resultUrl = assets.resultUrl const creditsConsumed = task.creditsConsumed ?? task.result?.creditsConsumed const statusMap: Record = { queued: '排队中', @@ -376,18 +426,22 @@ 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' ? '文字生成视频' : '文字生成 3D', + name: model.type === '视频' || task.provider === 'seedance' ? '文字生成视频' : model.type === '图像' ? '生成图片' : model.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 ? '已完成' : '计算中', - result: task.error?.message || (videoUrl ? '视频已生成' : modelUrl ? 'GLB 模型已生成' : task.status === 'succeeded' ? '异步任务已完成' : task.status === 'running' ? `正在生成 · ${Math.round(task.progress || 0)}%` : '等待平台调度'), + result: task.error?.message || (videoUrl ? '视频已生成' : imageUrl ? '图片已生成' : audioUrl ? '音频已生成' : modelUrl ? 'GLB 模型已生成' : resultUrl ? '文件已生成' : task.status === 'succeeded' ? '异步任务已完成' : task.status === 'running' ? `正在生成 · ${Math.round(task.progress || 0)}%` : '等待平台调度'), provider: task.provider, prompt: taskPrompt, - modelUrl, - videoUrl, + modelUrl: modelUrl || assets.modelUrl, + videoUrl: videoUrl || assets.videoUrl, previewUrl, + imageUrl, + audioUrl, + resultUrl, + resultFormat: task.output?.format || task.result?.format, creditsConsumed, remote: true, } @@ -423,7 +477,8 @@ async function pollTask(taskId: string, apiKey: string) { // the balance card and usage counters reflect that settlement immediately // instead of waiting for a full page reload. await refreshOverview() - emit('notify', latest.status === 'succeeded' ? '3D 模型生成完成,可以预览和下载' : '3D 任务未能完成') + historyRevision.value++ + emit('notify', latest.status === 'succeeded' ? `${previous.name}完成,可以查看和保存结果` : `${previous.name}未能完成,请查看错误说明`) } } catch (error) { taskPollers.delete(taskId) @@ -464,7 +519,7 @@ function mapCatalogModels(items: CatalogModel[], providers: Array<{ id: string; ...mapCatalogModel(item), logicalModelId: item.logicalModelId, provider: providerNames.get(item.providerId) || item.providerId, vendorName: item.vendorName, - sourceLabel: item.sourceLabel, pricing: item.pricing, pricingConfigured: item.pricingConfigured, billingReady: item.billingReady, priority: item.priority, maxConcurrency: item.maxConcurrency, executionReady: item.executionReady, + sourceLabel: item.sourceLabel, pricing: item.pricing, pricingConfigured: item.pricingConfigured, billingReady: item.billingReady, priority: item.priority, maxConcurrency: item.maxConcurrency, executionReady: item.executionReady, inputTypes: item.inputTypes, outputTypes: item.outputTypes, })) } @@ -481,6 +536,8 @@ function mapCatalogModel(item: LogicalModel): ModelItem { description: item.description, latency: item.mode === 'async' ? '异步任务' : '待采样', specification: item.outputTypes.join(' / ') || '统一接口', + inputTypes: item.inputTypes, + outputTypes: item.outputTypes, availability: item.status === 'active' ? '在线' : '已停用', accent: item.type === '3d' ? 'orange' : 'violet', icon: item.type === '3d' ? Box : item.type === 'image' ? Sparkles : MessageSquareText, @@ -645,7 +702,7 @@ async function createProject() {
-
REQUEST

请求配置

+
REQUEST

请求配置

@@ -654,24 +711,27 @@ async function createProject() {
按分组人民币售价和实际 Token 用量扣费;调用前预留额度,结束后释放差额。 +
输入{{ mediaTypeLabel(input) }}输出{{ mediaTypeLabel(output) }}
+

{{ activeModel.executionReady === false ? '该分组尚未接通相应的执行服务,暂时不能调用。' : !activeModel.pricingConfigured || activeModel.billingReady === false ? '该分组的计费尚未配置完成,暂时不能调用。' : '该模型的调用方式暂不支持在线调试。' }}

+ - - + +
RESPONSE

{{ callMode === '异步' ? '任务状态' : '模型输出' }}

思考过程
{{ reasoningOutput }}
-
{{ callMode === '异步' ? activeModel.type === '视频' ? '正在创建视频任务' : '正在创建 3D 任务' : '模型正在生成响应' }}

请求通过模亦灵枢统一网关发送

+
{{ callMode === '异步' ? `正在提交${generationLabel(activeModel.type)}任务` : '模型正在生成响应' }}

请求通过模亦灵枢统一网关发送

-
异步任务预览{{ activeTask.status === '已完成' ? '结果已生成' : '生成预览中' }}{{ activeTask.provider === 'tripo' ? 'TRIPO' : activeTask.provider === 'seedance' ? 'SEEDANCE' : 'MOYI GATEWAY' }}
+
{{ activeTask.status }}{{ activeTask.id }}
任务进度{{ activeTask.progress }}%

{{ activeTask.result }}

上游任务消耗
{{ activeTask.creditsConsumed }} credits
-
+
-
{{ responseError ? '调用未正常完成' : running ? '正在输出' : '调用完成' }}MOYI unified response · finish_reason: {{ finishReason }}

{{ response }}

{{ responseError }}

+
{{ responseError ? '调用未正常完成' : running ? '正在输出' : '调用完成' }}MOYI unified response · finish_reason: {{ finishReason }}

{{ response }}

{{ responseError }}

等待模型响应

配置请求并点击“开始调用”

@@ -772,7 +832,9 @@ export OPENAI_API_KEY="你的 MOYI 用户 API Key" $env:OPENAI_API_KEY="你的 MOYI 用户 API Key" # model 使用模型广场中的调用模型 ID

部分新版 Codex 工作流默认调用 /v1/responses、工具调用或专用认证流程,当前 MOYI 尚未承诺兼容这些接口;若客户端不能切换到 Chat Completions,会出现 404 或参数不兼容,应改用 Cherry Studio、OpenCode 的 OpenAI-compatible 模式,或等待平台提供 Responses 兼容接口。

-
API REFERENCE

接口、流式和异步任务

GET {{ platformApiBaseUrl }}/models查询当前 Key 已授权的模型
POST {{ platformApiBaseUrl }}/chat/completions同步聊天;传 stream: true 获取 SSE 流式响应
POST {{ platformApiBaseUrl }}/3d/tasks提交 3D 异步任务
POST {{ platformApiBaseUrl }}/video/tasks提交视频异步任务
GET {{ platformApiBaseUrl }}/tasks/<task-id>查询异步任务进度与结果

文本聊天的费用在完整响应后结算;流式连接中断时仍会根据使用记录处理结算。3D、视频模型不能通过聊天接口调用。

+
API REFERENCE

接口、流式和异步任务

GET {{ platformApiBaseUrl }}/models查询当前 Key 已授权的模型与模型 ID
POST {{ platformApiBaseUrl }}/chat/completions文本、多模态同步聊天;传 stream: true 获取 SSE 流式响应
POST {{ platformApiBaseUrl }}/3d/tasks提交 3D 异步任务
POST {{ platformApiBaseUrl }}/video/tasks提交视频异步任务
POST {{ platformApiBaseUrl }}/image/tasks提交图片异步任务(仅已接通的模型分组)
POST {{ platformApiBaseUrl }}/audio/tasks提交音频异步任务(仅已接通的模型分组)
GET {{ platformApiBaseUrl }}/tasks/<task-id>查询异步任务进度与图片、视频、音频或 3D 文件结果

文本和多模态聊天的费用在完整响应后结算;流式连接中断时仍会根据使用记录处理结算。异步媒体任务必须使用与模型类型匹配的任务接口,结果链接可能有有效期,请及时保存。

+ +
MEDIA & MULTIMODAL

图片、视频、3D 与语音

图片输入在在线调试中选择支持 image / image_url 的模型,填入可公开访问的 HTTPS 图片 URL,再补充文字提示。OpenAI-compatible 客户端使用 messages[].content 的 text + image_url 数组。

异步输出图片、视频、音频和 3D 任务返回任务 ID,状态为 queued / running / succeeded / failed;成功后在 output 或 result 中返回对应文件 URL。

在线预览平台会按 MIME 或文件格式分别渲染图片、视频播放器、音频播放器和 3D 文件下载;不要把视频或图片 URL 当作 GLB 下载。

TROUBLESHOOTING

常见问题

401 / INVALID_API_KEY确认使用的是用户端 API Key,前缀和完整值没有多余空格;停用的 Key 需要先重新启用。

403 / MODEL_FORBIDDEN当前 Key 没有授权这个模型或渠道分组;回到 API Keys 编辑权限。

404 / MODEL_NOT_FOUND模型 ID 填错,或管理员已停用模型/分组;重新从模型详情复制调用 ID。

429 / KEY_BUSY 或 MODEL_BUSY分别表示当前 Key 并发已满,或上游分组共享并发已满;等待后重试,不要重复创建 Key。

余额不足 / PROVIDER_NOT_CONFIGURED用户余额、渠道凭据或上游钱包需要管理员检查;不要在客户端暴露供应商密钥。

@@ -793,7 +855,7 @@ $env:OPENAI_API_KEY="你的 MOYI 用户 API Key" -
任务结果预览
{{ selectedTask.status }}{{ selectedTask.progress }}%
{{ selectedTask.result }}
任务 ID
{{ selectedTask.id }}
模型
{{ selectedTask.model }}
上游通道
{{ selectedTask.provider }}
任务消耗
{{ selectedTask.creditsConsumed }} credits
创建时间
{{ selectedTask.createdAt }}
耗时
{{ selectedTask.duration }}
{{ selectedTask.prompt }}
+
{{ selectedTask.status }}{{ selectedTask.progress }}%
{{ selectedTask.result }}
任务 ID
{{ selectedTask.id }}
模型
{{ selectedTask.model }}
上游通道
{{ selectedTask.provider }}
任务消耗
{{ selectedTask.creditsConsumed }} credits
创建时间
{{ selectedTask.createdAt }}
耗时
{{ selectedTask.duration }}
{{ selectedTask.prompt }}

确认删除「{{ deleteKeyTarget.name }}」?删除后无法重新启用,已有调用记录和任务会保留。

Key 创建后默认不开放模型权限,请在下一步选择具体可调用模型。
@@ -829,6 +891,13 @@ $env:OPENAI_API_KEY="你的 MOYI 用户 API Key" .playground-selectors { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; } .playground-selectors label { display: grid; gap: 8px; font-size: 13px; min-width: 0; } .playground-selectors select { width: 100%; min-width: 0; } +.capability-strip { display:flex; flex-wrap:wrap; align-items:center; gap:6px; padding:9px 10px; margin-top:12px; border:1px solid #e6e9f1; border-radius:8px; color:#687378; font-size:11px; background:#fbfcff; } +.capability-strip span { color:#475569; font-weight:700; margin-right:3px; } +.capability-strip em { padding:3px 7px; border-radius:5px; color:#5942b1; font-style:normal; background:#f0edff; } +.media-input-label { display:grid; gap:8px; } +.media-input-label small { color:var(--muted); font-weight:400; } +.input-media-preview { width:100%; max-height:160px; object-fit:contain; border:1px solid var(--border); border-radius:8px; background:var(--soft); } +.request-unavailable { margin:12px 0 0; padding:10px 12px; border:1px solid #f2d5a2; border-radius:8px; color:#8a5c14; font-size:11px; line-height:1.55; background:#fff8e8; } @media(max-width: 1180px) { .playground-grid { grid-template-columns: minmax(0, 1fr); } } @media(max-width: 700px) { .playground-selectors { grid-template-columns: minmax(0, 1fr); } } diff --git a/prototype/tests/media.test.mjs b/prototype/tests/media.test.mjs new file mode 100644 index 0000000..a3718cc --- /dev/null +++ b/prototype/tests/media.test.mjs @@ -0,0 +1,18 @@ +import { test } from 'node:test' +import assert from 'node:assert/strict' +import { mediaResult, safeMediaUrl } 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' }, '视频') + assert.equal(result.videoUrl, 'https://cdn.example.test/result.mp4') + assert.equal(result.modelUrl, undefined) + assert.equal(result.imageUrl, undefined) +}) + +test('mediaResult identifies image/audio and rejects unsafe URLs', () => { + assert.equal(safeMediaUrl('javascript:alert(1)'), undefined) + const image = mediaResult({ url: 'https://cdn.example.test/image.png' }, '图像') + const audio = mediaResult({ url: 'https://cdn.example.test/sound.mp3' }, '音频') + assert.equal(image.imageUrl, 'https://cdn.example.test/image.png') + assert.equal(audio.audioUrl, 'https://cdn.example.test/sound.mp3') +})