feat: replace preset metrics with live data
This commit is contained in:
1 parent
6dcc1504e2
commit
6de29ebd6d
10 files changed
+419
-326
No files matched your search
@@ -24,6 +24,7 @@ export interface LoginInput {
|
||||
}
|
||||
|
||||
export interface AuthClient {
|
||||
health(): Promise<{ status: 'ok'; service: string; capabilities: { verificationCode: boolean; passwordReset: boolean } }>
|
||||
login(input: LoginInput): Promise<AuthUser>
|
||||
register(input: RegisterInput): Promise<AuthUser>
|
||||
currentUser(): Promise<AuthUser | undefined>
|
||||
@@ -33,6 +34,10 @@ export interface AuthClient {
|
||||
class HttpAuthClient implements AuthClient {
|
||||
constructor(private readonly baseUrl: string) {}
|
||||
|
||||
async health() {
|
||||
return this.request<{ status: 'ok'; service: string; capabilities: { verificationCode: boolean; passwordReset: boolean } }>('/health')
|
||||
}
|
||||
|
||||
async login(input: LoginInput) {
|
||||
const payload = await this.request<{ user: AuthUser }>('/api/auth/login', {
|
||||
method: 'POST',
|
||||
@@ -85,40 +90,6 @@ class HttpAuthClient implements AuthClient {
|
||||
}
|
||||
}
|
||||
|
||||
class DemoAuthClient implements AuthClient {
|
||||
private readonly sessionKey = 'moyi_demo_session'
|
||||
private readonly user: AuthUser = {
|
||||
id: 'demo_admin',
|
||||
account: 'demo@moyi.ai',
|
||||
accountKind: 'email',
|
||||
displayName: '林默',
|
||||
role: 'admin',
|
||||
status: 'active',
|
||||
createdAt: '2026-08-20T00:00:00.000Z',
|
||||
}
|
||||
|
||||
async login(input: LoginInput) {
|
||||
if (!input.account.trim() || !input.password) throw new AuthApiError(400, '请输入账号和密码')
|
||||
sessionStorage.setItem(this.sessionKey, '1')
|
||||
return this.user
|
||||
}
|
||||
|
||||
async register(input: RegisterInput): Promise<AuthUser> {
|
||||
if (!input.invitationCode.trim()) throw new AuthApiError(400, '第一版内测需要填写邀请码')
|
||||
if (input.password.length < 8) throw new AuthApiError(400, '密码至少需要 8 位')
|
||||
sessionStorage.setItem(this.sessionKey, '1')
|
||||
return { ...this.user, account: input.account, displayName: input.displayName || input.account.split('@')[0] || 'MOYI 用户', role: 'user' }
|
||||
}
|
||||
|
||||
async currentUser() {
|
||||
return sessionStorage.getItem(this.sessionKey) ? this.user : undefined
|
||||
}
|
||||
|
||||
async logout() {
|
||||
sessionStorage.removeItem(this.sessionKey)
|
||||
}
|
||||
}
|
||||
|
||||
export class AuthApiError extends Error {
|
||||
constructor(
|
||||
readonly status: number,
|
||||
@@ -129,9 +100,6 @@ export class AuthApiError extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
const authMode = import.meta.env.VITE_AUTH_MODE || 'remote'
|
||||
const controlPlaneUrl = (import.meta.env.VITE_CONTROL_PLANE_URL || 'http://127.0.0.1:8787').replace(/\/$/, '')
|
||||
|
||||
export const authClient: AuthClient = authMode === 'demo'
|
||||
? new DemoAuthClient()
|
||||
: new HttpAuthClient(controlPlaneUrl)
|
||||
export const authClient: AuthClient = new HttpAuthClient(controlPlaneUrl)
|
||||
@@ -51,6 +51,54 @@ export interface CreatedCatalogKey {
|
||||
apiKey: CatalogApiKey
|
||||
}
|
||||
|
||||
export interface PlatformOverview {
|
||||
generatedAt: string
|
||||
callsToday: number
|
||||
callsThisMonth: number
|
||||
averageLatencyMs?: number
|
||||
availableCredit?: number
|
||||
availabilityPercent?: number
|
||||
asyncTasks: number
|
||||
asyncSuccessRate?: number
|
||||
tasks: { queued: number; running: number; succeeded: number; failed: number }
|
||||
series: Array<{ date: string; count: number }>
|
||||
ledger: Array<{ id: string; title: string; amount: number; createdAt: string }>
|
||||
}
|
||||
|
||||
export interface AdminCatalogUser {
|
||||
id: string
|
||||
account: string
|
||||
accountKind: 'email' | 'phone' | 'username'
|
||||
displayName: string
|
||||
role: 'user' | 'admin'
|
||||
status: 'active' | 'disabled'
|
||||
createdAt: string
|
||||
lastLoginAt?: string
|
||||
}
|
||||
|
||||
export interface AdminAuditEvent {
|
||||
id: string
|
||||
actorUserId?: string
|
||||
eventType: string
|
||||
targetType?: string
|
||||
targetId?: string
|
||||
ipAddress?: string
|
||||
details: Record<string, unknown>
|
||||
createdAt: string
|
||||
}
|
||||
|
||||
export interface AdminInvitation {
|
||||
id: string
|
||||
codePrefix: string
|
||||
label: string
|
||||
maxUses: number
|
||||
usedCount: number
|
||||
expiresAt?: string
|
||||
disabledAt?: string
|
||||
createdBy: string
|
||||
createdAt: string
|
||||
}
|
||||
|
||||
export interface ChatCompletionResult {
|
||||
id: string
|
||||
model: string
|
||||
@@ -99,6 +147,10 @@ class HttpCatalogClient {
|
||||
return this.request<{ keys: CatalogApiKey[] }>('/api/keys')
|
||||
}
|
||||
|
||||
async getOverview() {
|
||||
return this.request<PlatformOverview>('/api/overview')
|
||||
}
|
||||
|
||||
async createKey(input: { name: string; projectId?: string; scopes?: string[]; modelIds?: string[] }) {
|
||||
return this.request<CreatedCatalogKey>('/api/keys', { method: 'POST', body: JSON.stringify(input) })
|
||||
}
|
||||
@@ -135,6 +187,22 @@ class HttpCatalogClient {
|
||||
return this.request<{ models: CatalogModel[] }>('/api/admin/models')
|
||||
}
|
||||
|
||||
async listAdminUsers() {
|
||||
return this.request<{ users: AdminCatalogUser[] }>('/api/admin/users')
|
||||
}
|
||||
|
||||
async listAdminAudit(limit = 100) {
|
||||
return this.request<{ events: AdminAuditEvent[] }>(`/api/admin/audit?limit=${limit}`)
|
||||
}
|
||||
|
||||
async listAdminInvitations() {
|
||||
return this.request<{ invitations: AdminInvitation[] }>('/api/admin/invitations')
|
||||
}
|
||||
|
||||
async createAdminInvitation(input: { label?: string; maxUses?: number; expiresAt?: string }) {
|
||||
return this.request<{ code: string; invitation: AdminInvitation }>('/api/admin/invitations', { method: 'POST', body: JSON.stringify(input) })
|
||||
}
|
||||
|
||||
async listAdminProviders() {
|
||||
return this.request<{ providers: CatalogProvider[] }>('/api/admin/providers')
|
||||
}
|
||||
@@ -167,3 +235,4 @@ class HttpCatalogClient {
|
||||
|
||||
const controlPlaneUrl = (import.meta.env.VITE_CONTROL_PLANE_URL || 'http://127.0.0.1:8787').replace(/\/$/, '')
|
||||
export const catalogClient = new HttpCatalogClient(controlPlaneUrl)
|
||||
export const platformApiBaseUrl = (import.meta.env.VITE_PUBLIC_API_BASE_URL || `${controlPlaneUrl}/v1`).replace(/\/$/, '')
|
||||
@@ -0,0 +1,30 @@
|
||||
export type CopyResult = 'verified' | 'written' | 'failed'
|
||||
|
||||
export async function copyText(value: string): Promise<CopyResult> {
|
||||
if (!value) return 'failed'
|
||||
|
||||
try {
|
||||
if (navigator.clipboard?.writeText) {
|
||||
await navigator.clipboard.writeText(value)
|
||||
if (navigator.clipboard.readText) {
|
||||
try {
|
||||
return await navigator.clipboard.readText() === value ? 'verified' : 'failed'
|
||||
} catch {
|
||||
return 'written'
|
||||
}
|
||||
}
|
||||
return 'written'
|
||||
}
|
||||
} catch {}
|
||||
|
||||
const textarea = document.createElement('textarea')
|
||||
textarea.value = value
|
||||
textarea.setAttribute('readonly', '')
|
||||
textarea.style.position = 'fixed'
|
||||
textarea.style.opacity = '0'
|
||||
document.body.appendChild(textarea)
|
||||
textarea.select()
|
||||
const copied = document.execCommand('copy')
|
||||
textarea.remove()
|
||||
return copied ? 'written' : 'failed'
|
||||
}
|
||||
Reference in new issue
Block a user