complete reset async billing and upstream key rotation

This commit is contained in:
wlx committed 2026-09-27 14:58:24 +08:00
1 parent b54b6a8ac4
commit a80896e3c7
19 files changed
+531 -50

No files matched your search

+14
View File
@@ -27,6 +27,8 @@ export interface LoginInput {
export interface AuthClient {
verificationChannels(): Promise<{ email: boolean; phone: boolean }>
sendVerificationCode(account: string, invitationCode: string): Promise<{ retryAfterSeconds: number }>
sendPasswordResetCode(account: string): Promise<{ retryAfterSeconds: number }>
resetPassword(input: { account: string; verificationCode: string; newPassword: string }): Promise<void>
health(): Promise<{ status: 'ok'; service: string; capabilities: { verificationCode: boolean; passwordReset: boolean } }>
login(input: LoginInput): Promise<AuthUser>
register(input: RegisterInput): Promise<AuthUser>
@@ -48,6 +50,18 @@ class HttpAuthClient implements AuthClient {
})
}
sendPasswordResetCode(account: string) {
return this.request<{ retryAfterSeconds: number }>('/api/auth/password-reset/code', {
method: 'POST', body: JSON.stringify({ account }),
})
}
async resetPassword(input: { account: string; verificationCode: string; newPassword: string }) {
await this.request<void>('/api/auth/password-reset', {
method: 'POST', body: JSON.stringify(input),
})
}
async health() {
return this.request<{ status: 'ok'; service: string; capabilities: { verificationCode: boolean; passwordReset: boolean } }>('/health')
}
+3 -1
View File
@@ -30,6 +30,7 @@ export interface CatalogModel {
outputTypes: string[]
capabilities: Record<string, unknown>
pricing?: {
price?: number
input?: number
output?: number
cachedInput?: number
@@ -41,6 +42,7 @@ export interface CatalogModel {
listPriceUsd?: { input?: number; output?: number; cachedInput?: number }
}
pricingConfigured?: boolean
billingReady?: boolean
priority?: number
maxConcurrency?: number
executionReady?: boolean
@@ -498,7 +500,7 @@ class HttpCatalogClient {
return this.request<{ model: CatalogModel }>(`/api/admin/models${id ? `/${encodeURIComponent(id)}` : ''}`, { method: id ? 'PATCH' : 'POST', body: JSON.stringify(input) })
}
async createAdminModel(input: { providerId: string; publicName: string; upstreamModel: string; modelKey?: string; sourceLabel?: string; type: CatalogModelType; mode: CatalogCallMode; description?: string; inputTypes?: string[]; outputTypes?: string[]; pricing?: { input?: number; output?: number; unit?: string }; priority?: number; maxConcurrency?: number }) {
async createAdminModel(input: { providerId: string; publicName: string; upstreamModel: string; modelKey?: string; sourceLabel?: string; type: CatalogModelType; mode: CatalogCallMode; description?: string; inputTypes?: string[]; outputTypes?: string[]; pricing?: { price?: number; input?: number; output?: number; unit?: string }; priority?: number; maxConcurrency?: number }) {
return this.request<{ model: CatalogModel }>('/api/admin/models', { method: 'POST', body: JSON.stringify(input) })
}
+2
View File
@@ -35,6 +35,7 @@ export interface ModelItem {
modelKey?: string
sourceLabel?: string
pricing?: {
price?: number
input?: number
output?: number
cachedInput?: number
@@ -46,6 +47,7 @@ export interface ModelItem {
listPriceUsd?: { input?: number; output?: number; cachedInput?: number }
}
pricingConfigured?: boolean
billingReady?: boolean
priority?: number
maxConcurrency?: number
executionReady?: boolean
+2 -1
View File
@@ -83,7 +83,7 @@ async function refreshOverviewData(notifyOnSuccess = false) {
models.value = mapModels(modelResult.models, providerResult.providers)
const activeProviders = new Set(providerResult.providers.filter((item) => item.status === 'active').map((item) => item.id))
const activeDefinitions = new Set(modelResult.logicalModels.filter((item) => item.status === 'active').map((item) => item.id))
const publishedRoutes = modelResult.models.filter((item) => item.status === 'active' && activeProviders.has(item.providerId) && activeDefinitions.has(item.logicalModelId) && item.pricingConfigured && item.executionReady !== false)
const publishedRoutes = modelResult.models.filter((item) => item.status === 'active' && activeProviders.has(item.providerId) && activeDefinitions.has(item.logicalModelId) && item.pricingConfigured && item.billingReady !== false && item.executionReady !== false)
publicRouteCount.value = publishedRoutes.length
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
@@ -263,6 +263,7 @@ function mapModels(items: CatalogModel[], providersList: CatalogProvider[]): Mod
logicalModelId: model.logicalModelId,
vendorName: model.vendorName,
pricingConfigured: model.pricingConfigured,
billingReady: model.billingReady,
executionReady: model.executionReady,
}))
}
+44 -4
View File
@@ -66,6 +66,25 @@ async function sendCode() {
} finally { sendingCode.value = false }
}
async function sendResetCode() {
if (sendingCode.value || cooldown.value) return
const value = account.value.trim()
const valid = registerChannel.value === 'email'
? /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value)
: /^(?:\+86)?1[3-9]\d{9}$/.test(value)
if (!valid) return emit('notify', `请输入有效的${accountLabel.value}`)
sendingCode.value = true
try {
const result = await authClient.sendPasswordResetCode(value)
cooldown.value = result.retryAfterSeconds
clearInterval(cooldownTimer)
cooldownTimer = setInterval(() => { if (cooldown.value > 0) cooldown.value--; else clearInterval(cooldownTimer) }, 1000)
emit('notify', '验证码已发送,5 分钟内有效')
} catch (error) {
emit('notify', error instanceof AuthApiError ? error.message : '验证码发送失败')
} finally { sendingCode.value = false }
}
async function submitLogin() {
if (!account.value.trim() || !password.value) return emit('notify', '请输入账号和密码')
loading.value = true
@@ -102,8 +121,24 @@ async function submitRegister() {
}
}
function submitReset() {
emit('notify', '密码重置服务尚未接入,请联系平台管理员处理')
async function submitReset() {
if (!account.value.trim()) return emit('notify', `请输入${accountLabel.value}`)
if (!/^\d{6}$/.test(verificationCode.value)) return emit('notify', '请输入 6 位验证码')
if (password.value.length < 8) return emit('notify', '密码至少需要 8 位')
if (password.value !== confirmPassword.value) return emit('notify', '两次输入的密码不一致')
loading.value = true
try {
await authClient.resetPassword({ account: account.value.trim(), verificationCode: verificationCode.value, newPassword: password.value })
loading.value = false
password.value = ''
confirmPassword.value = ''
verificationCode.value = ''
emit('notify', '密码已重置,请使用新密码登录')
switchMode('login')
} catch (error) {
loading.value = false
emit('notify', error instanceof AuthApiError ? error.message : '密码重置失败')
}
}
onMounted(async () => {
@@ -187,10 +222,15 @@ onMounted(async () => {
<div class="auth-card-header reset-header">
<span class="reset-icon"><LockKeyhole :size="22" /></span>
<h2>重置密码</h2>
<p>密码重置服务尚未接入,当前请联系平台管理员处理。</p>
<p>通过注册邮箱或手机号获取验证码,设置新的登录密码。</p>
</div>
<form class="auth-form" @submit.prevent="submitReset">
<button class="auth-submit" type="submit">联系平台管理员<ArrowRight :size="17" /></button>
<div class="register-channel"><button type="button" :class="{ active: registerChannel === 'email' }" @click="registerChannel = 'email'"><Mail :size="15" />邮箱重置</button><button type="button" :class="{ active: registerChannel === 'phone' }" @click="registerChannel = 'phone'"><Phone :size="15" />手机重置</button></div>
<label><span>{{ accountLabel }}</span><div class="auth-input"><component :is="registerChannel === 'email' ? Mail : Phone" :size="17" /><input v-model="account" :placeholder="accountPlaceholder" autocomplete="username" /></div></label>
<label><span>验证码</span><div class="auth-code-row"><div class="auth-input"><ShieldCheck :size="17" /><input v-model="verificationCode" inputmode="numeric" autocomplete="one-time-code" maxlength="6" pattern="[0-9]{6}" required placeholder="6 位验证码" /></div><button type="button" :disabled="sendingCode || cooldown > 0 || !channels[registerChannel]" @click="sendResetCode">{{ sendingCode ? '发送中' : cooldown ? `${cooldown} 秒后重发` : '获取验证码' }}</button></div></label>
<label><span>新密码</span><div class="auth-input"><LockKeyhole :size="17" /><input v-model="password" :type="showPassword ? 'text' : 'password'" autocomplete="new-password" placeholder="至少 8 位字符" /><button type="button" @click="showPassword = !showPassword"><EyeOff v-if="showPassword" :size="17" /><Eye v-else :size="17" /></button></div></label>
<label><span>确认新密码</span><div class="auth-input"><LockKeyhole :size="17" /><input v-model="confirmPassword" :type="showConfirmPassword ? 'text' : 'password'" autocomplete="new-password" placeholder="再次输入新密码" /><button type="button" @click="showConfirmPassword = !showConfirmPassword"><EyeOff v-if="showConfirmPassword" :size="17" /><Eye v-else :size="17" /></button></div></label>
<button class="auth-submit" type="submit" :disabled="loading"><span v-if="loading" class="spinner"></span><template v-else>重置密码<ArrowRight :size="17" /></template></button>
</form>
</template>
</article>
+16 -6
View File
@@ -66,7 +66,7 @@ const galleryModels = computed<GalleryModel[]>(() => buildModelCatalog(catalogDe
const routes = groups.map(group => catalogModels.value.find(item => item.id === group.id)!).filter(Boolean)
const providerNames = [...new Set(routes.map(group => group.provider))]
return { ...mapCatalogModel(definition), groups: routes, providerNames,
provider: providerNames.join(' / ') || '暂无上线分组', availability: routes.some(group => group.pricingConfigured && group.executionReady !== false) ? '在线' : '待上线' }
provider: providerNames.join(' / ') || '暂无上线分组', availability: routes.some(group => group.pricingConfigured && group.billingReady !== false && group.executionReady !== false) ? '在线' : '待上线' }
}))
const featuredModels = computed(() => [...galleryModels.value].sort((a, b) => Number(!!b.groups.length) - Number(!!a.groups.length)).slice(0, 3))
const activeModel = ref<ModelItem>(emptyModel)
@@ -219,7 +219,11 @@ function formatUsdPrice(value: number | undefined) {
function standardPriceLabel(model: GalleryModel) {
const pricing = model.groups.find(group => group.pricing?.listPriceUsd)?.pricing
if (!pricing?.listPriceUsd) return '标准价待同步'
if (!pricing?.listPriceUsd) {
const unit = pricing?.unit
const price = pricing?.price ?? pricing?.input
return unit && price !== undefined ? `¥${Number(price).toLocaleString('zh-CN', { maximumFractionDigits: 8 })} / ${unit}` : '标准价待同步'
}
return `${formatUsdPrice(pricing.listPriceUsd.input)} 输入 / ${formatUsdPrice(pricing.listPriceUsd.output)} 输出 · USD / 1M`
}
@@ -231,24 +235,30 @@ function groupDiscountLabel(group: ModelItem) {
function groupPriceLabel(group: ModelItem) {
const pricing = group.pricing
if (!group.pricingConfigured || !pricing) return '当前不可调用:价格待配置'
if (pricing.unit && !String(pricing.unit).toLowerCase().includes('token')) {
const price = pricing.price ?? pricing.input
return price === undefined ? `计费单位:${pricing.unit}` : `¥${Number(price).toLocaleString('zh-CN', { maximumFractionDigits: 8 })} / ${pricing.unit}`
}
const input = pricing.input === undefined ? '待定' : `¥${pricing.input.toLocaleString('zh-CN', { maximumFractionDigits: 8 })}`
const output = pricing.output === undefined ? '待定' : `¥${pricing.output.toLocaleString('zh-CN', { maximumFractionDigits: 8 })}`
return `${input} 输入 / ${output} 输出 · ${pricing.unit || 'CNY / 1M tokens'}`
}
function hasCallableGroup(model: GalleryModel) {
return model.groups.some(group => group.pricingConfigured && group.executionReady !== false)
return model.groups.some(group => group.pricingConfigured && group.billingReady !== false && group.executionReady !== false)
}
function modelAvailabilityLabel(model: GalleryModel) {
if (!model.groups.length) return '待上线'
if (hasCallableGroup(model)) return '在线'
if (model.mode === '异步' && model.groups.some(group => group.pricingConfigured && group.executionReady === false)) return '异步执行器待接入'
if (model.mode === '异步' && model.groups.some(group => group.pricingConfigured && group.billingReady === false)) return '异步按任务计费待配置'
return '价格待配置'
}
function modelUnavailableLabel(model: GalleryModel) {
if (model.mode === '异步' && model.groups.some(group => group.pricingConfigured && group.executionReady === false)) return '异步执行器待接入'
if (model.mode === '异步' && model.groups.some(group => group.pricingConfigured && group.billingReady === false)) return '异步按任务计费待配置'
return '价格待配置'
}
@@ -288,7 +298,7 @@ async function refreshOverview() {
}
function tryModel(model: GalleryModel) {
const group = model.groups.find(item => item.pricingConfigured)
const group = model.groups.find(item => item.pricingConfigured && item.billingReady !== false && item.executionReady !== false)
if (!group) return emit('notify', '该模型已收录,但分组价格尚未配置,暂时不能调用')
activeModel.value = group
callMode.value = group.mode
@@ -437,7 +447,7 @@ function mapCatalogModels(items: CatalogModel[], providers: Array<{ id: string;
...mapCatalogModel(item), logicalModelId: item.logicalModelId,
provider: providerNames.get(item.providerId) || item.providerId,
vendorName: item.vendorName,
sourceLabel: item.sourceLabel, pricing: item.pricing, pricingConfigured: item.pricingConfigured, priority: item.priority, maxConcurrency: item.maxConcurrency, executionReady: item.executionReady,
sourceLabel: item.sourceLabel, pricing: item.pricing, pricingConfigured: item.pricingConfigured, billingReady: item.billingReady, priority: item.priority, maxConcurrency: item.maxConcurrency, executionReady: item.executionReady,
}))
}
@@ -762,7 +772,7 @@ $env:OPENAI_API_KEY="你的 MOYI 用户 API Key"
<label>调用模型 ID <code>{{ group.id }}</code></label>
<button class="text-link" @click="copy(group.id, '调用模型 ID', group.id)"><Copy :size="14" />{{ copySucceeded(group.id) ? '已复制' : '复制调用 ID' }}</button>
<small class="drawer-pricing">标准价:{{ group.pricing?.listPriceUsd ? `${formatUsdPrice(group.pricing.listPriceUsd.input)} 输入 / ${formatUsdPrice(group.pricing.listPriceUsd.output)} 输出 · USD / 1M` : '待同步' }} · {{ groupPriceLabel(group) }} · 对外 {{ groupDiscountLabel(group) }}</small>
<button class="button secondary" :disabled="!group.pricingConfigured || group.executionReady === false" @click="tryModel({ ...selectedModel, groups: [group] })">{{ !group.pricingConfigured ? '价格待配置' : group.executionReady === false ? '异步执行器待接入' : '试用此分组' }}</button>
<button class="button secondary" :disabled="!group.pricingConfigured || group.billingReady === false || group.executionReady === false" @click="tryModel({ ...selectedModel, groups: [group] })">{{ !group.pricingConfigured ? '价格待配置' : group.executionReady === false ? '异步执行器待接入' : group.billingReady === false ? '异步按任务计费待配置' : '试用此分组' }}</button>
</section>
<template #footer><button class="button primary full" :disabled="!hasCallableGroup(selectedModel)" @click="tryModel(selectedModel)"><Play :size="16" />{{ !selectedModel.groups.length ? '分组待上线' : hasCallableGroup(selectedModel) ? '在线试用' : modelUnavailableLabel(selectedModel) }}</button><button class="button secondary full" @click="selectedModel = null; emit('navigate', 'docs')"><BookOpen :size="16" />查看文档</button></template>
</SlidePanel>