feat: Provider 异步删除、可配置密码策略、Hub 超时优化及多项改进

- 新增 Provider 异步删除任务系统,后台分阶段删除子资源并清理残留引用
- 新增可配置密码策略等级(weak/medium/strong),支持系统设置面板调整
- aether-hub 升级至 0.1.4,idle timeout 支持禁用(设为 0),worker 默认超时调整为 120s
- OAuth 手动续期增加 Redis 分布式锁,防止并发刷新冲突
- ProxyNode 心跳检测改为 asyncio.to_thread,避免阻塞事件循环
- 删除 ModelMultiSelect 和 useInvalidModels,MultiSelect 组件通用化
- 明确 allowed_providers/allowed_api_formats 的 NULL 与空数组语义
- 前端 StandaloneKeyFormDialog、UserFormDialog 等多处 UI 优化
- 新增 Alembic 迁移脚本清理 Provider 删除后的残留引用
- 补充相关测试用例
This commit is contained in:
fawney19
2026-03-12 01:11:35 +08:00
parent 0d770d1c4d
commit 6e51a3f45d
55 changed files with 3219 additions and 862 deletions

View File

@@ -1,183 +0,0 @@
<template>
<div class="space-y-2">
<Label class="text-sm font-medium">允许的模型</Label>
<div class="relative">
<button
type="button"
class="flex h-10 w-full items-center justify-between rounded-lg border bg-background px-3 text-left transition-colors hover:bg-muted/50"
@click="isOpen = !isOpen"
>
<span
class="truncate text-sm"
:class="
modelValue.length ? 'text-foreground' : 'text-muted-foreground'
"
>
{{
modelValue.length ? `已选择 ${modelValue.length}` : '全部可用'
}}
<span
v-if="invalidModels.length"
class="text-destructive"
>({{ invalidModels.length }} 个已失效)</span>
</span>
<ChevronDown
class="h-4 w-4 text-muted-foreground transition-transform"
:class="isOpen ? 'rotate-180' : ''"
/>
</button>
<div
v-if="isOpen"
class="fixed inset-0 z-[80]"
@click.stop="isOpen = false"
/>
<div
v-if="isOpen"
class="absolute z-[90] mt-1 w-full rounded-lg border bg-popover shadow-lg"
>
<div
v-if="showSearch"
class="sticky top-0 z-10 border-b bg-popover/95 p-1 backdrop-blur supports-[backdrop-filter]:bg-popover/85"
>
<div class="relative">
<Search
class="pointer-events-none absolute left-3 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"
/>
<Input
v-model="searchQuery"
:placeholder="searchPlaceholder"
class="h-8 rounded-md border-border/60 bg-popover pl-8 text-xs"
@keydown.stop
/>
</div>
</div>
<div class="max-h-48 overflow-y-auto">
<div
v-for="modelName in filteredInvalidModels"
:key="modelName"
class="flex cursor-pointer items-center gap-2 bg-destructive/5 px-3 py-2 hover:bg-muted/50"
@click="removeModel(modelName)"
>
<input
type="checkbox"
:checked="true"
class="h-4 w-4 shrink-0 cursor-pointer rounded border-gray-300"
@click.stop
@change="removeModel(modelName)"
>
<span class="min-w-0 truncate text-sm text-destructive">{{ modelName }}</span>
<span class="shrink-0 text-xs text-destructive/70">(已失效)</span>
</div>
<div
v-for="model in filteredModels"
:key="model.name"
class="flex cursor-pointer items-center gap-2 px-3 py-2 hover:bg-muted/50"
@click="toggleModel(model.name)"
>
<input
type="checkbox"
:checked="modelValue.includes(model.name)"
class="h-4 w-4 shrink-0 cursor-pointer rounded border-gray-300"
@click.stop
@change="toggleModel(model.name)"
>
<span class="min-w-0 truncate text-sm">{{ model.name }}</span>
</div>
<div
v-if="
filteredModels.length === 0 && filteredInvalidModels.length === 0
"
class="px-3 py-2 text-sm text-muted-foreground"
>
{{ searchQuery.trim() ? '未找到匹配项' : '暂无可用模型' }}
</div>
</div>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { computed, ref, watch } from 'vue'
import { Input, Label } from '@/components/ui'
import { ChevronDown, Search } from 'lucide-vue-next'
import { useInvalidModels } from '@/composables/useInvalidModels'
import { matchesSearchQuery } from '@/utils/search'
export interface ModelWithName {
name: string
}
const props = withDefaults(
defineProps<{
modelValue: string[]
models: ModelWithName[]
searchThreshold?: number
searchPlaceholder?: string
}>(),
{
searchThreshold: 8,
searchPlaceholder: '输入模型名搜索...',
},
)
const emit = defineEmits<{
'update:modelValue': [value: string[]]
}>()
const isOpen = ref(false)
const searchQuery = ref('')
const { invalidModels } = useInvalidModels(
computed(() => props.modelValue),
computed(() => props.models),
)
const showSearch = computed(
() =>
props.models.length + invalidModels.value.length >= props.searchThreshold,
)
const filteredInvalidModels = computed(() => {
if (!showSearch.value || !searchQuery.value.trim()) {
return invalidModels.value
}
return invalidModels.value.filter((modelName) =>
matchesSearchQuery(searchQuery.value, modelName),
)
})
const filteredModels = computed(() => {
if (!showSearch.value || !searchQuery.value.trim()) {
return props.models
}
return props.models.filter((model) =>
matchesSearchQuery(searchQuery.value, model.name),
)
})
watch(isOpen, (open) => {
if (!open) {
searchQuery.value = ''
}
})
function toggleModel(name: string) {
const newValue = [...props.modelValue]
const index = newValue.indexOf(name)
if (index === -1) {
newValue.push(name)
} else {
newValue.splice(index, 1)
}
emit('update:modelValue', newValue)
}
function removeModel(name: string) {
const newValue = props.modelValue.filter((m) => m !== name)
emit('update:modelValue', newValue)
}
</script>

