mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-15 17:30:13 +08:00
fix(provider): persist model enable toggle (#7865)
* fix(provider): persist model enable toggle Fixes AstrBotDevs/AstrBot#7863 * fix(provider): wait for model toggle refresh
This commit is contained in:
@@ -89,6 +89,7 @@
|
||||
:supports-tool-call="supportsToolCall"
|
||||
:supports-reasoning="supportsReasoning"
|
||||
:format-context-limit="formatContextLimit"
|
||||
:saving-providers="savingProviderToggles"
|
||||
:testing-providers="testingProviders"
|
||||
:tm="tm"
|
||||
@fetch-models="fetchAvailableModels"
|
||||
@@ -209,6 +210,7 @@ const {
|
||||
availableModels,
|
||||
loadingModels,
|
||||
savingSource,
|
||||
savingProviderToggles,
|
||||
testingProviders,
|
||||
isSourceModified,
|
||||
configSchema,
|
||||
|
||||
@@ -84,12 +84,13 @@
|
||||
|
||||
<div class="provider-model-row__actions" @click.stop>
|
||||
<v-switch
|
||||
v-model="entry.provider.enable"
|
||||
:model-value="entry.provider.enable"
|
||||
density="compact"
|
||||
inset
|
||||
hide-details
|
||||
color="primary"
|
||||
class="provider-model-row__switch"
|
||||
:disabled="isProviderSaving(entry.provider.id)"
|
||||
@update:modelValue="emit('toggle-provider-enable', entry.provider, $event)"
|
||||
></v-switch>
|
||||
|
||||
@@ -97,7 +98,7 @@
|
||||
icon="mdi-connection"
|
||||
size="small"
|
||||
variant="text"
|
||||
:disabled="!entry.provider.enable"
|
||||
:disabled="!entry.provider.enable || isProviderSaving(entry.provider.id)"
|
||||
:loading="isProviderTesting(entry.provider.id)"
|
||||
@click.stop="emit('test-provider', entry.provider)"
|
||||
></v-btn>
|
||||
@@ -240,6 +241,10 @@ const props = defineProps({
|
||||
type: Array,
|
||||
default: () => []
|
||||
},
|
||||
savingProviders: {
|
||||
type: Array,
|
||||
default: () => []
|
||||
},
|
||||
tm: {
|
||||
type: Function,
|
||||
required: true
|
||||
@@ -288,6 +293,7 @@ const capabilityIcons = (metadata) => {
|
||||
}
|
||||
|
||||
const isProviderTesting = (providerId) => props.testingProviders.includes(providerId)
|
||||
const isProviderSaving = (providerId) => props.savingProviders.includes(providerId)
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
@@ -58,6 +58,7 @@ export function useProviderSources(options: UseProviderSourcesOptions) {
|
||||
const modelMetadata = ref<Record<string, any>>({})
|
||||
const loadingModels = ref(false)
|
||||
const savingSource = ref(false)
|
||||
const savingProviderToggles = ref<string[]>([])
|
||||
const testingProviders = ref<string[]>([])
|
||||
const isSourceModified = ref(false)
|
||||
const configSchema = ref<Record<string, any>>({})
|
||||
@@ -610,6 +611,33 @@ export function useProviderSources(options: UseProviderSourcesOptions) {
|
||||
}
|
||||
}
|
||||
|
||||
async function toggleProviderEnable(provider: any, value: boolean) {
|
||||
if (!provider?.id || savingProviderToggles.value.includes(provider.id)) {
|
||||
return false
|
||||
}
|
||||
|
||||
savingProviderToggles.value.push(provider.id)
|
||||
try {
|
||||
const nextConfig = { ...provider, enable: Boolean(value) }
|
||||
const response = await axios.post('/api/config/provider/update', {
|
||||
id: provider.id,
|
||||
config: nextConfig
|
||||
})
|
||||
if (response.data.status === 'error') {
|
||||
throw new Error(response.data.message)
|
||||
}
|
||||
provider.enable = nextConfig.enable
|
||||
showMessage(response.data.message || tm('messages.success.statusUpdate'))
|
||||
return true
|
||||
} catch (error: any) {
|
||||
showMessage(error.response?.data?.message || error.message || tm('providerSources.saveError'), 'error')
|
||||
return false
|
||||
} finally {
|
||||
await loadConfig()
|
||||
savingProviderToggles.value = savingProviderToggles.value.filter((id) => id !== provider.id)
|
||||
}
|
||||
}
|
||||
|
||||
async function testProvider(provider: any) {
|
||||
testingProviders.value.push(provider.id)
|
||||
try {
|
||||
@@ -629,7 +657,7 @@ export function useProviderSources(options: UseProviderSourcesOptions) {
|
||||
}
|
||||
|
||||
async function loadConfig() {
|
||||
loadProviderTemplate()
|
||||
await loadProviderTemplate()
|
||||
}
|
||||
|
||||
async function loadProviderTemplate() {
|
||||
@@ -670,6 +698,7 @@ export function useProviderSources(options: UseProviderSourcesOptions) {
|
||||
modelMetadata,
|
||||
loadingModels,
|
||||
savingSource,
|
||||
savingProviderToggles,
|
||||
testingProviders,
|
||||
isSourceModified,
|
||||
configSchema,
|
||||
@@ -711,6 +740,7 @@ export function useProviderSources(options: UseProviderSourcesOptions) {
|
||||
addModelProvider,
|
||||
deleteProvider,
|
||||
modelAlreadyConfigured,
|
||||
toggleProviderEnable,
|
||||
testProvider,
|
||||
loadConfig,
|
||||
loadProviderTemplate
|
||||
|
||||
Reference in New Issue
Block a user