Skip to content

Commit f168fef

Browse files
committed
feat: add tooltip for filling default API URL in settings
1 parent b517c2d commit f168fef

File tree

15 files changed

+139
-16
lines changed

15 files changed

+139
-16
lines changed

src/renderer/settings/components/AnthropicProviderSettingsDetail.vue

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,34 @@
5454
@keyup.enter="handleApiHostChange(apiHost)"
5555
/>
5656
<div class="text-xs text-muted-foreground">
57-
{{
58-
t('settings.provider.urlFormat', {
59-
defaultUrl: 'https://api.anthropic.com'
60-
})
61-
}}
57+
<TooltipProvider v-if="hasDefaultBaseUrl" :delayDuration="200">
58+
<Tooltip>
59+
<TooltipTrigger as-child>
60+
<button
61+
type="button"
62+
class="text-xs text-muted-foreground underline decoration-dotted underline-offset-2 transition-colors hover:text-foreground"
63+
:aria-label="t('settings.provider.urlFormatFill')"
64+
@click="fillDefaultBaseUrl"
65+
>
66+
{{
67+
t('settings.provider.urlFormat', {
68+
defaultUrl: defaultBaseUrl
69+
})
70+
}}
71+
</button>
72+
</TooltipTrigger>
73+
<TooltipContent>
74+
{{ t('settings.provider.urlFormatFill') }}
75+
</TooltipContent>
76+
</Tooltip>
77+
</TooltipProvider>
78+
<span v-else>
79+
{{
80+
t('settings.provider.urlFormat', {
81+
defaultUrl: defaultBaseUrl
82+
})
83+
}}
84+
</span>
6285
</div>
6386

