feat(grok): 账单绝对金额、调度阈值 UI、搜索/Voice 计费与 /v1/web_search

- BillingSummary 输出 prepaid/monthly_used/on_demand 绝对金额,并映射官方 7d/30d 进度条
- 账号编辑页支持 credentials.account_scheduling_threshold 覆盖;Settings 文案细化
- groups.search_price_per_1k + 管理端/缓存全链路;SearchCount/AudioUsage 请求级计费
- Voice TTS/STT/Realtime 成功路径 RecordUsage;独立 /v1/web_search 原生 Grok 搜索
This commit is contained in:
IanShaw027 committed 2026-08-07 15:52:55 +08:00
1 parent 99ad01f6de
commit 79df1647d4
46 files changed
+1665 -77

No files matched your search

@@ -1375,6 +1375,40 @@
</div>
</div>
<div
v-if="supportsAccountSchedulingThresholdOverride"
class="border-t border-gray-200 pt-4 dark:border-dark-600"
data-testid="account-scheduling-threshold-section"
>
<div class="mb-3 flex items-center justify-between">
<div>
<label class="input-label mb-0">{{ t('admin.accounts.accountSchedulingThresholdOverride') }}</label>
<p class="mt-1 text-xs text-gray-500 dark:text-gray-400">
{{ t('admin.accounts.accountSchedulingThresholdOverrideHint') }}
</p>
</div>
<input
v-model="accountSchedulingThresholdOverrideEnabled"
data-testid="account-scheduling-threshold-override-enabled"
type="checkbox"
class="h-4 w-4 rounded border-gray-300 text-primary-600 focus:ring-primary-500"
/>
</div>
<div v-if="accountSchedulingThresholdOverrideEnabled">
<label class="input-label">{{ t('admin.accounts.accountSchedulingThresholdOverrideValue') }}</label>
<input
v-model.number="accountSchedulingThresholdOverrideValue"
data-testid="account-scheduling-threshold-override-value"
type="number"
min="1"
max="100"
class="input"
/>
<p class="input-hint">{{ t('admin.accounts.accountSchedulingThresholdOverrideDisabledHint') }}</p>
</div>
</div>
<!-- Intercept Warmup Requests (Anthropic/Antigravity) -->
<div
v-if="account?.platform === 'anthropic' || account?.platform === 'antigravity'"
@@ -2867,6 +2901,12 @@ const antigravityWhitelistModels = ref<string[]>([])
const antigravityModelMappings = ref<ModelMapping[]>([])
const isSyncingAntigravityUpstream = ref(false)
const tempUnschedEnabled = ref(false)
const accountSchedulingThresholdOverrideEnabled = ref(false)
const accountSchedulingThresholdOverrideValue = ref(100)
const ACCOUNT_SCHEDULING_THRESHOLD_CREDENTIAL_KEY = 'account_scheduling_threshold'
const supportsAccountSchedulingThresholdOverride = computed(() =>
supportsAccountSchedulingThresholdOverridePlatform(props.account?.platform)
)
const tempUnschedRules = ref<TempUnschedRuleForm[]>([])
const getModelMappingKey = createStableObjectKeyResolver<ModelMapping>('edit-model-mapping')
const getOpenAICompactModelMappingKey = createStableObjectKeyResolver<ModelMapping>('edit-openai-compact-model-mapping')
@@ -3512,6 +3552,7 @@ const syncFormFromAccount = (newAccount: Account | null) => {
loadQuotaControlSettings(newAccount)
loadTempUnschedRules(credentials)
loadAccountSchedulingThresholdOverride(newAccount.platform, credentials)
// Load header override state (anthropic/openai apikey + grok apikey/oauth)
headerOverrideEnabled.value = false
@@ -3874,6 +3915,67 @@ const applyTempUnschedConfig = (credentials: Record<string, unknown>) => {
return true
}
const supportsAccountSchedulingThresholdOverridePlatform = (platform: Account['platform'] | undefined) =>
platform === 'openai' || platform === 'anthropic' || platform === 'grok'
const normalizeAccountSchedulingThresholdOverride = (value: unknown): number | null => {
if (value === null || value === undefined || value === '') {
return null
}
const numeric = Number(value)
if (!Number.isFinite(numeric)) {
return null
}
const integer = Math.trunc(numeric)
if (integer < 1 || integer > 100) {
return null
}
return integer
}
const clampAccountSchedulingThresholdOverride = (value: unknown): number =>
Math.min(100, Math.max(1, Math.trunc(Number(value) || 100)))
const loadAccountSchedulingThresholdOverride = (
platform: Account['platform'] | undefined,
credentials: Record<string, unknown> | undefined
) => {
if (!supportsAccountSchedulingThresholdOverridePlatform(platform)) {
accountSchedulingThresholdOverrideEnabled.value = false
accountSchedulingThresholdOverrideValue.value = 100
return
}
const value = normalizeAccountSchedulingThresholdOverride(
credentials?.[ACCOUNT_SCHEDULING_THRESHOLD_CREDENTIAL_KEY]
)
accountSchedulingThresholdOverrideEnabled.value = value !== null
accountSchedulingThresholdOverrideValue.value = value ?? 100
}
const applyAccountSchedulingThresholdOverridePatch = (
credentials: Record<string, unknown>,
currentCredentials: Record<string, unknown>,
platform: Account['platform'] | undefined = props.account?.platform
) => {
if (!supportsAccountSchedulingThresholdOverridePlatform(platform)) {
return
}
const current = normalizeAccountSchedulingThresholdOverride(
currentCredentials[ACCOUNT_SCHEDULING_THRESHOLD_CREDENTIAL_KEY]
)
if (!accountSchedulingThresholdOverrideEnabled.value) {
if (current !== null) {
credentials[ACCOUNT_SCHEDULING_THRESHOLD_CREDENTIAL_KEY] = null
}
return
}
const next = clampAccountSchedulingThresholdOverride(accountSchedulingThresholdOverrideValue.value)
if (current !== next) {
credentials[ACCOUNT_SCHEDULING_THRESHOLD_CREDENTIAL_KEY] = next
}
}
function loadTempUnschedRules(credentials?: Record<string, unknown>) {
tempUnschedEnabled.value = credentials?.temp_unschedulable_enabled === true
const rawRules = credentials?.temp_unschedulable_rules
@@ -4233,6 +4335,7 @@ const handleSubmit = async () => {
// Add intercept warmup requests setting
applyInterceptWarmup(newCredentials, interceptWarmupRequests.value, 'edit')
applyAccountSchedulingThresholdOverridePatch(newCredentials, currentCredentials)
if (!applyTempUnschedConfig(newCredentials)) {
return
}
@@ -4251,6 +4354,7 @@ const handleSubmit = async () => {
// Add intercept warmup requests setting
applyInterceptWarmup(newCredentials, interceptWarmupRequests.value, 'edit')
applyAccountSchedulingThresholdOverridePatch(newCredentials, currentCredentials)
if (!applyTempUnschedConfig(newCredentials)) {
return
}
@@ -4299,6 +4403,7 @@ const handleSubmit = async () => {
}
applyInterceptWarmup(newCredentials, interceptWarmupRequests.value, 'edit')
applyAccountSchedulingThresholdOverridePatch(newCredentials, currentCredentials)
if (!applyTempUnschedConfig(newCredentials)) {
return
}
@@ -4356,6 +4461,7 @@ const handleSubmit = async () => {
}
applyInterceptWarmup(newCredentials, interceptWarmupRequests.value, 'edit')
applyAccountSchedulingThresholdOverridePatch(newCredentials, currentCredentials)
if (!applyTempUnschedConfig(newCredentials)) {
return
}
@@ -4367,6 +4473,7 @@ const handleSubmit = async () => {
const newCredentials: Record<string, unknown> = { ...currentCredentials }
applyInterceptWarmup(newCredentials, interceptWarmupRequests.value, 'edit')
applyAccountSchedulingThresholdOverridePatch(newCredentials, currentCredentials)
if (!applyTempUnschedConfig(newCredentials)) {
return
}