View File

@@ -4,7 +4,8 @@
type="button"
:class="
cn(
'flex h-10 w-full items-center justify-between rounded-lg border bg-background px-3 text-left transition-colors hover:bg-muted/50',
'flex h-10 w-full items-center justify-between rounded-lg border bg-background px-3 text-left transition-colors',
disabled ? 'cursor-not-allowed opacity-60 hover:bg-background' : 'hover:bg-muted/50',
triggerClass,
)
"
@@ -16,6 +17,10 @@
class="truncate text-sm"
>
{{ displayText }}
<span
v-if="invalidItems.length"
class="text-destructive"
>({{ invalidItems.length }} 个已失效)</span>
</span>
<ChevronDown
class="h-4 w-4 shrink-0 text-muted-foreground transition-transform"
@@ -50,6 +55,23 @@
</div>
<div class="max-h-48 overflow-y-auto">
<div
v-for="item in filteredInvalidItems"
:key="'invalid-' + item"
class="flex cursor-pointer items-center gap-2 bg-destructive/5 px-3 py-2 hover:bg-muted/50"
@click="remove(item)"
>
<input
type="checkbox"
:checked="true"
class="h-4 w-4 shrink-0 cursor-pointer rounded border-gray-300"
@click.stop
@change="remove(item)"
>
<span class="min-w-0 truncate text-sm text-destructive">{{ item }}</span>
<span class="shrink-0 text-xs text-destructive/70">(已失效)</span>
</div>
<div
v-for="item in filteredOptions"
:key="item.value"
@@ -66,7 +88,7 @@
<span class="min-w-0 truncate text-sm">{{ item.label }}</span>
</div>
<div
v-if="filteredOptions.length === 0"
v-if="filteredOptions.length === 0 && filteredInvalidItems.length === 0"
class="px-3 py-2 text-sm text-muted-foreground"
>
{{ searchQuery.trim() ? noResultsText : emptyText }}
@@ -122,9 +144,27 @@ const emit = defineEmits<{
const isOpen = ref(false)
const searchQuery = ref('')
const showSearch = computed(
() => props.searchable && props.options.length >= props.searchThreshold,
const validValues = computed(() => new Set(props.options.map(o => o.value)))
const invalidItems = computed(() =>
props.modelValue.filter(v => !validValues.value.has(v)),
)
const totalCount = computed(() => props.options.length + invalidItems.value.length)
const showSearch = computed(
() => props.searchable && totalCount.value >= props.searchThreshold,
)
const filteredInvalidItems = computed(() => {
if (!showSearch.value || !searchQuery.value.trim()) {
return invalidItems.value
}
return invalidItems.value.filter((item) =>
matchesSearchQuery(searchQuery.value, item),
)
})
const filteredOptions = computed(() => {
if (!showSearch.value || !searchQuery.value.trim()) {
return props.options
@@ -161,4 +201,8 @@ function toggle(value: string) {
}
emit('update:modelValue', newValue)
}
function remove(value: string) {
emit('update:modelValue', props.modelValue.filter(v => v !== value))
}
</script>

View File

@@ -9,6 +9,5 @@ export { default as AlertDialog } from './AlertDialog.vue'
export { default as LoadingState } from './LoadingState.vue'
// 表单组件
export { default as ModelMultiSelect } from './ModelMultiSelect.vue'
export { default as MultiSelect } from './MultiSelect.vue'
export { default as TimeRangePicker } from './TimeRangePicker.vue'