fix: restore ordinary user overview and correct brand name

This commit is contained in:
wlx committed 2026-09-29 19:50:10 +08:00
1 parent 558c0dcdd5
commit 3969a50eee
4 files changed
+138 -43

No files matched your search

+1 -1
View File
@@ -262,7 +262,7 @@ MaaS 模型服务与应用开发
│ └── 面向创作者的 AI 生成 3D 产品 │ └── 面向创作者的 AI 生成 3D 产品
├── 模亦灵枢 / MOYI Model Intelligence Hub ├── 模亦灵枢 / MOYI Model Intelligence Hub
│ └── 面向开发者和企业的多模型智能基础设施 │ └── 面向开发者和企业的多模型智能基础设施
└── 模翎技术 └── 模灵科技
└── 平台底层技术、工程能力和模型研发体系 └── 平台底层技术、工程能力和模型研发体系
``` ```
@@ -491,8 +491,9 @@ public class AsyncProviderClient {
private String keyForFingerprint(String routeId, String upstreamModel, Environment environment, private String keyForFingerprint(String routeId, String upstreamModel, Environment environment,
ConcurrentMap<String, AtomicInteger> cursors, String fingerprint) { ConcurrentMap<String, AtomicInteger> cursors, String fingerprint) {
if (fingerprint == null || fingerprint.isBlank()) return nextApiKey(routeId, upstreamModel, environment, cursors); if (fingerprint == null || fingerprint.isBlank()) return nextApiKey(routeId, upstreamModel, environment, cursors);
List<String> candidates = routeKeys(routeId, upstreamModel, environment); List<String> candidates = new ArrayList<>(routeKeys(routeId, upstreamModel, environment));
if (candidates.isEmpty()) candidates = apiKeys; candidates.addAll(apiKeys);
candidates = candidates.stream().distinct().toList();
for (String candidate : candidates) if (fingerprint.equals(keyFingerprint(candidate))) return candidate; for (String candidate : candidates) if (fingerprint.equals(keyFingerprint(candidate))) return candidate;
throw new ApiException("UPSTREAM_KEY_NOT_AVAILABLE", "创建任务时使用的上游凭据已从服务器配置中移除,无法安全轮询", 503); throw new ApiException("UPSTREAM_KEY_NOT_AVAILABLE", "创建任务时使用的上游凭据已从服务器配置中移除,无法安全轮询", 503);
} }
+1 -1
View File
@@ -175,7 +175,7 @@ onMounted(async () => {
<i class="auth-orbit orbit-a"></i><i class="auth-orbit orbit-b"></i> <i class="auth-orbit orbit-a"></i><i class="auth-orbit orbit-b"></i>
<img src="/assets/moyi-logo.png" alt="" /> <img src="/assets/moyi-logo.png" alt="" />
</div> </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>
<section class="auth-form-area"> <section class="auth-form-area">
+133 -39
View File
@@ -173,6 +173,72 @@ const taskPollers = new Map<string, number>()
const copyTimers = new Map<string, number>() const copyTimers = new Map<string, number>()
const copyStates = ref<Record<string, CopyResult | undefined>>({}) 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) { function selectDebugApiKey(id: string) {
selectedApiKeyId.value = id selectedApiKeyId.value = id
} }
@@ -180,15 +246,17 @@ function selectDebugApiKey(id: string) {
onMounted(async () => { onMounted(async () => {
try { try {
const [catalog, keyResult, projectResult, overviewResult] = await Promise.all([catalogClient.listModels(), catalogClient.listKeys(), catalogClient.listProjects(), catalogClient.getOverview()]) 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) catalogModels.value = mapCatalogModels(catalog.models, catalog.providers)
catalogDefinitions.value = catalog.logicalModels catalogDefinitions.value = Array.isArray(catalog.logicalModels) ? catalog.logicalModels : []
catalogRoutes.value = catalog.models catalogRoutes.value = Array.isArray(catalog.models) ? catalog.models : []
if (catalogModels.value[0]) selectPlaygroundGroup(catalogModels.value[0].id) 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 || '') selectedApiKeyId.value = String(keys.value.find((key) => key.status === '正常')?.id || '')
projects.value = projectResult.projects projects.value = Array.isArray(projectResult.projects) ? projectResult.projects : []
overview.value = overviewResult overview.value = normalizeOverview(overviewResult)
emit('balance', overviewResult.availableCredit) emit('balance', overview.value.availableCredit)
overviewLoaded.value = true overviewLoaded.value = true
catalogConnected.value = true catalogConnected.value = true
try { try {
@@ -204,6 +272,7 @@ onMounted(async () => {
keys.value = [] keys.value = []
projects.value = [] projects.value = []
activeModel.value = emptyModel activeModel.value = emptyModel
overview.value = normalizeOverview(undefined)
overviewLoaded.value = false overviewLoaded.value = false
catalogConnected.value = false catalogConnected.value = false
} }
@@ -316,7 +385,7 @@ function resetModelFilters() {
async function refreshOverview() { async function refreshOverview() {
try { try {
overview.value = await catalogClient.getOverview() overview.value = normalizeOverview(await catalogClient.getOverview())
emit('balance', overview.value.availableCredit) emit('balance', overview.value.availableCredit)
overviewLoaded.value = true overviewLoaded.value = true
} catch {} } catch {}
@@ -524,14 +593,26 @@ async function createKey() {
} }
} }
function mapCatalogModels(items: CatalogModel[], providers: Array<{ id: string; name: string }>): ModelItem[] { function mapCatalogModels(items: unknown, providers: unknown): ModelItem[] {
const providerNames = new Map(providers.map((provider) => [provider.id, provider.name])) const providerRows = Array.isArray(providers) ? providers : []
return items.map(item => ({ 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, ...mapCatalogModel(item), logicalModelId: item.logicalModelId, gatewayModelId: item.gatewayModelId,
provider: providerNames.get(item.providerId) || item.providerId, provider: providerNames.get(providerId) || providerId || '未知渠道',
vendorName: item.vendorName, vendorName: model.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, 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 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 typeLabels: Record<string, ModelType> = { text: '文本', code: '文本', multimodal: '多模态', image: '图像', audio: '音频', video: '视频', embedding: '文本', '3d': '3D' }
const modeLabels: Record<string, CallMode> = { sync: '同步', stream: '流式', async: '异步' } 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 { return {
id: item.id, id,
name: item.publicName, name: asText(row.publicName, asText(row.modelKey, id || '未命名模型')),
provider: '', provider: '',
vendorName: item.vendorName, vendorName: asText(row.vendorName) || undefined,
type: typeLabels[item.type] || '文本', type: typeLabels[type] || '文本',
mode: modeLabels[item.mode] || '同步', mode: modeLabels[mode] || '同步',
description: item.description, description: asText(row.description),
latency: item.mode === 'async' ? '异步任务' : '待采样', latency: mode === 'async' ? '异步任务' : '待采样',
specification: item.outputTypes.join(' / ') || '统一接口', specification: outputTypes.join(' / ') || '统一接口',
inputTypes: item.inputTypes, inputTypes,
outputTypes: item.outputTypes, outputTypes,
availability: item.status === 'active' ? '在线' : '已停用', availability: asText(row.status, 'active') === 'active' ? '在线' : '已停用',
accent: item.type === '3d' ? 'orange' : 'violet', accent: type === '3d' ? 'orange' : 'violet',
icon: item.type === '3d' ? Box : item.type === 'image' ? Sparkles : MessageSquareText, icon: type === '3d' ? Box : type === 'image' ? Sparkles : MessageSquareText,
modelKey: item.modelKey, modelKey: asText(row.modelKey) || undefined,
} }
} }
@@ -574,17 +661,24 @@ function keyPermissionSummary(key: ApiKeyItem) {
} }
function mapCatalogKey(key: CatalogApiKey, plaintext = ''): 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 { return {
id: key.id, id,
name: key.name, name: keyName,
value: plaintext ? `${plaintext.slice(0, 10)}••••••••${plaintext.slice(-4)}` : `${key.keyPrefix}••••••••••••`, value: plaintext ? `${plaintext.slice(0, 10)}••••••••${plaintext.slice(-4)}` : `${keyPrefix}••••••••••••`,
scope: key.scopeType === 'project' ? `项目 Key${key.projectId ? ` · ${key.projectId.slice(0, 12)}` : ''}` : '个人 Key', scope: raw.scopeType === 'project' ? `项目 Key${raw.projectId ? ` · ${String(raw.projectId).slice(0, 12)}` : ''}` : '个人 Key',
scopeType: key.scopeType, scopeType: raw.scopeType === 'project' ? 'project' : 'personal',
projectId: key.projectId, projectId: raw.projectId,
modelIds: [...key.modelIds], modelIds,
createdAt: key.createdAt.slice(0, 10), createdAt: createdAt ? createdAt.slice(0, 10) : '未知时间',
lastUsed: key.lastUsedAt ? key.lastUsedAt.slice(0, 16).replace('T', ' ') : '尚未使用', lastUsed: lastUsedAt ? lastUsedAt.slice(0, 16).replace('T', ' ') : '尚未使用',
status: key.status === 'active' ? '正常' : '已停用', status: raw.status === 'active' ? '正常' : '已停用',
} }
} }