fix async dispatch stats and truthful status

This commit is contained in:
wlx committed 2026-09-27 19:55:17 +08:00
1 parent 9750aceb03
commit 8e9f0d52fd
4 files changed
+110 -48

No files matched your search

+1 -1
View File
@@ -103,7 +103,7 @@ export interface ProviderItem {
models: number
latency: string
successRate: string
status: '健康' | '波动' | '维护中'
status: '健康' | '已启用' | '波动' | '维护中'
enabled: boolean
code?: string
protocol?: 'openai-compatible' | 'http' | 'sdk'
+12 -8
View File
@@ -34,6 +34,7 @@ import {
import type { AdminUser, ModelItem, ProviderItem } from '../types'
import { catalogClient, type AdminAuditEvent, type AdminUsageSummary, type CatalogModel, type CatalogProvider, type UsageAuditRecord } from '../services/catalog'
import type { AuthUser } from '../services/auth'
import { authClient } from '../services/auth'
import SlidePanel from '../components/SlidePanel.vue'
import UiModal from '../components/UiModal.vue'
import CatalogAdmin from '../components/CatalogAdmin.vue'
@@ -67,17 +68,19 @@ const usageDeleteTarget = ref<string | null>(null)
const usageBulkDeleteOpen = ref(false)
const auditEvents = ref<Array<{ time: string; actor: string; action: string; target: string; source: string; level: string }>>([])
const overviewRefreshing = ref(false)
const verificationChannels = ref<{ email: boolean; phone: boolean } | null>(null)
async function refreshOverviewData(notifyOnSuccess = false) {
if (overviewRefreshing.value) return
overviewRefreshing.value = true
try {
const [providerResult, modelResult, userResult, auditResult, summaryResult] = await Promise.all([
const [providerResult, modelResult, userResult, auditResult, summaryResult, verificationResult] = await Promise.all([
catalogClient.listAdminProviders(),
catalogClient.listAdminModels(),
catalogClient.listAdminUsers(),
catalogClient.listAdminAudit(),
catalogClient.getAdminUsageSummary().catch(() => null),
authClient.verificationChannels().catch(() => null),
])
providers.value = mapProviders(providerResult.providers, modelResult.models)
models.value = mapModels(modelResult.models, providerResult.providers)
@@ -88,6 +91,7 @@ async function refreshOverviewData(notifyOnSuccess = false) {
publicModelCount.value = new Set(publishedRoutes.map((item) => item.logicalModelId)).size
unpricedRouteCount.value = modelResult.models.filter((item) => item.status === 'active' && activeProviders.has(item.providerId) && activeDefinitions.has(item.logicalModelId) && !item.pricingConfigured).length
adminSummary.value = summaryResult
verificationChannels.value = verificationResult
users.value = userResult.users.map(mapUser)
auditEvents.value = auditResult.events.map(mapAudit)
catalogConnected.value = true
@@ -225,9 +229,9 @@ function mapProviders(items: CatalogProvider[], modelItems: CatalogModel[]): Pro
name: provider.name,
capability: modelItems.filter((model) => model.providerId === provider.id).map((model) => model.type).join(' / ') || '待配置能力',
models: modelItems.filter((model) => model.providerId === provider.id).length,
latency: '待采样',
latency: '未采样',
successRate: '—',
status: provider.status === 'active' ? '健康' : '维护中',
status: provider.status === 'active' ? '已启用' : '维护中',
enabled: provider.status === 'active',
code: provider.code,
protocol: provider.protocol,
@@ -250,7 +254,7 @@ function mapModels(items: CatalogModel[], providersList: CatalogProvider[]): Mod
type: typeLabels[model.type] || '文本',
mode: modeLabels[model.mode] || '同步',
description: model.description,
latency: model.mode === 'async' ? '异步任务' : '待采样',
latency: model.mode === 'async' ? '异步任务' : '未采样',
specification: model.outputTypes.join(' / ') || '统一接口',
availability: model.status === 'active' ? '在线' : '停用',
accent: model.type === '3d' ? 'orange' : 'violet',
@@ -272,9 +276,9 @@ function mapModels(items: CatalogModel[], providersList: CatalogProvider[]): Mod
<template>
<div class="page-stack admin-pages">
<template v-if="view === 'admin-overview'">
<section class="page-heading compact"><div><span>ADMIN OVERVIEW</span><h1>管理总览</h1><p>掌握平台供给、用户、容量和风险状态。</p></div><div class="heading-actions"><span class="health-badge"><i></i>核心服务正常</span><button class="button secondary" :disabled="overviewRefreshing" @click="refreshOverviewData(true)"><Activity :size="16" />{{ overviewRefreshing ? '刷新中…' : '刷新数据' }}</button></div></section>
<section class="page-heading compact"><div><span>ADMIN OVERVIEW</span><h1>管理总览</h1><p>掌握平台供给、用户、容量和风险状态。</p></div><div class="heading-actions"><span class="health-badge"><i></i>目录数据已读取</span><button class="button secondary" :disabled="overviewRefreshing" @click="refreshOverviewData(true)"><Activity :size="16" />{{ overviewRefreshing ? '刷新中…' : '刷新数据' }}</button></div></section>
<section class="metric-grid"><article class="metric-card"><span class="icon-tile violet"><Users :size="18" /></span><div><small>用户总数</small><strong>{{ users.length }}</strong><em>来自认证服务</em></div></article><article class="metric-card"><span class="icon-tile cyan"><Cloud :size="18" /></span><div><small>用户端可用模型</small><strong>{{ publicModelCount }}</strong><em>{{ publicRouteCount }} 个已定价分组 · 管理目录 {{ models.length }} 条 · 待定价 {{ unpricedRouteCount }} 个</em></div></article><article class="metric-card"><span class="icon-tile orange"><Gauge :size="18" /></span><div><small>等待 / 执行任务</small><strong>{{ adminSummary?.waiting ?? '—' }}</strong><em>来自最近调用记录</em></div></article><article class="metric-card"><span class="icon-tile green"><CircleDollarSign :size="18" /></span><div><small>今日额度消耗</small><strong>{{ adminSummary ? `¥${Number(adminSummary.costToday || 0).toFixed(4)}` : '—' }}</strong><em>成功调用实际扣费</em></div></article></section>
<section class="two-column equal"><article class="panel chart-panel"><header class="panel-header"><div><span>PLATFORM TRAFFIC</span><h3>平台请求趋势</h3></div><span class="select-button static">最近 7 天</span></header><div v-if="adminSummary" class="traffic-list"><div v-for="point in adminSummary.series" :key="point.date"><span>{{ point.date }}</span><strong>{{ point.count }} 次</strong></div></div><div v-else class="empty-state compact"><BarChart3 :size="22" /><strong>正在加载平台流量</strong><span>刷新后显示最近 7 天调用量</span></div></article><article class="panel health-panel"><header class="panel-header"><div><span>GATEWAY HEALTH</span><h3>模型供给状态</h3></div><button class="text-link" @click="emit('navigate', 'admin-routing')">管理渠道<ArrowRight :size="14" /></button></header><div v-if="providers.length" class="health-list"><div v-for="provider in providers.slice(0, 3)" :key="provider.id"><span class="provider-mark">{{ provider.name.slice(0, 1) }}</span><p><strong>{{ provider.name }}</strong><small>{{ provider.capability }} · {{ provider.latency }}</small></p><b>{{ provider.successRate }}</b><span class="status-chip" :class="provider.status === '健康' ? 'success' : 'warning'"><i></i>{{ provider.status }}</span></div></div><div v-else class="empty-state compact"><Cloud :size="22" /><strong>暂无供应商</strong><span>由管理员登记上游渠道后显示</span></div></article></section>
<section class="two-column equal"><article class="panel chart-panel"><header class="panel-header"><div><span>PLATFORM TRAFFIC</span><h3>平台请求趋势</h3></div><span class="select-button static">最近 7 天</span></header><div v-if="adminSummary" class="traffic-list"><div v-for="point in adminSummary.series" :key="point.date"><span>{{ point.date }}</span><strong>{{ point.count }} 次</strong></div></div><div v-else class="empty-state compact"><BarChart3 :size="22" /><strong>正在加载平台流量</strong><span>刷新后显示最近 7 天调用量</span></div></article><article class="panel health-panel"><header class="panel-header"><div><span>GATEWAY STATUS</span><h3>模型供给状态</h3></div><button class="text-link" @click="emit('navigate', 'admin-routing')">管理渠道<ArrowRight :size="14" /></button></header><div v-if="providers.length" class="health-list"><div v-for="provider in providers.slice(0, 3)" :key="provider.id"><span class="provider-mark">{{ provider.name.slice(0, 1) }}</span><p><strong>{{ provider.name }}</strong><small>{{ provider.capability }} · {{ provider.latency }}</small></p><b>{{ provider.successRate }}</b><span class="status-chip" :class="provider.status === '已启用' ? 'success' : 'warning'"><i></i>{{ provider.status }}</span></div></div><div v-else class="empty-state compact"><Cloud :size="22" /><strong>暂无供应商</strong><span>由管理员登记上游渠道后显示</span></div></article></section>
<section class="two-column narrow-left"><article class="panel quick-credit"><header class="panel-header"><div><span>CREDIT OPERATIONS</span><h3>额度分配</h3></div><ShieldCheck :size="18" /></header><p>人民币额度余额与发放流水</p><button class="button primary full" @click="emit('navigate', 'admin-users')"><Users :size="16" />查看用户</button></article><article class="panel activity-panel"><header class="panel-header"><div><span>RECENT EVENTS</span><h3>最近运营事件</h3></div><button class="text-link" @click="emit('navigate', 'admin-audit')">审计日志<ArrowRight :size="14" /></button></header><div v-if="auditEvents.length" class="activity-list"><div v-for="event in auditEvents.slice(0, 3)" :key="`${event.time}-${event.action}`"><span class="activity-dot cyan"><ShieldCheck :size="14" /></span><p><strong>{{ event.action }}</strong><small>{{ event.actor }} · {{ event.target }}</small></p><time>{{ event.time }}</time></div></div><div v-else class="empty-state compact"><ShieldCheck :size="22" /><strong>暂无运营事件</strong><span>真实管理操作发生后会显示审计记录</span></div></article></section>
</template>
@@ -283,7 +287,7 @@ function mapModels(items: CatalogModel[], providersList: CatalogProvider[]): Mod
<template v-else-if="view === 'admin-capacity'">
<section class="page-heading"><div><span>CAPACITY CONTROL</span><h1>并发与队列</h1><p>显示最近调用记录中的运行、排队数量,以及每个模型分组的配置上限。</p></div><div class="heading-actions"><span class="admin-badge"><ShieldCheck :size="15" />队列保护已启用</span><button class="button secondary" @click="refreshOverviewData(true)"><RefreshCcw :size="15" />刷新监控</button></div></section>
<section class="capacity-grid"><article class="capacity-main"><div class="capacity-ring"><strong>{{ adminSummary?.capacityGroups.reduce((total, group) => total + group.running, 0) ?? '—' }}</strong><span>运行中</span></div><div><small>CONFIGURED CAPACITY</small><h2>{{ adminSummary?.capacityGroups.reduce((total, group) => total + group.limit, 0) ?? '—' }} 个分组上限</h2><p>同步请求超过上限时会在平台内排队,超出等待窗口后返回 429。</p></div></article><article class="metric-card"><span class="icon-tile orange"><Clock3 :size="18" /></span><div><small>等待任务</small><strong>{{ adminSummary?.waiting ?? '—' }}</strong><em>queued / running</em></div></article><article class="metric-card"><span class="icon-tile cyan"><Timer :size="18" /></span><div><small>排队窗口</small><strong>30s</strong><em>GATEWAY_QUEUE_WAIT_MS</em></div></article><article class="metric-card"><span class="icon-tile green"><CheckCircle2 :size="18" /></span><div><small>调度状态</small><strong>正常</strong><em>Redis 原子占用与释放</em></div></article></section>
<section class="capacity-grid"><article class="capacity-main"><div class="capacity-ring"><strong>{{ adminSummary?.capacityGroups.reduce((total, group) => total + group.running, 0) ?? '—' }}</strong><span>运行中</span></div><div><small>CONFIGURED CAPACITY</small><h2>{{ adminSummary?.capacityGroups.reduce((total, group) => total + group.limit, 0) ?? '—' }} 个分组上限</h2><p>同步请求超过上限时会在平台内排队,超出等待窗口后返回 429。</p></div></article><article class="metric-card"><span class="icon-tile orange"><Clock3 :size="18" /></span><div><small>等待任务</small><strong>{{ adminSummary?.waiting ?? '—' }}</strong><em>queued / running</em></div></article><article class="metric-card"><span class="icon-tile cyan"><Timer :size="18" /></span><div><small>排队窗口</small><strong>30s</strong><em>环境默认值</em></div></article><article class="metric-card"><span class="icon-tile green"><CheckCircle2 :size="18" /></span><div><small>调度状态</small><strong>已启用</strong><em>数据库队列与 Redis 占用</em></div></article></section>
<section class="panel table-card"><header class="panel-header"><div><span>CAPACITY GROUPS</span><h3>并发与排队状态</h3></div><span class="select-button static">最近 10 分钟</span></header><div class="responsive-table"><table><thead><tr><th>资源组</th><th>运行中</th><th>并发上限</th><th>排队数</th><th>预计等待</th><th>状态</th></tr></thead><tbody><tr v-for="group in queueGroups" :key="group.id"><td><strong>{{ group.name }}</strong><small>{{ group.type }}</small></td><td>{{ group.running }}</td><td>{{ group.limit || '默认' }}</td><td>{{ group.queued }}</td><td>{{ group.wait }}</td><td><span class="status-chip" :class="group.status === '正常' ? 'success' : 'warning'"><i></i>{{ group.status }}</span></td></tr><tr v-if="!queueGroups.length"><td colspan="6"><div class="empty-state compact"><Gauge :size="22" /><strong>暂无活跃模型分组</strong><span>启用并定价的模型调用后会显示容量状态</span></div></td></tr></tbody></table></div></section>
</template>
@@ -308,7 +312,7 @@ function mapModels(items: CatalogModel[], providersList: CatalogProvider[]): Mod
<template v-else>
<section class="page-heading"><div><span>PLATFORM SETTINGS</span><h1>平台设置</h1><p>展示当前服务器策略;敏感配置通过发布版本和环境变量管理。</p></div><span class="admin-badge"><ShieldCheck :size="15" />服务器策略</span></section>
<section class="settings-grid"><article class="panel settings-card"><header class="panel-header"><div><span>ACCESS CONTROL</span><h3>用户注册策略</h3></div><KeyRound :size="18" /></header><p>当前注册与验证码策略由服务端环境变量控制,页面提供实际入口状态。</p><div class="setting-list"><div><span><strong>邀请码注册</strong><small>管理端可创建、停用和查看邀请码记录</small></span><span class="status-chip success"><i></i>已启用</span></div><div><span><strong>邮箱验证码</strong><small>SMTP 发信通道由服务端配置</small></span><span class="status-chip success"><i></i>已接入</span></div><div><span><strong>手机号验证码</strong><small>短信通道由阿里云 AccessKey、签名和模板配置</small></span><span class="status-chip success"><i></i>已接入</span></div></div></article><article class="panel settings-card"><header class="panel-header"><div><span>OPERATIONS</span><h3>内测运营策略</h3></div><Settings2 :size="18" /></header><p>需要改变服务器策略时,请修改发布目录的 .env.cloud 后按升级流程重启。</p><div class="setting-list"><div><span><strong>额度发放与扣减</strong><small>在“用户与额度”中支持增加、减少和设置人民币余额</small></span><button class="button secondary small" @click="emit('navigate', 'admin-users')">打开</button></div><div><span><strong>并发排队</strong><small>模型组和 API Key 采用 Redis 原子占用,默认等待 30 秒</small></span><button class="button secondary small" @click="emit('navigate', 'admin-capacity')">查看</button></div><div><span><strong>操作审计</strong><small>认证、渠道、模型、Key 和额度变更都会记录</small></span><button class="button secondary small" @click="emit('navigate', 'admin-audit')">查看</button></div></div></article></section>
<section class="settings-grid"><article class="panel settings-card"><header class="panel-header"><div><span>ACCESS CONTROL</span><h3>用户注册策略</h3></div><KeyRound :size="18" /></header><p>当前注册与验证码策略由服务端环境变量控制,页面提供实际入口状态。</p><div class="setting-list"><div><span><strong>邀请码注册</strong><small>管理端可创建、停用和查看邀请码记录</small></span><span class="status-chip success"><i></i>已启用</span></div><div><span><strong>邮箱验证码</strong><small>SMTP 发信通道由服务端配置</small></span><span class="status-chip" :class="verificationChannels === null ? 'warning' : verificationChannels.email ? 'success' : 'warning'"><i></i>{{ verificationChannels === null ? '未读取' : verificationChannels.email ? '已接入' : '未配置' }}</span></div><div><span><strong>手机号验证码</strong><small>短信通道由阿里云 AccessKey、签名和模板配置</small></span><span class="status-chip" :class="verificationChannels === null ? 'warning' : verificationChannels.phone ? 'success' : 'warning'"><i></i>{{ verificationChannels === null ? '未读取' : verificationChannels.phone ? '已接入' : '未配置' }}</span></div></div></article><article class="panel settings-card"><header class="panel-header"><div><span>OPERATIONS</span><h3>内测运营策略</h3></div><Settings2 :size="18" /></header><p>需要改变服务器策略时,请修改发布目录的 .env.cloud 后按升级流程重启。</p><div class="setting-list"><div><span><strong>额度发放与扣减</strong><small>在“用户与额度”中支持增加、减少和设置人民币余额</small></span><button class="button secondary small" @click="emit('navigate', 'admin-users')">打开</button></div><div><span><strong>并发排队</strong><small>模型组和 API Key 采用 Redis 原子占用,默认等待 30 秒</small></span><button class="button secondary small" @click="emit('navigate', 'admin-capacity')">查看</button></div><div><span><strong>操作审计</strong><small>认证、渠道、模型、Key 和额度变更都会记录</small></span><button class="button secondary small" @click="emit('navigate', 'admin-audit')">查看</button></div></div></article></section>
</template>
<SlidePanel v-if="selectedUsage" :title="selectedUsage.modelName || selectedUsage.modelId || '调用记录详情'" eyebrow="REQUEST TRACE" @close="selectedUsage = null"><dl class="detail-list usage-detail-list"><div><dt>记录 ID</dt><dd><code>{{ selectedUsage.id }}</code></dd></div><div><dt>请求时间</dt><dd>{{ new Date(selectedUsage.createdAt).toLocaleString('zh-CN') }}</dd></div><div><dt>用户 / Key</dt><dd>{{ selectedUsage.userName || selectedUsage.userAccount || '--' }} / {{ selectedUsage.keyName || selectedUsage.keyPrefix || '--' }}</dd></div><div><dt>模型 / 供应商</dt><dd>{{ selectedUsage.modelName || selectedUsage.modelId }} / {{ selectedUsage.providerName || selectedUsage.providerId || '--' }}</dd></div><div><dt>状态与耗时</dt><dd>{{ selectedUsage.status }} · {{ selectedUsage.latencyMs ?? '--' }} ms</dd></div><div><dt>输入 / 输出单位</dt><dd>{{ selectedUsage.inputUnits ?? 0 }} / {{ selectedUsage.outputUnits ?? 0 }}</dd></div></dl><label class="form-label">输入数据(已脱敏)</label><pre class="usage-payload">{{ formatUsagePayload(selectedUsage.input) }}</pre><label class="form-label">输出数据(已脱敏)</label><pre class="usage-payload">{{ formatUsagePayload(selectedUsage.output) }}</pre><div v-if="selectedUsage.errorMessage" class="notice warning-notice"><AlertTriangle :size="16" /><span>{{ selectedUsage.errorCode }} · {{ selectedUsage.errorMessage }}</span></div><label class="form-label">管理员备注</label><textarea v-model="usageNote" class="text-input modal-textarea" placeholder="记录排查结论或运营备注"></textarea><template #footer><button class="button secondary" @click="saveUsageNote"><Check :size="16" />保存备注</button><button class="button danger" @click="deleteUsage(selectedUsage.id)"><Trash2 :size="16" />删除记录</button><button class="button primary" @click="selectedUsage = null">关闭</button></template></SlidePanel>