fix: restore ordinary user overview and correct brand name
This commit is contained in:
1 parent
558c0dcdd5
commit
3969a50eee
4 files changed
+138
-43
No files matched your search
@@ -175,7 +175,7 @@ onMounted(async () => {
|
||||
<i class="auth-orbit orbit-a"></i><i class="auth-orbit orbit-b"></i>
|
||||
<img src="/assets/moyi-logo.png" alt="" />
|
||||
</div>
|
||||
<footer><span :class="`service-${serviceStatus}`"><i></i>{{ serviceStatus === 'online' ? '服务可用' : serviceStatus === 'offline' ? '服务暂不可用' : '正在检测服务' }}</span><small>© 2026 模翎科技</small></footer>
|
||||
<footer><span :class="`service-${serviceStatus}`"><i></i>{{ serviceStatus === 'online' ? '服务可用' : serviceStatus === 'offline' ? '服务暂不可用' : '正在检测服务' }}</span><small>© 2026 模灵科技</small></footer>
|
||||
</section>
|
||||
|
||||
<section class="auth-form-area">
|
||||
|
||||
@@ -173,6 +173,72 @@ const taskPollers = new Map<string, number>()
|
||||
const copyTimers = new Map<string, number>()
|
||||
const copyStates = ref<Record<string, CopyResult | undefined>>({})
|
||||
|
||||
/**
|
||||
* The user portal must still render when an older control-plane node returns a
|
||||
* partial payload. A missing optional field used to throw during Vue render
|
||||
* (for example `series.map` or `asyncSuccessRate.toFixed`) and blanked the
|
||||
* entire workspace for ordinary users. Keep the API contract typed while
|
||||
* normalising the untrusted JSON boundary here.
|
||||
*/
|
||||
function asRecord(value: unknown): Record<string, unknown> {
|
||||
return value && typeof value === 'object' && !Array.isArray(value) ? value as Record<string, unknown> : {}
|
||||
}
|
||||
|
||||
function asText(value: unknown, fallback = ''): string {
|
||||
return typeof value === 'string' ? value : value == null ? fallback : String(value)
|
||||
}
|
||||
|
||||
function asNumber(value: unknown, fallback = 0): number {
|
||||
const number = typeof value === 'number' ? value : Number(value)
|
||||
return Number.isFinite(number) ? number : fallback
|
||||
}
|
||||
|
||||
function optionalNumber(value: unknown): number | undefined {
|
||||
if (value == null || value === '') return undefined
|
||||
const number = Number(value)
|
||||
return Number.isFinite(number) ? number : undefined
|
||||
}
|
||||
|
||||
function asStringArray(value: unknown): string[] {
|
||||
return Array.isArray(value) ? value.filter((item): item is string => typeof item === 'string') : []
|
||||
}
|
||||
|
||||
function normalizeOverview(value: unknown): PlatformOverview {
|
||||
const raw = asRecord(value)
|
||||
const rawTasks = asRecord(raw.tasks)
|
||||
const series = Array.isArray(raw.series) ? raw.series.flatMap((item) => {
|
||||
const row = asRecord(item)
|
||||
const date = asText(row.date)
|
||||
return date ? [{ date, count: asNumber(row.count) }] : []
|
||||
}) : []
|
||||
const ledger = Array.isArray(raw.ledger) ? raw.ledger.flatMap((item) => {
|
||||
const row = asRecord(item)
|
||||
const id = asText(row.id)
|
||||
return id ? [{ id, title: asText(row.title, '额度流水'), amount: asNumber(row.amount), createdAt: asText(row.createdAt) }] : []
|
||||
}) : []
|
||||
return {
|
||||
generatedAt: asText(raw.generatedAt),
|
||||
callsToday: asNumber(raw.callsToday),
|
||||
callsThisMonth: asNumber(raw.callsThisMonth),
|
||||
averageLatencyMs: optionalNumber(raw.averageLatencyMs),
|
||||
availableCredit: optionalNumber(raw.availableCredit),
|
||||
balance: optionalNumber(raw.balance),
|
||||
reservedCredit: optionalNumber(raw.reservedCredit),
|
||||
costThisMonth: optionalNumber(raw.costThisMonth),
|
||||
availabilityPercent: optionalNumber(raw.availabilityPercent),
|
||||
asyncTasks: asNumber(raw.asyncTasks),
|
||||
asyncSuccessRate: optionalNumber(raw.asyncSuccessRate),
|
||||
tasks: {
|
||||
queued: asNumber(rawTasks.queued),
|
||||
running: asNumber(rawTasks.running),
|
||||
succeeded: asNumber(rawTasks.succeeded),
|
||||
failed: asNumber(rawTasks.failed),
|
||||
},
|
||||
series,
|
||||
ledger,
|
||||
}
|
||||
}
|
||||
|
||||
function selectDebugApiKey(id: string) {
|
||||
selectedApiKeyId.value = id
|
||||
}
|
||||
@@ -180,15 +246,17 @@ function selectDebugApiKey(id: string) {
|
||||
onMounted(async () => {
|
||||
try {
|
||||
const [catalog, keyResult, projectResult, overviewResult] = await Promise.all([catalogClient.listModels(), catalogClient.listKeys(), catalogClient.listProjects(), catalogClient.getOverview()])
|
||||
// Treat every API collection as untrusted JSON. This keeps a partially
|
||||
// migrated control plane from taking down the whole authenticated shell.
|
||||
catalogModels.value = mapCatalogModels(catalog.models, catalog.providers)
|
||||
catalogDefinitions.value = catalog.logicalModels
|
||||
catalogRoutes.value = catalog.models
|
||||
catalogDefinitions.value = Array.isArray(catalog.logicalModels) ? catalog.logicalModels : []
|
||||
catalogRoutes.value = Array.isArray(catalog.models) ? catalog.models : []
|
||||
if (catalogModels.value[0]) selectPlaygroundGroup(catalogModels.value[0].id)
|
||||
keys.value = keyResult.keys.map((key) => mapCatalogKey(key))
|
||||
keys.value = (Array.isArray(keyResult.keys) ? keyResult.keys : []).map((key) => mapCatalogKey(key))
|
||||
selectedApiKeyId.value = String(keys.value.find((key) => key.status === '正常')?.id || '')
|
||||
projects.value = projectResult.projects
|
||||
overview.value = overviewResult
|
||||
emit('balance', overviewResult.availableCredit)
|
||||
projects.value = Array.isArray(projectResult.projects) ? projectResult.projects : []
|
||||
overview.value = normalizeOverview(overviewResult)
|
||||
emit('balance', overview.value.availableCredit)
|
||||
overviewLoaded.value = true
|
||||
catalogConnected.value = true
|
||||
try {
|
||||
@@ -204,6 +272,7 @@ onMounted(async () => {
|
||||
keys.value = []
|
||||
projects.value = []
|
||||
activeModel.value = emptyModel
|
||||
overview.value = normalizeOverview(undefined)
|
||||
overviewLoaded.value = false
|
||||
catalogConnected.value = false
|
||||
}
|
||||
@@ -316,7 +385,7 @@ function resetModelFilters() {
|
||||
|
||||
async function refreshOverview() {
|
||||
try {
|
||||
overview.value = await catalogClient.getOverview()
|
||||
overview.value = normalizeOverview(await catalogClient.getOverview())
|
||||
emit('balance', overview.value.availableCredit)
|
||||
overviewLoaded.value = true
|
||||
} catch {}
|
||||
@@ -524,14 +593,26 @@ async function createKey() {
|
||||
}
|
||||
}
|
||||
|
||||
function mapCatalogModels(items: CatalogModel[], providers: Array<{ id: string; name: string }>): ModelItem[] {
|
||||
const providerNames = new Map(providers.map((provider) => [provider.id, provider.name]))
|
||||
return items.map(item => ({
|
||||
function mapCatalogModels(items: unknown, providers: unknown): ModelItem[] {
|
||||
const providerRows = Array.isArray(providers) ? providers : []
|
||||
const providerNames = new Map(providerRows.map((provider) => {
|
||||
const row = asRecord(provider)
|
||||
return [asText(row.id), asText(row.name)] as const
|
||||
}).filter(([id]) => !!id))
|
||||
const modelRows = Array.isArray(items) ? items : []
|
||||
return modelRows.map(item => {
|
||||
const row = asRecord(item)
|
||||
const model = item as Partial<CatalogModel>
|
||||
const providerId = asText(row.providerId)
|
||||
const inputTypes = asStringArray(row.inputTypes)
|
||||
const outputTypes = asStringArray(row.outputTypes)
|
||||
return {
|
||||
...mapCatalogModel(item), logicalModelId: item.logicalModelId, gatewayModelId: item.gatewayModelId,
|
||||
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, inputTypes: item.inputTypes, outputTypes: item.outputTypes,
|
||||
}))
|
||||
provider: providerNames.get(providerId) || providerId || '未知渠道',
|
||||
vendorName: model.vendorName,
|
||||
sourceLabel: model.sourceLabel, pricing: model.pricing, pricingConfigured: model.pricingConfigured, billingReady: model.billingReady, priority: model.priority, maxConcurrency: model.maxConcurrency, executionReady: model.executionReady, inputTypes, outputTypes,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -544,25 +625,31 @@ function gatewayModelId(group: ModelItem): string {
|
||||
return group.gatewayModelId || group.modelKey || group.id
|
||||
}
|
||||
|
||||
function mapCatalogModel(item: LogicalModel): ModelItem {
|
||||
function mapCatalogModel(item: Partial<LogicalModel> | Partial<CatalogModel>): ModelItem {
|
||||
const typeLabels: Record<string, ModelType> = { text: '文本', code: '文本', multimodal: '多模态', image: '图像', audio: '音频', video: '视频', embedding: '文本', '3d': '3D' }
|
||||
const modeLabels: Record<string, CallMode> = { sync: '同步', stream: '流式', async: '异步' }
|
||||
const row = item as Record<string, unknown>
|
||||
const id = asText(row.id)
|
||||
const type = asText(row.type, 'text')
|
||||
const mode = asText(row.mode, 'sync')
|
||||
const inputTypes = asStringArray(row.inputTypes)
|
||||
const outputTypes = asStringArray(row.outputTypes)
|
||||
return {
|
||||
id: item.id,
|
||||
name: item.publicName,
|
||||
id,
|
||||
name: asText(row.publicName, asText(row.modelKey, id || '未命名模型')),
|
||||
provider: '',
|
||||
vendorName: item.vendorName,
|
||||
type: typeLabels[item.type] || '文本',
|
||||
mode: modeLabels[item.mode] || '同步',
|
||||
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,
|
||||
modelKey: item.modelKey,
|
||||
vendorName: asText(row.vendorName) || undefined,
|
||||
type: typeLabels[type] || '文本',
|
||||
mode: modeLabels[mode] || '同步',
|
||||
description: asText(row.description),
|
||||
latency: mode === 'async' ? '异步任务' : '待采样',
|
||||
specification: outputTypes.join(' / ') || '统一接口',
|
||||
inputTypes,
|
||||
outputTypes,
|
||||
availability: asText(row.status, 'active') === 'active' ? '在线' : '已停用',
|
||||
accent: type === '3d' ? 'orange' : 'violet',
|
||||
icon: type === '3d' ? Box : type === 'image' ? Sparkles : MessageSquareText,
|
||||
modelKey: asText(row.modelKey) || undefined,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -574,17 +661,24 @@ function keyPermissionSummary(key: ApiKeyItem) {
|
||||
}
|
||||
|
||||
function mapCatalogKey(key: CatalogApiKey, plaintext = ''): ApiKeyItem {
|
||||
const raw = key as Partial<CatalogApiKey>
|
||||
const id = asText(raw.id)
|
||||
const keyName = asText(raw.name, '未命名 Key')
|
||||
const keyPrefix = asText(raw.keyPrefix, 'moyi_')
|
||||
const modelIds = asStringArray(raw.modelIds)
|
||||
const createdAt = asText(raw.createdAt)
|
||||
const lastUsedAt = asText(raw.lastUsedAt)
|
||||
return {
|
||||
id: key.id,
|
||||
name: key.name,
|
||||
value: plaintext ? `${plaintext.slice(0, 10)}••••••••${plaintext.slice(-4)}` : `${key.keyPrefix}••••••••••••`,
|
||||
scope: key.scopeType === 'project' ? `项目 Key${key.projectId ? ` · ${key.projectId.slice(0, 12)}` : ''}` : '个人 Key',
|
||||
scopeType: key.scopeType,
|
||||
projectId: key.projectId,
|
||||
modelIds: [...key.modelIds],
|
||||
createdAt: key.createdAt.slice(0, 10),
|
||||
lastUsed: key.lastUsedAt ? key.lastUsedAt.slice(0, 16).replace('T', ' ') : '尚未使用',
|
||||
status: key.status === 'active' ? '正常' : '已停用',
|
||||
id,
|
||||
name: keyName,
|
||||
value: plaintext ? `${plaintext.slice(0, 10)}••••••••${plaintext.slice(-4)}` : `${keyPrefix}••••••••••••`,
|
||||
scope: raw.scopeType === 'project' ? `项目 Key${raw.projectId ? ` · ${String(raw.projectId).slice(0, 12)}` : ''}` : '个人 Key',
|
||||
scopeType: raw.scopeType === 'project' ? 'project' : 'personal',
|
||||
projectId: raw.projectId,
|
||||
modelIds,
|
||||
createdAt: createdAt ? createdAt.slice(0, 10) : '未知时间',
|
||||
lastUsed: lastUsedAt ? lastUsedAt.slice(0, 16).replace('T', ' ') : '尚未使用',
|
||||
status: raw.status === 'active' ? '正常' : '已停用',
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user