diff --git a/frontend/src/components/account/CNProviderQuotaCell.vue b/frontend/src/components/account/CNProviderQuotaCell.vue
index d814173abb..9cddb9f088 100644
--- a/frontend/src/components/account/CNProviderQuotaCell.vue
+++ b/frontend/src/components/account/CNProviderQuotaCell.vue
@@ -4,7 +4,7 @@
data-test="cn-provider-quota"
class="min-w-[220px] space-y-1"
>
-
cnQuotaCellVisible(props.account))
const loading = ref(false)
const error = ref(null)
-const data = ref(null)
+const probeData = ref(null)
+let probeGeneration = 0
// 后端周期任务/手动探测写入的 extra 快照键(_ 前缀,与后端
// cnQuotaExtraUpdates 对齐)。页面加载即有数据,无需等待探测。
@@ -118,6 +119,18 @@ const snapshotData = computed(() => {
return { success: true, tiers } as CNProviderQuotaProbeResult
})
+const data = computed(() => probeData.value ?? snapshotData.value)
+
+// A list refresh replaces account.extra even when its quota snapshot is
+// unchanged. Keep a manual probe until the quota values or snapshot version
+// actually change, rather than reverting it on unrelated account updates.
+watch(
+ [snapshotData, () => readExtraString(`${props.account.platform}_usage_updated_at`)],
+ (next, previous) => {
+ if (JSON.stringify(next) !== JSON.stringify(previous)) probeData.value = null
+ }
+)
+
// 快照是否过期(无更新时间或超过 staleness 窗口)→ 挂载时需要自动探测。
const snapshotIsStale = computed(() => {
const updatedAt = readExtraString(`${props.account.platform}_usage_updated_at`)
@@ -130,7 +143,6 @@ const snapshotIsStale = computed(() => {
// 避免静默失败导致单元格空白无提示)。
onMounted(() => {
if (!visible.value) return
- data.value = snapshotData.value
if (!snapshotIsStale.value) return
// 模块级去抖:列表页每行一个实例,翻页/筛选/刷新会重复挂载;同一账号
// 短时间内已自动探测过则跳过,避免对上游形成探测风暴。
@@ -168,27 +180,31 @@ const windowLabel = (window: string) => {
const handleProbe = async () => {
if (loading.value) return
+ const generation = ++probeGeneration
+ const accountID = props.account.id
loading.value = true
error.value = null
try {
- const result = await adminAPI.cnProviders.queryQuota(props.account.id)
+ const result = await adminAPI.cnProviders.queryQuota(accountID)
+ if (generation !== probeGeneration) return
// 失败时保留已渲染的快照条形图(仅显示错误行),成功才覆盖。
if (result.success) {
- data.value = result
+ probeData.value = result
} else {
error.value = result.error || t('common.error')
}
} catch (e) {
- error.value = extractErrorMessage(e)
+ if (generation === probeGeneration) error.value = extractErrorMessage(e)
} finally {
- loading.value = false
+ if (generation === probeGeneration) loading.value = false
}
}
watch(
- () => props.account.id,
+ [() => props.account.id, () => props.account.platform],
() => {
- data.value = null
+ probeGeneration++
+ probeData.value = null
error.value = null
loading.value = false
}
diff --git a/frontend/src/components/account/ModelWhitelistSelector.vue b/frontend/src/components/account/ModelWhitelistSelector.vue
index b1645a49fa..16788af018 100644
--- a/frontend/src/components/account/ModelWhitelistSelector.vue
+++ b/frontend/src/components/account/ModelWhitelistSelector.vue
@@ -278,6 +278,10 @@ const copyModelId = async (model: string) => {
const addCustom = () => {
const model = customModel.value.trim()
if (!model) return
+ if (model.includes('*')) {
+ appStore.showInfo(t('admin.accounts.modelWildcardNotSupported'))
+ return
+ }
if (props.modelValue.includes(model)) {
appStore.showInfo(t('admin.accounts.modelExists'))
return
diff --git a/frontend/src/components/account/__tests__/CNProviderQuotaCell.spec.ts b/frontend/src/components/account/__tests__/CNProviderQuotaCell.spec.ts
index e0384fe72c..55c250dbd1 100644
--- a/frontend/src/components/account/__tests__/CNProviderQuotaCell.spec.ts
+++ b/frontend/src/components/account/__tests__/CNProviderQuotaCell.spec.ts
@@ -1,5 +1,6 @@
import { flushPromises, mount } from '@vue/test-utils'
import { beforeEach, describe, expect, it, vi } from 'vitest'
+import { reactive } from 'vue'
import CNProviderQuotaCell from '../CNProviderQuotaCell.vue'
import UsageProgressBar from '../UsageProgressBar.vue'
import type { Account } from '@/types'
@@ -102,4 +103,85 @@ describe('CNProviderQuotaCell', () => {
await flushPromises()
expect(queryQuota).toHaveBeenCalledWith(account.id)
})
+
+ it('renders replacement quota values and windows for the same account without probing', async () => {
+ const wrapper = mount(CNProviderQuotaCell, { props: { account } })
+ await wrapper.setProps({ account: {
+ ...account,
+ extra: {
+ ...account.extra,
+ zhipu_5h_used_percent: 52,
+ zhipu_weekly_used_percent: null,
+ zhipu_monthly_used_percent: 81,
+ zhipu_monthly_reset_at: '2026-12-01T00:00:00Z'
+ }
+ } })
+ const bars = wrapper.findAllComponents(UsageProgressBar)
+ expect(bars.map(bar => bar.props('utilization'))).toEqual([52, 81])
+ expect(bars[1].props('label')).toBe('admin.accounts.cnProviders.windowMonthly')
+ expect(bars[1].props('resetsAt')).toBe('2026-12-01T00:00:00Z')
+ expect(queryQuota).not.toHaveBeenCalled()
+ })
+
+ it('reacts to quota changes inside the existing extra object', async () => {
+ const row = reactive({ ...account, extra: { ...account.extra } })
+ const wrapper = mount(CNProviderQuotaCell, { props: { account: row } })
+ row.extra.zhipu_5h_used_percent = 63
+ await flushPromises()
+ expect(wrapper.findAllComponents(UsageProgressBar)[0].props('utilization')).toBe(63)
+ expect(queryQuota).not.toHaveBeenCalled()
+ })
+
+ it('removes bars when a refreshed snapshot clears all quota windows', async () => {
+ const wrapper = mount(CNProviderQuotaCell, { props: { account } })
+ await wrapper.setProps({ account: {
+ ...account,
+ extra: { ...account.extra, zhipu_5h_used_percent: null, zhipu_weekly_used_percent: null }
+ } })
+ expect(wrapper.findAllComponents(UsageProgressBar)).toHaveLength(0)
+ expect(queryQuota).not.toHaveBeenCalled()
+ })
+
+ it('keeps a manual result through unrelated refreshes, then adopts a changed snapshot', async () => {
+ queryQuota.mockResolvedValue({ success: true, tiers: [{ window: '5h', used_percent: 44 }] })
+ const wrapper = mount(CNProviderQuotaCell, { props: { account } })
+ await wrapper.get('[data-test="cn-provider-quota-probe"]').trigger('click')
+ await flushPromises()
+ await wrapper.setProps({ account: {
+ ...account, extra: { ...account.extra, unrelated_field: true }
+ } })
+ expect(wrapper.findAllComponents(UsageProgressBar).map(bar => bar.props('utilization'))).toEqual([44])
+ await wrapper.setProps({ account: {
+ ...account, extra: { ...account.extra, zhipu_5h_used_percent: 66 }
+ } })
+ expect(wrapper.findAllComponents(UsageProgressBar).map(bar => bar.props('utilization'))).toEqual([66, 27])
+ expect(queryQuota).toHaveBeenCalledTimes(1)
+ })
+
+ it('adopts a new snapshot version even if its quota values equal the old snapshot', async () => {
+ queryQuota.mockResolvedValue({ success: true, tiers: [{ window: '5h', used_percent: 44 }] })
+ const wrapper = mount(CNProviderQuotaCell, { props: { account } })
+ await wrapper.get('[data-test="cn-provider-quota-probe"]').trigger('click')
+ await flushPromises()
+ await wrapper.setProps({ account: {
+ ...account,
+ extra: { ...account.extra, zhipu_usage_updated_at: new Date(Date.now() + 1000).toISOString() }
+ } })
+ expect(wrapper.findAllComponents(UsageProgressBar).map(bar => bar.props('utilization'))).toEqual([0, 27])
+ })
+
+ it('keeps the new account snapshot when the previous account probe finishes late', async () => {
+ let resolveProbe!: (value: unknown) => void
+ queryQuota.mockReturnValue(new Promise(resolve => { resolveProbe = resolve }))
+ const wrapper = mount(CNProviderQuotaCell, { props: { account } })
+ await wrapper.get('[data-test="cn-provider-quota-probe"]').trigger('click')
+ await wrapper.setProps({ account: {
+ ...account, id: 8, extra: { ...account.extra, zhipu_5h_used_percent: 91 }
+ } })
+ expect(wrapper.findAllComponents(UsageProgressBar)[0].props('utilization')).toBe(91)
+ resolveProbe({ success: true, tiers: [{ window: '5h', used_percent: 44 }] })
+ await flushPromises()
+ expect(wrapper.findAllComponents(UsageProgressBar)[0].props('utilization')).toBe(91)
+ expect(wrapper.get('[data-test="cn-provider-quota-probe"]').attributes('disabled')).toBeUndefined()
+ })
})
diff --git a/frontend/src/components/account/__tests__/ModelWhitelistSelector.spec.ts b/frontend/src/components/account/__tests__/ModelWhitelistSelector.spec.ts
index 83f843df73..277fdd4780 100644
--- a/frontend/src/components/account/__tests__/ModelWhitelistSelector.spec.ts
+++ b/frontend/src/components/account/__tests__/ModelWhitelistSelector.spec.ts
@@ -165,6 +165,33 @@ describe('ModelWhitelistSelector', () => {
wrapper.unmount()
})
+ it.each(['claude-*', '*', 'gpt-*-mini'])(
+ 'rejects wildcard whitelist entry %s without clearing the input', async (model) => {
+ const wrapper = mountSelector({ modelValue: ['gpt-5'] })
+ const input = wrapper.get('input[placeholder="admin.accounts.enterCustomModelName"]')
+ await input.setValue(model)
+ await wrapper.findAll('button').find(button => button.text() === 'admin.accounts.addModel')!.trigger('click')
+
+ expect(wrapper.emitted('update:modelValue')).toBeUndefined()
+ expect(showInfo).toHaveBeenCalledWith('admin.accounts.modelWildcardNotSupported')
+ expect((input.element as HTMLInputElement).value).toBe(model)
+ }
+ )
+
+ it('rejects wildcard entries submitted with Enter and accepts a corrected exact model', async () => {
+ const wrapper = mountSelector()
+ const input = wrapper.get('input[placeholder="admin.accounts.enterCustomModelName"]')
+ await input.setValue(' claude-* ')
+ await input.trigger('keydown.enter')
+ expect(wrapper.emitted('update:modelValue')).toBeUndefined()
+ expect(showInfo).toHaveBeenCalledWith('admin.accounts.modelWildcardNotSupported')
+
+ await input.setValue(' claude-sonnet-4-5 ')
+ await input.trigger('keydown.enter')
+ expect(wrapper.emitted('update:modelValue')).toEqual([[['claude-sonnet-4-5']]])
+ expect((input.element as HTMLInputElement).value).toBe('')
+ })
+
it('rejects a custom whitelist model that is already mapped to a different target', async () => {
const wrapper = mountSelector({ modelMappings: [{ from: 'gpt-latest', to: 'deepseek-chat' }] })
await wrapper.get('input[placeholder="admin.accounts.enterCustomModelName"]').setValue(' gpt-latest ')
diff --git a/frontend/src/components/charts/EndpointDistributionChart.vue b/frontend/src/components/charts/EndpointDistributionChart.vue
index a813df19b5..2cfc7f3110 100644
--- a/frontend/src/components/charts/EndpointDistributionChart.vue
+++ b/frontend/src/components/charts/EndpointDistributionChart.vue
@@ -83,6 +83,7 @@
| {{ t('admin.dashboard.requests') }} |
{{ t('admin.dashboard.tokens') }} |
{{ t('admin.dashboard.actual') }} |
+ {{ t('admin.dashboard.accountCost') }} |
{{ t('admin.dashboard.standard') }} |
@@ -109,15 +110,19 @@
${{ formatCost(item.actual_cost) }}
|
+
+ ${{ formatCost(item.account_cost ?? 0) }}
+ |
${{ formatCost(item.cost) }}
|
- |
+ |
|
@@ -161,6 +166,7 @@ const props = withDefaults(
showMetricToggle?: boolean
showSourceToggle?: boolean
enableBreakdown?: boolean
+ showAccountCost?: boolean
startDate?: string
endDate?: string
filters?: Record
@@ -174,7 +180,8 @@ const props = withDefaults(
source: 'inbound',
showMetricToggle: false,
showSourceToggle: false,
- enableBreakdown: true
+ enableBreakdown: true,
+ showAccountCost: true
}
)
diff --git a/frontend/src/i18n/locales/en/admin/accounts.ts b/frontend/src/i18n/locales/en/admin/accounts.ts
index 78f7c550dd..e851568a40 100644
--- a/frontend/src/i18n/locales/en/admin/accounts.ts
+++ b/frontend/src/i18n/locales/en/admin/accounts.ts
@@ -857,6 +857,7 @@ export default {
enterCustomModelName: 'Enter custom model name',
addModel: 'Add',
modelExists: 'Model already exists',
+ modelWildcardNotSupported: 'Wildcards are not supported in the model whitelist. Enter an exact model name.',
modelMappingConflict: 'A mapping already exists for {from} → {to}. Modify or remove it under Model Mapping before adding this whitelist model',
modelCount: '{count} models',
poolMode: 'Pool Mode',
diff --git a/frontend/src/i18n/locales/zh/admin/accounts.ts b/frontend/src/i18n/locales/zh/admin/accounts.ts
index e55b725e96..4c93b07972 100644
--- a/frontend/src/i18n/locales/zh/admin/accounts.ts
+++ b/frontend/src/i18n/locales/zh/admin/accounts.ts
@@ -968,6 +968,7 @@ export default {
enterCustomModelName: '输入自定义模型名称',
addModel: '填入',
modelExists: '该模型已存在',
+ modelWildcardNotSupported: '模型白名单不支持通配符,请输入完整的模型名称。',
modelMappingConflict: '该模型已配置映射 {from} → {to},请在模型映射中修改或删除后再添加白名单模型',
modelCount: '{count} 个模型',
poolMode: '池模式',
diff --git a/frontend/src/types/index.ts b/frontend/src/types/index.ts
index 1d3fd163d4..f98a4b83a8 100644
--- a/frontend/src/types/index.ts
+++ b/frontend/src/types/index.ts
@@ -2089,8 +2089,9 @@ export interface EndpointStat {
endpoint: string
requests: number
total_tokens: number
- cost: number
- actual_cost: number
+ cost: number // 标准计费
+ actual_cost: number // 实际扣除
+ account_cost?: number // 账号成本(仅管理员接口返回)
}
export interface GroupStat {
diff --git a/frontend/src/views/admin/ChannelsView.vue b/frontend/src/views/admin/ChannelsView.vue
index 5ee185131e..3633f27267 100644
--- a/frontend/src/views/admin/ChannelsView.vue
+++ b/frontend/src/views/admin/ChannelsView.vue
@@ -1196,18 +1196,10 @@ function formToAPI(): { group_ids: number[], model_pricing: ChannelModelPricing[
delete featuresConfig.codex_image_generation_bridge
}
- const bedrockCCCompat: Record = {}
- for (const section of form.platforms) {
- if (!section.enabled) continue
- if (section.platform === 'anthropic') {
- bedrockCCCompat[section.platform] = !!section.bedrock_cc_compat
- }
- }
- if (Object.keys(bedrockCCCompat).length > 0) {
- featuresConfig.bedrock_cc_compat = bedrockCCCompat
- } else {
- delete featuresConfig.bedrock_cc_compat
- }
+ // The backend reads a channel-level boolean; send false explicitly to clear it on update.
+ featuresConfig.bedrock_cc_compat = form.platforms.some(
+ section => section.enabled && section.platform === 'anthropic' && section.bedrock_cc_compat
+ )
return { group_ids: uniqueGroupIds, model_pricing, model_mapping, features_config: featuresConfig }
}
diff --git a/frontend/src/views/admin/__tests__/ChannelsView.bedrockCompat.spec.ts b/frontend/src/views/admin/__tests__/ChannelsView.bedrockCompat.spec.ts
new file mode 100644
index 0000000000..1291095480
--- /dev/null
+++ b/frontend/src/views/admin/__tests__/ChannelsView.bedrockCompat.spec.ts
@@ -0,0 +1,177 @@
+import { defineComponent } from 'vue'
+import { flushPromises, mount } from '@vue/test-utils'
+import { beforeEach, describe, expect, it, vi } from 'vitest'
+import type { Channel, CreateChannelRequest, UpdateChannelRequest } from '@/api/admin/channels'
+import ChannelsView from '@/views/admin/ChannelsView.vue'
+
+const { listChannels, createChannel, updateChannel, getGroups, showSuccess, showError } = vi.hoisted(() => ({
+ listChannels: vi.fn(),
+ createChannel: vi.fn(),
+ updateChannel: vi.fn(),
+ getGroups: vi.fn(),
+ showSuccess: vi.fn(),
+ showError: vi.fn()
+}))
+
+vi.mock('@/api/admin', () => ({
+ adminAPI: {
+ channels: { list: listChannels, create: createChannel, update: updateChannel },
+ groups: { getAll: getGroups },
+ settings: { getWebSearchEmulationConfig: vi.fn().mockResolvedValue({ enabled: false }) }
+ }
+}))
+
+vi.mock('@/stores/app', () => ({ useAppStore: () => ({ showSuccess, showError }) }))
+
+vi.mock('vue-i18n', async () => ({
+ ...await vi.importActual('vue-i18n'),
+ useI18n: () => ({ t: (key: string) => key })
+}))
+
+function mountView() {
+ return mount(ChannelsView, {
+ global: {
+ stubs: {
+ AppLayout: defineComponent({ template: '' }),
+ TablePageLayout: defineComponent({
+ template: ''
+ }),
+ BaseDialog: defineComponent({
+ props: ['show'],
+ template: ''
+ }),
+ DataTable: defineComponent({
+ props: ['data'],
+ template: '
'
+ }),
+ Pagination: true,
+ ConfirmDialog: true,
+ EmptyState: true,
+ Select: true,
+ Icon: true,
+ PlatformIcon: true,
+ PricingEntryCard: true
+ }
+ }
+ })
+}
+
+type View = ReturnType
+
+async function clickButton(wrapper: View, text: string) {
+ const button = wrapper.findAll('button').find(button => button.text() === text)
+ expect(button).toBeDefined()
+ await button!.trigger('click')
+ await flushPromises()
+}
+
+function platformCheckbox(wrapper: View, platform: string) {
+ return wrapper.findAll('label')
+ .find(label => label.text() === `admin.groups.platforms.${platform}`)!
+ .get('input[type="checkbox"]')
+}
+
+function bedrockToggle(wrapper: View) {
+ return wrapper.findAll('[role="switch"]')
+ .find(toggle => toggle.element.parentElement?.textContent?.includes('admin.channels.form.bedrockCCCompat'))!
+}
+
+function makeChannel(features: Record): Channel {
+ return {
+ id: 1, name: 'Bedrock relay', description: '', status: 'active',
+ billing_model_source: 'channel_mapped', restrict_models: false,
+ features_config: features, group_ids: [11, 22], model_pricing: [], model_mapping: {},
+ apply_pricing_to_account_stats: false, account_stats_pricing_rules: [],
+ created_at: '2026-01-01T00:00:00Z', updated_at: '2026-01-01T00:00:00Z'
+ }
+}
+
+describe('ChannelsView Bedrock compatibility', () => {
+ let stored: Channel[]
+
+ beforeEach(() => {
+ vi.clearAllMocks()
+ localStorage.clear()
+ stored = []
+ listChannels.mockImplementation(async () => ({ items: stored, total: stored.length }))
+ getGroups.mockResolvedValue([
+ { id: 11, name: 'Anthropic group', platform: 'anthropic', rate_multiplier: 1 },
+ { id: 22, name: 'OpenAI group', platform: 'openai', rate_multiplier: 1 }
+ ])
+ createChannel.mockImplementation(async (request: CreateChannelRequest) => {
+ const channel = makeChannel(request.features_config || {})
+ channel.group_ids = request.group_ids || []
+ stored = [channel]
+ return channel
+ })
+ updateChannel.mockImplementation(async (_id: number, request: UpdateChannelRequest) => {
+ stored = [{ ...stored[0], ...request } as Channel]
+ return stored[0]
+ })
+ })
+
+ it.each([true, false])('creates and reopens a channel with compatibility %s', async enabled => {
+ const wrapper = mountView()
+ await flushPromises()
+ await clickButton(wrapper, 'admin.channels.createChannel')
+ await wrapper.get('input[required]').setValue('Bedrock relay')
+ await platformCheckbox(wrapper, 'anthropic').setValue(true)
+ await clickButton(wrapper, 'admin.groups.platforms.anthropic')
+ await wrapper.findAll('label').find(label => label.text().includes('Anthropic group'))!
+ .get('input[type="checkbox"]').setValue(true)
+ if (enabled) await bedrockToggle(wrapper).trigger('click')
+
+ await wrapper.get('#channel-form').trigger('submit')
+ await flushPromises()
+ expect(showError).not.toHaveBeenCalled()
+ expect(createChannel).toHaveBeenCalledOnce()
+ expect(createChannel.mock.calls[0][0].features_config.bedrock_cc_compat).toBe(enabled)
+
+ await clickButton(wrapper, 'common.edit')
+ await clickButton(wrapper, 'admin.groups.platforms.anthropic')
+ expect(bedrockToggle(wrapper).attributes('aria-checked')).toBe(String(enabled))
+ wrapper.unmount()
+ })
+
+ it.each([true, false])('updates compatibility to %s while preserving other features', async enabled => {
+ stored = [makeChannel({ bedrock_cc_compat: true, future_feature: { enabled: true } })]
+ const wrapper = mountView()
+ await flushPromises()
+ await clickButton(wrapper, 'common.edit')
+ await clickButton(wrapper, 'admin.groups.platforms.anthropic')
+ expect(bedrockToggle(wrapper).attributes('aria-checked')).toBe('true')
+ if (!enabled) await bedrockToggle(wrapper).trigger('click')
+
+ await wrapper.get('#channel-form').trigger('submit')
+ await flushPromises()
+ expect(showError).not.toHaveBeenCalled()
+ expect(updateChannel).toHaveBeenCalledOnce()
+ expect(updateChannel.mock.calls[0][1].features_config).toMatchObject({
+ bedrock_cc_compat: enabled,
+ future_feature: { enabled: true }
+ })
+
+ await clickButton(wrapper, 'common.edit')
+ await clickButton(wrapper, 'admin.groups.platforms.anthropic')
+ expect(bedrockToggle(wrapper).attributes('aria-checked')).toBe(String(enabled))
+ wrapper.unmount()
+ })
+
+ it('explicitly disables compatibility when the Anthropic section is removed', async () => {
+ stored = [makeChannel({ bedrock_cc_compat: true, future_feature: { enabled: true } })]
+ const wrapper = mountView()
+ await flushPromises()
+ await clickButton(wrapper, 'common.edit')
+ await platformCheckbox(wrapper, 'anthropic').setValue(false)
+
+ await wrapper.get('#channel-form').trigger('submit')
+ await flushPromises()
+ expect(showError).not.toHaveBeenCalled()
+ expect(updateChannel).toHaveBeenCalledOnce()
+ expect(updateChannel.mock.calls[0][1]).toMatchObject({
+ group_ids: [22],
+ features_config: { bedrock_cc_compat: false, future_feature: { enabled: true } }
+ })
+ wrapper.unmount()
+ })
+})
diff --git a/frontend/src/views/user/UsageView.vue b/frontend/src/views/user/UsageView.vue
index 8ced361457..688bc19817 100644
--- a/frontend/src/views/user/UsageView.vue
+++ b/frontend/src/views/user/UsageView.vue
@@ -58,6 +58,7 @@
:show-source-toggle="false"
:show-metric-toggle="true"
:enable-breakdown="false"
+ :show-account-cost="false"
:title="t('usage.endpointDistribution')"
:start-date="startDate"
:end-date="endDate"