2026-04-13 12:15:16 +08:00
|
|
|
|
<script setup lang="ts">
|
2026-04-19 20:59:25 +08:00
|
|
|
|
import { ref, computed } from 'vue'
|
2026-04-13 12:15:16 +08:00
|
|
|
|
import { NButton, useMessage, useDialog } from 'naive-ui'
|
2026-04-16 08:38:18 +08:00
|
|
|
|
import type { AvailableModelGroup } from '@/api/hermes/system'
|
|
|
|
|
|
import { useModelsStore } from '@/stores/hermes/models'
|
2026-04-26 22:51:35 +08:00
|
|
|
|
import { useAppStore } from '@/stores/hermes/app'
|
|
|
|
|
|
import { useChatStore } from '@/stores/hermes/chat'
|
|
|
|
|
|
import { checkCopilotToken, disableCopilot } from '@/api/hermes/copilot-auth'
|
2026-04-13 15:15:14 +08:00
|
|
|
|
import { useI18n } from 'vue-i18n'
|
2026-04-13 12:15:16 +08:00
|
|
|
|
|
|
|
|
|
|
const props = defineProps<{ provider: AvailableModelGroup }>()
|
|
|
|
|
|
|
2026-04-13 15:15:14 +08:00
|
|
|
|
const { t } = useI18n()
|
2026-04-13 12:15:16 +08:00
|
|
|
|
const modelsStore = useModelsStore()
|
2026-04-26 22:51:35 +08:00
|
|
|
|
const appStore = useAppStore()
|
|
|
|
|
|
const chatStore = useChatStore()
|
2026-04-13 12:15:16 +08:00
|
|
|
|
const message = useMessage()
|
|
|
|
|
|
const dialog = useDialog()
|
|
|
|
|
|
|
|
|
|
|
|
const isCustom = computed(() => props.provider.provider.startsWith('custom:'))
|
2026-04-26 22:51:35 +08:00
|
|
|
|
const isCopilot = computed(() => props.provider.provider === 'copilot')
|
2026-04-13 12:15:16 +08:00
|
|
|
|
const displayName = computed(() => props.provider.label)
|
2026-04-19 20:59:25 +08:00
|
|
|
|
const deleting = ref(false)
|
2026-04-13 12:15:16 +08:00
|
|
|
|
|
|
|
|
|
|
async function handleDelete() {
|
2026-04-26 22:51:35 +08:00
|
|
|
|
let copilotMsg = ''
|
|
|
|
|
|
if (isCopilot.value) {
|
|
|
|
|
|
// 提前查 source,让用户清楚移除会不会影响 VS Code/gh CLI 等其他工具的登录态
|
|
|
|
|
|
try {
|
|
|
|
|
|
const status = await checkCopilotToken()
|
|
|
|
|
|
if (status.source === 'env') copilotMsg = t('models.copilotDeleteHintEnv')
|
|
|
|
|
|
else if (status.source === 'gh-cli') copilotMsg = t('models.copilotDeleteHintGhCli')
|
|
|
|
|
|
else if (status.source === 'apps-json') copilotMsg = t('models.copilotDeleteHintAppsJson')
|
|
|
|
|
|
} catch { /* ignore — fall back to generic confirm copy */ }
|
|
|
|
|
|
}
|
2026-04-13 12:15:16 +08:00
|
|
|
|
dialog.warning({
|
2026-04-13 15:15:14 +08:00
|
|
|
|
title: t('models.deleteProvider'),
|
2026-04-26 22:51:35 +08:00
|
|
|
|
content: isCopilot.value && copilotMsg
|
|
|
|
|
|
? `${t('models.deleteConfirm', { name: displayName.value })}\n\n${copilotMsg}`
|
|
|
|
|
|
: t('models.deleteConfirm', { name: displayName.value }),
|
2026-04-13 15:15:14 +08:00
|
|
|
|
positiveText: t('common.delete'),
|
|
|
|
|
|
negativeText: t('common.cancel'),
|
2026-04-13 12:15:16 +08:00
|
|
|
|
onPositiveClick: async () => {
|
2026-04-19 20:59:25 +08:00
|
|
|
|
deleting.value = true
|
2026-04-13 12:15:16 +08:00
|
|
|
|
try {
|
2026-04-26 22:51:35 +08:00
|
|
|
|
if (isCopilot.value) {
|
|
|
|
|
|
// Copilot 走显式 opt-in 模型:disable 把 enabled 置 false,
|
|
|
|
|
|
// 仅当 token 来自 ~/.hermes/.env 时才清掉,gh-cli / apps.json 不动。
|
|
|
|
|
|
await disableCopilot()
|
|
|
|
|
|
// 服务端会在默认模型属于 copilot 时清掉 model.default,这里再清理本地
|
|
|
|
|
|
// 会话级 model/provider,避免 Chat 页继续显示已下架的 copilot 模型。
|
|
|
|
|
|
chatStore.clearProviderFromSessions('copilot')
|
|
|
|
|
|
await Promise.all([modelsStore.fetchProviders(), appStore.loadModels()])
|
|
|
|
|
|
} else {
|
|
|
|
|
|
await modelsStore.removeProvider(props.provider.provider)
|
|
|
|
|
|
}
|
|
|
|
|
|
// 删完之后若已没有默认模型,自动从剩余 provider 里挑一个,避免 chat 页
|
|
|
|
|
|
// "无默认模型"的尴尬态。与 hermes CLI `model` 子命令的隐含行为对齐。
|
|
|
|
|
|
if (!appStore.selectedModel && appStore.modelGroups.length > 0) {
|
|
|
|
|
|
const first = appStore.modelGroups.find(g => g.models.length > 0)
|
|
|
|
|
|
if (first) {
|
|
|
|
|
|
await appStore.switchModel(first.models[0], first.provider)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-04-13 15:15:14 +08:00
|
|
|
|
message.success(t('models.providerDeleted'))
|
2026-04-13 12:15:16 +08:00
|
|
|
|
} catch (e: any) {
|
|
|
|
|
|
message.error(e.message)
|
2026-04-19 20:59:25 +08:00
|
|
|
|
} finally {
|
|
|
|
|
|
deleting.value = false
|
2026-04-13 12:15:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
|
<div class="provider-card">
|
|
|
|
|
|
<div class="card-header">
|
|
|
|
|
|
<h3 class="provider-name">{{ displayName }}</h3>
|
|
|
|
|
|
<span class="type-badge" :class="isCustom ? 'custom' : 'builtin'">
|
2026-04-13 15:15:14 +08:00
|
|
|
|
{{ isCustom ? t('models.customType') : t('models.builtIn') }}
|
2026-04-13 12:15:16 +08:00
|
|
|
|
</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="card-body">
|
|
|
|
|
|
<div class="info-row">
|
2026-04-13 15:15:14 +08:00
|
|
|
|
<span class="info-label">{{ t('models.provider') }}</span>
|
2026-04-13 12:15:16 +08:00
|
|
|
|
<code class="info-value mono">{{ provider.provider }}</code>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="info-row">
|
2026-04-13 15:15:14 +08:00
|
|
|
|
<span class="info-label">{{ t('models.baseUrl') }}</span>
|
2026-04-13 12:15:16 +08:00
|
|
|
|
<code class="info-value mono">{{ provider.base_url }}</code>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="card-actions">
|
2026-04-19 20:59:25 +08:00
|
|
|
|
<NButton size="tiny" quaternary type="error" :loading="deleting" @click="handleDelete">{{ t('common.delete') }}</NButton>
|
2026-04-13 12:15:16 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
|
|
@use '@/styles/variables' as *;
|
|
|
|
|
|
|
|
|
|
|
|
.provider-card {
|
|
|
|
|
|
background-color: $bg-card;
|
|
|
|
|
|
border: 1px solid $border-color;
|
|
|
|
|
|
border-radius: $radius-md;
|
|
|
|
|
|
padding: 16px;
|
|
|
|
|
|
transition: border-color $transition-fast;
|
|
|
|
|
|
|
|
|
|
|
|
&:hover {
|
2026-04-16 23:13:04 +08:00
|
|
|
|
border-color: rgba(var(--accent-primary-rgb), 0.3);
|
2026-04-13 12:15:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.card-header {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
|
margin-bottom: 12px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.provider-name {
|
|
|
|
|
|
font-size: 15px;
|
|
|
|
|
|
font-weight: 600;
|
|
|
|
|
|
color: $text-primary;
|
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
|
max-width: 70%;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.type-badge {
|
|
|
|
|
|
font-size: 11px;
|
|
|
|
|
|
padding: 2px 8px;
|
|
|
|
|
|
border-radius: 10px;
|
|
|
|
|
|
font-weight: 500;
|
|
|
|
|
|
|
|
|
|
|
|
&.builtin {
|
2026-04-16 23:13:04 +08:00
|
|
|
|
background: rgba(var(--accent-primary-rgb), 0.12);
|
2026-04-13 12:15:16 +08:00
|
|
|
|
color: $accent-primary;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
&.custom {
|
2026-04-16 23:13:04 +08:00
|
|
|
|
background: rgba(var(--success-rgb), 0.12);
|
2026-04-13 12:15:16 +08:00
|
|
|
|
color: $success;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.card-body {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
gap: 6px;
|
|
|
|
|
|
margin-bottom: 14px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.info-row {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.info-label {
|
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
|
color: $text-muted;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.info-value {
|
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
|
color: $text-secondary;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.mono {
|
|
|
|
|
|
font-family: $font-code;
|
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.card-actions {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
gap: 8px;
|
|
|
|
|
|
border-top: 1px solid $border-light;
|
|
|
|
|
|
padding-top: 10px;
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|