6487
<Label :for="`${provider.id}-apikey`" class="flex-1 cursor-pointer">{{
@@ -340,6 +363,12 @@ import { onMounted, ref, watch, onUnmounted, computed } from 'vue'
340363
import { Label } from '@shadcn/components/ui/label'
341364
import { Input } from '@shadcn/components/ui/input'
342365
import { Button } from '@shadcn/components/ui/button'
366+
import {
367+
Tooltip,
368+
TooltipContent,
369+
TooltipProvider,
370+
TooltipTrigger
371+
} from '@shadcn/components/ui/tooltip'
343372
import { Icon } from '@iconify/vue'
344373
import {
345374
Dialog,
@@ -396,6 +425,8 @@ const oauthCode = ref('')
396425
const codeValidationError = ref('')
397426
const isSubmittingCode = ref(false)
398427
const showDeleteProviderDialog = ref(false)
428+
const defaultBaseUrl = 'https://api.anthropic.com'
429+
const hasDefaultBaseUrl = defaultBaseUrl.length > 0
399430
400431
// Computed
401432
const hasOAuthToken = ref(false)
@@ -610,6 +641,12 @@ const handleApiHostChange = async (value: string) => {
610641
await providerStore.updateProviderApi(props.provider.id, undefined, value)
611642
}
612643
644+
const fillDefaultBaseUrl = async () => {
645+
if (!hasDefaultBaseUrl) return
646+
apiHost.value = defaultBaseUrl
647+
await handleApiHostChange(defaultBaseUrl)
648+
}
649+
613650
// API Key 处理
614651
const handleApiKeyChange = async (value: string) => {
615652
await providerStore.updateProviderApi(props.provider.id, value, undefined)

src/renderer/settings/components/OllamaProviderSettingsDetail.vue

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,34 @@
2323
@keyup.enter="handleApiHostChange(apiHost)"
2424
/>
2525
<div class="text-xs text-muted-foreground">
26-
{{
27-
t('settings.provider.urlFormat', {
28-
defaultUrl: 'http://127.0.0.1:11434'
29-
})
30-
}}
26+
<TooltipProvider v-if="hasDefaultBaseUrl" :delayDuration="200">
27+
<Tooltip>
28+
<TooltipTrigger as-child>
29+
<button
30+
type="button"
31+
class="text-xs text-muted-foreground underline decoration-dotted underline-offset-2 transition-colors hover:text-foreground"
32+
:aria-label="t('settings.provider.urlFormatFill')"
33+
@click="fillDefaultBaseUrl"
34+
>
35+
{{
36+
t('settings.provider.urlFormat', {
37+
defaultUrl: defaultBaseUrl
38+
})
39+
}}
40+
</button>
41+
</TooltipTrigger>
42+
<TooltipContent>
43+
{{ t('settings.provider.urlFormatFill') }}
44+
</TooltipContent>
45+
</Tooltip>
46+
</TooltipProvider>
47+
<span v-else>
48+
{{
49+
t('settings.provider.urlFormat', {
50+
defaultUrl: defaultBaseUrl
51+
})
52+
}}
53+
</span>
3154
</div>
3255
</div>
3356

@@ -276,6 +299,12 @@ import { Label } from '@shadcn/components/ui/label'
276299
import { Input } from '@shadcn/components/ui/input'
277300
import { Button } from '@shadcn/components/ui/button'
278301
import { Progress } from '@shadcn/components/ui/progress'
302+
import {
303+
Tooltip,
304+
TooltipContent,
305+
TooltipProvider,
306+
TooltipTrigger
307+
} from '@shadcn/components/ui/tooltip'
279308
import { Icon } from '@iconify/vue'
280309
import {
281310
Dialog,
@@ -310,6 +339,8 @@ const showPullModelDialog = ref(false)
310339
const showCheckModelDialog = ref(false)
311340
const checkResult = ref<boolean>(false)
312341
const showDeleteProviderDialog = ref(false)
342+
const defaultBaseUrl = 'http://127.0.0.1:11434'
343+
const hasDefaultBaseUrl = defaultBaseUrl.length > 0
313344
314345
// 模型列表 - 从 settings store 获取
315346
const runningModels = computed(() => ollamaStore.getOllamaRunningModels(props.provider.id))
@@ -903,6 +934,12 @@ const handleApiHostChange = async (value: string) => {
903934
await providerStore.updateProviderApi(props.provider.id, undefined, value)
904935
}
905936
937+
const fillDefaultBaseUrl = async () => {
938+
if (!hasDefaultBaseUrl) return
939+
apiHost.value = defaultBaseUrl
940+
await handleApiHostChange(defaultBaseUrl)
941+
}
942+
906943
// API Key 处理
907944
const handleApiKeyChange = async (value: string) => {
908945
await providerStore.updateProviderApi(props.provider.id, value, undefined)

src/renderer/settings/components/ProviderApiConfig.vue

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,34 @@
2323
@update:model-value="apiHost = String($event)"
2424
/>
2525
<div class="text-xs text-muted-foreground">
26-
{{
27-
t('settings.provider.urlFormat', {
28-
defaultUrl: providerWebsites?.defaultBaseUrl || ''
29-
})
30-
}}
26+
<TooltipProvider v-if="hasDefaultBaseUrl" :delayDuration="200">
27+
<Tooltip>
28+
<TooltipTrigger as-child>
29+
<button
30+
type="button"
31+
class="text-xs text-muted-foreground underline decoration-dotted underline-offset-2 transition-colors hover:text-foreground"
32+
:aria-label="t('settings.provider.urlFormatFill')"
33+
@click="fillDefaultBaseUrl"
34+
>
35+
{{
36+
t('settings.provider.urlFormat', {
37+
defaultUrl: defaultBaseUrl
38+
})
39+
}}
40+
</button>
41+
</TooltipTrigger>
42+
<TooltipContent>
43+
{{ t('settings.provider.urlFormatFill') }}
44+
</TooltipContent>
45+
</Tooltip>
46+
</TooltipProvider>
47+
<span v-else>
48+
{{
49+
t('settings.provider.urlFormat', {
50+
defaultUrl: defaultBaseUrl
51+
})
52+
}}
53+
</span>
3154
</div>
3255
</div>
3356

@@ -127,11 +150,17 @@
127150
</template>
128151

129152
<script setup lang="ts">
130-
import { onMounted, ref, watch } from 'vue'
153+
import { computed, onMounted, ref, watch } from 'vue'
131154
import { useI18n } from 'vue-i18n'
132155
import { Label } from '@shadcn/components/ui/label'
133156
import { Input } from '@shadcn/components/ui/input'
134157
import { Button } from '@shadcn/components/ui/button'
158+
import {
159+
Tooltip,
160+
TooltipContent,
161+
TooltipProvider,
162+
TooltipTrigger
163+
} from '@shadcn/components/ui/tooltip'
135164
import { Icon } from '@iconify/vue'
136165
import GitHubCopilotOAuth from './GitHubCopilotOAuth.vue'
137166
import { usePresenter } from '@/composables/usePresenter'
@@ -169,6 +198,8 @@ const apiHost = ref(props.provider.baseUrl || '')
169198
const keyStatus = ref<KeyStatus | null>(null)
170199
const isRefreshing = ref(false)
171200
const showApiKey = ref(false)
201+
const defaultBaseUrl = computed(() => props.providerWebsites?.defaultBaseUrl?.trim() || '')
202+
const hasDefaultBaseUrl = computed(() => defaultBaseUrl.value.length > 0)
172203
173204
watch(
174205
() => props.provider,
@@ -193,6 +224,12 @@ const handleApiHostChange = (value: string) => {
193224
emit('api-host-change', value)
194225
}
195226
227+
const fillDefaultBaseUrl = () => {
228+
if (!hasDefaultBaseUrl.value) return
229+
apiHost.value = defaultBaseUrl.value
230+
handleApiHostChange(defaultBaseUrl.value)
231+
}
232+
196233
const handleApiHostBlur = (event: FocusEvent) => {
197234
const target = event.target as HTMLInputElement | null
198235
if (!target) return

src/renderer/src/i18n/da-DK/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@
301301
"getKeyTip": "Besøg venligst",
302302
"getKeyTipEnd": "for at få API-nøglen",
303303
"urlFormat": "API-eksempel: {defaultUrl}",
304+
"urlFormatFill": "Udfyld API-URL",
304305
"modelList": "Modelliste",
305306
"enableModels": "Aktivér modeller",
306307
"disableAllModels": "Deaktiver alle modeller",

src/renderer/src/i18n/en-US/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@
313313
"getKeyTip": "Please visit",
314314
"getKeyTipEnd": "to get API Key",
315315
"urlFormat": "API Example: {defaultUrl}",
316+
"urlFormatFill": "Fill into API URL",
316317
"modelList": "Model List",
317318
"enableModels": "Enable Models",
318319
"disableAllModels": "Disable All Models",

src/renderer/src/i18n/fa-IR/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@
313313
"getKeyTip": "لطفاً به",
314314
"getKeyTipEnd": "بروید تا کلید API را دریافت کنید",
315315
"urlFormat": "نمونه API: {defaultUrl}",
316+
"urlFormatFill": "قرار دادن در URL API",
316317
"modelList": "فهرست مدل‌ها",
317318
"enableModels": "روشن کردن مدل‌ها",
318319
"disableAllModels": "خاموش کردن همه مدل‌ها",

src/renderer/src/i18n/fr-FR/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@
313313
"getKeyTip": "Veuillez visiter",
314314
"getKeyTipEnd": "pour obtenir la clé API",
315315
"urlFormat": "Exemple d'API : {defaultUrl}",
316+
"urlFormatFill": "Renseigner l'URL de l'API",
316317
"modelList": "Liste des modèles",
317318
"enableModels": "Activer les modèles",
318319
"disableAllModels": "Désactiver tous les modèles",

src/renderer/src/i18n/he-IL/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@
313313
"getKeyTip": "אנא בקר ב",
314314
"getKeyTipEnd": "כדי לקבל מפתח API",
315315
"urlFormat": "דוגמת API: {defaultUrl}",
316+
"urlFormatFill": "מילוי בכתובת ה-API",
316317
"modelList": "רשימת מודלים",
317318
"enableModels": "הפעל מודלים",
318319
"disableAllModels": "השבת את כל המודלים",

src/renderer/src/i18n/ja-JP/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@
313313
"getKeyTip": "以下へアクセスしてください",
314314
"getKeyTipEnd": "API Keyを取得する",
315315
"urlFormat": "API例:{defaultUrl}",
316+
"urlFormatFill": "API URL に入力",
316317
"modelList": "モデル一覧",
317318
"enableModels": "モデルを有効にする",
318319
"disableAllModels": "すべてのモデルを無効にする",

src/renderer/src/i18n/ko-KR/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@
434434
"noLocalModels": "로컬 모델 없음",
435435
"localModels": "로컬 모델",
436436
"urlFormat": "API 샘플 : {defaultUrl}",
437+
"urlFormatFill": "API URL에 입력",
437438
"azureApiVersion": "API 버전",
438439
"safety": {
439440
"title": "보안 설정",

0 commit comments

Comments
 (0)