|
| 1 | +<script setup lang="ts"> |
| 2 | +import type { RemovableRef } from '@vueuse/core' |
| 3 | +
|
| 4 | +import { |
| 5 | + Alert, |
| 6 | + ProviderAdvancedSettings, |
| 7 | + ProviderApiKeyInput, |
| 8 | + ProviderBaseUrlInput, |
| 9 | + ProviderBasicSettings, |
| 10 | + ProviderSettingsContainer, |
| 11 | + ProviderSettingsLayout, |
| 12 | +} from '@proj-airi/stage-ui/components' |
| 13 | +import { useProviderValidation } from '@proj-airi/stage-ui/composables/useProviderValidation' |
| 14 | +import { useProvidersStore } from '@proj-airi/stage-ui/stores/providers' |
| 15 | +import { storeToRefs } from 'pinia' |
| 16 | +import { computed } from 'vue' |
| 17 | +
|
| 18 | +const providerId = '302-ai' |
| 19 | +const providersStore = useProvidersStore() |
| 20 | +const { providers } = storeToRefs(providersStore) as { providers: RemovableRef<Record<string, any>> } |
| 21 | +
|
| 22 | +// Define computed properties for credentials |
| 23 | +const apiKey = computed({ |
| 24 | + get: () => providers.value[providerId]?.apiKey || '', |
| 25 | + set: (value) => { |
| 26 | + if (!providers.value[providerId]) |
| 27 | + providers.value[providerId] = {} |
| 28 | + providers.value[providerId].apiKey = value |
| 29 | + }, |
| 30 | +}) |
| 31 | +
|
| 32 | +const baseUrl = computed({ |
| 33 | + get: () => providers.value[providerId]?.baseUrl || '', |
| 34 | + set: (value) => { |
| 35 | + if (!providers.value[providerId]) |
| 36 | + providers.value[providerId] = {} |
| 37 | + providers.value[providerId].baseUrl = value |
| 38 | + }, |
| 39 | +}) |
| 40 | +
|
| 41 | +// Use the composable to get validation logic and state |
| 42 | +const { |
| 43 | + t, |
| 44 | + router, |
| 45 | + providerMetadata, |
| 46 | + isValidating, |
| 47 | + isValid, |
| 48 | + validationMessage, |
| 49 | + handleResetSettings, |
| 50 | +} = useProviderValidation(providerId) |
| 51 | +</script> |
| 52 | + |
| 53 | +<template> |
| 54 | + <ProviderSettingsLayout |
| 55 | + :provider-name="providerMetadata?.localizedName" |
| 56 | + :provider-icon-color="providerMetadata?.iconColor" |
| 57 | + :on-back="() => router.back()" |
| 58 | + > |
| 59 | + <ProviderSettingsContainer> |
| 60 | + <ProviderBasicSettings |
| 61 | + :title="t('settings.pages.providers.common.section.basic.title')" |
| 62 | + :description="t('settings.pages.providers.common.section.basic.description')" |
| 63 | + :on-reset="handleResetSettings" |
| 64 | + > |
| 65 | + <ProviderApiKeyInput |
| 66 | + v-model="apiKey" |
| 67 | + :provider-name="providerMetadata?.localizedName" |
| 68 | + placeholder="sk-..." |
| 69 | + /> |
| 70 | + </ProviderBasicSettings> |
| 71 | + |
| 72 | + <ProviderAdvancedSettings :title="t('settings.pages.providers.common.section.advanced.title')"> |
| 73 | + <ProviderBaseUrlInput |
| 74 | + v-model="baseUrl" |
| 75 | + placeholder="https://api.302.ai/v1/" |
| 76 | + /> |
| 77 | + </ProviderAdvancedSettings> |
| 78 | + |
| 79 | + <!-- Validation Status --> |
| 80 | + <Alert v-if="!isValid && isValidating === 0 && validationMessage" type="error"> |
| 81 | + <template #title> |
| 82 | + {{ t('settings.dialogs.onboarding.validationFailed') }} |
| 83 | + </template> |
| 84 | + <template v-if="validationMessage" #content> |
| 85 | + <div class="whitespace-pre-wrap break-all"> |
| 86 | + {{ validationMessage }} |
| 87 | + </div> |
| 88 | + </template> |
| 89 | + </Alert> |
| 90 | + <Alert v-if="isValid && isValidating === 0" type="success"> |
| 91 | + <template #title> |
| 92 | + {{ t('settings.dialogs.onboarding.validationSuccess') }} |
| 93 | + </template> |
| 94 | + </Alert> |
| 95 | + </ProviderSettingsContainer> |
| 96 | + </ProviderSettingsLayout> |
| 97 | +</template> |
| 98 | + |
| 99 | +<route lang="yaml"> |
| 100 | +meta: |
| 101 | + layout: settings |
| 102 | + stageTransition: |
| 103 | + name: slide |
| 104 | +</route> |
0 commit comments