From 3969a50eee339e74e16cae0c4b62eab1824296ea Mon Sep 17 00:00:00 2001 From: WangLX <519407855@qq.com> Date: Tue, 29 Sep 2026 19:50:10 +0800 Subject: [PATCH] fix: restore ordinary user overview and correct brand name --- README.md | 2 +- .../task/AsyncProviderClient.java | 5 +- prototype/src/views/AuthView.vue | 2 +- prototype/src/views/UserConsole.vue | 172 ++++++++++++++---- 4 files changed, 138 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index 6e3ab0d..5344b0d 100644 --- a/README.md +++ b/README.md @@ -262,7 +262,7 @@ MaaS 模型服务与应用开发 │ └── 面向创作者的 AI 生成 3D 产品 ├── 模亦灵枢 / MOYI Model Intelligence Hub │ └── 面向开发者和企业的多模型智能基础设施 -└── 模翎技术 +└── 模灵科技 └── 平台底层技术、工程能力和模型研发体系 ``` diff --git a/control-plane-java/src/main/java/com/moyi/controlplane/task/AsyncProviderClient.java b/control-plane-java/src/main/java/com/moyi/controlplane/task/AsyncProviderClient.java index 3b1e56c..1cc79ab 100644 --- a/control-plane-java/src/main/java/com/moyi/controlplane/task/AsyncProviderClient.java +++ b/control-plane-java/src/main/java/com/moyi/controlplane/task/AsyncProviderClient.java @@ -491,8 +491,9 @@ public class AsyncProviderClient { private String keyForFingerprint(String routeId, String upstreamModel, Environment environment, ConcurrentMap cursors, String fingerprint) { if (fingerprint == null || fingerprint.isBlank()) return nextApiKey(routeId, upstreamModel, environment, cursors); - List candidates = routeKeys(routeId, upstreamModel, environment); - if (candidates.isEmpty()) candidates = apiKeys; + List candidates = new ArrayList<>(routeKeys(routeId, upstreamModel, environment)); + candidates.addAll(apiKeys); + candidates = candidates.stream().distinct().toList(); for (String candidate : candidates) if (fingerprint.equals(keyFingerprint(candidate))) return candidate; throw new ApiException("UPSTREAM_KEY_NOT_AVAILABLE", "创建任务时使用的上游凭据已从服务器配置中移除,无法安全轮询", 503); } diff --git a/prototype/src/views/AuthView.vue b/prototype/src/views/AuthView.vue index bcb24f5..47db7c7 100644 --- a/prototype/src/views/AuthView.vue +++ b/prototype/src/views/AuthView.vue @@ -175,7 +175,7 @@ onMounted(async () => { -
{{ serviceStatus === 'online' ? '服务可用' : serviceStatus === 'offline' ? '服务暂不可用' : '正在检测服务' }}© 2026 模翎科技
+
{{ serviceStatus === 'online' ? '服务可用' : serviceStatus === 'offline' ? '服务暂不可用' : '正在检测服务' }}© 2026 模灵科技
diff --git a/prototype/src/views/UserConsole.vue b/prototype/src/views/UserConsole.vue index a7aa1db..5b4e79a 100644 --- a/prototype/src/views/UserConsole.vue +++ b/prototype/src/views/UserConsole.vue @@ -173,6 +173,72 @@ const taskPollers = new Map() const copyTimers = new Map() const copyStates = ref>({}) +/** + * 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 { + return value && typeof value === 'object' && !Array.isArray(value) ? value as Record : {} +} + +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 + 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 | Partial): ModelItem { const typeLabels: Record = { text: '文本', code: '文本', multimodal: '多模态', image: '图像', audio: '音频', video: '视频', embedding: '文本', '3d': '3D' } const modeLabels: Record = { sync: '同步', stream: '流式', async: '异步' } + const row = item as Record + 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 + 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' ? '正常' : '已停用', } }