feat(console): add deletion lifecycle, usage history and balance adjustments
This commit is contained in:
1 parent
32e977df5c
commit
7360cf3ebe
18 files changed
+832
-68
No files matched your search
@@ -50,6 +50,8 @@ export interface WalletEntry {
|
||||
id: string
|
||||
amount: number
|
||||
balanceAfter: number
|
||||
balanceBefore: number
|
||||
operation: 'increase' | 'decrease' | 'set'
|
||||
currency: 'CNY'
|
||||
reason: string
|
||||
createdAt: string
|
||||
@@ -200,6 +202,31 @@ export class CatalogApiError extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
export interface UserUsageRecord extends UsageAuditRecord {
|
||||
logicalModelId?: string
|
||||
groupName?: string
|
||||
endpoint?: string
|
||||
callMode?: string
|
||||
requestSource?: string
|
||||
userAgent?: string
|
||||
cachedInputUnits?: number
|
||||
cacheWriteUnits?: number
|
||||
firstTokenMs?: number
|
||||
reasoningEffort?: string
|
||||
taskId?: string
|
||||
progress?: number
|
||||
result?: unknown
|
||||
}
|
||||
export interface UserUsagePage extends UsageAuditPage {
|
||||
records: UserUsageRecord[]
|
||||
summary: { totalRequests: number; inputUnits: number; outputUnits: number; cachedInputUnits?: number; cacheWriteUnits?: number; totalCost?: number; pricedRequests: number; averageLatencyMs?: number }
|
||||
}
|
||||
export interface UsageOptions {
|
||||
keys: Array<{ id: string; name: string; deleted: boolean }>
|
||||
models: Array<{ id: string; name: string }>
|
||||
groups: Array<{ id: string; modelId: string; name: string; channel: string }>
|
||||
}
|
||||
|
||||
class HttpCatalogClient {
|
||||
constructor(private readonly baseUrl: string) {}
|
||||
|
||||
@@ -238,10 +265,32 @@ class HttpCatalogClient {
|
||||
await this.request(`/api/keys/${encodeURIComponent(id)}/revoke`, { method: 'POST' })
|
||||
}
|
||||
|
||||
async setKeyStatus(id: string, status: 'active' | 'disabled') {
|
||||
await this.request(`/api/keys/${encodeURIComponent(id)}/status`, { method: 'PATCH', body: JSON.stringify({ status }) })
|
||||
}
|
||||
async deleteKey(id: string) { await this.request(`/api/keys/${encodeURIComponent(id)}`, { method: 'DELETE' }) }
|
||||
async deleteCatalog(kind: 'channel' | 'model' | 'group', id: string) {
|
||||
const resource = { channel: 'providers', model: 'model-definitions', group: 'models' }[kind]
|
||||
await this.request(`/api/admin/${resource}/${encodeURIComponent(id)}`, { method: 'DELETE' })
|
||||
}
|
||||
async adjustCredit(userId: string, input: { requestId: string; operation: 'increase' | 'decrease' | 'set'; amount: string; reason: string; expectedBalance: string }) {
|
||||
return this.request<{ id: string; balance: number; currency: 'CNY' }>(`/api/admin/users/${encodeURIComponent(userId)}/wallet/adjustments`, { method: 'POST', body: JSON.stringify(input) })
|
||||
}
|
||||
async listUsage(filters: Record<string, string | number>) {
|
||||
return this.request<UserUsagePage>(`/api/usage?${new URLSearchParams(Object.entries(filters).map(([k, v]) => [k, String(v)]))}`)
|
||||
}
|
||||
async usageOptions() { return this.request<UsageOptions>('/api/usage/options') }
|
||||
async usageDetail(id: string) { return this.request<{ record: UserUsageRecord }>(`/api/usage/${encodeURIComponent(id)}`) }
|
||||
async exportUsage(filters: Record<string, string | number>) {
|
||||
const response = await fetch(`${this.baseUrl}/api/usage/export?${new URLSearchParams(Object.entries(filters).map(([k,v]) => [k,String(v)]))}`, { credentials: 'include' })
|
||||
if (!response.ok) { const data = await response.json().catch(() => ({})); throw new Error(data.error?.message || '导出失败') }
|
||||
return response.blob()
|
||||
}
|
||||
|
||||
async chatCompletion(apiKey: string, input: { model: string; prompt: string }) {
|
||||
return this.request<ChatCompletionResult>('/v1/chat/completions', {
|
||||
method: 'POST',
|
||||
headers: { Authorization: `Bearer ${apiKey}` },
|
||||
headers: { Authorization: `Bearer ${apiKey}`, 'X-Moyi-Source': 'playground' },
|
||||
body: JSON.stringify({ model: input.model, messages: [{ role: 'user', content: input.prompt }] }),
|
||||
})
|
||||
}
|
||||
@@ -249,7 +298,7 @@ class HttpCatalogClient {
|
||||
async createMediaTask(apiKey: string, input: { model: string; prompt: string; mediaType: '3d' | 'video' }) {
|
||||
const payload = await this.request<{ task: AsyncTaskResult }>(input.mediaType === 'video' ? '/v1/video/tasks' : '/v1/3d/tasks', {
|
||||
method: 'POST',
|
||||
headers: { Authorization: `Bearer ${apiKey}` },
|
||||
headers: { Authorization: `Bearer ${apiKey}`, 'X-Moyi-Source': 'playground' },
|
||||
body: JSON.stringify({ model: input.model, prompt: input.prompt }),
|
||||
})
|
||||
return payload.task
|
||||
|
||||
Reference in new issue
Block a user