fix(admin): 修复 Key 自动获取模型时 allowed_models 同步逻辑

- 关闭自动获取上游模型时清空 allowed_models
- 开启自动获取上游模型时立即拉取并覆盖 allowed_models
- 增加模型覆盖提示并补充相关回归测试
This commit is contained in:
AAEE86
2026-04-13 21:00:53 +08:00
committed by fawney19
parent 1000b706be
commit 23233a3243
7 changed files with 411 additions and 19 deletions

View File

@@ -276,7 +276,7 @@
v-if="showAutoFetchWarning"
class="text-xs text-amber-600 dark:text-amber-400"
>
已配置的模型权限将在下次获取时被覆盖
{{ autoFetchWarningMessage }}
</p>
</div>
<Switch v-model="form.auto_fetch_models" />
@@ -441,6 +441,15 @@ const showAutoFetchWarning = computed(() => {
return true
})
const autoFetchWarningMessage = computed(() => {
if (!showAutoFetchWarning.value || !props.editingKey?.allowed_models) return ''
const models = Array.isArray(props.editingKey.allowed_models)
? props.editingKey.allowed_models
: []
if (models.length === 0) return ''
return `当前 Key 模型权限存在以下模型:${models.map(model => `“${model}”`).join('、')},开启自动获取后将被覆盖`
})
// 检查是否正在切换认证类型
const switchingToVertexAI = computed(() =>
!!props.editingKey &&
@@ -754,6 +763,7 @@ async function handleSave() {
const authConfig = parseAuthConfig()
if (props.editingKey) {
const shouldClearAllowedModels = !!props.editingKey.auto_fetch_models && !form.value.auto_fetch_models
// 更新模式
// 注意rpm_limit 使用 null 表示自适应模式
// undefined 表示"保持原值不变"会在 JSON 序列化时被忽略
@@ -769,6 +779,7 @@ async function handleSave() {
note: form.value.note,
is_active: form.value.is_active,
capabilities: capabilitiesData,
allowed_models: shouldClearAllowedModels ? null : undefined,
auto_fetch_models: form.value.auto_fetch_models,
model_include_patterns: parsePatternText(form.value.model_include_patterns_text),
model_exclude_patterns: parsePatternText(form.value.model_exclude_patterns_text)

View File

@@ -124,7 +124,7 @@
v-if="showAutoFetchWarning"
class="text-xs text-amber-600 dark:text-amber-400"
>
已配置的模型权限将在下次获取时被覆盖
{{ autoFetchWarningMessage }}
</p>
</div>
<Switch v-model="form.auto_fetch_models" />
@@ -220,6 +220,15 @@ const showAutoFetchWarning = computed(() => {
return true
})
const autoFetchWarningMessage = computed(() => {
if (!showAutoFetchWarning.value || !props.editingKey?.allowed_models) return ''
const models = Array.isArray(props.editingKey.allowed_models)
? props.editingKey.allowed_models
: []
if (models.length === 0) return ''
return `当前 Key 模型权限存在以下模型:${models.map(model => `${model}`).join('、')},开启自动获取后将被覆盖`
})
// 表单是否可以保存
const canSave = computed(() => {
// 必须填写名称
@@ -345,6 +354,7 @@ async function handleSave() {
saving.value = true
try {
const shouldClearAllowedModels = !!props.editingKey.auto_fetch_models && !form.value.auto_fetch_models
const updateData: EndpointAPIKeyUpdate = {
name: form.value.name,
internal_priority: form.value.internal_priority,
@@ -352,6 +362,7 @@ async function handleSave() {
cache_ttl_minutes: form.value.cache_ttl_minutes,
max_probe_interval_minutes: form.value.max_probe_interval_minutes,
note: form.value.note,
allowed_models: shouldClearAllowedModels ? null : undefined,
auto_fetch_models: form.value.auto_fetch_models,
model_include_patterns: parsePatternText(form.value.model_include_patterns_text),
model_exclude_patterns: parsePatternText(form.value.model_exclude_patterns_text)