feat: add model management module with provider CRUD
- New /models page with provider list (built-in + custom) - Add provider via preset selection or custom URL with auto-fetch models - Delete provider removes from auth.json credential_pool + config.yaml custom_providers - Auto-switch model on add, fallback switch on delete - Sync sidebar ModelSelector on all provider changes - Unified provider presets in shared/providers.ts (frontend + backend) - Backend uses hardcoded catalog first, live probe as fallback Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref, computed } from 'vue'
|
||||
import * as systemApi from '@/api/system'
|
||||
import type { AvailableModelGroup, CustomProvider } from '@/api/system'
|
||||
import { useAppStore } from './app'
|
||||
|
||||
export const useModelsStore = defineStore('models', () => {
|
||||
const providers = ref<AvailableModelGroup[]>([])
|
||||
const defaultModel = ref('')
|
||||
const loading = ref(false)
|
||||
|
||||
const customProviders = computed(() =>
|
||||
providers.value.filter(g => g.provider.startsWith('custom:')),
|
||||
)
|
||||
|
||||
const builtinProviders = computed(() =>
|
||||
providers.value.filter(g => !g.provider.startsWith('custom:')),
|
||||
)
|
||||
|
||||
const allModels = computed(() =>
|
||||
providers.value.flatMap(g =>
|
||||
g.models.map(m => ({
|
||||
id: m,
|
||||
provider: g.provider,
|
||||
label: g.label,
|
||||
base_url: g.base_url,
|
||||
isDefault: m === defaultModel.value,
|
||||
})),
|
||||
),
|
||||
)
|
||||
|
||||
async function fetchProviders() {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await systemApi.fetchAvailableModels()
|
||||
providers.value = res.groups
|
||||
defaultModel.value = res.default
|
||||
} catch (err) {
|
||||
console.error('Failed to fetch providers:', err)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function setDefaultModel(modelId: string, provider: string) {
|
||||
await systemApi.updateDefaultModel({ default: modelId, provider })
|
||||
defaultModel.value = modelId
|
||||
const appStore = useAppStore()
|
||||
appStore.loadModels()
|
||||
}
|
||||
|
||||
async function addProvider(data: CustomProvider) {
|
||||
await systemApi.addCustomProvider(data)
|
||||
await fetchProviders()
|
||||
const appStore = useAppStore()
|
||||
appStore.loadModels()
|
||||
}
|
||||
|
||||
async function removeProvider(name: string) {
|
||||
await systemApi.removeCustomProvider(name)
|
||||
await fetchProviders()
|
||||
const appStore = useAppStore()
|
||||
appStore.loadModels()
|
||||
}
|
||||
|
||||
return {
|
||||
providers,
|
||||
defaultModel,
|
||||
loading,
|
||||
customProviders,
|
||||
builtinProviders,
|
||||
allModels,
|
||||
fetchProviders,
|
||||
setDefaultModel,
|
||||
addProvider,
|
||||
removeProvider,
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user