fix: align model availability and retail pricing controls
This commit is contained in:
1 parent
af505c5596
commit
813b406da4
9 files changed
+130
-47
No files matched your search
@@ -1,5 +1,23 @@
|
||||
import type { CatalogModel, CatalogProvider, LogicalModel } from './catalog'
|
||||
|
||||
type Readiness = Pick<CatalogModel, 'pricingConfigured' | 'billingReady' | 'executionReady' | 'integrationDeferred' | 'billingReason'> & { status?: string }
|
||||
export function routeReadinessLabel(route: Readiness) {
|
||||
if (route.integrationDeferred) return '暂不接入'
|
||||
if (route.status === 'disabled') return '已停用'
|
||||
if (!route.pricingConfigured) return '报价待核实'
|
||||
if (route.executionReady === false) return '执行接口待接入'
|
||||
if (route.billingReady === false) return '用量计费待核实'
|
||||
return '可调用'
|
||||
}
|
||||
|
||||
export function routeReadinessReason(route: Readiness) {
|
||||
if (route.integrationDeferred) return '该模型本期暂不接入,当前不开放调用。'
|
||||
if (route.status === 'disabled') return '该分组已停用。'
|
||||
if (routeReadinessLabel(route) === '可调用') return ''
|
||||
if (route.pricingConfigured && route.executionReady === false) return '该分组的执行接口尚未接入,当前不开放调用。'
|
||||
return route.billingReason || `${routeReadinessLabel(route)},当前不开放调用。`
|
||||
}
|
||||
|
||||
export interface ModelCatalogSummary {
|
||||
publishedModels: number
|
||||
readyModels: number
|
||||
|
||||
@@ -15,6 +15,26 @@ export interface DisplayPricing {
|
||||
listPriceCny?: { input?: number; output?: number; cachedInput?: number }
|
||||
}
|
||||
|
||||
/** Change only editable retail amounts; retain source evidence and async billing metadata. */
|
||||
export function editRetailAmounts(original: DisplayPricing | undefined, unit: string, values: { input: string | number; output: string | number; cachedInput: string | number; imageInput: string | number; price: string | number }) {
|
||||
const result: DisplayPricing = { ...original, unit }
|
||||
const parse = (value: string | number) => {
|
||||
if (!String(value).trim()) return undefined
|
||||
const amount = Number(value)
|
||||
if (!Number.isFinite(amount) || amount < 0 || amount > 1000000 || Number(amount.toFixed(8)) !== amount) throw new Error('人民币价格须在 0–100 万之间,最多 8 位小数')
|
||||
return amount
|
||||
}
|
||||
if (unit === 'CNY / 1M tokens') {
|
||||
delete result.price
|
||||
for (const key of ['input', 'output', 'cachedInput', 'imageInput'] as const) result[key] = parse(values[key])
|
||||
} else {
|
||||
if (!['CNY / image', 'CNY / task', 'CNY / generation'].includes(unit)) throw new Error('请选择已支持的人民币计费单位')
|
||||
result.price = parse(values.price)
|
||||
for (const key of ['input', 'output', 'cachedInput', 'imageInput'] as const) delete result[key]
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
function numberLabel(value: number | undefined, currency = '¥') {
|
||||
if (value === undefined || value === null || !Number.isFinite(value)) return '待配置'
|
||||
return `${currency}${value.toLocaleString('zh-CN', { maximumFractionDigits: 8 })}`
|
||||
|
||||
Reference in new issue
Block a user